@astrale-os/sdk 0.6.0-beta.5 → 0.6.0-beta.51

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 (651) hide show
  1. package/README.md +213 -60
  2. package/dist/application/action/action.d.ts +6 -0
  3. package/dist/application/action/authoring.d.ts +1 -1
  4. package/dist/application/action/context.d.ts +89 -33
  5. package/dist/application/action/define.d.ts +3 -3
  6. package/dist/application/action/index.d.ts +1 -1
  7. package/dist/application/define.d.ts +8 -6
  8. package/dist/application/define.js +28 -14
  9. package/dist/application/dependency/index.d.ts +1 -1
  10. package/dist/application/dependency/invoker.d.ts +21 -10
  11. package/dist/application/domain.d.ts +30 -0
  12. package/dist/application/error/error.d.ts +16 -1
  13. package/dist/application/error/error.js +39 -5
  14. package/dist/application/error/index.d.ts +1 -1
  15. package/dist/application/error/index.js +1 -1
  16. package/dist/application/index.d.ts +4 -4
  17. package/dist/application/index.js +1 -1
  18. package/dist/application/integration/define.d.ts +8 -1
  19. package/dist/application/integration/index.d.ts +2 -2
  20. package/dist/application/integration/integration.d.ts +13 -1
  21. package/dist/application/integration/operation.d.ts +16 -3
  22. package/dist/application/mutation/authoring/builder.d.ts +81 -33
  23. package/dist/application/mutation/authoring/builder.js +100 -30
  24. package/dist/application/mutation/authoring/guard.d.ts +37 -0
  25. package/dist/application/mutation/authoring/guard.js +150 -0
  26. package/dist/application/mutation/authoring/index.d.ts +5 -2
  27. package/dist/application/mutation/authoring/index.js +2 -1
  28. package/dist/application/mutation/authoring/names.d.ts +19 -0
  29. package/dist/application/mutation/authoring/names.js +83 -0
  30. package/dist/application/mutation/authoring/properties.d.ts +5 -3
  31. package/dist/application/mutation/authoring/properties.js +35 -2
  32. package/dist/application/mutation/authoring/transition.d.ts +3 -2
  33. package/dist/application/mutation/authoring/transition.js +4 -1
  34. package/dist/application/mutation/define.d.ts +24 -10
  35. package/dist/application/mutation/define.js +49 -53
  36. package/dist/application/mutation/execution/execute.d.ts +2 -2
  37. package/dist/application/mutation/execution/execute.js +78 -7
  38. package/dist/application/mutation/execution/executor.d.ts +4 -1
  39. package/dist/application/mutation/execution/executor.js +6 -1
  40. package/dist/application/mutation/failure.d.ts +17 -1
  41. package/dist/application/mutation/failure.js +40 -19
  42. package/dist/application/mutation/index.d.ts +9 -5
  43. package/dist/application/mutation/index.js +5 -2
  44. package/dist/application/mutation/legacy/v6/builder.d.ts +84 -0
  45. package/dist/application/mutation/legacy/v6/define.d.ts +18 -0
  46. package/dist/application/mutation/legacy/v6/define.js +56 -0
  47. package/dist/application/mutation/legacy/v6/mutation.d.ts +28 -0
  48. package/dist/application/mutation/{authoring → legacy/v6}/precondition.d.ts +4 -0
  49. package/dist/application/mutation/mutation.d.ts +47 -19
  50. package/dist/application/query/answer/answer.d.ts +117 -0
  51. package/dist/application/query/answer/conformance.d.ts +4 -0
  52. package/dist/application/query/answer/conformance.js +27 -0
  53. package/dist/application/query/answer/facts.d.ts +17 -0
  54. package/dist/application/query/answer/facts.js +57 -0
  55. package/dist/application/query/composite/builder.d.ts +1 -1
  56. package/dist/application/query/composite/builder.js +2 -2
  57. package/dist/application/query/composite/plan.d.ts +1 -5
  58. package/dist/application/query/composite/plan.js +1 -3
  59. package/dist/application/query/composite/query.d.ts +1 -2
  60. package/dist/application/query/define.d.ts +3 -34
  61. package/dist/application/query/define.js +5 -131
  62. package/dist/application/query/defined/define.d.ts +45 -0
  63. package/dist/application/query/defined/define.js +96 -0
  64. package/dist/application/query/defined/query.d.ts +139 -0
  65. package/dist/application/query/definition.d.ts +12 -0
  66. package/dist/application/query/definition.js +47 -0
  67. package/dist/application/query/execution/bounds.d.ts +22 -0
  68. package/dist/application/query/execution/bounds.js +88 -0
  69. package/dist/application/query/execution/client.d.ts +21 -0
  70. package/dist/application/query/execution/crossings.d.ts +25 -0
  71. package/dist/application/query/execution/crossings.js +218 -0
  72. package/dist/application/query/execution/error.d.ts +71 -0
  73. package/dist/application/query/execution/error.js +50 -0
  74. package/dist/application/query/execution/execute.d.ts +4 -10
  75. package/dist/application/query/execution/execute.js +3 -45
  76. package/dist/application/query/execution/executor.d.ts +2 -2
  77. package/dist/application/query/execution/refusal.d.ts +37 -0
  78. package/dist/application/query/execution/refusal.js +80 -0
  79. package/dist/application/query/execution/rows.d.ts +42 -0
  80. package/dist/application/query/execution/rows.js +326 -0
  81. package/dist/application/query/execution/run.d.ts +85 -0
  82. package/dist/application/query/execution/run.js +372 -0
  83. package/dist/application/query/execution/split.d.ts +24 -0
  84. package/dist/application/query/execution/split.js +190 -0
  85. package/dist/application/query/failure.d.ts +8 -0
  86. package/dist/application/query/failure.js +8 -0
  87. package/dist/application/query/handles/build.d.ts +10 -0
  88. package/dist/application/query/handles/build.js +53 -0
  89. package/dist/application/query/handles/conditions.d.ts +94 -0
  90. package/dist/application/query/handles/domain.d.ts +157 -0
  91. package/dist/application/query/handles/handles.d.ts +285 -0
  92. package/dist/application/query/handles/handles.js +1 -0
  93. package/dist/application/query/handles/model.d.ts +106 -0
  94. package/dist/application/query/handles/model.js +261 -0
  95. package/dist/application/query/handles/plan.d.ts +100 -0
  96. package/dist/application/query/handles/plan.js +37 -0
  97. package/dist/application/query/handles/reads.d.ts +106 -0
  98. package/dist/application/query/handles/reads.js +978 -0
  99. package/dist/application/query/handles/relations.d.ts +106 -0
  100. package/dist/application/query/handles/relations.js +1 -0
  101. package/dist/application/query/handles/rows.d.ts +94 -0
  102. package/dist/application/query/handles/rows.js +4 -0
  103. package/dist/application/query/handles/terms.d.ts +103 -0
  104. package/dist/application/query/handles/terms.js +282 -0
  105. package/dist/application/query/index.d.ts +14 -8
  106. package/dist/application/query/index.js +10 -5
  107. package/dist/application/query/language/index.d.ts +2 -0
  108. package/dist/application/query/language/index.js +2 -0
  109. package/dist/application/query/language/query.d.ts +323 -0
  110. package/dist/application/query/language/query.js +2 -0
  111. package/dist/application/query/{collection → legacy/v6/collection}/identity.d.ts +2 -2
  112. package/dist/application/query/{collection → legacy/v6/collection}/metadata.d.ts +1 -1
  113. package/dist/application/query/{collection → legacy/v6/collection}/union.d.ts +4 -4
  114. package/dist/application/query/{collection → legacy/v6/collection}/union.js +15 -8
  115. package/dist/application/query/legacy/v6/conformance.d.ts +15 -0
  116. package/dist/application/query/legacy/v6/conformance.js +46 -0
  117. package/dist/application/query/legacy/v6/define.d.ts +37 -0
  118. package/dist/application/query/legacy/v6/define.js +90 -0
  119. package/dist/application/query/legacy/v6/execution/execute.d.ts +18 -0
  120. package/dist/application/query/legacy/v6/execution/execute.js +50 -0
  121. package/dist/application/query/legacy/v6/index.d.ts +7 -0
  122. package/dist/application/query/legacy/v6/index.js +3 -0
  123. package/dist/application/query/legacy/v6/kernel.d.ts +6 -0
  124. package/dist/application/query/legacy/v6/kernel.js +5 -0
  125. package/dist/application/query/{single → legacy/v6/single}/pagination.js +1 -1
  126. package/dist/application/query/{single → legacy/v6/single}/query.d.ts +2 -14
  127. package/dist/application/query/legacy/v6/single/query.js +1 -0
  128. package/dist/application/query/query.d.ts +19 -4
  129. package/dist/application/routes/admission.d.ts +3 -3
  130. package/dist/application/routes/admission.js +3 -3
  131. package/dist/application/routes/index.d.ts +3 -2
  132. package/dist/application/routes/route.d.ts +3 -3
  133. package/dist/application/runtime/actions.js +3 -0
  134. package/dist/application/runtime/declarations.d.ts +6 -6
  135. package/dist/application/runtime/define.d.ts +5 -5
  136. package/dist/application/runtime/workflows.d.ts +3 -1
  137. package/dist/application/runtime/workflows.js +3 -4
  138. package/dist/application/view/define.js +4 -6
  139. package/dist/application/view/frontend.d.ts +2 -2
  140. package/dist/application/view/index.d.ts +1 -1
  141. package/dist/application/view/route.d.ts +0 -14
  142. package/dist/application/view/route.js +1 -64
  143. package/dist/application/workflow/authoring.d.ts +3 -2
  144. package/dist/application/workflow/context.d.ts +8 -2
  145. package/dist/application/workflow/define.d.ts +4 -4
  146. package/dist/application/workflow/define.js +14 -9
  147. package/dist/application/workflow/durable.d.ts +211 -0
  148. package/dist/application/workflow/durable.js +1 -0
  149. package/dist/application/workflow/index.d.ts +3 -2
  150. package/dist/application/workflow/runner/inline.js +3 -4
  151. package/dist/application/workflow/runner/runner.d.ts +2 -2
  152. package/dist/application/workflow/step/output.d.ts +2 -0
  153. package/dist/application/workflow/step/output.js +73 -0
  154. package/dist/application/workflow/workflow.d.ts +5 -3
  155. package/dist/deployment/adapter/adapter.d.ts +55 -13
  156. package/dist/deployment/adapter/bundle/bundle.d.ts +36 -0
  157. package/dist/deployment/adapter/bundle/bundle.js +1 -0
  158. package/dist/deployment/adapter/bundle/file.d.ts +10 -0
  159. package/dist/deployment/adapter/bundle/file.js +1 -0
  160. package/dist/deployment/adapter/bundle/index.d.ts +2 -0
  161. package/dist/deployment/adapter/bundle/index.js +1 -0
  162. package/dist/deployment/adapter/define.d.ts +4 -3
  163. package/dist/deployment/adapter/define.js +107 -23
  164. package/dist/deployment/adapter/index.d.ts +4 -3
  165. package/dist/deployment/adapter/index.js +1 -0
  166. package/dist/deployment/adapter/release/command.d.ts +33 -0
  167. package/dist/deployment/adapter/release/command.js +1 -0
  168. package/dist/deployment/adapter/release/context.d.ts +94 -0
  169. package/dist/deployment/adapter/release/context.js +1 -0
  170. package/dist/deployment/adapter/release/index.d.ts +4 -0
  171. package/dist/deployment/adapter/release/index.js +1 -0
  172. package/dist/deployment/adapter/release/list.d.ts +53 -0
  173. package/dist/deployment/adapter/release/list.js +1 -0
  174. package/dist/deployment/adapter/release/refusal.d.ts +10 -0
  175. package/dist/deployment/adapter/release/refusal.js +14 -0
  176. package/dist/deployment/adapter/release/result.d.ts +56 -0
  177. package/dist/deployment/adapter/release/result.js +1 -0
  178. package/dist/deployment/address/configuration.d.ts +96 -0
  179. package/dist/deployment/address/configuration.js +274 -0
  180. package/dist/deployment/address/fingerprint.d.ts +5 -0
  181. package/dist/deployment/address/fingerprint.js +27 -0
  182. package/dist/deployment/address/index.d.ts +5 -0
  183. package/dist/deployment/address/index.js +4 -0
  184. package/dist/deployment/address/label.d.ts +42 -0
  185. package/dist/deployment/address/label.js +80 -0
  186. package/dist/deployment/address/line.d.ts +29 -0
  187. package/dist/deployment/address/line.js +53 -0
  188. package/dist/deployment/address/record.d.ts +73 -0
  189. package/dist/deployment/address/record.js +138 -0
  190. package/dist/deployment/address/summary.d.ts +30 -0
  191. package/dist/deployment/address/summary.js +1 -0
  192. package/dist/deployment/address/vectors.d.ts +60 -0
  193. package/dist/deployment/address/vectors.js +517 -0
  194. package/dist/deployment/authoring.d.ts +0 -2
  195. package/dist/deployment/authoring.js +0 -1
  196. package/dist/deployment/build/build.d.ts +15 -2
  197. package/dist/deployment/build/compile.d.ts +4 -4
  198. package/dist/deployment/build/compile.js +19 -17
  199. package/dist/deployment/build/frontend/compilation.d.ts +2 -4
  200. package/dist/deployment/build/frontend/compilation.js +0 -5
  201. package/dist/deployment/build/frontend/digest.js +1 -5
  202. package/dist/deployment/build/index.d.ts +1 -0
  203. package/dist/deployment/build/index.js +1 -0
  204. package/dist/deployment/build/manifest.d.ts +59 -0
  205. package/dist/deployment/build/manifest.js +118 -0
  206. package/dist/deployment/build/material.d.ts +2 -2
  207. package/dist/deployment/build/material.js +31 -13
  208. package/dist/deployment/build/schema.d.ts +2 -2
  209. package/dist/deployment/deployment.d.ts +3 -2
  210. package/dist/deployment/environment.d.ts +6 -0
  211. package/dist/deployment/environment.js +6 -0
  212. package/dist/deployment/index.d.ts +4 -6
  213. package/dist/deployment/index.js +1 -2
  214. package/dist/deployment/release/addressing.d.ts +6 -5
  215. package/dist/deployment/release/addressing.js +2 -3
  216. package/dist/deployment/release/assemble.d.ts +6 -3
  217. package/dist/deployment/release/assemble.js +12 -10
  218. package/dist/deployment/release/release.d.ts +16 -5
  219. package/dist/deployment/release/seal.d.ts +14 -0
  220. package/dist/deployment/release/seal.js +22 -0
  221. package/dist/deployment/release/{publication → served}/callables.d.ts +2 -2
  222. package/dist/deployment/release/{publication → served}/callables.js +2 -2
  223. package/dist/deployment/release/served/index.d.ts +11 -0
  224. package/dist/deployment/release/served/index.js +26 -0
  225. package/dist/deployment/release/{publication → served}/views.d.ts +2 -2
  226. package/dist/deployment/release/{publication → served}/views.js +0 -1
  227. package/dist/deployment/runtime/admission.d.ts +2 -2
  228. package/dist/deployment/runtime/admission.js +5 -5
  229. package/dist/deployment/verify/index.d.ts +3 -4
  230. package/dist/deployment/verify/index.js +2 -3
  231. package/dist/deployment/verify/preflight/bundle.d.ts +18 -0
  232. package/dist/deployment/verify/preflight/bundle.js +71 -0
  233. package/dist/deployment/verify/preflight/index.d.ts +1 -12
  234. package/dist/deployment/verify/preflight/index.js +1 -12
  235. package/dist/deployment/verify/readiness/fetch.d.ts +13 -0
  236. package/dist/deployment/verify/readiness/fetch.js +26 -0
  237. package/dist/deployment/verify/readiness/identity.d.ts +3 -6
  238. package/dist/deployment/verify/readiness/identity.js +3 -3
  239. package/dist/deployment/verify/readiness/index.d.ts +15 -8
  240. package/dist/deployment/verify/readiness/index.js +25 -6
  241. package/dist/deployment/verify/readiness/release.d.ts +8 -0
  242. package/dist/deployment/verify/readiness/release.js +22 -0
  243. package/dist/deployment/worker/address.d.ts +26 -0
  244. package/dist/deployment/worker/address.js +43 -0
  245. package/dist/deployment/worker/build.d.ts +60 -0
  246. package/dist/deployment/worker/build.js +172 -0
  247. package/dist/deployment/worker/configuration.d.ts +73 -0
  248. package/dist/deployment/worker/configuration.js +165 -0
  249. package/dist/deployment/worker/content.d.ts +38 -0
  250. package/dist/deployment/worker/content.js +169 -0
  251. package/dist/deployment/worker/index.d.ts +29 -0
  252. package/dist/deployment/worker/index.js +29 -0
  253. package/dist/deployment/worker/limits.d.ts +30 -0
  254. package/dist/deployment/worker/limits.js +30 -0
  255. package/dist/deployment/worker/record.d.ts +29 -0
  256. package/dist/deployment/worker/record.js +69 -0
  257. package/dist/deployment/worker/request.d.ts +118 -0
  258. package/dist/deployment/worker/request.js +280 -0
  259. package/dist/deployment/worker/response.d.ts +101 -0
  260. package/dist/deployment/worker/response.js +207 -0
  261. package/dist/execution/cache/cache.d.ts +17 -0
  262. package/dist/execution/cache/cache.js +11 -0
  263. package/dist/execution/cache/index.d.ts +2 -0
  264. package/dist/execution/cache/index.js +2 -0
  265. package/dist/execution/cache/memory.d.ts +13 -0
  266. package/dist/execution/cache/memory.js +48 -0
  267. package/dist/execution/identity/authentication.d.ts +33 -3
  268. package/dist/execution/identity/authentication.js +90 -36
  269. package/dist/execution/identity/callback.d.ts +20 -20
  270. package/dist/execution/identity/callback.js +34 -26
  271. package/dist/execution/identity/delivery.d.ts +6 -4
  272. package/dist/execution/identity/delivery.js +25 -20
  273. package/dist/execution/identity/identity.d.ts +17 -3
  274. package/dist/execution/identity/identity.js +12 -4
  275. package/dist/execution/identity/jwks.d.ts +5 -0
  276. package/dist/execution/identity/jwks.js +92 -102
  277. package/dist/execution/index.d.ts +6 -4
  278. package/dist/execution/index.js +4 -2
  279. package/dist/execution/invocation/admission/age.d.ts +57 -0
  280. package/dist/execution/invocation/admission/age.js +208 -0
  281. package/dist/execution/invocation/admission/authentication.d.ts +13 -13
  282. package/dist/execution/invocation/admission/authentication.js +52 -44
  283. package/dist/execution/invocation/admission/authority.d.ts +28 -6
  284. package/dist/execution/invocation/admission/authority.js +9 -2
  285. package/dist/execution/invocation/admission/index.d.ts +4 -3
  286. package/dist/execution/invocation/admission/index.js +3 -2
  287. package/dist/execution/invocation/admission/input.d.ts +2 -2
  288. package/dist/execution/invocation/admission/input.js +16 -2
  289. package/dist/execution/invocation/admission/target.d.ts +11 -0
  290. package/dist/execution/invocation/admission/target.js +22 -3
  291. package/dist/execution/invocation/capabilities/bind.d.ts +14 -0
  292. package/dist/execution/invocation/capabilities/bind.js +74 -0
  293. package/dist/execution/invocation/capabilities/index.d.ts +1 -0
  294. package/dist/execution/invocation/capabilities/index.js +1 -0
  295. package/dist/execution/invocation/dependency/bind.d.ts +3 -1
  296. package/dist/execution/invocation/dependency/bind.js +36 -16
  297. package/dist/execution/invocation/dispatch/action.js +4 -2
  298. package/dist/execution/invocation/dispatch/context.d.ts +7 -6
  299. package/dist/execution/invocation/dispatch/context.js +11 -44
  300. package/dist/execution/invocation/dispatch/workflow.js +4 -6
  301. package/dist/execution/invocation/handler.js +8 -2
  302. package/dist/execution/invocation/index.d.ts +2 -2
  303. package/dist/execution/invocation/index.js +1 -1
  304. package/dist/execution/invocation/integration/authentication.d.ts +3 -3
  305. package/dist/execution/invocation/integration/authentication.js +7 -7
  306. package/dist/execution/invocation/integration/call.d.ts +2 -1
  307. package/dist/execution/invocation/integration/call.js +3 -3
  308. package/dist/execution/invocation/integration/clients.d.ts +1 -1
  309. package/dist/execution/invocation/integration/index.d.ts +1 -0
  310. package/dist/execution/invocation/integration/index.js +1 -0
  311. package/dist/execution/invocation/invocation.d.ts +6 -0
  312. package/dist/execution/invocation/invocation.js +129 -21
  313. package/dist/execution/invocation/lifecycle/active.d.ts +8 -2
  314. package/dist/execution/invocation/lifecycle/active.js +3 -3
  315. package/dist/execution/invocation/lifecycle/index.d.ts +1 -1
  316. package/dist/execution/invocation/result/errors.d.ts +0 -10
  317. package/dist/execution/invocation/result/errors.js +4 -16
  318. package/dist/execution/invocation/result/index.d.ts +3 -2
  319. package/dist/execution/invocation/result/index.js +2 -1
  320. package/dist/execution/invocation/result/project.js +41 -1
  321. package/dist/execution/invocation/result/undeclared.d.ts +7 -0
  322. package/dist/execution/invocation/result/undeclared.js +18 -0
  323. package/dist/execution/node/serve.d.ts +2 -2
  324. package/dist/execution/node/serve.js +1 -1
  325. package/dist/execution/runtime/index.d.ts +1 -0
  326. package/dist/execution/runtime/index.js +1 -0
  327. package/dist/execution/runtime/load.d.ts +3 -3
  328. package/dist/execution/runtime/load.js +3 -2
  329. package/dist/execution/runtime/release.d.ts +17 -0
  330. package/dist/execution/runtime/release.js +7 -0
  331. package/dist/execution/serve.d.ts +18 -4
  332. package/dist/execution/serve.js +10 -0
  333. package/dist/execution/service/create.js +43 -7
  334. package/dist/execution/service/initialization.d.ts +4 -4
  335. package/dist/execution/service/initialization.js +23 -14
  336. package/dist/execution/service/release.d.ts +2 -2
  337. package/dist/execution/service/release.js +3 -2
  338. package/dist/execution/service/service.d.ts +20 -5
  339. package/dist/execution/service/serving/delivery.d.ts +5 -0
  340. package/dist/execution/service/{publication → serving}/delivery.js +4 -1
  341. package/dist/execution/service/{publication → serving}/index.d.ts +1 -1
  342. package/dist/execution/service/serving/installation.d.ts +4 -0
  343. package/dist/execution/service/serving/installation.js +9 -0
  344. package/dist/execution/service/serving/source.d.ts +11 -0
  345. package/dist/execution/service/serving/source.js +15 -0
  346. package/dist/execution/workflows/attempts.d.ts +87 -0
  347. package/dist/execution/workflows/attempts.js +205 -0
  348. package/dist/execution/workflows/discovery.d.ts +14 -0
  349. package/dist/execution/workflows/discovery.js +151 -0
  350. package/dist/execution/workflows/engine.d.ts +83 -0
  351. package/dist/execution/workflows/engine.js +1 -0
  352. package/dist/execution/workflows/envelope.d.ts +12 -0
  353. package/dist/execution/workflows/envelope.js +46 -0
  354. package/dist/execution/workflows/failure.d.ts +56 -0
  355. package/dist/execution/workflows/failure.js +204 -0
  356. package/dist/execution/workflows/index.d.ts +4 -0
  357. package/dist/execution/workflows/index.js +3 -0
  358. package/dist/execution/workflows/integrations.d.ts +13 -0
  359. package/dist/execution/workflows/integrations.js +25 -0
  360. package/dist/execution/workflows/options.d.ts +81 -0
  361. package/dist/execution/workflows/options.js +158 -0
  362. package/dist/execution/workflows/receiver.d.ts +24 -0
  363. package/dist/execution/workflows/receiver.js +99 -0
  364. package/dist/execution/workflows/route.d.ts +12 -0
  365. package/dist/execution/workflows/route.js +35 -0
  366. package/dist/execution/workflows/run.d.ts +23 -0
  367. package/dist/execution/workflows/run.js +369 -0
  368. package/dist/execution/workflows/steps.d.ts +48 -0
  369. package/dist/execution/workflows/steps.js +93 -0
  370. package/dist/index.d.ts +4 -4
  371. package/dist/index.js +2 -2
  372. package/dist/platform/graph/alias.d.ts +1 -5
  373. package/dist/platform/graph/alias.js +1 -5
  374. package/dist/platform/graph/document/index.d.ts +1 -1
  375. package/dist/platform/graph/document/index.js +1 -1
  376. package/dist/platform/graph/index.d.ts +1 -1
  377. package/dist/platform/graph/index.js +1 -1
  378. package/dist/platform/release/index.d.ts +2 -0
  379. package/dist/platform/release/index.js +2 -0
  380. package/dist/platform/schema/callable-authoring.d.ts +21 -0
  381. package/dist/platform/schema/callable-authoring.js +27 -0
  382. package/dist/platform/schema/class-authoring.d.ts +56 -12
  383. package/dist/platform/schema/class-authoring.js +37 -4
  384. package/dist/platform/schema/class-icon-svg.d.ts +9 -0
  385. package/dist/platform/schema/class-icon-svg.js +29 -0
  386. package/dist/platform/schema/class-icon.d.ts +3 -8
  387. package/dist/platform/schema/class-icon.js +2 -29
  388. package/dist/platform/schema/index.d.ts +6 -4
  389. package/dist/platform/schema/index.js +2 -1
  390. package/dist/platform/schema/kernel-compiled.d.ts +2 -0
  391. package/dist/platform/schema/kernel-compiled.js +2 -0
  392. package/dist/platform/schema/kernel.d.ts +4 -2
  393. package/dist/platform/schema/property.d.ts +5 -0
  394. package/dist/platform/schema/schema-authoring.d.ts +14 -7
  395. package/dist/platform/schema/schema-authoring.js +5 -1
  396. package/dist/platform/versioning/dependents.d.ts +18 -0
  397. package/dist/platform/versioning/dependents.js +15 -0
  398. package/dist/platform/versioning/index.d.ts +5 -0
  399. package/dist/platform/versioning/index.js +5 -0
  400. package/dist/platform/versioning/name.d.ts +38 -0
  401. package/dist/platform/versioning/name.js +58 -0
  402. package/dist/platform/versioning/reference.d.ts +48 -0
  403. package/dist/platform/versioning/reference.js +95 -0
  404. package/dist/platform/versioning/version.d.ts +72 -0
  405. package/dist/platform/versioning/version.js +98 -0
  406. package/dist/project/admit.js +1 -5
  407. package/dist/project/define.d.ts +4 -4
  408. package/dist/project/define.js +55 -35
  409. package/dist/project/index.d.ts +1 -1
  410. package/dist/project/install-command.d.ts +6 -0
  411. package/dist/project/install-command.js +9 -0
  412. package/dist/project/project.d.ts +10 -8
  413. package/dist/testing/dataset/define.d.ts +1 -1
  414. package/dist/testing/durable/engine.d.ts +128 -0
  415. package/dist/testing/durable/engine.js +619 -0
  416. package/dist/testing/durable/index.d.ts +3 -0
  417. package/dist/testing/durable/index.js +1 -0
  418. package/dist/testing/durable/steps.d.ts +30 -0
  419. package/dist/testing/durable/steps.js +45 -0
  420. package/dist/testing/index.d.ts +8 -1
  421. package/dist/testing/index.js +6 -1
  422. package/dist/testing/load.js +1 -1
  423. package/dist/testing/query.d.ts +22 -0
  424. package/dist/testing/query.js +35 -0
  425. package/dist/tooling/cli/adapter-command.d.ts +35 -0
  426. package/dist/tooling/cli/adapter-command.js +66 -0
  427. package/dist/tooling/cli/arguments.d.ts +17 -6
  428. package/dist/tooling/cli/arguments.js +175 -52
  429. package/dist/tooling/cli/build.d.ts +55 -0
  430. package/dist/tooling/cli/build.js +77 -0
  431. package/dist/tooling/cli/bun.d.ts +0 -1
  432. package/dist/tooling/cli/bun.js +0 -7
  433. package/dist/tooling/cli/commit.d.ts +35 -0
  434. package/dist/tooling/cli/commit.js +235 -0
  435. package/dist/tooling/cli/deploy-mode.d.ts +26 -0
  436. package/dist/tooling/cli/deploy-mode.js +59 -0
  437. package/dist/tooling/cli/deploy-result.d.ts +80 -0
  438. package/dist/tooling/cli/deploy-result.js +64 -0
  439. package/dist/tooling/cli/diff/declared.d.ts +7 -0
  440. package/dist/tooling/cli/diff/declared.js +27 -0
  441. package/dist/tooling/cli/diff/index.d.ts +30 -0
  442. package/dist/tooling/cli/diff/index.js +58 -0
  443. package/dist/tooling/cli/diff/render.d.ts +15 -0
  444. package/dist/tooling/cli/diff/render.js +131 -0
  445. package/dist/tooling/cli/diff/report.d.ts +88 -0
  446. package/dist/tooling/cli/diff/report.js +154 -0
  447. package/dist/tooling/cli/dotenv.d.ts +5 -5
  448. package/dist/tooling/cli/dotenv.js +6 -36
  449. package/dist/tooling/cli/help.js +173 -60
  450. package/dist/tooling/cli/immutable-deployment.d.ts +83 -0
  451. package/dist/tooling/cli/immutable-deployment.js +135 -0
  452. package/dist/tooling/cli/index.d.ts +12 -4
  453. package/dist/tooling/cli/index.js +6 -3
  454. package/dist/tooling/cli/installed-on.d.ts +83 -0
  455. package/dist/tooling/cli/installed-on.js +156 -0
  456. package/dist/tooling/cli/list.d.ts +152 -0
  457. package/dist/tooling/cli/list.js +331 -0
  458. package/dist/tooling/cli/log.d.ts +5 -2
  459. package/dist/tooling/cli/log.js +9 -2
  460. package/dist/tooling/cli/orchestrate.d.ts +0 -6
  461. package/dist/tooling/cli/orchestrate.js +252 -91
  462. package/dist/tooling/cli/project.d.ts +3 -3
  463. package/dist/tooling/cli/publish/index.d.ts +81 -0
  464. package/dist/tooling/cli/publish/index.js +383 -0
  465. package/dist/tooling/cli/publish/report.d.ts +49 -0
  466. package/dist/tooling/cli/publish/report.js +15 -0
  467. package/dist/tooling/cli/registry/client.d.ts +121 -0
  468. package/dist/tooling/cli/registry/client.js +354 -0
  469. package/dist/tooling/cli/registry/error.d.ts +11 -0
  470. package/dist/tooling/cli/registry/error.js +17 -0
  471. package/dist/tooling/cli/registry/executable.d.ts +35 -0
  472. package/dist/tooling/cli/registry/executable.js +96 -0
  473. package/dist/tooling/cli/registry/index.d.ts +9 -0
  474. package/dist/tooling/cli/registry/index.js +8 -0
  475. package/dist/tooling/cli/registry/installations.d.ts +67 -0
  476. package/dist/tooling/cli/registry/installations.js +108 -0
  477. package/dist/tooling/cli/registry/process.d.ts +36 -0
  478. package/dist/tooling/cli/registry/process.js +119 -0
  479. package/dist/tooling/cli/secrets.d.ts +9 -0
  480. package/dist/tooling/cli/secrets.js +19 -0
  481. package/dist/tooling/cli/yank.d.ts +34 -0
  482. package/dist/tooling/cli/yank.js +32 -0
  483. package/dist/tooling/linter/adapters/typescript/definition-calls.d.ts +34 -0
  484. package/dist/tooling/linter/adapters/typescript/definition-calls.js +88 -0
  485. package/dist/tooling/linter/adapters/typescript/imports.d.ts +0 -1
  486. package/dist/tooling/linter/adapters/typescript/imports.js +1 -5
  487. package/dist/tooling/linter/adapters/typescript/index.d.ts +3 -2
  488. package/dist/tooling/linter/adapters/typescript/index.js +3 -2
  489. package/dist/tooling/linter/adapters/typescript/query-observation.js +37 -12
  490. package/dist/tooling/linter/adapters/typescript/syntax.d.ts +3 -3
  491. package/dist/tooling/linter/adapters/typescript/syntax.js +13 -25
  492. package/dist/tooling/linter/adapters/typescript/type-analysis.d.ts +2 -0
  493. package/dist/tooling/linter/adapters/typescript/type-analysis.js +10 -0
  494. package/dist/tooling/linter/implementations/source/callable-requirements.d.ts +1 -2
  495. package/dist/tooling/linter/implementations/source/callable-requirements.js +11 -16
  496. package/dist/tooling/linter/implementations/source/definitions.d.ts +2 -0
  497. package/dist/tooling/linter/implementations/source/definitions.js +425 -0
  498. package/dist/tooling/linter/implementations/source/dependencies.js +13 -72
  499. package/dist/tooling/linter/implementations/source/global.js +18 -11
  500. package/dist/tooling/linter/implementations/source/mutations.js +146 -48
  501. package/dist/tooling/linter/implementations/source/policy-edges.d.ts +2 -0
  502. package/dist/tooling/linter/implementations/source/policy-edges.js +113 -0
  503. package/dist/tooling/linter/implementations/source/providers.js +5 -5
  504. package/dist/tooling/linter/implementations/source/queries.js +1 -17
  505. package/dist/tooling/linter/implementations/source/shared.d.ts +19 -5
  506. package/dist/tooling/linter/implementations/source/shared.js +131 -55
  507. package/dist/tooling/linter/implementations/source/verifiers.js +4 -2
  508. package/dist/tooling/linter/implementations/source/views.js +2 -2
  509. package/dist/tooling/linter/implementations/source/workflows.js +499 -17
  510. package/dist/tooling/linter/policy/generated.js +15 -64
  511. package/dist/tooling/linter/requirements/registry.js +11 -9
  512. package/dist/tooling/packaging/declarations/ownership.js +1 -1
  513. package/dist/tooling/packaging/finalize.d.ts +1 -1
  514. package/dist/tooling/packaging/finalize.js +1 -1
  515. package/docs/admission-age.md +88 -0
  516. package/docs/auth-api-migration.md +55 -0
  517. package/docs/business-errors.md +42 -0
  518. package/docs/domain-definition-migration.md +44 -0
  519. package/docs/domain-schema-migration.md +36 -0
  520. package/docs/durable-workflows.md +473 -0
  521. package/docs/handler-dependencies.md +285 -0
  522. package/docs/legacy/query-v6.md +62 -0
  523. package/docs/queries.md +492 -0
  524. package/docs/release.md +155 -0
  525. package/docs/schema-cost.md +124 -0
  526. package/package.json +53 -21
  527. package/dist/application/application.d.ts +0 -28
  528. package/dist/application/query/execution/projection.d.ts +0 -3
  529. package/dist/application/query/execution/projection.js +0 -3
  530. package/dist/deployment/adapter/deploy/context.d.ts +0 -15
  531. package/dist/deployment/adapter/deploy/index.d.ts +0 -2
  532. package/dist/deployment/adapter/deploy/result.d.ts +0 -50
  533. package/dist/deployment/adapter/prepare/artifact.d.ts +0 -33
  534. package/dist/deployment/adapter/prepare/context.d.ts +0 -23
  535. package/dist/deployment/adapter/prepare/index.d.ts +0 -2
  536. package/dist/deployment/deploy.d.ts +0 -20
  537. package/dist/deployment/deploy.js +0 -31
  538. package/dist/deployment/release/publication/index.d.ts +0 -6
  539. package/dist/deployment/release/publication/index.js +0 -6
  540. package/dist/deployment/release/publication/manifest.d.ts +0 -3
  541. package/dist/deployment/release/publication/manifest.js +0 -5
  542. package/dist/deployment/release/publication/requirements.d.ts +0 -3
  543. package/dist/deployment/release/publication/requirements.js +0 -3
  544. package/dist/deployment/release/publication/seal.d.ts +0 -10
  545. package/dist/deployment/release/publication/seal.js +0 -39
  546. package/dist/deployment/verify/preflight/artifact.d.ts +0 -6
  547. package/dist/deployment/verify/preflight/artifact.js +0 -122
  548. package/dist/deployment/verify/preflight/publication.d.ts +0 -4
  549. package/dist/deployment/verify/preflight/publication.js +0 -14
  550. package/dist/deployment/verify/readiness/deployment.d.ts +0 -3
  551. package/dist/deployment/verify/readiness/deployment.js +0 -151
  552. package/dist/deployment/verify/readiness/publication.d.ts +0 -11
  553. package/dist/deployment/verify/readiness/publication.js +0 -41
  554. package/dist/execution/service/errors.d.ts +0 -3
  555. package/dist/execution/service/errors.js +0 -3
  556. package/dist/execution/service/publication/delivery.d.ts +0 -2
  557. package/dist/execution/service/publication/installation.d.ts +0 -3
  558. package/dist/execution/service/publication/installation.js +0 -8
  559. package/dist/execution/service/publication/source.d.ts +0 -3
  560. package/dist/execution/service/publication/source.js +0 -11
  561. package/dist/platform/publication/index.d.ts +0 -2
  562. package/dist/platform/publication/index.js +0 -2
  563. package/dist/tooling/cli/astrale/authority.d.ts +0 -5
  564. package/dist/tooling/cli/astrale/authority.js +0 -11
  565. package/dist/tooling/cli/astrale/executable.d.ts +0 -2
  566. package/dist/tooling/cli/astrale/executable.js +0 -47
  567. package/dist/tooling/cli/astrale/failure.d.ts +0 -6
  568. package/dist/tooling/cli/astrale/failure.js +0 -48
  569. package/dist/tooling/cli/astrale/instance.d.ts +0 -11
  570. package/dist/tooling/cli/astrale/instance.js +0 -52
  571. package/dist/tooling/cli/astrale/process.d.ts +0 -13
  572. package/dist/tooling/cli/astrale/process.js +0 -94
  573. package/dist/tooling/cli/astrale/version.d.ts +0 -18
  574. package/dist/tooling/cli/astrale/version.js +0 -55
  575. package/dist/tooling/cli/credential.d.ts +0 -2
  576. package/dist/tooling/cli/credential.js +0 -57
  577. package/dist/tooling/cli/deprecations.d.ts +0 -9
  578. package/dist/tooling/cli/deprecations.js +0 -15
  579. package/dist/tooling/cli/development/candidate.d.ts +0 -25
  580. package/dist/tooling/cli/development/candidate.js +0 -176
  581. package/dist/tooling/cli/development/deployment.d.ts +0 -16
  582. package/dist/tooling/cli/development/deployment.js +0 -39
  583. package/dist/tooling/cli/development/develop.d.ts +0 -11
  584. package/dist/tooling/cli/development/develop.js +0 -243
  585. package/dist/tooling/cli/development/lease.d.ts +0 -18
  586. package/dist/tooling/cli/development/lease.js +0 -163
  587. package/dist/tooling/cli/development/lifecycle.d.ts +0 -9
  588. package/dist/tooling/cli/development/lifecycle.js +0 -43
  589. package/dist/tooling/cli/development/project-imports.d.ts +0 -22
  590. package/dist/tooling/cli/development/project-imports.js +0 -39
  591. package/dist/tooling/cli/development/project-lock.d.ts +0 -16
  592. package/dist/tooling/cli/development/project-lock.js +0 -41
  593. package/dist/tooling/cli/development/rebuild.d.ts +0 -13
  594. package/dist/tooling/cli/development/rebuild.js +0 -58
  595. package/dist/tooling/cli/development/release-evidence.d.ts +0 -4
  596. package/dist/tooling/cli/development/release-evidence.js +0 -10
  597. package/dist/tooling/cli/development/report.d.ts +0 -6
  598. package/dist/tooling/cli/development/report.js +0 -14
  599. package/dist/tooling/cli/development/session-file.d.ts +0 -53
  600. package/dist/tooling/cli/development/session-file.js +0 -337
  601. package/dist/tooling/cli/development/source-watch.d.ts +0 -14
  602. package/dist/tooling/cli/development/source-watch.js +0 -140
  603. package/dist/tooling/cli/development/sources.d.ts +0 -7
  604. package/dist/tooling/cli/development/sources.js +0 -48
  605. package/dist/tooling/cli/development/target-lock.d.ts +0 -16
  606. package/dist/tooling/cli/development/target-lock.js +0 -68
  607. package/dist/tooling/cli/development/view.d.ts +0 -28
  608. package/dist/tooling/cli/development/view.js +0 -151
  609. package/dist/tooling/cli/environment-release.d.ts +0 -21
  610. package/dist/tooling/cli/environment-release.js +0 -46
  611. package/dist/tooling/cli/evidence.d.ts +0 -11
  612. package/dist/tooling/cli/evidence.js +0 -53
  613. package/dist/tooling/cli/installation/index.d.ts +0 -2
  614. package/dist/tooling/cli/installation/index.js +0 -1
  615. package/dist/tooling/cli/installation/observation.d.ts +0 -10
  616. package/dist/tooling/cli/installation/observation.js +0 -44
  617. package/dist/tooling/cli/installation/reconcile.d.ts +0 -32
  618. package/dist/tooling/cli/installation/reconcile.js +0 -122
  619. package/dist/tooling/linter/implementations/source/migrations.d.ts +0 -2
  620. package/dist/tooling/linter/implementations/source/migrations.js +0 -113
  621. package/dist/tooling/linter/qualification/index.d.ts +0 -10
  622. package/dist/tooling/linter/qualification/index.js +0 -2
  623. package/dist/tooling/linter/qualification/query-fixtures.d.ts +0 -2
  624. package/dist/tooling/linter/qualification/query-fixtures.js +0 -68
  625. package/dist/tooling/linter/qualification/runner.d.ts +0 -3
  626. package/dist/tooling/linter/qualification/runner.js +0 -6
  627. /package/dist/application/{application.js → domain.js} +0 -0
  628. /package/dist/application/{query/single/query.js → mutation/legacy/v6/builder.js} +0 -0
  629. /package/dist/{deployment/adapter/deploy/context.js → application/mutation/legacy/v6/mutation.js} +0 -0
  630. /package/dist/application/mutation/{authoring → legacy/v6}/precondition.js +0 -0
  631. /package/dist/{deployment/adapter/deploy/index.js → application/query/answer/answer.js} +0 -0
  632. /package/dist/{deployment/adapter/deploy/result.js → application/query/defined/query.js} +0 -0
  633. /package/dist/{deployment/adapter/prepare/artifact.js → application/query/execution/client.js} +0 -0
  634. /package/dist/{deployment/adapter/prepare/context.js → application/query/handles/conditions.js} +0 -0
  635. /package/dist/{deployment/adapter/prepare/index.js → application/query/handles/domain.js} +0 -0
  636. /package/dist/application/query/{collection → legacy/v6/collection}/identity.js +0 -0
  637. /package/dist/application/query/{collection → legacy/v6/collection}/limits.d.ts +0 -0
  638. /package/dist/application/query/{collection → legacy/v6/collection}/limits.js +0 -0
  639. /package/dist/application/query/{collection → legacy/v6/collection}/metadata.js +0 -0
  640. /package/dist/application/query/{execution → legacy/v6/execution}/pages.d.ts +0 -0
  641. /package/dist/application/query/{execution → legacy/v6/execution}/pages.js +0 -0
  642. /package/dist/application/query/{single → legacy/v6/single}/index.d.ts +0 -0
  643. /package/dist/application/query/{single → legacy/v6/single}/index.js +0 -0
  644. /package/dist/application/query/{single → legacy/v6/single}/node.d.ts +0 -0
  645. /package/dist/application/query/{single → legacy/v6/single}/node.js +0 -0
  646. /package/dist/application/query/{single → legacy/v6/single}/pagination.d.ts +0 -0
  647. /package/dist/application/query/{single → legacy/v6/single}/selection.d.ts +0 -0
  648. /package/dist/application/query/{single → legacy/v6/single}/selection.js +0 -0
  649. /package/dist/deployment/release/{publication → served}/routes.d.ts +0 -0
  650. /package/dist/deployment/release/{publication → served}/routes.js +0 -0
  651. /package/dist/execution/service/{publication → serving}/index.js +0 -0
