@replit/river 0.10.13 → 0.12.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.
Files changed (83) hide show
  1. package/README.md +28 -8
  2. package/dist/{builder-1f26296b.d.ts → builder-c593de11.d.ts} +14 -13
  3. package/dist/{chunk-3JGVFWKQ.js → chunk-24O3BKZA.js} +205 -180
  4. package/dist/chunk-4HOR4NUO.js +40 -0
  5. package/dist/chunk-ANGOKBE5.js +708 -0
  6. package/dist/{chunk-R6H2BIMC.js → chunk-GZ7HCLLM.js} +31 -7
  7. package/dist/{chunk-T7M7OKPE.js → chunk-H4BYJELI.js} +5 -1
  8. package/dist/chunk-IIBVKYDB.js +62 -0
  9. package/dist/chunk-IUDKWAOK.js +47 -0
  10. package/dist/chunk-WTOIOXB7.js +125 -0
  11. package/dist/chunk-XOTIAXAH.js +44 -0
  12. package/dist/codec/index.cjs +13 -7
  13. package/dist/codec/index.js +2 -4
  14. package/dist/connection-2956a1c5.d.ts +17 -0
  15. package/dist/connection-aaea7c88.d.ts +15 -0
  16. package/dist/connection-cd963ed5.d.ts +18 -0
  17. package/dist/index-d91775d9.d.ts +442 -0
  18. package/dist/logging/index.cjs +8 -3
  19. package/dist/logging/index.d.cts +6 -1
  20. package/dist/logging/index.d.ts +6 -1
  21. package/dist/logging/index.js +5 -3
  22. package/dist/messageFraming-b200ef25.d.ts +20 -0
  23. package/dist/router/index.cjs +249 -211
  24. package/dist/router/index.d.cts +6 -7
  25. package/dist/router/index.d.ts +6 -7
  26. package/dist/router/index.js +3 -3
  27. package/dist/transport/impls/stdio/client.cjs +891 -0
  28. package/dist/transport/impls/stdio/client.d.cts +27 -0
  29. package/dist/transport/impls/stdio/client.d.ts +27 -0
  30. package/dist/transport/impls/stdio/client.js +42 -0
  31. package/dist/transport/impls/stdio/server.cjs +861 -0
  32. package/dist/transport/impls/stdio/server.d.cts +25 -0
  33. package/dist/transport/impls/stdio/server.d.ts +25 -0
  34. package/dist/transport/impls/stdio/server.js +33 -0
  35. package/dist/transport/impls/uds/client.cjs +893 -0
  36. package/dist/transport/impls/uds/client.d.cts +16 -0
  37. package/dist/transport/impls/uds/client.d.ts +16 -0
  38. package/dist/transport/impls/uds/client.js +44 -0
  39. package/dist/transport/impls/uds/server.cjs +863 -0
  40. package/dist/transport/impls/uds/server.d.cts +16 -0
  41. package/dist/transport/impls/uds/server.d.ts +16 -0
  42. package/dist/transport/impls/uds/server.js +39 -0
  43. package/dist/transport/impls/ws/client.cjs +587 -248
  44. package/dist/transport/impls/ws/client.d.cts +6 -21
  45. package/dist/transport/impls/ws/client.d.ts +6 -21
  46. package/dist/transport/impls/ws/client.js +77 -7
  47. package/dist/transport/impls/ws/server.cjs +541 -194
  48. package/dist/transport/impls/ws/server.d.cts +6 -10
  49. package/dist/transport/impls/ws/server.d.ts +6 -10
  50. package/dist/transport/impls/ws/server.js +31 -8
  51. package/dist/transport/index.cjs +652 -129
  52. package/dist/transport/index.d.cts +3 -276
  53. package/dist/transport/index.d.ts +3 -276
  54. package/dist/transport/index.js +13 -10
  55. package/dist/util/testHelpers.cjs +40 -602
  56. package/dist/util/testHelpers.d.cts +18 -37
  57. package/dist/util/testHelpers.d.ts +18 -37
  58. package/dist/util/testHelpers.js +27 -47
  59. package/package.json +29 -14
  60. package/dist/chunk-3MQETIGZ.js +0 -80
  61. package/dist/chunk-5IC5XMWK.js +0 -140
  62. package/dist/chunk-L7D75G4K.js +0 -29
  63. package/dist/chunk-LQXPKF3A.js +0 -282
  64. package/dist/chunk-PJ2EUO7O.js +0 -63
  65. package/dist/chunk-WVT5QXMZ.js +0 -20
  66. package/dist/chunk-ZE4MX7DF.js +0 -75
  67. package/dist/connection-2529fc14.d.ts +0 -10
  68. package/dist/connection-316d6e3a.d.ts +0 -10
  69. package/dist/connection-8e19874c.d.ts +0 -11
  70. package/dist/connection-f7688cc1.d.ts +0 -11
  71. package/dist/transport/impls/stdio/stdio.cjs +0 -508
  72. package/dist/transport/impls/stdio/stdio.d.cts +0 -26
  73. package/dist/transport/impls/stdio/stdio.d.ts +0 -26
  74. package/dist/transport/impls/stdio/stdio.js +0 -70
  75. package/dist/transport/impls/unixsocket/client.cjs +0 -506
  76. package/dist/transport/impls/unixsocket/client.d.cts +0 -16
  77. package/dist/transport/impls/unixsocket/client.d.ts +0 -16
  78. package/dist/transport/impls/unixsocket/client.js +0 -67
  79. package/dist/transport/impls/unixsocket/server.cjs +0 -510
  80. package/dist/transport/impls/unixsocket/server.d.cts +0 -18
  81. package/dist/transport/impls/unixsocket/server.d.ts +0 -18
  82. package/dist/transport/impls/unixsocket/server.js +0 -73
  83. /package/dist/{chunk-ORAG7IAU.js → chunk-5IZ2UHWV.js} +0 -0
