@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
@@ -1,506 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
- // transport/impls/unixsocket/client.ts
21
- var client_exports = {};
22
- __export(client_exports, {
23
- UnixDomainSocketClientTransport: () => UnixDomainSocketClientTransport
24
- });
25
- module.exports = __toCommonJS(client_exports);
26
-
27
- // transport/transport.ts
28
- var import_value = require("@sinclair/typebox/value");
29
-
30
- // transport/message.ts
31
- var import_typebox = require("@sinclair/typebox");
32
- var import_nanoid = require("nanoid");
33
- var TransportMessageSchema = (t) => import_typebox.Type.Object({
34
- id: import_typebox.Type.String(),
35
- from: import_typebox.Type.String(),
36
- to: import_typebox.Type.String(),
37
- serviceName: import_typebox.Type.Optional(import_typebox.Type.Union([import_typebox.Type.String(), import_typebox.Type.Null()])),
38
- procedureName: import_typebox.Type.Optional(import_typebox.Type.Union([import_typebox.Type.String(), import_typebox.Type.Null()])),
39
- streamId: import_typebox.Type.String(),
40
- controlFlags: import_typebox.Type.Integer(),
41
- payload: t
42
- });
43
- var TransportAckSchema = TransportMessageSchema(
44
- import_typebox.Type.Object({
45
- ack: import_typebox.Type.String()
46
- })
47
- );
48
- var ControlMessagePayloadSchema = import_typebox.Type.Object({
49
- type: import_typebox.Type.Literal("CLOSE")
50
- });
51
- var OpaqueTransportMessageSchema = TransportMessageSchema(
52
- import_typebox.Type.Unknown()
53
- );
54
- function reply(msg, response) {
55
- return {
56
- id: (0, import_nanoid.nanoid)(),
57
- streamId: msg.streamId,
58
- controlFlags: 0,
59
- to: msg.from,
60
- from: msg.to,
61
- payload: response
62
- };
63
- }
64
- function isAck(controlFlag) {
65
- return (controlFlag & 1 /* AckBit */) === 1 /* AckBit */;
66
- }
67
-
68
- // logging/index.ts
69
- var log;
70
-
71
- // transport/events.ts
72
- var EventDispatcher = class {
73
- eventListeners = {};
74
- numberOfListeners(eventType) {
75
- return this.eventListeners[eventType]?.size ?? 0;
76
- }
77
- addEventListener(eventType, handler) {
78
- if (!this.eventListeners[eventType]) {
79
- this.eventListeners[eventType] = /* @__PURE__ */ new Set();
80
- }
81
- this.eventListeners[eventType]?.add(handler);
82
- }
83
- removeEventListener(eventType, handler) {
84
- const handlers = this.eventListeners[eventType];
85
- if (handlers) {
86
- this.eventListeners[eventType]?.delete(handler);
87
- }
88
- }
89
- dispatchEvent(eventType, event) {
90
- const handlers = this.eventListeners[eventType];
91
- if (handlers) {
92
- for (const handler of handlers) {
93
- handler(event);
94
- }
95
- }
96
- }
97
- };
98
-
99
- // transport/transport.ts
100
- var Connection = class {
101
- connectedTo;
102
- transport;
103
- constructor(transport, connectedTo) {
104
- this.connectedTo = connectedTo;
105
- this.transport = transport;
106
- }
107
- };
108
- var Transport = class {
109
- /**
110
- * A flag indicating whether the transport has been destroyed.
111
- * A destroyed transport will not attempt to reconnect and cannot be used again.
112
- */
113
- state;
114
- /**
115
- * The {@link Codec} used to encode and decode messages.
116
- */
117
- codec;
118
- /**
119
- * The client ID of this transport.
120
- */
121
- clientId;
122
- /**
123
- * An array of message IDs that are waiting to be sent over the WebSocket connection.
124
- * This builds up if the WebSocket is down for a period of time.
125
- */
126
- sendQueue;
127
- /**
128
- * The buffer of messages that have been sent but not yet acknowledged.
129
- */
130
- sendBuffer;
131
- /**
132
- * The map of {@link Connection}s managed by this transport.
133
- */
134
- connections;
135
- /**
136
- * The event dispatcher for handling events of type EventTypes.
137
- */
138
- eventDispatcher;
139
- /**
140
- * Creates a new Transport instance.
141
- * This should also set up {@link onConnect}, and {@link onDisconnect} listeners.
142
- * @param codec The codec used to encode and decode messages.
143
- * @param clientId The client ID of this transport.
144
- */
145
- constructor(codec, clientId) {
146
- this.eventDispatcher = new EventDispatcher();
147
- this.sendBuffer = /* @__PURE__ */ new Map();
148
- this.sendQueue = /* @__PURE__ */ new Map();
149
- this.connections = /* @__PURE__ */ new Map();
150
- this.codec = codec;
151
- this.clientId = clientId;
152
- this.state = "open";
153
- }
154
- /**
155
- * The downstream implementation needs to call this when a new connection is established.
156
- * @param conn The connection object.
157
- */
158
- onConnect(conn) {
159
- log?.info(`${this.clientId} -- new connection to ${conn.connectedTo}`);
160
- this.connections.set(conn.connectedTo, conn);
161
- this.eventDispatcher.dispatchEvent("connectionStatus", {
162
- status: "connect",
163
- conn
164
- });
165
- const outstanding = this.sendQueue.get(conn.connectedTo);
166
- if (!outstanding) {
167
- return;
168
- }
169
- for (const id of outstanding) {
170
- const msg = this.sendBuffer.get(id);
171
- if (!msg) {
172
- log?.warn(
173
- `${this.clientId} -- tried to resend a message we received an ack for`
174
- );
175
- continue;
176
- }
177
- this.send(msg);
178
- }
179
- this.sendQueue.delete(conn.connectedTo);
180
- }
181
- /**
182
- * The downstream implementation needs to call this when a connection is closed.
183
- * @param conn The connection object.
184
- */
185
- onDisconnect(conn) {
186
- log?.info(`${this.clientId} -- disconnect from ${conn.connectedTo}`);
187
- conn.close();
188
- this.connections.delete(conn.connectedTo);
189
- this.eventDispatcher.dispatchEvent("connectionStatus", {
190
- status: "disconnect",
191
- conn
192
- });
193
- }
194
- /**
195
- * Handles a message received by this transport. Thin wrapper around {@link handleMsg} and {@link parseMsg}.
196
- * @param msg The message to handle.
197
- */
198
- onMessage(msg) {
199
- return this.handleMsg(this.parseMsg(msg));
200
- }
201
- /**
202
- * Parses a message from a Uint8Array into a {@link OpaqueTransportMessage}.
203
- * @param msg The message to parse.
204
- * @returns The parsed message, or null if the message is malformed or invalid.
205
- */
206
- parseMsg(msg) {
207
- const parsedMsg = this.codec.fromBuffer(msg);
208
- if (parsedMsg === null) {
209
- const decodedBuffer = new TextDecoder().decode(msg);
210
- log?.warn(`${this.clientId} -- received malformed msg: ${decodedBuffer}`);
211
- return null;
212
- }
213
- if (import_value.Value.Check(OpaqueTransportMessageSchema, parsedMsg)) {
214
- return {
215
- ...parsedMsg,
216
- serviceName: parsedMsg.serviceName === null ? void 0 : parsedMsg.serviceName,
217
- procedureName: parsedMsg.procedureName === null ? void 0 : parsedMsg.procedureName
218
- };
219
- } else {
220
- log?.warn(
221
- `${this.clientId} -- received invalid msg: ${JSON.stringify(
222
- parsedMsg
223
- )}`
224
- );
225
- return null;
226
- }
227
- }
228
- /**
229
- * Called when a message is received by this transport.
230
- * You generally shouldn't need to override this in downstream transport implementations.
231
- * @param msg The received message.
232
- */
233
- handleMsg(msg) {
234
- if (!msg) {
235
- return;
236
- }
237
- if (isAck(msg.controlFlags) && import_value.Value.Check(TransportAckSchema, msg)) {
238
- log?.debug(`${this.clientId} -- received ack: ${JSON.stringify(msg)}`);
239
- if (this.sendBuffer.has(msg.payload.ack)) {
240
- this.sendBuffer.delete(msg.payload.ack);
241
- }
242
- } else {
243
- log?.debug(`${this.clientId} -- received msg: ${JSON.stringify(msg)}`);
244
- this.eventDispatcher.dispatchEvent("message", msg);
245
- if (!isAck(msg.controlFlags)) {
246
- const ackMsg = reply(msg, { ack: msg.id });
247
- ackMsg.controlFlags = 1 /* AckBit */;
248
- ackMsg.from = this.clientId;
249
- this.send(ackMsg);
250
- }
251
- }
252
- }
253
- /**
254
- * Adds a listener to this transport.
255
- * @param the type of event to listen for
256
- * @param handler The message handler to add.
257
- */
258
- addEventListener(type, handler) {
259
- this.eventDispatcher.addEventListener(type, handler);
260
- }
261
- /**
262
- * Removes a listener from this transport.
263
- * @param the type of event to unlisten on
264
- * @param handler The message handler to remove.
265
- */
266
- removeEventListener(type, handler) {
267
- this.eventDispatcher.removeEventListener(type, handler);
268
- }
269
- /**
270
- * Sends a message over this transport, delegating to the appropriate connection to actually
271
- * send the message.
272
- * @param msg The message to send.
273
- * @returns The ID of the sent message.
274
- */
275
- send(msg) {
276
- if (this.state === "destroyed") {
277
- const err = "transport is destroyed, cant send";
278
- log?.error(`${this.clientId} -- ` + err + `: ${JSON.stringify(msg)}`);
279
- throw new Error(err);
280
- } else if (this.state === "closed") {
281
- log?.info(
282
- `${this.clientId} -- transport closed when sending, discarding : ${JSON.stringify(
283
- msg
284
- )}`
285
- );
286
- return msg.id;
287
- }
288
- let conn = this.connections.get(msg.to);
289
- if (!isAck(msg.controlFlags)) {
290
- this.sendBuffer.set(msg.id, msg);
291
- }
292
- if (conn) {
293
- log?.debug(`${this.clientId} -- sending ${JSON.stringify(msg)}`);
294
- const ok = conn.send(this.codec.toBuffer(msg));
295
- if (ok) {
296
- return msg.id;
297
- }
298
- }
299
- log?.info(
300
- `${this.clientId} -- connection to ${msg.to} not ready, attempting reconnect and queuing ${JSON.stringify(msg)}`
301
- );
302
- const outstanding = this.sendQueue.get(msg.to) || [];
303
- outstanding.push(msg.id);
304
- this.sendQueue.set(msg.to, outstanding);
305
- this.createNewConnection(msg.to);
306
- return msg.id;
307
- }
308
- /**
309
- * Default close implementation for transports. You should override this in the downstream
310
- * implementation if you need to do any additional cleanup and call super.close() at the end.
311
- * Closes the transport. Any messages sent while the transport is closed will be silently discarded.
312
- */
313
- async close() {
314
- for (const conn of this.connections.values()) {
315
- conn.close();
316
- }
317
- this.connections.clear();
318
- this.state = "closed";
319
- log?.info(`${this.clientId} -- closed transport`);
320
- }
321
- /**
322
- * Default destroy implementation for transports. You should override this in the downstream
323
- * implementation if you need to do any additional cleanup and call super.destroy() at the end.
324
- * Destroys the transport. Any messages sent while the transport is destroyed will throw an error.
325
- */
326
- async destroy() {
327
- for (const conn of this.connections.values()) {
328
- conn.close();
329
- }
330
- this.connections.clear();
331
- this.state = "destroyed";
332
- log?.info(`${this.clientId} -- destroyed transport`);
333
- }
334
- };
335
-
336
- // codec/json.ts
337
- var encoder = new TextEncoder();
338
- var decoder = new TextDecoder();
339
- function uint8ArrayToBase64(uint8Array) {
340
- let binary = "";
341
- uint8Array.forEach((byte) => {
342
- binary += String.fromCharCode(byte);
343
- });
344
- return btoa(binary);
345
- }
346
- function base64ToUint8Array(base64) {
347
- const binaryString = atob(base64);
348
- const uint8Array = new Uint8Array(binaryString.length);
349
- for (let i = 0; i < binaryString.length; i++) {
350
- uint8Array[i] = binaryString.charCodeAt(i);
351
- }
352
- return uint8Array;
353
- }
354
- var NaiveJsonCodec = {
355
- toBuffer: (obj) => {
356
- return encoder.encode(
357
- JSON.stringify(obj, function replacer(key) {
358
- let val = this[key];
359
- if (val instanceof Uint8Array) {
360
- return { $t: uint8ArrayToBase64(val) };
361
- } else {
362
- return val;
363
- }
364
- })
365
- );
366
- },
367
- fromBuffer: (buff) => {
368
- try {
369
- return JSON.parse(decoder.decode(buff), function reviver(_key, val) {
370
- if (val?.$t) {
371
- return base64ToUint8Array(val.$t);
372
- } else {
373
- return val;
374
- }
375
- });
376
- } catch {
377
- return null;
378
- }
379
- }
380
- };
381
-
382
- // transport/transforms/delim.ts
383
- var import_node_stream = require("stream");
384
- var DelimiterParser = class extends import_node_stream.Transform {
385
- delimiter;
386
- buffer;
387
- maxBufferSizeBytes;
388
- constructor({ delimiter, maxBufferSizeBytes, ...options }) {
389
- super(options);
390
- this.maxBufferSizeBytes = maxBufferSizeBytes;
391
- this.delimiter = Buffer.from(delimiter);
392
- this.buffer = Buffer.alloc(0);
393
- }
394
- // tldr; backpressure will be automatically applied for transform streams
395
- // but it relies on both the input/output streams connected on either end having
396
- // implemented backpressure properly
397
- // see: https://nodejs.org/en/guides/backpressuring-in-streams#lifecycle-of-pipe
398
- _transform(chunk, _encoding, cb) {
399
- let data = Buffer.concat([this.buffer, chunk]);
400
- let position;
401
- while ((position = data.indexOf(this.delimiter)) !== -1) {
402
- this.push(data.subarray(0, position));
403
- data = data.subarray(position + this.delimiter.length);
404
- }
405
- if (data.byteLength > this.maxBufferSizeBytes) {
406
- const err = new Error(
407
- `buffer overflow: ${data.byteLength}B > ${this.maxBufferSizeBytes}B`
408
- );
409
- this.emit("error", err);
410
- return cb(err);
411
- }
412
- this.buffer = data;
413
- cb();
414
- }
415
- _flush(cb) {
416
- if (this.buffer.length) {
417
- this.push(this.buffer);
418
- }
419
- this.buffer = Buffer.alloc(0);
420
- cb();
421
- }
422
- _destroy(error, callback) {
423
- this.buffer = Buffer.alloc(0);
424
- super._destroy(error, callback);
425
- }
426
- };
427
- var defaultDelimiter = Buffer.from("\n");
428
- function createDelimitedStream(options) {
429
- return new DelimiterParser({
430
- delimiter: options?.delimiter ?? defaultDelimiter,
431
- maxBufferSizeBytes: options?.maxBufferSizeBytes ?? 16 * 1024 * 1024
432
- // 16MB
433
- });
434
- }
435
-
436
- // transport/impls/unixsocket/client.ts
437
- var import_node_net = require("net");
438
-
439
- // transport/impls/stdio/connection.ts
440
- var StreamConnection = class extends Connection {
441
- output;
442
- constructor(transport, connectedTo, output) {
443
- super(transport, connectedTo);
444
- this.output = output;
445
- }
446
- send(payload) {
447
- if (!this.output.writable) {
448
- return false;
449
- }
450
- return this.output.write(Buffer.concat([payload, defaultDelimiter]));
451
- }
452
- async close() {
453
- this.output.end();
454
- }
455
- };
456
-
457
- // transport/impls/unixsocket/client.ts
458
- var defaultOptions = {
459
- codec: NaiveJsonCodec
460
- };
461
- var UnixDomainSocketClientTransport = class extends Transport {
462
- path;
463
- serverId;
464
- constructor(socketPath, clientId, serverId, providedOptions) {
465
- const options = { ...defaultOptions, ...providedOptions };
466
- super(options.codec, clientId);
467
- this.path = socketPath;
468
- this.serverId = serverId;
469
- }
470
- // lazily create connection on first send to avoid cases
471
- // where we create client and server transports at the same time
472
- // but the server hasn't created the socket file yet
473
- async createNewConnection(to) {
474
- const oldConnection = this.connections.get(to);
475
- if (oldConnection) {
476
- oldConnection.close();
477
- }
478
- const sock = (0, import_node_net.createConnection)(this.path);
479
- const conn = new StreamConnection(this, to, sock);
480
- const delimStream = createDelimitedStream();
481
- sock.pipe(delimStream).on("data", (data) => {
482
- const parsedMsg = this.parseMsg(data);
483
- if (parsedMsg) {
484
- this.handleMsg(parsedMsg);
485
- }
486
- });
487
- const cleanup = () => {
488
- delimStream.destroy();
489
- if (conn) {
490
- this.onDisconnect(conn);
491
- }
492
- };
493
- sock.on("close", cleanup);
494
- sock.on("error", (err) => {
495
- log?.warn(
496
- `${this.clientId} -- socket error in connection to ${conn?.connectedTo ?? "unknown"}: ${err}`
497
- );
498
- cleanup();
499
- });
500
- this.onConnect(conn);
501
- }
502
- };
503
- // Annotate the CommonJS export names for ESM import in node:
504
- 0 && (module.exports = {
505
- UnixDomainSocketClientTransport
506
- });
@@ -1,16 +0,0 @@
1
- import { Transport, TransportClientId } from '../../index.cjs';
2
- import { C as Codec } from '../../../types-3e5768ec.js';
3
- import { S as StreamConnection } from '../../../connection-2529fc14.js';
4
- import '@sinclair/typebox';
5
-
6
- interface Options {
7
- codec: Codec;
8
- }
9
- declare class UnixDomainSocketClientTransport extends Transport<StreamConnection> {
10
- path: string;
11
- serverId: TransportClientId;
12
- constructor(socketPath: string, clientId: string, serverId: TransportClientId, providedOptions?: Partial<Options>);
13
- createNewConnection(to: string): Promise<void>;
14
- }
15
-
16
- export { UnixDomainSocketClientTransport };
@@ -1,16 +0,0 @@
1
- import { Transport, TransportClientId } from '../../index.js';
2
- import { C as Codec } from '../../../types-3e5768ec.js';
3
- import { S as StreamConnection } from '../../../connection-316d6e3a.js';
4
- import '@sinclair/typebox';
5
-
6
- interface Options {
7
- codec: Codec;
8
- }
9
- declare class UnixDomainSocketClientTransport extends Transport<StreamConnection> {
10
- path: string;
11
- serverId: TransportClientId;
12
- constructor(socketPath: string, clientId: string, serverId: TransportClientId, providedOptions?: Partial<Options>);
13
- createNewConnection(to: string): Promise<void>;
14
- }
15
-
16
- export { UnixDomainSocketClientTransport };
@@ -1,67 +0,0 @@
1
- import {
2
- StreamConnection,
3
- createDelimitedStream
4
- } from "../../../chunk-3MQETIGZ.js";
5
- import "../../../chunk-ORAG7IAU.js";
6
- import "../../../chunk-WVT5QXMZ.js";
7
- import {
8
- NaiveJsonCodec
9
- } from "../../../chunk-R6H2BIMC.js";
10
- import {
11
- Transport
12
- } from "../../../chunk-LQXPKF3A.js";
13
- import "../../../chunk-ZE4MX7DF.js";
14
- import {
15
- log
16
- } from "../../../chunk-T7M7OKPE.js";
17
-
18
- // transport/impls/unixsocket/client.ts
19
- import { createConnection } from "node:net";
20
- var defaultOptions = {
21
- codec: NaiveJsonCodec
22
- };
23
- var UnixDomainSocketClientTransport = class extends Transport {
24
- path;
25
- serverId;
26
- constructor(socketPath, clientId, serverId, providedOptions) {
27
- const options = { ...defaultOptions, ...providedOptions };
28
- super(options.codec, clientId);
29
- this.path = socketPath;
30
- this.serverId = serverId;
31
- }
32
- // lazily create connection on first send to avoid cases
33
- // where we create client and server transports at the same time
34
- // but the server hasn't created the socket file yet
35
- async createNewConnection(to) {
36
- const oldConnection = this.connections.get(to);
37
- if (oldConnection) {
38
- oldConnection.close();
39
- }
40
- const sock = createConnection(this.path);
41
- const conn = new StreamConnection(this, to, sock);
42
- const delimStream = createDelimitedStream();
43
- sock.pipe(delimStream).on("data", (data) => {
44
- const parsedMsg = this.parseMsg(data);
45
- if (parsedMsg) {
46
- this.handleMsg(parsedMsg);
47
- }
48
- });
49
- const cleanup = () => {
50
- delimStream.destroy();
51
- if (conn) {
52
- this.onDisconnect(conn);
53
- }
54
- };
55
- sock.on("close", cleanup);
56
- sock.on("error", (err) => {
57
- log?.warn(
58
- `${this.clientId} -- socket error in connection to ${conn?.connectedTo ?? "unknown"}: ${err}`
59
- );
60
- cleanup();
61
- });
62
- this.onConnect(conn);
63
- }
64
- };
65
- export {
66
- UnixDomainSocketClientTransport
67
- };