@actuallab/rpc 12.3.79 → 12.3.83

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
@@ -523,6 +523,12 @@ declare const RpcCallStage: {
523
523
  };
524
524
  type RpcCallStage = number;
525
525
 
526
+ /** Error thrown for a failed remote RPC call — carries the remote exception's type name when available. */
527
+ declare class RpcError extends Error {
528
+ readonly typeName?: string;
529
+ constructor(message: string, typeName?: string);
530
+ }
531
+
526
532
  /**
527
533
  * Compresses and decompresses monotonically increasing sequences of
528
534
  * integers using variable-length LEB128 encoding of successive deltas.
@@ -1056,6 +1062,7 @@ declare class RpcStream<T> implements AsyncIterable<T>, IRpcObject {
1056
1062
  private _started;
1057
1063
  private _iterating;
1058
1064
  private _ackSentUpTo;
1065
+ private _nextConsumedIndex;
1059
1066
  /** Create a local (origin-side) stream wrapping an async iterable or source factory with optional configuration. */
1060
1067
  constructor(source: RpcStreamSource<T>, options?: RpcStreamOptions<T>);
1061
1068
  /** Create a remote (target-side) stream from a parsed stream reference and peer. */
@@ -1288,4 +1295,4 @@ declare function xxh3_64str(input: string, seed?: bigint): bigint;
1288
1295
  */
1289
1296
  declare function computeMethodHash(methodName: string): number;
1290
1297
 
1291
- export { ARG_DELIMITER, ENVELOPE_DELIMITER, FRAME_DELIMITER, HANDSHAKE_TIMEOUT_MS, type IRpcObject, IncreasingSeqCompressor, type MethodMeta, RPC_CLOSE_CODE_UNSUPPORTED_FORMAT, type RemoteHandshake, type RpcCallOptions, RpcCallStage, RpcCallTypeId, RpcClientPeer, RpcClientPeerReconnectDelayer, type RpcConnection, RpcConnectionState, type RpcConnectionUrlResolver, type RpcDeserializedMessage, type RpcDispatchContext, RpcHub, RpcInboundCall, RpcInboundCallTracker, RpcJsonSerializationFormat, type RpcLogScope, type RpcMessage, RpcMessageChannelConnection, RpcMessagePackCompactSerializationFormat, RpcMessagePackSerializationFormat, type RpcMethodDef, type RpcMethodDefInput, RpcMethodRegistry, type RpcObjectId, RpcObjectKind, RpcOutboundCall, RpcOutboundCallTracker, RpcPeer, type RpcPeerFactory, RpcPeerRefBuilder, type RpcPeerState, RpcPeerStateKind, RpcPeerStateMonitor, type RpcReceivedMessage, RpcRemoteExecutionMode, RpcRemoteObjectTracker, RpcSerializationFormat, RpcSerializationFormatResolver, RpcServerPeer, type RpcServiceDef, RpcServiceHost, type RpcServiceImpl, RpcSharedObjectTracker, RpcStream, type RpcStreamOptions, type RpcStreamRef, RpcStreamSender, type RpcStreamSource, RpcSystemCallHandler, RpcSystemCallSender, RpcSystemCalls, RpcType, RpcWebSocketConnection, type RpcWireData, type ServiceMeta, type WebSocketLike, type WebSocketServer, WebSocketState, computeMethodHash, createBinaryEncoder, createMessageChannelPair, createRpcClient, defaultBinaryDecoder, defaultBinaryEncoder, defaultConnectionUrlResolver, defineRpcService, deserializeBinaryMessage, deserializeCompactBinaryMessage, deserializeMessage, getLogs, getMethodsMeta, getServiceMeta, getStateDescription, isConnected, likelyConnected, parseStreamRef, resolveStreamRefs, rpcMethod, rpcService, serializeBinaryFrame, serializeBinaryMessage, serializeCompactBinaryMessage, serializeFrame, serializeMessage, splitBinaryFrame, splitCompactBinaryFrame, splitFrame, wireMethodName, xxh3_64, xxh3_64str };
1298
+ export { ARG_DELIMITER, ENVELOPE_DELIMITER, FRAME_DELIMITER, HANDSHAKE_TIMEOUT_MS, type IRpcObject, IncreasingSeqCompressor, type MethodMeta, RPC_CLOSE_CODE_UNSUPPORTED_FORMAT, type RemoteHandshake, type RpcCallOptions, RpcCallStage, RpcCallTypeId, RpcClientPeer, RpcClientPeerReconnectDelayer, type RpcConnection, RpcConnectionState, type RpcConnectionUrlResolver, type RpcDeserializedMessage, type RpcDispatchContext, RpcError, RpcHub, RpcInboundCall, RpcInboundCallTracker, RpcJsonSerializationFormat, type RpcLogScope, type RpcMessage, RpcMessageChannelConnection, RpcMessagePackCompactSerializationFormat, RpcMessagePackSerializationFormat, type RpcMethodDef, type RpcMethodDefInput, RpcMethodRegistry, type RpcObjectId, RpcObjectKind, RpcOutboundCall, RpcOutboundCallTracker, RpcPeer, type RpcPeerFactory, RpcPeerRefBuilder, type RpcPeerState, RpcPeerStateKind, RpcPeerStateMonitor, type RpcReceivedMessage, RpcRemoteExecutionMode, RpcRemoteObjectTracker, RpcSerializationFormat, RpcSerializationFormatResolver, RpcServerPeer, type RpcServiceDef, RpcServiceHost, type RpcServiceImpl, RpcSharedObjectTracker, RpcStream, type RpcStreamOptions, type RpcStreamRef, RpcStreamSender, type RpcStreamSource, RpcSystemCallHandler, RpcSystemCallSender, RpcSystemCalls, RpcType, RpcWebSocketConnection, type RpcWireData, type ServiceMeta, type WebSocketLike, type WebSocketServer, WebSocketState, computeMethodHash, createBinaryEncoder, createMessageChannelPair, createRpcClient, defaultBinaryDecoder, defaultBinaryEncoder, defaultConnectionUrlResolver, defineRpcService, deserializeBinaryMessage, deserializeCompactBinaryMessage, deserializeMessage, getLogs, getMethodsMeta, getServiceMeta, getStateDescription, isConnected, likelyConnected, parseStreamRef, resolveStreamRefs, rpcMethod, rpcService, serializeBinaryFrame, serializeBinaryMessage, serializeCompactBinaryMessage, serializeFrame, serializeMessage, splitBinaryFrame, splitCompactBinaryFrame, splitFrame, wireMethodName, xxh3_64, xxh3_64str };
package/dist/index.d.ts CHANGED
@@ -523,6 +523,12 @@ declare const RpcCallStage: {
523
523
  };
