Pagination utilities for Codat list endpoints.
All Codat list responses use a pageNumber / pageSize / totalResults
envelope. This module provides a struct, lazy Stream pagination, and
concurrent fetch_all/2.
Summary
Functions
Returns the default page size.
Fetches all pages concurrently and returns a flat list.
Wraps a raw Codat list response body into a %Codat.Pagination{} struct.
Returns a lazy Stream that fetches pages on demand.
Like stream/1 but raises on error.
Converts page_opts keyword list into Req query params.
Types
@type page_opts() :: [ page: pos_integer(), page_size: pos_integer(), query: String.t(), order_by: String.t() ]
@type t() :: %Codat.Pagination{ has_more?: boolean(), page_number: pos_integer(), page_size: pos_integer(), results: [map()], total: non_neg_integer() }
Functions
@spec default_page_size() :: 100
Returns the default page size.
@spec fetch_all( (pos_integer() -> {:ok, t()} | {:error, Codat.Error.t()}), keyword() ) :: {:ok, [map()]} | {:error, Codat.Error.t()}
Fetches all pages concurrently and returns a flat list.
Options
:max_concurrency— max concurrent page fetches (default: 5):timeout— per-task timeout in ms (default: 30_000)
Wraps a raw Codat list response body into a %Codat.Pagination{} struct.
@spec stream((pos_integer() -> {:ok, t()} | {:error, Codat.Error.t()})) :: Enumerable.t()
Returns a lazy Stream that fetches pages on demand.
@spec stream!((pos_integer() -> {:ok, t()} | {:error, Codat.Error.t()}), String.t()) :: Enumerable.t()
Like stream/1 but raises on error.
Converts page_opts keyword list into Req query params.