Aurora.Uix.Integration.Ash.ContextParserDefaults (Aurora UIX v0.1.5-rc.1)

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

Fills in any missing options with default values derived from the Ecto schema or Ash resource. This function can be used to ensure that all necessary options are populated, even if the user did not explicitly provide them. The implementation can be customized to fill in defaults based on the schema or resource configuration.

Filters out options that are not relevant based on the presence of related options.

Resolves default values for context-derived properties.

Functions

fill_missing_options(parsed_opts, resource_config)

@spec fill_missing_options(map(), map()) :: map()

Fills in any missing options with default values derived from the Ecto schema or Ash resource. This function can be used to ensure that all necessary options are populated, even if the user did not explicitly provide them. The implementation can be customized to fill in defaults based on the schema or resource configuration.

Parameters

  • parsed_opts (map()): The current map of parsed options that may be missing some keys.
  • resource_config (map()): The resource configuration that may contain the Ecto schema or Ash resource information needed to derive default values.

Returns

  • map(): The updated map of parsed options with missing values filled in.

filter_options(valid_options, resource_opts)

Filters out options that are not relevant based on the presence of related options.

In the ash case, update and change actions are usually the same. In this case we want to use the primary update action if neither of them were defined. But if only one of them is defined, then both should used the same provided action.

The fill_missing_options in in charge of 'copying' the missing one, thus ensuring that both are the same wether one or none were provided and respect the distinction if both were provided.

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{...}}