524
524
  type RpcCallStage = number;
525
525
 
526
+ /** Error thrown for a failed remote RPC call — carries the remote exception's type name when available. */
527
+ declare class RpcError extends Error {
528
+ readonly typeName?: string;
529
+ constructor(message: string, typeName?: string);
530
+ }
531
+
526
532
  /**
527
533
  * Compresses and decompresses monotonically increasing sequences of
528
534
  * integers using variable-length LEB128 encoding of successive deltas.
@@ -1056,6 +1062,7 @@ declare class RpcStream<T> implements AsyncIterable<T>, IRpcObject {
1056
1062
  private _started;
1057
1063
  private _iterating;
1058
1064
  private _ackSentUpTo;
1065
+ private _nextConsumedIndex;
1059
1066
  /** Create a local (origin-side) stream wrapping an async iterable or source factory with optional configuration. */
1060
1067
  constructor(source: RpcStreamSource<T>, options?: RpcStreamOptions<T>);
1061
1068
  /** Create a remote (target-side) stream from a parsed stream reference and peer. */
@@ -1288,4 +1295,4 @@ declare function xxh3_64str(input: string, seed?: bigint): bigint;
1288
1295
  */
1289
1296
  declare function computeMethodHash(methodName: string): number;
1290
1297
 
1291
- export { ARG_DELIMITER, ENVELOPE_DELIMITER, FRAME_DELIMITER, HANDSHAKE_TIMEOUT_MS, type IRpcObject, IncreasingSeqCompressor, type MethodMeta, RPC_CLOSE_CODE_UNSUPPORTED_FORMAT, type RemoteHandshake, type RpcCallOptions, RpcCallStage, RpcCallTypeId, RpcClientPeer, RpcClientPeerReconnectDelayer, type RpcConnection, RpcConnectionState, type RpcConnectionUrlResolver, type RpcDeserializedMessage, type RpcDispatchContext, RpcHub, RpcInboundCall, RpcInboundCallTracker, RpcJsonSerializationFormat, type RpcLogScope, type RpcMessage, RpcMessageChannelConnection, RpcMessagePackCompactSerializationFormat, RpcMessagePackSerializationFormat, type RpcMethodDef, type RpcMethodDefInput, RpcMethodRegistry, type RpcObjectId, RpcObjectKind, RpcOutboundCall, RpcOutboundCallTracker, RpcPeer, type RpcPeerFactory, RpcPeerRefBuilder, type RpcPeerState, RpcPeerStateKind, RpcPeerStateMonitor, type RpcReceivedMessage, RpcRemoteExecutionMode, RpcRemoteObjectTracker, RpcSerializationFormat, RpcSerializationFormatResolver, RpcServerPeer, type RpcServiceDef, RpcServiceHost, type RpcServiceImpl, RpcSharedObjectTracker, RpcStream, type RpcStreamOptions, type RpcStreamRef, RpcStreamSender, type RpcStreamSource, RpcSystemCallHandler, RpcSystemCallSender, RpcSystemCalls, RpcType, RpcWebSocketConnection, type RpcWireData, type ServiceMeta, type WebSocketLike, type WebSocketServer, WebSocketState, computeMethodHash, createBinaryEncoder, createMessageChannelPair, createRpcClient, defaultBinaryDecoder, defaultBinaryEncoder, defaultConnectionUrlResolver, defineRpcService, deserializeBinaryMessage, deserializeCompactBinaryMessage, deserializeMessage, getLogs, getMethodsMeta, getServiceMeta, getStateDescription, isConnected, likelyConnected, parseStreamRef, resolveStreamRefs, rpcMethod, rpcService, serializeBinaryFrame, serializeBinaryMessage, serializeCompactBinaryMessage, serializeFrame, serializeMessage, splitBinaryFrame, splitCompactBinaryFrame, splitFrame, wireMethodName, xxh3_64, xxh3_64str };
1298
+ export { ARG_DELIMITER, ENVELOPE_DELIMITER, FRAME_DELIMITER, HANDSHAKE_TIMEOUT_MS, type IRpcObject, IncreasingSeqCompressor, type MethodMeta, RPC_CLOSE_CODE_UNSUPPORTED_FORMAT, type RemoteHandshake, type RpcCallOptions, RpcCallStage, RpcCallTypeId, RpcClientPeer, RpcClientPeerReconnectDelayer, type RpcConnection, RpcConnectionState, type RpcConnectionUrlResolver, type RpcDeserializedMessage, type RpcDispatchContext, RpcError, RpcHub, RpcInboundCall, RpcInboundCallTracker, RpcJsonSerializationFormat, type RpcLogScope, type RpcMessage, RpcMessageChannelConnection, RpcMessagePackCompactSerializationFormat, RpcMessagePackSerializationFormat, type RpcMethodDef, type RpcMethodDefInput, RpcMethodRegistry, type RpcObjectId, RpcObjectKind, RpcOutboundCall, RpcOutboundCallTracker, RpcPeer, type RpcPeerFactory, RpcPeerRefBuilder, type RpcPeerState, RpcPeerStateKind, RpcPeerStateMonitor, type RpcReceivedMessage, RpcRemoteExecutionMode, RpcRemoteObjectTracker, RpcSerializationFormat, RpcSerializationFormatResolver, RpcServerPeer, type RpcServiceDef, RpcServiceHost, type RpcServiceImpl, RpcSharedObjectTracker, RpcStream, type RpcStreamOptions, type RpcStreamRef, RpcStreamSender, type RpcStreamSource, RpcSystemCallHandler, RpcSystemCallSender, RpcSystemCalls, RpcType, RpcWebSocketConnection, type RpcWireData, type ServiceMeta, type WebSocketLike, type WebSocketServer, WebSocketState, computeMethodHash, createBinaryEncoder, createMessageChannelPair, createRpcClient, defaultBinaryDecoder, defaultBinaryEncoder, defaultConnectionUrlResolver, defineRpcService, deserializeBinaryMessage, deserializeCompactBinaryMessage, deserializeMessage, getLogs, getMethodsMeta, getServiceMeta, getStateDescription, isConnected, likelyConnected, parseStreamRef, resolveStreamRefs, rpcMethod, rpcService, serializeBinaryFrame, serializeBinaryMessage, serializeCompactBinaryMessage, serializeFrame, serializeMessage, splitBinaryFrame, splitCompactBinaryFrame, splitFrame, wireMethodName, xxh3_64, xxh3_64str };
package/dist/index.js CHANGED
@@ -757,6 +757,17 @@ var RpcInboundCallTracker = class {
757
757
  }
