@nongt/visql 0.8.0 → 0.9.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 (42) hide show
  1. package/README.md +23 -360
  2. package/dist/{MuiTimePicker-BjywwrRm.js → MuiTimePicker-DRqT6ByZ.js} +1 -1
  3. package/dist/PipelineEditor-C10lng6j.js +10544 -0
  4. package/dist/core.js +336 -78
  5. package/dist/explain.js +165 -0
  6. package/dist/index.js +114 -98
  7. package/dist/issueLocation-BOSdd1JX.js +1106 -0
  8. package/dist/mui-date-pickers-host.js +1 -1
  9. package/dist/mui-date-pickers.js +1 -1
  10. package/dist/mui.js +95 -84
  11. package/dist/params-MMOdKWnW.js +2217 -0
  12. package/dist/{schema-DFC26AhZ.js → schema-dP_ISylQ.js} +270 -242
  13. package/dist/sql-import.js +1 -1
  14. package/dist/sqlGen-B7-2-i9V.js +903 -0
  15. package/dist/style.css +1 -1
  16. package/dist/tokens-DV5rTGMj.js +171 -0
  17. package/dist/types/core/components/flow/NodeActionFrame.d.ts +20 -0
  18. package/dist/types/core/components/flow/useNodeActions.d.ts +18 -0
  19. package/dist/types/core/i18n/defaultMessages.d.ts +15 -0
  20. package/dist/types/core/i18n/messages.d.ts +11 -0
  21. package/dist/types/core/planFindings.d.ts +27 -0
  22. package/dist/types/core/queryHelpers.d.ts +1 -1
  23. package/dist/types/core/schema.d.ts +35 -20
  24. package/dist/types/core/scopeQuery.d.ts +2 -2
  25. package/dist/types/core/theme/appearance.d.ts +27 -0
  26. package/dist/types/core/theme/looks.d.ts +14 -0
  27. package/dist/types/core/theme/tokens.d.ts +9 -1
  28. package/dist/types/core-api.d.ts +1 -0
  29. package/dist/types/explain/explainQuery.d.ts +53 -0
  30. package/dist/types/explain/postgresPlan.d.ts +12 -0
  31. package/dist/types/explain.d.ts +2 -0
  32. package/dist/types/features/queryEditor/CanvasBackground.d.ts +2 -0
  33. package/dist/types/features/queryEditor/ExplainButton.d.ts +13 -0
  34. package/dist/types/features/queryEditor/IssuesButton.d.ts +14 -6
  35. package/dist/types/features/queryEditor/PipelineEditor.d.ts +15 -0
  36. package/dist/types/features/queryEditor/planText.d.ts +8 -0
  37. package/dist/types/index.d.ts +2 -0
  38. package/package.json +14 -1
  39. package/dist/PipelineEditor-DtT1TPgd.js +0 -10214
  40. package/dist/core-api-jaQDPXVK.js +0 -1171
  41. package/dist/issueLocation-DEIwB1DW.js +0 -3290
  42. package/dist/tokens-BTaVMSOx.js +0 -95
