jellyflow_core/core/model/
graph.rs1use std::collections::BTreeMap;
2
3use serde::{Deserialize, Serialize};
4
5use crate::core::ids::{
6 BindingId, EdgeId, GraphId, GroupId, NodeId, PortId, StickyNoteId, SymbolId,
7};
8use crate::core::imports::GraphImport;
9
10use super::binding::Binding;
11use super::edge::Edge;
12use super::node::Node;
13use super::port::Port;
14use super::resources::{Group, StickyNote, Symbol};
15
16pub const GRAPH_VERSION: u32 = 1;
18
19#[derive(Debug, Clone, Serialize, Deserialize)]
21pub struct Graph {
22 pub graph_id: GraphId,
24 pub graph_version: u32,
26
27 #[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
29 pub imports: BTreeMap<GraphId, GraphImport>,
30
31 pub symbols: BTreeMap<SymbolId, Symbol>,
33
34 pub nodes: BTreeMap<NodeId, Node>,
36
37 pub ports: BTreeMap<PortId, Port>,
39
40 pub edges: BTreeMap<EdgeId, Edge>,
42
43 #[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
45 pub groups: BTreeMap<GroupId, Group>,
46
47 #[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
49 pub sticky_notes: BTreeMap<StickyNoteId, StickyNote>,
50
51 #[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
53 pub bindings: BTreeMap<BindingId, Binding>,
54}
55
56impl Default for Graph {
57 fn default() -> Self {
58 Self::new(GraphId::new())
59 }
60}
61
62impl Graph {
63 pub fn new(graph_id: GraphId) -> Self {
65 Self {
66 graph_id,
67 graph_version: GRAPH_VERSION,
68 imports: BTreeMap::new(),
69 symbols: BTreeMap::new(),
70 nodes: BTreeMap::new(),
71 ports: BTreeMap::new(),
72 edges: BTreeMap::new(),
73 groups: BTreeMap::new(),
74 sticky_notes: BTreeMap::new(),
75 bindings: BTreeMap::new(),
76 }
77 }
78}