kotoba_schema/lib.rs
1//! # kotoba-schema
2//!
3//! Graph Schema Definition and Validation for Kotoba
4//! プロセスネットワーク as GTS(DPO)+OpenGraph with Merkle DAG & PG view
5//!
6//! ## Overview
7//!
8//! This crate provides comprehensive schema management for graph databases:
9//! - Schema definition and validation
10//! - Property type system with constraints
11//! - Schema registry and management
12//! - Migration and evolution support
13//! - JSON Schema integration
14//!
15//! ## Example
16//!
17//! ```rust
18//! use kotoba_schema::{GraphSchema, SchemaManager};
19//! use kotoba_storage::StorageManager;
20//!
21//! # async fn example() -> Result<(), Box<dyn std::error::Error>> {
22//! // Create schema
23//! let schema = GraphSchema::new(
24//! "my_schema".to_string(),
25//! "My Graph Schema".to_string(),
26//! "1.0.0".to_string(),
27//! );
28//!
29//! // Create storage and schema manager
30//! let storage = StorageManager::default().await?;
31//! let backend = std::sync::Arc::new(storage.backend().clone());
32//! let mut manager = SchemaManager::new(backend);
33//!
34//! // Register schema
35//! manager.register_schema(schema).await?;
36//! # Ok(())
37//! # }
38//! ```
39
40pub mod schema;
41pub mod validator;
42pub mod manager;
43pub mod registry;
44pub mod migration;
45pub mod export;
46
47#[cfg(feature = "graph")]
48pub mod graph_integration;
49
50/// Prelude module for convenient imports
51pub mod prelude {
52 pub use crate::schema::*;
53 pub use crate::validator::*;
54 pub use crate::manager::*;
55 pub use crate::registry::*;
56 pub use crate::migration::*;
57 pub use crate::export::*;
58
59 #[cfg(feature = "graph")]
60 pub use crate::graph_integration::*;
61}
62
63// Re-export main types for convenience
64pub use schema::*;
65pub use validator::*;
66pub use manager::*;
67pub use registry::*;
68pub use migration::*;
69pub use export::*;
70
71/// Version information
72pub const VERSION: &str = env!("CARGO_PKG_VERSION");
73
74/// Get the current version of kotoba-schema
75pub fn version() -> &'static str {
76 VERSION
77}
78
79/// Feature flags
80pub mod features {
81 /// Whether graph integration is enabled
82 pub const GRAPH_INTEGRATION: bool = cfg!(feature = "graph");
83
84 /// Whether async support is enabled
85 pub const ASYNC_SUPPORT: bool = cfg!(feature = "async");
86}
87
88/// Health check for the schema system
89pub fn health_check() -> Result<(), String> {
90 // Basic health check
91 let _schema = GraphSchema::default();
92 Ok(())
93}
94
95#[cfg(test)]
96mod tests {
97 use super::*;
98
99 #[test]
100 fn test_version() {
101 assert!(!version().is_empty());
102 }
103
104 #[test]
105 fn test_health_check() {
106 assert!(health_check().is_ok());
107 }
108
109 #[test]
110 fn test_default_schema() {
111 let schema = GraphSchema::default();
112 assert_eq!(schema.id, "default");
113 assert_eq!(schema.name, "Default Graph Schema");
114 assert_eq!(schema.version, "1.0.0");
115 }
116
117 #[test]
118 fn test_schema_validation() {
119 let schema = GraphSchema::default();
120 let validation = schema.validate_schema();
121 assert!(validation.is_valid);
122 assert!(validation.errors.is_empty());
123 }
124}