@replit/river 0.25.1 → 0.25.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 (50) hide show
  1. package/dist/{chunk-SZ5NBBX7.js → chunk-EHD2JJBW.js} +2 -2
  2. package/dist/{chunk-SZ5NBBX7.js.map → chunk-EHD2JJBW.js.map} +1 -1
  3. package/dist/{chunk-SGSRNAWJ.js → chunk-GDHQCPWW.js} +2 -2
  4. package/dist/{chunk-5CNNIOAO.js → chunk-ONIPHO7J.js} +102 -95
  5. package/dist/chunk-ONIPHO7J.js.map +1 -0
  6. package/dist/{chunk-D5O3ERJU.js → chunk-PF74DCPQ.js} +3 -3
  7. package/dist/chunk-PF74DCPQ.js.map +1 -0
  8. package/dist/{chunk-YM5Y4NAT.js → chunk-Q3PZBJXR.js} +199 -117
  9. package/dist/chunk-Q3PZBJXR.js.map +1 -0
  10. package/dist/{chunk-PCBPPTXH.js → chunk-QXMZJ7LF.js} +17 -26
  11. package/dist/chunk-QXMZJ7LF.js.map +1 -0
  12. package/dist/{chunk-MBMEJIPU.js → chunk-ZWMWRM23.js} +2 -2
  13. package/dist/{client-1321630c.d.ts → client-edc8e2de.d.ts} +3 -1
  14. package/dist/{connection-bd907ca6.d.ts → connection-ef50ac3a.d.ts} +1 -1
  15. package/dist/{handshake-3772d7ca.d.ts → handshake-12d57161.d.ts} +131 -83
  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-f0fd2b98.d.ts → server-f8228636.d.ts} +8 -3
  22. package/dist/{services-8d14ae16.d.ts → services-4b9e5232.d.ts} +2 -2
  23. package/dist/transport/impls/ws/client.cjs +291 -205
  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 +206 -136
  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 +304 -226
  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 +197 -115
  39. package/dist/util/testHelpers.cjs.map +1 -1
  40. package/dist/util/testHelpers.d.cts +5 -4
  41. package/dist/util/testHelpers.d.ts +5 -4
  42. package/dist/util/testHelpers.js +6 -3
  43. package/dist/util/testHelpers.js.map +1 -1
  44. package/package.json +14 -13
  45. package/dist/chunk-5CNNIOAO.js.map +0 -1
  46. package/dist/chunk-D5O3ERJU.js.map +0 -1
  47. package/dist/chunk-PCBPPTXH.js.map +0 -1
  48. package/dist/chunk-YM5Y4NAT.js.map +0 -1
  49. /package/dist/{chunk-SGSRNAWJ.js.map → chunk-GDHQCPWW.js.map} +0 -0
  50. /package/dist/{chunk-MBMEJIPU.js.map → chunk-ZWMWRM23.js.map} +0 -0
@@ -1,6 +1,6 @@
1
- export { b as ClientTransportOptions, C as Connection, j as EventHandler, E as EventMap, i as EventTypes, k as ProtocolError, l as ProtocolErrorType, c as ServerTransportOptions, S as Session, h as SessionConnected, f as SessionConnecting, g as SessionHandshaking, e as SessionNoConnection, d as SessionState, T as Transport, P as TransportOptions, a as TransportStatus } from '../handshake-3772d7ca.js';
2
- export { C as ClientTransport } from '../client-1321630c.js';
3
- export { S as ServerTransport, a as SessionWaitingForHandshake } from '../server-f0fd2b98.js';
1
+ export { b as ClientTransportOptions, C as Connection, j as EventHandler, E as EventMap, i as EventTypes, k as ProtocolError, l as ProtocolErrorType, c as ServerTransportOptions, S as Session, h as SessionConnected, f as SessionConnecting, g as SessionHandshaking, e as SessionNoConnection, d as SessionState, T as Transport, P as TransportOptions, a as TransportStatus } from '../handshake-12d57161.js';
2
+ export { C as ClientTransport } from '../client-edc8e2de.js';
3
+ export { S as ServerTransport, a as SessionWaitingForHandshake } from '../server-f8228636.js';
4
4
  export { b as OpaqueTransportMessage, O as OpaqueTransportMessageSchema, c as TransportClientId, a as TransportMessage, T as TransportMessageSchema, d as isStreamClose, i as isStreamOpen } from '../message-e6c560fd.js';
