| 53 | } |
| 54 | |
| 55 | export function ensureDirChain( |
| 56 | repoId: string, |
| 57 | dirPath: string, |
| 58 | dirNodes: Map<string, GraphNode>, |
| 59 | rels: GraphRelationship[], |
| 60 | ): void { |
| 61 | if (!dirPath || dirNodes.has(dirPath)) return; |
| 62 | |
| 63 | const parent = parentDir(dirPath); |
| 64 | ensureDirChain(repoId, parent, dirNodes, rels); |
| 65 | |
| 66 | const dirId = `${repoId}/${dirPath}`; |
| 67 | const name = dirPath.includes('/') |
| 68 | ? dirPath.slice(dirPath.lastIndexOf('/') + 1) |
| 69 | : dirPath; |
| 70 | |
| 71 | dirNodes.set(dirPath, { |
| 72 | id: dirId, |
| 73 | type: 'Directory', |
| 74 | name, |
| 75 | properties: { path: dirPath }, |
| 76 | }); |
| 77 | |
| 78 | const targetId = parent ? `${repoId}/${parent}` : repoId; |
| 79 | rels.push({ |
| 80 | id: `${targetId}->DEFINES->${dirId}`, |
| 81 | type: 'DEFINES', |
| 82 | source_id: targetId, |
| 83 | target_id: dirId, |
| 84 | }); |
| 85 | } |