@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.
Files changed (129) hide show
  1. package/dist/{router/builder.d.ts → builder-3c4485f0.d.ts} +82 -28
  2. package/dist/chunk-7WJ6YLE5.js +683 -0
  3. package/dist/chunk-AJQU4AZG.js +284 -0
  4. package/dist/chunk-ORAG7IAU.js +0 -0
  5. package/dist/chunk-PC65ZFWJ.js +29 -0
  6. package/dist/chunk-R6H2BIMC.js +49 -0
  7. package/dist/chunk-RGMHF6PF.js +65 -0
  8. package/dist/chunk-SLUSVGQH.js +30 -0
  9. package/dist/chunk-UU2Z7LDR.js +113 -0
  10. package/dist/chunk-WVT5QXMZ.js +20 -0
  11. package/dist/chunk-ZE4MX7DF.js +75 -0
  12. package/dist/codec/index.cjs +94 -0
  13. package/dist/codec/index.d.cts +15 -0
  14. package/dist/codec/index.d.ts +15 -4
  15. package/dist/codec/index.js +10 -2
  16. package/dist/connection-8e19874c.d.ts +11 -0
  17. package/dist/connection-f7688cc1.d.ts +11 -0
  18. package/dist/logging/index.cjs +56 -0
  19. package/dist/logging/index.d.cts +28 -0
  20. package/dist/logging/index.d.ts +6 -6
  21. package/dist/logging/index.js +9 -40
  22. package/dist/router/index.cjs +770 -0
  23. package/dist/router/index.d.cts +114 -0
  24. package/dist/router/index.d.ts +114 -10
  25. package/dist/router/index.js +24 -4
  26. package/dist/transport/impls/ws/client.cjs +505 -0
  27. package/dist/transport/impls/ws/client.d.cts +42 -0
  28. package/dist/transport/impls/ws/client.d.ts +9 -12
  29. package/dist/transport/impls/ws/client.js +10 -101
  30. package/dist/transport/impls/ws/server.cjs +457 -0
  31. package/dist/transport/impls/ws/server.d.cts +21 -0
  32. package/dist/transport/impls/ws/server.d.ts +14 -10
  33. package/dist/transport/impls/ws/server.js +11 -47
  34. package/dist/transport/index.cjs +362 -0
  35. package/dist/transport/{transport.d.ts → index.d.cts} +119 -7
  36. package/dist/transport/index.d.ts +273 -13
  37. package/dist/transport/index.js +20 -23
  38. package/dist/{codec/types.d.ts → types-3e5768ec.d.ts} +3 -2
  39. package/dist/util/testHelpers.cjs +731 -0
  40. package/dist/util/testHelpers.d.cts +79 -0
  41. package/dist/util/testHelpers.d.ts +34 -108
  42. package/dist/util/testHelpers.js +137 -320
  43. package/package.json +52 -23
  44. package/dist/__tests__/bandwidth.bench.d.ts +0 -2
  45. package/dist/__tests__/bandwidth.bench.d.ts.map +0 -1
  46. package/dist/__tests__/bandwidth.bench.js +0 -90
  47. package/dist/__tests__/e2e.test.d.ts +0 -2
  48. package/dist/__tests__/e2e.test.d.ts.map +0 -1
  49. package/dist/__tests__/e2e.test.js +0 -316
  50. package/dist/__tests__/fixtures/cleanup.d.ts +0 -12
  51. package/dist/__tests__/fixtures/cleanup.d.ts.map +0 -1
  52. package/dist/__tests__/fixtures/cleanup.js +0 -39
  53. package/dist/__tests__/fixtures/largePayload.json +0 -33
  54. package/dist/__tests__/fixtures/observable.d.ts +0 -26
  55. package/dist/__tests__/fixtures/observable.d.ts.map +0 -1
  56. package/dist/__tests__/fixtures/observable.js +0 -38
  57. package/dist/__tests__/fixtures/observable.test.d.ts +0 -2
  58. package/dist/__tests__/fixtures/observable.test.d.ts.map +0 -1
  59. package/dist/__tests__/fixtures/observable.test.js +0 -39
  60. package/dist/__tests__/fixtures/services.d.ts +0 -288
  61. package/dist/__tests__/fixtures/services.d.ts.map +0 -1
  62. package/dist/__tests__/fixtures/services.js +0 -224
  63. package/dist/__tests__/handler.test.d.ts +0 -2
  64. package/dist/__tests__/handler.test.d.ts.map +0 -1
  65. package/dist/__tests__/handler.test.js +0 -121
  66. package/dist/__tests__/invariants.test.d.ts +0 -2
  67. package/dist/__tests__/invariants.test.d.ts.map +0 -1
  68. package/dist/__tests__/invariants.test.js +0 -138
  69. package/dist/__tests__/serialize.test.d.ts +0 -2
  70. package/dist/__tests__/serialize.test.d.ts.map +0 -1
  71. package/dist/__tests__/serialize.test.js +0 -208
  72. package/dist/__tests__/typescript-stress.test.d.ts +0 -1583
  73. package/dist/__tests__/typescript-stress.test.d.ts.map +0 -1
  74. package/dist/__tests__/typescript-stress.test.js +0 -123
  75. package/dist/codec/binary.d.ts +0 -7
  76. package/dist/codec/binary.d.ts.map +0 -1
  77. package/dist/codec/binary.js +0 -20
  78. package/dist/codec/codec.test.d.ts +0 -5
  79. package/dist/codec/codec.test.d.ts.map +0 -1
  80. package/dist/codec/codec.test.js +0 -41
  81. package/dist/codec/index.d.ts.map +0 -1
  82. package/dist/codec/json.d.ts +0 -7
  83. package/dist/codec/json.d.ts.map +0 -1
  84. package/dist/codec/json.js +0 -51
  85. package/dist/codec/types.d.ts.map +0 -1
  86. package/dist/codec/types.js +0 -1
  87. package/dist/logging/index.d.ts.map +0 -1
  88. package/dist/router/builder.d.ts.map +0 -1
  89. package/dist/router/builder.js +0 -91
  90. package/dist/router/client.d.ts +0 -68
  91. package/dist/router/client.d.ts.map +0 -1
  92. package/dist/router/client.js +0 -159
  93. package/dist/router/context.d.ts +0 -30
  94. package/dist/router/context.d.ts.map +0 -1
  95. package/dist/router/context.js +0 -1
  96. package/dist/router/index.d.ts.map +0 -1
  97. package/dist/router/result.d.ts +0 -25
  98. package/dist/router/result.d.ts.map +0 -1
  99. package/dist/router/result.js +0 -18
  100. package/dist/router/server.d.ts +0 -39
  101. package/dist/router/server.d.ts.map +0 -1
  102. package/dist/router/server.js +0 -217
  103. package/dist/transport/events.d.ts +0 -19
  104. package/dist/transport/events.d.ts.map +0 -1
  105. package/dist/transport/events.js +0 -26
  106. package/dist/transport/impls/stdio/stdio.d.ts +0 -33
  107. package/dist/transport/impls/stdio/stdio.d.ts.map +0 -1
  108. package/dist/transport/impls/stdio/stdio.js +0 -75
  109. package/dist/transport/impls/stdio/stdio.test.d.ts +0 -2
  110. package/dist/transport/impls/stdio/stdio.test.d.ts.map +0 -1
  111. package/dist/transport/impls/stdio/stdio.test.js +0 -25
  112. package/dist/transport/impls/ws/client.d.ts.map +0 -1
  113. package/dist/transport/impls/ws/connection.d.ts +0 -11
  114. package/dist/transport/impls/ws/connection.d.ts.map +0 -1
  115. package/dist/transport/impls/ws/connection.js +0 -23
  116. package/dist/transport/impls/ws/server.d.ts.map +0 -1
  117. package/dist/transport/impls/ws/ws.test.d.ts +0 -2
  118. package/dist/transport/impls/ws/ws.test.d.ts.map +0 -1
  119. package/dist/transport/impls/ws/ws.test.js +0 -117
  120. package/dist/transport/index.d.ts.map +0 -1
  121. package/dist/transport/message.d.ts +0 -143
  122. package/dist/transport/message.d.ts.map +0 -1
  123. package/dist/transport/message.js +0 -113
  124. package/dist/transport/message.test.d.ts +0 -2
  125. package/dist/transport/message.test.d.ts.map +0 -1
  126. package/dist/transport/message.test.js +0 -52
  127. package/dist/transport/transport.d.ts.map +0 -1
  128. package/dist/transport/transport.js +0 -281
  129. package/dist/util/testHelpers.d.ts.map +0 -1
