@atomic-ehr/codegen 0.0.1-canary.20250927094522.7f26cfe → 0.0.1-canary.20250930075344.1c0b689

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 (45) hide show
  1. package/dist/api/builder.d.ts +2 -2
  2. package/dist/api/builder.js +1 -1
  3. package/dist/api/generators/base/BaseGenerator.js +5 -12
  4. package/dist/api/generators/base/FileManager.js +1 -3
  5. package/dist/api/generators/base/TemplateEngine.js +2 -2
  6. package/dist/api/generators/base/TypeScriptTypeMapper.js +1 -1
  7. package/dist/api/generators/base/builders/FileBuilder.js +6 -8
  8. package/dist/api/generators/base/errors.js +1 -3
  9. package/dist/api/generators/base/index.d.ts +1 -1
  10. package/dist/api/generators/base/index.js +1 -2
  11. package/dist/api/generators/base/types.d.ts +1 -1
  12. package/dist/api/generators/typescript.d.ts +1 -3
  13. package/dist/api/generators/typescript.js +13 -38
  14. package/dist/api/index.d.ts +1 -2
  15. package/dist/cli/commands/typeschema/generate.js +4 -10
  16. package/dist/cli/commands/typeschema.js +1 -2
  17. package/dist/cli/index.js +54 -54
  18. package/dist/cli/utils/spinner.js +2 -6
  19. package/dist/config.js +4 -16
  20. package/dist/logger.js +4 -13
  21. package/dist/typeschema/cache.d.ts +1 -1
  22. package/dist/typeschema/core/binding.d.ts +4 -7
  23. package/dist/typeschema/core/binding.js +16 -30
  24. package/dist/typeschema/core/field-builder.d.ts +6 -14
  25. package/dist/typeschema/core/field-builder.js +42 -88
  26. package/dist/typeschema/core/identifier.d.ts +5 -8
  27. package/dist/typeschema/core/identifier.js +8 -15
  28. package/dist/typeschema/core/nested-types.d.ts +4 -7
  29. package/dist/typeschema/core/nested-types.js +15 -14
  30. package/dist/typeschema/core/transformer.d.ts +6 -13
  31. package/dist/typeschema/core/transformer.js +74 -144
  32. package/dist/typeschema/generator.d.ts +5 -8
  33. package/dist/typeschema/generator.js +26 -24
  34. package/dist/typeschema/parser.d.ts +7 -8
  35. package/dist/typeschema/parser.js +67 -82
  36. package/dist/typeschema/profile/processor.d.ts +3 -2
  37. package/dist/typeschema/profile/processor.js +13 -23
  38. package/dist/typeschema/register.d.ts +16 -0
  39. package/dist/typeschema/register.js +65 -0
  40. package/dist/typeschema/types.d.ts +32 -21
  41. package/dist/typeschema/types.js +5 -5
  42. package/dist/typeschema/value-set/processor.d.ts +2 -2
  43. package/dist/typeschema/value-set/processor.js +3 -3
  44. package/dist/utils/codegen-logger.js +4 -12
  45. package/package.json +2 -2
@@ -1,4 +1,3 @@
1
- // @ts-nocheck
2
1
  /**
3
2
  * TypeSchema Parser
4
3
  *
@@ -27,9 +26,7 @@ export class TypeSchemaParser {
27
26
  */
28
27
  async parseFromFile(filePath) {
29
28
  const content = await readFile(filePath, "utf-8");
30
- const format = this.options.format === "auto"
31
- ? this.detectFormat(content, filePath)
32
- : this.options.format;
29
+ const format = this.options.format === "auto" ? this.detectFormat(content, filePath) : this.options.format;
33
30
  return this.parseFromString(content, format);
34
31
  }
35
32
  /**
@@ -102,73 +99,75 @@ export class TypeSchemaParser {
102
99
  /**
103
100
  * Get all dependencies from a schema
104
101
  */
