mod ext_info;
mod ext_settings;
use crate::error::ReductError;
use crate::io::BoxedReadRecord;
use crate::msg::entry_api::QueryEntry;
use async_trait::async_trait;
pub use ext_info::{IoExtensionInfo, IoExtensionInfoBuilder};
use futures::stream::Stream;
pub use ext_settings::{ExtSettings, ExtSettingsBuilder};
pub type BoxedRecordStream =
Box<dyn Stream<Item = Result<BoxedReadRecord, ReductError>> + Send + Sync>;
pub const EXTENSION_API_VERSION: &str = "0.3";
#[async_trait]
pub trait Commiter {
async fn commit_record(
&mut self,
record: BoxedReadRecord,
) -> Option<Result<BoxedReadRecord, ReductError>>;
async fn flush(&mut self) -> Option<Result<BoxedReadRecord, ReductError>>;
}
#[async_trait]
pub trait Processor {
async fn process_record(
&mut self,
record: BoxedReadRecord,
) -> Result<BoxedRecordStream, ReductError>;
}
pub type BoxedCommiter = Box<dyn Commiter + Send + Sync>;
pub type BoxedProcessor = Box<dyn Processor + Send + Sync>;
#[async_trait]
pub trait IoExtension {
fn info(&self) -> &IoExtensionInfo;
fn query(
&mut self,
bucket_name: &str,
entry_name: &str,
query: &QueryEntry,
) -> Result<(BoxedProcessor, BoxedCommiter), ReductError>;
}