@atomic-ehr/codegen 0.0.1-canary.20251007114955.88a8afc → 0.0.1-canary.20251007144346.822c49c
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 +36 -23
- package/dist/index.d.ts +22 -1
- package/dist/index.js +315 -80
- package/dist/index.js.map +1 -1
- package/package.json +2 -1
package/dist/index.js
CHANGED
|
@@ -1414,7 +1414,7 @@ function isBindingSchema(schema) {
|
|
|
1414
1414
|
}
|
|
1415
1415
|
|
|
1416
1416
|
// src/typeschema/register.ts
|
|
1417
|
-
var registerFromManager = async (manager,
|
|
1417
|
+
var registerFromManager = async (manager, logger2) => {
|
|
1418
1418
|
const packages = await manager.packages();
|
|
1419
1419
|
const flatRawIndex = {};
|
|
1420
1420
|
const indexByPackages = [];
|
|
@@ -1450,7 +1450,7 @@ var registerFromManager = async (manager, logger) => {
|
|
|
1450
1450
|
nameToCanonical[rfs.name] = rfs.url;
|
|
1451
1451
|
fsSuccess++;
|
|
1452
1452
|
} catch (error) {
|
|
1453
|
-
|
|
1453
|
+
logger2?.warn(
|
|
1454
1454
|
`Failed to convert StructureDefinition ${sd.name || sd.id}: ${error instanceof Error ? error.message : String(error)}`
|
|
1455
1455
|
);
|
|
1456
1456
|
fsFailed++;
|
|
@@ -1463,7 +1463,7 @@ var registerFromManager = async (manager, logger) => {
|
|
|
1463
1463
|
vsIndex[resource.url] = resource;
|
|
1464
1464
|
}
|
|
1465
1465
|
}
|
|
1466
|
-
|
|
1466
|
+
logger2?.success(
|
|
1467
1467
|
`FHIR Schema conversion for '${packageMetaToFhir(packageMeta)}' completed: ${fsSuccess} successful, ${fsFailed} failed`
|
|
1468
1468
|
);
|
|
1469
1469
|
}
|
|
@@ -1596,7 +1596,7 @@ function mkBindingIdentifier(fhirSchema, path, bindingName) {
|
|
|
1596
1596
|
}
|
|
1597
1597
|
|
|
1598
1598
|
// src/typeschema/profile/processor.ts
|
|
1599
|
-
async function transformProfile(register, fhirSchema,
|
|
1599
|
+
async function transformProfile(register, fhirSchema, logger2) {
|
|
1600
1600
|
const identifier = mkIdentifier(fhirSchema);
|
|
1601
1601
|
if (identifier.kind !== "profile") {
|
|
1602
1602
|
throw new Error(`Expected profile, got ${identifier.kind} for ${fhirSchema.name}`);
|
|
@@ -1628,7 +1628,7 @@ async function transformProfile(register, fhirSchema, logger) {
|
|
|
1628
1628
|
profileSchema.metadata = metadata;
|
|
1629
1629
|
}
|
|
1630
1630
|
if (fhirSchema.elements) {
|
|
1631
|
-
const fields = await mkFields(register, fhirSchema, [], fhirSchema.elements,
|
|
1631
|
+
const fields = await mkFields(register, fhirSchema, [], fhirSchema.elements, logger2);
|
|
1632
1632
|
if (fields && Object.keys(fields).length > 0) {
|
|
1633
1633
|
profileSchema.fields = fields;
|
|
1634
1634
|
}
|
|
@@ -1825,13 +1825,13 @@ function buildFieldType(register, fhirSchema, element) {
|
|
|
1825
1825
|
}
|
|
1826
1826
|
return void 0;
|
|
1827
1827
|
}
|
|
1828
|
-
var mkField = (register, fhirSchema, path, element,
|
|
1828
|
+
var mkField = (register, fhirSchema, path, element, logger2) => {
|
|
1829
1829
|
let binding;
|
|
1830
1830
|
let enumValues;
|
|
1831
1831
|
if (element.binding) {
|
|
1832
1832
|
binding = mkBindingIdentifier(fhirSchema, path, element.binding.bindingName);
|
|
1833
1833
|
if (element.binding.strength === "required" && element.type === "code") {
|
|
1834
|
-
enumValues = buildEnum(register, element,
|
|
1834
|
+
enumValues = buildEnum(register, element, logger2);
|
|
1835
1835
|
}
|
|
1836
1836
|
}
|
|
1837
1837
|
return {
|
|
@@ -1864,7 +1864,7 @@ function mkNestedField(register, fhirSchema, path, element) {
|
|
|
1864
1864
|
}
|
|
1865
1865
|
|
|
1866
1866
|
// src/typeschema/core/binding.ts
|
|
1867
|
-
function extractValueSetConceptsByUrl(register, valueSetUrl,
|
|
1867
|
+
function extractValueSetConceptsByUrl(register, valueSetUrl, logger2) {
|
|
1868
1868
|
const cleanUrl = dropVersionFromUrl(valueSetUrl) || valueSetUrl;
|
|
1869
1869
|
const valueSet = register.resolveVs(cleanUrl);
|
|
1870
1870
|
if (!valueSet) return void 0;
|
|
@@ -1909,7 +1909,7 @@ function extractValueSetConcepts(register, valueSet, _logger) {
|
|
|
1909
1909
|
return concepts.length > 0 ? concepts : void 0;
|
|
1910
1910
|
}
|
|
1911
1911
|
var MAX_ENUM_LENGTH = 100;
|
|
1912
|
-
function buildEnum(register, element,
|
|
1912
|
+
function buildEnum(register, element, logger2) {
|
|
1913
1913
|
if (!element.binding) return void 0;
|
|
1914
1914
|
const strength = element.binding.strength;
|
|
1915
1915
|
const valueSetUrl = element.binding.valueSet;
|
|
@@ -1920,14 +1920,14 @@ function buildEnum(register, element, logger) {
|
|
|
1920
1920
|
if (!concepts || concepts.length === 0) return void 0;
|
|
1921
1921
|
const codes = concepts.map((c) => c.code).filter((code) => code && typeof code === "string" && code.trim().length > 0);
|
|
1922
1922
|
if (codes.length > MAX_ENUM_LENGTH) {
|
|
1923
|
-
|
|
1923
|
+
logger2?.dry_warn(
|
|
1924
1924
|
`Value set ${valueSetUrl} has ${codes.length} which is more than ${MAX_ENUM_LENGTH} codes, which may cause issues with code generation.`
|
|
1925
1925
|
);
|
|
1926
1926
|
return void 0;
|
|
1927
1927
|
}
|
|
1928
1928
|
return codes.length > 0 ? codes : void 0;
|
|
1929
1929
|
}
|
|
1930
|
-
function generateBindingSchema(register, fhirSchema, path, element,
|
|
1930
|
+
function generateBindingSchema(register, fhirSchema, path, element, logger2) {
|
|
1931
1931
|
if (!element.binding?.valueSet) return void 0;
|
|
1932
1932
|
const identifier = mkBindingIdentifier(fhirSchema, path, element.binding.bindingName);
|
|
1933
1933
|
const fieldType = buildFieldType(register, fhirSchema, element);
|
|
@@ -1937,7 +1937,7 @@ function generateBindingSchema(register, fhirSchema, path, element, logger) {
|
|
|
1937
1937
|
dependencies.push(fieldType);
|
|
1938
1938
|
}
|
|
1939
1939
|
dependencies.push(valueSetIdentifier);
|
|
1940
|
-
const enumValues = buildEnum(register, element,
|
|
1940
|
+
const enumValues = buildEnum(register, element, logger2);
|
|
1941
1941
|
return {
|
|
1942
1942
|
identifier,
|
|
1943
1943
|
type: fieldType,
|
|
@@ -1947,7 +1947,7 @@ function generateBindingSchema(register, fhirSchema, path, element, logger) {
|
|
|
1947
1947
|
dependencies
|
|
1948
1948
|
};
|
|
1949
1949
|
}
|
|
1950
|
-
function collectBindingSchemas(register, fhirSchema,
|
|
1950
|
+
function collectBindingSchemas(register, fhirSchema, logger2) {
|
|
1951
1951
|
const processedPaths = /* @__PURE__ */ new Set();
|
|
1952
1952
|
if (!fhirSchema.elements) return [];
|
|
1953
1953
|
const bindings = [];
|
|
@@ -1958,7 +1958,7 @@ function collectBindingSchemas(register, fhirSchema, logger) {
|
|
|
1958
1958
|
if (processedPaths.has(pathKey)) continue;
|
|
1959
1959
|
processedPaths.add(pathKey);
|
|
1960
1960
|
if (element.binding) {
|
|
1961
|
-
const binding = generateBindingSchema(register, fhirSchema, path, element,
|
|
1961
|
+
const binding = generateBindingSchema(register, fhirSchema, path, element, logger2);
|
|
1962
1962
|
if (binding) {
|
|
1963
1963
|
bindings.push(binding);
|
|
1964
1964
|
}
|
|
@@ -1995,19 +1995,19 @@ function collectNestedElements(fhirSchema, parentPath, elements) {
|
|
|
1995
1995
|
}
|
|
1996
1996
|
return nested;
|
|
1997
1997
|
}
|
|
1998
|
-
function transformNestedElements(fhirSchema, parentPath, elements, register,
|
|
1998
|
+
function transformNestedElements(fhirSchema, parentPath, elements, register, logger2) {
|
|
1999
1999
|
const fields = {};
|
|
2000
2000
|
for (const [key, element] of Object.entries(elements)) {
|
|
2001
2001
|
const path = [...parentPath, key];
|
|
2002
2002
|
if (isNestedElement(element)) {
|
|
2003
2003
|
fields[key] = mkNestedField(register, fhirSchema, path, element);
|
|
2004
2004
|
} else {
|
|
2005
|
-
fields[key] = mkField(register, fhirSchema, path, element,
|
|
2005
|
+
fields[key] = mkField(register, fhirSchema, path, element, logger2);
|
|
2006
2006
|
}
|
|
2007
2007
|
}
|
|
2008
2008
|
return fields;
|
|
2009
2009
|
}
|
|
2010
|
-
function mkNestedTypes(register, fhirSchema,
|
|
2010
|
+
function mkNestedTypes(register, fhirSchema, logger2) {
|
|
2011
2011
|
if (!fhirSchema.elements) return void 0;
|
|
2012
2012
|
const nestedElements = collectNestedElements(fhirSchema, [], fhirSchema.elements);
|
|
2013
2013
|
const actualNested = nestedElements.filter(
|
|
@@ -2034,7 +2034,7 @@ function mkNestedTypes(register, fhirSchema, logger) {
|
|
|
2034
2034
|
url: `http://hl7.org/fhir/StructureDefinition/${element.type}`
|
|
2035
2035
|
};
|
|
2036
2036
|
}
|
|
2037
|
-
const fields = transformNestedElements(fhirSchema, path, element.elements, register,
|
|
2037
|
+
const fields = transformNestedElements(fhirSchema, path, element.elements, register, logger2);
|
|
2038
2038
|
const nestedType = {
|
|
2039
2039
|
identifier,
|
|
2040
2040
|
base,
|
|
@@ -2064,7 +2064,7 @@ function extractNestedDependencies(nestedTypes) {
|
|
|
2064
2064
|
}
|
|
2065
2065
|
|
|
2066
2066
|
// src/typeschema/core/transformer.ts
|
|
2067
|
-
function mkFields(register, fhirSchema, parentPath, elements,
|
|
2067
|
+
function mkFields(register, fhirSchema, parentPath, elements, logger2) {
|
|
2068
2068
|
if (!elements) return void 0;
|
|
2069
2069
|
const geneology = register.resolveFsGenealogy(fhirSchema.url);
|
|
2070
2070
|
const elems = {};
|
|
@@ -2089,7 +2089,7 @@ function mkFields(register, fhirSchema, parentPath, elements, logger) {
|
|
|
2089
2089
|
if (isNestedElement(elemSnapshot)) {
|
|
2090
2090
|
fields[key] = mkNestedField(register, fhirSchema, path, elemSnapshot);
|
|
2091
2091
|
} else {
|
|
2092
|
-
fields[key] = mkField(register, fhirSchema, path, elemSnapshot,
|
|
2092
|
+
fields[key] = mkField(register, fhirSchema, path, elemSnapshot, logger2);
|
|
2093
2093
|
}
|
|
2094
2094
|
}
|
|
2095
2095
|
return fields;
|
|
@@ -2134,7 +2134,7 @@ function isExtensionSchema(fhirSchema, _identifier) {
|
|
|
2134
2134
|
}
|
|
2135
2135
|
return false;
|
|
2136
2136
|
}
|
|
2137
|
-
async function transformValueSet(register, valueSet,
|
|
2137
|
+
async function transformValueSet(register, valueSet, logger2) {
|
|
2138
2138
|
if (!valueSet.url) throw new Error("ValueSet URL is required");
|
|
2139
2139
|
const identifier = mkValueSetIdentifierByUrl(register, valueSet.url);
|
|
2140
2140
|
const concept = extractValueSetConceptsByUrl(register, valueSet.url);
|
|
@@ -2145,7 +2145,7 @@ async function transformValueSet(register, valueSet, logger) {
|
|
|
2145
2145
|
compose: !concept ? valueSet.compose : void 0
|
|
2146
2146
|
};
|
|
2147
2147
|
}
|
|
2148
|
-
async function transformExtension(fhirSchema, register,
|
|
2148
|
+
async function transformExtension(fhirSchema, register, logger2) {
|
|
2149
2149
|
try {
|
|
2150
2150
|
const identifier = mkIdentifier(fhirSchema);
|
|
2151
2151
|
let base;
|
|
@@ -2182,13 +2182,13 @@ async function transformExtension(fhirSchema, register, logger) {
|
|
|
2182
2182
|
extensionSchema.dependencies.push(base);
|
|
2183
2183
|
}
|
|
2184
2184
|
if (fhirSchema.elements) {
|
|
2185
|
-
const fields = mkFields(register, fhirSchema, [], fhirSchema.elements,
|
|
2185
|
+
const fields = mkFields(register, fhirSchema, [], fhirSchema.elements, logger2);
|
|
2186
2186
|
if (fields && Object.keys(fields).length > 0) {
|
|
2187
2187
|
extensionSchema.fields = fields;
|
|
2188
2188
|
extensionSchema.dependencies.push(...extractFieldDependencies(fields));
|
|
2189
2189
|
}
|
|
2190
2190
|
}
|
|
2191
|
-
const nestedTypes = mkNestedTypes(register, fhirSchema,
|
|
2191
|
+
const nestedTypes = mkNestedTypes(register, fhirSchema, logger2);
|
|
2192
2192
|
if (nestedTypes && nestedTypes.length > 0) {
|
|
2193
2193
|
extensionSchema.nested = nestedTypes;
|
|
2194
2194
|
extensionSchema.dependencies.push(...extractNestedDependencies(nestedTypes));
|
|
@@ -2215,7 +2215,7 @@ function extractDependencies(identifier, base, fields, nestedTypes) {
|
|
|
2215
2215
|
const result = Object.values(uniqDeps).filter((e) => !(e.kind === "nested" && localNestedTypeUrls.has(e.url))).sort((a, b) => a.url.localeCompare(b.url));
|
|
2216
2216
|
return result.length > 0 ? result : void 0;
|
|
2217
2217
|
}
|
|
2218
|
-
function transformFhirSchemaResource(register, fhirSchema,
|
|
2218
|
+
function transformFhirSchemaResource(register, fhirSchema, logger2) {
|
|
2219
2219
|
const identifier = mkIdentifier(fhirSchema);
|
|
2220
2220
|
let base;
|
|
2221
2221
|
if (fhirSchema.base && fhirSchema.type !== "Element") {
|
|
@@ -2225,8 +2225,8 @@ function transformFhirSchemaResource(register, fhirSchema, logger) {
|
|
|
2225
2225
|
}
|
|
2226
2226
|
base = mkIdentifier(baseFs);
|
|
2227
2227
|
}
|
|
2228
|
-
const fields = mkFields(register, fhirSchema, [], fhirSchema.elements,
|
|
2229
|
-
const nested = mkNestedTypes(register, fhirSchema,
|
|
2228
|
+
const fields = mkFields(register, fhirSchema, [], fhirSchema.elements, logger2);
|
|
2229
|
+
const nested = mkNestedTypes(register, fhirSchema, logger2);
|
|
2230
2230
|
const dependencies = extractDependencies(identifier, base, fields, nested);
|
|
2231
2231
|
const typeSchema = {
|
|
2232
2232
|
identifier,
|
|
@@ -2236,27 +2236,27 @@ function transformFhirSchemaResource(register, fhirSchema, logger) {
|
|
|
2236
2236
|
description: fhirSchema.description,
|
|
2237
2237
|
dependencies
|
|
2238
2238
|
};
|
|
2239
|
-
const bindingSchemas = collectBindingSchemas(register, fhirSchema,
|
|
2239
|
+
const bindingSchemas = collectBindingSchemas(register, fhirSchema, logger2);
|
|
2240
2240
|
return [typeSchema, ...bindingSchemas];
|
|
2241
2241
|
}
|
|
2242
|
-
async function transformFhirSchema(register, fhirSchema,
|
|
2242
|
+
async function transformFhirSchema(register, fhirSchema, logger2) {
|
|
2243
2243
|
const results = [];
|
|
2244
2244
|
const identifier = mkIdentifier(fhirSchema);
|
|
2245
2245
|
if (identifier.kind === "profile") {
|
|
2246
|
-
const profileSchema = await transformProfile(register, fhirSchema,
|
|
2246
|
+
const profileSchema = await transformProfile(register, fhirSchema, logger2);
|
|
2247
2247
|
results.push(profileSchema);
|
|
2248
|
-
const bindingSchemas = collectBindingSchemas(register, fhirSchema,
|
|
2248
|
+
const bindingSchemas = collectBindingSchemas(register, fhirSchema, logger2);
|
|
2249
2249
|
results.push(...bindingSchemas);
|
|
2250
2250
|
return results;
|
|
2251
2251
|
}
|
|
2252
2252
|
if (isExtensionSchema(fhirSchema)) {
|
|
2253
|
-
const extensionSchema = await transformExtension(fhirSchema, register,
|
|
2253
|
+
const extensionSchema = await transformExtension(fhirSchema, register, logger2);
|
|
2254
2254
|
if (extensionSchema) {
|
|
2255
2255
|
results.push(extensionSchema);
|
|
2256
2256
|
}
|
|
2257
2257
|
return results;
|
|
2258
2258
|
}
|
|
2259
|
-
return transformFhirSchemaResource(register, fhirSchema,
|
|
2259
|
+
return transformFhirSchemaResource(register, fhirSchema, logger2);
|
|
2260
2260
|
}
|
|
2261
2261
|
var TypeSchemaCache = class {
|
|
2262
2262
|
cache = /* @__PURE__ */ new Map();
|
|
@@ -2476,6 +2476,224 @@ var TypeSchemaCache = class {
|
|
|
2476
2476
|
}
|
|
2477
2477
|
}
|
|
2478
2478
|
};
|
|
2479
|
+
|
|
2480
|
+
// src/logger.ts
|
|
2481
|
+
var LogLevel = /* @__PURE__ */ ((LogLevel2) => {
|
|
2482
|
+
LogLevel2[LogLevel2["DEBUG"] = 0] = "DEBUG";
|
|
2483
|
+
LogLevel2[LogLevel2["INFO"] = 1] = "INFO";
|
|
2484
|
+
LogLevel2[LogLevel2["WARN"] = 2] = "WARN";
|
|
2485
|
+
LogLevel2[LogLevel2["ERROR"] = 3] = "ERROR";
|
|
2486
|
+
LogLevel2[LogLevel2["SILENT"] = 4] = "SILENT";
|
|
2487
|
+
return LogLevel2;
|
|
2488
|
+
})(LogLevel || {});
|
|
2489
|
+
var ConsoleOutput = class {
|
|
2490
|
+
constructor(useStderr = false) {
|
|
2491
|
+
this.useStderr = useStderr;
|
|
2492
|
+
}
|
|
2493
|
+
write(entry, formatted) {
|
|
2494
|
+
const output = this.useStderr || entry.level >= 2 /* WARN */ ? console.error : console.log;
|
|
2495
|
+
output(formatted);
|
|
2496
|
+
}
|
|
2497
|
+
};
|
|
2498
|
+
var Logger = class _Logger {
|
|
2499
|
+
config;
|
|
2500
|
+
constructor(config = {}) {
|
|
2501
|
+
this.config = {
|
|
2502
|
+
level: 1 /* INFO */,
|
|
2503
|
+
format: "pretty",
|
|
2504
|
+
includeTimestamp: true,
|
|
2505
|
+
includeContext: true,
|
|
2506
|
+
colorize: true,
|
|
2507
|
+
outputs: [new ConsoleOutput()],
|
|
2508
|
+
...config
|
|
2509
|
+
};
|
|
2510
|
+
}
|
|
2511
|
+
/**
|
|
2512
|
+
* Update logger configuration
|
|
2513
|
+
*/
|
|
2514
|
+
configure(config) {
|
|
2515
|
+
this.config = { ...this.config, ...config };
|
|
2516
|
+
}
|
|
2517
|
+
/**
|
|
2518
|
+
* Check if a log level should be output
|
|
2519
|
+
*/
|
|
2520
|
+
shouldLog(level) {
|
|
2521
|
+
return level >= this.config.level;
|
|
2522
|
+
}
|
|
2523
|
+
/**
|
|
2524
|
+
* Create a log entry
|
|
2525
|
+
*/
|
|
2526
|
+
createEntry(level, message, context, error, operation) {
|
|
2527
|
+
const entry = {
|
|
2528
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
2529
|
+
level,
|
|
2530
|
+
levelName: LogLevel[level],
|
|
2531
|
+
message,
|
|
2532
|
+
component: this.config.component
|
|
2533
|
+
};
|
|
2534
|
+
if (context && this.config.includeContext) {
|
|
2535
|
+
entry.context = context;
|
|
2536
|
+
}
|
|
2537
|
+
if (operation) {
|
|
2538
|
+
entry.operation = operation;
|
|
2539
|
+
}
|
|
2540
|
+
if (error) {
|
|
2541
|
+
entry.error = {
|
|
2542
|
+
name: error.name,
|
|
2543
|
+
message: error.message,
|
|
2544
|
+
stack: error.stack
|
|
2545
|
+
};
|
|
2546
|
+
}
|
|
2547
|
+
return entry;
|
|
2548
|
+
}
|
|
2549
|
+
/**
|
|
2550
|
+
* Format log entry for output
|
|
2551
|
+
*/
|
|
2552
|
+
formatEntry(entry) {
|
|
2553
|
+
switch (this.config.format) {
|
|
2554
|
+
case "json":
|
|
2555
|
+
return JSON.stringify(entry);
|
|
2556
|
+
case "compact":
|
|
2557
|
+
return this.formatCompact(entry);
|
|
2558
|
+
default:
|
|
2559
|
+
return this.formatPretty(entry);
|
|
2560
|
+
}
|
|
2561
|
+
}
|
|
2562
|
+
/**
|
|
2563
|
+
* Format entry in compact format
|
|
2564
|
+
*/
|
|
2565
|
+
formatCompact(entry) {
|
|
2566
|
+
const timestamp = this.config.includeTimestamp ? `${entry.timestamp} ` : "";
|
|
2567
|
+
const component = entry.component ? `[${entry.component}] ` : "";
|
|
2568
|
+
const operation = entry.operation ? `(${entry.operation}) ` : "";
|
|
2569
|
+
const level = this.colorizeLevel(entry.levelName, entry.level);
|
|
2570
|
+
return `${timestamp}${level} ${component}${operation}${entry.message}`;
|
|
2571
|
+
}
|
|
2572
|
+
/**
|
|
2573
|
+
* Format entry in pretty format
|
|
2574
|
+
*/
|
|
2575
|
+
formatPretty(entry) {
|
|
2576
|
+
let formatted = "";
|
|
2577
|
+
const timestamp = this.config.includeTimestamp ? `${entry.timestamp} ` : "";
|
|
2578
|
+
const component = entry.component ? `[${entry.component}] ` : "";
|
|
2579
|
+
const operation = entry.operation ? `(${entry.operation}) ` : "";
|
|
2580
|
+
const level = this.colorizeLevel(entry.levelName.padEnd(5), entry.level);
|
|
2581
|
+
formatted += `${timestamp}${level} ${component}${operation}${entry.message}`;
|
|
2582
|
+
if (entry.context && Object.keys(entry.context).length > 0) {
|
|
2583
|
+
formatted += `
|
|
2584
|
+
Context: ${JSON.stringify(entry.context, null, 2).split("\n").join("\n ")}`;
|
|
2585
|
+
}
|
|
2586
|
+
if (entry.error) {
|
|
2587
|
+
formatted += `
|
|
2588
|
+
Error: [${entry.error.code || entry.error.name}] ${entry.error.message}`;
|
|
2589
|
+
if (entry.error.context && Object.keys(entry.error.context).length > 0) {
|
|
2590
|
+
formatted += `
|
|
2591
|
+
Error Context: ${JSON.stringify(entry.error.context, null, 2).split("\n").join("\n ")}`;
|
|
2592
|
+
}
|
|
2593
|
+
if (entry.error.suggestions && entry.error.suggestions.length > 0) {
|
|
2594
|
+
formatted += `
|
|
2595
|
+
Suggestions:
|
|
2596
|
+
${entry.error.suggestions.map((s) => ` \u2022 ${s}`).join("\n")}`;
|
|
2597
|
+
}
|
|
2598
|
+
if (entry.level === 0 /* DEBUG */ && entry.error.stack) {
|
|
2599
|
+
formatted += `
|
|
2600
|
+
Stack: ${entry.error.stack.split("\n").join("\n ")}`;
|
|
2601
|
+
}
|
|
2602
|
+
}
|
|
2603
|
+
return formatted;
|
|
2604
|
+
}
|
|
2605
|
+
/**
|
|
2606
|
+
* Colorize log level if enabled
|
|
2607
|
+
*/
|
|
2608
|
+
colorizeLevel(levelName, level) {
|
|
2609
|
+
if (!this.config.colorize) {
|
|
2610
|
+
return levelName;
|
|
2611
|
+
}
|
|
2612
|
+
const colors = {
|
|
2613
|
+
[0 /* DEBUG */]: "\x1B[36m",
|
|
2614
|
+
// Cyan
|
|
2615
|
+
[1 /* INFO */]: "\x1B[32m",
|
|
2616
|
+
// Green
|
|
2617
|
+
[2 /* WARN */]: "\x1B[33m",
|
|
2618
|
+
// Yellow
|
|
2619
|
+
[3 /* ERROR */]: "\x1B[31m"
|
|
2620
|
+
// Red
|
|
2621
|
+
};
|
|
2622
|
+
const reset = "\x1B[0m";
|
|
2623
|
+
const color = colors[level] || "";
|
|
2624
|
+
return `${color}${levelName}${reset}`;
|
|
2625
|
+
}
|
|
2626
|
+
/**
|
|
2627
|
+
* Write log entry to all outputs
|
|
2628
|
+
*/
|
|
2629
|
+
async writeEntry(entry) {
|
|
2630
|
+
if (!this.shouldLog(entry.level)) {
|
|
2631
|
+
return;
|
|
2632
|
+
}
|
|
2633
|
+
const formatted = this.formatEntry(entry);
|
|
2634
|
+
for (const output of this.config.outputs) {
|
|
2635
|
+
try {
|
|
2636
|
+
await output.write(entry, formatted);
|
|
2637
|
+
} catch (error) {
|
|
2638
|
+
console.error("Logger output failed:", error);
|
|
2639
|
+
console.error(formatted);
|
|
2640
|
+
}
|
|
2641
|
+
}
|
|
2642
|
+
}
|
|
2643
|
+
/**
|
|
2644
|
+
* Log debug message
|
|
2645
|
+
*/
|
|
2646
|
+
async debug(message, context, operation) {
|
|
2647
|
+
const entry = this.createEntry(0 /* DEBUG */, message, context, void 0, operation);
|
|
2648
|
+
await this.writeEntry(entry);
|
|
2649
|
+
}
|
|
2650
|
+
/**
|
|
2651
|
+
* Log info message
|
|
2652
|
+
*/
|
|
2653
|
+
async info(message, context, operation) {
|
|
2654
|
+
const entry = this.createEntry(1 /* INFO */, message, context, void 0, operation);
|
|
2655
|
+
await this.writeEntry(entry);
|
|
2656
|
+
}
|
|
2657
|
+
/**
|
|
2658
|
+
* Log warning message
|
|
2659
|
+
*/
|
|
2660
|
+
async warn(message, context, operation) {
|
|
2661
|
+
const entry = this.createEntry(2 /* WARN */, message, context, void 0, operation);
|
|
2662
|
+
await this.writeEntry(entry);
|
|
2663
|
+
}
|
|
2664
|
+
/**
|
|
2665
|
+
* Log error message
|
|
2666
|
+
*/
|
|
2667
|
+
async error(message, error, context, operation) {
|
|
2668
|
+
const entry = this.createEntry(3 /* ERROR */, message, context, error, operation);
|
|
2669
|
+
await this.writeEntry(entry);
|
|
2670
|
+
}
|
|
2671
|
+
/**
|
|
2672
|
+
* Create a child logger with additional context
|
|
2673
|
+
*/
|
|
2674
|
+
child(component, context) {
|
|
2675
|
+
const childLogger = new _Logger({
|
|
2676
|
+
...this.config,
|
|
2677
|
+
component: this.config.component ? `${this.config.component}.${component}` : component
|
|
2678
|
+
});
|
|
2679
|
+
if (context) {
|
|
2680
|
+
const originalMethods = {
|
|
2681
|
+
debug: childLogger.debug.bind(childLogger),
|
|
2682
|
+
info: childLogger.info.bind(childLogger),
|
|
2683
|
+
warn: childLogger.warn.bind(childLogger),
|
|
2684
|
+
error: childLogger.error.bind(childLogger)
|
|
2685
|
+
};
|
|
2686
|
+
childLogger.debug = (message, additionalContext, operation) => originalMethods.debug(message, { ...context, ...additionalContext }, operation);
|
|
2687
|
+
childLogger.info = (message, additionalContext, operation) => originalMethods.info(message, { ...context, ...additionalContext }, operation);
|
|
2688
|
+
childLogger.warn = (message, additionalContext, operation) => originalMethods.warn(message, { ...context, ...additionalContext }, operation);
|
|
2689
|
+
childLogger.error = (message, error, additionalContext, operation) => originalMethods.error(message, error, { ...context, ...additionalContext }, operation);
|
|
2690
|
+
}
|
|
2691
|
+
return childLogger;
|
|
2692
|
+
}
|
|
2693
|
+
};
|
|
2694
|
+
new Logger();
|
|
2695
|
+
|
|
2696
|
+
// src/utils/codegen-logger.ts
|
|
2479
2697
|
var CodegenLogger = class _CodegenLogger {
|
|
2480
2698
|
options;
|
|
2481
2699
|
dryWarnSet = /* @__PURE__ */ new Set();
|
|
@@ -2486,22 +2704,39 @@ var CodegenLogger = class _CodegenLogger {
|
|
|
2486
2704
|
...options
|
|
2487
2705
|
};
|
|
2488
2706
|
}
|
|
2707
|
+
static consoleLevelsMap = {
|
|
2708
|
+
[1 /* INFO */]: console.log,
|
|
2709
|
+
[2 /* WARN */]: console.warn,
|
|
2710
|
+
[3 /* ERROR */]: console.error,
|
|
2711
|
+
[0 /* DEBUG */]: console.log,
|
|
2712
|
+
[4 /* SILENT */]: () => {
|
|
2713
|
+
}
|
|
2714
|
+
};
|
|
2489
2715
|
formatMessage(level, message, color) {
|
|
2490
2716
|
const timestamp = this.options.timestamp ? `${pc.gray((/* @__PURE__ */ new Date()).toLocaleTimeString())} ` : "";
|
|
2491
2717
|
const prefix = this.options.prefix ? `${pc.cyan(`[${this.options.prefix}]`)} ` : "";
|
|
2492
2718
|
return `${timestamp}${color(level)} ${prefix}${message}`;
|
|
2493
2719
|
}
|
|
2720
|
+
isSuppressed(level) {
|
|
2721
|
+
return this.options.suppressLoggingLevel === "all" || this.options.suppressLoggingLevel?.includes(level) || false;
|
|
2722
|
+
}
|
|
2723
|
+
tryWriteToConsole(level, formattedMessage) {
|
|
2724
|
+
if (this.isSuppressed(level)) return;
|
|
2725
|
+
const logFn = _CodegenLogger.consoleLevelsMap[level] || console.log;
|
|
2726
|
+
logFn(formattedMessage);
|
|
2727
|
+
}
|
|
2494
2728
|
/**
|
|
2495
2729
|
* Success message with checkmark
|
|
2496
2730
|
*/
|
|
2497
2731
|
success(message) {
|
|
2498
|
-
|
|
2732
|
+
this.tryWriteToConsole(1 /* INFO */, this.formatMessage("", message, pc.green));
|
|
2499
2733
|
}
|
|
2500
2734
|
/**
|
|
2501
2735
|
* Error message with X mark
|
|
2502
2736
|
*/
|
|
2503
2737
|
error(message, error) {
|
|
2504
|
-
|
|
2738
|
+
if (this.isSuppressed(3 /* ERROR */)) return;
|
|
2739
|
+
console.error(this.formatMessage("", message, pc.red));
|
|
2505
2740
|
if (error && this.options.verbose) {
|
|
2506
2741
|
console.error(pc.red(` ${error.message}`));
|
|
2507
2742
|
if (error.stack) {
|
|
@@ -2513,7 +2748,7 @@ var CodegenLogger = class _CodegenLogger {
|
|
|
2513
2748
|
* Warning message with warning sign
|
|
2514
2749
|
*/
|
|
2515
2750
|
warn(message) {
|
|
2516
|
-
|
|
2751
|
+
this.tryWriteToConsole(2 /* WARN */, this.formatMessage("!", message, pc.yellow));
|
|
2517
2752
|
}
|
|
2518
2753
|
dry_warn(message) {
|
|
2519
2754
|
if (!this.dryWarnSet.has(message)) {
|
|
@@ -2525,27 +2760,27 @@ var CodegenLogger = class _CodegenLogger {
|
|
|
2525
2760
|
* Info message with info icon
|
|
2526
2761
|
*/
|
|
2527
2762
|
info(message) {
|
|
2528
|
-
|
|
2763
|
+
this.tryWriteToConsole(1 /* INFO */, this.formatMessage("i", message, pc.blue));
|
|
2529
2764
|
}
|
|
2530
2765
|
/**
|
|
2531
2766
|
* Debug message (only shows in verbose mode)
|
|
2532
2767
|
*/
|
|
2533
2768
|
debug(message) {
|
|
2534
2769
|
if (this.options.verbose) {
|
|
2535
|
-
|
|
2770
|
+
this.tryWriteToConsole(0 /* DEBUG */, this.formatMessage("\u{1F41B}", message, pc.magenta));
|
|
2536
2771
|
}
|
|
2537
2772
|
}
|
|
2538
2773
|
/**
|
|
2539
2774
|
* Step message with rocket
|
|
2540
2775
|
*/
|
|
2541
2776
|
step(message) {
|
|
2542
|
-
|
|
2777
|
+
this.tryWriteToConsole(1 /* INFO */, this.formatMessage("\u{1F680}", message, pc.cyan));
|
|
2543
2778
|
}
|
|
2544
2779
|
/**
|
|
2545
2780
|
* Progress message with clock
|
|
2546
2781
|
*/
|
|
2547
2782
|
progress(message) {
|
|
2548
|
-
|
|
2783
|
+
this.tryWriteToConsole(1 /* INFO */, this.formatMessage("\u23F3", message, pc.blue));
|
|
2549
2784
|
}
|
|
2550
2785
|
/**
|
|
2551
2786
|
* Plain message (no icon, just colored text)
|
|
@@ -2553,7 +2788,7 @@ var CodegenLogger = class _CodegenLogger {
|
|
|
2553
2788
|
plain(message, color = (s) => s) {
|
|
2554
2789
|
const timestamp = this.options.timestamp ? `${pc.gray((/* @__PURE__ */ new Date()).toLocaleTimeString())} ` : "";
|
|
2555
2790
|
const prefix = this.options.prefix ? `${pc.cyan(`[${this.options.prefix}]`)} ` : "";
|
|
2556
|
-
|
|
2791
|
+
this.tryWriteToConsole(1 /* INFO */, `${timestamp}${prefix}${color(message)}`);
|
|
2557
2792
|
}
|
|
2558
2793
|
/**
|
|
2559
2794
|
* Dimmed/gray text for less important info
|
|
@@ -2634,11 +2869,11 @@ var TypeSchemaGenerator = class {
|
|
|
2634
2869
|
);
|
|
2635
2870
|
return fhirSchemas;
|
|
2636
2871
|
}
|
|
2637
|
-
async generateValueSetSchemas(valueSets,
|
|
2872
|
+
async generateValueSetSchemas(valueSets, logger2) {
|
|
2638
2873
|
if (valueSets.length > 0) {
|
|
2639
2874
|
this.logger?.debug(`${valueSets.length} ValueSets available for enum extraction`);
|
|
2640
2875
|
}
|
|
2641
|
-
const register = await registerFromManager(this.manager,
|
|
2876
|
+
const register = await registerFromManager(this.manager, logger2);
|
|
2642
2877
|
const valueSetSchemas = [];
|
|
2643
2878
|
if (valueSets.length > 0) {
|
|
2644
2879
|
this.logger?.progress(`Converting ${valueSets.length} ValueSets to TypeSchema`);
|
|
@@ -2646,7 +2881,7 @@ var TypeSchemaGenerator = class {
|
|
|
2646
2881
|
let valueSetFailedCount = 0;
|
|
2647
2882
|
for (const vs of valueSets) {
|
|
2648
2883
|
try {
|
|
2649
|
-
const valueSetSchema = await transformValueSet(register, vs,
|
|
2884
|
+
const valueSetSchema = await transformValueSet(register, vs, logger2);
|
|
2650
2885
|
if (valueSetSchema) {
|
|
2651
2886
|
valueSetSchemas.push(valueSetSchema);
|
|
2652
2887
|
valueSetConvertedCount++;
|
|
@@ -2665,7 +2900,7 @@ var TypeSchemaGenerator = class {
|
|
|
2665
2900
|
}
|
|
2666
2901
|
return valueSetSchemas;
|
|
2667
2902
|
}
|
|
2668
|
-
async generateFromPackage(packageName, packageVersion,
|
|
2903
|
+
async generateFromPackage(packageName, packageVersion, logger2) {
|
|
2669
2904
|
await this.initializeCache();
|
|
2670
2905
|
if (this.cache && !(this.cacheConfig?.forceRegenerate ?? false)) {
|
|
2671
2906
|
const cachedSchemas = this.cache.getByPackage(packageName);
|
|
@@ -2681,8 +2916,8 @@ var TypeSchemaGenerator = class {
|
|
|
2681
2916
|
version: packageVersion || "latest"
|
|
2682
2917
|
};
|
|
2683
2918
|
const register = await this.registerFromPackageMetas([packageInfo]);
|
|
2684
|
-
const valueSets = await this.generateValueSetSchemas(register.allVs(),
|
|
2685
|
-
const fhirSchemas = (await Promise.all(register.allFs().map(async (fs2) => await transformFhirSchema(register, fs2,
|
|
2919
|
+
const valueSets = await this.generateValueSetSchemas(register.allVs(), logger2);
|
|
2920
|
+
const fhirSchemas = (await Promise.all(register.allFs().map(async (fs2) => await transformFhirSchema(register, fs2, logger2)))).flat();
|
|
2686
2921
|
const allSchemas = [...fhirSchemas, ...valueSets];
|
|
2687
2922
|
if (this.cache) {
|
|
2688
2923
|
for (const schema of allSchemas) {
|
|
@@ -3051,10 +3286,10 @@ var TypeSchemaParser = class {
|
|
|
3051
3286
|
};
|
|
3052
3287
|
|
|
3053
3288
|
// src/typeschema/index.ts
|
|
3054
|
-
var generateTypeSchemas = async (register,
|
|
3289
|
+
var generateTypeSchemas = async (register, logger2) => {
|
|
3055
3290
|
const fhirSchemas = [];
|
|
3056
3291
|
for (const fhirSchema of register.allFs()) {
|
|
3057
|
-
fhirSchemas.push(...await transformFhirSchema(register, fhirSchema,
|
|
3292
|
+
fhirSchemas.push(...await transformFhirSchema(register, fhirSchema, logger2));
|
|
3058
3293
|
}
|
|
3059
3294
|
for (const vsSchema of register.allVs()) {
|
|
3060
3295
|
fhirSchemas.push(await transformValueSet(register, vsSchema));
|
|
@@ -3112,45 +3347,45 @@ var ErrorHandler = class {
|
|
|
3112
3347
|
handleUnknownError(error, context) {
|
|
3113
3348
|
this.options.logger.error("Unexpected error occurred:", error);
|
|
3114
3349
|
if (this.options.verbose) {
|
|
3115
|
-
|
|
3116
|
-
|
|
3117
|
-
|
|
3350
|
+
this.options.logger.error("\n\u{1F6A8} Unexpected Error Details:");
|
|
3351
|
+
this.options.logger.error(` Type: ${error.constructor.name}`);
|
|
3352
|
+
this.options.logger.error(` Message: ${error.message}`);
|
|
3118
3353
|
if (error.stack) {
|
|
3119
|
-
|
|
3354
|
+
this.options.logger.error(` Stack: ${error.stack}`);
|
|
3120
3355
|
}
|
|
3121
3356
|
if (context?.schema) {
|
|
3122
|
-
|
|
3357
|
+
this.options.logger.error(` Schema: ${context.schema.identifier.name}`);
|
|
3123
3358
|
}
|
|
3124
3359
|
if (context?.filename) {
|
|
3125
|
-
|
|
3360
|
+
this.options.logger.error(` File: ${context.filename}`);
|
|
3126
3361
|
}
|
|
3127
3362
|
}
|
|
3128
|
-
|
|
3129
|
-
|
|
3130
|
-
|
|
3131
|
-
|
|
3132
|
-
|
|
3363
|
+
this.options.logger.error("\n\u{1F4A1} General troubleshooting suggestions:");
|
|
3364
|
+
this.options.logger.error(" \u2022 Run with --verbose flag for more details");
|
|
3365
|
+
this.options.logger.error(" \u2022 Check your input files for corruption");
|
|
3366
|
+
this.options.logger.error(" \u2022 Update to the latest version of atomic-codegen");
|
|
3367
|
+
this.options.logger.error(" \u2022 Report this issue at: https://github.com/atomic-ehr/codegen/issues");
|
|
3133
3368
|
}
|
|
3134
3369
|
/**
|
|
3135
3370
|
* Report error to console with formatting
|
|
3136
3371
|
*/
|
|
3137
3372
|
reportErrorToConsole(error) {
|
|
3138
3373
|
if ("getFormattedMessage" in error) {
|
|
3139
|
-
|
|
3374
|
+
this.options.logger.error(error.getFormattedMessage());
|
|
3140
3375
|
} else {
|
|
3141
|
-
|
|
3376
|
+
this.options.logger.error(`
|
|
3142
3377
|
\u274C ${error.constructor.name}: ${error.message}`);
|
|
3143
3378
|
const suggestions = error.getSuggestions();
|
|
3144
3379
|
if (suggestions.length > 0) {
|
|
3145
|
-
|
|
3380
|
+
this.options.logger.error("\n\u{1F4A1} Suggestions:");
|
|
3146
3381
|
suggestions.forEach((suggestion) => {
|
|
3147
|
-
|
|
3382
|
+
this.options.logger.error(` \u2022 ${suggestion}`);
|
|
3148
3383
|
});
|
|
3149
3384
|
}
|
|
3150
3385
|
}
|
|
3151
3386
|
if (this.options.verbose && error.context) {
|
|
3152
|
-
|
|
3153
|
-
|
|
3387
|
+
this.options.logger.error("\n\u{1F50D} Debug Information:");
|
|
3388
|
+
this.options.logger.error(JSON.stringify(error.context, null, 2));
|
|
3154
3389
|
}
|
|
3155
3390
|
}
|
|
3156
3391
|
/**
|
|
@@ -3165,7 +3400,7 @@ var ErrorHandler = class {
|
|
|
3165
3400
|
suggestions: error.getSuggestions(),
|
|
3166
3401
|
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
3167
3402
|
};
|
|
3168
|
-
|
|
3403
|
+
this.options.logger.error(JSON.stringify(errorData, null, 2));
|
|
3169
3404
|
}
|
|
3170
3405
|
/**
|
|
3171
3406
|
* Report error in structured format
|
|
@@ -3181,16 +3416,16 @@ var ErrorHandler = class {
|
|
|
3181
3416
|
suggestions: error.getSuggestions(),
|
|
3182
3417
|
actions: this.getRecoveryActions(error)
|
|
3183
3418
|
};
|
|
3184
|
-
|
|
3185
|
-
|
|
3186
|
-
|
|
3187
|
-
|
|
3419
|
+
this.options.logger.error("---");
|
|
3420
|
+
this.options.logger.error("Error Report:");
|
|
3421
|
+
this.options.logger.error(JSON.stringify(structure, null, 2));
|
|
3422
|
+
this.options.logger.error("---");
|
|
3188
3423
|
}
|
|
3189
3424
|
/**
|
|
3190
3425
|
* Report multiple errors efficiently
|
|
3191
3426
|
*/
|
|
3192
3427
|
reportBatchErrors(errors) {
|
|
3193
|
-
|
|
3428
|
+
this.options.logger.error(`
|
|
3194
3429
|
\u274C ${errors.length} errors occurred during generation:`);
|
|
3195
3430
|
const errorGroups = /* @__PURE__ */ new Map();
|
|
3196
3431
|
errors.forEach((error) => {
|
|
@@ -3201,19 +3436,19 @@ var ErrorHandler = class {
|
|
|
3201
3436
|
errorGroups.get(type)?.push(error);
|
|
3202
3437
|
});
|
|
3203
3438
|
for (const [type, groupErrors] of errorGroups) {
|
|
3204
|
-
|
|
3439
|
+
this.options.logger.error(`
|
|
3205
3440
|
\u{1F4CB} ${type} (${groupErrors.length} occurrences):`);
|
|
3206
3441
|
groupErrors.forEach((error, index) => {
|
|
3207
|
-
|
|
3442
|
+
this.options.logger.error(` ${index + 1}. ${error.message}`);
|
|
3208
3443
|
if (error.context?.schemaName) {
|
|
3209
|
-
|
|
3444
|
+
this.options.logger.error(` Schema: ${error.context.schemaName}`);
|
|
3210
3445
|
}
|
|
3211
3446
|
});
|
|
3212
3447
|
const commonSuggestions = this.getCommonSuggestions(groupErrors);
|
|
3213
3448
|
if (commonSuggestions.length > 0) {
|
|
3214
|
-
|
|
3449
|
+
this.options.logger.error("\n \u{1F4A1} Common suggestions:");
|
|
3215
3450
|
commonSuggestions.forEach((suggestion) => {
|
|
3216
|
-
|
|
3451
|
+
this.options.logger.error(` \u2022 ${suggestion}`);
|
|
3217
3452
|
});
|
|
3218
3453
|
}
|
|
3219
3454
|
}
|
|
@@ -3523,7 +3758,7 @@ var BaseGenerator = class {
|
|
|
3523
3758
|
logger: this.logger,
|
|
3524
3759
|
verbose: this.options.verbose || false,
|
|
3525
3760
|
beginnerMode: this.options.beginnerMode || false,
|
|
3526
|
-
outputFormat: this.options.
|
|
3761
|
+
outputFormat: "this.options.logger"
|
|
3527
3762
|
});
|
|
3528
3763
|
this.errorBoundary = new GeneratorErrorBoundary(this.errorHandler);
|
|
3529
3764
|
this.logger.debug(`${this.getLanguageName()} generator initialized`);
|
|
@@ -5195,8 +5430,8 @@ var Writer = class extends FileSystemWriter {
|
|
|
5195
5430
|
}
|
|
5196
5431
|
disclaimer() {
|
|
5197
5432
|
return [
|
|
5198
|
-
"WARNING: This file is autogenerated by
|
|
5199
|
-
"https://github.com/
|
|
5433
|
+
"WARNING: This file is autogenerated by @atomic-ehr/codegen.",
|
|
5434
|
+
"GitHub: https://github.com/orgs/atomic-ehr/repositories",
|
|
5200
5435
|
"Any manual changes made to this file may be overwritten."
|
|
5201
5436
|
];
|
|
5202
5437
|
}
|