@atomic-ehr/codegen 0.0.1-canary.20250822114054.4ca1428 → 0.0.1-canary.20250822150706.c3b8669

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 (120) hide show
  1. package/dist/api/builder.d.ts +3 -3
  2. package/dist/api/builder.d.ts.map +1 -1
  3. package/dist/api/builder.js +374 -0
  4. package/dist/api/generators/base/BaseGenerator.d.ts +4 -4
  5. package/dist/api/generators/base/BaseGenerator.d.ts.map +1 -1
  6. package/dist/api/generators/base/BaseGenerator.js +572 -0
  7. package/dist/api/generators/base/FileManager.d.ts +2 -2
  8. package/dist/api/generators/base/FileManager.d.ts.map +1 -1
  9. package/dist/api/generators/base/FileManager.js +204 -0
  10. package/dist/api/generators/base/PythonTypeMapper.d.ts +2 -2
  11. package/dist/api/generators/base/PythonTypeMapper.d.ts.map +1 -1
  12. package/dist/api/generators/base/PythonTypeMapper.js +71 -0
  13. package/dist/api/generators/base/TemplateEngine.d.ts +1 -1
  14. package/dist/api/generators/base/TemplateEngine.d.ts.map +1 -1
  15. package/dist/api/generators/base/TemplateEngine.js +133 -0
  16. package/dist/api/generators/base/TypeMapper.js +153 -0
  17. package/dist/api/generators/base/TypeScriptTypeMapper.d.ts +1 -1
  18. package/dist/api/generators/base/TypeScriptTypeMapper.d.ts.map +1 -1
  19. package/dist/api/generators/base/TypeScriptTypeMapper.js +232 -0
  20. package/dist/api/generators/base/builders/DirectoryBuilder.d.ts +4 -4
  21. package/dist/api/generators/base/builders/DirectoryBuilder.d.ts.map +1 -1
  22. package/dist/api/generators/base/builders/DirectoryBuilder.js +215 -0
  23. package/dist/api/generators/base/builders/FileBuilder.d.ts +2 -2
  24. package/dist/api/generators/base/builders/FileBuilder.d.ts.map +1 -1
  25. package/dist/api/generators/base/builders/FileBuilder.js +408 -0
  26. package/dist/api/generators/base/builders/IndexBuilder.d.ts +2 -2
  27. package/dist/api/generators/base/builders/IndexBuilder.d.ts.map +1 -1
  28. package/dist/api/generators/base/builders/IndexBuilder.js +290 -0
  29. package/dist/api/generators/base/enhanced-errors.d.ts +2 -2
  30. package/dist/api/generators/base/enhanced-errors.d.ts.map +1 -1
  31. package/dist/api/generators/base/enhanced-errors.js +259 -0
  32. package/dist/api/generators/base/error-handler.d.ts +1 -1
  33. package/dist/api/generators/base/error-handler.d.ts.map +1 -1
  34. package/dist/api/generators/base/error-handler.js +243 -0
  35. package/dist/api/generators/base/errors.d.ts +2 -2
  36. package/dist/api/generators/base/errors.d.ts.map +1 -1
  37. package/dist/api/generators/base/errors.js +694 -0
  38. package/dist/api/generators/base/index.d.ts +22 -22
  39. package/dist/api/generators/base/index.d.ts.map +1 -1
  40. package/dist/api/generators/base/index.js +161 -0
  41. package/dist/api/generators/base/types.d.ts +2 -2
  42. package/dist/api/generators/base/types.d.ts.map +1 -1
  43. package/dist/api/generators/base/types.js +12 -0
  44. package/dist/api/generators/rest-client.d.ts +2 -2
  45. package/dist/api/generators/rest-client.d.ts.map +1 -1
  46. package/dist/api/generators/rest-client.js +847 -0
  47. package/dist/api/generators/search-parameter-enhancer.d.ts +1 -1
  48. package/dist/api/generators/search-parameter-enhancer.d.ts.map +1 -1
  49. package/dist/api/generators/search-parameter-enhancer.js +801 -0
  50. package/dist/api/generators/types.js +4 -0
  51. package/dist/api/generators/typescript.d.ts +3 -3
  52. package/dist/api/generators/typescript.d.ts.map +1 -1
  53. package/dist/api/generators/typescript.js +537 -0
  54. package/dist/api/generators/validation-generator.js +632 -0
  55. package/dist/api/index.d.ts +10 -10
  56. package/dist/api/index.d.ts.map +1 -1
  57. package/dist/api/index.js +51 -0
  58. package/dist/cli/commands/generate/typescript.d.ts +1 -1
  59. package/dist/cli/commands/generate/typescript.d.ts.map +1 -1
  60. package/dist/cli/commands/generate/typescript.js +52 -0
  61. package/dist/cli/commands/generate.d.ts +5 -12
  62. package/dist/cli/commands/generate.d.ts.map +1 -1
  63. package/dist/cli/commands/generate.js +158 -0
  64. package/dist/cli/commands/index.d.ts +2 -1
  65. package/dist/cli/commands/index.d.ts.map +1 -1
  66. package/dist/cli/commands/index.js +100 -0
  67. package/dist/cli/commands/typeschema/generate.js +130 -0
  68. package/dist/cli/commands/typeschema.js +48 -0
  69. package/dist/cli/index.js +12 -8664
  70. package/dist/cli/utils/log.d.ts +2 -2
  71. package/dist/cli/utils/log.d.ts.map +1 -1
  72. package/dist/cli/utils/log.js +23 -0
  73. package/dist/cli/utils/prompts.js +224 -0
  74. package/dist/cli/utils/spinner.js +270 -0
  75. package/dist/config.js +703 -0
  76. package/dist/index.d.ts +2 -2
  77. package/dist/index.d.ts.map +1 -1
  78. package/dist/index.js +84 -40
  79. package/dist/logger.js +290 -0
  80. package/dist/typeschema/cache.d.ts +2 -2
  81. package/dist/typeschema/cache.d.ts.map +1 -1
  82. package/dist/typeschema/cache.js +285 -0
  83. package/dist/typeschema/core/binding.d.ts +1 -1
  84. package/dist/typeschema/core/binding.d.ts.map +1 -1
  85. package/dist/typeschema/core/binding.js +187 -0
  86. package/dist/typeschema/core/field-builder.d.ts +1 -1
  87. package/dist/typeschema/core/field-builder.d.ts.map +1 -1
  88. package/dist/typeschema/core/field-builder.js +259 -0
  89. package/dist/typeschema/core/identifier.js +117 -0
  90. package/dist/typeschema/core/nested-types.d.ts +1 -1
  91. package/dist/typeschema/core/nested-types.d.ts.map +1 -1
  92. package/dist/typeschema/core/nested-types.js +111 -0
  93. package/dist/typeschema/core/transformer.d.ts +2 -2
  94. package/dist/typeschema/core/transformer.d.ts.map +1 -1
  95. package/dist/typeschema/core/transformer.js +345 -0
  96. package/dist/typeschema/generator.d.ts +3 -3
  97. package/dist/typeschema/generator.d.ts.map +1 -1
  98. package/dist/typeschema/generator.js +352 -0
  99. package/dist/typeschema/index.d.ts +14 -14
  100. package/dist/typeschema/index.d.ts.map +1 -1
  101. package/dist/typeschema/index.js +92 -0
  102. package/dist/typeschema/parser.d.ts +2 -2
  103. package/dist/typeschema/parser.d.ts.map +1 -1
  104. package/dist/typeschema/parser.js +310 -0
  105. package/dist/typeschema/profile/processor.d.ts +1 -1
  106. package/dist/typeschema/profile/processor.d.ts.map +1 -1
  107. package/dist/typeschema/profile/processor.js +268 -0
  108. package/dist/typeschema/schema.js +456 -0
  109. package/dist/typeschema/type-schema.types.js +39 -0
  110. package/dist/typeschema/types.js +4 -0
  111. package/dist/typeschema/utils.d.ts +1 -1
  112. package/dist/typeschema/utils.d.ts.map +1 -1
  113. package/dist/typeschema/utils.js +13 -0
  114. package/dist/typeschema/value-set/processor.d.ts +1 -1
  115. package/dist/typeschema/value-set/processor.d.ts.map +1 -1
  116. package/dist/typeschema/value-set/processor.js +168 -0
  117. package/dist/utils/codegen-logger.js +204 -0
  118. package/dist/utils.js +42 -0
  119. package/package.json +15 -4
  120. package/dist/index-fgcebdva.js +0 -8515
