@myvitalrx/metadata-runtime 0.0.0-stage → 1.0.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/README.md +86 -2
- package/dist/index.d.ts +1766 -0
- package/dist/index.js +4793 -0
- package/dist/index.js.map +1 -0
- package/package.json +47 -4
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,1766 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { S3Client } from '@aws-sdk/client-s3';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Runtime metadata SDK observability event names and cache status values.
|
|
6
|
+
* Wire values are camelCase per platform convention.
|
|
7
|
+
*/
|
|
8
|
+
declare const CACHE_STATUS: {
|
|
9
|
+
readonly EMPTY: "empty";
|
|
10
|
+
readonly READY: "ready";
|
|
11
|
+
readonly REFRESHING: "refreshing";
|
|
12
|
+
readonly DEGRADED: "degraded";
|
|
13
|
+
readonly STALE: "stale";
|
|
14
|
+
};
|
|
15
|
+
type CacheStatus = (typeof CACHE_STATUS)[keyof typeof CACHE_STATUS];
|
|
16
|
+
declare const REFRESH_STATUS: {
|
|
17
|
+
readonly IDLE: "idle";
|
|
18
|
+
readonly IN_PROGRESS: "inProgress";
|
|
19
|
+
readonly SUCCEEDED: "succeeded";
|
|
20
|
+
readonly FAILED: "failed";
|
|
21
|
+
};
|
|
22
|
+
type RefreshStatus = (typeof REFRESH_STATUS)[keyof typeof REFRESH_STATUS];
|
|
23
|
+
declare const RUNTIME_METADATA_EVENTS: {
|
|
24
|
+
readonly INIT_START: "runtimeMetadata.init.start";
|
|
25
|
+
readonly INIT_COMPLETE: "runtimeMetadata.init.complete";
|
|
26
|
+
readonly INIT_FAILED: "runtimeMetadata.init.failed";
|
|
27
|
+
readonly REFRESH_START: "runtimeMetadata.refresh.start";
|
|
28
|
+
readonly REFRESH_COMPLETE: "runtimeMetadata.refresh.complete";
|
|
29
|
+
readonly REFRESH_FAILED: "runtimeMetadata.refresh.failed";
|
|
30
|
+
readonly REFRESH_SKIPPED: "runtimeMetadata.refresh.skipped";
|
|
31
|
+
readonly DOWNLOAD_START: "runtimeMetadata.download.start";
|
|
32
|
+
readonly DOWNLOAD_COMPLETE: "runtimeMetadata.download.complete";
|
|
33
|
+
readonly DOWNLOAD_FAILED: "runtimeMetadata.download.failed";
|
|
34
|
+
readonly MANIFEST_LOADED: "runtimeMetadata.manifest.loaded";
|
|
35
|
+
/** Authoritative keys after manifest parse (metadataTypes + lookupIndex type prefixes). */
|
|
36
|
+
readonly PROJECTION_MANIFEST_LOADED: "projection.manifest.loaded";
|
|
37
|
+
/** Per-file download begin. */
|
|
38
|
+
readonly PROJECTION_FILE_LOADING: "projection.file.loading";
|
|
39
|
+
/** Per-file download + parse complete. */
|
|
40
|
+
readonly PROJECTION_FILE_LOADED: "projection.file.loaded";
|
|
41
|
+
/** Selective skip: requested type has no integrity entry in this release. */
|
|
42
|
+
readonly PROJECTION_FILE_SKIPPED: "projection.file.skipped";
|
|
43
|
+
/** Domain type registered into the in-memory cache index. */
|
|
44
|
+
readonly PROJECTION_CACHE_REGISTER: "projection.cache.register";
|
|
45
|
+
/** supportsType decision with availableTypes for diagnosis. */
|
|
46
|
+
readonly PROJECTION_PROVIDER_SUPPORTS_TYPE: "projection.provider.supportsType";
|
|
47
|
+
/** getProjection / soft miss diagnosis. */
|
|
48
|
+
readonly PROJECTION_PROVIDER_GET_PROJECTION: "projection.provider.getProjection";
|
|
49
|
+
/** Post-initialize loaded type catalog. */
|
|
50
|
+
readonly RUNTIME_METADATA_INITIALIZED: "runtime.metadata.initialized";
|
|
51
|
+
readonly LOOKUP_MISS: "runtimeMetadata.lookup.miss";
|
|
52
|
+
readonly PERIODIC_CHECK: "runtimeMetadata.periodic.check";
|
|
53
|
+
readonly CACHE_HIT: "metadata_cache_hit";
|
|
54
|
+
readonly CACHE_MISS: "metadata_cache_miss";
|
|
55
|
+
readonly BATCH_LOOKUP: "metadata_batch_lookup";
|
|
56
|
+
readonly PROVIDER_SELECTED: "runtimeMetadata.provider.selected";
|
|
57
|
+
readonly PROVIDER_FALLBACK: "runtimeMetadata.provider.fallback";
|
|
58
|
+
readonly PROVIDER_RECOVERED: "runtimeMetadata.provider.recovered";
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Caller-supplied configuration. Never reads `process.env` inside the library —
|
|
63
|
+
* domain services / workers pass an options object (same boundary as metadata-projection).
|
|
64
|
+
*/
|
|
65
|
+
declare const runtimeMetadataConfigSchema: z.ZodObject<{
|
|
66
|
+
bucket: z.ZodString;
|
|
67
|
+
prefix: z.ZodOptional<z.ZodString>;
|
|
68
|
+
environment: z.ZodString;
|
|
69
|
+
expectedSchemaVersion: z.ZodOptional<z.ZodNumber>;
|
|
70
|
+
expectedProjectionVersion: z.ZodOptional<z.ZodString>;
|
|
71
|
+
revision: z.ZodOptional<z.ZodString>;
|
|
72
|
+
periodicCheckIntervalMs: z.ZodOptional<z.ZodNumber>;
|
|
73
|
+
}, z.core.$strip>;
|
|
74
|
+
type RuntimeMetadataConfigInput = z.input<typeof runtimeMetadataConfigSchema>;
|
|
75
|
+
type RuntimeMetadataConfig = {
|
|
76
|
+
bucket: string;
|
|
77
|
+
prefix: string;
|
|
78
|
+
environment: string;
|
|
79
|
+
expectedSchemaVersion: number;
|
|
80
|
+
expectedProjectionVersion: string;
|
|
81
|
+
revision?: string;
|
|
82
|
+
periodicCheckIntervalMs: number;
|
|
83
|
+
};
|
|
84
|
+
/**
|
|
85
|
+
* Parse and apply defaults for runtime metadata configuration.
|
|
86
|
+
*/
|
|
87
|
+
declare function resolveRuntimeMetadataConfig(input: RuntimeMetadataConfigInput): RuntimeMetadataConfig;
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Authoritative projections bucket resolution.
|
|
91
|
+
*
|
|
92
|
+
* Canonical name (producer CloudFormation export
|
|
93
|
+
* `{stage}-metadata-projection-runtime-ProjectionsBucketName`):
|
|
94
|
+
* `{stage}-mvx-metadata-projections-bucket`
|
|
95
|
+
*
|
|
96
|
+
* Env precedence is shared by the SDK, S3 fallback, and Lambda Extension.
|
|
97
|
+
*/
|
|
98
|
+
declare const METADATA_PROJECTIONS_BUCKET_ENV: {
|
|
99
|
+
readonly PRIMARY: "METADATA_PROJECTIONS_BUCKET";
|
|
100
|
+
readonly ALTERNATE: "METADATA_PROJECTION_BUCKET";
|
|
101
|
+
readonly LEGACY: "PROJECTION_BUCKET";
|
|
102
|
+
};
|
|
103
|
+
declare function canonicalMetadataProjectionsBucketName(stage: string): string;
|
|
104
|
+
declare function readMetadataProjectionsBucket(env?: NodeJS.ProcessEnv): string;
|
|
105
|
+
declare function resolveMetadataProjectionsBucket(env?: NodeJS.ProcessEnv): string;
|
|
106
|
+
declare function isMetadataProjectionsBucketConfigured(env?: NodeJS.ProcessEnv): boolean;
|
|
107
|
+
|
|
108
|
+
interface AppError extends Error {
|
|
109
|
+
statusCode?: number;
|
|
110
|
+
code?: string;
|
|
111
|
+
details?: {
|
|
112
|
+
code?: string;
|
|
113
|
+
field?: string;
|
|
114
|
+
message: string;
|
|
115
|
+
}[];
|
|
116
|
+
/** When false, consumers must not retry (e.g. validation). When true, safe to retry (e.g. transient upstream). */
|
|
117
|
+
retryable?: boolean;
|
|
118
|
+
metadata?: Record<string, unknown>;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
type BaseErrorOptions = {
|
|
122
|
+
retryable?: boolean;
|
|
123
|
+
metadata?: Record<string, unknown>;
|
|
124
|
+
};
|
|
125
|
+
declare class BaseError extends Error implements AppError {
|
|
126
|
+
statusCode: number;
|
|
127
|
+
code: string;
|
|
128
|
+
details?: {
|
|
129
|
+
code?: string;
|
|
130
|
+
field?: string;
|
|
131
|
+
message: string;
|
|
132
|
+
}[];
|
|
133
|
+
retryable?: boolean;
|
|
134
|
+
metadata?: Record<string, unknown>;
|
|
135
|
+
constructor(message: string, statusCode?: number, code?: string, details?: {
|
|
136
|
+
code?: string;
|
|
137
|
+
field?: string;
|
|
138
|
+
message: string;
|
|
139
|
+
}[], options?: BaseErrorOptions);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Domain error for runtime metadata load / refresh / lookup failures.
|
|
144
|
+
* Extends {@link BaseError} from `@api-hub/utils`.
|
|
145
|
+
*/
|
|
146
|
+
declare class RuntimeMetadataError extends BaseError {
|
|
147
|
+
constructor(message: string, statusCode?: number, code?: string, details?: {
|
|
148
|
+
code?: string;
|
|
149
|
+
field?: string;
|
|
150
|
+
message: string;
|
|
151
|
+
}[], options?: {
|
|
152
|
+
retryable?: boolean;
|
|
153
|
+
metadata?: Record<string, unknown>;
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
/** Manifest JSON failed schema / version / integrity checks. */
|
|
157
|
+
declare class ManifestValidationError extends RuntimeMetadataError {
|
|
158
|
+
constructor(message: string, details?: {
|
|
159
|
+
code?: string;
|
|
160
|
+
field?: string;
|
|
161
|
+
message: string;
|
|
162
|
+
}[]);
|
|
163
|
+
}
|
|
164
|
+
/** Projection file missing, corrupt, or checksum mismatch. */
|
|
165
|
+
declare class ProjectionDownloadError extends RuntimeMetadataError {
|
|
166
|
+
constructor(message: string, options?: {
|
|
167
|
+
retryable?: boolean;
|
|
168
|
+
metadata?: Record<string, unknown>;
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
/** Lookup against an empty / uninitialized cache. */
|
|
172
|
+
declare class MetadataNotReadyError extends RuntimeMetadataError {
|
|
173
|
+
constructor(message?: string);
|
|
174
|
+
}
|
|
175
|
+
/** Code not found in the loaded projection. */
|
|
176
|
+
declare class MetadataLookupError extends RuntimeMetadataError {
|
|
177
|
+
constructor(message: string, options?: {
|
|
178
|
+
metadata?: Record<string, unknown>;
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
/** Requested metadata type is not in the loaded runtime configuration. */
|
|
182
|
+
declare class UnknownMetadataTypeError extends RuntimeMetadataError {
|
|
183
|
+
constructor(metadataType: string, options?: {
|
|
184
|
+
metadata?: Record<string, unknown>;
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Projection snapshot is missing or the extension/S3 store cannot be reached.
|
|
189
|
+
* Distinct from {@link MetadataLookupError} — never report "not found" for
|
|
190
|
+
* infrastructure unavailability.
|
|
191
|
+
*/
|
|
192
|
+
declare class MetadataProjectionUnavailableError extends RuntimeMetadataError {
|
|
193
|
+
constructor(message?: string, options?: {
|
|
194
|
+
retryable?: boolean;
|
|
195
|
+
metadata?: Record<string, unknown>;
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
/** Compact `TypeCode:ValueCode` reference could not be parsed. */
|
|
199
|
+
declare class InvalidMetadataReferenceError extends RuntimeMetadataError {
|
|
200
|
+
constructor(reference: unknown, options?: {
|
|
201
|
+
metadata?: Record<string, unknown>;
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* Projection wire type — any non-empty camelCase (or legacy) identifier.
|
|
207
|
+
*
|
|
208
|
+
* Phase 4: domain Read Models are not limited to a fixed enum. Platform
|
|
209
|
+
* constants in {@link PROJECTION_TYPE} remain available for known files.
|
|
210
|
+
*/
|
|
211
|
+
type ProjectionType = string;
|
|
212
|
+
|
|
213
|
+
/** Applicability stored on VALUE and used for in-memory search filtering. */
|
|
214
|
+
interface Applicability {
|
|
215
|
+
module: string[];
|
|
216
|
+
category: string[];
|
|
217
|
+
condition: string[];
|
|
218
|
+
country: string[];
|
|
219
|
+
language?: string[];
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
* One file entry inside the projection manifest (integrity / download index).
|
|
224
|
+
*/
|
|
225
|
+
interface ProjectionManifestFileEntry {
|
|
226
|
+
fileName: string;
|
|
227
|
+
projectionType: ProjectionType;
|
|
228
|
+
contentHash: string;
|
|
229
|
+
itemCount: number;
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* Resolvable metadata type capability (replaces former runtime-config.json).
|
|
233
|
+
*/
|
|
234
|
+
interface ManifestMetadataTypeEntry {
|
|
235
|
+
/** MetadataTypeCode (e.g. `'Condition'`). */
|
|
236
|
+
typeCode: string;
|
|
237
|
+
/** Projection artifact file name (e.g. `'Condition.json'`). */
|
|
238
|
+
projectionFile: string;
|
|
239
|
+
/** Registry `valueDataType` (`Enum` | `Boolean` | `Text` | `Numeric`). */
|
|
240
|
+
valueDataType?: string;
|
|
241
|
+
/** Registry `multiSelectAllowed`. */
|
|
242
|
+
multiSelectAllowed?: boolean;
|
|
243
|
+
/** Localized display name of the Metadata Type. */
|
|
244
|
+
localizedDisplayName?: Record<string, string>;
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* One lookup-index entry: typeCode + valueCode → projection location.
|
|
248
|
+
*/
|
|
249
|
+
interface ManifestLookupIndexEntry {
|
|
250
|
+
typeCode: string;
|
|
251
|
+
valueCode: string;
|
|
252
|
+
projectionFile: string;
|
|
253
|
+
}
|
|
254
|
+
interface ManifestLocalizationInfo {
|
|
255
|
+
defaultLocale: string;
|
|
256
|
+
supportedLocales: string[];
|
|
257
|
+
files: Record<string, string>;
|
|
258
|
+
}
|
|
259
|
+
/**
|
|
260
|
+
* Projection manifest (manifest.json) — single authoritative runtime configuration
|
|
261
|
+
* for a release: integrity catalog, resolvable types, and lookup index.
|
|
262
|
+
*/
|
|
263
|
+
interface ProjectionManifest {
|
|
264
|
+
releaseId: string;
|
|
265
|
+
environment: string;
|
|
266
|
+
generatedAt: string;
|
|
267
|
+
projectionVersion: string;
|
|
268
|
+
metadataCount: number;
|
|
269
|
+
artifactCount: number;
|
|
270
|
+
contentHash: string;
|
|
271
|
+
/** Ordered list of artifact file names (excluding manifest itself). */
|
|
272
|
+
artifacts: string[];
|
|
273
|
+
/** Detailed file entries with content hashes for integrity checks. */
|
|
274
|
+
files: ProjectionManifestFileEntry[];
|
|
275
|
+
/**
|
|
276
|
+
* Resolvable domain metadata types and their projection files.
|
|
277
|
+
* Consumed by RuntimeMetadataService — not service DTO field names.
|
|
278
|
+
*/
|
|
279
|
+
metadataTypes: Record<string, ManifestMetadataTypeEntry>;
|
|
280
|
+
/**
|
|
281
|
+
* Composite key `${typeCode}:${valueCode}` → projection location.
|
|
282
|
+
* Generated automatically from domain projection records at publish time.
|
|
283
|
+
*/
|
|
284
|
+
lookupIndex: Record<string, ManifestLookupIndexEntry>;
|
|
285
|
+
/**
|
|
286
|
+
* Optional localization projection artifacts published in this release.
|
|
287
|
+
*/
|
|
288
|
+
localization?: ManifestLocalizationInfo;
|
|
289
|
+
/** @deprecated Alias of releaseId. */
|
|
290
|
+
revision: string;
|
|
291
|
+
/** Manifest schema version (2+ includes metadataTypes + lookupIndex). */
|
|
292
|
+
schemaVersion: number;
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
/**
|
|
296
|
+
* Bidirectional O(1) relationship lookup published as `relationship-index.json`.
|
|
297
|
+
*
|
|
298
|
+
* Key: `${sourceTypeCode}:${sourceValueCode}` → target type code → sorted unique
|
|
299
|
+
* target value codes. Both directions of every ACTIVE relation are present.
|
|
300
|
+
*/
|
|
301
|
+
type RelationshipIndex = Record<string, Record<string, string[]>>;
|
|
302
|
+
/**
|
|
303
|
+
* Slim related-value reference on a projection version entry.
|
|
304
|
+
*/
|
|
305
|
+
interface ProjectionRelationship {
|
|
306
|
+
targetMetadataTypeCode: string;
|
|
307
|
+
targetValueCode: string;
|
|
308
|
+
}
|
|
309
|
+
/**
|
|
310
|
+
* One immutable published version of a metadata value inside a projection release.
|
|
311
|
+
* Keyed under `records[code].versions[version]`.
|
|
312
|
+
*/
|
|
313
|
+
interface ProjectionVersionEntry {
|
|
314
|
+
version: number;
|
|
315
|
+
status: string;
|
|
316
|
+
code: string;
|
|
317
|
+
/** Business display name (from registry label). */
|
|
318
|
+
displayName: string;
|
|
319
|
+
/**
|
|
320
|
+
* Alias of displayName for callers that historically used `label`
|
|
321
|
+
* (e.g. runtime-response-projector).
|
|
322
|
+
*/
|
|
323
|
+
label: string;
|
|
324
|
+
/**
|
|
325
|
+
* BCP 47 locale → localized display label (e.g. `{ 'en-US': '…', 'hi-IN': '…' }`).
|
|
326
|
+
* When an English display value exists, `en-US` is populated from displayName
|
|
327
|
+
* (fallback: label). Explicit registry locales are preserved and override defaults.
|
|
328
|
+
* Absent only when there is no English display value and no registry locales.
|
|
329
|
+
*/
|
|
330
|
+
localizedLabels?: Record<string, string>;
|
|
331
|
+
description?: string;
|
|
332
|
+
sortOrder: number;
|
|
333
|
+
isGlobal: boolean;
|
|
334
|
+
attributes: Record<string, unknown>;
|
|
335
|
+
applicability: Applicability;
|
|
336
|
+
relationships?: ProjectionRelationship[];
|
|
337
|
+
}
|
|
338
|
+
/**
|
|
339
|
+
* @deprecated Prefer {@link ProjectionVersionEntry}. Kept as an alias for consumers.
|
|
340
|
+
*/
|
|
341
|
+
type ProjectionEntry = ProjectionVersionEntry;
|
|
342
|
+
/**
|
|
343
|
+
* Versioned record for a single business code (O(1) lookup by code).
|
|
344
|
+
*/
|
|
345
|
+
interface ProjectionRecord {
|
|
346
|
+
latestVersion: number;
|
|
347
|
+
publishedVersion: number;
|
|
348
|
+
versions: Record<string, ProjectionVersionEntry>;
|
|
349
|
+
}
|
|
350
|
+
/**
|
|
351
|
+
* Shared envelope fields stamped on every projection artifact.
|
|
352
|
+
*/
|
|
353
|
+
interface ProjectionEnvelope {
|
|
354
|
+
metadataType: ProjectionType;
|
|
355
|
+
environment: string;
|
|
356
|
+
releaseId: string;
|
|
357
|
+
generatedAt: string;
|
|
358
|
+
projectionVersion: string;
|
|
359
|
+
contentHash: string;
|
|
360
|
+
metadataCount: number;
|
|
361
|
+
}
|
|
362
|
+
/**
|
|
363
|
+
* Locale-keyed display text on a Metadata Type or Metadata Value.
|
|
364
|
+
* Canonical projection property for localized display — not for business logic.
|
|
365
|
+
*/
|
|
366
|
+
interface LocalizedDisplayName {
|
|
367
|
+
'en-US': string;
|
|
368
|
+
'hi-IN': string;
|
|
369
|
+
}
|
|
370
|
+
/**
|
|
371
|
+
* Consumption view of {@link ProjectionVersionEntry}.
|
|
372
|
+
* `displayName` is the locale-resolved display text.
|
|
373
|
+
*/
|
|
374
|
+
type ResolvedProjectionEntry = ProjectionVersionEntry & {
|
|
375
|
+
displayName: string;
|
|
376
|
+
};
|
|
377
|
+
/**
|
|
378
|
+
* Single domain projection file payload (e.g. metric.json).
|
|
379
|
+
*/
|
|
380
|
+
interface ProjectionFile extends ProjectionEnvelope {
|
|
381
|
+
/** Localized display name of the Metadata Type this file represents. */
|
|
382
|
+
localizedDisplayName?: LocalizedDisplayName;
|
|
383
|
+
/** Registry `valueDataType` (`Enum` | `Boolean` | `Text` | `Numeric`). */
|
|
384
|
+
valueDataType?: string;
|
|
385
|
+
/** Registry `multiSelectAllowed`. */
|
|
386
|
+
multiSelectAllowed?: boolean;
|
|
387
|
+
records: Record<string, ProjectionRecord>;
|
|
388
|
+
}
|
|
389
|
+
/**
|
|
390
|
+
* Cross-cutting common projection (common.json).
|
|
391
|
+
*/
|
|
392
|
+
interface CommonProjectionFile extends ProjectionEnvelope {
|
|
393
|
+
metadataType: 'common';
|
|
394
|
+
types: Array<{
|
|
395
|
+
metadataTypeCode: string;
|
|
396
|
+
displayName: string;
|
|
397
|
+
version: number;
|
|
398
|
+
status: string;
|
|
399
|
+
valueDataType: string;
|
|
400
|
+
multiSelectAllowed: boolean;
|
|
401
|
+
applicableModules: string[];
|
|
402
|
+
}>;
|
|
403
|
+
modules: string[];
|
|
404
|
+
}
|
|
405
|
+
/**
|
|
406
|
+
* Active-release pointer object (`current.json`).
|
|
407
|
+
*/
|
|
408
|
+
interface ProjectionCurrentPointer {
|
|
409
|
+
currentRelease: string;
|
|
410
|
+
generatedAt: string;
|
|
411
|
+
projectionVersion: string;
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
interface LogEntry {
|
|
415
|
+
event?: string;
|
|
416
|
+
message?: string;
|
|
417
|
+
err?: unknown;
|
|
418
|
+
error?: unknown;
|
|
419
|
+
[key: string]: unknown;
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
/**
|
|
423
|
+
* Structured logger compatible with legacy `@api-hub/logger` {@link LogEntry} call style
|
|
424
|
+
* (`logger.info({ event: 'x', ... } )`), backed by {@link getLogger} and AsyncLocalStorage context.
|
|
425
|
+
*/
|
|
426
|
+
declare class StructuredLogger {
|
|
427
|
+
private readonly persistentKeys;
|
|
428
|
+
constructor(persistentKeys?: Record<string, unknown>);
|
|
429
|
+
getPersistentKeys(): Record<string, unknown>;
|
|
430
|
+
info(entry: LogEntry): void;
|
|
431
|
+
warn(entry: LogEntry): void;
|
|
432
|
+
error(entry: LogEntry): void;
|
|
433
|
+
debug(entry: LogEntry): void;
|
|
434
|
+
http(entry: LogEntry): void;
|
|
435
|
+
verbose(entry: LogEntry): void;
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
/**
|
|
439
|
+
* Platform abstraction: a fully downloaded release bundle ready for atomic cache replace.
|
|
440
|
+
*
|
|
441
|
+
* Phase 5: {@link LoadedProjectionBundle} is the metadata specialization.
|
|
442
|
+
* Future LocalizationBundle / ThemeBundle should satisfy the same shape.
|
|
443
|
+
*
|
|
444
|
+
* Cache.replace(bundle) semantics remain atomic snapshot swap — unchanged.
|
|
445
|
+
*/
|
|
446
|
+
interface ReadModelBundle<TManifest = unknown, TArtifact = unknown> {
|
|
447
|
+
/** Alias of releaseId (legacy revision naming). */
|
|
448
|
+
readonly revision: string;
|
|
449
|
+
readonly releaseId: string;
|
|
450
|
+
readonly manifest: TManifest;
|
|
451
|
+
/**
|
|
452
|
+
* Group artifacts keyed by read-model identity.
|
|
453
|
+
* Metadata specialization exposes the same Map as `domainFiles` (typeCode → file).
|
|
454
|
+
*/
|
|
455
|
+
readonly domainFiles: Map<string, TArtifact>;
|
|
456
|
+
readonly loadedFiles: readonly string[] | string[];
|
|
457
|
+
readonly downloadedAt: string;
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
/**
|
|
461
|
+
* Resolvable metadata type codes from the loaded manifest.
|
|
462
|
+
* Not limited to a compile-time enum — new types appear when projection publishes them.
|
|
463
|
+
*/
|
|
464
|
+
type ResolvableMetadataType = string;
|
|
465
|
+
/**
|
|
466
|
+
* Immutable snapshot held by {@link MetadataCache}.
|
|
467
|
+
* Never mutate maps or entries after construction — replace the whole snapshot.
|
|
468
|
+
*
|
|
469
|
+
* Phase 5: metadata specialization of a generic read-model snapshot.
|
|
470
|
+
*/
|
|
471
|
+
type MetadataCacheSnapshot = {
|
|
472
|
+
readonly revision: string;
|
|
473
|
+
readonly releaseId: string;
|
|
474
|
+
readonly contentHash: string;
|
|
475
|
+
readonly schemaVersion: number;
|
|
476
|
+
readonly projectionVersion: string;
|
|
477
|
+
readonly generatedAt: string;
|
|
478
|
+
readonly loadedAt: string;
|
|
479
|
+
readonly loadedFiles: readonly string[];
|
|
480
|
+
readonly domainFiles: ReadonlyMap<string, ProjectionFile>;
|
|
481
|
+
readonly common?: CommonProjectionFile;
|
|
482
|
+
readonly relationshipIndex?: RelationshipIndex;
|
|
483
|
+
readonly manifest: ProjectionManifest;
|
|
484
|
+
readonly localization?: ReadonlyMap<string, ReadonlyMap<string, string>>;
|
|
485
|
+
};
|
|
486
|
+
/** Health / diagnostics surface for ops and health endpoints. */
|
|
487
|
+
type MetadataHealthReport = {
|
|
488
|
+
projectionVersion: string;
|
|
489
|
+
metadataRevision: string;
|
|
490
|
+
contentHash: string | null;
|
|
491
|
+
schemaVersion: number | null;
|
|
492
|
+
lastRefreshTime: string | null;
|
|
493
|
+
loadedFiles: readonly string[];
|
|
494
|
+
cacheStatus: CacheStatus;
|
|
495
|
+
refreshStatus: RefreshStatus;
|
|
496
|
+
lastRefreshError: string | null;
|
|
497
|
+
cacheAgeMs: number | null;
|
|
498
|
+
};
|
|
499
|
+
/**
|
|
500
|
+
* Result of a successful metadata load pipeline (manifest + projection files).
|
|
501
|
+
*
|
|
502
|
+
* Phase 5: concrete {@link ReadModelBundle} for the metadata read model.
|
|
503
|
+
* Field names and shape are unchanged for backward compatibility.
|
|
504
|
+
*/
|
|
505
|
+
type LoadedProjectionBundle = ReadModelBundle<ProjectionManifest, ProjectionFile> & {
|
|
506
|
+
common?: CommonProjectionFile;
|
|
507
|
+
relationshipIndex?: RelationshipIndex;
|
|
508
|
+
localization?: Map<string, Map<string, string>>;
|
|
509
|
+
loadedFiles: string[];
|
|
510
|
+
};
|
|
511
|
+
|
|
512
|
+
interface MetadataReference {
|
|
513
|
+
typeCode: string;
|
|
514
|
+
valueCode: string;
|
|
515
|
+
/**
|
|
516
|
+
* Locale → label map from the published projection.
|
|
517
|
+
* Omitted on wire references before enrichment; set by the response mapper.
|
|
518
|
+
*/
|
|
519
|
+
localizedLabels?: {
|
|
520
|
+
'en-US': string;
|
|
521
|
+
[locale: string]: string;
|
|
522
|
+
};
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
declare function isMetadataReference(value: unknown): value is MetadataReference;
|
|
526
|
+
|
|
527
|
+
/**
|
|
528
|
+
* Type guard for the `{ labelKey, value }` metadata value object representation.
|
|
529
|
+
*
|
|
530
|
+
* Supported formats:
|
|
531
|
+
* - `{ labelKey: "Chronic", value: "CHRONIC" }`
|
|
532
|
+
* - `{ labelKey: null, value: "CHRONIC" }`
|
|
533
|
+
* - `{ value: "CHRONIC" }` when validated against a metadata-backed field
|
|
534
|
+
*/
|
|
535
|
+
declare function isMetadataValueObject(val: unknown): val is {
|
|
536
|
+
value: string;
|
|
537
|
+
labelKey?: string | null;
|
|
538
|
+
};
|
|
539
|
+
/**
|
|
540
|
+
* Type guard for an array of `{ labelKey, value }` metadata value objects.
|
|
541
|
+
*/
|
|
542
|
+
declare function isMetadataValueObjectArray(val: unknown): val is Array<{
|
|
543
|
+
value: string;
|
|
544
|
+
labelKey?: string | null;
|
|
545
|
+
}>;
|
|
546
|
+
|
|
547
|
+
type CandidateDiagnostic = {
|
|
548
|
+
fieldPath: string;
|
|
549
|
+
strategy: 'metadata_reference' | 'value_object' | 'value_object_array' | 'code_field_convention' | 'naked_known_type';
|
|
550
|
+
candidateTypeCode: string;
|
|
551
|
+
accepted: boolean;
|
|
552
|
+
reason?: string;
|
|
553
|
+
};
|
|
554
|
+
type CollectMetadataDiagnostics = {
|
|
555
|
+
candidateFields: CandidateDiagnostic[];
|
|
556
|
+
totalCandidatesDiscovered: number;
|
|
557
|
+
totalUniqueTypesDiscovered: number;
|
|
558
|
+
totalUniqueTypeValuesDiscovered: number;
|
|
559
|
+
};
|
|
560
|
+
type CollectResponseMetadataOptions = {
|
|
561
|
+
/**
|
|
562
|
+
* Extra DTO field names that must not be treated as metadata `*Code` fields.
|
|
563
|
+
*/
|
|
564
|
+
excludedCodeFields?: Iterable<string>;
|
|
565
|
+
/**
|
|
566
|
+
* Known/supported metadata type codes to match against naked field names.
|
|
567
|
+
*/
|
|
568
|
+
knownTypes?: readonly string[] | Set<string>;
|
|
569
|
+
/**
|
|
570
|
+
* Optional diagnostics accumulator for detailed tracing.
|
|
571
|
+
*/
|
|
572
|
+
diagnostics?: CollectMetadataDiagnostics;
|
|
573
|
+
};
|
|
574
|
+
/**
|
|
575
|
+
* Recursively collect unique MetadataTypeCode values from:
|
|
576
|
+
* - explicit `{ typeCode, valueCode }` MetadataReference objects
|
|
577
|
+
* - explicit `{ labelKey, value }` metadata value objects
|
|
578
|
+
* - string `*Code` fields (`metricCode` → `MetricCode`)
|
|
579
|
+
* - naked metadata fields when knownTypes are provided (`category` → `Category`)
|
|
580
|
+
*
|
|
581
|
+
* Type codes are canonicalized (e.g. `Speciality` → `Specialty`) so selective
|
|
582
|
+
* downloads request the published projection file name.
|
|
583
|
+
*/
|
|
584
|
+
declare function collectResponseTypeCodes(value: unknown, options?: CollectResponseMetadataOptions): string[];
|
|
585
|
+
/**
|
|
586
|
+
* Collect unique `{ typeCode, valueCode }` references from a response DTO tree.
|
|
587
|
+
* Used by batch lookup so one extension request covers every field.
|
|
588
|
+
*
|
|
589
|
+
* Explicit MetadataReference.typeCode always wins over field-name inference.
|
|
590
|
+
*/
|
|
591
|
+
declare function collectResponseReferences(value: unknown, options?: CollectResponseMetadataOptions): MetadataReference[];
|
|
592
|
+
declare function getCandidateTypeCodesForKey(key: string): string[];
|
|
593
|
+
/**
|
|
594
|
+
* Fast inspection to determine if a response payload might contain
|
|
595
|
+
* any metadata references, { labelKey, value } metadata objects,
|
|
596
|
+
* or naked metadata codes before initiating network downloads.
|
|
597
|
+
*/
|
|
598
|
+
declare function hasPotentialMetadata(value: unknown): boolean;
|
|
599
|
+
|
|
600
|
+
/**
|
|
601
|
+
* Wire / Excel may use British spelling `Speciality`. Canonical MetadataTypeCode
|
|
602
|
+
* (and projection file name) is `Specialty`.
|
|
603
|
+
*/
|
|
604
|
+
declare const RUNTIME_METADATA_TYPE_CODE_ALIASES: Readonly<Record<string, string>>;
|
|
605
|
+
/**
|
|
606
|
+
* Normalize a MetadataTypeCode for projection download + lookup.
|
|
607
|
+
* Exact match preferred otherwise — only intentional aliases live here.
|
|
608
|
+
*/
|
|
609
|
+
declare function normalizeRuntimeMetadataTypeCode(metadataTypeCode: string): string;
|
|
610
|
+
|
|
611
|
+
/**
|
|
612
|
+
* Compact metadata identity: `{typeCode}:{valueCode}`.
|
|
613
|
+
*
|
|
614
|
+
* Type codes are exact MetadataTypeCode values (`Condition`, `MetricCode`).
|
|
615
|
+
* Value codes may contain additional `:` characters; only the first colon
|
|
616
|
+
* separates type from value. Malformed strings throw — they are never coerced.
|
|
617
|
+
*/
|
|
618
|
+
declare function parseMetadataReference(reference: string): MetadataReference;
|
|
619
|
+
/**
|
|
620
|
+
* Parse a compact reference without throwing.
|
|
621
|
+
* Returns null for blank / missing-colon / empty-segment input.
|
|
622
|
+
*/
|
|
623
|
+
declare function tryParseMetadataReference(reference: string | null | undefined): MetadataReference | null;
|
|
624
|
+
declare function formatMetadataReference(typeCode: string, valueCode: string): string;
|
|
625
|
+
declare function isCompactMetadataReference(value: unknown): value is string;
|
|
626
|
+
|
|
627
|
+
/**
|
|
628
|
+
* Field names that look like `*Code` but are structural / address / protocol
|
|
629
|
+
* fields, not metadata ValueCode carriers.
|
|
630
|
+
*/
|
|
631
|
+
declare const DEFAULT_EXCLUDED_CODE_FIELDS: readonly ["typeCode", "valueCode", "metadataTypeCode", "metadataValueCode", "targetValueCode", "targetMetadataTypeCode", "fromMetadataTypeCode", "fromMetadataValueCode", "toMetadataTypeCode", "toMetadataValueCode", "postalCode", "zipCode", "areaCode", "countryCallingCode", "phoneCountryCode", "dialCode", "hashCode", "errorCode", "httpStatusCode", "statusCode"];
|
|
632
|
+
declare const NON_METADATA_KEYS: Set<string>;
|
|
633
|
+
/**
|
|
634
|
+
* Names that match a metadata type only when the parent is a workflow step.
|
|
635
|
+
* `condition` on a step is a rule expression, not Condition metadata.
|
|
636
|
+
*/
|
|
637
|
+
declare const WORKFLOW_STEP_RULE_KEYS: Set<string>;
|
|
638
|
+
/**
|
|
639
|
+
* A workflow step record carries the rule field `condition` beside step structure.
|
|
640
|
+
*/
|
|
641
|
+
declare function isWorkflowStepRecord(node: Record<string, unknown>): boolean;
|
|
642
|
+
/**
|
|
643
|
+
* True when `key` is a workflow rule on a step and must not be resolved as metadata.
|
|
644
|
+
*/
|
|
645
|
+
declare function isWorkflowStepRuleField(key: string, parent: Record<string, unknown>): boolean;
|
|
646
|
+
/**
|
|
647
|
+
* Map a DTO field name to MetadataTypeCode when the `*Code` convention applies.
|
|
648
|
+
*
|
|
649
|
+
* `metricCode` → `MetricCode`
|
|
650
|
+
* `conditionCode` → `ConditionCode`
|
|
651
|
+
* `questionCode` → `QuestionCode`
|
|
652
|
+
*
|
|
653
|
+
* Returns undefined for non-code fields, excluded names, and empty input.
|
|
654
|
+
* Fields ending in `__Code` (DUAL_FIELD enrichment siblings) are always skipped.
|
|
655
|
+
*/
|
|
656
|
+
declare function typeCodeFromCodeFieldName(fieldName: string, excluded?: ReadonlySet<string>): string | undefined;
|
|
657
|
+
declare function createCodeFieldExclusionSet(extra?: Iterable<string>): Set<string>;
|
|
658
|
+
|
|
659
|
+
/**
|
|
660
|
+
* Extension-point vocabulary for runtime read-model families.
|
|
661
|
+
*
|
|
662
|
+
* Phase 5: types only — Metadata remains the sole concrete group.
|
|
663
|
+
* Future Localization / Country / Organization / Theme services plug in
|
|
664
|
+
* using the same {@link ReadModelCache} / {@link ReadModelDownloader} contracts.
|
|
665
|
+
*/
|
|
666
|
+
type ReadModelGroupId = 'metadata' | 'localization' | 'country' | 'organization' | 'theme' | (string & {});
|
|
667
|
+
/**
|
|
668
|
+
* Descriptor for a read-model family at runtime.
|
|
669
|
+
* Reserved for future multi-group registration — not consumed by MetadataCache today.
|
|
670
|
+
*/
|
|
671
|
+
interface ReadModelGroupDescriptor {
|
|
672
|
+
/** Read-model family id. */
|
|
673
|
+
readonly groupId: ReadModelGroupId;
|
|
674
|
+
/** Schema version for this family (independent of metadata projection schemaVersion). */
|
|
675
|
+
readonly schemaVersion: number;
|
|
676
|
+
/** Optional operator-facing label. */
|
|
677
|
+
readonly label?: string;
|
|
678
|
+
}
|
|
679
|
+
|
|
680
|
+
/**
|
|
681
|
+
* Platform abstraction: one downloaded / cached read-model artifact.
|
|
682
|
+
*
|
|
683
|
+
* Phase 5: Metadata maps this to a domain projection file (typeCode → ProjectionFile).
|
|
684
|
+
* Future Localization artifacts may key by locale / message namespace.
|
|
685
|
+
*
|
|
686
|
+
* Behaviour of MetadataDownloader / MetadataCache is unchanged — this is vocabulary only.
|
|
687
|
+
*/
|
|
688
|
+
interface ReadModelArtifact<TPayload = unknown> {
|
|
689
|
+
/**
|
|
690
|
+
* Identity within the read-model group.
|
|
691
|
+
* Metadata: typeCode (e.g. `'Condition'`).
|
|
692
|
+
*/
|
|
693
|
+
readonly key: string;
|
|
694
|
+
/** Artifact file name within the release (e.g. `'Condition.json'`). */
|
|
695
|
+
readonly fileName: string;
|
|
696
|
+
/** Optional integrity hash from the manifest file entry. */
|
|
697
|
+
readonly contentHash?: string;
|
|
698
|
+
/** Owning group — defaults to metadata for the current runtime. */
|
|
699
|
+
readonly groupId?: ReadModelGroupId;
|
|
700
|
+
/** Parsed artifact body. */
|
|
701
|
+
readonly payload: TPayload;
|
|
702
|
+
}
|
|
703
|
+
|
|
704
|
+
/**
|
|
705
|
+
* Platform abstraction: immutable in-memory read-model cache with atomic
|
|
706
|
+
* snapshot replacement.
|
|
707
|
+
*
|
|
708
|
+
* Phase 5: implemented by {@link MetadataCache} (unchanged behaviour).
|
|
709
|
+
* Metadata is one Read Model; Localization / Theme / etc. reuse this contract
|
|
710
|
+
* without redesigning the cache.
|
|
711
|
+
*
|
|
712
|
+
* Guarantees (must not change):
|
|
713
|
+
* - Atomic snapshot replace (readers never see a partial install)
|
|
714
|
+
* - Refresh failures must NOT clear a healthy prior snapshot
|
|
715
|
+
* - O(1) resolve stays on the resolver + lookupIndex — not the cache API
|
|
716
|
+
*/
|
|
717
|
+
interface ReadModelCache<TSnapshot = unknown, TManifest = unknown, TBundle = unknown, TStatus = CacheStatus> {
|
|
718
|
+
getStatus(): TStatus;
|
|
719
|
+
setStatus(status: TStatus): void;
|
|
720
|
+
isReady(): boolean;
|
|
721
|
+
getSnapshot(): TSnapshot | null;
|
|
722
|
+
getManifest(): TManifest | null;
|
|
723
|
+
/**
|
|
724
|
+
* Atomically replace the entire cache from a downloaded bundle.
|
|
725
|
+
* Previous snapshot is discarded (not mutated).
|
|
726
|
+
*/
|
|
727
|
+
replace(bundle: TBundle): TSnapshot;
|
|
728
|
+
/**
|
|
729
|
+
* Clear only when explicitly requested (e.g. tests).
|
|
730
|
+
* Refresh failures must NOT clear a healthy prior snapshot.
|
|
731
|
+
*/
|
|
732
|
+
clear(): void;
|
|
733
|
+
}
|
|
734
|
+
|
|
735
|
+
/**
|
|
736
|
+
* Extension point: future runtimes may load multiple read-model groups
|
|
737
|
+
* without redesigning {@link ReadModelCache.replace}.
|
|
738
|
+
*
|
|
739
|
+
* Phase 5: **types only** — MetadataCache continues to load a single metadata
|
|
740
|
+
* bundle via `replace(LoadedProjectionBundle)`.
|
|
741
|
+
*
|
|
742
|
+
* Current load path (unchanged):
|
|
743
|
+
* ```text
|
|
744
|
+
* current.json → manifest.json → projection files → MetadataCache.replace
|
|
745
|
+
* ```
|
|
746
|
+
*
|
|
747
|
+
* Future multi-group path (not implemented):
|
|
748
|
+
* ```text
|
|
749
|
+
* current.json → manifest (groups) → per-group artifacts → loadGroup × N
|
|
750
|
+
* ```
|
|
751
|
+
*/
|
|
752
|
+
interface ReadModelCacheLoader {
|
|
753
|
+
/**
|
|
754
|
+
* Install one read-model group into the cache strategy.
|
|
755
|
+
* Metadata today uses a full atomic `replace` instead of this method.
|
|
756
|
+
*/
|
|
757
|
+
loadGroup(groupId: ReadModelGroupId, bundle: ReadModelBundle): void;
|
|
758
|
+
}
|
|
759
|
+
|
|
760
|
+
/**
|
|
761
|
+
* Platform abstraction: resolve active release → validate manifest → bootstrap artifacts.
|
|
762
|
+
*
|
|
763
|
+
* Implemented by {@link MetadataDownloader}. Future LocalizationDownloader should
|
|
764
|
+
* implement the same contract against its storage.
|
|
765
|
+
*
|
|
766
|
+
* Pipeline:
|
|
767
|
+
* ```text
|
|
768
|
+
* current.json → manifest.json (release / integrity / lookupIndex / metadataTypes)
|
|
769
|
+
* Domain files: `{MetadataTypeCode}.json` on demand (not via this interface)
|
|
770
|
+
* ```
|
|
771
|
+
*
|
|
772
|
+
* Manifest is **not** used for projection filename discovery (`typeCode` → `{typeCode}.json`).
|
|
773
|
+
* `common.json` is not required for HTTP response enrichment.
|
|
774
|
+
*/
|
|
775
|
+
interface ReadModelDownloader<TBundle = unknown, TManifest = unknown> {
|
|
776
|
+
/** Resolve the active release via the current pointer (`current.json`). */
|
|
777
|
+
discoverLatestRevision(): Promise<string>;
|
|
778
|
+
/** Download + validate the authoritative manifest for a release. */
|
|
779
|
+
downloadManifest(releaseId: string): Promise<TManifest>;
|
|
780
|
+
/**
|
|
781
|
+
* Bootstrap only: current.json (if needed) → manifest.json.
|
|
782
|
+
* Domain projection files are loaded on demand by MetadataTypeCode.
|
|
783
|
+
*/
|
|
784
|
+
loadBootstrap(releaseId?: string): Promise<TBundle>;
|
|
785
|
+
/**
|
|
786
|
+
* Bootstrap from an already-fetched manifest (no common.json / domain files).
|
|
787
|
+
*/
|
|
788
|
+
downloadBootstrapBundle(manifest: TManifest): Promise<TBundle>;
|
|
789
|
+
}
|
|
790
|
+
|
|
791
|
+
/**
|
|
792
|
+
* Extension point for future multi-group manifests.
|
|
793
|
+
*
|
|
794
|
+
* **Do not change** the on-wire `ProjectionManifest` format in this phase.
|
|
795
|
+
* Today's manifest is equivalent to the `metadata` group only
|
|
796
|
+
* (`metadataTypes` + `lookupIndex` at the top level).
|
|
797
|
+
*
|
|
798
|
+
* Future publishers may nest additional groups without redesigning the cache:
|
|
799
|
+
*
|
|
800
|
+
* ```text
|
|
801
|
+
* manifest.json
|
|
802
|
+
* metadataTypes / lookupIndex ← current (metadata group)
|
|
803
|
+
* // future (additive):
|
|
804
|
+
* groups?: {
|
|
805
|
+
* localization?: { … }
|
|
806
|
+
* country?: { … }
|
|
807
|
+
* organization?: { … }
|
|
808
|
+
* theme?: { … }
|
|
809
|
+
* }
|
|
810
|
+
* ```
|
|
811
|
+
*/
|
|
812
|
+
interface ReadModelManifestGroupView {
|
|
813
|
+
readonly metadataTypes: Readonly<Record<string, ManifestMetadataTypeEntry>>;
|
|
814
|
+
readonly lookupIndex: Readonly<Record<string, ManifestLookupIndexEntry>>;
|
|
815
|
+
}
|
|
816
|
+
/**
|
|
817
|
+
* Conceptual multi-group manifest view.
|
|
818
|
+
* Not serialized today — documents how future groups attach without a cache redesign.
|
|
819
|
+
*/
|
|
820
|
+
type ReadModelManifestGroups = Partial<Record<ReadModelGroupId, unknown>> & {
|
|
821
|
+
/** Current projection manifest metadata surface. */
|
|
822
|
+
metadata?: ReadModelManifestGroupView;
|
|
823
|
+
};
|
|
824
|
+
/**
|
|
825
|
+
* View the authoritative flat manifest as the metadata read-model group.
|
|
826
|
+
* Pure adapter — does not allocate a new lookup strategy.
|
|
827
|
+
*/
|
|
828
|
+
declare function metadataGroupFromManifest(manifest: ProjectionManifest): ReadModelManifestGroupView;
|
|
829
|
+
/**
|
|
830
|
+
* Build a conceptual multi-group view from the current flat manifest.
|
|
831
|
+
* Only the `metadata` group is populated today.
|
|
832
|
+
*/
|
|
833
|
+
declare function readModelGroupsFromManifest(manifest: ProjectionManifest): ReadModelManifestGroups;
|
|
834
|
+
|
|
835
|
+
/**
|
|
836
|
+
* Platform abstraction: runtime façade that loads, caches, and resolves a
|
|
837
|
+
* read model for domain services.
|
|
838
|
+
*
|
|
839
|
+
* Phase 5: implemented by {@link RuntimeMetadataService}.
|
|
840
|
+
* Domain services depend on this provider (or the concrete metadata service);
|
|
841
|
+
* they must not depend on {@link ReadModelCache} / storage directly.
|
|
842
|
+
*
|
|
843
|
+
* Future LocalizationRuntimeService / CountryRuntimeService should implement
|
|
844
|
+
* the same contract — do not redesign RuntimeMetadataService public API.
|
|
845
|
+
*/
|
|
846
|
+
interface ReadModelProvider<TEntry = unknown> {
|
|
847
|
+
/** Startup: load read-model artifacts into cache. */
|
|
848
|
+
initialize(revision?: string): Promise<void>;
|
|
849
|
+
/** Generic resolve by typeCode and valueCode. */
|
|
850
|
+
resolve(typeCode: string, valueCode: string, version?: number): TEntry;
|
|
851
|
+
/** Resolve using an explicit {@link MetadataReference}. */
|
|
852
|
+
resolve(reference: MetadataReference, version?: number): TEntry;
|
|
853
|
+
/** Whether the given type is resolvable from the current loaded manifest. */
|
|
854
|
+
supportsType(typeCode: string): boolean;
|
|
855
|
+
/** Soft health check for middleware enrichment skip. */
|
|
856
|
+
isHealthy(): boolean;
|
|
857
|
+
}
|
|
858
|
+
|
|
859
|
+
/**
|
|
860
|
+
* Platform abstraction: startup / event / periodic cache refresh.
|
|
861
|
+
*
|
|
862
|
+
* Phase 5: implemented by {@link MetadataRefreshService} (behaviour unchanged).
|
|
863
|
+
* Future Localization refresh must reuse the same coordinator contract —
|
|
864
|
+
* graceful degradation, atomic replace, no clear-on-failure.
|
|
865
|
+
*/
|
|
866
|
+
interface ReadModelRefreshCoordinator {
|
|
867
|
+
/** Startup: load artifacts into cache. */
|
|
868
|
+
initialize(revision?: string): Promise<void>;
|
|
869
|
+
/**
|
|
870
|
+
* Event-driven reload (e.g. MetadataProjectionCompleted).
|
|
871
|
+
* Returns true when the cache was updated.
|
|
872
|
+
*/
|
|
873
|
+
refreshFromEvent(releaseId?: string): Promise<boolean>;
|
|
874
|
+
/**
|
|
875
|
+
* Periodic / manual check + conditional reload.
|
|
876
|
+
* Returns true when the cache was updated.
|
|
877
|
+
*/
|
|
878
|
+
checkAndRefresh(revision?: string): Promise<boolean>;
|
|
879
|
+
startPeriodicCheck(intervalMs: number): void;
|
|
880
|
+
stopPeriodicCheck(): void;
|
|
881
|
+
}
|
|
882
|
+
|
|
883
|
+
/**
|
|
884
|
+
* Platform abstraction: O(1) resolve against a loaded read-model cache.
|
|
885
|
+
*
|
|
886
|
+
* Phase 5: implemented by {@link MetadataResolver}.
|
|
887
|
+
* Lookup strategy (manifest.lookupIndex → domain file records) is unchanged.
|
|
888
|
+
* Future LocalizationRuntimeService should expose an equivalent resolve surface
|
|
889
|
+
* (typeCode / valueCode or locale-equivalent keys) without changing LookupIndex.
|
|
890
|
+
*/
|
|
891
|
+
interface ReadModelResolver<TEntry = unknown> {
|
|
892
|
+
/**
|
|
893
|
+
* Generic resolve by typeCode and valueCode.
|
|
894
|
+
*/
|
|
895
|
+
resolve(typeCode: string, valueCode: string, version?: number): TEntry;
|
|
896
|
+
/** Resolve using an explicit {@link MetadataReference}. */
|
|
897
|
+
resolve(reference: MetadataReference, version?: number): TEntry;
|
|
898
|
+
/** Whether the given type is resolvable from the current loaded manifest. */
|
|
899
|
+
supportsType(typeCode: string): boolean;
|
|
900
|
+
/**
|
|
901
|
+
* Types available for resolve from the loaded manifest.
|
|
902
|
+
* Metadata specialization: keys of `manifest.metadataTypes`.
|
|
903
|
+
*/
|
|
904
|
+
listMetadataTypes(): readonly string[];
|
|
905
|
+
}
|
|
906
|
+
|
|
907
|
+
declare const manifestLocalizationSchema: z.ZodOptional<z.ZodObject<{
|
|
908
|
+
defaultLocale: z.ZodString;
|
|
909
|
+
supportedLocales: z.ZodArray<z.ZodString>;
|
|
910
|
+
files: z.ZodRecord<z.ZodString, z.ZodString>;
|
|
911
|
+
}, z.core.$strip>>;
|
|
912
|
+
/**
|
|
913
|
+
* Zod schema for runtime projection manifest.json (single authoritative runtime config).
|
|
914
|
+
*/
|
|
915
|
+
declare const projectionManifestSchema: z.ZodObject<{
|
|
916
|
+
releaseId: z.ZodString;
|
|
917
|
+
environment: z.ZodString;
|
|
918
|
+
generatedAt: z.ZodString;
|
|
919
|
+
projectionVersion: z.ZodString;
|
|
920
|
+
metadataCount: z.ZodNumber;
|
|
921
|
+
artifactCount: z.ZodNumber;
|
|
922
|
+
contentHash: z.ZodString;
|
|
923
|
+
artifacts: z.ZodArray<z.ZodString>;
|
|
924
|
+
files: z.ZodArray<z.ZodObject<{
|
|
925
|
+
fileName: z.ZodString;
|
|
926
|
+
projectionType: z.ZodString;
|
|
927
|
+
contentHash: z.ZodString;
|
|
928
|
+
itemCount: z.ZodNumber;
|
|
929
|
+
}, z.core.$strip>>;
|
|
930
|
+
metadataTypes: z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
931
|
+
typeCode: z.ZodString;
|
|
932
|
+
projectionFile: z.ZodString;
|
|
933
|
+
localizedDisplayName: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
934
|
+
valueDataType: z.ZodOptional<z.ZodString>;
|
|
935
|
+
multiSelectAllowed: z.ZodOptional<z.ZodBoolean>;
|
|
936
|
+
}, z.core.$loose>>;
|
|
937
|
+
lookupIndex: z.ZodDefault<z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
938
|
+
typeCode: z.ZodString;
|
|
939
|
+
valueCode: z.ZodString;
|
|
940
|
+
projectionFile: z.ZodString;
|
|
941
|
+
}, z.core.$strip>>>>;
|
|
942
|
+
localization: z.ZodOptional<z.ZodObject<{
|
|
943
|
+
defaultLocale: z.ZodString;
|
|
944
|
+
supportedLocales: z.ZodArray<z.ZodString>;
|
|
945
|
+
files: z.ZodRecord<z.ZodString, z.ZodString>;
|
|
946
|
+
}, z.core.$strip>>;
|
|
947
|
+
revision: z.ZodString;
|
|
948
|
+
schemaVersion: z.ZodNumber;
|
|
949
|
+
}, z.core.$strip>;
|
|
950
|
+
type MetadataLoaderOptions = {
|
|
951
|
+
expectedSchemaVersion: number;
|
|
952
|
+
expectedProjectionVersion?: string;
|
|
953
|
+
logger?: StructuredLogger;
|
|
954
|
+
};
|
|
955
|
+
type ManifestCompareResult = {
|
|
956
|
+
changed: boolean;
|
|
957
|
+
previousRevision: string | null;
|
|
958
|
+
previousContentHash: string | null;
|
|
959
|
+
nextRevision: string;
|
|
960
|
+
nextContentHash: string;
|
|
961
|
+
};
|
|
962
|
+
/**
|
|
963
|
+
* Validates and compares projection manifests downloaded from S3.
|
|
964
|
+
*
|
|
965
|
+
* Manifest is used for: release identity, schema/version checks, integrity (`files`),
|
|
966
|
+
* `metadataTypes` catalog (supportsType), and `lookupIndex`.
|
|
967
|
+
* It is **not** used to discover which domain projection files to download.
|
|
968
|
+
*/
|
|
969
|
+
declare class MetadataLoader {
|
|
970
|
+
private readonly expectedSchemaVersion;
|
|
971
|
+
private readonly expectedProjectionVersion?;
|
|
972
|
+
private readonly logger;
|
|
973
|
+
constructor(options: MetadataLoaderOptions);
|
|
974
|
+
/**
|
|
975
|
+
* Parse + validate raw manifest JSON body.
|
|
976
|
+
*/
|
|
977
|
+
parseAndValidate(rawBody: string): ProjectionManifest;
|
|
978
|
+
/**
|
|
979
|
+
* Detect whether a newly loaded manifest differs from the currently cached one.
|
|
980
|
+
*/
|
|
981
|
+
compare(current: Pick<ProjectionManifest, 'revision' | 'contentHash'> | null, next: ProjectionManifest): ManifestCompareResult;
|
|
982
|
+
private validateVersion;
|
|
983
|
+
private validateRequiredFiles;
|
|
984
|
+
private validateManifestContentHash;
|
|
985
|
+
}
|
|
986
|
+
|
|
987
|
+
type MetadataDownloaderOptions = {
|
|
988
|
+
/** Injected S3 client — retry uses AWS SDK client configuration (do not duplicate). */
|
|
989
|
+
client: S3Client;
|
|
990
|
+
bucket: string;
|
|
991
|
+
prefix: string;
|
|
992
|
+
environment: string;
|
|
993
|
+
expectedSchemaVersion: number;
|
|
994
|
+
expectedProjectionVersion?: string;
|
|
995
|
+
logger?: StructuredLogger;
|
|
996
|
+
loader?: MetadataLoader;
|
|
997
|
+
};
|
|
998
|
+
/**
|
|
999
|
+
* Downloads projection artifacts from S3 via current.json → release folder.
|
|
1000
|
+
*
|
|
1001
|
+
* Domain projection files are addressed as `{MetadataTypeCode}.json` — never via
|
|
1002
|
+
* `manifest.metadataTypes` / projection filename lookup. Manifest remains for
|
|
1003
|
+
* integrity hashes (`files`), lookupIndex, and release validation.
|
|
1004
|
+
*
|
|
1005
|
+
* Implements platform {@link ReadModelDownloader} — the metadata Read Model adapter.
|
|
1006
|
+
*/
|
|
1007
|
+
declare class MetadataDownloader implements ReadModelDownloader<LoadedProjectionBundle, ProjectionManifest> {
|
|
1008
|
+
private readonly client;
|
|
1009
|
+
private readonly bucket;
|
|
1010
|
+
private readonly pathBuilder;
|
|
1011
|
+
private readonly expectedProjectionVersion;
|
|
1012
|
+
private readonly logger;
|
|
1013
|
+
private readonly loader;
|
|
1014
|
+
constructor(options: MetadataDownloaderOptions);
|
|
1015
|
+
buildKey(releaseId: string, fileName: string): string;
|
|
1016
|
+
/**
|
|
1017
|
+
* Resolve the active release via `current.json`.
|
|
1018
|
+
*/
|
|
1019
|
+
discoverLatestRevision(): Promise<string>;
|
|
1020
|
+
downloadCurrentPointer(): Promise<ProjectionCurrentPointer>;
|
|
1021
|
+
/**
|
|
1022
|
+
* Download + validate manifest.json for a release (lookupIndex + integrity catalog).
|
|
1023
|
+
*/
|
|
1024
|
+
downloadManifest(releaseId: string): Promise<ProjectionManifest>;
|
|
1025
|
+
/**
|
|
1026
|
+
* Bootstrap: resolve release → manifest.json only.
|
|
1027
|
+
*
|
|
1028
|
+
* Manifest supplies lookupIndex, metadataTypes, and integrity hashes.
|
|
1029
|
+
* `common.json` is **not** loaded — enrichment resolves from domain projections.
|
|
1030
|
+
* Domain `{typeCode}.json` files are downloaded later via
|
|
1031
|
+
* {@link downloadDomainProjections}.
|
|
1032
|
+
*/
|
|
1033
|
+
loadBootstrap(releaseId?: string): Promise<LoadedProjectionBundle>;
|
|
1034
|
+
/**
|
|
1035
|
+
* Installable bootstrap bundle from an already-fetched manifest.
|
|
1036
|
+
* Does not download common.json or domain projection files.
|
|
1037
|
+
*/
|
|
1038
|
+
downloadBootstrapBundle(manifest: ProjectionManifest): Promise<LoadedProjectionBundle>;
|
|
1039
|
+
/**
|
|
1040
|
+
* Download domain projection files for the given MetadataTypeCodes.
|
|
1041
|
+
* Filenames are `{MetadataTypeCode}.json` — never looked up from the manifest.
|
|
1042
|
+
* Manifest `files` entries supply contentHash for integrity only.
|
|
1043
|
+
*
|
|
1044
|
+
* Types without a manifest integrity entry are WARN-skipped
|
|
1045
|
+
* (`manifestIntegrityEntryMissing`) so unsupported/unpublished projections
|
|
1046
|
+
* do not fail the batch. S3/integrity failures for types that *are* in the
|
|
1047
|
+
* manifest still throw. Downloads in parallel.
|
|
1048
|
+
*/
|
|
1049
|
+
downloadDomainProjections(manifest: ProjectionManifest, metadataTypeCodes: readonly string[]): Promise<{
|
|
1050
|
+
domainFiles: Map<string, ProjectionFile>;
|
|
1051
|
+
loadedFiles: string[];
|
|
1052
|
+
}>;
|
|
1053
|
+
/**
|
|
1054
|
+
* Load `relationship-index.json` when listed in the manifest integrity catalog.
|
|
1055
|
+
* Missing/corrupt/mismatched artifacts fail closed — never activate an empty map.
|
|
1056
|
+
*/
|
|
1057
|
+
downloadRelationshipIndex(manifest: ProjectionManifest): Promise<RelationshipIndex | undefined>;
|
|
1058
|
+
private assertManifestMatchesRelease;
|
|
1059
|
+
private parseAndValidateProjectionBody;
|
|
1060
|
+
private getObjectBody;
|
|
1061
|
+
private validateDownloadedFile;
|
|
1062
|
+
}
|
|
1063
|
+
|
|
1064
|
+
/**
|
|
1065
|
+
* Immutable in-memory projection cache with atomic snapshot replacement.
|
|
1066
|
+
* Node is single-threaded: readers always see a complete snapshot reference.
|
|
1067
|
+
* Cached objects are never mutated after install.
|
|
1068
|
+
*
|
|
1069
|
+
* Cache keys for domain files are MetadataTypeCode.
|
|
1070
|
+
* Bootstrap installs manifest (lookupIndex + integrity); domain files are merged on demand.
|
|
1071
|
+
* `common.json` is optional and not required for HTTP enrichment.
|
|
1072
|
+
*
|
|
1073
|
+
* Implements platform {@link ReadModelCache}.
|
|
1074
|
+
*/
|
|
1075
|
+
type MetadataCacheWriteGuard = {
|
|
1076
|
+
releaseId: string;
|
|
1077
|
+
generation: number;
|
|
1078
|
+
};
|
|
1079
|
+
declare class MetadataCache implements ReadModelCache<MetadataCacheSnapshot, ProjectionManifest, LoadedProjectionBundle, CacheStatus> {
|
|
1080
|
+
private snapshot;
|
|
1081
|
+
private status;
|
|
1082
|
+
/**
|
|
1083
|
+
* Monotonic generation incremented on every replace/clear.
|
|
1084
|
+
* Stale async hydration must not write into a newer generation.
|
|
1085
|
+
*/
|
|
1086
|
+
private generation;
|
|
1087
|
+
getStatus(): CacheStatus;
|
|
1088
|
+
setStatus(status: CacheStatus): void;
|
|
1089
|
+
isReady(): boolean;
|
|
1090
|
+
getSnapshot(): MetadataCacheSnapshot | null;
|
|
1091
|
+
getManifest(): ProjectionManifest | null;
|
|
1092
|
+
getRevision(): string | null;
|
|
1093
|
+
getReleaseId(): string | null;
|
|
1094
|
+
getContentHash(): string | null;
|
|
1095
|
+
getLoadedAt(): string | null;
|
|
1096
|
+
getLoadedFiles(): readonly string[];
|
|
1097
|
+
getDomainFile(type: ResolvableMetadataType): ProjectionFile | undefined;
|
|
1098
|
+
getCommon(): CommonProjectionFile | undefined;
|
|
1099
|
+
getRelationshipIndex(): RelationshipIndex | undefined;
|
|
1100
|
+
getLocalization(locale: string): ReadonlyMap<string, string> | undefined;
|
|
1101
|
+
getLocalizationMap(locale: string): ReadonlyMap<string, string> | undefined;
|
|
1102
|
+
getLocalizationValue(key: string, locale?: string): string | undefined;
|
|
1103
|
+
getGeneration(): number;
|
|
1104
|
+
/**
|
|
1105
|
+
* Atomically replace the entire cache from a downloaded bundle.
|
|
1106
|
+
* Previous snapshot is discarded (not mutated).
|
|
1107
|
+
*/
|
|
1108
|
+
replace(bundle: LoadedProjectionBundle): MetadataCacheSnapshot;
|
|
1109
|
+
/**
|
|
1110
|
+
* Merge additional domain projection files into the current snapshot (same revision).
|
|
1111
|
+
* Used by selective on-demand downloads — never mutates the prior snapshot.
|
|
1112
|
+
*/
|
|
1113
|
+
mergeDomainFiles(domainFiles: ReadonlyMap<string, ProjectionFile>, additionalLoadedFiles: readonly string[], guard?: MetadataCacheWriteGuard): MetadataCacheSnapshot;
|
|
1114
|
+
/**
|
|
1115
|
+
* Merge individual resolved entries into domain record maps (same release).
|
|
1116
|
+
* Used after an extension batch lookup so {@link MetadataResolver.resolve}
|
|
1117
|
+
* remains synchronous.
|
|
1118
|
+
*/
|
|
1119
|
+
hydrateEntries(entries: ReadonlyArray<{
|
|
1120
|
+
typeCode: string;
|
|
1121
|
+
valueCode: string;
|
|
1122
|
+
entry: ProjectionEntry;
|
|
1123
|
+
}>, guard?: MetadataCacheWriteGuard): MetadataCacheSnapshot;
|
|
1124
|
+
/**
|
|
1125
|
+
* Clear only when explicitly requested (e.g. tests). Refresh failures must NOT call this.
|
|
1126
|
+
*/
|
|
1127
|
+
clear(): void;
|
|
1128
|
+
private guardAllowsWrite;
|
|
1129
|
+
}
|
|
1130
|
+
|
|
1131
|
+
type MetadataResolverOptions = {
|
|
1132
|
+
cache: MetadataCache;
|
|
1133
|
+
logger?: StructuredLogger;
|
|
1134
|
+
};
|
|
1135
|
+
/**
|
|
1136
|
+
* O(1) metadata lookups against the immutable cache using the manifest lookup index.
|
|
1137
|
+
* Domain services must use these APIs — never read projection JSON directly.
|
|
1138
|
+
*
|
|
1139
|
+
* Resolve keys are exact MetadataTypeCode values (e.g. `MetricCode`, `Condition`).
|
|
1140
|
+
* Cache domain files are keyed the same way; this class never downloads projections.
|
|
1141
|
+
*/
|
|
1142
|
+
declare class MetadataResolver implements ReadModelResolver<ProjectionEntry> {
|
|
1143
|
+
private readonly cache;
|
|
1144
|
+
private readonly logger;
|
|
1145
|
+
constructor(options: MetadataResolverOptions);
|
|
1146
|
+
/**
|
|
1147
|
+
* Generic resolve by MetadataTypeCode and valueCode via the published lookup index.
|
|
1148
|
+
*/
|
|
1149
|
+
resolve(typeCode: string, valueCode: string, version?: number): ProjectionEntry;
|
|
1150
|
+
/** Resolve using an explicit {@link MetadataReference}. */
|
|
1151
|
+
resolve(reference: MetadataReference, version?: number): ProjectionEntry;
|
|
1152
|
+
private resolveByTypeAndCode;
|
|
1153
|
+
/**
|
|
1154
|
+
* O(1) localization lookup using in-memory locale map.
|
|
1155
|
+
* Resolves by key `<typeCode>.<valueCode>`.
|
|
1156
|
+
* Falls back to default locale if requested locale does not have the key.
|
|
1157
|
+
*/
|
|
1158
|
+
resolveLocalization(typeCode: string, valueCode: string, locale?: string): string | undefined;
|
|
1159
|
+
/**
|
|
1160
|
+
* Look up localized display name for a MetadataType from manifest or domain file.
|
|
1161
|
+
*/
|
|
1162
|
+
getTypeLocalizedDisplayName(typeCode: string, locale?: string): string | undefined;
|
|
1163
|
+
/**
|
|
1164
|
+
* Value data type for a MetadataType (e.g. STRING, INTEGER).
|
|
1165
|
+
*/
|
|
1166
|
+
getValueDataType(typeCode: string): string | undefined;
|
|
1167
|
+
/**
|
|
1168
|
+
* Whether the given MetadataTypeCode is listed in the loaded manifest.
|
|
1169
|
+
* Does not require the domain projection file to be cached yet.
|
|
1170
|
+
*/
|
|
1171
|
+
supportsType(typeCode: string): boolean;
|
|
1172
|
+
/** MetadataTypeCodes available for resolve (from manifest.metadataTypes). */
|
|
1173
|
+
listMetadataTypes(): readonly string[];
|
|
1174
|
+
/** Authoritative loaded manifest (integrity catalog + metadataTypes + lookupIndex). */
|
|
1175
|
+
getManifest(): ProjectionManifest;
|
|
1176
|
+
/** Published lookup index from the loaded manifest. */
|
|
1177
|
+
getLookupIndex(): Readonly<Record<string, ManifestLookupIndexEntry>>;
|
|
1178
|
+
exists(type: ResolvableMetadataType, code: string, version?: number): boolean;
|
|
1179
|
+
/**
|
|
1180
|
+
* Return latest entries for a type, optionally filtered by a simple substring on code/label.
|
|
1181
|
+
* Not a hot path — used by tooling / health, not HTTP enrichment.
|
|
1182
|
+
*/
|
|
1183
|
+
search(type: ResolvableMetadataType, query?: string): ProjectionEntry[];
|
|
1184
|
+
getAll(type: ResolvableMetadataType): ProjectionEntry[];
|
|
1185
|
+
private requireSupportedType;
|
|
1186
|
+
/**
|
|
1187
|
+
* Resolve MetadataTypeCode against manifest.metadataTypes.
|
|
1188
|
+
* Applies {@link normalizeRuntimeMetadataTypeCode} (e.g. Speciality → Specialty).
|
|
1189
|
+
* No SCREAMING_SNAKE / case-folding aliases.
|
|
1190
|
+
*/
|
|
1191
|
+
private resolveMetadataTypeCode;
|
|
1192
|
+
private requireEntry;
|
|
1193
|
+
private lookupEntry;
|
|
1194
|
+
private requireManifest;
|
|
1195
|
+
private assertReady;
|
|
1196
|
+
}
|
|
1197
|
+
|
|
1198
|
+
type MetadataRefreshServiceOptions = {
|
|
1199
|
+
cache: ReadModelCache<MetadataCacheSnapshot, ProjectionManifest, LoadedProjectionBundle, CacheStatus>;
|
|
1200
|
+
downloader: ReadModelDownloader<LoadedProjectionBundle, ProjectionManifest>;
|
|
1201
|
+
loader: MetadataLoader;
|
|
1202
|
+
/** Optional default release when discovering is skipped. */
|
|
1203
|
+
configuredRevision?: string;
|
|
1204
|
+
logger?: StructuredLogger;
|
|
1205
|
+
/**
|
|
1206
|
+
* Reload previously cached domain types into the *new* release before
|
|
1207
|
+
* atomic replace. Prevents dropping a valid domain cache during refresh.
|
|
1208
|
+
*/
|
|
1209
|
+
reloadDomainFiles?: (manifest: ProjectionManifest, typeCodes: readonly string[]) => Promise<{
|
|
1210
|
+
domainFiles: Map<string, ProjectionFile>;
|
|
1211
|
+
loadedFiles: string[];
|
|
1212
|
+
}>;
|
|
1213
|
+
};
|
|
1214
|
+
/**
|
|
1215
|
+
* Coordinates startup, event-driven, and periodic cache refresh with graceful degradation.
|
|
1216
|
+
* On refresh failure the existing cache is retained.
|
|
1217
|
+
* Always resolves the active release via current.json unless a release id is forced.
|
|
1218
|
+
*
|
|
1219
|
+
* Bootstrap only (current.json → manifest.json). Domain `{MetadataTypeCode}.json` files
|
|
1220
|
+
* are loaded on demand by {@link RuntimeMetadataService.ensureProjectionTypesLoaded}.
|
|
1221
|
+
* `common.json` is not part of the HTTP enrichment bootstrap path.
|
|
1222
|
+
*
|
|
1223
|
+
* Implements platform {@link ReadModelRefreshCoordinator}.
|
|
1224
|
+
*/
|
|
1225
|
+
declare class MetadataRefreshService implements ReadModelRefreshCoordinator {
|
|
1226
|
+
private readonly cache;
|
|
1227
|
+
private readonly downloader;
|
|
1228
|
+
private readonly loader;
|
|
1229
|
+
private readonly configuredRevision?;
|
|
1230
|
+
private readonly logger;
|
|
1231
|
+
private readonly reloadDomainFiles?;
|
|
1232
|
+
private refreshStatus;
|
|
1233
|
+
private lastRefreshError;
|
|
1234
|
+
private refreshInFlight;
|
|
1235
|
+
private periodicTimer;
|
|
1236
|
+
constructor(options: MetadataRefreshServiceOptions);
|
|
1237
|
+
getRefreshStatus(): RefreshStatus;
|
|
1238
|
+
getLastRefreshError(): string | null;
|
|
1239
|
+
/**
|
|
1240
|
+
* Demand-driven bootstrap: current.json → manifest.json → atomic cache replace.
|
|
1241
|
+
* Domain projection files and common.json are not loaded here.
|
|
1242
|
+
*/
|
|
1243
|
+
initialize(revision?: string): Promise<void>;
|
|
1244
|
+
/**
|
|
1245
|
+
* Event strategy: MetadataProjectionCompleted → reload via current.json → atomic swap.
|
|
1246
|
+
* `releaseId` is diagnostic; the pointer is the source of truth.
|
|
1247
|
+
* Returns true when the cache was updated.
|
|
1248
|
+
*/
|
|
1249
|
+
refreshFromEvent(releaseId?: string): Promise<boolean>;
|
|
1250
|
+
/**
|
|
1251
|
+
* Periodic strategy: re-read current.json; reload only if changed.
|
|
1252
|
+
*/
|
|
1253
|
+
checkAndRefresh(preferredRevision?: string): Promise<boolean>;
|
|
1254
|
+
startPeriodicCheck(intervalMs: number): void;
|
|
1255
|
+
stopPeriodicCheck(): void;
|
|
1256
|
+
private runRefresh;
|
|
1257
|
+
private doRefresh;
|
|
1258
|
+
}
|
|
1259
|
+
|
|
1260
|
+
type MetadataHealthServiceOptions = {
|
|
1261
|
+
/**
|
|
1262
|
+
* Phase 5: accept the generic {@link ReadModelCache} contract.
|
|
1263
|
+
* Default / typical injection remains MetadataCache.
|
|
1264
|
+
*/
|
|
1265
|
+
cache: ReadModelCache<MetadataCacheSnapshot, ProjectionManifest, LoadedProjectionBundle, CacheStatus>;
|
|
1266
|
+
getRefreshStatus: () => RefreshStatus;
|
|
1267
|
+
getLastRefreshError: () => string | null;
|
|
1268
|
+
logger?: StructuredLogger;
|
|
1269
|
+
};
|
|
1270
|
+
/**
|
|
1271
|
+
* Exposes projection version, revision, cache age, and refresh status for health endpoints.
|
|
1272
|
+
*
|
|
1273
|
+
* Phase 5: depends on {@link ReadModelCache}; behaviour unchanged.
|
|
1274
|
+
*/
|
|
1275
|
+
declare class MetadataHealthService {
|
|
1276
|
+
private readonly cache;
|
|
1277
|
+
private readonly getRefreshStatus;
|
|
1278
|
+
private readonly getLastRefreshError;
|
|
1279
|
+
constructor(options: MetadataHealthServiceOptions);
|
|
1280
|
+
getHealth(): MetadataHealthReport;
|
|
1281
|
+
isHealthy(): boolean;
|
|
1282
|
+
}
|
|
1283
|
+
|
|
1284
|
+
type MetadataResolveOptions = {
|
|
1285
|
+
locale?: string;
|
|
1286
|
+
version?: number;
|
|
1287
|
+
};
|
|
1288
|
+
/**
|
|
1289
|
+
* Compact lookup item returned by {@link MetadataProvider.getValue} /
|
|
1290
|
+
* {@link MetadataProvider.batchGet}. Includes the published projection
|
|
1291
|
+
* entry so existing {@link RuntimeMetadataService.resolve} callers keep
|
|
1292
|
+
* full field access.
|
|
1293
|
+
*/
|
|
1294
|
+
type MetadataValue = {
|
|
1295
|
+
typeCode: string;
|
|
1296
|
+
valueCode: string;
|
|
1297
|
+
localizedLabel: string;
|
|
1298
|
+
status: string;
|
|
1299
|
+
version: number;
|
|
1300
|
+
entry: ProjectionEntry;
|
|
1301
|
+
};
|
|
1302
|
+
type MetadataProviderStatus = {
|
|
1303
|
+
state: string;
|
|
1304
|
+
releaseId: string | null;
|
|
1305
|
+
loadedAt: string | null;
|
|
1306
|
+
lastRefreshAttemptAt: string | null;
|
|
1307
|
+
lastSuccessfulRefreshAt: string | null;
|
|
1308
|
+
cacheAgeMs: number | null;
|
|
1309
|
+
metadataTypes?: readonly string[];
|
|
1310
|
+
};
|
|
1311
|
+
type MetadataBatchResult = {
|
|
1312
|
+
releaseId: string | null;
|
|
1313
|
+
items: Record<string, MetadataValue>;
|
|
1314
|
+
invalidReferences: string[];
|
|
1315
|
+
unavailable: boolean;
|
|
1316
|
+
};
|
|
1317
|
+
/**
|
|
1318
|
+
* Transport-agnostic metadata read API.
|
|
1319
|
+
*
|
|
1320
|
+
* Implementations: extension (localhost), S3 projection, in-memory tests.
|
|
1321
|
+
* Application code must not choose or implement fallback.
|
|
1322
|
+
*/
|
|
1323
|
+
interface MetadataProvider {
|
|
1324
|
+
getValue(typeCode: string, valueCode: string, options?: MetadataResolveOptions): Promise<MetadataValue | null>;
|
|
1325
|
+
batchGet(references: string[], options?: MetadataResolveOptions): Promise<MetadataBatchResult>;
|
|
1326
|
+
getRelatedValues(sourceTypeCode: string, sourceValueCode: string, targetTypeCode: string, options?: MetadataResolveOptions): Promise<MetadataValue[]>;
|
|
1327
|
+
getStatus(): Promise<MetadataProviderStatus>;
|
|
1328
|
+
isAvailable(): Promise<boolean>;
|
|
1329
|
+
/**
|
|
1330
|
+
* Block until the transport can serve lookups. Extension-only.
|
|
1331
|
+
*/
|
|
1332
|
+
waitUntilReady?(): Promise<MetadataProviderStatus>;
|
|
1333
|
+
/**
|
|
1334
|
+
* Ask the transport to re-read current.json and swap if changed.
|
|
1335
|
+
* Extension-only. Returns true when a new snapshot was activated.
|
|
1336
|
+
*/
|
|
1337
|
+
requestRefresh?(releaseId?: string): Promise<boolean>;
|
|
1338
|
+
}
|
|
1339
|
+
declare function projectionEntryToMetadataValue(typeCode: string, valueCode: string, entry: ProjectionEntry, locale?: string): MetadataValue;
|
|
1340
|
+
declare function localizedLabelFromEntry(entry: ProjectionEntry, locale?: string): string;
|
|
1341
|
+
declare function metadataValueToReference(value: MetadataValue): MetadataReference;
|
|
1342
|
+
|
|
1343
|
+
declare const METADATA_PROVIDER_KIND: {
|
|
1344
|
+
readonly EXTENSION: "extension";
|
|
1345
|
+
readonly S3: "s3";
|
|
1346
|
+
readonly MEMORY: "memory";
|
|
1347
|
+
};
|
|
1348
|
+
type MetadataProviderKind = (typeof METADATA_PROVIDER_KIND)[keyof typeof METADATA_PROVIDER_KIND];
|
|
1349
|
+
type SelectMetadataProviderInput = {
|
|
1350
|
+
env?: NodeJS.ProcessEnv;
|
|
1351
|
+
logger?: StructuredLogger;
|
|
1352
|
+
/** Injected extension client (tests). */
|
|
1353
|
+
extensionProvider?: MetadataProvider;
|
|
1354
|
+
/** S3 fallback constructed by the SDK. */
|
|
1355
|
+
s3Provider?: MetadataProvider;
|
|
1356
|
+
extensionFetch?: typeof fetch;
|
|
1357
|
+
};
|
|
1358
|
+
type SelectedMetadataProvider = {
|
|
1359
|
+
kind: MetadataProviderKind;
|
|
1360
|
+
provider: MetadataProvider;
|
|
1361
|
+
fallback?: MetadataProvider;
|
|
1362
|
+
};
|
|
1363
|
+
/**
|
|
1364
|
+
* SDK-owned transport selection. Application code must not branch on this.
|
|
1365
|
+
*
|
|
1366
|
+
* Preference:
|
|
1367
|
+
* 1. Explicit test extension provider
|
|
1368
|
+
* 2. Extension when enabled and a localhost URL / Lambda runtime is present
|
|
1369
|
+
* 3. S3 fallback
|
|
1370
|
+
*/
|
|
1371
|
+
declare function selectMetadataProvider(input: SelectMetadataProviderInput): SelectedMetadataProvider | null;
|
|
1372
|
+
declare function isExtensionEnabled(env?: NodeJS.ProcessEnv): boolean;
|
|
1373
|
+
declare function isMetadataProjectionConfigured(env?: NodeJS.ProcessEnv): boolean;
|
|
1374
|
+
|
|
1375
|
+
type RuntimeMetadataServiceOptions = {
|
|
1376
|
+
/** Injected S3 client — AWS SDK retry applies; never created inside this library. */
|
|
1377
|
+
client: S3Client;
|
|
1378
|
+
config: RuntimeMetadataConfigInput;
|
|
1379
|
+
logger?: StructuredLogger;
|
|
1380
|
+
cache?: MetadataCache;
|
|
1381
|
+
loader?: MetadataLoader;
|
|
1382
|
+
downloader?: MetadataDownloader;
|
|
1383
|
+
resolver?: MetadataResolver;
|
|
1384
|
+
refreshService?: MetadataRefreshService;
|
|
1385
|
+
healthService?: MetadataHealthService;
|
|
1386
|
+
/** Override transport (tests). */
|
|
1387
|
+
metadataProvider?: MetadataProvider;
|
|
1388
|
+
/** Override S3 fallback (tests). */
|
|
1389
|
+
metadataProviderFallback?: MetadataProvider;
|
|
1390
|
+
env?: NodeJS.ProcessEnv;
|
|
1391
|
+
};
|
|
1392
|
+
/**
|
|
1393
|
+
* Facade consumed by domain services (Care Plan, Monitoring, Patient, …).
|
|
1394
|
+
* Prefer {@link resolve} / exists / search / getAll / getHealth.
|
|
1395
|
+
*
|
|
1396
|
+
* Implements platform {@link ReadModelProvider}.
|
|
1397
|
+
*
|
|
1398
|
+
* Runtime flow (demand-driven — no beforeHandler preload):
|
|
1399
|
+
* ```text
|
|
1400
|
+
* Response DTO → unique typeCodes
|
|
1401
|
+
* → if none: zero S3
|
|
1402
|
+
* → else: ensure current+manifest in MetadataCache (once per warm context)
|
|
1403
|
+
* → missing typeCodes → parallel {typeCode}.json → merge cache
|
|
1404
|
+
* → MetadataResolver resolves valueCodes from memory only
|
|
1405
|
+
* ```
|
|
1406
|
+
*/
|
|
1407
|
+
declare class RuntimeMetadataService implements ReadModelProvider<ProjectionEntry> {
|
|
1408
|
+
readonly cache: MetadataCache;
|
|
1409
|
+
readonly loader: MetadataLoader;
|
|
1410
|
+
readonly downloader: MetadataDownloader;
|
|
1411
|
+
readonly resolver: MetadataResolver;
|
|
1412
|
+
readonly refreshService: MetadataRefreshService;
|
|
1413
|
+
readonly healthService: MetadataHealthService;
|
|
1414
|
+
private readonly config;
|
|
1415
|
+
private readonly logger;
|
|
1416
|
+
/** Coalesce concurrent cold bootstrap (current.json + manifest.json). */
|
|
1417
|
+
private initializeInFlight;
|
|
1418
|
+
/**
|
|
1419
|
+
* In-flight selective downloads keyed by MetadataTypeCode.
|
|
1420
|
+
* Concurrent requests (and overlapping type sets) share one download per type
|
|
1421
|
+
* for the lifetime of the Lambda execution context.
|
|
1422
|
+
*/
|
|
1423
|
+
private readonly domainLoadInFlight;
|
|
1424
|
+
/**
|
|
1425
|
+
* Types soft-skipped for the current release (no manifest integrity entry).
|
|
1426
|
+
* Prevents ensureProjectionTypesLoaded from retrying unsupported types forever.
|
|
1427
|
+
*/
|
|
1428
|
+
private unsupportedProjectionTypes;
|
|
1429
|
+
private unsupportedProjectionReleaseId;
|
|
1430
|
+
private readonly metadataProvider;
|
|
1431
|
+
private readonly metadataProviderKind;
|
|
1432
|
+
private readonly metadataProviderFallback?;
|
|
1433
|
+
private readonly providerCoordinator;
|
|
1434
|
+
constructor(options: RuntimeMetadataServiceOptions);
|
|
1435
|
+
/**
|
|
1436
|
+
* Load current.json + manifest.json into cache (no domain projections, no common.json).
|
|
1437
|
+
* Called on demand when a response needs metadata — not from beforeHandler.
|
|
1438
|
+
* Concurrent callers share one in-flight initialize.
|
|
1439
|
+
*/
|
|
1440
|
+
initialize(revision?: string): Promise<void>;
|
|
1441
|
+
private initializeInternal;
|
|
1442
|
+
/**
|
|
1443
|
+
* Handle MetadataProjectionCompleted — reload bootstrap via current.json.
|
|
1444
|
+
*
|
|
1445
|
+
* This refreshes the current execution environment only. It cannot fan-out
|
|
1446
|
+
* to every warm Lambda. Warm environments learn about new releases via the
|
|
1447
|
+
* extension INVOKE hook, extension polling, or this method when this
|
|
1448
|
+
* environment is the one that handled the event.
|
|
1449
|
+
*/
|
|
1450
|
+
onProjectionCompleted(releaseId?: string): Promise<boolean>;
|
|
1451
|
+
/** Periodic / manual current.json check + conditional snapshot reload. */
|
|
1452
|
+
checkForUpdates(revision?: string): Promise<boolean>;
|
|
1453
|
+
stop(): void;
|
|
1454
|
+
/**
|
|
1455
|
+
* Demand-driven selective load:
|
|
1456
|
+
* 1. Collect unique typeCodes from the response (zero S3 when none)
|
|
1457
|
+
* 2. Ensure release bootstrap (current + manifest) only if needed
|
|
1458
|
+
* 3. Download missing `{typeCode}.json` in parallel into MetadataCache
|
|
1459
|
+
*
|
|
1460
|
+
* {@link MetadataResolver} resolves valueCodes from cache only.
|
|
1461
|
+
*/
|
|
1462
|
+
/**
|
|
1463
|
+
* Demand-driven selective load:
|
|
1464
|
+
* 1. Collect unique typeCodes from the response (zero S3 when none)
|
|
1465
|
+
* 2. Ensure release bootstrap (current + manifest) only if needed
|
|
1466
|
+
* 3. Download missing `{typeCode}.json` in parallel into MetadataCache
|
|
1467
|
+
*
|
|
1468
|
+
* {@link MetadataResolver} resolves valueCodes from cache only.
|
|
1469
|
+
*/
|
|
1470
|
+
ensureProjectionsForResponse(response: unknown): Promise<void>;
|
|
1471
|
+
/**
|
|
1472
|
+
* Ensure domain projection files for the given MetadataTypeCodes are present in cache.
|
|
1473
|
+
* Filenames are `{MetadataTypeCode}.json` — not discovered from the manifest.
|
|
1474
|
+
*
|
|
1475
|
+
* Warm path: when every requested type is already in {@link MetadataCache}, this
|
|
1476
|
+
* returns immediately with **zero** S3 calls.
|
|
1477
|
+
*/
|
|
1478
|
+
ensureProjectionTypesLoaded(metadataTypeCodes: readonly string[]): Promise<void>;
|
|
1479
|
+
private syncUnsupportedProjectionRelease;
|
|
1480
|
+
private findMissingTypeCodes;
|
|
1481
|
+
private downloadAndMergeTypes;
|
|
1482
|
+
/**
|
|
1483
|
+
* Generic resolve by typeCode and valueCode.
|
|
1484
|
+
*/
|
|
1485
|
+
resolve(typeCode: string, valueCode: string, version?: number): ProjectionEntry;
|
|
1486
|
+
/** Resolve using an explicit {@link MetadataReference}. */
|
|
1487
|
+
resolve(reference: MetadataReference, version?: number): ProjectionEntry;
|
|
1488
|
+
supportsType(typeCode: string): boolean;
|
|
1489
|
+
resolveLocalization(typeCode: string, valueCode: string, locale?: string): string | undefined;
|
|
1490
|
+
getLocalizationValue(keyOrTypeCode: string, valueCodeOrLocale?: string, maybeLocale?: string): string | undefined;
|
|
1491
|
+
getDomainFile(typeCode: string): ProjectionFile | undefined;
|
|
1492
|
+
getTypeLocalizedDisplayName(typeCode: string, locale?: string): string | undefined;
|
|
1493
|
+
getValueDataType(typeCode: string): string | undefined;
|
|
1494
|
+
listMetadataTypes(): readonly string[];
|
|
1495
|
+
getManifest(): ProjectionManifest;
|
|
1496
|
+
getLookupIndex(): Readonly<Record<string, ManifestLookupIndexEntry>>;
|
|
1497
|
+
exists(type: ResolvableMetadataType, code: string, version?: number): boolean;
|
|
1498
|
+
search(type: ResolvableMetadataType, query?: string): ProjectionEntry[];
|
|
1499
|
+
getAll(type: ResolvableMetadataType): ProjectionEntry[];
|
|
1500
|
+
getHealth(): MetadataHealthReport;
|
|
1501
|
+
isHealthy(): boolean;
|
|
1502
|
+
getValue(typeCode: string, valueCode: string, options?: MetadataResolveOptions): Promise<MetadataValue | null>;
|
|
1503
|
+
batchGet(references: string[], options?: MetadataResolveOptions): Promise<MetadataBatchResult>;
|
|
1504
|
+
getRelatedValues(sourceTypeCode: string, sourceValueCode: string, targetTypeCode: string, options?: MetadataResolveOptions): Promise<MetadataValue[]>;
|
|
1505
|
+
getActiveProviderKind(): MetadataProviderKind;
|
|
1506
|
+
getProviderTransportState(): string;
|
|
1507
|
+
getExtensionHealthCheckCount(): number;
|
|
1508
|
+
private usesExtensionTransport;
|
|
1509
|
+
private activeProvider;
|
|
1510
|
+
private startS3PeriodicCheck;
|
|
1511
|
+
private refreshViaExtension;
|
|
1512
|
+
private initializeFromExtension;
|
|
1513
|
+
private installExtensionManifest;
|
|
1514
|
+
private hydrateProviderValues;
|
|
1515
|
+
private currentWriteGuard;
|
|
1516
|
+
private installBatchReleaseIfCurrent;
|
|
1517
|
+
private tryActivateFallbackFromError;
|
|
1518
|
+
}
|
|
1519
|
+
|
|
1520
|
+
/**
|
|
1521
|
+
* Optional env-based factory for domain services.
|
|
1522
|
+
* Reads standard projection env vars used by metadata-projection-runtime.
|
|
1523
|
+
* Prefer explicit config injection in production unit tests.
|
|
1524
|
+
*/
|
|
1525
|
+
type CreateRuntimeMetadataFromEnvOptions = {
|
|
1526
|
+
client: S3Client;
|
|
1527
|
+
logger?: StructuredLogger;
|
|
1528
|
+
env?: NodeJS.ProcessEnv;
|
|
1529
|
+
/** Override periodic check interval (ms). */
|
|
1530
|
+
periodicCheckIntervalMs?: number;
|
|
1531
|
+
revision?: string;
|
|
1532
|
+
environment?: string;
|
|
1533
|
+
};
|
|
1534
|
+
declare function createRuntimeMetadataFromEnv(options: CreateRuntimeMetadataFromEnvOptions): RuntimeMetadataService;
|
|
1535
|
+
|
|
1536
|
+
/**
|
|
1537
|
+
* Returns the process-wide RuntimeMetadataService instance.
|
|
1538
|
+
* Lazy initialized on first access.
|
|
1539
|
+
*/
|
|
1540
|
+
declare function getRuntimeMetadataService(): RuntimeMetadataService;
|
|
1541
|
+
/**
|
|
1542
|
+
* Resets bootstrap state. Useful in unit tests.
|
|
1543
|
+
*/
|
|
1544
|
+
declare function resetRuntimeMetadataBootstrapState(): void;
|
|
1545
|
+
/**
|
|
1546
|
+
* Ensures runtime metadata release bootstrap is loaded (current.json → manifest).
|
|
1547
|
+
*
|
|
1548
|
+
* Prefer demand-driven loading via
|
|
1549
|
+
* {@link RuntimeMetadataService.ensureProjectionsForResponse} from the response
|
|
1550
|
+
* projector after the DB response is known. Do **not** call this from
|
|
1551
|
+
* beforeHandler / Lambda bootstrap for projection warm-up.
|
|
1552
|
+
*
|
|
1553
|
+
* Domain projection files are downloaded on demand when the response projector
|
|
1554
|
+
* calls {@link RuntimeMetadataService.ensureProjectionsForResponse}.
|
|
1555
|
+
*
|
|
1556
|
+
* Warm start
|
|
1557
|
+
* - Throttles update checks
|
|
1558
|
+
* - Reloads bootstrap only if current.json / manifest changed
|
|
1559
|
+
*
|
|
1560
|
+
* Retained for health probes, event handlers, and explicit ops warm-up.
|
|
1561
|
+
*/
|
|
1562
|
+
declare function ensureRuntimeMetadataLoaded(): Promise<void>;
|
|
1563
|
+
/**
|
|
1564
|
+
* Used by health endpoints.
|
|
1565
|
+
*/
|
|
1566
|
+
declare function getRuntimeMetadataHealth(): MetadataHealthReport;
|
|
1567
|
+
/**
|
|
1568
|
+
* Returns the process-wide service when projection is configured, otherwise null.
|
|
1569
|
+
*/
|
|
1570
|
+
declare function tryGetRuntimeMetadataService(): RuntimeMetadataService | null;
|
|
1571
|
+
/**
|
|
1572
|
+
* Handles MetadataProjectionCompleted events.
|
|
1573
|
+
*/
|
|
1574
|
+
declare function onMetadataProjectionCompleted(releaseId?: string): Promise<boolean>;
|
|
1575
|
+
|
|
1576
|
+
/**
|
|
1577
|
+
* Wire-up checklist for domain services consuming `@api-hub/runtime-metadata`.
|
|
1578
|
+
*
|
|
1579
|
+
* ## Task service (HTTP response enrichment) — reference
|
|
1580
|
+
*
|
|
1581
|
+
* - Platform default: `@api-hub/middleware` `getPlatformDefaultResponseProjector`
|
|
1582
|
+
* (no beforeHandler metadata preload)
|
|
1583
|
+
* - Enrichment: `MetadataResponseProjector` inspects the DB/DTO response for
|
|
1584
|
+
* MetadataReference typeCodes. Transport is owned by `@api-hub/runtime-metadata`
|
|
1585
|
+
* (Lambda Extension localhost cache, with SDK-owned S3 fallback).
|
|
1586
|
+
* - Optional: `dtoFieldBindings` only for DTO field names that do not map to MetadataTypeCode
|
|
1587
|
+
*
|
|
1588
|
+
* ## Other services (Care Plan, Monitoring, Threshold, Symptom, Workflow, Alert)
|
|
1589
|
+
*
|
|
1590
|
+
* 1. Add `@api-hub/runtime-metadata` (+ `@api-hub/runtime-response-projector` if enriching HTTP)
|
|
1591
|
+
* 2. Copy IAM pattern against `{stage}-mvx-metadata-projections-bucket`
|
|
1592
|
+
* (or ImportValue `{stage}-metadata-projection-runtime-ProjectionsBucketName`)
|
|
1593
|
+
* 3. Set `METADATA_PROJECTIONS_BUCKET` (+ optional prefix / revision / check interval)
|
|
1594
|
+
* 4. Prefer platform default response projector (demand-driven); do not register
|
|
1595
|
+
* metadata warm-up as `beforeHandler`
|
|
1596
|
+
* 5. Do not add an EventBridge consumer merely to notify every warm Lambda.
|
|
1597
|
+
* Extensions are per execution environment. Freshness is:
|
|
1598
|
+
* - extension INVOKE hook (default 30s min interval)
|
|
1599
|
+
* - extension polling (`METADATA_PROJECTION_CHECK_INTERVAL_MS`)
|
|
1600
|
+
* - `onProjectionCompleted(releaseId)` on the environment that handled
|
|
1601
|
+
* the event (does not fan out)
|
|
1602
|
+
* 6. Surface `getHealth()` on the service health endpoint
|
|
1603
|
+
* 7. Prefer `resolve(MetadataTypeCode, valueCode)` — exact type codes only
|
|
1604
|
+
* 8. Prefer MetadataReference `{ typeCode, valueCode }` on DTOs (or convention / dtoFieldBindings)
|
|
1605
|
+
*/
|
|
1606
|
+
declare const RUNTIME_METADATA_INTEGRATION_TARGETS: readonly ["care-plan-runtime", "monitoring-runtime", "threshold-runtime", "symptom-runtime-service", "task-service", "workflow-service", "alert-service"];
|
|
1607
|
+
|
|
1608
|
+
type ExtensionMetadataProviderOptions = {
|
|
1609
|
+
/** Base URL including scheme and port, e.g. `http://127.0.0.1:12701`. */
|
|
1610
|
+
baseUrl: string;
|
|
1611
|
+
/** Ready-wait timeout for status polling during initialize. */
|
|
1612
|
+
readyTimeoutMs?: number;
|
|
1613
|
+
/** Per-request timeout. */
|
|
1614
|
+
requestTimeoutMs?: number;
|
|
1615
|
+
logger?: StructuredLogger;
|
|
1616
|
+
fetchImpl?: typeof fetch;
|
|
1617
|
+
};
|
|
1618
|
+
/**
|
|
1619
|
+
* Localhost client for the metadata Lambda Extension.
|
|
1620
|
+
* Business Lambdas must not construct this directly — use
|
|
1621
|
+
* {@link createMetadataProvider}.
|
|
1622
|
+
*/
|
|
1623
|
+
declare class ExtensionMetadataProvider implements MetadataProvider {
|
|
1624
|
+
private readonly baseUrl;
|
|
1625
|
+
private readonly readyTimeoutMs;
|
|
1626
|
+
private readonly requestTimeoutMs;
|
|
1627
|
+
private readonly logger;
|
|
1628
|
+
private readonly fetchImpl;
|
|
1629
|
+
constructor(options: ExtensionMetadataProviderOptions);
|
|
1630
|
+
isAvailable(): Promise<boolean>;
|
|
1631
|
+
waitUntilReady(): Promise<MetadataProviderStatus>;
|
|
1632
|
+
getStatus(): Promise<MetadataProviderStatus>;
|
|
1633
|
+
getValue(typeCode: string, valueCode: string, options?: MetadataResolveOptions): Promise<MetadataValue | null>;
|
|
1634
|
+
batchGet(references: string[], options?: MetadataResolveOptions): Promise<MetadataBatchResult>;
|
|
1635
|
+
getRelatedValues(sourceTypeCode: string, sourceValueCode: string, targetTypeCode: string, options?: MetadataResolveOptions): Promise<MetadataValue[]>;
|
|
1636
|
+
getLocalizationValue(keyOrTypeCode: string, valueCodeOrLocale?: string, maybeLocale?: string): Promise<string | undefined>;
|
|
1637
|
+
getLocalizationMap(locale: string): Promise<Record<string, string> | undefined>;
|
|
1638
|
+
requestRefresh(releaseId?: string): Promise<boolean>;
|
|
1639
|
+
private toMetadataValue;
|
|
1640
|
+
private requestJson;
|
|
1641
|
+
}
|
|
1642
|
+
declare function defaultExtensionBaseUrl(port?: number): string;
|
|
1643
|
+
|
|
1644
|
+
type S3MetadataProviderOptions = {
|
|
1645
|
+
cache: MetadataCache;
|
|
1646
|
+
resolver: MetadataResolver;
|
|
1647
|
+
downloader: MetadataDownloader;
|
|
1648
|
+
ensureTypesLoaded: (typeCodes: readonly string[]) => Promise<void>;
|
|
1649
|
+
logger?: StructuredLogger;
|
|
1650
|
+
};
|
|
1651
|
+
/**
|
|
1652
|
+
* S3-backed provider used when the Lambda Extension is unavailable.
|
|
1653
|
+
* Relies on {@link MetadataCache} + selective `{typeCode}.json` downloads.
|
|
1654
|
+
* Application code must not call this class directly.
|
|
1655
|
+
*/
|
|
1656
|
+
declare class S3MetadataProvider implements MetadataProvider {
|
|
1657
|
+
private readonly cache;
|
|
1658
|
+
private readonly resolver;
|
|
1659
|
+
private readonly ensureTypesLoaded;
|
|
1660
|
+
private readonly logger;
|
|
1661
|
+
constructor(options: S3MetadataProviderOptions);
|
|
1662
|
+
isAvailable(): Promise<boolean>;
|
|
1663
|
+
getStatus(): Promise<MetadataProviderStatus>;
|
|
1664
|
+
getValue(typeCode: string, valueCode: string, options?: MetadataResolveOptions): Promise<MetadataValue | null>;
|
|
1665
|
+
batchGet(references: string[], options?: MetadataResolveOptions): Promise<MetadataBatchResult>;
|
|
1666
|
+
getRelatedValues(sourceTypeCode: string, sourceValueCode: string, targetTypeCode: string, options?: MetadataResolveOptions): Promise<MetadataValue[]>;
|
|
1667
|
+
}
|
|
1668
|
+
declare function relatedValueCodes(index: RelationshipIndex | undefined, sourceTypeCode: string, sourceValueCode: string, targetTypeCode: string): string[];
|
|
1669
|
+
/** S3 client is owned by RuntimeMetadataService; listed for documentation. */
|
|
1670
|
+
type S3MetadataProviderClient = S3Client;
|
|
1671
|
+
|
|
1672
|
+
type InMemoryMetadataRecord = {
|
|
1673
|
+
typeCode: string;
|
|
1674
|
+
valueCode: string;
|
|
1675
|
+
entry: ProjectionEntry;
|
|
1676
|
+
related?: Record<string, string[]>;
|
|
1677
|
+
};
|
|
1678
|
+
type InMemoryMetadataProviderOptions = {
|
|
1679
|
+
releaseId?: string;
|
|
1680
|
+
records?: InMemoryMetadataRecord[];
|
|
1681
|
+
unavailable?: boolean;
|
|
1682
|
+
};
|
|
1683
|
+
/**
|
|
1684
|
+
* Test / local provider. Never talks to S3 or the extension.
|
|
1685
|
+
*/
|
|
1686
|
+
declare class InMemoryMetadataProvider implements MetadataProvider {
|
|
1687
|
+
private releaseId;
|
|
1688
|
+
private unavailable;
|
|
1689
|
+
private forcedState?;
|
|
1690
|
+
private readonly byKey;
|
|
1691
|
+
private readonly related;
|
|
1692
|
+
constructor(options?: InMemoryMetadataProviderOptions);
|
|
1693
|
+
isAvailable(): Promise<boolean>;
|
|
1694
|
+
setUnavailable(unavailable: boolean): void;
|
|
1695
|
+
setReleaseId(releaseId: string): void;
|
|
1696
|
+
setState(state: string): void;
|
|
1697
|
+
replaceRecords(records: InMemoryMetadataRecord[], releaseId?: string): void;
|
|
1698
|
+
waitUntilReady(): Promise<MetadataProviderStatus>;
|
|
1699
|
+
requestRefresh(_releaseId?: string): Promise<boolean>;
|
|
1700
|
+
getStatus(): Promise<MetadataProviderStatus>;
|
|
1701
|
+
getValue(typeCode: string, valueCode: string, options?: MetadataResolveOptions): Promise<MetadataValue | null>;
|
|
1702
|
+
batchGet(references: string[], options?: MetadataResolveOptions): Promise<MetadataBatchResult>;
|
|
1703
|
+
getRelatedValues(sourceTypeCode: string, sourceValueCode: string, targetTypeCode: string, options?: MetadataResolveOptions): Promise<MetadataValue[]>;
|
|
1704
|
+
}
|
|
1705
|
+
|
|
1706
|
+
declare const PROVIDER_TRANSPORT_STATE: {
|
|
1707
|
+
readonly EXTENSION_READY: "EXTENSION_READY";
|
|
1708
|
+
readonly EXTENSION_UNAVAILABLE: "EXTENSION_UNAVAILABLE";
|
|
1709
|
+
};
|
|
1710
|
+
type ProviderTransportState = (typeof PROVIDER_TRANSPORT_STATE)[keyof typeof PROVIDER_TRANSPORT_STATE];
|
|
1711
|
+
declare const DEFAULT_PROVIDER_RECOVERY_COOLDOWN_MS = 2000;
|
|
1712
|
+
type ProviderFailoverCoordinatorOptions = {
|
|
1713
|
+
extension: MetadataProvider;
|
|
1714
|
+
fallback?: MetadataProvider;
|
|
1715
|
+
kind: MetadataProviderKind;
|
|
1716
|
+
logger: StructuredLogger;
|
|
1717
|
+
/** Min interval between extension probes while in S3 fallback. */
|
|
1718
|
+
recoveryCooldownMs?: number;
|
|
1719
|
+
now?: () => number;
|
|
1720
|
+
onFallbackActivated?: (reason: string) => Promise<void>;
|
|
1721
|
+
onRecovered?: (status: MetadataProviderStatus) => Promise<void>;
|
|
1722
|
+
};
|
|
1723
|
+
/**
|
|
1724
|
+
* Deterministic, concurrency-safe extension ↔ S3 transport selection.
|
|
1725
|
+
*
|
|
1726
|
+
* Slow extension startup is not terminal: S3 may serve until the extension
|
|
1727
|
+
* becomes READY, then the SDK switches back. Health probes are coalesced and
|
|
1728
|
+
* cooldown-gated so concurrent lookups cannot stampede localhost.
|
|
1729
|
+
*/
|
|
1730
|
+
declare class ProviderFailoverCoordinator {
|
|
1731
|
+
private state;
|
|
1732
|
+
private recoveryInFlight;
|
|
1733
|
+
private fallbackActivateInFlight;
|
|
1734
|
+
private lastProbeAt;
|
|
1735
|
+
private healthCheckCount;
|
|
1736
|
+
private readonly extension;
|
|
1737
|
+
private readonly fallback?;
|
|
1738
|
+
private readonly kind;
|
|
1739
|
+
private readonly logger;
|
|
1740
|
+
private readonly recoveryCooldownMs;
|
|
1741
|
+
private readonly now;
|
|
1742
|
+
private readonly onFallbackActivated?;
|
|
1743
|
+
private readonly onRecovered?;
|
|
1744
|
+
constructor(options: ProviderFailoverCoordinatorOptions);
|
|
1745
|
+
getState(): ProviderTransportState;
|
|
1746
|
+
getActiveKind(): MetadataProviderKind;
|
|
1747
|
+
usesExtension(): boolean;
|
|
1748
|
+
getHealthCheckCount(): number;
|
|
1749
|
+
/**
|
|
1750
|
+
* Returns the current provider without probing. Warm extension path:
|
|
1751
|
+
* zero localhost health checks.
|
|
1752
|
+
*/
|
|
1753
|
+
peekProvider(): MetadataProvider;
|
|
1754
|
+
/**
|
|
1755
|
+
* When serving from S3 fallback, opportunistically recover if the cooldown
|
|
1756
|
+
* has elapsed. Concurrent callers share one in-flight probe.
|
|
1757
|
+
*/
|
|
1758
|
+
activeProvider(): Promise<MetadataProvider>;
|
|
1759
|
+
activateFallback(reason: string): Promise<void>;
|
|
1760
|
+
maybeRecover(): Promise<boolean>;
|
|
1761
|
+
private doActivateFallback;
|
|
1762
|
+
private probeExtension;
|
|
1763
|
+
}
|
|
1764
|
+
declare function isExtensionServing(status: MetadataProviderStatus): boolean;
|
|
1765
|
+
|
|
1766
|
+
export { CACHE_STATUS, type CacheStatus, type CandidateDiagnostic, type CollectMetadataDiagnostics, type CollectResponseMetadataOptions, type CreateRuntimeMetadataFromEnvOptions, DEFAULT_EXCLUDED_CODE_FIELDS, DEFAULT_PROVIDER_RECOVERY_COOLDOWN_MS, ExtensionMetadataProvider, type ExtensionMetadataProviderOptions, InMemoryMetadataProvider, type InMemoryMetadataProviderOptions, type InMemoryMetadataRecord, InvalidMetadataReferenceError, type LoadedProjectionBundle, METADATA_PROJECTIONS_BUCKET_ENV, METADATA_PROVIDER_KIND, type ManifestCompareResult, type ManifestLookupIndexEntry, type ManifestMetadataTypeEntry, ManifestValidationError, type MetadataBatchResult, MetadataCache, type MetadataCacheSnapshot, type MetadataCacheWriteGuard, MetadataDownloader, type MetadataDownloaderOptions, type MetadataHealthReport, MetadataHealthService, type MetadataHealthServiceOptions, MetadataLoader, type MetadataLoaderOptions, MetadataLookupError, MetadataNotReadyError, MetadataProjectionUnavailableError, type MetadataProvider, type MetadataProviderKind, type MetadataProviderStatus, type MetadataReference, MetadataRefreshService, type MetadataRefreshServiceOptions, type MetadataResolveOptions, MetadataResolver, type MetadataResolverOptions, type MetadataValue, NON_METADATA_KEYS, PROVIDER_TRANSPORT_STATE, ProjectionDownloadError, type ProjectionEntry, type ProjectionVersionEntry, ProviderFailoverCoordinator, type ProviderFailoverCoordinatorOptions, type ProviderTransportState, REFRESH_STATUS, RUNTIME_METADATA_EVENTS, RUNTIME_METADATA_INTEGRATION_TARGETS, RUNTIME_METADATA_TYPE_CODE_ALIASES, type ReadModelArtifact, type ReadModelBundle, type ReadModelCache, type ReadModelCacheLoader, type ReadModelDownloader, type ReadModelGroupDescriptor, type ReadModelGroupId, type ReadModelManifestGroupView, type ReadModelManifestGroups, type ReadModelProvider, type ReadModelRefreshCoordinator, type ReadModelResolver, type RefreshStatus, type ResolvableMetadataType, type ResolvedProjectionEntry, type RuntimeMetadataConfig, type RuntimeMetadataConfigInput, RuntimeMetadataError, RuntimeMetadataService, type RuntimeMetadataServiceOptions, S3MetadataProvider, type S3MetadataProviderClient, type S3MetadataProviderOptions, type SelectMetadataProviderInput, type SelectedMetadataProvider, 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 };
|