@replit/river 0.23.9 → 0.23.11

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 (54) hide show
  1. package/dist/{chunk-YGW5PYGV.js → chunk-EOJMKMDO.js} +55 -73
  2. package/dist/chunk-EOJMKMDO.js.map +1 -0
  3. package/dist/{chunk-XKVIPKMR.js → chunk-HM7VDTDJ.js} +2 -2
  4. package/dist/{chunk-XUVTMFTJ.js → chunk-MEHCOYKJ.js} +2 -2
  5. package/dist/chunk-MEHCOYKJ.js.map +1 -0
  6. package/dist/{chunk-KIWWKSRI.js → chunk-T6YEMFUF.js} +2 -2
  7. package/dist/{chunk-U4CSF3SQ.js → chunk-ZSKCZYVU.js} +473 -15
  8. package/dist/chunk-ZSKCZYVU.js.map +1 -0
  9. package/dist/{connection-afa08cf1.d.ts → connection-261eee8f.d.ts} +1 -1
  10. package/dist/{connection-f5fb7805.d.ts → connection-c1eeb95d.d.ts} +1 -1
  11. package/dist/router/index.cjs +473 -14
  12. package/dist/router/index.cjs.map +1 -1
  13. package/dist/router/index.d.cts +45 -7
  14. package/dist/router/index.d.ts +45 -7
  15. package/dist/router/index.js +4 -2
  16. package/dist/{services-49b1b43d.d.ts → services-524bab79.d.ts} +2 -2
  17. package/dist/transport/impls/uds/client.cjs +52 -70
  18. package/dist/transport/impls/uds/client.cjs.map +1 -1
  19. package/dist/transport/impls/uds/client.d.cts +2 -2
  20. package/dist/transport/impls/uds/client.d.ts +2 -2
  21. package/dist/transport/impls/uds/client.js +3 -3
  22. package/dist/transport/impls/uds/server.cjs +31 -60
  23. package/dist/transport/impls/uds/server.cjs.map +1 -1
  24. package/dist/transport/impls/uds/server.d.cts +2 -2
  25. package/dist/transport/impls/uds/server.d.ts +2 -2
  26. package/dist/transport/impls/uds/server.js +3 -3
  27. package/dist/transport/impls/ws/client.cjs +55 -70
  28. package/dist/transport/impls/ws/client.cjs.map +1 -1
  29. package/dist/transport/impls/ws/client.d.cts +2 -2
  30. package/dist/transport/impls/ws/client.d.ts +2 -2
  31. package/dist/transport/impls/ws/client.js +6 -3
  32. package/dist/transport/impls/ws/client.js.map +1 -1
  33. package/dist/transport/impls/ws/server.cjs +31 -60
  34. package/dist/transport/impls/ws/server.cjs.map +1 -1
  35. package/dist/transport/impls/ws/server.d.cts +2 -2
  36. package/dist/transport/impls/ws/server.d.ts +2 -2
  37. package/dist/transport/impls/ws/server.js +3 -3
  38. package/dist/transport/index.cjs +54 -72
  39. package/dist/transport/index.cjs.map +1 -1
  40. package/dist/transport/index.d.cts +1 -1
  41. package/dist/transport/index.d.ts +1 -1
  42. package/dist/transport/index.js +2 -2
  43. package/dist/{transport-3d0ba1da.d.ts → transport-c8f36f6d.d.ts} +15 -21
  44. package/dist/util/testHelpers.cjs +4 -21
  45. package/dist/util/testHelpers.cjs.map +1 -1
  46. package/dist/util/testHelpers.d.cts +2 -2
  47. package/dist/util/testHelpers.d.ts +2 -2
  48. package/dist/util/testHelpers.js +3 -3
  49. package/package.json +3 -3
  50. package/dist/chunk-U4CSF3SQ.js.map +0 -1
  51. package/dist/chunk-XUVTMFTJ.js.map +0 -1
  52. package/dist/chunk-YGW5PYGV.js.map +0 -1
  53. /package/dist/{chunk-XKVIPKMR.js.map → chunk-HM7VDTDJ.js.map} +0 -0
  54. /package/dist/{chunk-KIWWKSRI.js.map → chunk-T6YEMFUF.js.map} +0 -0
