@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
@@ -0,0 +1,442 @@
1
+ import { C as Codec } from './types-3e5768ec.js';
2
+ import * as _sinclair_typebox from '@sinclair/typebox';
3
+ import { TSchema } from '@sinclair/typebox';
4
+
5
+ /**
6
+ * Generic Typebox schema for a transport message.
7
+ * @template T The type of the payload.
8
+ * @param {T} t The payload schema.
9
+ * @returns The transport message schema.
10
+ */
11
+ declare const TransportMessageSchema: <T extends TSchema>(t: T) => _sinclair_typebox.TObject<{
12
+ id: _sinclair_typebox.TString;
13
+ from: _sinclair_typebox.TString;
14
+ to: _sinclair_typebox.TString;
15
+ seq: _sinclair_typebox.TInteger;
16
+ ack: _sinclair_typebox.TInteger;
17
+ serviceName: _sinclair_typebox.TOptional<_sinclair_typebox.TUnion<[_sinclair_typebox.TString, _sinclair_typebox.TNull]>>;
18
+ procedureName: _sinclair_typebox.TOptional<_sinclair_typebox.TUnion<[_sinclair_typebox.TString, _sinclair_typebox.TNull]>>;
19
+ streamId: _sinclair_typebox.TString;
20
+ controlFlags: _sinclair_typebox.TInteger;
21
+ payload: T;
22
+ }>;
23
+ /**
24
+ * Defines the schema for an opaque transport message that is agnostic to any
25
+ * procedure/service.
26
+ * @returns The transport message schema.
27
+ */
28
+ declare const OpaqueTransportMessageSchema: _sinclair_typebox.TObject<{
29
+ id: _sinclair_typebox.TString;
30
+ from: _sinclair_typebox.TString;
31
+ to: _sinclair_typebox.TString;
32
+ seq: _sinclair_typebox.TInteger;
33
+ ack: _sinclair_typebox.TInteger;
34
+ serviceName: _sinclair_typebox.TOptional<_sinclair_typebox.TUnion<[_sinclair_typebox.TString, _sinclair_typebox.TNull]>>;
35
+ procedureName: _sinclair_typebox.TOptional<_sinclair_typebox.TUnion<[_sinclair_typebox.TString, _sinclair_typebox.TNull]>>;
36
+ streamId: _sinclair_typebox.TString;
37
+ controlFlags: _sinclair_typebox.TInteger;
38
+ payload: _sinclair_typebox.TUnknown;
39
+ }>;
40
+ /**
41
+ * Represents a transport message. This is the same type as {@link TransportMessageSchema} but
42
+ * we can't statically infer generics from generic Typebox schemas so we have to define it again here.
43
+ *
44
+ * TypeScript can't enforce types when a bitmask is involved, so these are the semantics of
45
+ * `controlFlags`:
46
+ * * If `controlFlags & StreamOpenBit == StreamOpenBit`, `streamId` must be set to a unique value
47
+ * (suggestion: use `nanoid`).
48
+ * * If `controlFlags & StreamOpenBit == StreamOpenBit`, `serviceName` and `procedureName` must be set.
49
+ * * If `controlFlags & StreamClosedBit == StreamClosedBit` and the kind is `stream` or `subscription`,
50
+ * `payload` should be discarded (usually contains a control message).
51
+ * @template Payload The type of the payload.
52
+ */
53
+ interface TransportMessage<Payload = Record<string, unknown>> {
54
+ id: string;
55
+ from: string;
56
+ to: string;
57
+ seq: number;
58
+ ack: number;
59
+ serviceName?: string;
60
+ procedureName?: string;
61
+ streamId: string;
62
+ controlFlags: number;
63
+ payload: Payload;
64
+ }
65
+ type PartialTransportMessage<Payload extends Record<string, unknown> = Record<string, unknown>> = Omit<TransportMessage<Payload>, 'id' | 'from' | 'to' | 'seq' | 'ack'>;
66
+ /**
67
+ * A type alias for a transport message with an opaque payload.
68
+ * @template T - The type of the opaque payload.
69
+ */
70
+ type OpaqueTransportMessage = TransportMessage<unknown>;
71
+ type TransportClientId = string;
72
+ /**
73
+ * Checks if the given control flag (usually found in msg.controlFlag) is a stream open message.
74
+ * @param controlFlag - The control flag to check.
75
+ * @returns True if the control flag contains the StreamOpenBit, false otherwise.
76
+ */
77
+ declare function isStreamOpen(controlFlag: number): boolean;
78
+ /**
79
+ * Checks if the given control flag (usually found in msg.controlFlag) is a stream close message.
80
+ * @param controlFlag - The control flag to check.
81
+ * @returns True if the control flag contains the StreamCloseBit, false otherwise.
82
+ */
83
+ declare function isStreamClose(controlFlag: number): boolean;
84
+
85
+ /**
86
+ * A connection is the actual raw underlying transport connection.
87
+ * It’s responsible for dispatching to/from the actual connection itself
88
+ * This should be instantiated as soon as the client/server has a connection
89
+ * It’s tied to the lifecycle of the underlying transport connection (i.e. if the WS drops, this connection should be deleted)
90
+ */
91
+ declare abstract class Connection {
92
+ debugId: string;
93
+ constructor();
94
+ /**
95
+ * Handle adding a callback for when a message is received.
96
+ * @param msg The message that was received.
97
+ */
98
+ abstract addDataListener(cb: (msg: Uint8Array) => void): void;
99
+ abstract removeDataListener(cb: (msg: Uint8Array) => void): void;
100
+ /**
101
+ * Handle adding a callback for when the connection is closed.
102
+ * This should also be called if an error happens.
103
+ * @param cb The callback to call when the connection is closed.
104
+ */
105
+ abstract addCloseListener(cb: () => void): void;
106
+ /**
107
+ * Handle adding a callback for when an error is received.
108
+ * This should only be used for logging errors, all cleanup
109
+ * should be delegated to addCloseListener.
110
+ *
111
+ * The implementer should take care such that the implemented
112
+ * connection will call both the close and error callbacks
113
+ * on an error.
114
+ *
115
+ * @param cb The callback to call when an error is received.
116
+ */
117
+ abstract addErrorListener(cb: (err: Error) => void): void;
118
+ /**
119
+ * Sends a message over the connection.
120
+ * @param msg The message to send.
121
+ * @returns true if the message was sent, false otherwise.
122
+ */
123
+ abstract send(msg: Uint8Array): boolean;
124
+ /**
125
+ * Closes the connection.
126
+ */
127
+ abstract close(): void;
128
+ }
129
+ /**
130
+ * A session is a higher-level abstraction that operates over the span of potentially multiple transport-level connections
131
+ * - It’s responsible for tracking any metadata for a particular client that might need to be persisted across connections (i.e. the sendBuffer, ack, seq)
132
+ * - This will only be considered disconnected if
133
+ * - the server tells the client that we’ve reconnected but it doesn’t recognize us anymore (server definitely died) or
134
+ * - we hit a grace period after a connection disconnect
135
+ *
136
+ * Here's a legend for what each of the numbers means. A '-' indicates the
137
+ * session/connection is connected and ' ' means it is disconnected.
138
+ *
139
+ * 1. connectionStatus :: connect
140
+ * 2. sessionStatus :: connect
141
+ * 3. connectionStatus :: disconnect
142
+ * 4. sessionStatus :: disconnect
143
+ *
144
+ * From the server's perspective:
145
+ * ```plaintext
146
+ * session 2-----------------------4
147
+ * connection ----1---------3 1-------3
148
+ * ^-^ grace period
149
+ * ^---^ connection is created
150
+ * before connectionStatus event is fired
151
+ * ```
152
+ *
153
+ * From the client's perspective:
154
+ * ```plaintext
155
+ * session 2---------------------------4
156
+ * connection 1---------3 1-------3
157
+ * ^-^ grace period
158
+ * ^---^ session is created as soon
159
+ * as we send an outgoing message
160
+ * ```
161
+ */
162
+ declare class Session<ConnType extends Connection> {
163
+ private codec;
164
+ /**
165
+ * The buffer of messages that have been sent but not yet acknowledged.
166
+ */
167
+ private sendBuffer;
168
+ /**
169
+ * The active connection associated with this session
170
+ */
171
+ connection?: ConnType;
172
+ readonly from: TransportClientId;
173
+ readonly to: TransportClientId;
174
+ /**
175
+ * The unique ID of this session.
176
+ */
177
+ debugId: string;
178
+ /**
179
+ * Number of messages we've sent along this session (excluding handshake)
180
+ */
181
+ private seq;
182
+ /**
183
+ * Number of unique messages we've received this session (excluding handshake)
184
+ */
185
+ private ack;
186
+ /**
187
+ * The grace period between when the inner connection is disconnected
188
+ * and when we should consider the entire session disconnected.
189
+ */
190
+ private disconnectionGrace?;
191
+ /**
192
+ * Number of heartbeats we've sent without a response.
193
+ */
194
+ private heartbeatMisses;
195
+ /**
196
+ * The interval for sending heartbeats.
197
+ */
198
+ private heartbeat?;
199
+ constructor(codec: Codec, from: TransportClientId, connectedTo: TransportClientId, conn: ConnType | undefined);
200
+ /**
201
+ * Sends a message over the session's connection.
202
+ * If the connection is not ready or the message fails to send, the message can be buffered for retry unless skipped.
203
+ *
204
+ * @param msg The partial message to be sent, which will be constructed into a full message.
205
+ * @param skipRetry Optional. If true, the message will not be buffered for retry on failure. This should only be used for
206
+ * ack hearbeats, which contain information that can already be found in the other buffered messages.
207
+ * @returns The full transport ID of the message that was attempted to be sent.
208
+ */
209
+ send(msg: PartialTransportMessage, skipRetry?: boolean): string;
210
+ sendHeartbeat(): void;
211
+ resetBufferedMessages(): void;
212
+ sendBufferedMessages(): void;
213
+ updateBookkeeping(ack: number, seq: number): void;
214
+ addToSendBuff(msg: TransportMessage): void;
215
+ closeStaleConnection(conn?: ConnType): void;
216
+ replaceWithNewConnection(newConn: ConnType): void;
217
+ beginGrace(cb: () => void): void;
218
+ cancelGrace(): void;
219
+ get connected(): boolean;
220
+ get nextExpectedSeq(): number;
221
+ constructMsg<Payload extends Record<string, unknown>>(partialMsg: PartialTransportMessage<Payload>): TransportMessage<Payload>;
222
+ /**
223
+ * Closes the out-going connection but doesn't remove the listeners
224
+ * for incoming messages. The connection will eventually call onClose
225
+ * when it is ready to be cleaned up and only then will {@link connection} be set back
226
+ * to undefined
227
+ */
228
+ halfCloseConnection(): void;
229
+ inspectSendBuffer(): ReadonlyArray<OpaqueTransportMessage>;
230
+ }
231
+
232
+ type ConnectionStatus = 'connect' | 'disconnect';
233
+ interface EventMap {
234
+ message: OpaqueTransportMessage;
235
+ connectionStatus: {
236
+ status: ConnectionStatus;
237
+ conn: Connection;
238
+ };
239
+ sessionStatus: {
240
+ status: ConnectionStatus;
241
+ session: Session<Connection>;
242
+ };
243
+ }
244
+ type EventTypes = keyof EventMap;
245
+ type EventHandler<K extends EventTypes> = (event: EventMap[K]) => unknown;
246
+ declare class EventDispatcher<T extends EventTypes> {
247
+ private eventListeners;
248
+ numberOfListeners<K extends T>(eventType: K): number;
249
+ addEventListener<K extends T>(eventType: K, handler: EventHandler<K>): void;
250
+ removeEventListener<K extends T>(eventType: K, handler: EventHandler<K>): void;
251
+ dispatchEvent<K extends T>(eventType: K, event: EventMap[K]): void;
252
+ }
253
+
254
+ /**
255
+ * Represents the possible states of a transport.
256
+ * @property {'open'} open - The transport is open and operational (note that this doesn't mean it is actively connected)
257
+ * @property {'closed'} closed - The transport is closed and not operational, but can be reopened.
258
+ * @property {'destroyed'} destroyed - The transport is permanently destroyed and cannot be reopened.
259
+ */
260
+ type TransportStatus = 'open' | 'closed' | 'destroyed';
261
+ interface TransportOptions {
262
+ retryIntervalMs: number;
263
+ retryJitterMs: number;
264
+ retryAttemptsMax: number;
265
+ codec: Codec;
266
+ }
267
+ /**
268
+ * Transports manage the lifecycle (creation/deletion) of sessions and connections. Its responsibilities include:
269
+ *
270
+ * 1) Constructing a new {@link Session} and {@link Connection} on {@link TransportMessage}s from new clients.
271
+ * After constructing the {@link Connection}, {@link onConnect} is called which adds it to the connection map.
272
+ * 2) Delegating message listening of the connection to the newly created {@link Connection}.
273
+ * From this point on, the {@link Connection} is responsible for *reading* and *writing*
274
+ * messages from the connection.
275
+ * 3) When a connection is closed, the {@link Transport} calls {@link onDisconnect} which closes the
276
+ * connection via {@link Connection.close} and removes it from the {@link connections} map.
277
+
278
+ *
279
+ * ```plaintext
280
+ * ▲
281
+ * incoming │
282
+ * messages │
283
+ * ▼
284
+ * ┌─────────────┐ 1:N ┌───────────┐ 1:1* ┌────────────┐
285
+ * │ Transport │ ◄─────► │ Session │ ◄─────► │ Connection │
286
+ * └─────────────┘ └───────────┘ └────────────┘
287
+ * ▲ * (may or may not be initialized yet)
288
+ * │
289
+ * ▼
290
+ * ┌───────────┐
291
+ * │ Message │
292
+ * │ Listeners │
293
+ * └───────────┘
294
+ * ```
295
+ * @abstract
296
+ */
297
+ declare abstract class Transport<ConnType extends Connection> {
298
+ /**
299
+ * A flag indicating whether the transport has been destroyed.
300
+ * A destroyed transport will not attempt to reconnect and cannot be used again.
301
+ */
302
+ state: TransportStatus;
303
+ /**
304
+ * The {@link Codec} used to encode and decode messages.
305
+ */
306
+ codec: Codec;
307
+ /**
308
+ * The client ID of this transport.
309
+ */
310
+ clientId: TransportClientId;
311
+ /**
312
+ * The map of {@link Session}s managed by this transport.
313
+ */
314
+ sessions: Map<TransportClientId, Session<ConnType>>;
315
+ /**
316
+ * The map of {@link Connection}s managed by this transport.
317
+ */
318
+ get connections(): Map<string, ConnType>;
319
+ /**
320
+ * The event dispatcher for handling events of type EventTypes.
321
+ */
322
+ eventDispatcher: EventDispatcher<EventTypes>;
323
+ /**
324
+ * The options for this transport.
325
+ */
326
+ options: TransportOptions;
327
+ /**
328
+ * Creates a new Transport instance.
329
+ * This should also set up {@link onConnect}, and {@link onDisconnect} listeners.
330
+ * @param codec The codec used to encode and decode messages.
331
+ * @param clientId The client ID of this transport.
332
+ */
333
+ constructor(clientId: TransportClientId, providedOptions?: Partial<TransportOptions>);
334
+ private sessionByClientId;
335
+ /**
336
+ * This is called immediately after a new connection is established and we
337
+ * may or may not know the identity of the connected client.
338
+ * It should attach all the necessary listeners to the connection for lifecycle
339
+ * events (i.e. data, close, error)
340
+ *
341
+ * This method is implemented by {@link ClientTransport} and {@link ServerTransport}.
342
+ */
343
+ protected abstract handleConnection(conn: ConnType, to: TransportClientId): void;
344
+ /**
345
+ * Called when a new connection is established
346
+ * and we know the identity of the connected client.
347
+ * @param conn The connection object.
348
+ */
349
+ protected onConnect(conn: ConnType, connectedTo: TransportClientId): Session<ConnType>;
350
+ private createSession;
351
+ protected deleteSession(session: Session<ConnType>): void;
352
+ /**
353
+ * The downstream implementation needs to call this when a connection is closed.
354
+ * @param conn The connection object.
355
+ */
356
+ onDisconnect(conn: ConnType, connectedTo: TransportClientId | undefined): void;
357
+ /**
358
+ * Parses a message from a Uint8Array into a {@link OpaqueTransportMessage}.
359
+ * @param msg The message to parse.
360
+ * @returns The parsed message, or null if the message is malformed or invalid.
361
+ */
362
+ protected parseMsg(msg: Uint8Array): OpaqueTransportMessage | null;
363
+ /**
364
+ * Called when a message is received by this transport.
365
+ * You generally shouldn't need to override this in downstream transport implementations.
366
+ * @param msg The received message.
367
+ */
368
+ handleMsg(msg: OpaqueTransportMessage | null): void;
369
+ /**
370
+ * Adds a listener to this transport.
371
+ * @param the type of event to listen for
372
+ * @param handler The message handler to add.
373
+ */
374
+ addEventListener<K extends EventTypes, T extends EventHandler<K>>(type: K, handler: T): void;
375
+ /**
376
+ * Removes a listener from this transport.
377
+ * @param the type of event to unlisten on
378
+ * @param handler The message handler to remove.
379
+ */
380
+ removeEventListener<K extends EventTypes, T extends EventHandler<K>>(type: K, handler: T): void;
381
+ /**
382
+ * Sends a message over this transport, delegating to the appropriate connection to actually
383
+ * send the message.
384
+ * @param msg The message to send.
385
+ * @returns The ID of the sent message or undefined if it wasn't sent
386
+ */
387
+ send(to: TransportClientId, msg: PartialTransportMessage): string | undefined;
388
+ sendCloseStream(to: TransportClientId, streamId: string): string | undefined;
389
+ /**
390
+ * Default close implementation for transports. You should override this in the downstream
391
+ * implementation if you need to do any additional cleanup and call super.close() at the end.
392
+ * Closes the transport. Any messages sent while the transport is closed will be silently discarded.
393
+ */
394
+ close(): void;
395
+ /**
396
+ * Default destroy implementation for transports. You should override this in the downstream
397
+ * implementation if you need to do any additional cleanup and call super.destroy() at the end.
398
+ * Destroys the transport. Any messages sent while the transport is destroyed will throw an error.
399
+ */
400
+ destroy(): void;
401
+ }
402
+ declare abstract class ClientTransport<ConnType extends Connection> extends Transport<ConnType> {
403
+ /**
404
+ * The map of reconnect promises for each client ID.
405
+ */
406
+ inflightConnectionPromises: Map<TransportClientId, Promise<ConnType>>;
407
+ tryReconnecting: boolean;
408
+ serverInstanceIds: Map<string, string>;
409
+ constructor(clientId: TransportClientId, providedOptions?: Partial<TransportOptions>);
410
+ protected handleConnection(conn: ConnType, to: TransportClientId): void;
411
+ /**
412
+ * Abstract method that creates a new {@link Connection} object.
413
+ * This should call {@link handleConnection} when the connection is created.
414
+ * The downstream client implementation needs to implement this.
415
+ *
416
+ * @param to The client ID of the node to connect to.
417
+ * @returns The new connection object.
418
+ */
419
+ protected abstract createNewOutgoingConnection(to: TransportClientId): Promise<ConnType>;
420
+ /**
421
+ * Manually attempts to connect to a client.
422
+ * @param to The client ID of the node to connect to.
423
+ */
424
+ connect(to: TransportClientId, attempt?: number): Promise<void>;
425
+ receiveWithBootSequence(conn: ConnType, sessionCb: (sess: Session<ConnType>) => void): (data: Uint8Array) => void;
426
+ onDisconnect(conn: ConnType, connectedTo: string | undefined): void;
427
+ }
428
+ declare abstract class ServerTransport<ConnType extends Connection> extends Transport<ConnType> {
429
+ /**
430
+ * Unique per instance of server transport.
431
+ * This allows us to distinguish reconnects to different
432
+ * server transports at the same reachable address and signal
433
+ * the appropriate session disconnect back to the client at the
434
+ * boot stage.
435
+ */
436
+ instanceId: string;
437
+ constructor(clientId: TransportClientId, providedOptions?: Partial<TransportOptions>);
438
+ protected handleConnection(conn: ConnType): void;
439
+ receiveWithBootSequence(conn: ConnType, sessionCb: (sess: Session<ConnType>) => void): (data: Uint8Array) => void;
440
+ }
441
+
442
+ export { Connection as C, EventMap as E, OpaqueTransportMessage as O, PartialTransportMessage as P, ServerTransport as S, Transport as T, ClientTransport as a, TransportClientId as b, TransportOptions as c, Session as d, TransportMessageSchema as e, OpaqueTransportMessageSchema as f, TransportMessage as g, isStreamClose as h, isStreamOpen as i, EventTypes as j, EventHandler as k };
@@ -22,7 +22,8 @@ var logging_exports = {};
22
22
  __export(logging_exports, {
23
23
  bindLogger: () => bindLogger,
24
24
  log: () => log,
25
- setLevel: () => setLevel
25
+ setLevel: () => setLevel,
26
+ unbindLogger: () => unbindLogger
26
27
  });
