@replit/river 0.24.3 → 0.25.0

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 (63) hide show
  1. package/dist/{chunk-XKHLA5MP.js → chunk-4GCILF7L.js} +4 -4
  2. package/dist/{chunk-DZNP3EI5.js → chunk-6NPQ43ZP.js} +2 -2
  3. package/dist/{chunk-DZNP3EI5.js.map → chunk-6NPQ43ZP.js.map} +1 -1
  4. package/dist/{chunk-EHXKU4TW.js → chunk-BMSEVPGM.js} +2 -2
  5. package/dist/{chunk-FKBXIWWN.js → chunk-FEMGSUEE.js} +3 -3
  6. package/dist/{chunk-LSHUPI6U.js → chunk-JTZVFCMT.js} +2 -2
  7. package/dist/{chunk-W3CY6PNC.js → chunk-N2UT2H2D.js} +28 -23
  8. package/dist/chunk-N2UT2H2D.js.map +1 -0
  9. package/dist/{chunk-KVLCQ24J.js → chunk-XVGZYVNR.js} +34 -13
  10. package/dist/chunk-XVGZYVNR.js.map +1 -0
  11. package/dist/{client-2ba72e89.d.ts → client-1321630c.d.ts} +1 -1
  12. package/dist/{connection-55cba970.d.ts → connection-bd907ca6.d.ts} +1 -1
  13. package/dist/{handshake-0b88e8fc.d.ts → handshake-3772d7ca.d.ts} +4 -2
  14. package/dist/router/index.cjs +1 -1
  15. package/dist/router/index.cjs.map +1 -1
  16. package/dist/router/index.d.cts +7 -7
  17. package/dist/router/index.d.ts +7 -7
  18. package/dist/router/index.js +2 -2
  19. package/dist/{server-732e7014.d.ts → server-f0fd2b98.d.ts} +1 -1
  20. package/dist/{services-adfd0bc3.d.ts → services-8d14ae16.d.ts} +2 -2
  21. package/dist/transport/impls/ws/client.cjs +33 -12
  22. package/dist/transport/impls/ws/client.cjs.map +1 -1
  23. package/dist/transport/impls/ws/client.d.cts +3 -3
  24. package/dist/transport/impls/ws/client.d.ts +3 -3
  25. package/dist/transport/impls/ws/client.js +7 -7
  26. package/dist/transport/impls/ws/server.cjs +57 -31
  27. package/dist/transport/impls/ws/server.cjs.map +1 -1
  28. package/dist/transport/impls/ws/server.d.cts +3 -3
  29. package/dist/transport/impls/ws/server.d.ts +3 -3
  30. package/dist/transport/impls/ws/server.js +5 -5
  31. package/dist/transport/index.cjs +57 -31
  32. package/dist/transport/index.cjs.map +1 -1
  33. package/dist/transport/index.d.cts +3 -3
  34. package/dist/transport/index.d.ts +3 -3
  35. package/dist/transport/index.js +7 -7
  36. package/dist/util/testHelpers.cjs +33 -27
  37. package/dist/util/testHelpers.cjs.map +1 -1
  38. package/dist/util/testHelpers.d.cts +4 -7
  39. package/dist/util/testHelpers.d.ts +4 -7
  40. package/dist/util/testHelpers.js +3 -14
  41. package/dist/util/testHelpers.js.map +1 -1
  42. package/package.json +1 -1
  43. package/dist/chunk-KVLCQ24J.js.map +0 -1
  44. package/dist/chunk-TDFWZIXR.js +0 -106
  45. package/dist/chunk-TDFWZIXR.js.map +0 -1
  46. package/dist/chunk-W3CY6PNC.js.map +0 -1
  47. package/dist/connection-c6db05d9.d.ts +0 -31
  48. package/dist/transport/impls/uds/client.cjs +0 -1684
  49. package/dist/transport/impls/uds/client.cjs.map +0 -1
  50. package/dist/transport/impls/uds/client.d.cts +0 -18
  51. package/dist/transport/impls/uds/client.d.ts +0 -18
  52. package/dist/transport/impls/uds/client.js +0 -38
  53. package/dist/transport/impls/uds/client.js.map +0 -1
  54. package/dist/transport/impls/uds/server.cjs +0 -1650
  55. package/dist/transport/impls/uds/server.cjs.map +0 -1
  56. package/dist/transport/impls/uds/server.d.cts +0 -19
  57. package/dist/transport/impls/uds/server.d.ts +0 -19
  58. package/dist/transport/impls/uds/server.js +0 -33
  59. package/dist/transport/impls/uds/server.js.map +0 -1
  60. /package/dist/{chunk-XKHLA5MP.js.map → chunk-4GCILF7L.js.map} +0 -0
  61. /package/dist/{chunk-EHXKU4TW.js.map → chunk-BMSEVPGM.js.map} +0 -0
  62. /package/dist/{chunk-FKBXIWWN.js.map → chunk-FEMGSUEE.js.map} +0 -0
  63. /package/dist/{chunk-LSHUPI6U.js.map → chunk-JTZVFCMT.js.map} +0 -0
