@replit/river 0.12.6 → 0.13.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 (51) hide show
  1. package/README.md +4 -1
  2. package/dist/{builder-c593de11.d.ts → builder-169fbf7f.d.ts} +16 -7
  3. package/dist/{chunk-AFLZ6INU.js → chunk-CBRQM65K.js} +29 -10
  4. package/dist/{chunk-IIBVKYDB.js → chunk-CDH7QSB4.js} +39 -1
  5. package/dist/{chunk-XFFS4UOD.js → chunk-MGGIUH5O.js} +7 -7
  6. package/dist/{chunk-VLBVQX5H.js → chunk-NPXAAD7M.js} +1 -1
  7. package/dist/{chunk-4SDJ5VN4.js → chunk-R2IMXRVU.js} +150 -116
  8. package/dist/{connection-ba37d174.d.ts → connection-ab681c08.d.ts} +1 -1
  9. package/dist/{messageFraming-b200ef25.d.ts → connection-dd789651.d.ts} +17 -2
  10. package/dist/{index-54e0f99c.d.ts → index-21c1b21d.d.ts} +29 -13
  11. package/dist/router/index.cjs +31 -13
  12. package/dist/router/index.d.cts +5 -5
  13. package/dist/router/index.d.ts +5 -5
  14. package/dist/router/index.js +2 -2
  15. package/dist/transport/impls/uds/client.cjs +143 -121
  16. package/dist/transport/impls/uds/client.d.cts +2 -3
  17. package/dist/transport/impls/uds/client.d.ts +2 -3
  18. package/dist/transport/impls/uds/client.js +5 -6
  19. package/dist/transport/impls/uds/server.cjs +151 -127
  20. package/dist/transport/impls/uds/server.d.cts +2 -3
  21. package/dist/transport/impls/uds/server.d.ts +2 -3
  22. package/dist/transport/impls/uds/server.js +4 -5
  23. package/dist/transport/impls/ws/client.cjs +147 -123
  24. package/dist/transport/impls/ws/client.d.cts +4 -4
  25. package/dist/transport/impls/ws/client.d.ts +4 -4
  26. package/dist/transport/impls/ws/client.js +7 -7
  27. package/dist/transport/impls/ws/server.cjs +151 -127
  28. package/dist/transport/impls/ws/server.d.cts +2 -2
  29. package/dist/transport/impls/ws/server.d.ts +2 -2
  30. package/dist/transport/impls/ws/server.js +4 -4
  31. package/dist/transport/index.cjs +202 -167
  32. package/dist/transport/index.d.cts +1 -1
  33. package/dist/transport/index.d.ts +1 -1
  34. package/dist/transport/index.js +3 -3
  35. package/dist/util/testHelpers.cjs +294 -16
  36. package/dist/util/testHelpers.d.cts +2 -2
  37. package/dist/util/testHelpers.d.ts +2 -2
  38. package/dist/util/testHelpers.js +30 -8
  39. package/package.json +1 -9
  40. package/dist/chunk-PBPXYLI6.js +0 -44
  41. package/dist/chunk-Q7GL34DZ.js +0 -47
  42. package/dist/connection-1f9971d8.d.ts +0 -17
  43. package/dist/connection-24d878ac.d.ts +0 -18
  44. package/dist/transport/impls/stdio/client.cjs +0 -904
  45. package/dist/transport/impls/stdio/client.d.cts +0 -27
  46. package/dist/transport/impls/stdio/client.d.ts +0 -27
  47. package/dist/transport/impls/stdio/client.js +0 -42
  48. package/dist/transport/impls/stdio/server.cjs +0 -879
  49. package/dist/transport/impls/stdio/server.d.cts +0 -25
  50. package/dist/transport/impls/stdio/server.d.ts +0 -25
  51. package/dist/transport/impls/stdio/server.js +0 -33
@@ -48,6 +48,276 @@ module.exports = __toCommonJS(testHelpers_exports);
48
48
  var import_isomorphic_ws = __toESM(require("isomorphic-ws"), 1);
49
49
  var import_ws = require("ws");
50
50
 
