@atomic-ehr/codegen 0.0.1-canary.20250924114918.f41354b → 0.0.1-canary.20250925150012.6169b6d

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 (71) hide show
  1. package/dist/api/builder.d.ts +5 -5
  2. package/dist/api/builder.js +6 -6
  3. package/dist/api/generators/base/BaseGenerator.d.ts +5 -5
  4. package/dist/api/generators/base/BaseGenerator.js +4 -4
  5. package/dist/api/generators/base/FileManager.d.ts +2 -2
  6. package/dist/api/generators/base/FileManager.js +1 -1
  7. package/dist/api/generators/base/PythonTypeMapper.d.ts +3 -3
  8. package/dist/api/generators/base/PythonTypeMapper.js +1 -1
  9. package/dist/api/generators/base/TemplateEngine.d.ts +1 -1
  10. package/dist/api/generators/base/TemplateEngine.js +1 -1
  11. package/dist/api/generators/base/TypeMapper.d.ts +2 -2
  12. package/dist/api/generators/base/TypeScriptTypeMapper.d.ts +3 -3
  13. package/dist/api/generators/base/TypeScriptTypeMapper.js +1 -1
  14. package/dist/api/generators/base/builders/DirectoryBuilder.d.ts +4 -4
  15. package/dist/api/generators/base/builders/FileBuilder.d.ts +2 -2
  16. package/dist/api/generators/base/builders/IndexBuilder.d.ts +2 -2
  17. package/dist/api/generators/base/enhanced-errors.d.ts +2 -2
  18. package/dist/api/generators/base/enhanced-errors.js +1 -1
  19. package/dist/api/generators/base/error-handler.d.ts +2 -2
  20. package/dist/api/generators/base/error-handler.js +1 -1
  21. package/dist/api/generators/base/errors.d.ts +2 -2
  22. package/dist/api/generators/base/index.d.ts +22 -22
  23. package/dist/api/generators/base/index.js +11 -11
  24. package/dist/api/generators/base/types.d.ts +4 -4
  25. package/dist/api/generators/typescript.d.ts +6 -6
  26. package/dist/api/generators/typescript.js +54 -46
  27. package/dist/api/index.d.ts +8 -8
  28. package/dist/api/index.js +3 -3
  29. package/dist/cli/commands/generate/typescript.d.ts +1 -1
  30. package/dist/cli/commands/generate/typescript.js +2 -2
  31. package/dist/cli/commands/generate.d.ts +1 -1
  32. package/dist/cli/commands/generate.js +4 -4
  33. package/dist/cli/commands/index.js +3 -3
  34. package/dist/cli/commands/typeschema/generate.js +3 -3
  35. package/dist/cli/commands/typeschema.js +2 -2
  36. package/dist/cli/index.js +51 -51
  37. package/dist/cli/utils/log.d.ts +2 -2
  38. package/dist/cli/utils/log.js +2 -2
  39. package/dist/config.d.ts +2 -2
  40. package/dist/config.js +5 -5
  41. package/dist/index.d.ts +2 -2
  42. package/dist/index.js +2 -2
  43. package/dist/typeschema/cache.d.ts +7 -7
  44. package/dist/typeschema/core/binding.d.ts +1 -1
  45. package/dist/typeschema/core/binding.js +6 -4
  46. package/dist/typeschema/core/field-builder.d.ts +3 -3
  47. package/dist/typeschema/core/field-builder.js +3 -3
  48. package/dist/typeschema/core/identifier.d.ts +5 -17
  49. package/dist/typeschema/core/identifier.js +15 -47
  50. package/dist/typeschema/core/nested-types.d.ts +2 -2
  51. package/dist/typeschema/core/nested-types.js +2 -2
  52. package/dist/typeschema/core/transformer.d.ts +3 -3
  53. package/dist/typeschema/core/transformer.js +20 -28
  54. package/dist/typeschema/generator.d.ts +3 -4
  55. package/dist/typeschema/generator.js +9 -8
  56. package/dist/typeschema/index.d.ts +4 -5
  57. package/dist/typeschema/index.js +4 -4
  58. package/dist/typeschema/parser.d.ts +5 -5
  59. package/dist/typeschema/profile/processor.d.ts +2 -3
  60. package/dist/typeschema/profile/processor.js +12 -10
  61. package/dist/typeschema/types.d.ts +64 -375
  62. package/dist/typeschema/types.js +14 -2
  63. package/dist/typeschema/value-set/processor.d.ts +1 -1
  64. package/dist/typeschema/value-set/processor.js +1 -1
  65. package/package.json +1 -1
  66. package/dist/typeschema/schema.d.ts +0 -485
  67. package/dist/typeschema/schema.js +0 -456
  68. package/dist/typeschema/type-schema.types.d.ts +0 -186
  69. package/dist/typeschema/type-schema.types.js +0 -39
  70. package/dist/typeschema/utils.d.ts +0 -6
  71. package/dist/typeschema/utils.js +0 -13
@@ -1,8 +1,8 @@
1
1
  /**
2
2
  * CLI Utilities - Re-exports from main utils with spinner support
3
3
  */
