#![allow(missing_docs)]
mod postgres;
use crate::entity::Builder;
use async_trait::async_trait;
use buildsrs_common::entities::*;
pub use postgres::*;
use ssh_key::PublicKey;
use std::{collections::BTreeSet, sync::Arc};
use uuid::Uuid;
#[cfg(feature = "options")]
mod options;
#[cfg(feature = "options")]
pub use options::DatabaseOptions;
pub type BoxError = Box<dyn std::error::Error + Send + Sync + 'static>;
pub type AnyMetadata = Arc<dyn Metadata>;
#[async_trait]
pub trait Metadata: Send + Sync + std::fmt::Debug {
async fn read(&self) -> Result<Box<dyn ReadHandle>, BoxError>;
async fn write(&self) -> Result<Box<dyn WriteHandle>, BoxError>;
}
#[async_trait]
pub trait ReadHandle: Send + Sync {
async fn builder_lookup(&self, fingerprint: &str) -> Result<Uuid, Error>;
async fn builder_get(&self, builder: Uuid) -> Result<Builder, Error>;
async fn builder_list(&self) -> Result<Vec<Uuid>, Error>;
async fn builder_triples(&self, builder: Uuid) -> Result<BTreeSet<String>, Error>;
async fn crate_list(&self, name: &str) -> Result<Vec<String>, Error>;
async fn crate_info(&self, name: &str) -> Result<CrateInfo, Error>;
async fn crate_versions(&self, name: &str) -> Result<Vec<String>, Error>;
async fn crate_version_info(&self, name: &str, version: &str) -> Result<VersionInfo, Error>;
async fn job_info(&self, job: Uuid) -> Result<JobInfo, Error>;
async fn task_list(
&self,
krate: Option<&str>,
version: Option<&str>,
task: Option<&str>,
triple: Option<&str>,
) -> Result<Vec<Task>, Error>;
}
#[async_trait]
pub trait WriteHandle: ReadHandle + Send + Sync {
async fn crate_add(&self, name: &str) -> Result<(), BoxError>;
async fn crate_version_add(
&self,
name: &str,
version: &str,
url: &str,
checksum: &[u8],
yanked: bool,
) -> Result<(), BoxError>;
async fn job_request(&self, builder: Uuid) -> Result<Uuid, BoxError>;
async fn commit(self: Box<Self>) -> Result<(), BoxError>;
async fn builder_add(&self, uuid: Uuid, key: &PublicKey, comment: &str)
-> Result<(), BoxError>;
async fn builder_set_comment(&self, builder: Uuid, comment: &str) -> Result<(), BoxError>;
async fn builder_set_enabled(&self, builder: Uuid, enabled: bool) -> Result<(), BoxError>;
async fn builder_triple_add(&self, builder: Uuid, triple: &str) -> Result<(), BoxError>;
async fn builder_triple_remove(&self, builder: Uuid, triple: &str) -> Result<(), BoxError>;
}