fhir-runtime 0.2.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.
Files changed (124) hide show
  1. package/CHANGELOG.md +211 -0
  2. package/LICENSE +21 -0
  3. package/README.md +261 -0
  4. package/dist/cjs/index.cjs +7368 -0
  5. package/dist/cjs/index.cjs.map +7 -0
  6. package/dist/cjs/index.d.ts +4224 -0
  7. package/dist/cjs/package.json +5 -0
  8. package/dist/esm/index.d.ts +4224 -0
  9. package/dist/esm/index.mjs +7250 -0
  10. package/dist/esm/index.mjs.map +7 -0
  11. package/dist/esm/package.json +5 -0
  12. package/dist/index.d.ts +4224 -0
  13. package/dist/lib/context/bundle-loader.d.ts +124 -0
  14. package/dist/lib/context/bundle-loader.d.ts.map +1 -0
  15. package/dist/lib/context/core-definitions/index.d.ts +72 -0
  16. package/dist/lib/context/core-definitions/index.d.ts.map +1 -0
  17. package/dist/lib/context/errors.d.ts +114 -0
  18. package/dist/lib/context/errors.d.ts.map +1 -0
  19. package/dist/lib/context/fhir-context.d.ts +72 -0
  20. package/dist/lib/context/fhir-context.d.ts.map +1 -0
  21. package/dist/lib/context/index.d.ts +21 -0
  22. package/dist/lib/context/index.d.ts.map +1 -0
  23. package/dist/lib/context/inheritance-resolver.d.ts +98 -0
  24. package/dist/lib/context/inheritance-resolver.d.ts.map +1 -0
  25. package/dist/lib/context/inner-type-extractor.d.ts +80 -0
  26. package/dist/lib/context/inner-type-extractor.d.ts.map +1 -0
  27. package/dist/lib/context/loaders/composite-loader.d.ts +47 -0
  28. package/dist/lib/context/loaders/composite-loader.d.ts.map +1 -0
  29. package/dist/lib/context/loaders/file-loader.d.ts +47 -0
  30. package/dist/lib/context/loaders/file-loader.d.ts.map +1 -0
  31. package/dist/lib/context/loaders/index.d.ts +11 -0
  32. package/dist/lib/context/loaders/index.d.ts.map +1 -0
  33. package/dist/lib/context/loaders/memory-loader.d.ts +42 -0
  34. package/dist/lib/context/loaders/memory-loader.d.ts.map +1 -0
  35. package/dist/lib/context/registry.d.ts +116 -0
  36. package/dist/lib/context/registry.d.ts.map +1 -0
  37. package/dist/lib/context/types.d.ts +266 -0
  38. package/dist/lib/context/types.d.ts.map +1 -0
  39. package/dist/lib/fhirpath/atoms.d.ts +228 -0
  40. package/dist/lib/fhirpath/atoms.d.ts.map +1 -0
  41. package/dist/lib/fhirpath/cache.d.ts +79 -0
  42. package/dist/lib/fhirpath/cache.d.ts.map +1 -0
  43. package/dist/lib/fhirpath/date.d.ts +17 -0
  44. package/dist/lib/fhirpath/date.d.ts.map +1 -0
  45. package/dist/lib/fhirpath/functions.d.ts +28 -0
  46. package/dist/lib/fhirpath/functions.d.ts.map +1 -0
  47. package/dist/lib/fhirpath/index.d.ts +20 -0
  48. package/dist/lib/fhirpath/index.d.ts.map +1 -0
  49. package/dist/lib/fhirpath/lexer/parse.d.ts +100 -0
  50. package/dist/lib/fhirpath/lexer/parse.d.ts.map +1 -0
  51. package/dist/lib/fhirpath/lexer/tokenize.d.ts +80 -0
  52. package/dist/lib/fhirpath/lexer/tokenize.d.ts.map +1 -0
  53. package/dist/lib/fhirpath/parse.d.ts +101 -0
  54. package/dist/lib/fhirpath/parse.d.ts.map +1 -0
  55. package/dist/lib/fhirpath/tokenize.d.ts +20 -0
  56. package/dist/lib/fhirpath/tokenize.d.ts.map +1 -0
  57. package/dist/lib/fhirpath/types.d.ts +111 -0
  58. package/dist/lib/fhirpath/types.d.ts.map +1 -0
  59. package/dist/lib/fhirpath/utils.d.ts +81 -0
  60. package/dist/lib/fhirpath/utils.d.ts.map +1 -0
  61. package/dist/lib/index.d.ts +24 -0
  62. package/dist/lib/index.d.ts.map +1 -0
  63. package/dist/lib/model/canonical-profile.d.ts +381 -0
  64. package/dist/lib/model/canonical-profile.d.ts.map +1 -0
  65. package/dist/lib/model/element-definition.d.ts +503 -0
  66. package/dist/lib/model/element-definition.d.ts.map +1 -0
  67. package/dist/lib/model/index.d.ts +14 -0
  68. package/dist/lib/model/index.d.ts.map +1 -0
  69. package/dist/lib/model/primitives.d.ts +464 -0
  70. package/dist/lib/model/primitives.d.ts.map +1 -0
  71. package/dist/lib/model/structure-definition.d.ts +263 -0
  72. package/dist/lib/model/structure-definition.d.ts.map +1 -0
  73. package/dist/lib/parser/choice-type-parser.d.ts +182 -0
  74. package/dist/lib/parser/choice-type-parser.d.ts.map +1 -0
  75. package/dist/lib/parser/index.d.ts +16 -0
  76. package/dist/lib/parser/index.d.ts.map +1 -0
  77. package/dist/lib/parser/json-parser.d.ts +171 -0
  78. package/dist/lib/parser/json-parser.d.ts.map +1 -0
  79. package/dist/lib/parser/parse-error.d.ts +146 -0
  80. package/dist/lib/parser/parse-error.d.ts.map +1 -0
  81. package/dist/lib/parser/primitive-parser.d.ts +136 -0
  82. package/dist/lib/parser/primitive-parser.d.ts.map +1 -0
  83. package/dist/lib/parser/serializer.d.ts +64 -0
  84. package/dist/lib/parser/serializer.d.ts.map +1 -0
  85. package/dist/lib/parser/structure-definition-parser.d.ts +63 -0
  86. package/dist/lib/parser/structure-definition-parser.d.ts.map +1 -0
  87. package/dist/lib/profile/canonical-builder.d.ts +87 -0
  88. package/dist/lib/profile/canonical-builder.d.ts.map +1 -0
  89. package/dist/lib/profile/constraint-merger.d.ts +100 -0
  90. package/dist/lib/profile/constraint-merger.d.ts.map +1 -0
  91. package/dist/lib/profile/element-merger.d.ts +80 -0
  92. package/dist/lib/profile/element-merger.d.ts.map +1 -0
  93. package/dist/lib/profile/element-sorter.d.ts +81 -0
  94. package/dist/lib/profile/element-sorter.d.ts.map +1 -0
  95. package/dist/lib/profile/errors.d.ts +150 -0
  96. package/dist/lib/profile/errors.d.ts.map +1 -0
  97. package/dist/lib/profile/index.d.ts +27 -0
  98. package/dist/lib/profile/index.d.ts.map +1 -0
  99. package/dist/lib/profile/path-utils.d.ts +180 -0
  100. package/dist/lib/profile/path-utils.d.ts.map +1 -0
  101. package/dist/lib/profile/slicing-handler.d.ts +121 -0
  102. package/dist/lib/profile/slicing-handler.d.ts.map +1 -0
  103. package/dist/lib/profile/snapshot-generator.d.ts +73 -0
  104. package/dist/lib/profile/snapshot-generator.d.ts.map +1 -0
  105. package/dist/lib/profile/types.d.ts +220 -0
  106. package/dist/lib/profile/types.d.ts.map +1 -0
  107. package/dist/lib/validator/errors.d.ts +83 -0
  108. package/dist/lib/validator/errors.d.ts.map +1 -0
  109. package/dist/lib/validator/index.d.ts +23 -0
  110. package/dist/lib/validator/index.d.ts.map +1 -0
  111. package/dist/lib/validator/invariant-validator.d.ts +62 -0
  112. package/dist/lib/validator/invariant-validator.d.ts.map +1 -0
  113. package/dist/lib/validator/path-extractor.d.ts +123 -0
  114. package/dist/lib/validator/path-extractor.d.ts.map +1 -0
  115. package/dist/lib/validator/slicing-validator.d.ts +119 -0
  116. package/dist/lib/validator/slicing-validator.d.ts.map +1 -0
  117. package/dist/lib/validator/structure-validator.d.ts +74 -0
  118. package/dist/lib/validator/structure-validator.d.ts.map +1 -0
  119. package/dist/lib/validator/types.d.ts +288 -0
  120. package/dist/lib/validator/types.d.ts.map +1 -0
  121. package/dist/lib/validator/validation-rules.d.ts +198 -0
  122. package/dist/lib/validator/validation-rules.d.ts.map +1 -0
  123. package/dist/tsdoc-metadata.json +11 -0
  124. package/package.json +76 -0
