@nongt/visql 0.11.0 → 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,13 +1,13 @@
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
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";
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
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 }),
@@ -27,6 +27,14 @@ const q = (e) => typeof e == "object" && e !== null && !(e instanceof Date), T =
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",
@@ -116,23 +124,23 @@ const q = (e) => typeof e == "object" && e !== null && !(e instanceof Date), T =
116
124
  query: { joins: [], ...t, select: [{ id: w(), expression: e }] }
117
125
  })
118
126
  };
119
- function K(e, t, r) {
127
+ function V(e, t, r) {
120
128
  return i(e, t, { type: "setBaseTable", table: r });
121
129
  }
122
- function V(e, t, r, a = {}) {
130
+ function z(e, t, r, a = {}) {
123
131
  const n = { type: "addJoin", table: r, ...a };
124
132
  return i(e, t, n);
125
133
  }
126
- function z(e, t, r) {
134
+ function Z(e, t, r) {
127
135
  return i(e, t, { type: "removeJoin", joinId: r });
128
136
  }
129
137
  function x(e, t, r, a = {}) {
130
- const n = D(t), s = L(r);
138
+ const n = D(t), s = M(r);
131
139
  if (n && s.some((l) => l !== n.alias)) {
132
140
  if (s.includes(n.alias))
133
141
  throw new Error("addCondition: a condition names both the union and tables of its branches: add it in two parts");
134
142
  return n.query.union.forEach((l) => {
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));
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));
136
144
  if (S)
137
145
  throw new Error(`addCondition: "${S}" can't be reached from "${m}", one of the union's tables: a condition must reach every branch`);
138
146
  }), n.query.union.reduce((l, m, h) => Q(
@@ -143,28 +151,28 @@ function x(e, t, r, a = {}) {
143
151
  }
144
152
  const u = a.operator ?? "AND", { where: o } = t;
145
153
  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));
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));
147
155
  }
