@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,119 @@
1
+ import type { ExpressionNode } from './ast.js';
2
+ import type { JoinType } from './queryAst.js';
3
+ export type DatabaseColumnType = 'varchar' | 'decimal' | 'integer' | 'date' | 'dateTime'
4
+ /** A time of day (issue 130). */
5
+ | 'time'
6
+ /** Yes / no (issue 130). */
7
+ | 'boolean';
8
+ export interface Table {
9
+ name: string;
10
+ label: string;
11
+ columns: TableColumn[];
12
+ }
13
+ export interface TableColumn {
14
+ name: string;
15
+ label: string;
16
+ type: DatabaseColumnType;
17
+ nullable?: boolean;
18
+ /** A fixed set of allowed values (an enum, a status…). Values compared
19
+ * against this column are then picked from a dropdown instead of typed. */
20
+ options?: ColumnOption[];
21
+ /** A date, date-and-time or time column the database keeps as text in a
22
+ * form of its own: `'HH:mm'` for a time stored as `09:30`, `'YYYYMMDD'`
23
+ * for a day stored as `20261003`. Tokens: `YYYY`, `MM` (month), `DD`,
24
+ * `HH`, `mm` (minute), `ss`; the rest as it is. Users still pick a date
25
+ * or a time; the SQL writes what's compared with the column in this
26
+ * form (astToSql's / astToParameterizedSql's `schema` option). Ordering
27
+ * (`<`, `>`) compares the text: only a form from the largest unit down
28
+ * (`YYYY-MM-DD`, `HH:mm`) orders as the dates and times do. */
29
+ format?: string;
30
+ }
31
+ export interface ColumnOption {
32
+ value: string | number;
33
+ label: string;
34
+ }
35
+ /** One foreign key, declared once: `fromTable.fromColumn` references
36
+ * `toTable.toColumn` — so the `from` side is the "many" side (e.g.
37
+ * sale_transaction.product_id → product.id). The reverse direction
38
+ * (product → its sales) is derived wherever it's needed; never declare it as
39
+ * a second entry (validateSchema reports that as a duplicate). Single-column
40
+ * keys only. */
41
+ export interface Relation {
42
+ fromTable: string;
43
+ fromColumn: string;
44
+ toTable: string;
45
+ toColumn: string;
46
+ }
47
+ /** Everything the builder knows about the database it's building queries for —
48
+ * supplied by the host app (PipelineEditor's `schema` prop, distributed to
49
+ * components via SchemaContext) rather than baked into this package. Every
50
+ * lookup helper below takes one as its first argument instead of reading a
51
+ * module-level constant, so two editors on the same page can each work
52
+ * against a different database.
53
+ *
54
+ * `relations` lists each foreign key once (see Relation). */
55
+ export interface DatabaseSchema {
56
+ tables: Table[];
57
+ relations: Relation[];
58
+ }
59
+ /** No tables, no relations — SchemaContext's fallback when no provider is
60
+ * mounted, so a component rendered outside PipelineEditor degrades to empty
61
+ * pickers rather than crashing. */
62
+ export declare const EMPTY_SCHEMA: DatabaseSchema;
63
+ /** The part of `schema` a user may see: tables passing `tableFilter`, their
64
+ * columns passing `columnFilter`, and only relations between two visible
65
+ * tables (so no automatic join ever routes through a hidden one). With no
66
+ * filters it returns `schema` itself. */
67
+ export declare function filterSchema(schema: DatabaseSchema, tableFilter?: (table: Table) => boolean, columnFilter?: (table: Table, column: TableColumn) => boolean): DatabaseSchema;
68
+ /** Every table in the schema, sorted by label — the canonical source for both
69
+ * FieldView's column picker and FromFlowNode's table pickers. */
70
+ export declare function allTables(schema: DatabaseSchema): Table[];
71
+ export declare function findTable(schema: DatabaseSchema, name: string): Table | undefined;
72
+ /** Every foreign key touching `tableName`, in either direction — whether it
73
+ * holds the key or is referenced by one. */
74
+ export declare function relationsForTable(schema: DatabaseSchema, tableName: string): Relation[];
75
+ /** The foreign key between two tables, if one exists, regardless of argument
76
+ * order — the returned record itself says which side holds the key
77
+ * (`fromTable`), so callers never need to know which side is "many". When
78
+ * several keys connect the same two tables, the first declared wins. */
79
+ export declare function findRelation(schema: DatabaseSchema, tableA: string, tableB: string): Relation | undefined;
80
+ /** Shortest chain of tables connecting `target` to any of `existingTables`
81
+ * through the relation graph (walked in both directions), as the tables that
82
+ * would need to be added — in join order, intermediates first, ending with
83
+ * `target` itself. e.g. from [sale_transaction] to product_category that's
84
+ * [product, product_category]: product_category has no relation to
85
+ * sale_transaction directly, only through product. Breadth-first from every
86
+ * existing table at once (seeded in `existingTables` order, neighbours in
87
+ * `relations` order), so the result is deterministic and never longer than
88
+ * needed. Returns [] when `target` is already present, undefined when
89
+ * nothing connects it. */
90
+ export declare function findJoinPath(schema: DatabaseSchema, existingTables: string[], target: string): string[] | undefined;
91
+ /** Every table the relation graph (walked in both directions) reaches from
92
+ * `existingTables`, them included — what findJoinPath finds a path to,
93
+ * for all tables in one walk. */
94
+ export declare function reachableTables(schema: DatabaseSchema, existingTables: string[]): Set<string>;
95
+ export interface JoinSuggestion {
96
+ joinType: JoinType;
97
+ on: ExpressionNode;
98
+ }
99
+ /** Suggests a join type + ON condition for adding `newTable` alongside the tables
100
+ * already in the pipeline, using the relation graph. Tries each existing table in
101
+ * order (base table first, then join-insertion order) — first relation found wins,
102
+ * so the result is deterministic. `joinType` defaults to 'left' when the relation's
103
+ * FK column (`fromColumn`) is nullable (e.g. sale_transaction.promotion_id — an INNER
104
+ * join there would silently drop unpromoted sales) and 'inner' otherwise, read
105
+ * directly off the column's own `nullable` flag rather than hardcoded per-relation.
106
+ * Returns undefined if no relation connects `newTable` to anything already present. */
107
+ export declare function suggestJoin(schema: DatabaseSchema, existingTables: string[], newTable: string): JoinSuggestion | undefined;
108
+ export type SchemaIssueKind = 'duplicateTable' | 'duplicateColumn' | 'unknownTable' | 'unknownColumn' | 'duplicateRelation' | 'invalidFormat';
109
+ export interface SchemaIssue {
110
+ kind: SchemaIssueKind;
111
+ message: string;
112
+ }
113
+ /** Structural problems in a host-supplied schema — duplicate table/column
114
+ * names, relations pointing at tables/columns that don't exist, and the same
115
+ * foreign key declared twice (including once in each direction, the shape
116
+ * the old manyToOne + oneToMany format used). An empty array means the
117
+ * schema is safe to hand to PipelineEditor. Two *different* keys between the
118
+ * same pair of tables (e.g. billing_user_id and shipping_user_id) are fine. */
119
+ export declare function validateSchema(schema: DatabaseSchema): SchemaIssue[];
@@ -0,0 +1,45 @@
1
+ import type { ExpressionNode } from './ast.js';
2
+ import { type QueryPipeline } from './queryAst.js';
3
+ import { type DatabaseSchema } from './schema.js';
4
+ /** What must be scoped, and how. */
5
+ export interface ScopeRule {
6
+ /** The schema tables that must be scoped (e.g. every fact carrying a
7
+ * facility), by name. */
8
+ requires: (table: string) => boolean;
9
+ /** The condition, naming tables every scoped table reaches through the
10
+ * relations (the facility dimension, say) — params rather than values. */
11
+ condition: ExpressionNode;
12
+ }
13
+ /** A query body that reads a table needing scope but can't reach the
14
+ * condition's tables (scopeQuery). */
15
+ export declare class ScopeError extends Error {
16
+ /** Where the body is, as keys into the query (validateQuery's
17
+ * `pathSegments` style). */
18
+ readonly path: (string | number)[];
19
+ /** The table it reads that needs scope. */
20
+ readonly table: string;
21
+ constructor(path: (string | number)[], table: string, missing: string);
22
+ }
23
+ /** `query` with `rule.condition` in **every** body that reads a table
24
+ * `rule.requires` accepts (issue 151): the query itself, each derived
25
+ * table's query (each of a union's), each IN sub query and each EXISTS, at
26
+ * any depth. In each, it's ANDed into WHERE and the tables it names are
27
+ * joined through the relations (as addCondition does).
28
+ * - A body reading no such table is left alone.
29
+ * - A body that has the condition already is left alone, so scoping twice
30
+ * adds nothing.
31
+ * - A measure kept in step gets it as the report's filter (copied), so it
32
+ * stays in step.
33
+ * - Throws a ScopeError, changing nothing, when a body reads such a table
34
+ * but can't reach the condition's tables: never skips it, since a body
35
+ * left out is exactly the leak.
36
+ * Call it after validateQuery, on the checked query. */
37
+ export declare function scopeQuery(schema: DatabaseSchema, query: QueryPipeline, rule: ScopeRule): QueryPipeline;
38
+ /** Every body of `query` that reads a table `rule.requires` accepts without
39
+ * `rule.condition` ANDed at the top of its WHERE — where it is, and the
40
+ * table. Empty: `query` is scoped everywhere (see scopeQuery). For a query
41
+ * built or received some other way. */
42
+ export declare function unscopedBodies(query: QueryPipeline, rule: ScopeRule): {
43
+ path: (string | number)[];
44
+ table: string;
45
+ }[];
@@ -0,0 +1,23 @@
1
+ import type { ExpressionNode } from './ast.js';
2
+ import type { FunctionRegistry } from './functionRegistry.js';
3
+ import type { QueryBody, SelectItem } from './queryAst.js';
4
+ /** The SELECT columns HAVING and a sort key can pick by name: those that
5
+ * sum something up. A plain column there is a group key, picked as a
6
+ * field. */
7
+ export declare function aggregateColumns(query: QueryBody, registry: FunctionRegistry): SelectItem[];
8
+ /** What picking `item` puts in: a copy of its formula, marked with it. */
9
+ export declare function copyOfColumn(item: SelectItem): ExpressionNode;
10
+ /** `node` without the mark of a column copy — to compare it with the
11
+ * column's own formula. */
12
+ export declare function unmarked(node: ExpressionNode): ExpressionNode;
13
+ /** `query` with its HAVING's and sort keys' column copies following their
14
+ * columns: changed with them, and left as a plain formula once the column
15
+ * is gone or sums nothing up any more. The same object when nothing
16
+ * changes. */
17
+ export declare function followColumnCopies<Q extends QueryBody>(query: Q, registry: FunctionRegistry): Q;
18
+ /** For MySQL, which takes a SELECT alias in HAVING and ORDER BY: `node`
19
+ * with each column copy that still matches a named column written as
20
+ * that name (a field with no table: just the name). Not when the name is
21
+ * also a GROUP BY key's column: MySQL would read it as the column there.
22
+ * PostgreSQL and SQL Server keep the formula. */
23
+ export declare function aliasColumnCopies(node: ExpressionNode, query: QueryBody): ExpressionNode;
@@ -0,0 +1,11 @@
1
+ import { type FunctionRegistry } from './functionRegistry.js';
2
+ import { type QueryValue } from './queryAst.js';
3
+ import type { DatabaseSchema } from './schema.js';
4
+ /** What every edit of a query goes through, in the same step: HAVING's and
5
+ * sort keys' copies of SELECT columns following them (followColumnCopies),
6
+ * rows grouped automatically where a column needs it (groupAutomatically),
7
+ * unions' branches lined up (keepUnionsAligned), then measures kept in step
8
+ * with their report (keepMeasuresInStep), at every level. The editor
9
+ * applies it to every edit; the code helpers (addSelectItem, addGroupBy,
10
+ * addCondition, …) do too. */
11
+ export default function settleQuery(schema: DatabaseSchema, previous: QueryValue | undefined, next: QueryValue, registry?: FunctionRegistry): QueryValue;
@@ -0,0 +1,66 @@
1
+ import { type DatabaseSchema } from './schema.js';
2
+ import { type JoinType, type NestedQuery, type QueryBody, type QueryPipeline, type SharedQuery } from './queryAst.js';
3
+ import { type QueryPath } from './derivedTables.js';
4
+ import type { ExpressionNode } from './ast.js';
5
+ type Segments = (string | number)[];
6
+ /** Where each shared query is used in `query`, by id: each place's path
7
+ * (validateQuery's `pathSegments` style), in the order of the JSON. A
8
+ * shared query used nowhere has none. */
9
+ export declare function sharedUses(query: {
10
+ shared?: SharedQuery[];
11
+ }): Map<string, Segments[]>;
12
+ /** A name for a new shared query: `shared_query_<n>`, the first not taken
13
+ * by another shared query or a table of the schema (which it would hide
14
+ * in the SQL). */
15
+ export declare function sharedQueryName(schema: DatabaseSchema, query: {
16
+ shared?: SharedQuery[];
17
+ }): string;
18
+ /** `query` with a shared query added: `nested` named `name` (see
19
+ * sharedQueryName), under `id` — last, or just before the shared query
20
+ * `before` (one made from inside it, which it may then use). Used nowhere
21
+ * yet. */
22
+ export declare function addSharedQuery<Q extends {
23
+ shared?: SharedQuery[];
24
+ }>(query: Q, name: string, nested: NestedQuery, id?: string, before?: string): Q;
25
+ /** `body` (the whole query, or one in it: see updateQueryAt) joining the
26
+ * shared query `shared` of `query` — under its name, or `name_2` and so on
27
+ * when a table of `body` goes by that. Its ON is to be set, as a derived
28
+ * table's. Unchanged when there's no such shared query. */
29
+ export declare function joinSharedQuery<Q extends QueryBody>(query: QueryPipeline, body: Q, shared: string, options?: {
30
+ joinType?: JoinType;
31
+ on?: ExpressionNode;
32
+ id?: string;
33
+ }): Q;
34
+ /** `body` reading from the shared query `shared` of `query` as its base,
35
+ * under its name. Unchanged when there's no such shared query. */
36
+ export declare function setSharedBase<Q extends QueryBody>(query: QueryPipeline, body: Q, shared: string): Q;
37
+ /** `query` with the derived table `derivedId` — its base or a join of the
38
+ * query at `queryPath` (the whole query's by default) — made a shared
39
+ * query, named after its alias (`_2` and so on when taken): last in the
40
+ * list, or just before the shared query it's inside, which may then use
41
+ * it. Its place keeps its alias, so nothing naming it changes. Unchanged
42
+ * when there's no such derived table there. */
43
+ export declare function makeShared(query: QueryPipeline, derivedId: string, id?: string, queryPath?: QueryPath): QueryPipeline;
44
+ /** `query` with the place using a shared query at `path` (sharedUses's)
45
+ * made a sub query of its own: a copy, to change apart from the others.
46
+ * The shared query stays, even when used nowhere now (a warning). */
47
+ export declare function makeSubQuery(query: QueryPipeline, path: Segments): QueryPipeline;
48
+ /** `query` with the shared query `id` named `name`. Its places keep their
49
+ * aliases, so nothing naming them changes. */
50
+ export declare function renameSharedQuery<Q extends {
51
+ shared?: SharedQuery[];
52
+ }>(query: Q, id: string, name: string): Q;
53
+ /** Thrown by removeSharedQuery's `'removeUses'` when a query reads from the
54
+ * shared query as its base: taking it away would leave that query with no
55
+ * table. */
56
+ export declare class SharedBaseError extends Error {
57
+ constructor(name: string);
58
+ }
59
+ /** `query` without the shared query `id`. Its places become a sub query
60
+ * each, a copy of it (`'subQueries'`, the default: the rows stay the
61
+ * same), or go (`'removeUses'`: joins only — a base throws a
62
+ * SharedBaseError). */
63
+ export declare function removeSharedQuery<Q extends {
64
+ shared?: SharedQuery[];
65
+ }>(query: Q, id: string, places?: 'subQueries' | 'removeUses'): Q;
66
+ export {};
@@ -0,0 +1,102 @@
1
+ import { type ExpressionNode, type LiteralValue } from './ast.js';
2
+ import { type ResolveName } from './resolveNames.js';
3
+ import type { DatabaseSchema } from './schema.js';
4
+ import { type FromClause, type GroupByItem, type JoinClause, type OrderByItem, type QueryPipeline, type SelectItem } from './queryAst.js';
5
+ export type SqlDialect = 'mysql' | 'mssql' | 'postgres';
6
+ export declare const DIALECTS: SqlDialect[];
7
+ export declare const DIALECT_LABELS: Record<SqlDialect, string>;
8
+ /** Collects literal values while generating parameterized SQL (see
9
+ * astToParameterizedSql). Each value goes into the SQL as a token first;
10
+ * the tokens that end up in the final text become placeholders, in order. */
11
+ interface SqlParams {
12
+ values: LiteralValue[];
13
+ /** Values for the query's named params (ParamNode) — a Map, so a name
14
+ * like "toString" can't reach Object.prototype. */
15
+ named: Map<string, LiteralValue>;
16
+ }
17
+ /** While SQL is written with its spans (sqlSpans.ts): each part's path in
18
+ * the query (a node, a column, a join, LIMIT…), by index. A part's text is
19
+ * wrapped in U+E001 index U+E002 … U+E003, read back into offsets once
20
+ * written. Writing is synchronous: one at a time. */
21
+ export interface SpanMarks {
22
+ paths: (string | number)[][];
23
+ }
24
+ /** Writes with `marks` recording where each part goes (from the query as
25
+ * it's written: buildSql starts it). */
26
+ export declare function writeMarked<T>(marks: SpanMarks, write: () => T): T;
27
+ export declare function astToWhereClause(ast: ExpressionNode, dialect: SqlDialect, params?: SqlParams): string;
28
+ export declare function formatFromClause(from: FromClause, dialect: SqlDialect, params?: SqlParams): string;
29
+ export declare function formatJoinClause(join: JoinClause, dialect: SqlDialect, params?: SqlParams): string;
30
+ /** `SELECT *` when no column has been explicitly added yet (matches the
31
+ * behavior this function replaced), otherwise a multi-line
32
+ * `SELECT\n <expr>[ AS alias],\n ...` — one column per line, indented two
33
+ * spaces to match `astToWhereClause`'s own `WHERE\n ` body indent. Each
34
+ * column's own expression goes through the same `formatNode` every other
35
+ * expression position (WHERE, ON) already reuses, so a column can be a
36
+ * plain field, a function call, arithmetic, CASE/IF, etc. exactly like
37
+ * everywhere else in this app. Alias quoting mirrors `formatFromClause`/
38
+ * `formatJoinClause`'s own `AS ${quoteId(...)}` convention. */
39
+ export declare function formatSelectClause(columns: SelectItem[], dialect: SqlDialect, params?: SqlParams,
40
+ /** `SELECT` plus any modifiers — `SELECT DISTINCT`, `SELECT TOP (10)`. */
41
+ keyword?: string): string;
42
+ export declare function formatGroupByClause(items: GroupByItem[], dialect: SqlDialect, params?: SqlParams): string;
43
+ export declare function formatHavingClause(having: ExpressionNode, dialect: SqlDialect, params?: SqlParams): string;
44
+ export declare function formatOrderByClause(items: OrderByItem[], dialect: SqlDialect, params: SqlParams | undefined,
45
+ /** A key as it's written (MySQL's aliases: see buildSql). */
46
+ written: (key: ExpressionNode) => ExpressionNode): string;
47
+ /** The query as SQL with every value written inline (strings quoted and
48
+ * escaped) — for showing it. To run it, prefer astToParameterizedSql. */
49
+ export declare function astToSql(pipeline: QueryPipeline, dialect: SqlDialect, options?: {
50
+ /** Values for the query's named params, written as literals. Without
51
+ * them a param shows as `:name` (for display); with them, a param
52
+ * without a value is an error — the SQL never comes out half-filled. */
53
+ values?: Record<string, LiteralValue>;
54
+ /** The SQL name of each table and column, when the schema uses other
55
+ * (logical) names — see resolveNames. */
56
+ resolveName?: ResolveName;
57
+ /** A LIMIT for a query without one (see ParameterizedSqlOptions). */
58
+ defaultLimit?: number;
59
+ /** The schema the query is built on: a value compared with a column
60
+ * that has a `format` is written in it (see ParameterizedSqlOptions). */
61
+ schema?: DatabaseSchema;
62
+ }): string;
63
+ /** SQL with its values as bound parameters, for executing it. */
64
+ export interface ParameterizedSql {
65
+ /** The SQL, with a placeholder in place of each value: `?` (MySQL),
66
+ * `$1, $2, …` (PostgreSQL) or `@p1, @p2, …` (SQL Server). */
67
+ sql: string;
68
+ /** The values, in placeholder order (`params[0]` is `$1`/`@p1`/the first
69
+ * `?`). Strings, numbers and booleans as they are in the query; a date
70
+ * as text, `'2026-10-03'` or `'2026-10-03 09:30:00'` (the day and time
71
+ * it holds, no zone: the database reads it as the column's type) —
72
+ * never a Date, which a driver would write in the server's own time
73
+ * zone. NULL stays inline in the SQL. A value used twice in the SQL
74
+ * appears twice here. */
75
+ params: Exclude<LiteralValue, Date>[];
76
+ }
77
+ export interface ParameterizedSqlOptions {
78
+ /** Values for the query's named params (`{ type: 'param', name }`), by
79
+ * name. A param without a value is an error. */
80
+ values?: Record<string, LiteralValue>;
81
+ /** The SQL name of each table and column, when the schema uses other
82
+ * (logical) names: `(table)` → the table's SQL name, `(table, column)`
83
+ * → the column's. See resolveNames. */
84
+ resolveName?: ResolveName;
85
+ /** A LIMIT for a query that has none — a cap for reading a stored query
86
+ * that may not set one. Its own LIMIT, when it has one, is kept. The
87
+ * query itself isn't changed, only this SQL. */
88
+ defaultLimit?: number;
89
+ /** The schema the query is built on: a value compared with a column
90
+ * that has a `format` (a time kept as `'HH:mm'` text) is written in it
91
+ * — a param's value from `values` too. Without it, values are written
92
+ * the query's own way (a time `HH:MM:SS`). */
93
+ schema?: DatabaseSchema;
94
+ }
95
+ /** The query as SQL whose values — in WHERE, JOIN ON and SELECT, including
96
+ * inside functions, IF/CASE and IN lists — are bound parameters rather than
97
+ * text in the SQL, the safe way to execute it with a database driver.
98
+ * Named params take their values from `options.values`. Table/column names,
99
+ * function names, units and type names can't be parameters; they're quoted
100
+ * or checked instead. */
101
+ export declare function astToParameterizedSql(pipeline: QueryPipeline, dialect: SqlDialect, options?: ParameterizedSqlOptions): ParameterizedSql;
102
+ export {};
@@ -0,0 +1,5 @@
1
+ /** A Range over the characters `start` to `end` of the container's text. */
2
+ export declare function sqlRangeOf(container: Node, start: number, end: number): Range;
3
+ /** The index of the character at a point in the container's text, if the
4
+ * point is on one (not past a line's end, say). */
5
+ export declare function sqlOffsetAt(container: Node, x: number, y: number): number | undefined;
@@ -0,0 +1,33 @@
1
+ import type { QueryPipeline } from './queryAst.js';
2
+ import { type ParameterizedSqlOptions, type SqlDialect } from './sqlGen.js';
3
+ /** Where a part of the query is in the SQL: `sql.slice(start, end)`. */
4
+ export interface SqlSpan {
5
+ start: number;
6
+ end: number;
7
+ /** The part's path in the query, as validateQuery's issues have one —
8
+ * what PipelineEditor's goToIssue takes. */
9
+ pathSegments: (string | number)[];
10
+ }
11
+ export interface SqlWithSpans {
12
+ sql: string;
13
+ /** Every part's span: nodes, SELECT columns, FROM and each join, GROUP
14
+ * BY and ORDER BY keys, LIMIT and OFFSET — inner ones within outer
15
+ * ones, in the order they start (an outer one first). A part written
16
+ * twice (an argument some dialect repeats) has a span each time. */
17
+ spans: SqlSpan[];
18
+ }
19
+ /** The SQL as astToSql writes it — or, `parameterized`, as
20
+ * astToParameterizedSql does — with each part's span in it. */
21
+ export default function astToSqlWithSpans(query: QueryPipeline, dialect: SqlDialect, options?: ParameterizedSqlOptions & {
22
+ parameterized?: boolean;
23
+ }): SqlWithSpans;
24
+ /** The innermost of astToSqlWithSpans's `spans` at `offset` in the SQL (a
25
+ * character's index), if any: the most specific part there (of two with
26
+ * the same text, the one within the other). */
27
+ export declare function spanAt(spans: SqlSpan[], offset: number): SqlSpan | undefined;
28
+ /** Where the part at `pathSegments` is in the SQL: the outermost of
29
+ * `spans` at it or under it — its own span, or, for one written in pieces
30
+ * (a section: `['select']`), each of its parts'. Several when it's
31
+ * written more than once. For lighting up a part hovered in the editor
32
+ * (its onHoverPart). */
33
+ export declare function spansFor(spans: SqlSpan[], pathSegments: (string | number)[]): SqlSpan[];
@@ -0,0 +1,43 @@
1
+ import type { LiteralValue } from './ast.js';
2
+ import type { QueryValue } from './queryAst.js';
3
+ /** The format saveQuery writes. Raised when a change to the query's shape
4
+ * needs older stored queries migrated (see MIGRATIONS). */
5
+ export declare const QUERY_FORMAT_VERSION = 4;
6
+ /** A query as stored: plain JSON, with the format it's in. */
7
+ export interface StoredQuery {
8
+ version: number;
9
+ query: QueryValue;
10
+ }
11
+ /** Why a stored query can't be loaded. `newerVersion`: written by a later
12
+ * version of this package than the one reading it. `invalid`: not a
13
+ * stored query at all (no version, a version that isn't a whole number
14
+ * from 1, no query, an unreadable date or bigint). */
15
+ export declare class QueryFormatError extends Error {
16
+ readonly kind: 'newerVersion' | 'invalid';
17
+ constructor(kind: 'newerVersion' | 'invalid', message: string);
18
+ }
19
+ /** A migration takes a query stored in one format to the next. */
20
+ export type Migration = (query: unknown) => unknown;
21
+ /** The values of an IN list typed as one text (format 1): comma-separated,
22
+ * each optionally single-quoted ('' for a quote inside). An unquoted value
23
+ * that reads as a number is a number, anything else a string. Commas
24
+ * inside quotes don't split. */
25
+ export declare function parseInList(text: string): LiteralValue[];
26
+ /** Format 1 → 2 (issue 130): IN's values were one comma-separated text,
27
+ * now a list, one literal per value. Any other right side but a sub query
28
+ * becomes a list of itself. */
29
+ export declare function inListsMigration(query: unknown): unknown;
30
+ /** `query`, stored in format `version`, migrated to the last format
31
+ * `migrations` lead to. */
32
+ export declare function migrate(query: unknown, version: number, migrations: Migration[]): unknown;
33
+ /** `query` as it's stored: the current format's version, and the query
34
+ * itself as plain JSON (`JSON.stringify` it as is). loadQuery gives the
35
+ * same query back. */
36
+ export declare function saveQuery(query: QueryValue): StoredQuery;
37
+ /** A stored query read back (`JSON.parse`d), in the current format:
38
+ * migrated when it's older, its dates and bigints as they were. Throws a
39
+ * QueryFormatError when it's newer than this version knows, or isn't a
40
+ * stored query. Its tables and columns aren't checked against a schema —
41
+ * validateQuery does that, and should, since the schema may have changed
42
+ * since it was saved. */
43
+ export declare function loadQuery(stored: unknown): QueryValue;
@@ -0,0 +1,3 @@
1
+ import type { ExpressionNode } from './ast.js';
2
+ /** A short text of `exp`, two levels deep at most (deeper parts as `…`). */
3
+ export default function summarize(exp: ExpressionNode, depth?: number): string;
@@ -0,0 +1,74 @@
1
+ /** Every color the editor draws with, named by role rather than by hue so a
2
+ * host can recolor the editor freely (a light theme is just different
3
+ * values for the same roles). The defaults reproduce the original dark look.
4
+ *
5
+ * Each token becomes a CSS custom property on the editor root — `canvasBg`
6
+ * → `--qb-canvas-bg` — which components use through Tailwind utilities
7
+ * mapped in features/queryEditor/queryBuilder.css (`bg-qb-canvas-bg`,
8
+ * `text-qb-text-muted`, ...). Hosts
9
+ * override them either in CSS (`.qb-root { --qb-accent: #e91e63 }`) or with
10
+ * PipelineEditor's `theme` prop. */
11
+ export declare const DEFAULT_THEME: {
12
+ canvasBg: string;
13
+ canvasPattern: string;
14
+ edge: string;
15
+ headerBg: string;
16
+ headerBorder: string;
17
+ nodeBg: string;
18
+ nodeBorder: string;
19
+ nodeHoverBg: string;
20
+ nodeInputText: string;
21
+ nodeInputBorder: string;
22
+ nodeInputIcon: string;
23
+ groupBg: string;
24
+ groupBorder: string;
25
+ groupDragBg: string;
26
+ groupDragBorder: string;
27
+ textStrong: string;
28
+ text: string;
29
+ textSecondary: string;
30
+ textMuted: string;
31
+ textFaint: string;
32
+ fieldBg: string;
33
+ fieldControlBg: string;
34
+ fieldControlHoverBg: string;
35
+ fieldBorder: string;
36
+ fieldBorderHover: string;
37
+ fieldText: string;
38
+ fieldTextSoft: string;
39
+ fieldTextMuted: string;
40
+ fieldTextSubtle: string;
41
+ fieldGroupBorder: string;
42
+ conditional: string;
43
+ conditionalOnField: string;
44
+ conditionalBorder: string;
45
+ negate: string;
46
+ param: string;
47
+ paramBg: string;
48
+ summaryBg: string;
49
+ summaryBorder: string;
50
+ summaryText: string;
51
+ focusRing: string;
52
+ accent: string;
53
+ secondary: string;
54
+ danger: string;
55
+ warning: string;
56
+ };
57
+ export type ThemeToken = keyof typeof DEFAULT_THEME;
58
+ export type QueryBuilderTheme = Record<ThemeToken, string>;
59
+ /** Class the editor root carries — tokens are scoped to it, so they never
60
+ * leak into (or read from) the host page outside the editor. */
61
+ export declare const ROOT_CLASS = "qb-root";
62
+ /** `canvasBg` → `--qb-canvas-bg`. */
63
+ export declare function tokenVar(token: ThemeToken): string;
64
+ /** `var(--qb-canvas-bg)` — for inline styles / props that take a color. */
65
+ export declare function tokenRef(token: ThemeToken): string;
66
+ /** The defaults as a stylesheet. `:where()` gives the rule zero specificity,
67
+ * so any host rule targeting `.qb-root` overrides it, whatever the order. */
68
+ export declare function defaultTokensStylesheet(): string;
69
+ /** A partial theme as inline CSS custom properties for the editor root. */
70
+ export declare function themeToCssVars(theme: Partial<QueryBuilderTheme> | undefined): Record<string, string>;
71
+ /** The tokens actually in effect on `element` (defaults, host CSS and the
72
+ * `theme` prop all folded in by the browser), falling back to `fallback`
73
+ * for anything the element doesn't resolve. */
74
+ export declare function readResolvedTheme(element: Element, fallback: QueryBuilderTheme): QueryBuilderTheme;
@@ -0,0 +1,6 @@
1
+ import type { UIComponents } from './types.js';
2
+ /** The UI kit the surrounding editor renders with — provided once by
3
+ * PipelineEditor (its default adapter merged with the `components` prop). */
4
+ declare const UIContext: import("react").Context<UIComponents | null>;
5
+ export declare function useUI(): UIComponents;
6
+ export default UIContext;
@@ -0,0 +1,12 @@
1
+ import type { ButtonProps, ComboboxProps, DatePickerProps, DateTimePickerProps, TimePickerProps, IconButtonProps, ListInputProps, MenuProps, SelectProps, TextFieldProps, TooltipProps } from './types.js';
2
+ export declare const Tooltip: (props: TooltipProps) => import("react/jsx-runtime").JSX.Element;
3
+ export declare const IconButton: ({ navigation, ...props }: IconButtonProps) => import("react/jsx-runtime").JSX.Element;
4
+ export declare const Button: ({ showsValue, pressed, ...rest }: ButtonProps) => import("react/jsx-runtime").JSX.Element;
5
+ export declare const TextField: (props: TextFieldProps) => import("react/jsx-runtime").JSX.Element;
6
+ export declare const Select: (props: SelectProps) => import("react/jsx-runtime").JSX.Element;
7
+ export declare function Combobox<T>(props: ComboboxProps<T>): import("react/jsx-runtime").JSX.Element;
8
+ export declare const Menu: (props: MenuProps) => import("react/jsx-runtime").JSX.Element;
9
+ export declare const DatePicker: (props: DatePickerProps) => import("react/jsx-runtime").JSX.Element;
10
+ export declare const DateTimePicker: (props: DateTimePickerProps) => import("react/jsx-runtime").JSX.Element;
11
+ export declare const TimePicker: (props: TimePickerProps) => import("react/jsx-runtime").JSX.Element;
12
+ export declare const ListInput: (props: ListInputProps) => import("react/jsx-runtime").JSX.Element | null;