Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: changes to aggregate::Repository, event::Store, documentation and more #289

Merged
merged 12 commits into from
Feb 23, 2024
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
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,11 @@ jobs:
- name: Checkout sources
uses: actions/checkout@v4

- name: Install nightly toolchain
- name: Install stable toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: nightly
toolchain: stable
override: true
components: clippy,rustfmt

Expand Down
4 changes: 4 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"rust-analyzer.cargo.features": "all",
"rust-analyzer.check.command": "clippy"
}
15 changes: 14 additions & 1 deletion eventually-macros/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,25 @@
[package]
name = "eventually-macros"
description = "Macros for eventually crate"
version = "0.1.0"
edition = "2021"
authors = ["Danilo Cianfrone <danilocianfr@gmail.com>"]
license = "MIT"
readme = "../README.md"
repository = "https://github.com/get-eventually/eventually-rs"

categories = [
"rust-patterns",
"web-programming",
"asynchronous",
"data-structures",
]
keywords = ["architecture", "ddd", "event-sourcing", "cqrs", "es"]

[lib]
proc-macro = true

[dependencies]
syn = { version = "1.0.109", features = ["full"] }
quote = "1.0.33"
quote = "1.0.35"
eventually = { path = "../eventually" }
60 changes: 15 additions & 45 deletions eventually-macros/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,55 +1,21 @@
//! Module containing useful macros for the [eventually] crate.
//! `eventually-macros` contains useful macros that provides
//! different implementations of traits and functionalities from [eventually].

#![deny(unsafe_code, unused_qualifications, trivial_casts)]
#![warn(missing_docs)]
#![deny(clippy::all)]
#![warn(clippy::pedantic)]
#![deny(unsafe_code, unused_qualifications, trivial_casts, missing_docs)]
#![deny(clippy::all, clippy::pedantic, clippy::cargo)]

use proc_macro::TokenStream;
use quote::quote;
use syn::{parse_macro_input, AttributeArgs, Fields, ItemEnum, ItemStruct, Meta, NestedMeta, Path};
use syn::{parse_macro_input, AttributeArgs, Fields, ItemStruct, Meta, NestedMeta, Path};

#[proc_macro_derive(Message)]
pub fn derive_message(input: TokenStream) -> TokenStream {
let item = parse_macro_input!(input as ItemEnum);
let item_name = item.ident;
let event_prefix = item_name
.to_string()
.strip_suffix("Event")
.unwrap()
.to_owned();

let match_cases = item.variants.iter().fold(quote! {}, |acc, variant| {
let event_type = &variant.ident;
let event_name = format!("{}{}", event_prefix, event_type);

quote! {
#acc
#item_name::#event_type { .. } => #event_name,
}
});

let result = quote! {
impl eventually::message::Message for #item_name {
fn name(&self) -> &'static str {
match self {
#match_cases
}
}
}
};

result.into()
}

/// Implements a newtype to use the [eventually::aggregate::Root] instance with
/// user-defined [eventually::aggregate::Aggregate] types.
/// Implements a newtype to use the [`eventually::aggregate::Root`] instance with
/// user-defined [`eventually::aggregate::Aggregate`] types.
///
/// # Context
///
/// The eventually API uses `aggregate::Root<T>` to manage the versioning and
/// list of events to commit for an `Aggregate` instance. Domain commands
/// are to be implemented on the `aggregate::Root<T>` instance, as it gives
/// The eventually API uses [`aggregate::Root`][eventually::aggregate::Root]
/// to manage the versioning and list of events to commit for an `Aggregate` instance.
/// Domain commands are to be implemented on the `aggregate::Root<T>` instance, as it gives
/// access to use `Root<T>.record_that` or `Root<T>.record_new` to record Domain Events.
///
/// However, it's not possible to use `impl aggregate::Root<MyAggregateType>` (`MyAggregateType`
Expand All @@ -58,7 +24,11 @@ pub fn derive_message(input: TokenStream) -> TokenStream {
///
/// 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].
/// through [`std::ops::Deref`] and [`std::ops::DerefMut`].
///
/// # Panics
///
/// 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);
Expand Down
17 changes: 9 additions & 8 deletions eventually-postgres/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,27 @@ categories = ["web-programming", "asynchronous"]
keywords = ["postgres", "postgresql", "database", "ddd", "event-sourcing"]

[dependencies]
async-trait = "0.1.74"
chrono = "0.4.31"
anyhow = "1.0.80"
async-trait = "0.1.77"
chrono = "0.4.34"
eventually = { path = "../eventually", version = "0.5.0", features = [
"serde-json",
] }
futures = "0.3.29"
futures = "0.3.30"
lazy_static = "1.4.0"
regex = "1.10.2"
sqlx = { version = "0.7.2", features = [
regex = "1.10.3"
sqlx = { version = "0.7.3", features = [
"runtime-tokio-rustls",
"postgres",
"migrate",
] }
thiserror = "1.0.50"
thiserror = "1.0.57"

[dev-dependencies]
tokio = { version = "1.34.0", features = ["macros", "rt"] }
tokio = { version = "1.36.0", features = ["macros", "rt"] }
eventually = { path = "../eventually", version = "0.5.0", features = [
"serde-json",
] }
eventually-macros = { path = "../eventually-macros", version = "0.1.0" }
serde = { version = "1.0.192", features = ["derive"] }
serde = { version = "1.0.197", features = ["derive"] }
rand = "0.8.5"
Loading
Loading