Extracts requested fields from RPC results using type-driven dispatch.
This module uses the same pattern as ValueFormatter and FieldSelector:
type-driven recursive dispatch where each type is self-describing.
Architecture
The core insight is that both ValueFormatter and ResultProcessor need to
understand type structure:
- ValueFormatter: Formats field names (internal ↔ client)
- ResultProcessor: Extracts requested fields (filtering)
They share the need for type-driven recursive dispatch but have different concerns.
Type-Driven Extraction
extract_value/4 (unified type-driven dispatch)
│
├─> extract_resource_value/3 (Ash Resources)
├─> extract_typed_struct_value/3 (TypedStruct/NewType)
├─> extract_typed_map_value/3 (Map/Struct with fields)
├─> extract_union_value/3 (Ash.Type.Union)
├─> extract_array_value/4 (Arrays - recurse)
└─> normalize_primitive/1 (Primitives)
Summary
Functions
Determines the type and constraints for a given data value.
Extracts and normalizes a value based on its type and template.
Gets the type and constraints for a field, checking all field sources.
Normalizes a value for JSON serialization.
Alias for normalize_primitive/1 for backwards compatibility. Normalizes a value for JSON serialization.
Main entry point for processing Ash results.
Functions
Determines the type and constraints for a given data value.
This function infers type information from:
- The struct type of the data itself (if it's a struct)
- The provided resource context
- Falls back to nil for unknown types
Extracts and normalizes a value based on its type and template.
This is the core recursive function that dispatches to type-specific
handlers based on the type's characteristics. Mirrors the pattern
used in ValueFormatter.format/5.
Parameters
value- The value to extract fromtype- The Ash type (or nil for unknown)constraints- Type constraintstemplate- The extraction template (list of field specs)
Returns
The extracted and normalized value.
Gets the type and constraints for a field, checking all field sources.
This consolidates all the previous resource lookup functions into one.
Parameters
resource- The Ash resource module, TypedStruct module, or nilfield_name- The field name (atom)
Returns
{type, constraints} or {nil, []} if not found.
Normalizes a value for JSON serialization.
Handles DateTime, Date, Time, Decimal, CiString, atoms, keyword lists, nested maps, regular lists, and Ash.Union types. Recursively normalizes nested structures.
Alias for normalize_primitive/1 for backwards compatibility. Normalizes a value for JSON serialization.
Main entry point for processing Ash results.