@atomic-ehr/codegen 0.0.1-canary.20251007145120.703d8ab → 0.0.1-canary.20251008092936.b434b77
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 +26 -38
- package/dist/index.d.ts +3 -12
- package/dist/index.js +135 -520
- package/dist/index.js.map +1 -1
- package/package.json +1 -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, logger) => {
|
|
1418
1418
|
const packages = await manager.packages();
|
|
1419
1419
|
const flatRawIndex = {};
|
|
1420
1420
|
const indexByPackages = [];
|
|
@@ -1450,7 +1450,7 @@ var registerFromManager = async (manager, logger2) => {
|
|
|
1450
1450
|
nameToCanonical[rfs.name] = rfs.url;
|
|
1451
1451
|
fsSuccess++;
|
|
1452
1452
|
} catch (error) {
|
|
1453
|
-
|
|
1453
|
+
logger?.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, logger2) => {
|
|
|
1463
1463
|
vsIndex[resource.url] = resource;
|
|
1464
1464
|
}
|
|
1465
1465
|
}
|
|
1466
|
-
|
|
1466
|
+
logger?.success(
|
|
1467
1467
|
`FHIR Schema conversion for '${packageMetaToFhir(packageMeta)}' completed: ${fsSuccess} successful, ${fsFailed} failed`
|
|
1468
1468
|
);
|
|
1469
1469
|
}
|
|
@@ -1484,6 +1484,9 @@ var registerFromManager = async (manager, logger2) => {
|
|
|
1484
1484
|
}
|
|
1485
1485
|
return genealogy;
|
|
1486
1486
|
};
|
|
1487
|
+
const resolveFsSpecializations = (canonicalUrl) => {
|
|
1488
|
+
return resolveFsGenealogy(canonicalUrl).filter((fs2) => fs2.derivation === "specialization");
|
|
1489
|
+
};
|
|
1487
1490
|
return {
|
|
1488
1491
|
...manager,
|
|
1489
1492
|
appendFs(fs2) {
|
|
@@ -1493,6 +1496,7 @@ var registerFromManager = async (manager, logger2) => {
|
|
|
1493
1496
|
},
|
|
1494
1497
|
resolveFs: (canonicalUrl) => fsIndex[canonicalUrl],
|
|
1495
1498
|
resolveFsGenealogy,
|
|
1499
|
+
resolveFsSpecializations,
|
|
1496
1500
|
ensureCanonicalUrl: (name) => nameToCanonical[name] || name,
|
|
1497
1501
|
allSd: () => Object.values(sdIndex),
|
|
1498
1502
|
resolveSd: (canonicalUrl) => sdIndex[canonicalUrl],
|
|
@@ -1546,16 +1550,6 @@ function mkIdentifier(fhirSchema) {
|
|
|
1546
1550
|
url: fhirSchema.url
|
|
1547
1551
|
};
|
|
1548
1552
|
}
|
|
1549
|
-
function mkNestedIdentifier(fhirSchema, path) {
|
|
1550
|
-
const nestedName = path.join(".");
|
|
1551
|
-
return {
|
|
1552
|
-
kind: "nested",
|
|
1553
|
-
package: fhirSchema.package_meta.name,
|
|
1554
|
-
version: fhirSchema.package_meta.version,
|
|
1555
|
-
name: nestedName,
|
|
1556
|
-
url: `${fhirSchema.url}#${nestedName}`
|
|
1557
|
-
};
|
|
1558
|
-
}
|
|
1559
1553
|
var getValueSetName = (url) => {
|
|
1560
1554
|
const urlParts = url.split("/");
|
|
1561
1555
|
const lastSegment = urlParts[urlParts.length - 1];
|
|
@@ -1595,172 +1589,99 @@ function mkBindingIdentifier(fhirSchema, path, bindingName) {
|
|
|
1595
1589
|
};
|
|
1596
1590
|
}
|
|
1597
1591
|
|
|
1598
|
-
// src/typeschema/
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
if (
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
const baseUrl = fhirSchema.base.includes("/") ? fhirSchema.base : `http://hl7.org/fhir/StructureDefinition/${fhirSchema.base}`;
|
|
1607
|
-
const baseName = fhirSchema.base.split("/").pop() || fhirSchema.base;
|
|
1608
|
-
const baseKind = await determineBaseKind(baseUrl, register);
|
|
1609
|
-
const isStandardFhir = baseUrl.startsWith("http://hl7.org/fhir/");
|
|
1610
|
-
base = {
|
|
1611
|
-
kind: baseKind,
|
|
1612
|
-
package: isStandardFhir ? "hl7.fhir.r4.core" : fhirSchema.package_meta.name || "undefined",
|
|
1613
|
-
version: isStandardFhir ? "4.0.1" : fhirSchema.package_meta.version || "undefined",
|
|
1614
|
-
name: baseName,
|
|
1615
|
-
url: baseUrl
|
|
1616
|
-
};
|
|
1617
|
-
}
|
|
1618
|
-
const profileSchema = {
|
|
1619
|
-
identifier,
|
|
1620
|
-
base,
|
|
1621
|
-
dependencies: base ? [base] : []
|
|
1622
|
-
};
|
|
1623
|
-
if (fhirSchema.description) {
|
|
1624
|
-
profileSchema.description = fhirSchema.description;
|
|
1625
|
-
}
|
|
1626
|
-
const metadata = extractProfileMetadata(fhirSchema);
|
|
1627
|
-
if (Object.keys(metadata).length > 0) {
|
|
1628
|
-
profileSchema.metadata = metadata;
|
|
1629
|
-
}
|
|
1630
|
-
if (fhirSchema.elements) {
|
|
1631
|
-
const fields = await mkFields(register, fhirSchema, [], fhirSchema.elements, logger2);
|
|
1632
|
-
if (fields && Object.keys(fields).length > 0) {
|
|
1633
|
-
profileSchema.fields = fields;
|
|
1592
|
+
// src/typeschema/core/nested-types.ts
|
|
1593
|
+
function mkNestedIdentifier(register, fhirSchema, path, logger) {
|
|
1594
|
+
var nestedTypeOrigins = {};
|
|
1595
|
+
if (fhirSchema.derivation === "constraint") {
|
|
1596
|
+
const specializations = register.resolveFsSpecializations(fhirSchema.url);
|
|
1597
|
+
const nestedTypeGenealogy = specializations.map((fs2) => mkNestedTypes(register, fs2, logger)).filter((e) => e !== void 0).flat();
|
|
1598
|
+
for (const nt of nestedTypeGenealogy.reverse()) {
|
|
1599
|
+
nestedTypeOrigins[nt.identifier.name] = nt.identifier.url;
|
|
1634
1600
|
}
|
|
1635
1601
|
}
|
|
1636
|
-
const
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
if (validationRules.length > 0) {
|
|
1646
|
-
profileSchema.validation = validationRules;
|
|
1647
|
-
}
|
|
1648
|
-
return profileSchema;
|
|
1602
|
+
const nestedName = path.join(".");
|
|
1603
|
+
const url = nestedTypeOrigins[nestedName] ?? `${fhirSchema.url}#${nestedName}`;
|
|
1604
|
+
return {
|
|
1605
|
+
kind: "nested",
|
|
1606
|
+
package: fhirSchema.package_meta.name,
|
|
1607
|
+
version: fhirSchema.package_meta.version,
|
|
1608
|
+
name: nestedName,
|
|
1609
|
+
url
|
|
1610
|
+
};
|
|
1649
1611
|
}
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
if (
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
if (baseSchema.kind === "complex-type") return "complex-type";
|
|
1612
|
+
function collectNestedElements(fhirSchema, parentPath, elements) {
|
|
1613
|
+
const nested = [];
|
|
1614
|
+
for (const [key, element] of Object.entries(elements)) {
|
|
1615
|
+
const path = [...parentPath, key];
|
|
1616
|
+
if (isNestedElement(element)) {
|
|
1617
|
+
nested.push([path, element]);
|
|
1618
|
+
}
|
|
1619
|
+
if (element.elements) {
|
|
1620
|
+
nested.push(...collectNestedElements(fhirSchema, path, element.elements));
|
|
1660
1621
|
}
|
|
1661
|
-
} catch (error) {
|
|
1662
|
-
console.warn(`Could not resolve base schema ${baseUrl}:`, error);
|
|
1663
|
-
}
|
|
1664
|
-
if (baseUrl.includes("StructureDefinition/") && !baseUrl.startsWith("http://hl7.org/fhir/StructureDefinition/")) {
|
|
1665
|
-
return "profile";
|
|
1666
1622
|
}
|
|
1667
|
-
return
|
|
1668
|
-
}
|
|
1669
|
-
function extractProfileMetadata(fhirSchema) {
|
|
1670
|
-
const metadata = {};
|
|
1671
|
-
const packageInfo = fhirSchema.package_meta;
|
|
1672
|
-
if (fhirSchema.publisher) metadata.publisher = fhirSchema.publisher;
|
|
1673
|
-
if (fhirSchema.contact) metadata.contact = fhirSchema.contact;
|
|
1674
|
-
if (fhirSchema.copyright) metadata.copyright = fhirSchema.copyright;
|
|
1675
|
-
if (fhirSchema.purpose) metadata.purpose = fhirSchema.purpose;
|
|
1676
|
-
if (fhirSchema.experimental !== void 0) {
|
|
1677
|
-
metadata.experimental = fhirSchema.experimental;
|
|
1678
|
-
}
|
|
1679
|
-
if (fhirSchema.date) metadata.date = fhirSchema.date;
|
|
1680
|
-
if (fhirSchema.jurisdiction) metadata.jurisdiction = fhirSchema.jurisdiction;
|
|
1681
|
-
if (packageInfo?.name) {
|
|
1682
|
-
metadata.package = packageInfo.name;
|
|
1683
|
-
} else if (fhirSchema.package_meta.name) {
|
|
1684
|
-
metadata.package = fhirSchema.package_meta.name;
|
|
1685
|
-
}
|
|
1686
|
-
return metadata;
|
|
1623
|
+
return nested;
|
|
1687
1624
|
}
|
|
1688
|
-
|
|
1689
|
-
const
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
if (element.fixedValue !== void 0)
|
|
1697
|
-
elementConstraints.fixedValue = element.fixedValue;
|
|
1698
|
-
if (element.patternValue !== void 0)
|
|
1699
|
-
elementConstraints.patternValue = element.patternValue;
|
|
1700
|
-
if (element.binding) {
|
|
1701
|
-
elementConstraints.binding = {
|
|
1702
|
-
strength: element.binding.strength,
|
|
1703
|
-
valueSet: element.binding.valueSet ?? ""
|
|
1704
|
-
};
|
|
1705
|
-
}
|
|
1706
|
-
if (element.type && Array.isArray(element.type) && element.type.length > 0) {
|
|
1707
|
-
elementConstraints.types = element.type.map((t) => {
|
|
1708
|
-
const typeConstraint = { code: t.code };
|
|
1709
|
-
if (t.profile) typeConstraint.profile = t.profile;
|
|
1710
|
-
if (t.targetProfile) typeConstraint.targetProfile = t.targetProfile;
|
|
1711
|
-
return typeConstraint;
|
|
1712
|
-
});
|
|
1713
|
-
}
|
|
1714
|
-
if (element.slicing) {
|
|
1715
|
-
elementConstraints.slicing = {
|
|
1716
|
-
discriminator: element.slicing.discriminator ?? [],
|
|
1717
|
-
rules: String(element.slicing),
|
|
1718
|
-
ordered: element.slicing.ordered
|
|
1719
|
-
};
|
|
1720
|
-
}
|
|
1721
|
-
if (Object.keys(elementConstraints).length > 0) {
|
|
1722
|
-
constraints[path] = elementConstraints;
|
|
1625
|
+
function transformNestedElements(register, fhirSchema, parentPath, elements, logger) {
|
|
1626
|
+
const fields = {};
|
|
1627
|
+
for (const [key, element] of Object.entries(elements)) {
|
|
1628
|
+
const path = [...parentPath, key];
|
|
1629
|
+
if (isNestedElement(element)) {
|
|
1630
|
+
fields[key] = mkNestedField(register, fhirSchema, path, element, logger);
|
|
1631
|
+
} else {
|
|
1632
|
+
fields[key] = mkField(register, fhirSchema, path, element, logger);
|
|
1723
1633
|
}
|
|
1724
1634
|
}
|
|
1725
|
-
return
|
|
1635
|
+
return fields;
|
|
1726
1636
|
}
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
-
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
});
|
|
1741
|
-
}
|
|
1742
|
-
}
|
|
1637
|
+
function mkNestedTypes(register, fhirSchema, logger) {
|
|
1638
|
+
if (!fhirSchema.elements) return void 0;
|
|
1639
|
+
const nested = collectNestedElements(fhirSchema, [], fhirSchema.elements).filter(
|
|
1640
|
+
([_, element]) => element.elements && Object.keys(element.elements).length > 0
|
|
1641
|
+
);
|
|
1642
|
+
const nestedTypes = [];
|
|
1643
|
+
for (const [path, element] of nested) {
|
|
1644
|
+
const identifier = mkNestedIdentifier(register, fhirSchema, path, logger);
|
|
1645
|
+
let baseName;
|
|
1646
|
+
if (element.type === "BackboneElement" || !element.type) {
|
|
1647
|
+
baseName = "BackboneElement";
|
|
1648
|
+
} else {
|
|
1649
|
+
baseName = element.type;
|
|
1743
1650
|
}
|
|
1651
|
+
const base = {
|
|
1652
|
+
kind: "complex-type",
|
|
1653
|
+
package: fhirSchema.package_meta.name,
|
|
1654
|
+
version: fhirSchema.package_meta.version,
|
|
1655
|
+
name: baseName,
|
|
1656
|
+
url: register.ensureCanonicalUrl(baseName)
|
|
1657
|
+
};
|
|
1658
|
+
const fields = transformNestedElements(register, fhirSchema, path, element.elements, logger);
|
|
1659
|
+
const nestedType = {
|
|
1660
|
+
identifier,
|
|
1661
|
+
base,
|
|
1662
|
+
fields
|
|
1663
|
+
};
|
|
1664
|
+
nestedTypes.push(nestedType);
|
|
1744
1665
|
}
|
|
1745
|
-
|
|
1666
|
+
nestedTypes.sort((a, b) => a.identifier.url.localeCompare(b.identifier.url));
|
|
1667
|
+
return nestedTypes.length === 0 ? void 0 : nestedTypes;
|
|
1746
1668
|
}
|
|
1747
|
-
function
|
|
1748
|
-
const
|
|
1749
|
-
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
});
|
|
1669
|
+
function extractNestedDependencies(nestedTypes) {
|
|
1670
|
+
const deps = [];
|
|
1671
|
+
for (const nested of nestedTypes) {
|
|
1672
|
+
if (nested.base) {
|
|
1673
|
+
deps.push(nested.base);
|
|
1674
|
+
}
|
|
1675
|
+
for (const field of Object.values(nested.fields || {})) {
|
|
1676
|
+
if ("type" in field && field.type) {
|
|
1677
|
+
deps.push(field.type);
|
|
1678
|
+
}
|
|
1679
|
+
if ("binding" in field && field.binding) {
|
|
1680
|
+
deps.push(field.binding);
|
|
1760
1681
|
}
|
|
1761
1682
|
}
|
|
1762
1683
|
}
|
|
1763
|
-
return
|
|
1684
|
+
return deps;
|
|
1764
1685
|
}
|
|
1765
1686
|
|
|
1766
1687
|
// src/typeschema/core/field-builder.ts
|
|
@@ -1801,11 +1722,11 @@ var buildReferences = (element, register, _packageInfo) => {
|
|
|
1801
1722
|
return mkIdentifier(fs2);
|
|
1802
1723
|
});
|
|
1803
1724
|
};
|
|
1804
|
-
function buildFieldType(register, fhirSchema, element) {
|
|
1725
|
+
function buildFieldType(register, fhirSchema, element, logger) {
|
|
1805
1726
|
if (element.elementReference) {
|
|
1806
1727
|
const refPath = element.elementReference.filter((_, i) => i % 2 === 1).map((p) => p).filter((p) => p !== "elements");
|
|
1807
1728
|
if (refPath.length > 0) {
|
|
1808
|
-
return mkNestedIdentifier(fhirSchema, refPath);
|
|
1729
|
+
return mkNestedIdentifier(register, fhirSchema, refPath, logger);
|
|
1809
1730
|
}
|
|
1810
1731
|
}
|
|
1811
1732
|
if (element.type) {
|
|
@@ -1825,17 +1746,17 @@ function buildFieldType(register, fhirSchema, element) {
|
|
|
1825
1746
|
}
|
|
1826
1747
|
return void 0;
|
|
1827
1748
|
}
|
|
1828
|
-
var mkField = (register, fhirSchema, path, element,
|
|
1749
|
+
var mkField = (register, fhirSchema, path, element, logger) => {
|
|
1829
1750
|
let binding;
|
|
1830
1751
|
let enumValues;
|
|
1831
1752
|
if (element.binding) {
|
|
1832
1753
|
binding = mkBindingIdentifier(fhirSchema, path, element.binding.bindingName);
|
|
1833
1754
|
if (element.binding.strength === "required" && element.type === "code") {
|
|
1834
|
-
enumValues = buildEnum(register, element,
|
|
1755
|
+
enumValues = buildEnum(register, element, logger);
|
|
1835
1756
|
}
|
|
1836
1757
|
}
|
|
1837
1758
|
return {
|
|
1838
|
-
type: buildFieldType(register, fhirSchema, element),
|
|
1759
|
+
type: buildFieldType(register, fhirSchema, element, logger),
|
|
1839
1760
|
required: isRequired(register, fhirSchema, path),
|
|
1840
1761
|
excluded: isExcluded(register, fhirSchema, path),
|
|
1841
1762
|
reference: buildReferences(element, register, fhirSchema.package_meta),
|
|
@@ -1854,9 +1775,9 @@ function isNestedElement(element) {
|
|
|
1854
1775
|
const elementsWithoutType = element.type === void 0 && element.choiceOf === void 0 && element.elements !== void 0 && Object.keys(element.elements).length > 0;
|
|
1855
1776
|
return isBackbone || isElement || elementsWithoutType;
|
|
1856
1777
|
}
|
|
1857
|
-
function mkNestedField(register, fhirSchema, path, element) {
|
|
1778
|
+
function mkNestedField(register, fhirSchema, path, element, logger) {
|
|
1858
1779
|
return {
|
|
1859
|
-
type: mkNestedIdentifier(fhirSchema, path),
|
|
1780
|
+
type: mkNestedIdentifier(register, fhirSchema, path, logger),
|
|
1860
1781
|
array: element.array || false,
|
|
1861
1782
|
required: isRequired(register, fhirSchema, path),
|
|
1862
1783
|
excluded: isExcluded(register, fhirSchema, path)
|
|
@@ -1864,7 +1785,7 @@ function mkNestedField(register, fhirSchema, path, element) {
|
|
|
1864
1785
|
}
|
|
1865
1786
|
|
|
1866
1787
|
// src/typeschema/core/binding.ts
|
|
1867
|
-
function extractValueSetConceptsByUrl(register, valueSetUrl,
|
|
1788
|
+
function extractValueSetConceptsByUrl(register, valueSetUrl, logger) {
|
|
1868
1789
|
const cleanUrl = dropVersionFromUrl(valueSetUrl) || valueSetUrl;
|
|
1869
1790
|
const valueSet = register.resolveVs(cleanUrl);
|
|
1870
1791
|
if (!valueSet) return void 0;
|
|
@@ -1909,7 +1830,7 @@ function extractValueSetConcepts(register, valueSet, _logger) {
|
|
|
1909
1830
|
return concepts.length > 0 ? concepts : void 0;
|
|
1910
1831
|
}
|
|
1911
1832
|
var MAX_ENUM_LENGTH = 100;
|
|
1912
|
-
function buildEnum(register, element,
|
|
1833
|
+
function buildEnum(register, element, logger) {
|
|
1913
1834
|
if (!element.binding) return void 0;
|
|
1914
1835
|
const strength = element.binding.strength;
|
|
1915
1836
|
const valueSetUrl = element.binding.valueSet;
|
|
@@ -1920,24 +1841,24 @@ function buildEnum(register, element, logger2) {
|
|
|
1920
1841
|
if (!concepts || concepts.length === 0) return void 0;
|
|
1921
1842
|
const codes = concepts.map((c) => c.code).filter((code) => code && typeof code === "string" && code.trim().length > 0);
|
|
1922
1843
|
if (codes.length > MAX_ENUM_LENGTH) {
|
|
1923
|
-
|
|
1844
|
+
logger?.dry_warn(
|
|
1924
1845
|
`Value set ${valueSetUrl} has ${codes.length} which is more than ${MAX_ENUM_LENGTH} codes, which may cause issues with code generation.`
|
|
1925
1846
|
);
|
|
1926
1847
|
return void 0;
|
|
1927
1848
|
}
|
|
1928
1849
|
return codes.length > 0 ? codes : void 0;
|
|
1929
1850
|
}
|
|
1930
|
-
function generateBindingSchema(register, fhirSchema, path, element,
|
|
1851
|
+
function generateBindingSchema(register, fhirSchema, path, element, logger) {
|
|
1931
1852
|
if (!element.binding?.valueSet) return void 0;
|
|
1932
1853
|
const identifier = mkBindingIdentifier(fhirSchema, path, element.binding.bindingName);
|
|
1933
|
-
const fieldType = buildFieldType(register, fhirSchema, element);
|
|
1854
|
+
const fieldType = buildFieldType(register, fhirSchema, element, logger);
|
|
1934
1855
|
const valueSetIdentifier = mkValueSetIdentifierByUrl(register, element.binding.valueSet);
|
|
1935
1856
|
const dependencies = [];
|
|
1936
1857
|
if (fieldType) {
|
|
1937
1858
|
dependencies.push(fieldType);
|
|
1938
1859
|
}
|
|
1939
1860
|
dependencies.push(valueSetIdentifier);
|
|
1940
|
-
const enumValues = buildEnum(register, element,
|
|
1861
|
+
const enumValues = buildEnum(register, element, logger);
|
|
1941
1862
|
return {
|
|
1942
1863
|
identifier,
|
|
1943
1864
|
type: fieldType,
|
|
@@ -1947,7 +1868,7 @@ function generateBindingSchema(register, fhirSchema, path, element, logger2) {
|
|
|
1947
1868
|
dependencies
|
|
1948
1869
|
};
|
|
1949
1870
|
}
|
|
1950
|
-
function collectBindingSchemas(register, fhirSchema,
|
|
1871
|
+
function collectBindingSchemas(register, fhirSchema, logger) {
|
|
1951
1872
|
const processedPaths = /* @__PURE__ */ new Set();
|
|
1952
1873
|
if (!fhirSchema.elements) return [];
|
|
1953
1874
|
const bindings = [];
|
|
@@ -1958,7 +1879,7 @@ function collectBindingSchemas(register, fhirSchema, logger2) {
|
|
|
1958
1879
|
if (processedPaths.has(pathKey)) continue;
|
|
1959
1880
|
processedPaths.add(pathKey);
|
|
1960
1881
|
if (element.binding) {
|
|
1961
|
-
const binding = generateBindingSchema(register, fhirSchema, path, element,
|
|
1882
|
+
const binding = generateBindingSchema(register, fhirSchema, path, element, logger);
|
|
1962
1883
|
if (binding) {
|
|
1963
1884
|
bindings.push(binding);
|
|
1964
1885
|
}
|
|
@@ -1981,90 +1902,8 @@ function collectBindingSchemas(register, fhirSchema, logger2) {
|
|
|
1981
1902
|
return uniqueBindings;
|
|
1982
1903
|
}
|
|
1983
1904
|
|
|
1984
|
-
// src/typeschema/core/nested-types.ts
|
|
1985
|
-
function collectNestedElements(fhirSchema, parentPath, elements) {
|
|
1986
|
-
const nested = [];
|
|
1987
|
-
for (const [key, element] of Object.entries(elements)) {
|
|
1988
|
-
const path = [...parentPath, key];
|
|
1989
|
-
if (isNestedElement(element)) {
|
|
1990
|
-
nested.push([path, element]);
|
|
1991
|
-
}
|
|
1992
|
-
if (element.elements) {
|
|
1993
|
-
nested.push(...collectNestedElements(fhirSchema, path, element.elements));
|
|
1994
|
-
}
|
|
1995
|
-
}
|
|
1996
|
-
return nested;
|
|
1997
|
-
}
|
|
1998
|
-
function transformNestedElements(fhirSchema, parentPath, elements, register, logger2) {
|
|
1999
|
-
const fields = {};
|
|
2000
|
-
for (const [key, element] of Object.entries(elements)) {
|
|
2001
|
-
const path = [...parentPath, key];
|
|
2002
|
-
if (isNestedElement(element)) {
|
|
2003
|
-
fields[key] = mkNestedField(register, fhirSchema, path, element);
|
|
2004
|
-
} else {
|
|
2005
|
-
fields[key] = mkField(register, fhirSchema, path, element, logger2);
|
|
2006
|
-
}
|
|
2007
|
-
}
|
|
2008
|
-
return fields;
|
|
2009
|
-
}
|
|
2010
|
-
function mkNestedTypes(register, fhirSchema, logger2) {
|
|
2011
|
-
if (!fhirSchema.elements) return void 0;
|
|
2012
|
-
const nestedElements = collectNestedElements(fhirSchema, [], fhirSchema.elements);
|
|
2013
|
-
const actualNested = nestedElements.filter(
|
|
2014
|
-
([_, element]) => element.elements && Object.keys(element.elements).length > 0
|
|
2015
|
-
);
|
|
2016
|
-
const nestedTypes = [];
|
|
2017
|
-
for (const [path, element] of actualNested) {
|
|
2018
|
-
const identifier = mkNestedIdentifier(fhirSchema, path);
|
|
2019
|
-
let base;
|
|
2020
|
-
if (element.type === "BackboneElement" || !element.type) {
|
|
2021
|
-
base = {
|
|
2022
|
-
kind: "complex-type",
|
|
2023
|
-
package: fhirSchema.package_meta.name,
|
|
2024
|
-
version: fhirSchema.package_meta.version,
|
|
2025
|
-
name: "BackboneElement",
|
|
2026
|
-
url: "http://hl7.org/fhir/StructureDefinition/BackboneElement"
|
|
2027
|
-
};
|
|
2028
|
-
} else {
|
|
2029
|
-
base = {
|
|
2030
|
-
kind: "complex-type",
|
|
2031
|
-
package: fhirSchema.package_meta.name,
|
|
2032
|
-
version: fhirSchema.package_meta.version,
|
|
2033
|
-
name: element.type,
|
|
2034
|
-
url: `http://hl7.org/fhir/StructureDefinition/${element.type}`
|
|
2035
|
-
};
|
|
2036
|
-
}
|
|
2037
|
-
const fields = transformNestedElements(fhirSchema, path, element.elements, register, logger2);
|
|
2038
|
-
const nestedType = {
|
|
2039
|
-
identifier,
|
|
2040
|
-
base,
|
|
2041
|
-
fields
|
|
2042
|
-
};
|
|
2043
|
-
nestedTypes.push(nestedType);
|
|
2044
|
-
}
|
|
2045
|
-
nestedTypes.sort((a, b) => a.identifier.url.localeCompare(b.identifier.url));
|
|
2046
|
-
return nestedTypes.length === 0 ? void 0 : nestedTypes;
|
|
2047
|
-
}
|
|
2048
|
-
function extractNestedDependencies(nestedTypes) {
|
|
2049
|
-
const deps = [];
|
|
2050
|
-
for (const nested of nestedTypes) {
|
|
2051
|
-
if (nested.base) {
|
|
2052
|
-
deps.push(nested.base);
|
|
2053
|
-
}
|
|
2054
|
-
for (const field of Object.values(nested.fields || {})) {
|
|
2055
|
-
if ("type" in field && field.type) {
|
|
2056
|
-
deps.push(field.type);
|
|
2057
|
-
}
|
|
2058
|
-
if ("binding" in field && field.binding) {
|
|
2059
|
-
deps.push(field.binding);
|
|
2060
|
-
}
|
|
2061
|
-
}
|
|
2062
|
-
}
|
|
2063
|
-
return deps;
|
|
2064
|
-
}
|
|
2065
|
-
|
|
2066
1905
|
// src/typeschema/core/transformer.ts
|
|
2067
|
-
function mkFields(register, fhirSchema, parentPath, elements,
|
|
1906
|
+
function mkFields(register, fhirSchema, parentPath, elements, logger) {
|
|
2068
1907
|
if (!elements) return void 0;
|
|
2069
1908
|
const geneology = register.resolveFsGenealogy(fhirSchema.url);
|
|
2070
1909
|
const elems = {};
|
|
@@ -2087,9 +1926,9 @@ function mkFields(register, fhirSchema, parentPath, elements, logger2) {
|
|
|
2087
1926
|
const fields = {};
|
|
2088
1927
|
for (const [key, { elem, elemSnapshot, path }] of Object.entries(elems)) {
|
|
2089
1928
|
if (isNestedElement(elemSnapshot)) {
|
|
2090
|
-
fields[key] = mkNestedField(register, fhirSchema, path, elemSnapshot);
|
|
1929
|
+
fields[key] = mkNestedField(register, fhirSchema, path, elemSnapshot, logger);
|
|
2091
1930
|
} else {
|
|
2092
|
-
fields[key] = mkField(register, fhirSchema, path, elemSnapshot,
|
|
1931
|
+
fields[key] = mkField(register, fhirSchema, path, elemSnapshot, logger);
|
|
2093
1932
|
}
|
|
2094
1933
|
}
|
|
2095
1934
|
return fields;
|
|
@@ -2134,7 +1973,7 @@ function isExtensionSchema(fhirSchema, _identifier) {
|
|
|
2134
1973
|
}
|
|
2135
1974
|
return false;
|
|
2136
1975
|
}
|
|
2137
|
-
async function transformValueSet(register, valueSet,
|
|
1976
|
+
async function transformValueSet(register, valueSet, logger) {
|
|
2138
1977
|
if (!valueSet.url) throw new Error("ValueSet URL is required");
|
|
2139
1978
|
const identifier = mkValueSetIdentifierByUrl(register, valueSet.url);
|
|
2140
1979
|
const concept = extractValueSetConceptsByUrl(register, valueSet.url);
|
|
@@ -2145,7 +1984,7 @@ async function transformValueSet(register, valueSet, logger2) {
|
|
|
2145
1984
|
compose: !concept ? valueSet.compose : void 0
|
|
2146
1985
|
};
|
|
2147
1986
|
}
|
|
2148
|
-
async function transformExtension(fhirSchema, register,
|
|
1987
|
+
async function transformExtension(fhirSchema, register, logger) {
|
|
2149
1988
|
try {
|
|
2150
1989
|
const identifier = mkIdentifier(fhirSchema);
|
|
2151
1990
|
let base;
|
|
@@ -2182,13 +2021,13 @@ async function transformExtension(fhirSchema, register, logger2) {
|
|
|
2182
2021
|
extensionSchema.dependencies.push(base);
|
|
2183
2022
|
}
|
|
2184
2023
|
if (fhirSchema.elements) {
|
|
2185
|
-
const fields = mkFields(register, fhirSchema, [], fhirSchema.elements,
|
|
2024
|
+
const fields = mkFields(register, fhirSchema, [], fhirSchema.elements, logger);
|
|
2186
2025
|
if (fields && Object.keys(fields).length > 0) {
|
|
2187
2026
|
extensionSchema.fields = fields;
|
|
2188
2027
|
extensionSchema.dependencies.push(...extractFieldDependencies(fields));
|
|
2189
2028
|
}
|
|
2190
2029
|
}
|
|
2191
|
-
const nestedTypes = mkNestedTypes(register, fhirSchema,
|
|
2030
|
+
const nestedTypes = mkNestedTypes(register, fhirSchema, logger);
|
|
2192
2031
|
if (nestedTypes && nestedTypes.length > 0) {
|
|
2193
2032
|
extensionSchema.nested = nestedTypes;
|
|
2194
2033
|
extensionSchema.dependencies.push(...extractNestedDependencies(nestedTypes));
|
|
@@ -2215,7 +2054,7 @@ function extractDependencies(identifier, base, fields, nestedTypes) {
|
|
|
2215
2054
|
const result = Object.values(uniqDeps).filter((e) => !(e.kind === "nested" && localNestedTypeUrls.has(e.url))).sort((a, b) => a.url.localeCompare(b.url));
|
|
2216
2055
|
return result.length > 0 ? result : void 0;
|
|
2217
2056
|
}
|
|
2218
|
-
function transformFhirSchemaResource(register, fhirSchema,
|
|
2057
|
+
function transformFhirSchemaResource(register, fhirSchema, logger) {
|
|
2219
2058
|
const identifier = mkIdentifier(fhirSchema);
|
|
2220
2059
|
let base;
|
|
2221
2060
|
if (fhirSchema.base && fhirSchema.type !== "Element") {
|
|
@@ -2225,8 +2064,8 @@ function transformFhirSchemaResource(register, fhirSchema, logger2) {
|
|
|
2225
2064
|
}
|
|
2226
2065
|
base = mkIdentifier(baseFs);
|
|
2227
2066
|
}
|
|
2228
|
-
const fields = mkFields(register, fhirSchema, [], fhirSchema.elements,
|
|
2229
|
-
const nested = mkNestedTypes(register, fhirSchema,
|
|
2067
|
+
const fields = mkFields(register, fhirSchema, [], fhirSchema.elements, logger);
|
|
2068
|
+
const nested = mkNestedTypes(register, fhirSchema, logger);
|
|
2230
2069
|
const dependencies = extractDependencies(identifier, base, fields, nested);
|
|
2231
2070
|
const typeSchema = {
|
|
2232
2071
|
identifier,
|
|
@@ -2236,27 +2075,20 @@ function transformFhirSchemaResource(register, fhirSchema, logger2) {
|
|
|
2236
2075
|
description: fhirSchema.description,
|
|
2237
2076
|
dependencies
|
|
2238
2077
|
};
|
|
2239
|
-
const bindingSchemas = collectBindingSchemas(register, fhirSchema,
|
|
2078
|
+
const bindingSchemas = collectBindingSchemas(register, fhirSchema, logger);
|
|
2240
2079
|
return [typeSchema, ...bindingSchemas];
|
|
2241
2080
|
}
|
|
2242
|
-
async function transformFhirSchema(register, fhirSchema,
|
|
2081
|
+
async function transformFhirSchema(register, fhirSchema, logger) {
|
|
2243
2082
|
const results = [];
|
|
2244
|
-
|
|
2245
|
-
if (identifier.kind === "profile") {
|
|
2246
|
-
const profileSchema = await transformProfile(register, fhirSchema, logger2);
|
|
2247
|
-
results.push(profileSchema);
|
|
2248
|
-
const bindingSchemas = collectBindingSchemas(register, fhirSchema, logger2);
|
|
2249
|
-
results.push(...bindingSchemas);
|
|
2250
|
-
return results;
|
|
2251
|
-
}
|
|
2083
|
+
mkIdentifier(fhirSchema);
|
|
2252
2084
|
if (isExtensionSchema(fhirSchema)) {
|
|
2253
|
-
const extensionSchema = await transformExtension(fhirSchema, register,
|
|
2085
|
+
const extensionSchema = await transformExtension(fhirSchema, register, logger);
|
|
2254
2086
|
if (extensionSchema) {
|
|
2255
2087
|
results.push(extensionSchema);
|
|
2256
2088
|
}
|
|
2257
2089
|
return results;
|
|
2258
2090
|
}
|
|
2259
|
-
return transformFhirSchemaResource(register, fhirSchema,
|
|
2091
|
+
return transformFhirSchemaResource(register, fhirSchema, logger);
|
|
2260
2092
|
}
|
|
2261
2093
|
var TypeSchemaCache = class {
|
|
2262
2094
|
cache = /* @__PURE__ */ new Map();
|
|
@@ -2476,224 +2308,6 @@ var TypeSchemaCache = class {
|
|
|
2476
2308
|
}
|
|
2477
2309
|
}
|
|
2478
2310
|
};
|
|
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
|
|
2697
2311
|
var CodegenLogger = class _CodegenLogger {
|
|
2698
2312
|
options;
|
|
2699
2313
|
dryWarnSet = /* @__PURE__ */ new Set();
|
|
@@ -2869,11 +2483,11 @@ var TypeSchemaGenerator = class {
|
|
|
2869
2483
|
);
|
|
2870
2484
|
return fhirSchemas;
|
|
2871
2485
|
}
|
|
2872
|
-
async generateValueSetSchemas(valueSets,
|
|
2486
|
+
async generateValueSetSchemas(valueSets, logger) {
|
|
2873
2487
|
if (valueSets.length > 0) {
|
|
2874
2488
|
this.logger?.debug(`${valueSets.length} ValueSets available for enum extraction`);
|
|
2875
2489
|
}
|
|
2876
|
-
const register = await registerFromManager(this.manager,
|
|
2490
|
+
const register = await registerFromManager(this.manager, logger);
|
|
2877
2491
|
const valueSetSchemas = [];
|
|
2878
2492
|
if (valueSets.length > 0) {
|
|
2879
2493
|
this.logger?.progress(`Converting ${valueSets.length} ValueSets to TypeSchema`);
|
|
@@ -2881,7 +2495,7 @@ var TypeSchemaGenerator = class {
|
|
|
2881
2495
|
let valueSetFailedCount = 0;
|
|
2882
2496
|
for (const vs of valueSets) {
|
|
2883
2497
|
try {
|
|
2884
|
-
const valueSetSchema = await transformValueSet(register, vs,
|
|
2498
|
+
const valueSetSchema = await transformValueSet(register, vs, logger);
|
|
2885
2499
|
if (valueSetSchema) {
|
|
2886
2500
|
valueSetSchemas.push(valueSetSchema);
|
|
2887
2501
|
valueSetConvertedCount++;
|
|
@@ -2900,7 +2514,7 @@ var TypeSchemaGenerator = class {
|
|
|
2900
2514
|
}
|
|
2901
2515
|
return valueSetSchemas;
|
|
2902
2516
|
}
|
|
2903
|
-
async generateFromPackage(packageName, packageVersion,
|
|
2517
|
+
async generateFromPackage(packageName, packageVersion, logger) {
|
|
2904
2518
|
await this.initializeCache();
|
|
2905
2519
|
if (this.cache && !(this.cacheConfig?.forceRegenerate ?? false)) {
|
|
2906
2520
|
const cachedSchemas = this.cache.getByPackage(packageName);
|
|
@@ -2916,8 +2530,8 @@ var TypeSchemaGenerator = class {
|
|
|
2916
2530
|
version: packageVersion || "latest"
|
|
2917
2531
|
};
|
|
2918
2532
|
const register = await this.registerFromPackageMetas([packageInfo]);
|
|
2919
|
-
const valueSets = await this.generateValueSetSchemas(register.allVs(),
|
|
2920
|
-
const fhirSchemas = (await Promise.all(register.allFs().map(async (fs2) => await transformFhirSchema(register, fs2,
|
|
2533
|
+
const valueSets = await this.generateValueSetSchemas(register.allVs(), logger);
|
|
2534
|
+
const fhirSchemas = (await Promise.all(register.allFs().map(async (fs2) => await transformFhirSchema(register, fs2, logger)))).flat();
|
|
2921
2535
|
const allSchemas = [...fhirSchemas, ...valueSets];
|
|
2922
2536
|
if (this.cache) {
|
|
2923
2537
|
for (const schema of allSchemas) {
|
|
@@ -3286,10 +2900,10 @@ var TypeSchemaParser = class {
|
|
|
3286
2900
|
};
|
|
3287
2901
|
|
|
3288
2902
|
// src/typeschema/index.ts
|
|
3289
|
-
var generateTypeSchemas = async (register,
|
|
2903
|
+
var generateTypeSchemas = async (register, logger) => {
|
|
3290
2904
|
const fhirSchemas = [];
|
|
3291
2905
|
for (const fhirSchema of register.allFs()) {
|
|
3292
|
-
fhirSchemas.push(...await transformFhirSchema(register, fhirSchema,
|
|
2906
|
+
fhirSchemas.push(...await transformFhirSchema(register, fhirSchema, logger));
|
|
3293
2907
|
}
|
|
3294
2908
|
for (const vsSchema of register.allVs()) {
|
|
3295
2909
|
fhirSchemas.push(await transformValueSet(register, vsSchema));
|
|
@@ -5401,9 +5015,12 @@ var Writer = class extends FileSystemWriter {
|
|
|
5401
5015
|
this.write(" ".repeat(this.currentIndent));
|
|
5402
5016
|
}
|
|
5403
5017
|
line(...tokens) {
|
|
5404
|
-
|
|
5405
|
-
|
|
5018
|
+
if (tokens.length === 0) {
|
|
5019
|
+
this.write("\n");
|
|
5020
|
+
} else {
|
|
5021
|
+
this.write(`${tokens.join(" ")}
|
|
5406
5022
|
`);
|
|
5023
|
+
}
|
|
5407
5024
|
}
|
|
5408
5025
|
lineSM(...tokens) {
|
|
5409
5026
|
this.writeIndent();
|
|
@@ -5572,7 +5189,7 @@ var normalizeTsName = (n) => {
|
|
|
5572
5189
|
var TypeScript = class extends Writer {
|
|
5573
5190
|
resourceRelatives = [];
|
|
5574
5191
|
tsImportType(tsPackageName, ...entities) {
|
|
5575
|
-
this.lineSM(`import type { ${entities.join(", ")} } from
|
|
5192
|
+
this.lineSM(`import type { ${entities.join(", ")} } from "${tsPackageName}"`);
|
|
5576
5193
|
}
|
|
5577
5194
|
generateFhirPackageIndexFile(schemas) {
|
|
5578
5195
|
this.cat("index.ts", () => {
|
|
@@ -5586,7 +5203,7 @@ var TypeScript = class extends Writer {
|
|
|
5586
5203
|
);
|
|
5587
5204
|
for (const exp of exports) {
|
|
5588
5205
|
this.debugComment(exp.identifier);
|
|
5589
|
-
this.lineSM(`export type { ${exp.resourceName} } from
|
|
5206
|
+
this.lineSM(`export type { ${exp.resourceName} } from "./${exp.tsPackageName}"`);
|
|
5590
5207
|
}
|
|
5591
5208
|
});
|
|
5592
5209
|
}
|
|
@@ -5615,7 +5232,7 @@ var TypeScript = class extends Writer {
|
|
|
5615
5232
|
}));
|
|
5616
5233
|
if (complexTypeDeps && complexTypeDeps.length > 0) {
|
|
5617
5234
|
for (const dep of complexTypeDeps) {
|
|
5618
|
-
this.lineSM(`export type { ${dep.name} }from
|
|
5235
|
+
this.lineSM(`export type { ${dep.name} } from "${dep.tsPackage}"`);
|
|
5619
5236
|
}
|
|
5620
5237
|
this.line();
|
|
5621
5238
|
}
|
|
@@ -5642,7 +5259,7 @@ var TypeScript = class extends Writer {
|
|
|
5642
5259
|
if (schema.identifier.kind === "resource") {
|
|
5643
5260
|
const possibleResourceTypes = [schema.identifier];
|
|
5644
5261
|
possibleResourceTypes.push(...resourceChildren(this.resourceRelatives, schema.identifier));
|
|
5645
|
-
this.lineSM(`resourceType: ${possibleResourceTypes.map((e) => `
|
|
5262
|
+
this.lineSM(`resourceType: ${possibleResourceTypes.map((e) => `"${e.name}"`).join(" | ")}`);
|
|
5646
5263
|
this.line();
|
|
5647
5264
|
}
|
|
5648
5265
|
const fields = Object.entries(schema.fields).sort((a, b) => a[0].localeCompare(b[0]));
|
|
@@ -5667,11 +5284,11 @@ var TypeScript = class extends Writer {
|
|
|
5667
5284
|
type = "`${T}/${string}`";
|
|
5668
5285
|
}
|
|
5669
5286
|
if (field.reference?.length) {
|
|
5670
|
-
const references = field.reference.map((ref) => `
|
|
5287
|
+
const references = field.reference.map((ref) => `"${ref.name}"`).join(" | ");
|
|
5671
5288
|
type = `Reference<${references}>`;
|
|
5672
5289
|
}
|
|
5673
5290
|
if (field.enum) {
|
|
5674
|
-
type = field.enum.map((e) => `
|
|
5291
|
+
type = field.enum.map((e) => `"${e}"`).join(" | ");
|
|
5675
5292
|
}
|
|
5676
5293
|
this.lineSM(`${fieldNameFixed}${optionalSymbol}:`, `${type}${arraySymbol}`);
|
|
5677
5294
|
if (["resource", "complex-type"].includes(schema.identifier.kind)) {
|
|
@@ -5679,11 +5296,9 @@ var TypeScript = class extends Writer {
|
|
|
5679
5296
|
}
|
|
5680
5297
|
}
|
|
5681
5298
|
});
|
|
5682
|
-
this.line();
|
|
5683
5299
|
}
|
|
5684
5300
|
generateNestedTypes(schema) {
|
|
5685
5301
|
if (schema.nested) {
|
|
5686
|
-
this.line();
|
|
5687
5302
|
for (const subtype of schema.nested) {
|
|
5688
5303
|
this.generateType(subtype);
|
|
5689
5304
|
}
|
|
@@ -5827,7 +5442,7 @@ var APIBuilder = class {
|
|
|
5827
5442
|
typescript2(opts) {
|
|
5828
5443
|
const writerOpts = {
|
|
5829
5444
|
outputDir: Path2.join(this.options.outputDir, "/types"),
|
|
5830
|
-
tabSize:
|
|
5445
|
+
tabSize: 4,
|
|
5831
5446
|
withDebugComment: false,
|
|
5832
5447
|
commentLinePrefix: "//"
|
|
5833
5448
|
};
|