export interface AccumulateResponse { cursor?: string items: T[] } export type AccumulateFetchFn = ( cursor: string | undefined, ) => Promise> export async function accumulate( fn: AccumulateFetchFn, pageLimit = 100, ): Promise { let cursor: string | undefined let acc: T[] = [] for (let i = 0; i < pageLimit; i++) { const res = await fn(cursor) cursor = res.cursor acc = acc.concat(res.items) if (!cursor) { break } } return acc }