@htilabs/platform-common-models 0.8.23 → 0.8.24

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.
@@ -1,298 +1,97 @@
1
- import { z } from 'zod';
1
+ export { C as CvcCode, a as CvcCodeSchema, b as CvcDomain, c as CvcEntry, d as CvcEntrySchema, e as CvcEnvelope, f as CvcEnvelopeSchema, g as CvcKey, h as CvcKeySchema, i as CvcValidationError, P as PrimaryLanguageEntry, j as PrimaryLanguageEntrySchema, S as ServiceCategoryEntry, k as ServiceCategoryEntrySchema, l as getCvcLevel, v as validateCvc } from '../cvc-C7qdsXYK.cjs';
2
+ import 'zod';
2
3
 
3
4
  /**
4
- * @htilabs/platform-common-models — Controlled Vocabulary (CVC) Validation
5
+ * @htilabs/platform-common-models — CVC `_status`/`_source` provenance parser
5
6
  *
6
- * Zod schemas for validating CVC Source-of-Truth (SOT) JSON files and
7
- * individual CVC entries. Implements the locked spec §9.2 shapes.
7
+ * Problem this solves: `_status` on a SOT envelope (`src/cvcs/*.json`) is
8
+ * unvalidated free text (115 of 179 domains carry it; the rest predate the
9
+ * convention). A consumer that wants to know "is this actually a draft?" has
10
+ * had to eyeball a string like
8
11
  *
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.
12
+ * "DRAFT — TEMPORARY: net-new value-CVC not yet in Notion; provisional
13
+ * 900+ numbering; codes from prototype/data/cvcs/core_accommodation_type
14
+ * .yaml; PENDING canonical Notion authoring (PAVE Auditability backlog)."
13
15
  *
14
- * Canonical spec:
15
- * /gt/docs/data/cvcs/CVC Implementation Spec 2780449faf8045258c67daab0f1c5569.md
16
+ * and get it right past two real traps observed across the current
17
+ * population:
18
+ * - A leading `"CANONICAL — …"` marker is a PROVENANCE note on an
19
+ * ALREADY-ratified file, not a maturity warning — it must not be lumped
20
+ * in with `"DRAFT"`/`"PROVISIONAL"`.
21
+ * - `core_functions` is self-contradictory: it leads
22
+ * `"DRAFTED — NEEDS REVIEW"` but the same string continues
23
+ * `"…Canonical numbering (133), NOT provisional."` A naive
24
+ * leading-word reader silently picks one side; this parser flags it.
16
25
  *
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_states (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.
26
+ * This module is a pure, additive, standalone export. It does NOT touch
27
+ * `CvcEnvelopeSchema` (`./cvc.ts`) — `_status`/`_source` are intentionally
28
+ * outside that Zod schema (see its module header), and adding them there
29
+ * would risk changing parse behavior for every existing consumer. Callers
30
+ * pass the RAW parsed JSON object (before or instead of
31
+ * `CvcEnvelopeSchema.parse()`), not the Zod-inferred `CvcEnvelope`.
49
32
  *
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
- * Primary-language-specific entry. Adds:
119
- * - `iso6391Code` — the ISO 639-1 alpha-2 code for the language, or `null`
120
- * for entries without an ISO 639-1 code (missingness entries, Chinese
121
- * varieties Mandarin/Cantonese, `other_language`). ASL is stored as
122
- * `"ase"` (ISO 639-3) per Notion's convention; the CVC header documents
123
- * this caveat.
124
- * - `priority` — `true` for front-end short-list entries (14 total in
125
- * CVC-122: 13 L1 languages plus the canonical `unknown` missingness
126
- * entry). See locked spec §9.2.
127
- */
128
- declare const PrimaryLanguageEntrySchema: z.ZodObject<{
129
- code: z.ZodString;
130
- key: z.ZodString;
131
- title: z.ZodString;
132
- selectable: z.ZodBoolean;
133
- parentCode: z.ZodNullable<z.ZodString>;
134
- childCodes: z.ZodArray<z.ZodString, "many">;
135
- definition: z.ZodNullable<z.ZodString>;
136
- } & {
137
- iso6391Code: z.ZodNullable<z.ZodString>;
138
- priority: z.ZodBoolean;
139
- }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
140
- code: z.ZodString;
141
- key: z.ZodString;
142
- title: z.ZodString;
143
- selectable: z.ZodBoolean;
144
- parentCode: z.ZodNullable<z.ZodString>;
145
- childCodes: z.ZodArray<z.ZodString, "many">;
146
- definition: z.ZodNullable<z.ZodString>;
147
- } & {
148
- iso6391Code: z.ZodNullable<z.ZodString>;
149
- priority: z.ZodBoolean;
150
- }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
151
- code: z.ZodString;
152
- key: z.ZodString;
153
- title: z.ZodString;
154
- selectable: z.ZodBoolean;
155
- parentCode: z.ZodNullable<z.ZodString>;
156
- childCodes: z.ZodArray<z.ZodString, "many">;
157
- definition: z.ZodNullable<z.ZodString>;
158
- } & {
159
- iso6391Code: z.ZodNullable<z.ZodString>;
160
- priority: z.ZodBoolean;
161
- }, z.ZodTypeAny, "passthrough">>;
162
- /**
163
- * Top-level SOT JSON envelope. One envelope per (domain, version) pair.
164
- *
165
- * `levels` is a positional map from level number (`"0"`, `"1"`, …) to a human
166
- * label describing the level. Missingness entries are embedded in `entries`
167
- * (per-domain) rather than merged in from a shared SOT file; see module
168
- * header for the v2 format summary.
169
- */
170
- declare const CvcEnvelopeSchema: z.ZodObject<{
171
- domain: z.ZodString;
172
- name: z.ZodString;
173
- version: z.ZodString;
174
- levels: z.ZodRecord<z.ZodString, z.ZodString>;
175
- entries: z.ZodArray<z.ZodObject<{
176
- code: z.ZodString;
177
- key: z.ZodString;
178
- title: z.ZodString;
179
- selectable: z.ZodBoolean;
180
- parentCode: z.ZodNullable<z.ZodString>;
181
- childCodes: z.ZodArray<z.ZodString, "many">;
182
- definition: z.ZodNullable<z.ZodString>;
183
- }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
184
- code: z.ZodString;
185
- key: z.ZodString;
186
- title: z.ZodString;
187
- selectable: z.ZodBoolean;
188
- parentCode: z.ZodNullable<z.ZodString>;
189
- childCodes: z.ZodArray<z.ZodString, "many">;
190
- definition: z.ZodNullable<z.ZodString>;
191
- }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
192
- code: z.ZodString;
193
- key: z.ZodString;
194
- title: z.ZodString;
195
- selectable: z.ZodBoolean;
196
- parentCode: z.ZodNullable<z.ZodString>;
197
- childCodes: z.ZodArray<z.ZodString, "many">;
198
- definition: z.ZodNullable<z.ZodString>;
199
- }, z.ZodTypeAny, "passthrough">>, "many">;
200
- }, "strip", z.ZodTypeAny, {
201
- name: string;
202
- version: string;
203
- entries: z.objectOutputType<{
204
- code: z.ZodString;
205
- key: z.ZodString;
206
- title: z.ZodString;
207
- selectable: z.ZodBoolean;
208
- parentCode: z.ZodNullable<z.ZodString>;
209
- childCodes: z.ZodArray<z.ZodString, "many">;
210
- definition: z.ZodNullable<z.ZodString>;
211
- }, z.ZodTypeAny, "passthrough">[];
212
- domain: string;
213
- levels: Record<string, string>;
214
- }, {
215
- name: string;
216
- version: string;
217
- entries: z.objectInputType<{
218
- code: z.ZodString;
219
- key: z.ZodString;
220
- title: z.ZodString;
221
- selectable: z.ZodBoolean;
222
- parentCode: z.ZodNullable<z.ZodString>;
223
- childCodes: z.ZodArray<z.ZodString, "many">;
224
- definition: z.ZodNullable<z.ZodString>;
225
- }, z.ZodTypeAny, "passthrough">[];
226
- domain: string;
227
- levels: Record<string, string>;
228
- }>;
229
- type CvcCode = z.infer<typeof CvcCodeSchema>;
230
- type CvcKey = z.infer<typeof CvcKeySchema>;
231
- type CvcEntry = z.infer<typeof CvcEntrySchema>;
232
- type ServiceCategoryEntry = z.infer<typeof ServiceCategoryEntrySchema>;
233
- type PrimaryLanguageEntry = z.infer<typeof PrimaryLanguageEntrySchema>;
234
- type CvcEnvelope = z.infer<typeof CvcEnvelopeSchema>;
235
- /**
236
- * SOT family identifier (e.g. `"service_categories"`, `"service_states"`,
237
- * `"service_mechanisms"`, `"missingness"`). The canonical list of domains is
238
- * enumerated by the SOT JSON files in `src/cvcs/`. Typed as `string` rather
239
- * than a closed union so adding a new SOT file does not require touching this
240
- * type. See locked spec §2.
241
- */
242
- type CvcDomain = string;
243
- /**
244
- * Derive an entry's level from its 7-segment code per locked spec §3.3.
33
+ * Classification rule (leading token of `_status`, case-insensitive):
34
+ * - contains "draft" → `maturity: "draft"`
35
+ * - contains "provisional" → `maturity: "provisional"`
36
+ * - contains "canonical" → `maturity: "canonical"` (a provenance note on
37
+ * an already-ratified file, NOT a maturity flag — kept distinct from
38
+ * `"final"` below so a caller can tell "explicitly marked ratified"
39
+ * apart from "predates the convention entirely")
40
+ * - `_status` absent entirely → `maturity: "final"` (legacy/unmarked)
245
41
  *
246
- * - Segment 7 non-zero → level 0 (missingness value entry, e.g. `unknown`).
247
- * - Otherwise return the index (1..5) of the last non-zero hierarchy segment.
248
- * - Hierarchy segments 2..7 all zero → level 0 (per-domain missingness root,
249
- * e.g. `022-000-000-000-000-000-000`). Segment 1 carries the domain prefix
250
- * and is intentionally not consulted by the level derivation.
42
+ * One real domain (`share_purpose` — "Synced verbatim from canonical
43
+ * CVC-84…") has a present `_status` whose LEADING token ("Synced") is none
44
+ * of the three convention words. Rather than mis-file it as `"final"` (which
45
+ * per the rule above is reserved for an ABSENT field) this parser falls back
46
+ * to scanning the full string for a single unambiguous keyword family before
47
+ * giving up — see `detectMaturity` below.
251
48
  */
