@replit/river 0.11.0 → 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 (82) 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-GKPT5YQE.js → chunk-IIBVKYDB.js} +6 -34
  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-5IC5XMWK.js +0 -140
  61. package/dist/chunk-L7D75G4K.js +0 -29
  62. package/dist/chunk-LQXPKF3A.js +0 -282
  63. package/dist/chunk-PJ2EUO7O.js +0 -63
  64. package/dist/chunk-WVT5QXMZ.js +0 -20
  65. package/dist/chunk-ZE4MX7DF.js +0 -75
  66. package/dist/connection-2529fc14.d.ts +0 -10
  67. package/dist/connection-316d6e3a.d.ts +0 -10
  68. package/dist/connection-8e19874c.d.ts +0 -11
  69. package/dist/connection-f7688cc1.d.ts +0 -11
  70. package/dist/transport/impls/stdio/stdio.cjs +0 -518
  71. package/dist/transport/impls/stdio/stdio.d.cts +0 -26
  72. package/dist/transport/impls/stdio/stdio.d.ts +0 -26
  73. package/dist/transport/impls/stdio/stdio.js +0 -70
  74. package/dist/transport/impls/unixsocket/client.cjs +0 -516
  75. package/dist/transport/impls/unixsocket/client.d.cts +0 -16
  76. package/dist/transport/impls/unixsocket/client.d.ts +0 -16
  77. package/dist/transport/impls/unixsocket/client.js +0 -67
  78. package/dist/transport/impls/unixsocket/server.cjs +0 -520
  79. package/dist/transport/impls/unixsocket/server.d.cts +0 -18
  80. package/dist/transport/impls/unixsocket/server.d.ts +0 -18
  81. package/dist/transport/impls/unixsocket/server.js +0 -73
  82. /package/dist/{chunk-ORAG7IAU.js → chunk-5IZ2UHWV.js} +0 -0
