@nongt/visql 0.0.0-stage → 0.3.1
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/LICENSE +21 -0
- package/README.md +916 -2
- package/dist/PipelineEditor-DNZkDSaY.js +10042 -0
- package/dist/calendarDate-CYlr9TvX.js +43 -0
- package/dist/core-api-BDCnbFHY.js +1056 -0
- package/dist/core.js +80 -0
- package/dist/fixtures.js +7 -0
- package/dist/index.js +145 -0
- package/dist/issueLocation-Cw5sttQL.js +3183 -0
- package/dist/mui-date-pickers.js +117 -0
- package/dist/mui.js +510 -0
- package/dist/schema-z95dxLxu.js +839 -0
- package/dist/sql-import.js +1366 -0
- package/dist/style.css +1 -0
- package/dist/tokens-BTaVMSOx.js +95 -0
- package/dist/types/adapters/mui/MuiDatePicker.d.ts +12 -0
- package/dist/types/adapters/mui/MuiDateTimePicker.d.ts +10 -0
- package/dist/types/adapters/mui/MuiListInput.d.ts +9 -0
- package/dist/types/adapters/mui/MuiTimePicker.d.ts +10 -0
- package/dist/types/adapters/mui/QueryBuilder.d.ts +12 -0
- package/dist/types/adapters/mui/components.d.ts +16 -0
- package/dist/types/adapters/mui/index.d.ts +6 -0
- package/dist/types/adapters/mui/muiPickers.d.ts +6 -0
- package/dist/types/adapters/mui/pickerStyles.d.ts +28 -0
- package/dist/types/adapters/mui/theme.d.ts +11 -0
- package/dist/types/core/BetweenOnTextContext.d.ts +11 -0
- package/dist/types/core/DialectContext.d.ts +10 -0
- package/dist/types/core/DrillDownContext.d.ts +22 -0
- package/dist/types/core/ExistsContext.d.ts +29 -0
- package/dist/types/core/FlowDirectionContext.d.ts +8 -0
- package/dist/types/core/FlowOrientationContext.d.ts +6 -0
- package/dist/types/core/FunctionsContext.d.ts +25 -0
- package/dist/types/core/GroupKeysContext.d.ts +18 -0
- package/dist/types/core/MeasureLockContext.d.ts +12 -0
- package/dist/types/core/ReadOnlyContext.d.ts +6 -0
- package/dist/types/core/SchemaContext.d.ts +8 -0
- package/dist/types/core/SubqueryContext.d.ts +16 -0
- package/dist/types/core/UnionBranchContext.d.ts +6 -0
- package/dist/types/core/ValueInputContext.d.ts +24 -0
- package/dist/types/core/absolutePath.d.ts +57 -0
- package/dist/types/core/ast.d.ts +154 -0
- package/dist/types/core/astChildren.d.ts +4 -0
- package/dist/types/core/astEqual.d.ts +4 -0
- package/dist/types/core/astMap.d.ts +21 -0
- package/dist/types/core/calendarDate.d.ts +21 -0
- package/dist/types/core/columnFormats.d.ts +23 -0
- package/dist/types/core/components/BoolPicker.d.ts +8 -0
- package/dist/types/core/components/NumberInput.d.ts +8 -0
- package/dist/types/core/components/ReadOnlyPart.d.ts +10 -0
- package/dist/types/core/components/TextInput.d.ts +8 -0
- package/dist/types/core/components/expression/BinaryView.d.ts +10 -0
- package/dist/types/core/components/expression/ExprSummary.d.ts +12 -0
- package/dist/types/core/components/expression/ExpressionTypeSelector.d.ts +35 -0
- package/dist/types/core/components/expression/ExpressionView.d.ts +30 -0
- package/dist/types/core/components/expression/FieldView.d.ts +15 -0
- package/dist/types/core/components/expression/FormulaPeek.d.ts +14 -0
- package/dist/types/core/components/expression/FunctionArgInput.d.ts +22 -0
- package/dist/types/core/components/expression/FunctionView.d.ts +7 -0
- package/dist/types/core/components/expression/ListView.d.ts +20 -0
- package/dist/types/core/components/expression/LiteralView.d.ts +23 -0
- package/dist/types/core/components/expression/LogicalView.d.ts +9 -0
- package/dist/types/core/components/expression/MeasureMenu.d.ts +21 -0
- package/dist/types/core/components/expression/ParamView.d.ts +13 -0
- package/dist/types/core/components/expression/RelativeDateView.d.ts +15 -0
- package/dist/types/core/components/expression/SubqueryView.d.ts +8 -0
- package/dist/types/core/components/expression/formulaClasses.d.ts +8 -0
- package/dist/types/core/components/flow/CaseBranchFlowNode.d.ts +5 -0
- package/dist/types/core/components/flow/CaseElseFlowNode.d.ts +5 -0
- package/dist/types/core/components/flow/CaseFlowNode.d.ts +5 -0
- package/dist/types/core/components/flow/ConditionFlowNode.d.ts +5 -0
- package/dist/types/core/components/flow/CreateConditionFlowNode.d.ts +14 -0
- package/dist/types/core/components/flow/CreateHavingFlowNode.d.ts +11 -0
- package/dist/types/core/components/flow/DistinctToggle.d.ts +10 -0
- package/dist/types/core/components/flow/ExistsFlowNode.d.ts +9 -0
- package/dist/types/core/components/flow/FromFlowNode.d.ts +110 -0
- package/dist/types/core/components/flow/FunctionArgFlowNode.d.ts +5 -0
- package/dist/types/core/components/flow/FunctionCallFlowNode.d.ts +5 -0
- package/dist/types/core/components/flow/FunctionSortKeys.d.ts +10 -0
- package/dist/types/core/components/flow/GroupBgNode.d.ts +14 -0
- package/dist/types/core/components/flow/GroupByFlowNode.d.ts +29 -0
- package/dist/types/core/components/flow/IfElseFlowNode.d.ts +5 -0
- package/dist/types/core/components/flow/IfFlowNode.d.ts +5 -0
- package/dist/types/core/components/flow/IfThenFlowNode.d.ts +5 -0
- package/dist/types/core/components/flow/LeafConditionFrame.d.ts +19 -0
- package/dist/types/core/components/flow/LogicalFlowNode.d.ts +5 -0
- package/dist/types/core/components/flow/MoveTooltip.d.ts +19 -0
- package/dist/types/core/components/flow/NotFlowNode.d.ts +5 -0
- package/dist/types/core/components/flow/OrderByFlowNode.d.ts +32 -0
- package/dist/types/core/components/flow/SectionLabelFlowNode.d.ts +7 -0
- package/dist/types/core/components/flow/SelectFlowNode.d.ts +49 -0
- package/dist/types/core/components/flow/SharedQueriesFlowNode.d.ts +39 -0
- package/dist/types/core/components/flow/SummaryPill.d.ts +12 -0
- package/dist/types/core/components/flow/WarningNote.d.ts +9 -0
- package/dist/types/core/components/flow/chainSides.d.ts +18 -0
- package/dist/types/core/components/flow/dragContext.d.ts +12 -0
- package/dist/types/core/components/flow/moveTooltipHysteresis.d.ts +18 -0
- package/dist/types/core/components/flow/useRowDrag.d.ts +34 -0
- package/dist/types/core/components/flow/useRowReorderFlip.d.ts +30 -0
- package/dist/types/core/derivedTables.d.ts +98 -0
- package/dist/types/core/distinctSort.d.ts +7 -0
- package/dist/types/core/drillPath.d.ts +11 -0
- package/dist/types/core/exists.d.ts +7 -0
- package/dist/types/core/existsMenu.d.ts +61 -0
- package/dist/types/core/expressionFlow.d.ts +428 -0
- package/dist/types/core/fanOut.d.ts +58 -0
- package/dist/types/core/findParts.d.ts +19 -0
- package/dist/types/core/flowTrees.d.ts +20 -0
- package/dist/types/core/focusKey.d.ts +10 -0
- package/dist/types/core/formula.d.ts +24 -0
- package/dist/types/core/formulaPeek.d.ts +16 -0
- package/dist/types/core/functionRegistry.d.ts +117 -0
- package/dist/types/core/grouping.d.ts +58 -0
- package/dist/types/core/history.d.ts +25 -0
- package/dist/types/core/i18n/defaultMessages.d.ts +367 -0
- package/dist/types/core/i18n/messages.d.ts +273 -0
- package/dist/types/core/i18n/relativeDateWords.d.ts +3 -0
- package/dist/types/core/id.d.ts +5 -0
- package/dist/types/core/issueAnchor.d.ts +29 -0
- package/dist/types/core/issueLocation.d.ts +105 -0
- package/dist/types/core/limits.d.ts +17 -0
- package/dist/types/core/measures.d.ts +51 -0
- package/dist/types/core/params.d.ts +30 -0
- package/dist/types/core/pipelineAnchor.d.ts +118 -0
- package/dist/types/core/pipelineFlow.d.ts +271 -0
- package/dist/types/core/queryAst.d.ts +201 -0
- package/dist/types/core/queryHelpers.d.ts +113 -0
- package/dist/types/core/queryValidation.d.ts +206 -0
- package/dist/types/core/relativeDates.d.ts +11 -0
- package/dist/types/core/resolveNames.d.ts +17 -0
- package/dist/types/core/rowRange.d.ts +3 -0
- package/dist/types/core/schema.d.ts +119 -0
- package/dist/types/core/scopeQuery.d.ts +45 -0
- package/dist/types/core/selectColumns.d.ts +23 -0
- package/dist/types/core/settleQuery.d.ts +11 -0
- package/dist/types/core/sharedQueries.d.ts +66 -0
- package/dist/types/core/sqlGen.d.ts +102 -0
- package/dist/types/core/sqlOffsets.d.ts +5 -0
- package/dist/types/core/sqlSpans.d.ts +33 -0
- package/dist/types/core/storedQuery.d.ts +43 -0
- package/dist/types/core/summarize.d.ts +3 -0
- package/dist/types/core/theme/tokens.d.ts +74 -0
- package/dist/types/core/ui/UIContext.d.ts +6 -0
- package/dist/types/core/ui/index.d.ts +12 -0
- package/dist/types/core/ui/types.d.ts +264 -0
- package/dist/types/core/unionTables.d.ts +121 -0
- package/dist/types/core/useValueTypes.d.ts +12 -0
- package/dist/types/core/valueTypes.d.ts +54 -0
- package/dist/types/core-api.d.ts +20 -0
- package/dist/types/features/queryEditor/ExpressionFlowCanvas.d.ts +10 -0
- package/dist/types/features/queryEditor/FindBox.d.ts +12 -0
- package/dist/types/features/queryEditor/FlowCanvas.d.ts +96 -0
- package/dist/types/features/queryEditor/FocusPulse.d.ts +10 -0
- package/dist/types/features/queryEditor/IssuesButton.d.ts +16 -0
- package/dist/types/features/queryEditor/PipelineEditor.d.ts +210 -0
- package/dist/types/features/queryEditor/QueryOutline.d.ts +16 -0
- package/dist/types/features/queryEditor/ResultsPanel.d.ts +11 -0
- package/dist/types/features/queryEditor/RunButton.d.ts +11 -0
- package/dist/types/features/queryEditor/SubFlowPanel.d.ts +24 -0
- package/dist/types/features/queryEditor/UndoRedoToast.d.ts +6 -0
- package/dist/types/features/queryEditor/canvasPositioning.d.ts +81 -0
- package/dist/types/features/queryEditor/findKeys.d.ts +3 -0
- package/dist/types/features/queryEditor/flowDragUtils.d.ts +16 -0
- package/dist/types/features/queryEditor/focusContext.d.ts +24 -0
- package/dist/types/features/queryEditor/hoveredPart.d.ts +32 -0
- package/dist/types/features/queryEditor/issueFocusParts.d.ts +9 -0
- package/dist/types/features/queryEditor/issueLocationText.d.ts +7 -0
- package/dist/types/features/queryEditor/issueText.d.ts +11 -0
- package/dist/types/features/queryEditor/outlineSections.d.ts +23 -0
- package/dist/types/features/queryEditor/run.d.ts +36 -0
- package/dist/types/features/queryEditor/sectionLabels.d.ts +15 -0
- package/dist/types/features/queryEditor/treeScopeContext.d.ts +14 -0
- package/dist/types/features/queryEditor/useRemeasureOnDirectionChange.d.ts +7 -0
- package/dist/types/features/queryEditor/useRevealNewNodes.d.ts +35 -0
- package/dist/types/features/queryEditor/withTreeScope.d.ts +10 -0
- package/dist/types/fixtures.d.ts +44 -0
- package/dist/types/index.d.ts +13 -0
- package/dist/types/mui-date-pickers.d.ts +3 -0
- package/dist/types/mui.d.ts +2 -0
- package/dist/types/sql-import.d.ts +3 -0
- package/dist/types/sqlImport/context.d.ts +71 -0
- package/dist/types/sqlImport/expressions.d.ts +11 -0
- package/dist/types/sqlImport/importSql.d.ts +28 -0
- package/dist/types/sqlImport/parse.d.ts +6 -0
- package/dist/types/sqlImport/syntax.d.ts +245 -0
- package/dist/types/sqlImport/tokenize.d.ts +26 -0
- package/package.json +164 -3
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import type { ExpressionNode } from './ast.js';
|
|
2
|
+
import { type QueryBody } from './queryAst.js';
|
|
3
|
+
import type { DatabaseSchema } from './schema.js';
|
|
4
|
+
/** A join's place in the query's join tree (issue 146): the table it
|
|
5
|
+
* hangs off, and whether its rows repeat the rows they meet. */
|
|
6
|
+
export interface JoinMultiplicity {
|
|
7
|
+
/** The join's id. */
|
|
8
|
+
joinId: string;
|
|
9
|
+
/** The joined table, by the name fields use (its alias when it has one). */
|
|
10
|
+
key: string;
|
|
11
|
+
/** The table it hangs off — the earlier one its ON compares it with, by
|
|
12
|
+
* the name fields use; the base table when there's none. */
|
|
13
|
+
parent: string;
|
|
14
|
+
/** - `one`: each parent row meets at most one of its rows (it's the one
|
|
15
|
+
* side of the relation its ON follows, or a derived table with one row
|
|
16
|
+
* per what its ON matches, or a CROSS JOIN of a single row).
|
|
17
|
+
* - `many`: the parent's rows repeat, once per matching row (it holds
|
|
18
|
+
* the foreign key: the many side).
|
|
19
|
+
* - `cross`: a CROSS JOIN of more than one row — every row repeats.
|
|
20
|
+
* - `unknown`: its ON isn't a declared relation, so it could be either. */
|
|
21
|
+
side: 'one' | 'many' | 'cross' | 'unknown';
|
|
22
|
+
}
|
|
23
|
+
/** Each join of `query`'s own (not a derived table's), in order: the
|
|
24
|
+
* table it hangs off, and whether it repeats rows — from the schema's
|
|
25
|
+
* relations, which say which side of a join is the many side. */
|
|
26
|
+
export declare function joinMultiplicity(query: QueryBody, schema: DatabaseSchema): JoinMultiplicity[];
|
|
27
|
+
/** The tables (by the name or alias fields use) whose rows the joins
|
|
28
|
+
* repeat: everything but the many side's subtree, past a `many` join;
|
|
29
|
+
* the one side's subtree, past a `one` join; everything, past a `cross`.
|
|
30
|
+
* A derived table on the one side repeats too: its per-match total shows
|
|
31
|
+
* on each row it meets. An `unknown` join is left out (`ignore`, what
|
|
32
|
+
* fanOut does) or taken as `many` (`repeat`: the safe answer for an app
|
|
33
|
+
* that can't ask). */
|
|
34
|
+
export declare function repeatedTables(query: QueryBody, schema: DatabaseSchema, options?: {
|
|
35
|
+
unknown?: 'ignore' | 'repeat';
|
|
36
|
+
}): Set<string>;
|
|
37
|
+
/** The repeated tables `node` reads (its fields' tables), each once — for
|
|
38
|
+
* an app aggregating outside SQL (a pivot grid): a column reading one can
|
|
39
|
+
* be summed up there with MIN, MAX or COUNT DISTINCT, never SUM, AVG or
|
|
40
|
+
* COUNT (see fanOut). */
|
|
41
|
+
export declare function repeatedReads(node: ExpressionNode, repeated: ReadonlySet<string>): string[];
|
|
42
|
+
/** Whether `query`'s result has at most one row per row of its base table
|
|
43
|
+
* — what an app needs before it sums up detail rows itself. `many`: the
|
|
44
|
+
* joins repeat the base table's rows, or a RIGHT/FULL join adds rows with
|
|
45
|
+
* no base row. `unknown`: they would, if a join whose ON isn't a declared
|
|
46
|
+
* relation repeats rows. Filters (WHERE, EXISTS, IN) never add rows. */
|
|
47
|
+
export declare function rowsPerBase(query: QueryBody, schema: DatabaseSchema): 'one' | 'many' | 'unknown';
|
|
48
|
+
/** Where a query's sums, averages or counts read a column of a table its
|
|
49
|
+
* joins repeat (see repeatedTables) — each comes out too high. */
|
|
50
|
+
export interface FanOut {
|
|
51
|
+
/** The repeated tables those aggregates read (names or aliases). */
|
|
52
|
+
tables: string[];
|
|
53
|
+
/** SELECT columns and ORDER BY keys (ids) with such an aggregate. */
|
|
54
|
+
select: string[];
|
|
55
|
+
orderBy: string[];
|
|
56
|
+
having: boolean;
|
|
57
|
+
}
|
|
58
|
+
export declare function fanOut(query: QueryBody, schema: DatabaseSchema): FanOut;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { type FunctionRegistry } from './functionRegistry.js';
|
|
2
|
+
import type { QueryPipeline } from './queryAst.js';
|
|
3
|
+
import { type DatabaseSchema } from './schema.js';
|
|
4
|
+
export interface FoundPart {
|
|
5
|
+
/** What it is: a column, a value, a function, a param, a table, or a
|
|
6
|
+
* SELECT column's alias. */
|
|
7
|
+
kind: 'column' | 'value' | 'function' | 'param' | 'table' | 'alias';
|
|
8
|
+
/** How it reads: a column by its label, a table by its alias or label. */
|
|
9
|
+
text: string;
|
|
10
|
+
/** All it can be found by: its text, and its names besides (a column's
|
|
11
|
+
* name, its table's label; a function's other names). */
|
|
12
|
+
searchText: string;
|
|
13
|
+
pathSegments: (string | number)[];
|
|
14
|
+
}
|
|
15
|
+
/** Every part of `query` that can be found, in the order it reads. */
|
|
16
|
+
export default function findParts(query: QueryPipeline, { schema, functions }?: {
|
|
17
|
+
schema?: DatabaseSchema;
|
|
18
|
+
functions?: FunctionRegistry;
|
|
19
|
+
}): FoundPart[];
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { Edge, Node } from '@xyflow/react';
|
|
2
|
+
export type FlowTree = 'where' | 'having';
|
|
3
|
+
/** What a tree's node ids start with (after `bg-`, for a background): ''
|
|
4
|
+
* for WHERE, `having:` for HAVING. */
|
|
5
|
+
export declare const treeIdPrefix: (tree: FlowTree) => string;
|
|
6
|
+
/** The tree a canvas node belongs to (WHERE for any id without a prefix —
|
|
7
|
+
* FROM, the sections and their captions included). */
|
|
8
|
+
export declare function treeOfId(id: string): FlowTree;
|
|
9
|
+
/** A node's id within its own tree, as expressionToFlow named it. */
|
|
10
|
+
export declare function localNodeId(id: string): string;
|
|
11
|
+
/** A tree-local id as it goes on the canvas. */
|
|
12
|
+
export declare function canvasNodeId(tree: FlowTree, id: string): string;
|
|
13
|
+
/** A tree's nodes and edges as they go on the canvas: ids namespaced. */
|
|
14
|
+
export declare function namespaceGraph(tree: FlowTree, nodes: Node[], edges: Edge[]): {
|
|
15
|
+
nodes: Node[];
|
|
16
|
+
edges: Edge[];
|
|
17
|
+
};
|
|
18
|
+
/** The canvas's nodes of one tree, with their own ids back — what
|
|
19
|
+
* layoutFlow reads last render's sizes from. */
|
|
20
|
+
export declare function treeNodes(tree: FlowTree, nodes: Node[]): Node[];
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { AbsolutePath } from './absolutePath.js';
|
|
2
|
+
/** A part of a condition by its path in its canvas's tree: a comparison's
|
|
3
|
+
* side (`[..., { kind: 'left' }]`). */
|
|
4
|
+
export declare const pathFocusKey: (path: AbsolutePath) => string;
|
|
5
|
+
/** One of BETWEEN's bounds (issue 169), by its comparison's right side's
|
|
6
|
+
* path and its place: 0 low, 1 high. */
|
|
7
|
+
export declare const boundFocusKey: (right: AbsolutePath, index: number) => string;
|
|
8
|
+
/** A row of a section's list: `select`, `groupBy` or `orderBy`, by its
|
|
9
|
+
* place. */
|
|
10
|
+
export declare const rowFocusKey: (list: string, index: number) => string;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { ExpressionNode } from './ast.js';
|
|
2
|
+
import { type FunctionRegistry } from './functionRegistry.js';
|
|
3
|
+
import { type DatabaseSchema } from './schema.js';
|
|
4
|
+
/** What a part of a formula is: a column, a value, a param, a function's
|
|
5
|
+
* name, a keyword (AND, IF's `?`, CASE's `else`…), an operator, or a gap
|
|
6
|
+
* — something not filled in yet. None: punctuation and spaces. */
|
|
7
|
+
export type FormulaRole = 'column' | 'value' | 'param' | 'function' | 'keyword' | 'operator' | 'gap';
|
|
8
|
+
export interface FormulaPart {
|
|
9
|
+
text: string;
|
|
10
|
+
role?: FormulaRole;
|
|
11
|
+
}
|
|
12
|
+
export interface FormulaOptions {
|
|
13
|
+
/** Columns by their labels (else their names). */
|
|
14
|
+
schema?: DatabaseSchema;
|
|
15
|
+
/** Which arguments are words (a unit, a type), not values. */
|
|
16
|
+
functions?: FunctionRegistry;
|
|
17
|
+
/** How long the text may be, in characters (default 40): parts deeper
|
|
18
|
+
* in are left out (`…`) until it fits, the outermost kept. */
|
|
19
|
+
budget?: number;
|
|
20
|
+
}
|
|
21
|
+
/** The formula's text: its parts, joined. */
|
|
22
|
+
export declare function formulaText(parts: FormulaPart[]): string;
|
|
23
|
+
/** `expression` as a formula, as deep as `budget` allows. */
|
|
24
|
+
export default function formula(expression: ExpressionNode, options?: FormulaOptions): FormulaPart[];
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { AbsolutePath } from './absolutePath.js';
|
|
2
|
+
import type { ExpressionNode } from './ast.js';
|
|
3
|
+
import { type FormulaOptions, type FormulaPart } from './formula.js';
|
|
4
|
+
/** A piece of a line: a formula, with where it is in the expression
|
|
5
|
+
* (none: words of the layout, such as `→`). */
|
|
6
|
+
export interface PeekPiece {
|
|
7
|
+
parts: FormulaPart[];
|
|
8
|
+
path?: AbsolutePath;
|
|
9
|
+
}
|
|
10
|
+
export interface PeekLine {
|
|
11
|
+
/** 0 for the expression's own line, 1 for its parts. */
|
|
12
|
+
indent: number;
|
|
13
|
+
pieces: PeekPiece[];
|
|
14
|
+
}
|
|
15
|
+
/** `expression`'s lines: its own, then one per part of it. */
|
|
16
|
+
export default function peekLines(expression: ExpressionNode, options?: FormulaOptions): PeekLine[];
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import type { ExpressionNode, ValueType } from './ast.js';
|
|
2
|
+
import type { DatabaseColumnType } from './schema.js';
|
|
3
|
+
import type { SqlDialect } from './sqlGen.js';
|
|
4
|
+
/**
|
|
5
|
+
* Semantic kind of a function argument — drives UI rendering and field filtering.
|
|
6
|
+
*
|
|
7
|
+
* expr — any expression (field, literal, function, IF/CASE …)
|
|
8
|
+
* date-expr — expression expected to yield a date/datetime value
|
|
9
|
+
* num-expr — expression expected to yield a numeric value
|
|
10
|
+
* str-expr — expression expected to yield a string value
|
|
11
|
+
* unit — date-part keyword (DAY, MONTH …) stored as string literal, shown as dropdown
|
|
12
|
+
* type-name — SQL type name (INTEGER, VARCHAR …) stored as string literal, shown as text input
|
|
13
|
+
* fixed-text — a text written into the SQL itself, never a parameter (STRING_AGG's
|
|
14
|
+
* separator: MySQL takes only a literal there), stored as string literal,
|
|
15
|
+
* shown as text input
|
|
16
|
+
*/
|
|
17
|
+
export type ArgKind = 'expr' | 'date-expr' | 'num-expr' | 'str-expr' | 'unit' | 'type-name' | 'fixed-text';
|
|
18
|
+
/**
|
|
19
|
+
* Maps ArgKind to the column types that should be shown when the arg value is a field.
|
|
20
|
+
* Undefined means no filter (all column types are shown).
|
|
21
|
+
*/
|
|
22
|
+
export declare const ARG_TYPE_FILTER: Partial<Record<ArgKind, DatabaseColumnType[]>>;
|
|
23
|
+
export interface ArgDef {
|
|
24
|
+
/** Display label, e.g. 'date', 'amount', 'unit'. */
|
|
25
|
+
label: string;
|
|
26
|
+
kind: ArgKind;
|
|
27
|
+
/** When true, this arg may be omitted (trailing optional args). */
|
|
28
|
+
optional?: boolean;
|
|
29
|
+
/**
|
|
30
|
+
* When true, this arg (must be the last) can appear multiple times.
|
|
31
|
+
* buildDefaultArgs creates exactly one instance for the initial auto-create.
|
|
32
|
+
*/
|
|
33
|
+
variadic?: boolean;
|
|
34
|
+
/** Default ExpressionNode used when auto-creating this arg slot. */
|
|
35
|
+
default?: ExpressionNode;
|
|
36
|
+
/** Valid string choices — used when kind === 'unit'. */
|
|
37
|
+
choices?: string[];
|
|
38
|
+
}
|
|
39
|
+
export interface FunctionSignature {
|
|
40
|
+
name: string;
|
|
41
|
+
args: ArgDef[];
|
|
42
|
+
/** SQL dialects this function exists in. Omitted = all of them. Used by
|
|
43
|
+
* functionsForDialect() to offer only what the target database supports. */
|
|
44
|
+
dialects?: SqlDialect[];
|
|
45
|
+
/** An aggregate (SUM, COUNT, …): one value per group. Only offered where
|
|
46
|
+
* SQL allows one — SELECT, HAVING and ORDER BY, not WHERE, JOIN ON or
|
|
47
|
+
* GROUP BY — and what makes a query grouped (see grouping.ts). */
|
|
48
|
+
aggregate?: boolean;
|
|
49
|
+
/** The type of its result (issue 130), so a value compared with it gets
|
|
50
|
+
* the matching input: `'arg'` for its first argument's (MIN, COALESCE,
|
|
51
|
+
* DATE_ADD). Omitted: not known (the user picks the value's type). */
|
|
52
|
+
returns?: ValueType | 'arg';
|
|
53
|
+
/** Other names it goes by in some databases (STRING_AGG is MySQL's
|
|
54
|
+
* GROUP_CONCAT): typing one in a function picker finds it. The query
|
|
55
|
+
* always stores `name`. */
|
|
56
|
+
aliases?: string[];
|
|
57
|
+
}
|
|
58
|
+
/** Every function the editor offers, keyed by UPPERCASE name. The editor
|
|
59
|
+
* takes one through PipelineEditor's `functions` prop (default:
|
|
60
|
+
* DEFAULT_FUNCTIONS), so a host can add its own, drop some, or restrict
|
|
61
|
+
* them to a dialect. Function calls are rendered to SQL generically as
|
|
62
|
+
* `NAME(args…)`, so a custom function needs nothing more than its
|
|
63
|
+
* signature here. */
|
|
64
|
+
export type FunctionRegistry = Record<string, FunctionSignature>;
|
|
65
|
+
/** Date-part unit choices used by date functions. */
|
|
66
|
+
export declare const DATE_UNIT_CHOICES: string[];
|
|
67
|
+
/**
|
|
68
|
+
* Return the ArgDef for args[index].
|
|
69
|
+
* If index is beyond the defined args and the last arg is variadic, return the last ArgDef.
|
|
70
|
+
* Otherwise returns undefined (unrecognised arg slot).
|
|
71
|
+
*/
|
|
72
|
+
export declare function getArgDef(sig: FunctionSignature, index: number): ArgDef | undefined;
|
|
73
|
+
/**
|
|
74
|
+
* Create the initial arg list from a signature, using each ArgDef's default value.
|
|
75
|
+
* Variadic args produce exactly one instance.
|
|
76
|
+
*/
|
|
77
|
+
export declare function buildDefaultArgs(sig: FunctionSignature): ExpressionNode[];
|
|
78
|
+
export declare const FUNCTION_REGISTRY: FunctionRegistry;
|
|
79
|
+
/**
|
|
80
|
+
* Look up a FunctionSignature by name (case-insensitive).
|
|
81
|
+
* Returns undefined for unknown functions.
|
|
82
|
+
*/
|
|
83
|
+
export declare function lookupSignature(fnName: string, registry?: FunctionRegistry): FunctionSignature | undefined;
|
|
84
|
+
/** The function `typed` names in a picker: by its name, else by one of its
|
|
85
|
+
* aliases (GROUP_CONCAT finds STRING_AGG). */
|
|
86
|
+
export declare function pickFunction(typed: string, registry: FunctionRegistry): FunctionSignature | undefined;
|
|
87
|
+
/**
|
|
88
|
+
* Returns whether an additional arg can be appended to the function.
|
|
89
|
+
* - Unknown function (no sig): always true.
|
|
90
|
+
* - Variadic last arg: always true.
|
|
91
|
+
* - Otherwise: true only if currentCount is below the defined arg count.
|
|
92
|
+
*/
|
|
93
|
+
export declare function canAddArg(sig: FunctionSignature | undefined, currentCount: number): boolean;
|
|
94
|
+
/**
|
|
95
|
+
* Returns whether the last arg can be removed from the function.
|
|
96
|
+
* - Unknown function (no sig): true when at least one arg exists.
|
|
97
|
+
* - Variadic last arg: true when more than one arg exists (keep ≥ 1).
|
|
98
|
+
* - Otherwise: true only if there are optional trailing args that have been added.
|
|
99
|
+
*/
|
|
100
|
+
export declare function canRemoveArg(sig: FunctionSignature | undefined, currentCount: number): boolean;
|
|
101
|
+
/** All function names in `registry`, sorted — what the function picker offers. */
|
|
102
|
+
export declare function functionNames(registry?: FunctionRegistry): string[];
|
|
103
|
+
/** The default registry's names, for autocomplete. */
|
|
104
|
+
export declare const ALL_FUNCTION_NAMES: string[];
|
|
105
|
+
/** The functions the editor offers out of the box. Spread it to extend it
|
|
106
|
+
* (`{ ...DEFAULT_FUNCTIONS, MY_FN: {...} }`), or filter it. */
|
|
107
|
+
export declare const DEFAULT_FUNCTIONS: FunctionRegistry;
|
|
108
|
+
/** `registry` re-keyed by uppercase name (and each signature's `name`
|
|
109
|
+
* uppercased to match), so lookups — which are case-insensitive — find
|
|
110
|
+
* entries a host wrote in any case. */
|
|
111
|
+
export declare function normalizeRegistry(registry: FunctionRegistry): FunctionRegistry;
|
|
112
|
+
/** `registry` without its aggregates — what's offered where SQL doesn't
|
|
113
|
+
* allow one (WHERE, JOIN ON, GROUP BY). */
|
|
114
|
+
export declare function withoutAggregates(registry: FunctionRegistry): FunctionRegistry;
|
|
115
|
+
/** Only the functions available in `dialect` (those with no `dialects` list
|
|
116
|
+
* are available everywhere). */
|
|
117
|
+
export declare function functionsForDialect(registry: FunctionRegistry, dialect: SqlDialect): FunctionRegistry;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import type { ExpressionNode } from './ast.js';
|
|
2
|
+
import { type FunctionRegistry } from './functionRegistry.js';
|
|
3
|
+
import type { QueryBody } from './queryAst.js';
|
|
4
|
+
/** A call to one of `registry`'s aggregates (SUM, COUNT, …). */
|
|
5
|
+
export declare function isAggregateCall(node: ExpressionNode, registry: FunctionRegistry): boolean;
|
|
6
|
+
/** Whether `node` has an aggregate call anywhere in it. */
|
|
7
|
+
export declare function containsAggregate(node: ExpressionNode | undefined, registry: FunctionRegistry): boolean;
|
|
8
|
+
/** A call to a function `registry` doesn't know (issue 137). It may be an
|
|
9
|
+
* aggregate (a database's own, a host's left out of the registry), so
|
|
10
|
+
* it's never made a group key, nor reported as not one — validateQuery
|
|
11
|
+
* warns about it instead (`unknownAggregate`). An unnamed call is
|
|
12
|
+
* unfinished, not unknown. */
|
|
13
|
+
export declare function isUnknownCall(node: ExpressionNode, registry: FunctionRegistry): boolean;
|
|
14
|
+
/** Whether `node` has a call `registry` doesn't know anywhere in it. */
|
|
15
|
+
export declare function containsUnknownCall(node: ExpressionNode | undefined, registry: FunctionRegistry): boolean;
|
|
16
|
+
/** What a grouped query gets wrong: the parts that aren't one value per
|
|
17
|
+
* group, which PostgreSQL, SQL Server and MySQL (ONLY_FULL_GROUP_BY, its
|
|
18
|
+
* default) all reject. */
|
|
19
|
+
export interface GroupingProblems {
|
|
20
|
+
/** SELECT columns (ids) that aren't a group key or an aggregate. */
|
|
21
|
+
select: string[];
|
|
22
|
+
/** No columns picked (SELECT *) in a grouped query. */
|
|
23
|
+
selectAll: boolean;
|
|
24
|
+
/** ORDER BY keys (ids), same rule as SELECT. */
|
|
25
|
+
orderBy: string[];
|
|
26
|
+
/** HAVING uses a column that isn't a group key outside an aggregate. */
|
|
27
|
+
having: boolean;
|
|
28
|
+
}
|
|
29
|
+
/** A query is grouped once it has GROUP BY keys, a HAVING, or an
|
|
30
|
+
* aggregate in SELECT or ORDER BY (`SELECT COUNT(*) FROM t` is one group:
|
|
31
|
+
* the whole table). Everything it returns must then be one value per
|
|
32
|
+
* group — see GroupingProblems. */
|
|
33
|
+
/** Whether the query is grouped (see groupingProblems). */
|
|
34
|
+
export declare function isGrouped(query: QueryBody, registry: FunctionRegistry): boolean;
|
|
35
|
+
/** In a grouped query, the columns a field outside any aggregate may be in
|
|
36
|
+
* HAVING or a sort key: the group keys that are plain columns, as
|
|
37
|
+
* `table.column` (by the name fields use). Undefined when the query isn't
|
|
38
|
+
* grouped — any column goes. See GroupKeysContext. */
|
|
39
|
+
export declare function groupKeyColumns(query: QueryBody, registry: FunctionRegistry): string[] | undefined;
|
|
40
|
+
/** Whether the query sums anything up: an aggregate in SELECT, HAVING or
|
|
41
|
+
* ORDER BY. (GROUP BY keys alone only drop duplicate rows.) */
|
|
42
|
+
export declare function hasAggregate(query: QueryBody, registry: FunctionRegistry): boolean;
|
|
43
|
+
/** Whether `query`'s SELECT has an aggregate — when the editor shows Group
|
|
44
|
+
* Rows (see FlowCanvas). */
|
|
45
|
+
export declare function selectsAggregate(query: QueryBody, registry: FunctionRegistry): boolean;
|
|
46
|
+
/** `query` grouped automatically (issue 134): once it sums anything up
|
|
47
|
+
* (hasAggregate), each SELECT column that isn't one value per group and
|
|
48
|
+
* has no aggregate in it becomes a GROUP BY key — `SELECT city,
|
|
49
|
+
* SUM(total)` groups by city — marked `fromSelect` and following that
|
|
50
|
+
* column: changed with it, and gone with it, or once nothing is summed
|
|
51
|
+
* up any more. A key the user added is never touched; a column it
|
|
52
|
+
* already covers needs none. A column mixing an aggregate and a plain
|
|
53
|
+
* 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
|
|
55
|
+
* keys are never made keys: that would change the grouping unseen. The
|
|
56
|
+
* same object when nothing changes. */
|
|
57
|
+
export declare function groupAutomatically<Q extends QueryBody>(query: Q, registry: FunctionRegistry): Q;
|
|
58
|
+
export declare function groupingProblems(query: QueryBody, registry: FunctionRegistry): GroupingProblems;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { AbsolutePath } from './absolutePath.js';
|
|
2
|
+
export interface HistoryStep<T, P = AbsolutePath> {
|
|
3
|
+
ast: T;
|
|
4
|
+
/** Where this transition happened — used to decide whether to offer navigation.
|
|
5
|
+
* Generic (defaulting to a bare AbsolutePath) so a caller juggling more than one
|
|
6
|
+
* ExpressionNode tree can use a richer anchor that also says *which* tree the
|
|
7
|
+
* path is relative to — see PipelineEditor's PipelineAnchor. */
|
|
8
|
+
path: P;
|
|
9
|
+
}
|
|
10
|
+
export interface HistoryState<T, P = AbsolutePath> {
|
|
11
|
+
past: HistoryStep<T, P>[];
|
|
12
|
+
future: HistoryStep<T, P>[];
|
|
13
|
+
}
|
|
14
|
+
export declare function emptyHistory<T, P = AbsolutePath>(): HistoryState<T, P>;
|
|
15
|
+
/** Record `prevAst` (the state right before an action at `path` was applied)
|
|
16
|
+
* onto the undo stack. Any pending redo history is discarded — the usual
|
|
17
|
+
* convention once a new edit branches off from the current point. */
|
|
18
|
+
export declare function pushHistory<T, P = AbsolutePath>(state: HistoryState<T, P>, prevAst: T, path: P): HistoryState<T, P>;
|
|
19
|
+
interface HistoryResult<T, P = AbsolutePath> {
|
|
20
|
+
state: HistoryState<T, P>;
|
|
21
|
+
step: HistoryStep<T, P>;
|
|
22
|
+
}
|
|
23
|
+
export declare function undoHistory<T, P = AbsolutePath>(state: HistoryState<T, P>, currentAst: T): HistoryResult<T, P> | undefined;
|
|
24
|
+
export declare function redoHistory<T, P = AbsolutePath>(state: HistoryState<T, P>, currentAst: T): HistoryResult<T, P> | undefined;
|
|
25
|
+
export {};
|