@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.
@@ -0,0 +1,4 @@
1
+ declare const TqlPreviewNode: any;
2
+ export { TqlPreviewNode };
3
+ declare const _default: any;
4
+ export default _default;
@@ -0,0 +1,9 @@
1
+ import e from "./TqlPreview.vue2.js";
2
+ import { TqlPreviewNode as i } from "./TqlPreview.vue2.js";
3
+ /* empty css */
4
+ import o from "../../_virtual/_plugin-vue_export-helper.js";
5
+ const p = /* @__PURE__ */ o(e, [["__scopeId", "data-v-bae811e6"]]);
6
+ export {
7
+ i as TqlPreviewNode,
8
+ p as default
9
+ };
@@ -0,0 +1,264 @@
1
+ import { defineComponent as $, computed as v, ref as D, openBlock as i, createElementBlock as o, normalizeClass as f, createElementVNode as s, Fragment as h, toDisplayString as a, createCommentVNode as u, renderList as q, createVNode as P, unref as j } from "vue";
2
+ import { generatePreview as A } from "../../src/semanticPreview.js";
3
+ const F = {
4
+ key: 0,
5
+ class: "tql-preview__empty"
6
+ }, O = {
7
+ key: 0,
8
+ class: "tql-preview__complexity"
9
+ }, V = { class: "tql-preview__field-count" }, K = {
10
+ key: 1,
11
+ class: "tql-preview__warnings"
12
+ }, U = { class: "tql-preview__warning-icon" }, I = { class: "tql-preview__warning-text" }, M = {
13
+ key: 2,
14
+ class: "tql-preview__suggestions"
15
+ }, z = { class: "tql-preview__suggestions-list" }, H = {
16
+ key: 3,
17
+ class: "tql-preview__tree"
18
+ }, Q = { class: "tql-preview__tree-content" }, G = {
19
+ key: 4,
20
+ class: "tql-preview__fields"
21
+ }, J = { class: "tql-preview__fields-list" }, R = ["onClick"], W = { class: "tql-preview__field-name" }, X = {
22
+ key: 0,
23
+ class: "tql-preview__field-mutators"
24
+ }, Y = { class: "tql-preview__field-operator" }, Z = { class: "tql-preview__field-value" }, ee = ["title"], te = {
25
+ key: 5,
26
+ class: "tql-preview__operators"
27
+ }, ne = { class: "tql-preview__operators-list" }, le = $({
28
+ name: "TqlPreviewNode",
29
+ props: {
30
+ node: {
31
+ type: Object,
32
+ required: !0
33
+ },
34
+ depth: {
35
+ type: Number,
36
+ default: 0
37
+ },
38
+ nodeKey: {
39
+ type: String,
40
+ required: !0
41
+ },
42
+ isExpanded: {
43
+ type: Boolean,
44
+ default: !0
45
+ },
46
+ autoExpandDepth: {
47
+ type: Number,
48
+ default: 3
49
+ }
50
+ },
51
+ emits: ["toggle", "node-click"],
52
+ setup(t, { emit: m }) {
53
+ const _ = v(() => t.node.children && t.node.children.length > 0), y = v(() => {
54
+ var r;
55
+ if (t.node.type === "comparison") {
56
+ const k = (r = t.node.mutators) != null && r.length ? ` | ${t.node.mutators.join(" | ")}` : "", C = n(t.node.value);
57
+ return `${t.node.field}${k} ${t.node.operator} ${C}`;
58
+ }
59
+ return t.node.type;
60
+ });
61
+ function n(r) {
62
+ return r === null ? "null" : r === void 0 ? "" : typeof r == "string" ? `"${r}"` : Array.isArray(r) ? `[${r.map(n).join(", ")}]` : String(r);
63
+ }
64
+ function g() {
65
+ m("toggle", t.nodeKey);
66
+ }
67
+ function w() {
68
+ m("node-click", t.node);
69
+ }
70
+ function x(r) {
71
+ return `${t.nodeKey}-${r}`;
72
+ }
73
+ function p(r) {
74
+ return t.depth + 1 < t.autoExpandDepth;
75
+ }
76
+ return {
77
+ hasChildren: _,
78
+ nodeLabel: y,
79
+ handleToggle: g,
80
+ handleClick: w,
81
+ getChildKey: x,
82
+ shouldChildExpand: p
83
+ };
84
+ },
85
+ template: `
86
+ <div class="tql-preview__node" :class="'tql-preview__node--' + node.type.toLowerCase()">
87
+ <div
88
+ class="tql-preview__node-content"
89
+ :style="{ paddingLeft: depth * 16 + 'px' }"
90
+ @click="handleClick"
91
+ >
92
+ <button
93
+ v-if="hasChildren"
94
+ class="tql-preview__node-toggle"
95
+ @click.stop="handleToggle"
96
+ >
97
+ {{ isExpanded ? '-' : '+' }}
98
+ </button>
99
+ <span v-else class="tql-preview__node-toggle tql-preview__node-toggle--leaf">
100
+ -
101
+ </span>
102
+ <span class="tql-preview__node-type" v-if="node.type !== 'comparison'">
103
+ {{ node.type }}
104
+ </span>
105
+ <span class="tql-preview__node-label">{{ nodeLabel }}</span>
106
+ </div>
107
+ <div v-if="hasChildren && isExpanded" class="tql-preview__node-children">
108
+ <TqlPreviewNode
109
+ v-for="(child, index) in node.children"
110
+ :key="getChildKey(index)"
111
+ :node="child"
112
+ :depth="depth + 1"
113
+ :node-key="getChildKey(index)"
114
+ :is-expanded="shouldChildExpand(index)"
115
+ :auto-expand-depth="autoExpandDepth"
116
+ @toggle="(key) => $emit('toggle', key)"
117
+ @node-click="(n) => $emit('node-click', n)"
118
+ />
119
+ </div>
120
+ </div>
121
+ `
122
+ }), re = /* @__PURE__ */ $({
123
+ __name: "TqlPreview",
124
+ props: {
125
+ query: {},
126
+ showLogicTree: { type: Boolean, default: !0 },
127
+ showFieldUsage: { type: Boolean, default: !0 },
128
+ showComplexity: { type: Boolean, default: !0 },
129
+ showOperatorSummary: { type: Boolean, default: !1 },
130
+ maxExpandedDepth: { default: 3 },
131
+ compact: { type: Boolean, default: !1 }
132
+ },
133
+ emits: ["field-click", "node-click"],
134
+ setup(t, { emit: m }) {
135
+ const _ = t, y = m, n = v(() => A(_.query)), g = v(() => !_.query.trim() || !n.value.logicTree), w = v(() => {
136
+ const e = n.value.complexity.score;
137
+ return {
138
+ "tql-preview--low": e === "low",
139
+ "tql-preview--medium": e === "medium",
140
+ "tql-preview--high": e === "high"
141
+ };
142
+ }), x = v(() => ({
143
+ low: "Low complexity",
144
+ medium: "Medium complexity",
145
+ high: "High complexity"
146
+ })[n.value.complexity.score] || "Unknown"), p = D(/* @__PURE__ */ new Set());
147
+ function r(e) {
148
+ return p.value.has(e);
149
+ }
150
+ function k(e) {
151
+ p.value.has(e) ? p.value.delete(e) : p.value.add(e);
152
+ }
153
+ function C(e) {
154
+ return e < _.maxExpandedDepth;
155
+ }
156
+ function E(e) {
157
+ return e === null ? "null" : e === void 0 ? "" : typeof e == "string" ? `"${e}"` : Array.isArray(e) ? `[${e.map(E).join(", ")}]` : String(e);
158
+ }
159
+ function b(e) {
160
+ return {
161
+ exact: "=",
162
+ wildcard: "*",
163
+ range: "<>",
164
+ regex: "/.*/",
165
+ existence: "?",
166
+ null_check: "null",
167
+ cidr: "IP"
168
+ }[e] || "?";
169
+ }
170
+ function N(e) {
171
+ return `tql-preview__match-type--${e}`;
172
+ }
173
+ function S(e) {
174
+ return `tql-preview__warning--${e}`;
175
+ }
176
+ function L(e) {
177
+ y("field-click", e);
178
+ }
179
+ function B(e) {
180
+ y("node-click", e);
181
+ }
182
+ return (e, d) => (i(), o("div", {
183
+ class: f(["tql-preview", [w.value, { "tql-preview--compact": t.compact, "tql-preview--empty": g.value }]])
184
+ }, [
185
+ g.value ? (i(), o("div", F, [...d[0] || (d[0] = [
186
+ s("span", { class: "tql-preview__empty-text" }, "Enter a query to see preview", -1)
187
+ ])])) : (i(), o(h, { key: 1 }, [
188
+ t.showComplexity ? (i(), o("div", O, [
189
+ s("span", {
190
+ class: f(["tql-preview__complexity-badge", w.value])
191
+ }, a(x.value), 3),
192
+ s("span", V, a(n.value.fieldCount) + " field" + a(n.value.fieldCount !== 1 ? "s" : ""), 1)
193
+ ])) : u("", !0),
194
+ t.showComplexity && n.value.complexity.warnings.length > 0 ? (i(), o("div", K, [
195
+ (i(!0), o(h, null, q(n.value.complexity.warnings, (l, c) => (i(), o("div", {
196
+ key: c,
197
+ class: f(["tql-preview__warning", S(l.severity)])
198
+ }, [
199
+ s("span", U, a(l.severity === "error" || l.severity === "warning" ? "!" : "i"), 1),
200
+ s("span", I, a(l.message), 1)
201
+ ], 2))), 128))
202
+ ])) : u("", !0),
203
+ t.showComplexity && n.value.complexity.suggestions.length > 0 ? (i(), o("div", M, [
204
+ d[1] || (d[1] = s("div", { class: "tql-preview__suggestions-header" }, "Suggestions:", -1)),
205
+ s("ul", z, [
206
+ (i(!0), o(h, null, q(n.value.complexity.suggestions, (l, c) => (i(), o("li", {
207
+ key: c,
208
+ class: "tql-preview__suggestion"
209
+ }, a(l), 1))), 128))
210
+ ])
211
+ ])) : u("", !0),
212
+ t.showLogicTree && n.value.logicTree ? (i(), o("div", H, [
213
+ d[2] || (d[2] = s("div", { class: "tql-preview__tree-header" }, "Query Structure", -1)),
214
+ s("div", Q, [
215
+ P(j(le), {
216
+ node: n.value.logicTree,
217
+ depth: 0,
218
+ "node-key": "root",
219
+ "is-expanded": C(0) || r("root"),
220
+ "auto-expand-depth": t.maxExpandedDepth,
221
+ onToggle: k,
222
+ onNodeClick: B
223
+ }, null, 8, ["node", "is-expanded", "auto-expand-depth"])
224
+ ])
225
+ ])) : u("", !0),
226
+ t.showFieldUsage && n.value.fields.length > 0 ? (i(), o("div", G, [
227
+ d[3] || (d[3] = s("div", { class: "tql-preview__fields-header" }, "Fields Used", -1)),
228
+ s("div", J, [
229
+ (i(!0), o(h, null, q(n.value.fields, (l, c) => {
230
+ var T;
231
+ return i(), o("div", {
232
+ key: c,
233
+ class: "tql-preview__field",
234
+ onClick: (ie) => L(l)
235
+ }, [
236
+ s("span", W, a(l.name), 1),
237
+ (T = l.mutators) != null && T.length ? (i(), o("span", X, " | " + a(l.mutators.join(" | ")), 1)) : u("", !0),
238
+ s("span", Y, a(l.operator), 1),
239
+ s("span", Z, a(E(l.value)), 1),
240
+ s("span", {
241
+ class: f(["tql-preview__match-type", N(l.matchType)]),
242
+ title: l.matchType
243
+ }, a(b(l.matchType)), 11, ee)
244
+ ], 8, R);
245
+ }), 128))
246
+ ])
247
+ ])) : u("", !0),
248
+ t.showOperatorSummary && Object.keys(n.value.operatorSummary).length > 0 ? (i(), o("div", te, [
249
+ d[4] || (d[4] = s("div", { class: "tql-preview__operators-header" }, "Operators", -1)),
250
+ s("div", ne, [
251
+ (i(!0), o(h, null, q(n.value.operatorSummary, (l, c) => (i(), o("span", {
252
+ key: c,
253
+ class: "tql-preview__operator"
254
+ }, a(c) + ": " + a(l), 1))), 128))
255
+ ])
256
+ ])) : u("", !0)
257
+ ], 64))
258
+ ], 2));
259
+ }
260
+ });
261
+ export {
262
+ le as TqlPreviewNode,
263
+ re as default
264
+ };
@@ -0,0 +1,35 @@
1
+ import { Ref, ComputedRef } from 'vue';
2
+ import { QueryHistoryEntry, UseQueryHistoryOptions } from '../../src/types';
3
+
4
+ export interface UseQueryHistoryReturn {
5
+ /** Reactive array of all history entries */
6
+ history: Ref<QueryHistoryEntry[]>;
7
+ /** Computed array of favorited entries */
8
+ favorites: ComputedRef<QueryHistoryEntry[]>;
9
+ /** Add a query to history */
10
+ addQuery: (query: string, metadata?: QueryHistoryEntry["metadata"]) => QueryHistoryEntry;
11
+ /** Remove a query from history by ID */
12
+ removeQuery: (id: string) => boolean;
13
+ /** Clear all history (preserves favorites if specified) */
14
+ clearHistory: (preserveFavorites?: boolean) => void;
15
+ /** Toggle favorite status for a query */
16
+ toggleFavorite: (id: string) => boolean;
17
+ /** Set a label for a query (used for favorites) */
18
+ setLabel: (id: string, label: string) => boolean;
19
+ /** Search history by pattern (matches query text or label) */
20
+ searchHistory: (pattern: string) => QueryHistoryEntry[];
21
+ /** Get most recent queries (optionally excluding favorites) */
22
+ getRecentQueries: (limit?: number, excludeFavorites?: boolean) => QueryHistoryEntry[];
23
+ /** Get a specific entry by ID */
24
+ getEntry: (id: string) => QueryHistoryEntry | undefined;
25
+ /** Update metadata for an entry */
26
+ updateMetadata: (id: string, metadata: QueryHistoryEntry["metadata"]) => boolean;
27
+ /** Export history as JSON string */
28
+ exportHistory: () => string;
29
+ /** Import history from JSON string */
30
+ importHistory: (json: string, merge?: boolean) => number;
31
+ /** Check if storage is available */
32
+ isStorageAvailable: ComputedRef<boolean>;
33
+ }
34
+ export declare function useQueryHistory(options?: UseQueryHistoryOptions): UseQueryHistoryReturn;
35
+ export type { QueryHistoryEntry, UseQueryHistoryOptions };
@@ -0,0 +1,176 @@
1
+ import { ref as v, watch as Q, computed as d } from "vue";
2
+ const _ = {
3
+ maxHistory: 100,
4
+ storageKey: "tql-history",
5
+ storage: typeof localStorage < "u" ? localStorage : null,
6
+ deduplicate: !0
7
+ };
8
+ function L(y) {
9
+ const o = { ..._, ...y }, l = v(!1);
10
+ try {
11
+ if (o.storage) {
12
+ const e = "__tql_storage_test__";
13
+ o.storage.setItem(e, "test"), o.storage.removeItem(e), l.value = !0;
14
+ }
15
+ } catch {
16
+ l.value = !1;
17
+ }
18
+ const r = v([]);
19
+ if (l.value && o.storage)
20
+ try {
21
+ const e = o.storage.getItem(o.storageKey);
22
+ if (e) {
23
+ const t = JSON.parse(e);
24
+ Array.isArray(t) && (r.value = t);
25
+ }
26
+ } catch {
27
+ r.value = [];
28
+ }
29
+ Q(
30
+ r,
31
+ (e) => {
32
+ if (l.value && o.storage)
33
+ try {
34
+ o.storage.setItem(o.storageKey, JSON.stringify(e));
35
+ } catch (t) {
36
+ if (t instanceof Error && t.name === "QuotaExceededError") {
37
+ const i = e.filter((a) => !a.isFavorite);
38
+ if (i.length > 0) {
39
+ const a = i.slice(0, Math.ceil(i.length / 2));
40
+ r.value = e.filter(
41
+ (n) => !a.some((s) => s.id === n.id)
42
+ );
43
+ }
44
+ }
45
+ }
46
+ },
47
+ { deep: !0 }
48
+ );
49
+ const m = d(
50
+ () => r.value.filter((e) => e.isFavorite)
51
+ ), g = d(() => l.value);
52
+ function f() {
53
+ return `${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;
54
+ }
55
+ function p(e, t) {
56
+ const i = e.trim();
57
+ if (!i)
58
+ throw new Error("Cannot add empty query to history");
59
+ if (o.deduplicate) {
60
+ const n = r.value.findIndex((s) => s.query === i);
61
+ if (n !== -1) {
62
+ const s = r.value[n];
63
+ r.value.splice(n, 1);
64
+ const u = {
65
+ ...s,
66
+ timestamp: Date.now(),
67
+ metadata: { ...s.metadata, ...t }
68
+ };
69
+ return r.value.unshift(u), u;
70
+ }
71
+ }
72
+ const a = {
73
+ id: f(),
74
+ query: i,
75
+ timestamp: Date.now(),
76
+ isFavorite: !1,
77
+ metadata: t
78
+ };
79
+ return r.value.unshift(a), c(), a;
80
+ }
81
+ function c() {
82
+ const e = r.value.filter((t) => !t.isFavorite);
83
+ if (e.length > o.maxHistory) {
84
+ const t = e.length - o.maxHistory, i = new Set(
85
+ e.slice(-t).map((a) => a.id)
86
+ );
87
+ r.value = r.value.filter((a) => !i.has(a.id));
88
+ }
89
+ }
90
+ function h(e) {
91
+ const t = r.value.findIndex((i) => i.id === e);
92
+ return t === -1 ? !1 : (r.value.splice(t, 1), !0);
93
+ }
94
+ function x(e = !1) {
95
+ e ? r.value = r.value.filter((t) => t.isFavorite) : r.value = [];
96
+ }
97
+ function w(e) {
98
+ const t = r.value.find((i) => i.id === e);
99
+ return t ? (t.isFavorite = !t.isFavorite, !0) : !1;
100
+ }
101
+ function F(e, t) {
102
+ const i = r.value.find((a) => a.id === e);
103
+ return i ? (i.label = t.trim() || void 0, !0) : !1;
104
+ }
105
+ function S(e) {
106
+ if (!e.trim())
107
+ return [...r.value];
108
+ const t = e.toLowerCase();
109
+ return r.value.filter((i) => {
110
+ var a;
111
+ return !!(i.query.toLowerCase().includes(t) || (a = i.label) != null && a.toLowerCase().includes(t));
112
+ });
113
+ }
114
+ function E(e = 10, t = !1) {
115
+ let i = [...r.value];
116
+ return t && (i = i.filter((a) => !a.isFavorite)), i.sort((a, n) => n.timestamp - a.timestamp), i.slice(0, e);
117
+ }
118
+ function I(e) {
119
+ return r.value.find((t) => t.id === e);
120
+ }
121
+ function b(e, t) {
122
+ const i = r.value.find((a) => a.id === e);
123
+ return i ? (i.metadata = { ...i.metadata, ...t }, !0) : !1;
124
+ }
125
+ function q() {
126
+ return JSON.stringify(r.value, null, 2);
127
+ }
128
+ function H(e, t = !0) {
129
+ try {
130
+ const i = JSON.parse(e);
131
+ if (!Array.isArray(i))
132
+ throw new Error("Invalid history format: expected array");
133
+ const a = [];
134
+ for (const n of i)
135
+ A(n) && a.push({
136
+ ...n,
137
+ id: f()
138
+ });
139
+ if (t) {
140
+ const n = new Set(r.value.map((u) => u.query)), s = a.filter(
141
+ (u) => !n.has(u.query)
142
+ );
143
+ r.value = [...r.value, ...s];
144
+ } else
145
+ r.value = a;
146
+ return c(), a.length;
147
+ } catch {
148
+ return 0;
149
+ }
150
+ }
151
+ function A(e) {
152
+ if (typeof e != "object" || e === null)
153
+ return !1;
154
+ const t = e;
155
+ return typeof t.query == "string" && typeof t.timestamp == "number" && typeof t.isFavorite == "boolean";
156
+ }
157
+ return {
158
+ history: r,
159
+ favorites: m,
160
+ addQuery: p,
161
+ removeQuery: h,
162
+ clearHistory: x,
163
+ toggleFavorite: w,
164
+ setLabel: F,
165
+ searchHistory: S,
166
+ getRecentQueries: E,
167
+ getEntry: I,
168
+ updateMetadata: b,
169
+ exportHistory: q,
170
+ importHistory: H,
171
+ isStorageAvailable: g
172
+ };
173
+ }
174
+ export {
175
+ L as useQueryHistory
176
+ };
@@ -7,4 +7,6 @@
7
7
  */
8
8
  export { default as TqlInput } from './TqlInput.vue';
9
9
  export { default as TqlAutocomplete } from './TqlAutocomplete.vue';
10
+ export { default as TqlPreview } from './components/TqlPreview.vue';
10
11
  export { useTqlInput, type UseTqlInputOptions } from './useTqlInput';
12
+ export { useQueryHistory, type UseQueryHistoryReturn, type QueryHistoryEntry, type UseQueryHistoryOptions } from './composables/useQueryHistory';
package/dist/vue/index.js CHANGED
@@ -1,8 +1,12 @@
1
- import { default as o } from "./TqlInput.vue.js";
2
- import { default as p } from "./TqlAutocomplete.vue.js";
3
- import { useTqlInput as u } from "./useTqlInput.js";
1
+ import { default as r } from "./TqlInput.vue.js";
2
+ import { default as u } from "./TqlAutocomplete.vue.js";
3
+ import { default as l } from "./components/TqlPreview.vue.js";
4
+ import { useTqlInput as a } from "./useTqlInput.js";
5
+ import { useQueryHistory as s } from "./composables/useQueryHistory.js";
4
6
  export {
5
- p as TqlAutocomplete,
6
- o as TqlInput,
7
- u as useTqlInput
7
+ u as TqlAutocomplete,
8
+ r as TqlInput,
9
+ l as TqlPreview,
10
+ s as useQueryHistory,
11
+ a as useTqlInput
8
12
  };