@replit/river 0.209.2 → 0.209.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 (46) hide show
  1. package/dist/{chunk-L3KNTJU3.js → chunk-MIO5URHT.js} +25 -21
  2. package/dist/chunk-MIO5URHT.js.map +1 -0
  3. package/dist/{chunk-OTL2R22H.js → chunk-SWRTP3YW.js} +12 -5
  4. package/dist/chunk-SWRTP3YW.js.map +1 -0
  5. package/dist/{chunk-DVAIJ57I.js → chunk-VQAPXMIR.js} +24 -15
  6. package/dist/chunk-VQAPXMIR.js.map +1 -0
  7. package/dist/{client-BX3IXUA2.d.cts → client-DXJRow2s.d.cts} +1 -1
  8. package/dist/{client-CBak1h8Q.d.ts → client-Dw0JBBs3.d.ts} +1 -1
  9. package/dist/codec/index.js +2 -2
  10. package/dist/{connection-_eetKnva.d.cts → connection-BWkuQM31.d.cts} +1 -1
  11. package/dist/{connection-zMlysQKs.d.ts → connection-T0wHyOsa.d.ts} +1 -1
  12. package/dist/router/index.cjs +6 -2
  13. package/dist/router/index.cjs.map +1 -1
  14. package/dist/router/index.d.cts +7 -7
  15. package/dist/router/index.d.ts +7 -7
  16. package/dist/router/index.js +1 -1
  17. package/dist/{server-BV7GXuhz.d.cts → server-BDSYa-CO.d.cts} +1 -1
  18. package/dist/{server-B_H1zn-R.d.ts → server-DFOzjvLh.d.ts} +1 -1
  19. package/dist/{services-DtsSIaec.d.ts → services-DEubFUIR.d.ts} +12 -20
  20. package/dist/{services-BIMmk-v4.d.cts → services-GJyw0jKV.d.cts} +12 -20
  21. package/dist/testUtil/index.cjs +15 -6
  22. package/dist/testUtil/index.cjs.map +1 -1
  23. package/dist/testUtil/index.d.cts +4 -4
  24. package/dist/testUtil/index.d.ts +4 -4
  25. package/dist/testUtil/index.js +3 -3
  26. package/dist/transport/impls/ws/client.cjs +25 -9
  27. package/dist/transport/impls/ws/client.cjs.map +1 -1
  28. package/dist/transport/impls/ws/client.d.cts +3 -3
  29. package/dist/transport/impls/ws/client.d.ts +3 -3
  30. package/dist/transport/impls/ws/client.js +3 -3
  31. package/dist/transport/impls/ws/server.cjs +13 -5
  32. package/dist/transport/impls/ws/server.cjs.map +1 -1
  33. package/dist/transport/impls/ws/server.d.cts +3 -3
  34. package/dist/transport/impls/ws/server.d.ts +3 -3
  35. package/dist/transport/impls/ws/server.js +3 -3
  36. package/dist/transport/index.cjs +15 -6
  37. package/dist/transport/index.cjs.map +1 -1
  38. package/dist/transport/index.d.cts +4 -4
  39. package/dist/transport/index.d.ts +4 -4
  40. package/dist/transport/index.js +3 -3
  41. package/dist/{handshake-B3iu79B0.d.cts → transport-CxT7y8Qk.d.cts} +107 -102
  42. package/dist/{handshake-DNinPBA3.d.ts → transport-pdbkDzmJ.d.ts} +107 -102
  43. package/package.json +1 -1
  44. package/dist/chunk-DVAIJ57I.js.map +0 -1
  45. package/dist/chunk-L3KNTJU3.js.map +0 -1
  46. package/dist/chunk-OTL2R22H.js.map +0 -1
