@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.
Files changed (186) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +916 -2
  3. package/dist/PipelineEditor-DNZkDSaY.js +10042 -0
  4. package/dist/calendarDate-CYlr9TvX.js +43 -0
  5. package/dist/core-api-BDCnbFHY.js +1056 -0
  6. package/dist/core.js +80 -0
  7. package/dist/fixtures.js +7 -0
  8. package/dist/index.js +145 -0
  9. package/dist/issueLocation-Cw5sttQL.js +3183 -0
  10. package/dist/mui-date-pickers.js +117 -0
  11. package/dist/mui.js +510 -0
  12. package/dist/schema-z95dxLxu.js +839 -0
  13. package/dist/sql-import.js +1366 -0
  14. package/dist/style.css +1 -0
  15. package/dist/tokens-BTaVMSOx.js +95 -0
  16. package/dist/types/adapters/mui/MuiDatePicker.d.ts +12 -0
  17. package/dist/types/adapters/mui/MuiDateTimePicker.d.ts +10 -0
  18. package/dist/types/adapters/mui/MuiListInput.d.ts +9 -0
  19. package/dist/types/adapters/mui/MuiTimePicker.d.ts +10 -0
  20. package/dist/types/adapters/mui/QueryBuilder.d.ts +12 -0
  21. package/dist/types/adapters/mui/components.d.ts +16 -0
  22. package/dist/types/adapters/mui/index.d.ts +6 -0
  23. package/dist/types/adapters/mui/muiPickers.d.ts +6 -0
  24. package/dist/types/adapters/mui/pickerStyles.d.ts +28 -0
  25. package/dist/types/adapters/mui/theme.d.ts +11 -0
  26. package/dist/types/core/BetweenOnTextContext.d.ts +11 -0
  27. package/dist/types/core/DialectContext.d.ts +10 -0
  28. package/dist/types/core/DrillDownContext.d.ts +22 -0
  29. package/dist/types/core/ExistsContext.d.ts +29 -0
  30. package/dist/types/core/FlowDirectionContext.d.ts +8 -0
  31. package/dist/types/core/FlowOrientationContext.d.ts +6 -0
  32. package/dist/types/core/FunctionsContext.d.ts +25 -0
  33. package/dist/types/core/GroupKeysContext.d.ts +18 -0
  34. package/dist/types/core/MeasureLockContext.d.ts +12 -0
  35. package/dist/types/core/ReadOnlyContext.d.ts +6 -0
  36. package/dist/types/core/SchemaContext.d.ts +8 -0
  37. package/dist/types/core/SubqueryContext.d.ts +16 -0
  38. package/dist/types/core/UnionBranchContext.d.ts +6 -0
  39. package/dist/types/core/ValueInputContext.d.ts +24 -0
  40. package/dist/types/core/absolutePath.d.ts +57 -0
  41. package/dist/types/core/ast.d.ts +154 -0
  42. package/dist/types/core/astChildren.d.ts +4 -0
  43. package/dist/types/core/astEqual.d.ts +4 -0
  44. package/dist/types/core/astMap.d.ts +21 -0
  45. package/dist/types/core/calendarDate.d.ts +21 -0
  46. package/dist/types/core/columnFormats.d.ts +23 -0
  47. package/dist/types/core/components/BoolPicker.d.ts +8 -0
  48. package/dist/types/core/components/NumberInput.d.ts +8 -0
  49. package/dist/types/core/components/ReadOnlyPart.d.ts +10 -0
  50. package/dist/types/core/components/TextInput.d.ts +8 -0
  51. package/dist/types/core/components/expression/BinaryView.d.ts +10 -0
  52. package/dist/types/core/components/expression/ExprSummary.d.ts +12 -0
  53. package/dist/types/core/components/expression/ExpressionTypeSelector.d.ts +35 -0
  54. package/dist/types/core/components/expression/ExpressionView.d.ts +30 -0
  55. package/dist/types/core/components/expression/FieldView.d.ts +15 -0
  56. package/dist/types/core/components/expression/FormulaPeek.d.ts +14 -0
  57. package/dist/types/core/components/expression/FunctionArgInput.d.ts +22 -0
  58. package/dist/types/core/components/expression/FunctionView.d.ts +7 -0
  59. package/dist/types/core/components/expression/ListView.d.ts +20 -0
  60. package/dist/types/core/components/expression/LiteralView.d.ts +23 -0
  61. package/dist/types/core/components/expression/LogicalView.d.ts +9 -0
  62. package/dist/types/core/components/expression/MeasureMenu.d.ts +21 -0
  63. package/dist/types/core/components/expression/ParamView.d.ts +13 -0
  64. package/dist/types/core/components/expression/RelativeDateView.d.ts +15 -0
  65. package/dist/types/core/components/expression/SubqueryView.d.ts +8 -0
  66. package/dist/types/core/components/expression/formulaClasses.d.ts +8 -0
  67. package/dist/types/core/components/flow/CaseBranchFlowNode.d.ts +5 -0
  68. package/dist/types/core/components/flow/CaseElseFlowNode.d.ts +5 -0
  69. package/dist/types/core/components/flow/CaseFlowNode.d.ts +5 -0
  70. package/dist/types/core/components/flow/ConditionFlowNode.d.ts +5 -0
  71. package/dist/types/core/components/flow/CreateConditionFlowNode.d.ts +14 -0
  72. package/dist/types/core/components/flow/CreateHavingFlowNode.d.ts +11 -0
  73. package/dist/types/core/components/flow/DistinctToggle.d.ts +10 -0
  74. package/dist/types/core/components/flow/ExistsFlowNode.d.ts +9 -0
  75. package/dist/types/core/components/flow/FromFlowNode.d.ts +110 -0
  76. package/dist/types/core/components/flow/FunctionArgFlowNode.d.ts +5 -0
  77. package/dist/types/core/components/flow/FunctionCallFlowNode.d.ts +5 -0
  78. package/dist/types/core/components/flow/FunctionSortKeys.d.ts +10 -0
  79. package/dist/types/core/components/flow/GroupBgNode.d.ts +14 -0
  80. package/dist/types/core/components/flow/GroupByFlowNode.d.ts +29 -0
  81. package/dist/types/core/components/flow/IfElseFlowNode.d.ts +5 -0
  82. package/dist/types/core/components/flow/IfFlowNode.d.ts +5 -0
  83. package/dist/types/core/components/flow/IfThenFlowNode.d.ts +5 -0
  84. package/dist/types/core/components/flow/LeafConditionFrame.d.ts +19 -0
  85. package/dist/types/core/components/flow/LogicalFlowNode.d.ts +5 -0
  86. package/dist/types/core/components/flow/MoveTooltip.d.ts +19 -0
  87. package/dist/types/core/components/flow/NotFlowNode.d.ts +5 -0
  88. package/dist/types/core/components/flow/OrderByFlowNode.d.ts +32 -0
  89. package/dist/types/core/components/flow/SectionLabelFlowNode.d.ts +7 -0
  90. package/dist/types/core/components/flow/SelectFlowNode.d.ts +49 -0
  91. package/dist/types/core/components/flow/SharedQueriesFlowNode.d.ts +39 -0
  92. package/dist/types/core/components/flow/SummaryPill.d.ts +12 -0
  93. package/dist/types/core/components/flow/WarningNote.d.ts +9 -0
  94. package/dist/types/core/components/flow/chainSides.d.ts +18 -0
  95. package/dist/types/core/components/flow/dragContext.d.ts +12 -0
  96. package/dist/types/core/components/flow/moveTooltipHysteresis.d.ts +18 -0
  97. package/dist/types/core/components/flow/useRowDrag.d.ts +34 -0
  98. package/dist/types/core/components/flow/useRowReorderFlip.d.ts +30 -0
  99. package/dist/types/core/derivedTables.d.ts +98 -0
  100. package/dist/types/core/distinctSort.d.ts +7 -0
  101. package/dist/types/core/drillPath.d.ts +11 -0
  102. package/dist/types/core/exists.d.ts +7 -0
  103. package/dist/types/core/existsMenu.d.ts +61 -0
  104. package/dist/types/core/expressionFlow.d.ts +428 -0
  105. package/dist/types/core/fanOut.d.ts +58 -0
  106. package/dist/types/core/findParts.d.ts +19 -0
  107. package/dist/types/core/flowTrees.d.ts +20 -0
  108. package/dist/types/core/focusKey.d.ts +10 -0
  109. package/dist/types/core/formula.d.ts +24 -0
  110. package/dist/types/core/formulaPeek.d.ts +16 -0
  111. package/dist/types/core/functionRegistry.d.ts +117 -0
  112. package/dist/types/core/grouping.d.ts +58 -0
  113. package/dist/types/core/history.d.ts +25 -0
  114. package/dist/types/core/i18n/defaultMessages.d.ts +367 -0
  115. package/dist/types/core/i18n/messages.d.ts +273 -0
  116. package/dist/types/core/i18n/relativeDateWords.d.ts +3 -0
  117. package/dist/types/core/id.d.ts +5 -0
  118. package/dist/types/core/issueAnchor.d.ts +29 -0
  119. package/dist/types/core/issueLocation.d.ts +105 -0
  120. package/dist/types/core/limits.d.ts +17 -0
  121. package/dist/types/core/measures.d.ts +51 -0
  122. package/dist/types/core/params.d.ts +30 -0
  123. package/dist/types/core/pipelineAnchor.d.ts +118 -0
  124. package/dist/types/core/pipelineFlow.d.ts +271 -0
  125. package/dist/types/core/queryAst.d.ts +201 -0
  126. package/dist/types/core/queryHelpers.d.ts +113 -0
  127. package/dist/types/core/queryValidation.d.ts +206 -0
  128. package/dist/types/core/relativeDates.d.ts +11 -0
  129. package/dist/types/core/resolveNames.d.ts +17 -0
  130. package/dist/types/core/rowRange.d.ts +3 -0
  131. package/dist/types/core/schema.d.ts +119 -0
  132. package/dist/types/core/scopeQuery.d.ts +45 -0
  133. package/dist/types/core/selectColumns.d.ts +23 -0
  134. package/dist/types/core/settleQuery.d.ts +11 -0
  135. package/dist/types/core/sharedQueries.d.ts +66 -0
  136. package/dist/types/core/sqlGen.d.ts +102 -0
  137. package/dist/types/core/sqlOffsets.d.ts +5 -0
  138. package/dist/types/core/sqlSpans.d.ts +33 -0
  139. package/dist/types/core/storedQuery.d.ts +43 -0
  140. package/dist/types/core/summarize.d.ts +3 -0
  141. package/dist/types/core/theme/tokens.d.ts +74 -0
  142. package/dist/types/core/ui/UIContext.d.ts +6 -0
  143. package/dist/types/core/ui/index.d.ts +12 -0
  144. package/dist/types/core/ui/types.d.ts +264 -0
  145. package/dist/types/core/unionTables.d.ts +121 -0
  146. package/dist/types/core/useValueTypes.d.ts +12 -0
  147. package/dist/types/core/valueTypes.d.ts +54 -0
  148. package/dist/types/core-api.d.ts +20 -0
  149. package/dist/types/features/queryEditor/ExpressionFlowCanvas.d.ts +10 -0
  150. package/dist/types/features/queryEditor/FindBox.d.ts +12 -0
  151. package/dist/types/features/queryEditor/FlowCanvas.d.ts +96 -0
  152. package/dist/types/features/queryEditor/FocusPulse.d.ts +10 -0
  153. package/dist/types/features/queryEditor/IssuesButton.d.ts +16 -0
  154. package/dist/types/features/queryEditor/PipelineEditor.d.ts +210 -0
  155. package/dist/types/features/queryEditor/QueryOutline.d.ts +16 -0
  156. package/dist/types/features/queryEditor/ResultsPanel.d.ts +11 -0
  157. package/dist/types/features/queryEditor/RunButton.d.ts +11 -0
  158. package/dist/types/features/queryEditor/SubFlowPanel.d.ts +24 -0
  159. package/dist/types/features/queryEditor/UndoRedoToast.d.ts +6 -0
  160. package/dist/types/features/queryEditor/canvasPositioning.d.ts +81 -0
  161. package/dist/types/features/queryEditor/findKeys.d.ts +3 -0
  162. package/dist/types/features/queryEditor/flowDragUtils.d.ts +16 -0
  163. package/dist/types/features/queryEditor/focusContext.d.ts +24 -0
  164. package/dist/types/features/queryEditor/hoveredPart.d.ts +32 -0
  165. package/dist/types/features/queryEditor/issueFocusParts.d.ts +9 -0
  166. package/dist/types/features/queryEditor/issueLocationText.d.ts +7 -0
  167. package/dist/types/features/queryEditor/issueText.d.ts +11 -0
  168. package/dist/types/features/queryEditor/outlineSections.d.ts +23 -0
  169. package/dist/types/features/queryEditor/run.d.ts +36 -0
  170. package/dist/types/features/queryEditor/sectionLabels.d.ts +15 -0
  171. package/dist/types/features/queryEditor/treeScopeContext.d.ts +14 -0
  172. package/dist/types/features/queryEditor/useRemeasureOnDirectionChange.d.ts +7 -0
  173. package/dist/types/features/queryEditor/useRevealNewNodes.d.ts +35 -0
  174. package/dist/types/features/queryEditor/withTreeScope.d.ts +10 -0
  175. package/dist/types/fixtures.d.ts +44 -0
  176. package/dist/types/index.d.ts +13 -0
  177. package/dist/types/mui-date-pickers.d.ts +3 -0
  178. package/dist/types/mui.d.ts +2 -0
  179. package/dist/types/sql-import.d.ts +3 -0
  180. package/dist/types/sqlImport/context.d.ts +71 -0
  181. package/dist/types/sqlImport/expressions.d.ts +11 -0
  182. package/dist/types/sqlImport/importSql.d.ts +28 -0
  183. package/dist/types/sqlImport/parse.d.ts +6 -0
  184. package/dist/types/sqlImport/syntax.d.ts +245 -0
  185. package/dist/types/sqlImport/tokenize.d.ts +26 -0
  186. package/package.json +164 -3