758
758
  };
759
759
 
760
+ // src/rpc-error.ts
761
+ var RpcError = class extends Error {
762
+ typeName;
763
+ constructor(message, typeName) {
764
+ super(message);
765
+ this.name = "RpcError";
766
+ if (typeName !== void 0)
767
+ this.typeName = typeName;
768
+ }
769
+ };
770
+
760
771
  // src/increasing-seq-compressor.ts
761
772
  var IncreasingSeqCompressor = {
762
773
  /**
@@ -1366,6 +1377,7 @@ var RpcStream = class _RpcStream {
1366
1377
  _started = false;
1367
1378
  _iterating = false;
1368
1379
  _ackSentUpTo = 0;
1380
+ _nextConsumedIndex = 0;
1369
1381
  constructor(sourceOrRef, optionsOrPeer) {
1370
1382
  if (_isStreamSource(sourceOrRef)) {
1371
1383
  const options = optionsOrPeer ?? {};
@@ -1457,12 +1469,11 @@ var RpcStream = class _RpcStream {
1457
1469
  return;
1458
1470
  }
1459
1471
  if (index < this._nextExpectedIndex) {
1460
- this._maybeSendAck(index + 1);
1472
+ this._maybeSendAck(Math.min(index + 1, this._nextConsumedIndex));
1461
1473
  return;
1462
1474
  }
1463
1475
  this._buffer.push(item);
1464
1476
  this._nextExpectedIndex = index + 1;
1465
- this._maybeSendAck(this._nextExpectedIndex);
1466
1477
  this._notifyConsumer();
1467
1478
  }
1468
1479
  /** Called by system call handler when a batch arrives ($sys.B). */
@@ -1482,12 +1493,11 @@ var RpcStream = class _RpcStream {
1482
1493
  return;
1483
1494
  }
1484
1495
  if (index < this._nextExpectedIndex) {
1485
- this._maybeSendAck(index + items.length);
1496
+ this._maybeSendAck(Math.min(index + items.length, this._nextConsumedIndex));
1486
1497
  return;
1487
1498
  }
1488
1499
  for (const item of items) this._buffer.push(item);
1489
1500
  this._nextExpectedIndex = index + items.length;
1490
- this._maybeSendAck(this._nextExpectedIndex);
1491
1501
  this._notifyConsumer();
1492
1502
  }
