/** * Database Repository Implementation * * Database adapter integration with @plyaz/db for feature flag storage. * Extends BaseRepository for consistent CRUD operations and QueryBuilder support. * * @fileoverview Database repository for feature flags */ import { BaseRepository } from '@plyaz/db'; import { type FeatureFlag, type FeatureFlagRule, type FeatureFlagValue, type CreateFlagRequest, type FeatureFlagContext } from '@plyaz/types'; import type { FeatureFlagKey } from '@domain/types'; import { type CoreDatabaseFeatureFlagRow, type CoreFeatureFlagTableConfig } from '@plyaz/types/core'; import type { DatabaseServiceInterface } from '@plyaz/types/db'; /** * Extended row type with index signature for BaseRepository compatibility */ type FeatureFlagRow = CoreDatabaseFeatureFlagRow & Record; /** * Database Repository for Feature Flags * * Extends BaseRepository for consistent CRUD operations and QueryBuilder support. * Manages feature flags, rules, evaluations, and overrides across multiple tables. * * @template TKey - Feature flag key type (extends string) * * @example * ```typescript * // Create repository * const repository = FeatureFlagDatabaseRepository.create(); * * // Use QueryBuilder for complex queries * const enabledFlags = await repository.query() * .where('is_enabled', 'eq', true) * .orderByAsc('key') * .getMany(); * * // Get all flags with environment filter * const prodFlags = await repository.getAllFlags('production'); * ``` */ export declare class FeatureFlagDatabaseRepository extends BaseRepository { private readonly tableConfig; private readonly logger; /** * Creates a new repository with optional custom table names. * * @param db - Database service interface * @param tableConfig - Optional custom table configuration */ constructor(db: DatabaseServiceInterface, tableConfig?: Partial); /** * Factory method to create repository instance. * Uses DbService singleton if initialized. */ static create(tableConfig?: Partial): FeatureFlagDatabaseRepository; /** * Gets the current table configuration. */ getTableConfig(): CoreFeatureFlagTableConfig; /** * Gets the full table name including schema if needed. */ private getEvaluationsTableName; /** * Retrieves all feature flags with optional environment filtering. * Uses QueryBuilder fluent API for the query. * * @param environment - Optional environment filter * @returns Array of feature flags */ getAllFlags(environment?: string): Promise[]>; /** * Retrieves a specific feature flag by its key. * Uses findById with 'key' as the ID column. * * @param key - The feature flag key * @returns The feature flag or null */ getFlag(key: TKey): Promise | null>; /** * Find flags by enabled status using QueryBuilder. * * @param isEnabled - Filter by enabled status * @returns Array of matching flags */ findByEnabled(isEnabled: boolean): Promise[]>; /** * Count flags by enabled status using QueryBuilder. */ countByEnabled(isEnabled: boolean): Promise; /** * Creates a new feature flag. * * @param data - Flag creation data * @returns The created flag */ createFlag(data: CreateFlagRequest): Promise>; /** * Updates an existing feature flag. * * @param key - Flag key to update * @param data - Partial update data * @returns The updated flag */ updateFlag(key: TKey, data: Partial>): Promise>; /** * Deletes a feature flag. * * @param key - Flag key to delete */ deleteFlag(key: TKey): Promise; /** * Retrieves rules for a specific flag using direct db query. * Rules are in a separate table, so we use the underlying db service. * * @param key - Flag key to get rules for * @returns Array of rules */ getFlagRules(key: TKey): Promise[]>; /** * Retrieves all enabled rules across all flags. * * @returns Array of all enabled rules */ getAllRules(): Promise[]>; /** * Logs a feature flag evaluation for audit purposes. */ logEvaluation(params: { flagKey: TKey; userId?: string; context?: FeatureFlagContext; result: FeatureFlagValue; }): Promise; /** * Sets a user-specific override for a feature flag. */ setOverride(flagKey: TKey, userId: string, value: FeatureFlagValue, expiresAt?: Date): Promise; /** * Retrieves a user-specific override for a feature flag. */ getOverride(flagKey: TKey, userId: string): Promise; /** * Removes user-specific overrides for a feature flag. */ removeOverride(flagKey: TKey, userId: string): Promise; /** * Infers the type of a value for the type field. */ private toTypeField; /** * Maps a database row to a FeatureFlag object. */ private mapToFeatureFlag; /** * Maps a database row to a FeatureFlagRule object. */ private mapToFeatureFlagRule; } export {}; //# sourceMappingURL=FeatureFlagRepository.d.ts.map