@@ -0,0 +1,372 @@
1
+ import * as errors from '@astrale-os/kernel-protocol/errors';
2
+ import { isSnapshotStale, maximumResponseBytesOf, ResponseError, retryAfterOf, } from '../../../platform/client/index.js';
3
+ import { declaredErrorFactory } from '../../error/error.js';
4
+ import { requireAnswerConformance } from '../answer/conformance.js';
5
+ import { querySpecOf } from '../defined/define.js';
6
+ import { handlesOf } from '../handles/build.js';
7
+ import { modelOf } from '../handles/model.js';
8
+ import { isRead, planOf } from '../handles/plan.js';
9
+ import { describe } from '../handles/terms.js';
10
+ import { MAXIMUM_BOUND, MAXIMUM_READS, MAXIMUM_ROWS, MAXIMUM_STEPS, pastPage, rowsOf, wideIn, } from './bounds.js';
11
+ import { Crossings } from './crossings.js';
12
+ import { QueryError } from './error.js';
13
+ import { describeRefusals, isUnserved, refusalsOf } from './refusal.js';
14
+ import { emptyResult, rootResult } from './rows.js';
15
+ import { merge, split } from './split.js';
16
+ /** Reads of one step in flight at once. */
17
+ const IN_FLIGHT = 8;
18
+ /** `QUERY_SNAPSHOT_STALE`: nothing was read, so the read is sent again at once, this many times. */
19
+ const STALE_RESENDS = 3;
20
+ /** A refusal's protocol code by name, for one that gives no reason. */
21
+ const CODE_NAMES = new Map(Object.entries(errors.CODES).map(([name, code]) => [code, name]));
22
+ /**
23
+ * One Query call: its reads so far, against S11, and, read for the caller, the Classes they cross,
24
+ * against S12.
25
+ */
26
+ export class Run {
27
+ client;
28
+ domain;
29
+ query;
30
+ #reads = 0;
31
+ #rows = 0;
32
+ model;
33
+ #crossings;
34
+ constructor(client, domain, query, declared) {
35
+ this.client = client;
36
+ this.domain = domain;
37
+ this.query = query;
38
+ this.model = modelOf(domain);
39
+ this.#crossings =
40
+ declared === undefined ? undefined : new Crossings(this.model, domain, declared);
41
+ }
42
+ /**
43
+ * S11, before a step sends: its reads, its verbs' bounds, its rows and each property `in` its
44
+ * documents write. Then S12, given the Domain's requirements: each foreign Class its relations
45
+ * cross.
46
+ */
47
+ admit(plans) {
48
+ this.#reads += plans.length;
49
+ if (this.#reads > MAXIMUM_READS)
50
+ throw new QueryError('TOO_MANY', this.query, { limit: 'reads', bound: MAXIMUM_READS });
51
+ if (plans.some(pastPage))
52
+ throw new QueryError('TOO_MANY', this.query, { limit: 'rows', bound: MAXIMUM_BOUND });
53
+ this.#rows += plans.reduce((total, plan) => total + rowsOf(plan), 0);
54
+ if (this.#rows > MAXIMUM_ROWS)
55
+ throw new QueryError('TOO_MANY', this.query, { limit: 'rows', bound: MAXIMUM_ROWS });
56
+ for (const plan of plans) {
57
+ const path = plan.document === undefined ? undefined : wideIn(plan.document);
58
+ // Into the request `{ document, paging }`, as the Kernel's refusals point.
59
+ if (path !== undefined)
60
+ throw new QueryError('INPUT_INVALID', this.query, {
61
+ limit: 'in',
62
+ path: `/document${path}`,
63
+ });
64
+ }
65
+ for (const plan of plans)
66
+ this.#crossings?.check(this.query, plan);
67
+ }
68
+ /** One read's result: its verb's empty answer, or its documents' answers merged and rendered. */
69
+ async read(plan, paging) {
70
+ if (plan.empty)
71
+ return emptyResult(this.query, plan);
72
+ let document = plan.document;
73
+ if (plan.verb === 'page' && paging?.size !== undefined)
74
+ document = withLimit(document, paging.size);
75
+ const documents = plan.verb === 'page' || plan.verb === 'document'
76
+ ? [document]
77
+ : split(document, document.list?.orderBy !== undefined);
78
+ const answers = [];
79
+ for (const sent of documents) {
80
+ const answer = await this.#send(sent, paging?.after);
81
+ if ('list' in answer)
82
+ requireAnswerConformance(this.domain, answer);
83
+ answers.push(answer);
84
+ }
85
+ return rootResult(this.query, this.model, plan, merge(document, answers));
86
+ }
87
+ async #send(document, after) {
88
+ const paging = after === undefined ? {} : { paging: { after } };
89
+ for (let attempt = 0;; attempt += 1) {
90
+ try {
91
+ return await this.client.query(document, paging);
92
+ }
93
+ catch (error) {
94
+ if (isSnapshotStale(error) && attempt < STALE_RESENDS)
95
+ continue;
96
+ throw this.#refusal(error);
97
+ }
98
+ }
99
+ }
100
+ /**
101
+ * A Kernel refusal as a `QueryError`. A network failure, or a refusal that prescribes when to
102
+ * send again (capacity, draining), is not the read's: it passes as it came, for the caller to
103
+ * retry. An answer past the bytes one response may carry, the Host's or the client's, is
104
+ * `TOO_MANY`: the SDK does not split a read to fit it, and the same read would pass them again.
105
+ */
106
+ #refusal(error) {
107
+ const bytes = maximumResponseBytesOf(error);
108
+ if (bytes !== undefined)
109
+ return new QueryError('TOO_MANY', this.query, { limit: 'bytes', bound: bytes }, { cause: error });
110
+ if (!(error instanceof ResponseError) || retryAfterOf(error) !== undefined)
111
+ return error;
112
+ const kernelCode = error.reason?.code ?? CODE_NAMES.get(error.code) ?? String(error.code);
113
+ const details = (error.reason?.details ?? {});
114
+ const cause = { cause: error };
115
+ if (isSnapshotStale(error))
116
+ return new QueryError('REFUSED', this.query, { kernelCode, retryable: true }, cause);
117
+ const refusals = refusalsOf(error);
118
+ if (refusals !== undefined) {
119
+ const path = refusals[0]?.path ?? (typeof details.path === 'string' ? details.path : undefined);
120
+ return new QueryError('INPUT_INVALID', this.query, {
121
+ kernelCode,
122
+ ...(typeof details.phase === 'string' ? { phase: details.phase } : {}),
123
+ ...(path === undefined ? {} : { path }),
124
+ }, { ...cause, ...(refusals.length === 0 ? {} : { reason: describeRefusals(refusals) }) });
125
+ }
126
+ if (kernelCode === 'QUERY_EXPECTATION_MISMATCH')
127
+ return new QueryError('OUTDATED', this.query, { kernelCode: 'QUERY_EXPECTATION_MISMATCH' }, cause);
128
+ // A Kernel that predates v7 refuses its request at the Function's input.
129
+ if (isUnserved(error))
130
+ return new QueryError('UNSUPPORTED', this.query, { feature: 'v7' }, cause);
131
+ // Only a trusted backend answers v7 (a maintenance session's refusal says when to retry).
132
+ if (kernelCode === 'QUERY_BACKEND_CONTRACT')
133
+ return new QueryError('UNSUPPORTED', this.query, { feature: 'v7' }, cause);
134
+ return new QueryError('REFUSED', this.query, { kernelCode, retryable: false }, cause);
135
+ }
136
+ }
137
+ /** A page document of `size` rows. */
138
+ function withLimit(document, size) {
139
+ const list = document.list;
140
+ return { ...document, list: { ...list, limit: size } };
141
+ }
142
+ /** Each task, at most `limit` at once, the results in order; after a failure, no task starts. */
143
+ async function pooled(tasks, limit) {
144
+ const results = [];
145
+ let next = 0;
146
+ let failed = false;
147
+ const worker = async () => {
148
+ while (!failed && next < tasks.length) {
149
+ const index = next++;
150
+ try {
151
+ results[index] = await tasks[index]();
152
+ }
153
+ catch (error) {
154
+ failed = true;
155
+ throw error;
156
+ }
157
+ }
158
+ };
159
+ await Promise.all(Array.from({ length: Math.min(limit, tasks.length) }, worker));
160
+ return results;
161
+ }
162
+ const stepped = new WeakMap();
163
+ /**
164
+ * The `steps` a Query's `build` receives: two to eight steps, the first a record of facets and
165
+ * each next one a function of the merged results before it. It reads nothing: what it returns is
166
+ * read when `build` returns it.
167
+ */
168
+ export function stepsFor(query) {
169
+ return (...steps) => {
170
+ if (steps.length < 2 || steps.length > MAXIMUM_STEPS)
171
+ throw new TypeError(`Query ${query}: steps takes 2 to ${MAXIMUM_STEPS} steps; got ${steps.length}. ${steps.length < 2
172
+ ? 'Reads that wait for none are what build returns: one read, or a record of facets.'
173
+ : 'Read the facets that wait for the same results in one step.'}`);
174
+ const [first, ...next] = steps;
175
+ if (!isFacets(first))
176
+ throw new TypeError(`Query ${query}: the first step is a record of facets; got ${described(first)}.`);
177
+ const position = next.findIndex((step) => typeof step !== 'function');
178
+ if (position !== -1)
179
+ throw new TypeError(`Query ${query}: each step after the first is a function of the results before it; step ${position + 2} is ${describe(next[position])}.`);
180
+ const value = Object.freeze({});
181
+ stepped.set(value, Object.freeze({ first, next: Object.freeze(next) }));
182
+ return value;
183
+ };
184
+ }
185
+ /** A record of facets: a plain object, neither a read nor what `steps` returned. */
186
+ function isFacets(value) {
187
+ if (typeof value !== 'object' || value === null || isRead(value) || stepped.has(value))
188
+ return false;
189
+ const prototype = Object.getPrototypeOf(value);
190
+ return prototype === Object.prototype || prototype === null;
191
+ }
192
+ /** What a step was, for its refusal: `steps(…)` and a Promise are named with their fix. */
193
+ function described(value) {
194
+ if (typeof value === 'object' && value !== null && stepped.has(value))
195
+ return 'steps(…), which only build returns';
196
+ if (value instanceof Promise)
197
+ return 'a Promise: build and its steps are not async';
198
+ return describe(value);
199
+ }
200
+ /** The steps `build` returned, or `undefined` for one read or one record of facets. */
201
+ export function stepsOf(built) {
202
+ return typeof built === 'object' && built !== null ? stepped.get(built) : undefined;
203
+ }
204
+ /**
205
+ * The facets a step returned, each a read, a list of reads (`items.map`) or nothing. One read is
206
+ * `build`'s alone, without steps: each step returns a record of facets.
207
+ */
208
+ function facetsOf(query, built, single) {
209
+ if (!isFacets(built)) {
210
+ const expected = single
211
+ ? 'build returns one read, a record of facets, or steps(…)'
212
+ : 'each step returns a record of facets';
213
+ throw new TypeError(`Query ${query}: ${expected}; got ${described(built)}.`);
214
+ }
215
+ return Object.entries(built);
216
+ }
217
+ /** A page is a Query's single read: one step that returns it. */
218
+ function refusePage(query, plan) {
219
+ if (plan.verb === 'page')
220
+ throw new TypeError(`Query ${query}: a page is a Query's single read (D22); read the others with first or all.`);
221
+ }
222
+ /**
223
+ * The reads of one step, admitted (S11, S12): a single read, or each facet's in order and the
224
+ * shape that puts their results back. A facet takes a name no `earlier` step read: the merged
225
+ * results keep one value per name.
226
+ */
227
+ export function planStep(run, built, single, earlier = {}) {
228
+ if (single && isRead(built)) {
229
+ const plans = [planOf(built)];
230
+ run.admit(plans);
231
+ return { plans };
232
+ }
233
+ const facets = facetsOf(run.query, built, single);
234
+ for (const [name] of facets)
235
+ if (Object.hasOwn(earlier, name))
236
+ throw new TypeError(`Query ${run.query}: an earlier step read the facet ${name}; name this step's facet otherwise.`);
237
+ const plans = [];
238
+ const shape = [];
239
+ for (const [name, facet] of facets) {
240
+ if (facet === undefined)
241
+ shape.push([name, undefined]);
242
+ else if (Array.isArray(facet))
243
+ shape.push([name, facet.map((read) => plans.push(planOf(read)) - 1)]);
244
+ else
245
+ shape.push([name, plans.push(planOf(facet)) - 1]);
246
+ }
247
+ plans.forEach((plan) => refusePage(run.query, plan));
248
+ run.admit(plans);
249
+ return { plans, shape };
250
+ }
251
+ /** The results of one step: a read's result, or a record of each facet's. */
252
+ async function runStep(run, built, single, call, earlier) {
253
+ const { plans, shape } = planStep(run, built, single, earlier);
254
+ if (shape === undefined) {
255
+ const plan = plans[0];
256
+ return run.read(plan, plan.verb === 'page' ? call : undefined);
257
+ }
258
+ const results = await pooled(plans.map((plan) => () => run.read(plan)), IN_FLIGHT);
259
+ const record = {};
260
+ for (const [name, at] of shape)
261
+ record[name] =
262
+ at === undefined
263
+ ? undefined
264
+ : typeof at === 'number'
265
+ ? results[at]
266
+ : Object.freeze(at.map((index) => results[index]));
267
+ return Object.freeze(record);
268
+ }
269
+ /** The size and cursor of a page call, checked against the page's `max`. */
270
+ function pageCall(query, call, max) {
271
+ const { size, after } = call;
272
+ if (max === undefined) {
273
+ if (size !== undefined || after !== undefined)
274
+ throw new TypeError(`Query ${query} is not a page: size and after continue a page Query.`);
275
+ return {};
276
+ }
277
+ if (size !== undefined && (!Number.isInteger(size) || size < 1 || size > max))
278
+ throw new TypeError(`Query ${query}: size is a whole number from 1 to the page's max, ${max}; got ${describe(size)}.`);
279
+ if (after !== undefined && (typeof after !== 'string' || after.length === 0))
280
+ throw new TypeError(`Query ${query}: after is the cursor a page returned as next.`);
281
+ return { size: size ?? max, ...(after === undefined ? {} : { after }) };
282
+ }
283
+ /** What `build` returns for `input`, against the handles of `domain`. */
284
+ function build(domain, query, input) {
285
+ const spec = querySpecOf(query);
286
+ if (spec === undefined)
287
+ throw new TypeError(`Not a Query v7: define one with defineQuery<Schema>()(id, { build }); got ${describe(query)}.`);
288
+ const built = spec.build(input, handlesOf(domain), stepsFor(query.id));
289
+ return { query, input, spec, built };
290
+ }
291
+ /** The `max` of a Query whose single read is a page; `undefined` for any other Query. */
292
+ function pageBoundOf(built) {
293
+ if (!isRead(built))
294
+ return undefined;
295
+ const plan = planOf(built);
296
+ return plan.verb === 'page' ? plan.bound : undefined;
297
+ }
298
+ /** One call of a built Query: each of its steps in order, or its single read, then `output`. */
299
+ async function answer(run, { query, input, spec, built }, call) {
300
+ const steps = stepsOf(built);
301
+ let answered;
302
+ if (steps === undefined) {
303
+ answered = await runStep(run, built, true, pageCall(query.id, call, pageBoundOf(built)), {});
304
+ }
305
+ else {
306
+ pageCall(query.id, call, undefined);
307
+ let merged = {};
308
+ for (const step of [() => steps.first, ...steps.next]) {
309
+ const results = await runStep(run, step(Object.freeze({ ...merged })), false, {}, merged);
310
+ merged = { ...merged, ...results };
311
+ }
312
+ answered = Object.freeze(merged);
313
+ }
314
+ if (spec.output === undefined)
315
+ return answered;
316
+ return spec.output(answered, input, outputContext(query, run.model));
317
+ }
318
+ /**
319
+ * Run a Query for `input` against `domain`, the resolved Domain it was written for: what `build`
320
+ * returns, each of its steps in order, then its `output`. A page Query takes its call's `size`
321
+ * and `after`. A read the Kernel refuses raises a `QueryError`; `output` raises the Query's
322
+ * declared errors. Read for the caller, with the Class requirements the Domain's build `declared`,
323
+ * each step's relations are checked against them first (S12).
324
+ */
325
+ export async function runQuery(client, domain, query, input, call = {}, declared) {
326
+ const built = build(domain, query, input);
327
+ return (await answer(new Run(client, domain, query.id, declared), built, call));
328
+ }
329
+ /**
330
+ * Every row of a page Query for `input`, page after page: past `max` rows, `TOO_MANY`, as
331
+ * `all({ max })`. Each page is a call of its own, with its own bounds (S11) and its own snapshot,
332
+ * and asks for at most the rows `max` leaves, plus one: the pages read at most `max + 1` rows.
333
+ */
334
+ export async function runEveryPage(client, domain, query, input, max, declared) {
335
+ const built = build(domain, query, input);
336
+ const bound = pageBoundOf(built.built);
337
+ if (bound === undefined)
338
+ throw new TypeError(`Query ${query.id} is not a page: query.all reads every page of a Query whose single read is page({ max }).`);
339
+ if (!Number.isSafeInteger(max) || max < 1)
340
+ throw new TypeError(`Query ${query.id}: max is a whole number from 1; got ${describe(max)}.`);
341
+ const rows = [];
342
+ let after;
343
+ for (;;) {
344
+ const size = Math.min(bound, max + 1 - rows.length);
345
+ const call = after === undefined ? { size } : { size, after };
346
+ const run = new Run(client, domain, query.id, declared);
347
+ const page = (await answer(run, built, call));
348
+ rows.push(...page.rows);
349
+ if (rows.length > max)
350
+ throw new QueryError('TOO_MANY', query.id, { limit: 'max', bound: max });
351
+ if (page.next === undefined)
352
+ return Object.freeze(rows);
353
+ after = page.next;
354
+ }
355
+ }
356
+ /**
357
+ * The context a Query's `output`, or a defined Mutation's `reject`, receives: its declared errors,
358
+ * and `is`, which narrows a row by Class.
359
+ */
360
+ export function outputContext(query, model) {
361
+ return {
362
+ error: declaredErrorFactory(query),
363
+ is: (row, cls) => {
364
+ try {
365
+ return model.satisfies(model.classOf(row.$class)).has(cls);
366
+ }
367
+ catch {
368
+ return false;
369
+ }
370
+ },
371
+ };
372
+ }
@@ -0,0 +1,24 @@
1
+ import type { QueryCountAnswer, QueryExistsAnswer, QueryListAnswer } from '../answer/answer.js';
2
+ import type { QueryDocument } from '../language/query.js';
3
+ /** The Kernel's set members per v7 document: ids and value-set points, guards included. */
4
+ export declare const MAXIMUM_MEMBERS = 32768;
5
+ type ListAnswer = QueryListAnswer<unknown, unknown>;
6
+ type Answer = ListAnswer | QueryExistsAnswer | QueryCountAnswer;
7
+ /**
8
+ * The members a document counts against the Kernel's limit: each id, each value of an `in`, one
9
+ * for each other value atom. The Kernel may count fewer (it merges sets), never more.
10
+ */
11
+ export declare function membersOf(value: unknown): number;
12
+ /**
13
+ * The documents a read is sent as: itself, or one per slice of its root id list when it is past
14
+ * the members limit, each id in one slice only. `values` asks each slice for its root's values, so
15
+ * an ordered read can merge. A document whose members lie elsewhere is sent whole, and the Kernel
16
+ * names the limit.
17
+ */
18
+ export declare function split(document: QueryDocument, values: boolean): readonly QueryDocument[];
19
+ /**
20
+ * The answers of a split read as one: a list merged in the document's order and cut to its limit,
21
+ * `exists` if any slice has one, a count summed up to its bound.
22
+ */
23
+ export declare function merge(document: QueryDocument, answers: readonly Answer[]): Answer;
24
+ export {};
@@ -0,0 +1,190 @@
1
+ /**
2
+ * Long id lists (spec § Queries: the contract, § Semantics): a document past the Kernel's set
3
+ * members is sent as several, its root id list split, and their answers merged back in the
4
+ * Kernel's order and cut to the read's limit. Only a Node root's id list splits, and only for a
5
+ * read that is not a page: a page's cursor continues one document.
6
+ */
7
+ import { compareQueryText } from '@astrale-os/kernel-core/graph/query';
8
+ import { compareNodeIds } from '../../../platform/graph/node/index.js';
9
+ import { factKey } from '../answer/facts.js';
10
+ /** The Kernel's set members per v7 document: ids and value-set points, guards included. */
11
+ export const MAXIMUM_MEMBERS = 32_768;
12
+ const familyOf = (document) => 'list' in document ? 'list' : 'exists' in document ? 'exists' : 'count';
13
+ /**
14
+ * The members a document counts against the Kernel's limit: each id, each value of an `in`, one
15
+ * for each other value atom. The Kernel may count fewer (it merges sets), never more.
16
+ */
17
+ export function membersOf(value) {
18
+ if (Array.isArray(value))
19
+ return value.reduce((total, v) => total + membersOf(v), 0);
20
+ if (value === null || typeof value !== 'object')
21
+ return 0;
22
+ const record = value;
23
+ switch (record.op) {
24
+ case 'id':
25
+ return record.ids.length;
26
+ case 'in':
27
+ return record.values.length;
28
+ case 'eq':
29
+ case 'range':
30
+ case 'startsWith':
31
+ return 1;
32
+ case 'present':
33
+ case 'path':
34
+ case 'is':
35
+ return 0;
36
+ }
37
+ return Object.values(record).reduce((total, v) => total + membersOf(v), 0);
38
+ }
39
+ /** Where a Node root's id list is: its root, and the `id` atom with the most ids. */
40
+ function idList(document) {
41
+ const root = document[familyOf(document)];
42
+ if (!('nodes' in root))
43
+ return undefined;
44
+ const where = root.where;
45
+ if (where?.op === 'id')
46
+ return { root };
47
+ if (where?.op !== 'and')
48
+ return undefined;
49
+ let at;
50
+ let most = 0;
51
+ for (const [index, operand] of where.operands.entries()) {
52
+ const ids = operand.op === 'id' ? operand.ids.length : 0;
53
+ if (ids > most)
54
+ [at, most] = [index, ids];
55
+ }
56
+ return at === undefined ? undefined : { root, at };
57
+ }
58
+ /**
59
+ * The documents a read is sent as: itself, or one per slice of its root id list when it is past
60
+ * the members limit, each id in one slice only. `values` asks each slice for its root's values, so
61
+ * an ordered read can merge. A document whose members lie elsewhere is sent whole, and the Kernel
62
+ * names the limit.
63
+ */
64
+ export function split(document, values) {
65
+ const members = membersOf(document);
66
+ if (members <= MAXIMUM_MEMBERS)
67
+ return [document];
68
+ const found = idList(document);
69
+ if (found === undefined)
70
+ return [document];
71
+ const where = found.root.where;
72
+ const atom = found.at === undefined ? where : where.operands[found.at];
73
+ const listed = atom.ids;
74
+ const room = MAXIMUM_MEMBERS - (members - listed.length);
75
+ const ids = [...new Set(listed)];
76
+ if (room < 1)
77
+ return [document];
78
+ const family = familyOf(document);
79
+ const slices = [];
80
+ for (let start = 0; start < ids.length; start += room) {
81
+ const sliced = { op: 'id', ids: ids.slice(start, start + room) };
82
+ const operands = found.at === undefined ? undefined : [...where.operands];
83
+ if (operands !== undefined)
84
+ operands[found.at] = sliced;
85
+ const root = {
86
+ ...found.root,
87
+ where: operands === undefined ? sliced : { ...where, operands },
88
+ ...(values && family === 'list' ? { select: 'value' } : {}),
89
+ };
90
+ slices.push({ ...document, [family]: root });
91
+ }
92
+ return slices;
93
+ }
94
+ function rank(fact, property) {
95
+ if (fact === undefined || fact.withheld.includes(property))
96
+ return 'closed';
97
+ const value = fact.values[property];
98
+ if (value === undefined || value === null || typeof value === 'object')
99
+ return 'missing';
100
+ return { value: value };
101
+ }
102
+ function compareValues(left, right) {
103
+ if (typeof left === 'string' && typeof right === 'string')
104
+ return compareQueryText(left, right);
105
+ return Math.sign(Number(left) - Number(right));
106
+ }
107
+ /** Missing values sit first or last, closed ones after both; identity breaks every tie. */
108
+ function comparator(keys, facts) {
109
+ const bucket = (r, key) => r === 'closed'
110
+ ? 2
111
+ : r === 'missing'
112
+ ? key.missing === 'first'
113
+ ? 0
114
+ : 1
115
+ : key.missing === 'first'
116
+ ? 1
117
+ : 0;
118
+ return (left, right) => {
119
+ for (const key of keys) {
120
+ const a = rank(facts.get(factKey(left.fact)), key.property);
121
+ const b = rank(facts.get(factKey(right.fact)), key.property);
122
+ const buckets = bucket(a, key) - bucket(b, key);
123
+ if (buckets !== 0)
124
+ return buckets;
125
+ if (typeof a === 'object' && typeof b === 'object') {
126
+ const compared = compareValues(a.value, b.value);
127
+ if (compared !== 0)
128
+ return key.direction === 'asc' ? compared : -compared;
129
+ }
130
+ }
131
+ return compareNodeIds(left.fact, right.fact);
132
+ };
133
+ }
134
+ function undecidedOf(reported) {
135
+ const known = reported.filter((u) => u !== undefined);
136
+ if (known.length === 0)
137
+ return undefined;
138
+ return {
139
+ count: known.reduce((total, u) => total + u.count, 0),
140
+ more: known.some((u) => u.more),
141
+ };
142
+ }
143
+ /**
144
+ * The answers of a split read as one: a list merged in the document's order and cut to its limit,
145
+ * `exists` if any slice has one, a count summed up to its bound.
146
+ */
147
+ export function merge(document, answers) {
148
+ if (answers.length === 1)
149
+ return answers[0];
150
+ const json = document;
151
+ if ('exists' in json) {
152
+ const all = answers;
153
+ const undecided = all.some((a) => a.undecided === true);
154
+ return { exists: all.some((a) => a.exists), ...(undecided ? { undecided } : {}) };
155
+ }
156
+ if ('count' in json) {
157
+ const all = answers;
158
+ const upTo = json.upTo;
159
+ const sum = all.reduce((total, a) => total + a.count, 0);
160
+ const undecided = undecidedOf(all.map((a) => a.undecided));
161
+ return {
162
+ count: Math.min(sum, upTo),
163
+ more: sum > upTo || all.some((a) => a.more),
164
+ ...(undecided === undefined ? {} : { undecided }),
165
+ };
166
+ }
167
+ const lists = answers;
168
+ const root = json.list;
169
+ const facts = new Map();
170
+ for (const answer of lists)
171
+ for (const fact of answer.facts)
172
+ facts.set(factKey(fact.fact), fact);
173
+ const limit = root.limit;
174
+ const items = lists
175
+ .flatMap((answer) => answer.list.items)
176
+ .sort(comparator((root.orderBy ?? []), facts));
177
+ const undecided = undecidedOf(lists.map((a) => a.list.undecided));
178
+ const last = lists[lists.length - 1];
179
+ const revised = lists.some((a) => a.revised === true || a.revision !== lists[0].revision);
180
+ return {
181
+ list: {
182
+ items: items.slice(0, limit),
183
+ complete: items.length <= limit && lists.every((a) => a.list.complete),
184
+ ...(undecided === undefined ? {} : { undecided }),
185
+ },
186
+ facts: [...facts.values()],
187
+ revision: last.revision,
188
+ ...(revised ? { revised: true } : {}),
189
+ };
190
+ }
@@ -7,4 +7,12 @@ export declare class QueryPaginationError extends Error implements QueryFailure
7
7
  readonly name = "QueryPaginationError";
