(cg: CodeGraph, query: URLSearchParams)
| 27 | } |
| 28 | |
| 29 | export 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 | } |
no test coverage detected