@atomic-ehr/codegen 0.0.1-canary.20250811151625.dc70a39 → 0.0.1-canary.20250811234617.ea1d6c1

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.
@@ -47,6 +47,8 @@ export declare class TypeScriptAPIGenerator {
47
47
  private resourceTypes;
48
48
  private currentSchemaName?;
49
49
  private profileTypes;
50
+ private profilesByPackage;
51
+ private packageNameMap;
50
52
  private enumTypes;
51
53
  private globalEnumTypes;
52
54
  private fieldEnumMap;
@@ -104,6 +106,10 @@ export declare class TypeScriptAPIGenerator {
104
106
  getOptions(): TypeScriptAPIOptions;
105
107
  private generateIndexFile;
106
108
  private ensureDirectoryExists;
109
+ /**
110
+ * Clean the output directory by removing all existing files and subdirectories
111
+ */
112
+ private cleanOutputDirectory;
107
113
  /**
108
114
  * Filter schemas based on includeExtensions option
109
115
  */
@@ -112,6 +118,18 @@ export declare class TypeScriptAPIGenerator {
112
118
  * Generate index files for subfolders
113
119
  */
114
120
  private generateSubfolderIndexFiles;
121
+ /**
122
+ * Generate profile index files with package-based organization
123
+ */
124
+ private generateProfileIndexFiles;
125
+ /**
126
+ * Generate index file for a specific package
127
+ */
128
+ private generatePackageIndex;
129
+ /**
130
+ * Generate main profiles index with namespace exports
131
+ */
132
+ private generateMainProfilesIndex;
115
133
  /**
116
134
  * Generate index content for a subfolder
117
135
  */
@@ -132,6 +150,18 @@ export declare class TypeScriptAPIGenerator {
132
150
  * Get filename for schema
133
151
  */
134
152
  private getFilename;
153
+ /**
154
+ * Sanitize package name for use as directory name
155
+ */
156
+ private sanitizePackageName;
157
+ /**
158
+ * Generate namespace name from original package name by capitalizing each dot-separated segment
159
+ */
160
+ private generateNamespaceName;
161
+ /**
162
+ * Calculate the correct import path from current profile to base type
163
+ */
164
+ private calculateImportPath;
135
165
  /**
136
166
  * Generate TypeScript for a profile schema
137
167
  */
@@ -1 +1 @@
1
- {"version":3,"file":"typescript.d.ts","sourceRoot":"","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GAAG,IAAI;IAIxD;;OAEG;IACH,UAAU,IAAI,oBAAoB;YAIpB,iBAAiB;YA2IjB,qBAAqB;IAKnC;;OAEG;YACW,oBAAoB;IAelC;;OAEG;IACH,OAAO,CAAC,aAAa;IASrB;;OAEG;YACW,2BAA2B;IAuCzC;;OAEG;YACW,yBAAyB;IAyCvC;;OAEG;IACH,OAAO,CAAC,oBAAoB;IA8B5B;;OAEG;IACH,OAAO,CAAC,yBAAyB;IA+BjC;;OAEG;IACH,OAAO,CAAC,sBAAsB;IA4C9B;;OAEG;IACH,OAAO,CAAC,cAAc;IAOtB;;OAEG;IACH,OAAO,CAAC,OAAO;IAaf;;OAEG;IACH,OAAO,CAAC,gBAAgB;IAuBxB;;OAEG;IACH,OAAO,CAAC,WAAW;IAuBnB;;OAEG;IACH,OAAO,CAAC,mBAAmB;IAQ3B;;OAEG;IACH,OAAO,CAAC,qBAAqB;IAQ7B;;OAEG;IACH,OAAO,CAAC,mBAAmB;IAwB3B;;OAEG;YACW,eAAe;IA0B7B;;OAEG;IACH,OAAO,CAAC,4BAA4B;IAiGpC;;OAEG;IACH,OAAO,CAAC,oBAAoB;IA8E5B;;OAEG;IACH,OAAO,CAAC,wBAAwB;IAqFhC;;OAEG;IACH,OAAO,CAAC,+BAA+B;IA+EvC;;OAEG;IACH,OAAO,CAAC,4BAA4B;IAgDpC;;OAEG;IACH,OAAO,CAAC,gBAAgB;IA6BxB;;OAEG;IACH,OAAO,CAAC,iBAAiB;IAwBzB;;OAEG;IACH,OAAO,CAAC,YAAY;IAIpB;;OAEG;IACH,OAAO,CAAC,wBAAwB;CAqGhC"}
package/dist/cli/index.js CHANGED
@@ -17,7 +17,7 @@ import {
17
17
  step,
18
18
  success,
19
19
  warn
20
- } from "../index-ggpfvj56.js";
20
+ } from "../index-ts25e982.js";
21
21
 
22
22
  // node_modules/emoji-regex/index.js
23
23
  var require_emoji_regex = __commonJS((exports, module) => {
@@ -4997,7 +4997,7 @@ ${resourceTypesArray.map((type) => ` '${type}': ${type};`).join(`
4997
4997
  }
4998
4998
 
4999
4999
  // src/api/generators/typescript.ts
5000
- import { mkdir as mkdir3, writeFile as writeFile5 } from "node:fs/promises";
5000
+ import { access as access2, mkdir as mkdir3, rm, writeFile as writeFile5 } from "node:fs/promises";
5001
5001
  import { dirname as dirname2, join as join11 } from "node:path";
5002
5002
 
5003
5003
  // src/utils.ts
@@ -5039,6 +5039,8 @@ class TypeScriptAPIGenerator {
5039
5039
  resourceTypes = new Set;
5040
5040
  currentSchemaName;
5041
5041
  profileTypes = new Set;
5042
+ profilesByPackage = new Map;
5043
+ packageNameMap = new Map;
5042
5044
  enumTypes = new Map;
5043
5045
  globalEnumTypes = new Map;
5044
5046
  fieldEnumMap = new Map;
@@ -5247,6 +5249,7 @@ class TypeScriptAPIGenerator {
5247
5249
  const filteredSchemas = this.filterSchemas(schemas);
5248
5250
  const results = await this.transformSchemas(filteredSchemas);
5249
5251
  const generatedFiles = [];
5252
+ await this.cleanOutputDirectory();
5250
5253
  await mkdir3(this.options.outputDir, { recursive: true });
5251
5254
  if (this.options.includeProfiles) {
5252
5255
  await mkdir3(join11(this.options.outputDir, "profiles"), {
@@ -5468,6 +5471,17 @@ ${result.content}` : result.content;
5468
5471
  const dir = dirname2(filePath);
5469
5472
  await mkdir3(dir, { recursive: true });
5470
5473
  }
5474
+ async cleanOutputDirectory() {
5475
+ try {
5476
+ await access2(this.options.outputDir);
5477
+ this.logger.debug(`Cleaning output directory: ${this.options.outputDir}`);
5478
+ await rm(this.options.outputDir, { recursive: true, force: true });
5479
+ } catch (error2) {
5480
+ if (error2?.code !== "ENOENT") {
5481
+ this.logger.warn(`Failed to clean output directory: ${error2}`);
5482
+ }
5483
+ }
5484
+ }
5471
5485
  filterSchemas(schemas) {
5472
5486
  if (this.options.includeExtensions) {
5473
5487
  return schemas;
@@ -5483,17 +5497,88 @@ ${result.content}` : result.content;
5483
5497
  subfolders.push("profiles");
5484
5498
  }
5485
5499
  for (const subfolder of subfolders) {
5486
- const subfolderResults = results.filter((r) => r.filename.startsWith(`${subfolder}/`));
5487
- const indexContent = this.generateSubfolderIndex(subfolderResults, subfolder);
5488
- const indexPath = join11(this.options.outputDir, subfolder, "index.ts");
5489
- await writeFile5(indexPath, indexContent, "utf-8");
5500
+ if (subfolder === "profiles") {
5501
+ await this.generateProfileIndexFiles(generatedFiles);
5502
+ } else {
5503
+ const subfolderResults = results.filter((r) => r.filename.startsWith(`${subfolder}/`));
5504
+ const indexContent = this.generateSubfolderIndex(subfolderResults, subfolder);
5505
+ const indexPath = join11(this.options.outputDir, subfolder, "index.ts");
5506
+ await writeFile5(indexPath, indexContent, "utf-8");
5507
+ generatedFiles.push({
5508
+ path: indexPath,
5509
+ filename: `${subfolder}/index.ts`,
5510
+ content: indexContent,
5511
+ exports: subfolderResults.flatMap((r) => r.exports)
5512
+ });
5513
+ }
5514
+ }
5515
+ }
5516
+ async generateProfileIndexFiles(generatedFiles) {
5517
+ for (const [
5518
+ packageName,
5519
+ profileNames
5520
+ ] of this.profilesByPackage.entries()) {
5521
+ const packageIndexContent = this.generatePackageIndex(packageName, profileNames);
5522
+ const packageIndexPath = join11(this.options.outputDir, "profiles", packageName, "index.ts");
5523
+ await writeFile5(packageIndexPath, packageIndexContent, "utf-8");
5490
5524
  generatedFiles.push({
5491
- path: indexPath,
5492
- filename: `${subfolder}/index.ts`,
5493
- content: indexContent,
5494
- exports: subfolderResults.flatMap((r) => r.exports)
5525
+ path: packageIndexPath,
5526
+ filename: `profiles/${packageName}/index.ts`,
5527
+ content: packageIndexContent,
5528
+ exports: profileNames
5495
5529
  });
5496
5530
  }
5531
+ const mainProfilesIndex = this.generateMainProfilesIndex();
5532
+ const mainIndexPath = join11(this.options.outputDir, "profiles", "index.ts");
5533
+ await writeFile5(mainIndexPath, mainProfilesIndex, "utf-8");
5534
+ generatedFiles.push({
5535
+ path: mainIndexPath,
5536
+ filename: "profiles/index.ts",
5537
+ content: mainProfilesIndex,
5538
+ exports: Array.from(this.profilesByPackage.keys())
5539
+ });
5540
+ }
5541
+ generatePackageIndex(packageName, profileNames) {
5542
+ const lines = [];
5543
+ lines.push("/**");
5544
+ lines.push(` * ${packageName} Profiles Index`);
5545
+ lines.push(" * ");
5546
+ lines.push(" * Auto-generated exports for all profile types in this package.");
5547
+ lines.push(" */");
5548
+ lines.push("");
5549
+ if (profileNames.length === 0) {
5550
+ lines.push("// No profiles in this package");
5551
+ lines.push("export {};");
5552
+ return lines.join(`
5553
+ `);
5554
+ }
5555
+ for (const profileName of profileNames) {
5556
+ lines.push(`export type { ${profileName} } from './${profileName}';`);
5557
+ }
5558
+ return lines.join(`
5559
+ `);
5560
+ }
5561
+ generateMainProfilesIndex() {
5562
+ const lines = [];
5563
+ lines.push("/**");
5564
+ lines.push(" * Profiles Index");
5565
+ lines.push(" * ");
5566
+ lines.push(" * Auto-generated namespace exports for all profile packages.");
5567
+ lines.push(" */");
5568
+ lines.push("");
5569
+ if (this.profilesByPackage.size === 0) {
5570
+ lines.push("// No profile packages found");
5571
+ lines.push("export {};");
5572
+ return lines.join(`
5573
+ `);
5574
+ }
5575
+ for (const sanitizedPackageName of this.profilesByPackage.keys()) {
5576
+ const originalPackageName = this.packageNameMap.get(sanitizedPackageName);
5577
+ const namespaceNameForExport = this.generateNamespaceName(originalPackageName);
5578
+ lines.push(`export * as ${namespaceNameForExport} from './${sanitizedPackageName}';`);
5579
+ }
5580
+ return lines.join(`
5581
+ `);
5497
5582
  }
5498
5583
  generateSubfolderIndex(results, subfolder) {
5499
5584
  const lines = [];
@@ -5543,18 +5628,49 @@ ${result.content}` : result.content;
5543
5628
  }
5544
5629
  getBaseInterface(schema) {
5545
5630
  if ((isTypeSchemaForResourceComplexTypeLogical(schema) || schema.identifier.kind === "profile") && schema.base) {
5546
- return this.getType(schema.base);
5631
+ const baseIdentifier = schema.base;
5632
+ const typeInfo = this.getType(baseIdentifier);
5633
+ return {
5634
+ ...typeInfo,
5635
+ baseIdentifier
5636
+ };
5547
5637
  }
5548
5638
  return null;
5549
5639
  }
5550
5640
  getFilename(identifier) {
5551
5641
  const name = toPascalCase(identifier.name);
5552
5642
  if (identifier.kind === "profile" && this.options.includeProfiles) {
5553
- const subfolder = "profiles";
5643
+ const originalPackageName = identifier.package;
5644
+ const sanitizedPackageName = this.sanitizePackageName(originalPackageName);
5645
+ const subfolder = `profiles/${sanitizedPackageName}`;
5646
+ if (!this.profilesByPackage.has(sanitizedPackageName)) {
5647
+ this.profilesByPackage.set(sanitizedPackageName, []);
5648
+ this.packageNameMap.set(sanitizedPackageName, originalPackageName);
5649
+ }
5650
+ this.profilesByPackage.get(sanitizedPackageName).push(name);
5554
5651
  return `${subfolder}/${name}.ts`;
5555
5652
  }
5556
5653
  return `${name}.ts`;
5557
5654
  }
5655
+ sanitizePackageName(packageName) {
5656
+ return packageName.replace(/[@/.]/g, "-").replace(/[^a-zA-Z0-9\-_]/g, "").toLowerCase();
5657
+ }
5658
+ generateNamespaceName(originalPackageName) {
5659
+ return originalPackageName.split(".").map((segment) => this.toPascalCase(segment)).join("");
5660
+ }
5661
+ calculateImportPath(currentSchema, baseIdentifier) {
5662
+ if (baseIdentifier.kind === "profile") {
5663
+ const currentPackage = this.sanitizePackageName(currentSchema.identifier.package);
5664
+ const basePackage = this.sanitizePackageName(baseIdentifier.package);
5665
+ if (currentPackage === basePackage) {
5666
+ return `./${this.formatTypeName(baseIdentifier.name)}`;
5667
+ } else {
5668
+ return `../${basePackage}/${this.formatTypeName(baseIdentifier.name)}`;
5669
+ }
5670
+ } else {
5671
+ return `../../${this.formatTypeName(baseIdentifier.name)}`;
5672
+ }
5673
+ }
5558
5674
  async generateProfile(schema) {
5559
5675
  this.imports.clear();
5560
5676
  this.exports.clear();
@@ -5582,9 +5698,9 @@ ${result.content}` : result.content;
5582
5698
  }
5583
5699
  this.exports.add(interfaceName);
5584
5700
  const baseInterface = this.getBaseInterface(schema);
5585
- if (baseInterface && !baseInterface.isPrimitive) {
5586
- const importPath = baseInterface.value;
5587
- this.imports.set(baseInterface.value, `../${importPath}`);
5701
+ if (baseInterface && !baseInterface.isPrimitive && baseInterface.baseIdentifier) {
5702
+ const importPath = this.calculateImportPath(schema, baseInterface.baseIdentifier);
5703
+ this.imports.set(baseInterface.value, importPath);
5588
5704
  lines.push(`export interface ${interfaceName} extends ${baseInterface.value} {`);
5589
5705
  } else {
5590
5706
  lines.push(`export interface ${interfaceName} {`);
@@ -5640,7 +5756,8 @@ ${result.content}` : result.content;
5640
5756
  } else if (field.type) {
5641
5757
  const subType = this.getType(field.type);
5642
5758
  if (!subType.isPrimitive) {
5643
- this.imports.set(subType.value, `../${subType.value}`);
5759
+ const importPath = this.calculateImportPath(schema, field.type);
5760
+ this.imports.set(subType.value, importPath);
5644
5761
  }
5645
5762
  typeString = subType.value;
5646
5763
  }
@@ -5652,7 +5769,8 @@ ${result.content}` : result.content;
5652
5769
  } else if (field.type) {
5653
5770
  const subType = this.getType(field.type);
5654
5771
  if (!subType.isPrimitive) {
5655
- this.imports.set(subType.value, `../${subType.value}`);
5772
+ const importPath = this.calculateImportPath(schema, field.type);
5773
+ this.imports.set(subType.value, importPath);
5656
5774
  }
5657
5775
  typeString = subType.value;
5658
5776
  }
@@ -5684,8 +5802,9 @@ ${result.content}` : result.content;
5684
5802
  lines.push("\tconst errors: string[] = [];");
5685
5803
  lines.push("");
5686
5804
  const baseInterface = this.getBaseInterface(schema);
5687
- if (baseInterface && !baseInterface.isPrimitive) {
5688
- this.imports.set(`is${baseInterface.value}`, `../${baseInterface.value}`);
5805
+ if (baseInterface && !baseInterface.isPrimitive && baseInterface.baseIdentifier) {
5806
+ const importPath = this.calculateImportPath(schema, baseInterface.baseIdentifier);
5807
+ this.imports.set(`is${baseInterface.value}`, importPath);
5689
5808
  lines.push(` // Validate base resource`);
5690
5809
  lines.push(` if (!is${baseInterface.value}(resource)) {`);
5691
5810
  lines.push(` return { valid: false, errors: ['Not a valid ${baseInterface.value} resource'] };`);
@@ -5722,7 +5841,7 @@ ${result.content}` : result.content;
5722
5841
  lines.push("\t\terrors");
5723
5842
  lines.push("\t};");
5724
5843
  lines.push("}");
5725
- this.imports.set("ValidationResult", "../types");
5844
+ this.imports.set("ValidationResult", "../../types");
5726
5845
  return lines.join(`
5727
5846
  `);
5728
5847
  }
@@ -5860,8 +5979,9 @@ ${result.content}` : result.content;
5860
5979
  lines.push(" */");
5861
5980
  lines.push(`export function ${guardName}(resource: unknown): resource is ${interfaceName} {`);
5862
5981
  const baseInterface = this.getBaseInterface(schema);
5863
- if (baseInterface && !baseInterface.isPrimitive) {
5864
- this.imports.set(`is${baseInterface.value}`, `../${baseInterface.value}`);
5982
+ if (baseInterface && !baseInterface.isPrimitive && baseInterface.baseIdentifier) {
5983
+ const importPath = this.calculateImportPath(schema, baseInterface.baseIdentifier);
5984
+ this.imports.set(`is${baseInterface.value}`, importPath);
5865
5985
  lines.push(` if (!is${baseInterface.value}(resource)) return false;`);
5866
5986
  lines.push("");
5867
5987
  lines.push(` const typed = resource as ${baseInterface.value};`);
package/dist/index.js CHANGED
@@ -16,7 +16,7 @@ import {
16
16
  generateTypesFromPackage,
17
17
  isConfig,
18
18
  loadConfig
19
- } from "./index-ggpfvj56.js";
19
+ } from "./index-ts25e982.js";
20
20
  export {
21
21
  loadConfig,
22
22
  isConfig,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atomic-ehr/codegen",
3
- "version": "0.0.1-canary.20250811151625.dc70a39",
3
+ "version": "0.0.1-canary.20250811234617.ea1d6c1",
4
4
  "description": "Code generation tools for FHIR resources and TypeSchema definitions",
5
5
  "keywords": [
6
6
  "fhir",