@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.
- package/LICENSE +21 -0
- package/README.md +415 -2
- package/dist/article.d.ts +12 -0
- package/dist/article.d.ts.map +1 -0
- package/dist/article.js +16 -0
- package/dist/article.js.map +1 -0
- package/dist/cli/args.d.ts +101 -0
- package/dist/cli/args.d.ts.map +1 -0
- package/dist/cli/args.js +158 -0
- package/dist/cli/args.js.map +1 -0
- package/dist/cli/check.d.ts +2 -0
- package/dist/cli/check.d.ts.map +1 -0
- package/dist/cli/check.js +33 -0
- package/dist/cli/check.js.map +1 -0
- package/dist/cli/compile.d.ts +2 -0
- package/dist/cli/compile.d.ts.map +1 -0
- package/dist/cli/compile.js +43 -0
- package/dist/cli/compile.js.map +1 -0
- package/dist/cli/count.d.ts +15 -0
- package/dist/cli/count.d.ts.map +1 -0
- package/dist/cli/count.js +21 -0
- package/dist/cli/count.js.map +1 -0
- package/dist/cli/dataset.d.ts +28 -0
- package/dist/cli/dataset.d.ts.map +1 -0
- package/dist/cli/dataset.js +115 -0
- package/dist/cli/dataset.js.map +1 -0
- package/dist/cli/diff.d.ts +2 -0
- package/dist/cli/diff.d.ts.map +1 -0
- package/dist/cli/diff.js +297 -0
- package/dist/cli/diff.js.map +1 -0
- package/dist/cli/explain.d.ts +2 -0
- package/dist/cli/explain.d.ts.map +1 -0
- package/dist/cli/explain.js +95 -0
- package/dist/cli/explain.js.map +1 -0
- package/dist/cli/fields.d.ts +11 -0
- package/dist/cli/fields.d.ts.map +1 -0
- package/dist/cli/fields.js +13 -0
- package/dist/cli/fields.js.map +1 -0
- package/dist/cli/main.d.ts +2 -0
- package/dist/cli/main.d.ts.map +1 -0
- package/dist/cli/main.js +40 -0
- package/dist/cli/main.js.map +1 -0
- package/dist/cli/read.d.ts +56 -0
- package/dist/cli/read.d.ts.map +1 -0
- package/dist/cli/read.js +179 -0
- package/dist/cli/read.js.map +1 -0
- package/dist/cli/render.d.ts +58 -0
- package/dist/cli/render.d.ts.map +1 -0
- package/dist/cli/render.js +422 -0
- package/dist/cli/render.js.map +1 -0
- package/dist/cli/schema.d.ts +28 -0
- package/dist/cli/schema.d.ts.map +1 -0
- package/dist/cli/schema.js +46 -0
- package/dist/cli/schema.js.map +1 -0
- package/dist/cli/suite-report.d.ts +18 -0
- package/dist/cli/suite-report.d.ts.map +1 -0
- package/dist/cli/suite-report.js +58 -0
- package/dist/cli/suite-report.js.map +1 -0
- package/dist/cli/suites.d.ts +25 -0
- package/dist/cli/suites.d.ts.map +1 -0
- package/dist/cli/suites.js +67 -0
- package/dist/cli/suites.js.map +1 -0
- package/dist/cli/terminal.d.ts +45 -0
- package/dist/cli/terminal.d.ts.map +1 -0
- package/dist/cli/terminal.js +119 -0
- package/dist/cli/terminal.js.map +1 -0
- package/dist/cli/test.d.ts +12 -0
- package/dist/cli/test.d.ts.map +1 -0
- package/dist/cli/test.js +199 -0
- package/dist/cli/test.js.map +1 -0
- package/dist/cli/usage.d.ts +15 -0
- package/dist/cli/usage.d.ts.map +1 -0
- package/dist/cli/usage.js +95 -0
- package/dist/cli/usage.js.map +1 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +51 -0
- package/dist/cli.js.map +1 -0
- package/dist/compile/artifact-members.d.ts +57 -0
- package/dist/compile/artifact-members.d.ts.map +1 -0
- package/dist/compile/artifact-members.js +130 -0
- package/dist/compile/artifact-members.js.map +1 -0
- package/dist/compile/artifact.d.ts +20 -0
- package/dist/compile/artifact.d.ts.map +1 -0
- package/dist/compile/artifact.js +87 -0
- package/dist/compile/artifact.js.map +1 -0
- package/dist/compile/compilation.d.ts +46 -0
- package/dist/compile/compilation.d.ts.map +1 -0
- package/dist/compile/compilation.js +4 -0
- package/dist/compile/compilation.js.map +1 -0
- package/dist/compile/computed.d.ts +22 -0
- package/dist/compile/computed.d.ts.map +1 -0
- package/dist/compile/computed.js +245 -0
- package/dist/compile/computed.js.map +1 -0
- package/dist/compile/condition-warnings.d.ts +12 -0
- package/dist/compile/condition-warnings.d.ts.map +1 -0
- package/dist/compile/condition-warnings.js +26 -0
- package/dist/compile/condition-warnings.js.map +1 -0
- package/dist/compile/conditions.d.ts +18 -0
- package/dist/compile/conditions.d.ts.map +1 -0
- package/dist/compile/conditions.js +22 -0
- package/dist/compile/conditions.js.map +1 -0
- package/dist/compile/cross-checks.d.ts +67 -0
- package/dist/compile/cross-checks.d.ts.map +1 -0
- package/dist/compile/cross-checks.js +238 -0
- package/dist/compile/cross-checks.js.map +1 -0
- package/dist/compile/datasets.d.ts +52 -0
- package/dist/compile/datasets.d.ts.map +1 -0
- package/dist/compile/datasets.js +183 -0
- package/dist/compile/datasets.js.map +1 -0
- package/dist/compile/dead-weight.d.ts +26 -0
- package/dist/compile/dead-weight.d.ts.map +1 -0
- package/dist/compile/dead-weight.js +244 -0
- package/dist/compile/dead-weight.js.map +1 -0
- package/dist/compile/declaration-rules.d.ts +54 -0
- package/dist/compile/declaration-rules.d.ts.map +1 -0
- package/dist/compile/declaration-rules.js +510 -0
- package/dist/compile/declaration-rules.js.map +1 -0
- package/dist/compile/declarations.d.ts +44 -0
- package/dist/compile/declarations.d.ts.map +1 -0
- package/dist/compile/declarations.js +160 -0
- package/dist/compile/declarations.js.map +1 -0
- package/dist/compile/document.d.ts +4 -0
- package/dist/compile/document.d.ts.map +1 -0
- package/dist/compile/document.js +13 -0
- package/dist/compile/document.js.map +1 -0
- package/dist/compile/expression.d.ts +38 -0
- package/dist/compile/expression.d.ts.map +1 -0
- package/dist/compile/expression.js +288 -0
- package/dist/compile/expression.js.map +1 -0
- package/dist/compile/hashes.d.ts +26 -0
- package/dist/compile/hashes.d.ts.map +1 -0
- package/dist/compile/hashes.js +96 -0
- package/dist/compile/hashes.js.map +1 -0
- package/dist/compile/item-targets.d.ts +12 -0
- package/dist/compile/item-targets.d.ts.map +1 -0
- package/dist/compile/item-targets.js +287 -0
- package/dist/compile/item-targets.js.map +1 -0
- package/dist/compile/messages.d.ts +8 -0
- package/dist/compile/messages.d.ts.map +1 -0
- package/dist/compile/messages.js +62 -0
- package/dist/compile/messages.js.map +1 -0
- package/dist/compile/option-availability.d.ts +51 -0
- package/dist/compile/option-availability.d.ts.map +1 -0
- package/dist/compile/option-availability.js +171 -0
- package/dist/compile/option-availability.js.map +1 -0
- package/dist/compile/option-codes.d.ts +27 -0
- package/dist/compile/option-codes.d.ts.map +1 -0
- package/dist/compile/option-codes.js +212 -0
- package/dist/compile/option-codes.js.map +1 -0
- package/dist/compile/references.d.ts +14 -0
- package/dist/compile/references.d.ts.map +1 -0
- package/dist/compile/references.js +126 -0
- package/dist/compile/references.js.map +1 -0
- package/dist/compile/rows-from.d.ts +27 -0
- package/dist/compile/rows-from.d.ts.map +1 -0
- package/dist/compile/rows-from.js +164 -0
- package/dist/compile/rows-from.js.map +1 -0
- package/dist/compile/rules.d.ts +58 -0
- package/dist/compile/rules.d.ts.map +1 -0
- package/dist/compile/rules.js +327 -0
- package/dist/compile/rules.js.map +1 -0
- package/dist/compile/suggestions.d.ts +52 -0
- package/dist/compile/suggestions.d.ts.map +1 -0
- package/dist/compile/suggestions.js +633 -0
- package/dist/compile/suggestions.js.map +1 -0
- package/dist/compile/targets.d.ts +22 -0
- package/dist/compile/targets.d.ts.map +1 -0
- package/dist/compile/targets.js +125 -0
- package/dist/compile/targets.js.map +1 -0
- package/dist/compile/types.d.ts +84 -0
- package/dist/compile/types.d.ts.map +1 -0
- package/dist/compile/types.js +2 -0
- package/dist/compile/types.js.map +1 -0
- package/dist/compile/warning.d.ts +45 -0
- package/dist/compile/warning.d.ts.map +1 -0
- package/dist/compile/warning.js +2 -0
- package/dist/compile/warning.js.map +1 -0
- package/dist/compile-yaml.d.ts +23 -0
- package/dist/compile-yaml.d.ts.map +1 -0
- package/dist/compile-yaml.js +30 -0
- package/dist/compile-yaml.js.map +1 -0
- package/dist/compile.d.ts +78 -0
- package/dist/compile.d.ts.map +1 -0
- package/dist/compile.js +372 -0
- package/dist/compile.js.map +1 -0
- package/dist/csv/limits.d.ts +43 -0
- package/dist/csv/limits.d.ts.map +1 -0
- package/dist/csv/limits.js +51 -0
- package/dist/csv/limits.js.map +1 -0
- package/dist/csv/scalar.d.ts +33 -0
- package/dist/csv/scalar.d.ts.map +1 -0
- package/dist/csv/scalar.js +77 -0
- package/dist/csv/scalar.js.map +1 -0
- package/dist/datasets/csv.d.ts +46 -0
- package/dist/datasets/csv.d.ts.map +1 -0
- package/dist/datasets/csv.js +293 -0
- package/dist/datasets/csv.js.map +1 -0
- package/dist/datasets/declaration.d.ts +16 -0
- package/dist/datasets/declaration.d.ts.map +1 -0
- package/dist/datasets/declaration.js +104 -0
- package/dist/datasets/declaration.js.map +1 -0
- package/dist/datasets/diagnostics.d.ts +65 -0
- package/dist/datasets/diagnostics.d.ts.map +1 -0
- package/dist/datasets/diagnostics.js +2 -0
- package/dist/datasets/diagnostics.js.map +1 -0
- package/dist/datasets/diff.d.ts +46 -0
- package/dist/datasets/diff.d.ts.map +1 -0
- package/dist/datasets/diff.js +84 -0
- package/dist/datasets/diff.js.map +1 -0
- package/dist/datasets/document.d.ts +12 -0
- package/dist/datasets/document.d.ts.map +1 -0
- package/dist/datasets/document.js +382 -0
- package/dist/datasets/document.js.map +1 -0
- package/dist/datasets/index.d.ts +43 -0
- package/dist/datasets/index.d.ts.map +1 -0
- package/dist/datasets/index.js +68 -0
- package/dist/datasets/index.js.map +1 -0
- package/dist/datasets/repair.d.ts +26 -0
- package/dist/datasets/repair.d.ts.map +1 -0
- package/dist/datasets/repair.js +60 -0
- package/dist/datasets/repair.js.map +1 -0
- package/dist/document-path.d.ts +62 -0
- package/dist/document-path.d.ts.map +1 -0
- package/dist/document-path.js +200 -0
- package/dist/document-path.js.map +1 -0
- package/dist/expr/boundary.d.ts +8 -0
- package/dist/expr/boundary.d.ts.map +1 -0
- package/dist/expr/boundary.js +243 -0
- package/dist/expr/boundary.js.map +1 -0
- package/dist/expr/compile-expr.d.ts +35 -0
- package/dist/expr/compile-expr.d.ts.map +1 -0
- package/dist/expr/compile-expr.js +66 -0
- package/dist/expr/compile-expr.js.map +1 -0
- package/dist/expr/deprecation.d.ts +23 -0
- package/dist/expr/deprecation.d.ts.map +1 -0
- package/dist/expr/deprecation.js +28 -0
- package/dist/expr/deprecation.js.map +1 -0
- package/dist/expr/diagnostics.d.ts +31 -0
- package/dist/expr/diagnostics.d.ts.map +1 -0
- package/dist/expr/diagnostics.js +34 -0
- package/dist/expr/diagnostics.js.map +1 -0
- package/dist/expr/lexer.d.ts +49 -0
- package/dist/expr/lexer.d.ts.map +1 -0
- package/dist/expr/lexer.js +277 -0
- package/dist/expr/lexer.js.map +1 -0
- package/dist/expr/lint-warnings.d.ts +11 -0
- package/dist/expr/lint-warnings.d.ts.map +1 -0
- package/dist/expr/lint-warnings.js +20 -0
- package/dist/expr/lint-warnings.js.map +1 -0
- package/dist/expr/lint.d.ts +41 -0
- package/dist/expr/lint.d.ts.map +1 -0
- package/dist/expr/lint.js +1034 -0
- package/dist/expr/lint.js.map +1 -0
- package/dist/expr/parse/aggregates.d.ts +13 -0
- package/dist/expr/parse/aggregates.d.ts.map +1 -0
- package/dist/expr/parse/aggregates.js +48 -0
- package/dist/expr/parse/aggregates.js.map +1 -0
- package/dist/expr/parse/budget.d.ts +11 -0
- package/dist/expr/parse/budget.d.ts.map +1 -0
- package/dist/expr/parse/budget.js +57 -0
- package/dist/expr/parse/budget.js.map +1 -0
- package/dist/expr/parse/grammar.d.ts +9 -0
- package/dist/expr/parse/grammar.d.ts.map +1 -0
- package/dist/expr/parse/grammar.js +699 -0
- package/dist/expr/parse/grammar.js.map +1 -0
- package/dist/expr/parse/literals.d.ts +20 -0
- package/dist/expr/parse/literals.d.ts.map +1 -0
- package/dist/expr/parse/literals.js +132 -0
- package/dist/expr/parse/literals.js.map +1 -0
- package/dist/expr/parse/stream.d.ts +60 -0
- package/dist/expr/parse/stream.d.ts.map +1 -0
- package/dist/expr/parse/stream.js +151 -0
- package/dist/expr/parse/stream.js.map +1 -0
- package/dist/expr/parser.d.ts +45 -0
- package/dist/expr/parser.d.ts.map +1 -0
- package/dist/expr/parser.js +110 -0
- package/dist/expr/parser.js.map +1 -0
- package/dist/expr/print/spell.d.ts +78 -0
- package/dist/expr/print/spell.d.ts.map +1 -0
- package/dist/expr/print/spell.js +592 -0
- package/dist/expr/print/spell.js.map +1 -0
- package/dist/expr/print.d.ts +20 -0
- package/dist/expr/print.d.ts.map +1 -0
- package/dist/expr/print.js +102 -0
- package/dist/expr/print.js.map +1 -0
- package/dist/expr/suggest.d.ts +26 -0
- package/dist/expr/suggest.d.ts.map +1 -0
- package/dist/expr/suggest.js +77 -0
- package/dist/expr/suggest.js.map +1 -0
- package/dist/expr/typecheck/aggregates.d.ts +8 -0
- package/dist/expr/typecheck/aggregates.d.ts.map +1 -0
- package/dist/expr/typecheck/aggregates.js +334 -0
- package/dist/expr/typecheck/aggregates.js.map +1 -0
- package/dist/expr/typecheck/arithmetic.d.ts +6 -0
- package/dist/expr/typecheck/arithmetic.d.ts.map +1 -0
- package/dist/expr/typecheck/arithmetic.js +258 -0
- package/dist/expr/typecheck/arithmetic.js.map +1 -0
- package/dist/expr/typecheck/arity.d.ts +38 -0
- package/dist/expr/typecheck/arity.d.ts.map +1 -0
- package/dist/expr/typecheck/arity.js +173 -0
- package/dist/expr/typecheck/arity.js.map +1 -0
- package/dist/expr/typecheck/calls.d.ts +6 -0
- package/dist/expr/typecheck/calls.d.ts.map +1 -0
- package/dist/expr/typecheck/calls.js +137 -0
- package/dist/expr/typecheck/calls.js.map +1 -0
- package/dist/expr/typecheck/comparison.d.ts +13 -0
- package/dist/expr/typecheck/comparison.d.ts.map +1 -0
- package/dist/expr/typecheck/comparison.js +200 -0
- package/dist/expr/typecheck/comparison.js.map +1 -0
- package/dist/expr/typecheck/compound.d.ts +24 -0
- package/dist/expr/typecheck/compound.d.ts.map +1 -0
- package/dist/expr/typecheck/compound.js +175 -0
- package/dist/expr/typecheck/compound.js.map +1 -0
- package/dist/expr/typecheck/context.d.ts +44 -0
- package/dist/expr/typecheck/context.d.ts.map +1 -0
- package/dist/expr/typecheck/context.js +2 -0
- package/dist/expr/typecheck/context.js.map +1 -0
- package/dist/expr/typecheck/datasets.d.ts +17 -0
- package/dist/expr/typecheck/datasets.d.ts.map +1 -0
- package/dist/expr/typecheck/datasets.js +136 -0
- package/dist/expr/typecheck/datasets.js.map +1 -0
- package/dist/expr/typecheck/digest.d.ts +7 -0
- package/dist/expr/typecheck/digest.d.ts.map +1 -0
- package/dist/expr/typecheck/digest.js +44 -0
- package/dist/expr/typecheck/digest.js.map +1 -0
- package/dist/expr/typecheck/fold.d.ts +41 -0
- package/dist/expr/typecheck/fold.d.ts.map +1 -0
- package/dist/expr/typecheck/fold.js +71 -0
- package/dist/expr/typecheck/fold.js.map +1 -0
- package/dist/expr/typecheck/gate-folds.d.ts +22 -0
- package/dist/expr/typecheck/gate-folds.d.ts.map +1 -0
- package/dist/expr/typecheck/gate-folds.js +40 -0
- package/dist/expr/typecheck/gate-folds.js.map +1 -0
- package/dist/expr/typecheck/guards.d.ts +6 -0
- package/dist/expr/typecheck/guards.d.ts.map +1 -0
- package/dist/expr/typecheck/guards.js +38 -0
- package/dist/expr/typecheck/guards.js.map +1 -0
- package/dist/expr/typecheck/member.d.ts +17 -0
- package/dist/expr/typecheck/member.d.ts.map +1 -0
- package/dist/expr/typecheck/member.js +46 -0
- package/dist/expr/typecheck/member.js.map +1 -0
- package/dist/expr/typecheck/money.d.ts +8 -0
- package/dist/expr/typecheck/money.d.ts.map +1 -0
- package/dist/expr/typecheck/money.js +49 -0
- package/dist/expr/typecheck/money.js.map +1 -0
- package/dist/expr/typecheck/numeric.d.ts +8 -0
- package/dist/expr/typecheck/numeric.d.ts.map +1 -0
- package/dist/expr/typecheck/numeric.js +84 -0
- package/dist/expr/typecheck/numeric.js.map +1 -0
- package/dist/expr/typecheck/operands.d.ts +27 -0
- package/dist/expr/typecheck/operands.d.ts.map +1 -0
- package/dist/expr/typecheck/operands.js +106 -0
- package/dist/expr/typecheck/operands.js.map +1 -0
- package/dist/expr/typecheck/paths.d.ts +21 -0
- package/dist/expr/typecheck/paths.d.ts.map +1 -0
- package/dist/expr/typecheck/paths.js +321 -0
- package/dist/expr/typecheck/paths.js.map +1 -0
- package/dist/expr/typecheck/records.d.ts +24 -0
- package/dist/expr/typecheck/records.d.ts.map +1 -0
- package/dist/expr/typecheck/records.js +53 -0
- package/dist/expr/typecheck/records.js.map +1 -0
- package/dist/expr/typecheck/sequences.d.ts +15 -0
- package/dist/expr/typecheck/sequences.d.ts.map +1 -0
- package/dist/expr/typecheck/sequences.js +55 -0
- package/dist/expr/typecheck/sequences.js.map +1 -0
- package/dist/expr/typecheck/strings.d.ts +8 -0
- package/dist/expr/typecheck/strings.d.ts.map +1 -0
- package/dist/expr/typecheck/strings.js +188 -0
- package/dist/expr/typecheck/strings.js.map +1 -0
- package/dist/expr/typecheck/temporal.d.ts +7 -0
- package/dist/expr/typecheck/temporal.d.ts.map +1 -0
- package/dist/expr/typecheck/temporal.js +80 -0
- package/dist/expr/typecheck/temporal.js.map +1 -0
- package/dist/expr/typecheck/types.d.ts +163 -0
- package/dist/expr/typecheck/types.d.ts.map +1 -0
- package/dist/expr/typecheck/types.js +404 -0
- package/dist/expr/typecheck/types.js.map +1 -0
- package/dist/expr/typecheck.d.ts +75 -0
- package/dist/expr/typecheck.d.ts.map +1 -0
- package/dist/expr/typecheck.js +242 -0
- package/dist/expr/typecheck.js.map +1 -0
- package/dist/expr/undecided.d.ts +13 -0
- package/dist/expr/undecided.d.ts.map +1 -0
- package/dist/expr/undecided.js +58 -0
- package/dist/expr/undecided.js.map +1 -0
- package/dist/expr/values/code-points.d.ts +13 -0
- package/dist/expr/values/code-points.d.ts.map +1 -0
- package/dist/expr/values/code-points.js +25 -0
- package/dist/expr/values/code-points.js.map +1 -0
- package/dist/expr/values/inline.d.ts +77 -0
- package/dist/expr/values/inline.d.ts.map +1 -0
- package/dist/expr/values/inline.js +404 -0
- package/dist/expr/values/inline.js.map +1 -0
- package/dist/expr/values/interval.d.ts +19 -0
- package/dist/expr/values/interval.d.ts.map +1 -0
- package/dist/expr/values/interval.js +1180 -0
- package/dist/expr/values/interval.js.map +1 -0
- package/dist/index.d.ts +163 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +128 -0
- package/dist/index.js.map +1 -0
- package/dist/ingest/document.d.ts +58 -0
- package/dist/ingest/document.d.ts.map +1 -0
- package/dist/ingest/document.js +83 -0
- package/dist/ingest/document.js.map +1 -0
- package/dist/ingest/yaml-document.d.ts +15 -0
- package/dist/ingest/yaml-document.d.ts.map +1 -0
- package/dist/ingest/yaml-document.js +42 -0
- package/dist/ingest/yaml-document.js.map +1 -0
- package/dist/ingest/yaml.d.ts +51 -0
- package/dist/ingest/yaml.d.ts.map +1 -0
- package/dist/ingest/yaml.js +340 -0
- package/dist/ingest/yaml.js.map +1 -0
- package/dist/layout/compile.d.ts +6 -0
- package/dist/layout/compile.d.ts.map +1 -0
- package/dist/layout/compile.js +224 -0
- package/dist/layout/compile.js.map +1 -0
- package/dist/layout/context.d.ts +12 -0
- package/dist/layout/context.d.ts.map +1 -0
- package/dist/layout/context.js +26 -0
- package/dist/layout/context.js.map +1 -0
- package/dist/layout/grammar.d.ts +34 -0
- package/dist/layout/grammar.d.ts.map +1 -0
- package/dist/layout/grammar.js +171 -0
- package/dist/layout/grammar.js.map +1 -0
- package/dist/layout/read.d.ts +54 -0
- package/dist/layout/read.d.ts.map +1 -0
- package/dist/layout/read.js +101 -0
- package/dist/layout/read.js.map +1 -0
- package/dist/layout/shape.d.ts +34 -0
- package/dist/layout/shape.d.ts.map +1 -0
- package/dist/layout/shape.js +149 -0
- package/dist/layout/shape.js.map +1 -0
- package/dist/messages/compile.d.ts +47 -0
- package/dist/messages/compile.d.ts.map +1 -0
- package/dist/messages/compile.js +202 -0
- package/dist/messages/compile.js.map +1 -0
- package/dist/messages/locale.d.ts +18 -0
- package/dist/messages/locale.d.ts.map +1 -0
- package/dist/messages/locale.js +33 -0
- package/dist/messages/locale.js.map +1 -0
- package/dist/messages/slots.d.ts +54 -0
- package/dist/messages/slots.d.ts.map +1 -0
- package/dist/messages/slots.js +137 -0
- package/dist/messages/slots.js.map +1 -0
- package/dist/overlay/compile-overlay.d.ts +29 -0
- package/dist/overlay/compile-overlay.d.ts.map +1 -0
- package/dist/overlay/compile-overlay.js +120 -0
- package/dist/overlay/compile-overlay.js.map +1 -0
- package/dist/overlay/compose.d.ts +26 -0
- package/dist/overlay/compose.d.ts.map +1 -0
- package/dist/overlay/compose.js +674 -0
- package/dist/overlay/compose.js.map +1 -0
- package/dist/overlay/types.d.ts +41 -0
- package/dist/overlay/types.d.ts.map +1 -0
- package/dist/overlay/types.js +2 -0
- package/dist/overlay/types.js.map +1 -0
- package/dist/publish/classify.d.ts +50 -0
- package/dist/publish/classify.d.ts.map +1 -0
- package/dist/publish/classify.js +85 -0
- package/dist/publish/classify.js.map +1 -0
- package/dist/publish/environment.d.ts +15 -0
- package/dist/publish/environment.d.ts.map +1 -0
- package/dist/publish/environment.js +2 -0
- package/dist/publish/environment.js.map +1 -0
- package/dist/publish/migrations.d.ts +108 -0
- package/dist/publish/migrations.d.ts.map +1 -0
- package/dist/publish/migrations.js +166 -0
- package/dist/publish/migrations.js.map +1 -0
- package/dist/publish/observation.d.ts +29 -0
- package/dist/publish/observation.d.ts.map +1 -0
- package/dist/publish/observation.js +43 -0
- package/dist/publish/observation.js.map +1 -0
- package/dist/publish/readiness.d.ts +197 -0
- package/dist/publish/readiness.d.ts.map +1 -0
- package/dist/publish/readiness.js +239 -0
- package/dist/publish/readiness.js.map +1 -0
- package/dist/publish/vectors.d.ts +50 -0
- package/dist/publish/vectors.d.ts.map +1 -0
- package/dist/publish/vectors.js +306 -0
- package/dist/publish/vectors.js.map +1 -0
- package/dist/publish/verify.d.ts +146 -0
- package/dist/publish/verify.d.ts.map +1 -0
- package/dist/publish/verify.js +548 -0
- package/dist/publish/verify.js.map +1 -0
- package/dist/scenarios/branch.d.ts +36 -0
- package/dist/scenarios/branch.d.ts.map +1 -0
- package/dist/scenarios/branch.js +30 -0
- package/dist/scenarios/branch.js.map +1 -0
- package/dist/scenarios/capture.d.ts +89 -0
- package/dist/scenarios/capture.d.ts.map +1 -0
- package/dist/scenarios/capture.js +443 -0
- package/dist/scenarios/capture.js.map +1 -0
- package/dist/scenarios/classifier.d.ts +20 -0
- package/dist/scenarios/classifier.d.ts.map +1 -0
- package/dist/scenarios/classifier.js +88 -0
- package/dist/scenarios/classifier.js.map +1 -0
- package/dist/scenarios/credit.d.ts +33 -0
- package/dist/scenarios/credit.d.ts.map +1 -0
- package/dist/scenarios/credit.js +330 -0
- package/dist/scenarios/credit.js.map +1 -0
- package/dist/scenarios/csv.d.ts +34 -0
- package/dist/scenarios/csv.d.ts.map +1 -0
- package/dist/scenarios/csv.js +1047 -0
- package/dist/scenarios/csv.js.map +1 -0
- package/dist/scenarios/data-identity.d.ts +39 -0
- package/dist/scenarios/data-identity.d.ts.map +1 -0
- package/dist/scenarios/data-identity.js +28 -0
- package/dist/scenarios/data-identity.js.map +1 -0
- package/dist/scenarios/document.d.ts +148 -0
- package/dist/scenarios/document.d.ts.map +1 -0
- package/dist/scenarios/document.js +513 -0
- package/dist/scenarios/document.js.map +1 -0
- package/dist/scenarios/environment.d.ts +64 -0
- package/dist/scenarios/environment.d.ts.map +1 -0
- package/dist/scenarios/environment.js +106 -0
- package/dist/scenarios/environment.js.map +1 -0
- package/dist/scenarios/evidence.d.ts +128 -0
- package/dist/scenarios/evidence.d.ts.map +1 -0
- package/dist/scenarios/evidence.js +179 -0
- package/dist/scenarios/evidence.js.map +1 -0
- package/dist/scenarios/expectations.d.ts +63 -0
- package/dist/scenarios/expectations.d.ts.map +1 -0
- package/dist/scenarios/expectations.js +490 -0
- package/dist/scenarios/expectations.js.map +1 -0
- package/dist/scenarios/references.d.ts +15 -0
- package/dist/scenarios/references.d.ts.map +1 -0
- package/dist/scenarios/references.js +239 -0
- package/dist/scenarios/references.js.map +1 -0
- package/dist/scenarios/report.d.ts +216 -0
- package/dist/scenarios/report.d.ts.map +1 -0
- package/dist/scenarios/report.js +54 -0
- package/dist/scenarios/report.js.map +1 -0
- package/dist/scenarios/runner.d.ts +55 -0
- package/dist/scenarios/runner.d.ts.map +1 -0
- package/dist/scenarios/runner.js +205 -0
- package/dist/scenarios/runner.js.map +1 -0
- package/dist/scenarios/vocabulary.d.ts +19 -0
- package/dist/scenarios/vocabulary.d.ts.map +1 -0
- package/dist/scenarios/vocabulary.js +56 -0
- package/dist/scenarios/vocabulary.js.map +1 -0
- package/dist/schema/catalogue.d.ts +54 -0
- package/dist/schema/catalogue.d.ts.map +1 -0
- package/dist/schema/catalogue.js +221 -0
- package/dist/schema/catalogue.js.map +1 -0
- package/dist/schema/check.d.ts +22 -0
- package/dist/schema/check.d.ts.map +1 -0
- package/dist/schema/check.js +30 -0
- package/dist/schema/check.js.map +1 -0
- package/dist/schema/closed.d.ts +19 -0
- package/dist/schema/closed.d.ts.map +1 -0
- package/dist/schema/closed.js +33 -0
- package/dist/schema/closed.js.map +1 -0
- package/dist/schema/collapse.d.ts +27 -0
- package/dist/schema/collapse.d.ts.map +1 -0
- package/dist/schema/collapse.js +143 -0
- package/dist/schema/collapse.js.map +1 -0
- package/dist/schema/controls.d.ts +46 -0
- package/dist/schema/controls.d.ts.map +1 -0
- package/dist/schema/controls.js +75 -0
- package/dist/schema/controls.js.map +1 -0
- package/dist/schema/dataset-declaration.d.ts +11 -0
- package/dist/schema/dataset-declaration.d.ts.map +1 -0
- package/dist/schema/dataset-declaration.js +11 -0
- package/dist/schema/dataset-declaration.js.map +1 -0
- package/dist/schema/declaration-warnings.d.ts +14 -0
- package/dist/schema/declaration-warnings.d.ts.map +1 -0
- package/dist/schema/declaration-warnings.js +77 -0
- package/dist/schema/declaration-warnings.js.map +1 -0
- package/dist/schema/declarations.d.ts +41 -0
- package/dist/schema/declarations.d.ts.map +1 -0
- package/dist/schema/declarations.js +1299 -0
- package/dist/schema/declarations.js.map +1 -0
- package/dist/schema/diagnostic.d.ts +118 -0
- package/dist/schema/diagnostic.d.ts.map +1 -0
- package/dist/schema/diagnostic.js +39 -0
- package/dist/schema/diagnostic.js.map +1 -0
- package/dist/schema/document.d.ts +93 -0
- package/dist/schema/document.d.ts.map +1 -0
- package/dist/schema/document.js +507 -0
- package/dist/schema/document.js.map +1 -0
- package/dist/schema/fields.d.ts +11 -0
- package/dist/schema/fields.d.ts.map +1 -0
- package/dist/schema/fields.js +265 -0
- package/dist/schema/fields.js.map +1 -0
- package/dist/schema/gates.d.ts +4 -0
- package/dist/schema/gates.d.ts.map +1 -0
- package/dist/schema/gates.js +68 -0
- package/dist/schema/gates.js.map +1 -0
- package/dist/schema/located.d.ts +27 -0
- package/dist/schema/located.d.ts.map +1 -0
- package/dist/schema/located.js +56 -0
- package/dist/schema/located.js.map +1 -0
- package/dist/schema/measurement.d.ts +9 -0
- package/dist/schema/measurement.d.ts.map +1 -0
- package/dist/schema/measurement.js +38 -0
- package/dist/schema/measurement.js.map +1 -0
- package/dist/schema/member-wording.d.ts +35 -0
- package/dist/schema/member-wording.d.ts.map +1 -0
- package/dist/schema/member-wording.js +286 -0
- package/dist/schema/member-wording.js.map +1 -0
- package/dist/schema/metaschema.d.ts +20 -0
- package/dist/schema/metaschema.d.ts.map +1 -0
- package/dist/schema/metaschema.js +476 -0
- package/dist/schema/metaschema.js.map +1 -0
- package/dist/schema/pointer.d.ts +31 -0
- package/dist/schema/pointer.d.ts.map +1 -0
- package/dist/schema/pointer.js +73 -0
- package/dist/schema/pointer.js.map +1 -0
- package/dist/schema/primary.d.ts +29 -0
- package/dist/schema/primary.d.ts.map +1 -0
- package/dist/schema/primary.js +48 -0
- package/dist/schema/primary.js.map +1 -0
- package/dist/schema/publish-vector.d.ts +17 -0
- package/dist/schema/publish-vector.d.ts.map +1 -0
- package/dist/schema/publish-vector.js +34 -0
- package/dist/schema/publish-vector.js.map +1 -0
- package/dist/schema/repair.d.ts +34 -0
- package/dist/schema/repair.d.ts.map +1 -0
- package/dist/schema/repair.js +163 -0
- package/dist/schema/repair.js.map +1 -0
- package/dist/schema/schema-v1.generated.d.ts +14 -0
- package/dist/schema/schema-v1.generated.d.ts.map +1 -0
- package/dist/schema/schema-v1.generated.js +7089 -0
- package/dist/schema/schema-v1.generated.js.map +1 -0
- package/dist/schema/screens.d.ts +4 -0
- package/dist/schema/screens.d.ts.map +1 -0
- package/dist/schema/screens.js +28 -0
- package/dist/schema/screens.js.map +1 -0
- package/dist/schema/test-values.d.ts +12 -0
- package/dist/schema/test-values.d.ts.map +1 -0
- package/dist/schema/test-values.js +97 -0
- package/dist/schema/test-values.js.map +1 -0
- package/dist/schema/unions.d.ts +46 -0
- package/dist/schema/unions.d.ts.map +1 -0
- package/dist/schema/unions.js +131 -0
- package/dist/schema/unions.js.map +1 -0
- package/dist/schema/validate-yaml.d.ts +14 -0
- package/dist/schema/validate-yaml.d.ts.map +1 -0
- package/dist/schema/validate-yaml.js +17 -0
- package/dist/schema/validate-yaml.js.map +1 -0
- package/dist/schema/validate.d.ts +46 -0
- package/dist/schema/validate.d.ts.map +1 -0
- package/dist/schema/validate.js +186 -0
- package/dist/schema/validate.js.map +1 -0
- package/dist/testing.d.ts +21 -0
- package/dist/testing.d.ts.map +1 -0
- package/dist/testing.js +28 -0
- package/dist/testing.js.map +1 -0
- package/dist/vocabulary.d.ts +6 -0
- package/dist/vocabulary.d.ts.map +1 -0
- package/dist/vocabulary.js +26 -0
- package/dist/vocabulary.js.map +1 -0
- package/package.json +66 -3
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"limits.js","sourceRoot":"","sources":["../../src/csv/limits.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,yDAAyD;AACzD,MAAM,CAAC,MAAM,eAAe,GAAW,CAAC,GA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E,KAAa;IAC1D,OAAO,YAAY,CAAC,IAAI,EAAE,KAAK,CAAC,KAAK,SAAS,CAAC;AACjD,CAAC","sourcesContent":["/**\n * The declared bounds of a CSV front-end, stated once.\n *\n * Two front-ends read CSV text — the scenario matrix and a dataset file — and both are fed a\n * document a caller holds whole. The matrix's bounds exist so a spreadsheet pasted into a studio\n * cannot exhaust the tab, and a dataset carries the same shape of risk in CI: one file is one\n * allocation, so the same four bounds are applied to it rather than a second policy an operator\n * would have to learn.\n *\n * The numbers are a contract, not a tuning knob: they are pinned by both front-ends' tests, and a\n * caller that needs more must state a different, documented limit rather than raise one silently.\n */\n\n/** The 8 MiB bound on the input text, in UTF-8 bytes. */\nexport const MAX_INPUT_BYTES: number = 8 * 1024 * 1024;\n/** The bound on data rows. */\nexport const MAX_DATA_ROWS: number = 1_000;\n/** The bound on columns, header included. */\nexport const MAX_COLUMNS: number = 256;\n/** The bound on one decoded cell, in UTF-8 bytes. */\nexport const MAX_CELL_BYTES: number = 64 * 1024;\n\n/** Where a text first passes a byte limit. */\nexport interface Utf8Crossing {\n /** The limit that was passed. */\n readonly limit: number;\n /**\n * The 1-based byte offset of the character whose bytes crossed the limit.\n *\n * A surrogate pair's first code unit names the pair, so an emoji that straddles the limit is\n * reported at the byte its four-byte sequence starts, which is the offset an editor jumps to.\n */\n readonly offset: number;\n}\n\n/**\n * Where `text` first passes `limit` UTF-8 bytes, or `undefined` when it does not.\n *\n * Counted rather than measured with `TextEncoder` so an over-long document is refused before a\n * byte array is materialised, and so the scan stops at the crossing instead of walking a file\n * that is already known to be too large.\n */\nexport function utf8Crossing(text: string, limit: number): Utf8Crossing | undefined {\n let bytes = 0;\n for (let index = 0; index < text.length; index += 1) {\n const start = bytes + 1;\n const code = text.charCodeAt(index);\n const paired =\n code >= 0xd800 &&\n code <= 0xdbff &&\n index + 1 < text.length &&\n (text.charCodeAt(index + 1) & 0xfc00) === 0xdc00;\n // Completing a pair consumes its second unit; leaving it to the next turn would count the\n // low surrogate on its own and overstate the size of a well-formed string.\n if (paired) index += 1;\n bytes += code < 0x80 ? 1 : code < 0x800 ? 2 : paired ? 4 : 3;\n if (bytes > limit) return { limit, offset: start };\n }\n return undefined;\n}\n\n/** Whether `text` is longer than `limit` UTF-8 bytes. */\nexport function exceedsUtf8Bytes(text: string, limit: number): boolean {\n return utf8Crossing(text, limit) !== undefined;\n}\n"]}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { ScalarPrimitive, WireValue } from '@azx-pbc/axiom-runtime';
|
|
2
|
+
/**
|
|
3
|
+
* The one admission path for a flat CSV cell's canonical scalar.
|
|
4
|
+
*
|
|
5
|
+
* Two CSV front-ends read cells — the dataset compiler and the scenario-matrix adapter — and
|
|
6
|
+
* both must refuse the same spellings: a decimal with a trailing zero, an integer with a
|
|
7
|
+
* leading zero or a leading `+`, `-0`, an unsafe integer, an impossible civil date. This
|
|
8
|
+
* module is that rule, defined once beside the runtime pattern and parser each primitive
|
|
9
|
+
* already owns.
|
|
10
|
+
*
|
|
11
|
+
* What a cell's *text* may say before it reaches here is the caller's dialect and stays in the
|
|
12
|
+
* caller: a dataset reads the cell raw, while a scenario matrix requires a JSON string literal
|
|
13
|
+
* for a text value and decodes it first. That difference is one line per caller; the numeric
|
|
14
|
+
* and date admission below never has a second copy.
|
|
15
|
+
*/
|
|
16
|
+
/** The scalar a dataset column or scenario value states without a second dimension. */
|
|
17
|
+
export type CsvScalarPrimitive = Exclude<ScalarPrimitive, 'money'>;
|
|
18
|
+
/** One cell as the canonical value its primitive declares, or the reason it is not one. */
|
|
19
|
+
export type CellResult = {
|
|
20
|
+
readonly ok: true;
|
|
21
|
+
readonly value: WireValue;
|
|
22
|
+
} | {
|
|
23
|
+
readonly ok: false;
|
|
24
|
+
readonly detail: string;
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* Reads a cell's text as the canonical spelling of `primitive`.
|
|
28
|
+
*
|
|
29
|
+
* The text is the value's own spelling, never a trimmed or repaired reading: a cell that is
|
|
30
|
+
* not exactly canonical is refused with the sentence that names the repair.
|
|
31
|
+
*/
|
|
32
|
+
export declare function parseCanonicalScalarCell(text: string, primitive: CsvScalarPrimitive): CellResult;
|
|
33
|
+
//# sourceMappingURL=scalar.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scalar.d.ts","sourceRoot":"","sources":["../../src/csv/scalar.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAEzE;;;;;;;;;;;;;GAaG;AAEH,uFAAuF;AACvF,MAAM,MAAM,kBAAkB,GAAG,OAAO,CAAC,eAAe,EAAE,OAAO,CAAC,CAAC;AAEnE,2FAA2F;AAC3F,MAAM,MAAM,UAAU,GAClB;IAAE,QAAQ,CAAC,EAAE,EAAE,IAAI,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,SAAS,CAAA;CAAE,GAChD;IAAE,QAAQ,CAAC,EAAE,EAAE,KAAK,CAAC;IAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC;AAMpD;;;;;GAKG;AACH,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,kBAAkB,GAAG,UAAU,CA8DhG"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { AxiomError, DECIMAL_TEXT_PATTERN, INTEGER_TEXT_PATTERN, asDecimalString, assertNever, isWireValue, parseInstant, parsePlainDate, } from '@azx-pbc/axiom-runtime';
|
|
2
|
+
function refused(detail) {
|
|
3
|
+
return { ok: false, detail };
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* Reads a cell's text as the canonical spelling of `primitive`.
|
|
7
|
+
*
|
|
8
|
+
* The text is the value's own spelling, never a trimmed or repaired reading: a cell that is
|
|
9
|
+
* not exactly canonical is refused with the sentence that names the repair.
|
|
10
|
+
*/
|
|
11
|
+
export function parseCanonicalScalarCell(text, primitive) {
|
|
12
|
+
switch (primitive) {
|
|
13
|
+
case 'string':
|
|
14
|
+
// A string outside the wire profile (an unpaired surrogate) has no UTF-8 encoding and would
|
|
15
|
+
// fail the dataset wire reader after metaschema validation; refuse it at the cell itself.
|
|
16
|
+
if (!isWireValue(text)) {
|
|
17
|
+
return refused('string cell carries an unpaired surrogate; pair the surrogate or remove it, since strings admit only paired surrogates');
|
|
18
|
+
}
|
|
19
|
+
// The caller's dialect decided what a text cell may spell; this is the text it decoded.
|
|
20
|
+
return { ok: true, value: text };
|
|
21
|
+
case 'boolean':
|
|
22
|
+
if (text === 'true')
|
|
23
|
+
return { ok: true, value: true };
|
|
24
|
+
if (text === 'false')
|
|
25
|
+
return { ok: true, value: false };
|
|
26
|
+
return refused('boolean cells are written `true` or `false`');
|
|
27
|
+
case 'integer': {
|
|
28
|
+
// The runtime's canonical-integer pattern is the one rule: no leading `+`, no leading
|
|
29
|
+
// zeros beyond `0` and never `-0`, exactly as an expression literal or a wire value is
|
|
30
|
+
// read. A cell has no second spelling for an integer, so it is that text as it stands.
|
|
31
|
+
if (!INTEGER_TEXT_PATTERN.test(text)) {
|
|
32
|
+
return refused('integer cells are canonical base-10 text with no fraction, exponent or leading zero');
|
|
33
|
+
}
|
|
34
|
+
const value = Number(text);
|
|
35
|
+
if (!Number.isSafeInteger(value))
|
|
36
|
+
return refused('integer cells stay inside the safe range');
|
|
37
|
+
return { ok: true, value };
|
|
38
|
+
}
|
|
39
|
+
case 'decimal':
|
|
40
|
+
if (!DECIMAL_TEXT_PATTERN.test(text)) {
|
|
41
|
+
return refused('decimal cells are canonical decimal text with no exponent or trailing zero');
|
|
42
|
+
}
|
|
43
|
+
try {
|
|
44
|
+
return { ok: true, value: asDecimalString(text) };
|
|
45
|
+
}
|
|
46
|
+
catch (cause) {
|
|
47
|
+
if (!(cause instanceof AxiomError))
|
|
48
|
+
throw cause;
|
|
49
|
+
return refused(cause.message);
|
|
50
|
+
}
|
|
51
|
+
case 'date':
|
|
52
|
+
try {
|
|
53
|
+
parsePlainDate(text);
|
|
54
|
+
return { ok: true, value: text };
|
|
55
|
+
}
|
|
56
|
+
catch (cause) {
|
|
57
|
+
if (!(cause instanceof AxiomError))
|
|
58
|
+
throw cause;
|
|
59
|
+
return refused(cause.message);
|
|
60
|
+
}
|
|
61
|
+
case 'instant':
|
|
62
|
+
try {
|
|
63
|
+
parseInstant(text);
|
|
64
|
+
return { ok: true, value: text };
|
|
65
|
+
}
|
|
66
|
+
catch (cause) {
|
|
67
|
+
if (!(cause instanceof AxiomError))
|
|
68
|
+
throw cause;
|
|
69
|
+
return refused(cause.message);
|
|
70
|
+
}
|
|
71
|
+
case 'quantity':
|
|
72
|
+
return refused('a quantity names a unit, not a flat cell; write a JSON table row');
|
|
73
|
+
default:
|
|
74
|
+
return assertNever(primitive);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
//# sourceMappingURL=scalar.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scalar.js","sourceRoot":"","sources":["../../src/csv/scalar.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV,oBAAoB,EACpB,oBAAoB,EACpB,eAAe,EACf,WAAW,EACX,WAAW,EACX,YAAY,EACZ,cAAc,GACf,MAAM,wBAAwB,CAAC;AA0BhC,SAAS,OAAO,CAAC,MAAc;IAC7B,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC;AAC/B,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,wBAAwB,CAAC,IAAY,EAAE,SAA6B;IAClF,QAAQ,SAAS,EAAE,CAAC;QAClB,KAAK,QAAQ;YACX,4FAA4F;YAC5F,0FAA0F;YAC1F,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,EAAE,CAAC;gBACvB,OAAO,OAAO,CACZ,wHAAwH,CACzH,CAAC;YACJ,CAAC;YACD,wFAAwF;YACxF,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE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gBACrB,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;YACnC,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,IAAI,CAAC,CAAC,KAAK,YAAY,UAAU,CAAC;oBAAE,MAAM,KAAK,CAAC;gBAChD,OAAO,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;YAChC,CAAC;QACH,KAAK,SAAS;YACZ,IAAI,CAAC;gBACH,YAAY,CAAC,IAAI,CAAC,CAAC;gBACnB,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;YACnC,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,IAAI,CAAC,CAAC,KAAK,YAAY,UAAU,CAAC;oBAAE,MAAM,KAAK,CAAC;gBAChD,OAAO,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;YAChC,CAAC;QACH,KAAK,UAAU;YACb,OAAO,OAAO,CAAC,kEAAkE,CAAC,CAAC;QACrF;YACE,OAAO,WAAW,CAAC,SAAS,CAAC,CAAC;IAClC,CAAC;AACH,CAAC","sourcesContent":["import {\n AxiomError,\n DECIMAL_TEXT_PATTERN,\n INTEGER_TEXT_PATTERN,\n asDecimalString,\n assertNever,\n isWireValue,\n parseInstant,\n parsePlainDate,\n} from '@azx-pbc/axiom-runtime';\nimport type { ScalarPrimitive, WireValue } from '@azx-pbc/axiom-runtime';\n\n/**\n * The one admission path for a flat CSV cell's canonical scalar.\n *\n * Two CSV front-ends read cells — the dataset compiler and the scenario-matrix adapter — and\n * both must refuse the same spellings: a decimal with a trailing zero, an integer with a\n * leading zero or a leading `+`, `-0`, an unsafe integer, an impossible civil date. This\n * module is that rule, defined once beside the runtime pattern and parser each primitive\n * already owns.\n *\n * What a cell's *text* may say before it reaches here is the caller's dialect and stays in the\n * caller: a dataset reads the cell raw, while a scenario matrix requires a JSON string literal\n * for a text value and decodes it first. That difference is one line per caller; the numeric\n * and date admission below never has a second copy.\n */\n\n/** The scalar a dataset column or scenario value states without a second dimension. */\nexport type CsvScalarPrimitive = Exclude<ScalarPrimitive, 'money'>;\n\n/** One cell as the canonical value its primitive declares, or the reason it is not one. */\nexport type CellResult =\n | { readonly ok: true; readonly value: WireValue }\n | { readonly ok: false; readonly detail: string };\n\nfunction refused(detail: string): CellResult {\n return { ok: false, detail };\n}\n\n/**\n * Reads a cell's text as the canonical spelling of `primitive`.\n *\n * The text is the value's own spelling, never a trimmed or repaired reading: a cell that is\n * not exactly canonical is refused with the sentence that names the repair.\n */\nexport function parseCanonicalScalarCell(text: string, primitive: CsvScalarPrimitive): CellResult {\n switch (primitive) {\n case 'string':\n // A string outside the wire profile (an unpaired surrogate) has no UTF-8 encoding and would\n // fail the dataset wire reader after metaschema validation; refuse it at the cell itself.\n if (!isWireValue(text)) {\n return refused(\n 'string cell carries an unpaired surrogate; pair the surrogate or remove it, since strings admit only paired surrogates',\n );\n }\n // The caller's dialect decided what a text cell may spell; this is the text it decoded.\n return { ok: true, value: text };\n case 'boolean':\n if (text === 'true') return { ok: true, value: true };\n if (text === 'false') return { ok: true, value: false };\n return refused('boolean cells are written `true` or `false`');\n case 'integer': {\n // The runtime's canonical-integer pattern is the one rule: no leading `+`, no leading\n // zeros beyond `0` and never `-0`, exactly as an expression literal or a wire value is\n // read. A cell has no second spelling for an integer, so it is that text as it stands.\n if (!INTEGER_TEXT_PATTERN.test(text)) {\n return refused(\n 'integer cells are canonical base-10 text with no fraction, exponent or leading zero',\n );\n }\n const value = Number(text);\n if (!Number.isSafeInteger(value)) return refused('integer cells stay inside the safe range');\n return { ok: true, value };\n }\n case 'decimal':\n if (!DECIMAL_TEXT_PATTERN.test(text)) {\n return refused(\n 'decimal cells are canonical decimal text with no exponent or trailing zero',\n );\n }\n try {\n return { ok: true, value: asDecimalString(text) };\n } catch (cause) {\n if (!(cause instanceof AxiomError)) throw cause;\n return refused(cause.message);\n }\n case 'date':\n try {\n parsePlainDate(text);\n return { ok: true, value: text };\n } catch (cause) {\n if (!(cause instanceof AxiomError)) throw cause;\n return refused(cause.message);\n }\n case 'instant':\n try {\n parseInstant(text);\n return { ok: true, value: text };\n } catch (cause) {\n if (!(cause instanceof AxiomError)) throw cause;\n return refused(cause.message);\n }\n case 'quantity':\n return refused('a quantity names a unit, not a flat cell; write a JSON table row');\n default:\n return assertNever(primitive);\n }\n}\n"]}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { DatasetColumn, HitPolicy, TableBinding } from '@azx-pbc/axiom-runtime';
|
|
2
|
+
import type { DatasetCompileResult } from './diagnostics.js';
|
|
3
|
+
/**
|
|
4
|
+
* The CSV front-end of the dataset compiler.
|
|
5
|
+
*
|
|
6
|
+
* A CSV file carries rows and nothing else, so the table's own metadata — id, version,
|
|
7
|
+
* clock binding, kind, hit policy and declared columns — is supplied by the caller as a
|
|
8
|
+
* declaration. The header row then names `rowId`, each declared column in declaration order,
|
|
9
|
+
* and `outcome` for a decision table; every data cell is read against its column's primitive.
|
|
10
|
+
*
|
|
11
|
+
* The assembled document goes through the same metaschema and semantic checks as a JSON
|
|
12
|
+
* dataset, so the two formats cannot disagree about what a valid table is. A cell that is
|
|
13
|
+
* not the canonical spelling of its primitive is refused with the row and column it is in,
|
|
14
|
+
* never coerced.
|
|
15
|
+
*
|
|
16
|
+
* The file is held whole by the caller, so it carries the same declared bounds as the scenario
|
|
17
|
+
* matrix (`csv/limits.ts`): the input's bytes are counted before the byte-order mark is removed,
|
|
18
|
+
* the parse stops at the row bound, and the header's width and every cell are refused with the
|
|
19
|
+
* row and column an author must open. A CSV is one allocation in CI; a bound that only existed
|
|
20
|
+
* in the matrix let one file exhaust the job.
|
|
21
|
+
*/
|
|
22
|
+
/** What a CSV file cannot state about itself. */
|
|
23
|
+
export interface CsvDatasetDeclaration {
|
|
24
|
+
readonly tableId: string;
|
|
25
|
+
readonly tableVersion: number;
|
|
26
|
+
readonly binding: TableBinding;
|
|
27
|
+
/** A CSV holds rows, so it can compile a keyed table and never a set. */
|
|
28
|
+
readonly kind: 'lookup' | 'decision_table';
|
|
29
|
+
readonly hitPolicy: HitPolicy;
|
|
30
|
+
readonly collectLimit?: number;
|
|
31
|
+
readonly effectiveFrom?: string;
|
|
32
|
+
readonly effectiveTo?: string;
|
|
33
|
+
/** The declared columns, in the order the CSV columns appear after `rowId`. */
|
|
34
|
+
readonly columns: readonly DatasetColumn[];
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Compiles one CSV dataset against its declaration.
|
|
38
|
+
*
|
|
39
|
+
* The file's byte bound is read first, on the text the caller holds and before its byte-order
|
|
40
|
+
* mark is removed: a document that is already too large is refused without copying it. The
|
|
41
|
+
* declaration is checked next, as a table with no rows, so a bad binding, window, collect limit
|
|
42
|
+
* or duplicate column is reported before any cell is read. The data rows are then typed cell by
|
|
43
|
+
* cell and the assembled document is validated exactly as a JSON dataset is.
|
|
44
|
+
*/
|
|
45
|
+
export declare function compileCsvDataset(text: string, declaration: CsvDatasetDeclaration): DatasetCompileResult;
|
|
46
|
+
//# sourceMappingURL=csv.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"csv.d.ts","sourceRoot":"","sources":["../../src/datasets/csv.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,aAAa,EACb,SAAS,EAIT,YAAY,EAEb,MAAM,wBAAwB,CAAC;AAchC,OAAO,KAAK,EAAE,oBAAoB,EAAqB,MAAM,kBAAkB,CAAC;AAEhF;;;;;;;;;;;;;;;;;;GAkBG;AAEH,iDAAiD;AACjD,MAAM,WAAW,qBAAqB;IACpC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,OAAO,EAAE,YAAY,CAAC;IAC/B,yEAAyE;IACzE,QAAQ,CAAC,IAAI,EAAE,QAAQ,GAAG,gBAAgB,CAAC;IAC3C,QAAQ,CAAC,SAAS,EAAE,SAAS,CAAC;IAC9B,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,CAAC;IAC/B,QAAQ,CAAC,aAAa,CAAC,EAAE,MAAM,CAAC;IAChC,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAC9B,+EAA+E;IAC/E,QAAQ,CAAC,OAAO,EAAE,SAAS,aAAa,EAAE,CAAC;CAC5C;AA8GD;;;;;;;;GAQG;AACH,wBAAgB,iBAAiB,CAC/B,IAAI,EAAE,MAAM,EACZ,WAAW,EAAE,qBAAqB,GACjC,oBAAoB,CAiRtB"}
|
|
@@ -0,0 +1,293 @@
|
|
|
1
|
+
import Papa from 'papaparse';
|
|
2
|
+
import { AxiomError, parseRestrictedJson, toWireValue } from '@azx-pbc/axiom-runtime';
|
|
3
|
+
import { parseCanonicalScalarCell } from '../csv/scalar.js';
|
|
4
|
+
import { nonTextSourceDetail } from '../ingest/document.js';
|
|
5
|
+
import { OUTCOME_NAMES, isOutcome } from '../vocabulary.js';
|
|
6
|
+
import { MAX_CELL_BYTES, MAX_COLUMNS, MAX_DATA_ROWS, MAX_INPUT_BYTES, exceedsUtf8Bytes, utf8Crossing, } from '../csv/limits.js';
|
|
7
|
+
import { inspectDatasetDocument } from './document.js';
|
|
8
|
+
/** The reserved header cells a row's identity and outcome occupy. */
|
|
9
|
+
const ROW_ID_COLUMN = 'rowId';
|
|
10
|
+
const OUTCOME_COLUMN = 'outcome';
|
|
11
|
+
function refused(detail) {
|
|
12
|
+
return { ok: false, detail };
|
|
13
|
+
}
|
|
14
|
+
function parseCell(text, column) {
|
|
15
|
+
// A dataset reads the cell text raw. A scenario matrix requires a JSON string literal for a
|
|
16
|
+
// text value and decodes it before the same scalar admission runs; only that dialect differs.
|
|
17
|
+
if (column.primitive !== 'money')
|
|
18
|
+
return parseCanonicalScalarCell(text, column.primitive);
|
|
19
|
+
// A money cell is its canonical wire object in JSON text: a CSV has no second dimension in
|
|
20
|
+
// which to spell minor units, currency and scale apart from the data.
|
|
21
|
+
let parsed;
|
|
22
|
+
try {
|
|
23
|
+
parsed = parseRestrictedJson(text);
|
|
24
|
+
}
|
|
25
|
+
catch {
|
|
26
|
+
return refused('money cells are a canonical JSON money object as text');
|
|
27
|
+
}
|
|
28
|
+
try {
|
|
29
|
+
return { ok: true, value: toWireValue(parsed, '$', { primitive: 'money' }) };
|
|
30
|
+
}
|
|
31
|
+
catch (cause) {
|
|
32
|
+
if (!(cause instanceof AxiomError))
|
|
33
|
+
throw cause;
|
|
34
|
+
return refused(cause.message);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
/** The header a validated table requires, in order. */
|
|
38
|
+
function expectedHeader(table) {
|
|
39
|
+
return [
|
|
40
|
+
ROW_ID_COLUMN,
|
|
41
|
+
...(table.columns ?? []).map((column) => column.columnId),
|
|
42
|
+
...(table.kind === 'decision_table' ? [OUTCOME_COLUMN] : []),
|
|
43
|
+
];
|
|
44
|
+
}
|
|
45
|
+
function diagnostic(code, path, detail, row, column) {
|
|
46
|
+
return {
|
|
47
|
+
code,
|
|
48
|
+
path,
|
|
49
|
+
detail,
|
|
50
|
+
...(row === undefined ? {} : { row }),
|
|
51
|
+
...(column === undefined ? {} : { column }),
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
/** One refusal of a bound the CSV front-ends share, naming the row/column or byte offset. */
|
|
55
|
+
function boundsExceeded(path, detail, row, column) {
|
|
56
|
+
return diagnostic('CSV_BOUNDS', path, detail, row, column);
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* The rows of a file up to `limit` data rows, or the fact that there are more.
|
|
60
|
+
*
|
|
61
|
+
* The step parser hands over one row at a time, so the walk stops at the first row past the limit
|
|
62
|
+
* instead of materialising the file, and blank lines are skipped by the same reader the first pass
|
|
63
|
+
* used. The collected rows are complete whenever `over` is false — the reason a capped parse
|
|
64
|
+
* cannot simply be reused is that blank lines count toward its preview, so a table whose rows are
|
|
65
|
+
* interleaved with them would otherwise be compiled with its tail missing.
|
|
66
|
+
*/
|
|
67
|
+
function readCappedRows(text, limit) {
|
|
68
|
+
const rows = [];
|
|
69
|
+
const errors = [];
|
|
70
|
+
let over = false;
|
|
71
|
+
Papa.parse(text, {
|
|
72
|
+
header: false,
|
|
73
|
+
dynamicTyping: false,
|
|
74
|
+
skipEmptyLines: 'greedy',
|
|
75
|
+
delimiter: ',',
|
|
76
|
+
step: (results, parser) => {
|
|
77
|
+
for (const error of results.errors) {
|
|
78
|
+
errors.push(diagnostic('INVALID_ROW', '$.rows', `${error.code}: ${error.message}`, error.row === undefined ? undefined : error.row + 1));
|
|
79
|
+
}
|
|
80
|
+
rows.push(results.data);
|
|
81
|
+
if (rows.length <= limit + 1)
|
|
82
|
+
return;
|
|
83
|
+
over = true;
|
|
84
|
+
parser.abort();
|
|
85
|
+
},
|
|
86
|
+
});
|
|
87
|
+
return { rows, errors, over };
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Compiles one CSV dataset against its declaration.
|
|
91
|
+
*
|
|
92
|
+
* The file's byte bound is read first, on the text the caller holds and before its byte-order
|
|
93
|
+
* mark is removed: a document that is already too large is refused without copying it. The
|
|
94
|
+
* declaration is checked next, as a table with no rows, so a bad binding, window, collect limit
|
|
95
|
+
* or duplicate column is reported before any cell is read. The data rows are then typed cell by
|
|
96
|
+
* cell and the assembled document is validated exactly as a JSON dataset is.
|
|
97
|
+
*/
|
|
98
|
+
export function compileCsvDataset(text, declaration) {
|
|
99
|
+
const nonText = nonTextSourceDetail(text, 'the dataset');
|
|
100
|
+
if (nonText !== undefined) {
|
|
101
|
+
return { ok: false, diagnostics: [diagnostic('DATASET_INVALID', '$', nonText)] };
|
|
102
|
+
}
|
|
103
|
+
const crossing = utf8Crossing(text, MAX_INPUT_BYTES);
|
|
104
|
+
if (crossing !== undefined) {
|
|
105
|
+
return {
|
|
106
|
+
ok: false,
|
|
107
|
+
diagnostics: [
|
|
108
|
+
boundsExceeded('$', `the dataset text exceeds the ${String(MAX_INPUT_BYTES)}-byte (8 MiB) input limit at byte ${String(crossing.offset)}`),
|
|
109
|
+
],
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
// RFC 8259 permits one leading byte-order mark; `axiom`'s reader strips one too. The bound
|
|
113
|
+
// above measured the bytes the file actually carries, mark included.
|
|
114
|
+
const source = text.startsWith('\uFEFF') ? text.slice(1) : text;
|
|
115
|
+
const template = inspectDatasetDocument({ ...declaration, rows: [] });
|
|
116
|
+
if (!template.ok)
|
|
117
|
+
return template;
|
|
118
|
+
const expected = expectedHeader(template.dataset.document);
|
|
119
|
+
if (expected.length > MAX_COLUMNS) {
|
|
120
|
+
// The declaration fixes the header's width, so the bound is known before the file is parsed
|
|
121
|
+
// and a table that could never fit is refused without allocating a row of it.
|
|
122
|
+
return {
|
|
123
|
+
ok: false,
|
|
124
|
+
diagnostics: [
|
|
125
|
+
boundsExceeded(`$.header[${String(MAX_COLUMNS)}]`, `the table declares ${String(expected.length)} columns (header included); the limit is ${String(MAX_COLUMNS)}, so header column ${String(MAX_COLUMNS + 1)} is the first past it`, undefined, expected[MAX_COLUMNS]),
|
|
126
|
+
],
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
const parsed = Papa.parse(source, {
|
|
130
|
+
header: false,
|
|
131
|
+
dynamicTyping: false,
|
|
132
|
+
skipEmptyLines: 'greedy',
|
|
133
|
+
// A dataset is comma-separated by contract; inferring a delimiter from the first line
|
|
134
|
+
// would let a stray semicolon choose the format.
|
|
135
|
+
delimiter: ',',
|
|
136
|
+
// The parse is capped one record past the bound, so the tail of an oversized file is never
|
|
137
|
+
// materialised: the header plus 1,001 data rows is enough to know the bound was crossed.
|
|
138
|
+
preview: MAX_DATA_ROWS + 2,
|
|
139
|
+
});
|
|
140
|
+
const parseDiagnostics = parsed.errors.map((error) => diagnostic('INVALID_ROW', '$.rows', `${error.code}: ${error.message}`, error.row === undefined ? undefined : error.row + 1));
|
|
141
|
+
if (parseDiagnostics.length > 0)
|
|
142
|
+
return { ok: false, diagnostics: parseDiagnostics };
|
|
143
|
+
let header = parsed.data[0] ?? [];
|
|
144
|
+
let data = parsed.data.slice(1);
|
|
145
|
+
// A capped parse reports `truncated` when it stopped at the preview, which blank lines can
|
|
146
|
+
// reach on their own: `skipEmptyLines` drops them from the result but they still count as rows
|
|
147
|
+
// of the file. When it did, the rows are read again one at a time, up to the bound, so the file
|
|
148
|
+
// is either refused at the first row past the limit or compiled whole.
|
|
149
|
+
if (parsed.meta.truncated) {
|
|
150
|
+
const capped = readCappedRows(source, MAX_DATA_ROWS);
|
|
151
|
+
if (capped.errors.length > 0)
|
|
152
|
+
return { ok: false, diagnostics: capped.errors };
|
|
153
|
+
if (capped.over) {
|
|
154
|
+
const firstPast = MAX_DATA_ROWS + 1;
|
|
155
|
+
return {
|
|
156
|
+
ok: false,
|
|
157
|
+
diagnostics: [
|
|
158
|
+
boundsExceeded(`$.rows[${String(MAX_DATA_ROWS)}]`, `the table carries more than ${String(MAX_DATA_ROWS)} data rows; row ${String(firstPast)} is the first past the limit`, firstPast),
|
|
159
|
+
],
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
header = capped.rows[0] ?? header;
|
|
163
|
+
data = capped.rows.slice(1);
|
|
164
|
+
}
|
|
165
|
+
else if (data.length > MAX_DATA_ROWS) {
|
|
166
|
+
const firstPast = MAX_DATA_ROWS + 1;
|
|
167
|
+
return {
|
|
168
|
+
ok: false,
|
|
169
|
+
diagnostics: [
|
|
170
|
+
boundsExceeded(`$.rows[${String(MAX_DATA_ROWS)}]`, `the table carries more than ${String(MAX_DATA_ROWS)} data rows; row ${String(firstPast)} is the first past the limit`, firstPast),
|
|
171
|
+
],
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
if (header.length > MAX_COLUMNS) {
|
|
175
|
+
return {
|
|
176
|
+
ok: false,
|
|
177
|
+
diagnostics: [
|
|
178
|
+
boundsExceeded(`$.header[${String(MAX_COLUMNS)}]`, `the header declares ${String(header.length)} columns; the limit is ${String(MAX_COLUMNS)}, so header column ${String(MAX_COLUMNS + 1)} is the first past it`, undefined, header[MAX_COLUMNS] ?? expected[MAX_COLUMNS]),
|
|
179
|
+
],
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
const headerDiagnostics = [];
|
|
183
|
+
for (const [index, name] of header.entries()) {
|
|
184
|
+
if (!exceedsUtf8Bytes(name, MAX_CELL_BYTES))
|
|
185
|
+
continue;
|
|
186
|
+
// The bound is stated before the name is compared or reported: a 64 KiB header cell would
|
|
187
|
+
// otherwise travel through every diagnostic that quotes it.
|
|
188
|
+
headerDiagnostics.push(boundsExceeded(`$.header[${String(index)}]`, `header column ${String(index + 1)} exceeds the ${String(MAX_CELL_BYTES)}-byte cell limit`, undefined, expected[index]));
|
|
189
|
+
}
|
|
190
|
+
if (headerDiagnostics.length > 0)
|
|
191
|
+
return { ok: false, diagnostics: headerDiagnostics };
|
|
192
|
+
if (header.length !== expected.length) {
|
|
193
|
+
const firstExtra = expected[Math.min(header.length, expected.length - 1)];
|
|
194
|
+
headerDiagnostics.push(diagnostic('INVALID_HEADER', '$.columns', `the header declares ${String(header.length)} columns but the declaration requires ${String(expected.length)}: ${expected.join(', ')}`, undefined, firstExtra));
|
|
195
|
+
}
|
|
196
|
+
for (const [index, name] of expected.entries()) {
|
|
197
|
+
const found = header[index];
|
|
198
|
+
if (found === undefined || found === name)
|
|
199
|
+
continue;
|
|
200
|
+
headerDiagnostics.push(diagnostic('INVALID_HEADER', `$.columns[${String(index)}].columnId`, `column ${String(index + 1)} of the header is ${JSON.stringify(found)} but the declaration requires ${JSON.stringify(name)}`, undefined, name));
|
|
201
|
+
}
|
|
202
|
+
if (headerDiagnostics.length > 0)
|
|
203
|
+
return { ok: false, diagnostics: headerDiagnostics };
|
|
204
|
+
// The declaration passed the shared checks above, so the validated document's columns are
|
|
205
|
+
// the ones the rows are read against. A column's cell is at its position in the declaration,
|
|
206
|
+
// never at its rank within its role: orders the key columns among themselves
|
|
207
|
+
// and the output columns among themselves, and says nothing about one role preceding the
|
|
208
|
+
// other, so a declaration may interleave them.
|
|
209
|
+
const columns = (template.dataset.document.columns ?? []).map((column, index) => ({
|
|
210
|
+
column,
|
|
211
|
+
cell: index + 1,
|
|
212
|
+
}));
|
|
213
|
+
const keyColumns = columns.filter((entry) => entry.column.role === 'key');
|
|
214
|
+
const outputColumns = columns.filter((entry) => entry.column.role === 'output');
|
|
215
|
+
const rows = [];
|
|
216
|
+
const cellDiagnostics = [];
|
|
217
|
+
for (const [index, cells] of data.entries()) {
|
|
218
|
+
const rowNumber = index + 1;
|
|
219
|
+
const at = `$.rows[${String(index)}]`;
|
|
220
|
+
if (cells.length !== expected.length) {
|
|
221
|
+
cellDiagnostics.push(diagnostic('INVALID_ROW', at, `row ${rowNumber} carries ${String(cells.length)} cells for ${String(expected.length)} columns`, rowNumber, expected[cells.length] ?? header[cells.length]));
|
|
222
|
+
continue;
|
|
223
|
+
}
|
|
224
|
+
// Every cell is measured before any is typed: a 64 KiB value would otherwise be read into a
|
|
225
|
+
// record the table could not publish and the terminal could not print.
|
|
226
|
+
const oversized = cells.flatMap((cell, position) => exceedsUtf8Bytes(cell, MAX_CELL_BYTES)
|
|
227
|
+
? [
|
|
228
|
+
boundsExceeded(`${at}['${header[position] ?? expected[position] ?? ''}']`, `row ${rowNumber}, column \`${header[position] ?? expected[position] ?? ''}\`: the cell exceeds the ${String(MAX_CELL_BYTES)}-byte limit`, rowNumber, expected[position] ?? header[position]),
|
|
229
|
+
]
|
|
230
|
+
: []);
|
|
231
|
+
if (oversized.length > 0) {
|
|
232
|
+
cellDiagnostics.push(...oversized);
|
|
233
|
+
continue;
|
|
234
|
+
}
|
|
235
|
+
const key = [];
|
|
236
|
+
const output = {};
|
|
237
|
+
let rowValid = true;
|
|
238
|
+
/** Reads one cell, recording the row and column when it is not its declared primitive. */
|
|
239
|
+
const read = (column, cell, path) => {
|
|
240
|
+
const result = parseCell(cell, column);
|
|
241
|
+
if (result.ok)
|
|
242
|
+
return result.value;
|
|
243
|
+
cellDiagnostics.push(diagnostic('INVALID_CELL', path, result.detail, rowNumber, column.columnId));
|
|
244
|
+
rowValid = false;
|
|
245
|
+
return undefined;
|
|
246
|
+
};
|
|
247
|
+
keyColumns.forEach((entry, keyIndex) => {
|
|
248
|
+
const value = read(entry.column, cells[entry.cell] ?? '', `${at}.key[${String(keyIndex)}]`);
|
|
249
|
+
if (value !== undefined)
|
|
250
|
+
key.push(value);
|
|
251
|
+
});
|
|
252
|
+
const outputCells = outputColumns.map((entry) => cells[entry.cell] ?? '');
|
|
253
|
+
const empty = outputCells.filter((cell) => cell === '').length;
|
|
254
|
+
if (empty > 0 && empty < outputCells.length) {
|
|
255
|
+
// A CSV has no way to spell "absent", so a row either declares its whole output or
|
|
256
|
+
// none of it; a half-filled output would drop a member silently.
|
|
257
|
+
const column = outputColumns[outputCells.indexOf('')]?.column;
|
|
258
|
+
cellDiagnostics.push(diagnostic('INVALID_ROW', `${at}.output`, `row ${rowNumber} fills some output columns and not others; fill every output column or leave them all empty`, rowNumber, column?.columnId));
|
|
259
|
+
rowValid = false;
|
|
260
|
+
}
|
|
261
|
+
else if (empty === 0) {
|
|
262
|
+
outputColumns.forEach((entry, outputIndex) => {
|
|
263
|
+
const value = read(entry.column, outputCells[outputIndex] ?? '', `${at}.output.${entry.column.columnId}`);
|
|
264
|
+
if (value !== undefined)
|
|
265
|
+
output[entry.column.columnId] = value;
|
|
266
|
+
});
|
|
267
|
+
}
|
|
268
|
+
let outcome;
|
|
269
|
+
if (declaration.kind === 'decision_table') {
|
|
270
|
+
const cell = cells[expected.length - 1] ?? '';
|
|
271
|
+
if (isOutcome(cell))
|
|
272
|
+
outcome = cell;
|
|
273
|
+
else {
|
|
274
|
+
cellDiagnostics.push(diagnostic('INVALID_CELL', `${at}.outcome`, `an outcome cell is one of ${OUTCOME_NAMES.join(', ')}`, rowNumber, OUTCOME_COLUMN));
|
|
275
|
+
rowValid = false;
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
if (!rowValid)
|
|
279
|
+
continue;
|
|
280
|
+
rows.push({
|
|
281
|
+
rowId: cells[0] ?? '',
|
|
282
|
+
key,
|
|
283
|
+
...(outcome === undefined ? {} : { outcome }),
|
|
284
|
+
// An all-empty output section is how a CSV spells a row that produces no result
|
|
285
|
+
// ( permits it where the row does not decide `PASS`).
|
|
286
|
+
...(empty > 0 ? {} : { output }),
|
|
287
|
+
});
|
|
288
|
+
}
|
|
289
|
+
if (cellDiagnostics.length > 0)
|
|
290
|
+
return { ok: false, diagnostics: cellDiagnostics };
|
|
291
|
+
return inspectDatasetDocument({ ...template.dataset.document, rows });
|
|
292
|
+
}
|
|
293
|
+
//# sourceMappingURL=csv.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"csv.js","sourceRoot":"","sources":["../../src/datasets/csv.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,UAAU,EAAE,mBAAmB,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAUtF,OAAO,EAAE,wBAAwB,EAAE,MAAM,kBAAkB,CAAC;AAE5D,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC5D,OAAO,EACL,cAAc,EACd,WAAW,EACX,aAAa,EACb,eAAe,EACf,gBAAgB,EAChB,YAAY,GACb,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,sBAAsB,EAAE,MAAM,eAAe,CAAC;AAsCvD,qEAAqE;AACrE,MAAM,aAAa,GAAG,OAAO,CAAC;AAC9B,MAAM,cAAc,GAAG,SAAS,CAAC;AAEjC,SAAS,OAAO,CAAC,MAAc;IAC7B,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC;AAC/B,CAAC;AAED,SAAS,SAAS,CAAC,IAAY,EAAE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AAE,EACvD,SAAS,EACT,cAAc,CACf,CACF,CAAC;gBACF,QAAQ,GAAG,KAAK,CAAC;YACnB,CAAC;QACH,CAAC;QACD,IAAI,CAAC,QAAQ;YAAE,SAAS;QACxB,IAAI,CAAC,IAAI,CAAC;YACR,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,IAAI,EAAE;YACrB,GAAG;YACH,GAAG,CAAC,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC;YAC7C,gFAAgF;YAChF,sDAAsD;YACtD,GAAG,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC;SACjC,CAAC,CAAC;IACL,CAAC;IACD,IAAI,eAAe,CAAC,MAAM,GAAG,CAAC;QAAE,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,WAAW,EAAE,eAAe,EAAE,CAAC;IAEnF,OAAO,sBAAsB,CAAC,EAAE,GAAG,QAAQ,CAAC,OAAO,CAAC,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC;AACxE,CAAC","sourcesContent":["import Papa from 'papaparse';\nimport { AxiomError, parseRestrictedJson, toWireValue } from '@azx-pbc/axiom-runtime';\nimport type {\n DatasetColumn,\n HitPolicy,\n LookupRow,\n LookupTableDocument,\n Outcome,\n TableBinding,\n WireValue,\n} from '@azx-pbc/axiom-runtime';\nimport { parseCanonicalScalarCell } from '../csv/scalar.js';\nimport type { CellResult } from '../csv/scalar.js';\nimport { nonTextSourceDetail } from '../ingest/document.js';\nimport { OUTCOME_NAMES, isOutcome } from '../vocabulary.js';\nimport {\n MAX_CELL_BYTES,\n MAX_COLUMNS,\n MAX_DATA_ROWS,\n MAX_INPUT_BYTES,\n exceedsUtf8Bytes,\n utf8Crossing,\n} from '../csv/limits.js';\nimport { inspectDatasetDocument } from './document.js';\nimport type { DatasetCompileResult, DatasetDiagnostic } from './diagnostics.js';\n\n/**\n * The CSV front-end of the dataset compiler.\n *\n * A CSV file carries rows and nothing else, so the table's own metadata — id, version,\n * clock binding, kind, hit policy and declared columns — is supplied by the caller as a\n * declaration. The header row then names `rowId`, each declared column in declaration order,\n * and `outcome` for a decision table; every data cell is read against its column's primitive.\n *\n * The assembled document goes through the same metaschema and semantic checks as a JSON\n * dataset, so the two formats cannot disagree about what a valid table is. A cell that is\n * not the canonical spelling of its primitive is refused with the row and column it is in,\n * never coerced.\n *\n * The file is held whole by the caller, so it carries the same declared bounds as the scenario\n * matrix (`csv/limits.ts`): the input's bytes are counted before the byte-order mark is removed,\n * the parse stops at the row bound, and the header's width and every cell are refused with the\n * row and column an author must open. A CSV is one allocation in CI; a bound that only existed\n * in the matrix let one file exhaust the job.\n */\n\n/** What a CSV file cannot state about itself. */\nexport interface CsvDatasetDeclaration {\n readonly tableId: string;\n readonly tableVersion: number;\n readonly binding: TableBinding;\n /** A CSV holds rows, so it can compile a keyed table and never a set. */\n readonly kind: 'lookup' | 'decision_table';\n readonly hitPolicy: HitPolicy;\n readonly collectLimit?: number;\n readonly effectiveFrom?: string;\n readonly effectiveTo?: string;\n /** The declared columns, in the order the CSV columns appear after `rowId`. */\n readonly columns: readonly DatasetColumn[];\n}\n\n/** The reserved header cells a row's identity and outcome occupy. */\nconst ROW_ID_COLUMN = 'rowId';\nconst OUTCOME_COLUMN = 'outcome';\n\nfunction refused(detail: string): CellResult {\n return { ok: false, detail };\n}\n\nfunction parseCell(text: string, column: DatasetColumn): CellResult {\n // A dataset reads the cell text raw. A scenario matrix requires a JSON string literal for a\n // text value and decodes it before the same scalar admission runs; only that dialect differs.\n if (column.primitive !== 'money') return parseCanonicalScalarCell(text, column.primitive);\n // A money cell is its canonical wire object in JSON text: a CSV has no second dimension in\n // which to spell minor units, currency and scale apart from the data.\n let parsed: unknown;\n try {\n parsed = parseRestrictedJson(text);\n } catch {\n return refused('money cells are a canonical JSON money object as text');\n }\n try {\n return { ok: true, value: toWireValue(parsed, '$', { primitive: 'money' }) };\n } catch (cause) {\n if (!(cause instanceof AxiomError)) throw cause;\n return refused(cause.message);\n }\n}\n\n/** The header a validated table requires, in order. */\nfunction expectedHeader(table: LookupTableDocument): readonly string[] {\n return [\n ROW_ID_COLUMN,\n ...(table.columns ?? []).map((column) => column.columnId),\n ...(table.kind === 'decision_table' ? [OUTCOME_COLUMN] : []),\n ];\n}\n\nfunction diagnostic(\n code: DatasetDiagnostic['code'],\n path: string,\n detail: string,\n row?: number,\n column?: string,\n): DatasetDiagnostic {\n return {\n code,\n path,\n detail,\n ...(row === undefined ? {} : { row }),\n ...(column === undefined ? {} : { column }),\n };\n}\n\n/** One refusal of a bound the CSV front-ends share, naming the row/column or byte offset. */\nfunction boundsExceeded(\n path: string,\n detail: string,\n row?: number,\n column?: string,\n): DatasetDiagnostic {\n return diagnostic('CSV_BOUNDS', path, detail, row, column);\n}\n\n/**\n * The rows of a file up to `limit` data rows, or the fact that there are more.\n *\n * The step parser hands over one row at a time, so the walk stops at the first row past the limit\n * instead of materialising the file, and blank lines are skipped by the same reader the first pass\n * used. The collected rows are complete whenever `over` is false — the reason a capped parse\n * cannot simply be reused is that blank lines count toward its preview, so a table whose rows are\n * interleaved with them would otherwise be compiled with its tail missing.\n */\nfunction readCappedRows(\n text: string,\n limit: number,\n): {\n readonly rows: readonly string[][];\n readonly errors: readonly DatasetDiagnostic[];\n readonly over: boolean;\n} {\n const rows: string[][] = [];\n const errors: DatasetDiagnostic[] = [];\n let over = false;\n Papa.parse<string[]>(text, {\n header: false,\n dynamicTyping: false,\n skipEmptyLines: 'greedy',\n delimiter: ',',\n step: (results, parser) => {\n for (const error of results.errors) {\n errors.push(\n diagnostic(\n 'INVALID_ROW',\n '$.rows',\n `${error.code}: ${error.message}`,\n error.row === undefined ? undefined : error.row + 1,\n ),\n );\n }\n rows.push(results.data);\n if (rows.length <= limit + 1) return;\n over = true;\n parser.abort();\n },\n });\n return { rows, errors, over };\n}\n\n/**\n * Compiles one CSV dataset against its declaration.\n *\n * The file's byte bound is read first, on the text the caller holds and before its byte-order\n * mark is removed: a document that is already too large is refused without copying it. The\n * declaration is checked next, as a table with no rows, so a bad binding, window, collect limit\n * or duplicate column is reported before any cell is read. The data rows are then typed cell by\n * cell and the assembled document is validated exactly as a JSON dataset is.\n */\nexport function compileCsvDataset(\n text: string,\n declaration: CsvDatasetDeclaration,\n): DatasetCompileResult {\n const nonText = nonTextSourceDetail(text, 'the dataset');\n if (nonText !== undefined) {\n return { ok: false, diagnostics: [diagnostic('DATASET_INVALID', '$', nonText)] };\n }\n const crossing = utf8Crossing(text, MAX_INPUT_BYTES);\n if (crossing !== undefined) {\n return {\n ok: false,\n diagnostics: [\n boundsExceeded(\n '$',\n `the dataset text exceeds the ${String(MAX_INPUT_BYTES)}-byte (8 MiB) input limit at byte ${String(crossing.offset)}`,\n ),\n ],\n };\n }\n // RFC 8259 permits one leading byte-order mark; `axiom`'s reader strips one too. The bound\n // above measured the bytes the file actually carries, mark included.\n const source = text.startsWith('\\uFEFF') ? text.slice(1) : text;\n\n const template = inspectDatasetDocument({ ...declaration, rows: [] });\n if (!template.ok) return template;\n const expected = expectedHeader(template.dataset.document);\n if (expected.length > MAX_COLUMNS) {\n // The declaration fixes the header's width, so the bound is known before the file is parsed\n // and a table that could never fit is refused without allocating a row of it.\n return {\n ok: false,\n diagnostics: [\n boundsExceeded(\n `$.header[${String(MAX_COLUMNS)}]`,\n `the table declares ${String(expected.length)} columns (header included); the limit is ${String(MAX_COLUMNS)}, so header column ${String(MAX_COLUMNS + 1)} is the first past it`,\n undefined,\n expected[MAX_COLUMNS],\n ),\n ],\n };\n }\n\n const parsed = Papa.parse<string[]>(source, {\n header: false,\n dynamicTyping: false,\n skipEmptyLines: 'greedy',\n // A dataset is comma-separated by contract; inferring a delimiter from the first line\n // would let a stray semicolon choose the format.\n delimiter: ',',\n // The parse is capped one record past the bound, so the tail of an oversized file is never\n // materialised: the header plus 1,001 data rows is enough to know the bound was crossed.\n preview: MAX_DATA_ROWS + 2,\n });\n const parseDiagnostics = parsed.errors.map((error) =>\n diagnostic(\n 'INVALID_ROW',\n '$.rows',\n `${error.code}: ${error.message}`,\n error.row === undefined ? undefined : error.row + 1,\n ),\n );\n if (parseDiagnostics.length > 0) return { ok: false, diagnostics: parseDiagnostics };\n\n let header = parsed.data[0] ?? [];\n let data = parsed.data.slice(1);\n // A capped parse reports `truncated` when it stopped at the preview, which blank lines can\n // reach on their own: `skipEmptyLines` drops them from the result but they still count as rows\n // of the file. When it did, the rows are read again one at a time, up to the bound, so the file\n // is either refused at the first row past the limit or compiled whole.\n if (parsed.meta.truncated) {\n const capped = readCappedRows(source, MAX_DATA_ROWS);\n if (capped.errors.length > 0) return { ok: false, diagnostics: capped.errors };\n if (capped.over) {\n const firstPast = MAX_DATA_ROWS + 1;\n return {\n ok: false,\n diagnostics: [\n boundsExceeded(\n `$.rows[${String(MAX_DATA_ROWS)}]`,\n `the table carries more than ${String(MAX_DATA_ROWS)} data rows; row ${String(firstPast)} is the first past the limit`,\n firstPast,\n ),\n ],\n };\n }\n header = capped.rows[0] ?? header;\n data = capped.rows.slice(1);\n } else if (data.length > MAX_DATA_ROWS) {\n const firstPast = MAX_DATA_ROWS + 1;\n return {\n ok: false,\n diagnostics: [\n boundsExceeded(\n `$.rows[${String(MAX_DATA_ROWS)}]`,\n `the table carries more than ${String(MAX_DATA_ROWS)} data rows; row ${String(firstPast)} is the first past the limit`,\n firstPast,\n ),\n ],\n };\n }\n if (header.length > MAX_COLUMNS) {\n return {\n ok: false,\n diagnostics: [\n boundsExceeded(\n `$.header[${String(MAX_COLUMNS)}]`,\n `the header declares ${String(header.length)} columns; the limit is ${String(MAX_COLUMNS)}, so header column ${String(MAX_COLUMNS + 1)} is the first past it`,\n undefined,\n header[MAX_COLUMNS] ?? expected[MAX_COLUMNS],\n ),\n ],\n };\n }\n\n const headerDiagnostics: DatasetDiagnostic[] = [];\n for (const [index, name] of header.entries()) {\n if (!exceedsUtf8Bytes(name, MAX_CELL_BYTES)) continue;\n // The bound is stated before the name is compared or reported: a 64 KiB header cell would\n // otherwise travel through every diagnostic that quotes it.\n headerDiagnostics.push(\n boundsExceeded(\n `$.header[${String(index)}]`,\n `header column ${String(index + 1)} exceeds the ${String(MAX_CELL_BYTES)}-byte cell limit`,\n undefined,\n expected[index],\n ),\n );\n }\n if (headerDiagnostics.length > 0) return { ok: false, diagnostics: headerDiagnostics };\n if (header.length !== expected.length) {\n const firstExtra = expected[Math.min(header.length, expected.length - 1)];\n headerDiagnostics.push(\n diagnostic(\n 'INVALID_HEADER',\n '$.columns',\n `the header declares ${String(header.length)} columns but the declaration requires ${String(expected.length)}: ${expected.join(', ')}`,\n undefined,\n firstExtra,\n ),\n );\n }\n for (const [index, name] of expected.entries()) {\n const found = header[index];\n if (found === undefined || found === name) continue;\n headerDiagnostics.push(\n diagnostic(\n 'INVALID_HEADER',\n `$.columns[${String(index)}].columnId`,\n `column ${String(index + 1)} of the header is ${JSON.stringify(found)} but the declaration requires ${JSON.stringify(name)}`,\n undefined,\n name,\n ),\n );\n }\n if (headerDiagnostics.length > 0) return { ok: false, diagnostics: headerDiagnostics };\n\n // The declaration passed the shared checks above, so the validated document's columns are\n // the ones the rows are read against. A column's cell is at its position in the declaration,\n // never at its rank within its role: orders the key columns among themselves\n // and the output columns among themselves, and says nothing about one role preceding the\n // other, so a declaration may interleave them.\n const columns = (template.dataset.document.columns ?? []).map((column, index) => ({\n column,\n cell: index + 1,\n }));\n const keyColumns = columns.filter((entry) => entry.column.role === 'key');\n const outputColumns = columns.filter((entry) => entry.column.role === 'output');\n const rows: LookupRow[] = [];\n const cellDiagnostics: DatasetDiagnostic[] = [];\n for (const [index, cells] of data.entries()) {\n const rowNumber = index + 1;\n const at = `$.rows[${String(index)}]`;\n if (cells.length !== expected.length) {\n cellDiagnostics.push(\n diagnostic(\n 'INVALID_ROW',\n at,\n `row ${rowNumber} carries ${String(cells.length)} cells for ${String(expected.length)} columns`,\n rowNumber,\n expected[cells.length] ?? header[cells.length],\n ),\n );\n continue;\n }\n // Every cell is measured before any is typed: a 64 KiB value would otherwise be read into a\n // record the table could not publish and the terminal could not print.\n const oversized = cells.flatMap((cell, position) =>\n exceedsUtf8Bytes(cell, MAX_CELL_BYTES)\n ? [\n boundsExceeded(\n `${at}['${header[position] ?? expected[position] ?? ''}']`,\n `row ${rowNumber}, column \\`${header[position] ?? expected[position] ?? ''}\\`: the cell exceeds the ${String(MAX_CELL_BYTES)}-byte limit`,\n rowNumber,\n expected[position] ?? header[position],\n ),\n ]\n : [],\n );\n if (oversized.length > 0) {\n cellDiagnostics.push(...oversized);\n continue;\n }\n const key: WireValue[] = [];\n const output: Record<string, WireValue> = {};\n let rowValid = true;\n /** Reads one cell, recording the row and column when it is not its declared primitive. */\n const read = (column: DatasetColumn, cell: string, path: string): WireValue | undefined => {\n const result = parseCell(cell, column);\n if (result.ok) return result.value;\n cellDiagnostics.push(\n diagnostic('INVALID_CELL', path, result.detail, rowNumber, column.columnId),\n );\n rowValid = false;\n return undefined;\n };\n keyColumns.forEach((entry, keyIndex) => {\n const value = read(entry.column, cells[entry.cell] ?? '', `${at}.key[${String(keyIndex)}]`);\n if (value !== undefined) key.push(value);\n });\n const outputCells = outputColumns.map((entry) => cells[entry.cell] ?? '');\n const empty = outputCells.filter((cell) => cell === '').length;\n if (empty > 0 && empty < outputCells.length) {\n // A CSV has no way to spell \"absent\", so a row either declares its whole output or\n // none of it; a half-filled output would drop a member silently.\n const column = outputColumns[outputCells.indexOf('')]?.column;\n cellDiagnostics.push(\n diagnostic(\n 'INVALID_ROW',\n `${at}.output`,\n `row ${rowNumber} fills some output columns and not others; fill every output column or leave them all empty`,\n rowNumber,\n column?.columnId,\n ),\n );\n rowValid = false;\n } else if (empty === 0) {\n outputColumns.forEach((entry, outputIndex) => {\n const value = read(\n entry.column,\n outputCells[outputIndex] ?? '',\n `${at}.output.${entry.column.columnId}`,\n );\n if (value !== undefined) output[entry.column.columnId] = value;\n });\n }\n let outcome: Outcome | undefined;\n if (declaration.kind === 'decision_table') {\n const cell = cells[expected.length - 1] ?? '';\n if (isOutcome(cell)) outcome = cell;\n else {\n cellDiagnostics.push(\n diagnostic(\n 'INVALID_CELL',\n `${at}.outcome`,\n `an outcome cell is one of ${OUTCOME_NAMES.join(', ')}`,\n rowNumber,\n OUTCOME_COLUMN,\n ),\n );\n rowValid = false;\n }\n }\n if (!rowValid) continue;\n rows.push({\n rowId: cells[0] ?? '',\n key,\n ...(outcome === undefined ? {} : { outcome }),\n // An all-empty output section is how a CSV spells a row that produces no result\n // ( permits it where the row does not decide `PASS`).\n ...(empty > 0 ? {} : { output }),\n });\n }\n if (cellDiagnostics.length > 0) return { ok: false, diagnostics: cellDiagnostics };\n\n return inspectDatasetDocument({ ...template.dataset.document, rows });\n}\n"]}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { CsvDatasetDeclaration } from './csv.js';
|
|
2
|
+
/** A declaration read from untrusted JSON, or the member that is not the shape it declares. */
|
|
3
|
+
export type DeclarationNarrowing = {
|
|
4
|
+
readonly ok: true;
|
|
5
|
+
readonly declaration: CsvDatasetDeclaration;
|
|
6
|
+
} | {
|
|
7
|
+
readonly ok: false;
|
|
8
|
+
readonly path: string;
|
|
9
|
+
readonly detail: string;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Reads one declaration from untrusted JSON, naming the member that is not the shape the CSV
|
|
13
|
+
* front-end requires. The defect's `path` is a document path, so an author can go to it.
|
|
14
|
+
*/
|
|
15
|
+
export declare function narrowCsvDatasetDeclaration(value: unknown): DeclarationNarrowing;
|
|
16
|
+
//# sourceMappingURL=declaration.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"declaration.d.ts","sourceRoot":"","sources":["../../src/datasets/declaration.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,UAAU,CAAC;AAWtD,+FAA+F;AAC/F,MAAM,MAAM,oBAAoB,GAC5B;IAAE,QAAQ,CAAC,EAAE,EAAE,IAAI,CAAC;IAAC,QAAQ,CAAC,WAAW,EAAE,qBAAqB,CAAA;CAAE,GAClE;IAAE,QAAQ,CAAC,EAAE,EAAE,KAAK,CAAC;IAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC;AA0E3E;;;GAGG;AACH,wBAAgB,2BAA2B,CAAC,KAAK,EAAE,OAAO,GAAG,oBAAoB,CAShF"}
|