@myvitalrx/metadata-runtime 1.1.0 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +142 -1
- package/dist/index.js +768 -45
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -2,7 +2,7 @@ import { z } from 'zod';
|
|
|
2
2
|
import { DynamoDBClient } from '@aws-sdk/client-dynamodb';
|
|
3
3
|
import { DynamoDBDocumentClient } from '@aws-sdk/lib-dynamodb';
|
|
4
4
|
import crypto, { createHash } from 'crypto';
|
|
5
|
-
import { createLogger, createPerformanceTimer } from '@myvitalrx/platform-tools/observability';
|
|
5
|
+
import { createLogger, createPerformanceTimer, getContext } from '@myvitalrx/platform-tools/observability';
|
|
6
6
|
import { AsyncLocalStorage } from 'async_hooks';
|
|
7
7
|
import { GetObjectCommand, S3Client } from '@aws-sdk/client-s3';
|
|
8
8
|
|
|
@@ -87,6 +87,11 @@ var PROJECTION_TYPE = {
|
|
|
87
87
|
* Platform file — not a domain Metadata Type.
|
|
88
88
|
*/
|
|
89
89
|
RELATIONSHIP_INDEX: "relationshipIndex",
|
|
90
|
+
/**
|
|
91
|
+
* Forward relation rows (`typed-relations.json`), including inactive relations.
|
|
92
|
+
* Additive. The bidirectional index stays active-only.
|
|
93
|
+
*/
|
|
94
|
+
TYPED_RELATIONS: "typedRelations",
|
|
90
95
|
/**
|
|
91
96
|
* @deprecated Removed from publish — capabilities live on manifest.json.
|
|
92
97
|
* Kept so transitional parsers can ignore leftover objects.
|
|
@@ -105,6 +110,7 @@ var PROJECTION_FILE_NAME = {
|
|
|
105
110
|
[PROJECTION_TYPE.LANGUAGE]: "Language.json",
|
|
106
111
|
[PROJECTION_TYPE.COMMON]: "common.json",
|
|
107
112
|
[PROJECTION_TYPE.RELATIONSHIP_INDEX]: "relationship-index.json",
|
|
113
|
+
[PROJECTION_TYPE.TYPED_RELATIONS]: "typed-relations.json",
|
|
108
114
|
/** @deprecated No longer published. */
|
|
109
115
|
[PROJECTION_TYPE.RUNTIME_CONFIG]: "runtime-config.json",
|
|
110
116
|
[PROJECTION_TYPE.MANIFEST]: "manifest.json"
|
|
@@ -530,7 +536,10 @@ monotonicFactory();
|
|
|
530
536
|
// ../../libs/metadata/src/services/metadata-change-request.service.ts
|
|
531
537
|
monotonicFactory();
|
|
532
538
|
z.object({
|
|
533
|
-
/**
|
|
539
|
+
/**
|
|
540
|
+
* When true, a latest INACTIVE version is projected. Default false: the latest
|
|
541
|
+
* version must be ACTIVE, and an older ACTIVE version is not used instead.
|
|
542
|
+
*/
|
|
534
543
|
includeInactive: z.boolean().optional(),
|
|
535
544
|
/**
|
|
536
545
|
* When true, every published version of a value is retained under `versions`.
|
|
@@ -604,19 +613,80 @@ var ProjectionHelper = class _ProjectionHelper {
|
|
|
604
613
|
}
|
|
605
614
|
}
|
|
606
615
|
/**
|
|
607
|
-
*
|
|
608
|
-
*
|
|
616
|
+
* Row filter. Always excludes DELETED. When includeInactive is false, only ACTIVE.
|
|
617
|
+
*
|
|
618
|
+
* Does not apply latest-version rules. Callers that project a value code must use
|
|
619
|
+
* {@link selectProjectedValueVersions} so an older ACTIVE version cannot outrank
|
|
620
|
+
* a newer INACTIVE or DELETED version.
|
|
609
621
|
*/
|
|
610
622
|
static filterValues(values, includeInactive) {
|
|
611
|
-
return values.filter(
|
|
612
|
-
|
|
613
|
-
|
|
623
|
+
return values.filter(
|
|
624
|
+
(value) => _ProjectionHelper.isProjectableStatus(value.status, includeInactive)
|
|
625
|
+
);
|
|
626
|
+
}
|
|
627
|
+
/**
|
|
628
|
+
* Highest version of each type+code. Equal versions keep the first row.
|
|
629
|
+
*/
|
|
630
|
+
static latestValueByCode(values) {
|
|
631
|
+
const latest = /* @__PURE__ */ new Map();
|
|
632
|
+
for (const value of values) {
|
|
633
|
+
const key = _ProjectionHelper.relationFromKey(
|
|
634
|
+
value.metadataTypeCode,
|
|
635
|
+
value.valueCode
|
|
636
|
+
);
|
|
637
|
+
const current = latest.get(key);
|
|
638
|
+
if (!current || value.version > current.version) {
|
|
639
|
+
latest.set(key, value);
|
|
614
640
|
}
|
|
615
|
-
|
|
616
|
-
|
|
641
|
+
}
|
|
642
|
+
return latest;
|
|
643
|
+
}
|
|
644
|
+
/**
|
|
645
|
+
* Versions to write for each value code.
|
|
646
|
+
*
|
|
647
|
+
* The highest version decides. A latest INACTIVE version is omitted when
|
|
648
|
+
* `includeInactive` is false, and a latest DELETED version is always omitted.
|
|
649
|
+
* Older ACTIVE versions of that code are not projected in their place.
|
|
650
|
+
* When `includeAllVersions` is false, only that latest version is kept.
|
|
651
|
+
*/
|
|
652
|
+
static selectProjectedValueVersions(values, includeInactive, includeAllVersions) {
|
|
653
|
+
const latestByCode = _ProjectionHelper.latestValueByCode(values);
|
|
654
|
+
const grouped = /* @__PURE__ */ new Map();
|
|
655
|
+
for (const value of values) {
|
|
656
|
+
const key = _ProjectionHelper.relationFromKey(
|
|
657
|
+
value.metadataTypeCode,
|
|
658
|
+
value.valueCode
|
|
659
|
+
);
|
|
660
|
+
const list = grouped.get(key) ?? [];
|
|
661
|
+
list.push(value);
|
|
662
|
+
grouped.set(key, list);
|
|
663
|
+
}
|
|
664
|
+
const selected = [];
|
|
665
|
+
for (const [key, versions] of grouped) {
|
|
666
|
+
const latest = latestByCode.get(key);
|
|
667
|
+
if (!latest || !_ProjectionHelper.isProjectableStatus(latest.status, includeInactive)) {
|
|
668
|
+
continue;
|
|
617
669
|
}
|
|
618
|
-
|
|
619
|
-
|
|
670
|
+
if (!includeAllVersions) {
|
|
671
|
+
selected.push(latest);
|
|
672
|
+
continue;
|
|
673
|
+
}
|
|
674
|
+
for (const version of versions) {
|
|
675
|
+
if (_ProjectionHelper.isProjectableStatus(version.status, includeInactive)) {
|
|
676
|
+
selected.push(version);
|
|
677
|
+
}
|
|
678
|
+
}
|
|
679
|
+
}
|
|
680
|
+
return selected;
|
|
681
|
+
}
|
|
682
|
+
static isProjectableStatus(status, includeInactive) {
|
|
683
|
+
if (status === STATUS.DELETED) {
|
|
684
|
+
return false;
|
|
685
|
+
}
|
|
686
|
+
if (status === STATUS.INACTIVE) {
|
|
687
|
+
return includeInactive;
|
|
688
|
+
}
|
|
689
|
+
return status === STATUS.ACTIVE;
|
|
620
690
|
}
|
|
621
691
|
/**
|
|
622
692
|
* Filter relations to ACTIVE only.
|
|
@@ -786,9 +856,10 @@ var ProjectionHelper = class _ProjectionHelper {
|
|
|
786
856
|
* Shared by {@link GenericReadModelGenerator} — type-agnostic transform.
|
|
787
857
|
*/
|
|
788
858
|
static buildDomainProjectionRecords(input) {
|
|
789
|
-
const filtered = _ProjectionHelper.
|
|
859
|
+
const filtered = _ProjectionHelper.selectProjectedValueVersions(
|
|
790
860
|
input.values,
|
|
791
|
-
input.includeInactive
|
|
861
|
+
input.includeInactive,
|
|
862
|
+
input.includeAllVersions === true
|
|
792
863
|
);
|
|
793
864
|
const entries = filtered.map((value) => {
|
|
794
865
|
const fromKey = _ProjectionHelper.relationFromKey(
|
|
@@ -800,14 +871,53 @@ var ProjectionHelper = class _ProjectionHelper {
|
|
|
800
871
|
});
|
|
801
872
|
const records = _ProjectionHelper.buildRecordsMap(entries);
|
|
802
873
|
if (input.includeAllVersions === false) {
|
|
803
|
-
|
|
804
|
-
const latest = record.versions[String(record.latestVersion)];
|
|
805
|
-
record.versions = latest ? { [String(record.latestVersion)]: latest } : {};
|
|
806
|
-
}
|
|
874
|
+
_ProjectionHelper.keepLatestVersionOnly(records);
|
|
807
875
|
}
|
|
876
|
+
const inactiveRecords = _ProjectionHelper.buildInactiveRecords(
|
|
877
|
+
input,
|
|
878
|
+
records
|
|
879
|
+
);
|
|
808
880
|
const metadataCount = _ProjectionHelper.countVersions(records);
|
|
809
|
-
const contentHash = _ProjectionHelper.contentHash(records);
|
|
810
|
-
return { records, metadataCount, contentHash };
|
|
881
|
+
const contentHash = Object.keys(inactiveRecords).length > 0 ? _ProjectionHelper.contentHash({ records, inactiveRecords }) : _ProjectionHelper.contentHash(records);
|
|
882
|
+
return { records, inactiveRecords, metadataCount, contentHash };
|
|
883
|
+
}
|
|
884
|
+
/**
|
|
885
|
+
* Latest INACTIVE versions that are not already in the active `records` map.
|
|
886
|
+
* Empty when the caller already projected inactive values into `records`.
|
|
887
|
+
*/
|
|
888
|
+
static buildInactiveRecords(input, activeRecords) {
|
|
889
|
+
if (input.includeInactive) {
|
|
890
|
+
return {};
|
|
891
|
+
}
|
|
892
|
+
const selected = _ProjectionHelper.selectProjectedValueVersions(
|
|
893
|
+
input.values,
|
|
894
|
+
true,
|
|
895
|
+
input.includeAllVersions === true
|
|
896
|
+
).filter((value) => value.status === STATUS.INACTIVE);
|
|
897
|
+
const entries = selected.map((value) => {
|
|
898
|
+
const fromKey = _ProjectionHelper.relationFromKey(
|
|
899
|
+
value.metadataTypeCode,
|
|
900
|
+
value.valueCode
|
|
901
|
+
);
|
|
902
|
+
const relations = input.relationsByFrom.get(fromKey) ?? [];
|
|
903
|
+
return _ProjectionHelper.toProjectionEntry(value, relations);
|
|
904
|
+
});
|
|
905
|
+
const inactiveRecords = _ProjectionHelper.buildRecordsMap(entries);
|
|
906
|
+
if (input.includeAllVersions === false) {
|
|
907
|
+
_ProjectionHelper.keepLatestVersionOnly(inactiveRecords);
|
|
908
|
+
}
|
|
909
|
+
for (const code of Object.keys(inactiveRecords)) {
|
|
910
|
+
if (activeRecords[code]) {
|
|
911
|
+
delete inactiveRecords[code];
|
|
912
|
+
}
|
|
913
|
+
}
|
|
914
|
+
return inactiveRecords;
|
|
915
|
+
}
|
|
916
|
+
static keepLatestVersionOnly(records) {
|
|
917
|
+
for (const record of Object.values(records)) {
|
|
918
|
+
const latest = record.versions[String(record.latestVersion)];
|
|
919
|
+
record.versions = latest ? { [String(record.latestVersion)]: latest } : {};
|
|
920
|
+
}
|
|
811
921
|
}
|
|
812
922
|
};
|
|
813
923
|
|
|
@@ -816,7 +926,8 @@ var RESERVED_PROJECTION_NAMES = [
|
|
|
816
926
|
"common",
|
|
817
927
|
"manifest",
|
|
818
928
|
"runtimeConfig",
|
|
819
|
-
"relationshipIndex"
|
|
929
|
+
"relationshipIndex",
|
|
930
|
+
"typedRelations"
|
|
820
931
|
];
|
|
821
932
|
function assertUsableMetadataTypeCode(metadataTypeCode) {
|
|
822
933
|
const trimmed = metadataTypeCode.trim();
|
|
@@ -1131,6 +1242,72 @@ var ProjectionPathBuilder = class {
|
|
|
1131
1242
|
}
|
|
1132
1243
|
}
|
|
1133
1244
|
};
|
|
1245
|
+
|
|
1246
|
+
// ../../libs/metadata-projection/src/lib/generators/relationship-index/TypedRelationshipCatalog.ts
|
|
1247
|
+
function filterTypedRelations(relations, query) {
|
|
1248
|
+
return relations.filter((relation) => {
|
|
1249
|
+
if (relation.fromMetadataTypeCode !== query.fromType) {
|
|
1250
|
+
return false;
|
|
1251
|
+
}
|
|
1252
|
+
if (relation.fromMetadataValueCode !== query.fromValue) {
|
|
1253
|
+
return false;
|
|
1254
|
+
}
|
|
1255
|
+
if (query.relationType && relation.relationType !== query.relationType) {
|
|
1256
|
+
return false;
|
|
1257
|
+
}
|
|
1258
|
+
if (query.toType && relation.toMetadataTypeCode !== query.toType) {
|
|
1259
|
+
return false;
|
|
1260
|
+
}
|
|
1261
|
+
return true;
|
|
1262
|
+
});
|
|
1263
|
+
}
|
|
1264
|
+
function parseTypedRelationshipFile(parsed, expected) {
|
|
1265
|
+
const fileName = expected.fileName ?? "typed-relations.json";
|
|
1266
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
1267
|
+
throw new Error(`${fileName} is not a JSON object`);
|
|
1268
|
+
}
|
|
1269
|
+
const record = parsed;
|
|
1270
|
+
if (record.releaseId !== expected.releaseId) {
|
|
1271
|
+
throw new Error(
|
|
1272
|
+
`${fileName} releaseId ${String(record.releaseId)} does not match ${expected.releaseId}`
|
|
1273
|
+
);
|
|
1274
|
+
}
|
|
1275
|
+
if (record.contentHash !== expected.contentHash) {
|
|
1276
|
+
throw new Error(`Checksum mismatch for ${fileName}`);
|
|
1277
|
+
}
|
|
1278
|
+
if (!Array.isArray(record.relations)) {
|
|
1279
|
+
throw new Error(`${fileName} relations must be an array`);
|
|
1280
|
+
}
|
|
1281
|
+
const relations = [];
|
|
1282
|
+
for (const row of record.relations) {
|
|
1283
|
+
if (!row || typeof row !== "object" || Array.isArray(row)) {
|
|
1284
|
+
throw new Error(`${fileName} contains an invalid relation row`);
|
|
1285
|
+
}
|
|
1286
|
+
const item = row;
|
|
1287
|
+
if (typeof item.relationType !== "string" || typeof item.status !== "string" || typeof item.fromMetadataTypeCode !== "string" || typeof item.fromMetadataValueCode !== "string" || typeof item.toMetadataTypeCode !== "string" || typeof item.toMetadataValueCode !== "string") {
|
|
1288
|
+
throw new Error(`${fileName} contains an invalid relation row`);
|
|
1289
|
+
}
|
|
1290
|
+
const relation = {
|
|
1291
|
+
relationType: item.relationType,
|
|
1292
|
+
status: item.status,
|
|
1293
|
+
fromMetadataTypeCode: item.fromMetadataTypeCode,
|
|
1294
|
+
fromMetadataValueCode: item.fromMetadataValueCode,
|
|
1295
|
+
toMetadataTypeCode: item.toMetadataTypeCode,
|
|
1296
|
+
toMetadataValueCode: item.toMetadataValueCode
|
|
1297
|
+
};
|
|
1298
|
+
if (typeof item.moduleCode === "string") {
|
|
1299
|
+
relation.moduleCode = item.moduleCode;
|
|
1300
|
+
}
|
|
1301
|
+
if (typeof item.featureCode === "string") {
|
|
1302
|
+
relation.featureCode = item.featureCode;
|
|
1303
|
+
}
|
|
1304
|
+
if (typeof item.permissionActionCode === "string") {
|
|
1305
|
+
relation.permissionActionCode = item.permissionActionCode;
|
|
1306
|
+
}
|
|
1307
|
+
relations.push(relation);
|
|
1308
|
+
}
|
|
1309
|
+
return relations;
|
|
1310
|
+
}
|
|
1134
1311
|
createLogger({ serviceName: "metadata-projection" });
|
|
1135
1312
|
var metadataPublishedPayloadSchema = z.object({
|
|
1136
1313
|
changeRequestId: z.string().min(1),
|
|
@@ -2110,10 +2287,14 @@ var MetadataDownloader = class {
|
|
|
2110
2287
|
});
|
|
2111
2288
|
try {
|
|
2112
2289
|
const relationshipIndex = await this.downloadRelationshipIndex(manifest);
|
|
2290
|
+
const typedRelations = await this.downloadTypedRelations(manifest);
|
|
2113
2291
|
const loadedFiles = relationshipIndex ? [
|
|
2114
2292
|
manifestFileName,
|
|
2115
2293
|
PROJECTION_FILE_NAME[PROJECTION_TYPE.RELATIONSHIP_INDEX]
|
|
2116
2294
|
] : [manifestFileName];
|
|
2295
|
+
if (typedRelations) {
|
|
2296
|
+
loadedFiles.push(PROJECTION_FILE_NAME[PROJECTION_TYPE.TYPED_RELATIONS]);
|
|
2297
|
+
}
|
|
2117
2298
|
const localization = /* @__PURE__ */ new Map();
|
|
2118
2299
|
if (manifest.localization?.files) {
|
|
2119
2300
|
const localeEntries = Object.entries(manifest.localization.files);
|
|
@@ -2153,6 +2334,7 @@ var MetadataDownloader = class {
|
|
|
2153
2334
|
manifest,
|
|
2154
2335
|
domainFiles: /* @__PURE__ */ new Map(),
|
|
2155
2336
|
relationshipIndex,
|
|
2337
|
+
typedRelations,
|
|
2156
2338
|
loadedFiles: loadedFiles.sort((a, b) => a.localeCompare(b)),
|
|
2157
2339
|
localization: localization.size > 0 ? localization : void 0,
|
|
2158
2340
|
downloadedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
@@ -2297,6 +2479,66 @@ var MetadataDownloader = class {
|
|
|
2297
2479
|
* Load `relationship-index.json` when listed in the manifest integrity catalog.
|
|
2298
2480
|
* Missing/corrupt/mismatched artifacts fail closed — never activate an empty map.
|
|
2299
2481
|
*/
|
|
2482
|
+
/**
|
|
2483
|
+
* Download `common.json` for a release (type catalog: display name, value data type,
|
|
2484
|
+
* multi-select). Not part of bootstrap — published catalog APIs request it explicitly.
|
|
2485
|
+
*/
|
|
2486
|
+
async downloadCommon(manifest) {
|
|
2487
|
+
const fileName = PROJECTION_FILE_NAME[PROJECTION_TYPE.COMMON];
|
|
2488
|
+
const entry = manifest.files.find((file) => file.fileName === fileName);
|
|
2489
|
+
if (!entry) {
|
|
2490
|
+
throw new ProjectionDownloadError(
|
|
2491
|
+
"common.json is missing from the projection manifest",
|
|
2492
|
+
{
|
|
2493
|
+
retryable: false,
|
|
2494
|
+
metadata: { releaseId: manifest.releaseId, fileName }
|
|
2495
|
+
}
|
|
2496
|
+
);
|
|
2497
|
+
}
|
|
2498
|
+
const body = await this.getObjectBody(
|
|
2499
|
+
this.buildKey(manifest.releaseId, fileName)
|
|
2500
|
+
);
|
|
2501
|
+
return this.parseAndValidateProjectionBody(
|
|
2502
|
+
fileName,
|
|
2503
|
+
entry.contentHash,
|
|
2504
|
+
body,
|
|
2505
|
+
manifest.releaseId
|
|
2506
|
+
);
|
|
2507
|
+
}
|
|
2508
|
+
async downloadTypedRelations(manifest) {
|
|
2509
|
+
const fileName = PROJECTION_FILE_NAME[PROJECTION_TYPE.TYPED_RELATIONS];
|
|
2510
|
+
const entry = manifest.files.find((file) => file.fileName === fileName);
|
|
2511
|
+
if (!entry) {
|
|
2512
|
+
return void 0;
|
|
2513
|
+
}
|
|
2514
|
+
const body = await this.getObjectBody(
|
|
2515
|
+
this.buildKey(manifest.releaseId, fileName)
|
|
2516
|
+
);
|
|
2517
|
+
let parsed;
|
|
2518
|
+
try {
|
|
2519
|
+
parsed = JSON.parse(body);
|
|
2520
|
+
} catch {
|
|
2521
|
+
throw new ProjectionDownloadError(`Corrupted JSON for ${fileName}`, {
|
|
2522
|
+
retryable: false,
|
|
2523
|
+
metadata: { fileName, releaseId: manifest.releaseId }
|
|
2524
|
+
});
|
|
2525
|
+
}
|
|
2526
|
+
try {
|
|
2527
|
+
return parseTypedRelationshipFile(parsed, {
|
|
2528
|
+
releaseId: manifest.releaseId,
|
|
2529
|
+
contentHash: entry.contentHash,
|
|
2530
|
+
fileName
|
|
2531
|
+
});
|
|
2532
|
+
} catch (err) {
|
|
2533
|
+
throw new ProjectionDownloadError(
|
|
2534
|
+
err instanceof Error ? err.message : `Invalid typed relations for ${fileName}`,
|
|
2535
|
+
{
|
|
2536
|
+
retryable: false,
|
|
2537
|
+
metadata: { fileName, releaseId: manifest.releaseId }
|
|
2538
|
+
}
|
|
2539
|
+
);
|
|
2540
|
+
}
|
|
2541
|
+
}
|
|
2300
2542
|
async downloadRelationshipIndex(manifest) {
|
|
2301
2543
|
const fileName = PROJECTION_FILE_NAME[PROJECTION_TYPE.RELATIONSHIP_INDEX];
|
|
2302
2544
|
const entry = manifest.files.find((f) => f.fileName === fileName);
|
|
@@ -2453,6 +2695,10 @@ var MetadataCache = class {
|
|
|
2453
2695
|
getRelationshipIndex() {
|
|
2454
2696
|
return this.snapshot?.relationshipIndex;
|
|
2455
2697
|
}
|
|
2698
|
+
/** Undefined when the active release has no typed relation catalog. */
|
|
2699
|
+
getTypedRelations() {
|
|
2700
|
+
return this.snapshot?.typedRelations;
|
|
2701
|
+
}
|
|
2456
2702
|
getLocalization(locale) {
|
|
2457
2703
|
return this.snapshot?.localization?.get(locale);
|
|
2458
2704
|
}
|
|
@@ -2495,6 +2741,7 @@ var MetadataCache = class {
|
|
|
2495
2741
|
domainFiles,
|
|
2496
2742
|
common: bundle.common ? Object.freeze({ ...bundle.common }) : void 0,
|
|
2497
2743
|
relationshipIndex: bundle.relationshipIndex ? Object.freeze({ ...bundle.relationshipIndex }) : void 0,
|
|
2744
|
+
typedRelations: bundle.typedRelations ? Object.freeze([...bundle.typedRelations]) : void 0,
|
|
2498
2745
|
manifest: Object.freeze({
|
|
2499
2746
|
...bundle.manifest,
|
|
2500
2747
|
files: Object.freeze(
|
|
@@ -2517,6 +2764,38 @@ var MetadataCache = class {
|
|
|
2517
2764
|
this.status = CACHE_STATUS.READY;
|
|
2518
2765
|
return snapshot;
|
|
2519
2766
|
}
|
|
2767
|
+
/**
|
|
2768
|
+
* Install `common.json` into the current snapshot (same release).
|
|
2769
|
+
* Used by published catalog reads. Does not mutate the prior snapshot.
|
|
2770
|
+
*/
|
|
2771
|
+
mergeCommon(common, guard) {
|
|
2772
|
+
if (!this.snapshot) {
|
|
2773
|
+
throw new Error("Cannot merge common.json into an empty metadata cache");
|
|
2774
|
+
}
|
|
2775
|
+
if (!this.guardAllowsWrite(guard)) {
|
|
2776
|
+
return this.snapshot;
|
|
2777
|
+
}
|
|
2778
|
+
if (common.releaseId && common.releaseId !== this.snapshot.releaseId) {
|
|
2779
|
+
return this.snapshot;
|
|
2780
|
+
}
|
|
2781
|
+
const loadedFiles = Object.freeze(
|
|
2782
|
+
[
|
|
2783
|
+
.../* @__PURE__ */ new Set([
|
|
2784
|
+
...this.snapshot.loadedFiles,
|
|
2785
|
+
PROJECTION_FILE_NAME[PROJECTION_TYPE.COMMON]
|
|
2786
|
+
])
|
|
2787
|
+
].sort((a, b) => a.localeCompare(b))
|
|
2788
|
+
);
|
|
2789
|
+
const snapshot = Object.freeze({
|
|
2790
|
+
...this.snapshot,
|
|
2791
|
+
common: Object.freeze({ ...common }),
|
|
2792
|
+
loadedFiles,
|
|
2793
|
+
loadedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
2794
|
+
});
|
|
2795
|
+
this.snapshot = snapshot;
|
|
2796
|
+
this.status = CACHE_STATUS.READY;
|
|
2797
|
+
return snapshot;
|
|
2798
|
+
}
|
|
2520
2799
|
/**
|
|
2521
2800
|
* Merge additional domain projection files into the current snapshot (same revision).
|
|
2522
2801
|
* Used by selective on-demand downloads — never mutates the prior snapshot.
|
|
@@ -2753,7 +3032,7 @@ var MetadataResolver = class {
|
|
|
2753
3032
|
event: RUNTIME_METADATA_EVENTS.PROJECTION_PROVIDER_SUPPORTS_TYPE,
|
|
2754
3033
|
requestedType,
|
|
2755
3034
|
supported,
|
|
2756
|
-
availableTypes,
|
|
3035
|
+
availableTypes: availableTypes.length,
|
|
2757
3036
|
cacheStatus: this.cache.getStatus(),
|
|
2758
3037
|
releaseId: this.cache.getReleaseId()
|
|
2759
3038
|
});
|
|
@@ -3181,6 +3460,7 @@ function metadataValueToReference(value) {
|
|
|
3181
3460
|
// ../../libs/runtime-metadata/src/lib/provider/ExtensionMetadataProvider.ts
|
|
3182
3461
|
var DEFAULT_READY_TIMEOUT_MS = 5e3;
|
|
3183
3462
|
var DEFAULT_REQUEST_TIMEOUT_MS = 2e3;
|
|
3463
|
+
var RELATED_BATCH_LIMIT = 200;
|
|
3184
3464
|
var ExtensionMetadataProvider = class {
|
|
3185
3465
|
baseUrl;
|
|
3186
3466
|
readyTimeoutMs;
|
|
@@ -3203,25 +3483,52 @@ var ExtensionMetadataProvider = class {
|
|
|
3203
3483
|
}
|
|
3204
3484
|
}
|
|
3205
3485
|
async waitUntilReady() {
|
|
3486
|
+
const started = Date.now();
|
|
3206
3487
|
const deadline = Date.now() + this.readyTimeoutMs;
|
|
3207
3488
|
let lastError;
|
|
3489
|
+
let attempts = 0;
|
|
3208
3490
|
while (Date.now() < deadline) {
|
|
3491
|
+
attempts += 1;
|
|
3209
3492
|
try {
|
|
3210
3493
|
const status = await this.getStatus();
|
|
3211
3494
|
if (isServingState(status.state) && status.releaseId) {
|
|
3495
|
+
this.logger.info({
|
|
3496
|
+
event: "templates.performance",
|
|
3497
|
+
phase: "metadataExtension.ready",
|
|
3498
|
+
durationMs: Date.now() - started,
|
|
3499
|
+
attempts,
|
|
3500
|
+
state: status.state
|
|
3501
|
+
});
|
|
3212
3502
|
return status;
|
|
3213
3503
|
}
|
|
3504
|
+
if (status.lastError) {
|
|
3505
|
+
lastError = new Error(status.lastError);
|
|
3506
|
+
}
|
|
3507
|
+
if (status.state === "FAILED") {
|
|
3508
|
+
break;
|
|
3509
|
+
}
|
|
3214
3510
|
} catch (err) {
|
|
3215
3511
|
lastError = err;
|
|
3512
|
+
if (err instanceof MetadataProjectionUnavailableError && err.metadata?.unreachable === true) {
|
|
3513
|
+
break;
|
|
3514
|
+
}
|
|
3216
3515
|
}
|
|
3217
3516
|
await sleep(50);
|
|
3218
3517
|
}
|
|
3518
|
+
const detail = lastError instanceof Error ? lastError.message : lastError ? String(lastError) : "";
|
|
3519
|
+
this.logger.warn({
|
|
3520
|
+
event: "templates.performance",
|
|
3521
|
+
phase: "metadataExtension.ready",
|
|
3522
|
+
durationMs: Date.now() - started,
|
|
3523
|
+
attempts,
|
|
3524
|
+
outcome: "unavailable"
|
|
3525
|
+
});
|
|
3219
3526
|
throw new MetadataProjectionUnavailableError(
|
|
3220
|
-
"Metadata extension did not become ready",
|
|
3527
|
+
detail ? `Metadata extension did not become ready: ${detail}` : "Metadata extension did not become ready",
|
|
3221
3528
|
{
|
|
3222
3529
|
retryable: true,
|
|
3223
3530
|
metadata: {
|
|
3224
|
-
lastError:
|
|
3531
|
+
lastError: detail
|
|
3225
3532
|
}
|
|
3226
3533
|
}
|
|
3227
3534
|
);
|
|
@@ -3234,6 +3541,7 @@ var ExtensionMetadataProvider = class {
|
|
|
3234
3541
|
return {
|
|
3235
3542
|
state: body.state ?? "UNKNOWN",
|
|
3236
3543
|
releaseId: body.releaseId ?? null,
|
|
3544
|
+
lastError: body.lastError ?? null,
|
|
3237
3545
|
loadedAt: body.loadedAt ?? null,
|
|
3238
3546
|
lastRefreshAttemptAt: body.lastRefreshAttemptAt ?? null,
|
|
3239
3547
|
lastSuccessfulRefreshAt: body.lastSuccessfulRefreshAt ?? null,
|
|
@@ -3315,6 +3623,59 @@ var ExtensionMetadataProvider = class {
|
|
|
3315
3623
|
throw err;
|
|
3316
3624
|
}
|
|
3317
3625
|
}
|
|
3626
|
+
/**
|
|
3627
|
+
* Every published value for one metadata type.
|
|
3628
|
+
* GET /v1/metadata/{typeCode}. Unknown types are a projection miss (`null`).
|
|
3629
|
+
*/
|
|
3630
|
+
async listTypeValues(typeCode, options) {
|
|
3631
|
+
const params = new URLSearchParams();
|
|
3632
|
+
if (options?.locale) {
|
|
3633
|
+
params.set("locale", options.locale);
|
|
3634
|
+
}
|
|
3635
|
+
if (options?.includeInactive) {
|
|
3636
|
+
params.set("includeInactive", "true");
|
|
3637
|
+
}
|
|
3638
|
+
const query = params.toString();
|
|
3639
|
+
const path = `/v1/metadata/${encodeURIComponent(typeCode)}${query ? `?${query}` : ""}`;
|
|
3640
|
+
try {
|
|
3641
|
+
const body = await this.requestJson("GET", path);
|
|
3642
|
+
const values = Object.values(body.items ?? {}).map((item) => this.toMetadataValue(item, options?.locale)).filter((item) => item != null);
|
|
3643
|
+
return {
|
|
3644
|
+
releaseId: body.releaseId ?? null,
|
|
3645
|
+
values,
|
|
3646
|
+
type: parseTypeCatalog(body.type, typeCode)
|
|
3647
|
+
};
|
|
3648
|
+
} catch (err) {
|
|
3649
|
+
if (isNotFound(err)) {
|
|
3650
|
+
return null;
|
|
3651
|
+
}
|
|
3652
|
+
throw err;
|
|
3653
|
+
}
|
|
3654
|
+
}
|
|
3655
|
+
async listRelations(query) {
|
|
3656
|
+
const params = new URLSearchParams();
|
|
3657
|
+
params.set("fromType", query.fromType);
|
|
3658
|
+
params.set("fromValue", query.fromValue);
|
|
3659
|
+
if (query.relationType) {
|
|
3660
|
+
params.set("relationType", query.relationType);
|
|
3661
|
+
}
|
|
3662
|
+
if (query.toType) {
|
|
3663
|
+
params.set("toType", query.toType);
|
|
3664
|
+
}
|
|
3665
|
+
try {
|
|
3666
|
+
const body = await this.requestJson("GET", `/v1/relations?${params.toString()}`);
|
|
3667
|
+
return {
|
|
3668
|
+
releaseId: body.releaseId ?? null,
|
|
3669
|
+
supported: body.supported === true,
|
|
3670
|
+
relations: Array.isArray(body.relations) ? body.relations : []
|
|
3671
|
+
};
|
|
3672
|
+
} catch (err) {
|
|
3673
|
+
if (isNotFound(err)) {
|
|
3674
|
+
return { releaseId: null, supported: false, relations: [] };
|
|
3675
|
+
}
|
|
3676
|
+
throw err;
|
|
3677
|
+
}
|
|
3678
|
+
}
|
|
3318
3679
|
async getRelatedValues(sourceTypeCode, sourceValueCode, targetTypeCode, options) {
|
|
3319
3680
|
const localeQuery = options?.locale ? `?locale=${encodeURIComponent(options.locale)}` : "";
|
|
3320
3681
|
const path = `/v1/related/${encodeURIComponent(sourceTypeCode)}/${encodeURIComponent(sourceValueCode)}/${encodeURIComponent(targetTypeCode)}${localeQuery}`;
|
|
@@ -3331,6 +3692,38 @@ var ExtensionMetadataProvider = class {
|
|
|
3331
3692
|
throw err;
|
|
3332
3693
|
}
|
|
3333
3694
|
}
|
|
3695
|
+
async getRelatedValueGroups(sourceTypeCode, sourceValueCodes, targetTypeCode, options) {
|
|
3696
|
+
if (sourceValueCodes.length === 0) {
|
|
3697
|
+
return [];
|
|
3698
|
+
}
|
|
3699
|
+
const groups = [];
|
|
3700
|
+
try {
|
|
3701
|
+
for (let offset = 0; offset < sourceValueCodes.length; offset += RELATED_BATCH_LIMIT) {
|
|
3702
|
+
const sourceValues = sourceValueCodes.slice(offset, offset + RELATED_BATCH_LIMIT);
|
|
3703
|
+
const body = await this.requestJson("POST", "/v1/related/batch", {
|
|
3704
|
+
sourceType: sourceTypeCode,
|
|
3705
|
+
sourceValues,
|
|
3706
|
+
targetType: targetTypeCode,
|
|
3707
|
+
...options?.locale ? { locale: options.locale } : {}
|
|
3708
|
+
});
|
|
3709
|
+
for (const group of body.groups ?? []) {
|
|
3710
|
+
groups.push({
|
|
3711
|
+
sourceValueCode: group.sourceValueCode ?? "",
|
|
3712
|
+
values: (group.items ?? []).map((item) => this.toMetadataValue(item, options?.locale)).filter((item) => item != null)
|
|
3713
|
+
});
|
|
3714
|
+
}
|
|
3715
|
+
}
|
|
3716
|
+
return groups;
|
|
3717
|
+
} catch (err) {
|
|
3718
|
+
if (isNotFound(err)) {
|
|
3719
|
+
throw new MetadataProjectionUnavailableError(
|
|
3720
|
+
"Extension related batch route is unavailable",
|
|
3721
|
+
{ retryable: true, metadata: { path: "/v1/related/batch" } }
|
|
3722
|
+
);
|
|
3723
|
+
}
|
|
3724
|
+
throw err;
|
|
3725
|
+
}
|
|
3726
|
+
}
|
|
3334
3727
|
async getLocalizationValue(keyOrTypeCode, valueCodeOrLocale, maybeLocale) {
|
|
3335
3728
|
let key;
|
|
3336
3729
|
let locale;
|
|
@@ -3406,6 +3799,7 @@ var ExtensionMetadataProvider = class {
|
|
|
3406
3799
|
};
|
|
3407
3800
|
}
|
|
3408
3801
|
async requestJson(method, path, payload) {
|
|
3802
|
+
const started = Date.now();
|
|
3409
3803
|
const controller = new AbortController();
|
|
3410
3804
|
const timer = setTimeout(() => controller.abort(), this.requestTimeoutMs);
|
|
3411
3805
|
try {
|
|
@@ -3413,6 +3807,7 @@ var ExtensionMetadataProvider = class {
|
|
|
3413
3807
|
method,
|
|
3414
3808
|
headers: {
|
|
3415
3809
|
accept: "application/json",
|
|
3810
|
+
...correlationHeaders(),
|
|
3416
3811
|
...payload !== void 0 ? { "content-type": "application/json" } : {}
|
|
3417
3812
|
},
|
|
3418
3813
|
body: payload !== void 0 ? JSON.stringify(payload) : void 0,
|
|
@@ -3459,17 +3854,41 @@ var ExtensionMetadataProvider = class {
|
|
|
3459
3854
|
event: "runtimeMetadata.extension.requestFailed",
|
|
3460
3855
|
path,
|
|
3461
3856
|
aborted,
|
|
3462
|
-
|
|
3857
|
+
errorMessage: err instanceof Error ? err.message : String(err)
|
|
3463
3858
|
});
|
|
3464
3859
|
throw new MetadataProjectionUnavailableError(
|
|
3465
3860
|
aborted ? "Metadata extension request timed out" : "Metadata extension is unavailable",
|
|
3466
|
-
{
|
|
3861
|
+
{
|
|
3862
|
+
retryable: true,
|
|
3863
|
+
metadata: { path, unreachable: !aborted, durationMs: Date.now() - started }
|
|
3864
|
+
}
|
|
3467
3865
|
);
|
|
3468
3866
|
} finally {
|
|
3469
3867
|
clearTimeout(timer);
|
|
3470
3868
|
}
|
|
3471
3869
|
}
|
|
3472
3870
|
};
|
|
3871
|
+
function parseTypeCatalog(raw, fallbackTypeCode) {
|
|
3872
|
+
if (!raw || typeof raw !== "object") {
|
|
3873
|
+
return null;
|
|
3874
|
+
}
|
|
3875
|
+
if (typeof raw.displayName !== "string" || typeof raw.valueDataType !== "string") {
|
|
3876
|
+
return null;
|
|
3877
|
+
}
|
|
3878
|
+
if (typeof raw.multiSelectAllowed !== "boolean") {
|
|
3879
|
+
return null;
|
|
3880
|
+
}
|
|
3881
|
+
const metadataType = typeof raw.metadataType === "string" && raw.metadataType.trim() ? raw.metadataType : fallbackTypeCode;
|
|
3882
|
+
return {
|
|
3883
|
+
metadataType,
|
|
3884
|
+
displayName: raw.displayName,
|
|
3885
|
+
valueDataType: raw.valueDataType,
|
|
3886
|
+
multiSelectAllowed: raw.multiSelectAllowed,
|
|
3887
|
+
status: typeof raw.status === "string" ? raw.status : "",
|
|
3888
|
+
...typeof raw.required === "boolean" ? { required: raw.required } : {},
|
|
3889
|
+
...typeof raw.isGlobal === "boolean" ? { isGlobal: raw.isGlobal } : {}
|
|
3890
|
+
};
|
|
3891
|
+
}
|
|
3473
3892
|
function isNotFound(err) {
|
|
3474
3893
|
return err.code === "RUNTIME_METADATA_NOT_FOUND";
|
|
3475
3894
|
}
|
|
@@ -3479,6 +3898,13 @@ function isUnavailable(err) {
|
|
|
3479
3898
|
function isServingState(state) {
|
|
3480
3899
|
return state === "READY" || state === "STALE" || state === "DEGRADED";
|
|
3481
3900
|
}
|
|
3901
|
+
function correlationHeaders() {
|
|
3902
|
+
const correlationId = getContext().correlationId;
|
|
3903
|
+
if (!correlationId || correlationId === "unknown") {
|
|
3904
|
+
return {};
|
|
3905
|
+
}
|
|
3906
|
+
return { "x-correlation-id": correlationId };
|
|
3907
|
+
}
|
|
3482
3908
|
function sleep(ms) {
|
|
3483
3909
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
3484
3910
|
}
|
|
@@ -3785,39 +4211,109 @@ var S3MetadataProvider = class {
|
|
|
3785
4211
|
unavailable: !this.cache.isReady() && parsedRefs.length > 0
|
|
3786
4212
|
};
|
|
3787
4213
|
}
|
|
4214
|
+
async listRelations(query) {
|
|
4215
|
+
const relations = this.cache.getTypedRelations();
|
|
4216
|
+
if (!relations) {
|
|
4217
|
+
return {
|
|
4218
|
+
releaseId: this.cache.getReleaseId(),
|
|
4219
|
+
supported: false,
|
|
4220
|
+
relations: []
|
|
4221
|
+
};
|
|
4222
|
+
}
|
|
4223
|
+
return {
|
|
4224
|
+
releaseId: this.cache.getReleaseId(),
|
|
4225
|
+
supported: true,
|
|
4226
|
+
relations: filterTypedRelations(relations, query)
|
|
4227
|
+
};
|
|
4228
|
+
}
|
|
3788
4229
|
async getRelatedValues(sourceTypeCode, sourceValueCode, targetTypeCode, options) {
|
|
3789
|
-
await this.
|
|
3790
|
-
const index = this.cache.getRelationshipIndex();
|
|
3791
|
-
const codes = relatedValueCodes(
|
|
3792
|
-
index,
|
|
4230
|
+
const groups = await this.getRelatedValueGroups(
|
|
3793
4231
|
sourceTypeCode,
|
|
3794
|
-
sourceValueCode,
|
|
3795
|
-
targetTypeCode
|
|
4232
|
+
[sourceValueCode],
|
|
4233
|
+
targetTypeCode,
|
|
4234
|
+
options
|
|
3796
4235
|
);
|
|
3797
|
-
|
|
3798
|
-
|
|
3799
|
-
|
|
4236
|
+
const values = groups[0]?.values ?? [];
|
|
4237
|
+
this.logger.info({
|
|
4238
|
+
event: "runtimeMetadata.related.lookup",
|
|
4239
|
+
sourceTypeCode,
|
|
4240
|
+
sourceValueCode,
|
|
4241
|
+
targetTypeCode,
|
|
4242
|
+
count: values.length
|
|
4243
|
+
});
|
|
4244
|
+
return values;
|
|
4245
|
+
}
|
|
4246
|
+
async getRelatedValueGroups(sourceTypeCode, sourceValueCodes, targetTypeCode, options) {
|
|
4247
|
+
if (sourceValueCodes.length === 0) {
|
|
4248
|
+
return [];
|
|
4249
|
+
}
|
|
4250
|
+
await this.ensureTypesLoaded([sourceTypeCode, targetTypeCode]);
|
|
4251
|
+
const index = this.cache.getRelationshipIndex();
|
|
4252
|
+
const groups = [];
|
|
4253
|
+
for (const sourceValueCode of sourceValueCodes) {
|
|
4254
|
+
const codes = relatedValueCodes(
|
|
4255
|
+
index,
|
|
3800
4256
|
sourceTypeCode,
|
|
3801
4257
|
sourceValueCode,
|
|
3802
4258
|
targetTypeCode
|
|
3803
4259
|
);
|
|
3804
|
-
codes.
|
|
3805
|
-
|
|
3806
|
-
|
|
3807
|
-
|
|
3808
|
-
|
|
3809
|
-
|
|
3810
|
-
|
|
4260
|
+
if (codes.length === 0) {
|
|
4261
|
+
codes.push(
|
|
4262
|
+
...relatedValueCodesFromEntry(
|
|
4263
|
+
this.resolver,
|
|
4264
|
+
sourceTypeCode,
|
|
4265
|
+
sourceValueCode,
|
|
4266
|
+
targetTypeCode
|
|
4267
|
+
)
|
|
4268
|
+
);
|
|
4269
|
+
}
|
|
4270
|
+
const values = [];
|
|
4271
|
+
for (const valueCode of codes) {
|
|
4272
|
+
const value = await this.getValue(targetTypeCode, valueCode, options);
|
|
4273
|
+
if (value) {
|
|
4274
|
+
values.push(value);
|
|
4275
|
+
}
|
|
3811
4276
|
}
|
|
4277
|
+
groups.push({ sourceValueCode, values });
|
|
3812
4278
|
}
|
|
3813
4279
|
this.logger.info({
|
|
3814
|
-
event: "runtimeMetadata.related.
|
|
4280
|
+
event: "runtimeMetadata.related.batch",
|
|
3815
4281
|
sourceTypeCode,
|
|
3816
|
-
sourceValueCode,
|
|
3817
4282
|
targetTypeCode,
|
|
3818
|
-
|
|
4283
|
+
sources: sourceValueCodes.length,
|
|
4284
|
+
count: groups.reduce((sum, group) => sum + group.values.length, 0)
|
|
3819
4285
|
});
|
|
3820
|
-
return
|
|
4286
|
+
return groups;
|
|
4287
|
+
}
|
|
4288
|
+
async listTypeValues(typeCode, options) {
|
|
4289
|
+
await this.ensureTypesLoaded([typeCode]);
|
|
4290
|
+
const file = this.cache.getDomainFile(typeCode);
|
|
4291
|
+
if (!file) {
|
|
4292
|
+
return null;
|
|
4293
|
+
}
|
|
4294
|
+
const values = this.resolver.getAll(typeCode).map(
|
|
4295
|
+
(entry) => projectionEntryToMetadataValue(typeCode, entry.code, entry, options?.locale)
|
|
4296
|
+
);
|
|
4297
|
+
if (options?.includeInactive && file.inactiveRecords) {
|
|
4298
|
+
const seen = new Set(values.map((value) => value.valueCode));
|
|
4299
|
+
for (const [valueCode, record] of Object.entries(file.inactiveRecords)) {
|
|
4300
|
+
if (seen.has(valueCode)) {
|
|
4301
|
+
continue;
|
|
4302
|
+
}
|
|
4303
|
+
const entry = latestProjectionEntry(record);
|
|
4304
|
+
if (!entry) {
|
|
4305
|
+
continue;
|
|
4306
|
+
}
|
|
4307
|
+
values.push(
|
|
4308
|
+
projectionEntryToMetadataValue(typeCode, valueCode, entry, options.locale)
|
|
4309
|
+
);
|
|
4310
|
+
}
|
|
4311
|
+
}
|
|
4312
|
+
return {
|
|
4313
|
+
releaseId: this.cache.getReleaseId(),
|
|
4314
|
+
values,
|
|
4315
|
+
type: typeCatalogFromProjection(typeCode, file, this.cache.getCommon())
|
|
4316
|
+
};
|
|
3821
4317
|
}
|
|
3822
4318
|
};
|
|
3823
4319
|
function relatedValueCodes(index, sourceTypeCode, sourceValueCode, targetTypeCode) {
|
|
@@ -3828,6 +4324,36 @@ function relatedValueCodes(index, sourceTypeCode, sourceValueCode, targetTypeCod
|
|
|
3828
4324
|
const values = index[key]?.[targetTypeCode];
|
|
3829
4325
|
return values ? [...values] : [];
|
|
3830
4326
|
}
|
|
4327
|
+
function typeCatalogFromProjection(typeCode, file, common) {
|
|
4328
|
+
const fromCommon = common?.types.find(
|
|
4329
|
+
(type) => type.metadataTypeCode === typeCode
|
|
4330
|
+
);
|
|
4331
|
+
if (fromCommon && typeof fromCommon.displayName === "string" && fromCommon.displayName.trim() && typeof fromCommon.valueDataType === "string" && typeof fromCommon.multiSelectAllowed === "boolean") {
|
|
4332
|
+
return {
|
|
4333
|
+
metadataType: fromCommon.metadataTypeCode,
|
|
4334
|
+
displayName: fromCommon.displayName,
|
|
4335
|
+
valueDataType: fromCommon.valueDataType,
|
|
4336
|
+
multiSelectAllowed: fromCommon.multiSelectAllowed,
|
|
4337
|
+
status: typeof fromCommon.status === "string" ? fromCommon.status : "",
|
|
4338
|
+
...typeof fromCommon.required === "boolean" ? { required: fromCommon.required } : {},
|
|
4339
|
+
...typeof fromCommon.isGlobal === "boolean" ? { isGlobal: fromCommon.isGlobal } : {}
|
|
4340
|
+
};
|
|
4341
|
+
}
|
|
4342
|
+
const displayName = file.localizedDisplayName?.["en-US"]?.trim();
|
|
4343
|
+
if (!displayName || typeof file.valueDataType !== "string" || typeof file.multiSelectAllowed !== "boolean") {
|
|
4344
|
+
return null;
|
|
4345
|
+
}
|
|
4346
|
+
return {
|
|
4347
|
+
metadataType: typeCode,
|
|
4348
|
+
displayName,
|
|
4349
|
+
valueDataType: file.valueDataType,
|
|
4350
|
+
multiSelectAllowed: file.multiSelectAllowed,
|
|
4351
|
+
status: ""
|
|
4352
|
+
};
|
|
4353
|
+
}
|
|
4354
|
+
function latestProjectionEntry(record) {
|
|
4355
|
+
return record.versions[String(record.latestVersion)];
|
|
4356
|
+
}
|
|
3831
4357
|
function relatedValueCodesFromEntry(resolver, sourceTypeCode, sourceValueCode, targetTypeCode) {
|
|
3832
4358
|
try {
|
|
3833
4359
|
const entry = resolver.resolve(sourceTypeCode, sourceValueCode);
|
|
@@ -3855,6 +4381,8 @@ var RuntimeMetadataService = class {
|
|
|
3855
4381
|
* for the lifetime of the Lambda execution context.
|
|
3856
4382
|
*/
|
|
3857
4383
|
domainLoadInFlight = /* @__PURE__ */ new Map();
|
|
4384
|
+
/** Coalesce concurrent common.json downloads for the current release. */
|
|
4385
|
+
commonLoadInFlight = null;
|
|
3858
4386
|
/**
|
|
3859
4387
|
* Types soft-skipped for the current release (no manifest integrity entry).
|
|
3860
4388
|
* Prevents ensureProjectionTypesLoaded from retrying unsupported types forever.
|
|
@@ -4147,6 +4675,65 @@ var RuntimeMetadataService = class {
|
|
|
4147
4675
|
await batchPromise;
|
|
4148
4676
|
}
|
|
4149
4677
|
}
|
|
4678
|
+
/**
|
|
4679
|
+
* Ensure `common.json` is cached for the active release.
|
|
4680
|
+
* Published catalog reads use it for type display name, value data type, and multi-select.
|
|
4681
|
+
*/
|
|
4682
|
+
async ensureCommonLoaded() {
|
|
4683
|
+
if (!this.cache.isReady()) {
|
|
4684
|
+
await this.initialize();
|
|
4685
|
+
}
|
|
4686
|
+
for (let attempt = 0; attempt < 3; attempt += 1) {
|
|
4687
|
+
const releaseId = this.cache.getReleaseId();
|
|
4688
|
+
const cached = this.cache.getCommon();
|
|
4689
|
+
if (cached && cached.releaseId === releaseId) {
|
|
4690
|
+
return cached;
|
|
4691
|
+
}
|
|
4692
|
+
if (!this.commonLoadInFlight) {
|
|
4693
|
+
const generation = this.cache.getGeneration();
|
|
4694
|
+
this.commonLoadInFlight = this.downloadAndMergeCommon(
|
|
4695
|
+
releaseId,
|
|
4696
|
+
generation
|
|
4697
|
+
).finally(() => {
|
|
4698
|
+
this.commonLoadInFlight = null;
|
|
4699
|
+
});
|
|
4700
|
+
}
|
|
4701
|
+
await this.commonLoadInFlight;
|
|
4702
|
+
}
|
|
4703
|
+
const common = this.cache.getCommon();
|
|
4704
|
+
if (common && common.releaseId === this.cache.getReleaseId()) {
|
|
4705
|
+
return common;
|
|
4706
|
+
}
|
|
4707
|
+
throw new ProjectionDownloadError(
|
|
4708
|
+
"common.json was not installed in the metadata cache",
|
|
4709
|
+
{
|
|
4710
|
+
retryable: true,
|
|
4711
|
+
metadata: { releaseId: this.cache.getReleaseId() }
|
|
4712
|
+
}
|
|
4713
|
+
);
|
|
4714
|
+
}
|
|
4715
|
+
getRelationshipIndex() {
|
|
4716
|
+
return this.cache.getRelationshipIndex();
|
|
4717
|
+
}
|
|
4718
|
+
async downloadAndMergeCommon(expectedReleaseId, expectedGeneration) {
|
|
4719
|
+
const manifest = this.cache.getManifest();
|
|
4720
|
+
if (!manifest) {
|
|
4721
|
+
throw new ProjectionDownloadError("Projection manifest is not loaded", {
|
|
4722
|
+
retryable: true
|
|
4723
|
+
});
|
|
4724
|
+
}
|
|
4725
|
+
if (expectedReleaseId && (manifest.releaseId !== expectedReleaseId || this.cache.getGeneration() !== expectedGeneration)) {
|
|
4726
|
+
return;
|
|
4727
|
+
}
|
|
4728
|
+
const common = await this.downloader.downloadCommon(manifest);
|
|
4729
|
+
if (expectedReleaseId && (this.cache.getReleaseId() !== expectedReleaseId || this.cache.getGeneration() !== expectedGeneration)) {
|
|
4730
|
+
return;
|
|
4731
|
+
}
|
|
4732
|
+
this.cache.mergeCommon(common, {
|
|
4733
|
+
releaseId: manifest.releaseId,
|
|
4734
|
+
generation: expectedGeneration
|
|
4735
|
+
});
|
|
4736
|
+
}
|
|
4150
4737
|
syncUnsupportedProjectionRelease(releaseId) {
|
|
4151
4738
|
const id = releaseId ?? null;
|
|
4152
4739
|
if (this.unsupportedProjectionReleaseId !== id) {
|
|
@@ -4357,6 +4944,71 @@ var RuntimeMetadataService = class {
|
|
|
4357
4944
|
throw err;
|
|
4358
4945
|
}
|
|
4359
4946
|
}
|
|
4947
|
+
async getRelatedValueGroups(sourceTypeCode, sourceValueCodes, targetTypeCode, options) {
|
|
4948
|
+
try {
|
|
4949
|
+
const provider = await this.activeProvider();
|
|
4950
|
+
const guard = this.currentWriteGuard();
|
|
4951
|
+
const groups = await provider.getRelatedValueGroups(
|
|
4952
|
+
sourceTypeCode,
|
|
4953
|
+
sourceValueCodes,
|
|
4954
|
+
targetTypeCode,
|
|
4955
|
+
options
|
|
4956
|
+
);
|
|
4957
|
+
this.hydrateProviderValues(
|
|
4958
|
+
groups.flatMap((group) => group.values),
|
|
4959
|
+
guard
|
|
4960
|
+
);
|
|
4961
|
+
return groups;
|
|
4962
|
+
} catch (err) {
|
|
4963
|
+
if (await this.tryActivateFallbackFromError(err, "extension-related")) {
|
|
4964
|
+
const fallback = this.metadataProviderFallback;
|
|
4965
|
+
if (fallback) {
|
|
4966
|
+
return fallback.getRelatedValueGroups(
|
|
4967
|
+
sourceTypeCode,
|
|
4968
|
+
sourceValueCodes,
|
|
4969
|
+
targetTypeCode,
|
|
4970
|
+
options
|
|
4971
|
+
);
|
|
4972
|
+
}
|
|
4973
|
+
}
|
|
4974
|
+
throw err;
|
|
4975
|
+
}
|
|
4976
|
+
}
|
|
4977
|
+
async listRelations(query) {
|
|
4978
|
+
try {
|
|
4979
|
+
const provider = await this.activeProvider();
|
|
4980
|
+
const listed = await provider.listRelations(query);
|
|
4981
|
+
if (!listed.supported && this.metadataProviderFallback && provider !== this.metadataProviderFallback) {
|
|
4982
|
+
return this.metadataProviderFallback.listRelations(query);
|
|
4983
|
+
}
|
|
4984
|
+
return listed;
|
|
4985
|
+
} catch (err) {
|
|
4986
|
+
if (await this.tryActivateFallbackFromError(err, "extension-relations")) {
|
|
4987
|
+
const fallback = this.metadataProviderFallback;
|
|
4988
|
+
if (fallback) {
|
|
4989
|
+
return fallback.listRelations(query);
|
|
4990
|
+
}
|
|
4991
|
+
}
|
|
4992
|
+
throw err;
|
|
4993
|
+
}
|
|
4994
|
+
}
|
|
4995
|
+
async listTypeValues(typeCode, options) {
|
|
4996
|
+
try {
|
|
4997
|
+
const provider = await this.activeProvider();
|
|
4998
|
+
const guard = this.currentWriteGuard();
|
|
4999
|
+
const listed = await provider.listTypeValues(typeCode, options);
|
|
5000
|
+
this.hydrateProviderValues(listed?.values ?? [], guard);
|
|
5001
|
+
return listed;
|
|
5002
|
+
} catch (err) {
|
|
5003
|
+
if (await this.tryActivateFallbackFromError(err, "extension-list")) {
|
|
5004
|
+
const fallback = this.metadataProviderFallback;
|
|
5005
|
+
if (fallback) {
|
|
5006
|
+
return fallback.listTypeValues(typeCode, options);
|
|
5007
|
+
}
|
|
5008
|
+
}
|
|
5009
|
+
throw err;
|
|
5010
|
+
}
|
|
5011
|
+
}
|
|
4360
5012
|
getActiveProviderKind() {
|
|
4361
5013
|
return this.providerCoordinator.getActiveKind();
|
|
4362
5014
|
}
|
|
@@ -4644,9 +5296,11 @@ var InMemoryMetadataProvider = class {
|
|
|
4644
5296
|
forcedState;
|
|
4645
5297
|
byKey = /* @__PURE__ */ new Map();
|
|
4646
5298
|
related = /* @__PURE__ */ new Map();
|
|
5299
|
+
relations;
|
|
4647
5300
|
constructor(options = {}) {
|
|
4648
5301
|
this.releaseId = options.releaseId ?? "memory";
|
|
4649
5302
|
this.unavailable = options.unavailable === true;
|
|
5303
|
+
this.relations = options.relations;
|
|
4650
5304
|
for (const record of options.records ?? []) {
|
|
4651
5305
|
const key = formatMetadataReference(record.typeCode, record.valueCode);
|
|
4652
5306
|
this.byKey.set(key, record);
|
|
@@ -4768,6 +5422,22 @@ var InMemoryMetadataProvider = class {
|
|
|
4768
5422
|
unavailable: false
|
|
4769
5423
|
};
|
|
4770
5424
|
}
|
|
5425
|
+
async listRelations(query) {
|
|
5426
|
+
if (this.unavailable) {
|
|
5427
|
+
throw new MetadataProjectionUnavailableError(
|
|
5428
|
+
"In-memory metadata provider is unavailable",
|
|
5429
|
+
{ retryable: true }
|
|
5430
|
+
);
|
|
5431
|
+
}
|
|
5432
|
+
if (!this.relations) {
|
|
5433
|
+
return { releaseId: this.releaseId, supported: false, relations: [] };
|
|
5434
|
+
}
|
|
5435
|
+
return {
|
|
5436
|
+
releaseId: this.releaseId,
|
|
5437
|
+
supported: true,
|
|
5438
|
+
relations: filterTypedRelations(this.relations, query)
|
|
5439
|
+
};
|
|
5440
|
+
}
|
|
4771
5441
|
async getRelatedValues(sourceTypeCode, sourceValueCode, targetTypeCode, options) {
|
|
4772
5442
|
if (this.unavailable) {
|
|
4773
5443
|
throw new MetadataProjectionUnavailableError(
|
|
@@ -4775,6 +5445,33 @@ var InMemoryMetadataProvider = class {
|
|
|
4775
5445
|
{ retryable: true }
|
|
4776
5446
|
);
|
|
4777
5447
|
}
|
|
5448
|
+
return this.relatedValuesFor(sourceTypeCode, sourceValueCode, targetTypeCode, options);
|
|
5449
|
+
}
|
|
5450
|
+
async getRelatedValueGroups(sourceTypeCode, sourceValueCodes, targetTypeCode, options) {
|
|
5451
|
+
if (this.unavailable) {
|
|
5452
|
+
throw new MetadataProjectionUnavailableError(
|
|
5453
|
+
"In-memory metadata provider is unavailable",
|
|
5454
|
+
{ retryable: true }
|
|
5455
|
+
);
|
|
5456
|
+
}
|
|
5457
|
+
if (sourceValueCodes.length === 0) {
|
|
5458
|
+
return [];
|
|
5459
|
+
}
|
|
5460
|
+
const groups = [];
|
|
5461
|
+
for (const sourceValueCode of sourceValueCodes) {
|
|
5462
|
+
groups.push({
|
|
5463
|
+
sourceValueCode,
|
|
5464
|
+
values: await this.relatedValuesFor(
|
|
5465
|
+
sourceTypeCode,
|
|
5466
|
+
sourceValueCode,
|
|
5467
|
+
targetTypeCode,
|
|
5468
|
+
options
|
|
5469
|
+
)
|
|
5470
|
+
});
|
|
5471
|
+
}
|
|
5472
|
+
return groups;
|
|
5473
|
+
}
|
|
5474
|
+
async relatedValuesFor(sourceTypeCode, sourceValueCode, targetTypeCode, options) {
|
|
4778
5475
|
const sourceKey = formatMetadataReference(sourceTypeCode, sourceValueCode);
|
|
4779
5476
|
const targets = this.related.get(sourceKey)?.get(targetTypeCode) ?? [];
|
|
4780
5477
|
const values = [];
|
|
@@ -4786,6 +5483,32 @@ var InMemoryMetadataProvider = class {
|
|
|
4786
5483
|
}
|
|
4787
5484
|
return values;
|
|
4788
5485
|
}
|
|
5486
|
+
async listTypeValues(typeCode, options) {
|
|
5487
|
+
if (this.unavailable) {
|
|
5488
|
+
throw new MetadataProjectionUnavailableError(
|
|
5489
|
+
"In-memory metadata provider is unavailable",
|
|
5490
|
+
{ retryable: true }
|
|
5491
|
+
);
|
|
5492
|
+
}
|
|
5493
|
+
const values = [];
|
|
5494
|
+
for (const record of this.byKey.values()) {
|
|
5495
|
+
if (record.typeCode !== typeCode) {
|
|
5496
|
+
continue;
|
|
5497
|
+
}
|
|
5498
|
+
const value = await this.getValue(record.typeCode, record.valueCode, options);
|
|
5499
|
+
if (value) {
|
|
5500
|
+
values.push(value);
|
|
5501
|
+
}
|
|
5502
|
+
}
|
|
5503
|
+
if (values.length === 0) {
|
|
5504
|
+
return null;
|
|
5505
|
+
}
|
|
5506
|
+
return {
|
|
5507
|
+
releaseId: this.releaseId,
|
|
5508
|
+
values,
|
|
5509
|
+
type: null
|
|
5510
|
+
};
|
|
5511
|
+
}
|
|
4789
5512
|
};
|
|
4790
5513
|
|
|
4791
5514
|
export { CACHE_STATUS, DEFAULT_EXCLUDED_CODE_FIELDS, DEFAULT_PROVIDER_RECOVERY_COOLDOWN_MS, ExtensionMetadataProvider, InMemoryMetadataProvider, InvalidMetadataReferenceError, METADATA_PROJECTIONS_BUCKET_ENV, METADATA_PROVIDER_KIND, ManifestValidationError, MetadataCache, MetadataDownloader, MetadataHealthService, MetadataLoader, MetadataLookupError, MetadataNotReadyError, MetadataProjectionUnavailableError, MetadataRefreshService, MetadataResolver, NON_METADATA_KEYS, PROVIDER_TRANSPORT_STATE, ProjectionDownloadError, ProviderFailoverCoordinator, REFRESH_STATUS, RUNTIME_METADATA_EVENTS, RUNTIME_METADATA_INTEGRATION_TARGETS, RUNTIME_METADATA_TYPE_CODE_ALIASES, RuntimeMetadataError, RuntimeMetadataService, S3MetadataProvider, UnknownMetadataTypeError, WORKFLOW_STEP_RULE_KEYS, canonicalMetadataProjectionsBucketName, collectResponseReferences, collectResponseTypeCodes, createCodeFieldExclusionSet, createRuntimeMetadataFromEnv, defaultExtensionBaseUrl, ensureRuntimeMetadataLoaded, formatMetadataReference, getCandidateTypeCodesForKey, getRuntimeMetadataHealth, getRuntimeMetadataService, hasPotentialMetadata, isCompactMetadataReference, isExtensionEnabled, isExtensionServing, isMetadataProjectionConfigured, isMetadataProjectionsBucketConfigured, isMetadataReference, isMetadataValueObject, isMetadataValueObjectArray, isWorkflowStepRecord, isWorkflowStepRuleField, localizedLabelFromEntry, manifestLocalizationSchema, metadataGroupFromManifest, metadataValueToReference, normalizeRuntimeMetadataTypeCode, onMetadataProjectionCompleted, parseMetadataReference, projectionEntryToMetadataValue, projectionManifestSchema, readMetadataProjectionsBucket, readModelGroupsFromManifest, relatedValueCodes, resetRuntimeMetadataBootstrapState, resolveMetadataProjectionsBucket, resolveRuntimeMetadataConfig, runtimeMetadataConfigSchema, selectMetadataProvider, tryGetRuntimeMetadataService, tryParseMetadataReference, typeCodeFromCodeFieldName };
|