AshTypescript.TypeSystem.ResourceFields (ash_typescript v0.17.3)

Copy Markdown View Source

Provides unified resource field type lookup.

This module centralizes the logic for looking up field types from Ash resources, supporting attributes, calculations, relationships, and aggregates.

Variants

Both return {type, constraints} tuples, with {nil, []} for unknown fields.

Summary

Functions

Gets the resolved type for an aggregate field.

Gets the type and constraints for any field on a resource.

Gets the type and constraints for public fields only.

Resolves aggregate type info including constraints.

Functions

get_aggregate_type_info(resource, field_name)

@spec get_aggregate_type_info(module(), atom()) :: {atom() | nil, keyword()}

Gets the resolved type for an aggregate field.

Aggregates can have computed types based on the underlying field type. This function returns the fully resolved aggregate type.

Examples

iex> get_aggregate_type_info(MyApp.User, :todo_count)
{Ash.Type.Integer, []}

get_field_type_info(resource, field_name)

@spec get_field_type_info(module(), atom()) :: {atom() | tuple() | nil, keyword()}

Gets the type and constraints for any field on a resource.

Checks attributes, calculations, relationships, and aggregates in order. Uses non-public Ash.Resource.Info functions to access all fields.

Examples

iex> get_field_type_info(MyApp.User, :name)
{Ash.Type.String, []}

iex> get_field_type_info(MyApp.User, :todos)
{{:array, MyApp.Todo}, []}

iex> get_field_type_info(MyApp.User, :unknown)
{nil, []}

get_public_field_type_info(resource, field_name)

@spec get_public_field_type_info(module(), atom()) ::
  {atom() | tuple() | nil, keyword()}

Gets the type and constraints for public fields only.

Checks public attributes, calculations, aggregates, and relationships in order. Used for output formatting where we only want publicly accessible fields.

Examples

iex> get_public_field_type_info(MyApp.User, :name)
{Ash.Type.String, []}

iex> get_public_field_type_info(MyApp.User, :private_field)
{nil, []}

resolve_aggregate_type_info(resource, agg)

@spec resolve_aggregate_type_info(module(), Ash.Resource.Aggregate.t()) ::
  {atom() | tuple() | nil, keyword()}

Resolves aggregate type info including constraints.

For first aggregates with nil type, we need to look up the field on the destination resource to get the actual type and constraints.

Examples

iex> agg = Ash.Resource.Info.aggregate(MyApp.User, :first_todo_title)
iex> resolve_aggregate_type_info(MyApp.User, agg)
{Ash.Type.String, []}