@myvitalrx/metadata-runtime 1.11.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.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
- function filterTypedRelations(relations, query) {
1591
- return relations.filter((relation) => {
1592
- if (relation.fromMetadataTypeCode !== query.fromType) {
1593
- return false;
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
- if (relation.fromMetadataValueCode !== query.fromValue) {
1596
- return false;
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();
@@ -2001,20 +2322,30 @@ function queryPublishedRelationships(query) {
2001
2322
  message: "relationship filters must be non-empty strings"
2002
2323
  };
2003
2324
  }
2325
+ const status = resolveRelationshipStatus(query.status);
2326
+ if (!status.ok) {
2327
+ return status;
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);
2004
2339
  const seen = /* @__PURE__ */ new Set();
2005
2340
  const relationships = [];
2006
- for (const relation of query.relations) {
2007
- if (!isCompleteRelation(relation)) {
2341
+ for (const relation of bucket) {
2342
+ if (!isCompleteTypedRelation(relation)) {
2008
2343
  return {
2009
2344
  ok: false,
2010
2345
  code: "METADATA_TYPE_INCOMPLETE",
2011
2346
  message: "Typed relationship catalog contains a row that cannot be queried"
2012
2347
  };
2013
2348
  }
2014
- const matchesSource = direction === PUBLISHED_RELATION_DIRECTION.OUTGOING ? relation.fromMetadataTypeCode === sourceTypeCode && relation.fromMetadataValueCode === sourceValueCode : relation.toMetadataTypeCode === sourceTypeCode && relation.toMetadataValueCode === sourceValueCode;
2015
- if (!matchesSource) {
2016
- continue;
2017
- }
2018
2349
  if (relationType && relation.relationType !== relationType) {
2019
2350
  continue;
2020
2351
  }
@@ -2070,10 +2401,15 @@ function relationshipKey(relation) {
2070
2401
  relation.permissionActionCode ?? ""
2071
2402
  ].join("\0");
2072
2403
  }
2073
- function isCompleteRelation(relation) {
2074
- return Boolean(
2075
- 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()
2076
- );
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 };
2077
2413
  }
2078
2414
  function optionalCode(value) {
2079
2415
  if (value === void 0) {
@@ -2097,14 +2433,25 @@ function resolvePublishedRelationshipQuery(input) {
2097
2433
  if (input.typedSupported) {
2098
2434
  return queryPublishedRelationships({
2099
2435
  relations: input.relations,
2436
+ index: input.index,
2100
2437
  sourceTypeCode: input.sourceTypeCode,
2101
2438
  sourceValueCode: input.sourceValueCode,
2102
2439
  targetTypeCode: input.targetTypeCode,
2103
2440
  relationType: input.relationType,
2104
- direction: input.direction
2441
+ direction: input.direction,
2442
+ status: input.status
2105
2443
  });
2106
2444
  }
2107
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
+ }
2108
2455
  return queryRelationshipIndex({
2109
2456
  index: input.relationshipIndex,
2110
2457
  sourceTypeCode: input.sourceTypeCode,
@@ -2113,6 +2460,15 @@ function resolvePublishedRelationshipQuery(input) {
2113
2460
  direction: input.direction
2114
2461
  });
2115
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
+ }
2116
2472
  return { ok: true, supported: false, relationships: [] };
2117
2473
  }
2118
2474
  function queryRelationshipIndex(input) {
@@ -3622,6 +3978,9 @@ var MetadataCache = class {
3622
3978
  getTypedRelations() {
3623
3979
  return this.snapshot?.typedRelations;
3624
3980
  }
3981
+ getTypedRelationIndex() {
3982
+ return this.snapshot?.typedRelationIndex;
3983
+ }
3625
3984
  getLocalization(locale) {
3626
3985
  return this.snapshot?.localization?.get(locale);
3627
3986
  }
@@ -3652,6 +4011,7 @@ var MetadataCache = class {
3652
4011
  this.generation += 1;
3653
4012
  const domainFiles = new Map(bundle.domainFiles);
3654
4013
  Object.freeze(domainFiles);
4014
+ const typedRelations = bundle.typedRelations ? Object.freeze([...bundle.typedRelations]) : void 0;
3655
4015
  const snapshot = Object.freeze({
3656
4016
  revision: bundle.releaseId,
3657
4017
  releaseId: bundle.releaseId,
@@ -3664,7 +4024,8 @@ var MetadataCache = class {
3664
4024
  domainFiles,
3665
4025
  common: bundle.common ? Object.freeze({ ...bundle.common }) : void 0,
3666
4026
  relationshipIndex: bundle.relationshipIndex ? Object.freeze({ ...bundle.relationshipIndex }) : void 0,
3667
- typedRelations: bundle.typedRelations ? Object.freeze([...bundle.typedRelations]) : void 0,
4027
+ typedRelations,
4028
+ typedRelationIndex: typedRelations ? buildTypedRelationIndex(typedRelations) : void 0,
3668
4029
  manifest: Object.freeze({
3669
4030
  ...bundle.manifest,
3670
4031
  files: Object.freeze(
@@ -4012,7 +4373,7 @@ var MetadataResolver = class {
4012
4373
  const latest = [];
4013
4374
  for (const record of Object.values(file.records)) {
4014
4375
  const entry = record.versions[String(record.latestVersion)];
4015
- if (entry) {
4376
+ if (entry && canonicalMetadataStatus(entry.status) === METADATA_STATUS.ACTIVE) {
4016
4377
  latest.push(entry);
4017
4378
  }
4018
4379
  }
@@ -4083,7 +4444,11 @@ var MetadataResolver = class {
4083
4444
  return void 0;
4084
4445
  }
4085
4446
  const targetVersion = version !== void 0 ? version : record.latestVersion;
4086
- return record.versions[String(targetVersion)];
4447
+ const entry = record.versions[String(targetVersion)];
4448
+ if (!entry || canonicalMetadataStatus(entry.status) !== METADATA_STATUS.ACTIVE) {
4449
+ return void 0;
4450
+ }
4451
+ return entry;
4087
4452
  }
4088
4453
  requireManifest() {
4089
4454
  const manifest = this.cache.getManifest();
@@ -4428,6 +4793,7 @@ var ExtensionMetadataProvider = class {
4428
4793
  readyTimeoutMs;
4429
4794
  requestTimeoutMs;
4430
4795
  logger;
4796
+ lifecycleSupport;
4431
4797
  fetchImpl;
4432
4798
  constructor(options) {
4433
4799
  this.baseUrl = options.baseUrl.replace(/\/+$/, "");
@@ -4516,15 +4882,29 @@ var ExtensionMetadataProvider = class {
4516
4882
  lastRefreshAttemptAt: body.lastRefreshAttemptAt ?? null,
4517
4883
  lastSuccessfulRefreshAt: body.lastSuccessfulRefreshAt ?? null,
4518
4884
  cacheAgeMs: typeof body.cacheAgeMs === "number" ? body.cacheAgeMs : null,
4519
- 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
4520
4890
  };
4521
4891
  }
4522
4892
  async getValue(typeCode, valueCode, options) {
4523
- const localeQuery = options?.locale ? `?locale=${encodeURIComponent(options.locale)}` : "";
4524
- const path = `/v1/metadata/${encodeURIComponent(typeCode)}/${encodeURIComponent(valueCode)}${localeQuery}`;
4893
+ const filter = await this.assertQueryLifecycle("values", options);
4894
+ const path = `/v1/metadata/${encodeURIComponent(typeCode)}/${encodeURIComponent(valueCode)}${metadataQuery(options)}`;
4525
4895
  try {
4526
4896
  const item = await this.requestJson("GET", path);
4527
- return this.toMetadataValue(item, options?.locale);
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;
4528
4908
  } catch (err) {
4529
4909
  if (isNotFound(err)) {
4530
4910
  return null;
@@ -4598,18 +4978,28 @@ var ExtensionMetadataProvider = class {
4598
4978
  * GET /v1/metadata/{typeCode}. Unknown types are a projection miss (`null`).
4599
4979
  */
4600
4980
  async listTypeValues(typeCode, options) {
4981
+ const filter = await this.assertQueryLifecycle("values", options);
4601
4982
  const params = new URLSearchParams();
4602
4983
  if (options?.locale) {
4603
4984
  params.set("locale", options.locale);
4604
4985
  }
4605
- if (options?.includeInactive) {
4986
+ if (options?.status) {
4987
+ params.set("status", options.status);
4988
+ } else if (options?.includeInactive) {
4606
4989
  params.set("includeInactive", "true");
4607
4990
  }
4608
4991
  const query = params.toString();
4609
4992
  const path = `/v1/metadata/${encodeURIComponent(typeCode)}${query ? `?${query}` : ""}`;
4610
4993
  try {
4611
4994
  const body = await this.requestJson("GET", path);
4612
- const values = Object.values(body.items ?? {}).map((item) => this.toMetadataValue(item, options?.locale)).filter((item) => item != null);
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;
4613
5003
  return {
4614
5004
  releaseId: body.releaseId ?? null,
4615
5005
  values,
@@ -4624,15 +5014,18 @@ var ExtensionMetadataProvider = class {
4624
5014
  }
4625
5015
  async listValuesByType(typeCode, options) {
4626
5016
  await this.assertDiscoveryPolicy(options?.readPolicy);
5017
+ const filter = await this.assertQueryLifecycle("values", { status: options?.status });
4627
5018
  const body = await this.requestJson("GET", `/v1/metadata/types/${encodeURIComponent(typeCode)}/values${discoveryQuery(options)}`);
5019
+ const items = Array.isArray(body.items) ? body.items : [];
4628
5020
  return {
4629
5021
  releaseId: body.releaseId ?? null,
4630
- items: Array.isArray(body.items) ? body.items : [],
5022
+ items: listedValueItems(items, filter),
4631
5023
  ...body.nextCursor ? { nextCursor: body.nextCursor } : {}
4632
5024
  };
4633
5025
  }
4634
5026
  async listValuesByTypes(typeCodes, options) {
4635
5027
  await this.assertDiscoveryPolicy(options?.readPolicy);
5028
+ const filter = await this.assertQueryLifecycle("values", { status: options?.status });
4636
5029
  const body = await this.requestJson(
4637
5030
  "POST",
4638
5031
  "/v1/metadata/types/values",
@@ -4643,11 +5036,15 @@ var ExtensionMetadataProvider = class {
4643
5036
  );
4644
5037
  return {
4645
5038
  releaseId: body.releaseId ?? null,
4646
- 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
+ }))
4647
5043
  };
4648
5044
  }
4649
5045
  async getRelationships(query) {
4650
5046
  await this.assertDiscoveryPolicy(query.readPolicy);
5047
+ const filter = await this.assertQueryLifecycle("relations", { status: query.status });
4651
5048
  const body = await this.requestJson(
4652
5049
  "POST",
4653
5050
  "/v1/metadata/relationships/query",
@@ -4656,7 +5053,10 @@ var ExtensionMetadataProvider = class {
4656
5053
  return {
4657
5054
  releaseId: body.releaseId ?? null,
4658
5055
  supported: body.supported === true,
4659
- relationships: Array.isArray(body.relationships) ? body.relationships : []
5056
+ relationships: lifecycleRows(
5057
+ Array.isArray(body.relationships) ? body.relationships : [],
5058
+ filter
5059
+ )
4660
5060
  };
4661
5061
  }
4662
5062
  async listRelations(query) {
@@ -4669,12 +5069,19 @@ var ExtensionMetadataProvider = class {
4669
5069
  if (query.toType) {
4670
5070
  params.set("toType", query.toType);
4671
5071
  }
5072
+ const filter = await this.assertQueryLifecycle("relations", { status: query.status });
5073
+ if (query.status) {
5074
+ params.set("status", query.status);
5075
+ }
4672
5076
  try {
4673
5077
  const body = await this.requestJson("GET", `/v1/relations?${params.toString()}`);
4674
5078
  return {
4675
5079
  releaseId: body.releaseId ?? null,
4676
5080
  supported: body.supported === true,
4677
- relations: Array.isArray(body.relations) ? body.relations : []
5081
+ relations: lifecycleRows(
5082
+ Array.isArray(body.relations) ? body.relations : [],
5083
+ filter
5084
+ )
4678
5085
  };
4679
5086
  } catch (err) {
4680
5087
  if (isNotFound(err)) {
@@ -4684,8 +5091,8 @@ var ExtensionMetadataProvider = class {
4684
5091
  }
4685
5092
  }
4686
5093
  async getRelatedValues(sourceTypeCode, sourceValueCode, targetTypeCode, options) {
4687
- const localeQuery = options?.locale ? `?locale=${encodeURIComponent(options.locale)}` : "";
4688
- const path = `/v1/related/${encodeURIComponent(sourceTypeCode)}/${encodeURIComponent(sourceValueCode)}/${encodeURIComponent(targetTypeCode)}${localeQuery}`;
5094
+ await this.assertQueryLifecycle("values", options);
5095
+ const path = `/v1/related/${encodeURIComponent(sourceTypeCode)}/${encodeURIComponent(sourceValueCode)}/${encodeURIComponent(targetTypeCode)}${metadataQuery(options)}`;
4689
5096
  try {
4690
5097
  const body = await this.requestJson(
4691
5098
  "GET",
@@ -4703,6 +5110,7 @@ var ExtensionMetadataProvider = class {
4703
5110
  if (sourceValueCodes.length === 0) {
4704
5111
  return [];
4705
5112
  }
5113
+ await this.assertQueryLifecycle("values", options);
4706
5114
  const groups = [];
4707
5115
  try {
4708
5116
  for (let offset = 0; offset < sourceValueCodes.length; offset += RELATED_BATCH_LIMIT) {
@@ -4711,7 +5119,8 @@ var ExtensionMetadataProvider = class {
4711
5119
  sourceType: sourceTypeCode,
4712
5120
  sourceValues,
4713
5121
  targetType: targetTypeCode,
4714
- ...options?.locale ? { locale: options.locale } : {}
5122
+ ...options?.locale ? { locale: options.locale } : {},
5123
+ ...options?.status ? { status: options.status } : {}
4715
5124
  });
4716
5125
  for (const group of body.groups ?? []) {
4717
5126
  groups.push({
@@ -4762,6 +5171,7 @@ var ExtensionMetadataProvider = class {
4762
5171
  }
4763
5172
  }
4764
5173
  async requestRefresh(releaseId) {
5174
+ this.lifecycleSupport = void 0;
4765
5175
  const body = await this.requestJson(
4766
5176
  "POST",
4767
5177
  "/v1/refresh",
@@ -4769,6 +5179,32 @@ var ExtensionMetadataProvider = class {
4769
5179
  );
4770
5180
  return body.changed === true;
4771
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
+ }
4772
5208
  toMetadataValue(item, locale) {
4773
5209
  if (!item?.typeCode || !item.valueCode) {
4774
5210
  return null;
@@ -4856,7 +5292,7 @@ var ExtensionMetadataProvider = class {
4856
5292
  errorBody.actualReleaseId ?? errorBody.releaseId ?? null
4857
5293
  );
4858
5294
  }
4859
- if (code === "METADATA_DISCOVERY_INVALID" || code === "METADATA_TYPE_INCOMPLETE" || code === "METADATA_RELATION_SEMANTICS_UNSUPPORTED") {
5295
+ if (code === "METADATA_DISCOVERY_INVALID" || code === "METADATA_TYPE_INCOMPLETE" || code === "METADATA_RELATION_SEMANTICS_UNSUPPORTED" || code === METADATA_LIFECYCLE_UNSUPPORTED) {
4860
5296
  throw new MetadataDiscoveryError(
4861
5297
  errorBody.message ?? "Metadata discovery request was rejected",
4862
5298
  code
@@ -5011,6 +5447,49 @@ function appendDiscoveryParams(params, options) {
5011
5447
  }
5012
5448
  }
5013
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
+ }
5014
5493
  function sleep(ms) {
5015
5494
  return new Promise((resolve) => setTimeout(resolve, ms));
5016
5495
  }
@@ -5260,21 +5739,30 @@ var S3MetadataProvider = class {
5260
5739
  };
5261
5740
  }
5262
5741
  async getValue(typeCode, valueCode, options) {
5742
+ const resolved2 = this.valueFilter(options);
5263
5743
  await this.ensureTypesLoaded([typeCode]);
5264
- try {
5265
- const entry = this.resolver.resolve(typeCode, valueCode, options?.version);
5266
- return projectionEntryToMetadataValue(
5267
- typeCode,
5268
- valueCode,
5269
- entry,
5270
- options?.locale
5271
- );
5272
- } catch (err) {
5273
- if (err instanceof MetadataLookupError) {
5274
- return null;
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;
5275
5758
  }
5276
- throw err;
5277
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;
5278
5766
  }
5279
5767
  async batchGet(references, options) {
5280
5768
  const invalidReferences = [];
@@ -5321,8 +5809,18 @@ var S3MetadataProvider = class {
5321
5809
  };
5322
5810
  }
5323
5811
  async listRelations(query) {
5812
+ const resolved2 = resolveMetadataStatusFilter({ status: query.status });
5813
+ if (!resolved2.ok) {
5814
+ throw new MetadataDiscoveryError(resolved2.message, resolved2.code);
5815
+ }
5324
5816
  const relations = this.cache.getTypedRelations();
5325
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
+ }
5326
5824
  return {
5327
5825
  releaseId: this.cache.getReleaseId(),
5328
5826
  supported: false,
@@ -5332,7 +5830,10 @@ var S3MetadataProvider = class {
5332
5830
  return {
5333
5831
  releaseId: this.cache.getReleaseId(),
5334
5832
  supported: true,
5335
- relations: filterTypedRelations(relations, query)
5833
+ relations: filterTypedRelations(relations, {
5834
+ ...query,
5835
+ status: resolved2.filter
5836
+ })
5336
5837
  };
5337
5838
  }
5338
5839
  async getRelatedValues(sourceTypeCode, sourceValueCode, targetTypeCode, options) {
@@ -5356,7 +5857,18 @@ var S3MetadataProvider = class {
5356
5857
  if (sourceValueCodes.length === 0) {
5357
5858
  return [];
5358
5859
  }
5860
+ const resolved2 = this.valueFilter(options);
5359
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
+ }
5360
5872
  const index = this.cache.getRelationshipIndex();
5361
5873
  const groups = [];
5362
5874
  for (const sourceValueCode of sourceValueCodes) {
@@ -5400,24 +5912,10 @@ var S3MetadataProvider = class {
5400
5912
  if (!file) {
5401
5913
  return null;
5402
5914
  }
5403
- const values = this.resolver.getAll(typeCode).map(
5915
+ const resolved2 = this.valueFilter(options);
5916
+ const values = entriesForStatus(file, resolved2.filter).map(
5404
5917
  (entry) => projectionEntryToMetadataValue(typeCode, entry.code, entry, options?.locale)
5405
5918
  );
5406
- if (options?.includeInactive && file.inactiveRecords) {
5407
- const seen = new Set(values.map((value) => value.valueCode));
5408
- for (const [valueCode, record] of Object.entries(file.inactiveRecords)) {
5409
- if (seen.has(valueCode)) {
5410
- continue;
5411
- }
5412
- const entry = latestProjectionEntry(record);
5413
- if (!entry) {
5414
- continue;
5415
- }
5416
- values.push(
5417
- projectionEntryToMetadataValue(typeCode, valueCode, entry, options.locale)
5418
- );
5419
- }
5420
- }
5421
5919
  return {
5422
5920
  releaseId: this.cache.getReleaseId(),
5423
5921
  values,
@@ -5476,15 +5974,21 @@ var S3MetadataProvider = class {
5476
5974
  const releaseId = await this.prepareDiscoveryRead(query.readPolicy, query.releaseId);
5477
5975
  const relations = this.cache.getTypedRelations();
5478
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
+ }
5479
5981
  const listed = resolvePublishedRelationshipQuery({
5480
5982
  typedSupported: relations !== void 0,
5481
5983
  relations: relations ?? [],
5984
+ index: this.cache.getTypedRelationIndex(),
5482
5985
  relationshipIndex,
5483
5986
  sourceTypeCode: query.sourceTypeCode,
5484
5987
  sourceValueCode: query.sourceValueCode,
5485
5988
  targetTypeCode: query.targetTypeCode,
5486
5989
  relationType: query.relationType,
5487
- direction: query.direction
5990
+ direction: query.direction,
5991
+ status: resolved2.filter
5488
5992
  });
5489
5993
  if (!listed.ok) {
5490
5994
  throwPublishedListFailure(listed);
@@ -5528,13 +6032,26 @@ var S3MetadataProvider = class {
5528
6032
  "METADATA_TYPE_INCOMPLETE"
5529
6033
  );
5530
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
+ }
5531
6048
  const extracted = entriesFromProjectionFile(file);
5532
6049
  if (!extracted.ok) {
5533
6050
  throwPublishedListFailure(extracted);
5534
6051
  }
5535
6052
  const listed = listPublishedValues(extracted.entries, {
5536
6053
  releaseId,
5537
- status: options?.status,
6054
+ status: projectionStatusLiterals(resolved2.filter),
5538
6055
  limit: options?.limit,
5539
6056
  cursor: options?.cursor,
5540
6057
  sortBy: options?.sortBy,
@@ -5563,6 +6080,109 @@ var S3MetadataProvider = class {
5563
6080
  this.cache.getCommon()?.types.some((type) => type.metadataTypeCode === typeCode)
5564
6081
  );
5565
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
+ }
5566
6186
  };
5567
6187
  function relatedValueCodes(index, sourceTypeCode, sourceValueCode, targetTypeCode) {
5568
6188
  if (!index) {
@@ -5599,9 +6219,6 @@ function typeCatalogFromProjection(typeCode, file, common) {
5599
6219
  status: ""
5600
6220
  };
5601
6221
  }
5602
- function latestProjectionEntry(record) {
5603
- return record.versions[String(record.latestVersion)];
5604
- }
5605
6222
  function relatedValueCodesFromEntry(resolver, sourceTypeCode, sourceValueCode, targetTypeCode) {
5606
6223
  try {
5607
6224
  const entry = resolver.resolve(sourceTypeCode, sourceValueCode);
@@ -6144,8 +6761,9 @@ var RuntimeMetadataService = class {
6144
6761
  return this.healthService.isHealthy();
6145
6762
  }
6146
6763
  async getValue(typeCode, valueCode, options) {
6764
+ let provider;
6147
6765
  try {
6148
- const provider = await this.activeProvider();
6766
+ provider = await this.activeProvider();
6149
6767
  const guard = this.currentWriteGuard();
6150
6768
  const value = await provider.getValue(typeCode, valueCode, options);
6151
6769
  this.hydrateProviderValues(value ? [value] : [], guard);
@@ -6157,7 +6775,7 @@ var RuntimeMetadataService = class {
6157
6775
  });
6158
6776
  return value;
6159
6777
  } catch (err) {
6160
- if (await this.tryActivateFallbackFromError(err, "extension-lookup")) {
6778
+ if (await this.tryActivateFallbackFromError(err, "extension-lookup", provider)) {
6161
6779
  const fallback = this.metadataProviderFallback;
6162
6780
  if (fallback) {
6163
6781
  return fallback.getValue(typeCode, valueCode, options);
@@ -6167,8 +6785,9 @@ var RuntimeMetadataService = class {
6167
6785
  }
6168
6786
  }
6169
6787
  async batchGet(references, options) {
6788
+ let provider;
6170
6789
  try {
6171
- const provider = await this.activeProvider();
6790
+ provider = await this.activeProvider();
6172
6791
  const generationAtStart = this.cache.getGeneration();
6173
6792
  const result = await provider.batchGet(references, options);
6174
6793
  this.logger.info({
@@ -6180,7 +6799,7 @@ var RuntimeMetadataService = class {
6180
6799
  transport: this.providerCoordinator.getActiveKind(),
6181
6800
  releaseId: result.releaseId
6182
6801
  });
6183
- if (result.unavailable && this.metadataProviderFallback && this.usesExtensionTransport()) {
6802
+ if (result.unavailable && this.metadataProviderFallback && provider !== this.metadataProviderFallback) {
6184
6803
  await this.providerCoordinator.activateFallback("batch-unavailable");
6185
6804
  return this.metadataProviderFallback.batchGet(references, options);
6186
6805
  }
@@ -6194,7 +6813,7 @@ var RuntimeMetadataService = class {
6194
6813
  );
6195
6814
  return result;
6196
6815
  } catch (err) {
6197
- if (await this.tryActivateFallbackFromError(err, "batch-unavailable")) {
6816
+ if (await this.tryActivateFallbackFromError(err, "batch-unavailable", provider)) {
6198
6817
  const fallback = this.metadataProviderFallback;
6199
6818
  if (fallback) {
6200
6819
  return fallback.batchGet(references, options);
@@ -6204,8 +6823,9 @@ var RuntimeMetadataService = class {
6204
6823
  }
6205
6824
  }
6206
6825
  async getRelatedValues(sourceTypeCode, sourceValueCode, targetTypeCode, options) {
6826
+ let provider;
6207
6827
  try {
6208
- const provider = await this.activeProvider();
6828
+ provider = await this.activeProvider();
6209
6829
  const guard = this.currentWriteGuard();
6210
6830
  const values = await provider.getRelatedValues(
6211
6831
  sourceTypeCode,
@@ -6216,7 +6836,7 @@ var RuntimeMetadataService = class {
6216
6836
  this.hydrateProviderValues(values, guard);
6217
6837
  return values;
6218
6838
  } catch (err) {
6219
- if (await this.tryActivateFallbackFromError(err, "extension-related")) {
6839
+ if (await this.tryActivateFallbackFromError(err, "extension-related", provider)) {
6220
6840
  const fallback = this.metadataProviderFallback;
6221
6841
  if (fallback) {
6222
6842
  return fallback.getRelatedValues(
@@ -6261,15 +6881,16 @@ var RuntimeMetadataService = class {
6261
6881
  }
6262
6882
  }
6263
6883
  async listRelations(query) {
6884
+ let provider;
6264
6885
  try {
6265
- const provider = await this.activeProvider();
6886
+ provider = await this.activeProvider();
6266
6887
  const listed = await provider.listRelations(query);
6267
6888
  if (!listed.supported && this.metadataProviderFallback && provider !== this.metadataProviderFallback) {
6268
6889
  return this.metadataProviderFallback.listRelations(query);
6269
6890
  }
6270
6891
  return listed;
6271
6892
  } catch (err) {
6272
- if (await this.tryActivateFallbackFromError(err, "extension-relations")) {
6893
+ if (await this.tryActivateFallbackFromError(err, "extension-relations", provider)) {
6273
6894
  const fallback = this.metadataProviderFallback;
6274
6895
  if (fallback) {
6275
6896
  return fallback.listRelations(query);
@@ -6279,14 +6900,15 @@ var RuntimeMetadataService = class {
6279
6900
  }
6280
6901
  }
6281
6902
  async listTypeValues(typeCode, options) {
6903
+ let provider;
6282
6904
  try {
6283
- const provider = await this.activeProvider();
6905
+ provider = await this.activeProvider();
6284
6906
  const guard = this.currentWriteGuard();
6285
6907
  const listed = await provider.listTypeValues(typeCode, options);
6286
6908
  this.hydrateProviderValues(listed?.values ?? [], guard);
6287
6909
  return listed;
6288
6910
  } catch (err) {
6289
- if (await this.tryActivateFallbackFromError(err, "extension-list")) {
6911
+ if (await this.tryActivateFallbackFromError(err, "extension-list", provider)) {
6290
6912
  const fallback = this.metadataProviderFallback;
6291
6913
  if (fallback) {
6292
6914
  return fallback.listTypeValues(typeCode, options);
@@ -6580,10 +7202,13 @@ var RuntimeMetadataService = class {
6580
7202
  releaseId: err.metadata?.releaseId
6581
7203
  });
6582
7204
  }
6583
- async tryActivateFallbackFromError(err, reason) {
6584
- if (!(err instanceof MetadataProjectionUnavailableError) || !this.metadataProviderFallback || !this.usesExtensionTransport()) {
7205
+ async tryActivateFallbackFromError(err, reason, failedProvider) {
7206
+ if (!(err instanceof MetadataProjectionUnavailableError) || !this.metadataProviderFallback || failedProvider === this.metadataProviderFallback) {
6585
7207
  return false;
6586
7208
  }
7209
+ if (!this.usesExtensionTransport()) {
7210
+ return this.metadataProviderKind === METADATA_PROVIDER_KIND.EXTENSION;
7211
+ }
6587
7212
  await this.providerCoordinator.activateFallback(reason);
6588
7213
  return true;
6589
7214
  }
@@ -6707,27 +7332,23 @@ var InMemoryMetadataProvider = class {
6707
7332
  byKey = /* @__PURE__ */ new Map();
6708
7333
  related = /* @__PURE__ */ new Map();
6709
7334
  relations;
7335
+ typedRelationIndex;
6710
7336
  knownTypeCodes = /* @__PURE__ */ new Set();
7337
+ lifecycleSupported;
7338
+ activeByType = /* @__PURE__ */ new Map();
7339
+ inactiveByType = /* @__PURE__ */ new Map();
6711
7340
  constructor(options = {}) {
6712
7341
  this.releaseId = options.releaseId ?? "memory";
6713
7342
  this.unavailable = options.unavailable === true;
7343
+ this.lifecycleSupported = options.lifecycleSupported !== false;
6714
7344
  this.relations = options.relations;
7345
+ this.typedRelationIndex = options.relations ? buildTypedRelationIndex(options.relations) : void 0;
6715
7346
  for (const typeCode of options.knownTypeCodes ?? []) {
6716
7347
  if (typeCode.trim()) {
6717
7348
  this.knownTypeCodes.add(typeCode.trim());
6718
7349
  }
6719
7350
  }
6720
- for (const record of options.records ?? []) {
6721
- const key = formatMetadataReference(record.typeCode, record.valueCode);
6722
- this.byKey.set(key, record);
6723
- if (record.related) {
6724
- const byTarget = /* @__PURE__ */ new Map();
6725
- for (const [targetType, values] of Object.entries(record.related)) {
6726
- byTarget.set(targetType, [...values]);
6727
- }
6728
- this.related.set(key, byTarget);
6729
- }
6730
- }
7351
+ this.indexRecords(options.records ?? []);
6731
7352
  }
6732
7353
  async isAvailable() {
6733
7354
  return !this.unavailable;
@@ -6742,22 +7363,10 @@ var InMemoryMetadataProvider = class {
6742
7363
  this.forcedState = state;
6743
7364
  }
6744
7365
  replaceRecords(records, releaseId) {
6745
- this.byKey.clear();
6746
- this.related.clear();
6747
7366
  if (releaseId) {
6748
7367
  this.releaseId = releaseId;
6749
7368
  }
6750
- for (const record of records) {
6751
- const key = formatMetadataReference(record.typeCode, record.valueCode);
6752
- this.byKey.set(key, record);
6753
- if (record.related) {
6754
- const byTarget = /* @__PURE__ */ new Map();
6755
- for (const [targetType, values] of Object.entries(record.related)) {
6756
- byTarget.set(targetType, [...values]);
6757
- }
6758
- this.related.set(key, byTarget);
6759
- }
6760
- }
7369
+ this.indexRecords(records);
6761
7370
  }
6762
7371
  async waitUntilReady() {
6763
7372
  return this.getStatus();
@@ -6786,8 +7395,9 @@ var InMemoryMetadataProvider = class {
6786
7395
  { retryable: true }
6787
7396
  );
6788
7397
  }
7398
+ const resolved2 = this.readFilter(options);
6789
7399
  const record = this.byKey.get(formatMetadataReference(typeCode, valueCode));
6790
- if (!record) {
7400
+ if (!record || !statusMatchesFilter(record.entry.status, resolved2.filter)) {
6791
7401
  return null;
6792
7402
  }
6793
7403
  return projectionEntryToMetadataValue(
@@ -6845,13 +7455,26 @@ var InMemoryMetadataProvider = class {
6845
7455
  { retryable: true }
6846
7456
  );
6847
7457
  }
7458
+ const resolved2 = resolveMetadataStatusFilter({ status: query.status });
7459
+ if (!resolved2.ok) {
7460
+ throw new MetadataDiscoveryError(resolved2.message, resolved2.code);
7461
+ }
6848
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
+ }
6849
7469
  return { releaseId: this.releaseId, supported: false, relations: [] };
6850
7470
  }
6851
7471
  return {
6852
7472
  releaseId: this.releaseId,
6853
7473
  supported: true,
6854
- relations: filterTypedRelations(this.relations, query)
7474
+ relations: filterTypedRelations(this.relations, {
7475
+ ...query,
7476
+ status: resolved2.filter
7477
+ })
6855
7478
  };
6856
7479
  }
6857
7480
  async getRelatedValues(sourceTypeCode, sourceValueCode, targetTypeCode, options) {
@@ -6888,11 +7511,49 @@ var InMemoryMetadataProvider = class {
6888
7511
  return groups;
6889
7512
  }
6890
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
+ }
6891
7549
  const sourceKey = formatMetadataReference(sourceTypeCode, sourceValueCode);
6892
7550
  const targets = this.related.get(sourceKey)?.get(targetTypeCode) ?? [];
6893
7551
  const values = [];
6894
7552
  for (const valueCode of targets) {
6895
- const value = await this.getValue(targetTypeCode, valueCode, options);
7553
+ const value = await this.getValue(targetTypeCode, valueCode, {
7554
+ locale: options?.locale,
7555
+ status: METADATA_STATUS_FILTER.ACTIVE
7556
+ });
6896
7557
  if (value) {
6897
7558
  values.push(value);
6898
7559
  }
@@ -6906,19 +7567,18 @@ var InMemoryMetadataProvider = class {
6906
7567
  { retryable: true }
6907
7568
  );
6908
7569
  }
7570
+ if (!this.hasType(typeCode)) {
7571
+ return null;
7572
+ }
7573
+ const resolved2 = this.readFilter(options);
7574
+ const records = this.recordsForFilter(typeCode, resolved2.filter);
6909
7575
  const values = [];
6910
- for (const record of this.byKey.values()) {
6911
- if (record.typeCode !== typeCode) {
6912
- continue;
6913
- }
7576
+ for (const record of records) {
6914
7577
  const value = await this.getValue(record.typeCode, record.valueCode, options);
6915
7578
  if (value) {
6916
7579
  values.push(value);
6917
7580
  }
6918
7581
  }
6919
- if (values.length === 0) {
6920
- return null;
6921
- }
6922
7582
  return {
6923
7583
  releaseId: this.releaseId,
6924
7584
  values,
@@ -6978,14 +7638,20 @@ var InMemoryMetadataProvider = class {
6978
7638
  }
6979
7639
  async getRelationships(query) {
6980
7640
  this.assertReadable(query.readPolicy, query.releaseId);
7641
+ const resolved2 = resolveMetadataStatusFilter({ status: query.status });
7642
+ if (!resolved2.ok) {
7643
+ throw new MetadataDiscoveryError(resolved2.message, resolved2.code);
7644
+ }
6981
7645
  const listed = resolvePublishedRelationshipQuery({
6982
7646
  typedSupported: this.relations !== void 0,
6983
7647
  relations: this.relations ?? [],
7648
+ index: this.typedRelationIndex,
6984
7649
  sourceTypeCode: query.sourceTypeCode,
6985
7650
  sourceValueCode: query.sourceValueCode,
6986
7651
  targetTypeCode: query.targetTypeCode,
6987
7652
  relationType: query.relationType,
6988
- direction: query.direction
7653
+ direction: query.direction,
7654
+ status: resolved2.filter
6989
7655
  });
6990
7656
  if (!listed.ok) {
6991
7657
  throwPublishedListFailure(listed);
@@ -7000,10 +7666,22 @@ var InMemoryMetadataProvider = class {
7000
7666
  if (!this.hasType(typeCode)) {
7001
7667
  throw new UnknownMetadataTypeError(typeCode);
7002
7668
  }
7003
- const entries = [...this.byKey.values()].filter((record) => record.typeCode === typeCode).map((record) => record.entry);
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
+ );
7004
7682
  const listed = listPublishedValues(entries, {
7005
7683
  releaseId: this.releaseId,
7006
- status: options?.status,
7684
+ status: projectionStatusLiterals(resolved2.filter),
7007
7685
  limit: options?.limit,
7008
7686
  cursor: options?.cursor,
7009
7687
  sortBy: options?.sortBy,
@@ -7032,6 +7710,55 @@ var InMemoryMetadataProvider = class {
7032
7710
  }
7033
7711
  return false;
7034
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
+ }
7035
7762
  assertReadable(readPolicy, releaseId) {
7036
7763
  if (this.unavailable) {
7037
7764
  throw new MetadataProjectionUnavailableError(