(dag: BlockDependencyDag, blocksIds: string[], visited: Set<string> = new Set())
| 21 | } |
| 22 | |
| 23 | function getDownstreamBlocks(dag: BlockDependencyDag, blocksIds: string[], visited: Set<string> = new Set()): string[] { |
| 24 | const outputVariables = dag.nodes.filter(node => blocksIds.includes(node.id)).flatMap(node => node.outputVariables) |
| 25 | |
| 26 | const blocksThatAreUsingVariables = dag.nodes |
| 27 | .filter(node => node.inputVariables.find(inputVariable => outputVariables.includes(inputVariable))) |
| 28 | .map(node => node.id) |
| 29 | |
| 30 | if (blocksThatAreUsingVariables.length === 0) { |
| 31 | return [] |
| 32 | } |
| 33 | |
| 34 | // This prevents the function from making recursive calls for blocks that have already been visited. |
| 35 | const nextBlocks = blocksThatAreUsingVariables.filter(id => !visited.has(id)) |
| 36 | nextBlocks.forEach(id => { |
| 37 | visited.add(id) |
| 38 | }) |
| 39 | |
| 40 | return [...nextBlocks, ...getDownstreamBlocks(dag, nextBlocks, visited)] |
| 41 | } |
| 42 | |
| 43 | /** |
| 44 | * Accepts ids of target blocks and returns ids of blocks that these blocks depend on (upstream dependencies). |
no outgoing calls
no test coverage detected