@@ -1,8 +1,8 @@
1
- export { b as ClientTransportOptions, C as Connection, j as EventHandler, E as EventMap, i as EventTypes, k as ProtocolError, l as ProtocolErrorType, c as ServerTransportOptions, S as Session, h as SessionConnected, f as SessionConnecting, g as SessionHandshaking, e as SessionNoConnection, d as SessionState, T as Transport, P as TransportOptions, a as TransportStatus } from '../handshake-B3iu79B0.cjs';
2
- export { C as ClientTransport } from '../client-BX3IXUA2.cjs';
3
- export { S as ServerTransport, a as SessionWaitingForHandshake } from '../server-BV7GXuhz.cjs';
1
+ export { b as ClientTransportOptions, C as Connection, j as EventHandler, E as EventMap, i as EventTypes, k as ProtocolError, l as ProtocolErrorType, c as ServerTransportOptions, S as Session, h as SessionConnected, f as SessionConnecting, g as SessionHandshaking, e as SessionNoConnection, d as SessionState, T as Transport, P as TransportOptions, a as TransportStatus } from '../transport-CxT7y8Qk.cjs';
2
+ export { C as ClientTransport } from '../client-DXJRow2s.cjs';
3
+ export { S as ServerTransport, a as SessionWaitingForHandshake } from '../server-BDSYa-CO.cjs';
4
4
  export { b as OpaqueTransportMessage, O as OpaqueTransportMessageSchema, c as TransportClientId, a as TransportMessage, T as TransportMessageSchema, d as isStreamClose, i as isStreamOpen } from '../message-Dlsh5WDF.cjs';
5
- import '../index-D9R6UTMl.cjs';
6
5
  import '@sinclair/typebox';
6
+ import '../index-D9R6UTMl.cjs';
7
7
  import '../adapter-DjiEwOYi.cjs';
8
8
  import '@opentelemetry/api';
@@ -1,8 +1,8 @@
1
- export { b as ClientTransportOptions, C as Connection, j as EventHandler, E as EventMap, i as EventTypes, k as ProtocolError, l as ProtocolErrorType, c as ServerTransportOptions, S as Session, h as SessionConnected, f as SessionConnecting, g as SessionHandshaking, e as SessionNoConnection, d as SessionState, T as Transport, P as TransportOptions, a as TransportStatus } from '../handshake-DNinPBA3.js';
2
- export { C as ClientTransport } from '../client-CBak1h8Q.js';
3
- export { S as ServerTransport, a as SessionWaitingForHandshake } from '../server-B_H1zn-R.js';
1
+ export { b as ClientTransportOptions, C as Connection, j as EventHandler, E as EventMap, i as EventTypes, k as ProtocolError, l as ProtocolErrorType, c as ServerTransportOptions, S as Session, h as SessionConnected, f as SessionConnecting, g as SessionHandshaking, e as SessionNoConnection, d as SessionState, T as Transport, P as TransportOptions, a as TransportStatus } from '../transport-pdbkDzmJ.js';
2
+ export { C as ClientTransport } from '../client-Dw0JBBs3.js';
3
+ export { S as ServerTransport, a as SessionWaitingForHandshake } from '../server-DFOzjvLh.js';
4
4
  export { b as OpaqueTransportMessage, O as OpaqueTransportMessageSchema, c as TransportClientId, a as TransportMessage, T as TransportMessageSchema, d as isStreamClose, i as isStreamOpen } from '../message-Dlsh5WDF.js';
5
- import '../index-CSM8soK7.js';
6
5
  import '@sinclair/typebox';
6
+ import '../index-CSM8soK7.js';
7
7
  import '../adapter-Cp7_gIVA.js';
8
8
  import '@opentelemetry/api';
@@ -5,12 +5,12 @@ import {
5
5
  ServerTransport,
6
6
  SessionState,
7
7
  Transport
8
- } from "../chunk-DVAIJ57I.js";
8
+ } from "../chunk-VQAPXMIR.js";
9
+ import "../chunk-CC7RN7GI.js";
9
10
  import {
10
11
  OpaqueTransportMessageSchema,
11
12
  TransportMessageSchema
12
- } from "../chunk-L3KNTJU3.js";
13
- import "../chunk-CC7RN7GI.js";
13
+ } from "../chunk-MIO5URHT.js";
14
14
  export {
15
15
  ClientTransport,
16
16
  Connection,
@@ -1,6 +1,6 @@
1
- import { f as TelemetryInfo, c as TransportClientId, P as ProtocolVersion, b as OpaqueTransportMessage, e as PartialTransportMessage, a as TransportMessage, H as HandshakeErrorResponseCodes, g as HandshakeErrorCustomHandlerFatalResponseCodes } from './message-Dlsh5WDF.cjs';
1
+ import { TSchema, Static } from '@sinclair/typebox';
2
+ import { f as TelemetryInfo, c as TransportClientId, P as ProtocolVersion, b as OpaqueTransportMessage, e as PartialTransportMessage, a as TransportMessage, g as HandshakeErrorCustomHandlerFatalResponseCodes, H as HandshakeErrorResponseCodes } from './message-Dlsh5WDF.cjs';
2
3
  import { M as MessageMetadata, L as Logger, T as Tags, a as LogFn, b as LoggingLevel } from './index-D9R6UTMl.cjs';
3
- import { Static, TSchema } from '@sinclair/typebox';
4
4
  import { C as Codec, a as CodecMessageAdapter, S as SendResult, b as SendBufferResult } from './adapter-DjiEwOYi.cjs';
5
5
  import { Tracer } from '@opentelemetry/api';
6
6
 
@@ -187,6 +187,105 @@ declare abstract class IdentifiedSessionWithGracePeriod extends IdentifiedSessio
187
187
  _handleClose(): void;
188
188
  }