5
5
  import '@sinclair/typebox';
6
6
  import '../types-3e5768ec.js';
@@ -1,6 +1,6 @@
1
- export { b as ClientTransportOptions, C as Connection, j as EventHandler, E as EventMap, i as EventTypes, k as ProtocolError, l as ProtocolErrorType, c as ServerTransportOptions, S as Session, h as SessionConnected, f as SessionConnecting, g as SessionHandshaking, e as SessionNoConnection, d as SessionState, T as Transport, P as TransportOptions, a as TransportStatus } from '../handshake-3772d7ca.js';
2
- export { C as ClientTransport } from '../client-1321630c.js';
3
- export { S as ServerTransport, a as SessionWaitingForHandshake } from '../server-f0fd2b98.js';
1
+ export { b as ClientTransportOptions, C as Connection, j as EventHandler, E as EventMap, i as EventTypes, k as ProtocolError, l as ProtocolErrorType, c as ServerTransportOptions, S as Session, h as SessionConnected, f as SessionConnecting, g as SessionHandshaking, e as SessionNoConnection, d as SessionState, T as Transport, P as TransportOptions, a as TransportStatus } from '../handshake-12d57161.js';
2
+ export { C as ClientTransport } from '../client-edc8e2de.js';
3
+ export { S as ServerTransport, a as SessionWaitingForHandshake } from '../server-f8228636.js';
4
4
  export { b as OpaqueTransportMessage, O as OpaqueTransportMessageSchema, c as TransportClientId, a as TransportMessage, T as TransportMessageSchema, d as isStreamClose, i as isStreamOpen } from '../message-e6c560fd.js';
5
5
  import '@sinclair/typebox';
6
6
  import '../types-3e5768ec.js';
@@ -1,22 +1,22 @@
1
1
  import {
2
2
  ClientTransport
3
- } from "../chunk-5CNNIOAO.js";
3
+ } from "../chunk-ONIPHO7J.js";
4
4
  import {
5
5
  ServerTransport
6
- } from "../chunk-PCBPPTXH.js";
6
+ } from "../chunk-QXMZJ7LF.js";
7
7
  import {
8
8
  Connection,
9
9
  ProtocolError,
10
10
  Transport
11
- } from "../chunk-D5O3ERJU.js";
11
+ } from "../chunk-PF74DCPQ.js";
12
12
  import "../chunk-TAH2GVTJ.js";
13
13
  import {
14
14
  SessionState
15
- } from "../chunk-YM5Y4NAT.js";
15
+ } from "../chunk-Q3PZBJXR.js";
16
16
  import {
17
17
  OpaqueTransportMessageSchema,
18
18
  TransportMessageSchema
19
- } from "../chunk-SZ5NBBX7.js";
19
+ } from "../chunk-EHD2JJBW.js";
20
20
  import "../chunk-4PVU7J25.js";
