AshTypescript.Rpc.InputFormatter (ash_typescript v0.17.2)

Copy Markdown View Source

Formats input data from client format to internal format.

This module handles the conversion of client-provided field names and values to the internal representation expected by Ash actions. It focuses specifically on action arguments and accepted attributes, then delegates to ValueFormatter for recursive type-aware formatting of nested values.

Key responsibilities:

  • Convert client field names to internal atom keys (e.g., "userId" -> :user_id)
  • Preserve untyped map keys exactly as received
  • Handle nested structures within input data via ValueFormatter
  • Work only with action arguments and accepted attributes (simplified scope)

Summary

Functions

Builds a map of expected client field names to internal Elixir field names.

Formats input data from client format to internal format.

Functions

build_expected_keys_map(resource, action, input_formatter)

Builds a map of expected client field names to internal Elixir field names.

This map is used to correctly parse incoming input data by looking up the exact client name that codegen would have generated, rather than blindly applying formatter transformations.

Parameters

  • resource: The Ash resource module
  • action: The action struct
  • formatter: The field formatter configuration

Returns

A map where keys are client field names (strings) and values are internal Elixir field names (atoms).

Example

%{
  "userName" => :user_name,
  "isActive" => :is_active?,
  "addressLine1" => :address_line_1
}

format(data, resource, action_name_or_action, formatter)

Formats input data from client format to internal format.

Converts client field names to internal format while preserving untyped map keys. Only processes action arguments and accepted attributes - no relationships, calculations, or aggregates.

Parameters

  • data: The input data from the client
  • resource: The Ash resource module
  • action_name_or_action: The name of the action or the action struct itself
  • formatter: The field formatter to use for conversion

Returns

The formatted data with client field names converted to internal atom keys, except for untyped map keys which are preserved exactly.