@myvitalrx/metadata-runtime 1.11.0 → 1.13.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
@@ -898,7 +898,26 @@ z.object({
898
898
  * Optional storage key prefix hint for adapters (not used by pure build).
899
899
  * Callers may also pass prefix directly to {@link S3ProjectionStorage}.
900
900
  */
901
- storagePrefix: z.string().min(1).optional()
901
+ storagePrefix: z.string().min(1).optional(),
902
+ /**
903
+ * Maximum unresolved non-authorization relationships that may be omitted
904
+ * from one release. Above this count, publication fails.
905
+ * The worker parses `PROJECTION_MAX_EXCLUDED_RELATIONSHIPS`.
906
+ */
907
+ maxExcludedRelationships: z.number().int().nonnegative().optional(),
908
+ /**
909
+ * Maximum percentage of the relationship collection that may be omitted.
910
+ * Above this share, publication fails so an incomplete snapshot is not
911
+ * treated as a successful release. Integer 0–100.
912
+ */
913
+ maxExcludedRelationshipPercent: z.number().int().min(0).max(100).optional(),
914
+ /**
915
+ * When true, unresolved Role, Module, Feature, and PermissionAction
916
+ * relationships are excluded under the same thresholds. Default false:
917
+ * those relationships still fail the release.
918
+ * The worker parses `PROJECTION_ALLOW_UNRESOLVED_AUTHORIZATION_RELATIONS`.
919
+ */
920
+ allowUnresolvedAuthorizationRelations: z.boolean().optional()
902
921
  });
903
922
 
904
923
  // ../../libs/metadata-projection/src/lib/errors/ProjectionError.ts
@@ -1430,6 +1449,10 @@ var manifestSchema = z.object({
1430
1449
  ),
1431
1450
  metadataTypes: z.record(z.string(), metadataTypeEntrySchema),
1432
1451
  lookupIndex: z.record(z.string(), lookupIndexEntrySchema),
1452
+ lifecycle: z.object({
1453
+ values: z.literal("activeAndInactive"),
1454
+ relations: z.literal("activeAndInactive")
1455
+ }).optional(),
1433
1456
  revision: z.string().min(1),
1434
1457
  schemaVersion: z.number().int().positive()
1435
1458
  });
@@ -1586,15 +1609,230 @@ var ProjectionPathBuilder = class {
1586
1609
  }
1587
1610
  };
1588
1611
 
1612
+ // ../../libs/metadata-projection/src/lib/lifecycle/metadataLifecycle.ts
1613
+ var METADATA_STATUS = {
1614
+ ACTIVE: "ACTIVE",
1615
+ INACTIVE: "INACTIVE"
1616
+ };
1617
+ var METADATA_STATUS_FILTER = {
1618
+ ACTIVE: "ACTIVE",
1619
+ INACTIVE: "INACTIVE",
1620
+ ALL: "ALL"
1621
+ };
1622
+ var PROJECTION_LIFECYCLE_COVERAGE = "activeAndInactive";
1623
+ var METADATA_LIFECYCLE_UNSUPPORTED = "METADATA_LIFECYCLE_UNSUPPORTED";
1624
+ var ACTIVE_TOKENS = /* @__PURE__ */ new Set(["ACTIVE", "active"]);
1625
+ var INACTIVE_TOKENS = /* @__PURE__ */ new Set(["INACTIVE", "inactive"]);
1626
+ var ALL_TOKENS = /* @__PURE__ */ new Set(["ALL", "all"]);
1627
+ function canonicalMetadataStatus(status) {
1628
+ const token = status?.trim() ?? "";
1629
+ if (ACTIVE_TOKENS.has(token)) {
1630
+ return METADATA_STATUS.ACTIVE;
1631
+ }
1632
+ if (INACTIVE_TOKENS.has(token)) {
1633
+ return METADATA_STATUS.INACTIVE;
1634
+ }
1635
+ return void 0;
1636
+ }
1637
+ function statusMatchesFilter(status, filter = METADATA_STATUS_FILTER.ACTIVE) {
1638
+ const canonical = canonicalMetadataStatus(status);
1639
+ if (!canonical) {
1640
+ return false;
1641
+ }
1642
+ if (filter === METADATA_STATUS_FILTER.ALL) {
1643
+ return true;
1644
+ }
1645
+ return canonical === filter;
1646
+ }
1647
+ function resolveMetadataStatusFilter(input) {
1648
+ const explicit = normalizeExplicitStatus(input.status);
1649
+ if (explicit && !explicit.ok) {
1650
+ return explicit;
1651
+ }
1652
+ if (input.includeInactive === true) {
1653
+ if (explicit?.ok && explicit.filter !== METADATA_STATUS_FILTER.ALL) {
1654
+ return {
1655
+ ok: false,
1656
+ code: "METADATA_DISCOVERY_INVALID",
1657
+ message: "includeInactive cannot be combined with a different status filter"
1658
+ };
1659
+ }
1660
+ return {
1661
+ ok: true,
1662
+ filter: METADATA_STATUS_FILTER.ALL,
1663
+ enforceCapability: explicit?.ok === true
1664
+ };
1665
+ }
1666
+ if (explicit?.ok) {
1667
+ return explicit;
1668
+ }
1669
+ return {
1670
+ ok: true,
1671
+ filter: METADATA_STATUS_FILTER.ACTIVE,
1672
+ enforceCapability: false
1673
+ };
1674
+ }
1675
+ function projectionStatusLiterals(filter) {
1676
+ if (filter === METADATA_STATUS_FILTER.ALL) {
1677
+ return void 0;
1678
+ }
1679
+ if (filter === METADATA_STATUS_FILTER.INACTIVE) {
1680
+ return ["inactive", "INACTIVE"];
1681
+ }
1682
+ return ["active", "ACTIVE"];
1683
+ }
1684
+ function lifecycleQueryFailure(filter, supported) {
1685
+ if (filter === METADATA_STATUS_FILTER.ACTIVE || supported) {
1686
+ return void 0;
1687
+ }
1688
+ return {
1689
+ code: METADATA_LIFECYCLE_UNSUPPORTED,
1690
+ message: "This projection release does not publish inactive lifecycle records. An INACTIVE or ALL query cannot be answered from active-only artifacts."
1691
+ };
1692
+ }
1693
+ function inactiveValuesPublished(lifecycle) {
1694
+ return lifecycle?.values === PROJECTION_LIFECYCLE_COVERAGE;
1695
+ }
1696
+ function normalizeExplicitStatus(status) {
1697
+ if (status === void 0) {
1698
+ return void 0;
1699
+ }
1700
+ const raw = Array.isArray(status) ? [...status] : [status];
1701
+ const tokens = raw.map((value) => value.trim()).filter(Boolean);
1702
+ if (tokens.length === 0) {
1703
+ return {
1704
+ ok: false,
1705
+ code: "METADATA_DISCOVERY_INVALID",
1706
+ message: "status filter must contain at least one status"
1707
+ };
1708
+ }
1709
+ let sawActive = false;
1710
+ let sawInactive = false;
1711
+ let sawAll = false;
1712
+ for (const token of tokens) {
1713
+ if (ALL_TOKENS.has(token)) {
1714
+ sawAll = true;
1715
+ continue;
1716
+ }
1717
+ if (ACTIVE_TOKENS.has(token)) {
1718
+ sawActive = true;
1719
+ continue;
1720
+ }
1721
+ if (INACTIVE_TOKENS.has(token)) {
1722
+ sawInactive = true;
1723
+ continue;
1724
+ }
1725
+ return {
1726
+ ok: false,
1727
+ code: "METADATA_DISCOVERY_INVALID",
1728
+ message: `Unsupported metadata status ${token}`
1729
+ };
1730
+ }
1731
+ if (sawAll || sawActive && sawInactive) {
1732
+ return {
1733
+ ok: true,
1734
+ filter: METADATA_STATUS_FILTER.ALL,
1735
+ enforceCapability: true
1736
+ };
1737
+ }
1738
+ if (sawInactive) {
1739
+ return {
1740
+ ok: true,
1741
+ filter: METADATA_STATUS_FILTER.INACTIVE,
1742
+ enforceCapability: true
1743
+ };
1744
+ }
1745
+ return {
1746
+ ok: true,
1747
+ filter: METADATA_STATUS_FILTER.ACTIVE,
1748
+ enforceCapability: false
1749
+ };
1750
+ }
1751
+
1589
1752
  // ../../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;
