/**
 * SQL Safety Validator
 *
 * Validates SQL queries before execution to ensure safety.
 * This is the security gatekeeper for agent-generated SQL.
 *
 * Validation layers:
 * 1. Syntax check - basic SQL structure
 * 2. Statement type - only SELECT allowed
 * 3. Table whitelist - only approved tables
 * 4. Pattern blocklist - no dangerous patterns
 * 5. Complexity limits - prevent runaway queries
 *
 * Design principles:
 * - Fail closed (reject on uncertainty)
 * - Defense in depth (multiple validation layers)
 * - Clear error messages for debugging
 * - Performance-aware (avoid regex catastrophe)
 */
import type { SQLConstraints } from './sqlGenerator';
/**
 * Validation result
 */
export interface ValidationResult {
    /** Whether the query passed validation */
    valid: boolean;
    /** Error message if validation failed */
    reason?: string;
    /** All validation errors (may be multiple) */
    errors: ValidationError[];
    /** Warnings (non-blocking issues) */
    warnings: ValidationWarning[];
    /** Extracted metadata from query */
    metadata?: QueryMetadata;
}
/**
 * Validation error
 */
export interface ValidationError {
    code: ValidationErrorCode;
    message: string;
    /** Position in SQL string if applicable */
    position?: number;
}
/**
 * Validation warning (non-blocking)
 */
export interface ValidationWarning {
    code: ValidationWarningCode;
    message: string;
}
/**
 * Error codes for validation failures
 */
export declare enum ValidationErrorCode {
    EMPTY_QUERY = "EMPTY_QUERY",
    NOT_SELECT = "NOT_SELECT",
    MULTIPLE_STATEMENTS = "MULTIPLE_STATEMENTS",
    FORBIDDEN_PATTERN = "FORBIDDEN_PATTERN",
    UNKNOWN_TABLE = "UNKNOWN_TABLE",
    SYNTAX_ERROR = "SYNTAX_ERROR",
    COMPLEXITY_EXCEEDED = "COMPLEXITY_EXCEEDED",
    INJECTION_ATTEMPT = "INJECTION_ATTEMPT"
}
/**
 * Warning codes for non-blocking issues
 */
export declare enum ValidationWarningCode {
    MISSING_LIMIT = "MISSING_LIMIT",
    LARGE_LIMIT = "LARGE_LIMIT",
    MULTIPLE_JOINS = "MULTIPLE_JOINS",
    FULL_TABLE_SCAN = "FULL_TABLE_SCAN",
    CARTESIAN_PRODUCT = "CARTESIAN_PRODUCT"
}
/**
 * Extracted query metadata
 */
export interface QueryMetadata {
    /** Tables referenced in query */
    tables: string[];
    /** Number of JOIN operations */
    joinCount: number;
    /** Whether query has LIMIT clause */
    hasLimit: boolean;
    /** LIMIT value if present */
    limitValue?: number;
    /** Whether query has WHERE clause */
    hasWhere: boolean;
    /** Estimated complexity score */
    complexityScore: number;
}
/**
 * SQL safety validator for agent-generated queries.
 */
export declare class SQLValidator {
    private defaultConstraints;
    constructor(constraints?: Partial<SQLConstraints>);
    /**
     * Validate an SQL query against constraints.
     *
     * @param sql - The SQL query to validate
     * @param constraints - Override constraints (optional)
     * @returns Validation result with errors/warnings
     */
    validate(sql: string, constraints?: Partial<SQLConstraints>): ValidationResult;
    /**
     * Layer 1: Basic validation.
     */
    private validateBasic;
    /**
     * Layer 2: Statement type validation.
     */
    private validateStatementType;
    /**
     * Layer 3: Forbidden pattern validation.
     */
    private validateForbiddenPatterns;
    /**
     * Layer 4: Table whitelist validation.
     */
    private validateTables;
    /**
     * Layer 5: Complexity validation.
     */
    private validateComplexity;
    /**
     * Extract metadata from SQL query.
     */
    private extractMetadata;
    /**
     * Extract table names from SQL query.
     * This is a simplified parser - not 100% accurate but good enough for validation.
     */
    private extractTableNames;
    /**
     * Strip SQL comments from query.
     */
    private stripComments;
    /**
     * Add SQL query with automatic LIMIT if missing.
     */
    ensureLimit(sql: string, maxRows: number): string;
}
/**
 * Create an SQL validator instance.
 */
export declare function createSQLValidator(constraints?: Partial<SQLConstraints>): SQLValidator;
export default SQLValidator;
//# sourceMappingURL=sqlValidator.d.ts.map