Skip to main content

sqry_core/schema/
mod.rs

1//! Canonical schema types for sqry.
2//!
3//! This module provides the **single source of truth** for all semantic types
4//! used across sqry interfaces (CLI, LSP, MCP). Interface-specific wire types
5//! should derive from or reference these canonical definitions.
6//!
7//! # Design Goals
8//!
9//! 1. **Centralized definitions** - All semantic enums defined once
10//! 2. **Cross-interface consistency** - LSP and MCP use same underlying types
11//! 3. **Documentation** - Each type is fully documented for API consumers
12//! 4. **Serialization** - All types support JSON and postcard serialization
13//!
14//! # Type Categories
15//!
16//! ## Graph Types (re-exported from `graph::unified`)
17//! - [`NodeKind`](crate::graph::unified::node::NodeKind) - Categories of code symbols (function, class, method, etc.)
18//! - [`EdgeKind`](crate::graph::unified::edge::EdgeKind) - Relationship types between symbols (calls, imports, etc.)
19//!
20//! ## Query Types
21//! - [`RelationKind`](crate::schema::RelationKind) - Relation query types (callers, callees, imports, exports, returns)
22//! - [`Visibility`](crate::schema::Visibility) - Node visibility filter (public, private)
23//!
24//! ## Output Types
25//! - [`OutputFormat`](crate::schema::OutputFormat) - Graph/result output formats (json, dot, d2, mermaid)
26//!
27//! ## Analysis Types
28//! - [`ChangeKind`](crate::schema::ChangeKind) - Semantic diff change types (added, removed, modified, etc.)
29//! - [`CycleKind`](crate::schema::CycleKind) - Cycle detection types (calls, imports, modules)
30//! - [`DuplicateKind`](crate::schema::DuplicateKind) - Duplicate detection types (body, signature, struct)
31//! - [`UnusedScope`](crate::schema::UnusedScope) - Unused symbol scope (public, private, function, etc.)
32//!
33//! # Usage
34//!
35//! Interface packages should import these types and optionally create thin wrappers
36//! for JSON Schema generation (MCP) or protocol-specific serialization (LSP):
37//!
38//! ```rust,ignore
39//! use sqry_core::schema::{RelationKind, Visibility, OutputFormat};
40//!
41//! // MCP can derive schemars::JsonSchema on a wrapper if needed
42//! #[derive(schemars::JsonSchema)]
43//! #[serde(transparent)]
44//! pub struct RelationTypeParam(RelationKind);
45//! ```
46
47mod change;
48mod cycle;
49mod duplicate;
50mod format;
51mod relation;
52mod unused;
53mod visibility;
54
55// Re-export all canonical types
56pub use change::ChangeKind;
57pub use cycle::CycleKind;
58pub use duplicate::DuplicateKind;
59pub use format::OutputFormat;
60pub use relation::RelationKind;
61pub use unused::UnusedScope;
62pub use visibility::Visibility;
63
64// Re-export graph types as canonical schema types
65pub use crate::graph::unified::edge::EdgeKind;
66pub use crate::graph::unified::node::NodeKind;
67
68#[cfg(test)]
69mod tests {
70    use super::*;
71
72    #[test]
73    fn test_all_types_are_exported() {
74        // Verify all types are accessible
75        let _ = RelationKind::Callers;
76        let _ = Visibility::Public;
77        let _ = OutputFormat::Json;
78        let _ = ChangeKind::Added;
79        let _ = CycleKind::Calls;
80        let _ = DuplicateKind::Body;
81        let _ = UnusedScope::All;
82        let _ = NodeKind::Function;
83        let _ = EdgeKind::Calls {
84            argument_count: 0,
85            is_async: false,
86        };
87    }
88
89    #[test]
90    fn test_json_serialization() {
91        // All types should serialize to JSON consistently
92        assert_eq!(
93            serde_json::to_string(&RelationKind::Callers).unwrap(),
94            "\"callers\""
95        );
96        assert_eq!(
97            serde_json::to_string(&Visibility::Public).unwrap(),
98            "\"public\""
99        );
100        assert_eq!(
101            serde_json::to_string(&OutputFormat::Mermaid).unwrap(),
102            "\"mermaid\""
103        );
104        assert_eq!(
105            serde_json::to_string(&ChangeKind::SignatureChanged).unwrap(),
106            "\"signature_changed\""
107        );
108    }
109}