Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .clippy.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
allowed-duplicate-crates = [
"syn",
"thiserror",
"thiserror-impl",
# These are all coming from eventually-postgres, quite likely sqlx...
Expand Down
4 changes: 2 additions & 2 deletions eventually-macros/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ keywords = ["architecture", "ddd", "event-sourcing", "cqrs", "es"]
proc-macro = true

[dependencies]
syn = { version = "1.0.109", features = ["full"] }
quote = "1.0.35"
syn = { version = "2.0.100", features = ["full"] }
quote = "1.0.40"
eventually = { path = "../eventually" }
20 changes: 8 additions & 12 deletions eventually-macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@

use proc_macro::TokenStream;
use quote::quote;
use syn::{parse_macro_input, AttributeArgs, Fields, ItemStruct, Meta, NestedMeta, Path};
use syn::punctuated::Punctuated;
use syn::{parse_macro_input, Fields, ItemStruct, Token, Type};

/// Implements a newtype to use the [`eventually::aggregate::Root`] instance with
/// user-defined [`eventually::aggregate::Aggregate`] types.
Expand All @@ -22,7 +23,7 @@ use syn::{parse_macro_input, AttributeArgs, Fields, ItemStruct, Meta, NestedMeta
/// being an example of user-defined `Aggregate` type) outside the `eventually` crate (E0116).
/// Therefore, a newtype that uses `aggregate::Root<T>` is required.
///
/// This attribute macro makes the implementation of a newtype easy, as it Implements
/// This attribute macro makes the implementation of a newtype easy, as it implements
/// conversion traits from and to `aggregate::Root<T>` and implements automatic deref
/// through [`std::ops::Deref`] and [`std::ops::DerefMut`].
///
Expand All @@ -31,19 +32,14 @@ use syn::{parse_macro_input, AttributeArgs, Fields, ItemStruct, Meta, NestedMeta
/// This method will panic if the Aggregate Root type is not provided as a macro parameter.
#[proc_macro_attribute]
pub fn aggregate_root(args: TokenStream, item: TokenStream) -> TokenStream {
let args = parse_macro_input!(args as AttributeArgs);
let mut item = parse_macro_input!(item as ItemStruct);
let item_ident = item.ident.clone();

let aggregate_type = args
.first()
.and_then(|meta| match meta {
NestedMeta::Meta(Meta::Path(Path { segments, .. })) => Some(segments),
_ => None,
})
.and_then(|segments| segments.first())
.map(|segment| segment.ident.clone())
.expect("the aggregate root type must be provided as macro parameter");
let aggregate_type: Type =
parse_macro_input!(args with Punctuated::<Type, Token![,]>::parse_terminated)
.into_iter()
.next()
.expect("the aggregate root type must be provided as macro parameter");

item.fields = Fields::Unnamed(
syn::parse2(quote! { (eventually::aggregate::Root<#aggregate_type>) }).unwrap(),
Expand Down
4 changes: 2 additions & 2 deletions eventually-postgres/tests/aggregate_repository.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ async fn it_works() {
.await
.unwrap();

let aggregate_id = setup::TestAggregateId(rand::thread_rng().gen::<i64>());
let aggregate_id = setup::TestAggregateId(rand::rng().random::<i64>());

let result = aggregate_repository
.get(&aggregate_id)
Expand Down Expand Up @@ -68,7 +68,7 @@ async fn it_detects_data_races_and_returns_conflict_error() {
.await
.unwrap();

let aggregate_id = setup::TestAggregateId(rand::thread_rng().gen::<i64>());
let aggregate_id = setup::TestAggregateId(rand::rng().random::<i64>());

let mut root = setup::TestAggregateRoot::create(aggregate_id, "John Dee".to_owned())
.expect("aggregate root should be created");
Expand Down
6 changes: 3 additions & 3 deletions eventually-postgres/tests/event_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ async fn append_with_no_version_check_works() {
.await
.unwrap();

let id = rand::thread_rng().gen::<i64>();
let id = rand::rng().random::<i64>();
let event_stream_id = format!("test-event-stream-{}", id);

let expected_events = vec![setup::TestDomainEvent::WasCreated {
Expand Down Expand Up @@ -76,7 +76,7 @@ async fn it_works_with_version_check_for_conflict() {
.await
.unwrap();

let id = rand::thread_rng().gen::<i64>();
let id = rand::rng().random::<i64>();
let event_stream_id = format!("test-event-stream-{}", id);

let expected_events = vec![setup::TestDomainEvent::WasCreated {
Expand Down Expand Up @@ -151,7 +151,7 @@ async fn it_handles_concurrent_writes_to_the_same_stream() {
.await
.unwrap();

let id = rand::thread_rng().gen::<i64>();
let id = rand::rng().random::<i64>();
let event_stream_id = format!("test-event-stream-{}", id);

let expected_events = vec![setup::TestDomainEvent::WasCreated {
Expand Down
2 changes: 1 addition & 1 deletion examples/bank-accounting/src/domain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ impl aggregate::Aggregate for BankAccount {

fn apply(state: Option<Self>, event: Self::Event) -> Result<Self, Self::Error> {
match state {
None => match event {
Option::None => match event {
BankAccountEvent::WasOpened {
id,
initial_balance,
Expand Down
Loading