189
189
 
190
+ type ConstructHandshake<T extends TSchema> = () => Static<T> | Promise<Static<T>>;
191
+ type ValidateHandshake<T extends TSchema, ParsedMetadata> = (metadata: Static<T>, previousParsedMetadata?: ParsedMetadata) => Static<typeof HandshakeErrorCustomHandlerFatalResponseCodes> | ParsedMetadata | Promise<Static<typeof HandshakeErrorCustomHandlerFatalResponseCodes> | ParsedMetadata>;
192
+ interface ClientHandshakeOptions<MetadataSchema extends TSchema = TSchema> {
193
+ /**
194
+ * Schema for the metadata that the client sends to the server
195
+ * during the handshake.
196
+ */
197
+ schema: MetadataSchema;
198
+ /**
199
+ * Gets the {@link HandshakeRequestMetadata} to send to the server.
200
+ */
201
+ construct: ConstructHandshake<MetadataSchema>;
202
+ }
203
+ interface ServerHandshakeOptions<MetadataSchema extends TSchema = TSchema, ParsedMetadata extends object = object> {
204
+ /**
205
+ * Schema for the metadata that the server receives from the client
206
+ * during the handshake.
207
+ */
208
+ schema: MetadataSchema;
209
+ /**
210
+ * Parses the {@link HandshakeRequestMetadata} sent by the client, transforming
211
+ * it into {@link ParsedHandshakeMetadata}.
212
+ *
213
+ * May return `false` if the client should be rejected.
214
+ *
215
+ * @param metadata - The metadata sent by the client.
216
+ * @param session - The session that the client would be associated with.
217
+ * @param isReconnect - Whether the client is reconnecting to the session,
218
+ * or if this is a new session.
219
+ */
220
+ validate: ValidateHandshake<MetadataSchema, ParsedMetadata>;
221
+ }
222
+ declare function createClientHandshakeOptions<MetadataSchema extends TSchema = TSchema>(schema: MetadataSchema, construct: ConstructHandshake<MetadataSchema>): ClientHandshakeOptions;
223
+ declare function createServerHandshakeOptions<MetadataSchema extends TSchema = TSchema, ParsedMetadata extends object = object>(schema: MetadataSchema, validate: ValidateHandshake<MetadataSchema, ParsedMetadata>): ServerHandshakeOptions<MetadataSchema, ParsedMetadata>;
224
+
225
+ /**
226
+ * Options to control the backoff and retry behavior of the client transport's connection behaviour.
227
+ *
228
+ * River implements exponential backoff with jitter to prevent flooding the server
229
+ * when there's an issue with connection establishment.
230
+ *
231
+ * The backoff is calculated via the following:
232
+ * backOff = min(jitter + {@link baseIntervalMs} * 2 ^ budget_consumed, {@link maxBackoffMs})
233
+ *
234
+ * We use a leaky bucket rate limit with a budget of {@link attemptBudgetCapacity} reconnection attempts.
235
+ * Budget only starts to restore after a successful handshake at a rate of one budget per {@link budgetRestoreIntervalMs}.
236
+ */
237
+ interface ConnectionRetryOptions {
238
+ /**
239
+ * The base interval to wait before retrying a connection.
240
+ */
241
+ baseIntervalMs: number;
242
+ /**
243
+ * The maximum random jitter to add to the total backoff time.
244
+ */
245
+ maxJitterMs: number;
246
+ /**
247
+ * The maximum amount of time to wait before retrying a connection.
248
+ * This does not include the jitter.
249
+ */
250
+ maxBackoffMs: number;
251
+ /**
252
+ * The max number of times to attempt a connection before a successful handshake.
253
+ * This persists across connections but starts restoring budget after a successful handshake.
254
+ * The restoration interval depends on {@link budgetRestoreIntervalMs}
255
+ */
256
+ attemptBudgetCapacity: number;
257
+ /**
258
+ * After a successful connection attempt, how long to wait before we restore a single budget.
259
+ */
260
+ budgetRestoreIntervalMs: number;
261
+ /**
262
+ * A function to determine whether an error is fatal and should not be retried.
263
+ * If this function returns true, the client transport will not attempt to reconnect.
264
+ */
265
+ isFatalConnectionError: (err: Error) => boolean;
266
+ }
267
+ declare class LeakyBucketRateLimit {
268
+ private budgetConsumed;
269
+ private intervalHandle?;
270
+ private readonly options;
271
+ constructor(options: ConnectionRetryOptions);
272
+ getBackoffMs(): number;
273
+ get totalBudgetRestoreTime(): number;
274
+ consumeBudget(): void;
275
+ getBudgetConsumed(): number;
276
+ hasBudget(): boolean;
277
+ startRestoringBudget(): void;
278
+ private stopLeak;
279
+ close(): void;
280
+ }
281
+
282
+ type TransportOptions = SessionOptions;
283
+ type ProvidedTransportOptions = Partial<TransportOptions>;
284
+ type ClientTransportOptions = TransportOptions & ConnectionRetryOptions;
285
+ type ProvidedClientTransportOptions = Partial<ClientTransportOptions>;
286
+ type ServerTransportOptions = TransportOptions;
287
+ type ProvidedServerTransportOptions = Partial<ServerTransportOptions>;
288
+
190
289
  interface SessionConnectingListeners extends IdentifiedSessionWithGracePeriodListeners {
191
290
  onConnectionEstablished: (conn: Connection) => void;
192
291
  onConnectionFailed: (err: unknown) => void;
@@ -207,12 +306,6 @@ declare class SessionConnecting<ConnType extends Connection> extends IdentifiedS
207
306
  _handleClose(): void;
208
307
  }
209
308
 
210
- declare class SessionNoConnection extends IdentifiedSessionWithGracePeriod {
211
- readonly state: SessionState.NoConnection;
212
- _handleClose(): void;
213
- _handleStateExit(): void;
214
- }
215
-
216
309
  interface SessionHandshakingListeners extends IdentifiedSessionWithGracePeriodListeners {
217
310
  onConnectionErrored: (err: unknown) => void;
218
311
  onConnectionClosed: () => void;
@@ -303,6 +396,12 @@ declare class SessionConnected<ConnType extends Connection> extends IdentifiedSe
303
396
  _handleClose(): void;
304
397
  }
305
398
 
399
+ declare class SessionNoConnection extends IdentifiedSessionWithGracePeriod {
400
+ readonly state: SessionState.NoConnection;
401
+ _handleClose(): void;
402
+ _handleStateExit(): void;
403
+ }
404
+
306
405
  interface SessionBackingOffListeners extends IdentifiedSessionWithGracePeriodListeners {
307
406
  onBackoffFinished: () => void;
308
407
  }
@@ -379,65 +478,6 @@ declare class EventDispatcher<T extends EventTypes> {
379
478
  dispatchEvent<K extends T>(eventType: K, event: EventMap[K]): void;
380
479
  }
381
480
 
382
- /**
383
- * Options to control the backoff and retry behavior of the client transport's connection behaviour.
384
- *
385
- * River implements exponential backoff with jitter to prevent flooding the server
386
- * when there's an issue with connection establishment.
387
- *
388
- * The backoff is calculated via the following:
389
- * backOff = min(jitter + {@link baseIntervalMs} * 2 ^ budget_consumed, {@link maxBackoffMs})
390
- *
391
- * We use a leaky bucket rate limit with a budget of {@link attemptBudgetCapacity} reconnection attempts.
392
- * Budget only starts to restore after a successful handshake at a rate of one budget per {@link budgetRestoreIntervalMs}.
393
- */
394
- interface ConnectionRetryOptions {
395
- /**
396
- * The base interval to wait before retrying a connection.
397
- */
398
- baseIntervalMs: number;
399
- /**
400
- * The maximum random jitter to add to the total backoff time.
401
- */
402
- maxJitterMs: number;
403
- /**
404
- * The maximum amount of time to wait before retrying a connection.
405
- * This does not include the jitter.
406
- */
407
- maxBackoffMs: number;
408
- /**
409
- * The max number of times to attempt a connection before a successful handshake.
410
- * This persists across connections but starts restoring budget after a successful handshake.
411
- * The restoration interval depends on {@link budgetRestoreIntervalMs}
412
- */
413
- attemptBudgetCapacity: number;
414
- /**
415
- * After a successful connection attempt, how long to wait before we restore a single budget.
416
- */
417
- budgetRestoreIntervalMs: number;
418
- }
419
- declare class LeakyBucketRateLimit {
420
- private budgetConsumed;
421
- private intervalHandle?;
422
- private readonly options;
423
- constructor(options: ConnectionRetryOptions);
424
- getBackoffMs(): number;
425
- get totalBudgetRestoreTime(): number;
426
- consumeBudget(): void;
427
- getBudgetConsumed(): number;
428
- hasBudget(): boolean;
429
- startRestoringBudget(): void;
430
- private stopLeak;
431
- close(): void;
432
- }
433
-
434
- type TransportOptions = SessionOptions;
435
- type ProvidedTransportOptions = Partial<TransportOptions>;
436
- type ClientTransportOptions = TransportOptions & ConnectionRetryOptions;
437
- type ProvidedClientTransportOptions = Partial<ClientTransportOptions>;
438
- type ServerTransportOptions = TransportOptions;
439
- type ProvidedServerTransportOptions = Partial<ServerTransportOptions>;
440
-
441
481
  /**
442
482
  * Represents the possible states of a transport.
443
483
  * @property {'open'} open - The transport is open and operational (note that this doesn't mean it is actively connected)
@@ -539,39 +579,4 @@ declare abstract class Transport<ConnType extends Connection> {
539
579
  getSessionBoundSendFn(to: TransportClientId, sessionId: SessionId): SessionBoundSendFn;
540
580
  }
541
581
 
542
- type ConstructHandshake<T extends TSchema> = () => Static<T> | Promise<Static<T>>;
543
- type ValidateHandshake<T extends TSchema, ParsedMetadata> = (metadata: Static<T>, previousParsedMetadata?: ParsedMetadata) => Static<typeof HandshakeErrorCustomHandlerFatalResponseCodes> | ParsedMetadata | Promise<Static<typeof HandshakeErrorCustomHandlerFatalResponseCodes> | ParsedMetadata>;
544
- interface ClientHandshakeOptions<MetadataSchema extends TSchema = TSchema> {
545
- /**
546
- * Schema for the metadata that the client sends to the server
547
- * during the handshake.
548
- */
549
- schema: MetadataSchema;
550
- /**
551
- * Gets the {@link HandshakeRequestMetadata} to send to the server.
552
- */
553
- construct: ConstructHandshake<MetadataSchema>;
554
- }
555
- interface ServerHandshakeOptions<MetadataSchema extends TSchema = TSchema, ParsedMetadata extends object = object> {
556
- /**
557
- * Schema for the metadata that the server receives from the client
558
- * during the handshake.
559
- */
560
- schema: MetadataSchema;
561
- /**
562
- * Parses the {@link HandshakeRequestMetadata} sent by the client, transforming
563
- * it into {@link ParsedHandshakeMetadata}.
564
- *
565
- * May return `false` if the client should be rejected.
566
- *
567
- * @param metadata - The metadata sent by the client.
568
- * @param session - The session that the client would be associated with.
569
- * @param isReconnect - Whether the client is reconnecting to the session,
570
- * or if this is a new session.
571
- */
572
- validate: ValidateHandshake<MetadataSchema, ParsedMetadata>;
573
- }
574
- declare function createClientHandshakeOptions<MetadataSchema extends TSchema = TSchema>(schema: MetadataSchema, construct: ConstructHandshake<MetadataSchema>): ClientHandshakeOptions;
575
- declare function createServerHandshakeOptions<MetadataSchema extends TSchema = TSchema, ParsedMetadata extends object = object>(schema: MetadataSchema, validate: ValidateHandshake<MetadataSchema, ParsedMetadata>): ServerHandshakeOptions<MetadataSchema, ParsedMetadata>;
576
-
577
582
  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 { f as TelemetryInfo, c as TransportClientId, P as ProtocolVersion, b as OpaqueTransportMessage, e as PartialTransportMessage, a as TransportMessage, H as HandshakeErrorResponseCodes, g as HandshakeErrorCustomHandlerFatalResponseCodes } from './message-Dlsh5WDF.js';
