@replit/river 0.26.2 → 0.26.4

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 (52) hide show
  1. package/dist/{chunk-NC54BC47.js → chunk-42SXIIHP.js} +45 -17
  2. package/dist/chunk-42SXIIHP.js.map +1 -0
  3. package/dist/{chunk-M75K5TJS.js → chunk-65EMTMCV.js} +2 -2
  4. package/dist/{chunk-M75K5TJS.js.map → chunk-65EMTMCV.js.map} +1 -1
  5. package/dist/{chunk-AWCUCZY4.js → chunk-CYD6GTCU.js} +2 -2
  6. package/dist/{chunk-YQABPD3C.js → chunk-DS5LF6PS.js} +51 -56
  7. package/dist/chunk-DS5LF6PS.js.map +1 -0
  8. package/dist/{chunk-IV27BICV.js → chunk-HPOR6FST.js} +30 -31
  9. package/dist/chunk-HPOR6FST.js.map +1 -0
  10. package/dist/{chunk-MREEJE3X.js → chunk-PXRKBNWN.js} +2 -2
  11. package/dist/{chunk-M5X4JTU3.js → chunk-RSCUADHY.js} +5 -4
  12. package/dist/{chunk-M5X4JTU3.js.map → chunk-RSCUADHY.js.map} +1 -1
  13. package/dist/{client-654098be.d.ts → client-6c67339a.d.ts} +3 -3
  14. package/dist/{connection-bc2454dc.d.ts → connection-03ffb583.d.ts} +1 -1
  15. package/dist/{handshake-1a86f06d.d.ts → handshake-154a0bb2.d.ts} +30 -1
  16. package/dist/logging/index.d.cts +1 -1
  17. package/dist/logging/index.d.ts +1 -1
  18. package/dist/{message-57296605.d.ts → message-ff78a233.d.ts} +1 -1
  19. package/dist/router/index.cjs +1 -1
  20. package/dist/router/index.cjs.map +1 -1
  21. package/dist/router/index.d.cts +9 -8
  22. package/dist/router/index.d.ts +9 -8
  23. package/dist/router/index.js +2 -2
  24. package/dist/{server-9a6b5a8e.d.ts → server-1f5eb427.d.ts} +17 -4
  25. package/dist/{services-7daa60a0.d.ts → services-6140f578.d.ts} +3 -3
  26. package/dist/transport/impls/ws/client.cjs +75 -46
  27. package/dist/transport/impls/ws/client.cjs.map +1 -1
  28. package/dist/transport/impls/ws/client.d.cts +5 -4
  29. package/dist/transport/impls/ws/client.d.ts +5 -4
  30. package/dist/transport/impls/ws/client.js +8 -7
  31. package/dist/transport/impls/ws/client.js.map +1 -1
  32. package/dist/transport/impls/ws/server.cjs +93 -69
  33. package/dist/transport/impls/ws/server.cjs.map +1 -1
  34. package/dist/transport/impls/ws/server.d.cts +5 -4
  35. package/dist/transport/impls/ws/server.d.ts +5 -4
  36. package/dist/transport/impls/ws/server.js +5 -5
  37. package/dist/transport/index.cjs +119 -96
  38. package/dist/transport/index.cjs.map +1 -1
  39. package/dist/transport/index.d.cts +5 -4
  40. package/dist/transport/index.d.ts +5 -4
  41. package/dist/transport/index.js +5 -5
  42. package/dist/util/testHelpers.cjs +44 -16
  43. package/dist/util/testHelpers.cjs.map +1 -1
  44. package/dist/util/testHelpers.d.cts +5 -4
  45. package/dist/util/testHelpers.d.ts +5 -4
  46. package/dist/util/testHelpers.js +3 -3
  47. package/package.json +1 -1
  48. package/dist/chunk-IV27BICV.js.map +0 -1
  49. package/dist/chunk-NC54BC47.js.map +0 -1
  50. package/dist/chunk-YQABPD3C.js.map +0 -1
  51. /package/dist/{chunk-AWCUCZY4.js.map → chunk-CYD6GTCU.js.map} +0 -0
  52. /package/dist/{chunk-MREEJE3X.js.map → chunk-PXRKBNWN.js.map} +0 -0
@@ -1,12 +1,13 @@
1
- import { c as TransportClientId } from '../../../message-57296605.js';
1
+ import { c as TransportClientId } from '../../../message-ff78a233.js';
2
2
  import { WebSocketServer } from 'ws';
3
- import { W as WebSocketConnection } from '../../../connection-bc2454dc.js';
3
+ import { W as WebSocketConnection } from '../../../connection-03ffb583.js';
4
4
  import { W as WsLike } from '../../../wslike-e0b32dd5.js';
5
- import { S as ServerTransport } from '../../../server-9a6b5a8e.js';
6
- import { c as ProvidedServerTransportOptions } from '../../../handshake-1a86f06d.js';
5
+ import { S as ServerTransport } from '../../../server-1f5eb427.js';
6
+ import { c as ProvidedServerTransportOptions } from '../../../handshake-154a0bb2.js';
7
7
  import '@sinclair/typebox/value';
8
8
  import '@sinclair/typebox';
9
9
  import '@opentelemetry/api';
10
+ import '@sinclair/typebox/errors';
10
11
  import '../../../types-3e5768ec.js';
11
12
 
12
13
  declare class WebSocketServerTransport extends ServerTransport<WebSocketConnection> {
@@ -1,12 +1,13 @@
1
- import { c as TransportClientId } from '../../../message-57296605.js';
1
+ import { c as TransportClientId } from '../../../message-ff78a233.js';
2
2
  import { WebSocketServer } from 'ws';
3
- import { W as WebSocketConnection } from '../../../connection-bc2454dc.js';
3
+ import { W as WebSocketConnection } from '../../../connection-03ffb583.js';
4
4
  import { W as WsLike } from '../../../wslike-e0b32dd5.js';
5
- import { S as ServerTransport } from '../../../server-9a6b5a8e.js';
6
- import { c as ProvidedServerTransportOptions } from '../../../handshake-1a86f06d.js';
5
+ import { S as ServerTransport } from '../../../server-1f5eb427.js';
6
+ import { c as ProvidedServerTransportOptions } from '../../../handshake-154a0bb2.js';
7
7
  import '@sinclair/typebox/value';
8
8
  import '@sinclair/typebox';
9
9
  import '@opentelemetry/api';
10
+ import '@sinclair/typebox/errors';
10
11
  import '../../../types-3e5768ec.js';
11
12
 
12
13
  declare class WebSocketServerTransport extends ServerTransport<WebSocketConnection> {
@@ -1,13 +1,13 @@
1
1
  import {
2
2
  ServerTransport
3
- } from "../../../chunk-YQABPD3C.js";
3
+ } from "../../../chunk-DS5LF6PS.js";
4
4
  import {
5
5
  WebSocketConnection
6
- } from "../../../chunk-AWCUCZY4.js";
7
- import "../../../chunk-M5X4JTU3.js";
6
+ } from "../../../chunk-CYD6GTCU.js";
7
+ import "../../../chunk-RSCUADHY.js";
8
8
  import "../../../chunk-TAH2GVTJ.js";
9
- import "../../../chunk-NC54BC47.js";
10
- import "../../../chunk-M75K5TJS.js";
9
+ import "../../../chunk-42SXIIHP.js";
10
+ import "../../../chunk-65EMTMCV.js";
11
11
  import "../../../chunk-4PVU7J25.js";
12
12
 
13
13
  // transport/impls/ws/server.ts
@@ -385,6 +385,7 @@ var StateMachineState = class {
385
385
  }