4
- import { createSpinner } from "./spinner.js";
5
- export { type CodegenLogger, complete, configure, createLogger, debug, dim, error, header, info, type LogOptions, list, plain, progress, section, step, success, table, warn, } from "../../utils/codegen-logger.js";
4
+ import { createSpinner } from "./spinner";
5
+ export { type CodegenLogger, complete, configure, createLogger, debug, dim, error, header, info, type LogOptions, list, plain, progress, section, step, success, table, warn, } from "../../utils/codegen-logger";
6
6
  export { createSpinner };
7
7
  /**
8
8
  * Run a task with a spinner
@@ -1,9 +1,9 @@
1
1
  /**
2
2
  * CLI Utilities - Re-exports from main utils with spinner support
3
3
  */
4
- import { createSpinner } from "./spinner.js";
4
+ import { createSpinner } from "./spinner";
5
5
  // Re-export all logger functions from the main utils
6
- export { complete, configure, createLogger, debug, dim, error, header, info, list, plain, progress, section, step, success, table, warn, } from "../../utils/codegen-logger.js";
6
+ export { complete, configure, createLogger, debug, dim, error, header, info, list, plain, progress, section, step, success, table, warn, } from "../../utils/codegen-logger";
7
7
  // Export CLI-specific utilities
8
8
  export { createSpinner };
9
9
  /**
package/dist/config.d.ts CHANGED
@@ -22,11 +22,11 @@ export interface TypeScriptGeneratorConfig {
22
22
  /** Include helper validation functions in value set files (default: false) */
23
23
  includeValueSetHelpers?: boolean;
24
24
  /** Which binding strengths to generate value sets for (default: ['required']) */
25
- valueSetStrengths?: ('required' | 'preferred' | 'extensible' | 'example')[];
25
+ valueSetStrengths?: ("required" | "preferred" | "extensible" | "example")[];
26
26
  /** Directory name for value set files (relative to outputDir) (default: 'valuesets') */
27
27
  valueSetDirectory?: string;
28
28
  /** Value set generation mode (default: 'required-only') */
29
- valueSetMode?: 'all' | 'required-only' | 'custom';
29
+ valueSetMode?: "all" | "required-only" | "custom";
30
30
  fhirVersion?: "R4" | "R5";
31
31
  resourceTypes?: string[];
32
32
  maxDepth?: number;
