@northtalk/ts 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. package/README.md +9 -5
  2. package/{encoding-DWlbPq-e.js → base64-DORMd3Hv.js} +197 -1368
  3. package/binary-value-CEmh60GC.d.ts +15 -0
  4. package/capabilities-CH0FkRMq.js +1301 -0
  5. package/checker-Dc1jl2WH.js +6657 -0
  6. package/core-DptnvQT9.d.ts +14 -0
  7. package/{debug-D8Z_u244.d.ts → debug-CQBxKnJB.d.ts} +1147 -780
  8. package/debug.d.ts +2 -1
  9. package/debug.js +2 -1
  10. package/driver.d.ts +16 -2
  11. package/driver.js +98 -20
  12. package/encoding-nlrpj-Pb.js +99 -0
  13. package/{engine-CgCMdGGd.js → engine-BGaJ9dAk.js} +7 -5
  14. package/{engine-BPFnHT9N.d.ts → engine-vbYInVYF.d.ts} +3 -3
  15. package/{errors-DHwz1Vho.js → errors-LYJZ_c8h.js} +91 -17
  16. package/{group-B4eyJKTA.js → group-B742gg4T.js} +1490 -7278
  17. package/{sqlite-capability-CrCej3Po.js → http-capability-CSTkw1Yt.js} +255 -5
  18. package/http.d.ts +59 -0
  19. package/http.js +465 -0
  20. package/index.d.ts +23 -17
  21. package/index.js +19 -12
  22. package/manifest-BscyH_rW.d.ts +70 -0
  23. package/{manifest-DKe2Je6Z.js → manifest-DjsxDSuB.js} +11 -90
  24. package/message-layer.d.ts +12 -0
  25. package/message-layer.js +4 -0
  26. package/notify.d.ts +2 -1
  27. package/notify.js +2 -1
  28. package/{objects-MeXIDDFo.d.ts → objects-DJ3QtCCs.d.ts} +23 -8
  29. package/objects-Db7IB5vQ.js +91 -0
  30. package/operation-promises-EgZXG5N_.js +23 -0
  31. package/package.json +9 -1
  32. package/readers-BFPuosPk.d.ts +25 -0
  33. package/{readers-DyjxJEkL.js → readers-CjJHKHvH.js} +6 -3
  34. package/request-pump-binary-DdY3X-yl.js +2246 -0
  35. package/{router-DHPJNvbt.js → router--71qvxtY.js} +8 -6
  36. package/{router-DpDpAJjz.d.ts → router-Zhrw5l__.d.ts} +6 -5
  37. package/session.d.ts +2 -1
  38. package/session.js +58 -24
  39. package/setup.d.ts +2 -1
  40. package/setup.js +8 -4
  41. package/{sha256-0jiTgVJu.js → sha256-B_kyYw3Z.js} +1 -0
  42. package/sqlite.d.ts +3 -4
  43. package/sqlite.js +6 -5
  44. package/{store-capability-CDoVafZL.js → store-capability-OZp4hXmj.js} +10 -7
  45. package/{store-DrYjcoru.js → store-hJrRULMx.js} +3 -2
  46. package/store.d.ts +3 -2
  47. package/store.js +3 -2
  48. package/{user-capability-Cv0oJhhv.js → user-capability-BK4Asg7D.js} +8 -5
  49. package/wasm.d.ts +42 -22
  50. package/wasm.js +330 -46
  51. package/core-eU5KaYkz.d.ts +0 -23
  52. package/readers-Oh4tO2dK.d.ts +0 -57
  53. package/sqlite-capability-C7-SYdD7.d.ts +0 -87
  54. package/user-capability-CLkDsrCX.d.ts +0 -40
