@azx-pbc/axiom-compiler 0.0.0-stage → 0.0.6

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,1180 @@
1
+ import { asDecimalString, canonicalDecimal, civilFromDays, compareDecimalTexts, daysBetween, daysFromCivil, instantToEpochMilliseconds, isRecord, minutesBetweenInstants, minutesBetweenTimes, monthsBetween, parseClockTime, parseDecimal, parsePlainDate, secondsSinceMidnight, } from '@azx-pbc/axiom-runtime';
2
+ import { codePointIndexOf, codePointLength } from './code-points.js';
3
+ const MAX_SAFE_INTEGER = BigInt(Number.MAX_SAFE_INTEGER);
4
+ const MIN_SAFE_INTEGER = -MAX_SAFE_INTEGER;
5
+ const TOP = { kind: 'top' };
6
+ function integerBound(value) {
7
+ return { kind: 'integer', value };
8
+ }
9
+ function decimalBound(value) {
10
+ return { kind: 'decimal', value: asDecimalString(value) };
11
+ }
12
+ function scalarBound(value) {
13
+ return { kind: 'scalar', value };
14
+ }
15
+ function boundOf(family, value) {
16
+ switch (family) {
17
+ case 'integer':
18
+ case 'money':
19
+ case 'duration':
20
+ return integerBound(BigInt(value));
21
+ case 'decimal':
22
+ return decimalBound(String(value));
23
+ case 'date':
24
+ case 'instant':
25
+ case 'time':
26
+ return scalarBound(Number(value));
27
+ }
28
+ }
29
+ function familyOfPrimitive(primitive) {
30
+ switch (primitive) {
31
+ case 'integer':
32
+ return 'integer';
33
+ case 'decimal':
34
+ case 'quantity':
35
+ return 'decimal';
36
+ case 'money':
37
+ return 'money';
38
+ case 'duration':
39
+ return 'duration';
40
+ case 'date':
41
+ return 'date';
42
+ case 'instant':
43
+ return 'instant';
44
+ case 'time':
45
+ return 'time';
46
+ default:
47
+ return undefined;
48
+ }
49
+ }
50
+ function range(family, min, max, minInclusive = true, maxInclusive = true) {
51
+ if (min !== null && max !== null) {
52
+ const order = compareBounds(min, max);
53
+ if (order === undefined)
54
+ return { kind: 'empty', family };
55
+ if (order > 0 || (order === 0 && (!minInclusive || !maxInclusive))) {
56
+ return { kind: 'empty', family };
57
+ }
58
+ }
59
+ return { kind: 'range', family, min, minInclusive, max, maxInclusive };
60
+ }
61
+ function constant(family, value) {
62
+ const bound = boundOf(family, value);
63
+ return range(family, bound, bound);
64
+ }
65
+ function unbounded(family) {
66
+ return range(family, null, null);
67
+ }
68
+ function compareBounds(left, right) {
69
+ if (left.kind === 'integer' && right.kind === 'integer') {
70
+ if (left.value === right.value)
71
+ return 0;
72
+ return left.value < right.value ? -1 : 1;
73
+ }
74
+ if (left.kind === 'decimal' && right.kind === 'decimal') {
75
+ return compareDecimalTexts(left.value, right.value);
76
+ }
77
+ if (left.kind === 'scalar' && right.kind === 'scalar') {
78
+ if (left.value === right.value)
79
+ return 0;
80
+ return left.value < right.value ? -1 : 1;
81
+ }
82
+ return undefined;
83
+ }
84
+ function sameBound(left, right) {
85
+ return compareBounds(left, right) === 0;
86
+ }
87
+ function greaterBound(left, right) {
88
+ if (left === null)
89
+ return right;
90
+ if (right === null)
91
+ return left;
92
+ return compareBounds(left, right) === -1 ? right : left;
93
+ }
94
+ function lesserBound(left, right) {
95
+ if (left === null)
96
+ return right;
97
+ if (right === null)
98
+ return left;
99
+ return compareBounds(left, right) === 1 ? right : left;
100
+ }
101
+ function isConstant(value) {
102
+ return (value.kind === 'range' &&
103
+ value.min !== null &&
104
+ value.max !== null &&
105
+ sameBound(value.min, value.max));
106
+ }
107
+ function intersect(left, right) {
108
+ if (left.kind === 'top')
109
+ return right;
110
+ if (right.kind === 'top')
111
+ return left;
112
+ if (left.kind === 'empty')
113
+ return left;
114
+ if (right.kind === 'empty')
115
+ return right;
116
+ if (left.family !== right.family)
117
+ return TOP;
118
+ const lower = left.min === null
119
+ ? { bound: right.min, inclusive: right.minInclusive }
120
+ : right.min === null
121
+ ? { bound: left.min, inclusive: left.minInclusive }
122
+ : compareBounds(left.min, right.min) === -1
123
+ ? { bound: right.min, inclusive: right.minInclusive }
124
+ : compareBounds(left.min, right.min) === 1
125
+ ? { bound: left.min, inclusive: left.minInclusive }
126
+ : { bound: left.min, inclusive: left.minInclusive && right.minInclusive };
127
+ const upper = left.max === null
128
+ ? { bound: right.max, inclusive: right.maxInclusive }
129
+ : right.max === null
130
+ ? { bound: left.max, inclusive: left.maxInclusive }
131
+ : compareBounds(left.max, right.max) === 1
132
+ ? { bound: right.max, inclusive: right.maxInclusive }
133
+ : compareBounds(left.max, right.max) === -1
134
+ ? { bound: left.max, inclusive: left.maxInclusive }
135
+ : { bound: left.max, inclusive: left.maxInclusive && right.maxInclusive };
136
+ return range(left.family, lower.bound, upper.bound, lower.inclusive, upper.inclusive);
137
+ }
138
+ function unite(left, right) {
139
+ if (left.kind === 'top' || right.kind === 'top')
140
+ return TOP;
141
+ if (left.kind === 'empty')
142
+ return right;
143
+ if (right.kind === 'empty')
144
+ return left;
145
+ if (left.family !== right.family)
146
+ return TOP;
147
+ const lower = lesserBound(left.min, right.min);
148
+ const upper = greaterBound(left.max, right.max);
149
+ const minInclusive = left.min !== null &&
150
+ right.min !== null &&
151
+ sameBound(left.min, right.min) &&
152
+ left.minInclusive &&
153
+ right.minInclusive;
154
+ const maxInclusive = left.max !== null &&
155
+ right.max !== null &&
156
+ sameBound(left.max, right.max) &&
157
+ left.maxInclusive &&
158
+ right.maxInclusive;
159
+ return range(left.family, lower, upper, minInclusive, maxInclusive);
160
+ }
161
+ function toDecimal(value) {
162
+ if (value.kind === 'top' || value.kind === 'empty')
163
+ return value;
164
+ if (value.family === 'decimal')
165
+ return value;
166
+ if (value.family !== 'integer')
167
+ return TOP;
168
+ const min = value.min?.kind === 'integer' ? decimalBound(value.min.value.toString()) : null;
169
+ const max = value.max?.kind === 'integer' ? decimalBound(value.max.value.toString()) : null;
170
+ return range('decimal', min, max, value.minInclusive, value.maxInclusive);
171
+ }
172
+ function addBounds(left, right, family) {
173
+ if (left === null || right === null)
174
+ return null;
175
+ try {
176
+ if (family === 'integer' || family === 'money' || family === 'duration') {
177
+ if (left.kind !== 'integer' || right.kind !== 'integer')
178
+ return null;
179
+ const sum = left.value + right.value;
180
+ return sum > MAX_SAFE_INTEGER || sum < MIN_SAFE_INTEGER ? null : integerBound(sum);
181
+ }
182
+ if (family === 'decimal') {
183
+ if (left.kind !== 'decimal' || right.kind !== 'decimal')
184
+ return null;
185
+ return decimalBound(canonicalDecimal(parseDecimal(left.value).plus(parseDecimal(right.value))));
186
+ }
187
+ if (left.kind !== 'scalar' || right.kind !== 'scalar')
188
+ return null;
189
+ return scalarBound(left.value + right.value);
190
+ }
191
+ catch {
192
+ return null;
193
+ }
194
+ }
195
+ function negateInterval(value) {
196
+ if (value.kind === 'top' || value.kind === 'empty')
197
+ return value;
198
+ if (value.family === 'integer' || value.family === 'money' || value.family === 'duration') {
199
+ if (value.family !== 'integer')
200
+ return TOP;
201
+ const min = value.max?.kind === 'integer'
202
+ ? value.max.value === MIN_SAFE_INTEGER
203
+ ? undefined
204
+ : integerBound(-value.max.value)
205
+ : null;
206
+ const max = value.min?.kind === 'integer'
207
+ ? value.min.value === MIN_SAFE_INTEGER
208
+ ? undefined
209
+ : integerBound(-value.min.value)
210
+ : null;
211
+ if (min === undefined || max === undefined)
212
+ return TOP;
213
+ return range(value.family, min, max, value.maxInclusive, value.minInclusive);
214
+ }
215
+ if (value.family === 'decimal') {
216
+ if (value.min?.kind === 'decimal') {
217
+ const max = decimalBound(canonicalDecimal(parseDecimal(value.min.value).negated()));
218
+ const min = value.max?.kind === 'decimal'
219
+ ? decimalBound(canonicalDecimal(parseDecimal(value.max.value).negated()))
220
+ : null;
221
+ return range('decimal', min, max, value.maxInclusive, value.minInclusive);
222
+ }
223
+ return TOP;
224
+ }
225
+ return TOP;
226
+ }
227
+ function multiplyIntervals(left, right) {
228
+ if (left.kind === 'top' || right.kind === 'top')
229
+ return TOP;
230
+ if (left.kind === 'empty')
231
+ return left;
232
+ if (right.kind === 'empty')
233
+ return right;
234
+ if (left.family !== right.family)
235
+ return TOP;
236
+ const family = left.family;
237
+ if (family !== 'integer' && family !== 'decimal')
238
+ return TOP;
239
+ if (left.min === null || left.max === null || right.min === null || right.max === null)
240
+ return TOP;
241
+ const leftBounds = [left.min, left.max];
242
+ const rightBounds = [right.min, right.max];
243
+ const products = [];
244
+ try {
245
+ for (const a of leftBounds) {
246
+ for (const b of rightBounds) {
247
+ if (family === 'integer') {
248
+ if (a.kind !== 'integer' || b.kind !== 'integer')
249
+ return TOP;
250
+ const product = a.value * b.value;
251
+ if (product > MAX_SAFE_INTEGER || product < MIN_SAFE_INTEGER)
252
+ return TOP;
253
+ products.push(integerBound(product));
254
+ }
255
+ else {
256
+ if (a.kind !== 'decimal' || b.kind !== 'decimal')
257
+ return TOP;
258
+ products.push(decimalBound(canonicalDecimal(parseDecimal(a.value).times(parseDecimal(b.value)))));
259
+ }
260
+ }
261
+ }
262
+ }
263
+ catch {
264
+ return TOP;
265
+ }
266
+ let min = products[0];
267
+ let max = products[0];
268
+ if (min === undefined || max === undefined)
269
+ return TOP;
270
+ for (const product of products.slice(1)) {
271
+ if (compareBounds(product, min) === -1)
272
+ min = product;
273
+ if (compareBounds(product, max) === 1)
274
+ max = product;
275
+ }
276
+ return range(family, min, max);
277
+ }
278
+ function arithmeticIntervals(op, args) {
279
+ if (args.some((arg) => arg.kind === 'top'))
280
+ return TOP;
281
+ if (args.length === 0)
282
+ return TOP;
283
+ if (op === '/') {
284
+ if (args.length !== 2)
285
+ return TOP;
286
+ return divideIntervals(args[0] ?? TOP, args[1] ?? TOP);
287
+ }
288
+ if (op === '*') {
289
+ return args.reduce((left, right) => multiplyIntervals(left, right), args[0] ?? TOP);
290
+ }
291
+ if (op === '-' && args.length === 1)
292
+ return negateInterval(args[0] ?? TOP);
293
+ const families = args.flatMap((arg) => arg.kind === 'empty' || arg.kind === 'top' ? [] : [arg.family]);
294
+ if (families.length === 0)
295
+ return TOP;
296
+ const hasDecimal = families.includes('decimal');
297
+ const hasInteger = families.includes('integer');
298
+ if (families.every((family) => family === 'money')) {
299
+ return combineRanges('money', args, op);
300
+ }
301
+ if (families.every((family) => family === 'duration')) {
302
+ return combineRanges('duration', args, op);
303
+ }
304
+ if (hasDecimal || hasInteger) {
305
+ return combineRanges('decimal', args.map(toDecimal), op);
306
+ }
307
+ return TOP;
308
+ }
309
+ function scaledBound(bound) {
310
+ if (bound.kind === 'scalar')
311
+ return undefined;
312
+ const text = bound.kind === 'integer' ? bound.value.toString() : bound.value;
313
+ const negative = text.startsWith('-');
314
+ const unsigned = negative ? text.slice(1) : text;
315
+ const point = unsigned.indexOf('.');
316
+ const whole = point === -1 ? unsigned : unsigned.slice(0, point);
317
+ const fraction = point === -1 ? '' : unsigned.slice(point + 1);
318
+ const units = BigInt(`${whole}${fraction}`);
319
+ return { units: negative ? -units : units, scale: fraction.length };
320
+ }
321
+ function positiveFactors(value, factor) {
322
+ let count = 0;
323
+ let rest = value;
324
+ while (rest % factor === 0n) {
325
+ rest /= factor;
326
+ count += 1;
327
+ }
328
+ return count;
329
+ }
330
+ /**
331
+ * The exact quotient of two bounds as canonical decimal text, or `undefined` when the quotient
332
+ * has no finite decimal spelling or leaves the 34-digit result budget.
333
+ *
334
+ * The interval pass never rounds a bound: a rounded endpoint could exclude a value the
335
+ * expression really produces, which is a claim rather than a range. A quotient that does not
336
+ * terminate therefore leaves the result `top`.
337
+ */
338
+ function exactQuotient(dividend, divisor) {
339
+ if (dividend.kind === 'scalar' || divisor.kind === 'scalar')
340
+ return undefined;
341
+ const a = scaledBound(dividend);
342
+ const b = scaledBound(divisor);
343
+ if (a === undefined || b === undefined || b.units === 0n)
344
+ return undefined;
345
+ let numerator = a.units * 10n ** BigInt(b.scale);
346
+ let denominator = b.units * 10n ** BigInt(a.scale);
347
+ if (numerator === 0n)
348
+ return asDecimalString('0');
349
+ if (denominator < 0n) {
350
+ numerator = -numerator;
351
+ denominator = -denominator;
352
+ }
353
+ const common = greatestCommonFactor(numerator, denominator);
354
+ numerator /= common;
355
+ denominator /= common;
356
+ const twos = positiveFactors(denominator, 2n);
357
+ const rest = denominator / 2n ** BigInt(twos);
358
+ const fives = positiveFactors(rest, 5n);
359
+ if (rest / 5n ** BigInt(fives) !== 1n)
360
+ return undefined;
361
+ const digits = Math.max(twos, fives);
362
+ if (digits > 34)
363
+ return undefined;
364
+ const units = (numerator * 10n ** BigInt(digits)) / denominator;
365
+ return renderIntervalScaled(units, digits);
366
+ }
367
+ function greatestCommonFactor(left, right) {
368
+ let a = left < 0n ? -left : left;
369
+ let b = right;
370
+ while (b !== 0n) {
371
+ const remainder = a % b;
372
+ a = b;
373
+ b = remainder;
374
+ }
375
+ return a;
376
+ }
377
+ function renderIntervalScaled(units, scale) {
378
+ if (units === 0n)
379
+ return asDecimalString('0');
380
+ const negative = units < 0n;
381
+ let magnitude = (negative ? -units : units).toString();
382
+ while (scale > 0 && magnitude.endsWith('0')) {
383
+ magnitude = magnitude.slice(0, -1);
384
+ scale -= 1;
385
+ }
386
+ const digits = magnitude.padStart(scale + 1, '0');
387
+ const whole = digits.slice(0, digits.length - scale);
388
+ const fraction = digits.slice(digits.length - scale).replace(/0+$/, '');
389
+ const text = fraction === '' ? whole : `${whole}.${fraction}`;
390
+ const signed = negative ? `-${text}` : text;
391
+ const significant = signed
392
+ .replace('-', '')
393
+ .replace('.', '')
394
+ .replace(/^0+/, '')
395
+ .replace(/0+$/, '');
396
+ return significant.length > 34 ? undefined : asDecimalString(signed);
397
+ }
398
+ /**
399
+ * `/` over intervals. A divisor interval that contains zero answers `top`: no quotient bound
400
+ * can be stated when the divisor may be zero, and "cannot say" is the only honest answer.
401
+ */
402
+ function divideIntervals(left, right) {
403
+ if (left.kind === 'top' || right.kind === 'top')
404
+ return TOP;
405
+ if (left.kind === 'empty')
406
+ return left;
407
+ if (right.kind === 'empty')
408
+ return right;
409
+ if (left.family !== 'integer' && left.family !== 'decimal')
410
+ return TOP;
411
+ if (right.family !== 'integer' && right.family !== 'decimal')
412
+ return TOP;
413
+ const dividend = toDecimal(left);
414
+ const divisor = toDecimal(right);
415
+ if (dividend.kind !== 'range' || divisor.kind !== 'range')
416
+ return TOP;
417
+ if (dividend.min === null ||
418
+ dividend.max === null ||
419
+ divisor.min === null ||
420
+ divisor.max === null) {
421
+ return TOP;
422
+ }
423
+ const zero = decimalBound('0');
424
+ if (compareBounds(divisor.min, zero) !== 1 && compareBounds(divisor.max, zero) !== -1) {
425
+ return TOP;
426
+ }
427
+ const quotients = [
428
+ exactQuotient(dividend.min, divisor.min),
429
+ exactQuotient(dividend.min, divisor.max),
430
+ exactQuotient(dividend.max, divisor.min),
431
+ exactQuotient(dividend.max, divisor.max),
432
+ ];
433
+ if (quotients.some((quotient) => quotient === undefined))
434
+ return TOP;
435
+ const bounds = quotients.map((quotient) => decimalBound(quotient ?? '0'));
436
+ let min = bounds[0];
437
+ let max = bounds[0];
438
+ if (min === undefined || max === undefined)
439
+ return TOP;
440
+ for (const bound of bounds.slice(1)) {
441
+ if (compareBounds(bound, min) === -1)
442
+ min = bound;
443
+ if (compareBounds(bound, max) === 1)
444
+ max = bound;
445
+ }
446
+ return range('decimal', min, max);
447
+ }
448
+ function combineRanges(family, args, op) {
449
+ let lower = null;
450
+ let upper = null;
451
+ let first = true;
452
+ for (const arg of args) {
453
+ if (arg.kind !== 'range')
454
+ return TOP;
455
+ const min = op === '-' && !first ? arg.max : arg.min;
456
+ const max = op === '-' && !first ? arg.min : arg.max;
457
+ if (first) {
458
+ lower = min;
459
+ upper = max;
460
+ first = false;
461
+ continue;
462
+ }
463
+ lower = addBounds(lower, min, family);
464
+ upper = addBounds(upper, max, family);
465
+ if (lower === null || upper === null)
466
+ return TOP;
467
+ }
468
+ if (family === 'duration' && lower !== null && lower.kind === 'integer' && lower.value < 0n) {
469
+ return TOP;
470
+ }
471
+ return range(family, lower, upper);
472
+ }
473
+ function fieldAtPath(declarations, path, itemFieldId) {
474
+ const [head, ...rest] = path.split('.');
475
+ if (head === undefined)
476
+ return undefined;
477
+ if (head.startsWith('$')) {
478
+ if (itemFieldId === undefined || rest.length === 0)
479
+ return undefined;
480
+ const array = declarations.fields?.find((field) => field.fieldId === itemFieldId);
481
+ if (array === undefined)
482
+ return undefined;
483
+ return findMember(array, rest);
484
+ }
485
+ const top = declarations.fields?.find((field) => field.fieldId === head);
486
+ if (top === undefined)
487
+ return undefined;
488
+ return findMember(top, rest);
489
+ }
490
+ function findMember(field, path) {
491
+ let current = field;
492
+ for (const segment of path) {
493
+ const member = current.fields?.find((candidate) => candidate.fieldId === segment);
494
+ if (member === undefined)
495
+ return undefined;
496
+ current = member;
497
+ }
498
+ return current;
499
+ }
500
+ function boundFromHint(family, value) {
501
+ switch (family) {
502
+ case 'integer':
503
+ case 'money':
504
+ case 'duration':
505
+ return integerBound(BigInt(value));
506
+ case 'decimal':
507
+ return decimalBound(String(value));
508
+ case 'date':
509
+ return scalarBound(daysFromCivilValue(String(value)));
510
+ case 'instant':
511
+ return scalarBound(instantToEpochMilliseconds(String(value)));
512
+ case 'time':
513
+ return scalarBound(secondsSinceMidnight(parseClockTime(String(value))));
514
+ }
515
+ }
516
+ function fieldInterval(field) {
517
+ const family = familyOfPrimitive(field.primitive);
518
+ if (family === undefined)
519
+ return TOP;
520
+ const min = field.minimum;
521
+ const max = field.maximum;
522
+ if (min === undefined && max === undefined)
523
+ return TOP;
524
+ try {
525
+ const minBound = min === undefined ? null : boundFromHint(family, min);
526
+ const maxBound = max === undefined ? null : boundFromHint(family, max);
527
+ return range(family, minBound, maxBound);
528
+ }
529
+ catch {
530
+ return TOP;
531
+ }
532
+ }
533
+ function intervalOf(node, declarations, environment, itemFieldId) {
534
+ switch (node.kind) {
535
+ case 'literal':
536
+ return literalInterval(node);
537
+ case 'path': {
538
+ const narrowed = environment.get(node.path);
539
+ if (narrowed !== undefined)
540
+ return narrowed;
541
+ const field = fieldAtPath(declarations, node.path, itemFieldId);
542
+ return field === undefined ? TOP : fieldInterval(field);
543
+ }
544
+ case 'list':
545
+ return TOP;
546
+ case 'and':
547
+ case 'or':
548
+ case 'not':
549
+ case 'compare':
550
+ case 'if':
551
+ case 'coalesce':
552
+ case 'comprehension':
553
+ return TOP;
554
+ case 'call':
555
+ return callInterval(node, declarations, environment, itemFieldId);
556
+ }
557
+ }
558
+ function literalInterval(node) {
559
+ switch (node.domain) {
560
+ case 'integer':
561
+ return typeof node.value === 'number' && Number.isSafeInteger(node.value)
562
+ ? constant('integer', BigInt(node.value))
563
+ : TOP;
564
+ case 'decimal':
565
+ return typeof node.value === 'string'
566
+ ? constant('decimal', asDecimalString(node.value))
567
+ : TOP;
568
+ case 'money':
569
+ if (!isRecord(node.value))
570
+ return TOP;
571
+ return typeof node.value['minor'] === 'string'
572
+ ? constant('money', BigInt(node.value['minor']))
573
+ : TOP;
574
+ case 'quantity':
575
+ if (!isRecord(node.value))
576
+ return TOP;
577
+ return typeof node.value['value'] === 'string'
578
+ ? constant('decimal', asDecimalString(node.value['value']))
579
+ : TOP;
580
+ case 'duration':
581
+ if (!isRecord(node.value))
582
+ return TOP;
583
+ return typeof node.value['amount'] === 'number' && Number.isSafeInteger(node.value['amount'])
584
+ ? constant('duration', BigInt(node.value['amount']))
585
+ : TOP;
586
+ case 'date':
587
+ return typeof node.value === 'string'
588
+ ? constant('date', daysFromCivilValue(node.value))
589
+ : TOP;
590
+ case 'instant':
591
+ return typeof node.value === 'string'
592
+ ? constant('instant', instantToEpochMilliseconds(node.value))
593
+ : TOP;
594
+ case 'time':
595
+ return typeof node.value === 'string'
596
+ ? constant('time', secondsSinceMidnight(parseClockTime(node.value)))
597
+ : TOP;
598
+ default:
599
+ return TOP;
600
+ }
601
+ }
602
+ function daysFromCivilValue(text) {
603
+ const date = parsePlainDate(text);
604
+ return daysFromCivil(date.year, date.month, date.day);
605
+ }
606
+ function callInterval(node, declarations, environment, itemFieldId) {
607
+ if (node.op === '+' || node.op === '-' || node.op === '*' || node.op === '/') {
608
+ return arithmeticIntervals(node.op, node.args.map((arg) => intervalOf(arg, declarations, environment, itemFieldId)));
609
+ }
610
+ switch (node.op) {
611
+ case 'len': {
612
+ const [operand] = node.args;
613
+ if (operand?.kind === 'list')
614
+ return constant('integer', BigInt(operand.items.length));
615
+ if (operand?.kind === 'literal' && typeof operand.value === 'string') {
616
+ return constant('integer', BigInt(codePointLength(operand.value)));
617
+ }
618
+ if (operand?.kind === 'path') {
619
+ const field = fieldAtPath(declarations, operand.path, itemFieldId);
620
+ if (field?.primitive === 'array') {
621
+ return range('integer', field.minItems === undefined ? null : integerBound(BigInt(field.minItems)), field.maxItems === undefined ? null : integerBound(BigInt(field.maxItems)));
622
+ }
623
+ }
624
+ return TOP;
625
+ }
626
+ case 'index_of': {
627
+ const [haystack, needle] = node.args;
628
+ if (haystack?.kind === 'literal' &&
629
+ typeof haystack.value === 'string' &&
630
+ needle?.kind === 'literal' &&
631
+ typeof needle.value === 'string') {
632
+ return constant('integer', BigInt(codePointIndexOf(haystack.value, needle.value)));
633
+ }
634
+ if (haystack?.kind === 'literal' && typeof haystack.value === 'string') {
635
+ return range('integer', integerBound(-1n), integerBound(BigInt(codePointLength(haystack.value) - 1)));
636
+ }
637
+ return TOP;
638
+ }
639
+ case 'year':
640
+ case 'month':
641
+ case 'day':
642
+ case 'weekday': {
643
+ const value = intervalOf(node.args[0] ?? { kind: 'literal', domain: 'null', value: null }, declarations, environment, itemFieldId);
644
+ return temporalPartInterval(node.op, value);
645
+ }
646
+ case 'days_between': {
647
+ const left = intervalOf(node.args[0] ?? { kind: 'literal', domain: 'null', value: null }, declarations, environment, itemFieldId);
648
+ const right = intervalOf(node.args[1] ?? { kind: 'literal', domain: 'null', value: null }, declarations, environment, itemFieldId);
649
+ if (isConstant(left) && isConstant(right)) {
650
+ const a = left.min;
651
+ const b = right.min;
652
+ if (a?.kind === 'scalar' && b?.kind === 'scalar') {
653
+ const aDate = civilOfDays(a.value);
654
+ const bDate = civilOfDays(b.value);
655
+ return constant('integer', BigInt(daysBetween(aDate, bDate)));
656
+ }
657
+ }
658
+ return TOP;
659
+ }
660
+ case 'months_between': {
661
+ const left = intervalOf(node.args[0] ?? { kind: 'literal', domain: 'null', value: null }, declarations, environment, itemFieldId);
662
+ const right = intervalOf(node.args[1] ?? { kind: 'literal', domain: 'null', value: null }, declarations, environment, itemFieldId);
663
+ if (isConstant(left) && isConstant(right)) {
664
+ const a = left.min;
665
+ const b = right.min;
666
+ if (a?.kind === 'scalar' && b?.kind === 'scalar') {
667
+ const aDate = civilOfDays(a.value);
668
+ const bDate = civilOfDays(b.value);
669
+ return constant('integer', BigInt(monthsBetween(aDate, bDate)));
670
+ }
671
+ }
672
+ return TOP;
673
+ }
674
+ case 'minutes_between': {
675
+ const left = intervalOf(node.args[0] ?? { kind: 'literal', domain: 'null', value: null }, declarations, environment, itemFieldId);
676
+ const right = intervalOf(node.args[1] ?? { kind: 'literal', domain: 'null', value: null }, declarations, environment, itemFieldId);
677
+ if (left.kind === 'range' && right.kind === 'range') {
678
+ if (left.family === 'instant' &&
679
+ right.family === 'instant' &&
680
+ isConstant(left) &&
681
+ isConstant(right) &&
682
+ left.min?.kind === 'scalar' &&
683
+ right.min?.kind === 'scalar') {
684
+ return constant('integer', BigInt(minutesBetweenInstants(civilInstant(left.min.value), civilInstant(right.min.value))));
685
+ }
686
+ if (left.family === 'time' &&
687
+ right.family === 'time' &&
688
+ isConstant(left) &&
689
+ isConstant(right) &&
690
+ left.min?.kind === 'scalar' &&
691
+ right.min?.kind === 'scalar') {
692
+ return constant('integer', BigInt(minutesBetweenTimes(clockText(left.min.value), clockText(right.min.value))));
693
+ }
694
+ }
695
+ return TOP;
696
+ }
697
+ case 'duration_minutes':
698
+ case 'duration_seconds': {
699
+ const value = intervalOf(node.args[0] ?? { kind: 'literal', domain: 'null', value: null }, declarations, environment, itemFieldId);
700
+ return durationConversion(value, node.op === 'duration_minutes' ? 1n : 60n);
701
+ }
702
+ case 'money_minor': {
703
+ const value = intervalOf(node.args[0] ?? { kind: 'literal', domain: 'null', value: null }, declarations, environment, itemFieldId);
704
+ return moneyMinorInterval(value);
705
+ }
706
+ case 'abs': {
707
+ return absoluteInterval(intervalOf(node.args[0] ?? { kind: 'literal', domain: 'null', value: null }, declarations, environment, itemFieldId));
708
+ }
709
+ case 'sum':
710
+ case 'min':
711
+ case 'max':
712
+ return aggregateInterval(node.op, node.args[0], declarations, environment, itemFieldId);
713
+ default:
714
+ return TOP;
715
+ }
716
+ }
717
+ function civilOfDays(days) {
718
+ const date = civilFromDays(days);
719
+ return { year: date.year, month: date.month, day: date.day };
720
+ }
721
+ function civilInstant(milliseconds) {
722
+ const days = Math.floor(milliseconds / 86_400_000);
723
+ let rest = milliseconds - days * 86_400_000;
724
+ const date = civilFromDays(days);
725
+ const pad = (value, width) => String(value).padStart(width, '0');
726
+ const hour = Math.floor(rest / 3_600_000);
727
+ rest -= hour * 3_600_000;
728
+ const minute = Math.floor(rest / 60_000);
729
+ rest -= minute * 60_000;
730
+ const second = Math.floor(rest / 1_000);
731
+ rest -= second * 1_000;
732
+ return `${pad(date.year, 4)}-${pad(date.month, 2)}-${pad(date.day, 2)}T${pad(hour, 2)}:${pad(minute, 2)}:${pad(second, 2)}.${pad(rest, 3)}Z`;
733
+ }
734
+ function clockText(seconds) {
735
+ const hours = Math.floor(seconds / 3600);
736
+ const minutes = Math.floor((seconds % 3600) / 60);
737
+ const remainder = seconds % 60;
738
+ return `${String(hours).padStart(2, '0')}:${String(minutes).padStart(2, '0')}${remainder === 0 ? '' : `:${String(remainder).padStart(2, '0')}`}`;
739
+ }
740
+ function temporalPartInterval(op, value) {
741
+ if (op === 'weekday') {
742
+ return value.kind === 'range' && value.family === 'date'
743
+ ? range('integer', integerBound(1n), integerBound(7n))
744
+ : TOP;
745
+ }
746
+ if (value.kind !== 'range' || value.family !== 'date')
747
+ return TOP;
748
+ if (isConstant(value) && value.min?.kind === 'scalar') {
749
+ const date = civilOfDays(value.min.value);
750
+ return constant('integer', BigInt(op === 'year' ? date.year : op === 'month' ? date.month : date.day));
751
+ }
752
+ if (op === 'month')
753
+ return range('integer', integerBound(1n), integerBound(12n));
754
+ if (op === 'day')
755
+ return range('integer', integerBound(1n), integerBound(31n));
756
+ if (value.min?.kind !== 'scalar' || value.max?.kind !== 'scalar')
757
+ return TOP;
758
+ const first = civilOfDays(value.min.value);
759
+ const last = civilOfDays(value.max.value);
760
+ return range('integer', integerBound(BigInt(first.year)), integerBound(BigInt(last.year)));
761
+ }
762
+ function durationConversion(value, factor) {
763
+ if (value.kind !== 'range' || value.family !== 'duration')
764
+ return TOP;
765
+ const convert = (bound) => {
766
+ if (bound === null)
767
+ return null;
768
+ if (bound.kind !== 'integer')
769
+ return null;
770
+ const product = bound.value * factor;
771
+ return product > MAX_SAFE_INTEGER || product < MIN_SAFE_INTEGER ? null : integerBound(product);
772
+ };
773
+ return range('integer', convert(value.min), convert(value.max), value.minInclusive, value.maxInclusive);
774
+ }
775
+ function moneyMinorInterval(value) {
776
+ if (value.kind !== 'range' || value.family !== 'money')
777
+ return TOP;
778
+ const convert = (bound) => bound?.kind === 'integer' ? decimalBound(bound.value.toString()) : null;
779
+ return range('decimal', convert(value.min), convert(value.max), value.minInclusive, value.maxInclusive);
780
+ }
781
+ function absoluteInterval(value) {
782
+ if (value.kind !== 'range' || (value.family !== 'integer' && value.family !== 'decimal')) {
783
+ return TOP;
784
+ }
785
+ if (value.min === null || value.max === null)
786
+ return TOP;
787
+ const zero = value.family === 'integer' ? integerBound(0n) : decimalBound('0');
788
+ const lower = compareBounds(value.min, zero) === 1 ? value.min : zero;
789
+ const upperCandidate = compareBounds(value.max, zero) === -1 ? negateBound(value.max) : value.max;
790
+ if (upperCandidate === undefined)
791
+ return TOP;
792
+ return range(value.family, lower, upperCandidate);
793
+ }
794
+ function negateBound(bound) {
795
+ if (bound.kind === 'integer') {
796
+ return bound.value === MIN_SAFE_INTEGER ? undefined : integerBound(-bound.value);
797
+ }
798
+ if (bound.kind === 'decimal') {
799
+ return decimalBound(canonicalDecimal(parseDecimal(bound.value).negated()));
800
+ }
801
+ return scalarBound(-bound.value);
802
+ }
803
+ function aggregateInterval(op, operand, declarations, environment, itemFieldId) {
804
+ if (operand?.kind !== 'list' || operand.items.length === 0)
805
+ return TOP;
806
+ const items = operand.items.map((item) => intervalOf(item, declarations, environment, itemFieldId));
807
+ if (items.some((item) => item.kind === 'top' || item.kind === 'empty'))
808
+ return TOP;
809
+ if (op === 'min' || op === 'max') {
810
+ const ranges = items.filter((item) => item.kind === 'range');
811
+ if (ranges.length !== items.length)
812
+ return TOP;
813
+ const numeric = ranges.every((range) => range.family === 'integer' || range.family === 'decimal');
814
+ const normalized = numeric ? ranges.map(toDecimal) : ranges;
815
+ const normalizedRanges = normalized.filter((item) => item.kind === 'range');
816
+ if (normalizedRanges.length !== normalized.length)
817
+ return TOP;
818
+ const family = normalizedRanges[0]?.family;
819
+ if (family === undefined || normalizedRanges.some((range) => range.family !== family)) {
820
+ return TOP;
821
+ }
822
+ if (normalizedRanges.every((range) => range.min === null || range.max === null))
823
+ return TOP;
824
+ const lower = op === 'min'
825
+ ? normalizedRanges.reduce((chosen, range) => lesserBound(chosen, range.min), null)
826
+ : normalizedRanges.reduce((chosen, range) => greaterBound(chosen, range.min), null);
827
+ const upper = op === 'min'
828
+ ? normalizedRanges.reduce((chosen, range) => lesserBound(chosen, range.max), null)
829
+ : normalizedRanges.reduce((chosen, range) => greaterBound(chosen, range.max), null);
830
+ return range(family, lower, upper);
831
+ }
832
+ const numeric = items.map(toDecimal);
833
+ if (numeric.some((item) => item.kind !== 'range'))
834
+ return TOP;
835
+ let lower = decimalBound('0');
836
+ let upper = decimalBound('0');
837
+ for (const item of numeric) {
838
+ if (item.kind !== 'range')
839
+ return TOP;
840
+ lower = addBounds(lower, item.min, 'decimal');
841
+ upper = addBounds(upper, item.max, 'decimal');
842
+ if (lower === null || upper === null)
843
+ return TOP;
844
+ }
845
+ return range('decimal', lower, upper);
846
+ }
847
+ function truthOfLiteral(node) {
848
+ // The analyzer is called from untyped probe code as well as from the checker; a missing node
849
+ // is "cannot say", never a property read on `undefined`.
850
+ if (node === undefined)
851
+ return undefined;
852
+ if (node.kind !== 'literal' || node.domain !== 'boolean')
853
+ return undefined;
854
+ return node.value === true ? 'true' : 'false';
855
+ }
856
+ function comparisonTruth(op, left, right) {
857
+ if (left.kind === 'top' || right.kind === 'top')
858
+ return 'unknown';
859
+ if (left.kind === 'empty' || right.kind === 'empty')
860
+ return 'unknown';
861
+ if (left.family !== right.family)
862
+ return 'unknown';
863
+ if (op === '==') {
864
+ if (isConstant(left) && isConstant(right)) {
865
+ if (left.min === null || right.min === null)
866
+ return 'unknown';
867
+ return sameBound(left.min, right.min) ? 'true' : 'false';
868
+ }
869
+ return 'unknown';
870
+ }
871
+ if (op === '!=') {
872
+ if (isConstant(left) && isConstant(right)) {
873
+ if (left.min === null || right.min === null)
874
+ return 'unknown';
875
+ return sameBound(left.min, right.min) ? 'false' : 'true';
876
+ }
877
+ if (left.max !== null && right.min !== null) {
878
+ const order = compareBounds(left.max, right.min);
879
+ if (order === -1 || (order === 0 && (!left.maxInclusive || !right.minInclusive))) {
880
+ return 'true';
881
+ }
882
+ }
883
+ if (left.min !== null && right.max !== null) {
884
+ const order = compareBounds(left.min, right.max);
885
+ if (order === 1 || (order === 0 && (!left.minInclusive || !right.maxInclusive))) {
886
+ return 'true';
887
+ }
888
+ }
889
+ return 'unknown';
890
+ }
891
+ return orderTruth(op, left, right);
892
+ }
893
+ function orderTruth(op, left, right) {
894
+ if (op === '>')
895
+ return orderTruth('<', right, left);
896
+ if (op === '>=')
897
+ return orderTruth('<=', right, left);
898
+ if (op === '<') {
899
+ if (left.max !== null && right.min !== null) {
900
+ const order = compareBounds(left.max, right.min);
901
+ if (order === -1)
902
+ return 'true';
903
+ if (order === 0 && (!left.maxInclusive || !right.minInclusive))
904
+ return 'true';
905
+ // `left.max > right.min` proves only that the comparison is not always true: two
906
+ // overlapping ranges satisfy it and still hold for some pair of values. "Always false"
907
+ // is the second block's question, where `left.min` meets `right.max`.
908
+ }
909
+ if (left.min !== null && right.max !== null) {
910
+ const order = compareBounds(left.min, right.max);
911
+ if (order === 1)
912
+ return 'false';
913
+ if (order === 0 && (!left.minInclusive || !right.maxInclusive))
914
+ return 'false';
915
+ }
916
+ return 'unknown';
917
+ }
918
+ if (left.max !== null && right.min !== null) {
919
+ const order = compareBounds(left.max, right.min);
920
+ if (order === -1)
921
+ return 'true';
922
+ if (order === 0)
923
+ return 'true';
924
+ }
925
+ if (left.min !== null && right.max !== null) {
926
+ const order = compareBounds(left.min, right.max);
927
+ if (order === 1)
928
+ return 'false';
929
+ if (order === 0 && (!left.minInclusive || !right.maxInclusive))
930
+ return 'false';
931
+ }
932
+ return 'unknown';
933
+ }
934
+ function compareIntervals(op, left, right) {
935
+ if (left.kind === 'top' || right.kind === 'top')
936
+ return 'unknown';
937
+ if (left.kind === 'empty' || right.kind === 'empty')
938
+ return 'unknown';
939
+ if (left.family !== right.family) {
940
+ const numeric = (family) => family === 'integer' || family === 'decimal';
941
+ if (!numeric(left.family) || !numeric(right.family))
942
+ return 'unknown';
943
+ return compareIntervals(op, toDecimal(left), toDecimal(right));
944
+ }
945
+ if (op === '==' || op === '!=')
946
+ return comparisonTruth(op, left, right);
947
+ if (op === '<' || op === '<=')
948
+ return orderTruth(op, left, right);
949
+ return orderTruth(op, left, right);
950
+ }
951
+ function conditionFacts(node, declarations, environment, itemFieldId) {
952
+ if (node === undefined)
953
+ return { truth: 'unknown', derived: false, environment };
954
+ const literal = truthOfLiteral(node);
955
+ if (literal !== undefined) {
956
+ return { truth: literal, derived: false, environment };
957
+ }
958
+ switch (node.kind) {
959
+ case 'not': {
960
+ const child = conditionFacts(node.args[0] ?? { kind: 'literal', domain: 'null', value: null }, declarations, environment, itemFieldId);
961
+ return {
962
+ truth: child.truth === 'true' ? 'false' : child.truth === 'false' ? 'true' : 'unknown',
963
+ derived: child.derived,
964
+ environment,
965
+ };
966
+ }
967
+ case 'and': {
968
+ let current = environment;
969
+ let unknown = false;
970
+ let derived = false;
971
+ for (const arg of node.args) {
972
+ const child = conditionFacts(arg, declarations, current, itemFieldId);
973
+ derived = derived || child.derived;
974
+ if (child.truth === 'false') {
975
+ return { truth: 'false', derived, environment: current };
976
+ }
977
+ if (child.truth === 'unknown')
978
+ unknown = true;
979
+ current = child.environment;
980
+ }
981
+ return { truth: unknown ? 'unknown' : 'true', derived, environment: current };
982
+ }
983
+ case 'or': {
984
+ let unknown = false;
985
+ let derived = false;
986
+ let merged;
987
+ for (const arg of node.args) {
988
+ const child = conditionFacts(arg, declarations, environment, itemFieldId);
989
+ derived = derived || child.derived;
990
+ if (child.truth === 'true') {
991
+ return { truth: 'true', derived, environment };
992
+ }
993
+ if (child.truth === 'unknown')
994
+ unknown = true;
995
+ if (merged === undefined)
996
+ merged = child.environment;
997
+ else {
998
+ const union = new Map();
999
+ for (const [path, interval] of merged) {
1000
+ const other = child.environment.get(path);
1001
+ if (other === undefined)
1002
+ continue;
1003
+ const united = unite(interval, other);
1004
+ if (united.kind === 'range' || united.kind === 'empty')
1005
+ union.set(path, united);
1006
+ }
1007
+ merged = union;
1008
+ }
1009
+ }
1010
+ return { truth: unknown ? 'unknown' : 'false', derived, environment: merged ?? environment };
1011
+ }
1012
+ case 'compare': {
1013
+ const [leftNode, rightNode] = node.args;
1014
+ if (leftNode === undefined || rightNode === undefined) {
1015
+ return { truth: 'unknown', derived: false, environment };
1016
+ }
1017
+ const left = intervalOf(leftNode, declarations, environment, itemFieldId);
1018
+ const right = intervalOf(rightNode, declarations, environment, itemFieldId);
1019
+ const truth = node.op === 'in' ? 'unknown' : compareIntervals(node.op, left, right);
1020
+ const narrowed = narrowComparison(node.op, leftNode, rightNode, left, right, environment);
1021
+ return { truth, derived: true, environment: narrowed };
1022
+ }
1023
+ case 'call': {
1024
+ if (node.op === 'between')
1025
+ return betweenFacts(node, declarations, environment, itemFieldId);
1026
+ return { truth: 'unknown', derived: false, environment };
1027
+ }
1028
+ default:
1029
+ return { truth: 'unknown', derived: false, environment };
1030
+ }
1031
+ }
1032
+ function narrowComparison(op, leftNode, rightNode, left, right, environment) {
1033
+ if (op === 'in')
1034
+ return environment;
1035
+ if (leftNode.kind !== 'path' && rightNode.kind !== 'path')
1036
+ return environment;
1037
+ const next = new Map(environment);
1038
+ if (leftNode.kind === 'path' && right.kind === 'range') {
1039
+ next.set(leftNode.path, narrowByComparison(op, left, right));
1040
+ }
1041
+ if (rightNode.kind === 'path' && left.kind === 'range') {
1042
+ const inverted = op === '<' ? '>' : op === '<=' ? '>=' : op === '>' ? '<' : op === '>=' ? '<=' : op;
1043
+ next.set(rightNode.path, narrowByComparison(inverted, right, left));
1044
+ }
1045
+ return next;
1046
+ }
1047
+ function narrowByComparison(op, current, other) {
1048
+ const existing = current.kind === 'range' ? current : unbounded(other.family);
1049
+ const lower = op === '>' || op === '>='
1050
+ ? range(other.family, other.min, null, op === '>=' ? true : false)
1051
+ : op === '=='
1052
+ ? range(other.family, other.min, other.max, other.minInclusive, other.maxInclusive)
1053
+ : unbounded(other.family);
1054
+ const upper = op === '<' || op === '<='
1055
+ ? range(other.family, null, other.max, true, op === '<=' ? true : false)
1056
+ : unbounded(other.family);
1057
+ const narrowed = op === '==' ? lower : intersect(lower, upper);
1058
+ const result = intersect(existing, narrowed);
1059
+ return result.kind === 'range'
1060
+ ? result
1061
+ : result.kind === 'empty'
1062
+ ? result
1063
+ : unbounded(other.family);
1064
+ }
1065
+ function betweenFacts(node, declarations, environment, itemFieldId) {
1066
+ const [valueNode, lowNode, highNode] = node.args;
1067
+ if (valueNode === undefined || lowNode === undefined || highNode === undefined) {
1068
+ return { truth: 'unknown', derived: false, environment };
1069
+ }
1070
+ const value = intervalOf(valueNode, declarations, environment, itemFieldId);
1071
+ const low = intervalOf(lowNode, declarations, environment, itemFieldId);
1072
+ const high = intervalOf(highNode, declarations, environment, itemFieldId);
1073
+ if (isConstant(low) && isConstant(high) && low.min !== null && high.min !== null) {
1074
+ if (compareBounds(low.min, high.min) === 1) {
1075
+ return { truth: 'false', derived: true, environment };
1076
+ }
1077
+ }
1078
+ if (value.kind !== 'range' || low.kind !== 'range' || high.kind !== 'range') {
1079
+ return { truth: 'unknown', derived: true, environment };
1080
+ }
1081
+ const lowerTruth = compareIntervals('>=', value, low);
1082
+ const upperTruth = compareIntervals('<=', value, high);
1083
+ if (lowerTruth === 'false' || upperTruth === 'false') {
1084
+ return { truth: 'false', derived: true, environment };
1085
+ }
1086
+ if (lowerTruth === 'true' && upperTruth === 'true') {
1087
+ const next = new Map(environment);
1088
+ if (valueNode.kind === 'path') {
1089
+ const narrowed = intersect(value, range(value.family, low.min, high.max, low.minInclusive, high.maxInclusive));
1090
+ if (narrowed.kind === 'range')
1091
+ next.set(valueNode.path, narrowed);
1092
+ }
1093
+ return { truth: 'true', derived: true, environment: next };
1094
+ }
1095
+ return { truth: 'unknown', derived: true, environment };
1096
+ }
1097
+ function shapeOf(node) {
1098
+ if (node.kind === 'compare')
1099
+ return 'comparison';
1100
+ if (node.kind === 'and' || node.kind === 'or')
1101
+ return 'connector';
1102
+ if (node.kind === 'not') {
1103
+ const [child] = node.args;
1104
+ if (child?.kind === 'compare')
1105
+ return 'comparison';
1106
+ }
1107
+ if (node.kind === 'call' && node.op === 'between')
1108
+ return 'comparison';
1109
+ return 'other';
1110
+ }
1111
+ function invalidConstant(node, declarations, environment, itemFieldId) {
1112
+ switch (node.kind) {
1113
+ case 'call': {
1114
+ if (node.op === 'between') {
1115
+ const [valueNode, lowNode, highNode] = node.args;
1116
+ if (valueNode !== undefined && lowNode !== undefined && highNode !== undefined) {
1117
+ const low = intervalOf(lowNode, declarations, environment, itemFieldId);
1118
+ const high = intervalOf(highNode, declarations, environment, itemFieldId);
1119
+ if (isConstant(low) && isConstant(high) && low.min !== null && high.min !== null) {
1120
+ if (compareBounds(low.min, high.min) === 1) {
1121
+ return '`between` states a low bound above its high bound, so the expression is false for every value; write `between(x, low, high)` with `low <= high`';
1122
+ }
1123
+ }
1124
+ }
1125
+ }
1126
+ for (const arg of node.args) {
1127
+ const found = invalidConstant(arg, declarations, environment, itemFieldId);
1128
+ if (found !== undefined)
1129
+ return found;
1130
+ }
1131
+ return undefined;
1132
+ }
1133
+ case 'literal':
1134
+ case 'path':
1135
+ return undefined;
1136
+ case 'list': {
1137
+ for (const item of node.items) {
1138
+ const found = invalidConstant(item, declarations, environment, itemFieldId);
1139
+ if (found !== undefined)
1140
+ return found;
1141
+ }
1142
+ return undefined;
1143
+ }
1144
+ case 'comprehension': {
1145
+ const source = invalidConstant(node.source, declarations, environment, itemFieldId);
1146
+ if (source !== undefined)
1147
+ return source;
1148
+ if (node.valueExpr !== undefined) {
1149
+ const value = invalidConstant(node.valueExpr, declarations, environment, itemFieldId);
1150
+ if (value !== undefined)
1151
+ return value;
1152
+ }
1153
+ if (node.predicate !== undefined) {
1154
+ return invalidConstant(node.predicate, declarations, environment, itemFieldId);
1155
+ }
1156
+ return undefined;
1157
+ }
1158
+ default: {
1159
+ for (const arg of node.args) {
1160
+ const found = invalidConstant(arg, declarations, environment, itemFieldId);
1161
+ if (found !== undefined)
1162
+ return found;
1163
+ }
1164
+ return undefined;
1165
+ }
1166
+ }
1167
+ }
1168
+ /** Analyse one expression against its declarations, without assuming any other rule's outcome. */
1169
+ export function analyzeExpression(declarations, node, itemFieldId) {
1170
+ const environment = new Map();
1171
+ const facts = conditionFacts(node, declarations, environment, itemFieldId);
1172
+ const invalid = invalidConstant(node, declarations, environment, itemFieldId);
1173
+ return {
1174
+ truth: facts.truth,
1175
+ derived: facts.derived,
1176
+ shape: shapeOf(node),
1177
+ ...(invalid === undefined ? {} : { invalidConstant: invalid }),
1178
+ };
1179
+ }
1180
+ //# sourceMappingURL=interval.js.map