1
+ import { TSchema, Static } from '@sinclair/typebox';
2
+ import { f as TelemetryInfo, c as TransportClientId, P as ProtocolVersion, b as OpaqueTransportMessage, e as PartialTransportMessage, a as TransportMessage, g as HandshakeErrorCustomHandlerFatalResponseCodes, H as HandshakeErrorResponseCodes } from './message-Dlsh5WDF.js';
2
3
  import { M as MessageMetadata, L as Logger, T as Tags, a as LogFn, b as LoggingLevel } from './index-CSM8soK7.js';
3
- import { Static, TSchema } from '@sinclair/typebox';
4
4
  import { C as Codec, a as CodecMessageAdapter, S as SendResult, b as SendBufferResult } from './adapter-Cp7_gIVA.js';
5
5
  import { Tracer } from '@opentelemetry/api';
6
6
 
@@ -187,6 +187,105 @@ declare abstract class IdentifiedSessionWithGracePeriod extends IdentifiedSessio
187
187
  _handleClose(): void;
188
188
  }
189
189
 
190
+ type ConstructHandshake<T extends TSchema> = () => Static<T> | Promise<Static<T>>;
191
+ type ValidateHandshake<T extends TSchema, ParsedMetadata> = (metadata: Static<T>, previousParsedMetadata?: ParsedMetadata) => Static<typeof HandshakeErrorCustomHandlerFatalResponseCodes> | ParsedMetadata | Promise<Static<typeof HandshakeErrorCustomHandlerFatalResponseCodes> | ParsedMetadata>;
192
+ interface ClientHandshakeOptions<MetadataSchema extends TSchema = TSchema> {
193
+ /**
194
+ * Schema for the metadata that the client sends to the server
195
+ * during the handshake.
196
+ */
197
+ schema: MetadataSchema;
198
+ /**
199
+ * Gets the {@link HandshakeRequestMetadata} to send to the server.
200
+ */
201
+ construct: ConstructHandshake<MetadataSchema>;
202
+ }
203
+ interface ServerHandshakeOptions<MetadataSchema extends TSchema = TSchema, ParsedMetadata extends object = object> {
204
+ /**
205
+ * Schema for the metadata that the server receives from the client
206
+ * during the handshake.
207
+ */
208
+ schema: MetadataSchema;
209
+ /**
210
+ * Parses the {@link HandshakeRequestMetadata} sent by the client, transforming
211
+ * it into {@link ParsedHandshakeMetadata}.
212
+ *
213
+ * May return `false` if the client should be rejected.
214
+ *
215
+ * @param metadata - The metadata sent by the client.
216
+ * @param session - The session that the client would be associated with.
217
+ * @param isReconnect - Whether the client is reconnecting to the session,
218
+ * or if this is a new session.
219
+ */
220
+ validate: ValidateHandshake<MetadataSchema, ParsedMetadata>;
221
+ }
222
+ declare function createClientHandshakeOptions<MetadataSchema extends TSchema = TSchema>(schema: MetadataSchema, construct: ConstructHandshake<MetadataSchema>): ClientHandshakeOptions;
223
+ declare function createServerHandshakeOptions<MetadataSchema extends TSchema = TSchema, ParsedMetadata extends object = object>(schema: MetadataSchema, validate: ValidateHandshake<MetadataSchema, ParsedMetadata>): ServerHandshakeOptions<MetadataSchema, ParsedMetadata>;
224
+
225
+ /**
226
+ * Options to control the backoff and retry behavior of the client transport's connection behaviour.
227
+ *
228
+ * River implements exponential backoff with jitter to prevent flooding the server
229
+ * when there's an issue with connection establishment.
230
+ *
231
+ * The backoff is calculated via the following:
232
+ * backOff = min(jitter + {@link baseIntervalMs} * 2 ^ budget_consumed, {@link maxBackoffMs})
233
+ *
234
+ * We use a leaky bucket rate limit with a budget of {@link attemptBudgetCapacity} reconnection attempts.
235
+ * Budget only starts to restore after a successful handshake at a rate of one budget per {@link budgetRestoreIntervalMs}.
236
+ */
237
+ interface ConnectionRetryOptions {
238
+ /**
239
+ * The base interval to wait before retrying a connection.
240
+ */
241
+ baseIntervalMs: number;
242
+ /**
243
+ * The maximum random jitter to add to the total backoff time.
244
+ */
245
+ maxJitterMs: number;
246
+ /**
247
+ * The maximum amount of time to wait before retrying a connection.
248
+ * This does not include the jitter.
249
+ */
250
+ maxBackoffMs: number;
251
+ /**
252
+ * The max number of times to attempt a connection before a successful handshake.
253
+ * This persists across connections but starts restoring budget after a successful handshake.
254
+ * The restoration interval depends on {@link budgetRestoreIntervalMs}
255
+ */
256
+ attemptBudgetCapacity: number;
257
+ /**
258
+ * After a successful connection attempt, how long to wait before we restore a single budget.
259
+ */
260
+ budgetRestoreIntervalMs: number;
261
+ /**
262
+ * A function to determine whether an error is fatal and should not be retried.
263
+ * If this function returns true, the client transport will not attempt to reconnect.
264
+ */
265
+ isFatalConnectionError: (err: Error) => boolean;
266
+ }
267
+ declare class LeakyBucketRateLimit {
268
+ private budgetConsumed;
269
+ private intervalHandle?;
270
+ private readonly options;
271
+ constructor(options: ConnectionRetryOptions);
272
+ getBackoffMs(): number;
273
+ get totalBudgetRestoreTime(): number;
274
+ consumeBudget(): void;
275
+ getBudgetConsumed(): number;
276
+ hasBudget(): boolean;
277
+ startRestoringBudget(): void;
278
+ private stopLeak;
279
+ close(): void;
280
+ }
281
+
282
+ type TransportOptions = SessionOptions;
283
+ type ProvidedTransportOptions = Partial<TransportOptions>;
284
+ type ClientTransportOptions = TransportOptions & ConnectionRetryOptions;
285
+ type ProvidedClientTransportOptions = Partial<ClientTransportOptions>;
286
+ type ServerTransportOptions = TransportOptions;
287
+ type ProvidedServerTransportOptions = Partial<ServerTransportOptions>;
288
+
190
289
  interface SessionConnectingListeners extends IdentifiedSessionWithGracePeriodListeners {
191
290
  onConnectionEstablished: (conn: Connection) => void;
192
291
  onConnectionFailed: (err: unknown) => void;
@@ -207,12 +306,6 @@ declare class SessionConnecting<ConnType extends Connection> extends IdentifiedS
207
306
  _handleClose(): void;
208
307
  }