105
- getDependencies(schema) {
106
- const dependencies = [];
107
- // Add base dependency
108
- if ("base" in schema && schema.base) {
109
- dependencies.push(schema.base);
110
- }
111
- // Add explicit dependencies
112
- if ("dependencies" in schema && schema.dependencies) {
113
- dependencies.push(...schema.dependencies);
114
- }
115
- // Add field type dependencies
116
- if ("fields" in schema && schema.fields) {
117
- for (const field of Object.values(schema.fields)) {
118
- if ("type" in field && field.type) {
119
- dependencies.push(field.type);
120
- }
121
- if ("binding" in field && field.binding) {
122
- dependencies.push(field.binding);
123
- }
124
- if ("reference" in field && field.reference) {
125
- dependencies.push(...field.reference);
126
- }
127
- }
128
- }
129
- // Add nested type dependencies
130
- if ("nested" in schema && schema.nested) {
131
- for (const nested of schema.nested) {
132
- dependencies.push(nested.identifier);
133
- dependencies.push(nested.base);
134
- for (const field of Object.values(nested.fields)) {
135
- if ("type" in field && field.type) {
136
- dependencies.push(field.type);
137
- }
138
- if ("binding" in field && field.binding) {
139
- dependencies.push(field.binding);
140
- }
141
- if ("reference" in field && field.reference) {
142
- dependencies.push(...field.reference);
143
- }
144
- }
145
- }
146
- }
147
- // Add binding dependencies
148
- if ("valueset" in schema) {
149
- const bindingSchema = schema;
150
- dependencies.push(bindingSchema.valueset);
151
- if (bindingSchema.type) {
152
- dependencies.push(bindingSchema.type);
153
- }
154
- }
155
- // Remove duplicates
156
- return this.deduplicateDependencies(dependencies);
157
- }
102
+ // getDependencies(schema: TypeSchema): Identifier[] {
103
+ // const dependencies: Identifier[] = [];
104
+ // // Add base dependency
105
+ // if ("base" in schema && schema.base) {
106
+ // dependencies.push(schema.base);
107
+ // }
108
+ // // Add explicit dependencies
109
+ // if ("dependencies" in schema && schema.dependencies) {
110
+ // dependencies.push(...schema.dependencies);
111
+ // }
112
+ // // Add field type dependencies
113
+ // if ("fields" in schema && schema.fields) {
114
+ // for (const field of Object.values(schema.fields)) {
115
+ // if ("type" in field && field.type) {
116
+ // dependencies.push(field.type);
117
+ // }
118
+ // if ("binding" in field && field.binding) {
119
+ // dependencies.push(field.binding);
120
+ // }
121
+ // if ("reference" in field && field.reference) {
122
+ // dependencies.push(...field.reference);
123
+ // }
124
+ // }
125
+ // }
126
+ // if ("nested" in schema && schema.nested) {
127
+ // for (const nested of schema.nested) {
128
+ // dependencies.push(nested.identifier);
129
+ // dependencies.push(nested.base);
130
+ // for (const field of Object.values(nested.fields)) {
131
+ // if ("type" in field && field.type) {
132
+ // dependencies.push(field.type);
133
+ // }
134
+ // if ("binding" in field && field.binding) {
135
+ // dependencies.push(field.binding);
136
+ // }
137
+ // if ("reference" in field && field.reference) {
138
+ // dependencies.push(...field.reference);
139
+ // }
140
+ // }
141
+ // }
142
+ // }
143
+ // // Add binding dependencies
144
+ // if ("valueset" in schema) {
145
+ // const bindingSchema = schema as any;
146
+ // dependencies.push(bindingSchema.valueset);
147
+ // if (bindingSchema.type) {
148
+ // dependencies.push(bindingSchema.type);
149
+ // }
150
+ // }
151
+ // // Remove duplicates
152
+ // return this.deduplicateDependencies(dependencies);
153
+ // }
158
154
  /**
159
155
  * Resolve schema dependencies
160
156
  */
