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

Copy Markdown

Parsing functionality for Ash-based resource configurations.

Automatically detects and configures context-related functions for resources, such as listing, getting, creating, updating, and deleting elements. Infers function names based on context and schema module conventions using Ash resource naming conventions.

Key Features

  • Automatic function discovery from Ash resources
  • Primary action detection with fallback to first available action
  • Support for paginated and non-paginated read operations
  • Function reference creation with action metadata

Key Constraints

  • Currently only implements read-related actions (:list_function, :list_function_paginated, :get_function)
  • Requires Ash resource configuration
  • Returns placeholder function when no valid action is found
  • Functions are resolved from configured Ash resource

Implemented Options

  • :list_function - Function reference for reading all elements
  • :list_function_paginated - Function reference for reading elements using pagination
  • :get_function - Function reference for getting one element
  • :ash_actor_assign (alias: :actor_assign) - Atom naming the socket.assigns key that holds the actor for policy-protected resources. Default nil. When set, every generated CRUD call forwards actor: socket.assigns[<assign>] to Ash. Non-atom values are silently rejected as a defensive measure against typos.

Example

auix_resource_metadata :template,
  ash_resource: MyApp.Templates.InterfaceDocumentTemplate,
  ash_actor_assign: :current_user      # canonical
  # or, equivalently:
  # actor_assign: :current_user        # alias

See the Ash integration guide — Authorization &amp; policies for the worked example and the full behaviour matrix.

Summary

Functions

Resolves default values for context-derived properties.

Functions

option_value(parsed_opts, arg2, opts, auix_action)

@spec option_value(map(), map(), keyword(), atom()) ::
  Aurora.Uix.Integration.Connector.t() | nil

Resolves default values for context-derived properties.

Discovers Ash actions from the resource, selecting primary actions when available or falling back to the first available action.

Parameters

  • parsed_opts (map()) - Map containing resolved options with :source and :module.
  • resource_config (map()) - Map with keys:
    • :schema (module() | nil) - The Ash resource module.

  • key (atom()) - The Aurora UIX action key (:list_function, :list_function_paginated, :get_function, :change_function, :create_function, :update_function, :delete_function, :new_function).

Returns

Connector.t() | nil - Returns %Connector{} struct with %CrudSpec{} if action found, otherwise returns nil for unhandled keys.

Examples

iex> default_value(%{}, %{context: MyApp.Accounts, schema: MyApp.User}, :list_function)
%Connector{type: :ash, crud_spec: %CrudSpec{...}}

iex> default_value(%{}, %{context: nil, schema: MyApp.Post}, :get_function)
%Connector{type: :ash, crud_spec: %CrudSpec{...}}