@nongt/visql-core 0.10.1 → 0.11.0
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/core.js +137 -119
- package/dist/explain.js +3 -3
- package/dist/fixtures.js +1 -1
- package/dist/issueLocation-Yn71qJyP.js +1141 -0
- package/dist/{params-DkVFbMQn.js → params-DVkfcD6D.js} +245 -229
- package/dist/{schema-CgL10bid.js → schema-CzKt6cN2.js} +230 -152
- package/dist/sql-import.js +855 -821
- package/dist/{sqlGen-C1kZwvWI.js → sqlGen-BoJXaULd.js} +331 -309
- package/dist/types/core/ast.d.ts +9 -1
- package/dist/types/core/functionRegistry.d.ts +15 -2
- package/dist/types/core/i18n/defaultMessages.d.ts +16 -0
- package/dist/types/core/issueLocation.d.ts +5 -0
- package/dist/types/core/queryHelpers.d.ts +9 -1
- package/dist/types/core/queryValidation.d.ts +11 -1
- package/dist/types/core/storedQuery.d.ts +1 -1
- package/dist/types/sqlImport/syntax.d.ts +11 -2
- package/package.json +1 -1
- package/dist/issueLocation-BlQ280IE.js +0 -1108
package/dist/core.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
var N = Object.defineProperty;
|
|
2
2
|
var I = (e, t, r) => t in e ? N(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r;
|
|
3
|
-
var
|
|
4
|
-
import { l as
|
|
5
|
-
import { D as
|
|
6
|
-
import { au as D, t as L, av as
|
|
7
|
-
import { M as
|
|
8
|
-
import { c as
|
|
9
|
-
import { Q as
|
|
10
|
-
import { D as dt, c as
|
|
11
|
-
const q = (e) => typeof e == "object" && e !== null && !(e instanceof Date),
|
|
3
|
+
var v = (e, t, r) => I(e, typeof t != "symbol" ? t + "" : t, r);
|
|
4
|
+
import { l as w, q as B, t as A, h as O } from "./schema-CzKt6cN2.js";
|
|
5
|
+
import { D as pe, E as ye, M as ce, b as de, f as fe, a as me, c as he, i as be, r as ge, s as Se, v as Ee } from "./schema-CzKt6cN2.js";
|
|
6
|
+
import { au as D, t as L, av as M, F as Q, $ as U, p as c, al as _, aw as i, ah as j } from "./params-DVkfcD6D.js";
|
|
7
|
+
import { M as we, a as Te, b as Ne, d as Ie, e as Be, f as Ae, g as Oe, c as De, h as Le, k as Me, m as Qe, q as Ue, r as _e, i as je, s as qe, j as xe, o as Ce, l as Re, n as $e, u as ke } from "./params-DVkfcD6D.js";
|
|
8
|
+
import { c as Je, f as Fe, i as Pe } from "./calendarDate-CYlr9TvX.js";
|
|
9
|
+
import { Q as Xe, l as Ye, S as We, a as Ke, n as Ve, f as ze, j as Ze, m as et, b as tt, k as rt, r as at, c as nt, g as st, h as it, i as ot, s as ut, d as lt, e as pt, v as yt } from "./issueLocation-Yn71qJyP.js";
|
|
10
|
+
import { D as dt, c as ft, S as mt, a as ht, b as bt, s as gt, u as St } from "./sqlGen-BoJXaULd.js";
|
|
11
|
+
const q = (e) => typeof e == "object" && e !== null && !(e instanceof Date), T = {
|
|
12
12
|
/** A column: `expr.field('orders', 'status')`. */
|
|
13
13
|
field: (e, t) => ({ type: "field", table: e, column: t }),
|
|
14
14
|
/** A literal value, written into the SQL (as a bound parameter by
|
|
@@ -63,6 +63,19 @@ const q = (e) => typeof e == "object" && e !== null && !(e instanceof Date), v =
|
|
|
63
63
|
name: e,
|
|
64
64
|
args: t
|
|
65
65
|
}),
|
|
66
|
+
/** A window function's call (issue 20), over the rows of its body:
|
|
67
|
+
* `expr.over(expr.fn('LAG', status), { partitionBy: [employee], orderBy:
|
|
68
|
+
* [{ expression: payDate, direction: 'asc' }] })` is `LAG(status) OVER
|
|
69
|
+
* (PARTITION BY employee ORDER BY pay_date ASC)`. */
|
|
70
|
+
over: (e, t) => {
|
|
71
|
+
var r, a;
|
|
72
|
+
return {
|
|
73
|
+
...e,
|
|
74
|
+
over: !0,
|
|
75
|
+
...((r = t.partitionBy) == null ? void 0 : r.length) && { partitionBy: t.partitionBy },
|
|
76
|
+
...((a = t.orderBy) == null ? void 0 : a.length) && { orderBy: t.orderBy }
|
|
77
|
+
};
|
|
78
|
+
},
|
|
66
79
|
/** Whether the outer row has related rows: `EXISTS (SELECT 1 FROM …
|
|
67
80
|
* WHERE <link> AND <where>)`. `link` matches them to the outer row;
|
|
68
81
|
* `where` names the subquery's own tables only. NOT EXISTS:
|
|
@@ -75,7 +88,7 @@ const q = (e) => typeof e == "object" && e !== null && !(e instanceof Date), v =
|
|
|
75
88
|
type: "binary",
|
|
76
89
|
operator: "IN",
|
|
77
90
|
left: e,
|
|
78
|
-
right: Array.isArray(t) ?
|
|
91
|
+
right: Array.isArray(t) ? T.list(...t) : t
|
|
79
92
|
}),
|
|
80
93
|
/** `left BETWEEN low AND high` (issue 169), both bounds included: each a
|
|
81
94
|
* value or an expression (a param, a relative date). NOT BETWEEN:
|
|
@@ -84,7 +97,7 @@ const q = (e) => typeof e == "object" && e !== null && !(e instanceof Date), v =
|
|
|
84
97
|
type: "binary",
|
|
85
98
|
operator: "BETWEEN",
|
|
86
99
|
left: e,
|
|
87
|
-
right:
|
|
100
|
+
right: T.list(t, r)
|
|
88
101
|
}),
|
|
89
102
|
/** IN's values: each a value (`expr.list(1, 2)`) or an expression
|
|
90
103
|
* (`expr.list(expr.param('a'), expr.param('b'))`). */
|
|
@@ -99,18 +112,18 @@ const q = (e) => typeof e == "object" && e !== null && !(e instanceof Date), v =
|
|
|
99
112
|
* 'customer_id') }))`. */
|
|
100
113
|
subquery: ({ select: e, ...t }) => ({
|
|
101
114
|
type: "subquery",
|
|
102
|
-
id:
|
|
103
|
-
query: { joins: [], ...t, select: [{ id:
|
|
115
|
+
id: w(),
|
|
116
|
+
query: { joins: [], ...t, select: [{ id: w(), expression: e }] }
|
|
104
117
|
})
|
|
105
118
|
};
|
|
106
|
-
function
|
|
119
|
+
function K(e, t, r) {
|
|
107
120
|
return i(e, t, { type: "setBaseTable", table: r });
|
|
108
121
|
}
|
|
109
|
-
function
|
|
122
|
+
function V(e, t, r, a = {}) {
|
|
110
123
|
const n = { type: "addJoin", table: r, ...a };
|
|
111
124
|
return i(e, t, n);
|
|
112
125
|
}
|
|
113
|
-
function
|
|
126
|
+
function z(e, t, r) {
|
|
114
127
|
return i(e, t, { type: "removeJoin", joinId: r });
|
|
115
128
|
}
|
|
116
129
|
function x(e, t, r, a = {}) {
|
|
@@ -119,39 +132,39 @@ function x(e, t, r, a = {}) {
|
|
|
119
132
|
if (s.includes(n.alias))
|
|
120
133
|
throw new Error("addCondition: a condition names both the union and tables of its branches: add it in two parts");
|
|
121
134
|
return n.query.union.forEach((l) => {
|
|
122
|
-
const m = l.from.table, h = new Set(
|
|
123
|
-
if (
|
|
124
|
-
throw new Error(`addCondition: "${
|
|
125
|
-
}), n.query.union.reduce((l, m, h) =>
|
|
135
|
+
const m = l.from.table, h = new Set(B(l).map(A)), b = M(e, m), S = s.find((E) => !h.has(E) && !b.has(E));
|
|
136
|
+
if (S)
|
|
137
|
+
throw new Error(`addCondition: "${S}" can't be reached from "${m}", one of the union's tables: a condition must reach every branch`);
|
|
138
|
+
}), n.query.union.reduce((l, m, h) => Q(
|
|
126
139
|
l,
|
|
127
140
|
[U(n.id, h)],
|
|
128
141
|
(b) => x(e, b, r, a)
|
|
129
142
|
), t);
|
|
130
143
|
}
|
|
131
144
|
const u = a.operator ?? "AND", { where: o } = t;
|
|
132
|
-
let
|
|
133
|
-
return o ? o.type === "logical" && o.operator === u ?
|
|
145
|
+
let d;
|
|
146
|
+
return o ? o.type === "logical" && o.operator === u ? d = { ...o, operands: [...o.operands, r] } : d = { type: "logical", operator: u, operands: [o, r] } : d = r, c(e, t, _(e, t, d));
|
|
134
147
|
}
|
|
135
|
-
function
|
|
148
|
+
function Z(e, t, r, a) {
|
|
136
149
|
const n = i(e, t, { type: "addSelectItem" }), s = n.select[n.select.length - 1].id, u = i(e, n, {
|
|
137
150
|
type: "setSelectExpression",
|
|
138
151
|
selectId: s,
|
|
139
152
|
expression: r
|
|
140
153
|
}), o = a === void 0 ? u : i(e, u, { type: "setSelectAlias", selectId: s, alias: a });
|
|
141
|
-
return
|
|
154
|
+
return c(e, t, o);
|
|
142
155
|
}
|
|
143
|
-
function
|
|
156
|
+
function ee(e, t, r) {
|
|
144
157
|
const a = i(e, t, { type: "addGroupByItem" }), { id: n } = a.groupBy[a.groupBy.length - 1], s = i(e, a, {
|
|
145
158
|
type: "setGroupByExpression",
|
|
146
159
|
groupById: n,
|
|
147
160
|
expression: r
|
|
148
161
|
});
|
|
149
|
-
return
|
|
162
|
+
return c(e, t, s);
|
|
150
163
|
}
|
|
151
|
-
function
|
|
152
|
-
return
|
|
164
|
+
function te(e, t, r) {
|
|
165
|
+
return c(e, t, j(e, t, r));
|
|
153
166
|
}
|
|
154
|
-
function
|
|
167
|
+
function re(e, t, r, a = "asc") {
|
|
155
168
|
const n = i(e, t, { type: "addOrderByItem" }), { id: s } = n.orderBy[n.orderBy.length - 1], u = i(e, n, {
|
|
156
169
|
type: "setOrderByExpression",
|
|
157
170
|
orderById: s,
|
|
@@ -161,28 +174,28 @@ function te(e, t, r, a = "asc") {
|
|
|
161
174
|
orderById: s,
|
|
162
175
|
direction: a
|
|
163
176
|
});
|
|
164
|
-
return
|
|
177
|
+
return c(e, t, o);
|
|
165
178
|
}
|
|
166
|
-
function
|
|
179
|
+
function ae(e, t, r) {
|
|
167
180
|
let a = t;
|
|
168
181
|
return "limit" in r && (a = i(e, a, { type: "setLimit", limit: r.limit })), "offset" in r && (a = i(e, a, { type: "setOffset", offset: r.offset })), a;
|
|
169
182
|
}
|
|
170
|
-
function
|
|
183
|
+
function ne(e, t, r) {
|
|
171
184
|
return i(e, t, { type: "setDistinct", distinct: r });
|
|
172
185
|
}
|
|
173
|
-
function
|
|
186
|
+
function se(e) {
|
|
174
187
|
if (!O(e)) throw new Error(`query "${e.id}" has no base table yet`);
|
|
175
188
|
return e;
|
|
176
189
|
}
|
|
177
|
-
const
|
|
190
|
+
const g = 5;
|
|
178
191
|
class p extends Error {
|
|
179
192
|
constructor(r, a) {
|
|
180
193
|
super(a);
|
|
181
|
-
|
|
194
|
+
v(this, "kind");
|
|
182
195
|
this.name = "QueryFormatError", this.kind = r;
|
|
183
196
|
}
|
|
184
197
|
}
|
|
185
|
-
const
|
|
198
|
+
const y = (e) => typeof e == "object" && e !== null && !Array.isArray(e);
|
|
186
199
|
function C(e) {
|
|
187
200
|
const t = [];
|
|
188
201
|
let r = 0;
|
|
@@ -205,25 +218,30 @@ function C(e) {
|
|
|
205
218
|
function R(e) {
|
|
206
219
|
const t = (r) => {
|
|
207
220
|
if (Array.isArray(r)) return r.map(t);
|
|
208
|
-
if (!
|
|
221
|
+
if (!y(r)) return r;
|
|
209
222
|
const a = Object.fromEntries(Object.entries(r).map(([u, o]) => [u, t(o)])), { right: n } = a;
|
|
210
|
-
if (a.type !== "binary" || a.operator !== "IN" || !
|
|
223
|
+
if (a.type !== "binary" || a.operator !== "IN" || !y(n) || n.type === "subquery" || n.type === "list") return a;
|
|
211
224
|
const s = n.type === "literal" && typeof n.value == "string" ? C(n.value).map((u) => ({ type: "literal", value: u })) : [n];
|
|
212
225
|
return { ...a, right: { type: "list", items: s } };
|
|
213
226
|
};
|
|
214
227
|
return t(e);
|
|
215
228
|
}
|
|
216
|
-
const $ = (e) => e, k = (e) => e, G =
|
|
217
|
-
|
|
229
|
+
const $ = (e) => e, k = (e) => e, G = (e) => e, J = [
|
|
230
|
+
R,
|
|
231
|
+
$,
|
|
232
|
+
k,
|
|
233
|
+
G
|
|
234
|
+
];
|
|
235
|
+
function F(e, t, r) {
|
|
218
236
|
return r.slice(t - 1).reduce((a, n) => n(a), e);
|
|
219
237
|
}
|
|
220
238
|
function f(e, t) {
|
|
221
|
-
return Array.isArray(e) ? e.map((r) => f(r, t)) :
|
|
239
|
+
return Array.isArray(e) ? e.map((r) => f(r, t)) : y(e) ? e.type === "literal" ? t(e) : Object.fromEntries(Object.entries(e).map(([r, a]) => [r, f(a, t)])) : e;
|
|
222
240
|
}
|
|
223
|
-
function
|
|
241
|
+
function P(e) {
|
|
224
242
|
return e.value instanceof Date ? { ...e, value: e.value.toISOString(), valueType: "date" } : typeof e.value == "bigint" ? { ...e, value: String(e.value), valueType: "bigint" } : e;
|
|
225
243
|
}
|
|
226
|
-
function
|
|
244
|
+
function H(e) {
|
|
227
245
|
if (e.valueType === void 0) return e;
|
|
228
246
|
const { valueType: t, ...r } = e, a = String(r.value);
|
|
229
247
|
let n;
|
|
@@ -238,104 +256,104 @@ function P(e) {
|
|
|
238
256
|
}
|
|
239
257
|
return { ...r, value: n };
|
|
240
258
|
}
|
|
241
|
-
function
|
|
259
|
+
function ie(e) {
|
|
242
260
|
return {
|
|
243
|
-
version:
|
|
244
|
-
query: f(e,
|
|
261
|
+
version: g,
|
|
262
|
+
query: f(e, P)
|
|
245
263
|
};
|
|
246
264
|
}
|
|
247
|
-
function
|
|
248
|
-
if (!
|
|
265
|
+
function oe(e) {
|
|
266
|
+
if (!y(e))
|
|
249
267
|
throw new p("invalid", "a stored query is an object");
|
|
250
268
|
const { version: t } = e;
|
|
251
269
|
if (typeof t != "number" || !Number.isInteger(t) || t < 1)
|
|
252
270
|
throw new p("invalid", "a stored query has a whole-number version from 1");
|
|
253
|
-
if (t >
|
|
271
|
+
if (t > g)
|
|
254
272
|
throw new p(
|
|
255
273
|
"newerVersion",
|
|
256
|
-
`stored in format ${t}; this version reads up to ${
|
|
274
|
+
`stored in format ${t}; this version reads up to ${g}`
|
|
257
275
|
);
|
|
258
|
-
const r =
|
|
259
|
-
if (!
|
|
276
|
+
const r = F(e.query, t, J);
|
|
277
|
+
if (!y(r) || typeof r.id != "string")
|
|
260
278
|
throw new p("invalid", "a stored query has a query with a string id");
|
|
261
|
-
return f(r,
|
|
279
|
+
return f(r, H);
|
|
262
280
|
}
|
|
263
281
|
export {
|
|
264
|
-
|
|
282
|
+
pe as DEFAULT_FUNCTIONS,
|
|
265
283
|
dt as DIALECTS,
|
|
266
|
-
|
|
267
|
-
|
|
284
|
+
ft as DIALECT_LABELS,
|
|
285
|
+
ye as EMPTY_SCHEMA,
|
|
268
286
|
ce as MAX_NAME_LENGTH,
|
|
269
|
-
|
|
287
|
+
we as MAX_NUMBER_DIGITS,
|
|
270
288
|
Te as MAX_TEXT_LENGTH,
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
289
|
+
Ne as MAX_TYPE_NAME_LENGTH,
|
|
290
|
+
g as QUERY_FORMAT_VERSION,
|
|
291
|
+
Xe as QUERY_ISSUE_KINDS,
|
|
292
|
+
Ye as QUERY_WARNING_KINDS,
|
|
275
293
|
p as QueryFormatError,
|
|
276
|
-
|
|
277
|
-
|
|
294
|
+
mt as ScopeError,
|
|
295
|
+
We as SharedBaseError,
|
|
278
296
|
x as addCondition,
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
297
|
+
ee as addGroupBy,
|
|
298
|
+
V as addJoin,
|
|
299
|
+
Ie as addMeasure,
|
|
300
|
+
re as addOrderBy,
|
|
301
|
+
Z as addSelectItem,
|
|
302
|
+
Ke as addSharedQuery,
|
|
303
|
+
Be as addUnionBranch,
|
|
286
304
|
Ae as addUnionJoin,
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
305
|
+
Oe as addUnionTable,
|
|
306
|
+
ht as astToParameterizedSql,
|
|
307
|
+
bt as astToSql,
|
|
290
308
|
de as branchesOf,
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
309
|
+
Je as calendarDay,
|
|
310
|
+
De as createEmptyQuery,
|
|
311
|
+
Le as createUnion,
|
|
312
|
+
T as expr,
|
|
313
|
+
fe as filterSchema,
|
|
314
|
+
me as findJoinPath,
|
|
315
|
+
Fe as fromIsoDay,
|
|
316
|
+
he as functionsForDialect,
|
|
299
317
|
O as hasBaseTable,
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
318
|
+
be as isUnion,
|
|
319
|
+
Pe as isoDay,
|
|
320
|
+
Ve as issueLocation,
|
|
321
|
+
ze as joinMultiplicity,
|
|
322
|
+
Ze as joinSharedQuery,
|
|
323
|
+
Me as keepMeasuresInStep,
|
|
324
|
+
oe as loadQuery,
|
|
325
|
+
et as makeShared,
|
|
326
|
+
tt as makeSubQuery,
|
|
309
327
|
Qe as measureFacts,
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
328
|
+
Ue as queryParams,
|
|
329
|
+
ge as reachableTables,
|
|
330
|
+
rt as relativeDateLabel,
|
|
331
|
+
z as removeJoin,
|
|
332
|
+
at as removeSharedQuery,
|
|
333
|
+
_e as removeUnionTable,
|
|
334
|
+
nt as renameSharedQuery,
|
|
335
|
+
je as renameUnionColumn,
|
|
336
|
+
st as repeatedReads,
|
|
337
|
+
it as repeatedTables,
|
|
338
|
+
se as requireBaseTable,
|
|
339
|
+
ot as rowsPerBase,
|
|
340
|
+
ie as saveQuery,
|
|
341
|
+
gt as scopeQuery,
|
|
342
|
+
K as setBaseTable,
|
|
343
|
+
ne as setDistinct,
|
|
344
|
+
te as setHaving,
|
|
345
|
+
ae as setPaging,
|
|
346
|
+
ut as setSharedBase,
|
|
347
|
+
qe as setUnionAll,
|
|
348
|
+
lt as sharedQueryName,
|
|
349
|
+
pt as sharedUses,
|
|
332
350
|
Se as suggestJoin,
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
351
|
+
xe as unionName,
|
|
352
|
+
Ce as unionTableColumns,
|
|
353
|
+
Re as unionWithQuery,
|
|
354
|
+
$e as unionableTables,
|
|
337
355
|
St as unscopedBodies,
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
356
|
+
ke as unwrapUnion,
|
|
357
|
+
yt as validateQuery,
|
|
358
|
+
Ee as validateSchema
|
|
341
359
|
};
|
package/dist/explain.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { y as Y, m as G } from "./schema-
|
|
2
|
-
import { B as V } from "./params-
|
|
3
|
-
import { s as Z, b as tt, a as et } from "./sqlGen-
|
|
1
|
+
import { y as Y, m as G } from "./schema-CzKt6cN2.js";
|
|
2
|
+
import { B as V } from "./params-DVkfcD6D.js";
|
|
3
|
+
import { s as Z, b as tt, a as et } from "./sqlGen-BoJXaULd.js";
|
|
4
4
|
const C = (t, e) => e.reduce(
|
|
5
5
|
(s, i) => s[i],
|
|
6
6
|
t
|