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