@@ -0,0 +1,105 @@
1
+ import { type FunctionRegistry } from './functionRegistry.js';
2
+ import { type QueryBody } from './queryAst.js';
3
+ import { type DatabaseSchema } from './schema.js';
4
+ /** One step of an issue's location, outermost first. */
5
+ export type IssueLocationStep =
6
+ /** A section of a query: FROM, WHERE ("Conditions"), GROUP BY, HAVING,
7
+ * SELECT, or ORDER BY / LIMIT ("Sort & Limit"). */
8
+ {
9
+ kind: 'section';
10
+ section: 'from' | 'where' | 'group' | 'having' | 'select' | 'order';
11
+ }
12
+ /** A derived table: a sub query, by its name. Its own steps follow. */
13
+ | {
14
+ kind: 'subQuery';
15
+ name: string;
16
+ }
17
+ /** A shared query (issue 194), by its name. Its own steps follow. */
18
+ | {
19
+ kind: 'sharedQuery';
20
+ name: string;
21
+ }
22
+ /** One of a union's queries (from 1). */
23
+ | {
24
+ kind: 'unionQuery';
25
+ number: number;
26
+ }
27
+ /** IN's sub query. */
28
+ | {
29
+ kind: 'inSubQuery';
30
+ }
31
+ /** A table of FROM, by the name it shows: its alias, else its label. */
32
+ | {
33
+ kind: 'table';
34
+ name: string;
35
+ } | {
36
+ kind: 'joinCondition';
37
+ }
38
+ /** A SELECT column (from 1), by its alias or its column's label when it
39
+ * has one. */
40
+ | {
41
+ kind: 'column';
42
+ number: number;
43
+ name?: string;
44
+ } | {
45
+ kind: 'groupKey';
46
+ number: number;
47
+ }
48
+ /** A sort key (from 1): ORDER BY's, or one inside an aggregate. */
49
+ | {
50
+ kind: 'sortKey';
51
+ number: number;
52
+ }
53
+ /** One of a group's conditions (from 1). */
54
+ | {
55
+ kind: 'condition';
56
+ number: number;
57
+ } | {
58
+ kind: 'not';
59
+ }
60
+ /** A comparison's side. */
61
+ | {
62
+ kind: 'side';
63
+ side: 'left' | 'right';
64
+ }
65
+ /** One of IN's values (from 1). */
66
+ | {
67
+ kind: 'listItem';
68
+ number: number;
69
+ } | {
70
+ kind: 'function';
71
+ name: string;
72
+ }
73
+ /** A function's argument (from 1), by its signature's label. */
74
+ | {
75
+ kind: 'argument';
76
+ number: number;
77
+ label?: string;
78
+ } | {
79
+ kind: 'if';
80
+ part: 'condition' | 'then' | 'else';
81
+ }
82
+ /** A CASE's part; `branch` (from 1) for a WHEN's or THEN's. */
83
+ | {
84
+ kind: 'case';
85
+ part: 'subject' | 'when' | 'then' | 'else';
86
+ branch?: number;
87
+ }
88
+ /** An EXISTS, by the table it looks for rows in. */
89
+ | {
90
+ kind: 'exists';
91
+ table: string;
92
+ }
93
+ /** An EXISTS's link to the query around it. */
94
+ | {
95
+ kind: 'existsLink';
96
+ };
97
+ type Segments = (string | number)[];
98
+ /** Where the issue at `segments` (its pathSegments) is in `query`, as
99
+ * steps — as far as the path still leads in it. `schema` gives tables'
100
+ * and columns' labels, `functions` arguments' labels. */
101
+ export default function issueLocation(query: QueryBody, segments: Segments, options?: {
102
+ schema?: DatabaseSchema;
103
+ functions?: FunctionRegistry;
104
+ }): IssueLocationStep[];
105
+ export {};
@@ -0,0 +1,17 @@
1
+ /** A text value: long enough for any real filter value, short enough to
2
+ * catch a paste by mistake. */
3
+ export declare const MAX_TEXT_LENGTH = 1000;
4
+ /** A number's significant digits: what a JS number keeps exactly. A longer
5
+ * one would be written as some other number. */
6
+ export declare const MAX_NUMBER_DIGITS = 15;
7
+ /** A CAST's type name: enough for `DECIMAL(38, 10)` or `DOUBLE PRECISION`. */
8
+ export declare const MAX_TYPE_NAME_LENGTH = 40;
9
+ /** What's typed to search a picker. Never stored: the input only. */
10
+ export declare const MAX_SEARCH_LENGTH = 100;
11
+ /** The significant digits of a number written as `text` (`-0.00120` has 2,
12
+ * `1.5e-7` 2): leading zeros don't count, nor a fraction's trailing ones;
13
+ * a whole number's do (`100` has 3). */
14
+ export declare function significantDigits(text: string): number;
15
+ /** Whether `n` is a number a query can hold as is: finite, and at most
16
+ * MAX_NUMBER_DIGITS significant digits. */
17
+ export declare function fitsNumber(n: number): boolean;
@@ -0,0 +1,51 @@
1
+ import type { ExpressionNode } from './ast.js';
2
+ import { type DerivedJoin, type QueryBody, type QueryPipeline, type QueryValue } from './queryAst.js';
3
+ import { type DatabaseSchema, type Table } from './schema.js';
4
+ /** The tables `fact` shares with a report: itself, and every table it
5
+ * reaches through the relations going from the many side to the one side
6
+ * at each step (sales_target → store → region). A report grouped by
7
+ * columns of these has a grain the fact can be summed down to. */
8
+ export declare function sharedDimensions(schema: DatabaseSchema, fact: string, oneSides?: Map<string, string[]>): Set<string>;
9
+ /** A fact a measure could come from, in a report: every table of the
10
+ * schema, and — when it can't be one here — the table of a GROUP BY key
11
+ * it doesn't reach (`unlinked`: a table's name, or a derived table's). */
12
+ export interface MeasureFact {
13
+ table: Table;
14
+ unlinked?: string;
15
+ }
16
+ /** The facts a measure could come from in `query` (see MeasureFact): those
17
+ * sharing every table its GROUP BY keys name (sharedDimensions). */
18
+ export declare function measureFacts(schema: DatabaseSchema, query: QueryBody): MeasureFact[];
19
+ /** Whether one of the report's WHERE operands names both tables `fact`
20
+ * shares and tables it doesn't (an OR across them): it can't be split, so
21
+ * it isn't copied, and the measure's rows aren't filtered by it. */
22
+ export declare function mixedFilter(schema: DatabaseSchema, query: QueryBody, fact: string): boolean;
23
+ /** What Add measure is given: the fact, the value it sums up there (an
24
+ * aggregate of its columns, e.g. SUM(sales_target.amount)), the measure's
25
+ * own conditions, and the SELECT column to put it in (else a new one). */
26
+ export interface MeasureSpec {
27
+ table: string;
28
+ value: ExpressionNode;
29
+ where?: ExpressionNode;
30
+ selectId?: string;
31
+ }
32
+ /** `query` with a measure from another fact (see the design): `table`'s
33
+ * `value`, summed on its own down to the query's grain, as a derived table
34
+ * LEFT joined on the GROUP BY keys (NULL-safe), kept in step with the
35
+ * report (`drillAcross`), and read by MAX in a SELECT column. A second
36
+ * measure from the same fact with the same own conditions is another
37
+ * column of the same derived table. Throws when the query isn't grouped,
38
+ * or the fact doesn't share its grain (measureFacts). */
39
+ export declare function addMeasure(schema: DatabaseSchema, query: QueryPipeline, spec: MeasureSpec): QueryPipeline;
40
+ /** `join` (a measure in `report`) rebuilt to match the report as it is
41
+ * now: its keys, copied filters and ON; its own conditions and values
42
+ * kept. Undefined when the report's grain is one its fact can't follow —
43
+ * no GROUP BY, or a key on a table it doesn't share. */
44
+ export declare function rebuildMeasure(schema: DatabaseSchema, report: QueryBody, derivedJoin: DerivedJoin): DerivedJoin | undefined;
45
+ /** Whether a measure kept in step matches its report (see rebuildMeasure);
46
+ * false when the report's grain is one it can't follow. */
47
+ export declare function measureInStep(schema: DatabaseSchema, report: QueryBody, join: DerivedJoin): boolean;
48
+ /** `next` — the query after an edit of `previous` — with every measure in it
49
+ * kept in step (see keepLevel). The editor applies it to every edit, in
50
+ * the same undo step; code editing a query with measures should too. */
51
+ export declare function keepMeasuresInStep(schema: DatabaseSchema, previous: QueryValue | undefined, next: QueryValue): QueryValue;
@@ -0,0 +1,30 @@
1
+ import type { LiteralValue, RelativeDate } from './ast.js';
2
+ import { type QueryPipeline } from './queryAst.js';
3
+ import { type DatabaseColumnType, type DatabaseSchema } from './schema.js';
4
+ /** A param the query needs, and the type of the column it's compared
5
+ * against — undefined when it isn't compared against a known column, or is
6
+ * compared against columns of different types (see conflictingParams). */
7
+ export interface QueryParam {
8
+ name: string;
9
+ type?: DatabaseColumnType;
10
+ /** A date relative to when the query runs (issue 140): the application
11
+ * computes its value — "today" in its user's time zone, its first day of
12
+ * the week, the form a dateTime column needs (`type`). */
13
+ relative?: RelativeDate;
14
+ }
15
+ /** The params `query` needs a value for, in the order they first appear —
16
+ * what an application asks for before running a saved query (and the only
17
+ * names it should accept values for). With `schema`, each one's type is
18
+ * inferred from the column it's compared against (`hire_date >= :start` →
19
+ * `date`). */
20
+ export declare function queryParams(query: QueryPipeline, schema?: DatabaseSchema): QueryParam[];
21
+ /** Names given two different relative dates (`:from` as 30 days ago in one
22
+ * place and the start of the month in another) — one value can't be both. */
23
+ export declare function conflictingRelatives(query: QueryPipeline): string[];
24
+ /** Names compared against columns of more than one type (`:x` against a
25
+ * date and a number) — no one value suits both. */
26
+ export declare function conflictingParams(query: QueryPipeline, schema: DatabaseSchema): string[];
27
+ /** `query` with every param replaced by its value from `values`, as a
28
+ * literal — an error for a param without one. What astToSql does with its
29
+ * `values` option; astToParameterizedSql binds them instead. */
30
+ export declare function fillParams(query: QueryPipeline, values: Record<string, LiteralValue>): QueryPipeline;
@@ -0,0 +1,118 @@
1
+ import { type AbsolutePath } from './absolutePath.js';
2
+ import type { DrillLevel } from './DrillDownContext.js';
3
+ import type { FromClause, QueryPipeline } from './queryAst.js';
4
+ import { type QueryPath } from './derivedTables.js';
5
+ /** Where a PipelineEditor edit happened — which of the pipeline's several
6
+ * ExpressionNode trees `path` is relative to. 'structural' covers add/remove/
7
+ * reorder-join-style edits (and the equivalent SELECT-list edits) that have
8
+ * no drillable target at all (FromPanel/SelectPanel, where they're made, are
9
+ * always visible — nothing to navigate to). Its own optional `key` exists
10
+ * purely so PipelineEditor's pipelineDispatch can opt a *specific* kind of
11
+ * structural edit into coalescing (e.g. typing into one column's own alias
12
+ * field, keyed per selectId) without affecting any other structural action
13
+ * — every other one still keeps `key: undefined` and so never coalesces
14
+ * with anything (anchorsEqual only compares `key` at all, still ignoring
15
+ * everything else about a 'structural' anchor, matching its own prior
16
+ * always-equal behavior once both sides lack one). 'select' behaves like
17
+ * 'where' for a `path: []` anchor whose column is a plain field/literal
18
+ * (inline on the main canvas, no panel needed) but like 'join' the instant
19
+ * the column's own root is itself a function/if/case/binary/logical/not —
20
+ * that root then renders *collapsed* on the main canvas (an "Edit in
21
+ * sub-canvas" button, same as any nested drill boundary), so reaching
22
+ * anything *inside* it — a nested `path` — genuinely needs its own panel,
23
+ * synthesized the same way `anchorToDrillLevels` already does for a join's
24
+ * ON. See that function's own comment for exactly when the synthesized top
25
+ * entry applies. */
26
+ export type PipelineAnchor = ({
27
+ scope: 'structural';
28
+ key?: string;
29
+ } | {
30
+ scope: 'where';
31
+ path: AbsolutePath;
32
+ } | {
33
+ scope: 'join';
34
+ joinId: string;
35
+ path: AbsolutePath;
36
+ } | {
37
+ scope: 'select';
38
+ selectId: string;
39
+ path: AbsolutePath;
40
+ } | {
41
+ scope: 'orderBy';
42
+ orderById: string;
43
+ path: AbsolutePath;
44
+ } | {
45
+ scope: 'groupBy';
46
+ groupById: string;
47
+ path: AbsolutePath;
48
+ } | {
49
+ scope: 'having';
50
+ path: AbsolutePath;
51
+ }) & {
52
+ /** The query it's in, when that's a derived table's (see QueryPath);
53
+ * absent for the whole query. Everything else is relative to it. */
54
+ queryPath?: QueryPath;
55
+ };
56
+ /** Which expression tree a drill panel edits, besides WHERE's own:
57
+ * a join's ON, a SELECT column's or an ORDER BY item's expression. */
58
+ export type PipelineScopeRoot = {
59
+ joinId: string;
60
+ } | {
61
+ selectId: string;
62
+ } | {
63
+ orderById: string;
64
+ } | {
65
+ groupById: string;
66
+ } | {
67
+ having: true;
68
+ };
69
+ /** Which SubFlowPanel a drill-stack entry belongs to — undefined `scopeRoot`
70
+ * means WHERE's own (possibly nested) canvas; `{joinId}` means a specific
71
+ * join's ON condition; `{selectId}` means a specific SELECT column's own
72
+ * expression. Kept local to the pipeline layer: DrillDownContext.ts itself
73
+ * stays generic and doesn't need to know pipelines exist. */
74
+ export interface PipelineDrillLevel extends DrillLevel {
75
+ scopeRoot?: PipelineScopeRoot;
76
+ /** The query this level is in, when that's a derived table's; absent for
77
+ * the whole query. `scopeRoot` and `path` are relative to it. */
78
+ queryPath?: QueryPath;
79
+ /** A derived table's own canvas — the query at `queryPath` itself, with
80
+ * its FROM, WHERE, GROUP BY and SELECT — rather than an expression in it
81
+ * (`path` is []). */
82
+ pipeline?: true;
83
+ /** A sub query being made, not in the query yet: its canvas, empty, until
84
+ * its first table is picked — then it's added (as a join, as the base,
85
+ * by `in` as an IN's right side: issue 122, or as the base of another
86
+ * being made, the level before: 'nestedBase'), under the id `queryPath`
87
+ * ends with. A chain of them is made at once, from its innermost table.
88
+ * Leaving first adds nothing. */
89
+ pendingSubQuery?: 'join' | 'base' | 'nestedBase' | {
90
+ in: (from: FromClause, id: string) => void;
91
+ };
92
+ }
93
+ export declare function anchorsEqual(a: PipelineAnchor, b: PipelineAnchor): boolean;
94
+ /** The panels down to the derived table at `queryPath`: its own canvas,
95
+ * for each derived table on the way. */
96
+ export declare function derivedDrillLevels(pipeline: QueryPipeline | undefined, queryPath: QueryPath): PipelineDrillLevel[];
97
+ /** Reconstructs the drill stack needed to reach `anchor` (see
98
+ * localDrillLevels), through the canvases of the derived tables it's in. */
99
+ export declare function anchorToDrillLevels(pipeline: QueryPipeline | undefined, anchor: PipelineAnchor): PipelineDrillLevel[];
100
+ /** Whether `anchor`'s target is already visible under the currently-open
101
+ * `drillStack` — i.e. jumping to it would be a no-op. Only the panels of
102
+ * the query it's in count, past that query's own canvas. */
103
+ export declare function isAnchorCovered(drillStack: PipelineDrillLevel[], anchor: PipelineAnchor): boolean;
104
+ /** Truncates `stack` at the first level that no longer resolves under
105
+ * `pipeline` — either its own join/select-column was removed entirely, or
106
+ * (for a nested level) its path no longer points at a valid drillable node
107
+ * in whichever tree it belongs to (e.g. undo/redo shifted sibling indices
108
+ * elsewhere). A join scope-root's own top level (path: []) is always valid
109
+ * as long as its join still exists — it represents opening the ON
110
+ * sub-canvas itself, which (like WHERE's main canvas) stays valid even
111
+ * while its condition is unset. A select scope-root's own top level gets no
112
+ * such exception: unlike a join's `on`, a SELECT column's `expression` is
113
+ * never undefined, and its own panel (path: []) only ever exists because
114
+ * the column was already a function/if/case/binary/logical/not at the
115
+ * moment it was drilled into — so it's validated the same as any nested
116
+ * level, correctly pruned if e.g. undo swaps the column back to a plain
117
+ * field while that panel is open. */
118
+ export declare function pruneDrillStack(top: QueryPipeline | undefined, stack: PipelineDrillLevel[]): PipelineDrillLevel[];
@@ -0,0 +1,271 @@
1
+ import { type Messages } from './i18n/defaultMessages.js';
2
+ import type { ExpressionNode } from './ast.js';
3
+ import { type QueryPath } from './derivedTables.js';
4
+ import { type FromClause, type QueryBody, type EmptyQuery, type JoinClause, type JoinType, type QueryPipeline, type QueryValue, type SelectItem, type SortDirection } from './queryAst.js';
5
+ import { type DatabaseSchema, type Table } from './schema.js';
6
+ /** What a new derived table's query reads: a table, or a FROM of its own
7
+ * (a sub query, when one is made inside another being made). */
8
+ export type DerivedSource = {
9
+ table: string;
10
+ } | {
11
+ from: FromClause;
12
+ };
13
+ export type PipelineAction = {
14
+ type: 'setBaseTable';
15
+ table: string;
16
+ } | ({
17
+ type: 'setDerivedBaseTable';
18
+ id?: string;
19
+ } & DerivedSource) | {
20
+ type: 'changeBaseAlias';
21
+ alias: string | undefined;
22
+ } | {
23
+ type: 'addJoin';
24
+ table: string;
25
+ joinType?: JoinType;
26
+ on?: ExpressionNode;
27
+ } | ({
28
+ type: 'addDerivedJoin';
29
+ id?: string;
30
+ } & DerivedSource) | {
31
+ type: 'renameDerivedTable';
32
+ derivedId: string;
33
+ alias: string;
34
+ }
35
+ /** A shared query's place (issue 194) renamed: a join's, or the base's
36
+ * (no `joinId`). */
37
+ | {
38
+ type: 'renameSharedPlace';
39
+ joinId?: string;
40
+ alias: string;
41
+ } | {
42
+ type: 'setMeasureSynced';
43
+ joinId: string;
44
+ synced: boolean;
45
+ } | {
46
+ type: 'removeJoin';
47
+ joinId: string;
48
+ } | {
49
+ type: 'changeJoinType';
50
+ joinId: string;
51
+ joinType: JoinType;
52
+ } | {
53
+ type: 'changeJoinAlias';
54
+ joinId: string;
55
+ alias: string | undefined;
56
+ } | {
57
+ type: 'changeJoinOn';
58
+ joinId: string;
59
+ on: ExpressionNode | undefined;
60
+ } | {
61
+ type: 'reorderJoin';
62
+ joinId: string;
63
+ direction: 'up' | 'down';
64
+ } | {
65
+ type: 'reorderTables';
66
+ fromIndex: number;
67
+ toIndex: number;
68
+ } | {
69
+ type: 'removeBaseTable';
70
+ } | {
71
+ type: 'addSelectItem';
72
+ } | {
73
+ type: 'removeSelectItem';
74
+ selectId: string;
75
+ } | {
76
+ type: 'reorderSelectItems';
77
+ fromIndex: number;
78
+ toIndex: number;
79
+ } | {
80
+ type: 'setSelectAlias';
81
+ selectId: string;
82
+ alias: string | undefined;
83
+ } | {
84
+ type: 'setSelectExpression';
85
+ selectId: string;
86
+ expression: ExpressionNode;
87
+ } | {
88
+ type: 'addGroupByItem';
89
+ } | {
90
+ type: 'removeGroupByItem';
91
+ groupById: string;
92
+ } | {
93
+ type: 'reorderGroupByItems';
94
+ fromIndex: number;
95
+ toIndex: number;
96
+ } | {
97
+ type: 'setGroupByExpression';
98
+ groupById: string;
99
+ expression: ExpressionNode;
100
+ } | {
101
+ type: 'groupBySelectItem';
102
+ selectId: string;
103
+ } | {
104
+ type: 'removeHaving';
105
+ } | {
106
+ type: 'setDistinct';
107
+ distinct: boolean;
108
+ } | {
109
+ type: 'addOrderByItem';
110
+ } | {
111
+ type: 'removeOrderByItem';
112
+ orderById: string;
113
+ } | {
114
+ type: 'reorderOrderByItems';
115
+ fromIndex: number;
116
+ toIndex: number;
117
+ } | {
118
+ type: 'setOrderByExpression';
119
+ orderById: string;
120
+ expression: ExpressionNode;
121
+ } | {
122
+ type: 'setOrderByDirection';
123
+ orderById: string;
124
+ direction: SortDirection;
125
+ } | {
126
+ type: 'setLimit';
127
+ limit: number | undefined;
128
+ } | {
129
+ type: 'setOffset';
130
+ offset: number | undefined;
131
+ } | {
132
+ type: 'clearPaging';
133
+ };
134
+ /** Every distinct table referenced by a field in `ast` (deduplicated, in first-seen
135
+ * order) — used to auto-add tables to the pipeline as a WHERE condition references
136
+ * them. Only fields with an explicit `.table` count — an unqualified field doesn't
137
+ * imply any particular table. */
138
+ export declare function referencedTables(ast: ExpressionNode | undefined): string[];
139
+ /** Auto-adds (via addJoin's own suggestJoin logic) every table referenced by
140
+ * a field in `ast` that the pipeline doesn't already have. A table with no
141
+ * direct relation to anything already present gets the intermediate tables
142
+ * it needs added first (findJoinPath) — e.g. picking a product_category
143
+ * column with only sale_transaction in FROM adds product, then
144
+ * product_category — so each added join gets a real suggested ON condition
145
+ * instead of an unconnected one. A table nothing connects to at all is still
146
+ * added on its own (ON left for the user to set). A name that is a table's
147
+ * alias is that table, never a new one. */
148
+ export declare function addReferencedTables(schema: DatabaseSchema, pipeline: QueryPipeline, ast: ExpressionNode | undefined): QueryPipeline;
149
+ /** SELECT's counterpart to applyWhereChange — replaces one column's expression
150
+ * and auto-adds any table it newly references (addReferencedTables), as one
151
+ * pipeline update. Behind both the 'setSelectExpression' action (inline edits
152
+ * on the SELECT node) and PipelineEditor's drill-down setAtPath for a
153
+ * column's own sub-canvas. */
154
+ export declare function applySelectChange(schema: DatabaseSchema, pipeline: QueryPipeline, selectId: string, expression: ExpressionNode): QueryPipeline;
155
+ /** A join whose ON condition refers to a table that is only joined after
156
+ * it — SQL can't do that. `table` is the join, `needs` the table it
157
+ * refers to too early. */
158
+ export interface TableOrderConflict {
159
+ table: string;
160
+ needs: string;
161
+ }
162
+ /** The first join whose ON condition refers to a table not joined before
163
+ * it, or undefined when the order is fine. */
164
+ export declare function tableOrderConflict(pipeline: Pick<QueryBody, 'from' | 'joins'>): TableOrderConflict | undefined;
165
+ /** What would go wrong moving the [base, ...joins] entry at `fromIndex` to
166
+ * `toIndex` — undefined when the move keeps the order valid (or isn't a
167
+ * move at all). Drives the FROM node's Move Up/Down buttons and its drag
168
+ * feedback, and the reason they show. */
169
+ export declare function reorderTablesConflict(pipeline: QueryPipeline, fromIndex: number, toIndex: number): TableOrderConflict | undefined;
170
+ /** Whether that move is a real move that keeps the order valid;
171
+ * 'reorderTables' ignores any other. */
172
+ export declare function canReorderTables(pipeline: QueryPipeline, fromIndex: number, toIndex: number): boolean;
173
+ /** ORDER BY's counterpart to applySelectChange: replaces one sort item's
174
+ * expression and joins any table it newly refers to, as one update. */
175
+ export declare function applyOrderByChange(schema: DatabaseSchema, pipeline: QueryPipeline, orderById: string, expression: ExpressionNode): QueryPipeline;
176
+ /** GROUP BY's counterpart to applySelectChange: replaces one group key's
177
+ * expression and joins any table it newly refers to, as one update. */
178
+ export declare function applyGroupByChange(schema: DatabaseSchema, pipeline: QueryPipeline, groupById: string, expression: ExpressionNode): QueryPipeline;
179
+ /** `node` with every EXISTS in it joined, inside it, to the tables its own
180
+ * conditions use — through the relations, as WHERE's are
181
+ * (addReferencedTables). The same node when there's nothing to join. */
182
+ export declare function withExistsJoins(schema: DatabaseSchema, node: ExpressionNode | undefined): ExpressionNode | undefined;
183
+ /** HAVING's counterpart to applyWhereChange: the new condition, with any
184
+ * table it newly refers to joined, as one update. */
185
+ export declare function applyHavingChange(schema: DatabaseSchema, pipeline: QueryPipeline, nextHaving: ExpressionNode | undefined): QueryPipeline;
186
+ /** What a new derived table (a sub query) in `query` is called:
187
+ * `sub_query_<n>`, the smallest n no table of the query or the schema
188
+ * goes by. Not after the table it starts from: what it's made of changes,
189
+ * and a name saying otherwise would mislead. */
190
+ export declare function subQueryName(schema: DatabaseSchema, query: QueryBody | undefined): string;
191
+ /** A new query with nothing in it yet, under a fresh unique id. */
192
+ export declare function createEmptyQuery(): EmptyQuery;
193
+ /** Pure — applies a PipelineAction to a QueryPipeline. `schema` is only read
194
+ * by the actions that add tables ('addJoin' suggesting a join condition,
195
+ * 'setSelectExpression' auto-adding referenced tables). An EmptyQuery `prev`
196
+ * (no base table yet) only accepts 'setBaseTable', which fills it in under
197
+ * the same id; every other action returns it unchanged. A query only goes
198
+ * back to empty via 'removeBaseTable' emptying the combined table list —
199
+ * and keeps its id when it does, so it's still the same query. */
200
+ export declare function applyPipelineAction(schema: DatabaseSchema, prev: QueryValue, action: PipelineAction): QueryValue;
201
+ /** Label for a join's own drill-panel breadcrumb/entrance, e.g. "INNER JOIN
202
+ * product" — shared between FromPanel's condition-summary click (which opens
203
+ * the drill) and pipelineAnchor.ts's jump-to-here reconstruction after undo/redo,
204
+ * so both produce the exact same label for the same join. */
205
+ export declare function joinDrillLabel(join: JoinClause): string;
206
+ /** Label for a SELECT column's own drill-panel breadcrumb/entrance — shared
207
+ * between SelectFlowNode's own live "Edit in sub-canvas" click and
208
+ * pipelineAnchor.ts's jump-to-here reconstruction after undo/redo, so both
209
+ * produce the exact same label for the same column (mirrors
210
+ * `joinDrillLabel`'s own reasoning). */
211
+ export declare function selectColumnDrillLabel(item: SelectItem): string;
212
+ /** Label for an ORDER BY item's own drill-panel breadcrumb (see
213
+ * selectColumnDrillLabel). */
214
+ export declare function orderByDrillLabel(): string;
215
+ /** Label for a GROUP BY key's own drill-panel breadcrumb. */
216
+ export declare function groupByDrillLabel(): string;
217
+ /** Every table currently referenced by the pipeline (base + joins), resolved to full
218
+ * Table records — used to scope FieldView's picker to only what's actually joined. */
219
+ export declare function pipelineTables(schema: DatabaseSchema, pipeline: QueryPipeline): Table[];
220
+ /** The tables (by the name fields use: a table's, a derived table's alias)
221
+ * a field of `query` can name without leaving an error behind. Where a
222
+ * field joins the table it names (WHERE, SELECT, …: addReferencedTables),
223
+ * one in the query or one that joining gives a condition to — through the
224
+ * relations, intermediate tables or a derived table holding its key
225
+ * included — and its derived tables. In a join's ON (`joinId`), which joins
226
+ * nothing, the tables joined up to that one, itself included. */
227
+ export declare function pickableTables(schema: DatabaseSchema, query: QueryPipeline, joinId?: string): Set<string>;
228
+ /** The schema's tables as a field picker lists them for `query`, in the
229
+ * schema's order: one in the query by the name fields use for it (its
230
+ * alias — once per alias, when it's joined more than once), any other by
231
+ * its name. A field naming a table by its name when the query has it
232
+ * under an alias would name nothing. */
233
+ export declare function fieldPickerTables(schema: DatabaseSchema, query: QueryPipeline): {
234
+ ref: string;
235
+ table: Table;
236
+ }[];
237
+ /** Tables not yet referenced by the pipeline — what a UI would offer to add next. */
238
+ export declare function availableJoinTables(schema: DatabaseSchema, pipeline: QueryPipeline): Table[];
239
+ /** Counts leaf conditions in a WHERE/ON-style expression tree (walks through
240
+ * logical/not wrappers) — used for a summary like "3 conditions" in FromPanel/the
241
+ * WHERE canvas's own empty-state affordance. */
242
+ export declare function countConditions(ast: ExpressionNode | undefined): number;
243
+ /** Short human-readable summary of a join's ON condition, for its row in
244
+ * FromPanel — e.g. "sale_transaction.product_id = product.id", "3 conditions",
245
+ * or a not-yet-configured placeholder. */
246
+ export declare function summarizeJoinCondition(on: ExpressionNode | undefined, text?: Pick<Messages, 'setJoinCondition' | 'conditionCount'>): string;
247
+ /** Every table name this pipeline's WHERE clause or any *other* join's own ON
248
+ * condition currently depends on — removing one of these tables from the
249
+ * FROM/JOIN list would leave that reference dangling (pointing at a table no
250
+ * longer in the query), producing broken SQL. Used to decide when a row's
251
+ * own Remove button should be hidden. `excludeJoinId`, when given, leaves
252
+ * that one join's own ON condition out of the scan — removing a join always
253
+ * takes its own condition with it, so that join referencing its own table
254
+ * (or itself referencing another table it's about to stop being joined
255
+ * alongside) is never itself a reason to block its own removal; every
256
+ * *other* join's ON is still scanned regardless. Every SELECT column's own
257
+ * expression is scanned too, unconditionally — nothing analogous to
258
+ * `excludeJoinId` applies there, since removing a table is never done "in
259
+ * favor of" replacing a SELECT column the way it can be for the join
260
+ * losing its own condition. */
261
+ export declare function tablesReferencedElsewhere(pipeline: QueryPipeline, excludeJoinId?: string): Set<string>;
262
+ /** Given the pipeline just before an edit and the new WHERE tree just after it,
263
+ * auto-adds any table newly referenced by a field in `nextWhere` (see
264
+ * addReferencedTables) — folded into the same pipeline update so it's one
265
+ * undo step, not two. Never driven by a join's own ON condition (see the
266
+ * FROM-clause design plan). */
267
+ export declare function applyWhereChange(schema: DatabaseSchema, pipeline: QueryPipeline, nextWhere: ExpressionNode | undefined): QueryPipeline;
268
+ /** applyPipelineAction on the query at `path` — the whole query, or a
269
+ * derived table's (see derivedTables.ts). A derived table's query keeps a
270
+ * base table: an action that would leave it with none does nothing. */
271
+ export declare function applyPipelineActionAt(schema: DatabaseSchema, prev: QueryValue, path: QueryPath, action: PipelineAction): QueryValue;