(
nodes: IReactFlowNode[],
edges: IReactFlowEdge[],
componentNodes: IComponentNodes
)
| 19 | * Operates on already-parsed nodes/edges — no DB or network access. |
| 20 | */ |
| 21 | export const validateFlowData = ( |
| 22 | nodes: IReactFlowNode[], |
| 23 | edges: IReactFlowEdge[], |
| 24 | componentNodes: IComponentNodes |
| 25 | ): IValidationResult[] => { |
| 26 | const validationResults: IValidationResult[] = [] |
| 27 | |
| 28 | // Create a map of connected nodes |
| 29 | const connectedNodes = new Set<string>() |
| 30 | edges.forEach((edge: IReactFlowEdge) => { |
| 31 | connectedNodes.add(edge.source) |
| 32 | connectedNodes.add(edge.target) |
| 33 | }) |
| 34 | |
| 35 | // Validate each node |
| 36 | for (const node of nodes) { |
| 37 | if (node.data.name === 'stickyNoteAgentflow') continue |
| 38 | |
| 39 | const nodeIssues: string[] = [] |
| 40 | |
| 41 | // Check if node is connected |
| 42 | if (!connectedNodes.has(node.id)) { |
| 43 | nodeIssues.push('This node is not connected to anything') |
| 44 | } |
| 45 | |
| 46 | // Validate input parameters |
| 47 | if (node.data && node.data.inputParams && node.data.inputs) { |
| 48 | for (const param of node.data.inputParams) { |
| 49 | // Skip validation if the parameter has show condition that doesn't match |
| 50 | if (param.show) { |
| 51 | let shouldShow = true |
| 52 | for (const [key, value] of Object.entries(param.show)) { |
| 53 | if (node.data.inputs[key] !== value) { |
| 54 | shouldShow = false |
| 55 | break |
| 56 | } |
| 57 | } |
| 58 | if (!shouldShow) continue |
| 59 | } |
| 60 | |
| 61 | // Skip validation if the parameter has hide condition that matches |
| 62 | if (param.hide) { |
| 63 | let shouldHide = true |
| 64 | for (const [key, value] of Object.entries(param.hide)) { |
| 65 | if (node.data.inputs[key] !== value) { |
| 66 | shouldHide = false |
| 67 | break |
| 68 | } |
| 69 | } |
| 70 | if (shouldHide) continue |
| 71 | } |
| 72 | |
| 73 | // Check if required parameter has a value |
| 74 | if (!param.optional) { |
| 75 | const inputValue = node.data.inputs[param.name] |
| 76 | if (inputValue === undefined || inputValue === null || inputValue === '') { |
| 77 | nodeIssues.push(`${param.label} is required`) |
| 78 | } |
no test coverage detected