@replit/river 0.23.12 → 0.23.14

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 (75) hide show
  1. package/dist/{chunk-3AW3IXVD.js → chunk-4PVU7J25.js} +1 -21
  2. package/dist/chunk-4PVU7J25.js.map +1 -0
  3. package/dist/{chunk-HDBVL7EF.js → chunk-BEALFLCB.js} +2 -2
  4. package/dist/chunk-D2DHRRBN.js +476 -0
  5. package/dist/chunk-D2DHRRBN.js.map +1 -0
  6. package/dist/{chunk-7RUKEUKE.js → chunk-GCCRVSMR.js} +33 -4
  7. package/dist/chunk-GCCRVSMR.js.map +1 -0
  8. package/dist/{chunk-XZ6IOBM5.js → chunk-GN4YEXT7.js} +2 -2
  9. package/dist/chunk-GN4YEXT7.js.map +1 -0
  10. package/dist/chunk-O2AVDJCQ.js +335 -0
  11. package/dist/chunk-O2AVDJCQ.js.map +1 -0
  12. package/dist/chunk-OTVTKAN6.js +451 -0
  13. package/dist/chunk-OTVTKAN6.js.map +1 -0
  14. package/dist/chunk-WUL63FR6.js +335 -0
  15. package/dist/chunk-WUL63FR6.js.map +1 -0
  16. package/dist/{chunk-H6KTH6W6.js → chunk-YCLZWES2.js} +2 -2
  17. package/dist/client-e13979ac.d.ts +52 -0
  18. package/dist/codec/index.js +20 -2
  19. package/dist/codec/index.js.map +1 -1
  20. package/dist/{connection-8debd45f.d.ts → connection-5d0978ce.d.ts} +1 -1
  21. package/dist/{connection-581558f8.d.ts → connection-e57e98ea.d.ts} +1 -1
  22. package/dist/{transport-47af1c81.d.ts → handshake-5665ffd3.d.ts} +101 -153
  23. package/dist/{index-60f03cb7.d.ts → index-ea74cdbb.d.ts} +1 -1
  24. package/dist/logging/index.d.cts +1 -1
  25. package/dist/logging/index.d.ts +1 -1
  26. package/dist/router/index.cjs +16 -1
  27. package/dist/router/index.cjs.map +1 -1
  28. package/dist/router/index.d.cts +8 -6
  29. package/dist/router/index.d.ts +8 -6
  30. package/dist/router/index.js +2 -2
  31. package/dist/server-1cfc88d1.d.ts +24 -0
  32. package/dist/{services-ca72c9f8.d.ts → services-86c4d10d.d.ts} +3 -2
  33. package/dist/transport/impls/uds/client.cjs +303 -180
  34. package/dist/transport/impls/uds/client.cjs.map +1 -1
  35. package/dist/transport/impls/uds/client.d.cts +6 -5
  36. package/dist/transport/impls/uds/client.d.ts +6 -5
  37. package/dist/transport/impls/uds/client.js +6 -4
  38. package/dist/transport/impls/uds/client.js.map +1 -1
  39. package/dist/transport/impls/uds/server.cjs +396 -234
  40. package/dist/transport/impls/uds/server.cjs.map +1 -1
  41. package/dist/transport/impls/uds/server.d.cts +6 -5
  42. package/dist/transport/impls/uds/server.d.ts +6 -5
  43. package/dist/transport/impls/uds/server.js +8 -6
  44. package/dist/transport/impls/uds/server.js.map +1 -1
  45. package/dist/transport/impls/ws/client.cjs +305 -182
  46. package/dist/transport/impls/ws/client.cjs.map +1 -1
  47. package/dist/transport/impls/ws/client.d.cts +6 -5
  48. package/dist/transport/impls/ws/client.d.ts +6 -5
  49. package/dist/transport/impls/ws/client.js +6 -4
  50. package/dist/transport/impls/ws/client.js.map +1 -1
  51. package/dist/transport/impls/ws/server.cjs +350 -188
  52. package/dist/transport/impls/ws/server.cjs.map +1 -1
  53. package/dist/transport/impls/ws/server.d.cts +4 -3
  54. package/dist/transport/impls/ws/server.d.ts +4 -3
  55. package/dist/transport/impls/ws/server.js +8 -6
  56. package/dist/transport/impls/ws/server.js.map +1 -1
  57. package/dist/transport/index.cjs +338 -142
  58. package/dist/transport/index.cjs.map +1 -1
  59. package/dist/transport/index.d.cts +4 -2
  60. package/dist/transport/index.d.ts +4 -2
  61. package/dist/transport/index.js +14 -8
  62. package/dist/util/testHelpers.cjs +10 -6
  63. package/dist/util/testHelpers.cjs.map +1 -1
  64. package/dist/util/testHelpers.d.cts +5 -4
  65. package/dist/util/testHelpers.d.ts +5 -4
  66. package/dist/util/testHelpers.js +4 -5
  67. package/dist/util/testHelpers.js.map +1 -1
  68. package/package.json +13 -14
  69. package/dist/chunk-3AW3IXVD.js.map +0 -1
  70. package/dist/chunk-7RUKEUKE.js.map +0 -1
  71. package/dist/chunk-VRU4IKRT.js +0 -1392
  72. package/dist/chunk-VRU4IKRT.js.map +0 -1
  73. package/dist/chunk-XZ6IOBM5.js.map +0 -1
  74. /package/dist/{chunk-HDBVL7EF.js.map → chunk-BEALFLCB.js.map} +0 -0
  75. /package/dist/{chunk-H6KTH6W6.js.map → chunk-YCLZWES2.js.map} +0 -0
