capnweb 0.0.0-098dca7 → 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.
@@ -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
- 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>>> & {
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
@@ -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
- 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>>> & {
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
@@ -423,7 +423,7 @@ var RpcPayload = class RpcPayload {
423
423
  return hook.dup();
424
424
  } else return hook;
425
425
  }
426
- } else throw new Error("owned payload shouldn't contain raw ReadableStreams");
426
+ } else return streamImpl.createReadableStreamHook(stream);
427
427
  }
428
428
  deepCopy(value, oldParent, property, parent, dupStubs, owner) {
429
429
  switch (typeForRpc(value)) {
@@ -530,8 +530,10 @@ var RpcPayload = class RpcPayload {
530
530
  case "readable": {
531
531
  let stream = value;
532
532
  let hook;
533
- if (owner) hook = owner.getHookForReadableStream(stream, oldParent, dupStubs);
534
- else hook = streamImpl.createReadableStreamHook(stream);
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);
535
537
  this.hooks.push(hook);
536
538
  return stream;
537
539
  }
@@ -1892,10 +1894,11 @@ function estimateEncodedSize(value, seen, depth = 0) {
1892
1894
  var ImportTableEntry = class {
1893
1895
  session;
1894
1896
  importId;
1897
+ pulling;
1895
1898
  constructor(session, importId, pulling) {
1896
1899
  this.session = session;
1897
1900
  this.importId = importId;
1898
- if (pulling) this.activePull = Promise.withResolvers();
1901
+ this.pulling = pulling;
1899
1902
  }
1900
1903
  localRefcount = 0;
1901
1904
  remoteRefcount = 1;
@@ -1926,7 +1929,7 @@ var ImportTableEntry = class {
1926
1929
  }
1927
1930
  async awaitResolution() {
1928
1931
  if (!this.activePull) {
1929
- this.session.sendPull(this.importId);
1932
+ if (!this.pulling) this.session.sendPull(this.importId);
1930
1933
  this.activePull = Promise.withResolvers();
1931
1934
  }
1932
1935
  await this.activePull.promise;
@@ -2156,6 +2159,7 @@ var RpcSessionImpl = class {
2156
2159
  let autoRelease = exp.autoRelease;
2157
2160
  ++this.pullCount;
2158
2161
  exp.pull = resolve().then((payload) => {
2162
+ if (this.exports[exportId] !== exp) return;
2159
2163
  let value = Devaluator.devaluate(payload.value, void 0, this, payload, this.encodingLevel);
2160
2164
  this.send([
2161
2165
  "resolve",
@@ -2164,6 +2168,7 @@ var RpcSessionImpl = class {
2164
2168
  ]);
2165
2169
  if (autoRelease) this.releaseExport(exportId, 1);
2166
2170
  }, (error) => {
2171
+ if (this.exports[exportId] !== exp) return;
2167
2172
  this.send([
2168
2173
  "reject",
2169
2174
  exportId,
@@ -2283,6 +2288,7 @@ var RpcSessionImpl = class {
2283
2288
  value.push(devalue[0]);
2284
2289
  }
2285
2290
  this.send(["push", value]);
2291
+ args?.dispose();
2286
2292
  let entry = new ImportTableEntry(this, this.imports.length, false);
2287
2293
  this.imports.push(entry);
2288
2294
  return new RpcImportHook(true, entry);
@@ -2307,6 +2313,7 @@ var RpcSessionImpl = class {
2307
2313
  value.push(devalue[0]);
2308
2314
  let msg = ["stream", value];
2309
2315
  let size = this.send(msg);
2316
+ args.dispose();
2310
2317
  if (size === void 0) size = estimateEncodedSize(msg);
2311
2318
  let importId = this.imports.length;
2312
2319
  let entry = new ImportTableEntry(this, importId, true);