@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,334 @@
1
+ import { withArticle } from '../../article.js';
2
+ import { noteUndecidedFold } from './fold.js';
3
+ import { descendType } from './paths.js';
4
+ import { ORDERABLE, isBoolean, isNumeric, isPrimitive, primitiveType, typeName, withNullability, } from './types.js';
5
+ /** The element domains `mode` orders for its tie-break. */
6
+ const MODE_DOMAINS = new Set([
7
+ 'integer',
8
+ 'decimal',
9
+ 'string',
10
+ 'date',
11
+ 'instant',
12
+ 'boolean',
13
+ ]);
14
+ /**
15
+ * How a key argument reads in a repair: one member path, or the composite list of them.
16
+ * `undefined` when the argument is not a path shape, so a refusal never invents a form.
17
+ */
18
+ function keyRepair(node) {
19
+ if (node === undefined)
20
+ return undefined;
21
+ if (node.kind === 'path')
22
+ return node.path;
23
+ if (node.kind !== 'list')
24
+ return undefined;
25
+ const paths = [];
26
+ for (const item of node.items) {
27
+ if (item.kind !== 'path')
28
+ return undefined;
29
+ paths.push(item.path);
30
+ }
31
+ return paths.length === 0 ? undefined : `[${paths.join(', ')}]`;
32
+ }
33
+ /**
34
+ * The repair for a list that holds another list, `is_unique([f_rows], key)`.
35
+ *
36
+ * The two-argument form compares members of the rows the first argument names, so that
37
+ * argument is the list itself. Wrapping it in a list literal produces a list of lists, whose
38
+ * elements are not records: the runtime can only answer `UNKNOWN` for it (`EXPR-10.2.5`), and
39
+ * the checker must not accept a form that can never be decided. The repair names the form the
40
+ * author already has, with one bracket removed; an operand that is not the one-element literal
41
+ * is described by its type instead of inventing a spelling.
42
+ */
43
+ function wrappedListRepair(node, operand) {
44
+ const [listNode, keyNode] = node.args;
45
+ const key = keyRepair(keyNode);
46
+ const keyed = key === undefined ? '' : `, ${key}`;
47
+ const inner = listNode?.kind === 'list' && listNode.items.length === 1 && listNode.items[0]?.kind === 'path'
48
+ ? listNode.items[0].path
49
+ : undefined;
50
+ if (inner === undefined) {
51
+ return `\`is_unique\` compares members of one list of rows, but this operand is ${typeName(operand)}; pass the list itself, or project the key with \`is_unique(r in xs: r.key)\``;
52
+ }
53
+ return `\`is_unique\` compares members of one list of rows, but \`[${inner}]\` wraps that list in another; write \`is_unique(${inner}${keyed})\`, or project the key with \`is_unique(r in xs: r.key)\``;
54
+ }
55
+ export function aggregateType(ctx, op, node, operands) {
56
+ switch (op) {
57
+ case 'is_unique': {
58
+ const first = node.args[0];
59
+ // A comprehension projects the comparison key per element: `is_unique(x in xs: key)`.
60
+ // It is the keyed form a path cannot express, because the key is an expression rather
61
+ // than one member, and it takes no second argument — the projection is the key.
62
+ if (first?.kind === 'comprehension') {
63
+ if (node.args.length > 1) {
64
+ throw ctx.mismatch(node, '`is_unique` takes one comprehension, whose value projection is the key; remove the second argument');
65
+ }
66
+ if (first.valueExpr === undefined) {
67
+ throw ctx.mismatch(first, '`is_unique` requires a value projection to compare as its key');
68
+ }
69
+ const operand = operands.requireList(0);
70
+ const element = operand.element;
71
+ // A key is compared under the equality rule, so it has to be a value of one domain:
72
+ // a record or a list has none, and uniqueness would otherwise answer from a
73
+ // canonical spelling rather than from the language's equality.
74
+ if (element === undefined || element.kind !== 'primitive') {
75
+ throw ctx.mismatch(first.valueExpr, `\`is_unique\` compares each computed key, and ${withArticle(typeName(element ?? primitiveType('null')))} key has no domain to compare in; project a primitive value`);
76
+ }
77
+ return primitiveType('boolean');
78
+ }
79
+ const operand = operands.requireList(0);
80
+ // A list of lists is not a list of rows: `[f_rows]` holds one element, and that element
81
+ // is itself a list, so a key path relative to "each element" names a member of a list
82
+ // and the runtime can only answer `UNKNOWN` (`EXPR-10.2.5`). Refuse it with the form
83
+ // that states the list itself.
84
+ if (operand.element?.kind === 'list') {
85
+ throw ctx.mismatch(operands.nodeAt(0), wrappedListRepair(node, operand));
86
+ }
87
+ // One argument covers the elements themselves, so an element must be
88
+ // a value the equality rule defines: a record has no domain to compare in, and the
89
+ // absence of one would leave uniqueness answered from a canonical spelling.
90
+ if (node.args.length === 1) {
91
+ const element = operand.element;
92
+ if (element === undefined && operand.open) {
93
+ // An open list states no element domain, so uniqueness would have to guess whether
94
+ // `"7"` is an amount: refuse rather than answer from a canonical spelling.
95
+ throw ctx.mismatch(operands.nodeAt(0), '`is_unique` compares the elements themselves, and this list declares no element type; name the member with a second argument');
96
+ }
97
+ if (element !== undefined && element.kind !== 'primitive') {
98
+ throw ctx.mismatch(operands.nodeAt(0), `\`is_unique\` compares the elements themselves, and ${withArticle(typeName(element))} has no domain to compare in; name the member with a second argument`);
99
+ }
100
+ return primitiveType('boolean');
101
+ }
102
+ // The key is a member path of the element, or a list of paths for a composite key.
103
+ // Either way a misspelt segment is a compile error naming the element's fields rather
104
+ // than a runtime `ENGINE_ERROR`.
105
+ const element = operand.element;
106
+ // A two-argument key is relative to each element, so an open list states no element to
107
+ // read it from; the form to write is the comprehension projection below.
108
+ if (element === undefined && operand.open) {
109
+ throw ctx.mismatch(operands.nodeAt(0), `\`is_unique\` requires a list with a declared element type to read a key from, got ${typeName(operand)}`);
110
+ }
111
+ const key = operands.nodeAt(1);
112
+ const keyNodes = key.kind === 'list' ? key.items : [key];
113
+ if (key.kind === 'list' && key.items.length === 0) {
114
+ throw ctx.mismatch(key, '`is_unique` requires at least one member path in a composite key');
115
+ }
116
+ for (const keyNode of keyNodes) {
117
+ if (keyNode.kind !== 'path') {
118
+ throw ctx.mismatch(keyNode, '`is_unique` compares member paths, so its second argument is a path or a list of paths relative to each element');
119
+ }
120
+ if (element !== undefined) {
121
+ // A key is compared under the equality rule, so it must be a value of one domain:
122
+ // a record or a list has none, and uniqueness would otherwise answer from a
123
+ // canonical spelling. Money is primitive and keeps its declared equality by
124
+ // currency and scale, so it stays admitted (`EXPR-10.2.5`).
125
+ const keyType = descendType(element, keyNode.path.split('.'), ctx.offsetOf(keyNode));
126
+ if (keyType.kind !== 'primitive') {
127
+ throw ctx.mismatch(keyNode, `\`is_unique\` compares each key, and ${withArticle(typeName(keyType))} key has no domain to compare in; compare a primitive value; project the key with \`is_unique(r in xs: r.key)\``);
128
+ }
129
+ }
130
+ }
131
+ return primitiveType('boolean');
132
+ }
133
+ case 'all':
134
+ case 'any': {
135
+ const operand = operands.typeAt(0);
136
+ if (operand.kind !== 'list') {
137
+ throw ctx.mismatch(operands.nodeAt(0), `\`${op}\` requires a list of booleans, got ${typeName(operand)}`);
138
+ }
139
+ // An open list states no element type, so the fold would have to decide each element's
140
+ // outcome from its runtime value; an untyped element then raised `ENGINE_ERROR` instead
141
+ // of the expression being refused. The closed empty literal is still the documented
142
+ // `PASS`/`FAIL` identity (`EXPR-10.2.1`).
143
+ if (operand.element === undefined && operand.open) {
144
+ throw ctx.mismatch(operands.nodeAt(0), `\`${op}\` requires a list with a declared boolean element type, got ${typeName(operand)}`);
145
+ }
146
+ if (operand.element !== undefined && !isBoolean(operand.element)) {
147
+ throw ctx.mismatch(operands.nodeAt(0), `\`${op}\` requires a list of booleans, got ${typeName(operand)}`);
148
+ }
149
+ return primitiveType('boolean');
150
+ }
151
+ case 'sum': {
152
+ const operand = operands.requireList(0);
153
+ const element = operand.element;
154
+ // An open list states no element domain, so a populated `sum` could only be `UNKNOWN`
155
+ // while an empty one answered decimal `0` — the same expression disagreeing with itself.
156
+ // Refusing is the rule `min`/`avg`/`first` already state (`EXPR-10.2.2`).
157
+ if (element === undefined && operand.open) {
158
+ throw ctx.mismatch(operands.nodeAt(0), `\`${op}\` requires a list with a declared element type, got ${typeName(operand)}`);
159
+ }
160
+ // The element type decides the result: money stays money with the spelling its
161
+ // elements carry (`list<money<C,S>> -> money<C,S>`), and a numeric list answers
162
+ // canonical decimal text whatever the elements are (`list<decimal|integer> -> decimal`,
163
+ // `EXPR-6.1.9`). An empty list states no element, and `sum([])` is decimal `0`.
164
+ if (element !== undefined && isPrimitive(element, 'quantity')) {
165
+ // A quantity list totals only within one unit; v1 defines no unit conversion, so an
166
+ // empty list names no unit and `sum` is undecided on it.
167
+ noteUndecidedFold(ctx, node, op, operands.nodeAt(0), 'quantity');
168
+ return element;
169
+ }
170
+ if (element !== undefined && isPrimitive(element, 'duration')) {
171
+ // `MODEL-2.1.24`: `sum` folds a duration list of one unit. An empty list names
172
+ // no unit, so it is undecided there exactly as over a quantity list.
173
+ noteUndecidedFold(ctx, node, op, operands.nodeAt(0), 'duration');
174
+ return element;
175
+ }
176
+ if (element !== undefined && isPrimitive(element, 'money')) {
177
+ noteUndecidedFold(ctx, node, 'sum', operands.nodeAt(0));
178
+ return element;
179
+ }
180
+ if (element !== undefined && !isNumeric(element)) {
181
+ throw ctx.mismatch(operands.nodeAt(0), `\`${op}\` requires a list of numbers, got ${typeName(operand)}`);
182
+ }
183
+ return primitiveType('decimal');
184
+ }
185
+ case 'count_distinct': {
186
+ const operand = operands.requireList(0);
187
+ // A comprehension projects the value whose equality classes are counted: the key is
188
+ // the body (`count_distinct(r in f_rows: r.f_code)`), so the fold and the list form
189
+ // compare exactly one domain per element (`EXPR-3.1.2`, `EXPR-10.2.5`).
190
+ const projection = node.args[0]?.kind === 'comprehension';
191
+ // Distinctness compares under the equality rule, so an element must be a value of one
192
+ // domain; a record or a list has none, and an open list would have to guess.
193
+ if (operand.open && operand.element === undefined) {
194
+ throw ctx.mismatch(operands.nodeAt(0), '`count_distinct` compares the elements themselves, and this list declares no element type');
195
+ }
196
+ if (operand.element !== undefined && operand.element.kind !== 'primitive') {
197
+ throw ctx.mismatch(operands.nodeAt(0), `\`count_distinct\` ${projection ? 'compares the projected key' : 'compares the elements themselves'}, and ${withArticle(typeName(operand.element))} has no domain to compare in; project a primitive value, such as \`count_distinct(r in xs: r.code)\``);
198
+ }
199
+ return primitiveType('integer');
200
+ }
201
+ case 'count_where': {
202
+ // The predicate form folds the body's outcome per element; the list form is `len`.
203
+ const operand = node.args[0];
204
+ if (operand === undefined || operand.kind !== 'comprehension') {
205
+ throw ctx.mismatch(node, '`count_where` takes a comprehension, such as `count_where(r in xs: r.ok)`; use `len(xs)` for the number of entries');
206
+ }
207
+ if (node.args.length !== 1) {
208
+ throw ctx.mismatch(node, '`count_where` takes one comprehension');
209
+ }
210
+ return primitiveType('integer');
211
+ }
212
+ case 'min':
213
+ case 'max': {
214
+ const operand = operands.requireList(0);
215
+ const element = operand.element;
216
+ if (element === undefined && operand.open) {
217
+ // An open list states no element domain, so the aggregate's result has no declared
218
+ // domain to carry. Refusing keeps a downstream `+` from treating the result as a
219
+ // number the artifact never stated.
220
+ throw ctx.mismatch(node, `\`${op}\` requires a list with a declared element type, got ${typeName(operand)}`);
221
+ }
222
+ if (element !== undefined &&
223
+ (element.kind !== 'primitive' || !ORDERABLE.has(element.primitive))) {
224
+ // A row has members, so the repair is a projection. A list of booleans or of
225
+ // composites has no projection into a record, so the refusal states the domains the
226
+ // aggregate accepts instead of inventing a member that does not exist.
227
+ const repair = element.kind === 'record'
228
+ ? `; project an orderable member, such as \`${op}(r in xs: r.amount)\``
229
+ : `; \`${op}\` accepts a list of integers, decimals, strings, dates, instants, money, quantities or durations`;
230
+ throw ctx.mismatch(node, `\`${op}\` requires orderable elements, got ${typeName(element)}${repair}`);
231
+ }
232
+ if (element === undefined) {
233
+ // Only an empty closed list reaches here; an open list was refused above. It has no
234
+ // element to order, so the aggregate can only be undetermined, and the declared
235
+ // type is the numeric placeholder every empty aggregate carries.
236
+ noteUndecidedFold(ctx, node, op, operands.nodeAt(0));
237
+ return primitiveType('decimal');
238
+ }
239
+ noteUndecidedFold(ctx, node, op, operands.nodeAt(0));
240
+ return element;
241
+ }
242
+ case 'avg':
243
+ case 'median': {
244
+ const operand = operands.requireList(0);
245
+ const element = operand.element;
246
+ if (element === undefined && operand.open) {
247
+ throw ctx.mismatch(operands.nodeAt(0), `\`${op}\` requires a list with a declared numeric element type, got ${typeName(operand)}`);
248
+ }
249
+ if (element !== undefined && isPrimitive(element, 'money')) {
250
+ // A currency amount divided by a count need not land on a minor unit, and the language
251
+ // has no half-cent: the exact answer would be unrepresentable rather than merely
252
+ // unrounded, so money is refused here and the repair names the numeric spelling.
253
+ throw ctx.mismatch(operands.nodeAt(0), `\`${op}\` requires numeric elements, and an exact ${op === 'avg' ? 'average' : 'median'} of money can fall between two minor units; take \`${op}(money_minor(x) in xs: x)\` and convert back with \`money_from_minor\` if the rounded amount is what you want`);
254
+ }
255
+ if (element !== undefined && !isNumeric(element)) {
256
+ throw ctx.mismatch(operands.nodeAt(0), `\`${op}\` requires numeric elements, got ${typeName(element)}`);
257
+ }
258
+ // An empty list has no count to divide by (`avg`) and no element to choose (`median`), so
259
+ // a rule over a list that may be empty decides nothing there (`EXPR-10.2.2`).
260
+ noteUndecidedFold(ctx, node, op, operands.nodeAt(0));
261
+ return primitiveType('decimal');
262
+ }
263
+ case 'first':
264
+ case 'last': {
265
+ const operand = operands.requireList(0);
266
+ const element = operand.element;
267
+ if (element === undefined) {
268
+ if (operand.open) {
269
+ // An open list states no element type, so the `T | null` result has no `T` to state.
270
+ throw ctx.mismatch(operands.nodeAt(0), `\`${op}\` requires a list with a declared element type, got ${typeName(operand)}`);
271
+ }
272
+ // Only an empty list literal reaches here; its one possible value is the empty value.
273
+ return primitiveType('null');
274
+ }
275
+ if (element.kind !== 'primitive') {
276
+ throw ctx.mismatch(operands.nodeAt(0), `\`${op}\` requires a list of primitive values, and ${withArticle(typeName(element))} has no null form to return for an empty list; project a primitive member, such as \`${op}(r in xs: r.code)\``);
277
+ }
278
+ // `T | null` is the binder's own convention for an edge with no neighbour (`EXPR-10.1.2`),
279
+ // and `nullable` is how the type states it without widening the element domain.
280
+ return withNullability(element, true);
281
+ }
282
+ case 'mode': {
283
+ const operand = operands.requireList(0);
284
+ const element = operand.element;
285
+ if (element === undefined && operand.open) {
286
+ throw ctx.mismatch(operands.nodeAt(0), `\`mode\` requires a list with a declared element type, got ${typeName(operand)}`);
287
+ }
288
+ if (element !== undefined &&
289
+ (element.kind !== 'primitive' || !MODE_DOMAINS.has(element.primitive))) {
290
+ // Money and quantity name an order only through a currency or a unit the element does
291
+ // not carry, and a record has no order at all, so the tie-break could not be stated.
292
+ throw ctx.mismatch(operands.nodeAt(0), `\`mode\` requires a list of integers, decimals, strings, dates, instants or booleans, got ${typeName(element)}${isPrimitive(element, 'money') ? '; money has no single canonical order, so the tie-break would be undefined' : ''}`);
293
+ }
294
+ // An empty list has no element to choose, so the answer is the empty value, never a
295
+ // value the document did not state (`EXPR-10.2.13`).
296
+ if (element === undefined)
297
+ return primitiveType('null');
298
+ return withNullability(element, true);
299
+ }
300
+ case 'map': {
301
+ const operandNode = operands.nodeAt(0);
302
+ if (operandNode.kind !== 'comprehension') {
303
+ throw ctx.mismatch(operandNode, '`map` takes a comprehension, such as `map(x in xs: x.amount)`; pass a list unchanged by naming it directly');
304
+ }
305
+ const projected = operands.requireList(0);
306
+ if (projected.element === undefined) {
307
+ throw ctx.mismatch(operands.nodeAt(0), '`map` requires a value projection, such as `map(x in xs: x.amount)`');
308
+ }
309
+ // The comprehension's own type is `list<type of the projection>`, which is exactly the
310
+ // produced list: no widening and no cast (`EXPR-10.2.11`).
311
+ return projected;
312
+ }
313
+ case 'filter': {
314
+ const operandNode = operands.nodeAt(0);
315
+ if (operandNode.kind !== 'comprehension') {
316
+ throw ctx.mismatch(operandNode, '`filter` takes a comprehension, such as `filter(x in xs: x.ok)`; pass the list itself when every element is wanted');
317
+ }
318
+ if (operandNode.valueExpr !== undefined) {
319
+ throw ctx.mismatch(operandNode, '`filter` keeps the elements themselves, so its comprehension takes a predicate and no value projection; write `map(x in xs: expr if pred)` to project kept elements');
320
+ }
321
+ // The source's list type is the result: `filter` copies elements, so it never changes the
322
+ // element domain (`EXPR-10.2.12`).
323
+ const source = ctx.check(operandNode.source);
324
+ if (source.kind !== 'list' || source.element === undefined) {
325
+ throw ctx.mismatch(operandNode.source, `\`filter\` iterates a list with a declared element type, got ${typeName(source)}`);
326
+ }
327
+ // Checking the comprehension binds the binder and validates the predicate; its own list
328
+ // type is the body's (boolean), which is not the result.
329
+ operands.typeAt(0);
330
+ return source;
331
+ }
332
+ }
333
+ }
334
+ //# sourceMappingURL=aggregates.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"aggregates.js","sourceRoot":"","sources":["../../../src/expr/typecheck/aggregates.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAE/C,OAAO,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAE9C,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAEzC,OAAO,EACL,SAAS,EACT,SAAS,EACT,SAAS,EACT,WAAW,EACX,aAAa,EACb,QAAQ,EACR,eAAe,GAChB,MAAM,YAAY,CAAC;AAoBpB,2DAA2D;AAC3D,MAAM,YAAY,GAAwB,IAAI,GAAG,CAAC;IAChD,SAAS;IACT,SAAS;IACT,QAAQ;IACR,MAAM;IACN,SAAS;IACT,SAAS;CACV,CAAC,CAAC;AAEH;;;GAGG;AACH,SAAS,SAAS,CAAC,IAA0B;IAC3C,IAAI,IAAI,KAAK,SAAS;QAAE,OAAO,SAAS,CAAC;IACzC,IAAI,IAAI,CAAC,IAAI,KAAK,MAAM;QAAE,OAAO,IAAI,CAAC,IAAI,CAAC;IAC3C,IAAI,IAAI,CAAC,IAAI,KAAK,MAAM;QAAE,OAAO,SAAS,CAAC;IAC3C,MAAM,KAAK,GAAa,EAAE,CAAC;IAC3B,KAAK,MAAM,IAAI,IAAI,IAAI,CAAC,KAAK,EAAE,CAAC;QAC9B,IAAI,IAAI,CAAC,IAAI,KAAK,MAAM;YAAE,OAAO,SAAS,CAAC;QAC3C,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACxB,CAAC;IACD,OAAO,KAAK,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,GA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J,CAAC;YACD,wFAAwF;YACxF,yDAAyD;YACzD,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;YACnB,OAAO,MAAM,CAAC;QAChB,CAAC;IACH,CAAC;AACH,CAAC","sourcesContent":["import type { CallNode, ExprNode } from '@azx-pbc/axiom-runtime';\nimport { withArticle } from '../../article.js';\nimport type { CheckContext } from './context.js';\nimport { noteUndecidedFold } from './fold.js';\nimport type { Operands } from './operands.js';\nimport { descendType } from './paths.js';\nimport type { StaticType } from './types.js';\nimport {\n ORDERABLE,\n isBoolean,\n isNumeric,\n isPrimitive,\n primitiveType,\n typeName,\n withNullability,\n} from './types.js';\n\n/** List aggregates, uniqueness and the ordered extrema. */\nexport type AggregateOperator =\n | 'is_unique'\n | 'all'\n | 'any'\n | 'sum'\n | 'count_where'\n | 'count_distinct'\n | 'min'\n | 'max'\n | 'avg'\n | 'median'\n | 'first'\n | 'last'\n | 'mode'\n | 'map'\n | 'filter';\n\n/** The element domains `mode` orders for its tie-break. */\nconst MODE_DOMAINS: ReadonlySet<string> = new Set([\n 'integer',\n 'decimal',\n 'string',\n 'date',\n 'instant',\n 'boolean',\n]);\n\n/**\n * How a key argument reads in a repair: one member path, or the composite list of them.\n * `undefined` when the argument is not a path shape, so a refusal never invents a form.\n */\nfunction keyRepair(node: ExprNode | undefined): string | undefined {\n if (node === undefined) return undefined;\n if (node.kind === 'path') return node.path;\n if (node.kind !== 'list') return undefined;\n const paths: string[] = [];\n for (const item of node.items) {\n if (item.kind !== 'path') return undefined;\n paths.push(item.path);\n }\n return paths.length === 0 ? undefined : `[${paths.join(', ')}]`;\n}\n\n/**\n * The repair for a list that holds another list, `is_unique([f_rows], key)`.\n *\n * The two-argument form compares members of the rows the first argument names, so that\n * argument is the list itself. Wrapping it in a list literal produces a list of lists, whose\n * elements are not records: the runtime can only answer `UNKNOWN` for it (`EXPR-10.2.5`), and\n * the checker must not accept a form that can never be decided. The repair names the form the\n * author already has, with one bracket removed; an operand that is not the one-element literal\n * is described by its type instead of inventing a spelling.\n */\nfunction wrappedListRepair(node: CallNode, operand: StaticType): string {\n const [listNode, keyNode] = node.args;\n const key = keyRepair(keyNode);\n const keyed = key === undefined ? '' : `, ${key}`;\n const inner =\n listNode?.kind === 'list' && listNode.items.length === 1 && listNode.items[0]?.kind === 'path'\n ? listNode.items[0].path\n : undefined;\n if (inner === undefined) {\n return `\\`is_unique\\` compares members of one list of rows, but this operand is ${typeName(operand)}; pass the list itself, or project the key with \\`is_unique(r in xs: r.key)\\``;\n }\n return `\\`is_unique\\` compares members of one list of rows, but \\`[${inner}]\\` wraps that list in another; write \\`is_unique(${inner}${keyed})\\`, or project the key with \\`is_unique(r in xs: r.key)\\``;\n}\n\nexport function aggregateType(\n ctx: CheckContext,\n op: AggregateOperator,\n node: CallNode,\n operands: Operands,\n): StaticType {\n switch (op) {\n case 'is_unique': {\n const first = node.args[0];\n // A comprehension projects the comparison key per element: `is_unique(x in xs: key)`.\n // It is the keyed form a path cannot express, because the key is an expression rather\n // than one member, and it takes no second argument — the projection is the key.\n if (first?.kind === 'comprehension') {\n if (node.args.length > 1) {\n throw ctx.mismatch(\n node,\n '`is_unique` takes one comprehension, whose value projection is the key; remove the second argument',\n );\n }\n if (first.valueExpr === undefined) {\n throw ctx.mismatch(\n first,\n '`is_unique` requires a value projection to compare as its key',\n );\n }\n const operand = operands.requireList(0);\n const element = operand.element;\n // A key is compared under the equality rule, so it has to be a value of one domain:\n // a record or a list has none, and uniqueness would otherwise answer from a\n // canonical spelling rather than from the language's equality.\n if (element === undefined || element.kind !== 'primitive') {\n throw ctx.mismatch(\n first.valueExpr,\n `\\`is_unique\\` compares each computed key, and ${withArticle(typeName(element ?? primitiveType('null')))} key has no domain to compare in; project a primitive value`,\n );\n }\n return primitiveType('boolean');\n }\n const operand = operands.requireList(0);\n // A list of lists is not a list of rows: `[f_rows]` holds one element, and that element\n // is itself a list, so a key path relative to \"each element\" names a member of a list\n // and the runtime can only answer `UNKNOWN` (`EXPR-10.2.5`). Refuse it with the form\n // that states the list itself.\n if (operand.element?.kind === 'list') {\n throw ctx.mismatch(operands.nodeAt(0), wrappedListRepair(node, operand));\n }\n // One argument covers the elements themselves, so an element must be\n // a value the equality rule defines: a record has no domain to compare in, and the\n // absence of one would leave uniqueness answered from a canonical spelling.\n if (node.args.length === 1) {\n const element = operand.element;\n if (element === undefined && operand.open) {\n // An open list states no element domain, so uniqueness would have to guess whether\n // `\"7\"` is an amount: refuse rather than answer from a canonical spelling.\n throw ctx.mismatch(\n operands.nodeAt(0),\n '`is_unique` compares the elements themselves, and this list declares no element type; name the member with a second argument',\n );\n }\n if (element !== undefined && element.kind !== 'primitive') {\n throw ctx.mismatch(\n operands.nodeAt(0),\n `\\`is_unique\\` compares the elements themselves, and ${withArticle(typeName(element))} has no domain to compare in; name the member with a second argument`,\n );\n }\n return primitiveType('boolean');\n }\n // The key is a member path of the element, or a list of paths for a composite key.\n // Either way a misspelt segment is a compile error naming the element's fields rather\n // than a runtime `ENGINE_ERROR`.\n const element = operand.element;\n // A two-argument key is relative to each element, so an open list states no element to\n // read it from; the form to write is the comprehension projection below.\n if (element === undefined && operand.open) {\n throw ctx.mismatch(\n operands.nodeAt(0),\n `\\`is_unique\\` requires a list with a declared element type to read a key from, got ${typeName(operand)}`,\n );\n }\n const key = operands.nodeAt(1);\n const keyNodes = key.kind === 'list' ? key.items : [key];\n if (key.kind === 'list' && key.items.length === 0) {\n throw ctx.mismatch(key, '`is_unique` requires at least one member path in a composite key');\n }\n for (const keyNode of keyNodes) {\n if (keyNode.kind !== 'path') {\n throw ctx.mismatch(\n keyNode,\n '`is_unique` compares member paths, so its second argument is a path or a list of paths relative to each element',\n );\n }\n if (element !== undefined) {\n // A key is compared under the equality rule, so it must be a value of one domain:\n // a record or a list has none, and uniqueness would otherwise answer from a\n // canonical spelling. Money is primitive and keeps its declared equality by\n // currency and scale, so it stays admitted (`EXPR-10.2.5`).\n const keyType = descendType(element, keyNode.path.split('.'), ctx.offsetOf(keyNode));\n if (keyType.kind !== 'primitive') {\n throw ctx.mismatch(\n keyNode,\n `\\`is_unique\\` compares each key, and ${withArticle(typeName(keyType))} key has no domain to compare in; compare a primitive value; project the key with \\`is_unique(r in xs: r.key)\\``,\n );\n }\n }\n }\n return primitiveType('boolean');\n }\n case 'all':\n case 'any': {\n const operand = operands.typeAt(0);\n if (operand.kind !== 'list') {\n throw ctx.mismatch(\n operands.nodeAt(0),\n `\\`${op}\\` requires a list of booleans, got ${typeName(operand)}`,\n );\n }\n // An open list states no element type, so the fold would have to decide each element's\n // outcome from its runtime value; an untyped element then raised `ENGINE_ERROR` instead\n // of the expression being refused. The closed empty literal is still the documented\n // `PASS`/`FAIL` identity (`EXPR-10.2.1`).\n if (operand.element === undefined && operand.open) {\n throw ctx.mismatch(\n operands.nodeAt(0),\n `\\`${op}\\` requires a list with a declared boolean element type, got ${typeName(operand)}`,\n );\n }\n if (operand.element !== undefined && !isBoolean(operand.element)) {\n throw ctx.mismatch(\n operands.nodeAt(0),\n `\\`${op}\\` requires a list of booleans, got ${typeName(operand)}`,\n );\n }\n return primitiveType('boolean');\n }\n case 'sum': {\n const operand = operands.requireList(0);\n const element = operand.element;\n // An open list states no element domain, so a populated `sum` could only be `UNKNOWN`\n // while an empty one answered decimal `0` — the same expression disagreeing with itself.\n // Refusing is the rule `min`/`avg`/`first` already state (`EXPR-10.2.2`).\n if (element === undefined && operand.open) {\n throw ctx.mismatch(\n operands.nodeAt(0),\n `\\`${op}\\` requires a list with a declared element type, got ${typeName(operand)}`,\n );\n }\n // The element type decides the result: money stays money with the spelling its\n // elements carry (`list<money<C,S>> -> money<C,S>`), and a numeric list answers\n // canonical decimal text whatever the elements are (`list<decimal|integer> -> decimal`,\n // `EXPR-6.1.9`). An empty list states no element, and `sum([])` is decimal `0`.\n if (element !== undefined && isPrimitive(element, 'quantity')) {\n // A quantity list totals only within one unit; v1 defines no unit conversion, so an\n // empty list names no unit and `sum` is undecided on it.\n noteUndecidedFold(ctx, node, op, operands.nodeAt(0), 'quantity');\n return element;\n }\n if (element !== undefined && isPrimitive(element, 'duration')) {\n // `MODEL-2.1.24`: `sum` folds a duration list of one unit. An empty list names\n // no unit, so it is undecided there exactly as over a quantity list.\n noteUndecidedFold(ctx, node, op, operands.nodeAt(0), 'duration');\n return element;\n }\n if (element !== undefined && isPrimitive(element, 'money')) {\n noteUndecidedFold(ctx, node, 'sum', operands.nodeAt(0));\n return element;\n }\n if (element !== undefined && !isNumeric(element)) {\n throw ctx.mismatch(\n operands.nodeAt(0),\n `\\`${op}\\` requires a list of numbers, got ${typeName(operand)}`,\n );\n }\n return primitiveType('decimal');\n }\n case 'count_distinct': {\n const operand = operands.requireList(0);\n // A comprehension projects the value whose equality classes are counted: the key is\n // the body (`count_distinct(r in f_rows: r.f_code)`), so the fold and the list form\n // compare exactly one domain per element (`EXPR-3.1.2`, `EXPR-10.2.5`).\n const projection = node.args[0]?.kind === 'comprehension';\n // Distinctness compares under the equality rule, so an element must be a value of one\n // domain; a record or a list has none, and an open list would have to guess.\n if (operand.open && operand.element === undefined) {\n throw ctx.mismatch(\n operands.nodeAt(0),\n '`count_distinct` compares the elements themselves, and this list declares no element type',\n );\n }\n if (operand.element !== undefined && operand.element.kind !== 'primitive') {\n throw ctx.mismatch(\n operands.nodeAt(0),\n `\\`count_distinct\\` ${projection ? 'compares the projected key' : 'compares the elements themselves'}, and ${withArticle(typeName(operand.element))} has no domain to compare in; project a primitive value, such as \\`count_distinct(r in xs: r.code)\\``,\n );\n }\n return primitiveType('integer');\n }\n case 'count_where': {\n // The predicate form folds the body's outcome per element; the list form is `len`.\n const operand = node.args[0];\n if (operand === undefined || operand.kind !== 'comprehension') {\n throw ctx.mismatch(\n node,\n '`count_where` takes a comprehension, such as `count_where(r in xs: r.ok)`; use `len(xs)` for the number of entries',\n );\n }\n if (node.args.length !== 1) {\n throw ctx.mismatch(node, '`count_where` takes one comprehension');\n }\n return primitiveType('integer');\n }\n case 'min':\n case 'max': {\n const operand = operands.requireList(0);\n const element = operand.element;\n if (element === undefined && operand.open) {\n // An open list states no element domain, so the aggregate's result has no declared\n // domain to carry. Refusing keeps a downstream `+` from treating the result as a\n // number the artifact never stated.\n throw ctx.mismatch(\n node,\n `\\`${op}\\` requires a list with a declared element type, got ${typeName(operand)}`,\n );\n }\n if (\n element !== undefined &&\n (element.kind !== 'primitive' || !ORDERABLE.has(element.primitive))\n ) {\n // A row has members, so the repair is a projection. A list of booleans or of\n // composites has no projection into a record, so the refusal states the domains the\n // aggregate accepts instead of inventing a member that does not exist.\n const repair =\n element.kind === 'record'\n ? `; project an orderable member, such as \\`${op}(r in xs: r.amount)\\``\n : `; \\`${op}\\` accepts a list of integers, decimals, strings, dates, instants, money, quantities or durations`;\n throw ctx.mismatch(\n node,\n `\\`${op}\\` requires orderable elements, got ${typeName(element)}${repair}`,\n );\n }\n if (element === undefined) {\n // Only an empty closed list reaches here; an open list was refused above. It has no\n // element to order, so the aggregate can only be undetermined, and the declared\n // type is the numeric placeholder every empty aggregate carries.\n noteUndecidedFold(ctx, node, op, operands.nodeAt(0));\n return primitiveType('decimal');\n }\n noteUndecidedFold(ctx, node, op, operands.nodeAt(0));\n return element;\n }\n case 'avg':\n case 'median': {\n const operand = operands.requireList(0);\n const element = operand.element;\n if (element === undefined && operand.open) {\n throw ctx.mismatch(\n operands.nodeAt(0),\n `\\`${op}\\` requires a list with a declared numeric element type, got ${typeName(operand)}`,\n );\n }\n if (element !== undefined && isPrimitive(element, 'money')) {\n // A currency amount divided by a count need not land on a minor unit, and the language\n // has no half-cent: the exact answer would be unrepresentable rather than merely\n // unrounded, so money is refused here and the repair names the numeric spelling.\n throw ctx.mismatch(\n operands.nodeAt(0),\n `\\`${op}\\` requires numeric elements, and an exact ${op === 'avg' ? 'average' : 'median'} of money can fall between two minor units; take \\`${op}(money_minor(x) in xs: x)\\` and convert back with \\`money_from_minor\\` if the rounded amount is what you want`,\n );\n }\n if (element !== undefined && !isNumeric(element)) {\n throw ctx.mismatch(\n operands.nodeAt(0),\n `\\`${op}\\` requires numeric elements, got ${typeName(element)}`,\n );\n }\n // An empty list has no count to divide by (`avg`) and no element to choose (`median`), so\n // a rule over a list that may be empty decides nothing there (`EXPR-10.2.2`).\n noteUndecidedFold(ctx, node, op, operands.nodeAt(0));\n return primitiveType('decimal');\n }\n case 'first':\n case 'last': {\n const operand = operands.requireList(0);\n const element = operand.element;\n if (element === undefined) {\n if (operand.open) {\n // An open list states no element type, so the `T | null` result has no `T` to state.\n throw ctx.mismatch(\n operands.nodeAt(0),\n `\\`${op}\\` requires a list with a declared element type, got ${typeName(operand)}`,\n );\n }\n // Only an empty list literal reaches here; its one possible value is the empty value.\n return primitiveType('null');\n }\n if (element.kind !== 'primitive') {\n throw ctx.mismatch(\n operands.nodeAt(0),\n `\\`${op}\\` requires a list of primitive values, and ${withArticle(typeName(element))} has no null form to return for an empty list; project a primitive member, such as \\`${op}(r in xs: r.code)\\``,\n );\n }\n // `T | null` is the binder's own convention for an edge with no neighbour (`EXPR-10.1.2`),\n // and `nullable` is how the type states it without widening the element domain.\n return withNullability(element, true);\n }\n case 'mode': {\n const operand = operands.requireList(0);\n const element = operand.element;\n if (element === undefined && operand.open) {\n throw ctx.mismatch(\n operands.nodeAt(0),\n `\\`mode\\` requires a list with a declared element type, got ${typeName(operand)}`,\n );\n }\n if (\n element !== undefined &&\n (element.kind !== 'primitive' || !MODE_DOMAINS.has(element.primitive))\n ) {\n // Money and quantity name an order only through a currency or a unit the element does\n // not carry, and a record has no order at all, so the tie-break could not be stated.\n throw ctx.mismatch(\n operands.nodeAt(0),\n `\\`mode\\` requires a list of integers, decimals, strings, dates, instants or booleans, got ${typeName(element)}${isPrimitive(element, 'money') ? '; money has no single canonical order, so the tie-break would be undefined' : ''}`,\n );\n }\n // An empty list has no element to choose, so the answer is the empty value, never a\n // value the document did not state (`EXPR-10.2.13`).\n if (element === undefined) return primitiveType('null');\n return withNullability(element, true);\n }\n case 'map': {\n const operandNode = operands.nodeAt(0);\n if (operandNode.kind !== 'comprehension') {\n throw ctx.mismatch(\n operandNode,\n '`map` takes a comprehension, such as `map(x in xs: x.amount)`; pass a list unchanged by naming it directly',\n );\n }\n const projected = operands.requireList(0);\n if (projected.element === undefined) {\n throw ctx.mismatch(\n operands.nodeAt(0),\n '`map` requires a value projection, such as `map(x in xs: x.amount)`',\n );\n }\n // The comprehension's own type is `list<type of the projection>`, which is exactly the\n // produced list: no widening and no cast (`EXPR-10.2.11`).\n return projected;\n }\n case 'filter': {\n const operandNode = operands.nodeAt(0);\n if (operandNode.kind !== 'comprehension') {\n throw ctx.mismatch(\n operandNode,\n '`filter` takes a comprehension, such as `filter(x in xs: x.ok)`; pass the list itself when every element is wanted',\n );\n }\n if (operandNode.valueExpr !== undefined) {\n throw ctx.mismatch(\n operandNode,\n '`filter` keeps the elements themselves, so its comprehension takes a predicate and no value projection; write `map(x in xs: expr if pred)` to project kept elements',\n );\n }\n // The source's list type is the result: `filter` copies elements, so it never changes the\n // element domain (`EXPR-10.2.12`).\n const source = ctx.check(operandNode.source);\n if (source.kind !== 'list' || source.element === undefined) {\n throw ctx.mismatch(\n operandNode.source,\n `\\`filter\\` iterates a list with a declared element type, got ${typeName(source)}`,\n );\n }\n // Checking the comprehension binds the binder and validates the predicate; its own list\n // type is the body's (boolean), which is not the result.\n operands.typeAt(0);\n return source;\n }\n }\n}\n"]}
@@ -0,0 +1,6 @@
1
+ import type { CallNode } from '@azx-pbc/axiom-runtime';
2
+ import type { CheckContext } from './context.js';
3
+ import type { StaticType } from './types.js';
4
+ /** `+`, `-`, `*` and `/`: string concatenation, unary negation, numeric widening, division or measurement arithmetic. */
5
+ export declare function arithmeticType(ctx: CheckContext, op: '+' | '-' | '*' | '/' | '%' | '//', node: CallNode): StaticType;
6
+ //# sourceMappingURL=arithmetic.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"arithmetic.d.ts","sourceRoot":"","sources":["../../../src/expr/typecheck/arithmetic.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAY,MAAM,wBAAwB,CAAC;AAEjE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AACjD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAkB7C,yHAAyH;AACzH,wBAAgB,cAAc,CAC5B,GAAG,EAAE,YAAY,EACjB,EAAE,EAAE,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,IAAI,EACtC,IAAI,EAAE,QAAQ,GACb,UAAU,CAiCZ"}