@replit/river 0.209.0 → 0.209.2
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.
- package/dist/{chunk-TVN2TB6X.js → chunk-DVAIJ57I.js} +10 -10
- package/dist/{chunk-RATCBAZE.js → chunk-L3KNTJU3.js} +316 -303
- package/dist/chunk-L3KNTJU3.js.map +1 -0
- package/dist/{chunk-LPWARXI3.js → chunk-OTL2R22H.js} +2 -2
- package/dist/{client-aETS93z1.d.cts → client-BX3IXUA2.d.cts} +1 -1
- package/dist/{client-BzJwq-hg.d.ts → client-CBak1h8Q.d.ts} +1 -1
- package/dist/codec/index.js +2 -2
- package/dist/{connection-hUWlS-hg.d.cts → connection-_eetKnva.d.cts} +1 -1
- package/dist/{connection-b1wd5XrC.d.ts → connection-zMlysQKs.d.ts} +1 -1
- package/dist/{transport-CxjUaGhi.d.cts → handshake-B3iu79B0.d.cts} +102 -102
- package/dist/{transport-DwEB67zY.d.ts → handshake-DNinPBA3.d.ts} +102 -102
- package/dist/router/index.cjs +300 -285
- package/dist/router/index.cjs.map +1 -1
- package/dist/router/index.d.cts +7 -7
- package/dist/router/index.d.ts +7 -7
- package/dist/router/index.js +5 -1
- package/dist/{server-BBgDVOzk.d.cts → server-BV7GXuhz.d.cts} +1 -1
- package/dist/{server-DZ0Yzmpf.d.ts → server-B_H1zn-R.d.ts} +1 -1
- package/dist/{services-DC_uol9A.d.cts → services-BIMmk-v4.d.cts} +97 -4
- package/dist/{services-DBvjc-Mq.d.ts → services-DtsSIaec.d.ts} +97 -4
- package/dist/testUtil/index.cjs +1 -1
- package/dist/testUtil/index.cjs.map +1 -1
- package/dist/testUtil/index.d.cts +4 -4
- package/dist/testUtil/index.d.ts +4 -4
- package/dist/testUtil/index.js +3 -3
- package/dist/transport/impls/ws/client.cjs +1 -1
- package/dist/transport/impls/ws/client.cjs.map +1 -1
- package/dist/transport/impls/ws/client.d.cts +3 -3
- package/dist/transport/impls/ws/client.d.ts +3 -3
- package/dist/transport/impls/ws/client.js +3 -3
- package/dist/transport/impls/ws/server.cjs +1 -1
- package/dist/transport/impls/ws/server.cjs.map +1 -1
- package/dist/transport/impls/ws/server.d.cts +3 -3
- package/dist/transport/impls/ws/server.d.ts +3 -3
- package/dist/transport/impls/ws/server.js +3 -3
- package/dist/transport/index.cjs +1 -1
- package/dist/transport/index.cjs.map +1 -1
- package/dist/transport/index.d.cts +4 -4
- package/dist/transport/index.d.ts +4 -4
- package/dist/transport/index.js +3 -3
- package/package.json +1 -1
- package/dist/chunk-RATCBAZE.js.map +0 -1
- /package/dist/{chunk-TVN2TB6X.js.map → chunk-DVAIJ57I.js.map} +0 -0
- /package/dist/{chunk-LPWARXI3.js.map → chunk-OTL2R22H.js.map} +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
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';
|
|
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';
|
|
3
2
|
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,100 +187,6 @@ 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
|
-
|
|
284
190
|
interface SessionConnectingListeners extends IdentifiedSessionWithGracePeriodListeners {
|
|
285
191
|
onConnectionEstablished: (conn: Connection) => void;
|
|
286
192
|
onConnectionFailed: (err: unknown) => void;
|
|
@@ -301,6 +207,12 @@ declare class SessionConnecting<ConnType extends Connection> extends IdentifiedS
|
|
|
301
207
|
_handleClose(): void;
|
|
302
208
|
}
|
|
303
209
|
|
|
210
|
+
declare class SessionNoConnection extends IdentifiedSessionWithGracePeriod {
|
|
211
|
+
readonly state: SessionState.NoConnection;
|
|
212
|
+
_handleClose(): void;
|
|
213
|
+
_handleStateExit(): void;
|
|
214
|
+
}
|
|
215
|
+
|
|
304
216
|
interface SessionHandshakingListeners extends IdentifiedSessionWithGracePeriodListeners {
|
|
305
217
|
onConnectionErrored: (err: unknown) => void;
|
|
306
218
|
onConnectionClosed: () => void;
|
|
@@ -391,12 +303,6 @@ declare class SessionConnected<ConnType extends Connection> extends IdentifiedSe
|
|
|
391
303
|
_handleClose(): void;
|
|
392
304
|
}
|
|
393
305
|
|
|
394
|
-
declare class SessionNoConnection extends IdentifiedSessionWithGracePeriod {
|
|
395
|
-
readonly state: SessionState.NoConnection;
|
|
396
|
-
_handleClose(): void;
|
|
397
|
-
_handleStateExit(): void;
|
|
398
|
-
}
|
|
399
|
-
|
|
400
306
|
interface SessionBackingOffListeners extends IdentifiedSessionWithGracePeriodListeners {
|
|
401
307
|
onBackoffFinished: () => void;
|
|
402
308
|
}
|
|
@@ -473,6 +379,65 @@ declare class EventDispatcher<T extends EventTypes> {
|
|
|
473
379
|
dispatchEvent<K extends T>(eventType: K, event: EventMap[K]): void;
|
|
474
380
|
}
|
|
475
381
|
|
|
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
|
+
|
|
476
441
|
/**
|
|
477
442
|
* Represents the possible states of a transport.
|
|
478
443
|
* @property {'open'} open - The transport is open and operational (note that this doesn't mean it is actively connected)
|
|
@@ -574,4 +539,39 @@ declare abstract class Transport<ConnType extends Connection> {
|
|
|
574
539
|
getSessionBoundSendFn(to: TransportClientId, sessionId: SessionId): SessionBoundSendFn;
|
|
575
540
|
}
|
|
576
541
|
|
|
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 {
|
|
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';
|
|
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';
|
|
3
2
|
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,100 +187,6 @@ 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
|
-
|
|
284
190
|
interface SessionConnectingListeners extends IdentifiedSessionWithGracePeriodListeners {
|
|
285
191
|
onConnectionEstablished: (conn: Connection) => void;
|
|
286
192
|
onConnectionFailed: (err: unknown) => void;
|
|
@@ -301,6 +207,12 @@ declare class SessionConnecting<ConnType extends Connection> extends IdentifiedS
|
|
|
301
207
|
_handleClose(): void;
|
|
302
208
|
}
|
|
303
209
|
|
|
210
|
+
declare class SessionNoConnection extends IdentifiedSessionWithGracePeriod {
|
|
211
|
+
readonly state: SessionState.NoConnection;
|
|
212
|
+
_handleClose(): void;
|
|
213
|
+
_handleStateExit(): void;
|
|
214
|
+
}
|
|
215
|
+
|
|
304
216
|
interface SessionHandshakingListeners extends IdentifiedSessionWithGracePeriodListeners {
|
|
305
217
|
onConnectionErrored: (err: unknown) => void;
|
|
306
218
|
onConnectionClosed: () => void;
|
|
@@ -391,12 +303,6 @@ declare class SessionConnected<ConnType extends Connection> extends IdentifiedSe
|
|
|
391
303
|
_handleClose(): void;
|
|
392
304
|
}
|
|
393
305
|
|
|
394
|
-
declare class SessionNoConnection extends IdentifiedSessionWithGracePeriod {
|
|
395
|
-
readonly state: SessionState.NoConnection;
|
|
396
|
-
_handleClose(): void;
|
|
397
|
-
_handleStateExit(): void;
|
|
398
|
-
}
|
|
399
|
-
|
|
400
306
|
interface SessionBackingOffListeners extends IdentifiedSessionWithGracePeriodListeners {
|
|
401
307
|
onBackoffFinished: () => void;
|
|
402
308
|
}
|
|
@@ -473,6 +379,65 @@ declare class EventDispatcher<T extends EventTypes> {
|
|
|
473
379
|
dispatchEvent<K extends T>(eventType: K, event: EventMap[K]): void;
|
|
474
380
|
}
|
|
475
381
|
|
|
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
|
+
|
|
476
441
|
/**
|
|
477
442
|
* Represents the possible states of a transport.
|
|
478
443
|
* @property {'open'} open - The transport is open and operational (note that this doesn't mean it is actively connected)
|
|
@@ -574,4 +539,39 @@ declare abstract class Transport<ConnType extends Connection> {
|
|
|
574
539
|
getSessionBoundSendFn(to: TransportClientId, sessionId: SessionId): SessionBoundSendFn;
|
|
575
540
|
}
|
|
576
541
|
|
|
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 };
|