capnweb 0.0.0-aa4fe30 → 0.0.0-c2bb17b
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/README.md +17 -1
- package/dist/index-workers.cjs +651 -40
- package/dist/index-workers.cjs.map +1 -1
- package/dist/index-workers.d.cts +1 -1
- package/dist/index-workers.d.ts +1 -1
- package/dist/index-workers.js +651 -40
- package/dist/index-workers.js.map +1 -1
- package/dist/index.cjs +651 -40
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +30 -22
- package/dist/index.d.ts +30 -22
- package/dist/index.js +651 -40
- package/dist/index.js.map +1 -1
- package/package.json +8 -8
package/dist/index.cjs
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
// src/symbols.ts
|
|
4
|
-
var WORKERS_MODULE_SYMBOL = Symbol("workers-module");
|
|
4
|
+
var WORKERS_MODULE_SYMBOL = /* @__PURE__ */ Symbol("workers-module");
|
|
5
5
|
|
|
6
6
|
// src/core.ts
|
|
7
7
|
if (!Symbol.dispose) {
|
|
8
|
-
Symbol.dispose = Symbol.for("dispose");
|
|
8
|
+
Symbol.dispose = /* @__PURE__ */ Symbol.for("dispose");
|
|
9
9
|
}
|
|
10
10
|
if (!Symbol.asyncDispose) {
|
|
11
|
-
Symbol.asyncDispose = Symbol.for("asyncDispose");
|
|
11
|
+
Symbol.asyncDispose = /* @__PURE__ */ Symbol.for("asyncDispose");
|
|
12
12
|
}
|
|
13
13
|
if (!Promise.withResolvers) {
|
|
14
14
|
Promise.withResolvers = function() {
|
|
@@ -24,6 +24,8 @@ if (!Promise.withResolvers) {
|
|
|
24
24
|
var workersModule = globalThis[WORKERS_MODULE_SYMBOL];
|
|
25
25
|
var RpcTarget = workersModule ? workersModule.RpcTarget : class {
|
|
26
26
|
};
|
|
27
|
+
var AsyncFunction = (async function() {
|
|
28
|
+
}).constructor;
|
|
27
29
|
function typeForRpc(value) {
|
|
28
30
|
switch (typeof value) {
|
|
29
31
|
case "boolean":
|
|
@@ -48,6 +50,7 @@ function typeForRpc(value) {
|
|
|
48
50
|
case Object.prototype:
|
|
49
51
|
return "object";
|
|
50
52
|
case Function.prototype:
|
|
53
|
+
case AsyncFunction.prototype:
|
|
51
54
|
return "function";
|
|
52
55
|
case Array.prototype:
|
|
53
56
|
return "array";
|
|
@@ -55,6 +58,10 @@ function typeForRpc(value) {
|
|
|
55
58
|
return "date";
|
|
56
59
|
case Uint8Array.prototype:
|
|
57
60
|
return "bytes";
|
|
61
|
+
case WritableStream.prototype:
|
|
62
|
+
return "writable";
|
|
63
|
+
case ReadableStream.prototype:
|
|
64
|
+
return "readable";
|
|
58
65
|
// TODO: All other structured clone types.
|
|
59
66
|
case RpcStub.prototype:
|
|
60
67
|
return "stub";
|
|
@@ -82,7 +89,34 @@ function mapNotLoaded() {
|
|
|
82
89
|
throw new Error("RPC map() implementation was not loaded.");
|
|
83
90
|
}
|
|
84
91
|
var mapImpl = { applyMap: mapNotLoaded, sendMap: mapNotLoaded };
|
|
92
|
+
function streamNotLoaded() {
|
|
93
|
+
throw new Error("Stream implementation was not loaded.");
|
|
94
|
+
}
|
|
95
|
+
var streamImpl = {
|
|
96
|
+
createWritableStreamHook: streamNotLoaded,
|
|
97
|
+
createWritableStreamFromHook: streamNotLoaded,
|
|
98
|
+
createReadableStreamHook: streamNotLoaded
|
|
99
|
+
};
|
|
85
100
|
var StubHook = class {
|
|
101
|
+
// Like call(), but designed for streaming calls (e.g. WritableStream writes). Returns:
|
|
102
|
+
// - promise: A Promise<void> for the completion of the call.
|
|
103
|
+
// - size: If the call was remote, the byte size of the serialized message. For local calls,
|
|
104
|
+
// undefined is returned, indicating the caller should await the promise to serialize writes
|
|
105
|
+
// (no overlapping).
|
|
106
|
+
stream(path, args) {
|
|
107
|
+
let hook = this.call(path, args);
|
|
108
|
+
let pulled = hook.pull();
|
|
109
|
+
let promise;
|
|
110
|
+
if (pulled instanceof Promise) {
|
|
111
|
+
promise = pulled.then((p) => {
|
|
112
|
+
p.dispose();
|
|
113
|
+
});
|
|
114
|
+
} else {
|
|
115
|
+
pulled.dispose();
|
|
116
|
+
promise = Promise.resolve();
|
|
117
|
+
}
|
|
118
|
+
return { promise };
|
|
119
|
+
}
|
|
86
120
|
};
|
|
87
121
|
var ErrorStubHook = class extends StubHook {
|
|
88
122
|
constructor(error) {
|
|
@@ -131,7 +165,7 @@ function withCallInterceptor(interceptor, callback) {
|
|
|
131
165
|
doCall = oldValue;
|
|
132
166
|
}
|
|
133
167
|
}
|
|
134
|
-
var RAW_STUB = Symbol("realStub");
|
|
168
|
+
var RAW_STUB = /* @__PURE__ */ Symbol("realStub");
|
|
135
169
|
var PROXY_HANDLERS = {
|
|
136
170
|
apply(target, thisArg, argumentsList) {
|
|
137
171
|
let stub = target.raw;
|
|
@@ -307,10 +341,10 @@ async function pullPromise(promise) {
|
|
|
307
341
|
}
|
|
308
342
|
var RpcPayload = class _RpcPayload {
|
|
309
343
|
// Private constructor; use factory functions above to construct.
|
|
310
|
-
constructor(value, source,
|
|
344
|
+
constructor(value, source, hooks, promises) {
|
|
311
345
|
this.value = value;
|
|
312
346
|
this.source = source;
|
|
313
|
-
this.
|
|
347
|
+
this.hooks = hooks;
|
|
314
348
|
this.promises = promises;
|
|
315
349
|
}
|
|
316
350
|
// Create a payload from a value passed as params to an RPC from the app.
|
|
@@ -335,13 +369,13 @@ var RpcPayload = class _RpcPayload {
|
|
|
335
369
|
// stubs is transferred from the inputs to the outputs, hence if the output is disposed, the
|
|
336
370
|
// inputs should not be. (In case of exception, nothing is disposed, though.)
|
|
337
371
|
static fromArray(array) {
|
|
338
|
-
let
|
|
372
|
+
let hooks = [];
|
|
339
373
|
let promises = [];
|
|
340
374
|
let resultArray = [];
|
|
341
375
|
for (let payload of array) {
|
|
342
376
|
payload.ensureDeepCopied();
|
|
343
|
-
for (let
|
|
344
|
-
|
|
377
|
+
for (let hook of payload.hooks) {
|
|
378
|
+
hooks.push(hook);
|
|
345
379
|
}
|
|
346
380
|
for (let promise of payload.promises) {
|
|
347
381
|
if (promise.parent === payload) {
|
|
@@ -355,12 +389,12 @@ var RpcPayload = class _RpcPayload {
|
|
|
355
389
|
}
|
|
356
390
|
resultArray.push(payload.value);
|
|
357
391
|
}
|
|
358
|
-
return new _RpcPayload(resultArray, "owned",
|
|
392
|
+
return new _RpcPayload(resultArray, "owned", hooks, promises);
|
|
359
393
|
}
|
|
360
394
|
// Create a payload from a value parsed off the wire using Evaluator.evaluate().
|
|
361
395
|
//
|
|
362
|
-
// A payload is constructed with a null value and the given
|
|
363
|
-
// is expected to be filled in by the evaluator, and the
|
|
396
|
+
// A payload is constructed with a null value and the given hooks and promises arrays. The value
|
|
397
|
+
// is expected to be filled in by the evaluator, and the hooks and promises arrays are expected
|
|
364
398
|
// to be extended with stubs found during parsing. (This weird usage model is necessary so that
|
|
365
399
|
// if the root value turns out to be a promise, its `parent` in `promises` can be the payload
|
|
366
400
|
// object itself.)
|
|
@@ -368,8 +402,8 @@ var RpcPayload = class _RpcPayload {
|
|
|
368
402
|
// When done, the payload takes ownership of the final value and all the stubs within. It may
|
|
369
403
|
// modify the value in preparation for delivery, and may deliver the value directly to the app
|
|
370
404
|
// without copying.
|
|
371
|
-
static forEvaluate(
|
|
372
|
-
return new _RpcPayload(null, "owned",
|
|
405
|
+
static forEvaluate(hooks, promises) {
|
|
406
|
+
return new _RpcPayload(null, "owned", hooks, promises);
|
|
373
407
|
}
|
|
374
408
|
// Deep-copy the given value, including dup()ing all stubs.
|
|
375
409
|
//
|
|
@@ -391,14 +425,20 @@ var RpcPayload = class _RpcPayload {
|
|
|
391
425
|
return result;
|
|
392
426
|
}
|
|
393
427
|
// For `source === "return"` payloads only, this tracks any StubHooks created around RpcTargets
|
|
394
|
-
// found in the payload at the time that it is serialized (or deep-copied) for
|
|
395
|
-
// can make sure they are not disposed before the pipeline ends.
|
|
428
|
+
// or WritableStreams found in the payload at the time that it is serialized (or deep-copied) for
|
|
429
|
+
// return, so that we can make sure they are not disposed before the pipeline ends.
|
|
396
430
|
//
|
|
397
431
|
// This is initialized on first use.
|
|
398
432
|
rpcTargets;
|
|
399
433
|
// Get the StubHook representing the given RpcTarget found inside this payload.
|
|
400
434
|
getHookForRpcTarget(target, parent, dupStubs = true) {
|
|
401
435
|
if (this.source === "params") {
|
|
436
|
+
if (dupStubs) {
|
|
437
|
+
let dupable = target;
|
|
438
|
+
if (typeof dupable.dup === "function") {
|
|
439
|
+
target = dupable.dup();
|
|
440
|
+
}
|
|
441
|
+
}
|
|
402
442
|
return TargetStubHook.create(target, parent);
|
|
403
443
|
} else if (this.source === "return") {
|
|
404
444
|
let hook = this.rpcTargets?.get(target);
|
|
@@ -425,6 +465,64 @@ var RpcPayload = class _RpcPayload {
|
|
|
425
465
|
throw new Error("owned payload shouldn't contain raw RpcTargets");
|
|
426
466
|
}
|
|
427
467
|
}
|
|
468
|
+
// Get the StubHook representing the given WritableStream found inside this payload.
|
|
469
|
+
getHookForWritableStream(stream, parent, dupStubs = true) {
|
|
470
|
+
if (this.source === "params") {
|
|
471
|
+
return streamImpl.createWritableStreamHook(stream);
|
|
472
|
+
} else if (this.source === "return") {
|
|
473
|
+
let hook = this.rpcTargets?.get(stream);
|
|
474
|
+
if (hook) {
|
|
475
|
+
if (dupStubs) {
|
|
476
|
+
return hook.dup();
|
|
477
|
+
} else {
|
|
478
|
+
this.rpcTargets?.delete(stream);
|
|
479
|
+
return hook;
|
|
480
|
+
}
|
|
481
|
+
} else {
|
|
482
|
+
hook = streamImpl.createWritableStreamHook(stream);
|
|
483
|
+
if (dupStubs) {
|
|
484
|
+
if (!this.rpcTargets) {
|
|
485
|
+
this.rpcTargets = /* @__PURE__ */ new Map();
|
|
486
|
+
}
|
|
487
|
+
this.rpcTargets.set(stream, hook);
|
|
488
|
+
return hook.dup();
|
|
489
|
+
} else {
|
|
490
|
+
return hook;
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
} else {
|
|
494
|
+
throw new Error("owned payload shouldn't contain raw WritableStreams");
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
// Get the StubHook representing the given ReadableStream found inside this payload.
|
|
498
|
+
getHookForReadableStream(stream, parent, dupStubs = true) {
|
|
499
|
+
if (this.source === "params") {
|
|
500
|
+
return streamImpl.createReadableStreamHook(stream);
|
|
501
|
+
} else if (this.source === "return") {
|
|
502
|
+
let hook = this.rpcTargets?.get(stream);
|
|
503
|
+
if (hook) {
|
|
504
|
+
if (dupStubs) {
|
|
505
|
+
return hook.dup();
|
|
506
|
+
} else {
|
|
507
|
+
this.rpcTargets?.delete(stream);
|
|
508
|
+
return hook;
|
|
509
|
+
}
|
|
510
|
+
} else {
|
|
511
|
+
hook = streamImpl.createReadableStreamHook(stream);
|
|
512
|
+
if (dupStubs) {
|
|
513
|
+
if (!this.rpcTargets) {
|
|
514
|
+
this.rpcTargets = /* @__PURE__ */ new Map();
|
|
515
|
+
}
|
|
516
|
+
this.rpcTargets.set(stream, hook);
|
|
517
|
+
return hook.dup();
|
|
518
|
+
} else {
|
|
519
|
+
return hook;
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
} else {
|
|
523
|
+
throw new Error("owned payload shouldn't contain raw ReadableStreams");
|
|
524
|
+
}
|
|
525
|
+
}
|
|
428
526
|
deepCopy(value, oldParent, property, parent, dupStubs, owner) {
|
|
429
527
|
let kind = typeForRpc(value);
|
|
430
528
|
switch (kind) {
|
|
@@ -468,22 +566,21 @@ var RpcPayload = class _RpcPayload {
|
|
|
468
566
|
this.promises.push({ parent, property, promise });
|
|
469
567
|
return promise;
|
|
470
568
|
} else {
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
return newStub;
|
|
569
|
+
this.hooks.push(hook);
|
|
570
|
+
return new RpcStub(hook);
|
|
474
571
|
}
|
|
475
572
|
}
|
|
476
573
|
case "function":
|
|
477
574
|
case "rpc-target": {
|
|
478
575
|
let target = value;
|
|
479
|
-
let
|
|
576
|
+
let hook;
|
|
480
577
|
if (owner) {
|
|
481
|
-
|
|
578
|
+
hook = owner.getHookForRpcTarget(target, oldParent, dupStubs);
|
|
482
579
|
} else {
|
|
483
|
-
|
|
580
|
+
hook = TargetStubHook.create(target, oldParent);
|
|
484
581
|
}
|
|
485
|
-
this.
|
|
486
|
-
return
|
|
582
|
+
this.hooks.push(hook);
|
|
583
|
+
return new RpcStub(hook);
|
|
487
584
|
}
|
|
488
585
|
case "rpc-thenable": {
|
|
489
586
|
let target = value;
|
|
@@ -496,6 +593,28 @@ var RpcPayload = class _RpcPayload {
|
|
|
496
593
|
this.promises.push({ parent, property, promise });
|
|
497
594
|
return promise;
|
|
498
595
|
}
|
|
596
|
+
case "writable": {
|
|
597
|
+
let stream = value;
|
|
598
|
+
let hook;
|
|
599
|
+
if (owner) {
|
|
600
|
+
hook = owner.getHookForWritableStream(stream, oldParent, dupStubs);
|
|
601
|
+
} else {
|
|
602
|
+
hook = streamImpl.createWritableStreamHook(stream);
|
|
603
|
+
}
|
|
604
|
+
this.hooks.push(hook);
|
|
605
|
+
return stream;
|
|
606
|
+
}
|
|
607
|
+
case "readable": {
|
|
608
|
+
let stream = value;
|
|
609
|
+
let hook;
|
|
610
|
+
if (owner) {
|
|
611
|
+
hook = owner.getHookForReadableStream(stream, oldParent, dupStubs);
|
|
612
|
+
} else {
|
|
613
|
+
hook = streamImpl.createReadableStreamHook(stream);
|
|
614
|
+
}
|
|
615
|
+
this.hooks.push(hook);
|
|
616
|
+
return stream;
|
|
617
|
+
}
|
|
499
618
|
default:
|
|
500
619
|
throw new Error("unreachable");
|
|
501
620
|
}
|
|
@@ -505,12 +624,12 @@ var RpcPayload = class _RpcPayload {
|
|
|
505
624
|
ensureDeepCopied() {
|
|
506
625
|
if (this.source !== "owned") {
|
|
507
626
|
let dupStubs = this.source === "params";
|
|
508
|
-
this.
|
|
627
|
+
this.hooks = [];
|
|
509
628
|
this.promises = [];
|
|
510
629
|
try {
|
|
511
630
|
this.value = this.deepCopy(this.value, void 0, "value", this, dupStubs, this);
|
|
512
631
|
} catch (err) {
|
|
513
|
-
this.
|
|
632
|
+
this.hooks = void 0;
|
|
514
633
|
this.promises = void 0;
|
|
515
634
|
throw err;
|
|
516
635
|
}
|
|
@@ -613,7 +732,7 @@ var RpcPayload = class _RpcPayload {
|
|
|
613
732
|
}
|
|
614
733
|
dispose() {
|
|
615
734
|
if (this.source === "owned") {
|
|
616
|
-
this.
|
|
735
|
+
this.hooks.forEach((hook) => hook.dispose());
|
|
617
736
|
this.promises.forEach((promise) => promise.promise[Symbol.dispose]());
|
|
618
737
|
} else if (this.source === "return") {
|
|
619
738
|
this.disposeImpl(this.value, void 0);
|
|
@@ -622,7 +741,7 @@ var RpcPayload = class _RpcPayload {
|
|
|
622
741
|
}
|
|
623
742
|
} else ;
|
|
624
743
|
this.source = "owned";
|
|
625
|
-
this.
|
|
744
|
+
this.hooks = [];
|
|
626
745
|
this.promises = [];
|
|
627
746
|
}
|
|
628
747
|
// Recursive dispose, called only when `source` is "return".
|
|
@@ -675,6 +794,28 @@ var RpcPayload = class _RpcPayload {
|
|
|
675
794
|
}
|
|
676
795
|
case "rpc-thenable":
|
|
677
796
|
return;
|
|
797
|
+
case "writable": {
|
|
798
|
+
let stream = value;
|
|
799
|
+
let hook = this.rpcTargets?.get(stream);
|
|
800
|
+
if (hook) {
|
|
801
|
+
this.rpcTargets.delete(stream);
|
|
802
|
+
} else {
|
|
803
|
+
hook = streamImpl.createWritableStreamHook(stream);
|
|
804
|
+
}
|
|
805
|
+
hook.dispose();
|
|
806
|
+
return;
|
|
807
|
+
}
|
|
808
|
+
case "readable": {
|
|
809
|
+
let stream = value;
|
|
810
|
+
let hook = this.rpcTargets?.get(stream);
|
|
811
|
+
if (hook) {
|
|
812
|
+
this.rpcTargets.delete(stream);
|
|
813
|
+
} else {
|
|
814
|
+
hook = streamImpl.createReadableStreamHook(stream);
|
|
815
|
+
}
|
|
816
|
+
hook.dispose();
|
|
817
|
+
return;
|
|
818
|
+
}
|
|
678
819
|
default:
|
|
679
820
|
return;
|
|
680
821
|
}
|
|
@@ -683,9 +824,9 @@ var RpcPayload = class _RpcPayload {
|
|
|
683
824
|
// *would* be awaited if this payload were to be delivered. See the similarly-named method of
|
|
684
825
|
// StubHook for explanation.
|
|
685
826
|
ignoreUnhandledRejections() {
|
|
686
|
-
if (this.
|
|
687
|
-
this.
|
|
688
|
-
|
|
827
|
+
if (this.hooks) {
|
|
828
|
+
this.hooks.forEach((hook) => {
|
|
829
|
+
hook.ignoreUnhandledRejections();
|
|
689
830
|
});
|
|
690
831
|
this.promises.forEach(
|
|
691
832
|
(promise) => unwrapStubOrParent(promise.promise).ignoreUnhandledRejections()
|
|
@@ -706,6 +847,8 @@ var RpcPayload = class _RpcPayload {
|
|
|
706
847
|
case "undefined":
|
|
707
848
|
case "function":
|
|
708
849
|
case "rpc-target":
|
|
850
|
+
case "writable":
|
|
851
|
+
case "readable":
|
|
709
852
|
return;
|
|
710
853
|
case "array": {
|
|
711
854
|
let array = value;
|
|
@@ -778,6 +921,12 @@ function followPath(value, parent, path, owner) {
|
|
|
778
921
|
let { hook, pathIfPromise } = unwrapStubAndPath(value);
|
|
779
922
|
return { hook, remainingPath: pathIfPromise ? pathIfPromise.concat(path.slice(i)) : path.slice(i) };
|
|
780
923
|
}
|
|
924
|
+
case "writable":
|
|
925
|
+
value = void 0;
|
|
926
|
+
break;
|
|
927
|
+
case "readable":
|
|
928
|
+
value = void 0;
|
|
929
|
+
break;
|
|
781
930
|
case "primitive":
|
|
782
931
|
case "bigint":
|
|
783
932
|
case "bytes":
|
|
@@ -1017,6 +1166,14 @@ var PromiseStubHook = class _PromiseStubHook extends StubHook {
|
|
|
1017
1166
|
args.ensureDeepCopied();
|
|
1018
1167
|
return new _PromiseStubHook(this.promise.then((hook) => hook.call(path, args)));
|
|
1019
1168
|
}
|
|
1169
|
+
stream(path, args) {
|
|
1170
|
+
args.ensureDeepCopied();
|
|
1171
|
+
let promise = this.promise.then((hook) => {
|
|
1172
|
+
let result = hook.stream(path, args);
|
|
1173
|
+
return result.promise;
|
|
1174
|
+
});
|
|
1175
|
+
return { promise };
|
|
1176
|
+
}
|
|
1020
1177
|
map(path, captures, instructions) {
|
|
1021
1178
|
return new _PromiseStubHook(this.promise.then(
|
|
1022
1179
|
(hook) => hook.map(path, captures, instructions),
|
|
@@ -1089,6 +1246,9 @@ var NullExporter = class {
|
|
|
1089
1246
|
}
|
|
1090
1247
|
unexport(ids) {
|
|
1091
1248
|
}
|
|
1249
|
+
createPipe(readable) {
|
|
1250
|
+
throw new Error("Cannot create pipes without an RPC session.");
|
|
1251
|
+
}
|
|
1092
1252
|
onSendError(error) {
|
|
1093
1253
|
}
|
|
1094
1254
|
};
|
|
@@ -1247,6 +1407,22 @@ var Devaluator = class _Devaluator {
|
|
|
1247
1407
|
let hook = this.source.getHookForRpcTarget(value, parent);
|
|
1248
1408
|
return this.devaluateHook("promise", hook);
|
|
1249
1409
|
}
|
|
1410
|
+
case "writable": {
|
|
1411
|
+
if (!this.source) {
|
|
1412
|
+
throw new Error("Can't serialize WritableStream in this context.");
|
|
1413
|
+
}
|
|
1414
|
+
let hook = this.source.getHookForWritableStream(value, parent);
|
|
1415
|
+
return this.devaluateHook("writable", hook);
|
|
1416
|
+
}
|
|
1417
|
+
case "readable": {
|
|
1418
|
+
if (!this.source) {
|
|
1419
|
+
throw new Error("Can't serialize ReadableStream in this context.");
|
|
1420
|
+
}
|
|
1421
|
+
let ws = value;
|
|
1422
|
+
let hook = this.source.getHookForReadableStream(ws, parent);
|
|
1423
|
+
let importId = this.exporter.createPipe(ws, hook);
|
|
1424
|
+
return ["readable", importId];
|
|
1425
|
+
}
|
|
1250
1426
|
default:
|
|
1251
1427
|
throw new Error("unreachable");
|
|
1252
1428
|
}
|
|
@@ -1271,16 +1447,19 @@ var NullImporter = class {
|
|
|
1271
1447
|
getExport(idx) {
|
|
1272
1448
|
return void 0;
|
|
1273
1449
|
}
|
|
1450
|
+
getPipeReadable(exportId) {
|
|
1451
|
+
throw new Error("Cannot retrieve pipe readable without an RPC session.");
|
|
1452
|
+
}
|
|
1274
1453
|
};
|
|
1275
1454
|
var NULL_IMPORTER = new NullImporter();
|
|
1276
1455
|
var Evaluator = class _Evaluator {
|
|
1277
1456
|
constructor(importer) {
|
|
1278
1457
|
this.importer = importer;
|
|
1279
1458
|
}
|
|
1280
|
-
|
|
1459
|
+
hooks = [];
|
|
1281
1460
|
promises = [];
|
|
1282
1461
|
evaluate(value) {
|
|
1283
|
-
let payload = RpcPayload.forEvaluate(this.
|
|
1462
|
+
let payload = RpcPayload.forEvaluate(this.hooks, this.promises);
|
|
1284
1463
|
try {
|
|
1285
1464
|
payload.value = this.evaluateImpl(value, payload, "value");
|
|
1286
1465
|
return payload;
|
|
@@ -1369,9 +1548,8 @@ var Evaluator = class _Evaluator {
|
|
|
1369
1548
|
this.promises.push({ promise, parent, property });
|
|
1370
1549
|
return promise;
|
|
1371
1550
|
} else {
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
return stub;
|
|
1551
|
+
this.hooks.push(hook2);
|
|
1552
|
+
return new RpcPromise(hook2, []);
|
|
1375
1553
|
}
|
|
1376
1554
|
};
|
|
1377
1555
|
if (value.length == 2) {
|
|
@@ -1449,12 +1627,27 @@ var Evaluator = class _Evaluator {
|
|
|
1449
1627
|
return promise;
|
|
1450
1628
|
} else {
|
|
1451
1629
|
let hook = this.importer.importStub(value[1]);
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
return stub;
|
|
1630
|
+
this.hooks.push(hook);
|
|
1631
|
+
return new RpcStub(hook);
|
|
1455
1632
|
}
|
|
1456
1633
|
}
|
|
1457
1634
|
break;
|
|
1635
|
+
case "writable":
|
|
1636
|
+
if (typeof value[1] == "number") {
|
|
1637
|
+
let hook = this.importer.importStub(value[1]);
|
|
1638
|
+
let stream = streamImpl.createWritableStreamFromHook(hook);
|
|
1639
|
+
this.hooks.push(hook);
|
|
1640
|
+
return stream;
|
|
1641
|
+
}
|
|
1642
|
+
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;
|
|
1458
1651
|
}
|
|
1459
1652
|
throw new TypeError(`unknown special value: ${JSON.stringify(value)}`);
|
|
1460
1653
|
} else if (value instanceof Object) {
|
|
@@ -1594,6 +1787,14 @@ var RpcImportHook = class _RpcImportHook extends StubHook {
|
|
|
1594
1787
|
return entry.session.sendCall(entry.importId, path, args);
|
|
1595
1788
|
}
|
|
1596
1789
|
}
|
|
1790
|
+
stream(path, args) {
|
|
1791
|
+
let entry = this.getEntry();
|
|
1792
|
+
if (entry.resolution) {
|
|
1793
|
+
return entry.resolution.stream(path, args);
|
|
1794
|
+
} else {
|
|
1795
|
+
return entry.session.sendStream(entry.importId, path, args);
|
|
1796
|
+
}
|
|
1797
|
+
}
|
|
1597
1798
|
map(path, captures, instructions) {
|
|
1598
1799
|
let entry;
|
|
1599
1800
|
try {
|
|
@@ -1766,19 +1967,23 @@ var RpcSessionImpl = class {
|
|
|
1766
1967
|
return payload;
|
|
1767
1968
|
}
|
|
1768
1969
|
};
|
|
1970
|
+
let autoRelease = exp.autoRelease;
|
|
1769
1971
|
++this.pullCount;
|
|
1770
1972
|
exp.pull = resolve().then(
|
|
1771
1973
|
(payload) => {
|
|
1772
1974
|
let value = Devaluator.devaluate(payload.value, void 0, this, payload);
|
|
1773
1975
|
this.send(["resolve", exportId, value]);
|
|
1976
|
+
if (autoRelease) this.releaseExport(exportId, 1);
|
|
1774
1977
|
},
|
|
1775
1978
|
(error) => {
|
|
1776
1979
|
this.send(["reject", exportId, Devaluator.devaluate(error, void 0, this)]);
|
|
1980
|
+
if (autoRelease) this.releaseExport(exportId, 1);
|
|
1777
1981
|
}
|
|
1778
1982
|
).catch(
|
|
1779
1983
|
(error) => {
|
|
1780
1984
|
try {
|
|
1781
1985
|
this.send(["reject", exportId, Devaluator.devaluate(error, void 0, this)]);
|
|
1986
|
+
if (autoRelease) this.releaseExport(exportId, 1);
|
|
1782
1987
|
} catch (error2) {
|
|
1783
1988
|
this.abort(error2);
|
|
1784
1989
|
}
|
|
@@ -1830,9 +2035,35 @@ var RpcSessionImpl = class {
|
|
|
1830
2035
|
getExport(idx) {
|
|
1831
2036
|
return this.exports[idx]?.hook;
|
|
1832
2037
|
}
|
|
2038
|
+
getPipeReadable(exportId) {
|
|
2039
|
+
let entry = this.exports[exportId];
|
|
2040
|
+
if (!entry || !entry.pipeReadable) {
|
|
2041
|
+
throw new Error(`Export ${exportId} is not a pipe or its readable end was already consumed.`);
|
|
2042
|
+
}
|
|
2043
|
+
let readable = entry.pipeReadable;
|
|
2044
|
+
entry.pipeReadable = void 0;
|
|
2045
|
+
return readable;
|
|
2046
|
+
}
|
|
2047
|
+
createPipe(readable, readableHook) {
|
|
2048
|
+
if (this.abortReason) throw this.abortReason;
|
|
2049
|
+
this.send(["pipe"]);
|
|
2050
|
+
let importId = this.imports.length;
|
|
2051
|
+
let entry = new ImportTableEntry(this, importId, false);
|
|
2052
|
+
this.imports.push(entry);
|
|
2053
|
+
let hook = new RpcImportHook(
|
|
2054
|
+
/*isPromise=*/
|
|
2055
|
+
false,
|
|
2056
|
+
entry
|
|
2057
|
+
);
|
|
2058
|
+
let writable = streamImpl.createWritableStreamFromHook(hook);
|
|
2059
|
+
readable.pipeTo(writable).catch(() => {
|
|
2060
|
+
}).finally(() => readableHook.dispose());
|
|
2061
|
+
return importId;
|
|
2062
|
+
}
|
|
2063
|
+
// Serializes and sends a message. Returns the byte length of the serialized message.
|
|
1833
2064
|
send(msg) {
|
|
1834
2065
|
if (this.abortReason !== void 0) {
|
|
1835
|
-
return;
|
|
2066
|
+
return 0;
|
|
1836
2067
|
}
|
|
1837
2068
|
let msgText;
|
|
1838
2069
|
try {
|
|
@@ -1845,6 +2076,7 @@ var RpcSessionImpl = class {
|
|
|
1845
2076
|
throw err;
|
|
1846
2077
|
}
|
|
1847
2078
|
this.transport.send(msgText).catch((err) => this.abort(err, false));
|
|
2079
|
+
return msgText.length;
|
|
1848
2080
|
}
|
|
1849
2081
|
sendCall(id, path, args) {
|
|
1850
2082
|
if (this.abortReason) throw this.abortReason;
|
|
@@ -1862,6 +2094,34 @@ var RpcSessionImpl = class {
|
|
|
1862
2094
|
entry
|
|
1863
2095
|
);
|
|
1864
2096
|
}
|
|
2097
|
+
sendStream(id, path, args) {
|
|
2098
|
+
if (this.abortReason) throw this.abortReason;
|
|
2099
|
+
let value = ["pipeline", id, path];
|
|
2100
|
+
let devalue = Devaluator.devaluate(args.value, void 0, this, args);
|
|
2101
|
+
value.push(devalue[0]);
|
|
2102
|
+
let size = this.send(["stream", value]);
|
|
2103
|
+
let importId = this.imports.length;
|
|
2104
|
+
let entry = new ImportTableEntry(
|
|
2105
|
+
this,
|
|
2106
|
+
importId,
|
|
2107
|
+
/*pulling=*/
|
|
2108
|
+
true
|
|
2109
|
+
);
|
|
2110
|
+
entry.remoteRefcount = 0;
|
|
2111
|
+
entry.localRefcount = 1;
|
|
2112
|
+
this.imports.push(entry);
|
|
2113
|
+
let promise = entry.awaitResolution().then(
|
|
2114
|
+
(p) => {
|
|
2115
|
+
p.dispose();
|
|
2116
|
+
delete this.imports[importId];
|
|
2117
|
+
},
|
|
2118
|
+
(err) => {
|
|
2119
|
+
delete this.imports[importId];
|
|
2120
|
+
throw err;
|
|
2121
|
+
}
|
|
2122
|
+
);
|
|
2123
|
+
return { promise, size };
|
|
2124
|
+
}
|
|
1865
2125
|
sendMap(id, path, captures, instructions) {
|
|
1866
2126
|
if (this.abortReason) {
|
|
1867
2127
|
for (let cap of captures) {
|
|
@@ -1949,6 +2209,24 @@ var RpcSessionImpl = class {
|
|
|
1949
2209
|
continue;
|
|
1950
2210
|
}
|
|
1951
2211
|
break;
|
|
2212
|
+
case "stream": {
|
|
2213
|
+
if (msg.length > 1) {
|
|
2214
|
+
let payload = new Evaluator(this).evaluate(msg[1]);
|
|
2215
|
+
let hook = new PayloadStubHook(payload);
|
|
2216
|
+
hook.ignoreUnhandledRejections();
|
|
2217
|
+
let exportId = this.exports.length;
|
|
2218
|
+
this.exports.push({ hook, refcount: 1, autoRelease: true });
|
|
2219
|
+
this.ensureResolvingExport(exportId);
|
|
2220
|
+
continue;
|
|
2221
|
+
}
|
|
2222
|
+
break;
|
|
2223
|
+
}
|
|
2224
|
+
case "pipe": {
|
|
2225
|
+
let { readable, writable } = new TransformStream();
|
|
2226
|
+
let hook = streamImpl.createWritableStreamHook(writable);
|
|
2227
|
+
this.exports.push({ hook, refcount: 1, pipeReadable: readable });
|
|
2228
|
+
continue;
|
|
2229
|
+
}
|
|
1952
2230
|
case "pull": {
|
|
1953
2231
|
let exportId = msg[1];
|
|
1954
2232
|
if (typeof exportId == "number") {
|
|
@@ -2444,6 +2722,9 @@ var MapBuilder = class {
|
|
|
2444
2722
|
}
|
|
2445
2723
|
unexport(ids) {
|
|
2446
2724
|
}
|
|
2725
|
+
createPipe(readable) {
|
|
2726
|
+
throw new Error("Cannot send ReadableStream inside a mapper function.");
|
|
2727
|
+
}
|
|
2447
2728
|
onSendError(error) {
|
|
2448
2729
|
}
|
|
2449
2730
|
};
|
|
@@ -2553,6 +2834,9 @@ var MapApplicator = class {
|
|
|
2553
2834
|
return this.variables[idx];
|
|
2554
2835
|
}
|
|
2555
2836
|
}
|
|
2837
|
+
getPipeReadable(exportId) {
|
|
2838
|
+
throw new Error("A mapper function cannot use pipe readables.");
|
|
2839
|
+
}
|
|
2556
2840
|
};
|
|
2557
2841
|
function applyMapToElement(input, parent, owner, captures, instructions) {
|
|
2558
2842
|
let inputHook = new PayloadStubHook(RpcPayload.deepCopyFrom(input, parent, owner));
|
|
@@ -2593,6 +2877,333 @@ mapImpl.applyMap = (input, parent, owner, captures, instructions) => {
|
|
|
2593
2877
|
}
|
|
2594
2878
|
}
|
|
2595
2879
|
};
|
|
2880
|
+
|
|
2881
|
+
// src/streams.ts
|
|
2882
|
+
var WritableStreamStubHook = class _WritableStreamStubHook extends StubHook {
|
|
2883
|
+
state;
|
|
2884
|
+
// undefined when disposed
|
|
2885
|
+
// Creates a new WritableStreamStubHook that is not duplicated from an existing hook.
|
|
2886
|
+
static create(stream) {
|
|
2887
|
+
let writer = stream.getWriter();
|
|
2888
|
+
return new _WritableStreamStubHook({ refcount: 1, writer, closed: false });
|
|
2889
|
+
}
|
|
2890
|
+
constructor(state, dupFrom) {
|
|
2891
|
+
super();
|
|
2892
|
+
this.state = state;
|
|
2893
|
+
if (dupFrom) {
|
|
2894
|
+
++state.refcount;
|
|
2895
|
+
}
|
|
2896
|
+
}
|
|
2897
|
+
getState() {
|
|
2898
|
+
if (this.state) {
|
|
2899
|
+
return this.state;
|
|
2900
|
+
} else {
|
|
2901
|
+
throw new Error("Attempted to use a WritableStreamStubHook after it was disposed.");
|
|
2902
|
+
}
|
|
2903
|
+
}
|
|
2904
|
+
call(path, args) {
|
|
2905
|
+
try {
|
|
2906
|
+
let state = this.getState();
|
|
2907
|
+
if (path.length !== 1 || typeof path[0] !== "string") {
|
|
2908
|
+
throw new Error("WritableStream stub only supports direct method calls");
|
|
2909
|
+
}
|
|
2910
|
+
const method = path[0];
|
|
2911
|
+
if (method !== "write" && method !== "close" && method !== "abort") {
|
|
2912
|
+
args.dispose();
|
|
2913
|
+
throw new Error(`Unknown WritableStream method: ${method}`);
|
|
2914
|
+
}
|
|
2915
|
+
if (method === "close" || method === "abort") {
|
|
2916
|
+
state.closed = true;
|
|
2917
|
+
}
|
|
2918
|
+
let func = state.writer[method];
|
|
2919
|
+
let promise = args.deliverCall(func, state.writer);
|
|
2920
|
+
return new PromiseStubHook(promise.then((payload) => new PayloadStubHook(payload)));
|
|
2921
|
+
} catch (err) {
|
|
2922
|
+
return new ErrorStubHook(err);
|
|
2923
|
+
}
|
|
2924
|
+
}
|
|
2925
|
+
map(path, captures, instructions) {
|
|
2926
|
+
for (let cap of captures) {
|
|
2927
|
+
cap.dispose();
|
|
2928
|
+
}
|
|
2929
|
+
return new ErrorStubHook(new Error("Cannot use map() on a WritableStream"));
|
|
2930
|
+
}
|
|
2931
|
+
get(path) {
|
|
2932
|
+
return new ErrorStubHook(new Error("Cannot access properties on a WritableStream stub"));
|
|
2933
|
+
}
|
|
2934
|
+
dup() {
|
|
2935
|
+
let state = this.getState();
|
|
2936
|
+
return new _WritableStreamStubHook(state, this);
|
|
2937
|
+
}
|
|
2938
|
+
pull() {
|
|
2939
|
+
return Promise.reject(new Error("Cannot pull a WritableStream stub"));
|
|
2940
|
+
}
|
|
2941
|
+
ignoreUnhandledRejections() {
|
|
2942
|
+
}
|
|
2943
|
+
dispose() {
|
|
2944
|
+
let state = this.state;
|
|
2945
|
+
this.state = void 0;
|
|
2946
|
+
if (state) {
|
|
2947
|
+
if (--state.refcount === 0) {
|
|
2948
|
+
if (!state.closed) {
|
|
2949
|
+
state.writer.abort(new Error("WritableStream RPC stub was disposed without calling close()")).catch(() => {
|
|
2950
|
+
});
|
|
2951
|
+
}
|
|
2952
|
+
state.writer.releaseLock();
|
|
2953
|
+
}
|
|
2954
|
+
}
|
|
2955
|
+
}
|
|
2956
|
+
onBroken(callback) {
|
|
2957
|
+
}
|
|
2958
|
+
};
|
|
2959
|
+
var INITIAL_WINDOW = 256 * 1024;
|
|
2960
|
+
var MAX_WINDOW = 1024 * 1024 * 1024;
|
|
2961
|
+
var MIN_WINDOW = 64 * 1024;
|
|
2962
|
+
var STARTUP_GROWTH_FACTOR = 2;
|
|
2963
|
+
var STEADY_GROWTH_FACTOR = 1.25;
|
|
2964
|
+
var DECAY_FACTOR = 0.9;
|
|
2965
|
+
var STARTUP_EXIT_ROUNDS = 3;
|
|
2966
|
+
var FlowController = class {
|
|
2967
|
+
constructor(now) {
|
|
2968
|
+
this.now = now;
|
|
2969
|
+
}
|
|
2970
|
+
// The current window size in bytes. The sender blocks when bytesInFlight >= window.
|
|
2971
|
+
window = INITIAL_WINDOW;
|
|
2972
|
+
// Total bytes currently in flight (sent but not yet acked).
|
|
2973
|
+
bytesInFlight = 0;
|
|
2974
|
+
// Whether we're still in the startup phase.
|
|
2975
|
+
inStartupPhase = true;
|
|
2976
|
+
// ----- BDP estimation state (private) -----
|
|
2977
|
+
// Total bytes acked so far.
|
|
2978
|
+
delivered = 0;
|
|
2979
|
+
// Time of most recent ack.
|
|
2980
|
+
deliveredTime = 0;
|
|
2981
|
+
// Time when the very first ack was received.
|
|
2982
|
+
firstAckTime = 0;
|
|
2983
|
+
firstAckDelivered = 0;
|
|
2984
|
+
// Global minimum RTT observed (milliseconds).
|
|
2985
|
+
minRtt = Infinity;
|
|
2986
|
+
// For startup exit: count of consecutive RTT rounds where the window didn't meaningfully grow.
|
|
2987
|
+
roundsWithoutIncrease = 0;
|
|
2988
|
+
// Window size at the start of the current round, for startup exit detection.
|
|
2989
|
+
lastRoundWindow = 0;
|
|
2990
|
+
// Time when the current round started.
|
|
2991
|
+
roundStartTime = 0;
|
|
2992
|
+
// Called when a write of `size` bytes is about to be sent. Returns a token that must be
|
|
2993
|
+
// passed to onAck() when the ack arrives, and whether the sender should block (window full).
|
|
2994
|
+
onSend(size) {
|
|
2995
|
+
this.bytesInFlight += size;
|
|
2996
|
+
let token = {
|
|
2997
|
+
sentTime: this.now(),
|
|
2998
|
+
size,
|
|
2999
|
+
deliveredAtSend: this.delivered,
|
|
3000
|
+
deliveredTimeAtSend: this.deliveredTime,
|
|
3001
|
+
windowAtSend: this.window,
|
|
3002
|
+
windowFullAtSend: this.bytesInFlight >= this.window
|
|
3003
|
+
};
|
|
3004
|
+
return { token, shouldBlock: token.windowFullAtSend };
|
|
3005
|
+
}
|
|
3006
|
+
// Called when a previously-sent write fails. Restores bytesInFlight without updating
|
|
3007
|
+
// any BDP estimates.
|
|
3008
|
+
onError(token) {
|
|
3009
|
+
this.bytesInFlight -= token.size;
|
|
3010
|
+
}
|
|
3011
|
+
// Called when an ack is received for a previously-sent write. Updates BDP estimates and
|
|
3012
|
+
// the window. Returns whether a blocked sender should now unblock.
|
|
3013
|
+
onAck(token) {
|
|
3014
|
+
let ackTime = this.now();
|
|
3015
|
+
this.delivered += token.size;
|
|
3016
|
+
this.deliveredTime = ackTime;
|
|
3017
|
+
this.bytesInFlight -= token.size;
|
|
3018
|
+
let rtt = ackTime - token.sentTime;
|
|
3019
|
+
this.minRtt = Math.min(this.minRtt, rtt);
|
|
3020
|
+
if (this.firstAckTime === 0) {
|
|
3021
|
+
this.firstAckTime = ackTime;
|
|
3022
|
+
this.firstAckDelivered = this.delivered;
|
|
3023
|
+
} else {
|
|
3024
|
+
let baseTime;
|
|
3025
|
+
let baseDelivered;
|
|
3026
|
+
if (token.deliveredTimeAtSend === 0) {
|
|
3027
|
+
baseTime = this.firstAckTime;
|
|
3028
|
+
baseDelivered = this.firstAckDelivered;
|
|
3029
|
+
} else {
|
|
3030
|
+
baseTime = token.deliveredTimeAtSend;
|
|
3031
|
+
baseDelivered = token.deliveredAtSend;
|
|
3032
|
+
}
|
|
3033
|
+
let interval = ackTime - baseTime;
|
|
3034
|
+
let bytes = this.delivered - baseDelivered;
|
|
3035
|
+
let bandwidth = bytes / interval;
|
|
3036
|
+
let growthFactor = this.inStartupPhase ? STARTUP_GROWTH_FACTOR : STEADY_GROWTH_FACTOR;
|
|
3037
|
+
let newWindow = bandwidth * this.minRtt * growthFactor;
|
|
3038
|
+
newWindow = Math.min(newWindow, token.windowAtSend * growthFactor);
|
|
3039
|
+
if (token.windowFullAtSend) {
|
|
3040
|
+
newWindow = Math.max(newWindow, token.windowAtSend * DECAY_FACTOR);
|
|
3041
|
+
} else {
|
|
3042
|
+
newWindow = Math.max(newWindow, this.window);
|
|
3043
|
+
}
|
|
3044
|
+
this.window = Math.max(Math.min(newWindow, MAX_WINDOW), MIN_WINDOW);
|
|
3045
|
+
if (this.inStartupPhase && token.sentTime >= this.roundStartTime) {
|
|
3046
|
+
if (this.window > this.lastRoundWindow * STEADY_GROWTH_FACTOR) {
|
|
3047
|
+
this.roundsWithoutIncrease = 0;
|
|
3048
|
+
} else {
|
|
3049
|
+
if (++this.roundsWithoutIncrease >= STARTUP_EXIT_ROUNDS) {
|
|
3050
|
+
this.inStartupPhase = false;
|
|
3051
|
+
}
|
|
3052
|
+
}
|
|
3053
|
+
this.roundStartTime = ackTime;
|
|
3054
|
+
this.lastRoundWindow = this.window;
|
|
3055
|
+
}
|
|
3056
|
+
}
|
|
3057
|
+
return this.bytesInFlight < this.window;
|
|
3058
|
+
}
|
|
3059
|
+
};
|
|
3060
|
+
function createWritableStreamFromHook(hook) {
|
|
3061
|
+
let pendingError = void 0;
|
|
3062
|
+
let hookDisposed = false;
|
|
3063
|
+
let fc = new FlowController(() => performance.now());
|
|
3064
|
+
let windowResolve;
|
|
3065
|
+
let windowReject;
|
|
3066
|
+
const disposeHook = () => {
|
|
3067
|
+
if (!hookDisposed) {
|
|
3068
|
+
hookDisposed = true;
|
|
3069
|
+
hook.dispose();
|
|
3070
|
+
}
|
|
3071
|
+
};
|
|
3072
|
+
return new WritableStream({
|
|
3073
|
+
write(chunk, controller) {
|
|
3074
|
+
if (pendingError !== void 0) {
|
|
3075
|
+
throw pendingError;
|
|
3076
|
+
}
|
|
3077
|
+
const payload = RpcPayload.fromAppParams([chunk]);
|
|
3078
|
+
const { promise, size } = hook.stream(["write"], payload);
|
|
3079
|
+
if (size === void 0) {
|
|
3080
|
+
return promise.catch((err) => {
|
|
3081
|
+
if (pendingError === void 0) {
|
|
3082
|
+
pendingError = err;
|
|
3083
|
+
}
|
|
3084
|
+
throw err;
|
|
3085
|
+
});
|
|
3086
|
+
} else {
|
|
3087
|
+
let { token, shouldBlock } = fc.onSend(size);
|
|
3088
|
+
promise.then(() => {
|
|
3089
|
+
let hasCapacity = fc.onAck(token);
|
|
3090
|
+
if (hasCapacity && windowResolve) {
|
|
3091
|
+
windowResolve();
|
|
3092
|
+
windowResolve = void 0;
|
|
3093
|
+
windowReject = void 0;
|
|
3094
|
+
}
|
|
3095
|
+
}, (err) => {
|
|
3096
|
+
fc.onError(token);
|
|
3097
|
+
if (pendingError === void 0) {
|
|
3098
|
+
pendingError = err;
|
|
3099
|
+
controller.error(err);
|
|
3100
|
+
disposeHook();
|
|
3101
|
+
}
|
|
3102
|
+
if (windowReject) {
|
|
3103
|
+
windowReject(err);
|
|
3104
|
+
windowResolve = void 0;
|
|
3105
|
+
windowReject = void 0;
|
|
3106
|
+
}
|
|
3107
|
+
});
|
|
3108
|
+
if (shouldBlock) {
|
|
3109
|
+
return new Promise((resolve, reject) => {
|
|
3110
|
+
windowResolve = resolve;
|
|
3111
|
+
windowReject = reject;
|
|
3112
|
+
});
|
|
3113
|
+
}
|
|
3114
|
+
}
|
|
3115
|
+
},
|
|
3116
|
+
async close() {
|
|
3117
|
+
if (pendingError !== void 0) {
|
|
3118
|
+
disposeHook();
|
|
3119
|
+
throw pendingError;
|
|
3120
|
+
}
|
|
3121
|
+
const { promise } = hook.stream(["close"], RpcPayload.fromAppParams([]));
|
|
3122
|
+
try {
|
|
3123
|
+
await promise;
|
|
3124
|
+
} catch (err) {
|
|
3125
|
+
throw pendingError ?? err;
|
|
3126
|
+
} finally {
|
|
3127
|
+
disposeHook();
|
|
3128
|
+
}
|
|
3129
|
+
},
|
|
3130
|
+
abort(reason) {
|
|
3131
|
+
if (pendingError !== void 0) {
|
|
3132
|
+
return;
|
|
3133
|
+
}
|
|
3134
|
+
pendingError = reason ?? new Error("WritableStream was aborted");
|
|
3135
|
+
if (windowReject) {
|
|
3136
|
+
windowReject(pendingError);
|
|
3137
|
+
windowResolve = void 0;
|
|
3138
|
+
windowReject = void 0;
|
|
3139
|
+
}
|
|
3140
|
+
const { promise } = hook.stream(["abort"], RpcPayload.fromAppParams([reason]));
|
|
3141
|
+
promise.then(() => disposeHook(), () => disposeHook());
|
|
3142
|
+
}
|
|
3143
|
+
});
|
|
3144
|
+
}
|
|
3145
|
+
var ReadableStreamStubHook = class _ReadableStreamStubHook extends StubHook {
|
|
3146
|
+
state;
|
|
3147
|
+
// undefined when disposed
|
|
3148
|
+
// Creates a new ReadableStreamStubHook.
|
|
3149
|
+
static create(stream) {
|
|
3150
|
+
return new _ReadableStreamStubHook({ refcount: 1, stream, canceled: false });
|
|
3151
|
+
}
|
|
3152
|
+
constructor(state, dupFrom) {
|
|
3153
|
+
super();
|
|
3154
|
+
this.state = state;
|
|
3155
|
+
if (dupFrom) {
|
|
3156
|
+
++state.refcount;
|
|
3157
|
+
}
|
|
3158
|
+
}
|
|
3159
|
+
call(path, args) {
|
|
3160
|
+
args.dispose();
|
|
3161
|
+
return new ErrorStubHook(new Error("Cannot call methods on a ReadableStream stub"));
|
|
3162
|
+
}
|
|
3163
|
+
map(path, captures, instructions) {
|
|
3164
|
+
for (let cap of captures) {
|
|
3165
|
+
cap.dispose();
|
|
3166
|
+
}
|
|
3167
|
+
return new ErrorStubHook(new Error("Cannot use map() on a ReadableStream"));
|
|
3168
|
+
}
|
|
3169
|
+
get(path) {
|
|
3170
|
+
return new ErrorStubHook(new Error("Cannot access properties on a ReadableStream stub"));
|
|
3171
|
+
}
|
|
3172
|
+
dup() {
|
|
3173
|
+
let state = this.state;
|
|
3174
|
+
if (!state) {
|
|
3175
|
+
throw new Error("Attempted to dup a ReadableStreamStubHook after it was disposed.");
|
|
3176
|
+
}
|
|
3177
|
+
return new _ReadableStreamStubHook(state, this);
|
|
3178
|
+
}
|
|
3179
|
+
pull() {
|
|
3180
|
+
return Promise.reject(new Error("Cannot pull a ReadableStream stub"));
|
|
3181
|
+
}
|
|
3182
|
+
ignoreUnhandledRejections() {
|
|
3183
|
+
}
|
|
3184
|
+
dispose() {
|
|
3185
|
+
let state = this.state;
|
|
3186
|
+
this.state = void 0;
|
|
3187
|
+
if (state) {
|
|
3188
|
+
if (--state.refcount === 0) {
|
|
3189
|
+
if (!state.canceled) {
|
|
3190
|
+
state.canceled = true;
|
|
3191
|
+
if (!state.stream.locked) {
|
|
3192
|
+
state.stream.cancel(
|
|
3193
|
+
new Error("ReadableStream RPC stub was disposed without being consumed")
|
|
3194
|
+
).catch(() => {
|
|
3195
|
+
});
|
|
3196
|
+
}
|
|
3197
|
+
}
|
|
3198
|
+
}
|
|
3199
|
+
}
|
|
3200
|
+
}
|
|
3201
|
+
onBroken(callback) {
|
|
3202
|
+
}
|
|
3203
|
+
};
|
|
3204
|
+
streamImpl.createWritableStreamHook = WritableStreamStubHook.create;
|
|
3205
|
+
streamImpl.createWritableStreamFromHook = createWritableStreamFromHook;
|
|
3206
|
+
streamImpl.createReadableStreamHook = ReadableStreamStubHook.create;
|
|
2596
3207
|
var RpcStub2 = RpcStub;
|
|
2597
3208
|
var RpcPromise2 = RpcPromise;
|
|
2598
3209
|
var RpcSession2 = RpcSession;
|