8
8
  constructor(code: QueryPaginationErrorCode, message: string);
9
9
  }
10
+ /**
11
+ * A value the Kernel returned does not have the shape its Class has in the Domain this client was
12
+ * built from: one of its Properties changed type, or a Property the client requires is absent.
13
+ */
14
+ export declare class QueryValueMismatchError extends Error implements QueryFailure {
15
+ readonly name = "QueryValueMismatchError";
16
+ readonly code = "QUERY_VALUE_MISMATCH";
17
+ }
10
18
  export declare function queryFailure(input: unknown): QueryFailure | undefined;
@@ -6,6 +6,14 @@ export class QueryPaginationError extends Error {
6
6
  this.code = code;
7
7
  }
8
8
  }
9
+ /**
10
+ * A value the Kernel returned does not have the shape its Class has in the Domain this client was
11
+ * built from: one of its Properties changed type, or a Property the client requires is absent.
12
+ */
13
+ export class QueryValueMismatchError extends Error {
14
+ name = 'QueryValueMismatchError';
15
+ code = 'QUERY_VALUE_MISMATCH';
16
+ }
9
17
  export function queryFailure(input) {
10
18
  if (!(input instanceof Error))
11
19
  return undefined;
@@ -0,0 +1,10 @@
1
+ /**
2
+ * The handles a Query's `build` receives (S1), built once per resolved Domain: its own Classes,
3
+ * each dependency under its alias, the Kernel's Classes under `kernel`, its Core nodes under
4
+ * `core`, `origin`, and `document`, the escape hatch (D23). The fixed names win over a Class or
5
+ * an alias of the same name.
6
+ */
7
+ import type { Domain } from '../../../platform/schema/index.js';
8
+ import type { Handles } from './handles.js';
9
+ /** The handles of a resolved Domain, built once. */
10
+ export declare function handlesOf<Schema>(domain: Domain): Handles<Schema>;
@@ -0,0 +1,53 @@
1
+ import { Path } from '../../../platform/graph/path/index.js';
2
+ import { QUERY } from '../language/query.js';
3
+ import { kernelClasses, modelOf } from './model.js';
4
+ import { RootRead } from './plan.js';
5
+ import { EdgeSet, NodeSet } from './reads.js';
6
+ import { CoreNode, describe } from './terms.js';
7
+ const FIXED = new Set(['kernel', 'core', 'origin', 'document']);
8
+ function classHandles(model, classes) {
9
+ const out = {};
10
+ for (const [name, c] of Object.entries(classes)) {
11
+ if (FIXED.has(name))
12
+ continue;
13
+ out[name] = c.kind === 'edge' ? EdgeSet.of(model, c) : NodeSet.of(model, c);
14
+ }
15
+ return Object.freeze(out);
16
+ }
17
+ /** One canonical document, its rows unknown (D23): the read checks only its version. */
18
+ function document(query) {
19
+ if (typeof query !== 'object' ||
20
+ query === null ||
21
+ query.query !== QUERY)
22
+ throw new TypeError(`d.document takes one canonical ${QUERY} document; got ${describe(query)}.`);
23
+ return new RootRead({
24
+ verb: 'document',
25
+ empty: false,
26
+ document: query,
27
+ });
28
+ }
29
+ const built = new WeakMap();
30
+ /** The handles of a resolved Domain, built once. */
31
+ export function handlesOf(domain) {
32
+ let handles = built.get(domain);
33
+ if (handles === undefined) {
34
+ const model = modelOf(domain);
35
+ const aliases = {};
36
+ for (const [alias, dependency] of Object.entries(domain.dependencies))
37
+ if (!FIXED.has(alias))
38
+ aliases[alias] = classHandles(model, dependency.classes);
39
+ const core = {};
40
+ for (const [name, node] of Object.entries(domain.core.nodes))
41
+ core[name] = new CoreNode(node.key, Path.project(node.ref).raw);
42
+ handles = Object.freeze({
43
+ ...aliases,
44
+ ...classHandles(model, domain.classes),
45
+ kernel: classHandles(model, kernelClasses()),
46
+ core: Object.freeze(core),
47
+ origin: domain.origin,
48
+ document,
49
+ });
50
+ built.set(domain, handles);
51
+ }
52
+ return handles;
53
+ }