@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.
- package/README.md +482 -0
- package/dist/errors/index.d.ts +105 -0
- package/dist/errors/index.js +165 -0
- package/dist/errors/index.js.map +1 -0
- package/dist/filter/index.d.ts +43 -0
- package/dist/filter/index.js +335 -0
- package/dist/filter/index.js.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -0
- package/dist/model.d.ts +192 -0
- package/dist/model.js +45 -0
- package/dist/model.js.map +1 -0
- package/dist/parser/index.d.ts +120 -0
- package/dist/parser/index.js +497 -0
- package/dist/parser/index.js.map +1 -0
- package/dist/tokenizer/index.d.ts +89 -0
- package/dist/tokenizer/index.js +416 -0
- package/dist/tokenizer/index.js.map +1 -0
- package/dist/utils/index.d.ts +56 -0
- package/dist/utils/index.js +139 -0
- package/dist/utils/index.js.map +1 -0
- package/package.json +50 -0
|
@@ -0,0 +1,497 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-shadow */
|
|
2
|
+
/**
|
|
3
|
+
* Parser for AQL (Allure Query Language)
|
|
4
|
+
*/
|
|
5
|
+
import { AqlErrors } from "../errors/index.js";
|
|
6
|
+
import { AqlLogicalOperator, AqlOperation } from "../model.js";
|
|
7
|
+
import { AqlTokenizer } from "../tokenizer/index.js";
|
|
8
|
+
/**
|
|
9
|
+
* Parser for AQL (Allure Query Language) expressions.
|
|
10
|
+
* Converts AQL strings into abstract syntax trees (AST).
|
|
11
|
+
*/
|
|
12
|
+
export class AqlParser {
|
|
13
|
+
/**
|
|
14
|
+
* Creates a new AQL parser instance.
|
|
15
|
+
*
|
|
16
|
+
* @param input - The AQL string to parse
|
|
17
|
+
* @param context - Optional context map for function values (e.g., `now()`, `currentUser()`)
|
|
18
|
+
* @param config - Optional parser configuration to restrict available features
|
|
19
|
+
* @throws {AqlParserError} If input is not a non-empty string
|
|
20
|
+
*/
|
|
21
|
+
constructor(input, context = undefined, config = {}) {
|
|
22
|
+
this.tokens = [];
|
|
23
|
+
this.position = 0;
|
|
24
|
+
if (!input || typeof input !== "string") {
|
|
25
|
+
throw AqlErrors.invalidInput("Input must be a non-empty string");
|
|
26
|
+
}
|
|
27
|
+
const tokenizer = new AqlTokenizer(input);
|
|
28
|
+
this.tokens = tokenizer.tokenize();
|
|
29
|
+
// Use provided context or create empty Map only when needed
|
|
30
|
+
this.context = context;
|
|
31
|
+
this.config = config;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Parses the AQL string into an abstract syntax tree.
|
|
35
|
+
*
|
|
36
|
+
* @returns The parse result containing the expression or null if input is empty
|
|
37
|
+
* @throws {AqlParserError} If the AQL string is invalid or uses forbidden features
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* ```typescript
|
|
41
|
+
* const parser = new AqlParser('status = "passed"');
|
|
42
|
+
* const result = parser.parse();
|
|
43
|
+
* console.log(result.expression); // AqlConditionExpression
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
parse() {
|
|
47
|
+
if (this.reachedEOL) {
|
|
48
|
+
return { expression: null };
|
|
49
|
+
}
|
|
50
|
+
const expression = this.parseOrExpression();
|
|
51
|
+
this.expect("EOL");
|
|
52
|
+
return { expression };
|
|
53
|
+
}
|
|
54
|
+
parseOrExpression() {
|
|
55
|
+
let left = this.parseAndExpression();
|
|
56
|
+
while (this.match("OR")) {
|
|
57
|
+
const operator = AqlLogicalOperator.OR;
|
|
58
|
+
this.validateLogicalOperator(operator, this.previous.position);
|
|
59
|
+
const right = this.parseAndExpression();
|
|
60
|
+
left = {
|
|
61
|
+
type: "binary",
|
|
62
|
+
left,
|
|
63
|
+
operator,
|
|
64
|
+
right,
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
return left;
|
|
68
|
+
}
|
|
69
|
+
parseAndExpression() {
|
|
70
|
+
let left = this.parseNotExpression();
|
|
71
|
+
while (this.match("AND")) {
|
|
72
|
+
const operator = AqlLogicalOperator.AND;
|
|
73
|
+
this.validateLogicalOperator(operator, this.previous.position);
|
|
74
|
+
const right = this.parseNotExpression();
|
|
75
|
+
left = {
|
|
76
|
+
type: "binary",
|
|
77
|
+
left,
|
|
78
|
+
operator,
|
|
79
|
+
right,
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
return left;
|
|
83
|
+
}
|
|
84
|
+
parseNotExpression() {
|
|
85
|
+
if (this.match("NOT")) {
|
|
86
|
+
const position = this.previous.position;
|
|
87
|
+
this.validateLogicalOperator(AqlLogicalOperator.NOT, position);
|
|
88
|
+
const expression = this.parseNotExpression();
|
|
89
|
+
return {
|
|
90
|
+
type: "not",
|
|
91
|
+
expression,
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
return this.parsePrimaryExpression();
|
|
95
|
+
}
|
|
96
|
+
parsePrimaryExpression() {
|
|
97
|
+
/**
|
|
98
|
+
* Parentheses
|
|
99
|
+
*/
|
|
100
|
+
if (this.match("LPAREN")) {
|
|
101
|
+
const position = this.previous.position;
|
|
102
|
+
if (this.config.parentheses === false) {
|
|
103
|
+
throw AqlErrors.forbiddenParentheses(position);
|
|
104
|
+
}
|
|
105
|
+
const expression = this.parseOrExpression();
|
|
106
|
+
this.expect("RPAREN");
|
|
107
|
+
return {
|
|
108
|
+
type: "paren",
|
|
109
|
+
expression,
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Boolean value
|
|
114
|
+
*/
|
|
115
|
+
if (this.match("BOOLEAN")) {
|
|
116
|
+
const value = this.previous.value.toLowerCase() === "true"; // BOOLEAN always has value
|
|
117
|
+
return {
|
|
118
|
+
type: "boolean",
|
|
119
|
+
value,
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Condition or array condition
|
|
124
|
+
*/
|
|
125
|
+
const left = this.parseAccessor();
|
|
126
|
+
/**
|
|
127
|
+
* Array condition (IN)
|
|
128
|
+
*/
|
|
129
|
+
if (this.match("IN")) {
|
|
130
|
+
const position = this.previous.position;
|
|
131
|
+
const operator = AqlOperation.IN;
|
|
132
|
+
this.validateOperation(operator, position);
|
|
133
|
+
const right = this.parseArray();
|
|
134
|
+
return {
|
|
135
|
+
type: "arrayCondition",
|
|
136
|
+
left,
|
|
137
|
+
operator,
|
|
138
|
+
right,
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Regular condition
|
|
143
|
+
*/
|
|
144
|
+
const operator = this.parseOperation();
|
|
145
|
+
const right = this.parseValue();
|
|
146
|
+
return {
|
|
147
|
+
type: "condition",
|
|
148
|
+
left,
|
|
149
|
+
operator,
|
|
150
|
+
right,
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
parseAccessor() {
|
|
154
|
+
this.expect("IDENTIFIER");
|
|
155
|
+
const identifier = this.previous.value; // IDENTIFIER always has value
|
|
156
|
+
const position = this.previous.position;
|
|
157
|
+
/**
|
|
158
|
+
* Validate identifier format (only Latin letters and underscores)
|
|
159
|
+
*/
|
|
160
|
+
this.validateIdentifierFormat(identifier, position);
|
|
161
|
+
/**
|
|
162
|
+
* Validate field name (configuration-based)
|
|
163
|
+
*/
|
|
164
|
+
this.validateIdentifier(identifier, position);
|
|
165
|
+
/**
|
|
166
|
+
* Access to array element or object property
|
|
167
|
+
*/
|
|
168
|
+
if (this.match("LBRACKET")) {
|
|
169
|
+
if (this.config.indexAccess === false) {
|
|
170
|
+
throw AqlErrors.forbiddenBracketAccess(this.previous.position);
|
|
171
|
+
}
|
|
172
|
+
let param;
|
|
173
|
+
if (this.match("STRING")) {
|
|
174
|
+
const stringValue = this.previous.value; // STRING always has value
|
|
175
|
+
const unquoted = this.unquoteString(stringValue);
|
|
176
|
+
param = { value: unquoted, type: "string" };
|
|
177
|
+
}
|
|
178
|
+
else if (this.match("NUMBER")) {
|
|
179
|
+
const numberValue = this.previous.value; // NUMBER always has value
|
|
180
|
+
param = { value: parseFloat(numberValue), type: "number" };
|
|
181
|
+
}
|
|
182
|
+
else {
|
|
183
|
+
throw AqlErrors.expectedAccessor(this.current.position);
|
|
184
|
+
}
|
|
185
|
+
this.expect("RBRACKET");
|
|
186
|
+
return { identifier, param };
|
|
187
|
+
}
|
|
188
|
+
return { identifier };
|
|
189
|
+
}
|
|
190
|
+
parseOperation() {
|
|
191
|
+
const position = this.current.position;
|
|
192
|
+
let operation = null;
|
|
193
|
+
if (this.match("GT")) {
|
|
194
|
+
operation = AqlOperation.GT;
|
|
195
|
+
}
|
|
196
|
+
else if (this.match("GE")) {
|
|
197
|
+
operation = AqlOperation.GE;
|
|
198
|
+
}
|
|
199
|
+
else if (this.match("LT")) {
|
|
200
|
+
operation = AqlOperation.LT;
|
|
201
|
+
}
|
|
202
|
+
else if (this.match("LE")) {
|
|
203
|
+
operation = AqlOperation.LE;
|
|
204
|
+
}
|
|
205
|
+
else if (this.match("EQ")) {
|
|
206
|
+
operation = AqlOperation.EQ;
|
|
207
|
+
}
|
|
208
|
+
else if (this.match("NEQ")) {
|
|
209
|
+
operation = AqlOperation.NEQ;
|
|
210
|
+
}
|
|
211
|
+
else if (this.match("CONTAINS")) {
|
|
212
|
+
operation = AqlOperation.CONTAINS;
|
|
213
|
+
}
|
|
214
|
+
if (operation) {
|
|
215
|
+
this.validateOperation(operation, position);
|
|
216
|
+
return operation;
|
|
217
|
+
}
|
|
218
|
+
throw AqlErrors.expectedOperation(position);
|
|
219
|
+
}
|
|
220
|
+
parseValue() {
|
|
221
|
+
const position = this.current.position;
|
|
222
|
+
if (this.match("NULL")) {
|
|
223
|
+
const valueType = "NULL";
|
|
224
|
+
this.validateValueType(valueType, position);
|
|
225
|
+
return { value: "null", type: valueType };
|
|
226
|
+
}
|
|
227
|
+
if (this.match("BOOLEAN")) {
|
|
228
|
+
const value = this.previous.value; // BOOLEAN always has value
|
|
229
|
+
const valueType = "BOOLEAN";
|
|
230
|
+
this.validateValueType(valueType, position);
|
|
231
|
+
return { value, type: valueType };
|
|
232
|
+
}
|
|
233
|
+
if (this.match("NUMBER")) {
|
|
234
|
+
const value = this.previous.value; // NUMBER always has value
|
|
235
|
+
const valueType = "NUMBER";
|
|
236
|
+
this.validateValueType(valueType, position);
|
|
237
|
+
return { value, type: valueType };
|
|
238
|
+
}
|
|
239
|
+
if (this.match("STRING")) {
|
|
240
|
+
const value = this.previous.value; // STRING always has value
|
|
241
|
+
const unquoted = this.unquoteString(value);
|
|
242
|
+
const valueType = "STRING";
|
|
243
|
+
this.validateValueType(valueType, position);
|
|
244
|
+
return { value: unquoted, type: valueType };
|
|
245
|
+
}
|
|
246
|
+
if (this.match("FUNCTION")) {
|
|
247
|
+
const key = this.previous.value; // FUNCTION always has value
|
|
248
|
+
const valueType = "FUNCTION";
|
|
249
|
+
this.validateValueType(valueType, position);
|
|
250
|
+
if (!this.context || this.context.size === 0) {
|
|
251
|
+
return { value: "null", type: "NULL" };
|
|
252
|
+
}
|
|
253
|
+
const contextValue = this.context.get(key);
|
|
254
|
+
if (contextValue === null || contextValue === undefined) {
|
|
255
|
+
return { value: "null", type: "NULL" };
|
|
256
|
+
}
|
|
257
|
+
if (typeof contextValue === "number") {
|
|
258
|
+
return { value: String(contextValue), type: "NUMBER" };
|
|
259
|
+
}
|
|
260
|
+
if (typeof contextValue === "boolean") {
|
|
261
|
+
return { value: String(contextValue), type: "BOOLEAN" };
|
|
262
|
+
}
|
|
263
|
+
return { value: String(contextValue), type: "STRING" };
|
|
264
|
+
}
|
|
265
|
+
throw AqlErrors.expectedValue(position);
|
|
266
|
+
}
|
|
267
|
+
parseArray() {
|
|
268
|
+
this.expect("LBRACKET");
|
|
269
|
+
const values = [];
|
|
270
|
+
if (!this.match("RBRACKET")) {
|
|
271
|
+
do {
|
|
272
|
+
values.push(this.parseValue());
|
|
273
|
+
} while (this.match("COMMA"));
|
|
274
|
+
this.expect("RBRACKET");
|
|
275
|
+
}
|
|
276
|
+
return values;
|
|
277
|
+
}
|
|
278
|
+
match(type) {
|
|
279
|
+
if (this.check(type)) {
|
|
280
|
+
this.advance();
|
|
281
|
+
return true;
|
|
282
|
+
}
|
|
283
|
+
return false;
|
|
284
|
+
}
|
|
285
|
+
check(type) {
|
|
286
|
+
if (this.reachedEOL) {
|
|
287
|
+
return type === "EOL";
|
|
288
|
+
}
|
|
289
|
+
return this.current.type === type;
|
|
290
|
+
}
|
|
291
|
+
expect(type) {
|
|
292
|
+
if (!this.match(type)) {
|
|
293
|
+
const current = this.current;
|
|
294
|
+
const context = this.getErrorContext(current.position);
|
|
295
|
+
throw AqlErrors.expectedToken(type, current.type, current.position, context ?? undefined);
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
getErrorContext(position) {
|
|
299
|
+
if (position < 0 || position >= this.tokens.length) {
|
|
300
|
+
return null;
|
|
301
|
+
}
|
|
302
|
+
const start = Math.max(0, position - 2);
|
|
303
|
+
const end = Math.min(this.tokens.length, position + 3);
|
|
304
|
+
// Build context string directly without creating intermediate arrays
|
|
305
|
+
const parts = [];
|
|
306
|
+
for (let i = start; i < end; i++) {
|
|
307
|
+
const token = this.tokens[i];
|
|
308
|
+
parts.push(token.value ?? token.type);
|
|
309
|
+
}
|
|
310
|
+
return parts.join(" ");
|
|
311
|
+
}
|
|
312
|
+
advance() {
|
|
313
|
+
if (!this.reachedEOL) {
|
|
314
|
+
this.position++;
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
get reachedEOL() {
|
|
318
|
+
return this.current.type === "EOL";
|
|
319
|
+
}
|
|
320
|
+
get current() {
|
|
321
|
+
return this.tokens[this.position] || this.tokens[this.tokens.length - 1];
|
|
322
|
+
}
|
|
323
|
+
get previous() {
|
|
324
|
+
return this.tokens[this.position - 1];
|
|
325
|
+
}
|
|
326
|
+
unquoteString(quoted) {
|
|
327
|
+
if (quoted.length < 2 || quoted[0] !== '"' || quoted[quoted.length - 1] !== '"') {
|
|
328
|
+
return quoted;
|
|
329
|
+
}
|
|
330
|
+
// Optimize: process escape sequences in a single pass instead of multiple replace() calls
|
|
331
|
+
const chars = [];
|
|
332
|
+
for (let i = 1; i < quoted.length - 1; i++) {
|
|
333
|
+
const char = quoted[i];
|
|
334
|
+
if (char === "\\" && i + 1 < quoted.length - 1) {
|
|
335
|
+
const next = quoted[i + 1];
|
|
336
|
+
switch (next) {
|
|
337
|
+
case "n":
|
|
338
|
+
chars.push("\n");
|
|
339
|
+
i++; // Skip next character as it's part of escape sequence
|
|
340
|
+
continue;
|
|
341
|
+
case "t":
|
|
342
|
+
chars.push("\t");
|
|
343
|
+
i++;
|
|
344
|
+
continue;
|
|
345
|
+
case "r":
|
|
346
|
+
chars.push("\r");
|
|
347
|
+
i++;
|
|
348
|
+
continue;
|
|
349
|
+
case '"':
|
|
350
|
+
chars.push('"');
|
|
351
|
+
i++;
|
|
352
|
+
continue;
|
|
353
|
+
case "\\":
|
|
354
|
+
chars.push("\\");
|
|
355
|
+
i++;
|
|
356
|
+
continue;
|
|
357
|
+
default:
|
|
358
|
+
// Unknown escape sequence - add both backslash and next char as-is
|
|
359
|
+
chars.push(char);
|
|
360
|
+
chars.push(next);
|
|
361
|
+
i++;
|
|
362
|
+
continue;
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
else {
|
|
366
|
+
chars.push(char);
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
return chars.join("");
|
|
370
|
+
}
|
|
371
|
+
/**
|
|
372
|
+
* Validates that the identifier format is correct (only Latin letters and underscores).
|
|
373
|
+
*
|
|
374
|
+
* @param identifier - The identifier to validate
|
|
375
|
+
* @param position - The position in the input string where the identifier was found
|
|
376
|
+
* @throws {AqlParserError} If the identifier format is invalid
|
|
377
|
+
* @private
|
|
378
|
+
*/
|
|
379
|
+
validateIdentifierFormat(identifier, position) {
|
|
380
|
+
/**
|
|
381
|
+
* Check if identifier contains only Latin letters (a-z, A-Z) and underscores (_)
|
|
382
|
+
*/
|
|
383
|
+
if (!/^[a-zA-Z_]+$/.test(identifier)) {
|
|
384
|
+
throw AqlErrors.invalidIdentifier(identifier, position);
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
/**
|
|
388
|
+
* Validates that the logical operator is allowed according to the configuration.
|
|
389
|
+
*
|
|
390
|
+
* @param operator - The logical operator to validate (AND, OR, NOT)
|
|
391
|
+
* @param position - The position in the input string where the operator was found
|
|
392
|
+
* @throws {AqlParserError} If the operator is not allowed
|
|
393
|
+
* @private
|
|
394
|
+
*/
|
|
395
|
+
validateLogicalOperator(operator, position) {
|
|
396
|
+
if (this.config.logicalOperators === undefined) {
|
|
397
|
+
return; // All operators allowed
|
|
398
|
+
}
|
|
399
|
+
if (!this.config.logicalOperators.includes(operator)) {
|
|
400
|
+
throw AqlErrors.forbiddenLogicalOperator(operator, position);
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
/**
|
|
404
|
+
* Validates that the operation is allowed according to the configuration.
|
|
405
|
+
*
|
|
406
|
+
* @param operation - The operation to validate (GT, GE, LT, LE, EQ, NEQ, CONTAINS, IN)
|
|
407
|
+
* @param position - The position in the input string where the operation was found
|
|
408
|
+
* @throws {AqlParserError} If the operation is not allowed
|
|
409
|
+
* @private
|
|
410
|
+
*/
|
|
411
|
+
validateOperation(operation, position) {
|
|
412
|
+
if (this.config.operations === undefined) {
|
|
413
|
+
return; // All operations allowed
|
|
414
|
+
}
|
|
415
|
+
if (!this.config.operations.includes(operation)) {
|
|
416
|
+
throw AqlErrors.forbiddenOperation(operation, position);
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
/**
|
|
420
|
+
* Validates that the identifier is allowed according to the configuration.
|
|
421
|
+
*
|
|
422
|
+
* @param identifier - The identifier to validate
|
|
423
|
+
* @param position - The position in the input string where the identifier was found
|
|
424
|
+
* @throws {AqlParserError} If the identifier is not allowed
|
|
425
|
+
* @private
|
|
426
|
+
*/
|
|
427
|
+
validateIdentifier(identifier, position) {
|
|
428
|
+
if (this.config.identifiers === undefined) {
|
|
429
|
+
return; // All identifiers allowed
|
|
430
|
+
}
|
|
431
|
+
if (Array.isArray(this.config.identifiers)) {
|
|
432
|
+
if (!this.config.identifiers.includes(identifier)) {
|
|
433
|
+
throw AqlErrors.forbiddenIdentifier(identifier, position);
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
else if (typeof this.config.identifiers === "function") {
|
|
437
|
+
if (!this.config.identifiers(identifier)) {
|
|
438
|
+
throw AqlErrors.forbiddenIdentifier(identifier, position);
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
/**
|
|
443
|
+
* Validates that the value type is allowed according to the configuration.
|
|
444
|
+
*
|
|
445
|
+
* @param valueType - The value type to validate (NULL, BOOLEAN, NUMBER, STRING, FUNCTION)
|
|
446
|
+
* @param position - The position in the input string where the value was found
|
|
447
|
+
* @throws {AqlParserError} If the value type is not allowed
|
|
448
|
+
* @private
|
|
449
|
+
*/
|
|
450
|
+
validateValueType(valueType, position) {
|
|
451
|
+
if (this.config.valueTypes === undefined) {
|
|
452
|
+
return; // All value types allowed
|
|
453
|
+
}
|
|
454
|
+
if (!this.config.valueTypes.includes(valueType)) {
|
|
455
|
+
throw AqlErrors.forbiddenValueType(valueType, position);
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
/**
|
|
460
|
+
* Convenience function for parsing AQL string.
|
|
461
|
+
*
|
|
462
|
+
* @param aql - The AQL string to parse
|
|
463
|
+
* @param context - Optional context map or object for function values (e.g., `now()`, `currentUser()`)
|
|
464
|
+
* @param config - Optional parser configuration to restrict available features
|
|
465
|
+
* @returns The parse result containing the expression or null if input is empty
|
|
466
|
+
* @throws {AqlParserError} If the AQL string is invalid or uses forbidden features
|
|
467
|
+
*
|
|
468
|
+
* @example
|
|
469
|
+
* ```typescript
|
|
470
|
+
* // Basic usage
|
|
471
|
+
* const result = parseAql('status = "passed"');
|
|
472
|
+
*
|
|
473
|
+
* // With context
|
|
474
|
+
* const result = parseAql('createdDate >= now()', { "now()": Date.now() });
|
|
475
|
+
*
|
|
476
|
+
* // With configuration
|
|
477
|
+
* import { AqlOperation } from "./types";
|
|
478
|
+
* const config = { operations: [AqlOperation.EQ, AqlOperation.NEQ], identifiers: ["status"] };
|
|
479
|
+
* const result = parseAql('status = "passed"', undefined, config);
|
|
480
|
+
* ```
|
|
481
|
+
*/
|
|
482
|
+
export function parseAql(aql, context, config) {
|
|
483
|
+
if (!aql || typeof aql !== "string") {
|
|
484
|
+
return { expression: null };
|
|
485
|
+
}
|
|
486
|
+
let contextMap;
|
|
487
|
+
if (context instanceof Map) {
|
|
488
|
+
contextMap = context;
|
|
489
|
+
}
|
|
490
|
+
else if (context && typeof context === "object") {
|
|
491
|
+
// Convert plain object to Map, but avoid creating Map for Map instances (handled above)
|
|
492
|
+
contextMap = new Map(Object.entries(context));
|
|
493
|
+
}
|
|
494
|
+
const parser = new AqlParser(aql, contextMap, config);
|
|
495
|
+
return parser.parse();
|
|
496
|
+
}
|
|
497
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/parser/index.ts"],"names":[],"mappings":"AAAA,iDAAiD;AAEjD;;GAEG;AACH,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAmB/C,OAAO,EAAE,kBAAkB,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC/D,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAErD;;;GAGG;AACH,MAAM,OAAO,SAAS;IAMpB;;;;;;;OAOG;IACH,YAAY,KAAa,EAAE,UAAwC,SAAS,EAAE,SAA0B,EAAE;QAblG,WAAM,GAAe,EAAE,CAAC;QACxB,aAAQ,GAAW,CAAC,CAAC;QAa3B,IAAI,CAAC,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;YACxC,MAAM,SAAS,CAAC,YAAY,CAAC,kCAAkC,CAAC,CAA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CAAC;IAEtD,OAAO,MAAM,CAAC,KAAK,EAAE,CAAC;AACxB,CAAC"}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import type { AqlToken } from "../model.js";
|
|
2
|
+
/**
|
|
3
|
+
* Tokenizer for AQL (Allure Query Language).
|
|
4
|
+
* Converts AQL strings into tokens for parsing.
|
|
5
|
+
*/
|
|
6
|
+
export declare class AqlTokenizer {
|
|
7
|
+
private input;
|
|
8
|
+
private position;
|
|
9
|
+
private tokens;
|
|
10
|
+
/**
|
|
11
|
+
* Creates a new AQL tokenizer instance.
|
|
12
|
+
*
|
|
13
|
+
* @param input - The AQL string to tokenize
|
|
14
|
+
*/
|
|
15
|
+
constructor(input: string);
|
|
16
|
+
/**
|
|
17
|
+
* Tokenizes the input string into an array of tokens.
|
|
18
|
+
*
|
|
19
|
+
* @returns Array of tokens representing the AQL string
|
|
20
|
+
* @throws {AqlTokenizerError} If the input contains invalid characters or unterminated strings
|
|
21
|
+
*/
|
|
22
|
+
tokenize(): AqlToken[];
|
|
23
|
+
private nextToken;
|
|
24
|
+
private readWhitespace;
|
|
25
|
+
/**
|
|
26
|
+
* Reads a string token.
|
|
27
|
+
* Supports all Unicode characters including Chinese, Japanese, Korean, etc.
|
|
28
|
+
* String values can contain any Unicode characters, not just identifiers.
|
|
29
|
+
* Correctly handles brackets (), [], operators (>=, <=, etc.), and other special
|
|
30
|
+
* characters inside strings - they are treated as regular characters, not as tokens.
|
|
31
|
+
* Only the closing quote (") terminates the string.
|
|
32
|
+
*/
|
|
33
|
+
private readString;
|
|
34
|
+
private readNumber;
|
|
35
|
+
private readIdentifier;
|
|
36
|
+
/**
|
|
37
|
+
* Case-insensitive comparison helper for short strings (optimized for keywords)
|
|
38
|
+
* Compares characters directly by their codes to avoid creating new strings
|
|
39
|
+
*/
|
|
40
|
+
private equalsIgnoreCase;
|
|
41
|
+
/**
|
|
42
|
+
* Check if first character matches (case-insensitive) without creating new string
|
|
43
|
+
*/
|
|
44
|
+
private firstCharMatches;
|
|
45
|
+
/**
|
|
46
|
+
* Check if identifier is "and" keyword
|
|
47
|
+
*/
|
|
48
|
+
private isKeywordAnd;
|
|
49
|
+
/**
|
|
50
|
+
* Check if identifier is "or" keyword
|
|
51
|
+
*/
|
|
52
|
+
private isKeywordOr;
|
|
53
|
+
/**
|
|
54
|
+
* Check if identifier is "not" keyword
|
|
55
|
+
*/
|
|
56
|
+
private isKeywordNot;
|
|
57
|
+
/**
|
|
58
|
+
* Check if identifier is "in" keyword
|
|
59
|
+
*/
|
|
60
|
+
private isKeywordIn;
|
|
61
|
+
/**
|
|
62
|
+
* Check if identifier is "is" keyword
|
|
63
|
+
*/
|
|
64
|
+
private isKeywordIs;
|
|
65
|
+
/**
|
|
66
|
+
* Check if identifier is boolean keyword ("true" or "false")
|
|
67
|
+
*/
|
|
68
|
+
private isKeywordBoolean;
|
|
69
|
+
/**
|
|
70
|
+
* Check if identifier is null keyword ("null" or "empty")
|
|
71
|
+
*/
|
|
72
|
+
private isKeywordNull;
|
|
73
|
+
private currentChar;
|
|
74
|
+
private peek;
|
|
75
|
+
private advance;
|
|
76
|
+
private match;
|
|
77
|
+
private isWhitespace;
|
|
78
|
+
private isDigit;
|
|
79
|
+
/**
|
|
80
|
+
* Checks if character can start an identifier.
|
|
81
|
+
* Supports: Latin letters (a-z, A-Z) and underscore (_).
|
|
82
|
+
*/
|
|
83
|
+
private isIdentifierStart;
|
|
84
|
+
/**
|
|
85
|
+
* Checks if character can be part of an identifier.
|
|
86
|
+
* Supports: Latin letters (a-z, A-Z) and underscore (_).
|
|
87
|
+
*/
|
|
88
|
+
private isIdentifierChar;
|
|
89
|
+
}
|