@azx-pbc/axiom-runtime 0.0.0-stage → 0.0.5

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 (755) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +714 -2
  3. package/dist/cache/index.d.ts +191 -0
  4. package/dist/cache/index.d.ts.map +1 -0
  5. package/dist/cache/index.js +361 -0
  6. package/dist/cache/index.js.map +1 -0
  7. package/dist/canonical/jcs.d.ts +78 -0
  8. package/dist/canonical/jcs.d.ts.map +1 -0
  9. package/dist/canonical/jcs.js +500 -0
  10. package/dist/canonical/jcs.js.map +1 -0
  11. package/dist/canonical/restricted-json.d.ts +7 -0
  12. package/dist/canonical/restricted-json.d.ts.map +1 -0
  13. package/dist/canonical/restricted-json.js +318 -0
  14. package/dist/canonical/restricted-json.js.map +1 -0
  15. package/dist/canonical/restricted-value.d.ts +59 -0
  16. package/dist/canonical/restricted-value.d.ts.map +1 -0
  17. package/dist/canonical/restricted-value.js +156 -0
  18. package/dist/canonical/restricted-value.js.map +1 -0
  19. package/dist/canonical/restricted.d.ts +85 -0
  20. package/dist/canonical/restricted.d.ts.map +1 -0
  21. package/dist/canonical/restricted.js +163 -0
  22. package/dist/canonical/restricted.js.map +1 -0
  23. package/dist/canonical/signature.d.ts +38 -0
  24. package/dist/canonical/signature.d.ts.map +1 -0
  25. package/dist/canonical/signature.js +47 -0
  26. package/dist/canonical/signature.js.map +1 -0
  27. package/dist/eval/access/delivery.d.ts +63 -0
  28. package/dist/eval/access/delivery.d.ts.map +1 -0
  29. package/dist/eval/access/delivery.js +98 -0
  30. package/dist/eval/access/delivery.js.map +1 -0
  31. package/dist/eval/access/overlay.d.ts +72 -0
  32. package/dist/eval/access/overlay.d.ts.map +1 -0
  33. package/dist/eval/access/overlay.js +402 -0
  34. package/dist/eval/access/overlay.js.map +1 -0
  35. package/dist/eval/access/projection.d.ts +159 -0
  36. package/dist/eval/access/projection.d.ts.map +1 -0
  37. package/dist/eval/access/projection.js +211 -0
  38. package/dist/eval/access/projection.js.map +1 -0
  39. package/dist/eval/access/window.d.ts +128 -0
  40. package/dist/eval/access/window.d.ts.map +1 -0
  41. package/dist/eval/access/window.js +254 -0
  42. package/dist/eval/access/window.js.map +1 -0
  43. package/dist/eval/access/write.d.ts +113 -0
  44. package/dist/eval/access/write.d.ts.map +1 -0
  45. package/dist/eval/access/write.js +119 -0
  46. package/dist/eval/access/write.js.map +1 -0
  47. package/dist/eval/addressing.d.ts +131 -0
  48. package/dist/eval/addressing.d.ts.map +1 -0
  49. package/dist/eval/addressing.js +270 -0
  50. package/dist/eval/addressing.js.map +1 -0
  51. package/dist/eval/budget.d.ts +143 -0
  52. package/dist/eval/budget.d.ts.map +1 -0
  53. package/dist/eval/budget.js +387 -0
  54. package/dist/eval/budget.js.map +1 -0
  55. package/dist/eval/computed.d.ts +46 -0
  56. package/dist/eval/computed.d.ts.map +1 -0
  57. package/dist/eval/computed.js +89 -0
  58. package/dist/eval/computed.js.map +1 -0
  59. package/dist/eval/denials.d.ts +64 -0
  60. package/dist/eval/denials.d.ts.map +1 -0
  61. package/dist/eval/denials.js +87 -0
  62. package/dist/eval/denials.js.map +1 -0
  63. package/dist/eval/engine/cancellation.d.ts +12 -0
  64. package/dist/eval/engine/cancellation.d.ts.map +1 -0
  65. package/dist/eval/engine/cancellation.js +56 -0
  66. package/dist/eval/engine/cancellation.js.map +1 -0
  67. package/dist/eval/engine/delta.d.ts +104 -0
  68. package/dist/eval/engine/delta.d.ts.map +1 -0
  69. package/dist/eval/engine/delta.js +466 -0
  70. package/dist/eval/engine/delta.js.map +1 -0
  71. package/dist/eval/engine/deps.d.ts +136 -0
  72. package/dist/eval/engine/deps.d.ts.map +1 -0
  73. package/dist/eval/engine/deps.js +345 -0
  74. package/dist/eval/engine/deps.js.map +1 -0
  75. package/dist/eval/engine/identity.d.ts +128 -0
  76. package/dist/eval/engine/identity.d.ts.map +1 -0
  77. package/dist/eval/engine/identity.js +398 -0
  78. package/dist/eval/engine/identity.js.map +1 -0
  79. package/dist/eval/engine/index.d.ts +200 -0
  80. package/dist/eval/engine/index.d.ts.map +1 -0
  81. package/dist/eval/engine/index.js +1242 -0
  82. package/dist/eval/engine/index.js.map +1 -0
  83. package/dist/eval/engine/measurement.d.ts +23 -0
  84. package/dist/eval/engine/measurement.d.ts.map +1 -0
  85. package/dist/eval/engine/measurement.js +42 -0
  86. package/dist/eval/engine/measurement.js.map +1 -0
  87. package/dist/eval/engine/naive.d.ts +19 -0
  88. package/dist/eval/engine/naive.d.ts.map +1 -0
  89. package/dist/eval/engine/naive.js +59 -0
  90. package/dist/eval/engine/naive.js.map +1 -0
  91. package/dist/eval/engine/ops.d.ts +214 -0
  92. package/dist/eval/engine/ops.d.ts.map +1 -0
  93. package/dist/eval/engine/ops.js +1422 -0
  94. package/dist/eval/engine/ops.js.map +1 -0
  95. package/dist/eval/engine/patches.d.ts +40 -0
  96. package/dist/eval/engine/patches.d.ts.map +1 -0
  97. package/dist/eval/engine/patches.js +125 -0
  98. package/dist/eval/engine/patches.js.map +1 -0
  99. package/dist/eval/engine/ports.d.ts +71 -0
  100. package/dist/eval/engine/ports.d.ts.map +1 -0
  101. package/dist/eval/engine/ports.js +2 -0
  102. package/dist/eval/engine/ports.js.map +1 -0
  103. package/dist/eval/engine/session.d.ts +116 -0
  104. package/dist/eval/engine/session.d.ts.map +1 -0
  105. package/dist/eval/engine/session.js +653 -0
  106. package/dist/eval/engine/session.js.map +1 -0
  107. package/dist/eval/engine/snapshot.d.ts +97 -0
  108. package/dist/eval/engine/snapshot.d.ts.map +1 -0
  109. package/dist/eval/engine/snapshot.js +221 -0
  110. package/dist/eval/engine/snapshot.js.map +1 -0
  111. package/dist/eval/engine/subscriptions.d.ts +47 -0
  112. package/dist/eval/engine/subscriptions.d.ts.map +1 -0
  113. package/dist/eval/engine/subscriptions.js +103 -0
  114. package/dist/eval/engine/subscriptions.js.map +1 -0
  115. package/dist/eval/engine/trace.d.ts +77 -0
  116. package/dist/eval/engine/trace.d.ts.map +1 -0
  117. package/dist/eval/engine/trace.js +140 -0
  118. package/dist/eval/engine/trace.js.map +1 -0
  119. package/dist/eval/error-diagnostic.d.ts +26 -0
  120. package/dist/eval/error-diagnostic.d.ts.map +1 -0
  121. package/dist/eval/error-diagnostic.js +63 -0
  122. package/dist/eval/error-diagnostic.js.map +1 -0
  123. package/dist/eval/evaluate-expr.d.ts +44 -0
  124. package/dist/eval/evaluate-expr.d.ts.map +1 -0
  125. package/dist/eval/evaluate-expr.js +149 -0
  126. package/dist/eval/evaluate-expr.js.map +1 -0
  127. package/dist/eval/evaluate.d.ts +282 -0
  128. package/dist/eval/evaluate.d.ts.map +1 -0
  129. package/dist/eval/evaluate.js +391 -0
  130. package/dist/eval/evaluate.js.map +1 -0
  131. package/dist/eval/evolution/relocate.d.ts +72 -0
  132. package/dist/eval/evolution/relocate.d.ts.map +1 -0
  133. package/dist/eval/evolution/relocate.js +427 -0
  134. package/dist/eval/evolution/relocate.js.map +1 -0
  135. package/dist/eval/evolution/select.d.ts +11 -0
  136. package/dist/eval/evolution/select.d.ts.map +1 -0
  137. package/dist/eval/evolution/select.js +53 -0
  138. package/dist/eval/evolution/select.js.map +1 -0
  139. package/dist/eval/evolution/upcast.d.ts +13 -0
  140. package/dist/eval/evolution/upcast.d.ts.map +1 -0
  141. package/dist/eval/evolution/upcast.js +88 -0
  142. package/dist/eval/evolution/upcast.js.map +1 -0
  143. package/dist/eval/expr/aggregates.d.ts +75 -0
  144. package/dist/eval/expr/aggregates.d.ts.map +1 -0
  145. package/dist/eval/expr/aggregates.js +991 -0
  146. package/dist/eval/expr/aggregates.js.map +1 -0
  147. package/dist/eval/expr/arithmetic.d.ts +26 -0
  148. package/dist/eval/expr/arithmetic.d.ts.map +1 -0
  149. package/dist/eval/expr/arithmetic.js +387 -0
  150. package/dist/eval/expr/arithmetic.js.map +1 -0
  151. package/dist/eval/expr/between.d.ts +17 -0
  152. package/dist/eval/expr/between.d.ts.map +1 -0
  153. package/dist/eval/expr/between.js +46 -0
  154. package/dist/eval/expr/between.js.map +1 -0
  155. package/dist/eval/expr/binder.d.ts +96 -0
  156. package/dist/eval/expr/binder.d.ts.map +1 -0
  157. package/dist/eval/expr/binder.js +253 -0
  158. package/dist/eval/expr/binder.js.map +1 -0
  159. package/dist/eval/expr/call-dispatch.d.ts +28 -0
  160. package/dist/eval/expr/call-dispatch.d.ts.map +1 -0
  161. package/dist/eval/expr/call-dispatch.js +114 -0
  162. package/dist/eval/expr/call-dispatch.js.map +1 -0
  163. package/dist/eval/expr/collections.d.ts +20 -0
  164. package/dist/eval/expr/collections.d.ts.map +1 -0
  165. package/dist/eval/expr/collections.js +66 -0
  166. package/dist/eval/expr/collections.js.map +1 -0
  167. package/dist/eval/expr/compare.d.ts +36 -0
  168. package/dist/eval/expr/compare.d.ts.map +1 -0
  169. package/dist/eval/expr/compare.js +115 -0
  170. package/dist/eval/expr/compare.js.map +1 -0
  171. package/dist/eval/expr/datasets.d.ts +28 -0
  172. package/dist/eval/expr/datasets.d.ts.map +1 -0
  173. package/dist/eval/expr/datasets.js +304 -0
  174. package/dist/eval/expr/datasets.js.map +1 -0
  175. package/dist/eval/expr/digest.d.ts +23 -0
  176. package/dist/eval/expr/digest.d.ts.map +1 -0
  177. package/dist/eval/expr/digest.js +89 -0
  178. package/dist/eval/expr/digest.js.map +1 -0
  179. package/dist/eval/expr/domains.d.ts +19 -0
  180. package/dist/eval/expr/domains.d.ts.map +1 -0
  181. package/dist/eval/expr/domains.js +18 -0
  182. package/dist/eval/expr/domains.js.map +1 -0
  183. package/dist/eval/expr/host.d.ts +152 -0
  184. package/dist/eval/expr/host.d.ts.map +1 -0
  185. package/dist/eval/expr/host.js +36 -0
  186. package/dist/eval/expr/host.js.map +1 -0
  187. package/dist/eval/expr/lists.d.ts +24 -0
  188. package/dist/eval/expr/lists.d.ts.map +1 -0
  189. package/dist/eval/expr/lists.js +155 -0
  190. package/dist/eval/expr/lists.js.map +1 -0
  191. package/dist/eval/expr/member.d.ts +15 -0
  192. package/dist/eval/expr/member.d.ts.map +1 -0
  193. package/dist/eval/expr/member.js +32 -0
  194. package/dist/eval/expr/member.js.map +1 -0
  195. package/dist/eval/expr/money-ops.d.ts +10 -0
  196. package/dist/eval/expr/money-ops.d.ts.map +1 -0
  197. package/dist/eval/expr/money-ops.js +17 -0
  198. package/dist/eval/expr/money-ops.js.map +1 -0
  199. package/dist/eval/expr/operands.d.ts +27 -0
  200. package/dist/eval/expr/operands.d.ts.map +1 -0
  201. package/dist/eval/expr/operands.js +167 -0
  202. package/dist/eval/expr/operands.js.map +1 -0
  203. package/dist/eval/expr/presence.d.ts +27 -0
  204. package/dist/eval/expr/presence.d.ts.map +1 -0
  205. package/dist/eval/expr/presence.js +140 -0
  206. package/dist/eval/expr/presence.js.map +1 -0
  207. package/dist/eval/expr/records.d.ts +22 -0
  208. package/dist/eval/expr/records.d.ts.map +1 -0
  209. package/dist/eval/expr/records.js +101 -0
  210. package/dist/eval/expr/records.js.map +1 -0
  211. package/dist/eval/expr/rule-refs.d.ts +25 -0
  212. package/dist/eval/expr/rule-refs.d.ts.map +1 -0
  213. package/dist/eval/expr/rule-refs.js +60 -0
  214. package/dist/eval/expr/rule-refs.js.map +1 -0
  215. package/dist/eval/expr/sequences.d.ts +26 -0
  216. package/dist/eval/expr/sequences.d.ts.map +1 -0
  217. package/dist/eval/expr/sequences.js +151 -0
  218. package/dist/eval/expr/sequences.js.map +1 -0
  219. package/dist/eval/expr/value.d.ts +99 -0
  220. package/dist/eval/expr/value.d.ts.map +1 -0
  221. package/dist/eval/expr/value.js +14 -0
  222. package/dist/eval/expr/value.js.map +1 -0
  223. package/dist/eval/expression.d.ts +142 -0
  224. package/dist/eval/expression.d.ts.map +1 -0
  225. package/dist/eval/expression.js +446 -0
  226. package/dist/eval/expression.js.map +1 -0
  227. package/dist/eval/firing.d.ts +68 -0
  228. package/dist/eval/firing.d.ts.map +1 -0
  229. package/dist/eval/firing.js +222 -0
  230. package/dist/eval/firing.js.map +1 -0
  231. package/dist/eval/gate.d.ts +110 -0
  232. package/dist/eval/gate.d.ts.map +1 -0
  233. package/dist/eval/gate.js +278 -0
  234. package/dist/eval/gate.js.map +1 -0
  235. package/dist/eval/layout-visibility.d.ts +18 -0
  236. package/dist/eval/layout-visibility.d.ts.map +1 -0
  237. package/dist/eval/layout-visibility.js +61 -0
  238. package/dist/eval/layout-visibility.js.map +1 -0
  239. package/dist/eval/option-availability.d.ts +26 -0
  240. package/dist/eval/option-availability.d.ts.map +1 -0
  241. package/dist/eval/option-availability.js +580 -0
  242. package/dist/eval/option-availability.js.map +1 -0
  243. package/dist/eval/options-boundary.d.ts +15 -0
  244. package/dist/eval/options-boundary.d.ts.map +1 -0
  245. package/dist/eval/options-boundary.js +40 -0
  246. package/dist/eval/options-boundary.js.map +1 -0
  247. package/dist/eval/options.d.ts +99 -0
  248. package/dist/eval/options.d.ts.map +1 -0
  249. package/dist/eval/options.js +96 -0
  250. package/dist/eval/options.js.map +1 -0
  251. package/dist/eval/overrides.d.ts +116 -0
  252. package/dist/eval/overrides.d.ts.map +1 -0
  253. package/dist/eval/overrides.js +176 -0
  254. package/dist/eval/overrides.js.map +1 -0
  255. package/dist/eval/paths.d.ts +25 -0
  256. package/dist/eval/paths.d.ts.map +1 -0
  257. package/dist/eval/paths.js +47 -0
  258. package/dist/eval/paths.js.map +1 -0
  259. package/dist/eval/presentation-reads.d.ts +20 -0
  260. package/dist/eval/presentation-reads.d.ts.map +1 -0
  261. package/dist/eval/presentation-reads.js +2 -0
  262. package/dist/eval/presentation-reads.js.map +1 -0
  263. package/dist/eval/presentation.d.ts +122 -0
  264. package/dist/eval/presentation.d.ts.map +1 -0
  265. package/dist/eval/presentation.js +255 -0
  266. package/dist/eval/presentation.js.map +1 -0
  267. package/dist/eval/reader/context-value.d.ts +41 -0
  268. package/dist/eval/reader/context-value.d.ts.map +1 -0
  269. package/dist/eval/reader/context-value.js +129 -0
  270. package/dist/eval/reader/context-value.js.map +1 -0
  271. package/dist/eval/reader/covered.d.ts +53 -0
  272. package/dist/eval/reader/covered.d.ts.map +1 -0
  273. package/dist/eval/reader/covered.js +139 -0
  274. package/dist/eval/reader/covered.js.map +1 -0
  275. package/dist/eval/reader/declarations.d.ts +182 -0
  276. package/dist/eval/reader/declarations.d.ts.map +1 -0
  277. package/dist/eval/reader/declarations.js +153 -0
  278. package/dist/eval/reader/declarations.js.map +1 -0
  279. package/dist/eval/reader/member-access.d.ts +87 -0
  280. package/dist/eval/reader/member-access.d.ts.map +1 -0
  281. package/dist/eval/reader/member-access.js +212 -0
  282. package/dist/eval/reader/member-access.js.map +1 -0
  283. package/dist/eval/reader/memo.d.ts +34 -0
  284. package/dist/eval/reader/memo.d.ts.map +1 -0
  285. package/dist/eval/reader/memo.js +67 -0
  286. package/dist/eval/reader/memo.js.map +1 -0
  287. package/dist/eval/reader/overlay.d.ts +74 -0
  288. package/dist/eval/reader/overlay.d.ts.map +1 -0
  289. package/dist/eval/reader/overlay.js +365 -0
  290. package/dist/eval/reader/overlay.js.map +1 -0
  291. package/dist/eval/reader/questions.d.ts +37 -0
  292. package/dist/eval/reader/questions.d.ts.map +1 -0
  293. package/dist/eval/reader/questions.js +78 -0
  294. package/dist/eval/reader/questions.js.map +1 -0
  295. package/dist/eval/reader/resolve.d.ts +84 -0
  296. package/dist/eval/reader/resolve.d.ts.map +1 -0
  297. package/dist/eval/reader/resolve.js +310 -0
  298. package/dist/eval/reader/resolve.js.map +1 -0
  299. package/dist/eval/reader/value-read.d.ts +50 -0
  300. package/dist/eval/reader/value-read.d.ts.map +1 -0
  301. package/dist/eval/reader/value-read.js +133 -0
  302. package/dist/eval/reader/value-read.js.map +1 -0
  303. package/dist/eval/reader/withheld.d.ts +48 -0
  304. package/dist/eval/reader/withheld.d.ts.map +1 -0
  305. package/dist/eval/reader/withheld.js +108 -0
  306. package/dist/eval/reader/withheld.js.map +1 -0
  307. package/dist/eval/reader-paths.d.ts +24 -0
  308. package/dist/eval/reader-paths.d.ts.map +1 -0
  309. package/dist/eval/reader-paths.js +23 -0
  310. package/dist/eval/reader-paths.js.map +1 -0
  311. package/dist/eval/reader.d.ts +281 -0
  312. package/dist/eval/reader.d.ts.map +1 -0
  313. package/dist/eval/reader.js +560 -0
  314. package/dist/eval/reader.js.map +1 -0
  315. package/dist/eval/receipt.d.ts +37 -0
  316. package/dist/eval/receipt.d.ts.map +1 -0
  317. package/dist/eval/receipt.js +222 -0
  318. package/dist/eval/receipt.js.map +1 -0
  319. package/dist/eval/report/assemble.d.ts +84 -0
  320. package/dist/eval/report/assemble.d.ts.map +1 -0
  321. package/dist/eval/report/assemble.js +277 -0
  322. package/dist/eval/report/assemble.js.map +1 -0
  323. package/dist/eval/report/fold.d.ts +18 -0
  324. package/dist/eval/report/fold.d.ts.map +1 -0
  325. package/dist/eval/report/fold.js +58 -0
  326. package/dist/eval/report/fold.js.map +1 -0
  327. package/dist/eval/rule/alternatives.d.ts +23 -0
  328. package/dist/eval/rule/alternatives.d.ts.map +1 -0
  329. package/dist/eval/rule/alternatives.js +46 -0
  330. package/dist/eval/rule/alternatives.js.map +1 -0
  331. package/dist/eval/rule/behaviour.d.ts +47 -0
  332. package/dist/eval/rule/behaviour.d.ts.map +1 -0
  333. package/dist/eval/rule/behaviour.js +249 -0
  334. package/dist/eval/rule/behaviour.js.map +1 -0
  335. package/dist/eval/rule/compute.d.ts +46 -0
  336. package/dist/eval/rule/compute.d.ts.map +1 -0
  337. package/dist/eval/rule/compute.js +158 -0
  338. package/dist/eval/rule/compute.js.map +1 -0
  339. package/dist/eval/rule/create-state.d.ts +42 -0
  340. package/dist/eval/rule/create-state.d.ts.map +1 -0
  341. package/dist/eval/rule/create-state.js +134 -0
  342. package/dist/eval/rule/create-state.js.map +1 -0
  343. package/dist/eval/rule/diagnostics.d.ts +24 -0
  344. package/dist/eval/rule/diagnostics.d.ts.map +1 -0
  345. package/dist/eval/rule/diagnostics.js +45 -0
  346. package/dist/eval/rule/diagnostics.js.map +1 -0
  347. package/dist/eval/rule/execution.d.ts +24 -0
  348. package/dist/eval/rule/execution.d.ts.map +1 -0
  349. package/dist/eval/rule/execution.js +495 -0
  350. package/dist/eval/rule/execution.js.map +1 -0
  351. package/dist/eval/rule/gate.d.ts +12 -0
  352. package/dist/eval/rule/gate.d.ts.map +1 -0
  353. package/dist/eval/rule/gate.js +34 -0
  354. package/dist/eval/rule/gate.js.map +1 -0
  355. package/dist/eval/rule/item.d.ts +11 -0
  356. package/dist/eval/rule/item.d.ts.map +1 -0
  357. package/dist/eval/rule/item.js +265 -0
  358. package/dist/eval/rule/item.js.map +1 -0
  359. package/dist/eval/rule/prepare.d.ts +64 -0
  360. package/dist/eval/rule/prepare.d.ts.map +1 -0
  361. package/dist/eval/rule/prepare.js +131 -0
  362. package/dist/eval/rule/prepare.js.map +1 -0
  363. package/dist/eval/rule/result.d.ts +97 -0
  364. package/dist/eval/rule/result.d.ts.map +1 -0
  365. package/dist/eval/rule/result.js +347 -0
  366. package/dist/eval/rule/result.js.map +1 -0
  367. package/dist/eval/rule/runner.d.ts +128 -0
  368. package/dist/eval/rule/runner.d.ts.map +1 -0
  369. package/dist/eval/rule/runner.js +296 -0
  370. package/dist/eval/rule/runner.js.map +1 -0
  371. package/dist/eval/rule/screen.d.ts +32 -0
  372. package/dist/eval/rule/screen.d.ts.map +1 -0
  373. package/dist/eval/rule/screen.js +73 -0
  374. package/dist/eval/rule/screen.js.map +1 -0
  375. package/dist/eval/rule/state.d.ts +137 -0
  376. package/dist/eval/rule/state.d.ts.map +1 -0
  377. package/dist/eval/rule/state.js +2 -0
  378. package/dist/eval/rule/state.js.map +1 -0
  379. package/dist/eval/rule/steps.d.ts +44 -0
  380. package/dist/eval/rule/steps.d.ts.map +1 -0
  381. package/dist/eval/rule/steps.js +367 -0
  382. package/dist/eval/rule/steps.js.map +1 -0
  383. package/dist/eval/rule/visibility.d.ts +18 -0
  384. package/dist/eval/rule/visibility.d.ts.map +1 -0
  385. package/dist/eval/rule/visibility.js +79 -0
  386. package/dist/eval/rule/visibility.js.map +1 -0
  387. package/dist/eval/seal.d.ts +74 -0
  388. package/dist/eval/seal.d.ts.map +1 -0
  389. package/dist/eval/seal.js +154 -0
  390. package/dist/eval/seal.js.map +1 -0
  391. package/dist/eval/signature-coverage.d.ts +19 -0
  392. package/dist/eval/signature-coverage.d.ts.map +1 -0
  393. package/dist/eval/signature-coverage.js +160 -0
  394. package/dist/eval/signature-coverage.js.map +1 -0
  395. package/dist/eval/state/derive.d.ts +72 -0
  396. package/dist/eval/state/derive.d.ts.map +1 -0
  397. package/dist/eval/state/derive.js +61 -0
  398. package/dist/eval/state/derive.js.map +1 -0
  399. package/dist/eval/state/describe.d.ts +18 -0
  400. package/dist/eval/state/describe.d.ts.map +1 -0
  401. package/dist/eval/state/describe.js +19 -0
  402. package/dist/eval/state/describe.js.map +1 -0
  403. package/dist/eval/state/field-state.d.ts +471 -0
  404. package/dist/eval/state/field-state.d.ts.map +1 -0
  405. package/dist/eval/state/field-state.js +1604 -0
  406. package/dist/eval/state/field-state.js.map +1 -0
  407. package/dist/eval/state/measurement.d.ts +136 -0
  408. package/dist/eval/state/measurement.d.ts.map +1 -0
  409. package/dist/eval/state/measurement.js +209 -0
  410. package/dist/eval/state/measurement.js.map +1 -0
  411. package/dist/eval/state/options.d.ts +21 -0
  412. package/dist/eval/state/options.d.ts.map +1 -0
  413. package/dist/eval/state/options.js +3 -0
  414. package/dist/eval/state/options.js.map +1 -0
  415. package/dist/eval/state/readiness.d.ts +400 -0
  416. package/dist/eval/state/readiness.d.ts.map +1 -0
  417. package/dist/eval/state/readiness.js +1067 -0
  418. package/dist/eval/state/readiness.js.map +1 -0
  419. package/dist/eval/state/snapshot.d.ts +130 -0
  420. package/dist/eval/state/snapshot.d.ts.map +1 -0
  421. package/dist/eval/state/snapshot.js +35 -0
  422. package/dist/eval/state/snapshot.js.map +1 -0
  423. package/dist/eval/state/unavailable-options.d.ts +54 -0
  424. package/dist/eval/state/unavailable-options.d.ts.map +1 -0
  425. package/dist/eval/state/unavailable-options.js +82 -0
  426. package/dist/eval/state/unavailable-options.js.map +1 -0
  427. package/dist/eval/state/value-state.d.ts +38 -0
  428. package/dist/eval/state/value-state.d.ts.map +1 -0
  429. package/dist/eval/state/value-state.js +52 -0
  430. package/dist/eval/state/value-state.js.map +1 -0
  431. package/dist/eval/submission/admission.d.ts +50 -0
  432. package/dist/eval/submission/admission.d.ts.map +1 -0
  433. package/dist/eval/submission/admission.js +174 -0
  434. package/dist/eval/submission/admission.js.map +1 -0
  435. package/dist/eval/submission/authority.d.ts +71 -0
  436. package/dist/eval/submission/authority.d.ts.map +1 -0
  437. package/dist/eval/submission/authority.js +118 -0
  438. package/dist/eval/submission/authority.js.map +1 -0
  439. package/dist/eval/submission/datasets.d.ts +28 -0
  440. package/dist/eval/submission/datasets.d.ts.map +1 -0
  441. package/dist/eval/submission/datasets.js +109 -0
  442. package/dist/eval/submission/datasets.js.map +1 -0
  443. package/dist/eval/submission/index.d.ts +15 -0
  444. package/dist/eval/submission/index.d.ts.map +1 -0
  445. package/dist/eval/submission/index.js +13 -0
  446. package/dist/eval/submission/index.js.map +1 -0
  447. package/dist/eval/submission/refusals.d.ts +103 -0
  448. package/dist/eval/submission/refusals.d.ts.map +1 -0
  449. package/dist/eval/submission/refusals.js +15 -0
  450. package/dist/eval/submission/refusals.js.map +1 -0
  451. package/dist/eval/submission/signatures.d.ts +7 -0
  452. package/dist/eval/submission/signatures.d.ts.map +1 -0
  453. package/dist/eval/submission/signatures.js +215 -0
  454. package/dist/eval/submission/signatures.js.map +1 -0
  455. package/dist/eval/submission/writes.d.ts +51 -0
  456. package/dist/eval/submission/writes.d.ts.map +1 -0
  457. package/dist/eval/submission/writes.js +203 -0
  458. package/dist/eval/submission/writes.js.map +1 -0
  459. package/dist/eval/submission.d.ts +53 -0
  460. package/dist/eval/submission.d.ts.map +1 -0
  461. package/dist/eval/submission.js +521 -0
  462. package/dist/eval/submission.js.map +1 -0
  463. package/dist/eval/suggestions-to-engine.d.ts +18 -0
  464. package/dist/eval/suggestions-to-engine.d.ts.map +1 -0
  465. package/dist/eval/suggestions-to-engine.js +40 -0
  466. package/dist/eval/suggestions-to-engine.js.map +1 -0
  467. package/dist/eval/suggestions.d.ts +17 -0
  468. package/dist/eval/suggestions.d.ts.map +1 -0
  469. package/dist/eval/suggestions.js +314 -0
  470. package/dist/eval/suggestions.js.map +1 -0
  471. package/dist/eval/undecided.d.ts +64 -0
  472. package/dist/eval/undecided.d.ts.map +1 -0
  473. package/dist/eval/undecided.js +101 -0
  474. package/dist/eval/undecided.js.map +1 -0
  475. package/dist/eval/verdict.d.ts +66 -0
  476. package/dist/eval/verdict.d.ts.map +1 -0
  477. package/dist/eval/verdict.js +106 -0
  478. package/dist/eval/verdict.js.map +1 -0
  479. package/dist/eval/verify-signature.d.ts +78 -0
  480. package/dist/eval/verify-signature.d.ts.map +1 -0
  481. package/dist/eval/verify-signature.js +185 -0
  482. package/dist/eval/verify-signature.js.map +1 -0
  483. package/dist/eval/version-dispatch.d.ts +38 -0
  484. package/dist/eval/version-dispatch.d.ts.map +1 -0
  485. package/dist/eval/version-dispatch.js +61 -0
  486. package/dist/eval/version-dispatch.js.map +1 -0
  487. package/dist/eval/visibility.d.ts +33 -0
  488. package/dist/eval/visibility.d.ts.map +1 -0
  489. package/dist/eval/visibility.js +83 -0
  490. package/dist/eval/visibility.js.map +1 -0
  491. package/dist/evaluate.d.ts +24 -0
  492. package/dist/evaluate.d.ts.map +1 -0
  493. package/dist/evaluate.js +18 -0
  494. package/dist/evaluate.js.map +1 -0
  495. package/dist/expr/builtin-docs.d.ts +51 -0
  496. package/dist/expr/builtin-docs.d.ts.map +1 -0
  497. package/dist/expr/builtin-docs.js +874 -0
  498. package/dist/expr/builtin-docs.js.map +1 -0
  499. package/dist/expr/builtins.d.ts +50 -0
  500. package/dist/expr/builtins.d.ts.map +1 -0
  501. package/dist/expr/builtins.js +966 -0
  502. package/dist/expr/builtins.js.map +1 -0
  503. package/dist/expr/decimal-precision.d.ts +39 -0
  504. package/dist/expr/decimal-precision.d.ts.map +1 -0
  505. package/dist/expr/decimal-precision.js +62 -0
  506. package/dist/expr/decimal-precision.js.map +1 -0
  507. package/dist/expr/decimal.d.ts +172 -0
  508. package/dist/expr/decimal.d.ts.map +1 -0
  509. package/dist/expr/decimal.js +782 -0
  510. package/dist/expr/decimal.js.map +1 -0
  511. package/dist/expr/deprecations.d.ts +34 -0
  512. package/dist/expr/deprecations.d.ts.map +1 -0
  513. package/dist/expr/deprecations.js +17 -0
  514. package/dist/expr/deprecations.js.map +1 -0
  515. package/dist/expr/diagnostics.d.ts +21 -0
  516. package/dist/expr/diagnostics.d.ts.map +1 -0
  517. package/dist/expr/diagnostics.js +231 -0
  518. package/dist/expr/diagnostics.js.map +1 -0
  519. package/dist/expr/direction.d.ts +30 -0
  520. package/dist/expr/direction.d.ts.map +1 -0
  521. package/dist/expr/direction.js +77 -0
  522. package/dist/expr/direction.js.map +1 -0
  523. package/dist/expr/example-expression.d.ts +62 -0
  524. package/dist/expr/example-expression.d.ts.map +1 -0
  525. package/dist/expr/example-expression.js +670 -0
  526. package/dist/expr/example-expression.js.map +1 -0
  527. package/dist/expr/instant.d.ts +49 -0
  528. package/dist/expr/instant.d.ts.map +1 -0
  529. package/dist/expr/instant.js +111 -0
  530. package/dist/expr/instant.js.map +1 -0
  531. package/dist/expr/logic.d.ts +17 -0
  532. package/dist/expr/logic.d.ts.map +1 -0
  533. package/dist/expr/logic.js +65 -0
  534. package/dist/expr/logic.js.map +1 -0
  535. package/dist/expr/messages.d.ts +45 -0
  536. package/dist/expr/messages.d.ts.map +1 -0
  537. package/dist/expr/messages.js +280 -0
  538. package/dist/expr/messages.js.map +1 -0
  539. package/dist/expr/money.d.ts +38 -0
  540. package/dist/expr/money.d.ts.map +1 -0
  541. package/dist/expr/money.js +127 -0
  542. package/dist/expr/money.js.map +1 -0
  543. package/dist/expr/ordering.d.ts +56 -0
  544. package/dist/expr/ordering.d.ts.map +1 -0
  545. package/dist/expr/ordering.js +167 -0
  546. package/dist/expr/ordering.js.map +1 -0
  547. package/dist/expr/pattern.d.ts +44 -0
  548. package/dist/expr/pattern.d.ts.map +1 -0
  549. package/dist/expr/pattern.js +458 -0
  550. package/dist/expr/pattern.js.map +1 -0
  551. package/dist/expr/plain-date.d.ts +90 -0
  552. package/dist/expr/plain-date.d.ts.map +1 -0
  553. package/dist/expr/plain-date.js +230 -0
  554. package/dist/expr/plain-date.js.map +1 -0
  555. package/dist/expr/plural-categories.d.ts +8 -0
  556. package/dist/expr/plural-categories.d.ts.map +1 -0
  557. package/dist/expr/plural-categories.js +15 -0
  558. package/dist/expr/plural-categories.js.map +1 -0
  559. package/dist/expr/plural-keys.d.ts +39 -0
  560. package/dist/expr/plural-keys.d.ts.map +1 -0
  561. package/dist/expr/plural-keys.js +46 -0
  562. package/dist/expr/plural-keys.js.map +1 -0
  563. package/dist/expr/plural.d.ts +33 -0
  564. package/dist/expr/plural.d.ts.map +1 -0
  565. package/dist/expr/plural.js +50 -0
  566. package/dist/expr/plural.js.map +1 -0
  567. package/dist/expr/quantity.d.ts +31 -0
  568. package/dist/expr/quantity.d.ts.map +1 -0
  569. package/dist/expr/quantity.js +83 -0
  570. package/dist/expr/quantity.js.map +1 -0
  571. package/dist/expr/reduce.d.ts +50 -0
  572. package/dist/expr/reduce.d.ts.map +1 -0
  573. package/dist/expr/reduce.js +236 -0
  574. package/dist/expr/reduce.js.map +1 -0
  575. package/dist/expr/regex.d.ts +108 -0
  576. package/dist/expr/regex.d.ts.map +1 -0
  577. package/dist/expr/regex.js +1210 -0
  578. package/dist/expr/regex.js.map +1 -0
  579. package/dist/expr/select-locale.d.ts +67 -0
  580. package/dist/expr/select-locale.d.ts.map +1 -0
  581. package/dist/expr/select-locale.js +219 -0
  582. package/dist/expr/select-locale.js.map +1 -0
  583. package/dist/expr/sequences.d.ts +123 -0
  584. package/dist/expr/sequences.d.ts.map +1 -0
  585. package/dist/expr/sequences.js +234 -0
  586. package/dist/expr/sequences.js.map +1 -0
  587. package/dist/expr/strings.d.ts +50 -0
  588. package/dist/expr/strings.d.ts.map +1 -0
  589. package/dist/expr/strings.js +184 -0
  590. package/dist/expr/strings.js.map +1 -0
  591. package/dist/expr/validation.d.ts +32 -0
  592. package/dist/expr/validation.d.ts.map +1 -0
  593. package/dist/expr/validation.js +182 -0
  594. package/dist/expr/validation.js.map +1 -0
  595. package/dist/graph/freeze.d.ts +4 -0
  596. package/dist/graph/freeze.d.ts.map +1 -0
  597. package/dist/graph/freeze.js +52 -0
  598. package/dist/graph/freeze.js.map +1 -0
  599. package/dist/graph/index.d.ts +15 -0
  600. package/dist/graph/index.d.ts.map +1 -0
  601. package/dist/graph/index.js +13 -0
  602. package/dist/graph/index.js.map +1 -0
  603. package/dist/graph/inspect.d.ts +76 -0
  604. package/dist/graph/inspect.d.ts.map +1 -0
  605. package/dist/graph/inspect.js +263 -0
  606. package/dist/graph/inspect.js.map +1 -0
  607. package/dist/graph/read-walk.d.ts +101 -0
  608. package/dist/graph/read-walk.d.ts.map +1 -0
  609. package/dist/graph/read-walk.js +358 -0
  610. package/dist/graph/read-walk.js.map +1 -0
  611. package/dist/graph/record-index.d.ts +24 -0
  612. package/dist/graph/record-index.d.ts.map +1 -0
  613. package/dist/graph/record-index.js +35 -0
  614. package/dist/graph/record-index.js.map +1 -0
  615. package/dist/index.d.ts +104 -0
  616. package/dist/index.d.ts.map +1 -0
  617. package/dist/index.js +139 -0
  618. package/dist/index.js.map +1 -0
  619. package/dist/lookup/digest.d.ts +51 -0
  620. package/dist/lookup/digest.d.ts.map +1 -0
  621. package/dist/lookup/digest.js +46 -0
  622. package/dist/lookup/digest.js.map +1 -0
  623. package/dist/lookup/index.d.ts +28 -0
  624. package/dist/lookup/index.d.ts.map +1 -0
  625. package/dist/lookup/index.js +27 -0
  626. package/dist/lookup/index.js.map +1 -0
  627. package/dist/lookup/install.d.ts +48 -0
  628. package/dist/lookup/install.d.ts.map +1 -0
  629. package/dist/lookup/install.js +315 -0
  630. package/dist/lookup/install.js.map +1 -0
  631. package/dist/lookup/pass.d.ts +55 -0
  632. package/dist/lookup/pass.d.ts.map +1 -0
  633. package/dist/lookup/pass.js +212 -0
  634. package/dist/lookup/pass.js.map +1 -0
  635. package/dist/lookup/pins.d.ts +34 -0
  636. package/dist/lookup/pins.d.ts.map +1 -0
  637. package/dist/lookup/pins.js +39 -0
  638. package/dist/lookup/pins.js.map +1 -0
  639. package/dist/lookup/provenance.d.ts +23 -0
  640. package/dist/lookup/provenance.d.ts.map +1 -0
  641. package/dist/lookup/provenance.js +78 -0
  642. package/dist/lookup/provenance.js.map +1 -0
  643. package/dist/lookup/readiness.d.ts +13 -0
  644. package/dist/lookup/readiness.d.ts.map +1 -0
  645. package/dist/lookup/readiness.js +57 -0
  646. package/dist/lookup/readiness.js.map +1 -0
  647. package/dist/lookup/resolve.d.ts +24 -0
  648. package/dist/lookup/resolve.d.ts.map +1 -0
  649. package/dist/lookup/resolve.js +201 -0
  650. package/dist/lookup/resolve.js.map +1 -0
  651. package/dist/lookup/store.d.ts +41 -0
  652. package/dist/lookup/store.d.ts.map +1 -0
  653. package/dist/lookup/store.js +74 -0
  654. package/dist/lookup/store.js.map +1 -0
  655. package/dist/model/access.d.ts +200 -0
  656. package/dist/model/access.d.ts.map +1 -0
  657. package/dist/model/access.js +125 -0
  658. package/dist/model/access.js.map +1 -0
  659. package/dist/model/artifact-members.d.ts +3 -0
  660. package/dist/model/artifact-members.d.ts.map +1 -0
  661. package/dist/model/artifact-members.js +38 -0
  662. package/dist/model/artifact-members.js.map +1 -0
  663. package/dist/model/composition.d.ts +47 -0
  664. package/dist/model/composition.d.ts.map +1 -0
  665. package/dist/model/composition.js +66 -0
  666. package/dist/model/composition.js.map +1 -0
  667. package/dist/model/domain.d.ts +51 -0
  668. package/dist/model/domain.d.ts.map +1 -0
  669. package/dist/model/domain.js +75 -0
  670. package/dist/model/domain.js.map +1 -0
  671. package/dist/model/duration.d.ts +31 -0
  672. package/dist/model/duration.d.ts.map +1 -0
  673. package/dist/model/duration.js +136 -0
  674. package/dist/model/duration.js.map +1 -0
  675. package/dist/model/errors.d.ts +58 -0
  676. package/dist/model/errors.d.ts.map +1 -0
  677. package/dist/model/errors.js +81 -0
  678. package/dist/model/errors.js.map +1 -0
  679. package/dist/model/evolution.d.ts +177 -0
  680. package/dist/model/evolution.d.ts.map +1 -0
  681. package/dist/model/evolution.js +5 -0
  682. package/dist/model/evolution.js.map +1 -0
  683. package/dist/model/expr-children.d.ts +15 -0
  684. package/dist/model/expr-children.d.ts.map +1 -0
  685. package/dist/model/expr-children.js +45 -0
  686. package/dist/model/expr-children.js.map +1 -0
  687. package/dist/model/guards.d.ts +9 -0
  688. package/dist/model/guards.d.ts.map +1 -0
  689. package/dist/model/guards.js +11 -0
  690. package/dist/model/guards.js.map +1 -0
  691. package/dist/model/input.d.ts +42 -0
  692. package/dist/model/input.d.ts.map +1 -0
  693. package/dist/model/input.js +26 -0
  694. package/dist/model/input.js.map +1 -0
  695. package/dist/model/integer.d.ts +14 -0
  696. package/dist/model/integer.d.ts.map +1 -0
  697. package/dist/model/integer.js +16 -0
  698. package/dist/model/integer.js.map +1 -0
  699. package/dist/model/intrinsic.d.ts +18 -0
  700. package/dist/model/intrinsic.d.ts.map +1 -0
  701. package/dist/model/intrinsic.js +21 -0
  702. package/dist/model/intrinsic.js.map +1 -0
  703. package/dist/model/layout.d.ts +129 -0
  704. package/dist/model/layout.d.ts.map +1 -0
  705. package/dist/model/layout.js +2 -0
  706. package/dist/model/layout.js.map +1 -0
  707. package/dist/model/media.d.ts +33 -0
  708. package/dist/model/media.d.ts.map +1 -0
  709. package/dist/model/media.js +86 -0
  710. package/dist/model/media.js.map +1 -0
  711. package/dist/model/members.generated.d.ts +11 -0
  712. package/dist/model/members.generated.d.ts.map +1 -0
  713. package/dist/model/members.generated.js +71 -0
  714. package/dist/model/members.generated.js.map +1 -0
  715. package/dist/model/row-address.d.ts +27 -0
  716. package/dist/model/row-address.d.ts.map +1 -0
  717. package/dist/model/row-address.js +146 -0
  718. package/dist/model/row-address.js.map +1 -0
  719. package/dist/model/schema.d.ts +108 -0
  720. package/dist/model/schema.d.ts.map +1 -0
  721. package/dist/model/schema.js +2 -0
  722. package/dist/model/schema.js.map +1 -0
  723. package/dist/model/shape.d.ts +193 -0
  724. package/dist/model/shape.d.ts.map +1 -0
  725. package/dist/model/shape.js +2 -0
  726. package/dist/model/shape.js.map +1 -0
  727. package/dist/model/time.d.ts +61 -0
  728. package/dist/model/time.d.ts.map +1 -0
  729. package/dist/model/time.js +110 -0
  730. package/dist/model/time.js.map +1 -0
  731. package/dist/model/types.d.ts +1329 -0
  732. package/dist/model/types.d.ts.map +1 -0
  733. package/dist/model/types.js +424 -0
  734. package/dist/model/types.js.map +1 -0
  735. package/dist/model/values.d.ts +91 -0
  736. package/dist/model/values.d.ts.map +1 -0
  737. package/dist/model/values.js +195 -0
  738. package/dist/model/values.js.map +1 -0
  739. package/dist/model/wire.d.ts +356 -0
  740. package/dist/model/wire.d.ts.map +1 -0
  741. package/dist/model/wire.js +1504 -0
  742. package/dist/model/wire.js.map +1 -0
  743. package/dist/offline/index.d.ts +374 -0
  744. package/dist/offline/index.d.ts.map +1 -0
  745. package/dist/offline/index.js +422 -0
  746. package/dist/offline/index.js.map +1 -0
  747. package/dist/testing.d.ts +30 -0
  748. package/dist/testing.d.ts.map +1 -0
  749. package/dist/testing.js +42 -0
  750. package/dist/testing.js.map +1 -0
  751. package/dist/version.d.ts +30 -0
  752. package/dist/version.d.ts.map +1 -0
  753. package/dist/version.js +116 -0
  754. package/dist/version.js.map +1 -0
  755. package/package.json +98 -3
