Define aggregates as schema files and compile into Rust code.
Example
Yaml schema
# The name of the aggregate
name: BankAccount
# The events resulted resulting from commands
events:
AccountOpened:
fields:
- name: initial_balance
type: f64
DepositedFunds:
fields:
- name: amount
type: f64
WithdrewFunds:
fields:
- name: amount
type: f64
# The commands availble for the aggregate
commands:
open_account:
event: AccountOpened # resulting event when command is successful
args:
- name: initial_balance
type: f64
deposit_funds:
event: DepositedFunds
args:
- name: amount
type: f64
withdraw_funds:
event: WithdrewFunds
args:
- name: amount
type: f64
# Errors that can occur when executing a command
errors:
NegativeAmount:
message: "amount cannot be negative"
InsufficientFunds:
message: "insufficient funds for transaction"
Rust implementation
use ;
// Creates BankAccountCommand, BankAccountEvent (and individual events), BankAccountError
include_aggregate!;