( currentState: WorkflowState, previousState: WorkflowState | null )
| 71 | * Generate a detailed diff summary between two workflow states |
| 72 | */ |
| 73 | export function generateWorkflowDiffSummary( |
| 74 | currentState: WorkflowState, |
| 75 | previousState: WorkflowState | null |
| 76 | ): WorkflowDiffSummary { |
| 77 | const result: WorkflowDiffSummary = { |
| 78 | addedBlocks: [], |
| 79 | removedBlocks: [], |
| 80 | modifiedBlocks: [], |
| 81 | edgeChanges: { added: 0, removed: 0, addedDetails: [], removedDetails: [] }, |
| 82 | loopChanges: { added: 0, removed: 0, modified: 0 }, |
| 83 | parallelChanges: { added: 0, removed: 0, modified: 0 }, |
| 84 | variableChanges: { |
| 85 | added: 0, |
| 86 | removed: 0, |
| 87 | modified: 0, |
| 88 | addedNames: [], |
| 89 | removedNames: [], |
| 90 | modifiedNames: [], |
| 91 | }, |
| 92 | hasChanges: false, |
| 93 | } |
| 94 | |
| 95 | if (!previousState) { |
| 96 | const currentBlocks = currentState.blocks || {} |
| 97 | for (const [id, block] of Object.entries(currentBlocks)) { |
| 98 | result.addedBlocks.push({ |
| 99 | id, |
| 100 | type: block.type, |
| 101 | name: block.name, |
| 102 | }) |
| 103 | } |
| 104 | |
| 105 | const edges = currentState.edges || [] |
| 106 | result.edgeChanges.added = edges.length |
| 107 | for (const edge of edges) { |
| 108 | const sourceBlock = currentBlocks[edge.source] |
| 109 | const targetBlock = currentBlocks[edge.target] |
| 110 | result.edgeChanges.addedDetails.push({ |
| 111 | sourceName: sourceBlock?.name || sourceBlock?.type || edge.source, |
| 112 | targetName: targetBlock?.name || targetBlock?.type || edge.target, |
| 113 | }) |
| 114 | } |
| 115 | |
| 116 | result.loopChanges.added = Object.keys(currentState.loops || {}).length |
| 117 | result.parallelChanges.added = Object.keys(currentState.parallels || {}).length |
| 118 | |
| 119 | const variables = currentState.variables || {} |
| 120 | const varEntries = Object.entries(variables) |
| 121 | result.variableChanges.added = varEntries.length |
| 122 | for (const [id, variable] of varEntries) { |
| 123 | result.variableChanges.addedNames.push((variable as { name?: string }).name || id) |
| 124 | } |
| 125 | |
| 126 | result.hasChanges = true |
| 127 | return result |
| 128 | } |
| 129 | |
| 130 | const currentBlocks = currentState.blocks || {} |
no test coverage detected