ash v1.24.1 Ash.Type behaviour View Source

This behaviour is a superset of the Ecto.Type behavior, that also contains api level information, like what kinds of filters are allowed. Eventually, this may be used for composite types or serialization.

Much better to use Ash.Type than to say @behaviour Ash.Type and define everything yourself.

Built in types

Composite Types

Currently, the only composite type supported is a list type, specified via: {:array, Type}. The constraints available are:

  • :items - Constraints for the elements of the list. See the contained type's docs for more.

  • :min_length - A minimum length for the items

  • :max_length - A maximum length for the items

  • :nil_items? - Whether or not the list can contain nil items The default value is true.

Link to this section Summary

Functions

Confirms if a casted value matches the provided constraints.

Returns true if the value is a builtin type or adopts the Ash.Type behaviour

Casts input (e.g. unknown) data to an instance of the type, or errors

Casts a value from the data store to an instance of the type, or errors

Casts a value from the Elixir type to a value that the data store can persist

Returns the ecto compatible type for an Ash.Type.

Determines if two values of a given type are equal.

Returns the underlying storage type (the underlying type of the ecto type of the ash type)

Link to this section Types

Specs

constraint_error() :: String.t() | {String.t(), Keyword.t()}

Specs

constraints() :: Keyword.t()

Specs

t() :: atom() | {:array, atom()}

Link to this section Functions

Link to this function

apply_constraints(type, term, constraints)

View Source

Specs

apply_constraints(t(), term(), constraints()) :: :ok | {:error, String.t()}

Confirms if a casted value matches the provided constraints.

Specs

ash_type?(term()) :: boolean()

Returns true if the value is a builtin type or adopts the Ash.Type behaviour

Specs

cast_input(t(), term()) :: {:ok, term()} | {:error, Keyword.t()} | :error

Casts input (e.g. unknown) data to an instance of the type, or errors

Maps to Ecto.Type.cast/2

Specs

cast_stored(t(), term()) :: {:ok, term()} | {:error, keyword()} | :error

Casts a value from the data store to an instance of the type, or errors

Maps to Ecto.Type.load/2

Specs

constraints(t()) :: constraints()
Link to this function

dump_to_native(type, term)

View Source

Specs

dump_to_native(t(), term()) :: {:ok, term()} | {:error, keyword()} | :error

Casts a value from the Elixir type to a value that the data store can persist

Maps to Ecto.Type.dump/2

Specs

ecto_type(t()) :: Ecto.Type.t()

Returns the ecto compatible type for an Ash.Type.

If you use Ash.Type, this is created for you. For builtin types this may return a corresponding ecto builtin type (atom)

Link to this function

equal?(type, left, right)

View Source

Specs

equal?(t(), term(), term()) :: boolean()

Determines if two values of a given type are equal.

Maps to Ecto.Type.equal?/3

Specs

get_type(atom() | module()) :: atom() | module()

Specs

storage_type(t()) :: Ecto.Type.t()

Returns the underlying storage type (the underlying type of the ecto type of the ash type)

Link to this section Callbacks

Link to this callback

apply_constraints(term, constraints)

View Source

Specs

apply_constraints(term(), constraints()) ::
  :ok | {:error, constraint_error() | [constraint_error()]}

Specs

cast_input(term()) :: {:ok, term()} | {:error, Keyword.t()} | :error

Specs

cast_stored(term()) :: {:ok, term()} | :error

Specs

constraints() :: constraints()

Specs

dump_to_native(term()) :: {:ok, term()} | :error

Specs

ecto_type() :: Ecto.Type.t()

Specs

equal?(term(), term()) :: boolean()

Specs

storage_type() :: Ecto.Type.t()