@tellaro/tql 0.1.9 → 0.1.10
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/vue/useTqlInput.js
CHANGED
|
@@ -1,174 +1,168 @@
|
|
|
1
|
-
import { useDebounceFn as
|
|
2
|
-
import { ref as
|
|
3
|
-
import { getCompletions as
|
|
4
|
-
import { parseTql as
|
|
5
|
-
import { findTokenAtPosition as
|
|
6
|
-
import { validateTql as
|
|
7
|
-
function
|
|
1
|
+
import { useDebounceFn as O } from "@vueuse/core";
|
|
2
|
+
import { ref as p, computed as T, watch as oe } from "vue";
|
|
3
|
+
import { getCompletions as re, shouldTriggerCompletion as ue } from "../src/completionProvider.js";
|
|
4
|
+
import { parseTql as le } from "../src/parser.js";
|
|
5
|
+
import { findTokenAtPosition as R, tokenizeTql as ae } from "../src/tokenizer.js";
|
|
6
|
+
import { validateTql as ie } from "../src/validator.js";
|
|
7
|
+
function he(V) {
|
|
8
8
|
const {
|
|
9
9
|
modelValue: i,
|
|
10
10
|
fieldSchema: u,
|
|
11
11
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
12
|
-
snippets:
|
|
12
|
+
snippets: ce,
|
|
13
13
|
// Reserved for future snippet support
|
|
14
|
-
fieldValues:
|
|
14
|
+
fieldValues: y,
|
|
15
15
|
validateOnInput: j = !0,
|
|
16
16
|
debounceMs: Q = 300,
|
|
17
|
-
completionDebounceMs:
|
|
17
|
+
completionDebounceMs: U = 50,
|
|
18
18
|
// Faster debounce for completions
|
|
19
|
-
autocomplete:
|
|
20
|
-
onValidation:
|
|
21
|
-
onParse:
|
|
22
|
-
} = V,
|
|
23
|
-
let P = 0;
|
|
24
|
-
const $ = T(() => {
|
|
19
|
+
autocomplete: A = !0,
|
|
20
|
+
onValidation: C,
|
|
21
|
+
onParse: k
|
|
22
|
+
} = V, v = p([]), w = p(null), m = p(null), c = p(0), g = p([]), f = p(!1), q = p(!1), _ = T(() => {
|
|
25
23
|
var e;
|
|
26
|
-
return ((e =
|
|
24
|
+
return ((e = m.value) == null ? void 0 : e.valid) ?? !0;
|
|
27
25
|
}), b = T(() => {
|
|
28
26
|
var e;
|
|
29
|
-
return ((e =
|
|
30
|
-
}),
|
|
27
|
+
return ((e = m.value) == null ? void 0 : e.errors) ?? [];
|
|
28
|
+
}), P = T(() => {
|
|
31
29
|
var e;
|
|
32
|
-
return ((e =
|
|
33
|
-
}),
|
|
30
|
+
return ((e = m.value) == null ? void 0 : e.warnings) ?? [];
|
|
31
|
+
}), $ = T(() => b.value.length > 0), B = T(() => P.value.length > 0);
|
|
34
32
|
function M() {
|
|
35
|
-
return
|
|
33
|
+
return v.value = ae(i.value), v.value;
|
|
36
34
|
}
|
|
37
|
-
function
|
|
38
|
-
const e =
|
|
39
|
-
return
|
|
35
|
+
function G() {
|
|
36
|
+
const e = le(i.value);
|
|
37
|
+
return w.value = e, k == null || k(e), e;
|
|
40
38
|
}
|
|
41
39
|
function E() {
|
|
42
|
-
var
|
|
43
|
-
|
|
44
|
-
const e = (
|
|
45
|
-
(l,
|
|
40
|
+
var s, r;
|
|
41
|
+
q.value = !0;
|
|
42
|
+
const e = (s = u == null ? void 0 : u.value) == null ? void 0 : s.map((l) => l.name), t = (r = u == null ? void 0 : u.value) == null ? void 0 : r.reduce(
|
|
43
|
+
(l, d) => (l[d.name] = d.type, l),
|
|
46
44
|
{}
|
|
47
|
-
), n =
|
|
45
|
+
), n = ie(i.value, {
|
|
48
46
|
availableFields: e,
|
|
49
47
|
fieldTypes: t,
|
|
50
48
|
strictMode: !1
|
|
51
49
|
});
|
|
52
|
-
return
|
|
50
|
+
return m.value = n, q.value = !1, C == null || C(n), n;
|
|
53
51
|
}
|
|
54
|
-
const
|
|
52
|
+
const H = O(E, Q), J = O(I, U);
|
|
55
53
|
function I() {
|
|
56
|
-
if (!
|
|
57
|
-
|
|
54
|
+
if (!A) {
|
|
55
|
+
g.value = [], f.value = !1;
|
|
58
56
|
return;
|
|
59
57
|
}
|
|
60
|
-
|
|
61
|
-
d.value = [], p.value = !1;
|
|
62
|
-
return;
|
|
63
|
-
}
|
|
64
|
-
const e = ue(
|
|
58
|
+
const e = re(
|
|
65
59
|
{
|
|
66
60
|
query: i.value,
|
|
67
61
|
cursorPosition: c.value
|
|
68
62
|
},
|
|
69
63
|
{
|
|
70
64
|
fields: u == null ? void 0 : u.value,
|
|
71
|
-
fieldValues:
|
|
65
|
+
fieldValues: y == null ? void 0 : y.value,
|
|
72
66
|
includeSnippets: !0,
|
|
73
67
|
maxItems: 15
|
|
74
68
|
}
|
|
75
69
|
);
|
|
76
|
-
|
|
70
|
+
g.value = e, f.value = e.length > 0;
|
|
77
71
|
}
|
|
78
|
-
function
|
|
79
|
-
I(),
|
|
72
|
+
function K() {
|
|
73
|
+
I(), f.value = g.value.length > 0;
|
|
80
74
|
}
|
|
81
|
-
function
|
|
82
|
-
|
|
75
|
+
function W() {
|
|
76
|
+
f.value = !1;
|
|
83
77
|
}
|
|
84
|
-
function
|
|
85
|
-
M(), j &&
|
|
78
|
+
function z(e) {
|
|
79
|
+
M(), j && H(), A && ue(e, c.value) && (J(), g.value.length > 0 && (f.value = !0));
|
|
86
80
|
}
|
|
87
|
-
function
|
|
81
|
+
function L(e) {
|
|
88
82
|
c.value = e, I();
|
|
89
83
|
}
|
|
90
|
-
function
|
|
91
|
-
const t = i.value, n = c.value,
|
|
84
|
+
function N(e) {
|
|
85
|
+
const t = i.value, n = c.value, s = R(v.value, n);
|
|
92
86
|
let r = n, l = n;
|
|
93
|
-
if (
|
|
94
|
-
r =
|
|
87
|
+
if (s && s.type !== "whitespace")
|
|
88
|
+
r = s.start, l = s.end;
|
|
95
89
|
else {
|
|
96
|
-
const a =
|
|
90
|
+
const a = v.value.filter((o) => o.end <= n && o.type !== "whitespace");
|
|
97
91
|
if (a.length > 0) {
|
|
98
|
-
const
|
|
99
|
-
|
|
92
|
+
const o = a[a.length - 1];
|
|
93
|
+
o.end === n && (r = o.start, l = o.end);
|
|
100
94
|
}
|
|
101
95
|
}
|
|
102
|
-
const
|
|
96
|
+
const d = t.substring(0, r), ee = t.substring(l), x = [];
|
|
103
97
|
let h = e.insertText;
|
|
104
|
-
const
|
|
105
|
-
(a,
|
|
98
|
+
const te = [...e.insertText.matchAll(/\$(\d+)/g)].sort(
|
|
99
|
+
(a, o) => parseInt(a[1]) - parseInt(o[1])
|
|
106
100
|
);
|
|
107
|
-
let
|
|
108
|
-
for (const a of
|
|
109
|
-
const
|
|
110
|
-
if (
|
|
111
|
-
const F = r +
|
|
112
|
-
|
|
101
|
+
let D = 0;
|
|
102
|
+
for (const a of te) {
|
|
103
|
+
const o = h.indexOf(a[0]);
|
|
104
|
+
if (o !== -1) {
|
|
105
|
+
const F = r + o - D;
|
|
106
|
+
x.push({
|
|
113
107
|
start: F,
|
|
114
108
|
end: F
|
|
115
109
|
// Zero-width cursor position
|
|
116
|
-
}), h = h.replace(a[0], ""),
|
|
110
|
+
}), h = h.replace(a[0], ""), D += a[0].length;
|
|
117
111
|
}
|
|
118
112
|
}
|
|
119
|
-
const
|
|
120
|
-
return
|
|
113
|
+
const ne = d + h + ee, se = x.length > 0 ? x[0].start : r + h.length;
|
|
114
|
+
return W(), { query: ne, newCursorPosition: se, placeholders: x };
|
|
121
115
|
}
|
|
122
|
-
function
|
|
123
|
-
const t = i.value, n = c.value,
|
|
124
|
-
return
|
|
116
|
+
function X(e) {
|
|
117
|
+
const t = i.value, n = c.value, s = t.substring(0, n), r = t.substring(n), d = s.length > 0 && !s.endsWith(" ") && !s.endsWith("(") ? " " : "";
|
|
118
|
+
return s + d + e.insertText + r;
|
|
125
119
|
}
|
|
126
|
-
function
|
|
127
|
-
return
|
|
120
|
+
function Y() {
|
|
121
|
+
return R(v.value, c.value);
|
|
128
122
|
}
|
|
129
|
-
function
|
|
123
|
+
function Z(e) {
|
|
130
124
|
return b.value.some((t) => e >= t.start && e < t.end);
|
|
131
125
|
}
|
|
132
|
-
function
|
|
126
|
+
function S(e) {
|
|
133
127
|
return b.value.filter((t) => e >= t.start && e < t.end);
|
|
134
128
|
}
|
|
135
|
-
return
|
|
129
|
+
return oe(
|
|
136
130
|
i,
|
|
137
131
|
(e) => {
|
|
138
|
-
e !== void 0 &&
|
|
132
|
+
e !== void 0 && z(e);
|
|
139
133
|
},
|
|
140
134
|
{ immediate: !0 }
|
|
141
135
|
), {
|
|
142
136
|
// State
|
|
143
|
-
tokens:
|
|
144
|
-
parseResult:
|
|
145
|
-
validationResult:
|
|
137
|
+
tokens: v,
|
|
138
|
+
parseResult: w,
|
|
139
|
+
validationResult: m,
|
|
146
140
|
cursorPosition: c,
|
|
147
|
-
completionItems:
|
|
148
|
-
showAutocomplete:
|
|
149
|
-
isValidating:
|
|
141
|
+
completionItems: g,
|
|
142
|
+
showAutocomplete: f,
|
|
143
|
+
isValidating: q,
|
|
150
144
|
// Computed
|
|
151
|
-
isValid:
|
|
145
|
+
isValid: _,
|
|
152
146
|
errors: b,
|
|
153
|
-
warnings:
|
|
154
|
-
hasErrors:
|
|
155
|
-
hasWarnings:
|
|
147
|
+
warnings: P,
|
|
148
|
+
hasErrors: $,
|
|
149
|
+
hasWarnings: B,
|
|
156
150
|
// Methods
|
|
157
151
|
tokenize: M,
|
|
158
|
-
parse:
|
|
152
|
+
parse: G,
|
|
159
153
|
validate: E,
|
|
160
154
|
updateCompletions: I,
|
|
161
|
-
triggerAutocomplete:
|
|
162
|
-
hideAutocomplete:
|
|
163
|
-
handleInput:
|
|
164
|
-
handleCursorChange:
|
|
165
|
-
insertCompletion:
|
|
166
|
-
insertSnippet:
|
|
167
|
-
getTokenAtCursor:
|
|
168
|
-
isPositionInError:
|
|
169
|
-
getErrorsAtPosition:
|
|
155
|
+
triggerAutocomplete: K,
|
|
156
|
+
hideAutocomplete: W,
|
|
157
|
+
handleInput: z,
|
|
158
|
+
handleCursorChange: L,
|
|
159
|
+
insertCompletion: N,
|
|
160
|
+
insertSnippet: X,
|
|
161
|
+
getTokenAtCursor: Y,
|
|
162
|
+
isPositionInError: Z,
|
|
163
|
+
getErrorsAtPosition: S
|
|
170
164
|
};
|
|
171
165
|
}
|
|
172
166
|
export {
|
|
173
|
-
|
|
167
|
+
he as useTqlInput
|
|
174
168
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tellaro/tql",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.10",
|
|
4
4
|
"description": "Tellaro Query Language (TQL) parser, validator, and autocomplete for JavaScript/TypeScript",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -27,6 +27,10 @@
|
|
|
27
27
|
"test": "vitest run",
|
|
28
28
|
"test:watch": "vitest",
|
|
29
29
|
"test:shared": "vitest run --grep 'shared-fixtures'",
|
|
30
|
+
"test:e2e": "playwright test",
|
|
31
|
+
"test:e2e:ui": "playwright test --ui",
|
|
32
|
+
"playground:serve": "vite --config vite.playground.config.ts --port 5174",
|
|
33
|
+
"playground:dev": "vite --config vite.playground.config.ts",
|
|
30
34
|
"lint": "eslint src vue tests --ext .ts,.vue",
|
|
31
35
|
"typecheck": "vue-tsc --noEmit",
|
|
32
36
|
"prepublishOnly": "npm run build"
|
|
@@ -61,6 +65,7 @@
|
|
|
61
65
|
}
|
|
62
66
|
},
|
|
63
67
|
"devDependencies": {
|
|
68
|
+
"@playwright/test": "^1.40.0",
|
|
64
69
|
"@types/js-yaml": "^4.0.9",
|
|
65
70
|
"@types/node": "^20.11.0",
|
|
66
71
|
"@vitejs/plugin-vue": "^5.0.0",
|