Orkestra.Aggregate.Root (orkestra v0.2.0)

Copy Markdown View Source

The imperative shell for functional aggregates.

Orchestrates the load → fold → decide → append → publish pipeline, handling all I/O while keeping aggregate logic pure.

Usage

alias Orkestra.Aggregate.Root

{:ok, events, new_state} = Root.execute(MyAggregate, command)

# With options
{:ok, events, new_state} = Root.execute(MyAggregate, command,
  max_retries: 5,
  publish: true
)

Optimistic concurrency

If another process appends events to the same stream between our load and append, EventStore returns :wrong_expected_version. The shell automatically retries by re-loading, re-folding, and re-deciding.

Summary

Functions

Executes a command against an aggregate.

Types

execute_result()

@type execute_result() :: {:ok, [map()], term()} | {:error, term()}

Functions

execute(aggregate_module, command, opts \\ [])

@spec execute(module(), map(), keyword()) :: execute_result()

Executes a command against an aggregate.

Options

  • :max_retries — retries on concurrency conflict (default: 3)
  • :publish — publish events to MessageBus after append (default: true)
  • :metadata — Orkestra Metadata for event creation context