@@ -0,0 +1,51 @@
1
+ /**
2
+ * High-Level API Module
3
+ *
4
+ * Main entry point for the atomic-codegen high-level API.
5
+ * Provides convenient access to all generators and utilities.
6
+ *
7
+ * @packageDocumentation
8
+ */
9
+ // Re-export core utilities
10
+ export { TypeSchemaCache, TypeSchemaGenerator, TypeSchemaParser, } from "../typeschema/index.js";
11
+ // Export main API builder and utilities
12
+ export { APIBuilder, createAPI, createAPIFromConfig, generateTypesFromFiles, generateTypesFromPackage, } from "./builder.js";
13
+ export { RestClientGenerator } from "./generators/rest-client.js";
14
+ // Export generator classes for advanced usage
15
+ export { TypeScriptGenerator } from "./generators/typescript.js";
16
+ /**
17
+ * Quick start examples:
18
+ *
19
+ * @example
20
+ * Generate TypeScript types from a FHIR package:
21
+ * ```typescript
22
+ * import { createAPI } from '@atomic-codegen/api';
23
+ *
24
+ * const result = await createAPI()
25
+ * .fromPackage('hl7.fhir.r4.core')
26
+ * .typescript()
27
+ * .generate();
28
+ * ```
29
+ *
30
+ * @example
31
+ * Generate TypeScript types from TypeSchema files:
32
+ * ```typescript
33
+ * import { createAPI } from '@atomic-codegen/api';
34
+ *
35
+ * const result = await createAPI()
36
+ * .fromFiles('./schemas/*.ndjson')
37
+ * .typescript()
38
+ * .generate();
39
+ * ```
40
+ *
41
+ * @example
42
+ * Build in-memory without writing files:
43
+ * ```typescript
44
+ * import { createAPI } from '@atomic-codegen/api';
45
+ *
46
+ * const results = await createAPI()
47
+ * .fromPackage('hl7.fhir.r4.core')
48
+ * .typescript()
49
+ * .build();
50
+ * ```
51
+ */
@@ -3,7 +3,7 @@
3
3
  *
