/** * Configuration Override System * * This module implements a VS Code-style configuration override pattern. * Instead of deeply nested route and device-specific settings, we use a nested * structure with context keys for overrides. * * ## Pattern * * Base configuration: * ``` * uilayout.regions.header.showLogo = true * ``` * * Override for specific route and device: * ``` * [route=/dashboard][device=mobile]: { * uilayout: { * regions: { * header: { * showLogo: false * } * } * } * } * ``` * * ## Benefits * * 1. **Flat Schema**: Configuration schema is defined once, not duplicated per route/device * 2. **Clear Inheritance**: Easy to see what's overridden and what uses defaults * 3. **Flexibility**: Can add new context dimensions (e.g., [user=admin], [theme=dark]) * 4. **Database Friendly**: Nested structure is natural for MongoDB * 5. **Type Safe**: TypeScript can enforce config keys * * ## Usage in MongoDB * * ```json * { * "uiSettings": { * "uilayout": { * "regions": { * "header": { * "showLogo": true * } * } * }, * "[route=/dashboard][device=mobile]": { * "uilayout": { * "regions": { * "header": { * "showLogo": false * } * } * } * } * } * } * ``` */ export interface OverrideContext { route?: string; device?: 'desktop' | 'mobile'; theme?: string; user?: string; [key: string]: string | undefined; } /** * Parse multiple bracket pattern into array of identifiers * Supports both single bracket [/route.mobile] and multiple bracket [/route][mobile] patterns * * @example * parseMultipleBracketIdentifiers("[/dashboard][mobile]") * // Returns: ['/dashboard', 'mobile'] * * parseMultipleBracketIdentifiers("[mobile]") * // Returns: ['mobile'] * * parseMultipleBracketIdentifiers("[/dashboard.mobile]") // Backward compatibility * // Returns: ['/dashboard', 'mobile'] */ export declare function parseMultipleBracketIdentifiers(overrideKey: string): string[]; /** * Build multiple bracket pattern from identifiers array * * @example * buildMultipleBracketKey(['/dashboard', 'mobile']) * // Returns: "[/dashboard][mobile]" * * buildMultipleBracketKey(['mobile']) * // Returns: "[mobile]" */ export declare function buildMultipleBracketKey(identifiers: string[]): string; /** * Build multiple bracket pattern from context object * Uses the new multiple bracket format: [/route][device] * * @example * buildMultipleBracketKeyFromContext({ route: '/dashboard', device: 'mobile' }) * // Returns: "[/dashboard][mobile]" * * buildMultipleBracketKeyFromContext({ device: 'mobile' }) * // Returns: "[mobile]" */ export declare function buildMultipleBracketKeyFromContext(context: OverrideContext): string; /** * Convert multiple bracket pattern to context object * * @example * multipleBracketToContext("[/dashboard][mobile]") * // Returns: { route: '/dashboard', device: 'mobile' } */ export declare function multipleBracketToContext(overrideKey: string): OverrideContext; /** * Convert a dot-notation path to a nested object * @example * setNestedValue({}, 'uilayout.regions.header.showLogo', false) * // Returns: { uilayout: { regions: { header: { showLogo: false } } } } */ export declare function setNestedValue(obj: any, path: string, value: any): any; /** * Get a value from a nested object using dot notation * @example * getNestedValue({ uilayout: { regions: { header: { showLogo: false } } } }, 'uilayout.regions.header.showLogo') * // Returns: false */ export declare function getNestedValue(obj: any, path: string, defaultValue?: any): any; /** * Deep merge two objects */ export declare function deepMerge(target: any, source: any): any; /** * Build an override context key from context * * Format: [route][device] or [route] or [device] * * @example * buildOverrideKey({ route: '/dashboard', device: 'mobile' }) * // Returns: "[/dashboard][mobile]" * * buildOverrideKey({ route: '/dashboard' }) * // Returns: "[/dashboard]" * * buildOverrideKey({ device: 'mobile' }) * // Returns: "[mobile]" */ export declare function buildOverrideKey(context: OverrideContext): string; /** * Parse an override key into its components * Supports both new multiple bracket format and legacy dot notation * * @example * parseOverrideKey("[/dashboard][mobile]") // New format * // Returns: { route: '/dashboard', device: 'mobile' } * * parseOverrideKey("[/dashboard.mobile]") // Legacy format * // Returns: { route: '/dashboard', device: 'mobile' } * * parseOverrideKey("[/dashboard]") * // Returns: { route: '/dashboard' } * * parseOverrideKey("[mobile]") * // Returns: { device: 'mobile' } * * parseOverrideKey("[.mobile]") // Legacy device-only format * // Returns: { device: 'mobile' } */ export declare function parseOverrideKey(overrideKey: string): OverrideContext; /** * Get a configuration value with override support * * Priority: * 1. Most specific override (all context matches) * 2. Partial overrides (some context matches) * 3. Base configuration value * 4. Default value * * Works with nested storage where overrides are stored as: * { "[route=/dashboard][device=mobile]": { uilayout: { regions: { header: { showLogo: false } } } } } */ export declare function getConfigValue(settings: any, configKey: string, context: OverrideContext, defaultValue?: T): T; /** * Set a configuration value as an override * * Returns the context key and nested value structure. * The service layer will merge this into the settings object. * * @example * const result = setConfigOverride('regions.header.showLogo', false, { route: '/dashboard', device: 'mobile' }); * // Returns: { * // contextKey: '[device=mobile][route=/dashboard]', * // path: 'uilayout.regions.header.showLogo', * // value: false, * // nestedValue: { uilayout: { regions: { header: { showLogo: false } } } } * // } */ export declare function setConfigOverride(configKey: string, value: any, context: OverrideContext): { contextKey: string; path: string; value: any; nestedValue: any; }; /** * Get all overrides for a specific context * Works with nested storage format */ export declare function getContextOverrides(settings: any, context: OverrideContext): Record; /** * Remove all overrides for a specific context * Returns the context key to remove from settings */ export declare function clearContextOverrides(settings: any, context: OverrideContext): string | null; //# sourceMappingURL=configOverrides.d.ts.map