kotoba-schema
Graph Schema Definition and Validation for Kotoba - プロセスネットワーク as GTS(DPO)+OpenGraph with Merkle DAG & PG view
Overview
kotoba-schema provides a comprehensive schema system for defining and validating graph structures in the Kotoba graph database. It supports:
- Schema Definition: Define vertex types, edge types, properties, and constraints
- Validation: Validate graph data against schemas
- Schema Management: Register, update, and manage schemas
- Migration Support: Migrate graph data between schema versions
- JSON Schema Integration: Export schemas as JSON Schema for external validation
Features
- ✅ Graph Schema Definition (GTS-DPO compatible)
- ✅ Property Type System with Constraints
- ✅ Schema Validation Engine
- ✅ Schema Registry and Management
- ✅ Migration and Evolution Support
- ✅ JSON Schema Export/Import
- ✅ Async Support (optional)
Usage
Basic Schema Definition
use ;
use HashMap;
// Create a new schema
let mut schema = new;
// Define User vertex type
let mut user_props = new;
user_props.insert;
let user_vertex = VertexTypeSchema ;
schema.add_vertex_type;
// Validate the schema
let validation = schema.validate_schema;
assert!;
Schema Management
use SchemaManager;
use StorageManager;
// Create storage backend
let storage_manager = default.await?;
let backend = new;
// Create schema manager
let mut schema_manager = new;
// Register schema
schema_manager.register_schema.await?;
// Validate graph data
let graph_data = json!;
let validation = schema_manager.validate_graph_data.await?;
assert!;
Schema Migration
use ;
// Create migration rules
let migration_rules = from;
// Migrate schema
let result = schema_manager.migrate_schema.await?;
println!;
Schema Definition Language
Vertex Types
let user_vertex = VertexTypeSchema ;
Edge Types
let friendship_edge = EdgeTypeSchema ;
Property Types
String: Text dataInteger: 64-bit signed integerFloat: 64-bit floating pointBoolean: True/false valuesDateTime: ISO 8601 date/timeJson: Arbitrary JSON dataArray<T>: Array of type TMap: String-keyed map of values
Constraints
Property Constraints
MinLength(n): Minimum string lengthMaxLength(n): Maximum string lengthMinValue(n): Minimum numeric valueMaxValue(n): Maximum numeric valuePattern(regex): Regular expression patternEnum(values): Allowed values listCustom(name): Custom validation rule
Schema Constraints
UniqueProperty: Unique property valuesCardinality: Edge multiplicity constraintsPathConstraint: Complex path patternsCustom: Custom schema rules
Integration with Process Network
This crate integrates with the Kotoba process network as defined in dag.jsonnet:
'schema_validator': {
name: 'schema_validator',
path: 'crates/kotoba-schema/src/validator.rs',
type: 'schema',
description: 'Graph schema validation engine',
dependencies: ['types', 'graph_core'],
provides: ['SchemaValidator', 'ValidationResult'],
status: 'completed',
build_order: 4,
},
Architecture
kotoba-schema/
├── schema.rs # Core schema definitions
├── validator.rs # Validation engine
├── manager.rs # Schema management
├── registry.rs # Schema registry
├── migration.rs # Schema migration
└── export.rs # JSON Schema export
Testing
Benchmarks
License
MIT OR Apache-2.0