51
+ // logging/index.ts
52
+ var log;
53
+
54
+ // transport/session.ts
55
+ var import_nanoid = require("nanoid");
56
+
57
+ // codec/json.ts
58
+ var encoder = new TextEncoder();
59
+ var decoder = new TextDecoder();
60
+ function uint8ArrayToBase64(uint8Array) {
61
+ let binary = "";
62
+ uint8Array.forEach((byte) => {
63
+ binary += String.fromCharCode(byte);
64
+ });
65
+ return btoa(binary);
66
+ }
67
+ function base64ToUint8Array(base64) {
68
+ const binaryString = atob(base64);
69
+ const uint8Array = new Uint8Array(binaryString.length);
70
+ for (let i = 0; i < binaryString.length; i++) {
71
+ uint8Array[i] = binaryString.charCodeAt(i);
72
+ }
73
+ return uint8Array;
74
+ }
75
+ var NaiveJsonCodec = {
76
+ toBuffer: (obj) => {
77
+ return encoder.encode(
78
+ JSON.stringify(obj, function replacer(key) {
79
+ const val = this[key];
80
+ if (val instanceof Uint8Array) {
81
+ return { $t: uint8ArrayToBase64(val) };
82
+ } else {
83
+ return val;
84
+ }
85
+ })
86
+ );
87
+ },
88
+ fromBuffer: (buff) => {
89
+ try {
90
+ const parsed = JSON.parse(
91
+ decoder.decode(buff),
92
+ function reviver(_key, val) {
93
+ if (val?.$t) {
94
+ return base64ToUint8Array(val.$t);
95
+ } else {
96
+ return val;
97
+ }
98
+ }
99
+ );
100
+ if (typeof parsed === "object")
101
+ return parsed;
102
+ return null;
103
+ } catch {
104
+ return null;
105
+ }
106
+ }
107
+ };
108
+
109
+ // transport/session.ts
110
+ var nanoid = (0, import_nanoid.customAlphabet)("1234567890abcdefghijklmnopqrstuvxyz", 6);
111
+ var unsafeId = () => nanoid();
112
+ var HEARTBEAT_INTERVAL_MS = 1e3;
113
+ var HEARTBEATS_TILL_DEAD = 2;
114
+ var SESSION_DISCONNECT_GRACE_MS = 5e3;
115
+ var defaultSessionOptions = {
116
+ heartbeatIntervalMs: HEARTBEAT_INTERVAL_MS,
117
+ heartbeatsUntilDead: HEARTBEATS_TILL_DEAD,
118
+ sessionDisconnectGraceMs: SESSION_DISCONNECT_GRACE_MS,
119
+ codec: NaiveJsonCodec
120
+ };
121
+ var Session = class {
122
+ codec;
123
+ options;
124
+ /**
125
+ * The buffer of messages that have been sent but not yet acknowledged.
126
+ */
127
+ sendBuffer = [];
128
+ /**
129
+ * The active connection associated with this session
130
+ */
131
+ connection;
132
+ from;
133
+ to;
134
+ /**
135
+ * The unique ID of this session.
136
+ */
137
+ debugId;
138
+ /**
139
+ * Number of messages we've sent along this session (excluding handshake)
140
+ */
141
+ seq = 0;
142
+ /**
143
+ * Number of unique messages we've received this session (excluding handshake)
144
+ */
145
+ ack = 0;
146
+ /**
147
+ * The grace period between when the inner connection is disconnected
148
+ * and when we should consider the entire session disconnected.
149
+ */
150
+ disconnectionGrace;
151
+ /**
152
+ * Number of heartbeats we've sent without a response.
153
+ */
154
+ heartbeatMisses;
155
+ /**
156
+ * The interval for sending heartbeats.
157
+ */
158
+ heartbeat;
159
+ constructor(from, connectedTo, conn, options) {
160
+ this.options = options;
161
+ this.debugId = `sess-${unsafeId()}`;
162
+ this.from = from;
163
+ this.to = connectedTo;
164
+ this.connection = conn;
165
+ this.codec = options.codec;
166
+ this.heartbeatMisses = 0;
167
+ this.heartbeat = setInterval(
168
+ () => this.sendHeartbeat(),
169
+ options.heartbeatIntervalMs
170
+ );
171
+ }
172
+ /**
173
+ * Sends a message over the session's connection.
174
+ * If the connection is not ready or the message fails to send, the message can be buffered for retry unless skipped.
175
+ *
176
+ * @param msg The partial message to be sent, which will be constructed into a full message.
177
+ * @param skipRetry Optional. If true, the message will not be buffered for retry on failure. This should only be used for
178
+ * ack hearbeats, which contain information that can already be found in the other buffered messages.
179
+ * @returns The full transport ID of the message that was attempted to be sent.
180
+ */
181
+ send(msg, skipRetry) {
182
+ const fullMsg = this.constructMsg(msg);
183
+ log?.debug(`${this.from} -- sending ${JSON.stringify(fullMsg)}`);
184
+ if (this.connection) {
185
+ const ok = this.connection.send(this.codec.toBuffer(fullMsg));
186
+ if (ok)
187
+ return fullMsg.id;
188
+ log?.info(
189
+ `${this.from} -- failed to send ${fullMsg.id} to ${fullMsg.to}, connection (id: ${this.connection.debugId}) is probably dead`
190
+ );
191
+ } else {
192
+ log?.info(
193
+ `${this.from} -- failed to send ${fullMsg.id} to ${fullMsg.to}, connection not ready yet`
194
+ );
195
+ }
196
+ if (skipRetry)
197
+ return fullMsg.id;
198
+ this.addToSendBuff(fullMsg);
199
+ log?.info(
200
+ `${this.from} -- buffering msg ${fullMsg.id} until connection is healthy again`
201
+ );
202
+ return fullMsg.id;
203
+ }
204
+ sendHeartbeat() {
205
+ if (this.heartbeatMisses >= this.options.heartbeatsUntilDead) {
206
+ if (this.connection) {
207
+ log?.info(
208
+ `${this.from} -- closing connection (id: ${this.connection.debugId}) to ${this.to} due to inactivity`
209
+ );
210
+ this.closeStaleConnection(this.connection);
211
+ }
212
+ return;
213
+ }
214
+ this.send(
215
+ {
216
+ streamId: "heartbeat",
217
+ controlFlags: 1 /* AckBit */,
218
+ payload: {
219
+ type: "ACK"
220
+ }
221
+ },
222
+ true
223
+ );
224
+ this.heartbeatMisses++;
225
+ }
226
+ resetBufferedMessages() {
227
+ this.sendBuffer = [];
228
+ this.seq = 0;
229
+ this.ack = 0;
230
+ }
231
+ sendBufferedMessages() {
232
+ if (!this.connection) {
233
+ const msg = `${this.from} -- tried sending buffered messages without a connection (if you hit this code path something is seriously wrong)`;
234
+ log?.error(msg);
235
+ throw new Error(msg);
236
+ }
237
+ for (const msg of this.sendBuffer) {
238
+ log?.debug(`${this.from} -- resending ${JSON.stringify(msg)}`);
239
+ const ok = this.connection.send(this.codec.toBuffer(msg));
240
+ if (!ok) {
241
+ const msg2 = `${this.from} -- failed to send buffered message to ${this.to} in session (id: ${this.debugId}) (if you hit this code path something is seriously wrong)`;
242
+ log?.error(msg2);
243
+ throw new Error(msg2);
244
+ }
245
+ }
246
+ }
247
+ updateBookkeeping(ack, seq) {
248
+ this.sendBuffer = this.sendBuffer.filter((unacked) => unacked.seq > ack);
249
+ this.ack = seq + 1;
250
+ }
251
+ addToSendBuff(msg) {
252
+ this.sendBuffer.push(msg);
253
+ log?.debug(
254
+ `${this.from} -- send buff to ${this.to} now tracking ${this.sendBuffer.length} messages`
255
+ );
256
+ }
257
+ closeStaleConnection(conn) {
258
+ if (!this.connection || this.connection !== conn)
259
+ return;
260
+ log?.info(
261
+ `${this.from} -- closing old inner connection (id: ${this.connection.debugId}) from session (id: ${this.debugId}) to ${this.to}`
262
+ );
263
+ this.connection.close();
264
+ this.connection = void 0;
265
+ }
266
+ replaceWithNewConnection(newConn) {
267
+ this.closeStaleConnection(this.connection);
268
+ this.cancelGrace();
269
+ this.connection = newConn;
270
+ }
271
+ beginGrace(cb) {
272
+ this.disconnectionGrace = setTimeout(() => {
273
+ this.close();
274
+ cb();
275
+ }, this.options.sessionDisconnectGraceMs);
276
+ }
277
+ // called on reconnect of the underlying session
278
+ cancelGrace() {
279
+ this.heartbeatMisses = 0;
280
+ clearTimeout(this.disconnectionGrace);
281
+ }
282
+ // closed when we want to discard the whole session
283
+ // (i.e. shutdown or session disconnect)
284
+ close() {
285
+ this.closeStaleConnection(this.connection);
286
+ this.cancelGrace();
287
+ this.resetBufferedMessages();
288
+ clearInterval(this.heartbeat);
289
+ }
290
+ get connected() {
291
+ return this.connection !== void 0;
292
+ }
293
+ get nextExpectedSeq() {
294
+ return this.ack;
295
+ }
296
+ constructMsg(partialMsg) {
297
+ const msg = {
298
+ ...partialMsg,
299
+ id: unsafeId(),
300
+ to: this.to,
301
+ from: this.from,
302
+ seq: this.seq,
303
+ ack: this.ack
304
+ };
305
+ this.seq++;
306
+ return msg;
307
+ }
308
+ inspectSendBuffer() {
309
+ return this.sendBuffer;
310
+ }
311
+ };
312
+
313
+ // util/stringify.ts
314
+ function coerceErrorString(err) {
315
+ if (err instanceof Error) {
316
+ return err.message;
317
+ }
318
+ return `[coerced to error] ${String(err)}`;
319
+ }
320
+
51
321
  // node_modules/p-defer/index.js
