@dudousxd/nestjs-catalog-react 0.16.0 → 0.17.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/dist/ObjectExplorer.js +424 -48
- package/dist/QueryConsole.js +25 -17
- package/dist/SavedQueryPanel.js +1 -1
- package/dist/TransformEditor.js +12 -3
- package/dist/bundler/index.d.ts +20 -0
- package/dist/bundler/index.js +20 -0
- package/dist/bundler/shiki-subset.d.ts +83 -0
- package/dist/bundler/shiki-subset.js +196 -0
- package/dist/context.d.ts +20 -1
- package/dist/context.js +9 -0
- package/dist/diff/RevisionDiff.d.ts +67 -4
- package/dist/diff/RevisionDiff.js +126 -91
- package/dist/index.d.ts +2 -2
- package/dist/index.js +16 -6
- package/dist/ui/code-editor.d.ts +154 -8
- package/dist/ui/code-editor.js +176 -72
- package/dist/ui/code-languages.d.ts +80 -0
- package/dist/ui/code-languages.js +76 -0
- package/dist/ui/code-theme.d.ts +25 -0
- package/dist/ui/code-theme.js +26 -0
- package/package.json +21 -17
- package/dist/diff/line-diff.d.ts +0 -124
- package/dist/diff/line-diff.js +0 -318
package/dist/QueryConsole.js
CHANGED
|
@@ -150,19 +150,23 @@ export function QueryConsole({ onGenerate, maxRows = 500, savedQueryId, onSavedQ
|
|
|
150
150
|
}
|
|
151
151
|
return [...byType.entries()].sort(([a], [b]) => a.localeCompare(b));
|
|
152
152
|
}, [relations]);
|
|
153
|
+
/**
|
|
154
|
+
* Put a relation or column name where the caret is.
|
|
155
|
+
*
|
|
156
|
+
* One call now, where it used to be a `selectionStart` splice, a `setSql` and
|
|
157
|
+
* a `requestAnimationFrame` to put the caret back — the editor owns its
|
|
158
|
+
* document, so the insert goes THROUGH it and lands on its undo stack.
|
|
159
|
+
* Ctrl+Z takes an inserted table name back out again, which the splice
|
|
160
|
+
* version could not do: React rewrote the whole value and the browser's undo
|
|
161
|
+
* stack lost its boundary. The `setSql` still happens, via `onChange`.
|
|
162
|
+
*/
|
|
153
163
|
function insert(text) {
|
|
154
164
|
const editor = editorRef.current;
|
|
155
165
|
if (!editor) {
|
|
156
166
|
setSql((current) => `${current}${text}`);
|
|
157
167
|
return;
|
|
158
168
|
}
|
|
159
|
-
|
|
160
|
-
const end = editor.selectionEnd;
|
|
161
|
-
setSql((current) => current.slice(0, start) + text + current.slice(end));
|
|
162
|
-
requestAnimationFrame(() => {
|
|
163
|
-
editor.focus();
|
|
164
|
-
editor.selectionStart = editor.selectionEnd = start + text.length;
|
|
165
|
-
});
|
|
169
|
+
editor.insertAtCursor(text);
|
|
166
170
|
}
|
|
167
171
|
function onEditorKeyDown(event) {
|
|
168
172
|
// Cmd/Ctrl+Enter runs, the way every SQL console does.
|
|
@@ -171,10 +175,14 @@ export function QueryConsole({ onGenerate, maxRows = 500, savedQueryId, onSavedQ
|
|
|
171
175
|
run.mutate();
|
|
172
176
|
}
|
|
173
177
|
// A textarea that eats Tab is a textarea nobody can leave by keyboard, so
|
|
174
|
-
// Tab
|
|
178
|
+
// Tab is the editor's own now — it indents rather than moving focus, which
|
|
179
|
+
// is why `CodeEditor` puts an Escape hatch in front of it. And ⌘↵ has to be
|
|
180
|
+
// claimed here rather than merely observed: the editor's default keymap
|
|
181
|
+
// binds it to "insert a blank line", so a handler that did not
|
|
182
|
+
// `preventDefault` would run the query AND leave a blank line behind.
|
|
175
183
|
}
|
|
176
184
|
const error = run.error instanceof Error ? run.error.message : null;
|
|
177
|
-
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, openId: openedId, onLoad: open })] }), _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-sky-100 dark:bg-sky-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'] }))] }), missingId && _jsx(MissingSavedQuery, { id: missingId }), askOpen && onGenerate && (_jsx(AskAssistantPanel, { prompt: prompt, onPromptChange: setPrompt, pending: generate.isPending, error: generate.error, onSubmit: () => generate.mutate() })), _jsx(SqlEditor, { value: sql, onChange: setSql, onKeyDown: onEditorKeyDown,
|
|
185
|
+
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, openId: openedId, onLoad: open })] }), _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-sky-100 dark:bg-sky-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'] }))] }), missingId && _jsx(MissingSavedQuery, { id: missingId }), askOpen && onGenerate && (_jsx(AskAssistantPanel, { prompt: prompt, onPromptChange: setPrompt, pending: generate.isPending, error: generate.error, onSubmit: () => generate.mutate() })), _jsx(SqlEditor, { value: sql, onChange: setSql, onKeyDown: onEditorKeyDown, editorRef: 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." }))] })] })] }) }));
|
|
178
186
|
}
|
|
179
187
|
/**
|
|
180
188
|
* What a link naming a query that is not here gets to say.
|
|
@@ -198,18 +206,18 @@ function RelationRow({ relation, onInsert, }) {
|
|
|
198
206
|
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))) }))] }));
|
|
199
207
|
}
|
|
200
208
|
/**
|
|
201
|
-
*
|
|
209
|
+
* The SQL box.
|
|
202
210
|
*
|
|
203
|
-
*
|
|
204
|
-
*
|
|
205
|
-
*
|
|
206
|
-
*
|
|
211
|
+
* One `CodeEditor`, which is the same component the transform editor and the
|
|
212
|
+
* workflow canvas's code sheet render — there is deliberately no second
|
|
213
|
+
* implementation for "the primary input". What differs between the callers is
|
|
214
|
+
* the box it sits in, and that is a class name.
|
|
207
215
|
*/
|
|
208
|
-
function SqlEditor({ value, onChange, onKeyDown,
|
|
209
|
-
return (_jsx(CodeEditor, { value: value, onChange: onChange, onKeyDown: onKeyDown,
|
|
216
|
+
function SqlEditor({ value, onChange, onKeyDown, editorRef, }) {
|
|
217
|
+
return (_jsx(CodeEditor, { value: value, onChange: onChange, onKeyDown: onKeyDown, handleRef: editorRef, language: "sql", label: "SQL query",
|
|
210
218
|
// Roomier than the transform pane: this is the screen's primary input,
|
|
211
219
|
// not a side panel.
|
|
212
|
-
className: cn('h-56 shrink-0 border-b', RULE, PANEL)
|
|
220
|
+
className: cn('h-56 shrink-0 border-b', RULE, PANEL) }));
|
|
213
221
|
}
|
|
214
222
|
function ResultTable({ result }) {
|
|
215
223
|
// Built from the answer, because the answer decides them: a free SQL query
|
package/dist/SavedQueryPanel.js
CHANGED
|
@@ -127,5 +127,5 @@ export function SavedQueryPanel({ currentSql, openId, onLoad, }) {
|
|
|
127
127
|
: '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"] }))] }) }), query.shared && _jsx(ShareBadge, { shared: true, className: "mr-1" }), _jsx(ShareControl, { layout: "row", kind: "query", shared: query.shared, pending: share.isPending, name: query.name, onChange: (shared) => share.mutate({ id: query.id, shared }), className: cn('opacity-0 group-hover:opacity-100 focus-visible:opacity-100', MUTED) }), _jsx(Tooltip, { content: "Every SQL this query has been, and what changed between two of them", children: _jsx("button", { type: "button", onClick: () => setHistory(query), className: cn('rounded-sm p-1 opacity-0 group-hover:opacity-100 focus-visible:opacity-100', MUTED), "aria-label": `History of ${query.name}`, children: _jsx(History, { size: 11 }) }) }), _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))), share.error !== null && (_jsx("p", { className: "px-2 py-1 text-[11px] text-red-600", children: share.error instanceof Error ? share.error.message : 'Could not change sharing.' }))] }), history && (_jsx(RevisionHistorySheet, { open: true, onOpenChange: (open) => {
|
|
128
128
|
if (!open)
|
|
129
129
|
setHistory(null);
|
|
130
|
-
}, subject: { kind: 'saved-query', id: history.id, name: history.name } }))] }));
|
|
130
|
+
}, subject: { kind: 'saved-query', id: history.id, name: history.name }, ...(history.id === openId ? { buffer: { body: currentSql } } : {}) }))] }));
|
|
131
131
|
}
|
package/dist/TransformEditor.js
CHANGED
|
@@ -2,11 +2,12 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
|
|
|
2
2
|
import { isTransformLanguage } from '@dudousxd/nestjs-catalog/client';
|
|
3
3
|
import { useMutation } from '@tanstack/react-query';
|
|
4
4
|
import { ArrowLeft, Play } from 'lucide-react';
|
|
5
|
-
import {
|
|
5
|
+
import { useState } from 'react';
|
|
6
6
|
import { cn } from './cn';
|
|
7
7
|
import { useCatalogClient } from './context';
|
|
8
8
|
import { RevisionHistoryButton, RevisionHistorySheet } from './diff/RevisionDiff';
|
|
9
9
|
import { CodeEditor } from './ui/code-editor';
|
|
10
|
+
import { TRANSFORM_HIGHLIGHTED_AS } from './ui/code-languages';
|
|
10
11
|
import { TextField } from './ui/field';
|
|
11
12
|
import { SelectField } from './ui/select';
|
|
12
13
|
const MUTED = 'text-zinc-400 dark:text-zinc-500';
|
|
@@ -91,7 +92,6 @@ export function TransformEditor({ transform, languages, pythonPackages = [], onC
|
|
|
91
92
|
const [code, setCode] = useState(transform?.code ?? STARTERS[transform?.language ?? 'javascript']);
|
|
92
93
|
const [sample, setSample] = useState(SAMPLE);
|
|
93
94
|
const [historyOpen, setHistoryOpen] = useState(false);
|
|
94
|
-
const editorRef = useRef(null);
|
|
95
95
|
const tryIt = useMutation({
|
|
96
96
|
mutationFn: () => {
|
|
97
97
|
let records;
|
|
@@ -118,6 +118,10 @@ export function TransformEditor({ transform, languages, pythonPackages = [], onC
|
|
|
118
118
|
}),
|
|
119
119
|
onSuccess: onSaved,
|
|
120
120
|
});
|
|
121
|
+
// `preventDefault` is what claims the key. The editor's default keymap binds
|
|
122
|
+
// ⌘↵ to "insert a blank line", and `CodeEditor` only withholds a keystroke
|
|
123
|
+
// from it when the host has said it wants it — so without this, trying the
|
|
124
|
+
// transform would also leave a blank line in the code being tried.
|
|
121
125
|
function onKeyDown(event) {
|
|
122
126
|
if ((event.metaKey || event.ctrlKey) && event.key === 'Enter') {
|
|
123
127
|
event.preventDefault();
|
|
@@ -140,7 +144,12 @@ export function TransformEditor({ transform, languages, pythonPackages = [], onC
|
|
|
140
144
|
label: option,
|
|
141
145
|
})) })] }), _jsxs("div", { className: "grid gap-3 lg:grid-cols-2", children: [_jsxs("div", { className: cn('overflow-hidden rounded-lg border', RULE, PANEL), children: [_jsxs("div", { className: cn('flex items-center justify-between border-b px-3 py-1.5', RULE), children: [_jsx("span", { className: cn('font-mono text-[10px] uppercase tracking-[0.14em]', MUTED), children: "Code" }), _jsx("span", { className: cn('font-mono text-[10px]', MUTED), children: language === 'python' && pythonPackages.length > 0
|
|
142
146
|
? `imports: ${pythonPackages.join(', ')}`
|
|
143
|
-
: '⌘↵ to try' })] }), _jsx(CodeEditor, { value: code, onChange: setCode, onKeyDown: onKeyDown,
|
|
147
|
+
: '⌘↵ to try' })] }), _jsx(CodeEditor, { value: code, onChange: setCode, onKeyDown: onKeyDown,
|
|
148
|
+
// A table rather than the `language === 'python' ? 'python' : 'tsx'`
|
|
149
|
+
// that used to be here. The ternary answered a fourth transform
|
|
150
|
+
// language with `tsx` — silently, and wrongly — where the table
|
|
151
|
+
// cannot be indexed by one at all until somebody adds the row.
|
|
152
|
+
language: TRANSFORM_HIGHLIGHTED_AS[language], label: "Transform code", className: "h-72" })] }), _jsxs("div", { className: "space-y-3", children: [_jsxs("div", { className: cn('overflow-hidden rounded-lg border', RULE, PANEL), children: [_jsx("div", { className: cn('border-b px-3 py-1.5', RULE), children: _jsx("span", { className: cn('font-mono text-[10px] uppercase tracking-[0.14em]', MUTED), children: "Sample records" }) }), _jsx(CodeEditor, { value: sample, onChange: setSample, language: "json", label: "Sample records", className: "h-32" })] }), _jsxs("button", { type: "button", onClick: () => tryIt.mutate(), disabled: tryIt.isPending, className: "flex items-center gap-1.5 rounded-md bg-zinc-950 px-3 py-1.5 text-xs text-zinc-50 disabled:opacity-40 dark:bg-zinc-100 dark:text-zinc-950", children: [_jsx(Play, { size: 12 }), tryIt.isPending ? 'Running…' : 'Try it'] }), _jsxs("div", { className: cn('overflow-hidden rounded-lg border', RULE, PANEL), children: [_jsx("div", { className: cn('border-b px-3 py-1.5', RULE), children: _jsx("span", { className: cn('font-mono text-[10px] uppercase tracking-[0.14em]', MUTED), children: "Output" }) }), _jsx(TryOutput, { result: tryIt.data, error: tryIt.error })] })] })] }), _jsxs("div", { className: "flex flex-wrap items-center gap-2", children: [_jsx(SaveBar, { transform: transform, nameIsEmpty: name.trim().length === 0, pending: save.isPending, error: save.error, onSave: () => save.mutate() }), transform && (_jsx(RevisionHistoryButton, { className: "ml-auto", onClick: () => setHistoryOpen(true) }))] }), transform && (_jsx(RevisionHistorySheet, { open: historyOpen, onOpenChange: setHistoryOpen, subject: { kind: 'transform', id: transform.id, name: transform.name },
|
|
144
153
|
// The SAVED code, not what is in the editor above. A history is what
|
|
145
154
|
// this catalog has recorded; comparing against an unsaved buffer would
|
|
146
155
|
// put a version number on text that exists only in one browser tab,
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Build-time entry point: things a host's bundler config imports, not its app.
|
|
3
|
+
*
|
|
4
|
+
* Kept off the package's main entry deliberately. Everything reachable from
|
|
5
|
+
* `index.ts` is resolved and bundled by the host whether or not it renders it,
|
|
6
|
+
* and a build plugin has no business in a browser graph — the same reason
|
|
7
|
+
* `WorkflowCanvas` and the chart renderers sit on their own subpaths.
|
|
8
|
+
*
|
|
9
|
+
* import { shikiSubset } from "@dudousxd/nestjs-catalog-react/bundler";
|
|
10
|
+
*
|
|
11
|
+
* The `.js` on the specifiers below is the one thing that differs from every
|
|
12
|
+
* other file in this package, and it is not style. Everywhere else the importer
|
|
13
|
+
* is a bundler, which resolves an extensionless path; here it is NODE, because
|
|
14
|
+
* Vite loads `vite.config.ts` by bundling it and then importing the result, and
|
|
15
|
+
* an external dependency of that config is resolved by Node's ESM rules — which
|
|
16
|
+
* do not guess extensions. Without these this subpath throws ERR_MODULE_NOT_FOUND
|
|
17
|
+
* inside the config file, before a single line of the build runs.
|
|
18
|
+
*/
|
|
19
|
+
export { shikiSubset, type ShikiSubsetPlugin } from './shiki-subset.js';
|
|
20
|
+
export { CATALOG_CODE_LANGUAGES, CATALOG_CODE_THEMES, type CatalogCodeLanguage, type CatalogCodeTheme, } from '../ui/code-languages.js';
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Build-time entry point: things a host's bundler config imports, not its app.
|
|
3
|
+
*
|
|
4
|
+
* Kept off the package's main entry deliberately. Everything reachable from
|
|
5
|
+
* `index.ts` is resolved and bundled by the host whether or not it renders it,
|
|
6
|
+
* and a build plugin has no business in a browser graph — the same reason
|
|
7
|
+
* `WorkflowCanvas` and the chart renderers sit on their own subpaths.
|
|
8
|
+
*
|
|
9
|
+
* import { shikiSubset } from "@dudousxd/nestjs-catalog-react/bundler";
|
|
10
|
+
*
|
|
11
|
+
* The `.js` on the specifiers below is the one thing that differs from every
|
|
12
|
+
* other file in this package, and it is not style. Everywhere else the importer
|
|
13
|
+
* is a bundler, which resolves an extensionless path; here it is NODE, because
|
|
14
|
+
* Vite loads `vite.config.ts` by bundling it and then importing the result, and
|
|
15
|
+
* an external dependency of that config is resolved by Node's ESM rules — which
|
|
16
|
+
* do not guess extensions. Without these this subpath throws ERR_MODULE_NOT_FOUND
|
|
17
|
+
* inside the config file, before a single line of the build runs.
|
|
18
|
+
*/
|
|
19
|
+
export { shikiSubset } from './shiki-subset.js';
|
|
20
|
+
export { CATALOG_CODE_LANGUAGES, CATALOG_CODE_THEMES, } from '../ui/code-languages.js';
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A Vite/Rollup plugin that prunes Shiki down to what this console renders.
|
|
3
|
+
*
|
|
4
|
+
* THE PROBLEM IT SOLVES
|
|
5
|
+
* ---------------------
|
|
6
|
+
* `@pierre/diffs` is the editor and the diff, and it resolves a grammar by
|
|
7
|
+
* looking the name up in Shiki's `bundledLanguages` — an object of ~240 entries
|
|
8
|
+
* whose values are `() => import('@shikijs/langs/<name>')`. Themes work the same
|
|
9
|
+
* way through `@pierre/theming`'s collections. A bundler cannot tree-shake a
|
|
10
|
+
* dynamic import selected by a runtime key, so it emits a chunk for every entry
|
|
11
|
+
* whether or not the application can ever reach it. Measured on
|
|
12
|
+
* `packages/dashboard`'s SPA before this plugin existed: 319 JS chunks, of which
|
|
13
|
+
* 242 were grammars (7.47 MB minified) and 75 were themes (1.58 MB) — against a
|
|
14
|
+
* console that renders SQL, JSON, TSX and Python in two Pierre palettes.
|
|
15
|
+
*
|
|
16
|
+
* WHAT IT IS NOT
|
|
17
|
+
* --------------
|
|
18
|
+
* It is NOT an entry-bundle saving, and claiming one would be a lie the first
|
|
19
|
+
* `ls dist/spa/assets` would catch. Every one of those chunks is lazy: Shiki's
|
|
20
|
+
* core, its JavaScript regex engine and the editor itself are in the entry, and
|
|
21
|
+
* they stay there. What this removes is emitted-but-unreachable bytes and the
|
|
22
|
+
* files carrying them.
|
|
23
|
+
*
|
|
24
|
+
* HOW IT WORKS, AND WHY REWRITING IS THE SOUND WAY
|
|
25
|
+
* ------------------------------------------------
|
|
26
|
+
* Every `import('<registry>/<name>')` for a name outside the subset is rewritten
|
|
27
|
+
* to a rejected promise. Nothing else changes: the registry keeps its key, the
|
|
28
|
+
* loader is still a function, and the arrow is still only called if something
|
|
29
|
+
* asks for that name — at which point it rejects with a message naming the
|
|
30
|
+
* specifier and this plugin. There is no chunk because there is no longer an
|
|
31
|
+
* `import()` for Rollup to split on.
|
|
32
|
+
*
|
|
33
|
+
* The alternative — resolving those specifiers to a stub module — was rejected:
|
|
34
|
+
* a stub is still a module, so Rollup still emits ~240 chunks, only tiny ones.
|
|
35
|
+
* Deleting the entries from the registry object instead would mean rewriting
|
|
36
|
+
* generated dependency source by shape rather than by specifier, and a
|
|
37
|
+
* specifier is a package's public API where its bundler output is not.
|
|
38
|
+
*
|
|
39
|
+
* WHY IT CANNOT GO QUIET
|
|
40
|
+
* ----------------------
|
|
41
|
+
* A pruner that stops matching prunes nothing and says nothing — the build gets
|
|
42
|
+
* slower and fatter and stays green. So {@link buildEnd} asserts the opposite of
|
|
43
|
+
* the usual thing: not that names were REMOVED, but that every name that was
|
|
44
|
+
* KEPT was actually there to keep, and that each registry was seen at all. A
|
|
45
|
+
* Shiki release that renames `tsx`, a typo in `CATALOG_CODE_LANGUAGES`, a
|
|
46
|
+
* `@pierre/theming` that stops naming its palettes as subpath imports — each
|
|
47
|
+
* one fails the build with the name it could not find.
|
|
48
|
+
*
|
|
49
|
+
* USAGE
|
|
50
|
+
* -----
|
|
51
|
+
* ```ts
|
|
52
|
+
* import { shikiSubset } from '@dudousxd/nestjs-catalog-react/bundler';
|
|
53
|
+
*
|
|
54
|
+
* export default defineConfig({ plugins: [react(), shikiSubset()] });
|
|
55
|
+
* ```
|
|
56
|
+
*
|
|
57
|
+
* A host that wants a grammar this console does not — its own `<CodeEditor>` on
|
|
58
|
+
* its own page — should not install this plugin, because the subset is this
|
|
59
|
+
* package's set and not theirs. There is no option to extend it, deliberately:
|
|
60
|
+
* an extensible allow-list is a list again, and the type that makes this one
|
|
61
|
+
* safe is not extensible either.
|
|
62
|
+
*/
|
|
63
|
+
export declare function shikiSubset(): ShikiSubsetPlugin;
|
|
64
|
+
/** The name each pruned `import()` is rewritten to call. */
|
|
65
|
+
export declare const PRUNED = "__catalogPrunedShikiImport";
|
|
66
|
+
/**
|
|
67
|
+
* The plugin, typed structurally.
|
|
68
|
+
*
|
|
69
|
+
* Written out rather than imported from `vite` or `rollup`, because this package
|
|
70
|
+
* ships React components and taking a build tool as a dependency to name one
|
|
71
|
+
* interface would put it in every consumer's install. Vite accepts any object of
|
|
72
|
+
* this shape; the five fields are the five it reads.
|
|
73
|
+
*/
|
|
74
|
+
export interface ShikiSubsetPlugin {
|
|
75
|
+
name: string;
|
|
76
|
+
enforce: 'pre';
|
|
77
|
+
apply: 'build';
|
|
78
|
+
transform(code: string): {
|
|
79
|
+
code: string;
|
|
80
|
+
map: null;
|
|
81
|
+
} | null;
|
|
82
|
+
buildEnd(error?: unknown): void;
|
|
83
|
+
}
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
// `.js` on the specifier, because NODE resolves this one and does not guess
|
|
2
|
+
// extensions — see `bundler/index.ts` for why the importer is Node here.
|
|
3
|
+
import { CATALOG_CODE_LANGUAGES, CATALOG_CODE_THEMES, } from '../ui/code-languages.js';
|
|
4
|
+
/**
|
|
5
|
+
* A Vite/Rollup plugin that prunes Shiki down to what this console renders.
|
|
6
|
+
*
|
|
7
|
+
* THE PROBLEM IT SOLVES
|
|
8
|
+
* ---------------------
|
|
9
|
+
* `@pierre/diffs` is the editor and the diff, and it resolves a grammar by
|
|
10
|
+
* looking the name up in Shiki's `bundledLanguages` — an object of ~240 entries
|
|
11
|
+
* whose values are `() => import('@shikijs/langs/<name>')`. Themes work the same
|
|
12
|
+
* way through `@pierre/theming`'s collections. A bundler cannot tree-shake a
|
|
13
|
+
* dynamic import selected by a runtime key, so it emits a chunk for every entry
|
|
14
|
+
* whether or not the application can ever reach it. Measured on
|
|
15
|
+
* `packages/dashboard`'s SPA before this plugin existed: 319 JS chunks, of which
|
|
16
|
+
* 242 were grammars (7.47 MB minified) and 75 were themes (1.58 MB) — against a
|
|
17
|
+
* console that renders SQL, JSON, TSX and Python in two Pierre palettes.
|
|
18
|
+
*
|
|
19
|
+
* WHAT IT IS NOT
|
|
20
|
+
* --------------
|
|
21
|
+
* It is NOT an entry-bundle saving, and claiming one would be a lie the first
|
|
22
|
+
* `ls dist/spa/assets` would catch. Every one of those chunks is lazy: Shiki's
|
|
23
|
+
* core, its JavaScript regex engine and the editor itself are in the entry, and
|
|
24
|
+
* they stay there. What this removes is emitted-but-unreachable bytes and the
|
|
25
|
+
* files carrying them.
|
|
26
|
+
*
|
|
27
|
+
* HOW IT WORKS, AND WHY REWRITING IS THE SOUND WAY
|
|
28
|
+
* ------------------------------------------------
|
|
29
|
+
* Every `import('<registry>/<name>')` for a name outside the subset is rewritten
|
|
30
|
+
* to a rejected promise. Nothing else changes: the registry keeps its key, the
|
|
31
|
+
* loader is still a function, and the arrow is still only called if something
|
|
32
|
+
* asks for that name — at which point it rejects with a message naming the
|
|
33
|
+
* specifier and this plugin. There is no chunk because there is no longer an
|
|
34
|
+
* `import()` for Rollup to split on.
|
|
35
|
+
*
|
|
36
|
+
* The alternative — resolving those specifiers to a stub module — was rejected:
|
|
37
|
+
* a stub is still a module, so Rollup still emits ~240 chunks, only tiny ones.
|
|
38
|
+
* Deleting the entries from the registry object instead would mean rewriting
|
|
39
|
+
* generated dependency source by shape rather than by specifier, and a
|
|
40
|
+
* specifier is a package's public API where its bundler output is not.
|
|
41
|
+
*
|
|
42
|
+
* WHY IT CANNOT GO QUIET
|
|
43
|
+
* ----------------------
|
|
44
|
+
* A pruner that stops matching prunes nothing and says nothing — the build gets
|
|
45
|
+
* slower and fatter and stays green. So {@link buildEnd} asserts the opposite of
|
|
46
|
+
* the usual thing: not that names were REMOVED, but that every name that was
|
|
47
|
+
* KEPT was actually there to keep, and that each registry was seen at all. A
|
|
48
|
+
* Shiki release that renames `tsx`, a typo in `CATALOG_CODE_LANGUAGES`, a
|
|
49
|
+
* `@pierre/theming` that stops naming its palettes as subpath imports — each
|
|
50
|
+
* one fails the build with the name it could not find.
|
|
51
|
+
*
|
|
52
|
+
* USAGE
|
|
53
|
+
* -----
|
|
54
|
+
* ```ts
|
|
55
|
+
* import { shikiSubset } from '@dudousxd/nestjs-catalog-react/bundler';
|
|
56
|
+
*
|
|
57
|
+
* export default defineConfig({ plugins: [react(), shikiSubset()] });
|
|
58
|
+
* ```
|
|
59
|
+
*
|
|
60
|
+
* A host that wants a grammar this console does not — its own `<CodeEditor>` on
|
|
61
|
+
* its own page — should not install this plugin, because the subset is this
|
|
62
|
+
* package's set and not theirs. There is no option to extend it, deliberately:
|
|
63
|
+
* an extensible allow-list is a list again, and the type that makes this one
|
|
64
|
+
* safe is not extensible either.
|
|
65
|
+
*/
|
|
66
|
+
export function shikiSubset() {
|
|
67
|
+
const registries = REGISTRIES.map((registry) => ({
|
|
68
|
+
...registry,
|
|
69
|
+
/** Which of `keep` this build actually found. The absentees fail the build. */
|
|
70
|
+
found: new Set(),
|
|
71
|
+
/** Whether the registry was in the module graph at all. */
|
|
72
|
+
seen: false,
|
|
73
|
+
}));
|
|
74
|
+
return {
|
|
75
|
+
name: 'catalog-shiki-subset',
|
|
76
|
+
// Before anything else rewrites a dynamic import — this reads the
|
|
77
|
+
// dependency's own source, and wants it as the dependency wrote it.
|
|
78
|
+
enforce: 'pre',
|
|
79
|
+
// Build only. A dev server pre-bundles dependencies with esbuild, so this
|
|
80
|
+
// hook would see a fraction of them and `buildEnd` would fail the run over
|
|
81
|
+
// an absence that means nothing. Dev pays a slower cold start; nothing
|
|
82
|
+
// about correctness differs, because a pruned grammar is one nothing asks
|
|
83
|
+
// for.
|
|
84
|
+
apply: 'build',
|
|
85
|
+
transform(code) {
|
|
86
|
+
if (!registries.some((registry) => code.includes(registry.prefix)))
|
|
87
|
+
return null;
|
|
88
|
+
let touched = false;
|
|
89
|
+
const next = code.replace(DYNAMIC_IMPORT, (match, _quote, specifier) => {
|
|
90
|
+
const registry = registries.find((candidate) => specifier.startsWith(candidate.prefix));
|
|
91
|
+
if (!registry)
|
|
92
|
+
return match;
|
|
93
|
+
registry.seen = true;
|
|
94
|
+
const name = specifier.slice(registry.prefix.length);
|
|
95
|
+
if (registry.keep.has(name)) {
|
|
96
|
+
registry.found.add(name);
|
|
97
|
+
return match;
|
|
98
|
+
}
|
|
99
|
+
touched = true;
|
|
100
|
+
return `${PRUNED}(${JSON.stringify(specifier)})`;
|
|
101
|
+
});
|
|
102
|
+
// `null` when nothing changed, so a module that merely MENTIONS a registry
|
|
103
|
+
// — the resolver that reads it, say — is handed back untouched rather than
|
|
104
|
+
// re-emitted with a sourcemap this plugin cannot honestly produce.
|
|
105
|
+
return touched ? { code: `${prunedHelper()}\n${next}`, map: null } : null;
|
|
106
|
+
},
|
|
107
|
+
buildEnd(error) {
|
|
108
|
+
// A failed build has already said what is wrong, and the registries it
|
|
109
|
+
// never reached would only add noise on top of the real error.
|
|
110
|
+
if (error)
|
|
111
|
+
return;
|
|
112
|
+
const complaints = [];
|
|
113
|
+
for (const registry of registries) {
|
|
114
|
+
if (!registry.seen) {
|
|
115
|
+
complaints.push(`no \`import('${registry.prefix}…')\` reached this plugin, so nothing was pruned from it`);
|
|
116
|
+
continue;
|
|
117
|
+
}
|
|
118
|
+
const missing = [...registry.keep].filter((name) => !registry.found.has(name));
|
|
119
|
+
if (missing.length > 0) {
|
|
120
|
+
complaints.push(`${registry.prefix} offers no ${registry.what} named ${missing.join(', ')}`);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
if (complaints.length > 0) {
|
|
124
|
+
throw new Error(`catalog-shiki-subset: ${complaints.join('; ')}. ${ADVICE}`);
|
|
125
|
+
}
|
|
126
|
+
},
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Every dynamic import, by the only part of it that is a public contract.
|
|
131
|
+
*
|
|
132
|
+
* A package's subpath exports are declared in its `package.json` and are what a
|
|
133
|
+
* caller is allowed to write; the file its bundler emitted them into is not.
|
|
134
|
+
* So this matches `import('…')` and reads the specifier, rather than matching
|
|
135
|
+
* the `(() => import(…))` wrapper Shiki's generator happens to produce and
|
|
136
|
+
* `@pierre/theming`'s does not.
|
|
137
|
+
*/
|
|
138
|
+
const DYNAMIC_IMPORT = /\bimport\(\s*(['"])([^'"]+)\1\s*\)/g;
|
|
139
|
+
/** What to do about it, which is the same answer whichever way the subset went wrong. */
|
|
140
|
+
const ADVICE = 'The subset in `ui/code-languages.ts` is out of step with the packages it prunes — left alone ' +
|
|
141
|
+
'this plugin would silently stop pruning, or prune a grammar the console renders. Fix the ' +
|
|
142
|
+
'names, or drop the plugin.';
|
|
143
|
+
/** The registries pruned, and what survives each. */
|
|
144
|
+
const REGISTRIES = [
|
|
145
|
+
{
|
|
146
|
+
prefix: '@shikijs/langs/',
|
|
147
|
+
what: 'grammar',
|
|
148
|
+
keep: new Set(CATALOG_CODE_LANGUAGES),
|
|
149
|
+
},
|
|
150
|
+
{
|
|
151
|
+
// Every one. The console is painted by Pierre's palettes below, and Shiki's
|
|
152
|
+
// own 65 are reachable only by naming one, which nothing here does.
|
|
153
|
+
prefix: '@shikijs/themes/',
|
|
154
|
+
what: 'theme',
|
|
155
|
+
keep: new Set(),
|
|
156
|
+
},
|
|
157
|
+
{
|
|
158
|
+
prefix: '@pierre/theme/',
|
|
159
|
+
what: 'theme',
|
|
160
|
+
keep: new Set(CATALOG_CODE_THEMES),
|
|
161
|
+
},
|
|
162
|
+
];
|
|
163
|
+
/** The name each pruned `import()` is rewritten to call. */
|
|
164
|
+
export const PRUNED = '__catalogPrunedShikiImport';
|
|
165
|
+
/**
|
|
166
|
+
* What a pruned name evaluates to, declared ONCE per rewritten module.
|
|
167
|
+
*
|
|
168
|
+
* A rejected promise rather than a throw, because the registry's value is a
|
|
169
|
+
* loader that both `@pierre/diffs` and `@pierre/theming` `await` — so a
|
|
170
|
+
* rejection surfaces where the caller already handles one, while a synchronous
|
|
171
|
+
* throw from inside an arrow would surface somewhere neither of them looks.
|
|
172
|
+
* Nothing is constructed until the loader is called, so there is no promise
|
|
173
|
+
* sitting around to go unhandled.
|
|
174
|
+
*
|
|
175
|
+
* A shared helper rather than the sentence inlined at each of the ~320 call
|
|
176
|
+
* sites, and that is measured rather than tidy: inlined, the message added
|
|
177
|
+
* 58 KB to `packages/dashboard`'s ENTRY chunk — the one chunk this change was
|
|
178
|
+
* not supposed to touch — because the registry object it lives in is in the
|
|
179
|
+
* entry path even when every grammar it names is not. Hoisted, the call sites
|
|
180
|
+
* are shorter than the `import()` they replace once the minifier has renamed
|
|
181
|
+
* the helper, and the entry comes out smaller than before.
|
|
182
|
+
*
|
|
183
|
+
* The specifier is passed because the type that normally catches this
|
|
184
|
+
* (`CatalogCodeLanguage`) only sees literals written in this package; a `lang`
|
|
185
|
+
* inferred from a filename at runtime is the case that gets here, and "which
|
|
186
|
+
* one" is the whole question then.
|
|
187
|
+
*
|
|
188
|
+
* A function DECLARATION, so hoisting makes it valid above the registry no
|
|
189
|
+
* matter where in the module the imports sat.
|
|
190
|
+
*/
|
|
191
|
+
function prunedHelper() {
|
|
192
|
+
const advice = ' was pruned from this bundle by catalog-shiki-subset. Add it to ' +
|
|
193
|
+
'CATALOG_CODE_LANGUAGES / CATALOG_CODE_THEMES in @dudousxd/nestjs-catalog-react, ' +
|
|
194
|
+
'or stop asking for it.';
|
|
195
|
+
return `function ${PRUNED}(specifier){return Promise.reject(new Error(specifier+${JSON.stringify(advice)}))}`;
|
|
196
|
+
}
|
package/dist/context.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { CatalogAuditEvent, CatalogConnection, CatalogConnector, CatalogObjectPage, CatalogQueryRelation, CatalogQueryResult, CatalogRevision, CatalogSearchResult, CatalogSnapshot, CatalogTraceList, CatalogTransform, ConnectionCheck, ConnectorRun, Dashboard, DashboardCard, DeleteReconciliation, LoadExpectation, LoadExpectationInput, ObjectQueryParams, PropertyPatch, ResolvedLoadExpectation, RowCountBound, SaveQueryInput, SavedQuery, StoredLoadExpectation, TraceQuery, TransformLanguage, TransformResult, TypePatch } from '@dudousxd/nestjs-catalog/client';
|
|
1
|
+
import type { CatalogAuditEvent, CatalogConnection, CatalogConnector, CatalogObjectPage, CatalogQueryRelation, CatalogQueryResult, CatalogRevision, CatalogSearchResult, CatalogSnapshot, CatalogTraceList, CatalogTransform, ConnectionCheck, ConnectorRun, Dashboard, DashboardCard, DeleteReconciliation, LoadExpectation, LoadExpectationInput, ObjectQueryParams, PropertyPatch, ResolvedLoadExpectation, RowCountBound, SaveQueryInput, SavedQuery, SnapshotRef, StoredLoadExpectation, TraceQuery, TransformLanguage, TransformResult, TypePatch } from '@dudousxd/nestjs-catalog/client';
|
|
2
2
|
import { type ReactNode } from 'react';
|
|
3
3
|
import type { EmbeddedChartPayload, EmbeddedDashboardPayload } from './embed/payload';
|
|
4
4
|
import { type PeopleQuery } from './routes';
|
|
@@ -257,6 +257,17 @@ export interface PersonUpsertResult {
|
|
|
257
257
|
export interface CatalogClient {
|
|
258
258
|
snapshot(): Promise<CatalogSnapshot>;
|
|
259
259
|
objects(type: string, params: ObjectQueryParams): Promise<CatalogObjectPage>;
|
|
260
|
+
/**
|
|
261
|
+
* Every load of one type, newest first. Empty on a store that keeps no
|
|
262
|
+
* history, which is what makes the snapshot picker able to hide itself rather
|
|
263
|
+
* than offer a control that cannot work.
|
|
264
|
+
*
|
|
265
|
+
* A separate call from {@link objects} rather than a field on the page: the
|
|
266
|
+
* list changes once a load, and the page is refetched on every keystroke,
|
|
267
|
+
* every sort and every page turn. Carried on the page it would be a query per
|
|
268
|
+
* one of those.
|
|
269
|
+
*/
|
|
270
|
+
snapshots(type: string): Promise<SnapshotRef[]>;
|
|
260
271
|
patchType(name: string, patch: TypePatch): Promise<unknown>;
|
|
261
272
|
patchProperty(name: string, property: string, patch: PropertyPatch): Promise<unknown>;
|
|
262
273
|
reset(): Promise<CatalogSnapshot>;
|
|
@@ -546,6 +557,14 @@ export declare const catalogQueryKeys: {
|
|
|
546
557
|
all: readonly ["nestjs-catalog"];
|
|
547
558
|
snapshot: readonly ["nestjs-catalog", "snapshot"];
|
|
548
559
|
objects: (type: string, params: ObjectQueryParams) => readonly ["nestjs-catalog", "objects", string, ObjectQueryParams];
|
|
560
|
+
/**
|
|
561
|
+
* A type's loads, keyed by type and NOT by the read's parameters.
|
|
562
|
+
*
|
|
563
|
+
* The list is a property of the type, so paging, sorting and filtering must
|
|
564
|
+
* not re-ask for it — keyed under `objects(type, params)` it would be fetched
|
|
565
|
+
* again on every keystroke of a search box.
|
|
566
|
+
*/
|
|
567
|
+
objectSnapshots: (type: string) => readonly ["nestjs-catalog", "objects", string, "snapshots"];
|
|
549
568
|
/**
|
|
550
569
|
* Keyed on the term, so react-query caches per term and a backspace shows the
|
|
551
570
|
* previous answer instantly instead of re-asking.
|
package/dist/context.js
CHANGED
|
@@ -12,6 +12,7 @@ export function CatalogProvider({ transport, pipelineBasePath = DEFAULT_PIPELINE
|
|
|
12
12
|
objects: (type, params) => transport.get(catalogRoutes.objects(type), {
|
|
13
13
|
...params,
|
|
14
14
|
}),
|
|
15
|
+
snapshots: (type) => transport.get(catalogRoutes.snapshots(type)),
|
|
15
16
|
patchType: (name, patch) => transport.patch(catalogRoutes.type(name), patch),
|
|
16
17
|
patchProperty: (name, property, patch) => transport.patch(catalogRoutes.property(name, property), patch),
|
|
17
18
|
reset: () => transport.post(catalogRoutes.reset()),
|
|
@@ -112,6 +113,14 @@ export const catalogQueryKeys = {
|
|
|
112
113
|
all: ['nestjs-catalog'],
|
|
113
114
|
snapshot: ['nestjs-catalog', 'snapshot'],
|
|
114
115
|
objects: (type, params) => ['nestjs-catalog', 'objects', type, params],
|
|
116
|
+
/**
|
|
117
|
+
* A type's loads, keyed by type and NOT by the read's parameters.
|
|
118
|
+
*
|
|
119
|
+
* The list is a property of the type, so paging, sorting and filtering must
|
|
120
|
+
* not re-ask for it — keyed under `objects(type, params)` it would be fetched
|
|
121
|
+
* again on every keystroke of a search box.
|
|
122
|
+
*/
|
|
123
|
+
objectSnapshots: (type) => ['nestjs-catalog', 'objects', type, 'snapshots'],
|
|
115
124
|
/**
|
|
116
125
|
* Keyed on the term, so react-query caches per term and a backspace shows the
|
|
117
126
|
* previous answer instantly instead of re-asking.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import type { CatalogCodeLanguage } from '../ui/code-languages';
|
|
2
2
|
/** Which of the two editable things in this catalog is being compared. */
|
|
3
3
|
export type RevisionSubjectKind = 'transform' | 'saved-query';
|
|
4
4
|
export interface RevisionSubject {
|
|
@@ -22,6 +22,23 @@ export interface RevisionHistoryProps {
|
|
|
22
22
|
version: number;
|
|
23
23
|
body: string;
|
|
24
24
|
} | undefined;
|
|
25
|
+
/**
|
|
26
|
+
* What is in the editor right now, unsaved.
|
|
27
|
+
*
|
|
28
|
+
* Given one, this screen answers "what have I changed since the last save" —
|
|
29
|
+
* which nothing could answer before, because the sheet only ever compared
|
|
30
|
+
* RECORDED revisions against each other. It sits at the top of both pickers
|
|
31
|
+
* and is the default right-hand side, since the question somebody opens
|
|
32
|
+
* history with while mid-edit is almost always that one.
|
|
33
|
+
*
|
|
34
|
+
* Folded in only when there is at least one recorded revision to compare it
|
|
35
|
+
* against. On a subject with no history the empty states below are the true
|
|
36
|
+
* answer, and a diff of an unsaved buffer against nothing would replace them
|
|
37
|
+
* with a screen claiming every line was added.
|
|
38
|
+
*/
|
|
39
|
+
buffer?: {
|
|
40
|
+
body: string;
|
|
41
|
+
} | undefined;
|
|
25
42
|
/**
|
|
26
43
|
* The version a connector run recorded, pinned on the left.
|
|
27
44
|
*
|
|
@@ -31,10 +48,57 @@ export interface RevisionHistoryProps {
|
|
|
31
48
|
*/
|
|
32
49
|
ranVersion?: number | undefined;
|
|
33
50
|
}
|
|
34
|
-
export declare function RevisionHistory({ subject, current, ranVersion }: RevisionHistoryProps): import("react/jsx-runtime").JSX.Element;
|
|
35
|
-
|
|
51
|
+
export declare function RevisionHistory({ subject, current, buffer, ranVersion }: RevisionHistoryProps): import("react/jsx-runtime").JSX.Element;
|
|
52
|
+
/**
|
|
53
|
+
* The comparison itself.
|
|
54
|
+
*
|
|
55
|
+
* Split out from the fetching above so it can be rendered — and tested — from
|
|
56
|
+
* two plain strings, which is what the thing actually being asserted is.
|
|
57
|
+
*
|
|
58
|
+
* WHY THIS IS NO LONGER HAND-ROLLED
|
|
59
|
+
* ---------------------------------
|
|
60
|
+
* It used to be `line-diff.ts` — forty lines of LCS, a fold, and a row
|
|
61
|
+
* renderer — whose docblock argued that the two strings a catalog diffs are a
|
|
62
|
+
* transform's code and somebody's SQL against military logistics data, and that
|
|
63
|
+
* there was no version of this screen worth a supply-chain question mark on
|
|
64
|
+
* that content, so there was no dependency at all. That argument is dead, and it
|
|
65
|
+
* was not this file that killed it: `@pierre/diffs` is now the EDITOR, so it
|
|
66
|
+
* already sees every one of those strings on every keystroke. Keeping a second,
|
|
67
|
+
* weaker differ beside it to avoid a dependency that is already there would buy
|
|
68
|
+
* nothing and cost a divergence — two components disagreeing about what changed,
|
|
69
|
+
* which is the one thing a diff must not do. `line-diff.ts` and its spec are
|
|
70
|
+
* gone; the argument went with them rather than being left standing next to a
|
|
71
|
+
* package that refutes it.
|
|
72
|
+
*
|
|
73
|
+
* What is lost with it: the `coarse` fallback past `DIFF_MAX_CELLS` and the
|
|
74
|
+
* explicit row cap. Both were bounds on a hand-rolled algorithm. The renderer
|
|
75
|
+
* here is virtualised — it draws the rows in view and no more — so the wall of
|
|
76
|
+
* paint the cap existed to prevent is not reachable the same way.
|
|
77
|
+
*
|
|
78
|
+
* What is gained: word-level highlighting inside a changed line, which the old
|
|
79
|
+
* one explicitly could not do and which is most of the value when the answer to
|
|
80
|
+
* "why did Tuesday's load differ" is one renamed column.
|
|
81
|
+
*/
|
|
82
|
+
export declare function DiffBody({ before, after,
|
|
83
|
+
/**
|
|
84
|
+
* What to highlight it as.
|
|
85
|
+
*
|
|
86
|
+
* Optional and defaulting to nothing, because this component is reached from
|
|
87
|
+
* both subjects: a transform's code could be any of three languages and the
|
|
88
|
+
* sheet does not carry which, while a saved query is always SQL. Left unset,
|
|
89
|
+
* the name below carries no extension and the diff renders unhighlighted —
|
|
90
|
+
* which is honest, and better than colouring Python as SQL.
|
|
91
|
+
*
|
|
92
|
+
* Narrowed to {@link CatalogCodeLanguage} rather than left as `string`,
|
|
93
|
+
* because only the grammars in `ui/code-languages.ts` are in the bundle: a
|
|
94
|
+
* name outside them would render exactly like the `undefined` above, and the
|
|
95
|
+
* two nothings mean opposite things.
|
|
96
|
+
*/
|
|
97
|
+
language, name, }: {
|
|
36
98
|
before: string;
|
|
37
99
|
after: string;
|
|
100
|
+
language?: CatalogCodeLanguage | undefined;
|
|
101
|
+
name?: string;
|
|
38
102
|
}): import("react/jsx-runtime").JSX.Element;
|
|
39
103
|
export interface RevisionHistorySheetProps extends RevisionHistoryProps {
|
|
40
104
|
open: boolean;
|
|
@@ -60,4 +124,3 @@ export declare function RevisionHistoryButton({ label, onClick, className, }: {
|
|
|
60
124
|
onClick: () => void;
|
|
61
125
|
className?: string;
|
|
62
126
|
}): import("react/jsx-runtime").JSX.Element;
|
|
63
|
-
export type { DiffLine, DiffSection };
|