@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
@@ -184,11 +184,13 @@ var createLogProxy = (log) => ({
184
184
  var ProtocolError = {
185
185
  RetriesExceeded: "conn_retry_exceeded",
186
186
  HandshakeFailed: "handshake_failed",
187
- UseAfterDestroy: "use_after_destroy",
188
187
  MessageOrderingViolated: "message_ordering_violated"
189
188
  };
190
189
  var EventDispatcher = class {
191
190
  eventListeners = {};
191
+ removeAllListeners() {
192
+ this.eventListeners = {};
193
+ }
192
194
  numberOfListeners(eventType) {
193
195
  return this.eventListeners[eventType]?.size ?? 0;
194
196
  }
@@ -207,7 +209,8 @@ var EventDispatcher = class {
207
209
  dispatchEvent(eventType, event) {
208
210
  const handlers = this.eventListeners[eventType];
209
211
  if (handlers) {
210
- for (const handler of handlers) {
212
+ const copy = [...handlers];
213
+ for (const handler of copy) {
211
214
  handler(event);
212
215
  }
213
216
  }
@@ -221,7 +224,7 @@ var import_nanoid2 = require("nanoid");
221
224
  var import_api = require("@opentelemetry/api");
222
225
 
223
226
  // package.json
224
- var version = "0.23.9";
227
+ var version = "0.23.11";
225
228
 
226
229
  // tracing/index.ts
227
230
  function getPropagationContext(ctx) {
@@ -280,7 +283,7 @@ var Connection = class {
280
283
  get loggingMetadata() {
281
284
  const metadata = { connId: this.id };
282
285
  const spanContext = this.telemetry?.span.spanContext();
283
- if (spanContext) {
286
+ if (this.telemetry?.span.isRecording() && spanContext) {
284
287
  metadata.telemetry = {
285
288
  traceId: spanContext.traceId,
286
289
  spanId: spanContext.spanId
@@ -495,19 +498,8 @@ var Session = class {
495
498
  `starting ${this.options.sessionDisconnectGraceMs}ms grace period until session to ${this.to} is closed`,
496
499
  this.loggingMetadata
497
500
  );
498
- this.cancelGrace({ keepHeartbeatMisses: true });
501
+ this.cancelGrace();
499
502
  this.disconnectionGrace = setTimeout(() => {
500
- if (this.connection !== void 0) {
501
- this.log?.warn(
502
- `grace period for ${this.to} elapsed while connected. not calling callback`,
503
- {
504
- ...this.loggingMetadata,
505
- connId: this.connection.id,
506
- tags: ["invariant-violation"]
507
- }
508
- );
509
- return;
510
- }
511
503
  this.log?.info(
512
504
  `grace period for ${this.to} elapsed`,
513
505
  this.loggingMetadata
@@ -516,14 +508,8 @@ var Session = class {
516
508
  }, this.options.sessionDisconnectGraceMs);
517
509
  }
518
510
  // called on reconnect of the underlying session
519
- cancelGrace({ keepHeartbeatMisses } = {
520
- keepHeartbeatMisses: false
521
- }) {
522
- if (!keepHeartbeatMisses) {
523
- this.heartbeatMisses = 0;
524
- }
525
- if (this.disconnectionGrace === void 0)
526
- return;
511
+ cancelGrace() {
512
+ this.heartbeatMisses = 0;
527
513
  clearTimeout(this.disconnectionGrace);
528
514
  this.disconnectionGrace = void 0;
529
515
  }
@@ -726,10 +712,9 @@ var defaultServerTransportOptions = {
726
712
  };
727
713
  var Transport = class {
728
714
  /**
729
- * A flag indicating whether the transport has been destroyed.
730
- * A destroyed transport will not attempt to reconnect and cannot be used again.
715
+ * The status of the transport.
731
716
  */
732
- state;
717
+ status;
733
718
  /**
734
719
  * The {@link Codec} used to encode and decode messages.
735
720
  */
@@ -771,7 +756,7 @@ var Transport = class {
771
756
  this.sessions = /* @__PURE__ */ new Map();
772
757
  this.codec = this.options.codec;
773
758
  this.clientId = clientId;
774
- this.state = "open";
759
+ this.status = "open";
775
760
  }
776
761
  bindLogger(fn, level) {
777
762
  if (typeof fn === "function") {
@@ -785,7 +770,7 @@ var Transport = class {
785
770
  * and we know the identity of the connected client.
786
771
  * @param conn The connection object.
787
772
  */
788
- onConnect(conn, connectedTo, session, isReconnect) {
773
+ onConnect(conn, session, isReconnect) {
789
774
  this.eventDispatcher.dispatchEvent("connectionStatus", {
790
775
  status: "connect",
791
776
  conn
@@ -793,13 +778,11 @@ var Transport = class {
793
778
  conn.telemetry = createConnectionTelemetryInfo(conn, session.telemetry);
794
779
  if (isReconnect) {
795
780
  session.replaceWithNewConnection(conn);
796
- this.log?.info(`reconnected to ${connectedTo}`, {
797
- ...conn.loggingMetadata,
798
- ...session.loggingMetadata,
799
- clientId: this.clientId,
800
- connectedTo
801
- });
802
781
  }
782
+ this.log?.info(`connected to ${session.to}`, {
783
+ ...conn.loggingMetadata,
784
+ ...session.loggingMetadata
785
+ });
803
786
  }
804
787
  createSession(to, conn, propagationCtx) {
805
788
  const session = new Session(
@@ -933,7 +916,7 @@ var Transport = class {
933
916
  * @param msg The received message.
934
917
  */
935
918
  handleMsg(msg, conn) {
936
- if (this.state !== "open")
919
+ if (this.getStatus() !== "open")
937
920
  return;
938
921
  const session = this.sessions.get(msg.from);
939
922
  if (!session) {
@@ -1012,21 +995,14 @@ var Transport = class {
1012
995
  * @returns The ID of the sent message or undefined if it wasn't sent
1013
996
  */
1014
997
  send(to, msg) {
1015
- if (this.state === "destroyed") {
1016
- const err = "transport is destroyed, cant send";
998
+ if (this.getStatus() === "closed") {
999
+ const err = "transport is closed, cant send";
1017
1000
  this.log?.error(err, {
1018
1001
  clientId: this.clientId,
1019
1002
  transportMessage: msg,
1020
1003
  tags: ["invariant-violation"]
1021
1004
  });
1022
- this.protocolError(ProtocolError.UseAfterDestroy, err);
1023
- return void 0;
1024
- } else if (this.state === "closed") {
1025
- this.log?.info(`transport closed when sending, discarding`, {
1026
- clientId: this.clientId,
1027
- transportMessage: msg
1028
- });
1029
- return void 0;
1005
+ throw new Error(err);
1030
1006
  }
1031
1007
  return this.getOrCreateSession({ to }).session.send(msg);
1032
1008
  }
@@ -1049,23 +1025,18 @@ var Transport = class {
1049
1025
  * Closes the transport. Any messages sent while the transport is closed will be silently discarded.
1050
1026
  */
1051
1027
  close() {
1052
- this.state = "closed";
1028
+ this.status = "closed";
1053
1029
  for (const session of this.sessions.values()) {
1054
1030
  this.deleteSession({ session, closeHandshakingConnection: true });
1055
1031
  }
1032
+ this.eventDispatcher.dispatchEvent("transportStatus", {
1033
+ status: this.status
1034
+ });
1035
+ this.eventDispatcher.removeAllListeners();
1056
1036
  this.log?.info(`manually closed transport`, { clientId: this.clientId });
1057
1037
  }
1058
- /**
1059
- * Default destroy implementation for transports. You should override this in the downstream
1060
- * implementation if you need to do any additional cleanup and call super.destroy() at the end.
1061
- * Destroys the transport. Any messages sent while the transport is destroyed will throw an error.
1062
- */
1063
- destroy() {
1064
- this.state = "destroyed";
1065
- for (const session of this.sessions.values()) {
1066
- this.deleteSession({ session, closeHandshakingConnection: true });
1067
- }
1068
- this.log?.info(`manually destroyed transport`, { clientId: this.clientId });
1038
+ getStatus() {
1039
+ return this.status;
1069
1040
  }
1070
1041
  };
1071
1042
  var ClientTransport = class extends Transport {
@@ -1102,7 +1073,7 @@ var ClientTransport = class extends Transport {
1102
1073
  this.handshakeExtensions = options;
1103
1074
  }
1104
1075
  handleConnection(conn, to) {
1105
- if (this.state !== "open")
1076
+ if (this.getStatus() !== "open")
1106
1077
  return;
1107
1078
  let session = void 0;
1108
1079
  const handshakeTimeout = setTimeout(() => {
@@ -1142,12 +1113,16 @@ var ClientTransport = class extends Transport {
1142
1113
  if (session) {
1143
1114
  this.onDisconnect(conn, session);
1144
1115
  }
1145
- this.log?.info(`connection to ${to} disconnected`, {
1146
- ...conn.loggingMetadata,
1147
- ...session?.loggingMetadata,
1148
- clientId: this.clientId,
1149
- connectedTo: to
1150
- });
1116
+ const willReconnect = this.reconnectOnConnectionDrop && this.getStatus() === "open";
1117
+ this.log?.info(
1118
+ `connection to ${to} disconnected` + (willReconnect ? ", reconnecting" : ""),
1119
+ {
1120
+ ...conn.loggingMetadata,
1121
+ ...session?.loggingMetadata,
1122
+ clientId: this.clientId,
1123
+ connectedTo: to
1124
+ }
1125
+ );
1151
1126
  this.inflightConnectionPromises.delete(to);
1152
1127
  if (this.reconnectOnConnectionDrop) {
1153
1128
  void this.connect(to);
@@ -1233,8 +1208,8 @@ var ClientTransport = class extends Transport {
1233
1208
  conn,
1234
1209
  sessionId: parsed.payload.status.sessionId
1235
1210
  });
1236
- this.onConnect(conn, parsed.from, session, isReconnect);
1237
- this.retryBudget.startRestoringBudget(parsed.from);
1211
+ this.onConnect(conn, session, isReconnect);
1212
+ this.retryBudget.startRestoringBudget(session.to);
1238
1213
  return session;
1239
1214
  }
1240
1215
  /**
@@ -1242,7 +1217,14 @@ var ClientTransport = class extends Transport {
1242
1217
  * @param to The client ID of the node to connect to.
1243
1218
  */
1244
1219
  async connect(to) {
1245
- const canProceedWithConnection = () => this.state === "open";
1220
+ if (this.connections.has(to)) {
1221
+ this.log?.info(`already connected to ${to}, skipping connect attempt`, {
1222
+ clientId: this.clientId,
1223
+ connectedTo: to
1224
+ });
1225
+ return;
1226
+ }
1227
+ const canProceedWithConnection = () => this.getStatus() === "open";
1246
1228
  if (!canProceedWithConnection()) {
1247
1229
  this.log?.info(
1248
1230
  `transport state is no longer open, cancelling attempt to connect to ${to}`,
@@ -1252,8 +1234,8 @@ var ClientTransport = class extends Transport {
1252
1234
  }
1253
1235
  let reconnectPromise = this.inflightConnectionPromises.get(to);
1254
1236
  if (!reconnectPromise) {
1255
- const budgetConsumed = this.retryBudget.getBudgetConsumed(to);
1256
1237
  if (!this.retryBudget.hasBudget(to)) {
1238
+ const budgetConsumed = this.retryBudget.getBudgetConsumed(to);
1257
1239
  const errMsg = `tried to connect to ${to} but retry budget exceeded (more than ${budgetConsumed} attempts in the last ${this.retryBudget.totalBudgetRestoreTime}ms)`;
1258
1240
  this.log?.error(errMsg, { clientId: this.clientId, connectedTo: to });
1259
1241
  this.protocolError(ProtocolError.RetriesExceeded, errMsg);
@@ -1334,7 +1316,7 @@ var ClientTransport = class extends Transport {
1334
1316
  clientId: this.clientId,
1335
1317
  connectedTo: to
1336
1318
  });
1337
- return this.connect(to);
1319
+ await this.connect(to);
1338
1320
  }
1339
1321
  }
1340
1322
  }
@@ -1426,7 +1408,7 @@ var ServerTransport = class extends Transport {
1426
1408
  this.handshakeExtensions = options;
1427
1409
  }
1428
1410
  handleConnection(conn) {
1429
- if (this.state !== "open")
1411
+ if (this.getStatus() !== "open")
1430
1412
  return;
1431
1413
  this.log?.info(`new incoming connection`, {
1432
1414
  ...conn.loggingMetadata,
@@ -1642,7 +1624,7 @@ var ServerTransport = class extends Transport {
1642
1624
  sessionId: session.id
1643
1625
  });
1644
1626
  conn.send(this.codec.toBuffer(responseMsg));
1645
- this.onConnect(conn, parsed.from, session, isReconnect);
1627
+ this.onConnect(conn, session, isReconnect);
1646
1628
  return session;
1647
1629
  }
1648
1630
  };