@azx-pbc/axiom-compiler 0.0.0-stage → 0.0.1
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,1180 @@
|
|
|
1
|
+
import { asDecimalString, canonicalDecimal, civilFromDays, compareDecimalTexts, daysBetween, daysFromCivil, instantToEpochMilliseconds, isRecord, minutesBetweenInstants, minutesBetweenTimes, monthsBetween, parseClockTime, parseDecimal, parsePlainDate, secondsSinceMidnight, } from '@azx-pbc/axiom-runtime';
|
|
2
|
+
import { codePointIndexOf, codePointLength } from './code-points.js';
|
|
3
|
+
const MAX_SAFE_INTEGER = BigInt(Number.MAX_SAFE_INTEGER);
|
|
4
|
+
const MIN_SAFE_INTEGER = -MAX_SAFE_INTEGER;
|
|
5
|
+
const TOP = { kind: 'top' };
|
|
6
|
+
function integerBound(value) {
|
|
7
|
+
return { kind: 'integer', value };
|
|
8
|
+
}
|
|
9
|
+
function decimalBound(value) {
|
|
10
|
+
return { kind: 'decimal', value: asDecimalString(value) };
|
|
11
|
+
}
|
|
12
|
+
function scalarBound(value) {
|
|
13
|
+
return { kind: 'scalar', value };
|
|
14
|
+
}
|
|
15
|
+
function boundOf(family, value) {
|
|
16
|
+
switch (family) {
|
|
17
|
+
case 'integer':
|
|
18
|
+
case 'money':
|
|
19
|
+
case 'duration':
|
|
20
|
+
return integerBound(BigInt(value));
|
|
21
|
+
case 'decimal':
|
|
22
|
+
return decimalBound(String(value));
|
|
23
|
+
case 'date':
|
|
24
|
+
case 'instant':
|
|
25
|
+
case 'time':
|
|
26
|
+
return scalarBound(Number(value));
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
function familyOfPrimitive(primitive) {
|
|
30
|
+
switch (primitive) {
|
|
31
|
+
case 'integer':
|
|
32
|
+
return 'integer';
|
|
33
|
+
case 'decimal':
|
|
34
|
+
case 'quantity':
|
|
35
|
+
return 'decimal';
|
|
36
|
+
case 'money':
|
|
37
|
+
return 'money';
|
|
38
|
+
case 'duration':
|
|
39
|
+
return 'duration';
|
|
40
|
+
case 'date':
|
|
41
|
+
return 'date';
|
|
42
|
+
case 'instant':
|
|
43
|
+
return 'instant';
|
|
44
|
+
case 'time':
|
|
45
|
+
return 'time';
|
|
46
|
+
default:
|
|
47
|
+
return undefined;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
function range(family, min, max, minInclusive = true, maxInclusive = true) {
|
|
51
|
+
if (min !== null && max !== null) {
|
|
52
|
+
const order = compareBounds(min, max);
|
|
53
|
+
if (order === undefined)
|
|
54
|
+
return { kind: 'empty', family };
|
|
55
|
+
if (order > 0 || (order === 0 && (!minInclusive || !maxInclusive))) {
|
|
56
|
+
return { kind: 'empty', family };
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return { kind: 'range', family, min, minInclusive, max, maxInclusive };
|
|
60
|
+
}
|
|
61
|
+
function constant(family, value) {
|
|
62
|
+
const bound = boundOf(family, value);
|
|
63
|
+
return range(family, bound, bound);
|
|
64
|
+
}
|
|
65
|
+
function unbounded(family) {
|
|
66
|
+
return range(family, null, null);
|
|
67
|
+
}
|
|
68
|
+
function compareBounds(left, right) {
|
|
69
|
+
if (left.kind === 'integer' && right.kind === 'integer') {
|
|
70
|
+
if (left.value === right.value)
|
|
71
|
+
return 0;
|
|
72
|
+
return left.value < right.value ? -1 : 1;
|
|
73
|
+
}
|
|
74
|
+
if (left.kind === 'decimal' && right.kind === 'decimal') {
|
|
75
|
+
return compareDecimalTexts(left.value, right.value);
|
|
76
|
+
}
|
|
77
|
+
if (left.kind === 'scalar' && right.kind === 'scalar') {
|
|
78
|
+
if (left.value === right.value)
|
|
79
|
+
return 0;
|
|
80
|
+
return left.value < right.value ? -1 : 1;
|
|
81
|
+
}
|
|
82
|
+
return undefined;
|
|
83
|
+
}
|
|
84
|
+
function sameBound(left, right) {
|
|
85
|
+
return compareBounds(left, right) === 0;
|
|
86
|
+
}
|
|
87
|
+
function greaterBound(left, right) {
|
|
88
|
+
if (left === null)
|
|
89
|
+
return right;
|
|
90
|
+
if (right === null)
|
|
91
|
+
return left;
|
|
92
|
+
return compareBounds(left, right) === -1 ? right : left;
|
|
93
|
+
}
|
|
94
|
+
function lesserBound(left, right) {
|
|
95
|
+
if (left === null)
|
|
96
|
+
return right;
|
|
97
|
+
if (right === null)
|
|
98
|
+
return left;
|
|
99
|
+
return compareBounds(left, right) === 1 ? right : left;
|
|
100
|
+
}
|
|
101
|
+
function isConstant(value) {
|
|
102
|
+
return (value.kind === 'range' &&
|
|
103
|
+
value.min !== null &&
|
|
104
|
+
value.max !== null &&
|
|
105
|
+
sameBound(value.min, value.max));
|
|
106
|
+
}
|
|
107
|
+
function intersect(left, right) {
|
|
108
|
+
if (left.kind === 'top')
|
|
109
|
+
return right;
|
|
110
|
+
if (right.kind === 'top')
|
|
111
|
+
return left;
|
|
112
|
+
if (left.kind === 'empty')
|
|
113
|
+
return left;
|
|
114
|
+
if (right.kind === 'empty')
|
|
115
|
+
return right;
|
|
116
|
+
if (left.family !== right.family)
|
|
117
|
+
return TOP;
|
|
118
|
+
const lower = left.min === null
|
|
119
|
+
? { bound: right.min, inclusive: right.minInclusive }
|
|
120
|
+
: right.min === null
|
|
121
|
+
? { bound: left.min, inclusive: left.minInclusive }
|
|
122
|
+
: compareBounds(left.min, right.min) === -1
|
|
123
|
+
? { bound: right.min, inclusive: right.minInclusive }
|
|
124
|
+
: compareBounds(left.min, right.min) === 1
|
|
125
|
+
? { bound: left.min, inclusive: left.minInclusive }
|
|
126
|
+
: { bound: left.min, inclusive: left.minInclusive && right.minInclusive };
|
|
127
|
+
const upper = left.max === null
|
|
128
|
+
? { bound: right.max, inclusive: right.maxInclusive }
|
|
129
|
+
: right.max === null
|
|
130
|
+
? { bound: left.max, inclusive: left.maxInclusive }
|
|
131
|
+
: compareBounds(left.max, right.max) === 1
|
|
132
|
+
? { bound: right.max, inclusive: right.maxInclusive }
|
|
133
|
+
: compareBounds(left.max, right.max) === -1
|
|
134
|
+
? { bound: left.max, inclusive: left.maxInclusive }
|
|
135
|
+
: { bound: left.max, inclusive: left.maxInclusive && right.maxInclusive };
|
|
136
|
+
return range(left.family, lower.bound, upper.bound, lower.inclusive, upper.inclusive);
|
|
137
|
+
}
|
|
138
|
+
function unite(left, right) {
|
|
139
|
+
if (left.kind === 'top' || right.kind === 'top')
|
|
140
|
+
return TOP;
|
|
141
|
+
if (left.kind === 'empty')
|
|
142
|
+
return right;
|
|
143
|
+
if (right.kind === 'empty')
|
|
144
|
+
return left;
|
|
145
|
+
if (left.family !== right.family)
|
|
146
|
+
return TOP;
|
|
147
|
+
const lower = lesserBound(left.min, right.min);
|
|
148
|
+
const upper = greaterBound(left.max, right.max);
|
|
149
|
+
const minInclusive = left.min !== null &&
|
|
150
|
+
right.min !== null &&
|
|
151
|
+
sameBound(left.min, right.min) &&
|
|
152
|
+
left.minInclusive &&
|
|
153
|
+
right.minInclusive;
|
|
154
|
+
const maxInclusive = left.max !== null &&
|
|
155
|
+
right.max !== null &&
|
|
156
|
+
sameBound(left.max, right.max) &&
|
|
157
|
+
left.maxInclusive &&
|
|
158
|
+
right.maxInclusive;
|
|
159
|
+
return range(left.family, lower, upper, minInclusive, maxInclusive);
|
|
160
|
+
}
|
|
161
|
+
function toDecimal(value) {
|
|
162
|
+
if (value.kind === 'top' || value.kind === 'empty')
|
|
163
|
+
return value;
|
|
164
|
+
if (value.family === 'decimal')
|
|
165
|
+
return value;
|
|
166
|
+
if (value.family !== 'integer')
|
|
167
|
+
return TOP;
|
|
168
|
+
const min = value.min?.kind === 'integer' ? decimalBound(value.min.value.toString()) : null;
|
|
169
|
+
const max = value.max?.kind === 'integer' ? decimalBound(value.max.value.toString()) : null;
|
|
170
|
+
return range('decimal', min, max, value.minInclusive, value.maxInclusive);
|
|
171
|
+
}
|
|
172
|
+
function addBounds(left, right, family) {
|
|
173
|
+
if (left === null || right === null)
|
|
174
|
+
return null;
|
|
175
|
+
try {
|
|
176
|
+
if (family === 'integer' || family === 'money' || family === 'duration') {
|
|
177
|
+
if (left.kind !== 'integer' || right.kind !== 'integer')
|
|
178
|
+
return null;
|
|
179
|
+
const sum = left.value + right.value;
|
|
180
|
+
return sum > MAX_SAFE_INTEGER || sum < MIN_SAFE_INTEGER ? null : integerBound(sum);
|
|
181
|
+
}
|
|
182
|
+
if (family === 'decimal') {
|
|
183
|
+
if (left.kind !== 'decimal' || right.kind !== 'decimal')
|
|
184
|
+
return null;
|
|
185
|
+
return decimalBound(canonicalDecimal(parseDecimal(left.value).plus(parseDecimal(right.value))));
|
|
186
|
+
}
|
|
187
|
+
if (left.kind !== 'scalar' || right.kind !== 'scalar')
|
|
188
|
+
return null;
|
|
189
|
+
return scalarBound(left.value + right.value);
|
|
190
|
+
}
|
|
191
|
+
catch {
|
|
192
|
+
return null;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
function negateInterval(value) {
|
|
196
|
+
if (value.kind === 'top' || value.kind === 'empty')
|
|
197
|
+
return value;
|
|
198
|
+
if (value.family === 'integer' || value.family === 'money' || value.family === 'duration') {
|
|
199
|
+
if (value.family !== 'integer')
|
|
200
|
+
return TOP;
|
|
201
|
+
const min = value.max?.kind === 'integer'
|
|
202
|
+
? value.max.value === MIN_SAFE_INTEGER
|
|
203
|
+
? undefined
|
|
204
|
+
: integerBound(-value.max.value)
|
|
205
|
+
: null;
|
|
206
|
+
const max = value.min?.kind === 'integer'
|
|
207
|
+
? value.min.value === MIN_SAFE_INTEGER
|
|
208
|
+
? undefined
|
|
209
|
+
: integerBound(-value.min.value)
|
|
210
|
+
: null;
|
|
211
|
+
if (min === undefined || max === undefined)
|
|
212
|
+
return TOP;
|
|
213
|
+
return range(value.family, min, max, value.maxInclusive, value.minInclusive);
|
|
214
|
+
}
|
|
215
|
+
if (value.family === 'decimal') {
|
|
216
|
+
if (value.min?.kind === 'decimal') {
|
|
217
|
+
const max = decimalBound(canonicalDecimal(parseDecimal(value.min.value).negated()));
|
|
218
|
+
const min = value.max?.kind === 'decimal'
|
|
219
|
+
? decimalBound(canonicalDecimal(parseDecimal(value.max.value).negated()))
|
|
220
|
+
: null;
|
|
221
|
+
return range('decimal', min, max, value.maxInclusive, value.minInclusive);
|
|
222
|
+
}
|
|
223
|
+
return TOP;
|
|
224
|
+
}
|
|
225
|
+
return TOP;
|
|
226
|
+
}
|
|
227
|
+
function multiplyIntervals(left, right) {
|
|
228
|
+
if (left.kind === 'top' || right.kind === 'top')
|
|
229
|
+
return TOP;
|
|
230
|
+
if (left.kind === 'empty')
|
|
231
|
+
return left;
|
|
232
|
+
if (right.kind === 'empty')
|
|
233
|
+
return right;
|
|
234
|
+
if (left.family !== right.family)
|
|
235
|
+
return TOP;
|
|
236
|
+
const family = left.family;
|
|
237
|
+
if (family !== 'integer' && family !== 'decimal')
|
|
238
|
+
return TOP;
|
|
239
|
+
if (left.min === null || left.max === null || right.min === null || right.max === null)
|
|
240
|
+
return TOP;
|
|
241
|
+
const leftBounds = [left.min, left.max];
|
|
242
|
+
const rightBounds = [right.min, right.max];
|
|
243
|
+
const products = [];
|
|
244
|
+
try {
|
|
245
|
+
for (const a of leftBounds) {
|
|
246
|
+
for (const b of rightBounds) {
|
|
247
|
+
if (family === 'integer') {
|
|
248
|
+
if (a.kind !== 'integer' || b.kind !== 'integer')
|
|
249
|
+
return TOP;
|
|
250
|
+
const product = a.value * b.value;
|
|
251
|
+
if (product > MAX_SAFE_INTEGER || product < MIN_SAFE_INTEGER)
|
|
252
|
+
return TOP;
|
|
253
|
+
products.push(integerBound(product));
|
|
254
|
+
}
|
|
255
|
+
else {
|
|
256
|
+
if (a.kind !== 'decimal' || b.kind !== 'decimal')
|
|
257
|
+
return TOP;
|
|
258
|
+
products.push(decimalBound(canonicalDecimal(parseDecimal(a.value).times(parseDecimal(b.value)))));
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
catch {
|
|
264
|
+
return TOP;
|
|
265
|
+
}
|
|
266
|
+
let min = products[0];
|
|
267
|
+
let max = products[0];
|
|
268
|
+
if (min === undefined || max === undefined)
|
|
269
|
+
return TOP;
|
|
270
|
+
for (const product of products.slice(1)) {
|
|
271
|
+
if (compareBounds(product, min) === -1)
|
|
272
|
+
min = product;
|
|
273
|
+
if (compareBounds(product, max) === 1)
|
|
274
|
+
max = product;
|
|
275
|
+
}
|
|
276
|
+
return range(family, min, max);
|
|
277
|
+
}
|
|
278
|
+
function arithmeticIntervals(op, args) {
|
|
279
|
+
if (args.some((arg) => arg.kind === 'top'))
|
|
280
|
+
return TOP;
|
|
281
|
+
if (args.length === 0)
|
|
282
|
+
return TOP;
|
|
283
|
+
if (op === '/') {
|
|
284
|
+
if (args.length !== 2)
|
|
285
|
+
return TOP;
|
|
286
|
+
return divideIntervals(args[0] ?? TOP, args[1] ?? TOP);
|
|
287
|
+
}
|
|
288
|
+
if (op === '*') {
|
|
289
|
+
return args.reduce((left, right) => multiplyIntervals(left, right), args[0] ?? TOP);
|
|
290
|
+
}
|
|
291
|
+
if (op === '-' && args.length === 1)
|
|
292
|
+
return negateInterval(args[0] ?? TOP);
|
|
293
|
+
const families = args.flatMap((arg) => arg.kind === 'empty' || arg.kind === 'top' ? [] : [arg.family]);
|
|
294
|
+
if (families.length === 0)
|
|
295
|
+
return TOP;
|
|
296
|
+
const hasDecimal = families.includes('decimal');
|
|
297
|
+
const hasInteger = families.includes('integer');
|
|
298
|
+
if (families.every((family) => family === 'money')) {
|
|
299
|
+
return combineRanges('money', args, op);
|
|
300
|
+
}
|
|
301
|
+
if (families.every((family) => family === 'duration')) {
|
|
302
|
+
return combineRanges('duration', args, op);
|
|
303
|
+
}
|
|
304
|
+
if (hasDecimal || hasInteger) {
|
|
305
|
+
return combineRanges('decimal', args.map(toDecimal), op);
|
|
306
|
+
}
|
|
307
|
+
return TOP;
|
|
308
|
+
}
|
|
309
|
+
function scaledBound(bound) {
|
|
310
|
+
if (bound.kind === 'scalar')
|
|
311
|
+
return undefined;
|
|
312
|
+
const text = bound.kind === 'integer' ? bound.value.toString() : bound.value;
|
|
313
|
+
const negative = text.startsWith('-');
|
|
314
|
+
const unsigned = negative ? text.slice(1) : text;
|
|
315
|
+
const point = unsigned.indexOf('.');
|
|
316
|
+
const whole = point === -1 ? unsigned : unsigned.slice(0, point);
|
|
317
|
+
const fraction = point === -1 ? '' : unsigned.slice(point + 1);
|
|
318
|
+
const units = BigInt(`${whole}${fraction}`);
|
|
319
|
+
return { units: negative ? -units : units, scale: fraction.length };
|
|
320
|
+
}
|
|
321
|
+
function positiveFactors(value, factor) {
|
|
322
|
+
let count = 0;
|
|
323
|
+
let rest = value;
|
|
324
|
+
while (rest % factor === 0n) {
|
|
325
|
+
rest /= factor;
|
|
326
|
+
count += 1;
|
|
327
|
+
}
|
|
328
|
+
return count;
|
|
329
|
+
}
|
|
330
|
+
/**
|
|
331
|
+
* The exact quotient of two bounds as canonical decimal text, or `undefined` when the quotient
|
|
332
|
+
* has no finite decimal spelling or leaves the 34-digit result budget.
|
|
333
|
+
*
|
|
334
|
+
* The interval pass never rounds a bound: a rounded endpoint could exclude a value the
|
|
335
|
+
* expression really produces, which is a claim rather than a range. A quotient that does not
|
|
336
|
+
* terminate therefore leaves the result `top`.
|
|
337
|
+
*/
|
|
338
|
+
function exactQuotient(dividend, divisor) {
|
|
339
|
+
if (dividend.kind === 'scalar' || divisor.kind === 'scalar')
|
|
340
|
+
return undefined;
|
|
341
|
+
const a = scaledBound(dividend);
|
|
342
|
+
const b = scaledBound(divisor);
|
|
343
|
+
if (a === undefined || b === undefined || b.units === 0n)
|
|
344
|
+
return undefined;
|
|
345
|
+
let numerator = a.units * 10n ** BigInt(b.scale);
|
|
346
|
+
let denominator = b.units * 10n ** BigInt(a.scale);
|
|
347
|
+
if (numerator === 0n)
|
|
348
|
+
return asDecimalString('0');
|
|
349
|
+
if (denominator < 0n) {
|
|
350
|
+
numerator = -numerator;
|
|
351
|
+
denominator = -denominator;
|
|
352
|
+
}
|
|
353
|
+
const common = greatestCommonFactor(numerator, denominator);
|
|
354
|
+
numerator /= common;
|
|
355
|
+
denominator /= common;
|
|
356
|
+
const twos = positiveFactors(denominator, 2n);
|
|
357
|
+
const rest = denominator / 2n ** BigInt(twos);
|
|
358
|
+
const fives = positiveFactors(rest, 5n);
|
|
359
|
+
if (rest / 5n ** BigInt(fives) !== 1n)
|
|
360
|
+
return undefined;
|
|
361
|
+
const digits = Math.max(twos, fives);
|
|
362
|
+
if (digits > 34)
|
|
363
|
+
return undefined;
|
|
364
|
+
const units = (numerator * 10n ** BigInt(digits)) / denominator;
|
|
365
|
+
return renderIntervalScaled(units, digits);
|
|
366
|
+
}
|
|
367
|
+
function greatestCommonFactor(left, right) {
|
|
368
|
+
let a = left < 0n ? -left : left;
|
|
369
|
+
let b = right;
|
|
370
|
+
while (b !== 0n) {
|
|
371
|
+
const remainder = a % b;
|
|
372
|
+
a = b;
|
|
373
|
+
b = remainder;
|
|
374
|
+
}
|
|
375
|
+
return a;
|
|
376
|
+
}
|
|
377
|
+
function renderIntervalScaled(units, scale) {
|
|
378
|
+
if (units === 0n)
|
|
379
|
+
return asDecimalString('0');
|
|
380
|
+
const negative = units < 0n;
|
|
381
|
+
let magnitude = (negative ? -units : units).toString();
|
|
382
|
+
while (scale > 0 && magnitude.endsWith('0')) {
|
|
383
|
+
magnitude = magnitude.slice(0, -1);
|
|
384
|
+
scale -= 1;
|
|
385
|
+
}
|
|
386
|
+
const digits = magnitude.padStart(scale + 1, '0');
|
|
387
|
+
const whole = digits.slice(0, digits.length - scale);
|
|
388
|
+
const fraction = digits.slice(digits.length - scale).replace(/0+$/, '');
|
|
389
|
+
const text = fraction === '' ? whole : `${whole}.${fraction}`;
|
|
390
|
+
const signed = negative ? `-${text}` : text;
|
|
391
|
+
const significant = signed
|
|
392
|
+
.replace('-', '')
|
|
393
|
+
.replace('.', '')
|
|
394
|
+
.replace(/^0+/, '')
|
|
395
|
+
.replace(/0+$/, '');
|
|
396
|
+
return significant.length > 34 ? undefined : asDecimalString(signed);
|
|
397
|
+
}
|
|
398
|
+
/**
|
|
399
|
+
* `/` over intervals. A divisor interval that contains zero answers `top`: no quotient bound
|
|
400
|
+
* can be stated when the divisor may be zero, and "cannot say" is the only honest answer.
|
|
401
|
+
*/
|
|
402
|
+
function divideIntervals(left, right) {
|
|
403
|
+
if (left.kind === 'top' || right.kind === 'top')
|
|
404
|
+
return TOP;
|
|
405
|
+
if (left.kind === 'empty')
|
|
406
|
+
return left;
|
|
407
|
+
if (right.kind === 'empty')
|
|
408
|
+
return right;
|
|
409
|
+
if (left.family !== 'integer' && left.family !== 'decimal')
|
|
410
|
+
return TOP;
|
|
411
|
+
if (right.family !== 'integer' && right.family !== 'decimal')
|
|
412
|
+
return TOP;
|
|
413
|
+
const dividend = toDecimal(left);
|
|
414
|
+
const divisor = toDecimal(right);
|
|
415
|
+
if (dividend.kind !== 'range' || divisor.kind !== 'range')
|
|
416
|
+
return TOP;
|
|
417
|
+
if (dividend.min === null ||
|
|
418
|
+
dividend.max === null ||
|
|
419
|
+
divisor.min === null ||
|
|
420
|
+
divisor.max === null) {
|
|
421
|
+
return TOP;
|
|
422
|
+
}
|
|
423
|
+
const zero = decimalBound('0');
|
|
424
|
+
if (compareBounds(divisor.min, zero) !== 1 && compareBounds(divisor.max, zero) !== -1) {
|
|
425
|
+
return TOP;
|
|
426
|
+
}
|
|
427
|
+
const quotients = [
|
|
428
|
+
exactQuotient(dividend.min, divisor.min),
|
|
429
|
+
exactQuotient(dividend.min, divisor.max),
|
|
430
|
+
exactQuotient(dividend.max, divisor.min),
|
|
431
|
+
exactQuotient(dividend.max, divisor.max),
|
|
432
|
+
];
|
|
433
|
+
if (quotients.some((quotient) => quotient === undefined))
|
|
434
|
+
return TOP;
|
|
435
|
+
const bounds = quotients.map((quotient) => decimalBound(quotient ?? '0'));
|
|
436
|
+
let min = bounds[0];
|
|
437
|
+
let max = bounds[0];
|
|
438
|
+
if (min === undefined || max === undefined)
|
|
439
|
+
return TOP;
|
|
440
|
+
for (const bound of bounds.slice(1)) {
|
|
441
|
+
if (compareBounds(bound, min) === -1)
|
|
442
|
+
min = bound;
|
|
443
|
+
if (compareBounds(bound, max) === 1)
|
|
444
|
+
max = bound;
|
|
445
|
+
}
|
|
446
|
+
return range('decimal', min, max);
|
|
447
|
+
}
|
|
448
|
+
function combineRanges(family, args, op) {
|
|
449
|
+
let lower = null;
|
|
450
|
+
let upper = null;
|
|
451
|
+
let first = true;
|
|
452
|
+
for (const arg of args) {
|
|
453
|
+
if (arg.kind !== 'range')
|
|
454
|
+
return TOP;
|
|
455
|
+
const min = op === '-' && !first ? arg.max : arg.min;
|
|
456
|
+
const max = op === '-' && !first ? arg.min : arg.max;
|
|
457
|
+
if (first) {
|
|
458
|
+
lower = min;
|
|
459
|
+
upper = max;
|
|
460
|
+
first = false;
|
|
461
|
+
continue;
|
|
462
|
+
}
|
|
463
|
+
lower = addBounds(lower, min, family);
|
|
464
|
+
upper = addBounds(upper, max, family);
|
|
465
|
+
if (lower === null || upper === null)
|
|
466
|
+
return TOP;
|
|
467
|
+
}
|
|
468
|
+
if (family === 'duration' && lower !== null && lower.kind === 'integer' && lower.value < 0n) {
|
|
469
|
+
return TOP;
|
|
470
|
+
}
|
|
471
|
+
return range(family, lower, upper);
|
|
472
|
+
}
|
|
473
|
+
function fieldAtPath(declarations, path, itemFieldId) {
|
|
474
|
+
const [head, ...rest] = path.split('.');
|
|
475
|
+
if (head === undefined)
|
|
476
|
+
return undefined;
|
|
477
|
+
if (head.startsWith('$')) {
|
|
478
|
+
if (itemFieldId === undefined || rest.length === 0)
|
|
479
|
+
return undefined;
|
|
480
|
+
const array = declarations.fields?.find((field) => field.fieldId === itemFieldId);
|
|
481
|
+
if (array === undefined)
|
|
482
|
+
return undefined;
|
|
483
|
+
return findMember(array, rest);
|
|
484
|
+
}
|
|
485
|
+
const top = declarations.fields?.find((field) => field.fieldId === head);
|
|
486
|
+
if (top === undefined)
|
|
487
|
+
return undefined;
|
|
488
|
+
return findMember(top, rest);
|
|
489
|
+
}
|
|
490
|
+
function findMember(field, path) {
|
|
491
|
+
let current = field;
|
|
492
|
+
for (const segment of path) {
|
|
493
|
+
const member = current.fields?.find((candidate) => candidate.fieldId === segment);
|
|
494
|
+
if (member === undefined)
|
|
495
|
+
return undefined;
|
|
496
|
+
current = member;
|
|
497
|
+
}
|
|
498
|
+
return current;
|
|
499
|
+
}
|
|
500
|
+
function boundFromHint(family, value) {
|
|
501
|
+
switch (family) {
|
|
502
|
+
case 'integer':
|
|
503
|
+
case 'money':
|
|
504
|
+
case 'duration':
|
|
505
|
+
return integerBound(BigInt(value));
|
|
506
|
+
case 'decimal':
|
|
507
|
+
return decimalBound(String(value));
|
|
508
|
+
case 'date':
|
|
509
|
+
return scalarBound(daysFromCivilValue(String(value)));
|
|
510
|
+
case 'instant':
|
|
511
|
+
return scalarBound(instantToEpochMilliseconds(String(value)));
|
|
512
|
+
case 'time':
|
|
513
|
+
return scalarBound(secondsSinceMidnight(parseClockTime(String(value))));
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
function fieldInterval(field) {
|
|
517
|
+
const family = familyOfPrimitive(field.primitive);
|
|
518
|
+
if (family === undefined)
|
|
519
|
+
return TOP;
|
|
520
|
+
const min = field.minimum;
|
|
521
|
+
const max = field.maximum;
|
|
522
|
+
if (min === undefined && max === undefined)
|
|
523
|
+
return TOP;
|
|
524
|
+
try {
|
|
525
|
+
const minBound = min === undefined ? null : boundFromHint(family, min);
|
|
526
|
+
const maxBound = max === undefined ? null : boundFromHint(family, max);
|
|
527
|
+
return range(family, minBound, maxBound);
|
|
528
|
+
}
|
|
529
|
+
catch {
|
|
530
|
+
return TOP;
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
function intervalOf(node, declarations, environment, itemFieldId) {
|
|
534
|
+
switch (node.kind) {
|
|
535
|
+
case 'literal':
|
|
536
|
+
return literalInterval(node);
|
|
537
|
+
case 'path': {
|
|
538
|
+
const narrowed = environment.get(node.path);
|
|
539
|
+
if (narrowed !== undefined)
|
|
540
|
+
return narrowed;
|
|
541
|
+
const field = fieldAtPath(declarations, node.path, itemFieldId);
|
|
542
|
+
return field === undefined ? TOP : fieldInterval(field);
|
|
543
|
+
}
|
|
544
|
+
case 'list':
|
|
545
|
+
return TOP;
|
|
546
|
+
case 'and':
|
|
547
|
+
case 'or':
|
|
548
|
+
case 'not':
|
|
549
|
+
case 'compare':
|
|
550
|
+
case 'if':
|
|
551
|
+
case 'coalesce':
|
|
552
|
+
case 'comprehension':
|
|
553
|
+
return TOP;
|
|
554
|
+
case 'call':
|
|
555
|
+
return callInterval(node, declarations, environment, itemFieldId);
|
|
556
|
+
}
|
|
557
|
+
}
|
|
558
|
+
function literalInterval(node) {
|
|
559
|
+
switch (node.domain) {
|
|
560
|
+
case 'integer':
|
|
561
|
+
return typeof node.value === 'number' && Number.isSafeInteger(node.value)
|
|
562
|
+
? constant('integer', BigInt(node.value))
|
|
563
|
+
: TOP;
|
|
564
|
+
case 'decimal':
|
|
565
|
+
return typeof node.value === 'string'
|
|
566
|
+
? constant('decimal', asDecimalString(node.value))
|
|
567
|
+
: TOP;
|
|
568
|
+
case 'money':
|
|
569
|
+
if (!isRecord(node.value))
|
|
570
|
+
return TOP;
|
|
571
|
+
return typeof node.value['minor'] === 'string'
|
|
572
|
+
? constant('money', BigInt(node.value['minor']))
|
|
573
|
+
: TOP;
|
|
574
|
+
case 'quantity':
|
|
575
|
+
if (!isRecord(node.value))
|
|
576
|
+
return TOP;
|
|
577
|
+
return typeof node.value['value'] === 'string'
|
|
578
|
+
? constant('decimal', asDecimalString(node.value['value']))
|
|
579
|
+
: TOP;
|
|
580
|
+
case 'duration':
|
|
581
|
+
if (!isRecord(node.value))
|
|
582
|
+
return TOP;
|
|
583
|
+
return typeof node.value['amount'] === 'number' && Number.isSafeInteger(node.value['amount'])
|
|
584
|
+
? constant('duration', BigInt(node.value['amount']))
|
|
585
|
+
: TOP;
|
|
586
|
+
case 'date':
|
|
587
|
+
return typeof node.value === 'string'
|
|
588
|
+
? constant('date', daysFromCivilValue(node.value))
|
|
589
|
+
: TOP;
|
|
590
|
+
case 'instant':
|
|
591
|
+
return typeof node.value === 'string'
|
|
592
|
+
? constant('instant', instantToEpochMilliseconds(node.value))
|
|
593
|
+
: TOP;
|
|
594
|
+
case 'time':
|
|
595
|
+
return typeof node.value === 'string'
|
|
596
|
+
? constant('time', secondsSinceMidnight(parseClockTime(node.value)))
|
|
597
|
+
: TOP;
|
|
598
|
+
default:
|
|
599
|
+
return TOP;
|
|
600
|
+
}
|
|
601
|
+
}
|
|
602
|
+
function daysFromCivilValue(text) {
|
|
603
|
+
const date = parsePlainDate(text);
|
|
604
|
+
return daysFromCivil(date.year, date.month, date.day);
|
|
605
|
+
}
|
|
606
|
+
function callInterval(node, declarations, environment, itemFieldId) {
|
|
607
|
+
if (node.op === '+' || node.op === '-' || node.op === '*' || node.op === '/') {
|
|
608
|
+
return arithmeticIntervals(node.op, node.args.map((arg) => intervalOf(arg, declarations, environment, itemFieldId)));
|
|
609
|
+
}
|
|
610
|
+
switch (node.op) {
|
|
611
|
+
case 'len': {
|
|
612
|
+
const [operand] = node.args;
|
|
613
|
+
if (operand?.kind === 'list')
|
|
614
|
+
return constant('integer', BigInt(operand.items.length));
|
|
615
|
+
if (operand?.kind === 'literal' && typeof operand.value === 'string') {
|
|
616
|
+
return constant('integer', BigInt(codePointLength(operand.value)));
|
|
617
|
+
}
|
|
618
|
+
if (operand?.kind === 'path') {
|
|
619
|
+
const field = fieldAtPath(declarations, operand.path, itemFieldId);
|
|
620
|
+
if (field?.primitive === 'array') {
|
|
621
|
+
return range('integer', field.minItems === undefined ? null : integerBound(BigInt(field.minItems)), field.maxItems === undefined ? null : integerBound(BigInt(field.maxItems)));
|
|
622
|
+
}
|
|
623
|
+
}
|
|
624
|
+
return TOP;
|
|
625
|
+
}
|
|
626
|
+
case 'index_of': {
|
|
627
|
+
const [haystack, needle] = node.args;
|
|
628
|
+
if (haystack?.kind === 'literal' &&
|
|
629
|
+
typeof haystack.value === 'string' &&
|
|
630
|
+
needle?.kind === 'literal' &&
|
|
631
|
+
typeof needle.value === 'string') {
|
|
632
|
+
return constant('integer', BigInt(codePointIndexOf(haystack.value, needle.value)));
|
|
633
|
+
}
|
|
634
|
+
if (haystack?.kind === 'literal' && typeof haystack.value === 'string') {
|
|
635
|
+
return range('integer', integerBound(-1n), integerBound(BigInt(codePointLength(haystack.value) - 1)));
|
|
636
|
+
}
|
|
637
|
+
return TOP;
|
|
638
|
+
}
|
|
639
|
+
case 'year':
|
|
640
|
+
case 'month':
|
|
641
|
+
case 'day':
|
|
642
|
+
case 'weekday': {
|
|
643
|
+
const value = intervalOf(node.args[0] ?? { kind: 'literal', domain: 'null', value: null }, declarations, environment, itemFieldId);
|
|
644
|
+
return temporalPartInterval(node.op, value);
|
|
645
|
+
}
|
|
646
|
+
case 'days_between': {
|
|
647
|
+
const left = intervalOf(node.args[0] ?? { kind: 'literal', domain: 'null', value: null }, declarations, environment, itemFieldId);
|
|
648
|
+
const right = intervalOf(node.args[1] ?? { kind: 'literal', domain: 'null', value: null }, declarations, environment, itemFieldId);
|
|
649
|
+
if (isConstant(left) && isConstant(right)) {
|
|
650
|
+
const a = left.min;
|
|
651
|
+
const b = right.min;
|
|
652
|
+
if (a?.kind === 'scalar' && b?.kind === 'scalar') {
|
|
653
|
+
const aDate = civilOfDays(a.value);
|
|
654
|
+
const bDate = civilOfDays(b.value);
|
|
655
|
+
return constant('integer', BigInt(daysBetween(aDate, bDate)));
|
|
656
|
+
}
|
|
657
|
+
}
|
|
658
|
+
return TOP;
|
|
659
|
+
}
|
|
660
|
+
case 'months_between': {
|
|
661
|
+
const left = intervalOf(node.args[0] ?? { kind: 'literal', domain: 'null', value: null }, declarations, environment, itemFieldId);
|
|
662
|
+
const right = intervalOf(node.args[1] ?? { kind: 'literal', domain: 'null', value: null }, declarations, environment, itemFieldId);
|
|
663
|
+
if (isConstant(left) && isConstant(right)) {
|
|
664
|
+
const a = left.min;
|
|
665
|
+
const b = right.min;
|
|
666
|
+
if (a?.kind === 'scalar' && b?.kind === 'scalar') {
|
|
667
|
+
const aDate = civilOfDays(a.value);
|
|
668
|
+
const bDate = civilOfDays(b.value);
|
|
669
|
+
return constant('integer', BigInt(monthsBetween(aDate, bDate)));
|
|
670
|
+
}
|
|
671
|
+
}
|
|
672
|
+
return TOP;
|
|
673
|
+
}
|
|
674
|
+
case 'minutes_between': {
|
|
675
|
+
const left = intervalOf(node.args[0] ?? { kind: 'literal', domain: 'null', value: null }, declarations, environment, itemFieldId);
|
|
676
|
+
const right = intervalOf(node.args[1] ?? { kind: 'literal', domain: 'null', value: null }, declarations, environment, itemFieldId);
|
|
677
|
+
if (left.kind === 'range' && right.kind === 'range') {
|
|
678
|
+
if (left.family === 'instant' &&
|
|
679
|
+
right.family === 'instant' &&
|
|
680
|
+
isConstant(left) &&
|
|
681
|
+
isConstant(right) &&
|
|
682
|
+
left.min?.kind === 'scalar' &&
|
|
683
|
+
right.min?.kind === 'scalar') {
|
|
684
|
+
return constant('integer', BigInt(minutesBetweenInstants(civilInstant(left.min.value), civilInstant(right.min.value))));
|
|
685
|
+
}
|
|
686
|
+
if (left.family === 'time' &&
|
|
687
|
+
right.family === 'time' &&
|
|
688
|
+
isConstant(left) &&
|
|
689
|
+
isConstant(right) &&
|
|
690
|
+
left.min?.kind === 'scalar' &&
|
|
691
|
+
right.min?.kind === 'scalar') {
|
|
692
|
+
return constant('integer', BigInt(minutesBetweenTimes(clockText(left.min.value), clockText(right.min.value))));
|
|
693
|
+
}
|
|
694
|
+
}
|
|
695
|
+
return TOP;
|
|
696
|
+
}
|
|
697
|
+
case 'duration_minutes':
|
|
698
|
+
case 'duration_seconds': {
|
|
699
|
+
const value = intervalOf(node.args[0] ?? { kind: 'literal', domain: 'null', value: null }, declarations, environment, itemFieldId);
|
|
700
|
+
return durationConversion(value, node.op === 'duration_minutes' ? 1n : 60n);
|
|
701
|
+
}
|
|
702
|
+
case 'money_minor': {
|
|
703
|
+
const value = intervalOf(node.args[0] ?? { kind: 'literal', domain: 'null', value: null }, declarations, environment, itemFieldId);
|
|
704
|
+
return moneyMinorInterval(value);
|
|
705
|
+
}
|
|
706
|
+
case 'abs': {
|
|
707
|
+
return absoluteInterval(intervalOf(node.args[0] ?? { kind: 'literal', domain: 'null', value: null }, declarations, environment, itemFieldId));
|
|
708
|
+
}
|
|
709
|
+
case 'sum':
|
|
710
|
+
case 'min':
|
|
711
|
+
case 'max':
|
|
712
|
+
return aggregateInterval(node.op, node.args[0], declarations, environment, itemFieldId);
|
|
713
|
+
default:
|
|
714
|
+
return TOP;
|
|
715
|
+
}
|
|
716
|
+
}
|
|
717
|
+
function civilOfDays(days) {
|
|
718
|
+
const date = civilFromDays(days);
|
|
719
|
+
return { year: date.year, month: date.month, day: date.day };
|
|
720
|
+
}
|
|
721
|
+
function civilInstant(milliseconds) {
|
|
722
|
+
const days = Math.floor(milliseconds / 86_400_000);
|
|
723
|
+
let rest = milliseconds - days * 86_400_000;
|
|
724
|
+
const date = civilFromDays(days);
|
|
725
|
+
const pad = (value, width) => String(value).padStart(width, '0');
|
|
726
|
+
const hour = Math.floor(rest / 3_600_000);
|
|
727
|
+
rest -= hour * 3_600_000;
|
|
728
|
+
const minute = Math.floor(rest / 60_000);
|
|
729
|
+
rest -= minute * 60_000;
|
|
730
|
+
const second = Math.floor(rest / 1_000);
|
|
731
|
+
rest -= second * 1_000;
|
|
732
|
+
return `${pad(date.year, 4)}-${pad(date.month, 2)}-${pad(date.day, 2)}T${pad(hour, 2)}:${pad(minute, 2)}:${pad(second, 2)}.${pad(rest, 3)}Z`;
|
|
733
|
+
}
|
|
734
|
+
function clockText(seconds) {
|
|
735
|
+
const hours = Math.floor(seconds / 3600);
|
|
736
|
+
const minutes = Math.floor((seconds % 3600) / 60);
|
|
737
|
+
const remainder = seconds % 60;
|
|
738
|
+
return `${String(hours).padStart(2, '0')}:${String(minutes).padStart(2, '0')}${remainder === 0 ? '' : `:${String(remainder).padStart(2, '0')}`}`;
|
|
739
|
+
}
|
|
740
|
+
function temporalPartInterval(op, value) {
|
|
741
|
+
if (op === 'weekday') {
|
|
742
|
+
return value.kind === 'range' && value.family === 'date'
|
|
743
|
+
? range('integer', integerBound(1n), integerBound(7n))
|
|
744
|
+
: TOP;
|
|
745
|
+
}
|
|
746
|
+
if (value.kind !== 'range' || value.family !== 'date')
|
|
747
|
+
return TOP;
|
|
748
|
+
if (isConstant(value) && value.min?.kind === 'scalar') {
|
|
749
|
+
const date = civilOfDays(value.min.value);
|
|
750
|
+
return constant('integer', BigInt(op === 'year' ? date.year : op === 'month' ? date.month : date.day));
|
|
751
|
+
}
|
|
752
|
+
if (op === 'month')
|
|
753
|
+
return range('integer', integerBound(1n), integerBound(12n));
|
|
754
|
+
if (op === 'day')
|
|
755
|
+
return range('integer', integerBound(1n), integerBound(31n));
|
|
756
|
+
if (value.min?.kind !== 'scalar' || value.max?.kind !== 'scalar')
|
|
757
|
+
return TOP;
|
|
758
|
+
const first = civilOfDays(value.min.value);
|
|
759
|
+
const last = civilOfDays(value.max.value);
|
|
760
|
+
return range('integer', integerBound(BigInt(first.year)), integerBound(BigInt(last.year)));
|
|
761
|
+
}
|
|
762
|
+
function durationConversion(value, factor) {
|
|
763
|
+
if (value.kind !== 'range' || value.family !== 'duration')
|
|
764
|
+
return TOP;
|
|
765
|
+
const convert = (bound) => {
|
|
766
|
+
if (bound === null)
|
|
767
|
+
return null;
|
|
768
|
+
if (bound.kind !== 'integer')
|
|
769
|
+
return null;
|
|
770
|
+
const product = bound.value * factor;
|
|
771
|
+
return product > MAX_SAFE_INTEGER || product < MIN_SAFE_INTEGER ? null : integerBound(product);
|
|
772
|
+
};
|
|
773
|
+
return range('integer', convert(value.min), convert(value.max), value.minInclusive, value.maxInclusive);
|
|
774
|
+
}
|
|
775
|
+
function moneyMinorInterval(value) {
|
|
776
|
+
if (value.kind !== 'range' || value.family !== 'money')
|
|
777
|
+
return TOP;
|
|
778
|
+
const convert = (bound) => bound?.kind === 'integer' ? decimalBound(bound.value.toString()) : null;
|
|
779
|
+
return range('decimal', convert(value.min), convert(value.max), value.minInclusive, value.maxInclusive);
|
|
780
|
+
}
|
|
781
|
+
function absoluteInterval(value) {
|
|
782
|
+
if (value.kind !== 'range' || (value.family !== 'integer' && value.family !== 'decimal')) {
|
|
783
|
+
return TOP;
|
|
784
|
+
}
|
|
785
|
+
if (value.min === null || value.max === null)
|
|
786
|
+
return TOP;
|
|
787
|
+
const zero = value.family === 'integer' ? integerBound(0n) : decimalBound('0');
|
|
788
|
+
const lower = compareBounds(value.min, zero) === 1 ? value.min : zero;
|
|
789
|
+
const upperCandidate = compareBounds(value.max, zero) === -1 ? negateBound(value.max) : value.max;
|
|
790
|
+
if (upperCandidate === undefined)
|
|
791
|
+
return TOP;
|
|
792
|
+
return range(value.family, lower, upperCandidate);
|
|
793
|
+
}
|
|
794
|
+
function negateBound(bound) {
|
|
795
|
+
if (bound.kind === 'integer') {
|
|
796
|
+
return bound.value === MIN_SAFE_INTEGER ? undefined : integerBound(-bound.value);
|
|
797
|
+
}
|
|
798
|
+
if (bound.kind === 'decimal') {
|
|
799
|
+
return decimalBound(canonicalDecimal(parseDecimal(bound.value).negated()));
|
|
800
|
+
}
|
|
801
|
+
return scalarBound(-bound.value);
|
|
802
|
+
}
|
|
803
|
+
function aggregateInterval(op, operand, declarations, environment, itemFieldId) {
|
|
804
|
+
if (operand?.kind !== 'list' || operand.items.length === 0)
|
|
805
|
+
return TOP;
|
|
806
|
+
const items = operand.items.map((item) => intervalOf(item, declarations, environment, itemFieldId));
|
|
807
|
+
if (items.some((item) => item.kind === 'top' || item.kind === 'empty'))
|
|
808
|
+
return TOP;
|
|
809
|
+
if (op === 'min' || op === 'max') {
|
|
810
|
+
const ranges = items.filter((item) => item.kind === 'range');
|
|
811
|
+
if (ranges.length !== items.length)
|
|
812
|
+
return TOP;
|
|
813
|
+
const numeric = ranges.every((range) => range.family === 'integer' || range.family === 'decimal');
|
|
814
|
+
const normalized = numeric ? ranges.map(toDecimal) : ranges;
|
|
815
|
+
const normalizedRanges = normalized.filter((item) => item.kind === 'range');
|
|
816
|
+
if (normalizedRanges.length !== normalized.length)
|
|
817
|
+
return TOP;
|
|
818
|
+
const family = normalizedRanges[0]?.family;
|
|
819
|
+
if (family === undefined || normalizedRanges.some((range) => range.family !== family)) {
|
|
820
|
+
return TOP;
|
|
821
|
+
}
|
|
822
|
+
if (normalizedRanges.every((range) => range.min === null || range.max === null))
|
|
823
|
+
return TOP;
|
|
824
|
+
const lower = op === 'min'
|
|
825
|
+
? normalizedRanges.reduce((chosen, range) => lesserBound(chosen, range.min), null)
|
|
826
|
+
: normalizedRanges.reduce((chosen, range) => greaterBound(chosen, range.min), null);
|
|
827
|
+
const upper = op === 'min'
|
|
828
|
+
? normalizedRanges.reduce((chosen, range) => lesserBound(chosen, range.max), null)
|
|
829
|
+
: normalizedRanges.reduce((chosen, range) => greaterBound(chosen, range.max), null);
|
|
830
|
+
return range(family, lower, upper);
|
|
831
|
+
}
|
|
832
|
+
const numeric = items.map(toDecimal);
|
|
833
|
+
if (numeric.some((item) => item.kind !== 'range'))
|
|
834
|
+
return TOP;
|
|
835
|
+
let lower = decimalBound('0');
|
|
836
|
+
let upper = decimalBound('0');
|
|
837
|
+
for (const item of numeric) {
|
|
838
|
+
if (item.kind !== 'range')
|
|
839
|
+
return TOP;
|
|
840
|
+
lower = addBounds(lower, item.min, 'decimal');
|
|
841
|
+
upper = addBounds(upper, item.max, 'decimal');
|
|
842
|
+
if (lower === null || upper === null)
|
|
843
|
+
return TOP;
|
|
844
|
+
}
|
|
845
|
+
return range('decimal', lower, upper);
|
|
846
|
+
}
|
|
847
|
+
function truthOfLiteral(node) {
|
|
848
|
+
// The analyzer is called from untyped probe code as well as from the checker; a missing node
|
|
849
|
+
// is "cannot say", never a property read on `undefined`.
|
|
850
|
+
if (node === undefined)
|
|
851
|
+
return undefined;
|
|
852
|
+
if (node.kind !== 'literal' || node.domain !== 'boolean')
|
|
853
|
+
return undefined;
|
|
854
|
+
return node.value === true ? 'true' : 'false';
|
|
855
|
+
}
|
|
856
|
+
function comparisonTruth(op, left, right) {
|
|
857
|
+
if (left.kind === 'top' || right.kind === 'top')
|
|
858
|
+
return 'unknown';
|
|
859
|
+
if (left.kind === 'empty' || right.kind === 'empty')
|
|
860
|
+
return 'unknown';
|
|
861
|
+
if (left.family !== right.family)
|
|
862
|
+
return 'unknown';
|
|
863
|
+
if (op === '==') {
|
|
864
|
+
if (isConstant(left) && isConstant(right)) {
|
|
865
|
+
if (left.min === null || right.min === null)
|
|
866
|
+
return 'unknown';
|
|
867
|
+
return sameBound(left.min, right.min) ? 'true' : 'false';
|
|
868
|
+
}
|
|
869
|
+
return 'unknown';
|
|
870
|
+
}
|
|
871
|
+
if (op === '!=') {
|
|
872
|
+
if (isConstant(left) && isConstant(right)) {
|
|
873
|
+
if (left.min === null || right.min === null)
|
|
874
|
+
return 'unknown';
|
|
875
|
+
return sameBound(left.min, right.min) ? 'false' : 'true';
|
|
876
|
+
}
|
|
877
|
+
if (left.max !== null && right.min !== null) {
|
|
878
|
+
const order = compareBounds(left.max, right.min);
|
|
879
|
+
if (order === -1 || (order === 0 && (!left.maxInclusive || !right.minInclusive))) {
|
|
880
|
+
return 'true';
|
|
881
|
+
}
|
|
882
|
+
}
|
|
883
|
+
if (left.min !== null && right.max !== null) {
|
|
884
|
+
const order = compareBounds(left.min, right.max);
|
|
885
|
+
if (order === 1 || (order === 0 && (!left.minInclusive || !right.maxInclusive))) {
|
|
886
|
+
return 'true';
|
|
887
|
+
}
|
|
888
|
+
}
|
|
889
|
+
return 'unknown';
|
|
890
|
+
}
|
|
891
|
+
return orderTruth(op, left, right);
|
|
892
|
+
}
|
|
893
|
+
function orderTruth(op, left, right) {
|
|
894
|
+
if (op === '>')
|
|
895
|
+
return orderTruth('<', right, left);
|
|
896
|
+
if (op === '>=')
|
|
897
|
+
return orderTruth('<=', right, left);
|
|
898
|
+
if (op === '<') {
|
|
899
|
+
if (left.max !== null && right.min !== null) {
|
|
900
|
+
const order = compareBounds(left.max, right.min);
|
|
901
|
+
if (order === -1)
|
|
902
|
+
return 'true';
|
|
903
|
+
if (order === 0 && (!left.maxInclusive || !right.minInclusive))
|
|
904
|
+
return 'true';
|
|
905
|
+
// `left.max > right.min` proves only that the comparison is not always true: two
|
|
906
|
+
// overlapping ranges satisfy it and still hold for some pair of values. "Always false"
|
|
907
|
+
// is the second block's question, where `left.min` meets `right.max`.
|
|
908
|
+
}
|
|
909
|
+
if (left.min !== null && right.max !== null) {
|
|
910
|
+
const order = compareBounds(left.min, right.max);
|
|
911
|
+
if (order === 1)
|
|
912
|
+
return 'false';
|
|
913
|
+
if (order === 0 && (!left.minInclusive || !right.maxInclusive))
|
|
914
|
+
return 'false';
|
|
915
|
+
}
|
|
916
|
+
return 'unknown';
|
|
917
|
+
}
|
|
918
|
+
if (left.max !== null && right.min !== null) {
|
|
919
|
+
const order = compareBounds(left.max, right.min);
|
|
920
|
+
if (order === -1)
|
|
921
|
+
return 'true';
|
|
922
|
+
if (order === 0)
|
|
923
|
+
return 'true';
|
|
924
|
+
}
|
|
925
|
+
if (left.min !== null && right.max !== null) {
|
|
926
|
+
const order = compareBounds(left.min, right.max);
|
|
927
|
+
if (order === 1)
|
|
928
|
+
return 'false';
|
|
929
|
+
if (order === 0 && (!left.minInclusive || !right.maxInclusive))
|
|
930
|
+
return 'false';
|
|
931
|
+
}
|
|
932
|
+
return 'unknown';
|
|
933
|
+
}
|
|
934
|
+
function compareIntervals(op, left, right) {
|
|
935
|
+
if (left.kind === 'top' || right.kind === 'top')
|
|
936
|
+
return 'unknown';
|
|
937
|
+
if (left.kind === 'empty' || right.kind === 'empty')
|
|
938
|
+
return 'unknown';
|
|
939
|
+
if (left.family !== right.family) {
|
|
940
|
+
const numeric = (family) => family === 'integer' || family === 'decimal';
|
|
941
|
+
if (!numeric(left.family) || !numeric(right.family))
|
|
942
|
+
return 'unknown';
|
|
943
|
+
return compareIntervals(op, toDecimal(left), toDecimal(right));
|
|
944
|
+
}
|
|
945
|
+
if (op === '==' || op === '!=')
|
|
946
|
+
return comparisonTruth(op, left, right);
|
|
947
|
+
if (op === '<' || op === '<=')
|
|
948
|
+
return orderTruth(op, left, right);
|
|
949
|
+
return orderTruth(op, left, right);
|
|
950
|
+
}
|
|
951
|
+
function conditionFacts(node, declarations, environment, itemFieldId) {
|
|
952
|
+
if (node === undefined)
|
|
953
|
+
return { truth: 'unknown', derived: false, environment };
|
|
954
|
+
const literal = truthOfLiteral(node);
|
|
955
|
+
if (literal !== undefined) {
|
|
956
|
+
return { truth: literal, derived: false, environment };
|
|
957
|
+
}
|
|
958
|
+
switch (node.kind) {
|
|
959
|
+
case 'not': {
|
|
960
|
+
const child = conditionFacts(node.args[0] ?? { kind: 'literal', domain: 'null', value: null }, declarations, environment, itemFieldId);
|
|
961
|
+
return {
|
|
962
|
+
truth: child.truth === 'true' ? 'false' : child.truth === 'false' ? 'true' : 'unknown',
|
|
963
|
+
derived: child.derived,
|
|
964
|
+
environment,
|
|
965
|
+
};
|
|
966
|
+
}
|
|
967
|
+
case 'and': {
|
|
968
|
+
let current = environment;
|
|
969
|
+
let unknown = false;
|
|
970
|
+
let derived = false;
|
|
971
|
+
for (const arg of node.args) {
|
|
972
|
+
const child = conditionFacts(arg, declarations, current, itemFieldId);
|
|
973
|
+
derived = derived || child.derived;
|
|
974
|
+
if (child.truth === 'false') {
|
|
975
|
+
return { truth: 'false', derived, environment: current };
|
|
976
|
+
}
|
|
977
|
+
if (child.truth === 'unknown')
|
|
978
|
+
unknown = true;
|
|
979
|
+
current = child.environment;
|
|
980
|
+
}
|
|
981
|
+
return { truth: unknown ? 'unknown' : 'true', derived, environment: current };
|
|
982
|
+
}
|
|
983
|
+
case 'or': {
|
|
984
|
+
let unknown = false;
|
|
985
|
+
let derived = false;
|
|
986
|
+
let merged;
|
|
987
|
+
for (const arg of node.args) {
|
|
988
|
+
const child = conditionFacts(arg, declarations, environment, itemFieldId);
|
|
989
|
+
derived = derived || child.derived;
|
|
990
|
+
if (child.truth === 'true') {
|
|
991
|
+
return { truth: 'true', derived, environment };
|
|
992
|
+
}
|
|
993
|
+
if (child.truth === 'unknown')
|
|
994
|
+
unknown = true;
|
|
995
|
+
if (merged === undefined)
|
|
996
|
+
merged = child.environment;
|
|
997
|
+
else {
|
|
998
|
+
const union = new Map();
|
|
999
|
+
for (const [path, interval] of merged) {
|
|
1000
|
+
const other = child.environment.get(path);
|
|
1001
|
+
if (other === undefined)
|
|
1002
|
+
continue;
|
|
1003
|
+
const united = unite(interval, other);
|
|
1004
|
+
if (united.kind === 'range' || united.kind === 'empty')
|
|
1005
|
+
union.set(path, united);
|
|
1006
|
+
}
|
|
1007
|
+
merged = union;
|
|
1008
|
+
}
|
|
1009
|
+
}
|
|
1010
|
+
return { truth: unknown ? 'unknown' : 'false', derived, environment: merged ?? environment };
|
|
1011
|
+
}
|
|
1012
|
+
case 'compare': {
|
|
1013
|
+
const [leftNode, rightNode] = node.args;
|
|
1014
|
+
if (leftNode === undefined || rightNode === undefined) {
|
|
1015
|
+
return { truth: 'unknown', derived: false, environment };
|
|
1016
|
+
}
|
|
1017
|
+
const left = intervalOf(leftNode, declarations, environment, itemFieldId);
|
|
1018
|
+
const right = intervalOf(rightNode, declarations, environment, itemFieldId);
|
|
1019
|
+
const truth = node.op === 'in' ? 'unknown' : compareIntervals(node.op, left, right);
|
|
1020
|
+
const narrowed = narrowComparison(node.op, leftNode, rightNode, left, right, environment);
|
|
1021
|
+
return { truth, derived: true, environment: narrowed };
|
|
1022
|
+
}
|
|
1023
|
+
case 'call': {
|
|
1024
|
+
if (node.op === 'between')
|
|
1025
|
+
return betweenFacts(node, declarations, environment, itemFieldId);
|
|
1026
|
+
return { truth: 'unknown', derived: false, environment };
|
|
1027
|
+
}
|
|
1028
|
+
default:
|
|
1029
|
+
return { truth: 'unknown', derived: false, environment };
|
|
1030
|
+
}
|
|
1031
|
+
}
|
|
1032
|
+
function narrowComparison(op, leftNode, rightNode, left, right, environment) {
|
|
1033
|
+
if (op === 'in')
|
|
1034
|
+
return environment;
|
|
1035
|
+
if (leftNode.kind !== 'path' && rightNode.kind !== 'path')
|
|
1036
|
+
return environment;
|
|
1037
|
+
const next = new Map(environment);
|
|
1038
|
+
if (leftNode.kind === 'path' && right.kind === 'range') {
|
|
1039
|
+
next.set(leftNode.path, narrowByComparison(op, left, right));
|
|
1040
|
+
}
|
|
1041
|
+
if (rightNode.kind === 'path' && left.kind === 'range') {
|
|
1042
|
+
const inverted = op === '<' ? '>' : op === '<=' ? '>=' : op === '>' ? '<' : op === '>=' ? '<=' : op;
|
|
1043
|
+
next.set(rightNode.path, narrowByComparison(inverted, right, left));
|
|
1044
|
+
}
|
|
1045
|
+
return next;
|
|
1046
|
+
}
|
|
1047
|
+
function narrowByComparison(op, current, other) {
|
|
1048
|
+
const existing = current.kind === 'range' ? current : unbounded(other.family);
|
|
1049
|
+
const lower = op === '>' || op === '>='
|
|
1050
|
+
? range(other.family, other.min, null, op === '>=' ? true : false)
|
|
1051
|
+
: op === '=='
|
|
1052
|
+
? range(other.family, other.min, other.max, other.minInclusive, other.maxInclusive)
|
|
1053
|
+
: unbounded(other.family);
|
|
1054
|
+
const upper = op === '<' || op === '<='
|
|
1055
|
+
? range(other.family, null, other.max, true, op === '<=' ? true : false)
|
|
1056
|
+
: unbounded(other.family);
|
|
1057
|
+
const narrowed = op === '==' ? lower : intersect(lower, upper);
|
|
1058
|
+
const result = intersect(existing, narrowed);
|
|
1059
|
+
return result.kind === 'range'
|
|
1060
|
+
? result
|
|
1061
|
+
: result.kind === 'empty'
|
|
1062
|
+
? result
|
|
1063
|
+
: unbounded(other.family);
|
|
1064
|
+
}
|
|
1065
|
+
function betweenFacts(node, declarations, environment, itemFieldId) {
|
|
1066
|
+
const [valueNode, lowNode, highNode] = node.args;
|
|
1067
|
+
if (valueNode === undefined || lowNode === undefined || highNode === undefined) {
|
|
1068
|
+
return { truth: 'unknown', derived: false, environment };
|
|
1069
|
+
}
|
|
1070
|
+
const value = intervalOf(valueNode, declarations, environment, itemFieldId);
|
|
1071
|
+
const low = intervalOf(lowNode, declarations, environment, itemFieldId);
|
|
1072
|
+
const high = intervalOf(highNode, declarations, environment, itemFieldId);
|
|
1073
|
+
if (isConstant(low) && isConstant(high) && low.min !== null && high.min !== null) {
|
|
1074
|
+
if (compareBounds(low.min, high.min) === 1) {
|
|
1075
|
+
return { truth: 'false', derived: true, environment };
|
|
1076
|
+
}
|
|
1077
|
+
}
|
|
1078
|
+
if (value.kind !== 'range' || low.kind !== 'range' || high.kind !== 'range') {
|
|
1079
|
+
return { truth: 'unknown', derived: true, environment };
|
|
1080
|
+
}
|
|
1081
|
+
const lowerTruth = compareIntervals('>=', value, low);
|
|
1082
|
+
const upperTruth = compareIntervals('<=', value, high);
|
|
1083
|
+
if (lowerTruth === 'false' || upperTruth === 'false') {
|
|
1084
|
+
return { truth: 'false', derived: true, environment };
|
|
1085
|
+
}
|
|
1086
|
+
if (lowerTruth === 'true' && upperTruth === 'true') {
|
|
1087
|
+
const next = new Map(environment);
|
|
1088
|
+
if (valueNode.kind === 'path') {
|
|
1089
|
+
const narrowed = intersect(value, range(value.family, low.min, high.max, low.minInclusive, high.maxInclusive));
|
|
1090
|
+
if (narrowed.kind === 'range')
|
|
1091
|
+
next.set(valueNode.path, narrowed);
|
|
1092
|
+
}
|
|
1093
|
+
return { truth: 'true', derived: true, environment: next };
|
|
1094
|
+
}
|
|
1095
|
+
return { truth: 'unknown', derived: true, environment };
|
|
1096
|
+
}
|
|
1097
|
+
function shapeOf(node) {
|
|
1098
|
+
if (node.kind === 'compare')
|
|
1099
|
+
return 'comparison';
|
|
1100
|
+
if (node.kind === 'and' || node.kind === 'or')
|
|
1101
|
+
return 'connector';
|
|
1102
|
+
if (node.kind === 'not') {
|
|
1103
|
+
const [child] = node.args;
|
|
1104
|
+
if (child?.kind === 'compare')
|
|
1105
|
+
return 'comparison';
|
|
1106
|
+
}
|
|
1107
|
+
if (node.kind === 'call' && node.op === 'between')
|
|
1108
|
+
return 'comparison';
|
|
1109
|
+
return 'other';
|
|
1110
|
+
}
|
|
1111
|
+
function invalidConstant(node, declarations, environment, itemFieldId) {
|
|
1112
|
+
switch (node.kind) {
|
|
1113
|
+
case 'call': {
|
|
1114
|
+
if (node.op === 'between') {
|
|
1115
|
+
const [valueNode, lowNode, highNode] = node.args;
|
|
1116
|
+
if (valueNode !== undefined && lowNode !== undefined && highNode !== undefined) {
|
|
1117
|
+
const low = intervalOf(lowNode, declarations, environment, itemFieldId);
|
|
1118
|
+
const high = intervalOf(highNode, declarations, environment, itemFieldId);
|
|
1119
|
+
if (isConstant(low) && isConstant(high) && low.min !== null && high.min !== null) {
|
|
1120
|
+
if (compareBounds(low.min, high.min) === 1) {
|
|
1121
|
+
return '`between` states a low bound above its high bound, so the expression is false for every value; write `between(x, low, high)` with `low <= high`';
|
|
1122
|
+
}
|
|
1123
|
+
}
|
|
1124
|
+
}
|
|
1125
|
+
}
|
|
1126
|
+
for (const arg of node.args) {
|
|
1127
|
+
const found = invalidConstant(arg, declarations, environment, itemFieldId);
|
|
1128
|
+
if (found !== undefined)
|
|
1129
|
+
return found;
|
|
1130
|
+
}
|
|
1131
|
+
return undefined;
|
|
1132
|
+
}
|
|
1133
|
+
case 'literal':
|
|
1134
|
+
case 'path':
|
|
1135
|
+
return undefined;
|
|
1136
|
+
case 'list': {
|
|
1137
|
+
for (const item of node.items) {
|
|
1138
|
+
const found = invalidConstant(item, declarations, environment, itemFieldId);
|
|
1139
|
+
if (found !== undefined)
|
|
1140
|
+
return found;
|
|
1141
|
+
}
|
|
1142
|
+
return undefined;
|
|
1143
|
+
}
|
|
1144
|
+
case 'comprehension': {
|
|
1145
|
+
const source = invalidConstant(node.source, declarations, environment, itemFieldId);
|
|
1146
|
+
if (source !== undefined)
|
|
1147
|
+
return source;
|
|
1148
|
+
if (node.valueExpr !== undefined) {
|
|
1149
|
+
const value = invalidConstant(node.valueExpr, declarations, environment, itemFieldId);
|
|
1150
|
+
if (value !== undefined)
|
|
1151
|
+
return value;
|
|
1152
|
+
}
|
|
1153
|
+
if (node.predicate !== undefined) {
|
|
1154
|
+
return invalidConstant(node.predicate, declarations, environment, itemFieldId);
|
|
1155
|
+
}
|
|
1156
|
+
return undefined;
|
|
1157
|
+
}
|
|
1158
|
+
default: {
|
|
1159
|
+
for (const arg of node.args) {
|
|
1160
|
+
const found = invalidConstant(arg, declarations, environment, itemFieldId);
|
|
1161
|
+
if (found !== undefined)
|
|
1162
|
+
return found;
|
|
1163
|
+
}
|
|
1164
|
+
return undefined;
|
|
1165
|
+
}
|
|
1166
|
+
}
|
|
1167
|
+
}
|
|
1168
|
+
/** Analyse one expression against its declarations, without assuming any other rule's outcome. */
|
|
1169
|
+
export function analyzeExpression(declarations, node, itemFieldId) {
|
|
1170
|
+
const environment = new Map();
|
|
1171
|
+
const facts = conditionFacts(node, declarations, environment, itemFieldId);
|
|
1172
|
+
const invalid = invalidConstant(node, declarations, environment, itemFieldId);
|
|
1173
|
+
return {
|
|
1174
|
+
truth: facts.truth,
|
|
1175
|
+
derived: facts.derived,
|
|
1176
|
+
shape: shapeOf(node),
|
|
1177
|
+
...(invalid === undefined ? {} : { invalidConstant: invalid }),
|
|
1178
|
+
};
|
|
1179
|
+
}
|
|
1180
|
+
//# sourceMappingURL=interval.js.map
|