@htilabs/platform-common-models 0.2.0-beta.4 → 0.4.0-beta.1

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 (74) 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 +2350 -0
  11. package/dist/cvcs/index.cjs.map +1 -0
  12. package/dist/cvcs/index.d.cts +2449 -0
  13. package/dist/cvcs/index.d.ts +2449 -0
  14. package/dist/cvcs/index.js +2321 -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 +3132 -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 +3106 -786
  23. package/dist/index.js.map +1 -1
  24. package/dist/models/index.cjs +212 -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 +210 -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 +196 -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 +190 -729
  37. package/dist/schemas/index.js.map +1 -1
  38. package/dist/services/index.cjs +1443 -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 +1418 -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 +254 -0
  47. package/dist/validation/index.cjs.map +1 -0
  48. package/dist/validation/index.d.cts +252 -0
  49. package/dist/validation/index.d.ts +252 -0
  50. package/dist/validation/index.js +221 -0
  51. package/dist/validation/index.js.map +1 -0
  52. package/package.json +36 -12
  53. package/src/__tests__/__snapshots__/cvc-sot.snap +18 -0
  54. package/src/__tests__/cvc-sot-snapshot.test.ts +184 -0
  55. package/src/__tests__/cvc-structural.test.ts +129 -0
  56. package/src/constants/ic.ts +0 -925
  57. package/src/constants/service-catalog.ts +146 -4
  58. package/src/cvcs/index.ts +30 -0
  59. package/src/cvcs/serviceCategories.v1.0.0.json +2077 -0
  60. package/src/cvcs/serviceMechanisms.v1.0.0.json +87 -0
  61. package/src/cvcs/serviceStates.v1.0.0.json +146 -0
  62. package/src/generated/cvc-enums.ts +213 -0
  63. package/src/index.ts +61 -1
  64. package/src/models/cvcEntryModel.ts +32 -0
  65. package/src/models/cvcRegistryModel.ts +35 -0
  66. package/src/models/index.ts +8 -0
  67. package/src/schemas/cvcEntry.ts +159 -0
  68. package/src/schemas/cvcRegistry.ts +150 -0
  69. package/src/schemas/index.ts +16 -0
  70. package/src/services/__tests__/cvcRegistryService.test.ts +614 -0
  71. package/src/services/cvcRegistryService.ts +729 -0
  72. package/src/services/index.ts +21 -0
  73. package/src/validation/cvc.ts +397 -0
  74. package/src/validation/index.ts +15 -0
