capnweb 0.0.0-2de5871 → 0.0.0-31f8edc

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.
@@ -1,5 +1,4 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
-
3
2
  //#region src/symbols.ts
4
3
  let WORKERS_MODULE_SYMBOL = Symbol("workers-module");
5
4
 
@@ -42,6 +41,7 @@ function typeForRpc(value) {
42
41
  case AsyncFunction.prototype: return "function";
43
42
  case Array.prototype: return "array";
44
43
  case Date.prototype: return "date";
44
+ case RegExp.prototype: return "regexp";
45
45
  case Uint8Array.prototype:
46
46
  case BUFFER_PROTOTYPE:
47
47
  case ArrayBuffer.prototype:
@@ -246,7 +246,25 @@ var RpcStub$1 = class RpcStub$1 extends RpcTarget$1 {
246
246
  };
247
247
  var RpcPromise$1 = class extends RpcStub$1 {
248
248
  constructor(hook, pathIfPromise) {
249
- super(hook, pathIfPromise);
249
+ if (hook instanceof StubHook) super(hook, pathIfPromise ?? []);
250
+ else {
251
+ if (pathIfPromise !== void 0) throw new TypeError("RpcPromise constructor expected one argument, received two.");
252
+ let kind = typeForRpc(hook);
253
+ if (kind === "rpc-promise") {
254
+ let raw = unwrapStubAndPath(hook);
255
+ if (raw.pathIfPromise.length > 0) super(raw.hook, raw.pathIfPromise);
256
+ else {
257
+ let adopted = raw.hook;
258
+ raw.hook = DISPOSED_HOOK;
259
+ super(adopted, []);
260
+ }
261
+ } else if (kind === "rpc-thenable") super(TargetStubHook.create(hook, void 0), []);
262
+ else {
263
+ let promiseHook = new PromiseStubHook(Promise.resolve(hook).then((value) => new PayloadStubHook(RpcPayload.fromAppReturn(value))));
264
+ promiseHook.ignoreUnhandledRejections();
265
+ super(promiseHook, []);
266
+ }
267
+ }
250
268
  }
251
269
  then(onfulfilled, onrejected) {
252
270
  return pullPromise(this).then(...arguments);
@@ -341,12 +359,13 @@ var RpcPayload = class RpcPayload {
341
359
  return TargetStubHook.create(target, parent);
342
360
  } else if (this.source === "return") {
343
361
  let hook = this.rpcTargets?.get(target);
344
- if (hook) if (dupStubs) return hook.dup();
345
- else {
346
- this.rpcTargets?.delete(target);
347
- return hook;
348
- }
349
- else {
362
+ if (hook) {
363
+ if (dupStubs) return hook.dup();
364
+ else {
365
+ this.rpcTargets?.delete(target);
366
+ return hook;
367
+ }
368
+ } else {
350
369
  hook = TargetStubHook.create(target, parent);
351
370
  if (dupStubs) {
352
371
  if (!this.rpcTargets) this.rpcTargets = /* @__PURE__ */ new Map();
@@ -360,12 +379,13 @@ var RpcPayload = class RpcPayload {
360
379
  if (this.source === "params") return streamImpl.createWritableStreamHook(stream);
361
380
  else if (this.source === "return") {
362
381
  let hook = this.rpcTargets?.get(stream);
363
- if (hook) if (dupStubs) return hook.dup();
364
- else {
365
- this.rpcTargets?.delete(stream);
366
- return hook;
367
- }
368
- else {
382
+ if (hook) {
383
+ if (dupStubs) return hook.dup();
384
+ else {
385
+ this.rpcTargets?.delete(stream);
386
+ return hook;
387
+ }
388
+ } else {
369
389
  hook = streamImpl.createWritableStreamHook(stream);
370
390
  if (dupStubs) {
371
391
  if (!this.rpcTargets) this.rpcTargets = /* @__PURE__ */ new Map();
@@ -379,12 +399,13 @@ var RpcPayload = class RpcPayload {
379
399
  if (this.source === "params") return streamImpl.createReadableStreamHook(stream);
380
400
  else if (this.source === "return") {
381
401
  let hook = this.rpcTargets?.get(stream);
382
- if (hook) if (dupStubs) return hook.dup();
383
- else {
384
- this.rpcTargets?.delete(stream);
385
- return hook;
386
- }
387
- else {
402
+ if (hook) {
403
+ if (dupStubs) return hook.dup();
404
+ else {
405
+ this.rpcTargets?.delete(stream);
406
+ return hook;
407
+ }
408
+ } else {
388
409
  hook = streamImpl.createReadableStreamHook(stream);
389
410
  if (dupStubs) {
390
411
  if (!this.rpcTargets) this.rpcTargets = /* @__PURE__ */ new Map();
@@ -403,6 +424,7 @@ var RpcPayload = class RpcPayload {
403
424
  case "bytes":
404
425
  case "blob":
405
426
  case "url":
427
+ case "regexp":
406
428
  case "error":
407
429
  case "undefined": return value;
408
430
  case "array": {
@@ -601,6 +623,7 @@ var RpcPayload = class RpcPayload {
601
623
  case "blob":
602
624
  case "date":
603
625
  case "url":
626
+ case "regexp":
604
627
  case "error":
605
628
  case "undefined": return;
606
629
  case "array": {
@@ -684,6 +707,7 @@ var RpcPayload = class RpcPayload {
684
707
  case "writable":
685
708
  case "readable":
686
709
  case "url":
710
+ case "regexp":
687
711
  case "headers":
688
712
  case "request":
689
713
  case "response": return;
@@ -754,6 +778,7 @@ function followPath(value, parent, path, owner) {
754
778
  case "date":
755
779
  case "error":
756
780
  case "url":
781
+ case "regexp":
757
782
  case "headers":
758
783
  case "request":
759
784
  case "response":
@@ -799,7 +824,8 @@ var ValueStubHook = class extends StubHook {
799
824
  args.dispose();
800
825
  return new ErrorStubHook(/* @__PURE__ */ new TypeError(`'${path.join(".")}' is not a function.`));
801
826
  }
802
- return new PromiseStubHook(args.deliverCall(followResult.value, followResult.parent).then((payload) => {
827
+ let promise = args.deliverCall(followResult.value, followResult.parent);
828
+ return new PromiseStubHook(promise.then((payload) => {
803
829
  return new PayloadStubHook(payload);
804
830
  }));
805
831
  }
@@ -822,7 +848,10 @@ var ValueStubHook = class extends StubHook {
822
848
  get(path) {
823
849
  try {
824
850
  let { value, owner } = this.getValue();
825
- if (path.length === 0 && owner === null) throw new Error("Can't dup an RpcTarget stub as a promise.");
851
+ if (path.length === 0 && owner === null) {
852
+ if (value instanceof Object && "then" in value) return this.dup();
853
+ throw new Error("Can't dup an RpcTarget stub as a promise.");
854
+ }
826
855
  let followResult = followPath(value, void 0, path, owner);
827
856
  if (followResult.hook) return followResult.hook.get(followResult.remainingPath);
828
857
  return new PayloadStubHook(RpcPayload.deepCopyFrom(followResult.value, followResult.parent, followResult.owner));
@@ -925,7 +954,10 @@ var TargetStubHook = class TargetStubHook extends ValueStubHook {
925
954
  this.target = void 0;
926
955
  }
927
956
  }
928
- onBroken(callback) {}
957
+ onBroken(callback) {
958
+ let target = this.target;
959
+ if (target && "then" in target) Promise.resolve(target).then(() => {}, callback);
960
+ }
929
961
  };
930
962
  var PromiseStubHook = class PromiseStubHook extends StubHook {
931
963
  promise;
@@ -991,7 +1023,7 @@ const DEFAULT_MAX_DEPTH = 256;
991
1023
  const DEFAULT_LIMITS = {
992
1024
  maxBigIntDigits: 16384,
993
1025
  maxDepth: 256,
994
- maxMessageSize: 32 * 1024 * 1024
1026
+ maxMessageSize: 33554432
995
1027
  };
996
1028
  const NATIVE_LITTLE_ENDIAN = new Uint8Array(new Uint16Array([1]).buffer)[0] === 1;
997
1029
  const BYTE_CONTAINER_TYPE_NAMES = [
@@ -1053,9 +1085,7 @@ function swapByteOrder(bytes, elementSize) {
1053
1085
  case 4:
1054
1086
  view.setUint32(offset, view.getUint32(offset, false), true);
1055
1087
  break;
1056
- case 8:
1057
- view.setBigUint64(offset, view.getBigUint64(offset, false), true);
1058
- break;
1088
+ case 8: view.setBigUint64(offset, view.getBigUint64(offset, false), true);
1059
1089
  }
1060
1090
  }
1061
1091
  var NullExporter = class {
@@ -1148,6 +1178,15 @@ var Devaluator = class Devaluator {
1148
1178
  const time = value.getTime();
1149
1179
  return ["date", Number.isNaN(time) ? null : time];
1150
1180
  }
1181
+ case "regexp": {
1182
+ if (this.encodingLevel === "structuredClonable") return value;
1183
+ let re = value;
1184
+ return re.flags ? [
1185
+ "regexp",
1186
+ re.source,
1187
+ re.flags
1188
+ ] : ["regexp", re.source];
1189
+ }
1151
1190
  case "bytes": {
1152
1191
  let alternateTypeName = BYTE_CONTAINER_TYPE_BY_PROTOTYPE.get(Object.getPrototypeOf(value));
1153
1192
  let bytes;
@@ -1305,13 +1344,16 @@ var Devaluator = class Devaluator {
1305
1344
  if (!this.source) throw new Error("Can't serialize RPC stubs in this context.");
1306
1345
  let { hook, pathIfPromise } = unwrapStubAndPath(value);
1307
1346
  let importId = this.exporter.getImport(hook);
1308
- if (importId !== void 0) if (pathIfPromise) if (pathIfPromise.length > 0) return [
1309
- "pipeline",
1310
- importId,
1311
- pathIfPromise
1312
- ];
1313
- else return ["pipeline", importId];
1314
- else return ["import", importId];
1347
+ if (importId !== void 0) {
1348
+ if (pathIfPromise) {
1349
+ if (pathIfPromise.length > 0) return [
1350
+ "pipeline",
1351
+ importId,
1352
+ pathIfPromise
1353
+ ];
1354
+ else return ["pipeline", importId];
1355
+ } else return ["import", importId];
1356
+ }
1315
1357
  if (pathIfPromise) hook = hook.get(pathIfPromise);
1316
1358
  else hook = hook.dup();
1317
1359
  return this.devaluateHook(pathIfPromise ? "promise" : "export", hook);
@@ -1372,16 +1414,18 @@ var NullImporter = class {
1372
1414
  };
1373
1415
  const NULL_IMPORTER = new NullImporter();
1374
1416
  function fixBrokenRequestBody(request, body) {
1375
- return new RpcPromise$1(new PromiseStubHook(new Response(body).arrayBuffer().then((arrayBuffer) => {
1417
+ let promise = new Response(body).arrayBuffer().then((arrayBuffer) => {
1376
1418
  let bytes = new Uint8Array(arrayBuffer);
1377
1419
  let result = new Request(request, { body: bytes });
1378
1420
  return new PayloadStubHook(RpcPayload.fromAppReturn(result));
1379
- })), []);
1421
+ });
1422
+ return new RpcPromise$1(new PromiseStubHook(promise), []);
1380
1423
  }
1381
1424
  function streamToBlobPromise(stream, type) {
1382
- return new RpcPromise$1(new PromiseStubHook(streamToBlob(stream, type).then((blob) => {
1425
+ let promise = streamToBlob(stream, type).then((blob) => {
1383
1426
  return new PayloadStubHook(RpcPayload.fromAppReturn(blob));
1384
- })), []);
1427
+ });
1428
+ return new RpcPromise$1(new PromiseStubHook(promise), []);
1385
1429
  }
1386
1430
  var Evaluator = class Evaluator {
1387
1431
  importer;
@@ -1414,7 +1458,7 @@ var Evaluator = class Evaluator {
1414
1458
  let maxDepth = this.limits.maxDepth;
1415
1459
  if (depth >= maxDepth) throw new TypeError(`Deserialization exceeded maximum allowed message depth of ${maxDepth}.`);
1416
1460
  if (this.encodingLevel === "structuredClonable") {
1417
- if (value instanceof Date || typeof value === "bigint") return value;
1461
+ if (value instanceof Date || value instanceof RegExp || typeof value === "bigint") return value;
1418
1462
  }
1419
1463
  if (value instanceof Array) {
1420
1464
  if (value.length == 1 && value[0] instanceof Array) {
@@ -1434,18 +1478,22 @@ var Evaluator = class Evaluator {
1434
1478
  if (value[1] === null) return /* @__PURE__ */ new Date(NaN);
1435
1479
  if (typeof value[1] == "number") return new Date(value[1]);
1436
1480
  break;
1481
+ case "regexp":
1482
+ if (typeof value[1] === "string" && (value.length === 2 || value.length === 3 && typeof value[2] === "string")) return new RegExp(value[1], value[2]);
1483
+ break;
1437
1484
  case "bytes": {
1438
1485
  let bytes;
1439
1486
  if (value[1] instanceof Uint8Array) bytes = value[1];
1440
- else if (typeof value[1] == "string") if (typeof Buffer !== "undefined") bytes = Buffer.from(value[1], "base64");
1441
- else if (Uint8Array.fromBase64) bytes = Uint8Array.fromBase64(value[1]);
1442
- else {
1443
- let bs = atob(value[1]);
1444
- let len = bs.length;
1445
- bytes = new Uint8Array(len);
1446
- for (let i = 0; i < len; i++) bytes[i] = bs.charCodeAt(i);
1447
- }
1448
- else break;
1487
+ else if (typeof value[1] == "string") {
1488
+ if (typeof Buffer !== "undefined") bytes = Buffer.from(value[1], "base64");
1489
+ else if (Uint8Array.fromBase64) bytes = Uint8Array.fromBase64(value[1]);
1490
+ else {
1491
+ let bs = atob(value[1]);
1492
+ let len = bs.length;
1493
+ bytes = new Uint8Array(len);
1494
+ for (let i = 0; i < len; i++) bytes[i] = bs.charCodeAt(i);
1495
+ }
1496
+ } else break;
1449
1497
  if (value.length === 2) return bytes;
1450
1498
  if (typeof value[2] !== "string") throw new TypeError(`Unknown bytes type marker type: ${typeof value[2]}`);
1451
1499
  if (!isValidByteContainerName(value[2])) {
@@ -1471,7 +1519,6 @@ var Evaluator = class Evaluator {
1471
1519
  case "BigUint64Array": return new BigUint64Array(buffer);
1472
1520
  case "Float32Array": return new Float32Array(buffer);
1473
1521
  case "Float64Array": return new Float64Array(buffer);
1474
- default:
1475
1522
  }
1476
1523
  }
1477
1524
  case "error":
@@ -1577,8 +1624,10 @@ var Evaluator = class Evaluator {
1577
1624
  return new RpcPromise$1(hook, []);
1578
1625
  }
1579
1626
  };
1580
- if (value.length == 2) if (isPromise) return addStub(hook.get([]));
1581
- else return addStub(hook.dup());
1627
+ if (value.length == 2) {
1628
+ if (isPromise) return addStub(hook.get([]));
1629
+ else return addStub(hook.dup());
1630
+ }
1582
1631
  let path = value[2];
1583
1632
  if (!(path instanceof Array)) break;
1584
1633
  if (!path.every((part) => {
@@ -1608,7 +1657,8 @@ var Evaluator = class Evaluator {
1608
1657
  }
1609
1658
  });
1610
1659
  let instructions = value[4];
1611
- let promise = new RpcPromise$1(hook.map(path, captures, instructions), []);
1660
+ let resultHook = hook.map(path, captures, instructions);
1661
+ let promise = new RpcPromise$1(resultHook, []);
1612
1662
  this.promises.push({
1613
1663
  promise,
1614
1664
  parent,
@@ -1618,18 +1668,21 @@ var Evaluator = class Evaluator {
1618
1668
  }
1619
1669
  case "export":
1620
1670
  case "promise":
1621
- if (typeof value[1] == "number") if (value[0] == "promise") {
1622
- let promise = new RpcPromise$1(this.importer.importPromise(value[1]), []);
1623
- this.promises.push({
1624
- parent,
1625
- property,
1626
- promise
1627
- });
1628
- return promise;
1629
- } else {
1630
- let hook = this.importer.importStub(value[1]);
1631
- this.hooks.push(hook);
1632
- return new RpcStub$1(hook);
1671
+ if (typeof value[1] == "number") {
1672
+ if (value[0] == "promise") {
1673
+ let hook = this.importer.importPromise(value[1]);
1674
+ let promise = new RpcPromise$1(hook, []);
1675
+ this.promises.push({
1676
+ parent,
1677
+ property,
1678
+ promise
1679
+ });
1680
+ return promise;
1681
+ } else {
1682
+ let hook = this.importer.importStub(value[1]);
1683
+ this.hooks.push(hook);
1684
+ return new RpcStub$1(hook);
1685
+ }
1633
1686
  }
1634
1687
  break;
1635
1688
  case "writable":
@@ -1640,14 +1693,12 @@ var Evaluator = class Evaluator {
1640
1693
  return stream;
1641
1694
  }
1642
1695
  break;
1643
- case "readable":
1644
- if (typeof value[1] == "number") {
1645
- let stream = this.importer.getPipeReadable(value[1]);
1646
- let hook = streamImpl.createReadableStreamHook(stream);
1647
- this.hooks.push(hook);
1648
- return stream;
1649
- }
1650
- break;
1696
+ case "readable": if (typeof value[1] == "number") {
1697
+ let stream = this.importer.getPipeReadable(value[1]);
1698
+ let hook = streamImpl.createReadableStreamHook(stream);
1699
+ this.hooks.push(hook);
1700
+ return stream;
1701
+ }
1651
1702
  }
1652
1703
  throw new TypeError(`unknown special value: ${JSON.stringify(value)}`);
1653
1704
  } else if (value instanceof Object) {
@@ -1692,6 +1743,7 @@ function estimateEncodedSize(value, seen, depth = 0) {
1692
1743
  if (value instanceof ArrayBuffer) return ESTIMATED_BINARY_OVERHEAD + value.byteLength;
1693
1744
  if (typeof Blob !== "undefined" && value instanceof Blob) return ESTIMATED_BINARY_OVERHEAD + value.size;
1694
1745
  if (value instanceof Date) return 16;
1746
+ if (value instanceof RegExp) return ESTIMATED_OBJECT_OVERHEAD + estimateStringSize(value.source) + estimateStringSize(value.flags);
1695
1747
  seen ??= /* @__PURE__ */ new WeakSet();
1696
1748
  if (seen.has(value)) return ESTIMATED_ENTRY_OVERHEAD;
1697
1749
  seen.add(value);
@@ -2227,7 +2279,8 @@ var RpcSessionImpl = class {
2227
2279
  if (msg instanceof Array) switch (msg[0]) {
2228
2280
  case "push":
2229
2281
  if (msg.length > 1) {
2230
- let hook = new PayloadStubHook(new Evaluator(this, this.encodingLevel).evaluate(msg[1]));
2282
+ let payload = new Evaluator(this, this.encodingLevel).evaluate(msg[1]);
2283
+ let hook = new PayloadStubHook(payload);
2231
2284
  hook.ignoreUnhandledRejections();
2232
2285
  this.exports.push({
2233
2286
  hook,
@@ -2238,7 +2291,8 @@ var RpcSessionImpl = class {
2238
2291
  break;
2239
2292
  case "stream":
2240
2293
  if (msg.length > 1) {
2241
- let hook = new PayloadStubHook(new Evaluator(this, this.encodingLevel).evaluate(msg[1]));
2294
+ let payload = new Evaluator(this, this.encodingLevel).evaluate(msg[1]);
2295
+ let hook = new PayloadStubHook(payload);
2242
2296
  hook.ignoreUnhandledRejections();
2243
2297
  let exportId = this.exports.length;
2244
2298
  this.exports.push({
@@ -2273,13 +2327,14 @@ var RpcSessionImpl = class {
2273
2327
  let importId = msg[1];
2274
2328
  if (typeof importId == "number" && msg.length > 2) {
2275
2329
  let imp = this.imports[importId];
2276
- if (imp) if (msg[0] == "resolve") imp.resolve(new PayloadStubHook(new Evaluator(this, this.encodingLevel).evaluate(msg[2])));
2277
- else {
2278
- let payload = new Evaluator(this, this.encodingLevel).evaluate(msg[2]);
2279
- payload.dispose();
2280
- imp.resolve(new ErrorStubHook(payload.value));
2281
- }
2282
- else if (msg[0] == "resolve") new Evaluator(this, this.encodingLevel).evaluate(msg[2]).dispose();
2330
+ if (imp) {
2331
+ if (msg[0] == "resolve") imp.resolve(new PayloadStubHook(new Evaluator(this, this.encodingLevel).evaluate(msg[2])));
2332
+ else {
2333
+ let payload = new Evaluator(this, this.encodingLevel).evaluate(msg[2]);
2334
+ payload.dispose();
2335
+ imp.resolve(new ErrorStubHook(payload.value));
2336
+ }
2337
+ } else if (msg[0] == "resolve") new Evaluator(this, this.encodingLevel).evaluate(msg[2]).dispose();
2283
2338
  continue;
2284
2339
  }
2285
2340
  break;
@@ -2351,7 +2406,8 @@ var RpcSession$1 = class {
2351
2406
  const MAX_CLOSE_REASON_BYTES = 123;
2352
2407
  function newWebSocketRpcSession$1(webSocket, localMain, options) {
2353
2408
  if (typeof webSocket === "string") webSocket = new WebSocket(webSocket);
2354
- return new RpcSession$1(new WebSocketTransport(webSocket), localMain, options).getRemoteMain();
2409
+ let transport = new WebSocketTransport(webSocket);
2410
+ return new RpcSession$1(transport, localMain, options).getRemoteMain();
2355
2411
  }
2356
2412
  /**
2357
2413
  * For use in Cloudflare Workers: Construct an HTTP response that starts a WebSocket RPC session
@@ -2388,12 +2444,13 @@ var WebSocketTransport = class {
2388
2444
  });
2389
2445
  }
2390
2446
  webSocket.addEventListener("message", (event) => {
2391
- if (this.#error) {} else if (typeof event.data === "string" || event.data instanceof ArrayBuffer) if (this.#receiveResolver) {
2392
- this.#receiveResolver(event.data);
2393
- this.#receiveResolver = void 0;
2394
- this.#receiveRejecter = void 0;
2395
- } else this.#receiveQueue.push(event.data);
2396
- else this.#receivedError(/* @__PURE__ */ new TypeError("Received unexpected message type from WebSocket."));
2447
+ if (this.#error) {} else if (typeof event.data === "string" || event.data instanceof ArrayBuffer) {
2448
+ if (this.#receiveResolver) {
2449
+ this.#receiveResolver(event.data);
2450
+ this.#receiveResolver = void 0;
2451
+ this.#receiveRejecter = void 0;
2452
+ } else this.#receiveQueue.push(event.data);
2453
+ } else this.#receivedError(/* @__PURE__ */ new TypeError("Received unexpected message type from WebSocket."));
2397
2454
  });
2398
2455
  webSocket.addEventListener("close", (event) => {
2399
2456
  this.#receivedError(/* @__PURE__ */ new Error(`Peer closed WebSocket: ${event.code} ${event.reason}`));
@@ -2485,7 +2542,8 @@ function newHttpBatchRpcSession$1(urlOrRequest, options) {
2485
2542
  let body = await response.text();
2486
2543
  return body == "" ? [] : body.split("\n");
2487
2544
  };
2488
- return new RpcSession$1(new BatchClientTransport(sendBatch), void 0, options).getRemoteMain();
2545
+ let transport = new BatchClientTransport(sendBatch);
2546
+ return new RpcSession$1(transport, void 0, options).getRemoteMain();
2489
2547
  }
2490
2548
  var BatchServerTransport = class {
2491
2549
  constructor(batch) {
@@ -2528,7 +2586,8 @@ var BatchServerTransport = class {
2528
2586
  async function newHttpBatchRpcResponse(request, localMain, options) {
2529
2587
  if (request.method !== "POST") return new Response("This endpoint only accepts POST requests.", { status: 405 });
2530
2588
  let body = await request.text();
2531
- let transport = new BatchServerTransport(body === "" ? [] : body.split("\n"));
2589
+ let batch = body === "" ? [] : body.split("\n");
2590
+ let transport = new BatchServerTransport(batch);
2532
2591
  let rpc = new RpcSession$1(transport, localMain, options);
2533
2592
  await transport.whenAllReceived();
2534
2593
  await rpc.drain();
@@ -2558,7 +2617,8 @@ async function nodeHttpBatchRpcResponse(request, response, localMain, options) {
2558
2617
  });
2559
2618
  request.on("error", reject);
2560
2619
  });
2561
- let transport = new BatchServerTransport(body === "" ? [] : body.split("\n"));
2620
+ let batch = body === "" ? [] : body.split("\n");
2621
+ let transport = new BatchServerTransport(batch);
2562
2622
  let rpc = new RpcSession$1(transport, localMain, options);
2563
2623
  await transport.whenAllReceived();
2564
2624
  await rpc.drain();
@@ -2569,7 +2629,8 @@ async function nodeHttpBatchRpcResponse(request, response, localMain, options) {
2569
2629
  //#endregion
2570
2630
  //#region src/messageport.ts
2571
2631
  function newMessagePortRpcSession$1(port, localMain, options) {
2572
- return new RpcSession$1(new MessagePortTransport(port), localMain, options).getRemoteMain();
2632
+ let transport = new MessagePortTransport(port);
2633
+ return new RpcSession$1(transport, localMain, options).getRemoteMain();
2573
2634
  }
2574
2635
  var MessagePortTransport = class {
2575
2636
  encodingLevel = "structuredClonable";
@@ -2819,7 +2880,8 @@ var MapApplicator = class {
2819
2880
  }
2820
2881
  };
2821
2882
  function applyMapToElement(input, parent, owner, captures, instructions) {
2822
- let mapper = new MapApplicator(captures, new PayloadStubHook(RpcPayload.deepCopyFrom(input, parent, owner)));
2883
+ let inputHook = new PayloadStubHook(RpcPayload.deepCopyFrom(input, parent, owner));
2884
+ let mapper = new MapApplicator(captures, inputHook);
2823
2885
  try {
2824
2886
  return mapper.apply(instructions);
2825
2887
  } finally {
@@ -2852,9 +2914,10 @@ mapImpl.applyMap = (input, parent, owner, captures, instructions) => {
2852
2914
  var WritableStreamStubHook = class WritableStreamStubHook extends StubHook {
2853
2915
  state;
2854
2916
  static create(stream) {
2917
+ let writer = stream.getWriter();
2855
2918
  return new WritableStreamStubHook({
2856
2919
  refcount: 1,
2857
- writer: stream.getWriter(),
2920
+ writer,
2858
2921
  closed: false
2859
2922
  });
2860
2923
  }
@@ -2874,7 +2937,8 @@ var WritableStreamStubHook = class WritableStreamStubHook extends StubHook {
2874
2937
  const method = path[0];
2875
2938
  if (method !== "write" && method !== "close" && method !== "abort") throw new Error(`Unknown WritableStream method: ${method}`);
2876
2939
  if (method === "close" || method === "abort") state.closed = true;
2877
- return new PromiseStubHook((method === "write" ? args.deliverStreamWrite(state.writer) : args.deliverCall(state.writer[method], state.writer)).then((payload) => new PayloadStubHook(payload)));
2940
+ let promise = method === "write" ? args.deliverStreamWrite(state.writer) : args.deliverCall(state.writer[method], state.writer);
2941
+ return new PromiseStubHook(promise.then((payload) => new PayloadStubHook(payload)));
2878
2942
  } catch (err) {
2879
2943
  args.dispose();
2880
2944
  return new ErrorStubHook(err);
@@ -2888,7 +2952,8 @@ var WritableStreamStubHook = class WritableStreamStubHook extends StubHook {
2888
2952
  return new ErrorStubHook(/* @__PURE__ */ new Error("Cannot access properties on a WritableStream stub"));
2889
2953
  }
2890
2954
  dup() {
2891
- return new WritableStreamStubHook(this.getState(), this);
2955
+ let state = this.getState();
2956
+ return new WritableStreamStubHook(state, this);
2892
2957
  }
2893
2958
  pull() {
2894
2959
  return Promise.reject(/* @__PURE__ */ new Error("Cannot pull a WritableStream stub"));
@@ -2906,9 +2971,9 @@ var WritableStreamStubHook = class WritableStreamStubHook extends StubHook {
2906
2971
  }
2907
2972
  onBroken(callback) {}
2908
2973
  };
2909
- const INITIAL_WINDOW = 256 * 1024;
2910
- const MAX_WINDOW = 1024 * 1024 * 1024;
2911
- const MIN_WINDOW = 64 * 1024;
2974
+ const INITIAL_WINDOW = 262144;
2975
+ const MAX_WINDOW = 1073741824;
2976
+ const MIN_WINDOW = 65536;
2912
2977
  const STARTUP_GROWTH_FACTOR = 2;
2913
2978
  const STEADY_GROWTH_FACTOR = 1.25;
2914
2979
  const DECAY_FACTOR = .9;