@replit/river 0.203.1 → 0.205.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 (50) hide show
  1. package/README.md +7 -3
  2. package/dist/{chunk-TMOCPK63.js → chunk-AXZPYUY6.js} +50 -11
  3. package/dist/chunk-AXZPYUY6.js.map +1 -0
  4. package/dist/{chunk-2FHJVQBE.js → chunk-EU2H4J7U.js} +5 -11
  5. package/dist/chunk-EU2H4J7U.js.map +1 -0
  6. package/dist/chunk-GG3GL7CW.js +1955 -0
  7. package/dist/chunk-GG3GL7CW.js.map +1 -0
  8. package/dist/{chunk-T4WWG42M.js → chunk-RAO6UI45.js} +21 -17
  9. package/dist/chunk-RAO6UI45.js.map +1 -0
  10. package/dist/{chunk-7MKTFUJO.js → chunk-VN7QS6OS.js} +4 -3
  11. package/dist/chunk-VN7QS6OS.js.map +1 -0
  12. package/dist/{client-5d2e41a3.d.ts → client-3adfb12a.d.ts} +1 -1
  13. package/dist/{connection-11a4af0f.d.ts → connection-9ca3e7ed.d.ts} +1 -1
  14. package/dist/{context-d6dd8a1a.d.ts → context-1a332293.d.ts} +12 -3
  15. package/dist/router/index.cjs +25 -14
  16. package/dist/router/index.cjs.map +1 -1
  17. package/dist/router/index.d.cts +7 -7
  18. package/dist/router/index.d.ts +7 -7
  19. package/dist/router/index.js +18 -1611
  20. package/dist/router/index.js.map +1 -1
  21. package/dist/{server-e46399f9.d.ts → server-8ac5c6bf.d.ts} +1 -1
  22. package/dist/{services-56cbea0d.d.ts → services-4213d92e.d.ts} +2 -2
  23. package/dist/testUtil/index.cjs +82 -36
  24. package/dist/testUtil/index.cjs.map +1 -1
  25. package/dist/testUtil/index.d.cts +4 -4
  26. package/dist/testUtil/index.d.ts +4 -4
  27. package/dist/testUtil/index.js +8 -6
  28. package/dist/testUtil/index.js.map +1 -1
  29. package/dist/transport/impls/ws/client.cjs +82 -44
  30. package/dist/transport/impls/ws/client.cjs.map +1 -1
  31. package/dist/transport/impls/ws/client.d.cts +3 -3
  32. package/dist/transport/impls/ws/client.d.ts +3 -3
  33. package/dist/transport/impls/ws/client.js +4 -4
  34. package/dist/transport/impls/ws/server.cjs +66 -31
  35. package/dist/transport/impls/ws/server.cjs.map +1 -1
  36. package/dist/transport/impls/ws/server.d.cts +3 -3
  37. package/dist/transport/impls/ws/server.d.ts +3 -3
  38. package/dist/transport/impls/ws/server.js +4 -4
  39. package/dist/transport/index.cjs +80 -35
  40. package/dist/transport/index.cjs.map +1 -1
  41. package/dist/transport/index.d.cts +3 -3
  42. package/dist/transport/index.d.ts +3 -3
  43. package/dist/transport/index.js +4 -4
  44. package/package.json +2 -2
  45. package/dist/chunk-2FHJVQBE.js.map +0 -1
  46. package/dist/chunk-7MKTFUJO.js.map +0 -1
  47. package/dist/chunk-AK7NTFAM.js +0 -331
  48. package/dist/chunk-AK7NTFAM.js.map +0 -1
  49. package/dist/chunk-T4WWG42M.js.map +0 -1
  50. package/dist/chunk-TMOCPK63.js.map +0 -1
@@ -1,9 +1,9 @@
1
1
  import { c as TransportClientId } from '../../../message-3def9ded.js';
2
2
  import { WebSocketServer } from 'ws';
3
- import { W as WebSocketConnection } from '../../../connection-11a4af0f.js';
3
+ import { W as WebSocketConnection } from '../../../connection-9ca3e7ed.js';
4
4
  import { W as WsLike } from '../../../wslike-e0b32dd5.js';
5
- import { S as ServerTransport } from '../../../server-e46399f9.js';
6
- import { c as ProvidedServerTransportOptions } from '../../../context-d6dd8a1a.js';
5
+ import { S as ServerTransport } from '../../../server-8ac5c6bf.js';
6
+ import { c as ProvidedServerTransportOptions } from '../../../context-1a332293.js';
7
7
  import { IncomingMessage } from 'http';
8
8
  import '@sinclair/typebox/value';
9
9
  import '@sinclair/typebox';
@@ -1,9 +1,9 @@
1
1
  import { c as TransportClientId } from '../../../message-3def9ded.js';