@@ -0,0 +1,27 @@
1
+ import type { DefaultEdgeOptions } from '@xyflow/react';
2
+ /** The parts of the editor's look that aren't colours or sizes (those are
3
+ * theme tokens): what has to reach React Flow as a prop, or changes how
4
+ * the editor behaves. */
5
+ export interface Appearance {
6
+ /** The edges' shape, on every canvas. */
7
+ edges: 'smoothstep' | 'bezier' | 'step' | 'straight';
8
+ /** The canvas's pattern. */
9
+ background: 'lines' | 'dots' | 'cross' | 'none';
10
+ /** The pattern's spacing, in px. */
11
+ backgroundGap: number;
12
+ /** A group's backdrop: a box around its conditions, or a bar on its
13
+ * leading edge. */
14
+ groupFrame: 'box' | 'bar';
15
+ /** A node's buttons: in a toolbar above it while it's pointed at
16
+ * (selected, on a touch screen), and a row's while it's pointed at; or
17
+ * always beside them. */
18
+ actions: 'hover' | 'always';
19
+ }
20
+ /** CHARCOAL's (looks.ts). */
21
+ export declare const DEFAULT_APPEARANCE: Appearance;
22
+ declare const AppearanceContext: import("react").Context<Appearance>;
23
+ export declare function useAppearance(): Appearance;
24
+ export default AppearanceContext;
25
+ /** The edge shape asked for, as React Flow's `defaultEdgeOptions` (its
26
+ * bezier is called 'default'). */
27
+ export declare function useEdgeOptions(): DefaultEdgeOptions;
@@ -0,0 +1,14 @@
1
+ import { type Appearance } from './appearance.js';
2
+ import { type QueryBuilderTheme } from './tokens.js';
3
+ /** A whole look, colours and the rest: `<QueryBuilder {...NAVY} />`. A host
4
+ * makes its own the same way. */
5
+ export interface Look {
6
+ theme: QueryBuilderTheme;
7
+ appearance: Appearance;
8
+ }
9
+ /** The default: charcoal panels, white field cards, curved edges on dots,
10
+ * buttons beside each node. */
11
+ export declare const CHARCOAL: Look;
12
+ /** Navy panels, dark field cards and mint; smooth-step edges on a line grid,
13
+ * groups as a bar, and a node's buttons in a toolbar shown on hover. */
14
+ export declare const NAVY: Look;
@@ -1,6 +1,7 @@
1
1
  /** Every color the editor draws with, named by role rather than by hue so a
2
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.
3
+ * values for the same roles), and a few shapes (radii, the edges' width).
4
+ * The defaults are CHARCOAL's (looks.ts).
4
5
  *
5
6
  * Each token becomes a CSS custom property on the editor root — `canvasBg`
6
7
  * → `--qb-canvas-bg` — which components use through Tailwind utilities
@@ -39,6 +40,7 @@ export declare const DEFAULT_THEME: {
39
40
  fieldTextMuted: string;
40
41
  fieldTextSubtle: string;
41
42
  fieldGroupBorder: string;
43
+ fieldCardBorder: string;
42
44
  conditional: string;
43
45
  conditionalOnField: string;
44
46
  conditionalBorder: string;
@@ -53,9 +55,15 @@ export declare const DEFAULT_THEME: {
53
55
  secondary: string;
54
56
  danger: string;
55
57
  warning: string;
58
+ nodeRadius: string;
59
+ fieldRadius: string;
60
+ groupRadius: string;
61
+ edgeWidth: string;
56
62
  };
57
63
  export type ThemeToken = keyof typeof DEFAULT_THEME;
58
64
  export type QueryBuilderTheme = Record<ThemeToken, string>;
65
+ /** NAVY's colours (`looks.ts`): navy panels, dark field cards, mint. */
66
+ export declare const NAVY_THEME: QueryBuilderTheme;
59
67
  /** Class the editor root carries — tokens are scoped to it, so they never
60
68
  * leak into (or read from) the host page outside the editor. */
61
69
  export declare const ROOT_CLASS = "qb-root";
@@ -16,5 +16,6 @@ export type { ResolveName } from './core/resolveNames.js';
16
16
  export { astToParameterizedSql, astToSql, DIALECTS, DIALECT_LABELS, type NullSafeEqual, type ParameterizedSql, type ParameterizedSqlOptions, type SqlDialect, } from './core/sqlGen.js';
17
17
  export { EMPTY_SCHEMA, filterSchema, validateSchema, type DatabaseColumnType, type DatabaseSchema, type ColumnOption, type Relation, type SchemaIssue, type SchemaIssueKind, type Table, type TableColumn, type TableGroup, } from './core/schema.js';
18
18
  export { QUERY_ISSUE_KINDS, QUERY_WARNING_KINDS, validateQuery, type QueryIssue, type QueryIssueKind, type QueryWarningKind, type QueryIssueSeverity, type ValidateQueryOptions, } from './core/queryValidation.js';
19
+ export type { OnExplain, PlanFinding, PlanFindingKind } from './core/planFindings.js';
19
20
  export { default as issueLocation, type IssueLocationStep } from './core/issueLocation.js';
20
21
  export { DEFAULT_FUNCTIONS, functionsForDialect, type ArgDef, type ArgKind, type FunctionRegistry, type FunctionSignature, } from './core/functionRegistry.js';
