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,124 @@
1
+ /**
2
+ * Bundle Loader — Phase 7
3
+ *
4
+ * Loads FHIR Bundle JSON files containing StructureDefinition entries
5
+ * and converts them to CanonicalProfile[] for downstream consumption
6
+ * by Phase 8's schema generation pipeline.
7
+ *
8
+ * Two data paths exist in MedXAI:
9
+ *
10
+ * ```
11
+ * Path A — Stage-1 Validation (unchanged):
12
+ * core-definitions/*.json (73 files)
13
+ * → loadAllCoreDefinitions()
14
+ * → FhirContextImpl (runtime validation)
15
+ *
16
+ * Path B — Stage-2 Schema Generation (this module):
17
+ * spec/fhir/r4/profiles-*.json (complete bundles)
18
+ * → BundleLoader
19
+ * → StructureDefinitionRegistry (Phase 8)
20
+ * → TableSchemaBuilder (Phase 8)
21
+ * ```
22
+ *
23
+ * @module fhir-context
24
+ */
25
+ import type { CanonicalProfile } from '../model/canonical-profile.js';
26
+ import type { StructureDefinitionKind } from '../model/primitives.js';
27
+ import type { ParseIssue } from '../parser/parse-error.js';
28
+ /**
29
+ * Options for filtering which StructureDefinitions to load from a bundle.
30
+ */
31
+ export interface BundleLoadOptions {
32
+ /** Only include entries where kind matches. Default: all kinds. */
33
+ filterKind?: StructureDefinitionKind | StructureDefinitionKind[];
34
+ /** Exclude abstract definitions. Default: false (include abstract). */
35
+ excludeAbstract?: boolean;
36
+ /** Only include entries where type matches one of these. */
37
+ filterTypes?: string[];
38
+ }
39
+ /**
40
+ * Result of loading one or more bundles.
41
+ */
42
+ export interface BundleLoadResult {
43
+ /** Successfully loaded CanonicalProfiles. */
44
+ profiles: CanonicalProfile[];
45
+ /** Errors encountered during loading (partial failures). */
46
+ errors: BundleLoadError[];
47
+ /** Summary statistics. */
48
+ stats: {
49
+ /** Total StructureDefinition entries found in bundle(s). */
50
+ total: number;
51
+ /** Successfully parsed and converted to CanonicalProfile. */
52
+ loaded: number;
53
+ /** Filtered out by options (kind, abstract, type). */
54
+ skipped: number;
55
+ /** Failed to parse or convert. */
56
+ failed: number;
57
+ };
58
+ }
59
+ /**
60
+ * Describes a single error encountered while loading a StructureDefinition.
61
+ */
62
+ export interface BundleLoadError {
63
+ /** The name of the StructureDefinition that failed. */
64
+ name: string;
65
+ /** The canonical URL of the StructureDefinition that failed. */
66
+ url: string;
67
+ /** The error that occurred. */
68
+ error: Error;
69
+ /** Parse issues, if the failure was during parsing. */
70
+ parseIssues?: readonly ParseIssue[];
71
+ }
72
+ /**
73
+ * Minimal Bundle shape for type-safe access.
74
+ */
75
+ interface BundleShape {
76
+ resourceType: string;
77
+ entry?: Array<{
78
+ resource?: Record<string, unknown>;
79
+ }>;
80
+ }
81
+ /**
82
+ * Load CanonicalProfiles from an already-parsed Bundle object.
83
+ *
84
+ * This is the core loading function. It:
85
+ * 1. Extracts all StructureDefinition entries from the bundle
86
+ * 2. Applies filter options (kind, abstract, type)
87
+ * 3. Parses each SD through `parseStructureDefinition`
88
+ * 4. Converts each parsed SD to `CanonicalProfile` via `buildCanonicalProfile`
89
+ * 5. Collects errors without aborting (partial failure tolerance)
90
+ *
91
+ * @param bundle - A parsed FHIR Bundle object containing StructureDefinition entries.
92
+ * @param options - Optional filters to control which entries are loaded.
93
+ * @returns BundleLoadResult with profiles, errors, and statistics.
94
+ */
95
+ export declare function loadBundleFromObject(bundle: BundleShape, options?: BundleLoadOptions): BundleLoadResult;
96
+ /**
97
+ * Load CanonicalProfiles from a FHIR Bundle JSON file.
98
+ *
99
+ * Reads the file synchronously (spec files are loaded once at startup),
100
+ * parses the JSON, and delegates to `loadBundleFromObject`.
101
+ *
102
+ * @param filePath - Absolute path to a FHIR Bundle JSON file.
103
+ * @param options - Optional filters to control which entries are loaded.
104
+ * @returns BundleLoadResult with profiles, errors, and statistics.
105
+ * @throws Error if the file cannot be read or is not valid JSON.
106
+ */
107
+ export declare function loadBundleFromFile(filePath: string, options?: BundleLoadOptions): BundleLoadResult;
108
+ /**
109
+ * Load and merge multiple bundle files in order.
110
+ *
111
+ * Later bundles override earlier ones for the same canonical URL.
112
+ * This supports the standard loading order:
113
+ * 1. profiles-types.json — type system (no tables)
114
+ * 2. profiles-resources.json — clinical resources
115
+ * 3. profiles-others.json — conformance resources
116
+ * 4. profiles-platform.json — platform resources (Phase 9)
117
+ *
118
+ * @param filePaths - Array of absolute paths to FHIR Bundle JSON files.
119
+ * @param options - Optional filters applied to each bundle.
120
+ * @returns Merged BundleLoadResult with deduplicated profiles.
121
+ */
122
+ export declare function loadBundlesFromFiles(filePaths: string[], options?: BundleLoadOptions): BundleLoadResult;
123
+ export {};
124
+ //# sourceMappingURL=bundle-loader.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bundle-loader.d.ts","sourceRoot":"","sources":["../../../src/context/bundle-loader.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAMH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AACtE,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,wBAAwB,CAAC;AACtE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAM3D;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,mEAAmE;IACnE,UAAU,CAAC,EAAE,uBAAuB,GAAG,uBAAuB,EAAE,CAAC;IAEjE,uEAAuE;IACvE,eAAe,CAAC,EAAE,OAAO,CAAC;IAE1B,4DAA4D;IAC5D,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC;CACxB;AAED;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,6CAA6C;IAC7C,QAAQ,EAAE,gBAAgB,EAAE,CAAC;IAE7B,4DAA4D;IAC5D,MAAM,EAAE,eAAe,EAAE,CAAC;IAE1B,0BAA0B;IAC1B,KAAK,EAAE;QACL,4DAA4D;QAC5D,KAAK,EAAE,MAAM,CAAC;QACd,6DAA6D;QAC7D,MAAM,EAAE,MAAM,CAAC;QACf,sDAAsD;QACtD,OAAO,EAAE,MAAM,CAAC;QAChB,kCAAkC;QAClC,MAAM,EAAE,MAAM,CAAC;KAChB,CAAC;CACH;AAED;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,uDAAuD;IACvD,IAAI,EAAE,MAAM,CAAC;IACb,gEAAgE;IAChE,GAAG,EAAE,MAAM,CAAC;IACZ,+BAA+B;IAC/B,KAAK,EAAE,KAAK,CAAC;IACb,uDAAuD;IACvD,WAAW,CAAC,EAAE,SAAS,UAAU,EAAE,CAAC;CACrC;AAMD;;GAEG;AACH,UAAU,WAAW;IACnB,YAAY,EAAE,MAAM,CAAC;IACrB,KAAK,CAAC,EAAE,KAAK,CAAC;QACZ,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;KACpC,CAAC,CAAC;CACJ;AAoED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,oBAAoB,CAClC,MAAM,EAAE,WAAW,EACnB,OAAO,CAAC,EAAE,iBAAiB,GAC1B,gBAAgB,CA+ClB;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,kBAAkB,CAChC,QAAQ,EAAE,MAAM,EAChB,OAAO,CAAC,EAAE,iBAAiB,GAC1B,gBAAgB,CAIlB;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,oBAAoB,CAClC,SAAS,EAAE,MAAM,EAAE,EACnB,OAAO,CAAC,EAAE,iBAAiB,GAC1B,gBAAgB,CAyBlB"}
@@ -0,0 +1,72 @@
1
+ /**
2
+ * fhir-context — Core Definitions Index
3
+ *
4
+ * Provides the list of core FHIR R4 StructureDefinition filenames
5
+ * and a utility to load them from the `core-definitions/` directory.
6
+ *
7
+ * These definitions are extracted from the official FHIR R4 v4.0.1
8
+ * specification (`profiles-resources.json` and `profiles-types.json`).
9
+ *
10
+ * @module fhir-context
11
+ */
12
+ import type { StructureDefinition } from '../../model/index.js';
13
+ /**
14
+ * Base resource types — the foundation of the FHIR type hierarchy.
15
+ * These MUST be loaded first as other definitions depend on them.
16
+ */
17
+ export declare const BASE_RESOURCES: readonly ["Resource", "DomainResource", "Element", "BackboneElement", "Extension"];
18
+ /**
19
+ * Primitive types — FHIR primitive data types.
20
+ */
21
+ export declare const PRIMITIVE_TYPES: readonly ["base64Binary", "boolean", "canonical", "code", "date", "dateTime", "decimal", "id", "instant", "integer", "markdown", "oid", "positiveInt", "string", "time", "unsignedInt", "uri", "url", "uuid", "xhtml"];
22
+ /**
23
+ * Complex types — FHIR complex data types (non-resource).
24
+ */
25
+ export declare const COMPLEX_TYPES: readonly ["Address", "Age", "Annotation", "Attachment", "CodeableConcept", "Coding", "ContactDetail", "ContactPoint", "Count", "Distance", "Dosage", "Duration", "HumanName", "Identifier", "Meta", "Money", "Narrative", "Period", "Quantity", "Range", "Ratio", "Reference", "SampledData", "Signature", "Timing"];
26
+ /**
27
+ * Core clinical resources — commonly used FHIR resource types.
28
+ */
29
+ export declare const CORE_RESOURCES: readonly ["AllergyIntolerance", "Binary", "Bundle", "CarePlan", "Claim", "CodeSystem", "Condition", "DiagnosticReport", "DocumentReference", "Encounter", "Immunization", "Location", "Medication", "MedicationRequest", "Observation", "Organization", "Patient", "Practitioner", "Procedure", "Questionnaire", "ServiceRequest", "StructureDefinition", "ValueSet"];
30
+ /**
31
+ * All core definition filenames in dependency order:
32
+ * base → primitives → complex types → resources.
33
+ */
34
+ export declare const ALL_CORE_DEFINITIONS: readonly string[];
35
+ /**
36
+ * Resolve the absolute path to the `core-definitions/` directory.
37
+ *
38
+ * Works both in ESM (via `import.meta.url`) and when a custom
39
+ * `specDirectory` is provided.
40
+ *
41
+ * @param specDirectory - Optional override directory path
42
+ * @returns Absolute path to the core definitions directory
43
+ */
44
+ export declare function getCoreDefinitionsDir(specDirectory?: string): string;
45
+ /**
46
+ * Load a single core StructureDefinition by name (synchronous).
47
+ *
48
+ * @param name - Definition name (e.g., `"Patient"`, `"string"`)
49
+ * @param baseDir - Directory containing the JSON files
50
+ * @returns Parsed StructureDefinition
51
+ * @throws {@link LoaderError} if the file cannot be read or parsed
52
+ */
53
+ export declare function loadCoreDefinitionSync(name: string, baseDir: string): StructureDefinition;
54
+ /**
55
+ * Load a single core StructureDefinition by name (async).
56
+ *
57
+ * @param name - Definition name (e.g., `"Patient"`, `"string"`)
58
+ * @param baseDir - Directory containing the JSON files
59
+ * @returns Parsed StructureDefinition
60
+ * @throws {@link LoaderError} if the file cannot be read or parsed
61
+ */
62
+ export declare function loadCoreDefinition(name: string, baseDir: string): Promise<StructureDefinition>;
63
+ /**
64
+ * Load all core definitions and return them as a Map.
65
+ *
66
+ * Loads in dependency order (base → primitives → complex → resources).
67
+ *
68
+ * @param specDirectory - Optional override directory path
69
+ * @returns Map of canonical URL → StructureDefinition
70
+ */
71
+ export declare function loadAllCoreDefinitions(specDirectory?: string): Promise<Map<string, StructureDefinition>>;
72
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/context/core-definitions/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAOH,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAQhE;;;GAGG;AACH,eAAO,MAAM,cAAc,oFAMjB,CAAC;AAEX;;GAEG;AACH,eAAO,MAAM,eAAe,wNAKlB,CAAC;AAEX;;GAEG;AACH,eAAO,MAAM,aAAa,sTAMhB,CAAC;AAEX;;GAEG;AACH,eAAO,MAAM,cAAc,uWAMjB,CAAC;AAEX;;;GAGG;AACH,eAAO,MAAM,oBAAoB,EAAE,SAAS,MAAM,EAKjD,CAAC;AAMF;;;;;;;;GAQG;AACH,wBAAgB,qBAAqB,CAAC,aAAa,CAAC,EAAE,MAAM,GAAG,MAAM,CAOpE;AAED;;;;;;;GAOG;AACH,wBAAgB,sBAAsB,CACpC,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,MAAM,GACd,mBAAmB,CA2BrB;AAED;;;;;;;GAOG;AACH,wBAAsB,kBAAkB,CACtC,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,MAAM,GACd,OAAO,CAAC,mBAAmB,CAAC,CA2B9B;AAED;;;;;;;GAOG;AACH,wBAAsB,sBAAsB,CAC1C,aAAa,CAAC,EAAE,MAAM,GACrB,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,mBAAmB,CAAC,CAAC,CAU3C"}
@@ -0,0 +1,114 @@
1
+ /**
2
+ * fhir-context — Error Types
3
+ *
4
+ * Structured error hierarchy for the FHIR context module.
5
+ * All errors extend {@link ContextError} so consumers can catch
6
+ * context-related failures with a single `catch` clause.
7
+ *
8
+ * Error hierarchy:
9
+ * ```
10
+ * ContextError (base)
11
+ * ├── ResourceNotFoundError
12
+ * ├── CircularDependencyError
13
+ * ├── LoaderError
14
+ * └── InvalidStructureDefinitionError
15
+ * ```
16
+ *
17
+ * @module fhir-context
18
+ */
19
+ /**
20
+ * Base error class for all fhir-context failures.
21
+ *
22
+ * Provides a stable `name` property and preserves the original `cause`
23
+ * when wrapping lower-level errors.
24
+ */
25
+ export declare class ContextError extends Error {
26
+ readonly name: string;
27
+ constructor(message: string, options?: ErrorOptions);
28
+ }
29
+ /**
30
+ * Thrown when a StructureDefinition cannot be resolved by any loader.
31
+ *
32
+ * @example
33
+ * ```typescript
34
+ * throw new ResourceNotFoundError(
35
+ * 'http://hl7.org/fhir/StructureDefinition/UnknownType',
36
+ * ['memory', 'filesystem']
37
+ * );
38
+ * ```
39
+ */
40
+ export declare class ResourceNotFoundError extends ContextError {
41
+ readonly name = "ResourceNotFoundError";
42
+ /** The canonical URL that could not be resolved */
43
+ readonly url: string;
44
+ /** Loader source types that were tried */
45
+ readonly triedSources: readonly string[];
46
+ constructor(url: string, triedSources?: string[]);
47
+ }
48
+ /**
49
+ * Thrown when a circular `baseDefinition` chain is detected during
50
+ * inheritance resolution.
51
+ *
52
+ * @example
53
+ * ```typescript
54
+ * throw new CircularDependencyError([
55
+ * 'http://example.org/A',
56
+ * 'http://example.org/B',
57
+ * 'http://example.org/A', // cycle back to A
58
+ * ]);
59
+ * ```
60
+ */
61
+ export declare class CircularDependencyError extends ContextError {
62
+ readonly name = "CircularDependencyError";
63
+ /** The full chain of URLs that forms the cycle */
64
+ readonly chain: readonly string[];
65
+ constructor(chain: string[]);
66
+ }
67
+ /**
68
+ * Thrown when a {@link StructureDefinitionLoader} encounters an I/O
69
+ * or parse failure while loading a definition.
70
+ *
71
+ * The original error is preserved as `cause` for debugging.
72
+ *
73
+ * @example
74
+ * ```typescript
75
+ * throw new LoaderError(
76
+ * 'http://hl7.org/fhir/StructureDefinition/Patient',
77
+ * 'filesystem',
78
+ * originalError
79
+ * );
80
+ * ```
81
+ */
82
+ export declare class LoaderError extends ContextError {
83
+ readonly name = "LoaderError";
84
+ /** The canonical URL being loaded when the error occurred */
85
+ readonly url: string;
86
+ /** The loader source type that failed */
87
+ readonly sourceType: string;
88
+ constructor(url: string, sourceType: string, cause?: Error);
89
+ }
90
+ /**
91
+ * Thrown when a loaded or registered StructureDefinition is missing
92
+ * required fields or has invalid structure.
93
+ *
94
+ * Required fields for a valid StructureDefinition:
95
+ * - `url` — canonical URL
96
+ * - `name` — computer-friendly name
97
+ * - `status` — publication status
98
+ * - `kind` — resource | complex-type | primitive-type | logical
99
+ *
100
+ * @example
101
+ * ```typescript
102
+ * throw new InvalidStructureDefinitionError(
103
+ * 'Missing required field: url',
104
+ * 'http://example.org/MyProfile'
105
+ * );
106
+ * ```
107
+ */
108
+ export declare class InvalidStructureDefinitionError extends ContextError {
109
+ readonly name = "InvalidStructureDefinitionError";
110
+ /** The URL of the invalid definition (if available) */
111
+ readonly url: string | undefined;
112
+ constructor(reason: string, url?: string);
113
+ }
114
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../../src/context/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAMH;;;;;GAKG;AACH,qBAAa,YAAa,SAAQ,KAAK;IACrC,SAAkB,IAAI,EAAE,MAAM,CAAkB;gBAEpC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,YAAY;CAKpD;AAMD;;;;;;;;;;GAUG;AACH,qBAAa,qBAAsB,SAAQ,YAAY;IACrD,SAAkB,IAAI,2BAA2B;IAEjD,mDAAmD;IACnD,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IAErB,0CAA0C;IAC1C,QAAQ,CAAC,YAAY,EAAE,SAAS,MAAM,EAAE,CAAC;gBAE7B,GAAG,EAAE,MAAM,EAAE,YAAY,GAAE,MAAM,EAAO;CASrD;AAMD;;;;;;;;;;;;GAYG;AACH,qBAAa,uBAAwB,SAAQ,YAAY;IACvD,SAAkB,IAAI,6BAA6B;IAEnD,kDAAkD;IAClD,QAAQ,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,CAAC;gBAEtB,KAAK,EAAE,MAAM,EAAE;CAK5B;AAMD;;;;;;;;;;;;;;GAcG;AACH,qBAAa,WAAY,SAAQ,YAAY;IAC3C,SAAkB,IAAI,iBAAiB;IAEvC,6DAA6D;IAC7D,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IAErB,yCAAyC;IACzC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;gBAEhB,GAAG,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,KAAK;CAQ3D;AAMD;;;;;;;;;;;;;;;;;GAiBG;AACH,qBAAa,+BAAgC,SAAQ,YAAY;IAC/D,SAAkB,IAAI,qCAAqC;IAE3D,uDAAuD;IACvD,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,CAAC;gBAErB,MAAM,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM;CAKzC"}
@@ -0,0 +1,72 @@
1
+ /**
2
+ * fhir-context — FhirContextImpl
3
+ *
4
+ * Concrete implementation of the {@link FhirContext} interface.
5
+ * Integrates the registry, loaders, and inheritance resolver into
6
+ * a single cohesive entry point.
7
+ *
8
+ * Conceptual mapping:
9
+ * - HAPI `FhirContext` → this class
10
+ * - HAPI `IValidationSupport` → loader delegation
11
+ * - HAPI `ValidationSupportChain` → CompositeLoader
12
+ *
13
+ * @module fhir-context
14
+ */
15
+ import type { StructureDefinition, CanonicalProfile } from '../model/index.js';
16
+ import type { FhirContext, FhirContextOptions, ContextStatistics } from './types.js';
17
+ import { StructureDefinitionRegistry } from './registry.js';
18
+ import { InheritanceChainResolver } from './inheritance-resolver.js';
19
+ /**
20
+ * Concrete implementation of {@link FhirContext}.
21
+ *
22
+ * @example
23
+ * ```typescript
24
+ * const ctx = new FhirContextImpl({
25
+ * loaders: [memoryLoader, fileLoader],
26
+ * });
27
+ * await ctx.preloadCoreDefinitions();
28
+ *
29
+ * const patient = await ctx.loadStructureDefinition(
30
+ * 'http://hl7.org/fhir/StructureDefinition/Patient'
31
+ * );
32
+ * ```
33
+ */
34
+ export declare class FhirContextImpl implements FhirContext {
35
+ private readonly _registry;
36
+ private readonly _resolver;
37
+ private readonly _loader;
38
+ private readonly _options;
39
+ private readonly _stats;
40
+ private readonly _innerTypes;
41
+ private readonly _canonicalProfiles;
42
+ private _disposed;
43
+ constructor(options: FhirContextOptions);
44
+ loadStructureDefinition(url: string): Promise<StructureDefinition>;
45
+ getStructureDefinition(url: string): StructureDefinition | undefined;
46
+ hasStructureDefinition(url: string): boolean;
47
+ resolveInheritanceChain(url: string): Promise<string[]>;
48
+ registerStructureDefinition(sd: StructureDefinition): void;
49
+ preloadCoreDefinitions(): Promise<void>;
50
+ getStatistics(): ContextStatistics;
51
+ registerCanonicalProfile(profile: CanonicalProfile): void;
52
+ getInnerType(typeName: string): CanonicalProfile | undefined;
53
+ hasInnerType(typeName: string): boolean;
54
+ dispose(): void;
55
+ /**
56
+ * Validate that a StructureDefinition has the minimum required fields.
57
+ */
58
+ private _validateStructureDefinition;
59
+ /**
60
+ * Guard against use after dispose.
61
+ */
62
+ private _ensureNotDisposed;
63
+ /**
64
+ * Direct access to the internal registry (for diagnostics).
65
+ */
66
+ get registry(): StructureDefinitionRegistry;
67
+ /**
68
+ * Direct access to the internal resolver (for diagnostics).
69
+ */
70
+ get resolver(): InheritanceChainResolver;
71
+ }
72
+ //# sourceMappingURL=fhir-context.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fhir-context.d.ts","sourceRoot":"","sources":["../../../src/context/fhir-context.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,KAAK,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAC/E,OAAO,KAAK,EACV,WAAW,EACX,kBAAkB,EAClB,iBAAiB,EAElB,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAE,2BAA2B,EAAqB,MAAM,eAAe,CAAC;AAC/E,OAAO,EAAE,wBAAwB,EAAE,MAAM,2BAA2B,CAAC;AAYrE;;;;;;;;;;;;;;GAcG;AACH,qBAAa,eAAgB,YAAW,WAAW;IACjD,OAAO,CAAC,QAAQ,CAAC,SAAS,CAA8B;IACxD,OAAO,CAAC,QAAQ,CAAC,SAAS,CAA2B;IACrD,OAAO,CAAC,QAAQ,CAAC,OAAO,CAA4B;IACpD,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAqB;IAC9C,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAoB;IAC3C,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAuC;IACnE,OAAO,CAAC,QAAQ,CAAC,kBAAkB,CAAuC;IAC1E,OAAO,CAAC,SAAS,CAAS;gBAEd,OAAO,EAAE,kBAAkB;IAuBjC,uBAAuB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,mBAAmB,CAAC;IAgCxE,sBAAsB,CAAC,GAAG,EAAE,MAAM,GAAG,mBAAmB,GAAG,SAAS;IAKpE,sBAAsB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO;IAKtC,uBAAuB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;IAO7D,2BAA2B,CAAC,EAAE,EAAE,mBAAmB,GAAG,IAAI;IAWpD,sBAAsB,IAAI,OAAO,CAAC,IAAI,CAAC;IAY7C,aAAa,IAAI,iBAAiB;IAIlC,wBAAwB,CAAC,OAAO,EAAE,gBAAgB,GAAG,IAAI;IAYzD,YAAY,CAAC,QAAQ,EAAE,MAAM,GAAG,gBAAgB,GAAG,SAAS;IAK5D,YAAY,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO;IAKvC,OAAO,IAAI,IAAI;IAkBf;;OAEG;IACH,OAAO,CAAC,4BAA4B;IASpC;;OAEG;IACH,OAAO,CAAC,kBAAkB;IAY1B;;OAEG;IACH,IAAI,QAAQ,IAAI,2BAA2B,CAE1C;IAED;;OAEG;IACH,IAAI,QAAQ,IAAI,wBAAwB,CAEvC;CACF"}
@@ -0,0 +1,21 @@
1
+ /**
2
+ * fhir-context — Public API Barrel Exports
3
+ *
4
+ * Re-exports all public types, classes, and functions from the
5
+ * context module. Internal implementation details (registry,
6
+ * resolver) are NOT re-exported here.
7
+ *
8
+ * @module fhir-context
9
+ */
10
+ export type { FhirContext, FhirContextOptions, StructureDefinitionLoader, LoaderOptions, ContextStatistics, } from './types.js';
11
+ export { createEmptyStatistics } from './types.js';
12
+ export { FhirContextImpl } from './fhir-context.js';
13
+ export { MemoryLoader } from './loaders/memory-loader.js';
14
+ export { FileSystemLoader } from './loaders/file-loader.js';
15
+ export { CompositeLoader } from './loaders/composite-loader.js';
16
+ export { ContextError, ResourceNotFoundError, CircularDependencyError, LoaderError, InvalidStructureDefinitionError, } from './errors.js';
17
+ export type { BundleLoadOptions, BundleLoadResult, BundleLoadError, } from './bundle-loader.js';
18
+ export { loadBundleFromObject, loadBundleFromFile, loadBundlesFromFiles, } from './bundle-loader.js';
19
+ export { extractInnerTypes, buildTypeName, isBackboneElementType, } from './inner-type-extractor.js';
20
+ export { BASE_RESOURCES, PRIMITIVE_TYPES, COMPLEX_TYPES, CORE_RESOURCES, ALL_CORE_DEFINITIONS, loadAllCoreDefinitions, loadCoreDefinition, loadCoreDefinitionSync, getCoreDefinitionsDir, } from './core-definitions/index.js';
21
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/context/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAGH,YAAY,EACV,WAAW,EACX,kBAAkB,EAClB,yBAAyB,EACzB,aAAa,EACb,iBAAiB,GAClB,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AAGnD,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAGpD,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC1D,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAC5D,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAGhE,OAAO,EACL,YAAY,EACZ,qBAAqB,EACrB,uBAAuB,EACvB,WAAW,EACX,+BAA+B,GAChC,MAAM,aAAa,CAAC;AAGrB,YAAY,EACV,iBAAiB,EACjB,gBAAgB,EAChB,eAAe,GAChB,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EACL,oBAAoB,EACpB,kBAAkB,EAClB,oBAAoB,GACrB,MAAM,oBAAoB,CAAC;AAG5B,OAAO,EACL,iBAAiB,EACjB,aAAa,EACb,qBAAqB,GACtB,MAAM,2BAA2B,CAAC;AAGnC,OAAO,EACL,cAAc,EACd,eAAe,EACf,aAAa,EACb,cAAc,EACd,oBAAoB,EACpB,sBAAsB,EACtB,kBAAkB,EAClB,sBAAsB,EACtB,qBAAqB,GACtB,MAAM,6BAA6B,CAAC"}
@@ -0,0 +1,98 @@
1
+ /**
2
+ * fhir-context — Inheritance Chain Resolver
3
+ *
4
+ * Resolves the `baseDefinition` inheritance chain for a FHIR
5
+ * StructureDefinition, walking from a child profile up to the root
6
+ * resource type (e.g., `Resource`).
7
+ *
8
+ * Features:
9
+ * - Recursive resolution with on-demand loading
10
+ * - Circular dependency detection via an "in-flight" Set
11
+ * - Resolved chain caching with explicit invalidation
12
+ *
13
+ * @module fhir-context
14
+ */
15
+ import type { StructureDefinition } from '../model/index.js';
16
+ /**
17
+ * Minimal interface for loading a StructureDefinition by canonical URL.
18
+ *
19
+ * This decouples the resolver from the full {@link FhirContext} interface,
20
+ * making it independently testable. The `FhirContextImpl` class (Task 3.6)
21
+ * will satisfy this interface.
22
+ */
23
+ export interface DefinitionProvider {
24
+ /**
25
+ * Load a StructureDefinition by canonical URL.
26
+ *
27
+ * Must throw {@link ResourceNotFoundError} if the URL cannot be resolved.
28
+ */
29
+ loadStructureDefinition(url: string): Promise<StructureDefinition>;
30
+ }
31
+ /**
32
+ * Resolves profile inheritance chains by walking `baseDefinition` links.
33
+ *
34
+ * The resolver loads each StructureDefinition on demand via the provided
35
+ * {@link DefinitionProvider}, detects circular dependencies, and caches
36
+ * resolved chains for repeated lookups.
37
+ *
38
+ * @example
39
+ * ```typescript
40
+ * const resolver = new InheritanceChainResolver(provider);
41
+ * const chain = await resolver.resolve(
42
+ * 'http://hl7.org/fhir/StructureDefinition/Patient'
43
+ * );
44
+ * // → ['http://hl7.org/fhir/StructureDefinition/Patient',
45
+ * // 'http://hl7.org/fhir/StructureDefinition/DomainResource',
46
+ * // 'http://hl7.org/fhir/StructureDefinition/Resource']
47
+ * ```
48
+ */
49
+ export declare class InheritanceChainResolver {
50
+ private readonly _provider;
51
+ /** Cache of resolved chains: canonical URL → chain array */
52
+ private readonly _cache;
53
+ /** Statistics counter */
54
+ private _resolutionCount;
55
+ constructor(provider: DefinitionProvider);
56
+ /**
57
+ * Resolve the full inheritance chain for a profile.
58
+ *
59
+ * Returns an array of canonical URLs ordered from child to root:
60
+ * `[startUrl, ..., parentUrl, rootUrl]`
61
+ *
62
+ * @param url - Canonical URL of the starting StructureDefinition
63
+ * @returns Inheritance chain from child to root
64
+ * @throws {@link CircularDependencyError} if a cycle is detected
65
+ * @throws {@link ResourceNotFoundError} if a definition cannot be loaded
66
+ */
67
+ resolve(url: string): Promise<string[]>;
68
+ /**
69
+ * Invalidate the cached chain for a specific URL.
70
+ *
71
+ * Should be called when a StructureDefinition is re-registered,
72
+ * as its `baseDefinition` may have changed.
73
+ *
74
+ * @param url - Canonical URL to invalidate
75
+ */
76
+ invalidate(url: string): void;
77
+ /**
78
+ * Clear all cached chains.
79
+ */
80
+ clearCache(): void;
81
+ /**
82
+ * Number of chains that have been resolved (not from cache).
83
+ */
84
+ get resolutionCount(): number;
85
+ /**
86
+ * Number of chains currently in the cache.
87
+ */
88
+ get cacheSize(): number;
89
+ /**
90
+ * Recursive resolution with circular dependency detection.
91
+ *
92
+ * @param url - Current URL to resolve
93
+ * @param inFlight - Set of URLs currently being resolved (cycle detection)
94
+ * @returns Chain from current URL to root
95
+ */
96
+ private _resolveRecursive;
97
+ }
98
+ //# sourceMappingURL=inheritance-resolver.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"inheritance-resolver.d.ts","sourceRoot":"","sources":["../../../src/context/inheritance-resolver.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAO7D;;;;;;GAMG;AACH,MAAM,WAAW,kBAAkB;IACjC;;;;OAIG;IACH,uBAAuB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAAC;CACpE;AAMD;;;;;;;;;;;;;;;;;GAiBG;AACH,qBAAa,wBAAwB;IACnC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAqB;IAE/C,4DAA4D;IAC5D,OAAO,CAAC,QAAQ,CAAC,MAAM,CAA+B;IAEtD,yBAAyB;IACzB,OAAO,CAAC,gBAAgB,CAAK;gBAEjB,QAAQ,EAAE,kBAAkB;IAQxC;;;;;;;;;;OAUG;IACG,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;IA2B7C;;;;;;;OAOG;IACH,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI;IAS7B;;OAEG;IACH,UAAU,IAAI,IAAI;IAIlB;;OAEG;IACH,IAAI,eAAe,IAAI,MAAM,CAE5B;IAED;;OAEG;IACH,IAAI,SAAS,IAAI,MAAM,CAEtB;IAMD;;;;;;OAMG;YACW,iBAAiB;CA2ChC"}
@@ -0,0 +1,80 @@
1
+ /**
2
+ * fhir-context — InnerType Extractor
3
+ *
4
+ * Extracts inner types (BackboneElement sub-types) from a {@link CanonicalProfile}.
5
+ * These inner types represent nested complex structures within a FHIR resource,
6
+ * such as `Patient.contact` → `PatientContact`.
7
+ *
8
+ * Inspired by Medplum's `StructureDefinitionParser.enterInnerType()` and
9
+ * `buildTypeName()` from `@medplum/core/src/typeschema/types.ts`.
10
+ *
11
+ * ## Algorithm
12
+ *
13
+ * 1. Traverse all elements in the profile's `elements` Map
14
+ * 2. Identify elements whose `types` include `BackboneElement` or `Element`
15
+ * 3. For each such element, collect all direct child elements (path prefix match)
16
+ * 4. Build a new `CanonicalProfile` for the inner type with a generated name
17
+ *
18
+ * ## Naming Convention
19
+ *
20
+ * Path segments are PascalCase-joined:
21
+ * - `Patient.contact` → `PatientContact`
22
+ * - `Bundle.entry.request` → `BundleEntryRequest`
23
+ * - `Observation.component` → `ObservationComponent`
24
+ *
25
+ * @module fhir-context
26
+ */
27
+ import type { CanonicalProfile, CanonicalElement } from '../model/canonical-profile.js';
28
+ /**
29
+ * Build a PascalCase type name from path segments.
30
+ *
31
+ * @param components - Path segments (e.g., `['Patient', 'contact']`)
32
+ * @returns PascalCase type name (e.g., `'PatientContact'`)
33
+ *
34
+ * @example
35
+ * ```typescript
36
+ * buildTypeName(['Patient', 'contact']) // → 'PatientContact'
37
+ * buildTypeName(['Bundle', 'entry', 'request']) // → 'BundleEntryRequest'
38
+ * buildTypeName(['Patient']) // → 'Patient'
39
+ * ```
40
+ */
41
+ export declare function buildTypeName(components: string[]): string;
42
+ /**
43
+ * Check if an element defines a BackboneElement or Element inner type.
44
+ *
45
+ * An element is an inner type root if:
46
+ * - Its `types` array contains a type with `code === 'BackboneElement'` or `code === 'Element'`
47
+ * - It is not the root element of the profile (path has at least one dot)
48
+ *
49
+ * @param element - The canonical element to check
50
+ * @returns `true` if this element defines an inner type
51
+ */
52
+ export declare function isBackboneElementType(element: CanonicalElement): boolean;
53
+ /**
54
+ * Extract inner types from a CanonicalProfile.
55
+ *
56
+ * Scans the profile's elements for BackboneElement/Element types and creates
57
+ * independent `CanonicalProfile` instances for each, containing only their
58
+ * direct child elements.
59
+ *
60
+ * The returned Map is keyed by the generated type name (e.g., `'PatientContact'`).
61
+ * Each inner type has its `parentType` set to the profile's type name.
62
+ *
63
+ * **Note:** This function also handles nested BackboneElements. For example,
64
+ * if `Bundle.entry` is a BackboneElement containing `Bundle.entry.request`
65
+ * (also a BackboneElement), both `BundleEntry` and `BundleEntryRequest` will
66
+ * be extracted. `BundleEntryRequest` will have `parentType: 'BundleEntry'`.
67
+ *
68
+ * @param profile - The CanonicalProfile to extract inner types from
69
+ * @returns Map of inner type name → CanonicalProfile
70
+ *
71
+ * @example
72
+ * ```typescript
73
+ * const innerTypes = extractInnerTypes(patientProfile);
74
+ * // innerTypes.get('PatientContact') → CanonicalProfile for Patient.contact
75
+ * // innerTypes.get('PatientCommunication') → CanonicalProfile for Patient.communication
76
+ * // innerTypes.get('PatientLink') → CanonicalProfile for Patient.link
77
+ * ```
78
+ */
79
+ export declare function extractInnerTypes(profile: CanonicalProfile): Map<string, CanonicalProfile>;
80
+ //# sourceMappingURL=inner-type-extractor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"inner-type-extractor.d.ts","sourceRoot":"","sources":["../../../src/context/inner-type-extractor.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AAMxF;;;;;;;;;;;;GAYG;AACH,wBAAgB,aAAa,CAAC,UAAU,EAAE,MAAM,EAAE,GAAG,MAAM,CAK1D;AAeD;;;;;;;;;GASG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAIxE;AAMD;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAgB,iBAAiB,CAC/B,OAAO,EAAE,gBAAgB,GACxB,GAAG,CAAC,MAAM,EAAE,gBAAgB,CAAC,CA0D/B"}
@@ -0,0 +1,47 @@
1
+ /**
2
+ * fhir-context — CompositeLoader
3
+ *
4
+ * Chains multiple {@link StructureDefinitionLoader} instances using the
5
+ * chain-of-responsibility pattern. Each loader is tried in order until
6
+ * one returns a non-null result.
7
+ *
8
+ * Conceptually equivalent to HAPI's `ValidationSupportChain`.
9
+ *
10
+ * @module fhir-context
11
+ */
12
+ import type { StructureDefinition } from '../../model/index.js';
13
+ import type { StructureDefinitionLoader } from '../types.js';
14
+ /**
15
+ * A loader that delegates to an ordered list of child loaders.
16
+ *
17
+ * Resolution stops at the first loader that returns a non-null result.
18
+ * If a loader throws an error, the error is collected and the next
19
+ * loader is tried. If all loaders fail or return null, the first
20
+ * collected error (if any) is thrown.
21
+ *
22
+ * This follows the HAPI `ValidationSupportChain` pattern: record
23
+ * errors from individual loaders but continue trying remaining loaders.
24
+ *
25
+ * @example
26
+ * ```typescript
27
+ * const composite = new CompositeLoader([memoryLoader, fileLoader]);
28
+ * const sd = await composite.load(url);
29
+ * // Tries memoryLoader first, then fileLoader
30
+ * ```
31
+ */
32
+ export declare class CompositeLoader implements StructureDefinitionLoader {
33
+ private readonly _loaders;
34
+ /**
35
+ * @param loaders - Ordered list of loaders to try. First match wins.
36
+ * @throws Error if loaders array is empty
37
+ */
38
+ constructor(loaders: StructureDefinitionLoader[]);
39
+ load(url: string): Promise<StructureDefinition | null>;
40
+ canLoad(url: string): boolean;
41
+ getSourceType(): string;
42
+ /**
43
+ * Number of child loaders in the chain.
44
+ */
45
+ get loaderCount(): number;
46
+ }
47
+ //# sourceMappingURL=composite-loader.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"composite-loader.d.ts","sourceRoot":"","sources":["../../../../src/context/loaders/composite-loader.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAChE,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,aAAa,CAAC;AAG7D;;;;;;;;;;;;;;;;;GAiBG;AACH,qBAAa,eAAgB,YAAW,yBAAyB;IAC/D,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAuC;IAEhE;;;OAGG;gBACS,OAAO,EAAE,yBAAyB,EAAE;IAO1C,IAAI,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,mBAAmB,GAAG,IAAI,CAAC;IA4B5D,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO;IAI7B,aAAa,IAAI,MAAM;IAKvB;;OAEG;IACH,IAAI,WAAW,IAAI,MAAM,CAExB;CACF"}