@transitrix/diagrams 1.5.0 → 1.6.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/capability-map/CapabilityCardNode.d.ts +19 -0
- package/dist/capability-map/CapabilityCardNode.js +66 -0
- package/dist/capability-map/CapabilityMapView.d.ts +59 -0
- package/dist/capability-map/CapabilityMapView.js +204 -0
- package/dist/capability-map/CapabilityRootNode.d.ts +12 -0
- package/dist/capability-map/CapabilityRootNode.js +23 -0
- package/dist/capability-map/__tests__/CapabilityMapView.test.d.ts +1 -0
- package/dist/capability-map/__tests__/CapabilityMapView.test.js +217 -0
- package/dist/capability-map/__tests__/address.test.d.ts +1 -0
- package/dist/capability-map/__tests__/address.test.js +49 -0
- package/dist/capability-map/__tests__/dsm-layout.test.d.ts +1 -0
- package/dist/capability-map/__tests__/dsm-layout.test.js +46 -0
- package/dist/capability-map/__tests__/dsm-mutations.test.d.ts +1 -0
- package/dist/capability-map/__tests__/dsm-mutations.test.js +125 -0
- package/dist/capability-map/__tests__/dsm-validate.test.d.ts +1 -0
- package/dist/capability-map/__tests__/dsm-validate.test.js +56 -0
- package/dist/capability-map/address.d.ts +12 -0
- package/dist/capability-map/address.js +48 -0
- package/dist/capability-map/dsm-layout.d.ts +9 -0
- package/dist/capability-map/dsm-layout.js +125 -0
- package/dist/capability-map/dsm-mutations.d.ts +28 -0
- package/dist/capability-map/dsm-mutations.js +196 -0
- package/dist/capability-map/dsm-schema.d.ts +71 -0
- package/dist/capability-map/dsm-schema.js +14 -0
- package/dist/capability-map/dsm-theme.d.ts +20 -0
- package/dist/capability-map/dsm-theme.js +36 -0
- package/dist/capability-map/dsm-validate.d.ts +2 -0
- package/dist/capability-map/dsm-validate.js +93 -0
- package/dist/capability-map/index.d.ts +9 -0
- package/dist/capability-map/index.js +6 -0
- package/dist/compliance/__tests__/trace.test.d.ts +1 -0
- package/dist/compliance/__tests__/trace.test.js +144 -0
- package/dist/compliance/classify.js +7 -1
- package/dist/compliance/index.d.ts +2 -1
- package/dist/compliance/index.js +1 -0
- package/dist/compliance/reverse-index.js +4 -1
- package/dist/compliance/trace.d.ts +26 -0
- package/dist/compliance/trace.js +89 -0
- package/dist/compliance/types.d.ts +94 -1
- package/dist/goals/GoalNode.d.ts +18 -0
- package/dist/goals/GoalNode.js +91 -0
- package/dist/goals/GoalTreeView.d.ts +57 -0
- package/dist/goals/GoalTreeView.js +228 -0
- package/dist/goals/__tests__/GoalTreeView.test.d.ts +1 -0
- package/dist/goals/__tests__/GoalTreeView.test.js +296 -0
- package/dist/goals/index.d.ts +3 -0
- package/dist/goals/index.js +1 -0
- package/dist/goals/theme.d.ts +22 -0
- package/dist/goals/theme.js +32 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.js +1 -1
- package/package.json +4 -1
- package/src/capability-map/CapabilityCardNode.tsx +146 -0
- package/src/capability-map/CapabilityMapView.tsx +331 -0
- package/src/capability-map/CapabilityRootNode.tsx +38 -0
- package/src/capability-map/__tests__/CapabilityMapView.test.tsx +232 -0
- package/src/capability-map/__tests__/address.test.ts +59 -0
- package/src/capability-map/__tests__/dsm-layout.test.ts +52 -0
- package/src/capability-map/__tests__/dsm-mutations.test.ts +141 -0
- package/src/capability-map/__tests__/dsm-validate.test.ts +65 -0
- package/src/capability-map/address.ts +48 -0
- package/src/capability-map/dsm-layout.ts +142 -0
- package/src/capability-map/dsm-mutations.ts +208 -0
- package/src/capability-map/dsm-schema.ts +80 -0
- package/src/capability-map/dsm-theme.ts +53 -0
- package/src/capability-map/dsm-validate.ts +103 -0
- package/src/capability-map/index.ts +35 -0
- package/src/compliance/__tests__/trace.test.ts +157 -0
- package/src/compliance/classify.ts +7 -1
- package/src/compliance/index.ts +6 -0
- package/src/compliance/reverse-index.ts +3 -1
- package/src/compliance/trace.ts +118 -0
- package/src/compliance/types.ts +101 -1
- package/src/goals/GoalNode.tsx +212 -0
- package/src/goals/GoalTreeView.tsx +350 -0
- package/src/goals/__tests__/GoalTreeView.test.tsx +313 -0
- package/src/goals/index.ts +4 -0
- package/src/goals/theme.ts +54 -0
- package/src/index.ts +29 -1
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Types for the DSM-migration capability map (docs/extraction/capability-map.md).
|
|
3
|
+
*
|
|
4
|
+
* Distinct from `./types.ts` (`CapabilityNode`/`CapabilityMapFile`), which is
|
|
5
|
+
* Transitrix's own native `*.capability-map.transitrix.yaml` notation — a
|
|
6
|
+
* nested-children tree, statically rendered to SVG. This module is a
|
|
7
|
+
* separate, flat, address-triple data model matching DSM's internal
|
|
8
|
+
* capability editor, for the interactive `CapabilityMapView` component. The
|
|
9
|
+
* two coexist in this folder by design (see the address-helper/component
|
|
10
|
+
* deliverables in the extraction spec); only the validator function name
|
|
11
|
+
* collided, so it's `validateCapabilityMapData` here, not
|
|
12
|
+
* `validateCapabilityMap` (already taken by `./validate.ts`).
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
export interface MaturitySnapshot {
|
|
16
|
+
date: string;
|
|
17
|
+
level: number;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface Capability {
|
|
21
|
+
id: number;
|
|
22
|
+
name: string;
|
|
23
|
+
/** 'X.Y.Z' triple. X=0 or backlog=true means "not on the diagram". */
|
|
24
|
+
address: string;
|
|
25
|
+
backlog?: boolean;
|
|
26
|
+
description?: string;
|
|
27
|
+
maturity?: MaturitySnapshot[];
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export interface CapabilityMap {
|
|
31
|
+
organisation: string;
|
|
32
|
+
set_id: string;
|
|
33
|
+
capabilities: Capability[];
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export type {
|
|
37
|
+
ValidationError,
|
|
38
|
+
ValidationWarning,
|
|
39
|
+
ValidationResult,
|
|
40
|
+
} from '../validation-types.js';
|
|
41
|
+
|
|
42
|
+
import type { ValidationError } from '../validation-types.js';
|
|
43
|
+
|
|
44
|
+
export interface MutationResult<T> {
|
|
45
|
+
ok: boolean;
|
|
46
|
+
result?: T;
|
|
47
|
+
error?: ValidationError;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export interface LayoutOptions {
|
|
51
|
+
rankdir?: 'LR' | 'TB';
|
|
52
|
+
nodeWidth?: number;
|
|
53
|
+
nodeHeight?: number;
|
|
54
|
+
rankSep?: number;
|
|
55
|
+
nodeSep?: number;
|
|
56
|
+
hideCollapsed?: number[];
|
|
57
|
+
organisationLabel?: string;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export interface LaidOutNode {
|
|
61
|
+
id: number;
|
|
62
|
+
x: number;
|
|
63
|
+
y: number;
|
|
64
|
+
width: number;
|
|
65
|
+
height: number;
|
|
66
|
+
data: Capability | null;
|
|
67
|
+
hasHiddenChildren: boolean;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export interface LaidOutEdge {
|
|
71
|
+
source: number | 'root';
|
|
72
|
+
target: number;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export interface CapabilityMapLayout {
|
|
76
|
+
rootNode: LaidOutNode;
|
|
77
|
+
nodes: LaidOutNode[];
|
|
78
|
+
edges: LaidOutEdge[];
|
|
79
|
+
bounds: { x: number; y: number; width: number; height: number };
|
|
80
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/** Theme tokens for CapabilityMapView — same host-agnostic-prop pattern as
|
|
2
|
+
* the goals module's ThemeTokens (see ../goals/theme.ts). */
|
|
3
|
+
export interface ThemeTokens {
|
|
4
|
+
cardFill?: string;
|
|
5
|
+
cardBorderColor?: string;
|
|
6
|
+
cardBorderWidth?: number;
|
|
7
|
+
cardTextColor?: string;
|
|
8
|
+
cardMetaColor?: string;
|
|
9
|
+
edgeColor?: string;
|
|
10
|
+
edgeWidth?: number;
|
|
11
|
+
dropTargetBorderColor?: string;
|
|
12
|
+
rootFill?: string;
|
|
13
|
+
rootTextColor?: string;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/** Default 1..5 maturity-dot colour scale — overridable via the
|
|
17
|
+
* `maturityColours` prop (spec §6.2), which is separate from ThemeTokens
|
|
18
|
+
* since it's keyed by maturity level, not a fixed named token. */
|
|
19
|
+
export const DEFAULT_MATURITY_COLOURS: Record<number, string> = {
|
|
20
|
+
1: '#ef4444',
|
|
21
|
+
2: '#f97316',
|
|
22
|
+
3: '#eab308',
|
|
23
|
+
4: '#84cc16',
|
|
24
|
+
5: '#22c55e',
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export const DEFAULT_THEME: Required<ThemeTokens> = {
|
|
28
|
+
cardFill: '#eff6ff',
|
|
29
|
+
cardBorderColor: '#94a3b8',
|
|
30
|
+
cardBorderWidth: 1,
|
|
31
|
+
cardTextColor: '#0f172a',
|
|
32
|
+
cardMetaColor: '#64748b',
|
|
33
|
+
edgeColor: '#94a3b8',
|
|
34
|
+
edgeWidth: 1.5,
|
|
35
|
+
dropTargetBorderColor: '#2563eb',
|
|
36
|
+
rootFill: '#e2e8f0',
|
|
37
|
+
rootTextColor: '#0f172a',
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
export function resolveTheme(theme?: ThemeTokens): Required<ThemeTokens> {
|
|
41
|
+
return {
|
|
42
|
+
cardFill: theme?.cardFill ?? DEFAULT_THEME.cardFill,
|
|
43
|
+
cardBorderColor: theme?.cardBorderColor ?? DEFAULT_THEME.cardBorderColor,
|
|
44
|
+
cardBorderWidth: theme?.cardBorderWidth ?? DEFAULT_THEME.cardBorderWidth,
|
|
45
|
+
cardTextColor: theme?.cardTextColor ?? DEFAULT_THEME.cardTextColor,
|
|
46
|
+
cardMetaColor: theme?.cardMetaColor ?? DEFAULT_THEME.cardMetaColor,
|
|
47
|
+
edgeColor: theme?.edgeColor ?? DEFAULT_THEME.edgeColor,
|
|
48
|
+
edgeWidth: theme?.edgeWidth ?? DEFAULT_THEME.edgeWidth,
|
|
49
|
+
dropTargetBorderColor: theme?.dropTargetBorderColor ?? DEFAULT_THEME.dropTargetBorderColor,
|
|
50
|
+
rootFill: theme?.rootFill ?? DEFAULT_THEME.rootFill,
|
|
51
|
+
rootTextColor: theme?.rootTextColor ?? DEFAULT_THEME.rootTextColor,
|
|
52
|
+
};
|
|
53
|
+
}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import type { CapabilityMap, ValidationResult, ValidationError, ValidationWarning } from './dsm-schema.js';
|
|
2
|
+
|
|
3
|
+
/** Parses an address string loosely enough to tell "wrong shape"
|
|
4
|
+
* (INVALID_ADDRESS_FORMAT) apart from "right shape, too many levels"
|
|
5
|
+
* (MAX_DEPTH_EXCEEDED, e.g. '1.2.3.4') — a strict 3-segment regex would
|
|
6
|
+
* reject both identically and lose that distinction. */
|
|
7
|
+
function parseLoose(address: string): { triple: [number, number, number] } | { tooDeep: true } | null {
|
|
8
|
+
const parts = address.trim().split('.');
|
|
9
|
+
if (parts.length < 3 || !parts.every((p) => /^\d+$/.test(p))) return null;
|
|
10
|
+
if (parts.length > 3) return { tooDeep: true };
|
|
11
|
+
return { triple: [Number(parts[0]), Number(parts[1]), Number(parts[2])] };
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function validateCapabilityMapData(input: unknown): ValidationResult {
|
|
15
|
+
const errors: ValidationError[] = [];
|
|
16
|
+
const warnings: ValidationWarning[] = [];
|
|
17
|
+
|
|
18
|
+
if (!input || typeof input !== 'object') {
|
|
19
|
+
return { valid: false, errors: [{ code: 'SCHEMA_INVALID', message: 'Input must be an object' }], warnings: [] };
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const raw = input as Record<string, unknown>;
|
|
23
|
+
if (!Array.isArray(raw.capabilities)) {
|
|
24
|
+
errors.push({ code: 'SCHEMA_INVALID', message: 'capabilities must be an array', path: 'capabilities' });
|
|
25
|
+
return { valid: false, errors, warnings };
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const map = raw as unknown as CapabilityMap;
|
|
29
|
+
const idSet = new Set<number>();
|
|
30
|
+
const addressToId = new Map<string, number>();
|
|
31
|
+
const onDiagram = new Map<number, [number, number, number]>();
|
|
32
|
+
|
|
33
|
+
for (let i = 0; i < map.capabilities.length; i++) {
|
|
34
|
+
const c = map.capabilities[i] as unknown;
|
|
35
|
+
const path = `capabilities[${i}]`;
|
|
36
|
+
|
|
37
|
+
if (!c || typeof c !== 'object') {
|
|
38
|
+
errors.push({ code: 'SCHEMA_INVALID', message: 'capability entry must be an object', path });
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
41
|
+
const cap = c as { id?: unknown; name?: unknown; address?: unknown; backlog?: unknown; maturity?: unknown };
|
|
42
|
+
|
|
43
|
+
if (typeof cap.id !== 'number') {
|
|
44
|
+
errors.push({ code: 'SCHEMA_INVALID', message: 'capability id must be a number', path });
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
47
|
+
if (idSet.has(cap.id)) {
|
|
48
|
+
errors.push({ code: 'DUPLICATE_ID', message: `Duplicate capability id: ${cap.id}`, path });
|
|
49
|
+
} else {
|
|
50
|
+
idSet.add(cap.id);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (!cap.name || typeof cap.name !== 'string' || cap.name.trim() === '') {
|
|
54
|
+
errors.push({ code: 'EMPTY_NAME', message: `Capability ${cap.id} has empty name`, path });
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (typeof cap.address !== 'string') {
|
|
58
|
+
errors.push({ code: 'INVALID_ADDRESS_FORMAT', message: `Capability ${cap.id} address must be a string`, path });
|
|
59
|
+
continue;
|
|
60
|
+
}
|
|
61
|
+
const parsed = parseLoose(cap.address);
|
|
62
|
+
if (parsed === null) {
|
|
63
|
+
errors.push({ code: 'INVALID_ADDRESS_FORMAT', message: `Capability ${cap.id} address "${cap.address}" is not in 'X.Y.Z' form`, path });
|
|
64
|
+
continue;
|
|
65
|
+
}
|
|
66
|
+
if ('tooDeep' in parsed) {
|
|
67
|
+
errors.push({ code: 'MAX_DEPTH_EXCEEDED', message: `Capability ${cap.id} address "${cap.address}" has more than 3 levels`, path });
|
|
68
|
+
continue;
|
|
69
|
+
}
|
|
70
|
+
const triple = parsed.triple;
|
|
71
|
+
const isBacklog = cap.backlog === true || triple[0] === 0;
|
|
72
|
+
|
|
73
|
+
if (!isBacklog) {
|
|
74
|
+
if (addressToId.has(cap.address)) {
|
|
75
|
+
errors.push({ code: 'DUPLICATE_ADDRESS', message: `Duplicate address "${cap.address}" (capability ${cap.id})`, path });
|
|
76
|
+
} else {
|
|
77
|
+
addressToId.set(cap.address, cap.id);
|
|
78
|
+
}
|
|
79
|
+
onDiagram.set(cap.id, triple);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
if (Array.isArray(cap.maturity)) {
|
|
83
|
+
for (const snap of cap.maturity as unknown[]) {
|
|
84
|
+
const level = (snap as { level?: unknown } | null)?.level;
|
|
85
|
+
if (typeof level === 'number' && (level < 1 || level > 5)) {
|
|
86
|
+
warnings.push({ code: 'INVALID_MATURITY_LEVEL', message: `Capability ${cap.id} has maturity level ${level} outside 1..5`, path });
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
if (errors.length > 0) return { valid: false, errors, warnings };
|
|
93
|
+
|
|
94
|
+
for (const [id, [x, y, z]] of onDiagram) {
|
|
95
|
+
if (z !== 0 && !addressToId.has(`${x}.${y}.0`)) {
|
|
96
|
+
warnings.push({ code: 'MISSING_PARENT_BY_ADDRESS', message: `Capability ${id} (${x}.${y}.${z}) has no L2 parent at ${x}.${y}.0` });
|
|
97
|
+
} else if (y !== 0 && z === 0 && !addressToId.has(`${x}.0.0`)) {
|
|
98
|
+
warnings.push({ code: 'MISSING_PARENT_BY_ADDRESS', message: `Capability ${id} (${x}.${y}.0) has no L1 parent at ${x}.0.0` });
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
return { valid: errors.length === 0, errors, warnings };
|
|
103
|
+
}
|
|
@@ -17,3 +17,38 @@ export { layoutCapabilityTree, TREE_NODE_WIDTH, TREE_NODE_HEIGHT, TREE_RANK_SEP,
|
|
|
17
17
|
|
|
18
18
|
export type { RenderCapabilityTreeOptions } from './render-capability-tree.js';
|
|
19
19
|
export { renderCapabilityTreeSvg } from './render-capability-tree.js';
|
|
20
|
+
|
|
21
|
+
// ── DSM-migration capability map (docs/extraction/capability-map.md) ───────
|
|
22
|
+
// A separate, flat, address-triple data model from CapabilityNode above —
|
|
23
|
+
// see dsm-schema.ts for why the two coexist in this folder. Named
|
|
24
|
+
// `validateCapabilityMapData` rather than `validateCapabilityMap` because
|
|
25
|
+
// that name is already taken by the native-notation validator on line 8.
|
|
26
|
+
|
|
27
|
+
export type {
|
|
28
|
+
Capability,
|
|
29
|
+
CapabilityMap,
|
|
30
|
+
MaturitySnapshot,
|
|
31
|
+
MutationResult,
|
|
32
|
+
LayoutOptions,
|
|
33
|
+
LaidOutNode,
|
|
34
|
+
LaidOutEdge,
|
|
35
|
+
CapabilityMapLayout,
|
|
36
|
+
} from './dsm-schema.js';
|
|
37
|
+
|
|
38
|
+
export {
|
|
39
|
+
parseAddress,
|
|
40
|
+
formatAddress,
|
|
41
|
+
getLevel,
|
|
42
|
+
getParentAddress,
|
|
43
|
+
getFirstFreeAddress,
|
|
44
|
+
isAddressTaken,
|
|
45
|
+
} from './address.js';
|
|
46
|
+
|
|
47
|
+
export { validateCapabilityMapData } from './dsm-validate.js';
|
|
48
|
+
export { layoutCapabilityMap } from './dsm-layout.js';
|
|
49
|
+
export { reparent, addChild, deleteWithDescendants, moveBranchToBacklog, restoreFromBacklog, normaliseAddresses } from './dsm-mutations.js';
|
|
50
|
+
|
|
51
|
+
export { CapabilityMapView } from './CapabilityMapView.js';
|
|
52
|
+
export type { CapabilityMapViewProps, CapabilityMapChange } from './CapabilityMapView.js';
|
|
53
|
+
export type { ThemeTokens } from './dsm-theme.js';
|
|
54
|
+
export { DEFAULT_MATURITY_COLOURS } from './dsm-theme.js';
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest';
|
|
2
|
+
import { buildComplianceIndex } from '../reverse-index.js';
|
|
3
|
+
import { buildRequirementTrace, buildTraceElementCatalog } from '../trace.js';
|
|
4
|
+
import type { ComplianceIndexInput } from '../types.js';
|
|
5
|
+
import type { ComplianceCodexDoc } from '../classify.js';
|
|
6
|
+
|
|
7
|
+
// Requirement traceability + hierarchy view.
|
|
8
|
+
//
|
|
9
|
+
// The two halves the view exposes:
|
|
10
|
+
// 1. Trace chain — derived_from → REQUIREMENT → ASSERTION → subject +
|
|
11
|
+
// realised_via.
|
|
12
|
+
// 2. Hierarchy — parent chain + children via the `parent` field
|
|
13
|
+
// (15-requirement.md §2.4 / ELEMENT_PRIMITIVES.md §7.13).
|
|
14
|
+
|
|
15
|
+
const input: ComplianceIndexInput = {
|
|
16
|
+
requirements: [
|
|
17
|
+
// A broad legislative parent decomposed into two child requirements.
|
|
18
|
+
{ id: 'REQUIREMENT-DATA-PROTECTION-1', name: 'Personal-data protection', origin: 'legislative', derived_from: ['REGULATION-GDPR-2016-1'], element_kind: 'requirement' },
|
|
19
|
+
{ id: 'REQUIREMENT-DATA-ERASURE-1', name: 'Erase on request within 30 days', origin: 'legislative', parent: 'REQUIREMENT-DATA-PROTECTION-1', derived_from: ['REGULATION-GDPR-2016-1'], element_kind: 'requirement' },
|
|
20
|
+
{ id: 'REQUIREMENT-DATA-CONSENT-1', name: 'Obtain consent before processing', origin: 'legislative', parent: 'REQUIREMENT-DATA-PROTECTION-1', element_kind: 'requirement' },
|
|
21
|
+
// A process-product sub-requirement below the erasure duty (cross-origin).
|
|
22
|
+
{ id: 'REQUIREMENT-ERASURE-SLA-1', name: 'Erasure SOP — 30d target', origin: 'process-product', parent: 'REQUIREMENT-DATA-ERASURE-1', element_kind: 'requirement' },
|
|
23
|
+
// Constraint hierarchy (mirror pattern).
|
|
24
|
+
{ id: 'CONSTRAINT-EEA-TRANSFER-1', name: 'No transfer outside EEA without safeguards', element_kind: 'constraint' },
|
|
25
|
+
{ id: 'CONSTRAINT-EEA-ANALYTICS-1', name: 'No PII in analytics logs', parent: 'CONSTRAINT-EEA-TRANSFER-1', element_kind: 'constraint' },
|
|
26
|
+
// Internal-only requirement — no source, no parent — for the empty-case sanity check.
|
|
27
|
+
{ id: 'REQUIREMENT-INTERNAL-1', name: 'Internal-only', element_kind: 'requirement' },
|
|
28
|
+
],
|
|
29
|
+
assertions: [
|
|
30
|
+
{ id: 'ASSERTION-1', about: 'REQUIREMENT-DATA-ERASURE-1', subject: 'PRODUCT-MOBILE-1', realised_via: ['CAPABILITY-V1', 'PROCESS-PURGE-1'], status: 'compliant' },
|
|
31
|
+
{ id: 'ASSERTION-2', about: 'REQUIREMENT-DATA-ERASURE-1', subject: 'PRODUCT-WEB-1', status: 'partial' },
|
|
32
|
+
{ id: 'ASSERTION-3', about: 'REQUIREMENT-DATA-CONSENT-1', subject: 'PRODUCT-WEB-1', status: 'compliant' },
|
|
33
|
+
],
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
const codex: ComplianceCodexDoc[] = [
|
|
37
|
+
{ id: 'REGULATION-GDPR-2016-1', name: 'GDPR', type: 'REGULATION', jurisdiction: 'EU' },
|
|
38
|
+
];
|
|
39
|
+
|
|
40
|
+
const catalog = buildTraceElementCatalog(
|
|
41
|
+
[{ id: 'PRODUCT-MOBILE-1', name: 'Mobile app' }, { id: 'PRODUCT-WEB-1', name: 'Web app' }],
|
|
42
|
+
[{ id: 'CAPABILITY-V1', name: 'Erasure capability v1' }, { id: 'PROCESS-PURGE-1', name: 'Purge process' }],
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
describe('buildComplianceIndex — requirementsByParent', () => {
|
|
46
|
+
const idx = buildComplianceIndex(input);
|
|
47
|
+
it('groups children of the same parent', () => {
|
|
48
|
+
const children = idx.requirementsByParent.get('REQUIREMENT-DATA-PROTECTION-1');
|
|
49
|
+
expect(children?.map(r => r.id).sort()).toEqual(['REQUIREMENT-DATA-CONSENT-1', 'REQUIREMENT-DATA-ERASURE-1']);
|
|
50
|
+
});
|
|
51
|
+
it('groups CONSTRAINT children the same way (element_kind-agnostic)', () => {
|
|
52
|
+
const children = idx.requirementsByParent.get('CONSTRAINT-EEA-TRANSFER-1');
|
|
53
|
+
expect(children?.map(r => r.id)).toEqual(['CONSTRAINT-EEA-ANALYTICS-1']);
|
|
54
|
+
});
|
|
55
|
+
it('returns undefined for a leaf with no children', () => {
|
|
56
|
+
expect(idx.requirementsByParent.has('REQUIREMENT-INTERNAL-1')).toBe(false);
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
describe('buildRequirementTrace — trace chain', () => {
|
|
61
|
+
const idx = buildComplianceIndex(input);
|
|
62
|
+
it('resolves derived_from codex artefacts on the sources block', () => {
|
|
63
|
+
const trace = buildRequirementTrace('REQUIREMENT-DATA-ERASURE-1', idx, catalog, codex);
|
|
64
|
+
expect(trace.sources).toHaveLength(1);
|
|
65
|
+
expect(trace.sources[0].id).toBe('REGULATION-GDPR-2016-1');
|
|
66
|
+
expect(trace.sources[0].codex?.jurisdiction).toBe('EU');
|
|
67
|
+
});
|
|
68
|
+
it('keeps a dangling derived_from ref with no codex when the artefact is missing', () => {
|
|
69
|
+
const local: ComplianceIndexInput = {
|
|
70
|
+
requirements: [{ id: 'REQUIREMENT-X-1', name: 'X', derived_from: ['LAW-MISSING-1'] }],
|
|
71
|
+
assertions: [],
|
|
72
|
+
};
|
|
73
|
+
const trace = buildRequirementTrace('REQUIREMENT-X-1', buildComplianceIndex(local), catalog);
|
|
74
|
+
expect(trace.sources).toEqual([{ id: 'LAW-MISSING-1' }]);
|
|
75
|
+
});
|
|
76
|
+
it('lists ASSERTIONs id-sorted, each with resolved subject + realised_via names', () => {
|
|
77
|
+
const trace = buildRequirementTrace('REQUIREMENT-DATA-ERASURE-1', idx, catalog, codex);
|
|
78
|
+
expect(trace.assertions.map(a => a.assertion.id)).toEqual(['ASSERTION-1', 'ASSERTION-2']);
|
|
79
|
+
expect(trace.assertions[0].subject).toEqual({ id: 'PRODUCT-MOBILE-1', name: 'Mobile app' });
|
|
80
|
+
expect(trace.assertions[0].realisedVia.map(r => r.name)).toEqual(['Erasure capability v1', 'Purge process']);
|
|
81
|
+
});
|
|
82
|
+
it('returns an empty assertions list for a REQUIREMENT with no filed claim', () => {
|
|
83
|
+
const trace = buildRequirementTrace('REQUIREMENT-DATA-PROTECTION-1', idx, catalog);
|
|
84
|
+
expect(trace.assertions).toEqual([]);
|
|
85
|
+
});
|
|
86
|
+
it('returns an empty assertions list for a CONSTRAINT (16-assertion.md §1 — CONSTRAINT-side out of v1)', () => {
|
|
87
|
+
const trace = buildRequirementTrace('CONSTRAINT-EEA-TRANSFER-1', idx, catalog);
|
|
88
|
+
expect(trace.assertions).toEqual([]);
|
|
89
|
+
});
|
|
90
|
+
it('falls back to id when the subject / realised_via element is not in the catalog (dangling ref)', () => {
|
|
91
|
+
const local: ComplianceIndexInput = {
|
|
92
|
+
requirements: [{ id: 'REQUIREMENT-Y-1', name: 'Y' }],
|
|
93
|
+
assertions: [{ id: 'ASSERTION-9', about: 'REQUIREMENT-Y-1', subject: 'PRODUCT-GONE-1', realised_via: ['CAPABILITY-GONE-1'], status: 'n_a' }],
|
|
94
|
+
};
|
|
95
|
+
const trace = buildRequirementTrace('REQUIREMENT-Y-1', buildComplianceIndex(local), catalog);
|
|
96
|
+
expect(trace.assertions[0].subject).toEqual({ id: 'PRODUCT-GONE-1' });
|
|
97
|
+
expect(trace.assertions[0].realisedVia).toEqual([{ id: 'CAPABILITY-GONE-1' }]);
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
describe('buildRequirementTrace — hierarchy', () => {
|
|
102
|
+
const idx = buildComplianceIndex(input);
|
|
103
|
+
it('walks ancestors: immediate parent first, root last', () => {
|
|
104
|
+
const trace = buildRequirementTrace('REQUIREMENT-ERASURE-SLA-1', idx, catalog);
|
|
105
|
+
expect(trace.ancestors.map(r => r.id)).toEqual([
|
|
106
|
+
'REQUIREMENT-DATA-ERASURE-1',
|
|
107
|
+
'REQUIREMENT-DATA-PROTECTION-1',
|
|
108
|
+
]);
|
|
109
|
+
});
|
|
110
|
+
it('lists direct children id-sorted', () => {
|
|
111
|
+
const trace = buildRequirementTrace('REQUIREMENT-DATA-PROTECTION-1', idx, catalog);
|
|
112
|
+
expect(trace.children.map(r => r.id)).toEqual([
|
|
113
|
+
'REQUIREMENT-DATA-CONSENT-1',
|
|
114
|
+
'REQUIREMENT-DATA-ERASURE-1',
|
|
115
|
+
]);
|
|
116
|
+
});
|
|
117
|
+
it('handles a top-level requirement (no ancestors) with no children', () => {
|
|
118
|
+
const trace = buildRequirementTrace('REQUIREMENT-INTERNAL-1', idx, catalog);
|
|
119
|
+
expect(trace.ancestors).toEqual([]);
|
|
120
|
+
expect(trace.children).toEqual([]);
|
|
121
|
+
});
|
|
122
|
+
it('supports CONSTRAINT hierarchy the same way', () => {
|
|
123
|
+
const trace = buildRequirementTrace('CONSTRAINT-EEA-ANALYTICS-1', idx, catalog);
|
|
124
|
+
expect(trace.ancestors.map(r => r.id)).toEqual(['CONSTRAINT-EEA-TRANSFER-1']);
|
|
125
|
+
});
|
|
126
|
+
it('terminates at a missing parent without throwing (broken model)', () => {
|
|
127
|
+
const local: ComplianceIndexInput = {
|
|
128
|
+
requirements: [{ id: 'REQUIREMENT-ORPHAN-1', name: 'Orphan', parent: 'REQUIREMENT-GONE-1' }],
|
|
129
|
+
assertions: [],
|
|
130
|
+
};
|
|
131
|
+
const trace = buildRequirementTrace('REQUIREMENT-ORPHAN-1', buildComplianceIndex(local), catalog);
|
|
132
|
+
expect(trace.ancestors).toEqual([]);
|
|
133
|
+
});
|
|
134
|
+
it('breaks a parent cycle rather than looping', () => {
|
|
135
|
+
// A → B → A (misauthored).
|
|
136
|
+
const local: ComplianceIndexInput = {
|
|
137
|
+
requirements: [
|
|
138
|
+
{ id: 'REQUIREMENT-A-1', name: 'A', parent: 'REQUIREMENT-B-1' },
|
|
139
|
+
{ id: 'REQUIREMENT-B-1', name: 'B', parent: 'REQUIREMENT-A-1' },
|
|
140
|
+
],
|
|
141
|
+
assertions: [],
|
|
142
|
+
};
|
|
143
|
+
const trace = buildRequirementTrace('REQUIREMENT-A-1', buildComplianceIndex(local), catalog);
|
|
144
|
+
expect(trace.ancestors.map(r => r.id)).toEqual(['REQUIREMENT-B-1']);
|
|
145
|
+
});
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
describe('buildRequirementTrace — dangling target', () => {
|
|
149
|
+
it('returns a stub carrying the id as name when the requirement is not scanned', () => {
|
|
150
|
+
const trace = buildRequirementTrace('REQUIREMENT-UNKNOWN-1', buildComplianceIndex({ requirements: [], assertions: [] }), catalog);
|
|
151
|
+
expect(trace.requirement).toEqual({ id: 'REQUIREMENT-UNKNOWN-1', name: 'REQUIREMENT-UNKNOWN-1' });
|
|
152
|
+
expect(trace.sources).toEqual([]);
|
|
153
|
+
expect(trace.assertions).toEqual([]);
|
|
154
|
+
expect(trace.ancestors).toEqual([]);
|
|
155
|
+
expect(trace.children).toEqual([]);
|
|
156
|
+
});
|
|
157
|
+
});
|
|
@@ -65,7 +65,8 @@ export function ingestComplianceDoc(canon: ComplianceCanon, doc: unknown): strin
|
|
|
65
65
|
canon.subjects.push({ id, name: str(d.name) ?? id });
|
|
66
66
|
return id;
|
|
67
67
|
}
|
|
68
|
-
if (d.notation === 'requirement') {
|
|
68
|
+
if (d.notation === 'requirement' || d.notation === 'constraint') {
|
|
69
|
+
const origin = str(d.origin);
|
|
69
70
|
canon.requirements.push({
|
|
70
71
|
id,
|
|
71
72
|
name: str(d.name) ?? id,
|
|
@@ -73,6 +74,11 @@ export function ingestComplianceDoc(canon: ComplianceCanon, doc: unknown): strin
|
|
|
73
74
|
derived_from: strArray(d.derived_from),
|
|
74
75
|
admitted_at: str(d.admitted_at),
|
|
75
76
|
deadline: str(d.deadline),
|
|
77
|
+
origin: origin === 'legislative' || origin === 'process-product' || origin === 'project-product' ? origin : undefined,
|
|
78
|
+
parent: str(d.parent),
|
|
79
|
+
element_kind: d.notation,
|
|
80
|
+
description: str(d.description),
|
|
81
|
+
next_review_at: str(d.next_review_at),
|
|
76
82
|
});
|
|
77
83
|
return id;
|
|
78
84
|
}
|
package/src/compliance/index.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export { buildComplianceIndex } from './reverse-index.js';
|
|
2
2
|
export { buildLawTree, buildProductView } from './views.js';
|
|
3
|
+
export { buildRequirementTrace, buildTraceElementCatalog } from './trace.js';
|
|
3
4
|
export { buildGapReport } from './gap-report.js';
|
|
4
5
|
export type { GapReport, GapReportOptions } from './gap-report.js';
|
|
5
6
|
export { emptyCanon, ingestComplianceDoc } from './classify.js';
|
|
@@ -54,4 +55,9 @@ export type {
|
|
|
54
55
|
ProductRequirementStatus,
|
|
55
56
|
ObjectDetailDef,
|
|
56
57
|
ObjectDetailInput,
|
|
58
|
+
RequirementTrace,
|
|
59
|
+
TraceAssertionRow,
|
|
60
|
+
TraceElementCatalog,
|
|
61
|
+
TraceElementRef,
|
|
62
|
+
TraceSourceRef,
|
|
57
63
|
} from './types.js';
|
|
@@ -19,15 +19,17 @@ export function buildComplianceIndex(input: ComplianceIndexInput): ComplianceInd
|
|
|
19
19
|
const requirementsByLaw = new Map<string, IndexRequirement[]>();
|
|
20
20
|
const assertionsByRequirement = new Map<string, IndexAssertion[]>();
|
|
21
21
|
const assertionsBySubject = new Map<string, IndexAssertion[]>();
|
|
22
|
+
const requirementsByParent = new Map<string, IndexRequirement[]>();
|
|
22
23
|
|
|
23
24
|
for (const r of input.requirements) {
|
|
24
25
|
requirementById.set(r.id, r);
|
|
25
26
|
for (const law of r.derived_from ?? []) push(requirementsByLaw, law, r);
|
|
27
|
+
if (r.parent) push(requirementsByParent, r.parent, r);
|
|
26
28
|
}
|
|
27
29
|
for (const a of input.assertions) {
|
|
28
30
|
push(assertionsByRequirement, a.about, a);
|
|
29
31
|
push(assertionsBySubject, a.subject, a);
|
|
30
32
|
}
|
|
31
33
|
|
|
32
|
-
return { requirementById, requirementsByLaw, assertionsByRequirement, assertionsBySubject };
|
|
34
|
+
return { requirementById, requirementsByLaw, assertionsByRequirement, assertionsBySubject, requirementsByParent };
|
|
33
35
|
}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
// Requirement traceability + hierarchy builder.
|
|
2
|
+
//
|
|
3
|
+
// Two halves, both origin-agnostic per 15-requirement.md §2.1:
|
|
4
|
+
//
|
|
5
|
+
// 1. Trace chain — `derived_from` sources → the REQUIREMENT / CONSTRAINT
|
|
6
|
+
// itself → any ASSERTION targeting it (`about`) → the asserted `subject`
|
|
7
|
+
// + `realised_via` elements. Assertion coverage applies to REQUIREMENT
|
|
8
|
+
// only (16-assertion.md §1); CONSTRAINT trace shows sources + hierarchy
|
|
9
|
+
// only.
|
|
10
|
+
//
|
|
11
|
+
// 2. Hierarchy — the `parent` chain (ancestors, root last) plus the direct
|
|
12
|
+
// children (elements whose `parent` names this one). Same-TYPE only per
|
|
13
|
+
// 15-requirement.md §2.4; the chain terminates at the first missing or
|
|
14
|
+
// cyclic parent so a broken model still renders something useful.
|
|
15
|
+
//
|
|
16
|
+
// Pure: takes the reverse index + a name-resolution map + optional codex list;
|
|
17
|
+
// no IO. `ComplianceCodexDoc` comes from the scanner so we get jurisdiction
|
|
18
|
+
// alongside the codex id in the sources block.
|
|
19
|
+
|
|
20
|
+
import type {
|
|
21
|
+
ComplianceIndex,
|
|
22
|
+
IndexRequirement,
|
|
23
|
+
RequirementTrace,
|
|
24
|
+
TraceAssertionRow,
|
|
25
|
+
TraceElementCatalog,
|
|
26
|
+
TraceElementRef,
|
|
27
|
+
TraceSourceRef,
|
|
28
|
+
} from './types.js';
|
|
29
|
+
import type { ComplianceCodexDoc } from './classify.js';
|
|
30
|
+
|
|
31
|
+
function byId<T extends { id: string }>(a: T, b: T): number {
|
|
32
|
+
return a.id < b.id ? -1 : a.id > b.id ? 1 : 0;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function resolveElement(id: string, catalog: TraceElementCatalog): TraceElementRef {
|
|
36
|
+
const name = catalog.nameById.get(id);
|
|
37
|
+
return name ? { id, name } : { id };
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Walk the `parent` chain upward from `requirement`, stopping at the first
|
|
42
|
+
* missing or already-seen parent (cycle guard). Returns immediate parent first,
|
|
43
|
+
* root last. Empty array when the element has no `parent`.
|
|
44
|
+
*/
|
|
45
|
+
function collectAncestors(
|
|
46
|
+
requirement: IndexRequirement,
|
|
47
|
+
index: ComplianceIndex,
|
|
48
|
+
): IndexRequirement[] {
|
|
49
|
+
const out: IndexRequirement[] = [];
|
|
50
|
+
const seen = new Set<string>([requirement.id]);
|
|
51
|
+
let current: IndexRequirement | undefined = requirement;
|
|
52
|
+
while (current?.parent && !seen.has(current.parent)) {
|
|
53
|
+
seen.add(current.parent);
|
|
54
|
+
const next = index.requirementById.get(current.parent);
|
|
55
|
+
if (!next) break;
|
|
56
|
+
out.push(next);
|
|
57
|
+
current = next;
|
|
58
|
+
}
|
|
59
|
+
return out;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Builds the REQUIREMENT / CONSTRAINT traceability view.
|
|
64
|
+
*
|
|
65
|
+
* @param requirementId typed id of the element to trace
|
|
66
|
+
* @param index reverse index built by `buildComplianceIndex`
|
|
67
|
+
* @param catalog name-resolution map for subject / realised_via refs
|
|
68
|
+
* @param codex optional codex artefact list (from the scanner); when
|
|
69
|
+
* supplied, `sources[].codex` is populated with the
|
|
70
|
+
* resolved codex artefact for jurisdiction display
|
|
71
|
+
*/
|
|
72
|
+
export function buildRequirementTrace(
|
|
73
|
+
requirementId: string,
|
|
74
|
+
index: ComplianceIndex,
|
|
75
|
+
catalog: TraceElementCatalog,
|
|
76
|
+
codex: ComplianceCodexDoc[] = [],
|
|
77
|
+
): RequirementTrace {
|
|
78
|
+
const requirement: IndexRequirement =
|
|
79
|
+
index.requirementById.get(requirementId) ?? { id: requirementId, name: requirementId };
|
|
80
|
+
|
|
81
|
+
const codexById = new Map<string, ComplianceCodexDoc>();
|
|
82
|
+
for (const c of codex) codexById.set(c.id, c);
|
|
83
|
+
|
|
84
|
+
const sources: TraceSourceRef[] = (requirement.derived_from ?? []).map(sid => {
|
|
85
|
+
const c = codexById.get(sid);
|
|
86
|
+
return c ? { id: sid, codex: c } : { id: sid };
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
const rawAssertions = index.assertionsByRequirement.get(requirementId) ?? [];
|
|
90
|
+
const assertions: TraceAssertionRow[] = [...rawAssertions]
|
|
91
|
+
.sort(byId)
|
|
92
|
+
.map(assertion => ({
|
|
93
|
+
assertion,
|
|
94
|
+
subject: resolveElement(assertion.subject, catalog),
|
|
95
|
+
realisedVia: (assertion.realised_via ?? []).map(rid => resolveElement(rid, catalog)),
|
|
96
|
+
}));
|
|
97
|
+
|
|
98
|
+
const ancestors = collectAncestors(requirement, index);
|
|
99
|
+
const children = [...(index.requirementsByParent.get(requirementId) ?? [])].sort(byId);
|
|
100
|
+
|
|
101
|
+
return { requirement, sources, assertions, ancestors, children };
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Convenience: build a `TraceElementCatalog` from the scanned canon's product
|
|
106
|
+
* and subject buckets. Requirements/assertions are excluded — they are indexed
|
|
107
|
+
* separately by `buildComplianceIndex`; the catalog is only for resolving the
|
|
108
|
+
* elements a trace references (subjects + realised_via).
|
|
109
|
+
*/
|
|
110
|
+
export function buildTraceElementCatalog(
|
|
111
|
+
products: Array<{ id: string; name: string }>,
|
|
112
|
+
subjects: Array<{ id: string; name: string }>,
|
|
113
|
+
): TraceElementCatalog {
|
|
114
|
+
const nameById = new Map<string, string>();
|
|
115
|
+
for (const p of products) nameById.set(p.id, p.name);
|
|
116
|
+
for (const s of subjects) nameById.set(s.id, s.name);
|
|
117
|
+
return { nameById };
|
|
118
|
+
}
|