@@ -0,0 +1,53 @@
1
+ import type { PlanFinding } from '../core/planFindings.js';
2
+ import type { QueryPipeline } from '../core/queryAst.js';
3
+ import { type ScopeRule } from '../core/scopeQuery.js';
4
+ import { type ParameterizedSqlOptions } from '../core/sqlGen.js';
5
+ /** The databases whose plans can be read. */
6
+ export type ExplainDialect = 'postgres';
7
+ export interface ExplainOptions extends ParameterizedSqlOptions {
8
+ /** The rule the query runs under (see scopeQuery), so the plan is the
9
+ * one the query really gets. Needs `schema`. */
10
+ scope?: ScopeRule;
11
+ }
12
+ export interface PlanReadOptions {
13
+ /** How many rows each table has, by its name in the database, e.g. from
14
+ * `SELECT relname, reltuples FROM pg_class`. A plan only gives the rows a
15
+ * scan returns, after its filter: with the sizes, a big table read
16
+ * whole for a few rows is reported as a missing index. */
17
+ tableRows?: Record<string, number> | ((table: string) => number | undefined);
18
+ /** Below this many rows, nothing is reported. Default 10,000. */
19
+ minRows?: number;
20
+ }
21
+ export interface ExplainedQuery {
22
+ /** The statement to run, EXPLAIN included, with `params` bound. */
23
+ sql: string;
24
+ params: unknown[];
25
+ /** What the plan EXPLAIN gave says, on the parts of the query given to
26
+ * explainQuery. Takes the plan as the driver returns it (rows with a
27
+ * `QUERY PLAN` column) or as its JSON text. */
28
+ findings: (plan: unknown, options?: PlanReadOptions) => PlanFinding[];
29
+ }
30
+ /** A table, sub query or shared query's place in the query, under the name
31
+ * the explained SQL gives it. */
32
+ export interface Place {
33
+ /** Where it is: its FROM or join. */
34
+ path: (string | number)[];
35
+ /** Where the query body it's in is. */
36
+ body: (string | number)[];
37
+ /** Its schema table, for a table. */
38
+ table?: string;
39
+ }
40
+ /** `query` with every table, sub query and shared query's place named
41
+ * apart, and where each new name leads. Innermost bodies first: an
42
+ * EXISTS sees the names around it, so a name left in it after its own are
43
+ * renamed is the outer one, and renaming the outer body reaches it. */
44
+ export declare function namePlaces(query: QueryPipeline): {
45
+ named: QueryPipeline;
46
+ places: Map<string, Place>;
47
+ };
48
+ /** The statement to explain `query` with, and a reader for the plan it
49
+ * gives. Call it as you'd write the query's SQL to run it: on the checked
50
+ * query, with the same options (and `scope`, the rule it runs under), so
51
+ * the plan is the one it really gets. The findings are on `query` itself,
52
+ * the parts a user sees in the editor. */
53
+ export declare function explainQuery(query: QueryPipeline, dialect: ExplainDialect, options?: ExplainOptions): ExplainedQuery;
@@ -0,0 +1,12 @@
1
+ import type { PlanFinding } from '../core/planFindings.js';
2
+ import type { QueryPipeline } from '../core/queryAst.js';
3
+ import type { ResolveName } from '../core/resolveNames.js';
4
+ import type { Place, PlanReadOptions } from './explainQuery.js';
5
+ interface Context extends PlanReadOptions {
6
+ places: Map<string, Place>;
7
+ named: QueryPipeline;
8
+ resolveName?: ResolveName;
9
+ }
10
+ /** What `plan` says about the query `context.named` was named from. */
11
+ export default function readPostgresPlan(plan: unknown, context: Context): PlanFinding[];
12
+ export {};
@@ -0,0 +1,2 @@
1
+ export { explainQuery, type ExplainDialect, type ExplainedQuery, type ExplainOptions, type PlanReadOptions, } from './explain/explainQuery.js';
2
+ export type { PlanFinding, PlanFindingKind } from './core/planFindings.js';
@@ -0,0 +1,2 @@
1
+ /** A canvas's backdrop, in the pattern `appearance` asks for. */
2
+ export default function CanvasBackground(): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,13 @@
1
+ interface Props {
2
+ onExplain: () => void;
3
+ checking: boolean;
4
+ /** Why it can't check now, if it can't (shown as its tooltip). */
5
+ blocked?: string;
6
+ /** What the host's onExplain threw last time. */
7
+ failed?: string;
8
+ }
9
+ /** Asks the host for the query plan's findings (`onExplain`), in the bar
10
+ * above the canvas. Only ever when pressed: EXPLAIN is a round trip to the
11
+ * database. Off, with the reason, while the query can't run. */
12
+ declare const ExplainButton: ({ onExplain, checking, blocked, failed, }: Props) => import("react/jsx-runtime").JSX.Element;
13
+ export default ExplainButton;
@@ -1,3 +1,4 @@
1
+ import type { PlanFinding } from '../../core/planFindings.js';
1
2
  import type { QueryPipeline } from '../../core/queryAst.js';
