@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
@@ -162,11 +162,13 @@ var createLogProxy = (log) => ({
162
162
  var ProtocolError = {
163
163
  RetriesExceeded: "conn_retry_exceeded",
164
164
  HandshakeFailed: "handshake_failed",
165
- UseAfterDestroy: "use_after_destroy",
166
165
  MessageOrderingViolated: "message_ordering_violated"
167
166
  };
168
167
  var EventDispatcher = class {
169
168
  eventListeners = {};
169
+ removeAllListeners() {
170
+ this.eventListeners = {};
171
+ }
170
172
  numberOfListeners(eventType) {
171
173
  return this.eventListeners[eventType]?.size ?? 0;
172
174
  }
@@ -185,7 +187,8 @@ var EventDispatcher = class {
185
187
  dispatchEvent(eventType, event) {
186
188
  const handlers = this.eventListeners[eventType];
187
189
  if (handlers) {
188
- for (const handler of handlers) {
190
+ const copy = [...handlers];
191
+ for (const handler of copy) {
189
192
  handler(event);
190
193
  }
191
194
  }
@@ -199,7 +202,7 @@ var import_nanoid2 = require("nanoid");
199
202
  var import_api = require("@opentelemetry/api");
200
203
 
201
204
  // package.json
202
- var version = "0.23.9";
205
+ var version = "0.23.11";
203
206
 
204
207
  // tracing/index.ts
205
208
  function getPropagationContext(ctx) {
@@ -258,7 +261,7 @@ var Connection = class {
258
261
  get loggingMetadata() {
259
262
  const metadata = { connId: this.id };
260
263
  const spanContext = this.telemetry?.span.spanContext();
261
- if (spanContext) {
264
+ if (this.telemetry?.span.isRecording() && spanContext) {
262
265
  metadata.telemetry = {
263
266
  traceId: spanContext.traceId,
264
267
  spanId: spanContext.spanId
@@ -473,19 +476,8 @@ var Session = class {
473
476
  `starting ${this.options.sessionDisconnectGraceMs}ms grace period until session to ${this.to} is closed`,
474
477
  this.loggingMetadata
475
478
  );
476
- this.cancelGrace({ keepHeartbeatMisses: true });
479
+ this.cancelGrace();
477
480
  this.disconnectionGrace = setTimeout(() => {
478
- if (this.connection !== void 0) {
479
- this.log?.warn(
480
- `grace period for ${this.to} elapsed while connected. not calling callback`,
481
- {
482
- ...this.loggingMetadata,
483
- connId: this.connection.id,
484
- tags: ["invariant-violation"]
485
- }
486
- );
487
- return;
488
- }
489
481
  this.log?.info(
490
482
  `grace period for ${this.to} elapsed`,
491
483
  this.loggingMetadata
@@ -494,14 +486,8 @@ var Session = class {
494
486
  }, this.options.sessionDisconnectGraceMs);
495
487
  }
496
488
  // called on reconnect of the underlying session
497
- cancelGrace({ keepHeartbeatMisses } = {
498
- keepHeartbeatMisses: false
499
- }) {
500
- if (!keepHeartbeatMisses) {
501
- this.heartbeatMisses = 0;
502
- }
503
- if (this.disconnectionGrace === void 0)
504
- return;
489
+ cancelGrace() {
490
+ this.heartbeatMisses = 0;
505
491
  clearTimeout(this.disconnectionGrace);
506
492
  this.disconnectionGrace = void 0;
507
493
  }
@@ -704,10 +690,9 @@ var defaultServerTransportOptions = {
704
690
  };
705
691
  var Transport = class {
706
692
  /**
707
- * A flag indicating whether the transport has been destroyed.
708
- * A destroyed transport will not attempt to reconnect and cannot be used again.
693
+ * The status of the transport.
709
694
  */
710
- state;
695
+ status;
711
696
  /**
712
697
  * The {@link Codec} used to encode and decode messages.
713
698
  */
@@ -749,7 +734,7 @@ var Transport = class {
749
734
  this.sessions = /* @__PURE__ */ new Map();
750
735
  this.codec = this.options.codec;
751
736
  this.clientId = clientId;
752
- this.state = "open";
737
+ this.status = "open";
753
738
  }
754
739
  bindLogger(fn, level) {
755
740
  if (typeof fn === "function") {
@@ -763,7 +748,7 @@ var Transport = class {
763
748
  * and we know the identity of the connected client.
764
749
  * @param conn The connection object.
765
750
  */
766
- onConnect(conn, connectedTo, session, isReconnect) {
751
+ onConnect(conn, session, isReconnect) {
767
752
  this.eventDispatcher.dispatchEvent("connectionStatus", {
768
753
  status: "connect",
769
754
  conn
@@ -771,13 +756,11 @@ var Transport = class {
771
756
  conn.telemetry = createConnectionTelemetryInfo(conn, session.telemetry);
772
757
  if (isReconnect) {
773
758
  session.replaceWithNewConnection(conn);
774
- this.log?.info(`reconnected to ${connectedTo}`, {
775
- ...conn.loggingMetadata,
776
- ...session.loggingMetadata,
777
- clientId: this.clientId,
778
- connectedTo
779
- });
780
759
  }
760
+ this.log?.info(`connected to ${session.to}`, {
761
+ ...conn.loggingMetadata,
762
+ ...session.loggingMetadata
763
+ });
781
764
  }
782
765
  createSession(to, conn, propagationCtx) {
783
766
  const session = new Session(
@@ -911,7 +894,7 @@ var Transport = class {
911
894
  * @param msg The received message.
912
895
  */
913
896
  handleMsg(msg, conn) {
914
- if (this.state !== "open")
897
+ if (this.getStatus() !== "open")
915
898
  return;
916
899
  const session = this.sessions.get(msg.from);
917
900
  if (!session) {
@@ -990,21 +973,14 @@ var Transport = class {
990
973
  * @returns The ID of the sent message or undefined if it wasn't sent
991
974
  */
992
975
  send(to, msg) {
993
- if (this.state === "destroyed") {
994
- const err = "transport is destroyed, cant send";
976
+ if (this.getStatus() === "closed") {
977
+ const err = "transport is closed, cant send";
995
978
  this.log?.error(err, {
996
979
  clientId: this.clientId,
997
980
  transportMessage: msg,
998
981
  tags: ["invariant-violation"]
999
982
  });
1000
- this.protocolError(ProtocolError.UseAfterDestroy, err);
1001
- return void 0;
1002
- } else if (this.state === "closed") {
1003
- this.log?.info(`transport closed when sending, discarding`, {
1004
- clientId: this.clientId,
1005
- transportMessage: msg
1006
- });
1007
- return void 0;
983
+ throw new Error(err);
1008
984
  }
1009
985
  return this.getOrCreateSession({ to }).session.send(msg);
1010
986
  }
@@ -1027,23 +1003,18 @@ var Transport = class {
1027
1003
  * Closes the transport. Any messages sent while the transport is closed will be silently discarded.
1028
1004
  */
1029
1005
  close() {
1030
- this.state = "closed";
1006
+ this.status = "closed";
1031
1007
  for (const session of this.sessions.values()) {
1032
1008
  this.deleteSession({ session, closeHandshakingConnection: true });
1033
1009
  }
1010
+ this.eventDispatcher.dispatchEvent("transportStatus", {
1011
+ status: this.status
1012
+ });
1013
+ this.eventDispatcher.removeAllListeners();
1034
1014
  this.log?.info(`manually closed transport`, { clientId: this.clientId });
1035
1015
  }
1036
- /**
1037
- * Default destroy implementation for transports. You should override this in the downstream
1038
- * implementation if you need to do any additional cleanup and call super.destroy() at the end.
1039
- * Destroys the transport. Any messages sent while the transport is destroyed will throw an error.
1040
- */
1041
- destroy() {
1042
- this.state = "destroyed";
1043
- for (const session of this.sessions.values()) {
1044
- this.deleteSession({ session, closeHandshakingConnection: true });
1045
- }
1046
- this.log?.info(`manually destroyed transport`, { clientId: this.clientId });
1016
+ getStatus() {
1017
+ return this.status;
1047
1018
  }
1048
1019
  };
1049
1020
  var ClientTransport = class extends Transport {
@@ -1080,7 +1051,7 @@ var ClientTransport = class extends Transport {
1080
1051
  this.handshakeExtensions = options;
1081
1052
  }
1082
1053
  handleConnection(conn, to) {
1083
- if (this.state !== "open")
1054
+ if (this.getStatus() !== "open")
1084
1055
  return;
1085
1056
  let session = void 0;
1086
1057
  const handshakeTimeout = setTimeout(() => {
@@ -1120,12 +1091,16 @@ var ClientTransport = class extends Transport {
1120
1091
  if (session) {
1121
1092
  this.onDisconnect(conn, session);
1122
1093
  }
1123
- this.log?.info(`connection to ${to} disconnected`, {
1124
- ...conn.loggingMetadata,
1125
- ...session?.loggingMetadata,
1126
- clientId: this.clientId,
1127
- connectedTo: to
1128
- });
1094
+ const willReconnect = this.reconnectOnConnectionDrop && this.getStatus() === "open";
1095
+ this.log?.info(
1096
+ `connection to ${to} disconnected` + (willReconnect ? ", reconnecting" : ""),
1097
+ {
1098
+ ...conn.loggingMetadata,
1099
+ ...session?.loggingMetadata,
1100
+ clientId: this.clientId,
1101
+ connectedTo: to
1102
+ }
1103
+ );
1129
1104
  this.inflightConnectionPromises.delete(to);
1130
1105
  if (this.reconnectOnConnectionDrop) {
1131
1106
  void this.connect(to);
@@ -1211,8 +1186,8 @@ var ClientTransport = class extends Transport {
1211
1186
  conn,
1212
1187
  sessionId: parsed.payload.status.sessionId
1213
1188
  });
1214
- this.onConnect(conn, parsed.from, session, isReconnect);
1215
- this.retryBudget.startRestoringBudget(parsed.from);
1189
+ this.onConnect(conn, session, isReconnect);
1190
+ this.retryBudget.startRestoringBudget(session.to);
1216
1191
  return session;
1217
1192
  }
1218
1193
  /**
@@ -1220,7 +1195,14 @@ var ClientTransport = class extends Transport {
1220
1195
  * @param to The client ID of the node to connect to.
1221
1196
  */
1222
1197
  async connect(to) {
1223
- const canProceedWithConnection = () => this.state === "open";
1198
+ if (this.connections.has(to)) {
1199
+ this.log?.info(`already connected to ${to}, skipping connect attempt`, {
1200
+ clientId: this.clientId,
1201
+ connectedTo: to
1202
+ });
1203
+ return;
1204
+ }
1205
+ const canProceedWithConnection = () => this.getStatus() === "open";
1224
1206
  if (!canProceedWithConnection()) {
1225
1207
  this.log?.info(
1226
1208
  `transport state is no longer open, cancelling attempt to connect to ${to}`,
@@ -1230,8 +1212,8 @@ var ClientTransport = class extends Transport {
1230
1212
  }
1231
1213
  let reconnectPromise = this.inflightConnectionPromises.get(to);
1232
1214
  if (!reconnectPromise) {
1233
- const budgetConsumed = this.retryBudget.getBudgetConsumed(to);
1234
1215
  if (!this.retryBudget.hasBudget(to)) {
1216
+ const budgetConsumed = this.retryBudget.getBudgetConsumed(to);
1235
1217
  const errMsg = `tried to connect to ${to} but retry budget exceeded (more than ${budgetConsumed} attempts in the last ${this.retryBudget.totalBudgetRestoreTime}ms)`;
1236
1218
  this.log?.error(errMsg, { clientId: this.clientId, connectedTo: to });
1237
1219
  this.protocolError(ProtocolError.RetriesExceeded, errMsg);
@@ -1312,7 +1294,7 @@ var ClientTransport = class extends Transport {
1312
1294
  clientId: this.clientId,
1313
1295
  connectedTo: to
1314
1296
  });
1315
- return this.connect(to);
1297
+ await this.connect(to);
1316
1298
  }
1317
1299
  }
1318
1300
  }
@@ -1465,6 +1447,9 @@ var WebSocketClientTransport = class extends ClientTransport {
1465
1447
  ws.onclose = (evt) => {
1466
1448
  reject(new Error(evt.reason));
1467
1449
  };
1450
+ ws.onerror = (err) => {
1451
+ reject(new Error(err.message));
1452
+ };
1468
1453
  });
1469
1454
  const conn = new WebSocketConnection(ws);
1470
1455
  this.log?.info(`raw websocket to ${to} ok, starting handshake`, {