@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,321 @@
1
+ import { isIntrinsicPrimitive, intrinsicMembers, memberOf, valueDomainOf, } from '@azx-pbc/axiom-runtime';
2
+ import { withArticle } from '../../article.js';
3
+ import { ExpressionCompileError } from '../diagnostics.js';
4
+ import { closestByLeaf, closestNames, spreadsheetSuggestions } from '../suggest.js';
5
+ import { primitiveType, staticTypeOf, staticTypeOfDomain, typeName } from './types.js';
6
+ /**
7
+ * Rewrites a path ending in `.length` in place to `len(<targetPath>)` once the receiver's type
8
+ * is known to be a string or list, so a record member genuinely named `length` is never shadowed.
9
+ */
10
+ function lowerPathToLen(node, targetPath) {
11
+ Reflect.deleteProperty(node, 'path');
12
+ Object.assign(node, {
13
+ kind: 'call',
14
+ op: 'len',
15
+ args: [{ kind: 'path', path: targetPath }],
16
+ });
17
+ return primitiveType('integer');
18
+ }
19
+ /** The members a bare name could have meant, read through the record that holds them. */
20
+ function nestedRecordCandidates(fields, prefix = '') {
21
+ const candidates = [];
22
+ for (const field of fields) {
23
+ const path = prefix === '' ? field.fieldId : `${prefix}.${field.fieldId}`;
24
+ // A root field is offered by its own id; a nested member is only reachable through its
25
+ // container, so the suggestion is the whole path even though the typo is in the leaf.
26
+ if (prefix !== '')
27
+ candidates.push({ leaf: field.fieldId, suggestion: path });
28
+ // An array's row members are not read through the array path: the row is reached through
29
+ // `$it` inside an item rule, which `itemRowCandidates` offers instead.
30
+ if (field.primitive === 'record') {
31
+ candidates.push(...nestedRecordCandidates(field.fields ?? [], path));
32
+ }
33
+ }
34
+ return candidates;
35
+ }
36
+ /** The row members a bare name could have meant inside an item-scoped rule. */
37
+ function itemRowCandidates(ctx) {
38
+ const row = ctx.bindings().get('$it');
39
+ if (row?.kind !== 'record')
40
+ return [];
41
+ return row.fields.map((field) => ({
42
+ leaf: field.fieldId,
43
+ suggestion: `$it.${field.fieldId}`,
44
+ }));
45
+ }
46
+ /**
47
+ * The declared names a bare unknown segment could have meant: root ids, members reached
48
+ * through a record, and, inside an item rule, members of the row through `$it`.
49
+ */
50
+ function fieldSuggestions(ctx, name) {
51
+ return [
52
+ ...new Set([
53
+ ...spreadsheetSuggestions(name),
54
+ ...closestNames(name, [...ctx.fields.keys()]),
55
+ ...closestByLeaf(name, nestedRecordCandidates([...ctx.fields.values()])),
56
+ ...closestByLeaf(name, itemRowCandidates(ctx)),
57
+ ]),
58
+ ].slice(0, 3);
59
+ }
60
+ /** The static type a path names, resolving binders, context roots and declared fields. */
61
+ export function pathType(ctx, node) {
62
+ const path = node.path;
63
+ const offset = ctx.offsetOf(node);
64
+ if (path.startsWith('$')) {
65
+ const segments = path.split('.');
66
+ const sigil = segments[0] ?? path;
67
+ const base = ctx.bindings().get(sigil);
68
+ if (base === undefined) {
69
+ throw new ExpressionCompileError('UNKNOWN_IDENTIFIER', offset, `\`${sigil}\` is not in scope here; \`$row\` names an item rule's row, and \`$it\`, \`$i\`, \`$prev\` and \`$next\` are comprehension binders`, ['$row', '$it', '$i', '$prev', '$next']);
70
+ }
71
+ return descendType(base, segments.slice(1), offset, { node, basePath: sigil });
72
+ }
73
+ const segments = path.split('.');
74
+ const [first, ...rest] = segments;
75
+ if (first === undefined) {
76
+ throw new ExpressionCompileError('EXPR_PARSE_ERROR', offset, 'a path is empty');
77
+ }
78
+ const bound = ctx.bindings().get(first);
79
+ if (bound !== undefined)
80
+ return descendType(bound, rest, offset, { node, basePath: first });
81
+ if (first === 'context') {
82
+ // `context` is not a reserved word and makes every declared
83
+ // field a read root, so a record may hold a field with that name. The declared roots own
84
+ // the prefix wherever they claim the path; a path no root declares reads the field.
85
+ const named = ctx.fields.get('context');
86
+ const contextTarget = rest.join('.');
87
+ const contextLengthBase = rest.length >= 2 && rest[rest.length - 1] === 'length'
88
+ ? rest.slice(0, -1).join('.')
89
+ : undefined;
90
+ if (named === undefined ||
91
+ ctx.contextRoots.has(contextTarget) ||
92
+ (contextLengthBase !== undefined && ctx.contextRoots.has(contextLengthBase))) {
93
+ return contextPathType(ctx, rest, offset, node);
94
+ }
95
+ return declaredPathType(named, rest, offset, node);
96
+ }
97
+ const field = ctx.fields.get(first);
98
+ if (field === undefined) {
99
+ if (ctx.fields.size === 0) {
100
+ throw new ExpressionCompileError('UNKNOWN_IDENTIFIER', offset, `\`${first}\` is not a context root; a guard compiled without a record may read only context roots and literals`, [
101
+ ...new Set([
102
+ ...spreadsheetSuggestions(first),
103
+ ...closestNames(first, [...ctx.contextRoots.keys()]).map((root) => `context.${root}`),
104
+ ]),
105
+ ]);
106
+ }
107
+ throw new ExpressionCompileError('UNKNOWN_IDENTIFIER', offset, `\`${first}\` is not a declared field or context root`, fieldSuggestions(ctx, first));
108
+ }
109
+ return declaredPathType(field, rest, offset, node);
110
+ }
111
+ function contextPathType(ctx, rest, offset, node) {
112
+ const path = rest.join('.');
113
+ const root = ctx.contextRoots.get(path);
114
+ if (root === undefined) {
115
+ if (rest.length >= 2 && rest[rest.length - 1] === 'length') {
116
+ const prefix = rest.slice(0, -1).join('.');
117
+ const declared = ctx.contextRoots.get(prefix);
118
+ if (declared !== undefined &&
119
+ (declared.primitive === 'string' || declared.primitive === 'array')) {
120
+ return lowerPathToLen(node, `context.${prefix}`);
121
+ }
122
+ }
123
+ const arrayRoot = arrayRootOf(ctx, path);
124
+ if (arrayRoot !== undefined) {
125
+ const member = path.slice(arrayRoot.length + 1).split('.')[0] ?? '';
126
+ // A scalar or attachment array has no row, so its refusal names the binder rather than
127
+ // a member the element never had.
128
+ const declared = ctx.contextRoots.get(arrayRoot);
129
+ if (declared?.items !== undefined) {
130
+ throw new ExpressionCompileError('TYPE_MISMATCH', offset, `\`context.${path}\` reads a member of \`context.${arrayRoot}\`, whose elements are ${declared.items.primitive} values; element access uses a comprehension binder such as \`$it\`, never a member path`);
131
+ }
132
+ throw new ExpressionCompileError('TYPE_MISMATCH', offset, `\`context.${path}\` reads a member of the array \`context.${arrayRoot}\`; a row has no identity until a binder names it, so address the row as \`$it.${member}\` inside an item rule`);
133
+ }
134
+ const recordRoot = recordRootOf(ctx, path);
135
+ if (recordRoot !== undefined) {
136
+ throw new ExpressionCompileError('UNKNOWN_IDENTIFIER', offset, `\`context.${path}\` reads a member of \`context.${recordRoot}\`, a \`record\` context root; v1 reads a context root as one value, never its members, so declare \`context.${path}\` as its own root (a nested member is declared by its full dotted path) or move the related rows into a dataset table`, [`context.${recordRoot}`]);
137
+ }
138
+ throw new ExpressionCompileError('UNKNOWN_IDENTIFIER', offset, `\`context.${path}\` is not a declared context root`, closestNames(path, [...ctx.contextRoots.keys()]));
139
+ }
140
+ if (root.primitive === 'array') {
141
+ return {
142
+ kind: 'list',
143
+ element: root.items === undefined ? undefined : staticTypeOfDomain(valueDomainOf(root.items)),
144
+ open: root.items === undefined,
145
+ };
146
+ }
147
+ if (root.primitive === 'record')
148
+ return { kind: 'record', fields: [], open: true };
149
+ return staticTypeOfDomain(valueDomainOf(root));
150
+ }
151
+ /**
152
+ * The longest declared `record` context root `path` descends into, if any.
153
+ *
154
+ * A root is read as one value (`CTX-1.2.1`), and a nested member is declared as its own full
155
+ * dotted path (`CTX-2.1.1`), so a member read below a `record` root names nothing the reader
156
+ * could resolve. The declaration is still useful — `present(context.subject)` is the whole-root
157
+ * question — which is why the refusal is stated at the read rather than at the declaration.
158
+ */
159
+ function recordRootOf(ctx, path) {
160
+ const segments = path.split('.');
161
+ for (let length = segments.length - 1; length > 0; length -= 1) {
162
+ const prefix = segments.slice(0, length).join('.');
163
+ const declared = ctx.contextRoots.get(prefix);
164
+ if (declared === undefined)
165
+ continue;
166
+ return declared.primitive === 'record' ? prefix : undefined;
167
+ }
168
+ return undefined;
169
+ }
170
+ /**
171
+ * The longest declared `array` context root `path` descends into, if any.
172
+ *
173
+ * An array root is read as one list value; a member of a row is reached through a binder, not
174
+ * through the list path (`EXPR-3.1.3`). The evaluator refuses the same descent, so a compiler
175
+ * that resolved it would produce an expression that can only fail.
176
+ */
177
+ function arrayRootOf(ctx, path) {
178
+ const segments = path.split('.');
179
+ for (let length = segments.length - 1; length > 0; length -= 1) {
180
+ const prefix = segments.slice(0, length).join('.');
181
+ const declared = ctx.contextRoots.get(prefix);
182
+ if (declared === undefined)
183
+ continue;
184
+ return declared.primitive === 'array' ? prefix : undefined;
185
+ }
186
+ return undefined;
187
+ }
188
+ function declaredPathType(field, rest, offset, node) {
189
+ let current = field;
190
+ // The path read so far, so a refusal and its repair name the same text the author wrote.
191
+ let walked = field.fieldId;
192
+ let type = staticTypeOf(current);
193
+ for (const [index, segment] of rest.entries()) {
194
+ // An array's row members are reached through a binder, never through the array path:
195
+ // a path that descends into a list is element access, and Expr v1 has no index node and
196
+ // no row identity without a binder (`EXPR-3.1.3`, `EXPR-10.1.2`). The reader refuses the
197
+ // same path at evaluation, so accepting it here would be an expression that compiles and
198
+ // then decides nothing. `.length` on an array is the property sugar for `len(xs)`.
199
+ if (current.primitive === 'array') {
200
+ if (segment === 'length') {
201
+ const trailing = rest[index + 1];
202
+ if (trailing !== undefined) {
203
+ throw new ExpressionCompileError('TYPE_MISMATCH', offset, `an integer has no member \`${trailing}\`; check the name, or read the member from a record that declares it`);
204
+ }
205
+ return lowerPathToLen(node, walked);
206
+ }
207
+ const path = `${walked}.${rest.slice(index).join('.')}`;
208
+ // A scalar or attachment array has no row, so telling its author to project a member
209
+ // would name a member the element never had; the binder is the whole repair there.
210
+ if (current.items !== undefined) {
211
+ throw new ExpressionCompileError('TYPE_MISMATCH', offset, `\`${path}\` reads a member of \`${walked}\`, whose elements are ${current.items.primitive} values; element access uses a comprehension binder such as \`$it\`, never a member path`);
212
+ }
213
+ const member = segment;
214
+ const declaration = current.fields?.find((field) => field.fieldId === member);
215
+ const projection = memberProjection(walked, member, declaration);
216
+ const repair = projection === undefined
217
+ ? `address the row as \`$it.${member}\` inside an item rule`
218
+ : `write \`${projection}\`, or address the row as \`$it.${member}\` inside an item rule`;
219
+ throw new ExpressionCompileError('TYPE_MISMATCH', offset, `\`${path}\` reads a member of the array \`${walked}\`; a row has no identity until a binder names it, so ${repair}`);
220
+ }
221
+ // A record's declared member and an intrinsic primitive's member are the same read
222
+ // `memberOf` is the fact both this checker and the reader use, so a
223
+ // member a document type-checks is one a value can be read as.
224
+ const member = memberOf(current, segment);
225
+ if (member === undefined) {
226
+ if (current.primitive === 'string' && segment === 'length') {
227
+ const trailing = rest[index + 1];
228
+ if (trailing !== undefined) {
229
+ throw new ExpressionCompileError('TYPE_MISMATCH', offset, `an integer has no member \`${trailing}\`; check the name, or read the member from a record that declares it`);
230
+ }
231
+ return lowerPathToLen(node, walked);
232
+ }
233
+ throw new ExpressionCompileError('UNKNOWN_IDENTIFIER', offset, `${current.fieldId} has no member \`${segment}\``, closestNames(segment, (current.fields ?? intrinsicMembers(current.primitive) ?? []).map((candidate) => candidate.fieldId)));
234
+ }
235
+ current = member;
236
+ walked = `${walked}.${segment}`;
237
+ type = staticTypeOf(member);
238
+ }
239
+ return type;
240
+ }
241
+ /**
242
+ * The fold a member read on an array most likely meant, or `undefined` when no fold reads it.
243
+ *
244
+ * The element type of the comprehension is the member's declared primitive, so the returned
245
+ * source compiles and type-checks as written (`EXPR-18.1.4`): `sum` totals a numeric member,
246
+ * `join` renders text, `count_where` counts a boolean one, and `first` reads any other
247
+ * primitive. A record or list member is `undefined`, because no fold over it produces a value a
248
+ * comparison could use and the refusal names only the binder form instead.
249
+ */
250
+ function memberProjection(arrayPath, member, declaration) {
251
+ const readAny = `first(r in ${arrayPath}: r.${member})`;
252
+ // A member the row does not declare has no fold to suggest: the binder form is the only
253
+ // sentence that does not name a member the array's rows never had.
254
+ if (declaration === undefined)
255
+ return undefined;
256
+ switch (declaration.primitive) {
257
+ case 'integer':
258
+ case 'decimal':
259
+ return `sum(r in ${arrayPath}: r.${member})`;
260
+ case 'boolean':
261
+ return `count_where(r in ${arrayPath}: r.${member}) > 0`;
262
+ case 'record':
263
+ case 'array':
264
+ return undefined;
265
+ default:
266
+ // Every other primitive — text, date, instant, time, money, quantity, duration,
267
+ // media_ref, signature_ref, timeslot — is read by `first`, whose result is `T | null`.
268
+ return readAny;
269
+ }
270
+ }
271
+ /**
272
+ * The type reached from `base` by the trailing path segments. A binder may hold an intrinsic
273
+ * primitive, whose members the registry declares exactly as `declaredPathType` reads them, and
274
+ * a member a record does not declare is refused with the members it does.
275
+ *
276
+ * A `list` is never silently descended to its element: a member of a row is reached through a
277
+ * comprehension binder that names the row (`EXPR-3.1.3`, `EXPR-10.1.2`), so `xs.field` on a
278
+ * list is refused here exactly as the reader refuses it at evaluation. Descending made a
279
+ * list-of-lists look like a list of rows — `is_unique([f_rows], key)` compiled and was
280
+ * permanently `UNKNOWN` (`EXPR-10.2.5`).
281
+ */
282
+ export function descendType(base, rest, offset, lowerTarget) {
283
+ let current = base;
284
+ let walked = lowerTarget?.basePath;
285
+ for (const [index, segment] of rest.entries()) {
286
+ if (lowerTarget !== undefined &&
287
+ walked !== undefined &&
288
+ segment === 'length' &&
289
+ (current.kind === 'list' || (current.kind === 'primitive' && current.primitive === 'string'))) {
290
+ const trailing = rest[index + 1];
291
+ if (trailing !== undefined) {
292
+ throw new ExpressionCompileError('TYPE_MISMATCH', offset, `an integer has no member \`${trailing}\`; check the name, or read the member from a record that declares it`);
293
+ }
294
+ return lowerPathToLen(lowerTarget.node, walked);
295
+ }
296
+ if (current.kind === 'list') {
297
+ throw new ExpressionCompileError('TYPE_MISMATCH', offset, `${withArticle(typeName(current))} has no member \`${segment}\`; an element is reached through a comprehension binder such as \`$it\`, never by a member path`);
298
+ }
299
+ // A binder may hold an intrinsic primitive, whose members the registry declares
300
+ // exactly as `declaredPathType` reads them.
301
+ if (current.kind === 'primitive' && isIntrinsicPrimitive(current.primitive)) {
302
+ current = {
303
+ kind: 'record',
304
+ fields: intrinsicMembers(current.primitive) ?? [],
305
+ open: false,
306
+ };
307
+ }
308
+ if (current.kind !== 'record') {
309
+ throw new ExpressionCompileError('TYPE_MISMATCH', offset, `${withArticle(typeName(current))} has no member \`${segment}\`; check the name, or read the member from a record that declares it`);
310
+ }
311
+ const member = current.fields.find((candidate) => candidate.fieldId === segment);
312
+ if (member === undefined) {
313
+ throw new ExpressionCompileError('UNKNOWN_IDENTIFIER', offset, `${typeName(current)} has no member \`${segment}\``, closestNames(segment, current.fields.map((candidate) => candidate.fieldId)));
314
+ }
315
+ current = staticTypeOf(member);
316
+ if (walked !== undefined)
317
+ walked = `${walked}.${segment}`;
318
+ }
319
+ return current;
320
+ }
321
+ //# sourceMappingURL=paths.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"paths.js","sourceRoot":"","sources":["../../../src/expr/typecheck/paths.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,oBAAoB,EACpB,gBAAgB,EAChB,QAAQ,EACR,aAAa,GACd,MAAM,wBAAwB,CAAC;AAEhC,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,sBAAsB,EAAE,MAAM,mBAAmB,CAAC;AAC3D,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,sBAAsB,EAAE,MAAM,eAAe,CAAC;AAIpF,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,kBAAkB,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAEvF;;;GAGG;AACH,SAAS,cAAc,CAAC,IAAc,EAAE,UAAkB;IACxD,OAAO,CAAC,cAAc,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;IACrC,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE;QAClB,IAAI,EAAE,MAAM;QACZ,EAAE,EAAE,KAAK;QACT,IAAI,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,UAAU,EAAE,CAAC;KAC3C,CAAC,CAAC;IACH,OAAO,aAAa,CAAC,SAAS,CAAC,CAAC;AACl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AAG,YAAY,CAAC,MAAM,CAAC,CAAC;QAC/B,IAAI,MAAM,KAAK,SAAS;YAAE,MAAM,GAAG,GAAG,MAAM,IAAI,OAAO,EAAE,CAAC;IAC5D,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC","sourcesContent":["import {\n isIntrinsicPrimitive,\n intrinsicMembers,\n memberOf,\n valueDomainOf,\n} from '@azx-pbc/axiom-runtime';\nimport type { CompiledField, PathNode } from '@azx-pbc/axiom-runtime';\nimport { withArticle } from '../../article.js';\nimport { ExpressionCompileError } from '../diagnostics.js';\nimport { closestByLeaf, closestNames, spreadsheetSuggestions } from '../suggest.js';\nimport type { LeafCandidate } from '../suggest.js';\nimport type { CheckContext } from './context.js';\nimport type { StaticType } from './types.js';\nimport { primitiveType, staticTypeOf, staticTypeOfDomain, typeName } from './types.js';\n\n/**\n * Rewrites a path ending in `.length` in place to `len(<targetPath>)` once the receiver's type\n * is known to be a string or list, so a record member genuinely named `length` is never shadowed.\n */\nfunction lowerPathToLen(node: PathNode, targetPath: string): StaticType {\n Reflect.deleteProperty(node, 'path');\n Object.assign(node, {\n kind: 'call',\n op: 'len',\n args: [{ kind: 'path', path: targetPath }],\n });\n return primitiveType('integer');\n}\n\n/** The members a bare name could have meant, read through the record that holds them. */\nfunction nestedRecordCandidates(\n fields: readonly CompiledField[],\n prefix = '',\n): readonly LeafCandidate[] {\n const candidates: LeafCandidate[] = [];\n for (const field of fields) {\n const path = prefix === '' ? field.fieldId : `${prefix}.${field.fieldId}`;\n // A root field is offered by its own id; a nested member is only reachable through its\n // container, so the suggestion is the whole path even though the typo is in the leaf.\n if (prefix !== '') candidates.push({ leaf: field.fieldId, suggestion: path });\n // An array's row members are not read through the array path: the row is reached through\n // `$it` inside an item rule, which `itemRowCandidates` offers instead.\n if (field.primitive === 'record') {\n candidates.push(...nestedRecordCandidates(field.fields ?? [], path));\n }\n }\n return candidates;\n}\n\n/** The row members a bare name could have meant inside an item-scoped rule. */\nfunction itemRowCandidates(ctx: CheckContext): readonly LeafCandidate[] {\n const row = ctx.bindings().get('$it');\n if (row?.kind !== 'record') return [];\n return row.fields.map((field) => ({\n leaf: field.fieldId,\n suggestion: `$it.${field.fieldId}`,\n }));\n}\n\n/**\n * The declared names a bare unknown segment could have meant: root ids, members reached\n * through a record, and, inside an item rule, members of the row through `$it`.\n */\nfunction fieldSuggestions(ctx: CheckContext, name: string): readonly string[] {\n return [\n ...new Set([\n ...spreadsheetSuggestions(name),\n ...closestNames(name, [...ctx.fields.keys()]),\n ...closestByLeaf(name, nestedRecordCandidates([...ctx.fields.values()])),\n ...closestByLeaf(name, itemRowCandidates(ctx)),\n ]),\n ].slice(0, 3);\n}\n\n/** The static type a path names, resolving binders, context roots and declared fields. */\nexport function pathType(ctx: CheckContext, node: PathNode): StaticType {\n const path = node.path;\n const offset = ctx.offsetOf(node);\n if (path.startsWith('$')) {\n const segments = path.split('.');\n const sigil = segments[0] ?? path;\n const base = ctx.bindings().get(sigil);\n if (base === undefined) {\n throw new ExpressionCompileError(\n 'UNKNOWN_IDENTIFIER',\n offset,\n `\\`${sigil}\\` is not in scope here; \\`$row\\` names an item rule's row, and \\`$it\\`, \\`$i\\`, \\`$prev\\` and \\`$next\\` are comprehension binders`,\n ['$row', '$it', '$i', '$prev', '$next'],\n );\n }\n return descendType(base, segments.slice(1), offset, { node, basePath: sigil });\n }\n const segments = path.split('.');\n const [first, ...rest] = segments;\n if (first === undefined) {\n throw new ExpressionCompileError('EXPR_PARSE_ERROR', offset, 'a path is empty');\n }\n const bound = ctx.bindings().get(first);\n if (bound !== undefined) return descendType(bound, rest, offset, { node, basePath: first });\n if (first === 'context') {\n // `context` is not a reserved word and makes every declared\n // field a read root, so a record may hold a field with that name. The declared roots own\n // the prefix wherever they claim the path; a path no root declares reads the field.\n const named = ctx.fields.get('context');\n const contextTarget = rest.join('.');\n const contextLengthBase =\n rest.length >= 2 && rest[rest.length - 1] === 'length'\n ? rest.slice(0, -1).join('.')\n : undefined;\n if (\n named === undefined ||\n ctx.contextRoots.has(contextTarget) ||\n (contextLengthBase !== undefined && ctx.contextRoots.has(contextLengthBase))\n ) {\n return contextPathType(ctx, rest, offset, node);\n }\n return declaredPathType(named, rest, offset, node);\n }\n const field = ctx.fields.get(first);\n if (field === undefined) {\n if (ctx.fields.size === 0) {\n throw new ExpressionCompileError(\n 'UNKNOWN_IDENTIFIER',\n offset,\n `\\`${first}\\` is not a context root; a guard compiled without a record may read only context roots and literals`,\n [\n ...new Set([\n ...spreadsheetSuggestions(first),\n ...closestNames(first, [...ctx.contextRoots.keys()]).map((root) => `context.${root}`),\n ]),\n ],\n );\n }\n throw new ExpressionCompileError(\n 'UNKNOWN_IDENTIFIER',\n offset,\n `\\`${first}\\` is not a declared field or context root`,\n fieldSuggestions(ctx, first),\n );\n }\n return declaredPathType(field, rest, offset, node);\n}\n\nfunction contextPathType(\n ctx: CheckContext,\n rest: readonly string[],\n offset: number,\n node: PathNode,\n): StaticType {\n const path = rest.join('.');\n const root = ctx.contextRoots.get(path);\n if (root === undefined) {\n if (rest.length >= 2 && rest[rest.length - 1] === 'length') {\n const prefix = rest.slice(0, -1).join('.');\n const declared = ctx.contextRoots.get(prefix);\n if (\n declared !== undefined &&\n (declared.primitive === 'string' || declared.primitive === 'array')\n ) {\n return lowerPathToLen(node, `context.${prefix}`);\n }\n }\n const arrayRoot = arrayRootOf(ctx, path);\n if (arrayRoot !== undefined) {\n const member = path.slice(arrayRoot.length + 1).split('.')[0] ?? '';\n // A scalar or attachment array has no row, so its refusal names the binder rather than\n // a member the element never had.\n const declared = ctx.contextRoots.get(arrayRoot);\n if (declared?.items !== undefined) {\n throw new ExpressionCompileError(\n 'TYPE_MISMATCH',\n offset,\n `\\`context.${path}\\` reads a member of \\`context.${arrayRoot}\\`, whose elements are ${declared.items.primitive} values; element access uses a comprehension binder such as \\`$it\\`, never a member path`,\n );\n }\n throw new ExpressionCompileError(\n 'TYPE_MISMATCH',\n offset,\n `\\`context.${path}\\` reads a member of the array \\`context.${arrayRoot}\\`; a row has no identity until a binder names it, so address the row as \\`$it.${member}\\` inside an item rule`,\n );\n }\n const recordRoot = recordRootOf(ctx, path);\n if (recordRoot !== undefined) {\n throw new ExpressionCompileError(\n 'UNKNOWN_IDENTIFIER',\n offset,\n `\\`context.${path}\\` reads a member of \\`context.${recordRoot}\\`, a \\`record\\` context root; v1 reads a context root as one value, never its members, so declare \\`context.${path}\\` as its own root (a nested member is declared by its full dotted path) or move the related rows into a dataset table`,\n [`context.${recordRoot}`],\n );\n }\n throw new ExpressionCompileError(\n 'UNKNOWN_IDENTIFIER',\n offset,\n `\\`context.${path}\\` is not a declared context root`,\n closestNames(path, [...ctx.contextRoots.keys()]),\n );\n }\n if (root.primitive === 'array') {\n return {\n kind: 'list',\n element: root.items === undefined ? undefined : staticTypeOfDomain(valueDomainOf(root.items)),\n open: root.items === undefined,\n };\n }\n if (root.primitive === 'record') return { kind: 'record', fields: [], open: true };\n return staticTypeOfDomain(valueDomainOf(root));\n}\n\n/**\n * The longest declared `record` context root `path` descends into, if any.\n *\n * A root is read as one value (`CTX-1.2.1`), and a nested member is declared as its own full\n * dotted path (`CTX-2.1.1`), so a member read below a `record` root names nothing the reader\n * could resolve. The declaration is still useful — `present(context.subject)` is the whole-root\n * question — which is why the refusal is stated at the read rather than at the declaration.\n */\nfunction recordRootOf(ctx: CheckContext, path: string): string | undefined {\n const segments = path.split('.');\n for (let length = segments.length - 1; length > 0; length -= 1) {\n const prefix = segments.slice(0, length).join('.');\n const declared = ctx.contextRoots.get(prefix);\n if (declared === undefined) continue;\n return declared.primitive === 'record' ? prefix : undefined;\n }\n return undefined;\n}\n\n/**\n * The longest declared `array` context root `path` descends into, if any.\n *\n * An array root is read as one list value; a member of a row is reached through a binder, not\n * through the list path (`EXPR-3.1.3`). The evaluator refuses the same descent, so a compiler\n * that resolved it would produce an expression that can only fail.\n */\nfunction arrayRootOf(ctx: CheckContext, path: string): string | undefined {\n const segments = path.split('.');\n for (let length = segments.length - 1; length > 0; length -= 1) {\n const prefix = segments.slice(0, length).join('.');\n const declared = ctx.contextRoots.get(prefix);\n if (declared === undefined) continue;\n return declared.primitive === 'array' ? prefix : undefined;\n }\n return undefined;\n}\n\nfunction declaredPathType(\n field: CompiledField,\n rest: readonly string[],\n offset: number,\n node: PathNode,\n): StaticType {\n let current = field;\n // The path read so far, so a refusal and its repair name the same text the author wrote.\n let walked = field.fieldId;\n let type = staticTypeOf(current);\n for (const [index, segment] of rest.entries()) {\n // An array's row members are reached through a binder, never through the array path:\n // a path that descends into a list is element access, and Expr v1 has no index node and\n // no row identity without a binder (`EXPR-3.1.3`, `EXPR-10.1.2`). The reader refuses the\n // same path at evaluation, so accepting it here would be an expression that compiles and\n // then decides nothing. `.length` on an array is the property sugar for `len(xs)`.\n if (current.primitive === 'array') {\n if (segment === 'length') {\n const trailing = rest[index + 1];\n if (trailing !== undefined) {\n throw new ExpressionCompileError(\n 'TYPE_MISMATCH',\n offset,\n `an integer has no member \\`${trailing}\\`; check the name, or read the member from a record that declares it`,\n );\n }\n return lowerPathToLen(node, walked);\n }\n const path = `${walked}.${rest.slice(index).join('.')}`;\n // A scalar or attachment array has no row, so telling its author to project a member\n // would name a member the element never had; the binder is the whole repair there.\n if (current.items !== undefined) {\n throw new ExpressionCompileError(\n 'TYPE_MISMATCH',\n offset,\n `\\`${path}\\` reads a member of \\`${walked}\\`, whose elements are ${current.items.primitive} values; element access uses a comprehension binder such as \\`$it\\`, never a member path`,\n );\n }\n const member = segment;\n const declaration = current.fields?.find((field) => field.fieldId === member);\n const projection = memberProjection(walked, member, declaration);\n const repair =\n projection === undefined\n ? `address the row as \\`$it.${member}\\` inside an item rule`\n : `write \\`${projection}\\`, or address the row as \\`$it.${member}\\` inside an item rule`;\n throw new ExpressionCompileError(\n 'TYPE_MISMATCH',\n offset,\n `\\`${path}\\` reads a member of the array \\`${walked}\\`; a row has no identity until a binder names it, so ${repair}`,\n );\n }\n // A record's declared member and an intrinsic primitive's member are the same read\n // `memberOf` is the fact both this checker and the reader use, so a\n // member a document type-checks is one a value can be read as.\n const member = memberOf(current, segment);\n if (member === undefined) {\n if (current.primitive === 'string' && segment === 'length') {\n const trailing = rest[index + 1];\n if (trailing !== undefined) {\n throw new ExpressionCompileError(\n 'TYPE_MISMATCH',\n offset,\n `an integer has no member \\`${trailing}\\`; check the name, or read the member from a record that declares it`,\n );\n }\n return lowerPathToLen(node, walked);\n }\n throw new ExpressionCompileError(\n 'UNKNOWN_IDENTIFIER',\n offset,\n `${current.fieldId} has no member \\`${segment}\\``,\n closestNames(\n segment,\n (current.fields ?? intrinsicMembers(current.primitive) ?? []).map(\n (candidate) => candidate.fieldId,\n ),\n ),\n );\n }\n current = member;\n walked = `${walked}.${segment}`;\n type = staticTypeOf(member);\n }\n return type;\n}\n\n/**\n * The fold a member read on an array most likely meant, or `undefined` when no fold reads it.\n *\n * The element type of the comprehension is the member's declared primitive, so the returned\n * source compiles and type-checks as written (`EXPR-18.1.4`): `sum` totals a numeric member,\n * `join` renders text, `count_where` counts a boolean one, and `first` reads any other\n * primitive. A record or list member is `undefined`, because no fold over it produces a value a\n * comparison could use and the refusal names only the binder form instead.\n */\nfunction memberProjection(\n arrayPath: string,\n member: string,\n declaration: CompiledField | undefined,\n): string | undefined {\n const readAny = `first(r in ${arrayPath}: r.${member})`;\n // A member the row does not declare has no fold to suggest: the binder form is the only\n // sentence that does not name a member the array's rows never had.\n if (declaration === undefined) return undefined;\n switch (declaration.primitive) {\n case 'integer':\n case 'decimal':\n return `sum(r in ${arrayPath}: r.${member})`;\n case 'boolean':\n return `count_where(r in ${arrayPath}: r.${member}) > 0`;\n case 'record':\n case 'array':\n return undefined;\n default:\n // Every other primitive — text, date, instant, time, money, quantity, duration,\n // media_ref, signature_ref, timeslot — is read by `first`, whose result is `T | null`.\n return readAny;\n }\n}\n\n/**\n * The type reached from `base` by the trailing path segments. A binder may hold an intrinsic\n * primitive, whose members the registry declares exactly as `declaredPathType` reads them, and\n * a member a record does not declare is refused with the members it does.\n *\n * A `list` is never silently descended to its element: a member of a row is reached through a\n * comprehension binder that names the row (`EXPR-3.1.3`, `EXPR-10.1.2`), so `xs.field` on a\n * list is refused here exactly as the reader refuses it at evaluation. Descending made a\n * list-of-lists look like a list of rows — `is_unique([f_rows], key)` compiled and was\n * permanently `UNKNOWN` (`EXPR-10.2.5`).\n */\nexport function descendType(\n base: StaticType,\n rest: readonly string[],\n offset: number,\n lowerTarget?: { readonly node: PathNode; readonly basePath: string },\n): StaticType {\n let current = base;\n let walked = lowerTarget?.basePath;\n for (const [index, segment] of rest.entries()) {\n if (\n lowerTarget !== undefined &&\n walked !== undefined &&\n segment === 'length' &&\n (current.kind === 'list' || (current.kind === 'primitive' && current.primitive === 'string'))\n ) {\n const trailing = rest[index + 1];\n if (trailing !== undefined) {\n throw new ExpressionCompileError(\n 'TYPE_MISMATCH',\n offset,\n `an integer has no member \\`${trailing}\\`; check the name, or read the member from a record that declares it`,\n );\n }\n return lowerPathToLen(lowerTarget.node, walked);\n }\n if (current.kind === 'list') {\n throw new ExpressionCompileError(\n 'TYPE_MISMATCH',\n offset,\n `${withArticle(typeName(current))} has no member \\`${segment}\\`; an element is reached through a comprehension binder such as \\`$it\\`, never by a member path`,\n );\n }\n // A binder may hold an intrinsic primitive, whose members the registry declares\n // exactly as `declaredPathType` reads them.\n if (current.kind === 'primitive' && isIntrinsicPrimitive(current.primitive)) {\n current = {\n kind: 'record',\n fields: intrinsicMembers(current.primitive) ?? [],\n open: false,\n };\n }\n if (current.kind !== 'record') {\n throw new ExpressionCompileError(\n 'TYPE_MISMATCH',\n offset,\n `${withArticle(typeName(current))} has no member \\`${segment}\\`; check the name, or read the member from a record that declares it`,\n );\n }\n const member = current.fields.find((candidate) => candidate.fieldId === segment);\n if (member === undefined) {\n throw new ExpressionCompileError(\n 'UNKNOWN_IDENTIFIER',\n offset,\n `${typeName(current)} has no member \\`${segment}\\``,\n closestNames(\n segment,\n current.fields.map((candidate) => candidate.fieldId),\n ),\n );\n }\n current = staticTypeOf(member);\n if (walked !== undefined) walked = `${walked}.${segment}`;\n }\n return current;\n}\n"]}
@@ -0,0 +1,24 @@
1
+ import type { CallNode } from '@azx-pbc/axiom-runtime';
2
+ import type { CheckContext } from './context.js';
3
+ import type { Operands } from './operands.js';
4
+ import type { StaticType } from './types.js';
5
+ /** The record built-ins a closed record admits. */
6
+ export type RecordOperator = 'keys' | 'values';
7
+ /**
8
+ * `keys(record)` and `values(record)`: the members a closed record declares.
9
+ *
10
+ * A closed record's members are known, so both operations are total and statically typed. A
11
+ * record-typed context root is open (`CTX-1.2.1`): it declares no members, so `keys` would have
12
+ * to invent them from the record that happens to arrive, and `values` would have no element
13
+ * domain to state. Both are refused, and the refusal names the expression that produced the
14
+ * open type rather than the operator alone.
15
+ *
16
+ * `keys` is `list<string>` in declaration order. `values` uses the language's existing common
17
+ * type for its element: every member must unify with every other, so `integer` and `decimal`
18
+ * become `list<decimal>` (the type `EXPR-6.1.6` already gives a list of both), two money
19
+ * spellings must agree, and a record holding text beside an integer is refused because there is
20
+ * no one domain a caller could aggregate or compare. The rule is stated once here and in the
21
+ * reference page; a later member type cannot quietly become a second rule.
22
+ */
23
+ export declare function recordType(ctx: CheckContext, op: RecordOperator, node: CallNode, operands: Operands): StaticType;
24
+ //# sourceMappingURL=records.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"records.d.ts","sourceRoot":"","sources":["../../../src/expr/typecheck/records.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAY,MAAM,wBAAwB,CAAC;AACjE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AACjD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAC9C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAG7C,mDAAmD;AACnD,MAAM,MAAM,cAAc,GAAG,MAAM,GAAG,QAAQ,CAAC;AAS/C;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,UAAU,CACxB,GAAG,EAAE,YAAY,EACjB,EAAE,EAAE,cAAc,EAClB,IAAI,EAAE,QAAQ,EACd,QAAQ,EAAE,QAAQ,GACjB,UAAU,CAsCZ"}
@@ -0,0 +1,53 @@
1
+ import { primitiveType, staticTypeOf, typeName, unify } from './types.js';
2
+ /** The expression a refusal names, in the shape the author wrote. */
3
+ function describeExpression(node) {
4
+ if (node.kind === 'path')
5
+ return `\`${node.path}\``;
6
+ if (node.kind === 'call')
7
+ return `\`${node.op}(…)\``;
8
+ return `a \`${node.kind}\` expression`;
9
+ }
10
+ /**
11
+ * `keys(record)` and `values(record)`: the members a closed record declares.
12
+ *
13
+ * A closed record's members are known, so both operations are total and statically typed. A
14
+ * record-typed context root is open (`CTX-1.2.1`): it declares no members, so `keys` would have
15
+ * to invent them from the record that happens to arrive, and `values` would have no element
16
+ * domain to state. Both are refused, and the refusal names the expression that produced the
17
+ * open type rather than the operator alone.
18
+ *
19
+ * `keys` is `list<string>` in declaration order. `values` uses the language's existing common
20
+ * type for its element: every member must unify with every other, so `integer` and `decimal`
21
+ * become `list<decimal>` (the type `EXPR-6.1.6` already gives a list of both), two money
22
+ * spellings must agree, and a record holding text beside an integer is refused because there is
23
+ * no one domain a caller could aggregate or compare. The rule is stated once here and in the
24
+ * reference page; a later member type cannot quietly become a second rule.
25
+ */
26
+ export function recordType(ctx, op, node, operands) {
27
+ const base = operands.nodeAt(0);
28
+ const type = ctx.check(base);
29
+ if (type.kind !== 'record') {
30
+ throw ctx.mismatch(base, `\`${op}\` requires a record, got ${typeName(type)}; a record is a declared \`record\` field, a row, or a lookup result`);
31
+ }
32
+ if (type.open) {
33
+ throw ctx.mismatch(base, `\`${op}\` requires a record whose members are declared, and ${describeExpression(base)} is an open record (a record-typed context root declares no members); read a declared \`record\` field, an array row, or a lookup result`);
34
+ }
35
+ if (op === 'keys') {
36
+ return { kind: 'list', element: primitiveType('string'), open: false };
37
+ }
38
+ const [first, ...rest] = type.fields;
39
+ if (first === undefined) {
40
+ throw ctx.mismatch(base, `\`values\` requires a record with at least one declared member, and ${describeExpression(base)} declares none`);
41
+ }
42
+ let agreed = staticTypeOf(first);
43
+ for (const field of rest) {
44
+ const member = staticTypeOf(field);
45
+ const unified = unify(agreed, member);
46
+ if (unified === undefined) {
47
+ throw ctx.mismatch(base, `\`values\` requires every member of ${describeExpression(base)} to share one type, but \`${first.fieldId}\` is ${typeName(agreed)} and \`${field.fieldId}\` is ${typeName(member)}; read the members by name instead`);
48
+ }
49
+ agreed = unified;
50
+ }
51
+ return { kind: 'list', element: agreed, open: false };
52
+ }
53
+ //# sourceMappingURL=records.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"records.js","sourceRoot":"","sources":["../../../src/expr/typecheck/records.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAK1E,qEAAqE;AACrE,SAAS,kBAAkB,CAAC,IAAc;IACxC,IAAI,IAAI,CAAC,IAAI,KAAK,MAAM;QAAE,OAAO,KAAK,IAAI,CAAC,IAAI,IAAI,CAAC;IACpD,IAAI,IAAI,CAAC,IAAI,KAAK,MAAM;QAAE,OAAO,KAAK,IAAI,CAAC,EAAE,OAAO,CAAC;IACrD,OAAO,OAAO,IAAI,CAAC,IAAI,eAAe,CAAC;AACzC,CAAC;AAED;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,UAAU,CACxB,GAAiB,EACjB,EAAkB,EAClB,IAAc,EACd,QAAkB;IAElB,MAAM,IAAI,GAAG,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;IAChC,MAAM,IAAI,GAAG,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAC7B,IAAI,IAAI,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;QAC3B,MAAM,GAAG,CAAC,QAAQ,CAChB,IAAI,EACJ,KAAK,EAAE,6BAA6B,Q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AI,EAAE,KAAK,EAAE,CAAC;AACxD,CAAC","sourcesContent":["import type { CallNode, ExprNode } from '@azx-pbc/axiom-runtime';\nimport type { CheckContext } from './context.js';\nimport type { Operands } from './operands.js';\nimport type { StaticType } from './types.js';\nimport { primitiveType, staticTypeOf, typeName, unify } from './types.js';\n\n/** The record built-ins a closed record admits. */\nexport type RecordOperator = 'keys' | 'values';\n\n/** The expression a refusal names, in the shape the author wrote. */\nfunction describeExpression(node: ExprNode): string {\n if (node.kind === 'path') return `\\`${node.path}\\``;\n if (node.kind === 'call') return `\\`${node.op}(…)\\``;\n return `a \\`${node.kind}\\` expression`;\n}\n\n/**\n * `keys(record)` and `values(record)`: the members a closed record declares.\n *\n * A closed record's members are known, so both operations are total and statically typed. A\n * record-typed context root is open (`CTX-1.2.1`): it declares no members, so `keys` would have\n * to invent them from the record that happens to arrive, and `values` would have no element\n * domain to state. Both are refused, and the refusal names the expression that produced the\n * open type rather than the operator alone.\n *\n * `keys` is `list<string>` in declaration order. `values` uses the language's existing common\n * type for its element: every member must unify with every other, so `integer` and `decimal`\n * become `list<decimal>` (the type `EXPR-6.1.6` already gives a list of both), two money\n * spellings must agree, and a record holding text beside an integer is refused because there is\n * no one domain a caller could aggregate or compare. The rule is stated once here and in the\n * reference page; a later member type cannot quietly become a second rule.\n */\nexport function recordType(\n ctx: CheckContext,\n op: RecordOperator,\n node: CallNode,\n operands: Operands,\n): StaticType {\n const base = operands.nodeAt(0);\n const type = ctx.check(base);\n if (type.kind !== 'record') {\n throw ctx.mismatch(\n base,\n `\\`${op}\\` requires a record, got ${typeName(type)}; a record is a declared \\`record\\` field, a row, or a lookup result`,\n );\n }\n if (type.open) {\n throw ctx.mismatch(\n base,\n `\\`${op}\\` requires a record whose members are declared, and ${describeExpression(base)} is an open record (a record-typed context root declares no members); read a declared \\`record\\` field, an array row, or a lookup result`,\n );\n }\n if (op === 'keys') {\n return { kind: 'list', element: primitiveType('string'), open: false };\n }\n const [first, ...rest] = type.fields;\n if (first === undefined) {\n throw ctx.mismatch(\n base,\n `\\`values\\` requires a record with at least one declared member, and ${describeExpression(base)} declares none`,\n );\n }\n let agreed = staticTypeOf(first);\n for (const field of rest) {\n const member = staticTypeOf(field);\n const unified = unify(agreed, member);\n if (unified === undefined) {\n throw ctx.mismatch(\n base,\n `\\`values\\` requires every member of ${describeExpression(base)} to share one type, but \\`${first.fieldId}\\` is ${typeName(agreed)} and \\`${field.fieldId}\\` is ${typeName(member)}; read the members by name instead`,\n );\n }\n agreed = unified;\n }\n return { kind: 'list', element: agreed, open: false };\n}\n"]}
@@ -0,0 +1,15 @@
1
+ import type { CallNode } from '@azx-pbc/axiom-runtime';
2
+ import type { CheckContext } from './context.js';
3
+ import type { Operands } from './operands.js';
4
+ import type { StaticType } from './types.js';
5
+ /** The list operators that copy, order or deduplicate a list. */
6
+ export type SequenceOperator = 'sort' | 'slice' | 'distinct' | 'reverse';
7
+ /**
8
+ * `sort`, `slice`, `distinct` and `reverse`, `EXPR-10.2.14` to `EXPR-10.2.17`.
9
+ *
10
+ * Each returns the operand's own `list<T>`: an element keeps the domain its declaration pins,
11
+ * so a later comparison, aggregate or membership reads the same type the author declared. The
12
+ * element domain a fold needs is therefore never widened or dropped by a copy.
13
+ */
14
+ export declare function sequenceType(ctx: CheckContext, op: SequenceOperator, node: CallNode, operands: Operands): StaticType;
15
+ //# sourceMappingURL=sequences.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sequences.d.ts","sourceRoot":"","sources":["../../../src/expr/typecheck/sequences.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAEvD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AACjD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAC9C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAG7C,iEAAiE;AACjE,MAAM,MAAM,gBAAgB,GAAG,MAAM,GAAG,OAAO,GAAG,UAAU,GAAG,SAAS,CAAC;AAEzE;;;;;;GAMG;AACH,wBAAgB,YAAY,CAC1B,GAAG,EAAE,YAAY,EACjB,EAAE,EAAE,gBAAgB,EACpB,IAAI,EAAE,QAAQ,EACd,QAAQ,EAAE,QAAQ,GACjB,UAAU,CAwDZ"}
@@ -0,0 +1,55 @@
1
+ import { withArticle } from '../../article.js';
2
+ import { ORDERABLE, isPrimitive, typeName } from './types.js';
3
+ /**
4
+ * `sort`, `slice`, `distinct` and `reverse`, `EXPR-10.2.14` to `EXPR-10.2.17`.
5
+ *
6
+ * Each returns the operand's own `list<T>`: an element keeps the domain its declaration pins,
7
+ * so a later comparison, aggregate or membership reads the same type the author declared. The
8
+ * element domain a fold needs is therefore never widened or dropped by a copy.
9
+ */
10
+ export function sequenceType(ctx, op, node, operands) {
11
+ switch (op) {
12
+ case 'sort': {
13
+ const list = operands.requireList(0);
14
+ const element = list.element;
15
+ if (element === undefined) {
16
+ // An open list states no element type, so the order to sort by is not stated either.
17
+ throw ctx.mismatch(operands.nodeAt(0), `\`sort\` requires a list with a declared element type, got ${typeName(list)}`);
18
+ }
19
+ if (element.kind !== 'primitive' || !ORDERABLE.has(element.primitive)) {
20
+ throw ctx.mismatch(operands.nodeAt(0), `\`sort\` requires orderable elements — integers, decimals, text, dates, instants, times, money or quantities — got ${typeName(element)}`);
21
+ }
22
+ return list;
23
+ }
24
+ case 'distinct': {
25
+ const list = operands.requireList(0);
26
+ const element = list.element;
27
+ if (element === undefined) {
28
+ throw ctx.mismatch(operands.nodeAt(0), `\`distinct\` compares the elements themselves, and ${typeName(list)} declares no element type`);
29
+ }
30
+ if (element.kind !== 'primitive') {
31
+ throw ctx.mismatch(operands.nodeAt(0), `\`distinct\` compares the elements themselves, and ${withArticle(typeName(element))} has no domain to compare in; project a primitive value, such as \`distinct(map(r in xs: r.code))\``);
32
+ }
33
+ return list;
34
+ }
35
+ case 'reverse':
36
+ return operands.requireList(0);
37
+ case 'slice': {
38
+ const list = operands.requireList(0);
39
+ operands.requireType(1, (type) => isPrimitive(type, 'integer'), 'an integer start');
40
+ operands.requireType(2, (type) => isPrimitive(type, 'integer'), 'an integer count');
41
+ // A negative window has no reading the clamp rule covers, exactly as `substring` states
42
+ // it: the repair is to start at zero and take the absolute count.
43
+ const start = operands.nodeAt(1);
44
+ if (start.kind === 'literal' && typeof start.value === 'number' && start.value < 0) {
45
+ throw ctx.mismatch(start, '`slice` requires a non-negative start');
46
+ }
47
+ const count = operands.nodeAt(2);
48
+ if (count.kind === 'literal' && typeof count.value === 'number' && count.value < 0) {
49
+ throw ctx.mismatch(count, '`slice` requires a non-negative count');
50
+ }
51
+ return list;
52
+ }
53
+ }
54
+ }
55
+ //# sourceMappingURL=sequences.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sequences.js","sourceRoot":"","sources":["../../../src/expr/typecheck/sequences.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAI/C,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAK9D;;;;;;GAMG;AACH,MAAM,UAAU,YAAY,CAC1B,GAAiB,EACjB,EAAoB,EACpB,IAAc,EACd,QAAkB;IAElB,QAAQ,EAAE,EAAE,CAAC;QACX,KAAK,MAAM,EAAE,CAAC;YACZ,MAAM,IAAI,GAAG,QAAQ,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;YACrC,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC;YAC7B,IAAI,OAAO,KAAK,SAAS,EAAE,CAAC;gBAC1B,qFAAqF;gBACrF,MAAM,GAAG,CAAC,QAAQ,CAChB,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,EAClB,8DAA8D,QAAQ,CAAC,IAAI,CAAC,EAAE,CAC/E,CAAC;YACJ,CAAC;YACD,IAAI,OAAO,CAAC,IAAI,KAAK,WAAW,IAAI,CAAC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E,SAAS,CAAC,EAAE,kBAAkB,CAAC,CAAC;YACpF,wFAAwF;YACxF,kEAAkE;YAClE,MAAM,KAAK,GAAG,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;YACjC,IAAI,KAAK,CAAC,IAAI,KAAK,SAAS,IAAI,OAAO,KAAK,CAAC,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,KAAK,GAAG,CAAC,EAAE,CAAC;gBACnF,MAAM,GAAG,CAAC,QAAQ,CAAC,KAAK,EAAE,uCAAuC,CAAC,CAAC;YACrE,CAAC;YACD,MAAM,KAAK,GAAG,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;YACjC,IAAI,KAAK,CAAC,IAAI,KAAK,SAAS,IAAI,OAAO,KAAK,CAAC,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,KAAK,GAAG,CAAC,EAAE,CAAC;gBACnF,MAAM,GAAG,CAAC,QAAQ,CAAC,KAAK,EAAE,uCAAuC,CAAC,CAAC;YACrE,CAAC;YACD,OAAO,IAAI,CAAC;QACd,CAAC;IACH,CAAC;AACH,CAAC","sourcesContent":["import type { CallNode } from '@azx-pbc/axiom-runtime';\nimport { withArticle } from '../../article.js';\nimport type { CheckContext } from './context.js';\nimport type { Operands } from './operands.js';\nimport type { StaticType } from './types.js';\nimport { ORDERABLE, isPrimitive, typeName } from './types.js';\n\n/** The list operators that copy, order or deduplicate a list. */\nexport type SequenceOperator = 'sort' | 'slice' | 'distinct' | 'reverse';\n\n/**\n * `sort`, `slice`, `distinct` and `reverse`, `EXPR-10.2.14` to `EXPR-10.2.17`.\n *\n * Each returns the operand's own `list<T>`: an element keeps the domain its declaration pins,\n * so a later comparison, aggregate or membership reads the same type the author declared. The\n * element domain a fold needs is therefore never widened or dropped by a copy.\n */\nexport function sequenceType(\n ctx: CheckContext,\n op: SequenceOperator,\n node: CallNode,\n operands: Operands,\n): StaticType {\n switch (op) {\n case 'sort': {\n const list = operands.requireList(0);\n const element = list.element;\n if (element === undefined) {\n // An open list states no element type, so the order to sort by is not stated either.\n throw ctx.mismatch(\n operands.nodeAt(0),\n `\\`sort\\` requires a list with a declared element type, got ${typeName(list)}`,\n );\n }\n if (element.kind !== 'primitive' || !ORDERABLE.has(element.primitive)) {\n throw ctx.mismatch(\n operands.nodeAt(0),\n `\\`sort\\` requires orderable elements — integers, decimals, text, dates, instants, times, money or quantities — got ${typeName(element)}`,\n );\n }\n return list;\n }\n case 'distinct': {\n const list = operands.requireList(0);\n const element = list.element;\n if (element === undefined) {\n throw ctx.mismatch(\n operands.nodeAt(0),\n `\\`distinct\\` compares the elements themselves, and ${typeName(list)} declares no element type`,\n );\n }\n if (element.kind !== 'primitive') {\n throw ctx.mismatch(\n operands.nodeAt(0),\n `\\`distinct\\` compares the elements themselves, and ${withArticle(typeName(element))} has no domain to compare in; project a primitive value, such as \\`distinct(map(r in xs: r.code))\\``,\n );\n }\n return list;\n }\n case 'reverse':\n return operands.requireList(0);\n case 'slice': {\n const list = operands.requireList(0);\n operands.requireType(1, (type) => isPrimitive(type, 'integer'), 'an integer start');\n operands.requireType(2, (type) => isPrimitive(type, 'integer'), 'an integer count');\n // A negative window has no reading the clamp rule covers, exactly as `substring` states\n // it: the repair is to start at zero and take the absolute count.\n const start = operands.nodeAt(1);\n if (start.kind === 'literal' && typeof start.value === 'number' && start.value < 0) {\n throw ctx.mismatch(start, '`slice` requires a non-negative start');\n }\n const count = operands.nodeAt(2);\n if (count.kind === 'literal' && typeof count.value === 'number' && count.value < 0) {\n throw ctx.mismatch(count, '`slice` requires a non-negative count');\n }\n return list;\n }\n }\n}\n"]}
@@ -0,0 +1,8 @@
1
+ import type { CallNode } from '@azx-pbc/axiom-runtime';
2
+ import type { CheckContext } from './context.js';
3
+ import type { Operands } from './operands.js';
4
+ import type { StaticType } from './types.js';
5
+ /** The string, text-rendering and pattern built-ins. */
6
+ export type StringOperator = 'len' | 'lower' | 'upper' | 'trim' | 'is_email' | 'is_phone' | 'is_url' | 'empty' | 'to_string' | 'parse_integer' | 'parse_decimal' | 'starts_with' | 'ends_with' | 'contains' | 'ascii_match' | 'replace' | 'split' | 'join' | 'substring' | 'index_of' | 'matches' | 'concat';
7
+ export declare function stringType(ctx: CheckContext, op: StringOperator, node: CallNode, operands: Operands): StaticType;
8
+ //# sourceMappingURL=strings.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"strings.d.ts","sourceRoot":"","sources":["../../../src/expr/typecheck/strings.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,QAAQ,EAAY,MAAM,wBAAwB,CAAC;AAEjE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AACjD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAC9C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAG7C,wDAAwD;AACxD,MAAM,MAAM,cAAc,GACtB,KAAK,GACL,OAAO,GACP,OAAO,GACP,MAAM,GACN,UAAU,GACV,UAAU,GACV,QAAQ,GACR,OAAO,GACP,WAAW,GACX,eAAe,GACf,eAAe,GACf,aAAa,GACb,WAAW,GACX,UAAU,GACV,aAAa,GACb,SAAS,GACT,OAAO,GACP,MAAM,GACN,WAAW,GACX,UAAU,GACV,SAAS,GACT,QAAQ,CAAC;AAab,wBAAgB,UAAU,CACxB,GAAG,EAAE,YAAY,EACjB,EAAE,EAAE,cAAc,EAClB,IAAI,EAAE,QAAQ,EACd,QAAQ,EAAE,QAAQ,GACjB,UAAU,CAiMZ"}