@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,7 +1,7 @@
1
- import { C as ClientTransport } from '../../../client-0f636b3a.js';
1
+ import { C as ClientTransport } from '../../../client-654098be.js';
2
2
  import { c as TransportClientId } from '../../../message-57296605.js';
3
- import { b as ProvidedClientTransportOptions } from '../../../handshake-8752f79e.js';
4
- import { W as WebSocketConnection } from '../../../connection-07e97a79.js';
3
+ import { b as ProvidedClientTransportOptions } from '../../../handshake-1a86f06d.js';
4
+ import { W as WebSocketConnection } from '../../../connection-bc2454dc.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-0f636b3a.js';
1
+ import { C as ClientTransport } from '../../../client-654098be.js';
2
2
  import { c as TransportClientId } from '../../../message-57296605.js';
3
- import { b as ProvidedClientTransportOptions } from '../../../handshake-8752f79e.js';
4
- import { W as WebSocketConnection } from '../../../connection-07e97a79.js';
3
+ import { b as ProvidedClientTransportOptions } from '../../../handshake-1a86f06d.js';
4
+ import { W as WebSocketConnection } from '../../../connection-bc2454dc.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-XRI2BXMM.js";
3
+ } from "../../../chunk-IV27BICV.js";
4
4
  import {
5
5
  WebSocketConnection
6
- } from "../../../chunk-AYIMQWS7.js";
7
- import "../../../chunk-6UVTCZ6K.js";
6
+ } from "../../../chunk-AWCUCZY4.js";
7
+ import "../../../chunk-M5X4JTU3.js";
8
8
  import "../../../chunk-TAH2GVTJ.js";
9
- import "../../../chunk-M43R4RPL.js";
10
- import "../../../chunk-UQOD22AN.js";
9
+ import "../../../chunk-NC54BC47.js";
10
+ import "../../../chunk-M75K5TJS.js";
11
11
  import "../../../chunk-4PVU7J25.js";
12
12
 
13
13
  // transport/impls/ws/client.ts
@@ -322,6 +322,7 @@ var defaultTransportOptions = {
322
322
  sessionDisconnectGraceMs: 5e3,
323
323
  connectionTimeoutMs: 2e3,
324
324
  handshakeTimeoutMs: 1e3,
325
+ enableTransparentSessionReconnects: true,
325
326
  codec: NaiveJsonCodec
326
327
  };
327
328
  var defaultConnectionRetryOptions = {
@@ -573,9 +574,32 @@ var IdentifiedSession = class extends CommonSession {
573
574
  this.telemetry.span.end();
574
575
  }
575
576
  };
577
+ var IdentifiedSessionWithGracePeriod = class extends IdentifiedSession {
578
+ graceExpiryTime;
579
+ gracePeriodTimeout;
580
+ listeners;
581
+ constructor(props) {
582
+ super(props);
583
+ this.listeners = props.listeners;
584
+ this.graceExpiryTime = props.graceExpiryTime;
585
+ this.gracePeriodTimeout = setTimeout(() => {
586
+ this.listeners.onSessionGracePeriodElapsed();
587
+ }, this.graceExpiryTime - Date.now());
588
+ }
589
+ _handleStateExit() {
590
+ super._handleStateExit();
591
+ if (this.gracePeriodTimeout) {
592
+ clearTimeout(this.gracePeriodTimeout);
593
+ this.gracePeriodTimeout = void 0;
594
+ }
595
+ }
596
+ _handleClose() {
597
+ super._handleClose();
598
+ }
599
+ };
576
600
 
577
601
  // transport/sessionStateMachine/SessionConnecting.ts
