thalo_schema/
lib.rs

1//! Define aggregates as schema files and compile into Rust code.
2//!
3//! # Example
4//!
5//! Yaml schema
6//!
7//! ```yaml
8//! # The name of the aggregate
9//! name: BankAccount
10//!
11//! # The events resulted resulting from commands
12//! events:
13//!   AccountOpened:
14//!     fields:
15//!       - name: initial_balance
16//!         type: f64
17//!
18//!   DepositedFunds:
19//!     fields:
20//!       - name: amount
21//!         type: f64
22//!
23//!   WithdrewFunds:
24//!     fields:
25//!       - name: amount
26//!         type: f64
27//!
28//! # The commands availble for the aggregate
29//! commands:
30//!   open_account:
31//!     event: AccountOpened # resulting event when command is successful
32//!     args:
33//!       - name: initial_balance
34//!         type: f64
35//!
36//!   deposit_funds:
37//!     event: DepositedFunds
38//!     args:
39//!       - name: amount
40//!         type: f64
41//!
42//!   withdraw_funds:
43//!     event: WithdrewFunds
44//!     args:
45//!       - name: amount
46//!         type: f64
47//!
48//! # Errors that can occur when executing a command
49//! errors:
50//!   NegativeAmount:
51//!     message: "amount cannot be negative"
52//!
53//!   InsufficientFunds:
54//!     message: "insufficient funds for transaction"
55//! ```
56//!
57//! Rust implementation
58//!
59//! ```
60//! use thalo::aggregate::{Aggregate, TypeId};
61//!
62//! // Creates BankAccountCommand, BankAccountEvent (and individual events), BankAccountError
63//! include_aggregate!("BankAccount");
64//!
65//! #[derive(Aggregate, Clone, Debug, Default, PartialEq, TypeId)]
66//! pub struct BankAccount {
67//!     id: String,
68//!     balance: bool,
69//! }
70//!
71//! impl BankAccountCommand for BankAccount {
72//!     fn open_account(&self, initial_balance: f64) -> Result<OpenedAccountEvent, BankAccountError> {
73//!         todo!()
74//!     }
75//!
76//!     fn deposit_funds(&self, amount: f64) -> Result<DepositedFundsEvent, BankAccountError> {
77//!         todo!()
78//!     }
79//!
80//!     fn withdraw_funds(&self, amount: f64) -> Result<WithdrewFundsEvent, BankAccountError> {
81//!         todo!()
82//!     }
83//! }
84//!
85//! fn apply(bank_account: &mut BankAccount, event: BankAccountEvent) {
86//!     use BankAccountEvent::*;
87//!
88//!     match event {
89//!         OpenedAccount(_) => { todo!() },
90//!         DepositedFunds(_) => { todo!() },
91//!         WithdrewFunds(_) => { todo!() },
92//!     }
93//! }
94//! ```
95
96#![deny(missing_docs)]
97
98pub use compiler::Compiler;
99pub use error::Error;
100
101mod compiler;
102mod error;
103pub mod schema;
104
105/// Configure a compiler.
106pub fn configure() -> Compiler {
107    Compiler::new()
108}