@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,387 @@
1
+ import { AxiomError, assertNever } from '../model/errors.js';
2
+ import { childNodes } from '../model/expr-children.js';
3
+ import { isRecord } from '../model/values.js';
4
+ import { noteArtifactStaticDerivation } from './state/measurement.js';
5
+ /**
6
+ * The cost budget one evaluation pass may spend.
7
+ *
8
+ * A single counter for a whole pass made scale a correctness defect: twelve item rules over
9
+ * thirty thousand rows spent one rule's allowance before the last rules ran, so the later
10
+ * rows were reported `UNKNOWN` on an artifact that is entirely legal. The budget therefore
11
+ * scales with the work the artifact declares — the nodes one rule may visit grow with the
12
+ * rows it addresses — while an absolute pass ceiling keeps a hostile artifact bounded. The
13
+ * cap and the ceiling are budgets, not semantics: crossing one still refuses the evaluation
14
+ * rather than truncating it.
15
+ *
16
+ * A source cap alone does not bound a nesting either: 900 rows of 900 marks is a legal
17
+ * 900-element source evaluated 900 times, 810,000 materialised elements. The ledger therefore
18
+ * charges every element a *nested* comprehension materialises, cumulatively, against the source
19
+ * ceiling `EXPR-17.1.1` states. A nesting whose product stays at or below that ceiling is
20
+ * admitted — 810,000 is inside it — and one above it is refused. The outermost comprehension is
21
+ * charged nothing: it reads the declared source once, which is the work the rule's rows already
22
+ * bought, so charging it would refuse two aggregates over one admissible array. The charge
23
+ * resets with the node allowance at each rule boundary (`beginRule`) and is restored when a
24
+ * nested rule returns, exactly as that allowance is; a pass-wide counter would refuse twelve
25
+ * legal rules that each nest inside the ceiling, the same defect the node allowance fixed.
26
+ * One rule's nesting never spends another's, and the ledger is created by the evaluator, so no
27
+ * counter outlives one pass.
28
+ */
29
+ /** Nodes one rule may visit before its rows are addressed. */
30
+ const BASE_RULE_NODES = 1_000_000;
31
+ /**
32
+ * The nodes one additional declared row buys a rule.
33
+ *
34
+ * A row predicate is a compiled expression bounded by the compiler's token and depth
35
+ * budgets, so its visit count is a small multiple of its node count. 128 leaves room for a
36
+ * predicate several times the size of the one the scale test calls extreme (a 40-conjunct
37
+ * `and`, 121 visits) without letting a hostile artifact spend an unbounded number of visits
38
+ * per row.
39
+ */
40
+ const NODE_ALLOWANCE_PER_ROW = 128;
41
+ /**
42
+ * The most nodes one pass may visit, however many rules and rows the artifact declares.
43
+ *
44
+ * This is the hostile-artifact backstop, not a limit a declared form should reach: a
45
+ * twelve-rule, thirty-thousand-row form with a 121-visit predicate spends about 44 million
46
+ * visits, which is a third of this ceiling.
47
+ */
48
+ const MAX_PASS_NODES = 128_000_000;
49
+ /**
50
+ * The most report decisions one pass may produce.
51
+ *
52
+ * A decision is one `rules[]` entry: a whole-record rule answers once, and an item rule answers
53
+ * once per row, so `rules × rows` is the count. The report carries roughly 301 bytes per
54
+ * decision (the measured canonical text of a 100,000-row audit at two item rules is 60.2 MB for
55
+ * 200,000 decisions, a measurement that moves with the rule kind and the record's fields), so a
56
+ * million decisions is about a third of a gigabyte of report — enough for a large artifact to
57
+ * exhaust a device's memory before any node budget notices.
58
+ *
59
+ * 500,000 is chosen from that measurement: two and a half times the measured 100,000-row,
60
+ * two-rule audit (200,000 decisions, 60.2 MB) so the realistic case passes with room for
61
+ * another item rule or two, and about 150 MB of report at the measured bytes per decision —
62
+ * comfortably below the memory a hostile million-row shape would demand. The ceiling is a
63
+ * budget, not truncation: crossing it refuses the evaluation rather than returning a partial
64
+ * report.
65
+ */
66
+ const MAX_DECISIONS = 500_000;
67
+ /** The smallest comprehension source a rule may iterate, the historical published cap. */
68
+ const MIN_COMPREHENSION_ELEMENTS = 10_000;
69
+ /**
70
+ * The read-cap for a single comprehension, before any element is bound.
71
+ *
72
+ * At thirty thousand declared rows the historical ten-thousand cap refused a legal
73
+ * aggregate and surfaced it as an engine error. The cap now follows the declared rows —
74
+ * a comprehension may iterate the record the artifact declares — with the historical floor
75
+ * for a source no declaration backs (a list literal). The ceiling stops a hostile literal
76
+ * from materialising an unbounded binding list; the node budget still bounds the work.
77
+ */
78
+ const MAX_COMPREHENSION_ELEMENTS = 1_000_000;
79
+ /** The largest declared row count one budget will scale for. */
80
+ function declaredRowsWithinCeiling(rows) {
81
+ return Math.min(MAX_COMPREHENSION_ELEMENTS, rows);
82
+ }
83
+ /** The raw value at a dotted path of the submitted record, without reading it as a field. */
84
+ function rawAt(values, path) {
85
+ let current = values;
86
+ for (const segment of path.split('.')) {
87
+ if (!isRecord(current) || !Object.hasOwn(current, segment))
88
+ return undefined;
89
+ current = current[segment];
90
+ }
91
+ return current;
92
+ }
93
+ /**
94
+ * The rows the record declares: the summed length of every declared array.
95
+ *
96
+ * This is what the budget scales with. It is read from the raw submission rather than through
97
+ * the record reader, so measuring the budget does not validate, copy or mark considered the
98
+ * values the evaluation is about to read.
99
+ */
100
+ export function declaredRowCount(fields, values) {
101
+ let rows = 0;
102
+ const visit = (members, prefix) => {
103
+ for (const field of members) {
104
+ const path = prefix === '' ? field.fieldId : `${prefix}.${field.fieldId}`;
105
+ if (field.primitive === 'array') {
106
+ const raw = rawAt(values, path);
107
+ if (Array.isArray(raw))
108
+ rows += raw.length;
109
+ // An item's own arrays are per row; the row count is the container's length, and a
110
+ // nested array is bounded by the node budget when it is actually iterated.
111
+ continue;
112
+ }
113
+ visit(field.fields ?? [], path);
114
+ }
115
+ };
116
+ visit(fields ?? [], '');
117
+ return rows;
118
+ }
119
+ /** The rows a declared context array contributes, read from the raw context values. */
120
+ export function contextRowCount(roots, context) {
121
+ let rows = 0;
122
+ for (const root of roots ?? []) {
123
+ if (root.primitive !== 'array')
124
+ continue;
125
+ const raw = context?.[root.path.replace(/^context\./, '')];
126
+ if (Array.isArray(raw))
127
+ rows += raw.length;
128
+ }
129
+ return rows;
130
+ }
131
+ /**
132
+ * The budget an artifact's declared shape earns: one rule's allowance scales with the rows
133
+ * it addresses, and the pass ceiling is the sum of those allowances, bounded.
134
+ */
135
+ export function evaluationBudget(rows, ruleCount) {
136
+ const declared = declaredRowsWithinCeiling(rows);
137
+ const perRule = Math.max(BASE_RULE_NODES, declared * NODE_ALLOWANCE_PER_ROW);
138
+ const total = Math.min(MAX_PASS_NODES, Math.max(perRule, Math.max(1, ruleCount) * perRule));
139
+ return {
140
+ perRule,
141
+ total,
142
+ elements: Math.max(MIN_COMPREHENSION_ELEMENTS, declared),
143
+ // The ceiling, not the per-source allowance: `elements` can be the 10,000 literal floor on
144
+ // a small record, and a legal 900×900 nesting is 810,000 elements. `EXPR-17.1.1` admits a
145
+ // source up to the ceiling, so a nesting is charged against that same ceiling.
146
+ nestedElements: MAX_COMPREHENSION_ELEMENTS,
147
+ decisions: MAX_DECISIONS,
148
+ };
149
+ }
150
+ /** The budget a caller that declares no work runs under: one standalone expression. */
151
+ export const STANDALONE_BUDGET = evaluationBudget(0, 1);
152
+ /** The rule-like allowance units one expression earns, weighted by its actual AST size. */
153
+ function expressionCostUnits(node) {
154
+ let nodes = 0;
155
+ const pending = [node];
156
+ while (pending.length > 0) {
157
+ const current = pending.pop();
158
+ if (current === undefined)
159
+ break;
160
+ nodes += 1;
161
+ for (const child of childNodes(current))
162
+ pending.push(child);
163
+ }
164
+ return Math.max(1, Math.ceil(nodes / NODE_ALLOWANCE_PER_ROW));
165
+ }
166
+ /** The allowance units one declared alternative's expressions earn. */
167
+ function alternativeCostUnits(suggestions) {
168
+ let count = 0;
169
+ for (const suggestion of suggestions ?? []) {
170
+ for (const operation of suggestion.operations) {
171
+ switch (operation.kind) {
172
+ case 'value':
173
+ count += expressionCostUnits(operation.value);
174
+ break;
175
+ case 'append':
176
+ for (const node of Object.values(operation.row))
177
+ count += expressionCostUnits(node);
178
+ break;
179
+ case 'null':
180
+ case 'remove':
181
+ case 'removeRow':
182
+ break;
183
+ default:
184
+ assertNever(operation);
185
+ }
186
+ }
187
+ }
188
+ return count;
189
+ }
190
+ /** The option conditions an artifact declares, each one rule-like work in the pass total. */
191
+ function declaredOptionConditionCount(fields) {
192
+ let count = 0;
193
+ for (const field of fields) {
194
+ for (const option of field.options ?? []) {
195
+ if (option.availableWhen !== undefined)
196
+ count += 1;
197
+ }
198
+ count += declaredOptionConditionCount(field.fields ?? []);
199
+ }
200
+ return count;
201
+ }
202
+ /** The allowance units an artifact's alternative expressions earn, options included. */
203
+ function declaredAlternativeCostUnits(compiled) {
204
+ let count = 0;
205
+ for (const rule of compiled.rules ?? [])
206
+ count += alternativeCostUnits(rule.suggests);
207
+ const visit = (fields) => {
208
+ for (const field of fields) {
209
+ for (const option of field.options ?? []) {
210
+ count += alternativeCostUnits(option.suggests);
211
+ }
212
+ visit(field.fields ?? []);
213
+ }
214
+ };
215
+ visit(compiled.fields);
216
+ return count;
217
+ }
218
+ /** The budget a compiled artifact earns against one record. */
219
+ export function budgetForSchema(compiled, input) {
220
+ return evaluationBudget(declaredRowCount(compiled.fields, input.values) +
221
+ contextRowCount(compiled.context?.roots, input.context), declaredRuleWeight(compiled));
222
+ }
223
+ /**
224
+ * The rule-like allowance units one artifact declares.
225
+ *
226
+ * Counting the options and walking every alternative's expression tree is a fact about the
227
+ * artifact alone, so it is computed once per compiled artifact and reused by every pass, every
228
+ * evaluation isolate and every session over it. Only the row count scales with the record.
229
+ */
230
+ const RULE_WEIGHTS = new WeakMap();
231
+ function declaredRuleWeight(compiled) {
232
+ const cached = RULE_WEIGHTS.get(compiled);
233
+ if (cached !== undefined)
234
+ return cached;
235
+ noteArtifactStaticDerivation();
236
+ const weight = (compiled.rules?.length ?? 0) +
237
+ declaredOptionConditionCount(compiled.fields) +
238
+ declaredAlternativeCostUnits(compiled);
239
+ RULE_WEIGHTS.set(compiled, weight);
240
+ return weight;
241
+ }
242
+ /**
243
+ * A refusal that crossed a declared budget.
244
+ *
245
+ * It extends the runtime's own refusal so the evaluator's single error path still carries it,
246
+ * and it keeps the limit and the dimension, which the report states as parameters. Mapping a
247
+ * cost overrun to a bare `ENGINE_ERROR` hid which budget was crossed and by how much.
248
+ */
249
+ export class BudgetExceededError extends AxiomError {
250
+ limit;
251
+ dimension;
252
+ /**
253
+ * The operation that crossed the budget, when the caller can name one.
254
+ *
255
+ * A decision refusal is produced by an item rule or by the report fold, and naming which
256
+ * lets an operator size the right thing — one rule's row count rather than the whole pass —
257
+ * without reading the evaluator.
258
+ */
259
+ operation;
260
+ constructor(dimension, limit, detail, operation) {
261
+ super('COST_BUDGET_EXCEEDED', `${detail} (limit ${String(limit)})`);
262
+ this.name = 'BudgetExceededError';
263
+ this.limit = limit;
264
+ this.dimension = dimension;
265
+ this.operation = operation;
266
+ }
267
+ }
268
+ /**
269
+ * The work one pass has spent, and the allowance of the rule currently running.
270
+ *
271
+ * A nested rule — `rule_ok` evaluating another rule mid-expression — begins its own
272
+ * allowances and restores the interrupted ones, so one rule's spend never shortens another's.
273
+ * The element charge and the comprehension depth are part of that same boundary: a nested rule
274
+ * starts at depth zero, so a comprehension it evaluates is charged to the nested rule and not to
275
+ * the rule whose body asked about it.
276
+ */
277
+ export class NodeLedger {
278
+ budget;
279
+ ruleVisited = 0;
280
+ passVisited = 0;
281
+ chargedElements = 0;
282
+ comprehensionDepth = 0;
283
+ producedDecisions = 0;
284
+ constructor(budget) {
285
+ this.budget = budget;
286
+ }
287
+ /** Starts one rule's allowances, returning the interrupted counters to restore later. */
288
+ beginRule() {
289
+ const previous = {
290
+ visited: this.ruleVisited,
291
+ charged: this.chargedElements,
292
+ depth: this.comprehensionDepth,
293
+ };
294
+ this.ruleVisited = 0;
295
+ this.chargedElements = 0;
296
+ this.comprehensionDepth = 0;
297
+ return previous;
298
+ }
299
+ /** Restores the allowances of the rule that asked about this one. */
300
+ endRule(previous) {
301
+ this.ruleVisited = previous.visited;
302
+ this.chargedElements = previous.charged;
303
+ this.comprehensionDepth = previous.depth;
304
+ }
305
+ /** Counts one visited node against both allowances. */
306
+ spend() {
307
+ this.ruleVisited += 1;
308
+ this.passVisited += 1;
309
+ if (this.ruleVisited > this.budget.perRule) {
310
+ throw new BudgetExceededError('rule_nodes', this.budget.perRule, 'one rule visited more nodes than its rows allow');
311
+ }
312
+ if (this.passVisited > this.budget.total) {
313
+ throw new BudgetExceededError('pass_nodes', this.budget.total, 'the evaluation visited more nodes than this pass allows');
314
+ }
315
+ }
316
+ /** Enters one comprehension, returning the depth it interrupted. */
317
+ beginComprehension() {
318
+ const previous = this.comprehensionDepth;
319
+ this.comprehensionDepth = previous + 1;
320
+ return previous;
321
+ }
322
+ /** Leaves one comprehension, restoring the depth it interrupted. */
323
+ endComprehension(previous) {
324
+ this.comprehensionDepth = previous;
325
+ }
326
+ /**
327
+ * Refuses a comprehension source before the first element is bound.
328
+ *
329
+ * This is the per-source cap: one source no listing may exceed, and a list literal is held
330
+ * to the historical 10,000 floor through `elements`.
331
+ */
332
+ refuseElements(count) {
333
+ if (count <= this.budget.elements)
334
+ return;
335
+ throw new BudgetExceededError('comprehension_elements', this.budget.elements, 'a comprehension source carries more elements than this pass allows');
336
+ }
337
+ /**
338
+ * Counts the elements one nested comprehension materialised, against the rule's cumulative
339
+ * charge.
340
+ *
341
+ * The caller charges only a comprehension that is itself inside another: the outermost one
342
+ * reads the declared source once, which is the work the rule's rows already bought, so two
343
+ * aggregates over one admissible array are not refused. The cumulative ceiling is the source
344
+ * ceiling `EXPR-17.1.1` states, not the per-source allowance, so the 900×900 shape is
345
+ * admitted and a nesting that multiplies past 1,000,000 elements is refused.
346
+ */
347
+ chargeElements(count) {
348
+ this.chargedElements += count;
349
+ if (this.chargedElements <= this.budget.nestedElements)
350
+ return;
351
+ throw new BudgetExceededError('comprehension_elements', this.budget.nestedElements, 'nested comprehensions materialised more elements than this rule allows');
352
+ }
353
+ /**
354
+ * Refuses a block of report entries before any of them is allocated.
355
+ *
356
+ * An item rule knows its row count before it evaluates the first row, so checking here keeps
357
+ * an over-ceiling shape from allocating a result per row only to throw on the last one. The
358
+ * check does not commit the count; `spendDecisions` records the entries actually produced.
359
+ */
360
+ ensureDecisionRoom(count, operation) {
361
+ if (this.producedDecisions + count <= this.budget.decisions)
362
+ return;
363
+ throw new BudgetExceededError('decisions', this.budget.decisions, `the ${operation} would produce more report decisions than this evaluation allows`, operation);
364
+ }
365
+ /** Counts the report entries one rule produced against the pass-wide decision ceiling. */
366
+ spendDecisions(count, operation) {
367
+ this.producedDecisions += count;
368
+ if (this.producedDecisions <= this.budget.decisions)
369
+ return;
370
+ throw new BudgetExceededError('decisions', this.budget.decisions, `the ${operation} produced more report decisions than this evaluation allows`, operation);
371
+ }
372
+ }
373
+ /**
374
+ * The parameters a report states for a budget refusal, or `undefined` when the error is not
375
+ * one. The report names the limit and the dimension so a reader can size the record or split
376
+ * the expression without reading the evaluator.
377
+ */
378
+ export function budgetRefusalParams(error) {
379
+ if (!(error instanceof BudgetExceededError))
380
+ return undefined;
381
+ return {
382
+ limit: error.limit,
383
+ dimension: error.dimension,
384
+ ...(error.operation === undefined ? {} : { operation: error.operation }),
385
+ };
386
+ }
387
+ //# sourceMappingURL=budget.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"budget.js","sourceRoot":"","sources":["../../src/eval/budget.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAC7D,OAAO,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AAUvD,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9C,OAAO,EAAE,4BAA4B,EAAE,MAAM,wBAAwB,CAAC;AAEtE;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,8DAA8D;AAC9D,MAAM,eAAe,GAAG,SAAS,CAAC;AAElC;;;;;;;;GAQG;AACH,MAAM,sBAAsB,GAAG,GAAG,CAAC;AAEnC;;;;;;GAMG;AACH,MAAM,cAAc,GAAG,WAAW,CAAC;AAEnC;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,aAAa,GAAG,OAAO,CAAC;AAE9B,0FAA0F;AAC1F,MAAM,0BAA0B,GAAG,MAAM,CAAC;AAE1C;;;;;;;;GAQG;AACH,MAAM,0BAA0B,GAAG,SAAS,CAAC;AA6B7C,gEAAgE;AAChE,SAAS,yBAAyB,CAAC,IAAY;IAC7C,OAAO,IAAI,CAAC,GAAG,CAAC,0BAA0B,EAAE,IAAI,CAAC,CAAC;AACpD,CAAC;AAED,6FAA6F;AAC7F,SAAS,KAAK,CAAC,MAAyC,EAAE,IAAY;IACpE,IAAI,OAAO,GAAY,MAAM,CAAC;IAC9B,KAAK,MAAM,OAAO,IAAI,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC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iB;IAEjB,IAAI,CAAC,CAAC,KAAK,YAAY,mBAAmB,CAAC;QAAE,OAAO,SAAS,CAAC;IAC9D,OAAO;QACL,KAAK,EAAE,KAAK,CAAC,KAAK;QAClB,SAAS,EAAE,KAAK,CAAC,SAAS;QAC1B,GAAG,CAAC,KAAK,CAAC,SAAS,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,KAAK,CAAC,SAAS,EAAE,CAAC;KACzE,CAAC;AACJ,CAAC","sourcesContent":["import { AxiomError, assertNever } from '../model/errors.js';\nimport { childNodes } from '../model/expr-children.js';\nimport type {\n CompiledField,\n CompiledSuggestion,\n ContextRoot,\n ExprNode,\n WireValue,\n} from '../model/types.js';\nimport type { EvaluationInput } from '../model/access.js';\nimport type { CompiledSchema } from '../model/schema.js';\nimport { isRecord } from '../model/values.js';\nimport { noteArtifactStaticDerivation } from './state/measurement.js';\n\n/**\n * The cost budget one evaluation pass may spend.\n *\n * A single counter for a whole pass made scale a correctness defect: twelve item rules over\n * thirty thousand rows spent one rule's allowance before the last rules ran, so the later\n * rows were reported `UNKNOWN` on an artifact that is entirely legal. The budget therefore\n * scales with the work the artifact declares — the nodes one rule may visit grow with the\n * rows it addresses — while an absolute pass ceiling keeps a hostile artifact bounded. The\n * cap and the ceiling are budgets, not semantics: crossing one still refuses the evaluation\n * rather than truncating it.\n *\n * A source cap alone does not bound a nesting either: 900 rows of 900 marks is a legal\n * 900-element source evaluated 900 times, 810,000 materialised elements. The ledger therefore\n * charges every element a *nested* comprehension materialises, cumulatively, against the source\n * ceiling `EXPR-17.1.1` states. A nesting whose product stays at or below that ceiling is\n * admitted — 810,000 is inside it — and one above it is refused. The outermost comprehension is\n * charged nothing: it reads the declared source once, which is the work the rule's rows already\n * bought, so charging it would refuse two aggregates over one admissible array. The charge\n * resets with the node allowance at each rule boundary (`beginRule`) and is restored when a\n * nested rule returns, exactly as that allowance is; a pass-wide counter would refuse twelve\n * legal rules that each nest inside the ceiling, the same defect the node allowance fixed.\n * One rule's nesting never spends another's, and the ledger is created by the evaluator, so no\n * counter outlives one pass.\n */\n\n/** Nodes one rule may visit before its rows are addressed. */\nconst BASE_RULE_NODES = 1_000_000;\n\n/**\n * The nodes one additional declared row buys a rule.\n *\n * A row predicate is a compiled expression bounded by the compiler's token and depth\n * budgets, so its visit count is a small multiple of its node count. 128 leaves room for a\n * predicate several times the size of the one the scale test calls extreme (a 40-conjunct\n * `and`, 121 visits) without letting a hostile artifact spend an unbounded number of visits\n * per row.\n */\nconst NODE_ALLOWANCE_PER_ROW = 128;\n\n/**\n * The most nodes one pass may visit, however many rules and rows the artifact declares.\n *\n * This is the hostile-artifact backstop, not a limit a declared form should reach: a\n * twelve-rule, thirty-thousand-row form with a 121-visit predicate spends about 44 million\n * visits, which is a third of this ceiling.\n */\nconst MAX_PASS_NODES = 128_000_000;\n\n/**\n * The most report decisions one pass may produce.\n *\n * A decision is one `rules[]` entry: a whole-record rule answers once, and an item rule answers\n * once per row, so `rules × rows` is the count. The report carries roughly 301 bytes per\n * decision (the measured canonical text of a 100,000-row audit at two item rules is 60.2 MB for\n * 200,000 decisions, a measurement that moves with the rule kind and the record's fields), so a\n * million decisions is about a third of a gigabyte of report — enough for a large artifact to\n * exhaust a device's memory before any node budget notices.\n *\n * 500,000 is chosen from that measurement: two and a half times the measured 100,000-row,\n * two-rule audit (200,000 decisions, 60.2 MB) so the realistic case passes with room for\n * another item rule or two, and about 150 MB of report at the measured bytes per decision —\n * comfortably below the memory a hostile million-row shape would demand. The ceiling is a\n * budget, not truncation: crossing it refuses the evaluation rather than returning a partial\n * report.\n */\nconst MAX_DECISIONS = 500_000;\n\n/** The smallest comprehension source a rule may iterate, the historical published cap. */\nconst MIN_COMPREHENSION_ELEMENTS = 10_000;\n\n/**\n * The read-cap for a single comprehension, before any element is bound.\n *\n * At thirty thousand declared rows the historical ten-thousand cap refused a legal\n * aggregate and surfaced it as an engine error. The cap now follows the declared rows —\n * a comprehension may iterate the record the artifact declares — with the historical floor\n * for a source no declaration backs (a list literal). The ceiling stops a hostile literal\n * from materialising an unbounded binding list; the node budget still bounds the work.\n */\nconst MAX_COMPREHENSION_ELEMENTS = 1_000_000;\n\n/** The budget one pass runs under. */\nexport interface EvaluationBudget {\n /** Nodes one rule may visit. */\n readonly perRule: number;\n /** Nodes the whole pass may visit. */\n readonly total: number;\n /** Elements one comprehension source may carry before its first binding. */\n readonly elements: number;\n /**\n * Elements one rule may materialise across every nested comprehension it evaluates.\n *\n * This is the ceiling `EXPR-17.1.1` states, not the per-source allowance in `elements`: one\n * source at the ceiling is legal, and the cumulative charge exists to stop a nesting from\n * multiplying past it. 900 rows of 900 marks is 810,000 and admitted; 1,200 rows of 1,200\n * marks is 1,440,000 and refused.\n */\n readonly nestedElements: number;\n /**\n * Report entries one pass may produce, `rules × rows`.\n *\n * This is its own dimension because the report is the allocation nobody watches: the node\n * budget bounds the work an expression does, and this bounds the evidence the report retains\n * after every rule has run.\n */\n readonly decisions: number;\n}\n\n/** The largest declared row count one budget will scale for. */\nfunction declaredRowsWithinCeiling(rows: number): number {\n return Math.min(MAX_COMPREHENSION_ELEMENTS, rows);\n}\n\n/** The raw value at a dotted path of the submitted record, without reading it as a field. */\nfunction rawAt(values: Readonly<Record<string, unknown>>, path: string): unknown {\n let current: unknown = values;\n for (const segment of path.split('.')) {\n if (!isRecord(current) || !Object.hasOwn(current, segment)) return undefined;\n current = current[segment];\n }\n return current;\n}\n\n/**\n * The rows the record declares: the summed length of every declared array.\n *\n * This is what the budget scales with. It is read from the raw submission rather than through\n * the record reader, so measuring the budget does not validate, copy or mark considered the\n * values the evaluation is about to read.\n */\nexport function declaredRowCount(\n fields: readonly CompiledField[] | undefined,\n values: Readonly<Record<string, unknown>>,\n): number {\n let rows = 0;\n const visit = (members: readonly CompiledField[], prefix: string): void => {\n for (const field of members) {\n const path = prefix === '' ? field.fieldId : `${prefix}.${field.fieldId}`;\n if (field.primitive === 'array') {\n const raw = rawAt(values, path);\n if (Array.isArray(raw)) rows += raw.length;\n // An item's own arrays are per row; the row count is the container's length, and a\n // nested array is bounded by the node budget when it is actually iterated.\n continue;\n }\n visit(field.fields ?? [], path);\n }\n };\n visit(fields ?? [], '');\n return rows;\n}\n\n/** The rows a declared context array contributes, read from the raw context values. */\nexport function contextRowCount(\n roots: readonly ContextRoot[] | undefined,\n context: Readonly<Record<string, unknown>> | undefined,\n): number {\n let rows = 0;\n for (const root of roots ?? []) {\n if (root.primitive !== 'array') continue;\n const raw = context?.[root.path.replace(/^context\\./, '')];\n if (Array.isArray(raw)) rows += raw.length;\n }\n return rows;\n}\n\n/**\n * The budget an artifact's declared shape earns: one rule's allowance scales with the rows\n * it addresses, and the pass ceiling is the sum of those allowances, bounded.\n */\nexport function evaluationBudget(rows: number, ruleCount: number): EvaluationBudget {\n const declared = declaredRowsWithinCeiling(rows);\n const perRule = Math.max(BASE_RULE_NODES, declared * NODE_ALLOWANCE_PER_ROW);\n const total = Math.min(MAX_PASS_NODES, Math.max(perRule, Math.max(1, ruleCount) * perRule));\n return {\n perRule,\n total,\n elements: Math.max(MIN_COMPREHENSION_ELEMENTS, declared),\n // The ceiling, not the per-source allowance: `elements` can be the 10,000 literal floor on\n // a small record, and a legal 900×900 nesting is 810,000 elements. `EXPR-17.1.1` admits a\n // source up to the ceiling, so a nesting is charged against that same ceiling.\n nestedElements: MAX_COMPREHENSION_ELEMENTS,\n decisions: MAX_DECISIONS,\n };\n}\n\n/** The budget a caller that declares no work runs under: one standalone expression. */\nexport const STANDALONE_BUDGET: EvaluationBudget = evaluationBudget(0, 1);\n\n/** The rule-like allowance units one expression earns, weighted by its actual AST size. */\nfunction expressionCostUnits(node: ExprNode): number {\n let nodes = 0;\n const pending = [node];\n while (pending.length > 0) {\n const current = pending.pop();\n if (current === undefined) break;\n nodes += 1;\n for (const child of childNodes(current)) pending.push(child);\n }\n return Math.max(1, Math.ceil(nodes / NODE_ALLOWANCE_PER_ROW));\n}\n\n/** The allowance units one declared alternative's expressions earn. */\nfunction alternativeCostUnits(suggestions: readonly CompiledSuggestion[] | undefined): number {\n let count = 0;\n for (const suggestion of suggestions ?? []) {\n for (const operation of suggestion.operations) {\n switch (operation.kind) {\n case 'value':\n count += expressionCostUnits(operation.value);\n break;\n case 'append':\n for (const node of Object.values(operation.row)) count += expressionCostUnits(node);\n break;\n case 'null':\n case 'remove':\n case 'removeRow':\n break;\n default:\n assertNever(operation);\n }\n }\n }\n return count;\n}\n\n/** The option conditions an artifact declares, each one rule-like work in the pass total. */\nfunction declaredOptionConditionCount(fields: readonly CompiledField[]): number {\n let count = 0;\n for (const field of fields) {\n for (const option of field.options ?? []) {\n if (option.availableWhen !== undefined) count += 1;\n }\n count += declaredOptionConditionCount(field.fields ?? []);\n }\n return count;\n}\n\n/** The allowance units an artifact's alternative expressions earn, options included. */\nfunction declaredAlternativeCostUnits(compiled: CompiledSchema): number {\n let count = 0;\n for (const rule of compiled.rules ?? []) count += alternativeCostUnits(rule.suggests);\n const visit = (fields: readonly CompiledField[]): void => {\n for (const field of fields) {\n for (const option of field.options ?? []) {\n count += alternativeCostUnits(option.suggests);\n }\n visit(field.fields ?? []);\n }\n };\n visit(compiled.fields);\n return count;\n}\n\n/** The budget a compiled artifact earns against one record. */\nexport function budgetForSchema(\n compiled: CompiledSchema,\n input: EvaluationInput,\n): EvaluationBudget {\n return evaluationBudget(\n declaredRowCount(compiled.fields, input.values) +\n contextRowCount(compiled.context?.roots, input.context),\n declaredRuleWeight(compiled),\n );\n}\n\n/**\n * The rule-like allowance units one artifact declares.\n *\n * Counting the options and walking every alternative's expression tree is a fact about the\n * artifact alone, so it is computed once per compiled artifact and reused by every pass, every\n * evaluation isolate and every session over it. Only the row count scales with the record.\n */\nconst RULE_WEIGHTS: WeakMap<CompiledSchema, number> = new WeakMap();\n\nfunction declaredRuleWeight(compiled: CompiledSchema): number {\n const cached = RULE_WEIGHTS.get(compiled);\n if (cached !== undefined) return cached;\n noteArtifactStaticDerivation();\n const weight =\n (compiled.rules?.length ?? 0) +\n declaredOptionConditionCount(compiled.fields) +\n declaredAlternativeCostUnits(compiled);\n RULE_WEIGHTS.set(compiled, weight);\n return weight;\n}\n\n/** The budget dimension a refusal names, so a report can state which limit was crossed. */\nexport type BudgetDimension = 'rule_nodes' | 'pass_nodes' | 'comprehension_elements' | 'decisions';\n\n/**\n * A refusal that crossed a declared budget.\n *\n * It extends the runtime's own refusal so the evaluator's single error path still carries it,\n * and it keeps the limit and the dimension, which the report states as parameters. Mapping a\n * cost overrun to a bare `ENGINE_ERROR` hid which budget was crossed and by how much.\n */\nexport class BudgetExceededError extends AxiomError {\n readonly limit: number;\n readonly dimension: BudgetDimension;\n /**\n * The operation that crossed the budget, when the caller can name one.\n *\n * A decision refusal is produced by an item rule or by the report fold, and naming which\n * lets an operator size the right thing — one rule's row count rather than the whole pass —\n * without reading the evaluator.\n */\n readonly operation: string | undefined;\n\n constructor(dimension: BudgetDimension, limit: number, detail: string, operation?: string) {\n super('COST_BUDGET_EXCEEDED', `${detail} (limit ${String(limit)})`);\n this.name = 'BudgetExceededError';\n this.limit = limit;\n this.dimension = dimension;\n this.operation = operation;\n }\n}\n\n/**\n * The work one pass has spent, and the allowance of the rule currently running.\n *\n * A nested rule — `rule_ok` evaluating another rule mid-expression — begins its own\n * allowances and restores the interrupted ones, so one rule's spend never shortens another's.\n * The element charge and the comprehension depth are part of that same boundary: a nested rule\n * starts at depth zero, so a comprehension it evaluates is charged to the nested rule and not to\n * the rule whose body asked about it.\n */\nexport class NodeLedger {\n private readonly budget: EvaluationBudget;\n private ruleVisited = 0;\n private passVisited = 0;\n private chargedElements = 0;\n private comprehensionDepth = 0;\n private producedDecisions = 0;\n\n constructor(budget: EvaluationBudget) {\n this.budget = budget;\n }\n\n /** Starts one rule's allowances, returning the interrupted counters to restore later. */\n beginRule(): RuleAllowance {\n const previous: RuleAllowance = {\n visited: this.ruleVisited,\n charged: this.chargedElements,\n depth: this.comprehensionDepth,\n };\n this.ruleVisited = 0;\n this.chargedElements = 0;\n this.comprehensionDepth = 0;\n return previous;\n }\n\n /** Restores the allowances of the rule that asked about this one. */\n endRule(previous: RuleAllowance): void {\n this.ruleVisited = previous.visited;\n this.chargedElements = previous.charged;\n this.comprehensionDepth = previous.depth;\n }\n\n /** Counts one visited node against both allowances. */\n spend(): void {\n this.ruleVisited += 1;\n this.passVisited += 1;\n if (this.ruleVisited > this.budget.perRule) {\n throw new BudgetExceededError(\n 'rule_nodes',\n this.budget.perRule,\n 'one rule visited more nodes than its rows allow',\n );\n }\n if (this.passVisited > this.budget.total) {\n throw new BudgetExceededError(\n 'pass_nodes',\n this.budget.total,\n 'the evaluation visited more nodes than this pass allows',\n );\n }\n }\n\n /** Enters one comprehension, returning the depth it interrupted. */\n beginComprehension(): number {\n const previous = this.comprehensionDepth;\n this.comprehensionDepth = previous + 1;\n return previous;\n }\n\n /** Leaves one comprehension, restoring the depth it interrupted. */\n endComprehension(previous: number): void {\n this.comprehensionDepth = previous;\n }\n\n /**\n * Refuses a comprehension source before the first element is bound.\n *\n * This is the per-source cap: one source no listing may exceed, and a list literal is held\n * to the historical 10,000 floor through `elements`.\n */\n refuseElements(count: number): void {\n if (count <= this.budget.elements) return;\n throw new BudgetExceededError(\n 'comprehension_elements',\n this.budget.elements,\n 'a comprehension source carries more elements than this pass allows',\n );\n }\n\n /**\n * Counts the elements one nested comprehension materialised, against the rule's cumulative\n * charge.\n *\n * The caller charges only a comprehension that is itself inside another: the outermost one\n * reads the declared source once, which is the work the rule's rows already bought, so two\n * aggregates over one admissible array are not refused. The cumulative ceiling is the source\n * ceiling `EXPR-17.1.1` states, not the per-source allowance, so the 900×900 shape is\n * admitted and a nesting that multiplies past 1,000,000 elements is refused.\n */\n chargeElements(count: number): void {\n this.chargedElements += count;\n if (this.chargedElements <= this.budget.nestedElements) return;\n throw new BudgetExceededError(\n 'comprehension_elements',\n this.budget.nestedElements,\n 'nested comprehensions materialised more elements than this rule allows',\n );\n }\n\n /**\n * Refuses a block of report entries before any of them is allocated.\n *\n * An item rule knows its row count before it evaluates the first row, so checking here keeps\n * an over-ceiling shape from allocating a result per row only to throw on the last one. The\n * check does not commit the count; `spendDecisions` records the entries actually produced.\n */\n ensureDecisionRoom(count: number, operation: string): void {\n if (this.producedDecisions + count <= this.budget.decisions) return;\n throw new BudgetExceededError(\n 'decisions',\n this.budget.decisions,\n `the ${operation} would produce more report decisions than this evaluation allows`,\n operation,\n );\n }\n\n /** Counts the report entries one rule produced against the pass-wide decision ceiling. */\n spendDecisions(count: number, operation: string): void {\n this.producedDecisions += count;\n if (this.producedDecisions <= this.budget.decisions) return;\n throw new BudgetExceededError(\n 'decisions',\n this.budget.decisions,\n `the ${operation} produced more report decisions than this evaluation allows`,\n operation,\n );\n }\n}\n\n/** The counters one rule's allowances interrupted, restored when the rule returns. */\nexport interface RuleAllowance {\n /** Nodes the interrupted rule had visited. */\n readonly visited: number;\n /** Nested elements the interrupted rule had materialised. */\n readonly charged: number;\n /** Comprehension depth the interrupted rule was evaluating at. */\n readonly depth: number;\n}\n\n/**\n * The parameters a report states for a budget refusal, or `undefined` when the error is not\n * one. The report names the limit and the dimension so a reader can size the record or split\n * the expression without reading the evaluator.\n */\nexport function budgetRefusalParams(\n error: AxiomError,\n): Readonly<Record<string, WireValue>> | undefined {\n if (!(error instanceof BudgetExceededError)) return undefined;\n return {\n limit: error.limit,\n dimension: error.dimension,\n ...(error.operation === undefined ? {} : { operation: error.operation }),\n };\n}\n"]}
@@ -0,0 +1,46 @@
1
+ import type { CompiledField, ComputedValue, Undetermined } from '../model/types.js';
2
+ import type { Evaluated } from './expression.js';
3
+ /** The writable overlay one evaluation fills in dependency order. */
4
+ export interface ComputedOverlay {
5
+ /** The entry a writer produced for a declared field, or `undefined` when none applies. */
6
+ get(fieldId: string): ComputedValue | undefined;
7
+ /** Records a writer's result. The writer owns the field from now on. */
8
+ set(fieldId: string, value: ComputedValue): void;
9
+ /**
10
+ * The entry a row-scoped writer produced for one row's member, keyed by the array's
11
+ * natural or assigned row key rather than an array position.
12
+ */
13
+ getRow(fieldId: string, rowKey: string | number): ComputedValue | undefined;
14
+ /** Records one row's written member. The writer owns `(fieldId, rowKey)` from now on. */
15
+ setRow(fieldId: string, rowKey: string | number, value: ComputedValue): void;
16
+ /**
17
+ * Drops every entry one writer owns, so a writer that no longer produces a value (a
18
+ * `defaultCompute` whose override became active) does not leave a stale one shadowing the
19
+ * submitted value. A stateless evaluation gets this for free from a fresh overlay; a session
20
+ * that retains one must state it.
21
+ */
22
+ clear(fieldId: string): void;
23
+ /** Every field a writer owns, whether or not it has produced an entry yet. */
24
+ readonly writers: ReadonlySet<string>;
25
+ /**
26
+ * A copy of this overlay with its own maps.
27
+ *
28
+ * A session keeps the computed values of one committed state and derives the next state
29
+ * from them; forking is what lets a preview or a batch's staged operation read and write
30
+ * entries without touching the values the committed state still answers from.
31
+ */
32
+ fork(): ComputedOverlay;
33
+ }
34
+ /** An empty overlay that knows which fields writers own. */
35
+ export declare function computedOverlay(writers: ReadonlySet<string>): ComputedOverlay;
36
+ /** A computed value the writer could not produce, with the sentinel it reports. */
37
+ export declare function undeterminedValue(sentinel: Undetermined): ComputedValue;
38
+ /**
39
+ * The semantic result of one writer's expression: an absent read is `UNKNOWN`, an
40
+ * undetermined operand propagates, and a decided value is rendered against the target.
41
+ *
42
+ * `field` is the declaration the writer writes, or `undefined` for a writer that names no
43
+ * target; such a writer still reports a value but contributes no overlay entry.
44
+ */
45
+ export declare function renderComputedValue(field: CompiledField | undefined, evaluated: Evaluated, path: string): ComputedValue;
46
+ //# sourceMappingURL=computed.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"computed.d.ts","sourceRoot":"","sources":["../../src/eval/computed.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,aAAa,EAAE,YAAY,EAAa,MAAM,mBAAmB,CAAC;AAG/F,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAuBjD,qEAAqE;AACrE,MAAM,WAAW,eAAe;IAC9B,0FAA0F;IAC1F,GAAG,CAAC,OAAO,EAAE,MAAM,GAAG,aAAa,GAAG,SAAS,CAAC;IAChD,wEAAwE;IACxE,GAAG,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,aAAa,GAAG,IAAI,CAAC;IACjD;;;OAGG;IACH,MAAM,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,aAAa,GAAG,SAAS,CAAC;IAC5E,yFAAyF;IACzF,MAAM,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,KAAK,EAAE,aAAa,GAAG,IAAI,CAAC;IAC7E;;;;;OAKG;IACH,KAAK,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,8EAA8E;IAC9E,QAAQ,CAAC,OAAO,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;IACtC;;;;;;OAMG;IACH,IAAI,IAAI,eAAe,CAAC;CACzB;AAED,4DAA4D;AAC5D,wBAAgB,eAAe,CAAC,OAAO,EAAE,WAAW,CAAC,MAAM,CAAC,GAAG,eAAe,CA+B7E;AAED,mFAAmF;AACnF,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,YAAY,GAAG,aAAa,CAEvE;AAsBD;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CACjC,KAAK,EAAE,aAAa,GAAG,SAAS,EAChC,SAAS,EAAE,SAAS,EACpB,IAAI,EAAE,MAAM,GACX,aAAa,CAcf"}
@@ -0,0 +1,89 @@
1
+ import { asDecimalString } from '../expr/decimal.js';
2
+ import { isSafeInteger } from '../model/integer.js';
3
+ import { isUndetermined, UNKNOWN } from '../model/types.js';
4
+ import { rowKeyToken, toWireValue, wireDeclarationOf } from '../model/wire.js';
5
+ /** An empty overlay that knows which fields writers own. */
6
+ export function computedOverlay(writers) {
7
+ const entries = new Map();
8
+ const rows = new Map();
9
+ return {
10
+ get: (fieldId) => entries.get(fieldId),
11
+ set: (fieldId, value) => {
12
+ entries.set(fieldId, value);
13
+ },
14
+ getRow: (fieldId, rowKey) => rows.get(fieldId)?.get(rowKeyToken(rowKey))?.value,
15
+ setRow: (fieldId, rowKey, value) => {
16
+ // The token carries the wire type, so the integer `7` and the text `"7"` never name
17
+ // one row.
18
+ const token = rowKeyToken(rowKey);
19
+ const entriesForField = rows.get(fieldId);
20
+ if (entriesForField === undefined)
21
+ rows.set(fieldId, new Map([[token, { rowKey, value }]]));
22
+ else
23
+ entriesForField.set(token, { rowKey, value });
24
+ },
25
+ clear: (fieldId) => {
26
+ entries.delete(fieldId);
27
+ rows.delete(fieldId);
28
+ },
29
+ writers,
30
+ fork: () => {
31
+ const copy = computedOverlay(writers);
32
+ for (const [fieldId, value] of entries)
33
+ copy.set(fieldId, value);
34
+ for (const [fieldId, rowsForField] of rows) {
35
+ for (const entry of rowsForField.values())
36
+ copy.setRow(fieldId, entry.rowKey, entry.value);
37
+ }
38
+ return copy;
39
+ },
40
+ };
41
+ }
42
+ /** A computed value the writer could not produce, with the sentinel it reports. */
43
+ export function undeterminedValue(sentinel) {
44
+ return { kind: 'undetermined', sentinel };
45
+ }
46
+ /**
47
+ * The wire value a writer's decided result writes.
48
+ *
49
+ * The write boundary renders the target primitive canonically: `if` and `coalesce` unify an
50
+ * integer branch with a decimal one, so a decimal target can receive an integer at run time,
51
+ * and the wire contract spells a decimal as canonical text. A JSON number would be read as a
52
+ * different value (and `7` would reach the host as a number the decimal declaration refuses).
53
+ * Every result is validated through the target declaration; a value the declaration does not
54
+ * admit throws, and the caller reports the writer `UNKNOWN` instead of writing a coerced
55
+ * value.
56
+ */
57
+ function writeValue(field, value, path) {
58
+ if (field === undefined)
59
+ return value;
60
+ const rendered = field.primitive === 'decimal' && typeof value === 'number' && isSafeInteger(value)
61
+ ? asDecimalString(String(value), path)
62
+ : value;
63
+ return toWireValue(rendered, path, wireDeclarationOf(field));
64
+ }
65
+ /**
66
+ * The semantic result of one writer's expression: an absent read is `UNKNOWN`, an
67
+ * undetermined operand propagates, and a decided value is rendered against the target.
68
+ *
69
+ * `field` is the declaration the writer writes, or `undefined` for a writer that names no
70
+ * target; such a writer still reports a value but contributes no overlay entry.
71
+ */
72
+ export function renderComputedValue(field, evaluated, path) {
73
+ if (evaluated.kind === 'absent')
74
+ return undeterminedValue(UNKNOWN);
75
+ if (isUndetermined(evaluated.value))
76
+ return undeterminedValue(evaluated.value);
77
+ return {
78
+ kind: 'decided',
79
+ value: writeValue(field, evaluated.value, path),
80
+ ...(evaluated.withheldMembers === undefined
81
+ ? {}
82
+ : { withheldMembers: evaluated.withheldMembers }),
83
+ ...(evaluated.withheldRows === undefined ? {} : { withheldRows: evaluated.withheldRows }),
84
+ ...(evaluated.undeterminedRows === undefined
85
+ ? {}
86
+ : { undeterminedRows: evaluated.undeterminedRows }),
87
+ };
88
+ }
89
+ //# sourceMappingURL=computed.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"computed.js","sourceRoot":"","sources":["../../src/eval/computed.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEpD,OAAO,EAAE,cAAc,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAC5D,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAwD/E,4DAA4D;AAC5D,MAAM,UAAU,eAAe,CAAC,OAA4B;IAC1D,MAAM,OAAO,GAAG,IAAI,GAAG,EAAyB,CAAC;IACjD,MAAM,IAAI,GAAG,IAAI,GAAG,EAAiC,CAAC;IACtD,OAAO;QACL,GAAG,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC;QACtC,GAAG,EAAE,CAAC,OAAO,EAAE,KAAK,EAAE,EAAE;YACtB,OAAO,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CAAC;QACnD,GAAG,CAAC,SAAS,CAAC,YAAY,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,YAAY,EAAE,SAAS,CAAC,YAAY,EAAE,CAAC;QACzF,GAAG,CAAC,SAAS,CAAC,gBAAgB,KAAK,SAAS;YAC1C,CAAC,CAAC,EAAE;YACJ,CAAC,CAAC,EAAE,gBAAgB,EAAE,SAAS,CAAC,gBAAgB,EAAE,CAAC;KACtD,CAAC;AACJ,CAAC","sourcesContent":["import { asDecimalString } from '../expr/decimal.js';\nimport { isSafeInteger } from '../model/integer.js';\nimport type { CompiledField, ComputedValue, Undetermined, WireValue } from '../model/types.js';\nimport { isUndetermined, UNKNOWN } from '../model/types.js';\nimport { rowKeyToken, toWireValue, wireDeclarationOf } from '../model/wire.js';\nimport type { Evaluated } from './expression.js';\n\n/**\n * The computed-value overlay, `spec/semantics/rules-v1.md`.\n *\n * One evaluation owns one overlay. A writer's semantic result is recorded under the field it\n * owns, and every read of that field yields the entry rather than the submitted value: the\n * writer is the sole authority for a `compute` target, so there is no `overlay.get(id) ??\n * input.values[id]` fallback to leak a stale or tampered submission through an undetermined\n * computation. A `defaultCompute` is the exception the language states: while an override\n * record is active the stored value is the field's value, so no entry is recorded and the\n * reader resolves the submission as usual.\n *\n * The overlay is a plain mutable map rather than a class because its lifetime is one\n * evaluation and its identity is the map, not a type the contract exposes.\n */\n\n/** One row-scoped entry, kept with the key it was stored under so a fork copies it whole. */\ninterface RowEntry {\n readonly rowKey: string | number;\n readonly value: ComputedValue;\n}\n\n/** The writable overlay one evaluation fills in dependency order. */\nexport interface ComputedOverlay {\n /** The entry a writer produced for a declared field, or `undefined` when none applies. */\n get(fieldId: string): ComputedValue | undefined;\n /** Records a writer's result. The writer owns the field from now on. */\n set(fieldId: string, value: ComputedValue): void;\n /**\n * The entry a row-scoped writer produced for one row's member, keyed by the array's\n * natural or assigned row key rather than an array position.\n */\n getRow(fieldId: string, rowKey: string | number): ComputedValue | undefined;\n /** Records one row's written member. The writer owns `(fieldId, rowKey)` from now on. */\n setRow(fieldId: string, rowKey: string | number, value: ComputedValue): void;\n /**\n * Drops every entry one writer owns, so a writer that no longer produces a value (a\n * `defaultCompute` whose override became active) does not leave a stale one shadowing the\n * submitted value. A stateless evaluation gets this for free from a fresh overlay; a session\n * that retains one must state it.\n */\n clear(fieldId: string): void;\n /** Every field a writer owns, whether or not it has produced an entry yet. */\n readonly writers: ReadonlySet<string>;\n /**\n * A copy of this overlay with its own maps.\n *\n * A session keeps the computed values of one committed state and derives the next state\n * from them; forking is what lets a preview or a batch's staged operation read and write\n * entries without touching the values the committed state still answers from.\n */\n fork(): ComputedOverlay;\n}\n\n/** An empty overlay that knows which fields writers own. */\nexport function computedOverlay(writers: ReadonlySet<string>): ComputedOverlay {\n const entries = new Map<string, ComputedValue>();\n const rows = new Map<string, Map<string, RowEntry>>();\n return {\n get: (fieldId) => entries.get(fieldId),\n set: (fieldId, value) => {\n entries.set(fieldId, value);\n },\n getRow: (fieldId, rowKey) => rows.get(fieldId)?.get(rowKeyToken(rowKey))?.value,\n setRow: (fieldId, rowKey, value) => {\n // The token carries the wire type, so the integer `7` and the text `\"7\"` never name\n // one row.\n const token = rowKeyToken(rowKey);\n const entriesForField = rows.get(fieldId);\n if (entriesForField === undefined) rows.set(fieldId, new Map([[token, { rowKey, value }]]));\n else entriesForField.set(token, { rowKey, value });\n },\n clear: (fieldId) => {\n entries.delete(fieldId);\n rows.delete(fieldId);\n },\n writers,\n fork: () => {\n const copy = computedOverlay(writers);\n for (const [fieldId, value] of entries) copy.set(fieldId, value);\n for (const [fieldId, rowsForField] of rows) {\n for (const entry of rowsForField.values()) copy.setRow(fieldId, entry.rowKey, entry.value);\n }\n return copy;\n },\n };\n}\n\n/** A computed value the writer could not produce, with the sentinel it reports. */\nexport function undeterminedValue(sentinel: Undetermined): ComputedValue {\n return { kind: 'undetermined', sentinel };\n}\n\n/**\n * The wire value a writer's decided result writes.\n *\n * The write boundary renders the target primitive canonically: `if` and `coalesce` unify an\n * integer branch with a decimal one, so a decimal target can receive an integer at run time,\n * and the wire contract spells a decimal as canonical text. A JSON number would be read as a\n * different value (and `7` would reach the host as a number the decimal declaration refuses).\n * Every result is validated through the target declaration; a value the declaration does not\n * admit throws, and the caller reports the writer `UNKNOWN` instead of writing a coerced\n * value.\n */\nfunction writeValue(field: CompiledField | undefined, value: WireValue, path: string): WireValue {\n if (field === undefined) return value;\n const rendered =\n field.primitive === 'decimal' && typeof value === 'number' && isSafeInteger(value)\n ? asDecimalString(String(value), path)\n : value;\n return toWireValue(rendered, path, wireDeclarationOf(field));\n}\n\n/**\n * The semantic result of one writer's expression: an absent read is `UNKNOWN`, an\n * undetermined operand propagates, and a decided value is rendered against the target.\n *\n * `field` is the declaration the writer writes, or `undefined` for a writer that names no\n * target; such a writer still reports a value but contributes no overlay entry.\n */\nexport function renderComputedValue(\n field: CompiledField | undefined,\n evaluated: Evaluated,\n path: string,\n): ComputedValue {\n if (evaluated.kind === 'absent') return undeterminedValue(UNKNOWN);\n if (isUndetermined(evaluated.value)) return undeterminedValue(evaluated.value);\n return {\n kind: 'decided',\n value: writeValue(field, evaluated.value, path),\n ...(evaluated.withheldMembers === undefined\n ? {}\n : { withheldMembers: evaluated.withheldMembers }),\n ...(evaluated.withheldRows === undefined ? {} : { withheldRows: evaluated.withheldRows }),\n ...(evaluated.undeterminedRows === undefined\n ? {}\n : { undeterminedRows: evaluated.undeterminedRows }),\n };\n}\n"]}