Skip to main content

alizarin_core/graph/
meta.rs

1//! Lightweight graph metadata type.
2
3use super::nodes::StaticNode;
4use super::translatable::StaticTranslatableString;
5use serde::{Deserialize, Serialize};
6use std::collections::HashMap;
7
8/// Lightweight metadata about a graph, without the full nodes/edges arrays.
9/// Used for listing graphs without loading all their data.
10#[derive(Serialize, Deserialize, Clone, Debug)]
11pub struct StaticGraphMeta {
12    pub graphid: String,
13    #[serde(default)]
14    pub author: Option<String>,
15    #[serde(default)]
16    pub cards: Option<u32>,
17    #[serde(default)]
18    pub cards_x_nodes_x_widgets: Option<u32>,
19    #[serde(default)]
20    pub color: Option<String>,
21    #[serde(default)]
22    pub description: Option<StaticTranslatableString>,
23    #[serde(default)]
24    pub edges: Option<u32>,
25    #[serde(default)]
26    pub iconclass: Option<String>,
27    #[serde(default)]
28    pub is_editable: Option<bool>,
29    #[serde(default)]
30    pub isresource: Option<bool>,
31    /// JSON-LD context - can be a string (URL) or an object (inline context)
32    #[serde(default)]
33    pub jsonldcontext: Option<serde_json::Value>,
34    #[serde(default)]
35    pub name: Option<StaticTranslatableString>,
36    #[serde(default)]
37    pub nodegroups: Option<u32>,
38    #[serde(default)]
39    pub nodes: Option<u32>,
40    /// Ontology IDs used by this graph. Accepts a single string or an array
41    /// of strings on the wire.
42    #[serde(default, with = "super::serde_helpers::optional_string_or_vec")]
43    pub ontology_id: Option<Vec<String>>,
44    #[serde(default)]
45    pub publication: Option<HashMap<String, Option<String>>>,
46    #[serde(default)]
47    pub relatable_resource_model_ids: Vec<String>,
48    #[serde(default)]
49    pub resource_2_resource_constraints: Option<Vec<serde_json::Value>>,
50    #[serde(default)]
51    pub root: Option<Box<StaticNode>>,
52    #[serde(default)]
53    pub slug: Option<String>,
54    #[serde(default)]
55    pub subtitle: Option<StaticTranslatableString>,
56    #[serde(default)]
57    pub version: Option<String>,
58    /// Extra fields not explicitly defined
59    #[serde(default, flatten)]
60    pub extra_fields: HashMap<String, serde_json::Value>,
61}
62
63impl StaticGraphMeta {
64    /// Get the display name of the graph
65    pub fn display_name(&self) -> String {
66        self.name
67            .as_ref()
68            .map(|n| n.to_string_default())
69            .unwrap_or_default()
70    }
71
72    /// Get the display subtitle
73    pub fn display_subtitle(&self) -> String {
74        self.subtitle
75            .as_ref()
76            .map(|s| s.to_string_default())
77            .unwrap_or_default()
78    }
79
80    /// Get the display description
81    pub fn display_description(&self) -> String {
82        self.description
83            .as_ref()
84            .map(|d| d.to_string_default())
85            .unwrap_or_default()
86    }
87
88    /// Get the author
89    pub fn display_author(&self) -> String {
90        self.author.clone().unwrap_or_default()
91    }
92}