AshTypescript.Rpc.Codegen.Helpers.ActionIntrospection (ash_typescript v0.18.0)

Copy Markdown View Source

Provides helper functions for analyzing Ash actions.

This module contains utilities for determining action characteristics like:

  • Pagination support (offset, keyset, required, countable)
  • Input requirements
  • Return type field selectability

The return type analysis uses a type-driven classification pattern with classify_return_type/2 for consistent handling of all type variants.

Summary

Functions

Returns true if input_name refers to an accepted attribute on resource (i.e. present in the manifest resource's fields map) rather than a declared action argument. Used to decide whether to apply field-name mapping or argument-name mapping to an Ash.Info.Manifest.Argument.

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 supports keyset-based pagination.

Returns true if the action supports offset-based pagination.

Returns true if the action supports pagination.

Pure computation of action_returns_field_selectable_type?/1, taking an explicit type_lookup so it can run during manifest decoration (before the :type_lookup is persisted). The decorator stores the result on the action's custom.ash_typescript so the runtime path is a plain map read.

Resolves the TypeScript client name for an action input.

Looks up an action in the configured manifest's action lookup and raises on miss.

Functions

accepted_attribute?(resource, input_name, resource_lookup)

Returns true if input_name refers to an accepted attribute on resource (i.e. present in the manifest resource's fields map) rather than a declared action argument. Used to decide whether to apply field-name mapping or argument-name mapping to an Ash.Info.Manifest.Argument.

action_has_default_limit?(action)

Returns true if the action has a default limit configured.

action_input_type(action)

Returns :required | :optional | :none.

Inspects the action's unified inputs list. Each Ash.Info.Manifest.Argument carries required? directly — describing input presence independent of value shape (allow_nil? / has_default?).

action_requires_pagination?(action)

Returns true if the action requires pagination.

action_returns_field_selectable_type?(action)

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
  • {:ok, :array_of_unconstrained_map, nil} - Array of maps without field constraints
  • {:error, :not_generic_action} - Not a generic action
  • {:error, reason} - Other errors

action_supports_countable?(action)

Returns true if the action supports countable pagination.

action_supports_keyset_pagination?(action)

Returns true if the action supports keyset-based pagination.

action_supports_offset_pagination?(action)

Returns true if the action supports offset-based pagination.

action_supports_pagination?(action)

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

compute_action_returns_field_selectable_type?(action, type_lookup)

Pure computation of action_returns_field_selectable_type?/1, taking an explicit type_lookup so it can run during manifest decoration (before the :type_lookup is persisted). The decorator stores the result on the action's custom.ash_typescript so the runtime path is a plain map read.

format_input_name(resource, action_name, input_name, resource_lookup, formatter \\ nil)

Resolves the TypeScript client name for an action input.

Accepted attributes (present in the resource's field map) use field-name mapping via format_field_for_client/3 (resource-aware, honors field_names DSL). Declared action arguments use argument_names mapping via format_field_name/2 (formatter only — arguments don't carry resource field metadata).

get_action!(resource, action_name)

Looks up an action in the configured manifest's action lookup and raises on miss.

Use at runtime sites that have already validated action existence upstream (e.g. Pipeline.discover_action/2 returns {:error, {:action_not_found, …}} before reaching parse-time lookup), so a miss here indicates an internal consistency error rather than user input.