/** * Unified Where Clause Interface * * A consistent filtering interface that works across databases, * graphs, and vector stores using MongoDB-style operators. */ /** * Standard comparison operators (work on all data types) */ export interface IComparisonCondition { /** Equals */ $eq?: any; /** Not equals */ $ne?: any; /** Greater than */ $gt?: any; /** Greater than or equal */ $gte?: any; /** Less than */ $lt?: any; /** Less than or equal */ $lte?: any; /** In array */ $in?: any[]; /** Not in array */ $nin?: any[]; /** Between two values (inclusive) */ $between?: [any, any]; /** Is null */ $isNull?: boolean; /** Exists (field is present) */ $exists?: boolean; } /** * String-specific operators */ export interface IStringCondition extends IComparisonCondition { /** SQL LIKE pattern (case-sensitive) */ $like?: string; /** SQL ILIKE pattern (case-insensitive) */ $ilike?: string; /** Starts with prefix */ $startsWith?: string; /** Ends with suffix */ $endsWith?: string; /** Contains substring */ $contains?: string; /** Regular expression match */ $regex?: string | { pattern: string; flags?: string; }; } /** * Array-specific operators */ export interface IArrayCondition extends IComparisonCondition { /** Array contains value */ $contains?: any; /** Array is contained by */ $containedBy?: any[]; /** Arrays overlap */ $overlaps?: any[]; /** Array has length */ $size?: number; /** All elements match condition */ $all?: any[]; /** At least one element matches */ $elemMatch?: IUnifiedWhereClause; } /** * JSON/Object-specific operators */ export interface IJsonCondition extends IComparisonCondition { /** JSON path exists */ $hasKey?: string; /** JSON contains */ $jsonContains?: Record; /** Contained by JSON */ $jsonContainedBy?: Record; } /** * Vector similarity operator (for semantic search) */ export interface IVectorSimilarityCondition { $similar?: { /** Vector to compare against */ vector: number[]; /** Minimum similarity threshold (0-1 for cosine) */ threshold?: number; /** Maximum number of similar items */ topK?: number; /** Distance metric */ metric?: 'cosine' | 'euclidean' | 'dot_product'; }; } /** * Graph connectivity operator */ export interface IGraphConnectivityCondition { $connected?: { /** * Target node specification * Can be node ID or "Label:property=value" */ to: string; /** Relationship type to traverse */ via?: string; /** Maximum traversal depth */ maxDepth?: number; /** Direction of traversal */ direction?: 'outgoing' | 'incoming' | 'both'; }; /** Node has specific label */ $hasLabel?: string | string[]; /** Relationship exists */ $hasRelationship?: { type: string; direction?: 'outgoing' | 'incoming' | 'both'; properties?: IUnifiedWhereClause; }; } /** * Full-text search operator */ export interface IFullTextCondition { $text?: { /** Search query */ search: string; /** Language for stemming */ language?: string; /** Case sensitive */ caseSensitive?: boolean; /** Diacritic sensitive */ diacriticSensitive?: boolean; }; $match?: { /** Match query */ query: string; /** Fields to search */ fields?: string[]; /** Fuzziness level */ fuzziness?: number | 'auto'; }; } /** * All possible field conditions */ export type IFieldCondition = IComparisonCondition & IStringCondition & IArrayCondition & IJsonCondition & IVectorSimilarityCondition & IGraphConnectivityCondition & IFullTextCondition; /** * Logical operators for combining conditions */ export interface ILogicalOperators { /** All conditions must match */ $and?: IUnifiedWhereClause[]; /** At least one condition must match */ $or?: IUnifiedWhereClause[]; /** Condition must not match */ $not?: IUnifiedWhereClause; /** None of the conditions must match */ $nor?: IUnifiedWhereClause[]; } /** * Unified where clause that works across all data source types * * @example * // Simple equality * { "u.status": { $eq: "active" } } * * @example * // Complex with logical operators * { * $and: [ * { "u.age": { $gte: 18 } }, * { $or: [ * { "u.status": { $eq: "active" } }, * { "u.role": { $eq: "admin" } } * ]} * ] * } * * @example * // Vector similarity * { "embedding": { $similar: { vector: [...], threshold: 0.8 } } } * * @example * // Graph connectivity * { "node": { $connected: { to: "Category:AI", via: "BELONGS_TO" } } } */ export type IUnifiedWhereClause = ILogicalOperators & { [fieldPath: string]: IFieldCondition | any; }; /** * Check if a where clause is empty */ export declare function isEmptyWhereClause(where?: IUnifiedWhereClause): boolean; /** * Check if a condition uses vector operators */ export declare function hasVectorOperators(where?: IUnifiedWhereClause): boolean; /** * Check if a condition uses graph operators */ export declare function hasGraphOperators(where?: IUnifiedWhereClause): boolean; /** * Extract field paths from a where clause */ export declare function extractFieldPaths(where?: IUnifiedWhereClause): string[];