(dag: BlockDependencyDag, blocksIds: string[], visited: Set<string> = new Set())
| 61 | } |
| 62 | |
| 63 | function getUpstreamBlocks(dag: BlockDependencyDag, blocksIds: string[], visited: Set<string> = new Set()): string[] { |
| 64 | const inputVariables = dag.nodes.filter(node => blocksIds.includes(node.id)).flatMap(node => node.inputVariables) |
| 65 | |
| 66 | const blocksThatDefineVariables = dag.nodes |
| 67 | .filter(node => node.outputVariables.find(outputVariable => inputVariables.includes(outputVariable))) |
| 68 | .map(node => node.id) |
| 69 | |
| 70 | if (blocksThatDefineVariables.length === 0) { |
| 71 | return [] |
| 72 | } |
| 73 | |
| 74 | // This prevents the function from making recursive calls for blocks that have already been visited. |
| 75 | const nextBlocks = blocksThatDefineVariables.filter(id => !visited.has(id)) |
| 76 | nextBlocks.forEach(id => { |
| 77 | visited.add(id) |
| 78 | }) |
| 79 | |
| 80 | return [...nextBlocks, ...getUpstreamBlocks(dag, nextBlocks, visited)] |
| 81 | } |
no outgoing calls
no test coverage detected