import { QueryBuilder } from 'typeorm'; import { QueryHookPlugin, QueryHookContext } from '../index'; /** * Extract table names from raw SQL string * Handles SELECT, INSERT, UPDATE, DELETE, CREATE, ALTER, DROP, TRUNCATE * @param sql - Raw SQL string * @returns Array of table names found in the SQL */ export declare function extractTablesFromSQL(sql: string): string[]; /** * Recursively extract table names from a QueryBuilder's internal expressionMap * @param builder - The QueryBuilder instance * @returns Array of table names involved in the query */ export declare function extractTablesFromBuilder(builder: QueryBuilder): string[]; /** * Type augmentation to add getInvolvedTables() method to all QueryBuilder types */ declare module 'typeorm' { interface SelectQueryBuilder { /** * Get list of table names involved in this query * @returns Array of table names */ getInvolvedTables(): string[]; } interface InsertQueryBuilder { /** * Get list of table names involved in this query * @returns Array of table names */ getInvolvedTables(): string[]; } interface UpdateQueryBuilder { /** * Get list of table names involved in this query * @returns Array of table names */ getInvolvedTables(): string[]; } interface DeleteQueryBuilder { /** * Get list of table names involved in this query * @returns Array of table names */ getInvolvedTables(): string[]; } } /** * Callback type for table extraction events */ export type TableExtractorCallback = (tables: string[], builder: QueryBuilder, sql: string) => void; /** * Register a listener to be called whenever tables are extracted from a query * @param callback - Function to call with extracted tables */ export declare function onTablesExtracted(callback: TableExtractorCallback): void; /** * Remove a registered listener * @param callback - The callback to remove */ export declare function offTablesExtracted(callback: TableExtractorCallback): boolean; /** * Options for TableExtractorPlugin */ export interface TableExtractorOptions { /** * Show warning when no tables are extracted from a query (default: false) * When true, warns about queries that don't have extractable table metadata * * @deprecated Use onEmptyTables callback instead for custom handling */ warnOnEmptyTables?: boolean; /** * Enable console logging for this plugin (default: false) * When true, the plugin will log extracted table names to console */ enableLogging?: boolean; /** * Callback when tables are extracted from a query (optional) * * @param tables - Array of extracted table names * @param context - Query context * * @example * ```typescript * onTablesExtracted: (tables, context) => { * logger.info(`Query involves tables: ${tables.join(', ')}`); * } * ``` */ onTablesExtracted?: (tables: string[], context: QueryHookContext) => void; /** * Callback when no tables are extracted from a query (optional) * Use this instead of warnOnEmptyTables for custom warning handling * * @param context - Query context * * @example * ```typescript * onEmptyTables: (context) => { * logger.warn('No tables extracted', { * sql: context.sql, * queryType: context.queryType * }); * } * ``` */ onEmptyTables?: (context: QueryHookContext) => void; /** * Callback when a warning occurs during table extraction (optional) * * @param message - Warning message * @param context - Query context * * @example * ```typescript * onWarning: (message, context) => { * logger.warn(`[TableExtractor] ${message}`); * } * ``` */ onWarning?: (message: string, context: QueryHookContext) => void; /** * Callback when an error occurs during table extraction (optional) * * @param error - The error that occurred * @param context - Query context * * @example * ```typescript * onError: (error, context) => { * logger.error('Table extraction failed', { error, sql: context.sql }); * } * ``` */ onError?: (error: Error, context: QueryHookContext) => void; } /** * Table Extractor Plugin * Adds the ability to extract table names from QueryBuilder instances * * @example * ```typescript * import { registerPlugin } from 'typeorm-query-hooks'; * import { createTableExtractorPlugin } from 'typeorm-query-hooks/plugins/table-extractor'; * * registerPlugin(createTableExtractorPlugin({ * warnOnEmptyTables: true, // warn when no tables found (default: false) * enableLogging: false // log to console (default: false) * })); * ``` */ export declare function createTableExtractorPlugin(options?: TableExtractorOptions): QueryHookPlugin; /** * Default Table Extractor Plugin (for backward compatibility) * Uses default options: warnOnEmptyTables = true, enableLogging = false */ export declare const TableExtractorPlugin: QueryHookPlugin; //# sourceMappingURL=table-extractor.d.ts.map