@tellaro/tql 0.1.9 → 0.1.11

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,174 +1,168 @@
1
- import { useDebounceFn as R } from "@vueuse/core";
2
- import { ref as v, computed as T, watch as re } from "vue";
3
- import { getCompletions as ue, shouldTriggerCompletion as le } from "../src/completionProvider.js";
4
- import { parseTql as ae } from "../src/parser.js";
5
- import { findTokenAtPosition as U, tokenizeTql as ie } from "../src/tokenizer.js";
6
- import { validateTql as ce } from "../src/validator.js";
7
- function Te(V) {
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: pe,
12
+ snippets: ce,
13
13
  // Reserved for future snippet support
14
- fieldValues: w,
14
+ fieldValues: y,
15
15
  validateOnInput: j = !0,
16
16
  debounceMs: Q = 300,
17
- completionDebounceMs: _ = 50,
17
+ completionDebounceMs: U = 50,
18
18
  // Faster debounce for completions
19
- autocomplete: C = !0,
20
- onValidation: x,
21
- onParse: y
22
- } = V, f = v([]), q = v(null), g = v(null), c = v(0), d = v([]), p = v(!1), A = v(!1);
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 = g.value) == null ? void 0 : e.valid) ?? !0;
24
+ return ((e = m.value) == null ? void 0 : e.valid) ?? !0;
27
25
  }), b = T(() => {
28
26
  var e;
29
- return ((e = g.value) == null ? void 0 : e.errors) ?? [];
30
- }), D = T(() => {
27
+ return ((e = m.value) == null ? void 0 : e.errors) ?? [];
28
+ }), P = T(() => {
31
29
  var e;
32
- return ((e = g.value) == null ? void 0 : e.warnings) ?? [];
33
- }), B = T(() => b.value.length > 0), G = T(() => D.value.length > 0);
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 f.value = ie(i.value), f.value;
33
+ return v.value = ae(i.value), v.value;
36
34
  }
37
- function H() {
38
- const e = ae(i.value);
39
- return q.value = e, y == null || y(e), e;
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 o, r;
43
- A.value = !0;
44
- const e = (o = u == null ? void 0 : u.value) == null ? void 0 : o.map((l) => l.name), t = (r = u == null ? void 0 : u.value) == null ? void 0 : r.reduce(
45
- (l, m) => (l[m.name] = m.type, 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 = ce(i.value, {
45
+ ), n = ie(i.value, {
48
46
  availableFields: e,
49
47
  fieldTypes: t,
50
48
  strictMode: !1
51
49
  });
52
- return g.value = n, A.value = !1, x == null || x(n), n;
50
+ return m.value = n, q.value = !1, C == null || C(n), n;
53
51
  }
54
- const J = R(E, Q), K = R(I, _);
52
+ const H = O(E, Q), J = O(I, U);
55
53
  function I() {
56
- if (!C) {
57
- d.value = [], p.value = !1;
54
+ if (!A) {
55
+ g.value = [], f.value = !1;
58
56
  return;
59
57
  }
60
- if (Date.now() < P) {
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: w == null ? void 0 : w.value,
65
+ fieldValues: y == null ? void 0 : y.value,
72
66
  includeSnippets: !0,
73
67
  maxItems: 15
74
68
  }
75
69
  );
76
- d.value = e, p.value = e.length > 0;
70
+ g.value = e, f.value = e.length > 0;
77
71
  }
78
- function L() {
79
- I(), p.value = d.value.length > 0;
72
+ function K() {
73
+ I(), f.value = g.value.length > 0;
80
74
  }
81
- function O() {
82
- p.value = !1;
75
+ function W() {
76
+ f.value = !1;
83
77
  }
84
- function W(e) {
85
- M(), j && J(), C && le(e, c.value) && (K(), d.value.length > 0 && (p.value = !0));
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 N(e) {
81
+ function L(e) {
88
82
  c.value = e, I();
89
83
  }
90
- function X(e) {
91
- const t = i.value, n = c.value, o = U(f.value, n);
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 (o && o.type !== "whitespace")
94
- r = o.start, l = o.end;
87
+ if (s && s.type !== "whitespace")
88
+ r = s.start, l = s.end;
95
89
  else {
96
- const a = f.value.filter((s) => s.end <= n && s.type !== "whitespace");
90
+ const a = v.value.filter((o) => o.end <= n && o.type !== "whitespace");
97
91
  if (a.length > 0) {
98
- const s = a[a.length - 1];
99
- s.end === n && (r = s.start, l = s.end);
92
+ const o = a[a.length - 1];
93
+ o.end === n && (r = o.start, l = o.end);
100
94
  }
101
95
  }
102
- const m = t.substring(0, r), te = t.substring(l), k = [];
96
+ const d = t.substring(0, r), ee = t.substring(l), x = [];
103
97
  let h = e.insertText;
104
- const ne = [...e.insertText.matchAll(/\$(\d+)/g)].sort(
105
- (a, s) => parseInt(a[1]) - parseInt(s[1])
98
+ const te = [...e.insertText.matchAll(/\$(\d+)/g)].sort(
99
+ (a, o) => parseInt(a[1]) - parseInt(o[1])
106
100
  );
107
- let z = 0;
108
- for (const a of ne) {
109
- const s = h.indexOf(a[0]);
110
- if (s !== -1) {
111
- const F = r + s - z;
112
- k.push({
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], ""), z += a[0].length;
110
+ }), h = h.replace(a[0], ""), D += a[0].length;
117
111
  }
118
112
  }
119
- const oe = m + h + te, se = k.length > 0 ? k[0].start : r + h.length;
120
- return O(), e.kind === "logicalOp" && (P = Date.now() + 150), { query: oe, newCursorPosition: se, placeholders: k };
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 Y(e) {
123
- const t = i.value, n = c.value, o = t.substring(0, n), r = t.substring(n), m = o.length > 0 && !o.endsWith(" ") && !o.endsWith("(") ? " " : "";
124
- return o + m + e.insertText + r;
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 Z() {
127
- return U(f.value, c.value);
120
+ function Y() {
121
+ return R(v.value, c.value);
128
122
  }
129
- function S(e) {
123
+ function Z(e) {
130
124
  return b.value.some((t) => e >= t.start && e < t.end);
131
125
  }
132
- function ee(e) {
126
+ function S(e) {
133
127
  return b.value.filter((t) => e >= t.start && e < t.end);
134
128
  }
135
- return re(
129
+ return oe(
136
130
  i,
137
131
  (e) => {
138
- e !== void 0 && W(e);
132
+ e !== void 0 && z(e);
139
133
  },
140
134
  { immediate: !0 }
141
135
  ), {
142
136
  // State
143
- tokens: f,
144
- parseResult: q,
145
- validationResult: g,
137
+ tokens: v,
138
+ parseResult: w,
139
+ validationResult: m,
146
140
  cursorPosition: c,
147
- completionItems: d,
148
- showAutocomplete: p,
149
- isValidating: A,
141
+ completionItems: g,
142
+ showAutocomplete: f,
143
+ isValidating: q,
150
144
  // Computed
151
- isValid: $,
145
+ isValid: _,
152
146
  errors: b,
153
- warnings: D,
154
- hasErrors: B,
155
- hasWarnings: G,
147
+ warnings: P,
148
+ hasErrors: $,
149
+ hasWarnings: B,
156
150
  // Methods
157
151
  tokenize: M,
158
- parse: H,
152
+ parse: G,
159
153
  validate: E,
160
154
  updateCompletions: I,
161
- triggerAutocomplete: L,
162
- hideAutocomplete: O,
163
- handleInput: W,
164
- handleCursorChange: N,
165
- insertCompletion: X,
166
- insertSnippet: Y,
167
- getTokenAtCursor: Z,
168
- isPositionInError: S,
169
- getErrorsAtPosition: ee
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
- Te as useTqlInput
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.9",
3
+ "version": "0.1.11",
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",