@atomic-ehr/codegen 0.0.4-canary.20251218111944.d18e50d → 0.0.4-canary.20251223082214.2093b82
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/assets/api/writer-generator/csharp/Client.cs +333 -0
- package/assets/api/writer-generator/csharp/Helper.cs +19 -0
- package/dist/cli/index.js +11 -11
- package/dist/index.d.ts +9 -8
- package/dist/index.js +55 -23
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -6,8 +6,8 @@ import { readFile } from 'fs/promises';
|
|
|
6
6
|
import * as Path5 from 'path';
|
|
7
7
|
import Path5__default, { resolve } from 'path';
|
|
8
8
|
import { CanonicalManager } from '@atomic-ehr/fhir-canonical-manager';
|
|
9
|
-
import assert3 from 'assert';
|
|
10
9
|
import { fileURLToPath } from 'url';
|
|
10
|
+
import assert3 from 'assert';
|
|
11
11
|
import * as YAML from 'yaml';
|
|
12
12
|
import * as fhirschema from '@atomic-ehr/fhirschema';
|
|
13
13
|
import { isStructureDefinition } from '@atomic-ehr/fhirschema';
|
|
@@ -21,6 +21,22 @@ var LogLevel = /* @__PURE__ */ ((LogLevel2) => {
|
|
|
21
21
|
LogLevel2[LogLevel2["SILENT"] = 4] = "SILENT";
|
|
22
22
|
return LogLevel2;
|
|
23
23
|
})(LogLevel || {});
|
|
24
|
+
var parseLogLevel = (level) => {
|
|
25
|
+
switch (level.toUpperCase()) {
|
|
26
|
+
case "DEBUG":
|
|
27
|
+
return 0 /* DEBUG */;
|
|
28
|
+
case "INFO":
|
|
29
|
+
return 1 /* INFO */;
|
|
30
|
+
case "WARN":
|
|
31
|
+
return 2 /* WARN */;
|
|
32
|
+
case "ERROR":
|
|
33
|
+
return 3 /* ERROR */;
|
|
34
|
+
case "SILENT":
|
|
35
|
+
return 4 /* SILENT */;
|
|
36
|
+
default:
|
|
37
|
+
throw new Error(`Invalid log level: ${level}`);
|
|
38
|
+
}
|
|
39
|
+
};
|
|
24
40
|
var CodegenLogger = class _CodegenLogger {
|
|
25
41
|
options;
|
|
26
42
|
dryWarnSet = /* @__PURE__ */ new Set();
|
|
@@ -472,6 +488,15 @@ function formatName(input) {
|
|
|
472
488
|
}
|
|
473
489
|
|
|
474
490
|
// src/api/writer-generator/csharp/csharp.ts
|
|
491
|
+
var resolveCSharpAssets = (fn) => {
|
|
492
|
+
const __filename2 = fileURLToPath(import.meta.url);
|
|
493
|
+
const __dirname = Path5__default.dirname(__filename2);
|
|
494
|
+
if (__filename2.endsWith("dist/index.js")) {
|
|
495
|
+
return Path5__default.resolve(__dirname, "..", "assets", "api", "writer-generator", "csharp", fn);
|
|
496
|
+
} else {
|
|
497
|
+
return Path5__default.resolve(__dirname, "../../../..", "assets", "api", "writer-generator", "csharp", fn);
|
|
498
|
+
}
|
|
499
|
+
};
|
|
475
500
|
var PRIMITIVE_TYPE_MAP = {
|
|
476
501
|
boolean: "bool",
|
|
477
502
|
instant: "string",
|
|
@@ -642,8 +667,8 @@ var CSharp = class extends Writer {
|
|
|
642
667
|
"CSharpSDK",
|
|
643
668
|
"System.Text.Json",
|
|
644
669
|
"System.Text.Json.Serialization",
|
|
645
|
-
this.opts.
|
|
646
|
-
...packages.map((pkg) => `${this.opts.
|
|
670
|
+
this.opts.rootNamespace,
|
|
671
|
+
...packages.map((pkg) => `${this.opts.rootNamespace}.${pkg}`)
|
|
647
672
|
];
|
|
648
673
|
for (const using of globalUsings) this.lineSM("global", "using", using);
|
|
649
674
|
}
|
|
@@ -652,7 +677,7 @@ var CSharp = class extends Writer {
|
|
|
652
677
|
this.cat("base.cs", () => {
|
|
653
678
|
this.generateDisclaimer();
|
|
654
679
|
this.line();
|
|
655
|
-
this.lineSM("namespace", this.opts.
|
|
680
|
+
this.lineSM("namespace", this.opts.rootNamespace);
|
|
656
681
|
for (const schema of complexTypes) {
|
|
657
682
|
const packageName = formatName(schema.identifier.package);
|
|
658
683
|
this.generateType(schema, packageName);
|
|
@@ -669,7 +694,7 @@ var CSharp = class extends Writer {
|
|
|
669
694
|
this.cat(`${schema.identifier.name}.cs`, () => {
|
|
670
695
|
this.generateDisclaimer();
|
|
671
696
|
this.line();
|
|
672
|
-
this.lineSM("namespace", `${this.opts.
|
|
697
|
+
this.lineSM("namespace", `${this.opts.rootNamespace}.${packageName}`);
|
|
673
698
|
this.line();
|
|
674
699
|
this.generateType(schema, packageName);
|
|
675
700
|
});
|
|
@@ -693,7 +718,7 @@ var CSharp = class extends Writer {
|
|
|
693
718
|
generateEnumFileContent(packageName, enums) {
|
|
694
719
|
this.lineSM("using", "System.ComponentModel");
|
|
695
720
|
this.line();
|
|
696
|
-
this.lineSM(`namespace ${this.opts.
|
|
721
|
+
this.lineSM(`namespace ${this.opts.rootNamespace}.${packageName}`);
|
|
697
722
|
for (const [enumName, values] of Object.entries(enums)) {
|
|
698
723
|
this.generateEnum(enumName, values);
|
|
699
724
|
}
|
|
@@ -715,7 +740,7 @@ var CSharp = class extends Writer {
|
|
|
715
740
|
this.cat(`${packageName}ResourceDictionary.cs`, () => {
|
|
716
741
|
this.generateDisclaimer();
|
|
717
742
|
this.line();
|
|
718
|
-
this.lineSM(`namespace ${this.opts.
|
|
743
|
+
this.lineSM(`namespace ${this.opts.rootNamespace}`);
|
|
719
744
|
this.generateResourceDictionaryClass(packageName, packageResources);
|
|
720
745
|
});
|
|
721
746
|
}
|
|
@@ -733,12 +758,13 @@ var CSharp = class extends Writer {
|
|
|
733
758
|
});
|
|
734
759
|
}
|
|
735
760
|
copyStaticFiles() {
|
|
736
|
-
if (
|
|
737
|
-
const
|
|
738
|
-
fs__default.cpSync(
|
|
761
|
+
if (this.opts.inMemoryOnly) return;
|
|
762
|
+
const sourceDir = resolveCSharpAssets("");
|
|
763
|
+
fs__default.cpSync(sourceDir, this.opts.outputDir, { recursive: true });
|
|
739
764
|
}
|
|
740
765
|
generateHelperFile() {
|
|
741
|
-
|
|
766
|
+
if (this.opts.inMemoryOnly) return;
|
|
767
|
+
const sourceFile = resolveCSharpAssets("Helper.cs");
|
|
742
768
|
const destFile = Path5__default.join(this.opts.outputDir, "Helper.cs");
|
|
743
769
|
fs__default.copyFileSync(sourceFile, destFile);
|
|
744
770
|
}
|
|
@@ -3009,18 +3035,24 @@ var APIBuilder = class {
|
|
|
3009
3035
|
this.logger.debug(`Configured python generator`);
|
|
3010
3036
|
return this;
|
|
3011
3037
|
}
|
|
3012
|
-
csharp(
|
|
3013
|
-
const
|
|
3038
|
+
csharp(userOptions) {
|
|
3039
|
+
const defaultWriterOpts = {
|
|
3040
|
+
logger: this.logger,
|
|
3014
3041
|
outputDir: Path5.join(this.options.outputDir, "/types"),
|
|
3015
|
-
|
|
3016
|
-
|
|
3017
|
-
|
|
3018
|
-
|
|
3019
|
-
|
|
3020
|
-
|
|
3021
|
-
|
|
3022
|
-
}
|
|
3023
|
-
|
|
3042
|
+
tabSize: 4,
|
|
3043
|
+
withDebugComment: false,
|
|
3044
|
+
commentLinePrefix: "//"
|
|
3045
|
+
};
|
|
3046
|
+
const defaultCSharpOpts = {
|
|
3047
|
+
...defaultWriterOpts,
|
|
3048
|
+
rootNamespace: "Fhir.Types"
|
|
3049
|
+
};
|
|
3050
|
+
const opts = {
|
|
3051
|
+
...defaultCSharpOpts,
|
|
3052
|
+
...Object.fromEntries(Object.entries(userOptions).filter(([_, v]) => v !== void 0))
|
|
3053
|
+
};
|
|
3054
|
+
const generator = new CSharp(opts);
|
|
3055
|
+
this.generators.set("csharp", generator);
|
|
3024
3056
|
this.logger.debug(`Configured C# generator`);
|
|
3025
3057
|
return this;
|
|
3026
3058
|
}
|
|
@@ -3043,7 +3075,7 @@ var APIBuilder = class {
|
|
|
3043
3075
|
return this;
|
|
3044
3076
|
}
|
|
3045
3077
|
setLogLevel(level) {
|
|
3046
|
-
this.logger?.setLevel(level);
|
|
3078
|
+
this.logger?.setLevel(typeof level === "string" ? parseLogLevel(level) : level);
|
|
3047
3079
|
return this;
|
|
3048
3080
|
}
|
|
3049
3081
|
throwException(enabled = true) {
|