Configuration Reference

Copy Markdown 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 (multi-file architecture)
  output_file: "assets/js/ash_rpc.ts",
  types_output_file: nil,             # Auto-derives as ash_types.ts in output_file dir
  zod_output_file: nil,               # Auto-derives as ash_zod.ts in output_file dir

  # 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,

  # RPC namespace files
  enable_namespace_files: false,      # Generate separate files for namespaced RPC actions
  namespace_output_dir: nil,          # Directory for RPC namespace files (defaults to output_file dir)

  # Typed channel event subscriptions
  typed_channels: [],
  typed_channels_output_file: nil,

  # Typed controllers
  typed_controllers: [],
  router: nil,
  routes_output_file: nil,
  typed_controller_mode: :full,
  typed_controller_path_params_style: :object,
  typed_controller_base_path: "",             # Base URL prefix for all generated route URLs
  enable_controller_namespace_files: false,  # Generate separate files for namespaced routes
  controller_namespace_output_dir: nil,       # Directory for controller namespace files

  # Typed controller lifecycle hooks
  typed_controller_before_request_hook: nil,
  typed_controller_after_request_hook: nil,
  typed_controller_hook_context_type: "Record<string, any>",
  typed_controller_import_into_generated: [],

  # Typed controller error handling
  typed_controller_error_handler: nil,
  typed_controller_show_raised_errors: false,

  # Dev codegen behavior
  always_regenerate: false,

  # Get action behavior
  not_found_error?: true,

  # Developer experience - JSDoc
  add_ash_internals_to_jsdoc: false,
  source_path_prefix: nil,

  # Developer experience - Manifest
  manifest_file: nil,
  add_ash_internals_to_manifest: false

Multi-File Output

AshTypescript generates multiple TypeScript files, each with a specific responsibility:

FileConfig KeyDefaultContents
RPC functionsoutput_fileassets/js/ash_rpc.tsRPC functions, hook types, helpers
Shared typestypes_output_fileAuto-derived as ash_types.tsType aliases, resource schemas, filter types, utility types
Shared Zod schemaszod_output_fileAuto-derived as ash_zod.tsZod schemas for all resources (when generate_zod_schemas: true)
Route helpersroutes_output_filenil (disabled)Path helpers, typed fetch functions, controller input types
Typed channel functionstyped_channels_output_filenil (disabled)Channel factory, subscription helpers, cleanup functions
RPC namespace re-exportsnamespace_output_dirSame dir as output_filePer-namespace re-export files (when enable_namespace_files: true)
Controller namespace re-exportscontroller_namespace_output_dirSame dir as routes_output_filePer-namespace re-export files (when enable_controller_namespace_files: true)

types_output_file and zod_output_file auto-derive from the output_file directory — set output_file and the others follow. Override individually if needed.

Quick Reference

OptionTypeDefaultDescription
output_filestring"assets/js/ash_rpc.ts"Path where generated TypeScript code will be written
types_output_filestring | nilnilPath for shared types file (auto-derives from output_file dir as ash_types.ts)
zod_output_filestring | nilnilPath for shared Zod schemas file (auto-derives from output_file dir as ash_zod.ts)
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
enable_namespace_filesbooleanfalseGenerate separate files for namespaced RPC actions
namespace_output_dirstring | nilnilDirectory for RPC namespace files (defaults to output_file dir)
typed_channelslist(module)[]TypedChannel modules to generate event subscription helpers for
typed_channels_output_filestring | nilnilOutput file for typed channel functions (when nil, generation is skipped)
typed_controllerslist(module)[]TypedController modules to generate route helpers for
routermodule | nilnilPhoenix router module for path introspection
routes_output_filestring | nilnilOutput file path for generated route helpers
typed_controller_mode:full | :paths_only:fullGeneration mode: :full generates path helpers + fetch functions, :paths_only generates only path helpers
typed_controller_path_params_style:object | :args:objectPath parameter style in generated functions
typed_controller_base_pathstring | {:runtime_expr, string}""Base URL prefix for all generated route URLs
enable_controller_namespace_filesbooleanfalseGenerate separate files for namespaced controller routes
controller_namespace_output_dirstring | nilnilDirectory for controller namespace files (defaults to routes_output_file dir)
typed_controller_before_request_hookstring | nilnilFunction called before typed controller requests
typed_controller_after_request_hookstring | nilnilFunction called after typed controller requests
typed_controller_hook_context_typestring"Record<string, any>"TypeScript type for typed controller hook context
typed_controller_import_into_generatedlist(map)[]Custom imports for generated routes file
typed_controller_error_handlermfa | module | nilnilCustom error transformation handler
typed_controller_show_raised_errorsbooleanfalseShow exception messages in 500 responses
always_regeneratebooleanfalseSkip diff check and always write generated files
not_found_error?booleantrueGlobal default: true returns error on not found, false returns null
add_ash_internals_to_jsdocbooleanfalseShow Ash resource/action details in JSDoc
source_path_prefixstring | nilnilPrefix for source file paths (monorepos)
manifest_filestring | nilnilPath to generate Markdown manifest
add_ash_internals_to_manifestbooleanfalseShow Ash details in manifest

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
typed_controller_before_request_hookstring | nilnilFunction called before typed controller requests
typed_controller_after_request_hookstring | nilnilFunction called after typed controller requests
typed_controller_hook_context_typestring"Record<string, any>"TypeScript type for typed controller hook context

