Spaces:
Running
Running
File size: 583 Bytes
57b63b8 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | /** Read ordered rows in bounded pages, including children of batched IDs.
* Callers must supply a stable order and preserve their authorization filters.
*/
export async function readPages<T>(
load: (from: number, to: number) => PromiseLike<readonly T[]>,
pageSize = 500,
): Promise<T[]> {
if (!Number.isInteger(pageSize) || pageSize < 1) throw new Error("Invalid page size");
const rows: T[] = [];
for (let from = 0; ; from += pageSize) {
const page = await load(from, from + pageSize - 1);
rows.push(...page);
if (page.length < pageSize) return rows;
}
}
|