use bevy_ecs::prelude::Message;
use spacetimedb_sdk::{
__codegen::{AbstractEventContext, InModule, SpacetimeModule},
DbContext, Error, Identity, Result,
};
use std::sync::Arc;
pub type RowEvent<T> =
<<<T as InModule>::Module as SpacetimeModule>::EventContext as AbstractEventContext>::Event;
#[derive(Message, Debug)]
pub struct StdbConnectedMessage {
pub identity: Identity,
pub access_token: String,
}
#[derive(Message, Debug)]
pub struct StdbDisconnectedMessage {
pub err: Option<Error>,
}
#[derive(Message, Debug)]
pub struct StdbConnectionErrorMessage {
pub err: Error,
}
#[derive(Message, Clone, Debug)]
pub struct StdbSubscriptionAppliedMessage<K> {
pub key: K,
}
impl<K: PartialEq> StdbSubscriptionAppliedMessage<K> {
pub fn is(&self, key: &K) -> bool {
&self.key == key
}
}
#[derive(Message, Clone, Debug)]
pub struct StdbSubscriptionErrorMessage<K> {
pub key: K,
pub err: Error,
}
impl<K: PartialEq> StdbSubscriptionErrorMessage<K> {
pub fn is(&self, key: &K) -> bool {
&self.key == key
}
}
#[derive(Message, Debug)]
pub struct InsertMessage<T>
where
T: InModule,
RowEvent<T>: Send + Sync,
{
pub event: RowEvent<T>,
pub row: T,
}
#[derive(Message, Debug)]
pub struct DeleteMessage<T>
where
T: InModule,
RowEvent<T>: Send + Sync,
{
pub event: RowEvent<T>,
pub row: T,
}
#[derive(Message, Debug)]
pub struct UpdateMessage<T>
where
T: InModule,
RowEvent<T>: Send + Sync,
{
pub event: RowEvent<T>,
pub old: T,
pub new: T,
}
#[derive(Message, Debug)]
pub struct InsertUpdateMessage<T>
where
T: InModule,
RowEvent<T>: Send + Sync,
{
pub event: RowEvent<T>,
pub old: Option<T>,
pub new: T,
}
#[derive(Message, Clone, Debug, Default)]
pub struct RequestStdbConnectionMessage {
pub token: Option<String>,
pub uri: Option<String>,
pub module_name: Option<String>,
}
#[derive(Message)]
pub(crate) struct ConnectionBuildFinishedMessage<C: DbContext + Send + Sync + 'static> {
pub result: Result<Arc<C>>,
}