@actuallab/rpc 12.3.29 → 12.3.33
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.cjs +152 -78
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +6 -2
- package/dist/index.d.ts +6 -2
- package/dist/index.js +122 -49
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as _actuallab_core from '@actuallab/core';
|
|
2
2
|
import { EventHandlerSet, PromiseSource, RetryDelayer } from '@actuallab/core';
|
|
3
|
+
import { Encoder, Decoder } from '@msgpack/msgpack';
|
|
4
|
+
|
|
5
|
+
type RpcLogScope = 'RpcCallTracker' | 'RpcClient' | 'RpcClientPeerReconnectDelayer' | 'RpcConnection' | 'RpcHub' | 'RpcInterceptor' | 'RpcMessageChannelConnection' | 'RpcMethodRegistry' | 'RpcOutboundCall' | 'RpcPeer' | 'RpcPeerStateMonitor' | 'RpcRemoteObjectTracker' | 'RpcSerialization' | 'RpcServiceHost' | 'RpcSharedObjectTracker' | 'RpcSharedStream' | 'RpcStream' | 'RpcStreamSender' | 'RpcSystemCallHandler' | 'RpcSystemCallSender' | 'RpcWebSocketClient';
|
|
6
|
+
declare const getLogs: (scope: RpcLogScope) => _actuallab_core.LogScopeFns;
|
|
3
7
|
|
|
4
8
|
/** Identifies the type of an RPC call on the wire. */
|
|
5
9
|
declare const enum RpcCallTypeId {
|
|
@@ -1182,4 +1186,4 @@ declare function xxh3_64str(input: string, seed?: bigint): bigint;
|
|
|
1182
1186
|
*/
|
|
1183
1187
|
declare function computeMethodHash(methodName: string): number;
|
|
1184
1188
|
|
|
1185
|
-
export { ARG_DELIMITER, ENVELOPE_DELIMITER, FRAME_DELIMITER, type IRpcObject, IncreasingSeqCompressor, type MethodMeta, RPC_CLOSE_CODE_UNSUPPORTED_FORMAT, type RemoteHandshake, type RpcCallOptions, RpcCallStage, RpcCallTypeId, RpcClientPeer, RpcClientPeerReconnectDelayer, type RpcConnection, type RpcConnectionUrlResolver, type RpcDeserializedMessage, type RpcDispatchContext, RpcHub, RpcInboundCall, RpcInboundCallTracker, RpcJsonSerializationFormat, type RpcMessage, RpcMessageChannelConnection, RpcMessagePackCompactSerializationFormat, RpcMessagePackSerializationFormat, type RpcMethodDef, type RpcMethodDefInput, RpcMethodRegistry, type RpcObjectId, RpcObjectKind, RpcOutboundCall, RpcOutboundCallTracker, RpcPeer, RpcPeerConnectionKind, 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, getMethodsMeta, getServiceMeta, getStateDescription, isConnected, likelyConnected, parseStreamRef, resolveStreamRefs, rpcMethod, rpcService, serializeBinaryFrame, serializeBinaryMessage, serializeCompactBinaryMessage, serializeFrame, serializeMessage, splitBinaryFrame, splitCompactBinaryFrame, splitFrame, wireMethodName, xxh3_64, xxh3_64str };
|
|
1189
|
+
export { ARG_DELIMITER, ENVELOPE_DELIMITER, FRAME_DELIMITER, type IRpcObject, IncreasingSeqCompressor, type MethodMeta, RPC_CLOSE_CODE_UNSUPPORTED_FORMAT, type RemoteHandshake, type RpcCallOptions, RpcCallStage, RpcCallTypeId, RpcClientPeer, RpcClientPeerReconnectDelayer, type RpcConnection, 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, RpcPeerConnectionKind, 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
|
@@ -1,5 +1,9 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as _actuallab_core from '@actuallab/core';
|
|
2
2
|
import { EventHandlerSet, PromiseSource, RetryDelayer } from '@actuallab/core';
|
|
3
|
+
import { Encoder, Decoder } from '@msgpack/msgpack';
|
|
4
|
+
|
|
5
|
+
type RpcLogScope = 'RpcCallTracker' | 'RpcClient' | 'RpcClientPeerReconnectDelayer' | 'RpcConnection' | 'RpcHub' | 'RpcInterceptor' | 'RpcMessageChannelConnection' | 'RpcMethodRegistry' | 'RpcOutboundCall' | 'RpcPeer' | 'RpcPeerStateMonitor' | 'RpcRemoteObjectTracker' | 'RpcSerialization' | 'RpcServiceHost' | 'RpcSharedObjectTracker' | 'RpcSharedStream' | 'RpcStream' | 'RpcStreamSender' | 'RpcSystemCallHandler' | 'RpcSystemCallSender' | 'RpcWebSocketClient';
|
|
6
|
+
declare const getLogs: (scope: RpcLogScope) => _actuallab_core.LogScopeFns;
|
|
3
7
|
|
|
4
8
|
/** Identifies the type of an RPC call on the wire. */
|
|
5
9
|
declare const enum RpcCallTypeId {
|
|
@@ -1182,4 +1186,4 @@ declare function xxh3_64str(input: string, seed?: bigint): bigint;
|
|
|
1182
1186
|
*/
|
|
1183
1187
|
declare function computeMethodHash(methodName: string): number;
|
|
1184
1188
|
|
|
1185
|
-
export { ARG_DELIMITER, ENVELOPE_DELIMITER, FRAME_DELIMITER, type IRpcObject, IncreasingSeqCompressor, type MethodMeta, RPC_CLOSE_CODE_UNSUPPORTED_FORMAT, type RemoteHandshake, type RpcCallOptions, RpcCallStage, RpcCallTypeId, RpcClientPeer, RpcClientPeerReconnectDelayer, type RpcConnection, type RpcConnectionUrlResolver, type RpcDeserializedMessage, type RpcDispatchContext, RpcHub, RpcInboundCall, RpcInboundCallTracker, RpcJsonSerializationFormat, type RpcMessage, RpcMessageChannelConnection, RpcMessagePackCompactSerializationFormat, RpcMessagePackSerializationFormat, type RpcMethodDef, type RpcMethodDefInput, RpcMethodRegistry, type RpcObjectId, RpcObjectKind, RpcOutboundCall, RpcOutboundCallTracker, RpcPeer, RpcPeerConnectionKind, 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, getMethodsMeta, getServiceMeta, getStateDescription, isConnected, likelyConnected, parseStreamRef, resolveStreamRefs, rpcMethod, rpcService, serializeBinaryFrame, serializeBinaryMessage, serializeCompactBinaryMessage, serializeFrame, serializeMessage, splitBinaryFrame, splitCompactBinaryFrame, splitFrame, wireMethodName, xxh3_64, xxh3_64str };
|
|
1189
|
+
export { ARG_DELIMITER, ENVELOPE_DELIMITER, FRAME_DELIMITER, type IRpcObject, IncreasingSeqCompressor, type MethodMeta, RPC_CLOSE_CODE_UNSUPPORTED_FORMAT, type RemoteHandshake, type RpcCallOptions, RpcCallStage, RpcCallTypeId, RpcClientPeer, RpcClientPeerReconnectDelayer, type RpcConnection, 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, RpcPeerConnectionKind, 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
|
@@ -1,3 +1,30 @@
|
|
|
1
|
+
// src/logging.ts
|
|
2
|
+
import { createLogProvider, LogLevel } from "@actuallab/core";
|
|
3
|
+
var scopeDefaults = {
|
|
4
|
+
RpcCallTracker: LogLevel.Warn,
|
|
5
|
+
RpcClient: LogLevel.Warn,
|
|
6
|
+
RpcClientPeerReconnectDelayer: LogLevel.Warn,
|
|
7
|
+
RpcConnection: LogLevel.Warn,
|
|
8
|
+
RpcHub: LogLevel.Warn,
|
|
9
|
+
RpcInterceptor: LogLevel.Warn,
|
|
10
|
+
RpcMessageChannelConnection: LogLevel.Warn,
|
|
11
|
+
RpcMethodRegistry: LogLevel.Warn,
|
|
12
|
+
RpcOutboundCall: LogLevel.Warn,
|
|
13
|
+
RpcPeer: LogLevel.Info,
|
|
14
|
+
RpcPeerStateMonitor: LogLevel.Warn,
|
|
15
|
+
RpcRemoteObjectTracker: LogLevel.Warn,
|
|
16
|
+
RpcSerialization: LogLevel.Warn,
|
|
17
|
+
RpcServiceHost: LogLevel.Warn,
|
|
18
|
+
RpcSharedObjectTracker: LogLevel.Warn,
|
|
19
|
+
RpcSharedStream: LogLevel.Warn,
|
|
20
|
+
RpcStream: LogLevel.Warn,
|
|
21
|
+
RpcStreamSender: LogLevel.Warn,
|
|
22
|
+
RpcSystemCallHandler: LogLevel.Warn,
|
|
23
|
+
RpcSystemCallSender: LogLevel.Warn,
|
|
24
|
+
RpcWebSocketClient: LogLevel.Warn
|
|
25
|
+
};
|
|
26
|
+
var getLogs = createLogProvider("rpc.", scopeDefaults);
|
|
27
|
+
|
|
1
28
|
// src/rpc-message.ts
|
|
2
29
|
var RpcCallTypeId = /* @__PURE__ */ ((RpcCallTypeId2) => {
|
|
3
30
|
RpcCallTypeId2[RpcCallTypeId2["Regular"] = 0] = "Regular";
|
|
@@ -62,6 +89,7 @@ function patchMsgpackEncoderForMaps() {
|
|
|
62
89
|
patchMsgpackEncoderForMaps();
|
|
63
90
|
|
|
64
91
|
// src/rpc-serialization.ts
|
|
92
|
+
var { warnLog } = getLogs("RpcSerialization");
|
|
65
93
|
function serializeMessage(message, args) {
|
|
66
94
|
const envelope = JSON.stringify(message);
|
|
67
95
|
if (args === void 0 || args.length === 0) {
|
|
@@ -91,9 +119,7 @@ function deserializeMessage(raw) {
|
|
|
91
119
|
try {
|
|
92
120
|
return JSON.parse(s);
|
|
93
121
|
} catch {
|
|
94
|
-
|
|
95
|
-
`[RpcSerialization] failed to parse arg as JSON: ${s.substring(0, 100)}`
|
|
96
|
-
);
|
|
122
|
+
warnLog?.log(`failed to parse arg as JSON: ${s.substring(0, 100)}`);
|
|
97
123
|
return s;
|
|
98
124
|
}
|
|
99
125
|
});
|
|
@@ -349,6 +375,7 @@ function splitCompactBinaryFrame(frame, registry, decoder = defaultBinaryDecoder
|
|
|
349
375
|
// src/rpc-connection.ts
|
|
350
376
|
import { Decoder as Decoder2 } from "@msgpack/msgpack";
|
|
351
377
|
import { PromiseSource, EventHandlerSet } from "@actuallab/core";
|
|
378
|
+
var { warnLog: warnLog2 } = getLogs("RpcConnection");
|
|
352
379
|
var WebSocketState = {
|
|
353
380
|
CONNECTING: 0,
|
|
354
381
|
OPEN: 1,
|
|
@@ -410,6 +437,7 @@ var RpcWebSocketConnection = class {
|
|
|
410
437
|
});
|
|
411
438
|
}
|
|
412
439
|
} catch (e) {
|
|
440
|
+
warnLog2?.log("Failed to split binary frame:", e);
|
|
413
441
|
this.error.trigger(e);
|
|
414
442
|
}
|
|
415
443
|
} else if (typeof Blob !== "undefined" && ev.data instanceof Blob && this.binaryMode) {
|
|
@@ -425,6 +453,7 @@ var RpcWebSocketConnection = class {
|
|
|
425
453
|
});
|
|
426
454
|
}
|
|
427
455
|
} catch (e) {
|
|
456
|
+
warnLog2?.log("Failed to split binary blob frame:", e);
|
|
428
457
|
this.error.trigger(e);
|
|
429
458
|
}
|
|
430
459
|
});
|
|
@@ -838,6 +867,7 @@ var RpcObjectKind = { Local: 0, Remote: 1 };
|
|
|
838
867
|
|
|
839
868
|
// src/rpc-stream-sender.ts
|
|
840
869
|
import { PromiseSource as PromiseSource3, RingBuffer } from "@actuallab/core";
|
|
870
|
+
var { warnLog: warnLog3 } = getLogs("RpcSharedStream");
|
|
841
871
|
var DEFAULT_ACK_PERIOD = 256;
|
|
842
872
|
var DEFAULT_ACK_ADVANCE = 128;
|
|
843
873
|
var RpcStreamSender = class _RpcStreamSender {
|
|
@@ -1006,6 +1036,7 @@ var RpcStreamSender = class _RpcStreamSender {
|
|
|
1006
1036
|
if (this._ended) return;
|
|
1007
1037
|
ack = this._tryProcessAcks();
|
|
1008
1038
|
if (!ack) {
|
|
1039
|
+
warnLog3?.log("Something is off: couldn't read an acknowledgement");
|
|
1009
1040
|
return;
|
|
1010
1041
|
}
|
|
1011
1042
|
}
|
|
@@ -1078,7 +1109,10 @@ var RpcStreamSender = class _RpcStreamSender {
|
|
|
1078
1109
|
await this._waitAckReady();
|
|
1079
1110
|
if (this._ended) return;
|
|
1080
1111
|
ack = this._tryProcessAcks();
|
|
1081
|
-
if (!ack)
|
|
1112
|
+
if (!ack) {
|
|
1113
|
+
warnLog3?.log("Something is off: couldn't read an acknowledgement");
|
|
1114
|
+
return;
|
|
1115
|
+
}
|
|
1082
1116
|
}
|
|
1083
1117
|
this._lastAckedIndex = ack.nextIndex;
|
|
1084
1118
|
if (ack.mustReset && !isFullyBuffered) {
|
|
@@ -1274,6 +1308,7 @@ function _clamp(value, min, max) {
|
|
|
1274
1308
|
}
|
|
1275
1309
|
|
|
1276
1310
|
// src/rpc-stream.ts
|
|
1311
|
+
var { warnLog: warnLog4 } = getLogs("RpcStream");
|
|
1277
1312
|
var DEFAULT_ACK_PERIOD2 = 30;
|
|
1278
1313
|
var DEFAULT_ACK_ADVANCE2 = 61;
|
|
1279
1314
|
function parseStreamRef(value) {
|
|
@@ -1419,9 +1454,7 @@ var RpcStream = class _RpcStream {
|
|
|
1419
1454
|
onItem(index, item) {
|
|
1420
1455
|
if (this._disposed || this._completed) return;
|
|
1421
1456
|
if (index > this._nextExpectedIndex) {
|
|
1422
|
-
|
|
1423
|
-
`[RpcStream] item index gap: localId=${this.id.localId}, expected=${this._nextExpectedIndex}, received=${index}`
|
|
1424
|
-
);
|
|
1457
|
+
warnLog4?.log(`item index gap: localId=${this.id.localId}, expected=${this._nextExpectedIndex}, received=${index}`);
|
|
1425
1458
|
if (!this.allowReconnect) {
|
|
1426
1459
|
this._completed = true;
|
|
1427
1460
|
this._completionError = new Error(
|
|
@@ -1446,9 +1479,7 @@ var RpcStream = class _RpcStream {
|
|
|
1446
1479
|
onBatch(index, items) {
|
|
1447
1480
|
if (this._disposed || this._completed) return;
|
|
1448
1481
|
if (index > this._nextExpectedIndex) {
|
|
1449
|
-
|
|
1450
|
-
`[RpcStream] batch index gap: localId=${this.id.localId}, expected=${this._nextExpectedIndex}, received=${index}`
|
|
1451
|
-
);
|
|
1482
|
+
warnLog4?.log(`batch index gap: localId=${this.id.localId}, expected=${this._nextExpectedIndex}, received=${index}`);
|
|
1452
1483
|
if (!this.allowReconnect) {
|
|
1453
1484
|
this._completed = true;
|
|
1454
1485
|
this._completionError = new Error(
|
|
@@ -1635,10 +1666,12 @@ function base64Decode(encoded) {
|
|
|
1635
1666
|
}
|
|
1636
1667
|
|
|
1637
1668
|
// src/rpc-system-call-handler.ts
|
|
1669
|
+
var { debugLog, warnLog: warnLog5 } = getLogs("RpcSystemCallHandler");
|
|
1638
1670
|
var RpcSystemCallHandler = class {
|
|
1639
1671
|
handle(message, args, peer) {
|
|
1640
1672
|
const method = message.Method;
|
|
1641
1673
|
const relatedId = message.RelatedId ?? 0;
|
|
1674
|
+
debugLog?.log(`'${peer.ref}': handle ${method}#${relatedId}`);
|
|
1642
1675
|
switch (method) {
|
|
1643
1676
|
case RpcSystemCalls.ok: {
|
|
1644
1677
|
const call = peer.outbound.get(relatedId);
|
|
@@ -1660,6 +1693,12 @@ var RpcSystemCallHandler = class {
|
|
|
1660
1693
|
if (call !== void 0) {
|
|
1661
1694
|
const errorInfo = args[0];
|
|
1662
1695
|
const msg = errorInfo?.Message ?? errorInfo?.message ?? "RPC error";
|
|
1696
|
+
const errorType = errorInfo?.TypeRef ?? errorInfo?.typeRef;
|
|
1697
|
+
if (errorType !== null && typeof errorType === "object") {
|
|
1698
|
+
const t = errorType;
|
|
1699
|
+
if (t.TypeName === "RpcRerouteException" || t.typeName === "RpcRerouteException")
|
|
1700
|
+
warnLog5?.log("Got RpcRerouteException from remote peer:", msg);
|
|
1701
|
+
}
|
|
1663
1702
|
call.result.reject(new Error(msg));
|
|
1664
1703
|
}
|
|
1665
1704
|
break;
|
|
@@ -1673,25 +1712,20 @@ var RpcSystemCallHandler = class {
|
|
|
1673
1712
|
}
|
|
1674
1713
|
case RpcSystemCalls.item: {
|
|
1675
1714
|
const stream = peer.remoteObjects.get(relatedId);
|
|
1676
|
-
if (!stream)
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
);
|
|
1680
|
-
} else {
|
|
1715
|
+
if (!stream)
|
|
1716
|
+
debugLog?.log(`$sys.I: no stream for relatedId=${relatedId}`);
|
|
1717
|
+
else
|
|
1681
1718
|
stream.onItem(
|
|
1682
1719
|
args[0],
|
|
1683
1720
|
resolveStreamRefs(args[1], peer)
|
|
1684
1721
|
);
|
|
1685
|
-
}
|
|
1686
1722
|
break;
|
|
1687
1723
|
}
|
|
1688
1724
|
case RpcSystemCalls.batch: {
|
|
1689
1725
|
const stream = peer.remoteObjects.get(relatedId);
|
|
1690
|
-
if (!stream)
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
);
|
|
1694
|
-
} else if (Array.isArray(args[1])) {
|
|
1726
|
+
if (!stream)
|
|
1727
|
+
debugLog?.log(`$sys.B: no stream for relatedId=${relatedId}`);
|
|
1728
|
+
else if (Array.isArray(args[1])) {
|
|
1695
1729
|
const items = args[1];
|
|
1696
1730
|
for (let i = 0; i < items.length; i++)
|
|
1697
1731
|
items[i] = resolveStreamRefs(items[i], peer);
|
|
@@ -1702,9 +1736,7 @@ var RpcSystemCallHandler = class {
|
|
|
1702
1736
|
case RpcSystemCalls.end: {
|
|
1703
1737
|
const stream = peer.remoteObjects.get(relatedId);
|
|
1704
1738
|
if (!stream) {
|
|
1705
|
-
|
|
1706
|
-
`[RpcSysHandler] $sys.End: no stream for relatedId=${relatedId}`
|
|
1707
|
-
);
|
|
1739
|
+
debugLog?.log(`$sys.End: no stream for relatedId=${relatedId}`);
|
|
1708
1740
|
} else {
|
|
1709
1741
|
const errorInfo = args[1];
|
|
1710
1742
|
const msg = errorInfo?.Message ?? errorInfo?.message;
|
|
@@ -1793,6 +1825,7 @@ function _toBytes(value) {
|
|
|
1793
1825
|
}
|
|
1794
1826
|
|
|
1795
1827
|
// src/rpc-system-call-sender.ts
|
|
1828
|
+
var { errorLog } = getLogs("RpcSystemCallSender");
|
|
1796
1829
|
var RpcSystemCallSender = class _RpcSystemCallSender {
|
|
1797
1830
|
// Reusable envelopes — one per hot-path method.
|
|
1798
1831
|
_itemEnv = {
|
|
@@ -1849,12 +1882,17 @@ var RpcSystemCallSender = class _RpcSystemCallSender {
|
|
|
1849
1882
|
]);
|
|
1850
1883
|
}
|
|
1851
1884
|
ok(conn, format, relatedId, result) {
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
|
|
1885
|
+
try {
|
|
1886
|
+
this._send(
|
|
1887
|
+
conn,
|
|
1888
|
+
format,
|
|
1889
|
+
{ Method: RpcSystemCalls.ok, RelatedId: relatedId },
|
|
1890
|
+
[result]
|
|
1891
|
+
);
|
|
1892
|
+
} catch (e) {
|
|
1893
|
+
errorLog?.log(`Failed to send Ok response for call #${relatedId}`, e);
|
|
1894
|
+
this.error(conn, format, relatedId, e);
|
|
1895
|
+
}
|
|
1858
1896
|
}
|
|
1859
1897
|
error(conn, format, relatedId, error) {
|
|
1860
1898
|
const message = error instanceof Error ? error.message : String(error);
|
|
@@ -2136,6 +2174,7 @@ var RpcSerializationFormatResolver = class _RpcSerializationFormatResolver {
|
|
|
2136
2174
|
|
|
2137
2175
|
// src/rpc-peer.ts
|
|
2138
2176
|
var RPC_CLOSE_CODE_UNSUPPORTED_FORMAT = 4001;
|
|
2177
|
+
var { debugLog: debugLog2, infoLog, warnLog: warnLog6, errorLog: errorLog2 } = getLogs("RpcPeer");
|
|
2139
2178
|
var defaultConnectionUrlResolver = (peer) => {
|
|
2140
2179
|
const sep = peer.ref.includes("?") ? "&" : "?";
|
|
2141
2180
|
return peer.ref + sep + `clientId=${peer.clientId}&f=${peer.serializationFormat}`;
|
|
@@ -2174,9 +2213,14 @@ var RpcPeer = class {
|
|
|
2174
2213
|
conn.closed.add((ev) => {
|
|
2175
2214
|
this._connection = void 0;
|
|
2176
2215
|
this._stopKeepAlive();
|
|
2216
|
+
if (ev.reason)
|
|
2217
|
+
infoLog?.log(`'${this.ref}': Disconnected: ${ev.reason} (code=${ev.code})`);
|
|
2218
|
+
else
|
|
2219
|
+
infoLog?.log(`'${this.ref}': Disconnected`);
|
|
2177
2220
|
this.disconnected.trigger(ev);
|
|
2178
2221
|
});
|
|
2179
2222
|
void conn.whenConnected.then(() => {
|
|
2223
|
+
infoLog?.log(`'${this.ref}': Connected`);
|
|
2180
2224
|
this.connected.trigger();
|
|
2181
2225
|
this._startKeepAlive();
|
|
2182
2226
|
});
|
|
@@ -2251,6 +2295,7 @@ var RpcPeer = class {
|
|
|
2251
2295
|
this._sendWireData(wireData);
|
|
2252
2296
|
}
|
|
2253
2297
|
close() {
|
|
2298
|
+
infoLog?.log(`'${this.ref}': Stopping`);
|
|
2254
2299
|
this._stopKeepAlive();
|
|
2255
2300
|
this.remoteObjects.disconnectAll();
|
|
2256
2301
|
this.sharedObjects.disconnectAll();
|
|
@@ -2264,6 +2309,7 @@ var RpcPeer = class {
|
|
|
2264
2309
|
this.outbound.invalidateAll();
|
|
2265
2310
|
this._connection?.close();
|
|
2266
2311
|
this._hub.peers.delete(this.ref);
|
|
2312
|
+
infoLog?.log(`'${this.ref}': Stopped`);
|
|
2267
2313
|
}
|
|
2268
2314
|
/** Send any messages buffered while disconnected. Call after connection + handshake are ready. */
|
|
2269
2315
|
_flushPendingSends() {
|
|
@@ -2290,15 +2336,21 @@ var RpcPeer = class {
|
|
|
2290
2336
|
_handleMessage(received) {
|
|
2291
2337
|
let message;
|
|
2292
2338
|
let args;
|
|
2293
|
-
|
|
2294
|
-
|
|
2295
|
-
|
|
2296
|
-
|
|
2297
|
-
|
|
2298
|
-
|
|
2299
|
-
|
|
2339
|
+
try {
|
|
2340
|
+
if (received.kind === "binary") {
|
|
2341
|
+
message = received.message;
|
|
2342
|
+
args = received.args;
|
|
2343
|
+
} else {
|
|
2344
|
+
const parsed = deserializeMessage(received.raw);
|
|
2345
|
+
message = parsed.message;
|
|
2346
|
+
args = parsed.args;
|
|
2347
|
+
}
|
|
2348
|
+
} catch (e) {
|
|
2349
|
+
errorLog2?.log(`'${this.ref}': Failed to process inbound message:`, received, e);
|
|
2350
|
+
return;
|
|
2300
2351
|
}
|
|
2301
2352
|
const method = message.Method ?? "";
|
|
2353
|
+
debugLog2?.log(`'${this.ref}': <- ${method}#${message.RelatedId ?? 0}`);
|
|
2302
2354
|
if (method === RpcSystemCalls.handshake) {
|
|
2303
2355
|
const raw = args[0];
|
|
2304
2356
|
if (raw !== void 0) {
|
|
@@ -2365,6 +2417,7 @@ var RpcPeer = class {
|
|
|
2365
2417
|
e
|
|
2366
2418
|
);
|
|
2367
2419
|
}
|
|
2420
|
+
debugLog2?.log(`'${this.ref}': Inbound call failed: ${method}#${relatedId}`, e);
|
|
2368
2421
|
} finally {
|
|
2369
2422
|
if (!isNoWait) {
|
|
2370
2423
|
this.inbound.remove(relatedId);
|
|
@@ -2453,10 +2506,12 @@ var RpcClientPeer = class extends RpcPeer {
|
|
|
2453
2506
|
/** Start the reconnection loop — runs until disposed. */
|
|
2454
2507
|
async run(wsFactory) {
|
|
2455
2508
|
const connUrl = this.connectionUrlResolver(this);
|
|
2509
|
+
infoLog?.log(`'${this.ref}': Started (Client)`);
|
|
2456
2510
|
while (!this._disposed) {
|
|
2457
2511
|
let lastCloseCode = 0;
|
|
2458
2512
|
let lastCloseReason = "";
|
|
2459
2513
|
try {
|
|
2514
|
+
infoLog?.log(`'${this.ref}': Connecting to ${connUrl}`);
|
|
2460
2515
|
const ws = wsFactory?.(connUrl) ?? new WebSocket(connUrl);
|
|
2461
2516
|
const conn = new RpcWebSocketConnection(
|
|
2462
2517
|
ws,
|
|
@@ -2480,13 +2535,18 @@ var RpcClientPeer = class extends RpcPeer {
|
|
|
2480
2535
|
closedRejection.catch(() => {
|
|
2481
2536
|
});
|
|
2482
2537
|
await Promise.race([conn.whenConnected, closedRejection]);
|
|
2483
|
-
|
|
2484
|
-
|
|
2485
|
-
|
|
2486
|
-
|
|
2487
|
-
|
|
2488
|
-
|
|
2489
|
-
|
|
2538
|
+
try {
|
|
2539
|
+
this._hub.systemCallSender.handshake(
|
|
2540
|
+
conn,
|
|
2541
|
+
this.format,
|
|
2542
|
+
this.id,
|
|
2543
|
+
this._hub.hubId,
|
|
2544
|
+
++this._handshakeIndex
|
|
2545
|
+
);
|
|
2546
|
+
} catch (e) {
|
|
2547
|
+
warnLog6?.log(`'${this.ref}': Failed to send handshake`, e);
|
|
2548
|
+
throw e;
|
|
2549
|
+
}
|
|
2490
2550
|
const remoteHandshake = await Promise.race([
|
|
2491
2551
|
this._pendingHandshake.promise,
|
|
2492
2552
|
closedRejection
|
|
@@ -2499,20 +2559,24 @@ var RpcClientPeer = class extends RpcPeer {
|
|
|
2499
2559
|
isPeerChanged = this._lastRemoteHubId !== void 0 && this._lastRemoteHubId !== remoteHubId;
|
|
2500
2560
|
if (isPeerChanged) {
|
|
2501
2561
|
this.inbound.clear();
|
|
2562
|
+
infoLog?.log(`'${this.ref}': Peer changed`);
|
|
2502
2563
|
this.peerChanged.trigger();
|
|
2503
2564
|
}
|
|
2504
2565
|
this._lastRemoteHubId = remoteHubId;
|
|
2505
2566
|
}
|
|
2567
|
+
infoLog?.log(`'${this.ref}': Handshake succeeded, peerChanged=${isPeerChanged}`);
|
|
2506
2568
|
this._connection = conn;
|
|
2507
2569
|
this._connectionKind = 2 /* Connected */;
|
|
2508
2570
|
this._tryIndex = 0;
|
|
2509
2571
|
await this._reconnect(isPeerChanged);
|
|
2510
2572
|
await new Promise((r) => conn.closed.add(() => r()));
|
|
2511
|
-
} catch {
|
|
2573
|
+
} catch (e) {
|
|
2574
|
+
debugLog2?.log(`'${this.ref}': run() iteration failed:`, e);
|
|
2512
2575
|
}
|
|
2513
2576
|
this._connectionKind = 0 /* Disconnected */;
|
|
2514
2577
|
if (this._disposed) break;
|
|
2515
2578
|
if (lastCloseCode === RPC_CLOSE_CODE_UNSUPPORTED_FORMAT) {
|
|
2579
|
+
warnLog6?.log(`'${this.ref}': Unsupported serialization format - shutting down`);
|
|
2516
2580
|
this.unsupportedFormat.trigger({ reason: lastCloseReason });
|
|
2517
2581
|
this._disposed = true;
|
|
2518
2582
|
break;
|
|
@@ -2520,6 +2584,7 @@ var RpcClientPeer = class extends RpcPeer {
|
|
|
2520
2584
|
this._tryIndex++;
|
|
2521
2585
|
const delay = this.reconnectDelayer.getDelay(this._tryIndex);
|
|
2522
2586
|
if (delay.isLimitExceeded) {
|
|
2587
|
+
warnLog6?.log(`'${this.ref}': Reconnect limit exceeded - shutting down`);
|
|
2523
2588
|
this._disposed = true;
|
|
2524
2589
|
break;
|
|
2525
2590
|
}
|
|
@@ -2714,6 +2779,7 @@ function _toBytes2(value) {
|
|
|
2714
2779
|
}
|
|
2715
2780
|
|
|
2716
2781
|
// src/rpc-service-host.ts
|
|
2782
|
+
var { warnLog: warnLog7 } = getLogs("RpcServiceHost");
|
|
2717
2783
|
var RpcServiceHost = class {
|
|
2718
2784
|
_methods = /* @__PURE__ */ new Map();
|
|
2719
2785
|
register(def, impl) {
|
|
@@ -2728,8 +2794,10 @@ var RpcServiceHost = class {
|
|
|
2728
2794
|
}
|
|
2729
2795
|
async dispatch(wireMethod, args, context) {
|
|
2730
2796
|
const entry = this._methods.get(wireMethod);
|
|
2731
|
-
if (entry === void 0)
|
|
2797
|
+
if (entry === void 0) {
|
|
2798
|
+
warnLog7?.log(`Method not found: ${wireMethod}`);
|
|
2732
2799
|
throw new Error(`Method not found: ${wireMethod}`);
|
|
2800
|
+
}
|
|
2733
2801
|
if (context !== void 0 && entry.def.callTypeId !== 0) {
|
|
2734
2802
|
return await entry.fn(...args, context);
|
|
2735
2803
|
}
|
|
@@ -3259,6 +3327,7 @@ function computeMethodHash(methodName) {
|
|
|
3259
3327
|
}
|
|
3260
3328
|
|
|
3261
3329
|
// src/rpc-method-registry.ts
|
|
3330
|
+
var { warnLog: warnLog8 } = getLogs("RpcMethodRegistry");
|
|
3262
3331
|
var RpcMethodRegistry = class {
|
|
3263
3332
|
_nameToHash = /* @__PURE__ */ new Map();
|
|
3264
3333
|
_hashToName = /* @__PURE__ */ new Map();
|
|
@@ -3268,9 +3337,7 @@ var RpcMethodRegistry = class {
|
|
|
3268
3337
|
const hash = computeMethodHash(methodName);
|
|
3269
3338
|
const existing = this._hashToName.get(hash);
|
|
3270
3339
|
if (existing !== void 0 && existing !== methodName) {
|
|
3271
|
-
|
|
3272
|
-
`[RpcMethodRegistry] hash collision: "${methodName}" and "${existing}" both hash to ${hash}`
|
|
3273
|
-
);
|
|
3340
|
+
warnLog8?.log(`hash collision: "${methodName}" and "${existing}" both hash to ${hash}`);
|
|
3274
3341
|
return;
|
|
3275
3342
|
}
|
|
3276
3343
|
this._nameToHash.set(methodName, hash);
|
|
@@ -3303,6 +3370,7 @@ var RpcMethodRegistry = class {
|
|
|
3303
3370
|
};
|
|
3304
3371
|
|
|
3305
3372
|
// src/rpc-hub.ts
|
|
3373
|
+
var { warnLog: warnLog9 } = getLogs("RpcHub");
|
|
3306
3374
|
var RpcHub = class {
|
|
3307
3375
|
hubId;
|
|
3308
3376
|
peers = /* @__PURE__ */ new Map();
|
|
@@ -3328,6 +3396,7 @@ var RpcHub = class {
|
|
|
3328
3396
|
if (peer !== void 0) {
|
|
3329
3397
|
peer.close();
|
|
3330
3398
|
this.peers.delete(ref);
|
|
3399
|
+
warnLog9?.log(`'${ref}': peer is removed from RpcHub`);
|
|
3331
3400
|
}
|
|
3332
3401
|
}
|
|
3333
3402
|
/** Get or create a peer by ref. Server peers have "server://" prefix, everything else is a client peer. */
|
|
@@ -3560,6 +3629,7 @@ function getStateDescription(state, useLastError = false) {
|
|
|
3560
3629
|
|
|
3561
3630
|
// src/rpc-peer-state-monitor.ts
|
|
3562
3631
|
import { EventHandlerSet as EventHandlerSet4 } from "@actuallab/core";
|
|
3632
|
+
var { infoLog: infoLog2 } = getLogs("RpcPeerStateMonitor");
|
|
3563
3633
|
var JustConnectedPeriodMs = 1500;
|
|
3564
3634
|
var JustDisconnectedPeriodMs = 3e3;
|
|
3565
3635
|
var MinReconnectsInMs = 1e3;
|
|
@@ -3621,6 +3691,7 @@ var RpcPeerStateMonitor = class {
|
|
|
3621
3691
|
this._scheduleRecompute(
|
|
3622
3692
|
this._rawConnected ? JustConnectedPeriodMs : JustDisconnectedPeriodMs
|
|
3623
3693
|
);
|
|
3694
|
+
infoLog2?.log(`'${peer.ref}': monitor started`);
|
|
3624
3695
|
}
|
|
3625
3696
|
get state() {
|
|
3626
3697
|
return this._state;
|
|
@@ -3636,6 +3707,7 @@ var RpcPeerStateMonitor = class {
|
|
|
3636
3707
|
this.peer.reconnectDelayer.cancelDelaysChanged.remove(
|
|
3637
3708
|
this._onCancelDelaysChanged
|
|
3638
3709
|
);
|
|
3710
|
+
infoLog2?.log(`'${this.peer.ref}': monitor stopped`);
|
|
3639
3711
|
}
|
|
3640
3712
|
_recompute() {
|
|
3641
3713
|
if (this._timer !== void 0) {
|
|
@@ -3761,6 +3833,7 @@ export {
|
|
|
3761
3833
|
deserializeBinaryMessage,
|
|
3762
3834
|
deserializeCompactBinaryMessage,
|
|
3763
3835
|
deserializeMessage,
|
|
3836
|
+
getLogs,
|
|
3764
3837
|
getMethodsMeta,
|
|
3765
3838
|
getServiceMeta,
|
|
3766
3839
|
getStateDescription,
|