import DBConnection from './DBConnection.js'; import PaginationList from "./PaginationList.js"; import { Logger } from "../Logger.js"; export default abstract class CommonSearchCriteria { protected readonly logger: Logger; protected sql: string; protected orderBy: string; protected params: Array; private readonly page; private readonly pageSize; protected criteria: any; protected booleanFields?: Array; protected constructor(criteria?: any); /** * Sets fields to be coerced into boolean values. * @param fields - Array of field property paths (supports nested paths like 'user.isActive'). */ protected setBooleanFields(...fields: Array): void; /** * Builds dynamic SQL query criteria. Subclasses should override this method. * @protected * @abstract */ protected abstract buildDynamicQuery(): any; /** * Queries the count of matching records. * @param conn - Database connection object. * @param sql - SQL query string. * @param params - Array of SQL query parameters. * @private * @returns Promise resolving to the total count. */ private queryCount; /** * Post-construction row processor function invoked after mapping database rows to target objects. * Subclasses can override this method. * @protected * @returns Post-processor function or null. */ protected getPostProcessor(): ((obj: any) => void) | null; /** * Checks if a value is not empty. * @param s - Value to check. * @protected * @returns True if not empty. */ protected isNotEmpty(s: any): boolean; /** * Escapes percentage (%) characters in a string. * @param s - String to escape. * @protected * @returns Escaped string. */ protected escapePercentage(s: string): string; /** * Checks if a string contains wildcard asterisk (*). * @param s - String to check. * @protected * @returns True if string contains *. */ protected includeStar(s: string): boolean; /** * Replaces asterisk (*) wildcards with SQL percentage (%) wildcards. * @param s - Input string. * @protected * @returns Converted SQL wildcard string. */ protected toWildSQL(s: string): string; /** * Escapes existing percentage (%) characters and replaces wildcard asterisks (*) with %. * @param s - Input string to process. * @protected * @returns Processed string. */ protected replaceWildStar(s: string): string; /** * Calculates the start of the following day (00:00:00.000) for exclusive upper-bound date queries (< nextDayStart). * @param d - Input date or date string. * @protected * @returns Next day start Date or null if invalid. */ protected getNextDayStart(d: any): Date | null; /** * Adds range query criteria (from / to boundaries). * Automatically applies getNextDayStart to toValue if it is a Date instance. * @param fromValue - Start boundary value (inclusive >=). * @param toValue - End boundary value (exclusive <). * @param field - Database column name. * @protected * @returns Next parameter positional index. */ protected addRangeCriteria(fromValue: any, toValue: any, field: string): number; /** * Adds wildcard/LIKE query criteria (uses LIKE if * is present, otherwise equals =). * @param text - Search text. * @param field - Field name. * @protected * @returns Next parameter positional index. */ protected addWildcardCriteria(text: string, field: string): number; /** * Adds equality query criteria (field = value). * @param value - Search value. * @param field - Field name. * @protected * @returns Next parameter positional index. */ protected addEqualsCriteria(value: any, field: string): number; /** * Wraps a search string with % wildcards for LIKE matching (%string%). * @param s - Input string. * @protected * @returns Wrapped string (%string%). */ protected wrapLikeMatch(s: string): string; /** * Executes a paginated query and returns a PaginationList result. * @param conn - Database connection object. */ paginationQuery(conn: DBConnection): Promise; /** * Executes an unpaginated query, returning all matching records. * Applies getPostProcessor() post-processing callback consistently. * @param conn - Database connection object. * @returns Promise resolving to an array of result objects. */ query(conn: DBConnection): Promise>; }