use chrono::{DateTime, Utc};
use uuid::Uuid;
#[derive(Clone, PartialEq, Eq, Debug)]
pub struct Client {
pub latest_version_id: Uuid,
pub snapshot: Option<Snapshot>,
}
#[derive(Clone, PartialEq, Eq, Debug)]
pub struct Snapshot {
pub version_id: Uuid,
pub timestamp: DateTime<Utc>,
pub versions_since: u32,
}
#[derive(Clone, PartialEq, Eq, Debug)]
pub struct Version {
pub version_id: Uuid,
pub parent_version_id: Uuid,
pub history_segment: Vec<u8>,
}
#[async_trait::async_trait(?Send)]
pub trait StorageTxn {
async fn get_client(&mut self) -> anyhow::Result<Option<Client>>;
async fn new_client(&mut self, latest_version_id: Uuid) -> anyhow::Result<()>;
async fn set_snapshot(&mut self, snapshot: Snapshot, data: Vec<u8>) -> anyhow::Result<()>;
async fn get_snapshot_data(&mut self, version_id: Uuid) -> anyhow::Result<Option<Vec<u8>>>;
async fn get_version_by_parent(
&mut self,
parent_version_id: Uuid,
) -> anyhow::Result<Option<Version>>;
async fn get_version(&mut self, version_id: Uuid) -> anyhow::Result<Option<Version>>;
async fn add_version(
&mut self,
version_id: Uuid,
parent_version_id: Uuid,
history_segment: Vec<u8>,
) -> anyhow::Result<()>;
async fn commit(&mut self) -> anyhow::Result<()>;
}
#[async_trait::async_trait]
pub trait Storage: Send + Sync {
async fn txn(&self, client_id: Uuid) -> anyhow::Result<Box<dyn StorageTxn + '_>>;
}