@azx-pbc/axiom-compiler 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 (655) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +415 -2
  3. package/dist/article.d.ts +12 -0
  4. package/dist/article.d.ts.map +1 -0
  5. package/dist/article.js +16 -0
  6. package/dist/article.js.map +1 -0
  7. package/dist/cli/args.d.ts +101 -0
  8. package/dist/cli/args.d.ts.map +1 -0
  9. package/dist/cli/args.js +158 -0
  10. package/dist/cli/args.js.map +1 -0
  11. package/dist/cli/check.d.ts +2 -0
  12. package/dist/cli/check.d.ts.map +1 -0
  13. package/dist/cli/check.js +33 -0
  14. package/dist/cli/check.js.map +1 -0
  15. package/dist/cli/compile.d.ts +2 -0
  16. package/dist/cli/compile.d.ts.map +1 -0
  17. package/dist/cli/compile.js +43 -0
  18. package/dist/cli/compile.js.map +1 -0
  19. package/dist/cli/count.d.ts +15 -0
  20. package/dist/cli/count.d.ts.map +1 -0
  21. package/dist/cli/count.js +21 -0
  22. package/dist/cli/count.js.map +1 -0
  23. package/dist/cli/dataset.d.ts +28 -0
  24. package/dist/cli/dataset.d.ts.map +1 -0
  25. package/dist/cli/dataset.js +115 -0
  26. package/dist/cli/dataset.js.map +1 -0
  27. package/dist/cli/diff.d.ts +2 -0
  28. package/dist/cli/diff.d.ts.map +1 -0
  29. package/dist/cli/diff.js +297 -0
  30. package/dist/cli/diff.js.map +1 -0
  31. package/dist/cli/explain.d.ts +2 -0
  32. package/dist/cli/explain.d.ts.map +1 -0
  33. package/dist/cli/explain.js +95 -0
  34. package/dist/cli/explain.js.map +1 -0
  35. package/dist/cli/fields.d.ts +11 -0
  36. package/dist/cli/fields.d.ts.map +1 -0
  37. package/dist/cli/fields.js +13 -0
  38. package/dist/cli/fields.js.map +1 -0
  39. package/dist/cli/main.d.ts +2 -0
  40. package/dist/cli/main.d.ts.map +1 -0
  41. package/dist/cli/main.js +40 -0
  42. package/dist/cli/main.js.map +1 -0
  43. package/dist/cli/read.d.ts +56 -0
  44. package/dist/cli/read.d.ts.map +1 -0
  45. package/dist/cli/read.js +179 -0
  46. package/dist/cli/read.js.map +1 -0
  47. package/dist/cli/render.d.ts +58 -0
  48. package/dist/cli/render.d.ts.map +1 -0
  49. package/dist/cli/render.js +422 -0
  50. package/dist/cli/render.js.map +1 -0
  51. package/dist/cli/schema.d.ts +28 -0
  52. package/dist/cli/schema.d.ts.map +1 -0
  53. package/dist/cli/schema.js +46 -0
  54. package/dist/cli/schema.js.map +1 -0
  55. package/dist/cli/suite-report.d.ts +18 -0
  56. package/dist/cli/suite-report.d.ts.map +1 -0
  57. package/dist/cli/suite-report.js +58 -0
  58. package/dist/cli/suite-report.js.map +1 -0
  59. package/dist/cli/suites.d.ts +25 -0
  60. package/dist/cli/suites.d.ts.map +1 -0
  61. package/dist/cli/suites.js +67 -0
  62. package/dist/cli/suites.js.map +1 -0
  63. package/dist/cli/terminal.d.ts +45 -0
  64. package/dist/cli/terminal.d.ts.map +1 -0
  65. package/dist/cli/terminal.js +119 -0
  66. package/dist/cli/terminal.js.map +1 -0
  67. package/dist/cli/test.d.ts +12 -0
  68. package/dist/cli/test.d.ts.map +1 -0
  69. package/dist/cli/test.js +199 -0
  70. package/dist/cli/test.js.map +1 -0
  71. package/dist/cli/usage.d.ts +15 -0
  72. package/dist/cli/usage.d.ts.map +1 -0
  73. package/dist/cli/usage.js +95 -0
  74. package/dist/cli/usage.js.map +1 -0
  75. package/dist/cli.d.ts +3 -0
  76. package/dist/cli.d.ts.map +1 -0
  77. package/dist/cli.js +51 -0
  78. package/dist/cli.js.map +1 -0
  79. package/dist/compile/artifact-members.d.ts +57 -0
  80. package/dist/compile/artifact-members.d.ts.map +1 -0
  81. package/dist/compile/artifact-members.js +130 -0
  82. package/dist/compile/artifact-members.js.map +1 -0
  83. package/dist/compile/artifact.d.ts +20 -0
  84. package/dist/compile/artifact.d.ts.map +1 -0
  85. package/dist/compile/artifact.js +87 -0
  86. package/dist/compile/artifact.js.map +1 -0
  87. package/dist/compile/compilation.d.ts +46 -0
  88. package/dist/compile/compilation.d.ts.map +1 -0
  89. package/dist/compile/compilation.js +4 -0
  90. package/dist/compile/compilation.js.map +1 -0
  91. package/dist/compile/computed.d.ts +22 -0
  92. package/dist/compile/computed.d.ts.map +1 -0
  93. package/dist/compile/computed.js +245 -0
  94. package/dist/compile/computed.js.map +1 -0
  95. package/dist/compile/condition-warnings.d.ts +12 -0
  96. package/dist/compile/condition-warnings.d.ts.map +1 -0
  97. package/dist/compile/condition-warnings.js +26 -0
  98. package/dist/compile/condition-warnings.js.map +1 -0
  99. package/dist/compile/conditions.d.ts +18 -0
  100. package/dist/compile/conditions.d.ts.map +1 -0
  101. package/dist/compile/conditions.js +22 -0
  102. package/dist/compile/conditions.js.map +1 -0
  103. package/dist/compile/cross-checks.d.ts +67 -0
  104. package/dist/compile/cross-checks.d.ts.map +1 -0
  105. package/dist/compile/cross-checks.js +238 -0
  106. package/dist/compile/cross-checks.js.map +1 -0
  107. package/dist/compile/datasets.d.ts +52 -0
  108. package/dist/compile/datasets.d.ts.map +1 -0
  109. package/dist/compile/datasets.js +183 -0
  110. package/dist/compile/datasets.js.map +1 -0
  111. package/dist/compile/dead-weight.d.ts +26 -0
  112. package/dist/compile/dead-weight.d.ts.map +1 -0
  113. package/dist/compile/dead-weight.js +244 -0
  114. package/dist/compile/dead-weight.js.map +1 -0
  115. package/dist/compile/declaration-rules.d.ts +54 -0
  116. package/dist/compile/declaration-rules.d.ts.map +1 -0
  117. package/dist/compile/declaration-rules.js +510 -0
  118. package/dist/compile/declaration-rules.js.map +1 -0
  119. package/dist/compile/declarations.d.ts +44 -0
  120. package/dist/compile/declarations.d.ts.map +1 -0
  121. package/dist/compile/declarations.js +160 -0
  122. package/dist/compile/declarations.js.map +1 -0
  123. package/dist/compile/document.d.ts +4 -0
  124. package/dist/compile/document.d.ts.map +1 -0
  125. package/dist/compile/document.js +13 -0
  126. package/dist/compile/document.js.map +1 -0
  127. package/dist/compile/expression.d.ts +38 -0
  128. package/dist/compile/expression.d.ts.map +1 -0
  129. package/dist/compile/expression.js +288 -0
  130. package/dist/compile/expression.js.map +1 -0
  131. package/dist/compile/hashes.d.ts +26 -0
  132. package/dist/compile/hashes.d.ts.map +1 -0
  133. package/dist/compile/hashes.js +96 -0
  134. package/dist/compile/hashes.js.map +1 -0
  135. package/dist/compile/item-targets.d.ts +12 -0
  136. package/dist/compile/item-targets.d.ts.map +1 -0
  137. package/dist/compile/item-targets.js +287 -0
  138. package/dist/compile/item-targets.js.map +1 -0
  139. package/dist/compile/messages.d.ts +8 -0
  140. package/dist/compile/messages.d.ts.map +1 -0
  141. package/dist/compile/messages.js +62 -0
  142. package/dist/compile/messages.js.map +1 -0
  143. package/dist/compile/option-availability.d.ts +51 -0
  144. package/dist/compile/option-availability.d.ts.map +1 -0
  145. package/dist/compile/option-availability.js +171 -0
  146. package/dist/compile/option-availability.js.map +1 -0
  147. package/dist/compile/option-codes.d.ts +27 -0
  148. package/dist/compile/option-codes.d.ts.map +1 -0
  149. package/dist/compile/option-codes.js +212 -0
  150. package/dist/compile/option-codes.js.map +1 -0
  151. package/dist/compile/references.d.ts +14 -0
  152. package/dist/compile/references.d.ts.map +1 -0
  153. package/dist/compile/references.js +126 -0
  154. package/dist/compile/references.js.map +1 -0
  155. package/dist/compile/rows-from.d.ts +27 -0
  156. package/dist/compile/rows-from.d.ts.map +1 -0
  157. package/dist/compile/rows-from.js +164 -0
  158. package/dist/compile/rows-from.js.map +1 -0
  159. package/dist/compile/rules.d.ts +58 -0
  160. package/dist/compile/rules.d.ts.map +1 -0
  161. package/dist/compile/rules.js +327 -0
  162. package/dist/compile/rules.js.map +1 -0
  163. package/dist/compile/suggestions.d.ts +52 -0
  164. package/dist/compile/suggestions.d.ts.map +1 -0
  165. package/dist/compile/suggestions.js +633 -0
  166. package/dist/compile/suggestions.js.map +1 -0
  167. package/dist/compile/targets.d.ts +22 -0
  168. package/dist/compile/targets.d.ts.map +1 -0
  169. package/dist/compile/targets.js +125 -0
  170. package/dist/compile/targets.js.map +1 -0
  171. package/dist/compile/types.d.ts +84 -0
  172. package/dist/compile/types.d.ts.map +1 -0
  173. package/dist/compile/types.js +2 -0
  174. package/dist/compile/types.js.map +1 -0
  175. package/dist/compile/warning.d.ts +45 -0
  176. package/dist/compile/warning.d.ts.map +1 -0
  177. package/dist/compile/warning.js +2 -0
  178. package/dist/compile/warning.js.map +1 -0
  179. package/dist/compile-yaml.d.ts +23 -0
  180. package/dist/compile-yaml.d.ts.map +1 -0
  181. package/dist/compile-yaml.js +30 -0
  182. package/dist/compile-yaml.js.map +1 -0
  183. package/dist/compile.d.ts +78 -0
  184. package/dist/compile.d.ts.map +1 -0
  185. package/dist/compile.js +372 -0
  186. package/dist/compile.js.map +1 -0
  187. package/dist/csv/limits.d.ts +43 -0
  188. package/dist/csv/limits.d.ts.map +1 -0
  189. package/dist/csv/limits.js +51 -0
  190. package/dist/csv/limits.js.map +1 -0
  191. package/dist/csv/scalar.d.ts +33 -0
  192. package/dist/csv/scalar.d.ts.map +1 -0
  193. package/dist/csv/scalar.js +77 -0
  194. package/dist/csv/scalar.js.map +1 -0
  195. package/dist/datasets/csv.d.ts +46 -0
  196. package/dist/datasets/csv.d.ts.map +1 -0
  197. package/dist/datasets/csv.js +293 -0
  198. package/dist/datasets/csv.js.map +1 -0
  199. package/dist/datasets/declaration.d.ts +16 -0
  200. package/dist/datasets/declaration.d.ts.map +1 -0
  201. package/dist/datasets/declaration.js +104 -0
  202. package/dist/datasets/declaration.js.map +1 -0
  203. package/dist/datasets/diagnostics.d.ts +65 -0
  204. package/dist/datasets/diagnostics.d.ts.map +1 -0
  205. package/dist/datasets/diagnostics.js +2 -0
  206. package/dist/datasets/diagnostics.js.map +1 -0
  207. package/dist/datasets/diff.d.ts +46 -0
  208. package/dist/datasets/diff.d.ts.map +1 -0
  209. package/dist/datasets/diff.js +84 -0
  210. package/dist/datasets/diff.js.map +1 -0
  211. package/dist/datasets/document.d.ts +12 -0
  212. package/dist/datasets/document.d.ts.map +1 -0
  213. package/dist/datasets/document.js +382 -0
  214. package/dist/datasets/document.js.map +1 -0
  215. package/dist/datasets/index.d.ts +43 -0
  216. package/dist/datasets/index.d.ts.map +1 -0
  217. package/dist/datasets/index.js +68 -0
  218. package/dist/datasets/index.js.map +1 -0
  219. package/dist/datasets/repair.d.ts +26 -0
  220. package/dist/datasets/repair.d.ts.map +1 -0
  221. package/dist/datasets/repair.js +60 -0
  222. package/dist/datasets/repair.js.map +1 -0
  223. package/dist/document-path.d.ts +62 -0
  224. package/dist/document-path.d.ts.map +1 -0
  225. package/dist/document-path.js +200 -0
  226. package/dist/document-path.js.map +1 -0
  227. package/dist/expr/boundary.d.ts +8 -0
  228. package/dist/expr/boundary.d.ts.map +1 -0
  229. package/dist/expr/boundary.js +243 -0
  230. package/dist/expr/boundary.js.map +1 -0
  231. package/dist/expr/compile-expr.d.ts +35 -0
  232. package/dist/expr/compile-expr.d.ts.map +1 -0
  233. package/dist/expr/compile-expr.js +66 -0
  234. package/dist/expr/compile-expr.js.map +1 -0
  235. package/dist/expr/deprecation.d.ts +23 -0
  236. package/dist/expr/deprecation.d.ts.map +1 -0
  237. package/dist/expr/deprecation.js +28 -0
  238. package/dist/expr/deprecation.js.map +1 -0
  239. package/dist/expr/diagnostics.d.ts +31 -0
  240. package/dist/expr/diagnostics.d.ts.map +1 -0
  241. package/dist/expr/diagnostics.js +34 -0
  242. package/dist/expr/diagnostics.js.map +1 -0
  243. package/dist/expr/lexer.d.ts +49 -0
  244. package/dist/expr/lexer.d.ts.map +1 -0
  245. package/dist/expr/lexer.js +277 -0
  246. package/dist/expr/lexer.js.map +1 -0
  247. package/dist/expr/lint-warnings.d.ts +11 -0
  248. package/dist/expr/lint-warnings.d.ts.map +1 -0
  249. package/dist/expr/lint-warnings.js +20 -0
  250. package/dist/expr/lint-warnings.js.map +1 -0
  251. package/dist/expr/lint.d.ts +41 -0
  252. package/dist/expr/lint.d.ts.map +1 -0
  253. package/dist/expr/lint.js +1034 -0
  254. package/dist/expr/lint.js.map +1 -0
  255. package/dist/expr/parse/aggregates.d.ts +13 -0
  256. package/dist/expr/parse/aggregates.d.ts.map +1 -0
  257. package/dist/expr/parse/aggregates.js +48 -0
  258. package/dist/expr/parse/aggregates.js.map +1 -0
  259. package/dist/expr/parse/budget.d.ts +11 -0
  260. package/dist/expr/parse/budget.d.ts.map +1 -0
  261. package/dist/expr/parse/budget.js +57 -0
  262. package/dist/expr/parse/budget.js.map +1 -0
  263. package/dist/expr/parse/grammar.d.ts +9 -0
  264. package/dist/expr/parse/grammar.d.ts.map +1 -0
  265. package/dist/expr/parse/grammar.js +699 -0
  266. package/dist/expr/parse/grammar.js.map +1 -0
  267. package/dist/expr/parse/literals.d.ts +20 -0
  268. package/dist/expr/parse/literals.d.ts.map +1 -0
  269. package/dist/expr/parse/literals.js +132 -0
  270. package/dist/expr/parse/literals.js.map +1 -0
  271. package/dist/expr/parse/stream.d.ts +60 -0
  272. package/dist/expr/parse/stream.d.ts.map +1 -0
  273. package/dist/expr/parse/stream.js +151 -0
  274. package/dist/expr/parse/stream.js.map +1 -0
  275. package/dist/expr/parser.d.ts +45 -0
  276. package/dist/expr/parser.d.ts.map +1 -0
  277. package/dist/expr/parser.js +110 -0
  278. package/dist/expr/parser.js.map +1 -0
  279. package/dist/expr/print/spell.d.ts +78 -0
  280. package/dist/expr/print/spell.d.ts.map +1 -0
  281. package/dist/expr/print/spell.js +592 -0
  282. package/dist/expr/print/spell.js.map +1 -0
  283. package/dist/expr/print.d.ts +20 -0
  284. package/dist/expr/print.d.ts.map +1 -0
  285. package/dist/expr/print.js +102 -0
  286. package/dist/expr/print.js.map +1 -0
  287. package/dist/expr/suggest.d.ts +26 -0
  288. package/dist/expr/suggest.d.ts.map +1 -0
  289. package/dist/expr/suggest.js +77 -0
  290. package/dist/expr/suggest.js.map +1 -0
  291. package/dist/expr/typecheck/aggregates.d.ts +8 -0
  292. package/dist/expr/typecheck/aggregates.d.ts.map +1 -0
  293. package/dist/expr/typecheck/aggregates.js +334 -0
  294. package/dist/expr/typecheck/aggregates.js.map +1 -0
  295. package/dist/expr/typecheck/arithmetic.d.ts +6 -0
  296. package/dist/expr/typecheck/arithmetic.d.ts.map +1 -0
  297. package/dist/expr/typecheck/arithmetic.js +258 -0
  298. package/dist/expr/typecheck/arithmetic.js.map +1 -0
  299. package/dist/expr/typecheck/arity.d.ts +38 -0
  300. package/dist/expr/typecheck/arity.d.ts.map +1 -0
  301. package/dist/expr/typecheck/arity.js +173 -0
  302. package/dist/expr/typecheck/arity.js.map +1 -0
  303. package/dist/expr/typecheck/calls.d.ts +6 -0
  304. package/dist/expr/typecheck/calls.d.ts.map +1 -0
  305. package/dist/expr/typecheck/calls.js +137 -0
  306. package/dist/expr/typecheck/calls.js.map +1 -0
  307. package/dist/expr/typecheck/comparison.d.ts +13 -0
  308. package/dist/expr/typecheck/comparison.d.ts.map +1 -0
  309. package/dist/expr/typecheck/comparison.js +200 -0
  310. package/dist/expr/typecheck/comparison.js.map +1 -0
  311. package/dist/expr/typecheck/compound.d.ts +24 -0
  312. package/dist/expr/typecheck/compound.d.ts.map +1 -0
  313. package/dist/expr/typecheck/compound.js +175 -0
  314. package/dist/expr/typecheck/compound.js.map +1 -0
  315. package/dist/expr/typecheck/context.d.ts +44 -0
  316. package/dist/expr/typecheck/context.d.ts.map +1 -0
  317. package/dist/expr/typecheck/context.js +2 -0
  318. package/dist/expr/typecheck/context.js.map +1 -0
  319. package/dist/expr/typecheck/datasets.d.ts +17 -0
  320. package/dist/expr/typecheck/datasets.d.ts.map +1 -0
  321. package/dist/expr/typecheck/datasets.js +136 -0
  322. package/dist/expr/typecheck/datasets.js.map +1 -0
  323. package/dist/expr/typecheck/digest.d.ts +7 -0
  324. package/dist/expr/typecheck/digest.d.ts.map +1 -0
  325. package/dist/expr/typecheck/digest.js +44 -0
  326. package/dist/expr/typecheck/digest.js.map +1 -0
  327. package/dist/expr/typecheck/fold.d.ts +41 -0
  328. package/dist/expr/typecheck/fold.d.ts.map +1 -0
  329. package/dist/expr/typecheck/fold.js +71 -0
  330. package/dist/expr/typecheck/fold.js.map +1 -0
  331. package/dist/expr/typecheck/gate-folds.d.ts +22 -0
  332. package/dist/expr/typecheck/gate-folds.d.ts.map +1 -0
  333. package/dist/expr/typecheck/gate-folds.js +40 -0
  334. package/dist/expr/typecheck/gate-folds.js.map +1 -0
  335. package/dist/expr/typecheck/guards.d.ts +6 -0
  336. package/dist/expr/typecheck/guards.d.ts.map +1 -0
  337. package/dist/expr/typecheck/guards.js +38 -0
  338. package/dist/expr/typecheck/guards.js.map +1 -0
  339. package/dist/expr/typecheck/member.d.ts +17 -0
  340. package/dist/expr/typecheck/member.d.ts.map +1 -0
  341. package/dist/expr/typecheck/member.js +46 -0
  342. package/dist/expr/typecheck/member.js.map +1 -0
  343. package/dist/expr/typecheck/money.d.ts +8 -0
  344. package/dist/expr/typecheck/money.d.ts.map +1 -0
  345. package/dist/expr/typecheck/money.js +49 -0
  346. package/dist/expr/typecheck/money.js.map +1 -0
  347. package/dist/expr/typecheck/numeric.d.ts +8 -0
  348. package/dist/expr/typecheck/numeric.d.ts.map +1 -0
  349. package/dist/expr/typecheck/numeric.js +84 -0
  350. package/dist/expr/typecheck/numeric.js.map +1 -0
  351. package/dist/expr/typecheck/operands.d.ts +27 -0
  352. package/dist/expr/typecheck/operands.d.ts.map +1 -0
  353. package/dist/expr/typecheck/operands.js +106 -0
  354. package/dist/expr/typecheck/operands.js.map +1 -0
  355. package/dist/expr/typecheck/paths.d.ts +21 -0
  356. package/dist/expr/typecheck/paths.d.ts.map +1 -0
  357. package/dist/expr/typecheck/paths.js +321 -0
  358. package/dist/expr/typecheck/paths.js.map +1 -0
  359. package/dist/expr/typecheck/records.d.ts +24 -0
  360. package/dist/expr/typecheck/records.d.ts.map +1 -0
  361. package/dist/expr/typecheck/records.js +53 -0
  362. package/dist/expr/typecheck/records.js.map +1 -0
  363. package/dist/expr/typecheck/sequences.d.ts +15 -0
  364. package/dist/expr/typecheck/sequences.d.ts.map +1 -0
  365. package/dist/expr/typecheck/sequences.js +55 -0
  366. package/dist/expr/typecheck/sequences.js.map +1 -0
  367. package/dist/expr/typecheck/strings.d.ts +8 -0
  368. package/dist/expr/typecheck/strings.d.ts.map +1 -0
  369. package/dist/expr/typecheck/strings.js +188 -0
  370. package/dist/expr/typecheck/strings.js.map +1 -0
  371. package/dist/expr/typecheck/temporal.d.ts +7 -0
  372. package/dist/expr/typecheck/temporal.d.ts.map +1 -0
  373. package/dist/expr/typecheck/temporal.js +80 -0
  374. package/dist/expr/typecheck/temporal.js.map +1 -0
  375. package/dist/expr/typecheck/types.d.ts +163 -0
  376. package/dist/expr/typecheck/types.d.ts.map +1 -0
  377. package/dist/expr/typecheck/types.js +404 -0
  378. package/dist/expr/typecheck/types.js.map +1 -0
  379. package/dist/expr/typecheck.d.ts +75 -0
  380. package/dist/expr/typecheck.d.ts.map +1 -0
  381. package/dist/expr/typecheck.js +242 -0
  382. package/dist/expr/typecheck.js.map +1 -0
  383. package/dist/expr/undecided.d.ts +13 -0
  384. package/dist/expr/undecided.d.ts.map +1 -0
  385. package/dist/expr/undecided.js +58 -0
  386. package/dist/expr/undecided.js.map +1 -0
  387. package/dist/expr/values/code-points.d.ts +13 -0
  388. package/dist/expr/values/code-points.d.ts.map +1 -0
  389. package/dist/expr/values/code-points.js +25 -0
  390. package/dist/expr/values/code-points.js.map +1 -0
  391. package/dist/expr/values/inline.d.ts +77 -0
  392. package/dist/expr/values/inline.d.ts.map +1 -0
  393. package/dist/expr/values/inline.js +404 -0
  394. package/dist/expr/values/inline.js.map +1 -0
  395. package/dist/expr/values/interval.d.ts +19 -0
  396. package/dist/expr/values/interval.d.ts.map +1 -0
  397. package/dist/expr/values/interval.js +1180 -0
  398. package/dist/expr/values/interval.js.map +1 -0
  399. package/dist/index.d.ts +163 -0
  400. package/dist/index.d.ts.map +1 -0
  401. package/dist/index.js +128 -0
  402. package/dist/index.js.map +1 -0
  403. package/dist/ingest/document.d.ts +58 -0
  404. package/dist/ingest/document.d.ts.map +1 -0
  405. package/dist/ingest/document.js +83 -0
  406. package/dist/ingest/document.js.map +1 -0
  407. package/dist/ingest/yaml-document.d.ts +15 -0
  408. package/dist/ingest/yaml-document.d.ts.map +1 -0
  409. package/dist/ingest/yaml-document.js +42 -0
  410. package/dist/ingest/yaml-document.js.map +1 -0
  411. package/dist/ingest/yaml.d.ts +51 -0
  412. package/dist/ingest/yaml.d.ts.map +1 -0
  413. package/dist/ingest/yaml.js +340 -0
  414. package/dist/ingest/yaml.js.map +1 -0
  415. package/dist/layout/compile.d.ts +6 -0
  416. package/dist/layout/compile.d.ts.map +1 -0
  417. package/dist/layout/compile.js +224 -0
  418. package/dist/layout/compile.js.map +1 -0
  419. package/dist/layout/context.d.ts +12 -0
  420. package/dist/layout/context.d.ts.map +1 -0
  421. package/dist/layout/context.js +26 -0
  422. package/dist/layout/context.js.map +1 -0
  423. package/dist/layout/grammar.d.ts +34 -0
  424. package/dist/layout/grammar.d.ts.map +1 -0
  425. package/dist/layout/grammar.js +171 -0
  426. package/dist/layout/grammar.js.map +1 -0
  427. package/dist/layout/read.d.ts +54 -0
  428. package/dist/layout/read.d.ts.map +1 -0
  429. package/dist/layout/read.js +101 -0
  430. package/dist/layout/read.js.map +1 -0
  431. package/dist/layout/shape.d.ts +34 -0
  432. package/dist/layout/shape.d.ts.map +1 -0
  433. package/dist/layout/shape.js +149 -0
  434. package/dist/layout/shape.js.map +1 -0
  435. package/dist/messages/compile.d.ts +47 -0
  436. package/dist/messages/compile.d.ts.map +1 -0
  437. package/dist/messages/compile.js +202 -0
  438. package/dist/messages/compile.js.map +1 -0
  439. package/dist/messages/locale.d.ts +18 -0
  440. package/dist/messages/locale.d.ts.map +1 -0
  441. package/dist/messages/locale.js +33 -0
  442. package/dist/messages/locale.js.map +1 -0
  443. package/dist/messages/slots.d.ts +54 -0
  444. package/dist/messages/slots.d.ts.map +1 -0
  445. package/dist/messages/slots.js +137 -0
  446. package/dist/messages/slots.js.map +1 -0
  447. package/dist/overlay/compile-overlay.d.ts +29 -0
  448. package/dist/overlay/compile-overlay.d.ts.map +1 -0
  449. package/dist/overlay/compile-overlay.js +120 -0
  450. package/dist/overlay/compile-overlay.js.map +1 -0
  451. package/dist/overlay/compose.d.ts +26 -0
  452. package/dist/overlay/compose.d.ts.map +1 -0
  453. package/dist/overlay/compose.js +674 -0
  454. package/dist/overlay/compose.js.map +1 -0
  455. package/dist/overlay/types.d.ts +41 -0
  456. package/dist/overlay/types.d.ts.map +1 -0
  457. package/dist/overlay/types.js +2 -0
  458. package/dist/overlay/types.js.map +1 -0
  459. package/dist/publish/classify.d.ts +50 -0
  460. package/dist/publish/classify.d.ts.map +1 -0
  461. package/dist/publish/classify.js +85 -0
  462. package/dist/publish/classify.js.map +1 -0
  463. package/dist/publish/environment.d.ts +15 -0
  464. package/dist/publish/environment.d.ts.map +1 -0
  465. package/dist/publish/environment.js +2 -0
  466. package/dist/publish/environment.js.map +1 -0
  467. package/dist/publish/migrations.d.ts +108 -0
  468. package/dist/publish/migrations.d.ts.map +1 -0
  469. package/dist/publish/migrations.js +166 -0
  470. package/dist/publish/migrations.js.map +1 -0
  471. package/dist/publish/observation.d.ts +29 -0
  472. package/dist/publish/observation.d.ts.map +1 -0
  473. package/dist/publish/observation.js +43 -0
  474. package/dist/publish/observation.js.map +1 -0
  475. package/dist/publish/readiness.d.ts +197 -0
  476. package/dist/publish/readiness.d.ts.map +1 -0
  477. package/dist/publish/readiness.js +239 -0
  478. package/dist/publish/readiness.js.map +1 -0
  479. package/dist/publish/vectors.d.ts +50 -0
  480. package/dist/publish/vectors.d.ts.map +1 -0
  481. package/dist/publish/vectors.js +306 -0
  482. package/dist/publish/vectors.js.map +1 -0
  483. package/dist/publish/verify.d.ts +146 -0
  484. package/dist/publish/verify.d.ts.map +1 -0
  485. package/dist/publish/verify.js +548 -0
  486. package/dist/publish/verify.js.map +1 -0
  487. package/dist/scenarios/branch.d.ts +36 -0
  488. package/dist/scenarios/branch.d.ts.map +1 -0
  489. package/dist/scenarios/branch.js +30 -0
  490. package/dist/scenarios/branch.js.map +1 -0
  491. package/dist/scenarios/capture.d.ts +89 -0
  492. package/dist/scenarios/capture.d.ts.map +1 -0
  493. package/dist/scenarios/capture.js +443 -0
  494. package/dist/scenarios/capture.js.map +1 -0
  495. package/dist/scenarios/classifier.d.ts +20 -0
  496. package/dist/scenarios/classifier.d.ts.map +1 -0
  497. package/dist/scenarios/classifier.js +88 -0
  498. package/dist/scenarios/classifier.js.map +1 -0
  499. package/dist/scenarios/credit.d.ts +33 -0
  500. package/dist/scenarios/credit.d.ts.map +1 -0
  501. package/dist/scenarios/credit.js +330 -0
  502. package/dist/scenarios/credit.js.map +1 -0
  503. package/dist/scenarios/csv.d.ts +34 -0
  504. package/dist/scenarios/csv.d.ts.map +1 -0
  505. package/dist/scenarios/csv.js +1047 -0
  506. package/dist/scenarios/csv.js.map +1 -0
  507. package/dist/scenarios/data-identity.d.ts +39 -0
  508. package/dist/scenarios/data-identity.d.ts.map +1 -0
  509. package/dist/scenarios/data-identity.js +28 -0
  510. package/dist/scenarios/data-identity.js.map +1 -0
  511. package/dist/scenarios/document.d.ts +148 -0
  512. package/dist/scenarios/document.d.ts.map +1 -0
  513. package/dist/scenarios/document.js +513 -0
  514. package/dist/scenarios/document.js.map +1 -0
  515. package/dist/scenarios/environment.d.ts +64 -0
  516. package/dist/scenarios/environment.d.ts.map +1 -0
  517. package/dist/scenarios/environment.js +106 -0
  518. package/dist/scenarios/environment.js.map +1 -0
  519. package/dist/scenarios/evidence.d.ts +128 -0
  520. package/dist/scenarios/evidence.d.ts.map +1 -0
  521. package/dist/scenarios/evidence.js +179 -0
  522. package/dist/scenarios/evidence.js.map +1 -0
  523. package/dist/scenarios/expectations.d.ts +63 -0
  524. package/dist/scenarios/expectations.d.ts.map +1 -0
  525. package/dist/scenarios/expectations.js +490 -0
  526. package/dist/scenarios/expectations.js.map +1 -0
  527. package/dist/scenarios/references.d.ts +15 -0
  528. package/dist/scenarios/references.d.ts.map +1 -0
  529. package/dist/scenarios/references.js +239 -0
  530. package/dist/scenarios/references.js.map +1 -0
  531. package/dist/scenarios/report.d.ts +216 -0
  532. package/dist/scenarios/report.d.ts.map +1 -0
  533. package/dist/scenarios/report.js +54 -0
  534. package/dist/scenarios/report.js.map +1 -0
  535. package/dist/scenarios/runner.d.ts +55 -0
  536. package/dist/scenarios/runner.d.ts.map +1 -0
  537. package/dist/scenarios/runner.js +205 -0
  538. package/dist/scenarios/runner.js.map +1 -0
  539. package/dist/scenarios/vocabulary.d.ts +19 -0
  540. package/dist/scenarios/vocabulary.d.ts.map +1 -0
  541. package/dist/scenarios/vocabulary.js +56 -0
  542. package/dist/scenarios/vocabulary.js.map +1 -0
  543. package/dist/schema/catalogue.d.ts +54 -0
  544. package/dist/schema/catalogue.d.ts.map +1 -0
  545. package/dist/schema/catalogue.js +221 -0
  546. package/dist/schema/catalogue.js.map +1 -0
  547. package/dist/schema/check.d.ts +22 -0
  548. package/dist/schema/check.d.ts.map +1 -0
  549. package/dist/schema/check.js +30 -0
  550. package/dist/schema/check.js.map +1 -0
  551. package/dist/schema/closed.d.ts +19 -0
  552. package/dist/schema/closed.d.ts.map +1 -0
  553. package/dist/schema/closed.js +33 -0
  554. package/dist/schema/closed.js.map +1 -0
  555. package/dist/schema/collapse.d.ts +27 -0
  556. package/dist/schema/collapse.d.ts.map +1 -0
  557. package/dist/schema/collapse.js +143 -0
  558. package/dist/schema/collapse.js.map +1 -0
  559. package/dist/schema/controls.d.ts +46 -0
  560. package/dist/schema/controls.d.ts.map +1 -0
  561. package/dist/schema/controls.js +75 -0
  562. package/dist/schema/controls.js.map +1 -0
  563. package/dist/schema/dataset-declaration.d.ts +11 -0
  564. package/dist/schema/dataset-declaration.d.ts.map +1 -0
  565. package/dist/schema/dataset-declaration.js +11 -0
  566. package/dist/schema/dataset-declaration.js.map +1 -0
  567. package/dist/schema/declaration-warnings.d.ts +14 -0
  568. package/dist/schema/declaration-warnings.d.ts.map +1 -0
  569. package/dist/schema/declaration-warnings.js +77 -0
  570. package/dist/schema/declaration-warnings.js.map +1 -0
  571. package/dist/schema/declarations.d.ts +41 -0
  572. package/dist/schema/declarations.d.ts.map +1 -0
  573. package/dist/schema/declarations.js +1299 -0
  574. package/dist/schema/declarations.js.map +1 -0
  575. package/dist/schema/diagnostic.d.ts +118 -0
  576. package/dist/schema/diagnostic.d.ts.map +1 -0
  577. package/dist/schema/diagnostic.js +39 -0
  578. package/dist/schema/diagnostic.js.map +1 -0
  579. package/dist/schema/document.d.ts +93 -0
  580. package/dist/schema/document.d.ts.map +1 -0
  581. package/dist/schema/document.js +507 -0
  582. package/dist/schema/document.js.map +1 -0
  583. package/dist/schema/fields.d.ts +11 -0
  584. package/dist/schema/fields.d.ts.map +1 -0
  585. package/dist/schema/fields.js +265 -0
  586. package/dist/schema/fields.js.map +1 -0
  587. package/dist/schema/gates.d.ts +4 -0
  588. package/dist/schema/gates.d.ts.map +1 -0
  589. package/dist/schema/gates.js +68 -0
  590. package/dist/schema/gates.js.map +1 -0
  591. package/dist/schema/located.d.ts +27 -0
  592. package/dist/schema/located.d.ts.map +1 -0
  593. package/dist/schema/located.js +56 -0
  594. package/dist/schema/located.js.map +1 -0
  595. package/dist/schema/measurement.d.ts +9 -0
  596. package/dist/schema/measurement.d.ts.map +1 -0
  597. package/dist/schema/measurement.js +38 -0
  598. package/dist/schema/measurement.js.map +1 -0
  599. package/dist/schema/member-wording.d.ts +35 -0
  600. package/dist/schema/member-wording.d.ts.map +1 -0
  601. package/dist/schema/member-wording.js +286 -0
  602. package/dist/schema/member-wording.js.map +1 -0
  603. package/dist/schema/metaschema.d.ts +20 -0
  604. package/dist/schema/metaschema.d.ts.map +1 -0
  605. package/dist/schema/metaschema.js +476 -0
  606. package/dist/schema/metaschema.js.map +1 -0
  607. package/dist/schema/pointer.d.ts +31 -0
  608. package/dist/schema/pointer.d.ts.map +1 -0
  609. package/dist/schema/pointer.js +73 -0
  610. package/dist/schema/pointer.js.map +1 -0
  611. package/dist/schema/primary.d.ts +29 -0
  612. package/dist/schema/primary.d.ts.map +1 -0
  613. package/dist/schema/primary.js +48 -0
  614. package/dist/schema/primary.js.map +1 -0
  615. package/dist/schema/publish-vector.d.ts +17 -0
  616. package/dist/schema/publish-vector.d.ts.map +1 -0
  617. package/dist/schema/publish-vector.js +34 -0
  618. package/dist/schema/publish-vector.js.map +1 -0
  619. package/dist/schema/repair.d.ts +34 -0
  620. package/dist/schema/repair.d.ts.map +1 -0
  621. package/dist/schema/repair.js +163 -0
  622. package/dist/schema/repair.js.map +1 -0
  623. package/dist/schema/schema-v1.generated.d.ts +14 -0
  624. package/dist/schema/schema-v1.generated.d.ts.map +1 -0
  625. package/dist/schema/schema-v1.generated.js +7089 -0
  626. package/dist/schema/schema-v1.generated.js.map +1 -0
  627. package/dist/schema/screens.d.ts +4 -0
  628. package/dist/schema/screens.d.ts.map +1 -0
  629. package/dist/schema/screens.js +28 -0
  630. package/dist/schema/screens.js.map +1 -0
  631. package/dist/schema/test-values.d.ts +12 -0
  632. package/dist/schema/test-values.d.ts.map +1 -0
  633. package/dist/schema/test-values.js +97 -0
  634. package/dist/schema/test-values.js.map +1 -0
  635. package/dist/schema/unions.d.ts +46 -0
  636. package/dist/schema/unions.d.ts.map +1 -0
  637. package/dist/schema/unions.js +131 -0
  638. package/dist/schema/unions.js.map +1 -0
  639. package/dist/schema/validate-yaml.d.ts +14 -0
  640. package/dist/schema/validate-yaml.d.ts.map +1 -0
  641. package/dist/schema/validate-yaml.js +17 -0
  642. package/dist/schema/validate-yaml.js.map +1 -0
  643. package/dist/schema/validate.d.ts +46 -0
  644. package/dist/schema/validate.d.ts.map +1 -0
  645. package/dist/schema/validate.js +186 -0
  646. package/dist/schema/validate.js.map +1 -0
  647. package/dist/testing.d.ts +21 -0
  648. package/dist/testing.d.ts.map +1 -0
  649. package/dist/testing.js +28 -0
  650. package/dist/testing.js.map +1 -0
  651. package/dist/vocabulary.d.ts +6 -0
  652. package/dist/vocabulary.d.ts.map +1 -0
  653. package/dist/vocabulary.js +26 -0
  654. package/dist/vocabulary.js.map +1 -0
  655. package/package.json +66 -3
