@replit/river 0.9.3 → 0.10.1
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/{router/builder.d.ts → builder-3c4485f0.d.ts} +82 -28
- package/dist/chunk-7WJ6YLE5.js +683 -0
- package/dist/chunk-AJQU4AZG.js +284 -0
- package/dist/chunk-ORAG7IAU.js +0 -0
- package/dist/chunk-PC65ZFWJ.js +29 -0
- package/dist/chunk-R6H2BIMC.js +49 -0
- package/dist/chunk-RGMHF6PF.js +65 -0
- package/dist/chunk-SLUSVGQH.js +30 -0
- package/dist/chunk-UU2Z7LDR.js +113 -0
- package/dist/chunk-WVT5QXMZ.js +20 -0
- package/dist/chunk-ZE4MX7DF.js +75 -0
- package/dist/codec/index.cjs +94 -0
- package/dist/codec/index.d.cts +15 -0
- package/dist/codec/index.d.ts +15 -4
- package/dist/codec/index.js +10 -2
- package/dist/connection-8e19874c.d.ts +11 -0
- package/dist/connection-f7688cc1.d.ts +11 -0
- package/dist/logging/index.cjs +56 -0
- package/dist/logging/index.d.cts +28 -0
- package/dist/logging/index.d.ts +6 -6
- package/dist/logging/index.js +9 -40
- package/dist/router/index.cjs +770 -0
- package/dist/router/index.d.cts +114 -0
- package/dist/router/index.d.ts +114 -10
- package/dist/router/index.js +24 -4
- package/dist/transport/impls/ws/client.cjs +505 -0
- package/dist/transport/impls/ws/client.d.cts +42 -0
- package/dist/transport/impls/ws/client.d.ts +9 -12
- package/dist/transport/impls/ws/client.js +10 -101
- package/dist/transport/impls/ws/server.cjs +457 -0
- package/dist/transport/impls/ws/server.d.cts +21 -0
- package/dist/transport/impls/ws/server.d.ts +14 -10
- package/dist/transport/impls/ws/server.js +11 -47
- package/dist/transport/index.cjs +362 -0
- package/dist/transport/{transport.d.ts → index.d.cts} +119 -7
- package/dist/transport/index.d.ts +273 -13
- package/dist/transport/index.js +20 -23
- package/dist/{codec/types.d.ts → types-3e5768ec.d.ts} +3 -2
- package/dist/util/testHelpers.cjs +731 -0
- package/dist/util/testHelpers.d.cts +79 -0
- package/dist/util/testHelpers.d.ts +34 -108
- package/dist/util/testHelpers.js +137 -320
- package/package.json +52 -23
- package/dist/__tests__/bandwidth.bench.d.ts +0 -2
- package/dist/__tests__/bandwidth.bench.d.ts.map +0 -1
- package/dist/__tests__/bandwidth.bench.js +0 -90
- package/dist/__tests__/e2e.test.d.ts +0 -2
- package/dist/__tests__/e2e.test.d.ts.map +0 -1
- package/dist/__tests__/e2e.test.js +0 -316
- package/dist/__tests__/fixtures/cleanup.d.ts +0 -12
- package/dist/__tests__/fixtures/cleanup.d.ts.map +0 -1
- package/dist/__tests__/fixtures/cleanup.js +0 -39
- package/dist/__tests__/fixtures/largePayload.json +0 -33
- package/dist/__tests__/fixtures/observable.d.ts +0 -26
- package/dist/__tests__/fixtures/observable.d.ts.map +0 -1
- package/dist/__tests__/fixtures/observable.js +0 -38
- package/dist/__tests__/fixtures/observable.test.d.ts +0 -2
- package/dist/__tests__/fixtures/observable.test.d.ts.map +0 -1
- package/dist/__tests__/fixtures/observable.test.js +0 -39
- package/dist/__tests__/fixtures/services.d.ts +0 -288
- package/dist/__tests__/fixtures/services.d.ts.map +0 -1
- package/dist/__tests__/fixtures/services.js +0 -224
- package/dist/__tests__/handler.test.d.ts +0 -2
- package/dist/__tests__/handler.test.d.ts.map +0 -1
- package/dist/__tests__/handler.test.js +0 -121
- package/dist/__tests__/invariants.test.d.ts +0 -2
- package/dist/__tests__/invariants.test.d.ts.map +0 -1
- package/dist/__tests__/invariants.test.js +0 -138
- package/dist/__tests__/serialize.test.d.ts +0 -2
- package/dist/__tests__/serialize.test.d.ts.map +0 -1
- package/dist/__tests__/serialize.test.js +0 -208
- package/dist/__tests__/typescript-stress.test.d.ts +0 -1583
- package/dist/__tests__/typescript-stress.test.d.ts.map +0 -1
- package/dist/__tests__/typescript-stress.test.js +0 -123
- package/dist/codec/binary.d.ts +0 -7
- package/dist/codec/binary.d.ts.map +0 -1
- package/dist/codec/binary.js +0 -20
- package/dist/codec/codec.test.d.ts +0 -5
- package/dist/codec/codec.test.d.ts.map +0 -1
- package/dist/codec/codec.test.js +0 -41
- package/dist/codec/index.d.ts.map +0 -1
- package/dist/codec/json.d.ts +0 -7
- package/dist/codec/json.d.ts.map +0 -1
- package/dist/codec/json.js +0 -51
- package/dist/codec/types.d.ts.map +0 -1
- package/dist/codec/types.js +0 -1
- package/dist/logging/index.d.ts.map +0 -1
- package/dist/router/builder.d.ts.map +0 -1
- package/dist/router/builder.js +0 -91
- package/dist/router/client.d.ts +0 -68
- package/dist/router/client.d.ts.map +0 -1
- package/dist/router/client.js +0 -159
- package/dist/router/context.d.ts +0 -30
- package/dist/router/context.d.ts.map +0 -1
- package/dist/router/context.js +0 -1
- package/dist/router/index.d.ts.map +0 -1
- package/dist/router/result.d.ts +0 -25
- package/dist/router/result.d.ts.map +0 -1
- package/dist/router/result.js +0 -18
- package/dist/router/server.d.ts +0 -39
- package/dist/router/server.d.ts.map +0 -1
- package/dist/router/server.js +0 -217
- package/dist/transport/events.d.ts +0 -19
- package/dist/transport/events.d.ts.map +0 -1
- package/dist/transport/events.js +0 -26
- package/dist/transport/impls/stdio/stdio.d.ts +0 -33
- package/dist/transport/impls/stdio/stdio.d.ts.map +0 -1
- package/dist/transport/impls/stdio/stdio.js +0 -75
- package/dist/transport/impls/stdio/stdio.test.d.ts +0 -2
- package/dist/transport/impls/stdio/stdio.test.d.ts.map +0 -1
- package/dist/transport/impls/stdio/stdio.test.js +0 -25
- package/dist/transport/impls/ws/client.d.ts.map +0 -1
- package/dist/transport/impls/ws/connection.d.ts +0 -11
- package/dist/transport/impls/ws/connection.d.ts.map +0 -1
- package/dist/transport/impls/ws/connection.js +0 -23
- package/dist/transport/impls/ws/server.d.ts.map +0 -1
- package/dist/transport/impls/ws/ws.test.d.ts +0 -2
- package/dist/transport/impls/ws/ws.test.d.ts.map +0 -1
- package/dist/transport/impls/ws/ws.test.js +0 -117
- package/dist/transport/index.d.ts.map +0 -1
- package/dist/transport/message.d.ts +0 -143
- package/dist/transport/message.d.ts.map +0 -1
- package/dist/transport/message.js +0 -113
- package/dist/transport/message.test.d.ts +0 -2
- package/dist/transport/message.test.d.ts.map +0 -1
- package/dist/transport/message.test.js +0 -52
- package/dist/transport/transport.d.ts.map +0 -1
- package/dist/transport/transport.js +0 -281
- package/dist/util/testHelpers.d.ts.map +0 -1
package/dist/util/testHelpers.js
CHANGED
|
@@ -1,334 +1,151 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
1
|
+
import {
|
|
2
|
+
UNCAUGHT_ERROR
|
|
3
|
+
} from "../chunk-7WJ6YLE5.js";
|
|
4
|
+
import "../chunk-ORAG7IAU.js";
|
|
5
|
+
import {
|
|
6
|
+
WebSocketClientTransport
|
|
7
|
+
} from "../chunk-UU2Z7LDR.js";
|
|
8
|
+
import {
|
|
9
|
+
WebSocketServerTransport
|
|
10
|
+
} from "../chunk-RGMHF6PF.js";
|
|
11
|
+
import "../chunk-WVT5QXMZ.js";
|
|
12
|
+
import "../chunk-PC65ZFWJ.js";
|
|
13
|
+
import "../chunk-R6H2BIMC.js";
|
|
14
|
+
import "../chunk-AJQU4AZG.js";
|
|
15
|
+
import {
|
|
16
|
+
msg
|
|
17
|
+
} from "../chunk-ZE4MX7DF.js";
|
|
18
|
+
import "../chunk-SLUSVGQH.js";
|
|
19
|
+
|
|
20
|
+
// util/testHelpers.ts
|
|
21
|
+
import WebSocket from "isomorphic-ws";
|
|
22
|
+
import { WebSocketServer } from "ws";
|
|
23
|
+
import { pushable } from "it-pushable";
|
|
24
|
+
async function createWebSocketServer(server) {
|
|
25
|
+
return new WebSocketServer({ server });
|
|
16
26
|
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
server.listen(() => {
|
|
27
|
-
const addr = server.address();
|
|
28
|
-
if (typeof addr === 'object' && addr) {
|
|
29
|
-
resolve(addr.port);
|
|
30
|
-
}
|
|
31
|
-
else {
|
|
32
|
-
reject(new Error("couldn't find a port to allocate"));
|
|
33
|
-
}
|
|
34
|
-
});
|
|
27
|
+
async function onServerReady(server) {
|
|
28
|
+
return new Promise((resolve, reject) => {
|
|
29
|
+
server.listen(() => {
|
|
30
|
+
const addr = server.address();
|
|
31
|
+
if (typeof addr === "object" && addr) {
|
|
32
|
+
resolve(addr.port);
|
|
33
|
+
} else {
|
|
34
|
+
reject(new Error("couldn't find a port to allocate"));
|
|
35
|
+
}
|
|
35
36
|
});
|
|
37
|
+
});
|
|
36
38
|
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
* @returns A Promise that resolves to a WebSocket instance.
|
|
42
|
-
*/
|
|
43
|
-
export async function createLocalWebSocketClient(port) {
|
|
44
|
-
const sock = new WebSocket(`ws://localhost:${port}`);
|
|
45
|
-
sock.binaryType = 'arraybuffer';
|
|
46
|
-
return sock;
|
|
39
|
+
async function createLocalWebSocketClient(port) {
|
|
40
|
+
const sock = new WebSocket(`ws://localhost:${port}`);
|
|
41
|
+
sock.binaryType = "arraybuffer";
|
|
42
|
+
return sock;
|
|
47
43
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
];
|
|
44
|
+
function createWsTransports(port, wss, codec) {
|
|
45
|
+
const options = codec ? { codec } : void 0;
|
|
46
|
+
return [
|
|
47
|
+
new WebSocketClientTransport(
|
|
48
|
+
() => createLocalWebSocketClient(port),
|
|
49
|
+
"client",
|
|
50
|
+
"SERVER",
|
|
51
|
+
options
|
|
52
|
+
),
|
|
53
|
+
new WebSocketServerTransport(wss, "SERVER", options)
|
|
54
|
+
];
|
|
60
55
|
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
* This should only be used for testing.
|
|
64
|
-
* @template State - The type of the state object.
|
|
65
|
-
* @template I - The type of the input message payload.
|
|
66
|
-
* @template O - The type of the output message payload.
|
|
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.
|
|
71
|
-
*/
|
|
72
|
-
export function asClientRpc(state, proc, extendedContext) {
|
|
73
|
-
return (msg) => proc
|
|
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
|
-
});
|
|
56
|
+
function payloadToTransportMessage(payload, streamId, from = "client", to = "SERVER") {
|
|
57
|
+
return msg(from, to, streamId ?? "stream", payload, "service", "procedure");
|
|
83
58
|
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
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.
|
|
95
|
-
*/
|
|
96
|
-
export function asClientStream(state, proc, extendedContext) {
|
|
97
|
-
const rawInput = pushable({ objectMode: true });
|
|
98
|
-
const rawOutput = pushable({
|
|
99
|
-
objectMode: true,
|
|
100
|
-
});
|
|
101
|
-
const transportInput = pushable({
|
|
102
|
-
objectMode: true,
|
|
103
|
-
});
|
|
104
|
-
const transportOutput = pushable({
|
|
105
|
-
objectMode: true,
|
|
106
|
-
});
|
|
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];
|
|
59
|
+
function createDummyTransportMessage() {
|
|
60
|
+
return payloadToTransportMessage({
|
|
61
|
+
msg: "cool",
|
|
62
|
+
test: Math.random()
|
|
63
|
+
});
|
|
136
64
|
}
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
* Input messages can be pushed into the input stream.
|
|
140
|
-
* This should only be used for testing.
|
|
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.
|
|
148
|
-
*/
|
|
149
|
-
export function asClientStreamWithInitialization(state, proc, init, extendedContext) {
|
|
150
|
-
const rawInput = pushable({ objectMode: true });
|
|
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];
|
|
65
|
+
async function iterNext(iter) {
|
|
66
|
+
return await iter.next().then((res) => res.value);
|
|
189
67
|
}
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
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);
|
|
213
|
-
}
|
|
214
|
-
rawOutput.end();
|
|
215
|
-
})();
|
|
216
|
-
return async (msg) => {
|
|
217
|
-
proc
|
|
218
|
-
.handler({ ...extendedContext, state }, payloadToTransportMessage(msg), transportOutput)
|
|
219
|
-
.catch((err) => {
|
|
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;
|
|
227
|
-
};
|
|
68
|
+
async function waitForMessage(t, filter, rejectMismatch) {
|
|
69
|
+
return new Promise((resolve, reject) => {
|
|
70
|
+
function cleanup() {
|
|
71
|
+
t.removeEventListener("message", onMessage);
|
|
72
|
+
}
|
|
73
|
+
function onMessage(msg2) {
|
|
74
|
+
if (!filter || filter?.(msg2)) {
|
|
75
|
+
cleanup();
|
|
76
|
+
resolve(msg2.payload);
|
|
77
|
+
} else if (rejectMismatch) {
|
|
78
|
+
reject(new Error("message didnt match the filter"));
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
t.addEventListener("message", onMessage);
|
|
82
|
+
});
|
|
228
83
|
}
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
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({
|
|
244
|
-
objectMode: true,
|
|
245
|
-
});
|
|
246
|
-
// wrapping in transport
|
|
247
|
-
(async () => {
|
|
248
|
-
for await (const rawIn of rawInput) {
|
|
249
|
-
transportInput.push(payloadToTransportMessage(rawIn));
|
|
250
|
-
}
|
|
251
|
-
transportInput.end();
|
|
252
|
-
})();
|
|
253
|
-
return [
|
|
254
|
-
rawInput,
|
|
255
|
-
proc
|
|
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
|
-
];
|
|
84
|
+
function catchProcError(err) {
|
|
85
|
+
const errorMsg = err instanceof Error ? err.message : `[coerced to error] ${err}`;
|
|
86
|
+
return {
|
|
87
|
+
ok: false,
|
|
88
|
+
payload: {
|
|
89
|
+
code: UNCAUGHT_ERROR,
|
|
90
|
+
message: errorMsg
|
|
91
|
+
}
|
|
92
|
+
};
|
|
266
93
|
}
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
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));
|
|
290
|
-
}
|
|
291
|
-
transportInput.end();
|
|
292
|
-
})();
|
|
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
|
-
];
|
|
94
|
+
function asClientRpc(state, proc, extendedContext) {
|
|
95
|
+
return async (msg2) => {
|
|
96
|
+
return await proc.handler({ ...extendedContext, state }, msg2).catch(catchProcError);
|
|
97
|
+
};
|
|
306
98
|
}
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
99
|
+
function asClientStream(state, proc, init, extendedContext) {
|
|
100
|
+
const input = pushable({ objectMode: true });
|
|
101
|
+
const output = pushable({
|
|
102
|
+
objectMode: true
|
|
103
|
+
});
|
|
104
|
+
(async () => {
|
|
105
|
+
if (init) {
|
|
106
|
+
const _proc = proc;
|
|
107
|
+
await _proc.handler({ ...extendedContext, state }, init, input, output).catch((err) => output.push(catchProcError(err)));
|
|
108
|
+
} else {
|
|
109
|
+
const _proc = proc;
|
|
110
|
+
await _proc.handler({ ...extendedContext, state }, input, output).catch((err) => output.push(catchProcError(err)));
|
|
111
|
+
}
|
|
112
|
+
})();
|
|
113
|
+
return [input, output];
|
|
316
114
|
}
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
115
|
+
function asClientSubscription(state, proc, extendedContext) {
|
|
116
|
+
const output = pushable({
|
|
117
|
+
objectMode: true
|
|
118
|
+
});
|
|
119
|
+
return async (msg2) => {
|
|
120
|
+
(async () => {
|
|
121
|
+
return await proc.handler({ ...extendedContext, state }, msg2, output).catch((err) => output.push(catchProcError(err)));
|
|
122
|
+
})();
|
|
123
|
+
return output;
|
|
124
|
+
};
|
|
326
125
|
}
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
126
|
+
async function asClientUpload(state, proc, init, extendedContext) {
|
|
127
|
+
const input = pushable({ objectMode: true });
|
|
128
|
+
if (init) {
|
|
129
|
+
const _proc = proc;
|
|
130
|
+
const result = _proc.handler({ ...extendedContext, state }, init, input).catch(catchProcError);
|
|
131
|
+
return [input, result];
|
|
132
|
+
} else {
|
|
133
|
+
const _proc = proc;
|
|
134
|
+
const result = _proc.handler({ ...extendedContext, state }, input).catch(catchProcError);
|
|
135
|
+
return [input, result];
|
|
136
|
+
}
|
|
334
137
|
}
|
|
138
|
+
export {
|
|
139
|
+
asClientRpc,
|
|
140
|
+
asClientStream,
|
|
141
|
+
asClientSubscription,
|
|
142
|
+
asClientUpload,
|
|
143
|
+
createDummyTransportMessage,
|
|
144
|
+
createLocalWebSocketClient,
|
|
145
|
+
createWebSocketServer,
|
|
146
|
+
createWsTransports,
|
|
147
|
+
iterNext,
|
|
148
|
+
onServerReady,
|
|
149
|
+
payloadToTransportMessage,
|
|
150
|
+
waitForMessage
|
|
151
|
+
};
|
package/package.json
CHANGED
|
@@ -1,28 +1,56 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@replit/river",
|
|
3
|
-
"sideEffects": false,
|
|
4
3
|
"description": "It's like tRPC but... with JSON Schema Support, duplex streaming and support for service multiplexing. Transport agnostic!",
|
|
5
|
-
"version": "0.
|
|
4
|
+
"version": "0.10.1",
|
|
6
5
|
"type": "module",
|
|
7
6
|
"exports": {
|
|
8
|
-
".":
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
"./
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
7
|
+
".": {
|
|
8
|
+
"import": "./dist/router/index.js",
|
|
9
|
+
"require": "./dist/router/index.cjs"
|
|
10
|
+
},
|
|
11
|
+
"./logging": {
|
|
12
|
+
"import": "./dist/logging/index.js",
|
|
13
|
+
"require": "./dist/logging/index.cjs"
|
|
14
|
+
},
|
|
15
|
+
"./codec": {
|
|
16
|
+
"import": "./dist/codec/index.js",
|
|
17
|
+
"require": "./dist/codec/index.cjs"
|
|
18
|
+
},
|
|
19
|
+
"./transport": {
|
|
20
|
+
"import": "./dist/transport/index.js",
|
|
21
|
+
"require": "./dist/transport/index.cjs"
|
|
22
|
+
},
|
|
23
|
+
"./transport/ws/client": {
|
|
24
|
+
"import": "./dist/transport/impls/ws/client.js",
|
|
25
|
+
"require": "./dist/transport/impls/ws/client.cjs"
|
|
26
|
+
},
|
|
27
|
+
"./transport/ws/server": {
|
|
28
|
+
"import": "./dist/transport/impls/ws/server.js",
|
|
29
|
+
"require": "./dist/transport/impls/ws/server.cjs"
|
|
30
|
+
},
|
|
31
|
+
"./transport/stdio": {
|
|
32
|
+
"import": "./dist/transport/impls/stdio/stdio.js",
|
|
33
|
+
"require": "./dist/transport/impls/stdio/stdio.cjs"
|
|
34
|
+
},
|
|
35
|
+
"./test-util": {
|
|
36
|
+
"import": "./dist/util/testHelpers.js",
|
|
37
|
+
"require": "./dist/util/testHelpers.cjs"
|
|
38
|
+
}
|
|
16
39
|
},
|
|
40
|
+
"sideEffects": [
|
|
41
|
+
"./dist/logging/index.js"
|
|
42
|
+
],
|
|
17
43
|
"files": [
|
|
18
44
|
"dist"
|
|
19
45
|
],
|
|
20
46
|
"dependencies": {
|
|
21
47
|
"@msgpack/msgpack": "^3.0.0-beta2",
|
|
22
|
-
"
|
|
48
|
+
"nanoid": "^4.0.2"
|
|
49
|
+
},
|
|
50
|
+
"peerDependencies": {
|
|
51
|
+
"@sinclair/typebox": "^0.31.28",
|
|
23
52
|
"isomorphic-ws": "^5.0.0",
|
|
24
53
|
"it-pushable": "^3.2.1",
|
|
25
|
-
"nanoid": "^4.0.2",
|
|
26
54
|
"ws": "^8.13.0"
|
|
27
55
|
},
|
|
28
56
|
"devDependencies": {
|
|
@@ -33,6 +61,16 @@
|
|
|
33
61
|
"typescript": "^5.2.2",
|
|
34
62
|
"vitest": "^1.0.1"
|
|
35
63
|
},
|
|
64
|
+
"scripts": {
|
|
65
|
+
"check": "tsc --noEmit && npx prettier . --check",
|
|
66
|
+
"format": "npx prettier . --write",
|
|
67
|
+
"build": "tsup && du -sh dist",
|
|
68
|
+
"prepack": "npm run build",
|
|
69
|
+
"release": "npm publish --access public",
|
|
70
|
+
"test:ui": "echo \"remember to go to /__vitest__ in the webview\" && vitest --ui --api.host 0.0.0.0 --api.port 3000",
|
|
71
|
+
"test": "vitest --test-timeout=500",
|
|
72
|
+
"bench": "vitest bench"
|
|
73
|
+
},
|
|
36
74
|
"engines": {
|
|
37
75
|
"node": ">=16"
|
|
38
76
|
},
|
|
@@ -42,14 +80,5 @@
|
|
|
42
80
|
"jsonschema"
|
|
43
81
|
],
|
|
44
82
|
"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
|
-
}
|
|
83
|
+
"license": "MIT"
|
|
84
|
+
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"bandwidth.bench.d.ts","sourceRoot":"","sources":["../../__tests__/bandwidth.bench.ts"],"names":[],"mappings":""}
|