Skip to content
This repository has been archived by the owner on Mar 13, 2021. It is now read-only.

Commit

Permalink
Release v0.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
scothis committed May 13, 2020
1 parent bf764bf commit ced0e0d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 19 deletions.
30 changes: 13 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,44 +39,40 @@ module.exports.$interactionModel = 'request-reply';
Streaming functions must comply to the following signature:
```js
module.exports = (inputStreams, outputStreams) => {
const firstInputStream = inputStreams.$order[0];
const firstOutputStream = outputStreams.$order[0];
const secondOutputStream = outputStreams.$order[1];
const { numbers, letters } = inputStreams;
const { repetitions } = outputStreams;
// do something
};
module.exports.$interactionModel = 'node-streams';
```

Please note that streaming functions must always declare the corresponding interaction mode.

Parameters can also be looked up by name:
Streams can also be looked up by index:
```js
module.exports = (inputStreams, outputStreams) => {
const { numbers, letters } = inputStreams;
const { repetitions } = outputStreams;
const firstInputStream = inputStreams.$order[0];
const firstOutputStream = outputStreams.$order[0];
const secondOutputStream = outputStreams.$order[1];
// do something
};
module.exports.$interactionModel = 'node-streams';
```


Input streams are [Readable streams](https://nodejs.org/api/stream.html#stream_readable_streams).

Output streams are [Writable streams](https://nodejs.org/api/stream.html#stream_class_stream_readable).

The function **must** end the output streams when it is done emitting data or when an error occurs
(if the output streams are [`pipe`](https://nodejs.org/api/stream.html#stream_readable_pipe_destination_options)'d from
input streams, then this is automatically managed by this invoker).
input streams, then this is automatically managed).

## Message support

A message is an object that contains both headers and a payload.
Message headers are a map with case-insensitive keys and multiple string values.

Since JavaScript and Node have no built-in type for messages or headers, riff uses the [@projectriff/message](https://github.com/projectriff/node-message/) npm module. To use messages, functions should install the `@projectriff/message` package:
```bash
npm install --save @projectriff/message
```
Since JavaScript and Node have no built-in type for messages or headers, riff uses the [@projectriff/message](https://github.com/projectriff/node-message/) npm module.

By default, request-reply functions accept and produce payloads.
They can be configured instead to **receive** either the entire message or the headers only.
Expand All @@ -87,8 +83,6 @@ They can be configured instead to **receive** either the entire message or the h
##### Receiving messages

```js
const { Message } = require('@projectriff/message');

// a request-reply function that accepts a message, which is an instance of Message
module.exports = message => {
const authorization = message.headers.getValue('Authorization');
Expand All @@ -101,6 +95,11 @@ module.exports.$argumentType = 'message';

##### Producing messages

To produce messages, functions should install the `@projectriff/message` package:
```bash
npm install --save @projectriff/message
```

```js
const { Message } = require('@projectriff/message');

Expand All @@ -115,9 +114,6 @@ module.exports = name => {
.payload(`Hello ${name}!`)
.build();
};

// even if the function receives payloads, it can still produce a message
module.exports.$argumentType = 'payload';
```

## Lifecycle
Expand Down
2 changes: 1 addition & 1 deletion npm-shrinkwrap.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@projectriff/node-function-invoker",
"version": "0.2.2-snapshot",
"version": "0.3.0",
"description": "riff invoker for Node functions",
"main": "lib/invoker.js",
"repository": "[email protected]:projectriff/node-function-invoker.git",
Expand Down

0 comments on commit ced0e0d

Please sign in to comment.