@stryke/capnp 0.4.5 → 0.6.0

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/rpc.js CHANGED
@@ -1,4543 +1,12 @@
1
1
  import {
2
- AnyStruct,
3
- CompositeList,
4
- Data,
5
- ErrorAnswer,
6
- ErrorClient,
7
- FixedAnswer,
8
- INVARIANT_UNREACHABLE_CODE,
9
- List,
10
- ListElementSize,
11
- MAX_DEPTH,
2
+ Conn,
3
+ Deferred,
4
+ DeferredTransport
5
+ } from "./chunk-I2TLOFS6.js";
6
+ import {
12
7
  Message,
13
- NOT_IMPLEMENTED,
14
- ObjectSize,
15
- Pointer,
16
- PointerType,
17
- RPC_BAD_TARGET,
18
- RPC_CALL_QUEUE_FULL,
19
- RPC_ERROR,
20
- RPC_FINISH_UNKNOWN_ANSWER,
21
- RPC_FULFILL_ALREADY_CALLED,
22
- RPC_IMPORT_CLOSED,
23
- RPC_METHOD_ERROR,
24
- RPC_NO_MAIN_INTERFACE,
25
- RPC_NULL_CLIENT,
26
- RPC_QUESTION_ID_REUSED,
27
- RPC_QUEUE_CALL_CANCEL,
28
- RPC_RETURN_FOR_UNKNOWN_QUESTION,
29
- RPC_UNKNOWN_ANSWER_ID,
30
- RPC_UNKNOWN_CAP_DESCRIPTOR,
31
- RPC_UNKNOWN_EXPORT_ID,
32
- RPC_ZERO_REF,
33
- Struct,
34
- Text,
35
- __name,
36
- adopt,
37
- copyFrom,
38
- disown,
39
- format,
40
- getAs,
41
- getBit,
42
- getBitMask,
43
- getContent,
44
- getInterfaceClientOrNull,
45
- getList,
46
- getPointer,
47
- getStruct,
48
- getTargetPointerType,
49
- getText,
50
- getUint16,
51
- getUint32,
52
- getUint64,
53
- getUint8,
54
- getUint8Mask,
55
- initList,
56
- initStruct,
57
- initStructAt,
58
- isNull,
59
- setBit,
60
- setText,
61
- setUint16,
62
- setUint32,
63
- setUint64,
64
- setUint8,
65
- testWhich
66
- } from "./chunk-U3UL3P5H.js";
67
-
68
- // ../../node_modules/.pnpm/capnp-es@0.0.11_patch_hash=53996ae63a1465953815fff49405f2224c85d26eeeff469d2b1f87e1c2af451d_typescript@5.8.3/node_modules/capnp-es/dist/shared/capnp-es.UAt3nLGq.mjs
69
- var Interface = class extends Pointer {
70
- static {
71
- __name(this, "Interface");
72
- }
73
- static _capnp = {
74
- displayName: "Interface"
75
- };
76
- static getCapID = getCapID;
77
- static getAsInterface = getAsInterface;
78
- static isInterface = isInterface;
79
- static getClient = getClient;
80
- constructor(segment, byteOffset, depthLimit = MAX_DEPTH) {
81
- super(segment, byteOffset, depthLimit);
82
- }
83
- static fromPointer(p) {
84
- return getAsInterface(p);
85
- }
86
- getCapId() {
87
- return getCapID(this);
88
- }
89
- getClient() {
90
- return getClient(this);
91
- }
92
- [Symbol.for("nodejs.util.inspect.custom")]() {
93
- return format(
94
- "Interface_%d@%a,%d,limit:%x",
95
- this.segment.id,
96
- this.byteOffset,
97
- this.getCapId(),
98
- this._capnp.depthLimit
99
- );
100
- }
101
- };
102
- function getAsInterface(p) {
103
- if (getTargetPointerType(p) === PointerType.OTHER) {
104
- return new Interface(p.segment, p.byteOffset, p._capnp.depthLimit);
105
- }
106
- return null;
107
- }
108
- __name(getAsInterface, "getAsInterface");
109
- function isInterface(p) {
110
- return getTargetPointerType(p) === PointerType.OTHER;
111
- }
112
- __name(isInterface, "isInterface");
113
- function getCapID(i) {
114
- if (i.segment.getUint32(i.byteOffset) !== PointerType.OTHER) {
115
- return -1;
116
- }
117
- return i.segment.getUint32(i.byteOffset + 4);
118
- }
119
- __name(getCapID, "getCapID");
120
- function getClient(i) {
121
- const capID = getCapID(i);
122
- const { capTable } = i.segment.message._capnp;
123
- if (!capTable) {
124
- return null;
125
- }
126
- return capTable[capID];
127
- }
128
- __name(getClient, "getClient");
129
- function isDataCall(call) {
130
- return !!call.params;
131
- }
132
- __name(isDataCall, "isDataCall");
133
- function copyCall(call) {
134
- if (isDataCall(call)) {
135
- return call;
136
- }
137
- return {
138
- method: call.method,
139
- params: placeParams(call, void 0)
140
- };
141
- }
142
- __name(copyCall, "copyCall");
143
- function placeParams(call, contentPtr) {
144
- if (isDataCall(call)) {
145
- return call.params;
146
- }
147
- let p;
148
- if (contentPtr) {
149
- p = new call.method.ParamsClass(
150
- contentPtr.segment,
151
- contentPtr.byteOffset,
152
- contentPtr._capnp.depthLimit
153
- );
154
- } else {
155
- const msg = new Message();
156
- p = new call.method.ParamsClass(msg.getSegment(0), 0);
157
- }
158
- initStruct(call.method.ParamsClass._capnp.size, p);
159
- if (call.paramsFunc) {
160
- call.paramsFunc(p);
161
- }
162
- return p;
163
- }
164
- __name(placeParams, "placeParams");
165
- function pointerToStruct(p) {
166
- if (getTargetPointerType(p) === PointerType.STRUCT) {
167
- return new Struct(
168
- p.segment,
169
- p.byteOffset,
170
- p._capnp.depthLimit,
171
- p._capnp.compositeIndex
172
- );
173
- }
174
- return null;
175
- }
176
- __name(pointerToStruct, "pointerToStruct");
177
- function transformPtr(p, transform) {
178
- if (transform.length === 0) {
179
- return p;
180
- }
181
- let s = pointerToStruct(p);
182
- if (!s) {
183
- return p;
184
- }
185
- for (const op of transform) {
186
- s = getPointer(op.field, s);
187
- }
188
- return s;
189
- }
190
- __name(transformPtr, "transformPtr");
191
- var Deferred = class _Deferred {
192
- static {
193
- __name(this, "Deferred");
194
- }
195
- static fromPromise(p) {
196
- const d = new _Deferred();
197
- p.then(d.resolve, d.reject);
198
- return d;
199
- }
200
- promise;
201
- reject;
202
- resolve;
203
- constructor() {
204
- this.promise = new Promise((a, b) => {
205
- this.resolve = a;
206
- this.reject = b;
207
- });
208
- }
209
- };
210
- var ImmediateAnswer = class extends FixedAnswer {
211
- static {
212
- __name(this, "ImmediateAnswer");
213
- }
214
- constructor(s) {
215
- super();
216
- this.s = s;
217
- }
218
- structSync() {
219
- return this.s;
220
- }
221
- findClient(transform) {
222
- const p = transformPtr(this.s, transform);
223
- return getInterfaceClientOrNull(p);
224
- }
225
- pipelineCall(transform, call) {
226
- return this.findClient(transform).call(call);
227
- }
228
- pipelineClose(transform) {
229
- this.findClient(transform).close();
230
- }
231
- };
232
- var Queue = class {
233
- static {
234
- __name(this, "Queue");
235
- }
236
- // creates a new queue that starts with n elements.
237
- // The interface's length must not change over the course of
238
- // the queue's usage.
239
- constructor(q, n) {
240
- this.q = q;
241
- this.n = n;
242
- this.cap = q.len();
243
- }
244
- start = 0;
245
- cap;
246
- // len returns the length of the queue. This is different from the underlying
247
- // interface's length, which is the queue's capacity.
248
- len() {
249
- return this.n;
250
- }
251
- // push reserves space for an element on the queue, returning its index.
252
- // if the queue is full, push returns -1.
253
- push() {
254
- if (this.n >= this.cap) {
255
- return -1;
256
- }
257
- const i = (this.start + this.n) % this.cap;
258
- this.n++;
259
- return i;
260
- }
261
- // front returns the index of the front of the queue, or -1 if the queue is empty.
262
- front() {
263
- if (this.n === 0) {
264
- return -1;
265
- }
266
- return this.start;
267
- }
268
- // pop pops an element from the queue, returning whether it succeeded.
269
- pop() {
270
- if (this.n === 0) {
271
- return false;
272
- }
273
- this.q.clear(this.start);
274
- this.start = (this.start + 1) % this.cap;
275
- this.n--;
276
- return true;
277
- }
278
- };
279
- var EmbargoClient = class {
280
- static {
281
- __name(this, "EmbargoClient");
282
- }
283
- _client;
284
- q;
285
- calls;
286
- constructor(client, queue) {
287
- this._client = client;
288
- this.calls = queue.copy();
289
- this.q = new Queue(this.calls, this.calls.len());
290
- this.flushQueue();
291
- }
292
- flushQueue() {
293
- let c = null;
294
- {
295
- const i = this.q.front();
296
- if (i !== -1) {
297
- c = this.calls.data[i];
298
- }
299
- }
300
- while (c && c.call) {
301
- const ans = this._client.call(c.call);
302
- void (async (f, ans2) => {
303
- try {
304
- f.fulfill(await ans2.struct());
305
- } catch (error_) {
306
- f.reject(error_);
307
- }
308
- })(c.f, ans);
309
- this.q.pop();
310
- {
311
- const i = this.q.front();
312
- c = i === -1 ? null : this.calls.data[i];
313
- }
314
- }
315
- }
316
- // client returns the underlying client if the embargo has
317
- // been lifted and null otherwise
318
- client() {
319
- return this.isPassthrough() ? this._client : null;
320
- }
321
- isPassthrough() {
322
- return this.q.len() === 0;
323
- }
324
- // call either queues a call to the underlying client or starts a
325
- // call if the embargo has been lifted
326
- call(call) {
327
- if (this.isPassthrough()) {
328
- return this._client.call(call);
329
- }
330
- return this.push(call);
331
- }
332
- push(_call) {
333
- const f = new Fulfiller();
334
- const call = copyCall(_call);
335
- const i = this.q.push();
336
- if (i === -1) {
337
- return new ErrorAnswer(new Error(RPC_CALL_QUEUE_FULL));
338
- }
339
- this.calls.data[i] = {
340
- call,
341
- f
342
- };
343
- return f;
344
- }
345
- close() {
346
- while (this.q.len() > 0) {
347
- const first = this.calls.data[this.q.front()];
348
- if (!first) {
349
- throw new Error(INVARIANT_UNREACHABLE_CODE);
350
- }
351
- first.f.reject(new Error(RPC_QUEUE_CALL_CANCEL));
352
- this.q.pop();
353
- }
354
- this._client.close();
355
- }
356
- };
357
- var Ecalls = class _Ecalls {
358
- static {
359
- __name(this, "Ecalls");
360
- }
361
- data;
362
- constructor(data) {
363
- this.data = data;
364
- }
365
- static copyOf(data) {
366
- return new _Ecalls([...data]);
367
- }
368
- len() {
369
- return this.data.length;
370
- }
371
- clear(i) {
372
- this.data[i] = null;
373
- }
374
- copy() {
375
- return _Ecalls.copyOf(this.data);
376
- }
377
- };
378
- var callQueueSize = 64;
379
- var Fulfiller = class _Fulfiller {
380
- static {
381
- __name(this, "Fulfiller");
382
- }
383
- resolved = false;
384
- answer;
385
- queue = [];
386
- queueCap = callQueueSize;
387
- deferred = new Deferred();
388
- fulfill(s) {
389
- this.answer = new ImmediateAnswer(s);
390
- const queues = this.emptyQueue(s);
391
- const msgcap = s.segment.message._capnp;
392
- if (!msgcap.capTable) {
393
- msgcap.capTable = [];
394
- }
395
- const ctab = msgcap.capTable;
396
- for (const _capIdx of Object.keys(queues)) {
397
- const capIdx = +_capIdx;
398
- const q = queues[capIdx];
399
- const client = ctab[capIdx];
400
- if (!client) {
401
- throw new Error(INVARIANT_UNREACHABLE_CODE);
402
- }
403
- ctab[capIdx] = new EmbargoClient(client, q);
404
- }
405
- this.deferred.resolve(s);
406
- }
407
- reject(err) {
408
- this.deferred.reject(err);
409
- }
410
- peek() {
411
- return this.answer;
412
- }
413
- async struct() {
414
- return await this.deferred.promise;
415
- }
416
- // pipelineCall calls pipelineCall on the fulfilled answer or
417
- // queues the call if f has not been fulfilled
418
- pipelineCall(transform, call) {
419
- {
420
- const a = this.peek();
421
- if (a) {
422
- return a.pipelineCall(transform, call);
423
- }
424
- }
425
- if (this.queue.length === this.queueCap) {
426
- return new ErrorAnswer(new Error(RPC_CALL_QUEUE_FULL));
427
- }
428
- const cc = copyCall(call);
429
- const g = new _Fulfiller();
430
- this.queue.push({
431
- call: cc,
432
- f: g,
433
- transform
434
- });
435
- return g;
436
- }
437
- // pipelineClose waits until f is resolved and then calls
438
- // pipelineClose on the fulfilled answer
439
- // FIXME: should this be async?
440
- pipelineClose(transform) {
441
- const onFinally = /* @__PURE__ */ __name(() => {
442
- if (this.answer) {
443
- this.answer.pipelineClose(transform);
444
- }
445
- }, "onFinally");
446
- this.deferred.promise.then(onFinally, onFinally);
447
- }
448
- // emptyQueue splits the queue by which capability it targets and
449
- // drops any invalid calls. Once this function returns, f.queue will
450
- // be nil.
451
- emptyQueue(s) {
452
- const qs = {};
453
- for (let i = 0; i < this.queue.length; i++) {
454
- const pc = this.queue[i];
455
- let c;
456
- try {
457
- c = transformPtr(s, pc.transform);
458
- } catch (error_) {
459
- pc.f.reject(error_);
460
- continue;
461
- }
462
- const iface = Interface.fromPointer(c);
463
- if (!iface) {
464
- pc.f.reject(new Error(RPC_NULL_CLIENT));
465
- continue;
466
- }
467
- const cn = iface.getCapId();
468
- if (!qs[cn]) {
469
- qs[cn] = new Ecalls([]);
470
- }
471
- qs[cn].data.push(pc);
472
- }
473
- this.queue = [];
474
- return qs;
475
- }
476
- };
477
- var PipelineClient = class {
478
- static {
479
- __name(this, "PipelineClient");
480
- }
481
- constructor(pipeline) {
482
- this.pipeline = pipeline;
483
- }
484
- transform() {
485
- return this.pipeline.transform();
486
- }
487
- call(call) {
488
- return this.pipeline.answer.pipelineCall(this.transform(), call);
489
- }
490
- close() {
491
- this.pipeline.answer.pipelineClose(this.transform());
492
- }
493
- };
494
- var Pipeline = class _Pipeline {
495
- static {
496
- __name(this, "Pipeline");
497
- }
498
- // Returns a new Pipeline based on an answer
499
- constructor(ResultsClass, answer, op, parent) {
500
- this.ResultsClass = ResultsClass;
501
- this.answer = answer;
502
- this.parent = parent;
503
- this.op = op || { field: 0 };
504
- }
505
- op;
506
- pipelineClient;
507
- // transform returns the operations needed to transform the root answer
508
- // into the value p represents.
509
- transform() {
510
- const xform = [];
511
- for (let q = this; q.parent; q = q.parent) {
512
- xform.unshift(q.op);
513
- }
514
- return xform;
515
- }
516
- // Struct waits until the answer is resolved and returns the struct
517
- // this pipeline represents.
518
- async struct() {
519
- const s = await this.answer.struct();
520
- const t = transformPtr(s, this.transform());
521
- if (!t) {
522
- if (this.op.defaultValue) {
523
- copyFrom(this.op.defaultValue, t);
524
- } else {
525
- initStruct(this.ResultsClass._capnp.size, t);
526
- }
527
- }
528
- return getAs(this.ResultsClass, t);
529
- }
530
- // client returns the client version of this pipeline
531
- client() {
532
- if (!this.pipelineClient) {
533
- this.pipelineClient = new PipelineClient(this);
534
- }
535
- return this.pipelineClient;
536
- }
537
- // getPipeline returns a derived pipeline which yields the pointer field given
538
- getPipeline(ResultsClass, off, defaultValue) {
539
- return new _Pipeline(
540
- ResultsClass,
541
- this.answer,
542
- { field: off, defaultValue },
543
- this
544
- );
545
- }
546
- };
547
- var MethodError = class extends Error {
548
- static {
549
- __name(this, "MethodError");
550
- }
551
- constructor(method, message) {
552
- super(
553
- format(
554
- RPC_METHOD_ERROR,
555
- method.interfaceName,
556
- method.methodName,
557
- message
558
- )
559
- );
560
- this.method = method;
561
- }
562
- };
563
- var Registry = class {
564
- static {
565
- __name(this, "Registry");
566
- }
567
- static interfaces = /* @__PURE__ */ new Map();
568
- static register(id, def) {
569
- this.interfaces.set(id, def);
570
- }
571
- static lookup(id) {
572
- return this.interfaces.get(id);
573
- }
574
- };
575
-
576
- // ../../node_modules/.pnpm/capnp-es@0.0.11_patch_hash=53996ae63a1465953815fff49405f2224c85d26eeeff469d2b1f87e1c2af451d_typescript@5.8.3/node_modules/capnp-es/dist/capnp/rpc.mjs
577
- var _capnpFileId = BigInt("0xb312981b2552a250");
578
- var Message_Which = {
579
- /**
580
- * The sender previously received this message from the peer but didn't understand it or doesn't
581
- * yet implement the functionality that was requested. So, the sender is echoing the message
582
- * back. In some cases, the receiver may be able to recover from this by pretending the sender
583
- * had taken some appropriate "null" action.
584
- *
585
- * For example, say `resolve` is received by a level 0 implementation (because a previous call
586
- * or return happened to contain a promise). The level 0 implementation will echo it back as
587
- * `unimplemented`. The original sender can then simply release the cap to which the promise
588
- * had resolved, thus avoiding a leak.
589
- *
590
- * For any message type that introduces a question, if the message comes back unimplemented,
591
- * the original sender may simply treat it as if the question failed with an exception.
592
- *
593
- * In cases where there is no sensible way to react to an `unimplemented` message (without
594
- * resource leaks or other serious problems), the connection may need to be aborted. This is
595
- * a gray area; different implementations may take different approaches.
596
- *
597
- */
598
- UNIMPLEMENTED: 0,
599
- /**
600
- * Sent when a connection is being aborted due to an unrecoverable error. This could be e.g.
601
- * because the sender received an invalid or nonsensical message or because the sender had an
602
- * internal error. The sender will shut down the outgoing half of the connection after `abort`
603
- * and will completely close the connection shortly thereafter (it's up to the sender how much
604
- * of a time buffer they want to offer for the client to receive the `abort` before the
605
- * connection is reset).
606
- *
607
- */
608
- ABORT: 1,
609
- /**
610
- * Request the peer's bootstrap interface.
611
- *
612
- */
613
- BOOTSTRAP: 8,
614
- /**
615
- * Begin a method call.
616
- *
617
- */
618
- CALL: 2,
619
- /**
620
- * Complete a method call.
621
- *
622
- */
623
- RETURN: 3,
624
- /**
625
- * Release a returned answer / cancel a call.
626
- *
627
- */
628
- FINISH: 4,
629
- /**
630
- * Resolve a previously-sent promise.
631
- *
632
- */
633
- RESOLVE: 5,
634
- /**
635
- * Release a capability so that the remote object can be deallocated.
636
- *
637
- */
638
- RELEASE: 6,
639
- /**
640
- * Lift an embargo used to enforce E-order over promise resolution.
641
- *
642
- */
643
- DISEMBARGO: 13,
644
- /**
645
- * Obsolete request to save a capability, resulting in a SturdyRef. This has been replaced
646
- * by the `Persistent` interface defined in `persistent.capnp`. This operation was never
647
- * implemented.
648
- *
649
- */
650
- OBSOLETE_SAVE: 7,
651
- /**
652
- * Obsolete way to delete a SturdyRef. This operation was never implemented.
653
- *
654
- */
655
- OBSOLETE_DELETE: 9,
656
- /**
657
- * Provide a capability to a third party.
658
- *
659
- */
660
- PROVIDE: 10,
661
- /**
662
- * Accept a capability provided by a third party.
663
- *
664
- */
665
- ACCEPT: 11,
666
- /**
667
- * Directly connect to the common root of two or more proxied caps.
668
- *
669
- */
670
- JOIN: 12
671
- };
672
- var Message2 = class _Message extends Struct {
673
- static {
674
- __name(this, "Message");
675
- }
676
- static UNIMPLEMENTED = Message_Which.UNIMPLEMENTED;
677
- static ABORT = Message_Which.ABORT;
678
- static BOOTSTRAP = Message_Which.BOOTSTRAP;
679
- static CALL = Message_Which.CALL;
680
- static RETURN = Message_Which.RETURN;
681
- static FINISH = Message_Which.FINISH;
682
- static RESOLVE = Message_Which.RESOLVE;
683
- static RELEASE = Message_Which.RELEASE;
684
- static DISEMBARGO = Message_Which.DISEMBARGO;
685
- static OBSOLETE_SAVE = Message_Which.OBSOLETE_SAVE;
686
- static OBSOLETE_DELETE = Message_Which.OBSOLETE_DELETE;
687
- static PROVIDE = Message_Which.PROVIDE;
688
- static ACCEPT = Message_Which.ACCEPT;
689
- static JOIN = Message_Which.JOIN;
690
- static _capnp = {
691
- displayName: "Message",
692
- id: "91b79f1f808db032",
693
- size: new ObjectSize(8, 1)
694
- };
695
- _adoptUnimplemented(value) {
696
- setUint16(0, 0, this);
697
- adopt(value, getPointer(0, this));
698
- }
699
- _disownUnimplemented() {
700
- return disown(this.unimplemented);
701
- }
702
- /**
703
- * The sender previously received this message from the peer but didn't understand it or doesn't
704
- * yet implement the functionality that was requested. So, the sender is echoing the message
705
- * back. In some cases, the receiver may be able to recover from this by pretending the sender
706
- * had taken some appropriate "null" action.
707
- *
708
- * For example, say `resolve` is received by a level 0 implementation (because a previous call
709
- * or return happened to contain a promise). The level 0 implementation will echo it back as
710
- * `unimplemented`. The original sender can then simply release the cap to which the promise
711
- * had resolved, thus avoiding a leak.
712
- *
713
- * For any message type that introduces a question, if the message comes back unimplemented,
714
- * the original sender may simply treat it as if the question failed with an exception.
715
- *
716
- * In cases where there is no sensible way to react to an `unimplemented` message (without
717
- * resource leaks or other serious problems), the connection may need to be aborted. This is
718
- * a gray area; different implementations may take different approaches.
719
- *
720
- */
721
- get unimplemented() {
722
- testWhich("unimplemented", getUint16(0, this), 0, this);
723
- return getStruct(0, _Message, this);
724
- }
725
- _hasUnimplemented() {
726
- return !isNull(getPointer(0, this));
727
- }
728
- _initUnimplemented() {
729
- setUint16(0, 0, this);
730
- return initStructAt(0, _Message, this);
731
- }
732
- get _isUnimplemented() {
733
- return getUint16(0, this) === 0;
734
- }
735
- set unimplemented(value) {
736
- setUint16(0, 0, this);
737
- copyFrom(value, getPointer(0, this));
738
- }
739
- _adoptAbort(value) {
740
- setUint16(0, 1, this);
741
- adopt(value, getPointer(0, this));
742
- }
743
- _disownAbort() {
744
- return disown(this.abort);
745
- }
746
- /**
747
- * Sent when a connection is being aborted due to an unrecoverable error. This could be e.g.
748
- * because the sender received an invalid or nonsensical message or because the sender had an
749
- * internal error. The sender will shut down the outgoing half of the connection after `abort`
750
- * and will completely close the connection shortly thereafter (it's up to the sender how much
751
- * of a time buffer they want to offer for the client to receive the `abort` before the
752
- * connection is reset).
753
- *
754
- */
755
- get abort() {
756
- testWhich("abort", getUint16(0, this), 1, this);
757
- return getStruct(0, Exception, this);
758
- }
759
- _hasAbort() {
760
- return !isNull(getPointer(0, this));
761
- }
762
- _initAbort() {
763
- setUint16(0, 1, this);
764
- return initStructAt(0, Exception, this);
765
- }
766
- get _isAbort() {
767
- return getUint16(0, this) === 1;
768
- }
769
- set abort(value) {
770
- setUint16(0, 1, this);
771
- copyFrom(value, getPointer(0, this));
772
- }
773
- _adoptBootstrap(value) {
774
- setUint16(0, 8, this);
775
- adopt(value, getPointer(0, this));
776
- }
777
- _disownBootstrap() {
778
- return disown(this.bootstrap);
779
- }
780
- /**
781
- * Request the peer's bootstrap interface.
782
- *
783
- */
784
- get bootstrap() {
785
- testWhich("bootstrap", getUint16(0, this), 8, this);
786
- return getStruct(0, Bootstrap, this);
787
- }
788
- _hasBootstrap() {
789
- return !isNull(getPointer(0, this));
790
- }
791
- _initBootstrap() {
792
- setUint16(0, 8, this);
793
- return initStructAt(0, Bootstrap, this);
794
- }
795
- get _isBootstrap() {
796
- return getUint16(0, this) === 8;
797
- }
798
- set bootstrap(value) {
799
- setUint16(0, 8, this);
800
- copyFrom(value, getPointer(0, this));
801
- }
802
- _adoptCall(value) {
803
- setUint16(0, 2, this);
804
- adopt(value, getPointer(0, this));
805
- }
806
- _disownCall() {
807
- return disown(this.call);
808
- }
809
- /**
810
- * Begin a method call.
811
- *
812
- */
813
- get call() {
814
- testWhich("call", getUint16(0, this), 2, this);
815
- return getStruct(0, Call, this);
816
- }
817
- _hasCall() {
818
- return !isNull(getPointer(0, this));
819
- }
820
- _initCall() {
821
- setUint16(0, 2, this);
822
- return initStructAt(0, Call, this);
823
- }
824
- get _isCall() {
825
- return getUint16(0, this) === 2;
826
- }
827
- set call(value) {
828
- setUint16(0, 2, this);
829
- copyFrom(value, getPointer(0, this));
830
- }
831
- _adoptReturn(value) {
832
- setUint16(0, 3, this);
833
- adopt(value, getPointer(0, this));
834
- }
835
- _disownReturn() {
836
- return disown(this.return);
837
- }
838
- /**
839
- * Complete a method call.
840
- *
841
- */
842
- get return() {
843
- testWhich("return", getUint16(0, this), 3, this);
844
- return getStruct(0, Return, this);
845
- }
846
- _hasReturn() {
847
- return !isNull(getPointer(0, this));
848
- }
849
- _initReturn() {
850
- setUint16(0, 3, this);
851
- return initStructAt(0, Return, this);
852
- }
853
- get _isReturn() {
854
- return getUint16(0, this) === 3;
855
- }
856
- set return(value) {
857
- setUint16(0, 3, this);
858
- copyFrom(value, getPointer(0, this));
859
- }
860
- _adoptFinish(value) {
861
- setUint16(0, 4, this);
862
- adopt(value, getPointer(0, this));
863
- }
864
- _disownFinish() {
865
- return disown(this.finish);
866
- }
867
- /**
868
- * Release a returned answer / cancel a call.
869
- *
870
- */
871
- get finish() {
872
- testWhich("finish", getUint16(0, this), 4, this);
873
- return getStruct(0, Finish, this);
874
- }
875
- _hasFinish() {
876
- return !isNull(getPointer(0, this));
877
- }
878
- _initFinish() {
879
- setUint16(0, 4, this);
880
- return initStructAt(0, Finish, this);
881
- }
882
- get _isFinish() {
883
- return getUint16(0, this) === 4;
884
- }
885
- set finish(value) {
886
- setUint16(0, 4, this);
887
- copyFrom(value, getPointer(0, this));
888
- }
889
- _adoptResolve(value) {
890
- setUint16(0, 5, this);
891
- adopt(value, getPointer(0, this));
892
- }
893
- _disownResolve() {
894
- return disown(this.resolve);
895
- }
896
- /**
897
- * Resolve a previously-sent promise.
898
- *
899
- */
900
- get resolve() {
901
- testWhich("resolve", getUint16(0, this), 5, this);
902
- return getStruct(0, Resolve, this);
903
- }
904
- _hasResolve() {
905
- return !isNull(getPointer(0, this));
906
- }
907
- _initResolve() {
908
- setUint16(0, 5, this);
909
- return initStructAt(0, Resolve, this);
910
- }
911
- get _isResolve() {
912
- return getUint16(0, this) === 5;
913
- }
914
- set resolve(value) {
915
- setUint16(0, 5, this);
916
- copyFrom(value, getPointer(0, this));
917
- }
918
- _adoptRelease(value) {
919
- setUint16(0, 6, this);
920
- adopt(value, getPointer(0, this));
921
- }
922
- _disownRelease() {
923
- return disown(this.release);
924
- }
925
- /**
926
- * Release a capability so that the remote object can be deallocated.
927
- *
928
- */
929
- get release() {
930
- testWhich("release", getUint16(0, this), 6, this);
931
- return getStruct(0, Release, this);
932
- }
933
- _hasRelease() {
934
- return !isNull(getPointer(0, this));
935
- }
936
- _initRelease() {
937
- setUint16(0, 6, this);
938
- return initStructAt(0, Release, this);
939
- }
940
- get _isRelease() {
941
- return getUint16(0, this) === 6;
942
- }
943
- set release(value) {
944
- setUint16(0, 6, this);
945
- copyFrom(value, getPointer(0, this));
946
- }
947
- _adoptDisembargo(value) {
948
- setUint16(0, 13, this);
949
- adopt(value, getPointer(0, this));
950
- }
951
- _disownDisembargo() {
952
- return disown(this.disembargo);
953
- }
954
- /**
955
- * Lift an embargo used to enforce E-order over promise resolution.
956
- *
957
- */
958
- get disembargo() {
959
- testWhich("disembargo", getUint16(0, this), 13, this);
960
- return getStruct(0, Disembargo, this);
961
- }
962
- _hasDisembargo() {
963
- return !isNull(getPointer(0, this));
964
- }
965
- _initDisembargo() {
966
- setUint16(0, 13, this);
967
- return initStructAt(0, Disembargo, this);
968
- }
969
- get _isDisembargo() {
970
- return getUint16(0, this) === 13;
971
- }
972
- set disembargo(value) {
973
- setUint16(0, 13, this);
974
- copyFrom(value, getPointer(0, this));
975
- }
976
- _adoptObsoleteSave(value) {
977
- setUint16(0, 7, this);
978
- adopt(value, getPointer(0, this));
979
- }
980
- _disownObsoleteSave() {
981
- return disown(this.obsoleteSave);
982
- }
983
- /**
984
- * Obsolete request to save a capability, resulting in a SturdyRef. This has been replaced
985
- * by the `Persistent` interface defined in `persistent.capnp`. This operation was never
986
- * implemented.
987
- *
988
- */
989
- get obsoleteSave() {
990
- testWhich("obsoleteSave", getUint16(0, this), 7, this);
991
- return getPointer(0, this);
992
- }
993
- _hasObsoleteSave() {
994
- return !isNull(getPointer(0, this));
995
- }
996
- get _isObsoleteSave() {
997
- return getUint16(0, this) === 7;
998
- }
999
- set obsoleteSave(value) {
1000
- setUint16(0, 7, this);
1001
- copyFrom(value, getPointer(0, this));
1002
- }
1003
- _adoptObsoleteDelete(value) {
1004
- setUint16(0, 9, this);
1005
- adopt(value, getPointer(0, this));
1006
- }
1007
- _disownObsoleteDelete() {
1008
- return disown(this.obsoleteDelete);
1009
- }
1010
- /**
1011
- * Obsolete way to delete a SturdyRef. This operation was never implemented.
1012
- *
1013
- */
1014
- get obsoleteDelete() {
1015
- testWhich("obsoleteDelete", getUint16(0, this), 9, this);
1016
- return getPointer(0, this);
1017
- }
1018
- _hasObsoleteDelete() {
1019
- return !isNull(getPointer(0, this));
1020
- }
1021
- get _isObsoleteDelete() {
1022
- return getUint16(0, this) === 9;
1023
- }
1024
- set obsoleteDelete(value) {
1025
- setUint16(0, 9, this);
1026
- copyFrom(value, getPointer(0, this));
1027
- }
1028
- _adoptProvide(value) {
1029
- setUint16(0, 10, this);
1030
- adopt(value, getPointer(0, this));
1031
- }
1032
- _disownProvide() {
1033
- return disown(this.provide);
1034
- }
1035
- /**
1036
- * Provide a capability to a third party.
1037
- *
1038
- */
1039
- get provide() {
1040
- testWhich("provide", getUint16(0, this), 10, this);
1041
- return getStruct(0, Provide, this);
1042
- }
1043
- _hasProvide() {
1044
- return !isNull(getPointer(0, this));
1045
- }
1046
- _initProvide() {
1047
- setUint16(0, 10, this);
1048
- return initStructAt(0, Provide, this);
1049
- }
1050
- get _isProvide() {
1051
- return getUint16(0, this) === 10;
1052
- }
1053
- set provide(value) {
1054
- setUint16(0, 10, this);
1055
- copyFrom(value, getPointer(0, this));
1056
- }
1057
- _adoptAccept(value) {
1058
- setUint16(0, 11, this);
1059
- adopt(value, getPointer(0, this));
1060
- }
1061
- _disownAccept() {
1062
- return disown(this.accept);
1063
- }
1064
- /**
1065
- * Accept a capability provided by a third party.
1066
- *
1067
- */
1068
- get accept() {
1069
- testWhich("accept", getUint16(0, this), 11, this);
1070
- return getStruct(0, Accept, this);
1071
- }
1072
- _hasAccept() {
1073
- return !isNull(getPointer(0, this));
1074
- }
1075
- _initAccept() {
1076
- setUint16(0, 11, this);
1077
- return initStructAt(0, Accept, this);
1078
- }
1079
- get _isAccept() {
1080
- return getUint16(0, this) === 11;
1081
- }
1082
- set accept(value) {
1083
- setUint16(0, 11, this);
1084
- copyFrom(value, getPointer(0, this));
1085
- }
1086
- _adoptJoin(value) {
1087
- setUint16(0, 12, this);
1088
- adopt(value, getPointer(0, this));
1089
- }
1090
- _disownJoin() {
1091
- return disown(this.join);
1092
- }
1093
- /**
1094
- * Directly connect to the common root of two or more proxied caps.
1095
- *
1096
- */
1097
- get join() {
1098
- testWhich("join", getUint16(0, this), 12, this);
1099
- return getStruct(0, Join, this);
1100
- }
1101
- _hasJoin() {
1102
- return !isNull(getPointer(0, this));
1103
- }
1104
- _initJoin() {
1105
- setUint16(0, 12, this);
1106
- return initStructAt(0, Join, this);
1107
- }
1108
- get _isJoin() {
1109
- return getUint16(0, this) === 12;
1110
- }
1111
- set join(value) {
1112
- setUint16(0, 12, this);
1113
- copyFrom(value, getPointer(0, this));
1114
- }
1115
- toString() {
1116
- return "Message_" + super.toString();
1117
- }
1118
- which() {
1119
- return getUint16(0, this);
1120
- }
1121
- };
1122
- var Bootstrap = class extends Struct {
1123
- static {
1124
- __name(this, "Bootstrap");
1125
- }
1126
- static _capnp = {
1127
- displayName: "Bootstrap",
1128
- id: "e94ccf8031176ec4",
1129
- size: new ObjectSize(8, 1)
1130
- };
1131
- /**
1132
- * A new question ID identifying this request, which will eventually receive a Return message
1133
- * containing the restored capability.
1134
- *
1135
- */
1136
- get questionId() {
1137
- return getUint32(0, this);
1138
- }
1139
- set questionId(value) {
1140
- setUint32(0, value, this);
1141
- }
1142
- _adoptDeprecatedObjectId(value) {
1143
- adopt(value, getPointer(0, this));
1144
- }
1145
- _disownDeprecatedObjectId() {
1146
- return disown(this.deprecatedObjectId);
1147
- }
1148
- /**
1149
- * ** DEPRECATED **
1150
- *
1151
- * A Vat may export multiple bootstrap interfaces. In this case, `deprecatedObjectId` specifies
1152
- * which one to return. If this pointer is null, then the default bootstrap interface is returned.
1153
- *
1154
- * As of version 0.5, use of this field is deprecated. If a service wants to export multiple
1155
- * bootstrap interfaces, it should instead define a single bootstrap interface that has methods
1156
- * that return each of the other interfaces.
1157
- *
1158
- * **History**
1159
- *
1160
- * In the first version of Cap'n Proto RPC (0.4.x) the `Bootstrap` message was called `Restore`.
1161
- * At the time, it was thought that this would eventually serve as the way to restore SturdyRefs
1162
- * (level 2). Meanwhile, an application could offer its "main" interface on a well-known
1163
- * (non-secret) SturdyRef.
1164
- *
1165
- * Since level 2 RPC was not implemented at the time, the `Restore` message was in practice only
1166
- * used to obtain the main interface. Since most applications had only one main interface that
1167
- * they wanted to restore, they tended to designate this with a null `objectId`.
1168
- *
1169
- * Unfortunately, the earliest version of the EZ RPC interfaces set a precedent of exporting
1170
- * multiple main interfaces by allowing them to be exported under string names. In this case,
1171
- * `objectId` was a Text value specifying the name.
1172
- *
1173
- * All of this proved problematic for several reasons:
1174
- *
1175
- * - The arrangement assumed that a client wishing to restore a SturdyRef would know exactly what
1176
- * machine to connect to and would be able to immediately restore a SturdyRef on connection.
1177
- * However, in practice, the ability to restore SturdyRefs is itself a capability that may
1178
- * require going through an authentication process to obtain. Thus, it makes more sense to
1179
- * define a "restorer service" as a full Cap'n Proto interface. If this restorer interface is
1180
- * offered as the vat's bootstrap interface, then this is equivalent to the old arrangement.
1181
- *
1182
- * - Overloading "Restore" for the purpose of obtaining well-known capabilities encouraged the
1183
- * practice of exporting singleton services with string names. If singleton services are desired,
1184
- * it is better to have one main interface that has methods that can be used to obtain each
1185
- * service, in order to get all the usual benefits of schemas and type checking.
1186
- *
1187
- * - Overloading "Restore" also had a security problem: Often, "main" or "well-known"
1188
- * capabilities exported by a vat are in fact not public: they are intended to be accessed only
1189
- * by clients who are capable of forming a connection to the vat. This can lead to trouble if
1190
- * the client itself has other clients and wishes to forward some `Restore` requests from those
1191
- * external clients -- it has to be very careful not to allow through `Restore` requests
1192
- * addressing the default capability.
1193
- *
1194
- * For example, consider the case of a sandboxed Sandstorm application and its supervisor. The
1195
- * application exports a default capability to its supervisor that provides access to
1196
- * functionality that only the supervisor is supposed to access. Meanwhile, though, applications
1197
- * may publish other capabilities that may be persistent, in which case the application needs
1198
- * to field `Restore` requests that could come from anywhere. These requests of course have to
1199
- * pass through the supervisor, as all communications with the outside world must. But, the
1200
- * supervisor has to be careful not to honor an external request addressing the application's
1201
- * default capability, since this capability is privileged. Unfortunately, the default
1202
- * capability cannot be given an unguessable name, because then the supervisor itself would not
1203
- * be able to address it!
1204
- *
1205
- * As of Cap'n Proto 0.5, `Restore` has been renamed to `Bootstrap` and is no longer planned for
1206
- * use in restoring SturdyRefs.
1207
- *
1208
- * Note that 0.4 also defined a message type called `Delete` that, like `Restore`, addressed a
1209
- * SturdyRef, but indicated that the client would not restore the ref again in the future. This
1210
- * operation was never implemented, so it was removed entirely. If a "delete" operation is desired,
1211
- * it should exist as a method on the same interface that handles restoring SturdyRefs. However,
1212
- * the utility of such an operation is questionable. You wouldn't be able to rely on it for
1213
- * garbage collection since a client could always disappear permanently without remembering to
1214
- * delete all its SturdyRefs, thus leaving them dangling forever. Therefore, it is advisable to
1215
- * design systems such that SturdyRefs never represent "owned" pointers.
1216
- *
1217
- * For example, say a SturdyRef points to an image file hosted on some server. That image file
1218
- * should also live inside a collection (a gallery, perhaps) hosted on the same server, owned by
1219
- * a user who can delete the image at any time. If the user deletes the image, the SturdyRef
1220
- * stops working. On the other hand, if the SturdyRef is discarded, this has no effect on the
1221
- * existence of the image in its collection.
1222
- *
1223
- */
1224
- get deprecatedObjectId() {
1225
- return getPointer(0, this);
1226
- }
1227
- _hasDeprecatedObjectId() {
1228
- return !isNull(getPointer(0, this));
1229
- }
1230
- set deprecatedObjectId(value) {
1231
- copyFrom(value, getPointer(0, this));
1232
- }
1233
- toString() {
1234
- return "Bootstrap_" + super.toString();
1235
- }
1236
- };
1237
- var Call_SendResultsTo_Which = {
1238
- /**
1239
- * Send the return message back to the caller (the usual).
1240
- *
1241
- */
1242
- CALLER: 0,
1243
- /**
1244
- * **(level 1)**
1245
- *
1246
- * Don't actually return the results to the sender. Instead, hold on to them and await
1247
- * instructions from the sender regarding what to do with them. In particular, the sender
1248
- * may subsequently send a `Return` for some other call (which the receiver had previously made
1249
- * to the sender) with `takeFromOtherQuestion` set. The results from this call are then used
1250
- * as the results of the other call.
1251
- *
1252
- * When `yourself` is used, the receiver must still send a `Return` for the call, but sets the
1253
- * field `resultsSentElsewhere` in that `Return` rather than including the results.
1254
- *
1255
- * This feature can be used to implement tail calls in which a call from Vat A to Vat B ends up
1256
- * returning the result of a call from Vat B back to Vat A.
1257
- *
1258
- * In particular, the most common use case for this feature is when Vat A makes a call to a
1259
- * promise in Vat B, and then that promise ends up resolving to a capability back in Vat A.
1260
- * Vat B must forward all the queued calls on that promise back to Vat A, but can set `yourself`
1261
- * in the calls so that the results need not pass back through Vat B.
1262
- *
1263
- * For example:
1264
- * - Alice, in Vat A, calls foo() on Bob in Vat B.
1265
- * - Alice makes a pipelined call bar() on the promise returned by foo().
1266
- * - Later on, Bob resolves the promise from foo() to point at Carol, who lives in Vat A (next
1267
- * to Alice).
1268
- * - Vat B dutifully forwards the bar() call to Carol. Let us call this forwarded call bar'().
1269
- * Notice that bar() and bar'() are travelling in opposite directions on the same network
1270
- * link.
1271
- * - The `Call` for bar'() has `sendResultsTo` set to `yourself`.
1272
- * - Vat B sends a `Return` for bar() with `takeFromOtherQuestion` set in place of the results,
1273
- * with the value set to the question ID of bar'(). Vat B does not wait for bar'() to return,
1274
- * as doing so would introduce unnecessary round trip latency.
1275
- * - Vat A receives bar'() and delivers it to Carol.
1276
- * - When bar'() returns, Vat A sends a `Return` for bar'() to Vat B, with `resultsSentElsewhere`
1277
- * set in place of results.
1278
- * - Vat A sends a `Finish` for the bar() call to Vat B.
1279
- * - Vat B receives the `Finish` for bar() and sends a `Finish` for bar'().
1280
- *
1281
- */
1282
- YOURSELF: 1,
1283
- /**
1284
- * **(level 3)**
1285
- *
1286
- * The call's result should be returned to a different vat. The receiver (the callee) expects
1287
- * to receive an `Accept` message from the indicated vat, and should return the call's result
1288
- * to it, rather than to the sender of the `Call`.
1289
- *
1290
- * This operates much like `yourself`, above, except that Carol is in a separate Vat C. `Call`
1291
- * messages are sent from Vat A -> Vat B and Vat B -> Vat C. A `Return` message is sent from
1292
- * Vat B -> Vat A that contains `acceptFromThirdParty` in place of results. When Vat A sends
1293
- * an `Accept` to Vat C, it receives back a `Return` containing the call's actual result. Vat C
1294
- * also sends a `Return` to Vat B with `resultsSentElsewhere`.
1295
- *
1296
- */
1297
- THIRD_PARTY: 2
1298
- };
1299
- var Call_SendResultsTo = class extends Struct {
1300
- static {
1301
- __name(this, "Call_SendResultsTo");
1302
- }
1303
- static CALLER = Call_SendResultsTo_Which.CALLER;
1304
- static YOURSELF = Call_SendResultsTo_Which.YOURSELF;
1305
- static THIRD_PARTY = Call_SendResultsTo_Which.THIRD_PARTY;
1306
- static _capnp = {
1307
- displayName: "sendResultsTo",
1308
- id: "dae8b0f61aab5f99",
1309
- size: new ObjectSize(24, 3)
1310
- };
1311
- get _isCaller() {
1312
- return getUint16(6, this) === 0;
1313
- }
1314
- set caller(_) {
1315
- setUint16(6, 0, this);
1316
- }
1317
- get _isYourself() {
1318
- return getUint16(6, this) === 1;
1319
- }
1320
- set yourself(_) {
1321
- setUint16(6, 1, this);
1322
- }
1323
- _adoptThirdParty(value) {
1324
- setUint16(6, 2, this);
1325
- adopt(value, getPointer(2, this));
1326
- }
1327
- _disownThirdParty() {
1328
- return disown(this.thirdParty);
1329
- }
1330
- /**
1331
- * **(level 3)**
1332
- *
1333
- * The call's result should be returned to a different vat. The receiver (the callee) expects
1334
- * to receive an `Accept` message from the indicated vat, and should return the call's result
1335
- * to it, rather than to the sender of the `Call`.
1336
- *
1337
- * This operates much like `yourself`, above, except that Carol is in a separate Vat C. `Call`
1338
- * messages are sent from Vat A -> Vat B and Vat B -> Vat C. A `Return` message is sent from
1339
- * Vat B -> Vat A that contains `acceptFromThirdParty` in place of results. When Vat A sends
1340
- * an `Accept` to Vat C, it receives back a `Return` containing the call's actual result. Vat C
1341
- * also sends a `Return` to Vat B with `resultsSentElsewhere`.
1342
- *
1343
- */
1344
- get thirdParty() {
1345
- testWhich("thirdParty", getUint16(6, this), 2, this);
1346
- return getPointer(2, this);
1347
- }
1348
- _hasThirdParty() {
1349
- return !isNull(getPointer(2, this));
1350
- }
1351
- get _isThirdParty() {
1352
- return getUint16(6, this) === 2;
1353
- }
1354
- set thirdParty(value) {
1355
- setUint16(6, 2, this);
1356
- copyFrom(value, getPointer(2, this));
1357
- }
1358
- toString() {
1359
- return "Call_SendResultsTo_" + super.toString();
1360
- }
1361
- which() {
1362
- return getUint16(6, this);
1363
- }
1364
- };
1365
- var Call = class _Call extends Struct {
1366
- static {
1367
- __name(this, "Call");
1368
- }
1369
- static _capnp = {
1370
- displayName: "Call",
1371
- id: "836a53ce789d4cd4",
1372
- size: new ObjectSize(24, 3),
1373
- defaultAllowThirdPartyTailCall: getBitMask(false, 0),
1374
- defaultNoPromisePipelining: getBitMask(false, 1),
1375
- defaultOnlyPromisePipeline: getBitMask(false, 2)
1376
- };
1377
- /**
1378
- * A number, chosen by the caller, that identifies this call in future messages. This number
1379
- * must be different from all other calls originating from the same end of the connection (but
1380
- * may overlap with question IDs originating from the opposite end). A fine strategy is to use
1381
- * sequential question IDs, but the recipient should not assume this.
1382
- *
1383
- * A question ID can be reused once both:
1384
- * - A matching Return has been received from the callee.
1385
- * - A matching Finish has been sent from the caller.
1386
- *
1387
- */
1388
- get questionId() {
1389
- return getUint32(0, this);
1390
- }
1391
- set questionId(value) {
1392
- setUint32(0, value, this);
1393
- }
1394
- _adoptTarget(value) {
1395
- adopt(value, getPointer(0, this));
1396
- }
1397
- _disownTarget() {
1398
- return disown(this.target);
1399
- }
1400
- /**
1401
- * The object that should receive this call.
1402
- *
1403
- */
1404
- get target() {
1405
- return getStruct(0, MessageTarget, this);
1406
- }
1407
- _hasTarget() {
1408
- return !isNull(getPointer(0, this));
1409
- }
1410
- _initTarget() {
1411
- return initStructAt(0, MessageTarget, this);
1412
- }
1413
- set target(value) {
1414
- copyFrom(value, getPointer(0, this));
1415
- }
1416
- /**
1417
- * The type ID of the interface being called. Each capability may implement multiple interfaces.
1418
- *
1419
- */
1420
- get interfaceId() {
1421
- return getUint64(8, this);
1422
- }
1423
- set interfaceId(value) {
1424
- setUint64(8, value, this);
1425
- }
1426
- /**
1427
- * The ordinal number of the method to call within the requested interface.
1428
- *
1429
- */
1430
- get methodId() {
1431
- return getUint16(4, this);
1432
- }
1433
- set methodId(value) {
1434
- setUint16(4, value, this);
1435
- }
1436
- /**
1437
- * Indicates whether or not the receiver is allowed to send a `Return` containing
1438
- * `acceptFromThirdParty`. Level 3 implementations should set this true. Otherwise, the callee
1439
- * will have to proxy the return in the case of a tail call to a third-party vat.
1440
- *
1441
- */
1442
- get allowThirdPartyTailCall() {
1443
- return getBit(128, this, _Call._capnp.defaultAllowThirdPartyTailCall);
1444
- }
1445
- set allowThirdPartyTailCall(value) {
1446
- setBit(128, value, this, _Call._capnp.defaultAllowThirdPartyTailCall);
1447
- }
1448
- /**
1449
- * If true, the sender promises that it won't make any promise-pipelined calls on the results of
1450
- * this call. If it breaks this promise, the receiver may throw an arbitrary error from such
1451
- * calls.
1452
- *
1453
- * The receiver may use this as an optimization, by skipping the bookkeeping needed for pipelining
1454
- * when no pipelined calls are expected. The sender typically sets this to false when the method's
1455
- * schema does not specify any return capabilities.
1456
- *
1457
- */
1458
- get noPromisePipelining() {
1459
- return getBit(129, this, _Call._capnp.defaultNoPromisePipelining);
1460
- }
1461
- set noPromisePipelining(value) {
1462
- setBit(129, value, this, _Call._capnp.defaultNoPromisePipelining);
1463
- }
1464
- /**
1465
- * If true, the sender only plans to use this call to make pipelined calls. The receiver need not
1466
- * send a `Return` message (but is still allowed to do so).
1467
- *
1468
- * Since the sender does not know whether a `Return` will be sent, it must release all state
1469
- * related to the call when it sends `Finish`. However, in the case that the callee does not
1470
- * recognize this hint and chooses to send a `Return`, then technically the caller is not allowed
1471
- * to reuse the question ID until it receives said `Return`. This creates a conundrum: How does
1472
- * the caller decide when it's OK to reuse the ID? To sidestep the problem, the C++ implementation
1473
- * uses high-numbered IDs (with the high-order bit set) for such calls, and cycles through the
1474
- * IDs in order. If all 2^31 IDs in this space are used without ever seeing a `Return`, then the
1475
- * implementation assumes that the other end is in fact honoring the hint, and the ID counter is
1476
- * allowed to loop around. If a `Return` is ever seen when `onlyPromisePipeline` was set, then
1477
- * the implementation stops using this hint.
1478
- *
1479
- */
1480
- get onlyPromisePipeline() {
1481
- return getBit(130, this, _Call._capnp.defaultOnlyPromisePipeline);
1482
- }
1483
- set onlyPromisePipeline(value) {
1484
- setBit(130, value, this, _Call._capnp.defaultOnlyPromisePipeline);
1485
- }
1486
- _adoptParams(value) {
1487
- adopt(value, getPointer(1, this));
1488
- }
1489
- _disownParams() {
1490
- return disown(this.params);
1491
- }
1492
- /**
1493
- * The call parameters. `params.content` is a struct whose fields correspond to the parameters of
1494
- * the method.
1495
- *
1496
- */
1497
- get params() {
1498
- return getStruct(1, Payload, this);
1499
- }
1500
- _hasParams() {
1501
- return !isNull(getPointer(1, this));
1502
- }
1503
- _initParams() {
1504
- return initStructAt(1, Payload, this);
1505
- }
1506
- set params(value) {
1507
- copyFrom(value, getPointer(1, this));
1508
- }
1509
- /**
1510
- * Where should the return message be sent?
1511
- *
1512
- */
1513
- get sendResultsTo() {
1514
- return getAs(Call_SendResultsTo, this);
1515
- }
1516
- _initSendResultsTo() {
1517
- return getAs(Call_SendResultsTo, this);
1518
- }
1519
- toString() {
1520
- return "Call_" + super.toString();
1521
- }
1522
- };
1523
- var Return_Which = {
1524
- /**
1525
- * Equal to the QuestionId of the corresponding `Call` message.
1526
- *
1527
- */
1528
- RESULTS: 0,
1529
- /**
1530
- * If true, all capabilities that were in the params should be considered released. The sender
1531
- * must not send separate `Release` messages for them. Level 0 implementations in particular
1532
- * should always set this true. This defaults true because if level 0 implementations forget to
1533
- * set it they'll never notice (just silently leak caps), but if level >=1 implementations forget
1534
- * to set it to false they'll quickly get errors.
1535
- *
1536
- * The receiver should act as if the sender had sent a release message with count=1 for each
1537
- * CapDescriptor in the original Call message.
1538
- *
1539
- */
1540
- EXCEPTION: 1,
1541
- /**
1542
- * The result.
1543
- *
1544
- * For regular method calls, `results.content` points to the result struct.
1545
- *
1546
- * For a `Return` in response to an `Accept` or `Bootstrap`, `results` contains a single
1547
- * capability (rather than a struct), and `results.content` is just a capability pointer with
1548
- * index 0. A `Finish` is still required in this case.
1549
- *
1550
- */
1551
- CANCELED: 2,
1552
- /**
1553
- * Indicates that the call failed and explains why.
1554
- *
1555
- */
1556
- RESULTS_SENT_ELSEWHERE: 3,
1557
- /**
1558
- * Indicates that the call was canceled due to the caller sending a Finish message
1559
- * before the call had completed.
1560
- *
1561
- */
1562
- TAKE_FROM_OTHER_QUESTION: 4,
1563
- /**
1564
- * This is set when returning from a `Call` that had `sendResultsTo` set to something other
1565
- * than `caller`.
1566
- *
1567
- * It doesn't matter too much when this is sent, as the receiver doesn't need to do anything
1568
- * with it, but the C++ implementation appears to wait for the call to finish before sending
1569
- * this.
1570
- *
1571
- */
1572
- ACCEPT_FROM_THIRD_PARTY: 5
1573
- };
1574
- var Return = class _Return extends Struct {
1575
- static {
1576
- __name(this, "Return");
1577
- }
1578
- static RESULTS = Return_Which.RESULTS;
1579
- static EXCEPTION = Return_Which.EXCEPTION;
1580
- static CANCELED = Return_Which.CANCELED;
1581
- static RESULTS_SENT_ELSEWHERE = Return_Which.RESULTS_SENT_ELSEWHERE;
1582
- static TAKE_FROM_OTHER_QUESTION = Return_Which.TAKE_FROM_OTHER_QUESTION;
1583
- static ACCEPT_FROM_THIRD_PARTY = Return_Which.ACCEPT_FROM_THIRD_PARTY;
1584
- static _capnp = {
1585
- displayName: "Return",
1586
- id: "9e19b28d3db3573a",
1587
- size: new ObjectSize(16, 1),
1588
- defaultReleaseParamCaps: getBitMask(true, 0),
1589
- defaultNoFinishNeeded: getBitMask(false, 1)
1590
- };
1591
- /**
1592
- * Equal to the QuestionId of the corresponding `Call` message.
1593
- *
1594
- */
1595
- get answerId() {
1596
- return getUint32(0, this);
1597
- }
1598
- set answerId(value) {
1599
- setUint32(0, value, this);
1600
- }
1601
- /**
1602
- * If true, all capabilities that were in the params should be considered released. The sender
1603
- * must not send separate `Release` messages for them. Level 0 implementations in particular
1604
- * should always set this true. This defaults true because if level 0 implementations forget to
1605
- * set it they'll never notice (just silently leak caps), but if level >=1 implementations forget
1606
- * to set it to false they'll quickly get errors.
1607
- *
1608
- * The receiver should act as if the sender had sent a release message with count=1 for each
1609
- * CapDescriptor in the original Call message.
1610
- *
1611
- */
1612
- get releaseParamCaps() {
1613
- return getBit(32, this, _Return._capnp.defaultReleaseParamCaps);
1614
- }
1615
- set releaseParamCaps(value) {
1616
- setBit(32, value, this, _Return._capnp.defaultReleaseParamCaps);
1617
- }
1618
- /**
1619
- * If true, the sender does not need the receiver to send a `Finish` message; its answer table
1620
- * entry has already been cleaned up. This implies that the results do not contain any
1621
- * capabilities, since the `Finish` message would normally release those capabilities from
1622
- * promise pipelining responsibility. The caller may still send a `Finish` message if it wants,
1623
- * which will be silently ignored by the callee.
1624
- *
1625
- */
1626
- get noFinishNeeded() {
1627
- return getBit(33, this, _Return._capnp.defaultNoFinishNeeded);
1628
- }
1629
- set noFinishNeeded(value) {
1630
- setBit(33, value, this, _Return._capnp.defaultNoFinishNeeded);
1631
- }
1632
- _adoptResults(value) {
1633
- setUint16(6, 0, this);
1634
- adopt(value, getPointer(0, this));
1635
- }
1636
- _disownResults() {
1637
- return disown(this.results);
1638
- }
1639
- /**
1640
- * The result.
1641
- *
1642
- * For regular method calls, `results.content` points to the result struct.
1643
- *
1644
- * For a `Return` in response to an `Accept` or `Bootstrap`, `results` contains a single
1645
- * capability (rather than a struct), and `results.content` is just a capability pointer with
1646
- * index 0. A `Finish` is still required in this case.
1647
- *
1648
- */
1649
- get results() {
1650
- testWhich("results", getUint16(6, this), 0, this);
1651
- return getStruct(0, Payload, this);
1652
- }
1653
- _hasResults() {
1654
- return !isNull(getPointer(0, this));
1655
- }
1656
- _initResults() {
1657
- setUint16(6, 0, this);
1658
- return initStructAt(0, Payload, this);
1659
- }
1660
- get _isResults() {
1661
- return getUint16(6, this) === 0;
1662
- }
1663
- set results(value) {
1664
- setUint16(6, 0, this);
1665
- copyFrom(value, getPointer(0, this));
1666
- }
1667
- _adoptException(value) {
1668
- setUint16(6, 1, this);
1669
- adopt(value, getPointer(0, this));
1670
- }
1671
- _disownException() {
1672
- return disown(this.exception);
1673
- }
1674
- /**
1675
- * Indicates that the call failed and explains why.
1676
- *
1677
- */
1678
- get exception() {
1679
- testWhich("exception", getUint16(6, this), 1, this);
1680
- return getStruct(0, Exception, this);
1681
- }
1682
- _hasException() {
1683
- return !isNull(getPointer(0, this));
1684
- }
1685
- _initException() {
1686
- setUint16(6, 1, this);
1687
- return initStructAt(0, Exception, this);
1688
- }
1689
- get _isException() {
1690
- return getUint16(6, this) === 1;
1691
- }
1692
- set exception(value) {
1693
- setUint16(6, 1, this);
1694
- copyFrom(value, getPointer(0, this));
1695
- }
1696
- get _isCanceled() {
1697
- return getUint16(6, this) === 2;
1698
- }
1699
- set canceled(_) {
1700
- setUint16(6, 2, this);
1701
- }
1702
- get _isResultsSentElsewhere() {
1703
- return getUint16(6, this) === 3;
1704
- }
1705
- set resultsSentElsewhere(_) {
1706
- setUint16(6, 3, this);
1707
- }
1708
- /**
1709
- * The sender has also sent (before this message) a `Call` with the given question ID and with
1710
- * `sendResultsTo.yourself` set, and the results of that other call should be used as the
1711
- * results here. `takeFromOtherQuestion` can only used once per question.
1712
- *
1713
- */
1714
- get takeFromOtherQuestion() {
1715
- testWhich("takeFromOtherQuestion", getUint16(6, this), 4, this);
1716
- return getUint32(8, this);
1717
- }
1718
- get _isTakeFromOtherQuestion() {
1719
- return getUint16(6, this) === 4;
1720
- }
1721
- set takeFromOtherQuestion(value) {
1722
- setUint16(6, 4, this);
1723
- setUint32(8, value, this);
1724
- }
1725
- _adoptAcceptFromThirdParty(value) {
1726
- setUint16(6, 5, this);
1727
- adopt(value, getPointer(0, this));
1728
- }
1729
- _disownAcceptFromThirdParty() {
1730
- return disown(this.acceptFromThirdParty);
1731
- }
1732
- /**
1733
- * **(level 3)**
1734
- *
1735
- * The caller should contact a third-party vat to pick up the results. An `Accept` message
1736
- * sent to the vat will return the result. This pairs with `Call.sendResultsTo.thirdParty`.
1737
- * It should only be used if the corresponding `Call` had `allowThirdPartyTailCall` set.
1738
- *
1739
- */
1740
- get acceptFromThirdParty() {
1741
- testWhich("acceptFromThirdParty", getUint16(6, this), 5, this);
1742
- return getPointer(0, this);
1743
- }
1744
- _hasAcceptFromThirdParty() {
1745
- return !isNull(getPointer(0, this));
1746
- }
1747
- get _isAcceptFromThirdParty() {
1748
- return getUint16(6, this) === 5;
1749
- }
1750
- set acceptFromThirdParty(value) {
1751
- setUint16(6, 5, this);
1752
- copyFrom(value, getPointer(0, this));
1753
- }
1754
- toString() {
1755
- return "Return_" + super.toString();
1756
- }
1757
- which() {
1758
- return getUint16(6, this);
1759
- }
1760
- };
1761
- var Finish = class _Finish extends Struct {
1762
- static {
1763
- __name(this, "Finish");
1764
- }
1765
- static _capnp = {
1766
- displayName: "Finish",
1767
- id: "d37d2eb2c2f80e63",
1768
- size: new ObjectSize(8, 0),
1769
- defaultReleaseResultCaps: getBitMask(true, 0),
1770
- defaultRequireEarlyCancellationWorkaround: getBitMask(true, 1)
1771
- };
1772
- /**
1773
- * ID of the call whose result is to be released.
1774
- *
1775
- */
1776
- get questionId() {
1777
- return getUint32(0, this);
1778
- }
1779
- set questionId(value) {
1780
- setUint32(0, value, this);
1781
- }
1782
- /**
1783
- * If true, all capabilities that were in the results should be considered released. The sender
1784
- * must not send separate `Release` messages for them. Level 0 implementations in particular
1785
- * should always set this true. This defaults true because if level 0 implementations forget to
1786
- * set it they'll never notice (just silently leak caps), but if level >=1 implementations forget
1787
- * set it false they'll quickly get errors.
1788
- *
1789
- */
1790
- get releaseResultCaps() {
1791
- return getBit(32, this, _Finish._capnp.defaultReleaseResultCaps);
1792
- }
1793
- set releaseResultCaps(value) {
1794
- setBit(32, value, this, _Finish._capnp.defaultReleaseResultCaps);
1795
- }
1796
- /**
1797
- * If true, if the RPC system receives this Finish message before the original call has even been
1798
- * delivered, it should defer cancellation util after delivery. In particular, this gives the
1799
- * destination object a chance to opt out of cancellation, e.g. as controlled by the
1800
- * `allowCancellation` annotation defined in `c++.capnp`.
1801
- *
1802
- * This is a work-around. Versions 1.0 and up of Cap'n Proto always set this to false. However,
1803
- * older versions of Cap'n Proto unintentionally exhibited this errant behavior by default, and
1804
- * as a result programs built with older versions could be inadvertently relying on their peers
1805
- * to implement the behavior. The purpose of this flag is to let newer versions know when the
1806
- * peer is an older version, so that it can attempt to work around the issue.
1807
- *
1808
- * See also comments in handleFinish() in rpc.c++ for more details.
1809
- *
1810
- */
1811
- get requireEarlyCancellationWorkaround() {
1812
- return getBit(33, this, _Finish._capnp.defaultRequireEarlyCancellationWorkaround);
1813
- }
1814
- set requireEarlyCancellationWorkaround(value) {
1815
- setBit(33, value, this, _Finish._capnp.defaultRequireEarlyCancellationWorkaround);
1816
- }
1817
- toString() {
1818
- return "Finish_" + super.toString();
1819
- }
1820
- };
1821
- var Resolve_Which = {
1822
- /**
1823
- * The ID of the promise to be resolved.
1824
- *
1825
- * Unlike all other instances of `ExportId` sent from the exporter, the `Resolve` message does
1826
- * _not_ increase the reference count of `promiseId`. In fact, it is expected that the receiver
1827
- * will release the export soon after receiving `Resolve`, and the sender will not send this
1828
- * `ExportId` again until it has been released and recycled.
1829
- *
1830
- * When an export ID sent over the wire (e.g. in a `CapDescriptor`) is indicated to be a promise,
1831
- * this indicates that the sender will follow up at some point with a `Resolve` message. If the
1832
- * same `promiseId` is sent again before `Resolve`, still only one `Resolve` is sent. If the
1833
- * same ID is sent again later _after_ a `Resolve`, it can only be because the export's
1834
- * reference count hit zero in the meantime and the ID was re-assigned to a new export, therefore
1835
- * this later promise does _not_ correspond to the earlier `Resolve`.
1836
- *
1837
- * If a promise ID's reference count reaches zero before a `Resolve` is sent, the `Resolve`
1838
- * message may or may not still be sent (the `Resolve` may have already been in-flight when
1839
- * `Release` was sent, but if the `Release` is received before `Resolve` then there is no longer
1840
- * any reason to send a `Resolve`). Thus a `Resolve` may be received for a promise of which
1841
- * the receiver has no knowledge, because it already released it earlier. In this case, the
1842
- * receiver should simply release the capability to which the promise resolved.
1843
- *
1844
- */
1845
- CAP: 0,
1846
- /**
1847
- * The object to which the promise resolved.
1848
- *
1849
- * The sender promises that from this point forth, until `promiseId` is released, it shall
1850
- * simply forward all messages to the capability designated by `cap`. This is true even if
1851
- * `cap` itself happens to designate another promise, and that other promise later resolves --
1852
- * messages sent to `promiseId` shall still go to that other promise, not to its resolution.
1853
- * This is important in the case that the receiver of the `Resolve` ends up sending a
1854
- * `Disembargo` message towards `promiseId` in order to control message ordering -- that
1855
- * `Disembargo` really needs to reflect back to exactly the object designated by `cap` even
1856
- * if that object is itself a promise.
1857
- *
1858
- */
1859
- EXCEPTION: 1
1860
- };
1861
- var Resolve = class extends Struct {
1862
- static {
1863
- __name(this, "Resolve");
1864
- }
1865
- static CAP = Resolve_Which.CAP;
1866
- static EXCEPTION = Resolve_Which.EXCEPTION;
1867
- static _capnp = {
1868
- displayName: "Resolve",
1869
- id: "bbc29655fa89086e",
1870
- size: new ObjectSize(8, 1)
1871
- };
1872
- /**
1873
- * The ID of the promise to be resolved.
1874
- *
1875
- * Unlike all other instances of `ExportId` sent from the exporter, the `Resolve` message does
1876
- * _not_ increase the reference count of `promiseId`. In fact, it is expected that the receiver
1877
- * will release the export soon after receiving `Resolve`, and the sender will not send this
1878
- * `ExportId` again until it has been released and recycled.
1879
- *
1880
- * When an export ID sent over the wire (e.g. in a `CapDescriptor`) is indicated to be a promise,
1881
- * this indicates that the sender will follow up at some point with a `Resolve` message. If the
1882
- * same `promiseId` is sent again before `Resolve`, still only one `Resolve` is sent. If the
1883
- * same ID is sent again later _after_ a `Resolve`, it can only be because the export's
1884
- * reference count hit zero in the meantime and the ID was re-assigned to a new export, therefore
1885
- * this later promise does _not_ correspond to the earlier `Resolve`.
1886
- *
1887
- * If a promise ID's reference count reaches zero before a `Resolve` is sent, the `Resolve`
1888
- * message may or may not still be sent (the `Resolve` may have already been in-flight when
1889
- * `Release` was sent, but if the `Release` is received before `Resolve` then there is no longer
1890
- * any reason to send a `Resolve`). Thus a `Resolve` may be received for a promise of which
1891
- * the receiver has no knowledge, because it already released it earlier. In this case, the
1892
- * receiver should simply release the capability to which the promise resolved.
1893
- *
1894
- */
1895
- get promiseId() {
1896
- return getUint32(0, this);
1897
- }
1898
- set promiseId(value) {
1899
- setUint32(0, value, this);
1900
- }
1901
- _adoptCap(value) {
1902
- setUint16(4, 0, this);
1903
- adopt(value, getPointer(0, this));
1904
- }
1905
- _disownCap() {
1906
- return disown(this.cap);
1907
- }
1908
- /**
1909
- * The object to which the promise resolved.
1910
- *
1911
- * The sender promises that from this point forth, until `promiseId` is released, it shall
1912
- * simply forward all messages to the capability designated by `cap`. This is true even if
1913
- * `cap` itself happens to designate another promise, and that other promise later resolves --
1914
- * messages sent to `promiseId` shall still go to that other promise, not to its resolution.
1915
- * This is important in the case that the receiver of the `Resolve` ends up sending a
1916
- * `Disembargo` message towards `promiseId` in order to control message ordering -- that
1917
- * `Disembargo` really needs to reflect back to exactly the object designated by `cap` even
1918
- * if that object is itself a promise.
1919
- *
1920
- */
1921
- get cap() {
1922
- testWhich("cap", getUint16(4, this), 0, this);
1923
- return getStruct(0, CapDescriptor, this);
1924
- }
1925
- _hasCap() {
1926
- return !isNull(getPointer(0, this));
1927
- }
1928
- _initCap() {
1929
- setUint16(4, 0, this);
1930
- return initStructAt(0, CapDescriptor, this);
1931
- }
1932
- get _isCap() {
1933
- return getUint16(4, this) === 0;
1934
- }
1935
- set cap(value) {
1936
- setUint16(4, 0, this);
1937
- copyFrom(value, getPointer(0, this));
1938
- }
1939
- _adoptException(value) {
1940
- setUint16(4, 1, this);
1941
- adopt(value, getPointer(0, this));
1942
- }
1943
- _disownException() {
1944
- return disown(this.exception);
1945
- }
1946
- /**
1947
- * Indicates that the promise was broken.
1948
- *
1949
- */
1950
- get exception() {
1951
- testWhich("exception", getUint16(4, this), 1, this);
1952
- return getStruct(0, Exception, this);
1953
- }
1954
- _hasException() {
1955
- return !isNull(getPointer(0, this));
1956
- }
1957
- _initException() {
1958
- setUint16(4, 1, this);
1959
- return initStructAt(0, Exception, this);
1960
- }
1961
- get _isException() {
1962
- return getUint16(4, this) === 1;
1963
- }
1964
- set exception(value) {
1965
- setUint16(4, 1, this);
1966
- copyFrom(value, getPointer(0, this));
1967
- }
1968
- toString() {
1969
- return "Resolve_" + super.toString();
1970
- }
1971
- which() {
1972
- return getUint16(4, this);
1973
- }
1974
- };
1975
- var Release = class extends Struct {
1976
- static {
1977
- __name(this, "Release");
1978
- }
1979
- static _capnp = {
1980
- displayName: "Release",
1981
- id: "ad1a6c0d7dd07497",
1982
- size: new ObjectSize(8, 0)
1983
- };
1984
- /**
1985
- * What to release.
1986
- *
1987
- */
1988
- get id() {
1989
- return getUint32(0, this);
1990
- }
1991
- set id(value) {
1992
- setUint32(0, value, this);
1993
- }
1994
- /**
1995
- * The amount by which to decrement the reference count. The export is only actually released
1996
- * when the reference count reaches zero.
1997
- *
1998
- */
1999
- get referenceCount() {
2000
- return getUint32(4, this);
2001
- }
2002
- set referenceCount(value) {
2003
- setUint32(4, value, this);
2004
- }
2005
- toString() {
2006
- return "Release_" + super.toString();
2007
- }
2008
- };
2009
- var Disembargo_Context_Which = {
2010
- /**
2011
- * The sender is requesting a disembargo on a promise that is known to resolve back to a
2012
- * capability hosted by the sender. As soon as the receiver has echoed back all pipelined calls
2013
- * on this promise, it will deliver the Disembargo back to the sender with `receiverLoopback`
2014
- * set to the same value as `senderLoopback`. This value is chosen by the sender, and since
2015
- * it is also consumed be the sender, the sender can use whatever strategy it wants to make sure
2016
- * the value is unambiguous.
2017
- *
2018
- * The receiver must verify that the target capability actually resolves back to the sender's
2019
- * vat. Otherwise, the sender has committed a protocol error and should be disconnected.
2020
- *
2021
- */
2022
- SENDER_LOOPBACK: 0,
2023
- /**
2024
- * The receiver previously sent a `senderLoopback` Disembargo towards a promise resolving to
2025
- * this capability, and that Disembargo is now being echoed back.
2026
- *
2027
- */
2028
- RECEIVER_LOOPBACK: 1,
2029
- /**
2030
- * **(level 3)**
2031
- *
2032
- * The sender is requesting a disembargo on a promise that is known to resolve to a third-party
2033
- * capability that the sender is currently in the process of accepting (using `Accept`).
2034
- * The receiver of this `Disembargo` has an outstanding `Provide` on said capability. The
2035
- * receiver should now send a `Disembargo` with `provide` set to the question ID of that
2036
- * `Provide` message.
2037
- *
2038
- * See `Accept.embargo` for an example.
2039
- *
2040
- */
2041
- ACCEPT: 2,
2042
- /**
2043
- * **(level 3)**
2044
- *
2045
- * The sender is requesting a disembargo on a capability currently being provided to a third
2046
- * party. The question ID identifies the `Provide` message previously sent by the sender to
2047
- * this capability. On receipt, the receiver (the capability host) shall release the embargo
2048
- * on the `Accept` message that it has received from the third party. See `Accept.embargo` for
2049
- * an example.
2050
- *
2051
- */
2052
- PROVIDE: 3
2053
- };
2054
- var Disembargo_Context = class extends Struct {
2055
- static {
2056
- __name(this, "Disembargo_Context");
2057
- }
2058
- static SENDER_LOOPBACK = Disembargo_Context_Which.SENDER_LOOPBACK;
2059
- static RECEIVER_LOOPBACK = Disembargo_Context_Which.RECEIVER_LOOPBACK;
2060
- static ACCEPT = Disembargo_Context_Which.ACCEPT;
2061
- static PROVIDE = Disembargo_Context_Which.PROVIDE;
2062
- static _capnp = {
2063
- displayName: "context",
2064
- id: "d562b4df655bdd4d",
2065
- size: new ObjectSize(8, 1)
2066
- };
2067
- /**
2068
- * The sender is requesting a disembargo on a promise that is known to resolve back to a
2069
- * capability hosted by the sender. As soon as the receiver has echoed back all pipelined calls
2070
- * on this promise, it will deliver the Disembargo back to the sender with `receiverLoopback`
2071
- * set to the same value as `senderLoopback`. This value is chosen by the sender, and since
2072
- * it is also consumed be the sender, the sender can use whatever strategy it wants to make sure
2073
- * the value is unambiguous.
2074
- *
2075
- * The receiver must verify that the target capability actually resolves back to the sender's
2076
- * vat. Otherwise, the sender has committed a protocol error and should be disconnected.
2077
- *
2078
- */
2079
- get senderLoopback() {
2080
- testWhich("senderLoopback", getUint16(4, this), 0, this);
2081
- return getUint32(0, this);
2082
- }
2083
- get _isSenderLoopback() {
2084
- return getUint16(4, this) === 0;
2085
- }
2086
- set senderLoopback(value) {
2087
- setUint16(4, 0, this);
2088
- setUint32(0, value, this);
2089
- }
2090
- /**
2091
- * The receiver previously sent a `senderLoopback` Disembargo towards a promise resolving to
2092
- * this capability, and that Disembargo is now being echoed back.
2093
- *
2094
- */
2095
- get receiverLoopback() {
2096
- testWhich("receiverLoopback", getUint16(4, this), 1, this);
2097
- return getUint32(0, this);
2098
- }
2099
- get _isReceiverLoopback() {
2100
- return getUint16(4, this) === 1;
2101
- }
2102
- set receiverLoopback(value) {
2103
- setUint16(4, 1, this);
2104
- setUint32(0, value, this);
2105
- }
2106
- get _isAccept() {
2107
- return getUint16(4, this) === 2;
2108
- }
2109
- set accept(_) {
2110
- setUint16(4, 2, this);
2111
- }
2112
- /**
2113
- * **(level 3)**
2114
- *
2115
- * The sender is requesting a disembargo on a capability currently being provided to a third
2116
- * party. The question ID identifies the `Provide` message previously sent by the sender to
2117
- * this capability. On receipt, the receiver (the capability host) shall release the embargo
2118
- * on the `Accept` message that it has received from the third party. See `Accept.embargo` for
2119
- * an example.
2120
- *
2121
- */
2122
- get provide() {
2123
- testWhich("provide", getUint16(4, this), 3, this);
2124
- return getUint32(0, this);
2125
- }
2126
- get _isProvide() {
2127
- return getUint16(4, this) === 3;
2128
- }
2129
- set provide(value) {
2130
- setUint16(4, 3, this);
2131
- setUint32(0, value, this);
2132
- }
2133
- toString() {
2134
- return "Disembargo_Context_" + super.toString();
2135
- }
2136
- which() {
2137
- return getUint16(4, this);
2138
- }
2139
- };
2140
- var Disembargo = class extends Struct {
2141
- static {
2142
- __name(this, "Disembargo");
2143
- }
2144
- static _capnp = {
2145
- displayName: "Disembargo",
2146
- id: "f964368b0fbd3711",
2147
- size: new ObjectSize(8, 1)
2148
- };
2149
- _adoptTarget(value) {
2150
- adopt(value, getPointer(0, this));
2151
- }
2152
- _disownTarget() {
2153
- return disown(this.target);
2154
- }
2155
- /**
2156
- * What is to be disembargoed.
2157
- *
2158
- */
2159
- get target() {
2160
- return getStruct(0, MessageTarget, this);
2161
- }
2162
- _hasTarget() {
2163
- return !isNull(getPointer(0, this));
2164
- }
2165
- _initTarget() {
2166
- return initStructAt(0, MessageTarget, this);
2167
- }
2168
- set target(value) {
2169
- copyFrom(value, getPointer(0, this));
2170
- }
2171
- get context() {
2172
- return getAs(Disembargo_Context, this);
2173
- }
2174
- _initContext() {
2175
- return getAs(Disembargo_Context, this);
2176
- }
2177
- toString() {
2178
- return "Disembargo_" + super.toString();
2179
- }
2180
- };
2181
- var Provide = class extends Struct {
2182
- static {
2183
- __name(this, "Provide");
2184
- }
2185
- static _capnp = {
2186
- displayName: "Provide",
2187
- id: "9c6a046bfbc1ac5a",
2188
- size: new ObjectSize(8, 2)
2189
- };
2190
- /**
2191
- * Question ID to be held open until the recipient has received the capability. A result will be
2192
- * returned once the third party has successfully received the capability. The sender must at some
2193
- * point send a `Finish` message as with any other call, and that message can be used to cancel the
2194
- * whole operation.
2195
- *
2196
- */
2197
- get questionId() {
2198
- return getUint32(0, this);
2199
- }
2200
- set questionId(value) {
2201
- setUint32(0, value, this);
2202
- }
2203
- _adoptTarget(value) {
2204
- adopt(value, getPointer(0, this));
2205
- }
2206
- _disownTarget() {
2207
- return disown(this.target);
2208
- }
2209
- /**
2210
- * What is to be provided to the third party.
2211
- *
2212
- */
2213
- get target() {
2214
- return getStruct(0, MessageTarget, this);
2215
- }
2216
- _hasTarget() {
2217
- return !isNull(getPointer(0, this));
2218
- }
2219
- _initTarget() {
2220
- return initStructAt(0, MessageTarget, this);
2221
- }
2222
- set target(value) {
2223
- copyFrom(value, getPointer(0, this));
2224
- }
2225
- _adoptRecipient(value) {
2226
- adopt(value, getPointer(1, this));
2227
- }
2228
- _disownRecipient() {
2229
- return disown(this.recipient);
2230
- }
2231
- /**
2232
- * Identity of the third party that is expected to pick up the capability.
2233
- *
2234
- */
2235
- get recipient() {
2236
- return getPointer(1, this);
2237
- }
2238
- _hasRecipient() {
2239
- return !isNull(getPointer(1, this));
2240
- }
2241
- set recipient(value) {
2242
- copyFrom(value, getPointer(1, this));
2243
- }
2244
- toString() {
2245
- return "Provide_" + super.toString();
2246
- }
2247
- };
2248
- var Accept = class extends Struct {
2249
- static {
2250
- __name(this, "Accept");
2251
- }
2252
- static _capnp = {
2253
- displayName: "Accept",
2254
- id: "d4c9b56290554016",
2255
- size: new ObjectSize(8, 1)
2256
- };
2257
- /**
2258
- * A new question ID identifying this accept message, which will eventually receive a Return
2259
- * message containing the provided capability (or the call result in the case of a redirected
2260
- * return).
2261
- *
2262
- */
2263
- get questionId() {
2264
- return getUint32(0, this);
2265
- }
2266
- set questionId(value) {
2267
- setUint32(0, value, this);
2268
- }
2269
- _adoptProvision(value) {
2270
- adopt(value, getPointer(0, this));
2271
- }
2272
- _disownProvision() {
2273
- return disown(this.provision);
2274
- }
2275
- /**
2276
- * Identifies the provided object to be picked up.
2277
- *
2278
- */
2279
- get provision() {
2280
- return getPointer(0, this);
2281
- }
2282
- _hasProvision() {
2283
- return !isNull(getPointer(0, this));
2284
- }
2285
- set provision(value) {
2286
- copyFrom(value, getPointer(0, this));
2287
- }
2288
- /**
2289
- * If true, this accept shall be temporarily embargoed. The resulting `Return` will not be sent,
2290
- * and any pipelined calls will not be delivered, until the embargo is released. The receiver
2291
- * (the capability host) will expect the provider (the vat that sent the `Provide` message) to
2292
- * eventually send a `Disembargo` message with the field `context.provide` set to the question ID
2293
- * of the original `Provide` message. At that point, the embargo is released and the queued
2294
- * messages are delivered.
2295
- *
2296
- * For example:
2297
- * - Alice, in Vat A, holds a promise P, which currently points toward Vat B.
2298
- * - Alice calls foo() on P. The `Call` message is sent to Vat B.
2299
- * - The promise P in Vat B ends up resolving to Carol, in Vat C.
2300
- * - Vat B sends a `Provide` message to Vat C, identifying Vat A as the recipient.
2301
- * - Vat B sends a `Resolve` message to Vat A, indicating that the promise has resolved to a
2302
- * `ThirdPartyCapId` identifying Carol in Vat C.
2303
- * - Vat A sends an `Accept` message to Vat C to pick up the capability. Since Vat A knows that
2304
- * it has an outstanding call to the promise, it sets `embargo` to `true` in the `Accept`
2305
- * message.
2306
- * - Vat A sends a `Disembargo` message to Vat B on promise P, with `context.accept` set.
2307
- * - Alice makes a call bar() to promise P, which is now pointing towards Vat C. Alice doesn't
2308
- * know anything about the mechanics of promise resolution happening under the hood, but she
2309
- * expects that bar() will be delivered after foo() because that is the order in which she
2310
- * initiated the calls.
2311
- * - Vat A sends the bar() call to Vat C, as a pipelined call on the result of the `Accept` (which
2312
- * hasn't returned yet, due to the embargo). Since calls to the newly-accepted capability
2313
- * are embargoed, Vat C does not deliver the call yet.
2314
- * - At some point, Vat B forwards the foo() call from the beginning of this example on to Vat C.
2315
- * - Vat B forwards the `Disembargo` from Vat A on to vat C. It sets `context.provide` to the
2316
- * question ID of the `Provide` message it had sent previously.
2317
- * - Vat C receives foo() before `Disembargo`, thus allowing it to correctly deliver foo()
2318
- * before delivering bar().
2319
- * - Vat C receives `Disembargo` from Vat B. It can now send a `Return` for the `Accept` from
2320
- * Vat A, as well as deliver bar().
2321
- *
2322
- */
2323
- get embargo() {
2324
- return getBit(32, this);
2325
- }
2326
- set embargo(value) {
2327
- setBit(32, value, this);
2328
- }
2329
- toString() {
2330
- return "Accept_" + super.toString();
2331
- }
2332
- };
2333
- var Join = class extends Struct {
2334
- static {
2335
- __name(this, "Join");
2336
- }
2337
- static _capnp = {
2338
- displayName: "Join",
2339
- id: "fbe1980490e001af",
2340
- size: new ObjectSize(8, 2)
2341
- };
2342
- /**
2343
- * Question ID used to respond to this Join. (Note that this ID only identifies one part of the
2344
- * request for one hop; each part has a different ID and relayed copies of the request have
2345
- * (probably) different IDs still.)
2346
- *
2347
- * The receiver will reply with a `Return` whose `results` is a JoinResult. This `JoinResult`
2348
- * is relayed from the joined object's host, possibly with transformation applied as needed
2349
- * by the network.
2350
- *
2351
- * Like any return, the result must be released using a `Finish`. However, this release
2352
- * should not occur until the joiner has either successfully connected to the joined object.
2353
- * Vats relaying a `Join` message similarly must not release the result they receive until the
2354
- * return they relayed back towards the joiner has itself been released. This allows the
2355
- * joined object's host to detect when the Join operation is canceled before completing -- if
2356
- * it receives a `Finish` for one of the join results before the joiner successfully
2357
- * connects. It can then free any resources it had allocated as part of the join.
2358
- *
2359
- */
2360
- get questionId() {
2361
- return getUint32(0, this);
2362
- }
2363
- set questionId(value) {
2364
- setUint32(0, value, this);
2365
- }
2366
- _adoptTarget(value) {
2367
- adopt(value, getPointer(0, this));
2368
- }
2369
- _disownTarget() {
2370
- return disown(this.target);
2371
- }
2372
- /**
2373
- * The capability to join.
2374
- *
2375
- */
2376
- get target() {
2377
- return getStruct(0, MessageTarget, this);
2378
- }
2379
- _hasTarget() {
2380
- return !isNull(getPointer(0, this));
2381
- }
2382
- _initTarget() {
2383
- return initStructAt(0, MessageTarget, this);
2384
- }
2385
- set target(value) {
2386
- copyFrom(value, getPointer(0, this));
2387
- }
2388
- _adoptKeyPart(value) {
2389
- adopt(value, getPointer(1, this));
2390
- }
2391
- _disownKeyPart() {
2392
- return disown(this.keyPart);
2393
- }
2394
- /**
2395
- * A part of the join key. These combine to form the complete join key, which is used to establish
2396
- * a direct connection.
2397
- *
2398
- */
2399
- get keyPart() {
2400
- return getPointer(1, this);
2401
- }
2402
- _hasKeyPart() {
2403
- return !isNull(getPointer(1, this));
2404
- }
2405
- set keyPart(value) {
2406
- copyFrom(value, getPointer(1, this));
2407
- }
2408
- toString() {
2409
- return "Join_" + super.toString();
2410
- }
2411
- };
2412
- var MessageTarget_Which = {
2413
- /**
2414
- * This message is to a capability or promise previously imported by the caller (exported by
2415
- * the receiver).
2416
- *
2417
- */
2418
- IMPORTED_CAP: 0,
2419
- /**
2420
- * This message is to a capability that is expected to be returned by another call that has not
2421
- * yet been completed.
2422
- *
2423
- * At level 0, this is supported only for addressing the result of a previous `Bootstrap`, so
2424
- * that initial startup doesn't require a round trip.
2425
- *
2426
- */
2427
- PROMISED_ANSWER: 1
2428
- };
2429
- var MessageTarget = class extends Struct {
2430
- static {
2431
- __name(this, "MessageTarget");
2432
- }
2433
- static IMPORTED_CAP = MessageTarget_Which.IMPORTED_CAP;
2434
- static PROMISED_ANSWER = MessageTarget_Which.PROMISED_ANSWER;
2435
- static _capnp = {
2436
- displayName: "MessageTarget",
2437
- id: "95bc14545813fbc1",
2438
- size: new ObjectSize(8, 1)
2439
- };
2440
- /**
2441
- * This message is to a capability or promise previously imported by the caller (exported by
2442
- * the receiver).
2443
- *
2444
- */
2445
- get importedCap() {
2446
- testWhich("importedCap", getUint16(4, this), 0, this);
2447
- return getUint32(0, this);
2448
- }
2449
- get _isImportedCap() {
2450
- return getUint16(4, this) === 0;
2451
- }
2452
- set importedCap(value) {
2453
- setUint16(4, 0, this);
2454
- setUint32(0, value, this);
2455
- }
2456
- _adoptPromisedAnswer(value) {
2457
- setUint16(4, 1, this);
2458
- adopt(value, getPointer(0, this));
2459
- }
2460
- _disownPromisedAnswer() {
2461
- return disown(this.promisedAnswer);
2462
- }
2463
- /**
2464
- * This message is to a capability that is expected to be returned by another call that has not
2465
- * yet been completed.
2466
- *
2467
- * At level 0, this is supported only for addressing the result of a previous `Bootstrap`, so
2468
- * that initial startup doesn't require a round trip.
2469
- *
2470
- */
2471
- get promisedAnswer() {
2472
- testWhich("promisedAnswer", getUint16(4, this), 1, this);
2473
- return getStruct(0, PromisedAnswer, this);
2474
- }
2475
- _hasPromisedAnswer() {
2476
- return !isNull(getPointer(0, this));
2477
- }
2478
- _initPromisedAnswer() {
2479
- setUint16(4, 1, this);
2480
- return initStructAt(0, PromisedAnswer, this);
2481
- }
2482
- get _isPromisedAnswer() {
2483
- return getUint16(4, this) === 1;
2484
- }
2485
- set promisedAnswer(value) {
2486
- setUint16(4, 1, this);
2487
- copyFrom(value, getPointer(0, this));
2488
- }
2489
- toString() {
2490
- return "MessageTarget_" + super.toString();
2491
- }
2492
- which() {
2493
- return getUint16(4, this);
2494
- }
2495
- };
2496
- var Payload = class _Payload extends Struct {
2497
- static {
2498
- __name(this, "Payload");
2499
- }
2500
- static _capnp = {
2501
- displayName: "Payload",
2502
- id: "9a0e61223d96743b",
2503
- size: new ObjectSize(0, 2)
2504
- };
2505
- static _CapTable;
2506
- _adoptContent(value) {
2507
- adopt(value, getPointer(0, this));
2508
- }
2509
- _disownContent() {
2510
- return disown(this.content);
2511
- }
2512
- /**
2513
- * Some Cap'n Proto data structure. Capability pointers embedded in this structure index into
2514
- * `capTable`.
2515
- *
2516
- */
2517
- get content() {
2518
- return getPointer(0, this);
2519
- }
2520
- _hasContent() {
2521
- return !isNull(getPointer(0, this));
2522
- }
2523
- set content(value) {
2524
- copyFrom(value, getPointer(0, this));
2525
- }
2526
- _adoptCapTable(value) {
2527
- adopt(value, getPointer(1, this));
2528
- }
2529
- _disownCapTable() {
2530
- return disown(this.capTable);
2531
- }
2532
- /**
2533
- * Descriptors corresponding to the cap pointers in `content`.
2534
- *
2535
- */
2536
- get capTable() {
2537
- return getList(1, _Payload._CapTable, this);
2538
- }
2539
- _hasCapTable() {
2540
- return !isNull(getPointer(1, this));
2541
- }
2542
- _initCapTable(length) {
2543
- return initList(1, _Payload._CapTable, length, this);
2544
- }
2545
- set capTable(value) {
2546
- copyFrom(value, getPointer(1, this));
2547
- }
2548
- toString() {
2549
- return "Payload_" + super.toString();
2550
- }
2551
- };
2552
- var CapDescriptor_Which = {
2553
- /**
2554
- * There is no capability here. This `CapDescriptor` should not appear in the payload content.
2555
- * A `none` CapDescriptor can be generated when an application inserts a capability into a
2556
- * message and then later changes its mind and removes it -- rewriting all of the other
2557
- * capability pointers may be hard, so instead a tombstone is left, similar to the way a removed
2558
- * struct or list instance is zeroed out of the message but the space is not reclaimed.
2559
- * Hopefully this is unusual.
2560
- *
2561
- */
2562
- NONE: 0,
2563
- /**
2564
- * The ID of a capability in the sender's export table (receiver's import table). It may be a
2565
- * newly allocated table entry, or an existing entry (increments the reference count).
2566
- *
2567
- */
2568
- SENDER_HOSTED: 1,
2569
- /**
2570
- * A promise that the sender will resolve later. The sender will send exactly one Resolve
2571
- * message at a future point in time to replace this promise. Note that even if the same
2572
- * `senderPromise` is received multiple times, only one `Resolve` is sent to cover all of
2573
- * them. If `senderPromise` is released before the `Resolve` is sent, the sender (of this
2574
- * `CapDescriptor`) may choose not to send the `Resolve` at all.
2575
- *
2576
- */
2577
- SENDER_PROMISE: 2,
2578
- /**
2579
- * A capability (or promise) previously exported by the receiver (imported by the sender).
2580
- *
2581
- */
2582
- RECEIVER_HOSTED: 3,
2583
- /**
2584
- * A capability expected to be returned in the results of a currently-outstanding call posed
2585
- * by the sender.
2586
- *
2587
- */
2588
- RECEIVER_ANSWER: 4,
2589
- /**
2590
- * **(level 3)**
2591
- *
2592
- * A capability that lives in neither the sender's nor the receiver's vat. The sender needs
2593
- * to form a direct connection to a third party to pick up the capability.
2594
- *
2595
- * Level 1 and 2 implementations that receive a `thirdPartyHosted` may simply send calls to its
2596
- * `vine` instead.
2597
- *
2598
- */
2599
- THIRD_PARTY_HOSTED: 5
2600
- };
2601
- var CapDescriptor = class _CapDescriptor extends Struct {
2602
- static {
2603
- __name(this, "CapDescriptor");
2604
- }
2605
- static NONE = CapDescriptor_Which.NONE;
2606
- static SENDER_HOSTED = CapDescriptor_Which.SENDER_HOSTED;
2607
- static SENDER_PROMISE = CapDescriptor_Which.SENDER_PROMISE;
2608
- static RECEIVER_HOSTED = CapDescriptor_Which.RECEIVER_HOSTED;
2609
- static RECEIVER_ANSWER = CapDescriptor_Which.RECEIVER_ANSWER;
2610
- static THIRD_PARTY_HOSTED = CapDescriptor_Which.THIRD_PARTY_HOSTED;
2611
- static _capnp = {
2612
- displayName: "CapDescriptor",
2613
- id: "8523ddc40b86b8b0",
2614
- size: new ObjectSize(8, 1),
2615
- defaultAttachedFd: getUint8Mask(255)
2616
- };
2617
- get _isNone() {
2618
- return getUint16(0, this) === 0;
2619
- }
2620
- set none(_) {
2621
- setUint16(0, 0, this);
2622
- }
2623
- /**
2624
- * The ID of a capability in the sender's export table (receiver's import table). It may be a
2625
- * newly allocated table entry, or an existing entry (increments the reference count).
2626
- *
2627
- */
2628
- get senderHosted() {
2629
- testWhich("senderHosted", getUint16(0, this), 1, this);
2630
- return getUint32(4, this);
2631
- }
2632
- get _isSenderHosted() {
2633
- return getUint16(0, this) === 1;
2634
- }
2635
- set senderHosted(value) {
2636
- setUint16(0, 1, this);
2637
- setUint32(4, value, this);
2638
- }
2639
- /**
2640
- * A promise that the sender will resolve later. The sender will send exactly one Resolve
2641
- * message at a future point in time to replace this promise. Note that even if the same
2642
- * `senderPromise` is received multiple times, only one `Resolve` is sent to cover all of
2643
- * them. If `senderPromise` is released before the `Resolve` is sent, the sender (of this
2644
- * `CapDescriptor`) may choose not to send the `Resolve` at all.
2645
- *
2646
- */
2647
- get senderPromise() {
2648
- testWhich("senderPromise", getUint16(0, this), 2, this);
2649
- return getUint32(4, this);
2650
- }
2651
- get _isSenderPromise() {
2652
- return getUint16(0, this) === 2;
2653
- }
2654
- set senderPromise(value) {
2655
- setUint16(0, 2, this);
2656
- setUint32(4, value, this);
2657
- }
2658
- /**
2659
- * A capability (or promise) previously exported by the receiver (imported by the sender).
2660
- *
2661
- */
2662
- get receiverHosted() {
2663
- testWhich("receiverHosted", getUint16(0, this), 3, this);
2664
- return getUint32(4, this);
2665
- }
2666
- get _isReceiverHosted() {
2667
- return getUint16(0, this) === 3;
2668
- }
2669
- set receiverHosted(value) {
2670
- setUint16(0, 3, this);
2671
- setUint32(4, value, this);
2672
- }
2673
- _adoptReceiverAnswer(value) {
2674
- setUint16(0, 4, this);
2675
- adopt(value, getPointer(0, this));
2676
- }
2677
- _disownReceiverAnswer() {
2678
- return disown(this.receiverAnswer);
2679
- }
2680
- /**
2681
- * A capability expected to be returned in the results of a currently-outstanding call posed
2682
- * by the sender.
2683
- *
2684
- */
2685
- get receiverAnswer() {
2686
- testWhich("receiverAnswer", getUint16(0, this), 4, this);
2687
- return getStruct(0, PromisedAnswer, this);
2688
- }
2689
- _hasReceiverAnswer() {
2690
- return !isNull(getPointer(0, this));
2691
- }
2692
- _initReceiverAnswer() {
2693
- setUint16(0, 4, this);
2694
- return initStructAt(0, PromisedAnswer, this);
2695
- }
2696
- get _isReceiverAnswer() {
2697
- return getUint16(0, this) === 4;
2698
- }
2699
- set receiverAnswer(value) {
2700
- setUint16(0, 4, this);
2701
- copyFrom(value, getPointer(0, this));
2702
- }
2703
- _adoptThirdPartyHosted(value) {
2704
- setUint16(0, 5, this);
2705
- adopt(value, getPointer(0, this));
2706
- }
2707
- _disownThirdPartyHosted() {
2708
- return disown(this.thirdPartyHosted);
2709
- }
2710
- /**
2711
- * **(level 3)**
2712
- *
2713
- * A capability that lives in neither the sender's nor the receiver's vat. The sender needs
2714
- * to form a direct connection to a third party to pick up the capability.
2715
- *
2716
- * Level 1 and 2 implementations that receive a `thirdPartyHosted` may simply send calls to its
2717
- * `vine` instead.
2718
- *
2719
- */
2720
- get thirdPartyHosted() {
2721
- testWhich("thirdPartyHosted", getUint16(0, this), 5, this);
2722
- return getStruct(0, ThirdPartyCapDescriptor, this);
2723
- }
2724
- _hasThirdPartyHosted() {
2725
- return !isNull(getPointer(0, this));
2726
- }
2727
- _initThirdPartyHosted() {
2728
- setUint16(0, 5, this);
2729
- return initStructAt(0, ThirdPartyCapDescriptor, this);
2730
- }
2731
- get _isThirdPartyHosted() {
2732
- return getUint16(0, this) === 5;
2733
- }
2734
- set thirdPartyHosted(value) {
2735
- setUint16(0, 5, this);
2736
- copyFrom(value, getPointer(0, this));
2737
- }
2738
- /**
2739
- * If the RPC message in which this CapDescriptor was delivered also had file descriptors
2740
- * attached, and `fd` is a valid index into the list of attached file descriptors, then
2741
- * that file descriptor should be attached to this capability. If `attachedFd` is out-of-bounds
2742
- * for said list, then no FD is attached.
2743
- *
2744
- * For example, if the RPC message arrived over a Unix socket, then file descriptors may be
2745
- * attached by sending an SCM_RIGHTS ancillary message attached to the data bytes making up the
2746
- * raw message. Receivers who wish to opt into FD passing should arrange to receive SCM_RIGHTS
2747
- * whenever receiving an RPC message. Senders who wish to send FDs need not verify whether the
2748
- * receiver knows how to receive them, because the operating system will automatically discard
2749
- * ancillary messages like SCM_RIGHTS if the receiver doesn't ask to receive them, including
2750
- * automatically closing any FDs.
2751
- *
2752
- * It is up to the application protocol to define what capabilities are expected to have file
2753
- * descriptors attached, and what those FDs mean. But, for example, an application could use this
2754
- * to open a file on disk and then transmit the open file descriptor to a sandboxed process that
2755
- * does not otherwise have permission to access the filesystem directly. This is usually an
2756
- * optimization: the sending process could instead provide an RPC interface supporting all the
2757
- * operations needed (such as reading and writing a file), but by passing the file descriptor
2758
- * directly, the recipient can often perform operations much more efficiently. Application
2759
- * designers are encouraged to provide such RPC interfaces and automatically fall back to them
2760
- * when FD passing is not available, so that the application can still work when the parties are
2761
- * remote over a network.
2762
- *
2763
- * An attached FD is most often associated with a `senderHosted` descriptor. It could also make
2764
- * sense in the case of `thirdPartyHosted`: in this case, the sender is forwarding the FD that
2765
- * they received from the third party, so that the receiver can start using it without first
2766
- * interacting with the third party. This is an optional optimization -- the middleman may choose
2767
- * not to forward capabilities, in which case the receiver will need to complete the handshake
2768
- * with the third party directly before receiving the FD. If an implementation receives a second
2769
- * attached FD after having already received one previously (e.g. both in a `thirdPartyHosted`
2770
- * CapDescriptor and then later again when receiving the final capability directly from the
2771
- * third party), the implementation should discard the later FD and stick with the original. At
2772
- * present, there is no known reason why other capability types (e.g. `receiverHosted`) would want
2773
- * to carry an attached FD, but we reserve the right to define a meaning for this in the future.
2774
- *
2775
- * Each file descriptor attached to the message must be used in no more than one CapDescriptor,
2776
- * so that the receiver does not need to use dup() or refcounting to handle the possibility of
2777
- * multiple capabilities using the same descriptor. If multiple CapDescriptors do point to the
2778
- * same FD index, then the receiver can arbitrarily choose which capability ends up having the
2779
- * FD attached.
2780
- *
2781
- * To mitigate DoS attacks, RPC implementations should limit the number of FDs they are willing to
2782
- * receive in a single message to a small value. If a message happens to contain more than that,
2783
- * the list is truncated. Moreover, in some cases, FD passing needs to be blocked entirely for
2784
- * security or implementation reasons, in which case the list may be truncated to zero. Hence,
2785
- * `attachedFd` might point past the end of the list, which the implementation should treat as if
2786
- * no FD was attached at all.
2787
- *
2788
- * The type of this field was chosen to be UInt8 because Linux supports sending only a maximum
2789
- * of 253 file descriptors in an SCM_RIGHTS message anyway, and CapDescriptor had two bytes of
2790
- * padding left -- so after adding this, there is still one byte for a future feature.
2791
- * Conveniently, this also means we're able to use 0xff as the default value, which will always
2792
- * be out-of-range (of course, the implementation should explicitly enforce that 255 descriptors
2793
- * cannot be sent at once, rather than relying on Linux to do so).
2794
- *
2795
- */
2796
- get attachedFd() {
2797
- return getUint8(2, this, _CapDescriptor._capnp.defaultAttachedFd);
2798
- }
2799
- set attachedFd(value) {
2800
- setUint8(2, value, this, _CapDescriptor._capnp.defaultAttachedFd);
2801
- }
2802
- toString() {
2803
- return "CapDescriptor_" + super.toString();
2804
- }
2805
- which() {
2806
- return getUint16(0, this);
2807
- }
2808
- };
2809
- var PromisedAnswer_Op_Which = {
2810
- /**
2811
- * Does nothing. This member is mostly defined so that we can make `Op` a union even
2812
- * though (as of this writing) only one real operation is defined.
2813
- *
2814
- */
2815
- NOOP: 0,
2816
- /**
2817
- * Get a pointer field within a struct. The number is an index into the pointer section, NOT
2818
- * a field ordinal, so that the receiver does not need to understand the schema.
2819
- *
2820
- */
2821
- GET_POINTER_FIELD: 1
2822
- };
2823
- var PromisedAnswer_Op = class extends Struct {
2824
- static {
2825
- __name(this, "PromisedAnswer_Op");
2826
- }
2827
- static NOOP = PromisedAnswer_Op_Which.NOOP;
2828
- static GET_POINTER_FIELD = PromisedAnswer_Op_Which.GET_POINTER_FIELD;
2829
- static _capnp = {
2830
- displayName: "Op",
2831
- id: "f316944415569081",
2832
- size: new ObjectSize(8, 0)
2833
- };
2834
- get _isNoop() {
2835
- return getUint16(0, this) === 0;
2836
- }
2837
- set noop(_) {
2838
- setUint16(0, 0, this);
2839
- }
2840
- /**
2841
- * Get a pointer field within a struct. The number is an index into the pointer section, NOT
2842
- * a field ordinal, so that the receiver does not need to understand the schema.
2843
- *
2844
- */
2845
- get getPointerField() {
2846
- testWhich("getPointerField", getUint16(0, this), 1, this);
2847
- return getUint16(2, this);
2848
- }
2849
- get _isGetPointerField() {
2850
- return getUint16(0, this) === 1;
2851
- }
2852
- set getPointerField(value) {
2853
- setUint16(0, 1, this);
2854
- setUint16(2, value, this);
2855
- }
2856
- toString() {
2857
- return "PromisedAnswer_Op_" + super.toString();
2858
- }
2859
- which() {
2860
- return getUint16(0, this);
2861
- }
2862
- };
2863
- var PromisedAnswer = class _PromisedAnswer extends Struct {
2864
- static {
2865
- __name(this, "PromisedAnswer");
2866
- }
2867
- static Op = PromisedAnswer_Op;
2868
- static _capnp = {
2869
- displayName: "PromisedAnswer",
2870
- id: "d800b1d6cd6f1ca0",
2871
- size: new ObjectSize(8, 1)
2872
- };
2873
- static _Transform;
2874
- /**
2875
- * ID of the question (in the sender's question table / receiver's answer table) whose answer is
2876
- * expected to contain the capability.
2877
- *
2878
- */
2879
- get questionId() {
2880
- return getUint32(0, this);
2881
- }
2882
- set questionId(value) {
2883
- setUint32(0, value, this);
2884
- }
2885
- _adoptTransform(value) {
2886
- adopt(value, getPointer(0, this));
2887
- }
2888
- _disownTransform() {
2889
- return disown(this.transform);
2890
- }
2891
- /**
2892
- * Operations / transformations to apply to the result in order to get the capability actually
2893
- * being addressed. E.g. if the result is a struct and you want to call a method on a capability
2894
- * pointed to by a field of the struct, you need a `getPointerField` op.
2895
- *
2896
- */
2897
- get transform() {
2898
- return getList(0, _PromisedAnswer._Transform, this);
2899
- }
2900
- _hasTransform() {
2901
- return !isNull(getPointer(0, this));
2902
- }
2903
- _initTransform(length) {
2904
- return initList(0, _PromisedAnswer._Transform, length, this);
2905
- }
2906
- set transform(value) {
2907
- copyFrom(value, getPointer(0, this));
2908
- }
2909
- toString() {
2910
- return "PromisedAnswer_" + super.toString();
2911
- }
2912
- };
2913
- var ThirdPartyCapDescriptor = class extends Struct {
2914
- static {
2915
- __name(this, "ThirdPartyCapDescriptor");
2916
- }
2917
- static _capnp = {
2918
- displayName: "ThirdPartyCapDescriptor",
2919
- id: "d37007fde1f0027d",
2920
- size: new ObjectSize(8, 1)
2921
- };
2922
- _adoptId(value) {
2923
- adopt(value, getPointer(0, this));
2924
- }
2925
- _disownId() {
2926
- return disown(this.id);
2927
- }
2928
- /**
2929
- * Identifies the third-party host and the specific capability to accept from it.
2930
- *
2931
- */
2932
- get id() {
2933
- return getPointer(0, this);
2934
- }
2935
- _hasId() {
2936
- return !isNull(getPointer(0, this));
2937
- }
2938
- set id(value) {
2939
- copyFrom(value, getPointer(0, this));
2940
- }
2941
- /**
2942
- * A proxy for the third-party object exported by the sender. In CapTP terminology this is called
2943
- * a "vine", because it is an indirect reference to the third-party object that snakes through the
2944
- * sender vat. This serves two purposes:
2945
- *
2946
- * * Level 1 and 2 implementations that don't understand how to connect to a third party may
2947
- * simply send calls to the vine. Such calls will be forwarded to the third-party by the
2948
- * sender.
2949
- *
2950
- * * Level 3 implementations must release the vine only once they have successfully picked up the
2951
- * object from the third party. This ensures that the capability is not released by the sender
2952
- * prematurely.
2953
- *
2954
- * The sender will close the `Provide` request that it has sent to the third party as soon as
2955
- * it receives either a `Call` or a `Release` message directed at the vine.
2956
- *
2957
- */
2958
- get vineId() {
2959
- return getUint32(0, this);
2960
- }
2961
- set vineId(value) {
2962
- setUint32(0, value, this);
2963
- }
2964
- toString() {
2965
- return "ThirdPartyCapDescriptor_" + super.toString();
2966
- }
2967
- };
2968
- var Exception_Type = {
2969
- /**
2970
- * A generic problem occurred, and it is believed that if the operation were repeated without
2971
- * any change in the state of the world, the problem would occur again.
2972
- *
2973
- * A client might respond to this error by logging it for investigation by the developer and/or
2974
- * displaying it to the user.
2975
- *
2976
- */
2977
- FAILED: 0,
2978
- /**
2979
- * The request was rejected due to a temporary lack of resources.
2980
- *
2981
- * Examples include:
2982
- * - There's not enough CPU time to keep up with incoming requests, so some are rejected.
2983
- * - The server ran out of RAM or disk space during the request.
2984
- * - The operation timed out (took significantly longer than it should have).
2985
- *
2986
- * A client might respond to this error by scheduling to retry the operation much later. The
2987
- * client should NOT retry again immediately since this would likely exacerbate the problem.
2988
- *
2989
- */
2990
- OVERLOADED: 1,
2991
- /**
2992
- * The method failed because a connection to some necessary capability was lost.
2993
- *
2994
- * Examples include:
2995
- * - The client introduced the server to a third-party capability, the connection to that third
2996
- * party was subsequently lost, and then the client requested that the server use the dead
2997
- * capability for something.
2998
- * - The client previously requested that the server obtain a capability from some third party.
2999
- * The server returned a capability to an object wrapping the third-party capability. Later,
3000
- * the server's connection to the third party was lost.
3001
- * - The capability has been revoked. Revocation does not necessarily mean that the client is
3002
- * no longer authorized to use the capability; it is often used simply as a way to force the
3003
- * client to repeat the setup process, perhaps to efficiently move them to a new back-end or
3004
- * get them to recognize some other change that has occurred.
3005
- *
3006
- * A client should normally respond to this error by releasing all capabilities it is currently
3007
- * holding related to the one it called and then re-creating them by restoring SturdyRefs and/or
3008
- * repeating the method calls used to create them originally. In other words, disconnect and
3009
- * start over. This should in turn cause the server to obtain a new copy of the capability that
3010
- * it lost, thus making everything work.
3011
- *
3012
- * If the client receives another `disconnected` error in the process of rebuilding the
3013
- * capability and retrying the call, it should treat this as an `overloaded` error: the network
3014
- * is currently unreliable, possibly due to load or other temporary issues.
3015
- *
3016
- */
3017
- DISCONNECTED: 2,
3018
- /**
3019
- * The server doesn't implement the requested method. If there is some other method that the
3020
- * client could call (perhaps an older and/or slower interface), it should try that instead.
3021
- * Otherwise, this should be treated like `failed`.
3022
- *
3023
- */
3024
- UNIMPLEMENTED: 3
3025
- };
3026
- var Exception = class extends Struct {
3027
- static {
3028
- __name(this, "Exception");
3029
- }
3030
- static Type = Exception_Type;
3031
- static _capnp = {
3032
- displayName: "Exception",
3033
- id: "d625b7063acf691a",
3034
- size: new ObjectSize(8, 2)
3035
- };
3036
- /**
3037
- * Human-readable failure description.
3038
- *
3039
- */
3040
- get reason() {
3041
- return getText(0, this);
3042
- }
3043
- set reason(value) {
3044
- setText(0, value, this);
3045
- }
3046
- /**
3047
- * The type of the error. The purpose of this enum is not to describe the error itself, but
3048
- * rather to describe how the client might want to respond to the error.
3049
- *
3050
- */
3051
- get type() {
3052
- return getUint16(4, this);
3053
- }
3054
- set type(value) {
3055
- setUint16(4, value, this);
3056
- }
3057
- /**
3058
- * OBSOLETE. Ignore.
3059
- *
3060
- */
3061
- get obsoleteIsCallersFault() {
3062
- return getBit(0, this);
3063
- }
3064
- set obsoleteIsCallersFault(value) {
3065
- setBit(0, value, this);
3066
- }
3067
- /**
3068
- * OBSOLETE. See `type` instead.
3069
- *
3070
- */
3071
- get obsoleteDurability() {
3072
- return getUint16(2, this);
3073
- }
3074
- set obsoleteDurability(value) {
3075
- setUint16(2, value, this);
3076
- }
3077
- /**
3078
- * Stack trace text from the remote server. The format is not specified. By default,
3079
- * implementations do not provide stack traces; the application must explicitly enable them
3080
- * when desired.
3081
- *
3082
- */
3083
- get trace() {
3084
- return getText(1, this);
3085
- }
3086
- set trace(value) {
3087
- setText(1, value, this);
3088
- }
3089
- toString() {
3090
- return "Exception_" + super.toString();
3091
- }
3092
- };
3093
- Payload._CapTable = CompositeList(CapDescriptor);
3094
- PromisedAnswer._Transform = CompositeList(PromisedAnswer_Op);
3095
-
3096
- // ../../node_modules/.pnpm/capnp-es@0.0.11_patch_hash=53996ae63a1465953815fff49405f2224c85d26eeeff469d2b1f87e1c2af451d_typescript@5.8.3/node_modules/capnp-es/dist/index.mjs
3097
- var Void = class extends Struct {
3098
- static {
3099
- __name(this, "Void");
3100
- }
3101
- static _capnp = {
3102
- displayName: "Void",
3103
- id: "0",
3104
- size: new ObjectSize(0, 0)
3105
- };
3106
- };
3107
- function PointerList(PointerClass) {
3108
- return class extends List {
3109
- static _capnp = {
3110
- displayName: `List<${PointerClass._capnp.displayName}>`,
3111
- size: ListElementSize.POINTER
3112
- };
3113
- get(index) {
3114
- const c = getContent(this);
3115
- return new PointerClass(
3116
- c.segment,
3117
- c.byteOffset + index * 8,
3118
- this._capnp.depthLimit - 1
3119
- );
3120
- }
3121
- set(index, value) {
3122
- copyFrom(value, this.get(index));
3123
- }
3124
- [Symbol.toStringTag]() {
3125
- return `Pointer_${super.toString()},cls:${PointerClass.toString()}`;
3126
- }
3127
- };
3128
- }
3129
- __name(PointerList, "PointerList");
3130
- var AnyPointerList = PointerList(Pointer);
3131
- var BoolList = class extends List {
3132
- static {
3133
- __name(this, "BoolList");
3134
- }
3135
- static _capnp = {
3136
- displayName: "List<boolean>",
3137
- size: ListElementSize.BIT
3138
- };
3139
- get(index) {
3140
- const bitMask = 1 << index % 8;
3141
- const byteOffset = index >>> 3;
3142
- const c = getContent(this);
3143
- const v = c.segment.getUint8(c.byteOffset + byteOffset);
3144
- return (v & bitMask) !== 0;
3145
- }
3146
- set(index, value) {
3147
- const bitMask = 1 << index % 8;
3148
- const c = getContent(this);
3149
- const byteOffset = c.byteOffset + (index >>> 3);
3150
- const v = c.segment.getUint8(byteOffset);
3151
- c.segment.setUint8(byteOffset, value ? v | bitMask : v & ~bitMask);
3152
- }
3153
- [Symbol.toStringTag]() {
3154
- return `Bool_${super.toString()}`;
3155
- }
3156
- };
3157
- var DataList = PointerList(Data);
3158
- var Float32List = class extends List {
3159
- static {
3160
- __name(this, "Float32List");
3161
- }
3162
- static _capnp = {
3163
- displayName: "List<Float32>",
3164
- size: ListElementSize.BYTE_4
3165
- };
3166
- get(index) {
3167
- const c = getContent(this);
3168
- return c.segment.getFloat32(c.byteOffset + index * 4);
3169
- }
3170
- set(index, value) {
3171
- const c = getContent(this);
3172
- c.segment.setFloat32(c.byteOffset + index * 4, value);
3173
- }
3174
- [Symbol.toStringTag]() {
3175
- return `Float32_${super.toString()}`;
3176
- }
3177
- };
3178
- var Float64List = class extends List {
3179
- static {
3180
- __name(this, "Float64List");
3181
- }
3182
- static _capnp = {
3183
- displayName: "List<Float64>",
3184
- size: ListElementSize.BYTE_8
3185
- };
3186
- get(index) {
3187
- const c = getContent(this);
3188
- return c.segment.getFloat64(c.byteOffset + index * 8);
3189
- }
3190
- set(index, value) {
3191
- const c = getContent(this);
3192
- c.segment.setFloat64(c.byteOffset + index * 8, value);
3193
- }
3194
- [Symbol.toStringTag]() {
3195
- return `Float64_${super.toString()}`;
3196
- }
3197
- };
3198
- var Int8List = class extends List {
3199
- static {
3200
- __name(this, "Int8List");
3201
- }
3202
- static _capnp = {
3203
- displayName: "List<Int8>",
3204
- size: ListElementSize.BYTE
3205
- };
3206
- get(index) {
3207
- const c = getContent(this);
3208
- return c.segment.getInt8(c.byteOffset + index);
3209
- }
3210
- set(index, value) {
3211
- const c = getContent(this);
3212
- c.segment.setInt8(c.byteOffset + index, value);
3213
- }
3214
- [Symbol.toStringTag]() {
3215
- return `Int8_${super.toString()}`;
3216
- }
3217
- };
3218
- var Int16List = class extends List {
3219
- static {
3220
- __name(this, "Int16List");
3221
- }
3222
- static _capnp = {
3223
- displayName: "List<Int16>",
3224
- size: ListElementSize.BYTE_2
3225
- };
3226
- get(index) {
3227
- const c = getContent(this);
3228
- return c.segment.getInt16(c.byteOffset + index * 2);
3229
- }
3230
- set(index, value) {
3231
- const c = getContent(this);
3232
- c.segment.setInt16(c.byteOffset + index * 2, value);
3233
- }
3234
- [Symbol.toStringTag]() {
3235
- return `Int16_${super.toString()}`;
3236
- }
3237
- };
3238
- var Int32List = class extends List {
3239
- static {
3240
- __name(this, "Int32List");
3241
- }
3242
- static _capnp = {
3243
- displayName: "List<Int32>",
3244
- size: ListElementSize.BYTE_4
3245
- };
3246
- get(index) {
3247
- const c = getContent(this);
3248
- return c.segment.getInt32(c.byteOffset + index * 4);
3249
- }
3250
- set(index, value) {
3251
- const c = getContent(this);
3252
- c.segment.setInt32(c.byteOffset + index * 4, value);
3253
- }
3254
- [Symbol.toStringTag]() {
3255
- return `Int32_${super.toString()}`;
3256
- }
3257
- };
3258
- var Int64List = class extends List {
3259
- static {
3260
- __name(this, "Int64List");
3261
- }
3262
- static _capnp = {
3263
- displayName: "List<Int64>",
3264
- size: ListElementSize.BYTE_8
3265
- };
3266
- get(index) {
3267
- const c = getContent(this);
3268
- return c.segment.getInt64(c.byteOffset + index * 8);
3269
- }
3270
- set(index, value) {
3271
- const c = getContent(this);
3272
- c.segment.setInt64(c.byteOffset + index * 8, value);
3273
- }
3274
- [Symbol.toStringTag]() {
3275
- return `Int64_${super.toString()}`;
3276
- }
3277
- };
3278
- var InterfaceList = PointerList(Interface);
3279
- var TextList = class extends List {
3280
- static {
3281
- __name(this, "TextList");
3282
- }
3283
- static _capnp = {
3284
- displayName: "List<Text>",
3285
- size: ListElementSize.POINTER
3286
- };
3287
- get(index) {
3288
- const c = getContent(this);
3289
- c.byteOffset += index * 8;
3290
- return Text.fromPointer(c).get(0);
3291
- }
3292
- set(index, value) {
3293
- const c = getContent(this);
3294
- c.byteOffset += index * 8;
3295
- Text.fromPointer(c).set(0, value);
3296
- }
3297
- [Symbol.toStringTag]() {
3298
- return `Text_${super.toString()}`;
3299
- }
3300
- };
3301
- var Uint8List = class extends List {
3302
- static {
3303
- __name(this, "Uint8List");
3304
- }
3305
- static _capnp = {
3306
- displayName: "List<Uint8>",
3307
- size: ListElementSize.BYTE
3308
- };
3309
- get(index) {
3310
- const c = getContent(this);
3311
- return c.segment.getUint8(c.byteOffset + index);
3312
- }
3313
- set(index, value) {
3314
- const c = getContent(this);
3315
- c.segment.setUint8(c.byteOffset + index, value);
3316
- }
3317
- [Symbol.toStringTag]() {
3318
- return `Uint8_${super.toString()}`;
3319
- }
3320
- };
3321
- var Uint16List = class extends List {
3322
- static {
3323
- __name(this, "Uint16List");
3324
- }
3325
- static _capnp = {
3326
- displayName: "List<Uint16>",
3327
- size: ListElementSize.BYTE_2
3328
- };
3329
- get(index) {
3330
- const c = getContent(this);
3331
- return c.segment.getUint16(c.byteOffset + index * 2);
3332
- }
3333
- set(index, value) {
3334
- const c = getContent(this);
3335
- c.segment.setUint16(c.byteOffset + index * 2, value);
3336
- }
3337
- [Symbol.toStringTag]() {
3338
- return `Uint16_${super.toString()}`;
3339
- }
3340
- };
3341
- var Uint32List = class extends List {
3342
- static {
3343
- __name(this, "Uint32List");
3344
- }
3345
- static _capnp = {
3346
- displayName: "List<Uint32>",
3347
- size: ListElementSize.BYTE_4
3348
- };
3349
- get(index) {
3350
- const c = getContent(this);
3351
- return c.segment.getUint32(c.byteOffset + index * 4);
3352
- }
3353
- set(index, value) {
3354
- const c = getContent(this);
3355
- c.segment.setUint32(c.byteOffset + index * 4, value);
3356
- }
3357
- [Symbol.toStringTag]() {
3358
- return `Uint32_${super.toString()}`;
3359
- }
3360
- };
3361
- var Uint64List = class extends List {
3362
- static {
3363
- __name(this, "Uint64List");
3364
- }
3365
- static _capnp = {
3366
- displayName: "List<Uint64>",
3367
- size: ListElementSize.BYTE_8
3368
- };
3369
- get(index) {
3370
- const c = getContent(this);
3371
- return c.segment.getUint64(c.byteOffset + index * 8);
3372
- }
3373
- set(index, value) {
3374
- const c = getContent(this);
3375
- c.segment.setUint64(c.byteOffset + index * 8, value);
3376
- }
3377
- [Symbol.toStringTag]() {
3378
- return `Uint64_${super.toString()}`;
3379
- }
3380
- };
3381
- var VoidList = PointerList(Void);
3382
- function isSameClient(c, d) {
3383
- const norm = /* @__PURE__ */ __name((c2) => {
3384
- return c2;
3385
- }, "norm");
3386
- return norm(c) === norm(d);
3387
- }
3388
- __name(isSameClient, "isSameClient");
3389
- function clientFromResolution(transform, obj, err) {
3390
- if (err) {
3391
- return new ErrorClient(err);
3392
- }
3393
- if (!obj) {
3394
- return new ErrorClient(new Error(`null obj!`));
3395
- }
3396
- const out = transformPtr(obj, transform);
3397
- return getInterfaceClientOrNull(out);
3398
- }
3399
- __name(clientFromResolution, "clientFromResolution");
3400
- var IDGen = class {
3401
- static {
3402
- __name(this, "IDGen");
3403
- }
3404
- i = 0;
3405
- free = [];
3406
- next() {
3407
- return this.free.pop() ?? this.i++;
3408
- }
3409
- remove(i) {
3410
- this.free.push(i);
3411
- }
3412
- };
3413
- var Ref = class {
3414
- static {
3415
- __name(this, "Ref");
3416
- }
3417
- constructor(rc, finalize) {
3418
- this.rc = rc;
3419
- const closeState = { closed: false };
3420
- this.closeState = closeState;
3421
- finalize(this, () => {
3422
- if (!closeState.closed) {
3423
- closeState.closed = true;
3424
- rc.decref();
3425
- }
3426
- });
3427
- }
3428
- closeState;
3429
- call(cl) {
3430
- return this.rc.call(cl);
3431
- }
3432
- client() {
3433
- return this.rc._client;
3434
- }
3435
- close() {
3436
- if (!this.closeState.closed) {
3437
- this.closeState.closed = true;
3438
- this.rc.decref();
3439
- }
3440
- }
3441
- };
3442
- var RefCount = class _RefCount {
3443
- static {
3444
- __name(this, "RefCount");
3445
- }
3446
- refs;
3447
- finalize;
3448
- _client;
3449
- constructor(c, _finalize) {
3450
- this._client = c;
3451
- this.finalize = _finalize;
3452
- this.refs = 1;
3453
- }
3454
- // New creates a reference counter and the first client reference.
3455
- static new(c, finalize) {
3456
- const rc = new _RefCount(c, finalize);
3457
- const ref = rc.newRef();
3458
- return [rc, ref];
3459
- }
3460
- call(cl) {
3461
- return this._client.call(cl);
3462
- }
3463
- client() {
3464
- return this._client;
3465
- }
3466
- close() {
3467
- this._client.close();
3468
- }
3469
- ref() {
3470
- if (this.refs <= 0) {
3471
- return new ErrorClient(new Error(RPC_ZERO_REF));
3472
- }
3473
- this.refs++;
3474
- return this.newRef();
3475
- }
3476
- newRef() {
3477
- return new Ref(this, this.finalize);
3478
- }
3479
- decref() {
3480
- this.refs--;
3481
- if (this.refs === 0) {
3482
- this._client.close();
3483
- }
3484
- }
3485
- };
3486
- var RPCError = class extends Error {
3487
- static {
3488
- __name(this, "RPCError");
3489
- }
3490
- constructor(exception) {
3491
- super(format(RPC_ERROR, exception.reason));
3492
- this.exception = exception;
3493
- }
3494
- };
3495
- function toException(exc, err) {
3496
- if (err instanceof RPCError) {
3497
- exc.reason = err.exception.reason;
3498
- exc.type = err.exception.type;
3499
- return;
3500
- }
3501
- exc.reason = err.message;
3502
- exc.type = Exception.Type.FAILED;
3503
- }
3504
- __name(toException, "toException");
3505
- function newMessage() {
3506
- return new Message().initRoot(Message2);
3507
- }
3508
- __name(newMessage, "newMessage");
3509
- function newFinishMessage(questionID, release) {
3510
- const m = newMessage();
3511
- const f = m._initFinish();
3512
- f.questionId = questionID;
3513
- f.releaseResultCaps = release;
3514
- return m;
3515
- }
3516
- __name(newFinishMessage, "newFinishMessage");
3517
- function newUnimplementedMessage(m) {
3518
- const n = newMessage();
3519
- n.unimplemented = m;
3520
- return n;
3521
- }
3522
- __name(newUnimplementedMessage, "newUnimplementedMessage");
3523
- function newReturnMessage(id) {
3524
- const m = newMessage();
3525
- const ret = m._initReturn();
3526
- ret.answerId = id;
3527
- return m;
3528
- }
3529
- __name(newReturnMessage, "newReturnMessage");
3530
- function setReturnException(ret, err) {
3531
- const exc = ret._initException();
3532
- toException(exc, err);
3533
- return exc;
3534
- }
3535
- __name(setReturnException, "setReturnException");
3536
- function newDisembargoMessage(which, id) {
3537
- const m = newMessage();
3538
- const dis = m._initDisembargo();
3539
- const ctx = dis._initContext();
3540
- switch (which) {
3541
- case Disembargo_Context_Which.SENDER_LOOPBACK: {
3542
- ctx.senderLoopback = id;
3543
- break;
3544
- }
3545
- case Disembargo_Context_Which.RECEIVER_LOOPBACK: {
3546
- ctx.receiverLoopback = id;
3547
- break;
3548
- }
3549
- default: {
3550
- throw new Error(INVARIANT_UNREACHABLE_CODE);
3551
- }
3552
- }
3553
- return m;
3554
- }
3555
- __name(newDisembargoMessage, "newDisembargoMessage");
3556
- function transformToPromisedAnswer(answer, transform) {
3557
- const opList = answer._initTransform(transform.length);
3558
- for (const [i, op] of transform.entries()) {
3559
- opList.get(i).getPointerField = op.field;
3560
- }
3561
- }
3562
- __name(transformToPromisedAnswer, "transformToPromisedAnswer");
3563
- function promisedAnswerOpsToTransform(list) {
3564
- const transform = [];
3565
- for (const op of list) {
3566
- switch (op.which()) {
3567
- case PromisedAnswer_Op.GET_POINTER_FIELD: {
3568
- transform.push({
3569
- field: op.getPointerField
3570
- });
3571
- break;
3572
- }
3573
- case PromisedAnswer_Op.NOOP: {
3574
- break;
3575
- }
3576
- }
3577
- }
3578
- return transform;
3579
- }
3580
- __name(promisedAnswerOpsToTransform, "promisedAnswerOpsToTransform");
3581
- var QuestionState = /* @__PURE__ */ ((QuestionState2) => {
3582
- QuestionState2[QuestionState2["IN_PROGRESS"] = 0] = "IN_PROGRESS";
3583
- QuestionState2[QuestionState2["RESOLVED"] = 1] = "RESOLVED";
3584
- QuestionState2[QuestionState2["CANCELED"] = 2] = "CANCELED";
3585
- return QuestionState2;
3586
- })(QuestionState || {});
3587
- var Question = class {
3588
- static {
3589
- __name(this, "Question");
3590
- }
3591
- constructor(conn, id, method) {
3592
- this.conn = conn;
3593
- this.id = id;
3594
- this.method = method;
3595
- }
3596
- paramCaps = [];
3597
- state = 0;
3598
- obj;
3599
- err;
3600
- derived = [];
3601
- deferred = new Deferred();
3602
- async struct() {
3603
- return await this.deferred.promise;
3604
- }
3605
- // start signals the question has been sent
3606
- start() {
3607
- }
3608
- // fulfill is called to resolve a question successfully.
3609
- // The caller must be holding onto q.conn.mu.
3610
- fulfill(obj) {
3611
- if (this.state !== 0) {
3612
- throw new Error(RPC_FULFILL_ALREADY_CALLED);
3613
- }
3614
- if (this.method) {
3615
- this.obj = getAs(this.method.ResultsClass, obj);
3616
- } else {
3617
- this.obj = obj;
3618
- }
3619
- this.state = 1;
3620
- this.deferred.resolve(this.obj);
3621
- }
3622
- // reject is called to resolve a question with failure
3623
- reject(err) {
3624
- if (!err) {
3625
- throw new Error(`Question.reject called with null`);
3626
- }
3627
- if (this.state !== 0) {
3628
- throw new Error(`Question.reject called more than once`);
3629
- }
3630
- this.err = err;
3631
- this.state = 1;
3632
- this.deferred.reject(err);
3633
- }
3634
- // cancel is called to resolve a question with cancellation.
3635
- cancel(err) {
3636
- if (this.state === 0) {
3637
- this.err = err;
3638
- this.state = 2;
3639
- this.deferred.reject(err);
3640
- return true;
3641
- }
3642
- return false;
3643
- }
3644
- pipelineCall(transform, call) {
3645
- if (this.conn.findQuestion(this.id) !== this) {
3646
- if (this.state === 0) {
3647
- throw new Error(`question popped but not done`);
3648
- }
3649
- const client = clientFromResolution(transform, this.obj, this.err);
3650
- return client.call(call);
3651
- }
3652
- const pipeq = this.conn.newQuestion(call.method);
3653
- const msg = newMessage();
3654
- const msgCall = msg._initCall();
3655
- msgCall.questionId = pipeq.id;
3656
- msgCall.interfaceId = call.method.interfaceId;
3657
- msgCall.methodId = call.method.methodId;
3658
- const target = msgCall._initTarget();
3659
- const a = target._initPromisedAnswer();
3660
- a.questionId = this.id;
3661
- transformToPromisedAnswer(a, transform);
3662
- const payload = msgCall._initParams();
3663
- this.conn.fillParams(payload, call);
3664
- this.conn.sendMessage(msg);
3665
- this.addPromise(transform);
3666
- return pipeq;
3667
- }
3668
- addPromise(transform) {
3669
- for (const d of this.derived) {
3670
- if (transformsEqual(transform, d)) {
3671
- return;
3672
- }
3673
- }
3674
- this.derived.push(transform);
3675
- }
3676
- pipelineClose() {
3677
- throw new Error(NOT_IMPLEMENTED);
3678
- }
3679
- };
3680
- function transformsEqual(t, u) {
3681
- if (t.length !== u.length) {
3682
- return false;
3683
- }
3684
- for (const [i, element_] of t.entries()) {
3685
- if (element_.field !== u[i].field) {
3686
- return false;
3687
- }
3688
- }
3689
- return true;
3690
- }
3691
- __name(transformsEqual, "transformsEqual");
3692
- var Qcalls = class _Qcalls {
3693
- static {
3694
- __name(this, "Qcalls");
3695
- }
3696
- constructor(data) {
3697
- this.data = data;
3698
- }
3699
- static copyOf(data) {
3700
- return new _Qcalls([...data]);
3701
- }
3702
- len() {
3703
- return this.data.length;
3704
- }
3705
- clear(i) {
3706
- this.data[i] = null;
3707
- }
3708
- copy() {
3709
- return _Qcalls.copyOf(this.data);
3710
- }
3711
- };
3712
- function joinAnswer(fl, answer) {
3713
- answer.struct().then((obj) => {
3714
- fl.fulfill(obj);
3715
- }).catch((error_) => {
3716
- fl.reject(error_);
3717
- });
3718
- }
3719
- __name(joinAnswer, "joinAnswer");
3720
- var callQueueSize2 = 64;
3721
- var QueueClient = class {
3722
- static {
3723
- __name(this, "QueueClient");
3724
- }
3725
- constructor(conn, client, calls) {
3726
- this.conn = conn;
3727
- this._client = client;
3728
- this.calls = Qcalls.copyOf(calls);
3729
- this.q = new Queue(this.calls, callQueueSize2);
3730
- }
3731
- _client;
3732
- calls;
3733
- q;
3734
- pushCall(call) {
3735
- const f = new Fulfiller();
3736
- try {
3737
- call = copyCall(call);
3738
- } catch (error_) {
3739
- return new ErrorAnswer(error_);
3740
- }
3741
- const i = this.q.push();
3742
- if (i === -1) {
3743
- return new ErrorAnswer(new Error(RPC_CALL_QUEUE_FULL));
3744
- }
3745
- this.calls.data[i] = {
3746
- call,
3747
- f
3748
- };
3749
- return f;
3750
- }
3751
- pushEmbargo(id, tgt) {
3752
- const i = this.q.push();
3753
- if (i === -1) {
3754
- throw new Error(RPC_CALL_QUEUE_FULL);
3755
- }
3756
- this.calls.data[i] = {
3757
- embargoID: id,
3758
- embargoTarget: tgt
3759
- };
3760
- }
3761
- flushQueue() {
3762
- let c = null;
3763
- {
3764
- const i = this.q.front();
3765
- if (i !== -1) {
3766
- c = this.calls.data[i];
3767
- }
3768
- }
3769
- while (c) {
3770
- this.handle(c);
3771
- this.q.pop();
3772
- {
3773
- const i = this.q.front();
3774
- c = i === -1 ? null : this.calls.data[i];
3775
- }
3776
- }
3777
- }
3778
- handle(c) {
3779
- if (!c) {
3780
- return;
3781
- }
3782
- if (isRemoteCall(c)) {
3783
- const answer = this._client.call(c.call);
3784
- joinAnswer(c.a, answer);
3785
- } else if (isLocalCall(c)) {
3786
- const answer = this._client.call(c.call);
3787
- joinAnswer(c.f, answer);
3788
- } else if (isDisembargo(c)) {
3789
- const msg = newDisembargoMessage(
3790
- Disembargo_Context_Which.RECEIVER_LOOPBACK,
3791
- c.embargoID
3792
- );
3793
- msg.disembargo.target = c.embargoTarget;
3794
- this.conn.sendMessage(msg);
3795
- }
3796
- }
3797
- isPassthrough() {
3798
- return this.q.len() === 0;
3799
- }
3800
- call(call) {
3801
- if (this.isPassthrough()) {
3802
- return this._client.call(call);
3803
- }
3804
- return this.pushCall(call);
3805
- }
3806
- // close releases any resources associated with this client.
3807
- // No further calls to the client should be made after calling Close.
3808
- close() {
3809
- }
3810
- };
3811
- var AnswerEntry = class {
3812
- static {
3813
- __name(this, "AnswerEntry");
3814
- }
3815
- id;
3816
- conn;
3817
- resultCaps = [];
3818
- done = false;
3819
- obj;
3820
- err;
3821
- deferred = new Deferred();
3822
- queue = [];
3823
- constructor(conn, id) {
3824
- this.conn = conn;
3825
- this.id = id;
3826
- }
3827
- // fulfill is called to resolve an answer successfully.
3828
- fulfill(obj) {
3829
- if (this.done) {
3830
- throw new Error(`answer.fulfill called more than once`);
3831
- }
3832
- this.done = true;
3833
- this.obj = obj;
3834
- const retmsg = newReturnMessage(this.id);
3835
- const ret = retmsg.return;
3836
- const payload = ret._initResults();
3837
- payload.content = obj;
3838
- let firstErr;
3839
- try {
3840
- this.conn.makeCapTable(ret.segment, (len) => payload._initCapTable(len));
3841
- this.deferred.resolve(obj);
3842
- this.conn.sendMessage(retmsg);
3843
- } catch (error_) {
3844
- if (!firstErr) {
3845
- firstErr = error_;
3846
- }
3847
- }
3848
- const [queues, queuesErr] = this.emptyQueue(obj);
3849
- if (queuesErr && !firstErr) {
3850
- firstErr = queuesErr;
3851
- }
3852
- const objcap = obj.segment.message._capnp;
3853
- if (!objcap.capTable) {
3854
- objcap.capTable = [];
3855
- }
3856
- for (const capIdxStr of Object.keys(queues)) {
3857
- const capIdx = Number(capIdxStr);
3858
- const q = queues[capIdx];
3859
- if (objcap.capTable === null) throw new Error(INVARIANT_UNREACHABLE_CODE);
3860
- objcap.capTable[capIdx] = new QueueClient(
3861
- this.conn,
3862
- objcap.capTable[capIdx],
3863
- q
3864
- );
3865
- }
3866
- if (firstErr) {
3867
- throw firstErr;
3868
- }
3869
- }
3870
- // reject is called to resolve an answer with failure.
3871
- reject(err) {
3872
- if (!err) {
3873
- throw new Error(`answer.reject called with nil`);
3874
- }
3875
- if (this.done) {
3876
- throw new Error(`answer.reject claled more than once`);
3877
- }
3878
- const m = newReturnMessage(this.id);
3879
- const mret = m.return;
3880
- setReturnException(mret, err);
3881
- this.err = err;
3882
- this.done = true;
3883
- this.deferred.reject(err);
3884
- let firstErr;
3885
- try {
3886
- this.conn.sendMessage(m);
3887
- } catch (error_) {
3888
- firstErr = error_;
3889
- }
3890
- for (let i = 0; i < this.queue.length; i++) {
3891
- const qa = this.queue[i];
3892
- try {
3893
- if (qa.qcall && isRemoteCall(qa.qcall)) {
3894
- qa.qcall.a.reject(err);
3895
- }
3896
- } catch (error_) {
3897
- if (!firstErr) {
3898
- firstErr = error_;
3899
- }
3900
- }
3901
- }
3902
- this.queue = [];
3903
- if (firstErr) {
3904
- throw firstErr;
3905
- }
3906
- }
3907
- // emptyQueue splits the queue by which capability it targets
3908
- // and drops any invalid calls. Once this function returns,
3909
- // this.queue will be empty.
3910
- emptyQueue(obj) {
3911
- let firstErr;
3912
- const qs = {};
3913
- for (let i = 0; i < this.queue.length; i++) {
3914
- const pc = this.queue[i];
3915
- if (!isRemoteCall(pc.qcall)) {
3916
- continue;
3917
- }
3918
- if (!pc.qcall.a) {
3919
- continue;
3920
- }
3921
- let c;
3922
- try {
3923
- c = transformPtr(obj, pc.transform);
3924
- } catch (error_) {
3925
- try {
3926
- pc.qcall.a.reject(error_);
3927
- } catch (error_2) {
3928
- if (!firstErr) {
3929
- firstErr = error_2;
3930
- }
3931
- }
3932
- continue;
3933
- }
3934
- const ci = Interface.fromPointer(c);
3935
- if (!ci) {
3936
- try {
3937
- pc.qcall.a.reject(new Error(RPC_NULL_CLIENT));
3938
- } catch (error_) {
3939
- if (!firstErr) {
3940
- firstErr = error_;
3941
- }
3942
- }
3943
- continue;
3944
- }
3945
- const cn = ci.getCapId();
3946
- if (!qs[cn]) {
3947
- qs[cn] = [];
3948
- }
3949
- qs[cn].push(pc.qcall);
3950
- }
3951
- this.queue = [];
3952
- return [qs, firstErr];
3953
- }
3954
- queueCall(call, transform, a) {
3955
- if (this.queue.length >= callQueueSize2) {
3956
- throw new Error(RPC_CALL_QUEUE_FULL);
3957
- }
3958
- const qcall = {
3959
- a,
3960
- call: copyCall(call)
3961
- };
3962
- const pcall = {
3963
- qcall,
3964
- transform
3965
- };
3966
- this.queue.push(pcall);
3967
- }
3968
- };
3969
- function isRemoteCall(a) {
3970
- return !!a.a;
3971
- }
3972
- __name(isRemoteCall, "isRemoteCall");
3973
- function isLocalCall(a) {
3974
- return !!a.f;
3975
- }
3976
- __name(isLocalCall, "isLocalCall");
3977
- function isDisembargo(a) {
3978
- return !!a.embargoTarget;
3979
- }
3980
- __name(isDisembargo, "isDisembargo");
3981
- var ImportClient = class {
3982
- static {
3983
- __name(this, "ImportClient");
3984
- }
3985
- constructor(conn, id) {
3986
- this.conn = conn;
3987
- this.id = id;
3988
- }
3989
- closed = false;
3990
- call(cl) {
3991
- if (this.closed) {
3992
- return new ErrorAnswer(new Error(RPC_IMPORT_CLOSED));
3993
- }
3994
- const q = this.conn.newQuestion(cl.method);
3995
- const msg = newMessage();
3996
- const msgCall = msg._initCall();
3997
- msgCall.questionId = q.id;
3998
- msgCall.interfaceId = cl.method.interfaceId;
3999
- msgCall.methodId = cl.method.methodId;
4000
- const target = msgCall._initTarget();
4001
- target.importedCap = this.id;
4002
- const payload = msgCall._initParams();
4003
- this.conn.fillParams(payload, cl);
4004
- this.conn.sendMessage(msg);
4005
- return q;
4006
- }
4007
- close() {
4008
- }
4009
- };
4010
- var LocalAnswerClient = class {
4011
- static {
4012
- __name(this, "LocalAnswerClient");
4013
- }
4014
- constructor(a, transform) {
4015
- this.a = a;
4016
- this.transform = transform;
4017
- }
4018
- call(call) {
4019
- if (this.a.done) {
4020
- return clientFromResolution(this.transform, this.a.obj, this.a.err).call(
4021
- call
4022
- );
4023
- }
4024
- return new Fulfiller();
4025
- }
4026
- close() {
4027
- throw new Error(NOT_IMPLEMENTED);
4028
- }
4029
- };
4030
- var ConnWeakRefRegistry = globalThis.FinalizationRegistry ? new FinalizationRegistry((cb) => cb()) : void 0;
4031
- var ConDefaultFinalize = /* @__PURE__ */ __name((obj, finalizer) => {
4032
- ConnWeakRefRegistry?.register(obj, finalizer);
4033
- }, "ConDefaultFinalize");
4034
- var Conn = class {
4035
- static {
4036
- __name(this, "Conn");
4037
- }
4038
- /**
4039
- * Create a new connection
4040
- * @param transport The transport used to receive/send messages.
4041
- * @param finalize Weak reference implementation. Compatible with
4042
- * the 'weak' module on node.js (just add weak as a dependency and pass
4043
- * require("weak")), but alternative implementations can be provided for
4044
- * other platforms like Electron. Defaults to using FinalizationRegistry if
4045
- * available.
4046
- * @returns A new connection.
4047
- */
4048
- constructor(transport, finalize = ConDefaultFinalize) {
4049
- this.transport = transport;
4050
- this.finalize = finalize;
4051
- this.startWork();
4052
- }
4053
- questionID = new IDGen();
4054
- questions = [];
4055
- answers = {};
4056
- exportID = new IDGen();
4057
- exports = [];
4058
- imports = {};
4059
- onError;
4060
- main;
4061
- working = false;
4062
- bootstrap(InterfaceClass) {
4063
- const q = this.newQuestion();
4064
- const msg = newMessage();
4065
- const boot = msg._initBootstrap();
4066
- boot.questionId = q.id;
4067
- this.sendMessage(msg);
4068
- return new InterfaceClass.Client(new Pipeline(AnyStruct, q).client());
4069
- }
4070
- initMain(InterfaceClass, target) {
4071
- this.main = new InterfaceClass.Server(target);
4072
- this.addExport(this.main);
4073
- }
4074
- startWork() {
4075
- this.work().catch((error_) => {
4076
- if (this.onError) {
4077
- this.onError(error_);
4078
- } else if (error_ !== void 0) {
4079
- throw error_;
4080
- }
4081
- });
4082
- }
4083
- sendReturnException(id, err) {
4084
- const m = newReturnMessage(id);
4085
- setReturnException(m.return, err);
4086
- this.sendMessage(m);
4087
- }
4088
- handleBootstrapMessage(m) {
4089
- const boot = m.bootstrap;
4090
- const id = boot.questionId;
4091
- const ret = newReturnMessage(id);
4092
- ret.return.releaseParamCaps = false;
4093
- const a = this.insertAnswer(id);
4094
- if (a === null) {
4095
- return this.sendReturnException(id, new Error(RPC_QUESTION_ID_REUSED));
4096
- }
4097
- if (this.main === void 0) {
4098
- return a.reject(new Error(RPC_NO_MAIN_INTERFACE));
4099
- }
4100
- const msg = new Message();
4101
- msg.addCap(this.main);
4102
- a.fulfill(new Interface(msg.getSegment(0), 0));
4103
- }
4104
- handleFinishMessage(m) {
4105
- const { finish } = m;
4106
- const id = finish.questionId;
4107
- const a = this.popAnswer(id);
4108
- if (a === null) {
4109
- throw new Error(format(RPC_FINISH_UNKNOWN_ANSWER, id));
4110
- }
4111
- if (finish.releaseResultCaps) {
4112
- const caps = a.resultCaps;
4113
- let i = caps.length;
4114
- while (--i >= 0) {
4115
- this.releaseExport(i, 1);
4116
- }
4117
- }
4118
- }
4119
- handleMessage(m) {
4120
- switch (m.which()) {
4121
- case Message2.UNIMPLEMENTED: {
4122
- break;
4123
- }
4124
- case Message2.BOOTSTRAP: {
4125
- this.handleBootstrapMessage(m);
4126
- break;
4127
- }
4128
- case Message2.ABORT: {
4129
- this.shutdown(new RPCError(m.abort));
4130
- break;
4131
- }
4132
- case Message2.FINISH: {
4133
- this.handleFinishMessage(m);
4134
- break;
4135
- }
4136
- case Message2.RETURN: {
4137
- this.handleReturnMessage(m);
4138
- break;
4139
- }
4140
- case Message2.CALL: {
4141
- this.handleCallMessage(m);
4142
- break;
4143
- }
4144
- }
4145
- }
4146
- handleReturnMessage(m) {
4147
- const ret = m.return;
4148
- const id = ret.answerId;
4149
- const q = this.popQuestion(id);
4150
- if (!q) {
4151
- throw new Error(format(RPC_RETURN_FOR_UNKNOWN_QUESTION, id));
4152
- }
4153
- if (ret.releaseParamCaps) {
4154
- for (let i = 0; i < q.paramCaps.length; i++) {
4155
- this.releaseExport(id, 1);
4156
- }
4157
- }
4158
- let releaseResultCaps = true;
4159
- switch (ret.which()) {
4160
- case Return.RESULTS: {
4161
- releaseResultCaps = false;
4162
- const { results } = ret;
4163
- this.populateMessageCapTable(results);
4164
- const { content } = results;
4165
- q.fulfill(content);
4166
- break;
4167
- }
4168
- case Return.EXCEPTION: {
4169
- const exc = ret.exception;
4170
- const err = q.method ? new MethodError(q.method, exc.reason) : new RPCError(exc);
4171
- q.reject(err);
4172
- break;
4173
- }
4174
- }
4175
- const fin = newFinishMessage(id, releaseResultCaps);
4176
- this.sendMessage(fin);
4177
- }
4178
- handleCallMessage(m) {
4179
- const mcall = m.call;
4180
- const mt = mcall.target;
4181
- if (mt.which() !== MessageTarget.IMPORTED_CAP && mt.which() !== MessageTarget.PROMISED_ANSWER) {
4182
- const um = newUnimplementedMessage(m);
4183
- this.sendMessage(um);
4184
- return;
4185
- }
4186
- const mparams = mcall.params;
4187
- try {
4188
- this.populateMessageCapTable(mparams);
4189
- } catch {
4190
- const um = newUnimplementedMessage(m);
4191
- this.sendMessage(um);
4192
- return;
4193
- }
4194
- const id = mcall.questionId;
4195
- const a = this.insertAnswer(id);
4196
- if (!a) {
4197
- throw new Error(format(RPC_QUESTION_ID_REUSED, id));
4198
- }
4199
- const interfaceDef = Registry.lookup(mcall.interfaceId);
4200
- if (!interfaceDef) {
4201
- const um = newUnimplementedMessage(m);
4202
- this.sendMessage(um);
4203
- return;
4204
- }
4205
- const method = interfaceDef.methods[mcall.methodId];
4206
- if (!method) {
4207
- const um = newUnimplementedMessage(m);
4208
- this.sendMessage(um);
4209
- return;
4210
- }
4211
- const paramContent = mparams.content;
4212
- const call = {
4213
- method,
4214
- params: getAs(method.ParamsClass, paramContent)
4215
- };
4216
- try {
4217
- this.routeCallMessage(a, mt, call);
4218
- } catch (error_) {
4219
- a.reject(error_);
4220
- }
4221
- }
4222
- routeCallMessage(result, mt, cl) {
4223
- switch (mt.which()) {
4224
- case MessageTarget.IMPORTED_CAP: {
4225
- const id = mt.importedCap;
4226
- const e = this.findExport(id);
4227
- if (!e) {
4228
- throw new Error(RPC_BAD_TARGET);
4229
- }
4230
- const answer = this.call(e.client, cl);
4231
- joinAnswer(result, answer);
4232
- break;
4233
- }
4234
- case MessageTarget.PROMISED_ANSWER: {
4235
- const mpromise = mt.promisedAnswer;
4236
- const id = mpromise.questionId;
4237
- if (id === result.id) {
4238
- throw new Error(RPC_BAD_TARGET);
4239
- }
4240
- const pa = this.answers[id];
4241
- if (!pa) {
4242
- throw new Error(RPC_BAD_TARGET);
4243
- }
4244
- const mtrans = mpromise.transform;
4245
- const transform = promisedAnswerOpsToTransform(mtrans);
4246
- if (pa.done) {
4247
- const { obj, err } = pa;
4248
- const client = clientFromResolution(transform, obj, err);
4249
- const answer = this.call(client, cl);
4250
- joinAnswer(result, answer);
4251
- } else {
4252
- pa.queueCall(cl, transform, result);
4253
- }
4254
- break;
4255
- }
4256
- default: {
4257
- throw new Error(INVARIANT_UNREACHABLE_CODE);
4258
- }
4259
- }
4260
- }
4261
- populateMessageCapTable(payload) {
4262
- const msg = payload.segment.message;
4263
- const ctab = payload.capTable;
4264
- for (const desc of ctab) {
4265
- switch (desc.which()) {
4266
- case CapDescriptor.NONE: {
4267
- msg.addCap(null);
4268
- break;
4269
- }
4270
- case CapDescriptor.SENDER_HOSTED: {
4271
- const id = desc.senderHosted;
4272
- const client = this.addImport(id);
4273
- msg.addCap(client);
4274
- break;
4275
- }
4276
- case CapDescriptor.SENDER_PROMISE: {
4277
- const id = desc.senderPromise;
4278
- const client = this.addImport(id);
4279
- msg.addCap(client);
4280
- break;
4281
- }
4282
- case CapDescriptor.RECEIVER_HOSTED: {
4283
- const id = desc.receiverHosted;
4284
- const e = this.findExport(id);
4285
- if (!e) {
4286
- throw new Error(format(RPC_UNKNOWN_EXPORT_ID, id));
4287
- }
4288
- msg.addCap(e.rc.ref());
4289
- break;
4290
- }
4291
- case CapDescriptor.RECEIVER_ANSWER: {
4292
- const recvAns = desc.receiverAnswer;
4293
- const id = recvAns.questionId;
4294
- const a = this.answers[id];
4295
- if (!a) {
4296
- throw new Error(format(RPC_UNKNOWN_ANSWER_ID, id));
4297
- }
4298
- const recvTransform = recvAns.transform;
4299
- const transform = promisedAnswerOpsToTransform(recvTransform);
4300
- msg.addCap(answerPipelineClient(a, transform));
4301
- break;
4302
- }
4303
- default: {
4304
- throw new Error(format(RPC_UNKNOWN_CAP_DESCRIPTOR, desc.which()));
4305
- }
4306
- }
4307
- }
4308
- }
4309
- addImport(id) {
4310
- const importEntry = this.imports[id];
4311
- if (importEntry) {
4312
- importEntry.refs++;
4313
- return importEntry.rc.ref();
4314
- }
4315
- const client = new ImportClient(this, id);
4316
- const [rc, ref] = RefCount.new(client, this.finalize);
4317
- this.imports[id] = {
4318
- rc,
4319
- refs: 1
4320
- };
4321
- return ref;
4322
- }
4323
- findExport(id) {
4324
- if (id > this.exports.length) {
4325
- return null;
4326
- }
4327
- return this.exports[id];
4328
- }
4329
- addExport(client) {
4330
- for (let i = 0; i < this.exports.length; i++) {
4331
- const e = this.exports[i];
4332
- if (e && isSameClient(e.rc._client, client)) {
4333
- e.wireRefs++;
4334
- return i;
4335
- }
4336
- }
4337
- const id = this.exportID.next();
4338
- const [rc, ref] = RefCount.new(client, this.finalize);
4339
- const _export = {
4340
- client: ref,
4341
- id,
4342
- rc,
4343
- wireRefs: 1
4344
- };
4345
- if (id === this.exports.length) {
4346
- this.exports.push(_export);
4347
- } else {
4348
- this.exports[id] = _export;
4349
- }
4350
- return id;
4351
- }
4352
- releaseExport(id, refs) {
4353
- const e = this.findExport(id);
4354
- if (!e) {
4355
- return;
4356
- }
4357
- e.wireRefs -= refs;
4358
- if (e.wireRefs > 0) {
4359
- return;
4360
- }
4361
- if (e.wireRefs < 0) {
4362
- this.error(`warning: export ${id} has negative refcount (${e.wireRefs})`);
4363
- }
4364
- e.client.close();
4365
- this.exports[id] = null;
4366
- this.exportID.remove(id);
4367
- }
4368
- error(s) {
4369
- console.error(s);
4370
- }
4371
- newQuestion(method) {
4372
- const id = this.questionID.next();
4373
- const q = new Question(this, id, method);
4374
- if (id === this.questions.length) {
4375
- this.questions.push(q);
4376
- } else {
4377
- this.questions[id] = q;
4378
- }
4379
- return q;
4380
- }
4381
- findQuestion(id) {
4382
- if (id > this.questions.length) {
4383
- return null;
4384
- }
4385
- return this.questions[id];
4386
- }
4387
- popQuestion(id) {
4388
- const q = this.findQuestion(id);
4389
- if (!q) {
4390
- return q;
4391
- }
4392
- this.questions[id] = null;
4393
- this.questionID.remove(id);
4394
- return q;
4395
- }
4396
- // TODO: cancel context?
4397
- insertAnswer(id) {
4398
- if (this.answers[id]) {
4399
- return null;
4400
- }
4401
- const a = new AnswerEntry(this, id);
4402
- this.answers[id] = a;
4403
- return a;
4404
- }
4405
- popAnswer(id) {
4406
- const a = this.answers[id];
4407
- delete this.answers[id];
4408
- return a;
4409
- }
4410
- shutdown(_err) {
4411
- this.transport.close();
4412
- }
4413
- call(client, call) {
4414
- return client.call(call);
4415
- }
4416
- fillParams(payload, cl) {
4417
- const params = placeParams(cl, payload.content);
4418
- payload.content = params;
4419
- this.makeCapTable(
4420
- payload.segment,
4421
- (length) => payload._initCapTable(length)
4422
- );
4423
- }
4424
- makeCapTable(s, init) {
4425
- const msgtab = s.message._capnp.capTable;
4426
- if (!msgtab) {
4427
- return;
4428
- }
4429
- const t = init(msgtab.length);
4430
- for (const [i, client] of msgtab.entries()) {
4431
- const desc = t.get(i);
4432
- if (!client) {
4433
- desc.none = true;
4434
- continue;
4435
- }
4436
- this.descriptorForClient(desc, client);
4437
- }
4438
- }
4439
- // descriptorForClient fills desc for client, adding it to the export
4440
- // table if necessary. The caller must be holding onto c.mu.
4441
- descriptorForClient(desc, _client) {
4442
- {
4443
- dig: for (let client = _client; ; ) {
4444
- if (client instanceof ImportClient) {
4445
- if (client.conn !== this) {
4446
- break dig;
4447
- }
4448
- desc.receiverHosted = client.id;
4449
- return;
4450
- } else if (client instanceof Ref) {
4451
- client = client.client();
4452
- } else if (client instanceof PipelineClient) {
4453
- const p = client.pipeline;
4454
- const ans = p.answer;
4455
- const transform = p.transform();
4456
- if (ans instanceof FixedAnswer) {
4457
- let s;
4458
- let err;
4459
- try {
4460
- s = ans.structSync();
4461
- } catch (error_) {
4462
- err = error_;
4463
- }
4464
- client = clientFromResolution(transform, s, err);
4465
- } else if (ans instanceof Question) {
4466
- if (ans.state !== QuestionState.IN_PROGRESS) {
4467
- client = clientFromResolution(transform, ans.obj, ans.err);
4468
- continue;
4469
- }
4470
- if (ans.conn !== this) {
4471
- break dig;
4472
- }
4473
- const a = desc._initReceiverAnswer();
4474
- a.questionId = ans.id;
4475
- transformToPromisedAnswer(a, p.transform());
4476
- return;
4477
- } else {
4478
- break dig;
4479
- }
4480
- } else {
4481
- break dig;
4482
- }
4483
- }
4484
- }
4485
- const id = this.addExport(_client);
4486
- desc.senderHosted = id;
4487
- }
4488
- sendMessage(msg) {
4489
- this.transport.sendMessage(msg);
4490
- }
4491
- async work() {
4492
- this.working = true;
4493
- while (this.working) {
4494
- try {
4495
- const m = await this.transport.recvMessage();
4496
- this.handleMessage(m);
4497
- } catch (error_) {
4498
- if (error_ !== void 0) {
4499
- throw error_;
4500
- }
4501
- this.working = false;
4502
- }
4503
- }
4504
- }
4505
- };
4506
- function answerPipelineClient(a, transform) {
4507
- return new LocalAnswerClient(a, transform);
4508
- }
4509
- __name(answerPipelineClient, "answerPipelineClient");
4510
- var DeferredTransport = class {
4511
- static {
4512
- __name(this, "DeferredTransport");
4513
- }
4514
- d;
4515
- closed = false;
4516
- close() {
4517
- this.closed = true;
4518
- this.d?.reject();
4519
- }
4520
- recvMessage() {
4521
- if (this.closed) {
4522
- return Promise.reject();
4523
- }
4524
- if (this.d) {
4525
- this.d.reject();
4526
- }
4527
- this.d = new Deferred();
4528
- return this.d.promise;
4529
- }
4530
- reject = /* @__PURE__ */ __name((err) => {
4531
- this.d?.reject(err);
4532
- }, "reject");
4533
- resolve = /* @__PURE__ */ __name((buf) => {
4534
- try {
4535
- this.d?.resolve(new Message(buf, false).getRoot(Message2));
4536
- } catch (error_) {
4537
- this.d?.reject(error_);
4538
- }
4539
- }, "resolve");
4540
- };
8
+ __name
9
+ } from "./chunk-UHN7QD4F.js";
4541
10
 
4542
11
  // src/rpc.ts
4543
12
  import { MessageChannel } from "node:worker_threads";