@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,38 @@
1
+ import type { FieldAccess, FieldRef, WireValue } from '../../model/types.js';
2
+ import type { Presence } from '../expr/value.js';
3
+ /**
4
+ * What one field's value is, as a caller may observe it.
5
+ *
6
+ * The union separates a value the device may not see from one the record does not hold:
7
+ * `absent` means nothing was recorded, `withheld` means something was recorded and this
8
+ * device may not read it. Collapsing them would let a caller conclude "nothing recorded"
9
+ * from an access decision, and would let a masked value be reported as missing.
10
+ */
11
+ export type ValueState = {
12
+ readonly kind: 'value';
13
+ readonly value: WireValue;
14
+ } | {
15
+ readonly kind: 'absent';
16
+ } | {
17
+ readonly kind: 'withheld';
18
+ readonly reason: WithheldReason;
19
+ };
20
+ /** Why a value the record holds is not delivered to this device. */
21
+ export type WithheldReason = 'masked' | 'hidden' | 'write_only' | 'redacted';
22
+ /**
23
+ * The only value-state classifier, `[ACCESS-1.3.1]`–`[ACCESS-1.3.4]`.
24
+ *
25
+ * Presence is read as metadata and only then is the value classified, so a masked or hidden
26
+ * field that is present reports present while its value stays withheld. `null` is a value
27
+ * (the authored empty value), never an absence. A stored `write_only` value is delivered
28
+ * only once this session wrote it; the session set is keyed by `fieldKey`, so the integer
29
+ * row `1` and the text row `"1"` cannot unlock one another.
30
+ *
31
+ * A `write_only` binding with no recorded value is `absent`, not `withheld`: the record holds
32
+ * nothing there, so a host may offer the control that fills it, which is the one arm of
33
+ * `write_only` a reader can act on. The access state names the withholding when the record
34
+ * does hold a value, so a stored `write_only` binding beside a server redaction states the
35
+ * access the host granted rather than a reason the device cannot act on.
36
+ */
37
+ export declare function classifyValue(presence: Presence, access: FieldAccess, sessionWrites: ReadonlySet<string>, raw: WireValue | undefined, ref: FieldRef): ValueState;
38
+ //# sourceMappingURL=value-state.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"value-state.d.ts","sourceRoot":"","sources":["../../../src/eval/state/value-state.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAC7E,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAEjD;;;;;;;GAOG;AACH,MAAM,MAAM,UAAU,GAClB;IAAE,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,SAAS,CAAA;CAAE,GACrD;IAAE,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAA;CAAE,GAC3B;IAAE,QAAQ,CAAC,IAAI,EAAE,UAAU,CAAC;IAAC,QAAQ,CAAC,MAAM,EAAE,cAAc,CAAA;CAAE,CAAC;AAEnE,oEAAoE;AACpE,MAAM,MAAM,cAAc,GAAG,QAAQ,GAAG,QAAQ,GAAG,YAAY,GAAG,UAAU,CAAC;AAE7E;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,aAAa,CAC3B,QAAQ,EAAE,QAAQ,EAClB,MAAM,EAAE,WAAW,EACnB,aAAa,EAAE,WAAW,CAAC,MAAM,CAAC,EAClC,GAAG,EAAE,SAAS,GAAG,SAAS,EAC1B,GAAG,EAAE,QAAQ,GACZ,UAAU,CAMZ"}
@@ -0,0 +1,52 @@
1
+ import { fieldKey } from '../access/projection.js';
2
+ /**
3
+ * The only value-state classifier, `[ACCESS-1.3.1]`–`[ACCESS-1.3.4]`.
4
+ *
5
+ * Presence is read as metadata and only then is the value classified, so a masked or hidden
6
+ * field that is present reports present while its value stays withheld. `null` is a value
7
+ * (the authored empty value), never an absence. A stored `write_only` value is delivered
8
+ * only once this session wrote it; the session set is keyed by `fieldKey`, so the integer
9
+ * row `1` and the text row `"1"` cannot unlock one another.
10
+ *
11
+ * A `write_only` binding with no recorded value is `absent`, not `withheld`: the record holds
12
+ * nothing there, so a host may offer the control that fills it, which is the one arm of
13
+ * `write_only` a reader can act on. The access state names the withholding when the record
14
+ * does hold a value, so a stored `write_only` binding beside a server redaction states the
15
+ * access the host granted rather than a reason the device cannot act on.
16
+ */
17
+ export function classifyValue(presence, access, sessionWrites, raw, ref) {
18
+ const withheld = withheldReason(presence, access, sessionWrites.has(fieldKey(ref)));
19
+ if (withheld !== undefined)
20
+ return { kind: 'withheld', reason: withheld };
21
+ if (presence === 'absent' || presence === 'undetermined')
22
+ return { kind: 'absent' };
23
+ if (raw === undefined)
24
+ return { kind: 'absent' };
25
+ return { kind: 'value', value: raw };
26
+ }
27
+ /** The access state that withholds a value, before the session-write question is asked. */
28
+ function withheldReason(presence, access, sessionWritten) {
29
+ switch (access) {
30
+ case 'masked':
31
+ return 'masked';
32
+ case 'write_only':
33
+ // The session's own write reads back; a recorded value else is the record's own secret.
34
+ // Absence and the authored `null` are genuinely empty, so they are the control's to fill;
35
+ // an undetermined presence is not an empty one and stays withheld.
36
+ if (sessionWritten)
37
+ return undefined;
38
+ return presence === 'absent' || presence === 'null' ? undefined : 'write_only';
39
+ case 'hidden':
40
+ // A reference whose own declaration is deliverable can still be reported `hidden` here
41
+ // because a container or the server withheld the value; a redaction names its own cause.
42
+ return presence === 'redacted' ? 'redacted' : 'hidden';
43
+ case 'read_write':
44
+ case 'read_only':
45
+ if (presence === 'redacted')
46
+ return 'redacted';
47
+ // A container above this field may withhold it even though the field's own access
48
+ // permits a read; the caller resolves that by passing `hidden` for the reference.
49
+ return presence === 'unreadable' ? 'hidden' : undefined;
50
+ }
51
+ }
52
+ //# sourceMappingURL=value-state.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"value-state.js","sourceRoot":"","sources":["../../../src/eval/state/value-state.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AAoBnD;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,aAAa,CAC3B,QAAkB,EAClB,MAAmB,EACnB,aAAkC,EAClC,GAA0B,EAC1B,GAAa;IAEb,MAAM,QAAQ,GAAG,cAAc,CAAC,QAAQ,EAAE,MAAM,EAAE,aAAa,CAAC,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;IACpF,IAAI,QAAQ,KAAK,SAAS;QAAE,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC;IAC1E,IAAI,QAAQ,KAAK,QAAQ,IAAI,QAAQ,KAAK,cAAc;QAAE,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC;IACpF,IAAI,GAAG,KAAK,SAAS;QAAE,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC;IACjD,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC;AACvC,CAAC;AAED,2FAA2F;AAC3F,SAAS,cAAc,CACrB,QAAkB,EAClB,MAAmB,EACnB,cAAuB;IAEvB,QAAQ,MAAM,EAAE,CAAC;QACf,KAAK,QAAQ;YACX,OAAO,QAAQ,CAAC;QAClB,KAAK,YAAY;YACf,wFAAwF;YACxF,0FAA0F;YAC1F,mEAAmE;YACnE,IAAI,cAAc;gBAAE,OAAO,SAAS,CAAC;YACrC,OAAO,QAAQ,KAAK,QAAQ,IAAI,QAAQ,KAAK,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,YAAY,CAAC;QACjF,KAAK,QAAQ;YACX,uFAAuF;YACvF,yFAAyF;YACzF,OAAO,QAAQ,KAAK,UAAU,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,QAAQ,CAAC;QACzD,KAAK,YAAY,CAAC;QAClB,KAAK,WAAW;YACd,IAAI,QAAQ,KAAK,UAAU;gBAAE,OAAO,UAAU,CAAC;YAC/C,kFAAkF;YAClF,kFAAkF;YAClF,OAAO,QAAQ,KAAK,YAAY,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,SAAS,CAAC;IAC5D,CAAC;AACH,CAAC","sourcesContent":["import { fieldKey } from '../access/projection.js';\nimport type { FieldAccess, FieldRef, WireValue } from '../../model/types.js';\nimport type { Presence } from '../expr/value.js';\n\n/**\n * What one field's value is, as a caller may observe it.\n *\n * The union separates a value the device may not see from one the record does not hold:\n * `absent` means nothing was recorded, `withheld` means something was recorded and this\n * device may not read it. Collapsing them would let a caller conclude \"nothing recorded\"\n * from an access decision, and would let a masked value be reported as missing.\n */\nexport type ValueState =\n | { readonly kind: 'value'; readonly value: WireValue }\n | { readonly kind: 'absent' }\n | { readonly kind: 'withheld'; readonly reason: WithheldReason };\n\n/** Why a value the record holds is not delivered to this device. */\nexport type WithheldReason = 'masked' | 'hidden' | 'write_only' | 'redacted';\n\n/**\n * The only value-state classifier, `[ACCESS-1.3.1]`–`[ACCESS-1.3.4]`.\n *\n * Presence is read as metadata and only then is the value classified, so a masked or hidden\n * field that is present reports present while its value stays withheld. `null` is a value\n * (the authored empty value), never an absence. A stored `write_only` value is delivered\n * only once this session wrote it; the session set is keyed by `fieldKey`, so the integer\n * row `1` and the text row `\"1\"` cannot unlock one another.\n *\n * A `write_only` binding with no recorded value is `absent`, not `withheld`: the record holds\n * nothing there, so a host may offer the control that fills it, which is the one arm of\n * `write_only` a reader can act on. The access state names the withholding when the record\n * does hold a value, so a stored `write_only` binding beside a server redaction states the\n * access the host granted rather than a reason the device cannot act on.\n */\nexport function classifyValue(\n presence: Presence,\n access: FieldAccess,\n sessionWrites: ReadonlySet<string>,\n raw: WireValue | undefined,\n ref: FieldRef,\n): ValueState {\n const withheld = withheldReason(presence, access, sessionWrites.has(fieldKey(ref)));\n if (withheld !== undefined) return { kind: 'withheld', reason: withheld };\n if (presence === 'absent' || presence === 'undetermined') return { kind: 'absent' };\n if (raw === undefined) return { kind: 'absent' };\n return { kind: 'value', value: raw };\n}\n\n/** The access state that withholds a value, before the session-write question is asked. */\nfunction withheldReason(\n presence: Presence,\n access: FieldAccess,\n sessionWritten: boolean,\n): WithheldReason | undefined {\n switch (access) {\n case 'masked':\n return 'masked';\n case 'write_only':\n // The session's own write reads back; a recorded value else is the record's own secret.\n // Absence and the authored `null` are genuinely empty, so they are the control's to fill;\n // an undetermined presence is not an empty one and stays withheld.\n if (sessionWritten) return undefined;\n return presence === 'absent' || presence === 'null' ? undefined : 'write_only';\n case 'hidden':\n // A reference whose own declaration is deliverable can still be reported `hidden` here\n // because a container or the server withheld the value; a redaction names its own cause.\n return presence === 'redacted' ? 'redacted' : 'hidden';\n case 'read_write':\n case 'read_only':\n if (presence === 'redacted') return 'redacted';\n // A container above this field may withhold it even though the field's own access\n // permits a read; the caller resolves that by passing `hidden` for the reference.\n return presence === 'unreadable' ? 'hidden' : undefined;\n }\n}\n"]}
@@ -0,0 +1,50 @@
1
+ import type { EvaluationEnv, EvaluationInput, SubmissionAuthority } from '../../model/access.js';
2
+ import type { CompiledSchema } from '../../model/schema.js';
3
+ import type { WireValue } from '../../model/types.js';
4
+ import type { AccessWindow } from '../access/window.js';
5
+ import type { FormStateOptions } from '../state/options.js';
6
+ import type { SubmissionTrust } from './authority.js';
7
+ import type { WriteAuthority } from './writes.js';
8
+ import type { SubmissionRefusal } from './refusals.js';
9
+ /**
10
+ * One admission shared by both submission doors.
11
+ *
12
+ * `evaluateSubmission` and `submissionVerdict` differ in what they answer, not in what they
13
+ * trust. This module reads the body, the authority and the stance exactly once, resolves the
14
+ * access window, merges the server's held record beneath the body's answers, and refuses claims
15
+ * the stance does not permit — before any rule runs. The two doors then build their own answer
16
+ * from the admitted input, so a body cannot be admissible at one door and refused at the other.
17
+ */
18
+ /** What the submission boundary admitted: the evaluated input, or the reason it refused. */
19
+ interface AdmittedSubmission {
20
+ readonly input: EvaluationInput;
21
+ readonly env: EvaluationEnv;
22
+ readonly trust: SubmissionTrust;
23
+ readonly writeAuthority?: WriteAuthority;
24
+ readonly accessWindow: AccessWindow;
25
+ /** The record the *body* stated, before the server's held values were merged beneath it. */
26
+ readonly bodyValues: Readonly<Record<string, WireValue>>;
27
+ }
28
+ /** The boundary's answer: an admitted document, or one refusal envelope for every cause. */
29
+ export type Admission = {
30
+ readonly ok: true;
31
+ readonly value: AdmittedSubmission;
32
+ } | {
33
+ readonly ok: false;
34
+ readonly refusal: SubmissionRefusal;
35
+ };
36
+ /**
37
+ * Reads and validates one submission.
38
+ *
39
+ * `bodyAuthorsHostFacts` is false for an untrusted body (the host-only members are refused at
40
+ * `$.<member>`) and true for a `trusted-host` document the caller constructed (its host-only
41
+ * members are then its own, and the authority may not repeat them).
42
+ *
43
+ * The boundary is the only throw either door turns into data. The evaluation after it runs
44
+ * outside the catch, so an artifact whose invariants are broken still throws: that is a
45
+ * programmer error, and reporting it as a refusal of the caller's body would send a host
46
+ * looking for a fault in the record.
47
+ */
48
+ export declare function admitSubmission(compiled: CompiledSchema, body: unknown, env: unknown, authority: SubmissionAuthority, trust: SubmissionTrust, options: FormStateOptions, bodyAuthorsHostFacts: boolean): Admission;
49
+ export {};
50
+ //# sourceMappingURL=admission.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"admission.d.ts","sourceRoot":"","sources":["../../../src/eval/submission/admission.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,aAAa,EAAE,eAAe,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AACjG,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAEtD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAExD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAG5D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACtD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAClD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAEvD;;;;;;;;GAQG;AAEH,4FAA4F;AAC5F,UAAU,kBAAkB;IAC1B,QAAQ,CAAC,KAAK,EAAE,eAAe,CAAC;IAChC,QAAQ,CAAC,GAAG,EAAE,aAAa,CAAC;IAC5B,QAAQ,CAAC,KAAK,EAAE,eAAe,CAAC;IAChC,QAAQ,CAAC,cAAc,CAAC,EAAE,cAAc,CAAC;IACzC,QAAQ,CAAC,YAAY,EAAE,YAAY,CAAC;IACpC,4FAA4F;IAC5F,QAAQ,CAAC,UAAU,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC,CAAC;CAC1D;AAED,4FAA4F;AAC5F,MAAM,MAAM,SAAS,GACjB;IAAE,QAAQ,CAAC,EAAE,EAAE,IAAI,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,kBAAkB,CAAA;CAAE,GACzD;IAAE,QAAQ,CAAC,EAAE,EAAE,KAAK,CAAC;IAAC,QAAQ,CAAC,OAAO,EAAE,iBAAiB,CAAA;CAAE,CAAC;AAEhE;;;;;;;;;;;GAWG;AACH,wBAAgB,eAAe,CAC7B,QAAQ,EAAE,cAAc,EACxB,IAAI,EAAE,OAAO,EACb,GAAG,EAAE,OAAO,EACZ,SAAS,EAAE,mBAAmB,EAC9B,KAAK,EAAE,eAAe,EACtB,OAAO,EAAE,gBAAgB,EACzB,oBAAoB,EAAE,OAAO,GAC5B,SAAS,CAmGX"}
@@ -0,0 +1,174 @@
1
+ import { AxiomError } from '../../model/errors.js';
2
+ import { refusalOf, toEvaluationContext, toEvaluationEnv, toEvaluationInput, toEvaluationRecord, toSubmissionInput, } from '../../model/wire.js';
3
+ import { createAccessWindow } from '../access/window.js';
4
+ import { stillRedacted } from '../access/projection.js';
5
+ import { auditClaims, writeAuthorityOf } from './writes.js';
6
+ import { toSubmissionTrust } from './authority.js';
7
+ /**
8
+ * Reads and validates one submission.
9
+ *
10
+ * `bodyAuthorsHostFacts` is false for an untrusted body (the host-only members are refused at
11
+ * `$.<member>`) and true for a `trusted-host` document the caller constructed (its host-only
12
+ * members are then its own, and the authority may not repeat them).
13
+ *
14
+ * The boundary is the only throw either door turns into data. The evaluation after it runs
15
+ * outside the catch, so an artifact whose invariants are broken still throws: that is a
16
+ * programmer error, and reporting it as a refusal of the caller's body would send a host
17
+ * looking for a fault in the record.
18
+ */
19
+ export function admitSubmission(compiled, body, env, authority, trust, options, bodyAuthorsHostFacts) {
20
+ try {
21
+ // The stance is a host fact like the authority, so its own shape is a refusal a backend
22
+ // logs rather than a throw after the door. It is read first: a caller that stated an access
23
+ // answer is validated before the body it judges.
24
+ const stated = toSubmissionTrust(trust);
25
+ const { parsed, paths } = readSubmissionDocument(body, authority, stated.kind === 'trusted-host' && bodyAuthorsHostFacts);
26
+ // A `kind: 'access'` stance *is* the access answer: the evaluation reads through it and the
27
+ // write check judges against it, so the report, the delivery answer and the refusal cannot
28
+ // describe two different projections. A caller that also states one in `authority` is
29
+ // refused rather than resolved by precedence — the pair the existing model already refuses.
30
+ if (stated.kind === 'access' && (parsed.overlay !== undefined || parsed.access !== undefined)) {
31
+ throw new AxiomError('ENGINE_ERROR', 'a `kind: access` trust states the access answer; do not also state it in `authority`', 'trust.entries');
32
+ }
33
+ // Every host-supplied reference names a declaration. A typo is otherwise inert: the
34
+ // redaction list silently protects nothing, and a per-row entry narrows nothing.
35
+ const declared = declaredFieldIds(compiled);
36
+ assertDeclaredRefs(parsed.redacted, paths.redacted, declared);
37
+ assertDeclaredRefs(parsed.sessionWrites, paths.sessionWrites, declared);
38
+ assertDeclaredRefs(parsed.access, paths.access, declared);
39
+ if (stated.kind === 'access')
40
+ assertDeclaredRefs(stated.entries, 'trust.entries', declared);
41
+ // The authority's context crosses the same declaration boundary as the record, inside this
42
+ // catch, so a key the artifact does not declare is a refusal a backend logs rather than a
43
+ // throw after the door or — worse — a required root silently reading `UNKNOWN`.
44
+ const context = toEvaluationContext(compiled, parsed.context, 'authority.context');
45
+ const bodyValues = toEvaluationRecord(compiled, parsed.values);
46
+ // The server's held record sits beneath the body's answers: a binding the principal may not
47
+ // write is only ever the server's value, and a writable binding the body answered is the
48
+ // principal's. The stance is what names the difference, so held values require `access`.
49
+ const heldValues = readHeldValues(compiled, authority, stated);
50
+ const values = heldValues === undefined ? bodyValues : { ...heldValues, ...bodyValues };
51
+ const input = stated.kind === 'access'
52
+ ? {
53
+ values,
54
+ ...(context === undefined ? {} : { context }),
55
+ ...(parsed.redacted === undefined ? {} : { redacted: parsed.redacted }),
56
+ ...(parsed.sessionWrites === undefined ? {} : { sessionWrites: parsed.sessionWrites }),
57
+ access: stated.entries,
58
+ }
59
+ : {
60
+ ...parsed,
61
+ ...(context === undefined ? {} : { context }),
62
+ values,
63
+ };
64
+ // Resolve the session's own writes before the window is injected into evaluation. Building
65
+ // the window over the unfiltered input would preserve a handoff the evaluation already lifted,
66
+ // leaving readiness and the report with different answers for the same admitted record.
67
+ const resolvedInput = {
68
+ ...input,
69
+ ...(input.redacted === undefined
70
+ ? {}
71
+ : { redacted: stillRedacted(compiled.fields, input.redacted, input.sessionWrites) }),
72
+ };
73
+ const parsedEnv = toEvaluationEnv(env, authority.lookup, 'authority.lookup');
74
+ const accessWindow = createAccessWindow(compiled.fields, resolvedInput, parsedEnv, 'authority.overlay');
75
+ // The projection is resolved here, inside the catch: the resolver's duplicate refusal must
76
+ // not escape after the evaluation has run. `snapshotAccess` is the session-write set the
77
+ // evaluation itself resolves, so the write check and the read answer read the same keys.
78
+ const writeAuthority = stated.kind === 'access'
79
+ ? writeAuthorityOf(stated.entries, accessWindow.snapshotAccess().sessionWrites)
80
+ : undefined;
81
+ if (writeAuthority !== undefined) {
82
+ // Access alone decides this half, so it runs before the evaluation: an unauthorised body
83
+ // costs no rule and no table resolution, and the held record it tried to override is
84
+ // refused rather than read.
85
+ const claimRefusal = auditClaims(compiled, bodyValues, writeAuthority, options.identity);
86
+ if (claimRefusal !== undefined)
87
+ return { ok: false, refusal: claimRefusal };
88
+ }
89
+ return {
90
+ ok: true,
91
+ value: {
92
+ input,
93
+ env: parsedEnv,
94
+ trust: stated,
95
+ accessWindow,
96
+ bodyValues,
97
+ ...(writeAuthority === undefined ? {} : { writeAuthority }),
98
+ },
99
+ };
100
+ }
101
+ catch (error) {
102
+ if (error instanceof AxiomError)
103
+ return { ok: false, refusal: refusalOf(error) };
104
+ throw error;
105
+ }
106
+ }
107
+ /** A reference list's path for an untrusted body: the authority the host supplied. */
108
+ const AUTHORITY_REFERENCE_PATHS = {
109
+ redacted: 'authority.redacted',
110
+ sessionWrites: 'authority.sessionWrites',
111
+ access: 'authority.access',
112
+ };
113
+ /** A reference list's path for a document the caller constructed: the body itself. */
114
+ const BODY_REFERENCE_PATHS = {
115
+ redacted: '$.redacted',
116
+ sessionWrites: '$.sessionWrites',
117
+ access: '$.access',
118
+ };
119
+ /**
120
+ * Reads the body and the host facts into one document.
121
+ *
122
+ * An untrusted body is `toSubmissionInput`: `values` only, every host-only member refused by
123
+ * name. A `trusted-host` document is `toEvaluationInput`: its host-only members are the caller's
124
+ * own construction, so they are read — and the authority may not repeat them, because two
125
+ * answers to one question cannot be reconciled.
126
+ */
127
+ function readSubmissionDocument(body, authority, bodyAuthorsHostFacts) {
128
+ if (!bodyAuthorsHostFacts) {
129
+ return { parsed: toSubmissionInput(body, authority), paths: AUTHORITY_REFERENCE_PATHS };
130
+ }
131
+ // Read the authority through its own boundary even when the body states the facts, so a
132
+ // JavaScript caller's unknown member and an access pair are refused at the same paths.
133
+ const host = toSubmissionInput({ values: {} }, authority);
134
+ if (authority.heldValues !== undefined) {
135
+ throw new AxiomError('ENGINE_ERROR', '`heldValues` is applied only under a `kind: access` stance, which names the bindings the principal may not write', 'authority.heldValues');
136
+ }
137
+ for (const member of ['context', 'overlay', 'access', 'redacted', 'sessionWrites']) {
138
+ if (host[member] !== undefined) {
139
+ throw new AxiomError('ENGINE_ERROR', `a \`trusted-host\` document states its own \`${member}\`; the authority cannot state it too`, `authority.${member}`);
140
+ }
141
+ }
142
+ return { parsed: toEvaluationInput(body), paths: BODY_REFERENCE_PATHS };
143
+ }
144
+ /** Every field id the artifact declares, at any nesting depth. */
145
+ function declaredFieldIds(compiled) {
146
+ const declared = new Set();
147
+ const walk = (fields) => {
148
+ for (const field of fields) {
149
+ declared.add(field.fieldId);
150
+ if (field.fields !== undefined)
151
+ walk(field.fields);
152
+ }
153
+ };
154
+ walk(compiled.fields);
155
+ return declared;
156
+ }
157
+ /** Refuses a host-supplied reference that names no declaration, at the caller's own path. */
158
+ function assertDeclaredRefs(refs, path, declared) {
159
+ for (const [index, ref] of (refs ?? []).entries()) {
160
+ if (declared.has(ref.fieldId))
161
+ continue;
162
+ throw new AxiomError('ENGINE_ERROR', `the artifact declares no field \`${ref.fieldId}\`; a host-supplied reference must name a declaration`, `${path}[${String(index)}].fieldId`);
163
+ }
164
+ }
165
+ /** The server's held record, validated and read only under the access stance that scopes it. */
166
+ function readHeldValues(compiled, authority, stated) {
167
+ if (authority.heldValues === undefined)
168
+ return undefined;
169
+ if (stated.kind !== 'access') {
170
+ throw new AxiomError('ENGINE_ERROR', '`heldValues` is applied only under a `kind: access` stance, which names the bindings the principal may not write', 'authority.heldValues');
171
+ }
172
+ return toEvaluationRecord(compiled, authority.heldValues, 'authority.heldValues');
173
+ }
174
+ //# sourceMappingURL=admission.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"admission.js","sourceRoot":"","sources":["../../../src/eval/submission/admission.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,EACL,SAAS,EACT,mBAAmB,EACnB,eAAe,EACf,iBAAiB,EACjB,kBAAkB,EAClB,iBAAiB,GAClB,MAAM,qBAAqB,CAAC;AAI7B,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAEzD,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAExD,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC5D,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AA+BnD;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,eAAe,CAC7B,QAAwB,EACxB,IAAa,EACb,GAAY,EACZ,SAA8B,EAC9B,KAAsB,EACtB,OAAyB,EACzB,oBAA6B;IAE7B,IAAI,CAAC;QACH,wFAAwF;QACxF,4FAA4F;QAC5F,iDAAiD;QACjD,MAAM,MAAM,GAAG,iBAAiB,CAAC,KAAK,CAAC,CAAC;QACxC,MAAM,EAA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C3B,QAAQ,CAAC,GAAG,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;YAC5B,IAAI,KAAK,CAAC,MAAM,KAAK,SAAS;gBAAE,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;QACrD,CAAC;IACH,CAAC,CAAC;IACF,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;IACtB,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED,6FAA6F;AAC7F,SAAS,kBAAkB,CACzB,IAAyD,EACzD,IAAY,EACZ,QAA6B;IAE7B,KAAK,MAAM,CAAC,KAAK,EAAE,GAAG,CAAC,IAAI,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC;QAClD,IAAI,QAAQ,CAAC,GAAG,CAAC,GAAG,CAAC,OAAO,CAAC;YAAE,SAAS;QACxC,MAAM,IAAI,UAAU,CAClB,cAAc,EACd,oCAAoC,GAAG,CAAC,OAAO,uDAAuD,EACtG,GAAG,IAAI,IAAI,MAAM,CAAC,KAAK,CAAC,WAAW,CACpC,CAAC;IACJ,CAAC;AACH,CAAC;AAED,gGAAgG;AAChG,SAAS,cAAc,CACrB,QAAwB,EACxB,SAA8B,EAC9B,MAAuB;IAEvB,IAAI,SAAS,CAAC,UAAU,KAAK,SAAS;QAAE,OAAO,SAAS,CAAC;IACzD,IAAI,MAAM,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;QAC7B,MAAM,IAAI,UAAU,CAClB,cAAc,EACd,kHAAkH,EAClH,sBAAsB,CACvB,CAAC;IACJ,CAAC;IACD,OAAO,kBAAkB,CAAC,QAAQ,EAAE,SAAS,CAAC,UAAU,EAAE,sBAAsB,CAAC,CAAC;AACpF,CAAC","sourcesContent":["import { AxiomError } from '../../model/errors.js';\nimport {\n refusalOf,\n toEvaluationContext,\n toEvaluationEnv,\n toEvaluationInput,\n toEvaluationRecord,\n toSubmissionInput,\n} from '../../model/wire.js';\nimport type { EvaluationEnv, EvaluationInput, SubmissionAuthority } from '../../model/access.js';\nimport type { CompiledSchema } from '../../model/schema.js';\nimport type { WireValue } from '../../model/types.js';\nimport { createAccessWindow } from '../access/window.js';\nimport type { AccessWindow } from '../access/window.js';\nimport { stillRedacted } from '../access/projection.js';\nimport type { FormStateOptions } from '../state/options.js';\nimport { auditClaims, writeAuthorityOf } from './writes.js';\nimport { toSubmissionTrust } from './authority.js';\nimport type { SubmissionTrust } from './authority.js';\nimport type { WriteAuthority } from './writes.js';\nimport type { SubmissionRefusal } from './refusals.js';\n\n/**\n * One admission shared by both submission doors.\n *\n * `evaluateSubmission` and `submissionVerdict` differ in what they answer, not in what they\n * trust. This module reads the body, the authority and the stance exactly once, resolves the\n * access window, merges the server's held record beneath the body's answers, and refuses claims\n * the stance does not permit — before any rule runs. The two doors then build their own answer\n * from the admitted input, so a body cannot be admissible at one door and refused at the other.\n */\n\n/** What the submission boundary admitted: the evaluated input, or the reason it refused. */\ninterface AdmittedSubmission {\n readonly input: EvaluationInput;\n readonly env: EvaluationEnv;\n readonly trust: SubmissionTrust;\n readonly writeAuthority?: WriteAuthority;\n readonly accessWindow: AccessWindow;\n /** The record the *body* stated, before the server's held values were merged beneath it. */\n readonly bodyValues: Readonly<Record<string, WireValue>>;\n}\n\n/** The boundary's answer: an admitted document, or one refusal envelope for every cause. */\nexport type Admission =\n | { readonly ok: true; readonly value: AdmittedSubmission }\n | { readonly ok: false; readonly refusal: SubmissionRefusal };\n\n/**\n * Reads and validates one submission.\n *\n * `bodyAuthorsHostFacts` is false for an untrusted body (the host-only members are refused at\n * `$.<member>`) and true for a `trusted-host` document the caller constructed (its host-only\n * members are then its own, and the authority may not repeat them).\n *\n * The boundary is the only throw either door turns into data. The evaluation after it runs\n * outside the catch, so an artifact whose invariants are broken still throws: that is a\n * programmer error, and reporting it as a refusal of the caller's body would send a host\n * looking for a fault in the record.\n */\nexport function admitSubmission(\n compiled: CompiledSchema,\n body: unknown,\n env: unknown,\n authority: SubmissionAuthority,\n trust: SubmissionTrust,\n options: FormStateOptions,\n bodyAuthorsHostFacts: boolean,\n): Admission {\n try {\n // The stance is a host fact like the authority, so its own shape is a refusal a backend\n // logs rather than a throw after the door. It is read first: a caller that stated an access\n // answer is validated before the body it judges.\n const stated = toSubmissionTrust(trust);\n const { parsed, paths } = readSubmissionDocument(\n body,\n authority,\n stated.kind === 'trusted-host' && bodyAuthorsHostFacts,\n );\n // A `kind: 'access'` stance *is* the access answer: the evaluation reads through it and the\n // write check judges against it, so the report, the delivery answer and the refusal cannot\n // describe two different projections. A caller that also states one in `authority` is\n // refused rather than resolved by precedence — the pair the existing model already refuses.\n if (stated.kind === 'access' && (parsed.overlay !== undefined || parsed.access !== undefined)) {\n throw new AxiomError(\n 'ENGINE_ERROR',\n 'a `kind: access` trust states the access answer; do not also state it in `authority`',\n 'trust.entries',\n );\n }\n // Every host-supplied reference names a declaration. A typo is otherwise inert: the\n // redaction list silently protects nothing, and a per-row entry narrows nothing.\n const declared = declaredFieldIds(compiled);\n assertDeclaredRefs(parsed.redacted, paths.redacted, declared);\n assertDeclaredRefs(parsed.sessionWrites, paths.sessionWrites, declared);\n assertDeclaredRefs(parsed.access, paths.access, declared);\n if (stated.kind === 'access') assertDeclaredRefs(stated.entries, 'trust.entries', declared);\n // The authority's context crosses the same declaration boundary as the record, inside this\n // catch, so a key the artifact does not declare is a refusal a backend logs rather than a\n // throw after the door or — worse — a required root silently reading `UNKNOWN`.\n const context = toEvaluationContext(compiled, parsed.context, 'authority.context');\n const bodyValues = toEvaluationRecord(compiled, parsed.values);\n // The server's held record sits beneath the body's answers: a binding the principal may not\n // write is only ever the server's value, and a writable binding the body answered is the\n // principal's. The stance is what names the difference, so held values require `access`.\n const heldValues = readHeldValues(compiled, authority, stated);\n const values: Readonly<Record<string, WireValue>> =\n heldValues === undefined ? bodyValues : { ...heldValues, ...bodyValues };\n const input: EvaluationInput =\n stated.kind === 'access'\n ? {\n values,\n ...(context === undefined ? {} : { context }),\n ...(parsed.redacted === undefined ? {} : { redacted: parsed.redacted }),\n ...(parsed.sessionWrites === undefined ? {} : { sessionWrites: parsed.sessionWrites }),\n access: stated.entries,\n }\n : {\n ...parsed,\n ...(context === undefined ? {} : { context }),\n values,\n };\n // Resolve the session's own writes before the window is injected into evaluation. Building\n // the window over the unfiltered input would preserve a handoff the evaluation already lifted,\n // leaving readiness and the report with different answers for the same admitted record.\n const resolvedInput: EvaluationInput = {\n ...input,\n ...(input.redacted === undefined\n ? {}\n : { redacted: stillRedacted(compiled.fields, input.redacted, input.sessionWrites) }),\n };\n const parsedEnv = toEvaluationEnv(env, authority.lookup, 'authority.lookup');\n const accessWindow = createAccessWindow(\n compiled.fields,\n resolvedInput,\n parsedEnv,\n 'authority.overlay',\n );\n // The projection is resolved here, inside the catch: the resolver's duplicate refusal must\n // not escape after the evaluation has run. `snapshotAccess` is the session-write set the\n // evaluation itself resolves, so the write check and the read answer read the same keys.\n const writeAuthority =\n stated.kind === 'access'\n ? writeAuthorityOf(stated.entries, accessWindow.snapshotAccess().sessionWrites)\n : undefined;\n if (writeAuthority !== undefined) {\n // Access alone decides this half, so it runs before the evaluation: an unauthorised body\n // costs no rule and no table resolution, and the held record it tried to override is\n // refused rather than read.\n const claimRefusal = auditClaims(compiled, bodyValues, writeAuthority, options.identity);\n if (claimRefusal !== undefined) return { ok: false, refusal: claimRefusal };\n }\n return {\n ok: true,\n value: {\n input,\n env: parsedEnv,\n trust: stated,\n accessWindow,\n bodyValues,\n ...(writeAuthority === undefined ? {} : { writeAuthority }),\n },\n };\n } catch (error) {\n if (error instanceof AxiomError) return { ok: false, refusal: refusalOf(error) };\n throw error;\n }\n}\n\n/** Where a host-supplied reference list was read from, so a typo is refused at its own path. */\ninterface ReferencePaths {\n readonly redacted: string;\n readonly sessionWrites: string;\n readonly access: string;\n}\n\n/** A reference list's path for an untrusted body: the authority the host supplied. */\nconst AUTHORITY_REFERENCE_PATHS: ReferencePaths = {\n redacted: 'authority.redacted',\n sessionWrites: 'authority.sessionWrites',\n access: 'authority.access',\n};\n\n/** A reference list's path for a document the caller constructed: the body itself. */\nconst BODY_REFERENCE_PATHS: ReferencePaths = {\n redacted: '$.redacted',\n sessionWrites: '$.sessionWrites',\n access: '$.access',\n};\n\n/**\n * Reads the body and the host facts into one document.\n *\n * An untrusted body is `toSubmissionInput`: `values` only, every host-only member refused by\n * name. A `trusted-host` document is `toEvaluationInput`: its host-only members are the caller's\n * own construction, so they are read — and the authority may not repeat them, because two\n * answers to one question cannot be reconciled.\n */\nfunction readSubmissionDocument(\n body: unknown,\n authority: SubmissionAuthority,\n bodyAuthorsHostFacts: boolean,\n): { readonly parsed: EvaluationInput; readonly paths: ReferencePaths } {\n if (!bodyAuthorsHostFacts) {\n return { parsed: toSubmissionInput(body, authority), paths: AUTHORITY_REFERENCE_PATHS };\n }\n // Read the authority through its own boundary even when the body states the facts, so a\n // JavaScript caller's unknown member and an access pair are refused at the same paths.\n const host = toSubmissionInput({ values: {} }, authority);\n if (authority.heldValues !== undefined) {\n throw new AxiomError(\n 'ENGINE_ERROR',\n '`heldValues` is applied only under a `kind: access` stance, which names the bindings the principal may not write',\n 'authority.heldValues',\n );\n }\n for (const member of ['context', 'overlay', 'access', 'redacted', 'sessionWrites'] as const) {\n if (host[member] !== undefined) {\n throw new AxiomError(\n 'ENGINE_ERROR',\n `a \\`trusted-host\\` document states its own \\`${member}\\`; the authority cannot state it too`,\n `authority.${member}`,\n );\n }\n }\n return { parsed: toEvaluationInput(body), paths: BODY_REFERENCE_PATHS };\n}\n\n/** Every field id the artifact declares, at any nesting depth. */\nfunction declaredFieldIds(compiled: CompiledSchema): ReadonlySet<string> {\n const declared = new Set<string>();\n const walk = (fields: CompiledSchema['fields']): void => {\n for (const field of fields) {\n declared.add(field.fieldId);\n if (field.fields !== undefined) walk(field.fields);\n }\n };\n walk(compiled.fields);\n return declared;\n}\n\n/** Refuses a host-supplied reference that names no declaration, at the caller's own path. */\nfunction assertDeclaredRefs(\n refs: readonly { readonly fieldId: string }[] | undefined,\n path: string,\n declared: ReadonlySet<string>,\n): void {\n for (const [index, ref] of (refs ?? []).entries()) {\n if (declared.has(ref.fieldId)) continue;\n throw new AxiomError(\n 'ENGINE_ERROR',\n `the artifact declares no field \\`${ref.fieldId}\\`; a host-supplied reference must name a declaration`,\n `${path}[${String(index)}].fieldId`,\n );\n }\n}\n\n/** The server's held record, validated and read only under the access stance that scopes it. */\nfunction readHeldValues(\n compiled: CompiledSchema,\n authority: SubmissionAuthority,\n stated: SubmissionTrust,\n): Readonly<Record<string, WireValue>> | undefined {\n if (authority.heldValues === undefined) return undefined;\n if (stated.kind !== 'access') {\n throw new AxiomError(\n 'ENGINE_ERROR',\n '`heldValues` is applied only under a `kind: access` stance, which names the bindings the principal may not write',\n 'authority.heldValues',\n );\n }\n return toEvaluationRecord(compiled, authority.heldValues, 'authority.heldValues');\n}\n"]}
@@ -0,0 +1,71 @@
1
+ import type { AccessEntry } from '../../model/access.js';
2
+ import type { StoredSignature } from '../../model/evolution.js';
3
+ import type { FieldRef } from '../../model/types.js';
4
+ /**
5
+ * What a process states it trusts about an untrusted submission body.
6
+ *
7
+ * The wire boundary can close the *shape* of a body; it cannot answer the three questions the
8
+ * body's claims depend on:
9
+ *
10
+ * - **Who may write this field.** The access answer is the host's, so the caller states the
11
+ * projection it resolved (`kind: 'access'`), and every value in the body is judged by
12
+ * `checkWrite` against it.
13
+ * - **Who produced this signature.** A `signature_ref` is a system-origin capture, never a user
14
+ * write (`[ACCESS-1.2.4]`). A caller that captured signatures states them
15
+ * (`kind: 'verified'`, or `signatures` beside an access answer) and the door requires every
16
+ * body signature to be one of those captures; a caller that has not captured any cannot get a
17
+ * body signature accepted.
18
+ * - **Whether the body was authorised before this call.** A caller that authorised it elsewhere
19
+ * says so (`kind: 'trusted-host'`), with a reason, so the decision is visible at the call site
20
+ * and in the log rather than implied by an omission.
21
+ *
22
+ * ## The unstated stance
23
+ *
24
+ * `{ kind: 'unstated' }` is the default when the caller supplies no stance. It does not claim
25
+ * the body is authorised: the door still refuses every `signature_ref` the body carries (no
26
+ * capture was stated), and still refuses every table the artifact did not declare. It performs
27
+ * no per-field write check, because it holds no access answer, and it says so in the answer it
28
+ * returns (`SubmissionEvaluation.trust`). A server that stores the record — the caller this
29
+ * parameter exists for — must state `kind: 'access'` (with the projection it resolved) or
30
+ * `kind: 'trusted-host'` (with the reason it authorised the body). An omission is never read as
31
+ * "trusted": it is read as "this process did not claim to have authorised the writes", and the
32
+ * report is a proposal (`[ACCESS-7.1.1]`).
33
+ */
34
+ /** A signature the host captured on the server, before it read the body. */
35
+ export interface CapturedSignature {
36
+ /** The signature field the capture binds; the row key names one row of an array. */
37
+ readonly ref: FieldRef;
38
+ /** The members verification reads; `id`, `signedAt` and `signerRole` are the capture's own. */
39
+ readonly signature: StoredSignature;
40
+ }
41
+ /** The stance one call states over the body it submits. */
42
+ export type SubmissionTrust = {
43
+ readonly kind: 'access';
44
+ /** The host's resolved per-reference access. Every body value is write-checked. */
45
+ readonly entries: readonly AccessEntry[];
46
+ /** Signatures this process captured; a body signature must be one of them. */
47
+ readonly signatures?: readonly CapturedSignature[];
48
+ } | {
49
+ readonly kind: 'verified';
50
+ /** Signatures this process captured; a body signature must be one of them. */
51
+ readonly signatures: readonly CapturedSignature[];
52
+ } | {
53
+ readonly kind: 'trusted-host';
54
+ /** Why this process may treat the body as already authorised. Required, and logged. */
55
+ readonly reason: string;
56
+ } | {
57
+ readonly kind: 'unstated';
58
+ };
59
+ /** The stance's name, carried in the answer so a log states what the call trusted. */
60
+ export type SubmissionTrustKind = SubmissionTrust['kind'];
61
+ /** The stance a call that supplies none is judged under. */
62
+ export declare const UNSTATED_TRUST: SubmissionTrust;
63
+ /**
64
+ * Reads the stance a JavaScript caller passed.
65
+ *
66
+ * The value is a host fact, but a host can still pass a stale shape: an `entries` list that is
67
+ * not a list, an access state outside the five, a capture with no digest. Each is refused at the
68
+ * path the caller used, before any of them can decide a write or a signature.
69
+ */
70
+ export declare function toSubmissionTrust(value: unknown, path?: string): SubmissionTrust;
71
+ //# sourceMappingURL=authority.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"authority.d.ts","sourceRoot":"","sources":["../../../src/eval/submission/authority.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAChE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAGrD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAEH,4EAA4E;AAC5E,MAAM,WAAW,iBAAiB;IAChC,oFAAoF;IACpF,QAAQ,CAAC,GAAG,EAAE,QAAQ,CAAC;IACvB,+FAA+F;IAC/F,QAAQ,CAAC,SAAS,EAAE,eAAe,CAAC;CACrC;AAED,2DAA2D;AAC3D,MAAM,MAAM,eAAe,GACvB;IACE,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC;IACxB,mFAAmF;IACnF,QAAQ,CAAC,OAAO,EAAE,SAAS,WAAW,EAAE,CAAC;IACzC,8EAA8E;IAC9E,QAAQ,CAAC,UAAU,CAAC,EAAE,SAAS,iBAAiB,EAAE,CAAC;CACpD,GACD;IACE,QAAQ,CAAC,IAAI,EAAE,UAAU,CAAC;IAC1B,8EAA8E;IAC9E,QAAQ,CAAC,UAAU,EAAE,SAAS,iBAAiB,EAAE,CAAC;CACnD,GACD;IACE,QAAQ,CAAC,IAAI,EAAE,cAAc,CAAC;IAC9B,uFAAuF;IACvF,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACzB,GACD;IAAE,QAAQ,CAAC,IAAI,EAAE,UAAU,CAAA;CAAE,CAAC;AAElC,sFAAsF;AACtF,MAAM,MAAM,mBAAmB,GAAG,eAAe,CAAC,MAAM,CAAC,CAAC;AAE1D,4DAA4D;AAC5D,eAAO,MAAM,cAAc,EAAE,eAAqD,CAAC;AAmBnF;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,OAAO,EAAE,IAAI,SAAU,GAAG,eAAe,CAmCjF"}
@@ -0,0 +1,118 @@
1
+ import { fieldKey } from '../access/projection.js';
2
+ import { AxiomError } from '../../model/errors.js';
3
+ import { isRecord } from '../../model/guards.js';
4
+ import { SHA256_HEX_PATTERN } from '../../model/types.js';
5
+ import { toAccessEntry, toFieldRef } from '../../model/wire.js';
6
+ /** The stance a call that supplies none is judged under. */
7
+ export const UNSTATED_TRUST = Object.freeze({ kind: 'unstated' });
8
+ function refuse(path, message) {
9
+ throw new AxiomError('ENGINE_ERROR', message, path);
10
+ }
11
+ /** The members one stance admits, refusing a member the contract does not state. */
12
+ function members(value, path, admitted, optional = []) {
13
+ const known = new Set([...admitted, ...optional]);
14
+ for (const key of Object.keys(value)) {
15
+ if (!known.has(key))
16
+ refuse(path, `unknown member ${JSON.stringify(key)}`);
17
+ }
18
+ }
19
+ /**
20
+ * Reads the stance a JavaScript caller passed.
21
+ *
22
+ * The value is a host fact, but a host can still pass a stale shape: an `entries` list that is
23
+ * not a list, an access state outside the five, a capture with no digest. Each is refused at the
24
+ * path the caller used, before any of them can decide a write or a signature.
25
+ */
26
+ export function toSubmissionTrust(value, path = 'trust') {
27
+ if (!isRecord(value))
28
+ refuse(path, 'a submission trust must be an object');
29
+ const kind = value['kind'];
30
+ switch (kind) {
31
+ case 'unstated':
32
+ members(value, path, ['kind']);
33
+ return { kind };
34
+ case 'trusted-host': {
35
+ members(value, path, ['kind', 'reason']);
36
+ const reason = value['reason'];
37
+ if (typeof reason !== 'string' || reason.trim() === '') {
38
+ refuse(`${path}.reason`, 'a trusted-host stance states why the body is already authorised');
39
+ }
40
+ return { kind, reason };
41
+ }
42
+ case 'access': {
43
+ members(value, path, ['kind', 'entries'], ['signatures']);
44
+ const entries = readEntries(value['entries'], `${path}.entries`);
45
+ const signatures = readCaptures(value['signatures'], `${path}.signatures`);
46
+ return { kind, entries, ...(signatures === undefined ? {} : { signatures }) };
47
+ }
48
+ case 'verified': {
49
+ members(value, path, ['kind', 'signatures']);
50
+ const signatures = readCaptures(value['signatures'], `${path}.signatures`);
51
+ if (signatures === undefined) {
52
+ refuse(`${path}.signatures`, 'a verified stance states its signatures');
53
+ }
54
+ return { kind, signatures };
55
+ }
56
+ default:
57
+ return refuse(`${path}.kind`, 'kind must be one of unstated, access, verified or trusted-host');
58
+ }
59
+ }
60
+ /** Reads the per-reference access a `kind: 'access'` stance states. */
61
+ function readEntries(value, path) {
62
+ if (!Array.isArray(value))
63
+ refuse(path, 'entries must be an array');
64
+ const seen = new Set();
65
+ return value.map((entry, index) => {
66
+ const at = `${path}[${String(index)}]`;
67
+ const checked = toAccessEntry(entry, at);
68
+ // `projectAccess` refuses a duplicate by position; refusing it here names the caller's own
69
+ // path rather than the internal `$.access` one the resolver would otherwise report.
70
+ const key = fieldKey(checked);
71
+ if (seen.has(key))
72
+ refuse(at, `access is projected twice for ${key}`);
73
+ seen.add(key);
74
+ return checked;
75
+ });
76
+ }
77
+ /** Reads the server-captured signatures a stance states, when it states any. */
78
+ function readCaptures(value, path) {
79
+ if (value === undefined)
80
+ return undefined;
81
+ if (!Array.isArray(value))
82
+ refuse(path, 'signatures must be an array');
83
+ return value.map((capture, index) => {
84
+ const at = `${path}[${String(index)}]`;
85
+ if (!isRecord(capture))
86
+ refuse(at, 'a captured signature states `ref` and `signature`');
87
+ members(capture, at, ['ref', 'signature']);
88
+ const ref = toFieldRef(capture['ref'], `${at}.ref`);
89
+ return { ref, signature: readStoredSignature(capture['signature'], `${at}.signature`) };
90
+ });
91
+ }
92
+ /**
93
+ * The members of a `signature_ref` that verification reads.
94
+ *
95
+ * The host holds the whole blob (`id`, `mediaRefId`, `signerRole`, `signedAt`, `status` too),
96
+ * and the narrow view is all this door compares, so extra members are admitted and ignored.
97
+ */
98
+ function readStoredSignature(value, path) {
99
+ if (!isRecord(value))
100
+ refuse(path, 'a captured signature must be an object');
101
+ const coveredTargets = value['coveredTargets'];
102
+ if (!Array.isArray(coveredTargets) || coveredTargets.length === 0) {
103
+ refuse(`${path}.coveredTargets`, 'a captured signature covers at least one target');
104
+ }
105
+ const targets = coveredTargets.map((target, index) => toFieldRef(target, `${path}.coveredTargets[${String(index)}]`));
106
+ const schemaVersion = value['schemaVersion'];
107
+ if (typeof schemaVersion !== 'number' ||
108
+ !Number.isSafeInteger(schemaVersion) ||
109
+ schemaVersion < 1) {
110
+ refuse(`${path}.schemaVersion`, 'schemaVersion must be a positive integer');
111
+ }
112
+ const dataHash = value['dataHash'];
113
+ if (typeof dataHash !== 'string' || !SHA256_HEX_PATTERN.test(dataHash)) {
114
+ refuse(`${path}.dataHash`, 'dataHash must be lower-case hex');
115
+ }
116
+ return { coveredTargets: targets, schemaVersion, dataHash };
117
+ }
118
+ //# sourceMappingURL=authority.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"authority.js","sourceRoot":"","sources":["../../../src/eval/submission/authority.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AACnD,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AACjD,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAI1D,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAiEhE,4DAA4D;AAC5D,MAAM,CAAC,MAAM,cAAc,GAAoB,MAAM,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,UAAU,EAAE,CAAC,CAAC;AAEnF,SAAS,MAAM,CAAC,IAAY,EAAE,OAAe;IAC3C,MAAM,IAAI,UAAU,CAAC,cAAc,EAAE,OAAO,EAAE,IAAI,CAAC,CAAC;AACtD,CAAC;AAED,oFAAoF;AACpF,SAAS,OAAO,CACd,KAAwC,EACxC,IAAY,EACZ,QAA2B,EAC3B,QAAQ,GAAsB,EAAE;IAEhC,MAAM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,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC;QAAE,MAAM,CAAC,IAAI,EAAE,wCAAwC,CAAC,CAAC;IAC7E,MAAM,cAAc,GAAG,KAAK,CAAC,gBAAgB,CAAC,CAAC;IAC/C,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,cAAc,CAAC,IAAI,cAAc,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAClE,MAAM,CAAC,GAAG,IAAI,iBAAiB,EAAE,iDAAiD,CAAC,CAAC;IACtF,CAAC;IACD,MAAM,OAAO,GAAG,cAAc,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE,CACnD,UAAU,CAAC,MAAM,EAAE,GAAG,IAAI,mBAAmB,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAC/D,CAAC;IACF,MAAM,aAAa,GAAG,KAAK,CAAC,eAAe,CAAC,CAAC;IAC7C,IACE,OAAO,aAAa,KAAK,QAAQ;QACjC,CAAC,MAAM,CAAC,aAAa,CAAC,aAAa,CAAC;QACpC,aAAa,GAAG,CAAC,EACjB,CAAC;QACD,MAAM,CAAC,GAAG,IAAI,gBAAgB,EAAE,0CAA0C,CAAC,CAAC;IAC9E,CAAC;IACD,MAAM,QAAQ,GAAG,KAAK,CAAC,UAAU,CAAC,CAAC;IACnC,IAAI,OAAO,QAAQ,KAAK,QAAQ,IAAI,CAAC,kBAAkB,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC;QACvE,MAAM,CAAC,GAAG,IAAI,WAAW,EAAE,iCAAiC,CAAC,CAAC;IAChE,CAAC;IACD,OAAO,EAAE,cAAc,EAAE,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,CAAC;AAC9D,CAAC","sourcesContent":["import { fieldKey } from '../access/projection.js';\nimport { AxiomError } from '../../model/errors.js';\nimport { isRecord } from '../../model/guards.js';\nimport { SHA256_HEX_PATTERN } from '../../model/types.js';\nimport type { AccessEntry } from '../../model/access.js';\nimport type { StoredSignature } from '../../model/evolution.js';\nimport type { FieldRef } from '../../model/types.js';\nimport { toAccessEntry, toFieldRef } from '../../model/wire.js';\n\n/**\n * What a process states it trusts about an untrusted submission body.\n *\n * The wire boundary can close the *shape* of a body; it cannot answer the three questions the\n * body's claims depend on:\n *\n * - **Who may write this field.** The access answer is the host's, so the caller states the\n * projection it resolved (`kind: 'access'`), and every value in the body is judged by\n * `checkWrite` against it.\n * - **Who produced this signature.** A `signature_ref` is a system-origin capture, never a user\n * write (`[ACCESS-1.2.4]`). A caller that captured signatures states them\n * (`kind: 'verified'`, or `signatures` beside an access answer) and the door requires every\n * body signature to be one of those captures; a caller that has not captured any cannot get a\n * body signature accepted.\n * - **Whether the body was authorised before this call.** A caller that authorised it elsewhere\n * says so (`kind: 'trusted-host'`), with a reason, so the decision is visible at the call site\n * and in the log rather than implied by an omission.\n *\n * ## The unstated stance\n *\n * `{ kind: 'unstated' }` is the default when the caller supplies no stance. It does not claim\n * the body is authorised: the door still refuses every `signature_ref` the body carries (no\n * capture was stated), and still refuses every table the artifact did not declare. It performs\n * no per-field write check, because it holds no access answer, and it says so in the answer it\n * returns (`SubmissionEvaluation.trust`). A server that stores the record — the caller this\n * parameter exists for — must state `kind: 'access'` (with the projection it resolved) or\n * `kind: 'trusted-host'` (with the reason it authorised the body). An omission is never read as\n * \"trusted\": it is read as \"this process did not claim to have authorised the writes\", and the\n * report is a proposal (`[ACCESS-7.1.1]`).\n */\n\n/** A signature the host captured on the server, before it read the body. */\nexport interface CapturedSignature {\n /** The signature field the capture binds; the row key names one row of an array. */\n readonly ref: FieldRef;\n /** The members verification reads; `id`, `signedAt` and `signerRole` are the capture's own. */\n readonly signature: StoredSignature;\n}\n\n/** The stance one call states over the body it submits. */\nexport type SubmissionTrust =\n | {\n readonly kind: 'access';\n /** The host's resolved per-reference access. Every body value is write-checked. */\n readonly entries: readonly AccessEntry[];\n /** Signatures this process captured; a body signature must be one of them. */\n readonly signatures?: readonly CapturedSignature[];\n }\n | {\n readonly kind: 'verified';\n /** Signatures this process captured; a body signature must be one of them. */\n readonly signatures: readonly CapturedSignature[];\n }\n | {\n readonly kind: 'trusted-host';\n /** Why this process may treat the body as already authorised. Required, and logged. */\n readonly reason: string;\n }\n | { readonly kind: 'unstated' };\n\n/** The stance's name, carried in the answer so a log states what the call trusted. */\nexport type SubmissionTrustKind = SubmissionTrust['kind'];\n\n/** The stance a call that supplies none is judged under. */\nexport const UNSTATED_TRUST: SubmissionTrust = Object.freeze({ kind: 'unstated' });\n\nfunction refuse(path: string, message: string): never {\n throw new AxiomError('ENGINE_ERROR', message, path);\n}\n\n/** The members one stance admits, refusing a member the contract does not state. */\nfunction members(\n value: Readonly<Record<string, unknown>>,\n path: string,\n admitted: readonly string[],\n optional: readonly string[] = [],\n): void {\n const known = new Set([...admitted, ...optional]);\n for (const key of Object.keys(value)) {\n if (!known.has(key)) refuse(path, `unknown member ${JSON.stringify(key)}`);\n }\n}\n\n/**\n * Reads the stance a JavaScript caller passed.\n *\n * The value is a host fact, but a host can still pass a stale shape: an `entries` list that is\n * not a list, an access state outside the five, a capture with no digest. Each is refused at the\n * path the caller used, before any of them can decide a write or a signature.\n */\nexport function toSubmissionTrust(value: unknown, path = 'trust'): SubmissionTrust {\n if (!isRecord(value)) refuse(path, 'a submission trust must be an object');\n const kind = value['kind'];\n switch (kind) {\n case 'unstated':\n members(value, path, ['kind']);\n return { kind };\n case 'trusted-host': {\n members(value, path, ['kind', 'reason']);\n const reason = value['reason'];\n if (typeof reason !== 'string' || reason.trim() === '') {\n refuse(`${path}.reason`, 'a trusted-host stance states why the body is already authorised');\n }\n return { kind, reason };\n }\n case 'access': {\n members(value, path, ['kind', 'entries'], ['signatures']);\n const entries = readEntries(value['entries'], `${path}.entries`);\n const signatures = readCaptures(value['signatures'], `${path}.signatures`);\n return { kind, entries, ...(signatures === undefined ? {} : { signatures }) };\n }\n case 'verified': {\n members(value, path, ['kind', 'signatures']);\n const signatures = readCaptures(value['signatures'], `${path}.signatures`);\n if (signatures === undefined) {\n refuse(`${path}.signatures`, 'a verified stance states its signatures');\n }\n return { kind, signatures };\n }\n default:\n return refuse(\n `${path}.kind`,\n 'kind must be one of unstated, access, verified or trusted-host',\n );\n }\n}\n\n/** Reads the per-reference access a `kind: 'access'` stance states. */\nfunction readEntries(value: unknown, path: string): readonly AccessEntry[] {\n if (!Array.isArray(value)) refuse(path, 'entries must be an array');\n const seen = new Set<string>();\n return value.map((entry, index) => {\n const at = `${path}[${String(index)}]`;\n const checked = toAccessEntry(entry, at);\n // `projectAccess` refuses a duplicate by position; refusing it here names the caller's own\n // path rather than the internal `$.access` one the resolver would otherwise report.\n const key = fieldKey(checked);\n if (seen.has(key)) refuse(at, `access is projected twice for ${key}`);\n seen.add(key);\n return checked;\n });\n}\n\n/** Reads the server-captured signatures a stance states, when it states any. */\nfunction readCaptures(value: unknown, path: string): readonly CapturedSignature[] | undefined {\n if (value === undefined) return undefined;\n if (!Array.isArray(value)) refuse(path, 'signatures must be an array');\n return value.map((capture, index) => {\n const at = `${path}[${String(index)}]`;\n if (!isRecord(capture)) refuse(at, 'a captured signature states `ref` and `signature`');\n members(capture, at, ['ref', 'signature']);\n const ref = toFieldRef(capture['ref'], `${at}.ref`);\n return { ref, signature: readStoredSignature(capture['signature'], `${at}.signature`) };\n });\n}\n\n/**\n * The members of a `signature_ref` that verification reads.\n *\n * The host holds the whole blob (`id`, `mediaRefId`, `signerRole`, `signedAt`, `status` too),\n * and the narrow view is all this door compares, so extra members are admitted and ignored.\n */\nfunction readStoredSignature(value: unknown, path: string): StoredSignature {\n if (!isRecord(value)) refuse(path, 'a captured signature must be an object');\n const coveredTargets = value['coveredTargets'];\n if (!Array.isArray(coveredTargets) || coveredTargets.length === 0) {\n refuse(`${path}.coveredTargets`, 'a captured signature covers at least one target');\n }\n const targets = coveredTargets.map((target, index) =>\n toFieldRef(target, `${path}.coveredTargets[${String(index)}]`),\n );\n const schemaVersion = value['schemaVersion'];\n if (\n typeof schemaVersion !== 'number' ||\n !Number.isSafeInteger(schemaVersion) ||\n schemaVersion < 1\n ) {\n refuse(`${path}.schemaVersion`, 'schemaVersion must be a positive integer');\n }\n const dataHash = value['dataHash'];\n if (typeof dataHash !== 'string' || !SHA256_HEX_PATTERN.test(dataHash)) {\n refuse(`${path}.dataHash`, 'dataHash must be lower-case hex');\n }\n return { coveredTargets: targets, schemaVersion, dataHash };\n}\n"]}