@myvitalrx/metadata-runtime 1.10.0 → 1.12.0
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 +102 -3
- package/dist/index.js +1048 -133
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1430,6 +1430,10 @@ var manifestSchema = z.object({
|
|
|
1430
1430
|
),
|
|
1431
1431
|
metadataTypes: z.record(z.string(), metadataTypeEntrySchema),
|
|
1432
1432
|
lookupIndex: z.record(z.string(), lookupIndexEntrySchema),
|
|
1433
|
+
lifecycle: z.object({
|
|
1434
|
+
values: z.literal("activeAndInactive"),
|
|
1435
|
+
relations: z.literal("activeAndInactive")
|
|
1436
|
+
}).optional(),
|
|
1433
1437
|
revision: z.string().min(1),
|
|
1434
1438
|
schemaVersion: z.number().int().positive()
|
|
1435
1439
|
});
|
|
@@ -1586,15 +1590,230 @@ var ProjectionPathBuilder = class {
|
|
|
1586
1590
|
}
|
|
1587
1591
|
};
|
|
1588
1592
|
|
|
1593
|
+
// ../../libs/metadata-projection/src/lib/lifecycle/metadataLifecycle.ts
|
|
1594
|
+
var METADATA_STATUS = {
|
|
1595
|
+
ACTIVE: "ACTIVE",
|
|
1596
|
+
INACTIVE: "INACTIVE"
|
|
1597
|
+
};
|
|
1598
|
+
var METADATA_STATUS_FILTER = {
|
|
1599
|
+
ACTIVE: "ACTIVE",
|
|
1600
|
+
INACTIVE: "INACTIVE",
|
|
1601
|
+
ALL: "ALL"
|
|
1602
|
+
};
|
|
1603
|
+
var PROJECTION_LIFECYCLE_COVERAGE = "activeAndInactive";
|
|
1604
|
+
var METADATA_LIFECYCLE_UNSUPPORTED = "METADATA_LIFECYCLE_UNSUPPORTED";
|
|
1605
|
+
var ACTIVE_TOKENS = /* @__PURE__ */ new Set(["ACTIVE", "active"]);
|
|
1606
|
+
var INACTIVE_TOKENS = /* @__PURE__ */ new Set(["INACTIVE", "inactive"]);
|
|
1607
|
+
var ALL_TOKENS = /* @__PURE__ */ new Set(["ALL", "all"]);
|
|
1608
|
+
function canonicalMetadataStatus(status) {
|
|
1609
|
+
const token = status?.trim() ?? "";
|
|
1610
|
+
if (ACTIVE_TOKENS.has(token)) {
|
|
1611
|
+
return METADATA_STATUS.ACTIVE;
|
|
1612
|
+
}
|
|
1613
|
+
if (INACTIVE_TOKENS.has(token)) {
|
|
1614
|
+
return METADATA_STATUS.INACTIVE;
|
|
1615
|
+
}
|
|
1616
|
+
return void 0;
|
|
1617
|
+
}
|
|
1618
|
+
function statusMatchesFilter(status, filter = METADATA_STATUS_FILTER.ACTIVE) {
|
|
1619
|
+
const canonical = canonicalMetadataStatus(status);
|
|
1620
|
+
if (!canonical) {
|
|
1621
|
+
return false;
|
|
1622
|
+
}
|
|
1623
|
+
if (filter === METADATA_STATUS_FILTER.ALL) {
|
|
1624
|
+
return true;
|
|
1625
|
+
}
|
|
1626
|
+
return canonical === filter;
|
|
1627
|
+
}
|
|
1628
|
+
function resolveMetadataStatusFilter(input) {
|
|
1629
|
+
const explicit = normalizeExplicitStatus(input.status);
|
|
1630
|
+
if (explicit && !explicit.ok) {
|
|
1631
|
+
return explicit;
|
|
1632
|
+
}
|
|
1633
|
+
if (input.includeInactive === true) {
|
|
1634
|
+
if (explicit?.ok && explicit.filter !== METADATA_STATUS_FILTER.ALL) {
|
|
1635
|
+
return {
|
|
1636
|
+
ok: false,
|
|
1637
|
+
code: "METADATA_DISCOVERY_INVALID",
|
|
1638
|
+
message: "includeInactive cannot be combined with a different status filter"
|
|
1639
|
+
};
|
|
1640
|
+
}
|
|
1641
|
+
return {
|
|
1642
|
+
ok: true,
|
|
1643
|
+
filter: METADATA_STATUS_FILTER.ALL,
|
|
1644
|
+
enforceCapability: explicit?.ok === true
|
|
1645
|
+
};
|
|
1646
|
+
}
|
|
1647
|
+
if (explicit?.ok) {
|
|
1648
|
+
return explicit;
|
|
1649
|
+
}
|
|
1650
|
+
return {
|
|
1651
|
+
ok: true,
|
|
1652
|
+
filter: METADATA_STATUS_FILTER.ACTIVE,
|
|
1653
|
+
enforceCapability: false
|
|
1654
|
+
};
|
|
1655
|
+
}
|
|
1656
|
+
function projectionStatusLiterals(filter) {
|
|
1657
|
+
if (filter === METADATA_STATUS_FILTER.ALL) {
|
|
1658
|
+
return void 0;
|
|
1659
|
+
}
|
|
1660
|
+
if (filter === METADATA_STATUS_FILTER.INACTIVE) {
|
|
1661
|
+
return ["inactive", "INACTIVE"];
|
|
1662
|
+
}
|
|
1663
|
+
return ["active", "ACTIVE"];
|
|
1664
|
+
}
|
|
1665
|
+
function lifecycleQueryFailure(filter, supported) {
|
|
1666
|
+
if (filter === METADATA_STATUS_FILTER.ACTIVE || supported) {
|
|
1667
|
+
return void 0;
|
|
1668
|
+
}
|
|
1669
|
+
return {
|
|
1670
|
+
code: METADATA_LIFECYCLE_UNSUPPORTED,
|
|
1671
|
+
message: "This projection release does not publish inactive lifecycle records. An INACTIVE or ALL query cannot be answered from active-only artifacts."
|
|
1672
|
+
};
|
|
1673
|
+
}
|
|
1674
|
+
function inactiveValuesPublished(lifecycle) {
|
|
1675
|
+
return lifecycle?.values === PROJECTION_LIFECYCLE_COVERAGE;
|
|
1676
|
+
}
|
|
1677
|
+
function normalizeExplicitStatus(status) {
|
|
1678
|
+
if (status === void 0) {
|
|
1679
|
+
return void 0;
|
|
1680
|
+
}
|
|
1681
|
+
const raw = Array.isArray(status) ? [...status] : [status];
|
|
1682
|
+
const tokens = raw.map((value) => value.trim()).filter(Boolean);
|
|
1683
|
+
if (tokens.length === 0) {
|
|
1684
|
+
return {
|
|
1685
|
+
ok: false,
|
|
1686
|
+
code: "METADATA_DISCOVERY_INVALID",
|
|
1687
|
+
message: "status filter must contain at least one status"
|
|
1688
|
+
};
|
|
1689
|
+
}
|
|
1690
|
+
let sawActive = false;
|
|
1691
|
+
let sawInactive = false;
|
|
1692
|
+
let sawAll = false;
|
|
1693
|
+
for (const token of tokens) {
|
|
1694
|
+
if (ALL_TOKENS.has(token)) {
|
|
1695
|
+
sawAll = true;
|
|
1696
|
+
continue;
|
|
1697
|
+
}
|
|
1698
|
+
if (ACTIVE_TOKENS.has(token)) {
|
|
1699
|
+
sawActive = true;
|
|
1700
|
+
continue;
|
|
1701
|
+
}
|
|
1702
|
+
if (INACTIVE_TOKENS.has(token)) {
|
|
1703
|
+
sawInactive = true;
|
|
1704
|
+
continue;
|
|
1705
|
+
}
|
|
1706
|
+
return {
|
|
1707
|
+
ok: false,
|
|
1708
|
+
code: "METADATA_DISCOVERY_INVALID",
|
|
1709
|
+
message: `Unsupported metadata status ${token}`
|
|
1710
|
+
};
|
|
1711
|
+
}
|
|
1712
|
+
if (sawAll || sawActive && sawInactive) {
|
|
1713
|
+
return {
|
|
1714
|
+
ok: true,
|
|
1715
|
+
filter: METADATA_STATUS_FILTER.ALL,
|
|
1716
|
+
enforceCapability: true
|
|
1717
|
+
};
|
|
1718
|
+
}
|
|
1719
|
+
if (sawInactive) {
|
|
1720
|
+
return {
|
|
1721
|
+
ok: true,
|
|
1722
|
+
filter: METADATA_STATUS_FILTER.INACTIVE,
|
|
1723
|
+
enforceCapability: true
|
|
1724
|
+
};
|
|
1725
|
+
}
|
|
1726
|
+
return {
|
|
1727
|
+
ok: true,
|
|
1728
|
+
filter: METADATA_STATUS_FILTER.ACTIVE,
|
|
1729
|
+
enforceCapability: false
|
|
1730
|
+
};
|
|
1731
|
+
}
|
|
1732
|
+
|
|
1589
1733
|
// ../../libs/metadata-projection/src/lib/generators/relationship-index/TypedRelationshipCatalog.ts
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1734
|
+
var FIELD_SEPARATOR = "\0";
|
|
1735
|
+
var builtIndexes = /* @__PURE__ */ new WeakMap();
|
|
1736
|
+
function typedRelationEndpointKey(typeCode, valueCode) {
|
|
1737
|
+
return `${typeCode}${FIELD_SEPARATOR}${valueCode}`;
|
|
1738
|
+
}
|
|
1739
|
+
function isCompleteTypedRelation(relation) {
|
|
1740
|
+
return Boolean(
|
|
1741
|
+
relation && typeof relation.relationType === "string" && relation.relationType.trim() && typeof relation.status === "string" && relation.status.trim() && typeof relation.fromMetadataTypeCode === "string" && relation.fromMetadataTypeCode.trim() && typeof relation.fromMetadataValueCode === "string" && relation.fromMetadataValueCode.trim() && typeof relation.toMetadataTypeCode === "string" && relation.toMetadataTypeCode.trim() && typeof relation.toMetadataValueCode === "string" && relation.toMetadataValueCode.trim()
|
|
1742
|
+
);
|
|
1743
|
+
}
|
|
1744
|
+
function buildTypedRelationIndex(relations) {
|
|
1745
|
+
const outgoing = /* @__PURE__ */ new Map();
|
|
1746
|
+
const incoming = /* @__PURE__ */ new Map();
|
|
1747
|
+
const outgoingByStatus = emptyStatusBuckets();
|
|
1748
|
+
const incomingByStatus = emptyStatusBuckets();
|
|
1749
|
+
let complete = true;
|
|
1750
|
+
for (const relation of relations) {
|
|
1751
|
+
if (!isCompleteTypedRelation(relation)) {
|
|
1752
|
+
complete = false;
|
|
1753
|
+
continue;
|
|
1594
1754
|
}
|
|
1595
|
-
|
|
1596
|
-
|
|
1755
|
+
const fromKey = typedRelationEndpointKey(
|
|
1756
|
+
relation.fromMetadataTypeCode,
|
|
1757
|
+
relation.fromMetadataValueCode
|
|
1758
|
+
);
|
|
1759
|
+
const toKey = typedRelationEndpointKey(
|
|
1760
|
+
relation.toMetadataTypeCode,
|
|
1761
|
+
relation.toMetadataValueCode
|
|
1762
|
+
);
|
|
1763
|
+
appendBucket(outgoing, fromKey, relation);
|
|
1764
|
+
appendBucket(incoming, toKey, relation);
|
|
1765
|
+
const status = canonicalMetadataStatus(relation.status);
|
|
1766
|
+
if (!status) {
|
|
1767
|
+
continue;
|
|
1597
1768
|
}
|
|
1769
|
+
appendBucket(outgoingByStatus.get(status), fromKey, relation);
|
|
1770
|
+
appendBucket(incomingByStatus.get(status), toKey, relation);
|
|
1771
|
+
}
|
|
1772
|
+
return {
|
|
1773
|
+
complete,
|
|
1774
|
+
outgoing,
|
|
1775
|
+
incoming,
|
|
1776
|
+
outgoingByStatus,
|
|
1777
|
+
incomingByStatus
|
|
1778
|
+
};
|
|
1779
|
+
}
|
|
1780
|
+
function typedRelationsForEndpoint(index, direction, endpointKey, filter = METADATA_STATUS_FILTER.ACTIVE) {
|
|
1781
|
+
const byStatus = direction === "INCOMING" ? index.incomingByStatus : index.outgoingByStatus;
|
|
1782
|
+
if (filter === METADATA_STATUS_FILTER.ALL) {
|
|
1783
|
+
return [
|
|
1784
|
+
...byStatus.get(METADATA_STATUS.ACTIVE)?.get(endpointKey) ?? [],
|
|
1785
|
+
...byStatus.get(METADATA_STATUS.INACTIVE)?.get(endpointKey) ?? []
|
|
1786
|
+
];
|
|
1787
|
+
}
|
|
1788
|
+
return byStatus.get(filter)?.get(endpointKey) ?? [];
|
|
1789
|
+
}
|
|
1790
|
+
function typedRelationIndexFor(relations, index) {
|
|
1791
|
+
if (index) {
|
|
1792
|
+
return index;
|
|
1793
|
+
}
|
|
1794
|
+
const cached = builtIndexes.get(relations);
|
|
1795
|
+
if (cached) {
|
|
1796
|
+
return cached;
|
|
1797
|
+
}
|
|
1798
|
+
const built = buildTypedRelationIndex(relations);
|
|
1799
|
+
builtIndexes.set(relations, built);
|
|
1800
|
+
return built;
|
|
1801
|
+
}
|
|
1802
|
+
function filterTypedRelations(relations, query, index) {
|
|
1803
|
+
const resolved2 = typedRelationIndexFor(relations, index);
|
|
1804
|
+
const filter = query.status ?? METADATA_STATUS_FILTER.ACTIVE;
|
|
1805
|
+
if (!resolved2.complete) {
|
|
1806
|
+
return relations.filter(
|
|
1807
|
+
(relation) => matchesForward(relation, query) && statusMatchesRelation(relation, filter)
|
|
1808
|
+
);
|
|
1809
|
+
}
|
|
1810
|
+
const bucket = typedRelationsForEndpoint(
|
|
1811
|
+
resolved2,
|
|
1812
|
+
"OUTGOING",
|
|
1813
|
+
typedRelationEndpointKey(query.fromType, query.fromValue),
|
|
1814
|
+
filter
|
|
1815
|
+
);
|
|
1816
|
+
return bucket.filter((relation) => {
|
|
1598
1817
|
if (query.relationType && relation.relationType !== query.relationType) {
|
|
1599
1818
|
return false;
|
|
1600
1819
|
}
|
|
@@ -1604,6 +1823,38 @@ function filterTypedRelations(relations, query) {
|
|
|
1604
1823
|
return true;
|
|
1605
1824
|
});
|
|
1606
1825
|
}
|
|
1826
|
+
function matchesForward(relation, query) {
|
|
1827
|
+
if (relation.fromMetadataTypeCode !== query.fromType) {
|
|
1828
|
+
return false;
|
|
1829
|
+
}
|
|
1830
|
+
if (relation.fromMetadataValueCode !== query.fromValue) {
|
|
1831
|
+
return false;
|
|
1832
|
+
}
|
|
1833
|
+
if (query.relationType && relation.relationType !== query.relationType) {
|
|
1834
|
+
return false;
|
|
1835
|
+
}
|
|
1836
|
+
if (query.toType && relation.toMetadataTypeCode !== query.toType) {
|
|
1837
|
+
return false;
|
|
1838
|
+
}
|
|
1839
|
+
return true;
|
|
1840
|
+
}
|
|
1841
|
+
function statusMatchesRelation(relation, filter) {
|
|
1842
|
+
return canonicalMetadataStatus(relation.status) === void 0 ? false : filter === METADATA_STATUS_FILTER.ALL || canonicalMetadataStatus(relation.status) === filter;
|
|
1843
|
+
}
|
|
1844
|
+
function emptyStatusBuckets() {
|
|
1845
|
+
return /* @__PURE__ */ new Map([
|
|
1846
|
+
[METADATA_STATUS.ACTIVE, /* @__PURE__ */ new Map()],
|
|
1847
|
+
[METADATA_STATUS.INACTIVE, /* @__PURE__ */ new Map()]
|
|
1848
|
+
]);
|
|
1849
|
+
}
|
|
1850
|
+
function appendBucket(buckets, key, relation) {
|
|
1851
|
+
const existing = buckets.get(key);
|
|
1852
|
+
if (existing) {
|
|
1853
|
+
existing.push(relation);
|
|
1854
|
+
return;
|
|
1855
|
+
}
|
|
1856
|
+
buckets.set(key, [relation]);
|
|
1857
|
+
}
|
|
1607
1858
|
function parseTypedRelationshipFile(parsed, expected) {
|
|
1608
1859
|
const fileName = expected.fileName ?? "typed-relations.json";
|
|
1609
1860
|
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
@@ -1682,6 +1933,76 @@ var PUBLISHED_VALUE_LIST_CODE = {
|
|
|
1682
1933
|
INVALID: "METADATA_DISCOVERY_INVALID",
|
|
1683
1934
|
INCOMPLETE: "METADATA_TYPE_INCOMPLETE"
|
|
1684
1935
|
};
|
|
1936
|
+
function findPublishedEntry(file, valueCode, filter = METADATA_STATUS_FILTER.ACTIVE) {
|
|
1937
|
+
if (!file) {
|
|
1938
|
+
return void 0;
|
|
1939
|
+
}
|
|
1940
|
+
const fromRecords = latestEntry(file.records[valueCode]);
|
|
1941
|
+
const fromInactive = latestEntry(file.inactiveRecords?.[valueCode]);
|
|
1942
|
+
const active = entryWithStatus(fromRecords, METADATA_STATUS.ACTIVE);
|
|
1943
|
+
const inactive = entryWithStatus(fromInactive, METADATA_STATUS.INACTIVE) ?? entryWithStatus(fromRecords, METADATA_STATUS.INACTIVE);
|
|
1944
|
+
if (filter === METADATA_STATUS_FILTER.INACTIVE) {
|
|
1945
|
+
return inactive;
|
|
1946
|
+
}
|
|
1947
|
+
if (filter === METADATA_STATUS_FILTER.ALL) {
|
|
1948
|
+
return active ?? inactive;
|
|
1949
|
+
}
|
|
1950
|
+
return active;
|
|
1951
|
+
}
|
|
1952
|
+
function entriesForStatus(file, filter = METADATA_STATUS_FILTER.ACTIVE) {
|
|
1953
|
+
const entries = [];
|
|
1954
|
+
const seen = /* @__PURE__ */ new Set();
|
|
1955
|
+
if (filter !== METADATA_STATUS_FILTER.INACTIVE) {
|
|
1956
|
+
for (const [valueCode, record] of Object.entries(file.records)) {
|
|
1957
|
+
const entry = latestEntry(record);
|
|
1958
|
+
if (!entry || seen.has(valueCode)) {
|
|
1959
|
+
continue;
|
|
1960
|
+
}
|
|
1961
|
+
if (canonicalMetadataStatus(entry.status) !== METADATA_STATUS.ACTIVE) {
|
|
1962
|
+
continue;
|
|
1963
|
+
}
|
|
1964
|
+
seen.add(valueCode);
|
|
1965
|
+
entries.push(entry);
|
|
1966
|
+
}
|
|
1967
|
+
}
|
|
1968
|
+
if (filter !== METADATA_STATUS_FILTER.ACTIVE) {
|
|
1969
|
+
for (const [valueCode, record] of Object.entries(file.records)) {
|
|
1970
|
+
if (seen.has(valueCode)) {
|
|
1971
|
+
continue;
|
|
1972
|
+
}
|
|
1973
|
+
const entry = entryWithStatus(latestEntry(record), METADATA_STATUS.INACTIVE);
|
|
1974
|
+
if (!entry) {
|
|
1975
|
+
continue;
|
|
1976
|
+
}
|
|
1977
|
+
seen.add(valueCode);
|
|
1978
|
+
entries.push(entry);
|
|
1979
|
+
}
|
|
1980
|
+
for (const [valueCode, record] of Object.entries(file.inactiveRecords ?? {})) {
|
|
1981
|
+
if (seen.has(valueCode)) {
|
|
1982
|
+
continue;
|
|
1983
|
+
}
|
|
1984
|
+
const entry = entryWithStatus(latestEntry(record), METADATA_STATUS.INACTIVE);
|
|
1985
|
+
if (!entry) {
|
|
1986
|
+
continue;
|
|
1987
|
+
}
|
|
1988
|
+
seen.add(valueCode);
|
|
1989
|
+
entries.push(entry);
|
|
1990
|
+
}
|
|
1991
|
+
}
|
|
1992
|
+
return entries;
|
|
1993
|
+
}
|
|
1994
|
+
function latestEntry(record) {
|
|
1995
|
+
if (!record) {
|
|
1996
|
+
return void 0;
|
|
1997
|
+
}
|
|
1998
|
+
return record.versions[String(record.latestVersion)];
|
|
1999
|
+
}
|
|
2000
|
+
function entryWithStatus(entry, status) {
|
|
2001
|
+
if (!entry || canonicalMetadataStatus(entry.status) !== status) {
|
|
2002
|
+
return void 0;
|
|
2003
|
+
}
|
|
2004
|
+
return entry;
|
|
2005
|
+
}
|
|
1685
2006
|
function entriesFromProjectionFile(file) {
|
|
1686
2007
|
const entries = [];
|
|
1687
2008
|
const seen = /* @__PURE__ */ new Set();
|
|
@@ -1973,6 +2294,7 @@ var PUBLISHED_RELATION_DIRECTION = {
|
|
|
1973
2294
|
OUTGOING: "OUTGOING",
|
|
1974
2295
|
INCOMING: "INCOMING"
|
|
1975
2296
|
};
|
|
2297
|
+
var METADATA_RELATION_SEMANTICS_UNSUPPORTED = "METADATA_RELATION_SEMANTICS_UNSUPPORTED";
|
|
1976
2298
|
function queryPublishedRelationships(query) {
|
|
1977
2299
|
const sourceTypeCode = query.sourceTypeCode.trim();
|
|
1978
2300
|
const sourceValueCode = query.sourceValueCode.trim();
|
|
@@ -2000,23 +2322,30 @@ function queryPublishedRelationships(query) {
|
|
|
2000
2322
|
message: "relationship filters must be non-empty strings"
|
|
2001
2323
|
};
|
|
2002
2324
|
}
|
|
2003
|
-
|
|
2004
|
-
|
|
2325
|
+
const status = resolveRelationshipStatus(query.status);
|
|
2326
|
+
if (!status.ok) {
|
|
2327
|
+
return status;
|
|
2005
2328
|
}
|
|
2329
|
+
const index = typedRelationIndexFor(query.relations, query.index);
|
|
2330
|
+
if (!index.complete) {
|
|
2331
|
+
return {
|
|
2332
|
+
ok: false,
|
|
2333
|
+
code: "METADATA_TYPE_INCOMPLETE",
|
|
2334
|
+
message: "Typed relationship catalog contains a row that cannot be queried"
|
|
2335
|
+
};
|
|
2336
|
+
}
|
|
2337
|
+
const sourceKey = typedRelationEndpointKey(sourceTypeCode, sourceValueCode);
|
|
2338
|
+
const bucket = typedRelationsForEndpoint(index, direction, sourceKey, status.filter);
|
|
2006
2339
|
const seen = /* @__PURE__ */ new Set();
|
|
2007
2340
|
const relationships = [];
|
|
2008
|
-
for (const relation of
|
|
2009
|
-
if (!
|
|
2341
|
+
for (const relation of bucket) {
|
|
2342
|
+
if (!isCompleteTypedRelation(relation)) {
|
|
2010
2343
|
return {
|
|
2011
2344
|
ok: false,
|
|
2012
2345
|
code: "METADATA_TYPE_INCOMPLETE",
|
|
2013
2346
|
message: "Typed relationship catalog contains a row that cannot be queried"
|
|
2014
2347
|
};
|
|
2015
2348
|
}
|
|
2016
|
-
const matchesSource = direction === PUBLISHED_RELATION_DIRECTION.OUTGOING ? relation.fromMetadataTypeCode === sourceTypeCode && relation.fromMetadataValueCode === sourceValueCode : relation.toMetadataTypeCode === sourceTypeCode && relation.toMetadataValueCode === sourceValueCode;
|
|
2017
|
-
if (!matchesSource) {
|
|
2018
|
-
continue;
|
|
2019
|
-
}
|
|
2020
2349
|
if (relationType && relation.relationType !== relationType) {
|
|
2021
2350
|
continue;
|
|
2022
2351
|
}
|
|
@@ -2060,7 +2389,7 @@ function toView(relation, direction) {
|
|
|
2060
2389
|
}
|
|
2061
2390
|
function relationshipKey(relation) {
|
|
2062
2391
|
return [
|
|
2063
|
-
relation.relationType,
|
|
2392
|
+
relation.relationType ?? "",
|
|
2064
2393
|
relation.status,
|
|
2065
2394
|
relation.direction,
|
|
2066
2395
|
relation.fromMetadataTypeCode,
|
|
@@ -2072,10 +2401,15 @@ function relationshipKey(relation) {
|
|
|
2072
2401
|
relation.permissionActionCode ?? ""
|
|
2073
2402
|
].join("\0");
|
|
2074
2403
|
}
|
|
2075
|
-
function
|
|
2076
|
-
|
|
2077
|
-
|
|
2078
|
-
|
|
2404
|
+
function resolveRelationshipStatus(status) {
|
|
2405
|
+
const resolved2 = resolveMetadataStatusFilter({ status });
|
|
2406
|
+
if (!resolved2.ok) {
|
|
2407
|
+
return resolved2;
|
|
2408
|
+
}
|
|
2409
|
+
return { ok: true, filter: resolved2.filter };
|
|
2410
|
+
}
|
|
2411
|
+
function lifecycleUnsupported(message) {
|
|
2412
|
+
return { ok: false, code: METADATA_LIFECYCLE_UNSUPPORTED, message };
|
|
2079
2413
|
}
|
|
2080
2414
|
function optionalCode(value) {
|
|
2081
2415
|
if (value === void 0) {
|
|
@@ -2083,6 +2417,133 @@ function optionalCode(value) {
|
|
|
2083
2417
|
}
|
|
2084
2418
|
return value.trim();
|
|
2085
2419
|
}
|
|
2420
|
+
function resolvePublishedRelationshipQuery(input) {
|
|
2421
|
+
const validated = validateRelationshipQuery(input);
|
|
2422
|
+
if (validated) {
|
|
2423
|
+
return validated;
|
|
2424
|
+
}
|
|
2425
|
+
const relationType = optionalCode(input.relationType);
|
|
2426
|
+
if (relationType && !input.typedSupported) {
|
|
2427
|
+
return {
|
|
2428
|
+
ok: false,
|
|
2429
|
+
code: METADATA_RELATION_SEMANTICS_UNSUPPORTED,
|
|
2430
|
+
message: "Semantic relationship types are not stored in relationship-index.json"
|
|
2431
|
+
};
|
|
2432
|
+
}
|
|
2433
|
+
if (input.typedSupported) {
|
|
2434
|
+
return queryPublishedRelationships({
|
|
2435
|
+
relations: input.relations,
|
|
2436
|
+
index: input.index,
|
|
2437
|
+
sourceTypeCode: input.sourceTypeCode,
|
|
2438
|
+
sourceValueCode: input.sourceValueCode,
|
|
2439
|
+
targetTypeCode: input.targetTypeCode,
|
|
2440
|
+
relationType: input.relationType,
|
|
2441
|
+
direction: input.direction,
|
|
2442
|
+
status: input.status
|
|
2443
|
+
});
|
|
2444
|
+
}
|
|
2445
|
+
if (input.relationshipIndex) {
|
|
2446
|
+
const status2 = resolveRelationshipStatus(input.status);
|
|
2447
|
+
if (!status2.ok) {
|
|
2448
|
+
return status2;
|
|
2449
|
+
}
|
|
2450
|
+
if (status2.filter !== METADATA_STATUS_FILTER.ACTIVE) {
|
|
2451
|
+
return lifecycleUnsupported(
|
|
2452
|
+
"INACTIVE and ALL relationship queries require typed-relations.json"
|
|
2453
|
+
);
|
|
2454
|
+
}
|
|
2455
|
+
return queryRelationshipIndex({
|
|
2456
|
+
index: input.relationshipIndex,
|
|
2457
|
+
sourceTypeCode: input.sourceTypeCode,
|
|
2458
|
+
sourceValueCode: input.sourceValueCode,
|
|
2459
|
+
targetTypeCode: input.targetTypeCode,
|
|
2460
|
+
direction: input.direction
|
|
2461
|
+
});
|
|
2462
|
+
}
|
|
2463
|
+
const status = resolveRelationshipStatus(input.status);
|
|
2464
|
+
if (!status.ok) {
|
|
2465
|
+
return status;
|
|
2466
|
+
}
|
|
2467
|
+
if (status.filter !== METADATA_STATUS_FILTER.ACTIVE) {
|
|
2468
|
+
return lifecycleUnsupported(
|
|
2469
|
+
"INACTIVE and ALL relationship queries require typed-relations.json"
|
|
2470
|
+
);
|
|
2471
|
+
}
|
|
2472
|
+
return { ok: true, supported: false, relationships: [] };
|
|
2473
|
+
}
|
|
2474
|
+
function queryRelationshipIndex(input) {
|
|
2475
|
+
const validated = validateRelationshipQuery(input);
|
|
2476
|
+
if (validated) {
|
|
2477
|
+
return validated;
|
|
2478
|
+
}
|
|
2479
|
+
if (optionalCode(input.relationType)) {
|
|
2480
|
+
return {
|
|
2481
|
+
ok: false,
|
|
2482
|
+
code: METADATA_RELATION_SEMANTICS_UNSUPPORTED,
|
|
2483
|
+
message: "Semantic relationship types are not stored in relationship-index.json"
|
|
2484
|
+
};
|
|
2485
|
+
}
|
|
2486
|
+
const sourceTypeCode = input.sourceTypeCode.trim();
|
|
2487
|
+
const sourceValueCode = input.sourceValueCode.trim();
|
|
2488
|
+
const direction = input.direction ?? PUBLISHED_RELATION_DIRECTION.OUTGOING;
|
|
2489
|
+
const sourceKey = lookupIndexKey(sourceTypeCode, sourceValueCode);
|
|
2490
|
+
const byTargetType = input.index[sourceKey];
|
|
2491
|
+
const targetTypeCode = optionalCode(input.targetTypeCode);
|
|
2492
|
+
const targetTypes = !byTargetType ? [] : targetTypeCode ? byTargetType[targetTypeCode] ? [targetTypeCode] : [] : Object.keys(byTargetType).sort((left, right) => left.localeCompare(right));
|
|
2493
|
+
const relationships = [];
|
|
2494
|
+
for (const targetType of targetTypes) {
|
|
2495
|
+
for (const targetValue of byTargetType?.[targetType] ?? []) {
|
|
2496
|
+
relationships.push(
|
|
2497
|
+
direction === PUBLISHED_RELATION_DIRECTION.INCOMING ? {
|
|
2498
|
+
status: "active",
|
|
2499
|
+
direction,
|
|
2500
|
+
fromMetadataTypeCode: targetType,
|
|
2501
|
+
fromMetadataValueCode: targetValue,
|
|
2502
|
+
toMetadataTypeCode: sourceTypeCode,
|
|
2503
|
+
toMetadataValueCode: sourceValueCode
|
|
2504
|
+
} : {
|
|
2505
|
+
status: "active",
|
|
2506
|
+
direction: PUBLISHED_RELATION_DIRECTION.OUTGOING,
|
|
2507
|
+
fromMetadataTypeCode: sourceTypeCode,
|
|
2508
|
+
fromMetadataValueCode: sourceValueCode,
|
|
2509
|
+
toMetadataTypeCode: targetType,
|
|
2510
|
+
toMetadataValueCode: targetValue
|
|
2511
|
+
}
|
|
2512
|
+
);
|
|
2513
|
+
}
|
|
2514
|
+
}
|
|
2515
|
+
relationships.sort((left, right) => relationshipKey(left).localeCompare(relationshipKey(right)));
|
|
2516
|
+
return { ok: true, supported: true, relationships };
|
|
2517
|
+
}
|
|
2518
|
+
function validateRelationshipQuery(query) {
|
|
2519
|
+
const sourceTypeCode = query.sourceTypeCode.trim();
|
|
2520
|
+
const sourceValueCode = query.sourceValueCode.trim();
|
|
2521
|
+
if (!sourceTypeCode || !sourceValueCode) {
|
|
2522
|
+
return {
|
|
2523
|
+
ok: false,
|
|
2524
|
+
code: "METADATA_DISCOVERY_INVALID",
|
|
2525
|
+
message: "sourceTypeCode and sourceValueCode are required"
|
|
2526
|
+
};
|
|
2527
|
+
}
|
|
2528
|
+
const direction = query.direction ?? PUBLISHED_RELATION_DIRECTION.OUTGOING;
|
|
2529
|
+
if (direction !== PUBLISHED_RELATION_DIRECTION.OUTGOING && direction !== PUBLISHED_RELATION_DIRECTION.INCOMING) {
|
|
2530
|
+
return {
|
|
2531
|
+
ok: false,
|
|
2532
|
+
code: "METADATA_DISCOVERY_INVALID",
|
|
2533
|
+
message: "direction must be OUTGOING or INCOMING"
|
|
2534
|
+
};
|
|
2535
|
+
}
|
|
2536
|
+
const targetTypeCode = optionalCode(query.targetTypeCode);
|
|
2537
|
+
const relationType = optionalCode(query.relationType);
|
|
2538
|
+
if (targetTypeCode === "" || relationType === "") {
|
|
2539
|
+
return {
|
|
2540
|
+
ok: false,
|
|
2541
|
+
code: "METADATA_DISCOVERY_INVALID",
|
|
2542
|
+
message: "relationship filters must be non-empty strings"
|
|
2543
|
+
};
|
|
2544
|
+
}
|
|
2545
|
+
return void 0;
|
|
2546
|
+
}
|
|
2086
2547
|
var metadataPublishedPayloadSchema = z.object({
|
|
2087
2548
|
changeRequestId: z.string().min(1),
|
|
2088
2549
|
changeRevision: z.string().min(1).optional(),
|
|
@@ -2245,6 +2706,15 @@ var MetadataProjectionUnavailableError = class extends RuntimeMetadataError {
|
|
|
2245
2706
|
this.name = "MetadataProjectionUnavailableError";
|
|
2246
2707
|
}
|
|
2247
2708
|
};
|
|
2709
|
+
var MetadataExtensionContractError = class extends RuntimeMetadataError {
|
|
2710
|
+
constructor(message, path) {
|
|
2711
|
+
super(message, 404, "METADATA_EXTENSION_ROUTE_UNSUPPORTED", void 0, {
|
|
2712
|
+
retryable: false,
|
|
2713
|
+
metadata: path ? { path } : void 0
|
|
2714
|
+
});
|
|
2715
|
+
this.name = "MetadataExtensionContractError";
|
|
2716
|
+
}
|
|
2717
|
+
};
|
|
2248
2718
|
var MetadataDiscoveryError = class extends RuntimeMetadataError {
|
|
2249
2719
|
constructor(message, code = "METADATA_DISCOVERY_INVALID") {
|
|
2250
2720
|
super(message, code === "METADATA_TYPE_INCOMPLETE" ? 503 : 400, code, void 0, {
|
|
@@ -3508,6 +3978,9 @@ var MetadataCache = class {
|
|
|
3508
3978
|
getTypedRelations() {
|
|
3509
3979
|
return this.snapshot?.typedRelations;
|
|
3510
3980
|
}
|
|
3981
|
+
getTypedRelationIndex() {
|
|
3982
|
+
return this.snapshot?.typedRelationIndex;
|
|
3983
|
+
}
|
|
3511
3984
|
getLocalization(locale) {
|
|
3512
3985
|
return this.snapshot?.localization?.get(locale);
|
|
3513
3986
|
}
|
|
@@ -3538,6 +4011,7 @@ var MetadataCache = class {
|
|
|
3538
4011
|
this.generation += 1;
|
|
3539
4012
|
const domainFiles = new Map(bundle.domainFiles);
|
|
3540
4013
|
Object.freeze(domainFiles);
|
|
4014
|
+
const typedRelations = bundle.typedRelations ? Object.freeze([...bundle.typedRelations]) : void 0;
|
|
3541
4015
|
const snapshot = Object.freeze({
|
|
3542
4016
|
revision: bundle.releaseId,
|
|
3543
4017
|
releaseId: bundle.releaseId,
|
|
@@ -3550,7 +4024,8 @@ var MetadataCache = class {
|
|
|
3550
4024
|
domainFiles,
|
|
3551
4025
|
common: bundle.common ? Object.freeze({ ...bundle.common }) : void 0,
|
|
3552
4026
|
relationshipIndex: bundle.relationshipIndex ? Object.freeze({ ...bundle.relationshipIndex }) : void 0,
|
|
3553
|
-
typedRelations
|
|
4027
|
+
typedRelations,
|
|
4028
|
+
typedRelationIndex: typedRelations ? buildTypedRelationIndex(typedRelations) : void 0,
|
|
3554
4029
|
manifest: Object.freeze({
|
|
3555
4030
|
...bundle.manifest,
|
|
3556
4031
|
files: Object.freeze(
|
|
@@ -3898,7 +4373,7 @@ var MetadataResolver = class {
|
|
|
3898
4373
|
const latest = [];
|
|
3899
4374
|
for (const record of Object.values(file.records)) {
|
|
3900
4375
|
const entry = record.versions[String(record.latestVersion)];
|
|
3901
|
-
if (entry) {
|
|
4376
|
+
if (entry && canonicalMetadataStatus(entry.status) === METADATA_STATUS.ACTIVE) {
|
|
3902
4377
|
latest.push(entry);
|
|
3903
4378
|
}
|
|
3904
4379
|
}
|
|
@@ -3969,7 +4444,11 @@ var MetadataResolver = class {
|
|
|
3969
4444
|
return void 0;
|
|
3970
4445
|
}
|
|
3971
4446
|
const targetVersion = version !== void 0 ? version : record.latestVersion;
|
|
3972
|
-
|
|
4447
|
+
const entry = record.versions[String(targetVersion)];
|
|
4448
|
+
if (!entry || canonicalMetadataStatus(entry.status) !== METADATA_STATUS.ACTIVE) {
|
|
4449
|
+
return void 0;
|
|
4450
|
+
}
|
|
4451
|
+
return entry;
|
|
3973
4452
|
}
|
|
3974
4453
|
requireManifest() {
|
|
3975
4454
|
const manifest = this.cache.getManifest();
|
|
@@ -4314,6 +4793,7 @@ var ExtensionMetadataProvider = class {
|
|
|
4314
4793
|
readyTimeoutMs;
|
|
4315
4794
|
requestTimeoutMs;
|
|
4316
4795
|
logger;
|
|
4796
|
+
lifecycleSupport;
|
|
4317
4797
|
fetchImpl;
|
|
4318
4798
|
constructor(options) {
|
|
4319
4799
|
this.baseUrl = options.baseUrl.replace(/\/+$/, "");
|
|
@@ -4356,27 +4836,35 @@ var ExtensionMetadataProvider = class {
|
|
|
4356
4836
|
break;
|
|
4357
4837
|
}
|
|
4358
4838
|
} catch (err) {
|
|
4359
|
-
|
|
4360
|
-
|
|
4361
|
-
break;
|
|
4839
|
+
if (err instanceof MetadataExtensionContractError) {
|
|
4840
|
+
throw err;
|
|
4362
4841
|
}
|
|
4842
|
+
lastError = err;
|
|
4363
4843
|
}
|
|
4364
4844
|
await sleep(50);
|
|
4365
4845
|
}
|
|
4366
4846
|
const detail = lastError instanceof Error ? lastError.message : lastError ? String(lastError) : "";
|
|
4847
|
+
const unreachable = lastError instanceof MetadataProjectionUnavailableError && lastError.metadata?.unreachable === true;
|
|
4848
|
+
const timedOut = detail.includes("timed out");
|
|
4849
|
+
const reason = timedOut ? "Metadata extension readiness timed out" : unreachable ? "Metadata extension connection was refused" : "Metadata extension did not become ready";
|
|
4367
4850
|
this.logger.warn({
|
|
4368
4851
|
event: "templates.performance",
|
|
4369
4852
|
phase: "metadataExtension.ready",
|
|
4370
4853
|
durationMs: Date.now() - started,
|
|
4371
4854
|
attempts,
|
|
4372
|
-
outcome: "unavailable"
|
|
4855
|
+
outcome: "unavailable",
|
|
4856
|
+
unreachable,
|
|
4857
|
+
timedOut
|
|
4373
4858
|
});
|
|
4374
4859
|
throw new MetadataProjectionUnavailableError(
|
|
4375
|
-
detail ?
|
|
4860
|
+
detail ? `${reason}: ${detail}` : reason,
|
|
4376
4861
|
{
|
|
4377
4862
|
retryable: true,
|
|
4378
4863
|
metadata: {
|
|
4379
|
-
lastError: detail
|
|
4864
|
+
lastError: detail,
|
|
4865
|
+
unreachable,
|
|
4866
|
+
timedOut,
|
|
4867
|
+
attempts
|
|
4380
4868
|
}
|
|
4381
4869
|
}
|
|
4382
4870
|
);
|
|
@@ -4394,15 +4882,29 @@ var ExtensionMetadataProvider = class {
|
|
|
4394
4882
|
lastRefreshAttemptAt: body.lastRefreshAttemptAt ?? null,
|
|
4395
4883
|
lastSuccessfulRefreshAt: body.lastSuccessfulRefreshAt ?? null,
|
|
4396
4884
|
cacheAgeMs: typeof body.cacheAgeMs === "number" ? body.cacheAgeMs : null,
|
|
4397
|
-
metadataTypes: body.metadataTypes
|
|
4885
|
+
metadataTypes: body.metadataTypes,
|
|
4886
|
+
lifecycle: body.lifecycle ? {
|
|
4887
|
+
values: body.lifecycle.values === true,
|
|
4888
|
+
relations: body.lifecycle.relations === true
|
|
4889
|
+
} : void 0
|
|
4398
4890
|
};
|
|
4399
4891
|
}
|
|
4400
4892
|
async getValue(typeCode, valueCode, options) {
|
|
4401
|
-
const
|
|
4402
|
-
const path = `/v1/metadata/${encodeURIComponent(typeCode)}/${encodeURIComponent(valueCode)}${
|
|
4893
|
+
const filter = await this.assertQueryLifecycle("values", options);
|
|
4894
|
+
const path = `/v1/metadata/${encodeURIComponent(typeCode)}/${encodeURIComponent(valueCode)}${metadataQuery(options)}`;
|
|
4403
4895
|
try {
|
|
4404
4896
|
const item = await this.requestJson("GET", path);
|
|
4405
|
-
|
|
4897
|
+
const value = this.toMetadataValue(item, options?.locale);
|
|
4898
|
+
if (value && filter === METADATA_STATUS_FILTER.INACTIVE && !statusMatchesFilter(value.status, METADATA_STATUS_FILTER.INACTIVE)) {
|
|
4899
|
+
throw new MetadataDiscoveryError(
|
|
4900
|
+
"Extension returned a value outside the requested lifecycle filter",
|
|
4901
|
+
METADATA_LIFECYCLE_UNSUPPORTED
|
|
4902
|
+
);
|
|
4903
|
+
}
|
|
4904
|
+
if (value && filter === METADATA_STATUS_FILTER.ACTIVE && !statusMatchesFilter(value.status, "ACTIVE")) {
|
|
4905
|
+
return null;
|
|
4906
|
+
}
|
|
4907
|
+
return value;
|
|
4406
4908
|
} catch (err) {
|
|
4407
4909
|
if (isNotFound(err)) {
|
|
4408
4910
|
return null;
|
|
@@ -4476,18 +4978,28 @@ var ExtensionMetadataProvider = class {
|
|
|
4476
4978
|
* GET /v1/metadata/{typeCode}. Unknown types are a projection miss (`null`).
|
|
4477
4979
|
*/
|
|
4478
4980
|
async listTypeValues(typeCode, options) {
|
|
4981
|
+
const filter = await this.assertQueryLifecycle("values", options);
|
|
4479
4982
|
const params = new URLSearchParams();
|
|
4480
4983
|
if (options?.locale) {
|
|
4481
4984
|
params.set("locale", options.locale);
|
|
4482
4985
|
}
|
|
4483
|
-
if (options?.
|
|
4986
|
+
if (options?.status) {
|
|
4987
|
+
params.set("status", options.status);
|
|
4988
|
+
} else if (options?.includeInactive) {
|
|
4484
4989
|
params.set("includeInactive", "true");
|
|
4485
4990
|
}
|
|
4486
4991
|
const query = params.toString();
|
|
4487
4992
|
const path = `/v1/metadata/${encodeURIComponent(typeCode)}${query ? `?${query}` : ""}`;
|
|
4488
4993
|
try {
|
|
4489
4994
|
const body = await this.requestJson("GET", path);
|
|
4490
|
-
const
|
|
4995
|
+
const mapped = Object.values(body.items ?? {}).map((item) => this.toMetadataValue(item, options?.locale)).filter((item) => item != null);
|
|
4996
|
+
if (filter === METADATA_STATUS_FILTER.INACTIVE && mapped.some((item) => !statusMatchesFilter(item.status, filter))) {
|
|
4997
|
+
throw new MetadataDiscoveryError(
|
|
4998
|
+
"Extension returned values outside the requested lifecycle filter",
|
|
4999
|
+
METADATA_LIFECYCLE_UNSUPPORTED
|
|
5000
|
+
);
|
|
5001
|
+
}
|
|
5002
|
+
const values = filter === METADATA_STATUS_FILTER.ACTIVE ? mapped.filter((item) => statusMatchesFilter(item.status, filter)) : mapped;
|
|
4491
5003
|
return {
|
|
4492
5004
|
releaseId: body.releaseId ?? null,
|
|
4493
5005
|
values,
|
|
@@ -4502,15 +5014,18 @@ var ExtensionMetadataProvider = class {
|
|
|
4502
5014
|
}
|
|
4503
5015
|
async listValuesByType(typeCode, options) {
|
|
4504
5016
|
await this.assertDiscoveryPolicy(options?.readPolicy);
|
|
5017
|
+
const filter = await this.assertQueryLifecycle("values", { status: options?.status });
|
|
4505
5018
|
const body = await this.requestJson("GET", `/v1/metadata/types/${encodeURIComponent(typeCode)}/values${discoveryQuery(options)}`);
|
|
5019
|
+
const items = Array.isArray(body.items) ? body.items : [];
|
|
4506
5020
|
return {
|
|
4507
5021
|
releaseId: body.releaseId ?? null,
|
|
4508
|
-
items:
|
|
5022
|
+
items: listedValueItems(items, filter),
|
|
4509
5023
|
...body.nextCursor ? { nextCursor: body.nextCursor } : {}
|
|
4510
5024
|
};
|
|
4511
5025
|
}
|
|
4512
5026
|
async listValuesByTypes(typeCodes, options) {
|
|
4513
5027
|
await this.assertDiscoveryPolicy(options?.readPolicy);
|
|
5028
|
+
const filter = await this.assertQueryLifecycle("values", { status: options?.status });
|
|
4514
5029
|
const body = await this.requestJson(
|
|
4515
5030
|
"POST",
|
|
4516
5031
|
"/v1/metadata/types/values",
|
|
@@ -4521,11 +5036,15 @@ var ExtensionMetadataProvider = class {
|
|
|
4521
5036
|
);
|
|
4522
5037
|
return {
|
|
4523
5038
|
releaseId: body.releaseId ?? null,
|
|
4524
|
-
types: Array.isArray(body.types) ? body.types : []
|
|
5039
|
+
types: (Array.isArray(body.types) ? body.types : []).map((type) => ({
|
|
5040
|
+
...type,
|
|
5041
|
+
items: listedValueItems(type.items ?? [], filter)
|
|
5042
|
+
}))
|
|
4525
5043
|
};
|
|
4526
5044
|
}
|
|
4527
5045
|
async getRelationships(query) {
|
|
4528
5046
|
await this.assertDiscoveryPolicy(query.readPolicy);
|
|
5047
|
+
const filter = await this.assertQueryLifecycle("relations", { status: query.status });
|
|
4529
5048
|
const body = await this.requestJson(
|
|
4530
5049
|
"POST",
|
|
4531
5050
|
"/v1/metadata/relationships/query",
|
|
@@ -4534,7 +5053,10 @@ var ExtensionMetadataProvider = class {
|
|
|
4534
5053
|
return {
|
|
4535
5054
|
releaseId: body.releaseId ?? null,
|
|
4536
5055
|
supported: body.supported === true,
|
|
4537
|
-
relationships:
|
|
5056
|
+
relationships: lifecycleRows(
|
|
5057
|
+
Array.isArray(body.relationships) ? body.relationships : [],
|
|
5058
|
+
filter
|
|
5059
|
+
)
|
|
4538
5060
|
};
|
|
4539
5061
|
}
|
|
4540
5062
|
async listRelations(query) {
|
|
@@ -4547,12 +5069,19 @@ var ExtensionMetadataProvider = class {
|
|
|
4547
5069
|
if (query.toType) {
|
|
4548
5070
|
params.set("toType", query.toType);
|
|
4549
5071
|
}
|
|
5072
|
+
const filter = await this.assertQueryLifecycle("relations", { status: query.status });
|
|
5073
|
+
if (query.status) {
|
|
5074
|
+
params.set("status", query.status);
|
|
5075
|
+
}
|
|
4550
5076
|
try {
|
|
4551
5077
|
const body = await this.requestJson("GET", `/v1/relations?${params.toString()}`);
|
|
4552
5078
|
return {
|
|
4553
5079
|
releaseId: body.releaseId ?? null,
|
|
4554
5080
|
supported: body.supported === true,
|
|
4555
|
-
relations:
|
|
5081
|
+
relations: lifecycleRows(
|
|
5082
|
+
Array.isArray(body.relations) ? body.relations : [],
|
|
5083
|
+
filter
|
|
5084
|
+
)
|
|
4556
5085
|
};
|
|
4557
5086
|
} catch (err) {
|
|
4558
5087
|
if (isNotFound(err)) {
|
|
@@ -4562,8 +5091,8 @@ var ExtensionMetadataProvider = class {
|
|
|
4562
5091
|
}
|
|
4563
5092
|
}
|
|
4564
5093
|
async getRelatedValues(sourceTypeCode, sourceValueCode, targetTypeCode, options) {
|
|
4565
|
-
|
|
4566
|
-
const path = `/v1/related/${encodeURIComponent(sourceTypeCode)}/${encodeURIComponent(sourceValueCode)}/${encodeURIComponent(targetTypeCode)}${
|
|
5094
|
+
await this.assertQueryLifecycle("values", options);
|
|
5095
|
+
const path = `/v1/related/${encodeURIComponent(sourceTypeCode)}/${encodeURIComponent(sourceValueCode)}/${encodeURIComponent(targetTypeCode)}${metadataQuery(options)}`;
|
|
4567
5096
|
try {
|
|
4568
5097
|
const body = await this.requestJson(
|
|
4569
5098
|
"GET",
|
|
@@ -4581,6 +5110,7 @@ var ExtensionMetadataProvider = class {
|
|
|
4581
5110
|
if (sourceValueCodes.length === 0) {
|
|
4582
5111
|
return [];
|
|
4583
5112
|
}
|
|
5113
|
+
await this.assertQueryLifecycle("values", options);
|
|
4584
5114
|
const groups = [];
|
|
4585
5115
|
try {
|
|
4586
5116
|
for (let offset = 0; offset < sourceValueCodes.length; offset += RELATED_BATCH_LIMIT) {
|
|
@@ -4589,7 +5119,8 @@ var ExtensionMetadataProvider = class {
|
|
|
4589
5119
|
sourceType: sourceTypeCode,
|
|
4590
5120
|
sourceValues,
|
|
4591
5121
|
targetType: targetTypeCode,
|
|
4592
|
-
...options?.locale ? { locale: options.locale } : {}
|
|
5122
|
+
...options?.locale ? { locale: options.locale } : {},
|
|
5123
|
+
...options?.status ? { status: options.status } : {}
|
|
4593
5124
|
});
|
|
4594
5125
|
for (const group of body.groups ?? []) {
|
|
4595
5126
|
groups.push({
|
|
@@ -4640,6 +5171,7 @@ var ExtensionMetadataProvider = class {
|
|
|
4640
5171
|
}
|
|
4641
5172
|
}
|
|
4642
5173
|
async requestRefresh(releaseId) {
|
|
5174
|
+
this.lifecycleSupport = void 0;
|
|
4643
5175
|
const body = await this.requestJson(
|
|
4644
5176
|
"POST",
|
|
4645
5177
|
"/v1/refresh",
|
|
@@ -4647,6 +5179,32 @@ var ExtensionMetadataProvider = class {
|
|
|
4647
5179
|
);
|
|
4648
5180
|
return body.changed === true;
|
|
4649
5181
|
}
|
|
5182
|
+
async assertQueryLifecycle(kind, options) {
|
|
5183
|
+
const resolved2 = resolveMetadataStatusFilter({
|
|
5184
|
+
status: options?.status,
|
|
5185
|
+
includeInactive: options?.includeInactive
|
|
5186
|
+
});
|
|
5187
|
+
if (!resolved2.ok) {
|
|
5188
|
+
throw new MetadataDiscoveryError(resolved2.message, resolved2.code);
|
|
5189
|
+
}
|
|
5190
|
+
if (!resolved2.enforceCapability) {
|
|
5191
|
+
return resolved2.filter;
|
|
5192
|
+
}
|
|
5193
|
+
if (!this.lifecycleSupport) {
|
|
5194
|
+
const status = await this.getStatus();
|
|
5195
|
+
this.lifecycleSupport = {
|
|
5196
|
+
values: status.lifecycle?.values === true,
|
|
5197
|
+
relations: status.lifecycle?.relations === true
|
|
5198
|
+
};
|
|
5199
|
+
}
|
|
5200
|
+
if (!this.lifecycleSupport[kind]) {
|
|
5201
|
+
throw new MetadataDiscoveryError(
|
|
5202
|
+
"This projection release does not publish inactive lifecycle records. An INACTIVE or ALL query cannot be answered from active-only artifacts.",
|
|
5203
|
+
METADATA_LIFECYCLE_UNSUPPORTED
|
|
5204
|
+
);
|
|
5205
|
+
}
|
|
5206
|
+
return resolved2.filter;
|
|
5207
|
+
}
|
|
4650
5208
|
toMetadataValue(item, locale) {
|
|
4651
5209
|
if (!item?.typeCode || !item.valueCode) {
|
|
4652
5210
|
return null;
|
|
@@ -4734,12 +5292,18 @@ var ExtensionMetadataProvider = class {
|
|
|
4734
5292
|
errorBody.actualReleaseId ?? errorBody.releaseId ?? null
|
|
4735
5293
|
);
|
|
4736
5294
|
}
|
|
4737
|
-
if (code === "METADATA_DISCOVERY_INVALID" || code === "METADATA_TYPE_INCOMPLETE") {
|
|
5295
|
+
if (code === "METADATA_DISCOVERY_INVALID" || code === "METADATA_TYPE_INCOMPLETE" || code === "METADATA_RELATION_SEMANTICS_UNSUPPORTED" || code === METADATA_LIFECYCLE_UNSUPPORTED) {
|
|
4738
5296
|
throw new MetadataDiscoveryError(
|
|
4739
5297
|
errorBody.message ?? "Metadata discovery request was rejected",
|
|
4740
5298
|
code
|
|
4741
5299
|
);
|
|
4742
5300
|
}
|
|
5301
|
+
if (isUnsupportedExtensionRoute(response.status, errorBody)) {
|
|
5302
|
+
throw new MetadataExtensionContractError(
|
|
5303
|
+
errorBody.message ?? "Unknown extension route",
|
|
5304
|
+
path
|
|
5305
|
+
);
|
|
5306
|
+
}
|
|
4743
5307
|
if (response.status === 404) {
|
|
4744
5308
|
const err = new Error(errorBody.message ?? "not found");
|
|
4745
5309
|
err.code = "RUNTIME_METADATA_NOT_FOUND";
|
|
@@ -4758,7 +5322,7 @@ var ExtensionMetadataProvider = class {
|
|
|
4758
5322
|
}
|
|
4759
5323
|
return parsed;
|
|
4760
5324
|
} catch (err) {
|
|
4761
|
-
if (err instanceof MetadataProjectionUnavailableError || err instanceof UnknownMetadataTypeError || err instanceof MetadataFreshnessError || err instanceof MetadataReleaseMismatchError || err instanceof MetadataDiscoveryError) {
|
|
5325
|
+
if (err instanceof MetadataProjectionUnavailableError || err instanceof UnknownMetadataTypeError || err instanceof MetadataFreshnessError || err instanceof MetadataReleaseMismatchError || err instanceof MetadataDiscoveryError || err instanceof MetadataExtensionContractError) {
|
|
4762
5326
|
throw err;
|
|
4763
5327
|
}
|
|
4764
5328
|
if (err.code === "RUNTIME_METADATA_NOT_FOUND") {
|
|
@@ -4804,6 +5368,9 @@ function parseTypeCatalog(raw, fallbackTypeCode) {
|
|
|
4804
5368
|
...typeof raw.isGlobal === "boolean" ? { isGlobal: raw.isGlobal } : {}
|
|
4805
5369
|
};
|
|
4806
5370
|
}
|
|
5371
|
+
function isUnsupportedExtensionRoute(status, body) {
|
|
5372
|
+
return status === 404 && (body.code === "METADATA_EXTENSION_ROUTE_UNSUPPORTED" || body.message === "Unknown extension route");
|
|
5373
|
+
}
|
|
4807
5374
|
function isNotFound(err) {
|
|
4808
5375
|
return err.code === "RUNTIME_METADATA_NOT_FOUND";
|
|
4809
5376
|
}
|
|
@@ -4880,6 +5447,49 @@ function appendDiscoveryParams(params, options) {
|
|
|
4880
5447
|
}
|
|
4881
5448
|
}
|
|
4882
5449
|
}
|
|
5450
|
+
function metadataQuery(options) {
|
|
5451
|
+
const params = new URLSearchParams();
|
|
5452
|
+
if (options?.locale) {
|
|
5453
|
+
params.set("locale", options.locale);
|
|
5454
|
+
}
|
|
5455
|
+
if (options?.status) {
|
|
5456
|
+
params.set("status", options.status);
|
|
5457
|
+
} else if (options?.includeInactive) {
|
|
5458
|
+
params.set("includeInactive", "true");
|
|
5459
|
+
}
|
|
5460
|
+
const query = params.toString();
|
|
5461
|
+
return query ? `?${query}` : "";
|
|
5462
|
+
}
|
|
5463
|
+
function listedValueItems(items, filter) {
|
|
5464
|
+
if (filter === METADATA_STATUS_FILTER.ALL) {
|
|
5465
|
+
return [...items];
|
|
5466
|
+
}
|
|
5467
|
+
if (filter === METADATA_STATUS_FILTER.INACTIVE) {
|
|
5468
|
+
if (items.some((item) => !statusMatchesFilter(item.status, filter))) {
|
|
5469
|
+
throw new MetadataDiscoveryError(
|
|
5470
|
+
"Extension returned values outside the requested lifecycle filter",
|
|
5471
|
+
METADATA_LIFECYCLE_UNSUPPORTED
|
|
5472
|
+
);
|
|
5473
|
+
}
|
|
5474
|
+
return [...items];
|
|
5475
|
+
}
|
|
5476
|
+
return items.filter((item) => statusMatchesFilter(item.status, filter));
|
|
5477
|
+
}
|
|
5478
|
+
function lifecycleRows(rows, filter) {
|
|
5479
|
+
if (filter === METADATA_STATUS_FILTER.ALL) {
|
|
5480
|
+
return [...rows];
|
|
5481
|
+
}
|
|
5482
|
+
if (filter === METADATA_STATUS_FILTER.INACTIVE) {
|
|
5483
|
+
if (rows.some((row) => !statusMatchesFilter(row.status, filter))) {
|
|
5484
|
+
throw new MetadataDiscoveryError(
|
|
5485
|
+
"Extension returned relationships outside the requested lifecycle filter",
|
|
5486
|
+
METADATA_LIFECYCLE_UNSUPPORTED
|
|
5487
|
+
);
|
|
5488
|
+
}
|
|
5489
|
+
return [...rows];
|
|
5490
|
+
}
|
|
5491
|
+
return rows.filter((row) => statusMatchesFilter(row.status, filter));
|
|
5492
|
+
}
|
|
4883
5493
|
function sleep(ms) {
|
|
4884
5494
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
4885
5495
|
}
|
|
@@ -4896,10 +5506,11 @@ var METADATA_PROVIDER_KIND = {
|
|
|
4896
5506
|
function selectMetadataProvider(input) {
|
|
4897
5507
|
const env = input.env ?? process.env;
|
|
4898
5508
|
if (input.extensionProvider) {
|
|
5509
|
+
const fallbackEnabled = (env.METADATA_EXTENSION_FALLBACK ?? "s3") !== "none";
|
|
4899
5510
|
return {
|
|
4900
5511
|
kind: METADATA_PROVIDER_KIND.EXTENSION,
|
|
4901
5512
|
provider: input.extensionProvider,
|
|
4902
|
-
fallback: input.s3Provider
|
|
5513
|
+
fallback: fallbackEnabled ? input.s3Provider : void 0
|
|
4903
5514
|
};
|
|
4904
5515
|
}
|
|
4905
5516
|
const extensionEnabled = isExtensionEnabled(env);
|
|
@@ -5128,21 +5739,30 @@ var S3MetadataProvider = class {
|
|
|
5128
5739
|
};
|
|
5129
5740
|
}
|
|
5130
5741
|
async getValue(typeCode, valueCode, options) {
|
|
5742
|
+
const resolved2 = this.valueFilter(options);
|
|
5131
5743
|
await this.ensureTypesLoaded([typeCode]);
|
|
5132
|
-
|
|
5133
|
-
|
|
5134
|
-
|
|
5135
|
-
|
|
5136
|
-
|
|
5137
|
-
|
|
5138
|
-
|
|
5139
|
-
|
|
5140
|
-
|
|
5141
|
-
|
|
5142
|
-
|
|
5744
|
+
if (resolved2.filter === METADATA_STATUS_FILTER.ACTIVE) {
|
|
5745
|
+
try {
|
|
5746
|
+
const entry2 = this.resolver.resolve(typeCode, valueCode, options?.version);
|
|
5747
|
+
return projectionEntryToMetadataValue(
|
|
5748
|
+
typeCode,
|
|
5749
|
+
valueCode,
|
|
5750
|
+
entry2,
|
|
5751
|
+
options?.locale
|
|
5752
|
+
);
|
|
5753
|
+
} catch (err) {
|
|
5754
|
+
if (err instanceof MetadataLookupError) {
|
|
5755
|
+
return null;
|
|
5756
|
+
}
|
|
5757
|
+
throw err;
|
|
5143
5758
|
}
|
|
5144
|
-
throw err;
|
|
5145
5759
|
}
|
|
5760
|
+
const entry = findPublishedEntry(
|
|
5761
|
+
this.cache.getDomainFile(typeCode),
|
|
5762
|
+
valueCode,
|
|
5763
|
+
resolved2.filter
|
|
5764
|
+
);
|
|
5765
|
+
return entry ? projectionEntryToMetadataValue(typeCode, valueCode, entry, options?.locale) : null;
|
|
5146
5766
|
}
|
|
5147
5767
|
async batchGet(references, options) {
|
|
5148
5768
|
const invalidReferences = [];
|
|
@@ -5189,8 +5809,18 @@ var S3MetadataProvider = class {
|
|
|
5189
5809
|
};
|
|
5190
5810
|
}
|
|
5191
5811
|
async listRelations(query) {
|
|
5812
|
+
const resolved2 = resolveMetadataStatusFilter({ status: query.status });
|
|
5813
|
+
if (!resolved2.ok) {
|
|
5814
|
+
throw new MetadataDiscoveryError(resolved2.message, resolved2.code);
|
|
5815
|
+
}
|
|
5192
5816
|
const relations = this.cache.getTypedRelations();
|
|
5193
5817
|
if (!relations) {
|
|
5818
|
+
if (resolved2.filter !== METADATA_STATUS_FILTER.ACTIVE) {
|
|
5819
|
+
throw new MetadataDiscoveryError(
|
|
5820
|
+
"INACTIVE and ALL relationship queries require typed-relations.json",
|
|
5821
|
+
METADATA_LIFECYCLE_UNSUPPORTED
|
|
5822
|
+
);
|
|
5823
|
+
}
|
|
5194
5824
|
return {
|
|
5195
5825
|
releaseId: this.cache.getReleaseId(),
|
|
5196
5826
|
supported: false,
|
|
@@ -5200,7 +5830,10 @@ var S3MetadataProvider = class {
|
|
|
5200
5830
|
return {
|
|
5201
5831
|
releaseId: this.cache.getReleaseId(),
|
|
5202
5832
|
supported: true,
|
|
5203
|
-
relations: filterTypedRelations(relations,
|
|
5833
|
+
relations: filterTypedRelations(relations, {
|
|
5834
|
+
...query,
|
|
5835
|
+
status: resolved2.filter
|
|
5836
|
+
})
|
|
5204
5837
|
};
|
|
5205
5838
|
}
|
|
5206
5839
|
async getRelatedValues(sourceTypeCode, sourceValueCode, targetTypeCode, options) {
|
|
@@ -5224,7 +5857,18 @@ var S3MetadataProvider = class {
|
|
|
5224
5857
|
if (sourceValueCodes.length === 0) {
|
|
5225
5858
|
return [];
|
|
5226
5859
|
}
|
|
5860
|
+
const resolved2 = this.valueFilter(options);
|
|
5227
5861
|
await this.ensureTypesLoaded([sourceTypeCode, targetTypeCode]);
|
|
5862
|
+
if (resolved2.filter !== METADATA_STATUS_FILTER.ACTIVE) {
|
|
5863
|
+
return this.relatedGroupsForStatus(
|
|
5864
|
+
sourceTypeCode,
|
|
5865
|
+
sourceValueCodes,
|
|
5866
|
+
targetTypeCode,
|
|
5867
|
+
resolved2.filter,
|
|
5868
|
+
resolved2.enforceCapability,
|
|
5869
|
+
options
|
|
5870
|
+
);
|
|
5871
|
+
}
|
|
5228
5872
|
const index = this.cache.getRelationshipIndex();
|
|
5229
5873
|
const groups = [];
|
|
5230
5874
|
for (const sourceValueCode of sourceValueCodes) {
|
|
@@ -5268,24 +5912,10 @@ var S3MetadataProvider = class {
|
|
|
5268
5912
|
if (!file) {
|
|
5269
5913
|
return null;
|
|
5270
5914
|
}
|
|
5271
|
-
const
|
|
5915
|
+
const resolved2 = this.valueFilter(options);
|
|
5916
|
+
const values = entriesForStatus(file, resolved2.filter).map(
|
|
5272
5917
|
(entry) => projectionEntryToMetadataValue(typeCode, entry.code, entry, options?.locale)
|
|
5273
5918
|
);
|
|
5274
|
-
if (options?.includeInactive && file.inactiveRecords) {
|
|
5275
|
-
const seen = new Set(values.map((value) => value.valueCode));
|
|
5276
|
-
for (const [valueCode, record] of Object.entries(file.inactiveRecords)) {
|
|
5277
|
-
if (seen.has(valueCode)) {
|
|
5278
|
-
continue;
|
|
5279
|
-
}
|
|
5280
|
-
const entry = latestProjectionEntry(record);
|
|
5281
|
-
if (!entry) {
|
|
5282
|
-
continue;
|
|
5283
|
-
}
|
|
5284
|
-
values.push(
|
|
5285
|
-
projectionEntryToMetadataValue(typeCode, valueCode, entry, options.locale)
|
|
5286
|
-
);
|
|
5287
|
-
}
|
|
5288
|
-
}
|
|
5289
5919
|
return {
|
|
5290
5920
|
releaseId: this.cache.getReleaseId(),
|
|
5291
5921
|
values,
|
|
@@ -5343,14 +5973,22 @@ var S3MetadataProvider = class {
|
|
|
5343
5973
|
async getRelationships(query) {
|
|
5344
5974
|
const releaseId = await this.prepareDiscoveryRead(query.readPolicy, query.releaseId);
|
|
5345
5975
|
const relations = this.cache.getTypedRelations();
|
|
5346
|
-
const
|
|
5347
|
-
|
|
5976
|
+
const relationshipIndex = this.cache.getRelationshipIndex();
|
|
5977
|
+
const resolved2 = resolveMetadataStatusFilter({ status: query.status });
|
|
5978
|
+
if (!resolved2.ok) {
|
|
5979
|
+
throw new MetadataDiscoveryError(resolved2.message, resolved2.code);
|
|
5980
|
+
}
|
|
5981
|
+
const listed = resolvePublishedRelationshipQuery({
|
|
5982
|
+
typedSupported: relations !== void 0,
|
|
5348
5983
|
relations: relations ?? [],
|
|
5984
|
+
index: this.cache.getTypedRelationIndex(),
|
|
5985
|
+
relationshipIndex,
|
|
5349
5986
|
sourceTypeCode: query.sourceTypeCode,
|
|
5350
5987
|
sourceValueCode: query.sourceValueCode,
|
|
5351
5988
|
targetTypeCode: query.targetTypeCode,
|
|
5352
5989
|
relationType: query.relationType,
|
|
5353
|
-
direction: query.direction
|
|
5990
|
+
direction: query.direction,
|
|
5991
|
+
status: resolved2.filter
|
|
5354
5992
|
});
|
|
5355
5993
|
if (!listed.ok) {
|
|
5356
5994
|
throwPublishedListFailure(listed);
|
|
@@ -5394,13 +6032,26 @@ var S3MetadataProvider = class {
|
|
|
5394
6032
|
"METADATA_TYPE_INCOMPLETE"
|
|
5395
6033
|
);
|
|
5396
6034
|
}
|
|
6035
|
+
const resolved2 = resolveMetadataStatusFilter({ status: options?.status });
|
|
6036
|
+
if (!resolved2.ok) {
|
|
6037
|
+
throw new MetadataDiscoveryError(resolved2.message, resolved2.code);
|
|
6038
|
+
}
|
|
6039
|
+
if (resolved2.enforceCapability) {
|
|
6040
|
+
const blocked = lifecycleQueryFailure(
|
|
6041
|
+
resolved2.filter,
|
|
6042
|
+
inactiveValuesPublished(this.cache.getManifest()?.lifecycle)
|
|
6043
|
+
);
|
|
6044
|
+
if (blocked) {
|
|
6045
|
+
throw new MetadataDiscoveryError(blocked.message, blocked.code);
|
|
6046
|
+
}
|
|
6047
|
+
}
|
|
5397
6048
|
const extracted = entriesFromProjectionFile(file);
|
|
5398
6049
|
if (!extracted.ok) {
|
|
5399
6050
|
throwPublishedListFailure(extracted);
|
|
5400
6051
|
}
|
|
5401
6052
|
const listed = listPublishedValues(extracted.entries, {
|
|
5402
6053
|
releaseId,
|
|
5403
|
-
status:
|
|
6054
|
+
status: projectionStatusLiterals(resolved2.filter),
|
|
5404
6055
|
limit: options?.limit,
|
|
5405
6056
|
cursor: options?.cursor,
|
|
5406
6057
|
sortBy: options?.sortBy,
|
|
@@ -5429,6 +6080,109 @@ var S3MetadataProvider = class {
|
|
|
5429
6080
|
this.cache.getCommon()?.types.some((type) => type.metadataTypeCode === typeCode)
|
|
5430
6081
|
);
|
|
5431
6082
|
}
|
|
6083
|
+
valueFilter(options) {
|
|
6084
|
+
const resolved2 = resolveMetadataStatusFilter({
|
|
6085
|
+
status: options?.status,
|
|
6086
|
+
includeInactive: options?.includeInactive
|
|
6087
|
+
});
|
|
6088
|
+
if (!resolved2.ok) {
|
|
6089
|
+
throw new MetadataDiscoveryError(resolved2.message, resolved2.code);
|
|
6090
|
+
}
|
|
6091
|
+
if (resolved2.enforceCapability) {
|
|
6092
|
+
const blocked = lifecycleQueryFailure(
|
|
6093
|
+
resolved2.filter,
|
|
6094
|
+
inactiveValuesPublished(this.cache.getManifest()?.lifecycle)
|
|
6095
|
+
);
|
|
6096
|
+
if (blocked) {
|
|
6097
|
+
throw new MetadataDiscoveryError(blocked.message, blocked.code);
|
|
6098
|
+
}
|
|
6099
|
+
}
|
|
6100
|
+
return resolved2;
|
|
6101
|
+
}
|
|
6102
|
+
async relatedGroupsForStatus(sourceTypeCode, sourceValueCodes, targetTypeCode, filter, enforceCapability, options) {
|
|
6103
|
+
const relations = this.cache.getTypedRelations();
|
|
6104
|
+
if (!relations || !inactiveValuesPublished(this.cache.getManifest()?.lifecycle)) {
|
|
6105
|
+
if (enforceCapability) {
|
|
6106
|
+
throw new MetadataDiscoveryError(
|
|
6107
|
+
"INACTIVE and ALL related-value queries require a lifecycle-aware release",
|
|
6108
|
+
METADATA_LIFECYCLE_UNSUPPORTED
|
|
6109
|
+
);
|
|
6110
|
+
}
|
|
6111
|
+
return this.relatedGroupsFromAdjacency(
|
|
6112
|
+
sourceTypeCode,
|
|
6113
|
+
sourceValueCodes,
|
|
6114
|
+
targetTypeCode,
|
|
6115
|
+
options
|
|
6116
|
+
);
|
|
6117
|
+
}
|
|
6118
|
+
const groups = [];
|
|
6119
|
+
for (const sourceValueCode of sourceValueCodes) {
|
|
6120
|
+
const listed = resolvePublishedRelationshipQuery({
|
|
6121
|
+
typedSupported: true,
|
|
6122
|
+
relations,
|
|
6123
|
+
index: this.cache.getTypedRelationIndex(),
|
|
6124
|
+
sourceTypeCode,
|
|
6125
|
+
sourceValueCode,
|
|
6126
|
+
targetTypeCode,
|
|
6127
|
+
status: filter
|
|
6128
|
+
});
|
|
6129
|
+
if (!listed.ok) {
|
|
6130
|
+
throwPublishedListFailure(listed);
|
|
6131
|
+
}
|
|
6132
|
+
const values = [];
|
|
6133
|
+
const seen = /* @__PURE__ */ new Set();
|
|
6134
|
+
for (const row of listed.relationships) {
|
|
6135
|
+
if (seen.has(row.toMetadataValueCode)) {
|
|
6136
|
+
continue;
|
|
6137
|
+
}
|
|
6138
|
+
seen.add(row.toMetadataValueCode);
|
|
6139
|
+
const value = await this.getValue(targetTypeCode, row.toMetadataValueCode, {
|
|
6140
|
+
...options,
|
|
6141
|
+
status: filter,
|
|
6142
|
+
includeInactive: void 0
|
|
6143
|
+
});
|
|
6144
|
+
if (value) {
|
|
6145
|
+
values.push(value);
|
|
6146
|
+
}
|
|
6147
|
+
}
|
|
6148
|
+
groups.push({ sourceValueCode, values });
|
|
6149
|
+
}
|
|
6150
|
+
return groups;
|
|
6151
|
+
}
|
|
6152
|
+
async relatedGroupsFromAdjacency(sourceTypeCode, sourceValueCodes, targetTypeCode, options) {
|
|
6153
|
+
const index = this.cache.getRelationshipIndex();
|
|
6154
|
+
const groups = [];
|
|
6155
|
+
for (const sourceValueCode of sourceValueCodes) {
|
|
6156
|
+
const codes = relatedValueCodes(
|
|
6157
|
+
index,
|
|
6158
|
+
sourceTypeCode,
|
|
6159
|
+
sourceValueCode,
|
|
6160
|
+
targetTypeCode
|
|
6161
|
+
);
|
|
6162
|
+
if (codes.length === 0) {
|
|
6163
|
+
codes.push(
|
|
6164
|
+
...relatedValueCodesFromEntry(
|
|
6165
|
+
this.resolver,
|
|
6166
|
+
sourceTypeCode,
|
|
6167
|
+
sourceValueCode,
|
|
6168
|
+
targetTypeCode
|
|
6169
|
+
)
|
|
6170
|
+
);
|
|
6171
|
+
}
|
|
6172
|
+
const values = [];
|
|
6173
|
+
for (const valueCode of codes) {
|
|
6174
|
+
const value = await this.getValue(targetTypeCode, valueCode, {
|
|
6175
|
+
locale: options?.locale,
|
|
6176
|
+
status: METADATA_STATUS_FILTER.ACTIVE
|
|
6177
|
+
});
|
|
6178
|
+
if (value) {
|
|
6179
|
+
values.push(value);
|
|
6180
|
+
}
|
|
6181
|
+
}
|
|
6182
|
+
groups.push({ sourceValueCode, values });
|
|
6183
|
+
}
|
|
6184
|
+
return groups;
|
|
6185
|
+
}
|
|
5432
6186
|
};
|
|
5433
6187
|
function relatedValueCodes(index, sourceTypeCode, sourceValueCode, targetTypeCode) {
|
|
5434
6188
|
if (!index) {
|
|
@@ -5465,9 +6219,6 @@ function typeCatalogFromProjection(typeCode, file, common) {
|
|
|
5465
6219
|
status: ""
|
|
5466
6220
|
};
|
|
5467
6221
|
}
|
|
5468
|
-
function latestProjectionEntry(record) {
|
|
5469
|
-
return record.versions[String(record.latestVersion)];
|
|
5470
|
-
}
|
|
5471
6222
|
function relatedValueCodesFromEntry(resolver, sourceTypeCode, sourceValueCode, targetTypeCode) {
|
|
5472
6223
|
try {
|
|
5473
6224
|
const entry = resolver.resolve(sourceTypeCode, sourceValueCode);
|
|
@@ -5598,10 +6349,30 @@ var RuntimeMetadataService = class {
|
|
|
5598
6349
|
}
|
|
5599
6350
|
async initializeInternal(revision) {
|
|
5600
6351
|
if (this.usesExtensionTransport()) {
|
|
6352
|
+
this.logger.info({
|
|
6353
|
+
event: RUNTIME_METADATA_EVENTS.INIT_START,
|
|
6354
|
+
transport: "extension"
|
|
6355
|
+
});
|
|
5601
6356
|
const ready = await this.initializeFromExtension();
|
|
5602
6357
|
if (ready) {
|
|
6358
|
+
this.logger.info({
|
|
6359
|
+
event: RUNTIME_METADATA_EVENTS.INIT_COMPLETE,
|
|
6360
|
+
transport: "extension",
|
|
6361
|
+
releaseId: this.cache.getReleaseId()
|
|
6362
|
+
});
|
|
5603
6363
|
return;
|
|
5604
6364
|
}
|
|
6365
|
+
if (!this.metadataProviderFallback) {
|
|
6366
|
+
this.logger.warn({
|
|
6367
|
+
event: RUNTIME_METADATA_EVENTS.INIT_FAILED,
|
|
6368
|
+
transport: "extension",
|
|
6369
|
+
reason: "fallback-disabled"
|
|
6370
|
+
});
|
|
6371
|
+
throw new MetadataProjectionUnavailableError(
|
|
6372
|
+
"Metadata extension is unavailable and S3 fallback is disabled",
|
|
6373
|
+
{ retryable: true }
|
|
6374
|
+
);
|
|
6375
|
+
}
|
|
5605
6376
|
await this.providerCoordinator.activateFallback("extension-init");
|
|
5606
6377
|
}
|
|
5607
6378
|
await this.refreshService.initialize(revision ?? this.config.revision);
|
|
@@ -5621,6 +6392,9 @@ var RuntimeMetadataService = class {
|
|
|
5621
6392
|
const changed = await this.refreshViaExtension(releaseId);
|
|
5622
6393
|
return changed;
|
|
5623
6394
|
} catch (err) {
|
|
6395
|
+
if (!this.metadataProviderFallback || err instanceof MetadataExtensionContractError) {
|
|
6396
|
+
throw err;
|
|
6397
|
+
}
|
|
5624
6398
|
this.logger.warn({
|
|
5625
6399
|
event: RUNTIME_METADATA_EVENTS.PROVIDER_FALLBACK,
|
|
5626
6400
|
reason: "extension-refresh-failed",
|
|
@@ -5629,6 +6403,12 @@ var RuntimeMetadataService = class {
|
|
|
5629
6403
|
await this.providerCoordinator.activateFallback("extension-refresh");
|
|
5630
6404
|
}
|
|
5631
6405
|
}
|
|
6406
|
+
if (this.metadataProviderKind === METADATA_PROVIDER_KIND.EXTENSION && !this.metadataProviderFallback) {
|
|
6407
|
+
throw new MetadataProjectionUnavailableError(
|
|
6408
|
+
"Metadata extension is unavailable and S3 fallback is disabled",
|
|
6409
|
+
{ retryable: true }
|
|
6410
|
+
);
|
|
6411
|
+
}
|
|
5632
6412
|
return this.refreshService.refreshFromEvent(releaseId);
|
|
5633
6413
|
}
|
|
5634
6414
|
/** Periodic / manual current.json check + conditional snapshot reload. */
|
|
@@ -5637,6 +6417,9 @@ var RuntimeMetadataService = class {
|
|
|
5637
6417
|
try {
|
|
5638
6418
|
return await this.refreshViaExtension(revision);
|
|
5639
6419
|
} catch (err) {
|
|
6420
|
+
if (!this.metadataProviderFallback || err instanceof MetadataExtensionContractError) {
|
|
6421
|
+
throw err;
|
|
6422
|
+
}
|
|
5640
6423
|
this.logger.warn({
|
|
5641
6424
|
event: RUNTIME_METADATA_EVENTS.PROVIDER_FALLBACK,
|
|
5642
6425
|
reason: "extension-check-failed",
|
|
@@ -5645,6 +6428,12 @@ var RuntimeMetadataService = class {
|
|
|
5645
6428
|
await this.providerCoordinator.activateFallback("extension-check");
|
|
5646
6429
|
}
|
|
5647
6430
|
}
|
|
6431
|
+
if (this.metadataProviderKind === METADATA_PROVIDER_KIND.EXTENSION && !this.metadataProviderFallback) {
|
|
6432
|
+
throw new MetadataProjectionUnavailableError(
|
|
6433
|
+
"Metadata extension is unavailable and S3 fallback is disabled",
|
|
6434
|
+
{ retryable: true }
|
|
6435
|
+
);
|
|
6436
|
+
}
|
|
5648
6437
|
return this.refreshService.checkAndRefresh(revision);
|
|
5649
6438
|
}
|
|
5650
6439
|
stop() {
|
|
@@ -5972,8 +6761,9 @@ var RuntimeMetadataService = class {
|
|
|
5972
6761
|
return this.healthService.isHealthy();
|
|
5973
6762
|
}
|
|
5974
6763
|
async getValue(typeCode, valueCode, options) {
|
|
6764
|
+
let provider;
|
|
5975
6765
|
try {
|
|
5976
|
-
|
|
6766
|
+
provider = await this.activeProvider();
|
|
5977
6767
|
const guard = this.currentWriteGuard();
|
|
5978
6768
|
const value = await provider.getValue(typeCode, valueCode, options);
|
|
5979
6769
|
this.hydrateProviderValues(value ? [value] : [], guard);
|
|
@@ -5985,7 +6775,7 @@ var RuntimeMetadataService = class {
|
|
|
5985
6775
|
});
|
|
5986
6776
|
return value;
|
|
5987
6777
|
} catch (err) {
|
|
5988
|
-
if (await this.tryActivateFallbackFromError(err, "extension-lookup")) {
|
|
6778
|
+
if (await this.tryActivateFallbackFromError(err, "extension-lookup", provider)) {
|
|
5989
6779
|
const fallback = this.metadataProviderFallback;
|
|
5990
6780
|
if (fallback) {
|
|
5991
6781
|
return fallback.getValue(typeCode, valueCode, options);
|
|
@@ -5995,8 +6785,9 @@ var RuntimeMetadataService = class {
|
|
|
5995
6785
|
}
|
|
5996
6786
|
}
|
|
5997
6787
|
async batchGet(references, options) {
|
|
6788
|
+
let provider;
|
|
5998
6789
|
try {
|
|
5999
|
-
|
|
6790
|
+
provider = await this.activeProvider();
|
|
6000
6791
|
const generationAtStart = this.cache.getGeneration();
|
|
6001
6792
|
const result = await provider.batchGet(references, options);
|
|
6002
6793
|
this.logger.info({
|
|
@@ -6008,7 +6799,7 @@ var RuntimeMetadataService = class {
|
|
|
6008
6799
|
transport: this.providerCoordinator.getActiveKind(),
|
|
6009
6800
|
releaseId: result.releaseId
|
|
6010
6801
|
});
|
|
6011
|
-
if (result.unavailable && this.metadataProviderFallback && this.
|
|
6802
|
+
if (result.unavailable && this.metadataProviderFallback && provider !== this.metadataProviderFallback) {
|
|
6012
6803
|
await this.providerCoordinator.activateFallback("batch-unavailable");
|
|
6013
6804
|
return this.metadataProviderFallback.batchGet(references, options);
|
|
6014
6805
|
}
|
|
@@ -6022,7 +6813,7 @@ var RuntimeMetadataService = class {
|
|
|
6022
6813
|
);
|
|
6023
6814
|
return result;
|
|
6024
6815
|
} catch (err) {
|
|
6025
|
-
if (await this.tryActivateFallbackFromError(err, "batch-unavailable")) {
|
|
6816
|
+
if (await this.tryActivateFallbackFromError(err, "batch-unavailable", provider)) {
|
|
6026
6817
|
const fallback = this.metadataProviderFallback;
|
|
6027
6818
|
if (fallback) {
|
|
6028
6819
|
return fallback.batchGet(references, options);
|
|
@@ -6032,8 +6823,9 @@ var RuntimeMetadataService = class {
|
|
|
6032
6823
|
}
|
|
6033
6824
|
}
|
|
6034
6825
|
async getRelatedValues(sourceTypeCode, sourceValueCode, targetTypeCode, options) {
|
|
6826
|
+
let provider;
|
|
6035
6827
|
try {
|
|
6036
|
-
|
|
6828
|
+
provider = await this.activeProvider();
|
|
6037
6829
|
const guard = this.currentWriteGuard();
|
|
6038
6830
|
const values = await provider.getRelatedValues(
|
|
6039
6831
|
sourceTypeCode,
|
|
@@ -6044,7 +6836,7 @@ var RuntimeMetadataService = class {
|
|
|
6044
6836
|
this.hydrateProviderValues(values, guard);
|
|
6045
6837
|
return values;
|
|
6046
6838
|
} catch (err) {
|
|
6047
|
-
if (await this.tryActivateFallbackFromError(err, "extension-related")) {
|
|
6839
|
+
if (await this.tryActivateFallbackFromError(err, "extension-related", provider)) {
|
|
6048
6840
|
const fallback = this.metadataProviderFallback;
|
|
6049
6841
|
if (fallback) {
|
|
6050
6842
|
return fallback.getRelatedValues(
|
|
@@ -6089,15 +6881,16 @@ var RuntimeMetadataService = class {
|
|
|
6089
6881
|
}
|
|
6090
6882
|
}
|
|
6091
6883
|
async listRelations(query) {
|
|
6884
|
+
let provider;
|
|
6092
6885
|
try {
|
|
6093
|
-
|
|
6886
|
+
provider = await this.activeProvider();
|
|
6094
6887
|
const listed = await provider.listRelations(query);
|
|
6095
6888
|
if (!listed.supported && this.metadataProviderFallback && provider !== this.metadataProviderFallback) {
|
|
6096
6889
|
return this.metadataProviderFallback.listRelations(query);
|
|
6097
6890
|
}
|
|
6098
6891
|
return listed;
|
|
6099
6892
|
} catch (err) {
|
|
6100
|
-
if (await this.tryActivateFallbackFromError(err, "extension-relations")) {
|
|
6893
|
+
if (await this.tryActivateFallbackFromError(err, "extension-relations", provider)) {
|
|
6101
6894
|
const fallback = this.metadataProviderFallback;
|
|
6102
6895
|
if (fallback) {
|
|
6103
6896
|
return fallback.listRelations(query);
|
|
@@ -6107,14 +6900,15 @@ var RuntimeMetadataService = class {
|
|
|
6107
6900
|
}
|
|
6108
6901
|
}
|
|
6109
6902
|
async listTypeValues(typeCode, options) {
|
|
6903
|
+
let provider;
|
|
6110
6904
|
try {
|
|
6111
|
-
|
|
6905
|
+
provider = await this.activeProvider();
|
|
6112
6906
|
const guard = this.currentWriteGuard();
|
|
6113
6907
|
const listed = await provider.listTypeValues(typeCode, options);
|
|
6114
6908
|
this.hydrateProviderValues(listed?.values ?? [], guard);
|
|
6115
6909
|
return listed;
|
|
6116
6910
|
} catch (err) {
|
|
6117
|
-
if (await this.tryActivateFallbackFromError(err, "extension-list")) {
|
|
6911
|
+
if (await this.tryActivateFallbackFromError(err, "extension-list", provider)) {
|
|
6118
6912
|
const fallback = this.metadataProviderFallback;
|
|
6119
6913
|
if (fallback) {
|
|
6120
6914
|
return fallback.listTypeValues(typeCode, options);
|
|
@@ -6248,6 +7042,14 @@ var RuntimeMetadataService = class {
|
|
|
6248
7042
|
);
|
|
6249
7043
|
return true;
|
|
6250
7044
|
} catch (err) {
|
|
7045
|
+
if (err instanceof MetadataExtensionContractError) {
|
|
7046
|
+
this.logger.warn({
|
|
7047
|
+
event: RUNTIME_METADATA_EVENTS.INIT_FAILED,
|
|
7048
|
+
reason: "extension-contract",
|
|
7049
|
+
message: err.message
|
|
7050
|
+
});
|
|
7051
|
+
throw err;
|
|
7052
|
+
}
|
|
6251
7053
|
this.logger.warn({
|
|
6252
7054
|
event: RUNTIME_METADATA_EVENTS.PROVIDER_FALLBACK,
|
|
6253
7055
|
reason: "extension-unavailable",
|
|
@@ -6373,6 +7175,14 @@ var RuntimeMetadataService = class {
|
|
|
6373
7175
|
return await run(provider);
|
|
6374
7176
|
} catch (err) {
|
|
6375
7177
|
this.logFreshnessRejection(err);
|
|
7178
|
+
if (err instanceof MetadataExtensionContractError) {
|
|
7179
|
+
this.logger.warn({
|
|
7180
|
+
event: "runtimeMetadata.extension.contract",
|
|
7181
|
+
code: err.code,
|
|
7182
|
+
message: err.message
|
|
7183
|
+
});
|
|
7184
|
+
throw err;
|
|
7185
|
+
}
|
|
6376
7186
|
if (readPolicy !== METADATA_READ_POLICY.REQUIRE_FRESH && await this.tryActivateFallbackFromError(err, "extension-discovery")) {
|
|
6377
7187
|
const fallback = this.metadataProviderFallback;
|
|
6378
7188
|
if (fallback && supportsMetadataDiscovery(fallback)) {
|
|
@@ -6392,10 +7202,13 @@ var RuntimeMetadataService = class {
|
|
|
6392
7202
|
releaseId: err.metadata?.releaseId
|
|
6393
7203
|
});
|
|
6394
7204
|
}
|
|
6395
|
-
async tryActivateFallbackFromError(err, reason) {
|
|
6396
|
-
if (!(err instanceof MetadataProjectionUnavailableError) || !this.metadataProviderFallback ||
|
|
7205
|
+
async tryActivateFallbackFromError(err, reason, failedProvider) {
|
|
7206
|
+
if (!(err instanceof MetadataProjectionUnavailableError) || !this.metadataProviderFallback || failedProvider === this.metadataProviderFallback) {
|
|
6397
7207
|
return false;
|
|
6398
7208
|
}
|
|
7209
|
+
if (!this.usesExtensionTransport()) {
|
|
7210
|
+
return this.metadataProviderKind === METADATA_PROVIDER_KIND.EXTENSION;
|
|
7211
|
+
}
|
|
6399
7212
|
await this.providerCoordinator.activateFallback(reason);
|
|
6400
7213
|
return true;
|
|
6401
7214
|
}
|
|
@@ -6519,27 +7332,23 @@ var InMemoryMetadataProvider = class {
|
|
|
6519
7332
|
byKey = /* @__PURE__ */ new Map();
|
|
6520
7333
|
related = /* @__PURE__ */ new Map();
|
|
6521
7334
|
relations;
|
|
7335
|
+
typedRelationIndex;
|
|
6522
7336
|
knownTypeCodes = /* @__PURE__ */ new Set();
|
|
7337
|
+
lifecycleSupported;
|
|
7338
|
+
activeByType = /* @__PURE__ */ new Map();
|
|
7339
|
+
inactiveByType = /* @__PURE__ */ new Map();
|
|
6523
7340
|
constructor(options = {}) {
|
|
6524
7341
|
this.releaseId = options.releaseId ?? "memory";
|
|
6525
7342
|
this.unavailable = options.unavailable === true;
|
|
7343
|
+
this.lifecycleSupported = options.lifecycleSupported !== false;
|
|
6526
7344
|
this.relations = options.relations;
|
|
7345
|
+
this.typedRelationIndex = options.relations ? buildTypedRelationIndex(options.relations) : void 0;
|
|
6527
7346
|
for (const typeCode of options.knownTypeCodes ?? []) {
|
|
6528
7347
|
if (typeCode.trim()) {
|
|
6529
7348
|
this.knownTypeCodes.add(typeCode.trim());
|
|
6530
7349
|
}
|
|
6531
7350
|
}
|
|
6532
|
-
|
|
6533
|
-
const key = formatMetadataReference(record.typeCode, record.valueCode);
|
|
6534
|
-
this.byKey.set(key, record);
|
|
6535
|
-
if (record.related) {
|
|
6536
|
-
const byTarget = /* @__PURE__ */ new Map();
|
|
6537
|
-
for (const [targetType, values] of Object.entries(record.related)) {
|
|
6538
|
-
byTarget.set(targetType, [...values]);
|
|
6539
|
-
}
|
|
6540
|
-
this.related.set(key, byTarget);
|
|
6541
|
-
}
|
|
6542
|
-
}
|
|
7351
|
+
this.indexRecords(options.records ?? []);
|
|
6543
7352
|
}
|
|
6544
7353
|
async isAvailable() {
|
|
6545
7354
|
return !this.unavailable;
|
|
@@ -6554,22 +7363,10 @@ var InMemoryMetadataProvider = class {
|
|
|
6554
7363
|
this.forcedState = state;
|
|
6555
7364
|
}
|
|
6556
7365
|
replaceRecords(records, releaseId) {
|
|
6557
|
-
this.byKey.clear();
|
|
6558
|
-
this.related.clear();
|
|
6559
7366
|
if (releaseId) {
|
|
6560
7367
|
this.releaseId = releaseId;
|
|
6561
7368
|
}
|
|
6562
|
-
|
|
6563
|
-
const key = formatMetadataReference(record.typeCode, record.valueCode);
|
|
6564
|
-
this.byKey.set(key, record);
|
|
6565
|
-
if (record.related) {
|
|
6566
|
-
const byTarget = /* @__PURE__ */ new Map();
|
|
6567
|
-
for (const [targetType, values] of Object.entries(record.related)) {
|
|
6568
|
-
byTarget.set(targetType, [...values]);
|
|
6569
|
-
}
|
|
6570
|
-
this.related.set(key, byTarget);
|
|
6571
|
-
}
|
|
6572
|
-
}
|
|
7369
|
+
this.indexRecords(records);
|
|
6573
7370
|
}
|
|
6574
7371
|
async waitUntilReady() {
|
|
6575
7372
|
return this.getStatus();
|
|
@@ -6598,8 +7395,9 @@ var InMemoryMetadataProvider = class {
|
|
|
6598
7395
|
{ retryable: true }
|
|
6599
7396
|
);
|
|
6600
7397
|
}
|
|
7398
|
+
const resolved2 = this.readFilter(options);
|
|
6601
7399
|
const record = this.byKey.get(formatMetadataReference(typeCode, valueCode));
|
|
6602
|
-
if (!record) {
|
|
7400
|
+
if (!record || !statusMatchesFilter(record.entry.status, resolved2.filter)) {
|
|
6603
7401
|
return null;
|
|
6604
7402
|
}
|
|
6605
7403
|
return projectionEntryToMetadataValue(
|
|
@@ -6657,13 +7455,26 @@ var InMemoryMetadataProvider = class {
|
|
|
6657
7455
|
{ retryable: true }
|
|
6658
7456
|
);
|
|
6659
7457
|
}
|
|
7458
|
+
const resolved2 = resolveMetadataStatusFilter({ status: query.status });
|
|
7459
|
+
if (!resolved2.ok) {
|
|
7460
|
+
throw new MetadataDiscoveryError(resolved2.message, resolved2.code);
|
|
7461
|
+
}
|
|
6660
7462
|
if (!this.relations) {
|
|
7463
|
+
if (resolved2.filter !== METADATA_STATUS_FILTER.ACTIVE) {
|
|
7464
|
+
throw new MetadataDiscoveryError(
|
|
7465
|
+
"INACTIVE and ALL relationship queries require typed-relations.json",
|
|
7466
|
+
METADATA_LIFECYCLE_UNSUPPORTED
|
|
7467
|
+
);
|
|
7468
|
+
}
|
|
6661
7469
|
return { releaseId: this.releaseId, supported: false, relations: [] };
|
|
6662
7470
|
}
|
|
6663
7471
|
return {
|
|
6664
7472
|
releaseId: this.releaseId,
|
|
6665
7473
|
supported: true,
|
|
6666
|
-
relations: filterTypedRelations(this.relations,
|
|
7474
|
+
relations: filterTypedRelations(this.relations, {
|
|
7475
|
+
...query,
|
|
7476
|
+
status: resolved2.filter
|
|
7477
|
+
})
|
|
6667
7478
|
};
|
|
6668
7479
|
}
|
|
6669
7480
|
async getRelatedValues(sourceTypeCode, sourceValueCode, targetTypeCode, options) {
|
|
@@ -6700,11 +7511,49 @@ var InMemoryMetadataProvider = class {
|
|
|
6700
7511
|
return groups;
|
|
6701
7512
|
}
|
|
6702
7513
|
async relatedValuesFor(sourceTypeCode, sourceValueCode, targetTypeCode, options) {
|
|
7514
|
+
const resolved2 = this.readFilter(options);
|
|
7515
|
+
if (resolved2.filter !== METADATA_STATUS_FILTER.ACTIVE && !this.relations) {
|
|
7516
|
+
if (resolved2.enforceCapability) {
|
|
7517
|
+
throw new MetadataDiscoveryError(
|
|
7518
|
+
"INACTIVE and ALL related-value queries require typed-relations.json",
|
|
7519
|
+
METADATA_LIFECYCLE_UNSUPPORTED
|
|
7520
|
+
);
|
|
7521
|
+
}
|
|
7522
|
+
} else if (resolved2.filter !== METADATA_STATUS_FILTER.ACTIVE && this.relations) {
|
|
7523
|
+
const listed = resolvePublishedRelationshipQuery({
|
|
7524
|
+
typedSupported: true,
|
|
7525
|
+
relations: this.relations,
|
|
7526
|
+
index: this.typedRelationIndex,
|
|
7527
|
+
sourceTypeCode,
|
|
7528
|
+
sourceValueCode,
|
|
7529
|
+
targetTypeCode,
|
|
7530
|
+
status: resolved2.filter
|
|
7531
|
+
});
|
|
7532
|
+
if (!listed.ok) {
|
|
7533
|
+
throw new MetadataDiscoveryError(listed.message, listed.code);
|
|
7534
|
+
}
|
|
7535
|
+
const values2 = [];
|
|
7536
|
+
const seen = /* @__PURE__ */ new Set();
|
|
7537
|
+
for (const row of listed.relationships) {
|
|
7538
|
+
if (seen.has(row.toMetadataValueCode)) {
|
|
7539
|
+
continue;
|
|
7540
|
+
}
|
|
7541
|
+
seen.add(row.toMetadataValueCode);
|
|
7542
|
+
const value = await this.getValue(targetTypeCode, row.toMetadataValueCode, options);
|
|
7543
|
+
if (value) {
|
|
7544
|
+
values2.push(value);
|
|
7545
|
+
}
|
|
7546
|
+
}
|
|
7547
|
+
return values2;
|
|
7548
|
+
}
|
|
6703
7549
|
const sourceKey = formatMetadataReference(sourceTypeCode, sourceValueCode);
|
|
6704
7550
|
const targets = this.related.get(sourceKey)?.get(targetTypeCode) ?? [];
|
|
6705
7551
|
const values = [];
|
|
6706
7552
|
for (const valueCode of targets) {
|
|
6707
|
-
const value = await this.getValue(targetTypeCode, valueCode,
|
|
7553
|
+
const value = await this.getValue(targetTypeCode, valueCode, {
|
|
7554
|
+
locale: options?.locale,
|
|
7555
|
+
status: METADATA_STATUS_FILTER.ACTIVE
|
|
7556
|
+
});
|
|
6708
7557
|
if (value) {
|
|
6709
7558
|
values.push(value);
|
|
6710
7559
|
}
|
|
@@ -6718,19 +7567,18 @@ var InMemoryMetadataProvider = class {
|
|
|
6718
7567
|
{ retryable: true }
|
|
6719
7568
|
);
|
|
6720
7569
|
}
|
|
7570
|
+
if (!this.hasType(typeCode)) {
|
|
7571
|
+
return null;
|
|
7572
|
+
}
|
|
7573
|
+
const resolved2 = this.readFilter(options);
|
|
7574
|
+
const records = this.recordsForFilter(typeCode, resolved2.filter);
|
|
6721
7575
|
const values = [];
|
|
6722
|
-
for (const record of
|
|
6723
|
-
if (record.typeCode !== typeCode) {
|
|
6724
|
-
continue;
|
|
6725
|
-
}
|
|
7576
|
+
for (const record of records) {
|
|
6726
7577
|
const value = await this.getValue(record.typeCode, record.valueCode, options);
|
|
6727
7578
|
if (value) {
|
|
6728
7579
|
values.push(value);
|
|
6729
7580
|
}
|
|
6730
7581
|
}
|
|
6731
|
-
if (values.length === 0) {
|
|
6732
|
-
return null;
|
|
6733
|
-
}
|
|
6734
7582
|
return {
|
|
6735
7583
|
releaseId: this.releaseId,
|
|
6736
7584
|
values,
|
|
@@ -6790,14 +7638,20 @@ var InMemoryMetadataProvider = class {
|
|
|
6790
7638
|
}
|
|
6791
7639
|
async getRelationships(query) {
|
|
6792
7640
|
this.assertReadable(query.readPolicy, query.releaseId);
|
|
6793
|
-
const
|
|
6794
|
-
|
|
7641
|
+
const resolved2 = resolveMetadataStatusFilter({ status: query.status });
|
|
7642
|
+
if (!resolved2.ok) {
|
|
7643
|
+
throw new MetadataDiscoveryError(resolved2.message, resolved2.code);
|
|
7644
|
+
}
|
|
7645
|
+
const listed = resolvePublishedRelationshipQuery({
|
|
7646
|
+
typedSupported: this.relations !== void 0,
|
|
6795
7647
|
relations: this.relations ?? [],
|
|
7648
|
+
index: this.typedRelationIndex,
|
|
6796
7649
|
sourceTypeCode: query.sourceTypeCode,
|
|
6797
7650
|
sourceValueCode: query.sourceValueCode,
|
|
6798
7651
|
targetTypeCode: query.targetTypeCode,
|
|
6799
7652
|
relationType: query.relationType,
|
|
6800
|
-
direction: query.direction
|
|
7653
|
+
direction: query.direction,
|
|
7654
|
+
status: resolved2.filter
|
|
6801
7655
|
});
|
|
6802
7656
|
if (!listed.ok) {
|
|
6803
7657
|
throwPublishedListFailure(listed);
|
|
@@ -6812,10 +7666,22 @@ var InMemoryMetadataProvider = class {
|
|
|
6812
7666
|
if (!this.hasType(typeCode)) {
|
|
6813
7667
|
throw new UnknownMetadataTypeError(typeCode);
|
|
6814
7668
|
}
|
|
6815
|
-
const
|
|
7669
|
+
const resolved2 = resolveMetadataStatusFilter({ status: options?.status });
|
|
7670
|
+
if (!resolved2.ok) {
|
|
7671
|
+
throw new MetadataDiscoveryError(resolved2.message, resolved2.code);
|
|
7672
|
+
}
|
|
7673
|
+
if (resolved2.enforceCapability && !this.lifecycleSupported) {
|
|
7674
|
+
throw new MetadataDiscoveryError(
|
|
7675
|
+
"This projection release does not publish inactive lifecycle records. An INACTIVE or ALL query cannot be answered from active-only artifacts.",
|
|
7676
|
+
METADATA_LIFECYCLE_UNSUPPORTED
|
|
7677
|
+
);
|
|
7678
|
+
}
|
|
7679
|
+
const entries = this.recordsForFilter(typeCode, resolved2.filter).map(
|
|
7680
|
+
(record) => record.entry
|
|
7681
|
+
);
|
|
6816
7682
|
const listed = listPublishedValues(entries, {
|
|
6817
7683
|
releaseId: this.releaseId,
|
|
6818
|
-
status:
|
|
7684
|
+
status: projectionStatusLiterals(resolved2.filter),
|
|
6819
7685
|
limit: options?.limit,
|
|
6820
7686
|
cursor: options?.cursor,
|
|
6821
7687
|
sortBy: options?.sortBy,
|
|
@@ -6844,6 +7710,55 @@ var InMemoryMetadataProvider = class {
|
|
|
6844
7710
|
}
|
|
6845
7711
|
return false;
|
|
6846
7712
|
}
|
|
7713
|
+
indexRecords(records) {
|
|
7714
|
+
this.byKey.clear();
|
|
7715
|
+
this.related.clear();
|
|
7716
|
+
this.activeByType.clear();
|
|
7717
|
+
this.inactiveByType.clear();
|
|
7718
|
+
for (const record of records) {
|
|
7719
|
+
const key = formatMetadataReference(record.typeCode, record.valueCode);
|
|
7720
|
+
this.byKey.set(key, record);
|
|
7721
|
+
const bucket = statusMatchesFilter(record.entry.status, METADATA_STATUS_FILTER.INACTIVE) ? this.inactiveByType : this.activeByType;
|
|
7722
|
+
const list = bucket.get(record.typeCode) ?? [];
|
|
7723
|
+
list.push(record);
|
|
7724
|
+
bucket.set(record.typeCode, list);
|
|
7725
|
+
if (record.related) {
|
|
7726
|
+
const byTarget = /* @__PURE__ */ new Map();
|
|
7727
|
+
for (const [targetType, values] of Object.entries(record.related)) {
|
|
7728
|
+
byTarget.set(targetType, [...values]);
|
|
7729
|
+
}
|
|
7730
|
+
this.related.set(key, byTarget);
|
|
7731
|
+
}
|
|
7732
|
+
}
|
|
7733
|
+
}
|
|
7734
|
+
readFilter(options) {
|
|
7735
|
+
const resolved2 = resolveMetadataStatusFilter({
|
|
7736
|
+
status: options?.status,
|
|
7737
|
+
includeInactive: options?.includeInactive
|
|
7738
|
+
});
|
|
7739
|
+
if (!resolved2.ok) {
|
|
7740
|
+
throw new MetadataDiscoveryError(resolved2.message, resolved2.code);
|
|
7741
|
+
}
|
|
7742
|
+
if (resolved2.enforceCapability && !this.lifecycleSupported) {
|
|
7743
|
+
throw new MetadataDiscoveryError(
|
|
7744
|
+
"This projection release does not publish inactive lifecycle records. An INACTIVE or ALL query cannot be answered from active-only artifacts.",
|
|
7745
|
+
METADATA_LIFECYCLE_UNSUPPORTED
|
|
7746
|
+
);
|
|
7747
|
+
}
|
|
7748
|
+
return resolved2;
|
|
7749
|
+
}
|
|
7750
|
+
recordsForFilter(typeCode, filter) {
|
|
7751
|
+
if (filter === METADATA_STATUS_FILTER.INACTIVE) {
|
|
7752
|
+
return this.inactiveByType.get(typeCode) ?? [];
|
|
7753
|
+
}
|
|
7754
|
+
if (filter === METADATA_STATUS_FILTER.ALL) {
|
|
7755
|
+
return [
|
|
7756
|
+
...this.activeByType.get(typeCode) ?? [],
|
|
7757
|
+
...this.inactiveByType.get(typeCode) ?? []
|
|
7758
|
+
];
|
|
7759
|
+
}
|
|
7760
|
+
return this.activeByType.get(typeCode) ?? [];
|
|
7761
|
+
}
|
|
6847
7762
|
assertReadable(readPolicy, releaseId) {
|
|
6848
7763
|
if (this.unavailable) {
|
|
6849
7764
|
throw new MetadataProjectionUnavailableError(
|
|
@@ -6857,6 +7772,6 @@ var InMemoryMetadataProvider = class {
|
|
|
6857
7772
|
}
|
|
6858
7773
|
};
|
|
6859
7774
|
|
|
6860
|
-
export { CACHE_STATUS, DEFAULT_EXCLUDED_CODE_FIELDS, DEFAULT_PROVIDER_RECOVERY_COOLDOWN_MS, ExtensionMetadataProvider, InMemoryMetadataProvider, InvalidMetadataReferenceError, METADATA_ATTRIBUTE_FILTER_KEY, METADATA_PROJECTIONS_BUCKET_ENV, METADATA_PROVIDER_KIND, METADATA_READ_POLICY, METADATA_RELATION_DIRECTION, ManifestValidationError, MetadataCache, MetadataDiscoveryError, MetadataDownloader, MetadataFreshnessError, MetadataHealthService, MetadataLoader, MetadataLookupError, MetadataNotReadyError, MetadataProjectionUnavailableError, MetadataRefreshService, MetadataReleaseMismatchError, MetadataResolver, NON_METADATA_KEYS, PROVIDER_TRANSPORT_STATE, ProjectionDownloadError, ProviderFailoverCoordinator, REFRESH_STATUS, RUNTIME_METADATA_EVENTS, RUNTIME_METADATA_INTEGRATION_TARGETS, RUNTIME_METADATA_TYPE_CODE_ALIASES, RuntimeMetadataError, RuntimeMetadataService, S3MetadataProvider, UnknownMetadataTypeError, WORKFLOW_STEP_RULE_KEYS, assertMetadataReadPolicy, assertReleasePin, canonicalMetadataProjectionsBucketName, collectResponseReferences, collectResponseTypeCodes, createCodeFieldExclusionSet, createRuntimeMetadataFromEnv, defaultExtensionBaseUrl, ensureRuntimeMetadataLoaded, formatMetadataReference, getCandidateTypeCodesForKey, getRuntimeMetadataHealth, getRuntimeMetadataService, hasPotentialMetadata, isCompactMetadataReference, isExtensionEnabled, isExtensionServing, isFreshProjectionState, isMetadataProjectionConfigured, isMetadataProjectionsBucketConfigured, isMetadataReference, isMetadataValueObject, isMetadataValueObjectArray, isWorkflowStepRecord, isWorkflowStepRuleField, localizedLabelFromEntry, manifestLocalizationSchema, metadataGroupFromManifest, metadataValueToReference, normalizeRuntimeMetadataTypeCode, onMetadataProjectionCompleted, parseMetadataReference, projectionEntryToMetadataValue, projectionManifestSchema, readMetadataProjectionsBucket, readModelGroupsFromManifest, relatedValueCodes, resetRuntimeMetadataBootstrapState, resolveMetadataProjectionsBucket, resolveRuntimeMetadataConfig, runtimeMetadataConfigSchema, selectMetadataProvider, supportsMetadataDiscovery, throwPublishedListFailure, tryGetRuntimeMetadataService, tryParseMetadataReference, typeCodeFromCodeFieldName };
|
|
7775
|
+
export { CACHE_STATUS, DEFAULT_EXCLUDED_CODE_FIELDS, DEFAULT_PROVIDER_RECOVERY_COOLDOWN_MS, ExtensionMetadataProvider, InMemoryMetadataProvider, InvalidMetadataReferenceError, METADATA_ATTRIBUTE_FILTER_KEY, METADATA_PROJECTIONS_BUCKET_ENV, METADATA_PROVIDER_KIND, METADATA_READ_POLICY, METADATA_RELATION_DIRECTION, ManifestValidationError, MetadataCache, MetadataDiscoveryError, MetadataDownloader, MetadataExtensionContractError, MetadataFreshnessError, MetadataHealthService, MetadataLoader, MetadataLookupError, MetadataNotReadyError, MetadataProjectionUnavailableError, MetadataRefreshService, MetadataReleaseMismatchError, MetadataResolver, NON_METADATA_KEYS, PROVIDER_TRANSPORT_STATE, ProjectionDownloadError, ProviderFailoverCoordinator, REFRESH_STATUS, RUNTIME_METADATA_EVENTS, RUNTIME_METADATA_INTEGRATION_TARGETS, RUNTIME_METADATA_TYPE_CODE_ALIASES, RuntimeMetadataError, RuntimeMetadataService, S3MetadataProvider, UnknownMetadataTypeError, WORKFLOW_STEP_RULE_KEYS, assertMetadataReadPolicy, assertReleasePin, canonicalMetadataProjectionsBucketName, collectResponseReferences, collectResponseTypeCodes, createCodeFieldExclusionSet, createRuntimeMetadataFromEnv, defaultExtensionBaseUrl, ensureRuntimeMetadataLoaded, formatMetadataReference, getCandidateTypeCodesForKey, getRuntimeMetadataHealth, getRuntimeMetadataService, hasPotentialMetadata, isCompactMetadataReference, isExtensionEnabled, isExtensionServing, isFreshProjectionState, isMetadataProjectionConfigured, isMetadataProjectionsBucketConfigured, isMetadataReference, isMetadataValueObject, isMetadataValueObjectArray, isWorkflowStepRecord, isWorkflowStepRuleField, localizedLabelFromEntry, manifestLocalizationSchema, metadataGroupFromManifest, metadataValueToReference, normalizeRuntimeMetadataTypeCode, onMetadataProjectionCompleted, parseMetadataReference, projectionEntryToMetadataValue, projectionManifestSchema, readMetadataProjectionsBucket, readModelGroupsFromManifest, relatedValueCodes, resetRuntimeMetadataBootstrapState, resolveMetadataProjectionsBucket, resolveRuntimeMetadataConfig, runtimeMetadataConfigSchema, selectMetadataProvider, supportsMetadataDiscovery, throwPublishedListFailure, tryGetRuntimeMetadataService, tryParseMetadataReference, typeCodeFromCodeFieldName };
|
|
6861
7776
|
//# sourceMappingURL=index.js.map
|
|
6862
7777
|
//# sourceMappingURL=index.js.map
|