capnweb 0.10.0 → 0.11.1

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.d.cts CHANGED
@@ -39,8 +39,9 @@ interface StubBase<T = unknown> extends Disposable {
39
39
  }
40
40
  type Stub<T extends RpcCompatible<T>> = T extends object ? Provider<T> & StubBase<T> : StubBase<T>;
41
41
  type TypedArray = Uint8Array | Uint8ClampedArray | Uint16Array | Uint32Array | Int8Array | Int16Array | Int32Array | BigUint64Array | BigInt64Array | Float32Array | Float64Array; // This represents all the types that can be sent as-is over an RPC boundary
42
- type BaseType = void | undefined | null | boolean | number | bigint | string | TypedArray | ArrayBuffer | DataView | Date | Error | RegExp | Blob | ReadableStream<Uint8Array> | WritableStream<any> // Chunk type can be any RPC-compatible type
43
- | Request | Response | Headers; // Recursively rewrite all `Stubable` types with `Stub`s, and resolve promises.
42
+ type BaseType = void | undefined | null | boolean | number | bigint | string | TypedArray | ArrayBuffer | DataView | Date | Error | RegExp | Blob | ReadableStream<any> // Chunk type can be any RPC-compatible type
43
+ | WritableStream<any> // Chunk type can be any RPC-compatible type
44
+ | URL | Request | Response | Headers; // Recursively rewrite all `Stubable` types with `Stub`s, and resolve promises.
44
45
  // prettier-ignore
45
46
  type Stubify<T> = T extends Stubable ? Stub<T> : T extends Promise<infer U> ? Stubify<U> : T extends StubBase<any> ? T : T extends Map<infer K, infer V> ? Map<Stubify<K>, Stubify<V>> : T extends Set<infer V> ? Set<Stubify<V>> : T extends [] ? [] : T extends [infer Head, ...infer Tail] ? [Stubify<Head>, ...Stubify<Tail>] : T extends readonly [] ? readonly [] : T extends readonly [infer Head, ...infer Tail] ? readonly [Stubify<Head>, ...Stubify<Tail>] : T extends Array<infer V> ? Array<Stubify<V>> : T extends ReadonlyArray<infer V> ? ReadonlyArray<Stubify<V>> : T extends BaseType ? T // When using "unknown" instead of "any", interfaces are not stubified.
