@dudousxd/nestjs-catalog-react 0.1.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.
- package/LICENSE-bklit +21 -0
- package/README.md +282 -0
- package/dist/AccessConsole.d.ts +40 -0
- package/dist/AccessConsole.js +160 -0
- package/dist/CatalogManager.d.ts +12 -0
- package/dist/CatalogManager.js +123 -0
- package/dist/ConnectionPanel.d.ts +41 -0
- package/dist/ConnectionPanel.js +228 -0
- package/dist/CoverageLedger.d.ts +16 -0
- package/dist/CoverageLedger.js +16 -0
- package/dist/DashboardBoard.d.ts +10 -0
- package/dist/DashboardBoard.js +206 -0
- package/dist/EditableField.d.ts +18 -0
- package/dist/EditableField.js +61 -0
- package/dist/FlowView.d.ts +13 -0
- package/dist/FlowView.js +93 -0
- package/dist/GovernanceTimeline.d.ts +16 -0
- package/dist/GovernanceTimeline.js +93 -0
- package/dist/ObjectExplorer.d.ts +9 -0
- package/dist/ObjectExplorer.js +153 -0
- package/dist/PipelineConsole.d.ts +20 -0
- package/dist/PipelineConsole.js +272 -0
- package/dist/QueryConsole.d.ts +11 -0
- package/dist/QueryConsole.js +144 -0
- package/dist/SavedQueryPanel.d.ts +16 -0
- package/dist/SavedQueryPanel.js +78 -0
- package/dist/TraceExplorer.d.ts +54 -0
- package/dist/TraceExplorer.js +342 -0
- package/dist/TransformEditor.d.ts +23 -0
- package/dist/TransformEditor.js +129 -0
- package/dist/WorkflowCanvas.d.ts +24 -0
- package/dist/WorkflowCanvas.js +701 -0
- package/dist/charts/bklit/animation.d.ts +19 -0
- package/dist/charts/bklit/animation.js +28 -0
- package/dist/charts/bklit/area-chart-loading.d.ts +33 -0
- package/dist/charts/bklit/area-chart-loading.js +30 -0
- package/dist/charts/bklit/area-chart.d.ts +47 -0
- package/dist/charts/bklit/area-chart.js +65 -0
- package/dist/charts/bklit/area-gradient-defs.d.ts +28 -0
- package/dist/charts/bklit/area-gradient-defs.js +23 -0
- package/dist/charts/bklit/area.d.ts +75 -0
- package/dist/charts/bklit/area.js +112 -0
- package/dist/charts/bklit/bar-chart-loading.d.ts +16 -0
- package/dist/charts/bklit/bar-chart-loading.js +22 -0
- package/dist/charts/bklit/bar-chart.d.ts +54 -0
- package/dist/charts/bklit/bar-chart.js +440 -0
- package/dist/charts/bklit/bar-depth-geometry.d.ts +41 -0
- package/dist/charts/bklit/bar-depth-geometry.js +46 -0
- package/dist/charts/bklit/bar-squares-layout.d.ts +36 -0
- package/dist/charts/bklit/bar-squares-layout.js +46 -0
- package/dist/charts/bklit/bar-squares.d.ts +48 -0
- package/dist/charts/bklit/bar-squares.js +206 -0
- package/dist/charts/bklit/bar-x-axis.d.ts +13 -0
- package/dist/charts/bklit/bar-x-axis.js +81 -0
- package/dist/charts/bklit/bar-y-axis.d.ts +11 -0
- package/dist/charts/bklit/bar-y-axis.js +72 -0
- package/dist/charts/bklit/bar.d.ts +40 -0
- package/dist/charts/bklit/bar.js +207 -0
- package/dist/charts/bklit/chart-child-passthrough.d.ts +25 -0
- package/dist/charts/bklit/chart-child-passthrough.js +82 -0
- package/dist/charts/bklit/chart-config-context.d.ts +34 -0
- package/dist/charts/bklit/chart-config-context.js +55 -0
- package/dist/charts/bklit/chart-context.d.ts +207 -0
- package/dist/charts/bklit/chart-context.js +200 -0
- package/dist/charts/bklit/chart-defs.d.ts +21 -0
- package/dist/charts/bklit/chart-defs.js +57 -0
- package/dist/charts/bklit/chart-formatters.d.ts +16 -0
- package/dist/charts/bklit/chart-formatters.js +26 -0
- package/dist/charts/bklit/chart-legend-hover.d.ts +21 -0
- package/dist/charts/bklit/chart-legend-hover.js +26 -0
- package/dist/charts/bklit/chart-loading-label.d.ts +9 -0
- package/dist/charts/bklit/chart-loading-label.js +29 -0
- package/dist/charts/bklit/chart-phase.d.ts +39 -0
- package/dist/charts/bklit/chart-phase.js +20 -0
- package/dist/charts/bklit/chart-reveal-clip.d.ts +32 -0
- package/dist/charts/bklit/chart-reveal-clip.js +23 -0
- package/dist/charts/bklit/dash-tail-stroke.d.ts +17 -0
- package/dist/charts/bklit/dash-tail-stroke.js +21 -0
- package/dist/charts/bklit/decimate-time-series.d.ts +18 -0
- package/dist/charts/bklit/decimate-time-series.js +120 -0
- package/dist/charts/bklit/fade-edges.d.ts +42 -0
- package/dist/charts/bklit/fade-edges.js +34 -0
- package/dist/charts/bklit/filter-data-by-x-domain.d.ts +13 -0
- package/dist/charts/bklit/filter-data-by-x-domain.js +50 -0
- package/dist/charts/bklit/generate-chart-skeleton-data.d.ts +24 -0
- package/dist/charts/bklit/generate-chart-skeleton-data.js +33 -0
- package/dist/charts/bklit/grid.d.ts +57 -0
- package/dist/charts/bklit/grid.js +88 -0
- package/dist/charts/bklit/highlight-segment-bounds.d.ts +26 -0
- package/dist/charts/bklit/highlight-segment-bounds.js +35 -0
- package/dist/charts/bklit/highlight-segment.d.ts +30 -0
- package/dist/charts/bklit/highlight-segment.js +22 -0
- package/dist/charts/bklit/indicator-fade.d.ts +23 -0
- package/dist/charts/bklit/indicator-fade.js +41 -0
- package/dist/charts/bklit/line-chart-loading.d.ts +33 -0
- package/dist/charts/bklit/line-chart-loading.js +30 -0
- package/dist/charts/bklit/line-chart.d.ts +45 -0
- package/dist/charts/bklit/line-chart.js +99 -0
- package/dist/charts/bklit/line-loading-pulse.d.ts +19 -0
- package/dist/charts/bklit/line-loading-pulse.js +132 -0
- package/dist/charts/bklit/line-loading-timing.d.ts +18 -0
- package/dist/charts/bklit/line-loading-timing.js +18 -0
- package/dist/charts/bklit/line-series-terminal-marker.d.ts +15 -0
- package/dist/charts/bklit/line-series-terminal-marker.js +54 -0
- package/dist/charts/bklit/line.d.ts +63 -0
- package/dist/charts/bklit/line.js +104 -0
- package/dist/charts/bklit/loading-sweep.d.ts +65 -0
- package/dist/charts/bklit/loading-sweep.js +182 -0
- package/dist/charts/bklit/motion-utils.d.ts +17 -0
- package/dist/charts/bklit/motion-utils.js +27 -0
- package/dist/charts/bklit/path-stroke-utils.d.ts +28 -0
- package/dist/charts/bklit/path-stroke-utils.js +64 -0
- package/dist/charts/bklit/pattern-area.d.ts +20 -0
- package/dist/charts/bklit/pattern-area.js +27 -0
- package/dist/charts/bklit/pattern-preset.d.ts +34 -0
- package/dist/charts/bklit/pattern-preset.js +82 -0
- package/dist/charts/bklit/projection-config.d.ts +19 -0
- package/dist/charts/bklit/projection-config.js +88 -0
- package/dist/charts/bklit/projection-line-end-marker.d.ts +14 -0
- package/dist/charts/bklit/projection-line-end-marker.js +35 -0
- package/dist/charts/bklit/projection-line.d.ts +39 -0
- package/dist/charts/bklit/projection-line.js +87 -0
- package/dist/charts/bklit/projection-utils.d.ts +54 -0
- package/dist/charts/bklit/projection-utils.js +252 -0
- package/dist/charts/bklit/reference-area-config.d.ts +18 -0
- package/dist/charts/bklit/reference-area-config.js +47 -0
- package/dist/charts/bklit/reference-area-registration-context.d.ts +7 -0
- package/dist/charts/bklit/reference-area-registration-context.js +15 -0
- package/dist/charts/bklit/series-bar-layout.d.ts +26 -0
- package/dist/charts/bklit/series-bar-layout.js +39 -0
- package/dist/charts/bklit/series-dash-tail-overlay.d.ts +16 -0
- package/dist/charts/bklit/series-dash-tail-overlay.js +47 -0
- package/dist/charts/bklit/series-highlight-layer.d.ts +31 -0
- package/dist/charts/bklit/series-highlight-layer.js +20 -0
- package/dist/charts/bklit/series-hover-dim.d.ts +28 -0
- package/dist/charts/bklit/series-hover-dim.js +34 -0
- package/dist/charts/bklit/series-markers.d.ts +13 -0
- package/dist/charts/bklit/series-markers.js +106 -0
- package/dist/charts/bklit/series-path-utils.d.ts +18 -0
- package/dist/charts/bklit/series-path-utils.js +68 -0
- package/dist/charts/bklit/series-point-marker.d.ts +47 -0
- package/dist/charts/bklit/series-point-marker.js +47 -0
- package/dist/charts/bklit/static-chart-preview-context.d.ts +15 -0
- package/dist/charts/bklit/static-chart-preview-context.js +20 -0
- package/dist/charts/bklit/time-series-chart-shell.d.ts +46 -0
- package/dist/charts/bklit/time-series-chart-shell.js +398 -0
- package/dist/charts/bklit/tooltip/chart-tooltip.d.ts +75 -0
- package/dist/charts/bklit/tooltip/chart-tooltip.js +158 -0
- package/dist/charts/bklit/tooltip/date-ticker.d.ts +10 -0
- package/dist/charts/bklit/tooltip/date-ticker.js +85 -0
- package/dist/charts/bklit/tooltip/index.d.ts +15 -0
- package/dist/charts/bklit/tooltip/index.js +15 -0
- package/dist/charts/bklit/tooltip/tooltip-box.d.ts +56 -0
- package/dist/charts/bklit/tooltip/tooltip-box.js +122 -0
- package/dist/charts/bklit/tooltip/tooltip-content.d.ts +26 -0
- package/dist/charts/bklit/tooltip/tooltip-content.js +8 -0
- package/dist/charts/bklit/tooltip/tooltip-dot.d.ts +27 -0
- package/dist/charts/bklit/tooltip/tooltip-dot.js +62 -0
- package/dist/charts/bklit/tooltip/tooltip-indicator.d.ts +44 -0
- package/dist/charts/bklit/tooltip/tooltip-indicator.js +73 -0
- package/dist/charts/bklit/use-animated-series-path.d.ts +18 -0
- package/dist/charts/bklit/use-animated-series-path.js +101 -0
- package/dist/charts/bklit/use-animated-y-domains.d.ts +13 -0
- package/dist/charts/bklit/use-animated-y-domains.js +158 -0
- package/dist/charts/bklit/use-chart-interaction.d.ts +40 -0
- package/dist/charts/bklit/use-chart-interaction.js +252 -0
- package/dist/charts/bklit/use-chart-phase-orchestrator.d.ts +22 -0
- package/dist/charts/bklit/use-chart-phase-orchestrator.js +147 -0
- package/dist/charts/bklit/use-enter-complete.d.ts +16 -0
- package/dist/charts/bklit/use-enter-complete.js +22 -0
- package/dist/charts/bklit/use-grid-shimmer.d.ts +15 -0
- package/dist/charts/bklit/use-grid-shimmer.js +71 -0
- package/dist/charts/bklit/use-highlight-segment.d.ts +22 -0
- package/dist/charts/bklit/use-highlight-segment.js +42 -0
- package/dist/charts/bklit/use-mount-progress.d.ts +12 -0
- package/dist/charts/bklit/use-mount-progress.js +30 -0
- package/dist/charts/bklit/use-scheduled-tooltip.d.ts +8 -0
- package/dist/charts/bklit/use-scheduled-tooltip.js +84 -0
- package/dist/charts/bklit/visx-pattern.d.ts +27 -0
- package/dist/charts/bklit/visx-pattern.js +28 -0
- package/dist/charts/bklit/x-axis.d.ts +26 -0
- package/dist/charts/bklit/x-axis.js +423 -0
- package/dist/charts/bklit/y-axis-scales.d.ts +34 -0
- package/dist/charts/bklit/y-axis-scales.js +80 -0
- package/dist/charts/bklit/y-axis-ticks.d.ts +20 -0
- package/dist/charts/bklit/y-axis-ticks.js +32 -0
- package/dist/charts/bklit/y-domain-utils.d.ts +26 -0
- package/dist/charts/bklit/y-domain-utils.js +96 -0
- package/dist/charts/bklit.d.ts +2 -0
- package/dist/charts/bklit.js +90 -0
- package/dist/charts/components/shimmering-text.d.ts +31 -0
- package/dist/charts/components/shimmering-text.js +39 -0
- package/dist/charts/css.d.ts +35 -0
- package/dist/charts/css.js +64 -0
- package/dist/charts/recharts.d.ts +28 -0
- package/dist/charts/recharts.js +48 -0
- package/dist/charts/registry.d.ts +34 -0
- package/dist/charts/registry.js +60 -0
- package/dist/charts/skeleton.d.ts +55 -0
- package/dist/charts/skeleton.js +66 -0
- package/dist/cn.d.ts +10 -0
- package/dist/cn.js +13 -0
- package/dist/context.d.ts +346 -0
- package/dist/context.js +95 -0
- package/dist/index.d.ts +30 -0
- package/dist/index.js +65 -0
- package/dist/routes.d.ts +70 -0
- package/dist/routes.js +73 -0
- package/dist/source-fields.d.ts +111 -0
- package/dist/source-fields.js +204 -0
- package/dist/ui/chart.d.ts +54 -0
- package/dist/ui/chart.js +122 -0
- package/dist/ui/dialog.d.ts +27 -0
- package/dist/ui/dialog.js +24 -0
- package/dist/ui/field.d.ts +29 -0
- package/dist/ui/field.js +31 -0
- package/dist/ui/select.d.ts +42 -0
- package/dist/ui/select.js +30 -0
- package/dist/ui/sheet.d.ts +38 -0
- package/dist/ui/sheet.js +37 -0
- package/dist/ui/switch.d.ts +17 -0
- package/dist/ui/switch.js +14 -0
- package/dist/ui/tabs.d.ts +30 -0
- package/dist/ui/tabs.js +36 -0
- package/dist/ui/tooltip.d.ts +37 -0
- package/dist/ui/tooltip.js +43 -0
- package/dist/workflow/graph.d.ts +112 -0
- package/dist/workflow/graph.js +297 -0
- package/dist/workflow/index.d.ts +16 -0
- package/dist/workflow/index.js +16 -0
- package/dist/workflow/model.d.ts +151 -0
- package/dist/workflow/model.js +97 -0
- package/dist/workflow/name.d.ts +28 -0
- package/dist/workflow/name.js +28 -0
- package/dist/workflow/nodes.d.ts +40 -0
- package/dist/workflow/nodes.js +86 -0
- package/dist/workflow/validate.d.ts +104 -0
- package/dist/workflow/validate.js +199 -0
- package/package.json +148 -0
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useMutation, useQuery } from '@tanstack/react-query';
|
|
3
|
+
import { AlertTriangle, History, Layers, Play, Sparkles, TableIcon } from 'lucide-react';
|
|
4
|
+
import { Highlight, themes } from 'prism-react-renderer';
|
|
5
|
+
import { useMemo, useRef, useState } from 'react';
|
|
6
|
+
import { SavedQueryPanel } from './SavedQueryPanel';
|
|
7
|
+
import { cn } from './cn';
|
|
8
|
+
import { useCatalogClient } from './context';
|
|
9
|
+
import { Tooltip, TooltipProvider } from './ui/tooltip';
|
|
10
|
+
const MUTED = 'text-zinc-400 dark:text-zinc-500';
|
|
11
|
+
const PANEL = 'bg-white dark:bg-zinc-900';
|
|
12
|
+
const RULE = 'border-zinc-200 dark:border-zinc-800';
|
|
13
|
+
const STARTER = `-- Two relations per object type, and the difference is the point:
|
|
14
|
+
-- <type> the committed snapshot
|
|
15
|
+
-- obj_<type> every load ever written, with _snapshot_id
|
|
16
|
+
--
|
|
17
|
+
-- Across tables:
|
|
18
|
+
-- SELECT v.assetId, COUNT(*) AS work_orders
|
|
19
|
+
-- FROM mvr v JOIN subwo s ON s.assetId = v.assetId
|
|
20
|
+
-- GROUP BY v.assetId ORDER BY work_orders DESC
|
|
21
|
+
--
|
|
22
|
+
-- Across versions:
|
|
23
|
+
-- SELECT _snapshot_id, AVG(\`Risk Score\`) FROM obj_mvr GROUP BY _snapshot_id
|
|
24
|
+
|
|
25
|
+
SELECT * FROM `;
|
|
26
|
+
export function QueryConsole({ onGenerate, maxRows = 500 }) {
|
|
27
|
+
const client = useCatalogClient();
|
|
28
|
+
const [sql, setSql] = useState(STARTER);
|
|
29
|
+
const [prompt, setPrompt] = useState('');
|
|
30
|
+
const [askOpen, setAskOpen] = useState(false);
|
|
31
|
+
const editorRef = useRef(null);
|
|
32
|
+
const { data: relations = [] } = useQuery({
|
|
33
|
+
queryKey: ['catalog', 'query', 'relations'],
|
|
34
|
+
queryFn: () => client.queryRelations(),
|
|
35
|
+
staleTime: 60_000,
|
|
36
|
+
});
|
|
37
|
+
const run = useMutation({
|
|
38
|
+
mutationFn: () => client.runQuery({ sql, maxRows }),
|
|
39
|
+
});
|
|
40
|
+
const generate = useMutation({
|
|
41
|
+
mutationFn: async () => {
|
|
42
|
+
if (!onGenerate)
|
|
43
|
+
throw new Error('No assistant is configured.');
|
|
44
|
+
return onGenerate(prompt, relations);
|
|
45
|
+
},
|
|
46
|
+
onSuccess: (generated) => {
|
|
47
|
+
setSql(generated);
|
|
48
|
+
setAskOpen(false);
|
|
49
|
+
setPrompt('');
|
|
50
|
+
},
|
|
51
|
+
});
|
|
52
|
+
const grouped = useMemo(() => {
|
|
53
|
+
const byType = new Map();
|
|
54
|
+
for (const relation of relations) {
|
|
55
|
+
const list = byType.get(relation.objectType) ?? [];
|
|
56
|
+
list.push(relation);
|
|
57
|
+
byType.set(relation.objectType, list);
|
|
58
|
+
}
|
|
59
|
+
return [...byType.entries()].sort(([a], [b]) => a.localeCompare(b));
|
|
60
|
+
}, [relations]);
|
|
61
|
+
function insert(text) {
|
|
62
|
+
const editor = editorRef.current;
|
|
63
|
+
if (!editor) {
|
|
64
|
+
setSql((current) => `${current}${text}`);
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
const start = editor.selectionStart;
|
|
68
|
+
const end = editor.selectionEnd;
|
|
69
|
+
setSql((current) => current.slice(0, start) + text + current.slice(end));
|
|
70
|
+
requestAnimationFrame(() => {
|
|
71
|
+
editor.focus();
|
|
72
|
+
editor.selectionStart = editor.selectionEnd = start + text.length;
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
function onEditorKeyDown(event) {
|
|
76
|
+
// Cmd/Ctrl+Enter runs, the way every SQL console does.
|
|
77
|
+
if ((event.metaKey || event.ctrlKey) && event.key === 'Enter') {
|
|
78
|
+
event.preventDefault();
|
|
79
|
+
run.mutate();
|
|
80
|
+
}
|
|
81
|
+
// A textarea that eats Tab is a textarea nobody can leave by keyboard, so
|
|
82
|
+
// Tab still moves focus; indentation is Shift-agnostic two spaces on Enter.
|
|
83
|
+
}
|
|
84
|
+
const error = run.error instanceof Error ? run.error.message : null;
|
|
85
|
+
return (_jsx(TooltipProvider, { children: _jsxs("div", { className: "flex h-full min-h-0", children: [_jsxs("aside", { className: cn('flex w-64 shrink-0 flex-col border-r', RULE, PANEL), children: [_jsx("div", { className: cn('border-b px-3 py-2', RULE), children: _jsx("p", { className: cn('font-mono text-[10px] uppercase tracking-[0.14em]', MUTED), children: "Relations" }) }), _jsxs("div", { className: "min-h-0 flex-1 overflow-y-auto p-2", children: [grouped.length === 0 && (_jsx("p", { className: cn('px-2 py-6 text-center text-xs', MUTED), children: "Nothing has been published yet." })), grouped.map(([objectType, list]) => (_jsxs("div", { className: "mb-3", children: [_jsx("div", { className: cn('px-2 py-1 font-mono text-[10px] uppercase tracking-[0.14em]', MUTED), children: objectType }), list.map((relation) => (_jsx(RelationRow, { relation: relation, onInsert: insert }, relation.name)))] }, objectType)))] }), _jsx(SavedQueryPanel, { currentSql: sql, onLoad: (query) => setSql(query.sql) })] }), _jsxs("div", { className: "flex min-w-0 flex-1 flex-col", children: [_jsxs("div", { className: cn('flex shrink-0 items-center gap-2 border-b px-4 py-2', RULE, PANEL), children: [_jsxs("button", { type: "button", onClick: () => run.mutate(), disabled: run.isPending, className: "flex items-center gap-1.5 rounded-md bg-zinc-950 px-3 py-1.5 text-xs text-zinc-50 transition-colors hover:bg-zinc-800 disabled:opacity-50 dark:bg-zinc-100 dark:text-zinc-950", children: [_jsx(Play, { size: 12 }), run.isPending ? 'Running…' : 'Run'] }), _jsx("span", { className: cn('font-mono text-[10px]', MUTED), children: "\u2318\u21B5" }), onGenerate && (_jsxs("button", { type: "button", onClick: () => setAskOpen((open) => !open), className: cn('flex items-center gap-1.5 rounded-md border px-3 py-1.5 text-xs transition-colors', RULE, 'hover:bg-zinc-50 dark:hover:bg-zinc-800', askOpen && 'bg-violet-100 dark:bg-violet-950'), children: [_jsx(Sparkles, { size: 12 }), "Ask"] })), run.data && (_jsxs("span", { className: cn('ml-auto font-mono text-[11px]', MUTED), children: [run.data.rowCount, " rows \u00B7 ", run.data.cached ? 'cached' : `${run.data.elapsedMs} ms`, run.data.truncated && ' · capped'] }))] }), askOpen && onGenerate && (_jsxs("div", { className: cn('shrink-0 border-b bg-violet-50/60 px-4 py-3 dark:bg-violet-950/20', RULE), children: [_jsxs("form", { className: "flex gap-2", onSubmit: (e) => {
|
|
86
|
+
e.preventDefault();
|
|
87
|
+
generate.mutate();
|
|
88
|
+
}, children: [_jsx("input", { value: prompt, onChange: (e) => setPrompt(e.target.value), placeholder: "Which vehicles gained the most work orders since the last load?", "aria-label": "Describe the query", className: cn('flex-1 rounded-md border px-3 py-1.5 text-sm outline-none', RULE, PANEL, 'focus:border-violet-500 focus:ring-2 focus:ring-violet-500/15') }), _jsx("button", { type: "submit", disabled: generate.isPending || prompt.trim().length === 0, className: "rounded-md bg-violet-600 px-3 py-1.5 text-xs text-white disabled:opacity-40", children: generate.isPending ? 'Writing…' : 'Write the SQL' })] }), _jsx("p", { className: cn('mt-1.5 text-[11px]', MUTED), children: "It sees the relation and column names above, never the rows. Read the SQL before running it." }), generate.error && (_jsx("p", { className: "mt-1 text-[11px] text-red-600", children: generate.error instanceof Error
|
|
89
|
+
? generate.error.message
|
|
90
|
+
: 'The assistant could not write that.' }))] })), _jsx(SqlEditor, { value: sql, onChange: setSql, onKeyDown: onEditorKeyDown, textareaRef: editorRef }), _jsxs("div", { className: "min-h-0 flex-1 overflow-auto", children: [error && (_jsxs("div", { className: "m-4 flex items-start gap-2 rounded-md border border-red-200 bg-red-50 px-3 py-2 text-xs text-red-700 dark:border-red-900 dark:bg-red-950/40 dark:text-red-300", children: [_jsx(AlertTriangle, { size: 14, className: "mt-0.5 shrink-0" }), _jsx("span", { className: "font-mono leading-relaxed", children: error })] })), run.data && _jsx(ResultTable, { result: run.data }), !run.data && !error && (_jsx("p", { className: cn('p-8 text-center text-sm', MUTED), children: "Results appear here." }))] })] })] }) }));
|
|
91
|
+
}
|
|
92
|
+
function RelationRow({ relation, onInsert, }) {
|
|
93
|
+
const [open, setOpen] = useState(false);
|
|
94
|
+
const Icon = relation.kind === 'current' ? TableIcon : History;
|
|
95
|
+
return (_jsxs("div", { children: [_jsxs("div", { className: "flex items-center", children: [_jsx(Tooltip, { content: relation.description, side: "right", children: _jsxs("button", { type: "button", onClick: () => onInsert(relation.name), className: cn('flex min-w-0 flex-1 items-center gap-1.5 rounded-md px-2 py-1 text-left', 'hover:bg-zinc-50 dark:hover:bg-zinc-800'), children: [_jsx(Icon, { size: 12, className: relation.kind === 'current' ? 'text-emerald-600' : 'text-amber-600' }), _jsx("span", { className: "truncate font-mono text-[11px]", children: relation.name })] }) }), _jsx("button", { type: "button", onClick: () => setOpen((o) => !o), "aria-label": `${open ? 'Hide' : 'Show'} columns of ${relation.name}`, className: cn('rounded-sm px-1 py-1 text-[10px]', MUTED), children: _jsx(Layers, { size: 11 }) })] }), open && (_jsx("div", { className: "ml-4 border-l border-zinc-100 pl-2 dark:border-zinc-800", children: relation.columns.map((column) => (_jsxs("button", { type: "button", onClick: () => onInsert(column.name), className: "flex w-full items-baseline justify-between gap-2 rounded-sm px-1 py-0.5 text-left hover:bg-zinc-50 dark:hover:bg-zinc-800", children: [_jsx("span", { className: "truncate font-mono text-[10px]", children: column.name }), _jsx("span", { className: cn('font-mono text-[9px] uppercase', MUTED), children: column.type })] }, column.name))) }))] }));
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* A highlighted editor built from a textarea under a `<pre>`.
|
|
99
|
+
*
|
|
100
|
+
* The textarea keeps every behaviour a text input is supposed to have —
|
|
101
|
+
* selection, undo, IME, screen readers, native keyboard shortcuts — while the
|
|
102
|
+
* highlighted copy sits behind it, transparent text, identical metrics. A
|
|
103
|
+
* contenteditable would look the same and lose all of it.
|
|
104
|
+
*/
|
|
105
|
+
function SqlEditor({ value, onChange, onKeyDown, textareaRef, }) {
|
|
106
|
+
const shared = 'm-0 p-4 font-mono text-[13px] leading-[1.55] whitespace-pre-wrap break-words';
|
|
107
|
+
return (
|
|
108
|
+
// Two boxes, and the division between them is the whole point.
|
|
109
|
+
//
|
|
110
|
+
// The outer one is the *only* thing that scrolls. The inner one has no
|
|
111
|
+
// height of its own, so it grows to whatever the highlighted code needs —
|
|
112
|
+
// which is what lets the textarea be `inset-0` and still cover every line
|
|
113
|
+
// rather than only the visible ones.
|
|
114
|
+
//
|
|
115
|
+
// Both used to scroll: the textarea was pinned to the outer box's visible
|
|
116
|
+
// area with `overflow: auto` of its own, so a long query produced two
|
|
117
|
+
// scrollbars, and scrolling the outer one left the caret sitting over the
|
|
118
|
+
// wrong line because the highlight moved and the input did not.
|
|
119
|
+
_jsx("div", { className: cn('relative h-56 shrink-0 overflow-auto border-b', RULE, PANEL), children: _jsxs("div", { className: "relative min-h-full w-full", children: [_jsx(Highlight, { code: value, language: "sql", theme: themes.github, children: ({ tokens, getLineProps, getTokenProps }) => (_jsx("pre", { className: cn(shared, 'pointer-events-none min-h-full'), "aria-hidden": true, children: tokens.map((line, i) => (
|
|
120
|
+
// biome-ignore lint/suspicious/noArrayIndexKey: lines have no id
|
|
121
|
+
_jsx("div", { ...getLineProps({ line }), children: line.map((token, key) => (
|
|
122
|
+
// biome-ignore lint/suspicious/noArrayIndexKey: tokens have no id
|
|
123
|
+
_jsx("span", { ...getTokenProps({ token }) }, key))) }, i))) })) }), _jsx("textarea", { ref: textareaRef, value: value, onChange: (e) => onChange(e.target.value), onKeyDown: onKeyDown, spellCheck: false, "aria-label": "SQL query", className: cn(shared,
|
|
124
|
+
// `overflow-hidden`, not `auto`: this layer is as tall as the code it
|
|
125
|
+
// holds, so it has nothing to scroll — and giving it the option back
|
|
126
|
+
// is what produced the second scrollbar.
|
|
127
|
+
'absolute inset-0 h-full w-full resize-none overflow-hidden bg-transparent', 'text-transparent caret-zinc-900 outline-none dark:caret-zinc-100') })] }) }));
|
|
128
|
+
}
|
|
129
|
+
function ResultTable({ result }) {
|
|
130
|
+
if (result.rowCount === 0) {
|
|
131
|
+
return (_jsx("p", { className: cn('p-8 text-center text-sm', MUTED), children: "The query ran and matched nothing." }));
|
|
132
|
+
}
|
|
133
|
+
return (_jsxs("div", { className: "p-4", children: [result.truncated && (_jsxs("p", { className: "mb-2 text-[11px] text-amber-600", children: ["Showing the first ", result.rowCount, " rows. Add a LIMIT or an aggregate to see a complete answer."] })), _jsx("div", { className: cn('overflow-x-auto rounded-lg border', RULE, PANEL), children: _jsxs("table", { className: "w-full min-w-max text-sm", children: [_jsx("thead", { children: _jsx("tr", { className: cn('border-b bg-zinc-50 dark:bg-zinc-950', RULE), children: result.columns.map((column) => (_jsx("th", { className: cn('whitespace-nowrap px-3 py-2 text-left font-mono text-[10px] font-normal uppercase tracking-[0.12em]', MUTED), children: column }, column))) }) }), _jsx("tbody", { children: result.rows.map((row, index) => (
|
|
134
|
+
// biome-ignore lint/suspicious/noArrayIndexKey: arbitrary SQL has no key
|
|
135
|
+
_jsx("tr", { className: "border-b border-zinc-100 last:border-0 dark:border-zinc-900", children: result.columns.map((column) => {
|
|
136
|
+
const value = row[column];
|
|
137
|
+
const numeric = typeof value === 'number';
|
|
138
|
+
return (_jsx("td", { className: cn('whitespace-nowrap px-3 py-1.5', numeric && 'text-right font-mono tabular-nums', (value === null || value === undefined) && MUTED), children: value === null || value === undefined
|
|
139
|
+
? '—'
|
|
140
|
+
: typeof value === 'object'
|
|
141
|
+
? JSON.stringify(value)
|
|
142
|
+
: String(value) }, column));
|
|
143
|
+
}) }, index))) })] }) })] }));
|
|
144
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { SavedQuery } from '@dudousxd/nestjs-catalog/client';
|
|
2
|
+
export declare const savedQueryKeys: {
|
|
3
|
+
all: readonly ["catalog", "saved-queries"];
|
|
4
|
+
};
|
|
5
|
+
/**
|
|
6
|
+
* The saved-query list, and the form for adding to it.
|
|
7
|
+
*
|
|
8
|
+
* Saving asks for a cache TTL up front rather than defaulting to some global
|
|
9
|
+
* number, because only the person writing the query knows whether a
|
|
10
|
+
* five-minute-old answer is fine. Zero — never cache — is the default, so the
|
|
11
|
+
* surprising behaviour is the one you have to ask for.
|
|
12
|
+
*/
|
|
13
|
+
export declare function SavedQueryPanel({ currentSql, onLoad, }: {
|
|
14
|
+
currentSql: string;
|
|
15
|
+
onLoad: (query: SavedQuery) => void;
|
|
16
|
+
}): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
|
|
3
|
+
import { Bookmark, Download, Timer, Trash2 } from 'lucide-react';
|
|
4
|
+
import { useMemo, useState } from 'react';
|
|
5
|
+
import { registeredChartLibraries } from './charts/registry';
|
|
6
|
+
import { cn } from './cn';
|
|
7
|
+
import { useCatalogClient } from './context';
|
|
8
|
+
import { Tooltip } from './ui/tooltip';
|
|
9
|
+
const MUTED = 'text-zinc-400 dark:text-zinc-500';
|
|
10
|
+
const RULE = 'border-zinc-200 dark:border-zinc-800';
|
|
11
|
+
export const savedQueryKeys = {
|
|
12
|
+
all: ['catalog', 'saved-queries'],
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* The saved-query list, and the form for adding to it.
|
|
16
|
+
*
|
|
17
|
+
* Saving asks for a cache TTL up front rather than defaulting to some global
|
|
18
|
+
* number, because only the person writing the query knows whether a
|
|
19
|
+
* five-minute-old answer is fine. Zero — never cache — is the default, so the
|
|
20
|
+
* surprising behaviour is the one you have to ask for.
|
|
21
|
+
*/
|
|
22
|
+
export function SavedQueryPanel({ currentSql, onLoad, }) {
|
|
23
|
+
const client = useCatalogClient();
|
|
24
|
+
const queryClient = useQueryClient();
|
|
25
|
+
const [saving, setSaving] = useState(false);
|
|
26
|
+
const [draft, setDraft] = useState({
|
|
27
|
+
name: '',
|
|
28
|
+
sql: '',
|
|
29
|
+
folder: '',
|
|
30
|
+
cacheTtlSeconds: 0,
|
|
31
|
+
});
|
|
32
|
+
const { data: saved = [] } = useQuery({
|
|
33
|
+
queryKey: savedQueryKeys.all,
|
|
34
|
+
queryFn: () => client.listSavedQueries(),
|
|
35
|
+
});
|
|
36
|
+
const invalidate = () => queryClient.invalidateQueries({ queryKey: savedQueryKeys.all });
|
|
37
|
+
const save = useMutation({
|
|
38
|
+
mutationFn: () => client.saveQuery({ ...draft, sql: currentSql }),
|
|
39
|
+
onSuccess: () => {
|
|
40
|
+
setSaving(false);
|
|
41
|
+
setDraft({ name: '', sql: '', folder: '', cacheTtlSeconds: 0 });
|
|
42
|
+
invalidate();
|
|
43
|
+
},
|
|
44
|
+
});
|
|
45
|
+
const remove = useMutation({
|
|
46
|
+
mutationFn: (id) => client.deleteSavedQuery(id),
|
|
47
|
+
onSuccess: invalidate,
|
|
48
|
+
});
|
|
49
|
+
const grouped = useMemo(() => {
|
|
50
|
+
const byFolder = new Map();
|
|
51
|
+
for (const query of saved) {
|
|
52
|
+
const key = query.folder?.trim() || 'Ungrouped';
|
|
53
|
+
const list = byFolder.get(key) ?? [];
|
|
54
|
+
list.push(query);
|
|
55
|
+
byFolder.set(key, list);
|
|
56
|
+
}
|
|
57
|
+
return [...byFolder.entries()].sort(([a], [b]) => a.localeCompare(b));
|
|
58
|
+
}, [saved]);
|
|
59
|
+
return (_jsxs("div", { className: cn('border-t', RULE), children: [_jsxs("div", { className: "flex items-center justify-between px-3 py-2", children: [_jsx("span", { className: cn('font-mono text-[10px] uppercase tracking-[0.14em]', MUTED), children: "Saved" }), _jsx("button", { type: "button", onClick: () => setSaving((open) => !open), disabled: currentSql.trim().length === 0, className: cn('rounded-sm p-1 disabled:opacity-30', MUTED, 'hover:bg-zinc-100 hover:text-zinc-900 dark:hover:bg-zinc-800'), "aria-label": "Save the current query", children: _jsx(Bookmark, { size: 12 }) })] }), saving && (_jsxs("form", { className: "space-y-1.5 px-3 pb-3", onSubmit: (e) => {
|
|
60
|
+
e.preventDefault();
|
|
61
|
+
save.mutate();
|
|
62
|
+
}, children: [_jsx("input", { value: draft.name, onChange: (e) => setDraft({ ...draft, name: e.target.value }), placeholder: "Name", "aria-label": "Query name", className: cn('w-full rounded-md border bg-white px-2 py-1 text-xs outline-none dark:bg-zinc-900', RULE, 'focus:border-violet-500') }), _jsx("input", { value: draft.folder ?? '', onChange: (e) => setDraft({ ...draft, folder: e.target.value }), placeholder: "Folder (optional)", "aria-label": "Folder", className: cn('w-full rounded-md border bg-white px-2 py-1 text-xs outline-none dark:bg-zinc-900', RULE, 'focus:border-violet-500') }), _jsxs("div", { className: "flex gap-1.5", children: [_jsx("select", { value: draft.visualization?.kind ?? 'table', onChange: (e) => setDraft({
|
|
63
|
+
...draft,
|
|
64
|
+
visualization: {
|
|
65
|
+
...(draft.visualization ?? {}),
|
|
66
|
+
kind: e.target.value,
|
|
67
|
+
},
|
|
68
|
+
}), "aria-label": "Chart type", className: cn('min-w-0 flex-1 rounded-md border bg-white px-1 py-1 text-[11px] outline-none dark:bg-zinc-900', RULE), children: ['table', 'bar', 'line', 'area', 'number'].map((kind) => (_jsx("option", { value: kind, children: kind }, kind))) }), _jsx("select", { value: draft.visualization?.library ?? 'css', onChange: (e) => setDraft({
|
|
69
|
+
...draft,
|
|
70
|
+
visualization: {
|
|
71
|
+
...(draft.visualization ?? { kind: 'table' }),
|
|
72
|
+
library: e.target.value === 'css' ? undefined : e.target.value,
|
|
73
|
+
},
|
|
74
|
+
}), "aria-label": "Chart library", title: "Which chart library draws this. Only libraries this app registered appear here.", className: cn('min-w-0 flex-1 rounded-md border bg-white px-1 py-1 text-[11px] outline-none dark:bg-zinc-900', RULE), children: registeredChartLibraries().map((library) => (_jsx("option", { value: library, children: library }, library))) })] }), _jsxs("label", { className: cn('flex items-center gap-1.5 text-[11px]', MUTED), children: [_jsx("input", { type: "checkbox", checked: draft.shared ?? false, onChange: (e) => setDraft({ ...draft, shared: e.target.checked }), className: "accent-violet-500" }), "Let other apps embed this"] }), _jsxs("label", { className: cn('flex items-center gap-1.5 text-[11px]', MUTED), children: [_jsx(Timer, { size: 11 }), "Reuse the result for", _jsx("input", { type: "number", min: 0, value: draft.cacheTtlSeconds ?? 0, onChange: (e) => setDraft({ ...draft, cacheTtlSeconds: Number(e.target.value) }), "aria-label": "Cache seconds", className: cn('w-14 rounded-md border bg-white px-1 py-0.5 text-right text-[11px] outline-none dark:bg-zinc-900', RULE) }), "s"] }), _jsx("button", { type: "submit", disabled: save.isPending || draft.name.trim().length === 0, className: "w-full rounded-md bg-zinc-950 px-2 py-1 text-xs text-zinc-50 disabled:opacity-40 dark:bg-zinc-100 dark:text-zinc-950", children: save.isPending ? 'Saving…' : 'Save this query' }), save.error && (_jsx("p", { className: "text-[11px] text-red-600", children: save.error instanceof Error ? save.error.message : 'Could not save.' }))] })), _jsxs("div", { className: "max-h-64 overflow-y-auto px-2 pb-2", children: [saved.length === 0 && (_jsx("p", { className: cn('px-2 py-3 text-center text-[11px]', MUTED), children: "Nothing saved yet." })), grouped.map(([folder, list]) => (_jsxs("div", { className: "mb-2", children: [_jsx("div", { className: cn('px-2 py-1 font-mono text-[10px] uppercase tracking-[0.14em]', MUTED), children: folder }), list.map((query) => (_jsxs("div", { className: "group flex items-center", children: [_jsx(Tooltip, { side: "right", content: query.description ??
|
|
75
|
+
(query.cacheTtlSeconds > 0
|
|
76
|
+
? `Results reused for ${query.cacheTtlSeconds}s.`
|
|
77
|
+
: 'Never cached — runs every time.'), children: _jsxs("button", { type: "button", onClick: () => onLoad(query), className: "min-w-0 flex-1 truncate rounded-md px-2 py-1 text-left text-[11px] hover:bg-zinc-50 dark:hover:bg-zinc-800", children: [query.name, query.cacheTtlSeconds > 0 && (_jsxs("span", { className: cn('ml-1 font-mono text-[9px]', MUTED), children: [query.cacheTtlSeconds, "s"] }))] }) }), _jsx(Tooltip, { content: "Download as CSV", children: _jsx("a", { href: client.exportUrl(query.id), className: cn('rounded-sm p-1 opacity-0 group-hover:opacity-100', MUTED), "aria-label": `Export ${query.name}`, children: _jsx(Download, { size: 11 }) }) }), _jsx("button", { type: "button", onClick: () => remove.mutate(query.id), className: cn('rounded-sm p-1 opacity-0 group-hover:opacity-100 hover:text-red-600', MUTED), "aria-label": `Delete ${query.name}`, children: _jsx(Trash2, { size: 11 }) })] }, query.id)))] }, folder)))] })] }));
|
|
78
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import type { CatalogTraceList, TraceQuery } from '@dudousxd/nestjs-catalog';
|
|
2
|
+
import { Upload } from 'lucide-react';
|
|
3
|
+
/**
|
|
4
|
+
* Where this screen gets its traces.
|
|
5
|
+
*
|
|
6
|
+
* An interface rather than a direct fetch for the same reason the rest of these
|
|
7
|
+
* screens take a transport: the host already has an HTTP client with its own
|
|
8
|
+
* base URL, auth and error handling, and a console that authenticates
|
|
9
|
+
* differently from the app around it is a console nobody trusts.
|
|
10
|
+
*/
|
|
11
|
+
export interface CatalogTraceSource {
|
|
12
|
+
listTraces(query: TraceQuery): Promise<CatalogTraceList>;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Resolves the trace source from whatever client the host provided.
|
|
16
|
+
*
|
|
17
|
+
* Discovered at run time instead of being declared on `CatalogClient`, because
|
|
18
|
+
* this screen must not be the reason a host that has not updated its provider
|
|
19
|
+
* stops compiling — and because the shipped React view and a hand-written one
|
|
20
|
+
* should be reaching the same endpoint through the same seam. The moment
|
|
21
|
+
* `CatalogProvider` exposes `listTraces`, this lights up with no change here.
|
|
22
|
+
*
|
|
23
|
+
* The result is validated rather than trusted: it arrived through a method
|
|
24
|
+
* nobody type-checked, and a screen that renders a malformed trace as an empty
|
|
25
|
+
* one would hide exactly the load somebody came here to find.
|
|
26
|
+
*/
|
|
27
|
+
export declare function useTraceSource(explicit?: CatalogTraceSource): CatalogTraceSource | undefined;
|
|
28
|
+
/** What each event looks like, and what it means in one line. */
|
|
29
|
+
export declare const CATALOG_EVENT_META: Record<string, {
|
|
30
|
+
icon: typeof Upload;
|
|
31
|
+
tone: string;
|
|
32
|
+
bar: string;
|
|
33
|
+
label: string;
|
|
34
|
+
meaning: string;
|
|
35
|
+
}>;
|
|
36
|
+
export declare function eventMeta(event: string): {
|
|
37
|
+
icon: typeof Upload;
|
|
38
|
+
tone: string;
|
|
39
|
+
bar: string;
|
|
40
|
+
label: string;
|
|
41
|
+
meaning: string;
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* The trail as stories rather than as a list.
|
|
45
|
+
*
|
|
46
|
+
* Grouped by the correlation id that was always in the data — the snapshot id,
|
|
47
|
+
* which a connector run, its batches, its commit and its finish all carry, and
|
|
48
|
+
* which is the durable run id when durable scheduled the load. Nothing is
|
|
49
|
+
* inferred from timing: an event with no correlation id is shown as what it is,
|
|
50
|
+
* at the bottom, rather than adopted by whichever load happened to be running.
|
|
51
|
+
*/
|
|
52
|
+
export declare function TraceExplorer({ source }?: {
|
|
53
|
+
source?: CatalogTraceSource;
|
|
54
|
+
}): import("react/jsx-runtime").JSX.Element;
|