27
28
  module.exports = __toCommonJS(logging_exports);
28
29
  var LoggingLevels = {
@@ -32,7 +33,7 @@ var LoggingLevels = {
32
33
  error: 2
33
34
  };
34
35
  var log;
35
- var defaultLoggingLevel = "warn";
36
+ var defaultLoggingLevel = "info";
36
37
  function bindLogger(write, color) {
37
38
  const debug = color ? "\x1B[37mdebug\x1B[0m" : "debug";
38
39
  const info = color ? "\x1B[37minfo\x1B[0m" : "info";
@@ -46,6 +47,9 @@ function bindLogger(write, color) {
46
47
  minLevel: log?.minLevel ?? defaultLoggingLevel
47
48
  };
48
49
  }
50
+ function unbindLogger() {
51
+ log = void 0;
52
+ }
49
53
  function setLevel(level) {
50
54
  if (log) {
51
55
  log.minLevel = level;
@@ -55,5 +59,6 @@ function setLevel(level) {
55
59
  0 && (module.exports = {
56
60
  bindLogger,
57
61
  log,
58
- setLevel
62
+ setLevel,
63
+ unbindLogger
59
64
  });
@@ -20,10 +20,15 @@ declare let log: Logger | undefined;
20
20
  * @param color - Whether to use colored log levels.
21
21
  */
22
22
  declare function bindLogger(write: (msg: string) => void, color?: boolean): void;
23
+ /**
24
+ * Unbinds the logger so subsequent logs do not call
25
+ * the write callback previously provided to {@link bindLogger}
26
+ */
27
+ declare function unbindLogger(): void;
23
28
  /**
24
29
  * Sets the minimum logging level for the logger.
25
30
  * @param level - The minimum logging level to set.
26
31
  */
27
32
  declare function setLevel(level: LoggingLevel): void;
28
33
 
29
- export { Logger, bindLogger, log, setLevel };
34
+ export { Logger, bindLogger, log, setLevel, unbindLogger };
@@ -20,10 +20,15 @@ declare let log: Logger | undefined;
20
20
  * @param color - Whether to use colored log levels.
21
21
  */
22
22
  declare function bindLogger(write: (msg: string) => void, color?: boolean): void;
23
+ /**
24
+ * Unbinds the logger so subsequent logs do not call
25
+ * the write callback previously provided to {@link bindLogger}
26
+ */
27
+ declare function unbindLogger(): void;
23
28
  /**
24
29
  * Sets the minimum logging level for the logger.
25
30
  * @param level - The minimum logging level to set.
26
31
  */
27
32
  declare function setLevel(level: LoggingLevel): void;
28
33
 
29
- export { Logger, bindLogger, log, setLevel };
34
+ export { Logger, bindLogger, log, setLevel, unbindLogger };
@@ -1,10 +1,12 @@
1
1
  import {
2
2
  bindLogger,
3
3
  log,
4
- setLevel
5
- } from "../chunk-T7M7OKPE.js";
4
+ setLevel,
5
+ unbindLogger
6
+ } from "../chunk-H4BYJELI.js";
6
7
  export {
7
8
  bindLogger,
8
9
  log,
9
- setLevel
10
+ setLevel,
11
+ unbindLogger
10
12
  };
@@ -0,0 +1,20 @@
1
+ import { Transform, TransformCallback, TransformOptions } from 'node:stream';
2
+
3
+ interface LengthEncodedOptions extends TransformOptions {
4
+ /** Maximum in-memory buffer size before we throw */
5
+ maxBufferSizeBytes: number;
6
+ }
7
+ /**
8
+ * A transform stream that emits data each time a message with a network/BigEndian uint32 length prefix is received.
9
+ * @extends Transform
10
+ */
11
+ declare class Uint32LengthPrefixFraming extends Transform {
12
+ receivedBuffer: Buffer;
13
+ maxBufferSizeBytes: number;
14
+ constructor({ maxBufferSizeBytes, ...options }: LengthEncodedOptions);
15
+ _transform(chunk: Buffer, _encoding: BufferEncoding, cb: TransformCallback): void;
16
+ _flush(cb: TransformCallback): void;
17
+ _destroy(error: Error | null, callback: (error: Error | null) => void): void;
18
+ }
19
+
20
+ export { Uint32LengthPrefixFraming as U };