* Detect if a connection would create a cycle
(newConnection: Connection, existingEdges: Edge[])
| 174 | * Detect if a connection would create a cycle |
| 175 | */ |
| 176 | function wouldCreateCycle(newConnection: Connection, existingEdges: Edge[]): boolean { |
| 177 | const { source, target } = newConnection; |
| 178 | |
| 179 | if (!source || !target) return false; |
| 180 | |
| 181 | const visited = new Set<string>(); |
| 182 | |
| 183 | function hasPath(from: string, to: string): boolean { |
| 184 | if (from === to) return true; |
| 185 | if (visited.has(from)) return false; |
| 186 | |
| 187 | visited.add(from); |
| 188 | |
| 189 | const outgoingEdges = existingEdges.filter((edge) => edge.source === from); |
| 190 | return outgoingEdges.some((edge) => hasPath(edge.target, to)); |
| 191 | } |
| 192 | |
| 193 | return hasPath(target, source); |
| 194 | } |
| 195 | |
| 196 | /** |
| 197 | * Get validation warnings for a node (e.g., required inputs not connected) |
no test coverage detected