@codai/cbd
Version:
Codai Better Database - High-Performance Vector Memory System with HPKV-inspired architecture and MCP server
126 lines • 3.64 kB
TypeScript
/**
* Graph Storage Engine - Neo4j-compatible graph database
* Part of CBD Universal Database Phase 3
*/
import { EventEmitter } from 'events';
export interface GraphNode {
id: string;
labels: string[];
properties: Record<string, any>;
createdAt: Date;
updatedAt: Date;
}
export interface GraphRelationship {
id: string;
type: string;
fromNodeId: string;
toNodeId: string;
properties: Record<string, any>;
createdAt: Date;
updatedAt: Date;
}
export interface GraphPath {
nodes: GraphNode[];
relationships: GraphRelationship[];
length: number;
}
export interface GraphTraversalOptions {
maxDepth?: number;
relationshipTypes?: string[];
nodeLabels?: string[];
direction?: 'incoming' | 'outgoing' | 'both';
limit?: number;
filters?: Record<string, any>;
}
export interface GraphQueryResult {
nodes: GraphNode[];
relationships: GraphRelationship[];
paths: GraphPath[];
executionTime: number;
}
export interface CypherQuery {
query: string;
parameters?: Record<string, any>;
}
export interface GraphStats {
totalNodes: number;
totalRelationships: number;
nodeLabels: Map<string, number>;
relationshipTypes: Map<string, number>;
averageDegree: number;
maxDepth: number;
queryLatency: {
p50: number;
p95: number;
p99: number;
};
}
export declare class GraphStorageEngine extends EventEmitter {
private nodes;
private relationships;
private nodeIndex;
private relationshipIndex;
private adjacencyList;
private latencies;
constructor();
initialize(): Promise<void>;
/**
* Create a new node
*/
createNode(id: string, labels?: string[], properties?: Record<string, any>): Promise<GraphNode>;
/**
* Update a node
*/
updateNode(id: string, labels?: string[], properties?: Record<string, any>): Promise<GraphNode>;
/**
* Delete a node and all its relationships
*/
deleteNode(id: string): Promise<boolean>;
/**
* Create a relationship between two nodes
*/
createRelationship(id: string, type: string, fromNodeId: string, toNodeId: string, properties?: Record<string, any>): Promise<GraphRelationship>;
/**
* Update a relationship
*/
updateRelationship(id: string, properties: Record<string, any>): Promise<GraphRelationship>;
/**
* Delete a relationship
*/
deleteRelationship(id: string): Promise<boolean>;
/**
* Find nodes by label and properties
*/
findNodes(labels?: string[], properties?: Record<string, any>, limit?: number): Promise<GraphNode[]>;
/**
* Traverse the graph from a starting node
*/
traverse(startNodeId: string, options?: GraphTraversalOptions): Promise<GraphPath[]>;
/**
* Execute a simplified Cypher-like query
*/
executeCypherQuery(cypherQuery: CypherQuery): Promise<GraphQueryResult>;
/**
* Get graph statistics
*/
getGraphStats(): Promise<GraphStats>;
/**
* Get node by ID
*/
getNode(id: string): Promise<GraphNode | null>;
/**
* Get relationship by ID
*/
getRelationship(id: string): Promise<GraphRelationship | null>;
/**
* Find relationships by type
*/
findRelationships(type?: string, properties?: Record<string, any>, limit?: number): Promise<GraphRelationship[]>;
private traverseRecursive;
private matchesProperties;
private deduplicateNodes;
private deduplicateRelationships;
private trackLatency;
private percentile;
}
//# sourceMappingURL=GraphStorageEngine.d.ts.map