/** * Type definitions for TONL Query API * * Defines the Abstract Syntax Tree (AST) node types for path expressions * and filter conditions in JSONPath-like query syntax. */ /** * Base interface for all path nodes */ export interface BasePathNode { type: string; } /** * Root node ($) * Represents the root of the document */ export interface RootNode extends BasePathNode { type: 'root'; symbol: '$'; } /** * Property access node * Example: user.name → { type: 'property', name: 'name' } */ export interface PropertyNode extends BasePathNode { type: 'property'; name: string; } /** * Array index access node * Examples: * - users[0] → { type: 'index', index: 0 } * - users[-1] → { type: 'index', index: -1 } (last element) */ export interface IndexNode extends BasePathNode { type: 'index'; index: number; } /** * Wildcard node (*) * Matches all elements in an array or all properties in an object * Example: users[*].name */ export interface WildcardNode extends BasePathNode { type: 'wildcard'; } /** * Recursive descent node (..) * Searches for a property at any depth * Examples: * - $..email → find all 'email' properties at any level * - $.. → find all nodes at any level */ export interface RecursiveNode extends BasePathNode { type: 'recursive'; name?: string; } /** * Array slice node * Examples: * - users[0:5] → { type: 'slice', start: 0, end: 5, step: 1 } * - users[:3] → { type: 'slice', start: undefined, end: 3, step: 1 } * - users[2:] → { type: 'slice', start: 2, end: undefined, step: 1 } * - users[::2] → { type: 'slice', start: undefined, end: undefined, step: 2 } */ export interface SliceNode extends BasePathNode { type: 'slice'; start?: number; end?: number; step?: number; } /** * Filter expression node * Example: users[?(@.role == "admin")] */ export interface FilterNode extends BasePathNode { type: 'filter'; expression: FilterExpression; } /** * Union of all path node types */ export type PathNode = RootNode | PropertyNode | IndexNode | WildcardNode | RecursiveNode | SliceNode | FilterNode; /** * Filter expression types */ export type FilterExpression = BinaryExpression | UnaryExpression | LiteralExpression | PropertyExpression | FunctionExpression; /** * Binary expression (comparison or logical operators) * Examples: * - @.age > 18 * - @.role == "admin" * - @.active && @.verified */ export interface BinaryExpression { type: 'binary'; operator: BinaryOperator; left: FilterExpression; right: FilterExpression; } /** * Unary expression (negation) * Example: !@.deleted */ export interface UnaryExpression { type: 'unary'; operator: UnaryOperator; argument: FilterExpression; } /** * Literal value expression * Examples: 18, "admin", true, null */ export interface LiteralExpression { type: 'literal'; value: any; } /** * Property access in filter (relative to current item) * Examples: * - @.role → current item's role property * - @.user.email → nested property access */ export interface PropertyExpression { type: 'property'; path: string; } /** * Function call expression * Examples: * - contains(@.email, "@company.com") * - size(@.tags) > 0 */ export interface FunctionExpression { type: 'function'; name: string; arguments: FilterExpression[]; } /** * Binary operators for filter expressions */ export type BinaryOperator = '==' | '!=' | '>' | '<' | '>=' | '<=' | '&&' | '||' | 'contains' | 'startsWith' | 'endsWith' | 'matches' | '~=' | '~contains' | '~startsWith' | '~endsWith' | 'fuzzyMatch' | 'soundsLike' | 'similar' | 'before' | 'after' | 'between' | 'daysAgo' | 'weeksAgo' | 'monthsAgo' | 'yearsAgo' | 'sameDay' | 'sameWeek' | 'sameMonth' | 'sameYear' | 'in' | 'typeof' | 'instanceof'; /** * Fuzzy matching operators */ export type FuzzyOperator = '~=' | '~contains' | '~startsWith' | '~endsWith' | 'fuzzyMatch' | 'soundsLike' | 'similar'; /** * Temporal comparison operators */ export type TemporalOperator = 'before' | 'after' | 'between' | 'daysAgo' | 'weeksAgo' | 'monthsAgo' | 'yearsAgo' | 'sameDay' | 'sameWeek' | 'sameMonth' | 'sameYear'; /** * Unary operators for filter expressions */ export type UnaryOperator = '!' | 'exists' | 'empty'; /** * Token types for path tokenization */ export declare enum TokenType { ROOT = "ROOT",// $ DOT = "DOT",// . DOUBLE_DOT = "DOUBLE_DOT",// .. LBRACKET = "LBRACKET",// [ RBRACKET = "RBRACKET",// ] IDENTIFIER = "IDENTIFIER",// property names NUMBER = "NUMBER",// numeric values STRING = "STRING",// string literals WILDCARD = "WILDCARD",// * COLON = "COLON",// : (for slices) COMMA = "COMMA",// , (for unions) QUESTION = "QUESTION",// ? (filter prefix) AT = "AT",// @ (current item in filter) LPAREN = "LPAREN",// ( RPAREN = "RPAREN",// ) LBRACE = "LBRACE",// { RBRACE = "RBRACE",// } EQ = "EQ",// == NEQ = "NEQ",// != GT = "GT",// > LT = "LT",// < GTE = "GTE",// >= LTE = "LTE",// <= AND = "AND",// && OR = "OR",// || NOT = "NOT",// ! CONTAINS = "CONTAINS",// contains STARTS_WITH = "STARTS_WITH",// startsWith ENDS_WITH = "ENDS_WITH",// endsWith MATCHES = "MATCHES",// matches FUZZY_EQ = "FUZZY_EQ",// ~= FUZZY_CONTAINS = "FUZZY_CONTAINS",// ~contains FUZZY_STARTS = "FUZZY_STARTS",// ~startsWith FUZZY_ENDS = "FUZZY_ENDS",// ~endsWith FUZZY_MATCH = "FUZZY_MATCH",// fuzzyMatch SOUNDS_LIKE = "SOUNDS_LIKE",// soundsLike SIMILAR = "SIMILAR",// similar BEFORE = "BEFORE",// before AFTER = "AFTER",// after BETWEEN = "BETWEEN",// between DAYS_AGO = "DAYS_AGO",// daysAgo WEEKS_AGO = "WEEKS_AGO",// weeksAgo MONTHS_AGO = "MONTHS_AGO",// monthsAgo YEARS_AGO = "YEARS_AGO",// yearsAgo SAME_DAY = "SAME_DAY",// sameDay SAME_WEEK = "SAME_WEEK",// sameWeek SAME_MONTH = "SAME_MONTH",// sameMonth SAME_YEAR = "SAME_YEAR",// sameYear TEMPORAL = "TEMPORAL",// @now, @2025-01-15, etc. EOF = "EOF" } /** * Token representation */ export interface Token { type: TokenType; value: any; position: number; length: number; } /** * Parse context for error reporting */ export interface ParseContext { input: string; position: number; tokens: Token[]; currentToken: number; } /** * Parse error with detailed context */ export declare class ParseError extends Error { context: ParseContext; position: number; input: string; constructor(message: string, context: ParseContext, position: number); /** * Get a formatted error message with context */ getFormattedMessage(): string; } /** * Options for path parsing */ export interface ParseOptions { /** * Whether to validate the AST after parsing * @default true */ validate?: boolean; /** * Whether to allow partial paths (for auto-completion) * @default false */ allowPartial?: boolean; /** * Maximum depth for recursive descent to prevent infinite loops * @default 100 */ maxRecursionDepth?: number; } /** * Result of path parsing */ export interface ParseResult { /** * The parsed AST nodes */ ast: PathNode[]; /** * Whether the parse was successful */ success: boolean; /** * Error if parsing failed */ error?: ParseError; /** * Original input string */ input: string; } //# sourceMappingURL=types.d.ts.map