AshTypescript.Rpc.FieldProcessing.Atomizer (ash_typescript v0.17.2)

Copy Markdown View Source

Handles preprocessing of requested fields, converting map keys to atoms while preserving field name strings for later reverse mapping lookup.

Field name strings are preserved so that downstream processors can perform proper reverse mapping lookups using the original client field names. The actual conversion to atoms happens in the field processor after the correct internal field name has been resolved.

Summary

Functions

Processes requested fields, converting map keys to atoms for navigation while preserving field name strings for reverse mapping.

Processes a single field, which can be a string, atom, or map structure.

Processes field values, handling lists and nested maps.

Functions

atomize_field(field, formatter, resource)

atomize_field_value(value, formatter, resource, atomize_strings)

atomize_requested_fields(requested_fields, resource \\ nil)

Processes requested fields, converting map keys to atoms for navigation while preserving field name strings for reverse mapping.

For resources with field_names DSL mappings, those are applied to convert client names to internal names. For other types (TypedStructs, NewTypes), strings are preserved for the field processor to handle.

Parameters

  • requested_fields - List of strings/atoms or maps for relationships
  • resource - Optional resource module for field_names DSL lookup

Examples

iex> atomize_requested_fields(["id", "title", %{"user" => ["id", "name"]}])
[:id, :title, %{user: ["id", "name"]}]

iex> atomize_requested_fields([%{"self" => %{"args" => %{"prefix" => "test"}}}])
[%{self: %{args: %{prefix: "test"}}}]

process_field(field, formatter, resource \\ nil)

Processes a single field, which can be a string, atom, or map structure.

For string field names:

  • If resource has a field_names mapping for this client name, returns the mapped atom
  • Otherwise, preserves the string for downstream reverse mapping lookup

For map structures:

  • Converts map keys to atoms (for relationship/calculation navigation)
  • Preserves nested field name strings

process_field_value(value, formatter, resource \\ nil, atomize_strings \\ true)

Processes field values, handling lists and nested maps.

For calculation args (maps with args/fields keys), converts all strings. For field selection lists, preserves strings for type-aware reverse mapping.