1493
1503
  /** Called by system call handler when the stream ends ($sys.End). */
@@ -1531,9 +1541,11 @@ var RpcStream = class _RpcStream {
1531
1541
  this._started = true;
1532
1542
  this._sendAck(0, true);
1533
1543
  }
1544
+ this._maybeSendAck(this._nextConsumedIndex);
1534
1545
  for (; ; ) {
1535
1546
  if (!this._buffer.isEmpty()) {
1536
1547
  const value = this._buffer.shift();
1548
+ this._nextConsumedIndex++;
1537
1549
  return { value, done: false };
1538
1550
  }
1539
1551
  if (this._completed) {
@@ -1683,12 +1695,17 @@ var RpcSystemCallHandler = class {
1683
1695
  const errorInfo = args[0];
1684
1696
  const msg = errorInfo?.Message ?? errorInfo?.message ?? "RPC error";
1685
1697
  const errorType = errorInfo?.TypeRef ?? errorInfo?.typeRef;
1686
- if (errorType !== null && typeof errorType === "object") {
1698
+ let typeName;
1699
+ if (typeof errorType === "string") {
1700
+ const commaIdx = errorType.indexOf(",");
1701
+ typeName = commaIdx >= 0 ? errorType.slice(0, commaIdx) : errorType;
1702
+ } else if (errorType !== null && typeof errorType === "object") {
1687
1703
  const t = errorType;
1688
- if (t.TypeName === "RpcRerouteException" || t.typeName === "RpcRerouteException")
1689
- warnLog5?.log("Got RpcRerouteException from remote peer:", msg);
1704
+ typeName = t.TypeName ?? t.typeName;
1690
1705
  }
1691
- call.result.reject(new Error(msg));
1706
+ if (typeName === "ActualLab.Rpc.RpcRerouteException")
1707
+ warnLog5?.log("Got RpcRerouteException from remote peer:", msg);
1708
+ call.result.reject(new RpcError(msg, typeName));
1692
1709
  }
1693
1710
  break;
1694
1711
  }
@@ -3992,6 +4009,7 @@ export {
3992
4009
  RpcClientPeer,
3993
4010
  RpcClientPeerReconnectDelayer,
3994
4011
  RpcConnectionState,
4012
+ RpcError,
3995
4013
  RpcHub,
3996
4014
  RpcInboundCall,
3997
4015
  RpcInboundCallTracker,