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