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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
//! Core types and traits for the Evento event sourcing library.
//!
//! This crate provides the foundational abstractions for building event-sourced applications
//! with Evento. It defines the core traits, types, and builders used throughout the framework.
//!
//! # Features
//!
//! - **`macro`** (default) - Procedural macros from `evento-macro`
//! - **`group`** - Multi-executor support via `EventoGroup`
//! - **`rw`** - Read-write split executor pattern via `Rw`
//! - **`sqlite`**, **`mysql`**, **`postgres`** - Database support via sqlx
//! - **`fjall`** - Embedded key-value storage with Fjall
//!
//! # Core Concepts
//!
//! ## Events
//!
//! Events are immutable facts that represent something that happened in your domain.
//! The [`Event`] struct stores serialized event data with metadata:
//!
//! ```rust,ignore
//! // Define events using the aggregator macro
//! #[evento::aggregator]
//! pub enum BankAccount {
//! AccountOpened { owner_id: String, initial_balance: i64 },
//! MoneyDeposited { amount: i64 },
//! }
//! ```
//!
//! ## Executor
//!
//! The [`Executor`] trait abstracts event storage and retrieval. Implementations
//! handle persisting events, querying, and managing subscriptions.
//!
//! ## Aggregator Builder
//!
//! Use [`create()`] or [`aggregator()`] to build and commit events:
//!
//! ```rust,ignore
//! use evento::metadata::Metadata;
//!
//! let id = evento::create()
//! .event(&AccountOpened { owner_id: "user1".into(), initial_balance: 1000 })
//! .metadata(&Metadata::default())
//! .commit(&executor)
//! .await?;
//! ```
//!
//! ## Projections
//!
//! Build read models by replaying events. Use the [`projection`] module for loading
//! aggregate state:
//!
//! ```rust,ignore
//! use evento::projection::Projection;
//!
//! #[evento::projection]
//! #[derive(Debug)]
//! pub struct AccountView {
//! pub balance: i64,
//! }
//!
//! #[evento::handler]
//! async fn on_deposited(
//! event: Event<MoneyDeposited>,
//! projection: &mut AccountView,
//! ) -> anyhow::Result<()> {
//! projection.balance += event.data.amount;
//! Ok(())
//! }
//!
//! let result = Projection::<AccountView, _>::new::<BankAccount>("account-123")
//! .handler(on_deposited())
//! .execute(&executor)
//! .await?;
//! ```
//!
//! ## Subscriptions
//!
//! Process events continuously in real-time. See the [`subscription`] module:
//!
//! ```rust,ignore
//! use evento::subscription::SubscriptionBuilder;
//!
//! #[evento::subscription]
//! async fn on_deposited<E: Executor>(
//! context: &Context<'_, E>,
//! event: Event<MoneyDeposited>,
//! ) -> anyhow::Result<()> {
//! // Perform side effects
//! Ok(())
//! }
//!
//! let subscription = SubscriptionBuilder::<Sqlite>::new("deposit-processor")
//! .handler(on_deposited())
//! .routing_key("accounts")
//! .start(&executor)
//! .await?;
//! ```
//!
//! ## Cursor-based Pagination
//!
//! GraphQL-style pagination for querying events. See the [`cursor`] module.
//!
//! # Modules
//!
//! - [`context`] - Type-safe request context for storing arbitrary data
//! - [`cursor`] - Cursor-based pagination types and traits
//! - [`metadata`] - Standard event metadata types
//! - [`projection`] - Projections for loading aggregate state
//! - [`subscription`] - Continuous event processing with subscriptions
//!
//! # Example
//!
//! ```rust,ignore
//! use evento::{Executor, metadata::Metadata, cursor::Args, ReadAggregator};
//!
//! // Create and persist an event
//! let id = evento::create()
//! .event(&AccountOpened { owner_id: "user1".into(), initial_balance: 1000 })
//! .metadata(&Metadata::default())
//! .commit(&executor)
//! .await?;
//!
//! // Query events with pagination
//! let events = executor.read(
//! Some(vec![ReadAggregator::id("myapp/Account", &id)]),
//! None,
//! Args::forward(10, None),
//! ).await?;
//! ```
pub use *;
pub use *;
pub use *;
pub use RoutingKey;
use Debug;
use Ulid;
use crate::;
/// Cursor data for event pagination.
///
/// Used internally for base64-encoded cursor values in paginated queries.
/// Contains the essential fields needed to uniquely identify an event's position.
/// A stored event in the event store.
///
/// Events are immutable records of facts that occurred in your domain.
/// They contain serialized data and metadata, along with positioning
/// information for the aggregate they belong to.
///
/// # Fields
///
/// - `id` - Unique event identifier (ULID format for time-ordering)
/// - `aggregator_id` - The aggregate instance this event belongs to
/// - `aggregator_type` - Type name like `"myapp/BankAccount"`
/// - `version` - Sequence number within the aggregate (for optimistic concurrency)
/// - `name` - Event type name like `"AccountOpened"`
/// - `routing_key` - Optional key for event distribution/partitioning
/// - `data` - Serialized event payload (bitcode format)
/// - `metadata` - Event metadata (see [`metadata::Metadata`])
/// - `timestamp` - When the event occurred (Unix seconds)
/// - `timestamp_subsec` - Sub-second precision (milliseconds)
///
/// # Serialization
///
/// Event data is serialized using [bitcode](https://crates.io/crates/bitcode)
/// for compact binary representation. Use [`metadata::Event`] to deserialize typed events.