Pax.Adapter behaviour (Pax v0.0.1-dev)

View Source

Summary

Types

A Phoenix.LiveView socket

t()

Unsigned params from a Phoenix.LiveView handle_params/3

Types

adapter_module()

@type adapter_module() :: module()

callback_module()

@type callback_module() :: module()

lookup()

@type lookup() :: %{required(atom()) => any()}

object()

@type object() :: %{required(atom()) => any()}

opts()

@type opts() ::
  binary()
  | tuple()
  | atom()
  | integer()
  | float()
  | [opts()]
  | %{optional(opts()) => opts()}
  | MapSet.t()

scope()

@type scope() :: %{required(atom()) => any()}

socket()

@type socket() :: Phoenix.LiveView.Socket.t()

A Phoenix.LiveView socket

t()

@type t() :: %Pax.Adapter{module: term(), opts: term()}

unsigned_params()

@type unsigned_params() :: Phoenix.LiveView.unsigned_params()

Unsigned params from a Phoenix.LiveView handle_params/3

Callbacks

cast(opts, object, unsigned_params, fields)

@callback cast(opts(), object(), unsigned_params(), fields :: [Pax.Field.t()]) ::
  Ecto.Changeset.t()

config_spec(opts)

@callback config_spec(opts()) :: map()

A function that returns a valid Pax.Config spec for configuration keys and types accepted by the adapter.

count_objects(opts, scope)

@callback count_objects(opts(), scope()) :: integer()

create_object(opts, object, t)

@callback create_object(opts(), object(), Ecto.Changeset.t()) ::
  {:ok, map()} | {:error, Ecto.Changeset.t()}

default_fields(opts)

@callback default_fields(opts()) :: Pax.Index.fields()

field_type(opts, field_name)

@callback field_type(opts(), field_name :: atom()) ::
  {:ok, atom() | module()} | {:error, term()}

get_object(opts, lookup, scope, socket)

@callback get_object(opts(), lookup(), scope(), socket()) :: object()

id_fields(opts)

@callback id_fields(opts()) :: [atom()] | nil

init(callback_module, opts)

@callback init(callback_module(), opts :: []) :: opts()

The adapter initialization function, must return a map of initialized adapter state.

list_objects(opts, scope)

@callback list_objects(opts(), scope()) :: [object()]

merge_config(opts, config, socket)

@callback merge_config(opts(), config :: map(), socket()) :: map()

A function that merges any additional configuration options into the adapter's opts map.

new_object(opts, socket)

@callback new_object(opts(), socket()) :: object()

object_ids(opts, object)

@callback object_ids(opts(), object()) :: [String.Chars.t()] | nil

object_name(opts, object)

@callback object_name(opts(), object()) :: String.t() | nil

plural_name(opts)

@callback plural_name(opts()) :: String.t()

singular_name(opts)

@callback singular_name(opts()) :: String.t()

update_object(opts, object, t)

@callback update_object(opts(), object(), Ecto.Changeset.t()) ::
  {:ok, map()} | {:error, Ecto.Changeset.t()}

Functions

cast(adapter, object, params, fields)

@spec cast(t(), object(), unsigned_params(), fields :: [Pax.Field.t()]) ::
  Ecto.Changeset.t()

config_spec(adapter)

@spec config_spec(t()) :: map()

count_objects(adapter, scope)

@spec count_objects(t(), scope()) :: integer()

create_object(adapter, object, changeset)

default_fields(adapter)

@spec default_fields(t()) :: Pax.Index.fields()

field_type!(adapter, field_name)

@spec field_type!(t(), field_name :: atom()) :: atom()

get_object(adapter, lookup, scope, socket)

@spec get_object(t(), lookup(), scope(), socket()) :: object()

id_fields(adapter)

@spec id_fields(t()) :: [atom()] | nil

init(adapter_module, callback_module, opts \\ [])

list_objects(adapter, scope)

@spec list_objects(t(), scope()) :: [object()]

merge_config(adapter, config, socket)

new_object(adapter, socket)

@spec new_object(t(), socket()) :: object()

object_ids(adapter, object)

@spec object_ids(t(), object()) :: [String.Chars.t()]

object_name(adapter, object)

@spec object_name(t(), object()) :: String.t() | nil

plural_name(adapter)

@spec plural_name(t()) :: String.t() | nil

singular_name(adapter)

@spec singular_name(t()) :: String.t() | nil

update_object(adapter, object, changeset)

@spec update_object(t(), object(), Ecto.Changeset.t()) ::
  {:ok, any()} | {:error, Ecto.Changeset.t()}
@spec update_object(t(), object(), Ecto.Changeset.t()) ::
  {:ok, any()} | {:error, Ecto.Changeset.t()}