@@ -1,5 +1,5 @@
1
- import { a as TelemetryInfo, M as MessageMetadata, T as TransportClientId, b as PropagationContext, L as Logger, P as PartialTransportMessage, c as TransportMessage, O as OpaqueTransportMessage, g as LogFn, h as LoggingLevel } from './index-60f03cb7.js';
2
1
  import { C as Codec } from './types-3e5768ec.js';
2
+ import { e as TelemetryInfo, M as MessageMetadata, c as TransportClientId, f as PropagationContext, L as Logger, P as PartialTransportMessage, a as TransportMessage, b as OpaqueTransportMessage, g as LogFn, h as LoggingLevel } from './index-ea74cdbb.js';
3
3
  import { TSchema, Static } from '@sinclair/typebox';
4
4
 
5
5
  /**
@@ -151,7 +151,9 @@ declare class Session<ConnType extends Connection> {
151
151
  closeHandshakingConnection(expectedHandshakingConn?: ConnType): void;
152
152
  close(): void;
153
153
  get connected(): boolean;
154
+ get nextExpectedAck(): number;
154
155
  get nextExpectedSeq(): number;
156
+ advanceAckForTesting(by: number): void;
155
157
  constructMsg<Payload>(partialMsg: PartialTransportMessage<Payload>): TransportMessage<Payload>;
156
158
  inspectSendBuffer(): ReadonlyArray<OpaqueTransportMessage>;
157
159
  }
@@ -244,95 +246,12 @@ declare class LeakyBucketRateLimit {
244
246
  close(): void;
245
247
  }
246
248
 
247
- /**
248
- * The context for services/procedures. This is used only on
249
- * the server.
250
- *
251
- * An important detail is that the state prop is always on
252
- * this interface and it shouldn't be changed, removed, or
253
- * extended. This prop is for the state of a service.
254
- *
255
- * You should use declaration merging to extend this interface
256
- * with whatever you need. For example, if you need to access
257
- * a database, you could do:
258
- *
259
- * ```ts
260
- * declare module '@replit/river' {
261
- * interface ServiceContext {
262
- * db: Database;
263
- * }
264
- * }
265
- * ```
266
- */
267
- interface ServiceContext {
268
- }
269
- /**
270
- * The parsed metadata schema for a service. This is the
271
- * return value of the {@link ServerHandshakeOptions.validate}
272
- * if the handshake extension is used.
273
-
274
- * You should use declaration merging to extend this interface
275
- * with the sanitized metadata.
276
- *
277
- * ```ts
278
- * declare module '@replit/river' {
279
- * interface ParsedMetadata {
280
- * userId: number;
281
- * }
282
- * }
283
- * ```
284
- */
285
- interface ParsedMetadata {
286
- }
287
- /**
288
- * The {@link ServiceContext} with state. This is what is passed to procedures.
289
- */
290
- type ServiceContextWithState<State> = ServiceContext & {
291
- state: State;
292
- };
293
- type ServiceContextWithTransportInfo<State> = ServiceContext & {
294
- state: State;
295
- to: TransportClientId;
296
- from: TransportClientId;
297
- streamId: string;
298
- session: Session<Connection>;
299
- metadata: ParsedMetadata;
300
- };
301
-
302
- type ConstructHandshake<T extends TSchema> = () => Static<T> | Promise<Static<T>>;
303
- type ValidateHandshake<T extends TSchema> = (metadata: Static<T>, previousParsedMetadata?: ParsedMetadata) => false | ParsedMetadata | Promise<false | ParsedMetadata>;
304
- interface ClientHandshakeOptions<MetadataSchema extends TSchema = TSchema> {
305
- /**
306
- * Schema for the metadata that the client sends to the server
307
- * during the handshake.
308
- */
309
- schema: MetadataSchema;
310
- /**
311
- * Gets the {@link HandshakeRequestMetadata} to send to the server.
312
- */
313
- construct: ConstructHandshake<MetadataSchema>;
314
- }
315
- interface ServerHandshakeOptions<MetadataSchema extends TSchema = TSchema> {
316
- /**
317
- * Schema for the metadata that the server receives from the client
318
- * during the handshake.
319
- */
320
- schema: MetadataSchema;
321
- /**
322
- * Parses the {@link HandshakeRequestMetadata} sent by the client, transforming
323
- * it into {@link ParsedHandshakeMetadata}.
324
- *
325
- * May return `false` if the client should be rejected.
326
- *
327
- * @param metadata - The metadata sent by the client.
328
- * @param session - The session that the client would be associated with.
329
- * @param isReconnect - Whether the client is reconnecting to the session,
330
- * or if this is a new session.
331
- */
332
- validate: ValidateHandshake<MetadataSchema>;
333
- }
334
- declare function createClientHandshakeOptions<MetadataSchema extends TSchema = TSchema>(schema: MetadataSchema, construct: ConstructHandshake<MetadataSchema>): ClientHandshakeOptions;
335
- declare function createServerHandshakeOptions<MetadataSchema extends TSchema = TSchema>(schema: MetadataSchema, validate: ValidateHandshake<MetadataSchema>): ServerHandshakeOptions;
249
+ type TransportOptions = SessionOptions;
250
+ type ProvidedTransportOptions = Partial<TransportOptions>;
251
+ type ClientTransportOptions = TransportOptions & ConnectionRetryOptions;
252
+ type ProvidedClientTransportOptions = Partial<ClientTransportOptions>;
253
+ type ServerTransportOptions = TransportOptions;
254
+ type ProvidedServerTransportOptions = Partial<ServerTransportOptions>;
336
255
 
