import { QueryHookPlugin, QueryHookContext } from '../index'; /** * Query complexity metrics */ export interface QueryComplexityMetrics { joinCount: number; tableCount: number; hasSubquery: boolean; hasCTE: boolean; estimatedComplexity: 'low' | 'medium' | 'high'; warnings: string[]; } /** * Options for QueryComplexityPlugin */ export interface QueryComplexityOptions { /** * Maximum number of joins before warning (default: 5) * Queries with more joins will trigger a complexity warning */ maxJoins?: number; /** * Maximum number of tables before warning (default: 10) * Queries involving more tables will trigger a complexity warning */ maxTables?: number; /** * Warn on subqueries (default: false) * When true, warns whenever a subquery is detected */ warnOnSubqueries?: boolean; /** * Warn on CTEs (Common Table Expressions) (default: false) * When true, warns whenever a WITH clause is detected */ warnOnCTEs?: boolean; /** * Callback when complex query is detected (optional) * * @param metrics - Complexity metrics for the query * @param context - Full query context * * @example * ```typescript * onComplexQuery: (metrics, context) => { * if (metrics.estimatedComplexity === 'high') { * logger.warn('Complex query detected', { * joins: metrics.joinCount, * tables: metrics.tableCount, * warnings: metrics.warnings * }); * } * } * ``` */ onComplexQuery?: (metrics: QueryComplexityMetrics, context: QueryHookContext) => void; /** * Enable console logging for this plugin (default: false) * When true, logs complexity warnings to console */ enableLogging?: boolean; } /** * Plugin for detecting and warning about complex queries * Helps identify queries that might have performance issues * * 🟢 Priority: LOW - Nice to have for optimization * * @example * ```typescript * import { enableQueryHooks, registerPlugin } from 'typeorm-query-hooks'; * import { QueryComplexityPlugin } from 'typeorm-query-hooks/plugins/query-complexity'; * * enableQueryHooks(); * * // Basic usage: Warn on complex queries * registerPlugin(QueryComplexityPlugin({ * maxJoins: 5, * maxTables: 10, * warnOnSubqueries: true, * enableLogging: true * })); * * // Advanced: Custom complexity handling * registerPlugin(QueryComplexityPlugin({ * maxJoins: 3, * maxTables: 5, * warnOnSubqueries: true, * warnOnCTEs: true, * enableLogging: true, * onComplexQuery: (metrics, context) => { * if (metrics.estimatedComplexity === 'high') { * // Send to performance monitoring * datadog.increment('complex_queries', { * joins: metrics.joinCount, * tables: metrics.tableCount * }); * * // Log for review * logger.warn('Complex query needs optimization', { * sql: context.sql.substring(0, 200), * metrics, * suggestion: 'Consider adding indexes or breaking into smaller queries' * }); * } * } * })); * ``` */ export declare function QueryComplexityPlugin(options?: QueryComplexityOptions): QueryHookPlugin; //# sourceMappingURL=query-complexity.d.ts.map