@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,7 +1,7 @@
1
- import { C as ClientTransport } from '../../../client-1321630c.js';
1
+ import { C as ClientTransport } from '../../../client-edc8e2de.js';
2
2
  import { c as TransportClientId } from '../../../message-e6c560fd.js';
3
- import { b as ProvidedClientTransportOptions } from '../../../handshake-3772d7ca.js';
4
- import { W as WebSocketConnection } from '../../../connection-bd907ca6.js';
3
+ import { b as ProvidedClientTransportOptions } from '../../../handshake-12d57161.js';
4
+ import { W as WebSocketConnection } from '../../../connection-ef50ac3a.js';
5
5
  import { W as WsLike } from '../../../wslike-e0b32dd5.js';
6
6
  import '@sinclair/typebox/value';
7
7
  import '@sinclair/typebox';
@@ -1,7 +1,7 @@
1
- import { C as ClientTransport } from '../../../client-1321630c.js';
1
+ import { C as ClientTransport } from '../../../client-edc8e2de.js';
2
2
  import { c as TransportClientId } from '../../../message-e6c560fd.js';
3
- import { b as ProvidedClientTransportOptions } from '../../../handshake-3772d7ca.js';
4
- import { W as WebSocketConnection } from '../../../connection-bd907ca6.js';
3
+ import { b as ProvidedClientTransportOptions } from '../../../handshake-12d57161.js';
4
+ import { W as WebSocketConnection } from '../../../connection-ef50ac3a.js';
5
5
  import { W as WsLike } from '../../../wslike-e0b32dd5.js';
6
6
  import '@sinclair/typebox/value';
7
7
  import '@sinclair/typebox';
@@ -1,13 +1,13 @@
1
1
  import {
2
2
  ClientTransport
3
- } from "../../../chunk-5CNNIOAO.js";
3
+ } from "../../../chunk-ONIPHO7J.js";
4
4
  import {
5
5
  WebSocketConnection
6
- } from "../../../chunk-MBMEJIPU.js";
7
- import "../../../chunk-D5O3ERJU.js";
6
+ } from "../../../chunk-ZWMWRM23.js";
7
+ import "../../../chunk-PF74DCPQ.js";
8
8
  import "../../../chunk-TAH2GVTJ.js";
9
- import "../../../chunk-YM5Y4NAT.js";
10
- import "../../../chunk-SZ5NBBX7.js";
9
+ import "../../../chunk-Q3PZBJXR.js";
10
+ import "../../../chunk-EHD2JJBW.js";
11
11
  import "../../../chunk-4PVU7J25.js";
12
12
 
13
13
  // transport/impls/ws/client.ts
@@ -316,7 +316,7 @@ var defaultTransportOptions = {
316
316
  codec: NaiveJsonCodec
317
317
  };
