@atomic-ehr/codegen 0.0.1-canary.20251014085150.f19c2e1 → 0.0.1-canary.20251015064414.0fcee22

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
@@ -830,6 +830,9 @@ declare class APIBuilder {
830
830
  throwException(enabled?: boolean): APIBuilder;
831
831
  cleanOutput(enabled?: boolean): APIBuilder;
832
832
  writeTypeSchemas(target: string): this;
833
+ private static isIdenticalTo;
834
+ private writeTypeSchemasToSeparateFiles;
835
+ private writeTypeSchemasToSingleFile;
833
836
  private tryWriteTypeSchema;
834
837
  generate(): Promise<GenerationResult>;
835
838
  /**
package/dist/index.js CHANGED
@@ -2256,7 +2256,7 @@ var CodegenLogger = class _CodegenLogger {
2256
2256
  */
2257
2257
  error(message, error) {
2258
2258
  if (this.isSuppressed(3 /* ERROR */)) return;
2259
- console.error(this.formatMessage("", message, pc.red));
2259
+ console.error(this.formatMessage("X", message, pc.red));
2260
2260
  if (error && this.options.verbose) {
2261
2261
  console.error(pc.red(` ${error.message}`));
2262
2262
  if (error.stack) {
@@ -3012,6 +3012,23 @@ var uppercaseFirstLetter = (str) => {
3012
3012
  var uppercaseFirstLetterOfEach = (strings) => {
3013
3013
  return strings.map((str) => uppercaseFirstLetter(str));
3014
3014
  };
3015
+ function deepEqual(obj1, obj2) {
3016
+ if (obj1 === obj2) return true;
3017
+ if (obj1 === null || obj2 === null || typeof obj1 !== "object" || typeof obj2 !== "object") {
3018
+ return false;
3019
+ }
3020
+ if (Array.isArray(obj1) && Array.isArray(obj2)) {
3021
+ if (obj1.length !== obj2.length) return false;
3022
+ return obj1.every((item, index) => deepEqual(item, obj2[index]));
3023
+ }
3024
+ if (Array.isArray(obj1) || Array.isArray(obj2)) {
3025
+ return false;
3026
+ }
3027
+ const keys1 = Object.keys(obj1);
3028
+ const keys2 = Object.keys(obj2);
3029
+ if (keys1.length !== keys2.length) return false;
3030
+ return keys1.every((key) => keys2.includes(key) && deepEqual(obj1[key], obj2[key]));
3031
+ }
3015
3032
 
3016
3033
  // src/typeschema/utils.ts
3017
3034
  var groupByPackages = (typeSchemas) => {
@@ -5724,7 +5741,7 @@ var writerToGenerator = (writerGen) => {
5724
5741
  };
5725
5742
  };
5726
5743
  var normalizeFileName = (str) => str.replace(/[^a-zA-Z0-9]/g, "");
5727
- var APIBuilder = class {
5744
+ var APIBuilder = class _APIBuilder {
5728
5745
  schemas = [];
5729
5746
  options;
5730
5747
  generators = /* @__PURE__ */ new Map();
@@ -5852,33 +5869,53 @@ var APIBuilder = class {
5852
5869
  this.options.typeSchemaOutputDir = target;
5853
5870
  return this;
5854
5871
  }
5872
+ static async isIdenticalTo(path, tsJSON) {
5873
+ if (!await afs.exists(path)) return false;
5874
+ const json = await afs.readFile(path);
5875
+ const ts1 = JSON.parse(json.toString());
5876
+ const ts2 = JSON.parse(tsJSON);
5877
+ return deepEqual(ts1, ts2);
5878
+ }
5879
+ async writeTypeSchemasToSeparateFiles(typeSchemas, outputDir) {
5880
+ if (this.options.cleanOutput) fs.rmSync(outputDir, { recursive: true, force: true });
5881
+ await afs.mkdir(outputDir, { recursive: true });
5882
+ const usedNames = {};
5883
+ this.logger.info(`Writing TypeSchema files to ${outputDir}...`);
5884
+ for (const ts of typeSchemas) {
5885
+ const package_name = camelCase(ts.identifier.package.replaceAll("/", "-"));
5886
+ const name = normalizeFileName(ts.identifier.name.toString());
5887
+ const json = JSON.stringify(ts, null, 2);
5888
+ const baseName = Path2.join(outputDir, package_name, name);
5889
+ let fullName;
5890
+ if (usedNames[baseName] !== void 0) {
5891
+ usedNames[baseName]++;
5892
+ fullName = `${baseName}-${usedNames[baseName]}.typeschema.json`;
5893
+ } else {
5894
+ usedNames[baseName] = 0;
5895
+ fullName = `${baseName}.typeschema.json`;
5896
+ }
5897
+ if (await _APIBuilder.isIdenticalTo(fullName, json)) continue;
5898
+ await afs.mkdir(Path2.dirname(fullName), { recursive: true });
5899
+ await afs.writeFile(fullName, json);
5900
+ }
5901
+ }
5902
+ async writeTypeSchemasToSingleFile(typeSchemas, outputFile) {
5903
+ if (this.options.cleanOutput && fs.existsSync(outputFile)) fs.rmSync(outputFile);
5904
+ await afs.mkdir(Path2.dirname(outputFile), { recursive: true });
5905
+ this.logger.info(`Writing TypeSchemas to one file ${outputFile}...`);
5906
+ for (const ts of typeSchemas) {
5907
+ const json = JSON.stringify(ts, null, 2);
5908
+ await afs.appendFile(outputFile, json + "\n");
5909
+ }
5910
+ }
5855
5911
  async tryWriteTypeSchema(typeSchemas) {
5856
5912
  if (!this.options.typeSchemaOutputDir) return;
5857
5913
  try {
5858
- if (this.options.cleanOutput) fs.rmSync(this.options.typeSchemaOutputDir, { recursive: true, force: true });
5859
- await afs.mkdir(this.options.typeSchemaOutputDir, { recursive: true });
5860
- let writtenCount = 0;
5861
- let overrideCount = 0;
5862
- const usedNames = {};
5863
- this.logger.info(`Writing TypeSchema files to ${this.options.typeSchemaOutputDir}...`);
5864
- for (const ts of typeSchemas) {
5865
- const package_name = camelCase(ts.identifier.package.replaceAll("/", "-"));
5866
- const name = normalizeFileName(ts.identifier.name.toString());
5867
- const baseName = Path2.join(this.options.typeSchemaOutputDir, package_name, name);
5868
- let fullName;
5869
- if (usedNames[baseName] !== void 0) {
5870
- usedNames[baseName]++;
5871
- fullName = `${baseName}-${usedNames[baseName]}.typeschema.json`;
5872
- } else {
5873
- usedNames[baseName] = 0;
5874
- fullName = `${baseName}.typeschema.json`;
5875
- }
5876
- await afs.mkdir(Path2.dirname(fullName), { recursive: true });
5877
- afs.writeFile(fullName, JSON.stringify(ts, null, 2));
5878
- if (await afs.exists(fullName)) overrideCount++;
5879
- else writtenCount++;
5880
- }
5881
- this.logger.info(`Created ${writtenCount} new TypeSchema files, overrode ${overrideCount} files`);
5914
+ this.logger.info(`Starting writing TypeSchema files.`);
5915
+ if (Path2.extname(this.options.typeSchemaOutputDir) === ".ndjson")
5916
+ await this.writeTypeSchemasToSingleFile(typeSchemas, this.options.typeSchemaOutputDir);
5917
+ else await this.writeTypeSchemasToSeparateFiles(typeSchemas, this.options.typeSchemaOutputDir);
5918
+ this.logger.info(`Finished writing TypeSchema files.`);
5882
5919
  } catch (error) {
5883
5920
  if (this.options.throwException) throw error;
5884
5921
  this.logger.error(