@tellaro/tql 1.4.1 → 1.4.3
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.
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { tokenizeTql as x, COMPARISON_OPERATORS as
|
|
1
|
+
import { tokenizeTql as x, COMPARISON_OPERATORS as N, LOGICAL_OPERATORS as S, AGGREGATION_FUNCTIONS as I, VISUALIZATION_TYPES as A, TYPE_HINTS as L, MUTATORS as R } from "./tokenizer.js";
|
|
2
2
|
import { fuzzyMatch as w } from "./fuzzyMatcher.js";
|
|
3
3
|
import { getSchemaCache as $ } from "./schemaCache.js";
|
|
4
4
|
const P = [
|
|
@@ -120,6 +120,7 @@ const P = [
|
|
|
120
120
|
regexp: { detail: "Regular expression", documentation: "Match using regex pattern" },
|
|
121
121
|
regex: { detail: "Regular expression", documentation: "Alias for regexp" },
|
|
122
122
|
not_regexp: { detail: "Not matching regex", documentation: "Negative regex match" },
|
|
123
|
+
not_regex: { detail: "Not matching regex", documentation: "Alias for not_regexp" },
|
|
123
124
|
matches: { detail: "Pattern match", documentation: "Match using pattern" },
|
|
124
125
|
not_matches: { detail: "Not matching pattern", documentation: "Negative pattern match" },
|
|
125
126
|
between: { detail: "Between range", documentation: "Usage: field between A AND B" },
|
|
@@ -228,6 +229,7 @@ const P = [
|
|
|
228
229
|
regexp: ["text", "keyword"],
|
|
229
230
|
regex: ["text", "keyword"],
|
|
230
231
|
not_regexp: ["text", "keyword"],
|
|
232
|
+
not_regex: ["text", "keyword"],
|
|
231
233
|
matches: ["text", "keyword"],
|
|
232
234
|
not_matches: ["text", "keyword"],
|
|
233
235
|
// IP-specific operators
|
|
@@ -260,14 +262,14 @@ class E {
|
|
|
260
262
|
this.cache.clear();
|
|
261
263
|
}
|
|
262
264
|
}
|
|
263
|
-
const
|
|
265
|
+
const k = new E();
|
|
264
266
|
function U(e, t, i) {
|
|
265
267
|
if (!e) return { type: "start", partialText: "" };
|
|
266
|
-
const o = `${e.substring(0, t)}|${t}`, a =
|
|
268
|
+
const o = `${e.substring(0, t)}|${t}`, a = k.get(o);
|
|
267
269
|
if (a)
|
|
268
270
|
return a.fieldName && !a.fieldType && i && (a.fieldType = p(a.fieldName, i)), a;
|
|
269
271
|
const n = F(e, t, i);
|
|
270
|
-
return
|
|
272
|
+
return k.set(o, n), n;
|
|
271
273
|
}
|
|
272
274
|
function F(e, t, i) {
|
|
273
275
|
const a = x(e.substring(0, t)).filter((l) => l.type !== "whitespace");
|
|
@@ -381,9 +383,7 @@ function p(e, t) {
|
|
|
381
383
|
return t ? $().getFieldType(t, e) : void 0;
|
|
382
384
|
}
|
|
383
385
|
function Q(e, t = {}) {
|
|
384
|
-
const { query: i, cursorPosition: o } = e;
|
|
385
|
-
if (!i) return [];
|
|
386
|
-
const a = U(i, o, t.fields), n = [];
|
|
386
|
+
const { query: i, cursorPosition: o } = e, a = U(i, o, t.fields), n = [];
|
|
387
387
|
switch (a.type) {
|
|
388
388
|
case "start":
|
|
389
389
|
case "after_paren":
|
|
@@ -489,10 +489,10 @@ function g(e, t) {
|
|
|
489
489
|
return G(t);
|
|
490
490
|
const i = [];
|
|
491
491
|
for (const o of e) {
|
|
492
|
-
const a =
|
|
492
|
+
const a = v(o);
|
|
493
493
|
if (i.push(a), o.nested)
|
|
494
494
|
for (const n of o.nested) {
|
|
495
|
-
const s =
|
|
495
|
+
const s = v(n, o.name);
|
|
496
496
|
i.push(s);
|
|
497
497
|
}
|
|
498
498
|
}
|
|
@@ -524,7 +524,7 @@ function G(e) {
|
|
|
524
524
|
sortOrder: 10
|
|
525
525
|
}));
|
|
526
526
|
}
|
|
527
|
-
function
|
|
527
|
+
function v(e, t) {
|
|
528
528
|
const i = t ? `${t}.${e.name}` : e.name;
|
|
529
529
|
return {
|
|
530
530
|
label: i,
|
|
@@ -537,7 +537,7 @@ function k(e, t) {
|
|
|
537
537
|
};
|
|
538
538
|
}
|
|
539
539
|
function y(e, t) {
|
|
540
|
-
let i = [...
|
|
540
|
+
let i = [...N];
|
|
541
541
|
return t && (i = i.filter((o) => {
|
|
542
542
|
const a = z[o];
|
|
543
543
|
return !a || a.includes(t);
|
|
@@ -564,6 +564,7 @@ function q(e, t) {
|
|
|
564
564
|
"regexp",
|
|
565
565
|
"regex",
|
|
566
566
|
"not_regexp",
|
|
567
|
+
"not_regex",
|
|
567
568
|
"matches",
|
|
568
569
|
"not_matches"
|
|
569
570
|
], o = ["exists", "not_exists"], a = ["is", "is_not"];
|
|
@@ -608,7 +609,7 @@ function T(e) {
|
|
|
608
609
|
return e === "long" || e === "integer" || e === "double" || e === "float" || e === "short" || e === "byte" || e === "half_float" || e === "scaled_float" || e === "unsigned_long";
|
|
609
610
|
}
|
|
610
611
|
function _() {
|
|
611
|
-
return
|
|
612
|
+
return S.filter((e) => e !== "NOT").map(
|
|
612
613
|
(e, t) => O(e, t)
|
|
613
614
|
);
|
|
614
615
|
}
|
|
@@ -699,7 +700,7 @@ function C(e) {
|
|
|
699
700
|
}));
|
|
700
701
|
}
|
|
701
702
|
function H(e) {
|
|
702
|
-
return
|
|
703
|
+
return L.filter(
|
|
703
704
|
(t) => !e || t.toLowerCase().includes(e.toLowerCase())
|
|
704
705
|
).map((t, i) => ({
|
|
705
706
|
label: t,
|
|
@@ -710,7 +711,7 @@ function H(e) {
|
|
|
710
711
|
}));
|
|
711
712
|
}
|
|
712
713
|
function Y(e) {
|
|
713
|
-
return
|
|
714
|
+
return A.filter(
|
|
714
715
|
(t) => !e || t.toLowerCase().includes(e.toLowerCase())
|
|
715
716
|
).map((t, i) => ({
|
|
716
717
|
label: t,
|
|
@@ -96,7 +96,7 @@ class c {
|
|
|
96
96
|
}));
|
|
97
97
|
}
|
|
98
98
|
const s = e.operator.toLowerCase();
|
|
99
|
-
if ((s === "regexp" || s === "regex" || s === "matches" || s === "not_regexp" || s === "not_matches") && t.regexCount++, this.analyzeValue(e.value, t, a, e), (s === "in" || s === "not_in") && Array.isArray(e.value)) {
|
|
99
|
+
if ((s === "regexp" || s === "regex" || s === "matches" || s === "not_regexp" || s === "not_regex" || s === "not_matches") && t.regexCount++, this.analyzeValue(e.value, t, a, e), (s === "in" || s === "not_in") && Array.isArray(e.value)) {
|
|
100
100
|
const i = e.value.length;
|
|
101
101
|
t.inListMaxSize = Math.max(t.inListMaxSize, i);
|
|
102
102
|
}
|
package/dist/src/parser.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { parseTql as
|
|
1
|
+
import { parseTql as f } from "./parser.js";
|
|
2
2
|
import { analyzeComplexity as m } from "./complexityAnalyzer.js";
|
|
3
3
|
class u {
|
|
4
4
|
/**
|
|
5
5
|
* Generate a complete preview for a TQL query
|
|
6
6
|
*/
|
|
7
7
|
generatePreview(t) {
|
|
8
|
-
const r =
|
|
8
|
+
const r = f(t), i = m(t), n = [], s = {};
|
|
9
9
|
if (!r.ast)
|
|
10
10
|
return {
|
|
11
11
|
fields: [],
|
|
@@ -96,7 +96,7 @@ class u {
|
|
|
96
96
|
return "null_check";
|
|
97
97
|
if (t === "cidr" || t === "not_cidr")
|
|
98
98
|
return "cidr";
|
|
99
|
-
if (t === "regexp" || t === "regex" || t === "matches" || t === "not_regexp" || t === "not_matches")
|
|
99
|
+
if (t === "regexp" || t === "regex" || t === "matches" || t === "not_regexp" || t === "not_regex" || t === "not_matches")
|
|
100
100
|
return "regex";
|
|
101
101
|
if (t === "between" || t === "not_between" || t === "gt" || t === "gte" || t === "lt" || t === "lte")
|
|
102
102
|
return "range";
|
|
@@ -190,13 +190,13 @@ function F(e) {
|
|
|
190
190
|
}
|
|
191
191
|
function h(e) {
|
|
192
192
|
if (e.type === "comparison") {
|
|
193
|
-
const t = e.mutators?.length ? ` | ${e.mutators.join(" | ")}` : "", r =
|
|
193
|
+
const t = e.mutators?.length ? ` | ${e.mutators.join(" | ")}` : "", r = g(e.value);
|
|
194
194
|
return `${e.field}${t} ${e.operator} ${r}`;
|
|
195
195
|
}
|
|
196
196
|
return e.type === "NOT" && e.children?.length === 1 ? `NOT (${h(e.children[0])})` : e.type === "group" && e.children?.length === 1 ? `(${h(e.children[0])})` : (e.type === "AND" || e.type === "OR") && e.children ? e.children.map(h).join(` ${e.type} `) : "";
|
|
197
197
|
}
|
|
198
|
-
function
|
|
199
|
-
return e === null ? "null" : e === void 0 ? "" : typeof e == "string" ? `"${e}"` : Array.isArray(e) ? `[${e.map(
|
|
198
|
+
function g(e) {
|
|
199
|
+
return e === null ? "null" : e === void 0 ? "" : typeof e == "string" ? `"${e}"` : Array.isArray(e) ? `[${e.map(g).join(", ")}]` : String(e);
|
|
200
200
|
}
|
|
201
201
|
function N(e, t = "") {
|
|
202
202
|
if (!e)
|
|
@@ -208,7 +208,7 @@ function N(e, t = "") {
|
|
|
208
208
|
function l(e, t, r, i) {
|
|
209
209
|
const n = i ? "└── " : "├── ", s = i ? " " : "│ ";
|
|
210
210
|
if (e.type === "comparison") {
|
|
211
|
-
const a = e.mutators?.length ? ` | ${e.mutators.join(" | ")}` : "", c =
|
|
211
|
+
const a = e.mutators?.length ? ` | ${e.mutators.join(" | ")}` : "", c = g(e.value);
|
|
212
212
|
t.push(`${r}${n}${e.field}${a} ${e.operator} ${c}`);
|
|
213
213
|
} else e.type === "NOT" ? (t.push(`${r}${n}NOT`), e.children?.length && l(e.children[0], t, r + s, !0)) : e.type === "group" ? (t.push(`${r}${n}GROUP`), e.children?.length && l(e.children[0], t, r + s, !0)) : e.children && (t.push(`${r}${n}${e.type}`), e.children.forEach((a, c) => {
|
|
214
214
|
const o = c === e.children.length - 1;
|
package/dist/src/tokenizer.js
CHANGED
|
@@ -26,6 +26,7 @@ const l = [
|
|
|
26
26
|
"regexp",
|
|
27
27
|
"regex",
|
|
28
28
|
"not_regexp",
|
|
29
|
+
"not_regex",
|
|
29
30
|
"matches",
|
|
30
31
|
"not_matches",
|
|
31
32
|
// Range operators
|
|
@@ -68,6 +69,7 @@ const l = [
|
|
|
68
69
|
"!startswith": "not_startswith",
|
|
69
70
|
"!endswith": "not_endswith",
|
|
70
71
|
"!regexp": "not_regexp",
|
|
72
|
+
"!regex": "not_regex",
|
|
71
73
|
"!matches": "not_matches",
|
|
72
74
|
"!between": "not_between",
|
|
73
75
|
"!exists": "not_exists",
|
|
@@ -114,7 +116,7 @@ const l = [
|
|
|
114
116
|
"sum",
|
|
115
117
|
"min",
|
|
116
118
|
"max"
|
|
117
|
-
],
|
|
119
|
+
], _ = [
|
|
118
120
|
// Counting
|
|
119
121
|
"count",
|
|
120
122
|
"unique_count",
|
|
@@ -143,7 +145,7 @@ const l = [
|
|
|
143
145
|
"values",
|
|
144
146
|
"unique",
|
|
145
147
|
"distinct"
|
|
146
|
-
],
|
|
148
|
+
], f = [
|
|
147
149
|
"string",
|
|
148
150
|
"str",
|
|
149
151
|
"number",
|
|
@@ -355,7 +357,7 @@ class g {
|
|
|
355
357
|
*/
|
|
356
358
|
classifyIdentifier(t) {
|
|
357
359
|
const n = t.toUpperCase(), i = t.toLowerCase();
|
|
358
|
-
return d.includes(n) ? "logicalOp" : p.includes(n) ? "collectionOp" : i === "true" || i === "false" ? "boolean" : i === "null" ? "null" : i === "stats" ? "keyword" : l.includes(i) ? "operator" :
|
|
360
|
+
return d.includes(n) ? "logicalOp" : p.includes(n) ? "collectionOp" : i === "true" || i === "false" ? "boolean" : i === "null" ? "null" : i === "stats" ? "keyword" : l.includes(i) ? "operator" : _.includes(i) ? "aggregation" : k.includes(i) ? "mutator" : f.includes(i) ? "typeHint" : m.includes(i) ? "visualization" : w.includes(i) ? "keyword" : "field";
|
|
359
361
|
}
|
|
360
362
|
// ============================================================================
|
|
361
363
|
// Helper Methods
|
|
@@ -440,7 +442,7 @@ function E(o, t, n = !0) {
|
|
|
440
442
|
return e;
|
|
441
443
|
}
|
|
442
444
|
export {
|
|
443
|
-
|
|
445
|
+
_ as AGGREGATION_FUNCTIONS,
|
|
444
446
|
p as COLLECTION_OPERATORS,
|
|
445
447
|
l as COMPARISON_OPERATORS,
|
|
446
448
|
w as KEYWORDS,
|
|
@@ -448,7 +450,7 @@ export {
|
|
|
448
450
|
k as MUTATORS,
|
|
449
451
|
u as NEGATION_SYMBOL_OPERATORS,
|
|
450
452
|
h as SYMBOL_OPERATORS,
|
|
451
|
-
|
|
453
|
+
f as TYPE_HINTS,
|
|
452
454
|
g as TqlTokenizer,
|
|
453
455
|
m as VISUALIZATION_TYPES,
|
|
454
456
|
E as findPreviousToken,
|
package/dist/src/types.d.ts
CHANGED
|
@@ -97,7 +97,7 @@ export interface TqlFieldReference {
|
|
|
97
97
|
start: number;
|
|
98
98
|
end: number;
|
|
99
99
|
}
|
|
100
|
-
export type TqlComparisonOperator = "eq" | "ne" | "=" | "!=" | "==" | "eq_ci" | "gt" | "gte" | "lt" | "lte" | ">" | ">=" | "<" | "<=" | "contains" | "not_contains" | "!contains" | "startswith" | "not_startswith" | "!startswith" | "endswith" | "not_endswith" | "!endswith" | "contains_cs" | "not_contains_cs" | "!contains_cs" | "startswith_cs" | "not_startswith_cs" | "!startswith_cs" | "endswith_cs" | "not_endswith_cs" | "!endswith_cs" | "regexp" | "regex" | "not_regexp" | "!regexp" | "matches" | "not_matches" | "!matches" | "between" | "not_between" | "!between" | "in" | "not_in" | "!in" | "in_cs" | "not_in_cs" | "!in_cs" | "exists" | "not_exists" | "!exists" | "is" | "is_not" | "!is" | "cidr" | "not_cidr" | "!cidr" | "any" | "all" | "none" | "not_any" | "not_all" | "not_none" | "!any" | "!all" | "!none";
|
|
100
|
+
export type TqlComparisonOperator = "eq" | "ne" | "=" | "!=" | "==" | "eq_ci" | "gt" | "gte" | "lt" | "lte" | ">" | ">=" | "<" | "<=" | "contains" | "not_contains" | "!contains" | "startswith" | "not_startswith" | "!startswith" | "endswith" | "not_endswith" | "!endswith" | "contains_cs" | "not_contains_cs" | "!contains_cs" | "startswith_cs" | "not_startswith_cs" | "!startswith_cs" | "endswith_cs" | "not_endswith_cs" | "!endswith_cs" | "regexp" | "regex" | "not_regexp" | "not_regex" | "!regexp" | "!regex" | "matches" | "not_matches" | "!matches" | "between" | "not_between" | "!between" | "in" | "not_in" | "!in" | "in_cs" | "not_in_cs" | "!in_cs" | "exists" | "not_exists" | "!exists" | "is" | "is_not" | "!is" | "cidr" | "not_cidr" | "!cidr" | "any" | "all" | "none" | "not_any" | "not_all" | "not_none" | "!any" | "!all" | "!none";
|
|
101
101
|
export type TqlLogicalOperator = "AND" | "OR" | "NOT";
|
|
102
102
|
export type TqlCollectionOperator = "ANY" | "ALL" | "NONE";
|
|
103
103
|
export type TqlMutator = "lowercase" | "uppercase" | "trim" | "split" | "length" | "replace" | "b64encode" | "b64decode" | "urldecode" | "hexencode" | "hexdecode" | "md5" | "sha256" | "refang" | "defang" | "is_private" | "is_global" | "is_multicast" | "is_loopback" | "is_link_local" | "nslookup" | "geoip_lookup" | "geoip" | "geo" | "any" | "all" | "avg" | "average" | "sum" | "min" | "max";
|
package/dist/src/validator.js
CHANGED
|
@@ -38,7 +38,9 @@ const c = {
|
|
|
38
38
|
regexp: ["text", "keyword"],
|
|
39
39
|
regex: ["text", "keyword"],
|
|
40
40
|
not_regexp: ["text", "keyword"],
|
|
41
|
+
not_regex: ["text", "keyword"],
|
|
41
42
|
"!regexp": ["text", "keyword"],
|
|
43
|
+
"!regex": ["text", "keyword"],
|
|
42
44
|
matches: ["text", "keyword"],
|
|
43
45
|
not_matches: ["text", "keyword"],
|
|
44
46
|
"!matches": ["text", "keyword"],
|
|
@@ -114,7 +116,9 @@ const c = {
|
|
|
114
116
|
regexp: ["string"],
|
|
115
117
|
regex: ["string"],
|
|
116
118
|
not_regexp: ["string"],
|
|
119
|
+
not_regex: ["string"],
|
|
117
120
|
"!regexp": ["string"],
|
|
121
|
+
"!regex": ["string"],
|
|
118
122
|
matches: ["string"],
|
|
119
123
|
not_matches: ["string"],
|
|
120
124
|
"!matches": ["string"],
|
|
@@ -239,7 +243,7 @@ class b {
|
|
|
239
243
|
"TYPE_MISMATCH"
|
|
240
244
|
);
|
|
241
245
|
}
|
|
242
|
-
if ((e.operator === "regexp" || e.operator === "regex" || e.operator === "not_regexp" || e.operator === "matches" || e.operator === "not_matches") && !Array.isArray(e.value) && e.value.valueType === "string" && typeof e.value.value == "string")
|
|
246
|
+
if ((e.operator === "regexp" || e.operator === "regex" || e.operator === "not_regexp" || e.operator === "not_regex" || e.operator === "matches" || e.operator === "not_matches") && !Array.isArray(e.value) && e.value.valueType === "string" && typeof e.value.value == "string")
|
|
243
247
|
try {
|
|
244
248
|
new RegExp(e.value.value);
|
|
245
249
|
} catch {
|
|
@@ -313,7 +317,7 @@ class b {
|
|
|
313
317
|
function d(s, e) {
|
|
314
318
|
return new b(e).validate(s);
|
|
315
319
|
}
|
|
316
|
-
function
|
|
320
|
+
function h(s) {
|
|
317
321
|
return d(s).valid;
|
|
318
322
|
}
|
|
319
323
|
function y(s, e) {
|
|
@@ -334,6 +338,6 @@ export {
|
|
|
334
338
|
b as TqlValidator,
|
|
335
339
|
f as formatValidationResult,
|
|
336
340
|
y as getTqlIssues,
|
|
337
|
-
|
|
341
|
+
h as isValidTqlSyntax,
|
|
338
342
|
d as validateTql
|
|
339
343
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tellaro/tql",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.3",
|
|
4
4
|
"description": "Tellaro Query Language (TQL) parser, validator, and autocomplete for JavaScript/TypeScript",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -120,7 +120,9 @@
|
|
|
120
120
|
"@microsoft/api-extractor": {
|
|
121
121
|
"minimatch": ">=10.2.3"
|
|
122
122
|
},
|
|
123
|
+
"esbuild": ">=0.28.1",
|
|
123
124
|
"flatted": ">=3.4.0",
|
|
124
|
-
"lodash": ">=4.18.0"
|
|
125
|
+
"lodash": ">=4.18.0",
|
|
126
|
+
"postcss": ">=8.5.10"
|
|
125
127
|
}
|
|
126
128
|
}
|