@replit/river 0.26.1 → 0.26.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.
Files changed (48) hide show
  1. package/dist/{chunk-AYIMQWS7.js → chunk-AWCUCZY4.js} +2 -2
  2. package/dist/{chunk-XRI2BXMM.js → chunk-IV27BICV.js} +17 -4
  3. package/dist/chunk-IV27BICV.js.map +1 -0
  4. package/dist/{chunk-6UVTCZ6K.js → chunk-M5X4JTU3.js} +3 -3
  5. package/dist/{chunk-6UVTCZ6K.js.map → chunk-M5X4JTU3.js.map} +1 -1
  6. package/dist/{chunk-UQOD22AN.js → chunk-M75K5TJS.js} +2 -2
  7. package/dist/{chunk-UQOD22AN.js.map → chunk-M75K5TJS.js.map} +1 -1
  8. package/dist/{chunk-4W5LENT2.js → chunk-MREEJE3X.js} +2 -2
  9. package/dist/{chunk-M43R4RPL.js → chunk-NC54BC47.js} +90 -33
  10. package/dist/chunk-NC54BC47.js.map +1 -0
  11. package/dist/{chunk-IVNX5H6C.js → chunk-YQABPD3C.js} +14 -10
  12. package/dist/chunk-YQABPD3C.js.map +1 -0
  13. package/dist/{client-0f636b3a.d.ts → client-654098be.d.ts} +1 -3
  14. package/dist/{connection-07e97a79.d.ts → connection-bc2454dc.d.ts} +1 -1
  15. package/dist/{handshake-8752f79e.d.ts → handshake-1a86f06d.d.ts} +52 -38
  16. package/dist/router/index.cjs +1 -1
  17. package/dist/router/index.cjs.map +1 -1
  18. package/dist/router/index.d.cts +7 -7
  19. package/dist/router/index.d.ts +7 -7
  20. package/dist/router/index.js +2 -2
  21. package/dist/{server-e304daec.d.ts → server-9a6b5a8e.d.ts} +12 -4
  22. package/dist/{services-fc99aae1.d.ts → services-7daa60a0.d.ts} +2 -2
  23. package/dist/transport/impls/ws/client.cjs +102 -32
  24. package/dist/transport/impls/ws/client.cjs.map +1 -1
  25. package/dist/transport/impls/ws/client.d.cts +3 -3
  26. package/dist/transport/impls/ws/client.d.ts +3 -3
  27. package/dist/transport/impls/ws/client.js +5 -5
  28. package/dist/transport/impls/ws/server.cjs +99 -38
  29. package/dist/transport/impls/ws/server.cjs.map +1 -1
  30. package/dist/transport/impls/ws/server.d.cts +3 -3
  31. package/dist/transport/impls/ws/server.d.ts +3 -3
  32. package/dist/transport/impls/ws/server.js +5 -5
  33. package/dist/transport/index.cjs +112 -38
  34. package/dist/transport/index.cjs.map +1 -1
  35. package/dist/transport/index.d.cts +3 -3
  36. package/dist/transport/index.d.ts +3 -3
  37. package/dist/transport/index.js +5 -5
  38. package/dist/util/testHelpers.cjs +89 -32
  39. package/dist/util/testHelpers.cjs.map +1 -1
  40. package/dist/util/testHelpers.d.cts +3 -3
  41. package/dist/util/testHelpers.d.ts +3 -3
  42. package/dist/util/testHelpers.js +3 -3
  43. package/package.json +1 -1
  44. package/dist/chunk-IVNX5H6C.js.map +0 -1
  45. package/dist/chunk-M43R4RPL.js.map +0 -1
  46. package/dist/chunk-XRI2BXMM.js.map +0 -1
  47. /package/dist/{chunk-AYIMQWS7.js.map → chunk-AWCUCZY4.js.map} +0 -0
  48. /package/dist/{chunk-4W5LENT2.js.map → chunk-MREEJE3X.js.map} +0 -0
