@tellaro/tql 1.3.8 → 1.4.1
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.
- package/dist/index.js +44 -41
- package/dist/node_modules/@kurkle/color/dist/color.esm.js +442 -0
- package/dist/node_modules/chart.js/dist/chart.js +6149 -0
- package/dist/node_modules/chart.js/dist/chunks/helpers.dataset.js +1685 -0
- package/dist/node_modules/chartjs-adapter-luxon/dist/chartjs-adapter-luxon.esm.js +56 -0
- package/dist/node_modules/chartjs-plugin-datalabels/dist/chartjs-plugin-datalabels.esm.js +607 -0
- package/dist/node_modules/luxon/build/es6/luxon.js +5524 -0
- package/dist/src/builder.d.ts +62 -0
- package/dist/src/builder.js +56 -0
- package/dist/src/chart/colors.d.ts +23 -0
- package/dist/src/chart/colors.js +101 -0
- package/dist/src/chart/formatters.d.ts +17 -0
- package/dist/src/chart/formatters.js +49 -0
- package/dist/src/chart/index.d.ts +9 -0
- package/dist/src/chart/index.js +31 -0
- package/dist/src/chart/mappers.d.ts +849 -0
- package/dist/src/chart/mappers.js +613 -0
- package/dist/src/completionProvider.js +294 -165
- package/dist/src/index.d.ts +2 -1
- package/dist/src/parser.d.ts +10 -0
- package/dist/src/parser.js +41 -9
- package/dist/src/semanticPreview.d.ts +1 -1
- package/dist/src/tokenizer.js +124 -103
- package/dist/src/types.d.ts +27 -3
- package/dist/src/validator.js +37 -10
- package/dist/tql.css +1 -1
- package/dist/vue/TqlChart.vue.d.ts +2 -0
- package/dist/vue/TqlChart.vue.js +7 -0
- package/dist/vue/TqlChart.vue2.js +208 -0
- package/dist/vue/components/TqlPreview.vue.js +4 -4
- package/dist/vue/index.d.ts +1 -0
- package/dist/vue/index.js +12 -10
- package/dist/vue/useTqlInput.d.ts +54 -0
- package/dist/vue/useTqlInput.js +80 -80
- package/package.json +39 -3
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { TqlAggregationFunction, TqlVisualizationType, TqlVizParams } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Configuration for building a stats query.
|
|
4
|
+
*/
|
|
5
|
+
export interface StatsQueryConfig {
|
|
6
|
+
/** Optional TQL filter expression (prepended before | stats) */
|
|
7
|
+
filter?: string;
|
|
8
|
+
/** Aggregation functions to apply */
|
|
9
|
+
aggregations: AggregationConfig[];
|
|
10
|
+
/** Fields to group results by */
|
|
11
|
+
groupBy?: GroupByConfig[];
|
|
12
|
+
/** Visualization hint */
|
|
13
|
+
vizHint?: VizHintConfig;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Single aggregation function configuration.
|
|
17
|
+
*/
|
|
18
|
+
export interface AggregationConfig {
|
|
19
|
+
/** Aggregation function name */
|
|
20
|
+
function: TqlAggregationFunction;
|
|
21
|
+
/** Field to aggregate (omit or use "*" for count(*)) */
|
|
22
|
+
field?: string;
|
|
23
|
+
/** Alias for the result (e.g., "total_events") */
|
|
24
|
+
alias?: string;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Group-by field configuration.
|
|
28
|
+
*/
|
|
29
|
+
export interface GroupByConfig {
|
|
30
|
+
/** Field name to group by */
|
|
31
|
+
field: string;
|
|
32
|
+
/** Optional top N limit */
|
|
33
|
+
topN?: number;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Visualization hint configuration.
|
|
37
|
+
*/
|
|
38
|
+
export interface VizHintConfig {
|
|
39
|
+
/** Chart type */
|
|
40
|
+
type: TqlVisualizationType;
|
|
41
|
+
/** Optional visualization parameters */
|
|
42
|
+
params?: TqlVizParams;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Build a TQL stats query string from structured configuration.
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* ```ts
|
|
49
|
+
* buildStatsQuery({
|
|
50
|
+
* aggregations: [{ function: "count" }],
|
|
51
|
+
* groupBy: [{ field: "status" }],
|
|
52
|
+
* vizHint: { type: "bar", params: { title: "Events by Status" } }
|
|
53
|
+
* })
|
|
54
|
+
* // => '| stats count(*) by status => bar(title="Events by Status")'
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
export declare function buildStatsQuery(config: StatsQueryConfig): string;
|
|
58
|
+
/**
|
|
59
|
+
* Parse a TQL viz hint string (e.g., "bar" or 'bar(title="Events")') into a VizHintConfig.
|
|
60
|
+
* This is a lightweight parser for the viz_hint portion only.
|
|
61
|
+
*/
|
|
62
|
+
export declare function parseVizHintString(vizStr: string): VizHintConfig | null;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
function p(e) {
|
|
2
|
+
const i = [];
|
|
3
|
+
if (e.filter?.trim() && i.push(e.filter.trim()), i.push("| stats"), !e.aggregations || e.aggregations.length === 0)
|
|
4
|
+
throw new Error("At least one aggregation is required");
|
|
5
|
+
const a = e.aggregations.map((r) => {
|
|
6
|
+
const t = r.field && r.field !== "*" ? r.field : "*";
|
|
7
|
+
let s = `${r.function}(${t})`;
|
|
8
|
+
return r.alias && (s += ` as ${r.alias}`), s;
|
|
9
|
+
});
|
|
10
|
+
if (i.push(a.join(", ")), e.groupBy && e.groupBy.length > 0) {
|
|
11
|
+
const r = e.groupBy.map((t) => {
|
|
12
|
+
let s = t.field;
|
|
13
|
+
return t.topN !== void 0 && t.topN > 0 && (s += ` top ${t.topN}`), s;
|
|
14
|
+
});
|
|
15
|
+
i.push("by " + r.join(", "));
|
|
16
|
+
}
|
|
17
|
+
if (e.vizHint) {
|
|
18
|
+
let r = `=> ${e.vizHint.type}`;
|
|
19
|
+
if (e.vizHint.params) {
|
|
20
|
+
const t = Object.entries(e.vizHint.params).filter(
|
|
21
|
+
([, s]) => s !== void 0
|
|
22
|
+
);
|
|
23
|
+
if (t.length > 0) {
|
|
24
|
+
const s = t.map(([n, u]) => typeof u == "string" ? `${n}="${u}"` : `${n}=${u}`);
|
|
25
|
+
r += `(${s.join(", ")})`;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
i.push(r);
|
|
29
|
+
}
|
|
30
|
+
return i.join(" ");
|
|
31
|
+
}
|
|
32
|
+
function m(e) {
|
|
33
|
+
if (!e || !e.trim()) return null;
|
|
34
|
+
const i = e.trim(), a = i.indexOf("(");
|
|
35
|
+
if (a === -1)
|
|
36
|
+
return { type: i };
|
|
37
|
+
const r = i.substring(0, a).trim(), t = i.substring(a + 1, i.lastIndexOf(")"));
|
|
38
|
+
if (!t.trim())
|
|
39
|
+
return { type: r };
|
|
40
|
+
const s = {};
|
|
41
|
+
let n = "", u = !1, l = "";
|
|
42
|
+
for (const o of t)
|
|
43
|
+
(o === '"' || o === "'") && !u ? (u = !0, l = o, n += o) : o === l && u ? (u = !1, n += o) : o === "," && !u ? (f(n.trim(), s), n = "") : n += o;
|
|
44
|
+
return n.trim() && f(n.trim(), s), { type: r, params: Object.keys(s).length > 0 ? s : void 0 };
|
|
45
|
+
}
|
|
46
|
+
function f(e, i) {
|
|
47
|
+
const a = e.indexOf("=");
|
|
48
|
+
if (a === -1) return;
|
|
49
|
+
const r = e.substring(0, a).trim();
|
|
50
|
+
let t = e.substring(a + 1).trim();
|
|
51
|
+
t.startsWith('"') && t.endsWith('"') || t.startsWith("'") && t.endsWith("'") ? t = t.slice(1, -1) : t.toLowerCase() === "true" ? t = !0 : t.toLowerCase() === "false" ? t = !1 : !isNaN(Number(t)) && t !== "" && (t = Number(t)), i[r] = t;
|
|
52
|
+
}
|
|
53
|
+
export {
|
|
54
|
+
p as buildStatsQuery,
|
|
55
|
+
m as parseVizHintString
|
|
56
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TQL Chart Color System
|
|
3
|
+
*
|
|
4
|
+
* Named palettes, severity presets, and color utilities.
|
|
5
|
+
*/
|
|
6
|
+
/** Default palette — high-contrast colors for dark backgrounds */
|
|
7
|
+
export declare const PALETTE: readonly ["#818cf8", "#34d399", "#f472b6", "#fbbf24", "#60a5fa", "#a78bfa", "#fb923c", "#2dd4bf", "#f87171", "#a3e635", "#e879f9", "#38bdf8", "#c084fc", "#4ade80", "#facc15", "#fb7185"];
|
|
8
|
+
/** All named palettes */
|
|
9
|
+
export declare const PALETTES: Record<string, readonly string[]>;
|
|
10
|
+
export type PaletteName = keyof typeof PALETTES;
|
|
11
|
+
/**
|
|
12
|
+
* Severity-specific colors — colorblind-safe palette.
|
|
13
|
+
* Keyed by label string (case-insensitive matching in resolveColors).
|
|
14
|
+
* These are hardcoded to specific severity values, not positional.
|
|
15
|
+
* Red-orange-yellowgreen-blue avoids the red-green confusion in deuteranopia.
|
|
16
|
+
*/
|
|
17
|
+
export declare const SEVERITY: Record<string, string>;
|
|
18
|
+
/** Get color at index from a named palette */
|
|
19
|
+
export declare function colorAt(index: number, palette?: PaletteName): string;
|
|
20
|
+
/** Generate N colors from a named palette */
|
|
21
|
+
export declare function colorArray(count: number, palette?: PaletteName): string[];
|
|
22
|
+
/** Generate N colors with 20% opacity for fills */
|
|
23
|
+
export declare function fillColorArray(count: number, palette?: PaletteName): string[];
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
const c = [
|
|
2
|
+
"#818cf8",
|
|
3
|
+
"#34d399",
|
|
4
|
+
"#f472b6",
|
|
5
|
+
"#fbbf24",
|
|
6
|
+
"#60a5fa",
|
|
7
|
+
"#a78bfa",
|
|
8
|
+
"#fb923c",
|
|
9
|
+
"#2dd4bf",
|
|
10
|
+
"#f87171",
|
|
11
|
+
"#a3e635",
|
|
12
|
+
"#e879f9",
|
|
13
|
+
"#38bdf8",
|
|
14
|
+
"#c084fc",
|
|
15
|
+
"#4ade80",
|
|
16
|
+
"#facc15",
|
|
17
|
+
"#fb7185"
|
|
18
|
+
], d = [
|
|
19
|
+
"#ef4444",
|
|
20
|
+
"#f97316",
|
|
21
|
+
"#f59e0b",
|
|
22
|
+
"#eab308",
|
|
23
|
+
"#fb923c",
|
|
24
|
+
"#fbbf24",
|
|
25
|
+
"#f87171",
|
|
26
|
+
"#fb7185",
|
|
27
|
+
"#e11d48",
|
|
28
|
+
"#dc2626",
|
|
29
|
+
"#ea580c",
|
|
30
|
+
"#d97706"
|
|
31
|
+
], t = [
|
|
32
|
+
"#3b82f6",
|
|
33
|
+
"#6366f1",
|
|
34
|
+
"#8b5cf6",
|
|
35
|
+
"#06b6d4",
|
|
36
|
+
"#14b8a6",
|
|
37
|
+
"#22c55e",
|
|
38
|
+
"#60a5fa",
|
|
39
|
+
"#818cf8",
|
|
40
|
+
"#a78bfa",
|
|
41
|
+
"#2dd4bf",
|
|
42
|
+
"#34d399",
|
|
43
|
+
"#4ade80"
|
|
44
|
+
], o = [
|
|
45
|
+
"#ef4444",
|
|
46
|
+
"#f97316",
|
|
47
|
+
"#fbbf24",
|
|
48
|
+
"#a3e635",
|
|
49
|
+
"#22c55e",
|
|
50
|
+
"#14b8a6",
|
|
51
|
+
"#06b6d4",
|
|
52
|
+
"#3b82f6",
|
|
53
|
+
"#6366f1",
|
|
54
|
+
"#8b5cf6"
|
|
55
|
+
], n = [
|
|
56
|
+
"#dbeafe",
|
|
57
|
+
"#bfdbfe",
|
|
58
|
+
"#93c5fd",
|
|
59
|
+
"#60a5fa",
|
|
60
|
+
"#3b82f6",
|
|
61
|
+
"#2563eb",
|
|
62
|
+
"#1d4ed8",
|
|
63
|
+
"#1e40af",
|
|
64
|
+
"#1e3a8a",
|
|
65
|
+
"#172554"
|
|
66
|
+
], r = {
|
|
67
|
+
default: c,
|
|
68
|
+
warm: d,
|
|
69
|
+
cool: t,
|
|
70
|
+
diverging: o,
|
|
71
|
+
sequential: n
|
|
72
|
+
}, u = {
|
|
73
|
+
critical: "#dc2626",
|
|
74
|
+
// red-600 — clearly red even in protanopia
|
|
75
|
+
high: "#ea580c",
|
|
76
|
+
// orange-600 — distinct from red in all forms
|
|
77
|
+
medium: "#ca8a04",
|
|
78
|
+
// yellow-700 — darker yellow, visible on dark/light backgrounds
|
|
79
|
+
low: "#2563eb",
|
|
80
|
+
// blue-600 — completely safe, never confused with red/orange
|
|
81
|
+
informational: "#6b7280"
|
|
82
|
+
// grey-500 — neutral, non-alert
|
|
83
|
+
};
|
|
84
|
+
function l(f, a = "default") {
|
|
85
|
+
const e = r[a] || c;
|
|
86
|
+
return e[f % e.length];
|
|
87
|
+
}
|
|
88
|
+
function i(f, a = "default") {
|
|
89
|
+
return Array.from({ length: f }, (e, b) => l(b, a));
|
|
90
|
+
}
|
|
91
|
+
function s(f, a = "default") {
|
|
92
|
+
return i(f, a).map((e) => e + "33");
|
|
93
|
+
}
|
|
94
|
+
export {
|
|
95
|
+
c as PALETTE,
|
|
96
|
+
r as PALETTES,
|
|
97
|
+
u as SEVERITY,
|
|
98
|
+
i as colorArray,
|
|
99
|
+
l as colorAt,
|
|
100
|
+
s as fillColorArray
|
|
101
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TQL Chart Number Formatters
|
|
3
|
+
*
|
|
4
|
+
* Format numbers for axis ticks, tooltips, and data labels.
|
|
5
|
+
* Supports: number, percent, bytes, duration, short (1.2K, 3.4M).
|
|
6
|
+
*/
|
|
7
|
+
/** Format a number based on the format type */
|
|
8
|
+
export declare function formatValue(value: number, format?: string): string;
|
|
9
|
+
/** Create a Chart.js tick callback for the given format */
|
|
10
|
+
export declare function tickFormatter(format?: string): ((value: number | string) => string) | undefined;
|
|
11
|
+
/** Create a Chart.js tooltip label callback for the given format */
|
|
12
|
+
export declare function tooltipFormatter(format?: string): ((ctx: {
|
|
13
|
+
parsed: {
|
|
14
|
+
y: number;
|
|
15
|
+
};
|
|
16
|
+
label: string;
|
|
17
|
+
}) => string) | undefined;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
function s(r, t) {
|
|
2
|
+
if (!t || t === "number") return r.toLocaleString();
|
|
3
|
+
switch (t) {
|
|
4
|
+
case "short":
|
|
5
|
+
return u(r);
|
|
6
|
+
case "percent":
|
|
7
|
+
return (Number.isInteger(r * 100) ? String(Math.round(r * 100)) : (r * 100).toFixed(1)) + "%";
|
|
8
|
+
case "percent_raw":
|
|
9
|
+
return (Number.isInteger(r) ? String(Math.round(r)) : r.toFixed(1)) + "%";
|
|
10
|
+
case "bytes":
|
|
11
|
+
return c(r);
|
|
12
|
+
case "duration":
|
|
13
|
+
return f(r);
|
|
14
|
+
default:
|
|
15
|
+
return r.toLocaleString();
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
function u(r) {
|
|
19
|
+
const t = Math.abs(r), e = r < 0 ? "-" : "";
|
|
20
|
+
return t >= 1e9 ? e + (t / 1e9).toFixed(1) + "B" : t >= 1e6 ? e + (t / 1e6).toFixed(1) + "M" : t >= 1e3 ? e + (t / 1e3).toFixed(1) + "K" : Number.isInteger(r) ? r.toLocaleString() : r.toFixed(2);
|
|
21
|
+
}
|
|
22
|
+
function c(r) {
|
|
23
|
+
const t = Math.abs(r), e = r < 0 ? "-" : "";
|
|
24
|
+
return t >= 1073741824 ? e + (t / 1073741824).toFixed(1) + " GB" : t >= 1048576 ? e + (t / 1048576).toFixed(1) + " MB" : t >= 1024 ? e + (t / 1024).toFixed(1) + " KB" : e + t + " B";
|
|
25
|
+
}
|
|
26
|
+
function f(r) {
|
|
27
|
+
const t = Math.abs(r);
|
|
28
|
+
if (t < 1e3) return t.toFixed(0) + "ms";
|
|
29
|
+
if (t < 6e4) return (t / 1e3).toFixed(1) + "s";
|
|
30
|
+
if (t < 36e5) {
|
|
31
|
+
const o = Math.floor(t / 6e4), i = Math.round(t % 6e4 / 1e3);
|
|
32
|
+
return i > 0 ? `${o}m ${i}s` : `${o}m`;
|
|
33
|
+
}
|
|
34
|
+
const e = Math.floor(t / 36e5), n = Math.round(t % 36e5 / 6e4);
|
|
35
|
+
return n > 0 ? `${e}h ${n}m` : `${e}h`;
|
|
36
|
+
}
|
|
37
|
+
function d(r) {
|
|
38
|
+
if (r)
|
|
39
|
+
return (t) => s(Number(t), r);
|
|
40
|
+
}
|
|
41
|
+
function a(r) {
|
|
42
|
+
if (r)
|
|
43
|
+
return (t) => `${t.label}: ${s(t.parsed.y, r)}`;
|
|
44
|
+
}
|
|
45
|
+
export {
|
|
46
|
+
s as formatValue,
|
|
47
|
+
d as tickFormatter,
|
|
48
|
+
a as tooltipFormatter
|
|
49
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @tellaro/tql/chart
|
|
3
|
+
*
|
|
4
|
+
* Chart data mappers, formatters, and configuration builders for TQL stats visualizations.
|
|
5
|
+
* Pure functions — no Chart.js dependency at the module level.
|
|
6
|
+
*/
|
|
7
|
+
export { PALETTE, PALETTES, SEVERITY, type PaletteName, colorAt, colorArray, fillColorArray, } from './colors';
|
|
8
|
+
export { formatValue, tickFormatter, tooltipFormatter, } from './formatters';
|
|
9
|
+
export { type TqlStatsResult, type GroupedData, type DrilldownEvent, normalizeOpenSearchAggs, extractGroupedData, extractScalarValue, isTimeSeriesData, parseColorMap, applyVizFilters, expandLinkTemplate, isLinkTemplateSafe, barChartData, lineChartData, pieChartData, barChartOptions, lineChartOptions, pieChartOptions, chartJsType, buildChartData, buildChartOptions, } from './mappers';
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { PALETTE as t, PALETTES as e, SEVERITY as o, colorArray as i, colorAt as p, fillColorArray as l } from "./colors.js";
|
|
2
|
+
import { formatValue as s, tickFormatter as h, tooltipFormatter as m } from "./formatters.js";
|
|
3
|
+
import { applyVizFilters as T, barChartData as c, barChartOptions as f, buildChartData as x, buildChartOptions as A, chartJsType as D, expandLinkTemplate as E, extractGroupedData as S, extractScalarValue as u, isLinkTemplateSafe as O, isTimeSeriesData as b, lineChartData as d, lineChartOptions as y, normalizeOpenSearchAggs as L, parseColorMap as V, pieChartData as k, pieChartOptions as F } from "./mappers.js";
|
|
4
|
+
export {
|
|
5
|
+
t as PALETTE,
|
|
6
|
+
e as PALETTES,
|
|
7
|
+
o as SEVERITY,
|
|
8
|
+
T as applyVizFilters,
|
|
9
|
+
c as barChartData,
|
|
10
|
+
f as barChartOptions,
|
|
11
|
+
x as buildChartData,
|
|
12
|
+
A as buildChartOptions,
|
|
13
|
+
D as chartJsType,
|
|
14
|
+
i as colorArray,
|
|
15
|
+
p as colorAt,
|
|
16
|
+
E as expandLinkTemplate,
|
|
17
|
+
S as extractGroupedData,
|
|
18
|
+
u as extractScalarValue,
|
|
19
|
+
l as fillColorArray,
|
|
20
|
+
s as formatValue,
|
|
21
|
+
O as isLinkTemplateSafe,
|
|
22
|
+
b as isTimeSeriesData,
|
|
23
|
+
d as lineChartData,
|
|
24
|
+
y as lineChartOptions,
|
|
25
|
+
L as normalizeOpenSearchAggs,
|
|
26
|
+
V as parseColorMap,
|
|
27
|
+
k as pieChartData,
|
|
28
|
+
F as pieChartOptions,
|
|
29
|
+
h as tickFormatter,
|
|
30
|
+
m as tooltipFormatter
|
|
31
|
+
};
|