Pagination
Three helpers cover the three traversal styles:
| Helper | Walks | Returns | Use when |
|---|---|---|---|
paginate | pageInfo pages | All items buffered in a PaginateResult | You want the complete set |
paginatePages | pageInfo pages | An async generator of raw pages | You want to stream or exit early |
paginateChunks | hasNextChunk chunks | All items buffered in a ChunkPaginateResult | Traversing mediaListCollection |
paginate
typescript
const result = await aniLink.anilist.paginate(
(page, perPage) => aniLink.anilist.query.page.medias({ page, perPage, type: "ANIME" }),
"media",
{ perPage: 50, maxPages: 10, concurrency: 4 }
);
console.log(result.items.length, result.pageCount, result.truncated);paginatePages
typescript
for await (const page of aniLink.anilist.paginatePages((page, perPage) =>
aniLink.anilist.query.page.medias({ page, perPage, type: "ANIME" })
)) {
console.log(page.pageInfo.currentPage, page.media.length);
if (page.media[0]?.id === 1) break; // early exit without buffering everything
}paginateChunks
typescript
const chunked = await aniLink.anilist.paginateChunks(
(chunk, perChunk) =>
aniLink.anilist.query.mediaListCollection({ userId: 542244, type: "ANIME", chunk, perChunk }),
"lists",
{ perChunk: 500, maxChunks: 20 }
);
console.log(chunked.items.length, chunked.chunkCount, chunked.truncated);Options and clamps
| Option | Applies to | Default | Clamp | Meaning |
|---|---|---|---|---|
perPage | paginate, paginatePages | 50 | ≤ 50 | Items per page. Values above 50 are clamped down |
perChunk | paginateChunks | 500 | ≤ 500 | Entries per chunk. Values above 500 are clamped down |
startPage / startChunk | all | 1 | — | 1-based position to start from |
maxPages / maxChunks | all | 100 | — | Hard cap guarding unbounded loops |
concurrency | all | 1 | ≤ 8 | Look-ahead requests kept in flight |
Ordering and truncation guarantees
- Results are always in page/chunk order, regardless of completion order.
- Scheduling stops as soon as a fetched page reports
hasNextPage: false(or a chunk reportshasNextChunk: false). truncatedistruewhen the traversal stopped atmaxPages/maxChunksbefore the source ran out.hasNextChunksemantics:paginateChunkscontinues while the fetched chunk reports more chunks ahead, up tomaxChunks.
Next steps
- Page queries — the single-page building blocks.
- Recipes — a complete list-sync workflow.