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

[PLATFORM-1130]: Package refactor #161

Merged
merged 1 commit into from
Jun 9, 2023
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
6 changes: 4 additions & 2 deletions examples/aggregate_deletion/main.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
use sqlx::{Pool, Postgres};
use uuid::Uuid;

use esrs::postgres::{PgStore, PgStoreBuilder};
use esrs::{AggregateManager, AggregateState, EventStore, StoreEvent};
use esrs::manager::AggregateManager;
use esrs::store::postgres::{PgStore, PgStoreBuilder};
use esrs::store::{EventStore, StoreEvent};
use esrs::AggregateState;

use crate::common::{new_pool, BasicAggregate, BasicCommand, BasicEvent, BasicEventHandler, BasicView};

Expand Down
3 changes: 2 additions & 1 deletion examples/common/basic/event_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ use async_trait::async_trait;
use sqlx::{Pool, Postgres};
use uuid::Uuid;

use esrs::{EventHandler, StoreEvent};
use esrs::handler::EventHandler;
use esrs::store::StoreEvent;

use crate::common::{BasicAggregate, BasicEvent, BasicView};

Expand Down
3 changes: 2 additions & 1 deletion examples/common/shared/event_handler.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use async_trait::async_trait;
use sqlx::{Pool, Postgres};

use esrs::{EventHandler, ReplayableEventHandler, StoreEvent};
use esrs::handler::{EventHandler, ReplayableEventHandler};
use esrs::store::StoreEvent;

use crate::common::{AggregateA, AggregateB, EventA, EventB, SharedView, UpsertSharedView};

Expand Down
4 changes: 3 additions & 1 deletion examples/event_bus/kafka.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ use rdkafka::consumer::{Consumer, StreamConsumer};
use rdkafka::{ClientConfig, Message};
use serde::de::DeserializeOwned;

use esrs::{Aggregate, EventHandler, StoreEvent};
use esrs::handler::EventHandler;
use esrs::store::StoreEvent;
use esrs::Aggregate;

