@stryke/capnp 0.12.57 → 0.12.59

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