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-bun.d.cts
CHANGED
|
@@ -164,7 +164,9 @@ type TupleProvider<T extends ReadonlyArray<unknown>> = { [K in TupleIndexKeys<T>
|
|
|
164
164
|
// `__RPC_TARGET_BRAND` deliberately flows through the key mapping (as a `never` property) so
|
|
165
165
|
// stubs of branded targets stay assignable to workers-types' `Stubable`. Such stubs match our
|
|
166
166
|
// `Stubable` too — harmless, since all machinery checks `StubBase` before `Stubable`.
|
|
167
|
-
|
|
167
|
+
// Mapping over `keyof T` keeps "Go to Definition" working; `-?` because reading a stub
|
|
168
|
+
// member never yields `undefined`.
|
|
169
|
+
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>>> & {
|
|
168
170
|
map<V>(callback: (value: MapCallbackValue<NonNullable<T>>) => MapCallbackReturn<V>): Result<Array<V>>;
|
|
169
171
|
});
|
|
170
172
|
//#endregion
|
|
@@ -207,9 +209,12 @@ declare class RpcPromise$1 extends RpcStub$1 {
|
|
|
207
209
|
finally(onfinally?: (() => void) | undefined | null): Promise<unknown>;
|
|
208
210
|
toString(): string;
|
|
209
211
|
}
|
|
212
|
+
type PropertyName = string | number | {
|
|
213
|
+
mapKey: unknown;
|
|
214
|
+
};
|
|
210
215
|
type LocatedPromise = {
|
|
211
216
|
parent: object;
|
|
212
|
-
property:
|
|
217
|
+
property: PropertyName;
|
|
213
218
|
promise: RpcPromise$1;
|
|
214
219
|
};
|
|
215
220
|
declare class RpcPayload {
|
package/dist/index-bun.d.ts
CHANGED
|
@@ -164,7 +164,9 @@ type TupleProvider<T extends ReadonlyArray<unknown>> = { [K in TupleIndexKeys<T>
|
|
|
164
164
|
// `__RPC_TARGET_BRAND` deliberately flows through the key mapping (as a `never` property) so
|
|
165
165
|
// stubs of branded targets stay assignable to workers-types' `Stubable`. Such stubs match our
|
|
166
166
|
// `Stubable` too — harmless, since all machinery checks `StubBase` before `Stubable`.
|
|
167
|
-
|
|
167
|
+
// Mapping over `keyof T` keeps "Go to Definition" working; `-?` because reading a stub
|
|
168
|
+
// member never yields `undefined`.
|
|
169
|
+
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>>> & {
|
|
168
170
|
map<V>(callback: (value: MapCallbackValue<NonNullable<T>>) => MapCallbackReturn<V>): Result<Array<V>>;
|
|
169
171
|
});
|
|
170
172
|
//#endregion
|
|
@@ -207,9 +209,12 @@ declare class RpcPromise$1 extends RpcStub$1 {
|
|
|
207
209
|
finally(onfinally?: (() => void) | undefined | null): Promise<unknown>;
|
|
208
210
|
toString(): string;
|
|
209
211
|
}
|
|
212
|
+
type PropertyName = string | number | {
|
|
213
|
+
mapKey: unknown;
|
|
214
|
+
};
|
|
210
215
|
type LocatedPromise = {
|
|
211
216
|
parent: object;
|
|
212
|
-
property:
|
|
217
|
+
property: PropertyName;
|
|
213
218
|
promise: RpcPromise$1;
|
|
214
219
|
};
|
|
215
220
|
declare class RpcPayload {
|
package/dist/index-bun.js
CHANGED
|
@@ -42,6 +42,7 @@ function typeForRpc(value) {
|
|
|
42
42
|
case Date.prototype: return "date";
|
|
43
43
|
case RegExp.prototype: return "regexp";
|
|
44
44
|
case Set.prototype: return "set";
|
|
45
|
+
case Map.prototype: return "map";
|
|
45
46
|
case Uint8Array.prototype:
|
|
46
47
|
case BUFFER_PROTOTYPE:
|
|
47
48
|
case ArrayBuffer.prototype:
|
|
@@ -305,6 +306,9 @@ async function pullPromise(promise) {
|
|
|
305
306
|
if (pathIfPromise.length > 0) hook = hook.get(pathIfPromise);
|
|
306
307
|
return (await hook.pull()).deliverResolve();
|
|
307
308
|
}
|
|
309
|
+
function mapKeyToPropertyName(key) {
|
|
310
|
+
return typeof key === "string" || typeof key === "number" ? key : { mapKey: key };
|
|
311
|
+
}
|
|
308
312
|
var RpcPayload = class RpcPayload {
|
|
309
313
|
value;
|
|
310
314
|
source;
|
|
@@ -413,7 +417,7 @@ var RpcPayload = class RpcPayload {
|
|
|
413
417
|
return hook.dup();
|
|
414
418
|
} else return hook;
|
|
415
419
|
}
|
|
416
|
-
} else
|
|
420
|
+
} else return streamImpl.createReadableStreamHook(stream);
|
|
417
421
|
}
|
|
418
422
|
deepCopy(value, oldParent, property, parent, dupStubs, owner) {
|
|
419
423
|
switch (typeForRpc(value)) {
|
|
@@ -449,6 +453,20 @@ var RpcPayload = class RpcPayload {
|
|
|
449
453
|
}
|
|
450
454
|
return result;
|
|
451
455
|
}
|
|
456
|
+
case "map": {
|
|
457
|
+
let map = value;
|
|
458
|
+
let entries = [...map];
|
|
459
|
+
for (let [key] of entries) {
|
|
460
|
+
let kind = typeForRpc(key);
|
|
461
|
+
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.");
|
|
462
|
+
}
|
|
463
|
+
let result = /* @__PURE__ */ new Map();
|
|
464
|
+
for (let [key, val] of entries) {
|
|
465
|
+
let keyCopy = this.deepCopy(key, map, -1, result, dupStubs, owner);
|
|
466
|
+
result.set(keyCopy, this.deepCopy(val, map, mapKeyToPropertyName(keyCopy), result, dupStubs, owner));
|
|
467
|
+
}
|
|
468
|
+
return result;
|
|
469
|
+
}
|
|
452
470
|
case "object": {
|
|
453
471
|
let result = {};
|
|
454
472
|
let object = value;
|
|
@@ -506,8 +524,10 @@ var RpcPayload = class RpcPayload {
|
|
|
506
524
|
case "readable": {
|
|
507
525
|
let stream = value;
|
|
508
526
|
let hook;
|
|
509
|
-
if (owner)
|
|
510
|
-
|
|
527
|
+
if (owner) {
|
|
528
|
+
if (owner.source === "owned") throw new Error("Can't copy a ReadableStream.");
|
|
529
|
+
hook = owner.getHookForReadableStream(stream, oldParent, dupStubs);
|
|
530
|
+
} else hook = streamImpl.createReadableStreamHook(stream);
|
|
511
531
|
this.hooks.push(hook);
|
|
512
532
|
return stream;
|
|
513
533
|
}
|
|
@@ -550,7 +570,8 @@ var RpcPayload = class RpcPayload {
|
|
|
550
570
|
this.ensureDeepCopied();
|
|
551
571
|
if (this.value instanceof RpcPromise$1) RpcPayload.deliverRpcPromiseTo(this.value, parent, property, promises);
|
|
552
572
|
else {
|
|
553
|
-
parent
|
|
573
|
+
if (parent instanceof Map) parent.set(typeof property === "object" ? property.mapKey : property, this.value);
|
|
574
|
+
else parent[property] = this.value;
|
|
554
575
|
for (let record of this.promises) RpcPayload.deliverRpcPromiseTo(record.promise, record.parent, record.property, promises);
|
|
555
576
|
}
|
|
556
577
|
}
|
|
@@ -656,6 +677,14 @@ var RpcPayload = class RpcPayload {
|
|
|
656
677
|
for (let element of set) this.disposeImpl(element, set);
|
|
657
678
|
return;
|
|
658
679
|
}
|
|
680
|
+
case "map": {
|
|
681
|
+
let map = value;
|
|
682
|
+
for (let [key, val] of map) {
|
|
683
|
+
this.disposeImpl(key, map);
|
|
684
|
+
this.disposeImpl(val, map);
|
|
685
|
+
}
|
|
686
|
+
return;
|
|
687
|
+
}
|
|
659
688
|
case "object": {
|
|
660
689
|
let object = value;
|
|
661
690
|
for (let i in object) this.disposeImpl(object[i], object);
|
|
@@ -746,6 +775,14 @@ var RpcPayload = class RpcPayload {
|
|
|
746
775
|
for (let element of set) this.ignoreUnhandledRejectionsImpl(element);
|
|
747
776
|
return;
|
|
748
777
|
}
|
|
778
|
+
case "map": {
|
|
779
|
+
let map = value;
|
|
780
|
+
for (let [key, val] of map) {
|
|
781
|
+
this.ignoreUnhandledRejectionsImpl(key);
|
|
782
|
+
this.ignoreUnhandledRejectionsImpl(val);
|
|
783
|
+
}
|
|
784
|
+
return;
|
|
785
|
+
}
|
|
749
786
|
case "object": {
|
|
750
787
|
let object = value;
|
|
751
788
|
for (let i in object) this.ignoreUnhandledRejectionsImpl(object[i]);
|
|
@@ -806,6 +843,7 @@ function followPath(value, parent, path, owner) {
|
|
|
806
843
|
case "blob":
|
|
807
844
|
case "date":
|
|
808
845
|
case "set":
|
|
846
|
+
case "map":
|
|
809
847
|
case "error":
|
|
810
848
|
case "url":
|
|
811
849
|
case "regexp":
|
|
@@ -1212,6 +1250,18 @@ var Devaluator = class Devaluator {
|
|
|
1212
1250
|
for (let element of setElements) elements.push(this.devaluateImpl(element, set, depth + 1));
|
|
1213
1251
|
return ["set", elements];
|
|
1214
1252
|
}
|
|
1253
|
+
case "map": {
|
|
1254
|
+
let map = value;
|
|
1255
|
+
let mapEntries = [...map];
|
|
1256
|
+
let entries = [];
|
|
1257
|
+
for (let [key] of mapEntries) switch (typeForRpc(key)) {
|
|
1258
|
+
case "blob": throw new TypeError("Cannot serialize a Blob as a key of a Map.");
|
|
1259
|
+
case "rpc-promise":
|
|
1260
|
+
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.");
|
|
1261
|
+
}
|
|
1262
|
+
for (let [key, val] of mapEntries) entries.push([this.devaluateImpl(key, map, depth + 1), this.devaluateImpl(val, map, depth + 1)]);
|
|
1263
|
+
return ["map", entries];
|
|
1264
|
+
}
|
|
1215
1265
|
case "bigint":
|
|
1216
1266
|
if (this.encodingLevel === "structuredClonable") return value;
|
|
1217
1267
|
return ["bigint", value.toString()];
|
|
@@ -1538,6 +1588,20 @@ var Evaluator = class Evaluator {
|
|
|
1538
1588
|
return set;
|
|
1539
1589
|
}
|
|
1540
1590
|
break;
|
|
1591
|
+
case "map":
|
|
1592
|
+
if (value.length === 2 && value[1] instanceof Array) {
|
|
1593
|
+
let entries = value[1];
|
|
1594
|
+
let map = /* @__PURE__ */ new Map();
|
|
1595
|
+
for (let i = 0; i < entries.length; i++) {
|
|
1596
|
+
let entry = entries[i];
|
|
1597
|
+
if (!(entry instanceof Array) || entry.length !== 2) throw new TypeError("Map entries must be serialized as key/value pairs.");
|
|
1598
|
+
let key = this.evaluateImpl(entry[0], map, i, depth + 1);
|
|
1599
|
+
if (key instanceof RpcPromise$1) throw new TypeError("Cannot deserialize a promise as a key of a Map.");
|
|
1600
|
+
map.set(key, this.evaluateImpl(entry[1], map, mapKeyToPropertyName(key), depth + 1));
|
|
1601
|
+
}
|
|
1602
|
+
return map;
|
|
1603
|
+
}
|
|
1604
|
+
break;
|
|
1541
1605
|
case "bytes": {
|
|
1542
1606
|
let bytes;
|
|
1543
1607
|
if (value[1] instanceof Uint8Array) bytes = value[1];
|
|
@@ -1824,10 +1888,11 @@ function estimateEncodedSize(value, seen, depth = 0) {
|
|
|
1824
1888
|
var ImportTableEntry = class {
|
|
1825
1889
|
session;
|
|
1826
1890
|
importId;
|
|
1891
|
+
pulling;
|
|
1827
1892
|
constructor(session, importId, pulling) {
|
|
1828
1893
|
this.session = session;
|
|
1829
1894
|
this.importId = importId;
|
|
1830
|
-
|
|
1895
|
+
this.pulling = pulling;
|
|
1831
1896
|
}
|
|
1832
1897
|
localRefcount = 0;
|
|
1833
1898
|
remoteRefcount = 1;
|
|
@@ -1858,7 +1923,7 @@ var ImportTableEntry = class {
|
|
|
1858
1923
|
}
|
|
1859
1924
|
async awaitResolution() {
|
|
1860
1925
|
if (!this.activePull) {
|
|
1861
|
-
this.session.sendPull(this.importId);
|
|
1926
|
+
if (!this.pulling) this.session.sendPull(this.importId);
|
|
1862
1927
|
this.activePull = Promise.withResolvers();
|
|
1863
1928
|
}
|
|
1864
1929
|
await this.activePull.promise;
|
|
@@ -2088,6 +2153,7 @@ var RpcSessionImpl = class {
|
|
|
2088
2153
|
let autoRelease = exp.autoRelease;
|
|
2089
2154
|
++this.pullCount;
|
|
2090
2155
|
exp.pull = resolve().then((payload) => {
|
|
2156
|
+
if (this.exports[exportId] !== exp) return;
|
|
2091
2157
|
let value = Devaluator.devaluate(payload.value, void 0, this, payload, this.encodingLevel);
|
|
2092
2158
|
this.send([
|
|
2093
2159
|
"resolve",
|
|
@@ -2096,6 +2162,7 @@ var RpcSessionImpl = class {
|
|
|
2096
2162
|
]);
|
|
2097
2163
|
if (autoRelease) this.releaseExport(exportId, 1);
|
|
2098
2164
|
}, (error) => {
|
|
2165
|
+
if (this.exports[exportId] !== exp) return;
|
|
2099
2166
|
this.send([
|
|
2100
2167
|
"reject",
|
|
2101
2168
|
exportId,
|
|
@@ -2215,6 +2282,7 @@ var RpcSessionImpl = class {
|
|
|
2215
2282
|
value.push(devalue[0]);
|
|
2216
2283
|
}
|
|
2217
2284
|
this.send(["push", value]);
|
|
2285
|
+
args?.dispose();
|
|
2218
2286
|
let entry = new ImportTableEntry(this, this.imports.length, false);
|
|
2219
2287
|
this.imports.push(entry);
|
|
2220
2288
|
return new RpcImportHook(true, entry);
|
|
@@ -2239,6 +2307,7 @@ var RpcSessionImpl = class {
|
|
|
2239
2307
|
value.push(devalue[0]);
|
|
2240
2308
|
let msg = ["stream", value];
|
|
2241
2309
|
let size = this.send(msg);
|
|
2310
|
+
args.dispose();
|
|
2242
2311
|
if (size === void 0) size = estimateEncodedSize(msg);
|
|
2243
2312
|
let importId = this.imports.length;
|
|
2244
2313
|
let entry = new ImportTableEntry(this, importId, true);
|