1753
+ var FIELD_SEPARATOR = "\0";
1754
+ var builtIndexes = /* @__PURE__ */ new WeakMap();
1755
+ function typedRelationEndpointKey(typeCode, valueCode) {
1756
+ return `${typeCode}${FIELD_SEPARATOR}${valueCode}`;
1757
+ }
1758
+ function isCompleteTypedRelation(relation) {
1759
+ return Boolean(
1760
+ 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()
1761
+ );
1762
+ }
1763
+ function buildTypedRelationIndex(relations) {
1764
+ const outgoing = /* @__PURE__ */ new Map();
1765
+ const incoming = /* @__PURE__ */ new Map();
1766
+ const outgoingByStatus = emptyStatusBuckets();
1767
+ const incomingByStatus = emptyStatusBuckets();
1768
+ let complete = true;
1769
+ for (const relation of relations) {
1770
+ if (!isCompleteTypedRelation(relation)) {
1771
+ complete = false;
1772
+ continue;
1594
1773
  }
1595
- if (relation.fromMetadataValueCode !== query.fromValue) {
1596
- return false;
1774
+ const fromKey = typedRelationEndpointKey(
1775
+ relation.fromMetadataTypeCode,
1776
+ relation.fromMetadataValueCode
1777
+ );
1778
+ const toKey = typedRelationEndpointKey(
1779
+ relation.toMetadataTypeCode,
1780
+ relation.toMetadataValueCode
1781
+ );
1782
+ appendBucket(outgoing, fromKey, relation);
1783
+ appendBucket(incoming, toKey, relation);
1784
+ const status = canonicalMetadataStatus(relation.status);
1785
+ if (!status) {
1786
+ continue;
1597
1787
  }
1788
+ appendBucket(outgoingByStatus.get(status), fromKey, relation);
1789
+ appendBucket(incomingByStatus.get(status), toKey, relation);
1790
+ }
1791
+ return {
1792
+ complete,
1793
+ outgoing,
1794
+ incoming,
1795
+ outgoingByStatus,
1796
+ incomingByStatus
1797
+ };
1798
+ }
1799
+ function typedRelationsForEndpoint(index, direction, endpointKey, filter = METADATA_STATUS_FILTER.ACTIVE) {
1800
+ const byStatus = direction === "INCOMING" ? index.incomingByStatus : index.outgoingByStatus;
1801
+ if (filter === METADATA_STATUS_FILTER.ALL) {
1802
+ return [
1803
+ ...byStatus.get(METADATA_STATUS.ACTIVE)?.get(endpointKey) ?? [],
1804
+ ...byStatus.get(METADATA_STATUS.INACTIVE)?.get(endpointKey) ?? []
1805
+ ];
1806
+ }
1807
+ return byStatus.get(filter)?.get(endpointKey) ?? [];
1808
+ }
1809
+ function typedRelationIndexFor(relations, index) {
1810
+ if (index) {
1811
+ return index;
1812
+ }
1813
+ const cached = builtIndexes.get(relations);
1814
+ if (cached) {
1815
+ return cached;
1816
+ }
1817
+ const built = buildTypedRelationIndex(relations);
1818
+ builtIndexes.set(relations, built);
1819
+ return built;
1820
+ }
1821
+ function filterTypedRelations(relations, query, index) {
1822
+ const resolved2 = typedRelationIndexFor(relations, index);
1823
+ const filter = query.status ?? METADATA_STATUS_FILTER.ACTIVE;
1824
+ if (!resolved2.complete) {
1825
+ return relations.filter(
1826
+ (relation) => matchesForward(relation, query) && statusMatchesRelation(relation, filter)
1827
+ );
1828
+ }
1829
+ const bucket = typedRelationsForEndpoint(
1830
+ resolved2,
1831
+ "OUTGOING",
1832
+ typedRelationEndpointKey(query.fromType, query.fromValue),
1833
+ filter
1834
+ );
1835
+ return bucket.filter((relation) => {
1598
1836
  if (query.relationType && relation.relationType !== query.relationType) {
1599
1837
  return false;
1600
1838
  }
@@ -1604,6 +1842,38 @@ function filterTypedRelations(relations, query) {
1604
1842
  return true;
1605
1843
  });
1606
1844
  }
1845
+ function matchesForward(relation, query) {
1846
+ if (relation.fromMetadataTypeCode !== query.fromType) {
1847
+ return false;
1848
+ }
1849
+ if (relation.fromMetadataValueCode !== query.fromValue) {
1850
+ return false;
1851
+ }
1852
+ if (query.relationType && relation.relationType !== query.relationType) {
1853
+ return false;
1854
+ }
1855
+ if (query.toType && relation.toMetadataTypeCode !== query.toType) {
1856
+ return false;
1857
+ }
1858
+ return true;
1859
+ }
1860
+ function statusMatchesRelation(relation, filter) {
1861
+ return canonicalMetadataStatus(relation.status) === void 0 ? false : filter === METADATA_STATUS_FILTER.ALL || canonicalMetadataStatus(relation.status) === filter;
1862
+ }
1863
+ function emptyStatusBuckets() {
1864
+ return /* @__PURE__ */ new Map([
1865
+ [METADATA_STATUS.ACTIVE, /* @__PURE__ */ new Map()],
1866
+ [METADATA_STATUS.INACTIVE, /* @__PURE__ */ new Map()]
1867
+ ]);
1868
+ }
1869
+ function appendBucket(buckets, key, relation) {
1870
+ const existing = buckets.get(key);
1871
+ if (existing) {
1872
+ existing.push(relation);
1873
+ return;
1874
+ }
1875
+ buckets.set(key, [relation]);
1876
+ }
1607
1877
  function parseTypedRelationshipFile(parsed, expected) {
1608
1878
  const fileName = expected.fileName ?? "typed-relations.json";
1609
1879
  if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
@@ -1682,6 +1952,76 @@ var PUBLISHED_VALUE_LIST_CODE = {
1682
1952
  INVALID: "METADATA_DISCOVERY_INVALID",
1683
1953
  INCOMPLETE: "METADATA_TYPE_INCOMPLETE"
1684
1954
  };
1955
+ function findPublishedEntry(file, valueCode, filter = METADATA_STATUS_FILTER.ACTIVE) {
1956
+ if (!file) {
1957
+ return void 0;
1958
+ }
1959
+ const fromRecords = latestEntry(file.records[valueCode]);
1960
+ const fromInactive = latestEntry(file.inactiveRecords?.[valueCode]);
1961
+ const active = entryWithStatus(fromRecords, METADATA_STATUS.ACTIVE);
1962
+ const inactive = entryWithStatus(fromInactive, METADATA_STATUS.INACTIVE) ?? entryWithStatus(fromRecords, METADATA_STATUS.INACTIVE);
1963
+ if (filter === METADATA_STATUS_FILTER.INACTIVE) {
1964
+ return inactive;
1965
+ }
1966
+ if (filter === METADATA_STATUS_FILTER.ALL) {
1967
+ return active ?? inactive;
1968
+ }
1969
+ return active;
1970
+ }
1971
+ function entriesForStatus(file, filter = METADATA_STATUS_FILTER.ACTIVE) {
1972
+ const entries = [];
1973
+ const seen = /* @__PURE__ */ new Set();
1974
+ if (filter !== METADATA_STATUS_FILTER.INACTIVE) {
1975
+ for (const [valueCode, record] of Object.entries(file.records)) {
1976
+ const entry = latestEntry(record);
1977
+ if (!entry || seen.has(valueCode)) {
1978
+ continue;
1979
+ }
1980
+ if (canonicalMetadataStatus(entry.status) !== METADATA_STATUS.ACTIVE) {
1981
+ continue;
1982
+ }
1983
+ seen.add(valueCode);
1984
+ entries.push(entry);
1985
+ }
1986
+ }
1987
+ if (filter !== METADATA_STATUS_FILTER.ACTIVE) {
1988
+ for (const [valueCode, record] of Object.entries(file.records)) {
1989
+ if (seen.has(valueCode)) {
1990
+ continue;
1991
+ }
1992
+ const entry = entryWithStatus(latestEntry(record), METADATA_STATUS.INACTIVE);
1993
+ if (!entry) {
1994
+ continue;
1995
+ }
1996
+ seen.add(valueCode);
1997
+ entries.push(entry);
1998
+ }
1999
+ for (const [valueCode, record] of Object.entries(file.inactiveRecords ?? {})) {
2000
+ if (seen.has(valueCode)) {
2001
+ continue;
2002
+ }
2003
+ const entry = entryWithStatus(latestEntry(record), METADATA_STATUS.INACTIVE);
2004
+ if (!entry) {
2005
+ continue;
2006
+ }
2007
+ seen.add(valueCode);
2008
+ entries.push(entry);
2009
+ }
2010
+ }
2011
+ return entries;
2012
+ }
2013
+ function latestEntry(record) {
2014
+ if (!record) {
2015
+ return void 0;
2016
+ }
2017
+ return record.versions[String(record.latestVersion)];
2018
+ }
2019
+ function entryWithStatus(entry, status) {
2020
+ if (!entry || canonicalMetadataStatus(entry.status) !== status) {
2021
+ return void 0;
2022
+ }
2023
+ return entry;
2024
+ }
1685
2025
  function entriesFromProjectionFile(file) {
1686
2026
  const entries = [];
1687
2027
  const seen = /* @__PURE__ */ new Set();
@@ -2001,20 +2341,30 @@ function queryPublishedRelationships(query) {
2001
2341
  message: "relationship filters must be non-empty strings"
2002
2342
  };
2003
2343
  }
2344
+ const status = resolveRelationshipStatus(query.status);
2345
+ if (!status.ok) {
2346
+ return status;
2347
+ }
2348
+ const index = typedRelationIndexFor(query.relations, query.index);
2349
+ if (!index.complete) {
2350
+ return {
2351
+ ok: false,
2352
+ code: "METADATA_TYPE_INCOMPLETE",
2353
+ message: "Typed relationship catalog contains a row that cannot be queried"
2354
+ };
2355
+ }
2356
+ const sourceKey = typedRelationEndpointKey(sourceTypeCode, sourceValueCode);
2357
+ const bucket = typedRelationsForEndpoint(index, direction, sourceKey, status.filter);
2004
2358
  const seen = /* @__PURE__ */ new Set();
2005
2359
  const relationships = [];
2006
- for (const relation of query.relations) {
2007
- if (!isCompleteRelation(relation)) {
2360
+ for (const relation of bucket) {
2361
+ if (!isCompleteTypedRelation(relation)) {
2008
2362
  return {
2009
2363
  ok: false,
2010
2364
  code: "METADATA_TYPE_INCOMPLETE",
2011
2365
  message: "Typed relationship catalog contains a row that cannot be queried"
2012
2366
  };
2013
2367
  }
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
2368
  if (relationType && relation.relationType !== relationType) {
2019
2369
  continue;
2020
2370
  }
@@ -2070,10 +2420,15 @@ function relationshipKey(relation) {
2070
2420
  relation.permissionActionCode ?? ""
2071
2421
  ].join("\0");
2072
2422
  }
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
- );
2423
+ function resolveRelationshipStatus(status) {
2424
+ const resolved2 = resolveMetadataStatusFilter({ status });
2425
+ if (!resolved2.ok) {
2426
+ return resolved2;
2427
+ }
2428
+ return { ok: true, filter: resolved2.filter };
2429
+ }
2430
+ function lifecycleUnsupported(message) {
2431
+ return { ok: false, code: METADATA_LIFECYCLE_UNSUPPORTED, message };
2077
2432
  }
2078
2433
  function optionalCode(value) {
2079
2434
  if (value === void 0) {
@@ -2097,14 +2452,25 @@ function resolvePublishedRelationshipQuery(input) {
2097
2452
  if (input.typedSupported) {
2098
2453
  return queryPublishedRelationships({
2099
2454
  relations: input.relations,
2455
+ index: input.index,
2100
2456
  sourceTypeCode: input.sourceTypeCode,
2101
2457
  sourceValueCode: input.sourceValueCode,
2102
2458
  targetTypeCode: input.targetTypeCode,
2103
2459
  relationType: input.relationType,
2104
- direction: input.direction
2460
+ direction: input.direction,
2461
+ status: input.status
2105
2462
  });
2106
2463
  }
2107
2464
  if (input.relationshipIndex) {
2465
+ const status2 = resolveRelationshipStatus(input.status);
2466
+ if (!status2.ok) {
2467
+ return status2;
2468
+ }
2469
+ if (status2.filter !== METADATA_STATUS_FILTER.ACTIVE) {
2470
+ return lifecycleUnsupported(
2471
+ "INACTIVE and ALL relationship queries require typed-relations.json"
2472
+ );
2473
+ }
2108
2474
  return queryRelationshipIndex({
2109
2475
  index: input.relationshipIndex,
2110
2476
  sourceTypeCode: input.sourceTypeCode,
@@ -2113,6 +2479,15 @@ function resolvePublishedRelationshipQuery(input) {
2113
2479
  direction: input.direction
2114
2480
  });
2115
2481
  }
2482
+ const status = resolveRelationshipStatus(input.status);
2483
+ if (!status.ok) {
2484
+ return status;
2485
+ }
2486
+ if (status.filter !== METADATA_STATUS_FILTER.ACTIVE) {
2487
+ return lifecycleUnsupported(
2488
+ "INACTIVE and ALL relationship queries require typed-relations.json"
2489
+ );
2490
+ }
2116
2491
  return { ok: true, supported: false, relationships: [] };
2117
2492
  }
2118
2493
  function queryRelationshipIndex(input) {
@@ -3622,6 +3997,9 @@ var MetadataCache = class {
3622
3997
  getTypedRelations() {
3623
3998
  return this.snapshot?.typedRelations;
3624
3999
  }
4000
+ getTypedRelationIndex() {
4001
+ return this.snapshot?.typedRelationIndex;
4002
+ }
3625
4003
  getLocalization(locale) {
3626
4004
  return this.snapshot?.localization?.get(locale);
3627
4005
  }
@@ -3652,6 +4030,7 @@ var MetadataCache = class {
3652
4030
  this.generation += 1;
3653
4031
  const domainFiles = new Map(bundle.domainFiles);
3654
4032
  Object.freeze(domainFiles);
4033
+ const typedRelations = bundle.typedRelations ? Object.freeze([...bundle.typedRelations]) : void 0;
3655
4034
  const snapshot = Object.freeze({
3656
4035
  revision: bundle.releaseId,
3657
4036
  releaseId: bundle.releaseId,
@@ -3664,7 +4043,8 @@ var MetadataCache = class {
3664
4043
  domainFiles,
3665
4044
  common: bundle.common ? Object.freeze({ ...bundle.common }) : void 0,
3666
4045
  relationshipIndex: bundle.relationshipIndex ? Object.freeze({ ...bundle.relationshipIndex }) : void 0,
3667
- typedRelations: bundle.typedRelations ? Object.freeze([...bundle.typedRelations]) : void 0,
4046
+ typedRelations,
4047
+ typedRelationIndex: typedRelations ? buildTypedRelationIndex(typedRelations) : void 0,
3668
4048
  manifest: Object.freeze({
3669
4049
  ...bundle.manifest,
3670
4050
  files: Object.freeze(
@@ -4012,7 +4392,7 @@ var MetadataResolver = class {
4012
4392
  const latest = [];
4013
4393
  for (const record of Object.values(file.records)) {
4014
4394
  const entry = record.versions[String(record.latestVersion)];
4015
- if (entry) {
4395
+ if (entry && canonicalMetadataStatus(entry.status) === METADATA_STATUS.ACTIVE) {
4016
4396
  latest.push(entry);
4017
4397
  }
4018
4398
  }
@@ -4083,7 +4463,11 @@ var MetadataResolver = class {
4083
4463
  return void 0;
4084
4464
  }
4085
4465
  const targetVersion = version !== void 0 ? version : record.latestVersion;
4086
- return record.versions[String(targetVersion)];
4466
+ const entry = record.versions[String(targetVersion)];
4467
+ if (!entry || canonicalMetadataStatus(entry.status) !== METADATA_STATUS.ACTIVE) {
4468
+ return void 0;
4469
+ }
4470
+ return entry;
4087
4471
  }
4088
4472
  requireManifest() {
4089
4473
  const manifest = this.cache.getManifest();
@@ -4354,6 +4738,69 @@ var MetadataHealthService = class {
4354
4738
  }
4355
4739
  };
4356
4740
 
4741
+ // ../../libs/runtime-metadata/src/lib/config/metadataExtensionDefaults.ts
4742
+ var METADATA_EXTENSION_DEFAULTS = {
4743
+ HOST: "127.0.0.1",
4744
+ PORT: 12701,
4745
+ FALLBACK: "s3",
4746
+ RECOVERY_INTERVAL_MS: 2e3,
4747
+ STARTUP_TIMEOUT_MS: 8e3,
4748
+ INVOKE_REFRESH_MS: 3e4,
4749
+ PROJECTION_CHECK_INTERVAL_MS: 3e5,
4750
+ PROJECTIONS_PREFIX: "metadata-projections"
4751
+ };
4752
+ function resolveExtensionHost(env) {
4753
+ const host = env.METADATA_EXTENSION_HOST?.trim();
4754
+ return host || METADATA_EXTENSION_DEFAULTS.HOST;
4755
+ }
4756
+ function resolveExtensionPort(env) {
4757
+ return Number(env.METADATA_EXTENSION_PORT ?? METADATA_EXTENSION_DEFAULTS.PORT);
4758
+ }
4759
+ function resolveExtensionFallback(env) {
4760
+ return env.METADATA_EXTENSION_FALLBACK ?? METADATA_EXTENSION_DEFAULTS.FALLBACK;
4761
+ }
4762
+ function isMetadataExtensionS3FallbackEnabled(env) {
4763
+ return resolveExtensionFallback(env) !== "none";
4764
+ }
4765
+ function resolveExtensionStartupTimeoutMs(env) {
4766
+ if (env.METADATA_EXTENSION_READY_TIMEOUT_MS) {
4767
+ return Number(env.METADATA_EXTENSION_READY_TIMEOUT_MS);
4768
+ }
4769
+ if (env.METADATA_EXTENSION_STARTUP_TIMEOUT_MS) {
4770
+ return Number(env.METADATA_EXTENSION_STARTUP_TIMEOUT_MS);
4771
+ }
4772
+ return METADATA_EXTENSION_DEFAULTS.STARTUP_TIMEOUT_MS;
4773
+ }
4774
+ function resolveExtensionRecoveryIntervalMs(env) {
4775
+ const raw = env?.METADATA_EXTENSION_RECOVERY_INTERVAL_MS;
4776
+ if (!raw) {
4777
+ return METADATA_EXTENSION_DEFAULTS.RECOVERY_INTERVAL_MS;
4778
+ }
4779
+ const parsed = Number(raw);
4780
+ return Number.isFinite(parsed) && parsed >= 0 ? parsed : METADATA_EXTENSION_DEFAULTS.RECOVERY_INTERVAL_MS;
4781
+ }
4782
+ function resolveExtensionInvokeRefreshMs(env = process.env) {
4783
+ const raw = env.METADATA_EXTENSION_INVOKE_REFRESH_MS;
4784
+ if (!raw) {
4785
+ return METADATA_EXTENSION_DEFAULTS.INVOKE_REFRESH_MS;
4786
+ }
4787
+ const parsed = Number(raw);
4788
+ return Number.isFinite(parsed) && parsed >= 0 ? parsed : METADATA_EXTENSION_DEFAULTS.INVOKE_REFRESH_MS;
4789
+ }
4790
+ function resolveProjectionsPrefix(env) {
4791
+ return env.PROJECTION_ROOT_PREFIX ?? env.METADATA_PROJECTIONS_PREFIX ?? METADATA_EXTENSION_DEFAULTS.PROJECTIONS_PREFIX;
4792
+ }
4793
+ function resolveProjectionCheckIntervalMs(env, override) {
4794
+ if (override != null) {
4795
+ return override;
4796
+ }
4797
+ const raw = env.METADATA_PROJECTION_CHECK_INTERVAL_MS;
4798
+ if (raw == null || raw === "") {
4799
+ return METADATA_EXTENSION_DEFAULTS.PROJECTION_CHECK_INTERVAL_MS;
4800
+ }
4801
+ return Number(raw);
4802
+ }
4803
+
4357
4804
  // ../../libs/runtime-metadata/src/lib/provider/MetadataDiscovery.ts
4358
4805
  var METADATA_READ_POLICY = {
4359
4806
  ALLOW_STALE: "ALLOW_STALE",
@@ -4428,6 +4875,7 @@ var ExtensionMetadataProvider = class {
4428
4875
  readyTimeoutMs;
4429
4876
  requestTimeoutMs;
4430
4877
  logger;
4878
+ lifecycleSupport;
4431
4879
  fetchImpl;
4432
4880
  constructor(options) {
4433
4881
  this.baseUrl = options.baseUrl.replace(/\/+$/, "");
@@ -4516,15 +4964,29 @@ var ExtensionMetadataProvider = class {
4516
4964
  lastRefreshAttemptAt: body.lastRefreshAttemptAt ?? null,
4517
4965
  lastSuccessfulRefreshAt: body.lastSuccessfulRefreshAt ?? null,
4518
4966
  cacheAgeMs: typeof body.cacheAgeMs === "number" ? body.cacheAgeMs : null,
4519
- metadataTypes: body.metadataTypes
4967
+ metadataTypes: body.metadataTypes,
4968
+ lifecycle: body.lifecycle ? {
4969
+ values: body.lifecycle.values === true,
4970
+ relations: body.lifecycle.relations === true
4971
+ } : void 0
4520
4972
  };
4521
4973
  }
4522
4974
  async getValue(typeCode, valueCode, options) {
4523
- const localeQuery = options?.locale ? `?locale=${encodeURIComponent(options.locale)}` : "";
4524
- const path = `/v1/metadata/${encodeURIComponent(typeCode)}/${encodeURIComponent(valueCode)}${localeQuery}`;
4975
+ const filter = await this.assertQueryLifecycle("values", options);
4976
+ const path = `/v1/metadata/${encodeURIComponent(typeCode)}/${encodeURIComponent(valueCode)}${metadataQuery(options)}`;
4525
4977
  try {
4526
4978
  const item = await this.requestJson("GET", path);
4527
- return this.toMetadataValue(item, options?.locale);
4979
+ const value = this.toMetadataValue(item, options?.locale);
4980
+ if (value && filter === METADATA_STATUS_FILTER.INACTIVE && !statusMatchesFilter(value.status, METADATA_STATUS_FILTER.INACTIVE)) {
4981
+ throw new MetadataDiscoveryError(
4982
+ "Extension returned a value outside the requested lifecycle filter",
4983
+ METADATA_LIFECYCLE_UNSUPPORTED
4984
+ );
4985
+ }
4986
+ if (value && filter === METADATA_STATUS_FILTER.ACTIVE && !statusMatchesFilter(value.status, "ACTIVE")) {
4987
+ return null;
4988
+ }
4989
+ return value;
4528
4990
  } catch (err) {
4529
4991
  if (isNotFound(err)) {
4530
4992
  return null;
@@ -4598,18 +5060,28 @@ var ExtensionMetadataProvider = class {
4598
5060
  * GET /v1/metadata/{typeCode}. Unknown types are a projection miss (`null`).
4599
5061
  */
4600
5062
  async listTypeValues(typeCode, options) {
5063
+ const filter = await this.assertQueryLifecycle("values", options);
4601
5064
  const params = new URLSearchParams();
4602
5065
  if (options?.locale) {
4603
5066
  params.set("locale", options.locale);
4604
5067
  }
4605
- if (options?.includeInactive) {
5068
+ if (options?.status) {
5069
+ params.set("status", options.status);
5070
+ } else if (options?.includeInactive) {
4606
5071
  params.set("includeInactive", "true");
4607
5072
  }
4608
5073
  const query = params.toString();
4609
5074
  const path = `/v1/metadata/${encodeURIComponent(typeCode)}${query ? `?${query}` : ""}`;
4610
5075
  try {
4611
5076
  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);
5077
+ const mapped = Object.values(body.items ?? {}).map((item) => this.toMetadataValue(item, options?.locale)).filter((item) => item != null);
5078
+ if (filter === METADATA_STATUS_FILTER.INACTIVE && mapped.some((item) => !statusMatchesFilter(item.status, filter))) {
5079
+ throw new MetadataDiscoveryError(
5080
+ "Extension returned values outside the requested lifecycle filter",
5081
+ METADATA_LIFECYCLE_UNSUPPORTED
5082
+ );
5083
+ }
5084
+ const values = filter === METADATA_STATUS_FILTER.ACTIVE ? mapped.filter((item) => statusMatchesFilter(item.status, filter)) : mapped;
4613
5085
  return {
4614
5086
  releaseId: body.releaseId ?? null,
4615
5087
  values,
@@ -4624,15 +5096,18 @@ var ExtensionMetadataProvider = class {
4624
5096
  }
4625
5097
  async listValuesByType(typeCode, options) {
4626
5098
  await this.assertDiscoveryPolicy(options?.readPolicy);
5099
+ const filter = await this.assertQueryLifecycle("values", { status: options?.status });
4627
5100
  const body = await this.requestJson("GET", `/v1/metadata/types/${encodeURIComponent(typeCode)}/values${discoveryQuery(options)}`);
5101
+ const items = Array.isArray(body.items) ? body.items : [];
4628
5102
  return {
4629
5103
  releaseId: body.releaseId ?? null,
4630
- items: Array.isArray(body.items) ? body.items : [],
5104
+ items: listedValueItems(items, filter),
4631
5105
  ...body.nextCursor ? { nextCursor: body.nextCursor } : {}
4632
5106
  };
4633
5107
  }
4634
5108
  async listValuesByTypes(typeCodes, options) {
4635
5109
  await this.assertDiscoveryPolicy(options?.readPolicy);
5110
+ const filter = await this.assertQueryLifecycle("values", { status: options?.status });
4636
5111
  const body = await this.requestJson(
4637
5112
  "POST",
4638
5113
  "/v1/metadata/types/values",
@@ -4643,11 +5118,15 @@ var ExtensionMetadataProvider = class {
4643
5118
  );
4644
5119
  return {
4645
5120
  releaseId: body.releaseId ?? null,
4646
- types: Array.isArray(body.types) ? body.types : []
5121
+ types: (Array.isArray(body.types) ? body.types : []).map((type) => ({
5122
+ ...type,
5123
+ items: listedValueItems(type.items ?? [], filter)
5124
+ }))
4647
5125
  };
4648
5126
  }
4649
5127
  async getRelationships(query) {
4650
5128
  await this.assertDiscoveryPolicy(query.readPolicy);
5129
+ const filter = await this.assertQueryLifecycle("relations", { status: query.status });
4651
5130
  const body = await this.requestJson(
4652
5131
  "POST",
4653
5132
  "/v1/metadata/relationships/query",
@@ -4656,7 +5135,10 @@ var ExtensionMetadataProvider = class {
4656
5135
  return {
4657
5136
  releaseId: body.releaseId ?? null,
4658
5137
  supported: body.supported === true,
4659
- relationships: Array.isArray(body.relationships) ? body.relationships : []
5138
+ relationships: lifecycleRows(
5139
+ Array.isArray(body.relationships) ? body.relationships : [],
5140
+ filter
5141
+ )
4660
5142
  };
4661
5143
  }
4662
5144
  async listRelations(query) {
@@ -4669,12 +5151,19 @@ var ExtensionMetadataProvider = class {
4669
5151
  if (query.toType) {
4670
5152
  params.set("toType", query.toType);
4671
5153
  }
5154
+ const filter = await this.assertQueryLifecycle("relations", { status: query.status });
5155
+ if (query.status) {
5156
+ params.set("status", query.status);
5157
+ }
4672
5158
  try {
4673
5159
  const body = await this.requestJson("GET", `/v1/relations?${params.toString()}`);
4674
5160
  return {
4675
5161
  releaseId: body.releaseId ?? null,
4676
5162
  supported: body.supported === true,
4677
- relations: Array.isArray(body.relations) ? body.relations : []
5163
+ relations: lifecycleRows(
5164
+ Array.isArray(body.relations) ? body.relations : [],
5165
+ filter
5166
+ )
4678
5167
  };
4679
5168
  } catch (err) {
4680
5169
  if (isNotFound(err)) {
@@ -4684,8 +5173,8 @@ var ExtensionMetadataProvider = class {
4684
5173
  }
4685
5174
  }
4686
5175
  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}`;
5176
+ await this.assertQueryLifecycle("values", options);
5177
+ const path = `/v1/related/${encodeURIComponent(sourceTypeCode)}/${encodeURIComponent(sourceValueCode)}/${encodeURIComponent(targetTypeCode)}${metadataQuery(options)}`;
4689
5178
  try {
4690
5179
  const body = await this.requestJson(
4691
5180
  "GET",
@@ -4703,6 +5192,7 @@ var ExtensionMetadataProvider = class {
4703
5192
  if (sourceValueCodes.length === 0) {
4704
5193
  return [];
4705
5194
  }
5195
+ await this.assertQueryLifecycle("values", options);
4706
5196
  const groups = [];
4707
5197
  try {
4708
5198
  for (let offset = 0; offset < sourceValueCodes.length; offset += RELATED_BATCH_LIMIT) {
@@ -4711,7 +5201,8 @@ var ExtensionMetadataProvider = class {
4711
5201
  sourceType: sourceTypeCode,
4712
5202
  sourceValues,
4713
5203
  targetType: targetTypeCode,
4714
- ...options?.locale ? { locale: options.locale } : {}
5204
+ ...options?.locale ? { locale: options.locale } : {},
5205
+ ...options?.status ? { status: options.status } : {}
4715
5206
  });
4716
5207
  for (const group of body.groups ?? []) {
4717
5208
  groups.push({
@@ -4762,6 +5253,7 @@ var ExtensionMetadataProvider = class {
4762
5253
  }
4763
5254
  }
4764
5255
  async requestRefresh(releaseId) {
5256
+ this.lifecycleSupport = void 0;
4765
5257
  const body = await this.requestJson(
4766
5258
  "POST",
4767
5259
  "/v1/refresh",
@@ -4769,6 +5261,32 @@ var ExtensionMetadataProvider = class {
4769
5261
  );
4770
5262
  return body.changed === true;
4771
5263
  }
5264
+ async assertQueryLifecycle(kind, options) {
5265
+ const resolved2 = resolveMetadataStatusFilter({
5266
+ status: options?.status,
5267
+ includeInactive: options?.includeInactive
5268
+ });
5269
+ if (!resolved2.ok) {
5270
+ throw new MetadataDiscoveryError(resolved2.message, resolved2.code);
5271
+ }
5272
+ if (!resolved2.enforceCapability) {
5273
+ return resolved2.filter;
5274
+ }
5275
+ if (!this.lifecycleSupport) {
5276
+ const status = await this.getStatus();
5277
+ this.lifecycleSupport = {
5278
+ values: status.lifecycle?.values === true,
5279
+ relations: status.lifecycle?.relations === true
5280
+ };
5281
+ }
5282
+ if (!this.lifecycleSupport[kind]) {
5283
+ throw new MetadataDiscoveryError(
5284
+ "This projection release does not publish inactive lifecycle records. An INACTIVE or ALL query cannot be answered from active-only artifacts.",
5285
+ METADATA_LIFECYCLE_UNSUPPORTED
5286
+ );
5287
+ }
5288
+ return resolved2.filter;
5289
+ }
4772
5290
  toMetadataValue(item, locale) {
4773
5291
  if (!item?.typeCode || !item.valueCode) {
4774
5292
  return null;
@@ -4856,7 +5374,7 @@ var ExtensionMetadataProvider = class {
4856
5374
  errorBody.actualReleaseId ?? errorBody.releaseId ?? null
4857
5375
  );
4858
5376
  }
4859
- if (code === "METADATA_DISCOVERY_INVALID" || code === "METADATA_TYPE_INCOMPLETE" || code === "METADATA_RELATION_SEMANTICS_UNSUPPORTED") {
5377
+ if (code === "METADATA_DISCOVERY_INVALID" || code === "METADATA_TYPE_INCOMPLETE" || code === "METADATA_RELATION_SEMANTICS_UNSUPPORTED" || code === METADATA_LIFECYCLE_UNSUPPORTED) {
4860
5378
  throw new MetadataDiscoveryError(
4861
5379
  errorBody.message ?? "Metadata discovery request was rejected",
4862
5380
  code
@@ -5011,6 +5529,49 @@ function appendDiscoveryParams(params, options) {
5011
5529
  }
5012
5530
  }
5013
5531
  }
5532
+ function metadataQuery(options) {
5533
+ const params = new URLSearchParams();
5534
+ if (options?.locale) {
5535
+ params.set("locale", options.locale);
5536
+ }
5537
+ if (options?.status) {
5538
+ params.set("status", options.status);
5539
+ } else if (options?.includeInactive) {
5540
+ params.set("includeInactive", "true");
5541
+ }
5542
+ const query = params.toString();
5543
+ return query ? `?${query}` : "";
5544
+ }
5545
+ function listedValueItems(items, filter) {
5546
+ if (filter === METADATA_STATUS_FILTER.ALL) {
5547
+ return [...items];
5548
+ }
5549
+ if (filter === METADATA_STATUS_FILTER.INACTIVE) {
5550
+ if (items.some((item) => !statusMatchesFilter(item.status, filter))) {
5551
+ throw new MetadataDiscoveryError(
5552
+ "Extension returned values outside the requested lifecycle filter",
5553
+ METADATA_LIFECYCLE_UNSUPPORTED
5554
+ );
5555
+ }
5556
+ return [...items];
5557
+ }
5558
+ return items.filter((item) => statusMatchesFilter(item.status, filter));
5559
+ }
5560
+ function lifecycleRows(rows, filter) {
5561
+ if (filter === METADATA_STATUS_FILTER.ALL) {
5562
+ return [...rows];
5563
+ }
5564
+ if (filter === METADATA_STATUS_FILTER.INACTIVE) {
5565
+ if (rows.some((row) => !statusMatchesFilter(row.status, filter))) {
5566
+ throw new MetadataDiscoveryError(
5567
+ "Extension returned relationships outside the requested lifecycle filter",
5568
+ METADATA_LIFECYCLE_UNSUPPORTED
5569
+ );
5570
+ }
5571
+ return [...rows];
5572
+ }
5573
+ return rows.filter((row) => statusMatchesFilter(row.status, filter));
5574
+ }
5014
5575
  function sleep(ms) {
5015
5576
  return new Promise((resolve) => setTimeout(resolve, ms));
5016
5577
  }
@@ -5027,7 +5588,7 @@ var METADATA_PROVIDER_KIND = {
5027
5588
  function selectMetadataProvider(input) {
5028
5589
  const env = input.env ?? process.env;
5029
5590
  if (input.extensionProvider) {
5030
- const fallbackEnabled = (env.METADATA_EXTENSION_FALLBACK ?? "s3") !== "none";
5591
+ const fallbackEnabled = isMetadataExtensionS3FallbackEnabled(env);
5031
5592
  return {
5032
5593
  kind: METADATA_PROVIDER_KIND.EXTENSION,
5033
5594
  provider: input.extensionProvider,
@@ -5036,15 +5597,16 @@ function selectMetadataProvider(input) {
5036
5597
  }
5037
5598
  const extensionEnabled = isExtensionEnabled(env);
5038
5599
  if (extensionEnabled) {
5039
- const port = Number(env.METADATA_EXTENSION_PORT ?? "12701");
5040
- const baseUrl = (env.METADATA_EXTENSION_BASE_URL ?? defaultExtensionBaseUrl(port)).trim();
5600
+ const port = resolveExtensionPort(env);
5601
+ const host = resolveExtensionHost(env);
5602
+ const baseUrl = (env.METADATA_EXTENSION_BASE_URL ?? (host === METADATA_EXTENSION_DEFAULTS.HOST ? defaultExtensionBaseUrl(port) : `http://${host}:${port}`)).trim();
5041
5603
  const extension = new ExtensionMetadataProvider({
5042
5604
  baseUrl,
5043
5605
  logger: input.logger,
5044
5606
  fetchImpl: input.extensionFetch,
5045
- readyTimeoutMs: env.METADATA_EXTENSION_READY_TIMEOUT_MS ? Number(env.METADATA_EXTENSION_READY_TIMEOUT_MS) : void 0
5607
+ readyTimeoutMs: resolveExtensionStartupTimeoutMs(env)
5046
5608
  });
5047
- const fallbackEnabled = (env.METADATA_EXTENSION_FALLBACK ?? "s3") !== "none";
5609
+ const fallbackEnabled = isMetadataExtensionS3FallbackEnabled(env);
5048
5610
  return {
5049
5611
  kind: METADATA_PROVIDER_KIND.EXTENSION,
5050
5612
  provider: extension,
@@ -5083,7 +5645,7 @@ var PROVIDER_TRANSPORT_STATE = {
5083
5645
  EXTENSION_UNAVAILABLE: "EXTENSION_UNAVAILABLE"
5084
5646
  };
5085
5647
  var SERVING_STATES = /* @__PURE__ */ new Set(["READY", "STALE", "DEGRADED"]);
5086
- var DEFAULT_PROVIDER_RECOVERY_COOLDOWN_MS = 2e3;
5648
+ var DEFAULT_PROVIDER_RECOVERY_COOLDOWN_MS = METADATA_EXTENSION_DEFAULTS.RECOVERY_INTERVAL_MS;
5087
5649
  var ProviderFailoverCoordinator = class {
5088
5650
  state;
5089
5651
  recoveryInFlight = null;
@@ -5260,21 +5822,30 @@ var S3MetadataProvider = class {
5260
5822
  };
5261
5823
  }
5262
5824
  async getValue(typeCode, valueCode, options) {
5825
+ const resolved2 = this.valueFilter(options);
5263
5826
  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;
5827
+ if (resolved2.filter === METADATA_STATUS_FILTER.ACTIVE) {
5828
+ try {
5829
+ const entry2 = this.resolver.resolve(typeCode, valueCode, options?.version);
5830
+ return projectionEntryToMetadataValue(
5831
+ typeCode,
5832
+ valueCode,
5833
+ entry2,
5834
+ options?.locale
5835
+ );
5836
+ } catch (err) {
5837
+ if (err instanceof MetadataLookupError) {
5838
+ return null;
5839
+ }
5840
+ throw err;
5275
5841
  }
5276
- throw err;
5277
5842
  }
5843
+ const entry = findPublishedEntry(
5844
+ this.cache.getDomainFile(typeCode),
5845
+ valueCode,
5846
+ resolved2.filter
5847
+ );
5848
+ return entry ? projectionEntryToMetadataValue(typeCode, valueCode, entry, options?.locale) : null;
5278
5849
  }
5279
5850
  async batchGet(references, options) {
5280
5851
  const invalidReferences = [];
@@ -5321,8 +5892,18 @@ var S3MetadataProvider = class {
5321
5892
  };
5322
5893
  }
5323
5894
  async listRelations(query) {
5895
+ const resolved2 = resolveMetadataStatusFilter({ status: query.status });
5896
+ if (!resolved2.ok) {
5897
+ throw new MetadataDiscoveryError(resolved2.message, resolved2.code);
5898
+ }
5324
5899
  const relations = this.cache.getTypedRelations();
5325
5900
  if (!relations) {
5901
+ if (resolved2.filter !== METADATA_STATUS_FILTER.ACTIVE) {
5902
+ throw new MetadataDiscoveryError(
5903
+ "INACTIVE and ALL relationship queries require typed-relations.json",
5904
+ METADATA_LIFECYCLE_UNSUPPORTED
5905
+ );
5906
+ }
5326
5907
  return {
5327
5908
  releaseId: this.cache.getReleaseId(),
5328
5909
  supported: false,
@@ -5332,7 +5913,10 @@ var S3MetadataProvider = class {
5332
5913
  return {
5333
5914
  releaseId: this.cache.getReleaseId(),
5334
5915
  supported: true,
5335
- relations: filterTypedRelations(relations, query)
5916
+ relations: filterTypedRelations(relations, {
5917
+ ...query,
5918
+ status: resolved2.filter
5919
+ })
5336
5920
  };
5337
5921
  }
5338
5922
  async getRelatedValues(sourceTypeCode, sourceValueCode, targetTypeCode, options) {
@@ -5356,7 +5940,18 @@ var S3MetadataProvider = class {
5356
5940
  if (sourceValueCodes.length === 0) {
5357
5941
  return [];
5358
5942
  }
5943
+ const resolved2 = this.valueFilter(options);
5359
5944
  await this.ensureTypesLoaded([sourceTypeCode, targetTypeCode]);
5945
+ if (resolved2.filter !== METADATA_STATUS_FILTER.ACTIVE) {
5946
+ return this.relatedGroupsForStatus(
5947
+ sourceTypeCode,
5948
+ sourceValueCodes,
5949
+ targetTypeCode,
5950
+ resolved2.filter,
5951
+ resolved2.enforceCapability,
5952
+ options
5953
+ );
5954
+ }
5360
5955
  const index = this.cache.getRelationshipIndex();
5361
5956
  const groups = [];
5362
5957
  for (const sourceValueCode of sourceValueCodes) {
@@ -5400,24 +5995,10 @@ var S3MetadataProvider = class {
5400
5995
  if (!file) {
5401
5996
  return null;
5402
5997
  }
5403
- const values = this.resolver.getAll(typeCode).map(
5998
+ const resolved2 = this.valueFilter(options);
5999
+ const values = entriesForStatus(file, resolved2.filter).map(
5404
6000
  (entry) => projectionEntryToMetadataValue(typeCode, entry.code, entry, options?.locale)
5405
6001
  );
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
6002
  return {
5422
6003
  releaseId: this.cache.getReleaseId(),
5423
6004
  values,
@@ -5476,15 +6057,21 @@ var S3MetadataProvider = class {
5476
6057
  const releaseId = await this.prepareDiscoveryRead(query.readPolicy, query.releaseId);
5477
6058
  const relations = this.cache.getTypedRelations();
5478
6059
  const relationshipIndex = this.cache.getRelationshipIndex();
6060
+ const resolved2 = resolveMetadataStatusFilter({ status: query.status });
6061
+ if (!resolved2.ok) {
6062
+ throw new MetadataDiscoveryError(resolved2.message, resolved2.code);
6063
+ }
5479
6064
  const listed = resolvePublishedRelationshipQuery({
5480
6065
  typedSupported: relations !== void 0,
5481
6066
  relations: relations ?? [],
6067
+ index: this.cache.getTypedRelationIndex(),
5482
6068
  relationshipIndex,
5483
6069
  sourceTypeCode: query.sourceTypeCode,
5484
6070
  sourceValueCode: query.sourceValueCode,
5485
6071
  targetTypeCode: query.targetTypeCode,
5486
6072
  relationType: query.relationType,
5487
- direction: query.direction
6073
+ direction: query.direction,
6074
+ status: resolved2.filter
5488
6075
  });
5489
6076
  if (!listed.ok) {
5490
6077
  throwPublishedListFailure(listed);
@@ -5528,13 +6115,26 @@ var S3MetadataProvider = class {
5528
6115
  "METADATA_TYPE_INCOMPLETE"
5529
6116
  );
5530
6117
  }
6118
+ const resolved2 = resolveMetadataStatusFilter({ status: options?.status });
6119
+ if (!resolved2.ok) {
6120
+ throw new MetadataDiscoveryError(resolved2.message, resolved2.code);
6121
+ }
6122
+ if (resolved2.enforceCapability) {
6123
+ const blocked = lifecycleQueryFailure(
6124
+ resolved2.filter,
6125
+ inactiveValuesPublished(this.cache.getManifest()?.lifecycle)
6126
+ );
6127
+ if (blocked) {
6128
+ throw new MetadataDiscoveryError(blocked.message, blocked.code);
6129
+ }
6130
+ }
5531
6131
  const extracted = entriesFromProjectionFile(file);
5532
6132
  if (!extracted.ok) {
5533
6133
  throwPublishedListFailure(extracted);
5534
6134
  }
5535
6135
  const listed = listPublishedValues(extracted.entries, {
5536
6136
  releaseId,
5537
- status: options?.status,
6137
+ status: projectionStatusLiterals(resolved2.filter),
5538
6138
  limit: options?.limit,
5539
6139
  cursor: options?.cursor,
5540
6140
  sortBy: options?.sortBy,
@@ -5563,6 +6163,109 @@ var S3MetadataProvider = class {
5563
6163
  this.cache.getCommon()?.types.some((type) => type.metadataTypeCode === typeCode)
5564
6164
  );
5565
6165
  }
6166
+ valueFilter(options) {
6167
+ const resolved2 = resolveMetadataStatusFilter({
6168
+ status: options?.status,
6169
+ includeInactive: options?.includeInactive
6170
+ });
6171
+ if (!resolved2.ok) {
6172
+ throw new MetadataDiscoveryError(resolved2.message, resolved2.code);
6173
+ }
6174
+ if (resolved2.enforceCapability) {
6175
+ const blocked = lifecycleQueryFailure(
6176
+ resolved2.filter,
6177
+ inactiveValuesPublished(this.cache.getManifest()?.lifecycle)
6178
+ );
6179
+ if (blocked) {
6180
+ throw new MetadataDiscoveryError(blocked.message, blocked.code);
6181
+ }
6182
+ }
6183
+ return resolved2;
6184
+ }
6185
+ async relatedGroupsForStatus(sourceTypeCode, sourceValueCodes, targetTypeCode, filter, enforceCapability, options) {
6186
+ const relations = this.cache.getTypedRelations();
6187
+ if (!relations || !inactiveValuesPublished(this.cache.getManifest()?.lifecycle)) {
6188
+ if (enforceCapability) {
6189
+ throw new MetadataDiscoveryError(
6190
+ "INACTIVE and ALL related-value queries require a lifecycle-aware release",
6191
+ METADATA_LIFECYCLE_UNSUPPORTED
6192
+ );
6193
+ }
6194
+ return this.relatedGroupsFromAdjacency(
6195
+ sourceTypeCode,
6196
+ sourceValueCodes,
6197
+ targetTypeCode,
6198
+ options
6199
+ );
6200
+ }
6201
+ const groups = [];
6202
+ for (const sourceValueCode of sourceValueCodes) {
6203
+ const listed = resolvePublishedRelationshipQuery({
6204
+ typedSupported: true,
6205
+ relations,
6206
+ index: this.cache.getTypedRelationIndex(),
6207
+ sourceTypeCode,
6208
+ sourceValueCode,
6209
+ targetTypeCode,
6210
+ status: filter
6211
+ });
6212
+ if (!listed.ok) {
6213
+ throwPublishedListFailure(listed);
6214
+ }
6215
+ const values = [];
6216
+ const seen = /* @__PURE__ */ new Set();
6217
+ for (const row of listed.relationships) {
6218
+ if (seen.has(row.toMetadataValueCode)) {
6219
+ continue;
6220
+ }
6221
+ seen.add(row.toMetadataValueCode);
6222
+ const value = await this.getValue(targetTypeCode, row.toMetadataValueCode, {
6223
+ ...options,
6224
+ status: filter,
6225
+ includeInactive: void 0
6226
+ });
6227
+ if (value) {
6228
+ values.push(value);
6229
+ }
6230
+ }
6231
+ groups.push({ sourceValueCode, values });
6232
+ }
6233
+ return groups;
6234
+ }
6235
+ async relatedGroupsFromAdjacency(sourceTypeCode, sourceValueCodes, targetTypeCode, options) {
6236
+ const index = this.cache.getRelationshipIndex();
6237
+ const groups = [];
6238
+ for (const sourceValueCode of sourceValueCodes) {
6239
+ const codes = relatedValueCodes(
6240
+ index,
6241
+ sourceTypeCode,
6242
+ sourceValueCode,
6243
+ targetTypeCode
6244
+ );
6245
+ if (codes.length === 0) {
6246
+ codes.push(
6247
+ ...relatedValueCodesFromEntry(
6248
+ this.resolver,
6249
+ sourceTypeCode,
6250
+ sourceValueCode,
6251
+ targetTypeCode
6252
+ )
6253
+ );
6254
+ }
6255
+ const values = [];
6256
+ for (const valueCode of codes) {
6257
+ const value = await this.getValue(targetTypeCode, valueCode, {
6258
+ locale: options?.locale,
6259
+ status: METADATA_STATUS_FILTER.ACTIVE
6260
+ });
6261
+ if (value) {
6262
+ values.push(value);
6263
+ }
6264
+ }
6265
+ groups.push({ sourceValueCode, values });
6266
+ }
6267
+ return groups;
6268
+ }
5566
6269
  };
5567
6270
  function relatedValueCodes(index, sourceTypeCode, sourceValueCode, targetTypeCode) {
5568
6271
  if (!index) {
@@ -5599,9 +6302,6 @@ function typeCatalogFromProjection(typeCode, file, common) {
5599
6302
  status: ""
5600
6303
  };
5601
6304
  }
5602
- function latestProjectionEntry(record) {
5603
- return record.versions[String(record.latestVersion)];
5604
- }
5605
6305
  function relatedValueCodesFromEntry(resolver, sourceTypeCode, sourceValueCode, targetTypeCode) {
5606
6306
  try {
5607
6307
  const entry = resolver.resolve(sourceTypeCode, sourceValueCode);
@@ -6144,8 +6844,9 @@ var RuntimeMetadataService = class {
6144
6844
  return this.healthService.isHealthy();
6145
6845
  }
6146
6846
  async getValue(typeCode, valueCode, options) {
6847
+ let provider;
6147
6848
  try {
6148
- const provider = await this.activeProvider();
6849
+ provider = await this.activeProvider();
6149
6850
  const guard = this.currentWriteGuard();
6150
6851
  const value = await provider.getValue(typeCode, valueCode, options);
6151
6852
  this.hydrateProviderValues(value ? [value] : [], guard);
@@ -6157,7 +6858,7 @@ var RuntimeMetadataService = class {
6157
6858
  });
6158
6859
  return value;
6159
6860
  } catch (err) {
6160
- if (await this.tryActivateFallbackFromError(err, "extension-lookup")) {
6861
+ if (await this.tryActivateFallbackFromError(err, "extension-lookup", provider)) {
6161
6862
  const fallback = this.metadataProviderFallback;
6162
6863
  if (fallback) {
6163
6864
  return fallback.getValue(typeCode, valueCode, options);
@@ -6167,8 +6868,9 @@ var RuntimeMetadataService = class {
6167
6868
  }
6168
6869
  }
6169
6870
  async batchGet(references, options) {
6871
+ let provider;
6170
6872
  try {
6171
- const provider = await this.activeProvider();
6873
+ provider = await this.activeProvider();
6172
6874
  const generationAtStart = this.cache.getGeneration();
6173
6875
  const result = await provider.batchGet(references, options);
6174
6876
  this.logger.info({
@@ -6180,7 +6882,7 @@ var RuntimeMetadataService = class {
6180
6882
  transport: this.providerCoordinator.getActiveKind(),
6181
6883
  releaseId: result.releaseId
6182
6884
  });
6183
- if (result.unavailable && this.metadataProviderFallback && this.usesExtensionTransport()) {
6885
+ if (result.unavailable && this.metadataProviderFallback && provider !== this.metadataProviderFallback) {
6184
6886
  await this.providerCoordinator.activateFallback("batch-unavailable");
6185
6887
  return this.metadataProviderFallback.batchGet(references, options);
6186
6888
  }
@@ -6194,7 +6896,7 @@ var RuntimeMetadataService = class {
6194
6896
  );
6195
6897
  return result;
6196
6898
  } catch (err) {
6197
- if (await this.tryActivateFallbackFromError(err, "batch-unavailable")) {
6899
+ if (await this.tryActivateFallbackFromError(err, "batch-unavailable", provider)) {
6198
6900
  const fallback = this.metadataProviderFallback;
6199
6901
  if (fallback) {
6200
6902
  return fallback.batchGet(references, options);
@@ -6204,8 +6906,9 @@ var RuntimeMetadataService = class {
6204
6906
  }
6205
6907
  }
6206
6908
  async getRelatedValues(sourceTypeCode, sourceValueCode, targetTypeCode, options) {
6909
+ let provider;
6207
6910
  try {
6208
- const provider = await this.activeProvider();
6911
+ provider = await this.activeProvider();
6209
6912
  const guard = this.currentWriteGuard();
6210
6913
  const values = await provider.getRelatedValues(
6211
6914
  sourceTypeCode,
@@ -6216,7 +6919,7 @@ var RuntimeMetadataService = class {
6216
6919
  this.hydrateProviderValues(values, guard);
6217
6920
  return values;
6218
6921
  } catch (err) {
6219
- if (await this.tryActivateFallbackFromError(err, "extension-related")) {
6922
+ if (await this.tryActivateFallbackFromError(err, "extension-related", provider)) {
6220
6923
  const fallback = this.metadataProviderFallback;
6221
6924
  if (fallback) {
6222
6925
  return fallback.getRelatedValues(
@@ -6261,15 +6964,16 @@ var RuntimeMetadataService = class {
6261
6964
  }
6262
6965
  }
6263
6966
  async listRelations(query) {
6967
+ let provider;
6264
6968
  try {
6265
- const provider = await this.activeProvider();
6969
+ provider = await this.activeProvider();
6266
6970
  const listed = await provider.listRelations(query);
6267
6971
  if (!listed.supported && this.metadataProviderFallback && provider !== this.metadataProviderFallback) {
6268
6972
  return this.metadataProviderFallback.listRelations(query);
6269
6973
  }
6270
6974
  return listed;
6271
6975
  } catch (err) {
6272
- if (await this.tryActivateFallbackFromError(err, "extension-relations")) {
6976
+ if (await this.tryActivateFallbackFromError(err, "extension-relations", provider)) {
6273
6977
  const fallback = this.metadataProviderFallback;
6274
6978
  if (fallback) {
6275
6979
  return fallback.listRelations(query);
@@ -6279,14 +6983,15 @@ var RuntimeMetadataService = class {
6279
6983
  }
6280
6984
  }
6281
6985
  async listTypeValues(typeCode, options) {
6986
+ let provider;
6282
6987
  try {
6283
- const provider = await this.activeProvider();
6988
+ provider = await this.activeProvider();
6284
6989
  const guard = this.currentWriteGuard();
6285
6990
  const listed = await provider.listTypeValues(typeCode, options);
6286
6991
  this.hydrateProviderValues(listed?.values ?? [], guard);
6287
6992
  return listed;
6288
6993
  } catch (err) {
6289
- if (await this.tryActivateFallbackFromError(err, "extension-list")) {
6994
+ if (await this.tryActivateFallbackFromError(err, "extension-list", provider)) {
6290
6995
  const fallback = this.metadataProviderFallback;
6291
6996
  if (fallback) {
6292
6997
  return fallback.listTypeValues(typeCode, options);
@@ -6580,21 +7285,19 @@ var RuntimeMetadataService = class {
6580
7285
  releaseId: err.metadata?.releaseId
6581
7286
  });
6582
7287
  }
6583
- async tryActivateFallbackFromError(err, reason) {
6584
- if (!(err instanceof MetadataProjectionUnavailableError) || !this.metadataProviderFallback || !this.usesExtensionTransport()) {
7288
+ async tryActivateFallbackFromError(err, reason, failedProvider) {
7289
+ if (!(err instanceof MetadataProjectionUnavailableError) || !this.metadataProviderFallback || failedProvider === this.metadataProviderFallback) {
6585
7290
  return false;
6586
7291
  }
7292
+ if (!this.usesExtensionTransport()) {
7293
+ return this.metadataProviderKind === METADATA_PROVIDER_KIND.EXTENSION;
7294
+ }
6587
7295
  await this.providerCoordinator.activateFallback(reason);
6588
7296
  return true;
6589
7297
  }
6590
7298
  };
6591
7299
  function recoveryCooldownMs(env) {
6592
- const raw = env?.METADATA_EXTENSION_RECOVERY_INTERVAL_MS;
6593
- if (!raw) {
6594
- return void 0;
6595
- }
6596
- const parsed = Number(raw);
6597
- return Number.isFinite(parsed) && parsed >= 0 ? parsed : void 0;
7300
+ return resolveExtensionRecoveryIntervalMs(env);
6598
7301
  }
6599
7302
 
6600
7303
  // ../../libs/runtime-metadata/src/lib/integration/createRuntimeMetadataFromEnv.ts
@@ -6604,10 +7307,13 @@ function createRuntimeMetadataFromEnv(options) {
6604
7307
  const environment = (options.environment ?? env.PROJECTION_ENVIRONMENT ?? env.STAGE ?? env.NODE_ENV ?? "dev").trim().toLowerCase();
6605
7308
  const config2 = {
6606
7309
  bucket,
6607
- prefix: env.PROJECTION_ROOT_PREFIX ?? env.METADATA_PROJECTIONS_PREFIX,
7310
+ prefix: resolveProjectionsPrefix(env),
6608
7311
  environment,
6609
7312
  revision: options.revision ?? env.METADATA_PROJECTION_REVISION,
6610
- periodicCheckIntervalMs: options.periodicCheckIntervalMs ?? (env.METADATA_PROJECTION_CHECK_INTERVAL_MS ? Number(env.METADATA_PROJECTION_CHECK_INTERVAL_MS) : void 0)
7313
+ periodicCheckIntervalMs: resolveProjectionCheckIntervalMs(
7314
+ env,
7315
+ options.periodicCheckIntervalMs
7316
+ )
6611
7317
  };
6612
7318
  return new RuntimeMetadataService({
6613
7319
  client: options.client,
@@ -6624,7 +7330,6 @@ var metadataServiceInstance;
6624
7330
  var initializePromise;
6625
7331
  var initialized = false;
6626
7332
  var lastUpdateCheckAtMs = 0;
6627
- var UPDATE_CHECK_MIN_INTERVAL_MS = 3e4;
6628
7333
  function getRuntimeMetadataService() {
6629
7334
  if (!isMetadataProjectionConfigured()) {
6630
7335
  throw new Error(
@@ -6665,7 +7370,7 @@ async function ensureRuntimeMetadataLoaded() {
6665
7370
  return;
6666
7371
  }
6667
7372
  const now = Date.now();
6668
- if (now - lastUpdateCheckAtMs < UPDATE_CHECK_MIN_INTERVAL_MS) {
7373
+ if (now - lastUpdateCheckAtMs < resolveExtensionInvokeRefreshMs()) {
6669
7374
  return;
6670
7375
  }
6671
7376
  lastUpdateCheckAtMs = now;
@@ -6707,27 +7412,23 @@ var InMemoryMetadataProvider = class {
6707
7412
  byKey = /* @__PURE__ */ new Map();
6708
7413
  related = /* @__PURE__ */ new Map();
6709
7414
  relations;
7415
+ typedRelationIndex;
6710
7416
  knownTypeCodes = /* @__PURE__ */ new Set();
7417
+ lifecycleSupported;
7418
+ activeByType = /* @__PURE__ */ new Map();
7419
+ inactiveByType = /* @__PURE__ */ new Map();
6711
7420
  constructor(options = {}) {
6712
7421
  this.releaseId = options.releaseId ?? "memory";
6713
7422
  this.unavailable = options.unavailable === true;
7423
+ this.lifecycleSupported = options.lifecycleSupported !== false;
6714
7424
  this.relations = options.relations;
7425
+ this.typedRelationIndex = options.relations ? buildTypedRelationIndex(options.relations) : void 0;
6715
7426
  for (const typeCode of options.knownTypeCodes ?? []) {
6716
7427
  if (typeCode.trim()) {
6717
7428
  this.knownTypeCodes.add(typeCode.trim());
6718
7429
  }
6719
7430
  }
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
- }
7431
+ this.indexRecords(options.records ?? []);
6731
7432
  }
6732
7433
  async isAvailable() {
6733
7434
  return !this.unavailable;
@@ -6742,22 +7443,10 @@ var InMemoryMetadataProvider = class {
6742
7443
  this.forcedState = state;
6743
7444
  }
6744
7445
  replaceRecords(records, releaseId) {
6745
- this.byKey.clear();
6746
- this.related.clear();
6747
7446
  if (releaseId) {
6748
7447
  this.releaseId = releaseId;
6749
7448
  }
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
- }
7449
+ this.indexRecords(records);
6761
7450
  }
6762
7451
  async waitUntilReady() {
6763
7452
  return this.getStatus();
@@ -6786,8 +7475,9 @@ var InMemoryMetadataProvider = class {
6786
7475
  { retryable: true }
6787
7476
  );
6788
7477
  }
7478
+ const resolved2 = this.readFilter(options);
6789
7479
  const record = this.byKey.get(formatMetadataReference(typeCode, valueCode));
6790
- if (!record) {
7480
+ if (!record || !statusMatchesFilter(record.entry.status, resolved2.filter)) {
6791
7481
  return null;
6792
7482
  }
6793
7483
  return projectionEntryToMetadataValue(
@@ -6845,13 +7535,26 @@ var InMemoryMetadataProvider = class {
6845
7535
  { retryable: true }
6846
7536
  );
6847
7537
  }
7538
+ const resolved2 = resolveMetadataStatusFilter({ status: query.status });
7539
+ if (!resolved2.ok) {
7540
+ throw new MetadataDiscoveryError(resolved2.message, resolved2.code);
7541
+ }
6848
7542
  if (!this.relations) {
7543
+ if (resolved2.filter !== METADATA_STATUS_FILTER.ACTIVE) {
7544
+ throw new MetadataDiscoveryError(
7545
+ "INACTIVE and ALL relationship queries require typed-relations.json",
7546
+ METADATA_LIFECYCLE_UNSUPPORTED
7547
+ );
7548
+ }
6849
7549
  return { releaseId: this.releaseId, supported: false, relations: [] };
6850
7550
  }
6851
7551
  return {
6852
7552
  releaseId: this.releaseId,
6853
7553
  supported: true,
6854
- relations: filterTypedRelations(this.relations, query)
7554
+ relations: filterTypedRelations(this.relations, {
7555
+ ...query,
7556
+ status: resolved2.filter
7557
+ })
6855
7558
  };
6856
7559
  }
6857
7560
  async getRelatedValues(sourceTypeCode, sourceValueCode, targetTypeCode, options) {
@@ -6888,11 +7591,49 @@ var InMemoryMetadataProvider = class {
6888
7591
  return groups;
6889
7592
  }
6890
7593
  async relatedValuesFor(sourceTypeCode, sourceValueCode, targetTypeCode, options) {
7594
+ const resolved2 = this.readFilter(options);
7595
+ if (resolved2.filter !== METADATA_STATUS_FILTER.ACTIVE && !this.relations) {
7596
+ if (resolved2.enforceCapability) {
7597
+ throw new MetadataDiscoveryError(
7598
+ "INACTIVE and ALL related-value queries require typed-relations.json",
7599
+ METADATA_LIFECYCLE_UNSUPPORTED
7600
+ );
7601
+ }
7602
+ } else if (resolved2.filter !== METADATA_STATUS_FILTER.ACTIVE && this.relations) {
7603
+ const listed = resolvePublishedRelationshipQuery({
7604
+ typedSupported: true,
7605
+ relations: this.relations,
7606
+ index: this.typedRelationIndex,
7607
+ sourceTypeCode,
7608
+ sourceValueCode,
7609
+ targetTypeCode,
7610
+ status: resolved2.filter
7611
+ });
7612
+ if (!listed.ok) {
7613
+ throw new MetadataDiscoveryError(listed.message, listed.code);
7614
+ }
7615
+ const values2 = [];
7616
+ const seen = /* @__PURE__ */ new Set();
7617
+ for (const row of listed.relationships) {
7618
+ if (seen.has(row.toMetadataValueCode)) {
7619
+ continue;
7620
+ }
7621
+ seen.add(row.toMetadataValueCode);
7622
+ const value = await this.getValue(targetTypeCode, row.toMetadataValueCode, options);
7623
+ if (value) {
7624
+ values2.push(value);
7625
+ }
7626
+ }
7627
+ return values2;
7628
+ }
6891
7629
  const sourceKey = formatMetadataReference(sourceTypeCode, sourceValueCode);
6892
7630
  const targets = this.related.get(sourceKey)?.get(targetTypeCode) ?? [];
6893
7631
  const values = [];
6894
7632
  for (const valueCode of targets) {
6895
- const value = await this.getValue(targetTypeCode, valueCode, options);
7633
+ const value = await this.getValue(targetTypeCode, valueCode, {
7634
+ locale: options?.locale,
7635
+ status: METADATA_STATUS_FILTER.ACTIVE
7636
+ });
6896
7637
  if (value) {
6897
7638
  values.push(value);
6898
7639
  }
@@ -6906,19 +7647,18 @@ var InMemoryMetadataProvider = class {
6906
7647
  { retryable: true }
6907
7648
  );
6908
7649
  }
7650
+ if (!this.hasType(typeCode)) {
7651
+ return null;
7652
+ }
7653
+ const resolved2 = this.readFilter(options);
7654
+ const records = this.recordsForFilter(typeCode, resolved2.filter);
6909
7655
  const values = [];
6910
- for (const record of this.byKey.values()) {
6911
- if (record.typeCode !== typeCode) {
6912
- continue;
6913
- }
7656
+ for (const record of records) {
6914
7657
  const value = await this.getValue(record.typeCode, record.valueCode, options);
6915
7658
  if (value) {
6916
7659
  values.push(value);
6917
7660
  }
6918
7661
  }
6919
- if (values.length === 0) {
6920
- return null;
6921
- }
6922
7662
  return {
6923
7663
  releaseId: this.releaseId,
6924
7664
  values,
@@ -6978,14 +7718,20 @@ var InMemoryMetadataProvider = class {
6978
7718
  }
6979
7719
  async getRelationships(query) {
6980
7720
  this.assertReadable(query.readPolicy, query.releaseId);
7721
+ const resolved2 = resolveMetadataStatusFilter({ status: query.status });
7722
+ if (!resolved2.ok) {
7723
+ throw new MetadataDiscoveryError(resolved2.message, resolved2.code);
7724
+ }
6981
7725
  const listed = resolvePublishedRelationshipQuery({
6982
7726
  typedSupported: this.relations !== void 0,
6983
7727
  relations: this.relations ?? [],
7728
+ index: this.typedRelationIndex,
6984
7729
  sourceTypeCode: query.sourceTypeCode,
6985
7730
  sourceValueCode: query.sourceValueCode,
6986
7731
  targetTypeCode: query.targetTypeCode,
6987
7732
  relationType: query.relationType,
6988
- direction: query.direction
7733
+ direction: query.direction,
7734
+ status: resolved2.filter
6989
7735
  });
6990
7736
  if (!listed.ok) {
6991
7737
  throwPublishedListFailure(listed);
@@ -7000,10 +7746,22 @@ var InMemoryMetadataProvider = class {
7000
7746
  if (!this.hasType(typeCode)) {
7001
7747
  throw new UnknownMetadataTypeError(typeCode);
7002
7748
  }
7003
- const entries = [...this.byKey.values()].filter((record) => record.typeCode === typeCode).map((record) => record.entry);
7749
+ const resolved2 = resolveMetadataStatusFilter({ status: options?.status });
7750
+ if (!resolved2.ok) {
7751
+ throw new MetadataDiscoveryError(resolved2.message, resolved2.code);
7752
+ }
7753
+ if (resolved2.enforceCapability && !this.lifecycleSupported) {
7754
+ throw new MetadataDiscoveryError(
7755
+ "This projection release does not publish inactive lifecycle records. An INACTIVE or ALL query cannot be answered from active-only artifacts.",
7756
+ METADATA_LIFECYCLE_UNSUPPORTED
7757
+ );
7758
+ }
7759
+ const entries = this.recordsForFilter(typeCode, resolved2.filter).map(
7760
+ (record) => record.entry
7761
+ );
7004
7762
  const listed = listPublishedValues(entries, {
7005
7763
  releaseId: this.releaseId,
7006
- status: options?.status,
7764
+ status: projectionStatusLiterals(resolved2.filter),
7007
7765
  limit: options?.limit,
7008
7766
  cursor: options?.cursor,
7009
7767
  sortBy: options?.sortBy,
@@ -7032,6 +7790,55 @@ var InMemoryMetadataProvider = class {
7032
7790
  }
7033
7791
  return false;
7034
7792
  }
7793
+ indexRecords(records) {
7794
+ this.byKey.clear();
7795
+ this.related.clear();
7796
+ this.activeByType.clear();
7797
+ this.inactiveByType.clear();
7798
+ for (const record of records) {
7799
+ const key = formatMetadataReference(record.typeCode, record.valueCode);
7800
+ this.byKey.set(key, record);
7801
+ const bucket = statusMatchesFilter(record.entry.status, METADATA_STATUS_FILTER.INACTIVE) ? this.inactiveByType : this.activeByType;
7802
+ const list = bucket.get(record.typeCode) ?? [];
7803
+ list.push(record);
7804
+ bucket.set(record.typeCode, list);
7805
+ if (record.related) {
7806
+ const byTarget = /* @__PURE__ */ new Map();
7807
+ for (const [targetType, values] of Object.entries(record.related)) {
7808
+ byTarget.set(targetType, [...values]);
7809
+ }
7810
+ this.related.set(key, byTarget);
7811
+ }
7812
+ }
7813
+ }
7814
+ readFilter(options) {
7815
+ const resolved2 = resolveMetadataStatusFilter({
7816
+ status: options?.status,
7817
+ includeInactive: options?.includeInactive
7818
+ });
7819
+ if (!resolved2.ok) {
7820
+ throw new MetadataDiscoveryError(resolved2.message, resolved2.code);
7821
+ }
7822
+ if (resolved2.enforceCapability && !this.lifecycleSupported) {
7823
+ throw new MetadataDiscoveryError(
7824
+ "This projection release does not publish inactive lifecycle records. An INACTIVE or ALL query cannot be answered from active-only artifacts.",
7825
+ METADATA_LIFECYCLE_UNSUPPORTED
7826
+ );
7827
+ }
7828
+ return resolved2;
7829
+ }
7830
+ recordsForFilter(typeCode, filter) {
7831
+ if (filter === METADATA_STATUS_FILTER.INACTIVE) {
7832
+ return this.inactiveByType.get(typeCode) ?? [];
7833
+ }
7834
+ if (filter === METADATA_STATUS_FILTER.ALL) {
7835
+ return [
7836
+ ...this.activeByType.get(typeCode) ?? [],
7837
+ ...this.inactiveByType.get(typeCode) ?? []
7838
+ ];
7839
+ }
7840
+ return this.activeByType.get(typeCode) ?? [];
7841
+ }
7035
7842
  assertReadable(readPolicy, releaseId) {
7036
7843
  if (this.unavailable) {
7037
7844
  throw new MetadataProjectionUnavailableError(