( client: Awaited<ReturnType<typeof createCloudClient>>, pageSize: number | undefined, )
| 66 | |
| 67 | // fallow-ignore-next-line complexity |
| 68 | async function fetchAll( |
| 69 | client: Awaited<ReturnType<typeof createCloudClient>>, |
| 70 | pageSize: number | undefined, |
| 71 | ): Promise<HyperframesRenderDetail[]> { |
| 72 | const out: HyperframesRenderDetail[] = []; |
| 73 | const seenCursors = new Set<string>(); |
| 74 | let token: string | undefined; |
| 75 | for (let page = 0; page < MAX_ALL_PAGES; page++) { |
| 76 | const result = await client.listRenders({ limit: pageSize, token }); |
| 77 | out.push(...(result.data ?? [])); |
| 78 | if (!result.has_more) return out; |
| 79 | // Defensive: server said `has_more: true` but didn't hand us a |
| 80 | // cursor to use. Better to surface the malformed shape than |
| 81 | // return a silently-truncated list. |
| 82 | if (!result.next_token) { |
| 83 | errorBox( |
| 84 | "Pagination cursor missing", |
| 85 | "Server returned has_more: true with no next_token — incomplete response.", |
| 86 | "Retry the command, or report this if it persists.", |
| 87 | ); |
| 88 | process.exit(1); |
| 89 | } |
| 90 | if (seenCursors.has(result.next_token)) { |
| 91 | errorBox( |
| 92 | "Pagination loop detected", |
| 93 | `Server returned the same next_token (${result.next_token}) twice.`, |
| 94 | "Retry the command, or report this if it persists.", |
| 95 | ); |
| 96 | process.exit(1); |
| 97 | } |
| 98 | seenCursors.add(result.next_token); |
| 99 | token = result.next_token; |
| 100 | } |
| 101 | errorBox( |
| 102 | "Pagination cap reached", |
| 103 | `Stopped after ${MAX_ALL_PAGES} pages to avoid an unbounded loop.`, |
| 104 | `Re-run with a higher --limit, or paginate manually with --token.`, |
| 105 | ); |
| 106 | process.exit(1); |
| 107 | } |
| 108 | |
| 109 | // fallow-ignore-next-line complexity |
| 110 | function emit( |
no test coverage detected