@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,44 @@
1
+ import type { QueryIssueKind, QueryIssueSeverity } from './core/queryValidation.js';
2
+ import type { QueryValue } from './core/queryAst.js';
3
+ import type { DatabaseSchema } from './core/schema.js';
4
+ import type { SqlDialect } from './core/sqlGen.js';
5
+ /** A JSON value a fixture binds: no Date or bigint. */
6
+ export type FixtureValue = string | number | boolean | null;
7
+ /** What astToParameterizedSql makes of a fixture's query in one dialect —
8
+ * or the message it throws. */
9
+ export type FixtureResult = {
10
+ sql: string;
11
+ params: FixtureValue[];
12
+ } | {
13
+ error: string;
14
+ };
15
+ export interface ContractFixture {
16
+ name: string;
17
+ query: QueryValue;
18
+ /** Values for the query's params (astToParameterizedSql's `values`). */
19
+ values?: Record<string, FixtureValue>;
20
+ /** SQL names for the schema's tables (`table`) and columns
21
+ * (`table.column`) — as a resolveName option: `(t, c) =>
22
+ * names[c ? `${t}.${c}` : t] ?? c ?? t`. */
23
+ names?: Record<string, string>;
24
+ /** astToParameterizedSql's `defaultLimit`. */
25
+ defaultLimit?: number;
26
+ /** validateQuery's issues (against the fixtures' schema), in order —
27
+ * without their messages, which are for people and may change. */
28
+ issues: {
29
+ kind: QueryIssueKind;
30
+ severity: QueryIssueSeverity;
31
+ path: string;
32
+ }[];
33
+ /** The SQL in each dialect (astToParameterizedSql, with the fixtures'
34
+ * `schema` as its `schema` option); absent for a query with no base
35
+ * table yet. */
36
+ results?: Record<SqlDialect, FixtureResult>;
37
+ }
38
+ export interface ContractFixtures {
39
+ /** The schema every case is built and validated against. */
40
+ schema: DatabaseSchema;
41
+ cases: ContractFixture[];
42
+ }
43
+ declare const CONTRACT_FIXTURES: ContractFixtures;
44
+ export default CONTRACT_FIXTURES;
@@ -0,0 +1,13 @@
1
+ export { default as QueryBuilder, type PipelineEditorProps as QueryBuilderProps, type PipelineEditorHandle as QueryBuilderHandle, } from './features/queryEditor/PipelineEditor.js';
2
+ export * from './core-api.js';
3
+ export { default as formula, formulaText, type FormulaOptions, type FormulaPart, type FormulaRole, } from './core/formula.js';
4
+ export { default as astToSqlWithSpans, spanAt, spansFor, type SqlSpan, type SqlWithSpans, } from './core/sqlSpans.js';
5
+ export { sqlOffsetAt, sqlRangeOf } from './core/sqlOffsets.js';
6
+ export type { FlowDirection, FlowOrientation } from './core/expressionFlow.js';
7
+ export type { BetweenOnText } from './core/BetweenOnTextContext.js';
8
+ export type { OnRun, RunResult } from './features/queryEditor/run.js';
9
+ export type { ExistsOptions, ExistsPlace, ExistsRelations, } from './core/existsMenu.js';
10
+ export type { RenderValueInput, ValueInputProps } from './core/ValueInputContext.js';
11
+ export { DEFAULT_MESSAGES, type Messages } from './core/i18n/messages.js';
12
+ export { DEFAULT_THEME, type QueryBuilderTheme, type ThemeToken, } from './core/theme/tokens.js';
13
+ export type * from './core/ui/types.js';
@@ -0,0 +1,3 @@
1
+ export { default as MuiDatePicker } from './adapters/mui/MuiDatePicker.js';
2
+ export { default as MuiDateTimePicker } from './adapters/mui/MuiDateTimePicker.js';
3
+ export { default as MuiTimePicker } from './adapters/mui/MuiTimePicker.js';
@@ -0,0 +1,2 @@
1
+ export { default as QueryBuilder, type MuiQueryBuilderProps as QueryBuilderProps, } from './adapters/mui/QueryBuilder.js';
2
+ export { default as muiComponents } from './adapters/mui/index.js';
@@ -0,0 +1,3 @@
1
+ export { default as importSql, type ImportSqlOptions, type ImportSqlResult, } from './sqlImport/importSql.js';
2
+ export type { SqlImportProblem, SqlImportProblemKind } from './sqlImport/context.js';
3
+ export type { SqlPosition } from './sqlImport/tokenize.js';
@@ -0,0 +1,71 @@
1
+ import type { ExistsNode, FieldNode } from '../core/ast.js';
2
+ import type { FunctionRegistry } from '../core/functionRegistry.js';
3
+ import type { DatabaseSchema } from '../core/schema.js';
4
+ import type { SqlDialect } from '../core/sqlGen.js';
5
+ import type { DerivedQuery, SelectItem } from '../core/queryAst.js';
6
+ import type { SqlQuery, SqlSpan } from './syntax.js';
7
+ import { type SqlPosition } from './tokenize.js';
8
+ /** What can stop SQL from being imported:
9
+ * - `syntax`: SQL that can't be read at all.
10
+ * - `unsupported`: SQL the query can't hold (UNION at the top, WITH,
11
+ * arithmetic, a window function, …).
12
+ * - `unknownTable`, `unknownColumn`: a name the schema doesn't have.
13
+ * - `ambiguousColumn`: a column name more than one table has.
14
+ * - `duplicateTable`: two tables of one query by the same name.
15
+ * - `unknownFunction`: a function the registry doesn't have (unless
16
+ * `allowUnknownFunctions`).
17
+ * - `positionalParam`: `?`, `$1`: a param with no name.
18
+ * - `groupedBy` (a warning): a SELECT column next to an aggregate, not in
19
+ * GROUP BY, added to it (issue 134's automatic grouping). */
20
+ export type SqlImportProblemKind = 'syntax' | 'unsupported' | 'unknownTable' | 'unknownColumn' | 'ambiguousColumn' | 'duplicateTable' | 'unknownFunction' | 'positionalParam' | 'groupedBy';
21
+ /** Something in the SQL the import couldn't take, and where it is. An
22
+ * error leaves the query without it: none at all in strict mode; in
23
+ * lenient mode a blank field in its place, so the query is incomplete
24
+ * (validateQuery) until someone fixes it. A warning is in the query all
25
+ * the same: what was left out (a SELECT column, a sort key) or changed. */
26
+ export interface SqlImportProblem {
27
+ severity: 'error' | 'warning';
28
+ kind: SqlImportProblemKind;
29
+ message: string;
30
+ at: SqlPosition;
31
+ }
32
+ /** A table a field can name: by `ref` (its alias, else its name), with
33
+ * its columns as the query names them. */
34
+ export interface ScopeTable {
35
+ ref: string;
36
+ columns: string[];
37
+ /** The schema's table, when it is one. */
38
+ table?: string;
39
+ }
40
+ /** The tables a query's fields can name. An EXISTS sees the query around
41
+ * it (`outer`); a derived table or an IN's sub query sees only its own,
42
+ * but keeps the outer ones (`around`) to say why a name isn't there. */
43
+ export interface Scope {
44
+ tables: ScopeTable[];
45
+ outer?: Scope;
46
+ around?: Scope;
47
+ }
48
+ /** What a name can mean besides a column: a SELECT column's alias in
49
+ * ORDER BY (and in MySQL's HAVING). */
50
+ export type AliasLookup = (name: string) => SelectItem | undefined;
51
+ export interface ImportContext {
52
+ sql: string;
53
+ lenient: boolean;
54
+ dialect: SqlDialect;
55
+ schema: DatabaseSchema;
56
+ functions: FunctionRegistry;
57
+ allowUnknownFunctions: boolean;
58
+ problems: SqlImportProblem[];
59
+ /** Fields naming a table of the query around an EXISTS: its link. */
60
+ outerFields: WeakSet<FieldNode>;
61
+ /** The queries inside an expression, read by query.ts. */
62
+ existsQuery: (query: SqlQuery, scope: Scope, span: SqlSpan) => ExistsNode | undefined;
63
+ inQuery: (query: SqlQuery, scope: Scope) => DerivedQuery | undefined;
64
+ }
65
+ /** `kind` of problem at `span`. `leftOut`: what goes without it — an
66
+ * error in strict mode, a warning saying so in lenient mode. */
67
+ export declare function report(ctx: ImportContext, kind: SqlImportProblemKind, message: string, span: SqlSpan, severity?: 'error' | 'warning' | 'leftOut'): void;
68
+ /** `name` among `names`: the same, else the same but for case (SQL
69
+ * matches names case-insensitively); undefined when none is, or more than
70
+ * one is but for case. */
71
+ export declare function matchName(names: string[], name: string): string | undefined;
@@ -0,0 +1,11 @@
1
+ import type { ExpressionNode } from '../core/ast.js';
2
+ import { type ImportContext, type Scope } from './context.js';
3
+ import type { SqlExpr, SqlIdent } from './syntax.js';
4
+ /** Where an expression is: the tables its fields can name, and what else
5
+ * a bare name can mean there (a SELECT column, by its alias). */
6
+ export interface ExprPlace {
7
+ scope: Scope;
8
+ alias?: (name: SqlIdent) => ExpressionNode | undefined;
9
+ }
10
+ /** `node` in the query's terms, as it is at `place`. */
11
+ export default function convertExpr(ctx: ImportContext, root: SqlExpr, place: ExprPlace): ExpressionNode;
@@ -0,0 +1,28 @@
1
+ import { type FunctionRegistry } from '../core/functionRegistry.js';
2
+ import { type QueryPipeline } from '../core/queryAst.js';
3
+ import { type DatabaseSchema } from '../core/schema.js';
4
+ import type { SqlDialect } from '../core/sqlGen.js';
5
+ import { type SqlImportProblem } from './context.js';
6
+ export interface ImportSqlOptions {
7
+ dialect: SqlDialect;
8
+ /** The tables and columns the SQL names. */
9
+ schema: DatabaseSchema;
10
+ /** The functions it may call (default: DEFAULT_FUNCTIONS). */
11
+ functions?: FunctionRegistry;
12
+ /** Take a function the registry doesn't have, as validateQuery's
13
+ * option does. */
14
+ allowUnknownFunctions?: boolean;
15
+ /** `strict` (the default): no query with any error. `lenient`: the query
16
+ * whenever its tables can be read, with what it couldn't take (see
17
+ * SqlImportProblem). */
18
+ mode?: 'strict' | 'lenient';
19
+ }
20
+ export interface ImportSqlResult {
21
+ /** The query: in strict mode when there's no error; in lenient mode
22
+ * whenever its tables could be read. */
23
+ query?: QueryPipeline;
24
+ problems: SqlImportProblem[];
25
+ }
26
+ /** SQL (one SELECT, in `options.dialect`) as a query, with what kept it
27
+ * from being one, or from being all of it. */
28
+ export default function importSql(sql: string, options: ImportSqlOptions): ImportSqlResult;
@@ -0,0 +1,6 @@
1
+ import type { SqlDialect } from '../core/sqlGen.js';
2
+ import type { SqlQuery } from './syntax.js';
3
+ /** One SELECT query in `dialect`, read into its syntax tree (see
4
+ * syntax.ts). Throws a SqlSyntaxError, with where it is, for SQL that
5
+ * can't be read. */
6
+ export default function parseSql(sql: string, dialect: SqlDialect): SqlQuery;
@@ -0,0 +1,245 @@
1
+ /** Where a node's text is in the SQL: `sql.slice(start, end)`. */
2
+ export interface SqlSpan {
3
+ start: number;
4
+ end: number;
5
+ }
6
+ /** A name: a word as written, or a quoted name without its quotes. */
7
+ export interface SqlIdent {
8
+ value: string;
9
+ quoted: boolean;
10
+ span: SqlSpan;
11
+ }
12
+ /** A sort key: ORDER BY's, or one inside an aggregate. `direction` and
13
+ * `nulls` only when written. */
14
+ export interface SqlOrderItem {
15
+ expr: SqlExpr;
16
+ direction?: 'asc' | 'desc';
17
+ nulls?: 'first' | 'last';
18
+ span: SqlSpan;
19
+ }
20
+ export type SqlExpr = SqlName | SqlStar | SqlString | SqlNumber | SqlKeywordValue | SqlTyped | SqlInterval | SqlParam | SqlUnary | SqlBinary | SqlIsNull | SqlIn | SqlBetween | SqlCall | SqlCast | SqlExtract | SqlCase | SqlExists | SqlScalarSubquery;
21
+ /** A column (`name`, `t.name`), or a bare word such as CURRENT_DATE. */
22
+ export interface SqlName {
23
+ kind: 'name';
24
+ parts: SqlIdent[];
25
+ span: SqlSpan;
26
+ }
27
+ /** `*` or `t.*`: a SELECT item, or COUNT's argument. */
28
+ export interface SqlStar {
29
+ kind: 'star';
30
+ table?: SqlIdent[];
31
+ span: SqlSpan;
32
+ }
33
+ export interface SqlString {
34
+ kind: 'string';
35
+ value: string;
36
+ span: SqlSpan;
37
+ }
38
+ /** A number as written (`12`, `1.5`, `2e3`). */
39
+ export interface SqlNumber {
40
+ kind: 'number';
41
+ text: string;
42
+ span: SqlSpan;
43
+ }
44
+ /** NULL, TRUE or FALSE. */
45
+ export interface SqlKeywordValue {
46
+ kind: 'null' | 'true' | 'false';
47
+ span: SqlSpan;
48
+ }
49
+ /** `DATE '2026-10-08'`, `TIME '…'`, `TIMESTAMP '…'`. */
50
+ export interface SqlTyped {
51
+ kind: 'typed';
52
+ type: 'DATE' | 'TIME' | 'TIMESTAMP';
53
+ value: string;
54
+ span: SqlSpan;
55
+ }
56
+ /** `INTERVAL 3 DAY` (MySQL), `INTERVAL '3 day'` (PostgreSQL). */
57
+ export interface SqlInterval {
58
+ kind: 'interval';
59
+ value: SqlExpr;
60
+ unit?: string;
61
+ span: SqlSpan;
62
+ }
63
+ /** `:name` (every dialect), `?` (MySQL), `$1` (PostgreSQL), `@name`
64
+ * (SQL Server). `name` is what follows the sign; `?` has none. */
65
+ export interface SqlParam {
66
+ kind: 'param';
67
+ style: ':' | '?' | '$' | '@';
68
+ name: string;
69
+ span: SqlSpan;
70
+ }
71
+ /** NOT, or a sign in front of a value. */
72
+ export interface SqlUnary {
73
+ kind: 'unary';
74
+ op: 'NOT' | '-' | '+';
75
+ operand: SqlExpr;
76
+ span: SqlSpan;
77
+ }
78
+ /** Two operands and an operator, upper case: AND, OR, a comparison (as
79
+ * written: `<>` and `!=` both), arithmetic, `||` (text in PostgreSQL and
80
+ * SQL Server; MySQL's `||` is OR), `LIKE`/`NOT LIKE` (with ESCAPE),
81
+ * `ILIKE`, `REGEXP`/`RLIKE`, `~`-family, `<=>`, `IS [NOT] DISTINCT FROM`,
82
+ * `IS`/`IS NOT` with TRUE or FALSE. */
83
+ export interface SqlBinary {
84
+ kind: 'binary';
85
+ op: string;
86
+ left: SqlExpr;
87
+ right: SqlExpr;
88
+ escape?: SqlExpr;
89
+ span: SqlSpan;
90
+ }
91
+ export interface SqlIsNull {
92
+ kind: 'isNull';
93
+ operand: SqlExpr;
94
+ not: boolean;
95
+ span: SqlSpan;
96
+ }
97
+ /** `x [NOT] IN (a, b)` or `x [NOT] IN (SELECT …)`. */
98
+ export interface SqlIn {
99
+ kind: 'in';
100
+ operand: SqlExpr;
101
+ not: boolean;
102
+ list?: SqlExpr[];
103
+ query?: SqlQuery;
104
+ span: SqlSpan;
105
+ }
106
+ export interface SqlBetween {
107
+ kind: 'between';
108
+ operand: SqlExpr;
109
+ not: boolean;
110
+ low: SqlExpr;
111
+ high: SqlExpr;
112
+ span: SqlSpan;
113
+ }
114
+ /** A function call, with what aggregates take besides arguments. A window
115
+ * (`OVER …`) and PostgreSQL's FILTER are only marked: the AST has neither. */
116
+ export interface SqlCall {
117
+ kind: 'call';
118
+ name: SqlIdent[];
119
+ args: SqlExpr[];
120
+ distinct: boolean;
121
+ /** Inside the parentheses (PostgreSQL's STRING_AGG, MySQL's GROUP_CONCAT). */
122
+ orderBy?: SqlOrderItem[];
123
+ /** MySQL's GROUP_CONCAT(… SEPARATOR ', '). */
124
+ separator?: SqlExpr;
125
+ /** SQL Server's STRING_AGG(…) WITHIN GROUP (ORDER BY …). */
126
+ withinGroup?: SqlOrderItem[];
127
+ filter?: SqlSpan;
128
+ over?: SqlSpan;
129
+ span: SqlSpan;
130
+ }
131
+ /** `CAST(x AS type)`, or PostgreSQL's `x::type`. `type` as written, its
132
+ * size normalized: `DECIMAL(10, 2)`. */
133
+ export interface SqlCast {
134
+ kind: 'cast';
135
+ operand: SqlExpr;
136
+ type: string;
137
+ span: SqlSpan;
138
+ }
139
+ /** `EXTRACT(unit FROM x)`, the unit upper case. */
140
+ export interface SqlExtract {
141
+ kind: 'extract';
142
+ unit: string;
143
+ operand: SqlExpr;
144
+ span: SqlSpan;
145
+ }
146
+ export interface SqlCase {
147
+ kind: 'case';
148
+ subject?: SqlExpr;
149
+ branches: {
150
+ when: SqlExpr;
151
+ then: SqlExpr;
152
+ }[];
153
+ else?: SqlExpr;
154
+ span: SqlSpan;
155
+ }
156
+ export interface SqlExists {
157
+ kind: 'exists';
158
+ query: SqlQuery;
159
+ span: SqlSpan;
160
+ }
161
+ /** `(SELECT …)` as a value. */
162
+ export interface SqlScalarSubquery {
163
+ kind: 'subquery';
164
+ query: SqlQuery;
165
+ span: SqlSpan;
166
+ }
167
+ /** A table FROM or a join names: `name [AS alias]`, or `(SELECT …) alias`. */
168
+ export type SqlTableRef = {
169
+ kind: 'table';
170
+ name: SqlIdent[];
171
+ alias?: SqlIdent;
172
+ span: SqlSpan;
173
+ } | {
174
+ kind: 'derived';
175
+ query: SqlQuery;
176
+ alias?: SqlIdent;
177
+ span: SqlSpan;
178
+ };
179
+ export interface SqlJoin {
180
+ type: 'inner' | 'left' | 'right' | 'full' | 'cross';
181
+ table: SqlTableRef;
182
+ on?: SqlExpr;
183
+ using?: SqlIdent[];
184
+ span: SqlSpan;
185
+ }
186
+ /** One item of FROM's comma list: a table and the joins after it. */
187
+ export interface SqlFromItem {
188
+ table: SqlTableRef;
189
+ joins: SqlJoin[];
190
+ }
191
+ export interface SqlSelectItem {
192
+ expr: SqlExpr;
193
+ alias?: SqlIdent;
194
+ span: SqlSpan;
195
+ }
196
+ export interface SqlSelect {
197
+ kind: 'select';
198
+ distinct: boolean;
199
+ /** SQL Server's `TOP (n)`. */
200
+ top?: SqlExpr;
201
+ columns: SqlSelectItem[];
202
+ from: SqlFromItem[];
203
+ where?: SqlExpr;
204
+ groupBy: SqlExpr[];
205
+ having?: SqlExpr;
206
+ span: SqlSpan;
207
+ }
208
+ /** UNION, INTERSECT or EXCEPT of two query bodies. */
209
+ export interface SqlSetOp {
210
+ kind: 'setOp';
211
+ op: 'UNION' | 'INTERSECT' | 'EXCEPT';
212
+ all: boolean;
213
+ left: SqlQueryBody;
214
+ right: SqlQueryBody;
215
+ span: SqlSpan;
216
+ }
217
+ /** A query in parentheses, as one side of a UNION. */
218
+ export interface SqlNested {
219
+ kind: 'nested';
220
+ query: SqlQuery;
221
+ span: SqlSpan;
222
+ }
223
+ export type SqlQueryBody = SqlSelect | SqlSetOp | SqlNested;
224
+ /** A WITH query: `name [(columns)] AS (query)`. */
225
+ export interface SqlCte {
226
+ name: SqlIdent;
227
+ columns?: SqlIdent[];
228
+ /** PostgreSQL's `[NOT] MATERIALIZED`, where it is. */
229
+ hint?: SqlSpan;
230
+ query: SqlQuery;
231
+ span: SqlSpan;
232
+ }
233
+ /** A whole query: its body, and what applies to all of it. `limit` and
234
+ * `offset` come from LIMIT/OFFSET, `LIMIT offset, count` (MySQL) and
235
+ * OFFSET … FETCH; SQL Server's TOP stays on its SELECT. */
236
+ export interface SqlQuery {
237
+ with?: SqlCte[];
238
+ /** `WITH RECURSIVE`. */
239
+ recursive?: boolean;
240
+ body: SqlQueryBody;
241
+ orderBy: SqlOrderItem[];
242
+ limit?: SqlExpr;
243
+ offset?: SqlExpr;
244
+ span: SqlSpan;
245
+ }
@@ -0,0 +1,26 @@
1
+ import type { SqlDialect } from '../core/sqlGen.js';
2
+ /** A place in the SQL text: line and column from 1, `length` characters. */
3
+ export interface SqlPosition {
4
+ offset: number;
5
+ line: number;
6
+ column: number;
7
+ length: number;
8
+ }
9
+ export declare function positionOf(sql: string, start: number, end?: number): SqlPosition;
10
+ /** SQL that can't be read: what's wrong, and where. */
11
+ export declare class SqlSyntaxError extends Error {
12
+ readonly at: SqlPosition;
13
+ constructor(message: string, sql: string, start: number, end?: number);
14
+ }
15
+ export interface Token {
16
+ kind: 'word' | 'quoted' | 'string' | 'number' | 'param' | 'op' | 'end';
17
+ /** A word or number as written; a quoted name or a string without its
18
+ * quotes; an operator; a param's name (`''` for `?`). */
19
+ value: string;
20
+ style?: ':' | '?' | '$' | '@';
21
+ start: number;
22
+ end: number;
23
+ }
24
+ /** The SQL's tokens, comments and whitespace skipped, ending with an
25
+ * `end` token. */
26
+ export declare function tokenize(sql: string, dialect: SqlDialect): Token[];
package/package.json CHANGED
@@ -1,6 +1,167 @@
1
1
  {
2
2
  "name": "@nongt/visql",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.3.1",
4
+ "description": "A visual SQL query editor for React: build a whole query on a node canvas, store it as JSON, turn it into SQL.",
5
+ "keywords": [
6
+ "sql",
7
+ "query-builder",
8
+ "visual",
9
+ "react",
10
+ "react-flow",
11
+ "editor",
12
+ "mysql",
13
+ "postgres",
14
+ "sql-server"
15
+ ],
16
+ "license": "MIT",
17
+ "publishConfig": {
18
+ "registry": "https://registry.npmjs.org/",
19
+ "access": "public"
20
+ },
21
+ "type": "module",
22
+ "files": [
23
+ "dist",
24
+ "!dist/**/*.map"
25
+ ],
26
+ "sideEffects": [
27
+ "**/*.css"
28
+ ],
29
+ "exports": {
30
+ ".": {
31
+ "types": "./dist/types/index.d.ts",
32
+ "import": "./dist/index.js"
33
+ },
34
+ "./core": {
35
+ "types": "./dist/types/core-api.d.ts",
36
+ "import": "./dist/core.js"
37
+ },
38
+ "./mui": {
39
+ "types": "./dist/types/mui.d.ts",
40
+ "import": "./dist/mui.js"
41
+ },
42
+ "./mui-date-pickers": {
43
+ "types": "./dist/types/mui-date-pickers.d.ts",
44
+ "import": "./dist/mui-date-pickers.js"
45
+ },
46
+ "./fixtures": {
47
+ "types": "./dist/types/fixtures.d.ts",
48
+ "import": "./dist/fixtures.js"
49
+ },
50
+ "./sql-import": {
51
+ "types": "./dist/types/sql-import.d.ts",
52
+ "import": "./dist/sql-import.js"
53
+ },
54
+ "./style.css": "./dist/style.css"
55
+ },
56
+ "module": "./dist/index.js",
57
+ "types": "./dist/types/index.d.ts",
58
+ "dependencies": {
59
+ "clsx": "^2.1.1"
60
+ },
61
+ "peerDependencies": {
62
+ "@emotion/cache": "^11.14.0",
63
+ "@emotion/react": "^11.14.0",
64
+ "@emotion/styled": "^11.14.0",
65
+ "@mui/material": "^7.1.0",
66
+ "@mui/x-date-pickers": "^8.3.1",
67
+ "@xyflow/react": "^12.6.4",
68
+ "date-fns": "^4.1.0",
69
+ "iconoir-react": "^7.11.0",
70
+ "react": "^19.1.0",
71
+ "react-dom": "^19.1.0"
72
+ },
73
+ "peerDependenciesMeta": {
74
+ "@mui/material": {
75
+ "optional": true
76
+ },
77
+ "@mui/x-date-pickers": {
78
+ "optional": true
79
+ },
80
+ "@emotion/react": {
81
+ "optional": true
82
+ },
83
+ "@emotion/styled": {
84
+ "optional": true
85
+ },
86
+ "@emotion/cache": {
87
+ "optional": true
88
+ },
89
+ "date-fns": {
90
+ "optional": true
91
+ }
92
+ },
93
+ "devDependencies": {
94
+ "@changesets/cli": "^3.0.3",
95
+ "@emotion/cache": "^11.14.0",
96
+ "@emotion/react": "^11.14.0",
97
+ "@emotion/styled": "^11.14.0",
98
+ "@eslint/compat": "^1.2.9",
99
+ "@eslint/js": "^9.26.0",
100
+ "@fontsource/kanit": "^5.3.0",
101
+ "@fontsource/roboto": "^5.2.5",
102
+ "@mui/material": "^7.1.0",
103
+ "@mui/x-date-pickers": "^8.3.1",
104
+ "@playwright/test": "^1.62.1",
105
+ "@stylistic/eslint-plugin": "^3.1.0",
106
+ "@tailwindcss/vite": "^4.1.6",
107
+ "@testing-library/jest-dom": "^7.0.1",
108
+ "@testing-library/react": "^16.3.2",
109
+ "@testing-library/user-event": "^14.6.4",
110
+ "@types/node": "^26.2.0",
111
+ "@types/react": "^19.1.2",
112
+ "@types/react-dom": "^19.1.2",
113
+ "@types/react-syntax-highlighter": "^15.5.13",
114
+ "@typescript-eslint/eslint-plugin": "^8.32.0",
115
+ "@typescript-eslint/parser": "^8.32.0",
116
+ "@vitejs/plugin-react": "^4.4.1",
117
+ "@vitest/coverage-v8": "^4.1.10",
118
+ "@xyflow/react": "^12.6.4",
119
+ "date-fns": "^4.1.0",
120
+ "eslint": "^9.26.0",
121
+ "eslint-config-airbnb-extended": "^1.0.11",
122
+ "eslint-config-prettier": "^10.1.5",
123
+ "eslint-import-resolver-typescript": "^4.3.4",
124
+ "eslint-plugin-import-x": "^4.11.1",
125
+ "eslint-plugin-n": "^17.18.0",
126
+ "eslint-plugin-prettier": "^5.4.0",
127
+ "eslint-plugin-react-hooks": "^5.2.0",
128
+ "eslint-plugin-react-refresh": "^0.4.20",
129
+ "globals": "^16.0.0",
130
+ "happy-dom": "^20.11.2",
131
+ "iconoir-react": "^7.11.0",
132
+ "istanbul-lib-coverage": "^3.2.2",
133
+ "istanbul-lib-report": "^3.0.1",
134
+ "istanbul-reports": "^3.2.0",
135
+ "prettier": "^3.5.3",
136
+ "react": "^19.1.0",
137
+ "react-dom": "^19.1.0",
138
+ "react-syntax-highlighter": "^16.1.1",
139
+ "tailwindcss": "^4.1.6",
140
+ "typescript": "~5.8.3",
141
+ "typescript-eslint": "^8.32.0",
142
+ "vite": "^6.3.5",
143
+ "vite-plugin-istanbul": "^8.0.0",
144
+ "vitest": "^4.1.10"
145
+ },
146
+ "scripts": {
147
+ "dev": "vite",
148
+ "build": "tsc -b && vite build",
149
+ "build:lib": "vite build -c vite.lib.config.ts && tsc -p tsconfig.lib.json && node scripts/strip-dts-css.mjs && node scripts/fix-dts-extensions.mjs && node scripts/build-core-package.mjs",
150
+ "lint": "eslint . --max-warnings 0",
151
+ "preview": "vite preview",
152
+ "test": "vitest run",
153
+ "test:watch": "vitest",
154
+ "test:coverage": "vitest run --coverage",
155
+ "test:e2e": "playwright test",
156
+ "test:e2e:ui": "playwright test --ui",
157
+ "test:e2e:coverage": "rm -rf coverage-e2e-raw && E2E_COVERAGE=true playwright test",
158
+ "coverage:merge": "node scripts/merge-coverage.mjs",
159
+ "coverage:all": "pnpm test:coverage && pnpm test:e2e:coverage && pnpm coverage:merge",
160
+ "size": "node scripts/bundle-size.mjs",
161
+ "fixtures": "UPDATE_FIXTURES=1 vitest run tests/unit/fixtures",
162
+ "changeset": "changeset",
163
+ "version-packages": "changeset version",
164
+ "release": "pnpm build:lib && changeset publish",
165
+ "check:core": "node scripts/check-core-entry.mjs && tsc -p tests/types/nodenext"
166
+ }
6
167
  }