@myvitalrx/metadata-runtime 0.0.0-stage → 1.1.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 CHANGED
@@ -1,3 +1,777 @@
1
- # Temporary Holding Version
1
+ # Metadata Runtime Projection
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Reusable runtime library for consuming and resolving **Metadata Registry projections** across MyVitalRx services.
4
+
5
+ The package provides a consistent way for services to work with published metadata without directly coupling runtime operations to the Metadata Registry service.
6
+
7
+ ## Overview
8
+
9
+ The Metadata Registry acts as the centralized source of truth for metadata.
10
+
11
+ At runtime, services should consume the **published metadata projection** rather than repeatedly querying the Metadata Registry.
12
+
13
+ ```text
14
+ Metadata Registry
15
+ │
16
+ │ Publish
17
+ ▼
18
+ Metadata Projection
19
+ │
20
+ ▼
21
+ S3 Projection
22
+ │
23
+ │
24
+ ┌─────────┴─────────┐
25
+ │ │
26
+ ▼ ▼
27
+ Metadata Runtime Other Consumers
28
+ │
29
+ ▼
30
+ Domain Services
31
+ ```
32
+
33
+ `@myvitalrx/metadata-runtime` provides the reusable runtime capabilities required to load, resolve, and work with these projections.
34
+
35
+ ---
36
+
37
+ ## Goals
38
+
39
+ The library is designed to:
40
+
41
+ - Provide a reusable metadata runtime across services.
42
+ - Consume published metadata projections.
43
+ - Resolve metadata by stable codes.
44
+ - Resolve supported metadata relationships.
45
+ - Avoid direct Metadata Registry calls during normal runtime operations.
46
+ - Keep metadata access consistent across services.
47
+ - Allow the underlying metadata storage mechanism to evolve independently.
48
+ - Provide a stable NPM package that can be consumed by multiple repositories.
49
+
50
+ ---
51
+
52
+ ## Installation
53
+
54
+ Install the package from the configured private NPM registry:
55
+
56
+ ```bash
57
+ npm install @myvitalrx/metadata-runtime
58
+ ```
59
+
60
+ The package should be installed using the same registry/authentication configuration used by the other MyVitalRx internal packages.
61
+
62
+ ---
63
+
64
+ ## Basic Usage
65
+
66
+ Import the required runtime functionality from the package public API:
67
+
68
+ ```typescript
69
+ import {
70
+ MetadataRuntime,
71
+ } from '@myvitalrx/metadata-runtime';
72
+ ```
73
+
74
+ Initialize the runtime using the appropriate metadata provider:
75
+
76
+ ```typescript
77
+ const metadataRuntime = new MetadataRuntime({
78
+ provider: metadataProvider,
79
+ });
80
+ ```
81
+
82
+ The exact configuration should follow the exported public API of the installed package version.
83
+
84
+ ---
85
+
86
+ # Architecture
87
+
88
+ The runtime package is intentionally separated from the Metadata Registry.
89
+
90
+ ```text
91
+ ┌──────────────────────┐
92
+ │ Metadata Registry │
93
+ │ Source of Truth │
94
+ └──────────┬───────────┘
95
+ │
96
+ │ Metadata Published
97
+ ▼
98
+ ┌──────────────────────┐
99
+ │ Projection Builder │
100
+ └──────────┬───────────┘
101
+ │
102
+ ▼
103
+ ┌──────────────────────┐
104
+ │ S3 Metadata │
105
+ │ Projection │
106
+ └──────────┬───────────┘
107
+ │
108
+ ▼
109
+ ┌────────────────────────────┐
110
+ │ Metadata Runtime │
111
+ │ │
112
+ │ Metadata Resolution │
113
+ │ Relationship Resolution │
114
+ │ Projection Access │
115
+ │ Provider Abstraction │
116
+ └────────────┬───────────────┘
117
+ │
118
+ ▼
119
+ Domain Services
120
+ ```
121
+
122
+ The runtime library should not become a replacement for the Metadata Registry.
123
+
124
+ Its responsibility is to provide efficient runtime access to the **published metadata state**.
125
+
126
+ ---
127
+
128
+ # Metadata Provider
129
+
130
+ The runtime should interact with metadata through a provider abstraction rather than directly depending on a particular storage implementation.
131
+
132
+ Conceptually:
133
+
134
+ ```typescript
135
+ interface MetadataProvider {
136
+ getMetadata(
137
+ metadataType: string,
138
+ code: string,
139
+ ): Promise<Metadata | undefined>;
140
+
141
+ getMetadataByType(
142
+ metadataType: string,
143
+ ): Promise<Metadata[]>;
144
+
145
+ getRelatedValues(
146
+ sourceType: string,
147
+ sourceCode: string,
148
+ targetType: string,
149
+ ): Promise<Metadata[]>;
150
+ }
151
+ ```
152
+
153
+ The actual interface should be consumed from the package's public API and should follow the implementation defined by the library.
154
+
155
+ This abstraction allows the runtime to work with different metadata sources without changing domain services.
156
+
157
+ Possible providers include:
158
+
159
+ ```text
160
+ S3 Projection
161
+ │
162
+ ▼
163
+ MetadataProvider
164
+
165
+ In-Memory Projection
166
+ │
167
+ ▼
168
+ MetadataProvider
169
+
170
+ Test Fixture
171
+ │
172
+ ▼
173
+ MetadataProvider
174
+ ```
175
+
176
+ ---
177
+
178
+ # Why Use a Provider?
179
+
180
+ Services should not need to know whether metadata is stored in:
181
+
182
+ - S3
183
+ - DynamoDB
184
+ - an in-memory cache
185
+ - a local projection
186
+ - another optimized metadata store
187
+
188
+ The service only needs to work with the runtime contract.
189
+
190
+ For example:
191
+
192
+ ```typescript
193
+ const condition = await metadataRuntime.getMetadata(
194
+ 'Condition',
195
+ 'DIABETES',
196
+ );
197
+ ```
198
+
199
+ The service does not need to know how `DIABETES` was retrieved.
200
+
201
+ ---
202
+
203
+ # Metadata Resolution
204
+
205
+ Metadata should be referenced by stable codes.
206
+
207
+ Example:
208
+
209
+ ```typescript
210
+ const condition = await metadataRuntime.getMetadata(
211
+ 'Condition',
212
+ 'DIABETES',
213
+ );
214
+ ```
215
+
216
+ Conceptually:
217
+
218
+ ```text
219
+ Metadata Type
220
+ │
221
+ ▼
222
+ Condition
223
+ │
224
+ ▼
225
+ Code
226
+ │
227
+ ▼
228
+ DIABETES
229
+ │
230
+ ▼
231
+ Published Metadata
232
+ ```
233
+
234
+ This allows domain services to persist stable metadata codes instead of duplicating metadata definitions.
235
+
236
+ ---
237
+
238
+ # Relationship Resolution
239
+
240
+ The runtime can also resolve supported relationships between metadata types.
241
+
242
+ For example:
243
+
244
+ ```typescript
245
+ const devices = await metadataRuntime.getRelatedValues(
246
+ 'Vital',
247
+ 'BLOOD_PRESSURE',
248
+ 'Device',
249
+ );
250
+ ```
251
+
252
+ Conceptually:
253
+
254
+ ```text
255
+ Vital
256
+ │
257
+ └── BLOOD_PRESSURE
258
+ │
259
+ │ relationship
260
+ ▼
261
+ Device
262
+ │
263
+ ├── BP_MONITOR
264
+ └── DIGITAL_BP_DEVICE
265
+ ```
266
+
267
+ Reverse relationship resolution can also be supported where the metadata projection defines the relationship.
268
+
269
+ Example:
270
+
271
+ ```typescript
272
+ const conditions = await metadataRuntime.getRelatedValues(
273
+ 'Category',
274
+ 'CHRONIC',
275
+ 'Condition',
276
+ );
277
+ ```
278
+
279
+ The relationship should be resolved from the published metadata projection rather than requiring a direct Metadata Registry API call.
280
+
281
+ ---
282
+
283
+ # Runtime Data Flow
284
+
285
+ A typical runtime request looks like:
286
+
287
+ ```text
288
+ API Request
289
+ │
290
+ ▼
291
+ Domain Service
292
+ │
293
+ ▼
294
+ Metadata Runtime
295
+ │
296
+ ▼
297
+ Metadata Provider
298
+ │
299
+ ▼
300
+ Published Metadata Projection
301
+ │
302
+ ▼
303
+ Metadata Result
304
+ │
305
+ ▼
306
+ Domain Service
307
+ ```
308
+
309
+ The metadata runtime is therefore an **access/resolution layer**, not the system of record.
310
+
311
+ ---
312
+
313
+ # Caching
314
+
315
+ The runtime may use an appropriate caching strategy depending on the provider implementation.
316
+
317
+ The package should avoid making repeated remote calls for the same metadata within a request or execution context when caching is appropriate.
318
+
319
+ For example:
320
+
321
+ ```text
322
+ Request
323
+ │
324
+ ├── Resolve Condition: DIABETES
325
+ │ │
326
+ │ └── Projection lookup
327
+ │
328
+ ├── Resolve Condition: DIABETES
329
+ │ │
330
+ │ └── Cached result
331
+ │
332
+ └── Resolve Condition: DIABETES
333
+ │
334
+ └── Cached result
335
+ ```
336
+
337
+ Caching behavior should remain an implementation detail of the provider/runtime and should not require domain services to implement their own metadata caching.
338
+
339
+ ---
340
+
341
+ # Versioning
342
+
343
+ The package follows semantic versioning:
344
+
345
+ ```text
346
+ MAJOR.MINOR.PATCH
347
+ ```
348
+
349
+ Example:
350
+
351
+ ```text
352
+ 1.0.0
353
+ 1.1.0
354
+ 1.1.1
355
+ 2.0.0
356
+ ```
357
+
358
+ ### MAJOR
359
+
360
+ Breaking changes to the public API.
361
+
362
+ ### MINOR
363
+
364
+ Backward-compatible functionality.
365
+
366
+ ### PATCH
367
+
368
+ Backward-compatible bug fixes or internal improvements.
369
+
370
+ Consumers should explicitly control the package version used by their service.
371
+
372
+ Example:
373
+
374
+ ```json
375
+ {
376
+ "dependencies": {
377
+ "@myvitalrx/metadata-runtime": "1.2.0"
378
+ }
379
+ }
380
+ ```
381
+
382
+ For production services, avoid automatically consuming an untested major/minor version.
383
+
384
+ ---
385
+
386
+ # Metadata Version vs Package Version
387
+
388
+ The NPM package version and metadata projection version are different concepts.
389
+
390
+ ```text
391
+ NPM Package Version
392
+ │
393
+ └── Runtime library implementation
394
+
395
+ Metadata Projection Version
396
+ │
397
+ └── Published metadata state
398
+ ```
399
+
400
+ Updating the runtime package does not automatically change the metadata consumed by a service.
401
+
402
+ Similarly, publishing new metadata does not require publishing a new NPM package unless the runtime implementation itself changes.
403
+
404
+ ---
405
+
406
+ # Runtime Snapshot Principle
407
+
408
+ The runtime should consume the metadata projection/version that has been made available to the service.
409
+
410
+ This prevents metadata changes from unexpectedly changing existing business behavior.
411
+
412
+ Conceptually:
413
+
414
+ ```text
415
+ Metadata Registry
416
+ │
417
+ ▼
418
+ Published Metadata
419
+ │
420
+ ▼
421
+ Runtime Projection
422
+ │
423
+ ▼
424
+ Service
425
+ ```
426
+
427
+ The service should not dynamically mutate its business behavior simply because metadata was changed in the registry.
428
+
429
+ ---
430
+
431
+ # Error Handling
432
+
433
+ Consumers should handle metadata resolution failures explicitly.
434
+
435
+ Example:
436
+
437
+ ```typescript
438
+ const metadata = await metadataRuntime.getMetadata(
439
+ 'Condition',
440
+ conditionCode,
441
+ );
442
+
443
+ if (!metadata) {
444
+ // Handle unknown or unavailable metadata
445
+ }
446
+ ```
447
+
448
+ The runtime should distinguish between:
449
+
450
+ - metadata not found
451
+ - invalid metadata request
452
+ - provider failure
453
+ - projection unavailable
454
+ - malformed projection data
455
+
456
+ Do not silently convert infrastructure/provider failures into "metadata not found".
457
+
458
+ ---
459
+
460
+ # Package Design Principles
461
+
462
+ The package should follow these principles.
463
+
464
+ ### 1. Storage Agnostic
465
+
466
+ The core runtime should not be tightly coupled to S3, DynamoDB, or another storage engine.
467
+
468
+ ### 2. Registry Independent
469
+
470
+ Domain services should not need to call the Metadata Registry directly for normal metadata resolution.
471
+
472
+ ### 3. Stable Public API
473
+
474
+ Consumers should only depend on APIs exported through the package entry point.
475
+
476
+ ### 4. Reusable
477
+
478
+ The package should work across:
479
+
480
+ - Lambda services
481
+ - API services
482
+ - background workers
483
+ - scheduled jobs
484
+ - other repositories
485
+
486
+ ### 5. Lightweight
487
+
488
+ Avoid unnecessary AWS SDK dependencies or other heavy dependencies in the core runtime.
489
+
490
+ ### 6. Testable
491
+
492
+ The provider abstraction should allow in-memory/mock implementations for unit and integration testing.
493
+
494
+ ---
495
+
496
+ # NPM Package Structure
497
+
498
+ The package is maintained inside the Nx monorepo but is published independently.
499
+
500
+ Conceptually:
501
+
502
+ ```text
503
+ Nx Monorepo
504
+ │
505
+ ├── libs/
506
+ │ ├── metadata-runtime/
507
+ │ │ ├── src/
508
+ │ │ │ ├── index.ts
509
+ │ │ │ ├── runtime/
510
+ │ │ │ ├── provider/
511
+ │ │ │ ├── projection/
512
+ │ │ │ └── relationship/
513
+ │ │ ├── project.json
514
+ │ │ └── ...
515
+ │ │
516
+ │ └── other-published-libraries/
517
+ │
518
+ └── scripts/
519
+ └── publishing/
520
+ ```
521
+
522
+ The actual directory structure should follow the existing repository publishing conventions.
523
+
524
+ ---
525
+
526
+ # Development
527
+
528
+ Build the package:
529
+
530
+ ```bash
531
+ nx build <metadata-runtime-project>
532
+ ```
533
+
534
+ Run tests:
535
+
536
+ ```bash
537
+ nx test <metadata-runtime-project>
538
+ ```
539
+
540
+ Run lint:
541
+
542
+ ```bash
543
+ nx lint <metadata-runtime-project>
544
+ ```
545
+
546
+ ---
547
+
548
+ # Package Validation
549
+
550
+ Before publishing, validate the generated package:
551
+
552
+ ```bash
553
+ npm pack --dry-run
554
+ ```
555
+
556
+ Verify that the package contains only the required distribution artifacts.
557
+
558
+ A typical package should contain:
559
+
560
+ ```text
561
+ package.json
562
+ README.md
563
+ dist/
564
+ *.js
565
+ *.d.ts
566
+ ```
567
+
568
+ and should not contain:
569
+
570
+ ```text
571
+ node_modules/
572
+ tests/
573
+ Nx workspace configuration
574
+ source files
575
+ credentials
576
+ environment files
577
+ ```
578
+
579
+ unless explicitly required by the package implementation.
580
+
581
+ ---
582
+
583
+ # Publishing
584
+
585
+ The package follows the existing repository NPM publishing process.
586
+
587
+ Conceptually:
588
+
589
+ ```text
590
+ Build
591
+ │
592
+ ▼
593
+ Validate
594
+ │
595
+ ▼
596
+ Package
597
+ │
598
+ ▼
599
+ Publish
600
+ │
601
+ ▼
602
+ Private NPM Registry
603
+ ```
604
+
605
+ Example:
606
+
607
+ ```bash
608
+ nx build <metadata-runtime-project>
609
+
610
+ npm pack --dry-run
611
+
612
+ # Use the repository's standard publishing command
613
+ npm publish
614
+ ```
615
+
616
+ The actual publishing command should follow the existing monorepo publishing convention.
617
+
618
+ ---
619
+
620
+ # Authentication
621
+
622
+ NPM authentication must be provided through the repository's configured environment/CI mechanism.
623
+
624
+ Never commit an authentication token.
625
+
626
+ For local development, use the configured environment variable or `.npmrc` mechanism expected by the repository.
627
+
628
+ For CI/CD, the token should be injected securely by the pipeline.
629
+
630
+ ---
631
+
632
+ # Consuming the Package
633
+
634
+ From another service/repository:
635
+
636
+ ```bash
637
+ npm install @myvitalrx/metadata-runtime
638
+ ```
639
+
640
+ Then:
641
+
642
+ ```typescript
643
+ import {
644
+ MetadataRuntime,
645
+ } from '@myvitalrx/metadata-runtime';
646
+ ```
647
+
648
+ The consuming service should depend only on the published package API.
649
+
650
+ It should not import files directly from the Metadata Runtime repository:
651
+
652
+ ```typescript
653
+ // ❌ Do not do this
654
+
655
+ import { MetadataRuntime } from '../../../libs/metadata-runtime/src/...';
656
+ ```
657
+
658
+ Instead:
659
+
660
+ ```typescript
661
+ // ✅ Use the published package
662
+
663
+ import { MetadataRuntime } from '@myvitalrx/metadata-runtime';
664
+ ```
665
+
666
+ ---
667
+
668
+ # Compatibility
669
+
670
+ The package should remain compatible with the Node.js and TypeScript versions supported by the MyVitalRx platform.
671
+
672
+ Before upgrading the package's runtime requirements, verify compatibility with all consuming services.
673
+
674
+ ---
675
+
676
+ # Testing Strategy
677
+
678
+ The library should have tests covering:
679
+
680
+ ### Metadata Resolution
681
+
682
+ - Resolve metadata by type and code.
683
+ - Handle metadata not found.
684
+ - Handle invalid metadata requests.
685
+
686
+ ### Relationship Resolution
687
+
688
+ - Forward relationship resolution.
689
+ - Reverse relationship resolution where supported.
690
+ - Unknown relationships.
691
+ - Empty relationship results.
692
+
693
+ ### Provider
694
+
695
+ - Successful projection lookup.
696
+ - Projection unavailable.
697
+ - Provider errors.
698
+ - Malformed projection data.
699
+
700
+ ### Public API
701
+
702
+ Verify that consumers can import all supported APIs from:
703
+
704
+ ```typescript
705
+ @myvitalrx/metadata-runtime
706
+ ```
707
+
708
+ ---
709
+
710
+ # Example Usage
711
+
712
+ A service can use the runtime as follows:
713
+
714
+ ```typescript
715
+ import { MetadataRuntime } from '@myvitalrx/metadata-runtime';
716
+
717
+ const runtime = new MetadataRuntime({
718
+ provider: metadataProvider,
719
+ });
720
+
721
+ const condition = await runtime.getMetadata(
722
+ 'Condition',
723
+ 'DIABETES',
724
+ );
725
+
726
+ const devices = await runtime.getRelatedValues(
727
+ 'Vital',
728
+ 'BLOOD_PRESSURE',
729
+ 'Device',
730
+ );
731
+ ```
732
+
733
+ The domain service remains independent of the underlying metadata storage implementation.
734
+
735
+ ---
736
+
737
+ # Architecture Summary
738
+
739
+ ```text
740
+ ┌─────────────────────┐
741
+ │ Metadata Registry │
742
+ │ Source of Truth │
743
+ └──────────┬──────────┘
744
+ │
745
+ │ Publish
746
+ ▼
747
+ ┌─────────────────────┐
748
+ │ Projection Builder │
749
+ └──────────┬──────────┘
750
+ │
751
+ ▼
752
+ ┌─────────────────────┐
753
+ │ Metadata Projection │
754
+ │ S3 │
755
+ └──────────┬──────────┘
756
+ │
757
+ ▼
758
+ ┌────────────────────────────┐
759
+ │ Metadata Runtime NPM │
760
+ │ │
761
+ │ Metadata Resolution │
762
+ │ Relationship Resolution │
763
+ │ Provider Abstraction │
764
+ │ Runtime Caching │
765
+ └────────────┬───────────────┘
766
+ │
767
+ ┌────────────┼────────────┐
768
+ ▼ ▼ ▼
769
+ Template Package Other
770
+ Service Service Services
771
+ ```
772
+
773
+ ## Key Principle
774
+
775
+ > **Metadata Registry owns metadata. Metadata Projection publishes optimized runtime data. Metadata Runtime provides a reusable access and resolution layer for consuming that published data.**
776
+
777
+ The NPM package allows multiple services and repositories to consume the same runtime implementation without duplicating metadata resolution logic.