@@ -37,10 +37,9 @@ __export(testHelpers_exports, {
37
37
  createDummyTransportMessage: () => createDummyTransportMessage,
38
38
  createLocalWebSocketClient: () => createLocalWebSocketClient,
39
39
  createWebSocketServer: () => createWebSocketServer,
40
- createWsTransports: () => createWsTransports,
41
40
  getUnixSocketPath: () => getUnixSocketPath,
42
41
  iterNext: () => iterNext,
43
- onUnixSocketServeReady: () => onUnixSocketServeReady,
42
+ onUdsServeReady: () => onUdsServeReady,
44
43
  onWsServerReady: () => onWsServerReady,
45
44
  payloadToTransportMessage: () => payloadToTransportMessage,
46
45
  waitForMessage: () => waitForMessage
@@ -49,519 +48,6 @@ module.exports = __toCommonJS(testHelpers_exports);
49
48
  var import_isomorphic_ws = __toESM(require("isomorphic-ws"), 1);
50
49
  var import_ws = require("ws");
51
50
 
52
- // transport/transport.ts
53
- var import_value = require("@sinclair/typebox/value");
54
-
55
- // transport/message.ts
56
- var import_typebox = require("@sinclair/typebox");
57
- var import_nanoid = require("nanoid");
58
- var TransportMessageSchema = (t) => import_typebox.Type.Object({
59
- id: import_typebox.Type.String(),
60
- from: import_typebox.Type.String(),
61
- to: import_typebox.Type.String(),
62
- serviceName: import_typebox.Type.Optional(import_typebox.Type.Union([import_typebox.Type.String(), import_typebox.Type.Null()])),
63
- procedureName: import_typebox.Type.Optional(import_typebox.Type.Union([import_typebox.Type.String(), import_typebox.Type.Null()])),
64
- streamId: import_typebox.Type.String(),
65
- controlFlags: import_typebox.Type.Integer(),
66
- payload: t
67
- });
68
- var TransportAckSchema = TransportMessageSchema(
69
- import_typebox.Type.Object({
70
- ack: import_typebox.Type.String()
71
- })
72
- );
73
- var ControlMessagePayloadSchema = import_typebox.Type.Object({
74
- type: import_typebox.Type.Literal("CLOSE")
75
- });
76
- var OpaqueTransportMessageSchema = TransportMessageSchema(
77
- import_typebox.Type.Unknown()
78
- );
79
- function msg(from, to, streamId, payload, serviceName, procedureName) {
80
- return {
81
- id: (0, import_nanoid.nanoid)(),
82
- to,
83
- from,
84
- serviceName,
85
- procedureName,
86
- streamId,
87
- controlFlags: 0,
88
- payload
89
- };
90
- }
91
- function reply(msg2, response) {
92
- return {
93
- id: (0, import_nanoid.nanoid)(),
94
- streamId: msg2.streamId,
95
- controlFlags: 0,
96
- to: msg2.from,
97
- from: msg2.to,
98
- payload: response
99
- };
100
- }
101
- function isAck(controlFlag) {
102
- return (controlFlag & 1 /* AckBit */) === 1 /* AckBit */;
103
- }
104
-
105
- // logging/index.ts
106
- var log;
107
-
108
- // transport/events.ts
109
- var EventDispatcher = class {
110
- eventListeners = {};
111
- numberOfListeners(eventType) {
112
- return this.eventListeners[eventType]?.size ?? 0;
113
- }
114
- addEventListener(eventType, handler) {
115
- if (!this.eventListeners[eventType]) {
116
- this.eventListeners[eventType] = /* @__PURE__ */ new Set();
117
- }
118
- this.eventListeners[eventType]?.add(handler);
119
- }
120
- removeEventListener(eventType, handler) {
121
- const handlers = this.eventListeners[eventType];
122
- if (handlers) {
123
- this.eventListeners[eventType]?.delete(handler);
124
- }
125
- }
126
- dispatchEvent(eventType, event) {
127
- const handlers = this.eventListeners[eventType];
128
- if (handlers) {
129
- for (const handler of handlers) {
130
- handler(event);
131
- }
132
- }
133
- }
134
- };
135
-
136
- // transport/transport.ts
137
- var Connection = class {
138
- connectedTo;
139
- transport;
140
- constructor(transport, connectedTo) {
141
- this.connectedTo = connectedTo;
142
- this.transport = transport;
143
- }
144
- };
145
- var Transport = class {
146
- /**
147
- * A flag indicating whether the transport has been destroyed.
148
- * A destroyed transport will not attempt to reconnect and cannot be used again.
149
- */
150
- state;
151
- /**
152
- * The {@link Codec} used to encode and decode messages.
153
- */
154
- codec;
155
- /**
156
- * The client ID of this transport.
157
- */
158
- clientId;
159
- /**
160
- * An array of message IDs that are waiting to be sent over the WebSocket connection.
161
- * This builds up if the WebSocket is down for a period of time.
162
- */
163
- sendQueue;
164
- /**
165
- * The buffer of messages that have been sent but not yet acknowledged.
166
- */
167
- sendBuffer;
168
- /**
169
- * The map of {@link Connection}s managed by this transport.
170
- */
171
- connections;
172
- /**
173
- * The event dispatcher for handling events of type EventTypes.
174
- */
175
- eventDispatcher;
176
- /**
177
- * Creates a new Transport instance.
178
- * This should also set up {@link onConnect}, and {@link onDisconnect} listeners.
179
- * @param codec The codec used to encode and decode messages.
180
- * @param clientId The client ID of this transport.
181
- */
182
- constructor(codec, clientId) {
183
- this.eventDispatcher = new EventDispatcher();
184
- this.sendBuffer = /* @__PURE__ */ new Map();
185
- this.sendQueue = /* @__PURE__ */ new Map();
186
- this.connections = /* @__PURE__ */ new Map();
187
- this.codec = codec;
188
- this.clientId = clientId;
189
- this.state = "open";
190
- }
191
- /**
192
- * The downstream implementation needs to call this when a new connection is established.
193
- * @param conn The connection object.
194
- */
195
- onConnect(conn) {
196
- log?.info(`${this.clientId} -- new connection to ${conn.connectedTo}`);
197
- this.connections.set(conn.connectedTo, conn);
198
- this.eventDispatcher.dispatchEvent("connectionStatus", {
199
- status: "connect",
200
- conn
201
- });
202
- const outstanding = this.sendQueue.get(conn.connectedTo);
203
- if (!outstanding) {
204
- return;
205
- }
206
- for (const id of outstanding) {
207
- const msg2 = this.sendBuffer.get(id);
208
- if (!msg2) {
209
- log?.warn(
210
- `${this.clientId} -- tried to resend a message we received an ack for`
211
- );
212
- continue;
213
- }
214
- this.send(msg2);
215
- }
216
- this.sendQueue.delete(conn.connectedTo);
217
- }
218
- /**
219
- * The downstream implementation needs to call this when a connection is closed.
220
- * @param conn The connection object.
221
- */
222
- onDisconnect(conn) {
223
- log?.info(`${this.clientId} -- disconnect from ${conn.connectedTo}`);
224
- conn.close();
225
- this.connections.delete(conn.connectedTo);
226
- this.eventDispatcher.dispatchEvent("connectionStatus", {
227
- status: "disconnect",
228
- conn
229
- });
230
- }
231
- /**
232
- * Handles a message received by this transport. Thin wrapper around {@link handleMsg} and {@link parseMsg}.
233
- * @param msg The message to handle.
234
- */
235
- onMessage(msg2) {
236
- return this.handleMsg(this.parseMsg(msg2));
237
- }
238
- /**
239
- * Parses a message from a Uint8Array into a {@link OpaqueTransportMessage}.
240
- * @param msg The message to parse.
241
- * @returns The parsed message, or null if the message is malformed or invalid.
242
- */
243
- parseMsg(msg2) {
244
- const parsedMsg = this.codec.fromBuffer(msg2);
245
- if (parsedMsg === null) {
246
- const decodedBuffer = new TextDecoder().decode(msg2);
247
- log?.warn(`${this.clientId} -- received malformed msg: ${decodedBuffer}`);
248
- return null;
249
- }
250
- if (import_value.Value.Check(OpaqueTransportMessageSchema, parsedMsg)) {
251
- return {
252
- ...parsedMsg,
253
- serviceName: parsedMsg.serviceName === null ? void 0 : parsedMsg.serviceName,
254
- procedureName: parsedMsg.procedureName === null ? void 0 : parsedMsg.procedureName
255
- };
256
- } else {
257
- log?.warn(
258
- `${this.clientId} -- received invalid msg: ${JSON.stringify(
259
- parsedMsg
260
- )}`
261
- );
262
- return null;
263
- }
264
- }
265
- /**
266
- * Called when a message is received by this transport.
267
- * You generally shouldn't need to override this in downstream transport implementations.
268
- * @param msg The received message.
269
- */
270
- handleMsg(msg2) {
271
- if (!msg2) {
272
- return;
273
- }
274
- if (isAck(msg2.controlFlags) && import_value.Value.Check(TransportAckSchema, msg2)) {
275
- log?.debug(`${this.clientId} -- received ack: ${JSON.stringify(msg2)}`);
276
- if (this.sendBuffer.has(msg2.payload.ack)) {
277
- this.sendBuffer.delete(msg2.payload.ack);
278
- }
279
- } else {
280
- log?.debug(`${this.clientId} -- received msg: ${JSON.stringify(msg2)}`);
281
- this.eventDispatcher.dispatchEvent("message", msg2);
282
- if (!isAck(msg2.controlFlags)) {
283
- const ackMsg = reply(msg2, { ack: msg2.id });
284
- ackMsg.controlFlags = 1 /* AckBit */;
285
- ackMsg.from = this.clientId;
286
- this.send(ackMsg);
287
- }
288
- }
289
- }
290
- /**
291
- * Adds a listener to this transport.
292
- * @param the type of event to listen for
293
- * @param handler The message handler to add.
294
- */
295
- addEventListener(type, handler) {
296
- this.eventDispatcher.addEventListener(type, handler);
297
- }
298
- /**
299
- * Removes a listener from this transport.
300
- * @param the type of event to unlisten on
301
- * @param handler The message handler to remove.
302
- */
303
- removeEventListener(type, handler) {
304
- this.eventDispatcher.removeEventListener(type, handler);
305
- }
306
- /**
307
- * Sends a message over this transport, delegating to the appropriate connection to actually
308
- * send the message.
309
- * @param msg The message to send.
310
- * @returns The ID of the sent message.
311
- */
312
- send(msg2) {
313
- if (this.state === "destroyed") {
314
- const err = "transport is destroyed, cant send";
315
- log?.error(`${this.clientId} -- ` + err + `: ${JSON.stringify(msg2)}`);
316
- throw new Error(err);
317
- } else if (this.state === "closed") {
318
- log?.info(
319
- `${this.clientId} -- transport closed when sending, discarding : ${JSON.stringify(
320
- msg2
321
- )}`
322
- );
323
- return msg2.id;
324
- }
325
- let conn = this.connections.get(msg2.to);
326
- if (!isAck(msg2.controlFlags)) {
327
- this.sendBuffer.set(msg2.id, msg2);
328
- }
329
- if (conn) {
330
- log?.debug(`${this.clientId} -- sending ${JSON.stringify(msg2)}`);
331
- const ok = conn.send(this.codec.toBuffer(msg2));
332
- if (ok) {
333
- return msg2.id;
334
- }
335
- }
336
- log?.info(
337
- `${this.clientId} -- connection to ${msg2.to} not ready, attempting reconnect and queuing ${JSON.stringify(msg2)}`
338
- );
339
- const outstanding = this.sendQueue.get(msg2.to) || [];
340
- outstanding.push(msg2.id);
341
- this.sendQueue.set(msg2.to, outstanding);
342
- this.createNewConnection(msg2.to);
343
- return msg2.id;
344
- }
345
- /**
346
- * Default close implementation for transports. You should override this in the downstream
347
- * implementation if you need to do any additional cleanup and call super.close() at the end.
348
- * Closes the transport. Any messages sent while the transport is closed will be silently discarded.
349
- */
350
- async close() {
351
- for (const conn of this.connections.values()) {
352
- conn.close();
353
- }
354
- this.connections.clear();
355
- this.state = "closed";
356
- log?.info(`${this.clientId} -- closed transport`);
357
- }
358
- /**
359
- * Default destroy implementation for transports. You should override this in the downstream
360
- * implementation if you need to do any additional cleanup and call super.destroy() at the end.
361
- * Destroys the transport. Any messages sent while the transport is destroyed will throw an error.
362
- */
363
- async destroy() {
364
- for (const conn of this.connections.values()) {
365
- conn.close();
366
- }
367
- this.connections.clear();
368
- this.state = "destroyed";
369
- log?.info(`${this.clientId} -- destroyed transport`);
370
- }
371
- };
372
-
373
- // codec/json.ts
374
- var encoder = new TextEncoder();
375
- var decoder = new TextDecoder();
376
- function uint8ArrayToBase64(uint8Array) {
377
- let binary = "";
378
- uint8Array.forEach((byte) => {
379
- binary += String.fromCharCode(byte);
380
- });
381
- return btoa(binary);
382
- }
383
- function base64ToUint8Array(base64) {
384
- const binaryString = atob(base64);
385
- const uint8Array = new Uint8Array(binaryString.length);
386
- for (let i = 0; i < binaryString.length; i++) {
387
- uint8Array[i] = binaryString.charCodeAt(i);
388
- }
389
- return uint8Array;
390
- }
391
- var NaiveJsonCodec = {
392
- toBuffer: (obj) => {
393
- return encoder.encode(
394
- JSON.stringify(obj, function replacer(key) {
395
- let val = this[key];
396
- if (val instanceof Uint8Array) {
397
- return { $t: uint8ArrayToBase64(val) };
398
- } else {
399
- return val;
400
- }
401
- })
402
- );
403
- },
404
- fromBuffer: (buff) => {
405
- try {
406
- return JSON.parse(decoder.decode(buff), function reviver(_key, val) {
407
- if (val?.$t) {
408
- return base64ToUint8Array(val.$t);
409
- } else {
410
- return val;
411
- }
412
- });
413
- } catch {
414
- return null;
415
- }
416
- }
417
- };
418
-
419
- // transport/impls/ws/connection.ts
420
- var WebSocketConnection = class extends Connection {
421
- ws;
422
- constructor(transport, connectedTo, ws) {
423
- super(transport, connectedTo);
424
- this.ws = ws;
425
- ws.binaryType = "arraybuffer";
426
- this.ws.onmessage = (msg2) => transport.onMessage(msg2.data);
427
- }
428
- send(payload) {
429
- if (this.ws.readyState === this.ws.OPEN) {
430
- this.ws.send(payload);
431
- return true;
432
- } else {
433
- return false;
434
- }
435
- }
436
- async close() {
437
- this.ws.close();
438
- }
439
- };
440
-
441
- // transport/impls/ws/client.ts
442
- var defaultOptions = {
443
- retryIntervalMs: 250,
444
- retryAttemptsMax: 5,
445
- codec: NaiveJsonCodec
446
- };
447
- var WebSocketClientTransport = class extends Transport {
448
- /**
449
- * A function that returns a Promise that resolves to a WebSocket instance.
450
- */
451
- wsGetter;
452
- options;
453
- serverId;
454
- reconnectPromises;
455
- tryReconnecting = true;
456
- /**
457
- * Creates a new WebSocketClientTransport instance.
458
- * @param wsGetter A function that returns a Promise that resolves to a WebSocket instance.
459
- * @param sessionId The ID of the client using the transport. This should be unique per session.
460
- * @param serverId The ID of the server this transport is connecting to.
461
- * @param providedOptions An optional object containing configuration options for the transport.
462
- */
463
- constructor(wsGetter, sessionId, serverId, providedOptions) {
464
- const options = { ...defaultOptions, ...providedOptions };
465
- super(options.codec, sessionId);
466
- this.wsGetter = wsGetter;
467
- this.serverId = serverId;
468
- this.options = options;
469
- this.reconnectPromises = /* @__PURE__ */ new Map();
470
- this.createNewConnection(this.serverId);
471
- }
472
- reopen() {
473
- if (this.state === "destroyed") {
474
- throw new Error("cant reopen a destroyed connection");
475
- }
476
- this.state = "open";
477
- this.createNewConnection(this.serverId);
478
- }
479
- async createNewConnection(to, attempt = 0) {
480
- if (this.state === "destroyed") {
481
- throw new Error("cant reopen a destroyed connection");
482
- }
483
- let reconnectPromise = this.reconnectPromises.get(to);
484
- if (!reconnectPromise) {
485
- if (!this.tryReconnecting) {
486
- log?.info(
487
- `${this.clientId} -- tryReconnecting is false, not attempting reconnect`
488
- );
489
- return;
490
- }
491
- reconnectPromise = new Promise(async (resolve) => {
492
- log?.info(`${this.clientId} -- establishing a new websocket to ${to}`);
493
- try {
494
- const ws = await this.wsGetter(to);
495
- if (ws.readyState === ws.OPEN) {
496
- return resolve({ ws });
497
- }
498
- if (ws.readyState === ws.CLOSING || ws.readyState === ws.CLOSED) {
499
- return resolve({ err: "ws is closing or closed" });
500
- }
501
- const onOpen = () => {
502
- ws.removeEventListener("open", onOpen);
503
- resolve({ ws });
504
- };
505
- const onClose = (evt) => {
506
- ws.removeEventListener("close", onClose);
507
- resolve({ err: evt.reason });
508
- };
509
- ws.addEventListener("open", onOpen);
510
- ws.addEventListener("close", onClose);
511
- } catch (e) {
512
- const reason = e instanceof Error ? e.message : "unknown reason";
513
- return resolve({ err: `couldn't get a new websocket: ${reason}` });
514
- }
515
- });
516
- this.reconnectPromises.set(to, reconnectPromise);
517
- }
518
- const res = await reconnectPromise;
519
- if (this.state !== "open") {
520
- this.reconnectPromises.delete(to);
521
- if ("ws" in res) {
522
- res.ws.close();
523
- }
524
- return;
525
- }
526
- if ("ws" in res && res.ws.readyState === res.ws.OPEN) {
527
- if (res.ws === this.connections.get(to)?.ws) {
528
- return;
529
- }
530
- log?.info(`${this.clientId} -- websocket ok`);
531
- const conn = new WebSocketConnection(this, to, res.ws);
532
- this.onConnect(conn);
533
- res.ws.onclose = () => {
534
- this.reconnectPromises.delete(to);
535
- this.onDisconnect(conn);
536
- };
537
- this.state = "open";
538
- return;
539
- }
540
- this.reconnectPromises.delete(to);
541
- if (attempt >= this.options.retryAttemptsMax) {
542
- throw new Error(
543
- `${this.clientId} -- websocket to ${to} failed after ${attempt} attempts, giving up`
544
- );
545
- } else {
546
- log?.warn(
547
- `${this.clientId} -- websocket to ${to} failed, trying again in ${this.options.retryIntervalMs * attempt}ms`
548
- );
549
- setTimeout(
550
- () => this.createNewConnection(to, attempt + 1),
551
- this.options.retryIntervalMs * attempt
552
- );
553
- }
554
- }
555
- async close() {
556
- super.close();
557
- this.reconnectPromises.clear();
558
- }
559
- async destroy() {
560
- super.destroy();
561
- this.reconnectPromises.clear();
562
- }
563
- };
564
-
565
51
  // node_modules/p-defer/index.js
566
52
  function pDefer() {
567
53
  const deferred = {};
@@ -844,68 +330,29 @@ function _pushable(getNext, options) {
844
330
  return pushable2;
845
331
  }
846
332
 
847
- // transport/impls/ws/server.ts
848
- var defaultOptions2 = {
849
- codec: NaiveJsonCodec
850
- };
851
- var WebSocketServerTransport = class extends Transport {
852
- wss;
853
- constructor(wss, clientId, providedOptions) {
854
- const options = { ...defaultOptions2, ...providedOptions };
855
- super(options.codec, clientId);
856
- this.wss = wss;
857
- wss.on("listening", () => {
858
- log?.info(`${this.clientId} -- server is listening`);
859
- });
860
- this.wss.on("connection", this.connectionHandler);
861
- }
862
- connectionHandler = (ws) => {
863
- let conn = void 0;
864
- ws.onmessage = (msg2) => {
865
- const parsedMsg = this.parseMsg(msg2.data);
866
- if (parsedMsg && !conn) {
867
- conn = new WebSocketConnection(this, parsedMsg.from, ws);
868
- this.onConnect(conn);
869
- this.handleMsg(parsedMsg);
870
- }
871
- };
872
- ws.onclose = () => {
873
- if (conn) {
874
- this.onDisconnect(conn);
875
- }
876
- };
877
- ws.onerror = (msg2) => {
878
- log?.warn(
879
- `${this.clientId} -- ws error from client ${conn?.connectedTo ?? "unknown"}: ${msg2}`
880
- );
881
- };
882
- };
883
- async createNewConnection(to) {
884
- const err = `${this.clientId} -- failed to send msg to ${to}, client probably dropped`;
885
- log?.warn(err);
886
- return;
887
- }
888
- async close() {
889
- super.close();
890
- this.wss.off("connection", this.connectionHandler);
891
- }
892
- };
893
-
894
333
  // router/result.ts
895
- var import_typebox2 = require("@sinclair/typebox");
334
+ var import_typebox = require("@sinclair/typebox");
896
335
  var UNCAUGHT_ERROR = "UNCAUGHT_ERROR";
897
336
  var UNEXPECTED_DISCONNECT = "UNEXPECTED_DISCONNECT";
898
- var RiverUncaughtSchema = import_typebox2.Type.Object({
899
- code: import_typebox2.Type.Union([
900
- import_typebox2.Type.Literal(UNCAUGHT_ERROR),
901
- import_typebox2.Type.Literal(UNEXPECTED_DISCONNECT)
337
+ var RiverUncaughtSchema = import_typebox.Type.Object({
338
+ code: import_typebox.Type.Union([
339
+ import_typebox.Type.Literal(UNCAUGHT_ERROR),
340
+ import_typebox.Type.Literal(UNEXPECTED_DISCONNECT)
902
341
  ]),
903
- message: import_typebox2.Type.String()
342
+ message: import_typebox.Type.String()
904
343
  });
905
344
 
345
+ // util/stringify.ts
346
+ function coerceErrorString(err) {
347
+ if (err instanceof Error) {
348
+ return err.message;
349
+ }
350
+ return `[coerced to error] ${String(err)}`;
351
+ }
352
+
906
353
  // util/testHelpers.ts
907
- var import_nanoid2 = require("nanoid");
908
- async function createWebSocketServer(server) {
354
+ var import_nanoid = require("nanoid");
355
+ function createWebSocketServer(server) {
909
356
  return new import_ws.WebSocketServer({ server });
910
357
  }
911
358
  function onWsServerReady(server) {
@@ -920,30 +367,25 @@ function onWsServerReady(server) {
920
367
  });
921
368
  });
922
369
  }
923
- function onUnixSocketServeReady(server, path) {
370
+ function onUdsServeReady(server, path) {
924
371
  return new Promise((resolve) => {
925
372
  server.listen(path, resolve);
926
373
  });
927
374
  }
928
- async function createLocalWebSocketClient(port) {
375
+ function createLocalWebSocketClient(port) {
929
376
  const sock = new import_isomorphic_ws.default(`ws://localhost:${port}`);
930
377
  sock.binaryType = "arraybuffer";
931
378
  return sock;
932
379
  }
933
- function createWsTransports(port, wss, codec) {
934
- const options = codec ? { codec } : void 0;
935
- return [
936
- new WebSocketClientTransport(
937
- () => createLocalWebSocketClient(port),
938
- "client",
939
- "SERVER",
940
- options
941
- ),
942
- new WebSocketServerTransport(wss, "SERVER", options)
943
- ];
380
+ async function iterNext(iter) {
381
+ return await iter.next().then((res) => res.value);
944
382
  }
945
- function payloadToTransportMessage(payload, streamId, from = "client", to = "SERVER") {
946
- return msg(from, to, streamId ?? "stream", payload, "service", "procedure");
383
+ function payloadToTransportMessage(payload) {
384
+ return {
385
+ streamId: "stream",
386
+ controlFlags: 0,
387
+ payload
388
+ };
947
389
  }
948
390
  function createDummyTransportMessage() {
949
391
  return payloadToTransportMessage({
@@ -951,18 +393,15 @@ function createDummyTransportMessage() {
951
393
  test: Math.random()
952
394
  });
953
395
  }
954
- async function iterNext(iter) {
955
- return await iter.next().then((res) => res.value);
956
- }
957
396
  async function waitForMessage(t, filter, rejectMismatch) {
958
397
  return new Promise((resolve, reject) => {
959
398
  function cleanup() {
960
399
  t.removeEventListener("message", onMessage);
961
400
  }
962
- function onMessage(msg2) {
963
- if (!filter || filter?.(msg2)) {
401
+ function onMessage(msg) {
402
+ if (!filter || filter(msg)) {
964
403
  cleanup();
965
- resolve(msg2.payload);
404
+ resolve(msg.payload);
966
405
  } else if (rejectMismatch) {
967
406
  reject(new Error("message didnt match the filter"));
968
407
  }
@@ -971,7 +410,7 @@ async function waitForMessage(t, filter, rejectMismatch) {
971
410
  });
972
411
  }
973
412
  function catchProcError(err) {
974
- const errorMsg = err instanceof Error ? err.message : `[coerced to error] ${err}`;
413
+ const errorMsg = coerceErrorString(err);
975
414
  return {
976
415
  ok: false,
977
416
  payload: {
@@ -981,8 +420,8 @@ function catchProcError(err) {
981
420
  };
982
421
  }
983
422
  function asClientRpc(state, proc, extendedContext) {
984
- return async (msg2) => {
985
- return await proc.handler({ ...extendedContext, state }, msg2).catch(catchProcError);
423
+ return async (msg) => {
424
+ return await proc.handler({ ...extendedContext, state }, msg).catch(catchProcError);
986
425
  };
987
426
  }
988
427
  function asClientStream(state, proc, init, extendedContext) {
@@ -990,7 +429,7 @@ function asClientStream(state, proc, init, extendedContext) {
990
429
  const output = pushable({
991
430
  objectMode: true
992
431
  });
993
- (async () => {
432
+ void (async () => {
994
433
  if (init) {
995
434
  const _proc = proc;
996
435
  await _proc.handler({ ...extendedContext, state }, init, input, output).catch((err) => output.push(catchProcError(err)));
@@ -1005,14 +444,14 @@ function asClientSubscription(state, proc, extendedContext) {
1005
444
  const output = pushable({
1006
445
  objectMode: true
1007
446
  });
1008
- return async (msg2) => {
1009
- (async () => {
1010
- return await proc.handler({ ...extendedContext, state }, msg2, output).catch((err) => output.push(catchProcError(err)));
447
+ return (msg) => {
448
+ void (async () => {
449
+ return await proc.handler({ ...extendedContext, state }, msg, output).catch((err) => output.push(catchProcError(err)));
1011
450
  })();
1012
451
  return output;
1013
452
  };
1014
453
  }
1015
- async function asClientUpload(state, proc, init, extendedContext) {
454
+ function asClientUpload(state, proc, init, extendedContext) {
1016
455
  const input = pushable({ objectMode: true });
1017
456
  if (init) {
1018
457
  const _proc = proc;
@@ -1025,7 +464,7 @@ async function asClientUpload(state, proc, init, extendedContext) {
1025
464
  }
1026
465
  }
1027
466
  var getUnixSocketPath = () => {
1028
- return process.platform === "win32" ? `\\\\?\\pipe\\${(0, import_nanoid2.nanoid)()}` : `/tmp/${(0, import_nanoid2.nanoid)()}.sock`;
467
+ return process.platform === "win32" ? `\\\\?\\pipe\\${(0, import_nanoid.nanoid)()}` : `/tmp/${(0, import_nanoid.nanoid)()}.sock`;
1029
468
  };
1030
469
  // Annotate the CommonJS export names for ESM import in node:
1031
470
  0 && (module.exports = {
@@ -1036,10 +475,9 @@ var getUnixSocketPath = () => {
1036
475
  createDummyTransportMessage,
1037
476
  createLocalWebSocketClient,
1038
477
  createWebSocketServer,
1039
- createWsTransports,
1040
478
  getUnixSocketPath,
1041
479
  iterNext,
1042
- onUnixSocketServeReady,
480
+ onUdsServeReady,
1043
481
  onWsServerReady,
1044
482
  payloadToTransportMessage,
1045
483
  waitForMessage