2
3
  import type { QueryIssue } from '../../core/queryValidation.js';
3
4
  interface Props {
@@ -6,11 +7,18 @@ interface Props {
6
7
  query?: QueryPipeline;
7
8
  /** An entry of the list was picked: show where that issue is. */
8
9
  onSelect: (issue: QueryIssue) => void;
10
+ /** What the query plan says (onExplain), listed after the warnings. */
11
+ findings?: PlanFinding[];
12
+ /** The findings are about the query before its latest edits. */
13
+ findingsOutdated?: boolean;
14
+ /** A finding was picked: show where it is. */
15
+ onSelectFinding?: (finding: PlanFinding) => void;
9
16
  }
10
- /** The query's problems, in the bar above the canvas: how many errors and
11
- * warnings (each its colour and icon). Opens their list (issue 132):
12
- * errors, then warnings, each entry by its place — a section of the
13
- * canvas, or a sub query — and saying where it is; picking one goes to
14
- * it. Nothing at all without problems. */
15
- declare const IssuesButton: ({ issues, query, onSelect }: Props) => import("react/jsx-runtime").JSX.Element | null;
17
+ /** The query's problems, in the bar above the canvas: how many errors,
18
+ * warnings and performance hints (each its colour and icon). Opens their
19
+ * list (issue 132): errors, then warnings, then what the query plan says
20
+ * (issue 186), each entry by its place — a section of the canvas, or a
21
+ * sub query — and saying where it is; picking one goes to it. Nothing at
22
+ * all without any. */
23
+ declare const IssuesButton: ({ issues, query, onSelect, findings, findingsOutdated, onSelectFinding, }: Props) => import("react/jsx-runtime").JSX.Element | null;
16
24
  export default IssuesButton;
@@ -5,6 +5,7 @@ import { type QueryValue } from '../../core/queryAst.js';
5
5
  import { type DatabaseSchema, type SchemaIssue, type Table, type TableColumn } from '../../core/schema.js';
6
6
  import type { SqlDialect } from '../../core/sqlGen.js';
7
7
  import { type QueryIssue, type QueryIssueSeverity, type QueryWarningKind } from '../../core/queryValidation.js';
8
+ import { type Appearance } from '../../core/theme/appearance.js';
8
9
  import { type TablePickerOptions } from '../../core/tablePickerOptions.js';
9
10
  import { type BetweenOnText } from '../../core/BetweenOnTextContext.js';
10
11
  import { type RenderValueInput } from '../../core/ValueInputContext.js';
@@ -14,6 +15,7 @@ import type { UIComponents } from '../../core/ui/types.js';
14
15
  import { type QueryBuilderTheme } from '../../core/theme/tokens.js';
15
16
  import type { SectionLabels } from './sectionLabels.js';
16
17
  import { type OnRun } from './run.js';
18
+ import type { OnExplain } from '../../core/planFindings.js';
17
19
  export interface PipelineEditorProps {
18
20
  className?: string;
19
21
  /** The database the builder works against — its tables/columns populate
@@ -95,6 +97,9 @@ export interface PipelineEditorProps {
95
97
  * open), but nothing can be changed — no edit controls, inputs disabled,
96
98
  * no dragging, no undo/redo. */
97
99
  readOnly?: boolean;
100
+ /** How the outline in the corner starts: 'open' (default), or 'folded'
101
+ * to its title, for a small editor. The user can fold it either way. */
102
+ outline?: 'open' | 'folded';
98
103
  /** Which tables this user may see and add. Hidden tables are never
99
104
  * offered in pickers nor added automatically (not even as an
100
105
  * intermediate join); relations through them are ignored. The full
@@ -117,6 +122,11 @@ export interface PipelineEditorProps {
117
122
  * Rows — for a tall, narrow space. Combines with `direction`, which says
118
123
  * which side things start from. */
119
124
  orientation?: FlowOrientation;
125
+ /** How the canvases look beyond colours: edge shape, canvas pattern, how
126
+ * a group is drawn, where a node's buttons are. Unset parts keep
127
+ * `DEFAULT_APPEARANCE`'s (CHARCOAL's); a whole look such as NAVY sets
128
+ * this and `theme` together. */
129
+ appearance?: Partial<Appearance>;
120
130
  /** The EXISTS button ("has related rows"): which related tables its menu
121
131
  * lists (`relations`: 'toMany', the default, or 'both') and where it's
122
132
  * offered (`in`: ['where', 'having'] by default, 'joinOn' when asked
@@ -157,6 +167,11 @@ export interface PipelineEditorProps {
157
167
  * server. Return (or resolve to) a RunResult to show its rows under the
158
168
  * canvas; return nothing to show them yourself. See OnRun. */
159
169
  onRun?: OnRun;
170
+ /** Gets what the query plan (EXPLAIN) says about the query: a "Check
171
+ * performance" button above the canvas calls it, and the findings join the
172
+ * problems list, after the warnings. Gets the query, not SQL, like onRun.
173
+ * See OnExplain and PlanFinding. */
174
+ onExplain?: OnExplain;
160
175
  /** Warnings not to show, by kind (see QUERY_WARNING_KINDS) — in the
161
176
  * problems list, `onIssues` and on the canvas (the FROM node's fan-out
162
177
  * note). E.g. ['crossJoin'] for reports that CROSS JOIN on purpose.
@@ -0,0 +1,8 @@
1
+ import type { Messages } from '../../core/i18n/messages.js';
2
+ import type { PlanFinding } from '../../core/planFindings.js';
3
+ import type { QueryPipeline } from '../../core/queryAst.js';
4
+ import { type DatabaseSchema } from '../../core/schema.js';
5
+ /** A finding in the user's words: the known kinds from `messages`, naming
6
+ * the table as the canvas does (its alias, else its label); anything else
7
+ * by the host's own `message`. */
8
+ export default function planText(finding: PlanFinding, query: QueryPipeline | undefined, schema: DatabaseSchema, m: Messages): string;
@@ -11,4 +11,6 @@ export type { ExistsOptions, ExistsPlace, ExistsRelations, } from './core/exists
11
11
  export type { RenderValueInput, ValueInputProps } from './core/ValueInputContext.js';
12
12
  export { DEFAULT_MESSAGES, type Messages } from './core/i18n/messages.js';
13
13
  export { DEFAULT_THEME, type QueryBuilderTheme, type ThemeToken, } from './core/theme/tokens.js';
14
+ export { DEFAULT_APPEARANCE, type Appearance } from './core/theme/appearance.js';
15
+ export { CHARCOAL, NAVY, type Look } from './core/theme/looks.js';
14
16
  export type * from './core/ui/types.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nongt/visql",
3
- "version": "0.8.0",
3
+ "version": "0.9.0",
4
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
5
  "keywords": [
6
6
  "sql",
@@ -55,6 +55,10 @@
55
55
  "types": "./dist/types/sql-import.d.ts",
56
56
  "import": "./dist/sql-import.js"
57
57
  },
58
+ "./explain": {
59
+ "types": "./dist/types/explain.d.ts",
60
+ "import": "./dist/explain.js"
61
+ },
58
62
  "./style.css": "./dist/style.css"
59
63
  },
60
64
  "typesVersions": {
@@ -76,6 +80,9 @@
76
80
  ],
77
81
  "sql-import": [
78
82
  "./dist/types/sql-import.d.ts"
83
+ ],
84
+ "explain": [
85
+ "./dist/types/explain.d.ts"
79
86
  ]
80
87
  }
81
88
  },
@@ -166,9 +173,15 @@
166
173
  "vite-plugin-istanbul": "^8.0.0",
167
174
  "vitest": "^4.1.10"
168
175
  },
176
+ "homepage": "https://nongt.github.io/visql/",
169
177
  "scripts": {
170
178
  "dev": "vite",
171
179
  "build": "tsc -b && vite build",
180
+ "site:dev": "pnpm --filter visql-site dev",
181
+ "site:build": "pnpm --filter visql-site build && vite build --base /visql/playground/ --outDir site/dist/playground --emptyOutDir --sourcemap false && node scripts/check-site.mjs",
182
+ "site:preview": "pnpm --filter visql-site preview",
183
+ "site:check": "pnpm --filter visql-site check",
184
+ "test:site": "playwright test -c playwright.site.config.ts",
172
185
  "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",
173
186
  "lint": "eslint . --max-warnings 0",
174
187
  "preview": "vite preview",