@@ -0,0 +1,2246 @@
1
+
2
+ import { B as range, F as num, I as objectValue, K as text, L as patternValue, M as map, P as nothing, Qt as parseInstant, R as quantity, _ as dec, d as bytes, ht as normalizeNFC, k as listValues, l as Value, m as civilDate, o as invalidValue, qt as formatInstant, u as bool, w as instant, x as functionValue } from "./errors-LYJZ_c8h.js";
3
+ import { _ as viewSource, t as checkSource } from "./checker-Dc1jl2WH.js";
4
+ import { n as toBase64, rt as patternSource, v as decodeUtf8 } from "./base64-DORMd3Hv.js";
5
+ import { a as fromJson, n as JsonObject, o as isJsonNumber, s as isJsonObject, t as JsonNumber } from "./readers-CjJHKHvH.js";
6
+ //#region src/binary-value.ts
7
+ const coreErrors = /* @__PURE__ */ new WeakSet();
8
+ const max = 2n ** 64n;
9
+ const encoder = new TextEncoder();
10
+ const binaryFailure = () => invalidValue("Malformed canonical binary item");
11
+ const children = (item) => {
12
+ if (!Array.isArray(item.data)) return binaryFailure();
13
+ return item.data;
14
+ };
15
+ const itemText = (item) => {
16
+ if (item.tag !== 5 && item.tag !== 18 || typeof item.data !== "string") return binaryFailure();
17
+ return item.data;
18
+ };
19
+ const integerItem = (n) => {
20
+ if (n < -max || n >= max) return binaryFailure();
21
+ return {
22
+ tag: n < 0n ? 16 : 3,
23
+ data: n < 0n ? -n : n
24
+ };
25
+ };
26
+ const itemInteger = (item) => {
27
+ if (item.tag !== 3 && item.tag !== 16 || typeof item.data !== "bigint") return binaryFailure();
28
+ return item.tag === 16 ? -item.data : item.data;
29
+ };
30
+ const numberItem = (s) => {
31
+ if (dec(s).toString() !== s) return binaryFailure();
32
+ if (!s.includes(".")) {
33
+ const n = BigInt(s);
34
+ if (n >= -max && n < max) return integerItem(n);
35
+ }
36
+ return {
37
+ tag: 4,
38
+ data: s
39
+ };
40
+ };
41
+ /** A writer shared by standalone Values and positional Message Layer records. */
42
+ var BinaryWriter = class {
43
+ output = [];
44
+ uint(n) {
45
+ if (n < 0n || n > max) binaryFailure();
46
+ do {
47
+ const part = Number(n & 127n);
48
+ n >>= 7n;
49
+ this.output.push(part | (n ? 128 : 0));
50
+ } while (n);
51
+ }
52
+ item(root) {
53
+ const stack = [root];
54
+ while (stack.length) {
55
+ const item = stack.pop();
56
+ const { tag, data } = item;
57
+ this.output.push(tag);
58
+ if (tag === 0 || tag === 1 || tag === 2) continue;
59
+ if (tag === 3 || tag === 11 || tag === 16) this.uint(data);
60
+ else if ([
61
+ 4,
62
+ 5,
63
+ 8,
64
+ 12,
65
+ 13,
66
+ 18
67
+ ].includes(tag)) {
68
+ const b = typeof data === "string" ? encoder.encode(data) : data;
69
+ this.uint(BigInt(b.length));
70
+ for (const byte of b) this.output.push(byte);
71
+ } else {
72
+ const xs = children(item);
73
+ if ([
74
+ 6,
75
+ 7,
76
+ 17,
77
+ 19
78
+ ].includes(tag)) this.uint(BigInt(tag === 7 || tag === 17 ? xs.length / 2 : xs.length));
79
+ for (let i = xs.length - 1; i >= 0; i--) stack.push(xs[i]);
80
+ }
81
+ }
82
+ }
83
+ buffer() {
84
+ return Uint8Array.from(this.output).buffer;
85
+ }
86
+ };
87
+ /** Bounded by remaining bytes; containers use heap tasks, including deep Values. */
88
+ var BinaryReader = class {
89
+ data;
90
+ at = 0;
91
+ constructor(data) {
92
+ this.data = data;
93
+ }
94
+ byte() {
95
+ if (this.at >= this.data.length) return binaryFailure();
96
+ return this.data[this.at++];
97
+ }
98
+ uint(negative = false) {
99
+ let n = 0n;
100
+ for (let shift = 0n; shift < 70n; shift += 7n) {
101
+ const b = this.byte();
102
+ n |= BigInt(b & 127) << shift;
103
+ if (b < 128) {
104
+ if (shift && b === 0 || n >= max && !(negative && n === max)) return binaryFailure();
105
+ return n;
106
+ }
107
+ }
108
+ return binaryFailure();
109
+ }
110
+ count() {
111
+ const n = this.uint();
112
+ if (n > BigInt(this.data.length - this.at)) return binaryFailure();
113
+ return Number(n);
114
+ }
115
+ item() {
116
+ let root;
117
+ const tasks = [(v) => {
118
+ root = v;
119
+ }];
120
+ while (tasks.length) {
121
+ const assign = tasks.pop();
122
+ const tag = this.byte();
123
+ const item = { tag };
124
+ assign(item);
125
+ if (tag <= 2) continue;
126
+ if (tag === 3 || tag === 11 || tag === 16) {
127
+ item.data = this.uint(tag === 16);
128
+ if (tag === 16 && item.data === 0n) binaryFailure();
129
+ } else if ([
130
+ 4,
131
+ 5,
132
+ 8,
133
+ 12,
134
+ 13,
135
+ 18
136
+ ].includes(tag)) {
137
+ const n = this.count();
138
+ const data = this.data.subarray(this.at, this.at + n);
139
+ this.at += n;
140
+ if (tag === 8) item.data = data.slice();
141
+ else {
142
+ const s = decodeUtf8(data) ?? binaryFailure();
143
+ if (tag !== 18 && normalizeNFC(s) !== s) binaryFailure();
144
+ item.data = s;
145
+ if (tag === 4 && numberItem(s).tag !== 4) binaryFailure();
146
+ }
147
+ } else {
148
+ let n;
149
+ if ([
150
+ 6,
151
+ 7,
152
+ 17,
153
+ 19
154
+ ].includes(tag)) {
155
+ n = this.count();
156
+ if (tag === 19 && n !== 6 && n !== 7) binaryFailure();
157
+ if (tag === 7 || tag === 17) n *= 2;
158
+ } else if (tag === 9 || tag === 10 || tag === 14) n = 2;
159
+ else if (tag === 15) n = 3;
160
+ else return binaryFailure();
161
+ if (n > this.data.length - this.at) binaryFailure();
162
+ const xs = new Array(n);
163
+ item.data = xs;
164
+ for (let i = n - 1; i >= 0; i--) tasks.push((v) => {
165
+ xs[i] = v;
166
+ });
167
+ }
168
+ }
169
+ return root;
170
+ }
171
+ done() {
172
+ if (this.at !== this.data.length) binaryFailure();
173
+ }
174
+ };
175
+ const functionValid = (xs, o) => {
176
+ if (![
177
+ 3,
178
+ 6,
179
+ 7
180
+ ].includes(xs.length) || xs.length > 3 && !o.functionMetadata || xs.slice(0, 3).some((v) => v.kind !== "text")) binaryFailure();
181
+ if (xs.length >= 6) {
182
+ if (xs[3].kind !== "nothing" && xs[3].kind !== "text") binaryFailure();
183
+ const ns = xs.slice(4, 6).map((v) => v.kind === "number" && /^\d+$/.test(v.toString()) ? BigInt(v.toString()) : -1n);
184
+ if (ns[0] < 0n || ns[0] > ns[1] || ns[1] >= max) binaryFailure();
185
+ }
186
+ if (xs.length === 7 && (xs[6].kind !== "bytes" || xs[6].bytesView().length !== 32)) binaryFailure();
187
+ };
188
+ const valueItem = (value, o = {}) => {
189
+ let root;
190
+ const tasks = [];
191
+ const visit = (v, assign) => tasks.push(() => {
192
+ let item;
193
+ let xs;
194
+ switch (v.kind) {
195
+ case "nothing":
196
+ item = { tag: 0 };
197
+ break;
198
+ case "boolean":
199
+ item = { tag: v.asBool() ? 2 : 1 };
200
+ break;
201
+ case "number":
202
+ item = numberItem(v.toString());
203
+ break;
204
+ case "text":
205
+ item = {
206
+ tag: 5,
207
+ data: v.asText()
208
+ };
209
+ break;
210
+ case "bytes":
211
+ item = {
212
+ tag: 8,
213
+ data: v.bytesView()
214
+ };
215
+ break;
216
+ case "instant": {
217
+ const n = v.asInstant();
218
+ item = {
219
+ tag: 11,
220
+ data: n << 1n ^ n >> 63n
221
+ };
222
+ break;
223
+ }
224
+ case "civil date":
225
+ item = {
226
+ tag: 12,
227
+ data: v.toString()
228
+ };
229
+ break;
230
+ case "pattern":
231
+ item = {
232
+ tag: 13,
233
+ data: v.patternSource()
234
+ };
235
+ break;
236
+ case "list":
237
+ item = { tag: 6 };
238
+ xs = Array.from({ length: v.length }, (_, i) => v.index(i + 1));
239
+ break;
240
+ case "map":
241
+ item = { tag: coreErrors.has(v) && o.coreErrors ? 17 : 7 };
242
+ xs = v.entries().flatMap(([k, v]) => [text(k), v]);
243
+ break;
244
+ case "range": {
245
+ const r = v.asRange();
246
+ item = { tag: 10 };
247
+ xs = [r.from, r.to];
248
+ break;
249
+ }
250
+ case "quantity": {
251
+ const q = v.asQuantity();
252
+ item = { tag: 9 };
253
+ xs = [dec(q.number.toString()), text(q.unit)];
254
+ break;
255
+ }
256
+ case "object": {
257
+ const ref = v.asObjectRef();
258
+ item = { tag: 14 };
259
+ xs = [text(ref.kind), text(ref.id)];
260
+ break;
261
+ }
262
+ case "function":
263
+ xs = o.encodeFunction?.(v);
264
+ if (!xs) return binaryFailure();
265
+ functionValid(xs, o);
266
+ item = { tag: xs.length === 3 ? 15 : 19 };
267
+ break;
268
+ default: return binaryFailure();
269
+ }
270
+ assign(item);
271
+ if (xs) {
272
+ const items = new Array(xs.length);
273
+ item.data = items;
274
+ for (let i = xs.length - 1; i >= 0; i--) visit(xs[i], (v) => {
275
+ items[i] = v;
276
+ });
277
+ }
278
+ });
279
+ visit(value, (v) => {
280
+ root = v;
281
+ });
282
+ while (tasks.length) tasks.pop()();
283
+ return root;
284
+ };
285
+ const itemValue = (root, o = {}) => {
286
+ let result;
287
+ const tasks = [];
288
+ const visit = (item, assign) => tasks.push(() => {
289
+ const { tag, data } = item;
290
+ if (tag === 0) return assign(nothing);
291
+ if (tag === 1 || tag === 2) return assign(bool(tag === 2));
292
+ if (tag === 3 || tag === 16) return assign(num(itemInteger(item)));
293
+ if (tag === 4) return assign(dec(data));
294
+ if (tag === 5) return assign(text(data));
295
+ if (tag === 8) return assign(bytes(data));
296
+ if (tag === 11) {
297
+ const n = data;
298
+ return assign(instant(n >> 1n ^ -(n & 1n)));
299
+ }
300
+ if (tag === 12) {
301
+ const v = civilDate(data);
302
+ if (v.toString() !== data) binaryFailure();
303
+ return assign(v);
304
+ }
305
+ if (tag === 13) {
306
+ const source = data;
307
+ const checked = checkSource(`constant binary = ${source}`);
308
+ if (!checked.ok || !checked.tree) return binaryFailure();
309
+ const decl = viewSource(checked.tree.root)[0];
310
+ if (decl?.k !== "constant" || decl.value.k !== "pattern" || patternSource(decl.value.pattern) !== source) return binaryFailure();
311
+ return assign(patternValue({
312
+ source,
313
+ program: 0,
314
+ data: null
315
+ }));
316
+ }
317
+ const items = children(item);
318
+ const xs = new Array(items.length);
319
+ tasks.push(() => {
320
+ let v;
321
+ switch (tag) {
322
+ case 6:
323
+ v = listValues(xs);
324
+ break;
325
+ case 7:
326
+ case 17: {
327
+ const pairs = [];
328
+ const seen = /* @__PURE__ */ new Set();
329
+ for (let i = 0; i < xs.length; i += 2) {
330
+ if (items[i].tag !== 5 || seen.has(xs[i].asText())) return binaryFailure();
331
+ const k = xs[i].asText();
332
+ seen.add(k);
333
+ pairs.push([k, xs[i + 1]]);
334
+ }
335
+ v = map(pairs);
336
+ if (tag === 17) {
337
+ if (!o.coreErrors || v.get("message").kind !== "text") return binaryFailure();
338
+ coreErrors.add(v);
339
+ }
340
+ break;
341
+ }
342
+ case 9:
343
+ if (xs[0].kind !== "number" || xs[1].kind !== "text") return binaryFailure();
344
+ v = quantity(xs[0], xs[1].asText());
345
+ if (v.kind !== "quantity" || v.asQuantity().unit !== xs[1].asText()) return binaryFailure();
346
+ break;
347
+ case 10:
348
+ v = range(xs[0], xs[1]);
349
+ break;
350
+ case 14:
351
+ if (xs.some((v) => v.kind !== "text")) return binaryFailure();
352
+ v = o.object?.(xs[0].asText(), xs[1].asText()) ?? binaryFailure();
353
+ break;
354
+ case 15:
355
+ case 19:
356
+ functionValid(xs, o);
357
+ v = o.decodeFunction?.(xs) ?? binaryFailure();
358
+ break;
359
+ default: return binaryFailure();
360
+ }
361
+ assign(v);
362
+ });
363
+ for (let i = items.length - 1; i >= 0; i--) visit(items[i], (v) => {
364
+ xs[i] = v;
365
+ });
366
+ });
367
+ visit(root, (v) => {
368
+ result = v;
369
+ });
370
+ while (tasks.length) tasks.pop()();
371
+ return result;
372
+ };
373
+ /** Dedicated transferable buffer, with no linear-memory or Node dependencies. */
374
+ const encodeBinaryValue = (v, o) => {
375
+ const writer = new BinaryWriter();
376
+ writer.item(valueItem(v, o));
377
+ return writer.buffer();
378
+ };
379
+ const decodeBinaryValue = (buffer, o) => {
380
+ const reader = new BinaryReader(new Uint8Array(buffer));
381
+ const item = reader.item();
382
+ reader.done();
383
+ return itemValue(item, o);
384
+ };
385
+ //#endregion
386
+ //#region src/generated/envelope.ts
387
+ const envelopeFeatures = [
388
+ "request-pump-fields-v1",
389
+ "callbacks-fields-v1",
390
+ "settlements-fields-v1",
391
+ "load-fields-v1",
392
+ "queue-fields-v1"
393
+ ];
394
+ const envelopeMessages = [
395
+ {
396
+ tag: 1,
397
+ name: "request",
398
+ direction: "host-to-guest",
399
+ fields: [
400
+ {
401
+ name: "ref",
402
+ kind: "int",
403
+ required: true
404
+ },
405
+ {
406
+ name: "group",
407
+ kind: "text",
408
+ required: true
409
+ },
410
+ {
411
+ name: "to",
412
+ kind: "target",
413
+ required: false
414
+ },
415
+ {
416
+ name: "message",
417
+ kind: "message",
418
+ required: false
419
+ }
420
+ ]
421
+ },
422
+ {
423
+ tag: 2,
424
+ name: "call",
425
+ direction: "host-to-guest",
426
+ fields: [
427
+ {
428
+ name: "ref",
429
+ kind: "int",
430
+ required: true
431
+ },
432
+ {
433
+ name: "group",
434
+ kind: "text",
435
+ required: true
436
+ },
437
+ {
438
+ name: "fn",
439
+ kind: "value",
440
+ required: false
441
+ },
442
+ {
443
+ name: "args",
444
+ kind: "values",
445
+ required: false
446
+ },
447
+ {
448
+ name: "limits",
449
+ kind: "limits",
450
+ required: false
451
+ }
452
+ ]
453
+ },
454
+ {
455
+ tag: 3,
456
+ name: "pump",
457
+ direction: "host-to-guest",
458
+ fields: [
459
+ {
460
+ name: "ref",
461
+ kind: "int",
462
+ required: true
463
+ },
464
+ {
465
+ name: "group",
466
+ kind: "text",
467
+ required: true
468
+ },
469
+ {
470
+ name: "now",
471
+ kind: "instant",
472
+ required: false
473
+ },
474
+ {
475
+ name: "fuelSlice",
476
+ kind: "int",
477
+ required: false
478
+ },
479
+ {
480
+ name: "fuelCap",
481
+ kind: "int",
482
+ required: false
483
+ }
484
+ ]
485
+ },
486
+ {
487
+ tag: 4,
488
+ name: "request-pump",
489
+ direction: "host-to-guest",
490
+ fields: [
491
+ {
492
+ name: "ref",
493
+ kind: "int",
494
+ required: true
495
+ },
496
+ {
497
+ name: "group",
498
+ kind: "text",
499
+ required: true
500
+ },
501
+ {
502
+ name: "token",
503
+ kind: "uint",
504
+ required: false
505
+ },
506
+ {
507
+ name: "to",
508
+ kind: "target",
509
+ required: false
510
+ },
511
+ {
512
+ name: "message",
513
+ kind: "message",
514
+ required: false
515
+ },
516
+ {
517
+ name: "now",
518
+ kind: "instant",
519
+ required: false
520
+ },
521
+ {
522
+ name: "fuelSlice",
523
+ kind: "int",
524
+ required: false
525
+ },
526
+ {
527
+ name: "fuelCap",
528
+ kind: "int",
529
+ required: false
530
+ }
531
+ ]
532
+ },
533
+ {
534
+ tag: 5,
535
+ name: "call-pump",
536
+ direction: "host-to-guest",
537
+ fields: [
538
+ {
539
+ name: "ref",
540
+ kind: "int",
541
+ required: true
542
+ },
543
+ {
544
+ name: "group",
545
+ kind: "text",
546
+ required: true
547
+ },
548
+ {
549
+ name: "token",
550
+ kind: "uint",
551
+ required: false
552
+ },
553
+ {
554
+ name: "fn",
555
+ kind: "value",
556
+ required: false
557
+ },
558
+ {
559
+ name: "args",
560
+ kind: "values",
561
+ required: false
562
+ },
563
+ {
564
+ name: "limits",
565
+ kind: "limits",
566
+ required: false
567
+ },
568
+ {
569
+ name: "now",
570
+ kind: "instant",
571
+ required: false
572
+ },
573
+ {
574
+ name: "fuelSlice",
575
+ kind: "int",
576
+ required: false
577
+ },
578
+ {
579
+ name: "fuelCap",
580
+ kind: "int",
581
+ required: false
582
+ }
583
+ ]
584
+ },
585
+ {
586
+ tag: 6,
587
+ name: "op-result",
588
+ direction: "host-to-guest",
589
+ fields: [
590
+ {
591
+ name: "ref",
592
+ kind: "int",
593
+ required: true
594
+ },
595
+ {
596
+ name: "group",
597
+ kind: "text",
598
+ required: true
599
+ },
600
+ {
601
+ name: "outcome",
602
+ kind: "text",
603
+ required: true
604
+ },
605
+ {
606
+ name: "value",
607
+ kind: "value",
608
+ required: false
609
+ },
610
+ {
611
+ name: "code",
612
+ kind: "text",
613
+ required: false
614
+ },
615
+ {
616
+ name: "message",
617
+ kind: "text",
618
+ required: false
619
+ },
620
+ {
621
+ name: "charged",
622
+ kind: "uint",
623
+ required: false
624
+ }
625
+ ]
626
+ },
627
+ {
628
+ tag: 7,
629
+ name: "prop-result",
630
+ direction: "host-to-guest",
631
+ fields: [
632
+ {
633
+ name: "ref",
634
+ kind: "int",
635
+ required: true
636
+ },
637
+ {
638
+ name: "group",
639
+ kind: "text",
640
+ required: true
641
+ },
642
+ {
643
+ name: "outcome",
644
+ kind: "text",
645
+ required: true
646
+ },
647
+ {
648
+ name: "value",
649
+ kind: "value",
650
+ required: false
651
+ },
652
+ {
653
+ name: "code",
654
+ kind: "text",
655
+ required: false
656
+ },
657
+ {
658
+ name: "message",
659
+ kind: "text",
660
+ required: false
661
+ },
662
+ {
663
+ name: "charged",
664
+ kind: "uint",
665
+ required: false
666
+ }
667
+ ]
668
+ },
669
+ {
670
+ tag: 8,
671
+ name: "effect-result",
672
+ direction: "host-to-guest",
673
+ fields: [
674
+ {
675
+ name: "ref",
676
+ kind: "int",
677
+ required: true
678
+ },
679
+ {
680
+ name: "group",
681
+ kind: "text",
682
+ required: true
683
+ },
684
+ {
685
+ name: "status",
686
+ kind: "text",
687
+ required: false
688
+ }
689
+ ]
690
+ },
691
+ {
692
+ tag: 9,
693
+ name: "release-result",
694
+ direction: "host-to-guest",
695
+ fields: [{
696
+ name: "ref",
697
+ kind: "int",
698
+ required: true
699
+ }, {
700
+ name: "group",
701
+ kind: "text",
702
+ required: true
703
+ }]
704
+ },
705
+ {
706
+ tag: 10,
707
+ name: "settle-pump",
708
+ direction: "host-to-guest",
709
+ fields: [
710
+ {
711
+ name: "ref",
712
+ kind: "int",
713
+ required: true
714
+ },
715
+ {
716
+ name: "group",
717
+ kind: "text",
718
+ required: true
719
+ },
720
+ {
721
+ name: "now",
722
+ kind: "instant",
723
+ required: false
724
+ },
725
+ {
726
+ name: "fuelSlice",
727
+ kind: "int",
728
+ required: false
729
+ },
730
+ {
731
+ name: "fuelCap",
732
+ kind: "int",
733
+ required: false
734
+ },
735
+ {
736
+ name: "settlements",
737
+ kind: "settlements",
738
+ required: false
739
+ }
740
+ ]
741
+ },
742
+ {
743
+ tag: 11,
744
+ name: "load",
745
+ direction: "host-to-guest",
746
+ fields: [
747
+ {
748
+ name: "ref",
749
+ kind: "int",
750
+ required: true
751
+ },
752
+ {
753
+ name: "group",
754
+ kind: "text",
755
+ required: true
756
+ },
757
+ {
758
+ name: "name",
759
+ kind: "text",
760
+ required: true
761
+ },
762
+ {
763
+ name: "source",
764
+ kind: "text",
765
+ required: true
766
+ },
767
+ {
768
+ name: "grants",
769
+ kind: "record",
770
+ required: false
771
+ },
772
+ {
773
+ name: "grantsAsUsed",
774
+ kind: "bool",
775
+ required: false
776
+ },
777
+ {
778
+ name: "owner",
779
+ kind: "record",
780
+ required: false
781
+ },
782
+ {
783
+ name: "objects",
784
+ kind: "record",
785
+ required: false
786
+ },
787
+ {
788
+ name: "limits",
789
+ kind: "limits",
790
+ required: false
791
+ },
792
+ {
793
+ name: "newGroup",
794
+ kind: "record",
795
+ required: false
796
+ },
797
+ {
798
+ name: "refuseWorker",
799
+ kind: "bool",
800
+ required: false
801
+ }
802
+ ]
803
+ },
804
+ {
805
+ tag: 12,
806
+ name: "deliver",
807
+ direction: "host-to-guest",
808
+ fields: [
809
+ {
810
+ name: "ref",
811
+ kind: "int",
812
+ required: true
813
+ },
814
+ {
815
+ name: "group",
816
+ kind: "text",
817
+ required: true
818
+ },
819
+ {
820
+ name: "to",
821
+ kind: "target",
822
+ required: false
823
+ },
824
+ {
825
+ name: "message",
826
+ kind: "message",
827
+ required: false
828
+ }
829
+ ]
830
+ },
831
+ {
832
+ tag: 13,
833
+ name: "broadcast",
834
+ direction: "host-to-guest",
835
+ fields: [
836
+ {
837
+ name: "ref",
838
+ kind: "int",
839
+ required: true
840
+ },
841
+ {
842
+ name: "group",
843
+ kind: "text",
844
+ required: true
845
+ },
846
+ {
847
+ name: "message",
848
+ kind: "message",
849
+ required: false
850
+ }
851
+ ]
852
+ },
853
+ {
854
+ tag: 14,
855
+ name: "decide",
856
+ direction: "host-to-guest",
857
+ fields: [
858
+ {
859
+ name: "ref",
860
+ kind: "int",
861
+ required: true
862
+ },
863
+ {
864
+ name: "group",
865
+ kind: "text",
866
+ required: true
867
+ },
868
+ {
869
+ name: "to",
870
+ kind: "target",
871
+ required: false
872
+ },
873
+ {
874
+ name: "message",
875
+ kind: "message",
876
+ required: false
877
+ },
878
+ {
879
+ name: "broadcast",
880
+ kind: "bool",
881
+ required: false
882
+ }
883
+ ]
884
+ },
885
+ {
886
+ tag: 129,
887
+ name: "admission",
888
+ direction: "guest-to-host",
889
+ fields: [
890
+ {
891
+ name: "ref",
892
+ kind: "int",
893
+ required: true
894
+ },
895
+ {
896
+ name: "delivery",
897
+ kind: "text",
898
+ required: false
899
+ },
900
+ {
901
+ name: "err",
902
+ kind: "err",
903
+ required: false
904
+ },
905
+ {
906
+ name: "abandoned",
907
+ kind: "texts",
908
+ required: false
909
+ },
910
+ {
911
+ name: "settled",
912
+ kind: "texts",
913
+ required: false
914
+ },
915
+ {
916
+ name: "trace",
917
+ kind: "texts",
918
+ required: false
919
+ }
920
+ ]
921
+ },
922
+ {
923
+ tag: 130,
924
+ name: "completion",
925
+ direction: "guest-to-host",
926
+ fields: [
927
+ {
928
+ name: "ref",
929
+ kind: "int",
930
+ required: true
931
+ },
932
+ {
933
+ name: "delivery",
934
+ kind: "text",
935
+ required: false
936
+ },
937
+ {
938
+ name: "token",
939
+ kind: "uint",
940
+ required: false
941
+ },
942
+ {
943
+ name: "state",
944
+ kind: "text",
945
+ required: false
946
+ },
947
+ {
948
+ name: "nextDeadline",
949
+ kind: "instant",
950
+ required: false
951
+ },
952
+ {
953
+ name: "fuelUsed",
954
+ kind: "uint",
955
+ required: false
956
+ },
957
+ {
958
+ name: "reports",
959
+ kind: "reports",
960
+ required: false
961
+ },
962
+ {
963
+ name: "gone",
964
+ kind: "texts",
965
+ required: false
966
+ },
967
+ {
968
+ name: "err",
969
+ kind: "err",
970
+ required: false
971
+ },
972
+ {
973
+ name: "abandoned",
974
+ kind: "texts",
975
+ required: false
976
+ },
977
+ {
978
+ name: "settled",
979
+ kind: "texts",
980
+ required: false
981
+ },
982
+ {
983
+ name: "trace",
984
+ kind: "texts",
985
+ required: false
986
+ }
987
+ ]
988
+ },
989
+ {
990
+ tag: 131,
991
+ name: "op",
992
+ direction: "guest-to-host",
993
+ fields: [
994
+ {
995
+ name: "ref",
996
+ kind: "int",
997
+ required: true
998
+ },
999
+ {
1000
+ name: "call",
1001
+ kind: "text",
1002
+ required: true
1003
+ },
1004
+ {
1005
+ name: "script",
1006
+ kind: "text",
1007
+ required: true
1008
+ },
1009
+ {
1010
+ name: "run",
1011
+ kind: "text",
1012
+ required: true
1013
+ },
1014
+ {
1015
+ name: "segment",
1016
+ kind: "text",
1017
+ required: true
1018
+ },
1019
+ {
1020
+ name: "grant",
1021
+ kind: "text",
1022
+ required: true
1023
+ },
1024
+ {
1025
+ name: "capability",
1026
+ kind: "text",
1027
+ required: true
1028
+ },
1029
+ {
1030
+ name: "operation",
1031
+ kind: "text",
1032
+ required: true
1033
+ },
1034
+ {
1035
+ name: "mode",
1036
+ kind: "text",
1037
+ required: true
1038
+ },
1039
+ {
1040
+ name: "now",
1041
+ kind: "instant",
1042
+ required: true
1043
+ },
1044
+ {
1045
+ name: "args",
1046
+ kind: "values",
1047
+ required: true
1048
+ },
1049
+ {
1050
+ name: "scope",
1051
+ kind: "text",
1052
+ required: false
1053
+ },
1054
+ {
1055
+ name: "automatic",
1056
+ kind: "bool",
1057
+ required: false
1058
+ },
1059
+ {
1060
+ name: "fuelLeft",
1061
+ kind: "uint",
1062
+ required: false
1063
+ },
1064
+ {
1065
+ name: "delivery",
1066
+ kind: "text",
1067
+ required: false
1068
+ },
1069
+ {
1070
+ name: "abandoned",
1071
+ kind: "texts",
1072
+ required: false
1073
+ },
1074
+ {
1075
+ name: "settled",
1076
+ kind: "texts",
1077
+ required: false
1078
+ },
1079
+ {
1080
+ name: "trace",
1081
+ kind: "texts",
1082
+ required: false
1083
+ }
1084
+ ]
1085
+ },
1086
+ {
1087
+ tag: 132,
1088
+ name: "prop",
1089
+ direction: "guest-to-host",
1090
+ fields: [
1091
+ {
1092
+ name: "ref",
1093
+ kind: "int",
1094
+ required: true
1095
+ },
1096
+ {
1097
+ name: "object",
1098
+ kind: "texts",
1099
+ required: true
1100
+ },
1101
+ {
1102
+ name: "prop",
1103
+ kind: "text",
1104
+ required: true
1105
+ },
1106
+ {
1107
+ name: "set",
1108
+ kind: "bool",
1109
+ required: false
1110
+ },
1111
+ {
1112
+ name: "value",
1113
+ kind: "value",
1114
+ required: false
1115
+ },
1116
+ {
1117
+ name: "op",
1118
+ kind: "text",
1119
+ required: false
1120
+ },
1121
+ {
1122
+ name: "selector",
1123
+ kind: "value",
1124
+ required: false
1125
+ },
1126
+ {
1127
+ name: "abandoned",
1128
+ kind: "texts",
1129
+ required: false
1130
+ },
1131
+ {
1132
+ name: "settled",
1133
+ kind: "texts",
1134
+ required: false
1135
+ },
1136
+ {
1137
+ name: "trace",
1138
+ kind: "texts",
1139
+ required: false
1140
+ }
1141
+ ]
1142
+ },
1143
+ {
1144
+ tag: 133,
1145
+ name: "effect",
1146
+ direction: "guest-to-host",
1147
+ fields: [
1148
+ {
1149
+ name: "ref",
1150
+ kind: "int",
1151
+ required: true
1152
+ },
1153
+ {
1154
+ name: "script",
1155
+ kind: "text",
1156
+ required: true
1157
+ },
1158
+ {
1159
+ name: "run",
1160
+ kind: "text",
1161
+ required: true
1162
+ },
1163
+ {
1164
+ name: "segment",
1165
+ kind: "text",
1166
+ required: true
1167
+ },
1168
+ {
1169
+ name: "grant",
1170
+ kind: "text",
1171
+ required: true
1172
+ },
1173
+ {
1174
+ name: "grants",
1175
+ kind: "texts",
1176
+ required: true
1177
+ },
1178
+ {
1179
+ name: "coordinator",
1180
+ kind: "text",
1181
+ required: false
1182
+ },
1183
+ {
1184
+ name: "phase",
1185
+ kind: "text",
1186
+ required: true
1187
+ },
1188
+ {
1189
+ name: "now",
1190
+ kind: "instant",
1191
+ required: true
1192
+ },
1193
+ {
1194
+ name: "abandoned",
1195
+ kind: "texts",
1196
+ required: false
1197
+ },
1198
+ {
1199
+ name: "settled",
1200
+ kind: "texts",
1201
+ required: false
1202
+ },
1203
+ {
1204
+ name: "trace",
1205
+ kind: "texts",
1206
+ required: false
1207
+ }
1208
+ ]
1209
+ },
1210
+ {
1211
+ tag: 134,
1212
+ name: "release",
1213
+ direction: "guest-to-host",
1214
+ fields: [
1215
+ {
1216
+ name: "ref",
1217
+ kind: "int",
1218
+ required: true
1219
+ },
1220
+ {
1221
+ name: "script",
1222
+ kind: "text",
1223
+ required: true
1224
+ },
1225
+ {
1226
+ name: "grant",
1227
+ kind: "text",
1228
+ required: true
1229
+ },
1230
+ {
1231
+ name: "reason",
1232
+ kind: "text",
1233
+ required: true
1234
+ },
1235
+ {
1236
+ name: "now",
1237
+ kind: "instant",
1238
+ required: true
1239
+ },
1240
+ {
1241
+ name: "abandoned",
1242
+ kind: "texts",
1243
+ required: false
1244
+ },
1245
+ {
1246
+ name: "settled",
1247
+ kind: "texts",
1248
+ required: false
1249
+ },
1250
+ {
1251
+ name: "trace",
1252
+ kind: "texts",
1253
+ required: false
1254
+ }
1255
+ ]
1256
+ }
1257
+ ];
1258
+ const envelopeReports = [
1259
+ {
1260
+ tag: 1,
1261
+ name: "run end",
1262
+ direction: "guest-to-host",
1263
+ fields: [
1264
+ {
1265
+ name: "script",
1266
+ kind: "text",
1267
+ required: false
1268
+ },
1269
+ {
1270
+ name: "run",
1271
+ kind: "text",
1272
+ required: false
1273
+ },
1274
+ {
1275
+ name: "delivery",
1276
+ kind: "text",
1277
+ required: false
1278
+ },
1279
+ {
1280
+ name: "broadcast",
1281
+ kind: "text",
1282
+ required: false
1283
+ },
1284
+ {
1285
+ name: "handler",
1286
+ kind: "text",
1287
+ required: false
1288
+ },
1289
+ {
1290
+ name: "fallback",
1291
+ kind: "bool",
1292
+ required: false
1293
+ },
1294
+ {
1295
+ name: "climbed",
1296
+ kind: "bool",
1297
+ required: false
1298
+ },
1299
+ {
1300
+ name: "outcome",
1301
+ kind: "text",
1302
+ required: false
1303
+ },
1304
+ {
1305
+ name: "result",
1306
+ kind: "value",
1307
+ required: false
1308
+ },
1309
+ {
1310
+ name: "error",
1311
+ kind: "value",
1312
+ required: false
1313
+ },
1314
+ {
1315
+ name: "limit",
1316
+ kind: "text",
1317
+ required: false
1318
+ },
1319
+ {
1320
+ name: "effect",
1321
+ kind: "record",
1322
+ required: false
1323
+ },
1324
+ {
1325
+ name: "cleanupFailed",
1326
+ kind: "record",
1327
+ required: false
1328
+ },
1329
+ {
1330
+ name: "at",
1331
+ kind: "record",
1332
+ required: false
1333
+ },
1334
+ {
1335
+ name: "fuel",
1336
+ kind: "uint",
1337
+ required: false
1338
+ },
1339
+ {
1340
+ name: "alloc",
1341
+ kind: "uint",
1342
+ required: false
1343
+ }
1344
+ ]
1345
+ },
1346
+ {
1347
+ tag: 2,
1348
+ name: "run started",
1349
+ direction: "guest-to-host",
1350
+ fields: [
1351
+ {
1352
+ name: "script",
1353
+ kind: "text",
1354
+ required: false
1355
+ },
1356
+ {
1357
+ name: "run",
1358
+ kind: "text",
1359
+ required: false
1360
+ },
1361
+ {
1362
+ name: "args",
1363
+ kind: "values",
1364
+ required: false
1365
+ },
1366
+ {
1367
+ name: "rootDelivery",
1368
+ kind: "text",
1369
+ required: false
1370
+ },
1371
+ {
1372
+ name: "parentRun",
1373
+ kind: "text",
1374
+ required: false
1375
+ },
1376
+ {
1377
+ name: "parentCall",
1378
+ kind: "text",
1379
+ required: false
1380
+ },
1381
+ {
1382
+ name: "delivery",
1383
+ kind: "text",
1384
+ required: false
1385
+ },
1386
+ {
1387
+ name: "selector",
1388
+ kind: "text",
1389
+ required: false
1390
+ },
1391
+ {
1392
+ name: "fn",
1393
+ kind: "value",
1394
+ required: false
1395
+ }
1396
+ ]
1397
+ },
1398
+ {
1399
+ tag: 3,
1400
+ name: "run discarded",
1401
+ direction: "guest-to-host",
1402
+ fields: [
1403
+ {
1404
+ name: "script",
1405
+ kind: "text",
1406
+ required: false
1407
+ },
1408
+ {
1409
+ name: "run",
1410
+ kind: "text",
1411
+ required: false
1412
+ },
1413
+ {
1414
+ name: "reason",
1415
+ kind: "text",
1416
+ required: false
1417
+ },
1418
+ {
1419
+ name: "rootDelivery",
1420
+ kind: "text",
1421
+ required: false
1422
+ },
1423
+ {
1424
+ name: "parentRun",
1425
+ kind: "text",
1426
+ required: false
1427
+ },
1428
+ {
1429
+ name: "parentCall",
1430
+ kind: "text",
1431
+ required: false
1432
+ }
1433
+ ]
1434
+ },
1435
+ {
1436
+ tag: 4,
1437
+ name: "run accounting",
1438
+ direction: "guest-to-host",
1439
+ fields: [
1440
+ {
1441
+ name: "script",
1442
+ kind: "text",
1443
+ required: false
1444
+ },
1445
+ {
1446
+ name: "run",
1447
+ kind: "text",
1448
+ required: false
1449
+ },
1450
+ {
1451
+ name: "fuel",
1452
+ kind: "uint",
1453
+ required: false
1454
+ },
1455
+ {
1456
+ name: "state",
1457
+ kind: "text",
1458
+ required: false
1459
+ },
1460
+ {
1461
+ name: "rootDelivery",
1462
+ kind: "text",
1463
+ required: false
1464
+ },
1465
+ {
1466
+ name: "parentRun",
1467
+ kind: "text",
1468
+ required: false
1469
+ },
1470
+ {
1471
+ name: "parentCall",
1472
+ kind: "text",
1473
+ required: false
1474
+ }
1475
+ ]
1476
+ },
1477
+ {
1478
+ tag: 5,
1479
+ name: "causal work",
1480
+ direction: "guest-to-host",
1481
+ fields: [
1482
+ {
1483
+ name: "rootDelivery",
1484
+ kind: "text",
1485
+ required: false
1486
+ },
1487
+ {
1488
+ name: "liveRuns",
1489
+ kind: "uint",
1490
+ required: false
1491
+ },
1492
+ {
1493
+ name: "queuedMessages",
1494
+ kind: "uint",
1495
+ required: false
1496
+ },
1497
+ {
1498
+ name: "discardedMessages",
1499
+ kind: "uint",
1500
+ required: false
1501
+ }
1502
+ ]
1503
+ },
1504
+ {
1505
+ tag: 6,
1506
+ name: "stop",
1507
+ direction: "guest-to-host",
1508
+ fields: [
1509
+ {
1510
+ name: "script",
1511
+ kind: "text",
1512
+ required: false
1513
+ },
1514
+ {
1515
+ name: "reason",
1516
+ kind: "text",
1517
+ required: false
1518
+ },
1519
+ {
1520
+ name: "discardedRuns",
1521
+ kind: "texts",
1522
+ required: false
1523
+ },
1524
+ {
1525
+ name: "droppedMessages",
1526
+ kind: "texts",
1527
+ required: false
1528
+ },
1529
+ {
1530
+ name: "pendingCalls",
1531
+ kind: "texts",
1532
+ required: false
1533
+ }
1534
+ ]
1535
+ },
1536
+ {
1537
+ tag: 7,
1538
+ name: "unhandled",
1539
+ direction: "guest-to-host",
1540
+ fields: [
1541
+ {
1542
+ name: "delivery",
1543
+ kind: "text",
1544
+ required: false
1545
+ },
1546
+ {
1547
+ name: "message",
1548
+ kind: "message",
1549
+ required: false
1550
+ },
1551
+ {
1552
+ name: "target",
1553
+ kind: "value",
1554
+ required: false
1555
+ }
1556
+ ]
1557
+ },
1558
+ {
1559
+ tag: 8,
1560
+ name: "call failed",
1561
+ direction: "guest-to-host",
1562
+ fields: [
1563
+ {
1564
+ name: "script",
1565
+ kind: "text",
1566
+ required: false
1567
+ },
1568
+ {
1569
+ name: "call",
1570
+ kind: "text",
1571
+ required: false
1572
+ },
1573
+ {
1574
+ name: "operation",
1575
+ kind: "record",
1576
+ required: false
1577
+ },
1578
+ {
1579
+ name: "detail",
1580
+ kind: "text",
1581
+ required: false
1582
+ }
1583
+ ]
1584
+ },
1585
+ {
1586
+ tag: 9,
1587
+ name: "effect failure",
1588
+ direction: "guest-to-host",
1589
+ fields: [
1590
+ {
1591
+ name: "script",
1592
+ kind: "text",
1593
+ required: false
1594
+ },
1595
+ {
1596
+ name: "run",
1597
+ kind: "text",
1598
+ required: false
1599
+ },
1600
+ {
1601
+ name: "grant",
1602
+ kind: "text",
1603
+ required: false
1604
+ },
1605
+ {
1606
+ name: "segment",
1607
+ kind: "text",
1608
+ required: false
1609
+ },
1610
+ {
1611
+ name: "phase",
1612
+ kind: "text",
1613
+ required: false
1614
+ },
1615
+ {
1616
+ name: "status",
1617
+ kind: "text",
1618
+ required: false
1619
+ },
1620
+ {
1621
+ name: "scope",
1622
+ kind: "text",
1623
+ required: false
1624
+ }
1625
+ ]
1626
+ },
1627
+ {
1628
+ tag: 10,
1629
+ name: "decided",
1630
+ direction: "guest-to-host",
1631
+ fields: [
1632
+ {
1633
+ name: "delivery",
1634
+ kind: "text",
1635
+ required: false
1636
+ },
1637
+ {
1638
+ name: "broadcast",
1639
+ kind: "text",
1640
+ required: false
1641
+ },
1642
+ {
1643
+ name: "verdict",
1644
+ kind: "text",
1645
+ required: false
1646
+ },
1647
+ {
1648
+ name: "vetoes",
1649
+ kind: "record",
1650
+ required: false
1651
+ },
1652
+ {
1653
+ name: "undecided",
1654
+ kind: "record",
1655
+ required: false
1656
+ }
1657
+ ]
1658
+ },
1659
+ {
1660
+ tag: 11,
1661
+ name: "host error",
1662
+ direction: "guest-to-host",
1663
+ fields: [{
1664
+ name: "code",
1665
+ kind: "text",
1666
+ required: false
1667
+ }, {
1668
+ name: "detail",
1669
+ kind: "text",
1670
+ required: false
1671
+ }]
1672
+ },
1673
+ {
1674
+ tag: 12,
1675
+ name: "charge result",
1676
+ direction: "guest-to-host",
1677
+ fields: [
1678
+ {
1679
+ name: "request",
1680
+ kind: "text",
1681
+ required: false
1682
+ },
1683
+ {
1684
+ name: "call",
1685
+ kind: "text",
1686
+ required: false
1687
+ },
1688
+ {
1689
+ name: "fuel",
1690
+ kind: "uint",
1691
+ required: false
1692
+ },
1693
+ {
1694
+ name: "status",
1695
+ kind: "text",
1696
+ required: false
1697
+ }
1698
+ ]
1699
+ }
1700
+ ];
1701
+ const envelopeSettlement = [
1702
+ {
1703
+ name: "call",
1704
+ kind: "text",
1705
+ required: true
1706
+ },
1707
+ {
1708
+ name: "outcome",
1709
+ kind: "text",
1710
+ required: true
1711
+ },
1712
+ {
1713
+ name: "value",
1714
+ kind: "value",
1715
+ required: false
1716
+ },
1717
+ {
1718
+ name: "fuel",
1719
+ kind: "int",
1720
+ required: false
1721
+ },
1722
+ {
1723
+ name: "code",
1724
+ kind: "text",
1725
+ required: false
1726
+ },
1727
+ {
1728
+ name: "message",
1729
+ kind: "text",
1730
+ required: false
1731
+ }
1732
+ ];
1733
+ //#endregion
1734
+ //#region src/request-pump-binary.ts
1735
+ const requestPumpFeature = envelopeFeatures[0];
1736
+ const callbacksFeature = envelopeFeatures[1];
1737
+ const prefix = [
1738
+ 78,
1739
+ 84,
1740
+ 66,
1741
+ 1,
1742
+ 1
1743
+ ];
1744
+ const object = (j) => isJsonObject(j) ? j : binaryFailure();
1745
+ const field = (j, k) => object(j).pairs.find(([key]) => key === k)?.[1];
1746
+ const record = (pairs) => new JsonObject(pairs.filter((p) => p[1] !== void 0));
1747
+ const coreErrorNodes = /* @__PURE__ */ new WeakSet();
1748
+ const valueNodes = /* @__PURE__ */ new WeakMap();
1749
+ /**
1750
+ * A frame node standing for a Host Value, so a Host that holds the Value
1751
+ * skips its Value Encoding; Functions use the options' `encodeFunction`.
1752
+ */
1753
+ const valueNode = (v) => {
1754
+ const node = new JsonObject([]);
1755
+ valueNodes.set(node, v);
1756
+ return node;
1757
+ };
1758
+ /** The Value a `valueNode` holds. */
1759
+ const heldValue = (j) => isJsonObject(j) ? valueNodes.get(j) : void 0;
1760
+ /** Checks Values' metadata without resolving Objects or Functions. */
1761
+ const placeholderValues = (o) => ({
1762
+ ...o,
1763
+ object: (kind, id) => objectValue({
1764
+ kind,
1765
+ id,
1766
+ handle: {}
1767
+ }),
1768
+ decodeFunction: () => nothing
1769
+ });
1770
+ const metadata = placeholderValues;
1771
+ const jsonValueItem = (j, o) => {
1772
+ const held = isJsonObject(j) ? valueNodes.get(j) : void 0;
1773
+ if (held) return valueItem(held, o);
1774
+ const payloads = /* @__PURE__ */ new WeakMap();
1775
+ const v = fromJson(j, (kind, id) => objectValue({
1776
+ kind,
1777
+ id,
1778
+ handle: {}
1779
+ }), void 0, (tag, data) => {
1780
+ if (tag === "$pattern" && typeof data === "string") return patternValue({
1781
+ source: data,
1782
+ program: 0,
1783
+ data: null
1784
+ });
1785
+ if (tag !== "$function" || !Array.isArray(data)) return binaryFailure();
1786
+ const xs = data.map((x, i) => i === 6 && typeof x === "string" ? fromJson(new JsonObject([["$bytes", x]])) : fromJson(x));
1787
+ const placeholder = functionValue({
1788
+ home: "",
1789
+ place: "",
1790
+ identity: "",
1791
+ captures: [],
1792
+ maySuspend: false,
1793
+ code: null
1794
+ });
1795
+ payloads.set(placeholder, xs);
1796
+ return placeholder;
1797
+ });
1798
+ const root = valueItem(v, {
1799
+ ...o,
1800
+ encodeFunction: (v) => payloads.get(v) ?? binaryFailure()
1801
+ });
1802
+ const work = [[j, root]];
1803
+ while (work.length) {
1804
+ const [node, item] = work.pop();
1805
+ if (Array.isArray(node)) node.forEach((v, i) => work.push([v, children(item)[i]]));
1806
+ else if (isJsonObject(node)) {
1807
+ if (coreErrorNodes.has(node)) {
1808
+ if (!o.coreErrors) binaryFailure();
1809
+ item.tag = 17;
1810
+ }
1811
+ if (item.tag === 7 || item.tag === 17) {
1812
+ const escaped = field(node, "$map");
1813
+ (Array.isArray(escaped) ? escaped : node.pairs).forEach(([, v], i) => work.push([v, children(item)[2 * i + 1]]));
1814
+ } else if (item.tag === 10) {
1815
+ const ends = field(node, "$range");
1816
+ if (!Array.isArray(ends)) return binaryFailure();
1817
+ ends.forEach((v, i) => work.push([v, children(item)[i]]));
1818
+ }
1819
+ }
1820
+ }
1821
+ itemValue(root, metadata(o));
1822
+ return root;
1823
+ };
1824
+ const role = (key, parent) => [
1825
+ "fn",
1826
+ "result",
1827
+ "error",
1828
+ "object",
1829
+ "target"
1830
+ ].includes(key) || key === "reason" && parent === "vetoes" ? "value" : key === "args" ? "values" : "protocol";
1831
+ const jsonItem = (j, o, key = "", parent = "") => {
1832
+ if (j === null) return { tag: 0 };
1833
+ const r = role(key, parent);
1834
+ if (r === "value") return jsonValueItem(j, o);
1835
+ if (r === "values") {
1836
+ if (!Array.isArray(j)) return binaryFailure();
1837
+ return {
1838
+ tag: 6,
1839
+ data: j.map((v) => jsonValueItem(v, o))
1840
+ };
1841
+ }
1842
+ if (j === null) return { tag: 0 };
1843
+ if (typeof j === "boolean") return { tag: j ? 2 : 1 };
1844
+ if (typeof j === "string") return {
1845
+ tag: 18,
1846
+ data: j
1847
+ };
1848
+ if (isJsonNumber(j)) return /^-?\d+$/.test(j.source) ? integerItem(BigInt(j.source)) : valueItem(fromJson(new JsonObject([["$dec", j.source]])));
1849
+ if (Array.isArray(j)) return {
1850
+ tag: 6,
1851
+ data: j.map((v) => jsonItem(v, o, "", key))
1852
+ };
1853
+ return {
1854
+ tag: 7,
1855
+ data: j.pairs.flatMap(([k, v]) => [{
1856
+ tag: 5,
1857
+ data: k
1858
+ }, jsonItem(v, o, k, parent)])
1859
+ };
1860
+ };
1861
+ const itemJson = (root, o, value = false) => {
1862
+ let result;
1863
+ const tasks = [];
1864
+ const visit = (item, assign, value) => tasks.push(() => {
1865
+ const { tag, data } = item;
1866
+ if (tag === 0) return assign(null);
1867
+ if (tag === 1 || tag === 2) return assign(tag === 2);
1868
+ if (tag === 3 || tag === 16 || tag === 4) {
1869
+ const s = tag === 4 ? data : itemInteger(item).toString();
1870
+ return assign(value && (s.includes(".") || BigInt(s) <= -(2n ** 53n) || BigInt(s) >= 2n ** 53n) ? new JsonObject([["$dec", s]]) : new JsonNumber(s));
1871
+ }
1872
+ if (tag === 5 || tag === 18) {
1873
+ if (value && tag === 18) return binaryFailure();
1874
+ return assign(itemText(item));
1875
+ }
1876
+ if (tag === 11) {
1877
+ const n = data;
1878
+ const s = formatInstant(n >> 1n ^ -(n & 1n));
1879
+ return assign(value ? new JsonObject([["$instant", s]]) : s);
1880
+ }
1881
+ if (tag === 8 || tag === 12 || tag === 13) return assign(new JsonObject([[tag === 8 ? "$bytes" : tag === 12 ? "$date" : "$pattern", tag === 8 ? toBase64(data) : data]]));
1882
+ const items = children(item);
1883
+ const xs = new Array(items.length);
1884
+ tasks.push(() => {
1885
+ if (tag === 6) return assign(xs);
1886
+ if (tag === 7 || tag === 17) {
1887
+ if (tag === 17 && !o.coreErrors) return binaryFailure();
1888
+ const pairs = [];
1889
+ const seen = /* @__PURE__ */ new Set();
1890
+ for (let i = 0; i < xs.length; i += 2) {
1891
+ if (items[i].tag !== 5) return binaryFailure();
1892
+ const k = itemText(items[i]);
1893
+ if (seen.has(k)) return binaryFailure();
1894
+ seen.add(k);
1895
+ pairs.push([k, xs[i + 1]]);
1896
+ }
1897
+ const node = value && pairs.some(([k]) => k.startsWith("$")) ? new JsonObject([["$map", pairs.map(([k, v]) => [k, v])]]) : new JsonObject(pairs);
1898
+ if (tag === 17) coreErrorNodes.add(node);
1899
+ return assign(node);
1900
+ }
1901
+ if (tag === 9) {
1902
+ const n = children(item)[0];
1903
+ return assign(new JsonObject([["$quantity", [n.tag === 4 ? n.data : itemInteger(n).toString(), itemText(items[1])]]]));
1904
+ }
1905
+ if (tag === 10 || tag === 14) return assign(new JsonObject([[tag === 10 ? "$range" : "$object", xs]]));
1906
+ if (tag === 15 || tag === 19) {
1907
+ if (tag === 19 && !o.functionMetadata) return binaryFailure();
1908
+ if (xs.length === 7) xs[6] = toBase64(items[6].data);
1909
+ return assign(new JsonObject([["$function", xs]]));
1910
+ }
1911
+ return binaryFailure();
1912
+ });
1913
+ for (let i = items.length - 1; i >= 0; i--) {
1914
+ const v = value || ![6, 7].includes(tag);
1915
+ visit(items[i], (j) => {
1916
+ xs[i] = j;
1917
+ }, v);
1918
+ }
1919
+ });
1920
+ visit(root, (j) => {
1921
+ result = j;
1922
+ }, value);
1923
+ while (tasks.length) tasks.pop()();
1924
+ return result;
1925
+ };
1926
+ const convert = (item, o, key, parent = "") => {
1927
+ const kind = role(key, parent);
1928
+ if (kind === "value") {
1929
+ itemValue(item, metadata(o));
1930
+ return itemJson(item, o, true);
1931
+ }
1932
+ if (kind === "values") {
1933
+ if (item.tag !== 6) return binaryFailure();
1934
+ return children(item).map((v) => {
1935
+ itemValue(v, metadata(o));
1936
+ return itemJson(v, o, true);
1937
+ });
1938
+ }
1939
+ if (item.tag === 7) {
1940
+ const xs = children(item);
1941
+ const ps = [];
1942
+ const seen = /* @__PURE__ */ new Set();
1943
+ for (let i = 0; i < xs.length; i += 2) {
1944
+ if (xs[i].tag !== 5) return binaryFailure();
1945
+ const k = itemText(xs[i]);
1946
+ if (seen.has(k)) return binaryFailure();
1947
+ seen.add(k);
1948
+ ps.push([k, convert(xs[i + 1], o, k, parent)]);
1949
+ }
1950
+ return new JsonObject(ps);
1951
+ }
1952
+ if (item.tag === 6) return children(item).map((v) => convert(v, o, "", key));
1953
+ return itemJson(item, o);
1954
+ };
1955
+ const notices = [
1956
+ "abandoned",
1957
+ "settled",
1958
+ "trace"
1959
+ ];
1960
+ const member = (x, k) => isJsonObject(x) ? field(x, k) : x !== null && typeof x === "object" && !Value.isValue(x) ? x[k] : void 0;
1961
+ const schema = (entry, family, fromWire, extra = {}) => ({
1962
+ tag: entry.tag,
1963
+ name: entry.name,
1964
+ family,
1965
+ fields: entry.fields.map(({ name, kind }) => [name, kind]),
1966
+ keys: new Set(extra.keys ?? entry.fields.map((f) => f.name)),
1967
+ required: entry.fields.filter((f) => f.required).map((f) => f.name),
1968
+ fromWire,
1969
+ toWire: extra.toWire
1970
+ });
1971
+ const message = (entry) => schema(entry, entry.name.endsWith("-result") ? "result" : "message", (_, pairs) => new JsonObject([["m", entry.name], ...pairs]));
1972
+ const outcomeResult = (entry, outcomes) => schema(entry, "result", (get, pairs) => {
1973
+ const outcome = get("outcome");
1974
+ if (!outcomes.includes(outcome) || outcome === "fail" && get("code") === void 0) return binaryFailure();
1975
+ const value = get("value") ?? null;
1976
+ return new JsonObject([
1977
+ ["m", entry.name],
1978
+ ...pairs.filter(([k]) => k === "ref" || k === "group" || k === "charged"),
1979
+ [outcome, outcome === "fail" ? record([
1980
+ ["code", get("code")],
1981
+ ["message", get("message")],
1982
+ ["data", value]
1983
+ ]) : outcome === "result" || outcome === "value" ? value : outcome === "hostError" ? "" : true]
1984
+ ]);
1985
+ }, {
1986
+ keys: [
1987
+ "ref",
1988
+ "group",
1989
+ "charged",
1990
+ ...outcomes
1991
+ ],
1992
+ toWire: (get) => {
1993
+ let outcome;
1994
+ for (const k of outcomes) if (get(k) !== void 0) {
1995
+ if (outcome !== void 0) return binaryFailure();
1996
+ outcome = k;
1997
+ }
1998
+ if (outcome === void 0) return binaryFailure();
1999
+ const fail = outcome === "fail" ? get("fail") : void 0;
2000
+ const value = fail !== void 0 ? member(fail, "data") : outcome === "result" || outcome === "value" ? get(outcome) : void 0;
2001
+ return (k) => k === "outcome" ? outcome : k === "value" ? value : k === "code" || k === "message" ? member(fail, k) : get(k);
2002
+ }
2003
+ });
2004
+ const need = (entry, reshape) => schema(entry, "need", (get, pairs) => {
2005
+ const inner = pairs.filter(([k]) => k !== "ref" && !notices.includes(k));
2006
+ return new JsonObject([...pairs.filter(([k]) => k === "ref" || notices.includes(k)), ["need", new JsonObject([["m", entry.name], ...reshape ? reshape.fromWire(get, inner) : inner])]]);
2007
+ }, { toWire: reshape?.toWire });
2008
+ const property = {
2009
+ toWire: (get) => (k) => k === "object" ? member(get("object"), "$object") : k === "set" ? get("value") !== void 0 : get(k),
2010
+ fromWire: (get, pairs) => {
2011
+ const set = get("set") === true;
2012
+ const ref = get("object");
2013
+ if (!set && get("value") !== void 0 || ref.length !== 2) return binaryFailure();
2014
+ const ps = pairs.flatMap(([k, v]) => k === "set" ? [] : [[k, k === "object" ? new JsonObject([["$object", v]]) : v]]);
2015
+ if (set && get("value") === void 0) ps.push(["value", null]);
2016
+ return ps;
2017
+ }
2018
+ };
2019
+ const reply = (entry, outer, check) => schema(entry, "reply", (get, pairs) => {
2020
+ const err = get("err");
2021
+ if (!check(get, err !== void 0)) return binaryFailure();
2022
+ return record([...pairs.filter(([k]) => outer.includes(k)), err !== void 0 ? ["err", err] : ["ok", record(pairs.filter(([k]) => !outer.includes(k)))]]);
2023
+ });
2024
+ const schemas = envelopeMessages.map((entry) => {
2025
+ switch (entry.name) {
2026
+ case "op-result": return outcomeResult(entry, [
2027
+ "result",
2028
+ "started",
2029
+ "done",
2030
+ "fail",
2031
+ "limit",
2032
+ "hostError"
2033
+ ]);
2034
+ case "prop-result": return outcomeResult(entry, [
2035
+ "value",
2036
+ "ok",
2037
+ "fail",
2038
+ "hostError"
2039
+ ]);
2040
+ case "admission": return reply(entry, ["ref", ...notices], (get, failed) => failed || get("delivery") !== void 0);
2041
+ case "completion": return reply(entry, [
2042
+ "ref",
2043
+ ...notices,
2044
+ "delivery",
2045
+ "token"
2046
+ ], (get, failed) => get("delivery") === void 0 === (get("token") === void 0) && (failed || get("state") !== void 0 && isJsonNumber(get("fuelUsed")) && get("reports") !== void 0));
2047
+ default: return entry.direction === "guest-to-host" ? need(entry, entry.name === "prop" ? property : void 0) : message(entry);
2048
+ }
2049
+ });
2050
+ const byTag = new Map(schemas.map((s) => [s.tag, s]));
2051
+ const byMethod = new Map(schemas.filter((s) => s.family === "message" || s.family === "result").map((s) => [s.name, s]));
2052
+ const byNeed = new Map(schemas.filter((s) => s.family === "need").map((s) => [s.name, s]));
2053
+ const results = new Map(schemas.filter((s) => s.family === "result").map((s) => [s.name.replace(/-result$/, ""), s]));
2054
+ const integer = (x) => typeof x === "number" && Number.isSafeInteger(x) ? BigInt(x) : isJsonNumber(x) && /^-?\d+$/.test(x.source) ? BigInt(x.source) : binaryFailure();
2055
+ const textItem = (x) => typeof x === "string" ? {
2056
+ tag: 18,
2057
+ data: x
2058
+ } : binaryFailure();
2059
+ const valueOf = (x, o) => Value.isValue(x) ? valueItem(x, o) : jsonValueItem(x, o);
2060
+ const settlementFields = envelopeSettlement.map(({ name, kind }) => [name, kind]);
2061
+ const writeReports = (w, j, o) => {
2062
+ if (!Array.isArray(j)) return binaryFailure();
2063
+ w.output.push(6);
2064
+ w.uint(BigInt(j.length));
2065
+ for (const report of j) {
2066
+ const entry = envelopeReports.find((e) => e.name === field(report, "kind"));
2067
+ if (!entry) return binaryFailure();
2068
+ const keys = entry.fields.map((f) => f.name);
2069
+ if (object(report).pairs.some(([k]) => k !== "kind" && !keys.includes(k))) return binaryFailure();
2070
+ w.output.push(entry.tag, 6);
2071
+ w.uint(BigInt(keys.length));
2072
+ for (const { name, kind } of entry.fields) writeField(w, name, kind, field(report, name), o);
2073
+ }
2074
+ };
2075
+ const writeField = (w, name, kind, x, o) => {
2076
+ if (x === void 0 || x === null) {
2077
+ w.output.push(0);
2078
+ return;
2079
+ }
2080
+ switch (kind) {
2081
+ case "int":
2082
+ case "uint": {
2083
+ const n = integer(x);
2084
+ if (kind === "uint" && n < 0n || name === "token" && n <= 0n) return binaryFailure();
2085
+ return w.item(integerItem(n));
2086
+ }
2087
+ case "bool": return typeof x === "boolean" ? w.output.push(x ? 2 : 1) : binaryFailure();
2088
+ case "instant": {
2089
+ const n = parseInstant(typeof x === "string" ? x : binaryFailure());
2090
+ return w.item({
2091
+ tag: 11,
2092
+ data: n << 1n ^ n >> 63n
2093
+ });
2094
+ }
2095
+ case "text": return w.item(textItem(x));
2096
+ case "texts": return w.item({
2097
+ tag: 6,
2098
+ data: (Array.isArray(x) ? x : binaryFailure()).map(textItem)
2099
+ });
2100
+ case "value": return w.item(valueOf(x, o));
2101
+ case "values": return w.item({
2102
+ tag: 6,
2103
+ data: (Array.isArray(x) ? x : binaryFailure()).map((v) => valueOf(v, o))
2104
+ });
2105
+ case "target":
2106
+ case "message":
2107
+ case "limits":
2108
+ case "err":
2109
+ case "record": return w.item(jsonItem(x, o, name));
2110
+ case "settlements":
2111
+ if (!Array.isArray(x)) return binaryFailure();
2112
+ w.output.push(6);
2113
+ w.uint(BigInt(x.length));
2114
+ for (const settlement of x) {
2115
+ if (object(settlement).pairs.some(([key]) => !settlementFields.some(([name]) => name === key))) return binaryFailure();
2116
+ w.output.push(6);
2117
+ w.uint(BigInt(settlementFields.length));
2118
+ for (const [key, kind] of settlementFields) writeField(w, key, kind, field(settlement, key), o);
2119
+ }
2120
+ return;
2121
+ case "reports": return writeReports(w, x, o);
2122
+ }
2123
+ };
2124
+ const write = (s, get, o) => {
2125
+ const w = new BinaryWriter();
2126
+ w.output.push(...prefix, s.tag, 6);
2127
+ w.uint(BigInt(s.fields.length));
2128
+ const wire = s.toWire ? s.toWire(get) : get;
2129
+ for (const [name, kind] of s.fields) writeField(w, name, kind, wire(name), o);
2130
+ return w.buffer();
2131
+ };
2132
+ /** True before any attempt to interpret a frame as UTF-8 or JSON. */
2133
+ const isRequestPumpBinary = (bytes) => bytes.length >= 3 && bytes[0] === 78 && bytes[1] === 84 && bytes[2] === 66;
2134
+ /** True when a binary frame's tag is a callback need. */
2135
+ const isBinaryNeed = (bytes) => bytes.length > 5 && byTag.get(bytes[5])?.family === "need";
2136
+ const encodeBinaryFrame = (frame, o = {}) => {
2137
+ const m = field(frame, "m");
2138
+ const need = field(frame, "need");
2139
+ const ok = field(frame, "ok");
2140
+ const s = need !== void 0 ? byNeed.get(field(need, "m")) : m !== void 0 ? byMethod.get(m) : field(frame, "token") !== void 0 || isJsonObject(ok) && field(ok, "state") !== void 0 ? byTag.get(130) : byTag.get(129);
2141
+ const inner = need ?? ok;
2142
+ if (!s || [...object(frame).pairs, ...isJsonObject(inner) ? inner.pairs : []].some(([k]) => k !== "m" && k !== "need" && k !== "ok" && !s.keys.has(k))) return binaryFailure();
2143
+ return write(s, (k) => {
2144
+ const j = isJsonObject(inner) ? field(inner, k) : void 0;
2145
+ return j === void 0 ? field(frame, k) : j;
2146
+ }, o);
2147
+ };
2148
+ /**
2149
+ * The binary result answering a callback need, straight from its members:
2150
+ * `answer` holds them as Values and plain data, without `m`, `ref` and
2151
+ * `group`. Undefined when the need has no binary result.
2152
+ */
2153
+ const encodeResult = (need, ref, group, answer, o = {}) => {
2154
+ const s = results.get(need);
2155
+ return s && write(s, (k) => k === "ref" ? ref : k === "group" ? group : answer[k], o);
2156
+ };
2157
+ const readReports = (r, o) => {
2158
+ if (r.byte() !== 6) return binaryFailure();
2159
+ const count = r.count();
2160
+ const reports = [];
2161
+ for (let i = 0; i < count; i++) {
2162
+ const tag = r.byte();
2163
+ const report = envelopeReports.find((e) => e.tag === tag) ?? binaryFailure();
2164
+ if (r.byte() !== 6 || r.uint() !== BigInt(report.fields.length)) return binaryFailure();
2165
+ const ps = [["kind", report.name]];
2166
+ for (const { name, kind } of report.fields) {
2167
+ const item = r.item();
2168
+ if (item.tag !== 0) ps.push([name, readField(item, name, kind, o, (item) => {
2169
+ itemValue(item, metadata(o));
2170
+ return itemJson(item, o, true);
2171
+ })]);
2172
+ }
2173
+ if (report.name === "run end" && ps.some(([k, v]) => k === "outcome" && v === "completed") && !ps.some(([k]) => k === "result")) ps.push(["result", null]);
2174
+ reports.push(new JsonObject(ps));
2175
+ }
2176
+ return reports;
2177
+ };
2178
+ const readField = (item, name, kind, o, value) => {
2179
+ switch (kind) {
2180
+ case "int":
2181
+ case "uint": {
2182
+ const n = itemInteger(item);
2183
+ if (kind === "uint" && n < 0n || name === "token" && n <= 0n) return binaryFailure();
2184
+ return new JsonNumber(n.toString());
2185
+ }
2186
+ case "bool": return item.tag === 1 || item.tag === 2 ? item.tag === 2 : binaryFailure();
2187
+ case "instant": {
2188
+ if (item.tag !== 11) return binaryFailure();
2189
+ const n = item.data;
2190
+ return formatInstant(n >> 1n ^ -(n & 1n));
2191
+ }
2192
+ case "text": return item.tag === 18 ? itemText(item) : binaryFailure();
2193
+ case "texts": return item.tag === 6 ? children(item).map((t) => t.tag === 18 ? itemText(t) : binaryFailure()) : binaryFailure();
2194
+ case "value": return value(item);
2195
+ case "values": return item.tag === 6 ? children(item).map(value) : binaryFailure();
2196
+ case "settlements":
2197
+ if (item.tag !== 6) return binaryFailure();
2198
+ return children(item).map((settlement) => {
2199
+ const xs = children(settlement);
2200
+ if (settlement.tag !== 6 || xs.length !== settlementFields.length) return binaryFailure();
2201
+ const pairs = [];
2202
+ for (const [i, [key, kind]] of settlementFields.entries()) if (xs[i].tag !== 0) pairs.push([key, readField(xs[i], key, kind, o, value)]);
2203
+ const get = (key) => pairs.find(([k]) => k === key)?.[1];
2204
+ if (get("call") === void 0 || !["answer", "fail"].includes(get("outcome"))) return binaryFailure();
2205
+ if (get("value") === void 0) pairs.push(["value", null]);
2206
+ return new JsonObject(pairs);
2207
+ });
2208
+ default: return convert(item, o, name);
2209
+ }
2210
+ };
2211
+ const decode = (buffer, o, value) => {
2212
+ const r = new BinaryReader(new Uint8Array(buffer));
2213
+ for (const b of prefix) if (r.byte() !== b) binaryFailure();
2214
+ const s = byTag.get(r.byte()) ?? binaryFailure();
2215
+ if (r.byte() !== 6 || r.uint() !== BigInt(s.fields.length)) binaryFailure();
2216
+ const pairs = [];
2217
+ for (const [name, kind] of s.fields) {
2218
+ if (kind === "reports" && r.data[r.at] !== 0) {
2219
+ pairs.push([name, readReports(r, o)]);
2220
+ continue;
2221
+ }
2222
+ const item = r.item();
2223
+ if (item.tag !== 0) pairs.push([name, readField(item, name, kind, o, value)]);
2224
+ }
2225
+ r.done();
2226
+ const get = (k) => pairs.find(([key]) => key === k)?.[1];
2227
+ if (s.required.some((k) => get(k) === void 0)) return binaryFailure();
2228
+ return s.fromWire(get, pairs);
2229
+ };
2230
+ const decodeBinaryFrame = (buffer, o = {}) => {
2231
+ const meta = metadata(o);
2232
+ return decode(buffer, o, (item) => {
2233
+ itemValue(item, meta);
2234
+ return itemJson(item, o, true);
2235
+ });
2236
+ };
2237
+ /**
2238
+ * A callback need's packet, each Value decoded once under `o`'s Object and
2239
+ * Function hooks and held in a `valueNode`.
2240
+ */
2241
+ const decodeNeed = (buffer, o) => {
2242
+ if (!isBinaryNeed(new Uint8Array(buffer, 0, Math.min(6, buffer.byteLength)))) return binaryFailure();
2243
+ return decode(buffer, o, (item) => valueNode(itemValue(item, o)));
2244
+ };
2245
+ //#endregion
2246
+ export { encodeResult as a, isRequestPumpBinary as c, valueNode as d, decodeBinaryValue as f, encodeBinaryFrame as i, placeholderValues as l, decodeBinaryFrame as n, heldValue as o, encodeBinaryValue as p, decodeNeed as r, isBinaryNeed as s, callbacksFeature as t, requestPumpFeature as u };