/** * Memory Feature Flag Provider * * In-memory provider implementation that uses the FEATURES constant for flag data. * This will be moved to @plyaz/core when the package structure is finalized. * * @fileoverview Memory provider implementation for feature flags * @version 1.0.0 */ import type { FeatureFlag, FeatureFlagRule, FeatureFlagConfig, FeatureFlagValue, CreateFlagRequest } from '@plyaz/types'; import { FeatureFlagProvider } from '../provider'; /** * Memory-based feature flag provider that loads flags from the FEATURES constant. * * @class MemoryFeatureFlagProvider * @extends {FeatureFlagProvider} * * @example * ```typescript * const provider = new MemoryFeatureFlagProvider({ * provider: 'memory', * isCacheEnabled: false, * isLoggingEnabled: true, * }, FEATURES); * * await provider.initialize(); * const isEnabled = await provider.isEnabled('AUTH_GOOGLE'); * ``` */ export declare class MemoryFeatureFlagProvider extends FeatureFlagProvider { private flags; private rules; /** * Creates a new memory feature flag provider. * * @param config - Provider configuration * @param features - Record of feature flag keys to their default values */ constructor(config: FeatureFlagConfig, features: Record); /** * Fetches flags and rules from memory (FEATURES constant). * * @protected * @returns Promise resolving to flags and rules from memory */ protected fetchData(): Promise<{ flags: FeatureFlag[]; rules: FeatureFlagRule[]; }>; /** * Creates a FeatureFlag object from a FEATURES constant entry. * * @private * @param key - The feature flag key * @param value - The value from FEATURES constant * @param currentTime - Current timestamp * @returns FeatureFlag object */ private createFeatureFlagFromConstant; /** * Generates a human-readable name from a flag key. * * @private * @param key - The feature flag key * @returns Human-readable flag name */ private generateFlagName; /** * Infers the flag type from its value. * * @private * @param value - The flag value * @returns The inferred type */ private inferFlagType; /** * Gets manually added rules for memory provider. * * @private * @returns Array of manually configured rules */ private getManualRules; /** * Validates the memory provider configuration. * * @private * @throws Error if configuration is invalid */ private validateConfig; /** * Adds a rule to the memory provider at runtime. * * @param rule - The rule to add */ addRule(rule: FeatureFlagRule): void; /** * Removes a rule from the memory provider. * * @param ruleId - The ID of the rule to remove */ removeRule(ruleId: string): void; /** * Creates a new feature flag in memory. * * @param data - Flag creation data * @returns The created feature flag */ createFlag(data: CreateFlagRequest): Promise>; /** * Updates an existing feature flag in memory. * * @param key - Flag key to update * @param data - Partial flag data to update * @returns The updated feature flag */ updateFlag(key: FeatureFlagKey, data: Partial>): Promise>; /** * Deletes a feature flag from memory. * * @param key - Flag key to delete */ deleteFlag(key: FeatureFlagKey): Promise; /** * Gets all rules for a specific flag. * * @param key - Flag key to get rules for * @returns Array of rules for the flag */ getRules(key: FeatureFlagKey): Promise[]>; /** * Gets all enabled rules. * * @returns Array of all enabled rules */ getAllRules(): Promise[]>; /** * Adds a new flag to memory at runtime. * * @param key - The flag key * @param value - The flag value * @param props - Optional flag properties */ addFlag(key: FeatureFlagKey, value: FeatureFlagValue, props?: Partial, 'name' | 'description' | 'isEnabled' | 'environment' | 'rolloutPercentage' | 'type'>>): void; /** * Checks if a flag with the given key exists. */ private flagExists; /** * Creates a new flag object. */ private createNewFlag; /** * Gets default properties for a new flag. */ private getDefaultFlagProperties; /** * Merges default properties with user-provided properties. */ private mergeWithUserProps; /** * Adds the flag to the store and notifies systems. */ private addFlagToStore; /** * Removes a flag from memory. * * @param key - The flag key to remove */ removeFlag(key: FeatureFlagKey): void; /** * Gets all current flags in memory. * * @returns Array of current flags */ getCurrentFlags(): FeatureFlag[]; /** * Gets all current rules in memory. * * @returns Array of current rules */ getCurrentRules(): FeatureFlagRule[]; /** * Updates the features object and syncs all flags. * This allows updating the FEATURES constant at runtime. * * @param newFeatures - New features object to sync with */ syncFeatures(newFeatures: Record): Promise; /** * Resets the memory provider to its initial state. */ reset(): Promise; /** * Gets statistics about the memory provider. * * @returns Provider statistics */ getStats(): { flagCount: number; ruleCount: number; cacheSize: number; subscriberCount: number; isInitialized: boolean; }; /** * Logs messages with MemoryFeatureFlagProvider prefix. * * @param args - Arguments to log */ protected log(...args: unknown[]): void; } //# sourceMappingURL=memory.d.ts.map