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

Function handleApi

telemetry-dashboard/src/api.ts:889–921  ·  view source on GitHub ↗
(env: Env, url: URL)

Source from the content-addressed store, hash-verified

887 * turns what comes back into a Response.
888 */
889export async function handleApi(env: Env, url: URL): Promise<ApiResult> {
890 if (url.pathname === '/api/session') return { body: { authenticated: true } };
891 if (url.pathname === '/api/health') return health(env);
892 if (url.pathname === '/api/meta') return meta(env);
893
894 const ranged = new Set(['/api/summary', '/api/timeseries', '/api/breakdown', '/api/activation', '/api/retention']);
895 if (!ranged.has(url.pathname)) return fail('not found', 404);
896
897 const range = parseRange(url);
898 if (isApiResult(range)) return range;
899
900 try {
901 switch (url.pathname) {
902 case '/api/summary':
903 return await summary(env, range);
904 case '/api/timeseries':
905 return await timeseries(env, url, range);
906 case '/api/breakdown':
907 return await breakdown(env, url, range);
908 case '/api/activation':
909 return await activation(env, url, range);
910 case '/api/retention':
911 return await retention(env, range);
912 default:
913 return fail('not found', 404);
914 }
915 } catch (err) {
916 // The query failed, not the caller. Log the cause, tell the page something
917 // it can put in the panel, and let the other panels carry on.
918 console.error(JSON.stringify({ msg: 'api query failed', path: url.pathname, err: String(err) }));
919 return { body: { error: 'query failed' }, status: 503 };
920 }
921}

Callers 2

apiResponseFunction · 0.90
apiFunction · 0.90

Calls 12

parseRangeFunction · 0.85
isApiResultFunction · 0.85
timeseriesFunction · 0.85
hasMethod · 0.80
healthFunction · 0.70
metaFunction · 0.70
failFunction · 0.70
summaryFunction · 0.70
breakdownFunction · 0.70
activationFunction · 0.70
retentionFunction · 0.70
errorMethod · 0.65

Tested by 1

apiFunction · 0.72