2
2
  import { WebSocketServer } from 'ws';
3
- import { W as WebSocketConnection } from '../../../connection-11a4af0f.js';
3
+ import { W as WebSocketConnection } from '../../../connection-9ca3e7ed.js';
4
4
  import { W as WsLike } from '../../../wslike-e0b32dd5.js';
5
- import { S as ServerTransport } from '../../../server-e46399f9.js';
6
- import { c as ProvidedServerTransportOptions } from '../../../context-d6dd8a1a.js';
5
+ import { S as ServerTransport } from '../../../server-8ac5c6bf.js';
6
+ import { c as ProvidedServerTransportOptions } from '../../../context-1a332293.js';
7
7
  import { IncomingMessage } from 'http';
8
8
  import '@sinclair/typebox/value';
9
9
  import '@sinclair/typebox';
@@ -1,11 +1,11 @@
1
1
  import {
2
2
  ServerTransport
3
- } from "../../../chunk-7MKTFUJO.js";
3
+ } from "../../../chunk-VN7QS6OS.js";
4
4
  import {
5
5
  WebSocketConnection
6
- } from "../../../chunk-2FHJVQBE.js";
7
- import "../../../chunk-TMOCPK63.js";
8
- import "../../../chunk-AK7NTFAM.js";
6
+ } from "../../../chunk-EU2H4J7U.js";
7
+ import "../../../chunk-AXZPYUY6.js";
8
+ import "../../../chunk-GG3GL7CW.js";
9
9
  import "../../../chunk-WBGKPIFS.js";
10
10
  import "../../../chunk-AJGIY2UB.js";
11
11
 
