(
baseline: { nodes: WorkflowNode[]; edges: WorkflowEdge[] },
next: { nodes: WorkflowNode[]; edges: WorkflowEdge[] }
)
| 86 | } |
| 87 | |
| 88 | export function diffWorkflowGraphs( |
| 89 | baseline: { nodes: WorkflowNode[]; edges: WorkflowEdge[] }, |
| 90 | next: { nodes: WorkflowNode[]; edges: WorkflowEdge[] } |
| 91 | ): WorkflowDiffSummary { |
| 92 | const baseNodes = new Map((baseline.nodes ?? []).map((n) => [n.id, n])); |
| 93 | const nextNodes = new Map((next.nodes ?? []).map((n) => [n.id, n])); |
| 94 | |
| 95 | const nodeChanges: DiffItem[] = []; |
| 96 | for (const [id, node] of nextNodes) { |
| 97 | const before = baseNodes.get(id); |
| 98 | if (!before) { |
| 99 | nodeChanges.push({ kind: 'added', id }); |
| 100 | continue; |
| 101 | } |
| 102 | const fields = diffNodeFields(before, node); |
| 103 | if (fields.length) nodeChanges.push({ kind: 'updated', id, fields }); |
| 104 | } |
| 105 | for (const [id] of baseNodes) { |
| 106 | if (!nextNodes.has(id)) nodeChanges.push({ kind: 'deleted', id }); |
| 107 | } |
| 108 | |
| 109 | const baseEdges = new Map((baseline.edges ?? []).map((e) => [e.id, e])); |
| 110 | const nextEdges = new Map((next.edges ?? []).map((e) => [e.id, e])); |
| 111 | |
| 112 | const edgeChanges: DiffItem[] = []; |
| 113 | for (const [id, edge] of nextEdges) { |
| 114 | const before = baseEdges.get(id); |
| 115 | if (!before) { |
| 116 | edgeChanges.push({ kind: 'added', id }); |
| 117 | continue; |
| 118 | } |
| 119 | const fields = diffEdgeFields(before, edge); |
| 120 | if (fields.length) edgeChanges.push({ kind: 'updated', id, fields }); |
| 121 | } |
| 122 | for (const [id] of baseEdges) { |
| 123 | if (!nextEdges.has(id)) edgeChanges.push({ kind: 'deleted', id }); |
| 124 | } |
| 125 | |
| 126 | const count = (items: DiffItem[], kind: DiffKind) => items.filter((i) => i.kind === kind).length; |
| 127 | |
| 128 | return { |
| 129 | nodes: { |
| 130 | added: count(nodeChanges, 'added'), |
| 131 | deleted: count(nodeChanges, 'deleted'), |
| 132 | updated: count(nodeChanges, 'updated'), |
| 133 | }, |
| 134 | edges: { |
| 135 | added: count(edgeChanges, 'added'), |
| 136 | deleted: count(edgeChanges, 'deleted'), |
| 137 | updated: count(edgeChanges, 'updated'), |
| 138 | }, |
| 139 | nodeChanges, |
| 140 | edgeChanges, |
| 141 | }; |
| 142 | } |
no test coverage detected