@actuallab/rpc 12.2.21 → 12.2.23

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
@@ -192,9 +192,18 @@ declare abstract class RpcSerializationFormat {
192
192
  createEncoder(): Encoder | undefined;
193
193
  /** Create a reusable binary decoder for this format. Returns undefined for text formats. */
194
194
  createDecoder(): Decoder | undefined;
195
- private static _all;
196
- static register(format: RpcSerializationFormat): void;
195
+ static SystemJsonV5: RpcSerializationFormat;
196
+ static SystemJsonV5NP: RpcSerializationFormat;
197
+ static NewtonsoftJsonV5: RpcSerializationFormat;
198
+ static NewtonsoftJsonV5NP: RpcSerializationFormat;
199
+ static MessagePackV6: RpcSerializationFormat;
200
+ static MemoryPackV6: RpcSerializationFormat;
201
+ static MessagePackV6C: RpcSerializationFormat;
202
+ static MemoryPackV6C: RpcSerializationFormat;
203
+ static All: readonly RpcSerializationFormat[];
204
+ /** Convenience shortcut for RpcSerializationFormatResolver.Default.get(key). */
197
205
  static get(key: string): RpcSerializationFormat;
206
+ /** Convenience shortcut for RpcSerializationFormatResolver.Default.tryGet(key). */
198
207
  static tryGet(key: string): RpcSerializationFormat | undefined;
199
208
  }
200
209
  /**
@@ -242,6 +251,20 @@ declare class RpcMessagePackCompactSerializationFormat extends RpcSerializationF
242
251
  createEncoder(): Encoder;
243
252
  createDecoder(): Decoder;
244
253
  }
254
+ /**
255
+ * Resolves RpcSerializationFormat instances by key, with a configurable default.
256
+ * Mirrors .NET RpcSerializationFormatResolver.
257
+ */
258
+ declare class RpcSerializationFormatResolver {
259
+ static DefaultFormats: readonly RpcSerializationFormat[];
260
+ static Default: RpcSerializationFormatResolver;
261
+ readonly defaultFormatKey: string;
262
+ readonly formats: ReadonlyMap<string, RpcSerializationFormat>;
263
+ get defaultFormat(): RpcSerializationFormat;
264
+ constructor(defaultFormatKey: string, formats?: Iterable<RpcSerializationFormat>);
265
+ get(key: string): RpcSerializationFormat;
266
+ tryGet(key: string): RpcSerializationFormat | undefined;
267
+ }
245
268
 
246
269
  /** Abstract WebSocket interface — works with both browser WebSocket and Node.js ws. */