21
21
  export {
22
22
  ClientTransport,
@@ -44,6 +44,7 @@ __export(testHelpers_exports, {
44
44
  numberOfConnections: () => numberOfConnections,
45
45
  onWsServerReady: () => onWsServerReady,
46
46
  payloadToTransportMessage: () => payloadToTransportMessage,
47
+ testingClientSessionOptions: () => testingClientSessionOptions,
47
48
  testingSessionOptions: () => testingSessionOptions,
48
49
  waitForMessage: () => waitForMessage
49
50
  });
@@ -450,7 +451,7 @@ function Err(error) {
450
451
  var import_api = require("@opentelemetry/api");
451
452
 
452
453
  // package.json
453
- var version = "0.25.1";
454
+ var version = "0.25.2";
454
455
 
455
456
  // tracing/index.ts
456
457
  function createSessionTelemetryInfo(sessionId, to, from, propagationCtx) {
@@ -542,7 +543,7 @@ var defaultTransportOptions = {
542
543
  codec: NaiveJsonCodec
543
544
  };
544
545
  var defaultConnectionRetryOptions = {
545
- baseIntervalMs: 250,
546
+ baseIntervalMs: 150,
546
547
  maxJitterMs: 200,
547
548
  maxBackoffMs: 32e3,
548
549
  attemptBudgetCapacity: 5,
@@ -609,7 +610,7 @@ var CommonSession = class extends StateMachineState {
609
610
  from;
610
611
  options;
611
612
  log;
612
- constructor(from, options, log) {
613
+ constructor({ from, options, log }) {
613
614
  super();
614
615
  this.from = from;
615
616
  this.options = options;
@@ -650,8 +651,9 @@ var IdentifiedSession = class extends CommonSession {
650
651
  */
651
652
  ack;
652
653
  sendBuffer;
653
- constructor(id, from, to, seq, ack, sendBuffer, telemetry, options, log) {
654
- super(from, options, log);
654
+ constructor(props) {
655
+ const { id, to, seq, ack, sendBuffer, telemetry, log } = props;
656
+ super(props);
655
657
  this.id = id;
656
658
  this.to = to;
657
659
  this.seq = seq;
@@ -706,23 +708,23 @@ var SessionConnecting = class extends IdentifiedSession {
706
708
  connPromise;
707
709
  listeners;
708
710
  connectionTimeout;
709
- constructor(connPromise, listeners, ...args) {
710
- super(...args);
711
- this.connPromise = connPromise;
712
- this.listeners = listeners;
711
+ constructor(props) {
712
+ super(props);
713
+ this.connPromise = props.connPromise;
714
+ this.listeners = props.listeners;
713
715
  this.connectionTimeout = setTimeout(() => {
714
- listeners.onConnectionTimeout();
716
+ this.listeners.onConnectionTimeout();
715
717
  }, this.options.connectionTimeoutMs);
716
- connPromise.then(
718
+ this.connPromise.then(
717
719
  (conn) => {
718
720
  if (this._isConsumed)
719
721
  return;
720
- listeners.onConnectionEstablished(conn);
722
+ this.listeners.onConnectionEstablished(conn);
721
723
  },
722
724
  (err) => {
723
725
  if (this._isConsumed)
724
726
  return;
725
- listeners.onConnectionFailed(err);
727
+ this.listeners.onConnectionFailed(err);
726
728
  }
727
729
  );
728
730
  }
@@ -748,9 +750,9 @@ var SessionNoConnection = class extends IdentifiedSession {
748
750
  state = "NoConnection" /* NoConnection */;
749
751
  listeners;
750
752
  gracePeriodTimeout;
751
- constructor(listeners, ...args) {
752
- super(...args);
753
- this.listeners = listeners;
753
+ constructor(props) {
754
+ super(props);
755
+ this.listeners = props.listeners;
754
756
  this.gracePeriodTimeout = setTimeout(() => {
755
757
  this.listeners.onSessionGracePeriodElapsed();
756
758
  }, this.options.sessionDisconnectGraceMs);
@@ -773,16 +775,16 @@ var SessionWaitingForHandshake = class extends CommonSession {
773
775
  conn;
774
776
  listeners;
775
777
  handshakeTimeout;
776
- constructor(conn, listeners, ...args) {
777
- super(...args);
778
- this.conn = conn;
779
- this.listeners = listeners;
778
+ constructor(props) {
779
+ super(props);
780
+ this.conn = props.conn;
781
+ this.listeners = props.listeners;
780
782
  this.handshakeTimeout = setTimeout(() => {
781
- listeners.onHandshakeTimeout();
783
+ this.listeners.onHandshakeTimeout();
782
784
  }, this.options.handshakeTimeoutMs);
783
785
  this.conn.addDataListener(this.onHandshakeData);
784
- this.conn.addErrorListener(listeners.onConnectionErrored);
785
- this.conn.addCloseListener(listeners.onConnectionClosed);
786
+ this.conn.addErrorListener(this.listeners.onConnectionErrored);
787
+ this.conn.addCloseListener(this.listeners.onConnectionClosed);
786
788
  }
787
789
  onHandshakeData = (msg) => {
788
790
  const parsedMsg = this.parseMsg(msg);
@@ -819,16 +821,16 @@ var SessionHandshaking = class extends IdentifiedSession {
819
821
  conn;
820
822
  listeners;
821
823
  handshakeTimeout;
822
- constructor(conn, listeners, ...args) {
823
- super(...args);
824
- this.conn = conn;
825
- this.listeners = listeners;
824
+ constructor(props) {
825
+ super(props);
826
+ this.conn = props.conn;
827
+ this.listeners = props.listeners;
826
828
  this.handshakeTimeout = setTimeout(() => {
827
- listeners.onHandshakeTimeout();
829
+ this.listeners.onHandshakeTimeout();
828
830
  }, this.options.handshakeTimeoutMs);
829
831
  this.conn.addDataListener(this.onHandshakeData);
830
- this.conn.addErrorListener(listeners.onConnectionErrored);
831
- this.conn.addCloseListener(listeners.onConnectionClosed);
832
+ this.conn.addErrorListener(this.listeners.onConnectionErrored);
833
+ this.conn.addCloseListener(this.listeners.onConnectionClosed);
832
834
  }
833
835
  onHandshakeData = (msg) => {
834
836
  const parsedMsg = this.parseMsg(msg);
@@ -860,16 +862,13 @@ var SessionConnected = class extends IdentifiedSession {
860
862
  state = "Connected" /* Connected */;
861
863
  conn;
862
864
  listeners;
863
- activeHeartbeatHandle;
864
- activeHeartbeatMisses = 0;
865
- passiveHeartbeatHandle;
866
- get isActivelyHeartbeating() {
867
- return this.activeHeartbeatHandle !== void 0;
868
- }
865
+ heartbeatHandle;
866
+ heartbeatMisses = 0;
867
+ isActivelyHeartbeating;
869
868
  updateBookkeeping(ack, seq) {
870
869
  this.sendBuffer = this.sendBuffer.filter((unacked) => unacked.seq >= ack);
871
870
  this.ack = seq + 1;
872
- this.activeHeartbeatMisses = 0;
871
+ this.heartbeatMisses = 0;
873
872
  }
874
873
  send(msg) {
875
874
  const constructedMsg = this.constructMsg(msg);
@@ -877,13 +876,13 @@ var SessionConnected = class extends IdentifiedSession {
877
876
  this.conn.send(this.options.codec.toBuffer(constructedMsg));
878
877
  return constructedMsg.id;
879
878
  }
880
- constructor(conn, listeners, ...args) {
881
- super(...args);
882
- this.conn = conn;
883
- this.listeners = listeners;
879
+ constructor(props) {
880
+ super(props);
881
+ this.conn = props.conn;
882
+ this.listeners = props.listeners;
884
883
  this.conn.addDataListener(this.onMessageData);
885
- this.conn.addCloseListener(listeners.onConnectionClosed);
886
- this.conn.addErrorListener(listeners.onConnectionErrored);
884
+ this.conn.addCloseListener(this.listeners.onConnectionClosed);
885
+ this.conn.addErrorListener(this.listeners.onConnectionErrored);
887
886
  if (this.sendBuffer.length > 0) {
888
887
  this.log?.debug(
889
888
  `sending ${this.sendBuffer.length} buffered messages`,
@@ -891,12 +890,11 @@ var SessionConnected = class extends IdentifiedSession {
891
890
  );
892
891
  }
893
892
  for (const msg of this.sendBuffer) {
894
- conn.send(this.options.codec.toBuffer(msg));
893
+ this.conn.send(this.options.codec.toBuffer(msg));
895
894
  }
896
- }
897
- startActiveHeartbeat() {
898
- this.activeHeartbeatHandle = setInterval(() => {
899
- const misses = this.activeHeartbeatMisses;
895
+ this.isActivelyHeartbeating = false;
896
+ this.heartbeatHandle = setInterval(() => {
897
+ const misses = this.heartbeatMisses;
900
898
  const missDuration = misses * this.options.heartbeatIntervalMs;
901
899
  if (misses >= this.options.heartbeatsUntilDead) {
902
900
  this.log?.info(
@@ -905,29 +903,18 @@ var SessionConnected = class extends IdentifiedSession {
905
903
  );
906
904
  this.telemetry.span.addEvent("closing connection due to inactivity");
907
905
  this.conn.close();
908
- clearInterval(this.activeHeartbeatHandle);
909
- this.activeHeartbeatHandle = void 0;
906
+ clearInterval(this.heartbeatHandle);
907
+ this.heartbeatHandle = void 0;
910
908
  return;
911
909
  }
912
- this.sendHeartbeat();
913
- this.activeHeartbeatMisses++;
910
+ if (this.isActivelyHeartbeating) {
911
+ this.sendHeartbeat();
912
+ }
913
+ this.heartbeatMisses++;
914
914
  }, this.options.heartbeatIntervalMs);
915
915
  }
916
- waitForNextHeartbeat() {
917
- const duration = this.options.heartbeatsUntilDead * this.options.heartbeatIntervalMs;
918
- if (this.passiveHeartbeatHandle) {
919
- clearTimeout(this.passiveHeartbeatHandle);
920
- this.passiveHeartbeatHandle = void 0;
921
- }
922
- this.passiveHeartbeatHandle = setTimeout(() => {
923
- this.log?.info(
924
- `closing connection to ${this.to} due to not receiving a heartbeat in the last ${duration}ms`,
925
- this.loggingMetadata
926
- );
927
- this.telemetry.span.addEvent("closing connection due to inactivity");
928
- this.conn.close();
929
- this.passiveHeartbeatHandle = void 0;
930
- }, duration);
916
+ startActiveHeartbeat() {
917
+ this.isActivelyHeartbeating = true;
931
918
  }
932
919
  sendHeartbeat() {
933
920
  this.log?.debug("sending heartbeat", this.loggingMetadata);
@@ -982,7 +969,6 @@ var SessionConnected = class extends IdentifiedSession {
982
969
  });
983
970
  if (!this.isActivelyHeartbeating) {
984
971
  this.sendHeartbeat();
985
- this.waitForNextHeartbeat();
986
972
  }
987
973
  };
988
974
  _handleStateExit() {
@@ -990,10 +976,8 @@ var SessionConnected = class extends IdentifiedSession {
990
976
  this.conn.removeDataListener(this.onMessageData);
991
977
  this.conn.removeCloseListener(this.listeners.onConnectionClosed);
992
978
  this.conn.removeErrorListener(this.listeners.onConnectionErrored);
993
- clearInterval(this.activeHeartbeatHandle);
994
- clearTimeout(this.passiveHeartbeatHandle);
995
- this.activeHeartbeatHandle = void 0;
996
- this.passiveHeartbeatHandle = void 0;
979
+ clearInterval(this.heartbeatHandle);
980
+ this.heartbeatHandle = void 0;
997
981
  }
998
982
  _handleClose() {
999
983
  super._handleClose();
@@ -1001,52 +985,76 @@ var SessionConnected = class extends IdentifiedSession {
1001
985
  }
1002
986
  };
1003
987
 
988
+ // transport/sessionStateMachine/SessionBackingOff.ts
989
+ var SessionBackingOff = class extends IdentifiedSession {
990
+ state = "BackingOff" /* BackingOff */;
991
+ listeners;
992
+ backoffTimeout;
993
+ constructor(props) {
994
+ super(props);
995
+ this.listeners = props.listeners;
996
+ this.backoffTimeout = setTimeout(() => {
997
+ this.listeners.onBackoffFinished();
998
+ }, props.backoffMs);
999
+ }
1000
+ _handleClose() {
1001
+ super._handleClose();
1002
+ }
1003
+ _handleStateExit() {
1004
+ super._handleStateExit();
1005
+ if (this.backoffTimeout) {
1006
+ clearTimeout(this.backoffTimeout);
1007
+ this.backoffTimeout = void 0;
1008
+ }
1009
+ }
1010
+ };
1011
+
1004
1012
  // transport/sessionStateMachine/transitions.ts
1005
1013
  function inheritSharedSession(session) {
1006
- return [
1007
- session.id,
1008
- session.from,
1009
- session.to,
1010
- session.seq,
1011
- session.ack,
1012
- session.sendBuffer,
1013
- session.telemetry,
1014
- session.options,
1015
- session.log
1016
- ];
1014
+ return {
1015
+ id: session.id,
1016
+ from: session.from,
1017
+ to: session.to,
1018
+ seq: session.seq,
1019
+ ack: session.ack,
1020
+ sendBuffer: session.sendBuffer,
1021
+ telemetry: session.telemetry,
1022
+ options: session.options,
1023
+ log: session.log
1024
+ };
1017
1025
  }
1018
1026
  var SessionStateGraph = {
1019
1027
  entrypoints: {
1020
- NoConnection(to, from, listeners, options, log) {
1028
+ NoConnection: (to, from, listeners, options, log) => {
1021
1029
  const id = `session-${generateId()}`;
1022
1030
  const telemetry = createSessionTelemetryInfo(id, to, from);
1023
1031
  const sendBuffer = [];
1024
- const session = new SessionNoConnection(
1032
+ const session = new SessionNoConnection({
1025
1033
  listeners,
1026
1034
  id,
1027
1035
  from,
1028
1036
  to,
1029
- 0,
1030
- 0,
1037
+ seq: 0,
1038
+ ack: 0,
1031
1039
  sendBuffer,
1032
1040
  telemetry,
1033
1041
  options,
1034
1042
  log
1035
- );
1043
+ });
1036
1044
  session.log?.info(`session ${session.id} created in NoConnection state`, {
1037
1045
  ...session.loggingMetadata,
1038
1046
  tags: ["state-transition"]
1039
1047
  });
1040
1048
  return session;
1041
1049
  },
1042
- WaitingForHandshake(from, conn, listeners, options, log) {
1043
- const session = new SessionWaitingForHandshake(
1050
+ WaitingForHandshake: (from, conn, listeners, options, log) => {
1051
+ const session = new SessionWaitingForHandshake({
1044
1052
  conn,
1045
1053
  listeners,
1046
1054
  from,
1047
1055
  options,
1048
1056
  log
1049
- );
1057
+ });
1050
1058
  session.log?.info(`session created in WaitingForHandshake state`, {
1051
1059
  ...session.loggingMetadata,
1052
1060
  tags: ["state-transition"]
@@ -1058,16 +1066,33 @@ var SessionStateGraph = {
1058
1066
  // After a session is transitioned, any usage of the old session will throw.
1059
1067
  transition: {
1060
1068
  // happy path transitions
1061
- NoConnectionToConnecting(oldSession, connPromise, listeners) {
1069
+ NoConnectionToBackingOff: (oldSession, backoffMs, listeners) => {
1062
1070
  const carriedState = inheritSharedSession(oldSession);
1063
1071
  oldSession._handleStateExit();
1064
- const session = new SessionConnecting(
1065
- connPromise,
1072
+ const session = new SessionBackingOff({
1073
+ backoffMs,
1066
1074
  listeners,
1067
1075
  ...carriedState
1076
+ });
1077
+ session.log?.info(
1078
+ `session ${session.id} transition from NoConnection to BackingOff`,
1079
+ {
1080
+ ...session.loggingMetadata,
1081
+ tags: ["state-transition"]
1082
+ }
1068
1083
  );
1084
+ return session;
1085
+ },
1086
+ BackingOffToConnecting: (oldSession, connPromise, listeners) => {
1087
+ const carriedState = inheritSharedSession(oldSession);
1088
+ oldSession._handleStateExit();
1089
+ const session = new SessionConnecting({
1090
+ connPromise,
1091
+ listeners,
1092
+ ...carriedState
1093
+ });
1069
1094
  session.log?.info(
1070
- `session ${session.id} transition from NoConnection to Connecting`,
1095
+ `session ${session.id} transition from BackingOff to Connecting`,
1071
1096
  {
1072
1097
  ...session.loggingMetadata,
1073
1098
  tags: ["state-transition"]
@@ -1075,10 +1100,14 @@ var SessionStateGraph = {
1075
1100
  );
1076
1101
  return session;
1077
1102
  },
1078
- ConnectingToHandshaking(oldSession, conn, listeners) {
1103
+ ConnectingToHandshaking: (oldSession, conn, listeners) => {
1079
1104
  const carriedState = inheritSharedSession(oldSession);
1080
1105
  oldSession._handleStateExit();
1081
- const session = new SessionHandshaking(conn, listeners, ...carriedState);
1106
+ const session = new SessionHandshaking({
1107
+ conn,
1108
+ listeners,
1109
+ ...carriedState
1110
+ });
1082
1111
  session.log?.info(
1083
1112
  `session ${session.id} transition from Connecting to Handshaking`,
1084
1113
  {
@@ -1088,11 +1117,15 @@ var SessionStateGraph = {
1088
1117
  );
1089
1118
  return session;
1090
1119
  },
1091
- HandshakingToConnected(oldSession, listeners) {
1120
+ HandshakingToConnected: (oldSession, listeners) => {
1092
1121
  const carriedState = inheritSharedSession(oldSession);
1093
1122
  const conn = oldSession.conn;
1094
1123
  oldSession._handleStateExit();
1095
- const session = new SessionConnected(conn, listeners, ...carriedState);
1124
+ const session = new SessionConnected({
1125
+ conn,
1126
+ listeners,
1127
+ ...carriedState
1128
+ });
1096
1129
  session.log?.info(
1097
1130
  `session ${session.id} transition from Handshaking to Connected`,
1098
1131
  {
@@ -1102,7 +1135,7 @@ var SessionStateGraph = {
1102
1135
  );
1103
1136
  return session;
1104
1137
  },
1105
- WaitingForHandshakeToConnected(pendingSession, oldSession, sessionId, to, propagationCtx, listeners) {
1138
+ WaitingForHandshakeToConnected: (pendingSession, oldSession, sessionId, to, propagationCtx, listeners) => {
1106
1139
  const conn = pendingSession.conn;
1107
1140
  const { from, options } = pendingSession;
1108
1141
  const carriedState = oldSession ? (
@@ -1110,21 +1143,30 @@ var SessionStateGraph = {
1110
1143
  inheritSharedSession(oldSession)
1111
1144
  ) : (
1112
1145
  // old session does not exist, create new state
1113
- [
1114
- sessionId,
1146
+ {
1147
+ id: sessionId,
1115
1148
  from,
1116
1149
  to,
1117
- 0,
1118
- 0,
1119
- [],
1120
- createSessionTelemetryInfo(sessionId, to, from, propagationCtx),
1150
+ seq: 0,
1151
+ ack: 0,
1152
+ sendBuffer: [],
1153
+ telemetry: createSessionTelemetryInfo(
1154
+ sessionId,
1155
+ to,
1156
+ from,
1157
+ propagationCtx
1158
+ ),
1121
1159
  options,
1122
- pendingSession.log
1123
- ]
1160
+ log: pendingSession.log
1161
+ }
1124
1162
  );
1125
1163
  pendingSession._handleStateExit();
1126
1164
  oldSession?._handleStateExit();
1127
- const session = new SessionConnected(conn, listeners, ...carriedState);
1165
+ const session = new SessionConnected({
1166
+ conn,
1167
+ listeners,
1168
+ ...carriedState
1169
+ });
1128
1170
  session.log?.info(
1129
1171
  `session ${session.id} transition from WaitingForHandshake to Connected`,
1130
1172
  {
@@ -1135,11 +1177,24 @@ var SessionStateGraph = {
1135
1177
  return session;
1136
1178
  },
1137
1179
  // disconnect paths
1138
- ConnectingToNoConnection(oldSession, listeners) {
1180
+ BackingOffToNoConnection: (oldSession, listeners) => {
1181
+ const carriedState = inheritSharedSession(oldSession);
1182
+ oldSession._handleStateExit();
1183
+ const session = new SessionNoConnection({ listeners, ...carriedState });
1184
+ session.log?.info(
1185
+ `session ${session.id} transition from BackingOff to NoConnection`,
1186
+ {
1187
+ ...session.loggingMetadata,
1188
+ tags: ["state-transition"]
1189
+ }
1190
+ );
1191
+ return session;
1192
+ },
1193
+ ConnectingToNoConnection: (oldSession, listeners) => {
1139
1194
  const carriedState = inheritSharedSession(oldSession);
1140
1195
  oldSession.bestEffortClose();
1141
1196
  oldSession._handleStateExit();
1142
- const session = new SessionNoConnection(listeners, ...carriedState);
1197
+ const session = new SessionNoConnection({ listeners, ...carriedState });
1143
1198
  session.log?.info(
1144
1199
  `session ${session.id} transition from Connecting to NoConnection`,
1145
1200
  {
@@ -1149,11 +1204,11 @@ var SessionStateGraph = {
1149
1204
  );
1150
1205
  return session;
1151
1206
  },
1152
- HandshakingToNoConnection(oldSession, listeners) {
1207
+ HandshakingToNoConnection: (oldSession, listeners) => {
1153
1208
  const carriedState = inheritSharedSession(oldSession);
1154
1209
  oldSession.conn.close();
1155
1210
  oldSession._handleStateExit();
1156
- const session = new SessionNoConnection(listeners, ...carriedState);
1211
+ const session = new SessionNoConnection({ listeners, ...carriedState });
1157
1212
  session.log?.info(
1158
1213
  `session ${session.id} transition from Handshaking to NoConnection`,
1159
1214
  {
@@ -1163,11 +1218,11 @@ var SessionStateGraph = {
1163
1218
  );
1164
1219
  return session;
1165
1220
  },
1166
- ConnectedToNoConnection(oldSession, listeners) {
1221
+ ConnectedToNoConnection: (oldSession, listeners) => {
1167
1222
  const carriedState = inheritSharedSession(oldSession);
1168
1223
  oldSession.conn.close();
1169
1224
  oldSession._handleStateExit();
1170
- const session = new SessionNoConnection(listeners, ...carriedState);
1225
+ const session = new SessionNoConnection({ listeners, ...carriedState });
1171
1226
  session.log?.info(
1172
1227
  `session ${session.id} transition from Connected to NoConnection`,
1173
1228
  {
@@ -1179,6 +1234,31 @@ var SessionStateGraph = {
1179
1234
  }
1180
1235
  }
1181
1236
  };
1237
+ var transitions = SessionStateGraph.transition;
1238
+ var ClientSessionStateGraph = {
1239
+ entrypoint: SessionStateGraph.entrypoints.NoConnection,
1240
+ transition: {
1241
+ // happy paths
1242
+ NoConnectionToBackingOff: transitions.NoConnectionToBackingOff,
1243
+ BackingOffToConnecting: transitions.BackingOffToConnecting,
1244
+ ConnectingToHandshaking: transitions.ConnectingToHandshaking,
1245
+ HandshakingToConnected: transitions.HandshakingToConnected,
1246
+ // disconnect paths
1247
+ BackingOffToNoConnection: transitions.BackingOffToNoConnection,
1248
+ ConnectingToNoConnection: transitions.ConnectingToNoConnection,
1249
+ HandshakingToNoConnection: transitions.HandshakingToNoConnection,
1250
+ ConnectedToNoConnection: transitions.ConnectedToNoConnection
1251
+ }
1252
+ };
1253
+ var ServerSessionStateGraph = {
1254
+ entrypoint: SessionStateGraph.entrypoints.WaitingForHandshake,
1255
+ transition: {
1256
+ // happy paths
1257
+ WaitingForHandshakeToConnected: transitions.WaitingForHandshakeToConnected,
1258
+ // disconnect paths
1259
+ ConnectedToNoConnection: transitions.ConnectedToNoConnection
1260
+ }
1261
+ };
1182
1262
 
1183
1263
  // util/testHelpers.ts
1184
1264
  function createLocalWebSocketClient(port) {
@@ -1239,6 +1319,7 @@ function catchProcError(err) {
1239
1319
  return Err({ code: UNCAUGHT_ERROR, message: errorMsg });
1240
1320
  }
1241
1321
  var testingSessionOptions = defaultTransportOptions;
1322
+ var testingClientSessionOptions = defaultClientTransportOptions;
1242
1323
  function dummySession() {
1243
1324
  return SessionStateGraph.entrypoints.NoConnection(
1244
1325
  "client",
@@ -1338,6 +1419,7 @@ function closeAllConnections(transport) {
1338
1419
  numberOfConnections,
1339
1420
  onWsServerReady,
1340
1421
  payloadToTransportMessage,
1422
+ testingClientSessionOptions,
1341
1423
  testingSessionOptions,
1342
1424
  waitForMessage
1343
1425
  });