jellyflow_core/ops/mutation/planner/
edges.rs1use crate::core::{Edge, EdgeId};
2use crate::ops::{GraphOp, GraphTransaction};
3
4use super::GraphMutationPlanner;
5use crate::ops::mutation::GraphMutationError;
6
7impl GraphMutationPlanner<'_> {
8 pub fn add_edge_tx(
9 &self,
10 id: EdgeId,
11 edge: Edge,
12 label: impl Into<String>,
13 ) -> Result<GraphTransaction, GraphMutationError> {
14 Ok(GraphTransaction::new()
15 .with_label(label)
16 .with_ops([self.add_edge_op(id, edge)?]))
17 }
18
19 pub fn add_edge_op(&self, id: EdgeId, edge: Edge) -> Result<GraphOp, GraphMutationError> {
20 if self.graph.edges.contains_key(&id) {
21 return Err(GraphMutationError::EdgeAlreadyExists(id));
22 }
23 if !self.graph.ports.contains_key(&edge.from) {
24 return Err(GraphMutationError::MissingPort(edge.from));
25 }
26 if !self.graph.ports.contains_key(&edge.to) {
27 return Err(GraphMutationError::MissingPort(edge.to));
28 }
29 Ok(GraphOp::AddEdge { id, edge })
30 }
31
32 pub fn remove_edge_op(&self, id: EdgeId) -> Result<GraphOp, GraphMutationError> {
33 let edge = self
34 .graph
35 .edges
36 .get(&id)
37 .cloned()
38 .ok_or(GraphMutationError::MissingEdge(id))?;
39 Ok(GraphOp::RemoveEdge {
40 id,
41 edge,
42 bindings: bindings_for_edge(self.graph, id),
43 })
44 }
45
46 pub fn remove_edge_tx(
47 &self,
48 id: EdgeId,
49 label: impl Into<String>,
50 ) -> Result<GraphTransaction, GraphMutationError> {
51 Ok(GraphTransaction::new()
52 .with_label(label)
53 .with_ops([self.remove_edge_op(id)?]))
54 }
55}
56use crate::ops::mutation::collect::bindings_for_edge;