@replit/river 0.13.2 → 0.13.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. package/dist/{builder-eef3b061.d.ts → builder-6f4630d0.d.ts} +2 -3
  2. package/dist/{chunk-3Y2K543F.js → chunk-5V6B7TM3.js} +1 -1
  3. package/dist/{chunk-67M47YPQ.js → chunk-ASZ3VDCS.js} +1 -2
  4. package/dist/{chunk-23MWJLVJ.js → chunk-FIX2F6VT.js} +1 -1
  5. package/dist/{chunk-NLWRMDT6.js → chunk-MCTB3NYK.js} +13 -10
  6. package/dist/{connection-03e650c8.d.ts → connection-8d0efae0.d.ts} +1 -1
  7. package/dist/{connection-d052d027.d.ts → connection-fe33e684.d.ts} +1 -1
  8. package/dist/{index-9aa0aabb.d.ts → index-5c55c0d3.d.ts} +3 -3
  9. package/dist/router/index.cjs +1 -2
  10. package/dist/router/index.d.cts +3 -3
  11. package/dist/router/index.d.ts +3 -3
  12. package/dist/router/index.js +1 -1
  13. package/dist/transport/impls/uds/client.cjs +12 -9
  14. package/dist/transport/impls/uds/client.d.cts +2 -2
  15. package/dist/transport/impls/uds/client.d.ts +2 -2
  16. package/dist/transport/impls/uds/client.js +2 -2
  17. package/dist/transport/impls/uds/server.cjs +5 -5
  18. package/dist/transport/impls/uds/server.d.cts +2 -2
  19. package/dist/transport/impls/uds/server.d.ts +2 -2
  20. package/dist/transport/impls/uds/server.js +2 -2
  21. package/dist/transport/impls/ws/client.cjs +12 -9
  22. package/dist/transport/impls/ws/client.d.cts +2 -2
  23. package/dist/transport/impls/ws/client.d.ts +2 -2
  24. package/dist/transport/impls/ws/client.js +2 -2
  25. package/dist/transport/impls/ws/server.cjs +5 -5
  26. package/dist/transport/impls/ws/server.d.cts +2 -2
  27. package/dist/transport/impls/ws/server.d.ts +2 -2
  28. package/dist/transport/impls/ws/server.js +2 -2
  29. package/dist/transport/index.cjs +13 -10
  30. package/dist/transport/index.d.cts +1 -1
  31. package/dist/transport/index.d.ts +1 -1
  32. package/dist/transport/index.js +1 -1
  33. package/dist/util/testHelpers.cjs +3 -0
  34. package/dist/util/testHelpers.d.cts +2 -2
  35. package/dist/util/testHelpers.d.ts +2 -2
  36. package/dist/util/testHelpers.js +2 -2
  37. package/package.json +1 -1
@@ -1,6 +1,6 @@
1
1
  import { TObject, TUnion, TString, TSchema, TNever, TLiteral, Static } from '@sinclair/typebox';
2
2
  import { Pushable } from 'it-pushable';
3
- import { b as TransportClientId, d as Session, C as Connection } from './index-9aa0aabb.js';
3
+ import { b as TransportClientId, d as Session, C as Connection } from './index-5c55c0d3.js';
4
4
 
5
5
  /**
6
6
  * The context for services/procedures. This is used only on
@@ -200,9 +200,8 @@ declare class ServiceBuilder<T extends Service<string, object, ProcListing>> {
200
200
  private constructor();
201
201
  /**
202
202
  * Finalizes the schema for the service.
203
- * @returns {T} The finalized schema for the service.
204
203
  */
205
- finalize(): T;
204
+ finalize(): Readonly<T>;
206
205
  /**
207
206
  * Sets the initial state for the service.
208
207
  * @template InitState The type of the initial state.
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  Connection
3
- } from "./chunk-NLWRMDT6.js";
3
+ } from "./chunk-MCTB3NYK.js";
4
4
 
5
5
  // transport/impls/ws/connection.ts
6
6
  var WebSocketConnection = class extends Connection {
@@ -41,10 +41,9 @@ var ServiceBuilder = class _ServiceBuilder {
41
41
  }
42
42
  /**
43
43
  * Finalizes the schema for the service.
44
- * @returns {T} The finalized schema for the service.
45
44
  */
46
45
  finalize() {
47
- return this.schema;
46
+ return Object.freeze(this.schema);
48
47
  }
49
48
  /**
50
49
  * Sets the initial state for the service.
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  Connection
3
- } from "./chunk-NLWRMDT6.js";
3
+ } from "./chunk-MCTB3NYK.js";
4
4
 
5
5
  // transport/transforms/messageFraming.ts
6
6
  import { Transform } from "node:stream";
@@ -213,6 +213,9 @@ var Session = class {
213
213
  this.connection = newConn;
214
214
  }
215
215
  beginGrace(cb) {
216
+ log?.info(
217
+ `${this.from} -- starting ${this.options.sessionDisconnectGraceMs}ms grace period until session (id: ${this.debugId}) to ${this.to} is closed`
218
+ );
216
219
  this.disconnectionGrace = setTimeout(() => {
217
220
  this.close();
218
221
  cb();
@@ -384,14 +387,11 @@ var Transport = class {
384
387
  * @param conn The connection object.
385
388
  * @param connectedTo The peer we are connected to.
386
389
  */
