@nongt/visql 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.
Files changed (42) hide show
  1. package/dist/{MuiTimePicker-DRqT6ByZ.js → MuiTimePicker-CROJXSCL.js} +1 -1
  2. package/dist/{PipelineEditor-CGTZGbmf.js → PipelineEditor-DHfbOSzT.js} +4342 -4039
  3. package/dist/core.js +163 -136
  4. package/dist/explain.js +3 -3
  5. package/dist/fixtures.js +3 -3
  6. package/dist/index.js +102 -110
  7. package/dist/issueLocation-DY-vvgFF.js +1155 -0
  8. package/dist/mui-date-pickers-host.js +1 -1
  9. package/dist/mui-date-pickers.js +1 -1
  10. package/dist/mui.js +2 -2
  11. package/dist/{params-DkVFbMQn.js → params-Btjlj45_.js} +255 -226
  12. package/dist/{schema-CgL10bid.js → schema-DsMO9oFE.js} +327 -245
  13. package/dist/sql-import.js +829 -786
  14. package/dist/sqlGen-DGXVba3D.js +941 -0
  15. package/dist/{tokens-DV5rTGMj.js → tokens-3SURLAkL.js} +15 -14
  16. package/dist/types/core/FunctionsContext.d.ts +8 -2
  17. package/dist/types/core/absolutePath.d.ts +3 -0
  18. package/dist/types/core/ast.d.ts +24 -2
  19. package/dist/types/core/components/expression/ExpressionTypeSelector.d.ts +1 -1
  20. package/dist/types/core/components/flow/CalculationFlowNode.d.ts +5 -0
  21. package/dist/types/core/components/flow/WindowKeys.d.ts +10 -0
  22. package/dist/types/core/expressionFlow.d.ts +48 -5
  23. package/dist/types/core/formula.d.ts +4 -1
  24. package/dist/types/core/functionRegistry.d.ts +15 -2
  25. package/dist/types/core/grouping.d.ts +6 -1
  26. package/dist/types/core/i18n/defaultMessages.d.ts +23 -0
  27. package/dist/types/core/i18n/messages.d.ts +17 -0
  28. package/dist/types/core/issueLocation.d.ts +6 -1
  29. package/dist/types/core/queryHelpers.d.ts +12 -1
  30. package/dist/types/core/queryValidation.d.ts +11 -1
  31. package/dist/types/core/sqlGen.d.ts +12 -0
  32. package/dist/types/core/storedQuery.d.ts +1 -1
  33. package/dist/types/core/theme/appearance.d.ts +4 -1
  34. package/dist/types/core/theme/looks.d.ts +6 -5
  35. package/dist/types/core/theme/tokens.d.ts +6 -3
  36. package/dist/types/core/valueTypes.d.ts +2 -2
  37. package/dist/types/core-api.d.ts +2 -2
  38. package/dist/types/sqlImport/context.d.ts +2 -2
  39. package/dist/types/sqlImport/syntax.d.ts +11 -2
  40. package/package.json +1 -1
  41. package/dist/issueLocation-BlQ280IE.js +0 -1108
  42. package/dist/sqlGen-C1kZwvWI.js +0 -903
