/** * Base Entity Service * * Provides standard CRUD operations for entities with RLS support. * Entities extend this class and get type-safe operations out of the box. * * @example * ```typescript * export class ProductsService extends BaseEntityService { * constructor() { * super({ * tableName: 'products', * fields: ['title', 'description', 'status'], * searchableFields: ['title'], * }) * } * * // Custom methods when needed * async getByStatus(userId: string, status: string): Promise { * return this.query(userId, { * where: { status }, * orderBy: 'createdAt', * orderDir: 'desc', * }) * } * } * ``` * * @module BaseEntityService */ export interface ListOptions { limit?: number; offset?: number; orderBy?: string; orderDir?: 'asc' | 'desc'; where?: Record; search?: string; } export interface ListResult { data: T[]; total: number; limit: number; offset: number; } export interface EntityServiceConfig { /** Database table name (snake_case, e.g., 'products' or 'blog_posts') */ tableName: string; /** Entity fields that can be selected/inserted/updated (excluding system fields) */ fields: string[]; /** Fields that support text search (optional) */ searchableFields?: string[]; /** Default order by field */ defaultOrderBy?: string; /** Default order direction */ defaultOrderDir?: 'asc' | 'desc'; /** Default page size */ defaultLimit?: number; } export declare abstract class BaseEntityService, TUpdate = Partial> { protected config: Required; constructor(config: EntityServiceConfig); /** * Get all selectable fields (entity fields + system fields) */ protected get selectFields(): string[]; /** * Build SELECT clause with proper quoting */ protected buildSelectClause(): string; /** * Quote a field name if needed */ protected quoteField(field: string): string; /** * Build WHERE clause from conditions */ protected buildWhereClause(where: Record, startIndex?: number): { clause: string; params: unknown[]; nextIndex: number; }; /** * Build search condition for text search */ protected buildSearchCondition(search: string, paramIndex: number): { condition: string; param: string; } | null; /** * Map database row to entity (override for custom mapping) */ protected mapRowToEntity(row: Record): TEntity; /** * Get entity by ID * * @param id - Entity ID * @param userId - Current user ID for RLS * @returns Entity or null if not found */ getById(id: string, userId: string): Promise; /** * List entities with pagination, filtering, and search * * @param userId - Current user ID for RLS * @param options - List options (limit, offset, where, search, orderBy) * @returns Paginated result with data and total count */ list(userId: string, options?: ListOptions): Promise>; /** * Query entities with custom conditions (simpler than list) * * @param userId - Current user ID for RLS * @param options - Query options * @returns Array of entities */ query(userId: string, options?: Omit): Promise; /** * Create a new entity * * @param userId - Current user ID for RLS and ownership * @param teamId - Team ID for team isolation * @param data - Entity data * @returns Created entity */ create(userId: string, teamId: string, data: TCreate): Promise; /** * Update an existing entity * * @param id - Entity ID * @param userId - Current user ID for RLS * @param data - Fields to update * @returns Updated entity */ update(id: string, userId: string, data: TUpdate): Promise; /** * Delete an entity * * @param id - Entity ID * @param userId - Current user ID for RLS * @returns true if deleted, false if not found */ delete(id: string, userId: string): Promise; /** * Check if an entity exists * * @param id - Entity ID * @param userId - Current user ID for RLS * @returns true if exists and accessible */ exists(id: string, userId: string): Promise; /** * Count entities with optional filtering * * @param userId - Current user ID for RLS * @param where - Filter conditions * @returns Count of matching entities */ count(userId: string, where?: Record): Promise; } //# sourceMappingURL=base-entity.service.d.ts.map