Ash.Info.Manifest (ash v3.25.0)

Copy Markdown View Source

Generates a language-agnostic API specification from Ash resources and actions.

Given a list of {resource, action_name} tuples or an OTP app, traverses the type graph to find all reachable resources and types, producing structured IR (Elixir structs) that can also be serialized to JSON.

Operator canonical name vs. alias

%Operator{}.name is the user-facing symbol that appears in Ash.Query.filter expressions (e.g. :==, :<, :in). The %Operator{}.aliases list carries internal/legacy module-derived names (e.g. :eq, :less_than) for backward-compatible rendering. New code should prefer name; alias-substitution is for tools that historically rendered the module-derived spelling.

Summary

Functions

Builds an action lookup map from the spec, keyed by {resource_module, action_name}.

Returns the resolved %ApplicableCustomExpression{} list for {resource_module, field_name}. See applicable_filter_operators/2 for behavior.

Returns the resolved %ApplicableFunction{} list for {resource_module, field_name}. See applicable_filter_operators/2 for behavior.

Returns the resolved %ApplicableOperator{} list for {resource_module, field_name}.

Builds a custom-expression lookup map from the spec, keyed by expression name atom.

Builds a function lookup map from the spec, keyed by function name atom.

Generate an API specification for the given OTP app.

Generates a spec and returns the resource lookup map directly.

Gets an action by resource module and action name from an action lookup.

Gets a field by resource module and field name.

Gets a field or relationship by name, checking fields first.

Gets an identity by resource module and identity name.

Gets a relationship by resource module and relationship name.

Looks up a resource by module. Returns nil if not found.

Looks up a resource by module. Raises if not found.

Looks up a named type's full definition by module. Returns nil if not found.

Looks up a named type's full definition by module. Raises if not found.

Checks if a resource exists in the lookup.

Builds an operator lookup map from the spec, keyed by operator name atom.

Gets the primary key field names by resource module.

Builds a resource lookup map from the spec, keyed by resource module.

The schema version of the manifest's JSON serialization format.

Builds a type lookup map from the spec, keyed by named type module.

Types

action_lookup()

@type action_lookup() :: %{required({atom(), atom()}) => Ash.Info.Manifest.Action.t()}

resource_lookup()

@type resource_lookup() :: %{required(atom()) => Ash.Info.Manifest.Resource.t()}

t()

@type t() :: %Ash.Info.Manifest{
  custom: map(),
  entrypoints: [Ash.Info.Manifest.Entrypoint.t()],
  filter_capabilities: Ash.Info.Manifest.FilterCapabilities.t() | nil,
  resources: [Ash.Info.Manifest.Resource.t()],
  sort_capabilities: Ash.Info.Manifest.SortCapabilities.t() | nil,
  types: [Ash.Info.Manifest.Type.t()]
}

type_lookup()

@type type_lookup() :: %{required(atom()) => Ash.Info.Manifest.Type.t()}

Functions

action_lookup(manifest)

@spec action_lookup(t()) :: action_lookup()

Builds an action lookup map from the spec, keyed by {resource_module, action_name}.

applicable_filter_custom_expressions(manifest, arg)

@spec applicable_filter_custom_expressions(
  t(),
  {atom(), atom()}
) :: [Ash.Info.Manifest.ApplicableCustomExpression.t()]

Returns the resolved %ApplicableCustomExpression{} list for {resource_module, field_name}. See applicable_filter_operators/2 for behavior.

applicable_filter_functions(manifest, arg)

@spec applicable_filter_functions(
  t(),
  {atom(), atom()}
) :: [Ash.Info.Manifest.ApplicableFunction.t()]

Returns the resolved %ApplicableFunction{} list for {resource_module, field_name}. See applicable_filter_operators/2 for behavior.

applicable_filter_operators(manifest, arg)

@spec applicable_filter_operators(
  t(),
  {atom(), atom()}
) :: [Ash.Info.Manifest.ApplicableOperator.t()]

Returns the resolved %ApplicableOperator{} list for {resource_module, field_name}.

Returns [] when the field exists but is not filterable. Raises if the resource or field is unknown.

custom_expression_lookup(manifest)

@spec custom_expression_lookup(t()) :: %{
  required(atom()) => Ash.Info.Manifest.CustomExpression.t()
}

Builds a custom-expression lookup map from the spec, keyed by expression name atom.