337
256
  /**
338
257
  * Represents the possible states of a transport.
@@ -340,12 +259,6 @@ declare function createServerHandshakeOptions<MetadataSchema extends TSchema = T
340
259
  * @property {'closed'} closed - The transport is permanently closed and cannot be reopened.
341
260
  */
342
261
  type TransportStatus = 'open' | 'closed';
343
- type TransportOptions = SessionOptions;
344
- type ProvidedTransportOptions = Partial<TransportOptions>;
345
- type ClientTransportOptions = TransportOptions & ConnectionRetryOptions;
346
- type ProvidedClientTransportOptions = Partial<ClientTransportOptions>;
347
- type ServerTransportOptions = TransportOptions;
348
- type ProvidedServerTransportOptions = Partial<ServerTransportOptions>;
349
262
  /**
350
263
  * Transports manage the lifecycle (creation/deletion) of sessions and connections. Its responsibilities include:
351
264
  *
@@ -430,6 +343,17 @@ declare abstract class Transport<ConnType extends Connection> {
430
343
  */
431
344
  protected onConnect(conn: ConnType, session: Session<ConnType>, isTransparentReconnect: boolean): void;
432
345
  protected createSession(to: TransportClientId, conn?: ConnType, propagationCtx?: PropagationContext): Session<ConnType>;