52
322
  function pDefer() {
53
323
  const deferred = {};
@@ -342,16 +612,8 @@ var RiverUncaughtSchema = import_typebox.Type.Object({
342
612
  message: import_typebox.Type.String()
343
613
  });
344
614
 
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
-
353
615
  // util/testHelpers.ts
354
- var import_nanoid = require("nanoid");
616
+ var import_nanoid2 = require("nanoid");
355
617
  function createWebSocketServer(server) {
356
618
  return new import_ws.WebSocketServer({ server });
357
619
  }
@@ -419,9 +681,25 @@ function catchProcError(err) {
419
681
  }
420
682
  };
421
683
  }
684
+ function dummyCtx(state, extendedContext) {
685
+ const session = new Session(
686
+ "client",
687
+ "SERVER",
688
+ void 0,
689
+ defaultSessionOptions
690
+ );
691
+ return {
692
+ ...extendedContext,
693
+ state,
694
+ to: "SERVER",
695
+ from: "client",
696
+ streamId: (0, import_nanoid2.nanoid)(),
697
+ session
698
+ };
699
+ }
422
700
  function asClientRpc(state, proc, extendedContext) {
423
701
  return async (msg) => {
424
- return await proc.handler({ ...extendedContext, state }, msg).catch(catchProcError);
702
+ return await proc.handler(dummyCtx(state, extendedContext), msg).catch(catchProcError);
425
703
  };
426
704
  }