function_lookup(manifest)

@spec function_lookup(t()) :: %{required(atom()) => Ash.Info.Manifest.Function.t()}

Builds a function lookup map from the spec, keyed by function name atom.

generate(opts)

@spec generate(keyword()) :: {:ok, t()} | {:error, term()}

Generate an API specification for the given OTP app.

Options

  • :otp_app - The OTP app to scan for Ash domains and resources (required)
  • :action_entrypoints - Optional list of {resource_module, action_name} tuples used as entrypoints for deriving the spec. When omitted, all public actions across all domains are included.

generate_resource_lookup(opts)

@spec generate_resource_lookup(keyword()) ::
  {:ok, resource_lookup()} | {:error, term()}

Generates a spec and returns the resource lookup map directly.

get_action(action_lookup, resource_module, action_name)

@spec get_action(action_lookup(), atom(), atom()) ::
  Ash.Info.Manifest.Action.t() | nil

Gets an action by resource module and action name from an action lookup.

get_field(resource_lookup, resource_module, field_name)

@spec get_field(resource_lookup(), atom(), atom()) ::
  Ash.Info.Manifest.Field.t() | nil

Gets a field by resource module and field name.

get_field_or_relationship(resource_lookup, resource_module, name)

@spec get_field_or_relationship(resource_lookup(), atom(), atom()) ::
  Ash.Info.Manifest.Field.t() | Ash.Info.Manifest.Relationship.t() | nil

Gets a field or relationship by name, checking fields first.

Returns %Ash.Info.Manifest.Field{}, %Ash.Info.Manifest.Relationship{}, or nil.

get_identity(resource_lookup, resource_module, identity_name)

@spec get_identity(resource_lookup(), atom(), atom()) :: %{keys: [atom()]} | nil

Gets an identity by resource module and identity name.

get_relationship(resource_lookup, resource_module, rel_name)

@spec get_relationship(resource_lookup(), atom(), atom()) ::
  Ash.Info.Manifest.Relationship.t() | nil

Gets a relationship by resource module and relationship name.

get_resource(resource_lookup, module)

@spec get_resource(resource_lookup(), atom()) :: Ash.Info.Manifest.Resource.t() | nil

Looks up a resource by module. Returns nil if not found.

get_resource!(resource_lookup, module)

@spec get_resource!(resource_lookup(), atom()) :: Ash.Info.Manifest.Resource.t()

Looks up a resource by module. Raises if not found.

get_type(type_lookup, module)

@spec get_type(type_lookup(), atom()) :: Ash.Info.Manifest.Type.t() | nil

Looks up a named type's full definition by module. Returns nil if not found.

get_type!(type_lookup, module)

@spec get_type!(type_lookup(), atom()) :: Ash.Info.Manifest.Type.t()

Looks up a named type's full definition by module. Raises if not found.

A miss indicates a reachability bug: the type was referenced via :type_ref somewhere in the type graph but was never registered during spec generation. Reachability analysis (Ash.Info.Manifest.Generator.Reachability) should have collected it as a standalone type.

has_resource?(resource_lookup, module)

@spec has_resource?(resource_lookup(), atom()) :: boolean()

Checks if a resource exists in the lookup.

operator_lookup(manifest)

@spec operator_lookup(t()) :: %{required(atom()) => Ash.Info.Manifest.Operator.t()}

Builds an operator lookup map from the spec, keyed by operator name atom.

Returns an empty map when filter_capabilities is nil.

primary_key(resource_lookup, resource_module)

@spec primary_key(resource_lookup(), atom()) :: [atom()]

Gets the primary key field names by resource module.

resource_lookup(manifest)

@spec resource_lookup(t()) :: resource_lookup()

Builds a resource lookup map from the spec, keyed by resource module.

schema_version()

@spec schema_version() :: String.t()

The schema version of the manifest's JSON serialization format.

Bumped when the JSON output schema in Ash.Info.Manifest.JsonSerializer changes in a way downstream tools need to detect.

type_lookup(manifest)

@spec type_lookup(t()) :: type_lookup()

Builds a type lookup map from the spec, keyed by named type module.

Each entry is the fully-resolved %Ash.Info.Manifest.Type{} for a named type (Ash.Type.Enum implementations and Ash.Type.NewType subtypes) referenced somewhere in the reachable type graph.