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

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 (90) hide show
  1. package/dist/cli/index.js +45 -124
  2. package/dist/index.d.ts +2130 -62
  3. package/dist/index.js +5865 -84
  4. package/dist/index.js.map +1 -0
  5. package/package.json +3 -7
  6. package/dist/api/builder.d.ts +0 -154
  7. package/dist/api/builder.js +0 -341
  8. package/dist/api/generators/base/BaseGenerator.d.ts +0 -186
  9. package/dist/api/generators/base/BaseGenerator.js +0 -565
  10. package/dist/api/generators/base/FileManager.d.ts +0 -88
  11. package/dist/api/generators/base/FileManager.js +0 -202
  12. package/dist/api/generators/base/PythonTypeMapper.d.ts +0 -16
  13. package/dist/api/generators/base/PythonTypeMapper.js +0 -71
  14. package/dist/api/generators/base/TemplateEngine.d.ts +0 -126
  15. package/dist/api/generators/base/TemplateEngine.js +0 -133
  16. package/dist/api/generators/base/TypeMapper.d.ts +0 -129
  17. package/dist/api/generators/base/TypeMapper.js +0 -153
  18. package/dist/api/generators/base/TypeScriptTypeMapper.d.ts +0 -51
  19. package/dist/api/generators/base/TypeScriptTypeMapper.js +0 -232
  20. package/dist/api/generators/base/builders/DirectoryBuilder.d.ts +0 -99
  21. package/dist/api/generators/base/builders/DirectoryBuilder.js +0 -215
  22. package/dist/api/generators/base/builders/FileBuilder.d.ts +0 -160
  23. package/dist/api/generators/base/builders/FileBuilder.js +0 -406
  24. package/dist/api/generators/base/builders/IndexBuilder.d.ts +0 -126
  25. package/dist/api/generators/base/builders/IndexBuilder.js +0 -290
  26. package/dist/api/generators/base/enhanced-errors.d.ts +0 -84
  27. package/dist/api/generators/base/enhanced-errors.js +0 -259
  28. package/dist/api/generators/base/error-handler.d.ts +0 -89
  29. package/dist/api/generators/base/error-handler.js +0 -243
  30. package/dist/api/generators/base/errors.d.ts +0 -251
  31. package/dist/api/generators/base/errors.js +0 -692
  32. package/dist/api/generators/base/index.d.ts +0 -99
  33. package/dist/api/generators/base/index.js +0 -160
  34. package/dist/api/generators/base/types.d.ts +0 -433
  35. package/dist/api/generators/base/types.js +0 -12
  36. package/dist/api/generators/types.d.ts +0 -53
  37. package/dist/api/generators/types.js +0 -4
  38. package/dist/api/generators/typescript.d.ts +0 -190
  39. package/dist/api/generators/typescript.js +0 -819
  40. package/dist/api/index.d.ts +0 -51
  41. package/dist/api/index.js +0 -50
  42. package/dist/cli/commands/generate/typescript.d.ts +0 -10
  43. package/dist/cli/commands/generate/typescript.js +0 -52
  44. package/dist/cli/commands/generate.d.ts +0 -15
  45. package/dist/cli/commands/generate.js +0 -159
  46. package/dist/cli/commands/index.d.ts +0 -29
  47. package/dist/cli/commands/index.js +0 -100
  48. package/dist/cli/commands/typeschema/generate.d.ts +0 -19
  49. package/dist/cli/commands/typeschema/generate.js +0 -124
  50. package/dist/cli/commands/typeschema.d.ts +0 -10
  51. package/dist/cli/commands/typeschema.js +0 -47
  52. package/dist/cli/index.d.ts +0 -9
  53. package/dist/cli/utils/log.d.ts +0 -10
  54. package/dist/cli/utils/log.js +0 -23
  55. package/dist/cli/utils/prompts.d.ts +0 -56
  56. package/dist/cli/utils/prompts.js +0 -202
  57. package/dist/cli/utils/spinner.d.ts +0 -110
  58. package/dist/cli/utils/spinner.js +0 -266
  59. package/dist/config.d.ts +0 -217
  60. package/dist/config.js +0 -591
  61. package/dist/logger.d.ts +0 -157
  62. package/dist/logger.js +0 -281
  63. package/dist/typeschema/cache.d.ts +0 -80
  64. package/dist/typeschema/cache.js +0 -239
  65. package/dist/typeschema/core/binding.d.ts +0 -11
  66. package/dist/typeschema/core/binding.js +0 -143
  67. package/dist/typeschema/core/field-builder.d.ts +0 -12
  68. package/dist/typeschema/core/field-builder.js +0 -123
  69. package/dist/typeschema/core/identifier.d.ts +0 -13
  70. package/dist/typeschema/core/identifier.js +0 -94
  71. package/dist/typeschema/core/nested-types.d.ts +0 -9
  72. package/dist/typeschema/core/nested-types.js +0 -93
  73. package/dist/typeschema/core/transformer.d.ts +0 -11
  74. package/dist/typeschema/core/transformer.js +0 -235
  75. package/dist/typeschema/generator.d.ts +0 -36
  76. package/dist/typeschema/generator.js +0 -243
  77. package/dist/typeschema/index.d.ts +0 -15
  78. package/dist/typeschema/index.js +0 -15
  79. package/dist/typeschema/parser.d.ts +0 -79
  80. package/dist/typeschema/parser.js +0 -274
  81. package/dist/typeschema/profile/processor.d.ts +0 -14
  82. package/dist/typeschema/profile/processor.js +0 -261
  83. package/dist/typeschema/register.d.ts +0 -21
  84. package/dist/typeschema/register.js +0 -117
  85. package/dist/typeschema/types.d.ts +0 -240
  86. package/dist/typeschema/types.js +0 -19
  87. package/dist/utils/codegen-logger.d.ts +0 -102
  88. package/dist/utils/codegen-logger.js +0 -196
  89. package/dist/utils.d.ts +0 -22
  90. package/dist/utils.js +0 -42
