use std::sync::Arc;
use nodedb_array::sync::hlc::Hlc;
use nodedb_array::sync::op_log::OpLog;
use super::op_log::OriginOpLog;
use super::schema_registry::OriginSchemaRegistry;
pub struct OriginApplyEngine {
pub(super) schemas: Arc<OriginSchemaRegistry>,
pub(super) op_log: Arc<OriginOpLog>,
}
impl OriginApplyEngine {
pub fn new(schemas: Arc<OriginSchemaRegistry>, op_log: Arc<OriginOpLog>) -> Self {
Self { schemas, op_log }
}
pub fn schema_hlc(&self, array: &str) -> Option<Hlc> {
self.schemas.schema_hlc(array)
}
pub fn already_seen(&self, array: &str, hlc: Hlc) -> bool {
match self.op_log.scan_range(array, hlc, hlc) {
Ok(mut iter) => iter.next().is_some(),
Err(_) => false,
}
}
pub fn record_applied(
&self,
op: &nodedb_array::sync::op::ArrayOp,
) -> nodedb_array::error::ArrayResult<()> {
self.op_log.append(op)
}
}