@tellaro/tql 1.4.3 → 2.0.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.
@@ -1,7 +1,8 @@
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
- import { fuzzyMatch as w } from "./fuzzyMatcher.js";
3
- import { getSchemaCache as $ } from "./schemaCache.js";
4
- const P = [
1
+ import { BOOLEAN_PREDICATE_MUTATORS as L, tokenizeTql as T, COMPARISON_OPERATORS as E, LOGICAL_OPERATORS as R, AGGREGATION_FUNCTIONS as P, VISUALIZATION_TYPES as $, TYPE_HINTS as D, MUTATORS as M } from "./tokenizer.js";
2
+ import { fuzzyMatch as _ } from "./fuzzyMatcher.js";
3
+ import { getSchemaCache as S } from "./schemaCache.js";
4
+ import { ALL_FIELD_TYPES as u, BETWEEN_FIELD_TYPES as w, ORDERED_FIELD_TYPES as f } from "./validator.js";
5
+ const z = [
5
6
  {
6
7
  label: "Simple equality",
7
8
  insertText: 'field eq "value"',
@@ -104,13 +105,25 @@ const P = [
104
105
  description: "Top 10 results by count",
105
106
  category: "Stats"
106
107
  }
107
- ], D = {
108
+ ], U = {
108
109
  eq: { detail: "Equals", documentation: "Exact match comparison" },
109
110
  ne: { detail: "Not equals", documentation: "Match any value except this one" },
110
- gt: { detail: "Greater than", documentation: "Numeric/date comparison" },
111
- gte: { detail: "Greater than or equal", documentation: "Numeric/date comparison" },
112
- lt: { detail: "Less than", documentation: "Numeric/date comparison" },
113
- lte: { detail: "Less than or equal", documentation: "Numeric/date comparison" },
111
+ gt: {
112
+ detail: "Greater than",
113
+ documentation: "Ordered comparison. Numbers and dates compare numerically; two STRINGS compare lexicographically. An array-valued field matches if ANY element does."
114
+ },
115
+ gte: {
116
+ detail: "Greater than or equal",
117
+ documentation: "Ordered comparison. Numbers and dates compare numerically; two STRINGS compare lexicographically. An array-valued field matches if ANY element does."
118
+ },
119
+ lt: {
120
+ detail: "Less than",
121
+ documentation: "Ordered comparison. Numbers and dates compare numerically; two STRINGS compare lexicographically. An array-valued field matches if ANY element does."
122
+ },
123
+ lte: {
124
+ detail: "Less than or equal",
125
+ documentation: "Ordered comparison. Numbers and dates compare numerically; two STRINGS compare lexicographically. An array-valued field matches if ANY element does."
126
+ },
114
127
  contains: { detail: "Contains substring", documentation: "Case-insensitive substring match" },
115
128
  not_contains: { detail: "Does not contain", documentation: "Negative substring match" },
116
129
  startswith: { detail: "Starts with", documentation: "Match prefix of field value" },
@@ -123,23 +136,47 @@ const P = [
123
136
  not_regex: { detail: "Not matching regex", documentation: "Alias for not_regexp" },
124
137
  matches: { detail: "Pattern match", documentation: "Match using pattern" },
125
138
  not_matches: { detail: "Not matching pattern", documentation: "Negative pattern match" },
126
- between: { detail: "Between range", documentation: "Usage: field between A AND B" },
139
+ between: {
140
+ detail: "Between range",
141
+ documentation: "Inclusive range. Usage: field between A AND B, or field between [A, B]. Numeric bounds compare numerically; STRING bounds compare lexicographically, matching the range query this becomes on a keyword field."
142
+ },
127
143
  not_between: { detail: "Not between range", documentation: "Exclude values in range" },
128
144
  in: { detail: "In list", documentation: 'Usage: field in ["a", "b", "c"]' },
129
145
  not_in: { detail: "Not in list", documentation: "Exclude values in list" },
130
- exists: { detail: "Field exists", documentation: "Check if field has any value" },
131
- not_exists: { detail: "Field not exists", documentation: "Check if field is missing or null" },
132
- is: { detail: "Is null check", documentation: "Usage: field is null" },
133
- is_not: { detail: "Is not null check", documentation: "Usage: field is_not null" },
146
+ exists: {
147
+ detail: "Field exists",
148
+ documentation: "Field HAS A VALUE. An empty array [] counts as present."
149
+ },
150
+ not_exists: {
151
+ detail: "Field not exists",
152
+ documentation: "Field HAS NO VALUE — absent, or present and explicitly null. Identical to `field is null`. An empty array [] does NOT satisfy it."
153
+ },
154
+ is: {
155
+ detail: "Is null check",
156
+ documentation: "Usage: field is null. Means the field HAS NO VALUE — absent, OR present and explicitly null — so it is identical to `field not exists`. An empty array [] is a PRESENT value and does not satisfy it."
157
+ },
158
+ is_not: {
159
+ detail: "Is not null check",
160
+ documentation: "Usage: field is_not null (or `field is not null`). The exact complement of `is null`, and identical to `field exists`."
161
+ },
134
162
  cidr: { detail: "CIDR match", documentation: "Match IP addresses in CIDR range (IP fields only)" },
135
163
  not_cidr: { detail: "Not in CIDR", documentation: "Exclude IPs in CIDR range" },
136
- any: { detail: "Any element matches", documentation: "True if any array element matches" },
137
- all: { detail: "All elements match", documentation: "True if all array elements match" },
138
- none: { detail: "No elements match", documentation: "True if no array elements match" },
164
+ any: {
165
+ detail: "Any element matches",
166
+ documentation: "True if any element matches. A SCALAR field is treated as a one-element collection, so `any` works on non-array fields too."
167
+ },
168
+ all: {
169
+ detail: "All elements match",
170
+ documentation: "True if every element matches. A scalar field is treated as a one-element collection."
171
+ },
172
+ none: {
173
+ detail: "No elements match",
174
+ documentation: "True if no element matches. A scalar field is treated as a one-element collection."
175
+ },
139
176
  not_any: { detail: "Not any matches", documentation: "Negation of any" },
140
177
  not_all: { detail: "Not all match", documentation: "Negation of all" },
141
178
  not_none: { detail: "Not none match", documentation: "Negation of none" }
142
- }, M = {
179
+ }, F = {
143
180
  lowercase: { detail: "Convert to lowercase", documentation: "Transform string to lowercase" },
144
181
  uppercase: { detail: "Convert to uppercase", documentation: "Transform string to uppercase" },
145
182
  trim: { detail: "Trim whitespace", documentation: "Remove leading/trailing whitespace" },
@@ -155,8 +192,14 @@ const P = [
155
192
  sha256: { detail: "SHA256 hash", documentation: "Calculate SHA256 hash" },
156
193
  refang: { detail: "Refang IOC", documentation: "Convert defanged URL/IP to normal form" },
157
194
  defang: { detail: "Defang IOC", documentation: "Convert URL/IP to safe defanged form" },
158
- is_private: { detail: "Is private IP", documentation: "Check if IP is RFC1918/private" },
159
- is_global: { detail: "Is global IP", documentation: "Check if IP is globally routable" },
195
+ is_private: {
196
+ detail: "Is private IP",
197
+ documentation: "True if the IP is not globally reachable: RFC1918, loopback, link-local, IPv6 ULA, TEST-NET-1/2/3, benchmarking (198.18/15), class E (240/4) and 2001:db8::/32. NOT true for CGNAT 100.64/10, which is neither private nor global."
198
+ },
199
+ is_global: {
200
+ detail: "Is global IP",
201
+ documentation: "True only if the IP is genuinely routable. Not the inverse of is_private: CGNAT 100.64/10 and multicast are neither private nor global."
202
+ },
160
203
  nslookup: { detail: "DNS lookup", documentation: "Perform DNS lookup on hostname/IP" },
161
204
  geoip_lookup: { detail: "GeoIP lookup", documentation: "Get geolocation data for IP" },
162
205
  geoip: { detail: "GeoIP lookup", documentation: "Alias for geoip_lookup" },
@@ -168,7 +211,7 @@ const P = [
168
211
  sum: { detail: "Sum", documentation: "Sum of numeric array elements" },
169
212
  min: { detail: "Minimum", documentation: "Minimum value in array" },
170
213
  max: { detail: "Maximum", documentation: "Maximum value in array" }
171
- }, h = {
214
+ }, g = {
172
215
  // String outputs
173
216
  lowercase: "keyword",
174
217
  uppercase: "keyword",
@@ -185,8 +228,20 @@ const P = [
185
228
  defang: "keyword",
186
229
  nslookup: "keyword",
187
230
  // Boolean outputs
188
- is_private: "boolean",
189
- is_global: "boolean",
231
+ //
232
+ // SPREAD, not listed. This table used to name `is_private` and `is_global` by hand and
233
+ // stop there, so `is_loopback`, `is_multicast` and `is_link_local` — the three predicates
234
+ // added later — fell through to no declared output type and were offered the operator set
235
+ // for an unknown field. That is the identical omission Python made in three copies of its
236
+ // predicate list, and the reason both engines now derive the set instead of writing it out.
237
+ // There is exactly one JS copy, in `tokenizer.ts`, pinned against both engines by
238
+ // `tests/booleanPredicateSugar.spec.ts`.
239
+ ...Object.fromEntries(
240
+ L.map((e) => [e, "boolean"])
241
+ ),
242
+ // `any` and `all` are collection OPERATORS rather than predicates — absent from both
243
+ // engines' predicate sets, and not eligible for the `field | <name>` filter sugar — so
244
+ // they are declared here and not folded into the set above.
190
245
  any: "boolean",
191
246
  all: "boolean",
192
247
  // Number outputs
@@ -202,23 +257,32 @@ const P = [
202
257
  geo: "object",
203
258
  // Array output (returns array of strings)
204
259
  split: "keyword"
205
- }, z = {
206
- // Universal operators (work with all types)
207
- eq: ["text", "keyword", "long", "integer", "double", "float", "date", "boolean", "ip"],
208
- ne: ["text", "keyword", "long", "integer", "double", "float", "date", "boolean", "ip"],
209
- exists: ["text", "keyword", "long", "integer", "double", "float", "date", "boolean", "ip", "nested", "object"],
210
- not_exists: ["text", "keyword", "long", "integer", "double", "float", "date", "boolean", "ip", "nested", "object"],
211
- is: ["text", "keyword", "long", "integer", "double", "float", "date", "boolean", "ip"],
212
- is_not: ["text", "keyword", "long", "integer", "double", "float", "date", "boolean", "ip"],
213
- in: ["text", "keyword", "long", "integer", "double", "float", "date", "boolean", "ip"],
214
- not_in: ["text", "keyword", "long", "integer", "double", "float", "date", "boolean", "ip"],
215
- // Comparison operators (numeric + date only)
216
- gt: ["long", "integer", "double", "float", "date"],
217
- gte: ["long", "integer", "double", "float", "date"],
218
- lt: ["long", "integer", "double", "float", "date"],
219
- lte: ["long", "integer", "double", "float", "date"],
220
- between: ["long", "integer", "double", "float", "date"],
221
- not_between: ["long", "integer", "double", "float", "date"],
260
+ }, G = {
261
+ // Equality and membership — every field type, by NAME rather than by a transcribed list.
262
+ eq: u,
263
+ ne: u,
264
+ in: u,
265
+ not_in: u,
266
+ // Existence. `is null` is the SAME PREDICATE as `not exists`, so these four lists must be
267
+ // equal. They were not: `nested` and `object` were offered for `exists` and withheld from
268
+ // `is`, so the completion menu published one of two spellings of one operation depending
269
+ // on the field type. Pinned by `tests/collectionAndNullSemantics.spec.ts`.
270
+ exists: u,
271
+ not_exists: u,
272
+ is: u,
273
+ is_not: u,
274
+ // Ordered comparison — numeric, date and keyword. See ORDERED_FIELD_TYPES in
275
+ // `validator.ts`: both evaluators fall back to a lexicographic string comparison, and
276
+ // Python's own validator lists all four in `keyword_ops`. Withholding them from a keyword
277
+ // field's menu hid an operator every layer of the product supports.
278
+ gt: f,
279
+ gte: f,
280
+ lt: f,
281
+ lte: f,
282
+ // Numeric and date. `keyword` and `text` stay out because Python's `keyword_ops` excludes
283
+ // `between` while including `gte` — see BETWEEN_FIELD_TYPES in `validator.ts`.
284
+ between: w,
285
+ not_between: w,
222
286
  // String operators (text/keyword only)
223
287
  contains: ["text", "keyword"],
224
288
  not_contains: ["text", "keyword"],
@@ -235,12 +299,27 @@ const P = [
235
299
  // IP-specific operators
236
300
  cidr: ["ip"],
237
301
  not_cidr: ["ip"],
238
- // Collection operators
239
- any: ["nested", "object", "keyword"],
240
- all: ["nested", "object", "keyword"],
241
- none: ["nested", "object", "keyword"]
302
+ // Collection operators — every field type, and their negated forms stated explicitly.
303
+ //
304
+ // Two defects in four lines. `any`/`all`/`none` were restricted to `nested | object |
305
+ // keyword`, so the menu withheld them from an `ip` or `long` field — while both
306
+ // evaluators now treat a SCALAR as a one-element collection and iterate array-valued
307
+ // fields regardless of mapping type. `related.ip any [...]` is the ordinary case for an IP
308
+ // field: OpenSearch has no array type, so ECS's array guarantees live on ordinary `ip` and
309
+ // `keyword` mappings.
310
+ //
311
+ // And `not_any`/`not_all`/`not_none` were absent from this table entirely, which the
312
+ // filter reads as "no restriction" — so the negated halves were offered on every type
313
+ // while their positive twins were withheld. Permissive by omission is not the same as
314
+ // permissive by decision, and only one of them survives someone reading the table.
315
+ any: u,
316
+ all: u,
317
+ none: u,
318
+ not_any: u,
319
+ not_all: u,
320
+ not_none: u
242
321
  };
243
- class E {
322
+ class B {
244
323
  cache = /* @__PURE__ */ new Map();
245
324
  maxSize = 50;
246
325
  maxAge = 5e3;
@@ -262,149 +341,151 @@ class E {
262
341
  this.cache.clear();
263
342
  }
264
343
  }
265
- const k = new E();
266
- function U(e, t, i) {
344
+ const k = new B();
345
+ function V(e, t, i) {
267
346
  if (!e) return { type: "start", partialText: "" };
268
- const o = `${e.substring(0, t)}|${t}`, a = k.get(o);
347
+ const o = S().get(i)?.hash ?? "-", n = `${e.substring(0, t)}|${t}|${o}`, a = k.get(n);
269
348
  if (a)
270
- return a.fieldName && !a.fieldType && i && (a.fieldType = p(a.fieldName, i)), a;
271
- const n = F(e, t, i);
272
- return k.set(o, n), n;
349
+ return a.fieldName && !a.fieldType && i && (a.fieldType = h(a.fieldName, i)), a;
350
+ const s = Y(e, t, i);
351
+ return k.set(n, s), s;
273
352
  }
274
- function F(e, t, i) {
275
- const a = x(e.substring(0, t)).filter((l) => l.type !== "whitespace");
276
- if (a.length === 0)
353
+ function Y(e, t, i) {
354
+ const n = T(e.substring(0, t)).filter((l) => l.type !== "whitespace");
355
+ if (n.length === 0)
277
356
  return { type: "start" };
278
- const n = a[a.length - 1], s = a.length > 1 ? a[a.length - 2] : null, u = n.end === t && !e[t - 1]?.match(/\s/), d = u ? n.value : void 0;
279
- if (n.type === "logicalOp")
357
+ const a = n[n.length - 1], s = n.length > 1 ? n[n.length - 2] : null, c = a.end === t && !e[t - 1]?.match(/\s/), d = c ? a.value : void 0;
358
+ if (a.type === "logicalOp")
280
359
  return { type: "start" };
281
- if (n.type === "paren" && n.value === "(") {
282
- const l = a.length - 1, r = l > 0 ? a[l - 1] : null;
360
+ if (a.type === "paren" && a.value === "(") {
361
+ const l = n.length - 1, r = l > 0 ? n[l - 1] : null;
283
362
  if (r && r.type === "visualization")
284
363
  return { type: "in_viz_params" };
285
364
  }
286
- if (n.type === "comma" || n.type === "field" && u) {
287
- const l = a.indexOf(n);
365
+ if (a.type === "comma" || a.type === "field" && c) {
366
+ const l = n.indexOf(a);
288
367
  for (let r = l - 1; r >= 0; r--) {
289
- if (a[r].type === "paren" && a[r].value === "(") {
290
- if (r > 0 && a[r - 1].type === "visualization")
368
+ if (n[r].type === "paren" && n[r].value === "(") {
369
+ if (r > 0 && n[r - 1].type === "visualization")
291
370
  return { type: "in_viz_params", partialText: d };
292
371
  break;
293
372
  }
294
- if (a[r].type === "paren" && a[r].value === ")") break;
373
+ if (n[r].type === "paren" && n[r].value === ")") break;
295
374
  }
296
375
  }
297
- if (n.type === "paren" && n.value === "(")
376
+ if (a.type === "paren" && a.value === "(")
298
377
  return { type: "after_paren" };
299
- if (n.type === "arrow")
378
+ if (a.type === "arrow")
300
379
  return { type: "after_arrow", partialText: d };
301
- if (n.type === "doubleColon")
380
+ if (s?.type === "doubleColon" && c)
302
381
  return { type: "after_double_colon", partialText: d };
303
- if (n.type === "visualization" && u)
382
+ if (a.type === "doubleColon")
383
+ return { type: "after_double_colon" };
384
+ if (a.type === "visualization" && c)
304
385
  return { type: "after_arrow", partialText: d };
305
- if (n.type === "typeHint" && u)
386
+ if (a.type === "typeHint" && c)
306
387
  return { type: "after_double_colon", partialText: d };
307
- if (n.type === "keyword" && n.value.toLowerCase() === "stats")
388
+ if (a.type === "keyword" && a.value.toLowerCase() === "stats")
308
389
  return { type: "after_stats", partialText: d };
309
- if (n.type === "keyword" && n.value.toLowerCase() === "by")
390
+ if (a.type === "keyword" && a.value.toLowerCase() === "by")
310
391
  return { type: "after_by", partialText: d };
311
- if (n.type === "paren" && n.value === ")") {
312
- const l = a.indexOf(n);
392
+ if (a.type === "paren" && a.value === ")") {
393
+ const l = n.indexOf(a);
313
394
  for (let r = l - 1; r >= 0; r--) {
314
- if (a[r].type === "keyword" && a[r].value.toLowerCase() === "stats")
395
+ if (n[r].type === "keyword" && n[r].value.toLowerCase() === "stats")
315
396
  return { type: "after_stats_agg" };
316
- if (a[r].type === "keyword" && a[r].value.toLowerCase() === "by" || a[r].type === "pipe") break;
397
+ if (n[r].type === "keyword" && n[r].value.toLowerCase() === "by" || n[r].type === "pipe") break;
317
398
  }
318
399
  }
319
- if (n.type === "field" && !u) {
320
- const l = a.indexOf(n);
400
+ if (a.type === "field" && !c) {
401
+ const l = n.indexOf(a);
321
402
  for (let r = l - 1; r >= 0; r--) {
322
- if (a[r].type === "keyword" && a[r].value.toLowerCase() === "by") {
323
- for (let c = r - 1; c >= 0; c--) {
324
- if (a[c].type === "keyword" && a[c].value.toLowerCase() === "stats")
403
+ if (n[r].type === "keyword" && n[r].value.toLowerCase() === "by") {
404
+ for (let m = r - 1; m >= 0; m--) {
405
+ if (n[m].type === "keyword" && n[m].value.toLowerCase() === "stats")
325
406
  return { type: "after_group_by_field" };
326
- if (a[c].type === "pipe") break;
407
+ if (n[m].type === "pipe") break;
327
408
  }
328
409
  break;
329
410
  }
330
- if (a[r].type === "pipe") break;
411
+ if (n[r].type === "pipe") break;
331
412
  }
332
413
  }
333
- if (n.type === "pipe")
414
+ if (a.type === "pipe")
334
415
  return { type: "after_pipe", partialText: d };
335
- if (n.type === "mutator") {
336
- if (u)
416
+ if (a.type === "mutator") {
417
+ if (c)
337
418
  return { type: "after_pipe", partialText: d };
338
- const l = n.value.toLowerCase(), r = h[l];
419
+ const l = a.value.toLowerCase(), r = g[l];
339
420
  return {
340
421
  type: "after_mutator",
341
422
  mutatorName: l,
342
423
  mutatorOutputType: r
343
424
  };
344
425
  }
345
- if (n.type === "aggregation")
346
- return u ? { type: "after_stats", partialText: d } : { type: "after_value" };
347
- if (n.type === "field") {
348
- if (u)
426
+ if (a.type === "aggregation")
427
+ return c ? { type: "after_stats", partialText: d } : { type: "after_value" };
428
+ if (a.type === "field") {
429
+ if (c)
349
430
  return s?.type === "pipe" ? { type: "after_pipe", partialText: d } : { type: "start", partialText: d };
350
431
  if (s?.type === "pipe")
351
- return { type: "after_pipe", partialText: n.value };
352
- const l = p(n.value, i);
353
- return { type: "after_field", fieldName: n.value, fieldType: l };
432
+ return { type: "after_pipe", partialText: a.value };
433
+ const l = h(a.value, i);
434
+ return { type: "after_field", fieldName: a.value, fieldType: l };
354
435
  }
355
- if (n.type === "operator") {
356
- if (u) {
436
+ if (a.type === "operator") {
437
+ if (c) {
357
438
  if (s?.type === "field") {
358
- const l = p(s.value, i);
439
+ const l = h(s.value, i);
359
440
  return { type: "after_field", fieldName: s.value, fieldType: l, partialText: d };
360
441
  }
361
442
  if (s?.type === "mutator") {
362
- const l = s.value.toLowerCase(), r = h[l];
443
+ const l = s.value.toLowerCase(), r = g[l];
363
444
  return { type: "after_mutator", mutatorName: l, mutatorOutputType: r, partialText: d };
364
445
  }
365
446
  }
366
- return { type: "after_operator", operatorName: n.value };
447
+ return { type: "after_operator", operatorName: a.value };
367
448
  }
368
- if (n.type === "string" || n.type === "number" || n.type === "boolean" || n.type === "null")
369
- return u ? { type: "at_value_end" } : { type: "after_value" };
370
- if (n.type === "paren" && n.value === ")")
449
+ if (a.type === "string" || a.type === "number" || a.type === "boolean" || a.type === "null")
450
+ return c ? { type: "at_value_end" } : { type: "after_value" };
451
+ if (a.type === "paren" && a.value === ")")
371
452
  return { type: "after_value" };
372
- if (s?.type === "field" && u) {
373
- const l = p(s.value, i);
453
+ if (s?.type === "field" && c) {
454
+ const l = h(s.value, i);
374
455
  return { type: "after_field", fieldName: s.value, fieldType: l, partialText: d };
375
456
  }
376
- if (s?.type === "mutator" && u) {
377
- const l = s.value.toLowerCase(), r = h[l];
457
+ if (s?.type === "mutator" && c) {
458
+ const l = s.value.toLowerCase(), r = g[l];
378
459
  return { type: "after_mutator", mutatorName: l, mutatorOutputType: r, partialText: d };
379
460
  }
380
461
  return { type: "unknown", partialText: d };
381
462
  }
382
- function p(e, t) {
383
- return t ? $().getFieldType(t, e) : void 0;
463
+ function h(e, t) {
464
+ return t ? S().getFieldType(t, e) : void 0;
384
465
  }
385
- function Q(e, t = {}) {
386
- const { query: i, cursorPosition: o } = e, a = U(i, o, t.fields), n = [];
387
- switch (a.type) {
466
+ function ie(e, t = {}) {
467
+ const { query: i, cursorPosition: o } = e, n = V(i, o, t.fields), a = [];
468
+ switch (n.type) {
388
469
  case "start":
389
470
  case "after_paren":
390
- n.push(...g(t.fields, a.partialText)), n.push(O("NOT")), t.includeSnippets !== !1 && n.push(...B(t, a.partialText));
471
+ a.push(...x(t.fields, n.partialText)), a.push(I("NOT")), t.includeSnippets !== !1 && a.push(...K(t, n.partialText));
391
472
  break;
392
473
  case "after_field":
393
- n.push(...y(a.partialText, a.fieldType));
474
+ a.push(...b(n.partialText, n.fieldType));
394
475
  break;
395
476
  case "after_mutator":
396
- n.push(...y(a.partialText, a.mutatorOutputType));
477
+ a.push(...b(n.partialText, n.mutatorOutputType));
397
478
  break;
398
479
  case "after_operator":
399
- n.push(...j(a.fieldName, t));
480
+ a.push(...j(n.fieldName, t));
400
481
  break;
401
482
  case "after_value":
402
- n.push(..._());
483
+ a.push(...C());
403
484
  break;
404
485
  case "at_value_end":
405
486
  break;
406
487
  case "after_pipe":
407
- n.push(...V(a.partialText)), (!a.partialText || "stats".includes(a.partialText.toLowerCase())) && n.push({
488
+ a.push(...W(n.partialText)), (!n.partialText || "stats".includes(n.partialText.toLowerCase())) && a.push({
408
489
  label: "stats",
409
490
  insertText: "stats ",
410
491
  kind: "keyword",
@@ -414,13 +495,13 @@ function Q(e, t = {}) {
414
495
  });
415
496
  break;
416
497
  case "after_stats_agg":
417
- n.push({
498
+ a.push({
418
499
  label: "by",
419
500
  insertText: "by ",
420
501
  kind: "keyword",
421
502
  detail: "Group results by field",
422
503
  sortOrder: 1
423
- }), n.push({
504
+ }), a.push({
424
505
  label: "=>",
425
506
  insertText: "=> ",
426
507
  kind: "visualization",
@@ -429,13 +510,13 @@ function Q(e, t = {}) {
429
510
  });
430
511
  break;
431
512
  case "after_group_by_field":
432
- n.push({
513
+ a.push({
433
514
  label: "=>",
434
515
  insertText: "=> ",
435
516
  kind: "visualization",
436
517
  detail: "Set visualization type (bar, pie, line, ...)",
437
518
  sortOrder: 1
438
- }), n.push({
519
+ }), a.push({
439
520
  label: ",",
440
521
  insertText: ", ",
441
522
  kind: "keyword",
@@ -444,61 +525,61 @@ function Q(e, t = {}) {
444
525
  });
445
526
  break;
446
527
  case "after_double_colon":
447
- n.push(...H(a.partialText));
528
+ a.push(...Z(n.partialText));
448
529
  break;
449
530
  case "after_arrow":
450
- n.push(...Y(a.partialText));
531
+ a.push(...X(n.partialText));
451
532
  break;
452
533
  case "in_viz_params":
453
- n.push(...W(a.partialText));
534
+ a.push(...Q(n.partialText));
454
535
  break;
455
536
  case "after_stats":
456
- n.push(...C(a.partialText));
537
+ a.push(...O(n.partialText));
457
538
  break;
458
539
  case "after_by":
459
- n.push(...g(t.fields, a.partialText));
540
+ a.push(...x(t.fields, n.partialText));
460
541
  break;
461
542
  default:
462
- n.push(...g(t.fields, a.partialText)), n.push(...y(a.partialText)), n.push(..._());
543
+ a.push(...x(t.fields, n.partialText)), a.push(...b(n.partialText)), a.push(...C());
463
544
  }
464
- t.includeAggregations && a.type === "start" && n.push(...C(a.partialText));
465
- let s = n;
466
- const u = t.fuzzyMatching !== !1, d = t.minFuzzyScore ?? 0;
467
- if (a.partialText) {
468
- const l = a.partialText.toLowerCase();
469
- if (u) {
545
+ t.includeAggregations && n.type === "start" && a.push(...O(n.partialText));
546
+ let s = a;
547
+ const c = t.fuzzyMatching !== !1, d = t.minFuzzyScore ?? 0;
548
+ if (n.partialText) {
549
+ const l = n.partialText.toLowerCase();
550
+ if (c) {
470
551
  const r = [];
471
- for (const c of n) {
472
- const m = w(l, c.label), b = c.filterText ? w(l, c.filterText) : { matched: !1, score: 0 }, f = m.score >= b.score ? m : b;
473
- f.matched && f.score >= d && r.push({
474
- ...c,
475
- matchScore: f.score,
476
- matchedIndices: m.matched ? m.matchedIndices : void 0
552
+ for (const m of a) {
553
+ const p = _(l, m.label), v = m.filterText ? _(l, m.filterText) : { matched: !1, score: 0 }, y = p.score >= v.score ? p : v;
554
+ y.matched && y.score >= d && r.push({
555
+ ...m,
556
+ matchScore: y.score,
557
+ matchedIndices: p.matched ? p.matchedIndices : void 0
477
558
  });
478
559
  }
479
560
  s = r;
480
561
  } else
481
- s = n.filter(
562
+ s = a.filter(
482
563
  (r) => r.label.toLowerCase().includes(l) || r.filterText?.toLowerCase().includes(l)
483
564
  );
484
565
  }
485
566
  return s.sort((l, r) => l.matchScore !== void 0 && r.matchScore !== void 0 && r.matchScore !== l.matchScore ? r.matchScore - l.matchScore : l.sortOrder - r.sortOrder), t.maxItems && t.maxItems > 0 && (s = s.slice(0, t.maxItems)), s;
486
567
  }
487
- function g(e, t) {
568
+ function x(e, t) {
488
569
  if (!e || e.length === 0)
489
- return G(t);
570
+ return q(t);
490
571
  const i = [];
491
572
  for (const o of e) {
492
- const a = v(o);
493
- if (i.push(a), o.nested)
494
- for (const n of o.nested) {
495
- const s = v(n, o.name);
573
+ const n = N(o);
574
+ if (i.push(n), o.nested)
575
+ for (const a of o.nested) {
576
+ const s = N(a, o.name);
496
577
  i.push(s);
497
578
  }
498
579
  }
499
580
  return i;
500
581
  }
501
- function G(e) {
582
+ function q(e) {
502
583
  return [
503
584
  { name: "hostname", description: "Host/machine name" },
504
585
  { name: "status", description: "Status value" },
@@ -524,7 +605,7 @@ function G(e) {
524
605
  sortOrder: 10
525
606
  }));
526
607
  }
527
- function v(e, t) {
608
+ function N(e, t) {
528
609
  const i = t ? `${t}.${e.name}` : e.name;
529
610
  return {
530
611
  label: i,
@@ -536,24 +617,24 @@ function v(e, t) {
536
617
  sortOrder: 10
537
618
  };
538
619
  }
539
- function y(e, t) {
540
- let i = [...N];
620
+ function b(e, t) {
621
+ let i = [...E];
541
622
  return t && (i = i.filter((o) => {
542
- const a = z[o];
543
- return !a || a.includes(t);
544
- })), e && (i = i.filter((o) => o.toLowerCase().includes(e.toLowerCase()))), i.map((o, a) => {
545
- const n = D[o] || { detail: o, documentation: "" }, s = q(o, t);
623
+ const n = G[o];
624
+ return !n || n.includes(t);
625
+ })), e && (i = i.filter((o) => o.toLowerCase().includes(e.toLowerCase()))), i.map((o, n) => {
626
+ const a = U[o] || { detail: o, documentation: "" }, s = H(o, t);
546
627
  return {
547
628
  label: o,
548
629
  insertText: s,
549
630
  kind: "operator",
550
- detail: n.detail,
551
- documentation: n.documentation,
552
- sortOrder: 20 + a
631
+ detail: a.detail,
632
+ documentation: a.documentation,
633
+ sortOrder: 20 + n
553
634
  };
554
635
  });
555
636
  }
556
- function q(e, t) {
637
+ function H(e, t) {
557
638
  const i = [
558
639
  "contains",
559
640
  "not_contains",
@@ -567,12 +648,12 @@ function q(e, t) {
567
648
  "not_regex",
568
649
  "matches",
569
650
  "not_matches"
570
- ], o = ["exists", "not_exists"], a = ["is", "is_not"];
651
+ ], o = ["exists", "not_exists"], n = ["is", "is_not"];
571
652
  if (e === "in" || e === "not_in")
572
- return T(t) ? `${e} [$1]` : `${e} ["$1"]`;
653
+ return A(t) ? `${e} [$1]` : `${e} ["$1"]`;
573
654
  if (e === "between" || e === "not_between")
574
- return T(t) ? `${e} $1 AND $2` : `${e} "$1" AND "$2"`;
575
- if (a.includes(e))
655
+ return A(t) ? `${e} $1 AND $2` : `${e} "$1" AND "$2"`;
656
+ if (n.includes(e))
576
657
  return `${e} null`;
577
658
  if (o.includes(e))
578
659
  return e;
@@ -605,15 +686,15 @@ function q(e, t) {
605
686
  return `${e} `;
606
687
  }
607
688
  }
608
- function T(e) {
689
+ function A(e) {
609
690
  return e === "long" || e === "integer" || e === "double" || e === "float" || e === "short" || e === "byte" || e === "half_float" || e === "scaled_float" || e === "unsigned_long";
610
691
  }
611
- function _() {
612
- return S.filter((e) => e !== "NOT").map(
613
- (e, t) => O(e, t)
692
+ function C() {
693
+ return R.filter((e) => e !== "NOT").map(
694
+ (e, t) => I(e, t)
614
695
  );
615
696
  }
616
- function O(e, t = 0) {
697
+ function I(e, t = 0) {
617
698
  return {
618
699
  label: e,
619
700
  insertText: e + " ",
@@ -624,13 +705,13 @@ function O(e, t = 0) {
624
705
  }
625
706
  function j(e, t) {
626
707
  const i = [];
627
- return e && t?.fieldValues?.[e] && t.fieldValues[e].forEach((a, n) => {
708
+ return e && t?.fieldValues?.[e] && t.fieldValues[e].forEach((n, a) => {
628
709
  i.push({
629
- label: a,
630
- insertText: `"${a}"`,
710
+ label: n,
711
+ insertText: `"${n}"`,
631
712
  kind: "value",
632
713
  detail: `Known value for ${e}`,
633
- sortOrder: 40 + n
714
+ sortOrder: 40 + a
634
715
  });
635
716
  }), i.push(
636
717
  {
@@ -663,20 +744,20 @@ function j(e, t) {
663
744
  }
664
745
  ), i;
665
746
  }
666
- function B(e, t) {
667
- return P.filter((o) => !t || o.label.toLowerCase().includes(t.toLowerCase())).map((o, a) => ({
747
+ function K(e, t) {
748
+ return z.filter((o) => !t || o.label.toLowerCase().includes(t.toLowerCase())).map((o, n) => ({
668
749
  label: o.label,
669
750
  insertText: o.insertText,
670
751
  kind: "snippet",
671
752
  detail: o.description,
672
753
  documentation: `Insert: ${o.insertText}`,
673
- sortOrder: 100 + a
754
+ sortOrder: 100 + n
674
755
  }));
675
756
  }
676
- function V(e) {
677
- return R.filter((t) => !e || t.toLowerCase().includes(e.toLowerCase())).map(
757
+ function W(e) {
758
+ return M.filter((t) => !e || t.toLowerCase().includes(e.toLowerCase())).map(
678
759
  (t, i) => {
679
- const o = M[t] || { detail: "Field mutator", documentation: "" };
760
+ const o = F[t] || { detail: "Field mutator", documentation: "" };
680
761
  return {
681
762
  label: t,
682
763
  insertText: t,
@@ -688,8 +769,8 @@ function V(e) {
688
769
  }
689
770
  );
690
771
  }
691
- function C(e) {
692
- return I.filter(
772
+ function O(e) {
773
+ return P.filter(
693
774
  (t) => !e || t.toLowerCase().includes(e.toLowerCase())
694
775
  ).map((t, i) => ({
695
776
  label: t,
@@ -699,8 +780,8 @@ function C(e) {
699
780
  sortOrder: 70 + i
700
781
  }));
701
782
  }
702
- function H(e) {
703
- return L.filter(
783
+ function Z(e) {
784
+ return D.filter(
704
785
  (t) => !e || t.toLowerCase().includes(e.toLowerCase())
705
786
  ).map((t, i) => ({
706
787
  label: t,
@@ -710,8 +791,8 @@ function H(e) {
710
791
  sortOrder: 80 + i
711
792
  }));
712
793
  }
713
- function Y(e) {
714
- return A.filter(
794
+ function X(e) {
795
+ return $.filter(
715
796
  (t) => !e || t.toLowerCase().includes(e.toLowerCase())
716
797
  ).map((t, i) => ({
717
798
  label: t,
@@ -721,7 +802,7 @@ function Y(e) {
721
802
  sortOrder: 90 + i
722
803
  }));
723
804
  }
724
- const K = [
805
+ const J = [
725
806
  // Titles & labels
726
807
  { name: "title", detail: "Chart title", insertText: 'title="' },
727
808
  { name: "x_label", detail: "X-axis label", insertText: 'x_label="' },
@@ -757,8 +838,8 @@ const K = [
757
838
  { name: "link", detail: 'Template URL for value links: "https://...{{value}}"', insertText: 'link="' },
758
839
  { name: "link_target", detail: "Link target: _self (default) or _blank", insertText: "link_target=" }
759
840
  ];
760
- function W(e) {
761
- return K.filter(
841
+ function Q(e) {
842
+ return J.filter(
762
843
  (t) => !e || t.name.toLowerCase().includes(e.toLowerCase())
763
844
  ).map((t, i) => ({
764
845
  label: t.name,
@@ -768,9 +849,9 @@ function W(e) {
768
849
  sortOrder: 95 + i
769
850
  }));
770
851
  }
771
- function ee(e, t) {
772
- const o = x(e).find(
773
- (a) => a.start <= t && a.end >= t && a.type !== "whitespace"
852
+ function re(e, t) {
853
+ const o = T(e).find(
854
+ (n) => n.start <= t && n.end >= t && n.type !== "whitespace"
774
855
  );
775
856
  return o ? {
776
857
  word: o.value,
@@ -778,18 +859,18 @@ function ee(e, t) {
778
859
  end: o.end
779
860
  } : null;
780
861
  }
781
- function te() {
862
+ function oe() {
782
863
  return [" ", "(", ".", '"', "'", "|", ":", "="];
783
864
  }
784
- function ae(e, t, i) {
865
+ function le(e, t, i) {
785
866
  if (!e) return !1;
786
867
  if (i === " " || i === "(" || i === "." || i === "|" || i === ":" || i === "=") return !0;
787
- const o = x(e.substring(0, t)), a = o[o.length - 1];
788
- return !!(a && a.type === "field" && a.value.length >= 2);
868
+ const o = T(e.substring(0, t)), n = o[o.length - 1];
869
+ return !!(n && n.type === "field" && n.value.length >= 2);
789
870
  }
790
871
  export {
791
- te as getCompletionTriggerCharacters,
792
- Q as getCompletions,
793
- ee as getWordAtPosition,
794
- ae as shouldTriggerCompletion
872
+ oe as getCompletionTriggerCharacters,
873
+ ie as getCompletions,
874
+ re as getWordAtPosition,
875
+ le as shouldTriggerCompletion
795
876
  };