( edges: Edge[], blocks: Record<string, BlockState> )
| 48 | } |
| 49 | |
| 50 | export function validateEdges( |
| 51 | edges: Edge[], |
| 52 | blocks: Record<string, BlockState> |
| 53 | ): EdgeValidationResult { |
| 54 | const valid: Edge[] = [] |
| 55 | const dropped: DroppedEdge[] = [] |
| 56 | |
| 57 | for (const edge of edges) { |
| 58 | const sourceBlock = blocks[edge.source] |
| 59 | const targetBlock = blocks[edge.target] |
| 60 | |
| 61 | if (!sourceBlock || !targetBlock) { |
| 62 | dropped.push({ edge, reason: 'edge references a missing block' }) |
| 63 | continue |
| 64 | } |
| 65 | |
| 66 | if (isAnnotationOnlyBlock(sourceBlock.type) || isAnnotationOnlyBlock(targetBlock.type)) { |
| 67 | dropped.push({ edge, reason: 'edge references an annotation-only block' }) |
| 68 | continue |
| 69 | } |
| 70 | |
| 71 | if (TriggerUtils.isTriggerBlock(targetBlock)) { |
| 72 | dropped.push({ edge, reason: 'trigger blocks cannot be edge targets' }) |
| 73 | continue |
| 74 | } |
| 75 | |
| 76 | const scopeDropReason = getScopeDropReason(edge, blocks) |
| 77 | if (scopeDropReason) { |
| 78 | dropped.push({ edge, reason: scopeDropReason }) |
| 79 | continue |
| 80 | } |
| 81 | |
| 82 | valid.push(edge) |
| 83 | } |
| 84 | |
| 85 | return { valid, dropped } |
| 86 | } |
no test coverage detected