209
308
 
210
- declare class SessionNoConnection extends IdentifiedSessionWithGracePeriod {
211
- readonly state: SessionState.NoConnection;
212
- _handleClose(): void;
213
- _handleStateExit(): void;
214
- }
215
-
216
309
  interface SessionHandshakingListeners extends IdentifiedSessionWithGracePeriodListeners {
217
310
  onConnectionErrored: (err: unknown) => void;
218
311
  onConnectionClosed: () => void;
@@ -303,6 +396,12 @@ declare class SessionConnected<ConnType extends Connection> extends IdentifiedSe
303
396
  _handleClose(): void;
304
397
  }
305
398
 
399
+ declare class SessionNoConnection extends IdentifiedSessionWithGracePeriod {
400
+ readonly state: SessionState.NoConnection;
401
+ _handleClose(): void;
402
+ _handleStateExit(): void;
403
+ }
404
+
306
405
  interface SessionBackingOffListeners extends IdentifiedSessionWithGracePeriodListeners {
307
406
  onBackoffFinished: () => void;
308
407
  }
@@ -379,65 +478,6 @@ declare class EventDispatcher<T extends EventTypes> {
379
478
  dispatchEvent<K extends T>(eventType: K, event: EventMap[K]): void;
380
479
  }
381
480
 
