@htilabs/platform-common-models 0.19.0 → 0.21.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.
Files changed (59) hide show
  1. package/dist/cvcs/index.cjs +4867 -639
  2. package/dist/cvcs/index.cjs.map +1 -1
  3. package/dist/cvcs/index.d.cts +5145 -609
  4. package/dist/cvcs/index.d.ts +5145 -609
  5. package/dist/cvcs/index.js +4867 -639
  6. package/dist/cvcs/index.js.map +1 -1
  7. package/dist/enums/index.cjs +74 -1
  8. package/dist/enums/index.cjs.map +1 -1
  9. package/dist/enums/index.d.cts +77 -4
  10. package/dist/enums/index.d.ts +77 -4
  11. package/dist/enums/index.js +74 -1
  12. package/dist/enums/index.js.map +1 -1
  13. package/dist/{index-I-DiX9eQ.d.ts → index-CDoqrfc1.d.ts} +1 -1
  14. package/dist/{index-CoVr1jIV.d.cts → index-Zu_mOJRn.d.cts} +1 -1
  15. package/dist/index.cjs +5382 -588
  16. package/dist/index.cjs.map +1 -1
  17. package/dist/index.d.cts +3 -2
  18. package/dist/index.d.ts +3 -2
  19. package/dist/index.js +5371 -588
  20. package/dist/index.js.map +1 -1
  21. package/dist/information-scope/index.cjs +521 -0
  22. package/dist/information-scope/index.cjs.map +1 -0
  23. package/dist/information-scope/index.d.cts +442 -0
  24. package/dist/information-scope/index.d.ts +442 -0
  25. package/dist/information-scope/index.js +484 -0
  26. package/dist/information-scope/index.js.map +1 -0
  27. package/dist/models/index.d.cts +2 -2
  28. package/dist/models/index.d.ts +2 -2
  29. package/dist/schemas/index.d.cts +25 -25
  30. package/dist/schemas/index.d.ts +25 -25
  31. package/dist/services/index.cjs +495 -2
  32. package/dist/services/index.cjs.map +1 -1
  33. package/dist/services/index.d.cts +1 -0
  34. package/dist/services/index.d.ts +1 -0
  35. package/dist/services/index.js +483 -1
  36. package/dist/services/index.js.map +1 -1
  37. package/package.json +32 -26
  38. package/src/__tests__/__snapshots__/cvc-sot.snap +3 -3
  39. package/src/__tests__/core-information-scope-invariant.test.ts +835 -456
  40. package/src/__tests__/cvc-sot-snapshot.test.ts +17 -17
  41. package/src/__tests__/cvc-structural.test.ts +2 -2
  42. package/src/__tests__/location-type-routing-invariant.test.ts +25 -8
  43. package/src/cvcs/coreInformationScope.v2.1.0.json +5498 -0
  44. package/src/cvcs/index.ts +2 -2
  45. package/src/cvcs/roiScope.v1.4.0.json +360 -0
  46. package/src/generated/cvc-enums.ts +77 -4
  47. package/src/services/__tests__/fixtures/infoscope-v4/information_scope_v3_placements.projection.csv +12 -0
  48. package/src/services/__tests__/fixtures/infoscope-v4/information_scope_v4.migrations.csv +106 -0
  49. package/src/services/__tests__/fixtures/infoscope-v4/information_scope_v4.rows.csv +117 -0
  50. package/src/services/__tests__/fixtures/infoscope-v4/loadInfoscopeV4Fixtures.ts +187 -0
  51. package/src/services/__tests__/informationScopeResolver.test.ts +1278 -0
  52. package/src/services/index.ts +10 -3
  53. package/src/services/informationScope.ts +10 -0
  54. package/src/services/informationScopeResolver.ts +879 -0
  55. package/src/services/informationScopeSot.ts +203 -0
  56. package/src/cvcs/coreInformationScope.v1.1.0.json +0 -1290
  57. package/src/cvcs/roiScope.v1.2.0.json +0 -340
  58. package/dist/{cvcEntry-BCj1OWqL.d.cts → cvcEntry-0BIB9sen.d.cts} +8 -8
  59. package/dist/{cvcEntry-BCj1OWqL.d.ts → cvcEntry-0BIB9sen.d.ts} +8 -8
