use std::{
collections::{BTreeMap, BTreeSet},
path::PathBuf,
};
use serde::Serialize;
pub use sephera_core::types::ImportKind;
pub use sephera_core::types::ImportStatement;
use super::manifests;
#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
pub struct FileImports {
pub file_path: String,
pub language: Option<&'static str>,
pub imports: Vec<ImportStatement>,
}
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize)]
pub struct GraphEdge {
pub from: String,
pub to: Option<String>,
pub import_path: String,
pub resolved: bool,
pub local_gap: bool,
pub cfg_gated: bool,
#[serde(default)]
pub kind: ImportKind,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
pub struct GraphNode {
pub file_path: String,
pub language: Option<&'static str>,
pub imports_count: u64,
pub imported_by_count: u64,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
pub struct GraphMetrics {
pub total_files: u64,
pub total_internal_edges: u64,
pub self_references: u64,
pub total_external_edges: u64,
pub unresolved_local_edges: u64,
pub unresolved_local_samples: Vec<String>,
pub cfg_gated_edges: u64,
pub dependencies: Vec<manifests::Dependency>,
pub declared_dependency_edges: u64,
pub local_crate_edges: u64,
pub builtin_edges: u64,
pub circular_dependencies: u64,
pub most_importing: Vec<FileMetric>,
pub most_imported: Vec<FileMetric>,
pub cycles: Vec<Vec<String>>,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
pub struct FileMetric {
pub file_path: String,
pub count: u64,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
pub struct GraphReport {
pub base_path: PathBuf,
pub focus_paths: Vec<String>,
pub depth: Option<u32>,
pub query: Option<GraphQuery>,
pub nodes: Vec<GraphNode>,
pub edges: Vec<GraphEdge>,
pub metrics: GraphMetrics,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum GraphFormat {
Json,
Markdown,
Xml,
Dot,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
#[serde(rename_all = "snake_case")]
pub enum GraphQuery {
DependsOn(String),
}
pub(super) type NodeMap = BTreeMap<String, NodeEntry>;
#[derive(Debug, Default, Clone)]
pub(super) struct NodeEntry {
pub language: Option<&'static str>,
pub imports: Vec<String>,
pub imported_by: Vec<String>,
pub declarations: BTreeSet<String>,
}