@almadar/shell-runtime 0.1.0 → 1.1.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 (167) hide show
  1. package/dist/chunk-2WCVOMZ2.js +112 -0
  2. package/dist/chunk-57SBCUSM.js +62 -0
  3. package/dist/{chunk-Q2H75UYT.js → chunk-A2JJT4GA.js} +1 -37
  4. package/dist/chunk-BAS26HBN.js +10 -0
  5. package/dist/{chunk-REPX5QPI.js → chunk-BOVU4TCQ.js} +11 -3
  6. package/dist/chunk-BY5G4225.js +6 -0
  7. package/dist/chunk-DFDNHVDW.js +284 -0
  8. package/dist/{chunk-NATGCIVM.js → chunk-JVSREWQO.js} +378 -130
  9. package/dist/{chunk-DYOJGLIX.js → chunk-LKWYCYX5.js} +2 -5
  10. package/dist/chunk-LYFIQPXX.js +1 -0
  11. package/dist/{chunk-ODJCZ27I.js → chunk-N7HYNKK6.js} +35 -2
  12. package/dist/{chunk-4J2QEIUV.js → chunk-NTFQ36UN.js} +4 -30
  13. package/dist/chunk-NU6LVKGS.js +15 -0
  14. package/dist/{chunk-VNMG7NKY.js → chunk-OQVSN7DP.js} +21 -26
  15. package/dist/chunk-P2N6K2IV.js +20 -0
  16. package/dist/{chunk-QQRDUMB2.js → chunk-QCJWPXLH.js} +11 -11
  17. package/dist/{chunk-QELZ6TEJ.js → chunk-UD2CXYSJ.js} +39 -3
  18. package/dist/{chunk-UJHOUZAL.js → chunk-V4EMDPCO.js} +2 -5
  19. package/dist/chunk-VKQA2DJX.js +409 -0
  20. package/dist/chunk-VNGXRYFF.js +9 -0
  21. package/dist/{chunk-HNOAZWFH.js → chunk-WGCWJOT2.js} +2 -0
  22. package/dist/chunk-XZGVOBY6.js +33 -0
  23. package/dist/chunk-ZUSM4VW4.js +197 -0
  24. package/dist/client/EventTransport.d.ts +23 -7
  25. package/dist/client/EventTransport.js +1 -2
  26. package/dist/client/awaiting.js +0 -1
  27. package/dist/client/channel-transport.d.ts +6 -6
  28. package/dist/client/channel-transport.js +0 -1
  29. package/dist/client/circuit-store.d.ts +16 -5
  30. package/dist/client/circuit-store.js +2 -3
  31. package/dist/client/client-kernel.d.ts +36 -15
  32. package/dist/client/declared-input-dispatch.d.ts +19 -2
  33. package/dist/client/declared-input-dispatch.js +1 -2
  34. package/dist/client/inbound-dispatch.d.ts +21 -2
  35. package/dist/client/inbound-dispatch.js +1 -2
  36. package/dist/client/local-fold.d.ts +15 -8
  37. package/dist/client/local-fold.js +1 -2
  38. package/dist/client/render-sigils.js +0 -1
  39. package/dist/client/state-book.d.ts +9 -16
  40. package/dist/client/state-book.js +1 -2
  41. package/dist/client/trait-mount-error.js +0 -1
  42. package/dist/credentials/env-vars.d.ts +5 -1
  43. package/dist/credentials/env-vars.js +1 -3
  44. package/dist/credentials/scope.d.ts +8 -7
  45. package/dist/credentials/scope.js +0 -1
  46. package/dist/credentials/vault.d.ts +142 -0
  47. package/dist/credentials/vault.js +1 -0
  48. package/dist/effects/in-flight-calls.js +0 -1
  49. package/dist/effects/on-device-model.js +0 -1
  50. package/dist/events/EventBus.d.ts +1 -4
  51. package/dist/events/EventBus.js +0 -1
  52. package/dist/events/emit-stamp.js +0 -1
  53. package/dist/index.d.ts +25 -42
  54. package/dist/index.js +27 -45
  55. package/dist/kernel/decode.d.ts +10 -10
  56. package/dist/kernel/decode.js +1 -2
  57. package/dist/kernel/engine.d.ts +133 -31
  58. package/dist/kernel/engine.js +7 -9
  59. package/dist/kernel/frame-applier.d.ts +8 -7
  60. package/dist/kernel/frame-applier.js +1 -2
  61. package/dist/kernel/host.d.ts +148 -16
  62. package/dist/kernel/host.js +4 -7
  63. package/dist/kernel/lane.d.ts +1 -22
  64. package/dist/kernel/lane.js +1 -2
  65. package/dist/kernel/os-fetch-port.d.ts +7 -0
  66. package/dist/kernel/os-fetch-port.js +3 -0
  67. package/dist/kernel/os-port.d.ts +30 -8
  68. package/dist/kernel/os-port.js +1 -2
  69. package/dist/kernel/program-effects.d.ts +11 -28
  70. package/dist/kernel/program-effects.js +1 -2
  71. package/dist/kernel/secret-ports.d.ts +139 -0
  72. package/dist/kernel/secret-ports.js +2 -0
  73. package/dist/kernel/wire.d.ts +113 -12
  74. package/dist/loader/fetch-loader.d.ts +26 -0
  75. package/dist/loader/fetch-loader.js +1 -0
  76. package/dist/loader/lazy-page.js +0 -1
  77. package/dist/loader/schema-loader.d.ts +1 -17
  78. package/dist/persistence/native-memory.js +0 -1
  79. package/dist/runtime/entities/declaredCollections.d.ts +6 -0
  80. package/dist/runtime/entities/declaredCollections.js +1 -0
  81. package/dist/runtime/evaluation/local-store-transport.d.ts +16 -23
  82. package/dist/runtime/evaluation/local-store-transport.js +9 -13
  83. package/dist/runtime/evaluation/residence-transport.d.ts +3 -3
  84. package/dist/runtime/evaluation/residence-transport.js +1 -2
  85. package/dist/runtime/evaluation/routed-persistence.js +0 -1
  86. package/dist/runtime/events/identity/routing.d.ts +2 -53
  87. package/dist/runtime/events/identity/routing.js +1 -2
  88. package/dist/runtime/types.d.ts +5 -205
  89. package/dist/runtime/types.js +1 -2
  90. package/dist/service/default-call-service.js +0 -1
  91. package/dist/service/service-provider.js +0 -1
  92. package/package.json +8 -5
  93. package/dist/chunk-2JU7Y4KU.js +0 -21
  94. package/dist/chunk-46RWK2B5.js +0 -28
  95. package/dist/chunk-4ZICQ5PM.js +0 -192
  96. package/dist/chunk-53IPZXDP.js +0 -76
  97. package/dist/chunk-5D63EMO5.js +0 -16
  98. package/dist/chunk-CPSQXEJ6.js +0 -55
  99. package/dist/chunk-CQP5XAX6.js +0 -173
  100. package/dist/chunk-CROS2GEX.js +0 -49
  101. package/dist/chunk-D4XJTBLB.js +0 -217
  102. package/dist/chunk-D5USD2EX.js +0 -232
  103. package/dist/chunk-EV56K4GB.js +0 -63
  104. package/dist/chunk-FQ6IZMIU.js +0 -10
  105. package/dist/chunk-HMK6YMQS.js +0 -135
  106. package/dist/chunk-IHQLE5M7.js +0 -62
  107. package/dist/chunk-JFWFDUTR.js +0 -35
  108. package/dist/chunk-MHYSHSRG.js +0 -54
  109. package/dist/chunk-MLKGABMK.js +0 -7
  110. package/dist/chunk-NAECVIAR.js +0 -322
  111. package/dist/chunk-Q7JK4KY7.js +0 -9
  112. package/dist/chunk-RBUMDYFS.js +0 -681
  113. package/dist/chunk-SAS5KKCR.js +0 -43
  114. package/dist/chunk-SWPDU752.js +0 -28
  115. package/dist/chunk-T775TUCD.js +0 -18
  116. package/dist/chunk-VMOBW7RK.js +0 -21
  117. package/dist/chunk-WNPNNYXY.js +0 -22
  118. package/dist/chunk-XB5GYODW.js +0 -28
  119. package/dist/chunk-YL2SO5TP.js +0 -334
  120. package/dist/chunk-YO4LWS3I.js +0 -606
  121. package/dist/chunk-ZAQSS47X.js +0 -157
  122. package/dist/chunk-ZCQUUJIF.js +0 -129
  123. package/dist/client/ServerBridge.d.ts +0 -126
  124. package/dist/client/ServerBridge.js +0 -3
  125. package/dist/credentials/seed.d.ts +0 -21
  126. package/dist/credentials/seed.js +0 -2
  127. package/dist/credentials/store.d.ts +0 -110
  128. package/dist/credentials/store.js +0 -2
  129. package/dist/index-hT1xCdTq.d.ts +0 -46
  130. package/dist/kernel/beacon.d.ts +0 -32
  131. package/dist/kernel/beacon.js +0 -2
  132. package/dist/kernel/http.d.ts +0 -302
  133. package/dist/kernel/http.js +0 -6
  134. package/dist/kernel/oauth-effects.d.ts +0 -25
  135. package/dist/kernel/oauth-effects.js +0 -7
  136. package/dist/kernel/oauth-port.d.ts +0 -31
  137. package/dist/kernel/oauth-port.js +0 -2
  138. package/dist/loader/http-loader.d.ts +0 -111
  139. package/dist/loader/http-loader.js +0 -2
  140. package/dist/runtime/effects/composition/compose-behaviors.d.ts +0 -58
  141. package/dist/runtime/effects/composition/compose-behaviors.js +0 -4
  142. package/dist/runtime/effects/composition/event-wiring.d.ts +0 -38
  143. package/dist/runtime/effects/composition/event-wiring.js +0 -2
  144. package/dist/runtime/effects/composition/index.d.ts +0 -5
  145. package/dist/runtime/effects/composition/index.js +0 -6
  146. package/dist/runtime/effects/composition/layout-strategy.d.ts +0 -35
  147. package/dist/runtime/effects/composition/layout-strategy.js +0 -2
  148. package/dist/runtime/effects/composition/pipe.d.ts +0 -25
  149. package/dist/runtime/effects/composition/pipe.js +0 -2
  150. package/dist/runtime/entities/mockStoreSeed.d.ts +0 -56
  151. package/dist/runtime/entities/mockStoreSeed.js +0 -3
  152. package/dist/runtime/entities/seedBrowserStore.d.ts +0 -28
  153. package/dist/runtime/entities/seedBrowserStore.js +0 -2
  154. package/dist/runtime/entities/std-mock-seed.d.ts +0 -87
  155. package/dist/runtime/entities/std-mock-seed.js +0 -2
  156. package/dist/runtime/time/TickScheduler.d.ts +0 -77
  157. package/dist/runtime/time/TickScheduler.js +0 -3
  158. package/dist/runtime/time/cron.d.ts +0 -25
  159. package/dist/runtime/time/cron.js +0 -2
  160. package/dist/runtime/time/duration.d.ts +0 -20
  161. package/dist/runtime/time/duration.js +0 -2
  162. package/dist/runtime/traits/OrbitalTraitParsing.d.ts +0 -34
  163. package/dist/runtime/traits/OrbitalTraitParsing.js +0 -2
  164. package/dist/runtime/traits/listen-targets.d.ts +0 -16
  165. package/dist/runtime/traits/listen-targets.js +0 -3
  166. package/dist/runtime/traits/trait-index.d.ts +0 -35
  167. package/dist/runtime/traits/trait-index.js +0 -3