427
705
  function asClientStream(state, proc, init, extendedContext) {
@@ -432,10 +710,10 @@ function asClientStream(state, proc, init, extendedContext) {
432
710
  void (async () => {
433
711
  if (init) {
434
712
  const _proc = proc;
435
- await _proc.handler({ ...extendedContext, state }, init, input, output).catch((err) => output.push(catchProcError(err)));
713
+ await _proc.handler(dummyCtx(state, extendedContext), init, input, output).catch((err) => output.push(catchProcError(err)));
436
714
  } else {
437
715
  const _proc = proc;
438
- await _proc.handler({ ...extendedContext, state }, input, output).catch((err) => output.push(catchProcError(err)));
716
+ await _proc.handler(dummyCtx(state, extendedContext), input, output).catch((err) => output.push(catchProcError(err)));
439
717
  }
440
718
  })();
441
719
  return [input, output];
@@ -446,7 +724,7 @@ function asClientSubscription(state, proc, extendedContext) {
446
724
  });
447
725
  return (msg) => {
448
726
  void (async () => {
449
- return await proc.handler({ ...extendedContext, state }, msg, output).catch((err) => output.push(catchProcError(err)));
727
+ return await proc.handler(dummyCtx(state, extendedContext), msg, output).catch((err) => output.push(catchProcError(err)));
450
728
  })();
451
729
  return output;
452
730
  };
@@ -455,16 +733,16 @@ function asClientUpload(state, proc, init, extendedContext) {
455
733
  const input = pushable({ objectMode: true });
456
734
  if (init) {
457
735
  const _proc = proc;
458
- const result = _proc.handler({ ...extendedContext, state }, init, input).catch(catchProcError);
736
+ const result = _proc.handler(dummyCtx(state, extendedContext), init, input).catch(catchProcError);
459
737
  return [input, result];
460
738
  } else {
461
739
  const _proc = proc;
462
- const result = _proc.handler({ ...extendedContext, state }, input).catch(catchProcError);
740
+ const result = _proc.handler(dummyCtx(state, extendedContext), input).catch(catchProcError);
463
741
  return [input, result];
464
742
  }
465
743
  }
466
744
  var getUnixSocketPath = () => {
467
- return process.platform === "win32" ? `\\\\?\\pipe\\${(0, import_nanoid.nanoid)()}` : `/tmp/${(0, import_nanoid.nanoid)()}.sock`;
745
+ return process.platform === "win32" ? `\\\\?\\pipe\\${(0, import_nanoid2.nanoid)()}` : `/tmp/${(0, import_nanoid2.nanoid)()}.sock`;
468
746
  };
469
747
  // Annotate the CommonJS export names for ESM import in node:
470
748
  0 && (module.exports = {
@@ -1,8 +1,8 @@
1
1
  import * as it_pushable from 'it-pushable';
2
2
  import WebSocket from 'isomorphic-ws';
3
3
  import http from 'node:http';
4
- import { P as PartialTransportMessage, T as Transport, C as Connection, O as OpaqueTransportMessage } from '../index-54e0f99c.js';
5
- import { P as PayloadType, R as RiverError, a as Procedure, S as ServiceContext, b as Result, c as RiverUncaughtSchema } from '../builder-c593de11.js';
4
+ import { P as PartialTransportMessage, T as Transport, C as Connection, O as OpaqueTransportMessage } from '../index-21c1b21d.js';
5
+ import { P as PayloadType, R as RiverError, a as Procedure, S as ServiceContext, b as Result, c as RiverUncaughtSchema } from '../builder-169fbf7f.js';
6
6
  import { Static } from '@sinclair/typebox';
7
7
  import net from 'node:net';
8
8
  import '../types-3e5768ec.js';
@@ -1,8 +1,8 @@
1
1
  import * as it_pushable from 'it-pushable';
2
2
  import WebSocket from 'isomorphic-ws';
3
3
  import http from 'node:http';
4
- import { P as PartialTransportMessage, T as Transport, C as Connection, O as OpaqueTransportMessage } from '../index-54e0f99c.js';
5
- import { P as PayloadType, R as RiverError, a as Procedure, S as ServiceContext, b as Result, c as RiverUncaughtSchema } from '../builder-c593de11.js';
4
+ import { P as PartialTransportMessage, T as Transport, C as Connection, O as OpaqueTransportMessage } from '../index-21c1b21d.js';
5
+ import { P as PayloadType, R as RiverError, a as Procedure, S as ServiceContext, b as Result, c as RiverUncaughtSchema } from '../builder-169fbf7f.js';
6
6
  import { Static } from '@sinclair/typebox';
7
7
  import net from 'node:net';
8
8
  import '../types-3e5768ec.js';
@@ -1,11 +1,17 @@
1
1
  import {
2
2
  UNCAUGHT_ERROR,
3
3
  pushable
4
- } from "../chunk-AFLZ6INU.js";
4
+ } from "../chunk-CBRQM65K.js";
5
+ import "../chunk-5IZ2UHWV.js";
6
+ import {
7
+ Session,
8
+ defaultSessionOptions
9
+ } from "../chunk-R2IMXRVU.js";
5
10
  import {
6
11
  coerceErrorString
7
- } from "../chunk-XFFS4UOD.js";
12
+ } from "../chunk-MGGIUH5O.js";
8
13
  import "../chunk-H4BYJELI.js";
14
+ import "../chunk-GZ7HCLLM.js";
9
15
 
10
16
  // util/testHelpers.ts
11
17
  import WebSocket from "isomorphic-ws";
@@ -78,9 +84,25 @@ function catchProcError(err) {
78
84
  }
79
85
  };