@@ -0,0 +1,521 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/services/informationScope.ts
21
+ var informationScope_exports = {};
22
+ __export(informationScope_exports, {
23
+ INFORMATION_SCOPE_POLICY_VERSION_ROW_NOTE: () => INFORMATION_SCOPE_POLICY_VERSION_ROW_NOTE,
24
+ INFORMATION_SCOPE_READABLE_VERSIONS: () => INFORMATION_SCOPE_READABLE_VERSIONS,
25
+ INFORMATION_SCOPE_SYSTEM_INFO: () => INFORMATION_SCOPE_SYSTEM_INFO,
26
+ INFORMATION_SCOPE_VERSION: () => INFORMATION_SCOPE_VERSION,
27
+ createInformationScopeResolver: () => createInformationScopeResolver,
28
+ isScopeInstrumentRow: () => isScopeInstrumentRow,
29
+ isScopeRestRow: () => isScopeRestRow,
30
+ isSelectableScopeRow: () => isSelectableScopeRow,
31
+ kindForPerson: () => kindForPerson,
32
+ scopeMigrationsFromSot: () => scopeMigrationsFromSot,
33
+ scopeRowsFromSot: () => scopeRowsFromSot
34
+ });
35
+ module.exports = __toCommonJS(informationScope_exports);
36
+
37
+ // src/services/informationScopeResolver.ts
38
+ var INFORMATION_SCOPE_VERSION = 4;
39
+ var INFORMATION_SCOPE_READABLE_VERSIONS = Object.freeze([3, 4]);
40
+ var INFORMATION_SCOPE_SYSTEM_INFO = "system_info";
41
+ var isSelectableScopeRow = (row) => row !== void 0 && row.selectable && row.status !== "retired";
42
+ var isScopeRestRow = (row) => row !== void 0 && row.rowType === "category_rest";
43
+ var isScopeInstrumentRow = (row) => row !== void 0 && row.rowType === "instrument row";
44
+ function kindForPerson(person) {
45
+ if (person.causedHarm) return "offenders";
46
+ if (person.efmAsserted) return "family";
47
+ return "others";
48
+ }
49
+ var PERSON_KINDS = /* @__PURE__ */ new Set(["offenders", "family", "others"]);
50
+ var SPECIAL_DATA_TYPES = /* @__PURE__ */ new Set([
51
+ "none",
52
+ "survivor_confidential",
53
+ "criminal_intelligence",
54
+ "evidence"
55
+ ]);
56
+ var MIGRATION_RULES = /* @__PURE__ */ new Set([
57
+ "identity",
58
+ "row",
59
+ "category",
60
+ "subtract",
61
+ "retired before v4"
62
+ ]);
63
+ var RETIRED_RULES = /* @__PURE__ */ new Set([
64
+ "row",
65
+ "subtract",
66
+ "retired before v4"
67
+ ]);
68
+ var SELECTION_PRECEDENCE = [
69
+ "category",
70
+ "identity",
71
+ "row",
72
+ "retired before v4"
73
+ ];
74
+ var RESTRICTION_PRECEDENCE = [
75
+ "subtract",
76
+ ...SELECTION_PRECEDENCE
77
+ ];
78
+ var READING_SUBJECTS = /* @__PURE__ */ new Set([
79
+ "release",
80
+ "share",
81
+ "policy"
82
+ ]);
83
+ var INFORMATION_SCOPE_POLICY_VERSION_ROW_NOTE = "Handoff \xA7 3: a policy is migrated with a new version row on the record, dated, so a Member Admin sees a change in history, not a silent rewrite. Write that row before acting on this reading; the stored list itself is never rewritten.";
84
+ var asList = (list) => Array.isArray(list) ? list : [];
85
+ function createInformationScopeResolver(input) {
86
+ const rows = Object.freeze([...input.rows]);
87
+ const byCode = /* @__PURE__ */ new Map();
88
+ const order = /* @__PURE__ */ new Map();
89
+ for (const r of rows) {
90
+ if (byCode.has(r.scopeCode)) {
91
+ throw new Error(`information scope: duplicate code "${r.scopeCode}"`);
92
+ }
93
+ byCode.set(r.scopeCode, r);
94
+ order.set(r.scopeCode, order.size);
95
+ }
96
+ const isLive = (code) => {
97
+ const r = byCode.get(code);
98
+ return r !== void 0 && r.status !== "retired";
99
+ };
100
+ const children = /* @__PURE__ */ new Map();
101
+ for (const r of rows) {
102
+ if (r.status !== "retired" && !SPECIAL_DATA_TYPES.has(r.specialDataType)) {
103
+ throw new Error(
104
+ `information scope: "${r.scopeCode}" has specialDataType ${JSON.stringify(r.specialDataType)}`
105
+ );
106
+ }
107
+ if (r.parentScopeCode === null || r.parentScopeCode === "") continue;
108
+ if (!byCode.has(r.parentScopeCode)) {
109
+ throw new Error(
110
+ `information scope: "${r.scopeCode}" names unknown parent "${r.parentScopeCode}"`
111
+ );
112
+ }
113
+ if (r.status === "retired") continue;
114
+ const list = children.get(r.parentScopeCode) ?? [];
115
+ list.push(r.scopeCode);
116
+ children.set(r.parentScopeCode, list);
117
+ }
118
+ const ancestorCache = /* @__PURE__ */ new Map();
119
+ const ancestors = (code) => {
120
+ const hit = ancestorCache.get(code);
121
+ if (hit) return hit;
122
+ const out = [];
123
+ let cur = code;
124
+ while (cur !== null && cur !== "") {
125
+ const r = byCode.get(cur);
126
+ if (!r) break;
127
+ if (out.includes(cur)) throw new Error(`information scope: cycle at "${cur}"`);
128
+ out.push(cur);
129
+ cur = r.parentScopeCode;
130
+ }
131
+ ancestorCache.set(code, out);
132
+ return out;
133
+ };
134
+ for (const r of rows) ancestors(r.scopeCode);
135
+ if (!isLive(INFORMATION_SCOPE_SYSTEM_INFO)) {
136
+ throw new Error(`information scope: the tree has no "${INFORMATION_SCOPE_SYSTEM_INFO}" row`);
137
+ }
138
+ const alwaysCovered = new Set(ancestors(INFORMATION_SCOPE_SYSTEM_INFO));
139
+ const kids = (code) => children.get(code) ?? [];
140
+ const descendantsOf = (code) => {
141
+ const out = [];
142
+ const stack = [...kids(code)];
143
+ while (stack.length > 0) {
144
+ const c = stack.pop();
145
+ out.push(c);
146
+ stack.push(...kids(c));
147
+ }
148
+ return out;
149
+ };
150
+ const restRowOf = (code) => kids(code).find((c) => isScopeRestRow(byCode.get(c)));
151
+ const kindRoot = /* @__PURE__ */ new Map();
152
+ const perKindRow = /* @__PURE__ */ new Map();
153
+ for (const r of rows) {
154
+ if (r.status === "retired" || r.kindBranch === null || !PERSON_KINDS.has(r.kindBranch)) continue;
155
+ if (r.rowType === "person_type") {
156
+ kindRoot.set(r.kindBranch, r.scopeCode);
157
+ continue;
158
+ }
159
+ if (r.kindRow === void 0 || !isLive(r.kindRow)) {
160
+ throw new Error(
161
+ `information scope: per-kind row "${r.scopeCode}" has no live kindRow (${String(r.kindRow)})`
162
+ );
163
+ }
164
+ perKindRow.set(`${r.kindBranch}\0${r.kindRow}`, r.scopeCode);
165
+ }
166
+ const migrations = /* @__PURE__ */ new Map();
167
+ for (const m of input.migrations ?? []) {
168
+ if (!MIGRATION_RULES.has(m.rule)) {
169
+ throw new Error(`information scope: unknown migration rule "${m.rule}" on "${m.from}"`);
170
+ }
171
+ for (const to of m.to) {
172
+ if (!isLive(to)) {
173
+ throw new Error(
174
+ `information scope: migration "${m.from}" (${m.rule}) reads as "${to}", not a live row`
175
+ );
176
+ }
177
+ }
178
+ if (m.releaseReading !== void 0 && m.releaseReading !== "retain" && m.releaseReading !== "successor") {
179
+ throw new Error(`information scope: "${m.from}" has releaseReading "${String(m.releaseReading)}"`);
180
+ }
181
+ if (m.policyReading !== void 0 && m.policyReading !== "successor") {
182
+ throw new Error(`information scope: "${m.from}" has policyReading "${String(m.policyReading)}"`);
183
+ }
184
+ if (m.releaseReading === "retain" && (m.to.length !== 1 || !Array.isArray(m.v3Fields) || !Array.isArray(m.v3Domains))) {
185
+ throw new Error(
186
+ `information scope: retained line "${m.from}" needs one successor and its v3Fields / v3Domains`
187
+ );
188
+ }
189
+ const perCode = migrations.get(m.from) ?? /* @__PURE__ */ new Map();
190
+ const prior = perCode.get(m.rule);
191
+ if (prior && prior.to.join(" ") !== m.to.join(" ")) {
192
+ throw new Error(`information scope: two "${m.rule}" readings for "${m.from}"`);
193
+ }
194
+ const retain = m.releaseReading === "retain" ? m : prior?.releaseReading === "retain" ? prior : null;
195
+ perCode.set(m.rule, {
196
+ from: m.from,
197
+ rule: m.rule,
198
+ to: Object.freeze([...m.to]),
199
+ widens: m.widens === true || prior?.widens === true,
200
+ ...retain === null ? {} : {
201
+ releaseReading: "retain",
202
+ v3Fields: Object.freeze([...retain.v3Fields ?? []]),
203
+ v3Domains: Object.freeze([...retain.v3Domains ?? []]),
204
+ ...retain.v3FieldsNote === void 0 ? {} : { v3FieldsNote: retain.v3FieldsNote }
205
+ }
206
+ });
207
+ migrations.set(m.from, perCode);
208
+ }
209
+ const normalize = (codes, withSystemInfo = true) => {
210
+ const seen = /* @__PURE__ */ new Set();
211
+ const known = [];
212
+ const unknown = [];
213
+ const all = withSystemInfo ? [INFORMATION_SCOPE_SYSTEM_INFO, ...codes] : [...codes];
214
+ for (const c of all) {
215
+ if (seen.has(c)) continue;
216
+ seen.add(c);
217
+ (byCode.has(c) ? known : unknown).push(c);
218
+ }
219
+ known.sort((a, b) => order.get(a) - order.get(b));
220
+ return [...known, ...unknown];
221
+ };
222
+ const requirePickable = (code, op) => {
223
+ if (!byCode.has(code)) throw new RangeError(`information scope ${op}: unknown code "${code}"`);
224
+ if (!isSelectableScopeRow(byCode.get(code))) {
225
+ throw new RangeError(`information scope ${op}: "${code}" is not selectable`);
226
+ }
227
+ };
228
+ const isCovered = (selection, code) => {
229
+ if (!isLive(code)) return false;
230
+ if (alwaysCovered.has(code)) return true;
231
+ const sel = new Set(asList(selection));
232
+ if (ancestors(code).some((a) => sel.has(a))) return true;
233
+ const rest = restRowOf(code);
234
+ return rest !== void 0 && sel.has(rest);
235
+ };
236
+ const shareVerdict = (selection, code, options = {}) => {
237
+ if (!isLive(code)) return { included: false, reason: "unknown_code" };
238
+ if (!isCovered(selection, code)) return { included: false, reason: "not_covered" };
239
+ const chain = ancestors(code).map((c) => byCode.get(c));
240
+ if (chain.some((r) => r.platformFloor)) return { included: false, reason: "platform_floor" };
241
+ const enabled = new Set(options.enabledOffByDefault ?? []);
242
+ const notEnabled = chain.filter((r) => !r.shareableDefault && !enabled.has(r.scopeCode)).map((r) => r.scopeCode);
243
+ if (notEnabled.length > 0) return { included: false, reason: "off_by_default", notEnabled };
244
+ return { included: true, reason: "included" };
245
+ };
246
+ const expandSelectAll = (code) => {
247
+ if (!byCode.has(code)) throw new RangeError(`information scope expand: unknown code "${code}"`);
248
+ return [...kids(code)];
249
+ };
250
+ const selectAll = (selection, code) => {
251
+ requirePickable(code, "selectAll");
252
+ const drop = new Set(descendantsOf(code));
253
+ return normalize([...selection.filter((c) => !drop.has(c)), code]);
254
+ };
255
+ const deselectChild = (selection, childCode) => {
256
+ requirePickable(childCode, "deselectChild");
257
+ if (alwaysCovered.has(childCode)) {
258
+ throw new RangeError(`information scope deselectChild: "${childCode}" is always included`);
259
+ }
260
+ const sel = new Set(selection);
261
+ const path = ancestors(childCode);
262
+ let top = 0;
263
+ for (let i = 1; i < path.length; i += 1) if (sel.has(path[i])) top = i;
264
+ for (let i = 1; i <= top; i += 1) {
265
+ sel.delete(path[i]);
266
+ for (const c of kids(path[i])) if (c !== path[i - 1]) sel.add(c);
267
+ }
268
+ sel.delete(childCode);
269
+ for (const d of descendantsOf(childCode)) sel.delete(d);
270
+ return normalize(sel);
271
+ };
272
+ const readOne = (from, scopeVersion, precedence, keepsGrain) => {
273
+ if (scopeVersion === INFORMATION_SCOPE_VERSION && isLive(from)) {
274
+ return { from, rule: "identity", reads: [from], widens: false, retained: false };
275
+ }
276
+ const lines = migrations.get(from);
277
+ if (lines) {
278
+ for (const rule of precedence) {
279
+ if (scopeVersion === INFORMATION_SCOPE_VERSION && (rule === "identity" || rule === "category")) {
280
+ continue;
281
+ }
282
+ const line = lines.get(rule);
283
+ if (!line) continue;
284
+ if (keepsGrain && line.releaseReading === "retain") {
285
+ return scopeVersion === 3 ? { from, rule, reads: [], widens: false, retained: true } : { from, rule, reads: [], widens: false, retained: false };
286
+ }
287
+ return { from, rule, reads: [...line.to], widens: line.widens === true, retained: false };
288
+ }
289
+ }
290
+ return { from, rule: "unknown", reads: [], widens: false, retained: false };
291
+ };
292
+ const retainedOf = (c) => {
293
+ const line = migrations.get(c.from)?.get(c.rule);
294
+ return {
295
+ code: c.from,
296
+ v3Fields: [...line.v3Fields ?? []],
297
+ v3Domains: [...line.v3Domains ?? []],
298
+ successor: line.to[0],
299
+ ...line.v3FieldsNote === void 0 ? {} : { note: line.v3FieldsNote }
300
+ };
301
+ };
302
+ const read = (list, scopeVersion, precedence, subject) => {
303
+ const isRestriction = subject === null;
304
+ const keepsGrain = subject === "release" || subject === "share";
305
+ const isPolicyLike = subject === "policy" || isRestriction;
306
+ const stored = [...asList(list)];
307
+ const supported = typeof scopeVersion === "number" && INFORMATION_SCOPE_READABLE_VERSIONS.includes(scopeVersion);
308
+ const versionRowRequired = isPolicyLike && supported && scopeVersion !== INFORMATION_SCOPE_VERSION;
309
+ const codes = [];
310
+ const seen = /* @__PURE__ */ new Set();
311
+ for (const from of stored) {
312
+ if (seen.has(from)) continue;
313
+ seen.add(from);
314
+ codes.push(
315
+ supported ? readOne(from, scopeVersion, precedence, keepsGrain) : { from, rule: "unknown", reads: [], widens: false, retained: false }
316
+ );
317
+ }
318
+ return {
319
+ storedVersion: typeof scopeVersion === "number" ? scopeVersion : null,
320
+ stored,
321
+ version: INFORMATION_SCOPE_VERSION,
322
+ unsupportedVersion: !supported,
323
+ informationScope: normalize(
324
+ codes.flatMap((c) => c.reads),
325
+ !isRestriction
326
+ ),
327
+ codes,
328
+ retired: codes.filter((c) => RETIRED_RULES.has(c.rule)).map((c) => c.from),
329
+ unknown: codes.filter((c) => c.rule === "unknown").map((c) => c.from),
330
+ widened: codes.filter((c) => c.widens).map((c) => c.from),
331
+ subject,
332
+ retained: codes.filter((c) => c.retained).map(retainedOf),
333
+ versionRowRequired,
334
+ note: versionRowRequired ? INFORMATION_SCOPE_POLICY_VERSION_ROW_NOTE : null
335
+ };
336
+ };
337
+ const readSelection = (list, scopeVersion, options) => {
338
+ const subject = options?.subject;
339
+ if (subject === void 0 || !READING_SUBJECTS.has(subject)) {
340
+ throw new TypeError(
341
+ `information scope readSelection: options.subject must be "release", "share" or "policy" (got ${JSON.stringify(subject)}) \u2014 there is no default`
342
+ );
343
+ }
344
+ return read(list, scopeVersion, SELECTION_PRECEDENCE, subject);
345
+ };
346
+ const rowForSubject = (homeRow, kind) => {
347
+ const home = byCode.get(homeRow);
348
+ if (!home) throw new RangeError(`information scope rowForSubject: unknown home "${homeRow}"`);
349
+ if (kind === "client") return homeRow;
350
+ const chain = ancestors(homeRow);
351
+ if (byCode.get(chain[chain.length - 1])?.rowType !== "branch") return homeRow;
352
+ if (home.specialDataType === "criminal_intelligence") return homeRow;
353
+ const root = kindRoot.get(kind);
354
+ if (!root) throw new RangeError(`information scope rowForSubject: the tree has no "${kind}" kind`);
355
+ if (chain.includes(root)) return homeRow;
356
+ for (const anc of chain) {
357
+ const perKind = perKindRow.get(`${kind}\0${anc}`);
358
+ if (perKind !== void 0) return perKind;
359
+ }
360
+ return root;
361
+ };
362
+ const expandBranchPickToGrain = (selection, ceiling) => {
363
+ const ceil = asList(ceiling);
364
+ const ceilSet = new Set(ceil);
365
+ const isWithin = (c) => ancestors(c).some((a) => ceilSet.has(a));
366
+ const isAbove = (c) => ceil.some((k) => k !== c && ancestors(k).includes(c));
367
+ const out = [];
368
+ const stack = [...asList(selection)];
369
+ while (stack.length > 0) {
370
+ const c = stack.pop();
371
+ if (isLive(c) && !isWithin(c) && isAbove(c)) stack.push(...kids(c));
372
+ else out.push(c);
373
+ }
374
+ return normalize(out);
375
+ };
376
+ const clampToCeiling = (selection, ceiling) => {
377
+ const ceil = new Set(asList(ceiling));
378
+ return normalize(
379
+ expandBranchPickToGrain(selection, ceiling).filter(
380
+ (c) => isLive(c) && ancestors(c).some((a) => ceil.has(a))
381
+ )
382
+ );
383
+ };
384
+ return {
385
+ version: INFORMATION_SCOPE_VERSION,
386
+ rows,
387
+ row: (code) => byCode.get(code),
388
+ childrenOf: (code) => [...kids(code)],
389
+ ancestorsOf: (code) => [...ancestors(code)],
390
+ isCovered,
391
+ isIncludedOnShare: (selection, code, options) => shareVerdict(selection, code, options).included,
392
+ shareVerdict,
393
+ // Rule 7: the lowest internal viewing level that sees the row. Level 2
394
+ // (autocomplete) sees the level-1 stub (§ 5). Sharing ignores this.
395
+ isVisibleAtLevel: (level, code) => typeof level === "number" && isLive(code) && level >= byCode.get(code).levelFloor,
396
+ expandSelectAll,
397
+ selectAll,
398
+ deselectChild,
399
+ readSelection,
400
+ readRestriction: (list, scopeVersion) => read(list, scopeVersion, RESTRICTION_PRECEDENCE, null),
401
+ rowForSubject,
402
+ expandBranchPickToGrain,
403
+ clampToCeiling
404
+ };
405
+ }
406
+
407
+ // src/services/informationScopeSot.ts
408
+ var ROW_TYPES = /* @__PURE__ */ new Set([
409
+ "branch",
410
+ "category",
411
+ "subcategory",
412
+ "sub-category",
413
+ "person_type",
414
+ "category_rest",
415
+ "instrument row"
416
+ ]);
417
+ var KIND_BRANCHES = /* @__PURE__ */ new Set([
418
+ "client",
419
+ "offenders",
420
+ "family",
421
+ "others",
422
+ "leads"
423
+ ]);
424
+ var LIVE = /* @__PURE__ */ new Set(["as_today", "new"]);
425
+ var MISSINGNESS_ROOT = "missingness_root";
426
+ function keyReader(sot) {
427
+ const byKey = new Map(sot.entries.map((e) => [e.key, e.canonicalCode ?? e.key]));
428
+ return (key) => byKey.get(key) ?? key.replace(/__/g, ".");
429
+ }
430
+ function fail(key, field, value) {
431
+ throw new TypeError(
432
+ `information scope SOT: live entry "${key}" has ${field} ${JSON.stringify(value)}`
433
+ );
434
+ }
435
+ function scopeRowsFromSot(sot) {
436
+ const code = keyReader(sot);
437
+ const missingness = new Set(
438
+ sot.entries.filter((e) => e.key === MISSINGNESS_ROOT || e.parentKey === MISSINGNESS_ROOT).map((e) => e.key)
439
+ );
440
+ const rows = [];
441
+ for (const e of sot.entries) {
442
+ if (missingness.has(e.key)) continue;
443
+ if (e.status === "retired") continue;
444
+ if (e.status === void 0 || !LIVE.has(e.status)) fail(e.key, "status", e.status);
445
+ if (e.rowType === void 0 || !ROW_TYPES.has(e.rowType)) fail(e.key, "rowType", e.rowType);
446
+ const kindBranch = e.kindBranch ?? null;
447
+ if (kindBranch !== null && !KIND_BRANCHES.has(kindBranch)) fail(e.key, "kindBranch", kindBranch);
448
+ if (e.apps === void 0) fail(e.key, "apps", e.apps);
449
+ for (const b of ["selectable", "shareableDefault", "platformFloor"]) {
450
+ if (typeof e[b] !== "boolean") fail(e.key, b, e[b]);
451
+ }
452
+ if (e.levelFloor !== 1 && e.levelFloor !== 3) fail(e.key, "levelFloor", e.levelFloor);
453
+ if (e.specialDataType === void 0) fail(e.key, "specialDataType", e.specialDataType);
454
+ const row = {
455
+ scopeCode: code(e.key),
456
+ parentScopeCode: e.parentKey ? code(e.parentKey) : null,
457
+ rowType: e.rowType,
458
+ kindBranch,
459
+ apps: { pave: e.apps.pave, thread: e.apps.thread, leads: e.apps.leads },
460
+ selectable: e.selectable,
461
+ shareableDefault: e.shareableDefault,
462
+ platformFloor: e.platformFloor,
463
+ levelFloor: e.levelFloor,
464
+ specialDataType: e.specialDataType,
465
+ status: e.status,
466
+ replacesV3: [...e.replacesV3 ?? []]
467
+ };
468
+ if (e.kindRow !== void 0) row.kindRow = code(e.kindRow);
469
+ rows.push(row);
470
+ }
471
+ return rows;
472
+ }
473
+ function scopeMigrationsFromSot(sot) {
474
+ const code = keyReader(sot);
475
+ const byKey = new Map(sot.entries.map((e) => [e.key, e]));
476
+ return (sot.migrations?.table ?? []).map((l) => {
477
+ const m = {
478
+ from: code(l.from),
479
+ to: l.to.map(code),
480
+ rule: l.rule,
481
+ ...l.note === void 0 ? {} : { note: l.note },
482
+ ...l.widens === void 0 ? {} : { widens: l.widens },
483
+ ...l.informational === void 0 ? {} : { informational: l.informational },
484
+ ...l.policyReading === void 0 ? {} : { policyReading: l.policyReading }
485
+ };
486
+ if (l.releaseReading === void 0) return m;
487
+ if (l.releaseReading !== "retain") {
488
+ return {
489
+ ...m,
490
+ releaseReading: l.releaseReading,
491
+ ...l.releaseReadingNote === void 0 ? {} : { releaseReadingNote: l.releaseReadingNote }
492
+ };
493
+ }
494
+ const e = byKey.get(l.from);
495
+ if (e?.v3Fields === void 0 || e.v3Domains === void 0) {
496
+ fail(l.from, "v3Fields / v3Domains (its line is releaseReading retain)", e?.v3Fields);
497
+ }
498
+ return {
499
+ ...m,
500
+ releaseReading: l.releaseReading,
501
+ v3Fields: [...e.v3Fields],
502
+ v3Domains: [...e.v3Domains],
503
+ ...e.v3FieldsNote === void 0 ? {} : { v3FieldsNote: e.v3FieldsNote }
504
+ };
505
+ });
506
+ }
507
+ // Annotate the CommonJS export names for ESM import in node:
508
+ 0 && (module.exports = {
509
+ INFORMATION_SCOPE_POLICY_VERSION_ROW_NOTE,
510
+ INFORMATION_SCOPE_READABLE_VERSIONS,
511
+ INFORMATION_SCOPE_SYSTEM_INFO,
512
+ INFORMATION_SCOPE_VERSION,
513
+ createInformationScopeResolver,
514
+ isScopeInstrumentRow,
515
+ isScopeRestRow,
516
+ isSelectableScopeRow,
517
+ kindForPerson,
518
+ scopeMigrationsFromSot,
519
+ scopeRowsFromSot
520
+ });
521
+ //# sourceMappingURL=index.cjs.map