AshTypescript.Rpc.Pipeline (ash_typescript v0.17.3)

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

Summary

Functions

Stage 2: Execute Ash action using the parsed request.

Stage 4: Format output for client consumption.

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

Formats a sort string by converting field names from client format to internal format.

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.

format_output(filtered_result)

Stage 4: Format output for client consumption.

Applies output field formatting and final response structure.

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_list, formatter)

Formats a sort string by converting field names from client format to internal format.

Handles Ash.Query.sort_input format:

  • "name" or "+name" (ascending)
  • "++name" (ascending with nils first)
  • "-name" (descending)
  • "--name" (descending with nils last)
  • "-name,++title" (multiple fields with different modifiers)

Preserves sort modifiers while converting field names using the input formatter.

Examples

iex> format_sort_string("--startDate,++insertedAt", :camel_case)
"--start_date,++inserted_at"

iex> format_sort_string("-userName", :camel_case)
"-user_name"

iex> format_sort_string(nil, :camel_case)
nil

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.