/** * HTTP API Type Definitions * Types specific to HTTP API mode */ import type { DbConfig } from './adapter.js'; /** * HTTP Server Configuration */ export interface HttpConfig { port: number; host: string; apiKeys: string[]; cors: CorsConfig; rateLimit: RateLimitConfig; logging: LoggingConfig; session: SessionConfig; } /** * CORS Configuration */ export interface CorsConfig { origins: string | string[]; credentials: boolean; } /** * Rate Limiting Configuration */ export interface RateLimitConfig { max: number; window: string; } /** * Logging Configuration */ export interface LoggingConfig { level: 'debug' | 'info' | 'warn' | 'error'; pretty: boolean; } /** * Session Configuration */ export interface SessionConfig { timeout: number; cleanupInterval: number; } /** * Application Configuration */ export interface AppConfig { mode: 'mcp' | 'http'; database?: DbConfig; http?: HttpConfig; /** P0-1: query timeout in ms (overrides default 30000) */ queryTimeoutMs?: number; /** P0-1: slow query log threshold in ms (overrides default 5000) */ slowQueryThresholdMs?: number; /** v2.16: observability settings */ metrics?: MetricsConfig; /** v2.17: query analyzer settings (Explain / Lint / History / Template) */ queryAnalyzer?: QueryAnalyzerConfig; /** v2.18: multi-database profile manager settings */ profileManager?: ProfileManagerConfig; } /** * Observability / metrics configuration (v2.16+) */ export interface MetricsConfig { enabled: boolean; ipAllowList: string[]; slowBufferSize: number; } /** * Query analyzer configuration (v2.17+) * Controls Explain Plan, SQL Lint, query history, and parameterized templates. * * v2.20: cipher keys for templates.db / history.db (uses better-sqlite3-multiple-ciphers optional dep). */ export interface QueryAnalyzerConfig { enabled: boolean; templatesDbPath?: string; historyDbPath?: string; historyTtlDays: number; historyMaxRows: number; explainTimeoutMs: number; /** v2.20: SQLCipher key for templates.db. Undefined/empty → plaintext. */ templatesCipherKey?: string; /** v2.20: SQLCipher key for history.db. Undefined/empty → plaintext. */ historyCipherKey?: string; /** v2.20: rotation-old key for templates.db. */ templatesCipherKeyOld?: string; /** v2.20: rotation-old key for history.db. */ historyCipherKeyOld?: string; } /** * SQL file execution request (HTTP) * Mirrors the MCP `execute_sql_file` tool. */ export interface SqlFileRequest { sessionId: string; /** Absolute path to the .sql file (must be in DB_ALLOWED_FILE_PATHS) */ filePath: string; /** Wrap execution in a transaction (default: true) */ useTransaction?: boolean; } /** * Connect Request */ export interface ConnectRequest { type: string; host?: string; port?: number; user?: string; password?: string; database?: string; filePath?: string; authSource?: string; allowWrite?: boolean; /** Oracle Instant Client 路径(启用 Thick 模式以支持 11g) */ oracleClientPath?: string; } /** * Connect Response */ export interface ConnectResponse { sessionId: string; databaseType: string; connected: boolean; } /** * Disconnect Request */ export interface DisconnectRequest { sessionId: string; } /** * Disconnect Response */ export interface DisconnectResponse { disconnected: boolean; } /** * Query Request */ export interface QueryRequest { sessionId: string; query: string; params?: unknown[]; } /** * Execute Request (for write operations) */ export interface ExecuteRequest { sessionId: string; query: string; params?: unknown[]; } /** * Tables Request */ export interface TablesRequest { sessionId: string; } /** * Tables Response */ export interface TablesResponse { tables: string[]; } /** * Schema Request */ export interface SchemaRequest { sessionId: string; tableName?: string; } /** * API Error */ export interface ApiError { code: string; message: string; details?: unknown; } /** * Response Metadata */ export interface ResponseMetadata { executionTime?: number; timestamp: string; requestId: string; } /** * Generic API Response */ export interface ApiResponse { success: boolean; data?: T; error?: ApiError; metadata?: ResponseMetadata; } /** * Health Response */ export interface HealthResponse { status: 'healthy' | 'unhealthy'; uptime: number; timestamp: string; /** v2.16: optional observability fields (backward compatible — clients must tolerate absence) */ uptime_seconds?: number; active_db?: string; queries_total?: number; errors_total?: number; } /** * Info Response */ export interface InfoResponse { name: string; version: string; mode: string; supportedDatabases: string[]; } /** * Session */ export interface Session { id: string; adapter: any; config: DbConfig; createdAt: Date; lastAccessedAt: Date; } /** * HTTP Query Result (rows as JSON string for Coze compatibility) */ export interface HttpQueryResult { /** 查询返回的行数据(JSON字符串格式) */ rows: string; /** 受影响的行数(用于 INSERT/UPDATE/DELETE) */ affectedRows?: number; /** 执行时间(毫秒) */ executionTime?: number; /** 额外的元数据 */ metadata?: Record; } /** * Fastify Request with API Key */ export interface AuthenticatedRequest { apiKey?: string; } /** * Profile Manager configuration (v2.18+) * Controls multi-database profile management (save / use / route / global schema). * * v2.19: cipherKey for profiles.db (uses better-sqlite3-multiple-ciphers optional dep). * v2.20: templatesDbKey / historyDbKey moved to {@link QueryAnalyzerConfig} * (their stores belong to QueryAnalyzer, not ProfileManager). * v2.20: cipherKeyOld for rotation (set during one startup cycle after rotation). */ export interface ProfileManagerConfig { enabled: boolean; profilesDbPath?: string; maxProfiles: number; defaultRole: 'primary' | 'replica' | 'analytics'; readRouting: 'round-robin' | 'random' | 'least-loaded'; /** v2.19: SQLCipher key for profiles.db. Undefined/empty → plaintext fallback. */ cipherKey?: string; /** v2.20: rotation-old key. Set when DB_PROFILE_ENCRYPTION_KEY_OLD is provided. */ cipherKeyOld?: string; } //# sourceMappingURL=http.d.ts.map