@tellaro/tql 0.1.0 → 0.1.2

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,5 +1,10 @@
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 = [
1
+ var I = Object.defineProperty;
2
+ var S = (e, t, a) => t in e ? I(e, t, { enumerable: !0, configurable: !0, writable: !0, value: a }) : e[t] = a;
3
+ var p = (e, t, a) => S(e, typeof t != "symbol" ? t + "" : t, a);
4
+ import { tokenizeTql as b, COMPARISON_OPERATORS as A, LOGICAL_OPERATORS as L, AGGREGATION_FUNCTIONS as R, VISUALIZATION_TYPES as $, TYPE_HINTS as P, MUTATORS as D } from "./tokenizer.js";
5
+ import { fuzzyMatch as _ } from "./fuzzyMatcher.js";
6
+ import { getSchemaCache as M } from "./schemaCache.js";
7
+ const E = [
3
8
  {
4
9
  label: "Simple equality",
5
10
  insertText: 'field eq "value"',
@@ -102,7 +107,7 @@ const I = [
102
107
  description: "Top 10 results by count",
103
108
  category: "Stats"
104
109
  }
105
- ], A = {
110
+ ], U = {
106
111
  eq: { detail: "Equals", documentation: "Exact match comparison" },
107
112
  ne: { detail: "Not equals", documentation: "Match any value except this one" },
108
113
  gt: { detail: "Greater than", documentation: "Numeric/date comparison" },
@@ -136,7 +141,7 @@ const I = [
136
141
  not_any: { detail: "Not any matches", documentation: "Negation of any" },
137
142
  not_all: { detail: "Not all match", documentation: "Negation of all" },
138
143
  not_none: { detail: "Not none match", documentation: "Negation of none" }
139
- }, L = {
144
+ }, z = {
140
145
  lowercase: { detail: "Convert to lowercase", documentation: "Transform string to lowercase" },
141
146
  uppercase: { detail: "Convert to uppercase", documentation: "Transform string to uppercase" },
142
147
  trim: { detail: "Trim whitespace", documentation: "Remove leading/trailing whitespace" },
@@ -165,7 +170,7 @@ const I = [
165
170
  sum: { detail: "Sum", documentation: "Sum of numeric array elements" },
166
171
  min: { detail: "Minimum", documentation: "Minimum value in array" },
167
172
  max: { detail: "Maximum", documentation: "Maximum value in array" }
168
- }, m = {
173
+ }, h = {
169
174
  // String outputs
170
175
  lowercase: "keyword",
171
176
  uppercase: "keyword",
@@ -199,7 +204,7 @@ const I = [
199
204
  geo: "object",
200
205
  // Array output (returns array of strings)
201
206
  split: "keyword"
202
- }, S = {
207
+ }, F = {
203
208
  // Universal operators (work with all types)
204
209
  eq: ["text", "keyword", "long", "integer", "double", "float", "date", "boolean", "ip"],
205
210
  ne: ["text", "keyword", "long", "integer", "double", "float", "date", "boolean", "ip"],
@@ -236,147 +241,190 @@ const I = [
236
241
  all: ["nested", "object", "keyword"],
237
242
  none: ["nested", "object", "keyword"]
238
243
  };
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)
244
+ class q {
245
+ constructor() {
246
+ p(this, "cache", /* @__PURE__ */ new Map());
247
+ p(this, "maxSize", 50);
248
+ p(this, "maxAge", 5e3);
249
+ }
250
+ // 5 seconds
251
+ get(t) {
252
+ const a = this.cache.get(t);
253
+ if (a && Date.now() - a.timestamp < this.maxAge)
254
+ return a.result;
255
+ a && this.cache.delete(t);
256
+ }
257
+ set(t, a) {
258
+ if (this.cache.size >= this.maxSize) {
259
+ const o = this.cache.keys().next().value;
260
+ o && this.cache.delete(o);
261
+ }
262
+ this.cache.set(t, { result: a, timestamp: Date.now() });
263
+ }
264
+ clear() {
265
+ this.cache.clear();
266
+ }
267
+ }
268
+ const v = new q();
269
+ function B(e, t, a) {
270
+ const o = `${e.substring(0, t)}|${t}`, i = v.get(o);
271
+ if (i)
272
+ return i.fieldName && !i.fieldType && a && (i.fieldType = f(i.fieldName, a)), i;
273
+ const n = G(e, t, a);
274
+ return v.set(o, n), n;
275
+ }
276
+ function G(e, t, a) {
277
+ var d;
278
+ const i = b(e.substring(0, t)).filter((l) => l.type !== "whitespace");
279
+ if (i.length === 0)
243
280
  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")
281
+ const n = i[i.length - 1], r = i.length > 1 ? i[i.length - 2] : null, u = n.end === t && !((d = e[t - 1]) != null && d.match(/\s/)), s = u ? n.value : void 0;
282
+ if (n.type === "logicalOp")
246
283
  return { type: "start" };
247
- if (a.type === "paren" && a.value === "(")
284
+ if (n.type === "paren" && n.value === "(")
248
285
  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];
286
+ if (n.type === "arrow")
287
+ return { type: "after_arrow", partialText: s };
288
+ if (n.type === "doubleColon")
289
+ return { type: "after_double_colon", partialText: s };
290
+ if (n.type === "visualization" && u)
291
+ return { type: "after_arrow", partialText: s };
292
+ if (n.type === "typeHint" && u)
293
+ return { type: "after_double_colon", partialText: s };
294
+ if (n.type === "keyword" && n.value.toLowerCase() === "stats")
295
+ return { type: "after_stats", partialText: s };
296
+ if (n.type === "keyword" && n.value.toLowerCase() === "by")
297
+ return { type: "after_by", partialText: s };
298
+ if (n.type === "pipe")
299
+ return { type: "after_pipe", partialText: s };
300
+ if (n.type === "mutator") {
301
+ if (u)
302
+ return { type: "after_pipe", partialText: s };
303
+ const l = n.value.toLowerCase(), c = h[l];
267
304
  return {
268
305
  type: "after_mutator",
269
- mutatorName: s,
306
+ mutatorName: l,
270
307
  mutatorOutputType: c
271
308
  };
272
309
  }
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 };
310
+ if (n.type === "aggregation")
311
+ return u ? { type: "after_stats", partialText: s } : { type: "after_value" };
312
+ if (n.type === "field") {
313
+ if (u)
314
+ return (r == null ? void 0 : r.type) === "pipe" ? { type: "after_pipe", partialText: s } : { type: "start", partialText: s };
278
315
  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 };
316
+ return { type: "after_pipe", partialText: n.value };
317
+ const l = f(n.value, a);
318
+ return { type: "after_field", fieldName: n.value, fieldType: l };
282
319
  }
283
- if (a.type === "operator") {
284
- if (d) {
320
+ if (n.type === "operator") {
321
+ if (u) {
285
322
  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 };
323
+ const l = f(r.value, a);
324
+ return { type: "after_field", fieldName: r.value, fieldType: l, partialText: s };
288
325
  }
289
326
  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 };
327
+ const l = r.value.toLowerCase(), c = h[l];
328
+ return { type: "after_mutator", mutatorName: l, mutatorOutputType: c, partialText: s };
292
329
  }
293
330
  }
294
- return { type: "after_operator", operatorName: a.value };
331
+ return { type: "after_operator", operatorName: n.value };
295
332
  }
296
- if (a.type === "string" || a.type === "number" || a.type === "boolean" || a.type === "null")
333
+ if (n.type === "string" || n.type === "number" || n.type === "boolean" || n.type === "null")
297
334
  return { type: "after_value" };
298
- if (a.type === "paren" && a.value === ")")
335
+ if (n.type === "paren" && n.value === ")")
299
336
  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 };
