@atomic-ehr/codegen 0.0.1-canary.20251006094042.7f0be72 → 0.0.1-canary.20251007094146.5297616

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -2,224 +2,6 @@ import { CanonicalManager } from '@atomic-ehr/fhir-canonical-manager';
2
2
  import * as FS from '@atomic-ehr/fhirschema';
3
3
  import { FHIRSchema, StructureDefinition } from '@atomic-ehr/fhirschema';
4
4
 
5
- /**
6
- * New Config Schema for High-Level API
7
- *
8
- * Simple configuration system compatible ONLY with the new high-level APIBuilder.
9
- * All legacy config functionality has been removed.
10
- */
11
- /**
12
- * TypeScript generator configuration options
13
- */
14
- interface TypeScriptGeneratorConfig {
15
- moduleFormat?: "esm" | "cjs";
16
- generateIndex?: boolean;
17
- includeDocuments?: boolean;
18
- namingConvention?: "PascalCase" | "camelCase";
19
- strictMode?: boolean;
20
- includeProfiles?: boolean;
21
- includeExtensions?: boolean;
22
- includeCodeSystems?: boolean;
23
- includeOperations?: boolean;
24
- /** Generate individual TypeScript files for value sets (default: false) */
25
- generateValueSets?: boolean;
26
- /** Include helper validation functions in value set files (default: false) */
27
- includeValueSetHelpers?: boolean;
28
- /** Which binding strengths to generate value sets for (default: ['required']) */
29
- valueSetStrengths?: ("required" | "preferred" | "extensible" | "example")[];
30
- /** Directory name for value set files (relative to outputDir) (default: 'valuesets') */
31
- valueSetDirectory?: string;
32
- /** Value set generation mode (default: 'required-only') */
33
- valueSetMode?: "all" | "required-only" | "custom";
34
- fhirVersion?: "R4" | "R5";
35
- resourceTypes?: string[];
36
- maxDepth?: number;
37
- profileOptions?: {
38
- generateKind?: "interface" | "type" | "both";
39
- includeConstraints?: boolean;
40
- includeDocumentation?: boolean;
41
- strictMode?: boolean;
42
- subfolder?: string;
43
- };
44
- generateBuilders?: boolean;
45
- builderOptions?: {
46
- includeValidation?: boolean;
47
- includeFactoryMethods?: boolean;
48
- includeInterfaces?: boolean;
49
- generateNestedBuilders?: boolean;
50
- includeHelperMethods?: boolean;
51
- supportPartialBuild?: boolean;
52
- includeJSDoc?: boolean;
53
- generateFactories?: boolean;
54
- includeTypeGuards?: boolean;
55
- handleChoiceTypes?: boolean;
56
- generateArrayHelpers?: boolean;
57
- };
58
- validatorOptions?: {
59
- includeCardinality?: boolean;
60
- includeTypes?: boolean;
61
- includeConstraints?: boolean;
62
- includeInvariants?: boolean;
63
- validateRequired?: boolean;
64
- allowAdditional?: boolean;
65
- strictValidation?: boolean;
66
- collectMetrics?: boolean;
67
- generateAssertions?: boolean;
68
- generatePartialValidators?: boolean;
69
- optimizePerformance?: boolean;
70
- includeJSDoc?: boolean;
71
- generateCompositeValidators?: boolean;
72
- };
73
- guardOptions?: {
74
- includeRuntimeValidation?: boolean;
75
- includeErrorMessages?: boolean;
76
- treeShakeable?: boolean;
77
- targetTSVersion?: "3.8" | "4.0" | "4.5" | "5.0";
78
- strictGuards?: boolean;
79
- includeNullChecks?: boolean;
80
- verbose?: boolean;
81
- };
82
- }
83
- /**
84
- * TypeSchema Configuration
85
- * Controls TypeSchema generation and caching behavior
86
- */
87
- interface TypeSchemaConfig {
88
- /** Enable persistent caching of generated TypeSchemas */
89
- enablePersistence?: boolean;
90
- /** Directory to store cached TypeSchemas (relative to outputDir) */
91
- cacheDir?: string;
92
- /** Maximum age of cached schemas in milliseconds before regeneration */
93
- maxAge?: number;
94
- /** Whether to validate cached schemas before reuse */
95
- validateCached?: boolean;
96
- /** Force regeneration of schemas even if cached */
97
- forceRegenerate?: boolean;
98
- /** Share cache across multiple codegen runs */
99
- shareCache?: boolean;
100
- /** Cache key prefix for namespacing */
101
- cacheKeyPrefix?: string;
102
- /** Only generate TypeSchemas for specific ResourceTypes (treeshaking) */
103
- treeshake?: string[];
104
- /** Generate single TypeSchema file instead of multiple files */
105
- singleFile?: boolean;
106
- /** Profile packages configuration */
107
- profiles?: {
108
- /** Auto-detect profiles in packages */
109
- autoDetect?: boolean;
110
- };
111
- }
112
- /**
113
- * Main configuration schema for the new high-level API
114
- */
115
- interface Config {
116
- outputDir?: string;
117
- verbose?: boolean;
118
- overwrite?: boolean;
119
- validate?: boolean;
120
- cache?: boolean;
121
- typescript?: TypeScriptGeneratorConfig;
122
- typeSchema?: TypeSchemaConfig;
123
- packages?: string[];
124
- files?: string[];
125
- $schema?: string;
126
- }
127
- /**
128
- * Default configuration values
129
- */
130
- declare const DEFAULT_CONFIG: Required<Config>;
131
- /**
132
- * Configuration file names to search for
133
- */
134
- declare const CONFIG_FILE_NAMES: string[];
135
- /**
136
- * Validation error interface
137
- */
138
- interface ConfigValidationError {
139
- path: string;
140
- message: string;
141
- value?: unknown;
142
- }
143
- /**
144
- * Configuration validation result
145
- */
146
- interface ConfigValidationResult {
147
- valid: boolean;
148
- errors: ConfigValidationError[];
149
- warnings: string[];
150
- config?: Config;
151
- }
152
- /**
153
- * Simple configuration validator
154
- */
155
- declare class ConfigValidator {
156
- /**
157
- * Validate a configuration object
158
- */
159
- validate(config: unknown): ConfigValidationResult;
160
- private validateTypeScriptConfig;
161
- private validateValidatorOptions;
162
- private validateGuardOptions;
163
- private validateProfileOptions;
164
- private validateTypeSchemaConfig;
165
- }
166
- /**
167
- * Configuration loader with autoloading capabilities
168
- */
169
- declare class ConfigLoader {
170
- private validator;
171
- /**
172
- * Auto-load configuration from the current working directory
173
- */
174
- autoload(workingDir?: string): Promise<Config>;
175
- /**
176
- * Load configuration from a specific file
177
- */
178
- loadFromFile(filePath: string): Promise<Config>;
179
- /**
180
- * Find configuration file in the given directory
181
- */
182
- private findConfigFile;
183
- /**
184
- * Merge user config with defaults
185
- */
186
- private mergeWithDefaults;
187
- }
188
- /**
189
- * Global config loader instance
190
- */
191
- declare const configLoader: ConfigLoader;
192
- /**
193
- * Convenience function to auto-load configuration
194
- */
195
- declare function loadConfig(workingDir?: string): Promise<Config>;
196
- /**
197
- * Type guard to check if an object is a valid Config
198
- */
199
- declare function isConfig(obj: unknown): obj is Config;
200
- /**
201
- * Define configuration with type safety and IntelliSense support.
202
- * Similar to Vite's defineConfig function pattern.
203
- *
204
- * @example
205
- * ```typescript
206
- * import { defineConfig } from "@atomic-ehr/codegen";
207
- *
208
- * export default defineConfig({
209
- * outputDir: "./generated",
210
- * packages: [
211
- * "hl7.fhir.r4.core@4.0.1",
212
- * "hl7.fhir.us.core@6.1.0"
213
- * ],
214
- * typescript: {
215
- * generateIndex: true,
216
- * strictMode: true
217
- * }
218
- * });
219
- * ```
220
- */
221
- declare function defineConfig(config: Config): Config;
222
-
223
5
  /**
224
6
  * CodeGen Logger
225
7
  *
@@ -507,6 +289,238 @@ type RichValueSet = Omit<ValueSet, "name" | "url"> & {
507
289
  url?: CanonicalUrl;
508
290
  };
509
291
 
292
+ type Register = {
293
+ appendFs(fs: FHIRSchema): void;
294
+ ensureCanonicalUrl(name: string | Name | CanonicalUrl): CanonicalUrl;
295
+ resolveSd(canonicalUrl: CanonicalUrl): StructureDefinition | undefined;
296
+ resolveFs(canonicalUrl: CanonicalUrl): RichFHIRSchema | undefined;
297
+ resolveFsGenealogy(canonicalUrl: CanonicalUrl): RichFHIRSchema[];
298
+ allSd(): StructureDefinition[];
299
+ allFs(): RichFHIRSchema[];
300
+ allVs(): RichValueSet[];
301
+ resolveVs(canonicalUrl: CanonicalUrl): RichValueSet | undefined;
302
+ complexTypeDict(): Record<string, RichFHIRSchema>;
303
+ resolveAny(canonicalUrl: CanonicalUrl): any | undefined;
304
+ } & ReturnType<typeof CanonicalManager>;
305
+
306
+ /**
307
+ * New Config Schema for High-Level API
308
+ *
309
+ * Simple configuration system compatible ONLY with the new high-level APIBuilder.
310
+ * All legacy config functionality has been removed.
311
+ */
312
+ /**
313
+ * TypeScript generator configuration options
314
+ */
315
+ interface TypeScriptGeneratorConfig {
316
+ moduleFormat?: "esm" | "cjs";
317
+ generateIndex?: boolean;
318
+ includeDocuments?: boolean;
319
+ namingConvention?: "PascalCase" | "camelCase";
320
+ strictMode?: boolean;
321
+ includeProfiles?: boolean;
322
+ includeExtensions?: boolean;
323
+ includeCodeSystems?: boolean;
324
+ includeOperations?: boolean;
325
+ /** Generate individual TypeScript files for value sets (default: false) */
326
+ generateValueSets?: boolean;
327
+ /** Include helper validation functions in value set files (default: false) */
328
+ includeValueSetHelpers?: boolean;
329
+ /** Which binding strengths to generate value sets for (default: ['required']) */
330
+ valueSetStrengths?: ("required" | "preferred" | "extensible" | "example")[];
331
+ /** Directory name for value set files (relative to outputDir) (default: 'valuesets') */
332
+ valueSetDirectory?: string;
333
+ /** Value set generation mode (default: 'required-only') */
334
+ valueSetMode?: "all" | "required-only" | "custom";
335
+ fhirVersion?: "R4" | "R5";
336
+ resourceTypes?: string[];
337
+ maxDepth?: number;
338
+ profileOptions?: {
339
+ generateKind?: "interface" | "type" | "both";
340
+ includeConstraints?: boolean;
341
+ includeDocumentation?: boolean;
342
+ strictMode?: boolean;
343
+ subfolder?: string;
344
+ };
345
+ generateBuilders?: boolean;
346
+ builderOptions?: {
347
+ includeValidation?: boolean;
348
+ includeFactoryMethods?: boolean;
349
+ includeInterfaces?: boolean;
350
+ generateNestedBuilders?: boolean;
351
+ includeHelperMethods?: boolean;
352
+ supportPartialBuild?: boolean;
353
+ includeJSDoc?: boolean;
354
+ generateFactories?: boolean;
355
+ includeTypeGuards?: boolean;
356
+ handleChoiceTypes?: boolean;
357
+ generateArrayHelpers?: boolean;
358
+ };
359
+ validatorOptions?: {
360
+ includeCardinality?: boolean;
361
+ includeTypes?: boolean;
362
+ includeConstraints?: boolean;
363
+ includeInvariants?: boolean;
364
+ validateRequired?: boolean;
365
+ allowAdditional?: boolean;
366
+ strictValidation?: boolean;
367
+ collectMetrics?: boolean;
368
+ generateAssertions?: boolean;
369
+ generatePartialValidators?: boolean;
370
+ optimizePerformance?: boolean;
371
+ includeJSDoc?: boolean;
372
+ generateCompositeValidators?: boolean;
373
+ };
374
+ guardOptions?: {
375
+ includeRuntimeValidation?: boolean;
376
+ includeErrorMessages?: boolean;
377
+ treeShakeable?: boolean;
378
+ targetTSVersion?: "3.8" | "4.0" | "4.5" | "5.0";
379
+ strictGuards?: boolean;
380
+ includeNullChecks?: boolean;
381
+ verbose?: boolean;
382
+ };
383
+ }
384
+ /**
385
+ * TypeSchema Configuration
386
+ * Controls TypeSchema generation and caching behavior
387
+ */
388
+ interface TypeSchemaConfig {
389
+ /** Enable persistent caching of generated TypeSchemas */
390
+ enablePersistence?: boolean;
391
+ /** Directory to store cached TypeSchemas (relative to outputDir) */
392
+ cacheDir?: string;
393
+ /** Maximum age of cached schemas in milliseconds before regeneration */
394
+ maxAge?: number;
395
+ /** Whether to validate cached schemas before reuse */
396
+ validateCached?: boolean;
397
+ /** Force regeneration of schemas even if cached */
398
+ forceRegenerate?: boolean;
399
+ /** Share cache across multiple codegen runs */
400
+ shareCache?: boolean;
401
+ /** Cache key prefix for namespacing */
402
+ cacheKeyPrefix?: string;
403
+ /** Only generate TypeSchemas for specific ResourceTypes (treeshaking) */
404
+ treeshake?: string[];
405
+ /** Generate single TypeSchema file instead of multiple files */
406
+ singleFile?: boolean;
407
+ /** Profile packages configuration */
408
+ profiles?: {
409
+ /** Auto-detect profiles in packages */
410
+ autoDetect?: boolean;
411
+ };
412
+ }
413
+ /**
414
+ * Main configuration schema for the new high-level API
415
+ */
416
+ interface Config {
417
+ outputDir?: string;
418
+ verbose?: boolean;
419
+ overwrite?: boolean;
420
+ validate?: boolean;
421
+ cache?: boolean;
422
+ typescript?: TypeScriptGeneratorConfig;
423
+ typeSchema?: TypeSchemaConfig;
424
+ packages?: string[];
425
+ files?: string[];
426
+ $schema?: string;
427
+ }
428
+ /**
429
+ * Default configuration values
430
+ */
431
+ declare const DEFAULT_CONFIG: Required<Config>;
432
+ /**
433
+ * Configuration file names to search for
434
+ */
435
+ declare const CONFIG_FILE_NAMES: string[];
436
+ /**
437
+ * Validation error interface
438
+ */
439
+ interface ConfigValidationError {
440
+ path: string;
441
+ message: string;
442
+ value?: unknown;
443
+ }
444
+ /**
445
+ * Configuration validation result
446
+ */
447
+ interface ConfigValidationResult {
448
+ valid: boolean;
449
+ errors: ConfigValidationError[];
450
+ warnings: string[];
451
+ config?: Config;
452
+ }
453
+ /**
454
+ * Simple configuration validator
455
+ */
456
+ declare class ConfigValidator {
457
+ /**
458
+ * Validate a configuration object
459
+ */
460
+ validate(config: unknown): ConfigValidationResult;
461
+ private validateTypeScriptConfig;
462
+ private validateValidatorOptions;
463
+ private validateGuardOptions;
464
+ private validateProfileOptions;
465
+ private validateTypeSchemaConfig;
466
+ }
467
+ /**
468
+ * Configuration loader with autoloading capabilities
469
+ */
470
+ declare class ConfigLoader {
471
+ private validator;
472
+ /**
473
+ * Auto-load configuration from the current working directory
474
+ */
475
+ autoload(workingDir?: string): Promise<Config>;
476
+ /**
477
+ * Load configuration from a specific file
478
+ */
479
+ loadFromFile(filePath: string): Promise<Config>;
480
+ /**
481
+ * Find configuration file in the given directory
482
+ */
483
+ private findConfigFile;
484
+ /**
485
+ * Merge user config with defaults
486
+ */
487
+ private mergeWithDefaults;
488
+ }
489
+ /**
490
+ * Global config loader instance
491
+ */
492
+ declare const configLoader: ConfigLoader;
493
+ /**
494
+ * Convenience function to auto-load configuration
495
+ */
496
+ declare function loadConfig(workingDir?: string): Promise<Config>;
497
+ /**
498
+ * Type guard to check if an object is a valid Config
499
+ */
500
+ declare function isConfig(obj: unknown): obj is Config;
501
+ /**
502
+ * Define configuration with type safety and IntelliSense support.
503
+ * Similar to Vite's defineConfig function pattern.
504
+ *
505
+ * @example
506
+ * ```typescript
507
+ * import { defineConfig } from "@atomic-ehr/codegen";
508
+ *
509
+ * export default defineConfig({
510
+ * outputDir: "./generated",
511
+ * packages: [
512
+ * "hl7.fhir.r4.core@4.0.1",
513
+ * "hl7.fhir.us.core@6.1.0"
514
+ * ],
515
+ * typescript: {
516
+ * generateIndex: true,
517
+ * strictMode: true
518
+ * }
519
+ * });
520
+ * ```
521
+ */
522
+ declare function defineConfig(config: Config): Config;
523
+
510
524
  /**
511
525
  * TypeSchema Cache System
512
526
  *
@@ -587,20 +601,6 @@ declare class TypeSchemaCache {
587
601
  clearDisk(): Promise<void>;
588
602
  }
589
603
 
590
- type Register = {
591
- appendFs(fs: FHIRSchema): void;
592
- ensureCanonicalUrl(name: string | Name | CanonicalUrl): CanonicalUrl;
593
- resolveSd(canonicalUrl: CanonicalUrl): StructureDefinition | undefined;
594
- resolveFs(canonicalUrl: CanonicalUrl): RichFHIRSchema | undefined;
595
- resolveFsGenealogy(canonicalUrl: CanonicalUrl): RichFHIRSchema[];
596
- allSd(): StructureDefinition[];
597
- allFs(): RichFHIRSchema[];
598
- allVs(): RichValueSet[];
599
- resolveVs(canonicalUrl: CanonicalUrl): RichValueSet | undefined;
600
- complexTypeDict(): Record<string, RichFHIRSchema>;
601
- resolveAny(canonicalUrl: CanonicalUrl): any | undefined;
602
- } & ReturnType<typeof CanonicalManager>;
603
-
604
604
  /**
605
605
  * TypeSchema Generator
606
606
  *
@@ -624,7 +624,7 @@ declare class TypeSchemaGenerator {
624
624
  private initializeCache;
625
625
  registerFromPackageMetas(packageMetas: PackageMeta[]): Promise<Register>;
626
626
  generateFhirSchemas(structureDefinitions: StructureDefinition[]): FHIRSchema[];
627
- generateValueSetSchemas(valueSets: any[], _packageInfo: PackageMeta): Promise<TypeSchema[]>;
627
+ generateValueSetSchemas(valueSets: RichValueSet[]): Promise<TypeSchema[]>;
628
628
  generateFromPackage(packageName: string, packageVersion?: string): Promise<TypeSchema[]>;
629
629
  /**
630
630
  * Apply treeshaking to StructureDefinitions before FHIR schema transformation
@@ -715,6 +715,14 @@ declare class TypeSchemaParser {
715
715
  private matchesIdentifier;
716
716
  }
717
717
 
718
+ interface WriterOptions {
719
+ outputDir: string;
720
+ tabSize: number;
721
+ withDebugComment?: boolean;
722
+ commentLinePrefix: string;
723
+ logger?: CodegenLogger;
724
+ }
725
+
718
726
  /**
719
727
  * High-Level API Builder
720
728
  *
@@ -729,11 +737,11 @@ interface APIBuilderOptions {
729
737
  outputDir?: string;
730
738
  verbose?: boolean;
731
739
  overwrite?: boolean;
732
- validate?: boolean;
733
740
  cache?: boolean;
734
741
  typeSchemaConfig?: TypeSchemaConfig;
735
742
  logger?: CodegenLogger;
736
743
  manager?: ReturnType<typeof CanonicalManager> | null;
744
+ throwException?: boolean;
737
745
  }
738
746
  /**
739
747
  * Progress callback for long-running operations
@@ -760,16 +768,14 @@ declare class APIBuilder {
760
768
  private schemas;
761
769
  private options;
762
770
  private generators;
763
- private progressCallback?;
764
771
  private cache?;
765
772
  private pendingOperations;
766
773
  private typeSchemaGenerator?;
767
774
  private logger;
775
+ private packages;
776
+ progressCallback: any;
768
777
  private typeSchemaConfig?;
769
778
  constructor(options?: APIBuilderOptions);
770
- /**
771
- * Load TypeSchema from a FHIR package
772
- */
773
779
  fromPackage(packageName: string, version?: string): APIBuilder;