161
- resolveDependencies(schemas, targetSchema) {
162
- const dependencies = this.getDependencies(targetSchema);
163
- const resolved = [];
164
- for (const dep of dependencies) {
165
- const depSchema = this.findByUrl(schemas, dep.url);
166
- if (depSchema) {
167
- resolved.push(depSchema);
168
- }
169
- }
170
- return resolved;
171
- }
157
+ // resolveDependencies(
158
+ // schemas: TypeSchema[],
159
+ // targetSchema: TypeSchema,
160
+ // ): TypeSchema[] {
161
+ // const dependencies = this.getDependencies(targetSchema);
162
+ // const resolved: TypeSchema[] = [];
163
+ // for (const dep of dependencies) {
164
+ // const depSchema = this.findByUrl(schemas, dep.url);
165
+ // if (depSchema) {
166
+ // resolved.push(depSchema);
167
+ // }
168
+ // }
169
+ // return resolved;
170
+ // }
172
171
  /**
173
172
  * Detect format from content or filename
174
173
  */
@@ -272,20 +271,6 @@ export class TypeSchemaParser {
272
271
  (!criteria.name || identifier.name === criteria.name) &&
273
272
  (!criteria.url || identifier.url === criteria.url));
274
273
  }
275
- /**
276
- * Remove duplicate dependencies
277
- */
278
- deduplicateDependencies(deps) {
279
- const seen = new Set();
280
- const unique = [];
281
- for (const dep of deps) {
282
- if (!seen.has(dep.url)) {
283
- seen.add(dep.url);
284
- unique.push(dep);
285
- }
286
- }
287
- return unique.sort((a, b) => a.name.localeCompare(b.name));
288
- }
289
274
  }
290
275
  /**
291
276
  * Convenience function to parse TypeSchema from file
@@ -4,10 +4,11 @@
4
4
  * Handles transformation of FHIR profiles to TypeSchema format
5
5
  * This file is deprecated as profiles are not part of the core TypeSchema specification
6
6
  */
7
- import type { CanonicalManager } from "@atomic-ehr/fhir-canonical-manager";
7
+ import type { Register } from "@root/typeschema/register";
8
+ import type { RichFHIRSchema } from "@typeschema/types";
8
9
  import type { TypeSchemaForProfile } from "../types";
9
10
  /**
10
11
  * Transform a FHIR profile to TypeSchema format
11
12
  * Profiles are treated as specialized resources that extend base resources
12
13
  */
13
- export declare function transformProfile(fhirSchema: RichFHIRSchema, manager: ReturnType<typeof CanonicalManager>): Promise<TypeSchemaForProfile>;
14
+ export declare function transformProfile(fhirSchema: RichFHIRSchema, register: Register): Promise<TypeSchemaForProfile>;
@@ -1,19 +1,18 @@
1
- // @ts-nocheck
2
1
  /**
3
2
  * Profile Processor (DEPRECATED - Profiles not in core TypeSchema spec)
4
3
  *
5
4
  * Handles transformation of FHIR profiles to TypeSchema format
6
5
  * This file is deprecated as profiles are not part of the core TypeSchema specification
7
6
  */
8
- import { buildSchemaIdentifier } from "../core/identifier";
7
+ import { mkIdentifier } from "../core/identifier";
9
8
  import { transformElements } from "../core/transformer";
10
9
  /**
11
10
  * Transform a FHIR profile to TypeSchema format
12
11
  * Profiles are treated as specialized resources that extend base resources
13
12
  */