148
- function Z(e, t, r, a) {
156
+ function ee(e, t, r, a) {
149
157
  const n = i(e, t, { type: "addSelectItem" }), s = n.select[n.select.length - 1].id, u = i(e, n, {
150
158
  type: "setSelectExpression",
151
159
  selectId: s,
152
160
  expression: r
153
161
  }), o = a === void 0 ? u : i(e, u, { type: "setSelectAlias", selectId: s, alias: a });
154
- return c(e, t, o);
162
+ return y(e, t, o);
155
163
  }
156
- function ee(e, t, r) {
164
+ function te(e, t, r) {
157
165
  const a = i(e, t, { type: "addGroupByItem" }), { id: n } = a.groupBy[a.groupBy.length - 1], s = i(e, a, {
158
166
  type: "setGroupByExpression",
159
167
  groupById: n,
160
168
  expression: r
161
169
  });
162
- return c(e, t, s);
170
+ return y(e, t, s);
163
171
  }
164
- function te(e, t, r) {
165
- return c(e, t, j(e, t, r));
172
+ function re(e, t, r) {
173
+ return y(e, t, j(e, t, r));
166
174
  }
167
- function re(e, t, r, a = "asc") {
175
+ function ae(e, t, r, a = "asc") {
168
176
  const n = i(e, t, { type: "addOrderByItem" }), { id: s } = n.orderBy[n.orderBy.length - 1], u = i(e, n, {
169
177
  type: "setOrderByExpression",
170
178
  orderById: s,
@@ -174,28 +182,28 @@ function re(e, t, r, a = "asc") {
174
182
  orderById: s,
175
183
  direction: a
176
184
  });
177
- return c(e, t, o);
185
+ return y(e, t, o);
178
186
  }
179
- function ae(e, t, r) {
187
+ function ne(e, t, r) {
180
188
  let a = t;
181
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;
182
190
  }
183
- function ne(e, t, r) {
191
+ function se(e, t, r) {
184
192
  return i(e, t, { type: "setDistinct", distinct: r });
185
193
  }
186
- function se(e) {
194
+ function ie(e) {
187
195
  if (!O(e)) throw new Error(`query "${e.id}" has no base table yet`);
188
196
  return e;
189
197
  }
190
- const g = 5;
191
- class p extends Error {
198
+ const g = 6;
199
+ class c extends Error {
192
200
  constructor(r, a) {
193
201
  super(a);
194
202
  v(this, "kind");
195
203
  this.name = "QueryFormatError", this.kind = r;
196
204
  }
197
205
  }
198
- const y = (e) => typeof e == "object" && e !== null && !Array.isArray(e);
206
+ const p = (e) => typeof e == "object" && e !== null && !Array.isArray(e);
199
207
  function C(e) {
200
208
  const t = [];
201
209
  let r = 0;
@@ -218,142 +226,143 @@ function C(e) {
218
226
  function R(e) {
219
227
  const t = (r) => {
220
228
  if (Array.isArray(r)) return r.map(t);
221
- if (!y(r)) return r;
229
+ if (!p(r)) return r;
222
230
  const a = Object.fromEntries(Object.entries(r).map(([u, o]) => [u, t(o)])), { right: n } = a;
223
- if (a.type !== "binary" || a.operator !== "IN" || !y(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;
224
232
  const s = n.type === "literal" && typeof n.value == "string" ? C(n.value).map((u) => ({ type: "literal", value: u })) : [n];
225
233
  return { ...a, right: { type: "list", items: s } };
226
234
  };
227
235
  return t(e);
228
236
  }
229
- const $ = (e) => e, k = (e) => e, G = (e) => e, J = [
237
+ const $ = (e) => e, k = (e) => e, G = (e) => e, J = (e) => e, F = [
230
238
  R,
231
239
  $,
232
240
  k,
233
- G
241
+ G,
242
+ J
234
243
  ];
235
- function F(e, t, r) {
244
+ function P(e, t, r) {
236
245
  return r.slice(t - 1).reduce((a, n) => n(a), e);
237
246
  }
238
247
  function f(e, 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;
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;
240
249
  }
241
- function P(e) {
250
+ function H(e) {
242
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;
243
252
  }
244
- function H(e) {
253
+ function X(e) {
245
254
  if (e.valueType === void 0) return e;
246
255
  const { valueType: t, ...r } = e, a = String(r.value);
247
256
  let n;
248
257
  if (t === "date") {
249
258
  if (n = new Date(a), Number.isNaN(n.getTime()))
250
- throw new p("invalid", `not a date: ${JSON.stringify(a)}`);
259
+ throw new c("invalid", `not a date: ${JSON.stringify(a)}`);
251
260
  } else if (t === "bigint" && /^-?\d+$/.test(a))
252
261
  n = BigInt(a);
253
262
  else {
254
263
  const s = String(t);
255
- 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)}`);
256
265
  }
257
266
  return { ...r, value: n };
258
267
  }
259
- function ie(e) {
268
+ function oe(e) {
260
269
  return {
261
270
  version: g,
262
- query: f(e, P)
271
+ query: f(e, H)
263
272
  };
264
273
  }
265
- function oe(e) {
266
- if (!y(e))
267
- 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");
268
277
  const { version: t } = e;
269
278
  if (typeof t != "number" || !Number.isInteger(t) || t < 1)
270
- throw new p("invalid", "a stored query has a whole-number version from 1");
279
+ throw new c("invalid", "a stored query has a whole-number version from 1");
271
280
  if (t > g)
272
- throw new p(
281
+ throw new c(
273
282
  "newerVersion",
274
283
  `stored in format ${t}; this version reads up to ${g}`
275
284
  );
276
- const r = F(e.query, t, J);
277
- if (!y(r) || typeof r.id != "string")
278
- throw new p("invalid", "a stored query has a query with a string id");
279
- return f(r, H);
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);
280
289
  }
281
290
  export {
282
291
  pe as DEFAULT_FUNCTIONS,
283
- dt as DIALECTS,
284
- ft as DIALECT_LABELS,
292
+ ft as DIALECTS,
293
+ mt as DIALECT_LABELS,
285
294
  ye as EMPTY_SCHEMA,
286
- ce as MAX_NAME_LENGTH,
287
- we as MAX_NUMBER_DIGITS,
288
- Te as MAX_TEXT_LENGTH,
289
- Ne as MAX_TYPE_NAME_LENGTH,
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,
290
299
  g as QUERY_FORMAT_VERSION,
291
- Xe as QUERY_ISSUE_KINDS,
292
- Ye as QUERY_WARNING_KINDS,
293
- p as QueryFormatError,
294
- mt as ScopeError,
295
- We as SharedBaseError,
300
+ Ye as QUERY_ISSUE_KINDS,
301
+ We as QUERY_WARNING_KINDS,
302
+ c as QueryFormatError,
303
+ ht as ScopeError,
304
+ Ke as SharedBaseError,
296
305
  x as addCondition,
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,
304
- Ae as addUnionJoin,
305
- Oe as addUnionTable,
306
- ht as astToParameterizedSql,
307
- bt as astToSql,
308
- de as branchesOf,
309
- Je as calendarDay,
310
- De as createEmptyQuery,
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,
311
320
  Le as createUnion,
312
321
  T as expr,
313
- fe as filterSchema,
314
- me as findJoinPath,
315
- Fe as fromIsoDay,
316
- he as functionsForDialect,
322
+ me as filterSchema,
323
+ he as findJoinPath,
324
+ Pe as fromIsoDay,
325
+ be as functionsForDialect,
317
326
  O as hasBaseTable,
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,
327
- Qe as measureFacts,
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,
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,
349
358
  pt as sharedUses,
350
- Se as suggestJoin,
351
- xe as unionName,
352
- Ce as unionTableColumns,
353
- Re as unionWithQuery,
354
- $e as unionableTables,
355
- St as unscopedBodies,
356
- ke as unwrapUnion,
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,
357
366
  yt as validateQuery,
358
- Ee as validateSchema
367
+ ve as validateSchema
359
368
  };
package/dist/explain.js CHANGED
@@ -1,6 +1,6 @@
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";
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