@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 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-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) ? v.list(...t) : 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: v.list(t, r)
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: T(),
103
- query: { joins: [], ...t, select: [{ id: T(), expression: e }] }
115
+ id: w(),
116
+ query: { joins: [], ...t, select: [{ id: w(), expression: e }] }
104
117
  })
105
118
  };
106
- function W(e, t, r) {
119
+ function K(e, t, r) {
107
120
  return i(e, t, { type: "setBaseTable", table: r });
108
121
  }
109
- function K(e, t, r, a = {}) {
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 V(e, t, r) {
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(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(
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 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));
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 z(e, t, r, a) {
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 d(e, t, o);
154
+ return c(e, t, o);
142
155
  }
143
- function Z(e, t, r) {
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 d(e, t, s);
162
+ return c(e, t, s);
150
163
  }
151
- function ee(e, t, r) {
152
- return d(e, t, j(e, t, r));
164
+ function te(e, t, r) {
165
+ return c(e, t, j(e, t, r));
153
166
  }
154
- function te(e, t, r, a = "asc") {
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 d(e, t, o);
177
+ return c(e, t, o);
165
178
  }
166
- function re(e, t, r) {
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 ae(e, t, r) {
183
+ function ne(e, t, r) {
171
184
  return i(e, t, { type: "setDistinct", distinct: r });
172
185
  }
173
- function ne(e) {
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 S = 4;
190
+ const g = 5;
178
191
  class p extends Error {
179
192
  constructor(r, a) {
180
193
  super(a);
181
- E(this, "kind");
194
+ v(this, "kind");
182
195
  this.name = "QueryFormatError", this.kind = r;
183
196
  }
184
197
  }
185
- const c = (e) => typeof e == "object" && e !== null && !Array.isArray(e);
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 (!c(r)) return r;
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" || !c(n) || n.type === "subquery" || n.type === "list") return a;
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 = [R, $, k];
217
- function J(e, t, r) {
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)) : c(e) ? e.type === "literal" ? t(e) : Object.fromEntries(Object.entries(e).map(([r, a]) => [r, f(a, t)])) : e;
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 F(e) {
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 P(e) {
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 se(e) {
259
+ function ie(e) {
242
260
  return {
243
- version: S,
244
- query: f(e, F)
261
+ version: g,
262
+ query: f(e, P)
245
263
  };
246
264
  }
247
- function ie(e) {
248
- if (!c(e))
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 > S)
271
+ if (t > g)
254
272
  throw new p(
255
273
  "newerVersion",
256
- `stored in format ${t}; this version reads up to ${S}`
274
+ `stored in format ${t}; this version reads up to ${g}`
257
275
  );
258
- const r = J(e.query, t, G);
259
- if (!c(r) || typeof r.id != "string")
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, P);
279
+ return f(r, H);
262
280
  }
263
281
  export {
264
- le as DEFAULT_FUNCTIONS,
282
+ pe as DEFAULT_FUNCTIONS,
265
283
  dt as DIALECTS,
266
- yt as DIALECT_LABELS,
267
- pe as EMPTY_SCHEMA,
284
+ ft as DIALECT_LABELS,
285
+ ye as EMPTY_SCHEMA,
268
286
  ce as MAX_NAME_LENGTH,
269
- Ee as MAX_NUMBER_DIGITS,
287
+ we as MAX_NUMBER_DIGITS,
270
288
  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,
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
- ft as ScopeError,
277
- Ye as SharedBaseError,
294
+ mt as ScopeError,
295
+ We as SharedBaseError,
278
296
  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,
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
- Be as addUnionTable,
288
- mt as astToParameterizedSql,
289
- ht as astToSql,
305
+ Oe as addUnionTable,
306
+ ht as astToParameterizedSql,
307
+ bt as astToSql,
290
308
  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,
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
- 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,
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
- 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,
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
- qe as unionName,
334
- xe as unionTableColumns,
335
- Ce as unionWithQuery,
336
- Re as unionableTables,
351
+ xe as unionName,
352
+ Ce as unionTableColumns,
353
+ Re as unionWithQuery,
354
+ $e as unionableTables,
337
355
  St as unscopedBodies,
338
- $e as unwrapUnion,
339
- pt as validateQuery,
340
- we as validateSchema
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-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-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