@tellaro/tql 0.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,113 @@
1
+ import { TqlAggregationFunction, TqlCollectionOperator, TqlComparisonOperator, TqlLogicalOperator, TqlMutator, TqlToken, TqlTypeHint, TqlVisualizationType } from './types';
2
+
3
+ /**
4
+ * All comparison operators supported by TQL.
5
+ * Includes negated variants using both `not_` prefix and `!` prefix.
6
+ */
7
+ export declare const COMPARISON_OPERATORS: TqlComparisonOperator[];
8
+ /**
9
+ * Symbol-based operators mapped to their word equivalents.
10
+ */
11
+ export declare const SYMBOL_OPERATORS: Record<string, TqlComparisonOperator>;
12
+ /**
13
+ * Negation prefixes for operators.
14
+ */
15
+ export declare const NEGATION_SYMBOL_OPERATORS: Record<string, TqlComparisonOperator>;
16
+ export declare const LOGICAL_OPERATORS: TqlLogicalOperator[];
17
+ export declare const COLLECTION_OPERATORS: TqlCollectionOperator[];
18
+ /**
19
+ * All mutators supported by TQL.
20
+ * Synchronized with Python/Rust implementations.
21
+ */
22
+ export declare const MUTATORS: TqlMutator[];
23
+ /**
24
+ * All aggregation functions supported by TQL.
25
+ * Synchronized with Python/Rust implementations.
26
+ */
27
+ export declare const AGGREGATION_FUNCTIONS: TqlAggregationFunction[];
28
+ /**
29
+ * Type hints for field type specification.
30
+ */
31
+ export declare const TYPE_HINTS: TqlTypeHint[];
32
+ /**
33
+ * Visualization types for stats pipeline.
34
+ */
35
+ export declare const VISUALIZATION_TYPES: TqlVisualizationType[];
36
+ /**
37
+ * Keywords used in TQL.
38
+ */
39
+ export declare const KEYWORDS: string[];
40
+ export declare class TqlTokenizer {
41
+ private input;
42
+ private position;
43
+ private line;
44
+ private column;
45
+ private tokens;
46
+ constructor(input: string);
47
+ /**
48
+ * Tokenize the entire input string
49
+ */
50
+ tokenize(): TqlToken[];
51
+ /**
52
+ * Scan the next token
53
+ */
54
+ private scanToken;
55
+ /**
56
+ * Scan whitespace characters
57
+ */
58
+ private scanWhitespace;
59
+ /**
60
+ * Scan a string literal (single or double quoted)
61
+ */
62
+ private scanString;
63
+ /**
64
+ * Scan a numeric literal
65
+ */
66
+ private scanNumber;
67
+ /**
68
+ * Scan symbol-based operators (==, !=, >, >=, <, <=, !)
69
+ */
70
+ private scanSymbolOperator;
71
+ /**
72
+ * Scan an identifier (field name, operator keyword, etc.)
73
+ */
74
+ private scanIdentifier;
75
+ /**
76
+ * Classify an identifier into the appropriate token type
77
+ */
78
+ private classifyIdentifier;
79
+ private makeToken;
80
+ private isAtEnd;
81
+ private peek;
82
+ private peekNext;
83
+ private advance;
84
+ private isWhitespace;
85
+ private isDigit;
86
+ private isIdentifierStart;
87
+ private isIdentifierChar;
88
+ private isOperatorChar;
89
+ }
90
+ /**
91
+ * Tokenize a TQL query string
92
+ */
93
+ export declare function tokenizeTql(query: string): TqlToken[];
94
+ /**
95
+ * Get tokens without whitespace (for parsing)
96
+ */
97
+ export declare function tokenizeTqlNoWhitespace(query: string): TqlToken[];
98
+ /**
99
+ * Find token at a specific position
100
+ */
101
+ export declare function findTokenAtPosition(tokens: TqlToken[], position: number): TqlToken | null;
102
+ /**
103
+ * Find tokens in a range
104
+ */
105
+ export declare function findTokensInRange(tokens: TqlToken[], start: number, end: number): TqlToken[];
106
+ /**
107
+ * Get the token immediately before a position
108
+ */
109
+ export declare function findTokenBefore(tokens: TqlToken[], position: number): TqlToken | null;
110
+ /**
111
+ * Get the previous non-whitespace token
112
+ */
113
+ export declare function findPreviousToken(tokens: TqlToken[], position: number, skipWhitespace?: boolean): TqlToken | null;
@@ -0,0 +1,430 @@
1
+ var l = Object.defineProperty;
2
+ var u = (o, e, n) => e in o ? l(o, e, { enumerable: !0, configurable: !0, writable: !0, value: n }) : o[e] = n;
3
+ var a = (o, e, n) => u(o, typeof e != "symbol" ? e + "" : e, n);
4
+ const p = [
5
+ // Equality
6
+ "eq",
7
+ "ne",
8
+ // Comparison
9
+ "gt",
10
+ "gte",
11
+ "lt",
12
+ "lte",
13
+ // String operators
14
+ "contains",
15
+ "not_contains",
16
+ "startswith",
17
+ "not_startswith",
18
+ "endswith",
19
+ "not_endswith",
20
+ "regexp",
21
+ "regex",
22
+ "not_regexp",
23
+ "matches",
24
+ "not_matches",
25
+ // Range operators
26
+ "between",
27
+ "not_between",
28
+ "in",
29
+ "not_in",
30
+ // Existence operators
31
+ "exists",
32
+ "not_exists",
33
+ "is",
34
+ "is_not",
35
+ // IP-specific operators
36
+ "cidr",
37
+ "not_cidr",
38
+ // Collection operators (can be used as comparison)
39
+ "any",
40
+ "all",
41
+ "none",
42
+ "not_any",
43
+ "not_all",
44
+ "not_none"
45
+ ], c = {
46
+ "==": "eq",
47
+ "=": "eq",
48
+ "!=": "ne",
49
+ ">": "gt",
50
+ ">=": "gte",
51
+ "<": "lt",
52
+ "<=": "lte"
53
+ }, d = {
54
+ "!in": "not_in",
55
+ "!contains": "not_contains",
56
+ "!startswith": "not_startswith",
57
+ "!endswith": "not_endswith",
58
+ "!regexp": "not_regexp",
59
+ "!matches": "not_matches",
60
+ "!between": "not_between",
61
+ "!exists": "not_exists",
62
+ "!is": "is_not",
63
+ "!cidr": "not_cidr",
64
+ "!any": "not_any",
65
+ "!all": "not_all",
66
+ "!none": "not_none"
67
+ }, k = ["AND", "OR", "NOT"], f = ["ANY", "ALL", "NONE"], m = [
68
+ // String mutators
69
+ "lowercase",
70
+ "uppercase",
71
+ "trim",
72
+ "split",
73
+ "length",
74
+ "replace",
75
+ // Encoding mutators
76
+ "b64encode",
77
+ "b64decode",
78
+ "urldecode",
79
+ "hexencode",
80
+ "hexdecode",
81
+ "md5",
82
+ "sha256",
83
+ // Network/Security mutators
84
+ "refang",
85
+ "defang",
86
+ "is_private",
87
+ "is_global",
88
+ // DNS mutator
89
+ "nslookup",
90
+ // GeoIP mutators
91
+ "geoip_lookup",
92
+ "geoip",
93
+ "geo",
94
+ // List/Array mutators
95
+ "any",
96
+ "all",
97
+ "avg",
98
+ "average",
99
+ "sum",
100
+ "min",
101
+ "max"
102
+ ], _ = [
103
+ // Counting
104
+ "count",
105
+ "unique_count",
106
+ "cardinality",
107
+ // Numeric aggregations
108
+ "sum",
109
+ "min",
110
+ "max",
111
+ "avg",
112
+ "average",
113
+ "mean",
114
+ "median",
115
+ "med",
116
+ "std",
117
+ "standard_deviation",
118
+ // Percentile functions
119
+ "percentile",
120
+ "percentiles",
121
+ "p",
122
+ "pct",
123
+ "percentile_rank",
124
+ "percentile_ranks",
125
+ "pct_rank",
126
+ "pct_ranks",
127
+ // Unique values
128
+ "values",
129
+ "unique",
130
+ "distinct"
131
+ ], g = [
132
+ "string",
133
+ "str",
134
+ "number",
135
+ "int",
136
+ "integer",
137
+ "float",
138
+ "double",
139
+ "decimal",
140
+ "date",
141
+ "bool",
142
+ "boolean",
143
+ "array",
144
+ "list",
145
+ "object",
146
+ "geo"
147
+ ], T = [
148
+ "bar",
149
+ "barchart",
150
+ "line",
151
+ "area",
152
+ "pie",
153
+ "donut",
154
+ "scatter",
155
+ "heatmap",
156
+ "treemap",
157
+ "sunburst",
158
+ "table",
159
+ "number",
160
+ "gauge",
161
+ "map",
162
+ "grouped_bar",
163
+ "stacked_bar",
164
+ "nested_pie",
165
+ "nested_donut",
166
+ "chord"
167
+ ], w = ["by", "as", "null", "true", "false", "stats", "top", "bottom"];
168
+ class b {
169
+ constructor(e) {
170
+ a(this, "input");
171
+ a(this, "position");
172
+ a(this, "line");
173
+ a(this, "column");
174
+ a(this, "tokens");
175
+ this.input = e, this.position = 0, this.line = 1, this.column = 1, this.tokens = [];
176
+ }
177
+ /**
178
+ * Tokenize the entire input string
179
+ */
180
+ tokenize() {
181
+ for (this.tokens = [], this.position = 0, this.line = 1, this.column = 1; !this.isAtEnd(); ) {
182
+ const e = this.scanToken();
183
+ e && this.tokens.push(e);
184
+ }
185
+ return this.tokens;
186
+ }
187
+ /**
188
+ * Scan the next token
189
+ */
190
+ scanToken() {
191
+ if (this.isWhitespace(this.peek()))
192
+ return this.scanWhitespace();
193
+ const e = this.position, n = this.line, i = this.column, t = this.advance();
194
+ switch (t) {
195
+ case "(":
196
+ case ")":
197
+ return this.makeToken("paren", t, e, n, i);
198
+ case "[":
199
+ case "]":
200
+ return this.makeToken("bracket", t, e, n, i);
201
+ case ",":
202
+ return this.makeToken("comma", t, e, n, i);
203
+ case "|":
204
+ return this.makeToken("pipe", t, e, n, i);
205
+ }
206
+ return t === "=" && this.peek() === ">" ? (this.advance(), this.makeToken("arrow", "=>", e, n, i)) : t === ":" && this.peek() === ":" ? (this.advance(), this.makeToken("doubleColon", "::", e, n, i)) : t === '"' || t === "'" ? this.scanString(t, e, n, i) : this.isDigit(t) || t === "-" && this.isDigit(this.peek()) ? this.scanNumber(e, n, i) : this.isOperatorChar(t) ? this.scanSymbolOperator(e, n, i) : this.isIdentifierStart(t) ? this.scanIdentifier(e, n, i) : this.makeToken("unknown", t, e, n, i);
207
+ }
208
+ /**
209
+ * Scan whitespace characters
210
+ */
211
+ scanWhitespace() {
212
+ const e = this.position, n = this.line, i = this.column;
213
+ let t = "";
214
+ for (; !this.isAtEnd() && this.isWhitespace(this.peek()); ) {
215
+ const s = this.advance();
216
+ t += s;
217
+ }
218
+ return this.makeToken("whitespace", t, e, n, i);
219
+ }
220
+ /**
221
+ * Scan a string literal (single or double quoted)
222
+ */
223
+ scanString(e, n, i, t) {
224
+ let s = "";
225
+ const r = e;
226
+ for (; !this.isAtEnd() && this.peek() !== e; )
227
+ if (this.peek() === "\\") {
228
+ if (this.advance(), !this.isAtEnd()) {
229
+ const h = this.advance();
230
+ switch (h) {
231
+ case "n":
232
+ s += `
233
+ `;
234
+ break;
235
+ case "t":
236
+ s += " ";
237
+ break;
238
+ case "r":
239
+ s += "\r";
240
+ break;
241
+ case "\\":
242
+ s += "\\";
243
+ break;
244
+ case '"':
245
+ s += '"';
246
+ break;
247
+ case "'":
248
+ s += "'";
249
+ break;
250
+ default:
251
+ s += h;
252
+ }
253
+ }
254
+ } else
255
+ s += this.advance();
256
+ return this.isAtEnd() ? {
257
+ type: "error",
258
+ value: r + s,
259
+ start: n,
260
+ end: this.position,
261
+ line: i,
262
+ column: t,
263
+ raw: r + s
264
+ } : (this.advance(), {
265
+ type: "string",
266
+ value: s,
267
+ start: n,
268
+ end: this.position,
269
+ line: i,
270
+ column: t,
271
+ raw: e + s + e
272
+ });
273
+ }
274
+ /**
275
+ * Scan a numeric literal
276
+ */
277
+ scanNumber(e, n, i) {
278
+ this.position = e, this.column = i;
279
+ let t = "";
280
+ for (this.peek() === "-" && (t += this.advance()); !this.isAtEnd() && this.isDigit(this.peek()); )
281
+ t += this.advance();
282
+ if (this.peek() === "." && this.isDigit(this.peekNext()))
283
+ for (t += this.advance(); !this.isAtEnd() && this.isDigit(this.peek()); )
284
+ t += this.advance();
285
+ if (this.peek() === "e" || this.peek() === "E")
286
+ for (t += this.advance(), (this.peek() === "+" || this.peek() === "-") && (t += this.advance()); !this.isAtEnd() && this.isDigit(this.peek()); )
287
+ t += this.advance();
288
+ return this.makeToken("number", t, e, n, i);
289
+ }
290
+ /**
291
+ * Scan symbol-based operators (==, !=, >, >=, <, <=, !)
292
+ */
293
+ scanSymbolOperator(e, n, i) {
294
+ this.position = e, this.column = i;
295
+ let t = this.advance();
296
+ if (!this.isAtEnd()) {
297
+ const s = t + this.peek();
298
+ if (s === "=>")
299
+ return this.advance(), this.makeToken("arrow", "=>", e, n, i);
300
+ (s in c || s === "==" || s === "!=") && (t = s, this.advance());
301
+ }
302
+ if (t === "!") {
303
+ const s = this.position;
304
+ let r = "";
305
+ for (; !this.isAtEnd() && this.isIdentifierChar(this.peek()); )
306
+ r += this.advance();
307
+ if (r) {
308
+ if ("!" + r in d)
309
+ return this.makeToken("operator", "!" + r, e, n, i);
310
+ this.position = s, this.column = i + 1;
311
+ }
312
+ }
313
+ return t in c || t === "==" || t === "=" || t === "!=" || t === ">" || t === ">=" || t === "<" || t === "<=" ? this.makeToken("operator", t, e, n, i) : this.makeToken("unknown", t, e, n, i);
314
+ }
315
+ /**
316
+ * Scan an identifier (field name, operator keyword, etc.)
317
+ */
318
+ scanIdentifier(e, n, i) {
319
+ this.position = e, this.column = i;
320
+ let t = "";
321
+ for (; !this.isAtEnd() && this.isIdentifierChar(this.peek()); )
322
+ t += this.advance();
323
+ const s = this.classifyIdentifier(t);
324
+ return this.makeToken(s, t, e, n, i);
325
+ }
326
+ /**
327
+ * Classify an identifier into the appropriate token type
328
+ */
329
+ classifyIdentifier(e) {
330
+ const n = e.toUpperCase(), i = e.toLowerCase();
331
+ return k.includes(n) ? "logicalOp" : f.includes(n) ? "collectionOp" : i === "true" || i === "false" ? "boolean" : i === "null" ? "null" : i === "stats" ? "keyword" : p.includes(i) ? "operator" : _.includes(i) ? "aggregation" : m.includes(i) ? "mutator" : g.includes(i) ? "typeHint" : T.includes(i) ? "visualization" : w.includes(i) ? "keyword" : "field";
332
+ }
333
+ // ============================================================================
334
+ // Helper Methods
335
+ // ============================================================================
336
+ makeToken(e, n, i, t, s) {
337
+ return {
338
+ type: e,
339
+ value: n,
340
+ start: i,
341
+ end: this.position,
342
+ line: t,
343
+ column: s
344
+ };
345
+ }
346
+ isAtEnd() {
347
+ return this.position >= this.input.length;
348
+ }
349
+ peek() {
350
+ return this.isAtEnd() ? "\0" : this.input[this.position];
351
+ }
352
+ peekNext() {
353
+ return this.position + 1 >= this.input.length ? "\0" : this.input[this.position + 1];
354
+ }
355
+ advance() {
356
+ const e = this.input[this.position];
357
+ return this.position++, e === `
358
+ ` ? (this.line++, this.column = 1) : this.column++, e;
359
+ }
360
+ isWhitespace(e) {
361
+ return e === " " || e === " " || e === `
362
+ ` || e === "\r";
363
+ }
364
+ isDigit(e) {
365
+ return e >= "0" && e <= "9";
366
+ }
367
+ isIdentifierStart(e) {
368
+ return e >= "a" && e <= "z" || e >= "A" && e <= "Z" || e === "_" || e === "@";
369
+ }
370
+ isIdentifierChar(e) {
371
+ return this.isIdentifierStart(e) || this.isDigit(e) || e === "." || // For nested field access
372
+ e === "-";
373
+ }
374
+ isOperatorChar(e) {
375
+ return e === "=" || e === "!" || e === ">" || e === "<";
376
+ }
377
+ }
378
+ function v(o) {
379
+ return new b(o).tokenize();
380
+ }
381
+ function A(o) {
382
+ return v(o).filter((e) => e.type !== "whitespace");
383
+ }
384
+ function E(o, e) {
385
+ for (const n of o)
386
+ if (e >= n.start && e < n.end)
387
+ return n;
388
+ return null;
389
+ }
390
+ function S(o, e, n) {
391
+ return o.filter((i) => i.start < n && i.end > e);
392
+ }
393
+ function I(o, e) {
394
+ let n = null;
395
+ for (const i of o)
396
+ if (i.end <= e)
397
+ n = i;
398
+ else
399
+ break;
400
+ return n;
401
+ }
402
+ function y(o, e, n = !0) {
403
+ const i = n ? o.filter((s) => s.type !== "whitespace") : o;
404
+ let t = null;
405
+ for (const s of i)
406
+ if (s.end <= e)
407
+ t = s;
408
+ else
409
+ break;
410
+ return t;
411
+ }
412
+ export {
413
+ _ as AGGREGATION_FUNCTIONS,
414
+ f as COLLECTION_OPERATORS,
415
+ p as COMPARISON_OPERATORS,
416
+ w as KEYWORDS,
417
+ k as LOGICAL_OPERATORS,
418
+ m as MUTATORS,
419
+ d as NEGATION_SYMBOL_OPERATORS,
420
+ c as SYMBOL_OPERATORS,
421
+ g as TYPE_HINTS,
422
+ b as TqlTokenizer,
423
+ T as VISUALIZATION_TYPES,
424
+ y as findPreviousToken,
425
+ E as findTokenAtPosition,
426
+ I as findTokenBefore,
427
+ S as findTokensInRange,
428
+ v as tokenizeTql,
429
+ A as tokenizeTqlNoWhitespace
430
+ };