MCPcopy Index your code
hub / github.com/deepnote/deepnote / getUpstreamBlocks

Function getUpstreamBlocks

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

Source from the content-addressed store, hash-verified

61}
62
63function 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}

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected