@replit/river 0.209.2 → 0.209.3

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 (44) hide show
  1. package/dist/{chunk-L3KNTJU3.js → chunk-EHTVQM2C.js} +25 -21
  2. package/dist/chunk-EHTVQM2C.js.map +1 -0
  3. package/dist/{chunk-DVAIJ57I.js → chunk-I24PIZXW.js} +10 -10
  4. package/dist/{chunk-OTL2R22H.js → chunk-JRBDMLR3.js} +2 -2
  5. package/dist/{client-CBak1h8Q.d.ts → client-BzJwq-hg.d.ts} +1 -1
  6. package/dist/{client-BX3IXUA2.d.cts → client-aETS93z1.d.cts} +1 -1
  7. package/dist/codec/index.js +2 -2
  8. package/dist/{connection-zMlysQKs.d.ts → connection-b1wd5XrC.d.ts} +1 -1
  9. package/dist/{connection-_eetKnva.d.cts → connection-hUWlS-hg.d.cts} +1 -1
  10. package/dist/router/index.cjs +6 -2
  11. package/dist/router/index.cjs.map +1 -1
  12. package/dist/router/index.d.cts +7 -7
  13. package/dist/router/index.d.ts +7 -7
  14. package/dist/router/index.js +1 -1
  15. package/dist/{server-BV7GXuhz.d.cts → server-BBgDVOzk.d.cts} +1 -1
  16. package/dist/{server-B_H1zn-R.d.ts → server-DZ0Yzmpf.d.ts} +1 -1
  17. package/dist/{services-BIMmk-v4.d.cts → services-C53K219K.d.cts} +10 -18
  18. package/dist/{services-DtsSIaec.d.ts → services-DYik59tk.d.ts} +10 -18
  19. package/dist/testUtil/index.cjs +1 -1
  20. package/dist/testUtil/index.cjs.map +1 -1
  21. package/dist/testUtil/index.d.cts +4 -4
  22. package/dist/testUtil/index.d.ts +4 -4
  23. package/dist/testUtil/index.js +3 -3
  24. package/dist/transport/impls/ws/client.cjs +1 -1
  25. package/dist/transport/impls/ws/client.cjs.map +1 -1
  26. package/dist/transport/impls/ws/client.d.cts +3 -3
  27. package/dist/transport/impls/ws/client.d.ts +3 -3
  28. package/dist/transport/impls/ws/client.js +3 -3
  29. package/dist/transport/impls/ws/server.cjs +1 -1
  30. package/dist/transport/impls/ws/server.cjs.map +1 -1
  31. package/dist/transport/impls/ws/server.d.cts +3 -3
  32. package/dist/transport/impls/ws/server.d.ts +3 -3
  33. package/dist/transport/impls/ws/server.js +3 -3
  34. package/dist/transport/index.cjs +1 -1
  35. package/dist/transport/index.cjs.map +1 -1
  36. package/dist/transport/index.d.cts +4 -4
  37. package/dist/transport/index.d.ts +4 -4
  38. package/dist/transport/index.js +3 -3
  39. package/dist/{handshake-B3iu79B0.d.cts → transport-CxjUaGhi.d.cts} +102 -102
  40. package/dist/{handshake-DNinPBA3.d.ts → transport-DwEB67zY.d.ts} +102 -102
  41. package/package.json +1 -1
  42. package/dist/chunk-L3KNTJU3.js.map +0 -1
  43. /package/dist/{chunk-DVAIJ57I.js.map → chunk-I24PIZXW.js.map} +0 -0
  44. /package/dist/{chunk-OTL2R22H.js.map → chunk-JRBDMLR3.js.map} +0 -0
@@ -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-CxjUaGhi.cjs';
2
+ export { C as ClientTransport } from '../client-aETS93z1.cjs';
3
+ export { S as ServerTransport, a as SessionWaitingForHandshake } from '../server-BBgDVOzk.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-DwEB67zY.js';
2
+ export { C as ClientTransport } from '../client-BzJwq-hg.js';
3
+ export { S as ServerTransport, a as SessionWaitingForHandshake } from '../server-DZ0Yzmpf.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-I24PIZXW.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-EHTVQM2C.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,100 @@ 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
+ declare class LeakyBucketRateLimit {
263
+ private budgetConsumed;
264
+ private intervalHandle?;
265
+ private readonly options;
266
+ constructor(options: ConnectionRetryOptions);
267
+ getBackoffMs(): number;
268
+ get totalBudgetRestoreTime(): number;
269
+ consumeBudget(): void;
270
+ getBudgetConsumed(): number;
271
+ hasBudget(): boolean;
272
+ startRestoringBudget(): void;
273
+ private stopLeak;
274
+ close(): void;
275
+ }
276
+
277
+ type TransportOptions = SessionOptions;
278
+ type ProvidedTransportOptions = Partial<TransportOptions>;
279
+ type ClientTransportOptions = TransportOptions & ConnectionRetryOptions;
280
+ type ProvidedClientTransportOptions = Partial<ClientTransportOptions>;
281
+ type ServerTransportOptions = TransportOptions;
282
+ type ProvidedServerTransportOptions = Partial<ServerTransportOptions>;
283
+
190
284
  interface SessionConnectingListeners extends IdentifiedSessionWithGracePeriodListeners {
191
285
  onConnectionEstablished: (conn: Connection) => void;
192
286
  onConnectionFailed: (err: unknown) => void;
@@ -207,12 +301,6 @@ declare class SessionConnecting<ConnType extends Connection> extends IdentifiedS
207
301
  _handleClose(): void;
208
302
  }