@@ -0,0 +1,128 @@
1
+ import type { WireValue } from '../../model/types.js';
2
+ import type { CompiledSchema } from '../../model/schema.js';
3
+ import type { FormStateOptions } from '../state/options.js';
4
+ import type { IdFactory } from './ports.js';
5
+ /**
6
+ * `SessionIdentity`, `spec/semantics/identity-v1.md`.
7
+ *
8
+ * Row order and row identity are one fact, so they are kept in one place: an `assigned` array
9
+ * carries an ordered manifest of host-minted ids, and a `natural` or value-identified array
10
+ * derives its keys from the values themselves and keeps no second list. Every structural
11
+ * operation moves a value and the manifest in one step, so a row can never be addressed by a
12
+ * position that a reorder has since moved.
13
+ */
14
+ /** The refusal `spec/semantics/identity-v1.md` states, with the array or row it names. */
15
+ export type IdentityRefusal = {
16
+ readonly outcome: 'refused';
17
+ readonly code: 'ROW_KEY_DUPLICATE';
18
+ readonly fieldId: string;
19
+ readonly rowKey: string | number;
20
+ } | {
21
+ readonly outcome: 'refused';
22
+ readonly code: 'ROW_KEY_NOT_FOUND';
23
+ readonly fieldId: string;
24
+ readonly rowKey: string | number;
25
+ } | {
26
+ readonly outcome: 'refused';
27
+ readonly code: 'IDENTITY_UNSUPPORTED';
28
+ readonly fieldId: string;
29
+ } | {
30
+ readonly outcome: 'refused';
31
+ readonly code: 'ID_FACTORY_REQUIRED';
32
+ readonly fieldId: string;
33
+ } | {
34
+ readonly outcome: 'refused';
35
+ readonly code: 'ROW_INDEX_OUT_OF_RANGE';
36
+ readonly fieldId: string;
37
+ readonly index: number;
38
+ };
39
+ /** The identity state of one session. Values live in the session; identity lives here. */
40
+ export interface SessionIdentity {
41
+ /** The ordered id list of each `assigned` array whose identity is known. */
42
+ readonly manifests: ReadonlyMap<string, readonly string[]>;
43
+ }
44
+ /** A structural operation's whole effect: the next values and the next identity together. */
45
+ export interface IdentityStep {
46
+ readonly values: Readonly<Record<string, WireValue>>;
47
+ readonly identity: SessionIdentity;
48
+ }
49
+ /** The outcome of opening or hydrating one session's identity. */
50
+ export type IdentityOutcome = ({
51
+ readonly outcome: 'ok';
52
+ } & IdentityStep) | IdentityRefusal;
53
+ /**
54
+ * The refusal an open states when the artifact assigns row identity and the host supplied no
55
+ * factory, `[IDENT-2.1.7]`.
56
+ *
57
+ * A manifest that already names every current row does not lift the requirement: a later append
58
+ * or insert mints through the factory, and a session that could not complete that operation would
59
+ * have accepted a record it cannot maintain. This is the artifact-level form of the check
60
+ * `openIdentity` makes as it walks; a manifest open never reaches that walk, so it asks here.
61
+ */
62
+ export declare function factoryRefusal(compiled: CompiledSchema, idFactory: IdFactory | undefined): IdentityRefusal | undefined;
63
+ /**
64
+ * Opens the identity of a new session over initial values, `[IDENT-3.1.1]`.
65
+ *
66
+ * A new session has no saved identity to preserve, so each assigned array's manifest is
67
+ * minted in committed order. A duplicate natural key, or a row whose declared key member is
68
+ * absent, is refused before any session state exists.
69
+ */
70
+ export declare function openIdentity(compiled: CompiledSchema, values: Readonly<Record<string, WireValue>>, idFactory: IdFactory | undefined): IdentityOutcome;
71
+ /**
72
+ * Reconciles a hydrated payload's identity, `[IDENT-3.1.1]`–`[IDENT-3.1.3]`.
73
+ *
74
+ * A payload that carries a manifest for an assigned array restores it after checking that it
75
+ * names one id per row and no id twice. A payload that carries none leaves that array
76
+ * `unsupported`: the rows stay in the record, and no operation can address one by identity
77
+ * until a manifest arrives, because inferring identity from position is forbidden.
78
+ */
79
+ export declare function hydrateIdentity(compiled: CompiledSchema, values: Readonly<Record<string, WireValue>>, manifest: Readonly<Record<string, readonly string[]>> | undefined): IdentityOutcome;
80
+ /** The identity options the derived form state reads, `[ENGINE-7.1.6]`. */
81
+ export declare function identityOptions(identity: SessionIdentity): FormStateOptions;
82
+ /**
83
+ * The row keys one array addresses, in committed order.
84
+ *
85
+ * `undefined` means the array's identity does not reconcile: a caller must not read that as
86
+ * "no rows" and must not invent a positional key.
87
+ */
88
+ export declare function rowKeysOf(compiled: CompiledSchema, identity: SessionIdentity, values: Readonly<Record<string, WireValue>>, fieldId: string): readonly (string | number)[] | undefined;
89
+ /** The position of one row in committed order, or `undefined` when the key names none. */
90
+ export declare function rowIndexOf(compiled: CompiledSchema, identity: SessionIdentity, values: Readonly<Record<string, WireValue>>, fieldId: string, rowKey: string | number): number | undefined;
91
+ /** A structural operation's intent, before identity has resolved it. */
92
+ export type StructuralChange = {
93
+ readonly kind: 'append';
94
+ readonly fieldId: string;
95
+ readonly value: WireValue;
96
+ } | {
97
+ readonly kind: 'insert';
98
+ readonly fieldId: string;
99
+ readonly index: number;
100
+ readonly value: WireValue;
101
+ } | {
102
+ readonly kind: 'remove';
103
+ readonly fieldId: string;
104
+ readonly rowKey: string | number;
105
+ } | {
106
+ readonly kind: 'move';
107
+ readonly fieldId: string;
108
+ readonly rowKey: string | number;
109
+ readonly toIndex: number;
110
+ };
111
+ /**
112
+ * Whether one array's committed identity still holds after a value write, `[IDENT-2.1.6]`.
113
+ *
114
+ * A row write can break identity without touching the manifest: clearing a natural key, giving
115
+ * two rows one value in a value-identified array, or writing `null` where the item value *is*
116
+ * the identity. Answering `undefined` for "no identity" would silently make the array
117
+ * unaddressable, so the write is refused with the reason instead.
118
+ */
119
+ export declare function validateArrayIdentity(compiled: CompiledSchema, identity: SessionIdentity, values: Readonly<Record<string, WireValue>>, fieldId: string): IdentityRefusal | undefined;
120
+ /**
121
+ * Applies one structural operation to values and identity together, `[IDENT-2.1.4]`.
122
+ *
123
+ * The value list and the manifest move in one step, so no state exists in which a row is
124
+ * addressed by a position the other list has already left. Access is the caller's question;
125
+ * this function only answers identity.
126
+ */
127
+ export declare function applyStructural(compiled: CompiledSchema, identity: SessionIdentity, values: Readonly<Record<string, WireValue>>, change: StructuralChange, idFactory: IdFactory): IdentityStep | IdentityRefusal;
128
+ //# sourceMappingURL=identity.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"identity.d.ts","sourceRoot":"","sources":["../../../src/eval/engine/identity.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAY5D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAC5D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAE5C;;;;;;;;GAQG;AAEH,0FAA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AS,EAAE,SAAS,GACnB,YAAY,GAAG,eAAe,CA4GhC"}
@@ -0,0 +1,398 @@
1
+ import { wireMembers } from '../../model/values.js';
2
+ import { RESERVED_ROW_KEY } from '../../model/wire.js';
3
+ import { operationAddressingOf, arrayDeclarations, assignedRowKeyOf, declarationOf as arrayDeclarationOf, itemsOf, rowPositionOf, } from '../addressing.js';
4
+ /** The refusal one array's addressing states, or `undefined` when its rows are addressable. */
5
+ function refusalOf(compiled, fieldId, values, manifests) {
6
+ const addressing = operationAddressingOf(compiled, fieldId, values, manifests);
7
+ if (addressing.outcome === 'addressed')
8
+ return undefined;
9
+ if (addressing.outcome === 'duplicate') {
10
+ return { outcome: 'refused', code: 'ROW_KEY_DUPLICATE', fieldId, rowKey: addressing.rowKey };
11
+ }
12
+ return { outcome: 'refused', code: 'IDENTITY_UNSUPPORTED', fieldId };
13
+ }
14
+ /**
15
+ * Whether a natural array states the reserved spelling `current` as one row's key.
16
+ *
17
+ * A missing key member is a fact a rule answers once against the array (`IDENT-2.1.9`), so a
18
+ * natural array that does not reconcile still opens. The reserved spelling is different: the
19
+ * record states a key the report contract refuses (`report.v1.json`), so the array can never be
20
+ * addressed. The open and hydrate doors refuse it through the same unkeyed path an append
21
+ * reaches, and the refusal is `IDENTITY_UNSUPPORTED` rather than a second code.
22
+ */
23
+ function reservedRowKeyPresent(declaration, values) {
24
+ const keyMember = declaration.field.rowKey?.fieldId;
25
+ if (keyMember === undefined)
26
+ return false;
27
+ return itemsOf(values, declaration).some((item) => wireMembers(item)?.[keyMember] === RESERVED_ROW_KEY);
28
+ }
29
+ /** Mints one id for every row of an assigned array, in committed order. */
30
+ function mintManifest(count, idFactory) {
31
+ const ids = [];
32
+ for (let index = 0; index < count; index += 1)
33
+ ids.push(idFactory());
34
+ return ids;
35
+ }
36
+ /** The first top-level assigned array's field id, or `undefined` when the artifact assigns none. */
37
+ function firstAssignedArray(compiled) {
38
+ for (const declaration of arrayDeclarations(compiled)) {
39
+ // An array declared inside another array addresses no row of its own, so it never demands a
40
+ // factory: minting for one would refuse a session over an identity no operation can reach.
41
+ if (declaration.topLevel && declaration.mode === 'assigned')
42
+ return declaration.field.fieldId;
43
+ }
44
+ return undefined;
45
+ }
46
+ /**
47
+ * The refusal an open states when the artifact assigns row identity and the host supplied no
48
+ * factory, `[IDENT-2.1.7]`.
49
+ *
50
+ * A manifest that already names every current row does not lift the requirement: a later append
51
+ * or insert mints through the factory, and a session that could not complete that operation would
52
+ * have accepted a record it cannot maintain. This is the artifact-level form of the check
53
+ * `openIdentity` makes as it walks; a manifest open never reaches that walk, so it asks here.
54
+ */
55
+ export function factoryRefusal(compiled, idFactory) {
56
+ if (idFactory !== undefined)
57
+ return undefined;
58
+ const fieldId = firstAssignedArray(compiled);
59
+ return fieldId === undefined
60
+ ? undefined
61
+ : { outcome: 'refused', code: 'ID_FACTORY_REQUIRED', fieldId };
62
+ }
63
+ /** Validates the host-owned ids before two rows can acquire one binding key. */
64
+ function validateManifest(fieldId, manifest) {
65
+ const seen = new Set();
66
+ for (const supplied of manifest) {
67
+ // The same predicate the row-addressing authority reads, so a session and a stateless
68
+ // derivation never disagree about which id names a row.
69
+ const id = assignedRowKeyOf(supplied);
70
+ if (id === undefined) {
71
+ return { outcome: 'refused', code: 'IDENTITY_UNSUPPORTED', fieldId };
72
+ }
73
+ if (seen.has(id)) {
74
+ return { outcome: 'refused', code: 'ROW_KEY_DUPLICATE', fieldId, rowKey: id };
75
+ }
76
+ seen.add(id);
77
+ }
78
+ return undefined;
79
+ }
80
+ /** Whether one identity step's manifests and values still agree in length. */
81
+ function aligned(identity, declaration, values) {
82
+ if (declaration.mode !== 'assigned')
83
+ return true;
84
+ const manifest = identity.manifests.get(declaration.field.fieldId);
85
+ return manifest === undefined || manifest.length === itemsOf(values, declaration).length;
86
+ }
87
+ /**
88
+ * Opens the identity of a new session over initial values, `[IDENT-3.1.1]`.
89
+ *
90
+ * A new session has no saved identity to preserve, so each assigned array's manifest is
91
+ * minted in committed order. A duplicate natural key, or a row whose declared key member is
92
+ * absent, is refused before any session state exists.
93
+ */
94
+ export function openIdentity(compiled, values, idFactory) {
95
+ const manifests = new Map();
96
+ for (const declaration of arrayDeclarations(compiled)) {
97
+ const fieldId = declaration.field.fieldId;
98
+ // An array declared inside another array addresses no row of its own, so it never mints an
99
+ // id: demanding a factory for one would refuse a session over an identity no operation
100
+ // can reach.
101
+ if (!declaration.topLevel)
102
+ continue;
103
+ if (declaration.mode === 'assigned') {
104
+ if (idFactory === undefined) {
105
+ return { outcome: 'refused', code: 'ID_FACTORY_REQUIRED', fieldId };
106
+ }
107
+ const manifest = mintManifest(itemsOf(values, declaration).length, idFactory);
108
+ const refusal = validateManifest(fieldId, manifest);
109
+ if (refusal !== undefined)
110
+ return refusal;
111
+ manifests.set(fieldId, manifest);
112
+ continue;
113
+ }
114
+ // A natural key is a value the record itself carries, so two rows sharing one is data the
115
+ // user can repair: the session opens and the rule that asks about rows answers per row
116
+ // with `ROW_IDENTITY` (`IDENT-2.1.9`). A value-identified array is different — two rows
117
+ // holding one item value identify no row at all, and the wire contract refuses that
118
+ // (`IDENT-2.1.6`) — so it keeps its open/hydrate refusal below.
119
+ //
120
+ // The answer is still stated once here, through the operation door that charges the work:
121
+ // the opening pass is what builds the addressing a row write later reads, and a duplicate
122
+ // is an answer rather than a refusal.
123
+ if (declaration.mode === 'natural') {
124
+ operationAddressingOf(compiled, fieldId, values, manifests);
125
+ if (reservedRowKeyPresent(declaration, values)) {
126
+ return { outcome: 'refused', code: 'IDENTITY_UNSUPPORTED', fieldId };
127
+ }
128
+ continue;
129
+ }
130
+ const refusal = refusalOf(compiled, fieldId, values, manifests);
131
+ if (refusal !== undefined)
132
+ return refusal;
133
+ }
134
+ return { outcome: 'ok', values, identity: { manifests } };
135
+ }
136
+ /**
137
+ * Reconciles a hydrated payload's identity, `[IDENT-3.1.1]`–`[IDENT-3.1.3]`.
138
+ *
139
+ * A payload that carries a manifest for an assigned array restores it after checking that it
140
+ * names one id per row and no id twice. A payload that carries none leaves that array
141
+ * `unsupported`: the rows stay in the record, and no operation can address one by identity
142
+ * until a manifest arrives, because inferring identity from position is forbidden.
143
+ */
144
+ export function hydrateIdentity(compiled, values, manifest) {
145
+ const manifests = new Map();
146
+ for (const declaration of arrayDeclarations(compiled)) {
147
+ if (!declaration.topLevel)
148
+ continue;
149
+ const fieldId = declaration.field.fieldId;
150
+ if (declaration.mode === 'natural') {
151
+ // Same contract as `openIdentity`: a natural-key duplicate is answered per row by the
152
+ // rule that asks, so the payload the host is trying to repair still opens. The answer is
153
+ // stated here too, so the pass that commits a hydrated record is the one that pays for it.
154
+ operationAddressingOf(compiled, fieldId, values, manifests);
155
+ if (reservedRowKeyPresent(declaration, values)) {
156
+ return { outcome: 'refused', code: 'IDENTITY_UNSUPPORTED', fieldId };
157
+ }
158
+ continue;
159
+ }
160
+ if (declaration.mode !== 'assigned') {
161
+ const refusal = refusalOf(compiled, fieldId, values, manifests);
162
+ if (refusal !== undefined)
163
+ return refusal;
164
+ continue;
165
+ }
166
+ // A field id may be `constructor`; only an own member is a manifest entry, never an
167
+ // inherited object member.
168
+ const supplied = manifest !== undefined && Object.hasOwn(manifest, fieldId) ? manifest[fieldId] : undefined;
169
+ const count = itemsOf(values, declaration).length;
170
+ if (supplied !== undefined) {
171
+ if (!Array.isArray(supplied)) {
172
+ return { outcome: 'refused', code: 'IDENTITY_UNSUPPORTED', fieldId };
173
+ }
174
+ const refusal = validateManifest(fieldId, supplied);
175
+ if (refusal !== undefined)
176
+ return refusal;
177
+ if (supplied.length !== count) {
178
+ return { outcome: 'refused', code: 'IDENTITY_UNSUPPORTED', fieldId };
179
+ }
180
+ manifests.set(fieldId, [...supplied]);
181
+ continue;
182
+ }
183
+ if (count > 0)
184
+ continue;
185
+ manifests.set(fieldId, []);
186
+ }
187
+ return { outcome: 'ok', values, identity: { manifests } };
188
+ }
189
+ /** The identity options the derived form state reads, `[ENGINE-7.1.6]`. */
190
+ export function identityOptions(identity) {
191
+ return { identity: identity.manifests };
192
+ }
193
+ /** The array declaration one field names, when it is a top-level declared array. */
194
+ function declarationOf(compiled, fieldId) {
195
+ const declaration = arrayDeclarationOf(compiled, fieldId);
196
+ return declaration?.topLevel === true ? declaration : undefined;
197
+ }
198
+ /**
199
+ * The row keys one array addresses, in committed order.
200
+ *
201
+ * `undefined` means the array's identity does not reconcile: a caller must not read that as
202
+ * "no rows" and must not invent a positional key.
203
+ */
204
+ export function rowKeysOf(compiled, identity, values, fieldId) {
205
+ const addressing = operationAddressingOf(compiled, fieldId, values, identity.manifests);
206
+ return addressing.outcome === 'addressed' ? addressing.rows.map((row) => row.rowKey) : undefined;
207
+ }
208
+ /** The position of one row in committed order, or `undefined` when the key names none. */
209
+ export function rowIndexOf(compiled, identity, values, fieldId, rowKey) {
210
+ const addressing = operationAddressingOf(compiled, fieldId, values, identity.manifests);
211
+ // The derivation states each row's position beside its key, so a write addresses its row
212
+ // through that answer instead of walking every key the array holds.
213
+ return addressing.outcome === 'addressed' ? rowPositionOf(addressing, rowKey) : undefined;
214
+ }
215
+ /** Replaces one array's value, leaving every other member of the record alone. */
216
+ function withArray(values, declaration, items) {
217
+ const write = (record, depth) => {
218
+ const segment = declaration.path[depth];
219
+ if (segment === undefined)
220
+ return record;
221
+ const value = depth === declaration.path.length - 1
222
+ ? items
223
+ : write(wireMembers(record[segment] ?? null) ?? {}, depth + 1);
224
+ return { ...record, [segment]: value };
225
+ };
226
+ return write(values, 0);
227
+ }
228
+ /** Moves one element of a list, returning a new list. */
229
+ function moved(list, from, to) {
230
+ const next = [...list];
231
+ const [element] = next.splice(from, 1);
232
+ if (element === undefined)
233
+ return list;
234
+ next.splice(to, 0, element);
235
+ return next;
236
+ }
237
+ /**
238
+ * Whether one array's committed identity still holds after a value write, `[IDENT-2.1.6]`.
239
+ *
240
+ * A row write can break identity without touching the manifest: clearing a natural key, giving
241
+ * two rows one value in a value-identified array, or writing `null` where the item value *is*
242
+ * the identity. Answering `undefined` for "no identity" would silently make the array
243
+ * unaddressable, so the write is refused with the reason instead.
244
+ */
245
+ export function validateArrayIdentity(compiled, identity, values, fieldId) {
246
+ const declaration = declarationOf(compiled, fieldId);
247
+ if (declaration === undefined)
248
+ return undefined;
249
+ if (declaration.mode === 'assigned') {
250
+ // A container value write cannot mint or reconcile assigned ids. It may replace row values,
251
+ // but changing the row count without a structural operation would detach the manifest.
252
+ return aligned(identity, declaration, values)
253
+ ? undefined
254
+ : { outcome: 'refused', code: 'IDENTITY_UNSUPPORTED', fieldId };
255
+ }
256
+ return refusalOf(compiled, fieldId, values, identity.manifests);
257
+ }
258
+ /**
259
+ * Applies one structural operation to values and identity together, `[IDENT-2.1.4]`.
260
+ *
261
+ * The value list and the manifest move in one step, so no state exists in which a row is
262
+ * addressed by a position the other list has already left. Access is the caller's question;
263
+ * this function only answers identity.
264
+ */
265
+ export function applyStructural(compiled, identity, values, change, idFactory) {
266
+ const declaration = declarationOf(compiled, change.fieldId);
267
+ if (declaration === undefined) {
268
+ return { outcome: 'refused', code: 'IDENTITY_UNSUPPORTED', fieldId: change.fieldId };
269
+ }
270
+ const fieldId = declaration.field.fieldId;
271
+ const items = itemsOf(values, declaration);
272
+ if (declaration.mode === 'assigned' && !identity.manifests.has(fieldId)) {
273
+ return { outcome: 'refused', code: 'IDENTITY_UNSUPPORTED', fieldId };
274
+ }
275
+ switch (change.kind) {
276
+ case 'append': {
277
+ const nextValues = withArray(values, declaration, [...items, change.value]);
278
+ const manifest = identity.manifests.get(fieldId);
279
+ const nextIdentity = manifest === undefined
280
+ ? identity
281
+ : {
282
+ ...identity,
283
+ manifests: new Map(identity.manifests).set(fieldId, [...manifest, idFactory()]),
284
+ };
285
+ return finish(compiled, declaration, nextValues, nextIdentity);
286
+ }
287
+ case 'insert': {
288
+ if (!Number.isSafeInteger(change.index) || change.index < 0 || change.index > items.length) {
289
+ return {
290
+ outcome: 'refused',
291
+ code: 'ROW_INDEX_OUT_OF_RANGE',
292
+ fieldId,
293
+ index: change.index,
294
+ };
295
+ }
296
+ const nextItems = [...items];
297
+ nextItems.splice(change.index, 0, change.value);
298
+ const manifest = identity.manifests.get(fieldId);
299
+ let nextIdentity = identity;
300
+ if (manifest !== undefined) {
301
+ const nextManifest = [...manifest];
302
+ nextManifest.splice(change.index, 0, idFactory());
303
+ nextIdentity = {
304
+ ...identity,
305
+ manifests: new Map(identity.manifests).set(fieldId, nextManifest),
306
+ };
307
+ }
308
+ return finish(compiled, declaration, withArray(values, declaration, nextItems), nextIdentity);
309
+ }
310
+ case 'remove': {
311
+ const index = rowIndexOf(compiled, identity, values, fieldId, change.rowKey);
312
+ if (index === undefined) {
313
+ return {
314
+ outcome: 'refused',
315
+ code: 'ROW_KEY_NOT_FOUND',
316
+ fieldId,
317
+ rowKey: change.rowKey,
318
+ };
319
+ }
320
+ const nextItems = [...items];
321
+ nextItems.splice(index, 1);
322
+ const manifest = identity.manifests.get(fieldId);
323
+ let nextIdentity = identity;
324
+ if (manifest !== undefined) {
325
+ const nextManifest = [...manifest];
326
+ nextManifest.splice(index, 1);
327
+ nextIdentity = {
328
+ ...identity,
329
+ manifests: new Map(identity.manifests).set(fieldId, nextManifest),
330
+ };
331
+ }
332
+ return finish(compiled, declaration, withArray(values, declaration, nextItems), nextIdentity);
333
+ }
334
+ case 'move': {
335
+ const index = rowIndexOf(compiled, identity, values, fieldId, change.rowKey);
336
+ if (index === undefined) {
337
+ return {
338
+ outcome: 'refused',
339
+ code: 'ROW_KEY_NOT_FOUND',
340
+ fieldId,
341
+ rowKey: change.rowKey,
342
+ };
343
+ }
344
+ if (!Number.isSafeInteger(change.toIndex) ||
345
+ change.toIndex < 0 ||
346
+ change.toIndex >= items.length) {
347
+ return {
348
+ outcome: 'refused',
349
+ code: 'ROW_INDEX_OUT_OF_RANGE',
350
+ fieldId,
351
+ index: change.toIndex,
352
+ };
353
+ }
354
+ if (index === change.toIndex)
355
+ return { values, identity };
356
+ const nextItems = moved(items, index, change.toIndex);
357
+ const manifest = identity.manifests.get(fieldId);
358
+ const nextIdentity = manifest === undefined
359
+ ? identity
360
+ : {
361
+ ...identity,
362
+ manifests: new Map(identity.manifests).set(fieldId, moved(manifest, index, change.toIndex)),
363
+ };
364
+ return finish(compiled, declaration, withArray(values, declaration, nextItems), nextIdentity);
365
+ }
366
+ }
367
+ }
368
+ /**
369
+ * The final alignment check and the identity step for one structural change.
370
+ *
371
+ * A natural array can be driven into a duplicate by an insert, so the keys are re-derived
372
+ * after the change rather than trusted from before it.
373
+ */
374
+ function finish(compiled, declaration, values, identity) {
375
+ if (declaration.mode !== 'assigned') {
376
+ const refusal = refusalOf(compiled, declaration.field.fieldId, values, identity.manifests);
377
+ if (refusal !== undefined)
378
+ return refusal;
379
+ }
380
+ if (!aligned(identity, declaration, values)) {
381
+ return { outcome: 'refused', code: 'IDENTITY_UNSUPPORTED', fieldId: declaration.field.fieldId };
382
+ }
383
+ if (declaration.mode === 'assigned') {
384
+ const manifest = identity.manifests.get(declaration.field.fieldId);
385
+ if (manifest === undefined) {
386
+ return {
387
+ outcome: 'refused',
388
+ code: 'IDENTITY_UNSUPPORTED',
389
+ fieldId: declaration.field.fieldId,
390
+ };
391
+ }
392
+ const refusal = validateManifest(declaration.field.fieldId, manifest);
393
+ if (refusal !== undefined)
394
+ return refusal;
395
+ }
396
+ return { values, identity };
397
+ }
398
+ //# sourceMappingURL=identity.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"identity.js","sourceRoot":"","sources":["../../../src/eval/engine/identity.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,EACL,qBAAqB,EACrB,iBAAiB,EACjB,gBAAgB,EAChB,aAAa,IAAI,kBAAkB,EACnC,OAAO,EACP,aAAa,GACd,MAAM,kBAAkB,CAAC;AA6D1B,+FAA+F;AAC/F,SAAS,SAAS,CAChB,QAAwB,EACxB,OAAe,EACf,MAA2C,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AO;aACnC,CAAC;QACJ,CAAC;QACD,MAAM,OAAO,GAAG,gBAAgB,CAAC,WAAW,CAAC,KAAK,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;QACtE,IAAI,OAAO,KAAK,SAAS;YAAE,OAAO,OAAO,CAAC;IAC5C,CAAC;IACD,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC;AAC9B,CAAC","sourcesContent":["import type { WireValue } from '../../model/types.js';\nimport type { CompiledSchema } from '../../model/schema.js';\nimport { wireMembers } from '../../model/values.js';\nimport { RESERVED_ROW_KEY } from '../../model/wire.js';\nimport {\n operationAddressingOf,\n arrayDeclarations,\n assignedRowKeyOf,\n declarationOf as arrayDeclarationOf,\n itemsOf,\n rowPositionOf,\n} from '../addressing.js';\nimport type { ArrayDeclaration } from '../addressing.js';\nimport type { FormStateOptions } from '../state/options.js';\nimport type { IdFactory } from './ports.js';\n\n/**\n * `SessionIdentity`, `spec/semantics/identity-v1.md`.\n *\n * Row order and row identity are one fact, so they are kept in one place: an `assigned` array\n * carries an ordered manifest of host-minted ids, and a `natural` or value-identified array\n * derives its keys from the values themselves and keeps no second list. Every structural\n * operation moves a value and the manifest in one step, so a row can never be addressed by a\n * position that a reorder has since moved.\n */\n\n/** The refusal `spec/semantics/identity-v1.md` states, with the array or row it names. */\nexport type IdentityRefusal =\n | {\n readonly outcome: 'refused';\n readonly code: 'ROW_KEY_DUPLICATE';\n readonly fieldId: string;\n readonly rowKey: string | number;\n }\n | {\n readonly outcome: 'refused';\n readonly code: 'ROW_KEY_NOT_FOUND';\n readonly fieldId: string;\n readonly rowKey: string | number;\n }\n | {\n readonly outcome: 'refused';\n readonly code: 'IDENTITY_UNSUPPORTED';\n readonly fieldId: string;\n }\n | {\n readonly outcome: 'refused';\n readonly code: 'ID_FACTORY_REQUIRED';\n readonly fieldId: string;\n }\n | {\n readonly outcome: 'refused';\n readonly code: 'ROW_INDEX_OUT_OF_RANGE';\n readonly fieldId: string;\n readonly index: number;\n };\n\n/** The identity state of one session. Values live in the session; identity lives here. */\nexport interface SessionIdentity {\n /** The ordered id list of each `assigned` array whose identity is known. */\n readonly manifests: ReadonlyMap<string, readonly string[]>;\n}\n\n/** A structural operation's whole effect: the next values and the next identity together. */\nexport interface IdentityStep {\n readonly values: Readonly<Record<string, WireValue>>;\n readonly identity: SessionIdentity;\n}\n\n/** The outcome of opening or hydrating one session's identity. */\nexport type IdentityOutcome = ({ readonly outcome: 'ok' } & IdentityStep) | IdentityRefusal;\n\n/** The refusal one array's addressing states, or `undefined` when its rows are addressable. */\nfunction refusalOf(\n compiled: CompiledSchema,\n fieldId: string,\n values: Readonly<Record<string, WireValue>>,\n manifests: SessionIdentity['manifests'],\n): IdentityRefusal | undefined {\n const addressing = operationAddressingOf(compiled, fieldId, values, manifests);\n if (addressing.outcome === 'addressed') return undefined;\n if (addressing.outcome === 'duplicate') {\n return { outcome: 'refused', code: 'ROW_KEY_DUPLICATE', fieldId, rowKey: addressing.rowKey };\n }\n return { outcome: 'refused', code: 'IDENTITY_UNSUPPORTED', fieldId };\n}\n\n/**\n * Whether a natural array states the reserved spelling `current` as one row's key.\n *\n * A missing key member is a fact a rule answers once against the array (`IDENT-2.1.9`), so a\n * natural array that does not reconcile still opens. The reserved spelling is different: the\n * record states a key the report contract refuses (`report.v1.json`), so the array can never be\n * addressed. The open and hydrate doors refuse it through the same unkeyed path an append\n * reaches, and the refusal is `IDENTITY_UNSUPPORTED` rather than a second code.\n */\nfunction reservedRowKeyPresent(\n declaration: ArrayDeclaration,\n values: Readonly<Record<string, WireValue>>,\n): boolean {\n const keyMember = declaration.field.rowKey?.fieldId;\n if (keyMember === undefined) return false;\n return itemsOf(values, declaration).some(\n (item) => wireMembers(item)?.[keyMember] === RESERVED_ROW_KEY,\n );\n}\n\n/** Mints one id for every row of an assigned array, in committed order. */\nfunction mintManifest(count: number, idFactory: IdFactory): readonly string[] {\n const ids: string[] = [];\n for (let index = 0; index < count; index += 1) ids.push(idFactory());\n return ids;\n}\n\n/** The first top-level assigned array's field id, or `undefined` when the artifact assigns none. */\nfunction firstAssignedArray(compiled: CompiledSchema): string | undefined {\n for (const declaration of arrayDeclarations(compiled)) {\n // An array declared inside another array addresses no row of its own, so it never demands a\n // factory: minting for one would refuse a session over an identity no operation can reach.\n if (declaration.topLevel && declaration.mode === 'assigned') return declaration.field.fieldId;\n }\n return undefined;\n}\n\n/**\n * The refusal an open states when the artifact assigns row identity and the host supplied no\n * factory, `[IDENT-2.1.7]`.\n *\n * A manifest that already names every current row does not lift the requirement: a later append\n * or insert mints through the factory, and a session that could not complete that operation would\n * have accepted a record it cannot maintain. This is the artifact-level form of the check\n * `openIdentity` makes as it walks; a manifest open never reaches that walk, so it asks here.\n */\nexport function factoryRefusal(\n compiled: CompiledSchema,\n idFactory: IdFactory | undefined,\n): IdentityRefusal | undefined {\n if (idFactory !== undefined) return undefined;\n const fieldId = firstAssignedArray(compiled);\n return fieldId === undefined\n ? undefined\n : { outcome: 'refused', code: 'ID_FACTORY_REQUIRED', fieldId };\n}\n\n/** Validates the host-owned ids before two rows can acquire one binding key. */\nfunction validateManifest(\n fieldId: string,\n manifest: readonly unknown[],\n): IdentityRefusal | undefined {\n const seen = new Set<string>();\n for (const supplied of manifest) {\n // The same predicate the row-addressing authority reads, so a session and a stateless\n // derivation never disagree about which id names a row.\n const id = assignedRowKeyOf(supplied);\n if (id === undefined) {\n return { outcome: 'refused', code: 'IDENTITY_UNSUPPORTED', fieldId };\n }\n if (seen.has(id)) {\n return { outcome: 'refused', code: 'ROW_KEY_DUPLICATE', fieldId, rowKey: id };\n }\n seen.add(id);\n }\n return undefined;\n}\n\n/** Whether one identity step's manifests and values still agree in length. */\nfunction aligned(\n identity: SessionIdentity,\n declaration: ArrayDeclaration,\n values: Readonly<Record<string, WireValue>>,\n): boolean {\n if (declaration.mode !== 'assigned') return true;\n const manifest = identity.manifests.get(declaration.field.fieldId);\n return manifest === undefined || manifest.length === itemsOf(values, declaration).length;\n}\n\n/**\n * Opens the identity of a new session over initial values, `[IDENT-3.1.1]`.\n *\n * A new session has no saved identity to preserve, so each assigned array's manifest is\n * minted in committed order. A duplicate natural key, or a row whose declared key member is\n * absent, is refused before any session state exists.\n */\nexport function openIdentity(\n compiled: CompiledSchema,\n values: Readonly<Record<string, WireValue>>,\n idFactory: IdFactory | undefined,\n): IdentityOutcome {\n const manifests = new Map<string, readonly string[]>();\n for (const declaration of arrayDeclarations(compiled)) {\n const fieldId = declaration.field.fieldId;\n // An array declared inside another array addresses no row of its own, so it never mints an\n // id: demanding a factory for one would refuse a session over an identity no operation\n // can reach.\n if (!declaration.topLevel) continue;\n if (declaration.mode === 'assigned') {\n if (idFactory === undefined) {\n return { outcome: 'refused', code: 'ID_FACTORY_REQUIRED', fieldId };\n }\n const manifest = mintManifest(itemsOf(values, declaration).length, idFactory);\n const refusal = validateManifest(fieldId, manifest);\n if (refusal !== undefined) return refusal;\n manifests.set(fieldId, manifest);\n continue;\n }\n // A natural key is a value the record itself carries, so two rows sharing one is data the\n // user can repair: the session opens and the rule that asks about rows answers per row\n // with `ROW_IDENTITY` (`IDENT-2.1.9`). A value-identified array is different — two rows\n // holding one item value identify no row at all, and the wire contract refuses that\n // (`IDENT-2.1.6`) — so it keeps its open/hydrate refusal below.\n //\n // The answer is still stated once here, through the operation door that charges the work:\n // the opening pass is what builds the addressing a row write later reads, and a duplicate\n // is an answer rather than a refusal.\n if (declaration.mode === 'natural') {\n operationAddressingOf(compiled, fieldId, values, manifests);\n if (reservedRowKeyPresent(declaration, values)) {\n return { outcome: 'refused', code: 'IDENTITY_UNSUPPORTED', fieldId };\n }\n continue;\n }\n const refusal = refusalOf(compiled, fieldId, values, manifests);\n if (refusal !== undefined) return refusal;\n }\n return { outcome: 'ok', values, identity: { manifests } };\n}\n\n/**\n * Reconciles a hydrated payload's identity, `[IDENT-3.1.1]`–`[IDENT-3.1.3]`.\n *\n * A payload that carries a manifest for an assigned array restores it after checking that it\n * names one id per row and no id twice. A payload that carries none leaves that array\n * `unsupported`: the rows stay in the record, and no operation can address one by identity\n * until a manifest arrives, because inferring identity from position is forbidden.\n */\nexport function hydrateIdentity(\n compiled: CompiledSchema,\n values: Readonly<Record<string, WireValue>>,\n manifest: Readonly<Record<string, readonly string[]>> | undefined,\n): IdentityOutcome {\n const manifests = new Map<string, readonly string[]>();\n for (const declaration of arrayDeclarations(compiled)) {\n if (!declaration.topLevel) continue;\n const fieldId = declaration.field.fieldId;\n if (declaration.mode === 'natural') {\n // Same contract as `openIdentity`: a natural-key duplicate is answered per row by the\n // rule that asks, so the payload the host is trying to repair still opens. The answer is\n // stated here too, so the pass that commits a hydrated record is the one that pays for it.\n operationAddressingOf(compiled, fieldId, values, manifests);\n if (reservedRowKeyPresent(declaration, values)) {\n return { outcome: 'refused', code: 'IDENTITY_UNSUPPORTED', fieldId };\n }\n continue;\n }\n if (declaration.mode !== 'assigned') {\n const refusal = refusalOf(compiled, fieldId, values, manifests);\n if (refusal !== undefined) return refusal;\n continue;\n }\n // A field id may be `constructor`; only an own member is a manifest entry, never an\n // inherited object member.\n const supplied =\n manifest !== undefined && Object.hasOwn(manifest, fieldId) ? manifest[fieldId] : undefined;\n const count = itemsOf(values, declaration).length;\n if (supplied !== undefined) {\n if (!Array.isArray(supplied)) {\n return { outcome: 'refused', code: 'IDENTITY_UNSUPPORTED', fieldId };\n }\n const refusal = validateManifest(fieldId, supplied);\n if (refusal !== undefined) return refusal;\n if (supplied.length !== count) {\n return { outcome: 'refused', code: 'IDENTITY_UNSUPPORTED', fieldId };\n }\n manifests.set(fieldId, [...supplied]);\n continue;\n }\n if (count > 0) continue;\n manifests.set(fieldId, []);\n }\n return { outcome: 'ok', values, identity: { manifests } };\n}\n\n/** The identity options the derived form state reads, `[ENGINE-7.1.6]`. */\nexport function identityOptions(identity: SessionIdentity): FormStateOptions {\n return { identity: identity.manifests };\n}\n\n/** The array declaration one field names, when it is a top-level declared array. */\nfunction declarationOf(compiled: CompiledSchema, fieldId: string): ArrayDeclaration | undefined {\n const declaration = arrayDeclarationOf(compiled, fieldId);\n return declaration?.topLevel === true ? declaration : undefined;\n}\n\n/**\n * The row keys one array addresses, in committed order.\n *\n * `undefined` means the array's identity does not reconcile: a caller must not read that as\n * \"no rows\" and must not invent a positional key.\n */\nexport function rowKeysOf(\n compiled: CompiledSchema,\n identity: SessionIdentity,\n values: Readonly<Record<string, WireValue>>,\n fieldId: string,\n): readonly (string | number)[] | undefined {\n const addressing = operationAddressingOf(compiled, fieldId, values, identity.manifests);\n return addressing.outcome === 'addressed' ? addressing.rows.map((row) => row.rowKey) : undefined;\n}\n\n/** The position of one row in committed order, or `undefined` when the key names none. */\nexport function rowIndexOf(\n compiled: CompiledSchema,\n identity: SessionIdentity,\n values: Readonly<Record<string, WireValue>>,\n fieldId: string,\n rowKey: string | number,\n): number | undefined {\n const addressing = operationAddressingOf(compiled, fieldId, values, identity.manifests);\n // The derivation states each row's position beside its key, so a write addresses its row\n // through that answer instead of walking every key the array holds.\n return addressing.outcome === 'addressed' ? rowPositionOf(addressing, rowKey) : undefined;\n}\n\n/** A structural operation's intent, before identity has resolved it. */\nexport type StructuralChange =\n | { readonly kind: 'append'; readonly fieldId: string; readonly value: WireValue }\n | {\n readonly kind: 'insert';\n readonly fieldId: string;\n readonly index: number;\n readonly value: WireValue;\n }\n | { readonly kind: 'remove'; readonly fieldId: string; readonly rowKey: string | number }\n | {\n readonly kind: 'move';\n readonly fieldId: string;\n readonly rowKey: string | number;\n readonly toIndex: number;\n };\n\n/** Replaces one array's value, leaving every other member of the record alone. */\nfunction withArray(\n values: Readonly<Record<string, WireValue>>,\n declaration: ArrayDeclaration,\n items: readonly WireValue[],\n): Readonly<Record<string, WireValue>> {\n const write = (\n record: Readonly<Record<string, WireValue>>,\n depth: number,\n ): Readonly<Record<string, WireValue>> => {\n const segment = declaration.path[depth];\n if (segment === undefined) return record;\n const value =\n depth === declaration.path.length - 1\n ? items\n : write(wireMembers(record[segment] ?? null) ?? {}, depth + 1);\n return { ...record, [segment]: value };\n };\n return write(values, 0);\n}\n\n/** Moves one element of a list, returning a new list. */\nfunction moved<T>(list: readonly T[], from: number, to: number): readonly T[] {\n const next = [...list];\n const [element] = next.splice(from, 1);\n if (element === undefined) return list;\n next.splice(to, 0, element);\n return next;\n}\n\n/**\n * Whether one array's committed identity still holds after a value write, `[IDENT-2.1.6]`.\n *\n * A row write can break identity without touching the manifest: clearing a natural key, giving\n * two rows one value in a value-identified array, or writing `null` where the item value *is*\n * the identity. Answering `undefined` for \"no identity\" would silently make the array\n * unaddressable, so the write is refused with the reason instead.\n */\nexport function validateArrayIdentity(\n compiled: CompiledSchema,\n identity: SessionIdentity,\n values: Readonly<Record<string, WireValue>>,\n fieldId: string,\n): IdentityRefusal | undefined {\n const declaration = declarationOf(compiled, fieldId);\n if (declaration === undefined) return undefined;\n if (declaration.mode === 'assigned') {\n // A container value write cannot mint or reconcile assigned ids. It may replace row values,\n // but changing the row count without a structural operation would detach the manifest.\n return aligned(identity, declaration, values)\n ? undefined\n : { outcome: 'refused', code: 'IDENTITY_UNSUPPORTED', fieldId };\n }\n return refusalOf(compiled, fieldId, values, identity.manifests);\n}\n\n/**\n * Applies one structural operation to values and identity together, `[IDENT-2.1.4]`.\n *\n * The value list and the manifest move in one step, so no state exists in which a row is\n * addressed by a position the other list has already left. Access is the caller's question;\n * this function only answers identity.\n */\nexport function applyStructural(\n compiled: CompiledSchema,\n identity: SessionIdentity,\n values: Readonly<Record<string, WireValue>>,\n change: StructuralChange,\n idFactory: IdFactory,\n): IdentityStep | IdentityRefusal {\n const declaration = declarationOf(compiled, change.fieldId);\n if (declaration === undefined) {\n return { outcome: 'refused', code: 'IDENTITY_UNSUPPORTED', fieldId: change.fieldId };\n }\n const fieldId = declaration.field.fieldId;\n const items = itemsOf(values, declaration);\n if (declaration.mode === 'assigned' && !identity.manifests.has(fieldId)) {\n return { outcome: 'refused', code: 'IDENTITY_UNSUPPORTED', fieldId };\n }\n switch (change.kind) {\n case 'append': {\n const nextValues = withArray(values, declaration, [...items, change.value]);\n const manifest = identity.manifests.get(fieldId);\n const nextIdentity =\n manifest === undefined\n ? identity\n : {\n ...identity,\n manifests: new Map(identity.manifests).set(fieldId, [...manifest, idFactory()]),\n };\n return finish(compiled, declaration, nextValues, nextIdentity);\n }\n case 'insert': {\n if (!Number.isSafeInteger(change.index) || change.index < 0 || change.index > items.length) {\n return {\n outcome: 'refused',\n code: 'ROW_INDEX_OUT_OF_RANGE',\n fieldId,\n index: change.index,\n };\n }\n const nextItems = [...items];\n nextItems.splice(change.index, 0, change.value);\n const manifest = identity.manifests.get(fieldId);\n let nextIdentity = identity;\n if (manifest !== undefined) {\n const nextManifest = [...manifest];\n nextManifest.splice(change.index, 0, idFactory());\n nextIdentity = {\n ...identity,\n manifests: new Map(identity.manifests).set(fieldId, nextManifest),\n };\n }\n return finish(compiled, declaration, withArray(values, declaration, nextItems), nextIdentity);\n }\n case 'remove': {\n const index = rowIndexOf(compiled, identity, values, fieldId, change.rowKey);\n if (index === undefined) {\n return {\n outcome: 'refused',\n code: 'ROW_KEY_NOT_FOUND',\n fieldId,\n rowKey: change.rowKey,\n };\n }\n const nextItems = [...items];\n nextItems.splice(index, 1);\n const manifest = identity.manifests.get(fieldId);\n let nextIdentity = identity;\n if (manifest !== undefined) {\n const nextManifest = [...manifest];\n nextManifest.splice(index, 1);\n nextIdentity = {\n ...identity,\n manifests: new Map(identity.manifests).set(fieldId, nextManifest),\n };\n }\n return finish(compiled, declaration, withArray(values, declaration, nextItems), nextIdentity);\n }\n case 'move': {\n const index = rowIndexOf(compiled, identity, values, fieldId, change.rowKey);\n if (index === undefined) {\n return {\n outcome: 'refused',\n code: 'ROW_KEY_NOT_FOUND',\n fieldId,\n rowKey: change.rowKey,\n };\n }\n if (\n !Number.isSafeInteger(change.toIndex) ||\n change.toIndex < 0 ||\n change.toIndex >= items.length\n ) {\n return {\n outcome: 'refused',\n code: 'ROW_INDEX_OUT_OF_RANGE',\n fieldId,\n index: change.toIndex,\n };\n }\n if (index === change.toIndex) return { values, identity };\n const nextItems = moved(items, index, change.toIndex);\n const manifest = identity.manifests.get(fieldId);\n const nextIdentity =\n manifest === undefined\n ? identity\n : {\n ...identity,\n manifests: new Map(identity.manifests).set(\n fieldId,\n moved(manifest, index, change.toIndex),\n ),\n };\n return finish(compiled, declaration, withArray(values, declaration, nextItems), nextIdentity);\n }\n }\n}\n\n/**\n * The final alignment check and the identity step for one structural change.\n *\n * A natural array can be driven into a duplicate by an insert, so the keys are re-derived\n * after the change rather than trusted from before it.\n */\nfunction finish(\n compiled: CompiledSchema,\n declaration: ArrayDeclaration,\n values: Readonly<Record<string, WireValue>>,\n identity: SessionIdentity,\n): IdentityStep | IdentityRefusal {\n if (declaration.mode !== 'assigned') {\n const refusal = refusalOf(compiled, declaration.field.fieldId, values, identity.manifests);\n if (refusal !== undefined) return refusal;\n }\n if (!aligned(identity, declaration, values)) {\n return { outcome: 'refused', code: 'IDENTITY_UNSUPPORTED', fieldId: declaration.field.fieldId };\n }\n if (declaration.mode === 'assigned') {\n const manifest = identity.manifests.get(declaration.field.fieldId);\n if (manifest === undefined) {\n return {\n outcome: 'refused',\n code: 'IDENTITY_UNSUPPORTED',\n fieldId: declaration.field.fieldId,\n };\n }\n const refusal = validateManifest(declaration.field.fieldId, manifest);\n if (refusal !== undefined) return refusal;\n }\n return { values, identity };\n}\n"]}