@replit/river 0.207.3 → 0.208.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 (52) hide show
  1. package/dist/{adapter-f2b6e211.d.ts → adapter-ChksXKVN.d.ts} +2 -2
  2. package/dist/adapter-Cuc4JtfV.d.cts +46 -0
  3. package/dist/{chunk-BO7MFCO6.js → chunk-2JNVDUMN.js} +55 -97
  4. package/dist/chunk-2JNVDUMN.js.map +1 -0
  5. package/dist/{chunk-B7REV3ZV.js → chunk-DKW3GC3M.js} +2 -2
  6. package/dist/{chunk-QGPYCXV4.js → chunk-ETZAHFGQ.js} +80 -61
  7. package/dist/chunk-ETZAHFGQ.js.map +1 -0
  8. package/dist/codec/index.d.cts +3 -3
  9. package/dist/codec/index.d.ts +3 -3
  10. package/dist/codec/index.js +2 -2
  11. package/dist/connection-BF4zg6Qv.d.cts +35 -0
  12. package/dist/{connection-06d72f2e.d.ts → connection-Donr3JRB.d.ts} +4 -4
  13. package/dist/index-C9tpZjBN.d.cts +37 -0
  14. package/dist/{index-02554794.d.ts → index-D8IOd3LG.d.ts} +2 -2
  15. package/dist/logging/index.d.cts +2 -2
  16. package/dist/logging/index.d.ts +2 -2
  17. package/dist/{message-01c3e85a.d.ts → message-Di94OL80.d.cts} +1 -1
  18. package/dist/message-Di94OL80.d.ts +108 -0
  19. package/dist/router/index.cjs +62 -43
  20. package/dist/router/index.cjs.map +1 -1
  21. package/dist/router/index.d.cts +27 -8
  22. package/dist/router/index.d.ts +27 -8
  23. package/dist/router/index.js +1 -1
  24. package/dist/testUtil/index.cjs +56 -105
  25. package/dist/testUtil/index.cjs.map +1 -1
  26. package/dist/testUtil/index.d.cts +5 -5
  27. package/dist/testUtil/index.d.ts +5 -5
  28. package/dist/testUtil/index.js +7 -14
  29. package/dist/testUtil/index.js.map +1 -1
  30. package/dist/transport/impls/ws/client.cjs +51 -80
  31. package/dist/transport/impls/ws/client.cjs.map +1 -1
  32. package/dist/transport/impls/ws/client.d.cts +6 -6
  33. package/dist/transport/impls/ws/client.d.ts +6 -6
  34. package/dist/transport/impls/ws/client.js +3 -3
  35. package/dist/transport/impls/ws/server.cjs +52 -85
  36. package/dist/transport/impls/ws/server.cjs.map +1 -1
  37. package/dist/transport/impls/ws/server.d.cts +6 -6
  38. package/dist/transport/impls/ws/server.d.ts +6 -6
  39. package/dist/transport/impls/ws/server.js +3 -3
  40. package/dist/transport/index.cjs +52 -94
  41. package/dist/transport/index.cjs.map +1 -1
  42. package/dist/transport/index.d.cts +6 -6
  43. package/dist/transport/index.d.ts +6 -6
  44. package/dist/transport/index.js +3 -3
  45. package/dist/transport-CCaWx1Rb.d.cts +1566 -0
  46. package/dist/{services-87887bc5.d.ts → transport-CZb3vdB4.d.ts} +344 -347
  47. package/dist/{wslike-e0b32dd5.d.ts → wslike-Dng9H1C7.d.cts} +1 -1
  48. package/dist/wslike-Dng9H1C7.d.ts +40 -0
  49. package/package.json +3 -3
  50. package/dist/chunk-BO7MFCO6.js.map +0 -1
  51. package/dist/chunk-QGPYCXV4.js.map +0 -1
  52. /package/dist/{chunk-B7REV3ZV.js.map → chunk-DKW3GC3M.js.map} +0 -0
@@ -1,14 +1,14 @@
1
- import { T as TransportClientId } from '../../../message-01c3e85a.js';
1
+ import { T as TransportClientId } from '../../../message-Di94OL80.cjs';
2
2
  import { WebSocketServer } from 'ws';