387
- onDisconnect(conn, connectedTo) {
390
+ onDisconnect(conn, session) {
388
391
  this.eventDispatcher.dispatchEvent("connectionStatus", {
389
392
  status: "disconnect",
390
393
  conn
391
394
  });
392
- const session = this.sessions.get(connectedTo);
393
- if (!session)
394
- return;
395
395
  session.connection = void 0;
396
396
  session.beginGrace(() => this.deleteSession(session));
397
397
  }
@@ -549,13 +549,14 @@ var ClientTransport = class extends Transport {
549
549
  this.inflightConnectionPromises = /* @__PURE__ */ new Map();
550
550
  }
551
551
  handleConnection(conn, to) {
552
+ let session = void 0;
552
553
  const handshakeHandler = (data) => {
553
554
  const handshake = this.receiveHandshakeResponseMessage(data);
554
555
  if (!handshake) {
555
556
  conn.close();
556
557
  return;
557
558
  }
558
- this.onConnect(conn, handshake.from, handshake.instanceId);
559
+ session = this.onConnect(conn, handshake.from, handshake.instanceId);
559
560
  conn.removeDataListener(handshakeHandler);
560
561
  conn.addDataListener((data2) => {
561
562
  const parsed = this.parseMsg(data2);
@@ -568,7 +569,9 @@ var ClientTransport = class extends Transport {
568
569
  };
569
570
  conn.addDataListener(handshakeHandler);
570
571
  conn.addCloseListener(() => {
571
- this.onDisconnect(conn, to);
572
+ if (session) {
573
+ this.onDisconnect(conn, session);
574
+ }
572
575
  void this.connect(to);
573
576
  });
574
577
  conn.addErrorListener((err) => {
@@ -651,9 +654,9 @@ var ClientTransport = class extends Transport {
651
654
  log?.debug(`${this.clientId} -- sending handshake request to ${to}`);
652
655
  conn.send(this.codec.toBuffer(requestMsg));
653
656
  }
654
- onDisconnect(conn, connectedTo) {
655
- this.inflightConnectionPromises.delete(connectedTo);
656
- super.onDisconnect(conn, connectedTo);
657
+ onDisconnect(conn, session) {
658
+ this.inflightConnectionPromises.delete(session.to);
659
+ super.onDisconnect(conn, session);
657
660
  }
658
661
  };
659
662
  var ServerTransport = class extends Transport {
@@ -690,7 +693,7 @@ var ServerTransport = class extends Transport {
690
693
  log?.info(
691
694
  `${this.clientId} -- connection (id: ${conn.debugId}) to ${client()} disconnected`
692
695
  );
693
- this.onDisconnect(conn, session.to);
696
+ this.onDisconnect(conn, session);
694
697
  });
695
698
  conn.addErrorListener((err) => {
696
699
  if (!session)
@@ -1,4 +1,4 @@
1
- import { C as Connection } from './index-9aa0aabb.js';
1
+ import { C as Connection } from './index-5c55c0d3.js';
2
2
  import { Socket } from 'node:net';
3
3
  import stream, { Transform, TransformCallback, TransformOptions } from 'node:stream';
4
4
 
@@ -1,5 +1,5 @@
1
1
  import WebSocket from 'isomorphic-ws';
2
- import { C as Connection } from './index-9aa0aabb.js';
2
+ import { C as Connection } from './index-5c55c0d3.js';
3
3
 
4
4
  declare class WebSocketConnection extends Connection {
5
5
  ws: WebSocket;
@@ -336,7 +336,7 @@ declare abstract class Transport<ConnType extends Connection> {
336
336
  * @param conn The connection object.
337
337
  * @param connectedTo The peer we are connected to.
338
338
  */
339
- protected onDisconnect(conn: ConnType, connectedTo: TransportClientId): void;
339
+ protected onDisconnect(conn: ConnType, session: Session<ConnType>): void;
340
340
  /**
341
341
  * Parses a message from a Uint8Array into a {@link OpaqueTransportMessage}.
342
342
  * @param msg The message to parse.
@@ -410,7 +410,7 @@ declare abstract class ClientTransport<ConnType extends Connection> extends Tran
410
410
  */
411
411
  connect(to: TransportClientId, attempt?: number): Promise<void>;
412
412
  protected sendHandshake(to: TransportClientId, conn: ConnType): void;
413
- protected onDisconnect(conn: ConnType, connectedTo: string): void;
413
+ protected onDisconnect(conn: ConnType, session: Session<ConnType>): void;
414
414
  }
415
415
  declare abstract class ServerTransport<ConnType extends Connection> extends Transport<ConnType> {
416
416
  constructor(clientId: TransportClientId, providedOptions?: Partial<TransportOptions>);
@@ -421,4 +421,4 @@ declare abstract class ServerTransport<ConnType extends Connection> extends Tran
421
421
  };
422
422
  }
423
423
 
424
- export { Connection as C, EventMap as E, OpaqueTransportMessage as O, PartialTransportMessage as P, ServerTransport as S, Transport as T, ClientTransport as a, TransportClientId as b, TransportOptions as c, Session as d, TransportMessageSchema as e, OpaqueTransportMessageSchema as f, TransportMessage as g, isStreamClose as h, isStreamOpen as i, EventTypes as j, EventHandler as k };
424
+ export { Connection as C, EventMap as E, OpaqueTransportMessage as O, PartialTransportMessage as P, ServerTransport as S, Transport as T, ClientTransport as a, TransportClientId as b, TransportOptions as c, Session as d, TransportStatus as e, TransportMessageSchema as f, OpaqueTransportMessageSchema as g, TransportMessage as h, isStreamOpen as i, isStreamClose as j, EventTypes as k, EventHandler as l };
@@ -65,10 +65,9 @@ var ServiceBuilder = class _ServiceBuilder {
65
65
  }
66
66
  /**
67
67
  * Finalizes the schema for the service.
68
- * @returns {T} The finalized schema for the service.
69
68
  */
70
69
  finalize() {
71
- return this.schema;
70
+ return Object.freeze(this.schema);
72
71
  }
73
72
  /**
74
73
  * Sets the initial state for the service.
@@ -1,6 +1,6 @@
1
- import { A as AnyService, P as PayloadType, b as Result, R as RiverError, S as ServiceContext, d as ProcType, e as ProcInput, f as ProcOutput, g as ProcErrors, h as ProcHasInit, i as ProcInit } from '../builder-eef3b061.js';
2
- export { E as Err, O as Ok, m as ProcHandler, k as ProcListing, a as Procedure, p as RiverErrorSchema, c as RiverUncaughtSchema, l as Service, j as ServiceBuilder, n as ServiceContextWithState, o as ServiceContextWithTransportInfo, U as UNCAUGHT_ERROR, V as ValidProcType, s as serializeService } from '../builder-eef3b061.js';
3
- import { S as ServerTransport, C as Connection, a as ClientTransport } from '../index-9aa0aabb.js';
1
+ import { A as AnyService, P as PayloadType, b as Result, R as RiverError, S as ServiceContext, d as ProcType, e as ProcInput, f as ProcOutput, g as ProcErrors, h as ProcHasInit, i as ProcInit } from '../builder-6f4630d0.js';
2
+ export { E as Err, O as Ok, m as ProcHandler, k as ProcListing, a as Procedure, p as RiverErrorSchema, c as RiverUncaughtSchema, l as Service, j as ServiceBuilder, n as ServiceContextWithState, o as ServiceContextWithTransportInfo, U as UNCAUGHT_ERROR, V as ValidProcType, s as serializeService } from '../builder-6f4630d0.js';
3
+ import { S as ServerTransport, C as Connection, a as ClientTransport } from '../index-5c55c0d3.js';
4
4
  import { Pushable } from 'it-pushable';
5
5
  import { Static } from '@sinclair/typebox';
6
6
  import '../types-3e5768ec.js';
@@ -1,6 +1,6 @@
1
- import { A as AnyService, P as PayloadType, b as Result, R as RiverError, S as ServiceContext, d as ProcType, e as ProcInput, f as ProcOutput, g as ProcErrors, h as ProcHasInit, i as ProcInit } from '../builder-eef3b061.js';
2
- export { E as Err, O as Ok, m as ProcHandler, k as ProcListing, a as Procedure, p as RiverErrorSchema, c as RiverUncaughtSchema, l as Service, j as ServiceBuilder, n as ServiceContextWithState, o as ServiceContextWithTransportInfo, U as UNCAUGHT_ERROR, V as ValidProcType, s as serializeService } from '../builder-eef3b061.js';
3
- import { S as ServerTransport, C as Connection, a as ClientTransport } from '../index-9aa0aabb.js';
1
+ import { A as AnyService, P as PayloadType, b as Result, R as RiverError, S as ServiceContext, d as ProcType, e as ProcInput, f as ProcOutput, g as ProcErrors, h as ProcHasInit, i as ProcInit } from '../builder-6f4630d0.js';
2
+ export { E as Err, O as Ok, m as ProcHandler, k as ProcListing, a as Procedure, p as RiverErrorSchema, c as RiverUncaughtSchema, l as Service, j as ServiceBuilder, n as ServiceContextWithState, o as ServiceContextWithTransportInfo, U as UNCAUGHT_ERROR, V as ValidProcType, s as serializeService } from '../builder-6f4630d0.js';
3
+ import { S as ServerTransport, C as Connection, a as ClientTransport } from '../index-5c55c0d3.js';
4
4
  import { Pushable } from 'it-pushable';
5
5
  import { Static } from '@sinclair/typebox';
6
6
  import '../types-3e5768ec.js';
@@ -8,7 +8,7 @@ import {
8
8
  createClient,
9
9
  createServer,
10
10
  serializeService
11
- } from "../chunk-67M47YPQ.js";
11
+ } from "../chunk-ASZ3VDCS.js";
12
12
  import "../chunk-GFRAOY75.js";
13
13
  import "../chunk-H4BYJELI.js";
14
14
  export {
@@ -321,6 +321,9 @@ var Session = class {
321
321
  this.connection = newConn;
322
322
  }
323
323
  beginGrace(cb) {
324
+ log?.info(
325
+ `${this.from} -- starting ${this.options.sessionDisconnectGraceMs}ms grace period until session (id: ${this.debugId}) to ${this.to} is closed`
326
+ );
324
327
  this.disconnectionGrace = setTimeout(() => {
325
328
  this.close();
326
329
  cb();
@@ -625,14 +628,11 @@ var Transport = class {
625
628
  * @param conn The connection object.
626
629
  * @param connectedTo The peer we are connected to.
627
630
  */
628
- onDisconnect(conn, connectedTo) {
631
+ onDisconnect(conn, session) {
629
632
  this.eventDispatcher.dispatchEvent("connectionStatus", {
630
633
  status: "disconnect",
631
634
  conn
632
635
  });
633
- const session = this.sessions.get(connectedTo);
634
- if (!session)
635
- return;
636
636
  session.connection = void 0;
637
637
  session.beginGrace(() => this.deleteSession(session));
638
638
  }
@@ -790,13 +790,14 @@ var ClientTransport = class extends Transport {
790
790
  this.inflightConnectionPromises = /* @__PURE__ */ new Map();
791
791
  }
792
792
  handleConnection(conn, to) {
793
+ let session = void 0;
793
794
  const handshakeHandler = (data) => {
794
795
  const handshake = this.receiveHandshakeResponseMessage(data);
795
796
  if (!handshake) {
796
797
  conn.close();
797
798
  return;
798
799
  }
799
- this.onConnect(conn, handshake.from, handshake.instanceId);
800
+ session = this.onConnect(conn, handshake.from, handshake.instanceId);
800
801
  conn.removeDataListener(handshakeHandler);
801
802
  conn.addDataListener((data2) => {
802
803
  const parsed = this.parseMsg(data2);
@@ -809,7 +810,9 @@ var ClientTransport = class extends Transport {
809
810
  };
810
811
  conn.addDataListener(handshakeHandler);
811
812
  conn.addCloseListener(() => {
812
- this.onDisconnect(conn, to);
813
+ if (session) {
814
+ this.onDisconnect(conn, session);
815
+ }
813
816
  void this.connect(to);
814
817
  });
815
818
  conn.addErrorListener((err) => {
@@ -892,9 +895,9 @@ var ClientTransport = class extends Transport {
892
895
  log?.debug(`${this.clientId} -- sending handshake request to ${to}`);
893
896
  conn.send(this.codec.toBuffer(requestMsg));
894
897
  }
895
- onDisconnect(conn, connectedTo) {
896
- this.inflightConnectionPromises.delete(connectedTo);
897
- super.onDisconnect(conn, connectedTo);
898
+ onDisconnect(conn, session) {
899
+ this.inflightConnectionPromises.delete(session.to);
900
+ super.onDisconnect(conn, session);
898
901
  }
899
902
  };
900
903
 
@@ -1,5 +1,5 @@
1
- import { a as ClientTransport, b as TransportClientId, c as TransportOptions } from '../../../index-9aa0aabb.js';
2
- import { U as UdsConnection } from '../../../connection-03e650c8.js';
1
+ import { a as ClientTransport, b as TransportClientId, c as TransportOptions } from '../../../index-5c55c0d3.js';
2
+ import { U as UdsConnection } from '../../../connection-8d0efae0.js';
3
3
  import '../../../types-3e5768ec.js';
4
4
  import '@sinclair/typebox';
5
5
  import 'node:net';
@@ -1,5 +1,5 @@
1
- import { a as ClientTransport, b as TransportClientId, c as TransportOptions } from '../../../index-9aa0aabb.js';
2
- import { U as UdsConnection } from '../../../connection-03e650c8.js';
1
+ import { a as ClientTransport, b as TransportClientId, c as TransportOptions } from '../../../index-5c55c0d3.js';
2
+ import { U as UdsConnection } from '../../../connection-8d0efae0.js';
3
3
  import '../../../types-3e5768ec.js';
4
4
  import '@sinclair/typebox';
5
5
  import 'node:net';
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  UdsConnection
3
- } from "../../../chunk-23MWJLVJ.js";
3
+ } from "../../../chunk-FIX2F6VT.js";
4
4
  import {
5
5
  ClientTransport
6
- } from "../../../chunk-NLWRMDT6.js";
6
+ } from "../../../chunk-MCTB3NYK.js";
7
7
  import "../../../chunk-GFRAOY75.js";
8
8
  import {
9
9
  log
@@ -359,6 +359,9 @@ var Session = class {
359
359
  this.connection = newConn;
360
360
  }
361
361
  beginGrace(cb) {
362
+ log?.info(
363
+ `${this.from} -- starting ${this.options.sessionDisconnectGraceMs}ms grace period until session (id: ${this.debugId}) to ${this.to} is closed`
364
+ );
362
365
  this.disconnectionGrace = setTimeout(() => {
363
366
  this.close();
364
367
  cb();
@@ -539,14 +542,11 @@ var Transport = class {
539
542
  * @param conn The connection object.
540
543
  * @param connectedTo The peer we are connected to.
541
544
  */
542
- onDisconnect(conn, connectedTo) {
545
+ onDisconnect(conn, session) {
543
546
  this.eventDispatcher.dispatchEvent("connectionStatus", {
544
547
  status: "disconnect",
545
548
  conn
546
549
  });
547
- const session = this.sessions.get(connectedTo);
548
- if (!session)
549
- return;
550
550
  session.connection = void 0;
551
551
  session.beginGrace(() => this.deleteSession(session));
552
552
  }
@@ -725,7 +725,7 @@ var ServerTransport = class extends Transport {
725
725
  log?.info(
726
726
  `${this.clientId} -- connection (id: ${conn.debugId}) to ${client()} disconnected`
727
727
  );
728
- this.onDisconnect(conn, session.to);
728
+ this.onDisconnect(conn, session);
729
729
  });
730
730
  conn.addErrorListener((err) => {
731
731
  if (!session)
@@ -1,6 +1,6 @@
1
1
  import { Server, Socket } from 'node:net';
2
- import { S as ServerTransport, b as TransportClientId, c as TransportOptions } from '../../../index-9aa0aabb.js';
3
- import { U as UdsConnection } from '../../../connection-03e650c8.js';
2
+ import { S as ServerTransport, b as TransportClientId, c as TransportOptions } from '../../../index-5c55c0d3.js';
3
+ import { U as UdsConnection } from '../../../connection-8d0efae0.js';
4
4
  import '../../../types-3e5768ec.js';
5
5
  import '@sinclair/typebox';
6
6
  import 'node:stream';
@@ -1,6 +1,6 @@
1
1
  import { Server, Socket } from 'node:net';
2
- import { S as ServerTransport, b as TransportClientId, c as TransportOptions } from '../../../index-9aa0aabb.js';
3
- import { U as UdsConnection } from '../../../connection-03e650c8.js';
2
+ import { S as ServerTransport, b as TransportClientId, c as TransportOptions } from '../../../index-5c55c0d3.js';
3
+ import { U as UdsConnection } from '../../../connection-8d0efae0.js';
4
4
  import '../../../types-3e5768ec.js';
5
5
  import '@sinclair/typebox';
6
6
  import 'node:stream';
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  UdsConnection
3
- } from "../../../chunk-23MWJLVJ.js";
3
+ } from "../../../chunk-FIX2F6VT.js";
4
4
  import {
5
5
  ServerTransport
6
- } from "../../../chunk-NLWRMDT6.js";
6
+ } from "../../../chunk-MCTB3NYK.js";
7
7
  import "../../../chunk-GFRAOY75.js";
8
8
  import {
9
9
  log
@@ -351,6 +351,9 @@ var Session = class {
351
351
  this.connection = newConn;
352
352
  }
353
353
  beginGrace(cb) {
354
+ log?.info(
355
+ `${this.from} -- starting ${this.options.sessionDisconnectGraceMs}ms grace period until session (id: ${this.debugId}) to ${this.to} is closed`
356
+ );
354
357
  this.disconnectionGrace = setTimeout(() => {
355
358
  this.close();
356
359
  cb();
@@ -531,14 +534,11 @@ var Transport = class {
531
534
  * @param conn The connection object.
532
535
  * @param connectedTo The peer we are connected to.
533
536
  */
534
- onDisconnect(conn, connectedTo) {
537
+ onDisconnect(conn, session) {
535
538
  this.eventDispatcher.dispatchEvent("connectionStatus", {
536
539
  status: "disconnect",
537
540
  conn
538
541
  });
539
- const session = this.sessions.get(connectedTo);
540
- if (!session)
541
- return;
542
542
  session.connection = void 0;
543
543
  session.beginGrace(() => this.deleteSession(session));
544
544
  }
@@ -696,13 +696,14 @@ var ClientTransport = class extends Transport {
696
696
  this.inflightConnectionPromises = /* @__PURE__ */ new Map();
697
697
  }
698
698
  handleConnection(conn, to) {
699
+ let session = void 0;
699
700
  const handshakeHandler = (data) => {
700
701
  const handshake = this.receiveHandshakeResponseMessage(data);
701
702
  if (!handshake) {
702
703
  conn.close();
703
704
  return;
704
705
  }
705
- this.onConnect(conn, handshake.from, handshake.instanceId);
706
+ session = this.onConnect(conn, handshake.from, handshake.instanceId);
706
707
  conn.removeDataListener(handshakeHandler);
707
708
  conn.addDataListener((data2) => {
708
709
  const parsed = this.parseMsg(data2);
@@ -715,7 +716,9 @@ var ClientTransport = class extends Transport {
715
716
  };
716
717
  conn.addDataListener(handshakeHandler);
717
718
  conn.addCloseListener(() => {
718
- this.onDisconnect(conn, to);
719
+ if (session) {
720
+ this.onDisconnect(conn, session);
721
+ }
719
722
  void this.connect(to);
720
723
  });
721
724
  conn.addErrorListener((err) => {
@@ -798,9 +801,9 @@ var ClientTransport = class extends Transport {
798
801
  log?.debug(`${this.clientId} -- sending handshake request to ${to}`);
799
802
  conn.send(this.codec.toBuffer(requestMsg));
800
803
  }
801
- onDisconnect(conn, connectedTo) {
802
- this.inflightConnectionPromises.delete(connectedTo);
803
- super.onDisconnect(conn, connectedTo);
804
+ onDisconnect(conn, session) {
805
+ this.inflightConnectionPromises.delete(session.to);
806
+ super.onDisconnect(conn, session);
804
807
  }
805
808
  };
806
809
 
@@ -1,6 +1,6 @@
1
1
  import WebSocket from 'isomorphic-ws';
2
- import { a as ClientTransport, b as TransportClientId, c as TransportOptions } from '../../../index-9aa0aabb.js';
3
- import { W as WebSocketConnection } from '../../../connection-d052d027.js';
2
+ import { a as ClientTransport, b as TransportClientId, c as TransportOptions } from '../../../index-5c55c0d3.js';
3
+ import { W as WebSocketConnection } from '../../../connection-fe33e684.js';
4
4
  import '../../../types-3e5768ec.js';
5
5
  import '@sinclair/typebox';
6
6
 
@@ -1,6 +1,6 @@
1
1
  import WebSocket from 'isomorphic-ws';
2
- import { a as ClientTransport, b as TransportClientId, c as TransportOptions } from '../../../index-9aa0aabb.js';
3
- import { W as WebSocketConnection } from '../../../connection-d052d027.js';
2
+ import { a as ClientTransport, b as TransportClientId, c as TransportOptions } from '../../../index-5c55c0d3.js';
3
+ import { W as WebSocketConnection } from '../../../connection-fe33e684.js';
4
4
  import '../../../types-3e5768ec.js';
5
5
  import '@sinclair/typebox';
6
6
 
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  WebSocketConnection
3
- } from "../../../chunk-3Y2K543F.js";
3
+ } from "../../../chunk-5V6B7TM3.js";
4
4
  import {
5
5
  ClientTransport
6
- } from "../../../chunk-NLWRMDT6.js";
6
+ } from "../../../chunk-MCTB3NYK.js";
7
7
  import "../../../chunk-GFRAOY75.js";
8
8
  import {
9
9
  log
@@ -359,6 +359,9 @@ var Session = class {
359
359
  this.connection = newConn;
360
360
  }
361
361
  beginGrace(cb) {
362
+ log?.info(
363
+ `${this.from} -- starting ${this.options.sessionDisconnectGraceMs}ms grace period until session (id: ${this.debugId}) to ${this.to} is closed`
364
+ );
362
365
  this.disconnectionGrace = setTimeout(() => {
363
366
  this.close();
364
367
  cb();
@@ -539,14 +542,11 @@ var Transport = class {
539
542
  * @param conn The connection object.
540
543
  * @param connectedTo The peer we are connected to.
541
544
  */
542
- onDisconnect(conn, connectedTo) {
545
+ onDisconnect(conn, session) {
543
546
  this.eventDispatcher.dispatchEvent("connectionStatus", {
544
547
  status: "disconnect",
545
548
  conn
546
549
  });
547
- const session = this.sessions.get(connectedTo);
548
- if (!session)
549
- return;
550
550
  session.connection = void 0;
551
551
  session.beginGrace(() => this.deleteSession(session));
552
552
  }
@@ -725,7 +725,7 @@ var ServerTransport = class extends Transport {
725
725
  log?.info(
726
726
  `${this.clientId} -- connection (id: ${conn.debugId}) to ${client()} disconnected`
727
727
  );
728
- this.onDisconnect(conn, session.to);
728
+ this.onDisconnect(conn, session);
729
729
  });
730
730
  conn.addErrorListener((err) => {
731
731
  if (!session)
@@ -1,7 +1,7 @@
1
- import { S as ServerTransport, b as TransportClientId, c as TransportOptions } from '../../../index-9aa0aabb.js';
1
+ import { S as ServerTransport, b as TransportClientId, c as TransportOptions } from '../../../index-5c55c0d3.js';
2
2
  import { WebSocketServer } from 'ws';
3
3
  import { WebSocket } from 'isomorphic-ws';
4
- import { W as WebSocketConnection } from '../../../connection-d052d027.js';
4
+ import { W as WebSocketConnection } from '../../../connection-fe33e684.js';
5
5
  import '../../../types-3e5768ec.js';
6
6
  import '@sinclair/typebox';
7
7
 
@@ -1,7 +1,7 @@
1
- import { S as ServerTransport, b as TransportClientId, c as TransportOptions } from '../../../index-9aa0aabb.js';
1
+ import { S as ServerTransport, b as TransportClientId, c as TransportOptions } from '../../../index-5c55c0d3.js';
2
2
  import { WebSocketServer } from 'ws';
3
3
  import { WebSocket } from 'isomorphic-ws';
4
- import { W as WebSocketConnection } from '../../../connection-d052d027.js';
4
+ import { W as WebSocketConnection } from '../../../connection-fe33e684.js';
5
5
  import '../../../types-3e5768ec.js';
6
6
  import '@sinclair/typebox';
7
7
 
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  WebSocketConnection
3
- } from "../../../chunk-3Y2K543F.js";
3
+ } from "../../../chunk-5V6B7TM3.js";
4
4
  import {
5
5
  ServerTransport
6
- } from "../../../chunk-NLWRMDT6.js";
6
+ } from "../../../chunk-MCTB3NYK.js";
7
7
  import "../../../chunk-GFRAOY75.js";
8
8
  import {
9
9
  log
@@ -381,6 +381,9 @@ var Session = class {
381
381
  this.connection = newConn;
382
382
  }
383
383
  beginGrace(cb) {
384
+ log?.info(
385
+ `${this.from} -- starting ${this.options.sessionDisconnectGraceMs}ms grace period until session (id: ${this.debugId}) to ${this.to} is closed`
386
+ );
384
387
  this.disconnectionGrace = setTimeout(() => {
385
388
  this.close();
386
389
  cb();
@@ -561,14 +564,11 @@ var Transport = class {
561
564
  * @param conn The connection object.
562
565
  * @param connectedTo The peer we are connected to.
563
566
  */
564
- onDisconnect(conn, connectedTo) {
567
+ onDisconnect(conn, session) {
565
568
  this.eventDispatcher.dispatchEvent("connectionStatus", {
566
569
  status: "disconnect",
567
570
  conn
568
571
  });
569
- const session = this.sessions.get(connectedTo);
570
- if (!session)
571
- return;
572
572
  session.connection = void 0;
573
573
  session.beginGrace(() => this.deleteSession(session));
574
574
  }
@@ -726,13 +726,14 @@ var ClientTransport = class extends Transport {
726
726
  this.inflightConnectionPromises = /* @__PURE__ */ new Map();
727
727
  }
728
728
  handleConnection(conn, to) {
729
+ let session = void 0;
729
730
  const handshakeHandler = (data) => {
730
731
  const handshake = this.receiveHandshakeResponseMessage(data);
731
732
  if (!handshake) {
732
733
  conn.close();
733
734
  return;
734
735
  }
735
- this.onConnect(conn, handshake.from, handshake.instanceId);
736
+ session = this.onConnect(conn, handshake.from, handshake.instanceId);
736
737
  conn.removeDataListener(handshakeHandler);
737
738
  conn.addDataListener((data2) => {
738
739
  const parsed = this.parseMsg(data2);
@@ -745,7 +746,9 @@ var ClientTransport = class extends Transport {
745
746
  };
746
747
  conn.addDataListener(handshakeHandler);
747
748
  conn.addCloseListener(() => {
748
- this.onDisconnect(conn, to);
749
+ if (session) {
750
+ this.onDisconnect(conn, session);
751
+ }
749
752
  void this.connect(to);
750
753
  });
751
754
  conn.addErrorListener((err) => {
@@ -828,9 +831,9 @@ var ClientTransport = class extends Transport {
828
831
  log?.debug(`${this.clientId} -- sending handshake request to ${to}`);
829
832
  conn.send(this.codec.toBuffer(requestMsg));
830
833
  }
831
- onDisconnect(conn, connectedTo) {
832
- this.inflightConnectionPromises.delete(connectedTo);
833
- super.onDisconnect(conn, connectedTo);
834
+ onDisconnect(conn, session) {
835
+ this.inflightConnectionPromises.delete(session.to);
836
+ super.onDisconnect(conn, session);
834
837
  }
835
838
  };
836
839
  var ServerTransport = class extends Transport {
@@ -867,7 +870,7 @@ var ServerTransport = class extends Transport {
867
870
  log?.info(
868
871
  `${this.clientId} -- connection (id: ${conn.debugId}) to ${client()} disconnected`
869
872
  );
870
- this.onDisconnect(conn, session.to);
873
+ this.onDisconnect(conn, session);
871
874
  });
872
875
  conn.addErrorListener((err) => {
873
876
  if (!session)
@@ -1,3 +1,3 @@
1
- export { a as ClientTransport, C as Connection, k as EventHandler, E as EventMap, j as EventTypes, O as OpaqueTransportMessage, f as OpaqueTransportMessageSchema, S as ServerTransport, d as Session, T as Transport, b as TransportClientId, g as TransportMessage, e as TransportMessageSchema, h as isStreamClose, i as isStreamOpen } from '../index-9aa0aabb.js';
1
+ export { a as ClientTransport, C as Connection, l as EventHandler, E as EventMap, k as EventTypes, O as OpaqueTransportMessage, g as OpaqueTransportMessageSchema, S as ServerTransport, d as Session, T as Transport, b as TransportClientId, h as TransportMessage, f as TransportMessageSchema, c as TransportOptions, e as TransportStatus, j as isStreamClose, i as isStreamOpen } from '../index-5c55c0d3.js';
2
2
  import '../types-3e5768ec.js';
3
3
  import '@sinclair/typebox';
@@ -1,3 +1,3 @@
1
- export { a as ClientTransport, C as Connection, k as EventHandler, E as EventMap, j as EventTypes, O as OpaqueTransportMessage, f as OpaqueTransportMessageSchema, S as ServerTransport, d as Session, T as Transport, b as TransportClientId, g as TransportMessage, e as TransportMessageSchema, h as isStreamClose, i as isStreamOpen } from '../index-9aa0aabb.js';
1
+ export { a as ClientTransport, C as Connection, l as EventHandler, E as EventMap, k as EventTypes, O as OpaqueTransportMessage, g as OpaqueTransportMessageSchema, S as ServerTransport, d as Session, T as Transport, b as TransportClientId, h as TransportMessage, f as TransportMessageSchema, c as TransportOptions, e as TransportStatus, j as isStreamClose, i as isStreamOpen } from '../index-5c55c0d3.js';
2
2
  import '../types-3e5768ec.js';
3
3
  import '@sinclair/typebox';
@@ -5,7 +5,7 @@ import {
5
5
  ServerTransport,
6
6
  Session,
7
7
  Transport
8
- } from "../chunk-NLWRMDT6.js";
8
+ } from "../chunk-MCTB3NYK.js";
9
9
  import {
10
10
  OpaqueTransportMessageSchema,
11
11
  TransportMessageSchema
@@ -269,6 +269,9 @@ var Session = class {
269
269
  this.connection = newConn;
270
270
  }
271
271
  beginGrace(cb) {
272
+ log?.info(
273
+ `${this.from} -- starting ${this.options.sessionDisconnectGraceMs}ms grace period until session (id: ${this.debugId}) to ${this.to} is closed`
274
+ );
272
275
  this.disconnectionGrace = setTimeout(() => {
273
276
  this.close();
274
277
  cb();
@@ -1,8 +1,8 @@
1
1
  import * as it_pushable from 'it-pushable';
2
2
  import WebSocket from 'isomorphic-ws';
3
3
  import http from 'node:http';
4
- import { P as PartialTransportMessage, T as Transport, C as Connection, O as OpaqueTransportMessage } from '../index-9aa0aabb.js';
5
- import { P as PayloadType, R as RiverError, a as Procedure, S as ServiceContext, b as Result, c as RiverUncaughtSchema } from '../builder-eef3b061.js';
4
+ import { P as PartialTransportMessage, T as Transport, C as Connection, O as OpaqueTransportMessage } from '../index-5c55c0d3.js';
5
+ import { P as PayloadType, R as RiverError, a as Procedure, S as ServiceContext, b as Result, c as RiverUncaughtSchema } from '../builder-6f4630d0.js';
6
6
  import { Static } from '@sinclair/typebox';
7
7
  import net from 'node:net';
8
8
  import '../types-3e5768ec.js';
@@ -1,8 +1,8 @@
1
1
  import * as it_pushable from 'it-pushable';
2
2
  import WebSocket from 'isomorphic-ws';
3
3
  import http from 'node:http';
4
- import { P as PartialTransportMessage, T as Transport, C as Connection, O as OpaqueTransportMessage } from '../index-9aa0aabb.js';
5
- import { P as PayloadType, R as RiverError, a as Procedure, S as ServiceContext, b as Result, c as RiverUncaughtSchema } from '../builder-eef3b061.js';
4
+ import { P as PartialTransportMessage, T as Transport, C as Connection, O as OpaqueTransportMessage } from '../index-5c55c0d3.js';
5
+ import { P as PayloadType, R as RiverError, a as Procedure, S as ServiceContext, b as Result, c as RiverUncaughtSchema } from '../builder-6f4630d0.js';
6
6
  import { Static } from '@sinclair/typebox';
7
7
  import net from 'node:net';
8
8
  import '../types-3e5768ec.js';
@@ -1,12 +1,12 @@
1
1
  import {
2
2
  UNCAUGHT_ERROR,
3
3
  pushable
4
- } from "../chunk-67M47YPQ.js";
4
+ } from "../chunk-ASZ3VDCS.js";
5
5
  import "../chunk-5IZ2UHWV.js";
6
6
  import {
7
7
  Session,
8
8
  defaultSessionOptions
9
- } from "../chunk-NLWRMDT6.js";
9
+ } from "../chunk-MCTB3NYK.js";
10
10
  import {
11
11
  coerceErrorString
12
12
  } from "../chunk-GFRAOY75.js";
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.13.2",
4
+ "version": "0.13.4",
5
5
  "type": "module",
6
6
  "exports": {
7
7
  ".": {