AshCommanded.Commanded.Transformers.GenerateProjectionModules (AshCommanded v0.1.0)

View Source

Generates projection modules based on the projections defined in the DSL.

For each projection defined in a resource, this transformer will generate a corresponding module that handles the transformation of events into resource updates.

This transformer should run after the event module transformer.

Example

Given a resource with the following projection:

projection :user_registered do
  action :create
  changes(%{status: :active})
end

This transformer will generate a module like:

defmodule MyApp.Projections.UserRegistered do
  @moduledoc "Projection that handles user_registered events"
  
  def apply(event, resource) do
    # Apply changes to the resource based on the event
    changes = %{status: :active}
    Ash.Changeset.for_action(resource, event, :create, changes)
  end
end

Summary

Functions

Specifies that this transformer should run after the event module transformer.

Callback implementation for Spark.Dsl.Transformer.before?/1.

Builds the module name for a projection.

Builds the AST (Abstract Syntax Tree) for a projection module.

Transforms the DSL state to generate projection modules.

Functions

after?(arg1)

Specifies that this transformer should run after the event module transformer.

after_compile?()

Callback implementation for Spark.Dsl.Transformer.after_compile?/0.

before?(_)

Callback implementation for Spark.Dsl.Transformer.before?/1.

build_projection_module(projection, app_prefix)

Builds the module name for a projection.

Examples

iex> build_projection_module(%Projection{name: :user_registered}, MyApp)
MyApp.Projections.UserRegistered

build_projection_module_ast(projection, resource_name)

Builds the AST (Abstract Syntax Tree) for a projection module.

Examples

iex> build_projection_module_ast(%Projection{name: :user_registered, action: :create, changes: %{status: :active}}, "User")
{:__block__, [], [{:@, [...], [{:moduledoc, [...], [...]}]}, ...]}

transform(dsl_state)

Transforms the DSL state to generate projection modules.

Examples

iex> transform(dsl_state)
{:ok, updated_dsl_state}