AshTypescript.Rpc.Pipeline (ash_typescript v0.18.0)

Copy Markdown View Source

Implements the four-stage pipeline:

  1. parse_request/3 - Parse and validate input with fail-fast
  2. execute_ash_action/1 - Execute Ash operations
  3. filter_result_fields/2 - Apply field selection
  4. format_output/2 - Format for client consumption

Action shape

Stage 1 resolves the action by reading from the configured manifest's action lookup, so every downstream stage receives %Ash.Info.Manifest.Action{}. Consumers should rely on:

  • action.inputs — unified arguments + accepted attributes, each carrying a resolved %Ash.Info.Manifest.Type{} (no separate :constraints field; constraints are folded into the resolved type).
  • action.returns%Ash.Info.Manifest.Type{} or nil.
  • action.pagination%Ash.Info.Manifest.Pagination{} (uses :countable?, not :countable).
  • action.metadata — list of %Ash.Info.Manifest.Metadata{} whose :type is already resolved.

Raw-Ash fields (arguments, accept, constraints, allow_nil_input, require_attributes) are NOT present. Use AshTypescript.Rpc.Codegen.Helpers.ActionIntrospection.get_action!/2 for manifest lookups in runtime code paths instead of Ash.Resource.Info.action/2.

Summary

Functions

Stage 2: Execute Ash action using the parsed request.

Looks up the manifest entrypoint for a typed query by name.

Stage 4: Format output for client consumption.

Stage 4: Format output for client consumption with type awareness.

Stage 1: Parse and validate request.

Stage 3: Filter result fields using the extraction template.

Functions

execute_ash_action(request)

@spec execute_ash_action(AshTypescript.Rpc.Request.t()) ::
  {:ok, term()} | {:error, term()}

Stage 2: Execute Ash action using the parsed request.

Builds the appropriate Ash query/changeset and executes it. Returns the raw Ash result for further processing.

find_typed_query(typed_query_name)

Looks up the manifest entrypoint for a typed query by name.

Returns the %Ash.Info.Manifest.Entrypoint{} or nil. Public because Rpc.run_typed_query/4 needs the same lookup to read the query's fields before delegating to run_action/3.

format_output(filtered_result)

Stage 4: Format output for client consumption.

Applies output field formatting and final response structure.

The error clause handles failures raised before a %Request{} exists (action discovery, identity resolution, parameter validation); errors are formatted the same way as in format_output/2 so both paths agree on the response shape. The fallback clause formats bare data with no response envelope.

format_output(filtered_result, request)

Stage 4: Format output for client consumption with type awareness.

Applies type-aware output field formatting and final response structure.

format_sort_string(sort, formatter)

See AshTypescript.FieldFormatter.format_sort_string/2.

parse_request(otp_app, conn_or_socket, params, opts \\ [])

@spec parse_request(atom(), Plug.Conn.t() | Phoenix.Socket.t(), map(), keyword()) ::
  {:ok, AshTypescript.Rpc.Request.t()} | {:error, term()}

Stage 1: Parse and validate request.

Converts raw request parameters into a structured Request with validated fields. Fails fast on any invalid input - no permissive modes.

process_result(ash_result, request)

@spec process_result(term(), AshTypescript.Rpc.Request.t()) ::
  {:ok, term()} | {:error, term()}

Stage 3: Filter result fields using the extraction template.

Applies field selection to the Ash result using the pre-computed template. Performance-optimized single-pass filtering. For unconstrained maps, returns the normalized result directly. Handles metadata extraction for both read and mutation actions. If the extraction template is empty for mutation actions (create/update), returns empty data.