use serde::{Deserialize, Serialize};
use std::borrow::Cow;
use std::collections::HashMap;
pub type NodeData = HashMap<Cow<'static, str>, serde_json::Value>;
pub type GraphNode = (String, NodeData);
pub type EdgeData = (
String,
String,
String,
HashMap<Cow<'static, str>, serde_json::Value>,
);
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct GraphEdge {
pub source_id: String,
pub target_id: String,
pub relationship_name: String,
pub properties: HashMap<Cow<'static, str>, serde_json::Value>,
}
impl GraphEdge {
pub fn new(source_id: String, target_id: String, relationship_name: String) -> Self {
Self {
source_id,
target_id,
relationship_name,
properties: HashMap::new(),
}
}
pub fn with_properties(
source_id: String,
target_id: String,
relationship_name: String,
properties: HashMap<Cow<'static, str>, serde_json::Value>,
) -> Self {
Self {
source_id,
target_id,
relationship_name,
properties,
}
}
pub fn to_edge_data(self) -> EdgeData {
(
self.source_id,
self.target_id,
self.relationship_name,
self.properties,
)
}
pub fn from_edge_data(edge: EdgeData) -> Self {
Self {
source_id: edge.0,
target_id: edge.1,
relationship_name: edge.2,
properties: edge.3,
}
}
}
impl From<GraphEdge> for EdgeData {
fn from(edge: GraphEdge) -> Self {
edge.to_edge_data()
}
}
impl From<EdgeData> for GraphEdge {
fn from(edge: EdgeData) -> Self {
GraphEdge::from_edge_data(edge)
}
}