MCPcopy Index your code
hub / github.com/simstudioai/sim / findDbDescendants

Function findDbDescendants

apps/realtime/src/database/operations.ts:72–89  ·  view source on GitHub ↗

* Finds all descendant block IDs of a container (recursive). * Works with raw DB block arrays.

(containerId: string, allBlocks: DbBlockRef[])

Source from the content-addressed store, hash-verified

70 * Works with raw DB block arrays.
71 */
72function findDbDescendants(containerId: string, allBlocks: DbBlockRef[]): string[] {
73 const descendants: string[] = []
74 const visited = new Set<string>()
75 const stack = [containerId]
76 while (stack.length > 0) {
77 const current = stack.pop()!
78 if (visited.has(current)) continue
79 visited.add(current)
80 for (const b of allBlocks) {
81 const pid = (b.data as Record<string, unknown> | null)?.parentId
82 if (pid === current) {
83 descendants.push(b.id)
84 stack.push(b.id)
85 }
86 }
87 }
88 return descendants
89}
90
91/**
92 * Shared function to handle auto-connect edge insertion

Callers 1

handleBlocksOperationTxFunction · 0.85

Calls 2

addMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected