2024-05-11 23:23:00 +02:00
|
|
|
use hyperlog_core::log::GraphItem;
|
2024-05-12 22:24:37 +02:00
|
|
|
use tonic::transport::Channel;
|
2024-05-11 23:23:00 +02:00
|
|
|
|
|
|
|
use crate::shared_engine::SharedEngine;
|
2024-04-29 23:34:04 +02:00
|
|
|
|
2024-05-12 12:58:54 +02:00
|
|
|
mod local;
|
|
|
|
mod remote;
|
|
|
|
|
2024-05-12 14:29:14 +02:00
|
|
|
#[derive(Clone)]
|
2024-05-12 12:58:54 +02:00
|
|
|
enum QuerierVariant {
|
|
|
|
Local(local::Querier),
|
2024-05-12 15:54:03 +02:00
|
|
|
Remote(remote::Querier),
|
2024-05-12 12:58:54 +02:00
|
|
|
}
|
|
|
|
|
2024-05-12 14:29:14 +02:00
|
|
|
#[derive(Clone)]
|
2024-04-29 23:34:04 +02:00
|
|
|
pub struct Querier {
|
2024-05-12 12:58:54 +02:00
|
|
|
variant: QuerierVariant,
|
2024-04-29 23:34:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Querier {
|
2024-05-12 12:58:54 +02:00
|
|
|
pub fn local(engine: &SharedEngine) -> Self {
|
|
|
|
Self {
|
|
|
|
variant: QuerierVariant::Local(local::Querier::new(engine)),
|
|
|
|
}
|
2024-05-10 22:47:32 +02:00
|
|
|
}
|
|
|
|
|
2024-05-12 22:24:37 +02:00
|
|
|
pub async fn remote(channel: Channel) -> anyhow::Result<Self> {
|
2024-05-12 15:54:03 +02:00
|
|
|
Ok(Self {
|
2024-05-12 22:24:37 +02:00
|
|
|
variant: QuerierVariant::Remote(remote::Querier::new(channel).await?),
|
2024-05-12 15:54:03 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2024-04-29 23:34:04 +02:00
|
|
|
pub fn get(
|
|
|
|
&self,
|
|
|
|
root: &str,
|
|
|
|
path: impl IntoIterator<Item = impl Into<String>>,
|
|
|
|
) -> Option<GraphItem> {
|
2024-05-12 12:58:54 +02:00
|
|
|
match &self.variant {
|
|
|
|
QuerierVariant::Local(querier) => querier.get(root, path),
|
2024-05-12 15:54:03 +02:00
|
|
|
QuerierVariant::Remote(_) => todo!(),
|
2024-05-12 12:58:54 +02:00
|
|
|
}
|
|
|
|
}
|
2024-04-29 23:34:04 +02:00
|
|
|
|
2024-05-12 14:29:14 +02:00
|
|
|
pub async fn get_async(
|
|
|
|
&self,
|
|
|
|
root: &str,
|
|
|
|
path: impl IntoIterator<Item = impl Into<String>>,
|
2024-05-12 15:54:03 +02:00
|
|
|
) -> anyhow::Result<Option<GraphItem>> {
|
2024-05-12 14:29:14 +02:00
|
|
|
match &self.variant {
|
2024-05-12 15:54:03 +02:00
|
|
|
QuerierVariant::Local(querier) => Ok(querier.get(root, path)),
|
|
|
|
QuerierVariant::Remote(querier) => querier.get(root, path).await,
|
2024-05-12 14:29:14 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-05-12 12:58:54 +02:00
|
|
|
pub fn get_available_roots(&self) -> Option<Vec<String>> {
|
|
|
|
match &self.variant {
|
|
|
|
QuerierVariant::Local(querier) => querier.get_available_roots(),
|
2024-05-12 15:54:03 +02:00
|
|
|
QuerierVariant::Remote(_) => todo!(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub async fn get_available_roots_async(&self) -> anyhow::Result<Option<Vec<String>>> {
|
|
|
|
match &self.variant {
|
|
|
|
QuerierVariant::Local(querier) => Ok(querier.get_available_roots()),
|
2024-05-12 21:07:21 +02:00
|
|
|
QuerierVariant::Remote(querier) => querier.get_available_roots().await,
|
2024-05-12 12:58:54 +02:00
|
|
|
}
|
2024-04-29 23:34:04 +02:00
|
|
|
}
|
|
|
|
}
|