(text: string)
| 345 | * Trefferzeilen / `has_more:`). |
| 346 | */ |
| 347 | export function parseSearchResults(text: string): SearchResults { |
| 348 | const lines = text.split('\n'); |
| 349 | let total: number | undefined; |
| 350 | let mode: string | undefined; |
| 351 | let columns: string[] | undefined; |
| 352 | let declared: number | undefined; |
| 353 | let rows: string[][] | undefined; |
| 354 | let hasMore: boolean | undefined; |
| 355 | let returned: number | undefined; |
| 356 | let totalRelation: string | undefined; |
| 357 | let truncated: boolean | undefined; |
| 358 | let refs: ReadonlyMap<number, string> | undefined; |
| 359 | const footers: Pick<SearchResults, 'nextOffset' | 'truncationReason' | 'candidateWindowSaturated' | 'continuationRequiresHigherBudget' | 'maxOutputBytes' | 'outputBudgetFloorExceeded' | 'hint'> = {}; |
| 360 | |
| 361 | let i = 0; |
| 362 | while (i < lines.length) { |
| 363 | const line = lines[i]; |
| 364 | if (line.trim().length === 0) { |
| 365 | i += 1; |
| 366 | continue; |
| 367 | } |
| 368 | if (line.startsWith('results_refs:')) { |
| 369 | if (refs || rows) throw new Error('Duplicate or misplaced results_refs'); |
| 370 | const directory = readReferences(lines, i, 'results'); |
| 371 | if (!directory.refs) throw new Error('Malformed results_refs'); |
| 372 | refs = directory.refs; |
| 373 | i = directory.next; |
| 374 | continue; |
| 375 | } |
| 376 | |
| 377 | const totalMatch = TOTAL_LINE.exec(line); |
| 378 | if (totalMatch !== null) { |
| 379 | total = Number.parseInt(totalMatch[1], 10); |
| 380 | i += 1; |
| 381 | continue; |
| 382 | } |
| 383 | const modeMatch = MODE_LINE.exec(line); |
| 384 | if (modeMatch !== null) { |
| 385 | mode = modeMatch[1]; |
| 386 | i += 1; |
| 387 | continue; |
| 388 | } |
| 389 | const hasMoreMatch = HAS_MORE_LINE.exec(line); |
| 390 | if (hasMoreMatch !== null) { |
| 391 | hasMore = hasMoreMatch[1] === 'true'; |
| 392 | i += 1; |
| 393 | continue; |
| 394 | } |
| 395 | const returnedMatch = RETURNED_LINE.exec(line); |
| 396 | if (returnedMatch !== null) { |
| 397 | returned = Number.parseInt(returnedMatch[1], 10); |
| 398 | i += 1; |
| 399 | continue; |
| 400 | } |
| 401 | const relationMatch = TOTAL_RELATION_LINE.exec(line); |
| 402 | if (relationMatch !== null) { |
| 403 | totalRelation = relationMatch[1]; |
| 404 | i += 1; |
no test coverage detected