@simonecoelhosfo/optimizely-mcp-server
Version:
Optimizely MCP Server for AI assistants with integrated CLI tools
106 lines • 2.67 kB
TypeScript
/**
* TemplateQueryTranslator - Converts structured query templates to SQL
*
* This replaces the micro-kernel approach with deterministic template-based queries.
* Leverages existing field correction and synonym matching systems.
*
* Created: January 8, 2025
* Status: 🚧 IMPLEMENTATION STARTED
*/
export interface StructuredQueryTemplate {
from: string;
select?: string[];
where?: Record<string, any>;
group_by?: string[];
order_by?: {
field: string;
direction?: 'asc' | 'desc';
};
aggregate?: {
count?: string;
sum?: string;
avg?: string;
min?: string;
max?: string;
};
limit?: number;
page?: number;
page_size?: number;
no_limit?: boolean;
}
export interface SQLResult {
sql: string;
countSql: string;
params: any[];
viewUsed: string;
fieldsResolved: Record<string, string>;
limit: number;
offset: number;
page: number;
}
export interface ValidationResult {
valid: boolean;
errors?: string[];
warnings?: string[];
suggestions?: string[];
}
export declare class TemplateQueryTranslator {
private smartFieldMapper;
private paginationConfig;
private readonly FIELD_CORRECTIONS;
constructor();
/**
* Main translation method
*/
translateToSQL(template: StructuredQueryTemplate, db?: any): Promise<SQLResult>;
/**
* Resolve view name - maps simplified names to actual database view names
*/
resolveViewName(input: string): string;
/**
* Build SELECT clause with field resolution
*/
private buildSelectClause;
/**
* Build WHERE clause with field resolution
*/
private buildWhereClause;
/**
* Resolve field name using comprehensive field mapping system
*/
private resolveFieldName;
/**
* Build GROUP BY clause
*/
private buildGroupByClause;
/**
* Build ORDER BY clause
*/
private buildOrderByClause;
/**
* Get entity type from view name for SmartFieldMapper
*/
private getEntityTypeFromView;
/**
* Correct values for SQLite compatibility
*/
private correctValue;
/**
* Validate template structure
*/
private validateTemplate;
/**
* Get available fields for a view
*/
getAvailableFields(viewName: string): Promise<string[]>;
/**
* Map comparison operators to SQL operators
*/
private mapComparisonOperator;
/**
* Convert camelCase to snake_case
*/
private toSnakeCase;
}
export default TemplateQueryTranslator;
//# sourceMappingURL=TemplateQueryTranslator.d.ts.map