import { QueryTable, WhereClause, OrderByClause, ImportResult, ColumnMapping, ImportOptions, ServiceStatus, HealthCheckResult } from "@/types"; import { UniversalDAO } from "./universal-dao"; export interface FindOptions { where?: WhereClause[]; orderBy?: OrderByClause[]; limit?: number; offset?: number; columns?: string[]; } export type ErrorHandler = (error: Error) => void; export type EventHandler = (data: any) => void; /** * Universal BaseService - An enhanced abstract base class designed to provide * comprehensive CRUD operations and database management features across all * operating systems and frameworks using TypeScript and JavaScript. */ export declare abstract class BaseService { protected dao: UniversalDAO | null; protected schemaName: string; protected tableName: string; protected isOpened: boolean; protected isInitialized: boolean; protected errorHandlers: Map; protected eventListeners: Map; protected primaryKeyFields: string[]; private cache; private reconnectHandler; constructor(schemaName: string, tableName?: string); private bindMethods; /** * Set primary key fields for the service */ setPrimaryKeyFields(fields: string[]): this; /** * Initialize the service and establish database connection */ init(): Promise; /** * Upsert a record - Insert if not exists, update if exists * @param data - Data to insert or update * @param searchFields - Fields to check for existence (defaults to primary key) * @returns The created or updated record */ upsert(data: Partial, searchFields?: string[]): Promise; /** * Create a new record - Safe version với comprehensive error handling */ create(data: Partial): Promise; /** * Update an existing record */ update(id: any, data: Partial): Promise; /** * Delete a record by ID */ delete(id: any): Promise; /** * Find a record by ID */ findById(id: any): Promise; /** * Find the first record matching conditions */ findFirst(conditions?: Record): Promise; /** * Find all records matching conditions */ findAll(conditions?: Record, options?: FindOptions): Promise; /** * Count records matching conditions */ count(where?: WhereClause[] | Record): Promise; /** * Check if a record exists by ID */ exists(id: any): Promise; /** * Truncate table (delete all records and reset auto-increment) */ truncate(): Promise; /** * Bulk upsert records - Insert if not exists, update if exists for multiple records * @param dataArray - Array of data to insert or update * @param searchFields - Fields to check for existence (defaults to primary key) * @param useTransaction - Whether to wrap in transaction (default: true) * @returns Result with created and updated records */ bulkUpsert(dataArray: Partial[], searchFields?: string[], useTransaction?: boolean): Promise<{ created: T[]; updated: T[]; total: number; errors: Array<{ index: number; data: Partial; error: string; }>; }>; /** * Bulk insert records */ bulkInsert(items: Partial[]): Promise; /** * Bulk create records with transaction support */ bulkCreate(dataArray: Record[]): Promise; /** * Execute operations within a transaction */ executeTransaction(callback: () => Promise): Promise; /** * Import data from CSV */ importFromCSV(csvData: string, options?: { delimiter?: string; hasHeader?: boolean; columnMappings?: ColumnMapping[]; } & Partial): Promise; /** * Import data with column mapping */ importDataWithMapping(data: Record[], columnMappings: ColumnMapping[], options?: Partial): Promise; protected buildSelectTable(conditions?: Record, options?: FindOptions): QueryTable; protected buildDataTable(data: Record): QueryTable; protected buildWhereFromObject(obj: Record): WhereClause[]; on(event: string, handler: EventHandler): this; off(event: string, handler: EventHandler): this; protected _emit(event: string, data: any): void; setErrorHandler(errorType: string, handler: ErrorHandler): this; protected _handleError(errorType: string, error: Error): void; protected _validateData(data: any): void; protected _ensureInitialized(): Promise; private ensureValidConnection; getDatabaseInfo(): Promise; getTableInfo(): Promise; getStatus(): ServiceStatus; healthCheck(): Promise; close(): Promise; destroy(): void; getAll(conditions?: Record, options?: FindOptions): Promise; getById(id: string | number): Promise; getFirst(conditions?: Record): Promise; } //# sourceMappingURL=base-service.d.ts.map