774
780
  /**
775
781
  * Load TypeSchema from files
@@ -779,9 +785,6 @@ declare class APIBuilder {
779
785
  * Load TypeSchema from TypeSchema objects
780
786
  */
781
787
  fromSchemas(schemas: TypeSchema[]): APIBuilder;
782
- /**
783
- * Configure TypeScript generation
784
- */
785
788
  typescript(options?: {
786
789
  moduleFormat?: "esm" | "cjs";
787
790
  generateIndex?: boolean;
@@ -795,6 +798,7 @@ declare class APIBuilder {
795
798
  valueSetMode?: "all" | "required-only" | "custom";
796
799
  valueSetDirectory?: string;
797
800
  }): APIBuilder;
801
+ typescript2(opts: Partial<WriterOptions>): this;
798
802
  /**
799
803
  * Set a progress callback for monitoring generation
800
804
  */
@@ -803,17 +807,8 @@ declare class APIBuilder {
803
807
  * Set the output directory for all generators
804
808
  */
805
809
  outputTo(directory: string): APIBuilder;
806
- /**
807
- * Enable/disable verbose logging
808
- */
809
810
  verbose(enabled?: boolean): APIBuilder;
810
- /**
811
- * Enable/disable validation
812
- */
813
- validate(enabled?: boolean): APIBuilder;
814
- /**
815
- * Execute the generation process
816
- */
811
+ throwException(enabled?: boolean): APIBuilder;
817
812
  generate(): Promise<GenerationResult>;
818
813
  /**
819
814
  * Generate and return the results without writing to files
@@ -836,12 +831,8 @@ declare class APIBuilder {
836
831
  * Get configured generators (for inspection)
837
832
  */
838
833
  getGenerators(): string[];
839
- private loadFromPackage;
840
834
  private loadFromFiles;
841
- private resolveSchemas;
842
- private validateSchemas;
843
835
  private executeGenerators;
844
- private reportProgress;
845
836
  }
846
837
  /**
847
838
  * Create a new API builder instance