import type { Bundle } from 'fhir/r4'; import { MAX_ROWS } from './xlsx'; export async function allRows( first: string, getPage: (url: string) => Promise, max = MAX_ROWS, ): Promise { const rows: T[] = []; let next: string | undefined = first; while (next && rows.length < max) { const page = await getPage(next); for (const { resource } of page.entry ?? []) { if (resource) rows.push(resource as T); if (rows.length >= max) return rows; } next = page.link?.find(({ relation }) => relation === 'next')?.url; } return rows; }