318
318
  var defaultConnectionRetryOptions = {
319
- baseIntervalMs: 250,
319
+ baseIntervalMs: 150,
320
320
  maxJitterMs: 200,
321
321
  maxBackoffMs: 32e3,
322
322
  attemptBudgetCapacity: 5,
@@ -473,7 +473,7 @@ var CommonSession = class extends StateMachineState {
473
473
  from;
474
474
  options;
475
475
  log;
476
- constructor(from, options, log) {
476
+ constructor({ from, options, log }) {
477
477
  super();
478
478
  this.from = from;
479
479
  this.options = options;
@@ -514,8 +514,9 @@ var IdentifiedSession = class extends CommonSession {
514
514
  */
515
515
  ack;
516
516
  sendBuffer;
517
- constructor(id, from, to, seq, ack, sendBuffer, telemetry, options, log) {
518
- super(from, options, log);
517
+ constructor(props) {
518
+ const { id, to, seq, ack, sendBuffer, telemetry, log } = props;
519
+ super(props);
519
520
  this.id = id;
520
521
  this.to = to;
521
522
  this.seq = seq;
@@ -570,23 +571,23 @@ var SessionConnecting = class extends IdentifiedSession {
570
571
  connPromise;
571
572
  listeners;
572
573
  connectionTimeout;
573
- constructor(connPromise, listeners, ...args) {
574
- super(...args);
575
- this.connPromise = connPromise;
576
- this.listeners = listeners;
574
+ constructor(props) {
575
+ super(props);
576
+ this.connPromise = props.connPromise;
577
+ this.listeners = props.listeners;
577
578
  this.connectionTimeout = setTimeout(() => {
578
- listeners.onConnectionTimeout();
579
+ this.listeners.onConnectionTimeout();
579
580
  }, this.options.connectionTimeoutMs);
580
- connPromise.then(
581
+ this.connPromise.then(
581
582
  (conn) => {
582
583
  if (this._isConsumed)
583
584
  return;
584
- listeners.onConnectionEstablished(conn);
585
+ this.listeners.onConnectionEstablished(conn);
585
586
  },
586
587
  (err) => {
587
588
  if (this._isConsumed)
588
589
  return;
589
- listeners.onConnectionFailed(err);
590
+ this.listeners.onConnectionFailed(err);
590
591
  }
591
592
  );
592
593
  }
@@ -612,9 +613,9 @@ var SessionNoConnection = class extends IdentifiedSession {
612
613
  state = "NoConnection" /* NoConnection */;
613
614
  listeners;
614
615
  gracePeriodTimeout;
615
- constructor(listeners, ...args) {
616
- super(...args);
617
- this.listeners = listeners;
616
+ constructor(props) {
617
+ super(props);
618
+ this.listeners = props.listeners;
618
619
  this.gracePeriodTimeout = setTimeout(() => {
619
620
  this.listeners.onSessionGracePeriodElapsed();
620
621
  }, this.options.sessionDisconnectGraceMs);
@@ -635,7 +636,7 @@ var SessionNoConnection = class extends IdentifiedSession {
635
636
  var import_api = require("@opentelemetry/api");
636
637
 
637
638
  // package.json
638
- var version = "0.25.1";
639
+ var version = "0.25.2";
639
640
 
640
641
  // tracing/index.ts
641
642
  function createSessionTelemetryInfo(sessionId, to, from, propagationCtx) {
@@ -663,16 +664,16 @@ var SessionWaitingForHandshake = class extends CommonSession {
663
664
  conn;
664
665
  listeners;
665
666
  handshakeTimeout;
666
- constructor(conn, listeners, ...args) {
667
- super(...args);
668
- this.conn = conn;
669
- this.listeners = listeners;
667
+ constructor(props) {
668
+ super(props);
669
+ this.conn = props.conn;
670
+ this.listeners = props.listeners;
670
671
  this.handshakeTimeout = setTimeout(() => {
671
- listeners.onHandshakeTimeout();
672
+ this.listeners.onHandshakeTimeout();
672
673
  }, this.options.handshakeTimeoutMs);
673
674
  this.conn.addDataListener(this.onHandshakeData);
674
- this.conn.addErrorListener(listeners.onConnectionErrored);
675
- this.conn.addCloseListener(listeners.onConnectionClosed);
675
+ this.conn.addErrorListener(this.listeners.onConnectionErrored);
676
+ this.conn.addCloseListener(this.listeners.onConnectionClosed);
676
677
  }
677
678
  onHandshakeData = (msg) => {
678
679
  const parsedMsg = this.parseMsg(msg);
@@ -709,16 +710,16 @@ var SessionHandshaking = class extends IdentifiedSession {
709
710
  conn;
710
711
  listeners;
711
712
  handshakeTimeout;
712
- constructor(conn, listeners, ...args) {
713
- super(...args);
714
- this.conn = conn;
715
- this.listeners = listeners;
713
+ constructor(props) {
714
+ super(props);
715
+ this.conn = props.conn;
716
+ this.listeners = props.listeners;
716
717
  this.handshakeTimeout = setTimeout(() => {
717
- listeners.onHandshakeTimeout();
718
+ this.listeners.onHandshakeTimeout();
718
719
  }, this.options.handshakeTimeoutMs);
719
720
  this.conn.addDataListener(this.onHandshakeData);
720
- this.conn.addErrorListener(listeners.onConnectionErrored);
721
- this.conn.addCloseListener(listeners.onConnectionClosed);
721
+ this.conn.addErrorListener(this.listeners.onConnectionErrored);
722
+ this.conn.addCloseListener(this.listeners.onConnectionClosed);
722
723
  }
723
724
  onHandshakeData = (msg) => {
724
725
  const parsedMsg = this.parseMsg(msg);
@@ -750,16 +751,13 @@ var SessionConnected = class extends IdentifiedSession {
750
751
  state = "Connected" /* Connected */;
751
752
  conn;
752
753
  listeners;
753
- activeHeartbeatHandle;
754
- activeHeartbeatMisses = 0;
755
- passiveHeartbeatHandle;
756
- get isActivelyHeartbeating() {
757
- return this.activeHeartbeatHandle !== void 0;
758
- }
754
+ heartbeatHandle;
755
+ heartbeatMisses = 0;
756
+ isActivelyHeartbeating;
759
757
  updateBookkeeping(ack, seq) {
760
758
  this.sendBuffer = this.sendBuffer.filter((unacked) => unacked.seq >= ack);
761
759
  this.ack = seq + 1;
762
- this.activeHeartbeatMisses = 0;
760
+ this.heartbeatMisses = 0;
763
761
  }
764
762
  send(msg) {
765
763
  const constructedMsg = this.constructMsg(msg);
@@ -767,13 +765,13 @@ var SessionConnected = class extends IdentifiedSession {
767
765
  this.conn.send(this.options.codec.toBuffer(constructedMsg));
768
766
  return constructedMsg.id;
769
767
  }
770
- constructor(conn, listeners, ...args) {
771
- super(...args);
772
- this.conn = conn;
773
- this.listeners = listeners;
768
+ constructor(props) {
769
+ super(props);
770
+ this.conn = props.conn;
771
+ this.listeners = props.listeners;
774
772
  this.conn.addDataListener(this.onMessageData);
775
- this.conn.addCloseListener(listeners.onConnectionClosed);
776
- this.conn.addErrorListener(listeners.onConnectionErrored);
773
+ this.conn.addCloseListener(this.listeners.onConnectionClosed);
774
+ this.conn.addErrorListener(this.listeners.onConnectionErrored);
777
775
  if (this.sendBuffer.length > 0) {
778
776
  this.log?.debug(
779
777
  `sending ${this.sendBuffer.length} buffered messages`,
@@ -781,12 +779,11 @@ var SessionConnected = class extends IdentifiedSession {
781
779
  );
782
780
  }
783
781
  for (const msg of this.sendBuffer) {
784
- conn.send(this.options.codec.toBuffer(msg));
782
+ this.conn.send(this.options.codec.toBuffer(msg));
785
783
  }
786
- }
787
- startActiveHeartbeat() {
788
- this.activeHeartbeatHandle = setInterval(() => {
789
- const misses = this.activeHeartbeatMisses;
784
+ this.isActivelyHeartbeating = false;
785
+ this.heartbeatHandle = setInterval(() => {
786
+ const misses = this.heartbeatMisses;
790
787
  const missDuration = misses * this.options.heartbeatIntervalMs;
791
788
  if (misses >= this.options.heartbeatsUntilDead) {
792
789
  this.log?.info(
@@ -795,29 +792,18 @@ var SessionConnected = class extends IdentifiedSession {
795
792
  );
796
793
  this.telemetry.span.addEvent("closing connection due to inactivity");
797
794
  this.conn.close();
798
- clearInterval(this.activeHeartbeatHandle);
799
- this.activeHeartbeatHandle = void 0;
795
+ clearInterval(this.heartbeatHandle);
796
+ this.heartbeatHandle = void 0;
800
797
  return;
801
798
  }
802
- this.sendHeartbeat();
803
- this.activeHeartbeatMisses++;
799
+ if (this.isActivelyHeartbeating) {
800
+ this.sendHeartbeat();
801
+ }
802
+ this.heartbeatMisses++;
804
803
  }, this.options.heartbeatIntervalMs);
805
804
  }
806
- waitForNextHeartbeat() {
807
- const duration = this.options.heartbeatsUntilDead * this.options.heartbeatIntervalMs;
808
- if (this.passiveHeartbeatHandle) {
809
- clearTimeout(this.passiveHeartbeatHandle);
810
- this.passiveHeartbeatHandle = void 0;
811
- }
812
- this.passiveHeartbeatHandle = setTimeout(() => {
813
- this.log?.info(
814
- `closing connection to ${this.to} due to not receiving a heartbeat in the last ${duration}ms`,
815
- this.loggingMetadata
816
- );
817
- this.telemetry.span.addEvent("closing connection due to inactivity");
818
- this.conn.close();
819
- this.passiveHeartbeatHandle = void 0;
820
- }, duration);
805
+ startActiveHeartbeat() {
806
+ this.isActivelyHeartbeating = true;
821
807
  }
822
808
  sendHeartbeat() {
823
809
  this.log?.debug("sending heartbeat", this.loggingMetadata);
@@ -872,7 +858,6 @@ var SessionConnected = class extends IdentifiedSession {
872
858
  });
873
859
  if (!this.isActivelyHeartbeating) {
874
860
  this.sendHeartbeat();
875
- this.waitForNextHeartbeat();
876
861
  }
877
862
  };
878
863
  _handleStateExit() {
@@ -880,10 +865,8 @@ var SessionConnected = class extends IdentifiedSession {
880
865
  this.conn.removeDataListener(this.onMessageData);
881
866
  this.conn.removeCloseListener(this.listeners.onConnectionClosed);
882
867
  this.conn.removeErrorListener(this.listeners.onConnectionErrored);
883
- clearInterval(this.activeHeartbeatHandle);
884
- clearTimeout(this.passiveHeartbeatHandle);
885
- this.activeHeartbeatHandle = void 0;
886
- this.passiveHeartbeatHandle = void 0;
868
+ clearInterval(this.heartbeatHandle);
869
+ this.heartbeatHandle = void 0;
887
870
  }
888
871
  _handleClose() {
889
872
  super._handleClose();
@@ -891,52 +874,76 @@ var SessionConnected = class extends IdentifiedSession {
891
874
  }
892
875
  };
893
876
 
877
+ // transport/sessionStateMachine/SessionBackingOff.ts
878
+ var SessionBackingOff = class extends IdentifiedSession {
879
+ state = "BackingOff" /* BackingOff */;
880
+ listeners;
881
+ backoffTimeout;
882
+ constructor(props) {
883
+ super(props);
884
+ this.listeners = props.listeners;
885
+ this.backoffTimeout = setTimeout(() => {
886
+ this.listeners.onBackoffFinished();
887
+ }, props.backoffMs);
888
+ }
889
+ _handleClose() {
890
+ super._handleClose();
891
+ }
892
+ _handleStateExit() {
893
+ super._handleStateExit();
894
+ if (this.backoffTimeout) {
895
+ clearTimeout(this.backoffTimeout);
896
+ this.backoffTimeout = void 0;
897
+ }
898
+ }
899
+ };
900
+
894
901
  // transport/sessionStateMachine/transitions.ts
895
902
  function inheritSharedSession(session) {
896
- return [
897
- session.id,
898
- session.from,
899
- session.to,
900
- session.seq,
901
- session.ack,
902
- session.sendBuffer,
903
- session.telemetry,
904
- session.options,
905
- session.log
906
- ];
903
+ return {
904
+ id: session.id,
905
+ from: session.from,
906
+ to: session.to,
907
+ seq: session.seq,
908
+ ack: session.ack,
909
+ sendBuffer: session.sendBuffer,
910
+ telemetry: session.telemetry,
911
+ options: session.options,
912
+ log: session.log
913
+ };
907
914
  }
908
915
  var SessionStateGraph = {
909
916
  entrypoints: {
910
- NoConnection(to, from, listeners, options, log) {
917
+ NoConnection: (to, from, listeners, options, log) => {
911
918
  const id = `session-${generateId()}`;
912
919
  const telemetry = createSessionTelemetryInfo(id, to, from);
913
920
  const sendBuffer = [];
914
- const session = new SessionNoConnection(
921
+ const session = new SessionNoConnection({
915
922
  listeners,
916
923
  id,
917
924
  from,
918
925
  to,
919
- 0,
920
- 0,
926
+ seq: 0,
927
+ ack: 0,
921
928
  sendBuffer,
922
929
  telemetry,
923
930
  options,
924
931
  log
925
- );
932
+ });
926
933
  session.log?.info(`session ${session.id} created in NoConnection state`, {
927
934
  ...session.loggingMetadata,
928
935
  tags: ["state-transition"]
929
936
  });
930
937
  return session;
931
938
  },
932
- WaitingForHandshake(from, conn, listeners, options, log) {
933
- const session = new SessionWaitingForHandshake(
939
+ WaitingForHandshake: (from, conn, listeners, options, log) => {
940
+ const session = new SessionWaitingForHandshake({
934
941
  conn,
935
942
  listeners,
936
943
  from,
937
944
  options,
938
945
  log
939
- );
946
+ });
940
947
  session.log?.info(`session created in WaitingForHandshake state`, {
941
948
  ...session.loggingMetadata,
942
949
  tags: ["state-transition"]
@@ -948,16 +955,33 @@ var SessionStateGraph = {
948
955
  // After a session is transitioned, any usage of the old session will throw.
949
956
  transition: {
950
957
  // happy path transitions
951
- NoConnectionToConnecting(oldSession, connPromise, listeners) {
958
+ NoConnectionToBackingOff: (oldSession, backoffMs, listeners) => {
952
959
  const carriedState = inheritSharedSession(oldSession);
953
960
  oldSession._handleStateExit();
954
- const session = new SessionConnecting(
955
- connPromise,
961
+ const session = new SessionBackingOff({
962
+ backoffMs,
956
963
  listeners,
957
964
  ...carriedState
965
+ });
966
+ session.log?.info(
967
+ `session ${session.id} transition from NoConnection to BackingOff`,
968
+ {
969
+ ...session.loggingMetadata,
970
+ tags: ["state-transition"]
971
+ }
958
972
  );
973
+ return session;
974
+ },
975
+ BackingOffToConnecting: (oldSession, connPromise, listeners) => {
976
+ const carriedState = inheritSharedSession(oldSession);
977
+ oldSession._handleStateExit();
978
+ const session = new SessionConnecting({
979
+ connPromise,
980
+ listeners,
981
+ ...carriedState
982
+ });
959
983
  session.log?.info(
960
- `session ${session.id} transition from NoConnection to Connecting`,
984
+ `session ${session.id} transition from BackingOff to Connecting`,
961
985
  {
962
986
  ...session.loggingMetadata,
963
987
  tags: ["state-transition"]
@@ -965,10 +989,14 @@ var SessionStateGraph = {
965
989
  );
966
990
  return session;
967
991
  },
968
- ConnectingToHandshaking(oldSession, conn, listeners) {
992
+ ConnectingToHandshaking: (oldSession, conn, listeners) => {
969
993
  const carriedState = inheritSharedSession(oldSession);
970
994
  oldSession._handleStateExit();
971
- const session = new SessionHandshaking(conn, listeners, ...carriedState);
995
+ const session = new SessionHandshaking({
996
+ conn,
997
+ listeners,
998
+ ...carriedState
999
+ });
972
1000
  session.log?.info(
973
1001
  `session ${session.id} transition from Connecting to Handshaking`,
974
1002
  {
@@ -978,11 +1006,15 @@ var SessionStateGraph = {
978
1006
  );
979
1007
  return session;
980
1008
  },
981
- HandshakingToConnected(oldSession, listeners) {
1009
+ HandshakingToConnected: (oldSession, listeners) => {
982
1010
  const carriedState = inheritSharedSession(oldSession);
983
1011
  const conn = oldSession.conn;
984
1012
  oldSession._handleStateExit();
985
- const session = new SessionConnected(conn, listeners, ...carriedState);
1013
+ const session = new SessionConnected({
1014
+ conn,
1015
+ listeners,
1016
+ ...carriedState
1017
+ });
986
1018
  session.log?.info(
987
1019
  `session ${session.id} transition from Handshaking to Connected`,
988
1020
  {
@@ -992,7 +1024,7 @@ var SessionStateGraph = {
992
1024
  );
993
1025
  return session;
994
1026
  },
995
- WaitingForHandshakeToConnected(pendingSession, oldSession, sessionId, to, propagationCtx, listeners) {
1027
+ WaitingForHandshakeToConnected: (pendingSession, oldSession, sessionId, to, propagationCtx, listeners) => {
996
1028
  const conn = pendingSession.conn;
997
1029
  const { from, options } = pendingSession;
998
1030
  const carriedState = oldSession ? (
@@ -1000,21 +1032,30 @@ var SessionStateGraph = {
1000
1032
  inheritSharedSession(oldSession)
1001
1033
  ) : (
1002
1034
  // old session does not exist, create new state
1003
- [
1004
- sessionId,
1035
+ {
1036
+ id: sessionId,
1005
1037
  from,
1006
1038
  to,
1007
- 0,
1008
- 0,
1009
- [],
1010
- createSessionTelemetryInfo(sessionId, to, from, propagationCtx),
1039
+ seq: 0,
1040
+ ack: 0,
1041
+ sendBuffer: [],
1042
+ telemetry: createSessionTelemetryInfo(
1043
+ sessionId,
1044
+ to,
1045
+ from,
1046
+ propagationCtx
1047
+ ),
1011
1048
  options,
1012
- pendingSession.log
1013
- ]
1049
+ log: pendingSession.log
1050
+ }
1014
1051
  );
1015
1052
  pendingSession._handleStateExit();
1016
1053
  oldSession?._handleStateExit();
1017
- const session = new SessionConnected(conn, listeners, ...carriedState);
1054
+ const session = new SessionConnected({
1055
+ conn,
1056
+ listeners,
1057
+ ...carriedState
1058
+ });
1018
1059
  session.log?.info(
1019
1060
  `session ${session.id} transition from WaitingForHandshake to Connected`,
1020
1061
  {
@@ -1025,11 +1066,24 @@ var SessionStateGraph = {
1025
1066
  return session;
1026
1067
  },
1027
1068
  // disconnect paths
1028
- ConnectingToNoConnection(oldSession, listeners) {
1069
+ BackingOffToNoConnection: (oldSession, listeners) => {
1070
+ const carriedState = inheritSharedSession(oldSession);
1071
+ oldSession._handleStateExit();
1072
+ const session = new SessionNoConnection({ listeners, ...carriedState });
1073
+ session.log?.info(
1074
+ `session ${session.id} transition from BackingOff to NoConnection`,
1075
+ {
1076
+ ...session.loggingMetadata,
1077
+ tags: ["state-transition"]
1078
+ }
1079
+ );
1080
+ return session;
1081
+ },
1082
+ ConnectingToNoConnection: (oldSession, listeners) => {
1029
1083
  const carriedState = inheritSharedSession(oldSession);
1030
1084
  oldSession.bestEffortClose();
1031
1085
  oldSession._handleStateExit();
1032
- const session = new SessionNoConnection(listeners, ...carriedState);
1086
+ const session = new SessionNoConnection({ listeners, ...carriedState });
1033
1087
  session.log?.info(
1034
1088
  `session ${session.id} transition from Connecting to NoConnection`,
1035
1089
  {
@@ -1039,11 +1093,11 @@ var SessionStateGraph = {
1039
1093
  );
1040
1094
  return session;
1041
1095
  },
1042
- HandshakingToNoConnection(oldSession, listeners) {
1096
+ HandshakingToNoConnection: (oldSession, listeners) => {
1043
1097
  const carriedState = inheritSharedSession(oldSession);
1044
1098
  oldSession.conn.close();
1045
1099
  oldSession._handleStateExit();
1046
- const session = new SessionNoConnection(listeners, ...carriedState);
1100
+ const session = new SessionNoConnection({ listeners, ...carriedState });
1047
1101
  session.log?.info(
1048
1102
  `session ${session.id} transition from Handshaking to NoConnection`,
1049
1103
  {
@@ -1053,11 +1107,11 @@ var SessionStateGraph = {
1053
1107
  );
1054
1108
  return session;
1055
1109
  },
1056
- ConnectedToNoConnection(oldSession, listeners) {
1110
+ ConnectedToNoConnection: (oldSession, listeners) => {
1057
1111
  const carriedState = inheritSharedSession(oldSession);
1058
1112
  oldSession.conn.close();
1059
1113
  oldSession._handleStateExit();
1060
- const session = new SessionNoConnection(listeners, ...carriedState);
1114
+ const session = new SessionNoConnection({ listeners, ...carriedState });
1061
1115
  session.log?.info(
1062
1116
  `session ${session.id} transition from Connected to NoConnection`,
1063
1117
  {
@@ -1069,6 +1123,31 @@ var SessionStateGraph = {
1069
1123
  }
1070
1124
  }
1071
1125
  };
1126
+ var transitions = SessionStateGraph.transition;
1127
+ var ClientSessionStateGraph = {
1128
+ entrypoint: SessionStateGraph.entrypoints.NoConnection,
1129
+ transition: {
1130
+ // happy paths
1131
+ NoConnectionToBackingOff: transitions.NoConnectionToBackingOff,
1132
+ BackingOffToConnecting: transitions.BackingOffToConnecting,
1133
+ ConnectingToHandshaking: transitions.ConnectingToHandshaking,
1134
+ HandshakingToConnected: transitions.HandshakingToConnected,
1135
+ // disconnect paths
1136
+ BackingOffToNoConnection: transitions.BackingOffToNoConnection,
1137
+ ConnectingToNoConnection: transitions.ConnectingToNoConnection,
1138
+ HandshakingToNoConnection: transitions.HandshakingToNoConnection,
1139
+ ConnectedToNoConnection: transitions.ConnectedToNoConnection
1140
+ }
1141
+ };
1142
+ var ServerSessionStateGraph = {
1143
+ entrypoint: SessionStateGraph.entrypoints.WaitingForHandshake,
1144
+ transition: {
1145
+ // happy paths
1146
+ WaitingForHandshakeToConnected: transitions.WaitingForHandshakeToConnected,
1147
+ // disconnect paths
1148
+ ConnectedToNoConnection: transitions.ConnectedToNoConnection
1149
+ }
1150
+ };
1072
1151
 
1073
1152
  // transport/transport.ts
1074
1153
  var Transport = class {
@@ -1244,9 +1323,11 @@ var ServerTransport = class extends Transport {
1244
1323
  * A map of session handshake data for each session.
1245
1324
  */
1246
1325
  sessionHandshakeMetadata = /* @__PURE__ */ new Map();
1326
+ sessions = /* @__PURE__ */ new Map();
1247
1327
  pendingSessions = /* @__PURE__ */ new Set();
1248
1328
  constructor(clientId, providedOptions) {
1249
1329
  super(clientId, providedOptions);
1330
+ this.sessions = /* @__PURE__ */ new Map();
1250
1331
  this.options = {
1251
1332
  ...defaultServerTransportOptions,
1252
1333
  ...providedOptions
@@ -1297,7 +1378,7 @@ var ServerTransport = class extends Transport {
1297
1378
  clientId: this.clientId
1298
1379
  });
1299
1380
  let receivedHandshake = false;
1300
- const pendingSession = SessionStateGraph.entrypoints.WaitingForHandshake(
1381
+ const pendingSession = ServerSessionStateGraph.entrypoint(
1301
1382
  this.clientId,
1302
1383
  conn,
1303
1384
  {
@@ -1451,26 +1532,15 @@ var ServerTransport = class extends Transport {
1451
1532
  );
1452
1533
  return;
1453
1534
  }
1454
- if (oldSession.state === "Connected" /* Connected */) {
1455
- const noConnectionSession = SessionStateGraph.transition.ConnectedToNoConnection(oldSession, {
1456
- onSessionGracePeriodElapsed: () => {
1457
- this.onSessionGracePeriodElapsed(noConnectionSession);
1458
- }
1459
- });
1460
- oldSession = noConnectionSession;
1461
- } else if (oldSession.state === "Handshaking" /* Handshaking */) {
1462
- const noConnectionSession = SessionStateGraph.transition.HandshakingToNoConnection(oldSession, {
1463
- onSessionGracePeriodElapsed: () => {
1464
- this.onSessionGracePeriodElapsed(noConnectionSession);
1465
- }
1466
- });
1467
- oldSession = noConnectionSession;
1468
- } else if (oldSession.state === "Connecting" /* Connecting */) {
1469
- const noConnectionSession = SessionStateGraph.transition.ConnectingToNoConnection(oldSession, {
1470
- onSessionGracePeriodElapsed: () => {
1471
- this.onSessionGracePeriodElapsed(noConnectionSession);
1535
+ if (oldSession.state !== "NoConnection" /* NoConnection */) {
1536
+ const noConnectionSession = ServerSessionStateGraph.transition.ConnectedToNoConnection(
1537
+ oldSession,
1538
+ {
1539
+ onSessionGracePeriodElapsed: () => {
1540
+ this.onSessionGracePeriodElapsed(noConnectionSession);
1541
+ }
1472
1542
  }
1473
- });
1543
+ );
1474
1544
  oldSession = noConnectionSession;
1475
1545
  }
1476
1546
  this.updateSession(oldSession);
@@ -1519,7 +1589,7 @@ var ServerTransport = class extends Transport {
1519
1589
  }
1520
1590
  });
1521
1591
  session.sendHandshake(responseMsg);
1522
- const connectedSession = SessionStateGraph.transition.WaitingForHandshakeToConnected(
1592
+ const connectedSession = ServerSessionStateGraph.transition.WaitingForHandshakeToConnected(
1523
1593
  session,
1524
1594
  // by this point oldSession is either no connection or we dont have an old session
1525
1595
  oldSession,