mod error;
mod event_store;
#[cfg(feature = "listener")]
mod listener;
mod snapshotter;
pub use crate::event_store::PgEventStore;
#[cfg(feature = "listener")]
pub use crate::listener::{PgEventListener, PgEventListenerConfig};
pub use crate::snapshotter::PgSnapshotter;
use disintegrate::{DecisionMaker, EventSourcedDecisionStateStore, NoSnapshot, WithSnapshot};
use disintegrate_serde::Serde;
pub use error::Error;
pub type PgDecisionMaker<E, S, SN> =
DecisionMaker<EventSourcedDecisionStateStore<PgEventStore<E, S>, SN>>;
pub type WithPgSnapshot = WithSnapshot<PgSnapshotter>;
pub async fn decision_maker_with_snapshot<E: Clone, S: Serde<E> + Clone + Sync + Send>(
event_store: PgEventStore<E, S>,
every: u64,
) -> Result<PgDecisionMaker<E, S, WithPgSnapshot>, Error> {
let pool = event_store.pool.clone();
let snapshot = WithSnapshot::new(PgSnapshotter::new(pool, every).await?);
Ok(DecisionMaker::new(EventSourcedDecisionStateStore::new(
event_store,
snapshot,
)))
}
pub fn decision_maker<E: Clone, S: Serde<E> + Clone + Sync + Send>(
event_store: PgEventStore<E, S>,
) -> PgDecisionMaker<E, S, NoSnapshot> {
DecisionMaker::new(EventSourcedDecisionStateStore::new(event_store, NoSnapshot))
}