46
47
  : T extends {
@@ -69,7 +70,13 @@ interface MapValuePlaceholder<T> {
69
70
  }
70
71
  type NonStubMembers<T> = Exclude<T, StubBase<any>>; // Utility type for adding `Disposable`s to `object` types only.
71
72
  // Note `unknown & T` is equivalent to `T`.
72
- type MaybeDisposable<T> = T extends object ? Disposable : unknown; // Type for method return or property on an RPC interface.
73
+ type MaybeDisposable<T> = T extends object ? Disposable : unknown; // The type behind the public `RpcPromise` (re-exported with its `RpcCompatible` constraint from
74
+ // index.ts). Defined here so that `Result`'s arms below resolve to the exact same alias
75
+ // instantiation: when both sides of an assignability check are the same alias applied to the
76
+ // same type arguments, the checker short-circuits on identity instead of recursing through the
77
+ // full structural comparison of these mutually-recursive types.
78
+ type RpcPromise$1<T> = T extends Stubable ? Promise<Stub<T>> & Provider<T> & StubBase<T> : Promise<Stubify<T> & MaybeDisposable<T>> & Provider<T> & StubBase<T>;
79
+ // Type for method return or property on an RPC interface.
73
80
  // - Stubable types are replaced by stubs.
74
81
  // - RpcCompatible types are passed by value, with stubable types replaced by stubs
75
82
  // and a top-level `Disposer`.
@@ -77,7 +84,7 @@ type MaybeDisposable<T> = T extends object ? Disposable : unknown; // Type for m
77
84
  // Technically, we use custom thenables here, but they quack like `Promise`s.
78
85
  // Intersecting with `(Maybe)Provider` allows pipelining.
79
86
  // prettier-ignore
80
- type Result<R> = IsAny<R> extends true ? UnknownResult : IsUnknown<R> extends true ? UnknownResult : R extends Stubable ? Promise<Stub<R>> & Provider<R> & StubBase<R> : R extends RpcCompatible<R> ? Promise<Stubify<R> & MaybeDisposable<R>> & Provider<R> & StubBase<R> : never;
87
+ type Result<R> = IsAny<R> extends true ? UnknownResult : IsUnknown<R> extends true ? UnknownResult : R extends Stubable ? RpcPromise$1<R> : R extends RpcCompatible<R> ? RpcPromise$1<R> : never;
81
88
  type IsAny<T> = 0 extends (1 & T) ? true : false;
82
89
  type UnknownResult = Promise<unknown> & Provider<unknown> & StubBase<unknown>; // Type for method or property on an RPC interface.
83
90
  // For methods, unwrap `Stub`s in parameters, and rewrite returns to be `Result`s.
@@ -321,7 +328,7 @@ declare const RpcStub: {
321
328
  * if you only intend to use the promise for pipelining and you never await it, then there's no
322
329
  * need to transmit the resolution!
323
330
  */
324
- type RpcPromise<T extends RpcCompatible<T>> = Stub<T> & Promise<Stubify<T>>;
331
+ type RpcPromise<T extends RpcCompatible<T>> = RpcPromise$1<T>;
325
332
  declare const RpcPromise: {};
326
333
  /**
327
334
  * Use to construct an `RpcSession` on top of a custom `RpcTransport`.
package/dist/index.d.ts CHANGED
@@ -39,8 +39,9 @@ interface StubBase<T = unknown> extends Disposable {
39
39
  }
40
40
  type Stub<T extends RpcCompatible<T>> = T extends object ? Provider<T> & StubBase<T> : StubBase<T>;
41
41
  type TypedArray = Uint8Array | Uint8ClampedArray | Uint16Array | Uint32Array | Int8Array | Int16Array | Int32Array | BigUint64Array | BigInt64Array | Float32Array | Float64Array; // This represents all the types that can be sent as-is over an RPC boundary
42
- type BaseType = void | undefined | null | boolean | number | bigint | string | TypedArray | ArrayBuffer | DataView | Date | Error | RegExp | Blob | ReadableStream<Uint8Array> | WritableStream<any> // Chunk type can be any RPC-compatible type
43
- | Request | Response | Headers; // Recursively rewrite all `Stubable` types with `Stub`s, and resolve promises.
42
+ type BaseType = void | undefined | null | boolean | number | bigint | string | TypedArray | ArrayBuffer | DataView | Date | Error | RegExp | Blob | ReadableStream<any> // Chunk type can be any RPC-compatible type
43
+ | WritableStream<any> // Chunk type can be any RPC-compatible type
44
+ | URL | Request | Response | Headers; // Recursively rewrite all `Stubable` types with `Stub`s, and resolve promises.
44
45
  // prettier-ignore
45
46
  type Stubify<T> = T extends Stubable ? Stub<T> : T extends Promise<infer U> ? Stubify<U> : T extends StubBase<any> ? T : T extends Map<infer K, infer V> ? Map<Stubify<K>, Stubify<V>> : T extends Set<infer V> ? Set<Stubify<V>> : T extends [] ? [] : T extends [infer Head, ...infer Tail] ? [Stubify<Head>, ...Stubify<Tail>] : T extends readonly [] ? readonly [] : T extends readonly [infer Head, ...infer Tail] ? readonly [Stubify<Head>, ...Stubify<Tail>] : T extends Array<infer V> ? Array<Stubify<V>> : T extends ReadonlyArray<infer V> ? ReadonlyArray<Stubify<V>> : T extends BaseType ? T // When using "unknown" instead of "any", interfaces are not stubified.
46
47
  : T extends {
@@ -69,7 +70,13 @@ interface MapValuePlaceholder<T> {
69
70
  }
70
71
  type NonStubMembers<T> = Exclude<T, StubBase<any>>; // Utility type for adding `Disposable`s to `object` types only.
71
72
  // Note `unknown & T` is equivalent to `T`.
72
- type MaybeDisposable<T> = T extends object ? Disposable : unknown; // Type for method return or property on an RPC interface.
73
+ type MaybeDisposable<T> = T extends object ? Disposable : unknown; // The type behind the public `RpcPromise` (re-exported with its `RpcCompatible` constraint from
74
+ // index.ts). Defined here so that `Result`'s arms below resolve to the exact same alias
75
+ // instantiation: when both sides of an assignability check are the same alias applied to the
76
+ // same type arguments, the checker short-circuits on identity instead of recursing through the
77
+ // full structural comparison of these mutually-recursive types.
78
+ type RpcPromise$1<T> = T extends Stubable ? Promise<Stub<T>> & Provider<T> & StubBase<T> : Promise<Stubify<T> & MaybeDisposable<T>> & Provider<T> & StubBase<T>;
79
+ // Type for method return or property on an RPC interface.
73
80
  // - Stubable types are replaced by stubs.
74
81
  // - RpcCompatible types are passed by value, with stubable types replaced by stubs
75
82
  // and a top-level `Disposer`.
@@ -77,7 +84,7 @@ type MaybeDisposable<T> = T extends object ? Disposable : unknown; // Type for m
77
84
  // Technically, we use custom thenables here, but they quack like `Promise`s.
78
85
  // Intersecting with `(Maybe)Provider` allows pipelining.
79
86
  // prettier-ignore
80
- type Result<R> = IsAny<R> extends true ? UnknownResult : IsUnknown<R> extends true ? UnknownResult : R extends Stubable ? Promise<Stub<R>> & Provider<R> & StubBase<R> : R extends RpcCompatible<R> ? Promise<Stubify<R> & MaybeDisposable<R>> & Provider<R> & StubBase<R> : never;
87
+ type Result<R> = IsAny<R> extends true ? UnknownResult : IsUnknown<R> extends true ? UnknownResult : R extends Stubable ? RpcPromise$1<R> : R extends RpcCompatible<R> ? RpcPromise$1<R> : never;
81
88
  type IsAny<T> = 0 extends (1 & T) ? true : false;
82
89
  type UnknownResult = Promise<unknown> & Provider<unknown> & StubBase<unknown>; // Type for method or property on an RPC interface.
83
90
  // For methods, unwrap `Stub`s in parameters, and rewrite returns to be `Result`s.
@@ -321,7 +328,7 @@ declare const RpcStub: {
321
328
  * if you only intend to use the promise for pipelining and you never await it, then there's no
322
329
  * need to transmit the resolution!
323
330
  */
324
- type RpcPromise<T extends RpcCompatible<T>> = Stub<T> & Promise<Stubify<T>>;
331
+ type RpcPromise<T extends RpcCompatible<T>> = RpcPromise$1<T>;
325
332
  declare const RpcPromise: {};
326
333
  /**
327
334
  * Use to construct an `RpcSession` on top of a custom `RpcTransport`.
package/dist/index.js CHANGED
@@ -41,9 +41,22 @@ function typeForRpc(value) {
41
41
  case Array.prototype: return "array";
42
42
  case Date.prototype: return "date";
43
43
  case Uint8Array.prototype:
44
- case BUFFER_PROTOTYPE: return "bytes";
44
+ case BUFFER_PROTOTYPE:
45
+ case ArrayBuffer.prototype:
46
+ case DataView.prototype:
47
+ case Int8Array.prototype:
48
+ case Uint8ClampedArray.prototype:
49
+ case Int16Array.prototype:
50
+ case Uint16Array.prototype:
51
+ case Int32Array.prototype:
52
+ case Uint32Array.prototype:
53
+ case BigInt64Array.prototype:
54
+ case BigUint64Array.prototype:
55
+ case Float32Array.prototype:
56
+ case Float64Array.prototype: return "bytes";
45
57
  case WritableStream.prototype: return "writable";
46
58
  case ReadableStream.prototype: return "readable";
59
+ case URL.prototype: return "url";
47
60
  case Headers.prototype: return "headers";
48
61
  case Request.prototype: return "request";
49
62
  case Response.prototype: return "response";
@@ -378,6 +391,7 @@ var RpcPayload = class RpcPayload {
378
391
  case "date":
379
392
  case "bytes":
380
393
  case "blob":
394
+ case "url":
381
395
  case "error":
382
396
  case "undefined": return value;
383
397
  case "array": {
@@ -511,6 +525,30 @@ var RpcPayload = class RpcPayload {
511
525
  this.dispose();
512
526
  }
513
527
  }
528
+ async deliverStreamWrite(writer) {
529
+ try {
530
+ let promises = [];
531
+ this.deliverTo(this, "value", promises);
532
+ if (promises.length > 0) await Promise.all(promises);
533
+ let chunk = this.value[0];
534
+ if ((this.hooks.length > 0 || this.promises.length > 0) && chunk instanceof Object) {
535
+ if (!(Symbol.dispose in chunk)) Object.defineProperty(chunk, Symbol.dispose, {
536
+ value: () => this.dispose(),
537
+ writable: true,
538
+ enumerable: false,
539
+ configurable: true
540
+ });
541
+ await writer.write(chunk);
542
+ return RpcPayload.fromAppReturn(void 0);
543
+ }
544
+ await writer.write(chunk);
545
+ this.dispose();
546
+ return RpcPayload.fromAppReturn(void 0);
547
+ } catch (err) {
548
+ this.dispose();
549
+ throw err;
550
+ }
551
+ }
514
552
  async deliverResolve() {
515
553
  try {
516
554
  let promises = [];
@@ -551,6 +589,7 @@ var RpcPayload = class RpcPayload {
551
589
  case "bytes":
552
590
  case "blob":
553
591
  case "date":
592
+ case "url":
554
593
  case "error":
555
594
  case "undefined": return;
556
595
  case "array": {
@@ -633,6 +672,7 @@ var RpcPayload = class RpcPayload {
633
672
  case "rpc-target":
634
673
  case "writable":
635
674
  case "readable":
675
+ case "url":
636
676
  case "headers":
637
677
  case "request":
638
678
  case "response": return;
@@ -702,6 +742,7 @@ function followPath(value, parent, path, owner) {
702
742
  case "blob":
703
743
  case "date":
704
744
  case "error":
745
+ case "url":
705
746
  case "headers":
706
747
  case "request":
707
748
  case "response":
@@ -935,6 +976,71 @@ const DEFAULT_LIMITS = {
935
976
  maxDepth: 256,
936
977
  maxMessageSize: 32 * 1024 * 1024
937
978
  };
979
+ const NATIVE_LITTLE_ENDIAN = new Uint8Array(new Uint16Array([1]).buffer)[0] === 1;
980
+ const BYTE_CONTAINER_TYPE_NAMES = [
981
+ "ArrayBuffer",
982
+ "DataView",
983
+ "Int8Array",
984
+ "Uint8Array",
985
+ "Uint8ClampedArray",
986
+ "Int16Array",
987
+ "Uint16Array",
988
+ "Int32Array",
989
+ "Uint32Array",
990
+ "BigInt64Array",
991
+ "BigUint64Array",
992
+ "Float32Array",
993
+ "Float64Array"
994
+ ];
995
+ function isValidByteContainerName(value) {
996
+ return BYTE_CONTAINER_TYPE_NAMES.includes(value);
997
+ }
998
+ const TYPED_ARRAY_ELEMENT_SIZE = {
999
+ ArrayBuffer: void 0,
1000
+ DataView: void 0,
1001
+ Int8Array: void 0,
1002
+ Uint8Array: void 0,
1003
+ Uint8ClampedArray: void 0,
1004
+ Int16Array: 2,
1005
+ Uint16Array: 2,
1006
+ Int32Array: 4,
1007
+ Uint32Array: 4,
1008
+ BigInt64Array: 8,
1009
+ BigUint64Array: 8,
1010
+ Float32Array: 4,
1011
+ Float64Array: 8
1012
+ };
1013
+ const BYTE_CONTAINER_PROTOTYPES = {
1014
+ ArrayBuffer: ArrayBuffer.prototype,
1015
+ DataView: DataView.prototype,
1016
+ Int8Array: Int8Array.prototype,
1017
+ Uint8ClampedArray: Uint8ClampedArray.prototype,
1018
+ Int16Array: Int16Array.prototype,
1019
+ Uint16Array: Uint16Array.prototype,
1020
+ Int32Array: Int32Array.prototype,
1021
+ Uint32Array: Uint32Array.prototype,
1022
+ BigInt64Array: BigInt64Array.prototype,
1023
+ BigUint64Array: BigUint64Array.prototype,
1024
+ Float32Array: Float32Array.prototype,
1025
+ Float64Array: Float64Array.prototype
1026
+ };
1027
+ const BYTE_CONTAINER_TYPE_BY_PROTOTYPE = /* @__PURE__ */ new Map();
1028
+ for (let type of Object.keys(BYTE_CONTAINER_PROTOTYPES)) BYTE_CONTAINER_TYPE_BY_PROTOTYPE.set(BYTE_CONTAINER_PROTOTYPES[type], type);
1029
+ function swapByteOrder(bytes, elementSize) {
1030
+ if (elementSize !== 2 && elementSize !== 4 && elementSize !== 8) throw new RangeError(`Unsupported element size: ${elementSize}`);
1031
+ let view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
1032
+ for (let offset = 0; offset < bytes.byteLength; offset += elementSize) switch (elementSize) {
1033
+ case 2:
1034
+ view.setUint16(offset, view.getUint16(offset, false), true);
1035
+ break;
1036
+ case 4:
1037
+ view.setUint32(offset, view.getUint32(offset, false), true);
1038
+ break;
1039
+ case 8:
1040
+ view.setBigUint64(offset, view.getBigUint64(offset, false), true);
1041
+ break;
1042
+ }
1043
+ }
938
1044
  var NullExporter = class {
939
1045
  exportStub(stub) {
940
1046
  throw new Error("Cannot serialize RPC stubs without an RPC session.");
@@ -954,7 +1060,8 @@ async function streamToBlob(stream, type) {
954
1060
  let b = await new Response(stream).blob();
955
1061
  return b.type === type ? b : b.slice(0, b.size, type);
956
1062
  }
957
- const ERROR_TYPES = Object.assign(Object.create(null), {
1063
+ const ERROR_TYPES = {
1064
+ __proto__: null,
958
1065
  Error,
959
1066
  EvalError,
960
1067
  RangeError,
@@ -963,7 +1070,7 @@ const ERROR_TYPES = Object.assign(Object.create(null), {
963
1070
  TypeError,
964
1071
  URIError,
965
1072
  AggregateError
966
- });
1073
+ };
967
1074
  var Devaluator = class Devaluator {
968
1075
  exporter;
969
1076
  source;
@@ -1025,18 +1132,40 @@ var Devaluator = class Devaluator {
1025
1132
  return ["date", Number.isNaN(time) ? null : time];
1026
1133
  }
1027
1134
  case "bytes": {
1028
- let bytes = value;
1029
- if (this.encodingLevel === "structuredClonable" || this.encodingLevel === "jsonCompatibleWithBytes") return ["bytes", bytes];
1030
- if (bytes.toBase64) return ["bytes", bytes.toBase64({ omitPadding: true })];
1135
+ let alternateTypeName = BYTE_CONTAINER_TYPE_BY_PROTOTYPE.get(Object.getPrototypeOf(value));
1136
+ let bytes;
1137
+ if (alternateTypeName === "ArrayBuffer") bytes = new Uint8Array(value);
1138
+ else if (alternateTypeName === void 0) bytes = value;
1139
+ else {
1140
+ let view = value;
1141
+ bytes = new Uint8Array(view.buffer, view.byteOffset, view.byteLength);
1142
+ let elementSize = TYPED_ARRAY_ELEMENT_SIZE[alternateTypeName];
1143
+ if (!NATIVE_LITTLE_ENDIAN && elementSize) {
1144
+ bytes = bytes.slice();
1145
+ swapByteOrder(bytes, elementSize);
1146
+ }
1147
+ }
1148
+ if (this.encodingLevel === "structuredClonable" || this.encodingLevel === "jsonCompatibleWithBytes") return alternateTypeName === void 0 ? ["bytes", bytes] : [
1149
+ "bytes",
1150
+ bytes,
1151
+ alternateTypeName
1152
+ ];
1031
1153
  let b64;
1032
- if (typeof Buffer !== "undefined") b64 = (bytes instanceof Buffer ? bytes : Buffer.from(bytes.buffer, bytes.byteOffset, bytes.byteLength)).toString("base64");
1154
+ if (bytes.toBase64) b64 = bytes.toBase64({ omitPadding: true });
1155
+ else if (typeof Buffer !== "undefined") b64 = (bytes instanceof Buffer ? bytes : Buffer.from(bytes.buffer, bytes.byteOffset, bytes.byteLength)).toString("base64");
1033
1156
  else {
1034
1157
  let binary = "";
1035
1158
  for (let i = 0; i < bytes.length; i++) binary += String.fromCharCode(bytes[i]);
1036
1159
  b64 = btoa(binary);
1037
1160
  }
1038
- return ["bytes", b64.replace(/=+$/, "")];
1161
+ b64 = b64.replace(/=+$/, "");
1162
+ return alternateTypeName === void 0 ? ["bytes", b64] : [
1163
+ "bytes",
1164
+ b64,
1165
+ alternateTypeName
1166
+ ];
1039
1167
  }
1168
+ case "url": return ["url", value.href];
1040
1169
  case "headers": return ["headers", [...value]];
1041
1170
  case "request": {
1042
1171
  let req = value;
@@ -1288,18 +1417,46 @@ var Evaluator = class Evaluator {
1288
1417
  if (value[1] === null) return /* @__PURE__ */ new Date(NaN);
1289
1418
  if (typeof value[1] == "number") return new Date(value[1]);
1290
1419
  break;
1291
- case "bytes":
1292
- if (value[1] instanceof Uint8Array) return value[1];
1293
- if (typeof value[1] == "string") if (typeof Buffer !== "undefined") return Buffer.from(value[1], "base64");
1294
- else if (Uint8Array.fromBase64) return Uint8Array.fromBase64(value[1]);
1420
+ case "bytes": {
1421
+ let bytes;
1422
+ if (value[1] instanceof Uint8Array) bytes = value[1];
1423
+ else if (typeof value[1] == "string") if (typeof Buffer !== "undefined") bytes = Buffer.from(value[1], "base64");
1424
+ else if (Uint8Array.fromBase64) bytes = Uint8Array.fromBase64(value[1]);
1295
1425
  else {
1296
1426
  let bs = atob(value[1]);
1297
1427
  let len = bs.length;
1298
- let bytes = new Uint8Array(len);
1428
+ bytes = new Uint8Array(len);
1299
1429
  for (let i = 0; i < len; i++) bytes[i] = bs.charCodeAt(i);
1300
- return bytes;
1301
1430
  }
1302
- break;
1431
+ else break;
1432
+ if (value.length === 2) return bytes;
1433
+ if (typeof value[2] !== "string") throw new TypeError(`Unknown bytes type marker type: ${typeof value[2]}`);
1434
+ if (!isValidByteContainerName(value[2])) {
1435
+ let marker = value[2].slice(0, 64);
1436
+ throw new TypeError(`Unknown bytes type marker: ${marker}`);
1437
+ }
1438
+ let marker = value[2];
1439
+ let elementSize = TYPED_ARRAY_ELEMENT_SIZE[marker];
1440
+ if (elementSize !== void 0 && bytes.byteLength % elementSize !== 0) throw new TypeError(`Invalid byte length ${bytes.byteLength} for ${marker}; expected a multiple of ${elementSize}`);
1441
+ let buffer = bytes.buffer.slice(bytes.byteOffset, bytes.byteOffset + bytes.byteLength);
1442
+ if (!NATIVE_LITTLE_ENDIAN && elementSize !== void 0) swapByteOrder(new Uint8Array(buffer), elementSize);
1443
+ switch (marker) {
1444
+ case "ArrayBuffer": return buffer;
1445
+ case "DataView": return new DataView(buffer);
1446
+ case "Int8Array": return new Int8Array(buffer);
1447
+ case "Uint8Array": return new Uint8Array(buffer);
1448
+ case "Uint8ClampedArray": return new Uint8ClampedArray(buffer);
1449
+ case "Int16Array": return new Int16Array(buffer);
1450
+ case "Uint16Array": return new Uint16Array(buffer);
1451
+ case "Int32Array": return new Int32Array(buffer);
1452
+ case "Uint32Array": return new Uint32Array(buffer);
1453
+ case "BigInt64Array": return new BigInt64Array(buffer);
1454
+ case "BigUint64Array": return new BigUint64Array(buffer);
1455
+ case "Float32Array": return new Float32Array(buffer);
1456
+ case "Float64Array": return new Float64Array(buffer);
1457
+ default:
1458
+ }
1459
+ }
1303
1460
  case "error":
1304
1461
  if (value.length >= 3 && typeof value[1] === "string" && typeof value[2] === "string") {
1305
1462
  let cls = ERROR_TYPES[value[1]] || Error;
@@ -1328,6 +1485,9 @@ var Evaluator = class Evaluator {
1328
1485
  case "inf": return Infinity;
1329
1486
  case "-inf": return -Infinity;
1330
1487
  case "nan": return NaN;
1488
+ case "url":
1489
+ if (value.length === 2 && typeof value[1] === "string") return new URL(value[1]);
1490
+ break;
1331
1491
  case "headers":
1332
1492
  if (value.length === 2 && value[1] instanceof Array) return new Headers(value[1]);
1333
1493
  break;
@@ -1549,10 +1709,6 @@ var ImportTableEntry = class {
1549
1709
  resolution;
1550
1710
  onBrokenRegistrations;
1551
1711
  resolve(resolution) {
1552
- if (this.resolution) {
1553
- resolution.dispose();
1554
- return;
1555
- }
1556
1712
  if (this.localRefcount == 0) {
1557
1713
  resolution.dispose();
1558
1714
  return;
@@ -2152,6 +2308,8 @@ var RpcSession$1 = class {
2152
2308
 
2153
2309
  //#endregion
2154
2310
  //#region src/websocket.ts
2311
+ /** Close-frame reason max UTF-8 bytes: 125 payload - 2-byte status (RFC 6455 section 5.5). */
2312
+ const MAX_CLOSE_REASON_BYTES = 123;
2155
2313
  function newWebSocketRpcSession$1(webSocket, localMain, options) {
2156
2314
  if (typeof webSocket === "string") webSocket = new WebSocket(webSocket);
2157
2315
  return new RpcSession$1(new WebSocketTransport(webSocket), localMain, options).getRemoteMain();
@@ -2246,6 +2404,7 @@ var WebSocketTransport = class {
2246
2404
 
2247
2405
  //#endregion
2248
2406
  //#region src/batch.ts
2407
+ const yieldToMacrotask = typeof setImmediate === "function" ? () => new Promise((resolve) => setImmediate(resolve)) : () => new Promise((resolve) => setTimeout(resolve, 0));
2249
2408
  var BatchClientTransport = class {
2250
2409
  constructor(sendBatch) {
2251
2410
  this.#promise = this.#scheduleBatch(sendBatch);
@@ -2267,7 +2426,7 @@ var BatchClientTransport = class {
2267
2426
  this.#aborted = reason;
2268
2427
  }
2269
2428
  async #scheduleBatch(sendBatch) {
2270
- await new Promise((resolve) => setTimeout(resolve, 0));
2429
+ await yieldToMacrotask();
2271
2430
  if (this.#aborted !== void 0) throw this.#aborted;
2272
2431
  let batch = this.#batchToSend;
2273
2432
  this.#batchToSend = null;
@@ -2677,8 +2836,7 @@ var WritableStreamStubHook = class WritableStreamStubHook extends StubHook {
2677
2836
  throw new Error(`Unknown WritableStream method: ${method}`);
2678
2837
  }
2679
2838
  if (method === "close" || method === "abort") state.closed = true;
2680
- let func = state.writer[method];
2681
- return new PromiseStubHook(args.deliverCall(func, state.writer).then((payload) => new PayloadStubHook(payload)));
2839
+ return new PromiseStubHook((method === "write" ? args.deliverStreamWrite(state.writer) : args.deliverCall(state.writer[method], state.writer)).then((payload) => new PayloadStubHook(payload)));
2682
2840
  } catch (err) {
2683
2841
  return new ErrorStubHook(err);
2684
2842
  }