UNPKG

@simonecoelhosfo/optimizely-mcp-server

Version:

Optimizely MCP Server for AI assistants with integrated CLI tools

108 lines 3.23 kB
/** * Field Resolution Strategy - JOIN Necessity Algorithm * * CRITICAL COMPONENT: Prevents JOIN explosion by implementing smart field resolution * * DESIGN PRINCIPLES: * 1. Local First: Check primary entity fields before considering JOINs * 2. Aggregation Aware: Different logic for COUNT/SUM vs detail queries * 3. Cardinality Conscious: Prevent multiplication explosions * 4. Necessity Driven: Require explicit need for JOINs, not just availability * * Created: July 5, 2025 * Purpose: Fix 700-1400x count inflation caused by unnecessary JOINs */ export interface FieldResolutionStrategy { checkLocal: boolean; requireExplicit: boolean; aggregationAware: boolean; cardinalityLimit: number; fallbackToSimple: boolean; timeoutLimit: number; } export interface FieldResolutionContext { primaryEntity: string; requestedField: string; isAggregation: boolean; isGroupBy: boolean; projectId?: string; queryType: 'count' | 'list' | 'aggregate' | 'detail'; } export interface FieldResolutionResult { source: 'local' | 'related' | 'computed' | 'fallback'; fieldPath: string; joinRequired: boolean; joinPath?: JoinPath; estimatedCost: number; confidence: number; reasoning: string; } export interface JoinPath { fromTable: string; toTable: string; fromField: string; toField: string; joinType: 'INNER' | 'LEFT' | 'RIGHT'; estimatedMultiplier: number; } /** * JOIN Necessity Decision Tree Implementation */ export declare class FieldResolutionAlgorithm { private localFieldMaps; private dangerousJoins; constructor(); /** * Main field resolution method using necessity-driven algorithm */ resolveFieldWithPriority(field: string, context: FieldResolutionContext): FieldResolutionResult; /** * Step 1: Check if field exists in primary entity */ private checkLocalField; /** * Step 2: Check if aggregation can be done without JOIN */ private checkAggregationWithoutJoin; /** * Step 3: Evaluate if JOIN is truly necessary */ private evaluateJoinNecessity; /** * Step 4: Create fallback resolution */ private createFallbackResolution; /** * Check if a JOIN is safe (won't cause explosion) */ private isJoinSafe; /** * Generate field variations for fuzzy matching */ private generateFieldVariations; /** * Check junction tables for local field resolution */ private checkJunctionTableLocal; /** * Get potential JOIN paths for a field */ private getPotentialJoins; /** * Check if table is a large lookup table that causes explosions */ private isLargeLookupTable; /** * Initialize local field mappings for each entity */ private initializeLocalFieldMaps; /** * Initialize dangerous JOINs that cause explosions */ private initializeDangerousJoins; } /** * Factory function to create field resolution strategy based on query context */ export declare function createFieldResolutionStrategy(context: FieldResolutionContext): FieldResolutionStrategy; //# sourceMappingURL=FieldResolutionStrategy.d.ts.map