3
- import { W as WebSocketConnection } from '../../../connection-06d72f2e.js';
4
- import { W as WsLike } from '../../../wslike-e0b32dd5.js';
3
+ import { W as WebSocketConnection } from '../../../connection-BF4zg6Qv.cjs';
4
+ import { W as WsLike } from '../../../wslike-Dng9H1C7.cjs';
5
5
  import { ServerTransport } from '../../index.cjs';
6
- import { a as ProvidedServerTransportOptions } from '../../../services-87887bc5.js';
6
+ import { a as ProvidedServerTransportOptions } from '../../../transport-CCaWx1Rb.cjs';
7
7
  import { IncomingMessage } from 'http';
8
8
  import '@sinclair/typebox';
9
9
  import '@opentelemetry/api';
10
- import '../../../index-02554794.js';
11
- import '../../../adapter-f2b6e211.js';
10
+ import '../../../index-C9tpZjBN.cjs';
11
+ import '../../../adapter-Cuc4JtfV.cjs';
12
12
 
13
13
  declare class WebSocketServerTransport extends ServerTransport<WebSocketConnection> {
14
14
  wss: WebSocketServer;
@@ -1,14 +1,14 @@
1
- import { T as TransportClientId } from '../../../message-01c3e85a.js';
1
+ import { T as TransportClientId } from '../../../message-Di94OL80.js';
2
2
  import { WebSocketServer } from 'ws';
3
- import { W as WebSocketConnection } from '../../../connection-06d72f2e.js';
4
- import { W as WsLike } from '../../../wslike-e0b32dd5.js';
3
+ import { W as WebSocketConnection } from '../../../connection-Donr3JRB.js';
4
+ import { W as WsLike } from '../../../wslike-Dng9H1C7.js';
5
5
  import { ServerTransport } from '../../index.js';
6
- import { a as ProvidedServerTransportOptions } from '../../../services-87887bc5.js';
6
+ import { a as ProvidedServerTransportOptions } from '../../../transport-CZb3vdB4.js';
7
7
  import { IncomingMessage } from 'http';
8
8
  import '@sinclair/typebox';
9
9
  import '@opentelemetry/api';
10
- import '../../../index-02554794.js';
11
- import '../../../adapter-f2b6e211.js';
10
+ import '../../../index-D8IOd3LG.js';
11
+ import '../../../adapter-ChksXKVN.js';
12
12
 
13
13
  declare class WebSocketServerTransport extends ServerTransport<WebSocketConnection> {
14
14
  wss: WebSocketServer;
@@ -1,11 +1,11 @@
1
1
  import {
2
2
  WebSocketConnection
3
- } from "../../../chunk-B7REV3ZV.js";
3
+ } from "../../../chunk-DKW3GC3M.js";
4
4
  import {
5
5
  ServerTransport
6
- } from "../../../chunk-BO7MFCO6.js";
7
- import "../../../chunk-QGPYCXV4.js";
6
+ } from "../../../chunk-2JNVDUMN.js";
8
7
  import "../../../chunk-CC7RN7GI.js";
8
+ import "../../../chunk-ETZAHFGQ.js";
9
9
 
10
10
  // transport/impls/ws/server.ts