@@ -429,12 +429,14 @@ var StateMachineState = class {
429
429
  var CommonSession = class extends StateMachineState {
430
430
  from;
431
431
  options;
432
+ tracer;
432
433
  log;
433
- constructor({ from, options, log }) {
434
+ constructor({ from, options, log, tracer }) {
434
435
  super();
435
436
  this.from = from;
436
437
  this.options = options;
437
438
  this.log = log;
439
+ this.tracer = tracer;
438
440
  }
439
441
  parseMsg(msg) {
440
442
  const parsedMsg = this.options.codec.fromBuffer(msg);
@@ -619,8 +621,16 @@ var SessionNoConnection = class extends IdentifiedSessionWithGracePeriod {
619
621
  // tracing/index.ts
620
622
  var import_api2 = require("@opentelemetry/api");
621
623
 
624
+ // transport/stringifyError.ts
625
+ function coerceErrorString(err) {
626
+ if (err instanceof Error) {
627
+ return err.message || "unknown reason";
628
+ }
629
+ return `[coerced to error] ${String(err)}`;
630
+ }
631
+
622
632
  // package.json
623
- var version = "0.203.1";
633
+ var version = "0.205.0";
624
634
 
625
635
  // tracing/index.ts
626
636
  function getPropagationContext(ctx) {
@@ -631,10 +641,10 @@ function getPropagationContext(ctx) {
631
641
  import_api2.propagation.inject(ctx, tracing);
632
642
  return tracing;
633
643
  }
634
- function createSessionTelemetryInfo(sessionId, to, from, propagationCtx) {
644
+ function createSessionTelemetryInfo(tracer, sessionId, to, from, propagationCtx) {
635
645
  const parentCtx = propagationCtx ? import_api2.propagation.extract(import_api2.context.active(), propagationCtx) : import_api2.context.active();
636
646
  const span = tracer.startSpan(
637
- `session ${sessionId}`,
647
+ `river.session.${sessionId}`,
638
648
  {
639
649
  attributes: {
640
650
  component: "river",
@@ -648,7 +658,7 @@ function createSessionTelemetryInfo(sessionId, to, from, propagationCtx) {
648
658
  const ctx = import_api2.trace.setSpan(parentCtx, span);
649
659
  return { span, ctx };
650
660
  }
651
- function createConnectionTelemetryInfo(connection, info) {
661
+ function createConnectionTelemetryInfo(tracer, connection, info) {
652
662
  const span = tracer.startSpan(
653
663
  `connection ${connection.id}`,
654
664
  {
@@ -663,8 +673,9 @@ function createConnectionTelemetryInfo(connection, info) {
663
673
  const ctx = import_api2.trace.setSpan(info.ctx, span);
664
674
  return { span, ctx };
665
675
  }
666
- var tracer = import_api2.trace.getTracer("river", version);
667
- var tracing_default = tracer;
676
+ function getTracer() {
677
+ return import_api2.trace.getTracer("river", version);
678
+ }
668
679
 
669
680
  // transport/sessionStateMachine/SessionWaitingForHandshake.ts
670
681
  var SessionWaitingForHandshake = class extends CommonSession {
@@ -950,6 +961,7 @@ function inheritSharedSession(session) {
950
961
  telemetry: session.telemetry,
951
962
  options: session.options,
952
963
  log: session.log,
964
+ tracer: session.tracer,
953
965
  protocolVersion: session.protocolVersion
954
966
  };
955
967
  }
@@ -961,9 +973,9 @@ function inheritSharedSessionWithGrace(session) {
961
973
  }
962
974
  var SessionStateGraph = {
963
975
  entrypoints: {
964
- NoConnection: (to, from, listeners, options, protocolVersion, log) => {
976
+ NoConnection: (to, from, listeners, options, protocolVersion, tracer, log) => {
965
977
  const id = `session-${generateId()}`;
966
- const telemetry = createSessionTelemetryInfo(id, to, from);
978
+ const telemetry = createSessionTelemetryInfo(tracer, id, to, from);
967
979
  const sendBuffer = [];
968
980
  const session = new SessionNoConnection({
969
981
  listeners,
@@ -977,6 +989,7 @@ var SessionStateGraph = {
977
989
  telemetry,
978
990
  options,
979
991
  protocolVersion,
992
+ tracer,
980
993
  log
981
994
  });
982
995
  session.log?.info(`session ${session.id} created in NoConnection state`, {
@@ -985,12 +998,13 @@ var SessionStateGraph = {
985
998
  });
986
999
  return session;
987
1000
  },
988
- WaitingForHandshake: (from, conn, listeners, options, log) => {
1001
+ WaitingForHandshake: (from, conn, listeners, options, tracer, log) => {
989
1002
  const session = new SessionWaitingForHandshake({
990
1003
  conn,
991
1004
  listeners,
992
1005
  from,
993
1006
  options,
1007
+ tracer,
994
1008
  log
995
1009
  });
996
1010
  session.log?.info(`session created in WaitingForHandshake state`, {
@@ -1046,7 +1060,11 @@ var SessionStateGraph = {
1046
1060
  listeners,
1047
1061
  ...carriedState
1048
1062
  });
1049
- conn.telemetry = createConnectionTelemetryInfo(conn, session.telemetry);
1063
+ conn.telemetry = createConnectionTelemetryInfo(
1064
+ session.tracer,
1065
+ conn,
1066
+ session.telemetry
1067
+ );
1050
1068
  session.log?.info(
1051
1069
  `session ${session.id} transition from Connecting to Handshaking`,
1052
1070
  {
@@ -1090,12 +1108,14 @@ var SessionStateGraph = {
1090
1108
  ack: 0,
1091
1109
  sendBuffer: [],
1092
1110
  telemetry: createSessionTelemetryInfo(
1111
+ pendingSession.tracer,
1093
1112
  sessionId,
1094
1113
  to,
1095
1114
  from,
1096
1115
  propagationCtx
1097
1116
  ),
1098
1117
  options,
1118
+ tracer: pendingSession.tracer,
1099
1119
  log: pendingSession.log,
1100
1120
  protocolVersion
1101
1121
  }
@@ -1107,7 +1127,11 @@ var SessionStateGraph = {
1107
1127
  listeners,
1108
1128
  ...carriedState
1109
1129
  });
1110
- conn.telemetry = createConnectionTelemetryInfo(conn, session.telemetry);
1130
+ conn.telemetry = createConnectionTelemetryInfo(
1131
+ session.tracer,
1132
+ conn,
1133
+ session.telemetry
1134
+ );
1111
1135
  session.log?.info(
1112
1136
  `session ${session.id} transition from WaitingForHandshake to Connected`,
1113
1137
  {
@@ -1252,6 +1276,7 @@ var Transport = class {
1252
1276
  */
1253
1277
  options;
1254
1278
  log;
1279
+ tracer;
1255
1280
  sessions;
1256
1281
  /**
1257
1282
  * Creates a new Transport instance.
@@ -1264,6 +1289,7 @@ var Transport = class {
1264
1289
  this.clientId = clientId;
1265
1290
  this.status = "open";
1266
1291
  this.sessions = /* @__PURE__ */ new Map();
1292
+ this.tracer = getTracer();
1267
1293
  }
1268
1294
  bindLogger(fn, level) {
1269
1295
  if (typeof fn === "function") {
@@ -1308,7 +1334,8 @@ var Transport = class {
1308
1334
  */
1309
1335
  close() {
1310
1336
  this.status = "closed";
1311
- for (const session of this.sessions.values()) {
1337
+ const sessions = Array.from(this.sessions.values());
1338
+ for (const session of sessions) {
1312
1339
  this.deleteSession(session);
1313
1340
  }
1314
1341
  this.eventDispatcher.dispatchEvent("transportStatus", {
@@ -1333,7 +1360,7 @@ var Transport = class {
1333
1360
  }
1334
1361
  this.sessions.set(session.to, session);
1335
1362
  this.eventDispatcher.dispatchEvent("sessionStatus", {
1336
- status: "connect",
1363
+ status: "created",
1337
1364
  session
1338
1365
  });
1339
1366
  this.eventDispatcher.dispatchEvent("sessionTransition", {
@@ -1374,12 +1401,16 @@ var Transport = class {
1374
1401
  }
1375
1402
  session.log?.info(`closing session ${session.id}`, loggingMetadata);
1376
1403
  this.eventDispatcher.dispatchEvent("sessionStatus", {
1377
- status: "disconnect",
1404
+ status: "closing",
1378
1405
  session
1379
1406
  });
1380
1407
  const to = session.to;
1381
1408
  session.close();
1382
1409
  this.sessions.delete(to);
1410
+ this.eventDispatcher.dispatchEvent("sessionStatus", {
1411
+ status: "closed",
1412
+ session: { id: session.id, to }
1413
+ });
1383
1414
  }
1384
1415
  // common listeners
1385
1416
  onSessionGracePeriodElapsed(session) {
@@ -1516,14 +1547,6 @@ var LeakyBucketRateLimit = class {
1516
1547
  }
1517
1548
  };
1518
1549
 
1519
- // transport/stringifyError.ts
1520
- function coerceErrorString(err) {
1521
- if (err instanceof Error) {
1522
- return err.message || "unknown reason";
1523
- }
1524
- return `[coerced to error] ${String(err)}`;
1525
- }
1526
-
1527
1550
  // transport/client.ts
1528
1551
  var import_value2 = require("@sinclair/typebox/value");
1529
1552
  var ClientTransport = class extends Transport {
@@ -1580,6 +1603,7 @@ var ClientTransport = class extends Transport {
1580
1603
  },
1581
1604
  this.options,
1582
1605
  currentProtocolVersion,
1606
+ this.tracer,
1583
1607
  this.log
1584
1608
  );
1585
1609
  this.createSession(session);
@@ -1784,23 +1808,27 @@ var ClientTransport = class extends Transport {
1784
1808
  * and don't want to wait for the grace period to elapse.
1785
1809
  */
1786
1810
  hardDisconnect() {
1787
- for (const session of this.sessions.values()) {
1811
+ const sessions = Array.from(this.sessions.values());
1812
+ for (const session of sessions) {
1788
1813
  this.deleteSession(session);
1789
1814
  }
1790
1815
  }
1791
1816
  onBackoffFinished(session) {
1792
- const connPromise = tracing_default.startActiveSpan("connect", async (span) => {
1793
- try {
1794
- return await this.createNewOutgoingConnection(session.to);
1795
- } catch (err) {
1796
- const errStr = coerceErrorString(err);
1797
- span.recordException(errStr);
1798
- span.setStatus({ code: import_api4.SpanStatusCode.ERROR });
1799
- throw err;
1800
- } finally {
1801
- span.end();
1817
+ const connPromise = session.tracer.startActiveSpan(
1818
+ "connect",
1819
+ async (span) => {
1820
+ try {
1821
+ return await this.createNewOutgoingConnection(session.to);
1822
+ } catch (err) {
1823
+ const errStr = coerceErrorString(err);
1824
+ span.recordException(errStr);
1825
+ span.setStatus({ code: import_api4.SpanStatusCode.ERROR });
1826
+ throw err;
1827
+ } finally {
1828
+ span.end();
1829
+ }
1802
1830
  }
1803
- });
1831
+ );
1804
1832
  const connectingSession = ClientSessionStateGraph.transition.BackingOffToConnecting(
1805
1833
  session,
1806
1834
  connPromise,
@@ -1973,6 +2001,7 @@ var ServerTransport = class extends Transport {
1973
2001
  }
1974
2002
  },
1975
2003
  this.options,
2004
+ this.tracer,
1976
2005
  this.log
1977
2006
  );
1978
2007
  this.pendingSessions.add(pendingSession);
@@ -2255,6 +2284,22 @@ var Connection = class {
2255
2284
  get errorListeners() {
2256
2285
  return [...this._errorListeners];
2257
2286
  }
2287
+ onData(msg) {
2288
+ for (const cb of this.dataListeners) {
2289
+ cb(msg);
2290
+ }
2291
+ }
2292
+ onError(err) {
2293
+ for (const cb of this.errorListeners) {
2294
+ cb(err);
2295
+ }
2296
+ }
2297
+ onClose() {
2298
+ for (const cb of this.closeListeners) {
2299
+ cb();
2300
+ }
2301
+ this.telemetry?.span.end();
2302
+ }
2258
2303
  /**
2259
2304
  * Handle adding a callback for when a message is received.
2260
2305
  * @param msg The message that was received.