@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,201 @@
|
|
|
1
|
+
import type { ExpressionNode } from './ast.js';
|
|
2
|
+
/** 'cross': every row with every row — for a derived table of one row (a
|
|
3
|
+
* total to compare with, see derivedTables' singleRow). It uses no ON; one
|
|
4
|
+
* kept there (from before switching to it) is ignored, and used again
|
|
5
|
+
* once switched back. */
|
|
6
|
+
export declare const joinTypes: readonly ["inner", "left", "right", "full", "cross"];
|
|
7
|
+
export type JoinType = typeof joinTypes[number];
|
|
8
|
+
/** A query's base table: a table of the schema. */
|
|
9
|
+
export interface TableFrom {
|
|
10
|
+
table: string;
|
|
11
|
+
alias?: string;
|
|
12
|
+
query?: undefined;
|
|
13
|
+
shared?: undefined;
|
|
14
|
+
}
|
|
15
|
+
/** A derived table as a query's base (`FROM (SELECT …) AS alias`) — a
|
|
16
|
+
* summary of a summary, like the average of daily totals. `id` says
|
|
17
|
+
* where it is (a QueryPath step), as a derived join's does. */
|
|
18
|
+
export interface DerivedFrom {
|
|
19
|
+
id: string;
|
|
20
|
+
table?: undefined;
|
|
21
|
+
shared?: undefined;
|
|
22
|
+
alias: string;
|
|
23
|
+
query: NestedQuery;
|
|
24
|
+
}
|
|
25
|
+
/** A shared query (issue 194) as a query's base: `FROM name AS alias`.
|
|
26
|
+
* `shared` is the shared query's id; fields name it by `alias`, which
|
|
27
|
+
* stays when the shared query is renamed. */
|
|
28
|
+
export interface SharedFrom {
|
|
29
|
+
shared: string;
|
|
30
|
+
alias: string;
|
|
31
|
+
table?: undefined;
|
|
32
|
+
query?: undefined;
|
|
33
|
+
}
|
|
34
|
+
/** What FROM names: a table, a derived table, or a shared query. */
|
|
35
|
+
export type FromClause = TableFrom | DerivedFrom | SharedFrom;
|
|
36
|
+
interface JoinBase {
|
|
37
|
+
id: string;
|
|
38
|
+
alias?: string;
|
|
39
|
+
joinType: JoinType;
|
|
40
|
+
on?: ExpressionNode;
|
|
41
|
+
}
|
|
42
|
+
/** A join of a table. */
|
|
43
|
+
export interface TableJoin extends JoinBase {
|
|
44
|
+
table: string;
|
|
45
|
+
query?: undefined;
|
|
46
|
+
shared?: undefined;
|
|
47
|
+
}
|
|
48
|
+
/** A derived table's query: a query of its own, joined like a table
|
|
49
|
+
* (`JOIN (SELECT …) AS alias`). Its SELECT's aliases are its columns. */
|
|
50
|
+
export interface DerivedQuery {
|
|
51
|
+
from: FromClause;
|
|
52
|
+
joins: JoinClause[];
|
|
53
|
+
where?: ExpressionNode;
|
|
54
|
+
select: SelectItem[];
|
|
55
|
+
groupBy?: GroupByItem[];
|
|
56
|
+
having?: ExpressionNode;
|
|
57
|
+
distinct?: boolean;
|
|
58
|
+
}
|
|
59
|
+
/** A derived table's query stacking the rows of others (issue 121): the
|
|
60
|
+
* union of its branches, two or more, each a query of its own scope.
|
|
61
|
+
* Its columns are the first branch's names; every branch has as many, by
|
|
62
|
+
* the same names, in order, of types that go together (validateQuery). A
|
|
63
|
+
* value only some branches have is a typed NULL in the others: a NULL
|
|
64
|
+
* literal with `as` (sqlGen writes it as that type). `all: true` keeps
|
|
65
|
+
* every row (`UNION ALL`); `false` merges rows that are the same in every
|
|
66
|
+
* column (`UNION`, issue 153) — never for detail rows a grid sums, where
|
|
67
|
+
* two equal rows are two records. */
|
|
68
|
+
export interface UnionQuery {
|
|
69
|
+
union: DerivedQuery[];
|
|
70
|
+
all: boolean;
|
|
71
|
+
}
|
|
72
|
+
/** What a derived table's query can be: one query, or a stack of them. */
|
|
73
|
+
export type NestedQuery = DerivedQuery | UnionQuery;
|
|
74
|
+
export declare function isUnion(query: NestedQuery): query is UnionQuery;
|
|
75
|
+
/** A derived table's queries: a union's branches, else the one. */
|
|
76
|
+
export declare function branchesOf(query: NestedQuery): DerivedQuery[];
|
|
77
|
+
/** The query whose columns a derived table has: a union's first branch
|
|
78
|
+
* (its names are the union's), else the one. */
|
|
79
|
+
export declare function firstBranch(query: NestedQuery): DerivedQuery;
|
|
80
|
+
/** `query` with `branch` applied to each of its queries (see branchesOf),
|
|
81
|
+
* with its place — the same object when that changes none. */
|
|
82
|
+
export declare function mapBranches(query: NestedQuery, branch: (q: DerivedQuery, index: number) => DerivedQuery): NestedQuery;
|
|
83
|
+
/** `query` with each of its shared queries' (issue 194) query as `update`
|
|
84
|
+
* makes it — the same object when that changes none. */
|
|
85
|
+
export declare function mapSharedQueries<Q extends {
|
|
86
|
+
shared?: SharedQuery[];
|
|
87
|
+
}>(query: Q, update: (nested: NestedQuery, shared: SharedQuery) => NestedQuery): Q;
|
|
88
|
+
/** What a query is made of, a derived table's or the whole query's (which
|
|
89
|
+
* adds an id, ORDER BY, LIMIT and OFFSET). */
|
|
90
|
+
export type QueryBody = DerivedQuery & {
|
|
91
|
+
orderBy?: OrderByItem[];
|
|
92
|
+
};
|
|
93
|
+
/** On a derived table Add measure made (see docs/design/drill-across.md):
|
|
94
|
+
* whether it follows the query's GROUP BY and WHERE (`synced`), and how
|
|
95
|
+
* many of its WHERE's leading AND operands are filters copied from the
|
|
96
|
+
* query's (`copied`). */
|
|
97
|
+
export interface DrillAcross {
|
|
98
|
+
synced: boolean;
|
|
99
|
+
copied: number;
|
|
100
|
+
}
|
|
101
|
+
/** A join of a derived table: `query`, named `alias` (its fields name it
|
|
102
|
+
* by that). */
|
|
103
|
+
export interface DerivedJoin extends JoinBase {
|
|
104
|
+
table?: undefined;
|
|
105
|
+
shared?: undefined;
|
|
106
|
+
query: NestedQuery;
|
|
107
|
+
alias: string;
|
|
108
|
+
drillAcross?: DrillAcross;
|
|
109
|
+
}
|
|
110
|
+
/** A join of a shared query (issue 194), by its id, named `alias`. */
|
|
111
|
+
export interface SharedJoin extends JoinBase {
|
|
112
|
+
shared: string;
|
|
113
|
+
alias: string;
|
|
114
|
+
table?: undefined;
|
|
115
|
+
query?: undefined;
|
|
116
|
+
}
|
|
117
|
+
export type JoinClause = TableJoin | DerivedJoin | SharedJoin;
|
|
118
|
+
/** A query named once at the top of the whole query (`WITH name AS (…)`,
|
|
119
|
+
* issue 194, docs/design/shared-queries.md), used like a table anywhere in
|
|
120
|
+
* it — the base, a join, inside a sub query or an EXISTS — by its id.
|
|
121
|
+
* `id` is also its QueryPath step. */
|
|
122
|
+
export interface SharedQuery {
|
|
123
|
+
id: string;
|
|
124
|
+
name: string;
|
|
125
|
+
query: NestedQuery;
|
|
126
|
+
}
|
|
127
|
+
export interface SelectItem {
|
|
128
|
+
id: string;
|
|
129
|
+
expression: ExpressionNode;
|
|
130
|
+
alias?: string;
|
|
131
|
+
}
|
|
132
|
+
export type SortDirection = 'asc' | 'desc';
|
|
133
|
+
export interface OrderByItem {
|
|
134
|
+
id: string;
|
|
135
|
+
expression: ExpressionNode;
|
|
136
|
+
direction: SortDirection;
|
|
137
|
+
}
|
|
138
|
+
export interface GroupByItem {
|
|
139
|
+
id: string;
|
|
140
|
+
expression: ExpressionNode;
|
|
141
|
+
/** A key added automatically for the SELECT column with this id (see
|
|
142
|
+
* grouping.ts's groupAutomatically): it follows that column, and goes
|
|
143
|
+
* with it. Absent on a key the user added. */
|
|
144
|
+
fromSelect?: string;
|
|
145
|
+
}
|
|
146
|
+
export interface QueryPipeline {
|
|
147
|
+
id: string;
|
|
148
|
+
from: FromClause;
|
|
149
|
+
joins: JoinClause[];
|
|
150
|
+
where?: ExpressionNode;
|
|
151
|
+
select: SelectItem[];
|
|
152
|
+
/** GROUP BY: one result row per distinct combination of these. */
|
|
153
|
+
groupBy?: GroupByItem[];
|
|
154
|
+
/** HAVING: a condition on each group (aggregates allowed). */
|
|
155
|
+
having?: ExpressionNode;
|
|
156
|
+
/** SELECT DISTINCT. */
|
|
157
|
+
distinct?: boolean;
|
|
158
|
+
/** ORDER BY, in priority order. */
|
|
159
|
+
orderBy?: OrderByItem[];
|
|
160
|
+
/** At most this many rows (a non-negative integer). */
|
|
161
|
+
limit?: number;
|
|
162
|
+
/** Shared queries (WITH, issue 194), in order: each may use those before
|
|
163
|
+
* it, never itself or a later one. Only on the whole query. */
|
|
164
|
+
shared?: SharedQuery[];
|
|
165
|
+
/** Skip this many rows first (a non-negative integer). */
|
|
166
|
+
offset?: number;
|
|
167
|
+
}
|
|
168
|
+
/** Type guard distinguishing a QueryPipeline root from a bare ExpressionNode root —
|
|
169
|
+
* used at the absolutePath.ts boundary where a resolved value could be either. */
|
|
170
|
+
export declare function isQueryPipeline(root: QueryPipeline | ExpressionNode | undefined): root is QueryPipeline;
|
|
171
|
+
/** A query whose base table hasn't been chosen yet — still a query with its
|
|
172
|
+
* own identity (a user who removes the last table, or undoes back past
|
|
173
|
+
* choosing one, is still editing the same query), just nothing in it yet. */
|
|
174
|
+
export interface EmptyQuery {
|
|
175
|
+
id: string;
|
|
176
|
+
/** Shared queries kept while there's no table (issue 194): the base
|
|
177
|
+
* removed, or one to be used as the base. */
|
|
178
|
+
shared?: SharedQuery[];
|
|
179
|
+
}
|
|
180
|
+
/** What PipelineEditor's value/defaultValue/onChange carry: a query that
|
|
181
|
+
* either has a base table (QueryPipeline) or doesn't yet (EmptyQuery). */
|
|
182
|
+
export type QueryValue = QueryPipeline | EmptyQuery;
|
|
183
|
+
/** True once a base table has been chosen. */
|
|
184
|
+
export declare function hasBaseTable(query: QueryValue): query is QueryPipeline;
|
|
185
|
+
/** The longest name (an alias) every dialect takes as it is: PostgreSQL
|
|
186
|
+
* cuts longer ones to 63 characters without a word (so two could become
|
|
187
|
+
* one), MySQL takes 64, SQL Server 128. */
|
|
188
|
+
export declare const MAX_NAME_LENGTH = 63;
|
|
189
|
+
/** The name fields use for a table of a query: its alias, else its table's
|
|
190
|
+
* name. (A derived table has no table name: it goes by its alias.) */
|
|
191
|
+
export declare function tableRef(t: FromClause | JoinClause): string;
|
|
192
|
+
/** The name a derived table's SELECT item goes by outside it: its alias,
|
|
193
|
+
* else its field's column. Undefined for an unnamed expression (an error:
|
|
194
|
+
* nothing outside could name it). */
|
|
195
|
+
export declare function derivedColumnName(item: SelectItem): string | undefined;
|
|
196
|
+
/** A query's tables in order, its base first: FROM's, then each join's. */
|
|
197
|
+
export declare function queryTables(query: Pick<DerivedQuery, 'from' | 'joins'>): (FromClause | JoinClause)[];
|
|
198
|
+
/** The names of the schema's tables a query names (its base and table
|
|
199
|
+
* joins — not its derived tables, which aren't the schema's). */
|
|
200
|
+
export declare function queryTableNames(query: Pick<DerivedQuery, 'from' | 'joins'>): string[];
|
|
201
|
+
export {};
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import type { BinaryNode, BinaryOperator, ExistsNode, ExpressionNode, FieldNode, FunctionCallNode, LiteralNode, ListNode, LiteralValue, LogicalNode, LogicalOperator, NotNode, ParamNode, RelativeDate, SubqueryNode } from './ast.js';
|
|
2
|
+
import { type DerivedQuery, type JoinClause, type TableFrom, type JoinType, type QueryPipeline, type QueryValue, type SortDirection } from './queryAst.js';
|
|
3
|
+
import type { DatabaseSchema } from './schema.js';
|
|
4
|
+
export declare const expr: {
|
|
5
|
+
/** A column: `expr.field('orders', 'status')`. */
|
|
6
|
+
field: (table: string, column: string) => FieldNode;
|
|
7
|
+
/** A literal value, written into the SQL (as a bound parameter by
|
|
8
|
+
* astToParameterizedSql). `''` is marked as the empty text (see
|
|
9
|
+
* LiteralNode's `empty`), since code means it. */
|
|
10
|
+
value: (value: LiteralValue) => LiteralNode;
|
|
11
|
+
/** A named value the application supplies when generating the SQL
|
|
12
|
+
* (astToParameterizedSql's `values`). With `relative`, a date relative
|
|
13
|
+
* to when the query runs, which the application computes (issue 140):
|
|
14
|
+
* `expr.param('sale_from', { relative: { unit: 'day', offset: -30 } })`. */
|
|
15
|
+
param: (name: string, options?: {
|
|
16
|
+
relative?: RelativeDate;
|
|
17
|
+
}) => ParamNode;
|
|
18
|
+
/** `left <operator> right`. */
|
|
19
|
+
compare: (left: ExpressionNode, operator: BinaryOperator, right: ExpressionNode) => BinaryNode;
|
|
20
|
+
/** `operand IS NULL`. */
|
|
21
|
+
isNull: (operand: ExpressionNode) => BinaryNode;
|
|
22
|
+
/** `operand IS NOT NULL`. */
|
|
23
|
+
isNotNull: (operand: ExpressionNode) => BinaryNode;
|
|
24
|
+
/** `left = right`. */
|
|
25
|
+
eq: (left: ExpressionNode, right: ExpressionNode) => BinaryNode;
|
|
26
|
+
and: (...operands: ExpressionNode[]) => LogicalNode;
|
|
27
|
+
or: (...operands: ExpressionNode[]) => LogicalNode;
|
|
28
|
+
not: (operand: ExpressionNode) => NotNode;
|
|
29
|
+
/** A function call: `expr.fn('LOWER', expr.field('users', 'email'))`. */
|
|
30
|
+
fn: (name: string, ...args: ExpressionNode[]) => FunctionCallNode;
|
|
31
|
+
/** Whether the outer row has related rows: `EXISTS (SELECT 1 FROM …
|
|
32
|
+
* WHERE <link> AND <where>)`. `link` matches them to the outer row;
|
|
33
|
+
* `where` names the subquery's own tables only. NOT EXISTS:
|
|
34
|
+
* `expr.not(expr.exists(…))`. */
|
|
35
|
+
exists: (query: {
|
|
36
|
+
from: TableFrom;
|
|
37
|
+
joins?: JoinClause[];
|
|
38
|
+
where?: ExpressionNode;
|
|
39
|
+
}, link: ExpressionNode) => ExistsNode;
|
|
40
|
+
/** `left IN (…)`: the values (`[1, 2, 3]`, or a list of expressions
|
|
41
|
+
* such as params: `expr.list(…)`), or a sub query (`expr.subquery`).
|
|
42
|
+
* NOT IN: `expr.not(expr.in(…))`. */
|
|
43
|
+
in: (left: ExpressionNode, right: ListNode | SubqueryNode | readonly LiteralValue[]) => BinaryNode;
|
|
44
|
+
/** `left BETWEEN low AND high` (issue 169), both bounds included: each a
|
|
45
|
+
* value or an expression (a param, a relative date). NOT BETWEEN:
|
|
46
|
+
* `expr.not(expr.between(…))`. */
|
|
47
|
+
between: (left: ExpressionNode, low: LiteralValue | ExpressionNode, high: LiteralValue | ExpressionNode) => BinaryNode;
|
|
48
|
+
/** IN's values: each a value (`expr.list(1, 2)`) or an expression
|
|
49
|
+
* (`expr.list(expr.param('a'), expr.param('b'))`). */
|
|
50
|
+
list: (...items: (LiteralValue | ExpressionNode)[]) => ListNode;
|
|
51
|
+
/** A query of its own for IN to compare with, selecting `select` — one
|
|
52
|
+
* column. Its tables are its own: it sees nothing of the query around
|
|
53
|
+
* it. `expr.in(expr.field('customer', 'id'), expr.subquery({ from: {
|
|
54
|
+
* table: 'sale_transaction' }, select: expr.field('sale_transaction',
|
|
55
|
+
* 'customer_id') }))`. */
|
|
56
|
+
subquery: ({ select, ...query }: Omit<DerivedQuery, "joins" | "select"> & {
|
|
57
|
+
joins?: JoinClause[];
|
|
58
|
+
select: ExpressionNode;
|
|
59
|
+
}) => SubqueryNode;
|
|
60
|
+
};
|
|
61
|
+
/** Sets (or replaces) the query's base table. On an empty query this is
|
|
62
|
+
* what gives it one. */
|
|
63
|
+
export declare function setBaseTable(schema: DatabaseSchema, query: QueryValue, table: string): QueryPipeline;
|
|
64
|
+
/** Joins `table`. Without options it's what the editor's "+ Add Table"
|
|
65
|
+
* does: the join condition suggested from the schema's relations, and any
|
|
66
|
+
* intermediate tables needed to reach it joined first. With `joinType` or
|
|
67
|
+
* `on`, exactly that one join. */
|
|
68
|
+
export declare function addJoin(schema: DatabaseSchema, query: QueryPipeline, table: string, options?: {
|
|
69
|
+
joinType?: JoinType;
|
|
70
|
+
on?: ExpressionNode;
|
|
71
|
+
}): QueryPipeline;
|
|
72
|
+
/** Removes a join (by its id). */
|
|
73
|
+
export declare function removeJoin(schema: DatabaseSchema, query: QueryPipeline, joinId: string): QueryPipeline;
|
|
74
|
+
/** Adds `condition` to WHERE: combined with what's there by `operator`
|
|
75
|
+
* (default AND) — appended when WHERE already is a group of that operator,
|
|
76
|
+
* otherwise WHERE and the condition become one, so the whole existing
|
|
77
|
+
* condition stays together (`(a OR b) AND condition`). Tables the condition
|
|
78
|
+
* refers to that the query doesn't have yet are joined, as in the editor.
|
|
79
|
+
*
|
|
80
|
+
* On a query reading a union of tables (addUnionTable, issue 121), a
|
|
81
|
+
* condition naming tables goes into **every** branch, each joining what it
|
|
82
|
+
* needs — so a backend scoping every query (a tenant, a facility) scopes
|
|
83
|
+
* every table's rows. It throws, changing nothing, when a branch can't
|
|
84
|
+
* reach a table it names: a branch it skipped would leak rows. A condition
|
|
85
|
+
* naming the union itself (its alias) is the query's own. */
|
|
86
|
+
export declare function addCondition(schema: DatabaseSchema, query: QueryPipeline, condition: ExpressionNode, options?: {
|
|
87
|
+
operator?: LogicalOperator;
|
|
88
|
+
}): QueryPipeline;
|
|
89
|
+
/** Adds a SELECT column. Tables it refers to that the query doesn't have
|
|
90
|
+
* yet are joined, as in the editor. */
|
|
91
|
+
export declare function addSelectItem(schema: DatabaseSchema, query: QueryPipeline, expression: ExpressionNode, alias?: string): QueryPipeline;
|
|
92
|
+
/** Adds a GROUP BY key (after any existing ones). Tables it refers to that
|
|
93
|
+
* the query doesn't have yet are joined, as in the editor. */
|
|
94
|
+
export declare function addGroupBy(schema: DatabaseSchema, query: QueryPipeline, expression: ExpressionNode): QueryPipeline;
|
|
95
|
+
/** Sets (or, with undefined, removes) the HAVING condition — a condition on
|
|
96
|
+
* each group: `setHaving(schema, query, expr.compare(expr.fn('COUNT'), '>',
|
|
97
|
+
* expr.value(5)))`. Tables it refers to are joined, as in the editor. */
|
|
98
|
+
export declare function setHaving(schema: DatabaseSchema, query: QueryPipeline, condition: ExpressionNode | undefined): QueryPipeline;
|
|
99
|
+
/** Adds an ORDER BY key (after any existing ones). Tables it refers to that
|
|
100
|
+
* the query doesn't have yet are joined, as in the editor. */
|
|
101
|
+
export declare function addOrderBy(schema: DatabaseSchema, query: QueryPipeline, expression: ExpressionNode, direction?: SortDirection): QueryPipeline;
|
|
102
|
+
/** Sets LIMIT and/or OFFSET — whichever keys `paging` has; undefined
|
|
103
|
+
* clears one. Only non-negative integers are kept:
|
|
104
|
+
* `setPaging(schema, query, { limit: 50, offset: 100 })`. */
|
|
105
|
+
export declare function setPaging(schema: DatabaseSchema, query: QueryPipeline, paging: {
|
|
106
|
+
limit?: number;
|
|
107
|
+
offset?: number;
|
|
108
|
+
}): QueryPipeline;
|
|
109
|
+
/** SELECT DISTINCT on or off. */
|
|
110
|
+
export declare function setDistinct(schema: DatabaseSchema, query: QueryPipeline, distinct: boolean): QueryPipeline;
|
|
111
|
+
/** `query` as a QueryPipeline, or an error when it has no base table yet —
|
|
112
|
+
* for code that only handles complete queries. */
|
|
113
|
+
export declare function requireBaseTable(query: QueryValue): QueryPipeline;
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
import { type FunctionRegistry } from './functionRegistry.js';
|
|
2
|
+
import type { SqlDialect } from './sqlGen.js';
|
|
3
|
+
import { type DatabaseSchema, type Table, type TableColumn } from './schema.js';
|
|
4
|
+
/** Every kind of issue validateQuery reports. Kinds are public API: an
|
|
5
|
+
* application maps them to its own error codes, so renaming or removing
|
|
6
|
+
* one is a breaking change (a major version), and adding one is a minor
|
|
7
|
+
* version. Their meaning doesn't change silently either. */
|
|
8
|
+
export type QueryIssueKind =
|
|
9
|
+
/** Not a well-formed query: a missing or mistyped field, an unknown node
|
|
10
|
+
* type, operator or join type. */
|
|
11
|
+
'invalidStructure'
|
|
12
|
+
/** Two joins, or two SELECT columns, share an id. */
|
|
13
|
+
| 'duplicateId'
|
|
14
|
+
/** A table that isn't in the schema, or that the filters hide. The two
|
|
15
|
+
* are deliberately not told apart: a caller shouldn't learn from the
|
|
16
|
+
* answer that a hidden table exists. */
|
|
17
|
+
| 'unknownTable'
|
|
18
|
+
/** A column that isn't in its table, or that the filters hide (same
|
|
19
|
+
* reasoning as unknownTable). */
|
|
20
|
+
| 'unknownColumn'
|
|
21
|
+
/** A field naming a table that isn't in the query's FROM/JOINs — or one
|
|
22
|
+
* that is, but under an alias, which is then its only name in SQL. */
|
|
23
|
+
| 'tableNotInQuery'
|
|
24
|
+
/** A field with no table — it can't be checked against the schema. */
|
|
25
|
+
| 'unqualifiedField'
|
|
26
|
+
/** Something not filled in yet: a field with no column picked, a
|
|
27
|
+
* comparison with no right side, a value left blank (`''` not marked as
|
|
28
|
+
* the empty text, see LiteralNode's `empty`), a comparison with NULL
|
|
29
|
+
* (never true: IS NULL is meant), a join with no ON condition, an empty
|
|
30
|
+
* AND/OR group or CASE, an IF without its condition or THEN, a function
|
|
31
|
+
* call missing an argument its signature requires. */
|
|
32
|
+
| 'incomplete'
|
|
33
|
+
/** A function call with more arguments than its signature takes. */
|
|
34
|
+
| 'argCount'
|
|
35
|
+
/** Inside an EXISTS, a table named like one of the query around it,
|
|
36
|
+
* without an alias to tell them apart. */
|
|
37
|
+
| 'ambiguousTable'
|
|
38
|
+
/** Two tables of one query (the whole one, a derived table's, an
|
|
39
|
+
* EXISTS's) going by the same name — a table joined twice without an
|
|
40
|
+
* alias, an alias used twice. Every database rejects it. */
|
|
41
|
+
| 'duplicateTableName'
|
|
42
|
+
/** A derived table's column with no name outside it (an expression
|
|
43
|
+
* with no alias), or two of its columns with the same name. */
|
|
44
|
+
| 'derivedColumnName'
|
|
45
|
+
/** A function that isn't in the allowed registry. */
|
|
46
|
+
| 'unknownFunction'
|
|
47
|
+
/** A join's ON condition uses a table only joined after it. */
|
|
48
|
+
| 'joinOrder'
|
|
49
|
+
/** With DISTINCT, a sort key that isn't one of the selected columns —
|
|
50
|
+
* every database rejects it (see sortKeysOutsideDistinct). */
|
|
51
|
+
| 'distinctSort'
|
|
52
|
+
/** In a grouped query, a column (in SELECT, ORDER BY or HAVING) that
|
|
53
|
+
* isn't a group key or inside an aggregate, or SELECT * (see
|
|
54
|
+
* groupingProblems). */
|
|
55
|
+
| 'notGrouped'
|
|
56
|
+
/** A warning, with allowUnknownFunctions: in a grouped query, a column
|
|
57
|
+
* (in SELECT, ORDER BY or HAVING) calling a function the registry
|
|
58
|
+
* doesn't know (issue 137). It may be an aggregate, so it isn't made a
|
|
59
|
+
* group key; if it isn't one, the database rejects the query. Add it to
|
|
60
|
+
* `functions`, with `aggregate: true` if it sums rows up. */
|
|
61
|
+
| 'unknownAggregate'
|
|
62
|
+
/** An aggregate where SQL doesn't allow one: WHERE, JOIN ON, GROUP BY. */
|
|
63
|
+
| 'misplacedAggregate'
|
|
64
|
+
/** A param compared against columns of different types (`:x` against a
|
|
65
|
+
* date and a number) — no one value suits both. */
|
|
66
|
+
| 'paramConflict'
|
|
67
|
+
/** A warning: a SUM, AVG or COUNT over a column of a table whose rows a
|
|
68
|
+
* join repeats (joined to the many side of a relation) — it comes out
|
|
69
|
+
* too high (see fanOut). */
|
|
70
|
+
| 'fanOut'
|
|
71
|
+
/** A warning: a CROSS JOIN of more than one row (anything but a derived
|
|
72
|
+
* table summing up all its rows) — every row meets every row, so they
|
|
73
|
+
* multiply. */
|
|
74
|
+
| 'crossJoin'
|
|
75
|
+
/** A warning: a join (not CROSS) whose ON doesn't compare it with a
|
|
76
|
+
* table joined before it — it names only itself, or only the others —
|
|
77
|
+
* so every row meets every row it lets through, as in a CROSS JOIN. */
|
|
78
|
+
| 'unlinkedJoin'
|
|
79
|
+
/** A measure kept in step with the report (`drillAcross.synced`) that
|
|
80
|
+
* doesn't match it: the report's grain is one its fact can't follow (no
|
|
81
|
+
* GROUP BY, a key on a table it doesn't share), or the query was edited
|
|
82
|
+
* without keepMeasuresInStep. Uncheck "Keep in step", or change the
|
|
83
|
+
* grouping back. */
|
|
84
|
+
| 'drillAcrossOutOfStep'
|
|
85
|
+
/** A warning: a measure kept in step whose report filters by a condition
|
|
86
|
+
* naming both tables its fact shares and ones it doesn't (an OR across
|
|
87
|
+
* them) — not copied, so the measure isn't filtered by it. */
|
|
88
|
+
| 'drillAcrossFilterMixed'
|
|
89
|
+
/** Longer than it can be (issue 129, see limits.ts): a name (an alias, a
|
|
90
|
+
* parameter's, a function's) past MAX_NAME_LENGTH, a text value past
|
|
91
|
+
* MAX_TEXT_LENGTH, a CAST type past MAX_TYPE_NAME_LENGTH — or a number
|
|
92
|
+
* with more significant digits than MAX_NUMBER_DIGITS (it would be
|
|
93
|
+
* written as another number), a LIMIT/OFFSET past what's exact. */
|
|
94
|
+
| 'tooLong'
|
|
95
|
+
/** Something the `dialect` option's database doesn't have: REGEXP on
|
|
96
|
+
* SQL Server, which the SQL functions refuse to write (issue 130). */
|
|
97
|
+
| 'dialectUnsupported'
|
|
98
|
+
/** A sub query after IN (issue 122) selecting no column, or more than
|
|
99
|
+
* one: IN compares with one. */
|
|
100
|
+
| 'subqueryColumns'
|
|
101
|
+
/** A warning: NOT IN a sub query — a single NULL in the sub query's
|
|
102
|
+
* column makes it keep no rows at all, in every database (NOT EXISTS
|
|
103
|
+
* doesn't). Always warned: a column the schema calls non-null can still
|
|
104
|
+
* come out NULL (an outer join, an expression). */
|
|
105
|
+
| 'notInSubquery'
|
|
106
|
+
/** A warning, with the requireLimit option: no LIMIT — the query reads
|
|
107
|
+
* every row. */
|
|
108
|
+
| 'noLimit'
|
|
109
|
+
/** A warning, with requireLimit's `max`: a LIMIT above it. */
|
|
110
|
+
| 'limitTooHigh'
|
|
111
|
+
/** A union's branch (issue 121) whose columns aren't the first branch's:
|
|
112
|
+
* as many, by the same names, in order — or picked as SELECT *, which
|
|
113
|
+
* can't be lined up. */
|
|
114
|
+
| 'unionColumns'
|
|
115
|
+
/** A union's column whose branches give types that don't go together
|
|
116
|
+
* (a date in one, a number in another). NULL goes with any; a typed
|
|
117
|
+
* NULL (`as`) by its type. */
|
|
118
|
+
| 'unionTypes'
|
|
119
|
+
/** A warning by default (ValidateQueryOptions' `typeMismatch` makes it
|
|
120
|
+
* an error), issue 130: values of types that don't go together — a
|
|
121
|
+
* value that doesn't read as the type of what it's compared with (`'abc'`
|
|
122
|
+
* against a whole number), a column compared with a column of another
|
|
123
|
+
* type, LIKE or REGEXP on what isn't text, IN's values against its left
|
|
124
|
+
* side, IF/CASE's branches. The database may convert, or fail. Numbers
|
|
125
|
+
* go with numbers, a date with a date and time. */
|
|
126
|
+
| 'typeMismatch'
|
|
127
|
+
/** A REGEXP pattern that isn't a regular expression (read as JavaScript
|
|
128
|
+
* reads one: the databases' own syntax is close, not the same). */
|
|
129
|
+
| 'invalidPattern'
|
|
130
|
+
/** A place using a shared query (issue 194) that comes after it in
|
|
131
|
+
* `shared` — or is itself: a shared query uses only those before it. */
|
|
132
|
+
| 'sharedOrder'
|
|
133
|
+
/** A warning: a shared query used nowhere. It changes no row. */
|
|
134
|
+
| 'unusedShared';
|
|
135
|
+
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"];
|
|
136
|
+
/** The kinds that are warnings: the query can run with them. Only these
|
|
137
|
+
* can be hidden (ValidateQueryOptions' hideWarnings). */
|
|
138
|
+
export declare const QUERY_WARNING_KINDS: readonly ["fanOut", "crossJoin", "unlinkedJoin", "drillAcrossFilterMixed", "notInSubquery", "noLimit", "limitTooHigh", "typeMismatch", "unknownAggregate", "unusedShared"];
|
|
139
|
+
export type QueryWarningKind = typeof QUERY_WARNING_KINDS[number];
|
|
140
|
+
/** An error makes the SQL wrong or unsafe — don't run it. A warning is
|
|
141
|
+
* worth telling the user about, but the query can run. */
|
|
142
|
+
export type QueryIssueSeverity = 'error' | 'warning';
|
|
143
|
+
export interface QueryIssue {
|
|
144
|
+
kind: QueryIssueKind;
|
|
145
|
+
severity: QueryIssueSeverity;
|
|
146
|
+
/** Where, as a path into the query, e.g. `joins[0].on.left` (empty for
|
|
147
|
+
* the query as a whole). */
|
|
148
|
+
path: string;
|
|
149
|
+
/** The same path as segments — `['joins', 0, 'on', 'left']` — ready to
|
|
150
|
+
* use as a JSON path. */
|
|
151
|
+
pathSegments: (string | number)[];
|
|
152
|
+
message: string;
|
|
153
|
+
}
|
|
154
|
+
export interface ValidateQueryOptions {
|
|
155
|
+
/** The same visibility filters the editor was given for this user
|
|
156
|
+
* (PipelineEditor's tableFilter/columnFilter): anything they hide counts
|
|
157
|
+
* as unknown. */
|
|
158
|
+
tableFilter?: (table: Table) => boolean;
|
|
159
|
+
columnFilter?: (table: Table, column: TableColumn) => boolean;
|
|
160
|
+
/** The functions allowed (default DEFAULT_FUNCTIONS) — normally the same
|
|
161
|
+
* registry the editor was given. */
|
|
162
|
+
functions?: FunctionRegistry;
|
|
163
|
+
/** Allow function names that aren't in `functions`. The editor lets users
|
|
164
|
+
* type any function name, but a query from outside could then call
|
|
165
|
+
* anything the database offers — off by default. */
|
|
166
|
+
allowUnknownFunctions?: boolean;
|
|
167
|
+
/** Warn about a query that reads every row: `true` for one with no
|
|
168
|
+
* LIMIT (noLimit), `{ max }` also for a LIMIT above `max`
|
|
169
|
+
* (limitTooHigh). Off by default — some queries mean to read all. A
|
|
170
|
+
* query that sums the whole table into one row (an aggregate, no GROUP
|
|
171
|
+
* BY) needs none. To add one instead, see the SQL functions'
|
|
172
|
+
* `defaultLimit`. */
|
|
173
|
+
requireLimit?: boolean | {
|
|
174
|
+
max?: number;
|
|
175
|
+
};
|
|
176
|
+
/** Warnings not to report, by kind — e.g. ['crossJoin'] for an app whose
|
|
177
|
+
* reports CROSS JOIN on purpose. Errors are always reported. */
|
|
178
|
+
hideWarnings?: readonly QueryWarningKind[];
|
|
179
|
+
/** The database the query is for: what it doesn't have is reported
|
|
180
|
+
* (`dialectUnsupported`) — the SQL functions would refuse it. */
|
|
181
|
+
dialect?: SqlDialect;
|
|
182
|
+
/** How values of types that don't go together are reported
|
|
183
|
+
* (`typeMismatch`): a warning (the default) — the database may convert
|
|
184
|
+
* them — or an error, for an application that wants types kept. */
|
|
185
|
+
typeMismatch?: QueryIssueSeverity;
|
|
186
|
+
}
|
|
187
|
+
/** Checks a query — typically one that came from a client or from storage,
|
|
188
|
+
* so untrusted — before it's turned into SQL and run. Returns every issue
|
|
189
|
+
* found; an empty list means it's safe to hand to astToParameterizedSql.
|
|
190
|
+
*
|
|
191
|
+
* - Structure: the shape of every part, node types, operators, join types,
|
|
192
|
+
* ids present and unique.
|
|
193
|
+
* - References: every table and column (FROM, JOINs, and fields anywhere
|
|
194
|
+
* in WHERE/ON/SELECT) exists in `schema` and passes the filters; every
|
|
195
|
+
* field names a table that's in the query.
|
|
196
|
+
* - Functions: only ones in the registry, unless allowUnknownFunctions.
|
|
197
|
+
* - Join order: each ON condition only uses tables joined before it.
|
|
198
|
+
* - DISTINCT: every sort key is one of the selected columns.
|
|
199
|
+
* - Grouping: aggregates only in SELECT, HAVING and ORDER BY; in a grouped
|
|
200
|
+
* query, everything those return is a group key or an aggregate.
|
|
201
|
+
* - Params: each one compared against columns of one type only.
|
|
202
|
+
* - Fan-out (a warning): a sum, average or count over rows a join repeats.
|
|
203
|
+
* - With requireLimit (warnings): no LIMIT, or one above its `max`.
|
|
204
|
+
*
|
|
205
|
+
* An EmptyQuery (`{ id }`, no base table yet) is valid. */
|
|
206
|
+
export declare function validateQuery(schema: DatabaseSchema, query: unknown, options?: ValidateQueryOptions): QueryIssue[];
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { RelativeDate } from './ast.js';
|
|
2
|
+
/** The words for `relative`, as the editor shows it ("30 days ago", "Start
|
|
3
|
+
* of last week") — for an application's own screens, in the editor's
|
|
4
|
+
* messages (`messages`, default English). */
|
|
5
|
+
export declare function relativeDateLabel(relative: RelativeDate, messages?: {
|
|
6
|
+
relativeDate: (relative: RelativeDate) => string;
|
|
7
|
+
}): string;
|
|
8
|
+
/** The param name the editor gives a relative date: from what it means, so
|
|
9
|
+
* the same date is the same param (one value) wherever it's used, and a
|
|
10
|
+
* plain identifier — `today`, `day_minus_30`, `month_minus_1_start`. */
|
|
11
|
+
export declare function relativeParamName({ unit, offset, anchor }: RelativeDate): string;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { type QueryPipeline } from './queryAst.js';
|
|
2
|
+
/** Maps a table name — or, given a column too, that column's name — as the
|
|
3
|
+
* query has it (as the editor's schema calls it) to the name to write in
|
|
4
|
+
* the SQL. */
|
|
5
|
+
export type ResolveName = (table: string, column?: string) => string;
|
|
6
|
+
/** `query` with its tables and columns renamed by `resolve` — for a schema
|
|
7
|
+
* given to the editor in logical names (so saved queries outlive a database
|
|
8
|
+
* rename) that the database calls something else. Aliases stay as they
|
|
9
|
+
* are; a field naming one gets its column resolved against the aliased
|
|
10
|
+
* table. A field with no table can't be resolved and is left alone. The
|
|
11
|
+
* same goes inside an EXISTS, against its own tables, and inside a derived
|
|
12
|
+
* table, against its own; a field naming a derived table is left as it is
|
|
13
|
+
* (its columns are the derived table's SELECT aliases). A table renamed
|
|
14
|
+
* that has no alias is aliased by its own name in the query (issue 190):
|
|
15
|
+
* `dim_date AS pay_date`, its fields `pay_date.full_date` — so two tables
|
|
16
|
+
* of the query that are one in the database can both be joined. */
|
|
17
|
+
export default function resolveNames(query: QueryPipeline, resolve: ResolveName): QueryPipeline;
|