pub struct KafkaEventBusConsumer<A> {
consumer: StreamConsumer,
Expand Down
9 changes: 5 additions & 4 deletions examples/event_bus/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ use rdkafka::ClientConfig;
use sqlx::{Pool, Postgres};
use uuid::Uuid;

use esrs::event_bus::kafka::{KafkaEventBus, KafkaEventBusConfig};
use esrs::event_bus::rabbit::{RabbitEventBus, RabbitEventBusConfig};
use esrs::postgres::{PgStore, PgStoreBuilder};
use esrs::{AggregateManager, AggregateState};
use esrs::bus::kafka::{KafkaEventBus, KafkaEventBusConfig};
use esrs::bus::rabbit::{RabbitEventBus, RabbitEventBusConfig};
use esrs::manager::AggregateManager;
use esrs::store::postgres::{PgStore, PgStoreBuilder};
use esrs::AggregateState;

use crate::common::{new_pool, random_letters, BasicAggregate, BasicCommand, BasicEventHandler, BasicView};
use crate::kafka::KafkaEventBusConsumer;
Expand Down
4 changes: 3 additions & 1 deletion examples/event_bus/rabbit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ use lapin::types::FieldTable;
use lapin::{Connection, ConnectionProperties, Consumer};
use serde::de::DeserializeOwned;

use esrs::{Aggregate, EventHandler, StoreEvent};
use esrs::handler::EventHandler;
use esrs::store::StoreEvent;
use esrs::Aggregate;

use crate::common::random_letters;

Expand Down
5 changes: 3 additions & 2 deletions examples/eventual_view/main.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use sqlx::{Pool, Postgres};
use uuid::Uuid;

use esrs::postgres::{PgStore, PgStoreBuilder};
use esrs::{AggregateManager, AggregateState};
use esrs::manager::AggregateManager;
use esrs::store::postgres::{PgStore, PgStoreBuilder};
use esrs::AggregateState;

use crate::common::{new_pool, BasicAggregate, BasicCommand, BasicEventHandler, BasicView};

Expand Down
6 changes: 4 additions & 2 deletions examples/locking_strategies/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ use sqlx::{Pool, Postgres};
use tokio::sync::Mutex;
use uuid::Uuid;

use esrs::postgres::{PgStore, PgStoreBuilder};
use esrs::{AggregateManager, AggregateManagerError, AggregateState, EventStore};
use esrs::manager::{AggregateManager, AggregateManagerError};
use esrs::store::postgres::{PgStore, PgStoreBuilder};
use esrs::store::EventStore;
use esrs::AggregateState;

use crate::common::{new_pool, BasicAggregate, BasicCommand, BasicEvent};

Expand Down
7 changes: 5 additions & 2 deletions examples/multi_aggregate_rebuild/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ use futures::StreamExt;
use sqlx::{PgConnection, Pool, Postgres, Transaction};
use uuid::Uuid;

use esrs::postgres::{PgStore, PgStoreBuilder, PgStoreError};
use esrs::{AggregateManager, AggregateState, ReplayableEventHandler, StoreEvent, TransactionalEventHandler};
use esrs::handler::{ReplayableEventHandler, TransactionalEventHandler};
use esrs::manager::AggregateManager;
use esrs::store::postgres::{PgStore, PgStoreBuilder, PgStoreError};
use esrs::store::StoreEvent;
use esrs::AggregateState;

use crate::common::{
new_pool, AggregateA, AggregateB, CommandA, CommandB, EventA, EventB, SharedEventHandler, SharedView,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use async_trait::async_trait;
use sqlx::PgConnection;

use esrs::postgres::PgStoreError;
use esrs::{StoreEvent, TransactionalEventHandler};
use esrs::handler::TransactionalEventHandler;
use esrs::store::postgres::PgStoreError;
use esrs::store::StoreEvent;

use crate::common::{AggregateA, AggregateB, EventA, EventB, SharedView, UpsertSharedView};

Expand Down
3 changes: 2 additions & 1 deletion examples/rebuilder/event_handler.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use async_trait::async_trait;
use sqlx::{Pool, Postgres};

use esrs::{EventHandler, ReplayableEventHandler, StoreEvent};
use esrs::handler::{EventHandler, ReplayableEventHandler};
use esrs::store::StoreEvent;

/// This is just an example. The need of v1 and v2 is due to having both the version of this event
/// handler compiled in the code. In user codebase there will be only one `BasicEventHandler`
Expand Down
5 changes: 3 additions & 2 deletions examples/rebuilder/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,10 @@
use sqlx::{Pool, Postgres};
use uuid::Uuid;

use esrs::postgres::{PgStore, PgStoreBuilder};
use esrs::manager::AggregateManager;
use esrs::rebuilder::{PgRebuilder, Rebuilder};
use esrs::{AggregateManager, AggregateState};
use esrs::store::postgres::{PgStore, PgStoreBuilder};
use esrs::AggregateState;

use crate::common::{new_pool, BasicAggregate, BasicCommand, BasicView};
use crate::event_handler::{AnotherEventHandler, BasicEventHandlerV1, BasicEventHandlerV2};
Expand Down
5 changes: 3 additions & 2 deletions examples/rebuilder/transactional_event_handler.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use async_trait::async_trait;
use sqlx::PgConnection;

use esrs::postgres::PgStoreError;
use esrs::{StoreEvent, TransactionalEventHandler};
use esrs::handler::TransactionalEventHandler;
use esrs::store::postgres::PgStoreError;
use esrs::store::StoreEvent;

use crate::common::{BasicAggregate, BasicEvent, BasicView};

Expand Down
6 changes: 4 additions & 2 deletions examples/saga/event_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ use std::sync::Arc;
use async_trait::async_trait;
use futures::lock::Mutex;

use esrs::postgres::PgStore;
use esrs::{AggregateManager, EventHandler, StoreEvent};
use esrs::handler::EventHandler;
use esrs::manager::AggregateManager;
use esrs::store::postgres::PgStore;
use esrs::store::StoreEvent;

use crate::aggregate::{SagaAggregate, SagaCommand, SagaEvent};

Expand Down
6 changes: 4 additions & 2 deletions examples/saga/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ use futures::lock::Mutex;
use sqlx::{Pool, Postgres};
use uuid::Uuid;

use esrs::postgres::{PgStore, PgStoreBuilder};
use esrs::{AggregateManager, AggregateState, EventStore};
use esrs::manager::AggregateManager;
use esrs::store::postgres::{PgStore, PgStoreBuilder};
use esrs::store::EventStore;
use esrs::AggregateState;

use crate::aggregate::{SagaAggregate, SagaCommand, SagaEvent};
use crate::common::new_pool;
Expand Down
5 changes: 3 additions & 2 deletions examples/shared_view/main.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use sqlx::{Pool, Postgres};
use uuid::Uuid;

use esrs::postgres::{PgStore, PgStoreBuilder};
use esrs::{AggregateManager, AggregateState};
use esrs::manager::AggregateManager;
use esrs::store::postgres::{PgStore, PgStoreBuilder};
use esrs::AggregateState;

use crate::common::{new_pool, AggregateA, AggregateB, CommandA, CommandB, SharedEventHandler, SharedView};

Expand Down
7 changes: 4 additions & 3 deletions examples/store_crud/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ use sqlx::types::Json;
use sqlx::{Pool, Postgres};
use uuid::Uuid;

use esrs::postgres::{PgStore, PgStoreBuilder};
use esrs::sql::Event;
use esrs::{AggregateState, EventStore, StoreEvent};
use esrs::sql::event::Event;
use esrs::store::postgres::{PgStore, PgStoreBuilder};
use esrs::store::{EventStore, StoreEvent};
use esrs::AggregateState;

use crate::common::{new_pool, BasicAggregate, BasicEvent};

Expand Down
6 changes: 4 additions & 2 deletions examples/transactional_view/main.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
use sqlx::{Pool, Postgres};
use uuid::Uuid;

use esrs::postgres::{PgStore, PgStoreBuilder};
use esrs::{AggregateManager, AggregateState, EventStore};
use esrs::manager::AggregateManager;
use esrs::store::postgres::{PgStore, PgStoreBuilder};
use esrs::store::EventStore;
use esrs::AggregateState;

use crate::common::{new_pool, BasicAggregate, BasicCommand, BasicView, BasicViewRow};
use crate::transactional_event_handler::BasicTransactionalEventHandler;
Expand Down
5 changes: 3 additions & 2 deletions examples/transactional_view/transactional_event_handler.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use async_trait::async_trait;
use sqlx::PgConnection;

use esrs::postgres::PgStoreError;
use esrs::{StoreEvent, TransactionalEventHandler};
use esrs::handler::TransactionalEventHandler;
use esrs::store::postgres::PgStoreError;
use esrs::store::StoreEvent;

use crate::common::{BasicAggregate, BasicEvent, BasicView};

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use rdkafka::ClientConfig;
use typed_builder::TypedBuilder;

use crate::event_bus::kafka::error::KafkaEventBusError;
use crate::bus::kafka::error::KafkaEventBusError;

#[derive(TypedBuilder)]
pub struct KafkaEventBusConfig<'a> {
Expand All @@ -24,7 +24,7 @@ pub struct KafkaEventBusConfig<'a> {
pub(crate) client_config: Option<ClientConfig>,
/// A boxed anonymous function utilized to provide a form of error handling, commonly used for
/// reporting purposes.
#[builder(default = Box::new(|_| ()))]
#[builder(default = Box::new(| _ | ()))]
pub(crate) error_handler: Box<dyn Fn(KafkaEventBusError) + Send + Sync>,
}

Expand Down
File renamed without changes.
5 changes: 3 additions & 2 deletions src/esrs/event_bus/kafka/mod.rs → src/bus/kafka/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ use serde::Serialize;
pub use config::KafkaEventBusConfig;
pub use error::KafkaEventBusError;

use crate::event_bus::EventBus;
use crate::{Aggregate, StoreEvent};
use crate::bus::EventBus;
use crate::store::StoreEvent;
use crate::Aggregate;

mod config;
mod error;
Expand Down
3 changes: 2 additions & 1 deletion src/esrs/event_bus.rs → src/bus/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use async_trait::async_trait;

use crate::{Aggregate, StoreEvent};
use crate::store::StoreEvent;
use crate::Aggregate;

#[cfg(feature = "kafka")]
pub mod kafka;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use lapin::types::FieldTable;
use lapin::{BasicProperties, ConnectionProperties, ExchangeKind};
use typed_builder::TypedBuilder;

use crate::event_bus::rabbit::error::RabbitEventBusError;
use crate::bus::rabbit::error::RabbitEventBusError;

#[derive(TypedBuilder)]
pub struct RabbitEventBusConfig<'a> {
Expand Down Expand Up @@ -38,6 +38,6 @@ pub struct RabbitEventBusConfig<'a> {
pub(crate) publish_properties: BasicProperties,
/// A boxed anonymous function utilized to provide a form of error handling, commonly used for
/// reporting purposes.
#[builder(default = Box::new(|_| ()))]
#[builder(default = Box::new(| _ | ()))]
pub(crate) error_handler: Box<dyn Fn(RabbitEventBusError) + Send + Sync>,
}
File renamed without changes.
5 changes: 3 additions & 2 deletions src/esrs/event_bus/rabbit/mod.rs → src/bus/rabbit/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ use serde::Serialize;
pub use config::RabbitEventBusConfig;
pub use error::RabbitEventBusError;

