@replit/river 0.23.11 → 0.23.13

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 (74) hide show
  1. package/dist/chunk-2FNLANTJ.js +327 -0
  2. package/dist/chunk-2FNLANTJ.js.map +1 -0
  3. package/dist/{chunk-3AW3IXVD.js → chunk-4PVU7J25.js} +1 -21
  4. package/dist/chunk-4PVU7J25.js.map +1 -0
  5. package/dist/{chunk-T6YEMFUF.js → chunk-4QZOW4DH.js} +2 -2
  6. package/dist/{chunk-MEHCOYKJ.js → chunk-ES4XO2XD.js} +2 -2
  7. package/dist/{chunk-MEHCOYKJ.js.map → chunk-ES4XO2XD.js.map} +1 -1
  8. package/dist/{chunk-ZSKCZYVU.js → chunk-KFTGQ3QC.js} +2 -2
  9. package/dist/chunk-KFTGQ3QC.js.map +1 -0
  10. package/dist/chunk-S4DUN7KK.js +455 -0
  11. package/dist/chunk-S4DUN7KK.js.map +1 -0
  12. package/dist/{chunk-HM7VDTDJ.js → chunk-SX6HI63Q.js} +2 -2
  13. package/dist/chunk-XM656KMN.js +408 -0
  14. package/dist/chunk-XM656KMN.js.map +1 -0
  15. package/dist/chunk-ZUKDZY54.js +271 -0
  16. package/dist/chunk-ZUKDZY54.js.map +1 -0
  17. package/dist/client-dd5c9dd0.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-261eee8f.d.ts → connection-39816c00.d.ts} +1 -1
  21. package/dist/{connection-c1eeb95d.d.ts → connection-40318f22.d.ts} +1 -1
  22. package/dist/{transport-c8f36f6d.d.ts → handshake-e428d1c8.d.ts} +91 -155
  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 +1 -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-ebf80863.d.ts +24 -0
  32. package/dist/{services-524bab79.d.ts → services-f406b3aa.d.ts} +3 -2
  33. package/dist/transport/impls/uds/client.cjs +222 -174
  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 +252 -223
  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 +224 -176
  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 +206 -177
  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 +170 -116
  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 +6 -8
  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 +1 -1
  69. package/dist/chunk-3AW3IXVD.js.map +0 -1
  70. package/dist/chunk-EOJMKMDO.js +0 -1372
  71. package/dist/chunk-EOJMKMDO.js.map +0 -1
  72. package/dist/chunk-ZSKCZYVU.js.map +0 -1
  73. /package/dist/{chunk-T6YEMFUF.js.map → chunk-4QZOW4DH.js.map} +0 -0
  74. /package/dist/{chunk-HM7VDTDJ.js.map → chunk-SX6HI63Q.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
  /**
@@ -141,7 +141,7 @@ declare class Session<ConnType extends Connection> {
141
141
  sendBufferedMessages(conn: ConnType): void;
142
142
  updateBookkeeping(ack: number, seq: number): void;
143
143
  private closeStaleConnection;
144
- replaceWithNewConnection(newConn: ConnType): void;
144
+ replaceWithNewConnection(newConn: ConnType, isTransparentReconnect: boolean): void;
145
145
  replaceWithNewHandshakingConnection(newConn: ConnType): void;
146
146
  beginGrace(cb: () => void): void;
147
147
  cancelGrace(): void;
@@ -244,95 +244,12 @@ declare class LeakyBucketRateLimit {
244
244
  close(): void;
245
245
  }
246
246
 
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;
247
+ type TransportOptions = SessionOptions;
248
+ type ProvidedTransportOptions = Partial<TransportOptions>;
249
+ type ClientTransportOptions = TransportOptions & ConnectionRetryOptions;
250
+ type ProvidedClientTransportOptions = Partial<ClientTransportOptions>;
251
+ type ServerTransportOptions = TransportOptions;
252
+ type ProvidedServerTransportOptions = Partial<ServerTransportOptions>;
336
253
 
337
254
  /**
338
255
  * Represents the possible states of a transport.
@@ -340,12 +257,6 @@ declare function createServerHandshakeOptions<MetadataSchema extends TSchema = T
340
257
  * @property {'closed'} closed - The transport is permanently closed and cannot be reopened.
341
258
  */
342
259
  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
260
  /**
350
261
  * Transports manage the lifecycle (creation/deletion) of sessions and connections. Its responsibilities include:
351
262
  *
@@ -428,7 +339,7 @@ declare abstract class Transport<ConnType extends Connection> {
428
339
  * and we know the identity of the connected client.
429
340
  * @param conn The connection object.
430
341
  */
431
- protected onConnect(conn: ConnType, session: Session<ConnType>, isReconnect: boolean): void;
342
+ protected onConnect(conn: ConnType, session: Session<ConnType>, isTransparentReconnect: boolean): void;
432
343
  protected createSession(to: TransportClientId, conn?: ConnType, propagationCtx?: PropagationContext): Session<ConnType>;
433
344
  protected getOrCreateSession({ to, conn, handshakingConn, sessionId, propagationCtx, }: {
434
345
  to: TransportClientId;
@@ -439,6 +350,7 @@ declare abstract class Transport<ConnType extends Connection> {
439
350
  }): {
440
351
  session: Session<ConnType>;
441
352
  isReconnect: boolean;
353
+ isTransparentReconnect: boolean;
442
354
  };
443
355
  protected deleteSession({ session, closeHandshakingConnection, handshakingConn, }: {
444
356
  session: Session<ConnType>;
@@ -492,71 +404,95 @@ declare abstract class Transport<ConnType extends Connection> {
492
404
  close(): void;
493
405
  getStatus(): TransportStatus;
494
406
  }
495
- declare abstract class ClientTransport<ConnType extends Connection> extends Transport<ConnType> {
496
- /**
497
- * The options for this transport.
498
- */
499
- protected options: ClientTransportOptions;
500
- /**
501
- * The map of reconnect promises for each client ID.
502
- */
503
- inflightConnectionPromises: Map<TransportClientId, Promise<ConnType>>;
504
- retryBudget: LeakyBucketRateLimit;
505
- /**
506
- * A flag indicating whether the transport should automatically reconnect
507
- * when a connection is dropped.
508
- * Realistically, this should always be true for clients unless you are writing
509
- * tests or a special case where you don't want to reconnect.
510
- */
511
- reconnectOnConnectionDrop: boolean;
512
- /**
513
- * Optional handshake options for this client.
514
- */
515
- handshakeExtensions?: ClientHandshakeOptions;
516
- constructor(clientId: TransportClientId, providedOptions?: ProvidedClientTransportOptions);
517
- extendHandshake(options: ClientHandshakeOptions): void;
518
- protected handleConnection(conn: ConnType, to: TransportClientId): void;
519
- receiveHandshakeResponseMessage(data: Uint8Array, conn: ConnType): Session<ConnType> | false;
407
+
408
+ /**
409
+ * The context for services/procedures. This is used only on
410
+ * the server.
411
+ *
412
+ * An important detail is that the state prop is always on
413
+ * this interface and it shouldn't be changed, removed, or
414
+ * extended. This prop is for the state of a service.
415
+ *
416
+ * You should use declaration merging to extend this interface
417
+ * with whatever you need. For example, if you need to access
418
+ * a database, you could do:
419
+ *
420
+ * ```ts
421
+ * declare module '@replit/river' {
422
+ * interface ServiceContext {
423
+ * db: Database;
424
+ * }
425
+ * }
426
+ * ```
427
+ */
428
+ interface ServiceContext {
429
+ }
430
+ /**
431
+ * The parsed metadata schema for a service. This is the
432
+ * return value of the {@link ServerHandshakeOptions.validate}
433
+ * if the handshake extension is used.
434
+
435
+ * You should use declaration merging to extend this interface
436
+ * with the sanitized metadata.
437
+ *
438
+ * ```ts
439
+ * declare module '@replit/river' {
440
+ * interface ParsedMetadata {
441
+ * userId: number;
442
+ * }
443
+ * }
444
+ * ```
445
+ */
446
+ interface ParsedMetadata {
447
+ }
448
+ /**
449
+ * The {@link ServiceContext} with state. This is what is passed to procedures.
450
+ */
451
+ type ServiceContextWithState<State> = ServiceContext & {
452
+ state: State;
453
+ };
454
+ type ServiceContextWithTransportInfo<State> = ServiceContext & {
455
+ state: State;
456
+ to: TransportClientId;
457
+ from: TransportClientId;
458
+ streamId: string;
459
+ session: Session<Connection>;
460
+ metadata: ParsedMetadata;
461
+ };
462
+
463
+ type ConstructHandshake<T extends TSchema> = () => Static<T> | Promise<Static<T>>;
464
+ type ValidateHandshake<T extends TSchema> = (metadata: Static<T>, previousParsedMetadata?: ParsedMetadata) => false | ParsedMetadata | Promise<false | ParsedMetadata>;
465
+ interface ClientHandshakeOptions<MetadataSchema extends TSchema = TSchema> {
520
466
  /**
521
- * Abstract method that creates a new {@link Connection} object.
522
- * This should call {@link handleConnection} when the connection is created.
523
- * The downstream client implementation needs to implement this.
524
- *
525
- * @param to The client ID of the node to connect to.
526
- * @returns The new connection object.
467
+ * Schema for the metadata that the client sends to the server
468
+ * during the handshake.
527
469
  */
528
- protected abstract createNewOutgoingConnection(to: TransportClientId): Promise<ConnType>;
470
+ schema: MetadataSchema;
529
471
  /**
530
- * Manually attempts to connect to a client.
531
- * @param to The client ID of the node to connect to.
472
+ * Gets the {@link HandshakeRequestMetadata} to send to the server.
532
473
  */
533
- connect(to: TransportClientId): Promise<void>;
534
- protected deleteSession({ session, closeHandshakingConnection, handshakingConn, }: {
535
- session: Session<ConnType>;
536
- closeHandshakingConnection: boolean;
537
- handshakingConn?: ConnType;
538
- }): void;
539
- protected sendHandshake(to: TransportClientId, conn: ConnType): Promise<boolean>;
540
- close(): void;
474
+ construct: ConstructHandshake<MetadataSchema>;
541
475
  }
542
- declare abstract class ServerTransport<ConnType extends Connection> extends Transport<ConnType> {
543
- /**
544
- * The options for this transport.
545
- */
546
- protected options: ServerTransportOptions;
476
+ interface ServerHandshakeOptions<MetadataSchema extends TSchema = TSchema> {
547
477
  /**
548
- * Optional handshake options for the server.
478
+ * Schema for the metadata that the server receives from the client
479
+ * during the handshake.
549
480
  */
550
- handshakeExtensions?: ServerHandshakeOptions;
481
+ schema: MetadataSchema;
551
482
  /**
552
- * A map of session handshake data for each session.
483
+ * Parses the {@link HandshakeRequestMetadata} sent by the client, transforming
484
+ * it into {@link ParsedHandshakeMetadata}.
485
+ *
486
+ * May return `false` if the client should be rejected.
487
+ *
488
+ * @param metadata - The metadata sent by the client.
489
+ * @param session - The session that the client would be associated with.
490
+ * @param isReconnect - Whether the client is reconnecting to the session,
491
+ * or if this is a new session.
553
492
  */
554
- sessionHandshakeMetadata: WeakMap<Session<ConnType>, ParsedMetadata>;
555
- constructor(clientId: TransportClientId, providedOptions?: ProvidedServerTransportOptions);
556
- extendHandshake(options: ServerHandshakeOptions): void;
557
- protected handleConnection(conn: ConnType): void;
558
- private validateHandshakeMetadata;
559
- receiveHandshakeRequestMessage(data: Uint8Array, conn: ConnType): Promise<Session<ConnType> | false>;
493
+ validate: ValidateHandshake<MetadataSchema>;
560
494
  }
495
+ declare function createClientHandshakeOptions<MetadataSchema extends TSchema = TSchema>(schema: MetadataSchema, construct: ConstructHandshake<MetadataSchema>): ClientHandshakeOptions;
496
+ declare function createServerHandshakeOptions<MetadataSchema extends TSchema = TSchema>(schema: MetadataSchema, validate: ValidateHandshake<MetadataSchema>): ServerHandshakeOptions;
561
497
 
562
- 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 };
498
+ 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';
@@ -1172,7 +1172,7 @@ function Err(error) {
1172
1172
  var import_api = require("@opentelemetry/api");
1173
1173
 
1174
1174
  // package.json
1175
- var version = "0.23.11";
1175
+ var version = "0.23.13";
1176
1176
 
1177
1177
  // tracing/index.ts
1178
1178
  function getPropagationContext(ctx) {