@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,1299 @@
|
|
|
1
|
+
import { isRecord } from '@azx-pbc/axiom-runtime';
|
|
2
|
+
import { canonicalMediaAcceptEntry, compareDecimalTexts, DECIMAL_PRECISION, parseClockTime, parseInstant, parsePlainDate, tryDecimalString, UNIT_CODE_PATTERN, } from '@azx-pbc/axiom-runtime';
|
|
3
|
+
import { indefiniteArticle } from '../article.js';
|
|
4
|
+
import { documentPath } from '../document-path.js';
|
|
5
|
+
import { closestNames } from '../expr/suggest.js';
|
|
6
|
+
import { fieldDeclarations, listAt, textAt } from './document.js';
|
|
7
|
+
import { noteWriterComparison } from './measurement.js';
|
|
8
|
+
/** Rule kinds that write a field, so two of them naming one field is conflict. */
|
|
9
|
+
const WRITER_KINDS = new Set(['compute', 'defaultCompute']);
|
|
10
|
+
/**
|
|
11
|
+
* The rule kinds an array row member must not be named by outside `item` scope: a writer cannot
|
|
12
|
+
* say which row's value it produced, and a `required` rule cannot say which row it constrains.
|
|
13
|
+
* `RULES-1.1.11` names the one spelling of both.
|
|
14
|
+
*/
|
|
15
|
+
const ROW_MEMBER_FORBIDDEN_KINDS = new Set([
|
|
16
|
+
'compute',
|
|
17
|
+
'defaultCompute',
|
|
18
|
+
'required',
|
|
19
|
+
]);
|
|
20
|
+
/**
|
|
21
|
+
* The rule kinds refused at `item` scope: each reports through one section per
|
|
22
|
+
* declaration, and a per-row verdict has no consumer that could act on it.
|
|
23
|
+
*/
|
|
24
|
+
const ITEM_FORBIDDEN_KINDS = new Set(['visible', 'gate', 'screen']);
|
|
25
|
+
/** The item-scoped kinds that must name the row member they write or constrain. */
|
|
26
|
+
const ITEM_TARGET_KINDS = new Set([
|
|
27
|
+
'compute',
|
|
28
|
+
'defaultCompute',
|
|
29
|
+
'required',
|
|
30
|
+
'enabled',
|
|
31
|
+
]);
|
|
32
|
+
/** The refusal a rule on an array declared inside another array receives, `RULES-1.1.11`. */
|
|
33
|
+
const NESTED_ITEM_ARRAY_DETAIL = 'Item-scoped rules on nested record arrays are not supported in v1; move this array to the top level or remove the item-scoped rule.';
|
|
34
|
+
/** The primitives a natural `rowKey` may name. */
|
|
35
|
+
const ROW_KEY_PRIMITIVES = new Set(['string', 'integer']);
|
|
36
|
+
/**
|
|
37
|
+
* The repair a count written on a non-array offers.
|
|
38
|
+
*
|
|
39
|
+
* The same sentence the metaschema's own refusal states: a bounded primitive has a value bound
|
|
40
|
+
* with the nearest name, a string has a length bound, and anything else admits neither, so the
|
|
41
|
+
* count belongs on an array field or nowhere. Suggesting `minimum` on a `media_ref` would name
|
|
42
|
+
* a member that field does not admit either.
|
|
43
|
+
*/
|
|
44
|
+
function countAlternative(primitive, bound) {
|
|
45
|
+
if (primitive !== undefined && BOUNDED_PRIMITIVES.has(primitive)) {
|
|
46
|
+
return `did you mean \`${bound}\`?`;
|
|
47
|
+
}
|
|
48
|
+
if (primitive === 'string') {
|
|
49
|
+
return `did you mean \`${bound === 'minimum' ? 'minLength' : 'maxLength'}\`?`;
|
|
50
|
+
}
|
|
51
|
+
return 'declare the count on an `array` field';
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* The article a primitive name takes, so a refusal reads "a `decimal` field" or "an `integer`
|
|
55
|
+
* field" rather than assembling the sentence with the wrong one.
|
|
56
|
+
*/
|
|
57
|
+
const articleForPrimitive = indefiniteArticle;
|
|
58
|
+
/** One curated member refusal, built at the member that is not admitted. */
|
|
59
|
+
function memberRefusal(document, owner, member, detail, supersededClauses) {
|
|
60
|
+
const at = [...owner, member];
|
|
61
|
+
return {
|
|
62
|
+
diagnostic: {
|
|
63
|
+
code: 'SCHEMA_INVALID',
|
|
64
|
+
path: documentPath(pointerOf(at), document),
|
|
65
|
+
detail,
|
|
66
|
+
instancePath: at,
|
|
67
|
+
// Every curated detail states the action it takes, so the generic SCHEMA_INVALID repair
|
|
68
|
+
// would only follow a sentence that already ended with one.
|
|
69
|
+
repairStated: true,
|
|
70
|
+
},
|
|
71
|
+
owner,
|
|
72
|
+
supersededClauses,
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
/** One instance path as the RFC 6901 URI fragment the document-path renderer reads. */
|
|
76
|
+
function pointerOf(segments) {
|
|
77
|
+
return `#/${segments
|
|
78
|
+
.map((segment) => String(segment).replaceAll('~', '~0').replaceAll('/', '~1'))
|
|
79
|
+
.join('/')}`;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* A curated refusal stated at a nested member path — one entry of an `accept` list, for
|
|
83
|
+
* example. `memberRefusal` names a member of the declaration; this names the instance the
|
|
84
|
+
* refusal is about, so a duplicate entry is reported at its own index.
|
|
85
|
+
*/
|
|
86
|
+
function locatedRefusal(document, owner, detail, supersededClauses = []) {
|
|
87
|
+
return {
|
|
88
|
+
diagnostic: {
|
|
89
|
+
code: 'SCHEMA_INVALID',
|
|
90
|
+
path: documentPath(pointerOf(owner), document),
|
|
91
|
+
detail,
|
|
92
|
+
instancePath: owner,
|
|
93
|
+
repairStated: true,
|
|
94
|
+
},
|
|
95
|
+
owner,
|
|
96
|
+
supersededClauses,
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
/** Whether a field's value is one captured `media_ref` or a list of them, `MODEL-2.1.20`. */
|
|
100
|
+
function capturesMedia(field) {
|
|
101
|
+
const primitive = textAt(field, 'primitive');
|
|
102
|
+
if (primitive === 'media_ref')
|
|
103
|
+
return true;
|
|
104
|
+
if (primitive !== 'array')
|
|
105
|
+
return false;
|
|
106
|
+
const items = field['items'];
|
|
107
|
+
return isRecord(items) && items['primitive'] === 'media_ref';
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* The `(currency, scale)` pair one `money` declaration must state, `MODEL-2.1.15`.
|
|
111
|
+
*
|
|
112
|
+
* A money value carries its own spelling, so a declaration that names only one of the pair
|
|
113
|
+
* states no domain the reader can enforce. Fields are held to the pair by the metaschema and the
|
|
114
|
+
* member wording; a context root reaches this curated pass so the author is told to add both
|
|
115
|
+
* rather than left with a raw `uniqueItems`-style keyword.
|
|
116
|
+
*/
|
|
117
|
+
function moneyDomainRefusals(document, owner, holder, primitive, label, refusals) {
|
|
118
|
+
const currency = holder['currency'];
|
|
119
|
+
const scale = holder['scale'];
|
|
120
|
+
if (primitive !== 'money') {
|
|
121
|
+
if (currency !== undefined) {
|
|
122
|
+
refusals.push(memberRefusal(document, owner, 'currency', `\`currency\` is the domain of a \`money\` declaration; ${label} is \`${String(primitive)}\` — declare the money domain on a \`money\` root, or remove \`currency\``, []));
|
|
123
|
+
}
|
|
124
|
+
// `scale` is the fraction limit of a quantity as well as the money scale, so only the
|
|
125
|
+
// primitives that admit neither are refused it.
|
|
126
|
+
if (scale !== undefined && primitive !== 'quantity') {
|
|
127
|
+
refusals.push(memberRefusal(document, owner, 'scale', `\`scale\` is the domain of a \`money\` or \`quantity\` declaration; ${label} is \`${String(primitive)}\` — declare the domain on a measured root, or remove \`scale\``, []));
|
|
128
|
+
}
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
if (currency === undefined || scale === undefined) {
|
|
132
|
+
refusals.push(locatedRefusal(document, owner, `${label} is \`money\`, so it must declare \`currency\` and \`scale\` together; a money value carries its own spelling, and a root that states only one of the pair admits a value this artifact cannot check`));
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* The `units` refusals of one quantity declaration, `MODEL-2.1.21`.
|
|
137
|
+
*
|
|
138
|
+
* A unit code is identifier-like, so a unit is one token; the list is the field's domain and
|
|
139
|
+
* therefore non-empty and duplicate-free. The metaschema states the same bounds, but this pass
|
|
140
|
+
* names the member and the repair rather than leaving the author with a bare `uniqueItems`.
|
|
141
|
+
*/
|
|
142
|
+
function quantityUnitsRefusals(document, owner, holder, primitive, fieldId, refusals) {
|
|
143
|
+
const units = holder['units'];
|
|
144
|
+
// Misplaced `units` on a non-quantity declaration is refused by the metaschema's `false`
|
|
145
|
+
// subschema and worded by `FIELD_MEMBER_WORDING`, so `closedShapeErrors` and `checkSchema`
|
|
146
|
+
// state the same sentence.
|
|
147
|
+
if (primitive !== 'quantity')
|
|
148
|
+
return;
|
|
149
|
+
if (units === undefined) {
|
|
150
|
+
refusals.push(memberRefusal(document, owner, 'units', `\`quantity\` ${fieldId} declares no \`units\`; state the non-empty, duplicate-free list of unit codes the value may name, such as \`["sqm", "lm", "each"]\``, [15]));
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
if (!Array.isArray(units) || units.length === 0) {
|
|
154
|
+
refusals.push(locatedRefusal(document, [...owner, 'units'], `\`units\` on \`quantity\` ${fieldId} lists no unit; state at least one lower-case unit code such as \`sqm\``));
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
const seen = new Map();
|
|
158
|
+
units.forEach((unit, index) => {
|
|
159
|
+
const at = [...owner, 'units', index];
|
|
160
|
+
if (typeof unit !== 'string' || !UNIT_CODE_PATTERN.test(unit)) {
|
|
161
|
+
refusals.push(locatedRefusal(document, at, `\`units\` entry ${JSON.stringify(unit)} on \`quantity\` ${fieldId} is not a lower-case unit code; write one like \`sqm\`, \`lm\`, \`each\`, \`m3\` or \`kg\``));
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
const first = seen.get(unit);
|
|
165
|
+
if (first !== undefined) {
|
|
166
|
+
refusals.push(locatedRefusal(document, [...owner, 'units'], `\`units\` on \`quantity\` ${fieldId} lists \`${unit}\` twice (entries ${String(first)} and ${String(index)}); the unit set is a domain, so remove the duplicate`));
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
seen.set(unit, index);
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* The `unit` refusals of one duration declaration, `MODEL-2.1.24`.
|
|
174
|
+
*
|
|
175
|
+
* A unit belongs to a duration and to nothing else; a duration that states none is `minutes`,
|
|
176
|
+
* so the member is optional. This pass names the member and the repair rather than leaving the
|
|
177
|
+
* author with the generic shape refusal.
|
|
178
|
+
*/
|
|
179
|
+
function durationUnitRefusals(document, owner, holder, primitive, fieldId, refusals) {
|
|
180
|
+
const unit = holder['unit'];
|
|
181
|
+
// Misplaced `unit` on a non-duration declaration is refused by the metaschema's `false`
|
|
182
|
+
// subschema and worded by `FIELD_MEMBER_WORDING`, so `closedShapeErrors` and `checkSchema`
|
|
183
|
+
// state the same sentence.
|
|
184
|
+
if (unit === undefined || primitive !== 'duration')
|
|
185
|
+
return;
|
|
186
|
+
if (unit !== 'minutes' && unit !== 'hours' && unit !== 'seconds') {
|
|
187
|
+
refusals.push(locatedRefusal(document, [...owner, 'unit'], `\`unit\` on duration ${fieldId} is ${JSON.stringify(unit)}; a duration unit is \`minutes\`, \`hours\` or \`seconds\``));
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* The `accept`, `minBytes` and `maxBytes` refusals of one field, `MODEL-2.1.20`.
|
|
192
|
+
*
|
|
193
|
+
* A constraint declared on a field that captures nothing would be a declaration that does
|
|
194
|
+
* nothing, so it is refused at the member with the kinds that admit it. An `accept` entry is
|
|
195
|
+
* canonicalised before it is stored: a duplicate is a duplicate of the lower-case spelling, so
|
|
196
|
+
* `IMAGE/PNG` and `image/png` are one entry rather than two, and a value the vocabulary does not
|
|
197
|
+
* admit is refused at its own index.
|
|
198
|
+
*/
|
|
199
|
+
function mediaConstraintRefusals(document, owner, field, primitive, fieldId, refusals) {
|
|
200
|
+
const media = capturesMedia(field);
|
|
201
|
+
for (const member of ['accept', 'minBytes', 'maxBytes']) {
|
|
202
|
+
if (field[member] === undefined || media)
|
|
203
|
+
continue;
|
|
204
|
+
const kind = primitive === 'array'
|
|
205
|
+
? 'a list whose `items.primitive` is not `media_ref`'
|
|
206
|
+
: `${articleForPrimitive(primitive)} \`${String(primitive)}\` value`;
|
|
207
|
+
refusals.push(memberRefusal(document, owner, member, `\`${member}\` constrains a captured \`media_ref\`; field \`${fieldId}\` holds ${kind} — declare the constraint on a \`media_ref\` field or on an \`array\` whose \`items.primitive\` is \`media_ref\``, [33]));
|
|
208
|
+
}
|
|
209
|
+
if (!media)
|
|
210
|
+
return;
|
|
211
|
+
const accept = field['accept'];
|
|
212
|
+
if (accept !== undefined) {
|
|
213
|
+
if (!Array.isArray(accept) || accept.length === 0) {
|
|
214
|
+
refusals.push(locatedRefusal(document, [...owner, 'accept'], `\`accept\` on field \`${fieldId}\` lists no media type; state at least one media type such as \`image/*\` or \`application/pdf\`, or an extension such as \`.pdf\``));
|
|
215
|
+
}
|
|
216
|
+
else {
|
|
217
|
+
const seen = new Map();
|
|
218
|
+
accept.forEach((entry, index) => {
|
|
219
|
+
const canonical = canonicalMediaAcceptEntry(entry);
|
|
220
|
+
const at = [...owner, 'accept', index];
|
|
221
|
+
if (canonical === undefined) {
|
|
222
|
+
refusals.push(locatedRefusal(document, at, `\`accept\` entry ${JSON.stringify(entry)} on field \`${fieldId}\` is not a media type or a leading-dot extension; write a lower-case media type such as \`image/png\` or \`image/*\`, or an extension such as \`.pdf\``));
|
|
223
|
+
return;
|
|
224
|
+
}
|
|
225
|
+
const first = seen.get(canonical);
|
|
226
|
+
if (first !== undefined) {
|
|
227
|
+
refusals.push(locatedRefusal(document, at, `\`accept\` on field \`${fieldId}\` lists \`${canonical}\` twice (entries ${String(first)} and ${String(index)}); remove the duplicate, because one entry states the constraint`));
|
|
228
|
+
return;
|
|
229
|
+
}
|
|
230
|
+
seen.set(canonical, index);
|
|
231
|
+
});
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
const minBytes = field['minBytes'];
|
|
235
|
+
const maxBytes = field['maxBytes'];
|
|
236
|
+
for (const [member, bound] of [
|
|
237
|
+
['minBytes', minBytes],
|
|
238
|
+
['maxBytes', maxBytes],
|
|
239
|
+
]) {
|
|
240
|
+
if (bound === undefined)
|
|
241
|
+
continue;
|
|
242
|
+
if (typeof bound !== 'number' || !Number.isSafeInteger(bound) || bound < 1) {
|
|
243
|
+
refusals.push(memberRefusal(document, owner, member, `\`${member}\` on field \`${fieldId}\` is ${String(bound)}; a byte bound is a positive safe integer, so write a whole number of bytes such as \`5000000\``, [33]));
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
if (typeof minBytes === 'number' &&
|
|
247
|
+
Number.isSafeInteger(minBytes) &&
|
|
248
|
+
typeof maxBytes === 'number' &&
|
|
249
|
+
Number.isSafeInteger(maxBytes) &&
|
|
250
|
+
minBytes > maxBytes) {
|
|
251
|
+
refusals.push(memberRefusal(document, owner, 'minBytes', `\`minBytes\` is ${String(minBytes)} and \`maxBytes\` is ${String(maxBytes)} on field \`${fieldId}\`; a capture cannot need more bytes than it permits — set \`minBytes\` at or below \`maxBytes\``, [33]));
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
/** The availability members a declared option may state, `RULES-7.1.1` and `RULES-7.1.4`. */
|
|
255
|
+
const OPTION_AVAILABILITY_MEMBERS = [
|
|
256
|
+
'availableWhen',
|
|
257
|
+
'unavailableMessageKey',
|
|
258
|
+
'unavailableParams',
|
|
259
|
+
'suggests',
|
|
260
|
+
];
|
|
261
|
+
/**
|
|
262
|
+
* The refusal a field earns when it declares both `options` and `optionSource`.
|
|
263
|
+
*
|
|
264
|
+
* The two members are two authorities for one value domain, so one of them goes. When the
|
|
265
|
+
* declared options also state availability, the choice is already made: availability is a
|
|
266
|
+
* declaration about codes the document declares, and a dynamically sourced code has none the
|
|
267
|
+
* compiler could evaluate, so the sentence names the member and the repair instead of leaving the
|
|
268
|
+
* author to infer it from the pair.
|
|
269
|
+
*/
|
|
270
|
+
function optionAuthorityDetail(field, fieldId) {
|
|
271
|
+
const stated = new Set();
|
|
272
|
+
for (const option of listAt(field, 'options')) {
|
|
273
|
+
if (!isRecord(option))
|
|
274
|
+
continue;
|
|
275
|
+
for (const member of OPTION_AVAILABILITY_MEMBERS) {
|
|
276
|
+
if (Object.hasOwn(option, member))
|
|
277
|
+
stated.add(`\`${member}\``);
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
if (stated.size === 0) {
|
|
281
|
+
return '`options` and `optionSource` are two authorities for one value domain, not both: remove `options` to keep the dynamic source, or remove `optionSource` to keep the static list';
|
|
282
|
+
}
|
|
283
|
+
const label = fieldId === undefined ? 'this field' : `field \`${fieldId}\``;
|
|
284
|
+
return `${label} takes its codes from \`optionSource\` and its \`options\` state ${[...stated].join(', ')}; availability and alternatives are a declaration about codes the document declares, and a dynamically sourced code has none to evaluate — remove \`optionSource\` to keep the declared codes and their availability, or remove \`options\` and the availability they state to keep the dynamic source`;
|
|
285
|
+
}
|
|
286
|
+
/**
|
|
287
|
+
* The member-admissibility refusals the metaschema states as `allOf`/`not` pairs, plus the
|
|
288
|
+
* members it requires conditionally, restated with the member, the admitted kinds and the repair.
|
|
289
|
+
*
|
|
290
|
+
* These run before the metaschema because the generic `not` error is what an author would
|
|
291
|
+
* otherwise receive, and the metaschema cannot say which member caused it or what to write
|
|
292
|
+
* instead. Each check therefore also names the clause it supersedes, so the caller can suppress
|
|
293
|
+
* that one generic reason while keeping every other reason the document has. The metaschema
|
|
294
|
+
* clause remains the backstop: this pass adds no admission the contract does not already state.
|
|
295
|
+
*/
|
|
296
|
+
export function memberAdmissibilityDiagnostics(document) {
|
|
297
|
+
if (!isRecord(document))
|
|
298
|
+
return [];
|
|
299
|
+
const refusals = [];
|
|
300
|
+
const visitFields = (fields, path) => {
|
|
301
|
+
fields.forEach((field, index) => {
|
|
302
|
+
if (!isRecord(field))
|
|
303
|
+
return;
|
|
304
|
+
const owner = [...path, index];
|
|
305
|
+
if (field['options'] !== undefined && field['optionSource'] !== undefined) {
|
|
306
|
+
refusals.push(memberRefusal(document, owner, 'optionSource', optionAuthorityDetail(field, textAt(field, 'fieldId')), [13]));
|
|
307
|
+
}
|
|
308
|
+
// `MODEL-2.1.16` gives a field one requirement: `required` compiles the generated
|
|
309
|
+
// `required` rule with a constant, and `requiredWhen` compiles that same rule with a
|
|
310
|
+
// condition. Both members would state it twice, which the metaschema refuses as a bare
|
|
311
|
+
// `not`; this names the pair and the member to remove.
|
|
312
|
+
if (field['required'] !== undefined && field['requiredWhen'] !== undefined) {
|
|
313
|
+
refusals.push(memberRefusal(document, owner, 'requiredWhen', '`required` and `requiredWhen` state one requirement twice, not both: a field declares either an unconditional requirement (`required`) or a conditional one (`requiredWhen`) — remove `required` to keep the condition, or remove `requiredWhen` to keep the unconditional one', [33]));
|
|
314
|
+
}
|
|
315
|
+
// A blank condition is not a condition: `""` satisfies the metaschema's `minLength` for an
|
|
316
|
+
// expression slot and compiles to no rule at all, while a whitespace-only string parses to
|
|
317
|
+
// no expression. Either way the authored requirement or reveal silently does nothing, so
|
|
318
|
+
// the member is refused here with the two spellings that state the intent.
|
|
319
|
+
const blankFieldId = textAt(field, 'fieldId') ?? 'this field';
|
|
320
|
+
for (const member of ['requiredWhen', 'visibleWhen']) {
|
|
321
|
+
const condition = field[member];
|
|
322
|
+
if (typeof condition !== 'string' || condition.trim() !== '')
|
|
323
|
+
continue;
|
|
324
|
+
refusals.push(memberRefusal(document, owner, member, member === 'requiredWhen'
|
|
325
|
+
? `field \`${blankFieldId}\` states no condition for \`requiredWhen\`; name the condition that makes the field required (for example \`f_service == "premium"\`), or declare \`required: true\` when the field is always required`
|
|
326
|
+
: `field \`${blankFieldId}\` states no condition for \`visibleWhen\`; name the condition that reveals the field (for example \`f_service == "premium"\`), or remove \`visibleWhen\` when the field is always shown`, []));
|
|
327
|
+
}
|
|
328
|
+
const control = textAt(field, 'control');
|
|
329
|
+
if (field['covers'] !== undefined && control !== 'signature_capture') {
|
|
330
|
+
const fieldId = textAt(field, 'fieldId') ?? 'this field';
|
|
331
|
+
refusals.push(memberRefusal(document, owner, 'covers', `\`covers\` is admitted only on a \`signature_capture\` field, because it states the targets that signature binds; \`${fieldId}\` ${control === undefined ? 'declares no control' : `declares control \`${control}\``}, so remove \`covers\` or declare the field as \`signature_capture\``, [14]));
|
|
332
|
+
}
|
|
333
|
+
// `covers` is mandatory on a signature capture, not merely admitted: a signature only
|
|
334
|
+
// binds what its coverage declares, so a capture with no list states nothing a verifier
|
|
335
|
+
// could recompute. The metaschema's `then.required` is the backstop; this names the
|
|
336
|
+
// member and the repair instead of leaving the author with the keyword.
|
|
337
|
+
if (control === 'signature_capture' && field['covers'] === undefined) {
|
|
338
|
+
const fieldId = textAt(field, 'fieldId') ?? 'this field';
|
|
339
|
+
refusals.push({
|
|
340
|
+
diagnostic: {
|
|
341
|
+
code: 'SCHEMA_INVALID',
|
|
342
|
+
path: documentPath(pointerOf(owner), document),
|
|
343
|
+
detail: `signature field \`${fieldId}\` declares no \`covers\` list; state the fields and context roots this signature binds, naming each declared \`fieldId\` in binding order`,
|
|
344
|
+
keyword: 'required',
|
|
345
|
+
instancePath: owner,
|
|
346
|
+
repairStated: true,
|
|
347
|
+
},
|
|
348
|
+
owner,
|
|
349
|
+
supersededClauses: [14],
|
|
350
|
+
});
|
|
351
|
+
}
|
|
352
|
+
const primitive = textAt(field, 'primitive');
|
|
353
|
+
const fieldId = textAt(field, 'fieldId') ?? 'this field';
|
|
354
|
+
mediaConstraintRefusals(document, owner, field, primitive, fieldId, refusals);
|
|
355
|
+
if (primitive !== 'array') {
|
|
356
|
+
for (const member of ['rowsFrom', 'rowsFromSource']) {
|
|
357
|
+
if (field[member] === undefined)
|
|
358
|
+
continue;
|
|
359
|
+
refusals.push(memberRefusal(document, owner, member, `\`${member}\` sizes an \`array\` field; field \`${fieldId}\` is ${articleForPrimitive(primitive)} \`${String(primitive)}\` value — move the row-count source to the array it describes`, [34]));
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
quantityUnitsRefusals(document, owner, field, primitive, `field \`${fieldId}\``, refusals);
|
|
363
|
+
durationUnitRefusals(document, owner, field, primitive, `field \`${fieldId}\``, refusals);
|
|
364
|
+
const items = field['items'];
|
|
365
|
+
if (isRecord(items)) {
|
|
366
|
+
quantityUnitsRefusals(document, [...owner, 'items'], items, textAt(items, 'primitive'), `item declaration of field \`${fieldId}\``, refusals);
|
|
367
|
+
durationUnitRefusals(document, [...owner, 'items'], items, textAt(items, 'primitive'), `item declaration of field \`${fieldId}\``, refusals);
|
|
368
|
+
}
|
|
369
|
+
if (field['minItems'] !== undefined && primitive !== 'array') {
|
|
370
|
+
refusals.push(memberRefusal(document, owner, 'minItems', `\`minItems\` counts entries; field \`${fieldId}\` holds one \`${String(primitive)}\` value — ${countAlternative(primitive, 'minimum')}`, [16]));
|
|
371
|
+
}
|
|
372
|
+
if (field['maxItems'] !== undefined && primitive !== 'array') {
|
|
373
|
+
refusals.push(memberRefusal(document, owner, 'maxItems', `\`maxItems\` counts entries; field \`${fieldId}\` holds one \`${String(primitive)}\` value — ${countAlternative(primitive, 'maximum')}`, [16]));
|
|
374
|
+
}
|
|
375
|
+
if (field['maxScale'] !== undefined && primitive !== 'decimal') {
|
|
376
|
+
refusals.push(memberRefusal(document, owner, 'maxScale', `\`maxScale\` bounds the fractional digits of a \`decimal\` value; field \`${fieldId}\` is ${articleForPrimitive(primitive)} \`${String(primitive)}\` ${primitive === 'money' || primitive === 'quantity' ? 'field, which states its fractional digits in `scale` — declare `maxScale` on a `decimal` field' : primitive === 'integer' ? 'field, which carries no fractional part — use a `decimal` field when a fraction is needed' : 'value — declare `maxScale` on a `decimal` field'}`, [38]));
|
|
377
|
+
}
|
|
378
|
+
if (typeof field['maxScale'] === 'number' &&
|
|
379
|
+
Number.isSafeInteger(field['maxScale']) &&
|
|
380
|
+
field['maxScale'] > DECIMAL_PRECISION) {
|
|
381
|
+
refusals.push(memberRefusal(document, owner, 'maxScale', `\`maxScale\` is ${String(field['maxScale'])} on field \`${fieldId}\`; a decimal carries at most ${String(DECIMAL_PRECISION)} significant digits — state a bound at or below ${String(DECIMAL_PRECISION)}`, [38]));
|
|
382
|
+
}
|
|
383
|
+
if (field['minimum'] !== undefined && primitive === 'array') {
|
|
384
|
+
refusals.push(memberRefusal(document, owner, 'minimum', `\`minimum\` bounds a value; field \`${fieldId}\` is a list of entries — did you mean \`minItems\`?`, [17]));
|
|
385
|
+
}
|
|
386
|
+
if (field['maximum'] !== undefined && primitive === 'array') {
|
|
387
|
+
refusals.push(memberRefusal(document, owner, 'maximum', `\`maximum\` bounds a value; field \`${fieldId}\` is a list of entries — did you mean \`maxItems\`?`, [17]));
|
|
388
|
+
}
|
|
389
|
+
if (field['minLength'] !== undefined && primitive !== 'string') {
|
|
390
|
+
refusals.push(memberRefusal(document, owner, 'minLength', `\`minLength\` counts the characters of a string; field \`${fieldId}\` is ${articleForPrimitive(primitive)} ${String(primitive)} value${primitive === 'array' ? ' — did you mean `minItems`?' : ''}`, [22]));
|
|
391
|
+
}
|
|
392
|
+
if (field['maxLength'] !== undefined && primitive !== 'string') {
|
|
393
|
+
refusals.push(memberRefusal(document, owner, 'maxLength', `\`maxLength\` counts the characters of a string; field \`${fieldId}\` is ${articleForPrimitive(primitive)} ${String(primitive)} value${primitive === 'array' ? ' — did you mean `maxItems`?' : ''}`, [22]));
|
|
394
|
+
}
|
|
395
|
+
visitFields(listAt(field, 'fields'), [...owner, 'fields']);
|
|
396
|
+
});
|
|
397
|
+
};
|
|
398
|
+
visitFields(listAt(document, 'fields'), ['fields']);
|
|
399
|
+
// A context root declares the same value domain a field does, `CTX-3.1.6`, so the same
|
|
400
|
+
// units/unit/pair checks apply. The root's value comes from the host, which makes an
|
|
401
|
+
// unenforceable domain the one claim a reader cannot repair later.
|
|
402
|
+
const context = document['context'];
|
|
403
|
+
if (isRecord(context)) {
|
|
404
|
+
listAt(context, 'roots').forEach((root, index) => {
|
|
405
|
+
if (!isRecord(root))
|
|
406
|
+
return;
|
|
407
|
+
const owner = ['context', 'roots', index];
|
|
408
|
+
const primitive = textAt(root, 'primitive');
|
|
409
|
+
const path = textAt(root, 'path') ?? '$';
|
|
410
|
+
const label = `context root \`${path}\``;
|
|
411
|
+
moneyDomainRefusals(document, owner, root, primitive, label, refusals);
|
|
412
|
+
quantityUnitsRefusals(document, owner, root, primitive, label, refusals);
|
|
413
|
+
durationUnitRefusals(document, owner, root, primitive, label, refusals);
|
|
414
|
+
const items = root['items'];
|
|
415
|
+
if (isRecord(items)) {
|
|
416
|
+
quantityUnitsRefusals(document, [...owner, 'items'], items, textAt(items, 'primitive'), `item declaration of ${label}`, refusals);
|
|
417
|
+
durationUnitRefusals(document, [...owner, 'items'], items, textAt(items, 'primitive'), `item declaration of ${label}`, refusals);
|
|
418
|
+
}
|
|
419
|
+
});
|
|
420
|
+
}
|
|
421
|
+
listAt(document, 'rules').forEach((rule, index) => {
|
|
422
|
+
if (!isRecord(rule))
|
|
423
|
+
return;
|
|
424
|
+
const kind = textAt(rule, 'kind');
|
|
425
|
+
if (kind === undefined)
|
|
426
|
+
return;
|
|
427
|
+
const owner = ['rules', index];
|
|
428
|
+
// A note is documentation, and documentation that states nothing is noise: a blank note
|
|
429
|
+
// would sit in the artifact as an empty explanation, and one past the bound is an essay
|
|
430
|
+
// where the contract admits a note. Both are refused at the member with the bound stated.
|
|
431
|
+
const note = rule['note'];
|
|
432
|
+
if (typeof note === 'string') {
|
|
433
|
+
const trimmed = note.trim();
|
|
434
|
+
const ruleId = textAt(rule, 'ruleId') ?? `$.rules[${String(index)}]`;
|
|
435
|
+
if (trimmed === '') {
|
|
436
|
+
refusals.push(memberRefusal(document, owner, 'note', `a \`note\` documents why rule \`${ruleId}\` exists; this one is blank after trimming, so it documents nothing — write the reason in 1 to 500 characters, or remove \`note\``, []));
|
|
437
|
+
}
|
|
438
|
+
else {
|
|
439
|
+
const length = Array.from(trimmed).length;
|
|
440
|
+
if (length > 500) {
|
|
441
|
+
refusals.push(memberRefusal(document, owner, 'note', `a \`note\` documents why rule \`${ruleId}\` exists in 1 to 500 characters after trimming; this one is ${String(length)} — shorten it to the reason, or move the explanation to the authoring file`, []));
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
if (rule['fieldIds'] !== undefined && kind !== 'visible' && kind !== 'enabled') {
|
|
446
|
+
refusals.push(memberRefusal(document, owner, 'fieldIds', `\`fieldIds\` is admitted only on a \`visible\` or \`enabled\` record-scoped rule, which decides several targets at once; a \`${kind}\` rule decides one field in \`fieldId\`, so remove \`fieldIds\`, or declare a record-scoped \`visible\` or \`enabled\` rule`, [9, 10]));
|
|
447
|
+
}
|
|
448
|
+
if (rule['reasons'] !== undefined && kind !== 'screen') {
|
|
449
|
+
refusals.push(memberRefusal(document, owner, 'reasons', `\`reasons\` is admitted only on a \`screen\` rule, where each reason is a declared screen outcome; a \`${kind}\` rule raises one message, so remove \`reasons\`, or declare the rule as \`kind: "screen"\``, [5]));
|
|
450
|
+
}
|
|
451
|
+
if (rule['gate'] !== undefined && kind !== 'gate') {
|
|
452
|
+
refusals.push(memberRefusal(document, owner, 'gate', `\`gate\` is admitted only on a \`gate\` rule; a \`${kind}\` rule's expression is its own condition, so remove \`gate\`, or declare the rule as \`kind: "gate"\``, [7]));
|
|
453
|
+
}
|
|
454
|
+
// A verdict names a failure a host can clear; a kind that states a branch decides nothing a
|
|
455
|
+
// host could act on, so an alternative to it names no failure. The metaschema admits the member
|
|
456
|
+
// on every rule because the kind is one `if` away; the refusal is here, where the kind is known.
|
|
457
|
+
if (rule['suggests'] !== undefined && kind !== 'validate') {
|
|
458
|
+
refusals.push(memberRefusal(document, owner, 'suggests', `\`suggests\` is admitted only on a \`validate\` rule, where each alternative names a change set that clears the failure; a \`${kind}\` rule states a branch rather than a verdict, so an alternative to it names nothing a host could offer — remove \`suggests\`, or declare the rule as \`kind: "validate"\``, []));
|
|
459
|
+
}
|
|
460
|
+
// An alternative set that holds nothing offers nothing, and an alternative with no operation
|
|
461
|
+
// writes nothing (`RULES-6.1.1`). The metaschema states both as `minItems`, whose generic
|
|
462
|
+
// sentence names no repair; the two refusals below state it, at the member an author can fill.
|
|
463
|
+
// Only a `validate` rule reaches them: the member is refused outright on every other kind, and
|
|
464
|
+
// one cause must not be reported twice.
|
|
465
|
+
const suggests = rule['suggests'];
|
|
466
|
+
if (kind === 'validate' && Array.isArray(suggests)) {
|
|
467
|
+
const listedRuleId = textAt(rule, 'ruleId') ?? `$.rules[${String(index)}]`;
|
|
468
|
+
if (suggests.length === 0) {
|
|
469
|
+
refusals.push(locatedRefusal(document, [...owner, 'suggests'], `rule \`${listedRuleId}\` declares \`suggests\` with no alternative; an alternative set with nothing in it offers a host nothing, so state one alternative with its \`labelKey\` and the operations that clear the failure, or remove \`suggests\``));
|
|
470
|
+
}
|
|
471
|
+
suggests.forEach((entry, suggestionIndex) => {
|
|
472
|
+
if (!isRecord(entry))
|
|
473
|
+
return;
|
|
474
|
+
const operations = entry['operations'];
|
|
475
|
+
if (!Array.isArray(operations) || operations.length > 0)
|
|
476
|
+
return;
|
|
477
|
+
refusals.push(locatedRefusal(document, [...owner, 'suggests', suggestionIndex, 'operations'], `alternative ${String(suggestionIndex + 1)} of rule \`${listedRuleId}\` declares no operation; an alternative that writes nothing offers a host nothing, so state at least one \`value\`, \`null\`, \`remove\`, \`append\` or \`removeRow\` operation, or remove the alternative`));
|
|
478
|
+
});
|
|
479
|
+
}
|
|
480
|
+
// `ACCESS-6.1.2`: a hard gate always blocks, so it declares no read-only policy. A policy it
|
|
481
|
+
// did declare could only be ignored, while still taking part in the rule's hash — an author
|
|
482
|
+
// who wrote `warn` would believe the gate can let a refusal through.
|
|
483
|
+
const gate = rule['gate'];
|
|
484
|
+
if (kind === 'gate' &&
|
|
485
|
+
isRecord(gate) &&
|
|
486
|
+
gate['hard'] === true &&
|
|
487
|
+
gate['onReadOnlyError'] !== undefined) {
|
|
488
|
+
refusals.push(memberRefusal(document, [...owner, 'gate'], 'onReadOnlyError', `\`onReadOnlyError\` is admitted only on a non-hard gate: a hard gate always blocks, so it declares no read-only policy; remove \`onReadOnlyError\` from gate \`${textAt(rule, 'ruleId') ?? '$'}\`, or set \`"hard": false\``, []));
|
|
489
|
+
}
|
|
490
|
+
});
|
|
491
|
+
return refusals;
|
|
492
|
+
}
|
|
493
|
+
/** A stable key for one `options[].code`, which the metaschema admits as a string or an integer. */
|
|
494
|
+
function optionCodeKey(code) {
|
|
495
|
+
return `${typeof code}:${String(code)}`;
|
|
496
|
+
}
|
|
497
|
+
/** Every field a `compute` or `defaultCompute` rule writes. */
|
|
498
|
+
function computedFieldIds(document) {
|
|
499
|
+
const computed = new Set();
|
|
500
|
+
for (const rule of listAt(document, 'rules')) {
|
|
501
|
+
if (!isRecord(rule))
|
|
502
|
+
continue;
|
|
503
|
+
const kind = textAt(rule, 'kind');
|
|
504
|
+
if (kind === undefined || !WRITER_KINDS.has(kind))
|
|
505
|
+
continue;
|
|
506
|
+
const fieldId = textAt(rule, 'fieldId');
|
|
507
|
+
if (fieldId !== undefined)
|
|
508
|
+
computed.add(fieldId);
|
|
509
|
+
}
|
|
510
|
+
return computed;
|
|
511
|
+
}
|
|
512
|
+
/** How a refusal names the declaration a writer produces, and the array whose row holds it. */
|
|
513
|
+
function describeTarget(declared, fieldId) {
|
|
514
|
+
const array = declared.get(fieldId)?.rowArray;
|
|
515
|
+
return array === undefined ? `\`${fieldId}\`` : `\`${fieldId}\`, a member of array \`${array}\``;
|
|
516
|
+
}
|
|
517
|
+
/**
|
|
518
|
+
* Two rules writing one field must be refused rather than resolved by position: the report
|
|
519
|
+
* would otherwise carry two values for one field and the host would have to pick the one it
|
|
520
|
+
* read first.
|
|
521
|
+
*
|
|
522
|
+
* A writer is keyed by the declaration whose value it produces: two item writers of one array
|
|
523
|
+
* may write different members, and each owns its own. A writer of a container owns everything
|
|
524
|
+
* the container holds, because the container's value carries its members — so a container
|
|
525
|
+
* writer and a writer of one of its members are two writers of one value, whether the
|
|
526
|
+
* container is a record or the row member an item writer addresses.
|
|
527
|
+
*/
|
|
528
|
+
function duplicateWriters(document, declared) {
|
|
529
|
+
const diagnostics = [];
|
|
530
|
+
const writers = [];
|
|
531
|
+
listAt(document, 'rules').forEach((rule, index) => {
|
|
532
|
+
if (!isRecord(rule))
|
|
533
|
+
return;
|
|
534
|
+
const kind = textAt(rule, 'kind');
|
|
535
|
+
if (kind === undefined || !WRITER_KINDS.has(kind))
|
|
536
|
+
return;
|
|
537
|
+
const fieldId = textAt(rule, 'fieldId');
|
|
538
|
+
if (fieldId === undefined)
|
|
539
|
+
return;
|
|
540
|
+
const itemTarget = textAt(rule, 'scope') === 'item' ? textAt(rule, 'targetFieldId') : undefined;
|
|
541
|
+
// A target-less item writer is refused for the missing target; keying it here as well
|
|
542
|
+
// would report a second defect for the one cause.
|
|
543
|
+
if (textAt(rule, 'scope') === 'item' && itemTarget === undefined)
|
|
544
|
+
return;
|
|
545
|
+
// A writer outside `item` scope that names a row member is refused by
|
|
546
|
+
// `writerRowMemberDiagnostics` for the same reason: one cause, one refusal.
|
|
547
|
+
if (textAt(rule, 'scope') !== 'item' && declared.get(fieldId)?.rowArray !== undefined) {
|
|
548
|
+
return;
|
|
549
|
+
}
|
|
550
|
+
const ruleId = textAt(rule, 'ruleId') ?? `$.rules[${String(index)}]`;
|
|
551
|
+
writers.push({
|
|
552
|
+
index,
|
|
553
|
+
ruleId,
|
|
554
|
+
written: itemTarget ?? fieldId,
|
|
555
|
+
member: itemTarget === undefined ? 'fieldId' : 'targetFieldId',
|
|
556
|
+
});
|
|
557
|
+
});
|
|
558
|
+
// The duplicate is the first earlier writer of the same declaration, of an ancestor of it, or
|
|
559
|
+
// of a descendant of it. Indexing the writers already seen by what they write — and each
|
|
560
|
+
// writer under the ancestors it sits below — answers those three questions with a handful of
|
|
561
|
+
// map hits. Comparing every writer with every earlier one made the check the writers squared,
|
|
562
|
+
// and a document of computed columns is exactly where that showed.
|
|
563
|
+
const firstByWritten = new Map();
|
|
564
|
+
const firstBelow = new Map();
|
|
565
|
+
writers.forEach((writer) => {
|
|
566
|
+
const ancestors = declared.get(writer.written)?.ancestors ?? [];
|
|
567
|
+
let earlier;
|
|
568
|
+
const take = (candidate) => {
|
|
569
|
+
if (candidate === undefined)
|
|
570
|
+
return;
|
|
571
|
+
if (earlier === undefined || candidate.index < earlier.index)
|
|
572
|
+
earlier = candidate;
|
|
573
|
+
};
|
|
574
|
+
take(firstByWritten.get(writer.written));
|
|
575
|
+
for (const ancestor of ancestors)
|
|
576
|
+
take(firstByWritten.get(ancestor));
|
|
577
|
+
take(firstBelow.get(writer.written));
|
|
578
|
+
// Registered after the lookup so a writer never matches itself, and only when absent so
|
|
579
|
+
// each map keeps the earliest writer that states the fact.
|
|
580
|
+
noteWriterComparison();
|
|
581
|
+
if (!firstByWritten.has(writer.written))
|
|
582
|
+
firstByWritten.set(writer.written, writer);
|
|
583
|
+
for (const ancestor of ancestors) {
|
|
584
|
+
if (!firstBelow.has(ancestor))
|
|
585
|
+
firstBelow.set(ancestor, writer);
|
|
586
|
+
}
|
|
587
|
+
if (earlier === undefined)
|
|
588
|
+
return;
|
|
589
|
+
const container = earlier.written === writer.written
|
|
590
|
+
? undefined
|
|
591
|
+
: ancestors.includes(earlier.written)
|
|
592
|
+
? earlier.written
|
|
593
|
+
: writer.written;
|
|
594
|
+
// The report names the second writer, because that is the declaration the author can
|
|
595
|
+
// move or delete; the detail names both spells and which one holds the other.
|
|
596
|
+
const earlierHolds = container !== undefined && earlier.written === container;
|
|
597
|
+
const containerRule = earlierHolds ? earlier : writer;
|
|
598
|
+
const memberRule = earlierHolds ? writer : earlier;
|
|
599
|
+
diagnostics.push({
|
|
600
|
+
code: 'DUPLICATE_WRITER',
|
|
601
|
+
path: `$.rules[${String(writer.index)}].${writer.member}`,
|
|
602
|
+
detail: container === undefined
|
|
603
|
+
? `rule \`${writer.ruleId}\` and rule \`${earlier.ruleId}\` both write ${describeTarget(declared, writer.written)}; one rule owns each value, so a second writer is a compile error`
|
|
604
|
+
: `rule \`${containerRule.ruleId}\` writes ${describeTarget(declared, containerRule.written)} and owns everything the container holds, while rule \`${memberRule.ruleId}\` writes ${describeTarget(declared, memberRule.written)}, which the container's value carries; one rule owns each value, so a container writer and a member writer cannot both exist`,
|
|
605
|
+
});
|
|
606
|
+
});
|
|
607
|
+
return diagnostics;
|
|
608
|
+
}
|
|
609
|
+
/**
|
|
610
|
+
* Every declared fieldId in the document, nested declarations included.
|
|
611
|
+
*/
|
|
612
|
+
function declaredFieldIds(document) {
|
|
613
|
+
const ids = new Set();
|
|
614
|
+
const visit = (fields) => {
|
|
615
|
+
for (const field of fields) {
|
|
616
|
+
if (!isRecord(field))
|
|
617
|
+
continue;
|
|
618
|
+
const fieldId = textAt(field, 'fieldId');
|
|
619
|
+
if (fieldId !== undefined)
|
|
620
|
+
ids.add(fieldId);
|
|
621
|
+
visit(listAt(field, 'fields'));
|
|
622
|
+
}
|
|
623
|
+
};
|
|
624
|
+
visit(listAt(document, 'fields'));
|
|
625
|
+
return ids;
|
|
626
|
+
}
|
|
627
|
+
/**
|
|
628
|
+
* The array each row-scoped declaration belongs to, keyed by `fieldId`.
|
|
629
|
+
*
|
|
630
|
+
* A member of an `array` is only readable with the row it belongs to, so a `covers` entry —
|
|
631
|
+
* which carries no `rowKey` — cannot name it: the one stored target that could satisfy the
|
|
632
|
+
* declaration reads nothing. The container is the declaration that binds the whole list.
|
|
633
|
+
*/
|
|
634
|
+
function arrayMemberDeclarations(document) {
|
|
635
|
+
const containers = new Map();
|
|
636
|
+
const visit = (fields, inside) => {
|
|
637
|
+
for (const field of fields) {
|
|
638
|
+
if (!isRecord(field))
|
|
639
|
+
continue;
|
|
640
|
+
const fieldId = textAt(field, 'fieldId');
|
|
641
|
+
if (fieldId !== undefined && inside !== undefined)
|
|
642
|
+
containers.set(fieldId, inside);
|
|
643
|
+
const container = textAt(field, 'primitive') === 'array' ? (fieldId ?? inside) : inside;
|
|
644
|
+
visit(listAt(field, 'fields'), container);
|
|
645
|
+
}
|
|
646
|
+
};
|
|
647
|
+
visit(listAt(document, 'fields'), undefined);
|
|
648
|
+
return containers;
|
|
649
|
+
}
|
|
650
|
+
/**
|
|
651
|
+
* The coverage a `signature_capture` field declares.
|
|
652
|
+
*
|
|
653
|
+
* A signature binds values, so its declared coverage has to name values this document
|
|
654
|
+
* declares, and it must not name the signature itself: the value behind that target contains
|
|
655
|
+
* the digest of the coverage, so covering it would make the binding depend on its own result.
|
|
656
|
+
* A target declared inside an array is refused for the same kind of reason: a declaration
|
|
657
|
+
* names a field and never a row, so the container is the only target that can bind its rows.
|
|
658
|
+
* The absent and the empty list are refused by the closed metaschema before this check runs —
|
|
659
|
+
* a `signature_capture` field must declare at least one target. Whether the
|
|
660
|
+
* `digest(...)` the artifact verifies the signature with binds the same targets is checked
|
|
661
|
+
* where expressions are compiled, because a target list is an expression and this pass reads
|
|
662
|
+
* declarations only.
|
|
663
|
+
*/
|
|
664
|
+
function signatureCoverageDiagnostics(document) {
|
|
665
|
+
const diagnostics = [];
|
|
666
|
+
const declared = declaredFieldIds(document);
|
|
667
|
+
const arrayMembers = arrayMemberDeclarations(document);
|
|
668
|
+
const visit = (fields, path, ancestors) => {
|
|
669
|
+
fields.forEach((field, index) => {
|
|
670
|
+
if (!isRecord(field))
|
|
671
|
+
return;
|
|
672
|
+
const at = `${path}[${String(index)}]`;
|
|
673
|
+
const fieldId = textAt(field, 'fieldId');
|
|
674
|
+
listAt(field, 'covers').forEach((target, targetIndex) => {
|
|
675
|
+
if (typeof target !== 'string')
|
|
676
|
+
return;
|
|
677
|
+
const targetAt = `${at}.covers[${String(targetIndex)}]`;
|
|
678
|
+
if (target === fieldId) {
|
|
679
|
+
diagnostics.push({
|
|
680
|
+
code: 'SIGNATURE_COVERAGE',
|
|
681
|
+
path: targetAt,
|
|
682
|
+
detail: `signature field \`${target}\` covers itself; a signature cannot bind the value that carries its own digest`,
|
|
683
|
+
});
|
|
684
|
+
return;
|
|
685
|
+
}
|
|
686
|
+
if (ancestors.includes(target)) {
|
|
687
|
+
diagnostics.push({
|
|
688
|
+
code: 'SIGNATURE_COVERAGE',
|
|
689
|
+
path: targetAt,
|
|
690
|
+
detail: `signature field \`${fieldId ?? at}\` is declared inside \`${target}\` and cannot cover its own container; a signature cannot bind the value that carries its own digest`,
|
|
691
|
+
});
|
|
692
|
+
return;
|
|
693
|
+
}
|
|
694
|
+
if (!declared.has(target)) {
|
|
695
|
+
diagnostics.push({
|
|
696
|
+
code: 'SIGNATURE_COVERAGE',
|
|
697
|
+
path: targetAt,
|
|
698
|
+
detail: `covers \`${target}\`, which this document does not declare; a signature can only bind the values of a declared field`,
|
|
699
|
+
});
|
|
700
|
+
return;
|
|
701
|
+
}
|
|
702
|
+
const container = arrayMembers.get(target);
|
|
703
|
+
if (container === undefined)
|
|
704
|
+
return;
|
|
705
|
+
diagnostics.push({
|
|
706
|
+
code: 'SIGNATURE_COVERAGE',
|
|
707
|
+
path: targetAt,
|
|
708
|
+
detail: `covers \`${target}\`, a member of the array \`${container}\`; a declared target names a field, never a row, so declare \`${container}\` itself — its value is the whole list`,
|
|
709
|
+
});
|
|
710
|
+
});
|
|
711
|
+
const nextAncestors = fieldId === undefined ? ancestors : [...ancestors, fieldId];
|
|
712
|
+
visit(listAt(field, 'fields'), `${at}.fields`, nextAncestors);
|
|
713
|
+
});
|
|
714
|
+
};
|
|
715
|
+
visit(listAt(document, 'fields'), '$.fields', []);
|
|
716
|
+
return diagnostics;
|
|
717
|
+
}
|
|
718
|
+
/**
|
|
719
|
+
* Refuses a writer or a `required` rule outside `item` scope that names a row member,
|
|
720
|
+
* `RULES-1.1.4` `RULES-1.1.11`.
|
|
721
|
+
*
|
|
722
|
+
* A member of an array holds one value per row and none of its own, so a `field`- or
|
|
723
|
+
* `record`-scoped writer naming it cannot say which row's value it produced, and a
|
|
724
|
+
* `field`-scoped requirement cannot say which row it constrains — its expression runs once
|
|
725
|
+
* against the record and the row facts never see it. `item` scope with `targetFieldId` is the
|
|
726
|
+
* one spelling of both in v1, and a writer of the container itself is the other; both are named
|
|
727
|
+
* in the refusal so the author has a repair.
|
|
728
|
+
*/
|
|
729
|
+
function writerRowMemberDiagnostics(rule, at, ruleId, sites) {
|
|
730
|
+
const kind = textAt(rule, 'kind');
|
|
731
|
+
if (kind === undefined || !ROW_MEMBER_FORBIDDEN_KINDS.has(kind))
|
|
732
|
+
return [];
|
|
733
|
+
const scope = textAt(rule, 'scope');
|
|
734
|
+
if (scope === undefined || scope === 'item')
|
|
735
|
+
return [];
|
|
736
|
+
const fieldId = textAt(rule, 'fieldId');
|
|
737
|
+
if (fieldId === undefined)
|
|
738
|
+
return [];
|
|
739
|
+
const array = sites.get(fieldId)?.rowArray;
|
|
740
|
+
if (array === undefined)
|
|
741
|
+
return [];
|
|
742
|
+
const detail = kind === 'required'
|
|
743
|
+
? `rule \`${ruleId}\` constrains \`${fieldId}\`, a member of array \`${array}\`, at \`${scope}\` scope; a requirement that holds once per row is stated by an \`item\`-scoped rule, so declare \`scope: "item"\` with \`fieldId: "${array}"\` and \`targetFieldId: "${fieldId}"\``
|
|
744
|
+
: `rule \`${ruleId}\` writes \`${fieldId}\`, a member of array \`${array}\`, at \`${scope}\` scope; a value that exists once per row is written by an \`item\`-scoped rule, so declare \`scope: "item"\` with \`fieldId: "${array}"\` and \`targetFieldId: "${fieldId}"\`, or write the container \`${array}\` itself`;
|
|
745
|
+
return [{ code: 'INVALID_RULE_SCOPE', path: `${at}.fieldId`, detail }];
|
|
746
|
+
}
|
|
747
|
+
/**
|
|
748
|
+
* Whether one `item`-scope rule declares the target the contract admits, `RULES-1.1.11`.
|
|
749
|
+
*
|
|
750
|
+
* An item writer, `required` or `enabled` rule must name the direct member of the row it
|
|
751
|
+
* writes or constrains, and that array must be top level in v1: a row identity nested inside
|
|
752
|
+
* another array is a composite target this version does not state, so the rule is refused
|
|
753
|
+
* rather than left to write a row no report can address. A `validate` rule may omit the
|
|
754
|
+
* target and speak about the row as a whole.
|
|
755
|
+
*/
|
|
756
|
+
function itemScopeDiagnostics(rule, at, ruleId, sites) {
|
|
757
|
+
if (textAt(rule, 'scope') !== 'item')
|
|
758
|
+
return [];
|
|
759
|
+
const fieldId = textAt(rule, 'fieldId');
|
|
760
|
+
if (fieldId === undefined)
|
|
761
|
+
return [];
|
|
762
|
+
const site = sites.get(fieldId);
|
|
763
|
+
if (site === undefined || textAt(site.field, 'primitive') !== 'array')
|
|
764
|
+
return [];
|
|
765
|
+
if (site.arrays.length > 0) {
|
|
766
|
+
return [
|
|
767
|
+
{
|
|
768
|
+
code: 'INVALID_RULE_SCOPE',
|
|
769
|
+
path: `${at}.fieldId`,
|
|
770
|
+
detail: NESTED_ITEM_ARRAY_DETAIL,
|
|
771
|
+
},
|
|
772
|
+
];
|
|
773
|
+
}
|
|
774
|
+
// An array a record holds is declared, but not at the top level the clause requires: its
|
|
775
|
+
// rows sit on a declaration path inside that record. Refused here rather than left to the
|
|
776
|
+
// expression pass, which would report the id as an undeclared array and so name neither the
|
|
777
|
+
// real cause nor a repair.
|
|
778
|
+
const container = site.ancestors[site.ancestors.length - 1];
|
|
779
|
+
if (container !== undefined) {
|
|
780
|
+
return [
|
|
781
|
+
{
|
|
782
|
+
code: 'INVALID_RULE_SCOPE',
|
|
783
|
+
path: `${at}.fieldId`,
|
|
784
|
+
detail: `rule \`${ruleId}\` is item-scoped on \`${fieldId}\`, which \`${container}\` holds; an item-scoped rule addresses a top-level array in v1, so declare this array at the top level or remove the item-scoped rule`,
|
|
785
|
+
},
|
|
786
|
+
];
|
|
787
|
+
}
|
|
788
|
+
const kind = textAt(rule, 'kind');
|
|
789
|
+
const targetFieldId = textAt(rule, 'targetFieldId');
|
|
790
|
+
if (targetFieldId === undefined) {
|
|
791
|
+
if (kind === undefined || !ITEM_TARGET_KINDS.has(kind))
|
|
792
|
+
return [];
|
|
793
|
+
const verb = kind === 'required' || kind === 'enabled' ? 'constrains' : 'writes';
|
|
794
|
+
return [
|
|
795
|
+
{
|
|
796
|
+
code: 'INVALID_RULE_SCOPE',
|
|
797
|
+
path: `${at}.targetFieldId`,
|
|
798
|
+
detail: `rule \`${ruleId}\` is a \`${kind}\` rule at \`item\` scope and declares no \`targetFieldId\`; an item-scoped \`${kind}\` rule must declare the row member it ${verb}`,
|
|
799
|
+
},
|
|
800
|
+
];
|
|
801
|
+
}
|
|
802
|
+
const members = listAt(site.field, 'fields').filter(isRecord);
|
|
803
|
+
if (!members.some((member) => textAt(member, 'fieldId') === targetFieldId)) {
|
|
804
|
+
const targetSite = sites.get(targetFieldId);
|
|
805
|
+
// A target reached through an array inside this array's row is the nested case the
|
|
806
|
+
// clause names once: the boundary, not the member, is what an author has to move.
|
|
807
|
+
const crossesInnerArray = targetSite !== undefined &&
|
|
808
|
+
targetSite.rowArray !== undefined &&
|
|
809
|
+
targetSite.rowArray !== fieldId &&
|
|
810
|
+
targetSite.arrays.includes(fieldId);
|
|
811
|
+
return [
|
|
812
|
+
{
|
|
813
|
+
code: 'INVALID_RULE_SCOPE',
|
|
814
|
+
path: `${at}.targetFieldId`,
|
|
815
|
+
detail: crossesInnerArray
|
|
816
|
+
? NESTED_ITEM_ARRAY_DETAIL
|
|
817
|
+
: `rule \`${ruleId}\` names \`${targetFieldId}\` as its target, which is not a direct member of array \`${fieldId}\`; an item-scoped rule writes or constrains one member declared on that array's item declaration`,
|
|
818
|
+
},
|
|
819
|
+
];
|
|
820
|
+
}
|
|
821
|
+
// A natural key identifies the row rather than holding a value a rule has any business
|
|
822
|
+
// writing or constraining, so targeting it would let a rule rewrite row identity.
|
|
823
|
+
const rowKey = isRecord(site.field['rowKey']) ? site.field['rowKey'] : undefined;
|
|
824
|
+
if (rowKey !== undefined &&
|
|
825
|
+
textAt(rowKey, 'mode') === 'natural' &&
|
|
826
|
+
textAt(rowKey, 'fieldId') === targetFieldId) {
|
|
827
|
+
return [
|
|
828
|
+
{
|
|
829
|
+
code: 'INVALID_RULE_SCOPE',
|
|
830
|
+
path: `${at}.targetFieldId`,
|
|
831
|
+
detail: `rule \`${ruleId}\` targets \`${targetFieldId}\`, the natural row key of array \`${fieldId}\`; a row key identifies the row and cannot be written or constrained by an item-scoped rule`,
|
|
832
|
+
},
|
|
833
|
+
];
|
|
834
|
+
}
|
|
835
|
+
// A `defaultCompute` keeps a stored value only while a companion is active, and an item
|
|
836
|
+
// writer's companion is read as `$it.<overrideFieldId>`: a top-level record would be
|
|
837
|
+
// invisible to that read, so the authority would silently never apply.
|
|
838
|
+
if (kind === 'defaultCompute') {
|
|
839
|
+
const override = textAt(rule, 'overrideFieldId');
|
|
840
|
+
if (override !== undefined &&
|
|
841
|
+
!members.some((member) => textAt(member, 'fieldId') === override)) {
|
|
842
|
+
return [
|
|
843
|
+
{
|
|
844
|
+
code: 'INVALID_RULE_SCOPE',
|
|
845
|
+
path: `${at}.overrideFieldId`,
|
|
846
|
+
detail: `rule \`${ruleId}\` names \`${override}\` as its \`overrideFieldId\`, which is not a direct member of array \`${fieldId}\`; an item-scoped \`defaultCompute\` keeps its stored value through a companion member of the same row`,
|
|
847
|
+
},
|
|
848
|
+
];
|
|
849
|
+
}
|
|
850
|
+
}
|
|
851
|
+
return [];
|
|
852
|
+
}
|
|
853
|
+
/** Whether a field's governed annotations mark it deprecated, `EVOL-3.1.3`. */
|
|
854
|
+
function isDeprecated(field) {
|
|
855
|
+
const annotations = field?.['annotations'];
|
|
856
|
+
return isRecord(annotations) && annotations['deprecated'] === true;
|
|
857
|
+
}
|
|
858
|
+
/** The primitives that admit a value bound, `MODEL-2.1.16`. */
|
|
859
|
+
const BOUNDED_PRIMITIVES = new Set([
|
|
860
|
+
'integer',
|
|
861
|
+
'decimal',
|
|
862
|
+
'money',
|
|
863
|
+
'date',
|
|
864
|
+
'instant',
|
|
865
|
+
'time',
|
|
866
|
+
'quantity',
|
|
867
|
+
]);
|
|
868
|
+
/** The text a bound is stated in: canonical decimal text for a decimal field, else the value. */
|
|
869
|
+
function boundText(bound) {
|
|
870
|
+
return typeof bound === 'string' ? bound : String(bound);
|
|
871
|
+
}
|
|
872
|
+
/**
|
|
873
|
+
* Whether `minimum` does not exceed `maximum` in the field's own domain.
|
|
874
|
+
*
|
|
875
|
+
* A `decimal` field states its bounds as canonical decimal text, and text does not compare the
|
|
876
|
+
* way numbers do (`"10"` sorts before `"2"`), so the two spellings are parsed before the one
|
|
877
|
+
* comparison. Every other bounded primitive compares its own domain: numbers numerically, and
|
|
878
|
+
* canonical date/instant text lexicographically because the spelling is fixed-width.
|
|
879
|
+
*/
|
|
880
|
+
function boundsAreOrdered(primitive, minimum, maximum) {
|
|
881
|
+
if (primitive === 'decimal' || primitive === 'quantity') {
|
|
882
|
+
const low = tryDecimalString(boundText(minimum));
|
|
883
|
+
const high = tryDecimalString(boundText(maximum));
|
|
884
|
+
if (low !== undefined && high !== undefined)
|
|
885
|
+
return compareDecimalTexts(low, high) <= 0;
|
|
886
|
+
}
|
|
887
|
+
return ((typeof minimum === 'number' && typeof maximum === 'number' && minimum <= maximum) ||
|
|
888
|
+
(typeof minimum === 'string' && typeof maximum === 'string' && minimum <= maximum));
|
|
889
|
+
}
|
|
890
|
+
/**
|
|
891
|
+
* The declaration members that compile down to a rule, checked where a JSON Schema keyword
|
|
892
|
+
* cannot state the relation: the member only means something on one kind of field, and a pair
|
|
893
|
+
* of bounds only means something in order.
|
|
894
|
+
*
|
|
895
|
+
* The refusal names the member and the field's kind, because `minItems` on a scalar and
|
|
896
|
+
* `minimum` on an array are the two mistakes the vocabulary invites. A member silently ignored
|
|
897
|
+
* would ship a form whose authored bound never ran.
|
|
898
|
+
*/
|
|
899
|
+
function declarationMemberDiagnostics(document, declared) {
|
|
900
|
+
const diagnostics = [];
|
|
901
|
+
const refuseAt = (path, detail, code = 'SCHEMA_INVALID') => {
|
|
902
|
+
diagnostics.push({ code, path, detail });
|
|
903
|
+
};
|
|
904
|
+
for (const declaration of declared.values()) {
|
|
905
|
+
const field = declaration.field;
|
|
906
|
+
const primitive = textAt(field, 'primitive');
|
|
907
|
+
const at = declaration.path;
|
|
908
|
+
const fieldId = textAt(field, 'fieldId') ?? at;
|
|
909
|
+
const isArray = primitive === 'array';
|
|
910
|
+
const arrayInsideArray = declaration.rowArray !== undefined;
|
|
911
|
+
const itemMember = declaration.rowArray !== undefined;
|
|
912
|
+
if (typeof field['minLength'] === 'number' &&
|
|
913
|
+
typeof field['maxLength'] === 'number' &&
|
|
914
|
+
field['minLength'] > field['maxLength']) {
|
|
915
|
+
refuseAt(`${at}.minLength`, `\`minLength\` is ${String(field['minLength'])} and \`maxLength\` is ${String(field['maxLength'])} on field \`${fieldId}\`; a string cannot need more characters than it permits — set \`minLength\` at or below \`maxLength\``);
|
|
916
|
+
}
|
|
917
|
+
if (field['required'] === true && field['requiredWhen'] !== undefined) {
|
|
918
|
+
refuseAt(`${at}.requiredWhen`, `field \`${fieldId}\` states both \`required: true\` and \`requiredWhen\`; state one requirement, because two rules with one id would make the report ambiguous — use \`requiredWhen\` for a condition, or \`required: true\` for none`);
|
|
919
|
+
}
|
|
920
|
+
if ((field['minimum'] !== undefined || field['maximum'] !== undefined) &&
|
|
921
|
+
primitive !== undefined &&
|
|
922
|
+
!isArray &&
|
|
923
|
+
!BOUNDED_PRIMITIVES.has(primitive)) {
|
|
924
|
+
for (const member of ['minimum', 'maximum']) {
|
|
925
|
+
if (field[member] === undefined)
|
|
926
|
+
continue;
|
|
927
|
+
refuseAt(`${at}.${member}`, `\`${member}\` bounds the value of a numeric or date field; field \`${fieldId}\` is ${articleForPrimitive(primitive)} ${primitive} value, so it declares no \`${member}\``);
|
|
928
|
+
}
|
|
929
|
+
}
|
|
930
|
+
const minItems = field['minItems'];
|
|
931
|
+
const maxItems = field['maxItems'];
|
|
932
|
+
if (typeof minItems === 'number' &&
|
|
933
|
+
typeof maxItems === 'number' &&
|
|
934
|
+
Number.isSafeInteger(minItems) &&
|
|
935
|
+
Number.isSafeInteger(maxItems) &&
|
|
936
|
+
minItems > maxItems) {
|
|
937
|
+
refuseAt(`${at}.minItems`, `\`minItems\` is ${String(minItems)} and \`maxItems\` is ${String(maxItems)} on field \`${fieldId}\`; a list cannot need more entries than it permits — set \`minItems\` at or below \`maxItems\``);
|
|
938
|
+
}
|
|
939
|
+
const minimum = field['minimum'];
|
|
940
|
+
const maximum = field['maximum'];
|
|
941
|
+
if (minimum !== undefined && maximum !== undefined) {
|
|
942
|
+
// A validated document states both bounds in the field's own domain, so one comparison is
|
|
943
|
+
// enough: decimal text compares numerically, other numbers numerically, and canonical
|
|
944
|
+
// date/instant text lexicographically.
|
|
945
|
+
if (!boundsAreOrdered(primitive, minimum, maximum)) {
|
|
946
|
+
refuseAt(`${at}.minimum`, `\`minimum\` is greater than \`maximum\` on field \`${fieldId}\`; the smallest allowed value cannot exceed the largest — set \`minimum\` at or below \`maximum\``);
|
|
947
|
+
}
|
|
948
|
+
}
|
|
949
|
+
if ((primitive === 'integer' || primitive === 'money') && minimum !== undefined) {
|
|
950
|
+
if (typeof minimum !== 'number' || !Number.isSafeInteger(minimum)) {
|
|
951
|
+
refuseAt(`${at}.minimum`, `\`minimum\` on ${articleForPrimitive(primitive)} ${String(primitive)} field is a whole ${primitive === 'money' ? 'minor-unit count' : 'number'}; field \`${fieldId}\` declares ${String(minimum)}, which is not a safe integer`);
|
|
952
|
+
}
|
|
953
|
+
}
|
|
954
|
+
if ((primitive === 'integer' || primitive === 'money') && maximum !== undefined) {
|
|
955
|
+
if (typeof maximum !== 'number' || !Number.isSafeInteger(maximum)) {
|
|
956
|
+
refuseAt(`${at}.maximum`, `\`maximum\` on ${articleForPrimitive(primitive)} ${String(primitive)} field is a whole ${primitive === 'money' ? 'minor-unit count' : 'number'}; field \`${fieldId}\` declares ${String(maximum)}, which is not a safe integer`);
|
|
957
|
+
}
|
|
958
|
+
}
|
|
959
|
+
for (const member of ['minimum', 'maximum']) {
|
|
960
|
+
const bound = field[member];
|
|
961
|
+
if (bound === undefined)
|
|
962
|
+
continue;
|
|
963
|
+
// Restricted JSON carries no non-integer number, so a `decimal` bound is authored as
|
|
964
|
+
// canonical decimal text; a whole bound may still be a JSON number. Either way, the text
|
|
965
|
+
// is what the bound literal is built from, and a spelling the brand refuses is refused
|
|
966
|
+
// here rather than minted into an artifact the runtime cannot compare.
|
|
967
|
+
if ((primitive === 'decimal' || primitive === 'quantity') &&
|
|
968
|
+
tryDecimalString(boundText(bound)) === undefined) {
|
|
969
|
+
refuseAt(`${at}.${member}`, `\`${member}\` on ${String(primitive)} field \`${fieldId}\` must be canonical decimal text; \`${boundText(bound)}\` is not — write it without an exponent, leading zeros or trailing fractional zeros`);
|
|
970
|
+
}
|
|
971
|
+
// A date/instant bound's shape is the metaschema's `pattern`; whether the calendar holds
|
|
972
|
+
// that day, or the clock that instant, is the implementation's answer, and it must be the
|
|
973
|
+
// same answer the hand-written `date "…"`/`instant "…"` literal gets.
|
|
974
|
+
if ((primitive === 'date' || primitive === 'instant') && typeof bound === 'string') {
|
|
975
|
+
try {
|
|
976
|
+
if (primitive === 'date')
|
|
977
|
+
parsePlainDate(bound, `${at}.${member}`);
|
|
978
|
+
else
|
|
979
|
+
parseInstant(bound, `${at}.${member}`);
|
|
980
|
+
}
|
|
981
|
+
catch (error) {
|
|
982
|
+
refuseAt(`${at}.${member}`, `\`${member}\` on ${primitive} field \`${fieldId}\` is \`${bound}\`, which is not a real ${primitive === 'date' ? 'civil date' : 'instant'}: ${error instanceof Error ? error.message : String(error)}`);
|
|
983
|
+
}
|
|
984
|
+
}
|
|
985
|
+
if (primitive === 'time' && typeof bound === 'string') {
|
|
986
|
+
try {
|
|
987
|
+
parseClockTime(bound, `${at}.${member}`);
|
|
988
|
+
}
|
|
989
|
+
catch (error) {
|
|
990
|
+
refuseAt(`${at}.${member}`, `\`${member}\` on time field \`${fieldId}\` is \`${bound}\`, which is not a canonical local time of day: ${error instanceof Error ? error.message : String(error)}`);
|
|
991
|
+
}
|
|
992
|
+
}
|
|
993
|
+
}
|
|
994
|
+
// Item-scoped rules are refused on an array declared inside another array (`RULES-1.1.11`),
|
|
995
|
+
// and these declarations compile to item rules, so the refusal happens where the author
|
|
996
|
+
// wrote the declaration rather than at a generated rule the author never saw.
|
|
997
|
+
const compilesToItemRule = declaration.rowArray !== undefined &&
|
|
998
|
+
declaration.ancestors[declaration.ancestors.length - 1] === declaration.rowArray;
|
|
999
|
+
if (arrayInsideArray && field['minItems'] !== undefined) {
|
|
1000
|
+
refuseAt(`${at}.minItems`, `\`minItems\` on field \`${fieldId}\` counts the entries of an array declared inside array \`${String(declaration.rowArray)}\`; v1 addresses no row for a nested array, so move this array to the top level or drop \`minItems\``, 'INVALID_RULE_SCOPE');
|
|
1001
|
+
}
|
|
1002
|
+
if (arrayInsideArray && field['maxItems'] !== undefined) {
|
|
1003
|
+
refuseAt(`${at}.maxItems`, `\`maxItems\` on field \`${fieldId}\` counts the entries of an array declared inside array \`${String(declaration.rowArray)}\`; v1 addresses no row for a nested array, so move this array to the top level or drop \`maxItems\``, 'INVALID_RULE_SCOPE');
|
|
1004
|
+
}
|
|
1005
|
+
if (declaration.rowArray !== undefined &&
|
|
1006
|
+
!compilesToItemRule &&
|
|
1007
|
+
(field['required'] === true ||
|
|
1008
|
+
field['requiredWhen'] !== undefined ||
|
|
1009
|
+
field['visibleWhen'] !== undefined ||
|
|
1010
|
+
field['minimum'] !== undefined ||
|
|
1011
|
+
field['maximum'] !== undefined ||
|
|
1012
|
+
field['minLength'] !== undefined ||
|
|
1013
|
+
field['maxLength'] !== undefined)) {
|
|
1014
|
+
refuseAt(`${at}.required`, `field \`${fieldId}\` is not a direct member of array \`${String(declaration.rowArray)}\`; an item-scoped declaration must name one of the array's own members, so move the field to the row's top level or state the requirement on the record that holds it`, 'INVALID_RULE_SCOPE');
|
|
1015
|
+
}
|
|
1016
|
+
if (itemMember &&
|
|
1017
|
+
declaration.arrays.length > 1 &&
|
|
1018
|
+
(field['required'] === true ||
|
|
1019
|
+
field['requiredWhen'] !== undefined ||
|
|
1020
|
+
field['visibleWhen'] !== undefined ||
|
|
1021
|
+
field['minimum'] !== undefined ||
|
|
1022
|
+
field['maximum'] !== undefined ||
|
|
1023
|
+
field['minLength'] !== undefined ||
|
|
1024
|
+
field['maxLength'] !== undefined)) {
|
|
1025
|
+
refuseAt(`${at}.required`, `field \`${fieldId}\` is a member of array \`${String(declaration.rowArray)}\` declared inside another array; v1 refuses an item-scoped rule on a nested array, so a declaration that compiles to one is refused too — move the array to the top level or state the requirement as a record-level rule`, 'INVALID_RULE_SCOPE');
|
|
1026
|
+
}
|
|
1027
|
+
// A natural key is the row's identity, so it cannot also be constrained by an item rule:
|
|
1028
|
+
// an absent key leaves the row unaddressable and the constraint has no row to decide.
|
|
1029
|
+
if (itemMember && field['required'] === true) {
|
|
1030
|
+
const array = declaration.rowArray === undefined ? undefined : declared.get(declaration.rowArray);
|
|
1031
|
+
const keyMode = isRecord(array?.field['rowKey'])
|
|
1032
|
+
? textAt(array.field['rowKey'], 'mode')
|
|
1033
|
+
: undefined;
|
|
1034
|
+
const keyFieldId = isRecord(array?.field['rowKey'])
|
|
1035
|
+
? textAt(array.field['rowKey'], 'fieldId')
|
|
1036
|
+
: undefined;
|
|
1037
|
+
if (keyMode === 'natural' && keyFieldId === textAt(field, 'fieldId')) {
|
|
1038
|
+
refuseAt(`${at}.required`, `field \`${fieldId}\` is the natural row key of array \`${String(declaration.rowArray)}\`; a key identifies the row and cannot be constrained by an item-scoped rule, so remove \`required\` and let the row's identity carry the requirement`, 'INVALID_RULE_SCOPE');
|
|
1039
|
+
}
|
|
1040
|
+
}
|
|
1041
|
+
}
|
|
1042
|
+
return diagnostics;
|
|
1043
|
+
}
|
|
1044
|
+
/**
|
|
1045
|
+
* A field identifier is unique across the whole document, including nested record and
|
|
1046
|
+
* array declarations; a rule identifier is unique within the schema;
|
|
1047
|
+
* an option code is unique within its field; and the
|
|
1048
|
+
* declared context roots are a set keyed by path. Each duplicate would make
|
|
1049
|
+
* a read resolve to whichever declaration the walker reached first, so it is refused rather
|
|
1050
|
+
* than resolved by position.
|
|
1051
|
+
*
|
|
1052
|
+
* A natural `rowKey` is checked against the declaration it names: the
|
|
1053
|
+
* metaschema cannot see across the two declarations, and an unresolvable key would silently
|
|
1054
|
+
* leave every item without the identity a row-scoped access rule is matched against.
|
|
1055
|
+
*/
|
|
1056
|
+
export function declarationDiagnostics(document) {
|
|
1057
|
+
const fieldById = fieldDeclarations(document);
|
|
1058
|
+
const diagnostics = [
|
|
1059
|
+
...duplicateWriters(document, fieldById),
|
|
1060
|
+
...signatureCoverageDiagnostics(document),
|
|
1061
|
+
...declarationMemberDiagnostics(document, fieldById),
|
|
1062
|
+
];
|
|
1063
|
+
const computed = computedFieldIds(document);
|
|
1064
|
+
const fieldIds = new Set();
|
|
1065
|
+
const checkRowKey = (field, at) => {
|
|
1066
|
+
const declaration = field['rowKey'];
|
|
1067
|
+
if (!isRecord(declaration) || textAt(declaration, 'mode') !== 'natural')
|
|
1068
|
+
return;
|
|
1069
|
+
const target = textAt(declaration, 'fieldId');
|
|
1070
|
+
if (target === undefined)
|
|
1071
|
+
return;
|
|
1072
|
+
const path = `${at}.rowKey.fieldId`;
|
|
1073
|
+
const members = listAt(field, 'fields').filter(isRecord);
|
|
1074
|
+
const member = members.find((candidate) => textAt(candidate, 'fieldId') === target);
|
|
1075
|
+
if (member === undefined) {
|
|
1076
|
+
diagnostics.push({
|
|
1077
|
+
code: 'INVALID_ROW_KEY',
|
|
1078
|
+
path,
|
|
1079
|
+
detail: `natural rowKey \`${target}\` names no member of the item declaration; declare that \`fieldId\` on this array`,
|
|
1080
|
+
});
|
|
1081
|
+
return;
|
|
1082
|
+
}
|
|
1083
|
+
const primitive = textAt(member, 'primitive');
|
|
1084
|
+
if (primitive === undefined || !ROW_KEY_PRIMITIVES.has(primitive)) {
|
|
1085
|
+
diagnostics.push({
|
|
1086
|
+
code: 'INVALID_ROW_KEY',
|
|
1087
|
+
path,
|
|
1088
|
+
detail: `natural rowKey \`${target}\` is ${articleForPrimitive(primitive)} ${String(primitive)} member; declare a \`string\` or \`integer\` member of the item declaration`,
|
|
1089
|
+
});
|
|
1090
|
+
return;
|
|
1091
|
+
}
|
|
1092
|
+
if (computed.has(target)) {
|
|
1093
|
+
diagnostics.push({
|
|
1094
|
+
code: 'INVALID_ROW_KEY',
|
|
1095
|
+
path,
|
|
1096
|
+
detail: `natural rowKey \`${target}\` is computed; choose an uncomputed member as the key`,
|
|
1097
|
+
});
|
|
1098
|
+
}
|
|
1099
|
+
};
|
|
1100
|
+
const visitFields = (fields, path) => {
|
|
1101
|
+
fields.forEach((field, index) => {
|
|
1102
|
+
if (!isRecord(field))
|
|
1103
|
+
return;
|
|
1104
|
+
const at = `${path}[${String(index)}]`;
|
|
1105
|
+
const fieldId = textAt(field, 'fieldId');
|
|
1106
|
+
if (fieldId !== undefined) {
|
|
1107
|
+
if (fieldIds.has(fieldId)) {
|
|
1108
|
+
diagnostics.push({
|
|
1109
|
+
code: 'DUPLICATE_IDENTIFIER',
|
|
1110
|
+
path: `${at}.fieldId`,
|
|
1111
|
+
detail: `fieldId \`${fieldId}\` is declared more than once; choose a \`fieldId\` no other declaration uses`,
|
|
1112
|
+
});
|
|
1113
|
+
}
|
|
1114
|
+
fieldIds.add(fieldId);
|
|
1115
|
+
}
|
|
1116
|
+
const codes = new Set();
|
|
1117
|
+
listAt(field, 'options').forEach((option, optionIndex) => {
|
|
1118
|
+
if (!isRecord(option))
|
|
1119
|
+
return;
|
|
1120
|
+
const code = option['code'];
|
|
1121
|
+
if (typeof code !== 'string' && typeof code !== 'number')
|
|
1122
|
+
return;
|
|
1123
|
+
const key = optionCodeKey(code);
|
|
1124
|
+
if (codes.has(key)) {
|
|
1125
|
+
diagnostics.push({
|
|
1126
|
+
code: 'DUPLICATE_IDENTIFIER',
|
|
1127
|
+
path: `${at}.options[${String(optionIndex)}].code`,
|
|
1128
|
+
detail: `option code \`${String(code)}\` is declared more than once in field \`${fieldId ?? at}\`; choose an option \`code\` this field does not already use`,
|
|
1129
|
+
});
|
|
1130
|
+
}
|
|
1131
|
+
codes.add(key);
|
|
1132
|
+
});
|
|
1133
|
+
checkRowKey(field, at);
|
|
1134
|
+
visitFields(listAt(field, 'fields'), `${at}.fields`);
|
|
1135
|
+
});
|
|
1136
|
+
};
|
|
1137
|
+
visitFields(listAt(document, 'fields'), '$.fields');
|
|
1138
|
+
const ruleIds = new Set();
|
|
1139
|
+
listAt(document, 'rules').forEach((rule, index) => {
|
|
1140
|
+
if (!isRecord(rule))
|
|
1141
|
+
return;
|
|
1142
|
+
const ruleId = textAt(rule, 'ruleId');
|
|
1143
|
+
if (ruleId === undefined)
|
|
1144
|
+
return;
|
|
1145
|
+
if (ruleIds.has(ruleId)) {
|
|
1146
|
+
diagnostics.push({
|
|
1147
|
+
code: 'DUPLICATE_IDENTIFIER',
|
|
1148
|
+
path: `$.rules[${String(index)}].ruleId`,
|
|
1149
|
+
detail: `ruleId \`${ruleId}\` is declared more than once; choose a \`ruleId\` no other rule uses`,
|
|
1150
|
+
});
|
|
1151
|
+
return;
|
|
1152
|
+
}
|
|
1153
|
+
ruleIds.add(ruleId);
|
|
1154
|
+
});
|
|
1155
|
+
// The artifact pins one version per named table: two entries for one
|
|
1156
|
+
// table state two versions, and resolution could only honour one of them — silently the
|
|
1157
|
+
// last — so the document is refused rather than resolved against a pin its author did not
|
|
1158
|
+
// choose.
|
|
1159
|
+
const pinnedTables = new Set();
|
|
1160
|
+
listAt(document, 'datasets').forEach((ref, index) => {
|
|
1161
|
+
if (!isRecord(ref))
|
|
1162
|
+
return;
|
|
1163
|
+
const tableId = textAt(ref, 'tableId');
|
|
1164
|
+
if (tableId === undefined)
|
|
1165
|
+
return;
|
|
1166
|
+
if (pinnedTables.has(tableId)) {
|
|
1167
|
+
diagnostics.push({
|
|
1168
|
+
code: 'DUPLICATE_IDENTIFIER',
|
|
1169
|
+
path: `$.datasets[${String(index)}].tableId`,
|
|
1170
|
+
detail: `table \`${tableId}\` is declared more than once; pin each \`tableId\` once, because one artifact carries one version per table`,
|
|
1171
|
+
});
|
|
1172
|
+
return;
|
|
1173
|
+
}
|
|
1174
|
+
pinnedTables.add(tableId);
|
|
1175
|
+
});
|
|
1176
|
+
const declaredIds = [...fieldIds];
|
|
1177
|
+
const suggestion = (fieldId) => {
|
|
1178
|
+
const closest = closestNames(fieldId, declaredIds);
|
|
1179
|
+
return closest.length === 0 ? '' : `; did you mean ${closest.join(' or ')}?`;
|
|
1180
|
+
};
|
|
1181
|
+
const nearest = (fieldId) => closestNames(fieldId, declaredIds);
|
|
1182
|
+
listAt(document, 'rules').forEach((rule, index) => {
|
|
1183
|
+
if (!isRecord(rule))
|
|
1184
|
+
return;
|
|
1185
|
+
const at = `$.rules[${String(index)}]`;
|
|
1186
|
+
const ruleId = textAt(rule, 'ruleId') ?? at;
|
|
1187
|
+
const addressed = textAt(rule, 'fieldId');
|
|
1188
|
+
// `visible`, `gate` and `screen` each report through one section per declaration, so a
|
|
1189
|
+
// per-row verdict has nothing to act on it: a `gate` or `screen` item rule leaves every
|
|
1190
|
+
// evaluation blocked or undecided, and an item-scoped `visible` rule would decide rows no
|
|
1191
|
+
// report section, projection or binding reads — under `onHide: "exclude"` that is a value
|
|
1192
|
+
// the author withheld and the export would still carry. Refused here rather than left inert
|
|
1193
|
+
// which is what the clause already required of the first two.
|
|
1194
|
+
const kind = textAt(rule, 'kind');
|
|
1195
|
+
// EVOL-3.1.3 forbids a deprecated field from becoming required. The other half of the
|
|
1196
|
+
// clause — that it acquire no new rules — needs the retained declaration to compare
|
|
1197
|
+
// against, which a single document does not carry.
|
|
1198
|
+
if (kind === 'required') {
|
|
1199
|
+
const itemTarget = textAt(rule, 'scope') === 'item';
|
|
1200
|
+
const target = itemTarget ? textAt(rule, 'targetFieldId') : addressed;
|
|
1201
|
+
const targetField = target === undefined ? undefined : fieldById.get(target)?.field;
|
|
1202
|
+
if (target !== undefined && isDeprecated(targetField)) {
|
|
1203
|
+
diagnostics.push({
|
|
1204
|
+
code: 'SCHEMA_INVALID',
|
|
1205
|
+
path: `${at}.${itemTarget ? 'targetFieldId' : 'fieldId'}`,
|
|
1206
|
+
detail: `rule \`${ruleId}\` makes deprecated field \`${target}\` required; EVOL-3.1.3 forbids a deprecated field from becoming required, so remove the \`required\` rule or retire the deprecation`,
|
|
1207
|
+
});
|
|
1208
|
+
}
|
|
1209
|
+
}
|
|
1210
|
+
if (kind !== undefined && ITEM_FORBIDDEN_KINDS.has(kind) && textAt(rule, 'scope') === 'item') {
|
|
1211
|
+
diagnostics.push({
|
|
1212
|
+
code: 'INVALID_RULE_SCOPE',
|
|
1213
|
+
path: `${at}.scope`,
|
|
1214
|
+
detail: `rule \`${ruleId}\` is a \`${kind}\` rule at \`item\` scope; a \`${kind}\` rule decides one declaration in this version, and a per-row verdict has no consumer a report section, projection or binding could act on`,
|
|
1215
|
+
});
|
|
1216
|
+
}
|
|
1217
|
+
// An item-scoped rule reports one result per row, and a row is identified by its natural
|
|
1218
|
+
// key, the item value of a scalar array with a value domain, or, for an array whose identity
|
|
1219
|
+
// the session owns, the host-assigned id its manifest carries (`RULES-1.1.10`, `IDENT-4.1.3`).
|
|
1220
|
+
// An array with no identity at all has no rows a result can name, so it is refused where it is
|
|
1221
|
+
// authored rather than when it is first evaluated.
|
|
1222
|
+
if (textAt(rule, 'scope') === 'item' && addressed !== undefined) {
|
|
1223
|
+
const array = fieldById.get(addressed)?.field;
|
|
1224
|
+
const mode = isRecord(array?.['rowKey']) ? textAt(array['rowKey'], 'mode') : undefined;
|
|
1225
|
+
const valueIdentified = mode === undefined && isRecord(array?.['items']);
|
|
1226
|
+
if (array !== undefined &&
|
|
1227
|
+
textAt(array, 'primitive') === 'array' &&
|
|
1228
|
+
mode === undefined &&
|
|
1229
|
+
!valueIdentified) {
|
|
1230
|
+
diagnostics.push({
|
|
1231
|
+
code: 'INVALID_RULE_SCOPE',
|
|
1232
|
+
path: `${at}.fieldId`,
|
|
1233
|
+
detail: `rule \`${ruleId}\` is item-scoped on \`${addressed}\`, which declares no rowKey; a per-row result names the row it belongs to, and only a natural or host-assigned key can state it`,
|
|
1234
|
+
});
|
|
1235
|
+
}
|
|
1236
|
+
}
|
|
1237
|
+
// A rule is about the field it names, and a computed default's
|
|
1238
|
+
// override record lives in a companion field. A typo in either one is
|
|
1239
|
+
// not visible to the metaschema: a compute then writes a field nothing declares and the
|
|
1240
|
+
// field it meant to write is never computed, and an override companion no declaration
|
|
1241
|
+
// names is `ENGINE_ERROR` on every record rather than a publish-time refusal.
|
|
1242
|
+
if (addressed !== undefined && !fieldIds.has(addressed)) {
|
|
1243
|
+
const candidates = nearest(addressed);
|
|
1244
|
+
diagnostics.push({
|
|
1245
|
+
code: 'UNKNOWN_IDENTIFIER',
|
|
1246
|
+
path: `${at}.fieldId`,
|
|
1247
|
+
detail: `rule \`${ruleId}\` addresses field \`${addressed}\`, which this document does not declare${suggestion(addressed)}; name a declared \`fieldId\`, or add the field first`,
|
|
1248
|
+
...(candidates.length === 0 ? {} : { suggestions: candidates }),
|
|
1249
|
+
});
|
|
1250
|
+
}
|
|
1251
|
+
// A `visible` or `enabled` rule's target list names the fields it decides, and a target the
|
|
1252
|
+
// document does not declare would hide or disable nothing at all — the rule would report a
|
|
1253
|
+
// verdict about no field.
|
|
1254
|
+
listAt(rule, 'fieldIds').forEach((target, targetIndex) => {
|
|
1255
|
+
if (typeof target !== 'string' || fieldIds.has(target))
|
|
1256
|
+
return;
|
|
1257
|
+
const candidates = nearest(target);
|
|
1258
|
+
diagnostics.push({
|
|
1259
|
+
code: 'UNKNOWN_IDENTIFIER',
|
|
1260
|
+
path: `${at}.fieldIds[${String(targetIndex)}]`,
|
|
1261
|
+
detail: `rule \`${ruleId}\` decides field \`${target}\`, which this document does not declare${suggestion(target)}; name a declared \`fieldId\` for this \`${textAt(rule, 'kind') ?? 'rule'}\` rule, or add the field first`,
|
|
1262
|
+
...(candidates.length === 0 ? {} : { suggestions: candidates }),
|
|
1263
|
+
});
|
|
1264
|
+
});
|
|
1265
|
+
const companion = textAt(rule, 'overrideFieldId');
|
|
1266
|
+
if (companion !== undefined && !fieldIds.has(companion)) {
|
|
1267
|
+
const candidates = nearest(companion);
|
|
1268
|
+
diagnostics.push({
|
|
1269
|
+
code: 'UNKNOWN_IDENTIFIER',
|
|
1270
|
+
path: `${at}.overrideFieldId`,
|
|
1271
|
+
detail: `rule \`${ruleId}\` keeps its override record in \`${companion}\`, which this document does not declare${suggestion(companion)}; declare the companion field, or point \`overrideFieldId\` at a declared field`,
|
|
1272
|
+
...(candidates.length === 0 ? {} : { suggestions: candidates }),
|
|
1273
|
+
});
|
|
1274
|
+
}
|
|
1275
|
+
diagnostics.push(...itemScopeDiagnostics(rule, at, ruleId, fieldById));
|
|
1276
|
+
diagnostics.push(...writerRowMemberDiagnostics(rule, at, ruleId, fieldById));
|
|
1277
|
+
});
|
|
1278
|
+
const context = document['context'];
|
|
1279
|
+
if (isRecord(context)) {
|
|
1280
|
+
const paths = new Set();
|
|
1281
|
+
listAt(context, 'roots').forEach((root, index) => {
|
|
1282
|
+
if (!isRecord(root))
|
|
1283
|
+
return;
|
|
1284
|
+
const rootPath = textAt(root, 'path');
|
|
1285
|
+
if (rootPath === undefined)
|
|
1286
|
+
return;
|
|
1287
|
+
if (paths.has(rootPath)) {
|
|
1288
|
+
diagnostics.push({
|
|
1289
|
+
code: 'DUPLICATE_IDENTIFIER',
|
|
1290
|
+
path: `$.context.roots[${String(index)}].path`,
|
|
1291
|
+
detail: `context root path \`${rootPath}\` is declared more than once; list each root \`path\` once`,
|
|
1292
|
+
});
|
|
1293
|
+
}
|
|
1294
|
+
paths.add(rootPath);
|
|
1295
|
+
});
|
|
1296
|
+
}
|
|
1297
|
+
return diagnostics;
|
|
1298
|
+
}
|
|
1299
|
+
//# sourceMappingURL=declarations.js.map
|