See Lifecycle Hooks and Typed Controllers 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

Always Regenerate Mode

By default, mix ash_typescript.codegen --check compares the generated output against existing files and raises Ash.Error.Framework.PendingCodegen if they differ. This is useful for CI but in development—especially when using AshPhoenix.Plug.CheckCodegenStatus—you may want to skip the diff check and always write the generated files.

# config/dev.exs
config :ash_typescript, always_regenerate: true

When enabled, --check mode will write files directly instead of comparing, so the PendingCodegen error page is never shown during development.

Typed Channel Configuration

Configure typed channels to generate TypeScript event subscription helpers from Ash PubSub publications. Both typed_channels and typed_channels_output_file must be configured for generation to run.

config :ash_typescript,
  typed_channels: [MyApp.OrgChannel, MyApp.ActivityChannel],
  typed_channels_output_file: "assets/js/ash_typed_channels.ts"
OptionTypeDefaultDescription
typed_channelslist(module)[]Modules using AshTypescript.TypedChannel
typed_channels_output_filestring | nilnilOutput file for channel functions (when nil, generation is skipped)

Channel types (branded types, payload aliases, event maps) are appended to the shared types file (ash_types.ts). Channel functions (factory, subscription helpers) go into typed_channels_output_file and import their types from ash_types.ts.

See Typed Channels for complete documentation.

Typed Controller Configuration

Configure typed controllers to generate TypeScript path helpers and typed fetch functions for Phoenix controller routes. All three settings (typed_controllers, router, routes_output_file) must be configured for route generation to run.

config :ash_typescript,
  # List of TypedController modules
  typed_controllers: [MyApp.Session],

  # Phoenix router for path introspection
  router: MyAppWeb.Router,

  # Output file for generated route helpers
  routes_output_file: "assets/js/routes.ts",

  # Generation mode (optional)
  typed_controller_mode: :full,              # :full (default) or :paths_only
  typed_controller_path_params_style: :object, # :object (default) or :args
  typed_controller_base_path: "",            # Base URL prefix (string or {:runtime_expr, "..."})

  # Namespace files (optional)
  enable_controller_namespace_files: false,  # Generate separate files per namespace
  controller_namespace_output_dir: nil,      # Directory for namespace files (defaults to routes_output_file dir)

  # Lifecycle hooks (optional)
  typed_controller_before_request_hook: "RouteHooks.beforeRequest",
  typed_controller_after_request_hook: "RouteHooks.afterRequest",
  typed_controller_hook_context_type: "RouteHooks.RouteHookContext",
  typed_controller_import_into_generated: [
    %{import_name: "RouteHooks", file: "./routeHooks"}
  ],

  # Error handling (optional)
  typed_controller_error_handler: {MyApp.ErrorHandler, :handle, []},
  typed_controller_show_raised_errors: false  # true only in dev
OptionTypeDefaultDescription
typed_controllerslist(module)[]Modules using AshTypescript.TypedController
routermodulenilPhoenix router for path introspection
routes_output_filestringnilOutput file path (when nil, generation is skipped)
typed_controller_mode:full | :paths_only:full:full generates path helpers + fetch functions; :paths_only generates only path helpers
typed_controller_path_params_style:object | :args:objectPath parameter style in generated TypeScript
typed_controller_base_pathstring | {:runtime_expr, string}""Base URL prefix for all generated route URLs
enable_controller_namespace_filesbooleanfalseGenerate separate files for namespaced routes
controller_namespace_output_dirstring | nilnilDirectory for namespace files (defaults to routes_output_file dir)
typed_controller_before_request_hookstring | nilnilFunction called before typed controller requests
typed_controller_after_request_hookstring | nilnilFunction called after typed controller requests
typed_controller_hook_context_typestring"Record<string, any>"TypeScript type for hook context
typed_controller_import_into_generatedlist(map)[]Custom imports (%{import_name: "Name", file: "./path"})
typed_controller_error_handlermfa | module | nilnilCustom error transformation handler
typed_controller_show_raised_errorsbooleanfalseShow exception messages in 500 responses

See Typed Controllers for complete documentation.

Detailed Documentation

For in-depth configuration guides, see:

See Also