@replit/river 0.9.3 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/__tests__/bandwidth.bench.js +11 -11
- package/dist/__tests__/cleanup.test.d.ts +2 -0
- package/dist/__tests__/cleanup.test.d.ts.map +1 -0
- package/dist/__tests__/{invariants.test.js → cleanup.test.js} +47 -20
- package/dist/__tests__/disconnects.test.d.ts +2 -0
- package/dist/__tests__/disconnects.test.d.ts.map +1 -0
- package/dist/__tests__/disconnects.test.js +163 -0
- package/dist/__tests__/e2e.test.js +33 -32
- package/dist/__tests__/fixtures/cleanup.d.ts +2 -2
- package/dist/__tests__/fixtures/cleanup.d.ts.map +1 -1
- package/dist/__tests__/fixtures/cleanup.js +6 -9
- package/dist/__tests__/fixtures/services.d.ts +36 -36
- package/dist/__tests__/fixtures/services.d.ts.map +1 -1
- package/dist/__tests__/fixtures/services.js +36 -53
- package/dist/__tests__/handler.test.js +6 -7
- package/dist/__tests__/typescript-stress.test.d.ts +149 -149
- package/dist/__tests__/typescript-stress.test.d.ts.map +1 -1
- package/dist/__tests__/typescript-stress.test.js +14 -14
- package/dist/router/builder.d.ts +6 -7
- package/dist/router/builder.d.ts.map +1 -1
- package/dist/router/client.d.ts +7 -3
- package/dist/router/client.d.ts.map +1 -1
- package/dist/router/client.js +204 -106
- package/dist/router/defs.d.ts +16 -0
- package/dist/router/defs.d.ts.map +1 -0
- package/dist/router/defs.js +11 -0
- package/dist/router/index.d.ts +2 -0
- package/dist/router/index.d.ts.map +1 -1
- package/dist/router/index.js +1 -0
- package/dist/router/result.d.ts +2 -1
- package/dist/router/result.d.ts.map +1 -1
- package/dist/router/result.js +5 -1
- package/dist/router/server.d.ts +5 -5
- package/dist/router/server.d.ts.map +1 -1
- package/dist/router/server.js +125 -82
- package/dist/transport/impls/stdio/stdio.test.js +1 -2
- package/dist/transport/impls/ws/client.d.ts +1 -4
- package/dist/transport/impls/ws/client.d.ts.map +1 -1
- package/dist/transport/impls/ws/client.js +5 -6
- package/dist/transport/impls/ws/server.d.ts +3 -0
- package/dist/transport/impls/ws/server.d.ts.map +1 -1
- package/dist/transport/impls/ws/server.js +28 -23
- package/dist/transport/impls/ws/ws.test.js +84 -16
- package/dist/transport/index.d.ts +0 -9
- package/dist/transport/index.d.ts.map +1 -1
- package/dist/transport/index.js +0 -21
- package/dist/transport/message.d.ts +3 -4
- package/dist/transport/message.d.ts.map +1 -1
- package/dist/util/testHelpers.d.ts +20 -97
- package/dist/util/testHelpers.d.ts.map +1 -1
- package/dist/util/testHelpers.js +94 -249
- package/package.json +13 -12
- package/dist/__tests__/invariants.test.d.ts +0 -2
- package/dist/__tests__/invariants.test.d.ts.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../transport/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../transport/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACpD,OAAO,EACL,sBAAsB,EACtB,4BAA4B,EAC5B,GAAG,EACH,KAAK,GACN,MAAM,WAAW,CAAC;AACnB,YAAY,EACV,gBAAgB,EAChB,SAAS,EACT,sBAAsB,EACtB,iBAAiB,EACjB,YAAY,EACZ,aAAa,GACd,MAAM,WAAW,CAAC"}
|
package/dist/transport/index.js
CHANGED
|
@@ -1,23 +1,2 @@
|
|
|
1
|
-
// re-export
|
|
2
1
|
export { Transport, Connection } from './transport';
|
|
3
2
|
export { TransportMessageSchema, OpaqueTransportMessageSchema, msg, reply, } from './message';
|
|
4
|
-
/**
|
|
5
|
-
* Waits for a message from the transport.
|
|
6
|
-
* @param {Transport} t - The transport to listen to.
|
|
7
|
-
* @param filter - An optional filter function to apply to the received messages.
|
|
8
|
-
* @returns A promise that resolves with the payload of the first message that passes the filter.
|
|
9
|
-
*/
|
|
10
|
-
export async function waitForMessage(t, filter, rejectMismatch) {
|
|
11
|
-
return new Promise((resolve, reject) => {
|
|
12
|
-
function onMessage(msg) {
|
|
13
|
-
if (!filter || filter?.(msg)) {
|
|
14
|
-
resolve(msg.payload);
|
|
15
|
-
t.removeEventListener('message', onMessage);
|
|
16
|
-
}
|
|
17
|
-
else if (rejectMismatch) {
|
|
18
|
-
reject(new Error('message didnt match the filter'));
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
t.addEventListener('message', onMessage);
|
|
22
|
-
});
|
|
23
|
-
}
|
|
@@ -70,10 +70,9 @@ export declare const OpaqueTransportMessageSchema: import("@sinclair/typebox").T
|
|
|
70
70
|
* `controlFlags`:
|
|
71
71
|
* * If `controlFlags & StreamOpenBit == StreamOpenBit`, `streamId` must be set to a unique value
|
|
72
72
|
* (suggestion: use `nanoid`).
|
|
73
|
-
* * `serviceName` and `procedureName` must be set
|
|
74
|
-
*
|
|
75
|
-
*
|
|
76
|
-
* `payload` can be a control message.
|
|
73
|
+
* * If `controlFlags & StreamOpenBit == StreamOpenBit`, `serviceName` and `procedureName` must be set.
|
|
74
|
+
* * If `controlFlags & StreamClosedBit == StreamClosedBit` and the kind is `stream` or `subscription`,
|
|
75
|
+
* `payload` should be discarded (usually contains a control message).
|
|
77
76
|
* @template Payload The type of the payload.
|
|
78
77
|
*/
|
|
79
78
|
export type TransportMessage<Payload extends Record<string, unknown> | unknown = Record<string, unknown>> = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"message.d.ts","sourceRoot":"","sources":["../../transport/message.ts"],"names":[],"mappings":"AAAA,OAAO,EAAQ,OAAO,EAAU,MAAM,mBAAmB,CAAC;AAG1D;;;;;;GAMG;AACH,0BAAkB,YAAY;IAC5B,MAAM,IAAS;IACf,aAAa,IAAS;IACtB,eAAe,IAAS;CACzB;AAED;;;;;GAKG;AACH,eAAO,MAAM,sBAAsB;;;;;;;;;EAU/B,CAAC;AAEL;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;;;;;;;GAUG;AACH,wBAAgB,GAAG,CAAC,OAAO,SAAS,MAAM,EACxC,IAAI,EAAE,MAAM,EACZ,EAAE,EAAE,MAAM,EACV,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,OAAO,EAChB,WAAW,CAAC,EAAE,MAAM,EACpB,aAAa,CAAC,EAAE,MAAM,GACrB,gBAAgB,CAAC,OAAO,CAAC,CAW3B;AAED;;;;;GAKG;AACH,wBAAgB,KAAK,CAAC,OAAO,SAAS,MAAM,EAC1C,GAAG,EAAE,sBAAsB,EAC3B,QAAQ,EAAE,OAAO,GAChB,gBAAgB,CAAC,OAAO,CAAC,CAS3B;AAED;;;;;;GAMG;AACH,wBAAgB,WAAW,CACzB,IAAI,EAAE,iBAAiB,EACvB,EAAE,EAAE,iBAAiB,EACrB,MAAM,EAAE,MAAM;;GAOf;AAED;;;;GAIG;AACH,wBAAgB,KAAK,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAElD;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAIzD;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAK1D"}
|
|
@@ -3,14 +3,11 @@ import WebSocket from 'isomorphic-ws';
|
|
|
3
3
|
import { WebSocketServer } from 'ws';
|
|
4
4
|
import http from 'http';
|
|
5
5
|
import { WebSocketClientTransport } from '../transport/impls/ws/client';
|
|
6
|
-
import {
|
|
7
|
-
import { Procedure, ServiceContext } from '../router';
|
|
8
|
-
import { OpaqueTransportMessage, TransportClientId, TransportMessage } from '../transport';
|
|
9
|
-
import { Pushable } from 'it-pushable';
|
|
10
|
-
import { Result, RiverError, RiverUncaughtSchema } from '../router/result';
|
|
6
|
+
import { Connection, OpaqueTransportMessage, Transport, TransportClientId, TransportMessage } from '../transport';
|
|
11
7
|
import { Codec } from '../codec';
|
|
12
8
|
import { WebSocketServerTransport } from '../transport/impls/ws/server';
|
|
13
|
-
import { PayloadType } from '../router
|
|
9
|
+
import { PayloadType, Procedure, Result, RiverError, RiverUncaughtSchema, ServiceContext } from '../router';
|
|
10
|
+
import { Static } from '@sinclair/typebox';
|
|
14
11
|
/**
|
|
15
12
|
* Creates a WebSocket server instance using the provided HTTP server.
|
|
16
13
|
* Only used as helper for testing.
|
|
@@ -40,97 +37,6 @@ export declare function createLocalWebSocketClient(port: number): Promise<WebSoc
|
|
|
40
37
|
* @returns An array containing the client and server {@link WebSocketClientTransport} instances.
|
|
41
38
|
*/
|
|
42
39
|
export declare function createWsTransports(port: number, wss: WebSocketServer, codec?: Codec): [WebSocketClientTransport, WebSocketServerTransport];
|
|
43
|
-
/**
|
|
44
|
-
* Transforms an RPC procedure definition into a normal function call.
|
|
45
|
-
* This should only be used for testing.
|
|
46
|
-
* @template State - The type of the state object.
|
|
47
|
-
* @template I - The type of the input message payload.
|
|
48
|
-
* @template O - The type of the output message payload.
|
|
49
|
-
* @param {State} state - The state object.
|
|
50
|
-
* @param {Procedure<State, 'rpc', I, O, E, null>} proc - The RPC procedure to invoke.
|
|
51
|
-
* @param {Omit<ServiceContext, 'state'>} [extendedContext] - Optional extended context.
|
|
52
|
-
* @returns A function that can be used to invoke the RPC procedure.
|
|
53
|
-
*/
|
|
54
|
-
export declare function asClientRpc<State extends object | unknown, I extends PayloadType, O extends PayloadType, E extends RiverError>(state: State, proc: Procedure<State, 'rpc', I, O, E, null>, extendedContext?: Omit<ServiceContext, 'state'>): (msg: Static<I>) => Promise<Result<Static<O>, Static<E> | Static<typeof RiverUncaughtSchema>>>;
|
|
55
|
-
/**
|
|
56
|
-
* Transforms a stream procedure definition into a pair of input and output streams.
|
|
57
|
-
* Input messages can be pushed into the input stream.
|
|
58
|
-
* This should only be used for testing.
|
|
59
|
-
* @template State - The type of the state object.
|
|
60
|
-
* @template I - The type of the input object.
|
|
61
|
-
* @template O - The type of the output object.
|
|
62
|
-
* @param {State} state - The state object.
|
|
63
|
-
* @param {Procedure<State, 'stream', I, O, E, null>} proc - The procedure to handle the stream.
|
|
64
|
-
* @param {Omit<ServiceContext, 'state'>} [extendedContext] - The extended context object.
|
|
65
|
-
* @returns Pair of input and output streams.
|
|
66
|
-
*/
|
|
67
|
-
export declare function asClientStream<State extends object | unknown, I extends PayloadType, O extends PayloadType, E extends RiverError>(state: State, proc: Procedure<State, 'stream', I, O, E, null>, extendedContext?: Omit<ServiceContext, 'state'>): [
|
|
68
|
-
Pushable<Static<I>>,
|
|
69
|
-
Pushable<Result<Static<O>, Static<E> | Static<typeof RiverUncaughtSchema>>>
|
|
70
|
-
];
|
|
71
|
-
/**
|
|
72
|
-
* Transforms a stream procedure definition into a pair of input and output streams.
|
|
73
|
-
* Input messages can be pushed into the input stream.
|
|
74
|
-
* This should only be used for testing.
|
|
75
|
-
* @template State - The type of the state object.
|
|
76
|
-
* @template I - The type of the input object.
|
|
77
|
-
* @template O - The type of the output object.
|
|
78
|
-
* @param {State} state - The state object.
|
|
79
|
-
* @param {Procedure<State, 'stream', I, O, E, null>} proc - The procedure to handle the stream.
|
|
80
|
-
* @param {Omit<ServiceContext, 'state'>} [extendedContext] - The extended context object.
|
|
81
|
-
* @returns Pair of input and output streams.
|
|
82
|
-
*/
|
|
83
|
-
export declare function asClientStreamWithInitialization<State extends object | unknown, I extends PayloadType, O extends PayloadType, E extends RiverError, Init extends PayloadType>(state: State, proc: Procedure<State, 'stream', I, O, E, Init>, init: Static<PayloadType>, extendedContext?: Omit<ServiceContext, 'state'>): [
|
|
84
|
-
Pushable<Static<I>>,
|
|
85
|
-
Pushable<Result<Static<O>, Static<E> | Static<typeof RiverUncaughtSchema>>>
|
|
86
|
-
];
|
|
87
|
-
/**
|
|
88
|
-
* Transforms a subscription procedure definition into a procedure that returns an output stream.
|
|
89
|
-
* Input messages can be pushed into the input stream.
|
|
90
|
-
* This should only be used for testing.
|
|
91
|
-
* @template State - The type of the state object.
|
|
92
|
-
* @template I - The type of the input object.
|
|
93
|
-
* @template O - The type of the output object.
|
|
94
|
-
* @param {State} state - The state object.
|
|
95
|
-
* @param {Procedure<State, 'stream', I, O, E, null>} proc - The procedure to handle the stream.
|
|
96
|
-
* @param {Omit<ServiceContext, 'state'>} [extendedContext] - The extended context object.
|
|
97
|
-
* @returns A function that when passed a message, returns the output stream.
|
|
98
|
-
*/
|
|
99
|
-
export declare function asClientSubscription<State extends object | unknown, I extends PayloadType, O extends PayloadType, E extends RiverError>(state: State, proc: Procedure<State, 'subscription', I, O, E, null>, extendedContext?: Omit<ServiceContext, 'state'>): (msg: Static<I>) => Promise<Pushable<Result<Static<O>, Static<E> | Static<typeof RiverUncaughtSchema>>>>;
|
|
100
|
-
/**
|
|
101
|
-
* Transforms an upload procedure definition into a procedure that returns an input stream.
|
|
102
|
-
* Input messages can be pushed into the input stream.
|
|
103
|
-
* This should only be used for testing.
|
|
104
|
-
* @template State - The type of the state object.
|
|
105
|
-
* @template I - The type of the input object.
|
|
106
|
-
* @template O - The type of the output object.
|
|
107
|
-
* @param {State} state - The state object.
|
|
108
|
-
* @param {Procedure<State, 'upload', I, O, E, null>} proc - The procedure to handle the stream.
|
|
109
|
-
* @param {Omit<ServiceContext, 'state'>} [extendedContext] - The extended context object.
|
|
110
|
-
* @returns A function that when passed a message, returns the output stream.
|
|
111
|
-
*/
|
|
112
|
-
export declare function asClientUpload<State extends object | unknown, I extends PayloadType, O extends PayloadType, E extends RiverError>(state: State, proc: Procedure<State, 'upload', I, O, E, null>, extendedContext?: Omit<ServiceContext, 'state'>): [
|
|
113
|
-
Pushable<Static<I>>,
|
|
114
|
-
Promise<Result<Static<O>, Static<E> | Static<typeof RiverUncaughtSchema>>>
|
|
115
|
-
];
|
|
116
|
-
/**
|
|
117
|
-
* Transforms an upload with initialization procedure definition into a procedure that returns an
|
|
118
|
-
* input stream.
|
|
119
|
-
* Input messages can be pushed into the input stream.
|
|
120
|
-
* This should only be used for testing.
|
|
121
|
-
* @template State - The type of the state object.
|
|
122
|
-
* @template Init - The type of the init object.
|
|
123
|
-
* @template I - The type of the input object.
|
|
124
|
-
* @template O - The type of the output object.
|
|
125
|
-
* @param {State} state - The state object.
|
|
126
|
-
* @param {Procedure<State, 'upload', I, O, E, Init>} proc - The procedure to handle the stream.
|
|
127
|
-
* @param {Omit<ServiceContext, 'state'>} [extendedContext] - The extended context object.
|
|
128
|
-
* @returns A function that when passed a message, returns the output stream.
|
|
129
|
-
*/
|
|
130
|
-
export declare function asClientUploadWithInitialization<State extends object | unknown, I extends PayloadType, O extends PayloadType, E extends RiverError, Init extends PayloadType>(state: State, proc: Procedure<State, 'upload', I, O, E, Init>, init: Static<Init>, extendedContext?: Omit<ServiceContext, 'state'>): [
|
|
131
|
-
Pushable<Static<I>>,
|
|
132
|
-
Promise<Result<Static<O>, Static<E> | Static<typeof RiverUncaughtSchema>>>
|
|
133
|
-
];
|
|
134
40
|
/**
|
|
135
41
|
* Converts a payload object to a transport message with reasonable defaults.
|
|
136
42
|
* This should only be used for testing.
|
|
@@ -150,4 +56,21 @@ export declare function createDummyTransportMessage(): OpaqueTransportMessage;
|
|
|
150
56
|
* @returns A promise that resolves to the next value from the iterator.
|
|
151
57
|
*/
|
|
152
58
|
export declare function iterNext<T>(iter: AsyncIterableIterator<T>): Promise<any>;
|
|
59
|
+
/**
|
|
60
|
+
* Waits for a message on the transport.
|
|
61
|
+
* @param {Transport} t - The transport to listen to.
|
|
62
|
+
* @param filter - An optional filter function to apply to the received messages.
|
|
63
|
+
* @returns A promise that resolves with the payload of the first message that passes the filter.
|
|
64
|
+
*/
|
|
65
|
+
export declare function waitForMessage(t: Transport<Connection>, filter?: (msg: OpaqueTransportMessage) => boolean, rejectMismatch?: boolean): Promise<unknown>;
|
|
66
|
+
export declare function asClientRpc<State extends object | unknown, I extends PayloadType, O extends PayloadType, E extends RiverError, Init extends PayloadType | null = null>(state: State, proc: Procedure<State, 'rpc', I, O, E, Init>, extendedContext?: Omit<ServiceContext, 'state'>): (msg: Static<I>) => Promise<Result<Static<O>, Static<E> | Static<typeof RiverUncaughtSchema>>>;
|
|
67
|
+
export declare function asClientStream<State extends object | unknown, I extends PayloadType, O extends PayloadType, E extends RiverError, Init extends PayloadType | null = null>(state: State, proc: Procedure<State, 'stream', I, O, E, Init>, init?: Init extends PayloadType ? Static<Init> : null, extendedContext?: Omit<ServiceContext, 'state'>): readonly [import("it-pushable").Pushable<Static<I>, void, unknown>, import("it-pushable").Pushable<Result<Static<O>, Static<E>>, void, unknown>];
|
|
68
|
+
export declare function asClientSubscription<State extends object | unknown, I extends PayloadType, O extends PayloadType, E extends RiverError>(state: State, proc: Procedure<State, 'subscription', I, O, E>, extendedContext?: Omit<ServiceContext, 'state'>): (msg: Static<I>) => Promise<import("it-pushable").Pushable<Result<Static<O>, Static<E>>, void, unknown>>;
|
|
69
|
+
export declare function asClientUpload<State extends object | unknown, I extends PayloadType, O extends PayloadType, E extends RiverError, Init extends PayloadType | null = null>(state: State, proc: Procedure<State, 'upload', I, O, E, Init>, init?: Init extends PayloadType ? Static<Init> : null, extendedContext?: Omit<ServiceContext, 'state'>): Promise<readonly [import("it-pushable").Pushable<Static<I>, void, unknown>, Promise<{
|
|
70
|
+
ok: boolean;
|
|
71
|
+
payload: {
|
|
72
|
+
code: string;
|
|
73
|
+
message: string;
|
|
74
|
+
};
|
|
75
|
+
} | Result<Static<O>, Static<E>>>]>;
|
|
153
76
|
//# sourceMappingURL=testHelpers.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"testHelpers.d.ts","sourceRoot":"","sources":["../../util/testHelpers.ts"],"names":[],"mappings":";AAAA,OAAO,SAAS,MAAM,eAAe,CAAC;AACtC,OAAO,EAAE,eAAe,EAAE,MAAM,IAAI,CAAC;AACrC,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,wBAAwB,EAAE,MAAM,8BAA8B,CAAC;AACxE,OAAO,
|
|
1
|
+
{"version":3,"file":"testHelpers.d.ts","sourceRoot":"","sources":["../../util/testHelpers.ts"],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AC,oJAsBhD;AAED,wBAAgB,oBAAoB,CAClC,KAAK,SAAS,MAAM,GAAG,OAAO,EAC9B,CAAC,SAAS,WAAW,EACrB,CAAC,SAAS,WAAW,EACrB,CAAC,SAAS,UAAU,EAEpB,KAAK,EAAE,KAAK,EACZ,IAAI,EAAE,SAAS,CAAC,KAAK,EAAE,cAAc,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,EAC/C,eAAe,CAAC,EAAE,IAAI,CAAC,cAAc,EAAE,OAAO,CAAC,SAM5B,OAAO,CAAC,CAAC,0FAQ7B;AAED,wBAAsB,cAAc,CAClC,KAAK,SAAS,MAAM,GAAG,OAAO,EAC9B,CAAC,SAAS,WAAW,EACrB,CAAC,SAAS,WAAW,EACrB,CAAC,SAAS,UAAU,EACpB,IAAI,SAAS,WAAW,GAAG,IAAI,GAAG,IAAI,EAEtC,KAAK,EAAE,KAAK,EACZ,IAAI,EAAE,SAAS,CAAC,KAAK,EAAE,QAAQ,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,IAAI,CAAC,EAC/C,IAAI,CAAC,EAAE,IAAI,SAAS,WAAW,GAAG,MAAM,CAAC,IAAI,CAAC,GAAG,IAAI,EACrD,eAAe,CAAC,EAAE,IAAI,CAAC,cAAc,EAAE,OAAO,CAAC;;;;;;oCAgBhD"}
|
package/dist/util/testHelpers.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import WebSocket from 'isomorphic-ws';
|
|
2
2
|
import { WebSocketServer } from 'ws';
|
|
3
3
|
import { WebSocketClientTransport } from '../transport/impls/ws/client';
|
|
4
|
-
import { msg,
|
|
4
|
+
import { msg, } from '../transport';
|
|
5
5
|
import { pushable } from 'it-pushable';
|
|
6
|
-
import { Err, UNCAUGHT_ERROR, } from '../router/result';
|
|
7
6
|
import { WebSocketServerTransport } from '../transport/impls/ws/server';
|
|
7
|
+
import { UNCAUGHT_ERROR, } from '../router';
|
|
8
8
|
/**
|
|
9
9
|
* Creates a WebSocket server instance using the provided HTTP server.
|
|
10
10
|
* Only used as helper for testing.
|
|
@@ -59,276 +59,121 @@ export function createWsTransports(port, wss, codec) {
|
|
|
59
59
|
];
|
|
60
60
|
}
|
|
61
61
|
/**
|
|
62
|
-
*
|
|
62
|
+
* Converts a payload object to a transport message with reasonable defaults.
|
|
63
63
|
* This should only be used for testing.
|
|
64
|
-
* @
|
|
65
|
-
* @
|
|
66
|
-
* @
|
|
67
|
-
* @param {State} state - The state object.
|
|
68
|
-
* @param {Procedure<State, 'rpc', I, O, E, null>} proc - The RPC procedure to invoke.
|
|
69
|
-
* @param {Omit<ServiceContext, 'state'>} [extendedContext] - Optional extended context.
|
|
70
|
-
* @returns A function that can be used to invoke the RPC procedure.
|
|
64
|
+
* @param payload - The payload object to be converted.
|
|
65
|
+
* @param streamId - The optional stream ID.
|
|
66
|
+
* @returns The transport message.
|
|
71
67
|
*/
|
|
72
|
-
export function
|
|
73
|
-
return (
|
|
74
|
-
.handler({ ...extendedContext, state }, payloadToTransportMessage(msg))
|
|
75
|
-
.then((res) => res.payload)
|
|
76
|
-
.catch((err) => {
|
|
77
|
-
const errorMsg = err instanceof Error ? err.message : `[coerced to error] ${err}`;
|
|
78
|
-
return Err({
|
|
79
|
-
code: UNCAUGHT_ERROR,
|
|
80
|
-
message: errorMsg,
|
|
81
|
-
});
|
|
82
|
-
});
|
|
68
|
+
export function payloadToTransportMessage(payload, streamId, from = 'client', to = 'SERVER') {
|
|
69
|
+
return msg(from, to, streamId ?? 'stream', payload, 'service', 'procedure');
|
|
83
70
|
}
|
|
84
71
|
/**
|
|
85
|
-
*
|
|
86
|
-
*
|
|
87
|
-
* This should only be used for testing.
|
|
88
|
-
* @template State - The type of the state object.
|
|
89
|
-
* @template I - The type of the input object.
|
|
90
|
-
* @template O - The type of the output object.
|
|
91
|
-
* @param {State} state - The state object.
|
|
92
|
-
* @param {Procedure<State, 'stream', I, O, E, null>} proc - The procedure to handle the stream.
|
|
93
|
-
* @param {Omit<ServiceContext, 'state'>} [extendedContext] - The extended context object.
|
|
94
|
-
* @returns Pair of input and output streams.
|
|
72
|
+
* Creates a dummy opaque transport message for testing purposes.
|
|
73
|
+
* @returns The created opaque transport message.
|
|
95
74
|
*/
|
|
96
|
-
export function
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
});
|
|
101
|
-
const transportInput = pushable({
|
|
102
|
-
objectMode: true,
|
|
103
|
-
});
|
|
104
|
-
const transportOutput = pushable({
|
|
105
|
-
objectMode: true,
|
|
75
|
+
export function createDummyTransportMessage() {
|
|
76
|
+
return payloadToTransportMessage({
|
|
77
|
+
msg: 'cool',
|
|
78
|
+
test: Math.random(),
|
|
106
79
|
});
|
|
107
|
-
// wrapping in transport
|
|
108
|
-
(async () => {
|
|
109
|
-
for await (const rawIn of rawInput) {
|
|
110
|
-
transportInput.push(payloadToTransportMessage(rawIn));
|
|
111
|
-
}
|
|
112
|
-
transportInput.end();
|
|
113
|
-
})();
|
|
114
|
-
// unwrap from transport
|
|
115
|
-
(async () => {
|
|
116
|
-
for await (const transportRes of transportOutput) {
|
|
117
|
-
rawOutput.push(transportRes.payload);
|
|
118
|
-
}
|
|
119
|
-
rawOutput.end();
|
|
120
|
-
})();
|
|
121
|
-
// handle
|
|
122
|
-
(async () => {
|
|
123
|
-
try {
|
|
124
|
-
await proc.handler({ ...extendedContext, state }, transportInput, transportOutput);
|
|
125
|
-
}
|
|
126
|
-
catch (err) {
|
|
127
|
-
const errorMsg = err instanceof Error ? err.message : `[coerced to error] ${err}`;
|
|
128
|
-
transportOutput.push(reply(payloadToTransportMessage({}), Err({
|
|
129
|
-
code: UNCAUGHT_ERROR,
|
|
130
|
-
message: errorMsg,
|
|
131
|
-
})));
|
|
132
|
-
}
|
|
133
|
-
transportOutput.end();
|
|
134
|
-
})();
|
|
135
|
-
return [rawInput, rawOutput];
|
|
136
80
|
}
|
|
137
81
|
/**
|
|
138
|
-
*
|
|
139
|
-
*
|
|
140
|
-
*
|
|
141
|
-
* @template State - The type of the state object.
|
|
142
|
-
* @template I - The type of the input object.
|
|
143
|
-
* @template O - The type of the output object.
|
|
144
|
-
* @param {State} state - The state object.
|
|
145
|
-
* @param {Procedure<State, 'stream', I, O, E, null>} proc - The procedure to handle the stream.
|
|
146
|
-
* @param {Omit<ServiceContext, 'state'>} [extendedContext] - The extended context object.
|
|
147
|
-
* @returns Pair of input and output streams.
|
|
82
|
+
* Retrieves the next value from an async iterable iterator.
|
|
83
|
+
* @param iter The async iterable iterator.
|
|
84
|
+
* @returns A promise that resolves to the next value from the iterator.
|
|
148
85
|
*/
|
|
149
|
-
export function
|
|
150
|
-
|
|
151
|
-
const rawOutput = pushable({
|
|
152
|
-
objectMode: true,
|
|
153
|
-
});
|
|
154
|
-
const transportInput = pushable({
|
|
155
|
-
objectMode: true,
|
|
156
|
-
});
|
|
157
|
-
const transportOutput = pushable({
|
|
158
|
-
objectMode: true,
|
|
159
|
-
});
|
|
160
|
-
// wrapping in transport
|
|
161
|
-
(async () => {
|
|
162
|
-
for await (const rawIn of rawInput) {
|
|
163
|
-
transportInput.push(payloadToTransportMessage(rawIn));
|
|
164
|
-
}
|
|
165
|
-
transportInput.end();
|
|
166
|
-
})();
|
|
167
|
-
// unwrap from transport
|
|
168
|
-
(async () => {
|
|
169
|
-
for await (const transportRes of transportOutput) {
|
|
170
|
-
rawOutput.push(transportRes.payload);
|
|
171
|
-
}
|
|
172
|
-
rawOutput.end();
|
|
173
|
-
})();
|
|
174
|
-
// handle
|
|
175
|
-
(async () => {
|
|
176
|
-
try {
|
|
177
|
-
await proc.handler({ ...extendedContext, state }, payloadToTransportMessage(init), transportInput, transportOutput);
|
|
178
|
-
}
|
|
179
|
-
catch (err) {
|
|
180
|
-
const errorMsg = err instanceof Error ? err.message : `[coerced to error] ${err}`;
|
|
181
|
-
transportOutput.push(reply(payloadToTransportMessage({}), Err({
|
|
182
|
-
code: UNCAUGHT_ERROR,
|
|
183
|
-
message: errorMsg,
|
|
184
|
-
})));
|
|
185
|
-
}
|
|
186
|
-
transportOutput.end();
|
|
187
|
-
})();
|
|
188
|
-
return [rawInput, rawOutput];
|
|
86
|
+
export async function iterNext(iter) {
|
|
87
|
+
return await iter.next().then((res) => res.value);
|
|
189
88
|
}
|
|
190
89
|
/**
|
|
191
|
-
*
|
|
192
|
-
*
|
|
193
|
-
*
|
|
194
|
-
* @
|
|
195
|
-
* @template I - The type of the input object.
|
|
196
|
-
* @template O - The type of the output object.
|
|
197
|
-
* @param {State} state - The state object.
|
|
198
|
-
* @param {Procedure<State, 'stream', I, O, E, null>} proc - The procedure to handle the stream.
|
|
199
|
-
* @param {Omit<ServiceContext, 'state'>} [extendedContext] - The extended context object.
|
|
200
|
-
* @returns A function that when passed a message, returns the output stream.
|
|
90
|
+
* Waits for a message on the transport.
|
|
91
|
+
* @param {Transport} t - The transport to listen to.
|
|
92
|
+
* @param filter - An optional filter function to apply to the received messages.
|
|
93
|
+
* @returns A promise that resolves with the payload of the first message that passes the filter.
|
|
201
94
|
*/
|
|
202
|
-
export function
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
const transportOutput = pushable({
|
|
207
|
-
objectMode: true,
|
|
208
|
-
});
|
|
209
|
-
// unwrap from transport
|
|
210
|
-
(async () => {
|
|
211
|
-
for await (const transportRes of transportOutput) {
|
|
212
|
-
rawOutput.push(transportRes.payload);
|
|
95
|
+
export async function waitForMessage(t, filter, rejectMismatch) {
|
|
96
|
+
return new Promise((resolve, reject) => {
|
|
97
|
+
function cleanup() {
|
|
98
|
+
t.removeEventListener('message', onMessage);
|
|
213
99
|
}
|
|
214
|
-
|
|
215
|
-
|
|
100
|
+
function onMessage(msg) {
|
|
101
|
+
if (!filter || filter?.(msg)) {
|
|
102
|
+
cleanup();
|
|
103
|
+
resolve(msg.payload);
|
|
104
|
+
}
|
|
105
|
+
else if (rejectMismatch) {
|
|
106
|
+
reject(new Error('message didnt match the filter'));
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
t.addEventListener('message', onMessage);
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
function catchProcError(err) {
|
|
113
|
+
const errorMsg = err instanceof Error ? err.message : `[coerced to error] ${err}`;
|
|
114
|
+
return {
|
|
115
|
+
ok: false,
|
|
116
|
+
payload: {
|
|
117
|
+
code: UNCAUGHT_ERROR,
|
|
118
|
+
message: errorMsg,
|
|
119
|
+
},
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
export function asClientRpc(state, proc, extendedContext) {
|
|
216
123
|
return async (msg) => {
|
|
217
|
-
proc
|
|
218
|
-
.handler({ ...extendedContext, state },
|
|
219
|
-
.catch(
|
|
220
|
-
const errorMsg = err instanceof Error ? err.message : `[coerced to error] ${err}`;
|
|
221
|
-
return Err({
|
|
222
|
-
code: UNCAUGHT_ERROR,
|
|
223
|
-
message: errorMsg,
|
|
224
|
-
});
|
|
225
|
-
});
|
|
226
|
-
return rawOutput;
|
|
124
|
+
return await proc
|
|
125
|
+
.handler({ ...extendedContext, state }, msg)
|
|
126
|
+
.catch(catchProcError);
|
|
227
127
|
};
|
|
228
128
|
}
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
* This should only be used for testing.
|
|
233
|
-
* @template State - The type of the state object.
|
|
234
|
-
* @template I - The type of the input object.
|
|
235
|
-
* @template O - The type of the output object.
|
|
236
|
-
* @param {State} state - The state object.
|
|
237
|
-
* @param {Procedure<State, 'upload', I, O, E, null>} proc - The procedure to handle the stream.
|
|
238
|
-
* @param {Omit<ServiceContext, 'state'>} [extendedContext] - The extended context object.
|
|
239
|
-
* @returns A function that when passed a message, returns the output stream.
|
|
240
|
-
*/
|
|
241
|
-
export function asClientUpload(state, proc, extendedContext) {
|
|
242
|
-
const rawInput = pushable({ objectMode: true });
|
|
243
|
-
const transportInput = pushable({
|
|
129
|
+
export function asClientStream(state, proc, init, extendedContext) {
|
|
130
|
+
const input = pushable({ objectMode: true });
|
|
131
|
+
const output = pushable({
|
|
244
132
|
objectMode: true,
|
|
245
133
|
});
|
|
246
|
-
// wrapping in transport
|
|
247
134
|
(async () => {
|
|
248
|
-
|
|
249
|
-
|
|
135
|
+
if (init) {
|
|
136
|
+
const _proc = proc;
|
|
137
|
+
await _proc
|
|
138
|
+
.handler({ ...extendedContext, state }, init, input, output)
|
|
139
|
+
.catch((err) => output.push(catchProcError(err)));
|
|
250
140
|
}
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
.handler({ ...extendedContext, state }, transportInput)
|
|
257
|
-
.then((res) => res.payload)
|
|
258
|
-
.catch((err) => {
|
|
259
|
-
const errorMsg = err instanceof Error ? err.message : `[coerced to error] ${err}`;
|
|
260
|
-
return Err({
|
|
261
|
-
code: UNCAUGHT_ERROR,
|
|
262
|
-
message: errorMsg,
|
|
263
|
-
});
|
|
264
|
-
}),
|
|
265
|
-
];
|
|
266
|
-
}
|
|
267
|
-
/**
|
|
268
|
-
* Transforms an upload with initialization procedure definition into a procedure that returns an
|
|
269
|
-
* input stream.
|
|
270
|
-
* Input messages can be pushed into the input stream.
|
|
271
|
-
* This should only be used for testing.
|
|
272
|
-
* @template State - The type of the state object.
|
|
273
|
-
* @template Init - The type of the init object.
|
|
274
|
-
* @template I - The type of the input object.
|
|
275
|
-
* @template O - The type of the output object.
|
|
276
|
-
* @param {State} state - The state object.
|
|
277
|
-
* @param {Procedure<State, 'upload', I, O, E, Init>} proc - The procedure to handle the stream.
|
|
278
|
-
* @param {Omit<ServiceContext, 'state'>} [extendedContext] - The extended context object.
|
|
279
|
-
* @returns A function that when passed a message, returns the output stream.
|
|
280
|
-
*/
|
|
281
|
-
export function asClientUploadWithInitialization(state, proc, init, extendedContext) {
|
|
282
|
-
const rawInput = pushable({ objectMode: true });
|
|
283
|
-
const transportInput = pushable({
|
|
284
|
-
objectMode: true,
|
|
285
|
-
});
|
|
286
|
-
// wrapping in transport
|
|
287
|
-
(async () => {
|
|
288
|
-
for await (const rawIn of rawInput) {
|
|
289
|
-
transportInput.push(payloadToTransportMessage(rawIn));
|
|
141
|
+
else {
|
|
142
|
+
const _proc = proc;
|
|
143
|
+
await _proc
|
|
144
|
+
.handler({ ...extendedContext, state }, input, output)
|
|
145
|
+
.catch((err) => output.push(catchProcError(err)));
|
|
290
146
|
}
|
|
291
|
-
transportInput.end();
|
|
292
147
|
})();
|
|
293
|
-
return [
|
|
294
|
-
rawInput,
|
|
295
|
-
proc
|
|
296
|
-
.handler({ ...extendedContext, state }, payloadToTransportMessage(init), transportInput)
|
|
297
|
-
.then((res) => res.payload)
|
|
298
|
-
.catch((err) => {
|
|
299
|
-
const errorMsg = err instanceof Error ? err.message : `[coerced to error] ${err}`;
|
|
300
|
-
return Err({
|
|
301
|
-
code: UNCAUGHT_ERROR,
|
|
302
|
-
message: errorMsg,
|
|
303
|
-
});
|
|
304
|
-
}),
|
|
305
|
-
];
|
|
306
|
-
}
|
|
307
|
-
/**
|
|
308
|
-
* Converts a payload object to a transport message with reasonable defaults.
|
|
309
|
-
* This should only be used for testing.
|
|
310
|
-
* @param payload - The payload object to be converted.
|
|
311
|
-
* @param streamId - The optional stream ID.
|
|
312
|
-
* @returns The transport message.
|
|
313
|
-
*/
|
|
314
|
-
export function payloadToTransportMessage(payload, streamId, from = 'client', to = 'SERVER') {
|
|
315
|
-
return msg(from, to, streamId ?? 'stream', payload, 'service', 'procedure');
|
|
148
|
+
return [input, output];
|
|
316
149
|
}
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
*/
|
|
321
|
-
export function createDummyTransportMessage() {
|
|
322
|
-
return payloadToTransportMessage({
|
|
323
|
-
msg: 'cool',
|
|
324
|
-
test: Math.random(),
|
|
150
|
+
export function asClientSubscription(state, proc, extendedContext) {
|
|
151
|
+
const output = pushable({
|
|
152
|
+
objectMode: true,
|
|
325
153
|
});
|
|
154
|
+
return async (msg) => {
|
|
155
|
+
(async () => {
|
|
156
|
+
return await proc
|
|
157
|
+
.handler({ ...extendedContext, state }, msg, output)
|
|
158
|
+
.catch((err) => output.push(catchProcError(err)));
|
|
159
|
+
})();
|
|
160
|
+
return output;
|
|
161
|
+
};
|
|
326
162
|
}
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
163
|
+
export async function asClientUpload(state, proc, init, extendedContext) {
|
|
164
|
+
const input = pushable({ objectMode: true });
|
|
165
|
+
if (init) {
|
|
166
|
+
const _proc = proc;
|
|
167
|
+
const result = _proc
|
|
168
|
+
.handler({ ...extendedContext, state }, init, input)
|
|
169
|
+
.catch(catchProcError);
|
|
170
|
+
return [input, result];
|
|
171
|
+
}
|
|
172
|
+
else {
|
|
173
|
+
const _proc = proc;
|
|
174
|
+
const result = _proc
|
|
175
|
+
.handler({ ...extendedContext, state }, input)
|
|
176
|
+
.catch(catchProcError);
|
|
177
|
+
return [input, result];
|
|
178
|
+
}
|
|
334
179
|
}
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@replit/river",
|
|
3
3
|
"sideEffects": false,
|
|
4
4
|
"description": "It's like tRPC but... with JSON Schema Support, duplex streaming and support for service multiplexing. Transport agnostic!",
|
|
5
|
-
"version": "0.
|
|
5
|
+
"version": "0.10.0",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"exports": {
|
|
8
8
|
".": "./dist/router/index.js",
|
|
@@ -33,6 +33,16 @@
|
|
|
33
33
|
"typescript": "^5.2.2",
|
|
34
34
|
"vitest": "^1.0.1"
|
|
35
35
|
},
|
|
36
|
+
"scripts": {
|
|
37
|
+
"check": "tsc --noEmit && npx prettier . --check",
|
|
38
|
+
"format": "npx prettier . --write",
|
|
39
|
+
"build": "rm -rf ./dist && tsc",
|
|
40
|
+
"prepack": "npm run build",
|
|
41
|
+
"release": "npm publish --access public",
|
|
42
|
+
"test:ui": "echo \"remember to go to /__vitest__ in the webview\" && vitest --ui --api.host 0.0.0.0 --api.port 3000",
|
|
43
|
+
"test": "vitest --test-timeout=500",
|
|
44
|
+
"bench": "vitest bench"
|
|
45
|
+
},
|
|
36
46
|
"engines": {
|
|
37
47
|
"node": ">=16"
|
|
38
48
|
},
|
|
@@ -42,14 +52,5 @@
|
|
|
42
52
|
"jsonschema"
|
|
43
53
|
],
|
|
44
54
|
"author": "Jacky Zhao",
|
|
45
|
-
"license": "MIT"
|
|
46
|
-
|
|
47
|
-
"check": "tsc --noEmit && npx prettier . --check",
|
|
48
|
-
"format": "npx prettier . --write",
|
|
49
|
-
"build": "rm -rf ./dist && tsc",
|
|
50
|
-
"release": "npm publish --access public",
|
|
51
|
-
"test:ui": "echo \"remember to go to /__vitest__ in the webview\" && vitest --ui --api.host 0.0.0.0 --api.port 3000",
|
|
52
|
-
"test": "vitest --test-timeout=500",
|
|
53
|
-
"bench": "vitest bench"
|
|
54
|
-
}
|
|
55
|
-
}
|
|
55
|
+
"license": "MIT"
|
|
56
|
+
}
|