@replit/river 0.208.4 → 0.209.1

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 (59) hide show
  1. package/README.md +36 -1
  2. package/dist/{adapter-ChksXKVN.d.ts → adapter-Cp7_gIVA.d.ts} +1 -1
  3. package/dist/{adapter-Cuc4JtfV.d.cts → adapter-DjiEwOYi.d.cts} +1 -1
  4. package/dist/{chunk-N62U4PDY.js → chunk-2AV3IIW5.js} +174 -168
  5. package/dist/chunk-2AV3IIW5.js.map +1 -0
  6. package/dist/{chunk-NJNR3MK5.js → chunk-2DRHPFKM.js} +2 -2
  7. package/dist/{chunk-7TKRCDKJ.js → chunk-UC4MQ5FP.js} +2 -2
  8. package/dist/{chunk-7TKRCDKJ.js.map → chunk-UC4MQ5FP.js.map} +1 -1
  9. package/dist/client-CRY4aeRv.d.cts +54 -0
  10. package/dist/client-Cvl0bF5y.d.ts +54 -0
  11. package/dist/codec/index.d.cts +3 -3
  12. package/dist/codec/index.d.ts +3 -3
  13. package/dist/codec/index.js +2 -2
  14. package/dist/common-MmS1PQN7.d.cts +577 -0
  15. package/dist/common-yodP-WNy.d.ts +577 -0
  16. package/dist/{connection-BF4zg6Qv.d.cts → connection-BVE0wfE7.d.cts} +3 -3
  17. package/dist/{connection-Donr3JRB.d.ts → connection-BphUYGjL.d.ts} +3 -3
  18. package/dist/{index-D8IOd3LG.d.ts → index-CSM8soK7.d.ts} +1 -1
  19. package/dist/{index-C9tpZjBN.d.cts → index-D9R6UTMl.d.cts} +1 -1
  20. package/dist/logging/index.d.cts +2 -2
  21. package/dist/logging/index.d.ts +2 -2
  22. package/dist/{message-Di94OL80.d.cts → message-Dlsh5WDF.d.cts} +1 -1
  23. package/dist/{message-Di94OL80.d.ts → message-Dlsh5WDF.d.ts} +1 -1
  24. package/dist/router/index.cjs +174 -168
  25. package/dist/router/index.cjs.map +1 -1
  26. package/dist/router/index.d.cts +21 -18
  27. package/dist/router/index.d.ts +21 -18
  28. package/dist/router/index.js +3 -3
  29. package/dist/server-BKZTIlAc.d.cts +72 -0
  30. package/dist/server-hDGOXIRA.d.ts +72 -0
  31. package/dist/services-9I3wdkpy.d.cts +1010 -0
  32. package/dist/services-BFGny14R.d.ts +1010 -0
  33. package/dist/testUtil/index.cjs +1 -1
  34. package/dist/testUtil/index.cjs.map +1 -1
  35. package/dist/testUtil/index.d.cts +9 -7
  36. package/dist/testUtil/index.d.ts +9 -7
  37. package/dist/testUtil/index.js +2 -2
  38. package/dist/testUtil/index.js.map +1 -1
  39. package/dist/transport/impls/ws/client.cjs +1 -1
  40. package/dist/transport/impls/ws/client.cjs.map +1 -1
  41. package/dist/transport/impls/ws/client.d.cts +6 -5
  42. package/dist/transport/impls/ws/client.d.ts +6 -5
  43. package/dist/transport/impls/ws/client.js +3 -3
  44. package/dist/transport/impls/ws/server.cjs +1 -1
  45. package/dist/transport/impls/ws/server.cjs.map +1 -1
  46. package/dist/transport/impls/ws/server.d.cts +8 -8
  47. package/dist/transport/impls/ws/server.d.ts +8 -8
  48. package/dist/transport/impls/ws/server.js +3 -3
  49. package/dist/transport/impls/ws/server.js.map +1 -1
  50. package/dist/transport/index.cjs +1 -1
  51. package/dist/transport/index.cjs.map +1 -1
  52. package/dist/transport/index.d.cts +7 -74
  53. package/dist/transport/index.d.ts +7 -74
  54. package/dist/transport/index.js +2 -2
  55. package/package.json +1 -1
  56. package/dist/chunk-N62U4PDY.js.map +0 -1
  57. package/dist/transport-CCaWx1Rb.d.cts +0 -1566
  58. package/dist/transport-CZb3vdB4.d.ts +0 -1566
  59. /package/dist/{chunk-NJNR3MK5.js.map → chunk-2DRHPFKM.js.map} +0 -0