4
4
  * Generate TypeScript types from TypeSchema files using the new high-level API
5
5
  */
6
- import type { Config } from "../../../config";
6
+ import type { Config } from "../../../config.js";
7
7
  /**
8
8
  * Generate TypeScript types from TypeSchema using the high-level API
9
9
  */
@@ -1 +1 @@
1
- {"version":3,"file":"typescript.d.ts","sourceRoot":"","sources":["../../../../src/cli/commands/generate/typescript.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAiC9C;;GAEG;AACH,wBAAsB,kBAAkB,CACvC,MAAM,EAAE,MAAM,EACd,SAAS,CAAC,EAAE,MAAM,GAChB,OAAO,CAAC,IAAI,CAAC,CAmDf"}
1
+ {"version":3,"file":"typescript.d.ts","sourceRoot":"","sources":["../../../../src/cli/commands/generate/typescript.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAiCjD;;GAEG;AACH,wBAAsB,kBAAkB,CACvC,MAAM,EAAE,MAAM,EACd,SAAS,CAAC,EAAE,MAAM,GAChB,OAAO,CAAC,IAAI,CAAC,CAmDf"}
@@ -0,0 +1,52 @@
1
+ /**
2
+ * Generate TypeScript Command
3
+ *
4
+ * Generate TypeScript types from TypeSchema files using the new high-level API
5
+ */
6
+ import { APIBuilder } from "../../../api/index.js";
7
+ import { createLogger } from "../../utils/log.js";
8
+ /**
9
+ * Generate TypeScript types from TypeSchema using the high-level API
10
+ */
11
+ export async function generateTypeScript(config, inputPath) {
12
+ const log = createLogger({
13
+ verbose: config.verbose,
14
+ prefix: "TypeScript",
15
+ });
16
+ log.step("Generating TypeScript types using high-level API");
17
+ // Create API builder with config options
18
+ const builder = new APIBuilder({
19
+ outputDir: config.outputDir,
20
+ verbose: config.verbose,
21
+ overwrite: config.overwrite,
22
+ validate: config.validate,
23
+ cache: config.cache,
24
+ });
25
+ // Load TypeSchema from input path if provided
26
+ if (inputPath) {
27
+ log.info(`Loading TypeSchema from: ${inputPath}`);
28
+ builder.fromFiles(inputPath);
29
+ }
30
+ // Configure TypeScript generation with options from config
31
+ builder.typescript(config.typescript || {});
32
+ // Add progress callback if verbose
33
+ if (config.verbose) {
34
+ builder.onProgress((phase, current, total, message) => {
35
+ const progress = Math.round((current / total) * 100);
36
+ log.progress(`[${phase}] ${progress}% - ${message || "Processing..."}`);
37
+ });
38
+ }
39
+ // Execute the generation
40
+ const result = await builder.generate();
41
+ if (result.success) {
42
+ log.success(`Generated ${result.filesGenerated.length} TypeScript files in ${result.duration.toFixed(2)}ms`);
43
+ if (result.warnings.length > 0) {
44
+ log.warn(`${result.warnings.length} warnings found`);
45
+ result.warnings.forEach((warning) => log.dim(` ${warning}`));
46
+ }
47
+ }
48
+ else {
49
+ log.error(`TypeScript generation failed: ${result.errors.join(", ")}`);
50
+ throw new Error(`TypeScript generation failed: ${result.errors.join(", ")}`);
51
+ }
52
+ }
@@ -1,22 +1,15 @@
1
1
  /**
2
- * Generate Command - High-Level API
2
+ * Generate Command - Config-Driven Generation
3
3
  *
4
- * Main generate command that uses the high-level API for end-to-end generation
4
+ * Main generate command that reads all configuration from the config file
5
+ * and executes generation based purely on config settings.
5
6
  */
6
7
  import type { CommandModule } from "yargs";
7
- import type { CLIArgv } from "./index";
8
+ import type { CLIArgv } from "./index.js";
8
9
  interface GenerateArgs extends CLIArgv {
9
- packages?: string[];
10
- input?: string;
11
- output?: string;
12
- typescript?: boolean;
13
- format?: "esm" | "cjs";
14
- "generate-index"?: boolean;
15
- "include-docs"?: boolean;
16
- "naming-convention"?: "PascalCase" | "camelCase";
17
10
  }
18
11
  /**
19
- * Main generate command using high-level API
12
+ * Main generate command - fully config-driven
20
13
  */
21
14
  export declare const generateCommand: CommandModule<{}, GenerateArgs>;
22
15
  export {};
@@ -1 +1 @@
1
- {"version":3,"file":"generate.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/generate.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAI3C,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAEvC,UAAU,YAAa,SAAQ,OAAO;IACrC,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;IACpB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,MAAM,CAAC,EAAE,KAAK,GAAG,KAAK,CAAC;IACvB,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,mBAAmB,CAAC,EAAE,YAAY,GAAG,WAAW,CAAC;CACjD;AAED;;GAEG;AACH,eAAO,MAAM,eAAe,EAAE,aAAa,CAAC,EAAE,EAAE,YAAY,CA0N3D,CAAC"}
1
+ {"version":3,"file":"generate.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/generate.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAI3C,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAE1C,UAAU,YAAa,SAAQ,OAAO;CAErC;AAED;;GAEG;AACH,eAAO,MAAM,eAAe,EAAE,aAAa,CAAC,EAAE,EAAE,YAAY,CAgL3D,CAAC"}
@@ -0,0 +1,158 @@
1
+ /**
2
+ * Generate Command - Config-Driven Generation
3
+ *
4
+ * Main generate command that reads all configuration from the config file
5
+ * and executes generation based purely on config settings.
6
+ */
7
+ import { existsSync } from "node:fs";
8
+ import { resolve } from "node:path";
9
+ import { APIBuilder } from "../../api/index.js";
10
+ import { CONFIG_FILE_NAMES, loadConfig } from "../../config.js";
11
+ import { createLogger, error, step, success, warn } from "../utils/log.js";
12
+ /**
13
+ * Main generate command - fully config-driven
14
+ */
15
+ export const generateCommand = {
16
+ command: "generate",
17
+ describe: "Generate code based on configuration file settings",
18
+ builder: (yargs) => yargs
19
+ .option("verbose", {
20
+ alias: "v",
21
+ type: "boolean",
22
+ default: false,
23
+ description: "Enable verbose output",
24
+ })
25
+ .example("$0 generate", "Generate code using settings from config file")
26
+ .example("$0 generate --verbose", "Generate with verbose output"),
27
+ handler: async (argv) => {
28
+ // Check if config file exists first
29
+ const workingDir = process.cwd();
30
+ const configPath = await findConfigFile(workingDir);
31
+ if (!configPath) {
32
+ const configFilesList = CONFIG_FILE_NAMES.map((name) => ` - ${name}`).join("\n");
33
+ error(`No configuration file found. Please create one of the following files in your project root:\n${configFilesList}\n\nExample atomic-codegen.config.ts:\n\n` +
34
+ `import { defineConfig } from '@atomic-ehr/codegen';\n\n` +
35
+ `export default defineConfig({\n` +
36
+ ` packages: ['hl7.fhir.r4.core@4.0.1'],\n` +
37
+ ` typescript: {\n` +
38
+ ` generateIndex: true\n` +
39
+ ` }\n` +
40
+ `});`);
41
+ process.exit(1);
42
+ }
43
+ // Load config file
44
+ const config = await loadConfig(workingDir);
45
+ const verbose = argv.verbose ?? config.verbose ?? false;
46
+ // Create logger for CLI command
47
+ const logger = createLogger({
48
+ verbose,
49
+ prefix: "Generate",
50
+ });
51
+ try {
52
+ step("Starting generation from config");
53
+ if (verbose) {
54
+ logger.info(`Config file: ${configPath}`);
55
+ logger.info(`Output directory: ${config.outputDir || "./generated"}`);
56
+ logger.info(`Packages: ${config.packages?.length || 0}`);
57
+ logger.info(`Files: ${config.files?.length || 0}`);
58
+ logger.info(`TypeScript generation: ${config.typescript ? "enabled" : "disabled"}`);
59
+ logger.info(`REST Client generation: ${config.restClient ? "enabled" : "disabled"}`);
60
+ }
61
+ // Create API builder with config options
62
+ const builder = new APIBuilder({
63
+ outputDir: config.outputDir || "./generated",
64
+ verbose,
65
+ overwrite: config.overwrite ?? true,
66
+ validate: config.validate ?? true,
67
+ cache: config.cache ?? true,
68
+ typeSchemaConfig: config.typeSchema,
69
+ logger,
70
+ });
71
+ // Load data sources from config
72
+ if (config.packages && config.packages.length > 0) {
73
+ logger.info(`Loading packages from config: ${config.packages.join(", ")}`);
74
+ for (const packageSpec of config.packages) {
75
+ const [name, version] = packageSpec.includes("@")
76
+ ? packageSpec.split("@")
77
+ : [packageSpec, undefined];
78
+ builder.fromPackage(name, version);
79
+ }
80
+ }
81
+ else if (config.files && config.files.length > 0) {
82
+ logger.info(`Loading files from config: ${config.files.join(", ")}`);
83
+ for (const file of config.files) {
84
+ builder.fromFiles(file);
85
+ }
86
+ }
87
+ else {
88
+ throw new Error("No data source specified in config. Please configure 'packages' or 'files' in your config file.");
89
+ }
90
+ // Configure generators from config
91
+ if (config.typescript) {
92
+ if (verbose) {
93
+ logger.info("Configuring TypeScript generation from config");
94
+ logger.debug(`Module format: ${config.typescript.moduleFormat || "esm"}`);
95
+ logger.debug(`Generate index: ${config.typescript.generateIndex ?? true}`);
96
+ logger.debug(`Include docs: ${config.typescript.includeDocuments ?? false}`);
97
+ logger.debug(`Naming convention: ${config.typescript.namingConvention || "PascalCase"}`);
98
+ }
99
+ builder.typescript(config.typescript);
100
+ }
101
+ if (config.restClient) {
102
+ if (verbose) {
103
+ logger.info("Configuring REST Client generation from config");
104
+ logger.debug(`Client name: ${config.restClient.clientName || "FHIRClient"}`);
105
+ logger.debug(`Include validation: ${config.restClient.includeValidation ?? false}`);
106
+ logger.debug(`Enhanced search: ${config.restClient.enhancedSearch ?? false}`);
107
+ }
108
+ builder.restClient(config.restClient);
109
+ }
110
+ // Check that at least one generator is configured
111
+ if (!config.typescript && !config.restClient) {
112
+ throw new Error("No generators configured. Please enable 'typescript' or 'restClient' in your config file.");
113
+ }
114
+ // Add progress callback if verbose
115
+ if (verbose) {
116
+ builder.onProgress((phase, current, total, message) => {
117
+ const progress = Math.round((current / total) * 100);
118
+ logger.progress(`[${phase}] ${progress}% - ${message || "Processing..."}`);
119
+ });
120
+ }
121
+ // Execute generation
122
+ logger.step("Executing generation...");
123
+ const result = await builder.generate();
124
+ if (result.success) {
125
+ success(`Generated ${result.filesGenerated.length} files in ${result.duration.toFixed(2)}ms`);
126
+ logger.dim(`Output directory: ${result.outputDir}`);
127
+ if (result.warnings.length > 0) {
128
+ for (const warning of result.warnings) {
129
+ warn(warning);
130
+ }
131
+ }
132
+ }
133
+ else {
134
+ error(`Generation failed with ${result.errors.length} errors`);
135
+ for (const err of result.errors) {
136
+ logger.dim(` ${err}`);
137
+ }
138
+ process.exit(1);
139
+ }
140
+ }
141
+ catch (err) {
142
+ error("Generation failed with unexpected error", err instanceof Error ? err : new Error(String(err)));
143
+ process.exit(1);
144
+ }
145
+ },
146
+ };
147
+ /**
148
+ * Helper function to find config file in the given directory
149
+ */
150
+ async function findConfigFile(startDir) {
151
+ for (const fileName of CONFIG_FILE_NAMES) {
152
+ const configPath = resolve(startDir, fileName);
153
+ if (existsSync(configPath)) {
154
+ return configPath;
155
+ }
156
+ }
157
+ return null;
158
+ }
@@ -4,6 +4,7 @@
4
4
  *
5
5
  * Modern CLI with subcommands for typeschema and code generation
6
6
  */
7
+ import yargs from "yargs";
7
8
  /**
8
9
  * CLI arguments interface
9
10
  */
@@ -15,7 +16,7 @@ export interface CLIArgv {
15
16
  /**
16
17
  * Main CLI entry point with subcommands
17
18
  */
18
- export declare function createCLI(): import("yargs").Argv<{
19
+ export declare function createCLI(): yargs.Argv<{
19
20
  verbose: boolean;
20
21
  } & {
21
22
  debug: boolean;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/index.ts"],"names":[],"mappings":";AAEA;;;;GAIG;AAQH;;GAEG;AACH,MAAM,WAAW,OAAO;IACvB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,KAAK,CAAC,EAAE,OAAO,CAAC;CAChB;AAaD;;GAEG;AACH,wBAAgB,SAAS;;;;;;GA6FxB;AAED;;GAEG;AACH,wBAAsB,MAAM,kBAG3B"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/index.ts"],"names":[],"mappings":";AAEA;;;;GAIG;AAEH,OAAO,KAAK,MAAM,OAAO,CAAC;AAM1B;;GAEG;AACH,MAAM,WAAW,OAAO;IACvB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,KAAK,CAAC,EAAE,OAAO,CAAC;CAChB;AAaD;;GAEG;AACH,wBAAgB,SAAS;;;;;;GA4ExB;AAED;;GAEG;AACH,wBAAsB,MAAM,kBAG3B"}
@@ -0,0 +1,100 @@
1
+ #!/usr/bin/env bun
2
+ /**
3
+ * Atomic Codegen CLI - New Command Structure
4
+ *
5
+ * Modern CLI with subcommands for typeschema and code generation
6
+ */
7
+ import yargs from "yargs";
8
+ import { hideBin } from "yargs/helpers";
9
+ import { configure, error, header } from "../utils/log.js";
10
+ import { generateCommand } from "./generate.js";
11
+ import { typeschemaCommand } from "./typeschema.js";
12
+ /**
13
+ * Middleware to setup logging
14
+ */
15
+ async function setupLoggingMiddleware(argv) {
16
+ // Configure the CliLogger with user preferences
17
+ configure({
18
+ verbose: argv.verbose || argv.debug,
19
+ timestamp: argv.debug,
20
+ });
21
+ }
22
+ /**
23
+ * Main CLI entry point with subcommands
24
+ */
25
+ export function createCLI() {
26
+ return yargs(hideBin(process.argv))
27
+ .scriptName("atomic-codegen")
28
+ .usage("$0 <command> [options]")
29
+ .middleware(setupLoggingMiddleware)
30
+ .command(typeschemaCommand)
31
+ .command(generateCommand)
32
+ .option("verbose", {
33
+ alias: "v",
34
+ type: "boolean",
35
+ description: "Enable verbose output",
36
+ default: false,
37
+ global: true,
38
+ })
39
+ .option("debug", {
40
+ alias: "d",
41
+ type: "boolean",
42
+ description: "Enable debug output with detailed logging",
43
+ default: false,
44
+ global: true,
45
+ })
46
+ .option("config", {
47
+ alias: "c",
48
+ type: "string",
49
+ description: "Path to configuration file (.atomic-codegen.json by default)",
50
+ global: true,
51
+ })
52
+ .demandCommand(0) // Allow 0 commands so we can handle it ourselves
53
+ .middleware((argv) => {
54
+ // Check if no command was provided (only the script name in argv._)
55
+ if (argv._.length === 0) {
56
+ // Show available commands instead of error
57
+ header("Welcome to Atomic Codegen!");
58
+ console.log("Available commands:");
59
+ console.log(" typeschema Generate, validate and merge TypeSchema files");
60
+ console.log(" generate Generate code based on configuration file");
61
+ console.log("\nUse 'atomic-codegen <command> --help' for more information about a command.");
62
+ console.log("\nQuick examples:");
63
+ console.log(" atomic-codegen typeschema generate hl7.fhir.r4.core@4.0.1 -o schemas.ndjson");
64
+ console.log(" atomic-codegen generate # Uses atomic-codegen.config.ts");
65
+ console.log("\nUse 'atomic-codegen --help' to see all options.");
66
+ process.exit(0);
67
+ }
68
+ })
69
+ .help()
70
+ .version("0.1.0")
71
+ .example("$0 generate", "Generate code using atomic-codegen.config.ts")
72
+ .example("$0 generate --verbose", "Generate with detailed progress output")
73
+ .example("$0 --config custom-config.ts generate", "Use custom configuration file")
74
+ .example("$0 typeschema generate hl7.fhir.r4.core@4.0.1 -o schemas.ndjson", "Generate TypeSchemas from FHIR package")
75
+ .fail((msg, err, _yargs) => {
76
+ if (err) {
77
+ error(err.message, err);
78
+ }
79
+ else {
80
+ error(msg);
81
+ }
82
+ error("\nUse --help for usage information");
83
+ process.exit(1);
84
+ })
85
+ .wrap(Math.min(120, process.stdout.columns || 80));
86
+ }
87
+ /**
88
+ * Run the CLI
89
+ */
90
+ export async function runCLI() {
91
+ const cli = createCLI();
92
+ await cli.parseAsync();
93
+ }
94
+ // Run CLI if this file is executed directly
95
+ if (import.meta.main) {
96
+ runCLI().catch((error) => {
97
+ error("Unexpected error:", error);
98
+ process.exit(1);
99
+ });
100
+ }
@@ -0,0 +1,130 @@
1
+ /**
2
+ * TypeSchema Generate Command
3
+ *
4
+ * Generate TypeSchema files from FHIR packages
5
+ */
6
+ import { mkdir, writeFile } from "node:fs/promises";
7
+ import { dirname } from "node:path";
8
+ import { loadConfig } from "../../../config.js";
9
+ import { TypeSchemaGenerator } from "../../../typeschema/generator.js";
10
+ import { complete, createLogger, list } from "../../utils/log.js";
11
+ /**
12
+ * Generate TypeSchema from FHIR packages
13
+ */
14
+ export const generateTypeschemaCommand = {
15
+ command: "generate <packages..>",
16
+ describe: "Generate TypeSchema files from FHIR packages",
17
+ builder: {
18
+ packages: {
19
+ type: "string",
20
+ array: true,
21
+ demandOption: true,
22
+ describe: "FHIR packages to process (e.g., hl7.fhir.r4.core@4.0.1)",
23
+ },
24
+ output: {
25
+ alias: "o",
26
+ type: "string",
27
+ describe: "Output file or directory",
28
+ default: "./schemas.ndjson",
29
+ },
30
+ format: {
31
+ alias: "f",
32
+ type: "string",
33
+ choices: ["ndjson", "json"],
34
+ default: "ndjson",
35
+ describe: "Output format for TypeSchema files",
36
+ },
37
+ treeshake: {
38
+ alias: "t",
39
+ type: "string",
40
+ array: true,
41
+ describe: "Only generate TypeSchemas for specific ResourceTypes (treeshaking)",
42
+ },
43
+ singleFile: {
44
+ alias: "s",
45
+ type: "boolean",
46
+ default: false,
47
+ describe: "Generate single TypeSchema file instead of multiple files (NDJSON format)",
48
+ },
49
+ verbose: {
50
+ alias: "v",
51
+ type: "boolean",
52
+ default: false,
53
+ describe: "Enable verbose output",
54
+ },
55
+ },
56
+ handler: async (argv) => {
57
+ const log = createLogger({
58
+ verbose: argv.verbose,
59
+ prefix: "TypeSchema",
60
+ });
61
+ try {
62
+ // Load configuration from file
63
+ const config = await loadConfig(process.cwd());
64
+ log.step("Generating TypeSchema from FHIR packages");
65
+ log.info(`Packages: ${argv.packages.join(", ")}`);
66
+ log.info(`Output: ${argv.output}`);
67
+ // Merge singleFile options: CLI args take precedence over config file
68
+ const singleFileOption = argv.singleFile !== undefined
69
+ ? argv.singleFile
70
+ : (config.typeSchema?.singleFile ?? false);
71
+ const outputFormat = singleFileOption ? "ndjson" : argv.format;
72
+ log.debug(`Format: ${outputFormat}${singleFileOption && argv.format === "json" ? " (forced from json due to singleFile)" : ""}`);
73
+ // Merge treeshake options: CLI args take precedence over config file
74
+ const treeshakeOptions = argv.treeshake && argv.treeshake.length > 0
75
+ ? argv.treeshake
76
+ : config.typeSchema?.treeshake;
77
+ if (treeshakeOptions && treeshakeOptions.length > 0) {
78
+ log.info(`Treeshaking enabled for ResourceTypes: ${treeshakeOptions.join(", ")}`);
79
+ }
80
+ if (singleFileOption) {
81
+ log.info("Single file output enabled (NDJSON format)");
82
+ }
83
+ const startTime = Date.now();
84
+ // Create TypeSchema generator
85
+ const generator = new TypeSchemaGenerator({
86
+ verbose: argv.verbose,
87
+ treeshake: treeshakeOptions,
88
+ });
89
+ // Generate schemas from all packages
90
+ const allSchemas = [];
91
+ for (const packageSpec of argv.packages) {
92
+ const [name, version] = packageSpec.includes("@")
93
+ ? packageSpec.split("@")
94
+ : [packageSpec, undefined];
95
+ log.progress(`Processing package: ${name}${version ? `@${version}` : ""}`);
96
+ const schemas = await generator.generateFromPackage(name, version);
97
+ allSchemas.push(...schemas);
98
+ }
99
+ if (allSchemas.length === 0) {
100
+ throw new Error("No schemas were generated from the specified packages");
101
+ }
102
+ // Use the output format determined earlier
103
+ // Ensure output directory exists
104
+ const outputPath = argv.output;
105
+ await mkdir(dirname(outputPath), { recursive: true });
106
+ // Format and write the schemas
107
+ let content;
108
+ if (outputFormat === "json") {
109
+ content = JSON.stringify(allSchemas, null, 2);
110
+ }
111
+ else {
112
+ // NDJSON format (default for single file)
113
+ content = allSchemas.map((schema) => JSON.stringify(schema)).join("\n");
114
+ }
115
+ await writeFile(outputPath, content, "utf-8");
116
+ const duration = Date.now() - startTime;
117
+ complete(`Generated ${allSchemas.length} TypeSchema definitions`, duration, { schemas: allSchemas.length });
118
+ log.dim(`Output: ${outputPath}`);
119
+ if (argv.verbose) {
120
+ log.debug("Generated schemas:");
121
+ const schemaNames = allSchemas.map((schema) => `${schema.identifier?.name || "Unknown"} (${schema.identifier?.kind || "unknown"})`);
122
+ list(schemaNames);
123
+ }
124
+ }
125
+ catch (error) {
126
+ log.error("Failed to generate TypeSchema", error instanceof Error ? error : new Error(String(error)));
127
+ process.exit(1);
128
+ }
129
+ },
130
+ };
@@ -0,0 +1,48 @@
1
+ /**
2
+ * TypeSchema Commands
3
+ *
4
+ * Commands for validating and managing TypeSchema files
5
+ */
6
+ import { error, info, list } from "../utils/log.js";
7
+ import { generateTypeschemaCommand } from "./typeschema/generate.js";
8
+ /**
9
+ * TypeSchema command group
10
+ */
11
+ export const typeschemaCommand = {
12
+ command: "typeschema [subcommand]",
13
+ describe: "TypeSchema operations - generate, validate and merge schemas",
14
+ builder: (yargs) => {
15
+ return yargs
16
+ .command(generateTypeschemaCommand)
17
+ .help()
18
+ .example("$0 typeschema generate hl7.fhir.r4.core@4.0.1", "Generate TypeSchema from FHIR R4 core package");
19
+ },
20
+ handler: (argv) => {
21
+ // If no subcommand provided, show available subcommands
22
+ if (!argv.subcommand && argv._.length === 1) {
23
+ info("Available typeschema subcommands:");
24
+ list(["generate Generate TypeSchema files from FHIR packages"]);
25
+ console.log("\nUse 'atomic-codegen typeschema <subcommand> --help' for more information about a subcommand.");
26
+ console.log("\nExamples:");
27
+ list([
28
+ "atomic-codegen typeschema generate hl7.fhir.r4.core@4.0.1 -o schemas.ndjson",
29
+ "atomic-codegen typeschema validate schemas.ndjson",
30
+ "atomic-codegen typeschema merge schema1.ndjson schema2.ndjson -o merged.ndjson",
31
+ ]);
32
+ return;
33
+ }
34
+ // If unknown subcommand provided, show error and available commands
35
+ if (argv.subcommand &&
36
+ !["generate", "validate", "merge"].includes(argv.subcommand)) {
37
+ error(`Unknown typeschema subcommand: ${argv.subcommand}\n`);
38
+ info("Available typeschema subcommands:");
39
+ list([
40
+ "generate Generate TypeSchema files from FHIR packages",
41
+ "validate Validate TypeSchema files for correctness and consistency",
42
+ "merge Merge multiple TypeSchema files into a single file",
43
+ ]);
44
+ console.log("\nUse 'atomic-codegen typeschema <subcommand> --help' for more information about a subcommand.");
45
+ process.exit(1);
46
+ }
47
+ },
48
+ };