AshTypescript.Rpc.ResultProcessor (ash_typescript v0.18.0)

Copy Markdown View Source

Extracts requested fields from RPC results using type-driven dispatch.

All type dispatch uses %Ash.Info.Manifest.Type{} — no raw Ash type atoms or {:array, _} tuples in the primary dispatch path.

Type-Driven Extraction

extract_value/5 (unified type-driven dispatch)
   
   > extract_resource_value/4    (Ash Resources)
   > extract_typed_struct_value/4 (TypedStruct/NewType with field name mapping)
   > extract_typed_map_value/4   (Map/Struct/Tuple/Keyword with fields)
   > extract_union_value/4       (Ash.Type.Union)
   > extract_array_value/5       (Arrays - recurse)
   > normalize_primitive/1       (Primitives)

Summary

Functions

Shapes an %Ash.Page.Offset{}/%Ash.Page.Keyset{} into the client page map. Used for both top-level pagination and nested relationship pagination so the shapes are identical by construction. Keyset cursors are nil on empty pages.

Determines the %Ash.Info.Manifest.Type{} for a given data value. Returns nil for unknown/primitive types.

Functions

build_page_map(page, processed_results)

Shapes an %Ash.Page.Offset{}/%Ash.Page.Keyset{} into the client page map. Used for both top-level pagination and nested relationship pagination so the shapes are identical by construction. Keyset cursors are nil on empty pages.

determine_data_type(data, resource, resource_lookups)

Determines the %Ash.Info.Manifest.Type{} for a given data value. Returns nil for unknown/primitive types.

extract_value(value, type, constraints, template, resource_lookups \\ nil)

@spec extract_value(
  term(),
  atom() | tuple() | Ash.Info.Manifest.Type.t() | nil,
  keyword(),
  list(),
  map() | nil
) :: term()

get_field_or_relationship(resource, field_name, resource_lookups)

@spec get_field_or_relationship(module() | nil, atom(), map() | nil) ::
  Ash.Info.Manifest.Field.t() | Ash.Info.Manifest.Relationship.t() | nil

normalize_primitive(value)

normalize_value_for_json(value)

process(result, extraction_template, resource \\ nil, resource_lookups \\ nil, type_index \\ %{})

@spec process(term(), map(), module() | nil, map() | nil, map()) :: term()

Main entry point for processing Ash results.