@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.cjs +67 -33
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +26 -9
- package/dist/index.d.ts +26 -9
- package/dist/index.js +66 -32
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -31,7 +31,6 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
31
31
|
var index_exports = {};
|
|
32
32
|
__export(index_exports, {
|
|
33
33
|
ARG_DELIMITER: () => ARG_DELIMITER,
|
|
34
|
-
DEFAULT_SERIALIZATION_FORMAT: () => DEFAULT_SERIALIZATION_FORMAT,
|
|
35
34
|
ENVELOPE_DELIMITER: () => ENVELOPE_DELIMITER,
|
|
36
35
|
FRAME_DELIMITER: () => FRAME_DELIMITER,
|
|
37
36
|
RPC_CLOSE_CODE_UNSUPPORTED_FORMAT: () => RPC_CLOSE_CODE_UNSUPPORTED_FORMAT,
|
|
@@ -55,6 +54,7 @@ __export(index_exports, {
|
|
|
55
54
|
RpcPeerStateMonitor: () => RpcPeerStateMonitor,
|
|
56
55
|
RpcRemoteObjectTracker: () => RpcRemoteObjectTracker,
|
|
57
56
|
RpcSerializationFormat: () => RpcSerializationFormat,
|
|
57
|
+
RpcSerializationFormatResolver: () => RpcSerializationFormatResolver,
|
|
58
58
|
RpcServerPeer: () => RpcServerPeer,
|
|
59
59
|
RpcServiceHost: () => RpcServiceHost,
|
|
60
60
|
RpcSharedObjectTracker: () => RpcSharedObjectTracker,
|
|
@@ -1459,7 +1459,7 @@ var RpcClientPeerReconnectDelayer = class extends import_core6.RetryDelayer {
|
|
|
1459
1459
|
|
|
1460
1460
|
// src/rpc-serialization-format.ts
|
|
1461
1461
|
var import_msgpack3 = require("@msgpack/msgpack");
|
|
1462
|
-
var RpcSerializationFormat = class
|
|
1462
|
+
var RpcSerializationFormat = class {
|
|
1463
1463
|
/** Create a reusable binary encoder for this format. Returns undefined for text formats. */
|
|
1464
1464
|
createEncoder() {
|
|
1465
1465
|
return void 0;
|
|
@@ -1468,19 +1468,23 @@ var RpcSerializationFormat = class _RpcSerializationFormat {
|
|
|
1468
1468
|
createDecoder() {
|
|
1469
1469
|
return void 0;
|
|
1470
1470
|
}
|
|
1471
|
-
//
|
|
1472
|
-
static
|
|
1473
|
-
static
|
|
1474
|
-
|
|
1475
|
-
|
|
1471
|
+
// Named format instances — initialized in initFormats() below (after subclasses are defined)
|
|
1472
|
+
static SystemJsonV5;
|
|
1473
|
+
static SystemJsonV5NP;
|
|
1474
|
+
static NewtonsoftJsonV5;
|
|
1475
|
+
static NewtonsoftJsonV5NP;
|
|
1476
|
+
static MessagePackV6;
|
|
1477
|
+
static MemoryPackV6;
|
|
1478
|
+
static MessagePackV6C;
|
|
1479
|
+
static MemoryPackV6C;
|
|
1480
|
+
static All;
|
|
1481
|
+
/** Convenience shortcut for RpcSerializationFormatResolver.Default.get(key). */
|
|
1476
1482
|
static get(key) {
|
|
1477
|
-
|
|
1478
|
-
if (!format)
|
|
1479
|
-
throw new Error(`Unknown RPC serialization format: "${key}"`);
|
|
1480
|
-
return format;
|
|
1483
|
+
return RpcSerializationFormatResolver.Default.get(key);
|
|
1481
1484
|
}
|
|
1485
|
+
/** Convenience shortcut for RpcSerializationFormatResolver.Default.tryGet(key). */
|
|
1482
1486
|
static tryGet(key) {
|
|
1483
|
-
return
|
|
1487
|
+
return RpcSerializationFormatResolver.Default.tryGet(key);
|
|
1484
1488
|
}
|
|
1485
1489
|
};
|
|
1486
1490
|
var RpcJsonSerializationFormat = class extends RpcSerializationFormat {
|
|
@@ -1563,25 +1567,54 @@ var RpcMessagePackCompactSerializationFormat = class extends RpcSerializationFor
|
|
|
1563
1567
|
return new import_msgpack3.Decoder();
|
|
1564
1568
|
}
|
|
1565
1569
|
};
|
|
1566
|
-
RpcSerializationFormat.
|
|
1567
|
-
RpcSerializationFormat.
|
|
1568
|
-
RpcSerializationFormat.
|
|
1569
|
-
RpcSerializationFormat.
|
|
1570
|
-
RpcSerializationFormat.
|
|
1571
|
-
|
|
1572
|
-
);
|
|
1573
|
-
RpcSerializationFormat.
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
RpcSerializationFormat.
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
RpcSerializationFormat.
|
|
1580
|
-
|
|
1581
|
-
|
|
1570
|
+
RpcSerializationFormat.SystemJsonV5 = new RpcJsonSerializationFormat("json5");
|
|
1571
|
+
RpcSerializationFormat.SystemJsonV5NP = new RpcJsonSerializationFormat("json5np");
|
|
1572
|
+
RpcSerializationFormat.NewtonsoftJsonV5 = new RpcJsonSerializationFormat("njson5");
|
|
1573
|
+
RpcSerializationFormat.NewtonsoftJsonV5NP = new RpcJsonSerializationFormat("njson5np");
|
|
1574
|
+
RpcSerializationFormat.MessagePackV6 = new RpcMessagePackSerializationFormat("msgpack6");
|
|
1575
|
+
RpcSerializationFormat.MemoryPackV6 = new RpcMessagePackSerializationFormat("mempack6");
|
|
1576
|
+
RpcSerializationFormat.MessagePackV6C = new RpcMessagePackCompactSerializationFormat("msgpack6c");
|
|
1577
|
+
RpcSerializationFormat.MemoryPackV6C = new RpcMessagePackCompactSerializationFormat("mempack6c");
|
|
1578
|
+
RpcSerializationFormat.All = [
|
|
1579
|
+
RpcSerializationFormat.SystemJsonV5,
|
|
1580
|
+
RpcSerializationFormat.SystemJsonV5NP,
|
|
1581
|
+
RpcSerializationFormat.NewtonsoftJsonV5,
|
|
1582
|
+
RpcSerializationFormat.NewtonsoftJsonV5NP,
|
|
1583
|
+
RpcSerializationFormat.MessagePackV6,
|
|
1584
|
+
RpcSerializationFormat.MemoryPackV6,
|
|
1585
|
+
RpcSerializationFormat.MessagePackV6C,
|
|
1586
|
+
RpcSerializationFormat.MemoryPackV6C
|
|
1587
|
+
];
|
|
1588
|
+
var RpcSerializationFormatResolver = class _RpcSerializationFormatResolver {
|
|
1589
|
+
static DefaultFormats = RpcSerializationFormat.All;
|
|
1590
|
+
static Default = new _RpcSerializationFormatResolver("json5np");
|
|
1591
|
+
defaultFormatKey;
|
|
1592
|
+
formats;
|
|
1593
|
+
get defaultFormat() {
|
|
1594
|
+
return this.get(this.defaultFormatKey);
|
|
1595
|
+
}
|
|
1596
|
+
constructor(defaultFormatKey, formats) {
|
|
1597
|
+
const map = /* @__PURE__ */ new Map();
|
|
1598
|
+
for (const f of formats ?? _RpcSerializationFormatResolver.DefaultFormats)
|
|
1599
|
+
map.set(f.key, f);
|
|
1600
|
+
if (!map.has(defaultFormatKey))
|
|
1601
|
+
throw new Error(`No format with key '${defaultFormatKey}'.`);
|
|
1602
|
+
this.defaultFormatKey = defaultFormatKey;
|
|
1603
|
+
this.formats = map;
|
|
1604
|
+
}
|
|
1605
|
+
get(key) {
|
|
1606
|
+
const format = this.tryGet(key);
|
|
1607
|
+
if (!format)
|
|
1608
|
+
throw new Error(`No format with key '${key}'.`);
|
|
1609
|
+
return format;
|
|
1610
|
+
}
|
|
1611
|
+
tryGet(key) {
|
|
1612
|
+
if (!key) key = this.defaultFormatKey;
|
|
1613
|
+
return this.formats.get(key);
|
|
1614
|
+
}
|
|
1615
|
+
};
|
|
1582
1616
|
|
|
1583
1617
|
// src/rpc-peer.ts
|
|
1584
|
-
var DEFAULT_SERIALIZATION_FORMAT = "json5np";
|
|
1585
1618
|
var RPC_CLOSE_CODE_UNSUPPORTED_FORMAT = 4001;
|
|
1586
1619
|
var defaultConnectionUrlResolver = (peer) => {
|
|
1587
1620
|
const sep = peer.ref.includes("?") ? "&" : "?";
|
|
@@ -1630,7 +1663,7 @@ var RpcPeer = class {
|
|
|
1630
1663
|
}
|
|
1631
1664
|
/** The serialization format used by this peer. Override in subclasses. */
|
|
1632
1665
|
get format() {
|
|
1633
|
-
return
|
|
1666
|
+
return RpcSerializationFormatResolver.Default.defaultFormat;
|
|
1634
1667
|
}
|
|
1635
1668
|
call(method, args, options) {
|
|
1636
1669
|
const callId = this.outbound.nextId();
|
|
@@ -1867,8 +1900,9 @@ var RpcClientPeer = class extends RpcPeer {
|
|
|
1867
1900
|
constructor(hub, url, serializationFormat) {
|
|
1868
1901
|
super(url, hub);
|
|
1869
1902
|
this.clientId = guidToBase64Url(this.id);
|
|
1870
|
-
|
|
1871
|
-
this.
|
|
1903
|
+
const resolver = RpcSerializationFormatResolver.Default;
|
|
1904
|
+
this.serializationFormat = serializationFormat ?? resolver.defaultFormatKey;
|
|
1905
|
+
this._format = resolver.get(this.serializationFormat);
|
|
1872
1906
|
}
|
|
1873
1907
|
get format() {
|
|
1874
1908
|
return this._format;
|
|
@@ -3016,7 +3050,6 @@ var RpcPeerStateMonitor = class {
|
|
|
3016
3050
|
// Annotate the CommonJS export names for ESM import in node:
|
|
3017
3051
|
0 && (module.exports = {
|
|
3018
3052
|
ARG_DELIMITER,
|
|
3019
|
-
DEFAULT_SERIALIZATION_FORMAT,
|
|
3020
3053
|
ENVELOPE_DELIMITER,
|
|
3021
3054
|
FRAME_DELIMITER,
|
|
3022
3055
|
RPC_CLOSE_CODE_UNSUPPORTED_FORMAT,
|
|
@@ -3040,6 +3073,7 @@ var RpcPeerStateMonitor = class {
|
|
|
3040
3073
|
RpcPeerStateMonitor,
|
|
3041
3074
|
RpcRemoteObjectTracker,
|
|
3042
3075
|
RpcSerializationFormat,
|
|
3076
|
+
RpcSerializationFormatResolver,
|
|
3043
3077
|
RpcServerPeer,
|
|
3044
3078
|
RpcServiceHost,
|
|
3045
3079
|
RpcSharedObjectTracker,
|