209
303
 
210
- declare class SessionNoConnection extends IdentifiedSessionWithGracePeriod {
211
- readonly state: SessionState.NoConnection;
212
- _handleClose(): void;
213
- _handleStateExit(): void;
214
- }
215
-
216
304
  interface SessionHandshakingListeners extends IdentifiedSessionWithGracePeriodListeners {
217
305
  onConnectionErrored: (err: unknown) => void;
218
306
  onConnectionClosed: () => void;
@@ -303,6 +391,12 @@ declare class SessionConnected<ConnType extends Connection> extends IdentifiedSe
303
391
  _handleClose(): void;
304
392
  }
305
393
 
394
+ declare class SessionNoConnection extends IdentifiedSessionWithGracePeriod {
395
+ readonly state: SessionState.NoConnection;
396
+ _handleClose(): void;
397
+ _handleStateExit(): void;
398
+ }
399
+
306
400
  interface SessionBackingOffListeners extends IdentifiedSessionWithGracePeriodListeners {
307
401
  onBackoffFinished: () => void;
308
402
  }
@@ -379,65 +473,6 @@ declare class EventDispatcher<T extends EventTypes> {
379
473
  dispatchEvent<K extends T>(eventType: K, event: EventMap[K]): void;
380
474
  }
381
475
 
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
476
  /**
442
477
  * Represents the possible states of a transport.
443
478
  * @property {'open'} open - The transport is open and operational (note that this doesn't mean it is actively connected)
@@ -539,39 +574,4 @@ declare abstract class Transport<ConnType extends Connection> {
539
574
  getSessionBoundSendFn(to: TransportClientId, sessionId: SessionId): SessionBoundSendFn;
540
575
  }
541
576
 
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
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 { 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,100 @@ 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
+ declare class LeakyBucketRateLimit {
263
+ private budgetConsumed;
264
+ private intervalHandle?;
265
+ private readonly options;
266
+ constructor(options: ConnectionRetryOptions);
267
+ getBackoffMs(): number;
268
+ get totalBudgetRestoreTime(): number;
269
+ consumeBudget(): void;
270
+ getBudgetConsumed(): number;
271
+ hasBudget(): boolean;
272
+ startRestoringBudget(): void;
273
+ private stopLeak;
274
+ close(): void;
275
+ }
276
+
277
+ type TransportOptions = SessionOptions;
278
+ type ProvidedTransportOptions = Partial<TransportOptions>;
279
+ type ClientTransportOptions = TransportOptions & ConnectionRetryOptions;
280
+ type ProvidedClientTransportOptions = Partial<ClientTransportOptions>;
281
+ type ServerTransportOptions = TransportOptions;
282
+ type ProvidedServerTransportOptions = Partial<ServerTransportOptions>;
283
+
190
284
  interface SessionConnectingListeners extends IdentifiedSessionWithGracePeriodListeners {
191
285
  onConnectionEstablished: (conn: Connection) => void;
192
286
  onConnectionFailed: (err: unknown) => void;
@@ -207,12 +301,6 @@ declare class SessionConnecting<ConnType extends Connection> extends IdentifiedS
207
301
  _handleClose(): void;
208
302
  }
209
303
 
210
- declare class SessionNoConnection extends IdentifiedSessionWithGracePeriod {
211
- readonly state: SessionState.NoConnection;
212
- _handleClose(): void;
213
- _handleStateExit(): void;
214
- }
215
-
216
304
  interface SessionHandshakingListeners extends IdentifiedSessionWithGracePeriodListeners {
217
305
  onConnectionErrored: (err: unknown) => void;
218
306
  onConnectionClosed: () => void;
@@ -303,6 +391,12 @@ declare class SessionConnected<ConnType extends Connection> extends IdentifiedSe
303
391
  _handleClose(): void;
304
392
  }
305
393
 
394
+ declare class SessionNoConnection extends IdentifiedSessionWithGracePeriod {
395
+ readonly state: SessionState.NoConnection;
396
+ _handleClose(): void;
397
+ _handleStateExit(): void;
398
+ }
399
+
306
400
  interface SessionBackingOffListeners extends IdentifiedSessionWithGracePeriodListeners {
307
401
  onBackoffFinished: () => void;
308
402
  }
@@ -379,65 +473,6 @@ declare class EventDispatcher<T extends EventTypes> {
379
473
  dispatchEvent<K extends T>(eventType: K, event: EventMap[K]): void;
380
474
  }
381
475
 
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
476
  /**
442
477
  * Represents the possible states of a transport.
443
478
  * @property {'open'} open - The transport is open and operational (note that this doesn't mean it is actively connected)
@@ -539,39 +574,4 @@ declare abstract class Transport<ConnType extends Connection> {
539
574
  getSessionBoundSendFn(to: TransportClientId, sessionId: SessionId): SessionBoundSendFn;
540
575
  }
541
576
 
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
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 };
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.3",
5
5
  "type": "module",
6
6
  "exports": {
7
7
  ".": {