(cg: CodeGraph, query: URLSearchParams)
| 164 | // ============================================================================= |
| 165 | |
| 166 | export function buildEntryPoints(cg: CodeGraph, query: URLSearchParams): WireEntryPoints { |
| 167 | const started = Date.now(); |
| 168 | const limit = intParam(query, 'limit', { min: 1, max: 50, default: DEFAULT_LIMIT }); |
| 169 | const routeLimit = intParam(query, 'routes', { |
| 170 | min: 3, |
| 171 | max: MAX_ROUTE_LIMIT, |
| 172 | default: DEFAULT_ROUTE_LIMIT, |
| 173 | }); |
| 174 | |
| 175 | const stats = cg.getStats(); |
| 176 | // JSON rather than a joined string: a project root can contain any character |
| 177 | // a separator might have picked, and this key is compared for equality only. |
| 178 | const key = JSON.stringify([ |
| 179 | cg.getProjectRoot(), |
| 180 | cg.getLastIndexedAt() ?? 0, |
| 181 | stats.edgeCount, |
| 182 | stats.fileCount, |
| 183 | limit, |
| 184 | routeLimit, |
| 185 | ]); |
| 186 | const hit = cache.get(key); |
| 187 | if (hit) { |
| 188 | // Re-stamp rather than mutate: the body is shared with the next caller. |
| 189 | return { ...hit, timing: { elapsedMs: Date.now() - started, cached: true } }; |
| 190 | } |
| 191 | |
| 192 | const payload: WireEntryPoints = { |
| 193 | frameworks: cg.getDetectedFrameworks(), |
| 194 | routes: routeEntries(cg, routeLimit), |
| 195 | files: executableFiles(cg, limit), |
| 196 | tests: testFiles(cg, limit), |
| 197 | hubs: hubs(cg, limit), |
| 198 | index: { lastIndexedAt: cg.getLastIndexedAt() ?? null, files: stats.fileCount }, |
| 199 | timing: { elapsedMs: Date.now() - started, cached: false }, |
| 200 | }; |
| 201 | |
| 202 | if (cache.size >= CACHE_LIMIT) { |
| 203 | const oldest = cache.keys().next(); |
| 204 | if (!oldest.done) cache.delete(oldest.value); |
| 205 | } |
| 206 | cache.set(key, payload); |
| 207 | return payload; |
| 208 | } |
| 209 | |
| 210 | /** |
| 211 | * The routing manifest, trimmed to a starting-points list. |
no test coverage detected