@htilabs/platform-common-models 0.19.0 → 0.20.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/dist/cvcs/index.cjs +4769 -643
- package/dist/cvcs/index.cjs.map +1 -1
- package/dist/cvcs/index.d.cts +5036 -606
- package/dist/cvcs/index.d.ts +5036 -606
- package/dist/cvcs/index.js +4769 -643
- package/dist/cvcs/index.js.map +1 -1
- package/dist/enums/index.cjs +74 -1
- package/dist/enums/index.cjs.map +1 -1
- package/dist/enums/index.d.cts +77 -4
- package/dist/enums/index.d.ts +77 -4
- package/dist/enums/index.js +74 -1
- package/dist/enums/index.js.map +1 -1
- package/dist/index.cjs +5199 -588
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +5189 -588
- package/dist/index.js.map +1 -1
- package/dist/information-scope/index.cjs +440 -0
- package/dist/information-scope/index.cjs.map +1 -0
- package/dist/information-scope/index.d.cts +313 -0
- package/dist/information-scope/index.d.ts +313 -0
- package/dist/information-scope/index.js +404 -0
- package/dist/information-scope/index.js.map +1 -0
- package/dist/services/index.cjs +414 -2
- package/dist/services/index.cjs.map +1 -1
- package/dist/services/index.d.cts +1 -0
- package/dist/services/index.d.ts +1 -0
- package/dist/services/index.js +403 -1
- package/dist/services/index.js.map +1 -1
- package/package.json +32 -26
- package/src/__tests__/__snapshots__/cvc-sot.snap +3 -3
- package/src/__tests__/core-information-scope-invariant.test.ts +709 -456
- package/src/__tests__/cvc-sot-snapshot.test.ts +16 -17
- package/src/__tests__/cvc-structural.test.ts +2 -2
- package/src/__tests__/location-type-routing-invariant.test.ts +25 -8
- package/src/cvcs/coreInformationScope.v2.0.0.json +5396 -0
- package/src/cvcs/index.ts +2 -2
- package/src/cvcs/roiScope.v1.3.0.json +360 -0
- package/src/generated/cvc-enums.ts +77 -4
- package/src/services/__tests__/fixtures/infoscope-v4/information_scope_v4.migrations.csv +106 -0
- package/src/services/__tests__/fixtures/infoscope-v4/information_scope_v4.rows.csv +117 -0
- package/src/services/__tests__/fixtures/infoscope-v4/loadInfoscopeV4Fixtures.ts +116 -0
- package/src/services/__tests__/informationScopeResolver.test.ts +964 -0
- package/src/services/index.ts +10 -3
- package/src/services/informationScope.ts +10 -0
- package/src/services/informationScopeResolver.ts +672 -0
- package/src/services/informationScopeSot.ts +161 -0
- package/src/cvcs/coreInformationScope.v1.1.0.json +0 -1290
- package/src/cvcs/roiScope.v1.2.0.json +0 -340
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @htilabs/platform-common-models — CVC-236 SOT → information-scope resolver binding
|
|
3
|
+
*
|
|
4
|
+
* Maps the `core_information_scope` SOT envelope (`coreInformationScope.v2.0.0.json`,
|
|
5
|
+
* exported as `coreInformationScopeSot` from `/cvcs`) into the resolver's
|
|
6
|
+
* input shapes. Pure and dependency-free: the caller passes the envelope.
|
|
7
|
+
*
|
|
8
|
+
* The SOT keys a row by its package key (`offenders__risk`, `identifying__other`:
|
|
9
|
+
* canon's dotted codes with `.` spelled `__`) and by a seven-segment wire code;
|
|
10
|
+
* a stored selection holds canon's dotted code (`offenders.risk`). The
|
|
11
|
+
* adapter reads every key through the entry's `canonicalCode` (present on the
|
|
12
|
+
* dotted rows) and falls back to `__` → `.` for a key with no entry.
|
|
13
|
+
*
|
|
14
|
+
* Rows: the live v4 tree only (`status` `as_today` / `new`). The retired
|
|
15
|
+
* tombstones are left out — a stored retired code reads through the
|
|
16
|
+
* migration table, which names every tombstone — and so is the CVC
|
|
17
|
+
* missingness group (`missingness_root` and its children), which is not a
|
|
18
|
+
* scope row. A live entry missing a field the resolver needs throws: binding
|
|
19
|
+
* fails closed rather than guess.
|
|
20
|
+
*
|
|
21
|
+
* Usage:
|
|
22
|
+
* ```ts
|
|
23
|
+
* import { coreInformationScopeSot } from "@htilabs/platform-common-models/cvcs";
|
|
24
|
+
* import {
|
|
25
|
+
* createInformationScopeResolver, scopeRowsFromSot, scopeMigrationsFromSot,
|
|
26
|
+
* } from "@htilabs/platform-common-models/information-scope";
|
|
27
|
+
*
|
|
28
|
+
* const scope = createInformationScopeResolver({
|
|
29
|
+
* rows: scopeRowsFromSot(coreInformationScopeSot),
|
|
30
|
+
* migrations: scopeMigrationsFromSot(coreInformationScopeSot),
|
|
31
|
+
* });
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
|
|
35
|
+
import type {
|
|
36
|
+
ScopeKindBranch,
|
|
37
|
+
ScopeMigration,
|
|
38
|
+
ScopeMigrationRule,
|
|
39
|
+
ScopeRow,
|
|
40
|
+
ScopeRowStatus,
|
|
41
|
+
ScopeRowType,
|
|
42
|
+
ScopeSpecialDataType,
|
|
43
|
+
} from "./informationScopeResolver.js";
|
|
44
|
+
|
|
45
|
+
/** The SOT entry fields the adapter reads (structural, so the JSON import binds). */
|
|
46
|
+
export interface CoreInformationScopeSotEntry {
|
|
47
|
+
key: string;
|
|
48
|
+
canonicalCode?: string;
|
|
49
|
+
parentKey?: string | null;
|
|
50
|
+
rowType?: string;
|
|
51
|
+
kindBranch?: string | null;
|
|
52
|
+
kindRow?: string;
|
|
53
|
+
apps?: { pave: boolean; thread: boolean; leads: boolean };
|
|
54
|
+
selectable?: boolean;
|
|
55
|
+
shareableDefault?: boolean;
|
|
56
|
+
platformFloor?: boolean;
|
|
57
|
+
levelFloor?: number;
|
|
58
|
+
specialDataType?: string;
|
|
59
|
+
status?: string;
|
|
60
|
+
replacesV3?: readonly string[];
|
|
61
|
+
/** On a tombstone: its RESTRICTION reading; the table's `subtract` line is what binds. */
|
|
62
|
+
restrictionSuccessors?: readonly string[];
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export interface CoreInformationScopeSotMigrationLine {
|
|
66
|
+
from: string;
|
|
67
|
+
to: readonly string[];
|
|
68
|
+
rule: string;
|
|
69
|
+
note?: string;
|
|
70
|
+
widens?: boolean;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export interface CoreInformationScopeSot {
|
|
74
|
+
entries: readonly CoreInformationScopeSotEntry[];
|
|
75
|
+
migrations?: { table: readonly CoreInformationScopeSotMigrationLine[] };
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const ROW_TYPES: ReadonlySet<string> = new Set<ScopeRowType>([
|
|
79
|
+
"branch",
|
|
80
|
+
"category",
|
|
81
|
+
"subcategory",
|
|
82
|
+
"sub-category",
|
|
83
|
+
"person_type",
|
|
84
|
+
"category_rest",
|
|
85
|
+
"instrument row",
|
|
86
|
+
]);
|
|
87
|
+
const KIND_BRANCHES: ReadonlySet<string> = new Set([
|
|
88
|
+
"client",
|
|
89
|
+
"offenders",
|
|
90
|
+
"family",
|
|
91
|
+
"others",
|
|
92
|
+
"leads",
|
|
93
|
+
]);
|
|
94
|
+
const LIVE: ReadonlySet<string> = new Set<ScopeRowStatus>(["as_today", "new"]);
|
|
95
|
+
const MISSINGNESS_ROOT = "missingness_root";
|
|
96
|
+
|
|
97
|
+
/** Package key → canon scope code, through `canonicalCode`. */
|
|
98
|
+
function keyReader(sot: CoreInformationScopeSot): (key: string) => string {
|
|
99
|
+
const byKey = new Map(sot.entries.map((e) => [e.key, e.canonicalCode ?? e.key]));
|
|
100
|
+
return (key) => byKey.get(key) ?? key.replace(/__/g, ".");
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function fail(key: string, field: string, value: unknown): never {
|
|
104
|
+
throw new TypeError(
|
|
105
|
+
`information scope SOT: live entry "${key}" has ${field} ${JSON.stringify(value)}`,
|
|
106
|
+
);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/** The live v4 tree rows of a CVC-236 SOT, in the resolver's selection-code space. */
|
|
110
|
+
export function scopeRowsFromSot(sot: CoreInformationScopeSot): ScopeRow[] {
|
|
111
|
+
const code = keyReader(sot);
|
|
112
|
+
const missingness = new Set(
|
|
113
|
+
sot.entries
|
|
114
|
+
.filter((e) => e.key === MISSINGNESS_ROOT || e.parentKey === MISSINGNESS_ROOT)
|
|
115
|
+
.map((e) => e.key),
|
|
116
|
+
);
|
|
117
|
+
const rows: ScopeRow[] = [];
|
|
118
|
+
for (const e of sot.entries) {
|
|
119
|
+
if (missingness.has(e.key)) continue;
|
|
120
|
+
if (e.status === "retired") continue;
|
|
121
|
+
if (e.status === undefined || !LIVE.has(e.status)) fail(e.key, "status", e.status);
|
|
122
|
+
if (e.rowType === undefined || !ROW_TYPES.has(e.rowType)) fail(e.key, "rowType", e.rowType);
|
|
123
|
+
const kindBranch = e.kindBranch ?? null;
|
|
124
|
+
if (kindBranch !== null && !KIND_BRANCHES.has(kindBranch)) fail(e.key, "kindBranch", kindBranch);
|
|
125
|
+
if (e.apps === undefined) fail(e.key, "apps", e.apps);
|
|
126
|
+
for (const b of ["selectable", "shareableDefault", "platformFloor"] as const) {
|
|
127
|
+
if (typeof e[b] !== "boolean") fail(e.key, b, e[b]);
|
|
128
|
+
}
|
|
129
|
+
if (e.levelFloor !== 1 && e.levelFloor !== 3) fail(e.key, "levelFloor", e.levelFloor);
|
|
130
|
+
if (e.specialDataType === undefined) fail(e.key, "specialDataType", e.specialDataType);
|
|
131
|
+
const row: ScopeRow = {
|
|
132
|
+
scopeCode: code(e.key),
|
|
133
|
+
parentScopeCode: e.parentKey ? code(e.parentKey) : null,
|
|
134
|
+
rowType: e.rowType as ScopeRowType,
|
|
135
|
+
kindBranch: kindBranch as ScopeKindBranch,
|
|
136
|
+
apps: { pave: e.apps.pave, thread: e.apps.thread, leads: e.apps.leads },
|
|
137
|
+
selectable: e.selectable as boolean,
|
|
138
|
+
shareableDefault: e.shareableDefault as boolean,
|
|
139
|
+
platformFloor: e.platformFloor as boolean,
|
|
140
|
+
levelFloor: e.levelFloor,
|
|
141
|
+
specialDataType: e.specialDataType as ScopeSpecialDataType,
|
|
142
|
+
status: e.status as ScopeRowStatus,
|
|
143
|
+
replacesV3: [...(e.replacesV3 ?? [])],
|
|
144
|
+
};
|
|
145
|
+
if (e.kindRow !== undefined) row.kindRow = code(e.kindRow);
|
|
146
|
+
rows.push(row);
|
|
147
|
+
}
|
|
148
|
+
return rows;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/** The v3 → v4 from-to table of a CVC-236 SOT (`migrations.table`), in selection codes. */
|
|
152
|
+
export function scopeMigrationsFromSot(sot: CoreInformationScopeSot): ScopeMigration[] {
|
|
153
|
+
const code = keyReader(sot);
|
|
154
|
+
return (sot.migrations?.table ?? []).map((l) => ({
|
|
155
|
+
from: code(l.from),
|
|
156
|
+
to: l.to.map(code),
|
|
157
|
+
rule: l.rule as ScopeMigrationRule,
|
|
158
|
+
...(l.note === undefined ? {} : { note: l.note }),
|
|
159
|
+
...(l.widens === undefined ? {} : { widens: l.widens }),
|
|
160
|
+
}));
|
|
161
|
+
}
|