@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,1047 @@
1
+ import Papa from 'papaparse';
2
+ import { AxiomError, DEFAULT_EVIDENCE_TIER, IDENTIFIER_PATTERN, JsonIngestError, assertNever, compareCodePoints, isTier, isWireValue, parsePlainDate, parseRestrictedJson, sameWireValue, } from '@azx-pbc/axiom-runtime';
3
+ import { parseCanonicalScalarCell } from '../csv/scalar.js';
4
+ import { nonTextSourceDetail } from '../ingest/document.js';
5
+ import { MAX_CELL_BYTES, MAX_COLUMNS, MAX_DATA_ROWS, MAX_INPUT_BYTES, exceedsUtf8Bytes, utf8Crossing, } from '../csv/limits.js';
6
+ import { validateReferences } from './references.js';
7
+ import { isOutcome, isVectorScreenOutcome } from './vocabulary.js';
8
+ /**
9
+ * A flat scenario matrix, read as the closed suite the runner already executes.
10
+ *
11
+ * A business analyst authors cases in a spreadsheet, one row per scenario and one column per
12
+ * fact. This module translates between that grid and `ScenarioSuiteDocument`: it owns the
13
+ * locked header families, the cell grammar, the RFC 4180 export and the application of the
14
+ * bounds declared in `csv/limits.ts`. It holds no runner, classifier or coverage rule — the
15
+ * parsed suite goes to the same `runScenarioSuite` a JSON suite does — and it parses no
16
+ * expression: the AST authority stays the compiler's `parseExpr`.
17
+ *
18
+ * The dialect is deliberately narrow and never coercive. An empty value cell is *absent*; the
19
+ * exact text `null` is the wire null; a text value is a JSON string literal, so `""`, `"null"`
20
+ * and `"001"` are three different strings; a number, date or instant is its canonical
21
+ * spelling and nothing else. A shape the grid cannot carry — a nested record, an array, money,
22
+ * an attachment, a redaction, a capability, a row-key assertion — is refused with the JSON
23
+ * suite named as the alternative rather than approximated.
24
+ */
25
+ /** The tag a tagged expectation cell starts with. */
26
+ const OUTCOME_TAG = 'outcome:';
27
+ const SCREEN_TAG = 'screen:';
28
+ const VALUE_TAG = 'value:';
29
+ /** The characters a spreadsheet reads as the start of a formula or a line. */
30
+ const FORMULA_LEADS = new Set(['=', '+', '-', '@', '\t', '\r']);
31
+ function diagnostic(path, detail, code = 'SCENARIOS_INVALID') {
32
+ return { code, path, detail };
33
+ }
34
+ function boundsExceeded(path, detail) {
35
+ return diagnostic(path, detail, 'CSV_BOUNDS');
36
+ }
37
+ function indexOf(schema) {
38
+ return {
39
+ fields: new Map(schema.fields.map((field) => [field.fieldId, field])),
40
+ roots: new Map((schema.context?.roots ?? []).map((root) => [root.path.replace(/^context\./, ''), root])),
41
+ rules: new Map((schema.rules ?? []).map((rule) => [rule.ruleId, rule])),
42
+ };
43
+ }
44
+ function admitPrimitive(primitive) {
45
+ switch (primitive) {
46
+ case 'string':
47
+ case 'boolean':
48
+ case 'integer':
49
+ case 'decimal':
50
+ case 'date':
51
+ case 'instant':
52
+ return { kind: 'scalar', primitive };
53
+ case 'money':
54
+ return {
55
+ kind: 'refused',
56
+ detail: 'a money value carries minor units, a currency and a scale, which one cell cannot state; write a JSON suite',
57
+ };
58
+ case 'media_ref':
59
+ case 'signature_ref':
60
+ return {
61
+ kind: 'refused',
62
+ detail: `a \`${primitive}\` value is an object, not a flat cell; write a JSON suite`,
63
+ };
64
+ case 'timeslot':
65
+ return {
66
+ kind: 'refused',
67
+ detail: 'a `timeslot` value names an option, not a flat cell; write a JSON suite',
68
+ };
69
+ case 'time':
70
+ return {
71
+ kind: 'refused',
72
+ detail: 'a `time` value is a clock reading, not a flat cell; write a JSON suite',
73
+ };
74
+ case 'record':
75
+ return {
76
+ kind: 'refused',
77
+ detail: 'a nested record has no flat column; write a JSON suite',
78
+ };
79
+ case 'array':
80
+ return {
81
+ kind: 'refused',
82
+ detail: 'an array value is not a scalar cell; write a JSON suite',
83
+ };
84
+ case 'quantity':
85
+ return {
86
+ kind: 'refused',
87
+ detail: 'a quantity names a unit, not a flat cell; write a JSON suite',
88
+ };
89
+ case 'duration':
90
+ return {
91
+ kind: 'refused',
92
+ detail: 'a duration names a unit, not a flat cell; write a JSON suite',
93
+ };
94
+ case 'address':
95
+ case 'coordinate':
96
+ return {
97
+ kind: 'refused',
98
+ detail: `a \`${primitive}\` value is an object, not a flat cell; write a JSON suite`,
99
+ };
100
+ default:
101
+ return assertNever(primitive);
102
+ }
103
+ }
104
+ /**
105
+ * The header families a matrix may not state, with the JSON alternative.
106
+ *
107
+ * Each names a shape the closed suite contract carries and a grid cannot, so the refusal
108
+ * points at the format that can instead of accepting a lossy approximation.
109
+ */
110
+ const UNSUPPORTED_HEADERS = [
111
+ {
112
+ family: 'redacted',
113
+ detail: 'a redaction is not a matrix column; write a JSON suite',
114
+ },
115
+ {
116
+ family: 'sessionWrites',
117
+ detail: 'a session write is not a matrix column; write a JSON suite',
118
+ },
119
+ {
120
+ family: 'accessOverlay',
121
+ detail: 'an access overlay is not a matrix column; write a JSON suite',
122
+ },
123
+ {
124
+ family: 'capabilities',
125
+ detail: 'a capability list is not a matrix column; write a JSON suite',
126
+ },
127
+ {
128
+ family: 'datasets',
129
+ detail: 'a table exposure is not a matrix column; write a JSON suite',
130
+ },
131
+ {
132
+ family: 'expect.rows',
133
+ detail: 'a row-key assertion is not a matrix column; write a JSON suite',
134
+ },
135
+ ];
136
+ /** The families a matrix states, named in the refusal for a column outside them. */
137
+ const ACCEPTED_HEADERS = '`caseId`, `tier`, `recordDate`, `value.<fieldId>`, `context.<rootPath>`, `expect.rule.<ruleId>`, `expect.gate.<ruleId>.<itemId>`, `expect.computed.<fieldId>` or `expect.hidden.<fieldId>`';
138
+ /**
139
+ * One cell read as the value its primitive declares.
140
+ *
141
+ * Shared by both directions: the exporter re-reads each cell it writes with this function, so
142
+ * an export whose text would not parse back is refused rather than shipped lossy.
143
+ */
144
+ function readScalarCell(text, primitive) {
145
+ if (text === 'null')
146
+ return { ok: true, value: null };
147
+ if (primitive === 'string') {
148
+ // A text cell is a JSON string literal, so `""`, `"null"` and `"001"` keep their identity
149
+ // instead of collapsing into absent, null and an integer. The cell text itself is never
150
+ // trimmed or rewritten.
151
+ let decoded;
152
+ try {
153
+ decoded = parseRestrictedJson(text);
154
+ }
155
+ catch (cause) {
156
+ if (!(cause instanceof JsonIngestError))
157
+ throw cause;
158
+ return {
159
+ ok: false,
160
+ detail: `string cells are JSON string literals, for example \`"Ada"\`: ${cause.message}`,
161
+ };
162
+ }
163
+ return typeof decoded === 'string'
164
+ ? { ok: true, value: decoded }
165
+ : {
166
+ ok: false,
167
+ detail: `string cells are JSON string literals, for example \`"Ada"\`; \`${text}\` is not one`,
168
+ };
169
+ }
170
+ return parseCanonicalScalarCell(strippedExportPrefix(text), primitive);
171
+ }
172
+ /** The characters an export prefixes a `'` to, so a spreadsheet reads the cell as text. */
173
+ function isFormulaLead(character) {
174
+ return FORMULA_LEADS.has(character);
175
+ }
176
+ /** A cell's text with the one prefix an export added, or the text unchanged. */
177
+ function strippedExportPrefix(text) {
178
+ // A raw cell an export neutralised starts `'` and then a formula lead. A JSON string cell
179
+ // starts with `"`, so a value whose content is `'=1` keeps its own characters: the prefix is
180
+ // only ever removed from the raw numeric cells the exporter writes it for.
181
+ return text.startsWith("'") && isFormulaLead(text.charAt(1)) ? text.slice(1) : text;
182
+ }
183
+ /** A cell's text as an export writes it: neutralised before RFC 4180 quoting. */
184
+ function neutralised(cell) {
185
+ return isFormulaLead(cell.charAt(0)) ? `'${cell}` : cell;
186
+ }
187
+ /** The resolved column for one header cell, or the reason it is not one. */
188
+ function resolveColumn(header, cell, index) {
189
+ if (header === 'caseId')
190
+ return { header, cell, kind: 'caseId' };
191
+ if (header === 'tier')
192
+ return { header, cell, kind: 'tier' };
193
+ if (header === 'recordDate')
194
+ return { header, cell, kind: 'recordDate' };
195
+ if (header.startsWith('value.')) {
196
+ const name = header.slice('value.'.length);
197
+ const field = index.fields.get(name);
198
+ if (field === undefined) {
199
+ return diagnostic(`$.header[${String(cell)}]`, name.includes('.')
200
+ ? `\`${header}\` names a nested member; a matrix states top-level fields only, so write a JSON suite`
201
+ : `the artifact declares no field \`${name}\`; a \`value.\` column names a declared top-level field`);
202
+ }
203
+ const admission = admitPrimitive(field.primitive);
204
+ if (admission.kind === 'refused') {
205
+ return diagnostic(`$.header[${String(cell)}]`, `\`${name}\`: ${admission.detail}`);
206
+ }
207
+ return { header, cell, kind: 'value', field, primitive: admission.primitive };
208
+ }
209
+ if (header.startsWith('context.')) {
210
+ const rootPath = header.slice('context.'.length);
211
+ const root = index.roots.get(rootPath);
212
+ if (root === undefined) {
213
+ return diagnostic(`$.header[${String(cell)}]`, rootPath === 'record_date'
214
+ ? '`context.record_date` is the `recordDate` column of the environment, not a record context root'
215
+ : rootPath === 'schema_version'
216
+ ? '`context.schema_version` is the artifact’s own version and cannot be stated per scenario'
217
+ : `the artifact declares no context root \`${rootPath}\``);
218
+ }
219
+ const admission = admitPrimitive(root.primitive);
220
+ if (admission.kind === 'refused') {
221
+ return diagnostic(`$.header[${String(cell)}]`, `context root \`${rootPath}\`: ${admission.detail}`);
222
+ }
223
+ return { header, cell, kind: 'context', rootPath, primitive: admission.primitive };
224
+ }
225
+ if (header.startsWith('expect.rule.')) {
226
+ const ruleId = header.slice('expect.rule.'.length);
227
+ const rule = index.rules.get(ruleId);
228
+ if (rule === undefined) {
229
+ return diagnostic(`$.header[${String(cell)}]`, `the artifact declares no rule \`${ruleId}\`; an \`expect.rule.\` column names a declared rule`);
230
+ }
231
+ return { header, cell, kind: 'rule', rule };
232
+ }
233
+ if (header.startsWith('expect.gate.')) {
234
+ const parts = header.slice('expect.gate.'.length).split('.');
235
+ const ruleId = parts[0];
236
+ const itemId = parts[1];
237
+ if (parts.length !== 2 || ruleId === undefined || itemId === undefined || itemId === '') {
238
+ return diagnostic(`$.header[${String(cell)}]`, `\`${header}\` is not a gate item column; name the gate rule and its item as \`expect.gate.<ruleId>.<itemId>\``);
239
+ }
240
+ return { header, cell, kind: 'gateItem', ruleId, itemId };
241
+ }
242
+ if (header.startsWith('expect.computed.')) {
243
+ const fieldId = header.slice('expect.computed.'.length);
244
+ const field = index.fields.get(fieldId);
245
+ if (field === undefined) {
246
+ return diagnostic(`$.header[${String(cell)}]`, `the artifact declares no field \`${fieldId}\`; an \`expect.computed.\` column names a declared field`);
247
+ }
248
+ const admission = admitPrimitive(field.primitive);
249
+ if (admission.kind === 'refused') {
250
+ return diagnostic(`$.header[${String(cell)}]`, `\`${fieldId}\`: ${admission.detail}`);
251
+ }
252
+ return { header, cell, kind: 'computed', fieldId, primitive: admission.primitive };
253
+ }
254
+ if (header.startsWith('expect.hidden.')) {
255
+ return { header, cell, kind: 'hidden', fieldId: header.slice('expect.hidden.'.length) };
256
+ }
257
+ for (const unsupported of UNSUPPORTED_HEADERS) {
258
+ if (header === unsupported.family || header.startsWith(`${unsupported.family}.`)) {
259
+ return diagnostic(`$.header[${String(cell)}]`, unsupported.detail);
260
+ }
261
+ }
262
+ return diagnostic(`$.header[${String(cell)}]`, `unknown column \`${header}\`; a matrix states ${ACCEPTED_HEADERS}`);
263
+ }
264
+ /**
265
+ * The record field a writer rule writes, or `undefined` when the rule states no record value.
266
+ *
267
+ * Both directions need this: a `value:` cell is typed by the field the writer produces, and the
268
+ * exporter refuses a suite whose value assertion has no column. A row-scope writer is not one:
269
+ * its value lives on one row of an array, and a matrix states no array at all, so there is no
270
+ * cell a row value could occupy.
271
+ */
272
+ function writerFieldOf(rule, index) {
273
+ if (rule.kind !== 'compute' && rule.kind !== 'defaultCompute')
274
+ return undefined;
275
+ if (rule.scope === 'item')
276
+ return undefined;
277
+ return rule.fieldId === undefined ? undefined : index.fields.get(rule.fieldId);
278
+ }
279
+ /** The sentence saying why a rule's value has no cell, or `undefined` when it has one. */
280
+ function writerValueRefusal(rule) {
281
+ if (rule.kind !== 'compute' && rule.kind !== 'defaultCompute') {
282
+ return `a \`${rule.kind}\` rule states an outcome, not a value`;
283
+ }
284
+ if (rule.scope === 'item') {
285
+ return 'an item rule writes one value per row, and a matrix states no rows; write a JSON suite';
286
+ }
287
+ return undefined;
288
+ }
289
+ function splitTag(text) {
290
+ const colon = text.indexOf(':');
291
+ if (colon <= 0) {
292
+ return {
293
+ reason: `expectation cells are tagged: \`${OUTCOME_TAG}…\`, \`${SCREEN_TAG}…\` or \`${VALUE_TAG}…\``,
294
+ };
295
+ }
296
+ return { tag: text.slice(0, colon), body: text.slice(colon + 1) };
297
+ }
298
+ /** The assertion one `expect.rule.` cell states, or the reason it states none. */
299
+ function readRuleAssertion(text, rule, index) {
300
+ const tagged = splitTag(text);
301
+ if ('reason' in tagged)
302
+ return tagged.reason;
303
+ switch (tagged.tag) {
304
+ case 'outcome': {
305
+ const outcome = tagged.body;
306
+ if (!isOutcome(outcome)) {
307
+ return `\`${OUTCOME_TAG}\` states one of PASS, FAIL, UNKNOWN or DEFERRED`;
308
+ }
309
+ return { kind: 'rule', ruleId: rule.ruleId, observation: { kind: 'outcome', outcome } };
310
+ }
311
+ case 'screen': {
312
+ const outcome = tagged.body;
313
+ if (!isVectorScreenOutcome(outcome)) {
314
+ return `\`${SCREEN_TAG}\` states one of SCREEN_PASS, SCREEN_FAIL or SCREEN_REFER`;
315
+ }
316
+ return { kind: 'rule', ruleId: rule.ruleId, observation: { kind: 'screen', outcome } };
317
+ }
318
+ case 'value': {
319
+ const noValue = writerValueRefusal(rule);
320
+ if (noValue !== undefined)
321
+ return noValue;
322
+ const field = writerFieldOf(rule, index);
323
+ if (field === undefined) {
324
+ return `\`${rule.ruleId}\` names no declared field, so no column states its value`;
325
+ }
326
+ const admission = admitPrimitive(field.primitive);
327
+ if (admission.kind === 'refused')
328
+ return admission.detail;
329
+ const cell = readScalarCell(tagged.body, admission.primitive);
330
+ if (!cell.ok)
331
+ return cell.detail;
332
+ return {
333
+ kind: 'rule',
334
+ ruleId: rule.ruleId,
335
+ observation: { kind: 'value', value: cell.value },
336
+ };
337
+ }
338
+ default:
339
+ return `unknown expectation tag \`${tagged.tag}\`; rule expectations are \`${OUTCOME_TAG}\`, \`${SCREEN_TAG}\` or \`${VALUE_TAG}\``;
340
+ }
341
+ }
342
+ /** The assertion one `expect.gate.` cell states, or the reason it states none. */
343
+ function readGateItemAssertion(text, ruleId, itemId) {
344
+ const tagged = splitTag(text);
345
+ if ('reason' in tagged)
346
+ return tagged.reason;
347
+ if (tagged.tag !== 'outcome') {
348
+ return 'a gate item states an outcome, so its cell is `outcome:PASS`';
349
+ }
350
+ if (!isOutcome(tagged.body)) {
351
+ return `\`${OUTCOME_TAG}\` states one of PASS, FAIL, UNKNOWN or DEFERRED`;
352
+ }
353
+ return {
354
+ kind: 'gateItem',
355
+ ruleId,
356
+ itemId,
357
+ observation: { kind: 'outcome', outcome: tagged.body },
358
+ };
359
+ }
360
+ /**
361
+ * The assertion one `expect.computed.` cell states, or the reason it states none.
362
+ *
363
+ * The primitive is the admitted one the column already resolved, so this reader cannot be
364
+ * called for a field a flat cell cannot state.
365
+ */
366
+ function readComputedAssertion(text, fieldId, primitive) {
367
+ const tagged = splitTag(text);
368
+ if ('reason' in tagged)
369
+ return tagged.reason;
370
+ if (tagged.tag !== 'value') {
371
+ return 'a computed value is stated as `value:<typed value>`';
372
+ }
373
+ const cell = readScalarCell(tagged.body, primitive);
374
+ if (!cell.ok)
375
+ return cell.detail;
376
+ return { kind: 'computed', fieldId, expected: cell.value };
377
+ }
378
+ /** The assertion one `expect.hidden.` cell states, or the reason it states none. */
379
+ function readHiddenAssertion(text, fieldId) {
380
+ if (text === 'true')
381
+ return { kind: 'fieldHidden', fieldId };
382
+ if (text === 'false')
383
+ return { kind: 'fieldVisible', fieldId };
384
+ return 'hidden cells are `true` (assert the field hidden) or `false` (assert it visible)';
385
+ }
386
+ /** The path and detail of one cell refusal, naming the row and the column. */
387
+ function cellRefusal(rowNumber, header, detail) {
388
+ return diagnostic(`$.rows[${String(rowNumber - 1)}]['${header}']`, detail);
389
+ }
390
+ /**
391
+ * One scenario read from one row, or the diagnostics that stopped it.
392
+ *
393
+ * A cell that is empty states nothing for `value.` and `context.` (absent) or `expect.` (no
394
+ * assertion). The structural `caseId`, `tier` and `recordDate` cells are never empty. The exact
395
+ * text `null` is the wire null in a value cell.
396
+ */
397
+ function readRow(cells, columns, header, index, rowNumber, seenCaseIds) {
398
+ const diagnostics = [];
399
+ const refuse = (column, detail) => {
400
+ diagnostics.push(cellRefusal(rowNumber, column.header, detail));
401
+ };
402
+ if (cells.length !== header.length) {
403
+ // The width is the row's fact, so the path stays on the row; the column names the cell to fix
404
+ // — the first the row does not state, or the first it states past the header.
405
+ const firstMissing = cells.length < header.length ? header[cells.length] : undefined;
406
+ const firstExtra = cells.length > header.length ? cells[header.length] : undefined;
407
+ const where = firstMissing === undefined
408
+ ? firstExtra === undefined
409
+ ? ''
410
+ : `; the first cell past the header is ${JSON.stringify(firstExtra)} in column ${String(header.length + 1)}`
411
+ : `; the first missing column is \`${firstMissing}\` (column ${String(cells.length + 1)})`;
412
+ diagnostics.push(diagnostic(`$.rows[${String(rowNumber - 1)}]`, `row ${String(rowNumber)} carries ${String(cells.length)} cells for ${String(header.length)} columns${where}`));
413
+ return { diagnostics };
414
+ }
415
+ for (const [position, cell] of cells.entries()) {
416
+ if (!exceedsUtf8Bytes(cell, MAX_CELL_BYTES))
417
+ continue;
418
+ // The bound is stated before the cell is read: a 64 KiB value would otherwise be parsed
419
+ // into a record the run could not publish and the terminal could not print.
420
+ diagnostics.push(boundsExceeded(`$.rows[${String(rowNumber - 1)}]['${header[position] ?? ''}']`, `row ${String(rowNumber)}, column \`${header[position] ?? ''}\`: the cell exceeds the ${String(MAX_CELL_BYTES)}-byte limit`));
421
+ }
422
+ if (diagnostics.length > 0)
423
+ return { diagnostics };
424
+ const values = {};
425
+ const context = {};
426
+ const assertions = [];
427
+ let caseId;
428
+ let tier;
429
+ let recordDate;
430
+ let stated = 0;
431
+ for (const column of columns) {
432
+ const text = cells[column.cell] ?? '';
433
+ switch (column.kind) {
434
+ case 'caseId': {
435
+ if (text === '') {
436
+ refuse(column, `row ${String(rowNumber)} states no \`caseId\``);
437
+ break;
438
+ }
439
+ if (!IDENTIFIER_PATTERN.test(text)) {
440
+ refuse(column, `\`${text}\` is not a case id: an id starts with a lower-case letter and carries lower-case letters, digits and underscores`);
441
+ break;
442
+ }
443
+ caseId = text;
444
+ break;
445
+ }
446
+ case 'tier': {
447
+ if (!isTier(text)) {
448
+ refuse(column, 'tier cells are `server` or `client`');
449
+ break;
450
+ }
451
+ tier = text;
452
+ break;
453
+ }
454
+ case 'recordDate': {
455
+ if (text === '') {
456
+ refuse(column, '`recordDate` is an empty structural cell; state a canonical civil date or omit the column');
457
+ break;
458
+ }
459
+ try {
460
+ parsePlainDate(text);
461
+ }
462
+ catch (cause) {
463
+ if (!(cause instanceof AxiomError))
464
+ throw cause;
465
+ refuse(column, cause.message);
466
+ break;
467
+ }
468
+ recordDate = text;
469
+ break;
470
+ }
471
+ case 'value': {
472
+ if (text === '')
473
+ break;
474
+ const cell = readScalarCell(text, column.primitive);
475
+ if (!cell.ok) {
476
+ refuse(column, cell.detail);
477
+ break;
478
+ }
479
+ values[column.field.fieldId] = cell.value;
480
+ break;
481
+ }
482
+ case 'context': {
483
+ if (text === '')
484
+ break;
485
+ const cell = readScalarCell(text, column.primitive);
486
+ if (!cell.ok) {
487
+ refuse(column, cell.detail);
488
+ break;
489
+ }
490
+ context[column.rootPath] = cell.value;
491
+ break;
492
+ }
493
+ case 'rule': {
494
+ if (text === '')
495
+ break;
496
+ const assertion = readRuleAssertion(text, column.rule, index);
497
+ if (typeof assertion === 'string') {
498
+ refuse(column, assertion);
499
+ break;
500
+ }
501
+ assertions.push(assertion);
502
+ stated += 1;
503
+ break;
504
+ }
505
+ case 'gateItem': {
506
+ if (text === '')
507
+ break;
508
+ const assertion = readGateItemAssertion(text, column.ruleId, column.itemId);
509
+ if (typeof assertion === 'string') {
510
+ refuse(column, assertion);
511
+ break;
512
+ }
513
+ assertions.push(assertion);
514
+ stated += 1;
515
+ break;
516
+ }
517
+ case 'computed': {
518
+ if (text === '')
519
+ break;
520
+ const assertion = readComputedAssertion(text, column.fieldId, column.primitive);
521
+ if (typeof assertion === 'string') {
522
+ refuse(column, assertion);
523
+ break;
524
+ }
525
+ assertions.push(assertion);
526
+ stated += 1;
527
+ break;
528
+ }
529
+ case 'hidden': {
530
+ if (text === '')
531
+ break;
532
+ const assertion = readHiddenAssertion(text, column.fieldId);
533
+ if (typeof assertion === 'string') {
534
+ refuse(column, assertion);
535
+ break;
536
+ }
537
+ assertions.push(assertion);
538
+ stated += 1;
539
+ break;
540
+ }
541
+ default:
542
+ assertNever(column);
543
+ }
544
+ }
545
+ if (caseId !== undefined) {
546
+ if (seenCaseIds.has(caseId)) {
547
+ diagnostics.push(diagnostic(`$.rows[${String(rowNumber - 1)}]['caseId']`, `row ${String(rowNumber)} repeats the case id \`${caseId}\`; each row states its own`));
548
+ }
549
+ else {
550
+ seenCaseIds.add(caseId);
551
+ }
552
+ }
553
+ if (diagnostics.length === 0 && stated === 0) {
554
+ diagnostics.push(diagnostic(`$.rows[${String(rowNumber - 1)}]`, `row ${String(rowNumber)} states no assertion; a scenario states at least one \`expect.\` cell`));
555
+ }
556
+ if (diagnostics.length > 0)
557
+ return { diagnostics };
558
+ if (caseId === undefined) {
559
+ // The `caseId` column exists and its cell was read, so reaching here means the guard above
560
+ // and this reader disagree about the contract.
561
+ throw new Error('the matrix header has no caseId column');
562
+ }
563
+ return {
564
+ scenario: {
565
+ scenarioId: caseId,
566
+ input: {
567
+ values,
568
+ ...(Object.keys(context).length === 0 ? {} : { context }),
569
+ },
570
+ // The JSON reader starts a scenario at the evidence default tier, so a matrix that states none
571
+ // does too; a client matrix states it per row.
572
+ env: {
573
+ tier: tier ?? DEFAULT_EVIDENCE_TIER,
574
+ ...(recordDate === undefined ? {} : { recordDate }),
575
+ },
576
+ datasets: [],
577
+ assertions,
578
+ },
579
+ };
580
+ }
581
+ /**
582
+ * Reads one scenario matrix against the artifact it will be judged by.
583
+ *
584
+ * The artifact is needed because a cell's primitive is the field's declaration: a `value.`
585
+ * cell for an integer field is an integer spelling, one for a string field is a JSON string
586
+ * literal. Nothing here evaluates a rule; the suite is handed to `runScenarioSuite` exactly as
587
+ * a JSON suite is, and every reference it names is checked by that runner's own
588
+ * `validateReferences` before a record runs.
589
+ */
590
+ export function parseScenarioCsv(text, schema) {
591
+ const nonText = nonTextSourceDetail(text, 'the scenario matrix');
592
+ if (nonText !== undefined) {
593
+ return { ok: false, diagnostics: [diagnostic('$', nonText)] };
594
+ }
595
+ // The bound is read before the byte-order mark is removed: slicing first would materialise a
596
+ // copy of an input that is about to be refused.
597
+ const crossing = utf8Crossing(text, MAX_INPUT_BYTES);
598
+ if (crossing !== undefined) {
599
+ return {
600
+ ok: false,
601
+ diagnostics: [
602
+ boundsExceeded('$', `the matrix exceeds the ${String(MAX_INPUT_BYTES)}-byte (8 MiB) input limit at byte ${String(crossing.offset)}`),
603
+ ],
604
+ };
605
+ }
606
+ // RFC 8259 permits one leading byte-order mark; a spreadsheet may write one.
607
+ const source = text.startsWith('\uFEFF') ? text.slice(1) : text;
608
+ const parsed = Papa.parse(source, {
609
+ header: false,
610
+ dynamicTyping: false,
611
+ // No record is dropped before its width and `caseId` are checked: even an empty or quoted-empty
612
+ // line is a one-cell row, and a whitespace-only line must not be trimmed into one either.
613
+ skipEmptyLines: false,
614
+ // A matrix is comma-separated by contract; inferring a delimiter from the first line would
615
+ // let a stray semicolon choose the format.
616
+ delimiter: ',',
617
+ // One row past the bound is enough to know it is exceeded, so an 8 MiB file of one-cell
618
+ // rows is refused without first materialising two million records.
619
+ preview: MAX_DATA_ROWS + 2,
620
+ });
621
+ const parseDiagnostics = parsed.errors.map((error) => diagnostic(
622
+ // Papa counts every row from the header, so data row `n` is `row - 1` and its 1-based
623
+ // number is `row`.
624
+ `${error.row === undefined ? '$.rows' : `$.rows[${String(Math.max(error.row - 1, 0))}]`}`, `${error.row === undefined ? '' : `row ${String(error.row + 1)}: `}${error.code}: ${error.message}`));
625
+ if (parseDiagnostics.length > 0)
626
+ return { ok: false, diagnostics: parseDiagnostics };
627
+ // With empty-line skipping off, Papa represents the final record terminator as one last empty
628
+ // row. Remove exactly that sentinel only when the preview reached the input's end: when it is
629
+ // truncated, a final empty row is real input and the row bound below must see it.
630
+ const last = parsed.data[parsed.data.length - 1];
631
+ const data = !parsed.meta.truncated &&
632
+ (source.endsWith('\n') || source.endsWith('\r')) &&
633
+ last?.length === 1 &&
634
+ last[0] === ''
635
+ ? parsed.data.slice(0, -1)
636
+ : parsed.data;
637
+ const header = data[0];
638
+ if (header === undefined || header.length === 0) {
639
+ return {
640
+ ok: false,
641
+ diagnostics: [diagnostic('$', 'a scenario matrix needs a header row and at least one row')],
642
+ };
643
+ }
644
+ if (header.length > MAX_COLUMNS) {
645
+ return {
646
+ ok: false,
647
+ diagnostics: [
648
+ boundsExceeded(`$.header[${String(MAX_COLUMNS)}]`, `the matrix declares ${String(header.length)} columns; the limit is ${String(MAX_COLUMNS)}, so column ${String(MAX_COLUMNS + 1)} is the first past it`),
649
+ ],
650
+ };
651
+ }
652
+ const headerBounds = header.flatMap((name, cell) => exceedsUtf8Bytes(name, MAX_CELL_BYTES)
653
+ ? [
654
+ boundsExceeded(`$.header[${String(cell)}]`, `the header cell exceeds the ${String(MAX_CELL_BYTES)}-byte limit`),
655
+ ]
656
+ : []);
657
+ if (headerBounds.length > 0)
658
+ return { ok: false, diagnostics: headerBounds };
659
+ const rows = data.slice(1);
660
+ if (rows.length === 0) {
661
+ return {
662
+ ok: false,
663
+ diagnostics: [diagnostic('$.rows', 'a scenario matrix needs at least one data row')],
664
+ };
665
+ }
666
+ if (rows.length > MAX_DATA_ROWS) {
667
+ return {
668
+ ok: false,
669
+ diagnostics: [
670
+ boundsExceeded('$.rows', `the matrix carries more than ${String(MAX_DATA_ROWS)} data rows; the limit is ${String(MAX_DATA_ROWS)}`),
671
+ ],
672
+ };
673
+ }
674
+ // A duplicate header is refused before any column is resolved, so two spellings of one
675
+ // column cannot both land and quietly win by position. Case is the normalisation the
676
+ // identifier grammar makes: every declared id is lower-case, so `value.f_A` and `value.f_a`
677
+ // name one column.
678
+ const headerDiagnostics = [];
679
+ const exact = new Set();
680
+ const normalised = new Map();
681
+ for (const [cell, name] of header.entries()) {
682
+ if (exact.has(name)) {
683
+ headerDiagnostics.push(diagnostic(`$.header[${String(cell)}]`, `the header repeats \`${name}\``));
684
+ continue;
685
+ }
686
+ exact.add(name);
687
+ const key = name.toLowerCase();
688
+ const first = normalised.get(key);
689
+ if (first !== undefined) {
690
+ headerDiagnostics.push(diagnostic(`$.header[${String(cell)}]`, `\`${name}\` duplicates \`${first}\` once case is ignored, so one column is named twice`));
691
+ continue;
692
+ }
693
+ normalised.set(key, name);
694
+ }
695
+ if (headerDiagnostics.length > 0)
696
+ return { ok: false, diagnostics: headerDiagnostics };
697
+ const index = indexOf(schema);
698
+ const columns = [];
699
+ const columnDiagnostics = [];
700
+ for (const [cell, name] of header.entries()) {
701
+ const column = resolveColumn(name, cell, index);
702
+ if ('code' in column)
703
+ columnDiagnostics.push(column);
704
+ else
705
+ columns.push(column);
706
+ }
707
+ if (!columns.some((column) => column.kind === 'caseId')) {
708
+ columnDiagnostics.push(diagnostic('$.header', 'a scenario matrix needs a `caseId` column, one id per row'));
709
+ }
710
+ if (columnDiagnostics.length > 0)
711
+ return { ok: false, diagnostics: columnDiagnostics };
712
+ const seenCaseIds = new Set();
713
+ const scenarios = [];
714
+ for (const [position, cells] of rows.entries()) {
715
+ const row = readRow(cells, columns, header, index, position + 1, seenCaseIds);
716
+ if ('diagnostics' in row)
717
+ columnDiagnostics.push(...row.diagnostics);
718
+ else
719
+ scenarios.push(row.scenario);
720
+ }
721
+ if (columnDiagnostics.length > 0)
722
+ return { ok: false, diagnostics: columnDiagnostics };
723
+ const suite = { suiteVersion: 1, defaults: {}, scenarios };
724
+ // The runner's own reference check is the one authority for what a suite may name, so a
725
+ // matrix cannot produce a document it would refuse. The paths it states are the scenario
726
+ // paths an author reads in a JSON suite; the cell-level refusals above already name the
727
+ // spreadsheet coordinate.
728
+ const references = validateReferences(schema, suite);
729
+ if (references.length > 0)
730
+ return { ok: false, diagnostics: references };
731
+ return { ok: true, suite };
732
+ }
733
+ /** The cell text one wire value has under its declared primitive, or the refusal. */
734
+ function encodeScalarCell(value, primitive) {
735
+ const text = (() => {
736
+ if (value === null)
737
+ return 'null';
738
+ switch (primitive) {
739
+ case 'string':
740
+ return typeof value === 'string' ? JSON.stringify(value) : undefined;
741
+ case 'boolean':
742
+ return typeof value === 'boolean' ? (value ? 'true' : 'false') : undefined;
743
+ case 'integer':
744
+ return typeof value === 'number' ? String(value) : undefined;
745
+ case 'decimal':
746
+ case 'date':
747
+ case 'instant':
748
+ return typeof value === 'string' ? value : undefined;
749
+ case 'quantity':
750
+ // A quantity is a `{ value, unit }` pair; a flat cell cannot carry both members.
751
+ return undefined;
752
+ default:
753
+ return assertNever(primitive);
754
+ }
755
+ })();
756
+ if (text === undefined) {
757
+ return { ok: false, detail: `the value is not a canonical \`${primitive}\`` };
758
+ }
759
+ // The export re-reads what it wrote: a suite the row would not parse back is refused here
760
+ // rather than shipped as a file that loses a value.
761
+ const read = readScalarCell(text, primitive);
762
+ if (!read.ok)
763
+ return { ok: false, detail: read.detail };
764
+ if (!sameWireValue(read.value, value)) {
765
+ return { ok: false, detail: `the value is not a canonical \`${primitive}\`` };
766
+ }
767
+ return { ok: true, text };
768
+ }
769
+ /** The tagged `value:` body for one expectation, or the refusal. */
770
+ function encodeTaggedValue(value, primitive) {
771
+ const encoded = encodeScalarCell(value, primitive);
772
+ return encoded.ok ? { ok: true, text: `${VALUE_TAG}${encoded.text}` } : encoded;
773
+ }
774
+ /**
775
+ * The one row a scenario writes, or the reasons its facts have no cell.
776
+ *
777
+ * A suite that states a description, a defaults block, an overlay, a capability, a table
778
+ * exposure, a redaction or a session write has no column for it; so does an assertion kind
779
+ * the locked families do not name. Exporting it would drop a fact the suite holds, so the
780
+ * exporter refuses and points at the JSON suite that states it.
781
+ */
782
+ function cellsOfScenario(scenario, scenarioPath, index) {
783
+ const diagnostics = [];
784
+ const refuse = (path, detail) => {
785
+ diagnostics.push(diagnostic(path, detail));
786
+ };
787
+ if (scenario.description !== undefined) {
788
+ refuse(`${scenarioPath}.description`, 'a description is not a matrix column; write a JSON suite');
789
+ }
790
+ if (scenario.datasets.length > 0) {
791
+ refuse(`${scenarioPath}.given.datasets`, 'a table exposure is not a matrix column; write a JSON suite');
792
+ }
793
+ const { env, input } = scenario;
794
+ if (input.overlay !== undefined) {
795
+ refuse(`${scenarioPath}.given.accessOverlay`, 'an access overlay is not a matrix column; write a JSON suite');
796
+ }
797
+ if (env.capabilities !== undefined) {
798
+ refuse(`${scenarioPath}.given.capabilities`, 'a capability list is not a matrix column; write a JSON suite');
799
+ }
800
+ if (env.accessVersion !== undefined) {
801
+ refuse(`${scenarioPath}.given.accessVersion`, 'an access version belongs to an access overlay; write a JSON suite');
802
+ }
803
+ if (env.lookup !== undefined) {
804
+ refuse(`${scenarioPath}.given.lookup`, 'a lookup store is a run-time port, not a matrix column');
805
+ }
806
+ if (input.access !== undefined) {
807
+ refuse(`${scenarioPath}.given.access`, 'an access projection is not a matrix column; write a JSON suite');
808
+ }
809
+ if (input.redacted !== undefined) {
810
+ refuse(`${scenarioPath}.given.redacted`, 'a redaction is not a matrix column; write a JSON suite');
811
+ }
812
+ if (input.sessionWrites !== undefined) {
813
+ refuse(`${scenarioPath}.given.sessionWrites`, 'a session write is not a matrix column; write a JSON suite');
814
+ }
815
+ if (input.context !== undefined && Object.keys(input.context).length === 0) {
816
+ refuse(`${scenarioPath}.given.context`, 'an empty context object has no matrix column; write a JSON suite');
817
+ }
818
+ const cells = new Map();
819
+ const put = (header, text) => {
820
+ if (cells.has(header)) {
821
+ refuse(scenarioPath, `two expectations of this scenario share the \`${header}\` column, so one matrix row cannot carry both`);
822
+ return;
823
+ }
824
+ cells.set(header, text);
825
+ };
826
+ cells.set('caseId', scenario.scenarioId);
827
+ if (env.tier === 'client')
828
+ cells.set('tier', 'client');
829
+ if (env.recordDate !== undefined)
830
+ cells.set('recordDate', env.recordDate);
831
+ for (const [fieldId, value] of Object.entries(input.values)) {
832
+ if (!isWireValue(value)) {
833
+ refuse(`${scenarioPath}.given.values.${fieldId}`, 'the value is not a canonical wire value');
834
+ continue;
835
+ }
836
+ const field = index.fields.get(fieldId);
837
+ if (field === undefined) {
838
+ refuse(`${scenarioPath}.given.values.${fieldId}`, `the artifact declares no field \`${fieldId}\``);
839
+ continue;
840
+ }
841
+ const admission = admitPrimitive(field.primitive);
842
+ if (admission.kind === 'refused') {
843
+ refuse(`${scenarioPath}.given.values.${fieldId}`, admission.detail);
844
+ continue;
845
+ }
846
+ const encoded = encodeScalarCell(value, admission.primitive);
847
+ if (!encoded.ok) {
848
+ refuse(`${scenarioPath}.given.values.${fieldId}`, encoded.detail);
849
+ continue;
850
+ }
851
+ put(`value.${fieldId}`, encoded.text);
852
+ }
853
+ for (const [rootPath, value] of Object.entries(input.context ?? {})) {
854
+ if (!isWireValue(value)) {
855
+ refuse(`${scenarioPath}.given.context.${rootPath}`, 'the value is not a canonical wire value');
856
+ continue;
857
+ }
858
+ const root = index.roots.get(rootPath);
859
+ if (root === undefined) {
860
+ refuse(`${scenarioPath}.given.context.${rootPath}`, `the artifact declares no context root \`${rootPath}\``);
861
+ continue;
862
+ }
863
+ const admission = admitPrimitive(root.primitive);
864
+ if (admission.kind === 'refused') {
865
+ refuse(`${scenarioPath}.given.context.${rootPath}`, admission.detail);
866
+ continue;
867
+ }
868
+ const encoded = encodeScalarCell(value, admission.primitive);
869
+ if (!encoded.ok) {
870
+ refuse(`${scenarioPath}.given.context.${rootPath}`, encoded.detail);
871
+ continue;
872
+ }
873
+ put(`context.${rootPath}`, encoded.text);
874
+ }
875
+ for (const [assertionIndex, assertion] of scenario.assertions.entries()) {
876
+ const assertionPath = `${scenarioPath}.expect[${String(assertionIndex)}]`;
877
+ switch (assertion.kind) {
878
+ case 'rule': {
879
+ if (assertion.rowKey !== undefined) {
880
+ refuse(assertionPath, 'a row-key assertion is not a matrix column; write a JSON suite');
881
+ break;
882
+ }
883
+ const observation = assertion.observation;
884
+ if (observation.kind === 'outcome') {
885
+ put(`expect.rule.${assertion.ruleId}`, `${OUTCOME_TAG}${observation.outcome}`);
886
+ break;
887
+ }
888
+ if (observation.kind === 'screen') {
889
+ put(`expect.rule.${assertion.ruleId}`, `${SCREEN_TAG}${observation.outcome}`);
890
+ break;
891
+ }
892
+ const rule = index.rules.get(assertion.ruleId);
893
+ const noValue = rule === undefined ? undefined : writerValueRefusal(rule);
894
+ const field = rule === undefined ? undefined : writerFieldOf(rule, index);
895
+ if (noValue !== undefined || field === undefined) {
896
+ refuse(assertionPath, noValue ??
897
+ `\`${assertion.ruleId}\` names no declared field, so no column states its value`);
898
+ break;
899
+ }
900
+ const admission = admitPrimitive(field.primitive);
901
+ if (admission.kind === 'refused') {
902
+ refuse(assertionPath, admission.detail);
903
+ break;
904
+ }
905
+ const encoded = encodeTaggedValue(observation.value, admission.primitive);
906
+ if (!encoded.ok) {
907
+ refuse(assertionPath, encoded.detail);
908
+ break;
909
+ }
910
+ put(`expect.rule.${assertion.ruleId}`, encoded.text);
911
+ break;
912
+ }
913
+ case 'gateItem': {
914
+ if (assertion.observation.kind !== 'outcome') {
915
+ refuse(assertionPath, 'a gate item states an outcome, not a value or a screen outcome');
916
+ break;
917
+ }
918
+ put(`expect.gate.${assertion.ruleId}.${assertion.itemId}`, `${OUTCOME_TAG}${assertion.observation.outcome}`);
919
+ break;
920
+ }
921
+ case 'computed': {
922
+ const field = index.fields.get(assertion.fieldId);
923
+ if (field === undefined) {
924
+ refuse(assertionPath, `the artifact declares no field \`${assertion.fieldId}\``);
925
+ break;
926
+ }
927
+ const admission = admitPrimitive(field.primitive);
928
+ if (admission.kind === 'refused') {
929
+ refuse(assertionPath, admission.detail);
930
+ break;
931
+ }
932
+ const encoded = encodeTaggedValue(assertion.expected, admission.primitive);
933
+ if (!encoded.ok) {
934
+ refuse(assertionPath, encoded.detail);
935
+ break;
936
+ }
937
+ put(`expect.computed.${assertion.fieldId}`, encoded.text);
938
+ break;
939
+ }
940
+ case 'fieldHidden':
941
+ put(`expect.hidden.${assertion.fieldId}`, 'true');
942
+ break;
943
+ case 'fieldVisible':
944
+ put(`expect.hidden.${assertion.fieldId}`, 'false');
945
+ break;
946
+ case 'ready':
947
+ case 'fieldRequired':
948
+ case 'fieldMissingRequired':
949
+ case 'fieldDisabled':
950
+ case 'rowFact':
951
+ case 'gateStatus':
952
+ case 'gateOutcome':
953
+ case 'gateUndeterminedItem':
954
+ case 'screenOutcome':
955
+ case 'screenReason':
956
+ case 'exportIncludes':
957
+ case 'exportExcludes':
958
+ case 'exportValue':
959
+ case 'exportRefused':
960
+ refuse(assertionPath, `a \`${assertion.kind}\` expectation is not a matrix column; write a JSON suite`);
961
+ break;
962
+ default:
963
+ return assertNever(assertion);
964
+ }
965
+ }
966
+ return diagnostics.length > 0 ? { diagnostics } : { cells };
967
+ }
968
+ /** How one header family sorts relative to another, for a deterministic column order. */
969
+ function columnRank(header) {
970
+ if (header === 'caseId')
971
+ return 0;
972
+ if (header === 'tier')
973
+ return 1;
974
+ if (header === 'recordDate')
975
+ return 2;
976
+ if (header.startsWith('value.'))
977
+ return 3;
978
+ if (header.startsWith('context.'))
979
+ return 4;
980
+ if (header.startsWith('expect.rule.'))
981
+ return 5;
982
+ if (header.startsWith('expect.gate.'))
983
+ return 6;
984
+ if (header.startsWith('expect.computed.'))
985
+ return 7;
986
+ return 8;
987
+ }
988
+ /**
989
+ * Writes a suite as a deterministic RFC 4180 matrix.
990
+ *
991
+ * The columns are the union of every scenario's facts in a fixed family order, each family
992
+ * sorted by code point; the rows are the suite's scenarios in order; the line ending is CRLF.
993
+ * A cell whose text begins with a character a spreadsheet reads as a formula is neutralised
994
+ * with one leading `'` before RFC 4180 quoting, and `parseScenarioCsv` removes exactly that
995
+ * prefix from a raw numeric cell, so a negative value round-trips. A text cell is a JSON
996
+ * string literal, which already begins with `"` — a spreadsheet reads it as text, and its
997
+ * contents are never rewritten, so `=1+1` exported and re-imported is still `=1+1`.
998
+ */
999
+ export function exportScenarioCsv(suite, schema) {
1000
+ const diagnostics = [];
1001
+ if (suite.description !== undefined) {
1002
+ diagnostics.push(diagnostic('$.description', 'a description is not a matrix column; write a JSON suite'));
1003
+ }
1004
+ if (Object.keys(suite.defaults).length > 0) {
1005
+ diagnostics.push(diagnostic('$.defaults', 'a defaults block is not a matrix column; write a JSON suite'));
1006
+ }
1007
+ if (suite.scenarios.length === 0) {
1008
+ diagnostics.push(diagnostic('$.scenarios', 'a matrix states at least one scenario'));
1009
+ }
1010
+ const index = indexOf(schema);
1011
+ const headers = new Set();
1012
+ const rows = [];
1013
+ for (const [position, scenario] of suite.scenarios.entries()) {
1014
+ const row = cellsOfScenario(scenario, `$.scenarios[${String(position)}]`, index);
1015
+ if ('diagnostics' in row) {
1016
+ diagnostics.push(...row.diagnostics);
1017
+ continue;
1018
+ }
1019
+ for (const header of row.cells.keys())
1020
+ headers.add(header);
1021
+ rows.push(row.cells);
1022
+ }
1023
+ if (diagnostics.length > 0)
1024
+ return { ok: false, diagnostics };
1025
+ const ordered = [...headers].sort((left, right) => {
1026
+ const byRank = columnRank(left) - columnRank(right);
1027
+ return byRank === 0 ? compareCodePoints(left, right) : byRank;
1028
+ });
1029
+ const table = [
1030
+ ordered,
1031
+ ...rows.map((cells) => ordered.map((header) => {
1032
+ // A shared tier column cannot leave a default-tier row's structural cell empty. When no
1033
+ // row is a client the column is absent altogether and the reader's default still applies.
1034
+ const cell = cells.get(header) ?? (header === 'tier' ? DEFAULT_EVIDENCE_TIER : '');
1035
+ return neutralised(cell);
1036
+ })),
1037
+ ];
1038
+ const text = `${Papa.unparse(table, { newline: '\r\n' })}\r\n`;
1039
+ // The document type is not proof that a hand-built suite is closed, and the matrix has bounds
1040
+ // and structural rules as well as typed cells. A successful export must never be text this
1041
+ // adapter's own reader refuses, so the finished file crosses that same boundary before return.
1042
+ const parsed = parseScenarioCsv(text, schema);
1043
+ if (!parsed.ok)
1044
+ return { ok: false, diagnostics: parsed.diagnostics };
1045
+ return { ok: true, text };
1046
+ }
1047
+ //# sourceMappingURL=csv.js.map