Ash.Page.Keyset (ash v3.38.1)

Copy Markdown View Source

A page of results from keyset based pagination.

The results are generated with a keyset metadata, which can be used to fetch the next/previous pages.

A keyset is the sort values of a record. How it is encoded depends on whether config :ash, :keyset_signing_secret is set:

  • With a secret, the values are encoded with :erlang.term_to_binary/1 and signed with an HMAC. Ash only decodes keysets whose signature is valid, so every keyset it decodes was generated by this application.
  • Without a secret, the values are dumped with Ash.Type.dump_to_embedded/3 and encoded as JSON. Decoding JSON can only produce plain data, never structs, functions or atoms, and each value is cast back with Ash.Type.coerce/3, the same way values in a client-supplied filter are cast. A record sorted by values that can't be encoded as JSON has no keyset.

Summary

Functions

Appends keyset info to results.

Creates filters on the query using the query for the Keyset.

A restricted version of :erlang.binary_to_term/2 that forbids executable terms, such as anonymous functions. The opts are given to the underlying :erlang.binary_to_term/2 call, with an empty list as a default. By default this function does not restrict atoms, as an atom interned in one node may not yet have been interned on another (except for releases, which preload all code). If you want to avoid atoms from being created, then you can pass [:safe] as options, as that will also enable the safety mechanisms from :erlang.binary_to_term/2 itself. Ripped from https://github.com/elixir-plug/plug_crypto/blob/v1.2.0/lib/plug/crypto.ex

Types

page_opts()

@type page_opts() :: [
  before: page_opts_opts(),
  after: page_opts_opts(),
  limit: page_opts_opts(),
  filter: page_opts_opts(),
  count: page_opts_opts()
]

page_opts_opts()

@type page_opts_opts() :: [type: page_opts_type(), doc: String.t()]

page_opts_type()

@type page_opts_type() :: :non_neg_integer | :pos_integer | :any | :boolean

t()

@type t() :: %Ash.Page.Keyset{
  after: binary() | nil,
  before: binary() | nil,
  count: non_neg_integer(),
  limit: pos_integer(),
  more?: boolean(),
  rerun: {Ash.Query.t(), Keyword.t()},
  results: [Ash.Resource.Record.t()]
}

Functions

data_with_keyset(results, resource, sort)

@spec data_with_keyset([Ash.Resource.Record.t()], term(), term()) :: [
  Ash.Resource.Record.t()
]

Appends keyset info to results.

filter(query, values, sort, after_or_before)

@spec filter(Ash.Query.t(), [term()], term(), :after | :before) ::
  {:ok, Keyword.t()} | {:error, term()}

Creates filters on the query using the query for the Keyset.

new(results, count, sort, original_query, more?, opts)

Creates a new Ash.Page.Keyset.t.

non_executable_binary_to_term(binary, opts)

A restricted version of :erlang.binary_to_term/2 that forbids executable terms, such as anonymous functions. The opts are given to the underlying :erlang.binary_to_term/2 call, with an empty list as a default. By default this function does not restrict atoms, as an atom interned in one node may not yet have been interned on another (except for releases, which preload all code). If you want to avoid atoms from being created, then you can pass [:safe] as options, as that will also enable the safety mechanisms from :erlang.binary_to_term/2 itself. Ripped from https://github.com/elixir-plug/plug_crypto/blob/v1.2.0/lib/plug/crypto.ex