@@ -0,0 +1,252 @@
1
+ import { z } from 'zod';
2
+
3
+ /**
4
+ * @htilabs/platform-common-models — Controlled Vocabulary (CVC) Validation
5
+ *
6
+ * Zod schemas for validating CVC Source-of-Truth (SOT) JSON files and
7
+ * individual CVC entries. Implements the locked spec §9.2 shapes.
8
+ *
9
+ * Used by:
10
+ * - CI structural tests that parse every committed SOT file.
11
+ * - The generalized seed CLI (`seedCvc`) prior to persistence.
12
+ * - Downstream consumers that need to validate CVC payloads.
13
+ *
14
+ * Canonical spec:
15
+ * /gt/docs/data/cvcs/CVC Implementation Spec 2780449faf8045258c67daab0f1c5569.md
16
+ *
17
+ * Format v2 (2026-04-15):
18
+ * - Positional 7-segment codes `XXX-XXX-XXX-XXX-XXX-XXX-XXX` (3 digits per
19
+ * segment). Segment 1 is the Notion-aligned domain prefix:
20
+ * `022` service_categories (CVC-22)
21
+ * `025` service_mechanisms (CVC-25)
22
+ * `049` service_state (CVC-49)
23
+ * - Missingness entries are embedded per-domain (synthetic `missingness_root`
24
+ * at `<prefix>-000-000-000-000-000-000` plus three values at segment 7 =
25
+ * `001`/`002`/`003`). The shared `missingness.v1.0.0.json` file was
26
+ * retired in favor of per-domain missingness.
27
+ * - Envelope `missingness` field and the C7 invariant have been removed; the
28
+ * shared-merge pathway no longer exists.
29
+ */
30
+
31
+ /**
32
+ * 7-segment positional CVC code: `XXX-XXX-XXX-XXX-XXX-XXX-XXX` (three digits
33
+ * per segment). Segment 1 is the Notion-aligned domain prefix. Remaining
34
+ * hierarchy segments are filled left-to-right as levels deepen; unused
35
+ * segments remain `000`. See locked spec §3 (format v2).
36
+ */
37
+ declare const CvcCodeSchema: z.ZodString;
38
+ /**
39
+ * Stable machine key for a CVC entry. Must start with a lowercase letter and
40
+ * contain only lowercase alphanumerics or underscores. Used as a cross-CVC
41
+ * reference target (e.g. `relevantMechanisms` pointing at mechanism keys).
42
+ * See locked spec §3.2.
43
+ */
44
+ declare const CvcKeySchema: z.ZodString;
45
+ /**
46
+ * Base entry shape shared by every CVC domain. Domain-specific extensions
47
+ * (e.g. `ServiceCategoryEntrySchema`) should use `.extend()` to add fields.
48
+ * See locked spec §9.2.
49
+ *
50
+ * Uses `.passthrough()` so that domain-specific fields (like
51
+ * `relevantMechanisms` on service-category entries) survive base parsing
52
+ * unmodified. This keeps cross-CVC reference validation honest: the §4.5
53
+ * structural validator needs to see the raw referenced keys, and a strip-by-
54
+ * default schema would silently hide them.
55
+ */
56
+ declare const CvcEntrySchema: z.ZodObject<{
57
+ code: z.ZodString;
58
+ key: z.ZodString;
59
+ title: z.ZodString;
60
+ selectable: z.ZodBoolean;
61
+ parentCode: z.ZodNullable<z.ZodString>;
62
+ childCodes: z.ZodArray<z.ZodString, "many">;
63
+ definition: z.ZodNullable<z.ZodString>;
64
+ }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
65
+ code: z.ZodString;
66
+ key: z.ZodString;
67
+ title: z.ZodString;
68
+ selectable: z.ZodBoolean;
69
+ parentCode: z.ZodNullable<z.ZodString>;
70
+ childCodes: z.ZodArray<z.ZodString, "many">;
71
+ definition: z.ZodNullable<z.ZodString>;
72
+ }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
73
+ code: z.ZodString;
74
+ key: z.ZodString;
75
+ title: z.ZodString;
76
+ selectable: z.ZodBoolean;
77
+ parentCode: z.ZodNullable<z.ZodString>;
78
+ childCodes: z.ZodArray<z.ZodString, "many">;
79
+ definition: z.ZodNullable<z.ZodString>;
80
+ }, z.ZodTypeAny, "passthrough">>;
81
+ /**
82
+ * Service-category-specific entry. Adds `relevantMechanisms` — a cross-CVC
83
+ * reference into the `service_mechanisms` domain via entry keys. `null` means
84
+ * "not applicable" (e.g. structural L1 topic rows). See locked spec §9.2.
85
+ */
86
+ declare const ServiceCategoryEntrySchema: z.ZodObject<{
87
+ code: z.ZodString;
88
+ key: z.ZodString;
89
+ title: z.ZodString;
90
+ selectable: z.ZodBoolean;
91
+ parentCode: z.ZodNullable<z.ZodString>;
92
+ childCodes: z.ZodArray<z.ZodString, "many">;
93
+ definition: z.ZodNullable<z.ZodString>;
94
+ } & {
95
+ relevantMechanisms: z.ZodNullable<z.ZodArray<z.ZodString, "many">>;
96
+ }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
97
+ code: z.ZodString;
98
+ key: z.ZodString;
99
+ title: z.ZodString;
100
+ selectable: z.ZodBoolean;
101
+ parentCode: z.ZodNullable<z.ZodString>;
102
+ childCodes: z.ZodArray<z.ZodString, "many">;
103
+ definition: z.ZodNullable<z.ZodString>;
104
+ } & {
105
+ relevantMechanisms: z.ZodNullable<z.ZodArray<z.ZodString, "many">>;
106
+ }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
107
+ code: z.ZodString;
108
+ key: z.ZodString;
109
+ title: z.ZodString;
110
+ selectable: z.ZodBoolean;
111
+ parentCode: z.ZodNullable<z.ZodString>;
112
+ childCodes: z.ZodArray<z.ZodString, "many">;
113
+ definition: z.ZodNullable<z.ZodString>;
114
+ } & {
115
+ relevantMechanisms: z.ZodNullable<z.ZodArray<z.ZodString, "many">>;
116
+ }, z.ZodTypeAny, "passthrough">>;
117
+ /**
118
+ * Top-level SOT JSON envelope. One envelope per (domain, version) pair.
119
+ *
120
+ * `levels` is a positional map from level number (`"0"`, `"1"`, …) to a human
121
+ * label describing the level. Missingness entries are embedded in `entries`
122
+ * (per-domain) rather than merged in from a shared SOT file; see module
123
+ * header for the v2 format summary.
124
+ */
125
+ declare const CvcEnvelopeSchema: z.ZodObject<{
126
+ domain: z.ZodString;
127
+ name: z.ZodString;
128
+ version: z.ZodString;
129
+ levels: z.ZodRecord<z.ZodString, z.ZodString>;
130
+ entries: z.ZodArray<z.ZodObject<{
131
+ code: z.ZodString;
132
+ key: z.ZodString;
133
+ title: z.ZodString;
134
+ selectable: z.ZodBoolean;
135
+ parentCode: z.ZodNullable<z.ZodString>;
136
+ childCodes: z.ZodArray<z.ZodString, "many">;
137
+ definition: z.ZodNullable<z.ZodString>;
138
+ }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
139
+ code: z.ZodString;
140
+ key: z.ZodString;
141
+ title: z.ZodString;
142
+ selectable: z.ZodBoolean;
143
+ parentCode: z.ZodNullable<z.ZodString>;
144
+ childCodes: z.ZodArray<z.ZodString, "many">;
145
+ definition: z.ZodNullable<z.ZodString>;
146
+ }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
147
+ code: z.ZodString;
148
+ key: z.ZodString;
149
+ title: z.ZodString;
150
+ selectable: z.ZodBoolean;
151
+ parentCode: z.ZodNullable<z.ZodString>;
152
+ childCodes: z.ZodArray<z.ZodString, "many">;
153
+ definition: z.ZodNullable<z.ZodString>;
154
+ }, z.ZodTypeAny, "passthrough">>, "many">;
155
+ }, "strip", z.ZodTypeAny, {
156
+ name: string;
157
+ version: string;
158
+ entries: z.objectOutputType<{
159
+ code: z.ZodString;
160
+ key: z.ZodString;
161
+ title: z.ZodString;
162
+ selectable: z.ZodBoolean;
163
+ parentCode: z.ZodNullable<z.ZodString>;
164
+ childCodes: z.ZodArray<z.ZodString, "many">;
165
+ definition: z.ZodNullable<z.ZodString>;
166
+ }, z.ZodTypeAny, "passthrough">[];
167
+ domain: string;
168
+ levels: Record<string, string>;
169
+ }, {
170
+ name: string;
171
+ version: string;
172
+ entries: z.objectInputType<{
173
+ code: z.ZodString;
174
+ key: z.ZodString;
175
+ title: z.ZodString;
176
+ selectable: z.ZodBoolean;
177
+ parentCode: z.ZodNullable<z.ZodString>;
178
+ childCodes: z.ZodArray<z.ZodString, "many">;
179
+ definition: z.ZodNullable<z.ZodString>;
180
+ }, z.ZodTypeAny, "passthrough">[];
181
+ domain: string;
182
+ levels: Record<string, string>;
183
+ }>;
184
+ type CvcCode = z.infer<typeof CvcCodeSchema>;
185
+ type CvcKey = z.infer<typeof CvcKeySchema>;
186
+ type CvcEntry = z.infer<typeof CvcEntrySchema>;
187
+ type ServiceCategoryEntry = z.infer<typeof ServiceCategoryEntrySchema>;
188
+ type CvcEnvelope = z.infer<typeof CvcEnvelopeSchema>;
189
+ /**
190
+ * SOT family identifier (e.g. `"service_categories"`, `"service_state"`,
191
+ * `"service_mechanisms"`, `"missingness"`). The canonical list of domains is
192
+ * enumerated by the SOT JSON files in `src/cvcs/`. Typed as `string` rather
193
+ * than a closed union so adding a new SOT file does not require touching this
194
+ * type. See locked spec §2.
195
+ */
196
+ type CvcDomain = string;
197
+ /**
198
+ * Derive an entry's level from its 7-segment code per locked spec §3.3.
199
+ *
200
+ * - Segment 7 non-zero → level 0 (missingness value entry, e.g. `unknown`).
201
+ * - Otherwise return the index (1..5) of the last non-zero hierarchy segment.
202
+ * - Hierarchy segments 2..7 all zero → level 0 (per-domain missingness root,
203
+ * e.g. `022-000-000-000-000-000-000`). Segment 1 carries the domain prefix
204
+ * and is intentionally not consulted by the level derivation.
205
+ */
206
+ declare function getCvcLevel(code: string): number;
207
+ /**
208
+ * Error collected by {@link validateCvc}. Each error names the invariant it
209
+ * violates (`C1`..`C8`, skipping the retired `C7`) so CI output points
210
+ * straight at the locked spec rule that failed. `code` or `key` narrow the
211
+ * error to a specific entry when the violation is entry-scoped.
212
+ */
213
+ interface CvcValidationError {
214
+ invariant: "C1" | "C2" | "C3" | "C4" | "C5" | "C6" | "C8";
215
+ message: string;
216
+ code?: string;
217
+ key?: string;
218
+ }
219
+ /**
220
+ * Structural invariants to enforce on every committed SOT file per locked spec
221
+ * §4. Zod's schema `parse()` guarantees the *shape* of the envelope; this
222
+ * function enforces the cross-entry *semantics* that Zod cannot express.
223
+ *
224
+ * Invariants (locked spec §4):
225
+ * - **C1** Code format + uniqueness (§4.1). Format v2 uses 3-digit segments.
226
+ * - **C2** Key format + uniqueness (§4.2).
227
+ * - **C3** Tree: every `parentCode` resolves to an existing entry or null; no
228
+ * cycles (§4.3).
229
+ * - **C4** `childCodes` are the exact bidirectional inverse of `parentCode`
230
+ * (§4.3).
231
+ * - **C5** Selectability is a boolean (§4.4).
232
+ * - **C6** Cross-CVC `relevantMechanisms` references resolve against a
233
+ * provided `service_mechanisms` key set (§4.5, §7). Only checked when the
234
+ * caller supplies `options.mechanismKeys`.
235
+ * - **C7** _Retired in format v2_ (envelope no longer carries the shared
236
+ * `missingness` field; missingness is per-domain and embedded in
237
+ * `entries`). The invariant slot is intentionally left empty to preserve
238
+ * the numbering of C1/C2/C3/C4/C5/C6/C8 in historical references.
239
+ * - **C8** No entry anywhere contains a key `'provided'` (legacy Thread UI
240
+ * label guard; not a canonical state).
241
+ *
242
+ * @param envelope Parsed envelope (typically from `CvcEnvelopeSchema.parse()`).
243
+ * @param options.mechanismKeys Optional set of valid `service_mechanisms`
244
+ * entry keys. If provided and the envelope entries have `relevantMechanisms`
245
+ * fields, each referenced key must be in this set (C6).
246
+ * @returns An array of {@link CvcValidationError}. An empty array means valid.
247
+ */
248
+ declare function validateCvc(envelope: CvcEnvelope, options?: {
249
+ mechanismKeys?: ReadonlySet<string>;
250
+ }): CvcValidationError[];
251
+
252
+ export { type CvcCode, CvcCodeSchema, type CvcDomain, type CvcEntry, CvcEntrySchema, type CvcEnvelope, CvcEnvelopeSchema, type CvcKey, CvcKeySchema, type CvcValidationError, type ServiceCategoryEntry, ServiceCategoryEntrySchema, getCvcLevel, validateCvc };
@@ -0,0 +1,252 @@
1
+ import { z } from 'zod';
2
+
3
+ /**
4
+ * @htilabs/platform-common-models — Controlled Vocabulary (CVC) Validation
5
+ *
6
+ * Zod schemas for validating CVC Source-of-Truth (SOT) JSON files and
7
+ * individual CVC entries. Implements the locked spec §9.2 shapes.
8
+ *
9
+ * Used by:
10
+ * - CI structural tests that parse every committed SOT file.
11
+ * - The generalized seed CLI (`seedCvc`) prior to persistence.
12
+ * - Downstream consumers that need to validate CVC payloads.
13
+ *
14
+ * Canonical spec:
15
+ * /gt/docs/data/cvcs/CVC Implementation Spec 2780449faf8045258c67daab0f1c5569.md
16
+ *
17
+ * Format v2 (2026-04-15):
18
+ * - Positional 7-segment codes `XXX-XXX-XXX-XXX-XXX-XXX-XXX` (3 digits per
19
+ * segment). Segment 1 is the Notion-aligned domain prefix:
20
+ * `022` service_categories (CVC-22)
21
+ * `025` service_mechanisms (CVC-25)
22
+ * `049` service_state (CVC-49)
23
+ * - Missingness entries are embedded per-domain (synthetic `missingness_root`
24
+ * at `<prefix>-000-000-000-000-000-000` plus three values at segment 7 =
25
+ * `001`/`002`/`003`). The shared `missingness.v1.0.0.json` file was
26
+ * retired in favor of per-domain missingness.
27
+ * - Envelope `missingness` field and the C7 invariant have been removed; the
28
+ * shared-merge pathway no longer exists.
29
+ */
30
+
31
+ /**
32
+ * 7-segment positional CVC code: `XXX-XXX-XXX-XXX-XXX-XXX-XXX` (three digits
33
+ * per segment). Segment 1 is the Notion-aligned domain prefix. Remaining
34
+ * hierarchy segments are filled left-to-right as levels deepen; unused
35
+ * segments remain `000`. See locked spec §3 (format v2).
36
+ */
37
+ declare const CvcCodeSchema: z.ZodString;
38
+ /**
39
+ * Stable machine key for a CVC entry. Must start with a lowercase letter and
40
+ * contain only lowercase alphanumerics or underscores. Used as a cross-CVC
41
+ * reference target (e.g. `relevantMechanisms` pointing at mechanism keys).
42
+ * See locked spec §3.2.
43
+ */
44
+ declare const CvcKeySchema: z.ZodString;
45
+ /**
46
+ * Base entry shape shared by every CVC domain. Domain-specific extensions
47
+ * (e.g. `ServiceCategoryEntrySchema`) should use `.extend()` to add fields.
48
+ * See locked spec §9.2.
49
+ *
50
+ * Uses `.passthrough()` so that domain-specific fields (like
51
+ * `relevantMechanisms` on service-category entries) survive base parsing
52
+ * unmodified. This keeps cross-CVC reference validation honest: the §4.5
53
+ * structural validator needs to see the raw referenced keys, and a strip-by-
54
+ * default schema would silently hide them.
55
+ */
56
+ declare const CvcEntrySchema: z.ZodObject<{
57
+ code: z.ZodString;
58
+ key: z.ZodString;
59
+ title: z.ZodString;
60
+ selectable: z.ZodBoolean;
61
+ parentCode: z.ZodNullable<z.ZodString>;
62
+ childCodes: z.ZodArray<z.ZodString, "many">;
63
+ definition: z.ZodNullable<z.ZodString>;
64
+ }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
65
+ code: z.ZodString;
66
+ key: z.ZodString;
67
+ title: z.ZodString;
68
+ selectable: z.ZodBoolean;
69
+ parentCode: z.ZodNullable<z.ZodString>;
70
+ childCodes: z.ZodArray<z.ZodString, "many">;
71
+ definition: z.ZodNullable<z.ZodString>;
72
+ }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
73
+ code: z.ZodString;
74
+ key: z.ZodString;
75
+ title: z.ZodString;
76
+ selectable: z.ZodBoolean;
77
+ parentCode: z.ZodNullable<z.ZodString>;
78
+ childCodes: z.ZodArray<z.ZodString, "many">;
79
+ definition: z.ZodNullable<z.ZodString>;
80
+ }, z.ZodTypeAny, "passthrough">>;
81
+ /**
82
+ * Service-category-specific entry. Adds `relevantMechanisms` — a cross-CVC
83
+ * reference into the `service_mechanisms` domain via entry keys. `null` means
84
+ * "not applicable" (e.g. structural L1 topic rows). See locked spec §9.2.
85
+ */
86
+ declare const ServiceCategoryEntrySchema: z.ZodObject<{
87
+ code: z.ZodString;
88
+ key: z.ZodString;
89
+ title: z.ZodString;
90
+ selectable: z.ZodBoolean;
91
+ parentCode: z.ZodNullable<z.ZodString>;
92
+ childCodes: z.ZodArray<z.ZodString, "many">;
93
+ definition: z.ZodNullable<z.ZodString>;
94
+ } & {
95
+ relevantMechanisms: z.ZodNullable<z.ZodArray<z.ZodString, "many">>;
96
+ }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
97
+ code: z.ZodString;
98
+ key: z.ZodString;
99
+ title: z.ZodString;
100
+ selectable: z.ZodBoolean;
101
+ parentCode: z.ZodNullable<z.ZodString>;
102
+ childCodes: z.ZodArray<z.ZodString, "many">;
103
+ definition: z.ZodNullable<z.ZodString>;
104
+ } & {
105
+ relevantMechanisms: z.ZodNullable<z.ZodArray<z.ZodString, "many">>;
106
+ }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
107
+ code: z.ZodString;
108
+ key: z.ZodString;
109
+ title: z.ZodString;
110
+ selectable: z.ZodBoolean;
111
+ parentCode: z.ZodNullable<z.ZodString>;
112
+ childCodes: z.ZodArray<z.ZodString, "many">;
113
+ definition: z.ZodNullable<z.ZodString>;
114
+ } & {
115
+ relevantMechanisms: z.ZodNullable<z.ZodArray<z.ZodString, "many">>;
116
+ }, z.ZodTypeAny, "passthrough">>;
117
+ /**
118
+ * Top-level SOT JSON envelope. One envelope per (domain, version) pair.
119
+ *
120
+ * `levels` is a positional map from level number (`"0"`, `"1"`, …) to a human
121
+ * label describing the level. Missingness entries are embedded in `entries`
122
+ * (per-domain) rather than merged in from a shared SOT file; see module
123
+ * header for the v2 format summary.
124
+ */
125
+ declare const CvcEnvelopeSchema: z.ZodObject<{
126
+ domain: z.ZodString;
127
+ name: z.ZodString;
128
+ version: z.ZodString;
129
+ levels: z.ZodRecord<z.ZodString, z.ZodString>;
130
+ entries: z.ZodArray<z.ZodObject<{
131
+ code: z.ZodString;
132
+ key: z.ZodString;
133
+ title: z.ZodString;
134
+ selectable: z.ZodBoolean;
135
+ parentCode: z.ZodNullable<z.ZodString>;
136
+ childCodes: z.ZodArray<z.ZodString, "many">;
137
+ definition: z.ZodNullable<z.ZodString>;
138
+ }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
139
+ code: z.ZodString;
140
+ key: z.ZodString;
141
+ title: z.ZodString;
142
+ selectable: z.ZodBoolean;
143
+ parentCode: z.ZodNullable<z.ZodString>;
144
+ childCodes: z.ZodArray<z.ZodString, "many">;
145
+ definition: z.ZodNullable<z.ZodString>;
146
+ }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
147
+ code: z.ZodString;
148
+ key: z.ZodString;
149
+ title: z.ZodString;
150
+ selectable: z.ZodBoolean;
151
+ parentCode: z.ZodNullable<z.ZodString>;
152
+ childCodes: z.ZodArray<z.ZodString, "many">;
153
+ definition: z.ZodNullable<z.ZodString>;
154
+ }, z.ZodTypeAny, "passthrough">>, "many">;
155
+ }, "strip", z.ZodTypeAny, {
156
+ name: string;
157
+ version: string;
158
+ entries: z.objectOutputType<{
159
+ code: z.ZodString;
160
+ key: z.ZodString;
161
+ title: z.ZodString;
162
+ selectable: z.ZodBoolean;
163
+ parentCode: z.ZodNullable<z.ZodString>;
164
+ childCodes: z.ZodArray<z.ZodString, "many">;
165
+ definition: z.ZodNullable<z.ZodString>;
166
+ }, z.ZodTypeAny, "passthrough">[];
167
+ domain: string;
168
+ levels: Record<string, string>;
169
+ }, {
170
+ name: string;
171
+ version: string;
172
+ entries: z.objectInputType<{
173
+ code: z.ZodString;
174
+ key: z.ZodString;
175
+ title: z.ZodString;
176
+ selectable: z.ZodBoolean;
177
+ parentCode: z.ZodNullable<z.ZodString>;
178
+ childCodes: z.ZodArray<z.ZodString, "many">;
179
+ definition: z.ZodNullable<z.ZodString>;
180
+ }, z.ZodTypeAny, "passthrough">[];
181
+ domain: string;
182
+ levels: Record<string, string>;
183
+ }>;
184
+ type CvcCode = z.infer<typeof CvcCodeSchema>;
185
+ type CvcKey = z.infer<typeof CvcKeySchema>;
186
+ type CvcEntry = z.infer<typeof CvcEntrySchema>;
187
+ type ServiceCategoryEntry = z.infer<typeof ServiceCategoryEntrySchema>;
188
+ type CvcEnvelope = z.infer<typeof CvcEnvelopeSchema>;
189
+ /**
190
+ * SOT family identifier (e.g. `"service_categories"`, `"service_state"`,
191
+ * `"service_mechanisms"`, `"missingness"`). The canonical list of domains is
192
+ * enumerated by the SOT JSON files in `src/cvcs/`. Typed as `string` rather
193
+ * than a closed union so adding a new SOT file does not require touching this
194
+ * type. See locked spec §2.
195
+ */
196
+ type CvcDomain = string;
197
+ /**
198
+ * Derive an entry's level from its 7-segment code per locked spec §3.3.
199
+ *
200
+ * - Segment 7 non-zero → level 0 (missingness value entry, e.g. `unknown`).
201
+ * - Otherwise return the index (1..5) of the last non-zero hierarchy segment.
202
+ * - Hierarchy segments 2..7 all zero → level 0 (per-domain missingness root,
203
+ * e.g. `022-000-000-000-000-000-000`). Segment 1 carries the domain prefix
204
+ * and is intentionally not consulted by the level derivation.
205
+ */
206
+ declare function getCvcLevel(code: string): number;
207
+ /**
208
+ * Error collected by {@link validateCvc}. Each error names the invariant it
209
+ * violates (`C1`..`C8`, skipping the retired `C7`) so CI output points
210
+ * straight at the locked spec rule that failed. `code` or `key` narrow the
211
+ * error to a specific entry when the violation is entry-scoped.
212
+ */
213
+ interface CvcValidationError {
214
+ invariant: "C1" | "C2" | "C3" | "C4" | "C5" | "C6" | "C8";
215
+ message: string;
216
+ code?: string;
217
+ key?: string;
218
+ }
219
+ /**
220
+ * Structural invariants to enforce on every committed SOT file per locked spec
221
+ * §4. Zod's schema `parse()` guarantees the *shape* of the envelope; this
222
+ * function enforces the cross-entry *semantics* that Zod cannot express.
223
+ *
224
+ * Invariants (locked spec §4):
225
+ * - **C1** Code format + uniqueness (§4.1). Format v2 uses 3-digit segments.
226
+ * - **C2** Key format + uniqueness (§4.2).
227
+ * - **C3** Tree: every `parentCode` resolves to an existing entry or null; no
228
+ * cycles (§4.3).
229
+ * - **C4** `childCodes` are the exact bidirectional inverse of `parentCode`
230
+ * (§4.3).
231
+ * - **C5** Selectability is a boolean (§4.4).
232
+ * - **C6** Cross-CVC `relevantMechanisms` references resolve against a
233
+ * provided `service_mechanisms` key set (§4.5, §7). Only checked when the
234
+ * caller supplies `options.mechanismKeys`.
235
+ * - **C7** _Retired in format v2_ (envelope no longer carries the shared
236
+ * `missingness` field; missingness is per-domain and embedded in
237
+ * `entries`). The invariant slot is intentionally left empty to preserve
238
+ * the numbering of C1/C2/C3/C4/C5/C6/C8 in historical references.
239
+ * - **C8** No entry anywhere contains a key `'provided'` (legacy Thread UI
240
+ * label guard; not a canonical state).
241
+ *
242
+ * @param envelope Parsed envelope (typically from `CvcEnvelopeSchema.parse()`).
243
+ * @param options.mechanismKeys Optional set of valid `service_mechanisms`
244
+ * entry keys. If provided and the envelope entries have `relevantMechanisms`
245
+ * fields, each referenced key must be in this set (C6).
246
+ * @returns An array of {@link CvcValidationError}. An empty array means valid.
247
+ */
248
+ declare function validateCvc(envelope: CvcEnvelope, options?: {
249
+ mechanismKeys?: ReadonlySet<string>;
250
+ }): CvcValidationError[];
251
+
252
+ export { type CvcCode, CvcCodeSchema, type CvcDomain, type CvcEntry, CvcEntrySchema, type CvcEnvelope, CvcEnvelopeSchema, type CvcKey, CvcKeySchema, type CvcValidationError, type ServiceCategoryEntry, ServiceCategoryEntrySchema, getCvcLevel, validateCvc };