Skip to main content

reposcry_graph/
node.rs

1use serde::{Deserialize, Serialize};
2
3#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Hash)]
4pub enum NodeKind {
5    Repository,
6    Package,
7    Directory,
8    File,
9    Module,
10    Symbol,
11    Function,
12    Method,
13    Class,
14    Struct,
15    Enum,
16    Trait,
17    Interface,
18    Component,
19    Test,
20    Config,
21    Route,
22    DatabaseTable,
23    ApiEndpoint,
24    Hook,
25    ServerAction,
26}
27
28impl NodeKind {
29    pub fn as_str(&self) -> &'static str {
30        match self {
31            NodeKind::Repository => "repository",
32            NodeKind::Package => "package",
33            NodeKind::Directory => "directory",
34            NodeKind::File => "file",
35            NodeKind::Module => "module",
36            NodeKind::Symbol => "symbol",
37            NodeKind::Function => "function",
38            NodeKind::Method => "method",
39            NodeKind::Class => "class",
40            NodeKind::Struct => "struct",
41            NodeKind::Enum => "enum",
42            NodeKind::Trait => "trait",
43            NodeKind::Interface => "interface",
44            NodeKind::Component => "component",
45            NodeKind::Test => "test",
46            NodeKind::Config => "config",
47            NodeKind::Route => "route",
48            NodeKind::DatabaseTable => "database_table",
49            NodeKind::ApiEndpoint => "api_endpoint",
50            NodeKind::Hook => "hook",
51            NodeKind::ServerAction => "server_action",
52        }
53    }
54}
55
56#[derive(Debug, Clone, Serialize, Deserialize)]
57pub struct GraphNode {
58    pub id: u64,
59    pub name: String,
60    pub kind: NodeKind,
61    pub file_path: Option<String>,
62    pub language: Option<String>,
63    pub start_line: Option<u32>,
64    pub end_line: Option<u32>,
65    pub signature: Option<String>,
66    pub visibility: Option<String>,
67    pub doc_comment: Option<String>,
68}
69
70impl GraphNode {
71    pub fn new(id: u64, name: String, kind: NodeKind) -> Self {
72        Self {
73            id,
74            name,
75            kind,
76            file_path: None,
77            language: None,
78            start_line: None,
79            end_line: None,
80            signature: None,
81            visibility: None,
82            doc_comment: None,
83        }
84    }
85}