@replit/river 0.10.3 → 0.10.4

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.
@@ -373,9 +373,6 @@ function _pushable(getNext, options) {
373
373
  },
374
374
  get readableLength() {
375
375
  return _pushable2.readableLength;
376
- },
377
- onEmpty: (opts) => {
378
- return _pushable2.onEmpty(opts);
379
376
  }
380
377
  };
381
378
  return pushable2;
@@ -395,9 +395,6 @@ function _pushable(getNext, options) {
395
395
  },
396
396
  get readableLength() {
397
397
  return _pushable2.readableLength;
398
- },
399
- onEmpty: (opts) => {
400
- return _pushable2.onEmpty(opts);
401
398
  }
402
399
  };
403
400
  return pushable2;
@@ -8,7 +8,7 @@ import {
8
8
  createClient,
9
9
  createServer,
10
10
  serializeService
11
- } from "../chunk-IYRPZPSQ.js";
11
+ } from "../chunk-FWPZDOFL.js";
12
12
  import "../chunk-ZE4MX7DF.js";
13
13
  import "../chunk-SLUSVGQH.js";
14
14
  export {
@@ -0,0 +1,468 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // transport/impls/stdio/stdio.ts
31
+ var stdio_exports = {};
32
+ __export(stdio_exports, {
33
+ StdioConnection: () => StdioConnection,
34
+ StdioTransport: () => StdioTransport
35
+ });
36
+ module.exports = __toCommonJS(stdio_exports);
37
+
38
+ // codec/json.ts
39
+ var encoder = new TextEncoder();
40
+ var decoder = new TextDecoder();
41
+ function uint8ArrayToBase64(uint8Array) {
42
+ let binary = "";
43
+ uint8Array.forEach((byte) => {
44
+ binary += String.fromCharCode(byte);
45
+ });
46
+ return btoa(binary);
47
+ }
48
+ function base64ToUint8Array(base64) {
49
+ const binaryString = atob(base64);
50
+ const uint8Array = new Uint8Array(binaryString.length);
51
+ for (let i = 0; i < binaryString.length; i++) {
52
+ uint8Array[i] = binaryString.charCodeAt(i);
53
+ }
54
+ return uint8Array;
55
+ }
56
+ var NaiveJsonCodec = {
57
+ toBuffer: (obj) => {
58
+ return encoder.encode(
59
+ JSON.stringify(obj, function replacer(key) {
60
+ let val = this[key];
61
+ if (val instanceof Uint8Array) {
62
+ return { $t: uint8ArrayToBase64(val) };
63
+ } else {
64
+ return val;
65
+ }
66
+ })
67
+ );
68
+ },
69
+ fromBuffer: (buff) => {
70
+ try {
71
+ return JSON.parse(decoder.decode(buff), function reviver(_key, val) {
72
+ if (val?.$t) {
73
+ return base64ToUint8Array(val.$t);
74
+ } else {
75
+ return val;
76
+ }
77
+ });
78
+ } catch {
79
+ return null;
80
+ }
81
+ }
82
+ };
83
+
84
+ // logging/index.ts
85
+ var log;
86
+
87
+ // transport/transport.ts
88
+ var import_value = require("@sinclair/typebox/value");
89
+
90
+ // transport/message.ts
91
+ var import_typebox = require("@sinclair/typebox");
92
+ var import_nanoid = require("nanoid");
93
+ var TransportMessageSchema = (t) => import_typebox.Type.Object({
94
+ id: import_typebox.Type.String(),
95
+ from: import_typebox.Type.String(),
96
+ to: import_typebox.Type.String(),
97
+ serviceName: import_typebox.Type.Optional(import_typebox.Type.Union([import_typebox.Type.String(), import_typebox.Type.Null()])),
98
+ procedureName: import_typebox.Type.Optional(import_typebox.Type.Union([import_typebox.Type.String(), import_typebox.Type.Null()])),
99
+ streamId: import_typebox.Type.String(),
100
+ controlFlags: import_typebox.Type.Integer(),
101
+ payload: t
102
+ });
103
+ var TransportAckSchema = TransportMessageSchema(
104
+ import_typebox.Type.Object({
105
+ ack: import_typebox.Type.String()
106
+ })
107
+ );
108
+ var ControlMessagePayloadSchema = import_typebox.Type.Object({
109
+ type: import_typebox.Type.Literal("CLOSE")
110
+ });
111
+ var OpaqueTransportMessageSchema = TransportMessageSchema(
112
+ import_typebox.Type.Unknown()
113
+ );
114
+ function reply(msg, response) {
115
+ return {
116
+ id: (0, import_nanoid.nanoid)(),
117
+ streamId: msg.streamId,
118
+ controlFlags: 0,
119
+ to: msg.from,
120
+ from: msg.to,
121
+ payload: response
122
+ };
123
+ }
124
+ function isAck(controlFlag) {
125
+ return (controlFlag & 1 /* AckBit */) === 1 /* AckBit */;
126
+ }
127
+
128
+ // transport/events.ts
129
+ var EventDispatcher = class {
130
+ eventListeners = {};
131
+ numberOfListeners(eventType) {
132
+ return this.eventListeners[eventType]?.size ?? 0;
133
+ }
134
+ addEventListener(eventType, handler) {
135
+ if (!this.eventListeners[eventType]) {
136
+ this.eventListeners[eventType] = /* @__PURE__ */ new Set();
137
+ }
138
+ this.eventListeners[eventType]?.add(handler);
139
+ }
140
+ removeEventListener(eventType, handler) {
141
+ const handlers = this.eventListeners[eventType];
142
+ if (handlers) {
143
+ this.eventListeners[eventType]?.delete(handler);
144
+ }
145
+ }
146
+ dispatchEvent(eventType, event) {
147
+ const handlers = this.eventListeners[eventType];
148
+ if (handlers) {
149
+ for (const handler of handlers) {
150
+ handler(event);
151
+ }
152
+ }
153
+ }
154
+ };
155
+
156
+ // transport/transport.ts
157
+ var Connection = class {
158
+ connectedTo;
159
+ transport;
160
+ constructor(transport, connectedTo) {
161
+ this.connectedTo = connectedTo;
162
+ this.transport = transport;
163
+ }
164
+ };
165
+ var Transport = class {
166
+ /**
167
+ * A flag indicating whether the transport has been destroyed.
168
+ * A destroyed transport will not attempt to reconnect and cannot be used again.
169
+ */
170
+ state;
171
+ /**
172
+ * The {@link Codec} used to encode and decode messages.
173
+ */
174
+ codec;
175
+ /**
176
+ * The client ID of this transport.
177
+ */
178
+ clientId;
179
+ /**
180
+ * An array of message IDs that are waiting to be sent over the WebSocket connection.
181
+ * This builds up if the WebSocket is down for a period of time.
182
+ */
183
+ sendQueue;
184
+ /**
185
+ * The buffer of messages that have been sent but not yet acknowledged.
186
+ */
187
+ sendBuffer;
188
+ /**
189
+ * The map of {@link Connection}s managed by this transport.
190
+ */
191
+ connections;
192
+ /**
193
+ * The event dispatcher for handling events of type EventTypes.
194
+ */
195
+ eventDispatcher;
196
+ /**
197
+ * Creates a new Transport instance.
198
+ * @param codec The codec used to encode and decode messages.
199
+ * @param clientId The client ID of this transport.
200
+ */
201
+ constructor(codec, clientId) {
202
+ this.eventDispatcher = new EventDispatcher();
203
+ this.sendBuffer = /* @__PURE__ */ new Map();
204
+ this.sendQueue = /* @__PURE__ */ new Map();
205
+ this.connections = /* @__PURE__ */ new Map();
206
+ this.codec = codec;
207
+ this.clientId = clientId;
208
+ this.state = "open";
209
+ }
210
+ /**
211
+ * The downstream implementation needs to call this when a new connection is established.
212
+ * @param conn The connection object.
213
+ */
214
+ onConnect(conn) {
215
+ log?.info(`${this.clientId} -- new connection to ${conn.connectedTo}`);
216
+ this.connections.set(conn.connectedTo, conn);
217
+ this.eventDispatcher.dispatchEvent("connectionStatus", {
218
+ status: "connect",
219
+ conn
220
+ });
221
+ const outstanding = this.sendQueue.get(conn.connectedTo);
222
+ if (!outstanding) {
223
+ return;
224
+ }
225
+ for (const id of outstanding) {
226
+ const msg = this.sendBuffer.get(id);
227
+ if (!msg) {
228
+ log?.warn(
229
+ `${this.clientId} -- tried to resend a message we received an ack for`
230
+ );
231
+ continue;
232
+ }
233
+ this.send(msg);
234
+ }
235
+ this.sendQueue.delete(conn.connectedTo);
236
+ }
237
+ /**
238
+ * The downstream implementation needs to call this when a connection is closed.
239
+ * @param conn The connection object.
240
+ */
241
+ onDisconnect(conn) {
242
+ log?.info(`${this.clientId} -- disconnect from ${conn.connectedTo}`);
243
+ conn.close();
244
+ this.connections.delete(conn.connectedTo);
245
+ this.eventDispatcher.dispatchEvent("connectionStatus", {
246
+ status: "disconnect",
247
+ conn
248
+ });
249
+ }
250
+ /**
251
+ * Handles a message received by this transport. Thin wrapper around {@link handleMsg} and {@link parseMsg}.
252
+ * @param msg The message to handle.
253
+ */
254
+ onMessage(msg) {
255
+ return this.handleMsg(this.parseMsg(msg));
256
+ }
257
+ /**
258
+ * Parses a message from a Uint8Array into a {@link OpaqueTransportMessage}.
259
+ * @param msg The message to parse.
260
+ * @returns The parsed message, or null if the message is malformed or invalid.
261
+ */
262
+ parseMsg(msg) {
263
+ const parsedMsg = this.codec.fromBuffer(msg);
264
+ if (parsedMsg === null) {
265
+ const decodedBuffer = new TextDecoder().decode(msg);
266
+ log?.warn(`${this.clientId} -- received malformed msg: ${decodedBuffer}`);
267
+ return null;
268
+ }
269
+ if (import_value.Value.Check(OpaqueTransportMessageSchema, parsedMsg)) {
270
+ return {
271
+ ...parsedMsg,
272
+ serviceName: parsedMsg.serviceName === null ? void 0 : parsedMsg.serviceName,
273
+ procedureName: parsedMsg.procedureName === null ? void 0 : parsedMsg.procedureName
274
+ };
275
+ } else {
276
+ log?.warn(
277
+ `${this.clientId} -- received invalid msg: ${JSON.stringify(
278
+ parsedMsg
279
+ )}`
280
+ );
281
+ return null;
282
+ }
283
+ }
284
+ /**
285
+ * Called when a message is received by this transport.
286
+ * You generally shouldn't need to override this in downstream transport implementations.
287
+ * @param msg The received message.
288
+ */
289
+ handleMsg(msg) {
290
+ if (!msg) {
291
+ return;
292
+ }
293
+ if (isAck(msg.controlFlags) && import_value.Value.Check(TransportAckSchema, msg)) {
294
+ log?.info(`${this.clientId} -- received ack: ${JSON.stringify(msg)}`);
295
+ if (this.sendBuffer.has(msg.payload.ack)) {
296
+ this.sendBuffer.delete(msg.payload.ack);
297
+ }
298
+ } else {
299
+ log?.info(`${this.clientId} -- received msg: ${JSON.stringify(msg)}`);
300
+ if (msg.to !== this.clientId) {
301
+ return;
302
+ }
303
+ this.eventDispatcher.dispatchEvent("message", msg);
304
+ if (!isAck(msg.controlFlags)) {
305
+ const ackMsg = reply(msg, { ack: msg.id });
306
+ ackMsg.controlFlags = 1 /* AckBit */;
307
+ ackMsg.from = this.clientId;
308
+ this.send(ackMsg);
309
+ }
310
+ }
311
+ }
312
+ /**
313
+ * Adds a listener to this transport.
314
+ * @param the type of event to listen for
315
+ * @param handler The message handler to add.
316
+ */
317
+ addEventListener(type, handler) {
318
+ this.eventDispatcher.addEventListener(type, handler);
319
+ }
320
+ /**
321
+ * Removes a listener from this transport.
322
+ * @param the type of event to unlisten on
323
+ * @param handler The message handler to remove.
324
+ */
325
+ removeEventListener(type, handler) {
326
+ this.eventDispatcher.removeEventListener(type, handler);
327
+ }
328
+ /**
329
+ * Sends a message over this transport, delegating to the appropriate connection to actually
330
+ * send the message.
331
+ * @param msg The message to send.
332
+ * @returns The ID of the sent message.
333
+ */
334
+ send(msg) {
335
+ if (this.state === "destroyed") {
336
+ const err = "transport is destroyed, cant send";
337
+ log?.error(`${this.clientId} -- ` + err + `: ${JSON.stringify(msg)}`);
338
+ throw new Error(err);
339
+ } else if (this.state === "closed") {
340
+ log?.info(
341
+ `${this.clientId} -- transport closed when sending, discarding : ${JSON.stringify(
342
+ msg
343
+ )}`
344
+ );
345
+ return msg.id;
346
+ }
347
+ let conn = this.connections.get(msg.to);
348
+ if (!isAck(msg.controlFlags)) {
349
+ this.sendBuffer.set(msg.id, msg);
350
+ }
351
+ if (conn) {
352
+ log?.info(`${this.clientId} -- sending ${JSON.stringify(msg)}`);
353
+ const ok = conn.send(this.codec.toBuffer(msg));
354
+ if (ok) {
355
+ return msg.id;
356
+ }
357
+ }
358
+ log?.info(
359
+ `${this.clientId} -- connection to ${msg.to} not ready, attempting reconnect and queuing ${JSON.stringify(msg)}`
360
+ );
361
+ const outstanding = this.sendQueue.get(msg.to) || [];
362
+ outstanding.push(msg.id);
363
+ this.sendQueue.set(msg.to, outstanding);
364
+ this.createNewConnection(msg.to);
365
+ return msg.id;
366
+ }
367
+ /**
368
+ * Default close implementation for transports. You should override this in the downstream
369
+ * implementation if you need to do any additional cleanup and call super.close() at the end.
370
+ * Closes the transport. Any messages sent while the transport is closed will be silently discarded.
371
+ */
372
+ async close() {
373
+ for (const conn of this.connections.values()) {
374
+ conn.close();
375
+ }
376
+ this.connections.clear();
377
+ this.state = "closed";
378
+ log?.info(`${this.clientId} -- closed transport`);
379
+ }
380
+ /**
381
+ * Default destroy implementation for transports. You should override this in the downstream
382
+ * implementation if you need to do any additional cleanup and call super.destroy() at the end.
383
+ * Destroys the transport. Any messages sent while the transport is destroyed will throw an error.
384
+ */
385
+ async destroy() {
386
+ for (const conn of this.connections.values()) {
387
+ conn.close();
388
+ }
389
+ this.connections.clear();
390
+ this.state = "destroyed";
391
+ log?.info(`${this.clientId} -- destroyed transport`);
392
+ }
393
+ };
394
+
395
+ // transport/impls/stdio/stdio.ts
396
+ var import_readline = __toESM(require("readline"), 1);
397
+ var newlineBuff = new TextEncoder().encode("\n");
398
+ var StdioConnection = class extends Connection {
399
+ output;
400
+ constructor(transport, connectedTo, output) {
401
+ super(transport, connectedTo);
402
+ this.output = output;
403
+ }
404
+ send(payload) {
405
+ const out = new Uint8Array(payload.length + newlineBuff.length);
406
+ out.set(payload, 0);
407
+ out.set(newlineBuff, payload.length);
408
+ return this.output.write(out);
409
+ }
410
+ async close() {
411
+ this.output.end();
412
+ }
413
+ };
414
+ var defaultOptions = {
415
+ codec: NaiveJsonCodec
416
+ };
417
+ var StdioTransport = class extends Transport {
418
+ clientId;
419
+ input = process.stdin;
420
+ output = process.stdout;
421
+ /**
422
+ * Constructs a new StdioTransport instance.
423
+ * @param clientId - The ID of the client associated with this transport.
424
+ * @param input - The readable stream to use as input. Defaults to process.stdin.
425
+ * @param output - The writable stream to use as output. Defaults to process.stdout.
426
+ */
427
+ constructor(clientId, input = process.stdin, output = process.stdout, providedOptions) {
428
+ const options = { ...defaultOptions, ...providedOptions };
429
+ super(options.codec, clientId);
430
+ this.clientId = clientId;
431
+ this.input = input;
432
+ this.output = output;
433
+ this.setupConnectionStatusListeners();
434
+ }
435
+ setupConnectionStatusListeners() {
436
+ let conn = void 0;
437
+ const rl = import_readline.default.createInterface({
438
+ input: this.input
439
+ });
440
+ const encoder2 = new TextEncoder();
441
+ rl.on("line", (msg) => {
442
+ const parsedMsg = this.parseMsg(encoder2.encode(msg));
443
+ if (parsedMsg && !this.connections.has(parsedMsg.from)) {
444
+ conn = new StdioConnection(this, parsedMsg.from, this.output);
445
+ this.onConnect(conn);
446
+ }
447
+ this.handleMsg(parsedMsg);
448
+ });
449
+ rl.on("close", () => {
450
+ if (conn) {
451
+ this.onDisconnect(conn);
452
+ }
453
+ });
454
+ }
455
+ async createNewConnection(to) {
456
+ if (this.state === "destroyed") {
457
+ throw new Error("cant reopen a destroyed connection");
458
+ }
459
+ log?.info(`${this.clientId} -- establishing a new stream to ${to}`);
460
+ const conn = new StdioConnection(this, to, this.output);
461
+ this.onConnect(conn);
462
+ }
463
+ };
464
+ // Annotate the CommonJS export names for ESM import in node:
465
+ 0 && (module.exports = {
466
+ StdioConnection,
467
+ StdioTransport
468
+ });
@@ -0,0 +1,33 @@
1
+ import { C as Codec } from '../../../types-3e5768ec.js';
2
+ import { Connection, Transport, TransportClientId } from '../../index.cjs';
3
+ import '@sinclair/typebox';
4
+
5
+ declare class StdioConnection extends Connection {
6
+ output: NodeJS.WritableStream;
7
+ constructor(transport: Transport<StdioConnection>, connectedTo: TransportClientId, output: NodeJS.WritableStream);
8
+ send(payload: Uint8Array): boolean;
9
+ close(): Promise<void>;
10
+ }
11
+ interface Options {
12
+ codec: Codec;
13
+ }
14
+ /**
15
+ * A transport implementation that uses standard input and output streams.
16
+ * @extends Transport
17
+ */
18
+ declare class StdioTransport extends Transport<StdioConnection> {
19
+ clientId: TransportClientId;
20
+ input: NodeJS.ReadableStream;
21
+ output: NodeJS.WritableStream;
22
+ /**
23
+ * Constructs a new StdioTransport instance.
24
+ * @param clientId - The ID of the client associated with this transport.
25
+ * @param input - The readable stream to use as input. Defaults to process.stdin.
26
+ * @param output - The writable stream to use as output. Defaults to process.stdout.
27
+ */
28
+ constructor(clientId: TransportClientId, input?: NodeJS.ReadableStream, output?: NodeJS.WritableStream, providedOptions?: Partial<Options>);
29
+ setupConnectionStatusListeners(): void;
30
+ createNewConnection(to: TransportClientId): Promise<void>;
31
+ }
32
+
33
+ export { StdioConnection, StdioTransport };
@@ -0,0 +1,33 @@
1
+ import { C as Codec } from '../../../types-3e5768ec.js';
2
+ import { Connection, Transport, TransportClientId } from '../../index.js';
3
+ import '@sinclair/typebox';
4
+
5
+ declare class StdioConnection extends Connection {
6
+ output: NodeJS.WritableStream;
7
+ constructor(transport: Transport<StdioConnection>, connectedTo: TransportClientId, output: NodeJS.WritableStream);
8
+ send(payload: Uint8Array): boolean;
9
+ close(): Promise<void>;
10
+ }
11
+ interface Options {
12
+ codec: Codec;
13
+ }
14
+ /**
15
+ * A transport implementation that uses standard input and output streams.
16
+ * @extends Transport
17
+ */
18
+ declare class StdioTransport extends Transport<StdioConnection> {
19
+ clientId: TransportClientId;
20
+ input: NodeJS.ReadableStream;
21
+ output: NodeJS.WritableStream;
22
+ /**
23
+ * Constructs a new StdioTransport instance.
24
+ * @param clientId - The ID of the client associated with this transport.
25
+ * @param input - The readable stream to use as input. Defaults to process.stdin.
26
+ * @param output - The writable stream to use as output. Defaults to process.stdout.
27
+ */
28
+ constructor(clientId: TransportClientId, input?: NodeJS.ReadableStream, output?: NodeJS.WritableStream, providedOptions?: Partial<Options>);
29
+ setupConnectionStatusListeners(): void;
30
+ createNewConnection(to: TransportClientId): Promise<void>;
31
+ }
32
+
33
+ export { StdioConnection, StdioTransport };
@@ -0,0 +1,85 @@
1
+ import {
2
+ NaiveJsonCodec
3
+ } from "../../../chunk-R6H2BIMC.js";
4
+ import {
5
+ Connection,
6
+ Transport
7
+ } from "../../../chunk-AJQU4AZG.js";
8
+ import "../../../chunk-ZE4MX7DF.js";
9
+ import {
10
+ log
11
+ } from "../../../chunk-SLUSVGQH.js";
12
+
13
+ // transport/impls/stdio/stdio.ts
14
+ import readline from "readline";
15
+ var newlineBuff = new TextEncoder().encode("\n");
16
+ var StdioConnection = class extends Connection {
17
+ output;
18
+ constructor(transport, connectedTo, output) {
19
+ super(transport, connectedTo);
20
+ this.output = output;
21
+ }
22
+ send(payload) {
23
+ const out = new Uint8Array(payload.length + newlineBuff.length);
24
+ out.set(payload, 0);
25
+ out.set(newlineBuff, payload.length);
26
+ return this.output.write(out);
27
+ }
28
+ async close() {
29
+ this.output.end();
30
+ }
31
+ };
32
+ var defaultOptions = {
33
+ codec: NaiveJsonCodec
34
+ };
35
+ var StdioTransport = class extends Transport {
36
+ clientId;
37
+ input = process.stdin;
38
+ output = process.stdout;
39
+ /**
40
+ * Constructs a new StdioTransport instance.
41
+ * @param clientId - The ID of the client associated with this transport.
42
+ * @param input - The readable stream to use as input. Defaults to process.stdin.
43
+ * @param output - The writable stream to use as output. Defaults to process.stdout.
44
+ */
45
+ constructor(clientId, input = process.stdin, output = process.stdout, providedOptions) {
46
+ const options = { ...defaultOptions, ...providedOptions };
47
+ super(options.codec, clientId);
48
+ this.clientId = clientId;
49
+ this.input = input;
50
+ this.output = output;
51
+ this.setupConnectionStatusListeners();
52
+ }
53
+ setupConnectionStatusListeners() {
54
+ let conn = void 0;
55
+ const rl = readline.createInterface({
56
+ input: this.input
57
+ });
58
+ const encoder = new TextEncoder();
59
+ rl.on("line", (msg) => {
60
+ const parsedMsg = this.parseMsg(encoder.encode(msg));
61
+ if (parsedMsg && !this.connections.has(parsedMsg.from)) {
62
+ conn = new StdioConnection(this, parsedMsg.from, this.output);
63
+ this.onConnect(conn);
64
+ }
65
+ this.handleMsg(parsedMsg);
66
+ });
67
+ rl.on("close", () => {
68
+ if (conn) {
69
+ this.onDisconnect(conn);
70
+ }
71
+ });
72
+ }
73
+ async createNewConnection(to) {
74
+ if (this.state === "destroyed") {
75
+ throw new Error("cant reopen a destroyed connection");
76
+ }
77
+ log?.info(`${this.clientId} -- establishing a new stream to ${to}`);
78
+ const conn = new StdioConnection(this, to, this.output);
79
+ this.onConnect(conn);
80
+ }
81
+ };
82
+ export {
83
+ StdioConnection,
84
+ StdioTransport
85
+ };
@@ -809,9 +809,6 @@ function _pushable(getNext, options) {
809
809
  },
810
810
  get readableLength() {
811
811
  return _pushable2.readableLength;
812
- },
813
- onEmpty: (opts) => {
814
- return _pushable2.onEmpty(opts);
815
812
  }
816
813
  };