@@ -0,0 +1,119 @@
1
+ /**
2
+ * fhir-validator — Slicing Validation
3
+ *
4
+ * Implements slicing validation logic for FHIR array elements:
5
+ * - {@link validateSlicing} — orchestrates slice matching, cardinality, rules, and ordering
6
+ * - {@link findMatchingSlice} — matches a value to a named slice via discriminators
7
+ * - {@link matchesDiscriminator} — checks a single discriminator against a value
8
+ * - {@link isSliceOrderValid} — validates ordered slicing constraints
9
+ * - {@link extractValueAtPath} — extracts a nested value from an object using a dot path
10
+ * - {@link getSliceDiscriminatorValue} — retrieves the expected discriminator value from a slice element
11
+ *
12
+ * @module fhir-validator
13
+ */
14
+ import type { CanonicalElement, SlicingDiscriminatorDef } from '../model/canonical-profile.js';
15
+ import type { ValidationIssue } from './types.js';
16
+ /**
17
+ * Extract a value from an object using a simple dot-separated path.
18
+ *
19
+ * This is a lightweight path extractor for discriminator evaluation.
20
+ * Unlike the full `extractValues` in path-extractor.ts, this operates
21
+ * on plain objects (not full FHIR resources) and returns a single value.
22
+ *
23
+ * Handles:
24
+ * - Simple dot paths: `"system"`, `"coding.system"`
25
+ * - `$this` (returns the value itself)
26
+ * - `resolve()` is ignored (returns the value at the preceding path)
27
+ *
28
+ * @param value - The object to extract from.
29
+ * @param path - Dot-separated path (e.g., `"coding.system"`).
30
+ * @returns The extracted value, or `undefined` if not found.
31
+ */
32
+ export declare function extractValueAtPath(value: unknown, path: string): unknown;
33
+ /**
34
+ * Get the expected discriminator value from a slice element definition.
35
+ *
36
+ * For a "value" discriminator, the expected value comes from the slice's
37
+ * `fixed` or `pattern` constraint. The discriminator path is used to
38
+ * navigate into the fixed/pattern value if it's a complex object.
39
+ *
40
+ * @param slice - The slice element definition.
41
+ * @param discriminatorPath - The discriminator path (e.g., `"system"`).
42
+ * @returns The expected value for this discriminator, or `undefined`.
43
+ */
44
+ export declare function getSliceDiscriminatorValue(slice: CanonicalElement, discriminatorPath: string): unknown;
45
+ /**
46
+ * Get the expected type codes from a slice element definition.
47
+ *
48
+ * For a "type" discriminator, the expected types come from the slice's
49
+ * `types` array.
50
+ *
51
+ * @param slice - The slice element definition.
52
+ * @param _discriminatorPath - The discriminator path (currently unused).
53
+ * @returns Array of expected type code strings.
54
+ */
55
+ export declare function getSliceTypes(slice: CanonicalElement, _discriminatorPath: string): string[];
56
+ /**
57
+ * Check if a value matches a single discriminator for a slice.
58
+ *
59
+ * Supports 4 discriminator types:
60
+ * - `value`: The value at the discriminator path must deeply equal the
61
+ * slice's fixed/pattern value at the same path.
62
+ * - `pattern`: The value at the discriminator path must match the
63
+ * slice's pattern (partial/subset match).
64
+ * - `type`: The inferred FHIR type of the value at the discriminator
65
+ * path must match one of the slice's allowed types.
66
+ * - `exists`: The discriminator path must exist (have a non-undefined value)
67
+ * in the value.
68
+ * - `profile`: Always returns `true` (placeholder — full profile conformance
69
+ * checking requires context resolution not available here).
70
+ *
71
+ * @param value - The actual value to check.
72
+ * @param slice - The slice element definition.
73
+ * @param discriminator - The discriminator definition.
74
+ * @returns `true` if the value matches this discriminator.
75
+ */
76
+ export declare function matchesDiscriminator(value: unknown, slice: CanonicalElement, discriminator: SlicingDiscriminatorDef): boolean;
77
+ /**
78
+ * Find which named slice a value matches based on discriminators.
79
+ *
80
+ * Iterates through the slice elements and checks each discriminator.
81
+ * A value matches a slice if ALL discriminators match.
82
+ *
83
+ * @param value - The actual value to match.
84
+ * @param slices - Array of slice element definitions (must have `sliceName`).
85
+ * @param discriminators - The discriminator definitions from the slicing root.
86
+ * @returns The matching slice element, or `undefined` if no match.
87
+ */
88
+ export declare function findMatchingSlice(value: unknown, slices: CanonicalElement[], discriminators: SlicingDiscriminatorDef[]): CanonicalElement | undefined;
89
+ /**
90
+ * Check if values appear in the correct order according to slice definitions.
91
+ *
92
+ * For ordered slicing, values must appear in the same order as the slice
93
+ * definitions. Values matching slice A must all appear before values
94
+ * matching slice B if slice A is defined before slice B.
95
+ *
96
+ * @param values - The actual values in the array.
97
+ * @param slices - The slice element definitions (in definition order).
98
+ * @param discriminators - The discriminator definitions.
99
+ * @returns `true` if the values are in valid order.
100
+ */
101
+ export declare function isSliceOrderValid(values: unknown[], slices: CanonicalElement[], discriminators: SlicingDiscriminatorDef[]): boolean;
102
+ /**
103
+ * Validate slicing constraints for an array element.
104
+ *
105
+ * Performs the following checks:
106
+ * 1. **Slice matching** — each value is matched to a named slice via discriminators.
107
+ * 2. **Slice cardinality** — each slice's min/max is checked against matched values.
108
+ * 3. **Slicing rules** — for `closed` slicing, unmatched values produce errors.
109
+ * For `openAtEnd`, unmatched values must appear after all matched values.
110
+ * 4. **Ordering** — for `ordered` slicing, matched values must appear in
111
+ * slice definition order.
112
+ *
113
+ * @param slicingRoot - The element with the slicing definition.
114
+ * @param sliceElements - The named slice element definitions.
115
+ * @param values - The actual values in the array.
116
+ * @param issues - Mutable array to push validation issues into.
117
+ */
118
+ export declare function validateSlicing(slicingRoot: CanonicalElement, sliceElements: CanonicalElement[], values: unknown[], issues: ValidationIssue[]): void;
119
+ //# sourceMappingURL=slicing-validator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"slicing-validator.d.ts","sourceRoot":"","sources":["../../../src/validator/slicing-validator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,uBAAuB,EAAE,MAAM,+BAA+B,CAAC;AAC/F,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAQlD;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAwCxE;AAMD;;;;;;;;;;GAUG;AACH,wBAAgB,0BAA0B,CACxC,KAAK,EAAE,gBAAgB,EACvB,iBAAiB,EAAE,MAAM,GACxB,OAAO,CAkBT;AAMD;;;;;;;;;GASG;AACH,wBAAgB,aAAa,CAC3B,KAAK,EAAE,gBAAgB,EACvB,kBAAkB,EAAE,MAAM,GACzB,MAAM,EAAE,CAEV;AAMD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,oBAAoB,CAClC,KAAK,EAAE,OAAO,EACd,KAAK,EAAE,gBAAgB,EACvB,aAAa,EAAE,uBAAuB,GACrC,OAAO,CAgDT;AAMD;;;;;;;;;;GAUG;AACH,wBAAgB,iBAAiB,CAC/B,KAAK,EAAE,OAAO,EACd,MAAM,EAAE,gBAAgB,EAAE,EAC1B,cAAc,EAAE,uBAAuB,EAAE,GACxC,gBAAgB,GAAG,SAAS,CAgB9B;AAMD;;;;;;;;;;;GAWG;AACH,wBAAgB,iBAAiB,CAC/B,MAAM,EAAE,OAAO,EAAE,EACjB,MAAM,EAAE,gBAAgB,EAAE,EAC1B,cAAc,EAAE,uBAAuB,EAAE,GACxC,OAAO,CA4BT;AAMD;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,eAAe,CAC7B,WAAW,EAAE,gBAAgB,EAC7B,aAAa,EAAE,gBAAgB,EAAE,EACjC,MAAM,EAAE,OAAO,EAAE,EACjB,MAAM,EAAE,eAAe,EAAE,GACxB,IAAI,CAsFN"}
@@ -0,0 +1,74 @@
1
+ /**
2
+ * fhir-validator — Structure Validator (Orchestrator)
3
+ *
4
+ * Main validator class that coordinates all validation rules to validate
5
+ * a FHIR resource instance against a {@link CanonicalProfile}.
6
+ *
7
+ * Integrates:
8
+ * - Path extraction ({@link extractValues})
9
+ * - Cardinality validation ({@link validateCardinality})
10
+ * - Type validation ({@link validateType})
11
+ * - Fixed/pattern validation ({@link validateFixed}, {@link validatePattern})
12
+ * - Reference validation ({@link validateReference})
13
+ * - Slicing validation ({@link validateSlicing})
14
+ *
15
+ * Exported:
16
+ * - {@link StructureValidator} — main validator class
17
+ *
18
+ * @module fhir-validator
19
+ */
20
+ import type { CanonicalProfile, Resource } from '../model/index.js';
21
+ import type { ValidationOptions, ValidationResult } from './types.js';
22
+ /**
23
+ * Main validator class for structural validation of FHIR resources.
24
+ *
25
+ * Validates a resource instance against a {@link CanonicalProfile} by
26
+ * orchestrating all individual validation rules (cardinality, type,
27
+ * fixed/pattern, reference, slicing).
28
+ *
29
+ * @example
30
+ * ```typescript
31
+ * const validator = new StructureValidator();
32
+ *
33
+ * // Validate with an explicit profile
34
+ * const result = validator.validate(patient, patientProfile);
35
+ *
36
+ * if (!result.valid) {
37
+ * for (const issue of result.issues) {
38
+ * console.error(`${issue.severity}: ${issue.message}`);
39
+ * }
40
+ * }
41
+ * ```
42
+ */
43
+ export declare class StructureValidator {
44
+ private readonly options;
45
+ constructor(options?: ValidationOptions);
46
+ /**
47
+ * Validate a resource instance against a CanonicalProfile.
48
+ *
49
+ * @param resource - The FHIR resource to validate.
50
+ * @param profile - The CanonicalProfile to validate against.
51
+ * @param options - Optional per-call overrides for validation options.
52
+ * @returns The validation result with all issues.
53
+ * @throws {@link ProfileNotFoundError} if profile is undefined.
54
+ * @throws {@link ValidationFailedError} if failFast is enabled and an error is found.
55
+ */
56
+ validate(resource: Resource, profile: CanonicalProfile, options?: ValidationOptions): ValidationResult;
57
+ /**
58
+ * Check that the resource type matches the profile type.
59
+ */
60
+ private validateResourceType;
61
+ /**
62
+ * Validate all elements in the profile against the resource.
63
+ */
64
+ private validateElements;
65
+ /**
66
+ * Get all named slice elements for a slicing root path.
67
+ */
68
+ private getSliceElements;
69
+ /**
70
+ * Check if failFast is enabled and there are errors; if so, throw.
71
+ */
72
+ private checkFailFast;
73
+ }
74
+ //# sourceMappingURL=structure-validator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"structure-validator.d.ts","sourceRoot":"","sources":["../../../src/validator/structure-validator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAoB,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AACtF,OAAO,KAAK,EAAE,iBAAiB,EAAE,gBAAgB,EAAmB,MAAM,YAAY,CAAC;AAkBvF;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,qBAAa,kBAAkB;IAC7B,OAAO,CAAC,QAAQ,CAAC,OAAO,CAA8B;gBAE1C,OAAO,CAAC,EAAE,iBAAiB;IAQvC;;;;;;;;;OASG;IACH,QAAQ,CACN,QAAQ,EAAE,QAAQ,EAClB,OAAO,EAAE,gBAAgB,EACzB,OAAO,CAAC,EAAE,iBAAiB,GAC1B,gBAAgB;IA8BnB;;OAEG;IACH,OAAO,CAAC,oBAAoB;IAqC5B;;OAEG;IACH,OAAO,CAAC,gBAAgB;IA4ExB;;OAEG;IACH,OAAO,CAAC,gBAAgB;IAexB;;OAEG;IACH,OAAO,CAAC,aAAa;CAWtB"}
@@ -0,0 +1,288 @@
1
+ /**
2
+ * fhir-validator — Public Interfaces & Types
3
+ *
4
+ * Defines the core abstractions for the FHIR validator module:
5
+ * - {@link ValidationOptions} — validation configuration
6
+ * - {@link ValidationResult} — validation output
7
+ * - {@link ValidationIssue} — issue reporting
8
+ * - {@link ValidationIssueCode} — machine-readable issue codes
9
+ * - {@link ValidationContext} — internal validation state
10
+ *
11
+ * This module implements structural validation of FHIR resource instances
12
+ * against profile snapshots generated by the fhir-profile module.
13
+ *
14
+ * @module fhir-validator
15
+ */
16
+ import type { CanonicalProfile, Resource } from '../model/index.js';
17
+ /**
18
+ * Configuration options for structural validation.
19
+ *
20
+ * @example
21
+ * ```typescript
22
+ * const options: ValidationOptions = {
23
+ * profileUrl: 'http://hl7.org/fhir/StructureDefinition/Patient',
24
+ * validateSlicing: true,
25
+ * validateFixed: true,
26
+ * failFast: false,
27
+ * };
28
+ * ```
29
+ */
30
+ export interface ValidationOptions {
31
+ /**
32
+ * Profile URL to validate against.
33
+ *
34
+ * If not specified, the validator will attempt to extract the profile
35
+ * from `resource.meta.profile[0]`. If neither is available, the
36
+ * validator falls back to the base resource type
37
+ * (e.g., `http://hl7.org/fhir/StructureDefinition/{resourceType}`).
38
+ */
39
+ readonly profileUrl?: string;
40
+ /**
41
+ * Whether to validate slicing constraints.
42
+ *
43
+ * When `true` (default), the validator checks that array elements
44
+ * match their declared slices and that closed slicing rules are
45
+ * respected.
46
+ *
47
+ * @default true
48
+ */
49
+ readonly validateSlicing?: boolean;
50
+ /**
51
+ * Whether to validate fixed and pattern value constraints.
52
+ *
53
+ * When `true` (default), the validator checks that element values
54
+ * match any `fixed[x]` or `pattern[x]` constraints declared in
55
+ * the profile.
56
+ *
57
+ * @default true
58
+ */
59
+ readonly validateFixed?: boolean;
60
+ /**
61
+ * Maximum depth for nested validation.
62
+ *
63
+ * Prevents runaway recursion in deeply nested or pathological
64
+ * resource structures.
65
+ *
66
+ * @default 50
67
+ */
68
+ readonly maxDepth?: number;
69
+ /**
70
+ * Whether to stop on the first error or collect all issues.
71
+ *
72
+ * When `true`, the validator throws a {@link ValidationFailedError}
73
+ * on the first error-severity issue. When `false` (default), all
74
+ * issues are collected and returned in the result.
75
+ *
76
+ * @default false
77
+ */
78
+ readonly failFast?: boolean;
79
+ /**
80
+ * Whether to skip FHIRPath invariant validation.
81
+ *
82
+ * When `true`, constraint expressions from the profile are not
83
+ * evaluated. Useful for performance or when FHIRPath evaluation
84
+ * is not needed.
85
+ *
86
+ * @default false
87
+ */
88
+ readonly skipInvariants?: boolean;
89
+ }
90
+ /**
91
+ * Result of structural validation.
92
+ *
93
+ * Contains the overall validity status, the validated resource, and
94
+ * all issues encountered during validation.
95
+ *
96
+ * @example
97
+ * ```typescript
98
+ * const result = await validator.validate(patient);
99
+ * if (result.valid) {
100
+ * console.log('Resource is valid');
101
+ * } else {
102
+ * for (const issue of result.issues) {
103
+ * console.error(`${issue.severity}: ${issue.message} (at ${issue.path})`);
104
+ * }
105
+ * }
106
+ * ```
107
+ */
108
+ export interface ValidationResult {
109
+ /**
110
+ * Whether the resource is valid.
111
+ *
112
+ * `true` when no error-severity issues were recorded.
113
+ * Warnings and informational issues do not affect this flag.
114
+ */
115
+ readonly valid: boolean;
116
+ /** The resource that was validated. */
117
+ readonly resource: Resource;
118
+ /** The profile that was validated against. */
119
+ readonly profileUrl: string;
120
+ /** The resolved CanonicalProfile used for validation. */
121
+ readonly profile: CanonicalProfile;
122
+ /** Issues encountered during validation (errors + warnings + info). */
123
+ readonly issues: readonly ValidationIssue[];
124
+ }
125
+ /**
126
+ * A single issue encountered during validation.
127
+ *
128
+ * Mirrors the concept of FHIR OperationOutcome.issue but scoped to
129
+ * structural validation. Issues are collected during validation and
130
+ * returned in {@link ValidationResult.issues}.
131
+ *
132
+ * @example
133
+ * ```typescript
134
+ * const issue: ValidationIssue = {
135
+ * severity: 'error',
136
+ * code: 'CARDINALITY_MIN_VIOLATION',
137
+ * message: "Element 'Patient.name' requires at least 1 value(s), but found 0",
138
+ * path: 'Patient.name',
139
+ * expression: 'Patient.name',
140
+ * };
141
+ * ```
142
+ */
143
+ export interface ValidationIssue {
144
+ /** Severity level of the issue. */
145
+ readonly severity: 'error' | 'warning' | 'information';
146
+ /** Machine-readable issue code. */
147
+ readonly code: ValidationIssueCode;
148
+ /** Human-readable description of the issue. */
149
+ readonly message: string;
150
+ /**
151
+ * Element path where the issue occurred (dot-notation).
152
+ *
153
+ * @example `'Patient.name'`, `'Observation.value[x]'`
154
+ */
155
+ readonly path?: string;
156
+ /**
157
+ * FHIRPath expression pointing to the problematic element.
158
+ *
159
+ * Typically identical to `path` for structural validation, but may
160
+ * differ for sliced elements or choice types.
161
+ *
162
+ * @example `'Patient.identifier.where(system="urn:oid:1.2.3")'`
163
+ */
164
+ readonly expression?: string;
165
+ /** Additional diagnostic information for debugging. */
166
+ readonly diagnostics?: string;
167
+ }
168
+ /**
169
+ * Machine-readable issue codes for structural validation.
170
+ *
171
+ * Each code corresponds to a specific category of validation failure.
172
+ * Codes are designed to be stable across versions for programmatic
173
+ * consumption.
174
+ */
175
+ export type ValidationIssueCode =
176
+ /** Element has fewer values than the minimum cardinality. */
177
+ 'CARDINALITY_MIN_VIOLATION'
178
+ /** Element has more values than the maximum cardinality. */
179
+ | 'CARDINALITY_MAX_VIOLATION'
180
+ /** Value type does not match any of the allowed types. */
181
+ | 'TYPE_MISMATCH'
182
+ /** Choice type field uses an unsupported type suffix. */
183
+ | 'INVALID_CHOICE_TYPE'
184
+ /** A required element (min ≥ 1) is missing from the resource. */
185
+ | 'REQUIRED_ELEMENT_MISSING'
186
+ /** Value does not match the fixed value constraint. */
187
+ | 'FIXED_VALUE_MISMATCH'
188
+ /** Value does not match the pattern value constraint (partial match). */
189
+ | 'PATTERN_VALUE_MISMATCH'
190
+ /** Value does not match any slice discriminator in a closed slicing. */
191
+ | 'SLICING_NO_MATCH'
192
+ /** Slice cardinality violation (too few or too many values in a slice). */
193
+ | 'SLICING_CARDINALITY_VIOLATION'
194
+ /** Ordered slicing constraint violated (values out of order). */
195
+ | 'SLICING_ORDER_VIOLATION'
196
+ /** Reference target does not match any of the allowed target profiles. */
197
+ | 'REFERENCE_TARGET_MISMATCH'
198
+ /** The specified profile could not be found or loaded. */
199
+ | 'PROFILE_NOT_FOUND'
200
+ /** Resource type does not match the profile's type. */
201
+ | 'RESOURCE_TYPE_MISMATCH'
202
+ /** Resource contains an element not defined in the profile. */
203
+ | 'UNKNOWN_ELEMENT'
204
+ /** FHIRPath invariant evaluation is not yet supported (skipped). */
205
+ | 'INVARIANT_NOT_EVALUATED'
206
+ /** FHIRPath invariant constraint evaluated to false. */
207
+ | 'INVARIANT_VIOLATION'
208
+ /** FHIRPath invariant expression failed to evaluate (runtime error). */
209
+ | 'INVARIANT_EVALUATION_ERROR'
210
+ /** Internal validator error (should not happen). */
211
+ | 'INTERNAL_ERROR';
212
+ /**
213
+ * Internal state passed through the validation traversal.
214
+ *
215
+ * Tracks the current depth, accumulated issues, and options
216
+ * for the validation run.
217
+ *
218
+ * @internal Used by the StructureValidator and validation rules.
219
+ */
220
+ export interface ValidationContext {
221
+ /** The CanonicalProfile being validated against. */
222
+ readonly profile: CanonicalProfile;
223
+ /** Mutable array of accumulated issues. */
224
+ readonly issues: ValidationIssue[];
225
+ /** Resolved validation options. */
226
+ readonly options: Required<ValidationOptions>;
227
+ /** Current traversal depth (for maxDepth enforcement). */
228
+ depth: number;
229
+ }
230
+ /**
231
+ * Create a {@link ValidationIssue} with the given parameters.
232
+ *
233
+ * Convenience factory to reduce boilerplate when recording issues.
234
+ *
235
+ * @param severity - Issue severity level.
236
+ * @param code - Machine-readable issue code.
237
+ * @param message - Human-readable description.
238
+ * @param options - Optional path, expression, and diagnostics.
239
+ * @returns A frozen ValidationIssue object.
240
+ */
241
+ export declare function createValidationIssue(severity: ValidationIssue['severity'], code: ValidationIssueCode, message: string, options?: {
242
+ path?: string;
243
+ expression?: string;
244
+ diagnostics?: string;
245
+ }): ValidationIssue;
246
+ /**
247
+ * Create a {@link ValidationContext} with resolved defaults.
248
+ *
249
+ * @param profile - The CanonicalProfile to validate against.
250
+ * @param options - User-provided options (defaults applied for missing fields).
251
+ * @returns A new ValidationContext ready for traversal.
252
+ *
253
+ * @internal
254
+ */
255
+ export declare function createValidationContext(profile: CanonicalProfile, options?: ValidationOptions): ValidationContext;
256
+ /**
257
+ * Resolve default validation options.
258
+ *
259
+ * Fills in missing fields with sensible defaults.
260
+ *
261
+ * @param options - User-provided options (may be partial).
262
+ * @returns Fully resolved options with all fields populated.
263
+ */
264
+ export declare function resolveValidationOptions(options?: ValidationOptions): Required<ValidationOptions>;
265
+ /**
266
+ * Check whether a validation result has any error-severity issues.
267
+ *
268
+ * @param issues - The issues to check.
269
+ * @returns `true` if any issue has severity `'error'`.
270
+ */
271
+ export declare function hasValidationErrors(issues: readonly ValidationIssue[]): boolean;
272
+ /**
273
+ * Filter issues by severity.
274
+ *
275
+ * @param issues - The issues to filter.
276
+ * @param severity - The severity to filter by.
277
+ * @returns Issues matching the specified severity.
278
+ */
279
+ export declare function filterIssuesBySeverity(issues: readonly ValidationIssue[], severity: ValidationIssue['severity']): ValidationIssue[];
280
+ /**
281
+ * Filter issues by code.
282
+ *
283
+ * @param issues - The issues to filter.
284
+ * @param code - The issue code to filter by.
285
+ * @returns Issues matching the specified code.
286
+ */
287
+ export declare function filterIssuesByCode(issues: readonly ValidationIssue[], code: ValidationIssueCode): ValidationIssue[];
288
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/validator/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAMpE;;;;;;;;;;;;GAYG;AACH,MAAM,WAAW,iBAAiB;IAChC;;;;;;;OAOG;IACH,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;IAE7B;;;;;;;;OAQG;IACH,QAAQ,CAAC,eAAe,CAAC,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