Ash.Info.Manifest.Type (ash v3.25.1)

Copy Markdown View Source

Represents a resolved type in the API specification.

Named type modules (Ash.Type.Enum implementations and Ash.Type.NewType subtypes) are referenced via kind: :type_ref inline, with their full definitions in %Ash.Info.Manifest{}.types. This prevents circular references and mirrors how resources are referenced via kind: :resource with definitions in %Ash.Info.Manifest{}.resources.

Primitive types (string, integer, etc.) and anonymous containers (map/keyword/tuple without a named module) are still resolved inline.

Summary

Functions

Returns the effective module for a type — instance_of if set, otherwise module.

Returns the effective resource module for a type.

Finds a sub-field by name from the type's field descriptors.

Finds the type of a sub-field by name.

Finds a union member by name from the type's members.

Returns the list of field descriptors for a type.

Returns true if the type has nested field descriptors (.fields or .element_types).

Returns true if the type represents a resource (:resource or :embedded_resource).

Types

kind()

@type kind() ::
  :string
  | :integer
  | :boolean
  | :float
  | :decimal
  | :uuid
  | :date
  | :datetime
  | :utc_datetime
  | :utc_datetime_usec
  | :naive_datetime
  | :time
  | :time_usec
  | :duration
  | :binary
  | :atom
  | :ci_string
  | :term
  | :enum
  | :union
  | :resource
  | :embedded_resource
  | :map
  | :struct
  | :array
  | :tuple
  | :keyword
  | :type_ref
  | :any
  | :unknown

t()

@type t() :: %Ash.Info.Manifest.Type{
  allow_nil?: boolean() | nil,
  constraints: keyword() | nil,
  custom: map(),
  element_types: [%{name: atom(), type: t(), allow_nil?: boolean()}] | nil,
  fields: [%{name: atom(), type: t(), allow_nil?: boolean()}] | nil,
  instance_of: atom() | nil,
  item_type: t() | nil,
  kind: kind(),
  members: [%{name: atom(), type: t()}] | nil,
  module: atom() | nil,
  name: String.t(),
  resource_module: atom() | nil,
  values: [atom()] | nil
}

Functions

effective_module(type)

@spec effective_module(t()) :: atom() | nil

Returns the effective module for a type — instance_of if set, otherwise module.

For struct types wrapping a module (NewTypes, TypedStructs), instance_of points to the original module. For other types, module is the Ash type module.

effective_resource(t)

@spec effective_resource(t()) :: atom() | nil

Returns the effective resource module for a type.

For resource/embedded_resource types, returns resource_module. Falls back to effective_module/1.

find_field(type, field_name)

@spec find_field(t(), atom()) ::
  %{name: atom(), type: t(), allow_nil?: boolean()} | nil

Finds a sub-field by name from the type's field descriptors.

Returns the field map (%{name, type, allow_nil?}) or nil if not found.

find_field_type(type, field_name)

@spec find_field_type(t(), atom()) :: t() | nil

Finds the type of a sub-field by name.

Returns the %Ash.Info.Manifest.Type{} of the field, or nil if not found.

find_member(arg1, member_name)

@spec find_member(t(), atom()) :: map() | nil

Finds a union member by name from the type's members.

Returns the member map (%{name, type, tag, tag_value}) or nil.

get_fields(arg1)

@spec get_fields(t()) :: [%{name: atom(), type: t(), allow_nil?: boolean()}]

Returns the list of field descriptors for a type.

Checks .fields first (for map/struct/keyword), then .element_types (for tuple). Returns an empty list if neither is populated.

Each field is a map with :name, :type (%Ash.Info.Manifest.Type{}), and :allow_nil?.

has_fields?(arg1)

@spec has_fields?(t()) :: boolean()

Returns true if the type has nested field descriptors (.fields or .element_types).

resource_kind?(arg1)

@spec resource_kind?(t()) :: boolean()

Returns true if the type represents a resource (:resource or :embedded_resource).