offstage/pagination

Types

Represents pagination parameter for API requests with a cursor pointing to the item after which to start pagination.

  • after is the cursor pointing to the item after which to start pagination.
  • per_page is the number of items to return per page.
pub type AfterPagination(a) {
  AfterPagination(after: a, per_page: Int)
}

Constructors

  • AfterPagination(after: a, per_page: Int)

Represents pagination parameter for API requests with a cursor pointing to the item before which to start pagination.

  • before is the cursor pointing to the item before which to start pagination.
  • per_page is the number of items to return per page.
pub type BeforePagination(a) {
  BeforePagination(before: a, per_page: Int)
}

Constructors

  • BeforePagination(before: a, per_page: Int)

Represents pagination parameters for API requests.

  • page is the current page number (starting from 1).
  • per_page is the number of items to return per page.
pub type Pagination {
  Pagination(page: Int, per_page: Int)
}

Constructors

  • Pagination(page: Int, per_page: Int)

The configuration of the pagination strategy for API requests.

  • result is the type of pagination (one of Pagination, AfterPagination(b), or BeforePagination(b)).
  • cursor is the type of the cursor for after and before pagination (Nil for Pagination).
  • request is the type of the request.
pub type PaginationConfig(result, cursor, request) {
  SimplePaginationConfig(
    default_page: Int,
    default_per_page: Int,
    max_per_page: Int,
    parser: fn(
      PaginationConfig(result, cursor, request),
      request.Request(request),
    ) -> result,
  )
  AfterPaginationConfig(
    default_after: cursor,
    after_serializer: serialize.Serializer(cursor),
    is_json: Bool,
    default_per_page: Int,
    max_per_page: Int,
    parser: fn(
      PaginationConfig(result, cursor, request),
      request.Request(request),
    ) -> result,
  )
  BeforePaginationConfig(
    default_before: cursor,
    before_serializer: serialize.Serializer(cursor),
    is_json: Bool,
    default_per_page: Int,
    max_per_page: Int,
    parser: fn(
      PaginationConfig(result, cursor, request),
      request.Request(request),
    ) -> result,
  )
}

Constructors

  • SimplePaginationConfig(
      default_page: Int,
      default_per_page: Int,
      max_per_page: Int,
      parser: fn(
        PaginationConfig(result, cursor, request),
        request.Request(request),
      ) -> result,
    )
  • AfterPaginationConfig(
      default_after: cursor,
      after_serializer: serialize.Serializer(cursor),
      is_json: Bool,
      default_per_page: Int,
      max_per_page: Int,
      parser: fn(
        PaginationConfig(result, cursor, request),
        request.Request(request),
      ) -> result,
    )
  • BeforePaginationConfig(
      default_before: cursor,
      before_serializer: serialize.Serializer(cursor),
      is_json: Bool,
      default_per_page: Int,
      max_per_page: Int,
      parser: fn(
        PaginationConfig(result, cursor, request),
        request.Request(request),
      ) -> result,
    )

Values

pub fn after(
  default default: b,
  serializer serializer: serialize.Serializer(b),
) -> PaginationConfig(AfterPagination(b), b, c)

Create an after pagination configuration with default values.

  • default_after set to the provided default value
  • after_serializer set to the provided serializer
  • is_json set to False
  • default_per_page set to 10
  • max_per_page set to 100
pub fn as_json(
  config: PaginationConfig(a, b, c),
) -> PaginationConfig(a, b, c)

Set the is_json flag to True (if supported). Supported by AfterPaginationConfig and BeforePaginationConfig.

pub fn before(
  default default: b,
  serializer serializer: serialize.Serializer(b),
) -> PaginationConfig(BeforePagination(b), b, c)

Create a before pagination configuration with default values.

  • default_before set to the provided default value
  • before_serializer set to the provided serializer
  • is_json set to False
  • default_per_page set to 10
  • max_per_page set to 100
pub fn parse(
  config: PaginationConfig(a, b, c),
  request: request.Request(c),
) -> a

Retrieve the pagination parameters from the request based on the configuration.

pub fn set_default_page(
  config: PaginationConfig(a, b, c),
  default_page: Int,
) -> PaginationConfig(a, b, c)

Set the default_page value (if supported). Supported by SimplePaginationConfig.

pub fn set_default_per_page(
  config: PaginationConfig(a, b, c),
  default_per_page: Int,
) -> PaginationConfig(a, b, c)

Set the default_per_page value.

pub fn set_max_per_page(
  config: PaginationConfig(a, b, c),
  max_per_page: Int,
) -> PaginationConfig(a, b, c)

Set the max_per_page value.

pub fn simple() -> PaginationConfig(Pagination, Nil, c)

Create a simple pagination configuration with default values.

  • default_page set to 1
  • default_per_page set to 10
  • max_per_page set to 100
✨ Search Document