/** * Base Graph Adapter * * Abstract base class defining the interface for all graph database adapters. * Each adapter implementation must extend this class and implement all abstract methods. */ import { GraphType, GraphFeature } from '../types/enums'; import { IGraphConnectionOptions, IGraphConnectionResult, IGraphTestConnectionResult } from '../types/connection.interface'; import { ICreateNodeOptions, ICreateNodeResult, IFindNodesOptions, IFindNodesResult, IUpdateNodeOptions, IUpdateNodeResult, IDeleteNodeOptions, IDeleteNodeResult, IMergeNodeOptions, IMergeNodeResult, INode, IAddLabelsOptions, IAddLabelsResult, IRemoveLabelsOptions, IRemoveLabelsResult, ISetLabelsOptions, ISetLabelsResult } from '../types/node.interface'; import { ICreateRelationshipOptions, ICreateRelationshipResult, IFindRelationshipsOptions, IFindRelationshipsResult, IUpdateRelationshipOptions, IUpdateRelationshipResult, IDeleteRelationshipOptions, IDeleteRelationshipResult, IMergeRelationshipOptions, IMergeRelationshipResult, IRelationship } from '../types/relationship.interface'; import { ITraverseOptions, ITraverseResult, IShortestPathOptions, IShortestPathResult, IAllPathsOptions, IAllPathsResult, INeighborhoodOptions, INeighborhoodResult, IConnectedComponentsOptions, IConnectedComponentsResult } from '../types/traversal.interface'; import { IGraphTransaction, IGraphTransactionOptions } from '../types/transaction.interface'; import { IRawQueryOptions, IRawQueryResult, ICountNodesResult, ICountRelationshipsResult, IGraphStatistics, IFullTextSearchOptions, IFullTextSearchResult, IVectorSearchOptions, IVectorSearchResult, IGraphWhereClause } from '../types/query.interface'; import { ICreateNodeIndexOptions, ICreateNodeConstraintOptions, IListIndexesResult, IListConstraintsResult, ICreateIndexResult, ICreateConstraintResult, IDropIndexResult, IDropConstraintResult, IListLabelsResult, IListRelationshipTypesResult } from '../types/schema.interface'; import { ICreateRelationshipIndexOptions } from '../types/relationship.interface'; /** * Adapter connection options */ export interface IAdapterConnectionOptions { /** Connection URL */ connectionUrl: string; /** Route TCP via VPC connector relay (private Neptune) */ vpcConnectorTunnel?: import('../../database/types/connection.interface').IVpcConnectorTunnelOptions; /** Database name (for some adapters) */ database?: string; /** Graph name (for some adapters) */ graphName?: string; /** Authentication credentials */ auth?: { username: string; password: string; }; /** Additional connection options */ options?: IGraphConnectionOptions; } /** * Abstract base class for graph database adapters */ export declare abstract class BaseGraphAdapter { /** Graph database type this adapter handles */ protected abstract readonly graphType: GraphType; /** Underlying client instance */ protected client: any; /** Whether currently connected */ protected connected: boolean; /** Current connection URL */ protected connectionUrl: string; /** Connection options (stored for reconnection) */ protected connectionOptions: IAdapterConnectionOptions | null; /** Maximum retry attempts for auto-reconnection */ protected maxRetries: number; /** Flag to indicate if a reconnection is in progress */ private reconnecting; /** Supported features for this adapter */ protected abstract readonly supportedFeatures: Set; /** * Execute an operation with automatic retry on connection errors. * This handles transient connection timeouts and disconnects silently. */ protected executeWithRetry(operation: () => Promise, retries?: number): Promise; /** * Check if an error is a connection-related error */ protected isConnectionError(error: any): boolean; /** * Attempt to reconnect to the graph database */ protected attemptReconnect(): Promise; /** * Connect to the graph database */ abstract connect(options: IAdapterConnectionOptions): Promise; /** * Test connection without persisting */ abstract testConnection(options: IAdapterConnectionOptions): Promise; /** * Disconnect from the graph database */ abstract disconnect(): Promise; /** * Check if connected */ isConnected(): boolean; /** * Get the graph type */ getGraphType(): GraphType; /** * Check if a feature is supported */ supportsFeature(feature: GraphFeature): boolean; /** * Get all supported features */ getSupportedFeatures(): GraphFeature[]; /** * Create a node */ abstract createNode(options: ICreateNodeOptions, transaction?: IGraphTransaction): Promise>; /** * Find nodes by criteria */ abstract findNodes(options: IFindNodesOptions, transaction?: IGraphTransaction): Promise>; /** * Find a single node by ID */ abstract findNodeById(id: string | number, transaction?: IGraphTransaction): Promise | null>; /** * Update a node */ abstract updateNode(options: IUpdateNodeOptions, transaction?: IGraphTransaction): Promise>; /** * Delete a node */ abstract deleteNode(options: IDeleteNodeOptions, transaction?: IGraphTransaction): Promise; /** * Merge (upsert) a node */ abstract mergeNode(options: IMergeNodeOptions, transaction?: IGraphTransaction): Promise>; /** * Add labels to a node */ abstract addLabels(options: IAddLabelsOptions, transaction?: IGraphTransaction): Promise>; /** * Remove labels from a node */ abstract removeLabels(options: IRemoveLabelsOptions, transaction?: IGraphTransaction): Promise>; /** * Set labels on a node (replaces all existing labels) */ abstract setLabels(options: ISetLabelsOptions, transaction?: IGraphTransaction): Promise>; /** * Create a relationship */ abstract createRelationship(options: ICreateRelationshipOptions, transaction?: IGraphTransaction): Promise>; /** * Find relationships by criteria */ abstract findRelationships(options: IFindRelationshipsOptions, transaction?: IGraphTransaction): Promise>; /** * Find a single relationship by ID */ abstract findRelationshipById(id: string | number, transaction?: IGraphTransaction): Promise | null>; /** * Update a relationship */ abstract updateRelationship(options: IUpdateRelationshipOptions, transaction?: IGraphTransaction): Promise>; /** * Delete a relationship */ abstract deleteRelationship(options: IDeleteRelationshipOptions, transaction?: IGraphTransaction): Promise; /** * Merge (upsert) a relationship */ abstract mergeRelationship(options: IMergeRelationshipOptions, transaction?: IGraphTransaction): Promise>; /** * Traverse the graph from a starting node */ abstract traverse(options: ITraverseOptions, transaction?: IGraphTransaction): Promise>; /** * Find the shortest path between two nodes */ abstract shortestPath(options: IShortestPathOptions, transaction?: IGraphTransaction): Promise>; /** * Find all paths between two nodes */ abstract allPaths(options: IAllPathsOptions, transaction?: IGraphTransaction): Promise>; /** * Get the neighborhood of a node */ abstract getNeighborhood(options: INeighborhoodOptions, transaction?: IGraphTransaction): Promise>; /** * Find connected components in the graph */ abstract findConnectedComponents(options: IConnectedComponentsOptions, transaction?: IGraphTransaction): Promise>; /** * Count nodes matching criteria */ abstract countNodes(labels?: string[], where?: IGraphWhereClause, transaction?: IGraphTransaction): Promise; /** * Count relationships matching criteria */ abstract countRelationships(types?: string[], where?: IGraphWhereClause, transaction?: IGraphTransaction): Promise; /** * Get graph statistics */ abstract getStatistics(transaction?: IGraphTransaction): Promise; /** * Full-text search */ abstract fullTextSearch(options: IFullTextSearchOptions, transaction?: IGraphTransaction): Promise>; /** * Vector similarity search */ abstract vectorSearch(options: IVectorSearchOptions, transaction?: IGraphTransaction): Promise>; /** * Execute a raw query */ abstract query(options: IRawQueryOptions, transaction?: IGraphTransaction): Promise>; /** * Create a node index */ abstract createNodeIndex(options: ICreateNodeIndexOptions): Promise; /** * Create a node constraint */ abstract createNodeConstraint(options: ICreateNodeConstraintOptions): Promise; /** * Create a relationship index */ abstract createRelationshipIndex(options: ICreateRelationshipIndexOptions): Promise; /** * List all indexes */ abstract listIndexes(): Promise; /** * List all constraints */ abstract listConstraints(): Promise; /** * Drop an index */ abstract dropIndex(name: string): Promise; /** * Drop a constraint */ abstract dropConstraint(name: string): Promise; /** * List all node labels with counts and property information */ abstract listLabels(): Promise; /** * List all relationship types with counts */ abstract listRelationshipTypes(): Promise; /** * Begin a transaction */ abstract beginTransaction(options?: IGraphTransactionOptions): Promise; /** * Commit a transaction */ abstract commitTransaction(transaction: IGraphTransaction): Promise; /** * Rollback a transaction */ abstract rollbackTransaction(transaction: IGraphTransaction): Promise; /** * Get the underlying client */ getClient(): any; /** * Ensure the adapter is connected before performing operations * @throws GraphError if not connected */ protected ensureConnected(): void; /** * Build where clause for the specific database */ protected abstract buildWhereClause(where: IGraphWhereClause): any; /** * Parse database error into GraphError */ abstract parseError(error: unknown): Error; }