@allurereport/aql 3.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,192 @@
1
+ /**
2
+ * Types for AQL (Allure Query Language) parsing
3
+ */
4
+ export type AqlValueKind = "NULL" | "BOOLEAN" | "NUMBER" | "STRING" | "FUNCTION";
5
+ /**
6
+ * Token types for AQL tokenizer.
7
+ */
8
+ export type AqlTokenType = AqlOperations | AqlLogicalOperators | AqlValueKind | "IDENTIFIER" | "LPAREN" | "RPAREN" | "LBRACKET" | "RBRACKET" | "COMMA" | "EOL" | "WS";
9
+ /**
10
+ * Token interface for AQL tokenizer.
11
+ */
12
+ export interface AqlToken {
13
+ type: AqlTokenType;
14
+ /**
15
+ * Token value. Required only for tokens that carry data:
16
+ * - STRING: string value with quotes
17
+ * - NUMBER: numeric value
18
+ * - IDENTIFIER: identifier name
19
+ * - FUNCTION: function name with "()"
20
+ * - BOOLEAN: "true" or "false"
21
+ * Optional for operators, keywords, brackets, and EOL tokens.
22
+ */
23
+ value?: string;
24
+ position: number;
25
+ }
26
+ /**
27
+ * AQL operation types.
28
+ */
29
+ export declare const AqlOperation: {
30
+ /** Greater than: > */
31
+ readonly GT: "GT";
32
+ /** Greater than or equal: >= */
33
+ readonly GE: "GE";
34
+ /** Less than: < */
35
+ readonly LT: "LT";
36
+ /** Less than or equal: <= */
37
+ readonly LE: "LE";
38
+ /** Equal: = or is */
39
+ readonly EQ: "EQ";
40
+ /** Not equal: != */
41
+ readonly NEQ: "NEQ";
42
+ /** Contains: ~= */
43
+ readonly CONTAINS: "CONTAINS";
44
+ /** In array: IN */
45
+ readonly IN: "IN";
46
+ };
47
+ export type AqlOperations = (typeof AqlOperation)[keyof typeof AqlOperation];
48
+ export declare const AqlOperationAliases: {
49
+ readonly EQ: "=";
50
+ readonly NEQ: "!=";
51
+ readonly GT: ">";
52
+ readonly GE: ">=";
53
+ readonly LT: "<";
54
+ readonly LE: "<=";
55
+ readonly CONTAINS: "~=";
56
+ };
57
+ export type AqlOperationAlias = (typeof AqlOperationAliases)[keyof typeof AqlOperationAliases];
58
+ /**
59
+ * AQL operation with string literal aliases for backward compatibility.
60
+ * Includes both enum values (e.g., AqlOperation.EQ) and string literals (e.g., "=").
61
+ */
62
+ export type AqlOperationOrAlias = AqlOperations | AqlOperationAlias;
63
+ /**
64
+ * AQL logical operators.
65
+ */
66
+ export declare const AqlLogicalOperator: {
67
+ /** Logical AND */
68
+ readonly AND: "AND";
69
+ /** Logical OR */
70
+ readonly OR: "OR";
71
+ /** Logical NOT */
72
+ readonly NOT: "NOT";
73
+ };
74
+ export type AqlLogicalOperators = (typeof AqlLogicalOperator)[keyof typeof AqlLogicalOperator];
75
+ export interface AqlValue {
76
+ value: string;
77
+ type: AqlValueKind;
78
+ }
79
+ export interface AqlAccessor {
80
+ identifier: string;
81
+ param?: {
82
+ value: string | number;
83
+ type: "string" | "number";
84
+ };
85
+ }
86
+ type AqlConditionOperator = Exclude<AqlOperations, "IN">;
87
+ export interface AqlConditionExpression {
88
+ type: "condition";
89
+ left: AqlAccessor;
90
+ operator: AqlConditionOperator;
91
+ right: AqlValue;
92
+ }
93
+ type AqlArrayOperator = Extract<AqlOperations, "IN">;
94
+ export interface AqlArrayConditionExpression {
95
+ type: "arrayCondition";
96
+ left: AqlAccessor;
97
+ operator: AqlArrayOperator;
98
+ right: AqlValue[];
99
+ }
100
+ type AqlBinaryOperator = Extract<AqlLogicalOperators, "AND" | "OR">;
101
+ export interface AqlBinaryExpression {
102
+ type: "binary";
103
+ left: AqlExpression;
104
+ operator: AqlBinaryOperator;
105
+ right: AqlExpression;
106
+ }
107
+ export interface AqlNotExpression {
108
+ type: "not";
109
+ expression: AqlExpression;
110
+ }
111
+ export interface AqlParenExpression {
112
+ type: "paren";
113
+ expression: AqlExpression;
114
+ }
115
+ export interface AqlBooleanExpression {
116
+ type: "boolean";
117
+ value: boolean;
118
+ }
119
+ export type AqlExpression = AqlConditionExpression | AqlArrayConditionExpression | AqlBinaryExpression | AqlNotExpression | AqlParenExpression | AqlBooleanExpression;
120
+ export interface AqlParseResult {
121
+ expression: AqlExpression | null;
122
+ }
123
+ /**
124
+ * Configuration for AQL parser to restrict available features.
125
+ *
126
+ * @example
127
+ * ```typescript
128
+ * import { AqlLogicalOperator, AqlOperation } from "./types";
129
+ *
130
+ * const config: AqlParserConfig = {
131
+ * logicalOperators: [AqlLogicalOperator.AND, AqlLogicalOperator.OR],
132
+ * operations: [AqlOperation.EQ, AqlOperation.NEQ],
133
+ * identifiers: ["status", "name"],
134
+ * valueTypes: ["STRING", "NUMBER"],
135
+ * parentheses: true,
136
+ * indexAccess: false,
137
+ * };
138
+ * ```
139
+ */
140
+ export interface AqlParserConfig {
141
+ /**
142
+ * Available logical operators (AND, OR, NOT).
143
+ * If not specified, all operators are available.
144
+ *
145
+ * @default undefined (all operators available)
146
+ */
147
+ logicalOperators?: AqlLogicalOperators[];
148
+ /**
149
+ * Available operations (GT, GE, LT, LE, EQ, NEQ, CONTAINS, IN).
150
+ * If not specified, all operations are available.
151
+ *
152
+ * @default undefined (all operations available)
153
+ */
154
+ operations?: AqlOperations[];
155
+ /**
156
+ * Allowed identifiers
157
+ * Can be an array of allowed identifiers or a validation function.
158
+ * If not specified, all identifiers are allowed.
159
+ *
160
+ * @default undefined (all identifiers allowed)
161
+ *
162
+ * @example
163
+ * ```typescript
164
+ * // Array of allowed identifiers
165
+ * identifiers: ["status", "name"]
166
+ *
167
+ * // Validation function
168
+ * identifiers: (identifier) => identifier.startsWith("allowed_")
169
+ * ```
170
+ */
171
+ identifiers?: string[] | ((identifier: string) => boolean);
172
+ /**
173
+ * Available value types (NULL, BOOLEAN, NUMBER, STRING, FUNCTION).
174
+ * If not specified, all value types are available.
175
+ *
176
+ * @default undefined (all value types available)
177
+ */
178
+ valueTypes?: AqlValueKind[];
179
+ /**
180
+ * Whether parentheses are allowed for grouping expressions.
181
+ *
182
+ * @default true
183
+ */
184
+ parentheses?: boolean;
185
+ /**
186
+ * Whether array/object index access via brackets is allowed (e.g., `identifier[key]`).
187
+ *
188
+ * @default true
189
+ */
190
+ indexAccess?: boolean;
191
+ }
192
+ export {};
package/dist/model.js ADDED
@@ -0,0 +1,45 @@
1
+ /**
2
+ * Types for AQL (Allure Query Language) parsing
3
+ */
4
+ /**
5
+ * AQL operation types.
6
+ */
7
+ export const AqlOperation = {
8
+ /** Greater than: > */
9
+ GT: "GT",
10
+ /** Greater than or equal: >= */
11
+ GE: "GE",
12
+ /** Less than: < */
13
+ LT: "LT",
14
+ /** Less than or equal: <= */
15
+ LE: "LE",
16
+ /** Equal: = or is */
17
+ EQ: "EQ",
18
+ /** Not equal: != */
19
+ NEQ: "NEQ",
20
+ /** Contains: ~= */
21
+ CONTAINS: "CONTAINS",
22
+ /** In array: IN */
23
+ IN: "IN",
24
+ };
25
+ export const AqlOperationAliases = {
26
+ [AqlOperation.EQ]: "=",
27
+ [AqlOperation.NEQ]: "!=",
28
+ [AqlOperation.GT]: ">",
29
+ [AqlOperation.GE]: ">=",
30
+ [AqlOperation.LT]: "<",
31
+ [AqlOperation.LE]: "<=",
32
+ [AqlOperation.CONTAINS]: "~=",
33
+ };
34
+ /**
35
+ * AQL logical operators.
36
+ */
37
+ export const AqlLogicalOperator = {
38
+ /** Logical AND */
39
+ AND: "AND",
40
+ /** Logical OR */
41
+ OR: "OR",
42
+ /** Logical NOT */
43
+ NOT: "NOT",
44
+ };
45
+ //# sourceMappingURL=model.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"model.js","sourceRoot":"","sources":["../src/model.ts"],"names":[],"mappings":"AAAA;;GAEG;AAsCH;;GAEG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG;IAC1B,sBAAsB;IACtB,EAAE,EAAE,IAAI;IACR,gCAAgC;IAChC,EAAE,EAAE,IAAI;IACR,mBAAmB;IACnB,EAAE,EAAE,IAAI;IACR,6BAA6B;IAC7B,EAAE,EAAE,IAAI;IACR,qBAAqB;IACrB,EAAE,EAAE,IAAI;IACR,oBAAoB;IACpB,GAAG,EAAE,KAAK;IACV,mBAAmB;IACnB,QAAQ,EAAE,UAAU;IACpB,mBAAmB;IACnB,EAAE,EAAE,IAAI;CACA,CAAC;AAIX,MAAM,CAAC,MAAM,mBAAmB,GAAG;IACjC,CAAC,YAAY,CAAC,EAAE,CAAC,EAAE,GAAG;IACtB,CAAC,YAAY,CAAC,GAAG,CAAC,EAAE,IAAI;IACxB,CAAC,YAAY,CAAC,EAAE,CAAC,EAAE,GAAG;IACtB,CAAC,YAAY,CAAC,EAAE,CAAC,EAAE,IAAI;IACvB,CAAC,YAAY,CAAC,EAAE,CAAC,EAAE,GAAG;IACtB,CAAC,YAAY,CAAC,EAAE,CAAC,EAAE,IAAI;IACvB,CAAC,YAAY,CAAC,QAAQ,CAAC,EAAE,IAAI;CACrB,CAAC;AAUX;;GAEG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG;IAChC,kBAAkB;IAClB,GAAG,EAAE,KAAK;IACV,iBAAiB;IACjB,EAAE,EAAE,IAAI;IACR,kBAAkB;IAClB,GAAG,EAAE,KAAK;CACF,CAAC"}
@@ -0,0 +1,120 @@
1
+ import type { AqlParseResult, AqlParserConfig } from "../model.js";
2
+ /**
3
+ * Parser for AQL (Allure Query Language) expressions.
4
+ * Converts AQL strings into abstract syntax trees (AST).
5
+ */
6
+ export declare class AqlParser {
7
+ private tokens;
8
+ private position;
9
+ private context;
10
+ private config;
11
+ /**
12
+ * Creates a new AQL parser instance.
13
+ *
14
+ * @param input - The AQL string to parse
15
+ * @param context - Optional context map for function values (e.g., `now()`, `currentUser()`)
16
+ * @param config - Optional parser configuration to restrict available features
17
+ * @throws {AqlParserError} If input is not a non-empty string
18
+ */
19
+ constructor(input: string, context?: Map<string, any> | undefined, config?: AqlParserConfig);
20
+ /**
21
+ * Parses the AQL string into an abstract syntax tree.
22
+ *
23
+ * @returns The parse result containing the expression or null if input is empty
24
+ * @throws {AqlParserError} If the AQL string is invalid or uses forbidden features
25
+ *
26
+ * @example
27
+ * ```typescript
28
+ * const parser = new AqlParser('status = "passed"');
29
+ * const result = parser.parse();
30
+ * console.log(result.expression); // AqlConditionExpression
31
+ * ```
32
+ */
33
+ parse(): AqlParseResult;
34
+ private parseOrExpression;
35
+ private parseAndExpression;
36
+ private parseNotExpression;
37
+ private parsePrimaryExpression;
38
+ private parseAccessor;
39
+ private parseOperation;
40
+ private parseValue;
41
+ private parseArray;
42
+ private match;
43
+ private check;
44
+ private expect;
45
+ private getErrorContext;
46
+ private advance;
47
+ private get reachedEOL();
48
+ private get current();
49
+ private get previous();
50
+ private unquoteString;
51
+ /**
52
+ * Validates that the identifier format is correct (only Latin letters and underscores).
53
+ *
54
+ * @param identifier - The identifier to validate
55
+ * @param position - The position in the input string where the identifier was found
56
+ * @throws {AqlParserError} If the identifier format is invalid
57
+ * @private
58
+ */
59
+ private validateIdentifierFormat;
60
+ /**
61
+ * Validates that the logical operator is allowed according to the configuration.
62
+ *
63
+ * @param operator - The logical operator to validate (AND, OR, NOT)
64
+ * @param position - The position in the input string where the operator was found
65
+ * @throws {AqlParserError} If the operator is not allowed
66
+ * @private
67
+ */
68
+ private validateLogicalOperator;
69
+ /**
70
+ * Validates that the operation is allowed according to the configuration.
71
+ *
72
+ * @param operation - The operation to validate (GT, GE, LT, LE, EQ, NEQ, CONTAINS, IN)
73
+ * @param position - The position in the input string where the operation was found
74
+ * @throws {AqlParserError} If the operation is not allowed
75
+ * @private
76
+ */
77
+ private validateOperation;
78
+ /**
79
+ * Validates that the identifier is allowed according to the configuration.
80
+ *
81
+ * @param identifier - The identifier to validate
82
+ * @param position - The position in the input string where the identifier was found
83
+ * @throws {AqlParserError} If the identifier is not allowed
84
+ * @private
85
+ */
86
+ private validateIdentifier;
87
+ /**
88
+ * Validates that the value type is allowed according to the configuration.
89
+ *
90
+ * @param valueType - The value type to validate (NULL, BOOLEAN, NUMBER, STRING, FUNCTION)
91
+ * @param position - The position in the input string where the value was found
92
+ * @throws {AqlParserError} If the value type is not allowed
93
+ * @private
94
+ */
95
+ private validateValueType;
96
+ }
97
+ /**
98
+ * Convenience function for parsing AQL string.
99
+ *
100
+ * @param aql - The AQL string to parse
101
+ * @param context - Optional context map or object for function values (e.g., `now()`, `currentUser()`)
102
+ * @param config - Optional parser configuration to restrict available features
103
+ * @returns The parse result containing the expression or null if input is empty
104
+ * @throws {AqlParserError} If the AQL string is invalid or uses forbidden features
105
+ *
106
+ * @example
107
+ * ```typescript
108
+ * // Basic usage
109
+ * const result = parseAql('status = "passed"');
110
+ *
111
+ * // With context
112
+ * const result = parseAql('createdDate >= now()', { "now()": Date.now() });
113
+ *
114
+ * // With configuration
115
+ * import { AqlOperation } from "./types";
116
+ * const config = { operations: [AqlOperation.EQ, AqlOperation.NEQ], identifiers: ["status"] };
117
+ * const result = parseAql('status = "passed"', undefined, config);
118
+ * ```
119
+ */
120
+ export declare function parseAql(aql: string, context?: Map<string, any> | Record<string, any>, config?: AqlParserConfig): AqlParseResult;