/** * Generic Entity Service * * Provides generic CRUD operations for any entity by slug. * Unlike BaseEntityService (which is abstract and extended per-entity), * this service allows operations on any registered entity dynamically. * * Used by Server Actions to perform entity operations without * needing entity-specific service classes. * * @example * ```typescript * // Create a school record * const school = await GenericEntityService.create('schools', userId, teamId, { * name: 'MIT', * status: 'active' * }) * * // List campaigns with filtering * const result = await GenericEntityService.list('campaigns', userId, { * where: { status: 'active' }, * limit: 20 * }) * ``` */ import type { EntityConfig } from '../entities/types'; export interface GenericListOptions { limit?: number; offset?: number; orderBy?: string; orderDir?: 'asc' | 'desc'; where?: Record; search?: string; teamId?: string; } export interface GenericListResult { data: T[]; total: number; limit: number; offset: number; } export interface ValidationResult { valid: boolean; errors: string[]; } /** * Validate entity data against the entity configuration schema * * Validates field types, required fields, and selection options. * Can be used to pre-validate data before calling create/update actions. * * @param entityConfig - Entity configuration with field definitions * @param data - Data to validate * @param isUpdate - If true, required fields are not enforced (partial update) * @returns Validation result with { valid: boolean, errors: string[] } * * @example * ```typescript * import { entityRegistry } from '@nextsparkjs/core/entities' * import { validateEntityData } from '@nextsparkjs/core/services' * * const config = entityRegistry.get('schools') * const result = validateEntityData(config, formData, false) * * if (!result.valid) { * console.error('Validation errors:', result.errors) * } * ``` */ export declare function validateEntityData(entityConfig: EntityConfig, data: Record, isUpdate?: boolean): ValidationResult; export declare class GenericEntityService { /** * Get entity by ID * * @param entitySlug - The entity type slug (e.g., 'campaigns', 'schools') * @param id - Entity ID * @param userId - Current user ID for RLS * @param teamId - Team ID for team isolation (prevents cross-team access) * @returns Entity or null if not found */ static getById(entitySlug: string, id: string, userId: string, teamId?: string): Promise; /** * List entities with pagination, filtering, and search * * @param entitySlug - The entity type slug * @param userId - Current user ID for RLS * @param options - List options (limit, offset, where, search, orderBy) * @returns Paginated result with data and total count */ static list(entitySlug: string, userId: string, options?: GenericListOptions): Promise>; /** * Create a new entity * * @param entitySlug - The entity type slug * @param userId - Current user ID for RLS and ownership * @param teamId - Team ID for team isolation * @param data - Entity data * @returns Created entity */ static create(entitySlug: string, userId: string, teamId: string, data: Record): Promise; /** * Update an existing entity * * @param entitySlug - The entity type slug * @param id - Entity ID * @param userId - Current user ID for RLS * @param data - Fields to update * @param teamId - Team ID for team isolation (prevents cross-team access) * @returns Updated entity */ static update(entitySlug: string, id: string, userId: string, data: Record, teamId?: string): Promise; /** * Delete an entity * * @param entitySlug - The entity type slug * @param id - Entity ID * @param userId - Current user ID for RLS * @param teamId - Team ID for team isolation (prevents cross-team access) * @returns true if deleted, false if not found */ static delete(entitySlug: string, id: string, userId: string, teamId?: string): Promise; /** * Check if an entity exists * * @param entitySlug - The entity type slug * @param id - Entity ID * @param userId - Current user ID for RLS * @param teamId - Team ID for team isolation (prevents cross-team access) * @returns true if exists and accessible */ static exists(entitySlug: string, id: string, userId: string, teamId?: string): Promise; /** * Count entities with optional filtering * * @param entitySlug - The entity type slug * @param userId - Current user ID for RLS * @param where - Filter conditions * @returns Count of matching entities */ static count(entitySlug: string, userId: string, where?: Record): Promise; /** * Delete multiple entities in a single query (batch operation) * * More efficient than calling delete() in a loop. * * @param entitySlug - The entity type slug * @param ids - Array of entity IDs to delete * @param userId - Current user ID for RLS * @param options - Optional configuration * @param options.executeHooks - If true, executes hooks for each entity (less efficient). Default: false * @param options.teamId - Team ID for team isolation (prevents cross-team access) * @returns Number of entities deleted * * @note When executeHooks is false (default), uses a single atomic DELETE query. * When executeHooks is true, deletes are performed sequentially and are NOT transactional. * If one delete fails mid-batch, previous deletes remain committed. */ static deleteMany(entitySlug: string, ids: string[], userId: string, options?: { executeHooks?: boolean; teamId?: string; }): Promise; } //# sourceMappingURL=generic-entity.service.d.ts.map