Marqeta.Pagination (marqeta v1.0.0)

Copy Markdown View Source

Pagination cursor helpers for Marqeta list endpoints.

Marqeta paginates with count (page size) and start_index (offset). Responses include "is_more": true when further pages exist.

Example

{:ok, page} = Marqeta.Users.list(%{count: 10, start_index: 0})
if Marqeta.Pagination.has_more?(page) do
  next = Marqeta.Pagination.next_page_params(page, %{count: 10, start_index: 0})
  {:ok, page2} = Marqeta.Users.list(next)
end

Summary

Functions

Returns default pagination params %{count: 5, start_index: 0}.

Extracts the "data" list from a paginated response.

Returns true when the response signals there are more pages.

Returns params for the next page, or nil when no more pages exist.

Normalises params, enforcing the maximum allowed count and a default start_index.

Returns the record count from a paginated response.

Types

normalized_params()

@type normalized_params() :: %{
  :count => pos_integer(),
  :start_index => non_neg_integer(),
  optional(atom()) => term()
}

page()

@type page() :: %{optional(String.t()) => term()}

Functions

default_params()

@spec default_params() :: %{count: 5, start_index: 0}

Returns default pagination params %{count: 5, start_index: 0}.

extract_data(arg1)

@spec extract_data(page()) :: [map()]

Extracts the "data" list from a paginated response.

has_more?(arg1)

@spec has_more?(page()) :: boolean()

Returns true when the response signals there are more pages.

next_page_params(response, current_params)

@spec next_page_params(page(), map()) :: map() | nil

Returns params for the next page, or nil when no more pages exist.

Determines "more pages" via:

  1. "is_more": true in the response (Marqeta's explicit signal).
  2. Fallback: returned count equals requested count (more may exist).

normalize_params(params)

@spec normalize_params(map()) :: normalized_params()

Normalises params, enforcing the maximum allowed count and a default start_index.

Always returns a map containing at least :count and :start_index integer keys.

total_count(arg1)

@spec total_count(page()) :: non_neg_integer()

Returns the record count from a paginated response.