AshTypescript.Rpc.Codegen.Helpers.ConfigBuilder (ash_typescript v0.12.1)
View SourceBuilds TypeScript configuration field definitions for RPC functions.
Configuration fields define the parameters that can be passed to RPC functions, including tenant, primary key, input, pagination, filters, and metadata fields.
Summary
Functions
Builds common configuration fields shared across all RPC functions.
Builds the getBy configuration field for the TypeScript config type.
Builds the identity configuration field for the TypeScript config type.
Generates pagination configuration fields for the TypeScript config type.
Gets the action context - a map of values indicating what features the action supports.
Functions
Builds common configuration fields shared across all RPC functions.
This includes tenant, primary key, input, and hook context fields.
Parameters
resource- The Ash resource_action- The Ash action (currently unused but kept for consistency)context- The action context fromget_action_context/2opts- Options keyword list::rpc_action_name- The snake_case name of the RPC action:validation_function?- If true, identity types acceptType | string:is_validation- If true, this is for a validation function:is_channel- If true, this is for a channel function
Returns
A list of TypeScript field definition strings.
Examples
[" tenant: string;", " input: CreateTodoInput;", " hookCtx?: ActionHookContext;"]
Builds the getBy configuration field for the TypeScript config type.
This is used for get_by RPC actions where records are looked up by specific fields.
Parameters
resource- The Ash resourcerpc_action- The RPC action configuration
Returns
A list of TypeScript field definition strings, or an empty list if no get_by fields.
Examples
# Single get_by field
[" getBy: {", " email: string;", " };"]
# Multiple get_by fields
[" getBy: {", " userId: UUID;", " status: Status;", " };"]
Builds the identity configuration field for the TypeScript config type.
Generates a union type for all supported identities (primary key and/or named identities).
Parameters
resource- The Ash resourceidentities- List of identity atoms (e.g.,[:_primary_key, :email])opts- Options keyword list::validation_function?- If true, each field type becomesType | stringto accept either the typed value or a string representation (for validation functions)
Returns
A list containing one TypeScript field definition string for the identity.
Examples
# Single primary key (non-composite)
[" identity: UUID;"]
# Single primary key for validation function
[" identity: UUID | string;"]
# Primary key and email identity (identity uses email field)
[" identity: UUID | { email: string };"]
# Composite primary key
[" identity: { id: UUID; tenantId: string };"]
# Composite primary key for validation function
[" identity: { id: UUID | string; tenantId: string };"]
Generates pagination configuration fields for the TypeScript config type.
Returns a list of TypeScript field strings that define the page parameter
for pagination. The structure varies based on what pagination types are supported.
Parameters
action- The Ash action
Returns
A list of TypeScript field definition strings, or an empty list if pagination is not supported.
Examples
# Offset pagination only
[" page?: {", " limit?: number;", " offset?: number;", " };"]
# Keyset pagination only
[" page?: {", " limit?: number;", " after?: string;", " before?: string;", " };"]
# Mixed pagination (both offset and keyset)
[" page?: (", " {", " limit?: number;", " offset?: number;", " } | {", ...]
Gets the action context - a map of values indicating what features the action supports.
Note: The action should be augmented with RPC settings (get?, get_by) before calling this.
This is done in the codegen module via augment_action_with_rpc_settings/3.
Parameters
resource- The Ash resourceaction- The Ash action (possibly augmented with RPC settings)rpc_action- The RPC action configuration
Returns
A map with the following keys:
:requires_tenant- Whether the action requires a tenant parameter:identities- List of identity atoms for record lookup (update/destroy actions):supports_pagination- Whether the action supports pagination (list reads):supports_filtering- Whether the action supports filtering (list reads):action_input_type- Whether the input is :none, :required, or :optional:is_get_action- Whether this is a get action (returns single or null)
Examples
iex> get_action_context(MyResource, read_action, rpc_action)
%{
requires_tenant: true,
identities: [],
supports_pagination: true,
supports_filtering: true,
action_input_type: :required,
is_get_action: false
}