MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / buildNodeRefs

Function buildNodeRefs

src/ui-server/api/nodes.ts:29–54  ·  view source on GitHub ↗
(cg: CodeGraph, query: URLSearchParams)

Source from the content-addressed store, hash-verified

27}
28
29export function buildNodeRefs(cg: CodeGraph, query: URLSearchParams): WireNodeRefs {
30 const ids = query.getAll('id').filter((id) => id !== '');
31 if (ids.length === 0) {
32 throw badRequest(
33 'No ids were given.',
34 'Use /api/nodes?id=<id>&id=<id> — one `id` parameter per symbol.'
35 );
36 }
37 if (ids.length > MAX_NODE_REFS) {
38 throw badRequest(`Too many ids: ${ids.length}. At most ${MAX_NODE_REFS} per request.`);
39 }
40
41 const unique = [...new Set(ids)];
42 const byId = cg.getNodesByIds(unique);
43
44 const items: WireNodeRef[] = [];
45 const missing: string[] = [];
46 // Answer in the order asked, so the caller never has to re-sort.
47 for (const id of unique) {
48 const node = byId.get(id);
49 if (node) items.push(toNodeRef(node));
50 else missing.push(id);
51 }
52
53 return { items, missing };
54}

Callers 1

handlerFunction · 0.90

Calls 5

badRequestFunction · 0.90
toNodeRefFunction · 0.90
pushMethod · 0.80
getMethod · 0.65
getNodesByIdsMethod · 0.45

Tested by

no test coverage detected