/** * @fileoverview AST types for loq query representation * @module query/ast * * Defines the Abstract Syntax Tree (AST) node types used * to represent parsed loq queries. */ /** Union type of all possible query AST nodes */ export type QueryNode = | WhereClause | ComparisonExpr | BinaryLogicExpr | NotExpr | CountExpr | GroupByExpr | TimeFilterExpr | LimitExpr | SelectExpr; export interface WhereClause { type: 'where'; condition: QueryNode; } export interface ComparisonExpr { type: 'comparison'; field: string; operator: '=' | '!=' | '>' | '<' | '>=' | '<=' | 'contains' | 'matches'; value: string | number; } export interface BinaryLogicExpr { type: 'binary'; operator: 'and' | 'or'; left: QueryNode; right: QueryNode; } export interface NotExpr { type: 'not'; operand: QueryNode; } export interface CountExpr { type: 'count'; groupBy?: string; } export interface GroupByExpr { type: 'groupby'; field: string; aggregations: AggregationExpr[]; } export interface AggregationExpr { type: 'aggregation'; func: 'count' | 'sum' | 'avg' | 'min' | 'max'; field?: string; alias?: string; } export interface TimeFilterExpr { type: 'timefilter'; operator: 'between' | 'after' | 'before'; start?: string; end?: string; relative?: string; // 'today', 'yesterday' } export interface LimitExpr { type: 'limit'; count: number; } export interface SelectExpr { type: 'select'; fields: string[] | '*'; from: string; where?: QueryNode; groupBy?: string; aggregations?: AggregationExpr[]; limit?: number; } export interface ParsedQuery { source?: string; where?: QueryNode; timeFilter?: TimeFilterExpr; aggregation?: CountExpr | GroupByExpr; limit?: number; select?: SelectExpr; }