@atomic-ehr/codegen 0.0.1-canary.20251110125758.7d2cc60 → 0.0.1-canary.20251110160104.576d657

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -881,12 +881,8 @@ declare class APIBuilder {
881
881
  throwException(enabled?: boolean): APIBuilder;
882
882
  cleanOutput(enabled?: boolean): APIBuilder;
883
883
  writeTypeTree(filename: string): this;
884
- treeShakeBy(tree: TreeShake): this;
884
+ treeShake(tree: TreeShake): this;
885
885
  writeTypeSchemas(target: string): this;
886
- private writeTypeSchemasToSeparateFiles;
887
- private writeTypeSchemasToSingleFile;
888
- private tryWriteTypeSchema;
889
- cleanup(): Promise<void>;
890
886
  generate(): Promise<GenerationResult>;
891
887
  /**
892
888
  * Generate and return the results without writing to files
@@ -912,29 +908,10 @@ declare class APIBuilder {
912
908
  private loadFromFiles;
913
909
  private executeGenerators;
914
910
  }
915
- /**
916
- * Create a new API builder instance
917
- */
918
- declare function createAPI(options?: APIBuilderOptions): APIBuilder;
919
911
  /**
920
912
  * Create an API builder instance from a configuration object
921
913
  */
922
914
  declare function createAPIFromConfig(config: Config): APIBuilder;
923
- /**
924
- * Convenience function for quick TypeScript generation from a package
925
- */
926
- declare function generateTypesFromPackage(packageName: string, outputDir: string, options?: {
927
- version?: string;
928
- verbose?: boolean;
929
- validate?: boolean;
930
- }): Promise<GenerationResult>;
931
- /**
932
- * Convenience function for quick TypeScript generation from files
933
- */
934
- declare function generateTypesFromFiles(inputFiles: string[], outputDir: string, options?: {
935
- verbose?: boolean;
936
- validate?: boolean;
937
- }): Promise<GenerationResult>;
938
915
 
939
916
  /**
940
917
  * Core types and interfaces for the base generator system
@@ -2220,4 +2197,4 @@ declare class TypeScriptGenerator extends BaseGenerator<TypeScriptGeneratorOptio
2220
2197
  private generateMainIndexFile;
2221
2198
  }
2222
2199
 
2223
- export { APIBuilder, type APIBuilderOptions, CONFIG_FILE_NAMES, type Config, ConfigLoader, type ConfigValidationError, type ConfigValidationResult, ConfigValidator, DEFAULT_CONFIG, type GeneratedFile, type GenerationResult, type PackageMeta as PackageInfo, type ProgressCallback$1 as ProgressCallback, type TypeSchema, TypeSchemaCache, type TypeSchemaConfig, type Field as TypeSchemaField, TypeSchemaGenerator, type Identifier as TypeSchemaIdentifier, TypeSchemaParser, TypeScriptGenerator, type TypeScriptGeneratorConfig, type TypeScriptGeneratorOptions, configLoader, createAPI, createAPIFromConfig, defineConfig, generateTypesFromFiles, generateTypesFromPackage, isConfig, loadConfig };
2200
+ export { APIBuilder, type APIBuilderOptions, CONFIG_FILE_NAMES, type Config, ConfigLoader, type ConfigValidationError, type ConfigValidationResult, ConfigValidator, DEFAULT_CONFIG, type GeneratedFile, type GenerationResult, type PackageMeta as PackageInfo, type ProgressCallback$1 as ProgressCallback, type TypeSchema, TypeSchemaCache, type TypeSchemaConfig, type Field as TypeSchemaField, TypeSchemaGenerator, type Identifier as TypeSchemaIdentifier, TypeSchemaParser, TypeScriptGenerator, type TypeScriptGeneratorConfig, type TypeScriptGeneratorOptions, configLoader, createAPIFromConfig, defineConfig, isConfig, loadConfig };
package/dist/index.js CHANGED
@@ -6155,6 +6155,86 @@ var normalizeFileName = (str) => {
6155
6155
  if (res.length === 0) return "unknown";
6156
6156
  return res;
6157
6157
  };
6158
+ var cleanup = async (opts, logger) => {
6159
+ logger.info(`Cleaning outputs...`);
6160
+ try {
6161
+ logger.info(`Clean ${opts.outputDir}`);
6162
+ fs.rmSync(opts.outputDir, { recursive: true, force: true });
6163
+ if (opts.typeSchemaOutputDir) {
6164
+ logger.info(`Clean ${opts.typeSchemaOutputDir}`);
6165
+ fs.rmSync(opts.typeSchemaOutputDir, {
6166
+ recursive: true,
6167
+ force: true
6168
+ });
6169
+ }
6170
+ if (opts.exportTypeTree) {
6171
+ logger.info(`Clean ${opts.exportTypeTree}`);
6172
+ fs.rmSync(opts.exportTypeTree, {
6173
+ recursive: true,
6174
+ force: true
6175
+ });
6176
+ }
6177
+ } catch (error) {
6178
+ logger.warn(`Error cleaning output directory: ${error instanceof Error ? error.message : String(error)}`);
6179
+ }
6180
+ };
6181
+ var writeTypeSchemasToSeparateFiles = async (typeSchemas, outputDir, logger) => {
6182
+ await afs3.mkdir(outputDir, { recursive: true });
6183
+ logger.info(`Writing TypeSchema files to ${outputDir}/...`);
6184
+ const files = {};
6185
+ for (const ts of typeSchemas) {
6186
+ const pkg = {
6187
+ name: ts.identifier.package,
6188
+ version: ts.identifier.version
6189
+ };
6190
+ const pkgPath = normalizeFileName(packageMetaToFhir(pkg));
6191
+ const name = normalizeFileName(`${ts.identifier.name}(${extractNameFromCanonical(ts.identifier.url)})`);
6192
+ const json = JSON.stringify(ts, null, 2);
6193
+ const baseName = Path4.join(outputDir, pkgPath, name);
6194
+ if (!files[baseName]) files[baseName] = [];
6195
+ if (!files[baseName]?.some((e) => e === json)) {
6196
+ files[baseName].push(json);
6197
+ }
6198
+ }
6199
+ for (const [baseName, jsons] of Object.entries(files)) {
6200
+ await Promise.all(
6201
+ jsons.map(async (json, index) => {
6202
+ let fullName;
6203
+ if (index === 0) {
6204
+ fullName = `${baseName}.typeschema.json`;
6205
+ } else {
6206
+ fullName = `${baseName}-${index}.typeschema.json`;
6207
+ }
6208
+ await afs3.mkdir(Path4.dirname(fullName), { recursive: true });
6209
+ await afs3.writeFile(fullName, json);
6210
+ })
6211
+ );
6212
+ }
6213
+ };
6214
+ var writeTypeSchemasToSingleFile = async (typeSchemas, outputFile, logger) => {
6215
+ logger.info(`Writing TypeSchema files to: ${outputFile}`);
6216
+ await afs3.mkdir(Path4.dirname(outputFile), { recursive: true });
6217
+ logger.info(`Writing TypeSchemas to one file ${outputFile}...`);
6218
+ for (const ts of typeSchemas) {
6219
+ const json = JSON.stringify(ts, null, 2);
6220
+ await afs3.appendFile(outputFile, `${json}
6221
+ `);
6222
+ }
6223
+ };
6224
+ var tryWriteTypeSchema = async (typeSchemas, opts, logger) => {
6225
+ if (!opts.typeSchemaOutputDir) return;
6226
+ try {
6227
+ if (Path4.extname(opts.typeSchemaOutputDir) === ".ndjson") {
6228
+ await writeTypeSchemasToSingleFile(typeSchemas, opts.typeSchemaOutputDir, logger);
6229
+ } else {
6230
+ await writeTypeSchemasToSeparateFiles(typeSchemas, opts.typeSchemaOutputDir, logger);
6231
+ }
6232
+ logger.info(`Writing TypeSchema - DONE`);
6233
+ } catch (error) {
6234
+ logger.error("Failed to write TypeSchema output", error instanceof Error ? error : new Error(String(error)));
6235
+ if (opts.throwException) throw error;
6236
+ }
6237
+ };
6158
6238
  var APIBuilder = class {
6159
6239
  schemas = [];
6160
6240
  options;
@@ -6190,7 +6270,8 @@ var APIBuilder = class {
6190
6270
  }
6191
6271
  }
6192
6272
  fromPackage(packageName, version) {
6193
- this.packages.push(packageMetaToNpm({ name: packageName, version: version || "latest" }));
6273
+ const pkg = packageMetaToNpm({ name: packageName, version: version || "latest" });
6274
+ this.packages.push(pkg);
6194
6275
  return this;
6195
6276
  }
6196
6277
  fromFiles(...filePaths) {
@@ -6298,7 +6379,7 @@ var APIBuilder = class {
6298
6379
  this.options.exportTypeTree = filename;
6299
6380
  return this;
6300
6381
  }
6301
- treeShakeBy(tree) {
6382
+ treeShake(tree) {
6302
6383
  this.options.treeShake = tree;
6303
6384
  return this;
6304
6385
  }
@@ -6306,92 +6387,6 @@ var APIBuilder = class {
6306
6387
  this.options.typeSchemaOutputDir = target;
6307
6388
  return this;
6308
6389
  }
6309
- async writeTypeSchemasToSeparateFiles(typeSchemas, outputDir) {
6310
- await afs3.mkdir(outputDir, { recursive: true });
6311
- this.logger.info(`Writing TypeSchema files to ${outputDir}/...`);
6312
- const files = {};
6313
- for (const ts of typeSchemas) {
6314
- const pkg = {
6315
- name: ts.identifier.package,
6316
- version: ts.identifier.version
6317
- };
6318
- const pkgPath = normalizeFileName(packageMetaToFhir(pkg));
6319
- const name = normalizeFileName(`${ts.identifier.name}(${extractNameFromCanonical(ts.identifier.url)})`);
6320
- const json = JSON.stringify(ts, null, 2);
6321
- const baseName = Path4.join(outputDir, pkgPath, name);
6322
- if (!files[baseName]) files[baseName] = [];
6323
- if (!files[baseName]?.some((e) => e === json)) {
6324
- files[baseName].push(json);
6325
- }
6326
- }
6327
- for (const [baseName, jsons] of Object.entries(files)) {
6328
- await Promise.all(
6329
- jsons.map(async (json, index) => {
6330
- let fullName;
6331
- if (index === 0) {
6332
- fullName = `${baseName}.typeschema.json`;
6333
- } else {
6334
- fullName = `${baseName}-${index}.typeschema.json`;
6335
- }
6336
- await afs3.mkdir(Path4.dirname(fullName), { recursive: true });
6337
- await afs3.writeFile(fullName, json);
6338
- })
6339
- );
6340
- }
6341
- }
6342
- async writeTypeSchemasToSingleFile(typeSchemas, outputFile) {
6343
- this.logger.info(`Writing TypeSchema files to: ${outputFile}`);
6344
- if (this.options.cleanOutput && fs.existsSync(outputFile)) fs.rmSync(outputFile);
6345
- await afs3.mkdir(Path4.dirname(outputFile), { recursive: true });
6346
- this.logger.info(`Writing TypeSchemas to one file ${outputFile}...`);
6347
- for (const ts of typeSchemas) {
6348
- const json = JSON.stringify(ts, null, 2);
6349
- await afs3.appendFile(outputFile, `${json}
6350
- `);
6351
- }
6352
- }
6353
- async tryWriteTypeSchema(typeSchemas) {
6354
- if (!this.options.typeSchemaOutputDir) return;
6355
- try {
6356
- if (Path4.extname(this.options.typeSchemaOutputDir) === ".ndjson") {
6357
- await this.writeTypeSchemasToSingleFile(typeSchemas, this.options.typeSchemaOutputDir);
6358
- } else {
6359
- await this.writeTypeSchemasToSeparateFiles(typeSchemas, this.options.typeSchemaOutputDir);
6360
- }
6361
- this.logger.info(`Writing TypeSchema - DONE`);
6362
- } catch (error) {
6363
- this.logger.error(
6364
- "Failed to write TypeSchema output",
6365
- error instanceof Error ? error : new Error(String(error))
6366
- );
6367
- if (this.options.throwException) throw error;
6368
- }
6369
- }
6370
- async cleanup() {
6371
- this.logger.info(`Cleaning outputs...`);
6372
- try {
6373
- this.logger.info(`Clean ${this.options.outputDir}`);
6374
- fs.rmSync(this.options.outputDir, { recursive: true, force: true });
6375
- if (this.options.typeSchemaOutputDir) {
6376
- this.logger.info(`Clean ${this.options.typeSchemaOutputDir}`);
6377
- fs.rmSync(this.options.typeSchemaOutputDir, {
6378
- recursive: true,
6379
- force: true
6380
- });
6381
- }
6382
- if (this.options.exportTypeTree) {
6383
- this.logger.info(`Clean ${this.options.exportTypeTree}`);
6384
- fs.rmSync(this.options.exportTypeTree, {
6385
- recursive: true,
6386
- force: true
6387
- });
6388
- }
6389
- } catch (error) {
6390
- this.logger.warn(
6391
- `Error cleaning output directory: ${error instanceof Error ? error.message : String(error)}`
6392
- );
6393
- }
6394
- }
6395
6390
  async generate() {
6396
6391
  const startTime = performance.now();
6397
6392
  const result = {
@@ -6404,7 +6399,7 @@ var APIBuilder = class {
6404
6399
  };
6405
6400
  this.logger.debug(`Starting generation with ${this.generators.size} generators`);
6406
6401
  try {
6407
- if (this.options.cleanOutput) this.cleanup();
6402
+ if (this.options.cleanOutput) cleanup(this.options, this.logger);
6408
6403
  this.logger.info("Initialize Canonical Manager");
6409
6404
  const manager = CanonicalManager({
6410
6405
  packages: this.packages,
@@ -6416,7 +6411,7 @@ var APIBuilder = class {
6416
6411
  focusedPackages: this.packages.map(npmToPackageMeta)
6417
6412
  });
6418
6413
  const typeSchemas = await generateTypeSchemas(register, this.logger);
6419
- await this.tryWriteTypeSchema(typeSchemas);
6414
+ await tryWriteTypeSchema(typeSchemas, this.options, this.logger);
6420
6415
  let tsIndex = mkTypeSchemaIndex(typeSchemas, this.logger);
6421
6416
  if (this.options.treeShake) tsIndex = treeShake(tsIndex, this.options.treeShake, this.logger);
6422
6417
  if (this.options.exportTypeTree) await tsIndex.exportTree(this.options.exportTypeTree);
@@ -6508,9 +6503,6 @@ var APIBuilder = class {
6508
6503
  }
6509
6504
  }
6510
6505
  };
6511
- function createAPI(options) {
6512
- return new APIBuilder(options);
6513
- }
6514
6506
  function createAPIFromConfig(config) {
6515
6507
  const builder = new APIBuilder({
6516
6508
  outputDir: config.outputDir,
@@ -6533,18 +6525,6 @@ function createAPIFromConfig(config) {
6533
6525
  }
6534
6526
  return builder;
6535
6527
  }
6536
- async function generateTypesFromPackage(packageName, outputDir, options = {}) {
6537
- return createAPI({
6538
- outputDir,
6539
- verbose: options.verbose
6540
- }).fromPackage(packageName, options.version).typescriptDepricated().generate();
6541
- }
6542
- async function generateTypesFromFiles(inputFiles, outputDir, options = {}) {
6543
- return createAPI({
6544
- outputDir,
6545
- verbose: options.verbose
6546
- }).fromFiles(...inputFiles).typescriptDepricated().generate();
6547
- }
6548
6528
  var DEFAULT_CONFIG = {
6549
6529
  outputDir: "./generated",
6550
6530
  verbose: false,
@@ -7057,6 +7037,6 @@ function defineConfig(config) {
7057
7037
  return config;
7058
7038
  }
7059
7039
 
7060
- export { APIBuilder, CONFIG_FILE_NAMES, ConfigLoader, ConfigValidator, DEFAULT_CONFIG, TypeSchemaCache, TypeSchemaGenerator, TypeSchemaParser, TypeScriptGenerator, configLoader, createAPI, createAPIFromConfig, defineConfig, generateTypesFromFiles, generateTypesFromPackage, isConfig, loadConfig };
7040
+ export { APIBuilder, CONFIG_FILE_NAMES, ConfigLoader, ConfigValidator, DEFAULT_CONFIG, TypeSchemaCache, TypeSchemaGenerator, TypeSchemaParser, TypeScriptGenerator, configLoader, createAPIFromConfig, defineConfig, isConfig, loadConfig };
7061
7041
  //# sourceMappingURL=index.js.map
7062
7042
  //# sourceMappingURL=index.js.map