@@ -1,334 +1,151 @@
1
- import WebSocket from 'isomorphic-ws';
2
- import { WebSocketServer } from 'ws';
3
- import { WebSocketClientTransport } from '../transport/impls/ws/client';
4
- import { msg, reply, } from '../transport';
5
- import { pushable } from 'it-pushable';
6
- import { Err, UNCAUGHT_ERROR, } from '../router/result';
7
- import { WebSocketServerTransport } from '../transport/impls/ws/server';
8
- /**
9
- * Creates a WebSocket server instance using the provided HTTP server.
10
- * Only used as helper for testing.
11
- * @param server - The HTTP server instance to use for the WebSocket server.
12
- * @returns A Promise that resolves to the created WebSocket server instance.
13
- */
14
- export async function createWebSocketServer(server) {
15
- return new WebSocketServer({ server });
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
- * Starts listening on the given server and returns the automatically allocated port number.
19
- * This should only be used for testing.
20
- * @param server - The http server to listen on.
21
- * @returns A promise that resolves with the allocated port number.
22
- * @throws An error if a port cannot be allocated.
23
- */
24
- export async function onServerReady(server) {
25
- return new Promise((resolve, reject) => {
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
- * Creates a WebSocket client that connects to a local server at the specified port.
39
- * This should only be used for testing.
40
- * @param port - The port number to connect to.
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
- * Creates a pair of WebSocket transports for testing purposes.
50
- * @param port - The port number to use for the client transport. This should be acquired after starting a server via {@link createWebSocketServer}.
51
- * @param wss - The WebSocketServer instance to use for the server transport.
52
- * @returns An array containing the client and server {@link WebSocketClientTransport} instances.
53
- */
54
- export function createWsTransports(port, wss, codec) {
55
- const options = codec ? { codec } : undefined;
56
- return [
57
- new WebSocketClientTransport(() => createLocalWebSocketClient(port), 'client', 'SERVER', options),
58
- new WebSocketServerTransport(wss, 'SERVER', options),
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
- * Transforms an RPC procedure definition into a normal function call.
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
- * Transforms a stream procedure definition into a pair of input and output streams.
86
- * Input messages can be pushed into the input stream.
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.
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
- * Transforms a stream procedure definition into a pair of input and output streams.
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
- * Transforms a subscription procedure definition into a procedure that returns an output stream.
192
- * Input messages can be pushed into the input stream.
193
- * This should only be used for testing.
194
- * @template State - The type of the state object.
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.
201
- */
202
- export function asClientSubscription(state, proc, extendedContext) {
203
- const rawOutput = pushable({
204
- objectMode: true,
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
- * Transforms an upload procedure definition into a procedure that returns an input stream.
231
- * Input messages can be pushed into the input stream.
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({
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
- * 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));
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
- * 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');
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
- * Creates a dummy opaque transport message for testing purposes.
319
- * @returns The created opaque transport message.
320
- */
321
- export function createDummyTransportMessage() {
322
- return payloadToTransportMessage({
323
- msg: 'cool',
324
- test: Math.random(),
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
- * Retrieves the next value from an async iterable iterator.
329
- * @param iter The async iterable iterator.
330
- * @returns A promise that resolves to the next value from the iterator.
331
- */
332
- export function iterNext(iter) {
333
- return iter.next().then((res) => res.value);
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.9.3",
4
+ "version": "0.10.1",
6
5
  "type": "module",
7
6
  "exports": {
8
- ".": "./dist/router/index.js",
9
- "./logging": "./dist/logging/index.js",
10
- "./codec": "./dist/codec/index.js",
11
- "./test-util": "./dist/util/testHelpers.js",
12
- "./transport": "./dist/transport/index.js",
13
- "./transport/ws/client": "./dist/transport/impls/ws/client.js",
14
- "./transport/ws/server": "./dist/transport/impls/ws/server.js",
15
- "./transport/stdio": "./dist/transport/impls/stdio/stdio.js"
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
- "@sinclair/typebox": "^0.31.8",
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
- "scripts": {
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,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=bandwidth.bench.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"bandwidth.bench.d.ts","sourceRoot":"","sources":["../../__tests__/bandwidth.bench.ts"],"names":[],"mappings":""}