247
270
  interface WebSocketLike {
@@ -574,12 +597,6 @@ declare class RpcSharedObjectTracker {
574
597
  disconnectAll(): void;
575
598
  }
576
599
 
577
- /**
578
- * Default serialization format for RpcClientPeer connections.
579
- * TS uses plain JSON.stringify without polymorphic type wrapping,
580
- * so "json5np" (System.Text.Json, no polymorphism) is the correct match.
581
- */
582
- declare const DEFAULT_SERIALIZATION_FORMAT = "json5np";
583
600
  /** WebSocket close code sent by the server when the client's serialization format is unsupported. */
584
601
  declare const RPC_CLOSE_CODE_UNSUPPORTED_FORMAT = 4001;
585
602
  /** Builds the WebSocket connection URL for an RpcClientPeer. */
@@ -913,4 +930,4 @@ declare function xxh3_64str(input: string, seed?: bigint): bigint;
913
930
  */
914
931
  declare function computeMethodHash(methodName: string): number;
915
932
 
916
- export { ARG_DELIMITER, DEFAULT_SERIALIZATION_FORMAT, ENVELOPE_DELIMITER, FRAME_DELIMITER, type IRpcObject, type MethodMeta, RPC_CLOSE_CODE_UNSUPPORTED_FORMAT, type RemoteHandshake, type RpcCallOptions, 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, RpcRemoteObjectTracker, RpcSerializationFormat, RpcServerPeer, type RpcServiceDef, RpcServiceHost, type RpcServiceImpl, RpcSharedObjectTracker, RpcStream, type RpcStreamRef, RpcStreamSender, 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 };
933
+ export { ARG_DELIMITER, ENVELOPE_DELIMITER, FRAME_DELIMITER, type IRpcObject, type MethodMeta, RPC_CLOSE_CODE_UNSUPPORTED_FORMAT, type RemoteHandshake, type RpcCallOptions, 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, RpcRemoteObjectTracker, RpcSerializationFormat, RpcSerializationFormatResolver, RpcServerPeer, type RpcServiceDef, RpcServiceHost, type RpcServiceImpl, RpcSharedObjectTracker, RpcStream, type RpcStreamRef, RpcStreamSender, 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 };
package/dist/index.d.ts CHANGED
@@ -192,9 +192,18 @@ declare abstract class RpcSerializationFormat {
192
192
  createEncoder(): Encoder | undefined;
193
193
  /** Create a reusable binary decoder for this format. Returns undefined for text formats. */
194
194
  createDecoder(): Decoder | undefined;
195
- private static _all;
196
- static register(format: RpcSerializationFormat): void;
195
+ static SystemJsonV5: RpcSerializationFormat;
196
+ static SystemJsonV5NP: RpcSerializationFormat;
197
+ static NewtonsoftJsonV5: RpcSerializationFormat;
198
+ static NewtonsoftJsonV5NP: RpcSerializationFormat;
199
+ static MessagePackV6: RpcSerializationFormat;
200
+ static MemoryPackV6: RpcSerializationFormat;
201
+ static MessagePackV6C: RpcSerializationFormat;
202
+ static MemoryPackV6C: RpcSerializationFormat;
203
+ static All: readonly RpcSerializationFormat[];
204
+ /** Convenience shortcut for RpcSerializationFormatResolver.Default.get(key). */
197
205
  static get(key: string): RpcSerializationFormat;
206
+ /** Convenience shortcut for RpcSerializationFormatResolver.Default.tryGet(key). */
198
207
  static tryGet(key: string): RpcSerializationFormat | undefined;
199
208
  }
200
209
  /**
@@ -242,6 +251,20 @@ declare class RpcMessagePackCompactSerializationFormat extends RpcSerializationF
242
251
  createEncoder(): Encoder;
243
252
  createDecoder(): Decoder;
244
253
  }
254
+ /**
255
+ * Resolves RpcSerializationFormat instances by key, with a configurable default.
256
+ * Mirrors .NET RpcSerializationFormatResolver.
257
+ */
258
+ declare class RpcSerializationFormatResolver {
259
+ static DefaultFormats: readonly RpcSerializationFormat[];
260
+ static Default: RpcSerializationFormatResolver;
261
+ readonly defaultFormatKey: string;
262
+ readonly formats: ReadonlyMap<string, RpcSerializationFormat>;
263
+ get defaultFormat(): RpcSerializationFormat;
264
+ constructor(defaultFormatKey: string, formats?: Iterable<RpcSerializationFormat>);
265
+ get(key: string): RpcSerializationFormat;
266
+ tryGet(key: string): RpcSerializationFormat | undefined;
267
+ }
245
268
 
246
269
  /** Abstract WebSocket interface — works with both browser WebSocket and Node.js ws. */
247
270
  interface WebSocketLike {
@@ -574,12 +597,6 @@ declare class RpcSharedObjectTracker {
574
597
  disconnectAll(): void;
575
598
  }
576
599
 
577
- /**
578
- * Default serialization format for RpcClientPeer connections.
579
- * TS uses plain JSON.stringify without polymorphic type wrapping,
580
- * so "json5np" (System.Text.Json, no polymorphism) is the correct match.
581
- */
582
- declare const DEFAULT_SERIALIZATION_FORMAT = "json5np";
583
600
  /** WebSocket close code sent by the server when the client's serialization format is unsupported. */
584
601
  declare const RPC_CLOSE_CODE_UNSUPPORTED_FORMAT = 4001;
585
602
  /** Builds the WebSocket connection URL for an RpcClientPeer. */
@@ -913,4 +930,4 @@ declare function xxh3_64str(input: string, seed?: bigint): bigint;
913
930
  */
914
931
  declare function computeMethodHash(methodName: string): number;
915
932
 
916
- export { ARG_DELIMITER, DEFAULT_SERIALIZATION_FORMAT, ENVELOPE_DELIMITER, FRAME_DELIMITER, type IRpcObject, type MethodMeta, RPC_CLOSE_CODE_UNSUPPORTED_FORMAT, type RemoteHandshake, type RpcCallOptions, 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, RpcRemoteObjectTracker, RpcSerializationFormat, RpcServerPeer, type RpcServiceDef, RpcServiceHost, type RpcServiceImpl, RpcSharedObjectTracker, RpcStream, type RpcStreamRef, RpcStreamSender, 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 };
933
+ export { ARG_DELIMITER, ENVELOPE_DELIMITER, FRAME_DELIMITER, type IRpcObject, type MethodMeta, RPC_CLOSE_CODE_UNSUPPORTED_FORMAT, type RemoteHandshake, type RpcCallOptions, 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, RpcRemoteObjectTracker, RpcSerializationFormat, RpcSerializationFormatResolver, RpcServerPeer, type RpcServiceDef, RpcServiceHost, type RpcServiceImpl, RpcSharedObjectTracker, RpcStream, type RpcStreamRef, RpcStreamSender, 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 };
package/dist/index.js CHANGED
@@ -1360,7 +1360,7 @@ var RpcClientPeerReconnectDelayer = class extends RetryDelayer {
1360
1360
 
1361
1361
  // src/rpc-serialization-format.ts
1362
1362
  import { Decoder as Decoder3 } from "@msgpack/msgpack";
1363
- var RpcSerializationFormat = class _RpcSerializationFormat {
1363
+ var RpcSerializationFormat = class {
1364
1364
  /** Create a reusable binary encoder for this format. Returns undefined for text formats. */
1365
1365
  createEncoder() {
1366
1366
  return void 0;
@@ -1369,19 +1369,23 @@ var RpcSerializationFormat = class _RpcSerializationFormat {
1369
1369
  createDecoder() {
1370
1370
  return void 0;
1371
1371
  }
1372
- // --- Static registry ---
1373
- static _all = /* @__PURE__ */ new Map();
1374
- static register(format) {
1375
- _RpcSerializationFormat._all.set(format.key, format);
1376
- }
1372
+ // Named format instances — initialized in initFormats() below (after subclasses are defined)
1373
+ static SystemJsonV5;
1374
+ static SystemJsonV5NP;
1375
+ static NewtonsoftJsonV5;
1376
+ static NewtonsoftJsonV5NP;
1377
+ static MessagePackV6;
1378
+ static MemoryPackV6;
1379
+ static MessagePackV6C;
1380
+ static MemoryPackV6C;
1381
+ static All;
1382
+ /** Convenience shortcut for RpcSerializationFormatResolver.Default.get(key). */
1377
1383
  static get(key) {
1378
- const format = _RpcSerializationFormat._all.get(key);
1379
- if (!format)
1380
- throw new Error(`Unknown RPC serialization format: "${key}"`);
1381
- return format;
1384
+ return RpcSerializationFormatResolver.Default.get(key);
1382
1385
  }
1386
+ /** Convenience shortcut for RpcSerializationFormatResolver.Default.tryGet(key). */
1383
1387
  static tryGet(key) {
1384
- return _RpcSerializationFormat._all.get(key);
1388
+ return RpcSerializationFormatResolver.Default.tryGet(key);
1385
1389
  }
1386
1390
  };
1387
1391
  var RpcJsonSerializationFormat = class extends RpcSerializationFormat {
@@ -1464,25 +1468,54 @@ var RpcMessagePackCompactSerializationFormat = class extends RpcSerializationFor
1464
1468
  return new Decoder3();
1465
1469
  }
1466
1470
  };
1467
- RpcSerializationFormat.register(new RpcJsonSerializationFormat("json5"));
1468
- RpcSerializationFormat.register(new RpcJsonSerializationFormat("json5np"));
1469
- RpcSerializationFormat.register(new RpcJsonSerializationFormat("njson5"));
1470
- RpcSerializationFormat.register(new RpcJsonSerializationFormat("njson5np"));
1471
- RpcSerializationFormat.register(
1472
- new RpcMessagePackSerializationFormat("msgpack6")
1473
- );
1474
- RpcSerializationFormat.register(
1475
- new RpcMessagePackSerializationFormat("mempack6")
1476
- );
1477
- RpcSerializationFormat.register(
1478
- new RpcMessagePackCompactSerializationFormat("msgpack6c")
1479
- );
1480
- RpcSerializationFormat.register(
1481
- new RpcMessagePackCompactSerializationFormat("mempack6c")
1482
- );
1471
+ RpcSerializationFormat.SystemJsonV5 = new RpcJsonSerializationFormat("json5");
1472
+ RpcSerializationFormat.SystemJsonV5NP = new RpcJsonSerializationFormat("json5np");
1473
+ RpcSerializationFormat.NewtonsoftJsonV5 = new RpcJsonSerializationFormat("njson5");
1474
+ RpcSerializationFormat.NewtonsoftJsonV5NP = new RpcJsonSerializationFormat("njson5np");
1475
+ RpcSerializationFormat.MessagePackV6 = new RpcMessagePackSerializationFormat("msgpack6");
1476
+ RpcSerializationFormat.MemoryPackV6 = new RpcMessagePackSerializationFormat("mempack6");
1477
+ RpcSerializationFormat.MessagePackV6C = new RpcMessagePackCompactSerializationFormat("msgpack6c");
1478
+ RpcSerializationFormat.MemoryPackV6C = new RpcMessagePackCompactSerializationFormat("mempack6c");
1479
+ RpcSerializationFormat.All = [
1480
+ RpcSerializationFormat.SystemJsonV5,
1481
+ RpcSerializationFormat.SystemJsonV5NP,
1482
+ RpcSerializationFormat.NewtonsoftJsonV5,
1483
+ RpcSerializationFormat.NewtonsoftJsonV5NP,
1484
+ RpcSerializationFormat.MessagePackV6,
1485
+ RpcSerializationFormat.MemoryPackV6,
1486
+ RpcSerializationFormat.MessagePackV6C,
1487
+ RpcSerializationFormat.MemoryPackV6C
1488
+ ];
1489
+ var RpcSerializationFormatResolver = class _RpcSerializationFormatResolver {
1490
+ static DefaultFormats = RpcSerializationFormat.All;
1491
+ static Default = new _RpcSerializationFormatResolver("json5np");
1492
+ defaultFormatKey;
1493
+ formats;
1494
+ get defaultFormat() {
1495
+ return this.get(this.defaultFormatKey);
1496
+ }
1497
+ constructor(defaultFormatKey, formats) {
1498
+ const map = /* @__PURE__ */ new Map();
1499
+ for (const f of formats ?? _RpcSerializationFormatResolver.DefaultFormats)
1500
+ map.set(f.key, f);
1501
+ if (!map.has(defaultFormatKey))
1502
+ throw new Error(`No format with key '${defaultFormatKey}'.`);
1503
+ this.defaultFormatKey = defaultFormatKey;
1504
+ this.formats = map;
1505
+ }
1506
+ get(key) {
1507
+ const format = this.tryGet(key);
1508
+ if (!format)
1509
+ throw new Error(`No format with key '${key}'.`);
1510
+ return format;
1511
+ }
1512
+ tryGet(key) {
1513
+ if (!key) key = this.defaultFormatKey;
1514
+ return this.formats.get(key);
1515
+ }
1516
+ };
1483
1517
 
1484
1518
  // src/rpc-peer.ts
1485
- var DEFAULT_SERIALIZATION_FORMAT = "json5np";
1486
1519
  var RPC_CLOSE_CODE_UNSUPPORTED_FORMAT = 4001;
1487
1520
  var defaultConnectionUrlResolver = (peer) => {
1488
1521
  const sep = peer.ref.includes("?") ? "&" : "?";
@@ -1531,7 +1564,7 @@ var RpcPeer = class {
1531
1564
  }
1532
1565
  /** The serialization format used by this peer. Override in subclasses. */
1533
1566
  get format() {
1534
- return RpcSerializationFormat.get("json5np");
1567
+ return RpcSerializationFormatResolver.Default.defaultFormat;
1535
1568
  }
1536
1569
  call(method, args, options) {
1537
1570
  const callId = this.outbound.nextId();
@@ -1768,8 +1801,9 @@ var RpcClientPeer = class extends RpcPeer {
1768
1801
  constructor(hub, url, serializationFormat) {
1769
1802
  super(url, hub);
1770
1803
  this.clientId = guidToBase64Url(this.id);
1771
- this.serializationFormat = serializationFormat ?? DEFAULT_SERIALIZATION_FORMAT;
1772
- this._format = RpcSerializationFormat.get(this.serializationFormat);
1804
+ const resolver = RpcSerializationFormatResolver.Default;
1805
+ this.serializationFormat = serializationFormat ?? resolver.defaultFormatKey;
1806
+ this._format = resolver.get(this.serializationFormat);
1773
1807
  }
1774
1808
  get format() {
1775
1809
  return this._format;
@@ -2916,7 +2950,6 @@ var RpcPeerStateMonitor = class {
2916
2950
  };
2917
2951
  export {
2918
2952
  ARG_DELIMITER,
2919
- DEFAULT_SERIALIZATION_FORMAT,
2920
2953
  ENVELOPE_DELIMITER,
2921
2954
  FRAME_DELIMITER,
2922
2955
  RPC_CLOSE_CODE_UNSUPPORTED_FORMAT,
@@ -2940,6 +2973,7 @@ export {
2940
2973
  RpcPeerStateMonitor,
2941
2974
  RpcRemoteObjectTracker,
2942
2975
  RpcSerializationFormat,
2976
+ RpcSerializationFormatResolver,
2943
2977
  RpcServerPeer,
2944
2978
  RpcServiceHost,
2945
2979
  RpcSharedObjectTracker,