@transitrix/diagrams 1.0.1 → 1.2.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/activities/__tests__/validate.test.js +32 -1
- package/dist/activities/cpm.js +11 -2
- package/dist/activities/gantt.js +6 -3
- package/dist/activities/types.d.ts +1 -0
- package/dist/activities/validate.js +24 -8
- package/dist/activity-card/__tests__/resolver.test.js +22 -1
- package/dist/activity-card/__tests__/validate.test.js +23 -1
- package/dist/activity-card/resolver.js +28 -20
- package/dist/activity-card/validate.js +22 -11
- package/dist/capability-map/index.d.ts +4 -0
- package/dist/capability-map/index.js +2 -0
- package/dist/capability-map/layout-tree.d.ts +42 -0
- package/dist/capability-map/layout-tree.js +65 -0
- package/dist/capability-map/render-capability-tree.d.ts +15 -0
- package/dist/capability-map/render-capability-tree.js +108 -0
- package/dist/capability-map/types.d.ts +2 -0
- package/dist/compliance/__tests__/impact.test.js +198 -0
- package/dist/compliance/html.js +1 -7
- package/dist/compliance/impact.d.ts +24 -1
- package/dist/compliance/impact.js +97 -21
- package/dist/factor/__tests__/validate.test.js +3 -3
- package/dist/factor/types.d.ts +1 -1
- package/dist/factor/validate.js +2 -2
- package/dist/fgca/__tests__/chain-table.test.js +2 -2
- package/dist/fgca/__tests__/layout.test.js +11 -11
- package/dist/fgca/__tests__/preview-layout.test.js +7 -7
- package/dist/fgca/__tests__/resolver.test.js +2 -2
- package/dist/fgca/__tests__/validate.test.js +2 -2
- package/dist/fgca/chain-table.d.ts +1 -1
- package/dist/fgca/chain-table.js +4 -4
- package/dist/fgca/index.d.ts +2 -2
- package/dist/fgca/index.js +1 -1
- package/dist/fgca/layout.d.ts +2 -2
- package/dist/fgca/layout.js +9 -9
- package/dist/fgca/nodeTypes.d.ts +1 -1
- package/dist/fgca/nodeTypes.js +2 -2
- package/dist/fgca/nodes/FGCAFactorNode.d.ts +3 -3
- package/dist/fgca/nodes/FGCAFactorNode.js +5 -5
- package/dist/fgca/parse-canonical.js +24 -13
- package/dist/fgca/preview-layout.d.ts +1 -1
- package/dist/fgca/preview-layout.js +4 -4
- package/dist/fgca/resolver.js +3 -1
- package/dist/fgca/types.d.ts +13 -11
- package/dist/fgca/types.js +2 -2
- package/dist/fgca/validate.d.ts +2 -2
- package/dist/fgca/validate.js +34 -23
- package/dist/process-blueprint/index.d.ts +1 -1
- package/dist/process-blueprint/layout.js +64 -37
- package/dist/process-blueprint/types.d.ts +14 -0
- package/dist/scenarios/index.d.ts +1 -1
- package/dist/scenarios/types.d.ts +4 -4
- package/dist/theme/index.d.ts +1 -1
- package/dist/theme/index.js +1 -1
- package/dist/theme/themes.js +28 -3
- package/dist/theme/tokens.d.ts +47 -1
- package/dist/theme/tokens.js +31 -1
- package/dist/webview/__tests__/entry-notations.test.js +2 -0
- package/dist/webview/__tests__/render-process.test.d.ts +1 -0
- package/dist/webview/__tests__/render-process.test.js +463 -0
- package/dist/webview/__tests__/render-util.test.d.ts +1 -0
- package/dist/webview/__tests__/render-util.test.js +54 -0
- package/dist/webview/entry.d.ts +1 -1
- package/dist/webview/entry.js +9 -5
- package/dist/webview/render-activities.d.ts +21 -1
- package/dist/webview/render-activities.js +91 -56
- package/dist/webview/render-activity-card.d.ts +11 -1
- package/dist/webview/render-activity-card.js +11 -2
- package/dist/webview/render-blocks.d.ts +24 -1
- package/dist/webview/render-blocks.js +58 -24
- package/dist/webview/render-fgca.d.ts +27 -0
- package/dist/webview/render-fgca.js +30 -16
- package/dist/webview/render-goals.d.ts +26 -1
- package/dist/webview/render-goals.js +30 -20
- package/dist/webview/render-process-blueprint.d.ts +11 -1
- package/dist/webview/render-process-blueprint.js +118 -53
- package/dist/webview/render-process.d.ts +95 -0
- package/dist/webview/render-process.js +392 -0
- package/dist/webview/render-scenarios.js +2 -2
- package/dist/webview/render-util.d.ts +19 -6
- package/dist/webview/render-util.js +23 -15
- package/package.json +15 -1
- package/src/activities/__tests__/validate.test.ts +35 -1
- package/src/activities/cpm.ts +14 -2
- package/src/activities/gantt.ts +6 -5
- package/src/activities/types.ts +1 -0
- package/src/activities/validate.ts +24 -8
- package/src/activity-card/__tests__/resolver.test.ts +24 -1
- package/src/activity-card/__tests__/validate.test.ts +25 -1
- package/src/activity-card/resolver.ts +29 -20
- package/src/activity-card/validate.ts +20 -11
- package/src/capability-map/index.ts +11 -0
- package/src/capability-map/layout-tree.ts +114 -0
- package/src/capability-map/render-capability-tree.ts +131 -0
- package/src/capability-map/types.ts +2 -0
- package/src/compliance/__tests__/impact.test.ts +219 -0
- package/src/compliance/html.ts +1 -8
- package/src/compliance/impact.ts +141 -23
- package/src/factor/__tests__/validate.test.ts +3 -3
- package/src/factor/types.ts +1 -1
- package/src/factor/validate.ts +2 -2
- package/src/fgca/__tests__/chain-table.test.ts +2 -2
- package/src/fgca/__tests__/layout.test.ts +13 -13
- package/src/fgca/__tests__/preview-layout.test.ts +7 -7
- package/src/fgca/__tests__/resolver.test.ts +2 -2
- package/src/fgca/__tests__/validate.test.ts +2 -2
- package/src/fgca/chain-table.ts +5 -5
- package/src/fgca/index.ts +3 -3
- package/src/fgca/layout.ts +11 -11
- package/src/fgca/nodeTypes.ts +3 -3
- package/src/fgca/nodes/FGCAFactorNode.tsx +6 -6
- package/src/fgca/parse-canonical.ts +26 -15
- package/src/fgca/preview-layout.ts +5 -5
- package/src/fgca/resolver.ts +3 -1
- package/src/fgca/types.ts +15 -13
- package/src/fgca/validate.ts +32 -21
- package/src/process-blueprint/index.ts +1 -0
- package/src/process-blueprint/layout.ts +71 -42
- package/src/process-blueprint/types.ts +15 -0
- package/src/scenarios/index.ts +2 -2
- package/src/scenarios/types.ts +4 -4
- package/src/scenarios/validate.ts +3 -3
- package/src/theme/index.ts +1 -1
- package/src/theme/themes.ts +29 -2
- package/src/theme/tokens.ts +33 -1
- package/src/webview/__tests__/entry-notations.test.ts +2 -0
- package/src/webview/__tests__/render-process.test.ts +538 -0
- package/src/webview/__tests__/render-util.test.ts +66 -0
- package/src/webview/entry.ts +11 -5
- package/src/webview/render-activities.ts +107 -67
- package/src/webview/render-activity-card.ts +11 -2
- package/src/webview/render-blocks.ts +78 -28
- package/src/webview/render-fgca.ts +53 -29
- package/src/webview/render-goals.ts +45 -23
- package/src/webview/render-process-blueprint.ts +156 -82
- package/src/webview/render-process.ts +507 -0
- package/src/webview/render-scenarios.ts +3 -3
- package/src/webview/render-util.ts +27 -14
|
@@ -25,7 +25,7 @@ const doc: FGCAPreviewDoc = {
|
|
|
25
25
|
describe('layoutFGCAPreview', () => {
|
|
26
26
|
it('lays out all four columns in order (FGCA)', () => {
|
|
27
27
|
const layout = layoutFGCAPreview(doc);
|
|
28
|
-
expect(layout.columns.map(c => c.col)).toEqual(['
|
|
28
|
+
expect(layout.columns.map(c => c.col)).toEqual(['driver', 'goal', 'change', 'activity']);
|
|
29
29
|
// 2 factors + 2 goals + 1 change + 2 activities
|
|
30
30
|
expect(layout.nodes).toHaveLength(7);
|
|
31
31
|
expect(layout.width).toBeGreaterThan(0);
|
|
@@ -40,7 +40,7 @@ describe('layoutFGCAPreview', () => {
|
|
|
40
40
|
|
|
41
41
|
it('hideChanges (FGA) drops the Changes column and links goals to activities', () => {
|
|
42
42
|
const layout = layoutFGCAPreview(doc, { hideChanges: true });
|
|
43
|
-
expect(layout.columns.map(c => c.col)).toEqual(['
|
|
43
|
+
expect(layout.columns.map(c => c.col)).toEqual(['driver', 'goal', 'activity']);
|
|
44
44
|
// 2 factors + 2 goals + 2 activities
|
|
45
45
|
expect(layout.nodes).toHaveLength(6);
|
|
46
46
|
// F1→G1, F2→G2 (2), G1→A1, G2→A2 (2) = 4
|
|
@@ -70,7 +70,7 @@ describe('layoutFGCAPreview', () => {
|
|
|
70
70
|
|
|
71
71
|
it('larger rowGap increases the gap between stacked nodes', () => {
|
|
72
72
|
const gapOf = (rowGap: number) => {
|
|
73
|
-
const factors = layoutFGCAPreview(doc, { rowGap }).nodes.filter(n => n.col === '
|
|
73
|
+
const factors = layoutFGCAPreview(doc, { rowGap }).nodes.filter(n => n.col === 'driver');
|
|
74
74
|
return factors[1].y - factors[0].y;
|
|
75
75
|
};
|
|
76
76
|
expect(gapOf(120)).toBeGreaterThan(gapOf(20));
|
|
@@ -86,15 +86,15 @@ describe('layoutFGCAPreview', () => {
|
|
|
86
86
|
// root 10 → factor 1 (referenced by G10), change 20 (goal_id 10),
|
|
87
87
|
// activity 30 (via change 20). G11/F2/A31 are dropped.
|
|
88
88
|
const layout = layoutFGCAPreview(doc, { scope: { mode: 'root', rootGoalId: '10' } });
|
|
89
|
-
expect(idsOf(layout)).toEqual(new Set(['
|
|
89
|
+
expect(idsOf(layout)).toEqual(new Set(['driver_1', 'goal_10', 'change_20', 'activity_30']));
|
|
90
90
|
});
|
|
91
91
|
|
|
92
92
|
it("mode 'root' filters factors and activities to those touching the visible goal", () => {
|
|
93
93
|
// root 11 → factor 2, activity 31 (direct goal link); no change touches G11.
|
|
94
94
|
const layout = layoutFGCAPreview(doc, { scope: { mode: 'root', rootGoalId: '11' } });
|
|
95
|
-
expect(idsOf(layout)).toEqual(new Set(['
|
|
95
|
+
expect(idsOf(layout)).toEqual(new Set(['driver_2', 'goal_11', 'activity_31']));
|
|
96
96
|
// F1, A30, C20 (which only touch the hidden G10) are excluded.
|
|
97
|
-
expect(layout.nodes.some(n => n.id === '
|
|
97
|
+
expect(layout.nodes.some(n => n.id === 'driver_1')).toBe(false);
|
|
98
98
|
expect(layout.nodes.some(n => n.id === 'activity_30')).toBe(false);
|
|
99
99
|
});
|
|
100
100
|
|
|
@@ -112,7 +112,7 @@ describe('layoutFGCAPreview', () => {
|
|
|
112
112
|
],
|
|
113
113
|
};
|
|
114
114
|
const layout = layoutFGCAPreview(leveled, { scope: { mode: 'level', maxLevel: 0 } });
|
|
115
|
-
expect(idsOf(layout)).toEqual(new Set(['
|
|
115
|
+
expect(idsOf(layout)).toEqual(new Set(['driver_1', 'goal_10', 'activity_30']));
|
|
116
116
|
});
|
|
117
117
|
|
|
118
118
|
it("mode 'root' returns an empty layout when the root is absent", () => {
|
|
@@ -8,8 +8,8 @@ import { parseCanonicalFGCA } from '../parse-canonical.js';
|
|
|
8
8
|
// ── Inline canon element store (mirrors strategy-2026 data split into per-element form) ─
|
|
9
9
|
|
|
10
10
|
const ELEMENTS = [
|
|
11
|
-
{ notation: '
|
|
12
|
-
{ notation: '
|
|
11
|
+
{ notation: 'driver', id: 'FACTOR-1', name: 'Competitive market pressure', type: 'external' },
|
|
12
|
+
{ notation: 'driver', id: 'FACTOR-2', name: 'Digital adoption acceleration', type: 'external' },
|
|
13
13
|
{ notation: 'goal', id: 'GOAL-1', name: 'Grow revenue by 20%', factors: ['FACTOR-1', 'FACTOR-2'] },
|
|
14
14
|
{ notation: 'goal', id: 'GOAL-2', name: 'Reduce operational costs', factors: ['FACTOR-2'] },
|
|
15
15
|
{ notation: 'goal', id: 'GOAL-3', name: 'Improve customer retention', factors: ['FACTOR-1'] },
|
|
@@ -56,11 +56,11 @@ describe('validateFGCADoc', () => {
|
|
|
56
56
|
expect(result.errors.some(e => e.path === 'changes')).toBe(true);
|
|
57
57
|
});
|
|
58
58
|
|
|
59
|
-
it('errors when
|
|
59
|
+
it('errors when actions array is missing', () => {
|
|
60
60
|
const { activities: _, ...without } = VALID_DOC;
|
|
61
61
|
const result = validateFGCADoc({ ...without, notation: 'fgca' });
|
|
62
62
|
expect(result.valid).toBe(false);
|
|
63
|
-
expect(result.errors.some(e => e.path === '
|
|
63
|
+
expect(result.errors.some(e => e.path === 'actions')).toBe(true);
|
|
64
64
|
});
|
|
65
65
|
|
|
66
66
|
it('errors on empty factor name', () => {
|
package/src/fgca/chain-table.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// Chain-table model for the FGCA / FGA previews (vkgeorgia/strategy#137).
|
|
2
2
|
//
|
|
3
|
-
// The tree/chain preview (`layoutFGCAPreview`) shows
|
|
3
|
+
// The tree/chain preview (`layoutFGCAPreview`) shows Driver → Goal → Change →
|
|
4
4
|
// Activity as columns of nodes joined by edges. This module produces the
|
|
5
5
|
// *tabular* alternative: the same chain flattened into rows, with shared
|
|
6
6
|
// parents collapsed into vertically-merged (rowspan) cells.
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
|
|
24
24
|
import type { FGCAPreviewDoc } from './preview-layout.js';
|
|
25
25
|
|
|
26
|
-
export type ChainColumn = '
|
|
26
|
+
export type ChainColumn = 'driver' | 'goal' | 'change' | 'activity';
|
|
27
27
|
|
|
28
28
|
export interface ChainCell {
|
|
29
29
|
/** Column-qualified identity (e.g. "goal:3") — stable, unique across columns. */
|
|
@@ -76,8 +76,8 @@ function sameCell(a: ChainCell | null, b: ChainCell | null): boolean {
|
|
|
76
76
|
export function buildChainTable(doc: FGCAPreviewDoc, options: ChainTableOptions = {}): ChainTable {
|
|
77
77
|
const { hideChanges = false } = options;
|
|
78
78
|
const columns: ChainColumn[] = hideChanges
|
|
79
|
-
? ['
|
|
80
|
-
: ['
|
|
79
|
+
? ['driver', 'goal', 'activity']
|
|
80
|
+
: ['driver', 'goal', 'change', 'activity'];
|
|
81
81
|
|
|
82
82
|
const changes = doc.changes ?? [];
|
|
83
83
|
const factorIds = new Set(doc.factors.map(f => f.id));
|
|
@@ -146,7 +146,7 @@ export function buildChainTable(doc: FGCAPreviewDoc, options: ChainTableOptions
|
|
|
146
146
|
|
|
147
147
|
// Phase 1 — factor-rooted paths.
|
|
148
148
|
for (const f of doc.factors) {
|
|
149
|
-
const factorCell = cellOf('
|
|
149
|
+
const factorCell = cellOf('driver', f.id, f.name);
|
|
150
150
|
const goalsOfFactor = doc.goals.filter(g => (g.factor ?? []).some(ref => ref.id === f.id));
|
|
151
151
|
if (goalsOfFactor.length === 0) {
|
|
152
152
|
paths.push(pad([factorCell]));
|
package/src/fgca/index.ts
CHANGED
|
@@ -28,7 +28,7 @@ export {
|
|
|
28
28
|
FGCA_COLUMN_LABELS,
|
|
29
29
|
} from "./types";
|
|
30
30
|
export type {
|
|
31
|
-
|
|
31
|
+
DriverItem,
|
|
32
32
|
GoalItem,
|
|
33
33
|
BdnChangeWithActivities,
|
|
34
34
|
ActivityItem,
|
|
@@ -38,10 +38,10 @@ export type {
|
|
|
38
38
|
} from "./types";
|
|
39
39
|
export { resolveFGCA, isFGCAViewDoc } from './resolver.js';
|
|
40
40
|
export type { FGCAViewConfig, FGCACanonSources } from './resolver.js';
|
|
41
|
-
export { default as
|
|
41
|
+
export { default as FGCADriverNode } from "./nodes/FGCAFactorNode";
|
|
42
42
|
export { default as FGCAGoalNode } from "./nodes/FGCAGoalNode";
|
|
43
43
|
export { default as FGCAChangeNode } from "./nodes/FGCAChangeNode";
|
|
44
44
|
export { default as FGCAActivityNode } from "./nodes/FGCAActivityNode";
|
|
45
45
|
|
|
46
46
|
/** ReactFlow nodeTypes map — pass directly to <ReactFlow nodeTypes={FGCA_NODE_TYPES} /> */
|
|
47
|
-
export { FGCA_NODE_TYPES } from "./nodeTypes";
|
|
47
|
+
export { FGCA_NODE_TYPES } from "./nodeTypes";
|
package/src/fgca/layout.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Node, Edge } from "reactflow";
|
|
2
2
|
import { Position, MarkerType } from "reactflow";
|
|
3
3
|
import type {
|
|
4
|
-
|
|
4
|
+
DriverItem,
|
|
5
5
|
GoalItem,
|
|
6
6
|
BdnChangeWithActivities,
|
|
7
7
|
ActivityItem,
|
|
@@ -18,14 +18,14 @@ export const ROW_GAP = 24;
|
|
|
18
18
|
|
|
19
19
|
/** Default background colours per column. */
|
|
20
20
|
export const COLUMN_BG: Record<FGCAColumn, string> = {
|
|
21
|
-
|
|
21
|
+
driver: "#fef3c7",
|
|
22
22
|
goal: "#e0e7ff",
|
|
23
23
|
change: "#dbeafe",
|
|
24
24
|
activity: "#d4edda",
|
|
25
25
|
};
|
|
26
26
|
|
|
27
27
|
export interface FGCALayoutInput {
|
|
28
|
-
factors:
|
|
28
|
+
factors: DriverItem[];
|
|
29
29
|
goals: GoalItem[];
|
|
30
30
|
changes: BdnChangeWithActivities[];
|
|
31
31
|
activities: ActivityItem[];
|
|
@@ -66,12 +66,12 @@ export function buildFGCALayout({
|
|
|
66
66
|
const edgeStyle = { strokeWidth: edgeWidth, stroke: edgeColor };
|
|
67
67
|
const baseNodeStyle = { borderColor: nodeBorderColor, borderWidth: nodeBorderWidth, borderStyle: "solid" };
|
|
68
68
|
|
|
69
|
-
if (visibleColumns.has("
|
|
69
|
+
if (visibleColumns.has("driver")) {
|
|
70
70
|
factors.forEach((f, i) => {
|
|
71
71
|
nodes.push({
|
|
72
|
-
id: `
|
|
73
|
-
type: "
|
|
74
|
-
position: { x: colX["
|
|
72
|
+
id: `driver_${f.id}`,
|
|
73
|
+
type: "fgcaDriver",
|
|
74
|
+
position: { x: colX["driver"]!, y: i * (NODE_HEIGHT + ROW_GAP) },
|
|
75
75
|
data: { id: f.id, name: f.name, ...baseNodeStyle },
|
|
76
76
|
sourcePosition: Position.Right,
|
|
77
77
|
targetPosition: Position.Left,
|
|
@@ -132,13 +132,13 @@ export function buildFGCALayout({
|
|
|
132
132
|
});
|
|
133
133
|
}
|
|
134
134
|
|
|
135
|
-
//
|
|
136
|
-
if (visibleColumns.has("
|
|
135
|
+
// Driver→Goal edges (via embedded factor[] on each goal)
|
|
136
|
+
if (visibleColumns.has("driver") && visibleColumns.has("goal")) {
|
|
137
137
|
goals.forEach((g) => {
|
|
138
138
|
g.factor?.forEach((f) => {
|
|
139
139
|
edges.push({
|
|
140
|
-
id: `
|
|
141
|
-
source: `
|
|
140
|
+
id: `edge_d${f.id}_g${g.id}`,
|
|
141
|
+
source: `driver_${f.id}`,
|
|
142
142
|
target: `goal_${g.id}`,
|
|
143
143
|
markerEnd: { type: MarkerType.ArrowClosed },
|
|
144
144
|
type: "smoothstep",
|
package/src/fgca/nodeTypes.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import
|
|
1
|
+
import FGCADriverNode from "./nodes/FGCAFactorNode";
|
|
2
2
|
import FGCAGoalNode from "./nodes/FGCAGoalNode";
|
|
3
3
|
import FGCAChangeNode from "./nodes/FGCAChangeNode";
|
|
4
4
|
import FGCAActivityNode from "./nodes/FGCAActivityNode";
|
|
5
5
|
|
|
6
6
|
export const FGCA_NODE_TYPES = {
|
|
7
|
-
|
|
7
|
+
fgcaDriver: FGCADriverNode,
|
|
8
8
|
fgcaGoal: FGCAGoalNode,
|
|
9
9
|
fgcaChange: FGCAChangeNode,
|
|
10
10
|
fgcaActivity: FGCAActivityNode,
|
|
11
|
-
} as const;
|
|
11
|
+
} as const;
|
|
@@ -4,7 +4,7 @@ import { Handle, Position } from "reactflow";
|
|
|
4
4
|
const NODE_WIDTH = 250;
|
|
5
5
|
const NODE_HEIGHT = 80;
|
|
6
6
|
|
|
7
|
-
export interface
|
|
7
|
+
export interface FGCADriverNodeProps {
|
|
8
8
|
data: {
|
|
9
9
|
id: number;
|
|
10
10
|
name: string;
|
|
@@ -14,10 +14,10 @@ export interface FGCAFactorNodeProps {
|
|
|
14
14
|
isConnectable?: boolean;
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
const
|
|
17
|
+
const FGCADriverNode = memo(({ data, isConnectable }: FGCADriverNodeProps) => (
|
|
18
18
|
<div
|
|
19
19
|
style={{
|
|
20
|
-
background: "var(--ts-layer-
|
|
20
|
+
background: "var(--ts-layer-driver)",
|
|
21
21
|
width: NODE_WIDTH,
|
|
22
22
|
height: NODE_HEIGHT,
|
|
23
23
|
padding: "6px 8px",
|
|
@@ -54,11 +54,11 @@ const FGCAFactorNode = memo(({ data, isConnectable }: FGCAFactorNodeProps) => (
|
|
|
54
54
|
{data.name}
|
|
55
55
|
</div>
|
|
56
56
|
<div style={{ fontSize: "10px", color: "var(--ts-text-secondary)", marginTop: 2 }}>
|
|
57
|
-
|
|
57
|
+
D-{String(data.id).padStart(4, "0")}
|
|
58
58
|
</div>
|
|
59
59
|
</div>
|
|
60
60
|
));
|
|
61
61
|
|
|
62
|
-
|
|
62
|
+
FGCADriverNode.displayName = "FGCADriverNode";
|
|
63
63
|
|
|
64
|
-
export default
|
|
64
|
+
export default FGCADriverNode;
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
import type {
|
|
28
28
|
ActivityItem,
|
|
29
29
|
BdnChangeWithActivities,
|
|
30
|
-
|
|
30
|
+
DriverItem,
|
|
31
31
|
GoalItem,
|
|
32
32
|
} from './types.js';
|
|
33
33
|
import type { FGCADoc } from './validate.js';
|
|
@@ -46,10 +46,12 @@ export interface CanonicalFGCAResult extends ValidationResult {
|
|
|
46
46
|
// is fixed per layer; middle segments are optional; the terminal is a
|
|
47
47
|
// positive integer with no leading zeros.
|
|
48
48
|
const FACTOR_ID_RE = /^FACTOR(-[A-Z0-9][A-Z0-9_]*)*-\d+$/;
|
|
49
|
+
const DRIVER_ID_RE = /^DRIVER(-[A-Z0-9][A-Z0-9_]*)*-\d+$/;
|
|
50
|
+
const FACTOR_OR_DRIVER_ID_RE = /^(FACTOR|DRIVER)(-[A-Z0-9][A-Z0-9_]*)*-\d+$/;
|
|
49
51
|
const GOAL_ID_RE = /^GOAL(-[A-Z0-9][A-Z0-9_]*)*-\d+$/;
|
|
50
52
|
const CHANGE_ID_RE = /^CHANGE(-[A-Z0-9][A-Z0-9_]*)*-\d+$/;
|
|
51
53
|
const ACTIVITY_ID_RE = /^ACTIVITY(-[A-Z0-9][A-Z0-9_]*)*-\d+$/;
|
|
52
|
-
const FGCA_DOC_ID_RE = /^FGCA(-[A-Z0-9][A-Z0-9_]*)*-\d+$/;
|
|
54
|
+
const FGCA_DOC_ID_RE = /^(FGCA|DGCA)(-[A-Z0-9][A-Z0-9_]*)*-\d+$/;
|
|
53
55
|
const CONSTRAINT_ID_RE = /^CONSTRAINT(-[A-Z0-9][A-Z0-9_]*)*-\d+$/;
|
|
54
56
|
|
|
55
57
|
function isNonEmptyString(v: unknown): v is string {
|
|
@@ -84,18 +86,21 @@ export function parseCanonicalFGCA(input: unknown): CanonicalFGCAResult {
|
|
|
84
86
|
|
|
85
87
|
const raw = input as Record<string, unknown>;
|
|
86
88
|
|
|
87
|
-
if ('notation' in raw && raw['notation'] !== 'fgca') {
|
|
89
|
+
if ('notation' in raw && raw['notation'] !== 'fgca' && raw['notation'] !== 'dgca') {
|
|
88
90
|
return {
|
|
89
91
|
valid: false,
|
|
90
92
|
errors: [
|
|
91
93
|
{
|
|
92
94
|
code: 'FGCA-001',
|
|
93
|
-
message: `notation must be "fgca", got "${String(raw['notation'])}"`,
|
|
95
|
+
message: `notation must be "dgca" (or legacy "fgca"), got "${String(raw['notation'])}"`,
|
|
94
96
|
},
|
|
95
97
|
],
|
|
96
98
|
warnings,
|
|
97
99
|
};
|
|
98
100
|
}
|
|
101
|
+
if ('notation' in raw && raw['notation'] === 'fgca') {
|
|
102
|
+
warnings.push({ code: 'FGCA-001', message: 'notation "fgca" is deprecated — rename to "dgca"' });
|
|
103
|
+
}
|
|
99
104
|
|
|
100
105
|
// FGCA-002 — document id (optional in v1.4 per the canonical spec? — spec
|
|
101
106
|
// says required; absence is FGCA-002).
|
|
@@ -117,12 +122,16 @@ export function parseCanonicalFGCA(input: unknown): CanonicalFGCAResult {
|
|
|
117
122
|
const factorsRaw = asObjectArray(raw['factors']);
|
|
118
123
|
const goalsRaw = asObjectArray(raw['goals']);
|
|
119
124
|
const changesRaw = asObjectArray(raw['changes']);
|
|
120
|
-
|
|
125
|
+
// Accept canonical `actions:` or deprecated `activities:`; warn on the latter.
|
|
126
|
+
const activitiesRaw = asObjectArray(raw['actions']) ?? asObjectArray(raw['activities']);
|
|
127
|
+
if ('activities' in raw && !('actions' in raw)) {
|
|
128
|
+
warnings.push({ code: 'FGCA-001', message: '"activities" key is deprecated — rename to "actions"' });
|
|
129
|
+
}
|
|
121
130
|
|
|
122
131
|
if (factorsRaw === null) errors.push({ code: 'FGCA-004', message: 'factors must be an array', path: 'factors' });
|
|
123
132
|
if (goalsRaw === null) errors.push({ code: 'FGCA-004', message: 'goals must be an array', path: 'goals' });
|
|
124
133
|
if (changesRaw === null) errors.push({ code: 'FGCA-004', message: 'changes must be an array', path: 'changes' });
|
|
125
|
-
if (activitiesRaw === null) errors.push({ code: 'FGCA-004', message: '
|
|
134
|
+
if (activitiesRaw === null) errors.push({ code: 'FGCA-004', message: 'actions must be an array', path: 'actions' });
|
|
126
135
|
|
|
127
136
|
if (errors.length > 0) return { valid: false, errors, warnings };
|
|
128
137
|
|
|
@@ -173,7 +182,7 @@ export function parseCanonicalFGCA(input: unknown): CanonicalFGCAResult {
|
|
|
173
182
|
return { id, name: isNonEmptyString(name) ? name : '' };
|
|
174
183
|
}
|
|
175
184
|
|
|
176
|
-
factors.forEach((el, i) => checkLayerElement(el, `factors[${i}]`,
|
|
185
|
+
factors.forEach((el, i) => checkLayerElement(el, `factors[${i}]`, FACTOR_OR_DRIVER_ID_RE, factorIds));
|
|
177
186
|
goals.forEach((el, i) => checkLayerElement(el, `goals[${i}]`, GOAL_ID_RE, goalIds));
|
|
178
187
|
changes.forEach((el, i) => checkLayerElement(el, `changes[${i}]`, CHANGE_ID_RE, changeIds));
|
|
179
188
|
activities.forEach((el, i) => checkLayerElement(el, `activities[${i}]`, ACTIVITY_ID_RE, activityIds));
|
|
@@ -229,13 +238,13 @@ export function parseCanonicalFGCA(input: unknown): CanonicalFGCAResult {
|
|
|
229
238
|
}
|
|
230
239
|
|
|
231
240
|
// Layer entries (internal form).
|
|
232
|
-
const internalFactors:
|
|
241
|
+
const internalFactors: DriverItem[] = factors.map((el) => ({
|
|
233
242
|
id: intId(String(el!['id'])),
|
|
234
243
|
name: String(el!['name'] ?? ''),
|
|
235
244
|
}));
|
|
236
245
|
|
|
237
246
|
const internalGoals: GoalItem[] = goals.map((el, i) => {
|
|
238
|
-
const refIds = checkRefArray(el!, 'factors', factorIds,
|
|
247
|
+
const refIds = checkRefArray(el!, 'factors', factorIds, FACTOR_OR_DRIVER_ID_RE, 'FGCA-008', `goals[${i}]`);
|
|
239
248
|
return {
|
|
240
249
|
id: intId(String(el!['id'])),
|
|
241
250
|
name: String(el!['name'] ?? ''),
|
|
@@ -283,11 +292,13 @@ export function parseCanonicalFGCA(input: unknown): CanonicalFGCAResult {
|
|
|
283
292
|
});
|
|
284
293
|
|
|
285
294
|
const internalActivities: ActivityItem[] = activities.map((el, i) => {
|
|
286
|
-
const goalRefs = checkRefArray(el!, 'goals', goalIds, GOAL_ID_RE, 'FGCA-011', `
|
|
295
|
+
const goalRefs = checkRefArray(el!, 'goals', goalIds, GOAL_ID_RE, 'FGCA-011', `actions[${i}]`);
|
|
296
|
+
const typeVal = typeof el!['type'] === 'string' ? el!['type'] : undefined;
|
|
287
297
|
return {
|
|
288
298
|
id: intId(String(el!['id'])),
|
|
289
299
|
name: String(el!['name'] ?? ''),
|
|
290
300
|
goal_id: goalRefs.length > 0 ? intId(goalRefs[0]) : null,
|
|
301
|
+
...(typeVal !== undefined ? { type: typeVal } : {}),
|
|
291
302
|
};
|
|
292
303
|
});
|
|
293
304
|
|
|
@@ -313,7 +324,7 @@ export function parseCanonicalFGCA(input: unknown): CanonicalFGCAResult {
|
|
|
313
324
|
if (errors.length > 0) return { valid: false, errors, warnings };
|
|
314
325
|
|
|
315
326
|
const parsed: FGCADoc = {
|
|
316
|
-
notation: '
|
|
327
|
+
notation: (raw['notation'] as string) ?? 'dgca',
|
|
317
328
|
spec_version: typeof raw['spec_version'] === 'string' ? (raw['spec_version'] as string) : undefined,
|
|
318
329
|
factors: internalFactors,
|
|
319
330
|
goals: internalGoals,
|
|
@@ -324,7 +335,7 @@ export function parseCanonicalFGCA(input: unknown): CanonicalFGCAResult {
|
|
|
324
335
|
return { valid: true, errors, warnings, parsed };
|
|
325
336
|
}
|
|
326
337
|
|
|
327
|
-
const FGA_DOC_ID_RE = /^FGA(-[A-Z0-9][A-Z0-9_]*)*-\d+$/;
|
|
338
|
+
const FGA_DOC_ID_RE = /^(FGA|DGA)(-[A-Z0-9][A-Z0-9_]*)*-\d+$/;
|
|
328
339
|
|
|
329
340
|
/** On success, the internal-form FGCADoc derived from canonical FGA input. */
|
|
330
341
|
export interface CanonicalFGAResult extends ValidationResult {
|
|
@@ -353,10 +364,10 @@ export function parseCanonicalFGA(input: unknown): CanonicalFGAResult {
|
|
|
353
364
|
return { valid: false, errors: [{ code: 'FGA-001', message: 'document root is not an object' }], warnings: [] };
|
|
354
365
|
}
|
|
355
366
|
const raw = input as Record<string, unknown>;
|
|
356
|
-
if ('notation' in raw && raw['notation'] !== 'fga') {
|
|
367
|
+
if ('notation' in raw && raw['notation'] !== 'fga' && raw['notation'] !== 'dga') {
|
|
357
368
|
return {
|
|
358
369
|
valid: false,
|
|
359
|
-
errors: [{ code: 'FGA-001', message: `notation must be "fga", got "${String(raw['notation'])}"` }],
|
|
370
|
+
errors: [{ code: 'FGA-001', message: `notation must be "dga" (or legacy "fga"), got "${String(raw['notation'])}"` }],
|
|
360
371
|
warnings: [],
|
|
361
372
|
};
|
|
362
373
|
}
|
|
@@ -375,7 +386,7 @@ export function parseCanonicalFGA(input: unknown): CanonicalFGAResult {
|
|
|
375
386
|
// changes. Per-layer / per-ref checks all reuse the FGCA implementation;
|
|
376
387
|
// codes are remapped on the way out. FGCA-009 / 010 / 014 (changes-related)
|
|
377
388
|
// are unreachable here because `changes` is empty.
|
|
378
|
-
const synth = { ...raw, notation: '
|
|
389
|
+
const synth = { ...raw, notation: 'dgca', id: 'DGCA-FROM-DGA-1', changes: [] };
|
|
379
390
|
const r = parseCanonicalFGCA(synth);
|
|
380
391
|
const remap: Record<string, string> = {
|
|
381
392
|
'FGCA-001': 'FGA-001',
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
|
|
10
10
|
import type { Scope } from '../scope.js';
|
|
11
11
|
|
|
12
|
-
export type FGCAPreviewColumn = '
|
|
12
|
+
export type FGCAPreviewColumn = 'driver' | 'goal' | 'change' | 'activity';
|
|
13
13
|
|
|
14
14
|
export interface FGCAPreviewFactor {
|
|
15
15
|
id: number | string;
|
|
@@ -144,11 +144,11 @@ export function layoutFGCAPreview(
|
|
|
144
144
|
|
|
145
145
|
const colStride = FGCA_NODE_W + colGap;
|
|
146
146
|
const cols: FGCAPreviewColumn[] = hideChanges
|
|
147
|
-
? ['
|
|
148
|
-
: ['
|
|
147
|
+
? ['driver', 'goal', 'activity']
|
|
148
|
+
: ['driver', 'goal', 'change', 'activity'];
|
|
149
149
|
const changes = doc.changes ?? [];
|
|
150
150
|
const colItems: Record<FGCAPreviewColumn, Array<{ id: string; label: string }>> = {
|
|
151
|
-
|
|
151
|
+
driver: doc.factors.map(f => ({ id: `driver_${f.id}`, label: f.name })),
|
|
152
152
|
goal: doc.goals.map(g => ({ id: `goal_${g.id}`, label: g.name })),
|
|
153
153
|
change: changes.map(c => ({ id: `change_${c.id}`, label: c.name })),
|
|
154
154
|
activity: doc.activities.map(a => ({ id: `activity_${a.id}`, label: a.name })),
|
|
@@ -180,7 +180,7 @@ export function layoutFGCAPreview(
|
|
|
180
180
|
}
|
|
181
181
|
|
|
182
182
|
for (const g of doc.goals) {
|
|
183
|
-
for (const f of (g.factor ?? [])) addEdge(`
|
|
183
|
+
for (const f of (g.factor ?? [])) addEdge(`driver_${f.id}`, `goal_${g.id}`);
|
|
184
184
|
}
|
|
185
185
|
if (hideChanges) {
|
|
186
186
|
const connectedViaChange = new Set<number | string>();
|
package/src/fgca/resolver.ts
CHANGED
|
@@ -86,7 +86,9 @@ export function resolveFGCA(
|
|
|
86
86
|
const changesConf = isObject(vc['changes']) ? vc['changes'] : {};
|
|
87
87
|
const activitiesConf = isObject(vc['activities']) ? vc['activities'] : {};
|
|
88
88
|
|
|
89
|
-
const
|
|
89
|
+
const factorElemsLegacy = collectByNotation(sources.elements, 'factor');
|
|
90
|
+
const factorElemsNew = collectByNotation(sources.elements, 'driver');
|
|
91
|
+
const factorElems = new Map([...factorElemsLegacy, ...factorElemsNew]);
|
|
90
92
|
const goalElems = collectByNotation(sources.elements, 'goal');
|
|
91
93
|
const changeElems = collectByNotation(sources.elements, 'change');
|
|
92
94
|
const activityElems = collectByNotation(sources.elements, 'activity');
|
package/src/fgca/types.ts
CHANGED
|
@@ -1,32 +1,34 @@
|
|
|
1
|
-
export interface
|
|
2
|
-
id: number;
|
|
1
|
+
export interface DriverItem {
|
|
2
|
+
id: number | string;
|
|
3
3
|
name: string;
|
|
4
4
|
}
|
|
5
5
|
|
|
6
6
|
export interface GoalItem {
|
|
7
|
-
id: number;
|
|
7
|
+
id: number | string;
|
|
8
8
|
name: string;
|
|
9
9
|
level?: number;
|
|
10
10
|
/** Goals may carry embedded factor links returned by the API. */
|
|
11
|
-
factor?: Array<{ id: number }>;
|
|
11
|
+
factor?: Array<{ id: number | string }>;
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
export interface BdnChangeWithActivities {
|
|
15
|
-
id: number;
|
|
15
|
+
id: number | string;
|
|
16
16
|
name: string;
|
|
17
|
-
goal_id: number;
|
|
18
|
-
activity_ids: number
|
|
17
|
+
goal_id: number | string;
|
|
18
|
+
activity_ids: Array<number | string>;
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
export interface ActivityItem {
|
|
22
|
-
id: number;
|
|
22
|
+
id: number | string;
|
|
23
23
|
name: string;
|
|
24
|
-
goal_id?: number | null;
|
|
24
|
+
goal_id?: number | string | null;
|
|
25
25
|
activity_type_id?: number;
|
|
26
|
+
/** Canonical values: initiative | programme | project | work_package. Unknown values pass through without error. */
|
|
27
|
+
type?: string;
|
|
26
28
|
}
|
|
27
29
|
|
|
28
30
|
export interface ActivityTypeItem {
|
|
29
|
-
id: number;
|
|
31
|
+
id: number | string;
|
|
30
32
|
name?: string;
|
|
31
33
|
}
|
|
32
34
|
|
|
@@ -38,12 +40,12 @@ export interface DiagramStyle {
|
|
|
38
40
|
}
|
|
39
41
|
|
|
40
42
|
/** The four columns of the FGCA diagram. */
|
|
41
|
-
export type FGCAColumn = "
|
|
43
|
+
export type FGCAColumn = "driver" | "goal" | "change" | "activity";
|
|
42
44
|
|
|
43
|
-
export const ALL_FGCA_COLUMNS: FGCAColumn[] = ["
|
|
45
|
+
export const ALL_FGCA_COLUMNS: FGCAColumn[] = ["driver", "goal", "change", "activity"];
|
|
44
46
|
|
|
45
47
|
export const FGCA_COLUMN_LABELS: Record<FGCAColumn, string> = {
|
|
46
|
-
|
|
48
|
+
driver: "D",
|
|
47
49
|
goal: "G",
|
|
48
50
|
change: "C",
|
|
49
51
|
activity: "A",
|
package/src/fgca/validate.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { DriverItem, GoalItem, BdnChangeWithActivities, ActivityItem } from './types.js';
|
|
2
2
|
import type {
|
|
3
3
|
ValidationError,
|
|
4
4
|
ValidationWarning,
|
|
@@ -15,7 +15,7 @@ export type FGCAValidationResult = ValidationResult;
|
|
|
15
15
|
export interface FGCADoc {
|
|
16
16
|
notation: string;
|
|
17
17
|
spec_version?: string;
|
|
18
|
-
factors:
|
|
18
|
+
factors: DriverItem[];
|
|
19
19
|
goals: GoalItem[];
|
|
20
20
|
changes: BdnChangeWithActivities[];
|
|
21
21
|
activities: ActivityItem[];
|
|
@@ -35,31 +35,42 @@ export function validateFGCADoc(input: unknown): FGCAValidationResult {
|
|
|
35
35
|
errors.push({ code: 'MISSING_NOTATION', message: 'notation field is required' });
|
|
36
36
|
return { valid: false, errors, warnings };
|
|
37
37
|
}
|
|
38
|
-
if (raw.notation !== 'fgca') {
|
|
39
|
-
errors.push({ code: 'WRONG_NOTATION', message: `notation must be "fgca", got "${String(raw.notation)}"` });
|
|
38
|
+
if (raw.notation !== 'fgca' && raw.notation !== 'dgca') {
|
|
39
|
+
errors.push({ code: 'WRONG_NOTATION', message: `notation must be "dgca" (or legacy "fgca"), got "${String(raw.notation)}"` });
|
|
40
40
|
return { valid: false, errors, warnings };
|
|
41
41
|
}
|
|
42
|
+
if (raw.notation === 'fgca') {
|
|
43
|
+
warnings.push({ code: 'DEPRECATED_NOTATION', message: 'notation "fgca" is deprecated — rename to "dgca"' });
|
|
44
|
+
}
|
|
42
45
|
|
|
43
46
|
if (!Array.isArray(raw.factors)) errors.push({ code: 'SCHEMA_INVALID', message: 'factors must be an array', path: 'factors' });
|
|
44
47
|
if (!Array.isArray(raw.goals)) errors.push({ code: 'SCHEMA_INVALID', message: 'goals must be an array', path: 'goals' });
|
|
45
48
|
if (!Array.isArray(raw.changes)) errors.push({ code: 'SCHEMA_INVALID', message: 'changes must be an array', path: 'changes' });
|
|
46
|
-
|
|
49
|
+
// Accept canonical `actions:` or deprecated `activities:`; warn on the latter.
|
|
50
|
+
const hasActions = Array.isArray(raw.actions);
|
|
51
|
+
const hasActivities = Array.isArray(raw.activities);
|
|
52
|
+
if (!hasActions && !hasActivities) {
|
|
53
|
+
errors.push({ code: 'SCHEMA_INVALID', message: 'actions must be an array', path: 'actions' });
|
|
54
|
+
} else if ('activities' in raw) {
|
|
55
|
+
warnings.push({ code: 'DEPRECATED_NOTATION', message: '"activities" key is deprecated — rename to "actions"' });
|
|
56
|
+
}
|
|
47
57
|
if (errors.length > 0) return { valid: false, errors, warnings };
|
|
48
58
|
|
|
59
|
+
const actionsArr = (hasActions ? raw.actions : raw.activities) as unknown[];
|
|
49
60
|
const doc = raw as unknown as FGCADoc;
|
|
50
|
-
const collectIds = (arr: unknown[]): Set<number> => {
|
|
51
|
-
const out = new Set<number>();
|
|
61
|
+
const collectIds = (arr: unknown[]): Set<number | string> => {
|
|
62
|
+
const out = new Set<number | string>();
|
|
52
63
|
for (const el of arr) {
|
|
53
64
|
if (el && typeof el === 'object') {
|
|
54
65
|
const id = (el as { id?: unknown }).id;
|
|
55
|
-
if (typeof id === 'number') out.add(id);
|
|
66
|
+
if (typeof id === 'number' || typeof id === 'string') out.add(id);
|
|
56
67
|
}
|
|
57
68
|
}
|
|
58
69
|
return out;
|
|
59
70
|
};
|
|
60
71
|
const factorIds = collectIds(doc.factors as unknown as unknown[]);
|
|
61
72
|
const goalIds = collectIds(doc.goals as unknown as unknown[]);
|
|
62
|
-
const activityIds = collectIds(
|
|
73
|
+
const activityIds = collectIds(actionsArr);
|
|
63
74
|
|
|
64
75
|
for (let i = 0; i < doc.factors.length; i++) {
|
|
65
76
|
const f = doc.factors[i] as unknown;
|
|
@@ -68,7 +79,7 @@ export function validateFGCADoc(input: unknown): FGCAValidationResult {
|
|
|
68
79
|
continue;
|
|
69
80
|
}
|
|
70
81
|
const factor = f as { id?: unknown; name?: unknown };
|
|
71
|
-
if (typeof factor.id !== 'number') errors.push({ code: 'SCHEMA_INVALID', message: 'factor id must be a number', path: `factors[${i}]` });
|
|
82
|
+
if (typeof factor.id !== 'number' && typeof factor.id !== 'string') errors.push({ code: 'SCHEMA_INVALID', message: 'factor id must be a number or string', path: `factors[${i}]` });
|
|
72
83
|
if (typeof factor.name !== 'string' || !factor.name.trim()) errors.push({ code: 'EMPTY_NAME', message: `Factor ${String(factor.id)} has empty name`, path: `factors[${i}]` });
|
|
73
84
|
}
|
|
74
85
|
|
|
@@ -79,13 +90,13 @@ export function validateFGCADoc(input: unknown): FGCAValidationResult {
|
|
|
79
90
|
continue;
|
|
80
91
|
}
|
|
81
92
|
const goal = g as { id?: unknown; name?: unknown; factor?: unknown };
|
|
82
|
-
if (typeof goal.id !== 'number') errors.push({ code: 'SCHEMA_INVALID', message: 'goal id must be a number', path: `goals[${i}]` });
|
|
93
|
+
if (typeof goal.id !== 'number' && typeof goal.id !== 'string') errors.push({ code: 'SCHEMA_INVALID', message: 'goal id must be a number or string', path: `goals[${i}]` });
|
|
83
94
|
if (typeof goal.name !== 'string' || !goal.name.trim()) errors.push({ code: 'EMPTY_NAME', message: `Goal ${String(goal.id)} has empty name`, path: `goals[${i}]` });
|
|
84
95
|
const factorRefs = Array.isArray(goal.factor) ? (goal.factor as unknown[]) : [];
|
|
85
96
|
for (const fr of factorRefs) {
|
|
86
97
|
if (!fr || typeof fr !== 'object') continue;
|
|
87
98
|
const fid = (fr as { id?: unknown }).id;
|
|
88
|
-
if (typeof fid === 'number' && !factorIds.has(fid)) {
|
|
99
|
+
if ((typeof fid === 'number' || typeof fid === 'string') && !factorIds.has(fid)) {
|
|
89
100
|
warnings.push({ code: 'BROKEN_REF', message: `Goal ${String(goal.id)} references missing factor ${fid}`, path: `goals[${i}].factor` });
|
|
90
101
|
}
|
|
91
102
|
}
|
|
@@ -98,28 +109,28 @@ export function validateFGCADoc(input: unknown): FGCAValidationResult {
|
|
|
98
109
|
continue;
|
|
99
110
|
}
|
|
100
111
|
const change = c as { id?: unknown; name?: unknown; goal_id?: unknown; activity_ids?: unknown };
|
|
101
|
-
if (typeof change.id !== 'number') errors.push({ code: 'SCHEMA_INVALID', message: 'change id must be a number', path: `changes[${i}]` });
|
|
112
|
+
if (typeof change.id !== 'number' && typeof change.id !== 'string') errors.push({ code: 'SCHEMA_INVALID', message: 'change id must be a number or string', path: `changes[${i}]` });
|
|
102
113
|
if (typeof change.name !== 'string' || !change.name.trim()) errors.push({ code: 'EMPTY_NAME', message: `Change ${String(change.id)} has empty name`, path: `changes[${i}]` });
|
|
103
|
-
if (typeof change.goal_id === 'number' && !goalIds.has(change.goal_id)) {
|
|
114
|
+
if ((typeof change.goal_id === 'number' || typeof change.goal_id === 'string') && !goalIds.has(change.goal_id)) {
|
|
104
115
|
warnings.push({ code: 'BROKEN_REF', message: `Change ${String(change.id)} references missing goal ${change.goal_id}`, path: `changes[${i}].goal_id` });
|
|
105
116
|
}
|
|
106
117
|
const aids = Array.isArray(change.activity_ids) ? (change.activity_ids as unknown[]) : [];
|
|
107
118
|
for (const aid of aids) {
|
|
108
|
-
if (typeof aid === 'number' && !activityIds.has(aid)) {
|
|
119
|
+
if ((typeof aid === 'number' || typeof aid === 'string') && !activityIds.has(aid)) {
|
|
109
120
|
warnings.push({ code: 'BROKEN_REF', message: `Change ${String(change.id)} references missing activity ${aid}`, path: `changes[${i}].activity_ids` });
|
|
110
121
|
}
|
|
111
122
|
}
|
|
112
123
|
}
|
|
113
124
|
|
|
114
|
-
for (let i = 0; i <
|
|
115
|
-
const a =
|
|
125
|
+
for (let i = 0; i < actionsArr.length; i++) {
|
|
126
|
+
const a = actionsArr[i];
|
|
116
127
|
if (!a || typeof a !== 'object') {
|
|
117
|
-
errors.push({ code: 'SCHEMA_INVALID', message: '
|
|
128
|
+
errors.push({ code: 'SCHEMA_INVALID', message: 'action entry must be an object', path: `actions[${i}]` });
|
|
118
129
|
continue;
|
|
119
130
|
}
|
|
120
|
-
const
|
|
121
|
-
if (typeof
|
|
122
|
-
if (typeof
|
|
131
|
+
const action = a as { id?: unknown; name?: unknown };
|
|
132
|
+
if (typeof action.id !== 'number' && typeof action.id !== 'string') errors.push({ code: 'SCHEMA_INVALID', message: 'action id must be a number or string', path: `actions[${i}]` });
|
|
133
|
+
if (typeof action.name !== 'string' || !action.name.trim()) errors.push({ code: 'EMPTY_NAME', message: `Action ${String(action.id)} has empty name`, path: `actions[${i}]` });
|
|
123
134
|
}
|
|
124
135
|
|
|
125
136
|
return { valid: errors.length === 0, errors, warnings };
|