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.d.cts
CHANGED
|
@@ -163,7 +163,9 @@ type TupleProvider<T extends ReadonlyArray<unknown>> = { [K in TupleIndexKeys<T>
|
|
|
163
163
|
// `__RPC_TARGET_BRAND` deliberately flows through the key mapping (as a `never` property) so
|
|
164
164
|
// stubs of branded targets stay assignable to workers-types' `Stubable`. Such stubs match our
|
|
165
165
|
// `Stubable` too — harmless, since all machinery checks `StubBase` before `Stubable`.
|
|
166
|
-
|
|
166
|
+
// Mapping over `keyof T` keeps "Go to Definition" working; `-?` because reading a stub
|
|
167
|
+
// member never yields `undefined`.
|
|
168
|
+
type Provider<T> = MaybeCallableProvider<T> & (T extends ReadonlyArray<unknown> ? number extends T["length"] ? ArrayProvider<T[number]> : TupleProvider<T> : Pick<{ [K in keyof T]-?: MethodOrProperty<T[K]>; }, Exclude<keyof T, symbol | keyof StubBase<never>>> & {
|
|
167
169
|
map<V>(callback: (value: MapCallbackValue<NonNullable<T>>) => MapCallbackReturn<V>): Result<Array<V>>;
|
|
168
170
|
});
|
|
169
171
|
//#endregion
|
package/dist/index-workers.d.ts
CHANGED
|
@@ -163,7 +163,9 @@ type TupleProvider<T extends ReadonlyArray<unknown>> = { [K in TupleIndexKeys<T>
|
|
|
163
163
|
// `__RPC_TARGET_BRAND` deliberately flows through the key mapping (as a `never` property) so
|
|
164
164
|
// stubs of branded targets stay assignable to workers-types' `Stubable`. Such stubs match our
|
|
165
165
|
// `Stubable` too — harmless, since all machinery checks `StubBase` before `Stubable`.
|
|
166
|
-
|
|
166
|
+
// Mapping over `keyof T` keeps "Go to Definition" working; `-?` because reading a stub
|
|
167
|
+
// member never yields `undefined`.
|
|
168
|
+
type Provider<T> = MaybeCallableProvider<T> & (T extends ReadonlyArray<unknown> ? number extends T["length"] ? ArrayProvider<T[number]> : TupleProvider<T> : Pick<{ [K in keyof T]-?: MethodOrProperty<T[K]>; }, Exclude<keyof T, symbol | keyof StubBase<never>>> & {
|
|
167
169
|
map<V>(callback: (value: MapCallbackValue<NonNullable<T>>) => MapCallbackReturn<V>): Result<Array<V>>;
|
|
168
170
|
});
|
|
169
171
|
//#endregion
|
package/dist/index-workers.js
CHANGED
|
@@ -48,6 +48,7 @@ function typeForRpc(value) {
|
|
|
48
48
|
case Date.prototype: return "date";
|
|
49
49
|
case RegExp.prototype: return "regexp";
|
|
50
50
|
case Set.prototype: return "set";
|
|
51
|
+
case Map.prototype: return "map";
|
|
51
52
|
case Uint8Array.prototype:
|
|
52
53
|
case BUFFER_PROTOTYPE:
|
|
53
54
|
case ArrayBuffer.prototype:
|
|
@@ -311,6 +312,9 @@ async function pullPromise(promise) {
|
|
|
311
312
|
if (pathIfPromise.length > 0) hook = hook.get(pathIfPromise);
|
|
312
313
|
return (await hook.pull()).deliverResolve();
|
|
313
314
|
}
|
|
315
|
+
function mapKeyToPropertyName(key) {
|
|
316
|
+
return typeof key === "string" || typeof key === "number" ? key : { mapKey: key };
|
|
317
|
+
}
|
|
314
318
|
var RpcPayload = class RpcPayload {
|
|
315
319
|
value;
|
|
316
320
|
source;
|
|
@@ -419,7 +423,7 @@ var RpcPayload = class RpcPayload {
|
|
|
419
423
|
return hook.dup();
|
|
420
424
|
} else return hook;
|
|
421
425
|
}
|
|
422
|
-
} else
|
|
426
|
+
} else return streamImpl.createReadableStreamHook(stream);
|
|
423
427
|
}
|
|
424
428
|
deepCopy(value, oldParent, property, parent, dupStubs, owner) {
|
|
425
429
|
switch (typeForRpc(value)) {
|
|
@@ -455,6 +459,20 @@ var RpcPayload = class RpcPayload {
|
|
|
455
459
|
}
|
|
456
460
|
return result;
|
|
457
461
|
}
|
|
462
|
+
case "map": {
|
|
463
|
+
let map = value;
|
|
464
|
+
let entries = [...map];
|
|
465
|
+
for (let [key] of entries) {
|
|
466
|
+
let kind = typeForRpc(key);
|
|
467
|
+
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.");
|
|
468
|
+
}
|
|
469
|
+
let result = /* @__PURE__ */ new Map();
|
|
470
|
+
for (let [key, val] of entries) {
|
|
471
|
+
let keyCopy = this.deepCopy(key, map, -1, result, dupStubs, owner);
|
|
472
|
+
result.set(keyCopy, this.deepCopy(val, map, mapKeyToPropertyName(keyCopy), result, dupStubs, owner));
|
|
473
|
+
}
|
|
474
|
+
return result;
|
|
475
|
+
}
|
|
458
476
|
case "object": {
|
|
459
477
|
let result = {};
|
|
460
478
|
let object = value;
|
|
@@ -512,8 +530,10 @@ var RpcPayload = class RpcPayload {
|
|
|
512
530
|
case "readable": {
|
|
513
531
|
let stream = value;
|
|
514
532
|
let hook;
|
|
515
|
-
if (owner)
|
|
516
|
-
|
|
533
|
+
if (owner) {
|
|
534
|
+
if (owner.source === "owned") throw new Error("Can't copy a ReadableStream.");
|
|
535
|
+
hook = owner.getHookForReadableStream(stream, oldParent, dupStubs);
|
|
536
|
+
} else hook = streamImpl.createReadableStreamHook(stream);
|
|
517
537
|
this.hooks.push(hook);
|
|
518
538
|
return stream;
|
|
519
539
|
}
|
|
@@ -556,7 +576,8 @@ var RpcPayload = class RpcPayload {
|
|
|
556
576
|
this.ensureDeepCopied();
|
|
557
577
|
if (this.value instanceof RpcPromise$1) RpcPayload.deliverRpcPromiseTo(this.value, parent, property, promises);
|
|
558
578
|
else {
|
|
559
|
-
parent
|
|
579
|
+
if (parent instanceof Map) parent.set(typeof property === "object" ? property.mapKey : property, this.value);
|
|
580
|
+
else parent[property] = this.value;
|
|
560
581
|
for (let record of this.promises) RpcPayload.deliverRpcPromiseTo(record.promise, record.parent, record.property, promises);
|
|
561
582
|
}
|
|
562
583
|
}
|
|
@@ -662,6 +683,14 @@ var RpcPayload = class RpcPayload {
|
|
|
662
683
|
for (let element of set) this.disposeImpl(element, set);
|
|
663
684
|
return;
|
|
664
685
|
}
|
|
686
|
+
case "map": {
|
|
687
|
+
let map = value;
|
|
688
|
+
for (let [key, val] of map) {
|
|
689
|
+
this.disposeImpl(key, map);
|
|
690
|
+
this.disposeImpl(val, map);
|
|
691
|
+
}
|
|
692
|
+
return;
|
|
693
|
+
}
|
|
665
694
|
case "object": {
|
|
666
695
|
let object = value;
|
|
667
696
|
for (let i in object) this.disposeImpl(object[i], object);
|
|
@@ -752,6 +781,14 @@ var RpcPayload = class RpcPayload {
|
|
|
752
781
|
for (let element of set) this.ignoreUnhandledRejectionsImpl(element);
|
|
753
782
|
return;
|
|
754
783
|
}
|
|
784
|
+
case "map": {
|
|
785
|
+
let map = value;
|
|
786
|
+
for (let [key, val] of map) {
|
|
787
|
+
this.ignoreUnhandledRejectionsImpl(key);
|
|
788
|
+
this.ignoreUnhandledRejectionsImpl(val);
|
|
789
|
+
}
|
|
790
|
+
return;
|
|
791
|
+
}
|
|
755
792
|
case "object": {
|
|
756
793
|
let object = value;
|
|
757
794
|
for (let i in object) this.ignoreUnhandledRejectionsImpl(object[i]);
|
|
@@ -812,6 +849,7 @@ function followPath(value, parent, path, owner) {
|
|
|
812
849
|
case "blob":
|
|
813
850
|
case "date":
|
|
814
851
|
case "set":
|
|
852
|
+
case "map":
|
|
815
853
|
case "error":
|
|
816
854
|
case "url":
|
|
817
855
|
case "regexp":
|
|
@@ -1218,6 +1256,18 @@ var Devaluator = class Devaluator {
|
|
|
1218
1256
|
for (let element of setElements) elements.push(this.devaluateImpl(element, set, depth + 1));
|
|
1219
1257
|
return ["set", elements];
|
|
1220
1258
|
}
|
|
1259
|
+
case "map": {
|
|
1260
|
+
let map = value;
|
|
1261
|
+
let mapEntries = [...map];
|
|
1262
|
+
let entries = [];
|
|
1263
|
+
for (let [key] of mapEntries) switch (typeForRpc(key)) {
|
|
1264
|
+
case "blob": throw new TypeError("Cannot serialize a Blob as a key of a Map.");
|
|
1265
|
+
case "rpc-promise":
|
|
1266
|
+
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.");
|
|
1267
|
+
}
|
|
1268
|
+
for (let [key, val] of mapEntries) entries.push([this.devaluateImpl(key, map, depth + 1), this.devaluateImpl(val, map, depth + 1)]);
|
|
1269
|
+
return ["map", entries];
|
|
1270
|
+
}
|
|
1221
1271
|
case "bigint":
|
|
1222
1272
|
if (this.encodingLevel === "structuredClonable") return value;
|
|
1223
1273
|
return ["bigint", value.toString()];
|
|
@@ -1544,6 +1594,20 @@ var Evaluator = class Evaluator {
|
|
|
1544
1594
|
return set;
|
|
1545
1595
|
}
|
|
1546
1596
|
break;
|
|
1597
|
+
case "map":
|
|
1598
|
+
if (value.length === 2 && value[1] instanceof Array) {
|
|
1599
|
+
let entries = value[1];
|
|
1600
|
+
let map = /* @__PURE__ */ new Map();
|
|
1601
|
+
for (let i = 0; i < entries.length; i++) {
|
|
1602
|
+
let entry = entries[i];
|
|
1603
|
+
if (!(entry instanceof Array) || entry.length !== 2) throw new TypeError("Map entries must be serialized as key/value pairs.");
|
|
1604
|
+
let key = this.evaluateImpl(entry[0], map, i, depth + 1);
|
|
1605
|
+
if (key instanceof RpcPromise$1) throw new TypeError("Cannot deserialize a promise as a key of a Map.");
|
|
1606
|
+
map.set(key, this.evaluateImpl(entry[1], map, mapKeyToPropertyName(key), depth + 1));
|
|
1607
|
+
}
|
|
1608
|
+
return map;
|
|
1609
|
+
}
|
|
1610
|
+
break;
|
|
1547
1611
|
case "bytes": {
|
|
1548
1612
|
let bytes;
|
|
1549
1613
|
if (value[1] instanceof Uint8Array) bytes = value[1];
|
|
@@ -1830,10 +1894,11 @@ function estimateEncodedSize(value, seen, depth = 0) {
|
|
|
1830
1894
|
var ImportTableEntry = class {
|
|
1831
1895
|
session;
|
|
1832
1896
|
importId;
|
|
1897
|
+
pulling;
|
|
1833
1898
|
constructor(session, importId, pulling) {
|
|
1834
1899
|
this.session = session;
|
|
1835
1900
|
this.importId = importId;
|
|
1836
|
-
|
|
1901
|
+
this.pulling = pulling;
|
|
1837
1902
|
}
|
|
1838
1903
|
localRefcount = 0;
|
|
1839
1904
|
remoteRefcount = 1;
|
|
@@ -1864,7 +1929,7 @@ var ImportTableEntry = class {
|
|
|
1864
1929
|
}
|
|
1865
1930
|
async awaitResolution() {
|
|
1866
1931
|
if (!this.activePull) {
|
|
1867
|
-
this.session.sendPull(this.importId);
|
|
1932
|
+
if (!this.pulling) this.session.sendPull(this.importId);
|
|
1868
1933
|
this.activePull = Promise.withResolvers();
|
|
1869
1934
|
}
|
|
1870
1935
|
await this.activePull.promise;
|
|
@@ -2094,6 +2159,7 @@ var RpcSessionImpl = class {
|
|
|
2094
2159
|
let autoRelease = exp.autoRelease;
|
|
2095
2160
|
++this.pullCount;
|
|
2096
2161
|
exp.pull = resolve().then((payload) => {
|
|
2162
|
+
if (this.exports[exportId] !== exp) return;
|
|
2097
2163
|
let value = Devaluator.devaluate(payload.value, void 0, this, payload, this.encodingLevel);
|
|
2098
2164
|
this.send([
|
|
2099
2165
|
"resolve",
|
|
@@ -2102,6 +2168,7 @@ var RpcSessionImpl = class {
|
|
|
2102
2168
|
]);
|
|
2103
2169
|
if (autoRelease) this.releaseExport(exportId, 1);
|
|
2104
2170
|
}, (error) => {
|
|
2171
|
+
if (this.exports[exportId] !== exp) return;
|
|
2105
2172
|
this.send([
|
|
2106
2173
|
"reject",
|
|
2107
2174
|
exportId,
|
|
@@ -2221,6 +2288,7 @@ var RpcSessionImpl = class {
|
|
|
2221
2288
|
value.push(devalue[0]);
|
|
2222
2289
|
}
|
|
2223
2290
|
this.send(["push", value]);
|
|
2291
|
+
args?.dispose();
|
|
2224
2292
|
let entry = new ImportTableEntry(this, this.imports.length, false);
|
|
2225
2293
|
this.imports.push(entry);
|
|
2226
2294
|
return new RpcImportHook(true, entry);
|
|
@@ -2245,6 +2313,7 @@ var RpcSessionImpl = class {
|
|
|
2245
2313
|
value.push(devalue[0]);
|
|
2246
2314
|
let msg = ["stream", value];
|
|
2247
2315
|
let size = this.send(msg);
|
|
2316
|
+
args.dispose();
|
|
2248
2317
|
if (size === void 0) size = estimateEncodedSize(msg);
|
|
2249
2318
|
let importId = this.imports.length;
|
|
2250
2319
|
let entry = new ImportTableEntry(this, importId, true);
|