@@ -1,51 +0,0 @@
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
- export { TypeSchemaCache, TypeSchemaGenerator, TypeSchemaParser, } from "@typeschema/index";
10
- export type { Field as TypeSchemaField, Identifier as TypeSchemaIdentifier, PackageMeta as PackageInfo, TypeSchema, } from "@typeschema/types";
11
- export type { APIBuilderOptions, GenerationResult, ProgressCallback, } from "./builder";
12
- export { APIBuilder, createAPI, createAPIFromConfig, generateTypesFromFiles, generateTypesFromPackage, } from "./builder";
13
- export type { GeneratedFile } from "./generators/base/index";
14
- export type { TypeScriptGeneratorOptions } from "./generators/typescript";
15
- export { TypeScriptGenerator } from "./generators/typescript";
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
- */
package/dist/api/index.js DELETED
@@ -1,50 +0,0 @@
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";
11
- // Export main API builder and utilities
12
- export { APIBuilder, createAPI, createAPIFromConfig, generateTypesFromFiles, generateTypesFromPackage, } from "./builder";
13
- // Export generator classes for advanced usage
14
- export { TypeScriptGenerator } from "./generators/typescript";
15
- /**
16
- * Quick start examples:
17
- *
18
- * @example
19
- * Generate TypeScript types from a FHIR package:
20
- * ```typescript
21
- * import { createAPI } from '@atomic-codegen/api';
22
- *
23
- * const result = await createAPI()
24
- * .fromPackage('hl7.fhir.r4.core')
25
- * .typescript()
26
- * .generate();
27
- * ```
28
- *
29
- * @example
30
- * Generate TypeScript types from TypeSchema files:
31
- * ```typescript
32
- * import { createAPI } from '@atomic-codegen/api';
33
- *
34
- * const result = await createAPI()
35
- * .fromFiles('./schemas/*.ndjson')
36
- * .typescript()
37
- * .generate();
38
- * ```
39
- *
40
- * @example
41
- * Build in-memory without writing files:
42
- * ```typescript
43
- * import { createAPI } from '@atomic-codegen/api';
44
- *
45
- * const results = await createAPI()
46
- * .fromPackage('hl7.fhir.r4.core')
47
- * .typescript()
48
- * .build();
49
- * ```
50
- */
@@ -1,10 +0,0 @@
1
- /**
2
- * Generate TypeScript Command
3
- *
4
- * Generate TypeScript types from TypeSchema files using the new high-level API
5
- */
6
- import type { Config } from "../../../config";
7
- /**
8
- * Generate TypeScript types from TypeSchema using the high-level API
9
- */
10
- export declare function generateTypeScript(config: Config, inputPath?: string): Promise<void>;
@@ -1,52 +0,0 @@
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";
7
- import { createLogger } from "../../utils/log";
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,15 +0,0 @@
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 type { CommandModule } from "yargs";
8
- import type { CLIArgv } from "./index";
9
- interface GenerateArgs extends CLIArgv {
10
- }
11
- /**
12
- * Main generate command - fully config-driven
13
- */
14
- export declare const generateCommand: CommandModule<Record<string, unknown>, GenerateArgs>;
15
- export {};
@@ -1,159 +0,0 @@
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";
10
- import { CONFIG_FILE_NAMES, loadConfig } from "../../config";
11
- import { createLogger, error, step, success, warn } from "../utils/log";
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 for old command syntax and provide helpful error
29
- if (argv._.length > 1) {
30
- const extraArgs = argv._.slice(1).join(" ");
31
- error(`Invalid syntax: 'atomic-codegen generate ${extraArgs}'\n\n` +
32
- `The CLI has been simplified and no longer uses subcommands.\n\n` +
33
- `✅ Use: atomic-codegen generate\n` +
34
- `❌ Old: atomic-codegen generate typescript\n\n` +
35
- `All generation settings are now configured in your config file.\n` +
36
- `Create an atomic-codegen.config.ts file to get started.`);
37
- process.exit(1);
38
- }
39
- // Check if config file exists first
40
- const workingDir = process.cwd();
41
- const configPath = await findConfigFile(workingDir);
42
- if (!configPath) {
43
- const configFilesList = CONFIG_FILE_NAMES.map((name) => ` - ${name}`).join("\n");
44
- 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` +
45
- `import { defineConfig } from '@atomic-ehr/codegen';\n\n` +
46
- `export default defineConfig({\n` +
47
- ` packages: ['hl7.fhir.r4.core@4.0.1'],\n` +
48
- ` typescript: {\n` +
49
- ` generateIndex: true\n` +
50
- ` }\n` +
51
- `});`);
52
- process.exit(1);
53
- }
54
- // Load config file
55
- const config = await loadConfig(workingDir);
56
- const verbose = argv.verbose ?? config.verbose ?? false;
57
- // Create logger for CLI command
58
- const logger = createLogger({
59
- verbose,
60
- prefix: "Generate",
61
- });
62
- try {
63
- step("Starting generation from config");
64
- if (verbose) {
65
- logger.info(`Config file: ${configPath}`);
66
- logger.info(`Output directory: ${config.outputDir || "./generated"}`);
67
- logger.info(`Packages: ${config.packages?.length || 0}`);
68
- logger.info(`Files: ${config.files?.length || 0}`);
69
- logger.info(`TypeScript generation: ${config.typescript ? "enabled" : "disabled"}`);
70
- }
71
- // Create API builder with config options
72
- const builder = new APIBuilder({
73
- outputDir: config.outputDir || "./generated",
74
- verbose,
75
- overwrite: config.overwrite ?? true,
76
- validate: config.validate ?? true,
77
- cache: config.cache ?? true,
78
- typeSchemaConfig: config.typeSchema,
79
- logger,
80
- });
81
- // Load data sources from config
82
- if (config.packages && config.packages.length > 0) {
83
- logger.info(`Loading packages from config: ${config.packages.join(", ")}`);
84
- for (const packageSpec of config.packages) {
85
- const [name, version] = packageSpec.includes("@")
86
- ? packageSpec.split("@")
87
- : [packageSpec, undefined];
88
- builder.fromPackage(name, version);
89
- }
90
- }
91
- else if (config.files && config.files.length > 0) {
92
- logger.info(`Loading files from config: ${config.files.join(", ")}`);
93
- for (const file of config.files) {
94
- builder.fromFiles(file);
95
- }
96
- }
97
- else {
98
- throw new Error("No data source specified in config. Please configure 'packages' or 'files' in your config file.");
99
- }
100
- // Configure generators from config
101
- if (config.typescript) {
102
- if (verbose) {
103
- logger.info("Configuring TypeScript generation from config");
104
- logger.debug(`Module format: ${config.typescript.moduleFormat || "esm"}`);
105
- logger.debug(`Generate index: ${config.typescript.generateIndex ?? true}`);
106
- logger.debug(`Include docs: ${config.typescript.includeDocuments ?? false}`);
107
- logger.debug(`Naming convention: ${config.typescript.namingConvention || "PascalCase"}`);
108
- }
109
- builder.typescript(config.typescript);
110
- }
111
- // Check that at least one generator is configured
112
- if (!config.typescript) {
113
- throw new Error("No generators configured. Please enable 'typescript' in your config file.");
114
- }
115
- // Add progress callback if verbose
116
- if (verbose) {
117
- builder.onProgress((phase, current, total, message) => {
118
- const progress = Math.round((current / total) * 100);
119
- logger.progress(`[${phase}] ${progress}% - ${message || "Processing..."}`);
120
- });
121
- }
122
- // Execute generation
123
- logger.step("Executing generation...");
124
- const result = await builder.generate();
125
- if (result.success) {
126
- success(`Generated ${result.filesGenerated.length} files in ${result.duration.toFixed(2)}ms`);
127
- logger.dim(`Output directory: ${result.outputDir}`);
128
- if (result.warnings.length > 0) {
129
- for (const warning of result.warnings) {
130
- warn(warning);
131
- }
132
- }
133
- }
134
- else {
135
- error(`Generation failed with ${result.errors.length} errors`);
136
- for (const err of result.errors) {
137
- logger.dim(` ${err}`);
138
- }
139
- process.exit(1);
140
- }
141
- }
142
- catch (err) {
143
- error("Generation failed with unexpected error", err instanceof Error ? err : new Error(String(err)));
144
- process.exit(1);
145
- }
146
- },
147
- };
148
- /**
149
- * Helper function to find config file in the given directory
150
- */
151
- async function findConfigFile(startDir) {
152
- for (const fileName of CONFIG_FILE_NAMES) {
153
- const configPath = resolve(startDir, fileName);
154
- if (existsSync(configPath)) {
155
- return configPath;
156
- }
157
- }
158
- return null;
159
- }
@@ -1,29 +0,0 @@
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
- /**
9
- * CLI arguments interface
10
- */
11
- export interface CLIArgv {
12
- config?: string;
13
- verbose?: boolean;
14
- debug?: boolean;
15
- }
16
- /**
17
- * Main CLI entry point with subcommands
18
- */
19
- export declare function createCLI(): yargs.Argv<{
20
- verbose: boolean;
21
- } & {
22
- debug: boolean;
23
- } & {
24
- config: string | undefined;
25
- }>;
26
- /**
27
- * Run the CLI
28
- */
29
- export declare function runCLI(): Promise<void>;
@@ -1,100 +0,0 @@
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";
10
- import { generateCommand } from "./generate";
11
- import { typeschemaCommand } from "./typeschema";
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
- }
@@ -1,19 +0,0 @@
1
- /**
2
- * TypeSchema Generate Command
3
- *
4
- * Generate TypeSchema files from FHIR packages
5
- */
6
- import type { CommandModule } from "yargs";
7
- interface GenerateTypeschemaArgs {
8
- packages: string[];
9
- output?: string;
10
- format?: "ndjson" | "json";
11
- verbose?: boolean;
12
- treeshake?: string[];
13
- singleFile?: boolean;
14
- }
15
- /**
16
- * Generate TypeSchema from FHIR packages
17
- */
18
- export declare const generateTypeschemaCommand: CommandModule<Record<string, unknown>, GenerateTypeschemaArgs>;
19
- export {};
@@ -1,124 +0,0 @@
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 { TypeSchemaGenerator } from "@typeschema/generator";
9
- import { loadConfig } from "../../../config";
10
- import { complete, createLogger, list } from "../../utils/log";
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 ? argv.singleFile : (config.typeSchema?.singleFile ?? false);
69
- const outputFormat = singleFileOption ? "ndjson" : argv.format;
70
- log.debug(`Format: ${outputFormat}${singleFileOption && argv.format === "json" ? " (forced from json due to singleFile)" : ""}`);
71
- // Merge treeshake options: CLI args take precedence over config file
72
- const treeshakeOptions = argv.treeshake && argv.treeshake.length > 0 ? argv.treeshake : config.typeSchema?.treeshake;
73
- if (treeshakeOptions && treeshakeOptions.length > 0) {
74
- log.info(`Treeshaking enabled for ResourceTypes: ${treeshakeOptions.join(", ")}`);
75
- }
76
- if (singleFileOption) {
77
- log.info("Single file output enabled (NDJSON format)");
78
- }
79
- const startTime = Date.now();
80
- // Create TypeSchema generator
81
- const generator = new TypeSchemaGenerator({
82
- verbose: argv.verbose,
83
- treeshake: treeshakeOptions,
84
- });
85
- // Generate schemas from all packages
86
- const allSchemas = [];
87
- for (const packageSpec of argv.packages) {
88
- const [name, version] = packageSpec.includes("@") ? packageSpec.split("@") : [packageSpec, undefined];
89
- log.progress(`Processing package: ${name}${version ? `@${version}` : ""}`);
90
- const schemas = await generator.generateFromPackage(name, version);
91
- allSchemas.push(...schemas);
92
- }
93
- if (allSchemas.length === 0) {
94
- throw new Error("No schemas were generated from the specified packages");
95
- }
96
- // Use the output format determined earlier
97
- // Ensure output directory exists
98
- const outputPath = argv.output;
99
- await mkdir(dirname(outputPath), { recursive: true });
100
- // Format and write the schemas
101
- let content;
102
- if (outputFormat === "json") {
103
- content = JSON.stringify(allSchemas, null, 2);
104
- }
105
- else {
106
- // NDJSON format (default for single file)
107
- content = allSchemas.map((schema) => JSON.stringify(schema)).join("\n");
108
- }
109
- await writeFile(outputPath, content, "utf-8");
110
- const duration = Date.now() - startTime;
111
- complete(`Generated ${allSchemas.length} TypeSchema definitions`, duration, { schemas: allSchemas.length });
112
- log.dim(`Output: ${outputPath}`);
113
- if (argv.verbose) {
114
- log.debug("Generated schemas:");
115
- const schemaNames = allSchemas.map((schema) => `${schema.identifier?.name || "Unknown"} (${schema.identifier?.kind || "unknown"})`);
116
- list(schemaNames);
117
- }
118
- }
119
- catch (error) {
120
- log.error("Failed to generate TypeSchema", error instanceof Error ? error : new Error(String(error)));
121
- process.exit(1);
122
- }
123
- },
124
- };
@@ -1,10 +0,0 @@
1
- /**
2
- * TypeSchema Commands
3
- *
4
- * Commands for validating and managing TypeSchema files
5
- */
6
- import type { CommandModule } from "yargs";
7
- /**
8
- * TypeSchema command group
9
- */
10
- export declare const typeschemaCommand: CommandModule;
@@ -1,47 +0,0 @@
1
- /**
2
- * TypeSchema Commands
3
- *
4
- * Commands for validating and managing TypeSchema files
5
- */
6
- import { error, info, list } from "../utils/log";
7
- import { generateTypeschemaCommand } from "./typeschema/generate";
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 && !["generate", "validate", "merge"].includes(argv.subcommand)) {
36
- error(`Unknown typeschema subcommand: ${argv.subcommand}\n`);
37
- info("Available typeschema subcommands:");
38
- list([
39
- "generate Generate TypeSchema files from FHIR packages",
40
- "validate Validate TypeSchema files for correctness and consistency",
41
- "merge Merge multiple TypeSchema files into a single file",
42
- ]);
43
- console.log("\nUse 'atomic-codegen typeschema <subcommand> --help' for more information about a subcommand.");
44
- process.exit(1);
45
- }
46
- },
47
- };