252
- declare function getCvcLevel(code: string): number;
253
49
  /**
254
- * Error collected by {@link validateCvc}. Each error names the invariant it
255
- * violates (`C1`..`C8`, skipping the retired `C7`) so CI output points
256
- * straight at the locked spec rule that failed. `code` or `key` narrow the
257
- * error to a specific entry when the violation is entry-scoped.
50
+ * The subset of a raw (pre-validation) SOT envelope this parser reads.
51
+ * Deliberately NOT the Zod-inferred `CvcEnvelope` from `./cvc.ts` — that type
52
+ * is the *parsed* shape, which does not declare `_status`/`_source` at all
53
+ * (they live outside the locked envelope schema on purpose). Pass the raw
54
+ * `JSON.parse()` result of a `src/cvcs/*.json` file here.
258
55
  */
259
- interface CvcValidationError {
260
- invariant: "C1" | "C2" | "C3" | "C4" | "C5" | "C6" | "C8";
261
- message: string;
262
- code?: string;
263
- key?: string;
56
+ interface RawCvcEnvelopeProvenance {
57
+ _status?: unknown;
58
+ _source?: unknown;
59
+ }
60
+ /** The four observed maturity states. See module header for the rule. */
61
+ type CvcMaturity = "draft" | "provisional" | "canonical" | "final";
62
+ interface CvcStatusInfo {
63
+ /** One of the four states; see module header for the classification rule. */
64
+ maturity: CvcMaturity;
65
+ /**
66
+ * The text this parser classified. For a string `_status` this is that
67
+ * string verbatim. For the 11 domains authored with a structured
68
+ * `_status` object (`{ vocabStatus, authoredBy, evidence, … }` — e.g.
69
+ * `citizenship`, `core_functions`'s sibling `countries`), this is
70
+ * `_status.vocabStatus` — the field those envelopes use for exactly this
71
+ * purpose — not the whole object. `null` iff `_status` is absent.
72
+ */
73
+ rawStatus: string | null;
74
+ /** True iff `_source` cites a `prototype/data/cvcs/*.yaml` path. */
75
+ sourceIsPrototype: boolean;
76
+ /** The cited `prototype/data/cvcs/*.yaml` path, or `null` if none. */
77
+ sourcePath: string | null;
78
+ /**
79
+ * True when the classification is a judgment call rather than a clean
80
+ * read: either the leading token disagrees with a later
81
+ * "NOT draft"/"NOT provisional"/"NOT canonical" qualifier in the same
82
+ * string (the `core_functions` shape — generic, not special-cased, so any
83
+ * future domain authored in the same self-contradictory shape is also
84
+ * caught), or the string carries more than one maturity keyword family
85
+ * with no leading token to arbitrate between them.
86
+ */
87
+ ambiguous: boolean;
264
88
  }
265
89
  /**
266
- * Structural invariants to enforce on every committed SOT file per locked spec
267
- * §4. Zod's schema `parse()` guarantees the *shape* of the envelope; this
268
- * function enforces the cross-entry *semantics* that Zod cannot express.
269
- *
270
- * Invariants (locked spec §4):
271
- * - **C1** Code format + uniqueness (§4.1). Format v2 uses 3-digit segments.
272
- * - **C2** Key format + uniqueness (§4.2).
273
- * - **C3** Tree: every `parentCode` resolves to an existing entry or null; no
274
- * cycles (§4.3).
275
- * - **C4** `childCodes` are the exact bidirectional inverse of `parentCode`
276
- * (§4.3).
277
- * - **C5** Selectability is a boolean (§4.4).
278
- * - **C6** Cross-CVC `relevantMechanisms` references resolve against a
279
- * provided `service_mechanisms` key set (§4.5, §7). Only checked when the
280
- * caller supplies `options.mechanismKeys`.
281
- * - **C7** _Retired in format v2_ (envelope no longer carries the shared
282
- * `missingness` field; missingness is per-domain and embedded in
283
- * `entries`). The invariant slot is intentionally left empty to preserve
284
- * the numbering of C1/C2/C3/C4/C5/C6/C8 in historical references.
285
- * - **C8** No entry anywhere contains a key `'provided'` (legacy Thread UI
286
- * label guard; not a canonical state).
287
- *
288
- * @param envelope Parsed envelope (typically from `CvcEnvelopeSchema.parse()`).
289
- * @param options.mechanismKeys Optional set of valid `service_mechanisms`
290
- * entry keys. If provided and the envelope entries have `relevantMechanisms`
291
- * fields, each referenced key must be in this set (C6).
292
- * @returns An array of {@link CvcValidationError}. An empty array means valid.
90
+ * Parse a SOT envelope's `_status`/`_source` provenance fields into a
91
+ * structured, typed result. Pure function — no filesystem access, no
92
+ * dependency on `CvcEnvelopeSchema`. See module header for the full rule and
93
+ * the two known traps it exists to catch.
293
94
  */
294
- declare function validateCvc(envelope: CvcEnvelope, options?: {
295
- mechanismKeys?: ReadonlySet<string>;
296
- }): CvcValidationError[];
95
+ declare function parseCvcStatus(envelope: RawCvcEnvelopeProvenance): CvcStatusInfo;
297
96
 
298
- export { type CvcCode, CvcCodeSchema, type CvcDomain, type CvcEntry, CvcEntrySchema, type CvcEnvelope, CvcEnvelopeSchema, type CvcKey, CvcKeySchema, type CvcValidationError, type PrimaryLanguageEntry, PrimaryLanguageEntrySchema, type ServiceCategoryEntry, ServiceCategoryEntrySchema, getCvcLevel, validateCvc };
97
+ export { type CvcMaturity, type CvcStatusInfo, type RawCvcEnvelopeProvenance, parseCvcStatus };