@@ -1,9 +1,9 @@
1
1
  import { c as TransportClientId } from '../../../message-e6c560fd.js';
2
2
  import { WebSocketServer } from 'ws';
3
- import { W as WebSocketConnection } from '../../../connection-55cba970.js';
3
+ import { W as WebSocketConnection } from '../../../connection-bd907ca6.js';
4
4
  import { W as WsLike } from '../../../wslike-e0b32dd5.js';
5
- import { S as ServerTransport } from '../../../server-732e7014.js';
6
- import { c as ProvidedServerTransportOptions } from '../../../handshake-0b88e8fc.js';
5
+ import { S as ServerTransport } from '../../../server-f0fd2b98.js';
6
+ import { c as ProvidedServerTransportOptions } from '../../../handshake-3772d7ca.js';
7
7
  import '@sinclair/typebox/value';
8
8
  import '@sinclair/typebox';
9
9
  import '@opentelemetry/api';
@@ -1,13 +1,13 @@
1
1
  import {
2
2
  ServerTransport
3
- } from "../../../chunk-W3CY6PNC.js";
3
+ } from "../../../chunk-N2UT2H2D.js";
4
4
  import {
5
5
  WebSocketConnection
6
- } from "../../../chunk-EHXKU4TW.js";
7
- import "../../../chunk-FKBXIWWN.js";
6
+ } from "../../../chunk-BMSEVPGM.js";
7
+ import "../../../chunk-FEMGSUEE.js";
8
8
  import "../../../chunk-TAH2GVTJ.js";
9
- import "../../../chunk-KVLCQ24J.js";
10
- import "../../../chunk-DZNP3EI5.js";
9
+ import "../../../chunk-XVGZYVNR.js";
10
+ import "../../../chunk-6NPQ43ZP.js";
11
11
  import "../../../chunk-4PVU7J25.js";
12
12
 
13
13
  // transport/impls/ws/server.ts
