mix ash_dispatch.gen (AshDispatch v0.5.0)

View Source

Generates missing files for AshDispatch events based on DSL definitions.

This generator introspects all events and counters defined in resources using AshDispatch.Resource and generates missing template files, TypeScript types, and the complete SDK.

Usage

mix ash_dispatch.gen              # Generate all missing files
mix ash_dispatch.gen --check      # Exit with error if files missing (for CI)
mix ash_dispatch.gen --dry-run    # Show what would be generated
mix ash_dispatch.gen --verbose    # Show detailed output

Integration with mix ash.codegen

This task is automatically called when running mix ash.codegen:

mix ash.codegen                   # Runs all extension codegens
mix ash.codegen --check           # CI mode - fail if files missing
mix ash.codegen --dry-run         # Preview all changes

What Gets Generated

Email Templates

For each :email channel defined in your events:

FileWhen Generated
email.html.heexAlways for email channels
email.text.eexAlways for email channels
email.{variant}.html.heexWhen channel has variant: :xxx
email.{variant}.text.eexWhen channel has variant: :xxx

Templates are placed in {event_module_dir}/templates/.

TypeScript SDK

Generates a complete SDK in lib/ash-dispatch/ (next to your ash_typescript output):

FileDescription
types.tsCounter types, defaults, metadata, and accessors
events.tsEvent ID types and metadata
store.tsZustand store for counter state
channel.tsPhoenix channel utilities
index.tsRe-exports all SDK modules
hooks/use-channel.tsChannel connection hook
hooks/use-counter.tsSingle counter access hook
hooks/use-notifications.tsNotification actions hook

Configuration

TypeScript SDK generation requires ash_typescript to be configured:

# TypeScript output path (required for SDK generation)
config :ash_typescript,
  output_file: "apps/frontend/src/lib/ash_rpc.ts"

# SDK will be generated to: apps/frontend/src/lib/ash-dispatch/

Without this configuration, only templates and event modules will be generated. You can also explicitly configure the SDK output path:

config :ash_dispatch,
  sdk_output_path: "apps/frontend/src/lib/ash-dispatch"

See the Code Generation guide for details.