14
- export async function transformProfile(fhirSchema, manager) {
13
+ export async function transformProfile(fhirSchema, register) {
15
14
  // Build profile identifier
16
- const identifier = buildSchemaIdentifier(fhirSchema);
15
+ const identifier = mkIdentifier(fhirSchema);
17
16
  const packageInfo = fhirSchema.package_meta;
18
17
  // Ensure this is recognized as a profile
19
18
  if (identifier.kind !== "profile") {
@@ -27,17 +26,13 @@ export async function transformProfile(fhirSchema, manager) {
27
26
  : `http://hl7.org/fhir/StructureDefinition/${fhirSchema.base}`;
28
27
  const baseName = fhirSchema.base.split("/").pop() || fhirSchema.base;
29
28
  // Determine base kind - could be another profile or a base resource
30
- const baseKind = await determineBaseKind(baseUrl, manager);
29
+ const baseKind = await determineBaseKind(baseUrl, register);
31
30
  // For standard FHIR types, use the standard package
32
31
  const isStandardFhir = baseUrl.startsWith("http://hl7.org/fhir/");
33
32
  base = {
34
33
  kind: baseKind,
35
- package: isStandardFhir
36
- ? "hl7.fhir.r4.core"
37
- : fhirSchema.package_meta.name || "undefined",
38
- version: isStandardFhir
39
- ? "4.0.1"
40
- : fhirSchema.package_meta.version || "undefined",
34
+ package: isStandardFhir ? "hl7.fhir.r4.core" : fhirSchema.package_meta.name || "undefined",
35
+ version: isStandardFhir ? "4.0.1" : fhirSchema.package_meta.version || "undefined",
41
36
  name: baseName,
42
37
  url: baseUrl,
43
38
  };
@@ -59,18 +54,18 @@ export async function transformProfile(fhirSchema, manager) {
59
54
  }
60
55
  // Process profile fields from differential elements
61
56
  if (fhirSchema.elements) {
62
- const fields = await transformElements(fhirSchema, [], fhirSchema.elements, manager, packageInfo);
63
- if (Object.keys(fields).length > 0) {
57
+ const fields = await transformElements(fhirSchema, [], fhirSchema.elements, register, packageInfo);
58
+ if (fields && Object.keys(fields).length > 0) {
64
59
  profileSchema.fields = fields;
65
60
  }
66
61
  }
67
62
  // Process profile constraints
68
- const constraints = await processProfileConstraints(fhirSchema, manager);
63
+ const constraints = await processProfileConstraints(fhirSchema, register);
69
64
  if (Object.keys(constraints).length > 0) {
70
65
  profileSchema.constraints = constraints;
71
66
  }
72
67
  // Process extensions
73
- const extensions = await processProfileExtensions(fhirSchema, manager);
68
+ const extensions = await processProfileExtensions(fhirSchema, register);
74
69
  if (extensions.length > 0) {
75
70
  profileSchema.extensions = extensions;
76
71
  }
@@ -107,8 +102,7 @@ async function determineBaseKind(baseUrl, manager) {
107
102
  // Check if the URL suggests it's a profile from any implementation guide
108
103
  // Non-standard FHIR StructureDefinition URLs (not from base FHIR) are likely profiles
109
104
  // Check if it's any other profile URL pattern
110
- if (baseUrl.includes("StructureDefinition/") &&
111
- !baseUrl.startsWith("http://hl7.org/fhir/StructureDefinition/")) {
105
+ if (baseUrl.includes("StructureDefinition/") && !baseUrl.startsWith("http://hl7.org/fhir/StructureDefinition/")) {
112
106
  // Non-standard FHIR StructureDefinition URLs are likely profiles
113
107
  return "profile";
114
108
  }
@@ -192,9 +186,7 @@ async function processProfileConstraints(fhirSchema, _manager) {
192
186
  };
193
187
  }
194
188
  // Type constraints
195
- if (element.type &&
196
- Array.isArray(element.type) &&
197
- element.type.length > 0) {
189
+ if (element.type && Array.isArray(element.type) && element.type.length > 0) {
198
190
  elementConstraints.types = element.type.map((t) => {
199
191
  const typeConstraint = { code: t.code };
200
192
  if (t.profile)
@@ -227,9 +219,7 @@ async function processProfileExtensions(fhirSchema, _manager) {
227
219
  return extensions;
228
220
  // Look for extension elements
229
221
  for (const [path, element] of Object.entries(fhirSchema.elements)) {
230
- if (path.includes("extension") &&
231
- element.type &&
232
- Array.isArray(element.type)) {
222
+ if (path.includes("extension") && element.type && Array.isArray(element.type)) {
233
223
  for (const type of element.type) {
234
224
  if (type.code === "Extension" && type.profile) {
235
225
  extensions.push({
@@ -0,0 +1,16 @@
1
+ import { CanonicalManager } from "@atomic-ehr/fhir-canonical-manager";
2
+ import type { FHIRSchema, StructureDefinition } from "@atomic-ehr/fhirschema";
3
+ import type { CodegenLogger } from "@root/utils/codegen-logger";
4
+ import { type PackageMeta, type RichFHIRSchema } from "@typeschema/types";
5
+ export type Register = {
6
+ appendFS(fs: FHIRSchema): void;
7
+ ensureCanonicalUrl(canonicalUrl: string): string;
8
+ resolveSD(canonicalUrl: string): StructureDefinition | undefined;
9
+ resolveFS(canonicalUrl: string): RichFHIRSchema | undefined;
10
+ allSD(): StructureDefinition[];
11
+ allFS(): RichFHIRSchema[];
12
+ allVS(): any[];
13
+ complexTypeDict(): Record<string, RichFHIRSchema>;
14
+ } & ReturnType<typeof CanonicalManager>;
15
+ export declare const registerFromManager: (manager: ReturnType<typeof CanonicalManager>, logger?: CodegenLogger, packageInfo?: PackageMeta) => Promise<Register>;
16
+ export declare const registerFromPackageMetas: (packageMetas: PackageMeta[], logger?: CodegenLogger) => Promise<Register>;
@@ -0,0 +1,65 @@
1
+ import { CanonicalManager } from "@atomic-ehr/fhir-canonical-manager";
2
+ import * as fhirschema from "@atomic-ehr/fhirschema";
3
+ import { enrichFHIRSchema } from "@typeschema/types";
4
+ export const registerFromManager = async (manager, logger, packageInfo) => {
5
+ const resources = await manager.search({});
6
+ const structureDefinitions = {};
7
+ for (const resource of resources) {
8
+ if (resource.resourceType === "StructureDefinition") {
9
+ structureDefinitions[resource.url] = resource;
10
+ }
11
+ }
12
+ const fhirSchemas = {};
13
+ const nameDict = {};
14
+ let [success, failed] = [0, 0];
15
+ for (const sd of Object.values(structureDefinitions)) {
16
+ try {
17
+ const fs = fhirschema.translate(sd);
18
+ const rfs = enrichFHIRSchema(fs, packageInfo);
19
+ fhirSchemas[rfs.url] = rfs;
20
+ nameDict[rfs.name] = rfs.url;
21
+ success++;
22
+ }
23
+ catch (error) {
24
+ logger?.warn(`Failed to convert StructureDefinition ${sd.name || sd.id}: ${error instanceof Error ? error.message : String(error)}`);
25
+ failed++;
26
+ }
27
+ logger?.success(`FHIR Schema conversion completed: ${success}/${structureDefinitions.length} successful, ${failed} failed`);
28
+ }
29
+ const valueSets = {};
30
+ for (const resource of resources) {
31
+ if (resource.resourceType === "ValueSet") {
32
+ valueSets[resource.url] = resource;
33
+ }
34
+ }
35
+ const complexTypes = {};
36
+ for (const fs of Object.values(fhirSchemas)) {
37
+ if (fs.kind === "complex-type") {
38
+ complexTypes[fs.url] = fs;
39
+ }
40
+ }
41
+ return {
42
+ ...manager,
43
+ appendFS(fs) {
44
+ fhirSchemas[fs.url] = enrichFHIRSchema(fs);
45
+ },
46
+ resolveFS: (canonicalUrl) => fhirSchemas[canonicalUrl],
47
+ ensureCanonicalUrl: (canonicalUrl) => nameDict[canonicalUrl] || canonicalUrl,
48
+ allSD: () => Object.values(structureDefinitions),
49
+ resolveSD: (canonicalUrl) => structureDefinitions[canonicalUrl],
50
+ allFS: () => Object.values(fhirSchemas),
51
+ allVS: () => Object.values(valueSets),
52
+ complexTypeDict: () => complexTypes,
53
+ };
54
+ };
55
+ export const registerFromPackageMetas = async (packageMetas, logger) => {
56
+ const packageNames = packageMetas.map((meta) => `${meta.name}@${meta.version}`);
57
+ logger?.step(`Loading FHIR packages: ${packageNames.join(", ")}`);
58
+ const manager = CanonicalManager({
59
+ packages: packageNames,
60
+ workingDir: "tmp/fhir",
61
+ });
62
+ await manager.init();
63
+ // Pass package info from the first package (assuming single package for now)
64
+ return await registerFromManager(manager, logger, packageMetas[0]);
65
+ };
@@ -2,16 +2,16 @@
2
2
  * A code generation friendly representation of FHIR StructureDefinition and
3
3
  * FHIR Schema designed to simplify SDK resource classes/types generation.
4
4
  */
5
- import type * as FS from "@atomic-ehr/fhirschema";
6
5
  import type { CanonicalManager } from "@atomic-ehr/fhir-canonical-manager";
7
- export interface PackageInfo {
6
+ import type * as FS from "@atomic-ehr/fhirschema";
7
+ export interface PackageMeta {
8
8
  name: string;
9
9
  version: string;
10
10
  }
11
11
  export type RichFHIRSchema = Omit<FS.FHIRSchema, "package_meta"> & {
12
- package_meta: PackageInfo;
12
+ package_meta: PackageMeta;
13
13
  };
14
- export declare const enrichFHIRSchema: (schema: FS.FHIRSchema) => RichFHIRSchema;
14
+ export declare const enrichFHIRSchema: (schema: FS.FHIRSchema, packageMeta?: PackageMeta) => RichFHIRSchema;
15
15
  type IdentifierBase = {
16
16
  name: string;
17
17
  package: string;
@@ -27,13 +27,13 @@ type ComplexTypeIdentifier = {
27
27
  type ResourceIdentifier = {
28
28
  kind: "resource";
29
29
  } & IdentifierBase;
30
- type ValueSetIdentifier = {
30
+ export type ValueSetIdentifier = {
31
31
  kind: "value-set";
32
32
  } & IdentifierBase;
33
- type NestedIdentifier = {
33
+ export type NestedIdentifier = {
34
34
  kind: "nested";
35
35
  } & IdentifierBase;
36
- type BindingIdentifier = {
36
+ export type BindingIdentifier = {
37
37
  kind: "binding";
38
38
  } & IdentifierBase;
39
39
  type ProfileIdentifier = {
@@ -50,7 +50,12 @@ interface TypeSchemaForPrimitiveType {
50
50
  base: Identifier;
51
51
  dependencies?: Identifier[];
52
52
  }
53
- interface TypeSchemaForProfile {
53
+ export interface NestedType {
54
+ identifier: NestedIdentifier;
55
+ base: Identifier;
56
+ fields: Record<string, TypeSchemaField>;
57
+ }
58
+ export interface TypeSchemaForProfile {
54
59
  identifier: ProfileIdentifier;
55
60
  base: Identifier;
56
61
  description?: string;
@@ -60,9 +65,9 @@ interface TypeSchemaForProfile {
60
65
  validation?: ValidationRule[];
61
66
  dependencies?: Identifier[];
62
67
  metadata?: ProfileMetadata;
63
- nested?: any[];
68
+ nested?: NestedType[];
64
69
  }
65
- interface ProfileConstraint {
70
+ export interface ProfileConstraint {
66
71
  min?: number;
67
72
  max?: string;
68
73
  mustSupport?: boolean;
@@ -83,21 +88,21 @@ interface ProfileConstraint {
83
88
  ordered?: boolean;
84
89
  };
85
90
  }
86
- interface ProfileExtension {
91
+ export interface ProfileExtension {
87
92
  path: string;
88
93
  profile: string | string[];
89
94
  min?: number;
90
95
  max?: string;
91
96
  mustSupport?: boolean;
92
97
  }
93
- interface ValidationRule {
98
+ export interface ValidationRule {
94
99
  path: string;
95
100
  key: string;
96
101
  severity: "error" | "warning" | "information";
97
102
  human: string;
98
103
  expression?: string;
99
104
  }
100
- interface ProfileMetadata {
105
+ export interface ProfileMetadata {
101
106
  publisher?: string;
102
107
  contact?: any[];
103
108
  copyright?: string;
@@ -107,20 +112,21 @@ interface ProfileMetadata {
107
112
  jurisdiction?: any[];
108
113
  package?: string;
109
114
  }
115
+ export interface TypeSchemaNestedType {
116
+ identifier: NestedIdentifier;
117
+ base: Identifier;
118
+ fields?: {
119
+ [k: string]: RegularField | PolymorphicValueXFieldDeclaration | PolymorphicValueXFieldInstance;
120
+ };
121
+ }
110
122
  export interface TypeSchemaForResourceComplexTypeLogical {
111
- identifier: ResourceIdentifier | ComplexTypeIdentifier | LogicalIdentifier;
123
+ identifier: Identifier;
112
124
  base?: Identifier;
113
125
  description?: string;
114
126
  fields?: {
115
127
  [k: string]: RegularField | PolymorphicValueXFieldDeclaration | PolymorphicValueXFieldInstance;
116
128
  };
117
- nested?: {
118
- identifier: NestedIdentifier;
119
- base: Identifier;
120
- fields?: {
121
- [k: string]: RegularField | PolymorphicValueXFieldDeclaration | PolymorphicValueXFieldInstance;
122
- };
123
- }[];
129
+ nested?: TypeSchemaNestedType[];
124
130
  dependencies?: Identifier[];
125
131
  }
126
132
  export interface RegularField {
@@ -183,4 +189,9 @@ export interface TypeschemaGeneratorOptions {
183
189
  manager?: ReturnType<typeof CanonicalManager> | null;
184
190
  }
185
191
  export declare function isBindingSchema(schema: TypeSchema): schema is TypeSchemaForBinding;
192
+ export type TypeschemaParserOptions = {
193
+ format?: "auto" | "ndjson" | "json";
194
+ validate?: boolean;
195
+ strict?: boolean;
196
+ };
186
197
  export {};
@@ -2,13 +2,13 @@
2
2
  * A code generation friendly representation of FHIR StructureDefinition and
3
3
  * FHIR Schema designed to simplify SDK resource classes/types generation.
4
4
  */
5
- export const enrichFHIRSchema = (schema) => {
5
+ export const enrichFHIRSchema = (schema, packageMeta) => {
6
+ if (!packageMeta) {
7
+ packageMeta = { name: "undefined", version: "undefined" };
8
+ }
6
9
  return {
7
10
  ...schema,
8
- package_meta: {
9
- name: schema.package_name || schema.package_meta?.name || "undefined",
10
- version: schema.package_version || schema.package_meta?.version || "undefined",
11
- },
11
+ package_meta: schema.package_meta || packageMeta,
12
12
  };
13
13
  };
14
14
  export function isBindingSchema(schema) {
@@ -4,7 +4,7 @@
4
4
  * Functions for transforming FHIR ValueSets into TypeSchema format
5
5
  */
6
6
  import type { CanonicalManager } from "@atomic-ehr/fhir-canonical-manager";
7
- import type { PackageInfo, TypeSchemaForValueSet } from "../types";
7
+ import type { PackageMeta, TypeSchemaForValueSet } from "../types";
8
8
  /**
9
9
  * Extract all concepts from a ValueSet
10
10
  */
@@ -16,4 +16,4 @@ export declare function extractValueSetConcepts(valueSet: any, manager: ReturnTy
16
16
  /**
17
17
  * Transform a FHIR ValueSet to TypeSchema format
18
18
  */
19
- export declare function transformValueSet(valueSet: any, manager: ReturnType<typeof CanonicalManager>, packageInfo?: PackageInfo): Promise<TypeSchemaForValueSet>;
19
+ export declare function transformValueSet(valueSet: any, manager: ReturnType<typeof CanonicalManager>, packageInfo?: PackageMeta): Promise<TypeSchemaForValueSet>;
@@ -3,7 +3,7 @@
3
3
  *
4
4
  * Functions for transforming FHIR ValueSets into TypeSchema format
5
5
  */
6
- import { buildValueSetIdentifier } from "../core/identifier";
6
+ import { mkValueSetIdentifier } from "../core/identifier";
7
7
  /**
8
8
  * Extract concepts from a CodeSystem
9
9
  */
@@ -117,7 +117,7 @@ export async function extractValueSetConcepts(valueSet, manager) {
117
117
  * Transform a FHIR ValueSet to TypeSchema format
118
118
  */
119
119
  export async function transformValueSet(valueSet, manager, packageInfo) {
120
- const identifier = buildValueSetIdentifier(valueSet.url, valueSet, packageInfo);
120
+ const identifier = mkValueSetIdentifier(valueSet.url, valueSet, packageInfo);
121
121
  const typeSchemaValueSet = {
122
122
  identifier,
123
123
  };
@@ -152,7 +152,7 @@ export async function transformValueSet(valueSet, manager, packageInfo) {
152
152
  }
153
153
  if (item.valueSet) {
154
154
  for (const vsUrl of item.valueSet) {
155
- deps.push(buildValueSetIdentifier(vsUrl, undefined, packageInfo));
155
+ deps.push(mkValueSetIdentifier(vsUrl, undefined, packageInfo));
156
156
  }
157
157
  }
158
158
  }
@@ -17,12 +17,8 @@ export class CodegenLogger {
17
17
  };
18
18
  }
19
19
  formatMessage(level, message, color) {
20
- const timestamp = this.options.timestamp
21
- ? `${pc.gray(new Date().toLocaleTimeString())} `
22
- : "";
23
- const prefix = this.options.prefix
24
- ? `${pc.cyan(`[${this.options.prefix}]`)} `
25
- : "";
20
+ const timestamp = this.options.timestamp ? `${pc.gray(new Date().toLocaleTimeString())} ` : "";
21
+ const prefix = this.options.prefix ? `${pc.cyan(`[${this.options.prefix}]`)} ` : "";
26
22
  return `${timestamp}${color(level)} ${prefix}${message}`;
27
23
  }
28
24
  /**
@@ -79,12 +75,8 @@ export class CodegenLogger {
79
75
  * Plain message (no icon, just colored text)
80
76
  */
81
77
  plain(message, color = (s) => s) {
82
- const timestamp = this.options.timestamp
83
- ? `${pc.gray(new Date().toLocaleTimeString())} `
84
- : "";
85
- const prefix = this.options.prefix
86
- ? `${pc.cyan(`[${this.options.prefix}]`)} `
87
- : "";
78
+ const timestamp = this.options.timestamp ? `${pc.gray(new Date().toLocaleTimeString())} ` : "";
79
+ const prefix = this.options.prefix ? `${pc.cyan(`[${this.options.prefix}]`)} ` : "";
88
80
  console.log(`${timestamp}${prefix}${color(message)}`);
89
81
  }
90
82
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atomic-ehr/codegen",
3
- "version": "0.0.1-canary.20250927094522.7f26cfe",
3
+ "version": "0.0.1-canary.20250930075344.1c0b689",
4
4
  "description": "Code generation tools for FHIR resources and TypeSchema definitions",
5
5
  "keywords": [
6
6
  "fhir",
@@ -64,7 +64,7 @@
64
64
  "homepage": "https://github.com/atomic-ehr/codegen#readme",
65
65
  "devDependencies": {
66
66
  "@biomejs/biome": "^2.1.4",
67
- "@types/bun": "latest",
67
+ "@types/bun": "^1.2.23",
68
68
  "@types/handlebars": "^4.1.0",
69
69
  "@types/node": "^22.17.1",
70
70
  "@types/yargs": "^17.0.33",