Skip to main content

jellyflow_runtime/runtime/xyflow/
controlled.rs

1use super::apply::{
2    ApplyChangesReport, apply_edge_changes, apply_graph_changes, apply_node_changes,
3};
4use super::changes::{EdgeChange, NodeChange, NodeGraphChanges, NodeGraphPatch};
5use super::projection::XyFlowCommitProjection;
6use jellyflow_core::core::Graph;
7
8/// XyFlow-style controlled graph state for adapter-owned node/edge arrays.
9#[derive(Debug, Clone)]
10pub struct ControlledGraph {
11    graph: Graph,
12}
13
14impl ControlledGraph {
15    pub fn new(graph: Graph) -> Self {
16        Self { graph }
17    }
18
19    pub fn graph(&self) -> &Graph {
20        &self.graph
21    }
22
23    pub fn graph_mut(&mut self) -> &mut Graph {
24        &mut self.graph
25    }
26
27    pub fn into_graph(self) -> Graph {
28        self.graph
29    }
30
31    pub fn apply_changes(&mut self, changes: &NodeGraphChanges) -> ApplyChangesReport {
32        apply_graph_changes(&mut self.graph, changes)
33    }
34
35    pub fn apply_patch_changes(&mut self, patch: &NodeGraphPatch) -> ApplyChangesReport {
36        let projection = XyFlowCommitProjection::from_patch(patch);
37        self.apply_changes(projection.node_edge_changes())
38    }
39
40    pub fn apply_node_changes(&mut self, changes: &[NodeChange]) -> ApplyChangesReport {
41        apply_node_changes(&mut self.graph, changes)
42    }
43
44    pub fn apply_edge_changes(&mut self, changes: &[EdgeChange]) -> ApplyChangesReport {
45        apply_edge_changes(&mut self.graph, changes)
46    }
47}