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

Function buildSortedChildren

packages/cli/src/commands/dag.ts:261–288  ·  view source on GitHub ↗

* Build sorted children for a node, deduplicating edges to the same child.

(
  nodeId: string,
  childrenMap: Map<string, { id: string; variables: string[] }[]>,
  nodeMap: Map<string, DagNode>
)

Source from the content-addressed store, hash-verified

259 * Build sorted children for a node, deduplicating edges to the same child.
260 */
261function buildSortedChildren(
262 nodeId: string,
263 childrenMap: Map<string, { id: string; variables: string[] }[]>,
264 nodeMap: Map<string, DagNode>
265): { id: string; variables: string[] }[] {
266 // Get children and deduplicate by target ID, merging variables
267 const childrenRaw = childrenMap.get(nodeId) ?? []
268 const childrenById = new Map<string, string[]>()
269 for (const child of childrenRaw) {
270 const existing = childrenById.get(child.id) ?? []
271 existing.push(...child.variables)
272 childrenById.set(child.id, existing)
273 }
274
275 const children = Array.from(childrenById.entries()).map(([id, vars]) => ({
276 id,
277 variables: [...new Set(vars)], // deduplicate variables
278 }))
279
280 // Sort by DAG order
281 children.sort((a, b) => {
282 const orderA = nodeMap.get(a.id)?.order ?? 0
283 const orderB = nodeMap.get(b.id)?.order ?? 0
284 return orderA - orderB
285 })
286
287 return children
288}
289
290/**
291 * Render a node and its subtree in tree format.

Callers 1

renderTreeNodeFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected