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

Function parseFlowQuery

src/ui-server/api/flow.ts:266–300  ·  view source on GitHub ↗
(query: URLSearchParams)

Source from the content-addressed store, hash-verified

264 * mirrors `ui/src/lib/trail-codec.ts`, which owns the format.
265 */
266export function parseFlowQuery(query: URLSearchParams): FlowQuery {
267 const rawHops = query.getAll('hop').filter((h) => h.length > 1);
268 if (rawHops.length > 0) {
269 if (rawHops.length > MAX_TRAIL_HOPS) {
270 throw badRequest(
271 `A trail of ${rawHops.length} hops is longer than this endpoint reads (${MAX_TRAIL_HOPS}).`
272 );
273 }
274 const hops = rawHops.map((raw) => ({
275 id: raw.slice(1),
276 dir: DIR_CHARS[raw[0] as string] ?? ('down' as const),
277 }));
278 if (hops.length < 2) {
279 throw badRequest('A trail needs at least two hops to be read as a flow.');
280 }
281 return { kind: 'trail', hops };
282 }
283
284 const from = (query.get('from') ?? '').trim();
285 const to = (query.get('to') ?? '').trim();
286 if (from && to) {
287 if (normalizeToken(from) === normalizeToken(to)) {
288 throw badRequest('"from" and "to" name the same symbol, so there is no path to draw.');
289 }
290 return { kind: 'directed', from, to };
291 }
292
293 const symbols = (query.get('symbols') ?? '').trim();
294 if (symbols) return { kind: 'symbols', text: symbols };
295
296 throw badRequest(
297 'No flow was asked for.',
298 'Use /api/flow?from=<symbol>&to=<symbol>, ?symbols=a,b,c, or ?hop=s<id>&hop=d<id>.'
299 );
300}
301
302// =============================================================================
303// Edges

Callers 2

buildFlowFunction · 0.70

Calls 4

badRequestFunction · 0.90
normalizeTokenFunction · 0.90
mapMethod · 0.80
getMethod · 0.65

Tested by

no test coverage detected