@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,404 @@
1
+ import { toMoneyValue, valueDomainOf } from '@azx-pbc/axiom-runtime';
2
+ /** The money type of a declaration that pins nothing: `money<unknown, unknown>`. */
3
+ const UNKNOWN_MONEY = { currency: undefined, scale: undefined };
4
+ const UNKNOWN_QUANTITY = { units: undefined, scale: undefined };
5
+ const UNKNOWN_DURATION = { unit: undefined };
6
+ const NUMERIC = new Set(['integer', 'decimal']);
7
+ export const ORDERABLE = new Set([
8
+ 'integer',
9
+ 'decimal',
10
+ 'string',
11
+ 'date',
12
+ 'instant',
13
+ 'time',
14
+ 'money',
15
+ 'quantity',
16
+ 'duration',
17
+ ]);
18
+ export function primitiveType(primitive, money, nullable = false, quantity, duration) {
19
+ // A money type always states both parameters; `money<unknown, unknown>` is the unpinned
20
+ // one. A quantity type states its units and scale the same way. No other primitive carries
21
+ // a parameter, so the members are absent there.
22
+ if (primitive === 'money') {
23
+ return {
24
+ kind: 'primitive',
25
+ primitive,
26
+ money: money ?? UNKNOWN_MONEY,
27
+ ...(nullable ? { nullable: true } : {}),
28
+ };
29
+ }
30
+ if (primitive === 'quantity') {
31
+ return {
32
+ kind: 'primitive',
33
+ primitive,
34
+ quantity: quantity ?? UNKNOWN_QUANTITY,
35
+ ...(nullable ? { nullable: true } : {}),
36
+ };
37
+ }
38
+ if (primitive === 'duration') {
39
+ return {
40
+ kind: 'primitive',
41
+ primitive,
42
+ duration: duration ?? UNKNOWN_DURATION,
43
+ ...(nullable ? { nullable: true } : {}),
44
+ };
45
+ }
46
+ return { kind: 'primitive', primitive, ...(nullable ? { nullable: true } : {}) };
47
+ }
48
+ /** Whether the type may also be the empty value `null`. */
49
+ export function isNullable(type) {
50
+ return type.kind === 'primitive' && type.nullable === true;
51
+ }
52
+ /**
53
+ * The same type with its `null` arm stated or removed.
54
+ *
55
+ * `??` replaces `null` with its right operand (`EXPR-9.1.3`), so a coalesce is nullable
56
+ * exactly when its last operand can itself be `null`; the helper states that without
57
+ * rebuilding a list or record type.
58
+ */
59
+ export function withNullability(type, nullable) {
60
+ if (type.kind !== 'primitive')
61
+ return type;
62
+ const { money, quantity, duration } = type;
63
+ return primitiveType(type.primitive, money, nullable, quantity, duration);
64
+ }
65
+ /** The parameters of a money type, or `undefined` when `type` is not money. */
66
+ export function moneyDomainOf(type) {
67
+ return type.kind === 'primitive' && type.primitive === 'money'
68
+ ? (type.money ?? UNKNOWN_MONEY)
69
+ : undefined;
70
+ }
71
+ /** The parameters of a quantity type, or `undefined` when `type` is not quantity. */
72
+ export function quantityDomainOf(type) {
73
+ return type.kind === 'primitive' && type.primitive === 'quantity'
74
+ ? (type.quantity ?? UNKNOWN_QUANTITY)
75
+ : undefined;
76
+ }
77
+ /** The parameter of a duration type, or `undefined` when `type` is not duration. */
78
+ export function durationDomainOf(type) {
79
+ return type.kind === 'primitive' && type.primitive === 'duration'
80
+ ? (type.duration ?? UNKNOWN_DURATION)
81
+ : undefined;
82
+ }
83
+ /** A duration declaration's unit, from the field or item that states it. */
84
+ export function durationUnitName(domain) {
85
+ return domain.unit ?? 'unknown';
86
+ }
87
+ /**
88
+ * The two duration units as one type, or `undefined` when the declarations name different
89
+ * units. An `unknown` unit unifies with anything and stays `unknown`; a proven difference means
90
+ * no value satisfies both, so the operation is a compile error rather than a deferred one.
91
+ */
92
+ export function unifyDuration(left, right) {
93
+ const unit = left.unit === undefined || right.unit === undefined
94
+ ? undefined
95
+ : left.unit === right.unit
96
+ ? left.unit
97
+ : MISMATCH;
98
+ return unit === MISMATCH ? undefined : { unit };
99
+ }
100
+ /** How a quantity spelling reads in a refusal: `sqm|lm@2`, with `unknown` for an unpinned slot. */
101
+ export function quantityName(domain) {
102
+ const units = domain.units === undefined ? 'unknown' : domain.units.join('|');
103
+ return `${units}@${domain.scale === undefined ? 'unknown' : String(domain.scale)}`;
104
+ }
105
+ /**
106
+ * The two quantity parameters as one type, or `undefined` when the two declarations share no
107
+ * unit. An `unknown` slot unifies with anything and yields `unknown`; two disjoint unit sets
108
+ * prove no value can satisfy both, so the operation is refused rather than deferred.
109
+ */
110
+ export function unifyQuantity(left, right) {
111
+ const units = left.units === undefined || right.units === undefined
112
+ ? undefined
113
+ : left.units.filter((unit) => right.units?.includes(unit));
114
+ if (units !== undefined && units.length === 0)
115
+ return undefined;
116
+ const scale = left.scale === right.scale ? left.scale : undefined;
117
+ return { units, scale };
118
+ }
119
+ /** How a money spelling reads in a refusal: `AUD/2`, with `unknown` for an unpinned slot. */
120
+ export function moneySpellingName(domain) {
121
+ return `${domain.currency ?? 'unknown'}/${domain.scale === undefined ? 'unknown' : String(domain.scale)}`;
122
+ }
123
+ /**
124
+ * The two money parameters as one type, or `undefined` when the two spellings cannot be one
125
+ * value. An `unknown` slot unifies with anything and yields `unknown`: the runtime decides
126
+ * from the value, and a real mismatch there is refused then (`EXPR-12.1.3`).
127
+ */
128
+ /** A slot that proved two different literals; never a value a money type may hold. */
129
+ const MISMATCH = Symbol('money-mismatch');
130
+ export function unifyMoney(left, right) {
131
+ // `undefined` is the `unknown` slot and unifies with anything, yielding `unknown`.
132
+ const currency = left.currency === undefined || right.currency === undefined
133
+ ? undefined
134
+ : left.currency === right.currency
135
+ ? left.currency
136
+ : MISMATCH;
137
+ if (currency === MISMATCH)
138
+ return undefined;
139
+ const scale = left.scale === undefined || right.scale === undefined
140
+ ? undefined
141
+ : left.scale === right.scale
142
+ ? left.scale
143
+ : MISMATCH;
144
+ if (scale === MISMATCH)
145
+ return undefined;
146
+ return { currency, scale };
147
+ }
148
+ /** The money spelling a money literal states, or none when the value is not one. */
149
+ export function literalMoneyDomain(value) {
150
+ try {
151
+ const money = toMoneyValue(value);
152
+ return { currency: money.currency, scale: money.scale };
153
+ }
154
+ catch {
155
+ // A malformed literal is refused by its own diagnostic before this reads it; a type
156
+ // with no pinned spelling is the honest answer here rather than a second refusal.
157
+ return UNKNOWN_MONEY;
158
+ }
159
+ }
160
+ /** The units and scale a quantity literal states, or none when the value is not one. */
161
+ export function literalQuantityDomain(value) {
162
+ if (typeof value !== 'object' || value === null || Array.isArray(value))
163
+ return UNKNOWN_QUANTITY;
164
+ const unit = Reflect.get(value, 'unit');
165
+ const amount = Reflect.get(value, 'value');
166
+ if (typeof unit !== 'string' || typeof amount !== 'string')
167
+ return UNKNOWN_QUANTITY;
168
+ return { units: [unit], scale: undefined };
169
+ }
170
+ export function typeName(type) {
171
+ switch (type.kind) {
172
+ case 'primitive': {
173
+ const money = moneyDomainOf(type);
174
+ const quantity = quantityDomainOf(type);
175
+ const duration = durationDomainOf(type);
176
+ const name = money !== undefined
177
+ ? `money<${money.currency ?? 'unknown'}, ${money.scale === undefined ? 'unknown' : String(money.scale)}>`
178
+ : quantity !== undefined
179
+ ? `quantity<${quantity.units === undefined ? 'unknown' : quantity.units.join('|')}, ${quantity.scale === undefined ? 'unknown' : String(quantity.scale)}>${quantity.fieldId === undefined ? '' : ` on field \`${quantity.fieldId}\``}`
180
+ : duration !== undefined
181
+ ? `duration<${duration.unit ?? 'unknown'}>${duration.fieldId === undefined ? '' : ` on field \`${duration.fieldId}\``}`
182
+ : type.primitive;
183
+ return type.nullable === true ? `${name} | null` : name;
184
+ }
185
+ case 'record':
186
+ return 'record';
187
+ case 'list':
188
+ return type.element === undefined ? 'list' : `list<${typeName(type.element)}>`;
189
+ }
190
+ }
191
+ export function isPrimitive(type, ...primitives) {
192
+ return type.kind === 'primitive' && primitives.includes(type.primitive);
193
+ }
194
+ export function isBoolean(type) {
195
+ return isPrimitive(type, 'boolean');
196
+ }
197
+ export function isNumeric(type) {
198
+ return type.kind === 'primitive' && NUMERIC.has(type.primitive);
199
+ }
200
+ /**
201
+ * The common type two operands unify to, or `undefined`. `integer` and `decimal` widen to
202
+ * `decimal`; `null` unifies with any type because it is the empty value of every domain
203
+ * lists unify element-wise.
204
+ */
205
+ export function unify(left, right) {
206
+ if (isPrimitive(left, 'null'))
207
+ return right;
208
+ if (isPrimitive(right, 'null'))
209
+ return left;
210
+ if (left.kind === 'primitive' && right.kind === 'primitive') {
211
+ // `null` is one value of every domain, so either operand's `null` arm is inherited by
212
+ // the unified type rather than erased: `if(c, parse_integer(s), null)` is `integer | null`.
213
+ const nullable = isNullable(left) || isNullable(right);
214
+ if (left.primitive === right.primitive) {
215
+ if (left.primitive === 'money') {
216
+ const money = unifyMoney(moneyDomainOf(left) ?? UNKNOWN_MONEY, moneyDomainOf(right) ?? UNKNOWN_MONEY);
217
+ return money === undefined ? undefined : primitiveType('money', money, nullable);
218
+ }
219
+ if (left.primitive === 'quantity') {
220
+ const quantity = unifyQuantity(quantityDomainOf(left) ?? UNKNOWN_QUANTITY, quantityDomainOf(right) ?? UNKNOWN_QUANTITY);
221
+ return quantity === undefined
222
+ ? undefined
223
+ : primitiveType('quantity', undefined, nullable, quantity);
224
+ }
225
+ if (left.primitive === 'duration') {
226
+ const duration = unifyDuration(durationDomainOf(left) ?? UNKNOWN_DURATION, durationDomainOf(right) ?? UNKNOWN_DURATION);
227
+ return duration === undefined
228
+ ? undefined
229
+ : primitiveType('duration', undefined, nullable, undefined, duration);
230
+ }
231
+ return primitiveType(left.primitive, undefined, nullable);
232
+ }
233
+ if (NUMERIC.has(left.primitive) && NUMERIC.has(right.primitive)) {
234
+ return primitiveType('decimal', undefined, nullable);
235
+ }
236
+ return undefined;
237
+ }
238
+ if (left.kind === 'list' && right.kind === 'list') {
239
+ // An empty literal is neutral in a unification; an open context array is not. Preserve
240
+ // openness even when the other branch has a known element type, so a later write cannot
241
+ // mistake the open branch for a closed value of that type.
242
+ if (left.element === undefined) {
243
+ return left.open ? { kind: 'list', element: right.element, open: true } : right;
244
+ }
245
+ if (right.element === undefined) {
246
+ return right.open ? { kind: 'list', element: left.element, open: true } : left;
247
+ }
248
+ const element = unify(left.element, right.element);
249
+ return element === undefined
250
+ ? undefined
251
+ : { kind: 'list', element, open: left.open || right.open };
252
+ }
253
+ if (left.kind === 'record' && right.kind === 'record') {
254
+ if (left.open || right.open)
255
+ return { kind: 'record', fields: [], open: true };
256
+ // Two closed records unify only when they state the same members. Returning the left
257
+ // branch's fields made `if(c, {p}, {q}).p` typecheck while the right branch never had a
258
+ // `p`; there is no type that guarantees both members, so `EXPR-6.1.6`'s common type does
259
+ // not exist and the refusal is `undefined`.
260
+ return sameFieldSets(left.fields, right.fields)
261
+ ? { kind: 'record', fields: left.fields, open: false }
262
+ : undefined;
263
+ }
264
+ return undefined;
265
+ }
266
+ /** Whether two declared member lists state the same members, in any order. */
267
+ function sameFieldSets(left, right) {
268
+ if (left.length !== right.length)
269
+ return false;
270
+ const byId = new Map(right.map((field) => [field.fieldId, field]));
271
+ return left.every((field) => {
272
+ const other = byId.get(field.fieldId);
273
+ return other !== undefined && sameFieldDeclaration(field, other);
274
+ });
275
+ }
276
+ /** The ordered unit list one quantity declaration states, with an absent list as empty. */
277
+ function sameUnits(left, right) {
278
+ const mine = left ?? [];
279
+ const theirs = right ?? [];
280
+ return mine.length === theirs.length && mine.every((unit, index) => unit === theirs[index]);
281
+ }
282
+ /**
283
+ * Whether two members of the same identifier state the same value type.
284
+ *
285
+ * The parameters travel with the primitive: `money<AUD,2>` and `money<NZD,2>` are different
286
+ * types, as are two quantity unit sets and two duration units. A record or array member
287
+ * recurses, so a nested difference cannot hide behind an equal `fieldId`.
288
+ */
289
+ function sameFieldDeclaration(left, right) {
290
+ if (left.primitive !== right.primitive)
291
+ return false;
292
+ switch (left.primitive) {
293
+ case 'money':
294
+ return left.currency === right.currency && left.scale === right.scale;
295
+ case 'quantity':
296
+ return left.scale === right.scale && sameUnits(left.units, right.units);
297
+ case 'duration':
298
+ return left.unit === right.unit;
299
+ case 'array':
300
+ return (sameItemDeclaration(left.items, right.items) && sameFieldOption(left.fields, right.fields));
301
+ case 'record':
302
+ return sameFieldOption(left.fields, right.fields);
303
+ default:
304
+ return true;
305
+ }
306
+ }
307
+ /** Two optional nested member lists: both absent, or the same members. */
308
+ function sameFieldOption(left, right) {
309
+ if (left === undefined || right === undefined)
310
+ return left === right;
311
+ return sameFieldSets(left, right);
312
+ }
313
+ /** Whether two array item declarations state the same element type. */
314
+ function sameItemDeclaration(left, right) {
315
+ if (left === undefined || right === undefined)
316
+ return left === right;
317
+ if (left.primitive !== right.primitive)
318
+ return false;
319
+ switch (left.primitive) {
320
+ case 'money':
321
+ return left.currency === right.currency && left.scale === right.scale;
322
+ case 'quantity':
323
+ return left.scale === right.scale && sameUnits(left.units, right.units);
324
+ case 'duration':
325
+ return left.unit === right.unit;
326
+ default:
327
+ return true;
328
+ }
329
+ }
330
+ /**
331
+ * The type one element of a declared array has, or `undefined` when the declaration states
332
+ * no element type.
333
+ *
334
+ * A scalar or attachment array declares `items`, so its elements are that primitive; a record
335
+ * array declares `fields`, so its elements are that record. An intrinsic array member such as
336
+ * `media_ref.tags` declares neither, and the published contract describes no element for it,
337
+ * so it is an open list. One derivation serves the array's own type and an item-scoped rule's
338
+ * `$it`, so a rule that reads a scalar element and the read of the list cannot disagree about
339
+ * what an element is.
340
+ */
341
+ /**
342
+ * The static type one value domain has, as an expression reading it would see it.
343
+ *
344
+ * The domain is the runtime's `valueDomainOf`, so the type a declaration is checked under and
345
+ * the declaration the wire reader validates are one derivation. `sourceFieldId` only names the
346
+ * declaration in a refusal (`on field \`f_q\``); it changes no part of the type.
347
+ */
348
+ export function staticTypeOfDomain(domain, sourceFieldId) {
349
+ switch (domain.primitive) {
350
+ case 'array': {
351
+ const recordElement = {
352
+ kind: 'record',
353
+ fields: domain.fields ?? [],
354
+ open: false,
355
+ };
356
+ const element = domain.items !== undefined
357
+ ? staticTypeOfDomain(domain.items)
358
+ : domain.fields !== undefined
359
+ ? recordElement
360
+ : undefined;
361
+ // An array that declares neither `items` nor `fields` states no element type. It is an
362
+ // open list, not an empty record list: inventing `record{}` made a valid member read
363
+ // (`contains(f_photo.tags, "x")`) look like a record comparison.
364
+ return { kind: 'list', element, open: element === undefined };
365
+ }
366
+ case 'record':
367
+ return { kind: 'record', fields: domain.fields ?? [], open: false };
368
+ case 'money':
369
+ return primitiveType('money', { currency: domain.currency, scale: domain.scale });
370
+ case 'quantity':
371
+ return primitiveType('quantity', undefined, false, {
372
+ units: domain.units,
373
+ scale: domain.scale,
374
+ ...(sourceFieldId === undefined ? {} : { fieldId: sourceFieldId }),
375
+ });
376
+ case 'duration':
377
+ return primitiveType('duration', undefined, false, undefined, {
378
+ unit: domain.unit,
379
+ ...(sourceFieldId === undefined ? {} : { fieldId: sourceFieldId }),
380
+ });
381
+ default:
382
+ return primitiveType(domain.primitive);
383
+ }
384
+ }
385
+ /**
386
+ * The type one element of a declared array has, or `undefined` when the declaration states
387
+ * no element type.
388
+ *
389
+ * A scalar or attachment array declares `items`, so its elements are that primitive; a record
390
+ * array declares `fields`, so its elements are that record. An intrinsic array member such as
391
+ * `media_ref.tags` declares neither, and the published contract describes no element for it,
392
+ * so it is an open list. One derivation serves the array's own type and an item-scoped rule's
393
+ * `$it`, so a rule that reads a scalar element and the read of the list cannot disagree about
394
+ * what an element is.
395
+ */
396
+ export function arrayElementType(field) {
397
+ const type = staticTypeOfDomain(valueDomainOf(field));
398
+ return type.kind === 'list' ? type.element : undefined;
399
+ }
400
+ /** The static type one declared field's own value has, as an expression reading it would see it. */
401
+ export function staticTypeOf(field) {
402
+ return staticTypeOfDomain(valueDomainOf(field), field.fieldId);
403
+ }
404
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/expr/typecheck/types.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AA2BrE,oFAAoF;AACpF,MAAM,aAAa,GAAgB,EAAE,QAAQ,EAAE,SAAS,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC;AAiB7E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Primitive, WireValue } from '@azx-pbc/axiom-runtime';\nimport { toMoneyValue, valueDomainOf } from '@azx-pbc/axiom-runtime';\nimport type { ValueDomain } from '@azx-pbc/axiom-runtime';\n\n/**\n * Static typing of Expr v1, `spec/semantics/expr-v1.md` section 6 and the per-built-in\n * table.\n *\n * Every expression has exactly one type, resolved against the declarations it is compiled\n * for. A refusal names the offending segment with the expected and actual types, and a\n * misspelled identifier or path segment carries a bounded suggestion drawn from the\n * declarations in scope.\n */\n\n/**\n * The money type's two parameters: `money<currency, scale>`, each slot a literal or\n * `undefined` for `unknown`.\n *\n * Money carries its currency and scale in the value, so `money` alone cannot say whether two\n * amounts may be added. A declaration (`field.currency`, `field.scale`), a money literal and\n * `money_from_minor` with literal arguments each pin one; a declaration that states neither\n * is `money<unknown, unknown>`, and the runtime decides then (`EXPR-12.1.3`).\n */\nexport interface MoneyDomain {\n readonly currency: string | undefined;\n readonly scale: number | undefined;\n}\n\n/** The money type of a declaration that pins nothing: `money<unknown, unknown>`. */\nconst UNKNOWN_MONEY: MoneyDomain = { currency: undefined, scale: undefined };\n\n/**\n * The quantity type's parameters: `quantity<units, scale>`, `MODEL-2.1.21`.\n *\n * The unit set is the field's declared domain, so two quantity types with disjoint sets cannot\n * be added or compared: the compiler refuses the static mismatch and the runtime refuses a\n * value-stated one. `scale` is the largest number of fractional digits the declaration admits;\n * arithmetic keeps exact decimal text rather than rounding to it.\n */\nexport interface QuantityDomain {\n readonly units: readonly string[] | undefined;\n readonly scale: number | undefined;\n /** The declaration the domain came from, so a mixed-unit refusal can name the field. */\n readonly fieldId?: string;\n}\n\nconst UNKNOWN_QUANTITY: QuantityDomain = { units: undefined, scale: undefined };\n\n/**\n * The duration type's parameter: `duration<unit>`, `MODEL-2.1.24`.\n *\n * The unit is the field's declared unit (default `minutes`), so two durations with different\n * units cannot be added, compared or folded: the compiler refuses the static mismatch and the\n * runtime refuses a value-stated one. `undefined` is the unpinned unit, where the runtime decides.\n */\nexport interface DurationDomain {\n readonly unit: string | undefined;\n /** The declaration the domain came from, so a mixed-unit refusal can name the field. */\n readonly fieldId?: string;\n}\n\nconst UNKNOWN_DURATION: DurationDomain = { unit: undefined };\n\nexport type StaticType =\n | {\n readonly kind: 'primitive';\n readonly primitive: Primitive | 'null';\n /** The parameters a `money` type carries; absent for every other primitive. */\n readonly money?: MoneyDomain;\n /** The parameters a `quantity` type carries; absent for every other primitive. */\n readonly quantity?: QuantityDomain;\n /** The parameter a `duration` type carries; absent for every other primitive. */\n readonly duration?: DurationDomain;\n /**\n * Whether the value may also be the empty value `null`, `EXPR-6.1.12`.\n *\n * `parse_integer` and `parse_decimal` answer `null` when the text spells nothing, so\n * their declared type is `integer | null` and `decimal | null`. `null` is not a type\n * that refuses an operation — a construct that consumes it lifts to `UNKNOWN`\n * (`EXPR-5.1.12`) — so this flag exists to state the signature, and to let `??` and\n * `if` report the type they actually produce, not to narrow what the operators accept.\n */\n readonly nullable?: true;\n }\n | { readonly kind: 'list'; readonly element: StaticType | undefined; readonly open: boolean }\n | { readonly kind: 'record'; readonly fields: readonly CompiledField[]; readonly open: boolean };\n\nconst NUMERIC: ReadonlySet<string> = new Set(['integer', 'decimal']);\n\nexport const ORDERABLE: ReadonlySet<string> = new Set([\n 'integer',\n 'decimal',\n 'string',\n 'date',\n 'instant',\n 'time',\n 'money',\n 'quantity',\n 'duration',\n]);\n\nexport function primitiveType(\n primitive: Primitive | 'null',\n money?: MoneyDomain,\n nullable = false,\n quantity?: QuantityDomain,\n duration?: DurationDomain,\n): StaticType {\n // A money type always states both parameters; `money<unknown, unknown>` is the unpinned\n // one. A quantity type states its units and scale the same way. No other primitive carries\n // a parameter, so the members are absent there.\n if (primitive === 'money') {\n return {\n kind: 'primitive',\n primitive,\n money: money ?? UNKNOWN_MONEY,\n ...(nullable ? { nullable: true } : {}),\n };\n }\n if (primitive === 'quantity') {\n return {\n kind: 'primitive',\n primitive,\n quantity: quantity ?? UNKNOWN_QUANTITY,\n ...(nullable ? { nullable: true } : {}),\n };\n }\n if (primitive === 'duration') {\n return {\n kind: 'primitive',\n primitive,\n duration: duration ?? UNKNOWN_DURATION,\n ...(nullable ? { nullable: true } : {}),\n };\n }\n return { kind: 'primitive', primitive, ...(nullable ? { nullable: true } : {}) };\n}\n\n/** Whether the type may also be the empty value `null`. */\nexport function isNullable(type: StaticType): boolean {\n return type.kind === 'primitive' && type.nullable === true;\n}\n\n/**\n * The same type with its `null` arm stated or removed.\n *\n * `??` replaces `null` with its right operand (`EXPR-9.1.3`), so a coalesce is nullable\n * exactly when its last operand can itself be `null`; the helper states that without\n * rebuilding a list or record type.\n */\nexport function withNullability(type: StaticType, nullable: boolean): StaticType {\n if (type.kind !== 'primitive') return type;\n const { money, quantity, duration } = type;\n return primitiveType(type.primitive, money, nullable, quantity, duration);\n}\n\n/** The parameters of a money type, or `undefined` when `type` is not money. */\nexport function moneyDomainOf(type: StaticType): MoneyDomain | undefined {\n return type.kind === 'primitive' && type.primitive === 'money'\n ? (type.money ?? UNKNOWN_MONEY)\n : undefined;\n}\n\n/** The parameters of a quantity type, or `undefined` when `type` is not quantity. */\nexport function quantityDomainOf(type: StaticType): QuantityDomain | undefined {\n return type.kind === 'primitive' && type.primitive === 'quantity'\n ? (type.quantity ?? UNKNOWN_QUANTITY)\n : undefined;\n}\n\n/** The parameter of a duration type, or `undefined` when `type` is not duration. */\nexport function durationDomainOf(type: StaticType): DurationDomain | undefined {\n return type.kind === 'primitive' && type.primitive === 'duration'\n ? (type.duration ?? UNKNOWN_DURATION)\n : undefined;\n}\n\n/** A duration declaration's unit, from the field or item that states it. */\nexport function durationUnitName(domain: DurationDomain): string {\n return domain.unit ?? 'unknown';\n}\n\n/**\n * The two duration units as one type, or `undefined` when the declarations name different\n * units. An `unknown` unit unifies with anything and stays `unknown`; a proven difference means\n * no value satisfies both, so the operation is a compile error rather than a deferred one.\n */\nexport function unifyDuration(\n left: DurationDomain,\n right: DurationDomain,\n): DurationDomain | undefined {\n const unit =\n left.unit === undefined || right.unit === undefined\n ? undefined\n : left.unit === right.unit\n ? left.unit\n : MISMATCH;\n return unit === MISMATCH ? undefined : { unit };\n}\n\n/** How a quantity spelling reads in a refusal: `sqm|lm@2`, with `unknown` for an unpinned slot. */\nexport function quantityName(domain: QuantityDomain): string {\n const units = domain.units === undefined ? 'unknown' : domain.units.join('|');\n return `${units}@${domain.scale === undefined ? 'unknown' : String(domain.scale)}`;\n}\n\n/**\n * The two quantity parameters as one type, or `undefined` when the two declarations share no\n * unit. An `unknown` slot unifies with anything and yields `unknown`; two disjoint unit sets\n * prove no value can satisfy both, so the operation is refused rather than deferred.\n */\nexport function unifyQuantity(\n left: QuantityDomain,\n right: QuantityDomain,\n): QuantityDomain | undefined {\n const units =\n left.units === undefined || right.units === undefined\n ? undefined\n : left.units.filter((unit) => right.units?.includes(unit));\n if (units !== undefined && units.length === 0) return undefined;\n const scale = left.scale === right.scale ? left.scale : undefined;\n return { units, scale };\n}\n\n/** How a money spelling reads in a refusal: `AUD/2`, with `unknown` for an unpinned slot. */\nexport function moneySpellingName(domain: MoneyDomain): string {\n return `${domain.currency ?? 'unknown'}/${domain.scale === undefined ? 'unknown' : String(domain.scale)}`;\n}\n\n/**\n * The two money parameters as one type, or `undefined` when the two spellings cannot be one\n * value. An `unknown` slot unifies with anything and yields `unknown`: the runtime decides\n * from the value, and a real mismatch there is refused then (`EXPR-12.1.3`).\n */\n/** A slot that proved two different literals; never a value a money type may hold. */\nconst MISMATCH = Symbol('money-mismatch');\n\nexport function unifyMoney(left: MoneyDomain, right: MoneyDomain): MoneyDomain | undefined {\n // `undefined` is the `unknown` slot and unifies with anything, yielding `unknown`.\n const currency =\n left.currency === undefined || right.currency === undefined\n ? undefined\n : left.currency === right.currency\n ? left.currency\n : MISMATCH;\n if (currency === MISMATCH) return undefined;\n const scale =\n left.scale === undefined || right.scale === undefined\n ? undefined\n : left.scale === right.scale\n ? left.scale\n : MISMATCH;\n if (scale === MISMATCH) return undefined;\n return { currency, scale };\n}\n\n/** The money spelling a money literal states, or none when the value is not one. */\nexport function literalMoneyDomain(value: WireValue): MoneyDomain {\n try {\n const money = toMoneyValue(value);\n return { currency: money.currency, scale: money.scale };\n } catch {\n // A malformed literal is refused by its own diagnostic before this reads it; a type\n // with no pinned spelling is the honest answer here rather than a second refusal.\n return UNKNOWN_MONEY;\n }\n}\n\n/** The units and scale a quantity literal states, or none when the value is not one. */\nexport function literalQuantityDomain(value: WireValue): QuantityDomain {\n if (typeof value !== 'object' || value === null || Array.isArray(value)) return UNKNOWN_QUANTITY;\n const unit = Reflect.get(value, 'unit');\n const amount = Reflect.get(value, 'value');\n if (typeof unit !== 'string' || typeof amount !== 'string') return UNKNOWN_QUANTITY;\n return { units: [unit], scale: undefined };\n}\n\nexport function typeName(type: StaticType): string {\n switch (type.kind) {\n case 'primitive': {\n const money = moneyDomainOf(type);\n const quantity = quantityDomainOf(type);\n const duration = durationDomainOf(type);\n const name =\n money !== undefined\n ? `money<${money.currency ?? 'unknown'}, ${money.scale === undefined ? 'unknown' : String(money.scale)}>`\n : quantity !== undefined\n ? `quantity<${quantity.units === undefined ? 'unknown' : quantity.units.join('|')}, ${quantity.scale === undefined ? 'unknown' : String(quantity.scale)}>${quantity.fieldId === undefined ? '' : ` on field \\`${quantity.fieldId}\\``}`\n : duration !== undefined\n ? `duration<${duration.unit ?? 'unknown'}>${duration.fieldId === undefined ? '' : ` on field \\`${duration.fieldId}\\``}`\n : type.primitive;\n return type.nullable === true ? `${name} | null` : name;\n }\n case 'record':\n return 'record';\n case 'list':\n return type.element === undefined ? 'list' : `list<${typeName(type.element)}>`;\n }\n}\n\nexport function isPrimitive(type: StaticType, ...primitives: readonly string[]): boolean {\n return type.kind === 'primitive' && primitives.includes(type.primitive);\n}\n\nexport function isBoolean(type: StaticType): boolean {\n return isPrimitive(type, 'boolean');\n}\n\nexport function isNumeric(type: StaticType): boolean {\n return type.kind === 'primitive' && NUMERIC.has(type.primitive);\n}\n\n/**\n * The common type two operands unify to, or `undefined`. `integer` and `decimal` widen to\n * `decimal`; `null` unifies with any type because it is the empty value of every domain\n * lists unify element-wise.\n */\nexport function unify(left: StaticType, right: StaticType): StaticType | undefined {\n if (isPrimitive(left, 'null')) return right;\n if (isPrimitive(right, 'null')) return left;\n if (left.kind === 'primitive' && right.kind === 'primitive') {\n // `null` is one value of every domain, so either operand's `null` arm is inherited by\n // the unified type rather than erased: `if(c, parse_integer(s), null)` is `integer | null`.\n const nullable = isNullable(left) || isNullable(right);\n if (left.primitive === right.primitive) {\n if (left.primitive === 'money') {\n const money = unifyMoney(\n moneyDomainOf(left) ?? UNKNOWN_MONEY,\n moneyDomainOf(right) ?? UNKNOWN_MONEY,\n );\n return money === undefined ? undefined : primitiveType('money', money, nullable);\n }\n if (left.primitive === 'quantity') {\n const quantity = unifyQuantity(\n quantityDomainOf(left) ?? UNKNOWN_QUANTITY,\n quantityDomainOf(right) ?? UNKNOWN_QUANTITY,\n );\n return quantity === undefined\n ? undefined\n : primitiveType('quantity', undefined, nullable, quantity);\n }\n if (left.primitive === 'duration') {\n const duration = unifyDuration(\n durationDomainOf(left) ?? UNKNOWN_DURATION,\n durationDomainOf(right) ?? UNKNOWN_DURATION,\n );\n return duration === undefined\n ? undefined\n : primitiveType('duration', undefined, nullable, undefined, duration);\n }\n return primitiveType(left.primitive, undefined, nullable);\n }\n if (NUMERIC.has(left.primitive) && NUMERIC.has(right.primitive)) {\n return primitiveType('decimal', undefined, nullable);\n }\n return undefined;\n }\n if (left.kind === 'list' && right.kind === 'list') {\n // An empty literal is neutral in a unification; an open context array is not. Preserve\n // openness even when the other branch has a known element type, so a later write cannot\n // mistake the open branch for a closed value of that type.\n if (left.element === undefined) {\n return left.open ? { kind: 'list', element: right.element, open: true } : right;\n }\n if (right.element === undefined) {\n return right.open ? { kind: 'list', element: left.element, open: true } : left;\n }\n const element = unify(left.element, right.element);\n return element === undefined\n ? undefined\n : { kind: 'list', element, open: left.open || right.open };\n }\n if (left.kind === 'record' && right.kind === 'record') {\n if (left.open || right.open) return { kind: 'record', fields: [], open: true };\n // Two closed records unify only when they state the same members. Returning the left\n // branch's fields made `if(c, {p}, {q}).p` typecheck while the right branch never had a\n // `p`; there is no type that guarantees both members, so `EXPR-6.1.6`'s common type does\n // not exist and the refusal is `undefined`.\n return sameFieldSets(left.fields, right.fields)\n ? { kind: 'record', fields: left.fields, open: false }\n : undefined;\n }\n return undefined;\n}\n\n/** Whether two declared member lists state the same members, in any order. */\nfunction sameFieldSets(left: readonly CompiledField[], right: readonly CompiledField[]): boolean {\n if (left.length !== right.length) return false;\n const byId = new Map(right.map((field) => [field.fieldId, field]));\n return left.every((field) => {\n const other = byId.get(field.fieldId);\n return other !== undefined && sameFieldDeclaration(field, other);\n });\n}\n\n/** The ordered unit list one quantity declaration states, with an absent list as empty. */\nfunction sameUnits(\n left: readonly string[] | undefined,\n right: readonly string[] | undefined,\n): boolean {\n const mine = left ?? [];\n const theirs = right ?? [];\n return mine.length === theirs.length && mine.every((unit, index) => unit === theirs[index]);\n}\n\n/**\n * Whether two members of the same identifier state the same value type.\n *\n * The parameters travel with the primitive: `money<AUD,2>` and `money<NZD,2>` are different\n * types, as are two quantity unit sets and two duration units. A record or array member\n * recurses, so a nested difference cannot hide behind an equal `fieldId`.\n */\nfunction sameFieldDeclaration(left: CompiledField, right: CompiledField): boolean {\n if (left.primitive !== right.primitive) return false;\n switch (left.primitive) {\n case 'money':\n return left.currency === right.currency && left.scale === right.scale;\n case 'quantity':\n return left.scale === right.scale && sameUnits(left.units, right.units);\n case 'duration':\n return left.unit === right.unit;\n case 'array':\n return (\n sameItemDeclaration(left.items, right.items) && sameFieldOption(left.fields, right.fields)\n );\n case 'record':\n return sameFieldOption(left.fields, right.fields);\n default:\n return true;\n }\n}\n\n/** Two optional nested member lists: both absent, or the same members. */\nfunction sameFieldOption(\n left: readonly CompiledField[] | undefined,\n right: readonly CompiledField[] | undefined,\n): boolean {\n if (left === undefined || right === undefined) return left === right;\n return sameFieldSets(left, right);\n}\n\n/** Whether two array item declarations state the same element type. */\nfunction sameItemDeclaration(left: FieldItem | undefined, right: FieldItem | undefined): boolean {\n if (left === undefined || right === undefined) return left === right;\n if (left.primitive !== right.primitive) return false;\n switch (left.primitive) {\n case 'money':\n return left.currency === right.currency && left.scale === right.scale;\n case 'quantity':\n return left.scale === right.scale && sameUnits(left.units, right.units);\n case 'duration':\n return left.unit === right.unit;\n default:\n return true;\n }\n}\n\n/**\n * The type one element of a declared array has, or `undefined` when the declaration states\n * no element type.\n *\n * A scalar or attachment array declares `items`, so its elements are that primitive; a record\n * array declares `fields`, so its elements are that record. An intrinsic array member such as\n * `media_ref.tags` declares neither, and the published contract describes no element for it,\n * so it is an open list. One derivation serves the array's own type and an item-scoped rule's\n * `$it`, so a rule that reads a scalar element and the read of the list cannot disagree about\n * what an element is.\n */\n/**\n * The static type one value domain has, as an expression reading it would see it.\n *\n * The domain is the runtime's `valueDomainOf`, so the type a declaration is checked under and\n * the declaration the wire reader validates are one derivation. `sourceFieldId` only names the\n * declaration in a refusal (`on field \\`f_q\\``); it changes no part of the type.\n */\nexport function staticTypeOfDomain(domain: ValueDomain, sourceFieldId?: string): StaticType {\n switch (domain.primitive) {\n case 'array': {\n const recordElement: StaticType = {\n kind: 'record',\n fields: domain.fields ?? [],\n open: false,\n };\n const element =\n domain.items !== undefined\n ? staticTypeOfDomain(domain.items)\n : domain.fields !== undefined\n ? recordElement\n : undefined;\n // An array that declares neither `items` nor `fields` states no element type. It is an\n // open list, not an empty record list: inventing `record{}` made a valid member read\n // (`contains(f_photo.tags, \"x\")`) look like a record comparison.\n return { kind: 'list', element, open: element === undefined };\n }\n case 'record':\n return { kind: 'record', fields: domain.fields ?? [], open: false };\n case 'money':\n return primitiveType('money', { currency: domain.currency, scale: domain.scale });\n case 'quantity':\n return primitiveType('quantity', undefined, false, {\n units: domain.units,\n scale: domain.scale,\n ...(sourceFieldId === undefined ? {} : { fieldId: sourceFieldId }),\n });\n case 'duration':\n return primitiveType('duration', undefined, false, undefined, {\n unit: domain.unit,\n ...(sourceFieldId === undefined ? {} : { fieldId: sourceFieldId }),\n });\n default:\n return primitiveType(domain.primitive);\n }\n}\n\n/**\n * The type one element of a declared array has, or `undefined` when the declaration states\n * no element type.\n *\n * A scalar or attachment array declares `items`, so its elements are that primitive; a record\n * array declares `fields`, so its elements are that record. An intrinsic array member such as\n * `media_ref.tags` declares neither, and the published contract describes no element for it,\n * so it is an open list. One derivation serves the array's own type and an item-scoped rule's\n * `$it`, so a rule that reads a scalar element and the read of the list cannot disagree about\n * what an element is.\n */\nexport function arrayElementType(field: CompiledField): StaticType | undefined {\n const type = staticTypeOfDomain(valueDomainOf(field));\n return type.kind === 'list' ? type.element : undefined;\n}\n\n/** The static type one declared field's own value has, as an expression reading it would see it. */\nexport function staticTypeOf(field: CompiledField): StaticType {\n return staticTypeOfDomain(valueDomainOf(field), field.fieldId);\n}\n"]}
@@ -0,0 +1,75 @@
1
+ import type { ExprNode, ExpressionDeclarations } from '@azx-pbc/axiom-runtime';
2
+ import type { LintFinding } from './lint.js';
3
+ import type { UndecidedFold } from './typecheck/fold.js';
4
+ import type { StaticType } from './typecheck/types.js';
5
+ /**
6
+ * Static typing of Expr v1, `spec/semantics/expr-v1.md` section 6 and the per-built-in
7
+ * table.
8
+ *
9
+ * Every expression has exactly one type, resolved against the declarations it is compiled
10
+ * for. A refusal names the offending segment with the expected and actual types, and a
11
+ * misspelled identifier or path segment carries a bounded suggestion drawn from the
12
+ * declarations in scope.
13
+ *
14
+ * This entry resolves declarations and walks the tree; the type algebra is `typecheck/types`,
15
+ * paths `typecheck/paths`, the structural forms `typecheck/compound`, and each operator
16
+ * family its own module under `typecheck/`.
17
+ */
18
+ export type { StaticType } from './typecheck/types.js';
19
+ export type { UndecidedFold } from './typecheck/fold.js';
20
+ export { typeName } from './typecheck/types.js';
21
+ /** The implicit binders a rule's own scope puts in force, and where fold findings go. */
22
+ export interface ExpressionScope {
23
+ /** The array an item-scoped expression addresses, whose item is `$it`. */
24
+ readonly itemFieldId?: string;
25
+ /**
26
+ * Where a fold that is legal but undecided on an empty list is recorded, so a caller decides
27
+ * whether the finding becomes a warning beside the artifact or is discarded with a refusal.
28
+ */
29
+ readonly onUndecidedFold?: (finding: UndecidedFold) => void;
30
+ /**
31
+ * Whether the build admits `matches`, defaulting to true. A caller that forbids regular
32
+ * expressions in its documents sets this false, and every `matches` call is then refused at
33
+ * compile time with a sentence naming the build rather than the pattern.
34
+ */
35
+ readonly allowRegex?: boolean;
36
+ /**
37
+ * Where a warning the static analysis proves is recorded. The compiler attaches the document
38
+ * path, because the checker knows the expression's offsets and not where the slot lives.
39
+ */
40
+ readonly onLintFinding?: (finding: LintFinding) => void;
41
+ /**
42
+ * Whether this expression may read the gate fold (`rule_ok`, `no_blocking` and the step
43
+ * folds). Defaults to true; the document compiler owns the gate rule that supplies the fold,
44
+ * while `compileExpr` has no gate host and passes false.
45
+ */
46
+ readonly allowGateFolds?: boolean;
47
+ /**
48
+ * Nodes in the checked tree that originated from an inlined computed definition rather than
49
+ * from the current expression slot, used to avoid re-reporting aggregate warnings that already
50
+ * belong to the definition's own slot.
51
+ */
52
+ readonly inlinedNodes?: WeakSet<ExprNode>;
53
+ }
54
+ /** Type-checks a parsed expression against its declarations and the scope it runs in. */
55
+ export declare function checkExpression(declarations: ExpressionDeclarations, node: ExprNode, offsets: WeakMap<ExprNode, number>, scope?: ExpressionScope, powerOperators?: WeakSet<ExprNode>, lengthProperties?: WeakSet<ExprNode>): StaticType;
56
+ /**
57
+ * The lint pass over the analysis tree, separate from the tree the author's slot emits.
58
+ *
59
+ * `compileExpressionSlot` types the emitted node, where the `in`-to-`contains` lowering must
60
+ * land, and analyses the substituted copy, where a computed definition is visible. The copy
61
+ * brings its own offsets map, so a finding inside it keeps the position of the path it reads
62
+ * rather than collapsing to `0`.
63
+ */
64
+ export declare function lintExpression(declarations: ExpressionDeclarations, node: ExprNode, offsets: WeakMap<ExprNode, number>, onFinding: (finding: LintFinding) => void, scope?: ExpressionScope): void;
65
+ /**
66
+ * Collects undecided-fold findings over the substituted analysis tree, where pure computed
67
+ * definitions are visible (so a computed non-empty list literal proves a fold decided).
68
+ *
69
+ * Returns `undefined` when static typing fails on the substituted tree (for example, when a
70
+ * compute rule widens an integer into a decimal field read by a decimal-only built-in, or when
71
+ * the computed definition is itself ill-typed), allowing the caller to fall back to the findings
72
+ * recorded on the emitted tree.
73
+ */
74
+ export declare function undecidedFolds(declarations: ExpressionDeclarations, node: ExprNode, offsets: WeakMap<ExprNode, number>, scope?: ExpressionScope): readonly UndecidedFold[] | undefined;
75
+ //# sourceMappingURL=typecheck.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"typecheck.d.ts","sourceRoot":"","sources":["../../src/expr/typecheck.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAIV,QAAQ,EACR,sBAAsB,EACvB,MAAM,wBAAwB,CAAC;AAGhC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAa7C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAGzD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAQvD;;;;;;;;;;;;GAYG;AAEH,YAAY,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AACvD,YAAY,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAmOhD,yFAAyF;AACzF,MAAM,WAAW,eAAe;IAC9B,0EAA0E;IAC1E,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAC9B;;;OAGG;IACH,QAAQ,CAAC,eAAe,CAAC,EAAE,CAAC,OAAO,EAAE,aAAa,KAAK,IAAI,CAAC;IAC5D;;;;OAIG;IACH,QAAQ,CAAC,UAAU,CAAC,EAAE,OAAO,CAAC;IAC9B;;;OAGG;IACH,QAAQ,CAAC,aAAa,CAAC,EAAE,CAAC,OAAO,EAAE,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