Configuration Reference

View Source

This document provides a comprehensive reference for all AshTypescript configuration options.

Application Configuration

Configure AshTypescript in your config/config.exs file:

# config/config.exs
config :ash_typescript,
  # File generation
  output_file: "assets/js/ash_rpc.ts",

  # RPC endpoints
  run_endpoint: "/rpc/run",
  validate_endpoint: "/rpc/validate",

  # Field formatting
  input_field_formatter: :camel_case,
  output_field_formatter: :camel_case,

  # Multitenancy
  require_tenant_parameters: false,

  # Zod schema generation
  generate_zod_schemas: false,
  zod_import_path: "zod",
  zod_schema_suffix: "ZodSchema",

  # Validation functions
  generate_validation_functions: false,

  # Phoenix channel-based RPC actions
  generate_phx_channel_rpc_actions: false,
  phoenix_import_path: "phoenix",

  # Custom type imports
  import_into_generated: [],

  # Type mapping overrides
  type_mapping_overrides: [],

  # TypeScript type for untyped maps
  untyped_map_type: "Record<string, any>",

  # RPC resource warnings
  warn_on_missing_rpc_config: true,
  warn_on_non_rpc_references: true,

  # Get action behavior
  not_found_error?: true

Quick Reference

OptionTypeDefaultDescription
output_filestring"assets/js/ash_rpc.ts"Path where generated TypeScript code will be written
run_endpointstring | {:runtime_expr, string}"/rpc/run"Endpoint for executing RPC actions
validate_endpointstring | {:runtime_expr, string}"/rpc/validate"Endpoint for validating RPC requests
input_field_formatter:camel_case | :snake_case:camel_caseHow to format field names in request inputs
output_field_formatter:camel_case | :snake_case:camel_caseHow to format field names in response outputs
require_tenant_parametersbooleanfalseWhether to require tenant parameters in RPC calls
generate_zod_schemasbooleanfalseWhether to generate Zod validation schemas
zod_import_pathstring"zod"Import path for Zod library
zod_schema_suffixstring"ZodSchema"Suffix for generated Zod schema names
generate_validation_functionsbooleanfalseWhether to generate form validation functions
generate_phx_channel_rpc_actionsbooleanfalseWhether to generate Phoenix channel-based RPC functions
phoenix_import_pathstring"phoenix"Import path for Phoenix library
import_into_generatedlist[]List of custom modules to import
type_mapping_overrideslist[]Override TypeScript types for Ash types
untyped_map_typestring"Record<string, any>"TypeScript type for untyped maps
warn_on_missing_rpc_configbooleantrueWarn about resources with extension not in RPC config
warn_on_non_rpc_referencesbooleantrueWarn about non-RPC resources referenced by RPC resources
not_found_error?booleantrueGlobal default: true returns error on not found, false returns null

Lifecycle Hook Configuration

OptionTypeDefaultDescription
rpc_action_before_request_hookstring | nilnilFunction called before RPC action requests
rpc_action_after_request_hookstring | nilnilFunction called after RPC action requests
rpc_validation_before_request_hookstring | nilnilFunction called before validation requests
rpc_validation_after_request_hookstring | nilnilFunction called after validation requests
rpc_action_hook_context_typestring"Record<string, any>"TypeScript type for action hook context
rpc_validation_hook_context_typestring"Record<string, any>"TypeScript type for validation hook context
rpc_action_before_channel_push_hookstring | nilnilFunction called before channel push for actions
rpc_action_after_channel_response_hookstring | nilnilFunction called after channel response for actions
rpc_validation_before_channel_push_hookstring | nilnilFunction called before channel push for validations
rpc_validation_after_channel_response_hookstring | nilnilFunction called after channel response for validations
rpc_action_channel_hook_context_typestring"Record<string, any>"TypeScript type for channel action hook context
rpc_validation_channel_hook_context_typestring"Record<string, any>"TypeScript type for channel validation hook context

See Lifecycle Hooks for complete documentation.

Domain Configuration

Configure RPC actions and typed queries in your domain modules:

defmodule MyApp.Domain do
  use Ash.Domain, extensions: [AshTypescript.Rpc]

  typescript_rpc do
    resource MyApp.Todo do
      # Standard CRUD actions
      rpc_action :list_todos, :read
      rpc_action :get_todo, :get
      rpc_action :create_todo, :create
      rpc_action :update_todo, :update
      rpc_action :destroy_todo, :destroy

      # RPC action options
      rpc_action :list_limited, :read, allowed_loads: [:user]
      rpc_action :list_no_filter, :read, enable_filter?: false
      rpc_action :list_no_sort, :read, enable_sort?: false

      # Typed queries for SSR
      typed_query :dashboard_todos, :read do
        ts_result_type_name "DashboardTodo"
        ts_fields_const_name "dashboardTodoFields"
        fields [:id, :title, :priority, %{user: [:name]}]
      end
    end
  end
end

RPC Action Options

OptionTypeDefaultDescription
allowed_loadslist(atom | keyword)nilWhitelist of loadable fields
denied_loadslist(atom | keyword)nilBlacklist of loadable fields
enable_filter?booleantrueEnable client-side filtering
enable_sort?booleantrueEnable client-side sorting
get?booleanfalseReturn single record
get_bylist(atom)nilFields for single-record lookup
not_found_error?booleannilOverride global not_found_error?
identitieslist(atom)[:_primary_key]Allowed identity lookups
show_metadatalist(atom) | false | nilnilMetadata fields to expose
metadata_field_nameskeywordnilMetadata field name mappings

See RPC Action Options for complete documentation.

Dynamic RPC Endpoints

For separate frontend projects, use runtime expressions:

config :ash_typescript,
  # Environment variables
  run_endpoint: {:runtime_expr, "process.env.RPC_RUN_ENDPOINT || '/rpc/run'"},

  # Vite environment variables
  # run_endpoint: {:runtime_expr, "import.meta.env.VITE_RPC_RUN_ENDPOINT || '/rpc/run'"},

  # Custom functions
  # run_endpoint: {:runtime_expr, "MyAppConfig.getRunEndpoint()"}

RPC Resource Warnings

AshTypescript provides compile-time warnings for configuration issues:

Missing RPC Configuration Warning

Appears when resources have AshTypescript.Resource extension but are not in any typescript_rpc block.

Non-RPC References Warning

Appears when RPC resources reference other resources that are not configured as RPC resources.

To disable warnings:

config :ash_typescript,
  warn_on_missing_rpc_config: false,
  warn_on_non_rpc_references: false

Detailed Documentation

For in-depth configuration guides, see:

See Also