337
+ if ((r == null ? void 0 : r.type) === "field" && u) {
338
+ const l = f(r.value, a);
339
+ return { type: "after_field", fieldName: r.value, fieldType: l, partialText: s };
303
340
  }
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 };
341
+ if ((r == null ? void 0 : r.type) === "mutator" && u) {
342
+ const l = r.value.toLowerCase(), c = h[l];
343
+ return { type: "after_mutator", mutatorName: l, mutatorOutputType: c, partialText: s };
307
344
  }
308
- return { type: "unknown", partialText: l };
345
+ return { type: "unknown", partialText: s };
309
346
  }
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;
347
+ function f(e, t) {
348
+ return t ? M().getFieldType(t, e) : void 0;
314
349
  }
315
- function B(e, t = {}) {
316
- const { query: n, cursorPosition: i } = e, o = R(n, i, t.fields), a = [];
317
- switch (o.type) {
350
+ function te(e, t = {}) {
351
+ const { query: a, cursorPosition: o } = e, i = B(a, o, t.fields), n = [];
352
+ switch (i.type) {
318
353
  case "start":
319
354
  case "after_paren":
320
- a.push(...f(t.fields, o.partialText)), a.push(_("NOT")), t.includeSnippets !== !1 && a.push(...E(t, o.partialText));
355
+ n.push(...y(t.fields, i.partialText)), n.push(N("NOT")), t.includeSnippets !== !1 && n.push(...Y(t, i.partialText));
321
356
  break;
322
357
  case "after_field":
323
- a.push(...g(o.partialText, o.fieldType));
358
+ n.push(...x(i.partialText, i.fieldType));
324
359
  break;
325
360
  case "after_mutator":
326
- a.push(...g(o.partialText, o.mutatorOutputType));
361
+ n.push(...x(i.partialText, i.mutatorOutputType));
327
362
  break;
328
363
  case "after_operator":
329
- a.push(...D(o.fieldName, t));
364
+ n.push(...H(i.fieldName, t));
330
365
  break;
331
366
  case "after_value":
332
- a.push(...x());
367
+ n.push(...C());
333
368
  break;
334
369
  case "after_pipe":
335
- a.push(...M(o.partialText));
370
+ n.push(...K(i.partialText));
336
371
  break;
337
372
  case "after_double_colon":
338
- a.push(...U(o.partialText));
373
+ n.push(...W(i.partialText));
339
374
  break;
340
375
  case "after_arrow":
341
- a.push(...q(o.partialText));
376
+ n.push(...Z(i.partialText));
342
377
  break;
343
378
  case "after_stats":
344
- a.push(...w(o.partialText));
379
+ n.push(...O(i.partialText));
345
380
  break;
346
381
  case "after_by":
347
- a.push(...f(t.fields, o.partialText));
382
+ n.push(...y(t.fields, i.partialText));
348
383
  break;
349
384
  default:
350
- a.push(...f(t.fields, o.partialText)), a.push(...g(o.partialText)), a.push(...x());
385
+ n.push(...y(t.fields, i.partialText)), n.push(...x(i.partialText)), n.push(...C());
351
386
  }
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));
387
+ t.includeAggregations && i.type === "start" && n.push(...O(i.partialText));
388
+ let r = n;
389
+ const u = t.fuzzyMatching !== !1, s = t.minFuzzyScore ?? 0;
390
+ if (i.partialText) {
391
+ const d = i.partialText.toLowerCase();
392
+ if (u) {
393
+ const l = [];
394
+ for (const c of n) {
395
+ const m = _(d, c.label), w = c.filterText ? _(d, c.filterText) : { matched: !1, score: 0 }, g = m.score >= w.score ? m : w;
396
+ g.matched && g.score >= s && l.push({
397
+ ...c,
398
+ matchScore: g.score,
399
+ matchedIndices: m.matched ? m.matchedIndices : void 0
400
+ });
360
401
  }
361
- );
402
+ r = l;
403
+ } else
404
+ r = n.filter(
405
+ (l) => {
406
+ var c;
407
+ return l.label.toLowerCase().includes(d) || ((c = l.filterText) == null ? void 0 : c.toLowerCase().includes(d));
408
+ }
409
+ );
362
410
  }
