Skip to content
AniLink

Pagination

Three helpers cover the three traversal styles:

HelperWalksReturnsUse when
paginatepageInfo pagesAll items buffered in a PaginateResultYou want the complete set
paginatePagespageInfo pagesAn async generator of raw pagesYou want to stream or exit early
paginateChunkshasNextChunk chunksAll items buffered in a ChunkPaginateResultTraversing 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

OptionApplies toDefaultClampMeaning
perPagepaginate, paginatePages50≤ 50Items per page. Values above 50 are clamped down
perChunkpaginateChunks500≤ 500Entries per chunk. Values above 500 are clamped down
startPage / startChunkall11-based position to start from
maxPages / maxChunksall100Hard cap guarding unbounded loops
concurrencyall1≤ 8Look-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 reports hasNextChunk: false).
  • truncated is true when the traversal stopped at maxPages/maxChunks before the source ran out.
  • hasNextChunk semantics: paginateChunks continues while the fetched chunk reports more chunks ahead, up to maxChunks.

Next steps

AniLink — typed AniList & MyAnimeList client for TypeScript.