@nongt/visql 0.0.0-stage → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (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-CBN6rAQG.js +1052 -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,98 @@
1
+ import type { ExpressionNode, SubqueryNode } from './ast.js';
2
+ import { type FunctionRegistry } from './functionRegistry.js';
3
+ import { type DerivedFrom, type DerivedJoin, type DerivedQuery, type FromClause, type JoinClause, type NestedQuery, type QueryBody, type QueryPipeline, type QueryValue, type SharedFrom, type SharedJoin, type SharedQuery } from './queryAst.js';
4
+ import { type DatabaseSchema, type Table, type TableColumn } from './schema.js';
5
+ /** Where a query sits: the ids of the derived tables (a base or a join)
6
+ * leading to it from the whole query, outermost first. [] is the whole
7
+ * query. A union's branch is its derived table's id and its index,
8
+ * `id#1` (see branchStep). */
9
+ export type QueryPath = string[];
10
+ export declare const TOP_QUERY: QueryPath;
11
+ /** A derived table of a query: its base or one of its joins. */
12
+ export type Derived = DerivedFrom | DerivedJoin;
13
+ /** A query's derived tables, in order: its base when it is one, then its
14
+ * derived joins. */
15
+ export declare function derivedOf(query: Pick<DerivedQuery, 'from' | 'joins'>): Derived[];
16
+ /** A place using a shared query (issue 194): a base or a join. */
17
+ export type SharedUse = SharedFrom | SharedJoin;
18
+ /** The query a table of a query reads, when it's no schema table: a
19
+ * derived table's own, or the shared query it uses (from `shared`, the
20
+ * whole query's). */
21
+ export declare function nestedQueryOf(t: FromClause | JoinClause, shared?: readonly SharedQuery[]): NestedQuery | undefined;
22
+ /** A query's sub queries (IN's right sides, issue 122), in order: those in its
23
+ * own expression trees — inside an EXISTS's conditions too — not its
24
+ * derived tables' or other sub queries'. */
25
+ export declare function subqueriesOf(query: QueryBody): SubqueryNode[];
26
+ /** `query` with each of its sub queries (see subqueriesOf) as `update`
27
+ * makes it — the same object when that changes none. */
28
+ export declare function mapSubqueries<Q extends QueryBody>(query: Q, update: (subquery: SubqueryNode) => SubqueryNode): Q;
29
+ /** A union's branch as a QueryPath step: its derived table's id, `#`, its
30
+ * index. */
31
+ export declare const branchStep: (id: string, index: number) => string;
32
+ /** One branch of a derived table's union (issue 121), reached by a
33
+ * QueryPath step `id#index`: named like the derived table. */
34
+ export interface UnionBranch {
35
+ id: string;
36
+ alias: string;
37
+ query: DerivedQuery;
38
+ /** The derived table whose union it's in. */
39
+ of: Derived;
40
+ index: number;
41
+ }
42
+ /** Whether a QueryPath step's query is a union's branch. */
43
+ export declare function isUnionBranch(nested: Derived | SubqueryNode | UnionBranch): nested is UnionBranch;
44
+ /** A query nested in `query` by its id — a QueryPath step: one of its
45
+ * derived tables, one of its shared queries (the whole query's), one of
46
+ * its sub queries, or a branch of a derived table's union (`id#index`).
47
+ * A derived table that's a union is no query of its own: only its
48
+ * branches are. */
49
+ export declare function nestedAt(query: QueryBody, id: string): Derived | SubqueryNode | UnionBranch | undefined;
50
+ /** The query at `path` in `query` (a derived table's as a pipeline, see
51
+ * asPipeline), or undefined when the path no longer leads to one. */
52
+ export declare function queryAt(query: QueryPipeline | undefined, path: QueryPath): QueryPipeline | undefined;
53
+ /** `query` with the query at `path` replaced by what `update` makes of it.
54
+ * The whole query may become empty (no base table left); a derived table
55
+ * can't, so such an update leaves it as it was. Unchanged when the path
56
+ * doesn't lead to a query. */
57
+ export declare function updateQueryAt(query: QueryPipeline, path: QueryPath, update: (q: QueryPipeline) => QueryValue): QueryValue;
58
+ /** The columns a derived table's query gives, in order, typed after what
59
+ * they hold. With none picked (SELECT *), every column of its tables —
60
+ * then two can share a name, which validateQuery reports. A union's are
61
+ * its first branch's. `shared`: the whole query's shared queries, for a
62
+ * table that uses one. */
63
+ export declare function derivedColumns(schema: DatabaseSchema, nested: NestedQuery, shared?: readonly SharedQuery[]): TableColumn[];
64
+ /** What a derived table (or a place using a shared query) looks like from
65
+ * outside, as a table: its alias, and its columns (derivedColumns), each
66
+ * name once. */
67
+ export declare function derivedTable(schema: DatabaseSchema, derived: Derived | SharedUse, shared?: readonly SharedQuery[]): Table;
68
+ /** The names the query's own derived tables and shared queries' places go
69
+ * by, with the type each of their columns has (see derivedTable). */
70
+ export declare function derivedTables(schema: DatabaseSchema, query: QueryBody, shared?: readonly SharedQuery[]): Table[];
71
+ /** Whether a derived table's query gives one row at most: it sums up all
72
+ * its rows (every column an aggregate, no GROUP BY) — a total, an average
73
+ * over everything. Such a one joins every row of the query around it
74
+ * (CROSS JOIN) without multiplying them. A union stacks a row per branch
75
+ * at least: never. */
76
+ export declare function singleRow(nested: NestedQuery, registry?: FunctionRegistry): boolean;
77
+ /** `query` with every field naming `from` naming `to` instead — what
78
+ * renaming a table's alias takes. Its derived tables don't see the name
79
+ * (a scope of their own); an EXISTS does, unless one of its own tables
80
+ * goes by it. */
81
+ export declare function renameTableRef<Q extends QueryBody>(query: Q, from: string, to: string): Q;
82
+ /** Every table a relation links to a column of one of `query`'s derived
83
+ * tables, with the ON that link gives it (see derivedJoinOn), in order:
84
+ * derived tables, their columns, the relations. */
85
+ export declare function derivedLinks(schema: DatabaseSchema, query: QueryBody): {
86
+ table: string;
87
+ on: ExpressionNode;
88
+ }[];
89
+ /** What a table joining `query` is matched by when a relation links it to
90
+ * a column of one of the query's derived tables (`store.id =
91
+ * sales.store_id`) — what suggestJoin does with the query's tables, which
92
+ * a derived table isn't one of. Undefined when no relation does. */
93
+ export declare function derivedJoinOn(schema: DatabaseSchema, query: QueryBody, table: string): ExpressionNode | undefined;
94
+ /** What a derived table's ON starts as, in `query`: its column a relation
95
+ * links to a table of the query, matched to that table's column (as a
96
+ * join's ON is suggested) — else its first column, matched to a column to
97
+ * pick. Its own columns on the left: that's what it's joined by. */
98
+ export declare function derivedOnSeed(schema: DatabaseSchema, query: QueryBody, join: DerivedJoin): ExpressionNode;
@@ -0,0 +1,7 @@
1
+ import type { QueryPipeline } from './queryAst.js';
2
+ /** The ORDER BY keys (their ids) that SELECT DISTINCT rules out. With
3
+ * DISTINCT, PostgreSQL, SQL Server and MySQL 8 all reject a sort by
4
+ * anything that isn't selected — so each key has to be one of the SELECT
5
+ * columns, or, when none are picked (SELECT *), a plain column. A key with
6
+ * no column picked yet isn't counted: it's unfinished, not wrong. */
7
+ export default function sortKeysOutsideDistinct(query: QueryPipeline): string[];
@@ -0,0 +1,11 @@
1
+ import type { ExpressionNode } from './ast.js';
2
+ import { type AbsolutePath } from './absolutePath.js';
3
+ import type { DrillLevel } from './DrillDownContext.js';
4
+ /** Reconstruct the minimal drill stack needed to reach `target` under `root` —
5
+ * a DrillLevel per slot (drill-boundary) step, in order. Stops at the first
6
+ * step that no longer resolves to a valid drill target (e.g. a structural
7
+ * change elsewhere invalidated part of the path); the caller lands as deep
8
+ * as still resolves. Plain structural (operand-index) hops aren't boundaries
9
+ * on their own — they're just graph edges within whichever canvas they sit in. */
10
+ export declare function pathToDrillLevels(root: ExpressionNode | undefined, target: AbsolutePath): DrillLevel[];
11
+ export default pathToDrillLevels;
@@ -0,0 +1,7 @@
1
+ import type { ExistsNode, ExistsQuery, ExpressionNode, FieldNode } from './ast.js';
2
+ /** The names an EXISTS's own tables go by inside it (alias, else table). */
3
+ export declare function existsTables(query: ExistsQuery): Set<string>;
4
+ /** Whether `node` has an EXISTS anywhere in it. */
5
+ export declare function containsExists(node: ExpressionNode | undefined): boolean;
6
+ /** The fields an EXISTS's link names on the outer query's side. */
7
+ export declare function outerFields(node: ExistsNode): FieldNode[];
@@ -0,0 +1,61 @@
1
+ import type { ExistsNode, ExistsQuery, ExpressionNode } from './ast.js';
2
+ import { type AbsolutePath } from './absolutePath.js';
3
+ import { type FromClause, type JoinClause } from './queryAst.js';
4
+ import { type DatabaseSchema, type Table } from './schema.js';
5
+ /** Which related tables the EXISTS menu lists: 'toMany' those whose rows
6
+ * point at a row of the query (has leave requests), 'both' also those a
7
+ * row of the query points at (has a store). */
8
+ export type ExistsRelations = 'toMany' | 'both';
9
+ /** Where the editor offers the EXISTS button: WHERE's conditions, HAVING's,
10
+ * a join's ON. */
11
+ export type ExistsPlace = 'where' | 'having' | 'joinOn';
12
+ /** PipelineEditor's `exists` option: what the editor offers. An EXISTS
13
+ * already in a query is shown and editable wherever it is. */
14
+ export interface ExistsOptions {
15
+ /** Default 'toMany'. */
16
+ relations?: ExistsRelations;
17
+ /** Default ['where', 'having']; [] turns the button off. */
18
+ in?: ExistsPlace[];
19
+ }
20
+ /** A table as a query names it: by its alias, else its own name (`ref`). */
21
+ export interface ScopeTable {
22
+ ref: string;
23
+ table: Table;
24
+ }
25
+ /** One entry of the EXISTS menu: picking it adds `exists`. */
26
+ export interface ExistsCandidate {
27
+ key: string;
28
+ table: Table;
29
+ /** The foreign key's column label, when the menu lists `table` more than
30
+ * once ("by Approver"). */
31
+ via?: string;
32
+ exists: ExistsNode;
33
+ }
34
+ /** The related tables an EXISTS can look for, from a query with tables
35
+ * `outer`: one entry per relation and table of the query it links to. Each
36
+ * comes with its link (`inner.fk = outer.key`), and an alias when its name
37
+ * is one the query already uses (or `taken`: the queries around it). */
38
+ export declare function existsCandidates(schema: DatabaseSchema, outer: (FromClause | JoinClause)[], relations?: ExistsRelations, taken?: Iterable<string>): ExistsCandidate[];
39
+ /** How an EXISTS's node reads its link: the label of the table of the query
40
+ * it links to, and the foreign key's column label. Undefined for a link
41
+ * that isn't one equality between a column inside and one outside. */
42
+ export declare function describeLink(schema: DatabaseSchema, node: ExistsNode, outer?: ScopeTable[]): {
43
+ table: string;
44
+ via: string;
45
+ } | undefined;
46
+ /** The tables named in `tables`, as ScopeTables (an unknown one, or a
47
+ * derived table, left out). */
48
+ export declare function scopeTables(schema: DatabaseSchema, tables: (FromClause | JoinClause)[]): ScopeTable[];
49
+ /** The tables a field inside an EXISTS may name: its own, then every table
50
+ * the relations reach from them (picking one joins it inside), except
51
+ * those named like a table of a query around it (`taken`) and those only
52
+ * reached through one — inside, that name would be ambiguous. */
53
+ export declare function existsFieldTables(schema: DatabaseSchema, query: ExistsQuery, taken: Set<string>): ScopeTable[];
54
+ /** The innermost EXISTS whose conditions `path` (in the tree `root`) goes
55
+ * into, with the names the queries around those conditions use: `outer`
56
+ * (the query's own) and each enclosing EXISTS's. Undefined when the path
57
+ * doesn't go into one. */
58
+ export declare function existsAt(root: ExpressionNode | undefined, path: AbsolutePath, outer: string[]): {
59
+ node: ExistsNode;
60
+ taken: Set<string>;
61
+ } | undefined;
@@ -0,0 +1,428 @@
1
+ import type { Edge, Node } from '@xyflow/react';
2
+ import type { BinaryNode, CaseNode, ExistsNode, ExpressionNode, FunctionCallNode, FunctionSortKey, LogicalNode, NotNode } from './ast.js';
3
+ import { type AbsolutePath } from './absolutePath.js';
4
+ import { type ArgDef, type FunctionRegistry } from './functionRegistry.js';
5
+ /** 'rtl': children left, operator right (grows left on add)
6
+ * 'ltr': operator left, children right (grows right on add) */
7
+ export type FlowDirection = 'ltr' | 'rtl';
8
+ /** The default direction — PipelineEditor's `direction` prop picks another
9
+ * (see FlowDirectionContext). */
10
+ export declare const FLOW_DIRECTION: FlowDirection;
11
+ /** Which way the main canvas's chain flows (PipelineEditor's `orientation`
12
+ * prop, issue 188): 'horizontal' — FROM → WHERE → … side by side, the default —
13
+ * or 'vertical', each section below the last. Apart from `direction`: that
14
+ * says which side things start from, in either. */
15
+ export type FlowOrientation = 'horizontal' | 'vertical';
16
+ export declare const FLOW_ORIENTATION: FlowOrientation;
17
+ /** Set on root nodes of the main canvas (never a drilled sub-canvas) to let the
18
+ * node offer deleting itself — and everything nested under it — outright,
19
+ * clearing the whole query back to the empty state. */
20
+ export interface RootDeletable {
21
+ allowRootDelete?: boolean;
22
+ }
23
+ export interface ConditionNodeData extends Record<string, unknown>, RootDeletable {
24
+ binary: BinaryNode;
25
+ path: number[];
26
+ siblingCount: number;
27
+ direction: FlowDirection;
28
+ dispatch: FlowDispatch;
29
+ /** The canvas's top node although not at path [] — its only parent
30
+ * groups were collapsed (see `collapseSingle`) — so FROM/SELECT attach
31
+ * here. */
32
+ anchor?: boolean;
33
+ }
34
+ /** An EXISTS: a leaf on the condition canvas, like a comparison. */
35
+ export interface ExistsNodeData extends Record<string, unknown>, RootDeletable {
36
+ exists: ExistsNode;
37
+ path: number[];
38
+ siblingCount: number;
39
+ direction: FlowDirection;
40
+ dispatch: FlowDispatch;
41
+ /** As ConditionNodeData's. */
42
+ anchor?: boolean;
43
+ }
44
+ export interface NotNodeData extends Record<string, unknown>, RootDeletable {
45
+ not: NotNode;
46
+ path: number[];
47
+ siblingCount: number;
48
+ direction: FlowDirection;
49
+ dispatch: FlowDispatch;
50
+ }
51
+ export interface CaseBranch {
52
+ when: ExpressionNode;
53
+ then: ExpressionNode;
54
+ }
55
+ /**
56
+ * Path encoding convention:
57
+ *
58
+ * case / if nodes sit at the same level as binary/logical/not in the logical tree.
59
+ * Their `path` follows the same convention (numeric indices through logical.operands
60
+ * and not.operand). Branch-level operations use a separate `index` parameter —
61
+ * branch indices are NOT embedded in the path, keeping path[] clean.
62
+ *
63
+ * case node at path [1, 0] → logical.operands[1].operands[0] (a CaseNode)
64
+ * branch 2 of that case → path=[1,0], index=2
65
+ */
66
+ /** Header pill for an IF node — shows the condition expression. */
67
+ export interface IfNodeData extends Record<string, unknown>, RootDeletable {
68
+ condition: ExpressionNode;
69
+ hasElse: boolean;
70
+ path: number[];
71
+ siblingCount: number;
72
+ direction: FlowDirection;
73
+ dispatch: FlowDispatch;
74
+ }
75
+ /** The THEN branch card — shows the then expression. */
76
+ export interface IfThenNodeData extends Record<string, unknown> {
77
+ then: ExpressionNode;
78
+ ifPath: number[];
79
+ direction: FlowDirection;
80
+ dispatch: FlowDispatch;
81
+ }
82
+ /** The ELSE card — always last, not reorderable. */
83
+ export interface IfElseNodeData extends Record<string, unknown> {
84
+ else: ExpressionNode;
85
+ ifPath: number[];
86
+ direction: FlowDirection;
87
+ dispatch: FlowDispatch;
88
+ }
89
+ export interface CaseNodeData extends Record<string, unknown>, RootDeletable {
90
+ case: CaseNode;
91
+ path: number[];
92
+ siblingCount: number;
93
+ direction: FlowDirection;
94
+ dispatch: FlowDispatch;
95
+ }
96
+ /** One WHEN/THEN branch card in the flow.
97
+ * casePath — path to the parent CaseNode (for branch mutations).
98
+ * branchIndex — index within CaseNode.branches[].
99
+ * branchCount — total branches (controls up/down availability).
100
+ * caseSiblingCount — sibling count of the CaseNode itself (for moving the whole case).
101
+ */
102
+ export interface CaseBranchNodeData extends Record<string, unknown> {
103
+ branch: CaseBranch;
104
+ branchIndex: number;
105
+ branchCount: number;
106
+ casePath: number[];
107
+ caseSiblingCount: number;
108
+ /** Virtual path used by the drag system: [...casePath, branchIndex]. */
109
+ path: number[];
110
+ direction: FlowDirection;
111
+ dispatch: FlowDispatch;
112
+ }
113
+ /** The ELSE card — always last, not reorderable, at most one per CaseNode. */
114
+ export interface CaseElseNodeData extends Record<string, unknown> {
115
+ else: ExpressionNode;
116
+ casePath: number[];
117
+ direction: FlowDirection;
118
+ dispatch: FlowDispatch;
119
+ }
120
+ export type FlowAction = {
121
+ type: 'change';
122
+ path: number[];
123
+ exp: ExpressionNode | undefined;
124
+ } | {
125
+ type: 'addCondition';
126
+ path: number[];
127
+ } | {
128
+ type: 'addGroup';
129
+ path: number[];
130
+ } | {
131
+ type: 'reorder';
132
+ parentPath: number[];
133
+ index: number;
134
+ direction: 'up' | 'down';
135
+ } | {
136
+ type: 'move';
137
+ parentPath: number[];
138
+ fromIndex: number;
139
+ toIndex: number;
140
+ } | {
141
+ type: 'wrap';
142
+ path: number[];
143
+ } | {
144
+ type: 'unwrap';
145
+ path: number[];
146
+ } | {
147
+ type: 'wrapNot';
148
+ path: number[];
149
+ } | {
150
+ type: 'wrapRoot';
151
+ } | {
152
+ type: 'crossMove';
153
+ sourcePath: number[];
154
+ targetParentPath: number[];
155
+ targetIndex: number;
156
+ } | {
157
+ type: 'addBranch';
158
+ path: number[];
159
+ } | {
160
+ type: 'removeBranch';
161
+ path: number[];
162
+ index: number;
163
+ } | {
164
+ type: 'reorderBranch';
165
+ path: number[];
166
+ index: number;
167
+ direction: 'up' | 'down';
168
+ } | {
169
+ type: 'moveBranch';
170
+ casePath: number[];
171
+ fromIndex: number;
172
+ toIndex: number;
173
+ } | {
174
+ type: 'changeBranch';
175
+ path: number[];
176
+ index: number;
177
+ branch: CaseBranch;
178
+ } | {
179
+ type: 'changeCaseElse';
180
+ path: number[];
181
+ else: ExpressionNode | undefined;
182
+ } | {
183
+ type: 'changeIfCondition';
184
+ path: number[];
185
+ condition: ExpressionNode;
186
+ } | {
187
+ type: 'changeIfThen';
188
+ path: number[];
189
+ then: ExpressionNode;
190
+ } | {
191
+ type: 'changeIfElse';
192
+ path: number[];
193
+ else: ExpressionNode | undefined;
194
+ } | {
195
+ type: 'addCase';
196
+ path: number[];
197
+ } | {
198
+ type: 'addIf';
199
+ path: number[];
200
+ } | {
201
+ type: 'addExists';
202
+ path: number[];
203
+ exists: ExistsNode;
204
+ };
205
+ export type FlowDispatch = (action: FlowAction) => void;
206
+ export interface LogicalNodeData extends Record<string, unknown>, RootDeletable {
207
+ logical: LogicalNode;
208
+ path: number[];
209
+ siblingCount: number;
210
+ direction: FlowDirection;
211
+ dispatch: FlowDispatch;
212
+ }
213
+ export interface FlowGraph {
214
+ nodes: Node[];
215
+ edges: Edge[];
216
+ }
217
+ /** The node the canvas actually shows on top — the AST root, or, with
218
+ * `collapseSingle`, the first node under any collapsed groups — and its
219
+ * path. FROM/SELECT attach to it. */
220
+ export declare function effectiveRoot(exp: ExpressionNode, collapseSingle?: boolean): {
221
+ exp: ExpressionNode;
222
+ path: number[];
223
+ };
224
+ /** React Flow id of the node at `path` (same scheme as expressionToFlow). */
225
+ export declare const flowNodeId: (path: number[]) => string;
226
+ /** The condition-canvas nodes (expressionToFlow) on the way to the spot
227
+ * `path` names, outermost first: the groups and condition down its
228
+ * operand steps, then an IF's THEN/ELSE or a CASE's branch/ELSE card when
229
+ * the path goes into one. A spot inside a node's own slots (a comparison's
230
+ * sides, an IF's condition) is that node. */
231
+ export declare function conditionFlowNodeIds(path: AbsolutePath): string[];
232
+ export declare function expressionToFlow(exp: ExpressionNode, dispatch: FlowDispatch, allowRootDelete?: boolean, collapseSingle?: boolean, direction?: FlowDirection): FlowGraph;
233
+ export interface Size {
234
+ width: number;
235
+ height: number;
236
+ }
237
+ export interface LayoutBox {
238
+ width: number;
239
+ height: number;
240
+ nodeOffsetX: number;
241
+ nodeOffsetY: number;
242
+ childBoxes?: LayoutBox[];
243
+ childOffsets?: {
244
+ x: number;
245
+ y: number;
246
+ }[];
247
+ }
248
+ /**
249
+ * Compute a group layout box (shared by logical and not nodes).
250
+ * parentSize: the size of the parent node itself (logical pill / not pill).
251
+ * childBoxes: already-computed boxes for each child.
252
+ */
253
+ export declare function computeGroupBox(parentSize: Size, childBoxes: LayoutBox[], direction?: FlowDirection): LayoutBox;
254
+ /**
255
+ * Offset to translate an "anchor" subtree (the "+" create-condition node, or
256
+ * the WHERE tree's own already-laid-out output) by, so it sits immediately
257
+ * beside the FROM node, with its own vertical center landing on world y=0 —
258
+ * a shared center line FROM's own position is *also* built around
259
+ * (FlowCanvas.tsx's `fromNode`: `y: -fromSize.height / 2`, not a hardcoded
260
+ * 0). Centering both sides against a fixed line, rather than centering the
261
+ * anchor against FROM's *current* height directly, is what keeps them
262
+ * mutually aligned no matter which side's height changes: FROM growing or
263
+ * shrinking (adding/removing a table) re-centers FROM itself around that
264
+ * same fixed line instead of only ever growing downward from a pinned top
265
+ * (which would otherwise visibly shift the whole canvas down on every
266
+ * table add). `x` is still measured from FROM's own origin (so callers add
267
+ * it straight onto every anchor-subtree node's own position).
268
+ *
269
+ * ltr: anchor sits to FROM's right, offset by FROM's own width — needs only
270
+ * fromSize.
271
+ * rtl: anchor sits to FROM's left, offset by the ANCHOR's own width (so its
272
+ * right edge lands GAP_X left of FROM's left edge at x=0) — needs only
273
+ * anchorSize.
274
+ *
275
+ * Callers whose anchor isn't already positioned at local (0, 0) — the WHERE
276
+ * tree's own root node, whose un-translated position within its own
277
+ * `layoutFlow` output is generally *not* (0, 0) (`computeGroupBox` centers
278
+ * a group's own pill against its *own* children column — GROUP_PAD alone
279
+ * already shifts it once padding is non-zero, and it shifts further still
280
+ * once the children column is taller than the pill) — must additionally
281
+ * subtract that local position from this function's own `y` before
282
+ * applying it; see FlowCanvas.tsx's own `rootLaidOutPos` correction for
283
+ * exactly that case (confirmed directly: without it, root visibly drifted
284
+ * further from FROM's own center as more sibling conditions were added).
285
+ *
286
+ * Exported so both directions can be unit tested directly.
287
+ */
288
+ export declare function computeFromAnchorOffset(fromSize: Size, anchorSize: Size, direction?: FlowDirection): {
289
+ x: number;
290
+ y: number;
291
+ };
292
+ export declare function layoutFlow(rawNodes: Node[], // nodes derived from current AST (defines what nodes should exist)
293
+ prevNodes: Node[], // previous ReactFlow nodes (carries measured dimensions)
294
+ ast: ExpressionNode, collapseSingle?: boolean, // must match what expressionToFlow was given
295
+ direction?: FlowDirection): Node[];
296
+ /** Add a new operand to the LogicalNode at the given path. */
297
+ export declare function addOperandAtPath(root: ExpressionNode, path: number[], newOperand: ExpressionNode): ExpressionNode;
298
+ /** Move an operand up/down within the same parent node. */
299
+ export declare function reorderOperandAtPath(root: ExpressionNode, parentPath: number[], index: number, direction: 'up' | 'down'): ExpressionNode;
300
+ /** Wrap the node at path in a LogicalNode(AND). */
301
+ export declare function wrapInLogical(root: ExpressionNode, path: number[]): ExpressionNode;
302
+ /** Wrap the node at path in a NotNode. */
303
+ export declare function wrapInNot(root: ExpressionNode, path: number[]): ExpressionNode;
304
+ /** Unwrap a LogicalNode (single operand) or NotNode at path. */
305
+ export declare function unwrapLogical(root: ExpressionNode, path: number[]): ExpressionNode;
306
+ export declare function updateExpressionAtPath(root: ExpressionNode, path: number[], newExp: ExpressionNode | undefined): ExpressionNode | undefined;
307
+ /** Move an operand from one logical group to another. */
308
+ export declare function crossMoveOperand(root: ExpressionNode, sourcePath: number[], targetParentPath: number[], targetIndex: number): ExpressionNode;
309
+ /** Append an empty WHEN/THEN branch to the CaseNode at `path`. */
310
+ export declare function addBranchAtPath(root: ExpressionNode, path: number[]): ExpressionNode;
311
+ /** Remove branch at `index` from the CaseNode at `path`. */
312
+ export declare function removeBranchAtPath(root: ExpressionNode, path: number[], index: number): ExpressionNode;
313
+ /** Swap branch at `index` with its neighbour (up = index-1, down = index+1). */
314
+ export declare function reorderBranchAtPath(root: ExpressionNode, path: number[], index: number, direction: 'up' | 'down'): ExpressionNode;
315
+ /** Move a branch from one index to another within the CaseNode at `path`. */
316
+ export declare function moveBranchAtPath(root: ExpressionNode, path: number[], fromIndex: number, toIndex: number): ExpressionNode;
317
+ /** Replace the branch at `index` in the CaseNode at `path`. */
318
+ export declare function changeBranchAtPath(root: ExpressionNode, path: number[], index: number, branch: CaseBranch): ExpressionNode;
319
+ /** Set (or clear) the ELSE clause of the CaseNode at `path`. */
320
+ export declare function changeCaseElseAtPath(root: ExpressionNode, path: number[], newElse: ExpressionNode | undefined): ExpressionNode;
321
+ /** Move an operand from one index to another within the same parent. */
322
+ export declare function moveOperandAtPath(root: ExpressionNode, parentPath: number[], fromIndex: number, toIndex: number): ExpressionNode;
323
+ /**
324
+ * Apply a FlowAction to an ExpressionNode tree and return the updated tree.
325
+ * Pure function — used by both PipelineEditor and SubFlowPanel.
326
+ */
327
+ export declare function applyFlowAction(ast: ExpressionNode, action: FlowAction): ExpressionNode;
328
+ /** The structural path a FlowAction most directly touches — used only to decide
329
+ * where to offer post-undo/redo navigation, not for mutation correctness. */
330
+ export declare function flowActionTargetPath(action: FlowAction): AbsolutePath;
331
+ export interface FunctionCallNodeData extends Record<string, unknown> {
332
+ fn: FunctionCallNode;
333
+ /** Path through function.args[] to this function node. [] = root. */
334
+ path: number[];
335
+ direction: FlowDirection;
336
+ dispatch: ExpressionFlowDispatch;
337
+ }
338
+ export interface FunctionArgNodeData extends Record<string, unknown> {
339
+ arg: ExpressionNode;
340
+ /** Full path: [...parentFnPath, argIndex]. */
341
+ path: number[];
342
+ direction: FlowDirection;
343
+ dispatch: ExpressionFlowDispatch;
344
+ /** ArgDef from the function registry, if the parent function is a known function. */
345
+ argDef?: ArgDef;
346
+ /** True when the parent function has no registry signature (free-form). */
347
+ isUnknownFn: boolean;
348
+ isFirst: boolean;
349
+ isLast: boolean;
350
+ }
351
+ export type ExpressionFlowAction =
352
+ /** Change the name of the function at path (typing — does not rebuild args). */
353
+ {
354
+ type: 'exprChangeFnName';
355
+ path: number[];
356
+ name: string;
357
+ }
358
+ /**
359
+ * Select a function by name, replacing its args with registry-generated defaults.
360
+ * Used on explicit dropdown selection so the arg list matches the signature.
361
+ */
362
+ | {
363
+ type: 'exprSelectFn';
364
+ path: number[];
365
+ name: string;
366
+ args: ExpressionNode[];
367
+ }
368
+ /** Replace the arg at path (path = [...parentFnPath, argIndex]). */
369
+ | {
370
+ type: 'exprChangeArg';
371
+ path: number[];
372
+ exp: ExpressionNode;
373
+ }
374
+ /** Append a new literal arg to the function at path. */
375
+ | {
376
+ type: 'exprAddArg';
377
+ path: number[];
378
+ }
379
+ /** Remove the arg at path (path = [...parentFnPath, argIndex]). */
380
+ | {
381
+ type: 'exprRemoveArg';
382
+ path: number[];
383
+ }
384
+ /** Move the arg at path one step up or down within its parent's args list. */
385
+ | {
386
+ type: 'exprReorderArg';
387
+ path: number[];
388
+ direction: 'up' | 'down';
389
+ }
390
+ /** Move the arg at path to an explicit index within its parent's args list (used by drag). */
391
+ | {
392
+ type: 'exprMoveArgToIndex';
393
+ path: number[];
394
+ toIndex: number;
395
+ }
396
+ /** What the COUNT at path counts (see CountMode). */
397
+ | {
398
+ type: 'exprSetCount';
399
+ path: number[];
400
+ mode: CountMode;
401
+ }
402
+ /** Whether the aggregate at path takes only different values
403
+ * (`STRING_AGG(DISTINCT x)`). */
404
+ | {
405
+ type: 'exprSetDistinct';
406
+ path: number[];
407
+ distinct: boolean;
408
+ }
409
+ /** The order the aggregate at path takes its values in (STRING_AGG's
410
+ * ORDER BY); empty removes it. */
411
+ | {
412
+ type: 'exprSetOrderBy';
413
+ path: number[];
414
+ orderBy: FunctionSortKey[];
415
+ };
416
+ /** What a COUNT counts: every row (`COUNT(*)`, no argument), the rows
417
+ * where a value is set (`COUNT(x)`), or the different values
418
+ * (`COUNT(DISTINCT x)`). */
419
+ export type CountMode = 'rows' | 'values' | 'distinct';
420
+ export declare function countMode(fn: FunctionCallNode): CountMode;
421
+ export type ExpressionFlowDispatch = (action: ExpressionFlowAction) => void;
422
+ export declare function applyExpressionFlowAction(ast: ExpressionNode, action: ExpressionFlowAction): ExpressionNode;
423
+ /** The function-canvas nodes (expressionToFunctionFlow) on the way to the
424
+ * spot `path` names, outermost first: each call down its argument steps,
425
+ * and the argument itself (a call's node, or a leaf argument's). */
426
+ export declare function functionFlowNodeIds(path: AbsolutePath): string[];
427
+ export declare function expressionToFunctionFlow(ast: ExpressionNode, dispatch: ExpressionFlowDispatch, functions?: FunctionRegistry, direction?: FlowDirection): FlowGraph;
428
+ export declare function layoutFunctionFlow(rawNodes: Node[], prevNodes: Node[], ast: ExpressionNode, direction?: FlowDirection): Node[];