use crate::{
app::Context,
domain::{Aggregate, CommandEnum, EventEnum},
errors::UniError,
};
use ahash::{AHashMap, AHashSet};
use rkyv::{
Archive, Deserialize,
de::Pool,
rancor::{Error, Strategy},
};
use uuid::Uuid;
pub trait Restore: Send + 'static {
type Fut: Future<Output = Result<AHashMap<Uuid, AHashSet<Uuid>>, UniError>> + Send;
fn restore(&self, agg_type: &'static str, latest: i64) -> Self::Fut;
}
pub trait Stream: Send + Sync + 'static {
fn write(
&self,
agg_type: &'static str,
agg_id: Uuid,
com_id: Uuid,
revision: u64,
evt_data: &[u8],
) -> impl Future<Output = Result<(), UniError>> + Send;
fn respond(
&self,
agg_type: &'static str,
agg_id: Uuid,
com_id: Uuid,
res: &[u8; 1],
evt_data: &[u8],
) -> impl Future<Output = Result<(), UniError>> + Send;
}
pub trait Subscriber<A, C, E>: 'static
where
A: Aggregate,
C: CommandEnum<A = A, E = E>,
<C as Archive>::Archived: Deserialize<C, Strategy<Pool, Error>>,
E: EventEnum<A = A>,
<E as Archive>::Archived: Deserialize<E, Strategy<Pool, Error>>,
{
#[doc(hidden)]
fn launch(ctx: &'static Context) -> impl Future<Output = Result<(), String>>;
}