@@ -1,4 +1,4 @@
1
- const g = {
1
+ const u = {
2
2
  // Canvas
3
3
  canvasBg: "#242424",
4
4
  canvasPattern: "#505050",
@@ -67,7 +67,7 @@ const g = {
67
67
  fieldRadius: "0.375rem",
68
68
  groupRadius: "0.75rem",
69
69
  edgeWidth: "1px"
70
- }, c = {
70
+ }, i = {
71
71
  // Canvas
72
72
  canvasBg: "#0e1726",
73
73
  canvasPattern: "#132036",
@@ -134,26 +134,26 @@ const g = {
134
134
  fieldRadius: "0.375rem",
135
135
  groupRadius: "0.5rem",
136
136
  edgeWidth: "1px"
137
- }, i = "qb-root";
137
+ }, g = i, c = "qb-root";
138
138
  function a(e) {
139
139
  return `--qb-${e.replace(/[A-Z]/g, (r) => `-${r.toLowerCase()}`)}`;
140
140
  }
141
- function u(e) {
141
+ function s(e) {
142
142
  return `var(${a(e)})`;
143
143
  }
144
144
  const f = Object.keys(g);
145
- function s() {
145
+ function l() {
146
146
  const e = f.map((r) => `${a(r)}:${g[r]};`).join("");
147
- return `:where(.${i}){${e}}`;
147
+ return `:where(.${c}){${e}}`;
148
148
  }
149
- function l(e) {
149
+ function B(e) {
150
150
  const r = {};
151
151
  return e && f.forEach((o) => {
152
152
  const d = e[o];
153
153
  d !== void 0 && (r[a(o)] = d);
154
154
  }), r;
155
155
  }
156
- function B(e, r) {
156
+ function b(e, r) {
157
157
  const o = getComputedStyle(e), d = { ...r };
158
158
  return f.forEach((t) => {
159
159
  const n = o.getPropertyValue(a(t)).trim();
@@ -161,11 +161,12 @@ function B(e, r) {
161
161
  }), d;
162
162
  }
163
163
  export {
164
+ u as C,
164
165
  g as D,
165
- c as N,
166
- i as R,
167
- l as a,
168
- s as d,
169
- B as r,
170
- u as t
166
+ i as N,
167
+ c as R,
168
+ B as a,
169
+ l as d,
170
+ b as r,
171
+ s as t
171
172
  };
@@ -7,6 +7,11 @@ declare const FunctionsContext: import("react").Context<FunctionRegistry>;
7
7
  * SELECT, ORDER BY and HAVING, false elsewhere (WHERE, JOIN ON, GROUP BY),
8
8
  * where SQL doesn't allow them. */
9
9
  export declare const AggregatesContext: import("react").Context<boolean>;
10
+ /** Whether window functions (LAG, ROW_NUMBER, …, issue 20) may be picked
11
+ * here: true in a SELECT column and a sort key, false elsewhere and
12
+ * inside an aggregate or another window call, where SQL doesn't allow
13
+ * them. */
14
+ export declare const WindowsContext: import("react").Context<boolean>;
10
15
  /** Every function, for reading an existing call (its signature, args). */
11
16
  export declare function useFunctions(): FunctionRegistry;
12
17
  /** The functions a picker offers here — those the database has (see
@@ -14,8 +19,9 @@ export declare function useFunctions(): FunctionRegistry;
14
19
  * AggregatesContext). */
15
20
  export declare function useFunctionChoices(): FunctionRegistry;
16
21
  /** A function picker's names (see useFunctionChoices), and their group:
17
- * where aggregates are offered, those first, apart from the other
18
- * functions — an aggregate groups the rows. Elsewhere one list, no
22
+ * where aggregates or window functions are offered, those first, each
23
+ * group apart from the other functions — an aggregate groups the rows, a
24
+ * window function looks at the rows around one. Elsewhere one list, no
19
25
  * groups. `searchText` finds a function by its other names too. */
20
26
  export declare function useFunctionOptions(): {
21
27
  names: string[];
@@ -29,6 +29,9 @@ export declare const ROOT_PATH: AbsolutePath;
29
29
  * (see ExpressionView). Shared so drillStack reconstruction/pruning can
30
30
  * reuse the exact same rule. */
31
31
  export declare const CONDITION_DRILL_TYPES: Set<string>;
32
+ /** Types that open the function sub-canvas (mode 'expression'): a call, or
33
+ * a calculation, whose sides are drawn there like a call's arguments. */
34
+ export declare const EXPRESSION_DRILL_TYPES: Set<string>;
32
35
  /** Read the node at `path`, or undefined if any hop doesn't resolve (wrong
33
36
  * node type at that point, out-of-range index, or an empty optional slot). */
34
37
  export declare function getAtAbsolutePath(root: ExpressionNode | undefined, path: AbsolutePath): ExpressionNode | undefined;
@@ -5,13 +5,16 @@ export type BinaryOperator = typeof binaryOperators[number];
5
5
  export declare const unaryOperators: readonly ["IS NULL", "IS NOT NULL"];
6
6
  export declare function isUnaryOperator(operator: BinaryOperator | undefined): boolean;
7
7
  export type LogicalOperator = 'AND' | 'OR';
8
+ /** A calculation's operators (issue 26). */
9
+ export declare const arithmeticOperators: readonly ["+", "-", "*", "/"];
10
+ export type ArithmeticOperator = typeof arithmeticOperators[number];
8
11
  /** A value's type (issue 130, see valueTypes.ts). `integer` is a whole
9
12
  * number, `number` any. A `date` is a calendar day and a `dateTime` a day
10
13
  * and a time, both as calendarDate.ts holds them; a `time` is a time of
11
14
  * day, stored as `HH:MM:SS` text. */
12
15
  export type ValueType = 'text' | 'integer' | 'number' | 'date' | 'dateTime' | 'time' | 'boolean';
13
16
  export type LiteralValue = string | number | bigint | boolean | null | Date;
14
- export type ExpressionNode = LiteralNode | FieldNode | FunctionCallNode | BinaryNode | LogicalNode | NotNode | IfNode | CaseNode | ParamNode | ExistsNode | SubqueryNode | ListNode;
17
+ export type ExpressionNode = LiteralNode | FieldNode | FunctionCallNode | BinaryNode | ArithmeticNode | LogicalNode | NotNode | IfNode | CaseNode | ParamNode | ExistsNode | SubqueryNode | ListNode;
15
18
  /** A named value supplied by the application when the SQL is generated —
16
19
  * `astToParameterizedSql(query, dialect, { values: { [name]: … } })` —
17
20
  * never by the user. Code (typically a backend) adds it, e.g. a tenant or
@@ -70,8 +73,16 @@ export interface FunctionCallNode extends Record<string, unknown>, ColumnCopy {
70
73
  /** An aggregate over distinct values only: `COUNT(DISTINCT x)`. */
71
74
  distinct?: boolean;
72
75
  /** The order an aggregate takes its values in (issue 164): STRING_AGG's
73
- * text lists them so. Only STRING_AGG takes one. */
76
+ * text lists them so. A window call's (`over`) is its OVER's ORDER BY.
77
+ * Only STRING_AGG and window calls take one. */
74
78
  orderBy?: FunctionSortKey[];
79
+ /** A window function's call (issue 20, `window` in the registry): written
80
+ * with `OVER (PARTITION BY … ORDER BY …)`, over the rows its body
81
+ * returns rather than one value per row or group. */
82
+ over?: boolean;
83
+ /** A window call's PARTITION BY: the rows it looks at for a row are
84
+ * those with the same values. */
85
+ partitionBy?: ExpressionNode[];
75
86
  }
76
87
  /** One key of a function call's `orderBy`. */
77
88
  export interface FunctionSortKey {
@@ -85,6 +96,17 @@ export interface BinaryNode extends Record<string, unknown>, ColumnCopy {
85
96
  /** Absent exactly when `operator` is IS NULL / IS NOT NULL. */
86
97
  right?: ExpressionNode;
87
98
  }
99
+ /** A calculation on two numbers (issue 26): `left + right`, `left / right`.
100
+ * A value, where `binary` is a condition. `a + b + c` nests, `(a + b) + c`;
101
+ * sqlGen writes parentheses only where the order needs them. Division
102
+ * keeps its fraction in every database unless sqlGen's `division` option
103
+ * says otherwise. */
104
+ export interface ArithmeticNode extends Record<string, unknown>, ColumnCopy {
105
+ type: 'arithmetic';
106
+ operator: ArithmeticOperator;
107
+ left: ExpressionNode;
108
+ right: ExpressionNode;
109
+ }
88
110
  export interface LogicalNode extends Record<string, unknown> {
89
111
  type: 'logical';
90
112
  operator: LogicalOperator;
@@ -5,7 +5,7 @@ interface Props {
5
5
  onChange?: (exp: ExpressionNode) => void;
6
6
  /** Types not to offer here — e.g. a plain value as an ORDER BY key, where
7
7
  * it means nothing (and `ORDER BY 1` would mean "the first column"). */
8
- exclude?: readonly ('field' | 'literal' | 'param' | 'function' | 'if' | 'case')[];
8
+ exclude?: readonly ('field' | 'literal' | 'param' | 'function' | 'arithmetic' | 'if' | 'case')[];
9
9
  /** Only a label, as in read-only mode: no menu, can't be clicked. For a
10
10
  * type chosen elsewhere, e.g. the call at the top of a function's
11
11
  * sub-canvas. */
@@ -0,0 +1,5 @@
1
+ import { type Node, type NodeProps } from '@xyflow/react';
2
+ import type { CalculationNodeData } from '../../expressionFlow.js';
3
+ type CalculationFlowNodeType = Node<CalculationNodeData>;
4
+ declare const CalculationFlowNode: ({ data }: NodeProps<CalculationFlowNodeType>) => import("react/jsx-runtime").JSX.Element;
5
+ export default CalculationFlowNode;
@@ -0,0 +1,10 @@
1
+ import type { ExpressionNode, FunctionSortKey } from '../../ast.js';
2
+ /** A window call's OVER (issue 20): the columns its rows are split by
3
+ * (PARTITION BY), then their order (ORDER BY), each list under its name. */
4
+ declare const WindowKeys: ({ partitionBy, orderBy, onPartitionBy, onOrderBy, }: {
5
+ partitionBy: ExpressionNode[];
6
+ orderBy: FunctionSortKey[];
7
+ onPartitionBy: (keys: ExpressionNode[]) => void;
8
+ onOrderBy: (keys: FunctionSortKey[]) => void;
9
+ }) => import("react/jsx-runtime").JSX.Element;
10
+ export default WindowKeys;
@@ -1,6 +1,6 @@
1
1
  import type { Edge, Node } from '@xyflow/react';
2
- import type { BinaryNode, CaseNode, ExistsNode, ExpressionNode, FunctionCallNode, FunctionSortKey, LogicalNode, NotNode } from './ast.js';
3
- import { type AbsolutePath } from './absolutePath.js';
2
+ import type { ArithmeticNode, ArithmeticOperator, BinaryNode, CaseNode, ExistsNode, ExpressionNode, FunctionCallNode, FunctionSortKey, LogicalNode, NotNode } from './ast.js';
3
+ import { type AbsolutePath, type AbsoluteStep } from './absolutePath.js';
4
4
  import { type ArgDef, type FunctionRegistry } from './functionRegistry.js';
5
5
  /** 'rtl': children left, operator right (grows left on add)
6
6
  * 'ltr': operator left, children right (grows right on add) */
@@ -328,10 +328,26 @@ export declare function applyFlowAction(ast: ExpressionNode, action: FlowAction)
328
328
  /** The structural path a FlowAction most directly touches — used only to decide
329
329
  * where to offer post-undo/redo navigation, not for mutation correctness. */
330
330
  export declare function flowActionTargetPath(action: FlowAction): AbsolutePath;
331
+ /** What the function canvas draws as a node with inputs: a call, its
332
+ * arguments, or a calculation (issue 26), its two sides. */
333
+ export type CanvasCall = FunctionCallNode | ArithmeticNode;
334
+ export declare const isCanvasCall: (node: ExpressionNode) => node is CanvasCall;
335
+ /** A canvas call's inputs, in order: a call's arguments, a calculation's
336
+ * left then right side. A canvas path's numbers index these. */
337
+ export declare const canvasChildren: (node: CanvasCall) => ExpressionNode[];
331
338
  export interface FunctionCallNodeData extends Record<string, unknown> {
332
339
  fn: FunctionCallNode;
333
- /** Path through function.args[] to this function node. [] = root. */
340
+ /** Path through the canvas calls' inputs to this function node. [] = root. */
334
341
  path: number[];
342
+ /** The same place as path steps, from the canvas's root. */
343
+ steps: AbsoluteStep[];
344
+ direction: FlowDirection;
345
+ dispatch: ExpressionFlowDispatch;
346
+ }
347
+ export interface CalculationNodeData extends Record<string, unknown> {
348
+ calc: ArithmeticNode;
349
+ path: number[];
350
+ steps: AbsoluteStep[];
335
351
  direction: FlowDirection;
336
352
  dispatch: ExpressionFlowDispatch;
337
353
  }
@@ -339,6 +355,10 @@ export interface FunctionArgNodeData extends Record<string, unknown> {
339
355
  arg: ExpressionNode;
340
356
  /** Full path: [...parentFnPath, argIndex]. */
341
357
  path: number[];
358
+ /** The same place as path steps, from the canvas's root. */
359
+ steps: AbsoluteStep[];
360
+ /** A calculation's side rather than an argument: which one. */
361
+ side?: 'left' | 'right';
342
362
  direction: FlowDirection;
343
363
  dispatch: ExpressionFlowDispatch;
344
364
  /** ArgDef from the function registry, if the parent function is a known function. */
@@ -364,6 +384,8 @@ export type ExpressionFlowAction =
364
384
  path: number[];
365
385
  name: string;
366
386
  args: ExpressionNode[];
387
+ /** A window function's call (issue 20): it starts with OVER. */
388
+ over?: boolean;
367
389
  }
368
390
  /** Replace the arg at path (path = [...parentFnPath, argIndex]). */
369
391
  | {
@@ -412,6 +434,24 @@ export type ExpressionFlowAction =
412
434
  type: 'exprSetOrderBy';
413
435
  path: number[];
414
436
  orderBy: FunctionSortKey[];
437
+ }
438
+ /** The window call at path's PARTITION BY (issue 20); empty removes it. */
439
+ | {
440
+ type: 'exprSetPartitionBy';
441
+ path: number[];
442
+ partitionBy: ExpressionNode[];
443
+ }
444
+ /** The operator of the calculation at path (issue 26). */
445
+ | {
446
+ type: 'exprSetOperator';
447
+ path: number[];
448
+ operator: ArithmeticOperator;
449
+ }
450
+ /** The calculation at path, as it is, made the first value of a new one
451
+ * (issue 31): how its whole goes into another after it's built. */
452
+ | {
453
+ type: 'exprWrapCalc';
454
+ path: number[];
415
455
  };
416
456
  /** What a COUNT counts: every row (`COUNT(*)`, no argument), the rows
417
457
  * where a value is set (`COUNT(x)`), or the different values
@@ -421,8 +461,11 @@ export declare function countMode(fn: FunctionCallNode): CountMode;
421
461
  export type ExpressionFlowDispatch = (action: ExpressionFlowAction) => void;
422
462
  export declare function applyExpressionFlowAction(ast: ExpressionNode, action: ExpressionFlowAction): ExpressionNode;
423
463
  /** The function-canvas nodes (expressionToFunctionFlow) on the way to the
424
- * spot `path` names, outermost first: each call down its argument steps,
425
- * and the argument itself (a call's node, or a leaf argument's). */
464
+ * spot `path` names, outermost first: each call (or calculation) down its
465
+ * argument or side steps, and the input itself (a call's node, or a leaf
466
+ * input's). A side step is read as a calculation's: past a comparison
467
+ * (whose sides are on a panel of their own) it names nodes that aren't on
468
+ * this canvas, which FocusPulse passes over for the deepest one that is. */
426
469
  export declare function functionFlowNodeIds(path: AbsolutePath): string[];
427
470
  export declare function expressionToFunctionFlow(ast: ExpressionNode, dispatch: ExpressionFlowDispatch, functions?: FunctionRegistry, direction?: FlowDirection): FlowGraph;
428
471
  export declare function layoutFunctionFlow(rawNodes: Node[], prevNodes: Node[], ast: ExpressionNode, direction?: FlowDirection): Node[];
@@ -1,4 +1,4 @@
1
- import type { ExpressionNode } from './ast.js';
1
+ import type { ArithmeticOperator, ExpressionNode } from './ast.js';
2
2
  import { type FunctionRegistry } from './functionRegistry.js';
3
3
  import { type DatabaseSchema } from './schema.js';
4
4
  /** What a part of a formula is: a column, a value, a param, a function's
@@ -18,6 +18,9 @@ export interface FormulaOptions {
18
18
  * in are left out (`…`) until it fits, the outermost kept. */
19
19
  budget?: number;
20
20
  }
21
+ /** How a calculation's operator reads (issue 26): as written by hand, not
22
+ * as SQL has it. */
23
+ export declare const ARITHMETIC_SYMBOLS: Record<ArithmeticOperator, string>;
21
24
  /** The formula's text: its parts, joined. */
22
25
  export declare function formulaText(parts: FormulaPart[]): string;
23
26
  /** `expression` as a formula, as deep as `budget` allows. */
@@ -1,4 +1,4 @@
1
- import type { ExpressionNode, ValueType } from './ast.js';
1
+ import type { ExpressionNode, FunctionCallNode, ValueType } from './ast.js';
2
2
  import type { DatabaseColumnType } from './schema.js';
3
3
  import type { SqlDialect } from './sqlGen.js';
4
4
  /**
@@ -13,8 +13,11 @@ import type { SqlDialect } from './sqlGen.js';
13
13
  * fixed-text — a text written into the SQL itself, never a parameter (STRING_AGG's
14
14
  * separator: MySQL takes only a literal there), stored as string literal,
15
15
  * shown as text input
16
+ * fixed-count — a whole number from 0 written into the SQL itself, never a parameter
17
+ * (LAG's offset: MySQL takes only a literal there), stored as number
18
+ * literal, shown as number input
16
19
  */
17
- export type ArgKind = 'expr' | 'date-expr' | 'num-expr' | 'str-expr' | 'unit' | 'type-name' | 'fixed-text';
20
+ export type ArgKind = 'expr' | 'date-expr' | 'num-expr' | 'str-expr' | 'unit' | 'type-name' | 'fixed-text' | 'fixed-count';
18
21
  /**
19
22
  * Maps ArgKind to the column types that should be shown when the arg value is a field.
20
23
  * Undefined means no filter (all column types are shown).
@@ -46,6 +49,10 @@ export interface FunctionSignature {
46
49
  * SQL allows one — SELECT, HAVING and ORDER BY, not WHERE, JOIN ON or
47
50
  * GROUP BY — and what makes a query grouped (see grouping.ts). */
48
51
  aggregate?: boolean;
52
+ /** A window function (issue 20: LAG, ROW_NUMBER, …): its call has `over`
53
+ * and an ORDER BY, and goes only in SELECT and ORDER BY, of a body that
54
+ * isn't grouped. */
55
+ window?: boolean;
49
56
  /** The type of its result (issue 130), so a value compared with it gets
50
57
  * the matching input: `'arg'` for its first argument's (MIN, COALESCE,
51
58
  * DATE_ADD). Omitted: not known (the user picks the value's type). */
@@ -112,6 +119,12 @@ export declare function normalizeRegistry(registry: FunctionRegistry): FunctionR
112
119
  /** `registry` without its aggregates — what's offered where SQL doesn't
113
120
  * allow one (WHERE, JOIN ON, GROUP BY). */
114
121
  export declare function withoutAggregates(registry: FunctionRegistry): FunctionRegistry;
122
+ /** A new call to `sig`, as a function picker starts one: its default
123
+ * arguments, and OVER for a window function (issue 20). `name` is what
124
+ * it's stored by. */
125
+ export declare function startCall(sig: FunctionSignature, name: string): FunctionCallNode;
126
+ /** `registry` without its window functions (issue 20). */
127
+ export declare function withoutWindows(registry: FunctionRegistry): FunctionRegistry;
115
128
  /** Only the functions available in `dialect` (those with no `dialects` list
116
129
  * are available everywhere). */
117
130
  export declare function functionsForDialect(registry: FunctionRegistry, dialect: SqlDialect): FunctionRegistry;
@@ -5,6 +5,10 @@ import type { QueryBody } from './queryAst.js';
5
5
  export declare function isAggregateCall(node: ExpressionNode, registry: FunctionRegistry): boolean;
6
6
  /** Whether `node` has an aggregate call anywhere in it. */
7
7
  export declare function containsAggregate(node: ExpressionNode | undefined, registry: FunctionRegistry): boolean;
8
+ /** A window function's call (issue 20): one with OVER. */
9
+ export declare const isWindowCall: (node: ExpressionNode) => boolean;
10
+ /** Whether `node` has a window call anywhere in it. */
11
+ export declare function containsWindow(node: ExpressionNode | undefined): boolean;
8
12
  /** A call to a function `registry` doesn't know (issue 137). It may be an
9
13
  * aggregate (a database's own, a host's left out of the registry), so
10
14
  * it's never made a group key, nor reported as not one — validateQuery
@@ -51,7 +55,8 @@ export declare function selectsAggregate(query: QueryBody, registry: FunctionReg
51
55
  * up any more. A key the user added is never touched; a column it
52
56
  * already covers needs none. A column mixing an aggregate and a plain
53
57
  * column can't be fixed this way (groupingProblems still reports it), and
54
- * neither is one with a function the registry doesn't know (isUnknownCall). ORDER BY
58
+ * neither is one with a function the registry doesn't know (isUnknownCall), nor
59
+ * one with a window call. ORDER BY
55
60
  * keys are never made keys: that would change the grouping unseen. The
56
61
  * same object when nothing changes. */
57
62
  export declare function groupAutomatically<Q extends QueryBody>(query: Q, registry: FunctionRegistry): Q;
@@ -60,6 +60,11 @@ export declare const DEFAULT_MESSAGES: {
60
60
  removeElse: string;
61
61
  addArg: string;
62
62
  removeArg: string;
63
+ calcFirst: string;
64
+ calcSecond: string;
65
+ calcOperator: string;
66
+ /** Makes a calculation the first value of a new one. */
67
+ wrapInCalculation: string;
63
68
  typeField: string;
64
69
  typeValue: string;
65
70
  /** NULL, picked as a value (no value, on purpose). */
@@ -71,6 +76,8 @@ export declare const DEFAULT_MESSAGES: {
71
76
  typeDate: string;
72
77
  typeBoolean: string;
73
78
  typeFunction: string;
79
+ /** A calculation, `a + b` (issue 26). */
80
+ typeCalculation: string;
74
81
  typeExpression: string;
75
82
  /** A named param (set by the application, shown read-only). */
76
83
  typeParam: string;
@@ -94,6 +101,9 @@ export declare const DEFAULT_MESSAGES: {
94
101
  * (which group the rows) apart from the rest. Kept short: the list is
95
102
  * as narrow as the name box. */
96
103
  functionGroupAggregate: string;
104
+ /** Window functions (LAG, ROW_NUMBER, …): each looks at the rows around
105
+ * a row. */
106
+ functionGroupWindow: string;
97
107
  functionGroupOther: string;
98
108
  typeMenuCondition: string;
99
109
  /** IN's value as a query of its own (issue 122), when offered: its type,
@@ -239,6 +249,12 @@ export declare const DEFAULT_MESSAGES: {
239
249
  addSort: string;
240
250
  removeSort: string;
241
251
  toggleSortDirection: string;
252
+ /** A window function's OVER (issue 20): the columns its rows are split
253
+ * by, and their order. */
254
+ windowPartitionBy: string;
255
+ windowOrderBy: string;
256
+ addPartition: string;
257
+ removePartition: string;
242
258
  /** Opens the row-count inputs. */
243
259
  limitRows: string;
244
260
  removeLimit: string;
@@ -300,6 +316,7 @@ export declare const DEFAULT_MESSAGES: {
300
316
  locationColumn: (n: number) => string;
301
317
  locationGroupKey: (n: number) => string;
302
318
  locationSortKey: (n: number) => string;
319
+ locationPartitionKey: (n: number) => string;
303
320
  locationCondition: (n: number) => string;
304
321
  locationLeft: string;
305
322
  locationRight: string;
@@ -343,6 +360,9 @@ export declare const DEFAULT_MESSAGES: {
343
360
  issueSharedOrder: string;
344
361
  issueUnusedShared: string;
345
362
  issueJoinOnlyColumn: string;
363
+ issueMisplacedWindow: string;
364
+ issueGroupedWindow: string;
365
+ issueUnorderedWindow: string;
346
366
  issueUnknownTableNamed: (table: string) => string;
347
367
  issueUnknownColumnNamed: (table: string, column: string) => string;
348
368
  issueJoinOnlyColumnNamed: (column: string) => string;
@@ -370,6 +390,9 @@ export declare const DEFAULT_MESSAGES: {
370
390
  issueNotGroupedNamed: (column: string) => string;
371
391
  issueSelectAllGrouped: string;
372
392
  issueMisplacedAggregateNamed: (fn: string) => string;
393
+ issueMisplacedWindowNamed: (fn: string) => string;
394
+ issueGroupedWindowNamed: (fn: string) => string;
395
+ issueUnorderedWindowNamed: (fn: string) => string;
373
396
  peekHint: string;
374
397
  /** `keys`: its shortcut, as the user's keyboard has it (⌘F, Ctrl+F). */
375
398
  find: (keys: string) => string;
@@ -46,6 +46,10 @@ declare const MessagesContext: import("react").Context<{
46
46
  removeElse: string;
47
47
  addArg: string;
48
48
  removeArg: string;
49
+ calcFirst: string;
50
+ calcSecond: string;
51
+ calcOperator: string;
52
+ wrapInCalculation: string;
49
53
  typeField: string;
50
54
  typeValue: string;
51
55
  typeNull: string;
@@ -54,6 +58,7 @@ declare const MessagesContext: import("react").Context<{
54
58
  typeDate: string;
55
59
  typeBoolean: string;
56
60
  typeFunction: string;
61
+ typeCalculation: string;
57
62
  typeExpression: string;
58
63
  typeParam: string;
59
64
  typeRelativeDate: string;
@@ -69,6 +74,7 @@ declare const MessagesContext: import("react").Context<{
69
74
  paramNamePlaceholder: string;
70
75
  typeMenuBasic: string;
71
76
  functionGroupAggregate: string;
77
+ functionGroupWindow: string;
72
78
  functionGroupOther: string;
73
79
  typeMenuCondition: string;
74
80
  typeSubquery: string;
@@ -157,6 +163,10 @@ declare const MessagesContext: import("react").Context<{
157
163
  addSort: string;
158
164
  removeSort: string;
159
165
  toggleSortDirection: string;
166
+ windowPartitionBy: string;
167
+ windowOrderBy: string;
168
+ addPartition: string;
169
+ removePartition: string;
160
170
  limitRows: string;
161
171
  removeLimit: string;
162
172
  showRowsBefore: string;
@@ -201,6 +211,7 @@ declare const MessagesContext: import("react").Context<{
201
211
  locationColumn: (n: number) => string;
202
212
  locationGroupKey: (n: number) => string;
203
213
  locationSortKey: (n: number) => string;
214
+ locationPartitionKey: (n: number) => string;
204
215
  locationCondition: (n: number) => string;
205
216
  locationLeft: string;
206
217
  locationRight: string;
@@ -243,6 +254,9 @@ declare const MessagesContext: import("react").Context<{
243
254
  issueSharedOrder: string;
244
255
  issueUnusedShared: string;
245
256
  issueJoinOnlyColumn: string;
257
+ issueMisplacedWindow: string;
258
+ issueGroupedWindow: string;
259
+ issueUnorderedWindow: string;
246
260
  issueUnknownTableNamed: (table: string) => string;
247
261
  issueUnknownColumnNamed: (table: string, column: string) => string;
248
262
  issueJoinOnlyColumnNamed: (column: string) => string;
@@ -269,6 +283,9 @@ declare const MessagesContext: import("react").Context<{
269
283
  issueNotGroupedNamed: (column: string) => string;
270
284
  issueSelectAllGrouped: string;
271
285
  issueMisplacedAggregateNamed: (fn: string) => string;
286
+ issueMisplacedWindowNamed: (fn: string) => string;
287
+ issueGroupedWindowNamed: (fn: string) => string;
288
+ issueUnorderedWindowNamed: (fn: string) => string;
272
289
  peekHint: string;
273
290
  find: (keys: string) => string;
274
291
  findPlaceholder: string;
@@ -50,6 +50,11 @@ export type IssueLocationStep =
50
50
  kind: 'sortKey';
51
51
  number: number;
52
52
  }
53
+ /** One of a window call's PARTITION BY keys (issue 20), from 1. */
54
+ | {
55
+ kind: 'partitionKey';
56
+ number: number;
57
+ }
53
58
  /** One of a group's conditions (from 1). */
54
59
  | {
55
60
  kind: 'condition';
@@ -57,7 +62,7 @@ export type IssueLocationStep =
57
62
  } | {
58
63
  kind: 'not';
59
64
  }
60
- /** A comparison's side. */
65
+ /** A comparison's or a calculation's side. */
61
66
  | {
62
67
  kind: 'side';
63
68
  side: 'left' | 'right';
@@ -1,4 +1,4 @@
1
- import type { BinaryNode, BinaryOperator, ExistsNode, ExpressionNode, FieldNode, FunctionCallNode, LiteralNode, ListNode, LiteralValue, LogicalNode, LogicalOperator, NotNode, ParamNode, RelativeDate, SubqueryNode } from './ast.js';
1
+ import type { ArithmeticNode, ArithmeticOperator, BinaryNode, BinaryOperator, ExistsNode, ExpressionNode, FieldNode, FunctionCallNode, FunctionSortKey, LiteralNode, ListNode, LiteralValue, LogicalNode, LogicalOperator, NotNode, ParamNode, RelativeDate, SubqueryNode } from './ast.js';
2
2
  import { type DerivedQuery, type JoinClause, type TableFrom, type JoinType, type QueryPipeline, type QueryValue, type SortDirection } from './queryAst.js';
3
3
  import type { DatabaseSchema } from './schema.js';
4
4
  export declare const expr: {
@@ -17,6 +17,9 @@ export declare const expr: {
17
17
  }) => ParamNode;
18
18
  /** `left <operator> right`. */
19
19
  compare: (left: ExpressionNode, operator: BinaryOperator, right: ExpressionNode) => BinaryNode;
20
+ /** A calculation (issue 26), `left <operator> right`:
21
+ * `expr.calc(price, '*', quantity)`. */
22
+ calc: (left: ExpressionNode, operator: ArithmeticOperator, right: ExpressionNode) => ArithmeticNode;
20
23
  /** `operand IS NULL`. */
21
24
  isNull: (operand: ExpressionNode) => BinaryNode;
22
25
  /** `operand IS NOT NULL`. */
@@ -28,6 +31,14 @@ export declare const expr: {
28
31
  not: (operand: ExpressionNode) => NotNode;
29
32
  /** A function call: `expr.fn('LOWER', expr.field('users', 'email'))`. */
30
33
  fn: (name: string, ...args: ExpressionNode[]) => FunctionCallNode;
34
+ /** A window function's call (issue 20), over the rows of its body:
35
+ * `expr.over(expr.fn('LAG', status), { partitionBy: [employee], orderBy:
36
+ * [{ expression: payDate, direction: 'asc' }] })` is `LAG(status) OVER
37
+ * (PARTITION BY employee ORDER BY pay_date ASC)`. */
38
+ over: (call: FunctionCallNode, window: {
39
+ partitionBy?: ExpressionNode[];
40
+ orderBy?: FunctionSortKey[];
41
+ }) => FunctionCallNode;
31
42
  /** Whether the outer row has related rows: `EXISTS (SELECT 1 FROM …
32
43
  * WHERE <link> AND <where>)`. `link` matches them to the outer row;
33
44
  * `where` names the subquery's own tables only. NOT EXISTS:
@@ -61,6 +61,16 @@ export type QueryIssueKind =
61
61
  | 'unknownAggregate'
62
62
  /** An aggregate where SQL doesn't allow one: WHERE, JOIN ON, GROUP BY. */
63
63
  | 'misplacedAggregate'
64
+ /** A window function (issue 20) where SQL doesn't allow one: anywhere but
65
+ * SELECT and ORDER BY (WHERE, JOIN ON, GROUP BY, HAVING, an EXISTS), or
66
+ * inside another window function or an aggregate. */
67
+ | 'misplacedWindow'
68
+ /** A window function in a grouped query (aggregates, GROUP BY or
69
+ * HAVING): work it out in a sub query, and group around it. */
70
+ | 'groupedWindow'
71
+ /** A window function with no ORDER BY: which row comes before which
72
+ * isn't said, and SQL Server refuses it. */
73
+ | 'unorderedWindow'
64
74
  /** A param compared against columns of different types (`:x` against a
65
75
  * date and a number) — no one value suits both. */
66
76
  | 'paramConflict'
@@ -135,7 +145,7 @@ export type QueryIssueKind =
135
145
  /** A join-only column (a key, issue 234) used outside a join's ON or an
136
146
  * EXISTS's link, and not in a sub query's SELECT or GROUP BY. */
137
147
  | 'joinOnlyColumn';
138
- export declare const QUERY_ISSUE_KINDS: readonly ["invalidStructure", "duplicateId", "unknownTable", "unknownColumn", "tableNotInQuery", "unqualifiedField", "incomplete", "argCount", "ambiguousTable", "duplicateTableName", "derivedColumnName", "unknownFunction", "joinOrder", "distinctSort", "notGrouped", "unknownAggregate", "misplacedAggregate", "paramConflict", "fanOut", "crossJoin", "unlinkedJoin", "drillAcrossOutOfStep", "drillAcrossFilterMixed", "tooLong", "dialectUnsupported", "subqueryColumns", "notInSubquery", "noLimit", "limitTooHigh", "typeMismatch", "invalidPattern", "unionColumns", "unionTypes", "sharedOrder", "unusedShared", "joinOnlyColumn"];
148
+ export declare const QUERY_ISSUE_KINDS: readonly ["invalidStructure", "duplicateId", "unknownTable", "unknownColumn", "tableNotInQuery", "unqualifiedField", "incomplete", "argCount", "ambiguousTable", "duplicateTableName", "derivedColumnName", "unknownFunction", "joinOrder", "distinctSort", "notGrouped", "unknownAggregate", "misplacedAggregate", "paramConflict", "fanOut", "crossJoin", "misplacedWindow", "groupedWindow", "unorderedWindow", "unlinkedJoin", "drillAcrossOutOfStep", "drillAcrossFilterMixed", "tooLong", "dialectUnsupported", "subqueryColumns", "notInSubquery", "noLimit", "limitTooHigh", "typeMismatch", "invalidPattern", "unionColumns", "unionTypes", "sharedOrder", "unusedShared", "joinOnlyColumn"];
139
149
  /** The kinds that are warnings: the query can run with them. Only these
140
150
  * can be hidden (ValidateQueryOptions' hideWarnings). */
141
151
  export declare const QUERY_WARNING_KINDS: readonly ["fanOut", "crossJoin", "unlinkedJoin", "drillAcrossFilterMixed", "notInSubquery", "noLimit", "limitTooHigh", "typeMismatch", "unknownAggregate", "unusedShared"];
@@ -29,6 +29,12 @@ export declare function writeMarked<T>(marks: SpanMarks, write: () => T): T;
29
29
  * NULL AND b IS NULL))`, the same rows in any database, for SQL Server
30
30
  * before 2022, which has no IS NOT DISTINCT FROM. */
31
31
  export type NullSafeEqual = 'native' | 'expanded';
32
+ /** How a calculation's `/` is written (issue 26). `'decimal'`: with its
33
+ * fraction in every database, `5 / 2` is 2.5 — written `a * 1.0 / b` in
34
+ * PostgreSQL and SQL Server, which drop it when both sides are whole
35
+ * numbers (MySQL's `/` keeps it). `'native'`: `a / b`, each database's
36
+ * own division. */
37
+ export type Division = 'decimal' | 'native';
32
38
  export declare function astToWhereClause(ast: ExpressionNode, dialect: SqlDialect, params?: SqlParams): string;
33
39
  export declare function formatFromClause(from: FromClause, dialect: SqlDialect, params?: SqlParams): string;
34
40
  export declare function formatJoinClause(join: JoinClause, dialect: SqlDialect, params?: SqlParams): string;
@@ -66,6 +72,8 @@ export declare function astToSql(pipeline: QueryPipeline, dialect: SqlDialect, o
66
72
  schema?: DatabaseSchema;
67
73
  /** How a null-safe equal is written (see ParameterizedSqlOptions). */
68
74
  nullSafeEqual?: NullSafeEqual;
75
+ /** How a calculation divides (see ParameterizedSqlOptions). */
76
+ division?: Division;
69
77
  }): string;
70
78
  /** SQL with its values as bound parameters, for executing it. */
71
79
  export interface ParameterizedSql {
@@ -101,6 +109,10 @@ export interface ParameterizedSqlOptions {
101
109
  /** How `IS NOT DISTINCT FROM` is written: `'native'` (default), or
102
110
  * `'expanded'` into `=` and IS NULL for SQL Server before 2022. */
103
111
  nullSafeEqual?: NullSafeEqual;
112
+ /** How a calculation's `/` is written: `'decimal'` (default), with its
113
+ * fraction everywhere (`5 / 2` is 2.5), or `'native'`, each database's
114
+ * own (2 in PostgreSQL and SQL Server for two whole numbers). */
115
+ division?: Division;
104
116
  }
105
117
  /** The query as SQL whose values — in WHERE, JOIN ON and SELECT, including
106
118
  * inside functions, IF/CASE and IN lists — are bound parameters rather than
@@ -2,7 +2,7 @@ import type { LiteralValue } from './ast.js';
2
2
  import type { QueryValue } from './queryAst.js';
3
3
  /** The format saveQuery writes. Raised when a change to the query's shape
4
4
  * needs older stored queries migrated (see MIGRATIONS). */
5
- export declare const QUERY_FORMAT_VERSION = 4;
5
+ export declare const QUERY_FORMAT_VERSION = 6;
6
6
  /** A query as stored: plain JSON, with the format it's in. */
7
7
  export interface StoredQuery {
8
8
  version: number;
@@ -17,7 +17,10 @@ export interface Appearance {
17
17
  * always beside them. */
18
18
  actions: 'hover' | 'always';
19
19
  }
20
- /** CHARCOAL's (looks.ts). */
20
+ /** CHARCOAL's (looks.ts): buttons always beside each node. */
21
+ export declare const CHARCOAL_APPEARANCE: Appearance;
22
+ /** NAVY's (looks.ts), the default: a node's buttons in a toolbar on hover. */
23
+ export declare const NAVY_APPEARANCE: Appearance;
21
24
  export declare const DEFAULT_APPEARANCE: Appearance;
22
25
  declare const AppearanceContext: import("react").Context<Appearance>;
23
26
  export declare function useAppearance(): Appearance;