(dag: BlockDependencyDag, blocksIds: string[])
| 45 | * The method finds dependencies in upstream mode - we are filtering out nodes from the DAG that are defined after the target blocks. |
| 46 | */ |
| 47 | export function getUpstreamBlocksForBlocksIds(dag: BlockDependencyDag, blocksIds: string[]): string[] { |
| 48 | const targetBlocks = dag.nodes.filter(node => blocksIds.includes(node.id)) |
| 49 | |
| 50 | if (targetBlocks.length === 0) { |
| 51 | return [] |
| 52 | } |
| 53 | |
| 54 | const maxOrder = Math.max(...targetBlocks.map(node => node.order)) |
| 55 | const filteredDag = { |
| 56 | ...dag, |
| 57 | nodes: dag.nodes.filter(node => node.order <= maxOrder), |
| 58 | } |
| 59 | |
| 60 | return getUpstreamBlocks(filteredDag, blocksIds) |
| 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) |
no test coverage detected