@simonecoelhosfo/optimizely-mcp-server
Version:
Optimizely MCP Server for AI assistants with integrated CLI tools
128 lines • 4.24 kB
TypeScript
import Database from '../database/better-sqlite3-loader.js';
export interface SQLiteEngineConfig {
path: string;
backupDir?: string;
verbose?: (message: string) => void;
retryConfig?: {
maxRetries?: number;
baseDelay?: number;
maxDelay?: number;
exponentialBase?: number;
};
connectionConfig?: {
busyTimeout?: number;
cacheSize?: number;
maxConnections?: number;
};
}
export interface RetryableOperation<T> {
(): Promise<T> | T;
}
export declare class SQLiteEngine {
private db;
private config;
private isInitialized;
private readonly SCHEMA_VERSION;
private viewManager;
private operationQueue;
private isProcessingQueue;
private connectionPool;
private activeConnections;
private maxConnections;
private readonly retryConfig;
private readonly connectionConfig;
constructor(config: SQLiteEngineConfig);
/**
* Get the database file path
*/
get dbPath(): string;
init(options?: {
skipMigration?: boolean;
confirmReset?: boolean;
}): Promise<void>;
/**
* Check migration status without modifying the database
* @returns Migration status information
*/
checkMigrationStatus(): Promise<{
needsMigration: boolean;
currentVersion: number;
targetVersion: number;
reason?: string;
}>;
private checkNeedsMigration;
private setSchemaVersion;
private dropAllTables;
private createSchema;
/**
* Create all database views
* This ensures views are always created during initialization
*/
private createViews;
private migrateSchema;
query(sql: string, params?: any[]): Promise<any[]>;
get(sql: string, params?: any[]): Promise<any>;
/**
* Retry mechanism with exponential backoff for database operations
* Handles SQLite BUSY, LOCKED, and other transient errors
*/
private retryOperation;
/**
* Determines if an error is retryable based on SQLite error codes and patterns
*/
private isRetryableError;
/**
* Enhanced transaction wrapper with IMMEDIATE locking
* Prevents most deadlock scenarios by acquiring locks early
*/
private withTransaction;
/**
* Sleep utility for retry delays
*/
private sleep;
run(sql: string, params?: any[]): Promise<{
lastID?: number;
changes: number;
}>;
/**
* Enhanced batch operation method with progress reporting
* Performs multi-value INSERT operations for optimal performance
* @param baseSQL - Base SQL statement with single VALUES placeholder
* @param batchParams - Array of parameter arrays for batch insertion
* @param batchSize - Number of records to process per batch (default: 100)
* @param progressCallback - Optional callback for progress reporting
* @returns Promise that resolves when all batches are complete
*
* @example
* await engine.runBatch(
* "INSERT OR REPLACE INTO audiences (id, name) VALUES (?)",
* [["1", "Audience 1"], ["2", "Audience 2"]],
* 100,
* (saved, total) => console.log(`Progress: ${saved}/${total}`)
* );
*/
runBatch(baseSQL: string, batchParams: any[][], batchSize?: number, progressCallback?: (saved: number, total: number) => void): Promise<void>;
beginTransaction(): Promise<void>;
commit(): Promise<void>;
rollback(): Promise<void>;
transaction<T>(operations: (engine: SQLiteEngine) => Promise<T>): Promise<T>;
/**
* Test method for validating database locking solution
* Simulates concurrent operations to verify retry and queue mechanisms work
*/
testConcurrentOperations(): Promise<{
success: boolean;
results: any[];
}>;
backup(backupPath?: string): Promise<string>;
reset(): Promise<void>;
close(): Promise<void>;
getPath(): string;
isReady(): boolean;
/**
* Get the underlying Database instance for advanced operations
* @returns {Database.Database | null} The SQLite database instance
*/
getDatabase(): Database.Database | null;
}
//# sourceMappingURL=SQLiteEngine.d.ts.map