11
11
  function cleanHeaders(headers) {
@@ -434,13 +434,11 @@ var SessionConnecting = class extends IdentifiedSessionWithGracePeriod {
434
434
  this.listeners = props.listeners;
435
435
  this.connPromise.then(
436
436
  (conn) => {
437
- if (this._isConsumed)
438
- return;
437
+ if (this._isConsumed) return;
439
438
  this.listeners.onConnectionEstablished(conn);
440
439
  },
441
440
  (err) => {
442
- if (this._isConsumed)
443
- return;
441
+ if (this._isConsumed) return;
444
442
  this.listeners.onConnectionFailed(err);
445
443
  }
446
444
  );
@@ -642,7 +640,7 @@ function coerceErrorString(err) {
642
640
  }
643
641
 
644
642
  // package.json
645
- var version = "0.207.3";
643
+ var version = "0.208.0";
646
644
 
647
645
  // tracing/index.ts
648
646
  function getPropagationContext(ctx) {
@@ -656,7 +654,7 @@ function getPropagationContext(ctx) {
656
654
  function createSessionTelemetryInfo(tracer, sessionId, to, from, propagationCtx) {
657
655
  const parentCtx = propagationCtx ? import_api2.propagation.extract(import_api2.context.active(), propagationCtx) : import_api2.context.active();
658
656
  const span = tracer.startSpan(
659
- `river.session.${sessionId}`,
657
+ `river.session`,
660
658
  {
661
659
  attributes: {
662
660
  component: "river",
@@ -672,7 +670,7 @@ function createSessionTelemetryInfo(tracer, sessionId, to, from, propagationCtx)
672
670
  }
673
671
  function createConnectionTelemetryInfo(tracer, connection, info) {
674
672
  const span = tracer.startSpan(
675
- `connection ${connection.id}`,
673
+ `river.connection`,
676
674
  {
677
675
  attributes: {
678
676
  component: "river",
@@ -702,9 +700,9 @@ var SessionWaitingForHandshake = class extends CommonSession {
702
700
  this.handshakeTimeout = setTimeout(() => {
703
701
  this.listeners.onHandshakeTimeout();
704
702
  }, this.options.handshakeTimeoutMs);
705
- this.conn.addDataListener(this.onHandshakeData);
706
- this.conn.addErrorListener(this.listeners.onConnectionErrored);
707
- this.conn.addCloseListener(this.listeners.onConnectionClosed);
703
+ this.conn.setDataListener(this.onHandshakeData);
704
+ this.conn.setErrorListener(this.listeners.onConnectionErrored);
705
+ this.conn.setCloseListener(this.listeners.onConnectionClosed);
708
706
  }
709
707
  get loggingMetadata() {
710
708
  return {
@@ -728,9 +726,9 @@ var SessionWaitingForHandshake = class extends CommonSession {
728
726
  return sendMessage(this.conn, this.codec, msg);
729
727
  }
730
728
  _handleStateExit() {
731
- this.conn.removeDataListener(this.onHandshakeData);
732
- this.conn.removeErrorListener(this.listeners.onConnectionErrored);
733
- this.conn.removeCloseListener(this.listeners.onConnectionClosed);
729
+ this.conn.removeDataListener();
730
+ this.conn.removeErrorListener();
731
+ this.conn.removeCloseListener();
734
732
  clearTimeout(this.handshakeTimeout);
735
733
  this.handshakeTimeout = void 0;
736
734
  }
@@ -752,9 +750,9 @@ var SessionHandshaking = class extends IdentifiedSessionWithGracePeriod {
752
750
  this.handshakeTimeout = setTimeout(() => {
753
751
  this.listeners.onHandshakeTimeout();
754
752
  }, this.options.handshakeTimeoutMs);
755
- this.conn.addDataListener(this.onHandshakeData);
756
- this.conn.addErrorListener(this.listeners.onConnectionErrored);
757
- this.conn.addCloseListener(this.listeners.onConnectionClosed);
753
+ this.conn.setDataListener(this.onHandshakeData);
754
+ this.conn.setErrorListener(this.listeners.onConnectionErrored);
755
+ this.conn.setCloseListener(this.listeners.onConnectionClosed);
758
756
  }
759
757
  get loggingMetadata() {
760
758
  return {
@@ -778,9 +776,9 @@ var SessionHandshaking = class extends IdentifiedSessionWithGracePeriod {
778
776
  }
779
777
  _handleStateExit() {
780
778
  super._handleStateExit();
781
- this.conn.removeDataListener(this.onHandshakeData);
782
- this.conn.removeErrorListener(this.listeners.onConnectionErrored);
783
- this.conn.removeCloseListener(this.listeners.onConnectionClosed);
779
+ this.conn.removeDataListener();
780
+ this.conn.removeErrorListener();
781
+ this.conn.removeCloseListener();
784
782
  if (this.handshakeTimeout) {
785
783
  clearTimeout(this.handshakeTimeout);
786
784
  this.handshakeTimeout = void 0;
@@ -836,9 +834,9 @@ var SessionConnected = class extends IdentifiedSession {
836
834
  super(props);
837
835
  this.conn = props.conn;
838
836
  this.listeners = props.listeners;
839
- this.conn.addDataListener(this.onMessageData);
840
- this.conn.addCloseListener(this.listeners.onConnectionClosed);
841
- this.conn.addErrorListener(this.listeners.onConnectionErrored);
837
+ this.conn.setDataListener(this.onMessageData);
838
+ this.conn.setCloseListener(this.listeners.onConnectionClosed);
839
+ this.conn.setErrorListener(this.listeners.onConnectionErrored);
842
840
  }
843
841
  sendBufferedMessages() {
844
842
  if (this.sendBuffer.length > 0) {
@@ -947,9 +945,9 @@ var SessionConnected = class extends IdentifiedSession {
947
945
  };
948
946
  _handleStateExit() {
949
947
  super._handleStateExit();
950
- this.conn.removeDataListener(this.onMessageData);
951
- this.conn.removeCloseListener(this.listeners.onConnectionClosed);
952
- this.conn.removeErrorListener(this.listeners.onConnectionErrored);
948
+ this.conn.removeDataListener();
949
+ this.conn.removeCloseListener();
950
+ this.conn.removeErrorListener();
953
951
  if (this.heartbeatHandle) {
954
952
  clearInterval(this.heartbeatHandle);
955
953
  this.heartbeatHandle = void 0;
@@ -1394,8 +1392,7 @@ var Transport = class {
1394
1392
  * @param message The received message.
1395
1393
  */
1396
1394
  handleMsg(message) {
1397
- if (this.getStatus() !== "open")
1398
- return;
1395
+ if (this.getStatus() !== "open") return;
1399
1396
  this.eventDispatcher.dispatchEvent("message", message);
1400
1397
  }
1401
1398
  /**
@@ -1483,8 +1480,7 @@ var Transport = class {
1483
1480
  });
1484
1481
  }
1485
1482
  deleteSession(session, options) {
1486
- if (session._isConsumed)
1487
- return;
1483
+ if (session._isConsumed) return;
1488
1484
  const loggingMetadata = session.loggingMetadata;
1489
1485
  if (loggingMetadata.tags && options?.unhealthy) {
1490
1486
  loggingMetadata.tags.push("unhealthy-session");
@@ -1504,7 +1500,7 @@ var Transport = class {
1504
1500
  }
1505
1501
  // common listeners
1506
1502
  onSessionGracePeriodElapsed(session) {
1507
- this.log?.warn(
1503
+ this.log?.info(
1508
1504
  `session to ${session.to} grace period elapsed, closing`,
1509
1505
  session.loggingMetadata
1510
1506
  );
@@ -1861,15 +1857,6 @@ var ClientTransport = class extends Transport {
1861
1857
  });
1862
1858
  const res = connectedSession.sendBufferedMessages();
1863
1859
  if (!res.ok) {
1864
- this.log?.error(`failed to send buffered messages: ${res.reason}`, {
1865
- ...connectedSession.loggingMetadata,
1866
- transportMessage: msg
1867
- });
1868
- this.protocolError({
1869
- type: ProtocolError.MessageSendFailure,
1870
- message: res.reason
1871
- });
1872
- this.deleteSession(connectedSession, { unhealthy: true });
1873
1860
  return;
1874
1861
  }
1875
1862
  this.updateSession(connectedSession);
@@ -2071,8 +2058,7 @@ var ServerTransport = class extends Transport {
2071
2058
  super.deleteSession(session, options);
2072
2059
  }
2073
2060
  handleConnection(conn) {
2074
- if (this.getStatus() !== "open")
2075
- return;
2061
+ if (this.getStatus() !== "open") return;
2076
2062
  this.log?.info(`new incoming connection`, {
2077
2063
  ...conn.loggingMetadata,
2078
2064
  clientId: this.clientId
@@ -2416,18 +2402,6 @@ var ServerTransport = class extends Transport {
2416
2402
  );
2417
2403
  const bufferSendRes = connectedSession.sendBufferedMessages();
2418
2404
  if (!bufferSendRes.ok) {
2419
- this.log?.error(
2420
- `failed to send buffered messages: ${bufferSendRes.reason}`,
2421
- {
2422
- ...connectedSession.loggingMetadata,
2423
- transportMessage: msg
2424
- }
2425
- );
2426
- this.protocolError({
2427
- type: ProtocolError.MessageSendFailure,
2428
- message: bufferSendRes.reason
2429
- });
2430
- this.deleteSession(connectedSession, { unhealthy: true });
2431
2405
  return;
2432
2406
  }
2433
2407
  this.sessionHandshakeMetadata.set(connectedSession.to, parsedMetadata);
@@ -2458,60 +2432,44 @@ var Connection = class {
2458
2432
  }
2459
2433
  return metadata;
2460
2434
  }
2461
- // can't use event emitter because we need this to work in both node + browser
2462
- _dataListeners = /* @__PURE__ */ new Set();
2463
- _closeListeners = /* @__PURE__ */ new Set();
2464
- _errorListeners = /* @__PURE__ */ new Set();
2465
- get dataListeners() {
2466
- return [...this._dataListeners];
2467
- }
2468
- get closeListeners() {
2469
- return [...this._closeListeners];
2470
- }
2471
- get errorListeners() {
2472
- return [...this._errorListeners];
2473
- }
2435
+ dataListener;
2436
+ closeListener;
2437
+ errorListener;
2474
2438
  onData(msg) {
2475
- for (const cb of this.dataListeners) {
2476
- cb(msg);
2477
- }
2439
+ this.dataListener?.(msg);
2478
2440
  }
2479
2441
  onError(err) {
2480
- for (const cb of this.errorListeners) {
2481
- cb(err);
2482
- }
2442
+ this.errorListener?.(err);
2483
2443
  }
2484
2444
  onClose() {
2485
- for (const cb of this.closeListeners) {
2486
- cb();
2487
- }
2445
+ this.closeListener?.();
2488
2446
  this.telemetry?.span.end();
2489
2447
  }
2490
2448
  /**
2491
- * Handle adding a callback for when a message is received.
2492
- * @param msg The message that was received.
2449
+ * Set the callback for when a message is received.
2450
+ * @param cb The message handler callback.
2493
2451
  */
2494
- addDataListener(cb) {
2495
- this._dataListeners.add(cb);
2452
+ setDataListener(cb) {
2453
+ this.dataListener = cb;
2496
2454
  }
2497
- removeDataListener(cb) {
2498
- this._dataListeners.delete(cb);
2455
+ removeDataListener() {
2456
+ this.dataListener = void 0;
2499
2457
  }
2500
2458
  /**
2501
- * Handle adding a callback for when the connection is closed.
2502
- * This should also be called if an error happens and after notifying all the error listeners.
2459
+ * Set the callback for when the connection is closed.
2460
+ * This should also be called if an error happens and after notifying the error listener.
2503
2461
  * @param cb The callback to call when the connection is closed.
2504
2462
  */
2505
- addCloseListener(cb) {
2506
- this._closeListeners.add(cb);
2463
+ setCloseListener(cb) {
2464
+ this.closeListener = cb;
2507
2465
  }
2508
- removeCloseListener(cb) {
2509
- this._closeListeners.delete(cb);
2466
+ removeCloseListener() {
2467
+ this.closeListener = void 0;
2510
2468
  }
2511
2469
  /**
2512
- * Handle adding a callback for when an error is received.
2513
- * This should only be used for this.logging errors, all cleanup
2514
- * should be delegated to addCloseListener.
2470
+ * Set the callback for when an error is received.
2471
+ * This should only be used for logging errors, all cleanup
2472
+ * should be delegated to setCloseListener.
2515
2473
  *
2516
2474
  * The implementer should take care such that the implemented
2517
2475
  * connection will call both the close and error callbacks
@@ -2519,11 +2477,11 @@ var Connection = class {
2519
2477
  *
2520
2478
  * @param cb The callback to call when an error is received.
2521
2479
  */
2522
- addErrorListener(cb) {
2523
- this._errorListeners.add(cb);
2480
+ setErrorListener(cb) {
2481
+ this.errorListener = cb;
2524
2482
  }
2525
- removeErrorListener(cb) {
2526
- this._errorListeners.delete(cb);
2483
+ removeErrorListener() {
2484
+ this.errorListener = void 0;
2527
2485
  }
2528
2486
  };
2529
2487
  // Annotate the CommonJS export names for ESM import in node: