capnweb 0.0.0-07032e2 → 0.0.0-0b19df9
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-bun.cjs +75 -6
- package/dist/index-bun.cjs.map +1 -1
- package/dist/index-bun.d.cts +7 -2
- package/dist/index-bun.d.ts +7 -2
- package/dist/index-bun.js +75 -6
- package/dist/index-bun.js.map +1 -1
- package/dist/index-workers.cjs +75 -6
- package/dist/index-workers.cjs.map +1 -1
- package/dist/index-workers.d.cts +3 -1
- package/dist/index-workers.d.ts +3 -1
- package/dist/index-workers.js +75 -6
- package/dist/index-workers.js.map +1 -1
- package/dist/index.cjs +75 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +75 -6
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index-workers.cjs
CHANGED
|
@@ -77,6 +77,7 @@ function typeForRpc(value) {
|
|
|
77
77
|
case Date.prototype: return "date";
|
|
78
78
|
case RegExp.prototype: return "regexp";
|
|
79
79
|
case Set.prototype: return "set";
|
|
80
|
+
case Map.prototype: return "map";
|
|
80
81
|
case Uint8Array.prototype:
|
|
81
82
|
case BUFFER_PROTOTYPE:
|
|
82
83
|
case ArrayBuffer.prototype:
|
|
@@ -340,6 +341,9 @@ async function pullPromise(promise) {
|
|
|
340
341
|
if (pathIfPromise.length > 0) hook = hook.get(pathIfPromise);
|
|
341
342
|
return (await hook.pull()).deliverResolve();
|
|
342
343
|
}
|
|
344
|
+
function mapKeyToPropertyName(key) {
|
|
345
|
+
return typeof key === "string" || typeof key === "number" ? key : { mapKey: key };
|
|
346
|
+
}
|
|
343
347
|
var RpcPayload = class RpcPayload {
|
|
344
348
|
value;
|
|
345
349
|
source;
|
|
@@ -448,7 +452,7 @@ var RpcPayload = class RpcPayload {
|
|
|
448
452
|
return hook.dup();
|
|
449
453
|
} else return hook;
|
|
450
454
|
}
|
|
451
|
-
} else
|
|
455
|
+
} else return streamImpl.createReadableStreamHook(stream);
|
|
452
456
|
}
|
|
453
457
|
deepCopy(value, oldParent, property, parent, dupStubs, owner) {
|
|
454
458
|
switch (typeForRpc(value)) {
|
|
@@ -484,6 +488,20 @@ var RpcPayload = class RpcPayload {
|
|
|
484
488
|
}
|
|
485
489
|
return result;
|
|
486
490
|
}
|
|
491
|
+
case "map": {
|
|
492
|
+
let map = value;
|
|
493
|
+
let entries = [...map];
|
|
494
|
+
for (let [key] of entries) {
|
|
495
|
+
let kind = typeForRpc(key);
|
|
496
|
+
if (kind === "rpc-promise" || kind === "rpc-thenable") throw new TypeError("Cannot pass a promise as a key of a Map. Await the value before using it as a key.");
|
|
497
|
+
}
|
|
498
|
+
let result = /* @__PURE__ */ new Map();
|
|
499
|
+
for (let [key, val] of entries) {
|
|
500
|
+
let keyCopy = this.deepCopy(key, map, -1, result, dupStubs, owner);
|
|
501
|
+
result.set(keyCopy, this.deepCopy(val, map, mapKeyToPropertyName(keyCopy), result, dupStubs, owner));
|
|
502
|
+
}
|
|
503
|
+
return result;
|
|
504
|
+
}
|
|
487
505
|
case "object": {
|
|
488
506
|
let result = {};
|
|
489
507
|
let object = value;
|
|
@@ -541,8 +559,10 @@ var RpcPayload = class RpcPayload {
|
|
|
541
559
|
case "readable": {
|
|
542
560
|
let stream = value;
|
|
543
561
|
let hook;
|
|
544
|
-
if (owner)
|
|
545
|
-
|
|
562
|
+
if (owner) {
|
|
563
|
+
if (owner.source === "owned") throw new Error("Can't copy a ReadableStream.");
|
|
564
|
+
hook = owner.getHookForReadableStream(stream, oldParent, dupStubs);
|
|
565
|
+
} else hook = streamImpl.createReadableStreamHook(stream);
|
|
546
566
|
this.hooks.push(hook);
|
|
547
567
|
return stream;
|
|
548
568
|
}
|
|
@@ -585,7 +605,8 @@ var RpcPayload = class RpcPayload {
|
|
|
585
605
|
this.ensureDeepCopied();
|
|
586
606
|
if (this.value instanceof RpcPromise$1) RpcPayload.deliverRpcPromiseTo(this.value, parent, property, promises);
|
|
587
607
|
else {
|
|
588
|
-
parent
|
|
608
|
+
if (parent instanceof Map) parent.set(typeof property === "object" ? property.mapKey : property, this.value);
|
|
609
|
+
else parent[property] = this.value;
|
|
589
610
|
for (let record of this.promises) RpcPayload.deliverRpcPromiseTo(record.promise, record.parent, record.property, promises);
|
|
590
611
|
}
|
|
591
612
|
}
|
|
@@ -691,6 +712,14 @@ var RpcPayload = class RpcPayload {
|
|
|
691
712
|
for (let element of set) this.disposeImpl(element, set);
|
|
692
713
|
return;
|
|
693
714
|
}
|
|
715
|
+
case "map": {
|
|
716
|
+
let map = value;
|
|
717
|
+
for (let [key, val] of map) {
|
|
718
|
+
this.disposeImpl(key, map);
|
|
719
|
+
this.disposeImpl(val, map);
|
|
720
|
+
}
|
|
721
|
+
return;
|
|
722
|
+
}
|
|
694
723
|
case "object": {
|
|
695
724
|
let object = value;
|
|
696
725
|
for (let i in object) this.disposeImpl(object[i], object);
|
|
@@ -781,6 +810,14 @@ var RpcPayload = class RpcPayload {
|
|
|
781
810
|
for (let element of set) this.ignoreUnhandledRejectionsImpl(element);
|
|
782
811
|
return;
|
|
783
812
|
}
|
|
813
|
+
case "map": {
|
|
814
|
+
let map = value;
|
|
815
|
+
for (let [key, val] of map) {
|
|
816
|
+
this.ignoreUnhandledRejectionsImpl(key);
|
|
817
|
+
this.ignoreUnhandledRejectionsImpl(val);
|
|
818
|
+
}
|
|
819
|
+
return;
|
|
820
|
+
}
|
|
784
821
|
case "object": {
|
|
785
822
|
let object = value;
|
|
786
823
|
for (let i in object) this.ignoreUnhandledRejectionsImpl(object[i]);
|
|
@@ -841,6 +878,7 @@ function followPath(value, parent, path, owner) {
|
|
|
841
878
|
case "blob":
|
|
842
879
|
case "date":
|
|
843
880
|
case "set":
|
|
881
|
+
case "map":
|
|
844
882
|
case "error":
|
|
845
883
|
case "url":
|
|
846
884
|
case "regexp":
|
|
@@ -1247,6 +1285,18 @@ var Devaluator = class Devaluator {
|
|
|
1247
1285
|
for (let element of setElements) elements.push(this.devaluateImpl(element, set, depth + 1));
|
|
1248
1286
|
return ["set", elements];
|
|
1249
1287
|
}
|
|
1288
|
+
case "map": {
|
|
1289
|
+
let map = value;
|
|
1290
|
+
let mapEntries = [...map];
|
|
1291
|
+
let entries = [];
|
|
1292
|
+
for (let [key] of mapEntries) switch (typeForRpc(key)) {
|
|
1293
|
+
case "blob": throw new TypeError("Cannot serialize a Blob as a key of a Map.");
|
|
1294
|
+
case "rpc-promise":
|
|
1295
|
+
case "rpc-thenable": throw new TypeError("Cannot serialize a promise as a key of a Map. Await the value before using it as a key.");
|
|
1296
|
+
}
|
|
1297
|
+
for (let [key, val] of mapEntries) entries.push([this.devaluateImpl(key, map, depth + 1), this.devaluateImpl(val, map, depth + 1)]);
|
|
1298
|
+
return ["map", entries];
|
|
1299
|
+
}
|
|
1250
1300
|
case "bigint":
|
|
1251
1301
|
if (this.encodingLevel === "structuredClonable") return value;
|
|
1252
1302
|
return ["bigint", value.toString()];
|
|
@@ -1573,6 +1623,20 @@ var Evaluator = class Evaluator {
|
|
|
1573
1623
|
return set;
|
|
1574
1624
|
}
|
|
1575
1625
|
break;
|
|
1626
|
+
case "map":
|
|
1627
|
+
if (value.length === 2 && value[1] instanceof Array) {
|
|
1628
|
+
let entries = value[1];
|
|
1629
|
+
let map = /* @__PURE__ */ new Map();
|
|
1630
|
+
for (let i = 0; i < entries.length; i++) {
|
|
1631
|
+
let entry = entries[i];
|
|
1632
|
+
if (!(entry instanceof Array) || entry.length !== 2) throw new TypeError("Map entries must be serialized as key/value pairs.");
|
|
1633
|
+
let key = this.evaluateImpl(entry[0], map, i, depth + 1);
|
|
1634
|
+
if (key instanceof RpcPromise$1) throw new TypeError("Cannot deserialize a promise as a key of a Map.");
|
|
1635
|
+
map.set(key, this.evaluateImpl(entry[1], map, mapKeyToPropertyName(key), depth + 1));
|
|
1636
|
+
}
|
|
1637
|
+
return map;
|
|
1638
|
+
}
|
|
1639
|
+
break;
|
|
1576
1640
|
case "bytes": {
|
|
1577
1641
|
let bytes;
|
|
1578
1642
|
if (value[1] instanceof Uint8Array) bytes = value[1];
|
|
@@ -1859,10 +1923,11 @@ function estimateEncodedSize(value, seen, depth = 0) {
|
|
|
1859
1923
|
var ImportTableEntry = class {
|
|
1860
1924
|
session;
|
|
1861
1925
|
importId;
|
|
1926
|
+
pulling;
|
|
1862
1927
|
constructor(session, importId, pulling) {
|
|
1863
1928
|
this.session = session;
|
|
1864
1929
|
this.importId = importId;
|
|
1865
|
-
|
|
1930
|
+
this.pulling = pulling;
|
|
1866
1931
|
}
|
|
1867
1932
|
localRefcount = 0;
|
|
1868
1933
|
remoteRefcount = 1;
|
|
@@ -1893,7 +1958,7 @@ var ImportTableEntry = class {
|
|
|
1893
1958
|
}
|
|
1894
1959
|
async awaitResolution() {
|
|
1895
1960
|
if (!this.activePull) {
|
|
1896
|
-
this.session.sendPull(this.importId);
|
|
1961
|
+
if (!this.pulling) this.session.sendPull(this.importId);
|
|
1897
1962
|
this.activePull = Promise.withResolvers();
|
|
1898
1963
|
}
|
|
1899
1964
|
await this.activePull.promise;
|
|
@@ -2123,6 +2188,7 @@ var RpcSessionImpl = class {
|
|
|
2123
2188
|
let autoRelease = exp.autoRelease;
|
|
2124
2189
|
++this.pullCount;
|
|
2125
2190
|
exp.pull = resolve().then((payload) => {
|
|
2191
|
+
if (this.exports[exportId] !== exp) return;
|
|
2126
2192
|
let value = Devaluator.devaluate(payload.value, void 0, this, payload, this.encodingLevel);
|
|
2127
2193
|
this.send([
|
|
2128
2194
|
"resolve",
|
|
@@ -2131,6 +2197,7 @@ var RpcSessionImpl = class {
|
|
|
2131
2197
|
]);
|
|
2132
2198
|
if (autoRelease) this.releaseExport(exportId, 1);
|
|
2133
2199
|
}, (error) => {
|
|
2200
|
+
if (this.exports[exportId] !== exp) return;
|
|
2134
2201
|
this.send([
|
|
2135
2202
|
"reject",
|
|
2136
2203
|
exportId,
|
|
@@ -2250,6 +2317,7 @@ var RpcSessionImpl = class {
|
|
|
2250
2317
|
value.push(devalue[0]);
|
|
2251
2318
|
}
|
|
2252
2319
|
this.send(["push", value]);
|
|
2320
|
+
args?.dispose();
|
|
2253
2321
|
let entry = new ImportTableEntry(this, this.imports.length, false);
|
|
2254
2322
|
this.imports.push(entry);
|
|
2255
2323
|
return new RpcImportHook(true, entry);
|
|
@@ -2274,6 +2342,7 @@ var RpcSessionImpl = class {
|
|
|
2274
2342
|
value.push(devalue[0]);
|
|
2275
2343
|
let msg = ["stream", value];
|
|
2276
2344
|
let size = this.send(msg);
|
|
2345
|
+
args.dispose();
|
|
2277
2346
|
if (size === void 0) size = estimateEncodedSize(msg);
|
|
2278
2347
|
let importId = this.imports.length;
|
|
2279
2348
|
let entry = new ImportTableEntry(this, importId, true);
|