use crate::esrs::event_bus::EventBus;
use crate::{Aggregate, StoreEvent};
use crate::bus::EventBus;
use crate::store::StoreEvent;
use crate::Aggregate;

mod config;
mod error;
Expand Down
14 changes: 0 additions & 14 deletions src/esrs/mod.rs

This file was deleted.

3 changes: 2 additions & 1 deletion src/esrs/event_handler.rs → src/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ use std::ops::Deref;
use async_trait::async_trait;
use uuid::Uuid;

use crate::{Aggregate, StoreEvent};
use crate::store::StoreEvent;
use crate::Aggregate;

/// This trait is used to implement an [`EventHandler`]. An event handler is intended to be an entity
/// which can create, update and delete a read side and perform side effects.
Expand Down
42 changes: 12 additions & 30 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,41 +9,23 @@
//! while using `postgres` event store, everytime a state load is required a database query is
//! performed over the event store table.

pub use crate::esrs::aggregate::Aggregate;
pub use crate::esrs::aggregate_manager::AggregateManager;
pub use crate::esrs::aggregate_manager::AggregateManagerError;
pub use crate::esrs::aggregate_state::AggregateState;
#[cfg(any(feature = "kafka", feature = "rabbit"))]
pub use crate::esrs::event_bus;
pub use crate::esrs::event_handler::{EventHandler, ReplayableEventHandler, TransactionalEventHandler};
pub use crate::esrs::event_store::{EventStore, EventStoreLockGuard, StoreEvent, UnlockOnDrop};
#[cfg(feature = "rebuilder")]
pub use crate::esrs::rebuilder;
pub use aggregate::Aggregate;
pub use state::AggregateState;

