@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,191 @@
1
+ import type { DatasetDigestMismatch } from '../lookup/digest.js';
2
+ import type { CompiledSchema } from '../model/schema.js';
3
+ import type { LookupTableDocument } from '../model/types.js';
4
+ export type { DatasetDigestMismatch } from '../lookup/digest.js';
5
+ /**
6
+ * The store a host persists offline bytes in, and the reference implementation tests use.
7
+ *
8
+ * Admission answers *whether* a device's bytes may be evaluated. This door also states *where*
9
+ * those bytes and the device's drafts, reports and queued submissions live, so a host that
10
+ * implements the contract serves `admitOfflineArtifact` from the same store it writes to. See
11
+ * `./offline/index.ts` for the two operations that must be atomic.
12
+ */
13
+ export * from '../offline/index.js';
14
+ /**
15
+ * Pure offline readiness, `spec/semantics/canonical-v1.md` section 5.
16
+ *
17
+ * This module exposes data and two total functions. It stores nothing, signs nothing
18
+ * and reads no clock: the caller supplies the artifact bytes, the hashes it holds and
19
+ * the date range it needs, so the answer is reproducible and testable. The store contract
20
+ * beside them says where a host keeps those bytes between sessions; it too reads no clock,
21
+ * and its reference implementation holds only what a caller put in it.
22
+ */
23
+ /**
24
+ * A required artifact: the identity and version the evaluation needs, and the digest the
25
+ * match is filed under.
26
+ *
27
+ * `sha256` is part of the match key beside `artifactId` and `artifactVersion`, so a
28
+ * requirement states the copy it is asking for. `admitOfflineArtifact` builds each requirement
29
+ * from the artifact's own pin and verifies the held document against it before this fold runs,
30
+ * so on that path the digest is an integrity check of the table's content, not only an identity
31
+ * check.
32
+ */
33
+ export interface ArtifactRequirement {
34
+ readonly artifactId: string;
35
+ readonly artifactVersion: number;
36
+ readonly sha256: string;
37
+ }
38
+ /**
39
+ * An artifact the caller holds. A data-bound artifact declares its half-open
40
+ * `[effectiveFrom, effectiveTo)` window; a behavior artifact pins to
41
+ * the case and declares none.
42
+ */
43
+ export interface AvailableArtifact {
44
+ readonly artifactId: string;
45
+ readonly artifactVersion: number;
46
+ readonly sha256: string;
47
+ /**
48
+ * The table's clock binding, when the caller knows it. A `data` artifact must carry a
49
+ * window to be verifiable; a `behavior` artifact pins to the case and carries none.
50
+ */
51
+ readonly binding?: 'behavior' | 'data';
52
+ readonly effectiveFrom?: string;
53
+ readonly effectiveTo?: string;
54
+ }
55
+ /** The inclusive date range an evaluation is being prepared for. */
56
+ export interface RequiredDateRange {
57
+ readonly from: string;
58
+ readonly to: string;
59
+ }
60
+ /**
61
+ * Every requirement appears in exactly one bucket. `missing` also
62
+ * holds a requirement whose held copy cannot be verified, because an unverifiable
63
+ * artifact must not be assumed present.
64
+ */
65
+ export interface ReadinessReport {
66
+ readonly available: readonly ArtifactRequirement[];
67
+ readonly missing: readonly ArtifactRequirement[];
68
+ readonly stale: readonly ArtifactRequirement[];
69
+ }
70
+ /** The artifact bytes a caller is asking about. */
71
+ export interface ArtifactBytes {
72
+ readonly bytes: Uint8Array;
73
+ }
74
+ /**
75
+ * Whether an artifact's bytes hash to the expected digest. A mismatch
76
+ * returns `false` rather than throwing, and the artifact is never mutated.
77
+ */
78
+ export declare function verifyArtifactHash(artifact: ArtifactBytes, expectedHash: string): boolean;
79
+ /**
80
+ * Reports which required artifacts are available, missing or stale for a required date
81
+ * range. A requirement is matched on its identity, version and digest together, so a held
82
+ * copy filed at the same id and version but under another digest is missing, not available;
83
+ * a table whose window does not cover the range is stale, not missing. No clock is read.
84
+ *
85
+ * This function checks the digest the caller states. `admitOfflineArtifact` states the digest
86
+ * the artifact pins and verifies the held document against it first, so a same-version
87
+ * republished table is a `table_digest_mismatch` refusal there rather than a stale or missing
88
+ * entry here.
89
+ */
90
+ export declare function checkReadiness(required: readonly ArtifactRequirement[], availableHashes: readonly AvailableArtifact[], requiredDateRange: RequiredDateRange): ReadinessReport;
91
+ /** What a device holds when it asks whether it may evaluate a compiled artifact offline. */
92
+ export interface OfflineArtifactRequest {
93
+ /** The parsed artifact document, which is also the value the digest covers. */
94
+ readonly artifact: CompiledSchema;
95
+ /**
96
+ * The digest the artifact's canonical restricted-JSON text must hash to.
97
+ *
98
+ * The digest is over the canonical text rather than the file's bytes because a client
99
+ * rehydrates the document from a module loader that keeps no bytes: the same artifact arrives
100
+ * through Vite, Metro and `readFile` without sharing a byte sequence, and all three must reach
101
+ * the same admission answer.
102
+ */
103
+ readonly expectedSha256: string;
104
+ /**
105
+ * The table documents this device holds. Their identity, version, canonical digest and
106
+ * effective window are what the gate checks: the digest is recomputed from the document here
107
+ * and compared with the one the artifact pins, so a republished table under the same version
108
+ * is refused rather than resolved.
109
+ */
110
+ readonly tables: readonly LookupTableDocument[];
111
+ /**
112
+ * The record date the evaluation is being prepared for, when the record states one.
113
+ *
114
+ * Demanded only where a pinned copy's coverage reads it: a data-bound table resolves against its
115
+ * half-open window (`DATA-2.1.4`), and a copy that states a window is tested against it. A
116
+ * behavior-bound copy declares no window and covers every date (`DATA-2.1.2`), so a device that
117
+ * holds only those is admitted without a date rather than inventing one it does not have.
118
+ */
119
+ readonly recordDate: string | undefined;
120
+ }
121
+ /** A pin that names a table version but carries no digest, so its bytes cannot be verified. */
122
+ export interface UnboundDatasetPin {
123
+ readonly tableId: string;
124
+ readonly tableVersion: number;
125
+ }
126
+ /** Why a device may not evaluate an artifact offline, with the artifacts it names. */
127
+ export type OfflineRefusal = {
128
+ readonly kind: 'refused';
129
+ readonly reason: 'artifact_hash';
130
+ readonly expected: string;
131
+ readonly actual: string;
132
+ } | {
133
+ readonly kind: 'refused';
134
+ /**
135
+ * A pinned table whose coverage needs a record date and the device supplied none.
136
+ * `tables` names those tables only: a behavior-bound copy that declares no window needs no
137
+ * date, and a pin the device holds no copy of is named because its binding cannot be read.
138
+ */
139
+ readonly reason: 'no_record_date';
140
+ readonly tables: readonly string[];
141
+ } | {
142
+ readonly kind: 'refused';
143
+ /** A pin that names a version but no bytes: the table cannot be verified at all. */
144
+ readonly reason: 'table_digest_missing';
145
+ readonly tables: readonly UnboundDatasetPin[];
146
+ } | {
147
+ readonly kind: 'refused';
148
+ /** A held document at the pinned version whose canonical digest differs from the pin. */
149
+ readonly reason: 'table_digest_mismatch';
150
+ readonly tables: readonly DatasetDigestMismatch[];
151
+ } | {
152
+ readonly kind: 'refused';
153
+ readonly reason: 'table_missing' | 'table_stale';
154
+ readonly missing: readonly ArtifactRequirement[];
155
+ readonly stale: readonly ArtifactRequirement[];
156
+ };
157
+ /** The admission answer: evaluate, or the refusal a device renders instead of evaluating. */
158
+ export type OfflineAdmission = {
159
+ readonly kind: 'admitted';
160
+ } | OfflineRefusal;
161
+ /**
162
+ * One offline admission decision, `DR-AX-05`.
163
+ *
164
+ * Four questions are answered before any rule reads a value: does the artifact's canonical text
165
+ * hash to the digest the device was told to expect, does the artifact pin the bytes of every
166
+ * table the evaluation needs, does the device hold those exact bytes at the pinned version, and
167
+ * do those tables' effective windows cover the record date. A "no" to any of them is a refusal a
168
+ * device renders, never a fallback to a neighbouring table or a plausible default.
169
+ *
170
+ * The table half checks **identity, version, canonical digest and effective window**. A
171
+ * `DatasetRef` carries the restricted-JCS SHA-256 of the document it pins, computed by the same
172
+ * `canonicalHash` the store records as a resolution's `tableSha256` (`DATA-4.1.2`). This gate
173
+ * recomputes that digest over the held document and compares it, so a document republished under
174
+ * the pinned version is refused with both digests rather than resolved. A pin that carries no
175
+ * digest is refused too: a version is a name, and a name is not the bytes the decision was made
176
+ * on.
177
+ *
178
+ * A record date is a question about a copy, not a count of pins. A behavior-bound table pins to
179
+ * the case and declares no window (`DATA-2.1.2`), so a device holding only those is admitted with
180
+ * no date at all. A data-bound table, or any copy that states a window whatever its binding
181
+ * claims, needs the date to test its half-open window; with none, the gate refuses
182
+ * `no_record_date` and names exactly those tables. A pin the device holds no copy of is in that
183
+ * set too: its binding cannot be read, and the date-free answer is not assumed for bytes the gate
184
+ * cannot see.
185
+ *
186
+ * The artifact digest is `verifyArtifactHash` over the artifact's canonical text:
187
+ * `verifyArtifactHash` is a byte check, so the caller's value is made into the one canonical
188
+ * byte sequence rather than each loader inventing its own spelling.
189
+ */
190
+ export declare function admitOfflineArtifact(request: OfflineArtifactRequest): OfflineAdmission;
191
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/cache/index.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAC;AAEjE,OAAO,KAAK,EAAE,cAAc,EAAc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C,GACD;IACE,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC;IACzB,yFAAyF;IACzF,QAAQ,CAAC,MAAM,EAAE,uBAAuB,CAAC;IACzC,QAAQ,CAAC,MAAM,EAAE,SAAS,qBAAqB,EAAE,CAAC;CACnD,GACD;IACE,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC;IACzB,QAAQ,CAAC,MAAM,EAAE,eAAe,GAAG,aAAa,CAAC;IACjD,QAAQ,CAAC,OAAO,EAAE,SAAS,mBAAmB,EAAE,CAAC;IACjD,QAAQ,CAAC,KAAK,EAAE,SAAS,mBAAmB,EAAE,CAAC;CAChD,CAAC;AAEN,6FAA6F;AAC7F,MAAM,MAAM,gBAAgB,GAAG;IAAE,QAAQ,CAAC,IAAI,EAAE,UAAU,CAAA;CAAE,GAAG,cAAc,CAAC;AA8F9E;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,sBAAsB,GAAG,gBAAgB,CA0GtF"}
@@ -0,0 +1,361 @@
1
+ import { canonicalHash, canonicalizeRestricted, sha256HexOfBytes, utf8BytesOf, } from '../canonical/jcs.js';
2
+ import { daysFromCivil, parsePlainDate } from '../expr/plain-date.js';
3
+ import { declaredFieldExpressions, ruleExpressions } from '../graph/read-walk.js';
4
+ // The comparison and its mismatch shape are the lookup seam's, so this door and the evaluation
5
+ // path cannot disagree about what a mismatch is or how it is spelled.
6
+ import { datasetDigestMismatch } from '../lookup/digest.js';
7
+ import { AxiomError } from '../model/errors.js';
8
+ import { DATASET_BUILTINS } from '../model/types.js';
9
+ /**
10
+ * The store a host persists offline bytes in, and the reference implementation tests use.
11
+ *
12
+ * Admission answers *whether* a device's bytes may be evaluated. This door also states *where*
13
+ * those bytes and the device's drafts, reports and queued submissions live, so a host that
14
+ * implements the contract serves `admitOfflineArtifact` from the same store it writes to. See
15
+ * `./offline/index.ts` for the two operations that must be atomic.
16
+ */
17
+ export * from '../offline/index.js';
18
+ /**
19
+ * Whether an artifact's bytes hash to the expected digest. A mismatch
20
+ * returns `false` rather than throwing, and the artifact is never mutated.
21
+ */
22
+ export function verifyArtifactHash(artifact, expectedHash) {
23
+ return sha256HexOfBytes(artifact.bytes) === expectedHash;
24
+ }
25
+ /**
26
+ * Days since the epoch for a plain date, or `undefined` when the text is not one. A
27
+ * malformed date makes an artifact's window unverifiable, which `covers` reports as
28
+ * not covered rather than assuming it; the parse error carries nothing further the
29
+ * caller can act on.
30
+ */
31
+ function dayOf(text) {
32
+ try {
33
+ const date = parsePlainDate(text);
34
+ return daysFromCivil(date.year, date.month, date.day);
35
+ }
36
+ catch (error) {
37
+ // Only a refusal says the text is not a date; anything else is a defect that must
38
+ // not be reported as an unverifiable artifact window.
39
+ if (!(error instanceof AxiomError))
40
+ throw error;
41
+ return undefined;
42
+ }
43
+ }
44
+ /**
45
+ * The identity a requirement and a held artifact are matched on. The three fields are
46
+ * the whole match, so one map lookup replaces a linear scan per requirement.
47
+ */
48
+ function artifactKey(artifact) {
49
+ return `${artifact.artifactId}\u0000${String(artifact.artifactVersion)}\u0000${artifact.sha256}`;
50
+ }
51
+ /**
52
+ * Whether a copy needs no date at all to prove its coverage.
53
+ *
54
+ * Exactly one shape does: a copy that pins to the case and declares neither bound
55
+ * (`DATA-2.1.2`). A declared window is read whatever the binding claims, because a copy whose
56
+ * stated bounds disagree with its binding is windowed in fact, and choosing its cheaper half
57
+ * would admit a window no date was tested against.
58
+ */
59
+ function isDateFree(copy) {
60
+ return (copy.binding === 'behavior' &&
61
+ copy.effectiveFrom === undefined &&
62
+ copy.effectiveTo === undefined);
63
+ }
64
+ /**
65
+ * Whether a held artifact's window covers the required range.
66
+ *
67
+ * A copy that pins to the case and declares no window covers every date — including a range the
68
+ * caller could not parse. That branch precedes the range guard because a
69
+ * table which never reads a date must not become unverifiable when the date it ignores is
70
+ * malformed. A data-bound artifact versions independently, so its half-open window is part of
71
+ * what it must carry; without one its coverage cannot be verified and it is stale rather than
72
+ * assumed to cover everything. An artifact whose clock binding the caller did not state is not
73
+ * read as behavior-bound when it carries no window: that would let a data table which lost its
74
+ * window cover every date.
75
+ */
76
+ function covers(held, range) {
77
+ if (isDateFree(held))
78
+ return true;
79
+ const { from, to } = range;
80
+ if (from === undefined || to === undefined)
81
+ return false;
82
+ // A range whose end precedes its start is not a range any window can cover.
83
+ if (from > to)
84
+ return false;
85
+ const heldFrom = held.effectiveFrom === undefined ? undefined : dayOf(held.effectiveFrom);
86
+ const heldTo = held.effectiveTo === undefined ? undefined : dayOf(held.effectiveTo);
87
+ if (heldFrom === undefined || heldTo === undefined)
88
+ return false;
89
+ return heldFrom <= from && to < heldTo;
90
+ }
91
+ /**
92
+ * Reports which required artifacts are available, missing or stale for a required date
93
+ * range. A requirement is matched on its identity, version and digest together, so a held
94
+ * copy filed at the same id and version but under another digest is missing, not available;
95
+ * a table whose window does not cover the range is stale, not missing. No clock is read.
96
+ *
97
+ * This function checks the digest the caller states. `admitOfflineArtifact` states the digest
98
+ * the artifact pins and verifies the held document against it first, so a same-version
99
+ * republished table is a `table_digest_mismatch` refusal there rather than a stale or missing
100
+ * entry here.
101
+ */
102
+ export function checkReadiness(required, availableHashes, requiredDateRange) {
103
+ const held = new Map();
104
+ for (const artifact of availableHashes) {
105
+ const key = artifactKey(artifact);
106
+ // The first declaration wins, as the linear scan this replaces did.
107
+ if (!held.has(key))
108
+ held.set(key, artifact);
109
+ }
110
+ const range = {
111
+ from: dayOf(requiredDateRange.from),
112
+ to: dayOf(requiredDateRange.to),
113
+ };
114
+ const available = [];
115
+ const missing = [];
116
+ const stale = [];
117
+ for (const requirement of required) {
118
+ const match = held.get(artifactKey(requirement));
119
+ if (match === undefined) {
120
+ missing.push(requirement);
121
+ continue;
122
+ }
123
+ if (!covers(match, range)) {
124
+ stale.push(requirement);
125
+ continue;
126
+ }
127
+ available.push(requirement);
128
+ }
129
+ return { available, missing, stale };
130
+ }
131
+ /**
132
+ * The identity a held copy is filed under: a device caches versions side by side, and the
133
+ * digest of the version the artifact pins is not the digest of the newest one beside it.
134
+ */
135
+ function tableVersionKey(tableId, tableVersion) {
136
+ return `${tableId}\u0000${String(tableVersion)}`;
137
+ }
138
+ /**
139
+ * The first held document at each `(tableId, tableVersion)`, matching `checkReadiness`'s
140
+ * first-declaration-wins rule.
141
+ *
142
+ * Versioning is why this is not keyed by `tableId` alone: an installation that holds v1 and the
143
+ * v2 it downloaded later must still admit an artifact that pins v1.
144
+ */
145
+ function heldDocuments(tables) {
146
+ const documents = new Map();
147
+ for (const table of tables) {
148
+ const key = tableVersionKey(table.tableId, table.tableVersion);
149
+ if (!documents.has(key))
150
+ documents.set(key, table);
151
+ }
152
+ return documents;
153
+ }
154
+ /**
155
+ * The tables an artifact's rules and declared field expressions can reach. A client artifact's
156
+ * rule reachability is its client-tier rules: every server-tier rule became a deferred stub, and
157
+ * even an artifact that still carries an authored server expression never resolves a table for it
158
+ * on the device. A server artifact runs every rule it carries, so every rule counts. A declared
159
+ * field's own expressions (`rowsFrom`, option availability, reason parameters and alternatives)
160
+ * run on the device in both tiers, so tables they read are reachable in both tiers.
161
+ *
162
+ * Walking `ruleExpressions` and `declaredFieldExpressions` uses the same slot walk the compiler
163
+ * and submission door read.
164
+ */
165
+ function readableTables(artifact) {
166
+ const clientOnly = artifact.target === 'client';
167
+ const tables = new Set();
168
+ for (const rule of artifact.rules ?? []) {
169
+ if (clientOnly && rule.evaluateOn !== 'client')
170
+ continue;
171
+ for (const node of ruleExpressions(rule))
172
+ collectTables(node, tables);
173
+ }
174
+ for (const slot of declaredFieldExpressions(artifact.fields)) {
175
+ collectTables(slot.node, tables);
176
+ }
177
+ return tables;
178
+ }
179
+ /** Every table id a dataset built-in in this expression names, into `into`. */
180
+ function collectTables(node, into) {
181
+ switch (node.kind) {
182
+ case 'literal':
183
+ case 'path':
184
+ return;
185
+ case 'list':
186
+ for (const item of node.items)
187
+ collectTables(item, into);
188
+ return;
189
+ case 'comprehension':
190
+ collectTables(node.source, into);
191
+ if (node.valueExpr !== undefined)
192
+ collectTables(node.valueExpr, into);
193
+ if (node.predicate !== undefined)
194
+ collectTables(node.predicate, into);
195
+ return;
196
+ case 'call': {
197
+ if (DATASET_BUILTINS.has(node.op)) {
198
+ const [table] = node.args;
199
+ if (table?.kind === 'path')
200
+ into.add(table.path);
201
+ }
202
+ for (const arg of node.args)
203
+ collectTables(arg, into);
204
+ return;
205
+ }
206
+ default:
207
+ for (const arg of node.args)
208
+ collectTables(arg, into);
209
+ }
210
+ }
211
+ /**
212
+ * The pins a device must satisfy: only the tables the artifact's own rules or declared field
213
+ * expressions can reach.
214
+ *
215
+ * A pin no reachable rule or declared field expression can read is not a fact the device must
216
+ * carry: it cannot affect a decision, and requiring it would make an offline session depend on
217
+ * data no evaluation can use (`DATA-4.1.6`). A client artifact narrows rule reachability to its
218
+ * client-tier rules, so a table only a server rule reads is not a device requirement either.
219
+ */
220
+ function requiredPins(artifact) {
221
+ const pinned = artifact.datasets ?? [];
222
+ const readable = readableTables(artifact);
223
+ return pinned.filter((ref) => readable.has(ref.tableId));
224
+ }
225
+ /**
226
+ * One offline admission decision, `DR-AX-05`.
227
+ *
228
+ * Four questions are answered before any rule reads a value: does the artifact's canonical text
229
+ * hash to the digest the device was told to expect, does the artifact pin the bytes of every
230
+ * table the evaluation needs, does the device hold those exact bytes at the pinned version, and
231
+ * do those tables' effective windows cover the record date. A "no" to any of them is a refusal a
232
+ * device renders, never a fallback to a neighbouring table or a plausible default.
233
+ *
234
+ * The table half checks **identity, version, canonical digest and effective window**. A
235
+ * `DatasetRef` carries the restricted-JCS SHA-256 of the document it pins, computed by the same
236
+ * `canonicalHash` the store records as a resolution's `tableSha256` (`DATA-4.1.2`). This gate
237
+ * recomputes that digest over the held document and compares it, so a document republished under
238
+ * the pinned version is refused with both digests rather than resolved. A pin that carries no
239
+ * digest is refused too: a version is a name, and a name is not the bytes the decision was made
240
+ * on.
241
+ *
242
+ * A record date is a question about a copy, not a count of pins. A behavior-bound table pins to
243
+ * the case and declares no window (`DATA-2.1.2`), so a device holding only those is admitted with
244
+ * no date at all. A data-bound table, or any copy that states a window whatever its binding
245
+ * claims, needs the date to test its half-open window; with none, the gate refuses
246
+ * `no_record_date` and names exactly those tables. A pin the device holds no copy of is in that
247
+ * set too: its binding cannot be read, and the date-free answer is not assumed for bytes the gate
248
+ * cannot see.
249
+ *
250
+ * The artifact digest is `verifyArtifactHash` over the artifact's canonical text:
251
+ * `verifyArtifactHash` is a byte check, so the caller's value is made into the one canonical
252
+ * byte sequence rather than each loader inventing its own spelling.
253
+ */
254
+ export function admitOfflineArtifact(request) {
255
+ const bytes = utf8BytesOf(canonicalizeRestricted(request.artifact));
256
+ if (!verifyArtifactHash({ bytes }, request.expectedSha256)) {
257
+ return {
258
+ kind: 'refused',
259
+ reason: 'artifact_hash',
260
+ expected: request.expectedSha256,
261
+ actual: sha256HexOfBytes(bytes),
262
+ };
263
+ }
264
+ const required = requiredPins(request.artifact);
265
+ if (required.length === 0)
266
+ return { kind: 'admitted' };
267
+ const held = heldDocuments(request.tables);
268
+ // A date is only a fact this gate can demand where a copy's coverage would read it. A held copy
269
+ // that pins to the case and declares no window covers every date, so it needs none; every other
270
+ // pin does, and `tables` names those rather than the whole pin list. A pin with no held copy
271
+ // cannot show its binding, so it is counted as date-dependent: the gate does not assume the
272
+ // cheaper answer for a document it cannot read.
273
+ if (request.recordDate === undefined) {
274
+ const dateDependent = required.filter((ref) => {
275
+ const document = held.get(tableVersionKey(ref.tableId, ref.tableVersion));
276
+ return document === undefined || !isDateFree(document);
277
+ });
278
+ if (dateDependent.length > 0) {
279
+ return {
280
+ kind: 'refused',
281
+ reason: 'no_record_date',
282
+ tables: dateDependent.map((ref) => ref.tableId),
283
+ };
284
+ }
285
+ }
286
+ // A pin that carries no digest is a defect of the artifact, not of what this device happens to
287
+ // hold, so it is refused before any lookup: the table's bytes could never be verified. The
288
+ // bound list is the narrowed form, so the checks below never cast.
289
+ const unbound = [];
290
+ const bound = [];
291
+ for (const ref of required) {
292
+ if (typeof ref.sha256 !== 'string') {
293
+ unbound.push({ tableId: ref.tableId, tableVersion: ref.tableVersion });
294
+ continue;
295
+ }
296
+ bound.push({ ref, sha256: ref.sha256 });
297
+ }
298
+ if (unbound.length > 0) {
299
+ return { kind: 'refused', reason: 'table_digest_missing', tables: unbound };
300
+ }
301
+ const mismatched = [];
302
+ const missing = [];
303
+ for (const { ref, sha256 } of bound) {
304
+ const document = held.get(tableVersionKey(ref.tableId, ref.tableVersion));
305
+ if (document === undefined) {
306
+ // No bytes to compare: the table is missing, not unverifiable.
307
+ missing.push({
308
+ artifactId: ref.tableId,
309
+ artifactVersion: ref.tableVersion,
310
+ sha256,
311
+ });
312
+ continue;
313
+ }
314
+ const mismatch = datasetDigestMismatch({ tableId: ref.tableId, tableVersion: ref.tableVersion, sha256 }, canonicalHash(document));
315
+ if (mismatch !== undefined)
316
+ mismatched.push(mismatch);
317
+ }
318
+ if (missing.length > 0) {
319
+ return { kind: 'refused', reason: 'table_missing', missing, stale: [] };
320
+ }
321
+ if (mismatched.length > 0) {
322
+ return { kind: 'refused', reason: 'table_digest_mismatch', tables: mismatched };
323
+ }
324
+ // Every pin that needed a date was refused above when the device supplied none, so an absent
325
+ // date here means every bound copy is behavior-bound and windowless: there is no window left to
326
+ // ask `covers` about, and passing it an unparsed range would report those copies stale.
327
+ if (request.recordDate === undefined)
328
+ return { kind: 'admitted' };
329
+ const available = request.tables.map((table) => ({
330
+ artifactId: table.tableId,
331
+ artifactVersion: table.tableVersion,
332
+ sha256: canonicalHash(table),
333
+ ...(table.binding === undefined ? {} : { binding: table.binding }),
334
+ ...(table.effectiveFrom === undefined ? {} : { effectiveFrom: table.effectiveFrom }),
335
+ ...(table.effectiveTo === undefined ? {} : { effectiveTo: table.effectiveTo }),
336
+ }));
337
+ // Every required pin was matched to a held document whose digest equals the pin above, so the
338
+ // requirement's digest is the pin's: `checkReadiness` now answers only the window question.
339
+ const requirements = bound.map(({ ref, sha256 }) => ({
340
+ artifactId: ref.tableId,
341
+ artifactVersion: ref.tableVersion,
342
+ sha256,
343
+ }));
344
+ const report = checkReadiness(requirements, available, {
345
+ from: request.recordDate,
346
+ to: request.recordDate,
347
+ });
348
+ if (report.missing.length > 0) {
349
+ return {
350
+ kind: 'refused',
351
+ reason: 'table_missing',
352
+ missing: report.missing,
353
+ stale: report.stale,
354
+ };
355
+ }
356
+ if (report.stale.length > 0) {
357
+ return { kind: 'refused', reason: 'table_stale', missing: report.missing, stale: report.stale };
358
+ }
359
+ return { kind: 'admitted' };
360
+ }
361
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/cache/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EACb,sBAAsB,EACtB,gBAAgB,EAChB,WAAW,GACZ,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACtE,OAAO,EAAE,wBAAwB,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAClF,+FAA+F;AAC/F,sEAAsE;AACtE,OAAO,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAC;AAE5D,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAEhD,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAKrD;;;;;;;GAOG;AACH,cAAc,qBAAqB,CAAC;AAoEpC;;;GAGG;AACH,MAAM,UAAU,kBAAkB,CAAC,QAAuB,EAAE,YAAoB;IAC9E,OAAO,gBAAgB,CAAC,QAAQ,CAAC,KAAK,CAAC,KAAK,YAAY,CAAC;AAC3D,CAAC;AAED;;;;;GAKG;AACH,SAAS,KAAK,CAAC,IAAY;IACzB,IAAI,CAAC;QACH,MAAM,IAAI,GAAG,cAAc,CAAC,IAAI,CAAC,CAAC;QAClC,OAAO,aAAa,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAA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\n canonicalHash,\n canonicalizeRestricted,\n sha256HexOfBytes,\n utf8BytesOf,\n} from '../canonical/jcs.js';\nimport { daysFromCivil, parsePlainDate } from '../expr/plain-date.js';\nimport { declaredFieldExpressions, ruleExpressions } from '../graph/read-walk.js';\n// The comparison and its mismatch shape are the lookup seam's, so this door and the evaluation\n// path cannot disagree about what a mismatch is or how it is spelled.\nimport { datasetDigestMismatch } from '../lookup/digest.js';\nimport type { DatasetDigestMismatch } from '../lookup/digest.js';\nimport { AxiomError } from '../model/errors.js';\nimport type { CompiledSchema, DatasetRef } from '../model/schema.js';\nimport { DATASET_BUILTINS } from '../model/types.js';\nimport type { ExprNode, LookupTableDocument, TableBinding } from '../model/types.js';\n\nexport type { DatasetDigestMismatch } from '../lookup/digest.js';\n\n/**\n * The store a host persists offline bytes in, and the reference implementation tests use.\n *\n * Admission answers *whether* a device's bytes may be evaluated. This door also states *where*\n * those bytes and the device's drafts, reports and queued submissions live, so a host that\n * implements the contract serves `admitOfflineArtifact` from the same store it writes to. See\n * `./offline/index.ts` for the two operations that must be atomic.\n */\nexport * from '../offline/index.js';\n\n/**\n * Pure offline readiness, `spec/semantics/canonical-v1.md` section 5.\n *\n * This module exposes data and two total functions. It stores nothing, signs nothing\n * and reads no clock: the caller supplies the artifact bytes, the hashes it holds and\n * the date range it needs, so the answer is reproducible and testable. The store contract\n * beside them says where a host keeps those bytes between sessions; it too reads no clock,\n * and its reference implementation holds only what a caller put in it.\n */\n\n/**\n * A required artifact: the identity and version the evaluation needs, and the digest the\n * match is filed under.\n *\n * `sha256` is part of the match key beside `artifactId` and `artifactVersion`, so a\n * requirement states the copy it is asking for. `admitOfflineArtifact` builds each requirement\n * from the artifact's own pin and verifies the held document against it before this fold runs,\n * so on that path the digest is an integrity check of the table's content, not only an identity\n * check.\n */\nexport interface ArtifactRequirement {\n readonly artifactId: string;\n readonly artifactVersion: number;\n readonly sha256: string;\n}\n\n/**\n * An artifact the caller holds. A data-bound artifact declares its half-open\n * `[effectiveFrom, effectiveTo)` window; a behavior artifact pins to\n * the case and declares none.\n */\nexport interface AvailableArtifact {\n readonly artifactId: string;\n readonly artifactVersion: number;\n readonly sha256: string;\n /**\n * The table's clock binding, when the caller knows it. A `data` artifact must carry a\n * window to be verifiable; a `behavior` artifact pins to the case and carries none.\n */\n readonly binding?: 'behavior' | 'data';\n readonly effectiveFrom?: string;\n readonly effectiveTo?: string;\n}\n\n/** The inclusive date range an evaluation is being prepared for. */\nexport interface RequiredDateRange {\n readonly from: string;\n readonly to: string;\n}\n\n/**\n * Every requirement appears in exactly one bucket. `missing` also\n * holds a requirement whose held copy cannot be verified, because an unverifiable\n * artifact must not be assumed present.\n */\nexport interface ReadinessReport {\n readonly available: readonly ArtifactRequirement[];\n readonly missing: readonly ArtifactRequirement[];\n readonly stale: readonly ArtifactRequirement[];\n}\n\n/** The artifact bytes a caller is asking about. */\nexport interface ArtifactBytes {\n readonly bytes: Uint8Array;\n}\n\n/**\n * Whether an artifact's bytes hash to the expected digest. A mismatch\n * returns `false` rather than throwing, and the artifact is never mutated.\n */\nexport function verifyArtifactHash(artifact: ArtifactBytes, expectedHash: string): boolean {\n return sha256HexOfBytes(artifact.bytes) === expectedHash;\n}\n\n/**\n * Days since the epoch for a plain date, or `undefined` when the text is not one. A\n * malformed date makes an artifact's window unverifiable, which `covers` reports as\n * not covered rather than assuming it; the parse error carries nothing further the\n * caller can act on.\n */\nfunction dayOf(text: string): number | undefined {\n try {\n const date = parsePlainDate(text);\n return daysFromCivil(date.year, date.month, date.day);\n } catch (error) {\n // Only a refusal says the text is not a date; anything else is a defect that must\n // not be reported as an unverifiable artifact window.\n if (!(error instanceof AxiomError)) throw error;\n return undefined;\n }\n}\n\n/**\n * The identity a requirement and a held artifact are matched on. The three fields are\n * the whole match, so one map lookup replaces a linear scan per requirement.\n */\nfunction artifactKey(artifact: ArtifactRequirement): string {\n return `${artifact.artifactId}\\u0000${String(artifact.artifactVersion)}\\u0000${artifact.sha256}`;\n}\n\n/** The required range, parsed once rather than once per requirement. */\ninterface DayRange {\n readonly from: number | undefined;\n readonly to: number | undefined;\n}\n\n/** The members a coverage question reads: the clock binding and, for a data table, its window. */\ninterface ClockShape {\n readonly binding?: TableBinding | undefined;\n readonly effectiveFrom?: string | undefined;\n readonly effectiveTo?: string | undefined;\n}\n\n/**\n * Whether a copy needs no date at all to prove its coverage.\n *\n * Exactly one shape does: a copy that pins to the case and declares neither bound\n * (`DATA-2.1.2`). A declared window is read whatever the binding claims, because a copy whose\n * stated bounds disagree with its binding is windowed in fact, and choosing its cheaper half\n * would admit a window no date was tested against.\n */\nfunction isDateFree(copy: ClockShape): boolean {\n return (\n copy.binding === 'behavior' &&\n copy.effectiveFrom === undefined &&\n copy.effectiveTo === undefined\n );\n}\n\n/**\n * Whether a held artifact's window covers the required range.\n *\n * A copy that pins to the case and declares no window covers every date — including a range the\n * caller could not parse. That branch precedes the range guard because a\n * table which never reads a date must not become unverifiable when the date it ignores is\n * malformed. A data-bound artifact versions independently, so its half-open window is part of\n * what it must carry; without one its coverage cannot be verified and it is stale rather than\n * assumed to cover everything. An artifact whose clock binding the caller did not state is not\n * read as behavior-bound when it carries no window: that would let a data table which lost its\n * window cover every date.\n */\nfunction covers(held: AvailableArtifact, range: DayRange): boolean {\n if (isDateFree(held)) return true;\n const { from, to } = range;\n if (from === undefined || to === undefined) return false;\n // A range whose end precedes its start is not a range any window can cover.\n if (from > to) return false;\n const heldFrom = held.effectiveFrom === undefined ? undefined : dayOf(held.effectiveFrom);\n const heldTo = held.effectiveTo === undefined ? undefined : dayOf(held.effectiveTo);\n if (heldFrom === undefined || heldTo === undefined) return false;\n return heldFrom <= from && to < heldTo;\n}\n\n/**\n * Reports which required artifacts are available, missing or stale for a required date\n * range. A requirement is matched on its identity, version and digest together, so a held\n * copy filed at the same id and version but under another digest is missing, not available;\n * a table whose window does not cover the range is stale, not missing. No clock is read.\n *\n * This function checks the digest the caller states. `admitOfflineArtifact` states the digest\n * the artifact pins and verifies the held document against it first, so a same-version\n * republished table is a `table_digest_mismatch` refusal there rather than a stale or missing\n * entry here.\n */\nexport function checkReadiness(\n required: readonly ArtifactRequirement[],\n availableHashes: readonly AvailableArtifact[],\n requiredDateRange: RequiredDateRange,\n): ReadinessReport {\n const held = new Map<string, AvailableArtifact>();\n for (const artifact of availableHashes) {\n const key = artifactKey(artifact);\n // The first declaration wins, as the linear scan this replaces did.\n if (!held.has(key)) held.set(key, artifact);\n }\n const range: DayRange = {\n from: dayOf(requiredDateRange.from),\n to: dayOf(requiredDateRange.to),\n };\n const available: ArtifactRequirement[] = [];\n const missing: ArtifactRequirement[] = [];\n const stale: ArtifactRequirement[] = [];\n for (const requirement of required) {\n const match = held.get(artifactKey(requirement));\n if (match === undefined) {\n missing.push(requirement);\n continue;\n }\n if (!covers(match, range)) {\n stale.push(requirement);\n continue;\n }\n available.push(requirement);\n }\n return { available, missing, stale };\n}\n\n/** What a device holds when it asks whether it may evaluate a compiled artifact offline. */\nexport interface OfflineArtifactRequest {\n /** The parsed artifact document, which is also the value the digest covers. */\n readonly artifact: CompiledSchema;\n /**\n * The digest the artifact's canonical restricted-JSON text must hash to.\n *\n * The digest is over the canonical text rather than the file's bytes because a client\n * rehydrates the document from a module loader that keeps no bytes: the same artifact arrives\n * through Vite, Metro and `readFile` without sharing a byte sequence, and all three must reach\n * the same admission answer.\n */\n readonly expectedSha256: string;\n /**\n * The table documents this device holds. Their identity, version, canonical digest and\n * effective window are what the gate checks: the digest is recomputed from the document here\n * and compared with the one the artifact pins, so a republished table under the same version\n * is refused rather than resolved.\n */\n readonly tables: readonly LookupTableDocument[];\n /**\n * The record date the evaluation is being prepared for, when the record states one.\n *\n * Demanded only where a pinned copy's coverage reads it: a data-bound table resolves against its\n * half-open window (`DATA-2.1.4`), and a copy that states a window is tested against it. A\n * behavior-bound copy declares no window and covers every date (`DATA-2.1.2`), so a device that\n * holds only those is admitted without a date rather than inventing one it does not have.\n */\n readonly recordDate: string | undefined;\n}\n\n/** A pin that names a table version but carries no digest, so its bytes cannot be verified. */\nexport interface UnboundDatasetPin {\n readonly tableId: string;\n readonly tableVersion: number;\n}\n\n/** Why a device may not evaluate an artifact offline, with the artifacts it names. */\nexport type OfflineRefusal =\n | {\n readonly kind: 'refused';\n readonly reason: 'artifact_hash';\n readonly expected: string;\n readonly actual: string;\n }\n | {\n readonly kind: 'refused';\n /**\n * A pinned table whose coverage needs a record date and the device supplied none.\n * `tables` names those tables only: a behavior-bound copy that declares no window needs no\n * date, and a pin the device holds no copy of is named because its binding cannot be read.\n */\n readonly reason: 'no_record_date';\n readonly tables: readonly string[];\n }\n | {\n readonly kind: 'refused';\n /** A pin that names a version but no bytes: the table cannot be verified at all. */\n readonly reason: 'table_digest_missing';\n readonly tables: readonly UnboundDatasetPin[];\n }\n | {\n readonly kind: 'refused';\n /** A held document at the pinned version whose canonical digest differs from the pin. */\n readonly reason: 'table_digest_mismatch';\n readonly tables: readonly DatasetDigestMismatch[];\n }\n | {\n readonly kind: 'refused';\n readonly reason: 'table_missing' | 'table_stale';\n readonly missing: readonly ArtifactRequirement[];\n readonly stale: readonly ArtifactRequirement[];\n };\n\n/** The admission answer: evaluate, or the refusal a device renders instead of evaluating. */\nexport type OfflineAdmission = { readonly kind: 'admitted' } | OfflineRefusal;\n\n/**\n * The identity a held copy is filed under: a device caches versions side by side, and the\n * digest of the version the artifact pins is not the digest of the newest one beside it.\n */\nfunction tableVersionKey(tableId: string, tableVersion: number): string {\n return `${tableId}\\u0000${String(tableVersion)}`;\n}\n\n/**\n * The first held document at each `(tableId, tableVersion)`, matching `checkReadiness`'s\n * first-declaration-wins rule.\n *\n * Versioning is why this is not keyed by `tableId` alone: an installation that holds v1 and the\n * v2 it downloaded later must still admit an artifact that pins v1.\n */\nfunction heldDocuments(\n tables: readonly LookupTableDocument[],\n): ReadonlyMap<string, LookupTableDocument> {\n const documents = new Map<string, LookupTableDocument>();\n for (const table of tables) {\n const key = tableVersionKey(table.tableId, table.tableVersion);\n if (!documents.has(key)) documents.set(key, table);\n }\n return documents;\n}\n\n/**\n * The tables an artifact's rules and declared field expressions can reach. A client artifact's\n * rule reachability is its client-tier rules: every server-tier rule became a deferred stub, and\n * even an artifact that still carries an authored server expression never resolves a table for it\n * on the device. A server artifact runs every rule it carries, so every rule counts. A declared\n * field's own expressions (`rowsFrom`, option availability, reason parameters and alternatives)\n * run on the device in both tiers, so tables they read are reachable in both tiers.\n *\n * Walking `ruleExpressions` and `declaredFieldExpressions` uses the same slot walk the compiler\n * and submission door read.\n */\nfunction readableTables(artifact: CompiledSchema): ReadonlySet<string> {\n const clientOnly = artifact.target === 'client';\n const tables = new Set<string>();\n for (const rule of artifact.rules ?? []) {\n if (clientOnly && rule.evaluateOn !== 'client') continue;\n for (const node of ruleExpressions(rule)) collectTables(node, tables);\n }\n for (const slot of declaredFieldExpressions(artifact.fields)) {\n collectTables(slot.node, tables);\n }\n return tables;\n}\n\n/** Every table id a dataset built-in in this expression names, into `into`. */\nfunction collectTables(node: ExprNode, into: Set<string>): void {\n switch (node.kind) {\n case 'literal':\n case 'path':\n return;\n case 'list':\n for (const item of node.items) collectTables(item, into);\n return;\n case 'comprehension':\n collectTables(node.source, into);\n if (node.valueExpr !== undefined) collectTables(node.valueExpr, into);\n if (node.predicate !== undefined) collectTables(node.predicate, into);\n return;\n case 'call': {\n if (DATASET_BUILTINS.has(node.op)) {\n const [table] = node.args;\n if (table?.kind === 'path') into.add(table.path);\n }\n for (const arg of node.args) collectTables(arg, into);\n return;\n }\n default:\n for (const arg of node.args) collectTables(arg, into);\n }\n}\n\n/**\n * The pins a device must satisfy: only the tables the artifact's own rules or declared field\n * expressions can reach.\n *\n * A pin no reachable rule or declared field expression can read is not a fact the device must\n * carry: it cannot affect a decision, and requiring it would make an offline session depend on\n * data no evaluation can use (`DATA-4.1.6`). A client artifact narrows rule reachability to its\n * client-tier rules, so a table only a server rule reads is not a device requirement either.\n */\nfunction requiredPins(artifact: CompiledSchema): readonly DatasetRef[] {\n const pinned = artifact.datasets ?? [];\n const readable = readableTables(artifact);\n return pinned.filter((ref) => readable.has(ref.tableId));\n}\n\n/**\n * One offline admission decision, `DR-AX-05`.\n *\n * Four questions are answered before any rule reads a value: does the artifact's canonical text\n * hash to the digest the device was told to expect, does the artifact pin the bytes of every\n * table the evaluation needs, does the device hold those exact bytes at the pinned version, and\n * do those tables' effective windows cover the record date. A \"no\" to any of them is a refusal a\n * device renders, never a fallback to a neighbouring table or a plausible default.\n *\n * The table half checks **identity, version, canonical digest and effective window**. A\n * `DatasetRef` carries the restricted-JCS SHA-256 of the document it pins, computed by the same\n * `canonicalHash` the store records as a resolution's `tableSha256` (`DATA-4.1.2`). This gate\n * recomputes that digest over the held document and compares it, so a document republished under\n * the pinned version is refused with both digests rather than resolved. A pin that carries no\n * digest is refused too: a version is a name, and a name is not the bytes the decision was made\n * on.\n *\n * A record date is a question about a copy, not a count of pins. A behavior-bound table pins to\n * the case and declares no window (`DATA-2.1.2`), so a device holding only those is admitted with\n * no date at all. A data-bound table, or any copy that states a window whatever its binding\n * claims, needs the date to test its half-open window; with none, the gate refuses\n * `no_record_date` and names exactly those tables. A pin the device holds no copy of is in that\n * set too: its binding cannot be read, and the date-free answer is not assumed for bytes the gate\n * cannot see.\n *\n * The artifact digest is `verifyArtifactHash` over the artifact's canonical text:\n * `verifyArtifactHash` is a byte check, so the caller's value is made into the one canonical\n * byte sequence rather than each loader inventing its own spelling.\n */\nexport function admitOfflineArtifact(request: OfflineArtifactRequest): OfflineAdmission {\n const bytes = utf8BytesOf(canonicalizeRestricted(request.artifact));\n if (!verifyArtifactHash({ bytes }, request.expectedSha256)) {\n return {\n kind: 'refused',\n reason: 'artifact_hash',\n expected: request.expectedSha256,\n actual: sha256HexOfBytes(bytes),\n };\n }\n const required = requiredPins(request.artifact);\n if (required.length === 0) return { kind: 'admitted' };\n const held = heldDocuments(request.tables);\n // A date is only a fact this gate can demand where a copy's coverage would read it. A held copy\n // that pins to the case and declares no window covers every date, so it needs none; every other\n // pin does, and `tables` names those rather than the whole pin list. A pin with no held copy\n // cannot show its binding, so it is counted as date-dependent: the gate does not assume the\n // cheaper answer for a document it cannot read.\n if (request.recordDate === undefined) {\n const dateDependent = required.filter((ref) => {\n const document = held.get(tableVersionKey(ref.tableId, ref.tableVersion));\n return document === undefined || !isDateFree(document);\n });\n if (dateDependent.length > 0) {\n return {\n kind: 'refused',\n reason: 'no_record_date',\n tables: dateDependent.map((ref) => ref.tableId),\n };\n }\n }\n // A pin that carries no digest is a defect of the artifact, not of what this device happens to\n // hold, so it is refused before any lookup: the table's bytes could never be verified. The\n // bound list is the narrowed form, so the checks below never cast.\n const unbound: UnboundDatasetPin[] = [];\n const bound: { readonly ref: DatasetRef; readonly sha256: string }[] = [];\n for (const ref of required) {\n if (typeof ref.sha256 !== 'string') {\n unbound.push({ tableId: ref.tableId, tableVersion: ref.tableVersion });\n continue;\n }\n bound.push({ ref, sha256: ref.sha256 });\n }\n if (unbound.length > 0) {\n return { kind: 'refused', reason: 'table_digest_missing', tables: unbound };\n }\n const mismatched: DatasetDigestMismatch[] = [];\n const missing: ArtifactRequirement[] = [];\n for (const { ref, sha256 } of bound) {\n const document = held.get(tableVersionKey(ref.tableId, ref.tableVersion));\n if (document === undefined) {\n // No bytes to compare: the table is missing, not unverifiable.\n missing.push({\n artifactId: ref.tableId,\n artifactVersion: ref.tableVersion,\n sha256,\n });\n continue;\n }\n const mismatch = datasetDigestMismatch(\n { tableId: ref.tableId, tableVersion: ref.tableVersion, sha256 },\n canonicalHash(document),\n );\n if (mismatch !== undefined) mismatched.push(mismatch);\n }\n if (missing.length > 0) {\n return { kind: 'refused', reason: 'table_missing', missing, stale: [] };\n }\n if (mismatched.length > 0) {\n return { kind: 'refused', reason: 'table_digest_mismatch', tables: mismatched };\n }\n // Every pin that needed a date was refused above when the device supplied none, so an absent\n // date here means every bound copy is behavior-bound and windowless: there is no window left to\n // ask `covers` about, and passing it an unparsed range would report those copies stale.\n if (request.recordDate === undefined) return { kind: 'admitted' };\n const available: readonly AvailableArtifact[] = request.tables.map((table) => ({\n artifactId: table.tableId,\n artifactVersion: table.tableVersion,\n sha256: canonicalHash(table),\n ...(table.binding === undefined ? {} : { binding: table.binding }),\n ...(table.effectiveFrom === undefined ? {} : { effectiveFrom: table.effectiveFrom }),\n ...(table.effectiveTo === undefined ? {} : { effectiveTo: table.effectiveTo }),\n }));\n // Every required pin was matched to a held document whose digest equals the pin above, so the\n // requirement's digest is the pin's: `checkReadiness` now answers only the window question.\n const requirements: readonly ArtifactRequirement[] = bound.map(({ ref, sha256 }) => ({\n artifactId: ref.tableId,\n artifactVersion: ref.tableVersion,\n sha256,\n }));\n const report = checkReadiness(requirements, available, {\n from: request.recordDate,\n to: request.recordDate,\n });\n if (report.missing.length > 0) {\n return {\n kind: 'refused',\n reason: 'table_missing',\n missing: report.missing,\n stale: report.stale,\n };\n }\n if (report.stale.length > 0) {\n return { kind: 'refused', reason: 'table_stale', missing: report.missing, stale: report.stale };\n }\n return { kind: 'admitted' };\n}\n"]}