import { QueryBuilder } from 'typeorm'; import { QueryHookPlugin } from '../index'; /** * Extended query type (includes DDL, transactions, etc.) * This is separate from TypeORM's limited queryType */ export type ExtendedQueryType = 'SELECT' | 'INSERT' | 'UPDATE' | 'DELETE' | 'CREATE' | 'ALTER' | 'DROP' | 'TRUNCATE' | 'BEGIN' | 'COMMIT' | 'ROLLBACK' | 'WITH' | 'OTHER'; /** * Metadata associated with a query */ export interface QueryMetadata { tables: string[]; timestamp: Date; queryType?: 'SELECT' | 'INSERT' | 'UPDATE' | 'DELETE'; queryTypeExtended?: ExtendedQueryType; builder?: QueryBuilder; } /** * Registry that maps SQL strings to their metadata * This allows Logger implementations to look up table information from raw SQL */ declare class QueryMetadataRegistry { private registry; private maxSize; private cleanupThreshold; /** * Normalize SQL for consistent lookup * Removes extra whitespace and normalizes case */ private normalizeSQL; /** * Register metadata for a SQL query */ register(sql: string, metadata: QueryMetadata): void; /** * Retrieve metadata for a SQL query */ get(sql: string): QueryMetadata | undefined; /** * Get tables from SQL query * Returns empty array if not found */ getTables(sql: string): string[]; /** * Get query type from SQL query */ getQueryType(sql: string): string | undefined; /** * Check if metadata exists for a query */ has(sql: string): boolean; /** * Remove old entries to prevent memory leaks */ private cleanup; /** * Clear all entries */ clear(): void; /** * Get registry size */ size(): number; } /** * Global singleton instance */ export declare const queryMetadataRegistry: QueryMetadataRegistry; /** * Plugin that automatically registers query metadata in the global registry * This allows TypeORM Logger implementations to look up table information */ export declare const QueryMetadataRegistryPlugin: QueryHookPlugin; /** * Utility function to get tables from SQL (for use in Logger) * Falls back to empty array if not found in registry */ export declare function getTablesFromSQL(sql: string): string[]; /** * Format table names as a comma-separated string with spaces * @param tables - Array of table names * @returns Formatted string like "users, posts, comments" or empty string if no tables * * @example * ```typescript * const tables = getTablesFromSQL(sql); * const formatted = formatTableNames(tables); // "users, posts" * ``` */ export declare function formatTableNames(tables: string[]): string; /** * Utility function to get query type from SQL (for use in Logger) * This returns TypeORM's basic query type (SELECT/INSERT/UPDATE/DELETE) */ export declare function getQueryTypeFromSQL(sql: string): string | undefined; /** * Utility function to get extended query type from SQL (for use in Logger) * This includes DDL, transactions, and other types beyond basic CRUD * * @example * ```typescript * import { getExtendedQueryTypeFromSQL } from 'typeorm-query-hooks'; * * // In your logger * const queryType = getExtendedQueryTypeFromSQL(sql); * console.log(queryType); // "SELECT", "CREATE", "BEGIN", etc. * ``` */ export declare function getExtendedQueryTypeFromSQL(sql: string): ExtendedQueryType | undefined; /** * Check if query metadata is available */ export declare function hasQueryMetadata(sql: string): boolean; export {}; //# sourceMappingURL=query-metadata-registry.d.ts.map