@simonecoelhosfo/optimizely-mcp-server
Version:
Optimizely MCP Server for AI assistants with integrated CLI tools
79 lines • 2.98 kB
TypeScript
/**
* FieldLocalityResolver - Knows WHERE fields actually live in the database
*
* CRITICAL: This resolver prevents unnecessary JOINs by understanding field locations
* Example: environment_key lives in flag_environments, NOT environments table
*/
import { FieldLocalityInfo, EnhancedQueryIntent } from './types';
import { EntityType } from './types';
/**
* Enhanced Field Mapping Interface for Deep JSON Analytics
*
* This interface supports complex JSON operations including:
* - Dynamic key iteration (e.g., aggregating across unknown variation IDs)
* - Context-aware filtering (e.g., filtering by aggregator type)
* - Advanced SQL generation with json_each() and subqueries
*/
interface EnhancedFieldMapping {
table: string;
entity: string;
jsonPath: string;
aggregation?: string;
requiresIteration?: boolean;
contextFilters?: string[];
iterationSource?: string;
countCondition?: string;
}
export declare class FieldLocalityResolver {
private logger;
/**
* CRITICAL: This mapping tells us where fields ACTUALLY live
* This prevents JOIN explosions by knowing the true field locations
*/
private readonly FIELD_PRIMARY_LOCATIONS;
/**
* Enhanced Field Mappings for Deep JSON Analytics
*
* These mappings handle complex operations that require JSON iteration,
* aggregation across dynamic keys, and context-aware filtering.
*/
private readonly ENHANCED_FIELD_MAPPINGS;
/**
* Resolve where a field actually lives based on query context
*/
resolveFieldLocality(field: string, queryIntent: EnhancedQueryIntent, primaryEntity: EntityType): FieldLocalityInfo;
/**
* Check if a field has enhanced mapping for deep JSON analytics
*/
hasEnhancedMapping(field: string): boolean;
/**
* Get enhanced mapping for a field that requires complex JSON operations
*/
getEnhancedMapping(field: string): EnhancedFieldMapping | null;
/**
* Check if a field operation requires JSON iteration (dynamic key aggregation)
*/
requiresJsonIteration(field: string): boolean;
/**
* Get the COUNT condition for a field (handles COUNT(metrics) -> json_array_length)
*/
getCountCondition(field: string): string | null;
/**
* Resolve multiple fields and build a locality map
*/
resolveFieldsLocality(fields: string[], queryIntent: EnhancedQueryIntent, primaryEntity: EntityType): Map<string, FieldLocalityInfo>;
/**
* Check if a field exists in a specific table
*/
isFieldInTable(field: string, table: string): boolean;
/**
* Get the optimal table for aggregating by a field
*/
getOptimalTableForAggregation(field: string, aggregationType: 'count' | 'sum' | 'avg' | 'min' | 'max'): string | null;
/**
* Normalize field names to handle variations
*/
private normalizeFieldName;
}
export {};
//# sourceMappingURL=FieldLocalityResolver.d.ts.map