AshBackpex.LiveResource.Transformers.GenerateBackpex (Ash Backpex v0.3.3)
View SourceSpark DSL transformer that generates Backpex LiveResource code at compile time.
This transformer is the core of AshBackpex - it reads your backpex DSL configuration
and generates all the necessary code to create a fully functional Backpex LiveResource
backed by your Ash resource.
What Gets Generated
When you use AshBackpex.LiveResource with a backpex block, this transformer
generates:
Backpex Configuration
use Backpex.LiveResourcewith theAshBackpex.Adapter- Adapter configuration with resource, repo, and action settings
- Layout, pagination, sorting, and other Backpex options
Callback Implementations
fields/0- Returns the field configurations with auto-derived modulesfilters/0- Returns the filter configurationsitem_actions/1- Returns item actions (with default stripping support)singular_name/0- Returns the singular display nameplural_name/0- Returns the plural display namepanels/0- Returns panel configurations
Authorization
can?/3- Checks Ash authorization for each action type::newchecks create action authorization:index/:showcheck read action authorization:editchecks update action authorization:deletechecks destroy action authorization- Custom actions check for matching Ash actions
Helper Functions
load/3- Returns configured loads for the adaptermaybe_default_options/1- Derives select options fromone_ofconstraints
Field Type Derivation
The transformer automatically maps Ash types to Backpex field modules:
| Ash Type | Backpex Field |
|---|---|
Ash.Type.String | Backpex.Fields.Text |
Ash.Type.Atom | Backpex.Fields.Text (or Select with one_of) |
Ash.Type.Boolean | Backpex.Fields.Boolean |
Ash.Type.Integer | Backpex.Fields.Number |
Ash.Type.Float | Backpex.Fields.Number |
Ash.Type.Date | Backpex.Fields.Date |
Ash.Type.Time | Backpex.Fields.Time |
Ash.Type.DateTime | Backpex.Fields.DateTime |
:belongs_to | Backpex.Fields.BelongsTo |
:has_many | Backpex.Fields.HasMany |
:many_to_many | Backpex.Fields.HasMany |
{:array, EmbeddedResource} with InlineCRUD | AshBackpex.Fields.InlineCRUD (type: :embed) |
singular EmbeddedResource | AshBackpex.Fields.Embedded (explicit) |
{:array, _} | Backpex.Fields.MultiSelect |
Aggregates (:count, :sum, etc.) | Backpex.Fields.Number or Boolean |
Constraint Handling
- Attributes with
one_ofconstraints automatically useBackpex.Fields.Select - Array attributes with
one_ofconstraints useBackpex.Fields.MultiSelect - Options are auto-derived from constraint values with title-cased labels
- Relationship filters and sorts are auto-derived into Backpex
options_query
Error Handling
The transformer raises helpful errors when:
- A field doesn't exist on the Ash resource
- A field type can't be derived (suggests using
moduleoption) - Recursive
child_fieldsdo not resolve to an immediate child Ash resource - InlineCRUD is used with a cardinality other than
has_manyor an embedded-resource array - The resource lacks a primary key
- The LiveResource defines
can?/3,fields/0,filters/0,item_actions/1, orlayout/1itself. The generated callback would silently replace it, so the error points to the Ash policy or DSL option to use instead.
Internal Use
This module is invoked automatically by Spark during compilation. You don't
need to call it directly - just define your backpex block and the transformer
handles the rest.
Summary
Functions
Callback implementation for Spark.Dsl.Transformer.after?/1.
Callback implementation for Spark.Dsl.Transformer.after_compile?/0.
Callback implementation for Spark.Dsl.Transformer.before?/1.
Callback implementation for Spark.Dsl.Transformer.transform/1.
Functions
Callback implementation for Spark.Dsl.Transformer.after?/1.
Callback implementation for Spark.Dsl.Transformer.after_compile?/0.
Callback implementation for Spark.Dsl.Transformer.before?/1.
Callback implementation for Spark.Dsl.Transformer.transform/1.