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