@@ -0,0 +1,171 @@
1
+ import { isRecord } from '@azx-pbc/axiom-runtime';
2
+ import { refuse } from './compilation.js';
3
+ import { requireBooleanCondition } from './conditions.js';
4
+ import { crossCheckExpression, crossCheckMessageBinding } from './cross-checks.js';
5
+ import { fieldDeclarations, listAt, textAt } from '../schema/document.js';
6
+ import { compileExpressionSlot, compileParams } from './expression.js';
7
+ import { crossCheckOptionCodes } from './option-codes.js';
8
+ import { compileSuggestions } from './suggestions.js';
9
+ /** How a refusal names the option: ``option `gold` of field `f_plan` ``. */
10
+ function describeOption(fieldId, code) {
11
+ return code === undefined
12
+ ? `an option of field \`${fieldId}\``
13
+ : `option \`${String(code)}\` of field \`${fieldId}\``;
14
+ }
15
+ /**
16
+ * The compiled members one declared option states, or `undefined` when it states none.
17
+ *
18
+ * `itemFieldId` is the array the declaring field sits inside, so a condition on a row member's
19
+ * option reads its own row through `$it` exactly as an item-scoped rule does. Every refusal names
20
+ * the option, the member and the repair, because the expression slot is the only place the author
21
+ * can fix the condition.
22
+ *
23
+ * `binding` says whether the runtime can key the answer to this declaration: an availability
24
+ * answer belongs to one binding, and a binding is a field plus at most one row key. A field the
25
+ * record holds once has no row; a member of a top-level array has that array's row. A row of a
26
+ * nested array needs two keys and an array's own value is keyed by the array's row, so neither
27
+ * can carry an answer v1 could state — the declaration is refused rather than compiled into a
28
+ * condition no device evaluates.
29
+ */
30
+ function compileOption(compilation, fieldId, itemFieldId, binding, option, at) {
31
+ const code = option['code'];
32
+ const optionCode = typeof code === 'string' || typeof code === 'number' ? code : undefined;
33
+ const subject = describeOption(fieldId, optionCode);
34
+ const slots = [];
35
+ const availableWhenAt = `${at}.availableWhen`;
36
+ if (option['availableWhen'] !== undefined && binding !== 'addressable') {
37
+ refuse(compilation, 'INVALID_RULE_SCOPE', availableWhenAt, binding === 'nested'
38
+ ? `${subject} declares \`availableWhen\` on a member of array \`${String(itemFieldId)}\`, which sits inside a row of another array; v1 addresses no row of a nested array, so the device could not key this answer to a row; state the condition on a member of a top-level array, or on a field the record holds once`
39
+ : `${subject} declares \`availableWhen\` on \`${fieldId}\`, an array whose rows each hold their own domain; v1 keys an availability answer by one row key, which that array's rows do not supply; state the condition on a member of a top-level array, or on a field the record holds once`, { repairStated: true });
40
+ return undefined;
41
+ }
42
+ const conditionSlot = option['availableWhen'] === undefined
43
+ ? undefined
44
+ : compileExpressionSlot(compilation, option['availableWhen'], availableWhenAt, itemFieldId);
45
+ if (conditionSlot !== undefined) {
46
+ requireBooleanCondition(compilation, conditionSlot, availableWhenAt, `\`availableWhen\` on ${subject}`);
47
+ slots.push({ path: availableWhenAt, node: conditionSlot.node });
48
+ }
49
+ const params = compileParams(compilation, option['unavailableParams'], at, itemFieldId, slots, 'unavailableParams');
50
+ const messageKey = textAt(option, 'unavailableMessageKey');
51
+ if (messageKey !== undefined) {
52
+ crossCheckMessageBinding(compilation, {
53
+ key: messageKey,
54
+ path: `${at}.unavailableMessageKey`,
55
+ owner: subject,
56
+ binding: params,
57
+ member: 'unavailableParams',
58
+ });
59
+ }
60
+ const suggestions = compileSuggestions(compilation, option['suggests'], `${at}.suggests`, {
61
+ description: subject,
62
+ ...(itemFieldId === undefined ? {} : { itemFieldId }),
63
+ });
64
+ slots.push(...suggestions.slots);
65
+ // An option's slots earn the checks a rule's slots earn: a condition is Expr v1 wherever it is
66
+ // authored, so a `rule_ok` outside a gate, an undeclared step fold, a signature digest that
67
+ // binds other targets and a code a closed option domain does not declare are refused here too.
68
+ for (const slot of slots) {
69
+ crossCheckExpression(compilation, slot.path, slot.node, undefined, compilation.layoutTargets);
70
+ crossCheckOptionCodes(compilation, slot.path, slot.node, itemFieldId);
71
+ }
72
+ const states = conditionSlot !== undefined ||
73
+ Object.keys(params.nodes).length > 0 ||
74
+ suggestions.suggestions !== undefined ||
75
+ messageKey !== undefined;
76
+ if (!states)
77
+ return undefined;
78
+ return {
79
+ ...(conditionSlot === undefined ? {} : { availableWhen: conditionSlot.node }),
80
+ ...(messageKey === undefined ? {} : { unavailableMessageKey: messageKey }),
81
+ ...(Object.keys(params.nodes).length === 0 ? {} : { unavailableParams: params.nodes }),
82
+ ...(suggestions.suggestions === undefined ? {} : { suggests: suggestions.suggestions }),
83
+ };
84
+ }
85
+ /**
86
+ * Compiles every declared option's availability condition, reason message and alternatives.
87
+ *
88
+ * A field whose domain comes from `optionSource` declares no option, so there is no declaration
89
+ * to evaluate: the author's mistake is the pair itself, which the member pass refuses and names.
90
+ * Compiling here would report the same cause twice.
91
+ */
92
+ export function compileOptionAvailability(compilation, document) {
93
+ const compiled = new Map();
94
+ for (const [fieldId, declaration] of fieldDeclarations(document)) {
95
+ const options = listAt(declaration.field, 'options');
96
+ if (options.length === 0)
97
+ continue;
98
+ if (declaration.field['optionSource'] !== undefined)
99
+ continue;
100
+ const itemFieldId = declaration.rowArray;
101
+ const binding = declaration.arrays.length === 0
102
+ ? 'addressable'
103
+ : declaration.arrays.length > 1
104
+ ? 'nested'
105
+ : textAt(declaration.field, 'primitive') === 'array'
106
+ ? 'array-in-row'
107
+ : 'addressable';
108
+ compiled.set(fieldId, options.map((option, index) => isRecord(option)
109
+ ? compileOption(compilation, fieldId, itemFieldId, binding, option, `${declaration.path}.options[${String(index)}]`)
110
+ : undefined));
111
+ }
112
+ return compiled;
113
+ }
114
+ /**
115
+ * The declared field tree with each option's compiled slots attached.
116
+ *
117
+ * The artifact is narrowed from this tree, so the members travel in the shape the runtime reads
118
+ * while an option that declares none keeps the bytes it had before availability existed.
119
+ */
120
+ export function withOptionSlots(fields, compiled) {
121
+ if (!Array.isArray(fields))
122
+ return fields;
123
+ return fields.map((field) => {
124
+ if (!isRecord(field))
125
+ return field;
126
+ const fieldId = typeof field['fieldId'] === 'string' ? field['fieldId'] : undefined;
127
+ const slots = fieldId === undefined ? undefined : compiled.get(fieldId);
128
+ const options = field['options'];
129
+ const patched = slots === undefined || !Array.isArray(options)
130
+ ? field
131
+ : {
132
+ ...field,
133
+ options: options.map((option, index) => {
134
+ const slot = slots[index];
135
+ return slot === undefined || !isRecord(option) ? option : { ...option, ...slot };
136
+ }),
137
+ };
138
+ return Array.isArray(patched['fields'])
139
+ ? { ...patched, fields: withOptionSlots(patched['fields'], compiled) }
140
+ : patched;
141
+ });
142
+ }
143
+ /**
144
+ * The narrowed field tree with each option's compiled members attached.
145
+ *
146
+ * The document tree states these members in the authored spelling the metaschema admits, so the
147
+ * narrowing from that tree leaves them out. The compiled slots are already the typed values the
148
+ * runtime reads, produced by this compiler, so they are attached here rather than parsed back out
149
+ * of a tree the compile just wrote.
150
+ */
151
+ export function withCompiledOptions(fields, compiled) {
152
+ return fields.map((field) => {
153
+ const slots = compiled.get(field.fieldId);
154
+ const options = field.options;
155
+ return {
156
+ ...field,
157
+ ...(slots === undefined || options === undefined
158
+ ? {}
159
+ : {
160
+ options: options.map((option, index) => {
161
+ const slot = slots[index];
162
+ return slot === undefined ? option : { ...option, ...slot };
163
+ }),
164
+ }),
165
+ ...(field.fields === undefined
166
+ ? {}
167
+ : { fields: withCompiledOptions(field.fields, compiled) }),
168
+ };
169
+ });
170
+ }
171
+ //# sourceMappingURL=option-availability.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"option-availability.js","sourceRoot":"","sources":["../../src/compile/option-availability.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAGlD,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC1C,OAAO,EAAE,uBAAuB,EAAE,MAAM,iBAAiB,CAAC;AAC1D,OAAO,EAAE,oBAAoB,EAAE,wBAAwB,EAAE,MAAM,mBAAmB,CAAC;AACnF,OAAO,EAAE,iBAAiB,EAAE,MAAM,EAAE,MAAM,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CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE;QAC1B,MAAM,KAAK,GAAG,QAAQ,CAAC,GAAG,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QAC1C,MAAM,OAAO,GAAG,KAAK,CAAC,OAAO,CAAC;QAC9B,OAAO;YACL,GAAG,KAAK;YACR,GAAG,CAAC,KAAK,KAAK,SAAS,IAAI,OAAO,KAAK,SAAS;gBAC9C,CAAC,CAAC,EAAE;gBACJ,CAAC,CAAC;oBACE,OAAO,EAAE,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE;wBACrC,MAAM,IAAI,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC;wBAC1B,OAAO,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,GAAG,MAAM,EAAE,GAAG,IAAI,EAAE,CAAC;oBAC9D,CAAC,CAAC;iBACH,CAAC;YACN,GAAG,CAAC,KAAK,CAAC,MAAM,KAAK,SAAS;gBAC5B,CAAC,CAAC,EAAE;gBACJ,CAAC,CAAC,EAAE,MAAM,EAAE,mBAAmB,CAAC,KAAK,CAAC,MAAM,EAAE,QAAQ,CAAC,EAAE,CAAC;SAC7D,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import { isRecord } from '@azx-pbc/axiom-runtime';\nimport type { CompiledField, CompiledSuggestion, ExprNode } from '@azx-pbc/axiom-runtime';\nimport type { Compilation } from './compilation.js';\nimport { refuse } from './compilation.js';\nimport { requireBooleanCondition } from './conditions.js';\nimport { crossCheckExpression, crossCheckMessageBinding } from './cross-checks.js';\nimport { fieldDeclarations, listAt, textAt } from '../schema/document.js';\nimport { compileExpressionSlot, compileParams } from './expression.js';\nimport { crossCheckOptionCodes } from './option-codes.js';\nimport { compileSuggestions } from './suggestions.js';\n\n/**\n * The declared members of one option that decide when it may be chosen and what may replace it,\n * `RULES-7.1.1` and `RULES-7.1.4`.\n *\n * Availability is the same kind of slot a rule's condition is: Expr v1 authored in the scope of\n * the field that declares the option, compiled to the tree the runtime evaluates. The members are\n * one declaration, so a document that states none of them states no member at all and keeps the\n * artifact bytes it always had.\n */\ninterface CompiledOptionAvailability {\n readonly availableWhen?: ExprNode;\n readonly unavailableMessageKey?: string;\n readonly unavailableParams?: Readonly<Record<string, ExprNode>>;\n readonly suggests?: readonly CompiledSuggestion[];\n}\n\n/**\n * Every declared option's compiled members, keyed by the field that declares the option and then\n * by the option's position in that field's `options` list.\n *\n * A position a field does not fill is an option that declares no availability, so the artifact\n * carries no member for it rather than an empty declaration.\n */\nexport type CompiledOptionSlots = ReadonlyMap<\n string,\n readonly (CompiledOptionAvailability | undefined)[]\n>;\n\n/** One expression slot a compiled option carries, so the caller's cross-checks see it. */\ninterface OptionSlot {\n readonly path: string;\n readonly node: ExprNode;\n}\n\n/** How a refusal names the option: ``option `gold` of field `f_plan` ``. */\nfunction describeOption(fieldId: string, code: string | number | undefined): string {\n return code === undefined\n ? `an option of field \\`${fieldId}\\``\n : `option \\`${String(code)}\\` of field \\`${fieldId}\\``;\n}\n\n/**\n * The compiled members one declared option states, or `undefined` when it states none.\n *\n * `itemFieldId` is the array the declaring field sits inside, so a condition on a row member's\n * option reads its own row through `$it` exactly as an item-scoped rule does. Every refusal names\n * the option, the member and the repair, because the expression slot is the only place the author\n * can fix the condition.\n *\n * `binding` says whether the runtime can key the answer to this declaration: an availability\n * answer belongs to one binding, and a binding is a field plus at most one row key. A field the\n * record holds once has no row; a member of a top-level array has that array's row. A row of a\n * nested array needs two keys and an array's own value is keyed by the array's row, so neither\n * can carry an answer v1 could state — the declaration is refused rather than compiled into a\n * condition no device evaluates.\n */\nfunction compileOption(\n compilation: Compilation,\n fieldId: string,\n itemFieldId: string | undefined,\n binding: 'addressable' | 'nested' | 'array-in-row',\n option: Record<string, unknown>,\n at: string,\n): CompiledOptionAvailability | undefined {\n const code = option['code'];\n const optionCode = typeof code === 'string' || typeof code === 'number' ? code : undefined;\n const subject = describeOption(fieldId, optionCode);\n const slots: OptionSlot[] = [];\n const availableWhenAt = `${at}.availableWhen`;\n if (option['availableWhen'] !== undefined && binding !== 'addressable') {\n refuse(\n compilation,\n 'INVALID_RULE_SCOPE',\n availableWhenAt,\n binding === 'nested'\n ? `${subject} declares \\`availableWhen\\` on a member of array \\`${String(itemFieldId)}\\`, which sits inside a row of another array; v1 addresses no row of a nested array, so the device could not key this answer to a row; state the condition on a member of a top-level array, or on a field the record holds once`\n : `${subject} declares \\`availableWhen\\` on \\`${fieldId}\\`, an array whose rows each hold their own domain; v1 keys an availability answer by one row key, which that array's rows do not supply; state the condition on a member of a top-level array, or on a field the record holds once`,\n { repairStated: true },\n );\n return undefined;\n }\n const conditionSlot =\n option['availableWhen'] === undefined\n ? undefined\n : compileExpressionSlot(compilation, option['availableWhen'], availableWhenAt, itemFieldId);\n if (conditionSlot !== undefined) {\n requireBooleanCondition(\n compilation,\n conditionSlot,\n availableWhenAt,\n `\\`availableWhen\\` on ${subject}`,\n );\n slots.push({ path: availableWhenAt, node: conditionSlot.node });\n }\n const params = compileParams(\n compilation,\n option['unavailableParams'],\n at,\n itemFieldId,\n slots,\n 'unavailableParams',\n );\n const messageKey = textAt(option, 'unavailableMessageKey');\n if (messageKey !== undefined) {\n crossCheckMessageBinding(compilation, {\n key: messageKey,\n path: `${at}.unavailableMessageKey`,\n owner: subject,\n binding: params,\n member: 'unavailableParams',\n });\n }\n const suggestions = compileSuggestions(compilation, option['suggests'], `${at}.suggests`, {\n description: subject,\n ...(itemFieldId === undefined ? {} : { itemFieldId }),\n });\n slots.push(...suggestions.slots);\n // An option's slots earn the checks a rule's slots earn: a condition is Expr v1 wherever it is\n // authored, so a `rule_ok` outside a gate, an undeclared step fold, a signature digest that\n // binds other targets and a code a closed option domain does not declare are refused here too.\n for (const slot of slots) {\n crossCheckExpression(compilation, slot.path, slot.node, undefined, compilation.layoutTargets);\n crossCheckOptionCodes(compilation, slot.path, slot.node, itemFieldId);\n }\n const states =\n conditionSlot !== undefined ||\n Object.keys(params.nodes).length > 0 ||\n suggestions.suggestions !== undefined ||\n messageKey !== undefined;\n if (!states) return undefined;\n return {\n ...(conditionSlot === undefined ? {} : { availableWhen: conditionSlot.node }),\n ...(messageKey === undefined ? {} : { unavailableMessageKey: messageKey }),\n ...(Object.keys(params.nodes).length === 0 ? {} : { unavailableParams: params.nodes }),\n ...(suggestions.suggestions === undefined ? {} : { suggests: suggestions.suggestions }),\n };\n}\n\n/**\n * Compiles every declared option's availability condition, reason message and alternatives.\n *\n * A field whose domain comes from `optionSource` declares no option, so there is no declaration\n * to evaluate: the author's mistake is the pair itself, which the member pass refuses and names.\n * Compiling here would report the same cause twice.\n */\nexport function compileOptionAvailability(\n compilation: Compilation,\n document: Record<string, unknown>,\n): CompiledOptionSlots {\n const compiled = new Map<string, readonly (CompiledOptionAvailability | undefined)[]>();\n for (const [fieldId, declaration] of fieldDeclarations(document)) {\n const options = listAt(declaration.field, 'options');\n if (options.length === 0) continue;\n if (declaration.field['optionSource'] !== undefined) continue;\n const itemFieldId = declaration.rowArray;\n const binding: 'addressable' | 'nested' | 'array-in-row' =\n declaration.arrays.length === 0\n ? 'addressable'\n : declaration.arrays.length > 1\n ? 'nested'\n : textAt(declaration.field, 'primitive') === 'array'\n ? 'array-in-row'\n : 'addressable';\n compiled.set(\n fieldId,\n options.map((option, index) =>\n isRecord(option)\n ? compileOption(\n compilation,\n fieldId,\n itemFieldId,\n binding,\n option,\n `${declaration.path}.options[${String(index)}]`,\n )\n : undefined,\n ),\n );\n }\n return compiled;\n}\n\n/**\n * The declared field tree with each option's compiled slots attached.\n *\n * The artifact is narrowed from this tree, so the members travel in the shape the runtime reads\n * while an option that declares none keeps the bytes it had before availability existed.\n */\nexport function withOptionSlots(fields: unknown, compiled: CompiledOptionSlots): unknown {\n if (!Array.isArray(fields)) return fields;\n return fields.map((field) => {\n if (!isRecord(field)) return field;\n const fieldId = typeof field['fieldId'] === 'string' ? field['fieldId'] : undefined;\n const slots = fieldId === undefined ? undefined : compiled.get(fieldId);\n const options = field['options'];\n const patched =\n slots === undefined || !Array.isArray(options)\n ? field\n : {\n ...field,\n options: options.map((option, index) => {\n const slot = slots[index];\n return slot === undefined || !isRecord(option) ? option : { ...option, ...slot };\n }),\n };\n return Array.isArray(patched['fields'])\n ? { ...patched, fields: withOptionSlots(patched['fields'], compiled) }\n : patched;\n });\n}\n\n/**\n * The narrowed field tree with each option's compiled members attached.\n *\n * The document tree states these members in the authored spelling the metaschema admits, so the\n * narrowing from that tree leaves them out. The compiled slots are already the typed values the\n * runtime reads, produced by this compiler, so they are attached here rather than parsed back out\n * of a tree the compile just wrote.\n */\nexport function withCompiledOptions(\n fields: readonly CompiledField[],\n compiled: CompiledOptionSlots,\n): readonly CompiledField[] {\n return fields.map((field) => {\n const slots = compiled.get(field.fieldId);\n const options = field.options;\n return {\n ...field,\n ...(slots === undefined || options === undefined\n ? {}\n : {\n options: options.map((option, index) => {\n const slot = slots[index];\n return slot === undefined ? option : { ...option, ...slot };\n }),\n }),\n ...(field.fields === undefined\n ? {}\n : { fields: withCompiledOptions(field.fields, compiled) }),\n };\n });\n}\n"]}
@@ -0,0 +1,27 @@
1
+ import type { ExprNode } from '@azx-pbc/axiom-runtime';
2
+ import type { Compilation } from './compilation.js';
3
+ /**
4
+ * Every comparison and membership list in one expression slot, checked against the closed
5
+ * domains its operands name.
6
+ *
7
+ * One slot is one authored expression, so a code named twice in the same expression is one
8
+ * mistake repeated rather than two defects: the report is deduplicated by field and code.
9
+ */
10
+ export declare function crossCheckOptionCodes(compilation: Compilation, path: string, node: ExprNode, itemFieldId: string | undefined): void;
11
+ /**
12
+ * A writer's literal checked against the target field's closed domain.
13
+ *
14
+ * The writer's value reaches the control and the wire reader without conversion, so a literal
15
+ * the target field does not declare is a value the artifact promises and then refuses. The
16
+ * check is here rather than in `rejectTargetMismatch` because it needs the authored node, not
17
+ * only its static type: a string literal and a dynamic string expression share one type but
18
+ * only the literal states a code.
19
+ *
20
+ * `subject` names who writes, because a rule's own writer and an alternative that suggests a
21
+ * value reach the same domain and the refusal has to name the declaration to repair.
22
+ *
23
+ * @returns whether a refusal was reported, so a caller that must omit the whole construct it is
24
+ * building knows the slot did not compile.
25
+ */
26
+ export declare function crossCheckWriterLiteral(compilation: Compilation, fieldId: string, node: ExprNode, path: string, subject: string): boolean;
27
+ //# sourceMappingURL=option-codes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"option-codes.d.ts","sourceRoot":"","sources":["../../src/compile/option-codes.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAA8B,QAAQ,EAAe,MAAM,wBAAwB,CAAC;AAEhG,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAiGpD;;;;;;GAMG;AACH,wBAAgB,qBAAqB,CACnC,WAAW,EAAE,WAAW,EACxB,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,QAAQ,EACd,WAAW,EAAE,MAAM,GAAG,SAAS,GAC9B,IAAI,CAkFN;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,uBAAuB,CACrC,WAAW,EAAE,WAAW,EACxB,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,QAAQ,EACd,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,MAAM,GACd,OAAO,CA6BT"}
@@ -0,0 +1,212 @@
1
+ import { closestNames } from '../expr/suggest.js';
2
+ import { refuse } from './compilation.js';
3
+ /**
4
+ * Closed option domains, checked wherever an expression can name one of their codes.
5
+ *
6
+ * A field that declares `options` is the authority for those codes (`MODEL-3.1.8`). An
7
+ * expression that compares the field against a literal, lists literals beside it, or writes a
8
+ * literal into it is a second statement of the same domain, and a code the field does not
9
+ * declare makes that statement impossible: `f_plan == "goldn"` can never hold, `f_plan !=
10
+ * "goldn"` always holds, an `in` list can never match, and a writer can only produce a value the
11
+ * control and the wire reader refuse. The document alone proves all four, so the compiler names
12
+ * the field, the code and the nearest declared code instead of shipping an artifact whose
13
+ * behaviour contradicts its own declaration.
14
+ *
15
+ * A field whose domain is dynamic (`optionSource`) declares no enumerable list, so its
16
+ * comparisons and writers are admitted: the compiler cannot prove the code wrong, and refusing
17
+ * one would refuse a legitimate document.
18
+ */
19
+ /** The codes one literal states, in the wire spelling the option list uses. */
20
+ function literalCode(node) {
21
+ if (node.kind !== 'literal')
22
+ return undefined;
23
+ const value = node.value;
24
+ if (typeof value === 'string')
25
+ return value;
26
+ if (typeof value === 'number')
27
+ return String(value);
28
+ // A boolean field's two codes are the strings `true` and `false` (`MODEL-3.1.5`).
29
+ if (typeof value === 'boolean')
30
+ return String(value);
31
+ return undefined;
32
+ }
33
+ /** The declared option codes of the field a path reads, or `undefined` when it declares none. */
34
+ function codesOfPath(compilation, itemFieldId, boundNames, node) {
35
+ if (node.kind !== 'path')
36
+ return undefined;
37
+ const field = fieldAtPath(compilation, itemFieldId, boundNames, node.path);
38
+ if (field === undefined)
39
+ return undefined;
40
+ const codes = compilation.options.get(field.fieldId);
41
+ return codes === undefined ? undefined : { field, codes };
42
+ }
43
+ /**
44
+ * The declared field one path reads, resolving the owning item scope's row binders.
45
+ *
46
+ * `$row` is the owner's own row, stable across a nested comprehension, so it addresses the same
47
+ * member as `$it` here. A bare binder on a scalar array names that array's item domain. A
48
+ * comprehension's own binder is not a declared path and answers `undefined`, which leaves the
49
+ * comparison to the runtime rather than inventing a domain.
50
+ */
51
+ function fieldAtPath(compilation, itemFieldId, boundNames, path) {
52
+ const [head = '', ...rest] = path.split('.');
53
+ if (boundNames.has(head))
54
+ return undefined;
55
+ if (!path.startsWith('$'))
56
+ return compilation.declaredFieldPaths.get(path);
57
+ if (itemFieldId === undefined)
58
+ return undefined;
59
+ if (head !== '$it' && head !== '$prev' && head !== '$next' && head !== '$row')
60
+ return undefined;
61
+ if (rest.length === 0)
62
+ return compilation.fieldsById.get(itemFieldId);
63
+ const itemPath = compilation.declaredPathsById.get(itemFieldId);
64
+ if (itemPath === undefined)
65
+ return undefined;
66
+ return compilation.declaredFieldPaths.get(`${itemPath}.${rest.join('.')}`);
67
+ }
68
+ /** The literal spelling a refusal quotes: text in backticks, other scalars as authored. */
69
+ function spelling(node) {
70
+ return typeof node.value === 'string' ? `\`${node.value}\`` : String(node.value);
71
+ }
72
+ /** The nearest declared code, as prose, or `undefined` when none is close enough to offer. */
73
+ function nearestPhrase(code, codes) {
74
+ const closest = closestNames(code, codes);
75
+ if (closest.length === 0)
76
+ return undefined;
77
+ return `nearest ${closest.map((candidate) => `\`${candidate}\``).join(' or ')}`;
78
+ }
79
+ /** The candidates a repair loop offers for one undeclared code. */
80
+ function suggestionsFor(code, codes) {
81
+ const closest = closestNames(code, codes);
82
+ return closest.length === 0 ? codes.slice(0, 3) : closest;
83
+ }
84
+ /** The message one undeclared code earns at the slot that names it. */
85
+ function undeclaredDetail(cause, code, codes) {
86
+ const nearest = nearestPhrase(code, codes);
87
+ const declared = codes.map((entry) => `\`${entry}\``).join(', ');
88
+ return `${cause} \`${code}\`, which its \`options\` do not declare; the field declares [${declared}]${nearest === undefined ? '' : `, ${nearest}`}, so spell a declared code or add \`${code}\` to the field's \`options\``;
89
+ }
90
+ /**
91
+ * Every comparison and membership list in one expression slot, checked against the closed
92
+ * domains its operands name.
93
+ *
94
+ * One slot is one authored expression, so a code named twice in the same expression is one
95
+ * mistake repeated rather than two defects: the report is deduplicated by field and code.
96
+ */
97
+ export function crossCheckOptionCodes(compilation, path, node, itemFieldId) {
98
+ const reported = new Set();
99
+ const report = (field, code, codes, cause) => {
100
+ const identity = `${field.fieldId}\u0000${code}`;
101
+ if (reported.has(identity))
102
+ return;
103
+ reported.add(identity);
104
+ refuse(compilation, 'UNKNOWN_OPTION', path, undeclaredDetail(cause, code, codes), {
105
+ suggestions: suggestionsFor(code, codes),
106
+ });
107
+ };
108
+ const checkComparison = (comparison, boundNames) => {
109
+ const [left, right] = comparison.args;
110
+ if (comparison.op === '==' || comparison.op === '!=') {
111
+ for (const [operand, literal] of [
112
+ [left, right],
113
+ [right, left],
114
+ ]) {
115
+ const codes = codesOfPath(compilation, itemFieldId, boundNames, operand);
116
+ const code = literalCode(literal);
117
+ if (codes === undefined || code === undefined)
118
+ continue;
119
+ if (codes.codes.includes(code))
120
+ continue;
121
+ report(codes.field, code, codes.codes, `\`${comparison.op}\` compares field \`${codes.field.fieldId}\` against`);
122
+ }
123
+ return;
124
+ }
125
+ if (comparison.op !== 'in')
126
+ return;
127
+ if (right.kind !== 'list')
128
+ return;
129
+ const codes = codesOfPath(compilation, itemFieldId, boundNames, left);
130
+ if (codes === undefined)
131
+ return;
132
+ for (const item of right.items) {
133
+ const code = literalCode(item);
134
+ if (code === undefined || codes.codes.includes(code))
135
+ continue;
136
+ report(codes.field, code, codes.codes, `this \`in\` list names a value for field \`${codes.field.fieldId}\`:`);
137
+ }
138
+ };
139
+ const visit = (current, boundNames) => {
140
+ switch (current.kind) {
141
+ case 'literal':
142
+ case 'path':
143
+ return;
144
+ case 'list':
145
+ for (const item of current.items)
146
+ visit(item, boundNames);
147
+ return;
148
+ case 'comprehension': {
149
+ visit(current.source, boundNames);
150
+ // The named and implicit binders iterate this comprehension's source in its body. `$row`
151
+ // is deliberately absent: it remains the enclosing item rule's row.
152
+ const inner = new Set(boundNames);
153
+ inner.add(current.binder.name);
154
+ inner.add('$it').add('$prev').add('$next');
155
+ if (current.valueExpr !== undefined)
156
+ visit(current.valueExpr, inner);
157
+ if (current.predicate !== undefined)
158
+ visit(current.predicate, inner);
159
+ return;
160
+ }
161
+ case 'compare':
162
+ checkComparison(current, boundNames);
163
+ for (const arg of current.args)
164
+ visit(arg, boundNames);
165
+ return;
166
+ default:
167
+ for (const arg of current.args)
168
+ visit(arg, boundNames);
169
+ }
170
+ };
171
+ visit(node, new Set());
172
+ }
173
+ /**
174
+ * A writer's literal checked against the target field's closed domain.
175
+ *
176
+ * The writer's value reaches the control and the wire reader without conversion, so a literal
177
+ * the target field does not declare is a value the artifact promises and then refuses. The
178
+ * check is here rather than in `rejectTargetMismatch` because it needs the authored node, not
179
+ * only its static type: a string literal and a dynamic string expression share one type but
180
+ * only the literal states a code.
181
+ *
182
+ * `subject` names who writes, because a rule's own writer and an alternative that suggests a
183
+ * value reach the same domain and the refusal has to name the declaration to repair.
184
+ *
185
+ * @returns whether a refusal was reported, so a caller that must omit the whole construct it is
186
+ * building knows the slot did not compile.
187
+ */
188
+ export function crossCheckWriterLiteral(compilation, fieldId, node, path, subject) {
189
+ const field = compilation.fieldsById.get(fieldId);
190
+ if (field === undefined)
191
+ return false;
192
+ const codes = compilation.options.get(fieldId);
193
+ if (codes === undefined)
194
+ return false;
195
+ const literals = node.kind === 'literal'
196
+ ? [node]
197
+ : field.primitive === 'array' && node.kind === 'list'
198
+ ? node.items.filter((item) => item.kind === 'literal')
199
+ : [];
200
+ const reported = new Set();
201
+ for (const literal of literals) {
202
+ const code = literalCode(literal);
203
+ if (code === undefined || codes.includes(code) || reported.has(code))
204
+ continue;
205
+ reported.add(code);
206
+ const nearest = nearestPhrase(code, codes);
207
+ const declared = codes.map((entry) => `\`${entry}\``).join(', ');
208
+ refuse(compilation, 'UNKNOWN_OPTION', path, `${subject} writes ${spelling(literal)} into field \`${fieldId}\`, which its \`options\` do not declare; the field declares [${declared}]${nearest === undefined ? '' : `, ${nearest}`}, so write a declared code or add \`${code}\` to the field's \`options\``, { suggestions: suggestionsFor(code, codes) });
209
+ }
210
+ return reported.size > 0;
211
+ }
212
+ //# sourceMappingURL=option-codes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"option-codes.js","sourceRoot":"","sources":["../../src/compile/option-codes.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAElD,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAE1C;;;;;;;;;;;;;;;GAeG;AAEH,+EAA+E;AAC/E,SAAS,WAAW,CAAC,IAAc;IACjC,IAAI,IAAI,CAAC,IAAI,KAAK,SAAS;QAAE,OAAO,SAA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AAC,IAAI,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC;YAAE,SAAS;QAC/E,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QACnB,MAAM,OAAO,GAAG,aAAa,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;QAC3C,MAAM,QAAQ,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,KAAK,IAAI,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACjE,MAAM,CACJ,WAAW,EACX,gBAAgB,EAChB,IAAI,EACJ,GAAG,OAAO,WAAW,QAAQ,CAAC,OAAO,CAAC,iBAAiB,OAAO,iEAAiE,QAAQ,IACrI,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,KAAK,OAAO,EAC3C,uCAAuC,IAAI,+BAA+B,EAC1E,EAAE,WAAW,EAAE,cAAc,CAAC,IAAI,EAAE,KAAK,CAAC,EAAE,CAC7C,CAAC;IACJ,CAAC;IACD,OAAO,QAAQ,CAAC,IAAI,GAAG,CAAC,CAAC;AAC3B,CAAC","sourcesContent":["import type { CompareNode, CompiledField, ExprNode, LiteralNode } from '@azx-pbc/axiom-runtime';\nimport { closestNames } from '../expr/suggest.js';\nimport type { Compilation } from './compilation.js';\nimport { refuse } from './compilation.js';\n\n/**\n * Closed option domains, checked wherever an expression can name one of their codes.\n *\n * A field that declares `options` is the authority for those codes (`MODEL-3.1.8`). An\n * expression that compares the field against a literal, lists literals beside it, or writes a\n * literal into it is a second statement of the same domain, and a code the field does not\n * declare makes that statement impossible: `f_plan == \"goldn\"` can never hold, `f_plan !=\n * \"goldn\"` always holds, an `in` list can never match, and a writer can only produce a value the\n * control and the wire reader refuse. The document alone proves all four, so the compiler names\n * the field, the code and the nearest declared code instead of shipping an artifact whose\n * behaviour contradicts its own declaration.\n *\n * A field whose domain is dynamic (`optionSource`) declares no enumerable list, so its\n * comparisons and writers are admitted: the compiler cannot prove the code wrong, and refusing\n * one would refuse a legitimate document.\n */\n\n/** The codes one literal states, in the wire spelling the option list uses. */\nfunction literalCode(node: ExprNode): string | undefined {\n if (node.kind !== 'literal') return undefined;\n const value = node.value;\n if (typeof value === 'string') return value;\n if (typeof value === 'number') return String(value);\n // A boolean field's two codes are the strings `true` and `false` (`MODEL-3.1.5`).\n if (typeof value === 'boolean') return String(value);\n return undefined;\n}\n\n/** The declared option codes of the field a path reads, or `undefined` when it declares none. */\nfunction codesOfPath(\n compilation: Compilation,\n itemFieldId: string | undefined,\n boundNames: ReadonlySet<string>,\n node: ExprNode,\n): { readonly field: CompiledField; readonly codes: readonly string[] } | undefined {\n if (node.kind !== 'path') return undefined;\n const field = fieldAtPath(compilation, itemFieldId, boundNames, node.path);\n if (field === undefined) return undefined;\n const codes = compilation.options.get(field.fieldId);\n return codes === undefined ? undefined : { field, codes };\n}\n\n/**\n * The declared field one path reads, resolving the owning item scope's row binders.\n *\n * `$row` is the owner's own row, stable across a nested comprehension, so it addresses the same\n * member as `$it` here. A bare binder on a scalar array names that array's item domain. A\n * comprehension's own binder is not a declared path and answers `undefined`, which leaves the\n * comparison to the runtime rather than inventing a domain.\n */\nfunction fieldAtPath(\n compilation: Compilation,\n itemFieldId: string | undefined,\n boundNames: ReadonlySet<string>,\n path: string,\n): CompiledField | undefined {\n const [head = '', ...rest] = path.split('.');\n if (boundNames.has(head)) return undefined;\n if (!path.startsWith('$')) return compilation.declaredFieldPaths.get(path);\n if (itemFieldId === undefined) return undefined;\n if (head !== '$it' && head !== '$prev' && head !== '$next' && head !== '$row') return undefined;\n if (rest.length === 0) return compilation.fieldsById.get(itemFieldId);\n const itemPath = compilation.declaredPathsById.get(itemFieldId);\n if (itemPath === undefined) return undefined;\n return compilation.declaredFieldPaths.get(`${itemPath}.${rest.join('.')}`);\n}\n\n/** The literal spelling a refusal quotes: text in backticks, other scalars as authored. */\nfunction spelling(node: LiteralNode): string {\n return typeof node.value === 'string' ? `\\`${node.value}\\`` : String(node.value);\n}\n\n/** The nearest declared code, as prose, or `undefined` when none is close enough to offer. */\nfunction nearestPhrase(code: string, codes: readonly string[]): string | undefined {\n const closest = closestNames(code, codes);\n if (closest.length === 0) return undefined;\n return `nearest ${closest.map((candidate) => `\\`${candidate}\\``).join(' or ')}`;\n}\n\n/** The candidates a repair loop offers for one undeclared code. */\nfunction suggestionsFor(code: string, codes: readonly string[]): readonly string[] {\n const closest = closestNames(code, codes);\n return closest.length === 0 ? codes.slice(0, 3) : closest;\n}\n\n/** The message one undeclared code earns at the slot that names it. */\nfunction undeclaredDetail(cause: string, code: string, codes: readonly string[]): string {\n const nearest = nearestPhrase(code, codes);\n const declared = codes.map((entry) => `\\`${entry}\\``).join(', ');\n return `${cause} \\`${code}\\`, which its \\`options\\` do not declare; the field declares [${declared}]${\n nearest === undefined ? '' : `, ${nearest}`\n }, so spell a declared code or add \\`${code}\\` to the field's \\`options\\``;\n}\n\n/**\n * Every comparison and membership list in one expression slot, checked against the closed\n * domains its operands name.\n *\n * One slot is one authored expression, so a code named twice in the same expression is one\n * mistake repeated rather than two defects: the report is deduplicated by field and code.\n */\nexport function crossCheckOptionCodes(\n compilation: Compilation,\n path: string,\n node: ExprNode,\n itemFieldId: string | undefined,\n): void {\n const reported = new Set<string>();\n\n const report = (\n field: CompiledField,\n code: string,\n codes: readonly string[],\n cause: string,\n ): void => {\n const identity = `${field.fieldId}\\u0000${code}`;\n if (reported.has(identity)) return;\n reported.add(identity);\n refuse(compilation, 'UNKNOWN_OPTION', path, undeclaredDetail(cause, code, codes), {\n suggestions: suggestionsFor(code, codes),\n });\n };\n\n const checkComparison = (comparison: CompareNode, boundNames: ReadonlySet<string>): void => {\n const [left, right] = comparison.args;\n if (comparison.op === '==' || comparison.op === '!=') {\n for (const [operand, literal] of [\n [left, right],\n [right, left],\n ] as const) {\n const codes = codesOfPath(compilation, itemFieldId, boundNames, operand);\n const code = literalCode(literal);\n if (codes === undefined || code === undefined) continue;\n if (codes.codes.includes(code)) continue;\n report(\n codes.field,\n code,\n codes.codes,\n `\\`${comparison.op}\\` compares field \\`${codes.field.fieldId}\\` against`,\n );\n }\n return;\n }\n if (comparison.op !== 'in') return;\n if (right.kind !== 'list') return;\n const codes = codesOfPath(compilation, itemFieldId, boundNames, left);\n if (codes === undefined) return;\n for (const item of right.items) {\n const code = literalCode(item);\n if (code === undefined || codes.codes.includes(code)) continue;\n report(\n codes.field,\n code,\n codes.codes,\n `this \\`in\\` list names a value for field \\`${codes.field.fieldId}\\`:`,\n );\n }\n };\n\n const visit = (current: ExprNode, boundNames: ReadonlySet<string>): void => {\n switch (current.kind) {\n case 'literal':\n case 'path':\n return;\n case 'list':\n for (const item of current.items) visit(item, boundNames);\n return;\n case 'comprehension': {\n visit(current.source, boundNames);\n // The named and implicit binders iterate this comprehension's source in its body. `$row`\n // is deliberately absent: it remains the enclosing item rule's row.\n const inner = new Set(boundNames);\n inner.add(current.binder.name);\n inner.add('$it').add('$prev').add('$next');\n if (current.valueExpr !== undefined) visit(current.valueExpr, inner);\n if (current.predicate !== undefined) visit(current.predicate, inner);\n return;\n }\n case 'compare':\n checkComparison(current, boundNames);\n for (const arg of current.args) visit(arg, boundNames);\n return;\n default:\n for (const arg of current.args) visit(arg, boundNames);\n }\n };\n\n visit(node, new Set<string>());\n}\n\n/**\n * A writer's literal checked against the target field's closed domain.\n *\n * The writer's value reaches the control and the wire reader without conversion, so a literal\n * the target field does not declare is a value the artifact promises and then refuses. The\n * check is here rather than in `rejectTargetMismatch` because it needs the authored node, not\n * only its static type: a string literal and a dynamic string expression share one type but\n * only the literal states a code.\n *\n * `subject` names who writes, because a rule's own writer and an alternative that suggests a\n * value reach the same domain and the refusal has to name the declaration to repair.\n *\n * @returns whether a refusal was reported, so a caller that must omit the whole construct it is\n * building knows the slot did not compile.\n */\nexport function crossCheckWriterLiteral(\n compilation: Compilation,\n fieldId: string,\n node: ExprNode,\n path: string,\n subject: string,\n): boolean {\n const field = compilation.fieldsById.get(fieldId);\n if (field === undefined) return false;\n const codes = compilation.options.get(fieldId);\n if (codes === undefined) return false;\n const literals =\n node.kind === 'literal'\n ? [node]\n : field.primitive === 'array' && node.kind === 'list'\n ? node.items.filter((item): item is LiteralNode => item.kind === 'literal')\n : [];\n const reported = new Set<string>();\n for (const literal of literals) {\n const code = literalCode(literal);\n if (code === undefined || codes.includes(code) || reported.has(code)) continue;\n reported.add(code);\n const nearest = nearestPhrase(code, codes);\n const declared = codes.map((entry) => `\\`${entry}\\``).join(', ');\n refuse(\n compilation,\n 'UNKNOWN_OPTION',\n path,\n `${subject} writes ${spelling(literal)} into field \\`${fieldId}\\`, which its \\`options\\` do not declare; the field declares [${declared}]${\n nearest === undefined ? '' : `, ${nearest}`\n }, so write a declared code or add \\`${code}\\` to the field's \\`options\\``,\n { suggestions: suggestionsFor(code, codes) },\n );\n }\n return reported.size > 0;\n}\n"]}
@@ -0,0 +1,14 @@
1
+ import type { ExprNode } from '@azx-pbc/axiom-runtime';
2
+ /** Every `rule_ok` target a compiled expression names. */
3
+ export declare function ruleReferences(node: ExprNode, into?: Set<string>): ReadonlySet<string>;
4
+ /** The kind each `no_blocking` call names, with the slot's own path. */
5
+ export declare function noBlockingKinds(node: ExprNode, into?: ExprNode[]): readonly ExprNode[];
6
+ /** Every step-fold call a compiled expression makes, with the call node it is. */
7
+ export declare function stepFoldCalls(node: ExprNode, into?: ExprNode[]): readonly ExprNode[];
8
+ /** Every rule-reference built-in a compiled expression uses, with the slot that used it. */
9
+ export declare function ruleReferenceUses(node: ExprNode, into?: {
10
+ readonly op: string;
11
+ }[]): readonly {
12
+ readonly op: string;
13
+ }[];
14
+ //# sourceMappingURL=references.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"references.d.ts","sourceRoot":"","sources":["../../src/compile/references.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAEvD,0DAA0D;AAC1D,wBAAgB,cAAc,CAAC,IAAI,EAAE,QAAQ,EAAE,IAAI,GAAE,GAAG,CAAC,MAAM,CAAa,GAAG,WAAW,CAAC,MAAM,CAAC,CAwBjG;AAED,wEAAwE;AACxE,wBAAgB,eAAe,CAAC,IAAI,EAAE,QAAQ,EAAE,IAAI,GAAE,QAAQ,EAAO,GAAG,SAAS,QAAQ,EAAE,CAqB1F;AAED,kFAAkF;AAClF,wBAAgB,aAAa,CAAC,IAAI,EAAE,QAAQ,EAAE,IAAI,GAAE,QAAQ,EAAO,GAAG,SAAS,QAAQ,EAAE,CAuBxF;AAED,4FAA4F;AAC5F,wBAAgB,iBAAiB,CAC/B,IAAI,EAAE,QAAQ,EACd,IAAI,GAAE;IAAE,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAA;CAAE,EAAO,GACnC,SAAS;IAAE,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAA;CAAE,EAAE,CA6BpC"}
@@ -0,0 +1,126 @@
1
+ /** Every `rule_ok` target a compiled expression names. */
2
+ export function ruleReferences(node, into = new Set()) {
3
+ switch (node.kind) {
4
+ case 'literal':
5
+ case 'path':
6
+ return into;
7
+ case 'list':
8
+ for (const item of node.items)
9
+ ruleReferences(item, into);
10
+ return into;
11
+ case 'comprehension':
12
+ ruleReferences(node.source, into);
13
+ if (node.valueExpr !== undefined)
14
+ ruleReferences(node.valueExpr, into);
15
+ if (node.predicate !== undefined)
16
+ ruleReferences(node.predicate, into);
17
+ return into;
18
+ case 'call':
19
+ if (node.op === 'rule_ok') {
20
+ const [target] = node.args;
21
+ if (target?.kind === 'literal' && typeof target.value === 'string')
22
+ into.add(target.value);
23
+ }
24
+ for (const arg of node.args)
25
+ ruleReferences(arg, into);
26
+ return into;
27
+ default:
28
+ for (const arg of node.args)
29
+ ruleReferences(arg, into);
30
+ return into;
31
+ }
32
+ }
33
+ /** The kind each `no_blocking` call names, with the slot's own path. */
34
+ export function noBlockingKinds(node, into = []) {
35
+ switch (node.kind) {
36
+ case 'literal':
37
+ case 'path':
38
+ return into;
39
+ case 'list':
40
+ for (const item of node.items)
41
+ noBlockingKinds(item, into);
42
+ return into;
43
+ case 'comprehension':
44
+ noBlockingKinds(node.source, into);
45
+ if (node.valueExpr !== undefined)
46
+ noBlockingKinds(node.valueExpr, into);
47
+ if (node.predicate !== undefined)
48
+ noBlockingKinds(node.predicate, into);
49
+ return into;
50
+ case 'call':
51
+ if (node.op === 'no_blocking')
52
+ into.push(node);
53
+ for (const arg of node.args)
54
+ noBlockingKinds(arg, into);
55
+ return into;
56
+ default:
57
+ for (const arg of node.args)
58
+ noBlockingKinds(arg, into);
59
+ return into;
60
+ }
61
+ }
62
+ /** Every step-fold call a compiled expression makes, with the call node it is. */
63
+ export function stepFoldCalls(node, into = []) {
64
+ switch (node.kind) {
65
+ case 'literal':
66
+ case 'path':
67
+ return into;
68
+ case 'list':
69
+ for (const item of node.items)
70
+ stepFoldCalls(item, into);
71
+ return into;
72
+ case 'comprehension':
73
+ stepFoldCalls(node.source, into);
74
+ if (node.valueExpr !== undefined)
75
+ stepFoldCalls(node.valueExpr, into);
76
+ if (node.predicate !== undefined)
77
+ stepFoldCalls(node.predicate, into);
78
+ return into;
79
+ case 'call':
80
+ if (node.op === 'rule_ok_in' || node.op === 'no_blocking_in' || node.op === 'required_in') {
81
+ into.push(node);
82
+ }
83
+ for (const arg of node.args)
84
+ stepFoldCalls(arg, into);
85
+ return into;
86
+ default:
87
+ for (const arg of node.args)
88
+ stepFoldCalls(arg, into);
89
+ return into;
90
+ }
91
+ }
92
+ /** Every rule-reference built-in a compiled expression uses, with the slot that used it. */
93
+ export function ruleReferenceUses(node, into = []) {
94
+ switch (node.kind) {
95
+ case 'literal':
96
+ case 'path':
97
+ return into;
98
+ case 'list':
99
+ for (const item of node.items)
100
+ ruleReferenceUses(item, into);
101
+ return into;
102
+ case 'comprehension':
103
+ ruleReferenceUses(node.source, into);
104
+ if (node.valueExpr !== undefined)
105
+ ruleReferenceUses(node.valueExpr, into);
106
+ if (node.predicate !== undefined)
107
+ ruleReferenceUses(node.predicate, into);
108
+ return into;
109
+ case 'call':
110
+ if (node.op === 'rule_ok' ||
111
+ node.op === 'no_blocking' ||
112
+ node.op === 'rule_ok_in' ||
113
+ node.op === 'no_blocking_in' ||
114
+ node.op === 'required_in') {
115
+ into.push({ op: node.op });
116
+ }
117
+ for (const arg of node.args)
118
+ ruleReferenceUses(arg, into);
119
+ return into;
120
+ default:
121
+ for (const arg of node.args)
122
+ ruleReferenceUses(arg, into);
123
+ return into;
124
+ }
125
+ }
126
+ //# sourceMappingURL=references.js.map