#
View Source Ash.Type.NewType behaviour (ash v2.14.2)

Allows defining a new type that is the combination of an existing type and custom constraints

A subtle difference between this type and its supertype (one that will almost certainly not matter in any case) is that we use the `apply_constraints` logic of the underlying type in the same step as `cast_input`. We do this because new types like these are, generally speaking, considering the constraint application as part of the core type. Other types, if you simply do `Ash.Type.cast_input/3` you will not be also applying their constraints.

For Example:

    defmodule MyApp.Types.SSN do
      use Ash.Type.NewType, subtype_of: :string, constraints: [match: ~r/regex for ssn/]
    end

    defmodule MyApp.Types.Metadata do
      use Ash.Type.NewType, subtype_of: :union, constraints: [types: [
        foo: [...],
        bar: [...]
      ]]
    end

# Link to this section Summary

## Types

t()

## Callbacks

subtype_constraints()
subtype_of()
type_constraints(constraints, subtype_constraints)

## Functions

constraints(type, constraints)
new_type?(type)
subtype_of(type)

# Link to this section Types

Link to this type

# t()

View Source

    @type t() :: module() | atom() | {:array, module() | atom()}

# Link to this section Callbacks

Link to this callback

# subtype_constraints()

View Source

    @callback subtype_constraints() :: Keyword.t()

Link to this callback

# subtype_of()

View Source

    @callback subtype_of() :: module() | atom()

Link to this callback

# type_constraints(constraints, subtype_constraints)

View Source

    @callback type_constraints(constraints :: Keyword.t(), subtype_constraints :: Keyword.t()) ::
      Keyword.t()

# Link to this section Functions

Link to this function

# constraints(type, constraints)

View Source
Link to this function

# new_type?(type)

View Source

    @spec new_type?(Ash.Type.t()) :: boolean()

Link to this function

# subtype_of(type)

View Source

    @spec subtype_of(t()) :: Ash.Type.t()