@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,9 @@
1
+ const s = (t, e) => {
2
+ const o = t.__vccOpts || t;
3
+ for (const [r, c] of e)
4
+ o[r] = c;
5
+ return o;
6
+ };
7
+ export {
8
+ s as default
9
+ };
@@ -0,0 +1 @@
1
+ export * from './src/index'
package/dist/index.js ADDED
@@ -0,0 +1,37 @@
1
+ import { AGGREGATION_FUNCTIONS as T, COLLECTION_OPERATORS as r, COMPARISON_OPERATORS as t, KEYWORDS as i, LOGICAL_OPERATORS as O, MUTATORS as l, NEGATION_SYMBOL_OPERATORS as n, SYMBOL_OPERATORS as a, TYPE_HINTS as s, TqlTokenizer as R, VISUALIZATION_TYPES as A, findPreviousToken as S, findTokenAtPosition as E, findTokenBefore as P, findTokensInRange as I, tokenizeTql as d, tokenizeTqlNoWhitespace as f } from "./src/tokenizer.js";
2
+ import { TqlParser as g, formatParseError as N, getTqlErrors as m, isValidTql as p, parseTql as C } from "./src/parser.js";
3
+ import { TqlValidator as k, formatValidationResult as L, getTqlIssues as x, isValidTqlSyntax as G, validateTql as V } from "./src/validator.js";
4
+ import { getCompletionTriggerCharacters as u, getCompletions as M, getWordAtPosition as h, shouldTriggerCompletion as z } from "./src/completionProvider.js";
5
+ export {
6
+ T as AGGREGATION_FUNCTIONS,
7
+ r as COLLECTION_OPERATORS,
8
+ t as COMPARISON_OPERATORS,
9
+ i as KEYWORDS,
10
+ O as LOGICAL_OPERATORS,
11
+ l as MUTATORS,
12
+ n as NEGATION_SYMBOL_OPERATORS,
13
+ a as SYMBOL_OPERATORS,
14
+ s as TYPE_HINTS,
15
+ g as TqlParser,
16
+ R as TqlTokenizer,
17
+ k as TqlValidator,
18
+ A as VISUALIZATION_TYPES,
19
+ S as findPreviousToken,
20
+ E as findTokenAtPosition,
21
+ P as findTokenBefore,
22
+ I as findTokensInRange,
23
+ N as formatParseError,
24
+ L as formatValidationResult,
25
+ u as getCompletionTriggerCharacters,
26
+ M as getCompletions,
27
+ m as getTqlErrors,
28
+ x as getTqlIssues,
29
+ h as getWordAtPosition,
30
+ p as isValidTql,
31
+ G as isValidTqlSyntax,
32
+ C as parseTql,
33
+ z as shouldTriggerCompletion,
34
+ d as tokenizeTql,
35
+ f as tokenizeTqlNoWhitespace,
36
+ V as validateTql
37
+ };
@@ -0,0 +1,22 @@
1
+ import { TqlCompletionContext, TqlCompletionItem, TqlCompletionOptions } from './types';
2
+
3
+ /**
4
+ * Get completions for a TQL query at the cursor position
5
+ */
6
+ export declare function getCompletions(context: TqlCompletionContext, options?: TqlCompletionOptions): TqlCompletionItem[];
7
+ /**
8
+ * Get the word at the cursor position
9
+ */
10
+ export declare function getWordAtPosition(query: string, position: number): {
11
+ word: string;
12
+ start: number;
13
+ end: number;
14
+ } | null;
15
+ /**
16
+ * Get completion trigger characters
17
+ */
18
+ export declare function getCompletionTriggerCharacters(): string[];
19
+ /**
20
+ * Check if completion should be triggered automatically
21
+ */
22
+ export declare function shouldTriggerCompletion(query: string, position: number, triggerChar?: string): boolean;
@@ -0,0 +1,619 @@
1
+ import { tokenizeTql as y, COMPARISON_OPERATORS as k, LOGICAL_OPERATORS as v, AGGREGATION_FUNCTIONS as T, VISUALIZATION_TYPES as C, TYPE_HINTS as O, MUTATORS as N } from "./tokenizer.js";
2
+ const I = [
3
+ {
4
+ label: "Simple equality",
5
+ insertText: 'field eq "value"',
6
+ description: "Basic field equals value comparison",
7
+ category: "Basic"
8
+ },
9
+ {
10
+ label: "Contains search",
11
+ insertText: 'field contains "text"',
12
+ description: "Search for text within a field",
13
+ category: "Basic"
14
+ },
15
+ {
16
+ label: "Multiple conditions (AND)",
17
+ insertText: 'field1 eq "value1" AND field2 eq "value2"',
18
+ description: "Combine conditions with AND",
19
+ category: "Logical"
20
+ },
21
+ {
22
+ label: "Multiple conditions (OR)",
23
+ insertText: 'field1 eq "value1" OR field2 eq "value2"',
24
+ description: "Match either condition with OR",
25
+ category: "Logical"
26
+ },
27
+ {
28
+ label: "Negation",
29
+ insertText: 'NOT field eq "value"',
30
+ description: "Negate a condition",
31
+ category: "Logical"
32
+ },
33
+ {
34
+ label: "Field exists",
35
+ insertText: "field exists",
36
+ description: "Check if field has a value",
37
+ category: "Existence"
38
+ },
39
+ {
40
+ label: "Value in list",
41
+ insertText: 'field in ["value1", "value2", "value3"]',
42
+ description: "Match any value in a list",
43
+ category: "List"
44
+ },
45
+ {
46
+ label: "Value not in list",
47
+ insertText: 'field not_in ["value1", "value2"]',
48
+ description: "Exclude values in a list",
49
+ category: "List"
50
+ },
51
+ {
52
+ label: "Range (between)",
53
+ insertText: "field between 10 AND 100",
54
+ description: "Match values in a range",
55
+ category: "Range"
56
+ },
57
+ {
58
+ label: "Starts with",
59
+ insertText: 'field startswith "prefix"',
60
+ description: "Match fields starting with text",
61
+ category: "String"
62
+ },
63
+ {
64
+ label: "Regular expression",
65
+ insertText: 'field regexp "pattern.*"',
66
+ description: "Match using regex pattern",
67
+ category: "String"
68
+ },
69
+ {
70
+ label: "CIDR IP match",
71
+ insertText: 'source.ip cidr "192.168.0.0/24"',
72
+ description: "Match IP addresses in a CIDR range",
73
+ category: "Network"
74
+ },
75
+ {
76
+ label: "With mutator",
77
+ insertText: 'email | lowercase eq "test@example.com"',
78
+ description: "Apply mutator before comparison",
79
+ category: "Mutator"
80
+ },
81
+ {
82
+ label: "GeoIP lookup",
83
+ insertText: "source.ip | geoip_lookup",
84
+ description: "Enrich IP with geolocation data",
85
+ category: "Enrichment"
86
+ },
87
+ {
88
+ label: "Stats count by field",
89
+ insertText: "| stats count() by hostname",
90
+ description: "Count events grouped by field",
91
+ category: "Stats"
92
+ },
93
+ {
94
+ label: "Stats with visualization",
95
+ insertText: "| stats count() by status => bar",
96
+ description: "Stats with chart visualization",
97
+ category: "Stats"
98
+ },
99
+ {
100
+ label: "Stats top N",
101
+ insertText: "| stats count() by source.ip top 10",
102
+ description: "Top 10 results by count",
103
+ category: "Stats"
104
+ }
105
+ ], A = {
106
+ eq: { detail: "Equals", documentation: "Exact match comparison" },
107
+ ne: { detail: "Not equals", documentation: "Match any value except this one" },
108
+ gt: { detail: "Greater than", documentation: "Numeric/date comparison" },
109
+ gte: { detail: "Greater than or equal", documentation: "Numeric/date comparison" },
110
+ lt: { detail: "Less than", documentation: "Numeric/date comparison" },
111
+ lte: { detail: "Less than or equal", documentation: "Numeric/date comparison" },
112
+ contains: { detail: "Contains substring", documentation: "Case-insensitive substring match" },
113
+ not_contains: { detail: "Does not contain", documentation: "Negative substring match" },
114
+ startswith: { detail: "Starts with", documentation: "Match prefix of field value" },
115
+ not_startswith: { detail: "Does not start with", documentation: "Negative prefix match" },
116
+ endswith: { detail: "Ends with", documentation: "Match suffix of field value" },
117
+ not_endswith: { detail: "Does not end with", documentation: "Negative suffix match" },
118
+ regexp: { detail: "Regular expression", documentation: "Match using regex pattern" },
119
+ regex: { detail: "Regular expression", documentation: "Alias for regexp" },
120
+ not_regexp: { detail: "Not matching regex", documentation: "Negative regex match" },
121
+ matches: { detail: "Pattern match", documentation: "Match using pattern" },
122
+ not_matches: { detail: "Not matching pattern", documentation: "Negative pattern match" },
123
+ between: { detail: "Between range", documentation: "Usage: field between A AND B" },
124
+ not_between: { detail: "Not between range", documentation: "Exclude values in range" },
125
+ in: { detail: "In list", documentation: 'Usage: field in ["a", "b", "c"]' },
126
+ not_in: { detail: "Not in list", documentation: "Exclude values in list" },
127
+ exists: { detail: "Field exists", documentation: "Check if field has any value" },
128
+ not_exists: { detail: "Field not exists", documentation: "Check if field is missing or null" },
129
+ is: { detail: "Is null check", documentation: "Usage: field is null" },
130
+ is_not: { detail: "Is not null check", documentation: "Usage: field is_not null" },
131
+ cidr: { detail: "CIDR match", documentation: "Match IP addresses in CIDR range (IP fields only)" },
132
+ not_cidr: { detail: "Not in CIDR", documentation: "Exclude IPs in CIDR range" },
133
+ any: { detail: "Any element matches", documentation: "True if any array element matches" },
134
+ all: { detail: "All elements match", documentation: "True if all array elements match" },
135
+ none: { detail: "No elements match", documentation: "True if no array elements match" },
136
+ not_any: { detail: "Not any matches", documentation: "Negation of any" },
137
+ not_all: { detail: "Not all match", documentation: "Negation of all" },
138
+ not_none: { detail: "Not none match", documentation: "Negation of none" }
139
+ }, L = {
140
+ lowercase: { detail: "Convert to lowercase", documentation: "Transform string to lowercase" },
141
+ uppercase: { detail: "Convert to uppercase", documentation: "Transform string to uppercase" },
142
+ trim: { detail: "Trim whitespace", documentation: "Remove leading/trailing whitespace" },
143
+ split: { detail: "Split string", documentation: "Split string into array. Usage: split(delimiter)" },
144
+ length: { detail: "Get length", documentation: "Returns string/array length as number" },
145
+ replace: { detail: "Replace text", documentation: "Replace substring. Usage: replace(find, replace)" },
146
+ b64encode: { detail: "Base64 encode", documentation: "Encode value to Base64" },
147
+ b64decode: { detail: "Base64 decode", documentation: "Decode Base64 to string" },
148
+ urldecode: { detail: "URL decode", documentation: "Decode URL-encoded string" },
149
+ hexencode: { detail: "Hex encode", documentation: "Encode to hexadecimal" },
150
+ hexdecode: { detail: "Hex decode", documentation: "Decode from hexadecimal" },
151
+ md5: { detail: "MD5 hash", documentation: "Calculate MD5 hash" },
152
+ sha256: { detail: "SHA256 hash", documentation: "Calculate SHA256 hash" },
153
+ refang: { detail: "Refang IOC", documentation: "Convert defanged URL/IP to normal form" },
154
+ defang: { detail: "Defang IOC", documentation: "Convert URL/IP to safe defanged form" },
155
+ is_private: { detail: "Is private IP", documentation: "Check if IP is RFC1918/private" },
156
+ is_global: { detail: "Is global IP", documentation: "Check if IP is globally routable" },
157
+ nslookup: { detail: "DNS lookup", documentation: "Perform DNS lookup on hostname/IP" },
158
+ geoip_lookup: { detail: "GeoIP lookup", documentation: "Get geolocation data for IP" },
159
+ geoip: { detail: "GeoIP lookup", documentation: "Alias for geoip_lookup" },
160
+ geo: { detail: "GeoIP lookup", documentation: "Alias for geoip_lookup with conditions" },
161
+ any: { detail: "Any truthy", documentation: "True if any array element is truthy" },
162
+ all: { detail: "All truthy", documentation: "True if all array elements are truthy" },
163
+ avg: { detail: "Average", documentation: "Calculate average of numeric array" },
164
+ average: { detail: "Average", documentation: "Alias for avg" },
165
+ sum: { detail: "Sum", documentation: "Sum of numeric array elements" },
166
+ min: { detail: "Minimum", documentation: "Minimum value in array" },
167
+ max: { detail: "Maximum", documentation: "Maximum value in array" }
168
+ }, m = {
169
+ // String outputs
170
+ lowercase: "keyword",
171
+ uppercase: "keyword",
172
+ trim: "keyword",
173
+ replace: "keyword",
174
+ b64encode: "keyword",
175
+ b64decode: "keyword",
176
+ urldecode: "keyword",
177
+ hexencode: "keyword",
178
+ hexdecode: "keyword",
179
+ md5: "keyword",
180
+ sha256: "keyword",
181
+ refang: "keyword",
182
+ defang: "keyword",
183
+ nslookup: "keyword",
184
+ // Boolean outputs
185
+ is_private: "boolean",
186
+ is_global: "boolean",
187
+ any: "boolean",
188
+ all: "boolean",
189
+ // Number outputs
190
+ length: "long",
191
+ avg: "double",
192
+ average: "double",
193
+ sum: "double",
194
+ min: "double",
195
+ max: "double",
196
+ // Object outputs
197
+ geoip_lookup: "object",
198
+ geoip: "object",
199
+ geo: "object",
200
+ // Array output (returns array of strings)
201
+ split: "keyword"
202
+ }, S = {
203
+ // Universal operators (work with all types)
204
+ eq: ["text", "keyword", "long", "integer", "double", "float", "date", "boolean", "ip"],
205
+ ne: ["text", "keyword", "long", "integer", "double", "float", "date", "boolean", "ip"],
206
+ exists: ["text", "keyword", "long", "integer", "double", "float", "date", "boolean", "ip", "nested", "object"],
207
+ not_exists: ["text", "keyword", "long", "integer", "double", "float", "date", "boolean", "ip", "nested", "object"],
208
+ is: ["text", "keyword", "long", "integer", "double", "float", "date", "boolean", "ip"],
209
+ is_not: ["text", "keyword", "long", "integer", "double", "float", "date", "boolean", "ip"],
210
+ in: ["text", "keyword", "long", "integer", "double", "float", "date", "boolean", "ip"],
211
+ not_in: ["text", "keyword", "long", "integer", "double", "float", "date", "boolean", "ip"],
212
+ // Comparison operators (numeric + date only)
213
+ gt: ["long", "integer", "double", "float", "date"],
214
+ gte: ["long", "integer", "double", "float", "date"],
215
+ lt: ["long", "integer", "double", "float", "date"],
216
+ lte: ["long", "integer", "double", "float", "date"],
217
+ between: ["long", "integer", "double", "float", "date"],
218
+ not_between: ["long", "integer", "double", "float", "date"],
219
+ // String operators (text/keyword only)
220
+ contains: ["text", "keyword"],
221
+ not_contains: ["text", "keyword"],
222
+ startswith: ["text", "keyword"],
223
+ not_startswith: ["text", "keyword"],
224
+ endswith: ["text", "keyword"],
225
+ not_endswith: ["text", "keyword"],
226
+ regexp: ["text", "keyword"],
227
+ regex: ["text", "keyword"],
228
+ not_regexp: ["text", "keyword"],
229
+ matches: ["text", "keyword"],
230
+ not_matches: ["text", "keyword"],
231
+ // IP-specific operators
232
+ cidr: ["ip"],
233
+ not_cidr: ["ip"],
234
+ // Collection operators
235
+ any: ["nested", "object", "keyword"],
236
+ all: ["nested", "object", "keyword"],
237
+ none: ["nested", "object", "keyword"]
238
+ };
239
+ function R(e, t, n) {
240
+ var u;
241
+ const o = y(e.substring(0, t)).filter((s) => s.type !== "whitespace");
242
+ if (o.length === 0)
243
+ return { type: "start" };
244
+ const a = o[o.length - 1], r = o.length > 1 ? o[o.length - 2] : null, d = a.end === t && !((u = e[t - 1]) != null && u.match(/\s/)), l = d ? a.value : void 0;
245
+ if (a.type === "logicalOp")
246
+ return { type: "start" };
247
+ if (a.type === "paren" && a.value === "(")
248
+ return { type: "after_paren" };
249
+ if (a.type === "arrow")
250
+ return { type: "after_arrow", partialText: l };
251
+ if (a.type === "doubleColon")
252
+ return { type: "after_double_colon", partialText: l };
253
+ if (a.type === "visualization" && d)
254
+ return { type: "after_arrow", partialText: l };
255
+ if (a.type === "typeHint" && d)
256
+ return { type: "after_double_colon", partialText: l };
257
+ if (a.type === "keyword" && a.value.toLowerCase() === "stats")
258
+ return { type: "after_stats", partialText: l };
259
+ if (a.type === "keyword" && a.value.toLowerCase() === "by")
260
+ return { type: "after_by", partialText: l };
261
+ if (a.type === "pipe")
262
+ return { type: "after_pipe", partialText: l };
263
+ if (a.type === "mutator") {
264
+ if (d)
265
+ return { type: "after_pipe", partialText: l };
266
+ const s = a.value.toLowerCase(), c = m[s];
267
+ return {
268
+ type: "after_mutator",
269
+ mutatorName: s,
270
+ mutatorOutputType: c
271
+ };
272
+ }
273
+ if (a.type === "aggregation")
274
+ return d ? { type: "after_stats", partialText: l } : { type: "after_value" };
275
+ if (a.type === "field") {
276
+ if (d)
277
+ return (r == null ? void 0 : r.type) === "pipe" ? { type: "after_pipe", partialText: l } : { type: "start", partialText: l };
278
+ if ((r == null ? void 0 : r.type) === "pipe")
279
+ return { type: "after_pipe", partialText: a.value };
280
+ const s = p(a.value, n);
281
+ return { type: "after_field", fieldName: a.value, fieldType: s };
282
+ }
283
+ if (a.type === "operator") {
284
+ if (d) {
285
+ if ((r == null ? void 0 : r.type) === "field") {
286
+ const s = p(r.value, n);
287
+ return { type: "after_field", fieldName: r.value, fieldType: s, partialText: l };
288
+ }
289
+ if ((r == null ? void 0 : r.type) === "mutator") {
290
+ const s = r.value.toLowerCase(), c = m[s];
291
+ return { type: "after_mutator", mutatorName: s, mutatorOutputType: c, partialText: l };
292
+ }
293
+ }
294
+ return { type: "after_operator", operatorName: a.value };
295
+ }
296
+ if (a.type === "string" || a.type === "number" || a.type === "boolean" || a.type === "null")
297
+ return { type: "after_value" };
298
+ if (a.type === "paren" && a.value === ")")
299
+ return { type: "after_value" };
300
+ if ((r == null ? void 0 : r.type) === "field" && d) {
301
+ const s = p(r.value, n);
302
+ return { type: "after_field", fieldName: r.value, fieldType: s, partialText: l };
303
+ }
304
+ if ((r == null ? void 0 : r.type) === "mutator" && d) {
305
+ const s = r.value.toLowerCase(), c = m[s];
306
+ return { type: "after_mutator", mutatorName: s, mutatorOutputType: c, partialText: l };
307
+ }
308
+ return { type: "unknown", partialText: l };
309
+ }
310
+ function p(e, t) {
311
+ if (!t) return;
312
+ const n = t.find((i) => i.name === e);
313
+ return n == null ? void 0 : n.type;
314
+ }
315
+ function B(e, t = {}) {
316
+ const { query: n, cursorPosition: i } = e, o = R(n, i, t.fields), a = [];
317
+ switch (o.type) {
318
+ case "start":
319
+ case "after_paren":
320
+ a.push(...f(t.fields, o.partialText)), a.push(_("NOT")), t.includeSnippets !== !1 && a.push(...E(t, o.partialText));
321
+ break;
322
+ case "after_field":
323
+ a.push(...g(o.partialText, o.fieldType));
324
+ break;
325
+ case "after_mutator":
326
+ a.push(...g(o.partialText, o.mutatorOutputType));
327
+ break;
328
+ case "after_operator":
329
+ a.push(...D(o.fieldName, t));
330
+ break;
331
+ case "after_value":
332
+ a.push(...x());
333
+ break;
334
+ case "after_pipe":
335
+ a.push(...M(o.partialText));
336
+ break;
337
+ case "after_double_colon":
338
+ a.push(...U(o.partialText));
339
+ break;
340
+ case "after_arrow":
341
+ a.push(...q(o.partialText));
342
+ break;
343
+ case "after_stats":
344
+ a.push(...w(o.partialText));
345
+ break;
346
+ case "after_by":
347
+ a.push(...f(t.fields, o.partialText));
348
+ break;
349
+ default:
350
+ a.push(...f(t.fields, o.partialText)), a.push(...g(o.partialText)), a.push(...x());
351
+ }
352
+ t.includeAggregations && o.type === "start" && a.push(...w(o.partialText));
353
+ let r = a;
354
+ if (o.partialText) {
355
+ const d = o.partialText.toLowerCase();
356
+ r = a.filter(
357
+ (l) => {
358
+ var u;
359
+ return l.label.toLowerCase().includes(d) || ((u = l.filterText) == null ? void 0 : u.toLowerCase().includes(d));
360
+ }
361
+ );
362
+ }
363
+ return r.sort((d, l) => d.sortOrder - l.sortOrder), t.maxItems && t.maxItems > 0 && (r = r.slice(0, t.maxItems)), r;
364
+ }
365
+ function f(e, t) {
366
+ if (!e || e.length === 0)
367
+ return $(t);
368
+ const n = [];
369
+ for (const i of e) {
370
+ const o = h(i);
371
+ if (n.push(o), i.nested)
372
+ for (const a of i.nested) {
373
+ const r = h(a, i.name);
374
+ n.push(r);
375
+ }
376
+ }
377
+ return n;
378
+ }
379
+ function $(e) {
380
+ return [
381
+ { name: "hostname", description: "Host/machine name" },
382
+ { name: "status", description: "Status value" },
383
+ { name: "severity", description: "Severity level" },
384
+ { name: "source", description: "Event source" },
385
+ { name: "source.ip", description: "Source IP address" },
386
+ { name: "destination.ip", description: "Destination IP address" },
387
+ { name: "tags", description: "Associated tags" },
388
+ { name: "@timestamp", description: "Event timestamp" },
389
+ { name: "message", description: "Message content" },
390
+ { name: "user.name", description: "User name" },
391
+ { name: "os.family", description: "Operating system family" },
392
+ { name: "os.type", description: "Operating system type" },
393
+ { name: "os.version", description: "Operating system version" },
394
+ { name: "customer", description: "Customer identifier" },
395
+ { name: "stack", description: "Stack identifier" }
396
+ ].filter((n) => !e || n.name.toLowerCase().includes(e.toLowerCase())).map((n) => ({
397
+ label: n.name,
398
+ insertText: n.name,
399
+ kind: "field",
400
+ detail: n.description,
401
+ sortOrder: 10
402
+ }));
403
+ }
404
+ function h(e, t) {
405
+ const n = t ? `${t}.${e.name}` : e.name;
406
+ return {
407
+ label: n,
408
+ insertText: n,
409
+ kind: "field",
410
+ detail: e.description || `Type: ${e.type}`,
411
+ documentation: e.examples ? `Examples: ${e.examples.join(", ")}` : void 0,
412
+ sortOrder: 10
413
+ };
414
+ }
415
+ function g(e, t) {
416
+ let n = [...k];
417
+ return t && (n = n.filter((i) => {
418
+ const o = S[i];
419
+ return !o || o.includes(t);
420
+ })), e && (n = n.filter((i) => i.toLowerCase().includes(e.toLowerCase()))), n.map((i, o) => {
421
+ const a = A[i] || { detail: i, documentation: "" }, r = P(i, t);
422
+ return {
423
+ label: i,
424
+ insertText: r,
425
+ kind: "operator",
426
+ detail: a.detail,
427
+ documentation: a.documentation,
428
+ sortOrder: 20 + o
429
+ };
430
+ });
431
+ }
432
+ function P(e, t) {
433
+ const n = [
434
+ "contains",
435
+ "not_contains",
436
+ "startswith",
437
+ "not_startswith",
438
+ "endswith",
439
+ "not_endswith",
440
+ "regexp",
441
+ "regex",
442
+ "not_regexp",
443
+ "matches",
444
+ "not_matches"
445
+ ], i = ["exists", "not_exists"], o = ["is", "is_not"];
446
+ if (e === "in" || e === "not_in")
447
+ return b(t) ? `${e} [$1]` : `${e} ["$1"]`;
448
+ if (e === "between" || e === "not_between")
449
+ return b(t) ? `${e} $1 AND $2` : `${e} "$1" AND "$2"`;
450
+ if (o.includes(e))
451
+ return `${e} null`;
452
+ if (i.includes(e))
453
+ return e;
454
+ if (e === "cidr" || e === "not_cidr")
455
+ return `${e} "$1"`;
456
+ if (n.includes(e))
457
+ return `${e} "$1"`;
458
+ if (!t)
459
+ return `${e} `;
460
+ switch (t) {
461
+ case "text":
462
+ case "keyword":
463
+ return `${e} "$1"`;
464
+ case "boolean":
465
+ return `${e} $1`;
466
+ case "long":
467
+ case "integer":
468
+ case "double":
469
+ case "float":
470
+ return `${e} $1`;
471
+ case "date":
472
+ return `${e} "$1"`;
473
+ case "ip":
474
+ return `${e} "$1"`;
475
+ default:
476
+ return `${e} `;
477
+ }
478
+ }
479
+ function b(e) {
480
+ return e === "long" || e === "integer" || e === "double" || e === "float" || e === "short" || e === "byte" || e === "half_float" || e === "scaled_float" || e === "unsigned_long";
481
+ }
482
+ function x() {
483
+ return v.filter((e) => e !== "NOT").map(
484
+ (e, t) => _(e, t)
485
+ );
486
+ }
487
+ function _(e, t = 0) {
488
+ return {
489
+ label: e,
490
+ insertText: e + " ",
491
+ kind: "logicalOp",
492
+ detail: e === "AND" ? "Both conditions must match" : e === "OR" ? "Either condition can match" : "Negate the condition",
493
+ sortOrder: 30 + t
494
+ };
495
+ }
496
+ function D(e, t) {
497
+ var i;
498
+ const n = [];
499
+ return e && ((i = t == null ? void 0 : t.fieldValues) != null && i[e]) && t.fieldValues[e].forEach((a, r) => {
500
+ n.push({
501
+ label: a,
502
+ insertText: `"${a}"`,
503
+ kind: "value",
504
+ detail: `Known value for ${e}`,
505
+ sortOrder: 40 + r
506
+ });
507
+ }), n.push(
508
+ {
509
+ label: '"text"',
510
+ insertText: '"$1"',
511
+ kind: "value",
512
+ detail: "String value",
513
+ sortOrder: 50
514
+ },
515
+ {
516
+ label: "123",
517
+ insertText: "0",
518
+ kind: "value",
519
+ detail: "Numeric value",
520
+ sortOrder: 51
521
+ },
522
+ {
523
+ label: "true/false",
524
+ insertText: "true",
525
+ kind: "value",
526
+ detail: "Boolean value",
527
+ sortOrder: 52
528
+ },
529
+ {
530
+ label: "null",
531
+ insertText: "null",
532
+ kind: "value",
533
+ detail: "Null value",
534
+ sortOrder: 53
535
+ }
536
+ ), n;
537
+ }
538
+ function E(e, t) {
539
+ return I.filter((i) => !t || i.label.toLowerCase().includes(t.toLowerCase())).map((i, o) => ({
540
+ label: i.label,
541
+ insertText: i.insertText,
542
+ kind: "snippet",
543
+ detail: i.description,
544
+ documentation: `Insert: ${i.insertText}`,
545
+ sortOrder: 100 + o
546
+ }));
547
+ }
548
+ function M(e) {
549
+ return N.filter((t) => !e || t.toLowerCase().includes(e.toLowerCase())).map(
550
+ (t, n) => {
551
+ const i = L[t] || { detail: "Field mutator", documentation: "" };
552
+ return {
553
+ label: t,
554
+ insertText: t,
555
+ kind: "mutator",
556
+ detail: i.detail,
557
+ documentation: i.documentation,
558
+ sortOrder: 60 + n
559
+ };
560
+ }
561
+ );
562
+ }
563
+ function w(e) {
564
+ return T.filter(
565
+ (t) => !e || t.toLowerCase().includes(e.toLowerCase())
566
+ ).map((t, n) => ({
567
+ label: t,
568
+ insertText: `${t}($1)`,
569
+ kind: "aggregation",
570
+ detail: "Aggregation function",
571
+ sortOrder: 70 + n
572
+ }));
573
+ }
574
+ function U(e) {
575
+ return O.filter(
576
+ (t) => !e || t.toLowerCase().includes(e.toLowerCase())
577
+ ).map((t, n) => ({
578
+ label: t,
579
+ insertText: t,
580
+ kind: "typeHint",
581
+ detail: "Type hint",
582
+ sortOrder: 80 + n
583
+ }));
584
+ }
585
+ function q(e) {
586
+ return C.filter(
587
+ (t) => !e || t.toLowerCase().includes(e.toLowerCase())
588
+ ).map((t, n) => ({
589
+ label: t,
590
+ insertText: t,
591
+ kind: "visualization",
592
+ detail: "Visualization type",
593
+ sortOrder: 90 + n
594
+ }));
595
+ }
596
+ function G(e, t) {
597
+ const i = y(e).find(
598
+ (o) => o.start <= t && o.end >= t && o.type !== "whitespace"
599
+ );
600
+ return i ? {
601
+ word: i.value,
602
+ start: i.start,
603
+ end: i.end
604
+ } : null;
605
+ }
606
+ function V() {
607
+ return [" ", "(", ".", '"', "'", "|", ":", "="];
608
+ }
609
+ function j(e, t, n) {
610
+ if (n === " " || n === "(" || n === "." || n === "|" || n === ":" || n === "=") return !0;
611
+ const i = y(e.substring(0, t)), o = i[i.length - 1];
612
+ return !!(o && o.type === "field" && o.value.length >= 2);
613
+ }
614
+ export {
615
+ V as getCompletionTriggerCharacters,
616
+ B as getCompletions,
617
+ G as getWordAtPosition,
618
+ j as shouldTriggerCompletion
619
+ };