use akita_core::{cfg_if, InterceptorType, OperationType};
use std::collections::HashSet;
pub mod cache;
pub mod cursor_pagination;
pub mod field_fill;
mod logging;
pub mod optimistic_lock;
pub mod pagination;
pub mod performance;
pub mod shared;
pub mod soft_delete;
pub mod tenant;
pub use cache::CacheInterceptor;
pub use cursor_pagination::CursorPaginationInterceptor;
pub use field_fill::FieldFillInterceptor;
pub use logging::LoggingInterceptor;
pub use optimistic_lock::OptimisticLockerInterceptor;
pub use pagination::PaginationInterceptor;
pub use performance::PerformanceInterceptor;
pub use shared::InterceptorBase;
pub use soft_delete::SoftDeleteInterceptor;
pub use tenant::TenantLineInterceptor;
cfg_if! {if #[cfg(any(
feature = "mysql-sync",
feature = "postgres-sync",
feature = "sqlite-sync",
feature = "oracle-sync",
feature = "mssql-sync"
))] {
pub mod blocking;
}}
cfg_if! {if #[cfg(any(
feature = "mysql-async",
feature = "postgres-async",
feature = "sqlite-async",
feature = "oracle-async",
feature = "mssql-async"
))] {
pub mod non_blocking;
}}
#[derive(Debug, Clone)]
pub struct InterceptorConfig {
pub enable_async: bool,
pub enable_metrics: bool,
pub enable_tracing: bool,
pub max_interceptor_depth: usize,
pub timeout_ms: u64,
}
impl Default for InterceptorConfig {
fn default() -> Self {
Self {
enable_async: true,
enable_metrics: true,
enable_tracing: true,
max_interceptor_depth: 10,
timeout_ms: 5000,
}
}
}
#[derive(Debug, Clone)]
pub struct InterceptorConfigItem {
pub enabled: bool,
pub order: i32,
pub ignored_tables: HashSet<String>,
pub supported_operations: HashSet<OperationType>,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum LogLevel {
Trace = 1,
Debug = 2,
Info = 3,
Warn = 4,
Error = 5,
}
impl LogLevel {
pub fn from_str(s: &str) -> Option<Self> {
match s.to_uppercase().as_str() {
"ERROR" | "ERR" => Some(LogLevel::Error),
"WARN" | "WARNING" => Some(LogLevel::Warn),
"INFO" => Some(LogLevel::Info),
"DEBUG" => Some(LogLevel::Debug),
"TRACE" => Some(LogLevel::Trace),
_ => None,
}
}
pub fn as_str(&self) -> &'static str {
match self {
LogLevel::Error => "ERROR",
LogLevel::Warn => "WARN",
LogLevel::Info => "INFO",
LogLevel::Debug => "DEBUG",
LogLevel::Trace => "TRACE",
}
}
pub fn should_log(&self, other: LogLevel) -> bool {
*self <= other
}
}
impl PartialOrd for LogLevel {
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
Some((*self as u8).cmp(&(*other as u8)))
}
}
impl Ord for LogLevel {
fn cmp(&self, other: &Self) -> std::cmp::Ordering {
(*self as u8).cmp(&(*other as u8))
}
}
impl std::fmt::Display for LogLevel {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.as_str())
}
}
impl Default for LogLevel {
fn default() -> Self {
Self::Info
}
}