Aurora.Uix.Integration.Ash.FieldsParser (Aurora UIX v0.1.4-rc.6)

Copy Markdown

Helper functions for converting Ash Framework types to Ecto types.

Facilitates type mapping between Ash resources and Ecto schemas, enabling proper field type resolution for layout and form generation.

Key Features

  • Comprehensive mapping of Ash types to Ecto-compatible types
  • Support for both parameterized Ash types and their EctoType variants
  • Fallback handling for unknown or custom types
  • Direct passthrough for native Ecto types
  • HTML5 input type mapping for form generation
  • Field metadata extraction for select/enum types

Key Constraints

  • Only handles parameterized Ash types in tuple format {:parameterized, {type, opts}}
  • Unknown parameterized types default to :string
  • Requires Ash Framework type structure

Summary

Functions

Processes embedded resources from an Ash resource schema.

Parses all relationships from an Ash resource.

Parses a single field from an Ash resource into a Field struct.

Parses all attributes from an Ash resource into Field structs.

Functions

embedded_resource(parent_resource, result)

@spec embedded_resource({atom(), module(), atom()}, [Aurora.Uix.Resource.t()]) :: [
  Aurora.Uix.Resource.t()
]

Processes embedded resources from an Ash resource schema.

Recursively discovers and configures embedded resources from the parent resource, creating new resource configurations for each embedded field found.

Parameters

  • parent_resource ({atom(), module(), atom()}) - Tuple containing parent resource name, schema module, and type.
  • result (list(Resource.t())) - Accumulator list of resource configurations.

Returns

list(Resource.t()) - Updated list with embedded resource configurations added.

Examples

iex> embedded_resource({:users, MyApp.User, :ash}, [])
[%Resource{name: :users__profile, ...}]

parse_associations(resource_schema, resource_name, resources, fields)

@spec parse_associations(module(), atom(), [Aurora.Uix.Resource.t()], [
  Aurora.Uix.Field.t()
]) :: [
  Aurora.Uix.Field.t()
]

Parses all relationships from an Ash resource.

Iterates through resource relationships and converts each into a Field struct with proper relationship metadata and type information.

Parameters

  • resource_schema (module()) - The schema module containing relationships.
  • resource_name (atom()) - The name of the resource.
  • resources (list(Resource.t())) - List of available resources for reference lookup.
  • fields (list(Field.t())) - Existing fields list to prepend associations to.

Returns

list(Field.t()) - Updated list with relationship fields added.

parse_field(resource_schema, resource_name, schema_field_key, attributes \\ %{})

@spec parse_field(module(), atom(), atom() | {atom(), term()}, map()) ::
  Aurora.Uix.Field.t()

Parses a single field from an Ash resource into a Field struct.

Generates a field configuration including display attributes, HTML input types, validation constraints, and association metadata.

Parameters

  • resource_schema (module()) - The schema module for the resource.
  • resource_name (atom()) - The name of the resource this field belongs to.
  • schema_field_key (atom() | {atom(), term()}) - The field identifier or tuple with type.

  • attributes (map()) - Map of attributes with their specifications.

Returns

Field.t() - A fully configured field struct.

parse_fields(resource_schema, resource_name)

@spec parse_fields(module() | nil, atom()) :: [Aurora.Uix.Field.t()]

Parses all attributes from an Ash resource into Field structs.

Extracts field metadata from the resource and converts each attribute into a structured Field configuration with type information and display attributes.

Parameters

  • resource_schema (module() | nil) - The Ash resource module to parse fields from.

  • resource_name (atom()) - The identifier for the resource.

Returns

list(Field.t()) - List of configured field structs, or empty list if schema is nil.