@actuallab/rpc 12.3.81 → 12.3.85

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.
package/dist/index.d.cts CHANGED
@@ -748,7 +748,7 @@ declare const RPC_CLOSE_CODE_UNSUPPORTED_FORMAT = 4001;
748
748
  /** Maximum time to wait for the server's handshake response after opening the socket. */
749
749
  declare const HANDSHAKE_TIMEOUT_MS = 10000;
750
750
  /** Builds the WebSocket connection URL for an RpcClientPeer. */
751
- type RpcConnectionUrlResolver = (peer: RpcClientPeer) => string;
751
+ type RpcConnectionUrlResolver = (peer: RpcClientPeer) => string | Promise<string>;
752
752
  /** Default connection URL provider — sets `clientId` and `f` query parameters,
753
753
  * replacing any existing values to keep the wire format consistent with the
754
754
  * peer's actual `serializationFormat`. */
@@ -1062,6 +1062,7 @@ declare class RpcStream<T> implements AsyncIterable<T>, IRpcObject {
1062
1062
  private _started;
1063
1063
  private _iterating;
1064
1064
  private _ackSentUpTo;
1065
+ private _nextConsumedIndex;
1065
1066
  /** Create a local (origin-side) stream wrapping an async iterable or source factory with optional configuration. */
1066
1067
  constructor(source: RpcStreamSource<T>, options?: RpcStreamOptions<T>);
1067
1068
  /** Create a remote (target-side) stream from a parsed stream reference and peer. */
package/dist/index.d.ts CHANGED
@@ -748,7 +748,7 @@ declare const RPC_CLOSE_CODE_UNSUPPORTED_FORMAT = 4001;
748
748
  /** Maximum time to wait for the server's handshake response after opening the socket. */
749
749
  declare const HANDSHAKE_TIMEOUT_MS = 10000;
750
750
  /** Builds the WebSocket connection URL for an RpcClientPeer. */
751
- type RpcConnectionUrlResolver = (peer: RpcClientPeer) => string;
751
+ type RpcConnectionUrlResolver = (peer: RpcClientPeer) => string | Promise<string>;
752
752
  /** Default connection URL provider — sets `clientId` and `f` query parameters,
753
753
  * replacing any existing values to keep the wire format consistent with the
754
754
  * peer's actual `serializationFormat`. */
@@ -1062,6 +1062,7 @@ declare class RpcStream<T> implements AsyncIterable<T>, IRpcObject {
1062
1062
  private _started;
1063
1063
  private _iterating;
1064
1064
  private _ackSentUpTo;
1065
+ private _nextConsumedIndex;
1065
1066
  /** Create a local (origin-side) stream wrapping an async iterable or source factory with optional configuration. */
1066
1067
  constructor(source: RpcStreamSource<T>, options?: RpcStreamOptions<T>);
1067
1068
  /** Create a remote (target-side) stream from a parsed stream reference and peer. */
package/dist/index.js CHANGED
@@ -1377,6 +1377,7 @@ var RpcStream = class _RpcStream {
1377
1377
  _started = false;
1378
1378
  _iterating = false;
1379
1379
  _ackSentUpTo = 0;
1380
+ _nextConsumedIndex = 0;
1380
1381
  constructor(sourceOrRef, optionsOrPeer) {
1381
1382
  if (_isStreamSource(sourceOrRef)) {
1382
1383
  const options = optionsOrPeer ?? {};
@@ -1468,12 +1469,11 @@ var RpcStream = class _RpcStream {
1468
1469
  return;
1469
1470
  }
1470
1471
  if (index < this._nextExpectedIndex) {
1471
- this._maybeSendAck(index + 1);
1472
+ this._maybeSendAck(Math.min(index + 1, this._nextConsumedIndex));
1472
1473
  return;
1473
1474
  }
1474
1475
  this._buffer.push(item);
1475
1476
  this._nextExpectedIndex = index + 1;
1476
- this._maybeSendAck(this._nextExpectedIndex);
1477
1477
  this._notifyConsumer();
1478
1478
  }
1479
1479
  /** Called by system call handler when a batch arrives ($sys.B). */
@@ -1493,12 +1493,11 @@ var RpcStream = class _RpcStream {
1493
1493
  return;
1494
1494
  }
1495
1495
  if (index < this._nextExpectedIndex) {
1496
- this._maybeSendAck(index + items.length);
1496
+ this._maybeSendAck(Math.min(index + items.length, this._nextConsumedIndex));
1497
1497
  return;
1498
1498
  }
1499
1499
  for (const item of items) this._buffer.push(item);
1500
1500
  this._nextExpectedIndex = index + items.length;
1501
- this._maybeSendAck(this._nextExpectedIndex);
1502
1501
  this._notifyConsumer();
1503
1502
  }
1504
1503
  /** Called by system call handler when the stream ends ($sys.End). */
@@ -1542,9 +1541,11 @@ var RpcStream = class _RpcStream {
1542
1541
  this._started = true;
1543
1542
  this._sendAck(0, true);
1544
1543
  }
1544
+ this._maybeSendAck(this._nextConsumedIndex);
1545
1545
  for (; ; ) {
1546
1546
  if (!this._buffer.isEmpty()) {
1547
1547
  const value = this._buffer.shift();
1548
+ this._nextConsumedIndex++;
1548
1549
  return { value, done: false };
1549
1550
  }
1550
1551
  if (this._completed) {
@@ -2187,6 +2188,17 @@ var defaultConnectionUrlResolver = (peer) => {
2187
2188
  return peer.ref + sep + `clientId=${peer.clientId}&f=${formatKey}`;
2188
2189
  }
2189
2190
  };
2191
+ var sanitizeUrl = (url) => {
2192
+ try {
2193
+ const parsed = new URL(url);
2194
+ if (!parsed.searchParams.has("session"))
2195
+ return url;
2196
+ parsed.searchParams.set("session", "<redacted>");
2197
+ return parsed.toString();
2198
+ } catch {
2199
+ return url.replace(/([?&]session=)[^&]*/i, "$1<redacted>");
2200
+ }
2201
+ };
2190
2202
  function parseFormatFromUrl(url) {
2191
2203
  try {
2192
2204
  const f = new URL(url).searchParams.get("f");
@@ -2634,7 +2646,6 @@ var RpcClientPeer = class extends RpcPeer {
2634
2646
  }
2635
2647
  async _runImpl() {
2636
2648
  if (this._disposed) return;
2637
- const connUrl = this.connectionUrlResolver(this);
2638
2649
  infoLog?.log(`'${this.ref}': Started (Client)`);
2639
2650
  try {
2640
2651
  while (!this._disposed) {
@@ -2655,7 +2666,8 @@ var RpcClientPeer = class extends RpcPeer {
2655
2666
  let lastCloseCode = 0;
2656
2667
  let lastCloseReason = "";
2657
2668
  try {
2658
- infoLog?.log(`'${this.ref}': Connecting to ${connUrl}`);
2669
+ const connUrl = await this.connectionUrlResolver(this);
2670
+ infoLog?.log(`'${this.ref}': Connecting to ${sanitizeUrl(connUrl)}`);
2659
2671
  const ws = this.webSocketFactory?.(connUrl) ?? new WebSocket(connUrl);
2660
2672
  const conn = new RpcWebSocketConnection(
2661
2673
  ws,