@replit/river 0.26.2 → 0.26.3

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-MREEJE3X.js → chunk-3JCZNGF7.js} +2 -2
  2. package/dist/{chunk-IV27BICV.js → chunk-BB2E5L4U.js} +12 -13
  3. package/dist/chunk-BB2E5L4U.js.map +1 -0
  4. package/dist/{chunk-M5X4JTU3.js → chunk-JI6FFDY5.js} +5 -4
  5. package/dist/{chunk-M5X4JTU3.js.map → chunk-JI6FFDY5.js.map} +1 -1
  6. package/dist/{chunk-M75K5TJS.js → chunk-MZELCWJK.js} +2 -2
  7. package/dist/{chunk-M75K5TJS.js.map → chunk-MZELCWJK.js.map} +1 -1
  8. package/dist/{chunk-NC54BC47.js → chunk-OCL2FUTQ.js} +40 -14
  9. package/dist/chunk-OCL2FUTQ.js.map +1 -0
  10. package/dist/{chunk-YQABPD3C.js → chunk-X35QRIA5.js} +51 -56
  11. package/dist/chunk-X35QRIA5.js.map +1 -0
  12. package/dist/{chunk-AWCUCZY4.js → chunk-ZY2HYJ5Y.js} +2 -2
  13. package/dist/{client-654098be.d.ts → client-1894a9c9.d.ts} +2 -2
  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-491d8c32.d.ts} +3 -3
  26. package/dist/transport/impls/ws/client.cjs +52 -25
  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 +88 -66
  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 +96 -75
  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 +39 -13
  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-MREEJE3X.js.map → chunk-3JCZNGF7.js.map} +0 -0
  52. /package/dist/{chunk-AWCUCZY4.js.map → chunk-ZY2HYJ5Y.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-X35QRIA5.js";
4
4
  import {
5
5
  WebSocketConnection
6
- } from "../../../chunk-AWCUCZY4.js";
7
- import "../../../chunk-M5X4JTU3.js";
6
+ } from "../../../chunk-ZY2HYJ5Y.js";
7
+ import "../../../chunk-JI6FFDY5.js";
8
8
  import "../../../chunk-TAH2GVTJ.js";
9
- import "../../../chunk-NC54BC47.js";
10
- import "../../../chunk-M75K5TJS.js";
9
+ import "../../../chunk-OCL2FUTQ.js";
10
+ import "../../../chunk-MZELCWJK.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 = {
@@ -555,7 +559,16 @@ var SessionConnecting = class extends IdentifiedSessionWithGracePeriod {
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
+ void this.connPromise.then((conn) => {
563
+ conn.close();
564
+ this.log?.info(
565
+ "connection eventually resolved but session has transitioned, closed connection",
566
+ {
567
+ ...this.loggingMetadata,
568
+ ...conn.loggingMetadata
569
+ }
570
+ );
571
+ }).catch(() => {
559
572
  });
560
573
  }
561
574
  _handleStateExit() {
@@ -586,7 +599,7 @@ var SessionNoConnection = class extends IdentifiedSessionWithGracePeriod {
586
599
  var import_api = require("@opentelemetry/api");
587
600
 
588
601
  // package.json
589
- var version = "0.26.2";
602
+ var version = "0.26.3";
590
603
 
591
604
  // tracing/index.ts
592
605
  function getPropagationContext(ctx) {
@@ -634,6 +647,13 @@ var SessionWaitingForHandshake = class extends CommonSession {
634
647
  this.conn.addErrorListener(this.listeners.onConnectionErrored);
635
648
  this.conn.addCloseListener(this.listeners.onConnectionClosed);
636
649
  }
650
+ get loggingMetadata() {
651
+ return {
652
+ clientId: this.from,
653
+ connId: this.conn.id,
654
+ ...this.conn.loggingMetadata
655
+ };
656
+ }
637
657
  onHandshakeData = (msg) => {
638
658
  const parsedMsg = this.parseMsg(msg);
639
659
  if (parsedMsg === null) {
@@ -645,12 +665,6 @@ var SessionWaitingForHandshake = class extends CommonSession {
645
665
  }
646
666
  this.listeners.onHandshake(parsedMsg);
647
667
  };
648
- get loggingMetadata() {
649
- return {
650
- clientId: this.from,
651
- connId: this.conn.id
652
- };
653
- }
654
668
  sendHandshake(msg) {
655
669
  return this.conn.send(this.options.codec.toBuffer(msg));
656
670
  }
@@ -683,6 +697,12 @@ var SessionHandshaking = class extends IdentifiedSessionWithGracePeriod {
683
697
  this.conn.addErrorListener(this.listeners.onConnectionErrored);
684
698
  this.conn.addCloseListener(this.listeners.onConnectionClosed);
685
699
  }
700
+ get loggingMetadata() {
701
+ return {
702
+ ...super.loggingMetadata,
703
+ ...this.conn.loggingMetadata
704
+ };
705
+ }
686
706
  onHandshakeData = (msg) => {
687
707
  const parsedMsg = this.parseMsg(msg);
688
708
  if (parsedMsg === null) {
@@ -770,6 +790,12 @@ var SessionConnected = class extends IdentifiedSession {
770
790
  this.heartbeatMisses++;
771
791
  }, this.options.heartbeatIntervalMs);
772
792
  }
793
+ get loggingMetadata() {
794
+ return {
795
+ ...super.loggingMetadata,
796
+ ...this.conn.loggingMetadata
797
+ };
798
+ }
773
799
  startActiveHeartbeat() {
774
800
  this.isActivelyHeartbeating = true;
775
801
  }
@@ -1271,8 +1297,9 @@ var Transport = class {
1271
1297
  status: "disconnect",
1272
1298
  session
1273
1299
  });
1300
+ const to = session.to;
1274
1301
  session.close();
1275
- this.sessions.delete(session.to);
1302
+ this.sessions.delete(to);
1276
1303
  }
1277
1304
  // common listeners
1278
1305
  onSessionGracePeriodElapsed(session) {
@@ -1546,14 +1573,14 @@ var ClientTransport = class extends Transport {
1546
1573
  msg.payload.status.code
1547
1574
  ) : false;
1548
1575
  const reason = `handshake failed: ${msg.payload.status.reason}`;
1576
+ const to = session.to;
1549
1577
  this.rejectHandshakeResponse(session, reason, {
1550
1578
  ...session.loggingMetadata,
1551
1579
  transportMessage: msg
1552
1580
  });
1553
1581
  if (retriable) {
1554
- this.tryReconnecting(session.to);
1582
+ this.tryReconnecting(to);
1555
1583
  } else {
1556
- this.deleteSession(session);
1557
1584
  this.protocolError({
1558
1585
  type: ProtocolError.HandshakeFailed,
1559
1586
  code: msg.payload.status.code,
@@ -1606,6 +1633,12 @@ var ClientTransport = class extends Transport {
1606
1633
  * @param to The client ID of the node to connect to.
1607
1634
  */
1608
1635
  connect(to) {
1636
+ if (this.getStatus() !== "open") {
1637
+ this.log?.info(
1638
+ `transport state is no longer open, cancelling attempt to connect to ${to}`
1639
+ );
1640
+ return;
1641
+ }
1609
1642
  let session = this.sessions.get(to);
1610
1643
  session ??= this.createUnconnectedSession(to);
1611
1644
  if (session.state !== "NoConnection" /* NoConnection */) {
@@ -1615,13 +1648,6 @@ var ClientTransport = class extends Transport {
1615
1648
  );
1616
1649
  return;
1617
1650
  }
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
1651
  if (!this.retryBudget.hasBudget()) {
1626
1652
  const budgetConsumed = this.retryBudget.getBudgetConsumed();
1627
1653
  const errMsg = `tried to connect to ${to} but retry budget exceeded (more than ${budgetConsumed} attempts in the last ${this.retryBudget.totalBudgetRestoreTime}ms)`;
@@ -1918,14 +1944,53 @@ var ServerTransport = class extends Transport {
1918
1944
  return;
1919
1945
  }
1920
1946
  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;
1947
+ let parsedMetadata = {};
1948
+ if (this.handshakeExtensions) {
1949
+ if (!import_value3.Value.Check(this.handshakeExtensions.schema, msg.payload.metadata)) {
1950
+ this.rejectHandshakeRequest(
1951
+ session,
1952
+ msg.from,
1953
+ "received malformed handshake metadata",
1954
+ "MALFORMED_HANDSHAKE_META",
1955
+ {
1956
+ ...session.loggingMetadata,
1957
+ connectedTo: msg.from,
1958
+ validationErrors: [
1959
+ ...import_value3.Value.Errors(
1960
+ this.handshakeExtensions.schema,
1961
+ msg.payload.metadata
1962
+ )
1963
+ ]
1964
+ }
1965
+ );
1966
+ return;
1967
+ }
1968
+ const previousParsedMetadata = oldSession ? this.sessionHandshakeMetadata.get(oldSession.to) : void 0;
1969
+ const parsedMetadataOrFailureCode = await this.handshakeExtensions.validate(
1970
+ msg.payload.metadata,
1971
+ previousParsedMetadata
1972
+ );
1973
+ if (session._isConsumed) {
1974
+ return;
1975
+ }
1976
+ if (import_value3.Value.Check(
1977
+ HandshakeErrorCustomHandlerFatalResponseCodes,
1978
+ parsedMetadataOrFailureCode
1979
+ )) {
1980
+ this.rejectHandshakeRequest(
1981
+ session,
1982
+ msg.from,
1983
+ "rejected by handshake handler",
1984
+ parsedMetadataOrFailureCode,
1985
+ {
1986
+ ...session.loggingMetadata,
1987
+ connectedTo: msg.from,
1988
+ clientId: this.clientId
1989
+ }
1990
+ );
1991
+ return;
1992
+ }
1993
+ parsedMetadata = parsedMetadataOrFailureCode;
1929
1994
  }
1930
1995
  let connectCase = "new session";
1931
1996
  const clientNextExpectedSeq = msg.payload.expectedSessionState.nextExpectedSeq;
@@ -2057,50 +2122,6 @@ var ServerTransport = class extends Transport {
2057
2122
  this.pendingSessions.delete(session);
2058
2123
  connectedSession.startActiveHeartbeat();
2059
2124
  }
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
2125
  };
2105
2126
 
2106
2127
  // transport/connection.ts