817
814
  return pushable2;
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  UNCAUGHT_ERROR,
3
3
  pushable
4
- } from "../chunk-IYRPZPSQ.js";
4
+ } from "../chunk-FWPZDOFL.js";
5
5
  import "../chunk-ORAG7IAU.js";
6
6
  import {
7
7
  WebSocketClientTransport
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.10.3",
4
+ "version": "0.10.4",
5
5
  "type": "module",
6
6
  "exports": {
7
7
  ".": {
@@ -61,16 +61,6 @@
61
61
  "typescript": "^5.2.2",
62
62
  "vitest": "^1.0.1"
63
63
  },
64
- "scripts": {
65
- "check": "tsc --noEmit && npx prettier . --check",
66
- "format": "npx prettier . --write",
67
- "build": "tsup && du -sh dist",
68
- "prepack": "npm run build",
69
- "release": "npm publish --access public",
70
- "test:ui": "echo \"remember to go to /__vitest__ in the webview\" && vitest --ui --api.host 0.0.0.0 --api.port 3000",
71
- "test": "vitest --test-timeout=500",
72
- "bench": "vitest bench"
73
- },
74
64
  "engines": {
75
65
  "node": ">=16"
76
66
  },
@@ -80,5 +70,14 @@
80
70
  "jsonschema"
81
71
  ],
82
72
  "author": "Jacky Zhao",
83
- "license": "MIT"
84
- }
73
+ "license": "MIT",
74
+ "scripts": {
75
+ "check": "tsc --noEmit && npx prettier . --check",
76
+ "format": "npx prettier . --write",
77
+ "build": "rm -rf dist && tsup && du -sh dist",
78
+ "release": "npm publish --access public",
79
+ "test:ui": "echo \"remember to go to /__vitest__ in the webview\" && vitest --ui --api.host 0.0.0.0 --api.port 3000",
80
+ "test": "vitest --test-timeout=500",
81
+ "bench": "vitest bench"
82
+ }
83
+ }