@astrale-os/sdk 0.6.0-beta.6 → 0.6.0-beta.61

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 (717) hide show
  1. package/README.md +220 -66
  2. package/dist/application/action/action.d.ts +6 -0
  3. package/dist/application/action/authoring.d.ts +3 -1
  4. package/dist/application/action/authoring.js +1 -0
  5. package/dist/application/action/context.d.ts +95 -34
  6. package/dist/application/action/define.d.ts +3 -3
  7. package/dist/application/action/index.d.ts +3 -1
  8. package/dist/application/action/index.js +1 -0
  9. package/dist/application/define.d.ts +8 -6
  10. package/dist/application/define.js +28 -14
  11. package/dist/application/dependency/index.d.ts +1 -1
  12. package/dist/application/dependency/invoker.d.ts +21 -10
  13. package/dist/application/domain.d.ts +30 -0
  14. package/dist/application/error/error.d.ts +16 -1
  15. package/dist/application/error/error.js +40 -6
  16. package/dist/application/error/index.d.ts +1 -1
  17. package/dist/application/error/index.js +1 -1
  18. package/dist/application/file/binary.d.ts +11 -0
  19. package/dist/application/file/binary.js +45 -0
  20. package/dist/application/file/file.d.ts +77 -0
  21. package/dist/application/file/file.js +111 -0
  22. package/dist/application/file/index.d.ts +4 -0
  23. package/dist/application/file/index.js +2 -0
  24. package/dist/application/file/input.d.ts +13 -0
  25. package/dist/application/file/input.js +57 -0
  26. package/dist/application/index.d.ts +6 -5
  27. package/dist/application/index.js +1 -1
  28. package/dist/application/integration/define.d.ts +8 -1
  29. package/dist/application/integration/index.d.ts +2 -2
  30. package/dist/application/integration/integration.d.ts +13 -1
  31. package/dist/application/integration/operation.d.ts +16 -3
  32. package/dist/application/mutation/authoring/builder.d.ts +81 -33
  33. package/dist/application/mutation/authoring/builder.js +100 -30
  34. package/dist/application/mutation/authoring/guard.d.ts +37 -0
  35. package/dist/application/mutation/authoring/guard.js +150 -0
  36. package/dist/application/mutation/authoring/index.d.ts +5 -2
  37. package/dist/application/mutation/authoring/index.js +2 -1
  38. package/dist/application/mutation/authoring/names.d.ts +19 -0
  39. package/dist/application/mutation/authoring/names.js +83 -0
  40. package/dist/application/mutation/authoring/properties.d.ts +17 -4
  41. package/dist/application/mutation/authoring/properties.js +38 -2
  42. package/dist/application/mutation/authoring/transition.d.ts +3 -2
  43. package/dist/application/mutation/authoring/transition.js +4 -1
  44. package/dist/application/mutation/define.d.ts +24 -10
  45. package/dist/application/mutation/define.js +49 -53
  46. package/dist/application/mutation/execution/execute.d.ts +2 -2
  47. package/dist/application/mutation/execution/execute.js +78 -7
  48. package/dist/application/mutation/execution/executor.d.ts +4 -1
  49. package/dist/application/mutation/execution/executor.js +6 -1
  50. package/dist/application/mutation/failure.d.ts +17 -1
  51. package/dist/application/mutation/failure.js +40 -19
  52. package/dist/application/mutation/index.d.ts +9 -5
  53. package/dist/application/mutation/index.js +5 -2
  54. package/dist/application/mutation/legacy/v6/builder.d.ts +84 -0
  55. package/dist/application/mutation/legacy/v6/define.d.ts +18 -0
  56. package/dist/application/mutation/legacy/v6/define.js +56 -0
  57. package/dist/application/mutation/legacy/v6/mutation.d.ts +28 -0
  58. package/dist/application/mutation/{authoring → legacy/v6}/precondition.d.ts +4 -0
  59. package/dist/application/mutation/mutation.d.ts +47 -19
  60. package/dist/application/query/answer/answer.d.ts +117 -0
  61. package/dist/application/query/answer/conformance.d.ts +4 -0
  62. package/dist/application/query/answer/conformance.js +27 -0
  63. package/dist/application/query/answer/facts.d.ts +17 -0
  64. package/dist/application/query/answer/facts.js +57 -0
  65. package/dist/application/query/composite/builder.d.ts +1 -1
  66. package/dist/application/query/composite/builder.js +2 -2
  67. package/dist/application/query/composite/plan.d.ts +1 -5
  68. package/dist/application/query/composite/plan.js +1 -3
  69. package/dist/application/query/composite/query.d.ts +1 -2
  70. package/dist/application/query/define.d.ts +3 -34
  71. package/dist/application/query/define.js +5 -131
  72. package/dist/application/query/defined/define.d.ts +45 -0
  73. package/dist/application/query/defined/define.js +96 -0
  74. package/dist/application/query/defined/query.d.ts +139 -0
  75. package/dist/application/query/definition.d.ts +12 -0
  76. package/dist/application/query/definition.js +47 -0
  77. package/dist/application/query/execution/bounds.d.ts +22 -0
  78. package/dist/application/query/execution/bounds.js +88 -0
  79. package/dist/application/query/execution/client.d.ts +21 -0
  80. package/dist/application/query/execution/crossings.d.ts +30 -0
  81. package/dist/application/query/execution/crossings.js +232 -0
  82. package/dist/application/query/execution/error.d.ts +71 -0
  83. package/dist/application/query/execution/error.js +50 -0
  84. package/dist/application/query/execution/execute.d.ts +4 -10
  85. package/dist/application/query/execution/execute.js +3 -45
  86. package/dist/application/query/execution/executor.d.ts +2 -2
  87. package/dist/application/query/execution/legacy/declared-classes.d.ts +10 -0
  88. package/dist/application/query/execution/legacy/declared-classes.js +9 -0
  89. package/dist/application/query/execution/refusal.d.ts +37 -0
  90. package/dist/application/query/execution/refusal.js +80 -0
  91. package/dist/application/query/execution/rows.d.ts +42 -0
  92. package/dist/application/query/execution/rows.js +326 -0
  93. package/dist/application/query/execution/run.d.ts +85 -0
  94. package/dist/application/query/execution/run.js +372 -0
  95. package/dist/application/query/execution/split.d.ts +24 -0
  96. package/dist/application/query/execution/split.js +190 -0
  97. package/dist/application/query/failure.d.ts +8 -0
  98. package/dist/application/query/failure.js +8 -0
  99. package/dist/application/query/handles/build.d.ts +10 -0
  100. package/dist/application/query/handles/build.js +53 -0
  101. package/dist/application/query/handles/conditions.d.ts +94 -0
  102. package/dist/application/query/handles/domain.d.ts +157 -0
  103. package/dist/application/query/handles/handles.d.ts +285 -0
  104. package/dist/application/query/handles/handles.js +1 -0
  105. package/dist/application/query/handles/model.d.ts +106 -0
  106. package/dist/application/query/handles/model.js +261 -0
  107. package/dist/application/query/handles/plan.d.ts +100 -0
  108. package/dist/application/query/handles/plan.js +37 -0
  109. package/dist/application/query/handles/reads.d.ts +106 -0
  110. package/dist/application/query/handles/reads.js +978 -0
  111. package/dist/application/query/handles/relations.d.ts +106 -0
  112. package/dist/application/query/handles/relations.js +1 -0
  113. package/dist/application/query/handles/rows.d.ts +94 -0
  114. package/dist/application/query/handles/rows.js +4 -0
  115. package/dist/application/query/handles/terms.d.ts +103 -0
  116. package/dist/application/query/handles/terms.js +282 -0
  117. package/dist/application/query/index.d.ts +14 -8
  118. package/dist/application/query/index.js +10 -5
  119. package/dist/application/query/language/index.d.ts +2 -0
  120. package/dist/application/query/language/index.js +2 -0
  121. package/dist/application/query/language/query.d.ts +323 -0
  122. package/dist/application/query/language/query.js +2 -0
  123. package/dist/application/query/{collection → legacy/v6/collection}/identity.d.ts +2 -2
  124. package/dist/application/query/{collection → legacy/v6/collection}/metadata.d.ts +1 -1
  125. package/dist/application/query/{collection → legacy/v6/collection}/union.d.ts +4 -4
  126. package/dist/application/query/{collection → legacy/v6/collection}/union.js +15 -8
  127. package/dist/application/query/legacy/v6/conformance.d.ts +15 -0
  128. package/dist/application/query/legacy/v6/conformance.js +46 -0
  129. package/dist/application/query/legacy/v6/define.d.ts +37 -0
  130. package/dist/application/query/legacy/v6/define.js +90 -0
  131. package/dist/application/query/legacy/v6/execution/execute.d.ts +18 -0
  132. package/dist/application/query/legacy/v6/execution/execute.js +50 -0
  133. package/dist/application/query/legacy/v6/index.d.ts +7 -0
  134. package/dist/application/query/legacy/v6/index.js +3 -0
  135. package/dist/application/query/legacy/v6/kernel.d.ts +6 -0
  136. package/dist/application/query/legacy/v6/kernel.js +5 -0
  137. package/dist/application/query/{single → legacy/v6/single}/pagination.js +1 -1
  138. package/dist/application/query/{single → legacy/v6/single}/query.d.ts +2 -14
  139. package/dist/application/query/legacy/v6/single/query.js +1 -0
  140. package/dist/application/query/query.d.ts +19 -4
  141. package/dist/application/requirements/canonical.d.ts +7 -0
  142. package/dist/application/requirements/canonical.js +16 -0
  143. package/dist/application/requirements/classes.d.ts +9 -7
  144. package/dist/application/requirements/classes.js +35 -42
  145. package/dist/application/requirements/functions.d.ts +3 -1
  146. package/dist/application/requirements/functions.js +12 -27
  147. package/dist/application/requirements/index.d.ts +34 -16
  148. package/dist/application/requirements/index.js +17 -20
  149. package/dist/application/requirements/legacy/authority.d.ts +21 -0
  150. package/dist/application/requirements/{authority.js → legacy/authority.js} +5 -2
  151. package/dist/application/requirements/legacy/classes.d.ts +22 -0
  152. package/dist/application/requirements/legacy/classes.js +24 -0
  153. package/dist/application/requirements/legacy/core.d.ts +30 -0
  154. package/dist/application/requirements/{core.js → legacy/core.js} +15 -13
  155. package/dist/application/requirements/legacy/functions.d.ts +7 -0
  156. package/dist/application/requirements/legacy/functions.js +15 -0
  157. package/dist/application/requirements/legacy/index.d.ts +43 -0
  158. package/dist/application/requirements/legacy/index.js +1 -0
  159. package/dist/application/requirements/legacy/requirements.d.ts +31 -0
  160. package/dist/application/requirements/legacy/requirements.js +31 -0
  161. package/dist/application/requirements/requirement.d.ts +30 -19
  162. package/dist/application/requirements/roles.d.ts +17 -0
  163. package/dist/application/requirements/roles.js +62 -0
  164. package/dist/application/requirements/scopes.d.ts +16 -0
  165. package/dist/application/requirements/scopes.js +34 -0
  166. package/dist/application/routes/admission.d.ts +3 -3
  167. package/dist/application/routes/admission.js +3 -3
  168. package/dist/application/routes/index.d.ts +3 -2
  169. package/dist/application/routes/route.d.ts +3 -3
  170. package/dist/application/runtime/actions.js +3 -0
  171. package/dist/application/runtime/declarations.d.ts +6 -6
  172. package/dist/application/runtime/define.d.ts +5 -5
  173. package/dist/application/runtime/runtime.js +12 -0
  174. package/dist/application/runtime/workflows.d.ts +3 -1
  175. package/dist/application/runtime/workflows.js +3 -4
  176. package/dist/application/view/define.js +4 -6
  177. package/dist/application/view/frontend.d.ts +2 -2
  178. package/dist/application/view/index.d.ts +1 -1
  179. package/dist/application/view/route.d.ts +0 -14
  180. package/dist/application/view/route.js +1 -64
  181. package/dist/application/workflow/authoring.d.ts +3 -2
  182. package/dist/application/workflow/context.d.ts +8 -2
  183. package/dist/application/workflow/define.d.ts +4 -4
  184. package/dist/application/workflow/define.js +14 -9
  185. package/dist/application/workflow/durable.d.ts +211 -0
  186. package/dist/application/workflow/durable.js +1 -0
  187. package/dist/application/workflow/index.d.ts +3 -2
  188. package/dist/application/workflow/runner/inline.js +1 -0
  189. package/dist/application/workflow/runner/runner.d.ts +2 -2
  190. package/dist/application/workflow/workflow.d.ts +5 -3
  191. package/dist/deployment/adapter/adapter.d.ts +55 -13
  192. package/dist/deployment/adapter/bundle/bundle.d.ts +36 -0
  193. package/dist/deployment/adapter/bundle/bundle.js +1 -0
  194. package/dist/deployment/adapter/bundle/file.d.ts +10 -0
  195. package/dist/deployment/adapter/bundle/file.js +1 -0
  196. package/dist/deployment/adapter/bundle/index.d.ts +2 -0
  197. package/dist/deployment/adapter/bundle/index.js +1 -0
  198. package/dist/deployment/adapter/define.d.ts +4 -3
  199. package/dist/deployment/adapter/define.js +107 -23
  200. package/dist/deployment/adapter/index.d.ts +4 -3
  201. package/dist/deployment/adapter/index.js +1 -0
  202. package/dist/deployment/adapter/release/command.d.ts +33 -0
  203. package/dist/deployment/adapter/release/command.js +1 -0
  204. package/dist/deployment/adapter/release/context.d.ts +94 -0
  205. package/dist/deployment/adapter/release/context.js +1 -0
  206. package/dist/deployment/adapter/release/index.d.ts +4 -0
  207. package/dist/deployment/adapter/release/index.js +1 -0
  208. package/dist/deployment/adapter/release/list.d.ts +53 -0
  209. package/dist/deployment/adapter/release/list.js +1 -0
  210. package/dist/deployment/adapter/release/refusal.d.ts +10 -0
  211. package/dist/deployment/adapter/release/refusal.js +14 -0
  212. package/dist/deployment/adapter/release/result.d.ts +56 -0
  213. package/dist/deployment/adapter/release/result.js +1 -0
  214. package/dist/deployment/address/configuration.d.ts +96 -0
  215. package/dist/deployment/address/configuration.js +274 -0
  216. package/dist/deployment/address/fingerprint.d.ts +5 -0
  217. package/dist/deployment/address/fingerprint.js +27 -0
  218. package/dist/deployment/address/index.d.ts +5 -0
  219. package/dist/deployment/address/index.js +4 -0
  220. package/dist/deployment/address/label.d.ts +42 -0
  221. package/dist/deployment/address/label.js +80 -0
  222. package/dist/deployment/address/line.d.ts +29 -0
  223. package/dist/deployment/address/line.js +53 -0
  224. package/dist/deployment/address/record.d.ts +73 -0
  225. package/dist/deployment/address/record.js +138 -0
  226. package/dist/deployment/address/summary.d.ts +30 -0
  227. package/dist/deployment/address/summary.js +1 -0
  228. package/dist/deployment/address/vectors.d.ts +60 -0
  229. package/dist/deployment/address/vectors.js +517 -0
  230. package/dist/deployment/authoring.d.ts +0 -2
  231. package/dist/deployment/authoring.js +0 -1
  232. package/dist/deployment/build/build.d.ts +13 -2
  233. package/dist/deployment/build/compile.d.ts +4 -4
  234. package/dist/deployment/build/compile.js +31 -81
  235. package/dist/deployment/build/frontend/compilation.d.ts +2 -4
  236. package/dist/deployment/build/frontend/compilation.js +0 -5
  237. package/dist/deployment/build/frontend/digest.js +1 -5
  238. package/dist/deployment/build/index.d.ts +1 -0
  239. package/dist/deployment/build/index.js +1 -0
  240. package/dist/deployment/build/legacy/requirements.d.ts +11 -0
  241. package/dist/deployment/build/legacy/requirements.js +79 -0
  242. package/dist/deployment/build/manifest.d.ts +59 -0
  243. package/dist/deployment/build/manifest.js +118 -0
  244. package/dist/deployment/build/material.d.ts +2 -2
  245. package/dist/deployment/build/material.js +28 -13
  246. package/dist/deployment/build/schema.d.ts +2 -2
  247. package/dist/deployment/deployment.d.ts +3 -2
  248. package/dist/deployment/environment.d.ts +6 -0
  249. package/dist/deployment/environment.js +6 -0
  250. package/dist/deployment/index.d.ts +4 -6
  251. package/dist/deployment/index.js +1 -2
  252. package/dist/deployment/release/addressing.d.ts +6 -5
  253. package/dist/deployment/release/addressing.js +2 -3
  254. package/dist/deployment/release/assemble.d.ts +6 -3
  255. package/dist/deployment/release/assemble.js +12 -10
  256. package/dist/deployment/release/release.d.ts +16 -5
  257. package/dist/deployment/release/seal.d.ts +14 -0
  258. package/dist/deployment/release/seal.js +22 -0
  259. package/dist/deployment/release/{publication → served}/callables.d.ts +2 -2
  260. package/dist/deployment/release/{publication → served}/callables.js +2 -2
  261. package/dist/deployment/release/served/index.d.ts +11 -0
  262. package/dist/deployment/release/served/index.js +26 -0
  263. package/dist/deployment/release/{publication → served}/views.d.ts +2 -2
  264. package/dist/deployment/release/{publication → served}/views.js +0 -1
  265. package/dist/deployment/runtime/admission.d.ts +2 -2
  266. package/dist/deployment/runtime/admission.js +5 -5
  267. package/dist/deployment/verify/index.d.ts +3 -4
  268. package/dist/deployment/verify/index.js +2 -3
  269. package/dist/deployment/verify/preflight/bundle.d.ts +18 -0
  270. package/dist/deployment/verify/preflight/bundle.js +71 -0
  271. package/dist/deployment/verify/preflight/index.d.ts +1 -12
  272. package/dist/deployment/verify/preflight/index.js +1 -12
  273. package/dist/deployment/verify/readiness/fetch.d.ts +13 -0
  274. package/dist/deployment/verify/readiness/fetch.js +26 -0
  275. package/dist/deployment/verify/readiness/identity.d.ts +3 -6
  276. package/dist/deployment/verify/readiness/identity.js +3 -3
  277. package/dist/deployment/verify/readiness/index.d.ts +15 -8
  278. package/dist/deployment/verify/readiness/index.js +25 -6
  279. package/dist/deployment/verify/readiness/release.d.ts +8 -0
  280. package/dist/deployment/verify/readiness/release.js +22 -0
  281. package/dist/deployment/worker/address.d.ts +26 -0
  282. package/dist/deployment/worker/address.js +43 -0
  283. package/dist/deployment/worker/build.d.ts +60 -0
  284. package/dist/deployment/worker/build.js +172 -0
  285. package/dist/deployment/worker/configuration.d.ts +73 -0
  286. package/dist/deployment/worker/configuration.js +165 -0
  287. package/dist/deployment/worker/content.d.ts +38 -0
  288. package/dist/deployment/worker/content.js +169 -0
  289. package/dist/deployment/worker/index.d.ts +29 -0
  290. package/dist/deployment/worker/index.js +29 -0
  291. package/dist/deployment/worker/limits.d.ts +30 -0
  292. package/dist/deployment/worker/limits.js +30 -0
  293. package/dist/deployment/worker/record.d.ts +29 -0
  294. package/dist/deployment/worker/record.js +69 -0
  295. package/dist/deployment/worker/request.d.ts +118 -0
  296. package/dist/deployment/worker/request.js +280 -0
  297. package/dist/deployment/worker/response.d.ts +101 -0
  298. package/dist/deployment/worker/response.js +207 -0
  299. package/dist/execution/cache/cache.d.ts +17 -0
  300. package/dist/execution/cache/cache.js +11 -0
  301. package/dist/execution/cache/index.d.ts +2 -0
  302. package/dist/execution/cache/index.js +2 -0
  303. package/dist/execution/cache/memory.d.ts +13 -0
  304. package/dist/execution/cache/memory.js +48 -0
  305. package/dist/execution/identity/authentication.d.ts +33 -3
  306. package/dist/execution/identity/authentication.js +95 -36
  307. package/dist/execution/identity/callback.d.ts +20 -20
  308. package/dist/execution/identity/callback.js +34 -26
  309. package/dist/execution/identity/delivery.d.ts +6 -4
  310. package/dist/execution/identity/delivery.js +25 -20
  311. package/dist/execution/identity/exchange.js +11 -1
  312. package/dist/execution/identity/identity.d.ts +17 -3
  313. package/dist/execution/identity/identity.js +12 -4
  314. package/dist/execution/identity/jwks.d.ts +5 -0
  315. package/dist/execution/identity/jwks.js +92 -102
  316. package/dist/execution/index.d.ts +6 -4
  317. package/dist/execution/index.js +4 -2
  318. package/dist/execution/invocation/admission/age.d.ts +57 -0
  319. package/dist/execution/invocation/admission/age.js +208 -0
  320. package/dist/execution/invocation/admission/authentication.d.ts +13 -13
  321. package/dist/execution/invocation/admission/authentication.js +52 -44
  322. package/dist/execution/invocation/admission/authority.d.ts +28 -6
  323. package/dist/execution/invocation/admission/authority.js +9 -2
  324. package/dist/execution/invocation/admission/index.d.ts +4 -3
  325. package/dist/execution/invocation/admission/index.js +3 -2
  326. package/dist/execution/invocation/admission/input.d.ts +2 -2
  327. package/dist/execution/invocation/admission/input.js +16 -2
  328. package/dist/execution/invocation/admission/target.d.ts +11 -0
  329. package/dist/execution/invocation/admission/target.js +22 -3
  330. package/dist/execution/invocation/capabilities/bind.d.ts +14 -0
  331. package/dist/execution/invocation/capabilities/bind.js +74 -0
  332. package/dist/execution/invocation/capabilities/index.d.ts +1 -0
  333. package/dist/execution/invocation/capabilities/index.js +1 -0
  334. package/dist/execution/invocation/dependency/bind.d.ts +3 -1
  335. package/dist/execution/invocation/dependency/bind.js +36 -16
  336. package/dist/execution/invocation/dispatch/action.js +4 -2
  337. package/dist/execution/invocation/dispatch/context.d.ts +8 -7
  338. package/dist/execution/invocation/dispatch/context.js +34 -45
  339. package/dist/execution/invocation/dispatch/workflow.js +4 -6
  340. package/dist/execution/invocation/handler.js +8 -2
  341. package/dist/execution/invocation/index.d.ts +2 -2
  342. package/dist/execution/invocation/index.js +1 -1
  343. package/dist/execution/invocation/integration/authentication.d.ts +3 -3
  344. package/dist/execution/invocation/integration/authentication.js +7 -7
  345. package/dist/execution/invocation/integration/call.d.ts +2 -1
  346. package/dist/execution/invocation/integration/call.js +3 -3
  347. package/dist/execution/invocation/integration/clients.d.ts +1 -1
  348. package/dist/execution/invocation/integration/index.d.ts +1 -0
  349. package/dist/execution/invocation/integration/index.js +1 -0
  350. package/dist/execution/invocation/invocation.d.ts +6 -0
  351. package/dist/execution/invocation/invocation.js +130 -22
  352. package/dist/execution/invocation/lifecycle/active.d.ts +8 -2
  353. package/dist/execution/invocation/lifecycle/active.js +3 -3
  354. package/dist/execution/invocation/lifecycle/index.d.ts +1 -1
  355. package/dist/execution/invocation/result/errors.d.ts +0 -10
  356. package/dist/execution/invocation/result/errors.js +12 -16
  357. package/dist/execution/invocation/result/index.d.ts +3 -2
  358. package/dist/execution/invocation/result/index.js +2 -1
  359. package/dist/execution/invocation/result/project.js +41 -1
  360. package/dist/execution/invocation/result/undeclared.d.ts +7 -0
  361. package/dist/execution/invocation/result/undeclared.js +18 -0
  362. package/dist/execution/node/serve.d.ts +2 -2
  363. package/dist/execution/node/serve.js +1 -1
  364. package/dist/execution/runtime/index.d.ts +1 -0
  365. package/dist/execution/runtime/index.js +1 -0
  366. package/dist/execution/runtime/load.d.ts +3 -3
  367. package/dist/execution/runtime/load.js +3 -2
  368. package/dist/execution/runtime/release.d.ts +17 -0
  369. package/dist/execution/runtime/release.js +7 -0
  370. package/dist/execution/serve.d.ts +18 -4
  371. package/dist/execution/serve.js +10 -0
  372. package/dist/execution/service/create.js +43 -7
  373. package/dist/execution/service/initialization.d.ts +4 -4
  374. package/dist/execution/service/initialization.js +23 -14
  375. package/dist/execution/service/release.d.ts +2 -2
  376. package/dist/execution/service/release.js +3 -2
  377. package/dist/execution/service/service.d.ts +20 -5
  378. package/dist/execution/service/serving/delivery.d.ts +5 -0
  379. package/dist/execution/service/{publication → serving}/delivery.js +4 -1
  380. package/dist/execution/service/{publication → serving}/index.d.ts +1 -1
  381. package/dist/execution/service/serving/installation.d.ts +4 -0
  382. package/dist/execution/service/serving/installation.js +9 -0
  383. package/dist/execution/service/serving/source.d.ts +11 -0
  384. package/dist/execution/service/serving/source.js +15 -0
  385. package/dist/execution/workflows/attempts.d.ts +87 -0
  386. package/dist/execution/workflows/attempts.js +205 -0
  387. package/dist/execution/workflows/discovery.d.ts +14 -0
  388. package/dist/execution/workflows/discovery.js +151 -0
  389. package/dist/execution/workflows/engine.d.ts +83 -0
  390. package/dist/execution/workflows/engine.js +1 -0
  391. package/dist/execution/workflows/envelope.d.ts +12 -0
  392. package/dist/execution/workflows/envelope.js +46 -0
  393. package/dist/execution/workflows/failure.d.ts +56 -0
  394. package/dist/execution/workflows/failure.js +204 -0
  395. package/dist/execution/workflows/index.d.ts +4 -0
  396. package/dist/execution/workflows/index.js +3 -0
  397. package/dist/execution/workflows/integrations.d.ts +13 -0
  398. package/dist/execution/workflows/integrations.js +25 -0
  399. package/dist/execution/workflows/options.d.ts +81 -0
  400. package/dist/execution/workflows/options.js +158 -0
  401. package/dist/execution/workflows/receiver.d.ts +24 -0
  402. package/dist/execution/workflows/receiver.js +99 -0
  403. package/dist/execution/workflows/route.d.ts +12 -0
  404. package/dist/execution/workflows/route.js +35 -0
  405. package/dist/execution/workflows/run.d.ts +23 -0
  406. package/dist/execution/workflows/run.js +369 -0
  407. package/dist/execution/workflows/steps.d.ts +48 -0
  408. package/dist/execution/workflows/steps.js +93 -0
  409. package/dist/index.d.ts +5 -5
  410. package/dist/index.js +2 -2
  411. package/dist/platform/graph/alias.d.ts +1 -5
  412. package/dist/platform/graph/alias.js +1 -5
  413. package/dist/platform/graph/document/index.d.ts +1 -1
  414. package/dist/platform/graph/document/index.js +1 -1
  415. package/dist/platform/graph/index.d.ts +1 -1
  416. package/dist/platform/graph/index.js +1 -1
  417. package/dist/platform/release/index.d.ts +2 -0
  418. package/dist/platform/release/index.js +2 -0
  419. package/dist/platform/schema/callable-authoring.d.ts +21 -0
  420. package/dist/platform/schema/callable-authoring.js +27 -0
  421. package/dist/platform/schema/class-authoring.d.ts +58 -12
  422. package/dist/platform/schema/class-authoring.js +38 -4
  423. package/dist/platform/schema/class-icon-svg.d.ts +9 -0
  424. package/dist/platform/schema/class-icon-svg.js +29 -0
  425. package/dist/platform/schema/class-icon.d.ts +3 -8
  426. package/dist/platform/schema/class-icon.js +2 -29
  427. package/dist/platform/schema/index.d.ts +11 -4
  428. package/dist/platform/schema/index.js +2 -1
  429. package/dist/platform/schema/kernel-compiled.d.ts +2 -0
  430. package/dist/platform/schema/kernel-compiled.js +2 -0
  431. package/dist/platform/schema/kernel.d.ts +4 -2
  432. package/dist/platform/schema/property.d.ts +5 -0
  433. package/dist/platform/schema/references/index.d.ts +6 -0
  434. package/dist/platform/schema/references/index.js +1 -0
  435. package/dist/platform/schema/schema-authoring.d.ts +14 -7
  436. package/dist/platform/schema/schema-authoring.js +5 -1
  437. package/dist/platform/versioning/dependents.d.ts +18 -0
  438. package/dist/platform/versioning/dependents.js +15 -0
  439. package/dist/platform/versioning/index.d.ts +5 -0
  440. package/dist/platform/versioning/index.js +5 -0
  441. package/dist/platform/versioning/name.d.ts +38 -0
  442. package/dist/platform/versioning/name.js +58 -0
  443. package/dist/platform/versioning/reference.d.ts +48 -0
  444. package/dist/platform/versioning/reference.js +95 -0
  445. package/dist/platform/versioning/version.d.ts +72 -0
  446. package/dist/platform/versioning/version.js +98 -0
  447. package/dist/project/admit.js +1 -5
  448. package/dist/project/define.d.ts +4 -4
  449. package/dist/project/define.js +55 -35
  450. package/dist/project/index.d.ts +1 -1
  451. package/dist/project/install-command.d.ts +6 -0
  452. package/dist/project/install-command.js +9 -0
  453. package/dist/project/project.d.ts +10 -8
  454. package/dist/testing/dataset/define.d.ts +1 -1
  455. package/dist/testing/durable/engine.d.ts +128 -0
  456. package/dist/testing/durable/engine.js +619 -0
  457. package/dist/testing/durable/index.d.ts +3 -0
  458. package/dist/testing/durable/index.js +1 -0
  459. package/dist/testing/durable/steps.d.ts +30 -0
  460. package/dist/testing/durable/steps.js +45 -0
  461. package/dist/testing/file.d.ts +20 -0
  462. package/dist/testing/file.js +49 -0
  463. package/dist/testing/index.d.ts +10 -1
  464. package/dist/testing/index.js +7 -1
  465. package/dist/testing/load.js +1 -1
  466. package/dist/testing/query.d.ts +22 -0
  467. package/dist/testing/query.js +36 -0
  468. package/dist/tooling/cli/adapter-command.d.ts +35 -0
  469. package/dist/tooling/cli/adapter-command.js +66 -0
  470. package/dist/tooling/cli/arguments.d.ts +17 -6
  471. package/dist/tooling/cli/arguments.js +175 -52
  472. package/dist/tooling/cli/build.d.ts +55 -0
  473. package/dist/tooling/cli/build.js +77 -0
  474. package/dist/tooling/cli/bun.d.ts +0 -1
  475. package/dist/tooling/cli/bun.js +0 -7
  476. package/dist/tooling/cli/commit.d.ts +35 -0
  477. package/dist/tooling/cli/commit.js +235 -0
  478. package/dist/tooling/cli/deploy-mode.d.ts +26 -0
  479. package/dist/tooling/cli/deploy-mode.js +59 -0
  480. package/dist/tooling/cli/deploy-result.d.ts +80 -0
  481. package/dist/tooling/cli/deploy-result.js +64 -0
  482. package/dist/tooling/cli/diff/declared.d.ts +7 -0
  483. package/dist/tooling/cli/diff/declared.js +27 -0
  484. package/dist/tooling/cli/diff/index.d.ts +30 -0
  485. package/dist/tooling/cli/diff/index.js +58 -0
  486. package/dist/tooling/cli/diff/render.d.ts +15 -0
  487. package/dist/tooling/cli/diff/render.js +131 -0
  488. package/dist/tooling/cli/diff/report.d.ts +88 -0
  489. package/dist/tooling/cli/diff/report.js +154 -0
  490. package/dist/tooling/cli/dotenv.d.ts +5 -5
  491. package/dist/tooling/cli/dotenv.js +6 -36
  492. package/dist/tooling/cli/help.js +173 -60
  493. package/dist/tooling/cli/immutable-deployment.d.ts +83 -0
  494. package/dist/tooling/cli/immutable-deployment.js +135 -0
  495. package/dist/tooling/cli/index.d.ts +12 -4
  496. package/dist/tooling/cli/index.js +6 -3
  497. package/dist/tooling/cli/installed-on.d.ts +83 -0
  498. package/dist/tooling/cli/installed-on.js +156 -0
  499. package/dist/tooling/cli/list.d.ts +152 -0
  500. package/dist/tooling/cli/list.js +331 -0
  501. package/dist/tooling/cli/log.d.ts +5 -2
  502. package/dist/tooling/cli/log.js +9 -2
  503. package/dist/tooling/cli/orchestrate.d.ts +0 -6
  504. package/dist/tooling/cli/orchestrate.js +252 -91
  505. package/dist/tooling/cli/project.d.ts +3 -3
  506. package/dist/tooling/cli/publish/index.d.ts +81 -0
  507. package/dist/tooling/cli/publish/index.js +383 -0
  508. package/dist/tooling/cli/publish/report.d.ts +49 -0
  509. package/dist/tooling/cli/publish/report.js +15 -0
  510. package/dist/tooling/cli/registry/client.d.ts +121 -0
  511. package/dist/tooling/cli/registry/client.js +354 -0
  512. package/dist/tooling/cli/registry/error.d.ts +11 -0
  513. package/dist/tooling/cli/registry/error.js +17 -0
  514. package/dist/tooling/cli/registry/executable.d.ts +35 -0
  515. package/dist/tooling/cli/registry/executable.js +96 -0
  516. package/dist/tooling/cli/registry/index.d.ts +9 -0
  517. package/dist/tooling/cli/registry/index.js +8 -0
  518. package/dist/tooling/cli/registry/installations.d.ts +67 -0
  519. package/dist/tooling/cli/registry/installations.js +108 -0
  520. package/dist/tooling/cli/registry/process.d.ts +36 -0
  521. package/dist/tooling/cli/registry/process.js +119 -0
  522. package/dist/tooling/cli/secrets.d.ts +9 -0
  523. package/dist/tooling/cli/secrets.js +19 -0
  524. package/dist/tooling/cli/yank.d.ts +34 -0
  525. package/dist/tooling/cli/yank.js +32 -0
  526. package/dist/tooling/linter/adapters/typescript/definition-calls.d.ts +34 -0
  527. package/dist/tooling/linter/adapters/typescript/definition-calls.js +88 -0
  528. package/dist/tooling/linter/adapters/typescript/discover.js +8 -2
  529. package/dist/tooling/linter/adapters/typescript/imports.d.ts +0 -1
  530. package/dist/tooling/linter/adapters/typescript/imports.js +1 -5
  531. package/dist/tooling/linter/adapters/typescript/index.d.ts +9 -2
  532. package/dist/tooling/linter/adapters/typescript/index.js +4 -2
  533. package/dist/tooling/linter/adapters/typescript/legacy.d.ts +20 -0
  534. package/dist/tooling/linter/adapters/typescript/legacy.js +28 -0
  535. package/dist/tooling/linter/adapters/typescript/query-observation.js +37 -12
  536. package/dist/tooling/linter/adapters/typescript/syntax.d.ts +3 -3
  537. package/dist/tooling/linter/adapters/typescript/syntax.js +13 -25
  538. package/dist/tooling/linter/adapters/typescript/type-analysis.d.ts +2 -0
  539. package/dist/tooling/linter/adapters/typescript/type-analysis.js +10 -0
  540. package/dist/tooling/linter/implementations/source/callable-requirements.d.ts +2 -4
  541. package/dist/tooling/linter/implementations/source/callable-requirements.js +16 -58
  542. package/dist/tooling/linter/implementations/source/const-initializer.d.ts +3 -0
  543. package/dist/tooling/linter/implementations/source/const-initializer.js +31 -0
  544. package/dist/tooling/linter/implementations/source/definitions.d.ts +2 -0
  545. package/dist/tooling/linter/implementations/source/definitions.js +425 -0
  546. package/dist/tooling/linter/implementations/source/dependencies.js +13 -72
  547. package/dist/tooling/linter/implementations/source/domain-requirements.d.ts +8 -0
  548. package/dist/tooling/linter/implementations/source/domain-requirements.js +35 -0
  549. package/dist/tooling/linter/implementations/source/global.js +39 -19
  550. package/dist/tooling/linter/implementations/source/legacy/requirements.d.ts +10 -0
  551. package/dist/tooling/linter/implementations/source/legacy/requirements.js +40 -0
  552. package/dist/tooling/linter/implementations/source/legacy-folders.d.ts +3 -0
  553. package/dist/tooling/linter/implementations/source/legacy-folders.js +126 -0
  554. package/dist/tooling/linter/implementations/source/mutations.js +153 -70
  555. package/dist/tooling/linter/implementations/source/policy-edges.d.ts +2 -0
  556. package/dist/tooling/linter/implementations/source/policy-edges.js +113 -0
  557. package/dist/tooling/linter/implementations/source/providers.js +5 -5
  558. package/dist/tooling/linter/implementations/source/queries.js +1 -17
  559. package/dist/tooling/linter/implementations/source/requirement-entries.d.ts +24 -0
  560. package/dist/tooling/linter/implementations/source/requirement-entries.js +52 -0
  561. package/dist/tooling/linter/implementations/source/runtime-imports.d.ts +2 -0
  562. package/dist/tooling/linter/implementations/source/runtime-imports.js +119 -0
  563. package/dist/tooling/linter/implementations/source/schema.d.ts +3 -0
  564. package/dist/tooling/linter/implementations/source/schema.js +9 -5
  565. package/dist/tooling/linter/implementations/source/shared.d.ts +19 -5
  566. package/dist/tooling/linter/implementations/source/shared.js +131 -55
  567. package/dist/tooling/linter/implementations/source/tests.js +1 -1
  568. package/dist/tooling/linter/implementations/source/verifiers.js +8 -2
  569. package/dist/tooling/linter/implementations/source/views.js +2 -2
  570. package/dist/tooling/linter/implementations/source/workflows.js +499 -17
  571. package/dist/tooling/linter/policy/generated.js +18 -67
  572. package/dist/tooling/linter/requirements/registry.js +14 -9
  573. package/dist/tooling/packaging/declarations/ownership.js +1 -1
  574. package/dist/tooling/packaging/finalize.d.ts +1 -1
  575. package/dist/tooling/packaging/finalize.js +1 -1
  576. package/docs/accounts/scenarios.tsv +12 -0
  577. package/docs/admission-age.md +88 -0
  578. package/docs/auth-api-migration.md +57 -0
  579. package/docs/business-errors.md +42 -0
  580. package/docs/domain-definition-migration.md +44 -0
  581. package/docs/domain-schema-migration.md +36 -0
  582. package/docs/durable-workflows.md +530 -0
  583. package/docs/handler-dependencies.md +381 -0
  584. package/docs/legacy/query-v6.md +62 -0
  585. package/docs/legacy.md +113 -0
  586. package/docs/queries.md +493 -0
  587. package/docs/release.md +155 -0
  588. package/docs/requirements.md +143 -0
  589. package/docs/schema-cost.md +124 -0
  590. package/package.json +62 -26
  591. package/dist/application/application.d.ts +0 -28
  592. package/dist/application/query/execution/projection.d.ts +0 -3
  593. package/dist/application/query/execution/projection.js +0 -3
  594. package/dist/application/requirements/authority.d.ts +0 -7
  595. package/dist/application/requirements/core.d.ts +0 -14
  596. package/dist/deployment/adapter/deploy/context.d.ts +0 -15
  597. package/dist/deployment/adapter/deploy/index.d.ts +0 -2
  598. package/dist/deployment/adapter/deploy/result.d.ts +0 -50
  599. package/dist/deployment/adapter/prepare/artifact.d.ts +0 -33
  600. package/dist/deployment/adapter/prepare/context.d.ts +0 -23
  601. package/dist/deployment/adapter/prepare/index.d.ts +0 -2
  602. package/dist/deployment/deploy.d.ts +0 -20
  603. package/dist/deployment/deploy.js +0 -31
  604. package/dist/deployment/release/publication/index.d.ts +0 -6
  605. package/dist/deployment/release/publication/index.js +0 -6
  606. package/dist/deployment/release/publication/manifest.d.ts +0 -3
  607. package/dist/deployment/release/publication/manifest.js +0 -5
  608. package/dist/deployment/release/publication/requirements.d.ts +0 -3
  609. package/dist/deployment/release/publication/requirements.js +0 -3
  610. package/dist/deployment/release/publication/seal.d.ts +0 -10
  611. package/dist/deployment/release/publication/seal.js +0 -39
  612. package/dist/deployment/verify/preflight/artifact.d.ts +0 -6
  613. package/dist/deployment/verify/preflight/artifact.js +0 -122
  614. package/dist/deployment/verify/preflight/publication.d.ts +0 -4
  615. package/dist/deployment/verify/preflight/publication.js +0 -14
  616. package/dist/deployment/verify/readiness/deployment.d.ts +0 -3
  617. package/dist/deployment/verify/readiness/deployment.js +0 -151
  618. package/dist/deployment/verify/readiness/publication.d.ts +0 -11
  619. package/dist/deployment/verify/readiness/publication.js +0 -41
  620. package/dist/execution/service/errors.d.ts +0 -3
  621. package/dist/execution/service/errors.js +0 -3
  622. package/dist/execution/service/publication/delivery.d.ts +0 -2
  623. package/dist/execution/service/publication/installation.d.ts +0 -3
  624. package/dist/execution/service/publication/installation.js +0 -8
  625. package/dist/execution/service/publication/source.d.ts +0 -3
  626. package/dist/execution/service/publication/source.js +0 -11
  627. package/dist/platform/publication/index.d.ts +0 -2
  628. package/dist/platform/publication/index.js +0 -2
  629. package/dist/tooling/cli/astrale/authority.d.ts +0 -5
  630. package/dist/tooling/cli/astrale/authority.js +0 -11
  631. package/dist/tooling/cli/astrale/executable.d.ts +0 -2
  632. package/dist/tooling/cli/astrale/executable.js +0 -47
  633. package/dist/tooling/cli/astrale/failure.d.ts +0 -6
  634. package/dist/tooling/cli/astrale/failure.js +0 -48
  635. package/dist/tooling/cli/astrale/instance.d.ts +0 -11
  636. package/dist/tooling/cli/astrale/instance.js +0 -52
  637. package/dist/tooling/cli/astrale/process.d.ts +0 -13
  638. package/dist/tooling/cli/astrale/process.js +0 -94
  639. package/dist/tooling/cli/astrale/version.d.ts +0 -18
  640. package/dist/tooling/cli/astrale/version.js +0 -55
  641. package/dist/tooling/cli/credential.d.ts +0 -2
  642. package/dist/tooling/cli/credential.js +0 -57
  643. package/dist/tooling/cli/deprecations.d.ts +0 -9
  644. package/dist/tooling/cli/deprecations.js +0 -15
  645. package/dist/tooling/cli/development/candidate.d.ts +0 -25
  646. package/dist/tooling/cli/development/candidate.js +0 -176
  647. package/dist/tooling/cli/development/deployment.d.ts +0 -16
  648. package/dist/tooling/cli/development/deployment.js +0 -39
  649. package/dist/tooling/cli/development/develop.d.ts +0 -11
  650. package/dist/tooling/cli/development/develop.js +0 -243
  651. package/dist/tooling/cli/development/lease.d.ts +0 -18
  652. package/dist/tooling/cli/development/lease.js +0 -163
  653. package/dist/tooling/cli/development/lifecycle.d.ts +0 -9
  654. package/dist/tooling/cli/development/lifecycle.js +0 -43
  655. package/dist/tooling/cli/development/project-imports.d.ts +0 -22
  656. package/dist/tooling/cli/development/project-imports.js +0 -39
  657. package/dist/tooling/cli/development/project-lock.d.ts +0 -16
  658. package/dist/tooling/cli/development/project-lock.js +0 -41
  659. package/dist/tooling/cli/development/rebuild.d.ts +0 -13
  660. package/dist/tooling/cli/development/rebuild.js +0 -58
  661. package/dist/tooling/cli/development/release-evidence.d.ts +0 -4
  662. package/dist/tooling/cli/development/release-evidence.js +0 -10
  663. package/dist/tooling/cli/development/report.d.ts +0 -6
  664. package/dist/tooling/cli/development/report.js +0 -14
  665. package/dist/tooling/cli/development/session-file.d.ts +0 -53
  666. package/dist/tooling/cli/development/session-file.js +0 -337
  667. package/dist/tooling/cli/development/source-watch.d.ts +0 -14
  668. package/dist/tooling/cli/development/source-watch.js +0 -140
  669. package/dist/tooling/cli/development/sources.d.ts +0 -7
  670. package/dist/tooling/cli/development/sources.js +0 -48
  671. package/dist/tooling/cli/development/target-lock.d.ts +0 -16
  672. package/dist/tooling/cli/development/target-lock.js +0 -68
  673. package/dist/tooling/cli/development/view.d.ts +0 -28
  674. package/dist/tooling/cli/development/view.js +0 -151
  675. package/dist/tooling/cli/environment-release.d.ts +0 -21
  676. package/dist/tooling/cli/environment-release.js +0 -46
  677. package/dist/tooling/cli/evidence.d.ts +0 -11
  678. package/dist/tooling/cli/evidence.js +0 -53
  679. package/dist/tooling/cli/installation/index.d.ts +0 -2
  680. package/dist/tooling/cli/installation/index.js +0 -1
  681. package/dist/tooling/cli/installation/observation.d.ts +0 -10
  682. package/dist/tooling/cli/installation/observation.js +0 -44
  683. package/dist/tooling/cli/installation/reconcile.d.ts +0 -32
  684. package/dist/tooling/cli/installation/reconcile.js +0 -122
  685. package/dist/tooling/linter/implementations/source/migrations.d.ts +0 -2
  686. package/dist/tooling/linter/implementations/source/migrations.js +0 -113
  687. package/dist/tooling/linter/qualification/index.d.ts +0 -10
  688. package/dist/tooling/linter/qualification/index.js +0 -2
  689. package/dist/tooling/linter/qualification/query-fixtures.d.ts +0 -2
  690. package/dist/tooling/linter/qualification/query-fixtures.js +0 -68
  691. package/dist/tooling/linter/qualification/runner.d.ts +0 -3
  692. package/dist/tooling/linter/qualification/runner.js +0 -6
  693. /package/dist/application/{application.js → domain.js} +0 -0
  694. /package/dist/application/{query/single/query.js → mutation/legacy/v6/builder.js} +0 -0
  695. /package/dist/{deployment/adapter/deploy/context.js → application/mutation/legacy/v6/mutation.js} +0 -0
  696. /package/dist/application/mutation/{authoring → legacy/v6}/precondition.js +0 -0
  697. /package/dist/{deployment/adapter/deploy/index.js → application/query/answer/answer.js} +0 -0
  698. /package/dist/{deployment/adapter/deploy/result.js → application/query/defined/query.js} +0 -0
  699. /package/dist/{deployment/adapter/prepare/artifact.js → application/query/execution/client.js} +0 -0
  700. /package/dist/{deployment/adapter/prepare/context.js → application/query/handles/conditions.js} +0 -0
  701. /package/dist/{deployment/adapter/prepare/index.js → application/query/handles/domain.js} +0 -0
  702. /package/dist/application/query/{collection → legacy/v6/collection}/identity.js +0 -0
  703. /package/dist/application/query/{collection → legacy/v6/collection}/limits.d.ts +0 -0
  704. /package/dist/application/query/{collection → legacy/v6/collection}/limits.js +0 -0
  705. /package/dist/application/query/{collection → legacy/v6/collection}/metadata.js +0 -0
  706. /package/dist/application/query/{execution → legacy/v6/execution}/pages.d.ts +0 -0
  707. /package/dist/application/query/{execution → legacy/v6/execution}/pages.js +0 -0
  708. /package/dist/application/query/{single → legacy/v6/single}/index.d.ts +0 -0
  709. /package/dist/application/query/{single → legacy/v6/single}/index.js +0 -0
  710. /package/dist/application/query/{single → legacy/v6/single}/node.d.ts +0 -0
  711. /package/dist/application/query/{single → legacy/v6/single}/node.js +0 -0
  712. /package/dist/application/query/{single → legacy/v6/single}/pagination.d.ts +0 -0
  713. /package/dist/application/query/{single → legacy/v6/single}/selection.d.ts +0 -0
  714. /package/dist/application/query/{single → legacy/v6/single}/selection.js +0 -0
  715. /package/dist/deployment/release/{publication → served}/routes.d.ts +0 -0
  716. /package/dist/deployment/release/{publication → served}/routes.js +0 -0
  717. /package/dist/execution/service/{publication → serving}/index.js +0 -0
