import { Db } from 'mongodb'; import type { Context } from '../context.js'; type Middleware = (ctx: Context, next: () => Promise) => unknown; interface DatabaseConfig { type: 'mongodb' | 'mysql' | 'postgresql' | 'redis' | 'sqlite' | 'mssql' | 'oracle' | 'cassandra' | 'elasticsearch' | 'dynamodb' | 'firebase'; connection: string | Record; pool?: { min?: number; max?: number; idleTimeoutMillis?: number; connectionTimeoutMillis?: number; }; multiTenant?: boolean; tenantKey?: string; debug?: boolean; encryptionKey?: string; enableQueryLogging?: boolean; enableAuditLog?: boolean; maxQueryTime?: number; } interface DatabaseConnection { type: string; client: unknown; pool?: unknown; multiTenant: boolean; encryptionKey?: string; queryLogging?: boolean; auditLog?: boolean; } declare const DB_SECURITY_CONFIG: { encryption: { algorithm: string; keyLength: number; ivLength: number; }; sensitiveFields: string[]; maxQueryLogSize: number; enableAuditLog: boolean; maxQueryTime: number; enableEncryption: boolean; }; declare const queryLog: Array<{ timestamp: number; connection: string; operation: string; table?: string; collection?: string; query?: string; duration: number; success: boolean; clientIP?: string; userId?: string; error?: string; }>; /** * Advanced database plugin with connection pooling and multi-tenancy * * Features: * - Connection pooling for optimal performance * - Multi-tenant database isolation * - Automatic reconnection * - Query performance monitoring * - Transaction support * - Type-safe query builders */ export declare function database(name: string, config: DatabaseConfig): Middleware; /** * Type-safe query builder for MongoDB */ export interface IMongoQueryBuilder { find(filter?: Partial): Promise; findOne(filter: Partial): Promise; insertOne(doc: unknown): Promise; updateOne(filter: Partial, update: Partial): Promise; deleteOne(filter: Partial): Promise; aggregate(pipeline: unknown[]): Promise; } export declare class MongoQueryBuilder implements IMongoQueryBuilder { private db; private collection; constructor(db: Db, collection: string); find(filter?: Partial): Promise; findOne(filter: Partial): Promise; insertOne(doc: unknown): Promise; insertMany(docs: unknown[]): Promise; updateOne(filter: Partial, update: Partial): Promise; deleteOne(filter: Partial): Promise; aggregate(pipeline: unknown[]): Promise; } /** * Type-safe query builder for SQL databases */ export interface ISQLQueryBuilder { find(where?: Partial): Promise; findOne(where: Partial): Promise; insert(data: Partial): Promise; update(where: Partial, data: Partial): Promise; delete(where: Partial): Promise; raw(query: string, values?: unknown[]): Promise; } export declare class SQLQueryBuilder implements ISQLQueryBuilder { private pool; private table; private connectionName?; private encryptionKey?; constructor(pool: unknown, table: string, connectionName?: string | undefined, encryptionKey?: string | undefined); /** * Validate table name to prevent SQL injection */ private validateTableName; /** * Safely quote identifier (table or column name) */ private quoteIdentifier; find(where?: Partial): Promise; findOne(where: Partial): Promise; insert(data: Partial): Promise; update(where: Partial, data: Partial): Promise; delete(where: Partial): Promise; raw(query: string, values?: unknown[]): Promise; private encryptSensitiveFields; private decryptSensitiveFields; } /** * Cassandra query builder */ export interface ICassandraQueryBuilder { find(keyspace: string, table: string, where?: Partial): Promise; findOne(keyspace: string, table: string, where: Partial): Promise; insert(keyspace: string, table: string, data: Partial): Promise; update(keyspace: string, table: string, where: Partial, data: Partial): Promise; delete(keyspace: string, table: string, where: Partial): Promise; } export declare class CassandraQueryBuilder implements ICassandraQueryBuilder { private client; constructor(client: unknown); /** * Validate identifier to prevent injection */ private validateIdentifier; /** * Safely quote identifier (keyspace or table name) */ private quoteIdentifier; find(keyspace: string, table: string, where?: Partial): Promise; findOne(keyspace: string, table: string, where: Partial): Promise; insert(keyspace: string, table: string, data: Partial): Promise; update(keyspace: string, table: string, where: Partial, data: Partial): Promise; delete(keyspace: string, table: string, where: Partial): Promise; } /** * Elasticsearch query builder */ export interface IElasticsearchQueryBuilder { search(index: string, query?: Record): Promise; get(index: string, id: string): Promise; index(index: string, document: T): Promise; update(index: string, id: string, document: Partial): Promise; delete(index: string, id: string): Promise; } export declare class ElasticsearchQueryBuilder implements IElasticsearchQueryBuilder { private client; constructor(client: unknown); search(index: string, query?: Record): Promise; get(index: string, id: string): Promise; index(index: string, document: T): Promise; update(index: string, id: string, document: Partial): Promise; delete(index: string, id: string): Promise; } /** * DynamoDB query builder */ export interface IDynamoDBQueryBuilder { scan(tableName: string): Promise; query(tableName: string, keyCondition: Record): Promise; get(tableName: string, key: Record): Promise; put(tableName: string, item: T): Promise; update(tableName: string, key: Record, updateExpression: string, expressionAttributeValues: Record): Promise; delete(tableName: string, key: Record): Promise; } export declare class DynamoDBQueryBuilder implements IDynamoDBQueryBuilder { private client; constructor(client: unknown); scan(tableName: string): Promise; query(tableName: string, keyCondition: Record): Promise; get(tableName: string, key: Record): Promise; put(tableName: string, item: T): Promise; update(tableName: string, key: Record, updateExpression: string, expressionAttributeValues: Record): Promise; delete(tableName: string, key: Record): Promise; } /** * Firebase query builder */ export interface IFirebaseQueryBuilder { get(collection: string, docId?: string): Promise; set(collection: string, docId: string, data: T): Promise; update(collection: string, docId: string, data: Partial): Promise; delete(collection: string, docId: string): Promise; query(collection: string, where?: [string, any, any][]): Promise; } export declare class FirebaseQueryBuilder implements IFirebaseQueryBuilder { private db; constructor(db: unknown); get(collection: string, docId?: string): Promise; set(collection: string, docId: string, data: T): Promise; update(collection: string, docId: string, data: Partial): Promise; delete(collection: string, docId: string): Promise; query(collection: string, where?: [string, any, any][]): Promise; } /** * Redis cache adapter */ export interface IRedisCache { get(key: string): Promise; set(key: string, value: unknown, ttl?: number): Promise; delete(key: string): Promise; exists(key: string): Promise; increment(key: string): Promise; expire(key: string, seconds: number): Promise; keys(pattern: string): Promise; flushAll(): Promise; } export declare class RedisCache implements IRedisCache { private client; constructor(client: unknown); get(key: string): Promise; set(key: string, value: unknown, ttl?: number): Promise; delete(key: string): Promise; exists(key: string): Promise; increment(key: string): Promise; expire(key: string, seconds: number): Promise; keys(pattern: string): Promise; flushAll(): Promise; } /** * Close all database connections */ export declare function closeAllConnections(): Promise; export declare function getQueryLogs(limit?: number): typeof queryLog; export declare function clearQueryLogs(): void; export declare function getSecurityConfig(): typeof DB_SECURITY_CONFIG; export declare function healthCheck(connectionName: string): Promise<{ status: 'healthy' | 'unhealthy'; latency: number; connections?: number; error?: string; }>; export { type DatabaseConfig, type DatabaseConnection }; //# sourceMappingURL=database.d.ts.map