MCPcopy Create free account
hub / github.com/DeusData/codebase-memory-mcp / readTreeLevel

Function readTreeLevel

graph-ui/src/app/tree-model.ts:216–267  ·  view source on GitHub ↗
(payload: unknown)

Source from the content-addressed store, hash-verified

214
215/** Eine Antwort von `/api/tree` lesen: falten, aussortieren, sortieren. */
216export function readTreeLevel(payload: unknown): TreeLevel {
217 const raw = isRecord(payload) ? payload : {};
218 const rawChildren = Array.isArray(raw['children']) ? raw['children'] : [];
219
220 const byPath = new Map<string, TreeChild>();
221 let foldedDuplicates = 0;
222 let droppedNonPaths = 0;
223
224 for (const entry of rawChildren) {
225 if (!isRecord(entry)) {
226 continue;
227 }
228 const name = typeof entry['name'] === 'string' ? entry['name'] : '';
229 const path = typeof entry['path'] === 'string' ? entry['path'] : '';
230 if (!namesAPath({ name, path })) {
231 droppedNonPaths += 1;
232 continue;
233 }
234 const child: TreeChild = {
235 name,
236 path,
237 kind: entry['kind'] === 'dir' ? 'dir' : 'file',
238 symbols: asNumber(entry['symbols']),
239 files: asNumber(entry['files']),
240 };
241 const missed = asNumber(entry['missed']);
242 if (missed > 0) {
243 child.missed = missed;
244 }
245
246 const existing = byPath.get(path);
247 if (existing === undefined) {
248 byPath.set(path, child);
249 continue;
250 }
251 // Derselbe Pfad zweimal: der Ordner ist die Wahrheit, die Zahlen des
252 // Ordners auch. Der Folder-Knoten steuert nur sich selbst bei.
253 foldedDuplicates += 1;
254 if (existing.kind === 'file' && child.kind === 'dir') {
255 byPath.set(path, child);
256 }
257 }
258
259 return {
260 path: typeof raw['path'] === 'string' ? raw['path'] : '',
261 files: asNumber(raw['files']),
262 symbols: asNumber(raw['symbols']),
263 children: [...byPath.values()].sort(compareChildren),
264 foldedDuplicates,
265 droppedNonPaths,
266 };
267}
268
269/** Der Pfad des Ordners ueber diesem Pfad. Leer heisst Projektwurzel. */
270export function parentPath(path: string): string {

Callers 2

tree-model.test.tsFile · 0.90
treeMethod · 0.90

Calls 4

namesAPathFunction · 0.85
isRecordFunction · 0.70
asNumberFunction · 0.70
getMethod · 0.65

Tested by

no test coverage detected