@@ -1,14 +1,14 @@
1
- import { A as AnyServiceSchemaMap, I as InstantiatedServiceSchemaMap, P as PayloadType, b as Result, R as RiverError } from '../services-fc99aae1.js';
2
- export { C as Client, E as Err, O as Ok, z as Output, j as ProcErrors, f as ProcHandler, g as ProcInit, h as ProcInput, i as ProcOutput, k as ProcType, a as Procedure, p as ProcedureMap, d as ProcedureResult, q as RPCProcedure, y as ResultUnwrapErr, x as ResultUnwrapOk, w as RiverErrorSchema, c as RiverUncaughtSchema, o as SerializedProcedureSchema, m as SerializedServerSchema, n as SerializedServiceSchema, S as Service, e as ServiceConfiguration, l as ServiceSchema, t as StreamProcedure, r as SubscriptionProcedure, v as UNCAUGHT_ERROR, U as UploadProcedure, V as ValidProcType, u as createClient, s as serializeSchema } from '../services-fc99aae1.js';
1
+ import { A as AnyServiceSchemaMap, I as InstantiatedServiceSchemaMap, P as PayloadType, b as Result, R as RiverError } from '../services-7daa60a0.js';
2
+ export { C as Client, E as Err, O as Ok, z as Output, j as ProcErrors, f as ProcHandler, g as ProcInit, h as ProcInput, i as ProcOutput, k as ProcType, a as Procedure, p as ProcedureMap, d as ProcedureResult, q as RPCProcedure, y as ResultUnwrapErr, x as ResultUnwrapOk, w as RiverErrorSchema, c as RiverUncaughtSchema, o as SerializedProcedureSchema, m as SerializedServerSchema, n as SerializedServiceSchema, S as Service, e as ServiceConfiguration, l as ServiceSchema, t as StreamProcedure, r as SubscriptionProcedure, v as UNCAUGHT_ERROR, U as UploadProcedure, V as ValidProcType, u as createClient, s as serializeSchema } from '../services-7daa60a0.js';
3
3
  import { Static } from '@sinclair/typebox';
4
4
  import { Pushable } from 'it-pushable';
5
- import { C as Connection, s as ServerHandshakeOptions, o as ServiceContext } from '../handshake-8752f79e.js';
6
- export { t as ParsedMetadata, u as ServiceContextWithState, v as ServiceContextWithTransportInfo, w as createClientHandshakeOptions, x as createServerHandshakeOptions } from '../handshake-8752f79e.js';
7
- import { S as ServerTransport } from '../server-e304daec.js';
5
+ import { C as Connection, s as ServerHandshakeOptions, o as ServiceContext } from '../handshake-1a86f06d.js';
6
+ export { t as ParsedMetadata, u as ServiceContextWithState, v as ServiceContextWithTransportInfo, w as createClientHandshakeOptions, x as createServerHandshakeOptions } from '../handshake-1a86f06d.js';
7
+ import { S as ServerTransport } from '../server-9a6b5a8e.js';
8
8
  import '../message-57296605.js';
9
9
  import '@sinclair/typebox/value';
10
10
  import '@opentelemetry/api';
11
- import '../client-0f636b3a.js';
11
+ import '../client-654098be.js';
12
12
  import '../types-3e5768ec.js';
13
13
 
14
14
  /**
@@ -45,6 +45,6 @@ declare function createServer<Services extends AnyServiceSchemaMap>(transport: S
45
45
  extendedContext?: Omit<ServiceContext, 'state'>;
46
46
  }>): Server<Services>;
47
47
 
48
- var version = "0.26.1";
48
+ var version = "0.26.2";
49
49
 
50
50
  export { PayloadType, version as RIVER_VERSION, Result, RiverError, Server, ServiceContext, createServer };
@@ -1,14 +1,14 @@
1
- import { A as AnyServiceSchemaMap, I as InstantiatedServiceSchemaMap, P as PayloadType, b as Result, R as RiverError } from '../services-fc99aae1.js';
2
- export { C as Client, E as Err, O as Ok, z as Output, j as ProcErrors, f as ProcHandler, g as ProcInit, h as ProcInput, i as ProcOutput, k as ProcType, a as Procedure, p as ProcedureMap, d as ProcedureResult, q as RPCProcedure, y as ResultUnwrapErr, x as ResultUnwrapOk, w as RiverErrorSchema, c as RiverUncaughtSchema, o as SerializedProcedureSchema, m as SerializedServerSchema, n as SerializedServiceSchema, S as Service, e as ServiceConfiguration, l as ServiceSchema, t as StreamProcedure, r as SubscriptionProcedure, v as UNCAUGHT_ERROR, U as UploadProcedure, V as ValidProcType, u as createClient, s as serializeSchema } from '../services-fc99aae1.js';
1
+ import { A as AnyServiceSchemaMap, I as InstantiatedServiceSchemaMap, P as PayloadType, b as Result, R as RiverError } from '../services-7daa60a0.js';
2
+ export { C as Client, E as Err, O as Ok, z as Output, j as ProcErrors, f as ProcHandler, g as ProcInit, h as ProcInput, i as ProcOutput, k as ProcType, a as Procedure, p as ProcedureMap, d as ProcedureResult, q as RPCProcedure, y as ResultUnwrapErr, x as ResultUnwrapOk, w as RiverErrorSchema, c as RiverUncaughtSchema, o as SerializedProcedureSchema, m as SerializedServerSchema, n as SerializedServiceSchema, S as Service, e as ServiceConfiguration, l as ServiceSchema, t as StreamProcedure, r as SubscriptionProcedure, v as UNCAUGHT_ERROR, U as UploadProcedure, V as ValidProcType, u as createClient, s as serializeSchema } from '../services-7daa60a0.js';
3
3
  import { Static } from '@sinclair/typebox';
4
4
  import { Pushable } from 'it-pushable';
5
- import { C as Connection, s as ServerHandshakeOptions, o as ServiceContext } from '../handshake-8752f79e.js';
6
- export { t as ParsedMetadata, u as ServiceContextWithState, v as ServiceContextWithTransportInfo, w as createClientHandshakeOptions, x as createServerHandshakeOptions } from '../handshake-8752f79e.js';
7
- import { S as ServerTransport } from '../server-e304daec.js';
5
+ import { C as Connection, s as ServerHandshakeOptions, o as ServiceContext } from '../handshake-1a86f06d.js';
6
+ export { t as ParsedMetadata, u as ServiceContextWithState, v as ServiceContextWithTransportInfo, w as createClientHandshakeOptions, x as createServerHandshakeOptions } from '../handshake-1a86f06d.js';
7
+ import { S as ServerTransport } from '../server-9a6b5a8e.js';
8
8
  import '../message-57296605.js';
9
9
  import '@sinclair/typebox/value';
10
10
  import '@opentelemetry/api';
11
- import '../client-0f636b3a.js';
11
+ import '../client-654098be.js';
12
12
  import '../types-3e5768ec.js';
13
13
 
14
14
  /**
@@ -45,6 +45,6 @@ declare function createServer<Services extends AnyServiceSchemaMap>(transport: S
45
45
  extendedContext?: Omit<ServiceContext, 'state'>;
46
46
  }>): Server<Services>;
47
47
 
48
- var version = "0.26.1";
48
+ var version = "0.26.2";
49
49
 
50
50
  export { PayloadType, version as RIVER_VERSION, Result, RiverError, Server, ServiceContext, createServer };
@@ -10,10 +10,10 @@ import {
10
10
  createServer,
11
11
  createServerHandshakeOptions,
12
12
  serializeSchema
13
- } from "../chunk-4W5LENT2.js";
13
+ } from "../chunk-MREEJE3X.js";
14
14
  import {
15
15
  version
16
- } from "../chunk-UQOD22AN.js";
16
+ } from "../chunk-M75K5TJS.js";
17
17
  export {
18
18
  Err,
19
19
  Ok,
@@ -1,14 +1,22 @@
1
- import { C as Connection, y as CommonSession, d as SessionState, z as SessionHandshakingListeners, A as CommonSessionProps, T as Transport, B as ServerTransportOptions, s as ServerHandshakeOptions, t as ParsedMetadata, D as ServerSession, c as ProvidedServerTransportOptions } from './handshake-8752f79e.js';
2
- import { M as MessageMetadata, a as TransportMessage, c as TransportClientId, P as PartialTransportMessage, b as OpaqueTransportMessage } from './message-57296605.js';
1
+ import { C as Connection, y as CommonSession, d as SessionState, z as CommonSessionProps, T as Transport, A as ServerTransportOptions, s as ServerHandshakeOptions, t as ParsedMetadata, B as ServerSession, c as ProvidedServerTransportOptions } from './handshake-1a86f06d.js';
2
+ import { M as MessageMetadata, a as TransportMessage, b as OpaqueTransportMessage, H as HandshakeErrorResponseCodes, c as TransportClientId, P as PartialTransportMessage } from './message-57296605.js';
3
+ import { Static } from '@sinclair/typebox';
3
4
 
5
+ interface SessionWaitingForHandshakeListeners {
6
+ onConnectionErrored: (err: unknown) => void;
7
+ onConnectionClosed: () => void;
8
+ onHandshake: (msg: OpaqueTransportMessage) => void;
9
+ onInvalidHandshake: (reason: string, code: Static<typeof HandshakeErrorResponseCodes>) => void;
10
+ onHandshakeTimeout: () => void;
11
+ }
4
12
  interface SessionWaitingForHandshakeProps<ConnType extends Connection> extends CommonSessionProps {
5
13
  conn: ConnType;
6
- listeners: SessionHandshakingListeners;
14
+ listeners: SessionWaitingForHandshakeListeners;
7
15
  }
8
16
  declare class SessionWaitingForHandshake<ConnType extends Connection> extends CommonSession {
9
17
  readonly state: SessionState.WaitingForHandshake;
10
18
  conn: ConnType;
11
- listeners: SessionHandshakingListeners;
19
+ listeners: SessionWaitingForHandshakeListeners;
12
20
  handshakeTimeout?: ReturnType<typeof setTimeout>;
13
21
  constructor(props: SessionWaitingForHandshakeProps<ConnType>);
14
22
  onHandshakeData: (msg: Uint8Array) => void;
@@ -1,8 +1,8 @@
1
1
  import { Static, TObject, TUnion, TString, TSchema, TNever, TLiteral } from '@sinclair/typebox';
2
2
  import { Pushable } from 'it-pushable';
3
- import { C as Connection, p as ClientHandshakeOptions, v as ServiceContextWithTransportInfo, o as ServiceContext } from './handshake-8752f79e.js';
3
+ import { C as Connection, p as ClientHandshakeOptions, v as ServiceContextWithTransportInfo, o as ServiceContext } from './handshake-1a86f06d.js';
4
4
  import { c as TransportClientId } from './message-57296605.js';
5
- import { C as ClientTransport } from './client-0f636b3a.js';
5
+ import { C as ClientTransport } from './client-654098be.js';
6
6
 
7
7
  type AsyncIter<T> = AsyncGenerator<T, T>;
8
8
  /**
@@ -218,6 +218,7 @@ var defaultTransportOptions = {
218
218
  sessionDisconnectGraceMs: 5e3,
219
219
  connectionTimeoutMs: 2e3,
220
220
  handshakeTimeoutMs: 1e3,
221
+ enableTransparentSessionReconnects: true,
221
222
  codec: NaiveJsonCodec
222
223
  };
223
224
  var defaultConnectionRetryOptions = {
@@ -536,9 +537,32 @@ var IdentifiedSession = class extends CommonSession {
536
537
  this.telemetry.span.end();
537
538
  }
538
539
  };
540
+ var IdentifiedSessionWithGracePeriod = class extends IdentifiedSession {
541
+ graceExpiryTime;
542
+ gracePeriodTimeout;
543
+ listeners;
544
+ constructor(props) {
545
+ super(props);
546
+ this.listeners = props.listeners;
547
+ this.graceExpiryTime = props.graceExpiryTime;
548
+ this.gracePeriodTimeout = setTimeout(() => {
549
+ this.listeners.onSessionGracePeriodElapsed();
550
+ }, this.graceExpiryTime - Date.now());
551
+ }
552
+ _handleStateExit() {
553
+ super._handleStateExit();
554
+ if (this.gracePeriodTimeout) {
555
+ clearTimeout(this.gracePeriodTimeout);
556
+ this.gracePeriodTimeout = void 0;
557
+ }
558
+ }
559
+ _handleClose() {
560
+ super._handleClose();
561
+ }
562
+ };
539
563
 
540
564
  // transport/sessionStateMachine/SessionConnecting.ts
541
- var SessionConnecting = class extends IdentifiedSession {
565
+ var SessionConnecting = class extends IdentifiedSessionWithGracePeriod {
542
566
  state = "Connecting" /* Connecting */;
543
567
  connPromise;
544
568
  listeners;
@@ -571,8 +595,10 @@ var SessionConnecting = class extends IdentifiedSession {
571
595
  }
572
596
  _handleStateExit() {
573
597
  super._handleStateExit();
574
- clearTimeout(this.connectionTimeout);
575
- this.connectionTimeout = void 0;
598
+ if (this.connectionTimeout) {
599
+ clearTimeout(this.connectionTimeout);
600
+ this.connectionTimeout = void 0;
601
+ }
576
602
  }
577
603
  _handleClose() {
578
604
  this.bestEffortClose();
@@ -581,26 +607,13 @@ var SessionConnecting = class extends IdentifiedSession {
581
607
  };
582
608
 
583
609
  // transport/sessionStateMachine/SessionNoConnection.ts
584
- var SessionNoConnection = class extends IdentifiedSession {
610
+ var SessionNoConnection = class extends IdentifiedSessionWithGracePeriod {
585
611
  state = "NoConnection" /* NoConnection */;
586
- listeners;
587
- gracePeriodTimeout;
588
- constructor(props) {
589
- super(props);
590
- this.listeners = props.listeners;
591
- this.gracePeriodTimeout = setTimeout(() => {
592
- this.listeners.onSessionGracePeriodElapsed();
593
- }, this.options.sessionDisconnectGraceMs);
594
- }
595
612
  _handleClose() {
596
613
  super._handleClose();
597
614
  }
598
615
  _handleStateExit() {
599
616
  super._handleStateExit();
600
- if (this.gracePeriodTimeout) {
601
- clearTimeout(this.gracePeriodTimeout);
602
- this.gracePeriodTimeout = void 0;
603
- }
604
617
  }
605
618
  };
606
619
 
@@ -608,7 +621,7 @@ var SessionNoConnection = class extends IdentifiedSession {
608
621
  var import_api = require("@opentelemetry/api");
609
622
 
610
623
  // package.json
611
- var version = "0.26.1";
624
+ var version = "0.26.2";
612
625
 
613
626
  // tracing/index.ts
614
627
  function getPropagationContext(ctx) {
@@ -689,7 +702,7 @@ var SessionWaitingForHandshake = class extends CommonSession {
689
702
  };
690
703
 
691
704
  // transport/sessionStateMachine/SessionHandshaking.ts
692
- var SessionHandshaking = class extends IdentifiedSession {
705
+ var SessionHandshaking = class extends IdentifiedSessionWithGracePeriod {
693
706
  state = "Handshaking" /* Handshaking */;
694
707
  conn;
695
708
  listeners;
@@ -724,7 +737,10 @@ var SessionHandshaking = class extends IdentifiedSession {
724
737
  this.conn.removeDataListener(this.onHandshakeData);
725
738
  this.conn.removeErrorListener(this.listeners.onConnectionErrored);
726
739
  this.conn.removeCloseListener(this.listeners.onConnectionClosed);
727
- clearTimeout(this.handshakeTimeout);
740
+ if (this.handshakeTimeout) {
741
+ clearTimeout(this.handshakeTimeout);
742
+ this.handshakeTimeout = void 0;
743
+ }
728
744
  }
729
745
  _handleClose() {
730
746
  super._handleClose();
@@ -804,8 +820,10 @@ var SessionConnected = class extends IdentifiedSession {
804
820
  }
805
821
  onMessageData = (msg) => {
806
822
  const parsedMsg = this.parseMsg(msg);
807
- if (parsedMsg === null)
823
+ if (parsedMsg === null) {
824
+ this.listeners.onInvalidMessage("could not parse message");
808
825
  return;
826
+ }
809
827
  if (parsedMsg.seq !== this.ack) {
810
828
  if (parsedMsg.seq < this.ack) {
811
829
  this.log?.debug(
@@ -862,7 +880,7 @@ var SessionConnected = class extends IdentifiedSession {
862
880
  };
863
881
 
864
882
  // transport/sessionStateMachine/SessionBackingOff.ts
865
- var SessionBackingOff = class extends IdentifiedSession {
883
+ var SessionBackingOff = class extends IdentifiedSessionWithGracePeriod {
866
884
  state = "BackingOff" /* BackingOff */;
867
885
  listeners;
868
886
  backoffTimeout;
@@ -899,6 +917,12 @@ function inheritSharedSession(session) {
899
917
  log: session.log
900
918
  };
901
919
  }
920
+ function inheritSharedSessionWithGrace(session) {
921
+ return {
922
+ ...inheritSharedSession(session),
923
+ graceExpiryTime: session.graceExpiryTime
924
+ };
925
+ }
902
926
  var SessionStateGraph = {
903
927
  entrypoints: {
904
928
  NoConnection: (to, from, listeners, options, log) => {
@@ -912,6 +936,7 @@ var SessionStateGraph = {
912
936
  to,
913
937
  seq: 0,
914
938
  ack: 0,
939
+ graceExpiryTime: Date.now() + options.sessionDisconnectGraceMs,
915
940
  sendBuffer,
916
941
  telemetry,
917
942
  options,
@@ -943,7 +968,7 @@ var SessionStateGraph = {
943
968
  transition: {
944
969
  // happy path transitions
945
970
  NoConnectionToBackingOff: (oldSession, backoffMs, listeners) => {
946
- const carriedState = inheritSharedSession(oldSession);
971
+ const carriedState = inheritSharedSessionWithGrace(oldSession);
947
972
  oldSession._handleStateExit();
948
973
  const session = new SessionBackingOff({
949
974
  backoffMs,
@@ -960,7 +985,7 @@ var SessionStateGraph = {
960
985
  return session;
961
986
  },
962
987
  BackingOffToConnecting: (oldSession, connPromise, listeners) => {
963
- const carriedState = inheritSharedSession(oldSession);
988
+ const carriedState = inheritSharedSessionWithGrace(oldSession);
964
989
  oldSession._handleStateExit();
965
990
  const session = new SessionConnecting({
966
991
  connPromise,
@@ -977,7 +1002,7 @@ var SessionStateGraph = {
977
1002
  return session;
978
1003
  },
979
1004
  ConnectingToHandshaking: (oldSession, conn, listeners) => {
980
- const carriedState = inheritSharedSession(oldSession);
1005
+ const carriedState = inheritSharedSessionWithGrace(oldSession);
981
1006
  oldSession._handleStateExit();
982
1007
  const session = new SessionHandshaking({
983
1008
  conn,
@@ -1054,9 +1079,12 @@ var SessionStateGraph = {
1054
1079
  },
1055
1080
  // disconnect paths
1056
1081
  BackingOffToNoConnection: (oldSession, listeners) => {
1057
- const carriedState = inheritSharedSession(oldSession);
1082
+ const carriedState = inheritSharedSessionWithGrace(oldSession);
1058
1083
  oldSession._handleStateExit();
1059
- const session = new SessionNoConnection({ listeners, ...carriedState });
1084
+ const session = new SessionNoConnection({
1085
+ listeners,
1086
+ ...carriedState
1087
+ });
1060
1088
  session.log?.info(
1061
1089
  `session ${session.id} transition from BackingOff to NoConnection`,
1062
1090
  {
@@ -1067,10 +1095,13 @@ var SessionStateGraph = {
1067
1095
  return session;
1068
1096
  },
1069
1097
  ConnectingToNoConnection: (oldSession, listeners) => {
1070
- const carriedState = inheritSharedSession(oldSession);
1098
+ const carriedState = inheritSharedSessionWithGrace(oldSession);
1071
1099
  oldSession.bestEffortClose();
1072
1100
  oldSession._handleStateExit();
1073
- const session = new SessionNoConnection({ listeners, ...carriedState });
1101
+ const session = new SessionNoConnection({
1102
+ listeners,
1103
+ ...carriedState
1104
+ });
1074
1105
  session.log?.info(
1075
1106
  `session ${session.id} transition from Connecting to NoConnection`,
1076
1107
  {
@@ -1081,10 +1112,13 @@ var SessionStateGraph = {
1081
1112
  return session;
1082
1113
  },
1083
1114
  HandshakingToNoConnection: (oldSession, listeners) => {
1084
- const carriedState = inheritSharedSession(oldSession);
1115
+ const carriedState = inheritSharedSessionWithGrace(oldSession);
1085
1116
  oldSession.conn.close();
1086
1117
  oldSession._handleStateExit();
1087
- const session = new SessionNoConnection({ listeners, ...carriedState });
1118
+ const session = new SessionNoConnection({
1119
+ listeners,
1120
+ ...carriedState
1121
+ });
1088
1122
  session.log?.info(
1089
1123
  `session ${session.id} transition from Handshaking to NoConnection`,
1090
1124
  {
@@ -1096,9 +1130,14 @@ var SessionStateGraph = {
1096
1130
  },
1097
1131
  ConnectedToNoConnection: (oldSession, listeners) => {
1098
1132
  const carriedState = inheritSharedSession(oldSession);
1133
+ const graceExpiryTime = Date.now() + oldSession.options.sessionDisconnectGraceMs;
1099
1134
  oldSession.conn.close();
1100
1135
  oldSession._handleStateExit();
1101
- const session = new SessionNoConnection({ listeners, ...carriedState });
1136
+ const session = new SessionNoConnection({
1137
+ listeners,
1138
+ graceExpiryTime,
1139
+ ...carriedState
1140
+ });
1102
1141
  session.log?.info(
1103
1142
  `session ${session.id} transition from Connected to NoConnection`,
1104
1143
  {
@@ -1115,24 +1154,42 @@ var ClientSessionStateGraph = {
1115
1154
  entrypoint: SessionStateGraph.entrypoints.NoConnection,
1116
1155
  transition: {
1117
1156
  // happy paths
1157
+ // NoConnection -> BackingOff: attempt to connect
1118
1158
  NoConnectionToBackingOff: transitions.NoConnectionToBackingOff,
1159
+ // BackingOff -> Connecting: backoff period elapsed, start connection
1119
1160
  BackingOffToConnecting: transitions.BackingOffToConnecting,
1161
+ // Connecting -> Handshaking: connection established, start handshake
1120
1162
  ConnectingToHandshaking: transitions.ConnectingToHandshaking,
1163
+ // Handshaking -> Connected: handshake complete, session ready
1121
1164
  HandshakingToConnected: transitions.HandshakingToConnected,
1122
1165
  // disconnect paths
1166
+ // BackingOff -> NoConnection: unused
1123
1167
  BackingOffToNoConnection: transitions.BackingOffToNoConnection,
1168
+ // Connecting -> NoConnection: connection failed or connection timeout
1124
1169
  ConnectingToNoConnection: transitions.ConnectingToNoConnection,
1170
+ // Handshaking -> NoConnection: connection closed or handshake timeout
1125
1171
  HandshakingToNoConnection: transitions.HandshakingToNoConnection,
1172
+ // Connected -> NoConnection: connection closed
1126
1173
  ConnectedToNoConnection: transitions.ConnectedToNoConnection
1174
+ // destroy/close paths
1175
+ // NoConnection -> x: grace period elapsed
1176
+ // BackingOff -> x: grace period elapsed
1177
+ // Connecting -> x: grace period elapsed
1178
+ // Handshaking -> x: grace period elapsed or invalid handshake message or handshake rejection
1179
+ // Connected -> x: grace period elapsed or invalid message
1127
1180
  }
1128
1181
  };
1129
1182
  var ServerSessionStateGraph = {
1130
1183
  entrypoint: SessionStateGraph.entrypoints.WaitingForHandshake,
1131
1184
  transition: {
1132
1185
  // happy paths
1186
+ // WaitingForHandshake -> Connected: handshake complete, session ready
1133
1187
  WaitingForHandshakeToConnected: transitions.WaitingForHandshakeToConnected,
1134
1188
  // disconnect paths
1189
+ // Connected -> NoConnection: connection closed
1135
1190
  ConnectedToNoConnection: transitions.ConnectedToNoConnection
1191
+ // destroy/close paths
1192
+ // WaitingForHandshake -> x: handshake timeout elapsed or invalid handshake message or handshake rejection or connection closed
1136
1193
  }
1137
1194
  };
1138
1195
 
@@ -1328,6 +1385,10 @@ var ClientTransport = class extends Transport {
1328
1385
  this.handshakeExtensions = options;
1329
1386
  }
1330
1387
  tryReconnecting(to) {
1388
+ const oldSession = this.sessions.get(to);
1389
+ if (!this.options.enableTransparentSessionReconnects && oldSession) {
1390
+ this.deleteSession(oldSession);
1391
+ }
1331
1392
  if (this.reconnectOnConnectionDrop && this.getStatus() === "open") {
1332
1393
  this.connect(to);
1333
1394
  }
@@ -1414,6 +1475,9 @@ var ClientTransport = class extends Transport {
1414
1475
  handshakingSession.loggingMetadata
1415
1476
  );
1416
1477
  this.onConnClosed(handshakingSession);
1478
+ },
1479
+ onSessionGracePeriodElapsed: () => {
1480
+ this.onSessionGracePeriodElapsed(handshakingSession);
1417
1481
  }
1418
1482
  }
1419
1483
  );
@@ -1560,6 +1624,9 @@ var ClientTransport = class extends Transport {
1560
1624
  }
1561
1625
  );
1562
1626
  this.onBackoffFinished(backingOffSession, reconnectPromise);
1627
+ },
1628
+ onSessionGracePeriodElapsed: () => {
1629
+ this.onSessionGracePeriodElapsed(backingOffSession);
1563
1630
  }
1564
1631
  }
1565
1632
  );
@@ -1591,6 +1658,9 @@ var ClientTransport = class extends Transport {
1591
1658
  connectingSession.loggingMetadata
1592
1659
  );
1593
1660
  this.onConnectingFailed(connectingSession);
1661
+ },
1662
+ onSessionGracePeriodElapsed: () => {
1663
+ this.onSessionGracePeriodElapsed(connectingSession);
1594
1664
  }
1595
1665
  }
1596
1666
  );