MCPcopy Create free account
hub / github.com/deepnote/deepnote / getDownstreamBlocks

Function getDownstreamBlocks

packages/reactivity/src/dag-analyzer.ts:23–41  ·  view source on GitHub ↗
(dag: BlockDependencyDag, blocksIds: string[], visited: Set<string> = new Set())

Source from the content-addressed store, hash-verified

21}
22
23function 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).

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected