@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/dist/config.js
DELETED
|
@@ -1,591 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* New Config Schema for High-Level API
|
|
3
|
-
*
|
|
4
|
-
* Simple configuration system compatible ONLY with the new high-level APIBuilder.
|
|
5
|
-
* All legacy config functionality has been removed.
|
|
6
|
-
*/
|
|
7
|
-
import { existsSync } from "node:fs";
|
|
8
|
-
import { readFile } from "node:fs/promises";
|
|
9
|
-
import { resolve } from "node:path";
|
|
10
|
-
/**
|
|
11
|
-
* Default configuration values
|
|
12
|
-
*/
|
|
13
|
-
export const DEFAULT_CONFIG = {
|
|
14
|
-
outputDir: "./generated",
|
|
15
|
-
verbose: false,
|
|
16
|
-
overwrite: true,
|
|
17
|
-
validate: true,
|
|
18
|
-
cache: true,
|
|
19
|
-
typescript: {
|
|
20
|
-
moduleFormat: "esm",
|
|
21
|
-
generateIndex: true,
|
|
22
|
-
includeDocuments: false,
|
|
23
|
-
namingConvention: "PascalCase",
|
|
24
|
-
strictMode: true,
|
|
25
|
-
includeProfiles: true,
|
|
26
|
-
includeExtensions: false,
|
|
27
|
-
includeCodeSystems: false,
|
|
28
|
-
includeOperations: false,
|
|
29
|
-
generateValueSets: false,
|
|
30
|
-
valueSetDirectory: "valuesets",
|
|
31
|
-
valueSetMode: "required-only",
|
|
32
|
-
valueSetStrengths: ["required"],
|
|
33
|
-
includeValueSetHelpers: false,
|
|
34
|
-
fhirVersion: "R4",
|
|
35
|
-
resourceTypes: [],
|
|
36
|
-
maxDepth: 10,
|
|
37
|
-
// Profile generation defaults
|
|
38
|
-
profileOptions: {
|
|
39
|
-
generateKind: "interface",
|
|
40
|
-
includeConstraints: true,
|
|
41
|
-
includeDocumentation: true,
|
|
42
|
-
strictMode: false,
|
|
43
|
-
subfolder: "profiles",
|
|
44
|
-
},
|
|
45
|
-
// Builder generation defaults
|
|
46
|
-
generateBuilders: false,
|
|
47
|
-
builderOptions: {
|
|
48
|
-
includeValidation: true,
|
|
49
|
-
includeFactoryMethods: true,
|
|
50
|
-
includeInterfaces: true,
|
|
51
|
-
generateNestedBuilders: true,
|
|
52
|
-
includeHelperMethods: true,
|
|
53
|
-
supportPartialBuild: true,
|
|
54
|
-
includeJSDoc: true,
|
|
55
|
-
generateFactories: true,
|
|
56
|
-
includeTypeGuards: true,
|
|
57
|
-
handleChoiceTypes: true,
|
|
58
|
-
generateArrayHelpers: true,
|
|
59
|
-
},
|
|
60
|
-
// Validator generation defaults
|
|
61
|
-
validatorOptions: {
|
|
62
|
-
includeCardinality: true,
|
|
63
|
-
includeTypes: true,
|
|
64
|
-
includeConstraints: true,
|
|
65
|
-
includeInvariants: false,
|
|
66
|
-
validateRequired: true,
|
|
67
|
-
allowAdditional: false,
|
|
68
|
-
strictValidation: false,
|
|
69
|
-
collectMetrics: false,
|
|
70
|
-
generateAssertions: true,
|
|
71
|
-
generatePartialValidators: true,
|
|
72
|
-
optimizePerformance: true,
|
|
73
|
-
includeJSDoc: true,
|
|
74
|
-
generateCompositeValidators: true,
|
|
75
|
-
},
|
|
76
|
-
// Type guard generation defaults
|
|
77
|
-
guardOptions: {
|
|
78
|
-
includeRuntimeValidation: true,
|
|
79
|
-
includeErrorMessages: true,
|
|
80
|
-
treeShakeable: true,
|
|
81
|
-
targetTSVersion: "5.0",
|
|
82
|
-
strictGuards: false,
|
|
83
|
-
includeNullChecks: true,
|
|
84
|
-
verbose: false,
|
|
85
|
-
},
|
|
86
|
-
},
|
|
87
|
-
typeSchema: {
|
|
88
|
-
enablePersistence: true,
|
|
89
|
-
cacheDir: ".typeschema-cache",
|
|
90
|
-
maxAge: 24 * 60 * 60 * 1000, // 24 hours in milliseconds
|
|
91
|
-
validateCached: true,
|
|
92
|
-
forceRegenerate: false,
|
|
93
|
-
shareCache: true,
|
|
94
|
-
cacheKeyPrefix: "",
|
|
95
|
-
treeshake: [],
|
|
96
|
-
singleFile: false,
|
|
97
|
-
profiles: {
|
|
98
|
-
autoDetect: true,
|
|
99
|
-
},
|
|
100
|
-
},
|
|
101
|
-
packages: [],
|
|
102
|
-
files: [],
|
|
103
|
-
$schema: "",
|
|
104
|
-
};
|
|
105
|
-
/**
|
|
106
|
-
* Configuration file names to search for
|
|
107
|
-
*/
|
|
108
|
-
export const CONFIG_FILE_NAMES = [
|
|
109
|
-
"atomic-codegen.config.ts",
|
|
110
|
-
"atomic-codegen.config",
|
|
111
|
-
"atomic-codegen.config.json",
|
|
112
|
-
".atomic-codegenrc",
|
|
113
|
-
"atomic-codegen.json",
|
|
114
|
-
".atomic-codegen.json",
|
|
115
|
-
"codegen.config.json",
|
|
116
|
-
"codegen.json",
|
|
117
|
-
];
|
|
118
|
-
/**
|
|
119
|
-
* Simple configuration validator
|
|
120
|
-
*/
|
|
121
|
-
export class ConfigValidator {
|
|
122
|
-
/**
|
|
123
|
-
* Validate a configuration object
|
|
124
|
-
*/
|
|
125
|
-
validate(config) {
|
|
126
|
-
const result = {
|
|
127
|
-
valid: true,
|
|
128
|
-
errors: [],
|
|
129
|
-
warnings: [],
|
|
130
|
-
};
|
|
131
|
-
if (!config || typeof config !== "object") {
|
|
132
|
-
result.valid = false;
|
|
133
|
-
result.errors.push({
|
|
134
|
-
path: "root",
|
|
135
|
-
message: "Configuration must be an object",
|
|
136
|
-
value: config,
|
|
137
|
-
});
|
|
138
|
-
return result;
|
|
139
|
-
}
|
|
140
|
-
const cfg = config;
|
|
141
|
-
// Validate outputDir
|
|
142
|
-
if (cfg.outputDir !== undefined && typeof cfg.outputDir !== "string") {
|
|
143
|
-
result.errors.push({
|
|
144
|
-
path: "outputDir",
|
|
145
|
-
message: "outputDir must be a string",
|
|
146
|
-
value: cfg.outputDir,
|
|
147
|
-
});
|
|
148
|
-
}
|
|
149
|
-
// Validate boolean fields
|
|
150
|
-
const booleanFields = ["verbose", "overwrite", "validate", "cache"];
|
|
151
|
-
for (const field of booleanFields) {
|
|
152
|
-
if (cfg[field] !== undefined && typeof cfg[field] !== "boolean") {
|
|
153
|
-
result.errors.push({
|
|
154
|
-
path: field,
|
|
155
|
-
message: `${field} must be a boolean`,
|
|
156
|
-
value: cfg[field],
|
|
157
|
-
});
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
// Validate typescript config
|
|
161
|
-
if (cfg.typescript !== undefined) {
|
|
162
|
-
const tsErrors = this.validateTypeScriptConfig(cfg.typescript);
|
|
163
|
-
result.errors.push(...tsErrors);
|
|
164
|
-
}
|
|
165
|
-
// Validate typeSchema config
|
|
166
|
-
if (cfg.typeSchema !== undefined) {
|
|
167
|
-
const tsErrors = this.validateTypeSchemaConfig(cfg.typeSchema);
|
|
168
|
-
result.errors.push(...tsErrors);
|
|
169
|
-
}
|
|
170
|
-
// Validate packages array
|
|
171
|
-
if (cfg.packages !== undefined) {
|
|
172
|
-
if (!Array.isArray(cfg.packages)) {
|
|
173
|
-
result.errors.push({
|
|
174
|
-
path: "packages",
|
|
175
|
-
message: "packages must be an array",
|
|
176
|
-
value: cfg.packages,
|
|
177
|
-
});
|
|
178
|
-
}
|
|
179
|
-
else {
|
|
180
|
-
cfg.packages.forEach((pkg, index) => {
|
|
181
|
-
if (typeof pkg !== "string") {
|
|
182
|
-
result.errors.push({
|
|
183
|
-
path: `packages[${index}]`,
|
|
184
|
-
message: "package name must be a string",
|
|
185
|
-
value: pkg,
|
|
186
|
-
});
|
|
187
|
-
}
|
|
188
|
-
});
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
// Validate files array
|
|
192
|
-
if (cfg.files !== undefined) {
|
|
193
|
-
if (!Array.isArray(cfg.files)) {
|
|
194
|
-
result.errors.push({
|
|
195
|
-
path: "files",
|
|
196
|
-
message: "files must be an array",
|
|
197
|
-
value: cfg.files,
|
|
198
|
-
});
|
|
199
|
-
}
|
|
200
|
-
else {
|
|
201
|
-
cfg.files.forEach((file, index) => {
|
|
202
|
-
if (typeof file !== "string") {
|
|
203
|
-
result.errors.push({
|
|
204
|
-
path: `files[${index}]`,
|
|
205
|
-
message: "file path must be a string",
|
|
206
|
-
value: file,
|
|
207
|
-
});
|
|
208
|
-
}
|
|
209
|
-
});
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
result.valid = result.errors.length === 0;
|
|
213
|
-
if (result.valid) {
|
|
214
|
-
result.config = cfg;
|
|
215
|
-
}
|
|
216
|
-
return result;
|
|
217
|
-
}
|
|
218
|
-
validateTypeScriptConfig(config) {
|
|
219
|
-
const errors = [];
|
|
220
|
-
if (typeof config !== "object" || config === null) {
|
|
221
|
-
errors.push({
|
|
222
|
-
path: "typescript",
|
|
223
|
-
message: "typescript config must be an object",
|
|
224
|
-
value: config,
|
|
225
|
-
});
|
|
226
|
-
return errors;
|
|
227
|
-
}
|
|
228
|
-
const cfg = config;
|
|
229
|
-
// Validate moduleFormat
|
|
230
|
-
if (cfg.moduleFormat !== undefined) {
|
|
231
|
-
if (!["esm", "cjs"].includes(cfg.moduleFormat)) {
|
|
232
|
-
errors.push({
|
|
233
|
-
path: "typescript.moduleFormat",
|
|
234
|
-
message: 'moduleFormat must be "esm" or "cjs"',
|
|
235
|
-
value: cfg.moduleFormat,
|
|
236
|
-
});
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
// Validate namingConvention
|
|
240
|
-
if (cfg.namingConvention !== undefined) {
|
|
241
|
-
if (!["PascalCase", "camelCase"].includes(cfg.namingConvention)) {
|
|
242
|
-
errors.push({
|
|
243
|
-
path: "typescript.namingConvention",
|
|
244
|
-
message: 'namingConvention must be "PascalCase" or "camelCase"',
|
|
245
|
-
value: cfg.namingConvention,
|
|
246
|
-
});
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
// Validate boolean fields
|
|
250
|
-
const booleanFields = [
|
|
251
|
-
"generateIndex",
|
|
252
|
-
"includeDocuments",
|
|
253
|
-
"strictMode",
|
|
254
|
-
"includeProfiles",
|
|
255
|
-
"includeExtensions",
|
|
256
|
-
"includeCodeSystems",
|
|
257
|
-
"includeOperations",
|
|
258
|
-
"generateValueSets",
|
|
259
|
-
"includeValueSetHelpers",
|
|
260
|
-
];
|
|
261
|
-
for (const field of booleanFields) {
|
|
262
|
-
if (cfg[field] !== undefined && typeof cfg[field] !== "boolean") {
|
|
263
|
-
errors.push({
|
|
264
|
-
path: `typescript.${field}`,
|
|
265
|
-
message: `${field} must be a boolean`,
|
|
266
|
-
value: cfg[field],
|
|
267
|
-
});
|
|
268
|
-
}
|
|
269
|
-
}
|
|
270
|
-
// Validate validatorOptions
|
|
271
|
-
if (cfg.validatorOptions !== undefined) {
|
|
272
|
-
const validatorErrors = this.validateValidatorOptions(cfg.validatorOptions);
|
|
273
|
-
errors.push(...validatorErrors);
|
|
274
|
-
}
|
|
275
|
-
// Validate guardOptions
|
|
276
|
-
if (cfg.guardOptions !== undefined) {
|
|
277
|
-
const guardErrors = this.validateGuardOptions(cfg.guardOptions);
|
|
278
|
-
errors.push(...guardErrors);
|
|
279
|
-
}
|
|
280
|
-
// Validate profileOptions
|
|
281
|
-
if (cfg.profileOptions !== undefined) {
|
|
282
|
-
const profileErrors = this.validateProfileOptions(cfg.profileOptions);
|
|
283
|
-
errors.push(...profileErrors);
|
|
284
|
-
}
|
|
285
|
-
return errors;
|
|
286
|
-
}
|
|
287
|
-
validateValidatorOptions(config) {
|
|
288
|
-
const errors = [];
|
|
289
|
-
if (typeof config !== "object" || config === null) {
|
|
290
|
-
errors.push({
|
|
291
|
-
path: "typescript.validatorOptions",
|
|
292
|
-
message: "validatorOptions must be an object",
|
|
293
|
-
value: config,
|
|
294
|
-
});
|
|
295
|
-
return errors;
|
|
296
|
-
}
|
|
297
|
-
const cfg = config;
|
|
298
|
-
// Validate boolean fields
|
|
299
|
-
const booleanFields = [
|
|
300
|
-
"includeCardinality",
|
|
301
|
-
"includeTypes",
|
|
302
|
-
"includeConstraints",
|
|
303
|
-
"includeInvariants",
|
|
304
|
-
"validateRequired",
|
|
305
|
-
"allowAdditional",
|
|
306
|
-
"strictValidation",
|
|
307
|
-
"collectMetrics",
|
|
308
|
-
"generateAssertions",
|
|
309
|
-
"generatePartialValidators",
|
|
310
|
-
"optimizePerformance",
|
|
311
|
-
"includeJSDoc",
|
|
312
|
-
"generateCompositeValidators",
|
|
313
|
-
];
|
|
314
|
-
for (const field of booleanFields) {
|
|
315
|
-
if (cfg[field] !== undefined && typeof cfg[field] !== "boolean") {
|
|
316
|
-
errors.push({
|
|
317
|
-
path: `typescript.validatorOptions.${field}`,
|
|
318
|
-
message: `${field} must be a boolean`,
|
|
319
|
-
value: cfg[field],
|
|
320
|
-
});
|
|
321
|
-
}
|
|
322
|
-
}
|
|
323
|
-
return errors;
|
|
324
|
-
}
|
|
325
|
-
validateGuardOptions(config) {
|
|
326
|
-
const errors = [];
|
|
327
|
-
if (typeof config !== "object" || config === null) {
|
|
328
|
-
errors.push({
|
|
329
|
-
path: "typescript.guardOptions",
|
|
330
|
-
message: "guardOptions must be an object",
|
|
331
|
-
value: config,
|
|
332
|
-
});
|
|
333
|
-
return errors;
|
|
334
|
-
}
|
|
335
|
-
const cfg = config;
|
|
336
|
-
// Validate targetTSVersion
|
|
337
|
-
if (cfg.targetTSVersion !== undefined) {
|
|
338
|
-
if (!["3.8", "4.0", "4.5", "5.0"].includes(cfg.targetTSVersion)) {
|
|
339
|
-
errors.push({
|
|
340
|
-
path: "typescript.guardOptions.targetTSVersion",
|
|
341
|
-
message: 'targetTSVersion must be one of: "3.8", "4.0", "4.5", "5.0"',
|
|
342
|
-
value: cfg.targetTSVersion,
|
|
343
|
-
});
|
|
344
|
-
}
|
|
345
|
-
}
|
|
346
|
-
// Validate boolean fields
|
|
347
|
-
const booleanFields = [
|
|
348
|
-
"includeRuntimeValidation",
|
|
349
|
-
"includeErrorMessages",
|
|
350
|
-
"treeShakeable",
|
|
351
|
-
"strictGuards",
|
|
352
|
-
"includeNullChecks",
|
|
353
|
-
"verbose",
|
|
354
|
-
];
|
|
355
|
-
for (const field of booleanFields) {
|
|
356
|
-
if (cfg[field] !== undefined && typeof cfg[field] !== "boolean") {
|
|
357
|
-
errors.push({
|
|
358
|
-
path: `typescript.guardOptions.${field}`,
|
|
359
|
-
message: `${field} must be a boolean`,
|
|
360
|
-
value: cfg[field],
|
|
361
|
-
});
|
|
362
|
-
}
|
|
363
|
-
}
|
|
364
|
-
return errors;
|
|
365
|
-
}
|
|
366
|
-
validateProfileOptions(config) {
|
|
367
|
-
const errors = [];
|
|
368
|
-
if (typeof config !== "object" || config === null) {
|
|
369
|
-
errors.push({
|
|
370
|
-
path: "typescript.profileOptions",
|
|
371
|
-
message: "profileOptions must be an object",
|
|
372
|
-
value: config,
|
|
373
|
-
});
|
|
374
|
-
return errors;
|
|
375
|
-
}
|
|
376
|
-
const cfg = config;
|
|
377
|
-
// Validate generateKind
|
|
378
|
-
if (cfg.generateKind !== undefined) {
|
|
379
|
-
if (!["interface", "type", "both"].includes(cfg.generateKind)) {
|
|
380
|
-
errors.push({
|
|
381
|
-
path: "typescript.profileOptions.generateKind",
|
|
382
|
-
message: 'generateKind must be "interface", "type", or "both"',
|
|
383
|
-
value: cfg.generateKind,
|
|
384
|
-
});
|
|
385
|
-
}
|
|
386
|
-
}
|
|
387
|
-
// Validate subfolder
|
|
388
|
-
if (cfg.subfolder !== undefined && typeof cfg.subfolder !== "string") {
|
|
389
|
-
errors.push({
|
|
390
|
-
path: "typescript.profileOptions.subfolder",
|
|
391
|
-
message: "subfolder must be a string",
|
|
392
|
-
value: cfg.subfolder,
|
|
393
|
-
});
|
|
394
|
-
}
|
|
395
|
-
// Validate boolean fields
|
|
396
|
-
const booleanFields = ["includeConstraints", "includeDocumentation", "strictMode"];
|
|
397
|
-
for (const field of booleanFields) {
|
|
398
|
-
if (cfg[field] !== undefined && typeof cfg[field] !== "boolean") {
|
|
399
|
-
errors.push({
|
|
400
|
-
path: `typescript.profileOptions.${field}`,
|
|
401
|
-
message: `${field} must be a boolean`,
|
|
402
|
-
value: cfg[field],
|
|
403
|
-
});
|
|
404
|
-
}
|
|
405
|
-
}
|
|
406
|
-
return errors;
|
|
407
|
-
}
|
|
408
|
-
validateTypeSchemaConfig(config) {
|
|
409
|
-
const errors = [];
|
|
410
|
-
if (typeof config !== "object" || config === null) {
|
|
411
|
-
errors.push({
|
|
412
|
-
path: "typeSchema",
|
|
413
|
-
message: "typeSchema config must be an object",
|
|
414
|
-
value: config,
|
|
415
|
-
});
|
|
416
|
-
return errors;
|
|
417
|
-
}
|
|
418
|
-
const cfg = config;
|
|
419
|
-
// Validate boolean fields
|
|
420
|
-
const booleanFields = ["enablePersistence", "validateCached", "forceRegenerate", "shareCache"];
|
|
421
|
-
for (const field of booleanFields) {
|
|
422
|
-
if (cfg[field] !== undefined && typeof cfg[field] !== "boolean") {
|
|
423
|
-
errors.push({
|
|
424
|
-
path: `typeSchema.${field}`,
|
|
425
|
-
message: `${field} must be a boolean`,
|
|
426
|
-
value: cfg[field],
|
|
427
|
-
});
|
|
428
|
-
}
|
|
429
|
-
}
|
|
430
|
-
// Validate string fields
|
|
431
|
-
const stringFields = ["cacheDir", "cacheKeyPrefix"];
|
|
432
|
-
for (const field of stringFields) {
|
|
433
|
-
if (cfg[field] !== undefined && typeof cfg[field] !== "string") {
|
|
434
|
-
errors.push({
|
|
435
|
-
path: `typeSchema.${field}`,
|
|
436
|
-
message: `${field} must be a string`,
|
|
437
|
-
value: cfg[field],
|
|
438
|
-
});
|
|
439
|
-
}
|
|
440
|
-
}
|
|
441
|
-
// Validate maxAge
|
|
442
|
-
if (cfg.maxAge !== undefined) {
|
|
443
|
-
if (typeof cfg.maxAge !== "number" || cfg.maxAge <= 0) {
|
|
444
|
-
errors.push({
|
|
445
|
-
path: "typeSchema.maxAge",
|
|
446
|
-
message: "maxAge must be a positive number",
|
|
447
|
-
value: cfg.maxAge,
|
|
448
|
-
});
|
|
449
|
-
}
|
|
450
|
-
}
|
|
451
|
-
// Validate profiles
|
|
452
|
-
if (cfg.profiles !== undefined) {
|
|
453
|
-
if (typeof cfg.profiles !== "object" || cfg.profiles === null) {
|
|
454
|
-
errors.push({
|
|
455
|
-
path: "typeSchema.profiles",
|
|
456
|
-
message: "profiles must be an object",
|
|
457
|
-
value: cfg.profiles,
|
|
458
|
-
});
|
|
459
|
-
}
|
|
460
|
-
else {
|
|
461
|
-
const profiles = cfg.profiles;
|
|
462
|
-
// Validate autoDetect
|
|
463
|
-
if (profiles.autoDetect !== undefined && typeof profiles.autoDetect !== "boolean") {
|
|
464
|
-
errors.push({
|
|
465
|
-
path: "typeSchema.profiles.autoDetect",
|
|
466
|
-
message: "autoDetect must be a boolean",
|
|
467
|
-
value: profiles.autoDetect,
|
|
468
|
-
});
|
|
469
|
-
}
|
|
470
|
-
}
|
|
471
|
-
}
|
|
472
|
-
return errors;
|
|
473
|
-
}
|
|
474
|
-
}
|
|
475
|
-
/**
|
|
476
|
-
* Configuration loader with autoloading capabilities
|
|
477
|
-
*/
|
|
478
|
-
export class ConfigLoader {
|
|
479
|
-
validator = new ConfigValidator();
|
|
480
|
-
/**
|
|
481
|
-
* Auto-load configuration from the current working directory
|
|
482
|
-
*/
|
|
483
|
-
async autoload(workingDir = process.cwd()) {
|
|
484
|
-
const configPath = await this.findConfigFile(workingDir);
|
|
485
|
-
if (configPath) {
|
|
486
|
-
return this.loadFromFile(configPath);
|
|
487
|
-
}
|
|
488
|
-
// Return default config if no file found
|
|
489
|
-
return { ...DEFAULT_CONFIG };
|
|
490
|
-
}
|
|
491
|
-
/**
|
|
492
|
-
* Load configuration from a specific file
|
|
493
|
-
*/
|
|
494
|
-
async loadFromFile(filePath) {
|
|
495
|
-
try {
|
|
496
|
-
let config;
|
|
497
|
-
if (filePath.endsWith(".ts") || filePath.endsWith("")) {
|
|
498
|
-
// Use dynamic import for TypeScript/JavaScript files
|
|
499
|
-
const absolutePath = resolve(filePath);
|
|
500
|
-
const importResult = await import(absolutePath);
|
|
501
|
-
config = importResult.default || importResult;
|
|
502
|
-
}
|
|
503
|
-
else {
|
|
504
|
-
// JSON files
|
|
505
|
-
const content = await readFile(filePath, "utf-8");
|
|
506
|
-
config = JSON.parse(content);
|
|
507
|
-
}
|
|
508
|
-
const validation = this.validator.validate(config);
|
|
509
|
-
if (!validation.valid) {
|
|
510
|
-
const errorMessages = validation.errors.map((e) => `${e.path}: ${e.message}`).join("\n");
|
|
511
|
-
throw new Error(`Configuration validation failed:\n${errorMessages}`);
|
|
512
|
-
}
|
|
513
|
-
// Merge with defaults
|
|
514
|
-
return this.mergeWithDefaults(validation.config);
|
|
515
|
-
}
|
|
516
|
-
catch (error) {
|
|
517
|
-
if (error instanceof Error) {
|
|
518
|
-
throw new Error(`Failed to load config from ${filePath}: ${error.message}`);
|
|
519
|
-
}
|
|
520
|
-
throw error;
|
|
521
|
-
}
|
|
522
|
-
}
|
|
523
|
-
/**
|
|
524
|
-
* Find configuration file in the given directory
|
|
525
|
-
*/
|
|
526
|
-
async findConfigFile(startDir) {
|
|
527
|
-
for (const fileName of CONFIG_FILE_NAMES) {
|
|
528
|
-
const configPath = resolve(startDir, fileName);
|
|
529
|
-
if (existsSync(configPath)) {
|
|
530
|
-
return configPath;
|
|
531
|
-
}
|
|
532
|
-
}
|
|
533
|
-
return null;
|
|
534
|
-
}
|
|
535
|
-
/**
|
|
536
|
-
* Merge user config with defaults
|
|
537
|
-
*/
|
|
538
|
-
mergeWithDefaults(userConfig) {
|
|
539
|
-
const merged = {
|
|
540
|
-
...DEFAULT_CONFIG,
|
|
541
|
-
...userConfig,
|
|
542
|
-
typescript: {
|
|
543
|
-
...DEFAULT_CONFIG.typescript,
|
|
544
|
-
...userConfig.typescript,
|
|
545
|
-
},
|
|
546
|
-
};
|
|
547
|
-
return merged;
|
|
548
|
-
}
|
|
549
|
-
}
|
|
550
|
-
/**
|
|
551
|
-
* Global config loader instance
|
|
552
|
-
*/
|
|
553
|
-
export const configLoader = new ConfigLoader();
|
|
554
|
-
/**
|
|
555
|
-
* Convenience function to auto-load configuration
|
|
556
|
-
*/
|
|
557
|
-
export async function loadConfig(workingDir) {
|
|
558
|
-
return configLoader.autoload(workingDir);
|
|
559
|
-
}
|
|
560
|
-
/**
|
|
561
|
-
* Type guard to check if an object is a valid Config
|
|
562
|
-
*/
|
|
563
|
-
export function isConfig(obj) {
|
|
564
|
-
const validator = new ConfigValidator();
|
|
565
|
-
const result = validator.validate(obj);
|
|
566
|
-
return result.valid;
|
|
567
|
-
}
|
|
568
|
-
/**
|
|
569
|
-
* Define configuration with type safety and IntelliSense support.
|
|
570
|
-
* Similar to Vite's defineConfig function pattern.
|
|
571
|
-
*
|
|
572
|
-
* @example
|
|
573
|
-
* ```typescript
|
|
574
|
-
* import { defineConfig } from "@atomic-ehr/codegen";
|
|
575
|
-
*
|
|
576
|
-
* export default defineConfig({
|
|
577
|
-
* outputDir: "./generated",
|
|
578
|
-
* packages: [
|
|
579
|
-
* "hl7.fhir.r4.core@4.0.1",
|
|
580
|
-
* "hl7.fhir.us.core@6.1.0"
|
|
581
|
-
* ],
|
|
582
|
-
* typescript: {
|
|
583
|
-
* generateIndex: true,
|
|
584
|
-
* strictMode: true
|
|
585
|
-
* }
|
|
586
|
-
* });
|
|
587
|
-
* ```
|
|
588
|
-
*/
|
|
589
|
-
export function defineConfig(config) {
|
|
590
|
-
return config;
|
|
591
|
-
}
|