578
- var SessionConnecting = class extends IdentifiedSession {
602
+ var SessionConnecting = class extends IdentifiedSessionWithGracePeriod {
579
603
  state = "Connecting" /* Connecting */;
580
604
  connPromise;
581
605
  listeners;
@@ -608,8 +632,10 @@ var SessionConnecting = class extends IdentifiedSession {
608
632
  }
609
633
  _handleStateExit() {
610
634
  super._handleStateExit();
611
- clearTimeout(this.connectionTimeout);
612
- this.connectionTimeout = void 0;
635
+ if (this.connectionTimeout) {
636
+ clearTimeout(this.connectionTimeout);
637
+ this.connectionTimeout = void 0;
638
+ }
613
639
  }
614
640
  _handleClose() {
615
641
  this.bestEffortClose();
@@ -618,26 +644,13 @@ var SessionConnecting = class extends IdentifiedSession {
618
644
  };
619
645
 
620
646
  // transport/sessionStateMachine/SessionNoConnection.ts
621
- var SessionNoConnection = class extends IdentifiedSession {
647
+ var SessionNoConnection = class extends IdentifiedSessionWithGracePeriod {
622
648
  state = "NoConnection" /* NoConnection */;
623
- listeners;
624
- gracePeriodTimeout;
625
- constructor(props) {
626
- super(props);
627
- this.listeners = props.listeners;
628
- this.gracePeriodTimeout = setTimeout(() => {
629
- this.listeners.onSessionGracePeriodElapsed();
630
- }, this.options.sessionDisconnectGraceMs);
631
- }
632
649
  _handleClose() {
633
650
  super._handleClose();
634
651
  }
635
652
  _handleStateExit() {
636
653
  super._handleStateExit();
637
- if (this.gracePeriodTimeout) {
638
- clearTimeout(this.gracePeriodTimeout);
639
- this.gracePeriodTimeout = void 0;
640
- }
641
654
  }
642
655
  };
643
656
 
@@ -645,7 +658,7 @@ var SessionNoConnection = class extends IdentifiedSession {
645
658
  var import_api = require("@opentelemetry/api");
646
659
 
647
660
  // package.json
648
- var version = "0.26.1";
661
+ var version = "0.26.2";
649
662
 
650
663
  // tracing/index.ts
651
664
  function createSessionTelemetryInfo(sessionId, to, from, propagationCtx) {
@@ -717,7 +730,7 @@ var SessionWaitingForHandshake = class extends CommonSession {
717
730
  };
718
731
 
719
732
  // transport/sessionStateMachine/SessionHandshaking.ts
720
- var SessionHandshaking = class extends IdentifiedSession {
733
+ var SessionHandshaking = class extends IdentifiedSessionWithGracePeriod {
721
734
  state = "Handshaking" /* Handshaking */;
722
735
  conn;
723
736
  listeners;
@@ -752,7 +765,10 @@ var SessionHandshaking = class extends IdentifiedSession {
752
765
  this.conn.removeDataListener(this.onHandshakeData);
753
766
  this.conn.removeErrorListener(this.listeners.onConnectionErrored);
754
767
  this.conn.removeCloseListener(this.listeners.onConnectionClosed);
755
- clearTimeout(this.handshakeTimeout);
768
+ if (this.handshakeTimeout) {
769
+ clearTimeout(this.handshakeTimeout);
770
+ this.handshakeTimeout = void 0;
771
+ }
756
772
  }
757
773
  _handleClose() {
758
774
  super._handleClose();
@@ -832,8 +848,10 @@ var SessionConnected = class extends IdentifiedSession {
832
848
  }
833
849
  onMessageData = (msg) => {
834
850
  const parsedMsg = this.parseMsg(msg);
835
- if (parsedMsg === null)
851
+ if (parsedMsg === null) {
852
+ this.listeners.onInvalidMessage("could not parse message");
836
853
  return;
854
+ }
837
855
  if (parsedMsg.seq !== this.ack) {
838
856
  if (parsedMsg.seq < this.ack) {
839
857
  this.log?.debug(
@@ -890,7 +908,7 @@ var SessionConnected = class extends IdentifiedSession {
890
908
  };
891
909
 
892
910
  // transport/sessionStateMachine/SessionBackingOff.ts
893
- var SessionBackingOff = class extends IdentifiedSession {
911
+ var SessionBackingOff = class extends IdentifiedSessionWithGracePeriod {
894
912
  state = "BackingOff" /* BackingOff */;
895
913
  listeners;
896
914
  backoffTimeout;
@@ -927,6 +945,12 @@ function inheritSharedSession(session) {
927
945
  log: session.log
928
946
  };
929
947
  }
948
+ function inheritSharedSessionWithGrace(session) {
949
+ return {
950
+ ...inheritSharedSession(session),
951
+ graceExpiryTime: session.graceExpiryTime
952
+ };
953
+ }
930
954
  var SessionStateGraph = {
931
955
  entrypoints: {
932
956
  NoConnection: (to, from, listeners, options, log) => {
@@ -940,6 +964,7 @@ var SessionStateGraph = {
940
964
  to,
941
965
  seq: 0,
942
966
  ack: 0,
967
+ graceExpiryTime: Date.now() + options.sessionDisconnectGraceMs,
943
968
  sendBuffer,
944
969
  telemetry,
945
970
  options,
@@ -971,7 +996,7 @@ var SessionStateGraph = {
971
996
  transition: {
972
997
  // happy path transitions
973
998
  NoConnectionToBackingOff: (oldSession, backoffMs, listeners) => {
974
- const carriedState = inheritSharedSession(oldSession);
999
+ const carriedState = inheritSharedSessionWithGrace(oldSession);
975
1000
  oldSession._handleStateExit();
976
1001
  const session = new SessionBackingOff({
977
1002
  backoffMs,
@@ -988,7 +1013,7 @@ var SessionStateGraph = {
988
1013
  return session;
989
1014
  },
990
1015
  BackingOffToConnecting: (oldSession, connPromise, listeners) => {
991
- const carriedState = inheritSharedSession(oldSession);
1016
+ const carriedState = inheritSharedSessionWithGrace(oldSession);
992
1017
  oldSession._handleStateExit();
993
1018
  const session = new SessionConnecting({
994
1019
  connPromise,
@@ -1005,7 +1030,7 @@ var SessionStateGraph = {
1005
1030
  return session;
1006
1031
  },
1007
1032
  ConnectingToHandshaking: (oldSession, conn, listeners) => {
1008
- const carriedState = inheritSharedSession(oldSession);
1033
+ const carriedState = inheritSharedSessionWithGrace(oldSession);
1009
1034
  oldSession._handleStateExit();
1010
1035
  const session = new SessionHandshaking({
1011
1036
  conn,
@@ -1082,9 +1107,12 @@ var SessionStateGraph = {
1082
1107
  },
1083
1108
  // disconnect paths
1084
1109
  BackingOffToNoConnection: (oldSession, listeners) => {
1085
- const carriedState = inheritSharedSession(oldSession);
1110
+ const carriedState = inheritSharedSessionWithGrace(oldSession);
1086
1111
  oldSession._handleStateExit();
1087
- const session = new SessionNoConnection({ listeners, ...carriedState });
1112
+ const session = new SessionNoConnection({
1113
+ listeners,
1114
+ ...carriedState
1115
+ });
1088
1116
  session.log?.info(
1089
1117
  `session ${session.id} transition from BackingOff to NoConnection`,
1090
1118
  {
@@ -1095,10 +1123,13 @@ var SessionStateGraph = {
1095
1123
  return session;
1096
1124
  },
1097
1125
  ConnectingToNoConnection: (oldSession, listeners) => {
1098
- const carriedState = inheritSharedSession(oldSession);
1126
+ const carriedState = inheritSharedSessionWithGrace(oldSession);
1099
1127
  oldSession.bestEffortClose();
1100
1128
  oldSession._handleStateExit();
1101
- const session = new SessionNoConnection({ listeners, ...carriedState });
1129
+ const session = new SessionNoConnection({
1130
+ listeners,
1131
+ ...carriedState
1132
+ });
1102
1133
  session.log?.info(
1103
1134
  `session ${session.id} transition from Connecting to NoConnection`,
1104
1135
  {
@@ -1109,10 +1140,13 @@ var SessionStateGraph = {
1109
1140
  return session;
1110
1141
  },
1111
1142
  HandshakingToNoConnection: (oldSession, listeners) => {
1112
- const carriedState = inheritSharedSession(oldSession);
1143
+ const carriedState = inheritSharedSessionWithGrace(oldSession);
1113
1144
  oldSession.conn.close();
1114
1145
  oldSession._handleStateExit();
1115
- const session = new SessionNoConnection({ listeners, ...carriedState });
1146
+ const session = new SessionNoConnection({
1147
+ listeners,
1148
+ ...carriedState
1149
+ });
1116
1150
  session.log?.info(
1117
1151
  `session ${session.id} transition from Handshaking to NoConnection`,
1118
1152
  {
@@ -1124,9 +1158,14 @@ var SessionStateGraph = {
1124
1158
  },
1125
1159
  ConnectedToNoConnection: (oldSession, listeners) => {
1126
1160
  const carriedState = inheritSharedSession(oldSession);
1161
+ const graceExpiryTime = Date.now() + oldSession.options.sessionDisconnectGraceMs;
1127
1162
  oldSession.conn.close();
1128
1163
  oldSession._handleStateExit();
1129
- const session = new SessionNoConnection({ listeners, ...carriedState });
1164
+ const session = new SessionNoConnection({
1165
+ listeners,
1166
+ graceExpiryTime,
1167
+ ...carriedState
1168
+ });
1130
1169
  session.log?.info(
1131
1170
  `session ${session.id} transition from Connected to NoConnection`,
1132
1171
  {
@@ -1143,24 +1182,42 @@ var ClientSessionStateGraph = {
1143
1182
  entrypoint: SessionStateGraph.entrypoints.NoConnection,
1144
1183
  transition: {
1145
1184
  // happy paths
1185
+ // NoConnection -> BackingOff: attempt to connect
1146
1186
  NoConnectionToBackingOff: transitions.NoConnectionToBackingOff,
1187
+ // BackingOff -> Connecting: backoff period elapsed, start connection
1147
1188
  BackingOffToConnecting: transitions.BackingOffToConnecting,
1189
+ // Connecting -> Handshaking: connection established, start handshake
1148
1190
  ConnectingToHandshaking: transitions.ConnectingToHandshaking,
1191
+ // Handshaking -> Connected: handshake complete, session ready
1149
1192
  HandshakingToConnected: transitions.HandshakingToConnected,
1150
1193
  // disconnect paths
1194
+ // BackingOff -> NoConnection: unused
1151
1195
  BackingOffToNoConnection: transitions.BackingOffToNoConnection,
1196
+ // Connecting -> NoConnection: connection failed or connection timeout
1152
1197
  ConnectingToNoConnection: transitions.ConnectingToNoConnection,
1198
+ // Handshaking -> NoConnection: connection closed or handshake timeout
1153
1199
  HandshakingToNoConnection: transitions.HandshakingToNoConnection,
1200
+ // Connected -> NoConnection: connection closed
1154
1201
  ConnectedToNoConnection: transitions.ConnectedToNoConnection
1202
+ // destroy/close paths
1203
+ // NoConnection -> x: grace period elapsed
1204
+ // BackingOff -> x: grace period elapsed
1205
+ // Connecting -> x: grace period elapsed
1206
+ // Handshaking -> x: grace period elapsed or invalid handshake message or handshake rejection
1207
+ // Connected -> x: grace period elapsed or invalid message
1155
1208
  }
1156
1209
  };
1157
1210
  var ServerSessionStateGraph = {
1158
1211
  entrypoint: SessionStateGraph.entrypoints.WaitingForHandshake,
1159
1212
  transition: {
1160
1213
  // happy paths
1214
+ // WaitingForHandshake -> Connected: handshake complete, session ready
1161
1215
  WaitingForHandshakeToConnected: transitions.WaitingForHandshakeToConnected,
1162
1216
  // disconnect paths
1217
+ // Connected -> NoConnection: connection closed
1163
1218
  ConnectedToNoConnection: transitions.ConnectedToNoConnection
1219
+ // destroy/close paths
1220
+ // WaitingForHandshake -> x: handshake timeout elapsed or invalid handshake message or handshake rejection or connection closed
1164
1221
  }
1165
1222
  };
1166
1223
 
@@ -1523,7 +1580,7 @@ var ServerTransport = class extends Transport {
1523
1580
  let connectCase = "new session";
1524
1581
  const clientNextExpectedSeq = msg.payload.expectedSessionState.nextExpectedSeq;
1525
1582
  const clientNextSentSeq = msg.payload.expectedSessionState.nextSentSeq ?? 0;
1526
- if (oldSession && oldSession.id === msg.payload.sessionId) {
1583
+ if (this.options.enableTransparentSessionReconnects && oldSession && oldSession.id === msg.payload.sessionId) {
1527
1584
  connectCase = "transparent reconnection";
1528
1585
  const ourNextSeq = oldSession.nextSeq();
1529
1586
  const ourAck = oldSession.ack;
@@ -1582,10 +1639,11 @@ var ServerTransport = class extends Transport {
1582
1639
  }
1583
1640
  if (!oldSession && (clientNextSentSeq > 0 || clientNextExpectedSeq > 0)) {
1584
1641
  connectCase = "unknown session";
1642
+ const rejectionMessage = this.options.enableTransparentSessionReconnects ? `client is trying to reconnect to a session the server don't know about: ${msg.payload.sessionId}` : `client is attempting a transparent reconnect to a session but the server does not support it: ${msg.payload.sessionId}`;
1585
1643
  this.rejectHandshakeRequest(
1586
1644
  session,
1587
1645
  msg.from,
1588
- `client is trying to reconnect to a session the server don't know about: ${msg.payload.sessionId}`,
1646
+ rejectionMessage,
1589
1647
  "SESSION_STATE_MISMATCH",
1590
1648
  {
1591
1649
  ...session.loggingMetadata,
@@ -1670,16 +1728,19 @@ var ServerTransport = class extends Transport {
1670
1728
  return false;
1671
1729
  }
1672
1730
  const previousParsedMetadata = existingSession ? this.sessionHandshakeMetadata.get(existingSession.to) : void 0;
1673
- const parsedMetadata = await this.handshakeExtensions.validate(
1731
+ const parsedMetadataOrFailureCode = await this.handshakeExtensions.validate(
1674
1732
  rawMetadata,
1675
1733
  previousParsedMetadata
1676
1734
  );
1677
- if (import_value2.Value.Check(HandshakeErrorCustomHandlerFatalResponseCodes, parsedMetadata)) {
1735
+ if (import_value2.Value.Check(
1736
+ HandshakeErrorCustomHandlerFatalResponseCodes,
1737
+ parsedMetadataOrFailureCode
1738
+ )) {
1678
1739
  this.rejectHandshakeRequest(
1679
1740
  handshakingSession,
1680
1741
  from,
1681
1742
  "rejected by handshake handler",
1682
- parsedMetadata,
1743
+ parsedMetadataOrFailureCode,
1683
1744
  {
1684
1745
  ...handshakingSession.loggingMetadata,
1685
1746
  connectedTo: from,
@@ -1688,7 +1749,7 @@ var ServerTransport = class extends Transport {
1688
1749
  );
1689
1750
  return false;
1690
1751
  }
1691
- return parsedMetadata;
1752
+ return parsedMetadataOrFailureCode;
1692
1753
  }
1693
1754
  };
1694
1755