@replit/river 0.23.3 → 0.23.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.
Files changed (59) hide show
  1. package/README.md +48 -0
  2. package/dist/{chunk-IKT6A32W.js → chunk-BHNINW7F.js} +2 -2
  3. package/dist/chunk-BHNINW7F.js.map +1 -0
  4. package/dist/{chunk-XZV3HOQW.js → chunk-CHOAXTQF.js} +2 -2
  5. package/dist/chunk-CHOAXTQF.js.map +1 -0
  6. package/dist/{chunk-3U43VMW2.js → chunk-PTX6DT5G.js} +2 -2
  7. package/dist/{chunk-R3EG3FOP.js → chunk-RWYW2BES.js} +2 -2
  8. package/dist/{chunk-JBRQNEBV.js → chunk-WTJY7S3D.js} +2 -2
  9. package/dist/chunk-WTJY7S3D.js.map +1 -0
  10. package/dist/{connection-89a66019.d.ts → connection-36e8bb12.d.ts} +1 -1
  11. package/dist/{connection-4abad643.d.ts → connection-a5bc5e9f.d.ts} +1 -1
  12. package/dist/index-926aea33.d.ts +133 -0
  13. package/dist/logging/index.d.cts +1 -2
  14. package/dist/logging/index.d.ts +1 -2
  15. package/dist/router/index.cjs +1 -1
  16. package/dist/router/index.cjs.map +1 -1
  17. package/dist/router/index.d.cts +7 -7
  18. package/dist/router/index.d.ts +7 -7
  19. package/dist/router/index.js +2 -2
  20. package/dist/{services-ef89f5b0.d.ts → services-da250ed2.d.ts} +2 -2
  21. package/dist/transport/impls/uds/client.cjs +1 -1
  22. package/dist/transport/impls/uds/client.cjs.map +1 -1
  23. package/dist/transport/impls/uds/client.d.cts +4 -4
  24. package/dist/transport/impls/uds/client.d.ts +4 -4
  25. package/dist/transport/impls/uds/client.js +3 -3
  26. package/dist/transport/impls/uds/server.cjs +1 -1
  27. package/dist/transport/impls/uds/server.cjs.map +1 -1
  28. package/dist/transport/impls/uds/server.d.cts +4 -4
  29. package/dist/transport/impls/uds/server.d.ts +4 -4
  30. package/dist/transport/impls/uds/server.js +3 -3
  31. package/dist/transport/impls/ws/client.cjs +1 -1
  32. package/dist/transport/impls/ws/client.cjs.map +1 -1
  33. package/dist/transport/impls/ws/client.d.cts +4 -4
  34. package/dist/transport/impls/ws/client.d.ts +4 -4
  35. package/dist/transport/impls/ws/client.js +3 -3
  36. package/dist/transport/impls/ws/server.cjs +1 -1
  37. package/dist/transport/impls/ws/server.cjs.map +1 -1
  38. package/dist/transport/impls/ws/server.d.cts +3 -3
  39. package/dist/transport/impls/ws/server.d.ts +3 -3
  40. package/dist/transport/impls/ws/server.js +3 -3
  41. package/dist/transport/index.cjs +1 -1
  42. package/dist/transport/index.cjs.map +1 -1
  43. package/dist/transport/index.d.cts +4 -307
  44. package/dist/transport/index.d.ts +4 -307
  45. package/dist/transport/index.js +2 -2
  46. package/dist/transport-4a5e288a.d.ts +535 -0
  47. package/dist/util/testHelpers.cjs +1 -1
  48. package/dist/util/testHelpers.cjs.map +1 -1
  49. package/dist/util/testHelpers.d.cts +3 -3
  50. package/dist/util/testHelpers.d.ts +3 -3
  51. package/dist/util/testHelpers.js +3 -3
  52. package/package.json +1 -1
  53. package/dist/chunk-IKT6A32W.js.map +0 -1
  54. package/dist/chunk-JBRQNEBV.js.map +0 -1
  55. package/dist/chunk-XZV3HOQW.js.map +0 -1
  56. package/dist/index-a009d7f6.d.ts +0 -360
  57. package/dist/services-edc3b16d.d.ts +0 -707
  58. /package/dist/{chunk-3U43VMW2.js.map → chunk-PTX6DT5G.js.map} +0 -0
  59. /package/dist/{chunk-R3EG3FOP.js.map → chunk-RWYW2BES.js.map} +0 -0
