@htilabs/platform-common-models 0.2.0-beta.4 → 0.3.0-beta.5

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.
Files changed (75) hide show
  1. package/README.md +38 -0
  2. package/dist/constants/index.cjs +0 -843
  3. package/dist/constants/index.cjs.map +1 -1
  4. package/dist/constants/index.d.cts +146 -5
  5. package/dist/constants/index.d.ts +146 -5
  6. package/dist/constants/index.js +0 -786
  7. package/dist/constants/index.js.map +1 -1
  8. package/dist/{platform-role-AHv1l5Og.d.cts → cvcEntry-wqktWfzE.d.cts} +231 -37
  9. package/dist/{platform-role-AHv1l5Og.d.ts → cvcEntry-wqktWfzE.d.ts} +231 -37
  10. package/dist/cvcs/index.cjs +2184 -0
  11. package/dist/cvcs/index.cjs.map +1 -0
  12. package/dist/cvcs/index.d.cts +2384 -0
  13. package/dist/cvcs/index.d.ts +2384 -0
  14. package/dist/cvcs/index.js +2154 -0
  15. package/dist/cvcs/index.js.map +1 -0
  16. package/dist/index--NCIPluF.d.cts +378 -0
  17. package/dist/index-CFOrHA8l.d.ts +378 -0
  18. package/dist/index.cjs +2962 -843
  19. package/dist/index.cjs.map +1 -1
  20. package/dist/index.d.cts +217 -3
  21. package/dist/index.d.ts +217 -3
  22. package/dist/index.js +2934 -786
  23. package/dist/index.js.map +1 -1
  24. package/dist/models/index.cjs +211 -0
  25. package/dist/models/index.cjs.map +1 -1
  26. package/dist/models/index.d.cts +3 -292
  27. package/dist/models/index.d.ts +3 -292
  28. package/dist/models/index.js +209 -0
  29. package/dist/models/index.js.map +1 -1
  30. package/dist/{platform-auth-BTbQIY3b.d.cts → platform-auth-C-G2qeGM.d.cts} +1 -297
  31. package/dist/{platform-auth-BTbQIY3b.d.ts → platform-auth-C-G2qeGM.d.ts} +1 -297
  32. package/dist/schemas/index.cjs +195 -729
  33. package/dist/schemas/index.cjs.map +1 -1
  34. package/dist/schemas/index.d.cts +11 -11
  35. package/dist/schemas/index.d.ts +11 -11
  36. package/dist/schemas/index.js +189 -729
  37. package/dist/schemas/index.js.map +1 -1
  38. package/dist/services/index.cjs +1442 -0
  39. package/dist/services/index.cjs.map +1 -0
  40. package/dist/services/index.d.cts +305 -0
  41. package/dist/services/index.d.ts +305 -0
  42. package/dist/services/index.js +1417 -0
  43. package/dist/services/index.js.map +1 -0
  44. package/dist/types/index.d.cts +2 -2
  45. package/dist/types/index.d.ts +2 -2
  46. package/dist/validation/index.cjs +261 -0
  47. package/dist/validation/index.cjs.map +1 -0
  48. package/dist/validation/index.d.cts +251 -0
  49. package/dist/validation/index.d.ts +251 -0
  50. package/dist/validation/index.js +228 -0
  51. package/dist/validation/index.js.map +1 -0
  52. package/package.json +36 -12
  53. package/src/__tests__/__snapshots__/cvc-sot.snap +22 -0
  54. package/src/__tests__/cvc-sot-snapshot.test.ts +184 -0
  55. package/src/__tests__/cvc-structural.test.ts +130 -0
  56. package/src/constants/ic.ts +0 -925
  57. package/src/constants/service-catalog.ts +146 -4
  58. package/src/cvcs/index.ts +31 -0
  59. package/src/cvcs/missingness.v1.0.0.json +50 -0
  60. package/src/cvcs/serviceCategories.v1.0.0.json +1947 -0
  61. package/src/cvcs/serviceMechanisms.v1.0.0.json +47 -0
  62. package/src/cvcs/serviceStates.v1.0.0.json +106 -0
  63. package/src/generated/cvc-enums.ts +215 -0
  64. package/src/index.ts +61 -1
  65. package/src/models/cvcEntryModel.ts +32 -0
  66. package/src/models/cvcRegistryModel.ts +35 -0
  67. package/src/models/index.ts +8 -0
  68. package/src/schemas/cvcEntry.ts +158 -0
  69. package/src/schemas/cvcRegistry.ts +149 -0
  70. package/src/schemas/index.ts +16 -0
  71. package/src/services/__tests__/cvcRegistryService.test.ts +614 -0
  72. package/src/services/cvcRegistryService.ts +729 -0
  73. package/src/services/index.ts +21 -0
  74. package/src/validation/cvc.ts +414 -0
  75. package/src/validation/index.ts +15 -0
@@ -0,0 +1,130 @@
1
+ /**
2
+ * CVC Structural CI Test — locked spec §4 invariants
3
+ *
4
+ * For every committed SOT JSON file in `src/cvcs/`, this test:
5
+ * 1. Parses the envelope via `CvcEnvelopeSchema.parse()` — enforces shape
6
+ * (envelope fields, entry field types, code/key regex at entry level).
7
+ * 2. Calls `validateCvc()` — enforces §4 semantic invariants C1-C5, C7, C8
8
+ * (and C6 via the mechanism-key set wired in below).
9
+ *
10
+ * Cross-CVC C6 check: service_categories entries carry `relevantMechanisms`
11
+ * arrays pointing at `service_mechanisms` keys. Before validating the
12
+ * categories file we load the mechanisms file and build the set of valid
13
+ * keys; passing that into `validateCvc()` lights up the cross-ref check.
14
+ *
15
+ * This test is designed to run under vitest (`npm test`) on every PR and
16
+ * fail loud if any SOT file drifts from the locked spec §4 invariants. Each
17
+ * invariant is labeled `C1`..`C8` so CI output points straight at the spec
18
+ * rule that broke.
19
+ */
20
+
21
+ import { readFileSync } from "node:fs";
22
+ import path from "node:path";
23
+ import { fileURLToPath } from "node:url";
24
+
25
+ import { describe, it, expect } from "vitest";
26
+
27
+ import {
28
+ CvcEnvelopeSchema,
29
+ validateCvc,
30
+ type CvcValidationError,
31
+ } from "../validation/cvc.js";
32
+
33
+ // ─── Paths ──────────────────────────────────────────────────────────────────
34
+
35
+ const __filename = fileURLToPath(import.meta.url);
36
+ const __dirname = path.dirname(__filename);
37
+ const CVCS_DIR = path.resolve(__dirname, "..", "cvcs");
38
+
39
+ // ─── SOT files under test ───────────────────────────────────────────────────
40
+ // Ordering matters: load `service_mechanisms` first so we have its key set
41
+ // available before validating `service_categories` (which cross-references
42
+ // mechanism keys).
43
+
44
+ interface SotFile {
45
+ file: string;
46
+ expectedDomain: string;
47
+ }
48
+
49
+ const SOT_FILES: readonly SotFile[] = [
50
+ { file: "missingness.v1.0.0.json", expectedDomain: "missingness" },
51
+ { file: "serviceMechanisms.v1.0.0.json", expectedDomain: "service_mechanisms" },
52
+ { file: "serviceStates.v1.0.0.json", expectedDomain: "service_states" },
53
+ { file: "serviceCategories.v1.0.0.json", expectedDomain: "service_categories" },
54
+ ] as const;
55
+
56
+ function loadSot(file: string): unknown {
57
+ return JSON.parse(readFileSync(path.join(CVCS_DIR, file), "utf-8"));
58
+ }
59
+
60
+ /**
61
+ * Format validator errors as a single string for expect-assertion failure
62
+ * messages. Each line names the violated invariant so developers see which
63
+ * locked spec rule broke without rerunning with verbose flags.
64
+ */
65
+ function formatErrors(errors: readonly CvcValidationError[]): string {
66
+ return errors
67
+ .map((e) => {
68
+ const loc = e.code
69
+ ? ` [${e.code}${e.key ? ` / ${e.key}` : ""}]`
70
+ : "";
71
+ return ` ${e.invariant}${loc}: ${e.message}`;
72
+ })
73
+ .join("\n");
74
+ }
75
+
76
+ // ─── Tests ──────────────────────────────────────────────────────────────────
77
+
78
+ describe("CVC structural invariants (locked spec §4)", () => {
79
+ // Pre-load mechanism keys for the C6 cross-reference check.
80
+ const mechanismsRaw = loadSot("serviceMechanisms.v1.0.0.json");
81
+ const mechanismsEnvelope = CvcEnvelopeSchema.parse(mechanismsRaw);
82
+ const mechanismKeys = new Set(mechanismsEnvelope.entries.map((e) => e.key));
83
+
84
+ for (const { file, expectedDomain } of SOT_FILES) {
85
+ describe(file, () => {
86
+ const raw = loadSot(file);
87
+
88
+ it("parses via CvcEnvelopeSchema (shape contract)", () => {
89
+ // Zod will throw with a detailed error object if shape is wrong;
90
+ // letting it bubble gives vitest a readable failure.
91
+ expect(() => CvcEnvelopeSchema.parse(raw)).not.toThrow();
92
+ });
93
+
94
+ it(`envelope domain matches expected (${expectedDomain})`, () => {
95
+ const envelope = CvcEnvelopeSchema.parse(raw);
96
+ expect(envelope.domain).toBe(expectedDomain);
97
+ });
98
+
99
+ it("passes validateCvc (§4 invariants C1-C8)", () => {
100
+ const envelope = CvcEnvelopeSchema.parse(raw);
101
+
102
+ // Only service_categories needs mechanism cross-refs; other CVCs
103
+ // have no `relevantMechanisms` field so passing the set is harmless.
104
+ const errors = validateCvc(envelope, { mechanismKeys });
105
+
106
+ if (errors.length > 0) {
107
+ throw new Error(
108
+ `${file} violated §4 invariants:\n${formatErrors(errors)}`,
109
+ );
110
+ }
111
+ expect(errors).toHaveLength(0);
112
+ });
113
+ });
114
+ }
115
+
116
+ it("service_categories has at least one entry with relevantMechanisms (sanity: passthrough works)", () => {
117
+ // Guard against a future regression where CvcEntrySchema stops passing
118
+ // domain-specific fields through. Without this, C6 would silently pass
119
+ // on an empty input.
120
+ const raw = loadSot("serviceCategories.v1.0.0.json");
121
+ const envelope = CvcEnvelopeSchema.parse(raw);
122
+ const withRelevant = envelope.entries.filter((e) => {
123
+ const field = (e as unknown as Record<string, unknown>)[
124
+ "relevantMechanisms"
125
+ ];
126
+ return Array.isArray(field) && field.length > 0;
127
+ });
128
+ expect(withRelevant.length).toBeGreaterThan(0);
129
+ });
130
+ });