|
1 |
| -# Interval JS SDK |
| 1 | +## Interval SDK for Node |
2 | 2 |
|
3 |
| -The Interval SDK consists of several high-level actors responsible |
4 |
| -for handling communication between the defined actions and Interval. |
| 3 | +This is the official Interval SDK for Node.js. |
5 | 4 |
|
6 |
| -## Architecture |
7 |
| - |
8 |
| -What follows is a high-level overview of how the underlying actors interact |
9 |
| -with each other and with Interval. |
10 |
| - |
11 |
| -### `Interval` |
12 |
| - |
13 |
| -The default export `Interval` class is the entrypoint to connecting |
14 |
| -to Interval. Upon calling `listen()`, the `Interval` class does the |
15 |
| -following: |
16 |
| - |
17 |
| -1. Establishes an `ISocket` connection to Interval |
18 |
| -2. Creates a `DuplexRPCClient`, defining methods for sending |
19 |
| - and responding to high-level RPC messages from Interval. |
20 |
| -3. Sends the `INITIALIZE_HOST` RPC message to Interval, |
21 |
| - letting it know what actions this host is defining |
22 |
| - and the handlers to call when those actions are run. |
23 |
| - |
24 |
| -### `ISocket` |
25 |
| - |
26 |
| -A relatively thin wrapper around an underlying WebSocket connection. |
27 |
| -ISocket connections can be thought of as a TCP layer over WebSockets, |
28 |
| -each `MESSAGE` message must followed by an `ACK` message from the recipient. |
29 |
| -If the `ACK` is not received for a given `MESSAGE`, the Promise for that |
30 |
| -message is rejected and a `TimeoutError` is thrown. |
31 |
| - |
32 |
| -### `DuplexRPCClient` |
33 |
| - |
34 |
| -Responsible for exchanging high-level RPC messages with another `DuplexRPCClient`. |
35 |
| -Schemas that define the messages that the client can send and respond to are |
36 |
| -defined ahead of time, providing static guarantees that the messages are |
37 |
| -acceptable for the given connection. Uses an `ISocket` object to exchange data. |
38 |
| - |
39 |
| -### `IOClient` |
40 |
| - |
41 |
| -When a transaction is created for a given transaction, the SDK host |
42 |
| -`DuplexRPCClient` receives a `START_TRANSACTION` call, detailing the action |
43 |
| -and some additional metadata about the transaction. Upon receiving the |
44 |
| -`START_TRANSACTION` call, the call handler creates an `IOClient` object |
45 |
| -for the new transaction, passing a `send` argument to the `IOClient` |
46 |
| -constructor which translates the `IOClient`'s IO render instruction into |
47 |
| -an RPC message to be sent by the `DuplexRPCClient`. |
48 |
| - |
49 |
| -The `IOClient`'s primary purpose is to pass the `IO` namespace of IO methods to |
50 |
| -the action handler. These methods return `IOPromise` objects which detail |
51 |
| -translating the user-provided properties into the properties that make up an IO |
52 |
| -render instruction. |
53 |
| -The `IOPromise` objects can be `await`ed directly, |
54 |
| -rendering only the single component to the action runner, or in an `io.group`, |
55 |
| -which can render multiple `IOPromise` components in a single call. |
56 |
| - |
57 |
| -The `IOClient` defines the internal `renderComponents` method, which |
58 |
| -handles the render loop for a given IO call. |
59 |
| -Given a list of `IOComponent`s (potentially only one if not rendering a group) |
60 |
| -this method is responsible for sending the initial render call and handling |
61 |
| -responses (returns, state updates, or cancellations) from Interval. |
62 |
| -Resolves when each `IOComponent`'s `returnValue` Promise is resolved via |
63 |
| -response from Interval, or throws an IOError of kind `CANCELED` if canceled. |
64 |
| - |
65 |
| -### `IOPromise` |
66 |
| - |
67 |
| -A custom wrapper class that handles creating the underlying component |
68 |
| -model when the IO call is to be rendered, and optionally transforming |
69 |
| -the value received from Interval to a custom component return type. |
70 |
| -A relatively thin wrapper around the internal `IOComponent` which is primarily |
71 |
| -responsible for being `await`able and transforming the network-level |
72 |
| -props and return values to the values expected by the IO method caller. |
73 |
| -If `await`ed, resolves when the internal `IOComponent`'s `returnValue` Promise |
74 |
| -is resolved. |
75 |
| - |
76 |
| -### `IOComponent` |
77 |
| - |
78 |
| -The internal model underlying each `IOPromise`, responsible for constructing |
79 |
| -the data transmitted to Interval for an IO component, and handling responses |
80 |
| -received from Interval for the current component: resolving its `returnValue` |
81 |
| -when receiving a final response from the action runner, or constructing a new |
82 |
| -set of props when receiving new state. |
| 5 | +Visit [intervalkit.com](https://intervalkit.com) for more information. |
0 commit comments