use net_backend_protocol::storage::ObjectVersion;
use net_backend_protocol::{UnixMillis, UserId};
use serde_json::Value;
use crate::hooks::Event;
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
#[non_exhaustive]
pub enum Writer {
Owner,
Server,
Admin(UserId),
}
#[derive(Clone, Debug)]
#[non_exhaustive]
pub struct BeforeStorageWrite {
pub user_id: UserId,
pub collection: String,
pub key: String,
pub value: Value,
pub if_version: Option<ObjectVersion>,
pub writer: Writer,
}
impl Event for BeforeStorageWrite {
const NAME: &'static str = "storage.before_write";
}
#[derive(Clone, Debug)]
#[non_exhaustive]
pub struct InStorageWriteTx {
pub user_id: UserId,
pub collection: String,
pub key: String,
pub value: Value,
pub version: ObjectVersion,
pub writer: Writer,
}
impl Event for InStorageWriteTx {
const NAME: &'static str = "storage.in_tx_write";
}
#[derive(Clone, Debug)]
#[non_exhaustive]
pub struct AfterStorageWrite {
pub user_id: UserId,
pub collection: String,
pub key: String,
pub value: Value,
pub version: ObjectVersion,
pub updated_at: UnixMillis,
pub writer: Writer,
}
impl Event for AfterStorageWrite {
const NAME: &'static str = "storage.after_write";
}
#[derive(Clone, Debug)]
#[non_exhaustive]
pub struct BeforeStorageDelete {
pub user_id: UserId,
pub collection: String,
pub key: String,
pub writer: Writer,
}
impl Event for BeforeStorageDelete {
const NAME: &'static str = "storage.before_delete";
}
#[derive(Clone, Debug)]
#[non_exhaustive]
pub struct AfterStorageDelete {
pub user_id: UserId,
pub collection: String,
pub key: String,
pub existed: bool,
pub writer: Writer,
}
impl Event for AfterStorageDelete {
const NAME: &'static str = "storage.after_delete";
}