@atomic-ehr/codegen 0.0.1-canary.20251006070905.fb6ed98 → 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.
- package/dist/cli/index.js +45 -124
- package/dist/index.d.ts +2130 -62
- package/dist/index.js +5865 -84
- package/dist/index.js.map +1 -0
- package/package.json +3 -7
- package/dist/api/builder.d.ts +0 -154
- package/dist/api/builder.js +0 -341
- package/dist/api/generators/base/BaseGenerator.d.ts +0 -186
- package/dist/api/generators/base/BaseGenerator.js +0 -565
- package/dist/api/generators/base/FileManager.d.ts +0 -88
- package/dist/api/generators/base/FileManager.js +0 -202
- package/dist/api/generators/base/PythonTypeMapper.d.ts +0 -16
- package/dist/api/generators/base/PythonTypeMapper.js +0 -71
- package/dist/api/generators/base/TemplateEngine.d.ts +0 -126
- package/dist/api/generators/base/TemplateEngine.js +0 -133
- package/dist/api/generators/base/TypeMapper.d.ts +0 -129
- package/dist/api/generators/base/TypeMapper.js +0 -153
- package/dist/api/generators/base/TypeScriptTypeMapper.d.ts +0 -51
- package/dist/api/generators/base/TypeScriptTypeMapper.js +0 -232
- package/dist/api/generators/base/builders/DirectoryBuilder.d.ts +0 -99
- package/dist/api/generators/base/builders/DirectoryBuilder.js +0 -215
- package/dist/api/generators/base/builders/FileBuilder.d.ts +0 -160
- package/dist/api/generators/base/builders/FileBuilder.js +0 -406
- package/dist/api/generators/base/builders/IndexBuilder.d.ts +0 -126
- package/dist/api/generators/base/builders/IndexBuilder.js +0 -290
- package/dist/api/generators/base/enhanced-errors.d.ts +0 -84
- package/dist/api/generators/base/enhanced-errors.js +0 -259
- package/dist/api/generators/base/error-handler.d.ts +0 -89
- package/dist/api/generators/base/error-handler.js +0 -243
- package/dist/api/generators/base/errors.d.ts +0 -251
- package/dist/api/generators/base/errors.js +0 -692
- package/dist/api/generators/base/index.d.ts +0 -99
- package/dist/api/generators/base/index.js +0 -160
- package/dist/api/generators/base/types.d.ts +0 -433
- package/dist/api/generators/base/types.js +0 -12
- package/dist/api/generators/types.d.ts +0 -53
- package/dist/api/generators/types.js +0 -4
- package/dist/api/generators/typescript.d.ts +0 -190
- package/dist/api/generators/typescript.js +0 -819
- package/dist/api/index.d.ts +0 -51
- package/dist/api/index.js +0 -50
- package/dist/cli/commands/generate/typescript.d.ts +0 -10
- package/dist/cli/commands/generate/typescript.js +0 -52
- package/dist/cli/commands/generate.d.ts +0 -15
- package/dist/cli/commands/generate.js +0 -159
- package/dist/cli/commands/index.d.ts +0 -29
- package/dist/cli/commands/index.js +0 -100
- package/dist/cli/commands/typeschema/generate.d.ts +0 -19
- package/dist/cli/commands/typeschema/generate.js +0 -124
- package/dist/cli/commands/typeschema.d.ts +0 -10
- package/dist/cli/commands/typeschema.js +0 -47
- package/dist/cli/index.d.ts +0 -9
- package/dist/cli/utils/log.d.ts +0 -10
- package/dist/cli/utils/log.js +0 -23
- package/dist/cli/utils/prompts.d.ts +0 -56
- package/dist/cli/utils/prompts.js +0 -202
- package/dist/cli/utils/spinner.d.ts +0 -110
- package/dist/cli/utils/spinner.js +0 -266
- package/dist/config.d.ts +0 -217
- package/dist/config.js +0 -591
- package/dist/logger.d.ts +0 -157
- package/dist/logger.js +0 -281
- package/dist/typeschema/cache.d.ts +0 -80
- package/dist/typeschema/cache.js +0 -239
- package/dist/typeschema/core/binding.d.ts +0 -11
- package/dist/typeschema/core/binding.js +0 -143
- package/dist/typeschema/core/field-builder.d.ts +0 -12
- package/dist/typeschema/core/field-builder.js +0 -123
- package/dist/typeschema/core/identifier.d.ts +0 -13
- package/dist/typeschema/core/identifier.js +0 -94
- package/dist/typeschema/core/nested-types.d.ts +0 -9
- package/dist/typeschema/core/nested-types.js +0 -94
- package/dist/typeschema/core/transformer.d.ts +0 -11
- package/dist/typeschema/core/transformer.js +0 -235
- package/dist/typeschema/generator.d.ts +0 -43
- package/dist/typeschema/generator.js +0 -264
- package/dist/typeschema/index.d.ts +0 -15
- package/dist/typeschema/index.js +0 -15
- package/dist/typeschema/parser.d.ts +0 -79
- package/dist/typeschema/parser.js +0 -274
- package/dist/typeschema/profile/processor.d.ts +0 -14
- package/dist/typeschema/profile/processor.js +0 -262
- package/dist/typeschema/register.d.ts +0 -21
- package/dist/typeschema/register.js +0 -117
- package/dist/typeschema/types.d.ts +0 -240
- package/dist/typeschema/types.js +0 -19
- package/dist/utils/codegen-logger.d.ts +0 -102
- package/dist/utils/codegen-logger.js +0 -196
- package/dist/utils.d.ts +0 -22
- package/dist/utils.js +0 -42
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atomic-ehr/codegen",
|
|
3
|
-
"version": "0.0.1-canary.
|
|
3
|
+
"version": "0.0.1-canary.20251006094042.7f0be72",
|
|
4
4
|
"description": "Code generation tools for FHIR resources and TypeSchema definitions",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"fhir",
|
|
@@ -17,11 +17,6 @@
|
|
|
17
17
|
"types": "./dist/index.d.ts",
|
|
18
18
|
"import": "./dist/index.js",
|
|
19
19
|
"default": "./dist/index.js"
|
|
20
|
-
},
|
|
21
|
-
"./cli": {
|
|
22
|
-
"types": "./dist/cli/index.d.ts",
|
|
23
|
-
"import": "./dist/cli/index.js",
|
|
24
|
-
"default": "./dist/cli/index.js"
|
|
25
20
|
}
|
|
26
21
|
},
|
|
27
22
|
"type": "module",
|
|
@@ -43,7 +38,7 @@
|
|
|
43
38
|
"test:verbose": "bun test --verbose",
|
|
44
39
|
"test:helpers": "bun test test/helpers/",
|
|
45
40
|
"test:quick": "bun test test/unit/ --timeout 5000",
|
|
46
|
-
"build": "
|
|
41
|
+
"build": "tsup",
|
|
47
42
|
"typecheck": "bunx tsc --noEmit",
|
|
48
43
|
"lint": "biome check --write",
|
|
49
44
|
"format": "biome format --write",
|
|
@@ -70,6 +65,7 @@
|
|
|
70
65
|
"@types/node": "^22.17.1",
|
|
71
66
|
"@types/yargs": "^17.0.33",
|
|
72
67
|
"ts-prune": "^0.10.3",
|
|
68
|
+
"tsup": "^8.5.0",
|
|
73
69
|
"typescript": "^5.9.2"
|
|
74
70
|
},
|
|
75
71
|
"dependencies": {
|
package/dist/api/builder.d.ts
DELETED
|
@@ -1,154 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* High-Level API Builder
|
|
3
|
-
*
|
|
4
|
-
* Provides a fluent, chainable API for common codegen use cases with pre-built generators.
|
|
5
|
-
* This builder pattern allows users to configure generation in a declarative way.
|
|
6
|
-
*/
|
|
7
|
-
import type { CanonicalManager } from "@atomic-ehr/fhir-canonical-manager";
|
|
8
|
-
import type { TypeSchema } from "@typeschema/types";
|
|
9
|
-
import type { Config, TypeSchemaConfig } from "../config";
|
|
10
|
-
import type { CodegenLogger } from "../utils/codegen-logger";
|
|
11
|
-
/**
|
|
12
|
-
* Configuration options for the API builder
|
|
13
|
-
*/
|
|
14
|
-
export interface APIBuilderOptions {
|
|
15
|
-
outputDir?: string;
|
|
16
|
-
verbose?: boolean;
|
|
17
|
-
overwrite?: boolean;
|
|
18
|
-
validate?: boolean;
|
|
19
|
-
cache?: boolean;
|
|
20
|
-
typeSchemaConfig?: TypeSchemaConfig;
|
|
21
|
-
logger?: CodegenLogger;
|
|
22
|
-
manager?: ReturnType<typeof CanonicalManager> | null;
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* Progress callback for long-running operations
|
|
26
|
-
*/
|
|
27
|
-
export type ProgressCallback = (phase: string, current: number, total: number, message?: string) => void;
|
|
28
|
-
/**
|
|
29
|
-
* Generation result information
|
|
30
|
-
*/
|
|
31
|
-
export interface GenerationResult {
|
|
32
|
-
success: boolean;
|
|
33
|
-
outputDir: string;
|
|
34
|
-
filesGenerated: string[];
|
|
35
|
-
errors: string[];
|
|
36
|
-
warnings: string[];
|
|
37
|
-
duration: number;
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* High-Level API Builder class
|
|
41
|
-
*
|
|
42
|
-
* Provides a fluent interface for configuring and executing code generation
|
|
43
|
-
* from FHIR packages or TypeSchema documents.
|
|
44
|
-
*/
|
|
45
|
-
export declare class APIBuilder {
|
|
46
|
-
private schemas;
|
|
47
|
-
private options;
|
|
48
|
-
private generators;
|
|
49
|
-
private progressCallback?;
|
|
50
|
-
private cache?;
|
|
51
|
-
private pendingOperations;
|
|
52
|
-
private typeSchemaGenerator?;
|
|
53
|
-
private logger;
|
|
54
|
-
private typeSchemaConfig?;
|
|
55
|
-
constructor(options?: APIBuilderOptions);
|
|
56
|
-
/**
|
|
57
|
-
* Load TypeSchema from a FHIR package
|
|
58
|
-
*/
|
|
59
|
-
fromPackage(packageName: string, version?: string): APIBuilder;
|
|
60
|
-
/**
|
|
61
|
-
* Load TypeSchema from files
|
|
62
|
-
*/
|
|
63
|
-
fromFiles(...filePaths: string[]): APIBuilder;
|
|
64
|
-
/**
|
|
65
|
-
* Load TypeSchema from TypeSchema objects
|
|
66
|
-
*/
|
|
67
|
-
fromSchemas(schemas: TypeSchema[]): APIBuilder;
|
|
68
|
-
/**
|
|
69
|
-
* Configure TypeScript generation
|
|
70
|
-
*/
|
|
71
|
-
typescript(options?: {
|
|
72
|
-
moduleFormat?: "esm" | "cjs";
|
|
73
|
-
generateIndex?: boolean;
|
|
74
|
-
includeDocuments?: boolean;
|
|
75
|
-
namingConvention?: "PascalCase" | "camelCase";
|
|
76
|
-
includeExtensions?: boolean;
|
|
77
|
-
includeProfiles?: boolean;
|
|
78
|
-
generateValueSets?: boolean;
|
|
79
|
-
includeValueSetHelpers?: boolean;
|
|
80
|
-
valueSetStrengths?: ("required" | "preferred" | "extensible" | "example")[];
|
|
81
|
-
valueSetMode?: "all" | "required-only" | "custom";
|
|
82
|
-
valueSetDirectory?: string;
|
|
83
|
-
}): APIBuilder;
|
|
84
|
-
/**
|
|
85
|
-
* Set a progress callback for monitoring generation
|
|
86
|
-
*/
|
|
87
|
-
onProgress(callback: ProgressCallback): APIBuilder;
|
|
88
|
-
/**
|
|
89
|
-
* Set the output directory for all generators
|
|
90
|
-
*/
|
|
91
|
-
outputTo(directory: string): APIBuilder;
|
|
92
|
-
/**
|
|
93
|
-
* Enable/disable verbose logging
|
|
94
|
-
*/
|
|
95
|
-
verbose(enabled?: boolean): APIBuilder;
|
|
96
|
-
/**
|
|
97
|
-
* Enable/disable validation
|
|
98
|
-
*/
|
|
99
|
-
validate(enabled?: boolean): APIBuilder;
|
|
100
|
-
/**
|
|
101
|
-
* Execute the generation process
|
|
102
|
-
*/
|
|
103
|
-
generate(): Promise<GenerationResult>;
|
|
104
|
-
/**
|
|
105
|
-
* Generate and return the results without writing to files
|
|
106
|
-
*/
|
|
107
|
-
build(): Promise<{
|
|
108
|
-
typescript?: {
|
|
109
|
-
content: string;
|
|
110
|
-
filename: string;
|
|
111
|
-
}[];
|
|
112
|
-
}>;
|
|
113
|
-
/**
|
|
114
|
-
* Clear all configuration and start fresh
|
|
115
|
-
*/
|
|
116
|
-
reset(): APIBuilder;
|
|
117
|
-
/**
|
|
118
|
-
* Get loaded schemas (for inspection)
|
|
119
|
-
*/
|
|
120
|
-
getSchemas(): TypeSchema[];
|
|
121
|
-
/**
|
|
122
|
-
* Get configured generators (for inspection)
|
|
123
|
-
*/
|
|
124
|
-
getGenerators(): string[];
|
|
125
|
-
private loadFromPackage;
|
|
126
|
-
private loadFromFiles;
|
|
127
|
-
private resolveSchemas;
|
|
128
|
-
private validateSchemas;
|
|
129
|
-
private executeGenerators;
|
|
130
|
-
private reportProgress;
|
|
131
|
-
}
|
|
132
|
-
/**
|
|
133
|
-
* Create a new API builder instance
|
|
134
|
-
*/
|
|
135
|
-
export declare function createAPI(options?: APIBuilderOptions): APIBuilder;
|
|
136
|
-
/**
|
|
137
|
-
* Create an API builder instance from a configuration object
|
|
138
|
-
*/
|
|
139
|
-
export declare function createAPIFromConfig(config: Config): APIBuilder;
|
|
140
|
-
/**
|
|
141
|
-
* Convenience function for quick TypeScript generation from a package
|
|
142
|
-
*/
|
|
143
|
-
export declare function generateTypesFromPackage(packageName: string, outputDir: string, options?: {
|
|
144
|
-
version?: string;
|
|
145
|
-
verbose?: boolean;
|
|
146
|
-
validate?: boolean;
|
|
147
|
-
}): Promise<GenerationResult>;
|
|
148
|
-
/**
|
|
149
|
-
* Convenience function for quick TypeScript generation from files
|
|
150
|
-
*/
|
|
151
|
-
export declare function generateTypesFromFiles(inputFiles: string[], outputDir: string, options?: {
|
|
152
|
-
verbose?: boolean;
|
|
153
|
-
validate?: boolean;
|
|
154
|
-
}): Promise<GenerationResult>;
|
package/dist/api/builder.js
DELETED
|
@@ -1,341 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* High-Level API Builder
|
|
3
|
-
*
|
|
4
|
-
* Provides a fluent, chainable API for common codegen use cases with pre-built generators.
|
|
5
|
-
* This builder pattern allows users to configure generation in a declarative way.
|
|
6
|
-
*/
|
|
7
|
-
import { TypeSchemaCache, TypeSchemaGenerator, TypeSchemaParser } from "@typeschema/index";
|
|
8
|
-
import { createLogger } from "../utils/codegen-logger";
|
|
9
|
-
import { TypeScriptGenerator } from "./generators/typescript";
|
|
10
|
-
/**
|
|
11
|
-
* High-Level API Builder class
|
|
12
|
-
*
|
|
13
|
-
* Provides a fluent interface for configuring and executing code generation
|
|
14
|
-
* from FHIR packages or TypeSchema documents.
|
|
15
|
-
*/
|
|
16
|
-
export class APIBuilder {
|
|
17
|
-
schemas = [];
|
|
18
|
-
options;
|
|
19
|
-
generators = new Map();
|
|
20
|
-
progressCallback;
|
|
21
|
-
cache;
|
|
22
|
-
pendingOperations = [];
|
|
23
|
-
typeSchemaGenerator;
|
|
24
|
-
logger;
|
|
25
|
-
typeSchemaConfig;
|
|
26
|
-
constructor(options = {}) {
|
|
27
|
-
this.options = {
|
|
28
|
-
outputDir: options.outputDir || "./generated",
|
|
29
|
-
verbose: options.verbose ?? false,
|
|
30
|
-
overwrite: options.overwrite ?? true,
|
|
31
|
-
validate: options.validate ?? true,
|
|
32
|
-
cache: options.cache ?? true,
|
|
33
|
-
typeSchemaConfig: options.typeSchemaConfig,
|
|
34
|
-
manager: options.manager || null,
|
|
35
|
-
};
|
|
36
|
-
this.typeSchemaConfig = options.typeSchemaConfig;
|
|
37
|
-
// Use provided logger or create a default one
|
|
38
|
-
this.logger =
|
|
39
|
-
options.logger ||
|
|
40
|
-
createLogger({
|
|
41
|
-
verbose: this.options.verbose,
|
|
42
|
-
prefix: "API",
|
|
43
|
-
});
|
|
44
|
-
if (this.options.cache) {
|
|
45
|
-
this.cache = new TypeSchemaCache(this.typeSchemaConfig);
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
/**
|
|
49
|
-
* Load TypeSchema from a FHIR package
|
|
50
|
-
*/
|
|
51
|
-
fromPackage(packageName, version) {
|
|
52
|
-
this.logger.debug(`Loading from FHIR package: ${packageName}@${version || "latest"}`);
|
|
53
|
-
const operation = this.loadFromPackage(packageName, version);
|
|
54
|
-
this.pendingOperations.push(operation);
|
|
55
|
-
return this;
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* Load TypeSchema from files
|
|
59
|
-
*/
|
|
60
|
-
fromFiles(...filePaths) {
|
|
61
|
-
this.logger.debug(`Loading from ${filePaths.length} TypeSchema files`);
|
|
62
|
-
const operation = this.loadFromFiles(filePaths);
|
|
63
|
-
this.pendingOperations.push(operation);
|
|
64
|
-
return this;
|
|
65
|
-
}
|
|
66
|
-
/**
|
|
67
|
-
* Load TypeSchema from TypeSchema objects
|
|
68
|
-
*/
|
|
69
|
-
fromSchemas(schemas) {
|
|
70
|
-
this.logger.debug(`Adding ${schemas.length} TypeSchemas to generation`);
|
|
71
|
-
this.schemas = [...this.schemas, ...schemas];
|
|
72
|
-
return this;
|
|
73
|
-
}
|
|
74
|
-
/**
|
|
75
|
-
* Configure TypeScript generation
|
|
76
|
-
*/
|
|
77
|
-
typescript(options = {}) {
|
|
78
|
-
// Hardcode types subfolder
|
|
79
|
-
const typesOutputDir = `${this.options.outputDir}/types`;
|
|
80
|
-
const generator = new TypeScriptGenerator({
|
|
81
|
-
outputDir: typesOutputDir,
|
|
82
|
-
moduleFormat: options.moduleFormat || "esm",
|
|
83
|
-
generateIndex: options.generateIndex ?? true,
|
|
84
|
-
includeDocuments: options.includeDocuments ?? true,
|
|
85
|
-
namingConvention: options.namingConvention || "PascalCase",
|
|
86
|
-
includeExtensions: options.includeExtensions ?? false,
|
|
87
|
-
includeProfiles: options.includeProfiles ?? false,
|
|
88
|
-
generateValueSets: options.generateValueSets ?? false,
|
|
89
|
-
includeValueSetHelpers: options.includeValueSetHelpers ?? false,
|
|
90
|
-
valueSetStrengths: options.valueSetStrengths ?? ["required"],
|
|
91
|
-
logger: this.logger.child("TS"),
|
|
92
|
-
valueSetMode: options.valueSetMode ?? "required-only",
|
|
93
|
-
valueSetDirectory: options.valueSetDirectory ?? "valuesets",
|
|
94
|
-
verbose: this.options.verbose,
|
|
95
|
-
validate: true, // Enable validation for debugging
|
|
96
|
-
overwrite: this.options.overwrite,
|
|
97
|
-
});
|
|
98
|
-
this.generators.set("typescript", generator);
|
|
99
|
-
this.logger.debug(`Configured TypeScript generator (${options.moduleFormat || "esm"})`);
|
|
100
|
-
return this;
|
|
101
|
-
}
|
|
102
|
-
/**
|
|
103
|
-
* Set a progress callback for monitoring generation
|
|
104
|
-
*/
|
|
105
|
-
onProgress(callback) {
|
|
106
|
-
this.progressCallback = callback;
|
|
107
|
-
return this;
|
|
108
|
-
}
|
|
109
|
-
/**
|
|
110
|
-
* Set the output directory for all generators
|
|
111
|
-
*/
|
|
112
|
-
outputTo(directory) {
|
|
113
|
-
this.logger.debug(`Setting output directory: ${directory}`);
|
|
114
|
-
this.options.outputDir = directory;
|
|
115
|
-
// Update all configured generators
|
|
116
|
-
for (const generator of this.generators.values()) {
|
|
117
|
-
if (generator.setOutputDir) {
|
|
118
|
-
generator.setOutputDir(directory);
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
return this;
|
|
122
|
-
}
|
|
123
|
-
/**
|
|
124
|
-
* Enable/disable verbose logging
|
|
125
|
-
*/
|
|
126
|
-
verbose(enabled = true) {
|
|
127
|
-
this.options.verbose = enabled;
|
|
128
|
-
return this;
|
|
129
|
-
}
|
|
130
|
-
/**
|
|
131
|
-
* Enable/disable validation
|
|
132
|
-
*/
|
|
133
|
-
validate(enabled = true) {
|
|
134
|
-
this.options.validate = enabled;
|
|
135
|
-
return this;
|
|
136
|
-
}
|
|
137
|
-
/**
|
|
138
|
-
* Execute the generation process
|
|
139
|
-
*/
|
|
140
|
-
async generate() {
|
|
141
|
-
const startTime = performance.now();
|
|
142
|
-
const result = {
|
|
143
|
-
success: false,
|
|
144
|
-
outputDir: this.options.outputDir,
|
|
145
|
-
filesGenerated: [],
|
|
146
|
-
errors: [],
|
|
147
|
-
warnings: [],
|
|
148
|
-
duration: 0,
|
|
149
|
-
};
|
|
150
|
-
this.logger.debug(`Starting generation with ${this.generators.size} generators`);
|
|
151
|
-
try {
|
|
152
|
-
this.reportProgress("Loading", 0, 4, "Loading TypeSchema data...");
|
|
153
|
-
// Load schemas if needed
|
|
154
|
-
await this.resolveSchemas();
|
|
155
|
-
this.logger.debug(`Resolved ${this.schemas.length} schemas`);
|
|
156
|
-
this.reportProgress("Validating", 1, 4, "Validating TypeSchema documents...");
|
|
157
|
-
// Validate schemas
|
|
158
|
-
if (this.options.validate) {
|
|
159
|
-
this.logger.debug("Starting schema validation");
|
|
160
|
-
await this.validateSchemas(result);
|
|
161
|
-
this.logger.debug("Schema validation completed");
|
|
162
|
-
}
|
|
163
|
-
this.reportProgress("Generating", 2, 4, "Generating code...");
|
|
164
|
-
this.logger.debug(`Executing ${this.generators.size} generators`);
|
|
165
|
-
// Execute all configured generators
|
|
166
|
-
await this.executeGenerators(result);
|
|
167
|
-
this.reportProgress("Complete", 4, 4, "Generation completed successfully");
|
|
168
|
-
result.success = result.errors.length === 0;
|
|
169
|
-
this.logger.debug(`Generation completed: ${result.filesGenerated.length} files`);
|
|
170
|
-
}
|
|
171
|
-
catch (error) {
|
|
172
|
-
this.logger.error("Code generation failed", error instanceof Error ? error : new Error(String(error)));
|
|
173
|
-
result.errors.push(error instanceof Error ? error.message : String(error));
|
|
174
|
-
result.success = false;
|
|
175
|
-
}
|
|
176
|
-
finally {
|
|
177
|
-
result.duration = performance.now() - startTime;
|
|
178
|
-
}
|
|
179
|
-
return result;
|
|
180
|
-
}
|
|
181
|
-
/**
|
|
182
|
-
* Generate and return the results without writing to files
|
|
183
|
-
*/
|
|
184
|
-
async build() {
|
|
185
|
-
await this.resolveSchemas();
|
|
186
|
-
const results = {};
|
|
187
|
-
for (const [type, generator] of this.generators.entries()) {
|
|
188
|
-
if (generator.build) {
|
|
189
|
-
results[type] = await generator.build(this.schemas);
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
return results;
|
|
193
|
-
}
|
|
194
|
-
/**
|
|
195
|
-
* Clear all configuration and start fresh
|
|
196
|
-
*/
|
|
197
|
-
reset() {
|
|
198
|
-
this.schemas = [];
|
|
199
|
-
this.generators.clear();
|
|
200
|
-
this.progressCallback = undefined;
|
|
201
|
-
return this;
|
|
202
|
-
}
|
|
203
|
-
/**
|
|
204
|
-
* Get loaded schemas (for inspection)
|
|
205
|
-
*/
|
|
206
|
-
getSchemas() {
|
|
207
|
-
return [...this.schemas];
|
|
208
|
-
}
|
|
209
|
-
/**
|
|
210
|
-
* Get configured generators (for inspection)
|
|
211
|
-
*/
|
|
212
|
-
getGenerators() {
|
|
213
|
-
return Array.from(this.generators.keys());
|
|
214
|
-
}
|
|
215
|
-
// Private implementation methods
|
|
216
|
-
async loadFromPackage(packageName, version) {
|
|
217
|
-
const generator = new TypeSchemaGenerator({
|
|
218
|
-
verbose: this.options.verbose,
|
|
219
|
-
logger: this.logger.child("Schema"),
|
|
220
|
-
treeshake: this.typeSchemaConfig?.treeshake,
|
|
221
|
-
manager: this.options.manager,
|
|
222
|
-
}, this.typeSchemaConfig);
|
|
223
|
-
this.typeSchemaGenerator = generator;
|
|
224
|
-
const schemas = await generator.generateFromPackage(packageName, version);
|
|
225
|
-
this.schemas = [...this.schemas, ...schemas];
|
|
226
|
-
if (this.cache) {
|
|
227
|
-
this.cache.setMany(schemas);
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
async loadFromFiles(filePaths) {
|
|
231
|
-
if (!this.typeSchemaGenerator) {
|
|
232
|
-
this.typeSchemaGenerator = new TypeSchemaGenerator({
|
|
233
|
-
verbose: this.options.verbose,
|
|
234
|
-
logger: this.logger.child("Schema"),
|
|
235
|
-
treeshake: this.typeSchemaConfig?.treeshake,
|
|
236
|
-
}, this.typeSchemaConfig);
|
|
237
|
-
}
|
|
238
|
-
const parser = new TypeSchemaParser({
|
|
239
|
-
format: "auto",
|
|
240
|
-
validate: this.options.validate,
|
|
241
|
-
});
|
|
242
|
-
const schemas = await parser.parseFromFiles(filePaths);
|
|
243
|
-
this.schemas = [...this.schemas, ...schemas];
|
|
244
|
-
if (this.cache) {
|
|
245
|
-
this.cache.setMany(schemas);
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
async resolveSchemas() {
|
|
249
|
-
// Wait for all pending async operations to complete
|
|
250
|
-
if (this.pendingOperations.length > 0) {
|
|
251
|
-
await Promise.all(this.pendingOperations);
|
|
252
|
-
this.pendingOperations = []; // Clear completed operations
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
async validateSchemas(_result) {
|
|
256
|
-
return;
|
|
257
|
-
}
|
|
258
|
-
async executeGenerators(result) {
|
|
259
|
-
const generatorCount = this.generators.size;
|
|
260
|
-
let current = 0;
|
|
261
|
-
for (const [type, generator] of this.generators.entries()) {
|
|
262
|
-
this.reportProgress("Generating", 2 + current / generatorCount, 4, `Generating ${type}...`);
|
|
263
|
-
try {
|
|
264
|
-
const files = await generator.generate(this.schemas);
|
|
265
|
-
result.filesGenerated.push(...files.map((f) => f.path || f.filename));
|
|
266
|
-
}
|
|
267
|
-
catch (error) {
|
|
268
|
-
result.errors.push(`${type} generator failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
269
|
-
}
|
|
270
|
-
current++;
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
|
-
reportProgress(phase, current, total, message) {
|
|
274
|
-
if (this.progressCallback) {
|
|
275
|
-
this.progressCallback(phase, current, total, message);
|
|
276
|
-
}
|
|
277
|
-
if (this.options.verbose && message) {
|
|
278
|
-
this.logger.debug(`[${phase}] ${message}`);
|
|
279
|
-
}
|
|
280
|
-
}
|
|
281
|
-
}
|
|
282
|
-
/**
|
|
283
|
-
* Create a new API builder instance
|
|
284
|
-
*/
|
|
285
|
-
export function createAPI(options) {
|
|
286
|
-
return new APIBuilder(options);
|
|
287
|
-
}
|
|
288
|
-
/**
|
|
289
|
-
* Create an API builder instance from a configuration object
|
|
290
|
-
*/
|
|
291
|
-
export function createAPIFromConfig(config) {
|
|
292
|
-
const builder = new APIBuilder({
|
|
293
|
-
outputDir: config.outputDir,
|
|
294
|
-
verbose: config.verbose,
|
|
295
|
-
overwrite: config.overwrite,
|
|
296
|
-
validate: config.validate,
|
|
297
|
-
cache: config.cache,
|
|
298
|
-
typeSchemaConfig: config.typeSchema,
|
|
299
|
-
});
|
|
300
|
-
// Add packages if specified
|
|
301
|
-
if (config.packages && config.packages.length > 0) {
|
|
302
|
-
for (const pkg of config.packages) {
|
|
303
|
-
builder.fromPackage(pkg);
|
|
304
|
-
}
|
|
305
|
-
}
|
|
306
|
-
// Add files if specified
|
|
307
|
-
if (config.files && config.files.length > 0) {
|
|
308
|
-
builder.fromFiles(...config.files);
|
|
309
|
-
}
|
|
310
|
-
// Configure TypeScript generator if specified
|
|
311
|
-
if (config.typescript) {
|
|
312
|
-
builder.typescript(config.typescript);
|
|
313
|
-
}
|
|
314
|
-
return builder;
|
|
315
|
-
}
|
|
316
|
-
/**
|
|
317
|
-
* Convenience function for quick TypeScript generation from a package
|
|
318
|
-
*/
|
|
319
|
-
export async function generateTypesFromPackage(packageName, outputDir, options = {}) {
|
|
320
|
-
return createAPI({
|
|
321
|
-
outputDir,
|
|
322
|
-
verbose: options.verbose,
|
|
323
|
-
validate: options.validate,
|
|
324
|
-
})
|
|
325
|
-
.fromPackage(packageName, options.version)
|
|
326
|
-
.typescript()
|
|
327
|
-
.generate();
|
|
328
|
-
}
|
|
329
|
-
/**
|
|
330
|
-
* Convenience function for quick TypeScript generation from files
|
|
331
|
-
*/
|
|
332
|
-
export async function generateTypesFromFiles(inputFiles, outputDir, options = {}) {
|
|
333
|
-
return createAPI({
|
|
334
|
-
outputDir,
|
|
335
|
-
verbose: options.verbose,
|
|
336
|
-
validate: options.validate,
|
|
337
|
-
})
|
|
338
|
-
.fromFiles(...inputFiles)
|
|
339
|
-
.typescript()
|
|
340
|
-
.generate();
|
|
341
|
-
}
|