Spaces:
Running
Running
Download src/read-pages.ts from Shoraky/Sporalize-api: direct link, hf CLI and curl.
- Browser
- Download file 583 Bytes
-
https://huggingface.co/spaces/Shoraky/Sporalize-api/resolve/main/src/read-pages.ts
- Command line
-
hf download hf://spaces/Shoraky/Sporalize-api/src/read-pages.ts
-
curl -L -o read-pages.ts https://huggingface.co/spaces/Shoraky/Sporalize-api/resolve/main/src/read-pages.ts
583 Bytes
| /** 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; | |
| } | |
| } | |