@@ -1,681 +0,0 @@
1
- import { isEventResponse } from '@almadar/core/kernel-wire';
2
- import { RowCommitSchema, RowWriteBatchSchema, RowQuerySchema, isJsonObject } from '@almadar/core';
3
-
4
- // src/kernel/decode.ts
5
- function isRecord(value) {
6
- return typeof value === "object" && value !== null && !Array.isArray(value);
7
- }
8
- function field(record, name) {
9
- const value = record[name];
10
- if (value === void 0) throw new Error(`kernel wire: "${name}" is missing`);
11
- return value;
12
- }
13
- function text(record, name) {
14
- const value = field(record, name);
15
- if (typeof value !== "string") throw new Error(`kernel wire: "${name}" is not a string`);
16
- return value;
17
- }
18
- function whole(record, name) {
19
- const value = field(record, name);
20
- if (typeof value !== "number" || !Number.isInteger(value)) throw new Error(`kernel wire: "${name}" is not an integer`);
21
- return value;
22
- }
23
- function list(record, name) {
24
- const value = field(record, name);
25
- if (!Array.isArray(value)) throw new Error(`kernel wire: "${name}" is not a list`);
26
- return value;
27
- }
28
- function optionalText(record, name) {
29
- return record[name] === void 0 ? void 0 : text(record, name);
30
- }
31
- function decodeSite(value) {
32
- if (!isRecord(value)) throw new Error('kernel wire: "site" is not an object');
33
- const orbital = optionalText(value, "orbital");
34
- const emit = field(value, "emit");
35
- if (!isRecord(emit)) throw new Error('kernel wire: "emit" is not an object');
36
- const success = optionalText(emit, "success");
37
- const failure = optionalText(emit, "failure");
38
- const cancelled = optionalText(emit, "cancelled");
39
- const onMessage = optionalText(emit, "onMessage");
40
- const followOn = field(value, "followOn");
41
- if (typeof followOn !== "boolean") throw new Error('kernel wire: "followOn" is not a boolean');
42
- return {
43
- ...orbital !== void 0 ? { orbital } : {},
44
- trait: text(value, "trait"),
45
- ...optionalText(value, "entityId") !== void 0 ? { entityId: optionalText(value, "entityId") } : {},
46
- followOn,
47
- emit: {
48
- ...success !== void 0 ? { success } : {},
49
- ...failure !== void 0 ? { failure } : {},
50
- ...cancelled !== void 0 ? { cancelled } : {},
51
- ...onMessage !== void 0 ? { onMessage } : {}
52
- }
53
- };
54
- }
55
- function headerPairs(record, name) {
56
- return list(record, name).map((pair) => {
57
- const [headerName, headerValue, ...rest] = Array.isArray(pair) ? pair : [];
58
- if (typeof headerName !== "string" || typeof headerValue !== "string" || rest.length > 0) {
59
- throw new Error(`kernel wire: "${name}" holds a header that is not a [name, value] pair`);
60
- }
61
- return [headerName, headerValue];
62
- });
63
- }
64
- function decodeHttpBody(value) {
65
- if (!isRecord(value)) throw new Error("kernel wire: an http body is not an object");
66
- const kind = text(value, "kind");
67
- switch (kind) {
68
- case "empty":
69
- return { kind };
70
- case "text":
71
- return { kind, text: text(value, "text") };
72
- case "base64":
73
- return { kind, data: text(value, "data") };
74
- default:
75
- throw new Error(`kernel wire: unknown http body kind "${kind}"`);
76
- }
77
- }
78
- function decodeHttpRequest(value) {
79
- if (!isRecord(value)) throw new Error("kernel wire: an http request is not an object");
80
- const timeoutMs = value.timeoutMs;
81
- if (timeoutMs !== void 0 && (typeof timeoutMs !== "number" || !Number.isInteger(timeoutMs) || timeoutMs < 0)) {
82
- throw new Error('kernel wire: "timeoutMs" is not a non-negative integer');
83
- }
84
- return {
85
- method: text(value, "method"),
86
- url: text(value, "url"),
87
- headers: headerPairs(value, "headers"),
88
- body: decodeHttpBody(field(value, "body")),
89
- ...timeoutMs !== void 0 ? { timeoutMs } : {}
90
- };
91
- }
92
- function decodeHttpResponse(value) {
93
- if (!isRecord(value)) throw new Error("kernel wire: an http response is not an object");
94
- const status = whole(value, "status");
95
- return { status, headers: headerPairs(value, "headers"), body: decodeHttpBody(field(value, "body")) };
96
- }
97
- var OS_OPS = [
98
- "os/read-file",
99
- "os/write-file",
100
- "os/append-file",
101
- "os/open",
102
- "os/close",
103
- "os/read",
104
- "os/write",
105
- "os/seek",
106
- "os/truncate",
107
- "os/fsync",
108
- "os/copy",
109
- "os/rename",
110
- "os/remove",
111
- "os/link",
112
- "os/symlink",
113
- "os/readlink",
114
- "os/watch-files",
115
- "os/mkdir",
116
- "os/rmdir",
117
- "os/list-dir",
118
- "os/glob",
119
- "os/mktemp",
120
- "os/realpath",
121
- "os/cwd",
122
- "os/chdir",
123
- "os/stat",
124
- "os/lstat",
125
- "os/access",
126
- "os/exists",
127
- "os/chmod",
128
- "os/chown",
129
- "os/utimes",
130
- "os/spawn",
131
- "os/wait",
132
- "os/kill",
133
- "os/pid",
134
- "os/ppid",
135
- "os/watch-process",
136
- "os/watch-signal",
137
- "os/getenv",
138
- "os/setenv",
139
- "os/unsetenv",
140
- "os/environ",
141
- "os/watch-env",
142
- "os/stdin-read",
143
- "os/stdout-write",
144
- "os/stderr-write",
145
- "os/isatty",
146
- "os/tty-size",
147
- "os/tcp-connect",
148
- "os/tcp-listen",
149
- "os/send",
150
- "os/recv",
151
- "os/udp-bind",
152
- "os/sendto",
153
- "os/recvfrom",
154
- "os/dns-resolve",
155
- "os/shutdown",
156
- "os/watch-port",
157
- "os/clock-monotonic",
158
- "os/uid",
159
- "os/gid",
160
- "os/username",
161
- "os/group-of",
162
- "os/watch-cron",
163
- "os/cpu-usage",
164
- "os/memory-info",
165
- "os/uptime",
166
- "os/load-avg",
167
- "os/hostname",
168
- "os/uname",
169
- "os/disk-usage",
170
- "os/mounts",
171
- "os/disk-io",
172
- "os/network-interfaces",
173
- "os/network-stats",
174
- "os/network-connected",
175
- "os/default-gateway",
176
- "os/battery-status",
177
- "os/ac-power",
178
- "os/thermal-zones",
179
- "os/notify",
180
- "os/speak",
181
- "os/brightness-get",
182
- "os/brightness-set",
183
- "os/volume-get",
184
- "os/volume-set",
185
- "os/volume-mute",
186
- "os/suspend",
187
- "os/hibernate"
188
- ];
189
- function osOp(record, name) {
190
- const raw = text(record, name);
191
- const found = OS_OPS.find((op) => op === raw);
192
- if (found === void 0) throw new Error(`kernel wire: unknown os op "${raw}"`);
193
- return found;
194
- }
195
- var REQUEST_KINDS = {
196
- readRow: true,
197
- listRows: true,
198
- queryRows: true,
199
- writeRows: true,
200
- commitRows: true,
201
- createRow: true,
202
- writeRow: true,
203
- deleteRow: true,
204
- callService: true,
205
- cancelCall: true,
206
- substrate: true,
207
- http: true,
208
- httpStream: true,
209
- httpBeacon: true,
210
- pageFacts: true,
211
- prompt: true,
212
- embed: true,
213
- tab: true,
214
- secret: true,
215
- secretSet: true,
216
- secretRotate: true,
217
- oauth: true,
218
- deliver: true,
219
- random: true,
220
- os: true,
221
- credentialStatus: true,
222
- credentialForget: true,
223
- clock: true,
224
- credentialStoreList: true,
225
- credentialStoreRead: true,
226
- credentialStoreWrite: true,
227
- credentialStoreRemove: true,
228
- credentialStoreRotate: true,
229
- credentialModeRead: true,
230
- credentialModeWrite: true
231
- };
232
- function isRequestKind(raw) {
233
- return Object.prototype.hasOwnProperty.call(REQUEST_KINDS, raw);
234
- }
235
- function assertNever(value) {
236
- throw new Error(`kernel wire: unhandled request kind "${String(value)}"`);
237
- }
238
- function decodeInstanceRef(value) {
239
- if (!isRecord(value)) throw new Error("kernel wire: an instance reference is not an object");
240
- const trait = optionalText(value, "trait");
241
- return { instance: text(value, "instance"), orbital: text(value, "orbital"), ...trait !== void 0 ? { trait } : {} };
242
- }
243
- function decodeEnvelope(value) {
244
- if (!isRecord(value)) throw new Error("kernel wire: an envelope is not an object");
245
- return {
246
- id: text(value, "id"),
247
- from: decodeInstanceRef(field(value, "from")),
248
- to: decodeInstanceRef(field(value, "to")),
249
- event: text(value, "event"),
250
- payload: field(value, "payload"),
251
- causalId: text(value, "causalId"),
252
- hop: whole(value, "hop")
253
- };
254
- }
255
- function optionalFlag(record, name) {
256
- const value = record[name];
257
- if (value === void 0) return void 0;
258
- if (typeof value !== "boolean") throw new Error(`kernel wire: "${name}" is not a boolean`);
259
- return value;
260
- }
261
- function optionalWhole(record, name) {
262
- return record[name] === void 0 ? void 0 : whole(record, name);
263
- }
264
- function tabRecord(value, what) {
265
- if (!isRecord(value)) throw new Error(`kernel wire: ${what} is not an object`);
266
- return value;
267
- }
268
- function decodeTabField(value) {
269
- const entry = tabRecord(value, "a tab field");
270
- const selector = optionalText(entry, "selector");
271
- const attr = optionalText(entry, "attr");
272
- const template = optionalText(entry, "template");
273
- const resolve = optionalFlag(entry, "resolve");
274
- const required = optionalFlag(entry, "required");
275
- return {
276
- name: text(entry, "name"),
277
- ...selector !== void 0 ? { selector } : {},
278
- ...attr !== void 0 ? { attr } : {},
279
- ...resolve !== void 0 ? { resolve } : {},
280
- ...template !== void 0 ? { template } : {},
281
- ...required !== void 0 ? { required } : {}
282
- };
283
- }
284
- function decodeTabApply(entry) {
285
- const label = optionalText(entry, "label");
286
- return {
287
- elementId: text(entry, "elementId"),
288
- styles: list(entry, "styles").map((style) => {
289
- const record = tabRecord(style, "a tab style");
290
- return { property: text(record, "property"), value: text(record, "value") };
291
- }),
292
- ...label !== void 0 ? { label } : {}
293
- };
294
- }
295
- function tabAction(entry) {
296
- const raw = text(entry, "action");
297
- if (raw === "click" || raw === "focus" || raw === "type") return raw;
298
- throw new Error(`kernel wire: unknown tab action "${raw}"`);
299
- }
300
- function decodeTabCommand(value) {
301
- const entry = tabRecord(value, "a tab command");
302
- const kind = text(entry, "kind");
303
- switch (kind) {
304
- case "query": {
305
- const limit = optionalWhole(entry, "limit");
306
- const waitMs = optionalWhole(entry, "waitMs");
307
- return {
308
- kind,
309
- selector: text(entry, "selector"),
310
- fields: list(entry, "fields").map(decodeTabField),
311
- ...limit !== void 0 ? { limit } : {},
312
- ...waitMs !== void 0 ? { waitMs } : {}
313
- };
314
- }
315
- case "watch":
316
- return { kind, watchId: text(entry, "watchId"), selector: text(entry, "selector"), fields: list(entry, "fields").map(decodeTabField) };
317
- case "unwatch":
318
- return { kind, watchId: text(entry, "watchId") };
319
- case "apply":
320
- return { kind, ...decodeTabApply(entry) };
321
- case "applyMany":
322
- return { kind, items: list(entry, "items").map((item) => decodeTabApply(tabRecord(item, "a tab treatment"))) };
323
- case "act": {
324
- const typed = optionalText(entry, "text");
325
- return { kind, elementId: text(entry, "elementId"), action: tabAction(entry), ...typed !== void 0 ? { text: typed } : {} };
326
- }
327
- default:
328
- throw new Error(`kernel wire: unknown tab command "${kind}"`);
329
- }
330
- }
331
- function decodeTabAsk(value) {
332
- const entry = tabRecord(value, "a tab ask");
333
- const kind = text(entry, "kind");
334
- switch (kind) {
335
- case "list":
336
- return { kind };
337
- case "open": {
338
- const active = optionalFlag(entry, "active");
339
- if (active === void 0) throw new Error('kernel wire: "active" is missing');
340
- return { kind, url: text(entry, "url"), active };
341
- }
342
- case "close":
343
- return { kind, tab: whole(entry, "tab") };
344
- case "navigate":
345
- return { kind, tab: whole(entry, "tab"), url: text(entry, "url") };
346
- case "command":
347
- return { kind, tab: whole(entry, "tab"), command: decodeTabCommand(field(entry, "command")) };
348
- case "awaitReady":
349
- return { kind, tab: whole(entry, "tab"), timeoutMs: whole(entry, "timeoutMs") };
350
- case "watch": {
351
- const deliver = tabRecord(field(entry, "deliver"), "a tab delivery");
352
- return {
353
- kind,
354
- watchId: text(entry, "watchId"),
355
- match: text(entry, "match"),
356
- selector: text(entry, "selector"),
357
- fields: list(entry, "fields").map(decodeTabField),
358
- deliver: { orbital: text(deliver, "orbital"), trait: text(deliver, "trait"), event: text(deliver, "event") }
359
- };
360
- }
361
- case "unwatch":
362
- return { kind, watchId: text(entry, "watchId") };
363
- case "capture": {
364
- const format = text(entry, "format");
365
- if (format !== "png" && format !== "jpeg") throw new Error(`kernel wire: unknown capture format "${format}"`);
366
- const quality = "quality" in entry ? whole(entry, "quality") : void 0;
367
- return { kind, tab: whole(entry, "tab"), format, ...quality !== void 0 ? { quality } : {} };
368
- }
369
- default:
370
- throw new Error(`kernel wire: unknown tab ask "${kind}"`);
371
- }
372
- }
373
- function pageFactField(entry) {
374
- if (entry === "hostname" || entry === "referrer" || entry === "screenWidth") return entry;
375
- throw new Error('kernel wire: "fields" holds an unknown page fact');
376
- }
377
- function decodeRequest(value) {
378
- if (!isRecord(value)) throw new Error("kernel wire: a request is not an object");
379
- const rawKind = text(value, "kind");
380
- if (!isRequestKind(rawKind)) throw new Error(`kernel wire: unknown request kind "${rawKind}"`);
381
- const kind = rawKind;
382
- switch (kind) {
383
- case "readRow":
384
- return { kind, entityType: text(value, "entityType"), id: text(value, "id") };
385
- case "listRows":
386
- return { kind, entityType: text(value, "entityType") };
387
- case "queryRows": {
388
- const project = text(value, "project");
389
- if (project !== "rows" && project !== "ids") throw new Error(`kernel wire: unknown projection "${project}"`);
390
- return { kind, entityType: text(value, "entityType"), query: RowQuerySchema.parse(field(value, "query")), project };
391
- }
392
- case "writeRows":
393
- return { kind, batch: RowWriteBatchSchema.parse(field(value, "batch")) };
394
- case "commitRows":
395
- return { kind, rows: RowCommitSchema.array().parse(field(value, "rows")) };
396
- case "createRow":
397
- return { kind, entityType: text(value, "entityType"), data: field(value, "data") };
398
- case "writeRow":
399
- return { kind, entityType: text(value, "entityType"), id: text(value, "id"), data: field(value, "data") };
400
- case "deleteRow":
401
- return { kind, entityType: text(value, "entityType"), id: text(value, "id") };
402
- case "callService": {
403
- const key = optionalText(value, "key");
404
- const rawCaller = value.caller;
405
- let caller;
406
- if (rawCaller !== void 0) {
407
- if (!isRecord(rawCaller)) throw new Error('kernel wire: "caller" is not an object');
408
- const role = optionalText(rawCaller, "role");
409
- caller = { principal: text(rawCaller, "principal"), ...role !== void 0 ? { role } : {} };
410
- }
411
- const rawSite = value.site;
412
- return {
413
- kind,
414
- service: text(value, "service"),
415
- method: text(value, "method"),
416
- args: field(value, "args"),
417
- ...key !== void 0 ? { key } : {},
418
- ...caller !== void 0 ? { caller } : {},
419
- ...rawSite !== void 0 ? { site: decodeSite(rawSite) } : {}
420
- };
421
- }
422
- case "cancelCall":
423
- return { kind, key: text(value, "key") };
424
- case "substrate": {
425
- const key = optionalText(value, "key");
426
- const site = value.site;
427
- return { kind, op: text(value, "op"), args: list(value, "args"), ...key !== void 0 ? { key } : {}, ...site !== void 0 ? { site: decodeSite(site) } : {} };
428
- }
429
- case "http": {
430
- const key = optionalText(value, "key");
431
- const rawSite = value.site;
432
- const delayMs = value.delayMs;
433
- if (delayMs !== void 0 && (typeof delayMs !== "number" || !Number.isInteger(delayMs) || delayMs < 0)) {
434
- throw new Error('kernel wire: "delayMs" is not a non-negative integer');
435
- }
436
- return {
437
- kind,
438
- request: decodeHttpRequest(field(value, "request")),
439
- ...delayMs !== void 0 ? { delayMs } : {},
440
- ...key !== void 0 ? { key } : {},
441
- ...rawSite !== void 0 ? { site: decodeSite(rawSite) } : {}
442
- };
443
- }
444
- case "httpStream": {
445
- const key = optionalText(value, "key");
446
- const framing = text(value, "framing");
447
- if (framing !== "sse" && framing !== "jsonLines") throw new Error(`kernel wire: unknown stream framing "${framing}"`);
448
- const rawSite = value.site;
449
- return {
450
- kind,
451
- request: decodeHttpRequest(field(value, "request")),
452
- framing,
453
- ...key !== void 0 ? { key } : {},
454
- ...rawSite !== void 0 ? { site: decodeSite(rawSite) } : {}
455
- };
456
- }
457
- case "prompt": {
458
- const key = optionalText(value, "key");
459
- return { kind, text: text(value, "text"), schema: text(value, "schema"), ...key !== void 0 ? { key } : {} };
460
- }
461
- case "embed": {
462
- const key = optionalText(value, "key");
463
- const texts = list(value, "texts").map((entry) => {
464
- if (typeof entry !== "string") throw new Error('kernel wire: "texts" holds a non-string');
465
- return entry;
466
- });
467
- return { kind, texts, ...key !== void 0 ? { key } : {} };
468
- }
469
- case "tab": {
470
- const key = optionalText(value, "key");
471
- return { kind, ask: decodeTabAsk(field(value, "ask")), ...key !== void 0 ? { key } : {} };
472
- }
473
- case "secret": {
474
- const principal = optionalText(value, "principal");
475
- return { kind, name: text(value, "name"), ...principal !== void 0 ? { principal } : {} };
476
- }
477
- case "secretSet": {
478
- const principal = optionalText(value, "principal");
479
- return { kind, name: text(value, "name"), value: text(value, "value"), ttlMs: whole(value, "ttlMs"), ...principal !== void 0 ? { principal } : {} };
480
- }
481
- case "secretRotate": {
482
- const principal = optionalText(value, "principal");
483
- return { kind, name: text(value, "name"), value: text(value, "value"), ...principal !== void 0 ? { principal } : {} };
484
- }
485
- case "random":
486
- return { kind, bytes: whole(value, "bytes") };
487
- case "clock":
488
- return { kind };
489
- case "os": {
490
- const key = optionalText(value, "key");
491
- const rawSite = value.site;
492
- return {
493
- kind,
494
- op: osOp(value, "op"),
495
- args: list(value, "args"),
496
- ...key !== void 0 ? { key } : {},
497
- ...rawSite !== void 0 ? { site: decodeSite(rawSite) } : {}
498
- };
499
- }
500
- case "oauth": {
501
- const principal = optionalText(value, "principal");
502
- return { kind, ask: decodeOAuthAsk(field(value, "ask")), ...principal !== void 0 ? { principal } : {} };
503
- }
504
- case "credentialStatus":
505
- case "credentialForget": {
506
- const principal = optionalText(value, "principal");
507
- return { kind, name: text(value, "name"), ...principal !== void 0 ? { principal } : {} };
508
- }
509
- case "credentialStoreList":
510
- case "credentialStoreRotate":
511
- case "credentialModeRead":
512
- return { kind };
513
- case "credentialStoreRead":
514
- case "credentialStoreRemove":
515
- return { kind, name: text(value, "name") };
516
- case "credentialStoreWrite":
517
- return { kind, service: text(value, "service"), name: text(value, "name"), value: text(value, "value") };
518
- case "credentialModeWrite":
519
- return { kind, mode: text(value, "mode") };
520
- case "httpBeacon": {
521
- const key = optionalText(value, "key");
522
- const rawSite = value.site;
523
- return {
524
- kind,
525
- request: decodeHttpRequest(field(value, "request")),
526
- ...key !== void 0 ? { key } : {},
527
- ...rawSite !== void 0 ? { site: decodeSite(rawSite) } : {}
528
- };
529
- }
530
- case "pageFacts":
531
- return { kind, fields: list(value, "fields").map(pageFactField) };
532
- case "deliver": {
533
- const key = optionalText(value, "key");
534
- return { kind, envelope: decodeEnvelope(field(value, "envelope")), ...key !== void 0 ? { key } : {}, site: decodeSite(field(value, "site")) };
535
- }
536
- default:
537
- return assertNever(kind);
538
- }
539
- }
540
- function decodePending(value) {
541
- if (!isRecord(value)) throw new Error("kernel wire: a pending request is not an object");
542
- return { id: whole(value, "id"), request: decodeRequest(field(value, "request")) };
543
- }
544
- function withSharedEffects(response) {
545
- const frames = response.clientEffectsByTrait;
546
- if (frames === void 0 || response.clientEffects?.length !== frames.length) return response;
547
- return { ...response, clientEffects: frames.map((frame) => frame.effect) };
548
- }
549
- function decodeProgress(json) {
550
- const value = JSON.parse(json);
551
- if (!isRecord(value)) throw new Error("kernel wire: progress is not an object");
552
- const status = text(value, "status");
553
- if (status === "done") {
554
- const response = field(value, "response");
555
- if (!isEventResponse(response)) throw new Error('kernel wire: "response" is not an event response');
556
- return { status, response: withSharedEffects(response) };
557
- }
558
- if (status === "await") {
559
- return { status, flight: whole(value, "flight"), requests: list(value, "requests").map(decodePending) };
560
- }
561
- throw new Error(`kernel wire: unknown status "${status}"`);
562
- }
563
- function decodeResolveProgress(json) {
564
- const value = JSON.parse(json);
565
- if (!isRecord(value)) throw new Error("kernel wire: resolve progress is not an object");
566
- const status = text(value, "status");
567
- if (status === "done") {
568
- const rows = list(value, "rows").map((row) => {
569
- if (!isRecord(row)) throw new Error("kernel wire: a resolved row is not an object");
570
- return row;
571
- });
572
- const total = field(value, "total");
573
- if (typeof total !== "number") throw new Error('kernel wire: "total" is not a number');
574
- return { status, rows, total };
575
- }
576
- if (status === "await") {
577
- return { status, flight: whole(value, "flight"), requests: list(value, "requests").map(decodePending) };
578
- }
579
- throw new Error(`kernel wire: unknown status "${status}"`);
580
- }
581
- function recordOf(value, what) {
582
- if (value === void 0 || !isJsonObject(value)) throw new Error(`${what} is not an object`);
583
- return value;
584
- }
585
- function oauthText(source, key) {
586
- const value = source[key];
587
- if (typeof value !== "string") throw new Error(`driver oauth ask: \`${key}\` is not text`);
588
- return value;
589
- }
590
- function oauthNumber(source, key) {
591
- const value = source[key];
592
- if (typeof value !== "number") throw new Error(`driver oauth ask: \`${key}\` is not a number`);
593
- return value;
594
- }
595
- function oauthNullableText(source, key) {
596
- const value = source[key];
597
- if (value === null || value === void 0) return null;
598
- return oauthText(source, key);
599
- }
600
- function oauthProvider(source) {
601
- const value = source.provider;
602
- if (value === "google" || value === "github" || value === "auth0") return value;
603
- throw new Error("driver oauth ask: `provider` is not google, github or auth0");
604
- }
605
- function oauthTextList(source, key) {
606
- const value = source[key];
607
- if (value === null || value === void 0) return null;
608
- if (!Array.isArray(value) || value.some((item) => typeof item !== "string")) throw new Error(`driver oauth ask: \`${key}\` is not a list of text`);
609
- return value.flatMap((item) => typeof item === "string" ? [item] : []);
610
- }
611
- function decodeOAuthAsk(value) {
612
- const ask = recordOf(value, "the oauth ask");
613
- switch (ask.ask) {
614
- case "pendingPut": {
615
- const grant = recordOf(ask.grant, "the pending grant");
616
- if (typeof ask.ttlMs !== "number") throw new Error("driver oauth ask: `ttlMs` is not a number");
617
- return {
618
- ask: "pendingPut",
619
- state: oauthText(ask, "state"),
620
- ttlMs: ask.ttlMs,
621
- grant: {
622
- provider: oauthText(grant, "provider"),
623
- redirectUri: oauthText(grant, "redirectUri"),
624
- verifier: oauthText(grant, "verifier"),
625
- subject: oauthNullableText(grant, "subject"),
626
- scopes: oauthTextList(grant, "scopes") ?? []
627
- }
628
- };
629
- }
630
- case "pendingTake":
631
- return { ask: "pendingTake", state: oauthText(ask, "state") };
632
- case "connectionAvailable":
633
- return { ask: "connectionAvailable" };
634
- case "connectionSave": {
635
- const grant = recordOf(ask.grant, "the token grant");
636
- if (typeof grant.expiresIn !== "number") throw new Error("driver oauth ask: `expiresIn` is not a number");
637
- return {
638
- ask: "connectionSave",
639
- provider: oauthProvider(ask),
640
- grant: {
641
- accessToken: oauthText(grant, "accessToken"),
642
- refreshToken: oauthNullableText(grant, "refreshToken"),
643
- expiresIn: grant.expiresIn,
644
- tokenType: oauthText(grant, "tokenType"),
645
- scope: oauthTextList(grant, "scope"),
646
- subject: oauthNullableText(grant, "subject")
647
- }
648
- };
649
- }
650
- case "connectionStatus":
651
- return { ask: "connectionStatus", provider: oauthProvider(ask) };
652
- case "connectionRemove":
653
- return { ask: "connectionRemove", provider: oauthProvider(ask) };
654
- case "subjectRemember":
655
- return { ask: "subjectRemember", accessToken: oauthText(ask, "accessToken"), subject: oauthText(ask, "subject") };
656
- case "subjectLookup":
657
- return { ask: "subjectLookup", accessToken: oauthText(ask, "accessToken") };
658
- case "subjectForget":
659
- return { ask: "subjectForget", accessToken: oauthText(ask, "accessToken") };
660
- case "metadataGet":
661
- return { ask: "metadataGet", issuer: oauthText(ask, "issuer") };
662
- case "metadataPut":
663
- return { ask: "metadataPut", issuer: oauthText(ask, "issuer"), metadata: recordOf(ask.metadata, "the metadata") };
664
- case "clock":
665
- return { ask: "clock" };
666
- case "mockTokenPut":
667
- return { ask: "mockTokenPut", accessToken: oauthText(ask, "accessToken"), refreshToken: oauthText(ask, "refreshToken"), expiresAtMs: oauthNumber(ask, "expiresAtMs"), provider: oauthProvider(ask) };
668
- case "mockTokenRefresh":
669
- return { ask: "mockTokenRefresh", refreshToken: oauthText(ask, "refreshToken"), newAccessToken: oauthText(ask, "newAccessToken"), expiresAtMs: oauthNumber(ask, "expiresAtMs") };
670
- case "mockTokenRevoke":
671
- return { ask: "mockTokenRevoke", token: oauthText(ask, "token") };
672
- case "mockTokenCheck":
673
- return { ask: "mockTokenCheck", accessToken: oauthText(ask, "accessToken") };
674
- case "consent":
675
- return { ask: "consent", authUrl: oauthText(ask, "authUrl"), state: oauthText(ask, "state"), redirectUri: oauthText(ask, "redirectUri") };
676
- default:
677
- throw new Error(`driver oauth ask "${String(ask.ask)}" is unknown`);
678
- }
679
- }
680
-
681
- export { decodeHttpBody, decodeHttpRequest, decodeHttpResponse, decodeOAuthAsk, decodeProgress, decodeRequest, decodeResolveProgress };