@@ -0,0 +1,535 @@
1
+ import { C as Codec } from './types-3e5768ec.js';
2
+ import { a as TelemetryInfo, T as TransportClientId, b as PropagationContext, M as MessageMetadata, P as PartialTransportMessage, c as TransportMessage, O as OpaqueTransportMessage } from './index-926aea33.js';
3
+ import { TSchema, Static } from '@sinclair/typebox';
4
+
5
+ /**
6
+ * A connection is the actual raw underlying transport connection.
7
+ * It’s responsible for dispatching to/from the actual connection itself
8
+ * This should be instantiated as soon as the client/server has a connection
9
+ * It’s tied to the lifecycle of the underlying transport connection (i.e. if the WS drops, this connection should be deleted)
10
+ */
11
+ declare abstract class Connection {
12
+ id: string;
13
+ telemetry?: TelemetryInfo;
14
+ constructor();
15
+ /**
16
+ * Handle adding a callback for when a message is received.
17
+ * @param msg The message that was received.
18
+ */
19
+ abstract addDataListener(cb: (msg: Uint8Array) => void): void;
20
+ abstract removeDataListener(cb: (msg: Uint8Array) => void): void;
21
+ /**
22
+ * Handle adding a callback for when the connection is closed.
23
+ * This should also be called if an error happens.
24
+ * @param cb The callback to call when the connection is closed.
25
+ */
26
+ abstract addCloseListener(cb: () => void): void;
27
+ /**
28
+ * Handle adding a callback for when an error is received.
29
+ * This should only be used for logging errors, all cleanup
30
+ * should be delegated to addCloseListener.
31
+ *
32
+ * The implementer should take care such that the implemented
33
+ * connection will call both the close and error callbacks
34
+ * on an error.
35
+ *
36
+ * @param cb The callback to call when an error is received.
37
+ */
38
+ abstract addErrorListener(cb: (err: Error) => void): void;
39
+ /**
40
+ * Sends a message over the connection.
41
+ * @param msg The message to send.
42
+ * @returns true if the message was sent, false otherwise.
43
+ */
44
+ abstract send(msg: Uint8Array): boolean;
45
+ /**
46
+ * Closes the connection.
47
+ */
48
+ abstract close(): void;
49
+ }
50
+ interface SessionOptions {
51
+ /**
52
+ * Frequency at which to send heartbeat acknowledgements
53
+ */
54
+ heartbeatIntervalMs: number;
55
+ /**
56
+ * Number of elapsed heartbeats without a response message before we consider
57
+ * the connection dead.
58
+ */
59
+ heartbeatsUntilDead: number;
60
+ /**
61
+ * Duration to wait between connection disconnect and actual session disconnect
62
+ */
63
+ sessionDisconnectGraceMs: number;
64
+ /**
65
+ * The codec to use for encoding/decoding messages over the wire
66
+ */
67
+ codec: Codec;
68
+ }
69
+ /**
70
+ * A session is a higher-level abstraction that operates over the span of potentially multiple transport-level connections
71
+ * - 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)
72
+ * - This will only be considered disconnected if
73
+ * - the server tells the client that we’ve reconnected but it doesn’t recognize us anymore (server definitely died) or
74
+ * - we hit a grace period after a connection disconnect
75
+ */
76
+ declare class Session<ConnType extends Connection> {
77
+ private codec;
78
+ private options;
79
+ telemetry: TelemetryInfo;
80
+ /**
81
+ * The buffer of messages that have been sent but not yet acknowledged.
82
+ */
83
+ private sendBuffer;
84
+ /**
85
+ * The active connection associated with this session
86
+ */
87
+ connection?: ConnType;
88
+ readonly from: TransportClientId;
89
+ readonly to: TransportClientId;
90
+ /**
91
+ * The unique ID of this session.
92
+ */
93
+ id: string;
94
+ /**
95
+ * What the other side advertised as their session ID
96
+ * for this session.
97
+ */
98
+ advertisedSessionId?: string;
99
+ /**
100
+ * Number of messages we've sent along this session (excluding handshake and acks)
101
+ */
102
+ private seq;
103
+ /**
104
+ * Number of unique messages we've received this session (excluding handshake and acks)
105
+ */
106
+ private ack;
107
+ /**
108
+ * The grace period between when the inner connection is disconnected
109
+ * and when we should consider the entire session disconnected.
110
+ */
111
+ private disconnectionGrace?;
112
+ /**
113
+ * Number of heartbeats we've sent without a response.
114
+ */
115
+ private heartbeatMisses;
116
+ /**
117
+ * The interval for sending heartbeats.
118
+ */
119
+ private heartbeat;
120
+ constructor(conn: ConnType | undefined, from: TransportClientId, to: TransportClientId, options: SessionOptions, propagationCtx?: PropagationContext);
121
+ get loggingMetadata(): Omit<MessageMetadata, 'parsedMsg'>;
122
+ /**
123
+ * Sends a message over the session's connection.
124
+ * If the connection is not ready or the message fails to send, the message can be buffered for retry unless skipped.
125
+ *
126
+ * @param msg The partial message to be sent, which will be constructed into a full message.
127
+ * @param addToSendBuff Whether to add the message to the send buffer for retry.
128
+ * @returns The full transport ID of the message that was attempted to be sent.
129
+ */
130
+ send(msg: PartialTransportMessage): string;
131
+ sendHeartbeat(): void;
132
+ resetBufferedMessages(): void;
133
+ sendBufferedMessages(conn: ConnType): void;
134
+ updateBookkeeping(ack: number, seq: number): void;
135
+ closeStaleConnection(conn?: ConnType): void;
136
+ replaceWithNewConnection(newConn: ConnType): void;
137
+ beginGrace(cb: () => void): void;
138
+ cancelGrace(): void;
139
+ close(): void;
140
+ get connected(): boolean;
141
+ get nextExpectedSeq(): number;
142
+ constructMsg<Payload>(partialMsg: PartialTransportMessage<Payload>): TransportMessage<Payload>;
143
+ inspectSendBuffer(): ReadonlyArray<OpaqueTransportMessage>;
144
+ }
145
+
146
+ type ConnectionStatus = 'connect' | 'disconnect';
147
+ declare const ProtocolError: {
148
+ readonly RetriesExceeded: "conn_retry_exceeded";
149
+ readonly HandshakeFailed: "handshake_failed";
150
+ readonly UseAfterDestroy: "use_after_destroy";
151
+ readonly MessageOrderingViolated: "message_ordering_violated";
152
+ };
153
+ type ProtocolErrorType = (typeof ProtocolError)[keyof typeof ProtocolError];
154
+ interface EventMap {
155
+ message: OpaqueTransportMessage;
156
+ connectionStatus: {
157
+ status: ConnectionStatus;
158
+ conn: Connection;
159
+ };
160
+ sessionStatus: {
161
+ status: ConnectionStatus;
162
+ session: Session<Connection>;
163
+ };
164
+ protocolError: {
165
+ type: ProtocolErrorType;
166
+ message: string;
167
+ };
168
+ }
169
+ type EventTypes = keyof EventMap;
170
+ type EventHandler<K extends EventTypes> = (event: EventMap[K]) => unknown;
171
+ declare class EventDispatcher<T extends EventTypes> {
172
+ private eventListeners;
173
+ numberOfListeners<K extends T>(eventType: K): number;
174
+ addEventListener<K extends T>(eventType: K, handler: EventHandler<K>): void;
175
+ removeEventListener<K extends T>(eventType: K, handler: EventHandler<K>): void;
176
+ dispatchEvent<K extends T>(eventType: K, event: EventMap[K]): void;
177
+ }
178
+
179
+ /**
180
+ * Options to control the backoff and retry behavior of the client transport's connection behaviour.
181
+ *
182
+ * River implements exponential backoff with jitter to prevent flooding the server
183
+ * when there's an issue with connection establishment.
184
+ *
185
+ * The backoff is calculated via the following:
186
+ * backOff = min(jitter + {@link baseIntervalMs} * 2 ^ budget_consumed, {@link maxBackoffMs})
187
+ *
188
+ * We use a leaky bucket rate limit with a budget of {@link attemptBudgetCapacity} reconnection attempts.
189
+ * Budget only starts to restore after a successful handshake at a rate of one budget per {@link budgetRestoreIntervalMs}.
190
+ */
191
+ interface ConnectionRetryOptions {
192
+ /**
193
+ * The base interval to wait before retrying a connection.
194
+ */
195
+ baseIntervalMs: number;
196
+ /**
197
+ * The maximum random jitter to add to the total backoff time.
198
+ */
199
+ maxJitterMs: number;
200
+ /**
201
+ * The maximum amount of time to wait before retrying a connection.
202
+ * This does not include the jitter.
203
+ */
204
+ maxBackoffMs: number;
205
+ /**
206
+ * The max number of times to attempt a connection before a successful handshake.
207
+ * This persists across connections but starts restoring budget after a successful handshake.
208
+ * The restoration interval depends on {@link budgetRestoreIntervalMs}
209
+ */
210
+ attemptBudgetCapacity: number;
211
+ /**
212
+ * After a successful connection attempt, how long to wait before we restore a single budget.
213
+ */
214
+ budgetRestoreIntervalMs: number;
215
+ }
216
+ declare class LeakyBucketRateLimit {
217
+ private budgetConsumed;
218
+ private intervalHandles;
219
+ private readonly options;
220
+ constructor(options: ConnectionRetryOptions);
221
+ getBackoffMs(user: TransportClientId): number;
222
+ get totalBudgetRestoreTime(): number;
223
+ consumeBudget(user: TransportClientId): void;
224
+ getBudgetConsumed(user: TransportClientId): number;
225
+ hasBudget(user: TransportClientId): boolean;
226
+ startRestoringBudget(user: TransportClientId): void;
227
+ private stopLeak;
228
+ close(): void;
229
+ }
230
+
231
+ /**
232
+ * The context for services/procedures. This is used only on
233
+ * the server.
234
+ *
235
+ * An important detail is that the state prop is always on
236
+ * this interface and it shouldn't be changed, removed, or
237
+ * extended. This prop is for the state of a service.
238
+ *
239
+ * You should use declaration merging to extend this interface
240
+ * with whatever you need. For example, if you need to access
241
+ * a database, you could do:
242
+ *
243
+ * ```ts
244
+ * declare module '@replit/river' {
245
+ * interface ServiceContext {
246
+ * db: Database;
247
+ * }
248
+ * }
249
+ * ```
250
+ */
251
+ interface ServiceContext {
252
+ }
253
+ /**
254
+ * The parsed metadata schema for a service. This is the
255
+ * return value of the {@link ServerHandshakeOptions.validate}
256
+ * if the handshake extension is used.
257
+
258
+ * You should use declaration merging to extend this interface
259
+ * with the sanitized metadata.
260
+ *
261
+ * ```ts
262
+ * declare module '@replit/river' {
263
+ * interface ParsedMetadata {
264
+ * userId: number;
265
+ * }
266
+ * }
267
+ * ```
268
+ */
269
+ interface ParsedMetadata {
270
+ }
271
+ /**
272
+ * The {@link ServiceContext} with state. This is what is passed to procedures.
273
+ */
274
+ type ServiceContextWithState<State> = ServiceContext & {
275
+ state: State;
276
+ };
277
+ type ServiceContextWithTransportInfo<State> = ServiceContext & {
278
+ state: Omit<State, typeof Symbol.dispose>;
279
+ to: TransportClientId;
280
+ from: TransportClientId;
281
+ streamId: string;
282
+ session: Session<Connection>;
283
+ metadata: ParsedMetadata;
284
+ };
285
+
286
+ type ConstructHandshake<T extends TSchema> = () => Static<T> | Promise<Static<T>>;
287
+ type ValidateHandshake<T extends TSchema> = (metadata: Static<T>, previousParsedMetadata?: ParsedMetadata) => false | ParsedMetadata | Promise<false | ParsedMetadata>;
288
+ interface ClientHandshakeOptions<MetadataSchema extends TSchema = TSchema> {
289
+ /**
290
+ * Schema for the metadata that the client sends to the server
291
+ * during the handshake.
292
+ */
293
+ schema: MetadataSchema;
294
+ /**
295
+ * Gets the {@link HandshakeRequestMetadata} to send to the server.
296
+ */
297
+ construct: ConstructHandshake<MetadataSchema>;
298
+ }
299
+ interface ServerHandshakeOptions<MetadataSchema extends TSchema = TSchema> {
300
+ /**
301
+ * Schema for the metadata that the server receives from the client
302
+ * during the handshake.
303
+ */
304
+ schema: MetadataSchema;
305
+ /**
306
+ * Parses the {@link HandshakeRequestMetadata} sent by the client, transforming
307
+ * it into {@link ParsedHandshakeMetadata}.
308
+ *
309
+ * May return `false` if the client should be rejected.
310
+ *
311
+ * @param metadata - The metadata sent by the client.
312
+ * @param session - The session that the client would be associated with.
313
+ * @param isReconnect - Whether the client is reconnecting to the session,
314
+ * or if this is a new session.
315
+ */
316
+ validate: ValidateHandshake<MetadataSchema>;
317
+ }
318
+
319
+ /**
320
+ * Represents the possible states of a transport.
321
+ * @property {'open'} open - The transport is open and operational (note that this doesn't mean it is actively connected)
322
+ * @property {'closed'} closed - The transport is closed and not operational, but can be reopened.
323
+ * @property {'destroyed'} destroyed - The transport is permanently destroyed and cannot be reopened.
324
+ */
325
+ type TransportStatus = 'open' | 'closed' | 'destroyed';
326
+ type TransportOptions = SessionOptions;
327
+ type ProvidedTransportOptions = Partial<TransportOptions>;
328
+ type ClientTransportOptions = TransportOptions & ConnectionRetryOptions;
329
+ type ProvidedClientTransportOptions = Partial<ClientTransportOptions>;
330
+ type ServerTransportOptions = TransportOptions;
331
+ type ProvidedServerTransportOptions = Partial<ServerTransportOptions>;
332
+ /**
333
+ * Transports manage the lifecycle (creation/deletion) of sessions and connections. Its responsibilities include:
334
+ *
335
+ * 1) Constructing a new {@link Session} and {@link Connection} on {@link TransportMessage}s from new clients.
336
+ * After constructing the {@link Connection}, {@link onConnect} is called which adds it to the connection map.
337
+ * 2) Delegating message listening of the connection to the newly created {@link Connection}.
338
+ * From this point on, the {@link Connection} is responsible for *reading* and *writing*
339
+ * messages from the connection.
340
+ * 3) When a connection is closed, the {@link Transport} calls {@link onDisconnect} which closes the
341
+ * connection via {@link Connection.close} and removes it from the {@link connections} map.
342
+
343
+ *
344
+ * ```plaintext
345
+ * ▲
346
+ * incoming │
347
+ * messages │
348
+ * ▼
349
+ * ┌─────────────┐ 1:N ┌───────────┐ 1:1* ┌────────────┐
350
+ * │ Transport │ ◄─────► │ Session │ ◄─────► │ Connection │
351
+ * └─────────────┘ └───────────┘ └────────────┘
352
+ * ▲ * (may or may not be initialized yet)
353
+ * │
354
+ * ▼
355
+ * ┌───────────┐
356
+ * │ Message │
357
+ * │ Listeners │
358
+ * └───────────┘
359
+ * ```
360
+ * @abstract
361
+ */
362
+ declare abstract class Transport<ConnType extends Connection> {
363
+ /**
364
+ * A flag indicating whether the transport has been destroyed.
365
+ * A destroyed transport will not attempt to reconnect and cannot be used again.
366
+ */
367
+ state: TransportStatus;
368
+ /**
369
+ * The {@link Codec} used to encode and decode messages.
370
+ */
371
+ codec: Codec;
372
+ /**
373
+ * The client ID of this transport.
374
+ */
375
+ clientId: TransportClientId;
376
+ /**
377
+ * The map of {@link Session}s managed by this transport.
378
+ */
379
+ sessions: Map<TransportClientId, Session<ConnType>>;
380
+ /**
381
+ * The map of {@link Connection}s managed by this transport.
382
+ */
383
+ get connections(): Map<string, ConnType>;
384
+ /**
385
+ * The event dispatcher for handling events of type EventTypes.
386
+ */
387
+ eventDispatcher: EventDispatcher<EventTypes>;
388
+ /**
389
+ * The options for this transport.
390
+ */
391
+ protected options: TransportOptions;
392
+ /**
393
+ * Creates a new Transport instance.
394
+ * This should also set up {@link onConnect}, and {@link onDisconnect} listeners.
395
+ * @param codec The codec used to encode and decode messages.
396
+ * @param clientId The client ID of this transport.
397
+ */
398
+ constructor(clientId: TransportClientId, providedOptions?: ProvidedTransportOptions);
399
+ /**
400
+ * This is called immediately after a new connection is established and we
401
+ * may or may not know the identity of the connected client.
402
+ * It should attach all the necessary listeners to the connection for lifecycle
403
+ * events (i.e. data, close, error)
404
+ *
405
+ * This method is implemented by {@link ClientTransport} and {@link ServerTransport}.
406
+ */
407
+ protected abstract handleConnection(conn: ConnType, to: TransportClientId): void;
408
+ /**
409
+ * Called when a new connection is established
410
+ * and we know the identity of the connected client.
411
+ * @param conn The connection object.
412
+ */
413
+ protected onConnect(conn: ConnType, connectedTo: TransportClientId, session: Session<ConnType>, isReconnect: boolean): void;
414
+ protected createSession(to: TransportClientId, conn?: ConnType, propagationCtx?: PropagationContext): Session<ConnType>;
415
+ protected getOrCreateSession(to: TransportClientId, conn?: ConnType, sessionId?: string, propagationCtx?: PropagationContext): {
416
+ session: Session<ConnType>;
417
+ isReconnect: boolean;
418
+ };
419
+ protected deleteSession(session: Session<ConnType>): void;
420
+ /**
421
+ * The downstream implementation needs to call this when a connection is closed.
422
+ * @param conn The connection object.
423
+ * @param connectedTo The peer we are connected to.
424
+ */
425
+ protected onDisconnect(conn: ConnType, session: Session<ConnType>): void;
426
+ /**
427
+ * Parses a message from a Uint8Array into a {@link OpaqueTransportMessage}.
428
+ * @param msg The message to parse.
429
+ * @returns The parsed message, or null if the message is malformed or invalid.
430
+ */
431
+ protected parseMsg(msg: Uint8Array): OpaqueTransportMessage | null;
432
+ /**
433
+ * Called when a message is received by this transport.
434
+ * You generally shouldn't need to override this in downstream transport implementations.
435
+ * @param msg The received message.
436
+ */
437
+ protected handleMsg(msg: OpaqueTransportMessage): void;
438
+ /**
439
+ * Adds a listener to this transport.
440
+ * @param the type of event to listen for
441
+ * @param handler The message handler to add.
442
+ */
443
+ addEventListener<K extends EventTypes, T extends EventHandler<K>>(type: K, handler: T): void;
444
+ /**
445
+ * Removes a listener from this transport.
446
+ * @param the type of event to un-listen on
447
+ * @param handler The message handler to remove.
448
+ */
449
+ removeEventListener<K extends EventTypes, T extends EventHandler<K>>(type: K, handler: T): void;
450
+ /**
451
+ * Sends a message over this transport, delegating to the appropriate connection to actually
452
+ * send the message.
453
+ * @param msg The message to send.
454
+ * @returns The ID of the sent message or undefined if it wasn't sent
455
+ */
456
+ send(to: TransportClientId, msg: PartialTransportMessage): string | undefined;
457
+ sendCloseStream(to: TransportClientId, streamId: string): string | undefined;
458
+ protected protocolError(type: ProtocolErrorType, message: string): void;
459
+ /**
460
+ * Default close implementation for transports. You should override this in the downstream
461
+ * implementation if you need to do any additional cleanup and call super.close() at the end.
462
+ * Closes the transport. Any messages sent while the transport is closed will be silently discarded.
463
+ */
464
+ close(): void;
465
+ /**
466
+ * Default destroy implementation for transports. You should override this in the downstream
467
+ * implementation if you need to do any additional cleanup and call super.destroy() at the end.
468
+ * Destroys the transport. Any messages sent while the transport is destroyed will throw an error.
469
+ */
470
+ destroy(): void;
471
+ }
472
+ declare abstract class ClientTransport<ConnType extends Connection> extends Transport<ConnType> {
473
+ /**
474
+ * The options for this transport.
475
+ */
476
+ protected options: ClientTransportOptions;
477
+ /**
478
+ * The map of reconnect promises for each client ID.
479
+ */
480
+ inflightConnectionPromises: Map<TransportClientId, Promise<ConnType>>;
481
+ retryBudget: LeakyBucketRateLimit;
482
+ /**
483
+ * A flag indicating whether the transport should automatically reconnect
484
+ * when a connection is dropped.
485
+ * Realistically, this should always be true for clients unless you are writing
486
+ * tests or a special case where you don't want to reconnect.
487
+ */
488
+ reconnectOnConnectionDrop: boolean;
489
+ /**
490
+ * Optional handshake options for this client.
491
+ */
492
+ handshakeExtensions?: ClientHandshakeOptions;
493
+ constructor(clientId: TransportClientId, providedOptions?: ProvidedClientTransportOptions);
494
+ extendHandshake(options: ClientHandshakeOptions): void;
495
+ protected handleConnection(conn: ConnType, to: TransportClientId): void;
496
+ receiveHandshakeResponseMessage(data: Uint8Array, conn: ConnType): Session<ConnType> | false;
497
+ /**
498
+ * Abstract method that creates a new {@link Connection} object.
499
+ * This should call {@link handleConnection} when the connection is created.
500
+ * The downstream client implementation needs to implement this.
501
+ *
502
+ * @param to The client ID of the node to connect to.
503
+ * @returns The new connection object.
504
+ */
505
+ protected abstract createNewOutgoingConnection(to: TransportClientId): Promise<ConnType>;
506
+ /**
507
+ * Manually attempts to connect to a client.
508
+ * @param to The client ID of the node to connect to.
509
+ */
510
+ connect(to: TransportClientId): Promise<void>;
511
+ protected deleteSession(session: Session<ConnType>): void;
512
+ protected sendHandshake(to: TransportClientId, conn: ConnType): Promise<boolean>;
513
+ close(): void;
514
+ }
515
+ declare abstract class ServerTransport<ConnType extends Connection> extends Transport<ConnType> {
516
+ /**
517
+ * The options for this transport.
518
+ */
519
+ protected options: ServerTransportOptions;
520
+ /**
521
+ * Optional handshake options for the server.
522
+ */
523
+ handshakeExtensions?: ServerHandshakeOptions;
524
+ /**
525
+ * A map of session handshake data for each session.
526
+ */
527
+ sessionHandshakeMetadata: WeakMap<Session<ConnType>, ParsedMetadata>;
528
+ constructor(clientId: TransportClientId, providedOptions?: ProvidedServerTransportOptions);
529
+ extendHandshake(options: ServerHandshakeOptions): void;
530
+ protected handleConnection(conn: ConnType): void;
531
+ private validateHandshakeMetadata;
532
+ receiveHandshakeRequestMessage(data: Uint8Array, conn: ConnType): Promise<Session<ConnType> | false>;
533
+ }
534
+
535
+ export { Connection as C, EventMap as E, ProvidedClientTransportOptions as P, SessionOptions as S, Transport as T, ServiceContext as a, Session as b, ClientTransport as c, ServerTransport as d, ProvidedServerTransportOptions as e, ServerHandshakeOptions as f, ParsedMetadata as g, ServiceContextWithState as h, ServiceContextWithTransportInfo as i, ClientHandshakeOptions as j, ProvidedTransportOptions as k, TransportStatus as l, EventTypes as m, EventHandler as n, ProtocolError as o, ProtocolErrorType as p };
@@ -355,7 +355,7 @@ var log = void 0;
355
355
  var import_api = require("@opentelemetry/api");
356
356
 
357
357
  // package.json
358
- var version = "0.23.3";
358
+ var version = "0.23.4";
359
359
 
360
360
  // tracing/index.ts
361
361
  function createSessionTelemetryInfo(session, propagationCtx) {