346
+ protected createNewSession({ to, conn, sessionId, propagationCtx, }: {
347
+ to: TransportClientId;
348
+ conn: ConnType;
349
+ sessionId: string;
350
+ propagationCtx?: PropagationContext;
351
+ }): Session<ConnType>;
352
+ protected getExistingSession({ to, sessionId, nextExpectedSeq, }: {
353
+ to: TransportClientId;
354
+ sessionId: string;
355
+ nextExpectedSeq: number;
356
+ }): false | Session<ConnType>;
433
357
  protected getOrCreateSession({ to, conn, handshakingConn, sessionId, propagationCtx, }: {
434
358
  to: TransportClientId;
435
359
  conn?: ConnType;
@@ -493,71 +417,95 @@ declare abstract class Transport<ConnType extends Connection> {
493
417
  close(): void;
494
418
  getStatus(): TransportStatus;
495
419
  }
496
- declare abstract class ClientTransport<ConnType extends Connection> extends Transport<ConnType> {
497
- /**
498
- * The options for this transport.
499
- */
500
- protected options: ClientTransportOptions;
501
- /**
502
- * The map of reconnect promises for each client ID.
503
- */
504
- inflightConnectionPromises: Map<TransportClientId, Promise<ConnType>>;
505
- retryBudget: LeakyBucketRateLimit;
506
- /**
507
- * A flag indicating whether the transport should automatically reconnect
508
- * when a connection is dropped.
509
- * Realistically, this should always be true for clients unless you are writing
510
- * tests or a special case where you don't want to reconnect.
511
- */
512
- reconnectOnConnectionDrop: boolean;
513
- /**
514
- * Optional handshake options for this client.
515
- */
516
- handshakeExtensions?: ClientHandshakeOptions;
517
- constructor(clientId: TransportClientId, providedOptions?: ProvidedClientTransportOptions);
518
- extendHandshake(options: ClientHandshakeOptions): void;
519
- protected handleConnection(conn: ConnType, to: TransportClientId): void;
520
- receiveHandshakeResponseMessage(data: Uint8Array, conn: ConnType): Session<ConnType> | false;
420
+
421
+ /**
422
+ * The context for services/procedures. This is used only on
423
+ * the server.
424
+ *
425
+ * An important detail is that the state prop is always on
426
+ * this interface and it shouldn't be changed, removed, or
427
+ * extended. This prop is for the state of a service.
428
+ *
429
+ * You should use declaration merging to extend this interface
430
+ * with whatever you need. For example, if you need to access
431
+ * a database, you could do:
432
+ *
433
+ * ```ts
434
+ * declare module '@replit/river' {
435
+ * interface ServiceContext {
436
+ * db: Database;
437
+ * }
438
+ * }
439
+ * ```
440
+ */
441
+ interface ServiceContext {
442
+ }
443
+ /**
444
+ * The parsed metadata schema for a service. This is the
445
+ * return value of the {@link ServerHandshakeOptions.validate}
446
+ * if the handshake extension is used.
447
+
448
+ * You should use declaration merging to extend this interface
449
+ * with the sanitized metadata.
450
+ *
451
+ * ```ts
452
+ * declare module '@replit/river' {
453
+ * interface ParsedMetadata {
454
+ * userId: number;
455
+ * }
456
+ * }
457
+ * ```
458
+ */
459
+ interface ParsedMetadata {
460
+ }
461
+ /**
462
+ * The {@link ServiceContext} with state. This is what is passed to procedures.
463
+ */
464
+ type ServiceContextWithState<State> = ServiceContext & {
465
+ state: State;
466
+ };
467
+ type ServiceContextWithTransportInfo<State> = ServiceContext & {
468
+ state: State;
469
+ to: TransportClientId;
470
+ from: TransportClientId;
471
+ streamId: string;
472
+ session: Session<Connection>;
473
+ metadata: ParsedMetadata;
474
+ };
475
+
476
+ type ConstructHandshake<T extends TSchema> = () => Static<T> | Promise<Static<T>>;
477
+ type ValidateHandshake<T extends TSchema> = (metadata: Static<T>, previousParsedMetadata?: ParsedMetadata) => false | ParsedMetadata | Promise<false | ParsedMetadata>;
478
+ interface ClientHandshakeOptions<MetadataSchema extends TSchema = TSchema> {
521
479
  /**
522
- * Abstract method that creates a new {@link Connection} object.
523
- * This should call {@link handleConnection} when the connection is created.
524
- * The downstream client implementation needs to implement this.
525
- *
526
- * @param to The client ID of the node to connect to.
527
- * @returns The new connection object.
480
+ * Schema for the metadata that the client sends to the server
481
+ * during the handshake.
528
482
  */
529
- protected abstract createNewOutgoingConnection(to: TransportClientId): Promise<ConnType>;
483
+ schema: MetadataSchema;
530
484
  /**
531
- * Manually attempts to connect to a client.
532
- * @param to The client ID of the node to connect to.
485
+ * Gets the {@link HandshakeRequestMetadata} to send to the server.
533
486
  */
534
- connect(to: TransportClientId): Promise<void>;
535
- protected deleteSession({ session, closeHandshakingConnection, handshakingConn, }: {
536
- session: Session<ConnType>;
537
- closeHandshakingConnection: boolean;
538
- handshakingConn?: ConnType;
539
- }): void;
540
- protected sendHandshake(to: TransportClientId, conn: ConnType): Promise<boolean>;
541
- close(): void;
487
+ construct: ConstructHandshake<MetadataSchema>;
542
488
  }
543
- declare abstract class ServerTransport<ConnType extends Connection> extends Transport<ConnType> {
544
- /**
545
- * The options for this transport.
546
- */
547
- protected options: ServerTransportOptions;
489
+ interface ServerHandshakeOptions<MetadataSchema extends TSchema = TSchema> {
548
490
  /**
549
- * Optional handshake options for the server.
491
+ * Schema for the metadata that the server receives from the client
492
+ * during the handshake.
550
493
  */
551
- handshakeExtensions?: ServerHandshakeOptions;
494
+ schema: MetadataSchema;
552
495
  /**
553
- * A map of session handshake data for each session.
496
+ * Parses the {@link HandshakeRequestMetadata} sent by the client, transforming
497
+ * it into {@link ParsedHandshakeMetadata}.
498
+ *
499
+ * May return `false` if the client should be rejected.
500
+ *
501
+ * @param metadata - The metadata sent by the client.
502
+ * @param session - The session that the client would be associated with.
503
+ * @param isReconnect - Whether the client is reconnecting to the session,
504
+ * or if this is a new session.
554
505
  */
555
- sessionHandshakeMetadata: WeakMap<Session<ConnType>, ParsedMetadata>;
556
- constructor(clientId: TransportClientId, providedOptions?: ProvidedServerTransportOptions);
557
- extendHandshake(options: ServerHandshakeOptions): void;
558
- protected handleConnection(conn: ConnType): void;
559
- private validateHandshakeMetadata;
560
- receiveHandshakeRequestMessage(data: Uint8Array, conn: ConnType): Promise<Session<ConnType> | false>;
506
+ validate: ValidateHandshake<MetadataSchema>;
561
507
  }
508
+ declare function createClientHandshakeOptions<MetadataSchema extends TSchema = TSchema>(schema: MetadataSchema, construct: ConstructHandshake<MetadataSchema>): ClientHandshakeOptions;
509
+ declare function createServerHandshakeOptions<MetadataSchema extends TSchema = TSchema>(schema: MetadataSchema, validate: ValidateHandshake<MetadataSchema>): ServerHandshakeOptions;
562
510
 
563
- export { Connection as C, EventMap as E, ProvidedClientTransportOptions as P, SessionOptions as S, Transport as T, Session as a, ServiceContext as b, ClientTransport as c, ServerTransport as d, ProvidedServerTransportOptions as e, ServerHandshakeOptions as f, ParsedMetadata as g, ServiceContextWithState as h, ServiceContextWithTransportInfo as i, createClientHandshakeOptions as j, createServerHandshakeOptions as k, ClientHandshakeOptions as l, ProvidedTransportOptions as m, TransportStatus as n, EventTypes as o, EventHandler as p, ProtocolError as q, ProtocolErrorType as r };
511
+ export { Connection as C, EventMap as E, LeakyBucketRateLimit as L, ProvidedTransportOptions as P, Session as S, Transport as T, TransportStatus as a, ProvidedClientTransportOptions as b, ProvidedServerTransportOptions as c, EventTypes as d, EventHandler as e, ProtocolError as f, ProtocolErrorType as g, SessionOptions as h, ServiceContext as i, ClientTransportOptions as j, ClientHandshakeOptions as k, ServerTransportOptions as l, ServerHandshakeOptions as m, ParsedMetadata as n, ServiceContextWithState as o, ServiceContextWithTransportInfo as p, createClientHandshakeOptions as q, createServerHandshakeOptions as r };
@@ -133,4 +133,4 @@ declare function isStreamOpen(controlFlag: number): boolean;
133
133
  */
134
134
  declare function isStreamClose(controlFlag: number): boolean;
135
135
 
136
- export { Logger as L, MessageMetadata as M, OpaqueTransportMessage as O, PartialTransportMessage as P, TransportClientId as T, TelemetryInfo as a, PropagationContext as b, TransportMessage as c, TransportMessageSchema as d, OpaqueTransportMessageSchema as e, isStreamClose as f, LogFn as g, LoggingLevel as h, isStreamOpen as i, coloredStringLogger as j, jsonLogger as k, stringLogger as s };
136
+ export { Logger as L, MessageMetadata as M, OpaqueTransportMessageSchema as O, PartialTransportMessage as P, TransportMessageSchema as T, TransportMessage as a, OpaqueTransportMessage as b, TransportClientId as c, isStreamClose as d, TelemetryInfo as e, PropagationContext as f, LogFn as g, LoggingLevel as h, isStreamOpen as i, coloredStringLogger as j, jsonLogger as k, stringLogger as s };
@@ -1,4 +1,4 @@
1
- export { g as LogFn, L as Logger, M as MessageMetadata, j as coloredStringLogger, k as jsonLogger, s as stringLogger } from '../index-60f03cb7.js';
1
+ export { g as LogFn, L as Logger, M as MessageMetadata, j as coloredStringLogger, k as jsonLogger, s as stringLogger } from '../index-ea74cdbb.js';
2
2
  import '@sinclair/typebox/value';
3
3
  import '@sinclair/typebox';
4
4
  import '@opentelemetry/api';
@@ -1,4 +1,4 @@
1
- export { g as LogFn, L as Logger, M as MessageMetadata, j as coloredStringLogger, k as jsonLogger, s as stringLogger } from '../index-60f03cb7.js';
1
+ export { g as LogFn, L as Logger, M as MessageMetadata, j as coloredStringLogger, k as jsonLogger, s as stringLogger } from '../index-ea74cdbb.js';
2
2
  import '@sinclair/typebox/value';
3
3
  import '@sinclair/typebox';
4
4
  import '@opentelemetry/api';
@@ -1104,6 +1104,21 @@ var ControlMessageHandshakeRequestSchema = import_typebox3.Type.Object({
1104
1104
  type: import_typebox3.Type.Literal("HANDSHAKE_REQ"),
1105
1105
  protocolVersion: import_typebox3.Type.String(),
1106
1106
  sessionId: import_typebox3.Type.String(),
1107
+ /**
1108
+ * Specifies what the server's expected session state (from the pov of the client). This can be
1109
+ * used by the server to know whether this is a new or a reestablished connection, and whether it
1110
+ * is compatible with what it already has.
1111
+ */
1112
+ expectedSessionState: import_typebox3.Type.Optional(
1113
+ import_typebox3.Type.Object({
1114
+ /**
1115
+ * reconnect is set to true if the client explicitly wants to reestablish an existing
1116
+ * connection.
1117
+ */
1118
+ reconnect: import_typebox3.Type.Boolean(),
1119
+ nextExpectedSeq: import_typebox3.Type.Integer()
1120
+ })
1121
+ ),
1107
1122
  metadata: import_typebox3.Type.Optional(import_typebox3.Type.Unknown())
1108
1123
  });
1109
1124
  var ControlMessageHandshakeResponseSchema = import_typebox3.Type.Object({
@@ -1172,7 +1187,7 @@ function Err(error) {
1172
1187
  var import_api = require("@opentelemetry/api");
1173
1188
 
1174
1189
  // package.json
1175
- var version = "0.23.12";
1190
+ var version = "0.23.14";
1176
1191
 
1177
1192
  // tracing/index.ts
1178
1193
  function getPropagationContext(ctx) {