interface CursorPage { items: T[] pageInfo: { hasMore: boolean nextCursor: string | null } } /** * Traverses every page for interactive selectors that need the full set. * * @param getPage - Loads one page from its optional preceding cursor. */ export async function collectCursorPages( getPage: (cursor: string | undefined) => Promise>, ) { const items: T[] = [] let cursor: string | undefined do { const page = await getPage(cursor) items.push(...page.items) cursor = page.pageInfo.nextCursor ?? undefined } while (cursor !== undefined) return items }