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

Copy Markdown View Source

Represents a resource in the API specification.

Resources are pure type/shape definitions. Fields and relationships are stored as maps keyed by atom name for O(1) lookup. Actions live separately in %Ash.Info.Manifest{}.entrypoints.

Summary

Functions

Returns relationships whose destination is in the allowed list, sorted by name.

Returns all fields as a list, sorted by name.

Returns all relationships as a list, sorted by name.

Returns all field names (attributes, calculations, aggregates), sorted.

Returns all fields of a given kind (:attribute, :calculation, or :aggregate), sorted by name.

Gets a field (attribute, calculation, or aggregate) by name.

Gets an identity by name.

Gets a relationship by name.

Checks if a field or relationship exists by name.

Returns all relationship names, sorted.

Types

t()

@type t() :: %Ash.Info.Manifest.Resource{
  custom: map(),
  description: String.t() | nil,
  embedded?: boolean(),
  fields: %{required(atom()) => Ash.Info.Manifest.Field.t()},
  identities: %{required(atom()) => %{keys: [atom()]}},
  module: atom(),
  multitenancy:
    %{strategy: atom(), global?: boolean(), attribute: atom()} | nil,
  name: String.t(),
  primary_key: [atom()],
  relationships: %{required(atom()) => Ash.Info.Manifest.Relationship.t()}
}

Functions

accessible_relationships(resource, allowed_resources)

@spec accessible_relationships(t(), [atom()] | MapSet.t()) :: [
  Ash.Info.Manifest.Relationship.t()
]

Returns relationships whose destination is in the allowed list, sorted by name.

all_fields(resource)

@spec all_fields(t()) :: [Ash.Info.Manifest.Field.t()]

Returns all fields as a list, sorted by name.

Sorting ensures codegen output is deterministic across runs (Erlang map iteration order is unstable for maps with more than 32 keys).

all_relationships(resource)

@spec all_relationships(t()) :: [Ash.Info.Manifest.Relationship.t()]

Returns all relationships as a list, sorted by name.

field_names(resource)

@spec field_names(t()) :: [atom()]

Returns all field names (attributes, calculations, aggregates), sorted.

fields_by_kind(resource, kind)

@spec fields_by_kind(t(), Ash.Info.Manifest.Field.kind()) :: [
  Ash.Info.Manifest.Field.t()
]

Returns all fields of a given kind (:attribute, :calculation, or :aggregate), sorted by name.

get_field(resource, name)

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

Gets a field (attribute, calculation, or aggregate) by name.

get_identity(resource, name)

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

Gets an identity by name.

get_relationship(resource, name)

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

Gets a relationship by name.

has_field?(resource, name)

@spec has_field?(t(), atom()) :: boolean()

Checks if a field or relationship exists by name.

relationship_names(resource)

@spec relationship_names(t()) :: [atom()]

Returns all relationship names, sorted.