fhirpath-ts 0.0.0-bootstrap.0
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 +201 -0
- package/README.md +391 -0
- package/THIRD-PARTY-NOTICES.md +296 -0
- package/dist/analyzer/analyze-dto.d.ts +45 -0
- package/dist/analyzer/analyze-dto.d.ts.map +1 -0
- package/dist/analyzer/analyze-dto.js +147 -0
- package/dist/analyzer/analyze-dto.js.map +1 -0
- package/dist/analyzer/analyze.d.ts +98 -0
- package/dist/analyzer/analyze.d.ts.map +1 -0
- package/dist/analyzer/analyze.js +925 -0
- package/dist/analyzer/analyze.js.map +1 -0
- package/dist/analyzer/expression-policy.d.ts +210 -0
- package/dist/analyzer/expression-policy.d.ts.map +1 -0
- package/dist/analyzer/expression-policy.js +254 -0
- package/dist/analyzer/expression-policy.js.map +1 -0
- package/dist/analyzer/index.d.ts +3 -0
- package/dist/analyzer/index.d.ts.map +1 -0
- package/dist/analyzer/index.js +6 -0
- package/dist/analyzer/index.js.map +1 -0
- package/dist/analyzer/regex-safety.d.ts +10 -0
- package/dist/analyzer/regex-safety.d.ts.map +1 -0
- package/dist/analyzer/regex-safety.js +84 -0
- package/dist/analyzer/regex-safety.js.map +1 -0
- package/dist/analyzer/signatures.d.ts +72 -0
- package/dist/analyzer/signatures.d.ts.map +1 -0
- package/dist/analyzer/signatures.js +195 -0
- package/dist/analyzer/signatures.js.map +1 -0
- package/dist/api/bundle.d.ts +29 -0
- package/dist/api/bundle.d.ts.map +1 -0
- package/dist/api/bundle.js +108 -0
- package/dist/api/bundle.js.map +1 -0
- package/dist/api/cache.d.ts +10 -0
- package/dist/api/cache.d.ts.map +1 -0
- package/dist/api/cache.js +38 -0
- package/dist/api/cache.js.map +1 -0
- package/dist/api/column-signature.d.ts +53 -0
- package/dist/api/column-signature.d.ts.map +1 -0
- package/dist/api/column-signature.js +43 -0
- package/dist/api/column-signature.js.map +1 -0
- package/dist/api/compile.d.ts +120 -0
- package/dist/api/compile.d.ts.map +1 -0
- package/dist/api/compile.js +167 -0
- package/dist/api/compile.js.map +1 -0
- package/dist/api/constraints.d.ts +48 -0
- package/dist/api/constraints.d.ts.map +1 -0
- package/dist/api/constraints.js +52 -0
- package/dist/api/constraints.js.map +1 -0
- package/dist/api/dto.d.ts +134 -0
- package/dist/api/dto.d.ts.map +1 -0
- package/dist/api/dto.js +295 -0
- package/dist/api/dto.js.map +1 -0
- package/dist/api/engine.d.ts +136 -0
- package/dist/api/engine.d.ts.map +1 -0
- package/dist/api/engine.js +183 -0
- package/dist/api/engine.js.map +1 -0
- package/dist/api/evaluate.d.ts +7 -0
- package/dist/api/evaluate.d.ts.map +1 -0
- package/dist/api/evaluate.js +10 -0
- package/dist/api/evaluate.js.map +1 -0
- package/dist/api/project.d.ts +89 -0
- package/dist/api/project.d.ts.map +1 -0
- package/dist/api/project.js +150 -0
- package/dist/api/project.js.map +1 -0
- package/dist/api/tagged.d.ts +14 -0
- package/dist/api/tagged.d.ts.map +1 -0
- package/dist/api/tagged.js +13 -0
- package/dist/api/tagged.js.map +1 -0
- package/dist/cli/dto-check.d.ts +25 -0
- package/dist/cli/dto-check.d.ts.map +1 -0
- package/dist/cli/dto-check.js +77 -0
- package/dist/cli/dto-check.js.map +1 -0
- package/dist/cli/fhirpath-check.d.ts +3 -0
- package/dist/cli/fhirpath-check.d.ts.map +1 -0
- package/dist/cli/fhirpath-check.js +149 -0
- package/dist/cli/fhirpath-check.js.map +1 -0
- package/dist/cli/ts-loader.d.mts +3 -0
- package/dist/cli/ts-loader.d.mts.map +1 -0
- package/dist/cli/ts-loader.mjs +48 -0
- package/dist/cli/ts-loader.mjs.map +1 -0
- package/dist/engine/context.d.ts +173 -0
- package/dist/engine/context.d.ts.map +1 -0
- package/dist/engine/context.js +118 -0
- package/dist/engine/context.js.map +1 -0
- package/dist/engine/evaluator.d.ts +7 -0
- package/dist/engine/evaluator.d.ts.map +1 -0
- package/dist/engine/evaluator.js +196 -0
- package/dist/engine/evaluator.js.map +1 -0
- package/dist/engine/navigation.d.ts +11 -0
- package/dist/engine/navigation.d.ts.map +1 -0
- package/dist/engine/navigation.js +102 -0
- package/dist/engine/navigation.js.map +1 -0
- package/dist/engine/operators/collections.d.ts +12 -0
- package/dist/engine/operators/collections.d.ts.map +1 -0
- package/dist/engine/operators/collections.js +31 -0
- package/dist/engine/operators/collections.js.map +1 -0
- package/dist/engine/operators/comparison.d.ts +13 -0
- package/dist/engine/operators/comparison.d.ts.map +1 -0
- package/dist/engine/operators/comparison.js +77 -0
- package/dist/engine/operators/comparison.js.map +1 -0
- package/dist/engine/operators/equality.d.ts +19 -0
- package/dist/engine/operators/equality.d.ts.map +1 -0
- package/dist/engine/operators/equality.js +203 -0
- package/dist/engine/operators/equality.js.map +1 -0
- package/dist/engine/operators/index.d.ts +18 -0
- package/dist/engine/operators/index.d.ts.map +1 -0
- package/dist/engine/operators/index.js +30 -0
- package/dist/engine/operators/index.js.map +1 -0
- package/dist/engine/operators/logic.d.ts +8 -0
- package/dist/engine/operators/logic.d.ts.map +1 -0
- package/dist/engine/operators/logic.js +38 -0
- package/dist/engine/operators/logic.js.map +1 -0
- package/dist/engine/operators/math.d.ts +13 -0
- package/dist/engine/operators/math.d.ts.map +1 -0
- package/dist/engine/operators/math.js +198 -0
- package/dist/engine/operators/math.js.map +1 -0
- package/dist/engine/operators/strings.d.ts +8 -0
- package/dist/engine/operators/strings.d.ts.map +1 -0
- package/dist/engine/operators/strings.js +22 -0
- package/dist/engine/operators/strings.js.map +1 -0
- package/dist/engine/operators/types.d.ts +3 -0
- package/dist/engine/operators/types.d.ts.map +1 -0
- package/dist/engine/operators/types.js +15 -0
- package/dist/engine/operators/types.js.map +1 -0
- package/dist/engine/type-matching.d.ts +20 -0
- package/dist/engine/type-matching.d.ts.map +1 -0
- package/dist/engine/type-matching.js +122 -0
- package/dist/engine/type-matching.js.map +1 -0
- package/dist/errors.d.ts +25 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +21 -0
- package/dist/errors.js.map +1 -0
- package/dist/eslint/index.d.ts +12 -0
- package/dist/eslint/index.d.ts.map +1 -0
- package/dist/eslint/index.js +316 -0
- package/dist/eslint/index.js.map +1 -0
- package/dist/fhir/html-checks.d.ts +7 -0
- package/dist/fhir/html-checks.d.ts.map +1 -0
- package/dist/fhir/html-checks.js +256 -0
- package/dist/fhir/html-checks.js.map +1 -0
- package/dist/fhir/model-navigation.d.ts +11 -0
- package/dist/fhir/model-navigation.d.ts.map +1 -0
- package/dist/fhir/model-navigation.js +142 -0
- package/dist/fhir/model-navigation.js.map +1 -0
- package/dist/functions/aggregate.d.ts +2 -0
- package/dist/functions/aggregate.d.ts.map +1 -0
- package/dist/functions/aggregate.js +127 -0
- package/dist/functions/aggregate.js.map +1 -0
- package/dist/functions/boundary.d.ts +2 -0
- package/dist/functions/boundary.d.ts.map +1 -0
- package/dist/functions/boundary.js +189 -0
- package/dist/functions/boundary.js.map +1 -0
- package/dist/functions/combining.d.ts +2 -0
- package/dist/functions/combining.d.ts.map +1 -0
- package/dist/functions/combining.js +13 -0
- package/dist/functions/combining.js.map +1 -0
- package/dist/functions/control.d.ts +2 -0
- package/dist/functions/control.d.ts.map +1 -0
- package/dist/functions/control.js +25 -0
- package/dist/functions/control.js.map +1 -0
- package/dist/functions/conversion.d.ts +3 -0
- package/dist/functions/conversion.d.ts.map +1 -0
- package/dist/functions/conversion.js +316 -0
- package/dist/functions/conversion.js.map +1 -0
- package/dist/functions/date-components.d.ts +2 -0
- package/dist/functions/date-components.d.ts.map +1 -0
- package/dist/functions/date-components.js +81 -0
- package/dist/functions/date-components.js.map +1 -0
- package/dist/functions/existence.d.ts +4 -0
- package/dist/functions/existence.d.ts.map +1 -0
- package/dist/functions/existence.js +97 -0
- package/dist/functions/existence.js.map +1 -0
- package/dist/functions/fhir.d.ts +2 -0
- package/dist/functions/fhir.d.ts.map +1 -0
- package/dist/functions/fhir.js +222 -0
- package/dist/functions/fhir.js.map +1 -0
- package/dist/functions/filtering.d.ts +2 -0
- package/dist/functions/filtering.d.ts.map +1 -0
- package/dist/functions/filtering.js +112 -0
- package/dist/functions/filtering.js.map +1 -0
- package/dist/functions/install.d.ts +18 -0
- package/dist/functions/install.d.ts.map +1 -0
- package/dist/functions/install.js +20 -0
- package/dist/functions/install.js.map +1 -0
- package/dist/functions/iteration.d.ts +7 -0
- package/dist/functions/iteration.d.ts.map +1 -0
- package/dist/functions/iteration.js +9 -0
- package/dist/functions/iteration.js.map +1 -0
- package/dist/functions/math.d.ts +2 -0
- package/dist/functions/math.d.ts.map +1 -0
- package/dist/functions/math.js +152 -0
- package/dist/functions/math.js.map +1 -0
- package/dist/functions/reflection.d.ts +2 -0
- package/dist/functions/reflection.d.ts.map +1 -0
- package/dist/functions/reflection.js +23 -0
- package/dist/functions/reflection.js.map +1 -0
- package/dist/functions/registry.d.ts +28 -0
- package/dist/functions/registry.d.ts.map +1 -0
- package/dist/functions/registry.js +46 -0
- package/dist/functions/registry.js.map +1 -0
- package/dist/functions/sort.d.ts +2 -0
- package/dist/functions/sort.d.ts.map +1 -0
- package/dist/functions/sort.js +48 -0
- package/dist/functions/sort.js.map +1 -0
- package/dist/functions/string.d.ts +2 -0
- package/dist/functions/string.d.ts.map +1 -0
- package/dist/functions/string.js +353 -0
- package/dist/functions/string.js.map +1 -0
- package/dist/functions/subsetting.d.ts +2 -0
- package/dist/functions/subsetting.d.ts.map +1 -0
- package/dist/functions/subsetting.js +72 -0
- package/dist/functions/subsetting.js.map +1 -0
- package/dist/functions/tree.d.ts +8 -0
- package/dist/functions/tree.d.ts.map +1 -0
- package/dist/functions/tree.js +109 -0
- package/dist/functions/tree.js.map +1 -0
- package/dist/functions/type-specifier.d.ts +8 -0
- package/dist/functions/type-specifier.d.ts.map +1 -0
- package/dist/functions/type-specifier.js +27 -0
- package/dist/functions/type-specifier.js.map +1 -0
- package/dist/functions/utility.d.ts +2 -0
- package/dist/functions/utility.d.ts.map +1 -0
- package/dist/functions/utility.js +76 -0
- package/dist/functions/utility.js.map +1 -0
- package/dist/functions/variables.d.ts +2 -0
- package/dist/functions/variables.d.ts.map +1 -0
- package/dist/functions/variables.js +35 -0
- package/dist/functions/variables.js.map +1 -0
- package/dist/index.d.ts +25 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +11 -0
- package/dist/index.js.map +1 -0
- package/dist/lexer/lexer.d.ts +4 -0
- package/dist/lexer/lexer.d.ts.map +1 -0
- package/dist/lexer/lexer.js +318 -0
- package/dist/lexer/lexer.js.map +1 -0
- package/dist/lexer/tokens.d.ts +23 -0
- package/dist/lexer/tokens.d.ts.map +1 -0
- package/dist/lexer/tokens.js +40 -0
- package/dist/lexer/tokens.js.map +1 -0
- package/dist/model/provider.d.ts +36 -0
- package/dist/model/provider.d.ts.map +1 -0
- package/dist/model/provider.js +2 -0
- package/dist/model/provider.js.map +1 -0
- package/dist/parser/ast.d.ts +104 -0
- package/dist/parser/ast.d.ts.map +1 -0
- package/dist/parser/ast.js +2 -0
- package/dist/parser/ast.js.map +1 -0
- package/dist/parser/parser.d.ts +4 -0
- package/dist/parser/parser.d.ts.map +1 -0
- package/dist/parser/parser.js +299 -0
- package/dist/parser/parser.js.map +1 -0
- package/dist/parser/precedence.d.ts +24 -0
- package/dist/parser/precedence.d.ts.map +1 -0
- package/dist/parser/precedence.js +52 -0
- package/dist/parser/precedence.js.map +1 -0
- package/dist/parser/printer.d.ts +4 -0
- package/dist/parser/printer.d.ts.map +1 -0
- package/dist/parser/printer.js +112 -0
- package/dist/parser/printer.js.map +1 -0
- package/dist/r4/generated/resources-data.d.ts +3 -0
- package/dist/r4/generated/resources-data.d.ts.map +1 -0
- package/dist/r4/generated/resources-data.js +28628 -0
- package/dist/r4/generated/resources-data.js.map +1 -0
- package/dist/r4/generated/type-maps.d.ts +43153 -0
- package/dist/r4/generated/type-maps.d.ts.map +1 -0
- package/dist/r4/generated/type-maps.js +4 -0
- package/dist/r4/generated/type-maps.js.map +1 -0
- package/dist/r4/generated/types-data.d.ts +3 -0
- package/dist/r4/generated/types-data.d.ts.map +1 -0
- package/dist/r4/generated/types-data.js +2205 -0
- package/dist/r4/generated/types-data.js.map +1 -0
- package/dist/r4/index.d.ts +9 -0
- package/dist/r4/index.d.ts.map +1 -0
- package/dist/r4/index.js +94 -0
- package/dist/r4/index.js.map +1 -0
- package/dist/r4/model-data.d.ts +17 -0
- package/dist/r4/model-data.d.ts.map +1 -0
- package/dist/r4/model-data.js +2 -0
- package/dist/r4/model-data.js.map +1 -0
- package/dist/sites/index.d.ts +31 -0
- package/dist/sites/index.d.ts.map +1 -0
- package/dist/sites/index.js +205 -0
- package/dist/sites/index.js.map +1 -0
- package/dist/typed/infer.d.ts +234 -0
- package/dist/typed/infer.d.ts.map +1 -0
- package/dist/typed/infer.js +85 -0
- package/dist/typed/infer.js.map +1 -0
- package/dist/typed/perf-fixture.types.d.ts +136 -0
- package/dist/typed/perf-fixture.types.d.ts.map +1 -0
- package/dist/typed/perf-fixture.types.js +2 -0
- package/dist/typed/perf-fixture.types.js.map +1 -0
- package/dist/values/collection.d.ts +24 -0
- package/dist/values/collection.d.ts.map +1 -0
- package/dist/values/collection.js +51 -0
- package/dist/values/collection.js.map +1 -0
- package/dist/values/datetime.d.ts +54 -0
- package/dist/values/datetime.d.ts.map +1 -0
- package/dist/values/datetime.js +226 -0
- package/dist/values/datetime.js.map +1 -0
- package/dist/values/decimal.d.ts +48 -0
- package/dist/values/decimal.d.ts.map +1 -0
- package/dist/values/decimal.js +188 -0
- package/dist/values/decimal.js.map +1 -0
- package/dist/values/numeric.d.ts +24 -0
- package/dist/values/numeric.d.ts.map +1 -0
- package/dist/values/numeric.js +53 -0
- package/dist/values/numeric.js.map +1 -0
- package/dist/values/quantity.d.ts +49 -0
- package/dist/values/quantity.d.ts.map +1 -0
- package/dist/values/quantity.js +297 -0
- package/dist/values/quantity.js.map +1 -0
- package/dist/values/temporal-arithmetic.d.ts +17 -0
- package/dist/values/temporal-arithmetic.d.ts.map +1 -0
- package/dist/values/temporal-arithmetic.js +183 -0
- package/dist/values/temporal-arithmetic.js.map +1 -0
- package/dist/values/temporal-compare.d.ts +9 -0
- package/dist/values/temporal-compare.d.ts.map +1 -0
- package/dist/values/temporal-compare.js +59 -0
- package/dist/values/temporal-compare.js.map +1 -0
- package/dist/values/type-compat.d.ts +47 -0
- package/dist/values/type-compat.d.ts.map +1 -0
- package/dist/values/type-compat.js +100 -0
- package/dist/values/type-compat.js.map +1 -0
- package/dist/values/typed-value.d.ts +48 -0
- package/dist/values/typed-value.d.ts.map +1 -0
- package/dist/values/typed-value.js +117 -0
- package/dist/values/typed-value.js.map +1 -0
- package/dist/values/ucum.d.ts +14 -0
- package/dist/values/ucum.d.ts.map +1 -0
- package/dist/values/ucum.js +146 -0
- package/dist/values/ucum.js.map +1 -0
- package/package.json +137 -0
- package/src/analyzer/analyze-dto.ts +195 -0
- package/src/analyzer/analyze.ts +1181 -0
- package/src/analyzer/expression-policy.ts +434 -0
- package/src/analyzer/index.ts +23 -0
- package/src/analyzer/regex-safety.ts +85 -0
- package/src/analyzer/signatures.ts +260 -0
- package/src/api/bundle.ts +132 -0
- package/src/api/cache.ts +40 -0
- package/src/api/column-signature.ts +71 -0
- package/src/api/compile.ts +308 -0
- package/src/api/constraints.ts +104 -0
- package/src/api/dto.ts +445 -0
- package/src/api/engine.ts +328 -0
- package/src/api/evaluate.ts +11 -0
- package/src/api/project.ts +255 -0
- package/src/api/tagged.ts +35 -0
- package/src/cli/dto-check.ts +94 -0
- package/src/cli/fhirpath-check.ts +168 -0
- package/src/cli/ts-loader.mjs +49 -0
- package/src/engine/context.ts +282 -0
- package/src/engine/evaluator.ts +246 -0
- package/src/engine/navigation.ts +106 -0
- package/src/engine/operators/collections.ts +34 -0
- package/src/engine/operators/comparison.ts +82 -0
- package/src/engine/operators/equality.ts +232 -0
- package/src/engine/operators/index.ts +65 -0
- package/src/engine/operators/logic.ts +53 -0
- package/src/engine/operators/math.ts +225 -0
- package/src/engine/operators/strings.ts +25 -0
- package/src/engine/operators/types.ts +16 -0
- package/src/engine/type-matching.ts +148 -0
- package/src/errors.ts +33 -0
- package/src/eslint/index.ts +388 -0
- package/src/fhir/html-checks.ts +266 -0
- package/src/fhir/model-navigation.ts +148 -0
- package/src/functions/aggregate.ts +136 -0
- package/src/functions/boundary.ts +209 -0
- package/src/functions/combining.ts +15 -0
- package/src/functions/control.ts +25 -0
- package/src/functions/conversion.ts +349 -0
- package/src/functions/date-components.ts +88 -0
- package/src/functions/existence.ts +107 -0
- package/src/functions/fhir.ts +247 -0
- package/src/functions/filtering.ts +120 -0
- package/src/functions/install.ts +19 -0
- package/src/functions/iteration.ts +21 -0
- package/src/functions/math.ts +167 -0
- package/src/functions/reflection.ts +24 -0
- package/src/functions/registry.ts +72 -0
- package/src/functions/sort.ts +68 -0
- package/src/functions/string.ts +413 -0
- package/src/functions/subsetting.ts +89 -0
- package/src/functions/tree.ts +112 -0
- package/src/functions/type-specifier.ts +29 -0
- package/src/functions/utility.ts +82 -0
- package/src/functions/variables.ts +36 -0
- package/src/index.ts +30 -0
- package/src/lexer/lexer.ts +341 -0
- package/src/lexer/tokens.ts +69 -0
- package/src/model/provider.ts +36 -0
- package/src/parser/ast.ts +164 -0
- package/src/parser/parser.ts +321 -0
- package/src/parser/precedence.ts +52 -0
- package/src/parser/printer.ts +114 -0
- package/src/r4/generated/resources-data.ts +28631 -0
- package/src/r4/generated/type-maps.ts +22145 -0
- package/src/r4/generated/types-data.ts +2208 -0
- package/src/r4/index.ts +107 -0
- package/src/r4/model-data.ts +17 -0
- package/src/sites/index.ts +285 -0
- package/src/typed/infer.ts +433 -0
- package/src/typed/perf-fixture.types.ts +143 -0
- package/src/values/collection.ts +57 -0
- package/src/values/datetime.ts +285 -0
- package/src/values/decimal.ts +213 -0
- package/src/values/numeric.ts +63 -0
- package/src/values/quantity.ts +358 -0
- package/src/values/temporal-arithmetic.ts +231 -0
- package/src/values/temporal-compare.ts +65 -0
- package/src/values/type-compat.ts +133 -0
- package/src/values/typed-value.ts +151 -0
- package/src/values/ucum.ts +181 -0
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared column signature rules for DTO registration, source walkers, and
|
|
3
|
+
* `analyzeDto`. This file accepts simple option shapes so it has no runtime or
|
|
4
|
+
* AST dependency.
|
|
5
|
+
*/
|
|
6
|
+
/** The column options this rule reads; `ColumnOptions` and an AST-derived record both satisfy it. */
|
|
7
|
+
export interface ColumnTypeClaim {
|
|
8
|
+
/** The declared FHIR type (`ColumnOptions.type`). */
|
|
9
|
+
type?: string | undefined;
|
|
10
|
+
/** Present when the column narrows to an `enum` of codes. */
|
|
11
|
+
enum?: unknown;
|
|
12
|
+
/** Present when `as` reshapes values outside FHIRPath. */
|
|
13
|
+
as?: unknown;
|
|
14
|
+
/** Present when `choices` decodes values outside FHIRPath. */
|
|
15
|
+
choices?: unknown;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* The type a column's values carry, or undefined when it claims nothing:
|
|
19
|
+
* `as`/`choices` hand values to JavaScript, so the expression's own result is all
|
|
20
|
+
* that can be said about them, while an `enum` only narrows codes that are
|
|
21
|
+
* Strings either way.
|
|
22
|
+
*/
|
|
23
|
+
export declare function columnResultType(column: ColumnTypeClaim): string | undefined;
|
|
24
|
+
/**
|
|
25
|
+
* What a registered column declares as a function. `input` is the type the
|
|
26
|
+
* column was written for, which is the DTO class's `fhirType`. `result` is what
|
|
27
|
+
* its expression returns. A column may declare either, both, or neither. The
|
|
28
|
+
* shape is assignable to `CustomFunctionSignature`.
|
|
29
|
+
*/
|
|
30
|
+
export interface ColumnFunctionSignature {
|
|
31
|
+
input?: {
|
|
32
|
+
types: string[];
|
|
33
|
+
};
|
|
34
|
+
result?: {
|
|
35
|
+
types: string[];
|
|
36
|
+
single: boolean;
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Returns the function signature contributed by a column. `hostType` is the DTO
|
|
41
|
+
* type. A source walker may omit it when the class root is not visible.
|
|
42
|
+
*/
|
|
43
|
+
export declare function columnSignature(column: ColumnTypeClaim & {
|
|
44
|
+
collection?: boolean;
|
|
45
|
+
}, hostType?: string): ColumnFunctionSignature | undefined;
|
|
46
|
+
/**
|
|
47
|
+
* The signature a `@criteria` contributes. Its expression goes through the
|
|
48
|
+
* criteria rule (see `criteriaBoolean`), so the function returns a single
|
|
49
|
+
* Boolean whatever the expression returns. This is a function rather than a
|
|
50
|
+
* shared constant, so one caller cannot change what the next caller reads.
|
|
51
|
+
*/
|
|
52
|
+
export declare function criteriaSignature(hostType?: string): ColumnFunctionSignature;
|
|
53
|
+
//# sourceMappingURL=column-signature.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"column-signature.d.ts","sourceRoot":"","sources":["../../src/api/column-signature.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,qGAAqG;AACrG,MAAM,WAAW,eAAe;IAC9B,qDAAqD;IACrD,IAAI,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IACzB,6DAA6D;IAC7D,IAAI,CAAC,EAAE,OAAO,CAAA;IACd,0DAA0D;IAC1D,EAAE,CAAC,EAAE,OAAO,CAAA;IACZ,8DAA8D;IAC9D,OAAO,CAAC,EAAE,OAAO,CAAA;CAClB;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,eAAe,GAAG,MAAM,GAAG,SAAS,CAK5E;AAED;;;;;GAKG;AACH,MAAM,WAAW,uBAAuB;IACtC,KAAK,CAAC,EAAE;QAAE,KAAK,EAAE,MAAM,EAAE,CAAA;KAAE,CAAA;IAC3B,MAAM,CAAC,EAAE;QAAE,KAAK,EAAE,MAAM,EAAE,CAAC;QAAC,MAAM,EAAE,OAAO,CAAA;KAAE,CAAA;CAC9C;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAC7B,MAAM,EAAE,eAAe,GAAG;IAAE,UAAU,CAAC,EAAE,OAAO,CAAA;CAAE,EAClD,QAAQ,CAAC,EAAE,MAAM,GAChB,uBAAuB,GAAG,SAAS,CAQrC;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,uBAAuB,CAK5E"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared column signature rules for DTO registration, source walkers, and
|
|
3
|
+
* `analyzeDto`. This file accepts simple option shapes so it has no runtime or
|
|
4
|
+
* AST dependency.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* The type a column's values carry, or undefined when it claims nothing:
|
|
8
|
+
* `as`/`choices` hand values to JavaScript, so the expression's own result is all
|
|
9
|
+
* that can be said about them, while an `enum` only narrows codes that are
|
|
10
|
+
* Strings either way.
|
|
11
|
+
*/
|
|
12
|
+
export function columnResultType(column) {
|
|
13
|
+
if (column.as !== undefined || column.choices !== undefined) {
|
|
14
|
+
return undefined;
|
|
15
|
+
}
|
|
16
|
+
return column.type ?? (column.enum !== undefined ? 'System.String' : undefined);
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Returns the function signature contributed by a column. `hostType` is the DTO
|
|
20
|
+
* type. A source walker may omit it when the class root is not visible.
|
|
21
|
+
*/
|
|
22
|
+
export function columnSignature(column, hostType) {
|
|
23
|
+
const type = columnResultType(column);
|
|
24
|
+
const input = hostType === undefined ? undefined : { types: [hostType] };
|
|
25
|
+
const result = type === undefined ? undefined : { types: [type], single: column.collection !== true };
|
|
26
|
+
if (input === undefined && result === undefined) {
|
|
27
|
+
return undefined;
|
|
28
|
+
}
|
|
29
|
+
return { ...(input !== undefined && { input }), ...(result !== undefined && { result }) };
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* The signature a `@criteria` contributes. Its expression goes through the
|
|
33
|
+
* criteria rule (see `criteriaBoolean`), so the function returns a single
|
|
34
|
+
* Boolean whatever the expression returns. This is a function rather than a
|
|
35
|
+
* shared constant, so one caller cannot change what the next caller reads.
|
|
36
|
+
*/
|
|
37
|
+
export function criteriaSignature(hostType) {
|
|
38
|
+
return {
|
|
39
|
+
...(hostType !== undefined && { input: { types: [hostType] } }),
|
|
40
|
+
result: { types: ['System.Boolean'], single: true },
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=column-signature.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"column-signature.js","sourceRoot":"","sources":["../../src/api/column-signature.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAcH;;;;;GAKG;AACH,MAAM,UAAU,gBAAgB,CAAC,MAAuB;IACtD,IAAI,MAAM,CAAC,EAAE,KAAK,SAAS,IAAI,MAAM,CAAC,OAAO,KAAK,SAAS,EAAE,CAAC;QAC5D,OAAO,SAAS,CAAA;IAClB,CAAC;IACD,OAAO,MAAM,CAAC,IAAI,IAAI,CAAC,MAAM,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,SAAS,CAAC,CAAA;AACjF,CAAC;AAaD;;;GAGG;AACH,MAAM,UAAU,eAAe,CAC7B,MAAkD,EAClD,QAAiB;IAEjB,MAAM,IAAI,GAAG,gBAAgB,CAAC,MAAM,CAAC,CAAA;IACrC,MAAM,KAAK,GAAG,QAAQ,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAA;IACxE,MAAM,MAAM,GAAG,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,UAAU,KAAK,IAAI,EAAE,CAAA;IACrG,IAAI,KAAK,KAAK,SAAS,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;QAChD,OAAO,SAAS,CAAA;IAClB,CAAC;IACD,OAAO,EAAE,GAAG,CAAC,KAAK,KAAK,SAAS,IAAI,EAAE,KAAK,EAAE,CAAC,EAAE,GAAG,CAAC,MAAM,KAAK,SAAS,IAAI,EAAE,MAAM,EAAE,CAAC,EAAE,CAAA;AAC3F,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,iBAAiB,CAAC,QAAiB;IACjD,OAAO;QACL,GAAG,CAAC,QAAQ,KAAK,SAAS,IAAI,EAAE,KAAK,EAAE,EAAE,KAAK,EAAE,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;QAC/D,MAAM,EAAE,EAAE,KAAK,EAAE,CAAC,gBAAgB,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE;KACpD,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import type { CustomFunctionSignature } from '../analyzer/signatures.ts';
|
|
2
|
+
import { type EvaluationContext, type HostNativeFunction, type RegexEngine } from '../engine/context.ts';
|
|
3
|
+
import type { ModelProvider } from '../model/provider.ts';
|
|
4
|
+
import type { AstNode } from '../parser/ast.ts';
|
|
5
|
+
import type { R4TypeOf } from '../r4/generated/type-maps.ts';
|
|
6
|
+
import type { FhirpathInput, FhirpathResult, FhirpathResultIn, FhirTypeName } from '../typed/infer.ts';
|
|
7
|
+
import { type TypedValue } from '../values/typed-value.ts';
|
|
8
|
+
/**
|
|
9
|
+
* A native or expression-defined FHIRPath function. Native functions receive
|
|
10
|
+
* evaluated JavaScript values. Expression functions take no arguments, keep
|
|
11
|
+
* FHIRPath types, and use the call focus with the caller's `%context` and
|
|
12
|
+
* environment. A signature lets the analyzer check either form. Built-in names
|
|
13
|
+
* cannot be replaced.
|
|
14
|
+
*/
|
|
15
|
+
export type SingleCustomFunction = (HostNativeFunction & {
|
|
16
|
+
signature?: CustomFunctionSignature;
|
|
17
|
+
expression?: never;
|
|
18
|
+
criteria?: never;
|
|
19
|
+
/** Only an expression body reads `%name`; a native `fn` gets plain values. */
|
|
20
|
+
env?: never;
|
|
21
|
+
}) | {
|
|
22
|
+
expression: AnyExpression;
|
|
23
|
+
signature?: CustomFunctionSignature;
|
|
24
|
+
/** Environment values available only while this expression body runs. */
|
|
25
|
+
env?: Record<string, unknown>;
|
|
26
|
+
/** Return one criteria Boolean. An empty body result becomes `false`. */
|
|
27
|
+
criteria?: boolean;
|
|
28
|
+
fn?: never;
|
|
29
|
+
minArity?: never;
|
|
30
|
+
maxArity?: never;
|
|
31
|
+
};
|
|
32
|
+
/** Same-name functions selected in order by `signature.input.types`. */
|
|
33
|
+
export interface OverloadedCustomFunction {
|
|
34
|
+
overloads: readonly SingleCustomFunction[];
|
|
35
|
+
fn?: never;
|
|
36
|
+
expression?: never;
|
|
37
|
+
signature?: never;
|
|
38
|
+
criteria?: never;
|
|
39
|
+
env?: never;
|
|
40
|
+
minArity?: never;
|
|
41
|
+
maxArity?: never;
|
|
42
|
+
}
|
|
43
|
+
export type CustomFunction = SingleCustomFunction | OverloadedCustomFunction;
|
|
44
|
+
export interface EvaluateOptions {
|
|
45
|
+
/** Environment variables (`%name`), keyed with or without the leading `%`. */
|
|
46
|
+
env?: Record<string, unknown>;
|
|
47
|
+
/**
|
|
48
|
+
* FHIRPath bindings evaluated against the input in declaration order. They
|
|
49
|
+
* keep FHIRPath types and may use `%context`, `env`, and earlier variables.
|
|
50
|
+
* During projection they run once per row. A `TypedValue[]` binds directly.
|
|
51
|
+
*/
|
|
52
|
+
vars?: Record<string, AnyExpression | readonly TypedValue[]>;
|
|
53
|
+
model?: ModelProvider;
|
|
54
|
+
/** Clock for `now()`, `today()`, and `timeOfDay()`. Defaults to the current time. */
|
|
55
|
+
now?: Date;
|
|
56
|
+
/**
|
|
57
|
+
* Sink for trace(name, ...) calls. No default logging: traced values may contain
|
|
58
|
+
* patient data, so sending them anywhere is an explicit choice.
|
|
59
|
+
*/
|
|
60
|
+
trace?: (name: string, values: TypedValue[]) => void;
|
|
61
|
+
/** Host functions by name. Pass the same declarations to `AnalyzeOptions.functions`. */
|
|
62
|
+
functions?: Record<string, CustomFunction>;
|
|
63
|
+
/**
|
|
64
|
+
* Regex engine for matches()/matchesFull()/replaceMatches(). The default is
|
|
65
|
+
* the built-in RegExp, which backtracks and cannot be timed out — supply a
|
|
66
|
+
* linear-time engine (e.g. an RE2 binding) when evaluating untrusted
|
|
67
|
+
* expressions (see README, Security).
|
|
68
|
+
*/
|
|
69
|
+
regex?: RegexEngine;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* A parsed expression, reusable across inputs. Create via `compile()` or the
|
|
73
|
+
* `fhirpath` tag: literal expressions carry inferred result and input types for
|
|
74
|
+
* the supported subset (see src/typed/infer.ts), everything else is unknown[].
|
|
75
|
+
*
|
|
76
|
+
* `TInput`/`TResult` default to the built-in inference but can be overridden,
|
|
77
|
+
* e.g. with `@medplum/fhirtypes` types, for full type-level fidelity with
|
|
78
|
+
* another FHIR type package: `compile<'Patient.name', Patient, HumanName[]>(...)`.
|
|
79
|
+
*/
|
|
80
|
+
export declare class CompiledExpression<Expr extends string = string, TInput = FhirpathInput<Expr>, TResult extends unknown[] = FhirpathResult<Expr>> {
|
|
81
|
+
readonly source: string;
|
|
82
|
+
readonly ast: AstNode;
|
|
83
|
+
constructor(source: Expr);
|
|
84
|
+
/** Evaluate and unwrap results to plain JS values. */
|
|
85
|
+
evaluate(input?: TInput, options?: EvaluateOptions): TResult;
|
|
86
|
+
/** Evaluate keeping the internal typed representation (types, Decimal, Temporal). */
|
|
87
|
+
evaluateTyped(input?: unknown, options?: EvaluateOptions): TypedValue[];
|
|
88
|
+
/** The canonical form of the expression. */
|
|
89
|
+
toString(): string;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Parse an expression once for reuse. Unlike `evaluate()`, does not touch the
|
|
93
|
+
* parse cache. A second argument declares the type the expression runs against,
|
|
94
|
+
* so a relative path infers like a DTO column and the static checkers analyze it
|
|
95
|
+
* against that type — see `fhirpath`, which takes the same declaration.
|
|
96
|
+
*/
|
|
97
|
+
export declare function compile<const Expr extends string, const Root extends FhirTypeName, TResult extends unknown[] = FhirpathResultIn<Expr, Root>>(expression: Expr, inputType: Root): CompiledExpression<Expr, R4TypeOf[Root], TResult>;
|
|
98
|
+
export declare function compile<const Expr extends string, TInput = FhirpathInput<Expr>, TResult extends unknown[] = FhirpathResult<Expr>>(expression: Expr): CompiledExpression<Expr, TInput, TResult>;
|
|
99
|
+
/** An expression as text or already compiled, with any literal type. */
|
|
100
|
+
export type AnyExpression = string | CompiledExpression<any>;
|
|
101
|
+
/**
|
|
102
|
+
* Prepares options once, then creates an evaluation context for each root.
|
|
103
|
+
* Variables bind in order. `extraEnv` contains call-specific values, such as
|
|
104
|
+
* projection row numbers, and replaces matching option values.
|
|
105
|
+
*/
|
|
106
|
+
export declare function contextFactory(options: EvaluateOptions | undefined): (root: TypedValue[], extraEnv?: Record<string, unknown>) => EvaluationContext;
|
|
107
|
+
/** Default for `EngineOptions.cacheSize`, matching Firely's FhirPathCompilerCache default. */
|
|
108
|
+
export declare const DEFAULT_PARSE_CACHE_SIZE = 500;
|
|
109
|
+
/**
|
|
110
|
+
* Parses an expression, reusing an earlier parse of the same text while it is
|
|
111
|
+
* still cached. An already-compiled expression passes through untouched.
|
|
112
|
+
*/
|
|
113
|
+
export type Compiler = (expression: AnyExpression) => CompiledExpression<string>;
|
|
114
|
+
/**
|
|
115
|
+
* A compiler over its own LRU of `capacity` distinct expression texts (`0`
|
|
116
|
+
* caches nothing). Each owner holds one — every `FhirPathEngine`, and the free
|
|
117
|
+
* `evaluate()` — so parses are never reused across them.
|
|
118
|
+
*/
|
|
119
|
+
export declare function createCachedCompiler(capacity?: number): Compiler;
|
|
120
|
+
//# sourceMappingURL=compile.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compile.d.ts","sourceRoot":"","sources":["../../src/api/compile.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,2BAA2B,CAAA;AACxE,OAA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Node } from "../engine/evaluator.js";
|
|
3
|
+
import { FhirPathTypeError } from "../errors.js";
|
|
4
|
+
import { parse } from "../parser/parser.js";
|
|
5
|
+
import { printExpression } from "../parser/printer.js";
|
|
6
|
+
import { toCollection, unwrap } from "../values/typed-value.js";
|
|
7
|
+
import { LruCache } from "./cache.js";
|
|
8
|
+
/**
|
|
9
|
+
* A parsed expression, reusable across inputs. Create via `compile()` or the
|
|
10
|
+
* `fhirpath` tag: literal expressions carry inferred result and input types for
|
|
11
|
+
* the supported subset (see src/typed/infer.ts), everything else is unknown[].
|
|
12
|
+
*
|
|
13
|
+
* `TInput`/`TResult` default to the built-in inference but can be overridden,
|
|
14
|
+
* e.g. with `@medplum/fhirtypes` types, for full type-level fidelity with
|
|
15
|
+
* another FHIR type package: `compile<'Patient.name', Patient, HumanName[]>(...)`.
|
|
16
|
+
*/
|
|
17
|
+
export class CompiledExpression {
|
|
18
|
+
source;
|
|
19
|
+
ast;
|
|
20
|
+
constructor(source) {
|
|
21
|
+
this.source = source;
|
|
22
|
+
this.ast = parse(source);
|
|
23
|
+
}
|
|
24
|
+
/** Evaluate and unwrap results to plain JS values. */
|
|
25
|
+
evaluate(input, options) {
|
|
26
|
+
return this.evaluateTyped(input, options).map(unwrap);
|
|
27
|
+
}
|
|
28
|
+
/** Evaluate keeping the internal typed representation (types, Decimal, Temporal). */
|
|
29
|
+
evaluateTyped(input, options) {
|
|
30
|
+
const root = toCollection(input);
|
|
31
|
+
return evaluateNode(this.ast, contextFactory(options)(root), root);
|
|
32
|
+
}
|
|
33
|
+
/** The canonical form of the expression. */
|
|
34
|
+
toString() {
|
|
35
|
+
return printExpression(this.ast);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
export function compile(expression) {
|
|
39
|
+
// A declared input type is a compile-time and check-time declaration (see
|
|
40
|
+
// `fhirpath`), with nothing for the evaluator to do.
|
|
41
|
+
return new CompiledExpression(expression);
|
|
42
|
+
}
|
|
43
|
+
/** A pre-resolved `vars` value; Array.isArray alone cannot exclude readonly arrays for the checker. */
|
|
44
|
+
function isResolvedCollection(value) {
|
|
45
|
+
return Array.isArray(value);
|
|
46
|
+
}
|
|
47
|
+
/** Bind planned vars into a fresh context (see contextFactory for the scoping rules). */
|
|
48
|
+
function bindVars(context, vars) {
|
|
49
|
+
for (const [name, value] of vars) {
|
|
50
|
+
if (context.env.has(name)) {
|
|
51
|
+
throw new FhirPathTypeError(`Cannot override the environment variable %${name} with a var`);
|
|
52
|
+
}
|
|
53
|
+
context.variables.set(name, isResolvedCollection(value) ? [...value] : evaluateNode(value, forkVariables(context), context.root));
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
/** Take a `vars` record apart once — keys normalize, string bodies parse — keeping declaration order. */
|
|
57
|
+
function planVars(vars) {
|
|
58
|
+
return Object.entries(normalizeEnvKeys(vars)).map(([name, value]) => {
|
|
59
|
+
if (typeof value === 'string') {
|
|
60
|
+
return [name, parse(value)];
|
|
61
|
+
}
|
|
62
|
+
return [name, isResolvedCollection(value) ? value : value.ast];
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Prepares options once, then creates an evaluation context for each root.
|
|
67
|
+
* Variables bind in order. `extraEnv` contains call-specific values, such as
|
|
68
|
+
* projection row numbers, and replaces matching option values.
|
|
69
|
+
*/
|
|
70
|
+
export function contextFactory(options) {
|
|
71
|
+
const functions = options?.functions === undefined ? undefined : toHostFunctions(options.functions);
|
|
72
|
+
const env = normalizeEnvKeys(options?.env);
|
|
73
|
+
const vars = options?.vars === undefined ? undefined : planVars(options.vars);
|
|
74
|
+
return (root, extraEnv) => {
|
|
75
|
+
const context = createContext({
|
|
76
|
+
root,
|
|
77
|
+
env: extraEnv === undefined ? env : { ...env, ...extraEnv },
|
|
78
|
+
model: options?.model,
|
|
79
|
+
now: options?.now,
|
|
80
|
+
trace: options?.trace,
|
|
81
|
+
functions,
|
|
82
|
+
regex: options?.regex,
|
|
83
|
+
});
|
|
84
|
+
if (vars !== undefined) {
|
|
85
|
+
bindVars(context, vars);
|
|
86
|
+
}
|
|
87
|
+
return context;
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Converts CustomFunctions to their runtime form. Expression bodies parse to
|
|
92
|
+
* ASTs, and the declared input types come across for the engine to check. The
|
|
93
|
+
* rest of the signature stays in the API layer, which is the analyzer's half.
|
|
94
|
+
*/
|
|
95
|
+
function toHostFunctions(functions) {
|
|
96
|
+
const host = {};
|
|
97
|
+
for (const [name, custom] of Object.entries(functions)) {
|
|
98
|
+
host[name] =
|
|
99
|
+
'overloads' in custom
|
|
100
|
+
? { overloads: custom.overloads.map(overload => toHostFunction(name, overload)) }
|
|
101
|
+
: toHostFunction(name, custom);
|
|
102
|
+
}
|
|
103
|
+
return host;
|
|
104
|
+
}
|
|
105
|
+
function toHostFunction(name, custom) {
|
|
106
|
+
if ('expression' in custom) {
|
|
107
|
+
if ('fn' in custom) {
|
|
108
|
+
throw new FhirPathTypeError(`Custom function '${name}' declares both 'fn' and 'expression'; use one`);
|
|
109
|
+
}
|
|
110
|
+
return hostExpressionFunction(custom);
|
|
111
|
+
}
|
|
112
|
+
const inputTypes = custom.signature?.input?.types;
|
|
113
|
+
// Copy rather than pass through. `custom` is the caller's own object, and the
|
|
114
|
+
// runtime form carries fields the API form does not.
|
|
115
|
+
return inputTypes === undefined ? custom : { ...custom, inputTypes };
|
|
116
|
+
}
|
|
117
|
+
/** The runtime form of an expression-defined CustomFunction: its body, plus what the engine checks around it. */
|
|
118
|
+
function hostExpressionFunction(custom) {
|
|
119
|
+
const { expression, signature } = custom;
|
|
120
|
+
const inputTypes = signature?.input?.types;
|
|
121
|
+
return {
|
|
122
|
+
ast: typeof expression === 'string' ? parse(expression) : expression.ast,
|
|
123
|
+
...(inputTypes !== undefined && { inputTypes }),
|
|
124
|
+
...(custom.env !== undefined && { env: envOverlay(custom.env) }),
|
|
125
|
+
...(custom.criteria === true && { criteria: true }),
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Overlays already built, by the env record they were built from. A context
|
|
130
|
+
* factory is made per evaluation and resolves every host function, so without
|
|
131
|
+
* this a DTO's tables would be re-wrapped on every `evaluate()` — including
|
|
132
|
+
* evaluations that never call one of its columns. The record is the DTO's
|
|
133
|
+
* cached definition, one object shared by all of its columns, so the entry is
|
|
134
|
+
* reached again on the next evaluation and released with the class.
|
|
135
|
+
*/
|
|
136
|
+
const overlays = new WeakMap();
|
|
137
|
+
/** A definition's own env as the collections the context binds, wrapped once per record. */
|
|
138
|
+
function envOverlay(env) {
|
|
139
|
+
let overlay = overlays.get(env);
|
|
140
|
+
if (overlay === undefined) {
|
|
141
|
+
overlay = envCollections(env);
|
|
142
|
+
overlays.set(env, overlay);
|
|
143
|
+
}
|
|
144
|
+
return overlay;
|
|
145
|
+
}
|
|
146
|
+
/** Default for `EngineOptions.cacheSize`, matching Firely's FhirPathCompilerCache default. */
|
|
147
|
+
export const DEFAULT_PARSE_CACHE_SIZE = 500;
|
|
148
|
+
/**
|
|
149
|
+
* A compiler over its own LRU of `capacity` distinct expression texts (`0`
|
|
150
|
+
* caches nothing). Each owner holds one — every `FhirPathEngine`, and the free
|
|
151
|
+
* `evaluate()` — so parses are never reused across them.
|
|
152
|
+
*/
|
|
153
|
+
export function createCachedCompiler(capacity = DEFAULT_PARSE_CACHE_SIZE) {
|
|
154
|
+
const cache = new LruCache(capacity);
|
|
155
|
+
return expression => {
|
|
156
|
+
if (typeof expression !== 'string') {
|
|
157
|
+
return expression;
|
|
158
|
+
}
|
|
159
|
+
let compiled = cache.get(expression);
|
|
160
|
+
if (!compiled) {
|
|
161
|
+
compiled = new CompiledExpression(expression);
|
|
162
|
+
cache.set(expression, compiled);
|
|
163
|
+
}
|
|
164
|
+
return compiled;
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
//# sourceMappingURL=compile.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"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AI,EAAE,CAAC;KACpD,CAAA;AACH,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,QAAQ,GAAG,IAAI,OAAO,EAA6C,CAAA;AAEzE,4FAA4F;AAC5F,SAAS,UAAU,CAAC,GAA4B;IAC9C,IAAI,OAAO,GAAG,QAAQ,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;IAC/B,IAAI,OAAO,KAAK,SAAS,EAAE,CAAC;QAC1B,OAAO,GAAG,cAAc,CAAC,GAAG,CAAC,CAAA;QAC7B,QAAQ,CAAC,GAAG,CAAC,GAAG,EAAE,OAAO,CAAC,CAAA;IAC5B,CAAC;IACD,OAAO,OAAO,CAAA;AAChB,CAAC;AAED,8FAA8F;AAC9F,MAAM,CAAC,MAAM,wBAAwB,GAAG,GAAG,CAAA;AAQ3C;;;;GAIG;AACH,MAAM,UAAU,oBAAoB,CAAC,WAAmB,wBAAwB;IAC9E,MAAM,KAAK,GAAG,IAAI,QAAQ,CAAqB,QAAQ,CAAC,CAAA;IACxD,OAAO,UAAU,CAAC,EAAE;QAClB,IAAI,OAAO,UAAU,KAAK,QAAQ,EAAE,CAAC;YACnC,OAAO,UAAU,CAAA;QACnB,CAAC;QACD,IAAI,QAAQ,GAAG,KAAK,CAAC,GAAG,CAAC,UAAU,CAAC,CAAA;QACpC,IAAI,CAAC,QAAQ,EAAE,CAAC;YACd,QAAQ,GAAG,IAAI,kBAAkB,CAAC,UAAU,CAAC,CAAA;YAC7C,KAAK,CAAC,GAAG,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAA;QACjC,CAAC;QACD,OAAO,QAAQ,CAAA;IACjB,CAAC,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { Compiler, EvaluateOptions } from './compile.ts';
|
|
2
|
+
/** An invariant to check, shaped like FHIR's `ElementDefinition.constraint`. */
|
|
3
|
+
export interface FhirConstraint {
|
|
4
|
+
/** Constraint id, e.g. `pat-1`. */
|
|
5
|
+
key: string;
|
|
6
|
+
/** `error` (default) fails validation; `warning` is reported but does not. */
|
|
7
|
+
severity?: 'error' | 'warning';
|
|
8
|
+
/** Human-readable description of the rule. */
|
|
9
|
+
human?: string;
|
|
10
|
+
/** FHIRPath expression that must evaluate to true. */
|
|
11
|
+
expression: string;
|
|
12
|
+
}
|
|
13
|
+
/** A constraint that did not hold, echoing its definition. */
|
|
14
|
+
export interface ConstraintIssue {
|
|
15
|
+
key: string;
|
|
16
|
+
severity: 'error' | 'warning';
|
|
17
|
+
human?: string;
|
|
18
|
+
expression: string;
|
|
19
|
+
/** Set when the expression itself failed to parse or evaluate, with the engine error. */
|
|
20
|
+
error?: string;
|
|
21
|
+
/** For array or Bundle inputs: position of the failing resource (in the array, or in `Bundle.entry`). */
|
|
22
|
+
index?: number;
|
|
23
|
+
}
|
|
24
|
+
/** Minimal OperationOutcome shape; structurally assignable to the full R4 type. */
|
|
25
|
+
export interface OperationOutcome {
|
|
26
|
+
resourceType: 'OperationOutcome';
|
|
27
|
+
issue: {
|
|
28
|
+
severity: 'error' | 'warning' | 'information';
|
|
29
|
+
code: 'invariant' | 'informational';
|
|
30
|
+
details: {
|
|
31
|
+
text: string;
|
|
32
|
+
};
|
|
33
|
+
diagnostics?: string;
|
|
34
|
+
/** For Bundle inputs: FHIRPath to the failing entry resource, e.g. `Bundle.entry[3].resource`. */
|
|
35
|
+
expression?: string[];
|
|
36
|
+
}[];
|
|
37
|
+
}
|
|
38
|
+
export interface ConstraintCheckResult {
|
|
39
|
+
/** True when no error-severity constraint failed; warnings do not invalidate. */
|
|
40
|
+
valid: boolean;
|
|
41
|
+
/** The constraints that failed (both severities), in input order. */
|
|
42
|
+
issues: ConstraintIssue[];
|
|
43
|
+
/** The same issues as a FHIR OperationOutcome (`issue.code = 'invariant'`, validator-style). */
|
|
44
|
+
toOperationOutcome(): OperationOutcome;
|
|
45
|
+
}
|
|
46
|
+
/** Implementation behind `FhirPathEngine.checkConstraints`; options come pre-merged. */
|
|
47
|
+
export declare function evaluateConstraints(input: unknown, constraints: readonly FhirConstraint[], options: EvaluateOptions, compile: Compiler): ConstraintCheckResult;
|
|
48
|
+
//# sourceMappingURL=constraints.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constraints.d.ts","sourceRoot":"","sources":["../../src/api/constraints.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,QAAQ,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AAE7D,gFAAgF;AAChF,MAAM,WAAW,cAAc;IAC7B,mCAAmC;IACnC,GAAG,EAAE,MAAM,CAAA;IACX,8EAA8E;IAC9E,QAAQ,CAAC,EAAE,OAAO,GAAG,SAAS,CAAA;IAC9B,8CAA8C;IAC9C,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,sDAAsD;IACtD,UAAU,EAAE,MAAM,CAAA;CACnB;AAED,8DAA8D;AAC9D,MAAM,WAAW,eAAe;IAC9B,GAAG,EAAE,MAAM,CAAA;IACX,QAAQ,EAAE,OAAO,GAAG,SAAS,CAAA;IAC7B,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,UAAU,EAAE,MAAM,CAAA;IAClB,yFAAyF;IACzF,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,yGAAyG;IACzG,KAAK,CAAC,EAAE,MAAM,CAAA;CACf;AAED,mFAAmF;AACnF,MAAM,WAAW,gBAAgB;IAC/B,YAAY,EAAE,kBAAkB,CAAA;IAChC,KAAK,EAAE;QACL,QAAQ,EAAE,OAAO,GAAG,SAAS,GAAG,aAAa,CAAA;QAC7C,IAAI,EAAE,WAAW,GAAG,eAAe,CAAA;QACnC,OAAO,EAAE;YAAE,IAAI,EAAE,MAAM,CAAA;SAAE,CAAA;QACzB,WAAW,CAAC,EAAE,MAAM,CAAA;QACpB,kGAAkG;QAClG,UAAU,CAAC,EAAE,MAAM,EAAE,CAAA;KACtB,EAAE,CAAA;CACJ;AAED,MAAM,WAAW,qBAAqB;IACpC,iFAAiF;IACjF,KAAK,EAAE,OAAO,CAAA;IACd,qEAAqE;IACrE,MAAM,EAAE,eAAe,EAAE,CAAA;IACzB,gGAAgG;IAChG,kBAAkB,IAAI,gBAAgB,CAAA;CACvC;AAED,wFAAwF;AACxF,wBAAgB,mBAAmB,CACjC,KAAK,EAAE,OAAO,EACd,WAAW,EAAE,SAAS,cAAc,EAAE,EACtC,OAAO,EAAE,eAAe,EACxB,OAAO,EAAE,QAAQ,GAChB,qBAAqB,CA2BvB"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { FhirPathError } from "../errors.js";
|
|
2
|
+
import { criteriaBoolean } from "../values/collection.js";
|
|
3
|
+
import { isBundle, toSubjects } from "./bundle.js";
|
|
4
|
+
/** Implementation behind `FhirPathEngine.checkConstraints`; options come pre-merged. */
|
|
5
|
+
export function evaluateConstraints(input, constraints, options, compile) {
|
|
6
|
+
const bundle = isBundle(input);
|
|
7
|
+
const issues = [];
|
|
8
|
+
for (const subject of toSubjects(input)) {
|
|
9
|
+
for (const constraint of constraints) {
|
|
10
|
+
const issue = {
|
|
11
|
+
key: constraint.key,
|
|
12
|
+
severity: constraint.severity ?? 'error',
|
|
13
|
+
expression: constraint.expression,
|
|
14
|
+
...(constraint.human === undefined ? {} : { human: constraint.human }),
|
|
15
|
+
...(subject.index === undefined ? {} : { index: subject.index }),
|
|
16
|
+
};
|
|
17
|
+
try {
|
|
18
|
+
if (!criteriaBoolean(compile(constraint.expression).evaluateTyped(subject.value, options))) {
|
|
19
|
+
issues.push(issue);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
catch (error) {
|
|
23
|
+
issue.error = error instanceof FhirPathError ? error.message : String(error);
|
|
24
|
+
issues.push(issue);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return {
|
|
29
|
+
valid: issues.every(issue => issue.severity !== 'error'),
|
|
30
|
+
issues,
|
|
31
|
+
toOperationOutcome: () => toOperationOutcome(issues, bundle),
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
function toOperationOutcome(issues, bundle) {
|
|
35
|
+
if (issues.length === 0) {
|
|
36
|
+
return {
|
|
37
|
+
resourceType: 'OperationOutcome',
|
|
38
|
+
issue: [{ severity: 'information', code: 'informational', details: { text: 'All constraints passed' } }],
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
return {
|
|
42
|
+
resourceType: 'OperationOutcome',
|
|
43
|
+
issue: issues.map(issue => ({
|
|
44
|
+
severity: issue.severity,
|
|
45
|
+
code: 'invariant',
|
|
46
|
+
details: { text: issue.human ?? `Constraint ${issue.key} failed` },
|
|
47
|
+
diagnostics: issue.error === undefined ? issue.expression : `${issue.expression} (${issue.error})`,
|
|
48
|
+
...(bundle && issue.index !== undefined ? { expression: [`Bundle.entry[${issue.index}].resource`] } : {}),
|
|
49
|
+
})),
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=constraints.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constraints.js","sourceRoot":"","sources":["../../src/api/constraints.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAA;AAC5C,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAA;AACzD,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAiDlD,wFAAwF;AACxF,MAAM,UAAU,mBAAmB,CACjC,KAAc,EACd,WAAsC,EACtC,OAAwB,EACxB,OAAiB;IAEjB,MAAM,MAAM,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAA;IAC9B,MAAM,MAAM,GAAsB,EAAE,CAAA;IACpC,KAAK,MAAM,OAAO,IAAI,UAAU,CAAC,KAAK,CAAC,EAAE,CAAC;QACxC,KAAK,MAAM,UAAU,IAAI,WAAW,EAAE,CAAC;YACrC,MAAM,KAAK,GAAoB;gBAC7B,GAAG,EAAE,UAAU,CAAC,GAAG;gBACnB,QAAQ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