386
386
  if (prop === "_handleClose") {
387
387
  return () => {
388
+ target._isConsumed = true;
388
389
  target._handleStateExit();
389
390
  target._handleClose();
390
391
  };
@@ -465,15 +466,18 @@ var IdentifiedSession = class extends CommonSession {
465
466
  }
466
467
  get loggingMetadata() {
467
468
  const spanContext = this.telemetry.span.spanContext();
468
- return {
469
+ const metadata = {
469
470
  clientId: this.from,
470
471
  connectedTo: this.to,
471
- sessionId: this.id,
472
- telemetry: {
472
+ sessionId: this.id
473
+ };
474
+ if (this.telemetry.span.isRecording()) {
475
+ metadata.telemetry = {
473
476
  traceId: spanContext.traceId,
474
477
  spanId: spanContext.spanId
475
- }
476
- };
478
+ };
479
+ }
480
+ return metadata;
477
481
  }
478
482
  constructMsg(partialMsg) {
479
483
  const msg = {
@@ -536,9 +540,6 @@ var SessionConnecting = class extends IdentifiedSessionWithGracePeriod {
536
540
  super(props);
537
541
  this.connPromise = props.connPromise;
538
542
  this.listeners = props.listeners;
539
- this.connectionTimeout = setTimeout(() => {
540
- this.listeners.onConnectionTimeout();
541
- }, this.options.connectionTimeoutMs);
542
543
  this.connPromise.then(
543
544
  (conn) => {
544
545
  if (this._isConsumed)
@@ -551,11 +552,25 @@ var SessionConnecting = class extends IdentifiedSessionWithGracePeriod {
551
552
  this.listeners.onConnectionFailed(err);
552
553
  }
553
554
  );
555
+ this.connectionTimeout = setTimeout(() => {
556
+ this.listeners.onConnectionTimeout();
557
+ }, this.options.connectionTimeoutMs);
554
558
  }
555
559
  // close a pending connection if it resolves, ignore errors if the promise
556
560
  // ends up rejected anyways
557
561
  bestEffortClose() {
558
- void this.connPromise.then((conn) => conn.close()).catch(() => {
562
+ const logger = this.log;
563
+ const metadata = this.loggingMetadata;
564
+ this.connPromise.then((conn) => {
565
+ conn.close();
566
+ logger?.info(
567
+ "connection eventually resolved but session has transitioned, closed connection",
568
+ {
569
+ ...metadata,
570
+ ...conn.loggingMetadata
571
+ }
572
+ );
573
+ }).catch(() => {
559
574
  });
560
575
  }
561
576
  _handleStateExit() {
@@ -586,7 +601,7 @@ var SessionNoConnection = class extends IdentifiedSessionWithGracePeriod {
586
601
  var import_api = require("@opentelemetry/api");
587
602
 
588
603
  // package.json
589
- var version = "0.26.2";
604
+ var version = "0.26.4";
590
605
 
591
606
  // tracing/index.ts
592
607
  function getPropagationContext(ctx) {
@@ -634,6 +649,13 @@ var SessionWaitingForHandshake = class extends CommonSession {
634
649
  this.conn.addErrorListener(this.listeners.onConnectionErrored);
635
650
  this.conn.addCloseListener(this.listeners.onConnectionClosed);
636
651
  }
652
+ get loggingMetadata() {
653
+ return {
654
+ clientId: this.from,
655
+ connId: this.conn.id,
656
+ ...this.conn.loggingMetadata
657
+ };
658
+ }
637
659
  onHandshakeData = (msg) => {
638
660
  const parsedMsg = this.parseMsg(msg);
639
661
  if (parsedMsg === null) {
@@ -645,12 +667,6 @@ var SessionWaitingForHandshake = class extends CommonSession {
645
667
  }
646
668
  this.listeners.onHandshake(parsedMsg);
647
669
  };
648
- get loggingMetadata() {
649
- return {
650
- clientId: this.from,
651
- connId: this.conn.id
652
- };
653
- }
654
670
  sendHandshake(msg) {
655
671
  return this.conn.send(this.options.codec.toBuffer(msg));
656
672
  }
@@ -683,6 +699,12 @@ var SessionHandshaking = class extends IdentifiedSessionWithGracePeriod {
683
699
  this.conn.addErrorListener(this.listeners.onConnectionErrored);
684
700
  this.conn.addCloseListener(this.listeners.onConnectionClosed);
685
701
  }
702
+ get loggingMetadata() {
703
+ return {
704
+ ...super.loggingMetadata,
705
+ ...this.conn.loggingMetadata
706
+ };
707
+ }
686
708
  onHandshakeData = (msg) => {
687
709
  const parsedMsg = this.parseMsg(msg);
688
710
  if (parsedMsg === null) {
@@ -770,6 +792,12 @@ var SessionConnected = class extends IdentifiedSession {
770
792
  this.heartbeatMisses++;
771
793
  }, this.options.heartbeatIntervalMs);
772
794
  }
795
+ get loggingMetadata() {
796
+ return {
797
+ ...super.loggingMetadata,
798
+ ...this.conn.loggingMetadata
799
+ };
800
+ }
773
801
  startActiveHeartbeat() {
774
802
  this.isActivelyHeartbeating = true;
775
803
  }
@@ -1271,8 +1299,9 @@ var Transport = class {
1271
1299
  status: "disconnect",
1272
1300
  session
1273
1301
  });
1302
+ const to = session.to;
1274
1303
  session.close();
1275
- this.sessions.delete(session.to);
1304
+ this.sessions.delete(to);
1276
1305
  }
1277
1306
  // common listeners
1278
1307
  onSessionGracePeriodElapsed(session) {
@@ -1546,14 +1575,14 @@ var ClientTransport = class extends Transport {
1546
1575
  msg.payload.status.code
1547
1576
  ) : false;
1548
1577
  const reason = `handshake failed: ${msg.payload.status.reason}`;
1578
+ const to = session.to;
1549
1579
  this.rejectHandshakeResponse(session, reason, {
1550
1580
  ...session.loggingMetadata,
1551
1581
  transportMessage: msg
1552
1582
  });
1553
1583
  if (retriable) {
1554
- this.tryReconnecting(session.to);
1584
+ this.tryReconnecting(to);
1555
1585
  } else {
1556
- this.deleteSession(session);
1557
1586
  this.protocolError({
1558
1587
  type: ProtocolError.HandshakeFailed,
1559
1588
  code: msg.payload.status.code,
@@ -1606,6 +1635,12 @@ var ClientTransport = class extends Transport {
1606
1635
  * @param to The client ID of the node to connect to.
1607
1636
  */
1608
1637
  connect(to) {
1638
+ if (this.getStatus() !== "open") {
1639
+ this.log?.info(
1640
+ `transport state is no longer open, cancelling attempt to connect to ${to}`
1641
+ );
1642
+ return;
1643
+ }
1609
1644
  let session = this.sessions.get(to);
1610
1645
  session ??= this.createUnconnectedSession(to);
1611
1646
  if (session.state !== "NoConnection" /* NoConnection */) {
@@ -1615,13 +1650,6 @@ var ClientTransport = class extends Transport {
1615
1650
  );
1616
1651
  return;
1617
1652
  }
1618
- if (this.getStatus() !== "open") {
1619
- this.log?.info(
1620
- `transport state is no longer open, cancelling attempt to connect to ${to}`,
1621
- session.loggingMetadata
1622
- );
1623
- return;
1624
- }
1625
1653
  if (!this.retryBudget.hasBudget()) {
1626
1654
  const budgetConsumed = this.retryBudget.getBudgetConsumed();
1627
1655
  const errMsg = `tried to connect to ${to} but retry budget exceeded (more than ${budgetConsumed} attempts in the last ${this.retryBudget.totalBudgetRestoreTime}ms)`;
@@ -1643,22 +1671,7 @@ var ClientTransport = class extends Transport {
1643
1671
  backoffMs,
1644
1672
  {
1645
1673
  onBackoffFinished: () => {
1646
- const reconnectPromise = tracing_default.startActiveSpan(
1647
- "connect",
1648
- async (span) => {
1649
- try {
1650
- return await this.createNewOutgoingConnection(to);
1651
- } catch (err) {
1652
- const errStr = coerceErrorString(err);
1653
- span.recordException(errStr);
1654
- span.setStatus({ code: import_api3.SpanStatusCode.ERROR });
1655
- throw err;
1656
- } finally {
1657
- span.end();
1658
- }
1659
- }
1660
- );
1661
- this.onBackoffFinished(backingOffSession, reconnectPromise);
1674
+ this.onBackoffFinished(backingOffSession);
1662
1675
  },
1663
1676
  onSessionGracePeriodElapsed: () => {
1664
1677
  this.onSessionGracePeriodElapsed(backingOffSession);
@@ -1667,7 +1680,19 @@ var ClientTransport = class extends Transport {
1667
1680
  );
1668
1681
  this.updateSession(backingOffSession);
1669
1682
  }
1670
- onBackoffFinished(session, connPromise) {
1683
+ onBackoffFinished(session) {
1684
+ const connPromise = tracing_default.startActiveSpan("connect", async (span) => {
1685
+ try {
1686
+ return await this.createNewOutgoingConnection(session.to);
1687
+ } catch (err) {
1688
+ const errStr = coerceErrorString(err);
1689
+ span.recordException(errStr);
1690
+ span.setStatus({ code: import_api3.SpanStatusCode.ERROR });
1691
+ throw err;
1692
+ } finally {
1693
+ span.end();
1694
+ }
1695
+ });
1671
1696
  const connectingSession = ClientSessionStateGraph.transition.BackingOffToConnecting(
1672
1697
  session,
1673
1698
  connPromise,
@@ -1675,7 +1700,10 @@ var ClientTransport = class extends Transport {
1675
1700
  onConnectionEstablished: (conn) => {
1676
1701
  this.log?.debug(
1677
1702
  `connection to ${connectingSession.to} established`,
1678
- connectingSession.loggingMetadata
1703
+ {
1704
+ ...conn.loggingMetadata,
1705
+ ...connectingSession.loggingMetadata
1706
+ }
1679
1707
  );
1680
1708
  this.onConnectionEstablished(connectingSession, conn);
1681
1709
  },
@@ -1918,14 +1946,53 @@ var ServerTransport = class extends Transport {
1918
1946
  return;
1919
1947
  }
1920
1948
  let oldSession = this.sessions.get(msg.from);
1921
- const parsedMetadata = await this.validateHandshakeMetadata(
1922
- session,
1923
- oldSession,
1924
- msg.payload.metadata,
1925
- msg.from
1926
- );
1927
- if (parsedMetadata === false) {
1928
- return;
1949
+ let parsedMetadata = {};
1950
+ if (this.handshakeExtensions) {
1951
+ if (!import_value3.Value.Check(this.handshakeExtensions.schema, msg.payload.metadata)) {
1952
+ this.rejectHandshakeRequest(
1953
+ session,
1954
+ msg.from,
1955
+ "received malformed handshake metadata",
1956
+ "MALFORMED_HANDSHAKE_META",
1957
+ {
1958
+ ...session.loggingMetadata,
1959
+ connectedTo: msg.from,
1960
+ validationErrors: [
1961
+ ...import_value3.Value.Errors(
1962
+ this.handshakeExtensions.schema,
1963
+ msg.payload.metadata
1964
+ )
1965
+ ]
1966
+ }
1967
+ );
1968
+ return;
1969
+ }
1970
+ const previousParsedMetadata = oldSession ? this.sessionHandshakeMetadata.get(oldSession.to) : void 0;
1971
+ const parsedMetadataOrFailureCode = await this.handshakeExtensions.validate(
1972
+ msg.payload.metadata,
1973
+ previousParsedMetadata
1974
+ );
1975
+ if (session._isConsumed) {
1976
+ return;
1977
+ }
1978
+ if (import_value3.Value.Check(
1979
+ HandshakeErrorCustomHandlerFatalResponseCodes,
1980
+ parsedMetadataOrFailureCode
1981
+ )) {
1982
+ this.rejectHandshakeRequest(
1983
+ session,
1984
+ msg.from,
1985
+ "rejected by handshake handler",
1986
+ parsedMetadataOrFailureCode,
1987
+ {
1988
+ ...session.loggingMetadata,
1989
+ connectedTo: msg.from,
1990
+ clientId: this.clientId
1991
+ }
1992
+ );
1993
+ return;
1994
+ }
1995
+ parsedMetadata = parsedMetadataOrFailureCode;
1929
1996
  }
1930
1997
  let connectCase = "new session";
1931
1998
  const clientNextExpectedSeq = msg.payload.expectedSessionState.nextExpectedSeq;
@@ -2057,50 +2124,6 @@ var ServerTransport = class extends Transport {
2057
2124
  this.pendingSessions.delete(session);
2058
2125
  connectedSession.startActiveHeartbeat();
2059
2126
  }
2060
- async validateHandshakeMetadata(handshakingSession, existingSession, rawMetadata, from) {
2061
- if (!this.handshakeExtensions) {
2062
- return {};
2063
- }
2064
- if (!import_value3.Value.Check(this.handshakeExtensions.schema, rawMetadata)) {
2065
- this.rejectHandshakeRequest(
2066
- handshakingSession,
2067
- from,
2068
- "received malformed handshake metadata",
2069
- "MALFORMED_HANDSHAKE_META",
2070
- {
2071
- ...handshakingSession.loggingMetadata,
2072
- connectedTo: from,
2073
- validationErrors: [
2074
- ...import_value3.Value.Errors(this.handshakeExtensions.schema, rawMetadata)
2075
- ]
2076
- }
2077
- );
2078
- return false;
2079
- }
2080
- const previousParsedMetadata = existingSession ? this.sessionHandshakeMetadata.get(existingSession.to) : void 0;
2081
- const parsedMetadataOrFailureCode = await this.handshakeExtensions.validate(
2082
- rawMetadata,
2083
- previousParsedMetadata
2084
- );
2085
- if (import_value3.Value.Check(
2086
- HandshakeErrorCustomHandlerFatalResponseCodes,
2087
- parsedMetadataOrFailureCode
2088
- )) {
2089
- this.rejectHandshakeRequest(
2090
- handshakingSession,
2091
- from,
2092
- "rejected by handshake handler",
2093
- parsedMetadataOrFailureCode,
2094
- {
2095
- ...handshakingSession.loggingMetadata,
2096
- connectedTo: from,
2097
- clientId: this.clientId
2098
- }
2099
- );
2100
- return false;
2101
- }
2102
- return parsedMetadataOrFailureCode;
2103
- }
2104
2127
  };
2105
2128
 
2106
2129
  // transport/connection.ts