@@ -159,11 +159,13 @@ var createLogProxy = (log) => ({
159
159
  var ProtocolError = {
160
160
  RetriesExceeded: "conn_retry_exceeded",
161
161
  HandshakeFailed: "handshake_failed",
162
- UseAfterDestroy: "use_after_destroy",
163
162
  MessageOrderingViolated: "message_ordering_violated"
164
163
  };
165
164
  var EventDispatcher = class {
166
165
  eventListeners = {};
166
+ removeAllListeners() {
167
+ this.eventListeners = {};
168
+ }
167
169
  numberOfListeners(eventType) {
168
170
  return this.eventListeners[eventType]?.size ?? 0;
169
171
  }
@@ -182,7 +184,8 @@ var EventDispatcher = class {
182
184
  dispatchEvent(eventType, event) {
183
185
  const handlers = this.eventListeners[eventType];
184
186
  if (handlers) {
185
- for (const handler of handlers) {
187
+ const copy = [...handlers];
188
+ for (const handler of copy) {
186
189
  handler(event);
187
190
  }
188
191
  }
@@ -196,7 +199,7 @@ var import_nanoid2 = require("nanoid");
196
199
  var import_api = require("@opentelemetry/api");
197
200
 
198
201
  // package.json
199
- var version = "0.23.9";
202
+ var version = "0.23.11";
200
203
 
201
204
  // tracing/index.ts
202
205
  function createSessionTelemetryInfo(session, propagationCtx) {
@@ -246,7 +249,7 @@ var Connection = class {
246
249
  get loggingMetadata() {
247
250
  const metadata = { connId: this.id };
248
251
  const spanContext = this.telemetry?.span.spanContext();
249
- if (spanContext) {
252
+ if (this.telemetry?.span.isRecording() && spanContext) {
250
253
  metadata.telemetry = {
251
254
  traceId: spanContext.traceId,
252
255
  spanId: spanContext.spanId
@@ -461,19 +464,8 @@ var Session = class {
461
464
  `starting ${this.options.sessionDisconnectGraceMs}ms grace period until session to ${this.to} is closed`,
462
465
  this.loggingMetadata
463
466
  );
464
- this.cancelGrace({ keepHeartbeatMisses: true });
467
+ this.cancelGrace();
465
468
  this.disconnectionGrace = setTimeout(() => {
466
- if (this.connection !== void 0) {
467
- this.log?.warn(
468
- `grace period for ${this.to} elapsed while connected. not calling callback`,
469
- {
470
- ...this.loggingMetadata,
471
- connId: this.connection.id,
472
- tags: ["invariant-violation"]
473
- }
474
- );
475
- return;
476
- }
477
469
  this.log?.info(
478
470
  `grace period for ${this.to} elapsed`,
479
471
  this.loggingMetadata
@@ -482,14 +474,8 @@ var Session = class {
482
474
  }, this.options.sessionDisconnectGraceMs);
483
475
  }
484
476
  // called on reconnect of the underlying session
485
- cancelGrace({ keepHeartbeatMisses } = {
486
- keepHeartbeatMisses: false
487
- }) {
488
- if (!keepHeartbeatMisses) {
489
- this.heartbeatMisses = 0;
490
- }
491
- if (this.disconnectionGrace === void 0)
492
- return;
477
+ cancelGrace() {
478
+ this.heartbeatMisses = 0;
493
479
  clearTimeout(this.disconnectionGrace);
494
480
  this.disconnectionGrace = void 0;
495
481
  }
@@ -621,10 +607,9 @@ var defaultServerTransportOptions = {
621
607
  };
622
608
  var Transport = class {
623
609
  /**
624
- * A flag indicating whether the transport has been destroyed.
625
- * A destroyed transport will not attempt to reconnect and cannot be used again.
610
+ * The status of the transport.
626
611
  */
627
- state;
612
+ status;
628
613
  /**
629
614
  * The {@link Codec} used to encode and decode messages.
630
615
  */
@@ -666,7 +651,7 @@ var Transport = class {
666
651
  this.sessions = /* @__PURE__ */ new Map();
667
652
  this.codec = this.options.codec;
668
653
  this.clientId = clientId;
669
- this.state = "open";
654
+ this.status = "open";
670
655
  }
671
656
  bindLogger(fn, level) {
672
657
  if (typeof fn === "function") {
@@ -680,7 +665,7 @@ var Transport = class {
680
665
  * and we know the identity of the connected client.
681
666
  * @param conn The connection object.
682
667
  */
683
- onConnect(conn, connectedTo, session, isReconnect) {
668
+ onConnect(conn, session, isReconnect) {
684
669
  this.eventDispatcher.dispatchEvent("connectionStatus", {
685
670
  status: "connect",
686
671
  conn
@@ -688,13 +673,11 @@ var Transport = class {
688
673
  conn.telemetry = createConnectionTelemetryInfo(conn, session.telemetry);
689
674
  if (isReconnect) {
690
675
  session.replaceWithNewConnection(conn);
691
- this.log?.info(`reconnected to ${connectedTo}`, {
692
- ...conn.loggingMetadata,
693
- ...session.loggingMetadata,
694
- clientId: this.clientId,
695
- connectedTo
696
- });
697
676
  }
677
+ this.log?.info(`connected to ${session.to}`, {
678
+ ...conn.loggingMetadata,
679
+ ...session.loggingMetadata
680
+ });
698
681
  }
699
682
  createSession(to, conn, propagationCtx) {
700
683
  const session = new Session(
@@ -828,7 +811,7 @@ var Transport = class {
828
811
  * @param msg The received message.
829
812
  */
830
813
  handleMsg(msg, conn) {
831
- if (this.state !== "open")
814
+ if (this.getStatus() !== "open")
832
815
  return;
833
816
  const session = this.sessions.get(msg.from);
834
817
  if (!session) {
@@ -907,21 +890,14 @@ var Transport = class {
907
890
  * @returns The ID of the sent message or undefined if it wasn't sent
908
891
  */
909
892
  send(to, msg) {
910
- if (this.state === "destroyed") {
911
- const err = "transport is destroyed, cant send";
893
+ if (this.getStatus() === "closed") {
894
+ const err = "transport is closed, cant send";
912
895
  this.log?.error(err, {
913
896
  clientId: this.clientId,
914
897
  transportMessage: msg,
915
898
  tags: ["invariant-violation"]
916
899
  });
917
- this.protocolError(ProtocolError.UseAfterDestroy, err);
918
- return void 0;
919
- } else if (this.state === "closed") {
920
- this.log?.info(`transport closed when sending, discarding`, {
921
- clientId: this.clientId,
922
- transportMessage: msg
923
- });
924
- return void 0;
900
+ throw new Error(err);
925
901
  }
926
902
  return this.getOrCreateSession({ to }).session.send(msg);
927
903
  }
@@ -944,23 +920,18 @@ var Transport = class {
944
920
  * Closes the transport. Any messages sent while the transport is closed will be silently discarded.
945
921
  */
946
922
  close() {
947
- this.state = "closed";
923
+ this.status = "closed";
948
924
  for (const session of this.sessions.values()) {
949
925
  this.deleteSession({ session, closeHandshakingConnection: true });
950
926
  }
927
+ this.eventDispatcher.dispatchEvent("transportStatus", {
928
+ status: this.status
929
+ });
930
+ this.eventDispatcher.removeAllListeners();
951
931
  this.log?.info(`manually closed transport`, { clientId: this.clientId });
952
932
  }
953
- /**
954
- * Default destroy implementation for transports. You should override this in the downstream
955
- * implementation if you need to do any additional cleanup and call super.destroy() at the end.
956
- * Destroys the transport. Any messages sent while the transport is destroyed will throw an error.
957
- */
958
- destroy() {
959
- this.state = "destroyed";
960
- for (const session of this.sessions.values()) {
961
- this.deleteSession({ session, closeHandshakingConnection: true });
962
- }
963
- this.log?.info(`manually destroyed transport`, { clientId: this.clientId });
933
+ getStatus() {
934
+ return this.status;
964
935
  }
965
936
  };
966
937
  var ServerTransport = class extends Transport {
@@ -992,7 +963,7 @@ var ServerTransport = class extends Transport {
992
963
  this.handshakeExtensions = options;
993
964
  }
994
965
  handleConnection(conn) {
995
- if (this.state !== "open")
966
+ if (this.getStatus() !== "open")
996
967
  return;
997
968
  this.log?.info(`new incoming connection`, {
998
969
  ...conn.loggingMetadata,
@@ -1208,7 +1179,7 @@ var ServerTransport = class extends Transport {
1208
1179
  sessionId: session.id
1209
1180
  });
1210
1181
  conn.send(this.codec.toBuffer(responseMsg));
1211
- this.onConnect(conn, parsed.from, session, isReconnect);
1182
+ this.onConnect(conn, session, isReconnect);
1212
1183
  return session;
1213
1184
  }
1214
1185
  };