@@ -562,7 +562,7 @@ var SessionNoConnection = class extends IdentifiedSession {
562
562
  var import_api = require("@opentelemetry/api");
563
563
 
564
564
  // package.json
565
- var version = "0.24.3";
565
+ var version = "0.25.0";
566
566
 
567
567
  // tracing/index.ts
568
568
  function getPropagationContext(ctx) {
@@ -686,15 +686,16 @@ var SessionConnected = class extends IdentifiedSession {
686
686
  state = "Connected" /* Connected */;
687
687
  conn;
688
688
  listeners;
689
- heartbeatHandle;
690
- heartbeatMisses = 0;
689
+ activeHeartbeatHandle;
690
+ activeHeartbeatMisses = 0;
691
+ passiveHeartbeatHandle;
691
692
  get isActivelyHeartbeating() {
692
- return this.heartbeatHandle !== void 0;
693
+ return this.activeHeartbeatHandle !== void 0;
693
694
  }
694
695
  updateBookkeeping(ack, seq) {
695
696
  this.sendBuffer = this.sendBuffer.filter((unacked) => unacked.seq >= ack);
696
697
  this.ack = seq + 1;
697
- this.heartbeatMisses = 0;
698
+ this.activeHeartbeatMisses = 0;
698
699
  }
699
700
  send(msg) {
700
701
  const constructedMsg = this.constructMsg(msg);
@@ -720,8 +721,8 @@ var SessionConnected = class extends IdentifiedSession {
720
721
  }
721
722
  }
722
723
  startActiveHeartbeat() {
723
- this.heartbeatHandle = setInterval(() => {
724
- const misses = this.heartbeatMisses;
724
+ this.activeHeartbeatHandle = setInterval(() => {
725
+ const misses = this.activeHeartbeatMisses;
725
726
  const missDuration = misses * this.options.heartbeatIntervalMs;
726
727
  if (misses >= this.options.heartbeatsUntilDead) {
727
728
  this.log?.info(
@@ -730,15 +731,32 @@ var SessionConnected = class extends IdentifiedSession {
730
731
  );
731
732
  this.telemetry.span.addEvent("closing connection due to inactivity");
732
733
  this.conn.close();
733
- clearInterval(this.heartbeatHandle);
734
- this.heartbeatHandle = void 0;
734
+ clearInterval(this.activeHeartbeatHandle);
735
+ this.activeHeartbeatHandle = void 0;
735
736
  return;
736
737
  }
737
738
  this.sendHeartbeat();
738
- this.heartbeatMisses++;
739
+ this.activeHeartbeatMisses++;
739
740
  }, this.options.heartbeatIntervalMs);
740
741
  }
742
+ waitForNextHeartbeat() {
743
+ const duration = this.options.heartbeatsUntilDead * this.options.heartbeatIntervalMs;
744
+ if (this.passiveHeartbeatHandle) {
745
+ clearTimeout(this.passiveHeartbeatHandle);
746
+ this.passiveHeartbeatHandle = void 0;
747
+ }
748
+ this.passiveHeartbeatHandle = setTimeout(() => {
749
+ this.log?.info(
750
+ `closing connection to ${this.to} due to not receiving a heartbeat in the last ${duration}ms`,
751
+ this.loggingMetadata
752
+ );
753
+ this.telemetry.span.addEvent("closing connection due to inactivity");
754
+ this.conn.close();
755
+ this.passiveHeartbeatHandle = void 0;
756
+ }, duration);
757
+ }
741
758
  sendHeartbeat() {
759
+ this.log?.debug("sending heartbeat", this.loggingMetadata);
742
760
  this.send({
743
761
  streamId: "heartbeat",
744
762
  controlFlags: 1 /* AckBit */,
@@ -790,6 +808,7 @@ var SessionConnected = class extends IdentifiedSession {
790
808
  });
791
809
  if (!this.isActivelyHeartbeating) {
792
810
  this.sendHeartbeat();
811
+ this.waitForNextHeartbeat();
793
812
  }
794
813
  };
795
814
  _handleStateExit() {
@@ -797,8 +816,10 @@ var SessionConnected = class extends IdentifiedSession {
797
816
  this.conn.removeDataListener(this.onMessageData);
798
817
  this.conn.removeCloseListener(this.listeners.onConnectionClosed);
799
818
  this.conn.removeErrorListener(this.listeners.onConnectionErrored);
800
- clearInterval(this.heartbeatHandle);
801
- this.heartbeatHandle = void 0;
819
+ clearInterval(this.activeHeartbeatHandle);
820
+ clearTimeout(this.passiveHeartbeatHandle);
821
+ this.activeHeartbeatHandle = void 0;
822
+ this.passiveHeartbeatHandle = void 0;
802
823
  }
803
824
  _handleClose() {
804
825
  super._handleClose();
@@ -1711,10 +1732,10 @@ var ServerTransport = class extends Transport {
1711
1732
  return;
1712
1733
  }
1713
1734
  let connectCase = "new session";
1735
+ const clientNextExpectedSeq = msg.payload.expectedSessionState.nextExpectedSeq;
1736
+ const clientNextSentSeq = msg.payload.expectedSessionState.nextSentSeq ?? 0;
1714
1737
  if (oldSession && oldSession.id === msg.payload.sessionId) {
1715
1738
  connectCase = "transparent reconnection";
1716
- const clientNextExpectedSeq = msg.payload.expectedSessionState.nextExpectedSeq;
1717
- const clientNextSentSeq = msg.payload.expectedSessionState.nextSentSeq ?? 0;
1718
1739
  const ourNextSeq = oldSession.nextSeq();
1719
1740
  const ourAck = oldSession.ack;
1720
1741
  if (clientNextSentSeq > ourAck) {
@@ -1770,26 +1791,31 @@ var ServerTransport = class extends Transport {
1770
1791
  this.updateSession(oldSession);
1771
1792
  } else if (oldSession) {
1772
1793
  connectCase = "hard reconnection";
1794
+ this.log?.info(
1795
+ `client is reconnecting to a new session (${msg.payload.sessionId}) with an old session (${oldSession.id}) already existing, closing old session`,
1796
+ {
1797
+ ...session.loggingMetadata,
1798
+ connectedTo: msg.from,
1799
+ sessionId: msg.payload.sessionId
1800
+ }
1801
+ );
1773
1802
  this.deleteSession(oldSession);
1774
1803
  oldSession = void 0;
1775
- } else {
1804
+ }
1805
+ if (!oldSession && (clientNextSentSeq > 0 || clientNextExpectedSeq > 0)) {
1776
1806
  connectCase = "unknown session";
1777
- const clientNextExpectedSeq = msg.payload.expectedSessionState.nextExpectedSeq;
1778
- const clientNextSentSeq = msg.payload.expectedSessionState.nextSentSeq ?? 0;
1779
- if (clientNextSentSeq > 0 || clientNextExpectedSeq > 0) {
1780
- this.rejectHandshakeRequest(
1781
- session,
1782
- msg.from,
1783
- `client is trying to reconnect to a session the server don't know about: ${msg.payload.sessionId}`,
1784
- "SESSION_STATE_MISMATCH",
1785
- {
1786
- ...session.loggingMetadata,
1787
- connectedTo: msg.from,
1788
- transportMessage: msg
1789
- }
1790
- );
1791
- return;
1792
- }
1807
+ this.rejectHandshakeRequest(
1808
+ session,
1809
+ msg.from,
1810
+ `client is trying to reconnect to a session the server don't know about: ${msg.payload.sessionId}`,
1811
+ "SESSION_STATE_MISMATCH",
1812
+ {
1813
+ ...session.loggingMetadata,
1814
+ connectedTo: msg.from,
1815
+ transportMessage: msg
1816
+ }
1817
+ );
1818
+ return;
1793
1819
  }
1794
1820
  const sessionId = msg.payload.sessionId;
1795
1821
  this.log?.info(