(client: GraphQueryClient, project: string, query: string, key: string, signal?: AbortSignal,
onRequest?: () => void, onPage?: (rows: readonly Record<string, string>[]) => 'stop' | void)
| 44 | * `onPage` answering 'stop' (a layer at its render limit, K8): the caller then |
| 45 | * holds a deliberately cut result and must mark it partial. */ |
| 46 | export async function readGraphPages(client: GraphQueryClient, project: string, query: string, key: string, signal?: AbortSignal, |
| 47 | onRequest?: () => void, onPage?: (rows: readonly Record<string, string>[]) => 'stop' | void): Promise<Record<string, string>[]> { |
| 48 | signal?.throwIfAborted(); |
| 49 | onRequest?.(); |
| 50 | let page = await client.queryGraph(project, query, undefined, SCOPE_PAGE_BUDGET); |
| 51 | const columns = page.columns, total = page.total, records: Record<string, string>[] = []; |
| 52 | const cursors = new Set<string>(), identities = new Set<number>(); |
| 53 | for (;;) { |
| 54 | signal?.throwIfAborted(); |
| 55 | if (JSON.stringify(columns) !== JSON.stringify(page.columns) || page.total !== total |
| 56 | || (page.offset !== undefined && page.offset !== records.length)) throw new Error('Graph pagination changed its result snapshot.'); |
| 57 | const fresh: Record<string, string>[] = []; |
| 58 | for (const row of page.rows) { |
| 59 | const record = Object.fromEntries(columns.map((column, index) => [column, row[index] ?? ''])); |
| 60 | const identity = id(record[key]); |
| 61 | if (identities.has(identity)) throw new Error('Graph pagination repeated a row.'); |
| 62 | identities.add(identity); records.push(record); fresh.push(record); |
| 63 | } |
| 64 | if (onPage?.(fresh) === 'stop') return records; |
| 65 | if (!page.nextCursor) { |
| 66 | if (page.hasMore || page.truncated || page.totalRelation === 'gte' || (total !== undefined && records.length < total)) |
| 67 | throw new Error(`Incomplete graph response (${records.length} relationships read); ${page.truncationReason ?? 'the server did not provide a continuation'}.`); |
| 68 | return records; |
| 69 | } |
| 70 | if (!page.rows.length || cursors.has(page.nextCursor)) throw new Error('Graph pagination did not advance.'); |
| 71 | if (page.nextOffset !== undefined && page.nextOffset !== records.length) throw new Error('Graph pagination skipped rows.'); |
| 72 | cursors.add(page.nextCursor); signal?.throwIfAborted(); |
| 73 | onRequest?.(); |
| 74 | page = await client.queryGraph(project, query, page.nextCursor, SCOPE_PAGE_BUDGET); |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | const languageColors: Record<string, string> = { ts: '#6ea6be', tsx: '#6ea6be', js: '#c3b775', jsx: '#c3b775', c: '#92a8b4', h: '#92a8b4', cpp: '#b28da6', py: '#8daf88', go: '#77b2b4', rs: '#bd947c', java: '#bd9281', cs: '#a392bb', rb: '#b78288', swift: '#bf9b85', kt: '#af97ba' }; |
| 79 | function readNode(row: Record<string, string>, prefix: string, layout: Map<number, GraphNode>): GraphNode { |
no test coverage detected