@@ -1,520 +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/server.ts
21
- var server_exports = {};
22
- __export(server_exports, {
23
- UnixDomainSocketServerTransport: () => UnixDomainSocketServerTransport
24
- });
25
- module.exports = __toCommonJS(server_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/messageFraming.ts
383
- var import_node_stream = require("stream");
384
- var Uint32LengthPrefixFraming = class extends import_node_stream.Transform {
385
- receivedBuffer;
386
- maxBufferSizeBytes;
387
- constructor({
388
- preAllocatedBufferSize,
389
- maxBufferSizeBytes,
390
- ...options
391
- }) {
392
- super(options);
393
- this.maxBufferSizeBytes = maxBufferSizeBytes;
394
- this.receivedBuffer = Buffer.alloc(preAllocatedBufferSize);
395
- }
396
- _transform(chunk, _encoding, cb) {
397
- if (this.receivedBuffer.byteLength + chunk.byteLength > this.maxBufferSizeBytes) {
398
- const err = new Error(
399
- `buffer overflow: ${this.receivedBuffer.byteLength}B > ${this.maxBufferSizeBytes}B`
400
- );
401
- this.emit("error", err);
402
- return cb(err);
403
- }
404
- this.receivedBuffer = Buffer.concat([this.receivedBuffer, chunk]);
405
- while (this.receivedBuffer.length > 4) {
406
- const claimedMessageLength = this.receivedBuffer.readUInt32BE(0) + 4;
407
- if (this.receivedBuffer.length >= claimedMessageLength) {
408
- const message = this.receivedBuffer.subarray(4, claimedMessageLength);
409
- this.push(message);
410
- this.receivedBuffer = this.receivedBuffer.subarray(claimedMessageLength);
411
- } else {
412
- break;
413
- }
414
- }
415
- cb();
416
- }
417
- _flush(cb) {
418
- if (this.receivedBuffer.length) {
419
- this.emit("error", new Error("got incomplete message while flushing"));
420
- }
421
- this.receivedBuffer = Buffer.alloc(0);
422
- cb();
423
- }
424
- _destroy(error, callback) {
425
- this.receivedBuffer = Buffer.alloc(0);
426
- super._destroy(error, callback);
427
- }
428
- };
429
- function createLengthEncodedStream(options) {
430
- return new Uint32LengthPrefixFraming({
431
- maxBufferSizeBytes: options?.maxBufferSizeBytes ?? 16 * 1024 * 1024,
432
- // 16MB
433
- preAllocatedBufferSize: options?.preAllocatedBufferSize ?? 16 * 1024
434
- // 16KB
435
- });
436
- }
437
- var MessageFramer = {
438
- createFramedStream: createLengthEncodedStream,
439
- write: (buf) => {
440
- const lengthPrefix = Buffer.alloc(4);
441
- lengthPrefix.writeUInt32BE(buf.length, 0);
442
- return Buffer.concat([lengthPrefix, buf]);
443
- }
444
- };
445
-
446
- // transport/impls/stdio/connection.ts
447
- var StreamConnection = class extends Connection {
448
- output;
449
- constructor(transport, connectedTo, output) {
450
- super(transport, connectedTo);
451
- this.output = output;
452
- }
453
- send(payload) {
454
- if (!this.output.writable) {
455
- return false;
456
- }
457
- return this.output.write(MessageFramer.write(payload));
458
- }
459
- async close() {
460
- this.output.end();
461
- }
462
- };
463
-
464
- // transport/impls/unixsocket/server.ts
465
- var defaultOptions = {
466
- codec: NaiveJsonCodec
467
- };
468
- var UnixDomainSocketServerTransport = class extends Transport {
469
- server;
470
- constructor(server, clientId, providedOptions) {
471
- const options = { ...defaultOptions, ...providedOptions };
472
- super(options.codec, clientId);
473
- this.server = server;
474
- server.addListener("connection", this.connectionListener);
475
- server.on("listening", () => {
476
- log?.info(`${this.clientId} -- server is listening`);
477
- });
478
- }
479
- connectionListener = (sock) => {
480
- let conn = void 0;
481
- const framedMessageStream = MessageFramer.createFramedStream();
482
- sock.pipe(framedMessageStream).on("data", (data) => {
483
- const parsedMsg = this.parseMsg(data);
484
- if (!parsedMsg) {
485
- return;
486
- }
487
- if (!conn) {
488
- conn = new StreamConnection(this, parsedMsg.from, sock);
489
- this.onConnect(conn);
490
- }
491
- this.handleMsg(parsedMsg);
492
- });
493
- const cleanup = () => {
494
- framedMessageStream.destroy();
495
- if (conn) {
496
- this.onDisconnect(conn);
497
- }
498
- };
499
- sock.on("close", cleanup);
500
- sock.on("error", (err) => {
501
- log?.warn(
502
- `${this.clientId} -- socket error in connection to ${conn?.connectedTo ?? "unknown"}: ${err}`
503
- );
504
- cleanup();
505
- });
506
- };
507
- async createNewConnection(to) {
508
- const err = `${this.clientId} -- failed to send msg to ${to}, client probably dropped`;
509
- log?.warn(err);
510
- return;
511
- }
512
- async close() {
513
- this.server.removeListener("connection", this.connectionListener);
514
- super.close();
515
- }
516
- };
517
- // Annotate the CommonJS export names for ESM import in node:
518
- 0 && (module.exports = {
519
- UnixDomainSocketServerTransport
520
- });
@@ -1,18 +0,0 @@
1
- import { Transport, TransportClientId } from '../../index.cjs';
2
- import { C as Codec } from '../../../types-3e5768ec.js';
3
- import { Server, Socket } from 'node:net';
4
- import { S as StreamConnection } from '../../../connection-2529fc14.js';
5
- import '@sinclair/typebox';
6
-
7
- interface Options {
8
- codec: Codec;
9
- }
10
- declare class UnixDomainSocketServerTransport extends Transport<StreamConnection> {
11
- server: Server;
12
- constructor(server: Server, clientId: TransportClientId, providedOptions?: Partial<Options>);
13
- connectionListener: (sock: Socket) => void;
14
- createNewConnection(to: string): Promise<void>;
15
- close(): Promise<void>;
16
- }
17
-
18
- export { UnixDomainSocketServerTransport };
@@ -1,18 +0,0 @@
1
- import { Transport, TransportClientId } from '../../index.js';
2
- import { C as Codec } from '../../../types-3e5768ec.js';
3
- import { Server, Socket } from 'node:net';
4
- import { S as StreamConnection } from '../../../connection-316d6e3a.js';
5
- import '@sinclair/typebox';
6
-
7
- interface Options {
8
- codec: Codec;
9
- }
10
- declare class UnixDomainSocketServerTransport extends Transport<StreamConnection> {
11
- server: Server;
12
- constructor(server: Server, clientId: TransportClientId, providedOptions?: Partial<Options>);
13
- connectionListener: (sock: Socket) => void;
14
- createNewConnection(to: string): Promise<void>;
15
- close(): Promise<void>;
16
- }
17
-
18
- export { UnixDomainSocketServerTransport };
@@ -1,73 +0,0 @@
1
- import {
2
- MessageFramer,
3
- StreamConnection
4
- } from "../../../chunk-GKPT5YQE.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/server.ts
19
- var defaultOptions = {
20
- codec: NaiveJsonCodec
21
- };
22
- var UnixDomainSocketServerTransport = class extends Transport {
23
- server;
24
- constructor(server, clientId, providedOptions) {
25
- const options = { ...defaultOptions, ...providedOptions };
26
- super(options.codec, clientId);
27
- this.server = server;
28
- server.addListener("connection", this.connectionListener);
29
- server.on("listening", () => {
30
- log?.info(`${this.clientId} -- server is listening`);
31
- });
32
- }
33
- connectionListener = (sock) => {
34
- let conn = void 0;
35
- const framedMessageStream = MessageFramer.createFramedStream();
36
- sock.pipe(framedMessageStream).on("data", (data) => {
37
- const parsedMsg = this.parseMsg(data);
38
- if (!parsedMsg) {
39
- return;
40
- }
41
- if (!conn) {
42
- conn = new StreamConnection(this, parsedMsg.from, sock);
43
- this.onConnect(conn);
44
- }
45
- this.handleMsg(parsedMsg);
46
- });
47
- const cleanup = () => {
48
- framedMessageStream.destroy();
49
- if (conn) {
50
- this.onDisconnect(conn);
51
- }
52
- };
53
- sock.on("close", cleanup);
54
- sock.on("error", (err) => {
55
- log?.warn(
56
- `${this.clientId} -- socket error in connection to ${conn?.connectedTo ?? "unknown"}: ${err}`
57
- );
58
- cleanup();
59
- });
60
- };
61
- async createNewConnection(to) {
62
- const err = `${this.clientId} -- failed to send msg to ${to}, client probably dropped`;
63
- log?.warn(err);
64
- return;
65
- }
66
- async close() {
67
- this.server.removeListener("connection", this.connectionListener);
68
- super.close();
69
- }
70
- };
71
- export {
72
- UnixDomainSocketServerTransport
73
- };
File without changes