@@ -0,0 +1,577 @@
1
+ import { f as TelemetryInfo, b as OpaqueTransportMessage, H as HandshakeErrorResponseCodes, P as ProtocolVersion, a as TransportMessage, e as PartialTransportMessage, c as TransportClientId, g as HandshakeErrorCustomHandlerFatalResponseCodes } from './message-Dlsh5WDF.js';
2
+ import { M as MessageMetadata, T as Tags, L as Logger, a as LogFn, b as LoggingLevel } from './index-CSM8soK7.js';
3
+ import { Static, TSchema } from '@sinclair/typebox';
4
+ import { S as SendResult, b as SendBufferResult, C as Codec, a as CodecMessageAdapter } from './adapter-Cp7_gIVA.js';
5
+ import { Tracer } from '@opentelemetry/api';
6
+
7
+ /**
8
+ * A connection is the actual raw underlying transport connection.
9
+ * It's responsible for dispatching to/from the actual connection itself
10
+ * This should be instantiated as soon as the client/server has a connection
11
+ * It's tied to the lifecycle of the underlying transport connection (i.e. if the WS drops, this connection should be deleted)
12
+ */
13
+ declare abstract class Connection {
14
+ id: string;
15
+ telemetry?: TelemetryInfo;
16
+ constructor();
17
+ get loggingMetadata(): MessageMetadata;
18
+ dataListener?: (msg: Uint8Array) => void;
19
+ closeListener?: () => void;
20
+ errorListener?: (err: Error) => void;
21
+ onData(msg: Uint8Array): void;
22
+ onError(err: Error): void;
23
+ onClose(): void;
24
+ /**
25
+ * Set the callback for when a message is received.
26
+ * @param cb The message handler callback.
27
+ */
28
+ setDataListener(cb: (msg: Uint8Array) => void): void;
29
+ removeDataListener(): void;
30
+ /**
31
+ * Set the callback for when the connection is closed.
32
+ * This should also be called if an error happens and after notifying the error listener.
33
+ * @param cb The callback to call when the connection is closed.
34
+ */
35
+ setCloseListener(cb: () => void): void;
36
+ removeCloseListener(): void;
37
+ /**
38
+ * Set the callback for when an error is received.
39
+ * This should only be used for logging errors, all cleanup
40
+ * should be delegated to setCloseListener.
41
+ *
42
+ * The implementer should take care such that the implemented
43
+ * connection will call both the close and error callbacks
44
+ * on an error.
45
+ *
46
+ * @param cb The callback to call when an error is received.
47
+ */
48
+ setErrorListener(cb: (err: Error) => void): void;
49
+ removeErrorListener(): void;
50
+ /**
51
+ * Sends a message over the connection.
52
+ * @param msg The message to send.
53
+ * @returns true if the message was sent, false otherwise.
54
+ */
55
+ abstract send(msg: Uint8Array): boolean;
56
+ /**
57
+ * Closes the connection.
58
+ */
59
+ abstract close(): void;
60
+ }
61
+
62
+ interface SessionConnectingListeners extends IdentifiedSessionWithGracePeriodListeners {
63
+ onConnectionEstablished: (conn: Connection) => void;
64
+ onConnectionFailed: (err: unknown) => void;
65
+ onConnectionTimeout: () => void;
66
+ }
67
+ interface SessionConnectingProps<ConnType extends Connection> extends IdentifiedSessionWithGracePeriodProps {
68
+ connPromise: Promise<ConnType>;
69
+ listeners: SessionConnectingListeners;
70
+ }
71
+ declare class SessionConnecting<ConnType extends Connection> extends IdentifiedSessionWithGracePeriod {
72
+ readonly state: SessionState.Connecting;
73
+ connPromise: Promise<ConnType>;
74
+ listeners: SessionConnectingListeners;
75
+ connectionTimeout?: ReturnType<typeof setTimeout>;
76
+ constructor(props: SessionConnectingProps<ConnType>);
77
+ bestEffortClose(): void;
78
+ _handleStateExit(): void;
79
+ _handleClose(): void;
80
+ }
81
+
82
+ declare class SessionNoConnection extends IdentifiedSessionWithGracePeriod {
83
+ readonly state: SessionState.NoConnection;
84
+ _handleClose(): void;
85
+ _handleStateExit(): void;
86
+ }
87
+
88
+ interface SessionHandshakingListeners extends IdentifiedSessionWithGracePeriodListeners {
89
+ onConnectionErrored: (err: unknown) => void;
90
+ onConnectionClosed: () => void;
91
+ onHandshake: (msg: OpaqueTransportMessage) => void;
92
+ onInvalidHandshake: (reason: string, code: Static<typeof HandshakeErrorResponseCodes>) => void;
93
+ onHandshakeTimeout: () => void;
94
+ }
95
+ interface SessionHandshakingProps<ConnType extends Connection> extends IdentifiedSessionWithGracePeriodProps {
96
+ conn: ConnType;
97
+ listeners: SessionHandshakingListeners;
98
+ }
99
+ declare class SessionHandshaking<ConnType extends Connection> extends IdentifiedSessionWithGracePeriod {
100
+ readonly state: SessionState.Handshaking;
101
+ conn: ConnType;
102
+ listeners: SessionHandshakingListeners;
103
+ handshakeTimeout?: ReturnType<typeof setTimeout>;
104
+ constructor(props: SessionHandshakingProps<ConnType>);
105
+ get loggingMetadata(): {
106
+ protocolVersion?: ProtocolVersion | undefined;
107
+ clientId?: string | undefined;
108
+ connectedTo?: string | undefined;
109
+ sessionId?: string | undefined;
110
+ connId?: string | undefined;
111
+ transportMessage?: Partial<OpaqueTransportMessage> | undefined;
112
+ validationErrors?: {
113
+ path: string;
114
+ message: string;
115
+ }[] | undefined;
116
+ tags?: Tags[] | undefined;
117
+ telemetry?: {
118
+ traceId: string;
119
+ spanId: string;
120
+ } | undefined;
121
+ extras?: Record<string, unknown> | undefined;
122
+ };
123
+ onHandshakeData: (msg: Uint8Array) => void;
124
+ sendHandshake(msg: TransportMessage): SendResult;
125
+ _handleStateExit(): void;
126
+ _handleClose(): void;
127
+ }
128
+
129
+ interface SessionConnectedListeners {
130
+ onConnectionErrored: (err: unknown) => void;
131
+ onConnectionClosed: () => void;
132
+ onMessage: (msg: OpaqueTransportMessage) => void;
133
+ onMessageSendFailure: (msg: PartialTransportMessage, reason: string) => void;
134
+ onInvalidMessage: (reason: string) => void;
135
+ }
136
+ interface SessionConnectedProps<ConnType extends Connection> extends IdentifiedSessionProps {
137
+ conn: ConnType;
138
+ listeners: SessionConnectedListeners;
139
+ }
140
+ declare class SessionConnected<ConnType extends Connection> extends IdentifiedSession {
141
+ readonly state: SessionState.Connected;
142
+ conn: ConnType;
143
+ listeners: SessionConnectedListeners;
144
+ private heartbeatHandle?;
145
+ private heartbeatMissTimeout?;
146
+ private isActivelyHeartbeating;
147
+ updateBookkeeping(ack: number, seq: number): void;
148
+ private assertSendOrdering;
149
+ send(msg: PartialTransportMessage): SendResult;
150
+ constructor(props: SessionConnectedProps<ConnType>);
151
+ sendBufferedMessages(): SendBufferResult;
152
+ get loggingMetadata(): {
153
+ protocolVersion?: ProtocolVersion | undefined;
154
+ clientId?: string | undefined;
155
+ connectedTo?: string | undefined;
156
+ sessionId?: string | undefined;
157
+ connId?: string | undefined;
158
+ transportMessage?: Partial<OpaqueTransportMessage> | undefined;
159
+ validationErrors?: {
160
+ path: string;
161
+ message: string;
162
+ }[] | undefined;
163
+ tags?: Tags[] | undefined;
164
+ telemetry?: {
165
+ traceId: string;
166
+ spanId: string;
167
+ } | undefined;
168
+ extras?: Record<string, unknown> | undefined;
169
+ };
170
+ startMissingHeartbeatTimeout(): void;
171
+ startActiveHeartbeat(): void;
172
+ private sendHeartbeat;
173
+ onMessageData: (msg: Uint8Array) => void;
174
+ _handleStateExit(): void;
175
+ _handleClose(): void;
176
+ }
177
+
178
+ interface SessionBackingOffListeners extends IdentifiedSessionWithGracePeriodListeners {
179
+ onBackoffFinished: () => void;
180
+ }
181
+ interface SessionBackingOffProps extends IdentifiedSessionWithGracePeriodProps {
182
+ backoffMs: number;
183
+ listeners: SessionBackingOffListeners;
184
+ }
185
+ declare class SessionBackingOff extends IdentifiedSessionWithGracePeriod {
186
+ readonly state: SessionState.BackingOff;
187
+ listeners: SessionBackingOffListeners;
188
+ backoffTimeout?: ReturnType<typeof setTimeout>;
189
+ constructor(props: SessionBackingOffProps);
190
+ _handleClose(): void;
191
+ _handleStateExit(): void;
192
+ }
193
+
194
+ type ClientSession<ConnType extends Connection> = SessionNoConnection | SessionBackingOff | SessionConnecting<ConnType> | SessionHandshaking<ConnType> | SessionConnected<ConnType>;
195
+ type ServerSession<ConnType extends Connection> = SessionConnected<ConnType> | SessionNoConnection;
196
+ type Session<ConnType extends Connection> = ClientSession<ConnType> | ServerSession<ConnType>;
197
+
198
+ declare const ProtocolError: {
199
+ readonly RetriesExceeded: "conn_retry_exceeded";
200
+ readonly HandshakeFailed: "handshake_failed";
201
+ readonly MessageOrderingViolated: "message_ordering_violated";
202
+ readonly InvalidMessage: "invalid_message";
203
+ readonly MessageSendFailure: "message_send_failure";
204
+ };
205
+ type ProtocolErrorType = (typeof ProtocolError)[keyof typeof ProtocolError];
206
+ interface EventMap {
207
+ message: OpaqueTransportMessage;
208
+ sessionStatus: {
209
+ status: 'created' | 'closing';
210
+ session: Session<Connection>;
211
+ } | {
212
+ status: 'closed';
213
+ session: Pick<Session<Connection>, 'id' | 'to'>;
214
+ };
215
+ sessionTransition: {
216
+ state: SessionState.Connected;
217
+ id: SessionId;
218
+ } | {
219
+ state: SessionState.Handshaking;
220
+ id: SessionId;
221
+ } | {
222
+ state: SessionState.Connecting;
223
+ id: SessionId;
224
+ } | {
225
+ state: SessionState.BackingOff;
226
+ id: SessionId;
227
+ } | {
228
+ state: SessionState.NoConnection;
229
+ id: SessionId;
230
+ };
231
+ protocolError: {
232
+ type: (typeof ProtocolError)['HandshakeFailed'];
233
+ code: Static<typeof HandshakeErrorResponseCodes>;
234
+ message: string;
235
+ } | {
236
+ type: Omit<ProtocolErrorType, (typeof ProtocolError)['HandshakeFailed']>;
237
+ message: string;
238
+ };
239
+ transportStatus: {
240
+ status: TransportStatus;
241
+ };
242
+ }
243
+ type EventTypes = keyof EventMap;
244
+ type EventHandler<K extends EventTypes> = (event: EventMap[K]) => unknown;
245
+ declare class EventDispatcher<T extends EventTypes> {
246
+ private eventListeners;
247
+ removeAllListeners(): void;
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
+ * Options to control the backoff and retry behavior of the client transport's connection behaviour.
256
+ *
257
+ * River implements exponential backoff with jitter to prevent flooding the server
258
+ * when there's an issue with connection establishment.
259
+ *
260
+ * The backoff is calculated via the following:
261
+ * backOff = min(jitter + {@link baseIntervalMs} * 2 ^ budget_consumed, {@link maxBackoffMs})
262
+ *
263
+ * We use a leaky bucket rate limit with a budget of {@link attemptBudgetCapacity} reconnection attempts.
264
+ * Budget only starts to restore after a successful handshake at a rate of one budget per {@link budgetRestoreIntervalMs}.
265
+ */
266
+ interface ConnectionRetryOptions {
267
+ /**
268
+ * The base interval to wait before retrying a connection.
269
+ */
270
+ baseIntervalMs: number;
271
+ /**
272
+ * The maximum random jitter to add to the total backoff time.
273
+ */
274
+ maxJitterMs: number;
275
+ /**
276
+ * The maximum amount of time to wait before retrying a connection.
277
+ * This does not include the jitter.
278
+ */
279
+ maxBackoffMs: number;
280
+ /**
281
+ * The max number of times to attempt a connection before a successful handshake.
282
+ * This persists across connections but starts restoring budget after a successful handshake.
283
+ * The restoration interval depends on {@link budgetRestoreIntervalMs}
284
+ */
285
+ attemptBudgetCapacity: number;
286
+ /**
287
+ * After a successful connection attempt, how long to wait before we restore a single budget.
288
+ */
289
+ budgetRestoreIntervalMs: number;
290
+ }
291
+ declare class LeakyBucketRateLimit {
292
+ private budgetConsumed;
293
+ private intervalHandle?;
294
+ private readonly options;
295
+ constructor(options: ConnectionRetryOptions);
296
+ getBackoffMs(): number;
297
+ get totalBudgetRestoreTime(): number;
298
+ consumeBudget(): void;
299
+ getBudgetConsumed(): number;
300
+ hasBudget(): boolean;
301
+ startRestoringBudget(): void;
302
+ private stopLeak;
303
+ close(): void;
304
+ }
305
+
306
+ type TransportOptions = SessionOptions;
307
+ type ProvidedTransportOptions = Partial<TransportOptions>;
308
+ type ClientTransportOptions = TransportOptions & ConnectionRetryOptions;
309
+ type ProvidedClientTransportOptions = Partial<ClientTransportOptions>;
310
+ type ServerTransportOptions = TransportOptions;
311
+ type ProvidedServerTransportOptions = Partial<ServerTransportOptions>;
312
+
313
+ /**
314
+ * Represents the possible states of a transport.
315
+ * @property {'open'} open - The transport is open and operational (note that this doesn't mean it is actively connected)
316
+ * @property {'closed'} closed - The transport is permanently closed and cannot be reopened.
317
+ */
318
+ type TransportStatus = 'open' | 'closed';
319
+ interface DeleteSessionOptions {
320
+ unhealthy: boolean;
321
+ }
322
+ type SessionBoundSendFn = (msg: PartialTransportMessage) => string;
323
+ /**
324
+ * Transports manage the lifecycle (creation/deletion) of sessions
325
+ *
326
+ * ```plaintext
327
+ * ▲
328
+ * incoming │
329
+ * messages │
330
+ * ▼
331
+ * ┌─────────────┐ 1:N ┌───────────┐ 1:1* ┌────────────┐
332
+ * │ Transport │ ◄─────► │ Session │ ◄─────► │ Connection │
333
+ * └─────────────┘ └───────────┘ └────────────┘
334
+ * ▲ * (may or may not be initialized yet)
335
+ * │
336
+ * ▼
337
+ * ┌───────────┐
338
+ * │ Message │
339
+ * │ Listeners │
340
+ * └───────────┘
341
+ * ```
342
+ * @abstract
343
+ */
344
+ declare abstract class Transport<ConnType extends Connection> {
345
+ /**
346
+ * The status of the transport.
347
+ */
348
+ private status;
349
+ /**
350
+ * The client ID of this transport.
351
+ */
352
+ clientId: TransportClientId;
353
+ /**
354
+ * The event dispatcher for handling events of type EventTypes.
355
+ */
356
+ eventDispatcher: EventDispatcher<EventTypes>;
357
+ /**
358
+ * The options for this transport.
359
+ */
360
+ protected options: TransportOptions;
361
+ log?: Logger;
362
+ tracer: Tracer;
363
+ sessions: Map<TransportClientId, Session<ConnType>>;
364
+ /**
365
+ * Creates a new Transport instance.
366
+ * @param codec The codec used to encode and decode messages.
367
+ * @param clientId The client ID of this transport.
368
+ */
369
+ constructor(clientId: TransportClientId, providedOptions?: ProvidedTransportOptions);
370
+ bindLogger(fn: LogFn | Logger, level?: LoggingLevel): void;
371
+ /**
372
+ * Called when a message is received by this transport.
373
+ * You generally shouldn't need to override this in downstream transport implementations.
374
+ * @param message The received message.
375
+ */
376
+ protected handleMsg(message: OpaqueTransportMessage): void;
377
+ /**
378
+ * Adds a listener to this transport.
379
+ * @param the type of event to listen for
380
+ * @param handler The message handler to add.
381
+ */
382
+ addEventListener<K extends EventTypes, T extends EventHandler<K>>(type: K, handler: T): void;
383
+ /**
384
+ * Removes a listener from this transport.
385
+ * @param the type of event to un-listen on
386
+ * @param handler The message handler to remove.
387
+ */
388
+ removeEventListener<K extends EventTypes, T extends EventHandler<K>>(type: K, handler: T): void;
389
+ protected protocolError(message: EventMap['protocolError']): void;
390
+ /**
391
+ * Default close implementation for transports. You should override this in the downstream
392
+ * implementation if you need to do any additional cleanup and call super.close() at the end.
393
+ * Closes the transport. Any messages sent while the transport is closed will be silently discarded.
394
+ */
395
+ close(): void;
396
+ getStatus(): TransportStatus;
397
+ protected createSession<S extends Session<ConnType>>(session: S): void;
398
+ protected updateSession<S extends Session<ConnType>>(session: S): void;
399
+ protected deleteSession(session: Session<ConnType>, options?: DeleteSessionOptions): void;
400
+ protected onSessionGracePeriodElapsed(session: Session<ConnType>): void;
401
+ protected onConnectingFailed(session: SessionConnecting<ConnType>): SessionNoConnection;
402
+ protected onConnClosed(session: SessionHandshaking<ConnType> | SessionConnected<ConnType>): SessionNoConnection;
403
+ /**
404
+ * Gets a send closure scoped to a specific session. Sending using the returned
405
+ * closure after the session has transitioned to a different state will be a noop.
406
+ *
407
+ * Session objects themselves can become stale as they transition between
408
+ * states. As stale sessions cannot be used again (and will throw), holding
409
+ * onto a session object is not recommended.
410
+ */
411
+ getSessionBoundSendFn(to: TransportClientId, sessionId: SessionId): SessionBoundSendFn;
412
+ }
413
+
414
+ type ConstructHandshake<T extends TSchema> = () => Static<T> | Promise<Static<T>>;
415
+ type ValidateHandshake<T extends TSchema, ParsedMetadata> = (metadata: Static<T>, previousParsedMetadata?: ParsedMetadata) => Static<typeof HandshakeErrorCustomHandlerFatalResponseCodes> | ParsedMetadata | Promise<Static<typeof HandshakeErrorCustomHandlerFatalResponseCodes> | ParsedMetadata>;
416
+ interface ClientHandshakeOptions<MetadataSchema extends TSchema = TSchema> {
417
+ /**
418
+ * Schema for the metadata that the client sends to the server
419
+ * during the handshake.
420
+ */
421
+ schema: MetadataSchema;
422
+ /**
423
+ * Gets the {@link HandshakeRequestMetadata} to send to the server.
424
+ */
425
+ construct: ConstructHandshake<MetadataSchema>;
426
+ }
427
+ interface ServerHandshakeOptions<MetadataSchema extends TSchema = TSchema, ParsedMetadata extends object = object> {
428
+ /**
429
+ * Schema for the metadata that the server receives from the client
430
+ * during the handshake.
431
+ */
432
+ schema: MetadataSchema;
433
+ /**
434
+ * Parses the {@link HandshakeRequestMetadata} sent by the client, transforming
435
+ * it into {@link ParsedHandshakeMetadata}.
436
+ *
437
+ * May return `false` if the client should be rejected.
438
+ *
439
+ * @param metadata - The metadata sent by the client.
440
+ * @param session - The session that the client would be associated with.
441
+ * @param isReconnect - Whether the client is reconnecting to the session,
442
+ * or if this is a new session.
443
+ */
444
+ validate: ValidateHandshake<MetadataSchema, ParsedMetadata>;
445
+ }
446
+ declare function createClientHandshakeOptions<MetadataSchema extends TSchema = TSchema>(schema: MetadataSchema, construct: ConstructHandshake<MetadataSchema>): ClientHandshakeOptions;
447
+ declare function createServerHandshakeOptions<MetadataSchema extends TSchema = TSchema, ParsedMetadata extends object = object>(schema: MetadataSchema, validate: ValidateHandshake<MetadataSchema, ParsedMetadata>): ServerHandshakeOptions<MetadataSchema, ParsedMetadata>;
448
+
449
+ declare const enum SessionState {
450
+ NoConnection = "NoConnection",
451
+ BackingOff = "BackingOff",
452
+ Connecting = "Connecting",
453
+ Handshaking = "Handshaking",
454
+ Connected = "Connected",
455
+ WaitingForHandshake = "WaitingForHandshake"
456
+ }
457
+ declare abstract class StateMachineState {
458
+ abstract readonly state: SessionState;
459
+ _isConsumed: boolean;
460
+ abstract _handleStateExit(): void;
461
+ abstract _handleClose(): void;
462
+ /**
463
+ * Cleanup this state machine state and mark it as consumed.
464
+ * After calling close, it is an error to access any properties on the state.
465
+ * You should never need to call this as a consumer.
466
+ *
467
+ * If you're looking to close the session from the client,
468
+ * use `.hardDisconnect` on the client transport.
469
+ */
470
+ close(): void;
471
+ constructor();
472
+ }
473
+ interface SessionOptions {
474
+ /**
475
+ * Frequency at which to send heartbeat acknowledgements
476
+ */
477
+ heartbeatIntervalMs: number;
478
+ /**
479
+ * Number of elapsed heartbeats without a response message before we consider
480
+ * the connection dead.
481
+ */
482
+ heartbeatsUntilDead: number;
483
+ /**
484
+ * Max duration that a session can be without a connection before we consider
485
+ * it dead. This deadline is carried between states and is used to determine
486
+ * when to consider the session a lost cause and delete it entirely.
487
+ * Generally, this should be strictly greater than the sum of
488
+ * {@link connectionTimeoutMs} and {@link handshakeTimeoutMs}.
489
+ */
490
+ sessionDisconnectGraceMs: number;
491
+ /**
492
+ * Connection timeout in milliseconds
493
+ */
494
+ connectionTimeoutMs: number;
495
+ /**
496
+ * Handshake timeout in milliseconds
497
+ */
498
+ handshakeTimeoutMs: number;
499
+ /**
500
+ * Whether to enable transparent session reconnects
501
+ */
502
+ enableTransparentSessionReconnects: boolean;
503
+ /**
504
+ * The codec to use for encoding/decoding messages over the wire
505
+ */
506
+ codec: Codec;
507
+ }
508
+ interface CommonSessionProps {
509
+ from: TransportClientId;
510
+ options: SessionOptions;
511
+ codec: CodecMessageAdapter;
512
+ tracer: Tracer;
513
+ log: Logger | undefined;
514
+ }
515
+ declare abstract class CommonSession extends StateMachineState {
516
+ readonly from: TransportClientId;
517
+ readonly options: SessionOptions;
518
+ readonly codec: CodecMessageAdapter;
519
+ tracer: Tracer;
520
+ log?: Logger;
521
+ abstract get loggingMetadata(): MessageMetadata;
522
+ constructor({ from, options, log, tracer, codec }: CommonSessionProps);
523
+ }
524
+ type SessionId = string;
525
+ interface IdentifiedSessionProps extends CommonSessionProps {
526
+ id: SessionId;
527
+ to: TransportClientId;
528
+ seq: number;
529
+ ack: number;
530
+ seqSent: number;
531
+ sendBuffer: Array<OpaqueTransportMessage>;
532
+ telemetry: TelemetryInfo;
533
+ protocolVersion: ProtocolVersion;
534
+ }
535
+ declare abstract class IdentifiedSession extends CommonSession {
536
+ readonly id: SessionId;
537
+ readonly telemetry: TelemetryInfo;
538
+ readonly to: TransportClientId;
539
+ readonly protocolVersion: ProtocolVersion;
540
+ /**
541
+ * Index of the message we will send next (excluding handshake)
542
+ */
543
+ seq: number;
544
+ /**
545
+ * Last seq we sent over the wire this session (excluding handshake) and retransmissions
546
+ */
547
+ seqSent: number;
548
+ /**
549
+ * Number of unique messages we've received this session (excluding handshake)
550
+ */
551
+ ack: number;
552
+ sendBuffer: Array<OpaqueTransportMessage>;
553
+ constructor(props: IdentifiedSessionProps);
554
+ get loggingMetadata(): MessageMetadata;
555
+ constructMsg<Payload>(partialMsg: PartialTransportMessage<Payload>): TransportMessage<Payload>;
556
+ nextSeq(): number;
557
+ send(msg: PartialTransportMessage): SendResult;
558
+ _handleStateExit(): void;
559
+ _handleClose(): void;
560
+ }
561
+ interface IdentifiedSessionWithGracePeriodListeners {
562
+ onSessionGracePeriodElapsed: () => void;
563
+ }
564
+ interface IdentifiedSessionWithGracePeriodProps extends IdentifiedSessionProps {
565
+ graceExpiryTime: number;
566
+ listeners: IdentifiedSessionWithGracePeriodListeners;
567
+ }
568
+ declare abstract class IdentifiedSessionWithGracePeriod extends IdentifiedSession {
569
+ graceExpiryTime: number;
570
+ protected gracePeriodTimeout?: ReturnType<typeof setTimeout>;
571
+ listeners: IdentifiedSessionWithGracePeriodListeners;
572
+ constructor(props: IdentifiedSessionWithGracePeriodProps);
573
+ _handleStateExit(): void;
574
+ _handleClose(): void;
575
+ }
576
+
577
+ export { Connection as C, type DeleteSessionOptions as D, type EventMap as E, LeakyBucketRateLimit as L, type ProvidedTransportOptions as P, type Session as S, Transport as T, type TransportStatus as a, type ProvidedClientTransportOptions as b, type ProvidedServerTransportOptions as c, SessionState as d, SessionNoConnection as e, SessionConnecting as f, SessionHandshaking as g, SessionConnected as h, type EventTypes as i, type EventHandler as j, ProtocolError as k, type ProtocolErrorType as l, type ClientTransportOptions as m, type ClientHandshakeOptions as n, type ClientSession as o, SessionBackingOff as p, type ServerHandshakeOptions as q, createClientHandshakeOptions as r, createServerHandshakeOptions as s, CommonSession as t, type CommonSessionProps as u, type ServerTransportOptions as v, type ServerSession as w, type SessionOptions as x, type SessionBoundSendFn as y, type SessionId as z };
@@ -1,6 +1,6 @@
1
- import { T as Tags } from './index-C9tpZjBN.cjs';
2
- import { P as ProtocolVersion, O as OpaqueTransportMessage } from './message-Di94OL80.cjs';
3
- import { b as Connection } from './transport-CCaWx1Rb.cjs';
1
+ import { T as Tags } from './index-D9R6UTMl.cjs';
2
+ import { P as ProtocolVersion, b as OpaqueTransportMessage } from './message-Dlsh5WDF.cjs';
3
+ import { C as Connection } from './common-MmS1PQN7.cjs';
4
4
  import { W as WsLike } from './wslike-Dng9H1C7.cjs';
5
5
 
6
6
  interface ConnectionInfoExtras extends Record<string, unknown> {
@@ -1,6 +1,6 @@
1
- import { T as Tags } from './index-D8IOd3LG.js';
2
- import { P as ProtocolVersion, O as OpaqueTransportMessage } from './message-Di94OL80.js';
3
- import { b as Connection } from './transport-CZb3vdB4.js';
1
+ import { T as Tags } from './index-CSM8soK7.js';
2
+ import { P as ProtocolVersion, b as OpaqueTransportMessage } from './message-Dlsh5WDF.js';
3
+ import { C as Connection } from './common-yodP-WNy.js';
4
4
  import { W as WsLike } from './wslike-Dng9H1C7.js';
5
5
 
6
6
  interface ConnectionInfoExtras extends Record<string, unknown> {
@@ -1,4 +1,4 @@
1
- import { P as ProtocolVersion, O as OpaqueTransportMessage } from './message-Di94OL80.js';
1
+ import { P as ProtocolVersion, b as OpaqueTransportMessage } from './message-Dlsh5WDF.js';
2
2
 
3
3
  declare const LoggingLevels: {
4
4
  readonly debug: -1;
@@ -1,4 +1,4 @@
1
- import { P as ProtocolVersion, O as OpaqueTransportMessage } from './message-Di94OL80.cjs';
1
+ import { P as ProtocolVersion, b as OpaqueTransportMessage } from './message-Dlsh5WDF.cjs';
2
2
 
3
3
  declare const LoggingLevels: {
4
4
  readonly debug: -1;
@@ -1,4 +1,4 @@
1
- export { a as LogFn, L as Logger, M as MessageMetadata, c as coloredStringLogger, j as jsonLogger, s as stringLogger } from '../index-C9tpZjBN.cjs';
2
- import '../message-Di94OL80.cjs';
1
+ export { a as LogFn, L as Logger, M as MessageMetadata, c as coloredStringLogger, j as jsonLogger, s as stringLogger } from '../index-D9R6UTMl.cjs';
2
+ import '../message-Dlsh5WDF.cjs';
3
3
  import '@sinclair/typebox';
4
4
  import '@opentelemetry/api';
@@ -1,4 +1,4 @@
1
- export { a as LogFn, L as Logger, M as MessageMetadata, c as coloredStringLogger, j as jsonLogger, s as stringLogger } from '../index-D8IOd3LG.js';
2
- import '../message-Di94OL80.js';
1
+ export { a as LogFn, L as Logger, M as MessageMetadata, c as coloredStringLogger, j as jsonLogger, s as stringLogger } from '../index-CSM8soK7.js';
2
+ import '../message-Dlsh5WDF.js';
3
3
  import '@sinclair/typebox';
4
4
  import '@opentelemetry/api';
@@ -105,4 +105,4 @@ declare function isStreamOpen(controlFlag: number): boolean;
105
105
  */
106
106
  declare function isStreamClose(controlFlag: number): boolean;
107
107
 
108
- export { HandshakeErrorCustomHandlerFatalResponseCodes as H, type OpaqueTransportMessage as O, type ProtocolVersion as P, type TransportClientId as T, type PartialTransportMessage as a, type TelemetryInfo as b, type TransportMessage as c, HandshakeErrorResponseCodes as d, TransportMessageSchema as e, OpaqueTransportMessageSchema as f, isStreamClose as g, isStreamOpen as i };
108
+ export { HandshakeErrorResponseCodes as H, OpaqueTransportMessageSchema as O, type ProtocolVersion as P, TransportMessageSchema as T, type TransportMessage as a, type OpaqueTransportMessage as b, type TransportClientId as c, isStreamClose as d, type PartialTransportMessage as e, type TelemetryInfo as f, HandshakeErrorCustomHandlerFatalResponseCodes as g, isStreamOpen as i };
@@ -105,4 +105,4 @@ declare function isStreamOpen(controlFlag: number): boolean;
105
105
  */
106
106
  declare function isStreamClose(controlFlag: number): boolean;
107
107
 
108
- export { HandshakeErrorCustomHandlerFatalResponseCodes as H, type OpaqueTransportMessage as O, type ProtocolVersion as P, type TransportClientId as T, type PartialTransportMessage as a, type TelemetryInfo as b, type TransportMessage as c, HandshakeErrorResponseCodes as d, TransportMessageSchema as e, OpaqueTransportMessageSchema as f, isStreamClose as g, isStreamOpen as i };
108
+ export { HandshakeErrorResponseCodes as H, OpaqueTransportMessageSchema as O, type ProtocolVersion as P, TransportMessageSchema as T, type TransportMessage as a, type OpaqueTransportMessage as b, type TransportClientId as c, isStreamClose as d, type PartialTransportMessage as e, type TelemetryInfo as f, HandshakeErrorCustomHandlerFatalResponseCodes as g, isStreamOpen as i };