80
86
  }
87
+ function dummyCtx(state, extendedContext) {
88
+ const session = new Session(
89
+ "client",
90
+ "SERVER",
91
+ void 0,
92
+ defaultSessionOptions
93
+ );
94
+ return {
95
+ ...extendedContext,
96
+ state,
97
+ to: "SERVER",
98
+ from: "client",
99
+ streamId: nanoid(),
100
+ session
101
+ };
102
+ }
81
103
  function asClientRpc(state, proc, extendedContext) {
82
104
  return async (msg) => {
83
- return await proc.handler({ ...extendedContext, state }, msg).catch(catchProcError);
105
+ return await proc.handler(dummyCtx(state, extendedContext), msg).catch(catchProcError);
84
106
  };
85
107
  }
86
108
  function asClientStream(state, proc, init, extendedContext) {
@@ -91,10 +113,10 @@ function asClientStream(state, proc, init, extendedContext) {
91
113
  void (async () => {
92
114
  if (init) {
93
115
  const _proc = proc;
94
- await _proc.handler({ ...extendedContext, state }, init, input, output).catch((err) => output.push(catchProcError(err)));
116
+ await _proc.handler(dummyCtx(state, extendedContext), init, input, output).catch((err) => output.push(catchProcError(err)));
95
117
  } else {
96
118
  const _proc = proc;
97
- await _proc.handler({ ...extendedContext, state }, input, output).catch((err) => output.push(catchProcError(err)));
119
+ await _proc.handler(dummyCtx(state, extendedContext), input, output).catch((err) => output.push(catchProcError(err)));
98
120
  }
99
121
  })();
100
122
  return [input, output];
@@ -105,7 +127,7 @@ function asClientSubscription(state, proc, extendedContext) {
105
127
  });
106
128
  return (msg) => {
107
129
  void (async () => {
108
- return await proc.handler({ ...extendedContext, state }, msg, output).catch((err) => output.push(catchProcError(err)));
130
+ return await proc.handler(dummyCtx(state, extendedContext), msg, output).catch((err) => output.push(catchProcError(err)));
109
131
  })();
110
132
  return output;
111
133
  };
@@ -114,11 +136,11 @@ function asClientUpload(state, proc, init, extendedContext) {
114
136
  const input = pushable({ objectMode: true });
115
137
  if (init) {
116
138
  const _proc = proc;
117
- const result = _proc.handler({ ...extendedContext, state }, init, input).catch(catchProcError);
139
+ const result = _proc.handler(dummyCtx(state, extendedContext), init, input).catch(catchProcError);
118
140
  return [input, result];
119
141
  } else {
120
142
  const _proc = proc;
121
- const result = _proc.handler({ ...extendedContext, state }, input).catch(catchProcError);
143
+ const result = _proc.handler(dummyCtx(state, extendedContext), input).catch(catchProcError);
122
144
  return [input, result];
123
145
  }
124
146
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@replit/river",
3
3
  "description": "It's like tRPC but... with JSON Schema Support, duplex streaming and support for service multiplexing. Transport agnostic!",
4
- "version": "0.12.6",
4
+ "version": "0.13.0",
5
5
  "type": "module",
6
6
  "exports": {
7
7
  ".": {
@@ -36,14 +36,6 @@
36
36
  "import": "./dist/transport/impls/uds/server.js",
37
37
  "require": "./dist/transport/impls/uds/server.cjs"
38
38
  },
39
- "./transport/stdio/client": {
40
- "import": "./dist/transport/impls/stdio/client.js",
41
- "require": "./dist/transport/impls/stdio/client.cjs"
42
- },
43
- "./transport/stdio/server": {
44
- "import": "./dist/transport/impls/stdio/server.js",
45
- "require": "./dist/transport/impls/stdio/server.cjs"
46
- },
47
39
  "./test-util": {
48
40
  "import": "./dist/util/testHelpers.js",
49
41
  "require": "./dist/util/testHelpers.cjs"
@@ -1,44 +0,0 @@
1
- import {
2
- MessageFramer
3
- } from "./chunk-IIBVKYDB.js";
4
- import {
5
- Connection
6
- } from "./chunk-4SDJ5VN4.js";
7
-
8
- // transport/impls/uds/connection.ts
9
- var UdsConnection = class extends Connection {
10
- sock;
11
- input;
12
- framer;
13
- constructor(sock) {
14
- super();
15
- this.framer = MessageFramer.createFramedStream();
16
- this.sock = sock;
17
- this.input = sock.pipe(this.framer);
18
- }
19
- addDataListener(cb) {
20
- this.input.on("data", cb);
21
- }
22
- removeDataListener(cb) {
23
- this.input.off("data", cb);
24
- }
25
- addCloseListener(cb) {
26
- this.sock.on("close", cb);
27
- }
28
- addErrorListener(cb) {
29
- this.sock.on("error", cb);
30
- }
31
- send(payload) {
32
- if (this.framer.destroyed || !this.sock.writable)
33
- return false;
34
- return this.sock.write(MessageFramer.write(payload));
35
- }
36
- close() {
37
- this.sock.destroy();
38
- this.framer.destroy();
39
- }
40
- };
41
-
42
- export {
43
- UdsConnection
44
- };
@@ -1,47 +0,0 @@
1
- import {
2
- MessageFramer
3
- } from "./chunk-IIBVKYDB.js";
4
- import {
5
- Connection
6
- } from "./chunk-4SDJ5VN4.js";
7
-
8
- // transport/impls/stdio/connection.ts
9
- var StreamConnection = class extends Connection {
10
- input;
11
- output;
12
- framer;
13
- constructor(input, output) {
14
- super();
15
- this.framer = MessageFramer.createFramedStream();
16
- this.input = input.pipe(this.framer);
17
- this.output = output;
18
- }
19
- addDataListener(cb) {
20
- this.input.on("data", cb);
21
- }
22
- removeDataListener(cb) {
23
- this.input.off("data", cb);
24
- }
25
- addCloseListener(cb) {
26
- this.input.on("close", cb);
27
- this.output.on("close", cb);
28
- }
29
- addErrorListener(cb) {
30
- this.input.on("error", cb);
31
- this.output.on("error", cb);
32
- }
33
- send(payload) {
34
- if (!this.output.writable)
35
- return false;
36
- return this.output.write(MessageFramer.write(payload));
37
- }
38
- close() {
39
- this.output.end();
40
- this.input.unpipe(this.framer);
41
- this.framer.destroy();
42
- }
43
- };
44
-
45
- export {
46
- StreamConnection
47
- };
@@ -1,17 +0,0 @@
1
- import { C as Connection } from './index-54e0f99c.js';
2
- import { U as Uint32LengthPrefixFraming } from './messageFraming-b200ef25.js';
3
-
4
- declare class StreamConnection extends Connection {
5
- input: NodeJS.ReadableStream;
6
- output: NodeJS.WritableStream;
7
- framer: Uint32LengthPrefixFraming;
8
- constructor(input: NodeJS.ReadableStream, output: NodeJS.WritableStream);
9
- addDataListener(cb: (msg: Uint8Array) => void): void;
10
- removeDataListener(cb: (msg: Uint8Array) => void): void;
11
- addCloseListener(cb: () => void): void;
12
- addErrorListener(cb: (err: Error) => void): void;
13
- send(payload: Uint8Array): boolean;
14
- close(): void;
15
- }
16
-
17
- export { StreamConnection as S };
@@ -1,18 +0,0 @@
1
- import { C as Connection } from './index-54e0f99c.js';
2
- import { Socket } from 'node:net';
3
- import { U as Uint32LengthPrefixFraming } from './messageFraming-b200ef25.js';
4
-
5
- declare class UdsConnection extends Connection {
6
- sock: Socket;
7
- input: NodeJS.ReadableStream;
8
- framer: Uint32LengthPrefixFraming;
9
- constructor(sock: Socket);
10
- addDataListener(cb: (msg: Uint8Array) => void): void;
11
- removeDataListener(cb: (msg: Uint8Array) => void): void;
12
- addCloseListener(cb: () => void): void;
13
- addErrorListener(cb: (err: Error) => void): void;
14
- send(payload: Uint8Array): boolean;
15
- close(): void;
16
- }
17
-
18
- export { UdsConnection as U };