package/dist/config.js CHANGED
@@ -27,9 +27,9 @@ export const DEFAULT_CONFIG = {
27
27
  includeCodeSystems: false,
28
28
  includeOperations: false,
29
29
  generateValueSets: false,
30
- valueSetDirectory: 'valuesets',
31
- valueSetMode: 'required-only',
32
- valueSetStrengths: ['required'],
30
+ valueSetDirectory: "valuesets",
31
+ valueSetMode: "required-only",
32
+ valueSetStrengths: ["required"],
33
33
  includeValueSetHelpers: false,
34
34
  fhirVersion: "R4",
35
35
  resourceTypes: [],
@@ -107,7 +107,7 @@ export const DEFAULT_CONFIG = {
107
107
  */
108
108
  export const CONFIG_FILE_NAMES = [
109
109
  "atomic-codegen.config.ts",
110
- "atomic-codegen.config.js",
110
+ "atomic-codegen.config",
111
111
  "atomic-codegen.config.json",
112
112
  ".atomic-codegenrc",
113
113
  "atomic-codegen.json",
@@ -504,7 +504,7 @@ export class ConfigLoader {
504
504
  async loadFromFile(filePath) {
505
505
  try {
506
506
  let config;
507
- if (filePath.endsWith(".ts") || filePath.endsWith(".js")) {
507
+ if (filePath.endsWith(".ts") || filePath.endsWith("")) {
508
508
  // Use dynamic import for TypeScript/JavaScript files
509
509
  const absolutePath = resolve(filePath);
510
510
  const importResult = await import(absolutePath);
package/dist/index.d.ts CHANGED
@@ -78,5 +78,5 @@
78
78
  * @author Atomic EHR Team
79
79
  * @since 0.0.1
80
80
  */
81
- export * from "./api/index.js";
82
- export * from "./config.js";
81
+ export * from "./api/index";
82
+ export * from "./config";
package/dist/index.js CHANGED
@@ -79,6 +79,6 @@
79
79
  * @since 0.0.1
80
80
  */
81
81
  // Export new high-level API (primary)
82
- export * from "./api/index.js";
82
+ export * from "./api/index";
83
83
  // Export new config system
84
- export * from "./config.js";
84
+ export * from "./config";
@@ -3,8 +3,8 @@
3
3
  *
4
4
  * Caching system for TypeSchema documents with both in-memory and persistent file-based storage.
5
5
  */
6
- import type { TypeSchemaConfig } from "../config.js";
7
- import type { TypeSchema, TypeSchemaIdentifier } from "./type-schema.types.js";
6
+ import type { TypeSchemaConfig } from "@root/config";
7
+ import type { TypeSchema, Identifier } from "@typeschema/types";
8
8
  /**
9
9
  * TypeSchema Cache with optional persistent storage
10
10
  */
@@ -20,7 +20,7 @@ export declare class TypeSchemaCache {
20
20
  /**
21
21
  * Retrieve a schema by identifier
22
22
  */
23
- get(identifier: TypeSchemaIdentifier): TypeSchema | null;
23
+ get(identifier: Identifier): TypeSchema | null;
24
24
  /**
25
25
  * Retrieve a schema by URL
26
26
  */
@@ -28,7 +28,7 @@ export declare class TypeSchemaCache {
28
28
  /**
29
29
  * Check if a schema exists in cache
30
30
  */
31
- has(identifier: TypeSchemaIdentifier): boolean;
31
+ has(identifier: Identifier): boolean;
32
32
  /**
33
33
  * Check if a schema exists by URL
34
34
  */
@@ -36,7 +36,7 @@ export declare class TypeSchemaCache {
36
36
  /**
37
37
  * Delete a schema from cache
38
38
  */
39
- delete(identifier: TypeSchemaIdentifier): boolean;
39
+ delete(identifier: Identifier): boolean;
40
40
  /**
41
41
  * Delete a schema by URL
42
42
  */
@@ -97,8 +97,8 @@ export declare function cacheSchema(schema: TypeSchema): void;
97
97
  /**
98
98
  * Get cached schema using global cache
99
99
  */
100
- export declare function getCachedSchema(identifier: TypeSchemaIdentifier): TypeSchema | null;
100
+ export declare function getCachedSchema(identifier: Identifier): TypeSchema | null;
101
101
  /**
102
102
  * Check if schema is cached using global cache
103
103
  */
104
- export declare function isCached(identifier: TypeSchemaIdentifier): boolean;
104
+ export declare function isCached(identifier: Identifier): boolean;
@@ -5,7 +5,7 @@
5
5
  */
6
6
  import type { CanonicalManager } from "@atomic-ehr/fhir-canonical-manager";
7
7
  import type { FHIRSchema, FHIRSchemaElement } from "@atomic-ehr/fhirschema";
8
- import type { PackageInfo, TypeSchemaForBinding } from "../types.js";
8
+ import type { PackageInfo, TypeSchemaForBinding } from "../types";
9
9
  /**
10
10
  * Extract concepts from a ValueSet
11
11
  */
@@ -4,8 +4,8 @@
4
4
  *
5
5
  * Functions for processing value set bindings and generating enums
6
6
  */
7
- import { buildFieldType } from "./field-builder.js";
8
- import { buildBindingIdentifier, buildValueSetIdentifier, dropVersionFromUrl, } from "./identifier.js";
7
+ import { buildFieldType } from "./field-builder";
8
+ import { buildBindingIdentifier, buildValueSetIdentifier, dropVersionFromUrl, } from "./identifier";
9
9
  /**
10
10
  * Extract concepts from a ValueSet
11
11
  */
@@ -86,8 +86,10 @@ export async function buildEnum(element, manager) {
86
86
  // 3. Preferred bindings on code types (for common usage patterns)
87
87
  // 4. Extensible bindings on Coding types (broader coverage)
88
88
  const shouldGenerateEnum = strength === "required" ||
89
- (strength === "extensible" && (element.type === "code" || element.type === "Coding")) ||
90
- (strength === "preferred" && (element.type === "code" || element.type === "Coding"));
89
+ (strength === "extensible" &&
90
+ (element.type === "code" || element.type === "Coding")) ||
91
+ (strength === "preferred" &&
92
+ (element.type === "code" || element.type === "Coding"));
91
93
  if (!shouldGenerateEnum) {
92
94
  return undefined;
93
95
  }
@@ -5,7 +5,7 @@
5
5
  */
6
6
  import type { CanonicalManager } from "@atomic-ehr/fhir-canonical-manager";
7
7
  import type { FHIRSchema, FHIRSchemaElement } from "@atomic-ehr/fhirschema";
8
- import type { PackageInfo, TypeSchemaField, TypeSchemaIdentifier } from "../types.js";
8
+ import type { PackageInfo, TypeSchemaField, Identifier } from "../types";
9
9
  /**
10
10
  * Get the full element hierarchy for a given path
11
11
  */
@@ -25,11 +25,11 @@ export declare function isExcluded(fhirSchema: FHIRSchema, path: string[], _mana
25
25
  /**
26
26
  * Build reference array from element refers
27
27
  */
28
- export declare function buildReferences(element: FHIRSchemaElement, manager: ReturnType<typeof CanonicalManager>, packageInfo?: PackageInfo): Promise<TypeSchemaIdentifier[] | undefined>;
28
+ export declare function buildReferences(element: FHIRSchemaElement, manager: ReturnType<typeof CanonicalManager>, packageInfo?: PackageInfo): Promise<Identifier[] | undefined>;
29
29
  /**
30
30
  * Build field type identifier
31
31
  */
32
- export declare function buildFieldType(fhirSchema: FHIRSchema, _path: string[], element: FHIRSchemaElement, _manager: ReturnType<typeof CanonicalManager>, packageInfo?: PackageInfo): TypeSchemaIdentifier | undefined;
32
+ export declare function buildFieldType(fhirSchema: FHIRSchema, _path: string[], element: FHIRSchemaElement, _manager: ReturnType<typeof CanonicalManager>, packageInfo?: PackageInfo): Identifier | undefined;
33
33
  /**
34
34
  * Build a TypeSchema field from a FHIRSchema element
35
35
  */
@@ -1,6 +1,6 @@
1
1
  // @ts-nocheck
2
- import { buildEnum } from "./binding.js";
3
- import { buildBindingIdentifier, buildNestedIdentifier, buildSchemaIdentifier, } from "./identifier.js";
2
+ import { buildEnum } from "./binding";
3
+ import { buildBindingIdentifier, buildNestedIdentifier, buildSchemaIdentifier, } from "./identifier";
4
4
  /**
5
5
  * Get the full element hierarchy for a given path
6
6
  */
@@ -134,7 +134,7 @@ export async function buildReferences(element, manager, packageInfo) {
134
134
  try {
135
135
  const resource = await manager.resolve(ref);
136
136
  if (resource) {
137
- references.push(buildSchemaIdentifier(resource, packageInfo));
137
+ references.push(buildSchemaIdentifier(resource));
138
138
  }
139
139
  }
140
140
  catch { }
@@ -4,24 +4,12 @@
4
4
  * Functions for creating TypeSchema identifiers from FHIRSchema entities
5
5
  */
6
6
  import type { FHIRSchema } from "@atomic-ehr/fhirschema";
7
- import type { PackageInfo, TypeSchemaForValueSet, TypeSchemaIdentifier } from "../types";
8
- /**
9
- * Drop version suffix from canonical URL (e.g., "http://example.com|1.0.0" -> "http://example.com")
10
- */
7
+ import type { PackageInfo, TypeSchemaForValueSet, Identifier, RichFHIRSchema } from "../types";
11
8
  export declare function dropVersionFromUrl(url: string | undefined): string | undefined;
12
- /**
13
- * Build identifier for primitive-type, complex-type, resource, or constraint
14
- */
15
- export declare function buildSchemaIdentifier(fhirSchema: FHIRSchema, packageInfo?: PackageInfo): TypeSchemaIdentifier;
16
- /**
17
- * Build nested type identifier for BackboneElements
18
- */
19
- export declare function buildNestedIdentifier(fhirSchema: FHIRSchema, path: string[], packageInfo?: PackageInfo): TypeSchemaIdentifier;
20
- /**
21
- * Build value set identifier
22
- */
23
- export declare function buildValueSetIdentifier(valueSetUrl: string, valueSet?: any, packageInfo?: PackageInfo): TypeSchemaForValueSet["identifier"];
9
+ export declare function buildSchemaIdentifier(fhirSchema: RichFHIRSchema): Identifier;
10
+ export declare function buildNestedIdentifier(fhirSchema: FHIRSchema, path: string[], packageInfo?: PackageInfo): Identifier;
11
+ export declare function buildValueSetIdentifier(valueSetUrl: string, valueSet: any, packageInfo?: PackageInfo): TypeSchemaForValueSet["identifier"];
24
12
  /**
25
13
  * Build binding identifier for an element with value set binding
26
14
  */
27
- export declare function buildBindingIdentifier(fhirSchema: FHIRSchema, path: string[], bindingName?: string, packageInfo?: PackageInfo): TypeSchemaIdentifier;
15
+ export declare function buildBindingIdentifier(fhirSchema: FHIRSchema, path: string[], bindingName?: string, packageInfo?: PackageInfo): Identifier;
@@ -3,73 +3,41 @@
3
3
  *
4
4
  * Functions for creating TypeSchema identifiers from FHIRSchema entities
5
5
  */
6
- /**
7
- * Drop version suffix from canonical URL (e.g., "http://example.com|1.0.0" -> "http://example.com")
8
- */
9
6
  export function dropVersionFromUrl(url) {
10
7
  if (!url)
11
8
  return undefined;
12
9
  return url.split("|")[0];
13
10
  }
14
- /**
15
- * Determine the kind of schema based on FHIRSchema properties
16
- */
17
11
  function determineKind(fhirSchema) {
18
- // Check for constraint/profile
19
- if (fhirSchema.derivation === "constraint") {
20
- // Distinguish between profiles and other constraints
21
- // Profiles typically constrain resources or complex types and have a base type
22
- if (fhirSchema.base &&
23
- (fhirSchema.type === "Resource" ||
24
- fhirSchema.kind === "resource" ||
25
- fhirSchema.kind === "complex-type")) {
26
- return "profile";
27
- }
12
+ if (fhirSchema.derivation === "constraint")
28
13
  return "profile";
29
- }
30
- // Use explicit kind if available
31
- if (fhirSchema.kind) {
32
- switch (fhirSchema.kind) {
33
- case "primitive-type":
34
- return "primitive-type";
35
- case "complex-type":
36
- return "complex-type";
37
- case "resource":
38
- return "resource";
39
- }
40
- }
41
- // Default to resource
14
+ if (fhirSchema.kind === "primitive-type")
15
+ return "primitive-type";
16
+ if (fhirSchema.kind === "complex-type")
17
+ return "complex-type";
18
+ if (fhirSchema.kind === "resource")
19
+ return "resource";
42
20
  return "resource";
43
21
  }
44
- /**
45
- * Build identifier for primitive-type, complex-type, resource, or constraint
46
- */
47
- export function buildSchemaIdentifier(fhirSchema, packageInfo) {
48
- const kind = determineKind(fhirSchema);
22
+ export function buildSchemaIdentifier(fhirSchema) {
49
23
  return {
50
- kind,
51
- package: packageInfo?.name || fhirSchema.package_name || "undefined",
52
- version: packageInfo?.version || fhirSchema.package_version || "undefined",
24
+ kind: determineKind(fhirSchema),
25
+ package: fhirSchema.package_meta.name,
26
+ version: fhirSchema.package_meta.version,
53
27
  name: fhirSchema.name,
54
28
  url: fhirSchema.url,
55
29
  };
56
30
  }
57
- /**
58
- * Build nested type identifier for BackboneElements
59
- */
60
31
  export function buildNestedIdentifier(fhirSchema, path, packageInfo) {
61
32
  const nestedName = path.join(".");
62
33
  return {
63
34
  kind: "nested",
64
- package: packageInfo?.name || fhirSchema.package_name || "undefined",
65
- version: packageInfo?.version || fhirSchema.package_version || "undefined",
35
+ package: packageInfo?.name || fhirSchema.package_meta.name || "undefined",
36
+ version: packageInfo?.version || fhirSchema.package_meta.version || "undefined",
66
37
  name: nestedName,
67
38
  url: `${fhirSchema.url}#${nestedName}`,
68
39
  };
69
40
  }
70
- /**
71
- * Build value set identifier
72
- */
73
41
  export function buildValueSetIdentifier(valueSetUrl, valueSet, packageInfo) {
74
42
  const cleanUrl = dropVersionFromUrl(valueSetUrl) || valueSetUrl;
75
43
  // Generate a meaningful name from the URL instead of using potentially hash-like IDs
@@ -107,8 +75,8 @@ export function buildBindingIdentifier(fhirSchema, path, bindingName, packageInf
107
75
  const name = bindingName || `${fhirSchema.name}.${pathStr}_binding`;
108
76
  return {
109
77
  kind: "binding",
110
- package: packageInfo?.name || fhirSchema.package_name || "undefined",
111
- version: packageInfo?.version || fhirSchema.package_version || "undefined",
78
+ package: packageInfo?.name || fhirSchema.package_meta.name || "undefined",
79
+ version: packageInfo?.version || fhirSchema.package_meta.version || "undefined",
112
80
  name,
113
81
  url: bindingName
114
82
  ? `urn:fhir:binding:${name}`
@@ -5,7 +5,7 @@
5
5
  */
6
6
  import type { CanonicalManager } from "@atomic-ehr/fhir-canonical-manager";
7
7
  import type { FHIRSchema, FHIRSchemaElement } from "@atomic-ehr/fhirschema";
8
- import type { PackageInfo, TypeSchemaField, TypeSchemaIdentifier } from "../types.js";
8
+ import type { PackageInfo, TypeSchemaField, Identifier } from "../types";
9
9
  /**
10
10
  * Collect all nested elements from a FHIRSchema
11
11
  */
@@ -21,4 +21,4 @@ export declare function buildNestedTypes(fhirSchema: FHIRSchema, manager: Return
21
21
  /**
22
22
  * Extract dependencies from nested types
23
23
  */
24
- export declare function extractNestedDependencies(nestedTypes: TypeSchemaNestedType[]): TypeSchemaIdentifier[];
24
+ export declare function extractNestedDependencies(nestedTypes: TypeSchemaNestedType[]): Identifier[];
@@ -1,6 +1,6 @@
1
1
  // @ts-nocheck
2
- import { buildField, buildNestedField, isNestedElement, } from "./field-builder.js";
3
- import { buildNestedIdentifier } from "./identifier.js";
2
+ import { buildField, buildNestedField, isNestedElement } from "./field-builder";
3
+ import { buildNestedIdentifier } from "./identifier";
4
4
  /**
5
5
  * Collect all nested elements from a FHIRSchema
6
6
  */
@@ -5,8 +5,8 @@
5
5
  */
6
6
  import type { CanonicalManager } from "@atomic-ehr/fhir-canonical-manager";
7
7
  import type { FHIRSchema, FHIRSchemaElement } from "@atomic-ehr/fhirschema";
8
- import type { TypeSchema, TypeSchemaField } from "../type-schema.types.js";
9
- import type { PackageInfo } from "../types.js";
8
+ import type { TypeSchema, TypeSchemaField, RichFHIRSchema } from "@typeschema/types";
9
+ import type { PackageInfo } from "../types";
10
10
  /**
11
11
  * Transform elements into fields
12
12
  */
@@ -15,4 +15,4 @@ export declare function transformElements(fhirSchema: FHIRSchema, parentPath: st
15
15
  * Transform a single FHIRSchema to TypeSchema(s) with enhanced categorization
16
16
  * Returns the main schema plus any binding schemas
17
17
  */
18
- export declare function transformFHIRSchema(manager: ReturnType<typeof CanonicalManager>, fhirSchema: FHIRSchema, packageInfo?: PackageInfo): Promise<TypeSchema[]>;
18
+ export declare function transformFHIRSchema(manager: ReturnType<typeof CanonicalManager>, fhirSchema: RichFHIRSchema): Promise<TypeSchema[]>;
@@ -1,9 +1,9 @@
1
1
  // @ts-nocheck
2
- import { transformProfile } from "../profile/processor.js";
3
- import { collectBindingSchemas } from "./binding.js";
4
- import { buildField, buildNestedField, getElementHierarchy, isNestedElement, mergeElementHierarchy, } from "./field-builder.js";
5
- import { buildSchemaIdentifier } from "./identifier.js";
6
- import { buildNestedTypes, extractNestedDependencies } from "./nested-types.js";
2
+ import { transformProfile } from "../profile/processor";
3
+ import { collectBindingSchemas } from "./binding";
4
+ import { buildField, buildNestedField, getElementHierarchy, isNestedElement, mergeElementHierarchy, } from "./field-builder";
5
+ import { buildSchemaIdentifier } from "./identifier";
6
+ import { buildNestedTypes, extractNestedDependencies } from "./nested-types";
7
7
  /**
8
8
  * Transform elements into fields
9
9
  */
@@ -86,7 +86,7 @@ function isExtensionSchema(fhirSchema, _identifier) {
86
86
  */
87
87
  async function transformValueSet(fhirSchema, _manager, packageInfo) {
88
88
  try {
89
- const identifier = buildSchemaIdentifier(fhirSchema, packageInfo);
89
+ const identifier = buildSchemaIdentifier(fhirSchema);
90
90
  identifier.kind = "value-set"; // Ensure correct kind
91
91
  const valueSetSchema = {
92
92
  identifier,
@@ -123,7 +123,7 @@ async function transformValueSet(fhirSchema, _manager, packageInfo) {
123
123
  */
124
124
  async function transformExtension(fhirSchema, manager, packageInfo) {
125
125
  try {
126
- const identifier = buildSchemaIdentifier(fhirSchema, packageInfo);
126
+ const identifier = buildSchemaIdentifier(fhirSchema);
127
127
  // Build base identifier if present
128
128
  let base;
129
129
  if (fhirSchema.base && fhirSchema.base !== "Extension") {
@@ -133,8 +133,8 @@ async function transformExtension(fhirSchema, manager, packageInfo) {
133
133
  const baseName = fhirSchema.base.split("/").pop() || fhirSchema.base;
134
134
  base = {
135
135
  kind: "complex-type",
136
- package: packageInfo?.name || "hl7.fhir.r4.core",
137
- version: packageInfo?.version || "4.0.1",
136
+ package: "hl7.fhir.r4.core",
137
+ version: "4.0.1",
138
138
  name: baseName,
139
139
  url: baseUrl,
140
140
  };
@@ -191,29 +191,21 @@ async function transformExtension(fhirSchema, manager, packageInfo) {
191
191
  * Transform a single FHIRSchema to TypeSchema(s) with enhanced categorization
192
192
  * Returns the main schema plus any binding schemas
193
193
  */
194
- export async function transformFHIRSchema(manager, fhirSchema, packageInfo) {
194
+ export async function transformFHIRSchema(manager, fhirSchema) {
195
195
  const results = [];
196
- // Extract package info from schema if not provided
197
- if (!packageInfo && (fhirSchema.package_name || fhirSchema.package_id)) {
198
- packageInfo = {
199
- name: fhirSchema.package_name || fhirSchema.package_id || "undefined",
200
- version: fhirSchema.package_version || "undefined",
201
- };
202
- }
203
- // Build main identifier with enhanced categorization
204
- const identifier = buildSchemaIdentifier(fhirSchema, packageInfo);
196
+ const identifier = buildSchemaIdentifier(fhirSchema);
205
197
  // Handle profiles with specialized processor
206
198
  if (identifier.kind === "profile") {
207
- const profileSchema = await transformProfile(fhirSchema, manager, packageInfo);
199
+ const profileSchema = await transformProfile(fhirSchema, manager, fhirSchema.package_meta);
208
200
  results.push(profileSchema);
209
201
  // Collect binding schemas for profiles too
210
- const bindingSchemas = await collectBindingSchemas(fhirSchema, manager, packageInfo);
202
+ const bindingSchemas = await collectBindingSchemas(fhirSchema, manager, fhirSchema.package_meta);
211
203
  results.push(...bindingSchemas);
212
204
  return results;
213
205
  }
214
206
  // Handle value sets specially
215
207
  if (identifier.kind === "value-set" || fhirSchema.kind === "value-set") {
216
- const valueSetSchema = await transformValueSet(fhirSchema, manager, packageInfo);
208
+ const valueSetSchema = await transformValueSet(fhirSchema, manager, fhirSchema.package_meta);
217
209
  if (valueSetSchema) {
218
210
  results.push(valueSetSchema);
219
211
  }
@@ -221,7 +213,7 @@ export async function transformFHIRSchema(manager, fhirSchema, packageInfo) {
221
213
  }
222
214
  // Handle extensions specially
223
215
  if (isExtensionSchema(fhirSchema, identifier)) {
224
- const extensionSchema = await transformExtension(fhirSchema, manager, packageInfo);
216
+ const extensionSchema = await transformExtension(fhirSchema, manager, fhirSchema.package_meta);
225
217
  if (extensionSchema) {
226
218
  results.push(extensionSchema);
227
219
  }
@@ -279,10 +271,10 @@ export async function transformFHIRSchema(manager, fhirSchema, packageInfo) {
279
271
  kind: kind,
280
272
  package: isStandardFhir
281
273
  ? "hl7.fhir.r4.core"
282
- : packageInfo?.name || fhirSchema.package_name || "undefined",
274
+ : fhirSchema.package_meta.name || "undefined",
283
275
  version: isStandardFhir
284
276
  ? "4.0.1"
285
- : packageInfo?.version || fhirSchema.package_version || "undefined",
277
+ : fhirSchema.package_meta.version || "undefined",
286
278
  name: baseName,
287
279
  url: baseUrl,
288
280
  };
@@ -305,14 +297,14 @@ export async function transformFHIRSchema(manager, fhirSchema, packageInfo) {
305
297
  }
306
298
  // Transform elements into fields (for non-primitive types)
307
299
  if (fhirSchema.kind !== "primitive-type" && fhirSchema.elements) {
308
- const fields = await transformElements(fhirSchema, [], fhirSchema.elements, manager, packageInfo);
300
+ const fields = await transformElements(fhirSchema, [], fhirSchema.elements, manager, fhirSchema.package_meta);
309
301
  if (Object.keys(fields).length > 0) {
310
302
  mainSchema.fields = fields;
311
303
  }
312
304
  // Extract field dependencies (types and bindings)
313
305
  allDependencies.push(...extractFieldDependencies(fields));
314
306
  // Build nested types
315
- const nestedTypes = await buildNestedTypes(fhirSchema, manager, packageInfo);
307
+ const nestedTypes = await buildNestedTypes(fhirSchema, manager, fhirSchema.package_meta);
316
308
  if (nestedTypes.length > 0) {
317
309
  mainSchema.nested = nestedTypes;
318
310
  // Add nested type dependencies
@@ -328,7 +320,7 @@ export async function transformFHIRSchema(manager, fhirSchema, packageInfo) {
328
320
  // Add main schema to results
329
321
  results.push(mainSchema);
330
322
  // Collect and add binding schemas
331
- const bindingSchemas = await collectBindingSchemas(fhirSchema, manager, packageInfo);
323
+ const bindingSchemas = await collectBindingSchemas(fhirSchema, manager, fhirSchema.package_meta);
332
324
  results.push(...bindingSchemas);
333
325
  return results;
334
326
  }
@@ -5,9 +5,8 @@
5
5
  * Provides high-level API for converting FHIR Structure Definitions to TypeSchema format.
6
6
  */
7
7
  import { type FHIRSchema, type StructureDefinition } from "@atomic-ehr/fhirschema";
8
- import type { TypeSchemaConfig } from "../config.js";
9
- import type { TypeSchema } from "./type-schema.types.js";
10
- import type { PackageInfo, TypeschemaGeneratorOptions } from "./types.js";
8
+ import type { TypeSchemaConfig } from "@root/config";
9
+ import type { PackageInfo, RichFHIRSchema, TypeSchema, TypeschemaGeneratorOptions } from "./types";
11
10
  /**
12
11
  * TypeSchema Generator class
13
12
  *
@@ -29,7 +28,7 @@ export declare class TypeSchemaGenerator {
29
28
  generateFhirSchemas(structureDefinitions: StructureDefinition[]): FHIRSchema[];
30
29
  generateValueSetSchemas(valueSets: any[], packageInfo: PackageInfo): Promise<TypeSchema[]>;
31
30
  generateFromPackage(packageName: string, packageVersion?: string): Promise<TypeSchema[]>;
32
- generateResourceTypeSchemas(fhirSchemas: FHIRSchema[], packageInfo: PackageInfo): Promise<TypeSchema[]>;
31
+ generateResourceTypeSchemas(fhirSchemas: RichFHIRSchema[]): Promise<TypeSchema[]>;
33
32
  /**
34
33
  * Apply treeshaking to StructureDefinitions before FHIR schema transformation
35
34
  * This is more efficient and includes smart reference handling
@@ -6,10 +6,11 @@
6
6
  */
7
7
  import { CanonicalManager } from "@atomic-ehr/fhir-canonical-manager";
8
8
  import * as fhirschema from "@atomic-ehr/fhirschema";
9
- import { createLogger } from "../utils/codegen-logger.js";
10
- import { TypeSchemaCache } from "./cache.js";
11
- import { transformFHIRSchema } from "./core/transformer.js";
12
- import { transformValueSet } from "./value-set/processor.js";
9
+ import { createLogger } from "@root/utils/codegen-logger";
10
+ import { TypeSchemaCache } from "./cache";
11
+ import { transformFHIRSchema } from "./core/transformer";
12
+ import { enrichFHIRSchema } from "./types";
13
+ import { transformValueSet } from "./value-set/processor";
13
14
  /**
14
15
  * TypeSchema Generator class
15
16
  *
@@ -116,9 +117,9 @@ export class TypeSchemaGenerator {
116
117
  version: packageVersion || "latest",
117
118
  };
118
119
  const { valueSets, structureDefinitions } = await this.fetchPackage(packageName, packageVersion);
119
- const fhirSchemas = this.generateFhirSchemas(structureDefinitions);
120
+ const fhirSchemas = this.generateFhirSchemas(structureDefinitions).map(enrichFHIRSchema);
120
121
  const valueSetSchemas = await this.generateValueSetSchemas(valueSets, packageInfo);
121
- const schemas = await this.generateResourceTypeSchemas(fhirSchemas, packageInfo);
122
+ const schemas = await this.generateResourceTypeSchemas(fhirSchemas);
122
123
  const allSchemas = [...schemas, ...valueSetSchemas];
123
124
  if (this.cache) {
124
125
  for (const schema of allSchemas) {
@@ -127,11 +128,11 @@ export class TypeSchemaGenerator {
127
128
  }
128
129
  return allSchemas;
129
130
  }
130
- async generateResourceTypeSchemas(fhirSchemas, packageInfo) {
131
+ async generateResourceTypeSchemas(fhirSchemas) {
131
132
  this.logger.info(`Transforming ${fhirSchemas.length} FHIR schemas to Type Schema`);
132
133
  const typeSchemas = [];
133
134
  for (const fhirSchema of fhirSchemas) {
134
- typeSchemas.push(...(await transformFHIRSchema(this.manager, fhirSchema, packageInfo)));
135
+ typeSchemas.push(...(await transformFHIRSchema(this.manager, fhirSchema)));
135
136
  }
136
137
  return typeSchemas;
137
138
  }
@@ -9,8 +9,7 @@
9
9
  * - Reading TypeSchema documents
10
10
  * - Validating TypeSchema documents
11
11
  */
12
- export type { FHIRSchema } from "@atomic-ehr/fhirschema";
13
- export { TypeSchemaCache } from "./cache.js";
14
- export { TypeSchemaGenerator } from "./generator.js";
15
- export { TypeSchemaParser } from "./parser.js";
16
- export * from "./type-schema.types.js";
12
+ export { TypeSchemaCache } from "./cache";
13
+ export { TypeSchemaGenerator } from "./generator";
14
+ export { TypeSchemaParser } from "./parser";
15
+ export type { Identifier, TypeSchema } from "./types";
@@ -9,7 +9,7 @@
9
9
  * - Reading TypeSchema documents
10
10
  * - Validating TypeSchema documents
11
11
  */
12
- export { TypeSchemaCache } from "./cache.js";
13
- export { TypeSchemaGenerator } from "./generator.js";
14
- export { TypeSchemaParser } from "./parser.js";
15
- export * from "./type-schema.types.js";
12
+ // Re-export core dependencies
13
+ export { TypeSchemaCache } from "./cache";
14
+ export { TypeSchemaGenerator } from "./generator";
15
+ export { TypeSchemaParser } from "./parser";
@@ -1,5 +1,5 @@
1
- import type { TypeSchema, TypeSchemaIdentifier } from "./type-schema.types.js";
2
- import type { TypeschemaParserOptions } from "./types.js";
1
+ import type { TypeSchema, Identifier } from "@typeschema/types";
2
+ import type { TypeschemaParserOptions } from "./types";
3
3
  /**
4
4
  * TypeSchema Parser class
5
5
  *
@@ -28,7 +28,7 @@ export declare class TypeSchemaParser {
28
28
  /**
29
29
  * Find schemas by identifier
30
30
  */
31
- findByIdentifier(schemas: TypeSchema[], identifier: Partial<TypeSchemaIdentifier>): TypeSchema[];
31
+ findByIdentifier(schemas: TypeSchema[], identifier: Partial<Identifier>): TypeSchema[];
32
32
  /**
33
33
  * Find schema by URL
34
34
  */
@@ -36,7 +36,7 @@ export declare class TypeSchemaParser {
36
36
  /**
37
37
  * Find schemas by kind
38
38
  */
39
- findByKind(schemas: TypeSchema[], kind: TypeSchemaIdentifier["kind"]): TypeSchema[];
39
+ findByKind(schemas: TypeSchema[], kind: Identifier["kind"]): TypeSchema[];
40
40
  /**
41
41
  * Find schemas by package
42
42
  */
@@ -44,7 +44,7 @@ export declare class TypeSchemaParser {
44
44
  /**
45
45
  * Get all dependencies from a schema
46
46
  */
47
- getDependencies(schema: TypeSchema): TypeSchemaIdentifier[];
47
+ getDependencies(schema: TypeSchema): Identifier[];
48
48
  /**
49
49
  * Resolve schema dependencies
50
50
  */