use serde::{Deserialize, Serialize};
use crate::memory::{ConstraintRequest, IndexRequest};
use crate::{NodeId, NodeRecord, Properties, PropertyValue, RelationshipId, RelationshipRecord};
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub enum MutationEvent {
CreateNode {
id: NodeId,
labels: Vec<String>,
properties: Properties,
},
CreateRelationship {
id: RelationshipId,
src: NodeId,
dst: NodeId,
rel_type: String,
properties: Properties,
},
SetNodeProperty {
node_id: NodeId,
key: String,
value: PropertyValue,
},
RemoveNodeProperty {
node_id: NodeId,
key: String,
},
AddNodeLabel {
node_id: NodeId,
label: String,
},
RemoveNodeLabel {
node_id: NodeId,
label: String,
},
SetRelationshipProperty {
rel_id: RelationshipId,
key: String,
value: PropertyValue,
},
RemoveRelationshipProperty {
rel_id: RelationshipId,
key: String,
},
DeleteRelationship {
rel_id: RelationshipId,
},
DeleteNode {
node_id: NodeId,
},
DetachDeleteNode {
node_id: NodeId,
},
Clear,
CreateIndex {
request: IndexRequest,
if_not_exists: bool,
},
DropIndex {
name: String,
if_exists: bool,
},
CreateConstraint {
request: ConstraintRequest,
if_not_exists: bool,
},
DropConstraint {
name: String,
if_exists: bool,
},
}
pub trait MutationRecorder: Send + Sync + 'static {
fn record(&self, event: MutationEvent);
fn poisoned(&self) -> Option<String> {
None
}
}
pub trait DeletedRecordSink: Send + Sync + 'static {
fn node_deleted(&self, record: &NodeRecord);
fn relationship_deleted(&self, record: &RelationshipRecord);
}
pub struct ClosureRecorder<F>(pub F)
where
F: Fn(MutationEvent) + Send + Sync + 'static;
impl<F> MutationRecorder for ClosureRecorder<F>
where
F: Fn(MutationEvent) + Send + Sync + 'static,
{
fn record(&self, event: MutationEvent) {
(self.0)(event)
}
}