Provides helper functions for analyzing Ash actions.
This module contains language-agnostic utilities for determining action characteristics, enabling code generators to produce appropriate client code for different action types.
Features
- Pagination Analysis - Detect offset, keyset, required, and countable pagination
- Input Requirements - Determine if actions require, optionally accept, or have no input
- Return Type Classification - Identify field-selectable return types for generic actions
Usage
Pagination Support
alias AshIntrospection.Codegen.ActionIntrospection
action = AshIntrospection.ResourceInfo.action(MyApp.Post, :list)
if ActionIntrospection.action_supports_pagination?(action) do
# Generate paginated response type
if ActionIntrospection.action_supports_offset_pagination?(action) do
# Include offset/limit parameters
end
if ActionIntrospection.action_supports_keyset_pagination?(action) do
# Include after/before parameters
end
endInput Requirements
case ActionIntrospection.action_input_type(resource, action) do
:required -> # Generate required input parameter
:optional -> # Generate optional input parameter
:none -> # No input parameter needed
end
# Get specific field lists
required_fields = ActionIntrospection.get_required_inputs(resource, action)
optional_fields = ActionIntrospection.get_optional_inputs(resource, action)Generic Action Return Types
case ActionIntrospection.action_returns_field_selectable_type?(action) do
{:ok, :resource, MyApp.User} ->
# Returns a single User, can select fields
{:ok, :array_of_resource, MyApp.User} ->
# Returns array of Users, can select fields
{:ok, :typed_map, fields} ->
# Returns map with typed fields, can select from field list
{:ok, :unconstrained_map, nil} ->
# Returns map without constraints, no field selection
{:error, :not_field_selectable_type} ->
# Returns primitive type, no field selection
{:error, :not_generic_action} ->
# Not a generic action (use standard CRUD handling)
endDesign Notes
The return type analysis uses a type-driven classification pattern with
classify_return_type/2 for consistent handling of all type variants
including resources, typed maps, typed structs, and primitives.
Summary
Functions
Returns true if the action has a default limit configured.
Returns :required | :optional | :none
Returns true if the action requires pagination.
Checks if a generic action returns a field-selectable type.
Returns true if the action supports countable pagination.
Returns true if the action returns a type that supports field selection.
Returns true if the action supports keyset-based pagination.
Returns true if the action supports offset-based pagination.
Returns true if the action supports pagination.
Returns the default limit for the action, or nil if not configured.
Returns the max page size for the action, or nil if not configured.
Returns the list of optional input fields for an action.
Gets the pagination configuration for an action.
Returns the list of required input fields for an action.
Returns true if the action has pagination configuration.
Functions
Returns true if the action has a default limit configured.
Returns :required | :optional | :none
Determines whether an action requires input, has optional input, or has no input. This is based on the action's public arguments and accepted attributes.
Returns true if the action requires pagination.
Checks if a generic action returns a field-selectable type.
Returns:
{:ok, :resource, resource_module}- Single resource{:ok, :array_of_resource, resource_module}- Array of resources{:ok, :typed_map, fields}- Typed map with constraints{:ok, :array_of_typed_map, fields}- Array of typed maps{:ok, :typed_struct, {module, fields}}- Type with field constraints (TypedStruct or similar){:ok, :array_of_typed_struct, {module, fields}}- Array of types with field constraints{:ok, :unconstrained_map, nil}- Map without field constraints{:error, :not_generic_action}- Not a generic action{:error, reason}- Other errors
Returns true if the action supports countable pagination.
Returns true if the action returns a type that supports field selection.
This is a convenience wrapper that returns a boolean.
Returns true if the action supports keyset-based pagination.
Returns true if the action supports offset-based pagination.
Returns true if the action supports pagination.
Examples
iex> action_supports_pagination?(%{type: :read, get?: false, pagination: %{offset?: true}})
true
iex> action_supports_pagination?(%{type: :read, get?: true})
false
Returns the default limit for the action, or nil if not configured.
Returns the max page size for the action, or nil if not configured.
Returns the list of optional input fields for an action.
This returns the field names that can be provided but are not required.
Gets the pagination configuration for an action.
Returns the list of required input fields for an action.
This returns the field names that must be provided (non-nil, no default).
Returns true if the action has pagination configuration.