infinity-fetch - v1.5.0
    Preparing search index...

    Type Alias PaginationOptions<TResponse, TItem, TOut>

    Options shared by every helper: lifecycle callbacks, stop conditions, per-item transforms, pacing, retries and cancellation.

    TItem is what getItems returns; TOut is what ends up in the result, which differs only when mapItem is provided.

    type PaginationOptions<TResponse, TItem, TOut = TItem> = {
        onStart?: () => unknown;
        onEnd?: (result: InfinityFetchResult<TOut>) => unknown;
        onPage?: (items: TOut[], response: TResponse, pageIndex: number) => unknown;
        maxPages?: number;
        maxItems?: number;
        stopWhen?: (
            items: TOut[],
            response: TResponse,
            pageIndex: number,
        ) => boolean;
        mapItem?: (item: TItem, index: number) => TOut;
        filterItem?: (item: TOut, index: number) => boolean;
        dedupeBy?: (item: TOut) => unknown;
        delay?: number;
        retry?: InfinityFetchRetryConfig;
        signal?: AbortSignal;
    }

    Type Parameters

    • TResponse
    • TItem
    • TOut = TItem
    Index
    onStart?: () => unknown

    Optional: called once before the first fetch starts

    onEnd?: (result: InfinityFetchResult<TOut>) => unknown

    Optional: called once after all pages have been fetched

    onPage?: (items: TOut[], response: TResponse, pageIndex: number) => unknown

    Optional: called after each page is fetched. Awaited, so it can apply backpressure

    maxPages?: number

    Optional: maximum number of pages to fetch (safety limit)

    maxItems?: number

    Optional: stop once this many items have been collected. The last page is truncated

    stopWhen?: (items: TOut[], response: TResponse, pageIndex: number) => boolean

    Optional: return true to stop after the current page (checked after isLastPage)

    mapItem?: (item: TItem, index: number) => TOut

    Optional: transform each item. index is its zero-based position across all pages

    filterItem?: (item: TOut, index: number) => boolean

    Optional: keep only the items for which this returns true

    dedupeBy?: (item: TOut) => unknown

    Optional: drop items whose key was already seen on this or a previous page

    delay?: number

    Optional: milliseconds to wait between each page fetch

    Optional: retry failed page fetches

    signal?: AbortSignal

    Optional: signal to abort pagination early and return partial results