382
- /**
383
- * Options to control the backoff and retry behavior of the client transport's connection behaviour.
384
- *
385
- * River implements exponential backoff with jitter to prevent flooding the server
386
- * when there's an issue with connection establishment.
387
- *
388
- * The backoff is calculated via the following:
389
- * backOff = min(jitter + {@link baseIntervalMs} * 2 ^ budget_consumed, {@link maxBackoffMs})
390
- *
391
- * We use a leaky bucket rate limit with a budget of {@link attemptBudgetCapacity} reconnection attempts.
392
- * Budget only starts to restore after a successful handshake at a rate of one budget per {@link budgetRestoreIntervalMs}.
393
- */
394
- interface ConnectionRetryOptions {
395
- /**
396
- * The base interval to wait before retrying a connection.
397
- */
398
- baseIntervalMs: number;
399
- /**
400
- * The maximum random jitter to add to the total backoff time.
401
- */
402
- maxJitterMs: number;
403
- /**
404
- * The maximum amount of time to wait before retrying a connection.
405
- * This does not include the jitter.
406
- */
407
- maxBackoffMs: number;
408
- /**
409
- * The max number of times to attempt a connection before a successful handshake.
410
- * This persists across connections but starts restoring budget after a successful handshake.
411
- * The restoration interval depends on {@link budgetRestoreIntervalMs}
412
- */
413
- attemptBudgetCapacity: number;
414
- /**
415
- * After a successful connection attempt, how long to wait before we restore a single budget.
416
- */
417
- budgetRestoreIntervalMs: number;
418
- }
419
- declare class LeakyBucketRateLimit {
420
- private budgetConsumed;
421
- private intervalHandle?;
422
- private readonly options;
423
- constructor(options: ConnectionRetryOptions);
424
- getBackoffMs(): number;
425
- get totalBudgetRestoreTime(): number;
426
- consumeBudget(): void;
427
- getBudgetConsumed(): number;
428
- hasBudget(): boolean;
429
- startRestoringBudget(): void;
430
- private stopLeak;
431
- close(): void;
432
- }
433
-
434
- type TransportOptions = SessionOptions;
435
- type ProvidedTransportOptions = Partial<TransportOptions>;
436
- type ClientTransportOptions = TransportOptions & ConnectionRetryOptions;
437
- type ProvidedClientTransportOptions = Partial<ClientTransportOptions>;
438
- type ServerTransportOptions = TransportOptions;
439
- type ProvidedServerTransportOptions = Partial<ServerTransportOptions>;
440
-
441
481
  /**
442
482
  * Represents the possible states of a transport.
443
483
  * @property {'open'} open - The transport is open and operational (note that this doesn't mean it is actively connected)
@@ -539,39 +579,4 @@ declare abstract class Transport<ConnType extends Connection> {
539
579
  getSessionBoundSendFn(to: TransportClientId, sessionId: SessionId): SessionBoundSendFn;
540
580
  }
541
581
 
542
- type ConstructHandshake<T extends TSchema> = () => Static<T> | Promise<Static<T>>;
543
- type ValidateHandshake<T extends TSchema, ParsedMetadata> = (metadata: Static<T>, previousParsedMetadata?: ParsedMetadata) => Static<typeof HandshakeErrorCustomHandlerFatalResponseCodes> | ParsedMetadata | Promise<Static<typeof HandshakeErrorCustomHandlerFatalResponseCodes> | ParsedMetadata>;
544
- interface ClientHandshakeOptions<MetadataSchema extends TSchema = TSchema> {
545
- /**
546
- * Schema for the metadata that the client sends to the server
547
- * during the handshake.
548
- */
549
- schema: MetadataSchema;
550
- /**
551
- * Gets the {@link HandshakeRequestMetadata} to send to the server.
552
- */
553
- construct: ConstructHandshake<MetadataSchema>;
554
- }
555
- interface ServerHandshakeOptions<MetadataSchema extends TSchema = TSchema, ParsedMetadata extends object = object> {
556
- /**
557
- * Schema for the metadata that the server receives from the client
558
- * during the handshake.
559
- */
560
- schema: MetadataSchema;
561
- /**
562
- * Parses the {@link HandshakeRequestMetadata} sent by the client, transforming
563
- * it into {@link ParsedHandshakeMetadata}.
564
- *
565
- * May return `false` if the client should be rejected.
566
- *
567
- * @param metadata - The metadata sent by the client.
568
- * @param session - The session that the client would be associated with.
569
- * @param isReconnect - Whether the client is reconnecting to the session,
570
- * or if this is a new session.
571
- */
572
- validate: ValidateHandshake<MetadataSchema, ParsedMetadata>;
573
- }
574
- declare function createClientHandshakeOptions<MetadataSchema extends TSchema = TSchema>(schema: MetadataSchema, construct: ConstructHandshake<MetadataSchema>): ClientHandshakeOptions;
575
- declare function createServerHandshakeOptions<MetadataSchema extends TSchema = TSchema, ParsedMetadata extends object = object>(schema: MetadataSchema, validate: ValidateHandshake<MetadataSchema, ParsedMetadata>): ServerHandshakeOptions<MetadataSchema, ParsedMetadata>;
576
-
577
582
  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 };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@replit/river",
3
3
  "description": "It's like tRPC but... with JSON Schema Support, duplex streaming and support for service multiplexing. Transport agnostic!",
4
- "version": "0.209.2",
4
+ "version": "0.209.4",
5
5
  "type": "module",
6
6
  "exports": {
7
7
  ".": {