use std::sync::Arc;
use anyhow::Result;
#[cfg(feature = "jwks")]
use chrono::{DateTime, Utc};
#[cfg(feature = "jwks")]
use jsonwebtoken::jwk::JwkSet;
use crate::catalog::{self};
#[cfg(feature = "jwks")]
#[derive(Debug)]
pub(crate) struct CachedJwks {
pub(crate) jwks: JwkSet,
pub(crate) time: DateTime<Utc>,
}
#[derive(Clone, Debug)]
pub(crate) enum Entry {
#[cfg(feature = "jwks")]
Jwk(Arc<CachedJwks>),
Fds(Arc<[catalog::FieldDefinition]>),
Evs(Arc<[catalog::EventDefinition]>),
Fts(Arc<[catalog::TableDefinition]>),
Ixs(Arc<[catalog::IndexDefinition]>),
Lvs(Arc<[catalog::SubscriptionDefinition]>),
}
impl Entry {
#[cfg(feature = "jwks")]
pub(crate) fn try_into_jwk(self) -> Result<Arc<CachedJwks>> {
match self {
Entry::Jwk(v) => Ok(v),
_ => fail!("Unable to convert type into Entry::Jwk"),
}
}
pub(crate) fn try_into_fds(self) -> Result<Arc<[catalog::FieldDefinition]>> {
match self {
Entry::Fds(v) => Ok(v),
_ => fail!("Unable to convert type into Entry::Fds"),
}
}
pub(crate) fn try_into_evs(self) -> Result<Arc<[catalog::EventDefinition]>> {
match self {
Entry::Evs(v) => Ok(v),
_ => fail!("Unable to convert type into Entry::Evs"),
}
}
pub(crate) fn try_into_ixs(self) -> Result<Arc<[catalog::IndexDefinition]>> {
match self {
Entry::Ixs(v) => Ok(v),
_ => fail!("Unable to convert type into Entry::Ixs"),
}
}
pub(crate) fn try_into_fts(self) -> Result<Arc<[catalog::TableDefinition]>> {
match self {
Entry::Fts(v) => Ok(v),
_ => fail!("Unable to convert type into Entry::Fts"),
}
}
pub(crate) fn try_into_lvs(self) -> Result<Arc<[catalog::SubscriptionDefinition]>> {
match self {
Entry::Lvs(v) => Ok(v),
_ => fail!("Unable to convert type into Entry::Lvs"),
}
}
}