363
- return r.sort((d, l) => d.sortOrder - l.sortOrder), t.maxItems && t.maxItems > 0 && (r = r.slice(0, t.maxItems)), r;
411
+ return r.sort((d, l) => d.matchScore !== void 0 && l.matchScore !== void 0 && l.matchScore !== d.matchScore ? l.matchScore - d.matchScore : d.sortOrder - l.sortOrder), t.maxItems && t.maxItems > 0 && (r = r.slice(0, t.maxItems)), r;
364
412
  }
365
- function f(e, t) {
413
+ function y(e, t) {
366
414
  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);
415
+ return V(t);
416
+ const a = [];
417
+ for (const o of e) {
418
+ const i = k(o);
419
+ if (a.push(i), o.nested)
420
+ for (const n of o.nested) {
421
+ const r = k(n, o.name);
422
+ a.push(r);
375
423
  }
376
424
  }
377
- return n;
425
+ return a;
378
426
  }
379
- function $(e) {
427
+ function V(e) {
380
428
  return [
381
429
  { name: "hostname", description: "Host/machine name" },
382
430
  { name: "status", description: "Status value" },
@@ -393,44 +441,44 @@ function $(e) {
393
441
  { name: "os.version", description: "Operating system version" },
394
442
  { name: "customer", description: "Customer identifier" },
395
443
  { 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,
444
+ ].filter((a) => !e || a.name.toLowerCase().includes(e.toLowerCase())).map((a) => ({
445
+ label: a.name,
446
+ insertText: a.name,
399
447
  kind: "field",
400
- detail: n.description,
448
+ detail: a.description,
401
449
  sortOrder: 10
402
450
  }));
403
451
  }
404
- function h(e, t) {
405
- const n = t ? `${t}.${e.name}` : e.name;
452
+ function k(e, t) {
453
+ const a = t ? `${t}.${e.name}` : e.name;
406
454
  return {
407
- label: n,
408
- insertText: n,
455
+ label: a,
456
+ insertText: a,
409
457
  kind: "field",
410
458
  detail: e.description || `Type: ${e.type}`,
411
459
  documentation: e.examples ? `Examples: ${e.examples.join(", ")}` : void 0,
412
460
  sortOrder: 10
413
461
  };
414
462
  }
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);
463
+ function x(e, t) {
464
+ let a = [...A];
465
+ return t && (a = a.filter((o) => {
466
+ const i = F[o];
467
+ return !i || i.includes(t);
468
+ })), e && (a = a.filter((o) => o.toLowerCase().includes(e.toLowerCase()))), a.map((o, i) => {
469
+ const n = U[o] || { detail: o, documentation: "" }, r = j(o, t);
422
470
  return {
423
- label: i,
471
+ label: o,
424
472
  insertText: r,
425
473
  kind: "operator",
426
- detail: a.detail,
427
- documentation: a.documentation,
428
- sortOrder: 20 + o
474
+ detail: n.detail,
475
+ documentation: n.documentation,
476
+ sortOrder: 20 + i
429
477
  };
430
478
  });
431
479
  }
432
- function P(e, t) {
433
- const n = [
480
+ function j(e, t) {
481
+ const a = [
434
482
  "contains",
435
483
  "not_contains",
436
484
  "startswith",
@@ -442,18 +490,18 @@ function P(e, t) {
442
490
  "not_regexp",
443
491
  "matches",
444
492
  "not_matches"
445
- ], i = ["exists", "not_exists"], o = ["is", "is_not"];
493
+ ], o = ["exists", "not_exists"], i = ["is", "is_not"];
446
494
  if (e === "in" || e === "not_in")
447
- return b(t) ? `${e} [$1]` : `${e} ["$1"]`;
495
+ return T(t) ? `${e} [$1]` : `${e} ["$1"]`;
448
496
  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`;
497
+ return T(t) ? `${e} $1 AND $2` : `${e} "$1" AND "$2"`;
452
498
  if (i.includes(e))
499
+ return `${e} null`;
500
+ if (o.includes(e))
453
501
  return e;
454
502
  if (e === "cidr" || e === "not_cidr")
455
503
  return `${e} "$1"`;
456
- if (n.includes(e))
504
+ if (a.includes(e))
457
505
  return `${e} "$1"`;
458
506
  if (!t)
459
507
  return `${e} `;
@@ -476,15 +524,15 @@ function P(e, t) {
476
524
  return `${e} `;
477
525
  }
478
526
  }
479
- function b(e) {
527
+ function T(e) {
480
528
  return e === "long" || e === "integer" || e === "double" || e === "float" || e === "short" || e === "byte" || e === "half_float" || e === "scaled_float" || e === "unsigned_long";
481
529
  }
482
- function x() {
483
- return v.filter((e) => e !== "NOT").map(
484
- (e, t) => _(e, t)
530
+ function C() {
531
+ return L.filter((e) => e !== "NOT").map(
532
+ (e, t) => N(e, t)
485
533
  );
486
534
  }
487
- function _(e, t = 0) {
535
+ function N(e, t = 0) {
488
536
  return {
489
537
  label: e,
490
538
  insertText: e + " ",
@@ -493,18 +541,18 @@ function _(e, t = 0) {
493
541
  sortOrder: 30 + t
494
542
  };
495
543
  }
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}"`,
544
+ function H(e, t) {
545
+ var o;
546
+ const a = [];
547
+ return e && ((o = t == null ? void 0 : t.fieldValues) != null && o[e]) && t.fieldValues[e].forEach((n, r) => {
548
+ a.push({
549
+ label: n,
550
+ insertText: `"${n}"`,
503
551
  kind: "value",
504
552
  detail: `Known value for ${e}`,
505
553
  sortOrder: 40 + r
506
554
  });
507
- }), n.push(
555
+ }), a.push(
508
556
  {
509
557
  label: '"text"',
510
558
  insertText: '"$1"',
@@ -533,87 +581,87 @@ function D(e, t) {
533
581
  detail: "Null value",
534
582
  sortOrder: 53
535
583
  }
536
- ), n;
584
+ ), a;
537
585
  }
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,
586
+ function Y(e, t) {
587
+ return E.filter((o) => !t || o.label.toLowerCase().includes(t.toLowerCase())).map((o, i) => ({
588
+ label: o.label,
589
+ insertText: o.insertText,
542
590
  kind: "snippet",
543
- detail: i.description,
544
- documentation: `Insert: ${i.insertText}`,
545
- sortOrder: 100 + o
591
+ detail: o.description,
592
+ documentation: `Insert: ${o.insertText}`,
593
+ sortOrder: 100 + i
546
594
  }));
547
595
  }
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: "" };
596
+ function K(e) {
597
+ return D.filter((t) => !e || t.toLowerCase().includes(e.toLowerCase())).map(
598
+ (t, a) => {
599
+ const o = z[t] || { detail: "Field mutator", documentation: "" };
552
600
  return {
553
601
  label: t,
554
602
  insertText: t,
555
603
  kind: "mutator",
556
- detail: i.detail,
557
- documentation: i.documentation,
558
- sortOrder: 60 + n
604
+ detail: o.detail,
605
+ documentation: o.documentation,
606
+ sortOrder: 60 + a
559
607
  };
560
608
  }
561
609
  );
562
610
  }
563
- function w(e) {
564
- return T.filter(
611
+ function O(e) {
612
+ return R.filter(
565
613
  (t) => !e || t.toLowerCase().includes(e.toLowerCase())
566
- ).map((t, n) => ({
614
+ ).map((t, a) => ({
567
615
  label: t,
568
616
  insertText: `${t}($1)`,
569
617
  kind: "aggregation",
570
618
  detail: "Aggregation function",
571
- sortOrder: 70 + n
619
+ sortOrder: 70 + a
572
620
  }));
573
621
  }
574
- function U(e) {
575
- return O.filter(
622
+ function W(e) {
623
+ return P.filter(
576
624
  (t) => !e || t.toLowerCase().includes(e.toLowerCase())
577
- ).map((t, n) => ({
625
+ ).map((t, a) => ({
578
626
  label: t,
579
627
  insertText: t,
580
628
  kind: "typeHint",
581
629
  detail: "Type hint",
582
- sortOrder: 80 + n
630
+ sortOrder: 80 + a
583
631
  }));
584
632
  }
585
- function q(e) {
586
- return C.filter(
633
+ function Z(e) {
634
+ return $.filter(
587
635
  (t) => !e || t.toLowerCase().includes(e.toLowerCase())
588
- ).map((t, n) => ({
636
+ ).map((t, a) => ({
589
637
  label: t,
590
638
  insertText: t,
591
639
  kind: "visualization",
592
640
  detail: "Visualization type",
593
- sortOrder: 90 + n
641
+ sortOrder: 90 + a
594
642
  }));
595
643
  }
596
- function G(e, t) {
597
- const i = y(e).find(
598
- (o) => o.start <= t && o.end >= t && o.type !== "whitespace"
644
+ function ae(e, t) {
645
+ const o = b(e).find(
646
+ (i) => i.start <= t && i.end >= t && i.type !== "whitespace"
599
647
  );
600
- return i ? {
601
- word: i.value,
602
- start: i.start,
603
- end: i.end
648
+ return o ? {
649
+ word: o.value,
650
+ start: o.start,
651
+ end: o.end
604
652
  } : null;
605
653
  }
606
- function V() {
654
+ function ne() {
607
655
  return [" ", "(", ".", '"', "'", "|", ":", "="];
608
656
  }
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);
657
+ function ie(e, t, a) {
658
+ if (a === " " || a === "(" || a === "." || a === "|" || a === ":" || a === "=") return !0;
659
+ const o = b(e.substring(0, t)), i = o[o.length - 1];
660
+ return !!(i && i.type === "field" && i.value.length >= 2);
613
661
  }
614
662
  export {
615
- V as getCompletionTriggerCharacters,
616
- B as getCompletions,
617
- G as getWordAtPosition,
618
- j as shouldTriggerCompletion
663
+ ne as getCompletionTriggerCharacters,
664
+ te as getCompletions,
665
+ ae as getWordAtPosition,
666
+ ie as shouldTriggerCompletion
619
667
  };
@@ -0,0 +1,55 @@
1
+ import { ComplexityMetrics, ComplexityResult, ComplexityThresholds, ComplexityWarning } from './types';
2
+
3
+ export declare class ComplexityAnalyzer {
4
+ private thresholds;
5
+ constructor(thresholds?: ComplexityThresholds);
6
+ /**
7
+ * Analyze a TQL query for complexity
8
+ */
9
+ analyze(query: string): ComplexityResult;
10
+ /**
11
+ * Recursively analyze an expression and collect metrics
12
+ */
13
+ private analyzeExpression;
14
+ private analyzeBinaryExpression;
15
+ private analyzeUnaryExpression;
16
+ private analyzeGroupExpression;
17
+ private analyzeComparisonExpression;
18
+ private analyzeValue;
19
+ /**
20
+ * Calculate the length of OR chains (consecutive ORs)
21
+ */
22
+ private calculateOrChainLength;
23
+ /**
24
+ * Calculate the length of AND chains (consecutive ANDs)
25
+ */
26
+ private calculateAndChainLength;
27
+ /**
28
+ * Generate warnings based on collected metrics
29
+ */
30
+ private generateWarnings;
31
+ /**
32
+ * Generate optimization suggestions based on warnings
33
+ */
34
+ private generateSuggestions;
35
+ /**
36
+ * Calculate overall complexity score based on metrics and warnings
37
+ */
38
+ private calculateScore;
39
+ }
40
+ /**
41
+ * Analyze a TQL query for complexity using default thresholds
42
+ */
43
+ export declare function analyzeComplexity(query: string, thresholds?: ComplexityThresholds): ComplexityResult;
44
+ /**
45
+ * Quick check if a query is considered high complexity
46
+ */
47
+ export declare function isHighComplexity(query: string, thresholds?: ComplexityThresholds): boolean;
48
+ /**
49
+ * Get only warnings for a query (without full analysis)
50
+ */
51
+ export declare function getComplexityWarnings(query: string, thresholds?: ComplexityThresholds): ComplexityWarning[];
52
+ /**
53
+ * Get complexity metrics for a query
54
+ */
55
+ export declare function getComplexityMetrics(query: string): ComplexityMetrics;