use async_trait::async_trait;
use crate::model::{Collection, Component, Filter, Id, Link, LinkKind};
use crate::temporal::{Date, Timestamp};
pub trait Clock {
fn now(&self) -> Timestamp;
fn today(&self) -> Date;
}
pub trait IdGenerator {
fn next_id(&self) -> Id;
}
#[async_trait(?Send)]
pub trait ComponentStore {
async fn get<C: Component>(&self, id: &Id) -> Option<C>;
async fn set<C: Component>(&self, id: &Id, value: C);
async fn remove<C: Component>(&self, id: &Id);
}
#[async_trait(?Send)]
pub trait TaskEntityStore {
async fn create(&self, id: &Id, created: Timestamp, updated: Timestamp);
async fn touch(&self, id: &Id, updated: Timestamp);
async fn meta(&self, id: &Id) -> Option<(Timestamp, Timestamp)>;
async fn delete(&self, id: &Id);
async fn all(&self) -> Vec<Id>;
}
#[async_trait(?Send)]
pub trait LinkRepository {
async fn put(&self, link: Link);
async fn remove(&self, from: &Id, to: &Id, kind: LinkKind);
async fn outgoing(&self, from: &Id, kind: LinkKind) -> Vec<Link>;
async fn incoming(&self, to: &Id, kind: LinkKind) -> Vec<Link>;
}
#[async_trait(?Send)]
pub trait BlobStore {
async fn put(&self, bytes: Vec<u8>) -> Id;
async fn get(&self, id: &Id) -> Option<Vec<u8>>;
async fn remove(&self, id: &Id);
}
#[async_trait(?Send)]
pub trait CollectionRepository {
async fn save(&self, collection: Collection);
async fn get(&self, id: &Id) -> Option<Collection>;
async fn by_name(&self, name: &str) -> Option<Collection>;
async fn all(&self) -> Vec<Collection>;
}
#[async_trait(?Send)]
pub trait QueryEngine {
async fn select(&self, filter: &Filter, today: Date) -> Vec<Id>;
}