1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
//! Procedural macros for the EventCore event sourcing library.
//!
//! This crate provides derive macros and attribute macros to reduce boilerplate
//! when implementing commands and other EventCore patterns.
use TokenStream;
use ;
use expand_derive_command;
/// Derive macro for implementing the CommandStreams trait.
///
/// This macro generates a complete implementation of `CommandStreams` based on
/// fields marked with `#[stream]`. You only need to implement `CommandLogic`
/// for your domain logic.
///
/// # Example
///
/// ```ignore
/// use eventcore_macros::Command;
/// use eventcore::{CommandLogic, prelude::*};
///
/// #[derive(Command, Clone)]
/// struct TransferMoney {
/// #[stream]
/// from_account: StreamId,
/// #[stream]
/// to_account: StreamId,
/// amount: Money,
/// }
///
/// #[async_trait]
/// impl CommandLogic for TransferMoney {
/// type State = AccountBalances;
/// type Event = BankingEvent;
///
/// fn apply(&self, state: &mut Self::State, event: &StoredEvent<Self::Event>) {
/// // Your event folding logic
/// }
///
/// async fn handle(
/// &self,
/// read_streams: ReadStreams<Self::StreamSet>,
/// state: Self::State,
/// input: Self::Input,
/// stream_resolver: &mut StreamResolver,
/// ) -> CommandResult<Vec<StreamWrite<Self::StreamSet, Self::Event>>> {
/// // Your business logic
/// }
/// }
/// ```
///
/// This automatically generates:
/// - Complete `CommandStreams` trait implementation
/// - `type Input = Self` (the command struct serves as input)
/// - `type StreamSet = TransferMoneyStreamSet` (phantom type for stream access)
/// - `fn read_streams()` implementation extracting from `#[stream]` fields
/// Internal module for testing macro expansion.