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

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 +1207 -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,1242 @@
1
+ import { AxiomError } from '../../model/errors.js';
2
+ import { canonicalHashOwned, copyRestricted } from '../../canonical/jcs.js';
3
+ import { objectShapeViolation } from '../../canonical/restricted.js';
4
+ import { evaluationInputOf, parsedAccessOf } from '../../model/input.js';
5
+ import { isSafeInteger } from '../../model/integer.js';
6
+ import { isTier } from '../../model/types.js';
7
+ import { isRecord, isWireValue } from '../../model/values.js';
8
+ import { toLookupPort } from '../../model/wire.js';
9
+ import { projectSubmission } from '../submission.js';
10
+ import { freezeTree, sealReport } from '../seal.js';
11
+ import { fieldKey, permitsReadOf } from '../access/projection.js';
12
+ import { permitsUserWrite } from '../access/write.js';
13
+ import { engineGraph } from './deps.js';
14
+ import { candidateDelta, identifyBlockers } from './delta.js';
15
+ import { rowKeysOf } from './identity.js';
16
+ import { noteDeliveryIndexWalk } from './measurement.js';
17
+ import { declarationFor, freezeOperations, sameOperations } from './ops.js';
18
+ import { assertArtifactReceipt } from '../receipt.js';
19
+ import { deriveSession, hydrateSession, openSession } from './session.js';
20
+ import { addresses, bindingKeyOf, fieldIndex, refOfBindingKey, sameData, snapshotOf, absentRowSnapshot, } from './snapshot.js';
21
+ import { EngineSubscriptions } from './subscriptions.js';
22
+ import { explainFieldOf, inspectFieldDepsOf } from './trace.js';
23
+ export { SESSION_REFUSAL_CODES, SESSION_REFUSAL_REPAIRS, sessionRefusalRepair } from './ops.js';
24
+ export { SessionRefusedError } from './session.js';
25
+ /**
26
+ * The largest number of queued listener operations one commit drains before refusing the rest.
27
+ *
28
+ * Bounding total drained operations rather than rounds lets a finite multi-link listener cascade
29
+ * commit every link cleanly, while stopping a livelocking listener that writes on every
30
+ * notification and reporting the abandoned work with `DRAIN_BUDGET_EXCEEDED`.
31
+ */
32
+ const MAX_DRAIN_OPERATIONS = 256;
33
+ /**
34
+ * The maximum number of recent derived candidates retained for by-value `commit()` lookup on the
35
+ * current committed basis.
36
+ *
37
+ * Bounding retention keeps repeated `preview()` and `propose()` calls on one basis O(1) in both
38
+ * memory and insert cost while still allowing recent by-value copies to commit with their exact
39
+ * displayed row keys (`[ENGINE-8.2.3]`). Live candidate references still resolve in O(1) through
40
+ * `derivedCandidates` regardless of this window.
41
+ */
42
+ const MAX_BASIS_CANDIDATES = 32;
43
+ function isWriteOrigin(value) {
44
+ return value === 'user' || value === 'system' || value === 'hydrate' || value === 'sync';
45
+ }
46
+ function isFieldAccess(value) {
47
+ return (value === 'read_write' ||
48
+ value === 'read_only' ||
49
+ value === 'write_only' ||
50
+ value === 'masked' ||
51
+ value === 'hidden');
52
+ }
53
+ function isOverlayKind(value) {
54
+ return value === 'exact' || value === 'template' || value === 'container' || value === 'section';
55
+ }
56
+ /** Rejects accessors, symbol keys, non-enumerable members and callable `toJSON` on untrusted containers. */
57
+ function hasPlainShape(value, trusted) {
58
+ return trusted || objectShapeViolation(value) === undefined;
59
+ }
60
+ /** Copies a dense array of strings in one pass, or returns `undefined` if any entry is not a string. */
61
+ function copyStringArray(value, trusted) {
62
+ if (!Array.isArray(value) || !hasPlainShape(value, trusted))
63
+ return undefined;
64
+ const out = [];
65
+ for (let index = 0; index < value.length; index += 1) {
66
+ if (!trusted && !Object.hasOwn(value, index))
67
+ return undefined;
68
+ const entry = value[index];
69
+ if (typeof entry !== 'string')
70
+ return undefined;
71
+ out.push(entry);
72
+ }
73
+ return out;
74
+ }
75
+ /**
76
+ * Copies an untrusted value into a fresh restricted-JSON tree in one pass so a mutating getter
77
+ * cannot validate cleanly and then throw during canonicalisation.
78
+ */
79
+ function copyKeyValue(value, trusted) {
80
+ if (trusted) {
81
+ return isWireValue(value) ? { ok: true, value } : { ok: false };
82
+ }
83
+ try {
84
+ const copied = copyRestricted(value, '$');
85
+ return isWireValue(copied) ? { ok: true, value: copied } : { ok: false };
86
+ }
87
+ catch {
88
+ return { ok: false };
89
+ }
90
+ }
91
+ /**
92
+ * Whether a derived state carries an assigned-row manifest that changed from committed state and
93
+ * whose keys are not all visible in `form`.
94
+ */
95
+ function hasHiddenManifest(derived, committedManifests) {
96
+ const { manifests } = derived.working.identity;
97
+ if (manifests.size === 0)
98
+ return false;
99
+ const fieldsById = fieldIndex(derived.form);
100
+ for (const [fieldId, ids] of manifests) {
101
+ if (ids.length === 0)
102
+ continue;
103
+ const committed = committedManifests.get(fieldId);
104
+ if (committed !== undefined &&
105
+ committed.length === ids.length &&
106
+ committed.every((id, index) => id === ids[index])) {
107
+ continue;
108
+ }
109
+ const visibleKeys = fieldsById.get(fieldId)?.addressableRows;
110
+ if (visibleKeys === undefined ||
111
+ visibleKeys.length !== ids.length ||
112
+ visibleKeys.some((key, index) => key !== ids[index])) {
113
+ return true;
114
+ }
115
+ }
116
+ return false;
117
+ }
118
+ /** A compact canonical digest of an assigned-row manifest map, empty when no manifest is held. */
119
+ function manifestKey(manifests) {
120
+ if (manifests.size === 0)
121
+ return '';
122
+ const entries = [...manifests.entries()].sort(([left], [right]) => left < right ? -1 : left > right ? 1 : 0);
123
+ return canonicalHashOwned(entries);
124
+ }
125
+ /** Normalises a field reference into a canonical ref object, or `undefined` when malformed. */
126
+ function normalizeRefForKey(value, trusted) {
127
+ if (!isRecord(value) || !hasPlainShape(value, trusted))
128
+ return undefined;
129
+ const fieldId = value['fieldId'];
130
+ if (typeof fieldId !== 'string')
131
+ return undefined;
132
+ const rowKey = value['rowKey'];
133
+ if (rowKey === undefined)
134
+ return { fieldId };
135
+ if (typeof rowKey !== 'string' && (typeof rowKey !== 'number' || !isSafeInteger(rowKey))) {
136
+ return undefined;
137
+ }
138
+ return { fieldId, rowKey };
139
+ }
140
+ /** Normalises an access overlay into a fresh copied overlay, or `undefined` when malformed. */
141
+ function normalizeOverlayForKey(value, trusted) {
142
+ if (!isRecord(value) || !hasPlainShape(value, trusted))
143
+ return undefined;
144
+ const accessVersion = value['accessVersion'];
145
+ const defaultAccess = value['defaultAccess'];
146
+ const rules = value['rules'];
147
+ if (typeof accessVersion !== 'number' || !isSafeInteger(accessVersion))
148
+ return undefined;
149
+ if (!isFieldAccess(defaultAccess))
150
+ return undefined;
151
+ if (!Array.isArray(rules) || !hasPlainShape(rules, trusted))
152
+ return undefined;
153
+ const copiedRules = [];
154
+ for (let index = 0; index < rules.length; index += 1) {
155
+ if (!trusted && !Object.hasOwn(rules, index))
156
+ return undefined;
157
+ const rule = rules[index];
158
+ if (!isRecord(rule) || !hasPlainShape(rule, trusted))
159
+ return undefined;
160
+ if (!trusted && Object.keys(rule).length !== 3)
161
+ return undefined;
162
+ const kind = rule['kind'];
163
+ const match = rule['match'];
164
+ const access = rule['access'];
165
+ if (!isOverlayKind(kind) || typeof match !== 'string' || !isFieldAccess(access)) {
166
+ return undefined;
167
+ }
168
+ copiedRules.push({ kind, match, access });
169
+ }
170
+ const allowMaskedRead = value['allowMaskedRead'];
171
+ let copiedAllowMaskedRead;
172
+ if (allowMaskedRead !== undefined) {
173
+ copiedAllowMaskedRead = copyStringArray(allowMaskedRead, trusted);
174
+ if (copiedAllowMaskedRead === undefined)
175
+ return undefined;
176
+ }
177
+ return {
178
+ accessVersion,
179
+ defaultAccess,
180
+ rules: copiedRules,
181
+ ...(copiedAllowMaskedRead === undefined ? {} : { allowMaskedRead: copiedAllowMaskedRead }),
182
+ };
183
+ }
184
+ /** The field, row or root one operation names, for the refusal a dropped queued write states. */
185
+ function operationRef(operation) {
186
+ switch (operation.kind) {
187
+ case 'value':
188
+ case 'null':
189
+ case 'remove':
190
+ return {
191
+ fieldId: operation.ref.fieldId,
192
+ ...(operation.ref.rowKey === undefined ? {} : { rowKey: operation.ref.rowKey }),
193
+ };
194
+ case 'append':
195
+ case 'insert':
196
+ return { fieldId: operation.fieldId };
197
+ case 'removeRow':
198
+ case 'move':
199
+ return { fieldId: operation.fieldId, rowKey: operation.rowKey };
200
+ case 'context':
201
+ return { root: operation.root };
202
+ case 'env':
203
+ case 'access':
204
+ return {};
205
+ }
206
+ }
207
+ /** The field entry one identifier names, refusing one the artifact does not declare. */
208
+ function fieldOf(state, fieldId) {
209
+ const field = fieldIndex(state.form).get(fieldId);
210
+ if (field === undefined) {
211
+ throw new AxiomError('ENGINE_ERROR', `no field is named ${fieldId}`, fieldId);
212
+ }
213
+ return field;
214
+ }
215
+ /**
216
+ * Opens one stateful session over a compiled artifact, `createEngine()`.
217
+ *
218
+ * The record and context cross the artifact's boundary before any rule reads them, and an
219
+ * identity the artifact cannot support raises `SessionRefusedError` carrying the structured
220
+ * code — no report is ever produced for it. A malformed value raises the runtime's own refusal
221
+ * with its path. A payload that arrives with its identity manifest opens against those ids.
222
+ *
223
+ * A cost budget refused while a pass derives — an item rule's source cap, the availability row
224
+ * walk, the node or decision ceiling — escapes as the `AxiomError` whose code is
225
+ * `COST_BUDGET_EXCEEDED`. The pass stops and committed state is unchanged: a commit adopts one
226
+ * whole derived state and never a partially derived one, so the record a caller read before the
227
+ * call is the record it reads after.
228
+ */
229
+ export function createEngine(compiled, config) {
230
+ assertArtifactReceipt(compiled);
231
+ const graph = engineGraph(compiled);
232
+ const ports = config.ports ?? {};
233
+ const opened = openSession(compiled, config.input, config.env ?? {}, ports, config.identity);
234
+ let state = opened.state;
235
+ let basis = 0;
236
+ let emitting = false;
237
+ let queue = [];
238
+ // A failing listener is the host's bug; it is reported to the host and never rolls back the
239
+ // commit `[ENGINE-2.1.8]`. With no channel the registry throws it after delivering the rest,
240
+ // so a host cannot mistake a broken form for a quiet one.
241
+ const subscriptions = new EngineSubscriptions(ports.onListenerError);
242
+ const snapshots = new Map();
243
+ /**
244
+ * The sealed report of one committed state. Sealing canonicalises and hashes the body, which
245
+ * a per-keystroke derivation must not pay for; asking for the report once per commit seals it,
246
+ * and the committed report body's identity is what makes the cache correct.
247
+ */
248
+ let sealed;
249
+ let writeSnapshot;
250
+ const sessionWrites = () => {
251
+ if (writeSnapshot?.source !== state.working.sessionWrites) {
252
+ writeSnapshot = {
253
+ source: state.working.sessionWrites,
254
+ refs: Object.freeze([...state.working.sessionWrites.values()].map((ref) => Object.freeze({ ...ref }))),
255
+ };
256
+ }
257
+ return writeSnapshot.refs;
258
+ };
259
+ const sealedReport = () => {
260
+ // A drain can append dropped-write facts to the trace without changing the report body.
261
+ // Keying to the body keeps that bookkeeping from paying a second canonicalisation and hash.
262
+ if (sealed?.body !== state.report)
263
+ sealed = { body: state.report, report: sealReport(state.report) };
264
+ return sealed.report;
265
+ };
266
+ /**
267
+ * The derived state each live candidate would install, so its commit adopts it rather than
268
+ * staging the operations a second time.
269
+ *
270
+ * This is what makes a previewed append and its commit one change: an assigned array's factory
271
+ * is asked once when the candidate is derived, and the row key it minted is the one the commit
272
+ * installs. The map holds only what the candidate itself keeps alive, so a discarded proposal
273
+ * leaves nothing behind.
274
+ */
275
+ const derivedCandidates = new WeakMap();
276
+ /**
277
+ * Stable per-session identity tokens for borrowed `LookupPort` objects so env operations can be
278
+ * indexed canonically without serialising host port methods.
279
+ */
280
+ let nextLookupToken = 0;
281
+ const lookupTokens = new WeakMap();
282
+ const lookupTokenOf = (port, allocate) => {
283
+ const existing = lookupTokens.get(port);
284
+ if (existing !== undefined)
285
+ return existing;
286
+ if (!allocate)
287
+ return undefined;
288
+ nextLookupToken += 1;
289
+ lookupTokens.set(port, nextLookupToken);
290
+ return nextLookupToken;
291
+ };
292
+ const normalizeEnvForKey = (value, trusted) => {
293
+ if (!isRecord(value) || !hasPlainShape(value, trusted))
294
+ return undefined;
295
+ const key = {};
296
+ const tier = value['tier'];
297
+ if (tier !== undefined) {
298
+ if (!isTier(tier))
299
+ return undefined;
300
+ key['tier'] = tier;
301
+ }
302
+ const accessVersion = value['accessVersion'];
303
+ if (accessVersion !== undefined) {
304
+ if (typeof accessVersion !== 'number' || !isSafeInteger(accessVersion))
305
+ return undefined;
306
+ key['accessVersion'] = accessVersion;
307
+ }
308
+ const recordDate = value['recordDate'];
309
+ if (recordDate !== undefined) {
310
+ if (typeof recordDate !== 'string')
311
+ return undefined;
312
+ key['recordDate'] = recordDate;
313
+ }
314
+ const capabilities = value['capabilities'];
315
+ let copiedCapabilities;
316
+ if (capabilities !== undefined) {
317
+ copiedCapabilities = copyStringArray(capabilities, trusted);
318
+ if (copiedCapabilities === undefined)
319
+ return undefined;
320
+ key['capabilities'] = copiedCapabilities;
321
+ }
322
+ const lookup = value['lookup'];
323
+ let checkedLookup;
324
+ if (lookup !== undefined) {
325
+ if ((typeof lookup !== 'object' && typeof lookup !== 'function') || lookup === null) {
326
+ return undefined;
327
+ }
328
+ const token = lookupTokenOf(lookup, trusted);
329
+ if (token === undefined)
330
+ return undefined;
331
+ checkedLookup = toLookupPort(lookup, '$.env.lookup');
332
+ key['lookup'] = token;
333
+ }
334
+ const env = {
335
+ ...(tier === undefined ? {} : { tier }),
336
+ ...(accessVersion === undefined ? {} : { accessVersion }),
337
+ ...(recordDate === undefined ? {} : { recordDate }),
338
+ ...(copiedCapabilities === undefined ? {} : { capabilities: copiedCapabilities }),
339
+ ...(checkedLookup === undefined ? {} : { lookup: checkedLookup }),
340
+ };
341
+ return { key, env };
342
+ };
343
+ const normalizeOperationForKey = (value, trusted) => {
344
+ if (!isRecord(value) || !hasPlainShape(value, trusted))
345
+ return undefined;
346
+ const kind = value['kind'];
347
+ if (typeof kind !== 'string')
348
+ return undefined;
349
+ switch (kind) {
350
+ case 'value': {
351
+ const origin = value['origin'];
352
+ const ref = normalizeRefForKey(value['ref'], trusted);
353
+ const opValue = copyKeyValue(value['value'], trusted);
354
+ if (!isWriteOrigin(origin) || ref === undefined || !opValue.ok)
355
+ return undefined;
356
+ return {
357
+ key: { kind, origin, ref, value: opValue.value },
358
+ operation: { kind: 'value', origin, ref, value: opValue.value },
359
+ };
360
+ }
361
+ case 'null': {
362
+ const origin = value['origin'];
363
+ const ref = normalizeRefForKey(value['ref'], trusted);
364
+ if (!isWriteOrigin(origin) || ref === undefined)
365
+ return undefined;
366
+ return {
367
+ key: { kind, origin, ref },
368
+ operation: { kind: 'null', origin, ref },
369
+ };
370
+ }
371
+ case 'remove': {
372
+ const origin = value['origin'];
373
+ const ref = normalizeRefForKey(value['ref'], trusted);
374
+ if (!isWriteOrigin(origin) || ref === undefined)
375
+ return undefined;
376
+ return {
377
+ key: { kind, origin, ref },
378
+ operation: { kind: 'remove', origin, ref },
379
+ };
380
+ }
381
+ case 'context': {
382
+ const root = value['root'];
383
+ const opValue = copyKeyValue(value['value'], trusted);
384
+ if (typeof root !== 'string' || !opValue.ok)
385
+ return undefined;
386
+ return {
387
+ key: { kind, root, value: opValue.value },
388
+ operation: { kind: 'context', root, value: opValue.value },
389
+ };
390
+ }
391
+ case 'env': {
392
+ const parsedEnv = normalizeEnvForKey(value['env'], trusted);
393
+ if (parsedEnv === undefined)
394
+ return undefined;
395
+ return {
396
+ key: { kind, env: parsedEnv.key },
397
+ operation: { kind: 'env', env: parsedEnv.env },
398
+ };
399
+ }
400
+ case 'access': {
401
+ const overlay = normalizeOverlayForKey(value['overlay'], trusted);
402
+ if (overlay === undefined)
403
+ return undefined;
404
+ return {
405
+ key: { kind, overlay },
406
+ operation: { kind: 'access', overlay },
407
+ };
408
+ }
409
+ case 'append': {
410
+ const fieldId = value['fieldId'];
411
+ const origin = value['origin'];
412
+ const opValue = copyKeyValue(value['value'], trusted);
413
+ if (typeof fieldId !== 'string' || !isWriteOrigin(origin) || !opValue.ok) {
414
+ return undefined;
415
+ }
416
+ return {
417
+ key: { kind, fieldId, origin, value: opValue.value },
418
+ operation: { kind: 'append', fieldId, origin, value: opValue.value },
419
+ };
420
+ }
421
+ case 'insert': {
422
+ const fieldId = value['fieldId'];
423
+ const index = value['index'];
424
+ const origin = value['origin'];
425
+ const opValue = copyKeyValue(value['value'], trusted);
426
+ if (typeof fieldId !== 'string' ||
427
+ typeof index !== 'number' ||
428
+ !isSafeInteger(index) ||
429
+ !isWriteOrigin(origin) ||
430
+ !opValue.ok) {
431
+ return undefined;
432
+ }
433
+ return {
434
+ key: { kind, fieldId, index, origin, value: opValue.value },
435
+ operation: { kind: 'insert', fieldId, index, origin, value: opValue.value },
436
+ };
437
+ }
438
+ case 'removeRow': {
439
+ const fieldId = value['fieldId'];
440
+ const rowKey = value['rowKey'];
441
+ const origin = value['origin'];
442
+ if (typeof fieldId !== 'string' ||
443
+ (typeof rowKey !== 'string' && (typeof rowKey !== 'number' || !isSafeInteger(rowKey))) ||
444
+ !isWriteOrigin(origin)) {
445
+ return undefined;
446
+ }
447
+ return {
448
+ key: { kind, fieldId, rowKey, origin },
449
+ operation: { kind: 'removeRow', fieldId, rowKey, origin },
450
+ };
451
+ }
452
+ case 'move': {
453
+ const fieldId = value['fieldId'];
454
+ const rowKey = value['rowKey'];
455
+ const toIndex = value['toIndex'];
456
+ const origin = value['origin'];
457
+ if (typeof fieldId !== 'string' ||
458
+ (typeof rowKey !== 'string' && (typeof rowKey !== 'number' || !isSafeInteger(rowKey))) ||
459
+ typeof toIndex !== 'number' ||
460
+ !isSafeInteger(toIndex) ||
461
+ !isWriteOrigin(origin)) {
462
+ return undefined;
463
+ }
464
+ return {
465
+ key: { kind, fieldId, rowKey, toIndex, origin },
466
+ operation: { kind: 'move', fieldId, rowKey, toIndex, origin },
467
+ };
468
+ }
469
+ default:
470
+ return undefined;
471
+ }
472
+ };
473
+ /**
474
+ * Normalises an operation list and computes its canonical digest in a single pass so untrusted
475
+ * by-value commit candidates are never read twice and throwing getters refuse as `STALE_BASIS`.
476
+ */
477
+ const parseOperationsForKey = (operations, trusted) => {
478
+ try {
479
+ if (!Array.isArray(operations) || !hasPlainShape(operations, trusted))
480
+ return undefined;
481
+ const normalizedKeys = [];
482
+ const parsedOperations = [];
483
+ for (let index = 0; index < operations.length; index += 1) {
484
+ if (!trusted && !Object.hasOwn(operations, index))
485
+ return undefined;
486
+ const entry = normalizeOperationForKey(operations[index], trusted);
487
+ if (entry === undefined)
488
+ return undefined;
489
+ normalizedKeys.push(entry.key);
490
+ parsedOperations.push(entry.operation);
491
+ }
492
+ return {
493
+ key: canonicalHashOwned(normalizedKeys),
494
+ operations: parsedOperations,
495
+ };
496
+ }
497
+ catch {
498
+ return undefined;
499
+ }
500
+ };
501
+ /**
502
+ * Recent candidates derived on the current committed basis, bounded to `MAX_BASIS_CANDIDATES`
503
+ * entries in LRU order and cleared whenever the basis advances.
504
+ *
505
+ * A candidate carried by value (spread or cloned across a host boundary) misses the identity
506
+ * WeakMap above; indexing by canonical operation digest avoids O(n) form scans on every
507
+ * `preview()`/`propose()`, while matching inside the operation bucket installs the exact state
508
+ * displayed without invoking `idFactory` a second time. Unknown or evicted by-value candidates
509
+ * are refused with `STALE_BASIS` instead of falling through to re-derivation.
510
+ */
511
+ const basisCandidates = new Set();
512
+ const basisCandidatesByOp = new Map();
513
+ const evictedOpKeys = new Set();
514
+ const removeFromOpIndex = (record) => {
515
+ const bucket = basisCandidatesByOp.get(record.opKey);
516
+ if (bucket === undefined)
517
+ return;
518
+ const index = bucket.indexOf(record);
519
+ if (index !== -1)
520
+ bucket.splice(index, 1);
521
+ if (bucket.length === 0)
522
+ basisCandidatesByOp.delete(record.opKey);
523
+ };
524
+ const advanceBasis = () => {
525
+ basis += 1;
526
+ basisCandidates.clear();
527
+ basisCandidatesByOp.clear();
528
+ evictedOpKeys.clear();
529
+ };
530
+ const rememberDerived = (candidate, derived, candidateBasis) => {
531
+ derivedCandidates.set(candidate, { derived, operations: candidate.operations });
532
+ if (candidateBasis !== basis)
533
+ return;
534
+ const parsed = parseOperationsForKey(candidate.operations, true);
535
+ if (parsed === undefined)
536
+ return;
537
+ const opKey = parsed.key;
538
+ const manifest = manifestKey(derived.working.identity.manifests);
539
+ const existingBucket = basisCandidatesByOp.get(opKey);
540
+ if (existingBucket !== undefined) {
541
+ const existing = existingBucket.find((record) => record.manifestKey === manifest &&
542
+ (record.derived.form === derived.form || sameData(record.derived.form, derived.form)) &&
543
+ (record.derived.report === derived.report ||
544
+ sameData(record.derived.report, derived.report)));
545
+ if (existing !== undefined) {
546
+ // Refresh recency in LRU order only when the manifest, displayed form, and report match;
547
+ // a stateful lookup port can produce distinct results for the same operations.
548
+ basisCandidates.delete(existing);
549
+ basisCandidates.add(existing);
550
+ return;
551
+ }
552
+ }
553
+ if (basisCandidates.size >= MAX_BASIS_CANDIDATES) {
554
+ const oldest = basisCandidates.values().next();
555
+ if (!oldest.done) {
556
+ basisCandidates.delete(oldest.value);
557
+ removeFromOpIndex(oldest.value);
558
+ evictedOpKeys.add(oldest.value.opKey);
559
+ }
560
+ }
561
+ const record = {
562
+ opKey,
563
+ manifestKey: manifest,
564
+ operations: candidate.operations,
565
+ derived,
566
+ };
567
+ basisCandidates.add(record);
568
+ const bucket = basisCandidatesByOp.get(opKey);
569
+ if (bucket === undefined) {
570
+ basisCandidatesByOp.set(opKey, [record]);
571
+ }
572
+ else {
573
+ bucket.push(record);
574
+ }
575
+ };
576
+ const resolveDerived = (candidate) => {
577
+ const byIdentity = derivedCandidates.get(candidate);
578
+ if (byIdentity !== undefined)
579
+ return byIdentity;
580
+ if (basisCandidates.size === 0)
581
+ return undefined;
582
+ let rawOperations;
583
+ let candidateForm;
584
+ try {
585
+ rawOperations = candidate.operations;
586
+ candidateForm = candidate.form;
587
+ }
588
+ catch {
589
+ return undefined;
590
+ }
591
+ const parsed = parseOperationsForKey(rawOperations, false);
592
+ if (parsed === undefined)
593
+ return undefined;
594
+ const bucket = basisCandidatesByOp.get(parsed.key);
595
+ if (bucket === undefined)
596
+ return undefined;
597
+ const matches = bucket.filter((record) => {
598
+ try {
599
+ return (sameOperations(record.operations, parsed.operations) &&
600
+ (candidateForm === record.derived.form || sameData(candidateForm, record.derived.form)));
601
+ }
602
+ catch {
603
+ return false;
604
+ }
605
+ });
606
+ if (matches.length === 0)
607
+ return undefined;
608
+ const committedManifests = state.working.identity.manifests;
609
+ if (matches.length === 1) {
610
+ const only = matches[0];
611
+ if (only === undefined)
612
+ return undefined;
613
+ if (evictedOpKeys.has(parsed.key)) {
614
+ // An earlier candidate for this same operation was evicted from the bounded window on this
615
+ // basis. If minted row keys that changed from committed state are hidden from `form`, an
616
+ // evicted candidate and the retained one are indistinguishable by value, so refuse with
617
+ // `STALE_BASIS`; otherwise verify the sealed report matches before committing.
618
+ if (hasHiddenManifest(only.derived, committedManifests))
619
+ return undefined;
620
+ let candidateReport;
621
+ try {
622
+ candidateReport = candidate.report;
623
+ }
624
+ catch {
625
+ return undefined;
626
+ }
627
+ if (!isRecord(candidateReport))
628
+ return undefined;
629
+ try {
630
+ if (!sameData(candidateReport, sealReport(only.derived.report)))
631
+ return undefined;
632
+ }
633
+ catch {
634
+ return undefined;
635
+ }
636
+ }
637
+ return { derived: only.derived, operations: only.operations };
638
+ }
639
+ // Multiple retained candidates on this basis share the same operations and visible form
640
+ // (for example, hidden assigned-array rows with distinct manifests). Disambiguate using
641
+ // `candidate.report`; if multiple candidates still match or none match, refuse as
642
+ // `STALE_BASIS` rather than silently committing the wrong minted row key.
643
+ let candidateReport;
644
+ try {
645
+ candidateReport = candidate.report;
646
+ }
647
+ catch {
648
+ return undefined;
649
+ }
650
+ if (!isRecord(candidateReport))
651
+ return undefined;
652
+ const reportMatches = matches.filter((record) => {
653
+ try {
654
+ return sameData(candidateReport, sealReport(record.derived.report));
655
+ }
656
+ catch {
657
+ return false;
658
+ }
659
+ });
660
+ if (reportMatches.length !== 1)
661
+ return undefined;
662
+ const onlyMatch = reportMatches[0];
663
+ if (onlyMatch === undefined)
664
+ return undefined;
665
+ if (evictedOpKeys.has(parsed.key) && hasHiddenManifest(onlyMatch.derived, committedManifests)) {
666
+ return undefined;
667
+ }
668
+ return { derived: onlyMatch.derived, operations: onlyMatch.operations };
669
+ };
670
+ /** One immutable candidate over a derived state, frozen so a later edit cannot restate it. */
671
+ const candidateOf = (derived, operations, candidateBasis) => {
672
+ // The report is sealed on first read. A preview a host inspects only through `form` and a
673
+ // staged write a host confirms without reading the candidate report both avoid a
674
+ // canonicalisation and hash over the whole report body.
675
+ let report;
676
+ const candidate = {
677
+ outcome: 'candidate',
678
+ session: engine,
679
+ basis: candidateBasis,
680
+ get report() {
681
+ report ??= sealReport(derived.report);
682
+ return report;
683
+ },
684
+ form: derived.form,
685
+ // `operations` are the validated, owned snapshots staged during derivation, frozen here so
686
+ // a caller editing the original input cannot turn commit into a different operation.
687
+ operations: freezeOperations(operations),
688
+ };
689
+ return Object.freeze(candidate);
690
+ };
691
+ /** The evaluation inputs committed state reads, so a projection resolves the same record. */
692
+ const input = () => evaluationInputOf({
693
+ values: state.working.values,
694
+ context: state.working.context,
695
+ ...(state.working.redacted === undefined ? {} : { redacted: state.working.redacted }),
696
+ sessionWrites: [...state.working.sessionWrites.values()],
697
+ }, parsedAccessOf(state.working.overlay, state.working.access));
698
+ /** Every binding one state delivers, indexed once rather than scanned once per subscriber. */
699
+ const deliveredBindings = (from) => {
700
+ noteDeliveryIndexWalk();
701
+ const delivered = new Set();
702
+ for (const field of from.form.fields) {
703
+ const ref = { fieldId: field.fieldId };
704
+ if (from.access.field(ref).readable)
705
+ delivered.add(fieldKey(ref));
706
+ for (const row of field.rows ?? []) {
707
+ const rowRef = { fieldId: field.fieldId, rowKey: row.rowKey };
708
+ if (permitsReadOf(row.access, fieldKey(rowRef), from.access.sessionWriteKeys)) {
709
+ delivered.add(fieldKey(rowRef));
710
+ }
711
+ }
712
+ }
713
+ return delivered;
714
+ };
715
+ /**
716
+ * Evicts the subscriptions a narrowed access or structural removal no longer permits,
717
+ * `[ENGINE-5.1.2]`.
718
+ *
719
+ * A new overlay is one revocation of every binding it withholds, so each undelivered binding
720
+ * is released. Any other commit releases the bindings it stopped delivering (a row removed
721
+ * structurally, a natural key re-keyed, a hydrate that cleared an unlock) and nothing else. A
722
+ * plain value edit with unchanged access and no structural or row-identity change cannot revoke
723
+ * any delivered binding, so it skips the full-form delivery walk in O(1). A `write_only`
724
+ * binding that never delivered keeps its listener, because nothing about it changed.
725
+ */
726
+ const evictRevoked = (previous) => {
727
+ if (!subscriptions.hasBindings())
728
+ return;
729
+ const narrowed = state.working.overlay !== previous.working.overlay;
730
+ if (!narrowed && !state.mayRevokeBindings)
731
+ return;
732
+ // A form may hold thirty thousand row listeners. Index delivery once: resolving every
733
+ // listener through a field/row scan made its first write O(listeners x rows).
734
+ const after = deliveredBindings(state);
735
+ if (narrowed) {
736
+ subscriptions.evict((key) => !after.has(key));
737
+ return;
738
+ }
739
+ const before = deliveredBindings(previous);
740
+ subscriptions.evict((key) => before.has(key) && !after.has(key));
741
+ };
742
+ /** Forgets the cached snapshots whose binding no longer names a row of committed state. */
743
+ const pruneSnapshots = () => {
744
+ for (const key of [...snapshots.keys()]) {
745
+ if (!addresses(state.form, refOfBindingKey(key)))
746
+ snapshots.delete(key);
747
+ }
748
+ };
749
+ /** Notifies the changed bindings, then commits whatever the listeners wrote, `[ENGINE-2.1.8]`. */
750
+ const emit = (previous, patches) => {
751
+ const keys = [...new Set(state.trace.notified)];
752
+ // A binding whose facts survived the pass keeps the snapshot it already delivered; only a
753
+ // binding committed state no longer addresses is forgotten here, so a long session cannot
754
+ // accumulate an entry per row it once held.
755
+ pruneSnapshots();
756
+ // Eviction is not tied to an access or unlock change: a structural patch removes a binding
757
+ // just as surely, and a listener left on a removed row would fire for the next row that
758
+ // reuses its key.
759
+ evictRevoked(previous);
760
+ // A pass may assemble a body whose bytes are the committed one's — an environment change no
761
+ // rule reads re-evaluates everything and states the same facts. Notification follows the
762
+ // bytes, not the object identity.
763
+ const formChanged = keys.length > 0 || patches.length > 0 || !sameData(state.report, previous.report);
764
+ emitting = true;
765
+ try {
766
+ subscriptions.notify(keys, formChanged);
767
+ }
768
+ finally {
769
+ emitting = false;
770
+ }
771
+ };
772
+ /**
773
+ * Stages one atomic group and publishes it; a refusal drops the group as a whole.
774
+ *
775
+ * `firstIndex` is the group's first position in the batch the door was handed, which the drain
776
+ * needs once it has split one listener batch around an access barrier: the sub-batch begins
777
+ * partway through the original batch, so the refusal is `firstIndex + result.index`. Omitted,
778
+ * the group is the batch and the position speaks for itself.
779
+ */
780
+ const stage = (operations, dropped, firstIndex = 0) => {
781
+ const previous = state;
782
+ const result = deriveSession(compiled, graph, state, operations, ports);
783
+ if (result.outcome === 'refused') {
784
+ dropped.push({
785
+ ...result.refusal,
786
+ operationIndex: firstIndex + result.index,
787
+ queued: true,
788
+ });
789
+ return;
790
+ }
791
+ state = result.state;
792
+ advanceBasis();
793
+ emit(previous, result.patches);
794
+ };
795
+ /**
796
+ * Discards what an aborted emission queued.
797
+ *
798
+ * A listener failure that escapes the notification aborts the emission, so the writes its
799
+ * listeners had already queued belong to a batch that never committed. Keeping them would let
800
+ * the next unrelated host operation adopt them, attributing one emission's writes to another.
801
+ */
802
+ const abandonQueuedWrites = () => {
803
+ queue = [];
804
+ };
805
+ /**
806
+ * Installs the candidate a listener committed while a pass was emitting.
807
+ *
808
+ * The derived state is adopted when the basis it was derived on is still committed state, so
809
+ * the view the host was handed is the one that lands. An earlier piece of queued work that
810
+ * moved committed state makes that basis stale, and `[ENGINE-8.1.2]` refuses the candidate
811
+ * rather than installing state derived from a basis that no longer exists: staging its
812
+ * operations instead would commit row keys the candidate never displayed, which is worse than
813
+ * saying the candidate is stale. The refusal rides the drain's dropped list, as every queued
814
+ * write the session refuses does.
815
+ */
816
+ const commitQueued = (work, dropped) => {
817
+ if (work.basis !== basis) {
818
+ dropped.push({
819
+ outcome: 'refused',
820
+ code: 'STALE_BASIS',
821
+ basis: work.basis,
822
+ queued: true,
823
+ });
824
+ return;
825
+ }
826
+ adopt(state, work.derived, work.derived.trace.patches);
827
+ };
828
+ const workSize = (work) => Math.max(1, work.operations.length);
829
+ /**
830
+ * Commits the operations listeners issued while the pass was emitting, `[ENGINE-2.1.8]`.
831
+ *
832
+ * The writes one emission queued are one batch under `[ENGINE-2.1.3]`: they commit together
833
+ * and a refusal abandons the whole group, so a listener cannot publish half a logical turn.
834
+ * An access change is a barrier and commits on its own, because a write it revoked must be
835
+ * dropped with `ACCESS_DENIED` while the new overlay still takes effect. Writes a listener
836
+ * issues in response to the resulting emission belong to the next round.
837
+ */
838
+ const drain = () => {
839
+ const dropped = [];
840
+ let drainedOperations = 0;
841
+ try {
842
+ while (queue.length > 0) {
843
+ let groupOperations = 0;
844
+ for (const work of queue)
845
+ groupOperations += workSize(work);
846
+ if (drainedOperations + groupOperations > MAX_DRAIN_OPERATIONS)
847
+ break;
848
+ drainedOperations += groupOperations;
849
+ const basisBefore = basis;
850
+ const group = queue.splice(0);
851
+ let run = [];
852
+ // The first position of the run in the batch the door was handed, and the position the
853
+ // next operation will take. An access operation stages on its own, so the run after it
854
+ // starts at the access operation's position plus one rather than at zero.
855
+ let runFirst = 0;
856
+ let position = 0;
857
+ for (const work of group) {
858
+ if (work.kind === 'candidate') {
859
+ if (run.length > 0)
860
+ stage(run, dropped, runFirst);
861
+ run = [];
862
+ commitQueued(work, dropped);
863
+ continue;
864
+ }
865
+ for (const operation of work.operations) {
866
+ const at = position;
867
+ position += 1;
868
+ if (operation.kind !== 'access') {
869
+ if (run.length === 0)
870
+ runFirst = at;
871
+ run.push(operation);
872
+ continue;
873
+ }
874
+ if (run.length > 0)
875
+ stage(run, dropped, runFirst);
876
+ run = [];
877
+ stage([operation], dropped, at);
878
+ }
879
+ }
880
+ if (run.length > 0)
881
+ stage(run, dropped, runFirst);
882
+ // Stop if a drain round made no state progress, so queued work cannot spin without bound.
883
+ if (basis === basisBefore)
884
+ break;
885
+ }
886
+ if (queue.length > 0) {
887
+ // The drain bound exists so a listener that writes on every notification cannot livelock
888
+ // the host. Whatever is still queued is dropped with `DRAIN_BUDGET_EXCEEDED`, rather than
889
+ // vanishing or claiming an access denial. A dropped operation keeps its position in the
890
+ // batch its door was handed.
891
+ for (const work of queue.splice(0)) {
892
+ if (work.kind === 'candidate') {
893
+ const first = work.operations[0];
894
+ dropped.push({
895
+ outcome: 'refused',
896
+ code: 'DRAIN_BUDGET_EXCEEDED',
897
+ queued: true,
898
+ operationIndex: 0,
899
+ ...(first === undefined ? {} : operationRef(first)),
900
+ });
901
+ continue;
902
+ }
903
+ for (const [index, operation] of work.operations.entries()) {
904
+ dropped.push({
905
+ outcome: 'refused',
906
+ code: 'DRAIN_BUDGET_EXCEEDED',
907
+ queued: true,
908
+ operationIndex: index,
909
+ ...operationRef(operation),
910
+ });
911
+ }
912
+ }
913
+ }
914
+ }
915
+ catch (error) {
916
+ // A listener failure with no error channel escapes here; the batch that was draining did
917
+ // not finish, so nothing it still had queued may be adopted by a later call.
918
+ abandonQueuedWrites();
919
+ throw error;
920
+ }
921
+ if (dropped.length > 0) {
922
+ state = { ...state, trace: freezeTree({ ...state.trace, dropped }) };
923
+ }
924
+ };
925
+ /** Adopts one commit and publishes it; the caller drains the writes it caused. */
926
+ const adopt = (previous, next, patches) => {
927
+ state = next;
928
+ advanceBasis();
929
+ try {
930
+ emit(previous, patches);
931
+ }
932
+ catch (error) {
933
+ // Every entry point — including hydrate — abandons an aborted emission's queue. The commit
934
+ // itself stands, but writes its listeners staged must not leak into the next host operation.
935
+ abandonQueuedWrites();
936
+ throw error;
937
+ }
938
+ return { outcome: 'committed', patches };
939
+ };
940
+ /** Applies operations, or queues them when a listener is being notified. */
941
+ const apply = (operations) => {
942
+ if (emitting) {
943
+ queue.push({ kind: 'operations', operations });
944
+ return { outcome: 'queued' };
945
+ }
946
+ const previous = state;
947
+ const result = deriveSession(compiled, graph, state, operations, ports);
948
+ if (result.outcome === 'refused') {
949
+ return { ...result.refusal, operationIndex: result.index };
950
+ }
951
+ const outcome = adopt(previous, result.state, result.patches);
952
+ drain();
953
+ return outcome;
954
+ };
955
+ /** The row key at one committed position, refusing a position no row holds. */
956
+ const rowKeyAt = (fieldId, index, origin) => {
957
+ const declared = fieldIndex(state.form).get(fieldId);
958
+ if (declared === undefined || declared.primitive !== 'array') {
959
+ return {
960
+ outcome: 'refused',
961
+ code: 'ACCESS_DENIED',
962
+ origin,
963
+ fieldId,
964
+ operationIndex: 0,
965
+ };
966
+ }
967
+ // An otherwise writable user write may address only rows the derived view delivers. Other
968
+ // origins still reach the ordinary access/enabled guard with its established refusal order.
969
+ const keys = origin === 'user' && permitsUserWrite(declared.access) && declared.enabled
970
+ ? declared.addressableRows
971
+ : rowKeysOf(compiled, state.working.identity, state.working.values, fieldId);
972
+ if (keys === undefined) {
973
+ return {
974
+ outcome: 'refused',
975
+ code: 'IDENTITY_UNSUPPORTED',
976
+ fieldId,
977
+ operationIndex: 0,
978
+ };
979
+ }
980
+ const key = keys[index];
981
+ if (key === undefined) {
982
+ return {
983
+ outcome: 'refused',
984
+ code: 'ROW_INDEX_OUT_OF_RANGE',
985
+ fieldId,
986
+ index,
987
+ operationIndex: 0,
988
+ };
989
+ }
990
+ return key;
991
+ };
992
+ /**
993
+ * One binding's derived state, with the absent arm chosen by the caller.
994
+ *
995
+ * `getField` refuses a row the record does not address — that is a caller's mistake and the
996
+ * explanation door keeps the same rule. `getFieldOrAbsent` answers the absent binding instead,
997
+ * because a control can outlive its row and a read is not the place to refuse what the record
998
+ * did. Both share the cache and the identity rule, so the two doors cannot disagree about a
999
+ * binding that does exist.
1000
+ */
1001
+ const readField = (fieldId, rowKey, absent) => {
1002
+ const field = fieldOf(state, fieldId);
1003
+ const key = fieldKey(rowKey === undefined ? { fieldId } : { fieldId, rowKey });
1004
+ // A derived entry is reused across every pass its facts survive, so its identity is the
1005
+ // snapshot's validity: a container entry that did not move cannot state a different
1006
+ // snapshot, and rebuilding one would walk and freeze every row to answer the same fact.
1007
+ const cached = snapshots.get(key);
1008
+ if (cached !== undefined && cached.field === field)
1009
+ return cached.snapshot;
1010
+ let candidate = snapshotOf(field, rowKey);
1011
+ if (candidate === undefined) {
1012
+ if (rowKey === undefined || absent === 'throw') {
1013
+ throw new AxiomError('ENGINE_ERROR', `no row ${String(rowKey)} is addressed by ${fieldId}`, fieldId);
1014
+ }
1015
+ candidate = absentRowSnapshot(field, rowKey);
1016
+ }
1017
+ if (cached !== undefined && rowKey !== undefined && sameData(cached.snapshot, candidate)) {
1018
+ // Re-deriving a member states a new row entry per row, so a sibling's write replaces
1019
+ // this row's entry object even when this row's facts are untouched. The binding is the
1020
+ // same fact, so the snapshot a control already holds stays the delivered object; the
1021
+ // fresh entry is cached beside it so the compare happens once, not once per read.
1022
+ snapshots.set(key, { field, snapshot: cached.snapshot });
1023
+ return cached.snapshot;
1024
+ }
1025
+ snapshots.set(key, { field, snapshot: candidate });
1026
+ return candidate;
1027
+ };
1028
+ const engine = {
1029
+ getField(fieldId, rowKey) {
1030
+ return readField(fieldId, rowKey, 'throw');
1031
+ },
1032
+ getFieldOrAbsent(fieldId, rowKey) {
1033
+ return readField(fieldId, rowKey, 'state');
1034
+ },
1035
+ getFormState() {
1036
+ return state.form;
1037
+ },
1038
+ report() {
1039
+ return sealedReport();
1040
+ },
1041
+ lastPass() {
1042
+ return state.trace;
1043
+ },
1044
+ explainField(fieldId, rowKey) {
1045
+ const field = fieldOf(state, fieldId);
1046
+ if (rowKey !== undefined && snapshotOf(field, rowKey) === undefined) {
1047
+ // A row key that names no row of committed state is not another row's answer: the
1048
+ // explanation states one binding's provenance, and the field accessor refuses it too.
1049
+ throw new AxiomError('ENGINE_ERROR', `no row ${String(rowKey)} is addressed by ${fieldId}`, fieldId);
1050
+ }
1051
+ return explainFieldOf(graph, state.contributions, sealedReport(), field, rowKey);
1052
+ },
1053
+ inspectFieldDeps(fieldId) {
1054
+ declarationFor(compiled, fieldId);
1055
+ return inspectFieldDepsOf(compiled, graph, fieldId);
1056
+ },
1057
+ exportSubmission(options) {
1058
+ return projectSubmission(compiled, input(), {
1059
+ report: state.report,
1060
+ access: state.access.snapshotAccess(),
1061
+ assignedRowKeys: (fieldId) => state.working.identity.manifests.get(fieldId),
1062
+ }, options);
1063
+ },
1064
+ values() {
1065
+ // A copy, so a host that keeps the answer cannot mutate committed state through it.
1066
+ return copyRestricted(state.working.values);
1067
+ },
1068
+ rowManifest() {
1069
+ return Object.fromEntries([...state.working.identity.manifests].map(([fieldId, ids]) => [fieldId, [...ids]]));
1070
+ },
1071
+ sessionWrites() {
1072
+ return sessionWrites();
1073
+ },
1074
+ setValue(ref, value, origin) {
1075
+ return apply([{ kind: 'value', ref, value, origin }]);
1076
+ },
1077
+ setNull(ref, origin) {
1078
+ return apply([{ kind: 'null', ref, origin }]);
1079
+ },
1080
+ removeValue(ref, origin) {
1081
+ return apply([{ kind: 'remove', ref, origin }]);
1082
+ },
1083
+ setContext(root, value) {
1084
+ return apply([{ kind: 'context', root, value }]);
1085
+ },
1086
+ setEnv(env) {
1087
+ return apply([{ kind: 'env', env }]);
1088
+ },
1089
+ setAccess(overlay) {
1090
+ return apply([{ kind: 'access', overlay }]);
1091
+ },
1092
+ append(fieldId, value, origin) {
1093
+ return apply([{ kind: 'append', fieldId, value, origin }]);
1094
+ },
1095
+ insert(fieldId, index, value, origin) {
1096
+ return apply([{ kind: 'insert', fieldId, index, value, origin }]);
1097
+ },
1098
+ remove(fieldId, rowKey, origin) {
1099
+ return apply([{ kind: 'removeRow', fieldId, rowKey, origin }]);
1100
+ },
1101
+ move(fieldId, fromIndex, toIndex, origin) {
1102
+ const rowKey = rowKeyAt(fieldId, fromIndex, origin);
1103
+ if (typeof rowKey !== 'string' && typeof rowKey !== 'number')
1104
+ return rowKey;
1105
+ return apply([{ kind: 'move', fieldId, rowKey, toIndex, origin }]);
1106
+ },
1107
+ moveRow(fieldId, rowKey, toIndex, origin) {
1108
+ return apply([{ kind: 'move', fieldId, rowKey, toIndex, origin }]);
1109
+ },
1110
+ batch(operations) {
1111
+ return apply(operations);
1112
+ },
1113
+ hydrate(values, manifest) {
1114
+ if (emitting) {
1115
+ return { outcome: 'refused', code: 'EMISSION_IN_PROGRESS' };
1116
+ }
1117
+ const previous = state;
1118
+ const result = hydrateSession(compiled, graph, state, values, manifest, ports);
1119
+ if (result.outcome === 'refused')
1120
+ return result.refusal;
1121
+ const outcome = adopt(previous, result.state, result.patches);
1122
+ drain();
1123
+ return outcome;
1124
+ },
1125
+ subscribe(fieldId, rowKey, listener) {
1126
+ const ref = rowKey === undefined ? { fieldId } : { fieldId, rowKey };
1127
+ return subscriptions.subscribe(bindingKeyOf(ref), listener);
1128
+ },
1129
+ subscribeForm(listener) {
1130
+ return subscriptions.subscribeForm(listener);
1131
+ },
1132
+ subscriptionCount(fieldId, rowKey) {
1133
+ return subscriptions.count(fieldKey(rowKey === undefined ? { fieldId } : { fieldId, rowKey }));
1134
+ },
1135
+ preview(operations) {
1136
+ const candidateBasis = basis;
1137
+ const result = deriveSession(compiled, graph, state, operations, ports);
1138
+ if (result.outcome === 'refused') {
1139
+ return { ...result.refusal, operationIndex: result.index };
1140
+ }
1141
+ const candidate = candidateOf(result.state, result.operations, candidateBasis);
1142
+ rememberDerived(candidate, result.state, candidateBasis);
1143
+ return candidate;
1144
+ },
1145
+ propose(operations) {
1146
+ // Evaluation ports are host code and can commit reentrantly. Keep the state and basis this
1147
+ // derivation actually read so such a commit makes the candidate stale instead of letting it
1148
+ // adopt its old view over the intervening write. The base *body* is captured rather than
1149
+ // its digest: a host that never reads the delta never pays to seal a report it never asked
1150
+ // for, and a reentrant commit is answered by comparing the body at read time.
1151
+ //
1152
+ // The base, its report body and this closure's candidate state are cleared once the delta
1153
+ // is built. Until then the closure below holds the pre-write state; afterwards the memoised
1154
+ // `delta` is all the getter needs. The session's own candidate record still holds the
1155
+ // derived state for `commit`, exactly as it does for a candidate a host never inspects, and
1156
+ // the store holds the same committed base while the proposal is pending. A build that
1157
+ // throws leaves the references set, so a retry rebuilds from the same basis.
1158
+ let base = state;
1159
+ let baseBody = base.report;
1160
+ const candidateBasis = basis;
1161
+ const result = deriveSession(compiled, graph, base, operations, ports);
1162
+ if (result.outcome === 'refused') {
1163
+ return { ...result.refusal, operationIndex: result.index };
1164
+ }
1165
+ let derivedState = result.state;
1166
+ // The delta reads only the structural writes from this result, so hold that list rather
1167
+ // than the whole result: the closure below otherwise keeps the candidate's full session
1168
+ // state alive through `result.state` even after it has cleared its own reference.
1169
+ const structuralWrites = result.structuralWrites;
1170
+ const candidate = candidateOf(result.state, result.operations, candidateBasis);
1171
+ rememberDerived(candidate, result.state, candidateBasis);
1172
+ // The staging decision reads only which blockers the change set adds, and the whole delta
1173
+ // reads the same two identified lists. Both are built here once: the eager answer is the
1174
+ // pair's frozen `added` array, and the delta reuses it rather than canonicalising again.
1175
+ const blockers = identifyBlockers(base, result.state);
1176
+ const addedBlockers = blockers.added;
1177
+ let delta;
1178
+ const deltaOf = () => {
1179
+ if (delta !== undefined)
1180
+ return delta;
1181
+ const heldBase = base;
1182
+ const heldBody = baseBody;
1183
+ const heldCandidate = derivedState;
1184
+ if (heldBase === undefined || heldBody === undefined || heldCandidate === undefined) {
1185
+ throw new AxiomError('ENGINE_ERROR', 'the proposal delta was built after its basis was released');
1186
+ }
1187
+ const baseReportHash = (heldBody === state.report ? sealedReport() : sealReport(heldBody))
1188
+ .reportHash;
1189
+ const built = freezeTree(candidateDelta(compiled, heldBase, heldCandidate, {
1190
+ operations: candidate.operations,
1191
+ structuralWrites,
1192
+ baseReportHash,
1193
+ candidateReportHash: candidate.report.reportHash,
1194
+ blockers,
1195
+ }));
1196
+ base = undefined;
1197
+ baseBody = undefined;
1198
+ derivedState = undefined;
1199
+ delta = built;
1200
+ return built;
1201
+ };
1202
+ const proposed = {
1203
+ outcome: 'proposed',
1204
+ candidate,
1205
+ addedBlockers,
1206
+ get delta() {
1207
+ return deltaOf();
1208
+ },
1209
+ };
1210
+ return Object.freeze(proposed);
1211
+ },
1212
+ commit(candidate) {
1213
+ if (candidate.session !== engine || candidate.basis !== basis) {
1214
+ return { outcome: 'refused', code: 'STALE_BASIS', basis: candidate.basis };
1215
+ }
1216
+ const resolved = resolveDerived(candidate);
1217
+ // Unknown candidates are refused rather than re-derived, so committing a candidate never
1218
+ // falls through to minting different assigned row keys than those displayed (`[ENGINE-8.2.3]`).
1219
+ if (resolved === undefined) {
1220
+ return { outcome: 'refused', code: 'STALE_BASIS', basis: candidate.basis };
1221
+ }
1222
+ if (emitting) {
1223
+ // A candidate committed from a listener is work the drain performs once the emission
1224
+ // finishes, exactly as a listener's write is. Its derived state travels with it so the
1225
+ // view the host was handed is the one installed.
1226
+ queue.push({
1227
+ kind: 'candidate',
1228
+ derived: resolved.derived,
1229
+ basis: candidate.basis,
1230
+ operations: resolved.operations,
1231
+ });
1232
+ return { outcome: 'queued' };
1233
+ }
1234
+ derivedCandidates.delete(candidate);
1235
+ const outcome = adopt(state, resolved.derived, resolved.derived.trace.patches);
1236
+ drain();
1237
+ return outcome;
1238
+ },
1239
+ };
1240
+ return engine;
1241
+ }
1242
+ //# sourceMappingURL=index.js.map