@@ -0,0 +1,978 @@
1
+ var _a, _b, _c;
2
+ import { QUERY } from '../language/query.js';
3
+ import { HANDLE_MEMBERS, ROW_KEYS } from './model.js';
4
+ import { RelationRead, RootRead } from './plan.js';
5
+ import { and, atom, Condition, describe, foldedTo, folding, isPathText, kept, orderKeys, propertyHandle, scope, targetCondition, targetLabel, whereOf, within, } from './terms.js';
6
+ const defined = (fields) => Object.fromEntries(Object.entries(fields).filter(([, value]) => value !== undefined));
7
+ const nonEmpty = (items) => items.length > 0 ? items : undefined;
8
+ const keysOf = (classes) => classes.map((c) => c.key);
9
+ /**
10
+ * A canonical document, from its family's fields. The lowering writes the grammar by construction;
11
+ * the lowering checks hold it to `SizedQuery<Schema>` per construct.
12
+ */
13
+ const documentOf = (family) => ({ query: QUERY, ...family });
14
+ const optional = (condition) => condition.always || condition.never ? undefined : whereOf(condition.conjuncts);
15
+ /**
16
+ * A part of a document, from its conditions and its Branches: as sent, absent when a condition is
17
+ * NEVER, and as written when the input folds one of them (absent when it is the part as sent).
18
+ */
19
+ function lowered(conditions, branches, write) {
20
+ const part = (cs, withs) => cs.some((c) => c.never) ? undefined : write(cs, withs);
21
+ const sent = part(conditions, branches.flatMap((b) => (b.branch === undefined ? [] : [b.branch])));
22
+ if (!conditions.some((c) => c.folded) && branches.every((b) => b.written === undefined))
23
+ return { sent };
24
+ const written = part(conditions.map((c) => c.asWritten), branches.flatMap((b) => {
25
+ const branch = b.written ?? b.branch;
26
+ return branch === undefined ? [] : [branch];
27
+ }));
28
+ return { sent, written };
29
+ }
30
+ /** A root read: its plan, and its document as `lowered` writes it from its condition. */
31
+ function rootRead(plan, where, branches, write) {
32
+ const { sent, written } = lowered([where], branches, ([w], withs) => write(w, withs));
33
+ return new RootRead({
34
+ ...plan,
35
+ empty: sent === undefined,
36
+ ...(sent === undefined ? {} : { document: sent }),
37
+ ...(written === undefined ? {} : { written }),
38
+ });
39
+ }
40
+ /**
41
+ * A whole number of at least `min`, as a verb or a condition takes it. A verb bound past the
42
+ * Kernel's page is the call's `TOO_MANY`, since it may come from the input (S11).
43
+ */
44
+ function integer(value, what, min) {
45
+ if (!Number.isSafeInteger(value) || value < min)
46
+ throw new TypeError(`${what} takes an integer of at least ${min}; got ${describe(value)}.`);
47
+ return value;
48
+ }
49
+ function callback(value, what) {
50
+ if (typeof value !== 'function')
51
+ throw new TypeError(`${what} takes a callback; got ${describe(value)}.`);
52
+ return value;
53
+ }
54
+ function options(value, what) {
55
+ if (typeof value !== 'object' || value === null)
56
+ throw new TypeError(`${what} takes an options object; got ${describe(value)}.`);
57
+ return value;
58
+ }
59
+ /** Whether `first(n, written)` also says if more rows exist: `{ more: true }`. */
60
+ function withMore(written) {
61
+ return (written !== undefined && options(written, 'first').more === true);
62
+ }
63
+ // ─── Handles ───────────────────────────────────────────────────────────────────────────────────
64
+ /**
65
+ * The Property handles of some Classes by name: each Class's flat Properties, and on one Class
66
+ * its groups (F6). On a union, a name every Class keeps flat, by its keys (F7).
67
+ */
68
+ function propertyHandles(model, classes, taken, context) {
69
+ const layouts = classes.map((c) => model.layout(c, taken));
70
+ const out = new Map();
71
+ for (const name of layouts[0]?.flat.keys() ?? []) {
72
+ const keys = layouts.map((layout) => layout.flat.get(name));
73
+ if (keys.every((key) => key !== undefined))
74
+ out.set(name, propertyHandle([...new Set(keys)], context));
75
+ }
76
+ if (layouts.length === 1)
77
+ for (const [group, members] of layouts[0].groups) {
78
+ const handles = Object.create(null);
79
+ for (const [name, key] of members)
80
+ handles[name] = propertyHandle([key], context);
81
+ out.set(group, Object.freeze(handles));
82
+ }
83
+ return out;
84
+ }
85
+ /** A handle with fixed members first, then names resolved once on first read. */
86
+ function handle(fixed, resolve) {
87
+ const target = Object.freeze(Object.assign(Object.create(null), fixed));
88
+ const resolved = new Map();
89
+ return new Proxy(target, {
90
+ get(t, name) {
91
+ if (typeof name !== 'string')
92
+ return undefined;
93
+ if (Object.hasOwn(t, name))
94
+ return t[name];
95
+ if (!resolved.has(name))
96
+ resolved.set(name, resolve(name));
97
+ return resolved.get(name);
98
+ },
99
+ });
100
+ }
101
+ /** The Classes a Class handle names: a set of Nodes no method was called on. */
102
+ function classesOf(value, what) {
103
+ if (value instanceof NodeSet && value.pristine)
104
+ return value.classes;
105
+ throw new TypeError(`${what} takes a Class handle (d.<Class>) on which no method was called.`);
106
+ }
107
+ /** The Edge Class an Edge handle names. */
108
+ function edgeOf(value) {
109
+ if (value instanceof EdgeSet && value.pristine)
110
+ return value.edge;
111
+ throw new TypeError('via takes an Edge Class handle (d.<Edge>), or a list of them, on which no method was called.');
112
+ }
113
+ /**
114
+ * The one Class a Class handle names, as a write takes it: `d.<Class>`, on which no method was
115
+ * called. `undefined` for a value that is no set of roots.
116
+ */
117
+ export function handleClass(value) {
118
+ if (value instanceof NodeSet) {
119
+ if (value.pristine && value.classes.length === 1)
120
+ return value.classes[0];
121
+ }
122
+ else if (value instanceof EdgeSet) {
123
+ if (value.pristine)
124
+ return value.edge;
125
+ }
126
+ else
127
+ return undefined;
128
+ throw new TypeError('A write names one Class by its handle, `d.<Class>`, on which no method was called.');
129
+ }
130
+ /**
131
+ * A guard's range (S7), the roots of a Class handle after `where`, `union` and `orderBy`, as a
132
+ * read: of whether one exists, or, `ordered`, of them in their order. `undefined` for a value that
133
+ * is no set of roots; a set whose rows render (`with`, `ref`, `includeWithheld`) is refused.
134
+ */
135
+ export function rangeRead(value, ordered) {
136
+ if (value instanceof NodeSet)
137
+ return NodeSet.range(value, ordered);
138
+ if (value instanceof EdgeSet)
139
+ return EdgeSet.range(value, ordered);
140
+ return undefined;
141
+ }
142
+ function renderedRange() {
143
+ throw new TypeError("A guard reads its range's roots alone: `.with`, `.ref` and `.includeWithheld` render rows, which a guard never reads.");
144
+ }
145
+ const DIRECTIONS = new Set(['outgoing', 'incoming', 'incident']);
146
+ /** The direction from `classes` along `edge`, written or derived from the end that accepts them. */
147
+ function directionOf(model, classes, edge, written) {
148
+ const { source, target } = model.ends(edge);
149
+ const s = model.touches(classes, source);
150
+ const t = model.touches(classes, target);
151
+ if (written !== undefined) {
152
+ if (!DIRECTIONS.has(written))
153
+ throw new TypeError(`direction is outgoing, incoming or incident; got ${describe(written)}.`);
154
+ if ((written === 'outgoing' && !s) || (written === 'incoming' && !t) || (!s && !t))
155
+ throw new TypeError(`This Class is not the ${written === 'outgoing' ? 'source' : written === 'incoming' ? 'target' : 'end'} of ${edge.key}: check the direction.`);
156
+ return written;
157
+ }
158
+ if (s && t)
159
+ throw new TypeError(`Both ends of ${edge.key} accept this Class: pass { direction }.`);
160
+ if (!s && !t)
161
+ throw new TypeError(`${edge.key} has no end that accepts this Class: read it from a Class one of its ends accepts.`);
162
+ return s ? 'outgoing' : 'incoming';
163
+ }
164
+ /** A Node handle: its Properties, its named to-one relations, and the methods every Node has. */
165
+ export function nodeHandle(model, classes, context) {
166
+ const properties = propertyHandles(model, classes, HANDLE_MEMBERS, context);
167
+ const classCondition = (op, of) => {
168
+ const atoms = of.map((c) => ({ op, class: c.key }));
169
+ const where = atoms.length === 1 ? atoms[0] : { op: 'or', operands: atoms };
170
+ return new Condition(atom(context, where).conjuncts, keysOf(of));
171
+ };
172
+ const fixed = {
173
+ id: Object.freeze({
174
+ eq: (target) => targetCondition(context, [target]),
175
+ in: (targets) => {
176
+ if (!Array.isArray(targets))
177
+ throw new TypeError(`id.in takes a list; got ${describe(targets)}.`);
178
+ return targetCondition(context, targets);
179
+ },
180
+ }),
181
+ path: Object.freeze({
182
+ eq: (path) => pathCondition(context, [path]),
183
+ in: (paths) => {
184
+ if (!Array.isArray(paths))
185
+ throw new TypeError(`path.in takes a list; got ${describe(paths)}.`);
186
+ return pathCondition(context, paths);
187
+ },
188
+ }),
189
+ is: (cls, conditions) => {
190
+ const narrowed = classesOf(cls, 'is');
191
+ const is = classCondition('is', narrowed);
192
+ if (conditions === undefined)
193
+ return is;
194
+ const inner = nodeHandle(model, narrowed, context);
195
+ const listed = kept(callback(conditions, 'is')(inner));
196
+ within(listed, [context.scope]);
197
+ return and([is, ...listed]);
198
+ },
199
+ isExactly: (cls) => classCondition('isExactly', classesOf(cls, 'isExactly')),
200
+ via: (edge, written) => {
201
+ const edges = (Array.isArray(edge) ? edge : [edge]).map(edgeOf);
202
+ if (edges.length === 0)
203
+ throw new TypeError('via takes at least one Edge Class handle.');
204
+ const asked = written === undefined
205
+ ? undefined
206
+ : options(written, 'via').direction;
207
+ const directions = new Set(edges.map((e) => directionOf(model, classes, e, asked)));
208
+ if (directions.size > 1)
209
+ throw new TypeError('These Edges leave this Class in different directions: pass { direction }.');
210
+ const [direction] = directions;
211
+ const far = model.reached(edges, direction);
212
+ if (far.length === 0)
213
+ throw new TypeError(`${keysOf(edges).join(', ')} reaches only Classes this Domain does not declare or depend on: depend on the Domain that declares them.`);
214
+ const name = `via(${keysOf(edges).join(', ')})`;
215
+ return Relation.of(model, name, classes, edges, direction, far, context);
216
+ },
217
+ };
218
+ return handle(fixed, (name) => {
219
+ const property = properties.get(name);
220
+ if (property !== undefined)
221
+ return property;
222
+ return relationNamed(model, classes, name, context);
223
+ });
224
+ }
225
+ function pathCondition(context, paths) {
226
+ if (paths.length === 0)
227
+ return foldedTo(Condition.NEVER, atom(context, { op: 'path', paths: [] }));
228
+ for (const path of paths)
229
+ if (!isPathText(path))
230
+ throw new TypeError(`A path starts with "/" or "@"; got ${describe(path)}.`);
231
+ return atom(context, { op: 'path', paths });
232
+ }
233
+ /** The named to-one relation of a handle's Classes: on a union, one every Class names alike. */
234
+ function relationNamed(model, classes, name, context) {
235
+ const named = classes.map((c) => model.relations(c).get(name));
236
+ if (named.some((r) => r !== undefined && 'ambiguous' in r))
237
+ throw new TypeError(`"${name}" names several relations of this Class: use .via(d.<Edge>).`);
238
+ const relations = named;
239
+ if (relations.length === 0 || relations.some((r) => r === undefined))
240
+ return undefined;
241
+ const directions = new Set(relations.map((r) => r.direction));
242
+ if (directions.size > 1)
243
+ return undefined;
244
+ const edges = [...new Set(relations.map((r) => r.edge))];
245
+ const far = [...new Set(relations.flatMap((r) => r.far))];
246
+ return Relation.of(model, name, classes, edges, relations[0].direction, far, context);
247
+ }
248
+ /** An Edge handle in a `(node, edge) =>` callback: the Properties its Edges share. */
249
+ function edgeHandle(model, edges, context) {
250
+ const properties = propertyHandles(model, edges, new Set(), context);
251
+ return handle({}, (name) => properties.get(name));
252
+ }
253
+ // ─── Branches ──────────────────────────────────────────────────────────────────────────────────
254
+ const BRANCH_NAME = /^[A-Za-z][A-Za-z0-9_]{0,63}$/;
255
+ /**
256
+ * The Branches of a pattern, named after their `.with` keys: a key that is a valid Branch name
257
+ * keeps it, any other gets `w<index>`, made unique among its siblings.
258
+ */
259
+ function lowerWiths(withs) {
260
+ const names = new Set();
261
+ const kept = withs.map(([key]) => {
262
+ if (!BRANCH_NAME.test(key) || names.has(key))
263
+ return undefined;
264
+ names.add(key);
265
+ return key;
266
+ });
267
+ return withs.map(([key, read], index) => {
268
+ let name = kept[index];
269
+ if (name === undefined) {
270
+ name = `w${index}`;
271
+ for (let n = 1; names.has(name); n += 1)
272
+ name = `w${index}_${n}`;
273
+ names.add(name);
274
+ }
275
+ return read.lower(key, name);
276
+ });
277
+ }
278
+ /** The relation reads a `.with` callback returned, by name, checked against the row's names. */
279
+ function withsOf(value, handleScope, taken, earlier) {
280
+ if (typeof value !== 'object' || value === null || Array.isArray(value))
281
+ throw new TypeError(`with takes a callback that returns an object of relation reads; got ${describe(value)}.`);
282
+ const names = new Set(earlier.map(([name]) => name));
283
+ return Object.entries(value).map(([name, entry]) => {
284
+ if (taken.has(name) || ROW_KEYS.has(name) || names.has(name) || name.startsWith('$'))
285
+ throw new TypeError(`"${name}" is already a row key of this Class: give the .with another name.`);
286
+ const read = entry instanceof Exists ? entry.read : entry;
287
+ if (read instanceof RootRead)
288
+ throw new TypeError(`"${name}" reads another root: read it as a facet of the Query.`);
289
+ if (!(read instanceof RelationRead))
290
+ throw new TypeError(`"${name}" is not a relation read: end the relation with a verb (find, first, all, count, exists).`);
291
+ if (read.scope !== handleScope)
292
+ throw new TypeError(`"${name}" reads a relation of another handle: a .with reads the handle it receives.`);
293
+ return [name, read];
294
+ });
295
+ }
296
+ const DISTINCT_EDGE = 'A distinct relation renders its Nodes only: its rows have no single Edge, so no withEdge.';
297
+ function keyJson(key, distinct) {
298
+ let on;
299
+ if (key.target === 'item')
300
+ on = distinct ? undefined : 'node';
301
+ else if (key.target === 'edge') {
302
+ if (distinct)
303
+ throw new TypeError('A distinct relation orders by its Nodes only: its rows have no single Edge.');
304
+ on = 'edge';
305
+ }
306
+ else
307
+ on = key.target;
308
+ return defined({ property: key.property, direction: key.direction, missing: key.missing, on });
309
+ }
310
+ function rootKeyJson(key) {
311
+ return defined({
312
+ property: key.property,
313
+ direction: key.direction,
314
+ missing: key.missing,
315
+ on: key.target === 'source' || key.target === 'target' ? key.target : undefined,
316
+ });
317
+ }
318
+ /** A condition that is also a relation read: `exists()` is a boolean in `.with`. */
319
+ class Exists extends Condition {
320
+ read;
321
+ constructor(condition, read) {
322
+ super(condition.conjuncts, undefined, condition.written);
323
+ this.read = read;
324
+ }
325
+ }
326
+ /** A Node one of `end`'s Classes accepts: an `is` of each. */
327
+ function acceptedBy(end) {
328
+ const atoms = end.accepts.map((key) => ({ op: 'is', class: key }));
329
+ return atoms.length === 1 ? atoms[0] : { op: 'or', operands: atoms };
330
+ }
331
+ /**
332
+ * The far role a relation along an undirected Edge Class sends, in `direction` from `from`. Its
333
+ * ends have no order: the Kernel follows it both ways, whatever direction is written, and a
334
+ * direction names a role, never a stored end. From a Node its near role accepts, the far Node
335
+ * takes the far role when that role accepts it, so the relation follows the Edge `incident` to a
336
+ * Node of the far role's Classes; when the far role accepts every Node the near one does, every
337
+ * far Node takes it and nothing is sent. A relation from Nodes its near role may not accept, or
338
+ * along several Edge Classes one of which needs that condition, is refused: one condition on the
339
+ * far Node cannot say it.
340
+ */
341
+ function farRole(model, from, edges, direction) {
342
+ if (direction === 'incident')
343
+ return undefined;
344
+ let needed;
345
+ for (const edge of edges) {
346
+ const { source, target, undirected } = model.ends(edge);
347
+ if (!undirected)
348
+ continue;
349
+ const [near, far] = direction === 'outgoing' ? [source, target] : [target, source];
350
+ const stray = from.find((c) => !model.covers(near, [c.key]));
351
+ if (stray !== undefined)
352
+ throw new TypeError(`An undirected Edge's ends have no order: this relation reads ${edge.key} from its ${near.role} role, which does not accept ${stray.key}. Read it from a Class that role accepts, or with { direction: 'incident' }.`);
353
+ if (!model.covers(far, near.accepts))
354
+ needed = { edge, far };
355
+ }
356
+ if (needed === undefined)
357
+ return undefined;
358
+ if (edges.length > 1)
359
+ throw new TypeError(`An undirected Edge's ends have no order: a far Node of ${needed.edge.key} takes its ${needed.far.role} role only when that role accepts it, which one condition over several Edge Classes cannot say. Read ${needed.edge.key} with its own .via().`);
360
+ return acceptedBy(needed.far);
361
+ }
362
+ /** A relation from a Node: the Nodes at the far end of its Edges. */
363
+ export class Relation {
364
+ #s;
365
+ constructor(state) {
366
+ this.#s = state;
367
+ }
368
+ static of(model, name, from, edges, direction, far, context) {
369
+ return new _a({
370
+ model,
371
+ name,
372
+ edges,
373
+ direction,
374
+ far,
375
+ role: farRole(model, from, edges, direction),
376
+ context,
377
+ node: Condition.ALWAYS,
378
+ edge: Condition.ALWAYS,
379
+ orderBy: [],
380
+ with: [],
381
+ select: 'value',
382
+ withheld: false,
383
+ selectEdge: false,
384
+ distinct: false,
385
+ });
386
+ }
387
+ #next(patch) {
388
+ return new _a({ ...this.#s, ...patch });
389
+ }
390
+ /** Fresh handles for a `(node, edge) =>` callback, each on its own scope. */
391
+ #handles() {
392
+ const nodeScope = scope(`the Nodes of ${this.#s.name}`);
393
+ const edgeScope = scope(`the Edges of ${this.#s.name}`);
394
+ return {
395
+ node: nodeHandle(this.#s.model, this.#s.far, { scope: nodeScope, on: 'item' }),
396
+ edge: edgeHandle(this.#s.model, this.#s.edges, { scope: edgeScope, on: 'edge' }),
397
+ scopes: [nodeScope, edgeScope],
398
+ };
399
+ }
400
+ /** A `(node, edge) =>` callback's conditions, split into the node's and the Edge's. */
401
+ #split(conditions, what) {
402
+ if (conditions === undefined)
403
+ return { node: Condition.ALWAYS, edge: Condition.ALWAYS };
404
+ const { node, edge, scopes } = this.#handles();
405
+ const listed = kept(callback(conditions, what)(node, edge));
406
+ within(listed, scopes);
407
+ const narrows = [...new Set(listed.flatMap((c) => c.narrows ?? []))];
408
+ const side = (on) => folding(listed, (cs) => and(cs.map((c) => c.never ? Condition.NEVER : new Condition(c.conjuncts.filter((x) => x.scope === on)))));
409
+ return {
410
+ node: side(scopes[0]),
411
+ edge: side(scopes[1]),
412
+ ...(narrows.length > 0 ? { narrows } : {}),
413
+ };
414
+ }
415
+ where(conditions) {
416
+ const split = this.#split(callback(conditions, 'where'), 'where');
417
+ return this.#next({
418
+ node: and([this.#s.node, split.node]),
419
+ edge: and([this.#s.edge, split.edge]),
420
+ far: split.narrows ? split.narrows.map((key) => this.#s.model.classOf(key)) : this.#s.far,
421
+ });
422
+ }
423
+ orderBy(keys) {
424
+ const { node, edge, scopes } = this.#handles();
425
+ const ordering = callback(keys, 'orderBy')(node, edge);
426
+ return this.#next({ orderBy: [...this.#s.orderBy, ...orderKeys(ordering, scopes)] });
427
+ }
428
+ with(relations) {
429
+ const handleScope = scope(`the Nodes of ${this.#s.name}`);
430
+ const node = nodeHandle(this.#s.model, this.#s.far, { scope: handleScope, on: 'item' });
431
+ const value = callback(relations, 'with')(node);
432
+ const taken = new Set(this.#s.far.flatMap((c) => [...this.#s.model.propertyNames(c)]));
433
+ return this.#next({
434
+ with: [...this.#s.with, ...withsOf(value, handleScope, taken, this.#s.with)],
435
+ });
436
+ }
437
+ withEdge() {
438
+ if (this.#s.distinct)
439
+ throw new TypeError(DISTINCT_EDGE);
440
+ return this.#next({ selectEdge: true });
441
+ }
442
+ ref() {
443
+ return this.#next({ select: 'reference' });
444
+ }
445
+ includeWithheld() {
446
+ return this.#next({ withheld: true });
447
+ }
448
+ distinct() {
449
+ if (this.#s.selectEdge)
450
+ throw new TypeError(DISTINCT_EDGE);
451
+ return this.#next({ distinct: true });
452
+ }
453
+ /** Its Traversal: along an undirected Edge whose far role needs it, `incident` to that role. */
454
+ #traversal(node, edge) {
455
+ const { role } = this.#s;
456
+ const conjuncts = [
457
+ ...(role === undefined ? [] : [role]),
458
+ ...(node.always || node.never ? [] : node.conjuncts.map((c) => c.where)),
459
+ ];
460
+ return defined({
461
+ via: keysOf(this.#s.edges),
462
+ direction: role === undefined ? this.#s.direction : 'incident',
463
+ distinct: this.#s.distinct ? true : undefined,
464
+ edge: optional(edge),
465
+ node: conjuncts.length === 0
466
+ ? undefined
467
+ : conjuncts.length === 1
468
+ ? conjuncts[0]
469
+ : { op: 'and', operands: conjuncts },
470
+ });
471
+ }
472
+ #read(verb, limit, bound) {
473
+ const s = this.#s;
474
+ return new RelationRead(s.context.scope, (key, name) => {
475
+ const counted = verb === 'count' || verb === 'exists';
476
+ const branches = counted ? [] : lowerWiths(s.with);
477
+ const { sent, written } = lowered([s.node, s.edge], branches, ([node, edge], withs) => {
478
+ const traversal = this.#traversal(node, edge);
479
+ if (counted)
480
+ return { name, ...traversal, mode: 'count', upTo: limit };
481
+ const orderBy = s.orderBy.map((k) => keyJson(k, s.distinct));
482
+ return defined({
483
+ name,
484
+ ...traversal,
485
+ mode: 'optional',
486
+ orderBy: nonEmpty(orderBy),
487
+ select: s.select === 'value' ? 'value' : undefined,
488
+ selectEdge: s.selectEdge ? 'value' : undefined,
489
+ with: nonEmpty(withs),
490
+ limit,
491
+ });
492
+ });
493
+ const plan = {
494
+ key,
495
+ name,
496
+ relation: s.name,
497
+ verb,
498
+ ...(bound === undefined ? {} : { bound }),
499
+ empty: sent === undefined,
500
+ ...(s.selectEdge ? { edge: 'value' } : {}),
501
+ classes: keysOf(s.far),
502
+ select: s.select,
503
+ withheld: s.withheld,
504
+ branches: branches.map((b) => b.plan),
505
+ };
506
+ return {
507
+ plan,
508
+ ...(sent === undefined ? {} : { branch: sent }),
509
+ ...(written === undefined ? {} : { written }),
510
+ };
511
+ });
512
+ }
513
+ /** Exactly one per parent: two rows, to see a second. */
514
+ get() {
515
+ return this.#read('get', 2);
516
+ }
517
+ find() {
518
+ return this.#read('find', 2);
519
+ }
520
+ first(n, written) {
521
+ if (n === undefined)
522
+ return this.#read('first', 1);
523
+ const bound = integer(n, 'first', 1);
524
+ return withMore(written)
525
+ ? this.#read('firstMore', bound + 1, bound)
526
+ : this.#read('firstN', bound, bound);
527
+ }
528
+ all(written) {
529
+ const max = integer(options(written, 'all').max, 'all({ max })', 1);
530
+ return this.#read('all', max + 1, max);
531
+ }
532
+ count(written) {
533
+ const upTo = integer(options(written, 'count').upTo, 'count({ upTo })', 1);
534
+ return this.#read('count', upTo, upTo);
535
+ }
536
+ /** At least `atLeast` Edges of the relation meet the extra conditions. */
537
+ #exists(extra, atLeast = 1) {
538
+ const sides = [and([this.#s.node, extra.node]), and([this.#s.edge, extra.edge])];
539
+ return folding(sides, ([node, edge]) => node.never || edge.never
540
+ ? Condition.NEVER
541
+ : atom(this.#s.context, {
542
+ op: 'exists',
543
+ ...this.#traversal(node, edge),
544
+ ...(atLeast > 1 ? { atLeast } : {}),
545
+ }));
546
+ }
547
+ /** A boolean per parent in a `.with`; a condition in a `where`. */
548
+ exists() {
549
+ return new Exists(this.#exists({ node: Condition.ALWAYS, edge: Condition.ALWAYS }), this.#read('exists', 1));
550
+ }
551
+ /** The relation reaches this Node. */
552
+ is(target) {
553
+ const node = targetCondition({ scope: scope(`the Nodes of ${this.#s.name}`), on: 'item' }, [
554
+ target,
555
+ ]);
556
+ return this.#exists({ node, edge: Condition.ALWAYS });
557
+ }
558
+ some(conditions) {
559
+ return this.#exists(this.#split(conditions, 'some'));
560
+ }
561
+ none(conditions) {
562
+ return this.#exists(this.#split(conditions, 'none')).not();
563
+ }
564
+ atLeast(n, conditions) {
565
+ const bound = integer(n, 'atLeast', 0);
566
+ const some = this.#exists(this.#split(conditions, 'atLeast'), Math.max(bound, 1));
567
+ // At least none is ALWAYS; as written, it still reads the relation.
568
+ return bound === 0 ? foldedTo(Condition.ALWAYS, some) : some;
569
+ }
570
+ atMost(n, conditions) {
571
+ const bound = integer(n, 'atMost', 0);
572
+ return this.#exists(this.#split(conditions, 'atMost'), bound + 1).not();
573
+ }
574
+ exactly(n, conditions) {
575
+ const bound = integer(n, 'exactly', 0);
576
+ const split = this.#split(conditions, 'exactly');
577
+ const more = this.#exists(split, bound + 1).not();
578
+ return bound === 0 ? more : and([this.#exists(split, bound), more]);
579
+ }
580
+ /** No Edge of the relation fails the conditions: `none` of their negation, on one side. */
581
+ every(conditions) {
582
+ const split = this.#split(callback(conditions, 'every'), 'every');
583
+ return folding([split.node, split.edge], ([node, edge]) => {
584
+ if (node.never || edge.never)
585
+ return this.none();
586
+ if (!node.always && !edge.always)
587
+ throw new TypeError('`every` over both the node and its Edge is not in Query v7: write one `every` per side.');
588
+ if (node.always && edge.always)
589
+ return Condition.ALWAYS;
590
+ const failing = node.always
591
+ ? { node: Condition.ALWAYS, edge: edge.not() }
592
+ : { node: node.not(), edge: Condition.ALWAYS };
593
+ return this.#exists(failing).not();
594
+ });
595
+ }
596
+ }
597
+ _a = Relation;
598
+ /** The Nodes of a Class, or of a union of Classes, at the root of a read. */
599
+ export class NodeSet {
600
+ #s;
601
+ constructor(state) {
602
+ this.#s = state;
603
+ }
604
+ static of(model, cls) {
605
+ const classes = [cls];
606
+ return new _b({
607
+ model,
608
+ roots: classes,
609
+ classes,
610
+ where: Condition.ALWAYS,
611
+ orderBy: [],
612
+ with: [],
613
+ select: 'value',
614
+ withheld: false,
615
+ });
616
+ }
617
+ /** Its Classes, after narrowing. */
618
+ get classes() {
619
+ return this.#s.classes;
620
+ }
621
+ /** No method was called on it but `union`: a Class handle, as `is` and `union` take one. */
622
+ get pristine() {
623
+ const s = this.#s;
624
+ return (s.where.always &&
625
+ s.orderBy.length === 0 &&
626
+ s.with.length === 0 &&
627
+ s.select === 'value' &&
628
+ !s.withheld &&
629
+ s.roots === s.classes);
630
+ }
631
+ /** The range a guard reads (S7); a set whose rows render is none. */
632
+ static range(set, ordered) {
633
+ const s = set.#s;
634
+ if (s.with.length > 0 || s.select !== 'value' || s.withheld)
635
+ renderedRange();
636
+ return ordered ? set.#list('first', 1) : set.#range('exists');
637
+ }
638
+ #next(patch) {
639
+ return new _b({ ...this.#s, ...patch });
640
+ }
641
+ #handle() {
642
+ const handleScope = scope(`the Nodes of ${keysOf(this.#s.classes).join(' | ')}`);
643
+ return {
644
+ node: nodeHandle(this.#s.model, this.#s.classes, { scope: handleScope, on: 'item' }),
645
+ scope: handleScope,
646
+ };
647
+ }
648
+ where(conditions) {
649
+ const { node, scope: handleScope } = this.#handle();
650
+ const listed = kept(callback(conditions, 'where')(node));
651
+ within(listed, [handleScope]);
652
+ const narrows = [...new Set(listed.flatMap((c) => c.narrows ?? []))];
653
+ return this.#next({
654
+ where: and([this.#s.where, ...listed]),
655
+ classes: narrows.length > 0 ? narrows.map((key) => this.#s.model.classOf(key)) : this.#s.classes,
656
+ });
657
+ }
658
+ orderBy(keys) {
659
+ const { node, scope: handleScope } = this.#handle();
660
+ const ordering = callback(keys, 'orderBy')(node);
661
+ return this.#next({ orderBy: [...this.#s.orderBy, ...orderKeys(ordering, [handleScope])] });
662
+ }
663
+ with(relations) {
664
+ const { node, scope: handleScope } = this.#handle();
665
+ const value = callback(relations, 'with')(node);
666
+ const taken = new Set(this.#s.classes.flatMap((c) => [...this.#s.model.propertyNames(c)]));
667
+ return this.#next({
668
+ with: [...this.#s.with, ...withsOf(value, handleScope, taken, this.#s.with)],
669
+ });
670
+ }
671
+ ref() {
672
+ return this.#next({ select: 'reference' });
673
+ }
674
+ includeWithheld() {
675
+ return this.#next({ withheld: true });
676
+ }
677
+ union(other) {
678
+ const s = this.#s;
679
+ if (!s.where.always || s.orderBy.length > 0 || s.with.length > 0 || s.roots !== s.classes)
680
+ throw new TypeError('Call union before where, orderBy and with: they read the union.');
681
+ const classes = [...new Set([...s.roots, ...classesOf(other, 'union')])];
682
+ return this.#next({ roots: classes, classes });
683
+ }
684
+ #root(branches) {
685
+ return {
686
+ kind: 'nodes',
687
+ classes: keysOf(this.#s.classes),
688
+ select: this.#s.select,
689
+ withheld: this.#s.withheld,
690
+ branches: branches.map((b) => b.plan),
691
+ };
692
+ }
693
+ #where(id) {
694
+ if (id === undefined)
695
+ return this.#s.where;
696
+ return and([this.#s.where, targetCondition({ scope: scope('the root'), on: 'item' }, [id])]);
697
+ }
698
+ #list(verb, limit, bound, id) {
699
+ const s = this.#s;
700
+ const where = this.#where(id);
701
+ const branches = lowerWiths(s.with);
702
+ const plan = {
703
+ verb,
704
+ ...(bound === undefined ? {} : { bound }),
705
+ ...(id === undefined ? {} : { target: targetLabel(id) }),
706
+ root: this.#root(branches),
707
+ };
708
+ return rootRead(plan, where, branches, (where, withs) => documentOf({
709
+ list: defined({
710
+ nodes: keysOf(s.roots),
711
+ where: optional(where),
712
+ orderBy: nonEmpty(s.orderBy.map(rootKeyJson)),
713
+ select: s.select === 'value' ? 'value' : undefined,
714
+ with: nonEmpty(withs),
715
+ limit,
716
+ }),
717
+ }));
718
+ }
719
+ #range(verb, id, upTo) {
720
+ const where = this.#where(id);
721
+ const plan = {
722
+ verb,
723
+ ...(upTo === undefined ? {} : { bound: upTo }),
724
+ ...(id === undefined ? {} : { target: targetLabel(id) }),
725
+ root: this.#root([]),
726
+ };
727
+ return rootRead(plan, where, [], (where) => {
728
+ const range = defined({ nodes: keysOf(this.#s.roots), where: optional(where) });
729
+ return documentOf(verb === 'exists' ? { exists: range } : { count: range, upTo });
730
+ });
731
+ }
732
+ /** Exactly one: two rows, to see a second. */
733
+ get(id) {
734
+ return this.#list('get', 2, undefined, id);
735
+ }
736
+ find(id) {
737
+ return this.#list('find', 2, undefined, id);
738
+ }
739
+ first(n, written) {
740
+ if (n === undefined)
741
+ return this.#list('first', 1);
742
+ const bound = integer(n, 'first', 1);
743
+ return withMore(written)
744
+ ? this.#list('firstMore', bound + 1, bound)
745
+ : this.#list('firstN', bound, bound);
746
+ }
747
+ page(written) {
748
+ const max = integer(options(written, 'page').max, 'page({ max })', 1);
749
+ return this.#list('page', max, max);
750
+ }
751
+ all(written) {
752
+ const max = integer(options(written, 'all').max, 'all({ max })', 1);
753
+ return this.#list('all', max + 1, max);
754
+ }
755
+ exists(id) {
756
+ return this.#range('exists', id);
757
+ }
758
+ count(written) {
759
+ const upTo = integer(options(written, 'count').upTo, 'count({ upTo })', 1);
760
+ return this.#range('count', undefined, upTo);
761
+ }
762
+ }
763
+ _b = NodeSet;
764
+ /** Whether an Edge root's condition reads one of its ends. */
765
+ function readsEnd(where) {
766
+ switch (where.op) {
767
+ case 'source':
768
+ case 'target':
769
+ return true;
770
+ case 'and':
771
+ case 'or':
772
+ return where.operands.some(readsEnd);
773
+ case 'not':
774
+ return readsEnd(where.operand);
775
+ }
776
+ return false;
777
+ }
778
+ /**
779
+ * An Edge root's condition with its ends exchanged. At an Edge root a condition is a connective, a
780
+ * condition on the Edge's Properties, or a condition on one end, whose operand is the end Node's
781
+ * and is kept as it is.
782
+ */
783
+ function swapped(where) {
784
+ switch (where.op) {
785
+ case 'source':
786
+ return { ...where, op: 'target' };
787
+ case 'target':
788
+ return { ...where, op: 'source' };
789
+ case 'and':
790
+ case 'or':
791
+ return { ...where, operands: where.operands.map(swapped) };
792
+ case 'not':
793
+ return { ...where, operand: swapped(where.operand) };
794
+ }
795
+ return where;
796
+ }
797
+ /**
798
+ * The condition an undirected Edge root sends, from the one its roles are written in. Its ends
799
+ * have no order: the stored `source` is the end with the smaller NodeId, whatever its role. An
800
+ * Edge meets a condition on its roles when one pairing of its two ends with its two roles does,
801
+ * each role's Classes accepted at the end it takes: `or(W[roles→(source, target)],
802
+ * W[roles→(target, source)])`. The conjuncts that read no end are the same in both pairings and
803
+ * stay outside the `or`; an end's acceptance that every stored Edge meets is not written.
804
+ */
805
+ function paired(model, ends, condition) {
806
+ const read = (condition.conjuncts ?? []).filter((c) => readsEnd(c.where));
807
+ if (read.length === 0)
808
+ return condition;
809
+ const accepted = (end, on, other) => model.covers(end, other.accepts) ? [] : [{ op: on, operand: acceptedBy(end) }];
810
+ const { source, target } = ends;
811
+ const atoms = [
812
+ ...accepted(source, 'source', target),
813
+ ...accepted(target, 'target', source),
814
+ ...read.map((c) => c.where),
815
+ ];
816
+ const pairing = atoms.length === 1 ? atoms[0] : { op: 'and', operands: atoms };
817
+ return new Condition([
818
+ ...condition.conjuncts.filter((c) => !readsEnd(c.where)),
819
+ { scope: read[0].scope, where: { op: 'or', operands: [pairing, swapped(pairing)] } },
820
+ ], condition.narrows);
821
+ }
822
+ /** The Edges of a Class at the root of a read: its Properties, and both ends by role. */
823
+ export class EdgeSet {
824
+ #s;
825
+ constructor(state) {
826
+ this.#s = state;
827
+ }
828
+ static of(model, edge) {
829
+ return new _c({
830
+ model,
831
+ edge,
832
+ where: Condition.ALWAYS,
833
+ orderBy: [],
834
+ select: 'value',
835
+ withheld: false,
836
+ });
837
+ }
838
+ get edge() {
839
+ return this.#s.edge;
840
+ }
841
+ get pristine() {
842
+ const s = this.#s;
843
+ return s.where.always && s.orderBy.length === 0 && s.select === 'value' && !s.withheld;
844
+ }
845
+ /** The range a guard reads (S7); a set whose rows render is none. */
846
+ static range(set, ordered) {
847
+ const s = set.#s;
848
+ if (s.select !== 'value' || s.withheld)
849
+ renderedRange();
850
+ return ordered ? set.#list('first', 1) : set.#range('exists');
851
+ }
852
+ #next(patch) {
853
+ return new _c({ ...this.#s, ...patch });
854
+ }
855
+ #handle() {
856
+ const { model, edge } = this.#s;
857
+ const handleScope = scope(`the Edges of ${edge.key}`);
858
+ const { source, target } = model.ends(edge);
859
+ const end = (e, on) => nodeHandle(model, model.far(e), {
860
+ scope: handleScope,
861
+ on,
862
+ wrap: (where) => ({ op: on, operand: where }),
863
+ });
864
+ const roles = new Set([source.role, target.role]);
865
+ const properties = propertyHandles(model, [edge], roles, { scope: handleScope, on: 'item' });
866
+ const ends = { [source.role]: end(source, 'source'), [target.role]: end(target, 'target') };
867
+ return { edge: handle(ends, (name) => properties.get(name)), scope: handleScope };
868
+ }
869
+ where(conditions) {
870
+ const { edge, scope: handleScope } = this.#handle();
871
+ const listed = kept(callback(conditions, 'where')(edge));
872
+ within(listed, [handleScope]);
873
+ return this.#next({ where: and([this.#s.where, ...listed]) });
874
+ }
875
+ orderBy(keys) {
876
+ const { edge, scope: handleScope } = this.#handle();
877
+ const ordering = callback(keys, 'orderBy')(edge);
878
+ const listed = orderKeys(ordering, [handleScope]);
879
+ const ends = this.#s.model.ends(this.#s.edge);
880
+ const role = listed.find((key) => key.target === 'source' || key.target === 'target')?.target;
881
+ if (ends.undirected && role !== undefined)
882
+ throw new TypeError(`An undirected Edge's ends have no order: ${this.#s.edge.key} orders by its own Properties, not by its ${ends[role].role}'s.`);
883
+ return this.#next({ orderBy: [...this.#s.orderBy, ...listed] });
884
+ }
885
+ ref() {
886
+ return this.#next({ select: 'reference' });
887
+ }
888
+ includeWithheld() {
889
+ return this.#next({ withheld: true });
890
+ }
891
+ #root() {
892
+ const { model, edge } = this.#s;
893
+ const { source, target } = model.ends(edge);
894
+ return {
895
+ kind: 'edges',
896
+ classes: [edge.key],
897
+ select: this.#s.select,
898
+ withheld: this.#s.withheld,
899
+ source: { role: source.role, classes: keysOf(model.far(source)), select: this.#s.select },
900
+ target: { role: target.role, classes: keysOf(model.far(target)), select: this.#s.select },
901
+ };
902
+ }
903
+ /** The condition the read sends: an undirected Edge's, over both pairings of its ends. */
904
+ #where() {
905
+ const { model, edge, where } = this.#s;
906
+ const ends = model.ends(edge);
907
+ return ends.undirected ? folding([where], ([c]) => paired(model, ends, c)) : where;
908
+ }
909
+ /**
910
+ * The rows of a list, each end under its role. An undirected Edge's ends render in their stored
911
+ * order, which is one pairing of its roles that the read meets only when its roles accept the
912
+ * same Classes and its condition reads no end; any other list of it is refused.
913
+ */
914
+ #rows(verb, limit, bound) {
915
+ const { model, edge, where } = this.#s;
916
+ const { source, target, undirected } = model.ends(edge);
917
+ if (undirected &&
918
+ !(model.covers(source, target.accepts) && model.covers(target, source.accepts)))
919
+ throw new TypeError(`An undirected Edge's ends have no order: a row of ${edge.key} cannot say which end is its ${source.role} and which its ${target.role}. Read the Edge from a Node with .via(), or ask exists() or count().`);
920
+ if (undirected && (where.written ?? []).some((c) => readsEnd(c.where)))
921
+ throw new TypeError(`An undirected Edge's ends have no order: a row of ${edge.key} read by a condition on its ${source.role} or ${target.role} cannot say which end meets it. Read the Edge from a Node with .via(), or ask exists() or count().`);
922
+ return this.#list(verb, limit, bound);
923
+ }
924
+ #list(verb, limit, bound) {
925
+ const s = this.#s;
926
+ const plan = { verb, ...(bound === undefined ? {} : { bound }), root: this.#root() };
927
+ return rootRead(plan, this.#where(), [], (where) => documentOf({
928
+ list: defined({
929
+ edges: [s.edge.key],
930
+ where: optional(where),
931
+ orderBy: nonEmpty(s.orderBy.map(rootKeyJson)),
932
+ // Both ends, so each carries its Class; a reference Edge is the canonical default.
933
+ select: s.select === 'value'
934
+ ? { edge: 'value', source: 'value', target: 'value' }
935
+ : { source: 'reference', target: 'reference' },
936
+ limit,
937
+ }),
938
+ }));
939
+ }
940
+ #range(verb, upTo) {
941
+ const s = this.#s;
942
+ const plan = { verb, ...(upTo === undefined ? {} : { bound: upTo }), root: this.#root() };
943
+ return rootRead(plan, this.#where(), [], (where) => {
944
+ const range = defined({ edges: [s.edge.key], where: optional(where) });
945
+ return documentOf(verb === 'exists' ? { exists: range } : { count: range, upTo });
946
+ });
947
+ }
948
+ get() {
949
+ return this.#rows('get', 2);
950
+ }
951
+ find() {
952
+ return this.#rows('find', 2);
953
+ }
954
+ first(n, written) {
955
+ if (n === undefined)
956
+ return this.#rows('first', 1);
957
+ const bound = integer(n, 'first', 1);
958
+ return withMore(written)
959
+ ? this.#rows('firstMore', bound + 1, bound)
960
+ : this.#rows('firstN', bound, bound);
961
+ }
962
+ page(written) {
963
+ const max = integer(options(written, 'page').max, 'page({ max })', 1);
964
+ return this.#rows('page', max, max);
965
+ }
966
+ all(written) {
967
+ const max = integer(options(written, 'all').max, 'all({ max })', 1);
968
+ return this.#rows('all', max + 1, max);
969
+ }
970
+ exists() {
971
+ return this.#range('exists');
972
+ }
973
+ count(written) {
974
+ const upTo = integer(options(written, 'count').upTo, 'count({ upTo })', 1);
975
+ return this.#range('count', upTo);
976
+ }
977
+ }
978
+ _c = EdgeSet;