@htilabs/platform-common-models 0.12.0 → 0.12.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.
- package/dist/config/index.cjs +0 -81
- package/dist/config/index.cjs.map +1 -1
- package/dist/config/index.d.cts +4 -79
- package/dist/config/index.d.ts +4 -79
- package/dist/config/index.js +1 -79
- package/dist/config/index.js.map +1 -1
- package/dist/constants/index.cjs +18 -2
- package/dist/constants/index.cjs.map +1 -1
- package/dist/constants/index.d.cts +1 -1
- package/dist/constants/index.d.ts +1 -1
- package/dist/constants/index.js +18 -2
- package/dist/constants/index.js.map +1 -1
- package/dist/cvc-Cp4uWnAa.d.cts +298 -0
- package/dist/cvc-Cp4uWnAa.d.ts +298 -0
- package/dist/cvcs/index.cjs +6678 -221
- package/dist/cvcs/index.cjs.map +1 -1
- package/dist/cvcs/index.d.cts +15019 -8052
- package/dist/cvcs/index.d.ts +15019 -8052
- package/dist/cvcs/index.js +6666 -221
- package/dist/cvcs/index.js.map +1 -1
- package/dist/enums/index.cjs +4557 -0
- package/dist/enums/index.cjs.map +1 -0
- package/dist/enums/index.d.cts +5257 -0
- package/dist/enums/index.d.ts +5257 -0
- package/dist/enums/index.js +4354 -0
- package/dist/enums/index.js.map +1 -0
- package/dist/{index-I-DiX9eQ.d.ts → index-CDoqrfc1.d.ts} +1 -1
- package/dist/{index-CoVr1jIV.d.cts → index-Zu_mOJRn.d.cts} +1 -1
- package/dist/index.cjs +7219 -232
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +7 -4700
- package/dist/index.d.ts +7 -4700
- package/dist/index.js +7195 -232
- package/dist/index.js.map +1 -1
- package/dist/models/index.d.cts +2 -2
- package/dist/models/index.d.ts +2 -2
- package/dist/mongo/index.cjs +0 -1
- package/dist/mongo/index.cjs.map +1 -1
- package/dist/mongo/index.js +1 -2
- package/dist/mongo/index.js.map +1 -1
- package/dist/{platform-auth-v53r3BhN.d.cts → platform-auth-Dv5fu0Fh.d.cts} +5 -4
- package/dist/{platform-auth-v53r3BhN.d.ts → platform-auth-Dv5fu0Fh.d.ts} +5 -4
- package/dist/schemas/index.cjs +5 -1
- package/dist/schemas/index.cjs.map +1 -1
- package/dist/schemas/index.d.cts +25 -25
- package/dist/schemas/index.d.ts +25 -25
- package/dist/schemas/index.js +5 -1
- package/dist/schemas/index.js.map +1 -1
- package/dist/types/index.d.cts +2 -2
- package/dist/types/index.d.ts +2 -2
- package/dist/validation/index.cjs +58 -0
- package/dist/validation/index.cjs.map +1 -1
- package/dist/validation/index.d.cts +82 -283
- package/dist/validation/index.d.ts +82 -283
- package/dist/validation/index.js +57 -0
- package/dist/validation/index.js.map +1 -1
- package/package.json +10 -1
- package/src/__sot__/README.md +36 -1
- package/src/__sot__/coreIndicatorFields.ts +331 -0
- package/src/__sot__/coreIndicators.pin.json +1936 -2
- package/src/__sot__/cvcIndex.pin.json +8 -4
- package/src/__tests__/__snapshots__/cvc-sot.snap +41 -13
- package/src/__tests__/core-information-scope-invariant.test.ts +134 -0
- package/src/__tests__/cvc-136-scoring-invariant.test.ts +8 -3
- package/src/__tests__/cvc-181-182-country-parity.test.ts +163 -0
- package/src/__tests__/cvc-drift-gate.test.ts +445 -12
- package/src/__tests__/cvc-sot-snapshot.test.ts +73 -11
- package/src/__tests__/cvc-status-parser.test.ts +150 -0
- package/src/__tests__/cvc-structural.test.ts +14 -0
- package/src/__tests__/runtime-contract-validator.test.ts +1 -325
- package/src/config/index.ts +4 -189
- package/src/constants/ic.ts +120 -3
- package/src/cvcs/assertionDomain.v1.1.0.json +19 -1
- package/src/cvcs/assertionStatus.v1.0.0.json +80 -0
- package/src/cvcs/carCorrectionReason.v1.0.0.json +89 -0
- package/src/cvcs/caseShareState.v1.0.0.json +62 -0
- package/src/cvcs/coreIndicators.v1.0.0.json +83 -5
- package/src/cvcs/coreInformationScope.v1.0.0.json +1165 -0
- package/src/cvcs/countries.v1.0.0.json +3077 -0
- package/src/cvcs/createdBySystem.v1.0.0.json +89 -0
- package/src/cvcs/criminalOrgCategory.v1.0.0.json +116 -0
- package/src/cvcs/determinationHelperCategories.v1.0.0.json +1166 -0
- package/src/cvcs/incidentParticipationRoles.v1.0.0.json +11 -1
- package/src/cvcs/index.ts +32 -0
- package/src/cvcs/minorAdultStatus.v1.0.0.json +80 -0
- package/src/cvcs/personRelationships.v1.0.0.json +67 -2
- package/src/cvcs/referralOrigin.v1.0.0.json +26 -0
- package/src/cvcs/relationshipConcern.v1.0.0.json +28 -19
- package/src/cvcs/riskIdentificationMilestone.v1.0.0.json +109 -0
- package/src/cvcs/sessionTemplate.v1.0.0.json +22 -0
- package/src/cvcs/sharePurpose.v1.0.0.json +80 -12
- package/src/cvcs/subjectType.v1.0.0.json +80 -0
- package/src/generated/cvc-enums.ts +606 -20
- package/src/validation/cvcStatus.ts +209 -0
- package/src/validation/index.ts +1 -0
- package/dist/{cvcEntry-BCj1OWqL.d.cts → cvcEntry-0BIB9sen.d.cts} +8 -8
- package/dist/{cvcEntry-BCj1OWqL.d.ts → cvcEntry-0BIB9sen.d.ts} +8 -8
package/src/__sot__/README.md
CHANGED
|
@@ -10,7 +10,7 @@ live in other repos:
|
|
|
10
10
|
| Pin | Upstream | What it is |
|
|
11
11
|
|---|---|---|
|
|
12
12
|
| `cvcIndex.pin.json` | `htilabstech/prototype` · `Final CVCs/CVC_INDEX.md` | The CVC **number space** — which number belongs to which vocabulary. **Authoritative.** A yaml's self-declared number is not. |
|
|
13
|
-
| `coreIndicators.pin.json` | `htilabstech/prototype` · `data/core_indicators.yaml` | The indicator **catalog** — which indicator codes legitimately exist. |
|
|
13
|
+
| `coreIndicators.pin.json` | `htilabstech/prototype` · `data/core_indicators.yaml` | The indicator **catalog** — which indicator codes legitimately exist, **and what the catalog says about each one** (label · definition · family · polarity · severity · is_alert · alert_when, verbatim). |
|
|
14
14
|
| `scoringEmits.pin.json` | `htilabstech/hti-scoring` · `weights/risk.weights.json` → `emits_by_code` | What the risk pipeline actually **consumes** — what CVC-136 must be able to express. |
|
|
15
15
|
|
|
16
16
|
(Notion is the fourth SOT: **ratification**. It has no pin because it is a human
|
|
@@ -18,6 +18,41 @@ process. Items awaiting it carry `_status.vocabStatus:
|
|
|
18
18
|
"provisional-pending-notion-ratification"` in their CVC JSON, and are listed in
|
|
19
19
|
`docs/adrs/ADR-CVC-0.8.13-canonical-alignment.md`.)
|
|
20
20
|
|
|
21
|
+
### The field half of `coreIndicators.pin.json`
|
|
22
|
+
|
|
23
|
+
That pin originally carried only `codes: string[]` — the sorted **set of code
|
|
24
|
+
names**. So both halves of the contract were blind to everything else the catalog
|
|
25
|
+
says: a code could keep its name while its label, definition, family, polarity,
|
|
26
|
+
severity or alert routing was rewritten, and nothing failed. That shipped twice
|
|
27
|
+
in consecutive refreshes — 0.8.14 dropped a definition revision, and the 0.8.17
|
|
28
|
+
branch initially dropped a label rename plus a load-bearing deprecation
|
|
29
|
+
qualifier, caught in human review rather than by CI.
|
|
30
|
+
|
|
31
|
+
The pin now also carries `fields` — the seven projected values per code,
|
|
32
|
+
**verbatim**. `GATE H` in the drift gate asserts CVC-136 restates every one of
|
|
33
|
+
them. The projection and the (enumerated, individually self-tested) YAML
|
|
34
|
+
round-trip normalizations live in `coreIndicatorFields.ts` **next to this file**,
|
|
35
|
+
because both halves must share one definition of them.
|
|
36
|
+
|
|
37
|
+
> `coreIndicatorFields.ts` is hand-maintained source, not a pin. The
|
|
38
|
+
> "do not hand-edit" rule above is about the `*.pin.json` snapshots.
|
|
39
|
+
|
|
40
|
+
### Regenerating one pin without bumping another
|
|
41
|
+
|
|
42
|
+
The pins are deliberately allowed to sit at **different** upstream SHAs. For a
|
|
43
|
+
release `cvcIndex` was held at `a596eb9` while the prototype moved on, because
|
|
44
|
+
absorbing the newer `CVC_INDEX.md` meant reconciling `INDEX_ABSENT` first —
|
|
45
|
+
`juvenile_justice_involvement_status` (CVC-95) gained an index row and had to be
|
|
46
|
+
promoted out of `INDEX_ABSENT` into `CANONICAL_BINDING`, and CVC-177's binding
|
|
47
|
+
had to be re-pointed at the surviving spelling after the stale duplicate row was
|
|
48
|
+
removed. That reconcile has landed and `cvcIndex` is now at `622410b`;
|
|
49
|
+
`scoringEmits` still sits at its own SHA. Use `--only` so refreshing one pin from
|
|
50
|
+
a checkout does not drag the others along:
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
npm run sot:pins -- --only=coreIndicators
|
|
54
|
+
```
|
|
55
|
+
|
|
21
56
|
Before these pins existed, platform-common validated itself **against itself**.
|
|
22
57
|
So it drifted, silently, in every direction at once — 66 canonical indicator
|
|
23
58
|
codes missing (including the whole perpetrator lane, which made facilitator
|
|
@@ -0,0 +1,331 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* THE FIELD HALF OF THE coreIndicators PIN
|
|
3
|
+
* ========================================
|
|
4
|
+
*
|
|
5
|
+
* `coreIndicators.pin.json` used to carry ONLY `codes: string[]` — the sorted
|
|
6
|
+
* SET of `code:` values in `data/core_indicators.yaml`. That made the pin, and
|
|
7
|
+
* therefore BOTH halves of the drift contract, blind to everything else the
|
|
8
|
+
* catalog says about an indicator. A code could keep its name while its label,
|
|
9
|
+
* definition, family, polarity, severity, alert routing, or alert recency
|
|
10
|
+
* window was rewritten upstream, and neither `sot:pins:check` nor `gate:cvc`
|
|
11
|
+
* could see it.
|
|
12
|
+
*
|
|
13
|
+
* That blindness shipped twice, in consecutive refreshes:
|
|
14
|
+
*
|
|
15
|
+
* 0.8.14 — dropped a definition revision that came with the code delta.
|
|
16
|
+
* 0.8.17 — initially dropped a LABEL RENAME and a load-bearing DEPRECATION
|
|
17
|
+
* QUALIFIER in a definition. Caught in human review, not by CI.
|
|
18
|
+
*
|
|
19
|
+
* Both are the same bug: a set-of-codes pin cannot express a field revision, so
|
|
20
|
+
* a refresh that copies the code delta and forgets the field delta passes green.
|
|
21
|
+
*
|
|
22
|
+
* This module is the fix. It defines the PROJECTION — the seven fields of an
|
|
23
|
+
* indicator that platform-common actually restates in
|
|
24
|
+
* `src/cvcs/coreIndicators.v1.0.0.json` — and the NORMALIZATION that makes a
|
|
25
|
+
* YAML scalar and a JSON string comparable. `scripts/sot-pins.ts` uses it to
|
|
26
|
+
* widen the pin; `src/__tests__/cvc-drift-gate.test.ts` (GATE H) uses it to
|
|
27
|
+
* assert the shipped CVC-136 restates every pinned field faithfully.
|
|
28
|
+
*
|
|
29
|
+
* It lives in `src/` rather than `scripts/` for one reason: the root tsconfig
|
|
30
|
+
* sets `rootDir: ./src`, so a `src/` test cannot import from `scripts/`, while
|
|
31
|
+
* `scripts/tsconfig.json` deliberately includes `../src/**`. Putting it here is
|
|
32
|
+
* what lets BOTH halves share ONE definition of the projection — the same
|
|
33
|
+
* property `scripts/sot-pins.ts` already relies on for the pins themselves:
|
|
34
|
+
* a pin can never disagree with the checker that validates it.
|
|
35
|
+
*
|
|
36
|
+
* (This is a `.ts` source file in `src/__sot__/`, not a pin. The README's
|
|
37
|
+
* "do not hand-edit, regenerate with `npm run sot:pins`" rule is about the
|
|
38
|
+
* `*.pin.json` snapshots. This file is hand-maintained.)
|
|
39
|
+
*/
|
|
40
|
+
|
|
41
|
+
// ─── The projection ─────────────────────────────────────────────────────────
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* The fields CVC-136 restates from the catalog, and therefore the fields the
|
|
45
|
+
* pin must carry. Adding a field here widens the gate: regenerate the pin
|
|
46
|
+
* (`npm run sot:pins`) and GATE H starts enforcing it.
|
|
47
|
+
*/
|
|
48
|
+
export const PROJECTED_FIELDS = [
|
|
49
|
+
"label",
|
|
50
|
+
"definition",
|
|
51
|
+
"family",
|
|
52
|
+
"polarity",
|
|
53
|
+
"severity",
|
|
54
|
+
"isAlert",
|
|
55
|
+
"alertWhen",
|
|
56
|
+
] as const;
|
|
57
|
+
|
|
58
|
+
export type ProjectedField = (typeof PROJECTED_FIELDS)[number];
|
|
59
|
+
|
|
60
|
+
/** One indicator's projected fields. `null` means the source omits the field. */
|
|
61
|
+
export type ProjectedIndicatorFields = Readonly<Record<ProjectedField, string | null>>;
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* `data/core_indicators.yaml` field name -> projected name. The catalog is
|
|
65
|
+
* snake_case; the CVC envelope is camelCase.
|
|
66
|
+
*/
|
|
67
|
+
const CATALOG_TO_PROJECTED: ReadonlyArray<readonly [string, ProjectedField]> = [
|
|
68
|
+
["label", "label"],
|
|
69
|
+
["definition", "definition"],
|
|
70
|
+
["family", "family"],
|
|
71
|
+
["polarity", "polarity"],
|
|
72
|
+
["severity", "severity"],
|
|
73
|
+
["is_alert", "isAlert"],
|
|
74
|
+
["alert_when", "alertWhen"],
|
|
75
|
+
];
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* `coreIndicators.v1.0.0.json` entry field name -> projected name. Note the one
|
|
79
|
+
* genuine rename: the CVC envelope calls the catalog's `label` a `title`,
|
|
80
|
+
* because `title` is the envelope-wide field for a human-readable value name.
|
|
81
|
+
* That rename is structural and deliberate — it is NOT drift.
|
|
82
|
+
*/
|
|
83
|
+
const SOT_TO_PROJECTED: ReadonlyArray<readonly [string, ProjectedField]> = [
|
|
84
|
+
["title", "label"],
|
|
85
|
+
["definition", "definition"],
|
|
86
|
+
["family", "family"],
|
|
87
|
+
["polarity", "polarity"],
|
|
88
|
+
["severity", "severity"],
|
|
89
|
+
["isAlert", "isAlert"],
|
|
90
|
+
["alertWhen", "alertWhen"],
|
|
91
|
+
];
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Free-prose fields, which get the full text normalization below. The other
|
|
95
|
+
* four are machine-consumed enum tokens and are compared as-is apart from
|
|
96
|
+
* trimming — a stray space inside `thread_pave` is real drift, not formatting.
|
|
97
|
+
*/
|
|
98
|
+
const PROSE_FIELDS: ReadonlySet<ProjectedField> = new Set<ProjectedField>([
|
|
99
|
+
"label",
|
|
100
|
+
"definition",
|
|
101
|
+
]);
|
|
102
|
+
|
|
103
|
+
// ─── Normalization ──────────────────────────────────────────────────────────
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* WHICH SIDE OF THE COMPARISON A VALUE CAME FROM.
|
|
107
|
+
*
|
|
108
|
+
* This matters, and it is not decoration. A normalization applied to BOTH sides
|
|
109
|
+
* can only ever absorb a difference — it can never CREATE one. That is fine for
|
|
110
|
+
* an artifact the emitter inflicts on the catalog and that CVC-136 was always
|
|
111
|
+
* free to restate either way (a wrap point, a trailing newline). It is NOT fine
|
|
112
|
+
* for an artifact that CVC-136 has an obligation to FIX.
|
|
113
|
+
*
|
|
114
|
+
* E4 is the second kind. See its entry below.
|
|
115
|
+
*/
|
|
116
|
+
export type NormalizationSide = "catalog" | "sot";
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* THE NORMALIZATION EXEMPTIONS.
|
|
120
|
+
*
|
|
121
|
+
* A YAML scalar and the JSON string that restates it are not byte-identical
|
|
122
|
+
* even when they say exactly the same thing, because the catalog is written and
|
|
123
|
+
* rewritten by a YAML emitter that hard-wraps long scalars. Each exemption
|
|
124
|
+
* below is a real, enumerated round-trip artifact observed in the pinned
|
|
125
|
+
* catalog — NOT a general-purpose fuzzy match.
|
|
126
|
+
*
|
|
127
|
+
* Each carries:
|
|
128
|
+
*
|
|
129
|
+
* `codes` — the exact catalog codes that exercise it.
|
|
130
|
+
* `fields` — the exact projected fields it covers. SCOPED DELIBERATELY: a
|
|
131
|
+
* self-test that spans all seven fields can be satisfied by a
|
|
132
|
+
* DIFFERENT exemption's artifact in a different field, so a dead
|
|
133
|
+
* exemption would look alive. (Observed: every prose artifact in
|
|
134
|
+
* the pinned catalog is in `definition`; E4 and E2 share both a
|
|
135
|
+
* code AND that field.)
|
|
136
|
+
* `sides` — which side of the comparison the normalization runs on. All but
|
|
137
|
+
* E4 are symmetric.
|
|
138
|
+
* `detect` — a predicate over the RAW CATALOG value that is true iff the
|
|
139
|
+
* underlying artifact is still physically present. Field scoping
|
|
140
|
+
* alone is not enough to make a dead exemption fail when two
|
|
141
|
+
* exemptions overlap on one code+field (E2/E4 do exactly that);
|
|
142
|
+
* this is what makes each one independently falsifiable.
|
|
143
|
+
*
|
|
144
|
+
* GATE H's exemption self-tests assert all four: the artifact is still detected,
|
|
145
|
+
* a RAW comparison of the covered fields genuinely fails, and the normalized
|
|
146
|
+
* comparison passes. An exemption that stops being exercised is therefore
|
|
147
|
+
* visible, not silently load-bearing forever.
|
|
148
|
+
*
|
|
149
|
+
* What these CANNOT hide — and this is the point — is any change to what a
|
|
150
|
+
* field SAYS: a label rename, a definition revision, a deprecation qualifier, a
|
|
151
|
+
* family/polarity/severity reclassification, or an alert-routing change. Those
|
|
152
|
+
* are exactly the drift class that shipped twice, and they all survive
|
|
153
|
+
* normalization intact.
|
|
154
|
+
*/
|
|
155
|
+
export const NORMALIZATION_EXEMPTIONS = [
|
|
156
|
+
{
|
|
157
|
+
id: "E1-trailing-newline",
|
|
158
|
+
what: "Block and wrapped quoted scalars parse with a trailing newline; the JSON prose does not.",
|
|
159
|
+
sides: "both",
|
|
160
|
+
codes: [
|
|
161
|
+
"intimate_partner_violence_reported_to_law_enforcement",
|
|
162
|
+
"sex_acts_in_own_residence",
|
|
163
|
+
"payment_routed_through_third_party",
|
|
164
|
+
],
|
|
165
|
+
fields: ["definition"],
|
|
166
|
+
detect: (raw: string) => /\s$/.test(raw),
|
|
167
|
+
},
|
|
168
|
+
{
|
|
169
|
+
id: "E2-wrap-folding",
|
|
170
|
+
what:
|
|
171
|
+
"The emitter hard-wraps long scalars, so wrap points parse as newlines. " +
|
|
172
|
+
"CVC-136 sometimes preserved them and sometimes folded them to spaces. " +
|
|
173
|
+
"Every whitespace run collapses to one space on BOTH sides.",
|
|
174
|
+
sides: "both",
|
|
175
|
+
codes: [
|
|
176
|
+
"depends_on_spouse_or_family_for_immigration_status",
|
|
177
|
+
"clients_unaware_of_third_party_coordination",
|
|
178
|
+
"trauma_perpetrator_is_current_manager",
|
|
179
|
+
],
|
|
180
|
+
fields: ["definition"],
|
|
181
|
+
detect: (raw: string) => /\S[ \t]*\r?\n[ \t]*\S/.test(raw),
|
|
182
|
+
},
|
|
183
|
+
{
|
|
184
|
+
id: "E3-wrapped-hyphen",
|
|
185
|
+
what:
|
|
186
|
+
"When a wrap point falls immediately after a hyphen inside a compound word " +
|
|
187
|
+
'("emotional-\\nverbal-stalking"), the join is hyphen-direct with NO space. ' +
|
|
188
|
+
"Applied before E2, which would otherwise leave a space behind the hyphen.",
|
|
189
|
+
sides: "both",
|
|
190
|
+
codes: ["trauma_perpetrator_is_current_manager"],
|
|
191
|
+
fields: ["definition"],
|
|
192
|
+
detect: (raw: string) => /-[ \t]*\r?\n/.test(raw),
|
|
193
|
+
},
|
|
194
|
+
{
|
|
195
|
+
id: "E4-leaked-hex-escape",
|
|
196
|
+
what:
|
|
197
|
+
"One upstream scalar was authored SINGLE-QUOTED with Python-style escapes, " +
|
|
198
|
+
"so `fianc\\xE9` parses as six literal characters rather than `fiancé`. " +
|
|
199
|
+
"CVC-136 carries the real character, and MUST: the escape is an upstream " +
|
|
200
|
+
"defect that the restatement is obliged to fix, not a formatting choice it " +
|
|
201
|
+
"is free to mirror. So this decode is CATALOG-ONLY — running it on the SOT " +
|
|
202
|
+
"side too would make a shipped literal `fianc\\xE9(e)` compare EQUAL to the " +
|
|
203
|
+
"catalog and pass, which is the one thing this exemption must never do. " +
|
|
204
|
+
"(That symmetry was the real bug: a snapshot test cannot hold the line, " +
|
|
205
|
+
"because it is refreshed with UPDATE_SNAPSHOT=1.) GATE H additionally " +
|
|
206
|
+
"asserts outright that no shipped CVC-136 value contains `\\xNN`.",
|
|
207
|
+
sides: "catalog",
|
|
208
|
+
codes: ["depends_on_spouse_or_family_for_immigration_status"],
|
|
209
|
+
fields: ["definition"],
|
|
210
|
+
detect: (raw: string) => LEAKED_HEX_ESCAPE.test(raw),
|
|
211
|
+
},
|
|
212
|
+
{
|
|
213
|
+
id: "E5-empty-is-alert",
|
|
214
|
+
what:
|
|
215
|
+
"One catalog entry carries `is_alert: ''`. CVC-136 models 'no alert routing' " +
|
|
216
|
+
"as an absent field. An empty string is read as absent on BOTH sides — but " +
|
|
217
|
+
"ONLY for `isAlert`, which is the only field that is ever empty on either " +
|
|
218
|
+
"side. A blanket empty-reads-as-absent rule would silently excuse an emptied " +
|
|
219
|
+
"label or definition, which is drift, not formatting.",
|
|
220
|
+
sides: "both",
|
|
221
|
+
codes: ["intimate_partner_violence_reported_to_law_enforcement"],
|
|
222
|
+
fields: ["isAlert"],
|
|
223
|
+
detect: (raw: string) => raw === "",
|
|
224
|
+
},
|
|
225
|
+
] as const;
|
|
226
|
+
|
|
227
|
+
/** The one field E5 covers. An empty value is read as absent here and nowhere else. */
|
|
228
|
+
const EMPTY_READS_AS_ABSENT: ReadonlySet<ProjectedField> = new Set<ProjectedField>(["isAlert"]);
|
|
229
|
+
|
|
230
|
+
/** E4's artifact, as a pattern. Also used by GATE H's belt-and-brace assertion. */
|
|
231
|
+
export const LEAKED_HEX_ESCAPE = /\\x[0-9A-Fa-f]{2}/;
|
|
232
|
+
|
|
233
|
+
/**
|
|
234
|
+
* E4. Decode Python-style `\xNN` escapes that leaked into single-quoted scalars.
|
|
235
|
+
*
|
|
236
|
+
* CATALOG-SIDE ONLY — see the E4 exemption entry. Applying this to the shipped
|
|
237
|
+
* CVC-136 value would let a literal escape ship undetected.
|
|
238
|
+
*/
|
|
239
|
+
export function decodeLeakedHexEscapes(value: string): string {
|
|
240
|
+
return value.replace(/\\x([0-9A-Fa-f]{2})/g, (_match, hex: string) =>
|
|
241
|
+
String.fromCharCode(Number.parseInt(hex, 16)),
|
|
242
|
+
);
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
/**
|
|
246
|
+
* E1 + E2 + E3 (symmetric) + E4 (catalog only), in the order they must be
|
|
247
|
+
* applied.
|
|
248
|
+
*/
|
|
249
|
+
export function normalizeProse(value: string, side: NormalizationSide): string {
|
|
250
|
+
const decoded = side === "catalog" ? decodeLeakedHexEscapes(value) : value; // E4
|
|
251
|
+
return decoded
|
|
252
|
+
.replace(/-[ \t]*\r?\n[ \t]*/g, "-") // E3 — must precede E2
|
|
253
|
+
.replace(/\s+/g, " ") // E2 (and E1's trailing newline)
|
|
254
|
+
.trim(); // E1
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
/**
|
|
258
|
+
* Normalize one projected value for comparison. Prose gets the full treatment;
|
|
259
|
+
* enum tokens get trimming only. An empty `isAlert` reads as absent (E5); an
|
|
260
|
+
* empty anything-else stays empty and will therefore mismatch, which is what we
|
|
261
|
+
* want — that is content loss, not formatting.
|
|
262
|
+
*/
|
|
263
|
+
export function normalizeProjectedValue(
|
|
264
|
+
field: ProjectedField,
|
|
265
|
+
value: string | null,
|
|
266
|
+
side: NormalizationSide,
|
|
267
|
+
): string | null {
|
|
268
|
+
if (value === null) return null;
|
|
269
|
+
const normalized = PROSE_FIELDS.has(field) ? normalizeProse(value, side) : value.trim();
|
|
270
|
+
if (normalized === "" && EMPTY_READS_AS_ABSENT.has(field)) return null; // E5
|
|
271
|
+
return normalized;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
/** Normalize one value that came from `data/core_indicators.yaml`. */
|
|
275
|
+
export function normalizeCatalogValue(
|
|
276
|
+
field: ProjectedField,
|
|
277
|
+
value: string | null,
|
|
278
|
+
): string | null {
|
|
279
|
+
return normalizeProjectedValue(field, value, "catalog");
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
/** Normalize one value that came from `src/cvcs/coreIndicators.v1.0.0.json`. */
|
|
283
|
+
export function normalizeSotValue(field: ProjectedField, value: string | null): string | null {
|
|
284
|
+
return normalizeProjectedValue(field, value, "sot");
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
/** Normalize a whole projected record. */
|
|
288
|
+
export function normalizeProjectedFields(
|
|
289
|
+
fields: ProjectedIndicatorFields,
|
|
290
|
+
side: NormalizationSide,
|
|
291
|
+
): ProjectedIndicatorFields {
|
|
292
|
+
const out = {} as Record<ProjectedField, string | null>;
|
|
293
|
+
for (const field of PROJECTED_FIELDS) {
|
|
294
|
+
out[field] = normalizeProjectedValue(field, fields[field], side);
|
|
295
|
+
}
|
|
296
|
+
return out;
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
// ─── Projection ─────────────────────────────────────────────────────────────
|
|
300
|
+
|
|
301
|
+
function readRaw(source: Record<string, unknown>, key: string): string | null {
|
|
302
|
+
const value = source[key];
|
|
303
|
+
if (value === undefined || value === null) return null;
|
|
304
|
+
return typeof value === "string" ? value : String(value);
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
function project(
|
|
308
|
+
source: Record<string, unknown>,
|
|
309
|
+
mapping: ReadonlyArray<readonly [string, ProjectedField]>,
|
|
310
|
+
): ProjectedIndicatorFields {
|
|
311
|
+
const out = {} as Record<ProjectedField, string | null>;
|
|
312
|
+
for (const [sourceKey, field] of mapping) {
|
|
313
|
+
out[field] = readRaw(source, sourceKey);
|
|
314
|
+
}
|
|
315
|
+
return out;
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
/**
|
|
319
|
+
* Project one `data/core_indicators.yaml` entry. Values are VERBATIM — the pin
|
|
320
|
+
* is an honest snapshot of the upstream bytes, exactly like `cvcIndex.pin.json`
|
|
321
|
+
* storing exact index-row strings. Normalization is a comparison-time concern,
|
|
322
|
+
* which is what lets GATE H prove each exemption is really needed.
|
|
323
|
+
*/
|
|
324
|
+
export function projectCatalogEntry(entry: Record<string, unknown>): ProjectedIndicatorFields {
|
|
325
|
+
return project(entry, CATALOG_TO_PROJECTED);
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
/** Project one `src/cvcs/coreIndicators.v1.0.0.json` entry. */
|
|
329
|
+
export function projectSotEntry(entry: Record<string, unknown>): ProjectedIndicatorFields {
|
|
330
|
+
return project(entry, SOT_TO_PROJECTED);
|
|
331
|
+
}
|