import type { IAdapter, IGate, IType } from '@flippercloud/flipper'; import type { Feature as FeatureClass, Export, Dsl } from '@flippercloud/flipper'; import type { ModelStatic } from 'sequelize'; import type { FlipperFeatureModel, FlipperGateModel } from './Models.js'; /** * Options for initializing the SequelizeAdapter. */ export interface SequelizeAdapterOptions { /** * The Flipper Feature model instance */ Feature: ModelStatic; /** * The Flipper Gate model instance */ Gate: ModelStatic; /** * Whether the adapter is read-only (default: false) */ readOnly?: boolean; /** * Force all read queries to use the primary database connection in a * replicated setup (default: false). This passes `useMaster: true` to * Sequelize find calls so they bypass replicas. Helpful when you have * just written feature changes and need read-after-write consistency. */ useMaster?: boolean; } /** * Sequelize adapter for storing Flipper feature flags in a database. * * Supports any database backend that Sequelize supports (MySQL, PostgreSQL, SQLite, etc.). * * @example * import { Sequelize } from 'sequelize' * import Flipper from '@flippercloud/flipper' * import { SequelizeAdapter, createFlipperModels } from '@flippercloud/flipper-sequelize' * * const sequelize = new Sequelize('mysql://user:pass@localhost/db') * const { Feature, Gate } = createFlipperModels(sequelize) * * const adapter = new SequelizeAdapter({ Feature, Gate }) * const flipper = new Flipper(adapter) * * // Use flipper * await flipper.enable('new-feature') */ declare class SequelizeAdapter implements IAdapter { /** * The name of this adapter. */ name: string; /** * The Feature model */ private Feature; /** * The Gate model */ private Gate; /** * Whether the adapter is read-only */ private _readOnly; /** * Whether read queries should be forced to the primary (master) connection. */ private _useMaster; constructor(options: SequelizeAdapterOptions); /** * Get all features. * @returns Array of all Feature instances */ features(): Promise; /** * Add a new feature. * @param feature - Feature to add * @returns True if successful */ add(feature: FeatureClass): Promise; /** * Remove a feature. * @param feature - Feature to remove * @returns True if successful */ remove(feature: FeatureClass): Promise; /** * Get feature state from the database. * @param feature - Feature to get state for * @returns Object with gate keys and their values */ get(feature: FeatureClass): Promise>; /** * Get multiple features' state from the database. * @param features - Features to get state for * @returns Map of feature keys to gate values */ getMulti(features: FeatureClass[]): Promise>>; /** * Get all features' state from the database. * @returns Map of all feature keys to gate values */ getAll(): Promise>>; /** * Enable a gate for a feature. * @param feature - Feature to enable gate for * @param gate - Gate to enable * @param thing - Value to enable for the gate * @returns True if successful */ enable(feature: FeatureClass, gate: IGate, thing: IType): Promise; /** * Disable a gate for a feature. * @param feature - Feature to disable gate for * @param gate - Gate to disable * @param thing - Value to disable for the gate * @returns True if successful */ disable(feature: FeatureClass, gate: IGate, thing: IType): Promise; /** * Clear all gate values for a feature. * @param feature - Feature to clear * @returns True if successful */ clear(feature: FeatureClass): Promise; /** * Check if the adapter is read-only. * @returns True if read-only, false otherwise */ readOnly(): boolean; /** * Export the adapter's features. * @param options - Export options * @returns Export object */ export(options?: { format?: string; version?: number; }): Promise; /** * Import features from another source. * * This is a destructive operation - it will replace all local features * with the features from the source. * * @param source - The source to import from (Dsl, Adapter, or Export) * @returns True if successful */ import(source: IAdapter | Export | Dsl): Promise; /** * Extract an adapter from a source. * @private * @param source - The source to extract from * @returns The adapter */ private getSourceAdapter; /** * Add a value to a set gate. * Mirrors ActiveRecord adapter behavior by writing one row per value. */ private enableMulti; /** * Create or replace a single gate value. */ private set; /** * Delete all rows for a specific gate. */ private deleteGate; /** * Remove single value from set gate. */ private deleteSetValue; /** * Convert database rows to Flipper gate structure. */ private resultForGates; /** * Serialize a gate value based on its type. * @private * @param dataType - The gate data type * @param value - The value to serialize * @returns Serialized value as string */ private serializeGateValue; /** * Parse a gate value from storage. * @private * @param value - The serialized value * @returns Parsed value */ private parseGateValue; /** * Return the primary storage key for a gate, using snake_case for cross-language compatibility. * Ruby Flipper stores percentage gates as `percentage_of_actors`/`percentage_of_time`, so we * mirror that format while still accepting camelCase keys that may already exist in the DB. */ private storageKey; /** * Return all accepted storage keys for a gate (camelCase + snake_case) so we can read and clean * up data regardless of which client wrote it. */ private storageKeys; private toSnakeCase; } export default SequelizeAdapter; //# sourceMappingURL=SequelizeAdapter.d.ts.map