mod esrs;
mod aggregate;
mod state;

#[cfg(feature = "postgres")]
pub mod postgres {
//! Provides implementation of the [`EventStore`] for Postgres.
pub use crate::esrs::postgres::PgStore;
pub use crate::esrs::postgres::PgStoreBuilder;
pub use crate::esrs::postgres::PgStoreError;
}
pub mod bus;
pub mod handler;
pub mod manager;
pub mod store;

#[cfg(feature = "rebuilder")]
pub mod rebuilder;
#[cfg(feature = "sql")]
pub mod sql {
pub use crate::esrs::sql::event::Event;
pub use crate::esrs::sql::migrations::{Migrations, MigrationsHandler};
}

pub mod error {
//! All possible errors returned by this crate
pub use serde_json::Error as JsonError;
#[cfg(feature = "sql")]
pub use sqlx::Error as SqlxError;
}
pub mod sql;

pub mod types {
//! Provides custom types.
pub use crate::esrs::SequenceNumber;
pub type SequenceNumber = i32;
}
3 changes: 2 additions & 1 deletion src/esrs/aggregate_manager.rs → src/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ use std::fmt::{Debug, Formatter};

use uuid::Uuid;

use crate::{Aggregate, AggregateState, EventStore, StoreEvent};
use crate::store::{EventStore, StoreEvent};
use crate::{Aggregate, AggregateState};

/// The AggregateManager is responsible for coupling the Aggregate with a Store, so that the events
/// can be persisted when handled, and the state can be reconstructed by loading and apply events sequentially.
Expand Down
Loading