@dudousxd/nestjs-catalog-react 0.14.0 → 0.15.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/PipelineConsole.js +75 -5
- package/dist/SavedQueryPanel.js +14 -2
- package/dist/TransformEditor.js +8 -1
- package/dist/context.d.ts +57 -1
- package/dist/context.js +12 -0
- package/dist/diff/RevisionDiff.d.ts +63 -0
- package/dist/diff/RevisionDiff.js +279 -0
- package/dist/diff/line-diff.d.ts +124 -0
- package/dist/diff/line-diff.js +318 -0
- package/dist/index.d.ts +3 -1
- package/dist/index.js +14 -0
- package/dist/routes.d.ts +15 -0
- package/dist/routes.js +17 -0
- package/package.json +2 -2
package/dist/PipelineConsole.js
CHANGED
|
@@ -6,6 +6,7 @@ import { ConnectionPanel, connectionOptionsFor } from './ConnectionPanel';
|
|
|
6
6
|
import { TransformEditor } from './TransformEditor';
|
|
7
7
|
import { cn } from './cn';
|
|
8
8
|
import { catalogQueryKeys, useCatalogClient } from './context';
|
|
9
|
+
import { RevisionHistorySheet } from './diff/RevisionDiff';
|
|
9
10
|
// One description of what a source needs, shared with the workflow canvas's
|
|
10
11
|
// source inspector. See the header of that module for why it is not two.
|
|
11
12
|
import { INLINE_CONNECTION, KIND_OPTIONS, ReadModeFields, SourceFields, parseRecords, readsIncrementally, sourceConfigFrom, sourceDraftFrom, sourceIsIncomplete, toConnectorKind, usesConnection, } from './source-fields';
|
|
@@ -192,10 +193,6 @@ function describeSource(connector, connection) {
|
|
|
192
193
|
function ConnectorCard({ connector, transform, connection, canEdit, running, onRun, onEdit, onDeleted, }) {
|
|
193
194
|
const client = useCatalogClient();
|
|
194
195
|
const [confirming, setConfirming] = useState(false);
|
|
195
|
-
const { data: runs = [] } = useQuery({
|
|
196
|
-
queryKey: catalogQueryKeys.runs(connector.id),
|
|
197
|
-
queryFn: () => client.listRuns(connector.id),
|
|
198
|
-
});
|
|
199
196
|
const remove = useMutation({
|
|
200
197
|
mutationFn: () => client.deleteConnector(connector.id),
|
|
201
198
|
onSuccess: () => {
|
|
@@ -203,12 +200,85 @@ function ConnectorCard({ connector, transform, connection, canEdit, running, onR
|
|
|
203
200
|
onDeleted();
|
|
204
201
|
},
|
|
205
202
|
});
|
|
206
|
-
return (_jsxs("div", { className: cn('rounded-lg border p-4', RULE, PANEL), children: [_jsxs("div", { className: "flex flex-wrap items-start justify-between gap-3", children: [_jsxs("div", { className: "min-w-0", children: [_jsxs("div", { className: "flex flex-wrap items-center gap-2", children: [_jsx("span", { className: "text-sm font-medium", children: connector.name }), _jsx("span", { className: "rounded-sm bg-zinc-100 px-1.5 py-0.5 font-mono text-[10px] uppercase dark:bg-zinc-800", children: connector.kind }), _jsxs("span", { className: cn('font-mono text-[10px]', MUTED), children: ["\u2192 ", connector.targetType] }), connection && (_jsx(Tooltip, { content: `Reads through the ${connection.name} connection, which supplies the address and the credential. Moving that connection moves this connector with it.`, children: _jsxs("span", { className: cn('flex cursor-help items-center gap-1 font-mono text-[10px]', MUTED), children: [_jsx(Plug, { size: 10 }), connection.name] }) })), connector.mode === 'incremental' && (_jsx(Tooltip, { content: "Reads only what changed since the last run, and carries the rest forward.", children: _jsxs("span", { className: cn('flex cursor-help items-center gap-1 font-mono text-[10px]', MUTED), children: [_jsx(RefreshCw, { size: 10 }), "incremental"] }) })), !connector.enabled && (_jsx("span", { className: "rounded-sm bg-zinc-100 px-1.5 py-0.5 font-mono text-[10px] uppercase text-zinc-500 dark:bg-zinc-800", children: "disabled" }))] }), _jsx("div", { className: cn('mt-1 font-mono text-[11px]', MUTED), children: describeSource(connector, connection) }), connector.secretEnvVar && (_jsx(Tooltip, { content: "The catalog stores the NAME of this variable, never its value. A leaked catalog database gives away the shape of the integration, not the keys to it.", children: _jsxs("div", { className: cn('mt-1 flex w-fit cursor-help items-center gap-1 font-mono text-[10px]', MUTED), children: [_jsx(KeyRound, { size: 10 }), connector.secretEnvVar] }) }))] }), _jsxs("div", { className: "flex shrink-0 items-center gap-1", children: [_jsxs("button", { type: "button", onClick: onRun, disabled: running || !connector.enabled, 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: [running ? _jsx(Loader2, { size: 12, className: "animate-spin" }) : _jsx(Play, { size: 12 }), running ? 'Running…' : 'Run now'] }), canEdit && (_jsx(Tooltip, { content: `Delete ${connector.name}`, children: _jsx("button", { type: "button", onClick: () => setConfirming(true), "aria-label": `Delete ${connector.name}`, className: cn('rounded-sm p-1.5 hover:text-red-600', MUTED), children: _jsx(Trash2, { size: 12 }) }) }))] })] }), transform && (_jsxs("button", { type: "button", onClick: onEdit, className: cn('mt-3 flex items-center gap-1.5 text-[11px]', MUTED, 'hover:text-sky-600'), children: [_jsx(Code2, { size: 11 }), transform.name, _jsxs("span", { className: "font-mono", children: [transform.language, " \u00B7 v", transform.version] })] })),
|
|
203
|
+
return (_jsxs("div", { className: cn('rounded-lg border p-4', RULE, PANEL), children: [_jsxs("div", { className: "flex flex-wrap items-start justify-between gap-3", children: [_jsxs("div", { className: "min-w-0", children: [_jsxs("div", { className: "flex flex-wrap items-center gap-2", children: [_jsx("span", { className: "text-sm font-medium", children: connector.name }), _jsx("span", { className: "rounded-sm bg-zinc-100 px-1.5 py-0.5 font-mono text-[10px] uppercase dark:bg-zinc-800", children: connector.kind }), _jsxs("span", { className: cn('font-mono text-[10px]', MUTED), children: ["\u2192 ", connector.targetType] }), connection && (_jsx(Tooltip, { content: `Reads through the ${connection.name} connection, which supplies the address and the credential. Moving that connection moves this connector with it.`, children: _jsxs("span", { className: cn('flex cursor-help items-center gap-1 font-mono text-[10px]', MUTED), children: [_jsx(Plug, { size: 10 }), connection.name] }) })), connector.mode === 'incremental' && (_jsx(Tooltip, { content: "Reads only what changed since the last run, and carries the rest forward.", children: _jsxs("span", { className: cn('flex cursor-help items-center gap-1 font-mono text-[10px]', MUTED), children: [_jsx(RefreshCw, { size: 10 }), "incremental"] }) })), !connector.enabled && (_jsx("span", { className: "rounded-sm bg-zinc-100 px-1.5 py-0.5 font-mono text-[10px] uppercase text-zinc-500 dark:bg-zinc-800", children: "disabled" }))] }), _jsx("div", { className: cn('mt-1 font-mono text-[11px]', MUTED), children: describeSource(connector, connection) }), connector.secretEnvVar && (_jsx(Tooltip, { content: "The catalog stores the NAME of this variable, never its value. A leaked catalog database gives away the shape of the integration, not the keys to it.", children: _jsxs("div", { className: cn('mt-1 flex w-fit cursor-help items-center gap-1 font-mono text-[10px]', MUTED), children: [_jsx(KeyRound, { size: 10 }), connector.secretEnvVar] }) }))] }), _jsxs("div", { className: "flex shrink-0 items-center gap-1", children: [_jsxs("button", { type: "button", onClick: onRun, disabled: running || !connector.enabled, 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: [running ? _jsx(Loader2, { size: 12, className: "animate-spin" }) : _jsx(Play, { size: 12 }), running ? 'Running…' : 'Run now'] }), canEdit && (_jsx(Tooltip, { content: `Delete ${connector.name}`, children: _jsx("button", { type: "button", onClick: () => setConfirming(true), "aria-label": `Delete ${connector.name}`, className: cn('rounded-sm p-1.5 hover:text-red-600', MUTED), children: _jsx(Trash2, { size: 12 }) }) }))] })] }), transform && (_jsxs("button", { type: "button", onClick: onEdit, className: cn('mt-3 flex items-center gap-1.5 text-[11px]', MUTED, 'hover:text-sky-600'), children: [_jsx(Code2, { size: 11 }), transform.name, _jsxs("span", { className: "font-mono", children: [transform.language, " \u00B7 v", transform.version] })] })), _jsx(RecentRuns, { connectorId: connector.id, transform: transform }), _jsx(ConfirmDialog, { open: confirming, onOpenChange: setConfirming, title: `Delete ${connector.name}?`, description: "The snapshots it already wrote stay where they are \u2014 this removes the connector, its schedule and its incremental watermark. Recreating it later starts reading from the beginning again.", confirmLabel: remove.isPending ? 'Deleting…' : 'Delete', pending: remove.isPending, onConfirm: () => remove.mutate(), error: remove.error
|
|
207
204
|
? remove.error instanceof Error
|
|
208
205
|
? remove.error.message
|
|
209
206
|
: 'Could not delete it.'
|
|
210
207
|
: undefined })] }));
|
|
211
208
|
}
|
|
209
|
+
/**
|
|
210
|
+
* What this connector has done lately, and the way from a load to the code that
|
|
211
|
+
* produced it.
|
|
212
|
+
*
|
|
213
|
+
* Its own component rather than a block inside the card, because it owns state
|
|
214
|
+
* the card has no other use for — which version is being compared — and because
|
|
215
|
+
* the runs it reads are the card's only query that is not about the connector
|
|
216
|
+
* itself. Lifting it out is also what keeps `ConnectorCard` under the cognitive
|
|
217
|
+
* complexity the linter enforces, which is the linter noticing something real:
|
|
218
|
+
* a card that renders a source, a schedule, a credential, a transform, a run
|
|
219
|
+
* list AND a comparison panel is doing six things.
|
|
220
|
+
*/
|
|
221
|
+
function RecentRuns({ connectorId, transform, }) {
|
|
222
|
+
const client = useCatalogClient();
|
|
223
|
+
/**
|
|
224
|
+
* Which run's code is being compared, as the version number it recorded.
|
|
225
|
+
*
|
|
226
|
+
* This is where the question actually occurs to somebody: they are looking at
|
|
227
|
+
* a load that came out different from the last one, and the row in front of
|
|
228
|
+
* them already says `code v3`. Making that number the way in means nobody has
|
|
229
|
+
* to carry it to another screen and pick it out of a dropdown — which is the
|
|
230
|
+
* step where you pick the wrong one and conclude the code was fine.
|
|
231
|
+
*/
|
|
232
|
+
const [comparing, setComparing] = useState(null);
|
|
233
|
+
const { data: runs = [] } = useQuery({
|
|
234
|
+
queryKey: catalogQueryKeys.runs(connectorId),
|
|
235
|
+
queryFn: () => client.listRuns(connectorId),
|
|
236
|
+
});
|
|
237
|
+
if (runs.length === 0)
|
|
238
|
+
return null;
|
|
239
|
+
return (_jsxs(_Fragment, { children: [_jsxs("div", { className: cn('mt-3 border-t pt-3', RULE), children: [_jsx("div", { className: cn('mb-1.5 font-mono text-[10px] uppercase tracking-[0.14em]', MUTED), children: "Recent runs" }), _jsx("div", { className: "space-y-1", children: runs.slice(0, 4).map((entry) => (_jsx(Tooltip, { content: entry.error ? (_jsx("span", { className: "font-mono text-[11px]", children: entry.error })) : (_jsx("span", { className: "font-mono text-[11px]", children: entry.logs.slice(-3).join('\n') || 'No logs.' })), children: _jsxs("div", { className: "flex cursor-help items-center gap-2 text-[11px]", children: [_jsxs("span", { className: "sr-only", children: [entry.status, ": "] }), _jsx(RunStatusIcon, { status: entry.status }), _jsx("span", { className: "font-mono", children: entry.snapshotId }), _jsxs("span", { className: MUTED, children: [entry.fetched, " fetched \u00B7 ", entry.written, " written"] }), _jsx(RanCodeVersion, { version: entry.transformVersion, comparable: transform !== undefined, onCompare: setComparing }), _jsx("span", { className: cn('ml-auto font-mono text-[10px]', MUTED), children: new Date(entry.startedAt).toLocaleTimeString() })] }) }, entry.id))) })] }), transform && (_jsx(RevisionHistorySheet, { open: comparing !== null, onOpenChange: (open) => {
|
|
240
|
+
if (!open)
|
|
241
|
+
setComparing(null);
|
|
242
|
+
}, subject: { kind: 'transform', id: transform.id, name: transform.name }, current: { version: transform.version, body: transform.code }, ranVersion: comparing ?? undefined }))] }));
|
|
243
|
+
}
|
|
244
|
+
function RunStatusIcon({ status }) {
|
|
245
|
+
if (status === 'succeeded')
|
|
246
|
+
return _jsx(CircleCheck, { size: 11, "aria-hidden": true, className: "text-emerald-600" });
|
|
247
|
+
if (status === 'failed')
|
|
248
|
+
return _jsx(CircleX, { size: 11, "aria-hidden": true, className: "text-red-600" });
|
|
249
|
+
return _jsx(Loader2, { size: 11, "aria-hidden": true, className: "animate-spin text-sky-600" });
|
|
250
|
+
}
|
|
251
|
+
/**
|
|
252
|
+
* `code v3` on a run, as a way into the comparison rather than as a fact.
|
|
253
|
+
*
|
|
254
|
+
* Where somebody is standing when the question occurs to them. The number was
|
|
255
|
+
* already on this row and already meant "this load ran that code"; what it did
|
|
256
|
+
* not have was anywhere to go, because until revisions existed the code it named
|
|
257
|
+
* had been overwritten. Making it the control means nobody carries a version
|
|
258
|
+
* number to another screen and picks it out of a dropdown — which is the step
|
|
259
|
+
* where you pick the wrong one and conclude the code was fine.
|
|
260
|
+
*
|
|
261
|
+
* Still only text when there is nothing on the other side: a connector with no
|
|
262
|
+
* transform never records a version, and a version whose transform has since
|
|
263
|
+
* been deleted has no current code to compare against. A control that opens an
|
|
264
|
+
* empty panel is a control that teaches people to stop pressing it.
|
|
265
|
+
*
|
|
266
|
+
* Its own component rather than three ternaries inside the run row, because the
|
|
267
|
+
* row is inside a `Tooltip` inside a `map` inside a card that is already at the
|
|
268
|
+
* complexity budget — and because "what does the version on a run do" is a
|
|
269
|
+
* question with one answer, which should be in one place.
|
|
270
|
+
*/
|
|
271
|
+
function RanCodeVersion({ version, comparable, onCompare, }) {
|
|
272
|
+
if (version === undefined)
|
|
273
|
+
return null;
|
|
274
|
+
if (!comparable)
|
|
275
|
+
return _jsxs("span", { className: cn('font-mono', MUTED), children: ["code v", version] });
|
|
276
|
+
return (
|
|
277
|
+
// Inside the tooltip's trigger rather than beside it, because this row IS
|
|
278
|
+
// the trigger: pulling the button out would put a gap in the hover target
|
|
279
|
+
// exactly where the pointer is heading. A click inside it bubbles normally.
|
|
280
|
+
_jsxs("button", { type: "button", onClick: () => onCompare(version), "aria-label": `Compare the code that ran (v${version}) with the current code`, className: cn('rounded-sm px-1 font-mono underline decoration-dotted underline-offset-2', MUTED, 'hover:text-sky-600'), children: ["code v", version] }));
|
|
281
|
+
}
|
|
212
282
|
/**
|
|
213
283
|
* The connection picker, above the address fields it replaces.
|
|
214
284
|
*
|
package/dist/SavedQueryPanel.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
|
|
3
|
-
import { Bookmark, Download, Timer, Trash2 } from 'lucide-react';
|
|
3
|
+
import { Bookmark, Download, History, Timer, Trash2 } from 'lucide-react';
|
|
4
4
|
import { useMemo, useState } from 'react';
|
|
5
5
|
import { registeredChartLibraries } from './charts/registry';
|
|
6
6
|
import { cn } from './cn';
|
|
7
7
|
import { useCatalogClient } from './context';
|
|
8
|
+
import { RevisionHistorySheet } from './diff/RevisionDiff';
|
|
8
9
|
import { ShareBadge, ShareControl } from './sharing';
|
|
9
10
|
import { Select } from './ui/select';
|
|
10
11
|
import { Tooltip } from './ui/tooltip';
|
|
@@ -47,6 +48,14 @@ export function SavedQueryPanel({ currentSql, openId, onLoad, }) {
|
|
|
47
48
|
const client = useCatalogClient();
|
|
48
49
|
const queryClient = useQueryClient();
|
|
49
50
|
const [saving, setSaving] = useState(false);
|
|
51
|
+
/**
|
|
52
|
+
* Which query's history is open, as the query itself rather than an id.
|
|
53
|
+
*
|
|
54
|
+
* The whole row, because the sheet is titled by name and a panel headed with
|
|
55
|
+
* an opaque id helps nobody. Looking the name back up from the id would be a
|
|
56
|
+
* second read of an array this component is already holding.
|
|
57
|
+
*/
|
|
58
|
+
const [history, setHistory] = useState(null);
|
|
50
59
|
const [draft, setDraft] = useState({
|
|
51
60
|
name: '',
|
|
52
61
|
sql: '',
|
|
@@ -115,5 +124,8 @@ export function SavedQueryPanel({ currentSql, openId, onLoad, }) {
|
|
|
115
124
|
? `Results reused for ${query.cacheTtlSeconds}s.`
|
|
116
125
|
: 'Never cached — runs every time.'), children: _jsxs("button", { type: "button", onClick: () => onLoad(query), "aria-current": query.id === openId ? 'true' : undefined, className: cn('min-w-0 flex-1 truncate rounded-md px-2 py-1 text-left text-[11px]', query.id === openId
|
|
117
126
|
? 'bg-sky-100 dark:bg-sky-950'
|
|
118
|
-
: '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: "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.' }))] })
|
|
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
|
+
if (!open)
|
|
129
|
+
setHistory(null);
|
|
130
|
+
}, subject: { kind: 'saved-query', id: history.id, name: history.name } }))] }));
|
|
119
131
|
}
|
package/dist/TransformEditor.js
CHANGED
|
@@ -5,6 +5,7 @@ import { ArrowLeft, Play } from 'lucide-react';
|
|
|
5
5
|
import { useRef, useState } from 'react';
|
|
6
6
|
import { cn } from './cn';
|
|
7
7
|
import { useCatalogClient } from './context';
|
|
8
|
+
import { RevisionHistoryButton, RevisionHistorySheet } from './diff/RevisionDiff';
|
|
8
9
|
import { CodeEditor } from './ui/code-editor';
|
|
9
10
|
import { TextField } from './ui/field';
|
|
10
11
|
import { SelectField } from './ui/select';
|
|
@@ -89,6 +90,7 @@ export function TransformEditor({ transform, languages, pythonPackages = [], onC
|
|
|
89
90
|
const [language, setLanguage] = useState(transform?.language ?? languages[0] ?? 'javascript');
|
|
90
91
|
const [code, setCode] = useState(transform?.code ?? STARTERS[transform?.language ?? 'javascript']);
|
|
91
92
|
const [sample, setSample] = useState(SAMPLE);
|
|
93
|
+
const [historyOpen, setHistoryOpen] = useState(false);
|
|
92
94
|
const editorRef = useRef(null);
|
|
93
95
|
const tryIt = useMutation({
|
|
94
96
|
mutationFn: () => {
|
|
@@ -138,5 +140,10 @@ export function TransformEditor({ transform, languages, pythonPackages = [], onC
|
|
|
138
140
|
label: option,
|
|
139
141
|
})) })] }), _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
|
|
140
142
|
? `imports: ${pythonPackages.join(', ')}`
|
|
141
|
-
: '⌘↵ to try' })] }), _jsx(CodeEditor, { value: code, onChange: setCode, onKeyDown: onKeyDown, language: language === 'python' ? 'python' : 'tsx', label: "Transform code", textareaRef: editorRef, 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 })] })] })] }), _jsx(SaveBar, { transform: transform, nameIsEmpty: name.trim().length === 0, pending: save.isPending, error: save.error, onSave: () => save.mutate() })] })
|
|
143
|
+
: '⌘↵ to try' })] }), _jsx(CodeEditor, { value: code, onChange: setCode, onKeyDown: onKeyDown, language: language === 'python' ? 'python' : 'tsx', label: "Transform code", textareaRef: editorRef, 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
|
+
// The SAVED code, not what is in the editor above. A history is what
|
|
145
|
+
// this catalog has recorded; comparing against an unsaved buffer would
|
|
146
|
+
// put a version number on text that exists only in one browser tab,
|
|
147
|
+
// and no run will ever have used it.
|
|
148
|
+
current: { version: transform.version, body: transform.code } }))] }));
|
|
142
149
|
}
|
package/dist/context.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { CatalogAuditEvent, CatalogConnection, CatalogConnector, CatalogObjectPage, CatalogQueryRelation, CatalogQueryResult, CatalogSearchResult, CatalogSnapshot, CatalogTraceList, CatalogTransform, ConnectionCheck, ConnectorRun, Dashboard, DashboardCard, ObjectQueryParams, PropertyPatch, SaveQueryInput, SavedQuery, 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, ObjectQueryParams, PropertyPatch, SaveQueryInput, SavedQuery, 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';
|
|
@@ -116,6 +116,25 @@ export interface TransformInput {
|
|
|
116
116
|
language: TransformLanguage;
|
|
117
117
|
code: string;
|
|
118
118
|
}
|
|
119
|
+
/**
|
|
120
|
+
* One saved version of the two things in this catalog whose text a person edits.
|
|
121
|
+
*
|
|
122
|
+
* RE-EXPORTED rather than mirrored, unlike `PipelineCapabilities` above. The
|
|
123
|
+
* distinction is worth keeping straight: `PipelineCapabilities` is mirrored
|
|
124
|
+
* because importing it would mean importing `@dudousxd/nestjs-catalog-pipeline`,
|
|
125
|
+
* a package built for a Node process with database drivers behind optional
|
|
126
|
+
* imports, into a browser bundle. `CatalogRevision` has no such problem — it is
|
|
127
|
+
* a plain shape on `@dudousxd/nestjs-catalog/client`, the entry point that
|
|
128
|
+
* exists precisely so a browser can name the catalog's own contracts, and
|
|
129
|
+
* restating it here would be the second copy of something two packages already
|
|
130
|
+
* serve.
|
|
131
|
+
*
|
|
132
|
+
* Named here at all, rather than left for callers to import from the client
|
|
133
|
+
* package, because everything else this file's `CatalogClient` returns is
|
|
134
|
+
* reachable from this module and a host should not have to know which of the two
|
|
135
|
+
* packages owns which shape to type a variable.
|
|
136
|
+
*/
|
|
137
|
+
export type { CatalogRevision };
|
|
119
138
|
/** The three answers a console can give somebody about what they may do. */
|
|
120
139
|
export type CatalogPersonRole = 'viewer' | 'curator' | 'admin';
|
|
121
140
|
/**
|
|
@@ -252,6 +271,23 @@ export interface CatalogClient {
|
|
|
252
271
|
result: CatalogQueryResult;
|
|
253
272
|
}>;
|
|
254
273
|
exportUrl(id: string): string;
|
|
274
|
+
/**
|
|
275
|
+
* Every SQL this saved query has ever been, newest first.
|
|
276
|
+
*
|
|
277
|
+
* Beside {@link listTransformRevisions} rather than one polymorphic
|
|
278
|
+
* `listRevisions(kind, id)`, because the two are served by different things:
|
|
279
|
+
* a saved query is the catalog library's own resource and a transform is the
|
|
280
|
+
* host's. One method taking a kind would hide that a host can move one of the
|
|
281
|
+
* two endpoints and not the other, which is exactly the mistake `routes.ts`
|
|
282
|
+
* spends its header preventing.
|
|
283
|
+
*
|
|
284
|
+
* An EMPTY list is a real answer and not an error. Every saved query written
|
|
285
|
+
* before revisions existed has no history, and whether the store backfills a
|
|
286
|
+
* first revision from the current SQL is a decision belonging to the store.
|
|
287
|
+
* The screen has to read "nothing recorded" as "nothing recorded" — never as
|
|
288
|
+
* "nothing has changed".
|
|
289
|
+
*/
|
|
290
|
+
listSavedQueryRevisions(id: string): Promise<CatalogRevision[]>;
|
|
255
291
|
listDashboards(): Promise<Dashboard[]>;
|
|
256
292
|
/**
|
|
257
293
|
* `shared` is declared on both writes, and it is not decoration.
|
|
@@ -378,6 +414,16 @@ export interface CatalogClient {
|
|
|
378
414
|
deleteTransform(id: string): Promise<{
|
|
379
415
|
deleted: boolean;
|
|
380
416
|
}>;
|
|
417
|
+
/**
|
|
418
|
+
* Every version of this transform's code, newest first.
|
|
419
|
+
*
|
|
420
|
+
* The list rather than one version by number, because the screen that needs
|
|
421
|
+
* this is comparing two of them and has to know which exist before it can pick
|
|
422
|
+
* — including the case where the version a run recorded is NOT among them,
|
|
423
|
+
* which is what a transform older than the revision store looks like and is a
|
|
424
|
+
* thing the screen has to be able to say out loud.
|
|
425
|
+
*/
|
|
426
|
+
listTransformRevisions(id: string): Promise<CatalogRevision[]>;
|
|
381
427
|
/**
|
|
382
428
|
* Run code against sample records without storing anything.
|
|
383
429
|
*
|
|
@@ -478,6 +524,16 @@ export declare const catalogQueryKeys: {
|
|
|
478
524
|
connections: readonly ["nestjs-catalog", "pipeline", "connections"];
|
|
479
525
|
connectors: readonly ["nestjs-catalog", "pipeline", "connectors"];
|
|
480
526
|
transforms: readonly ["nestjs-catalog", "pipeline", "transforms"];
|
|
527
|
+
/**
|
|
528
|
+
* A transform's history, keyed UNDER `transforms` on purpose.
|
|
529
|
+
*
|
|
530
|
+
* `catalogQueryKeys.transforms` is a prefix of this, so the invalidation the
|
|
531
|
+
* transform list already performs after a save reaches the history too — and
|
|
532
|
+
* it must, because saving new code is precisely what cuts a revision. Keyed
|
|
533
|
+
* anywhere else, the diff screen would keep showing yesterday's history beside
|
|
534
|
+
* today's code, which is the one thing it exists not to do.
|
|
535
|
+
*/
|
|
536
|
+
transformRevisions: (id: string) => readonly ["nestjs-catalog", "pipeline", "transforms", string, "revisions"];
|
|
481
537
|
runs: (connectorId?: string) => readonly ["nestjs-catalog", "pipeline", "runs", string];
|
|
482
538
|
workflows: readonly ["nestjs-catalog", "pipeline", "workflows"];
|
|
483
539
|
/**
|
package/dist/context.js
CHANGED
|
@@ -32,6 +32,7 @@ export function CatalogProvider({ transport, pipelineBasePath = DEFAULT_PIPELINE
|
|
|
32
32
|
updateSavedQuery: (id, input) => transport.patch(catalogRoutes.savedQuery(id), input),
|
|
33
33
|
deleteSavedQuery: (id) => transport.delete(catalogRoutes.savedQuery(id)),
|
|
34
34
|
runSavedQuery: (id) => transport.post(catalogRoutes.runSavedQuery(id), {}),
|
|
35
|
+
listSavedQueryRevisions: (id) => transport.get(catalogRoutes.savedQueryRevisions(id)),
|
|
35
36
|
// A URL rather than a fetch: an export the browser downloads itself can
|
|
36
37
|
// be a link, and a link can be copied, bookmarked or scheduled. Where
|
|
37
38
|
// that link points is the transport's answer, exactly like every other
|
|
@@ -76,6 +77,7 @@ export function CatalogProvider({ transport, pipelineBasePath = DEFAULT_PIPELINE
|
|
|
76
77
|
listTransforms: () => transport.get(pipeline.transforms()),
|
|
77
78
|
saveTransform: (input) => transport.post(pipeline.transforms(), input),
|
|
78
79
|
deleteTransform: (id) => transport.delete(pipeline.transform(id)),
|
|
80
|
+
listTransformRevisions: (id) => transport.get(pipeline.transformRevisions(id)),
|
|
79
81
|
tryTransform: (input) => transport.post(pipeline.tryTransform(), input),
|
|
80
82
|
listWorkflows: () => transport.get(pipeline.workflows()),
|
|
81
83
|
saveWorkflow: (input) => transport.post(pipeline.workflows(), input),
|
|
@@ -125,6 +127,16 @@ export const catalogQueryKeys = {
|
|
|
125
127
|
connections: ['nestjs-catalog', 'pipeline', 'connections'],
|
|
126
128
|
connectors: ['nestjs-catalog', 'pipeline', 'connectors'],
|
|
127
129
|
transforms: ['nestjs-catalog', 'pipeline', 'transforms'],
|
|
130
|
+
/**
|
|
131
|
+
* A transform's history, keyed UNDER `transforms` on purpose.
|
|
132
|
+
*
|
|
133
|
+
* `catalogQueryKeys.transforms` is a prefix of this, so the invalidation the
|
|
134
|
+
* transform list already performs after a save reaches the history too — and
|
|
135
|
+
* it must, because saving new code is precisely what cuts a revision. Keyed
|
|
136
|
+
* anywhere else, the diff screen would keep showing yesterday's history beside
|
|
137
|
+
* today's code, which is the one thing it exists not to do.
|
|
138
|
+
*/
|
|
139
|
+
transformRevisions: (id) => ['nestjs-catalog', 'pipeline', 'transforms', id, 'revisions'],
|
|
128
140
|
runs: (connectorId) => ['nestjs-catalog', 'pipeline', 'runs', connectorId ?? 'all'],
|
|
129
141
|
workflows: ['nestjs-catalog', 'pipeline', 'workflows'],
|
|
130
142
|
/**
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { type DiffLine, type DiffSection } from './line-diff';
|
|
2
|
+
/** Which of the two editable things in this catalog is being compared. */
|
|
3
|
+
export type RevisionSubjectKind = 'transform' | 'saved-query';
|
|
4
|
+
export interface RevisionSubject {
|
|
5
|
+
kind: RevisionSubjectKind;
|
|
6
|
+
id: string;
|
|
7
|
+
/** For the heading. A history sheet titled by an id helps nobody. */
|
|
8
|
+
name: string;
|
|
9
|
+
}
|
|
10
|
+
export interface RevisionHistoryProps {
|
|
11
|
+
subject: RevisionSubject;
|
|
12
|
+
/**
|
|
13
|
+
* What is live right now, from the row the caller is already holding.
|
|
14
|
+
*
|
|
15
|
+
* Every entry point has it — the transform editor has the transform, the
|
|
16
|
+
* connector card has it too, and the saved-query panel has the query — so
|
|
17
|
+
* asking for it costs nobody a request, and without it this screen cannot
|
|
18
|
+
* tell a history that is complete from one that stops short of the code
|
|
19
|
+
* running in production.
|
|
20
|
+
*/
|
|
21
|
+
current?: {
|
|
22
|
+
version: number;
|
|
23
|
+
body: string;
|
|
24
|
+
} | undefined;
|
|
25
|
+
/**
|
|
26
|
+
* The version a connector run recorded, pinned on the left.
|
|
27
|
+
*
|
|
28
|
+
* The whole reason the runs list is an entry point. Given one, this opens on
|
|
29
|
+
* "what changed between the code that produced that load and the code that
|
|
30
|
+
* would produce one now" without anybody choosing anything from a dropdown.
|
|
31
|
+
*/
|
|
32
|
+
ranVersion?: number | undefined;
|
|
33
|
+
}
|
|
34
|
+
export declare function RevisionHistory({ subject, current, ranVersion }: RevisionHistoryProps): import("react/jsx-runtime").JSX.Element;
|
|
35
|
+
export declare function DiffBody({ before, after }: {
|
|
36
|
+
before: string;
|
|
37
|
+
after: string;
|
|
38
|
+
}): import("react/jsx-runtime").JSX.Element;
|
|
39
|
+
export interface RevisionHistorySheetProps extends RevisionHistoryProps {
|
|
40
|
+
open: boolean;
|
|
41
|
+
onOpenChange: (open: boolean) => void;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* The history, in the panel every entry point opens it in.
|
|
45
|
+
*
|
|
46
|
+
* A `Sheet` rather than a route or a full-screen view, for the reason the sheet
|
|
47
|
+
* was built: the screen underneath — a half-edited transform, a connector list
|
|
48
|
+
* scrolled to the run somebody was reading — stays mounted, so closing this puts
|
|
49
|
+
* them back exactly where the question occurred to them rather than at the top
|
|
50
|
+
* of a list. `wide`, because a diff at 24rem wraps every line and stops being a
|
|
51
|
+
* diff.
|
|
52
|
+
*/
|
|
53
|
+
export declare function RevisionHistorySheet({ open, onOpenChange, ...props }: RevisionHistorySheetProps): import("react/jsx-runtime").JSX.Element;
|
|
54
|
+
/**
|
|
55
|
+
* The control that opens it, so the three entry points cannot drift into three
|
|
56
|
+
* different affordances for one thing.
|
|
57
|
+
*/
|
|
58
|
+
export declare function RevisionHistoryButton({ label, onClick, className, }: {
|
|
59
|
+
label?: string;
|
|
60
|
+
onClick: () => void;
|
|
61
|
+
className?: string;
|
|
62
|
+
}): import("react/jsx-runtime").JSX.Element;
|
|
63
|
+
export type { DiffLine, DiffSection };
|
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { CATALOG_REVISION_LIMIT } from '@dudousxd/nestjs-catalog/client';
|
|
3
|
+
import { useQuery } from '@tanstack/react-query';
|
|
4
|
+
import { GitCompare, History } from 'lucide-react';
|
|
5
|
+
import { useMemo, useState } from 'react';
|
|
6
|
+
import { cn } from '../cn';
|
|
7
|
+
import { catalogQueryKeys, useCatalogClient } from '../context';
|
|
8
|
+
import { Button } from '../ui/button';
|
|
9
|
+
import { SelectField } from '../ui/select';
|
|
10
|
+
import { Sheet } from '../ui/sheet';
|
|
11
|
+
import { diffLines, foldUnchanged } from './line-diff';
|
|
12
|
+
/**
|
|
13
|
+
* Why a load came out different from the last one.
|
|
14
|
+
*
|
|
15
|
+
* THE QUESTION THIS SCREEN ANSWERS
|
|
16
|
+
* --------------------------------
|
|
17
|
+
* Not "show me two texts". A connector run records `transformVersion` and the
|
|
18
|
+
* runs list renders it as `code v3`, so somebody looking at a surprising load
|
|
19
|
+
* already has a version number in front of them — and until now that number
|
|
20
|
+
* named code that existed nowhere, because `CatalogTransform.version` counts
|
|
21
|
+
* saves of a row that is overwritten in place. The valuable comparison is
|
|
22
|
+
* therefore the version that RAN against the version that is CURRENT, reached
|
|
23
|
+
* from the run where the question occurs to somebody, and that is what
|
|
24
|
+
* {@link RevisionHistory} opens on by default. The two selects are the fallback
|
|
25
|
+
* for the other question, not the way in.
|
|
26
|
+
*
|
|
27
|
+
* WHAT IS HONEST ABOUT AN EMPTY HISTORY
|
|
28
|
+
* -------------------------------------
|
|
29
|
+
* Every transform and saved query that predates revisions may have one recorded
|
|
30
|
+
* version or none, depending on what the store decided about backfill. Three
|
|
31
|
+
* different nothings live in here and they are rendered as three different
|
|
32
|
+
* things, because collapsing any pair of them tells somebody a lie about their
|
|
33
|
+
* own code:
|
|
34
|
+
*
|
|
35
|
+
* - **Nothing recorded.** There is no history. It is NOT a claim that nothing
|
|
36
|
+
* changed — the changes happened, they were simply not kept.
|
|
37
|
+
* - **One version recorded.** There is history and there is nothing before it to
|
|
38
|
+
* compare against. Also not a claim that nothing changed.
|
|
39
|
+
* - **Two versions that are byte-identical.** THIS is the one that means nothing
|
|
40
|
+
* changed, and it is the only one that gets to say so.
|
|
41
|
+
*
|
|
42
|
+
* And a fourth, which the run entry point can produce on its own: a run naming a
|
|
43
|
+
* version the recorded history does not contain. That is said out loud with the
|
|
44
|
+
* number in it, because it is the difference between "the code that ran is not
|
|
45
|
+
* here" and "the code that ran is the code you are looking at".
|
|
46
|
+
*/
|
|
47
|
+
const MUTED = 'text-zinc-400 dark:text-zinc-500';
|
|
48
|
+
const RULE = 'border-zinc-200 dark:border-zinc-800';
|
|
49
|
+
const PANEL = 'bg-white dark:bg-zinc-900';
|
|
50
|
+
/**
|
|
51
|
+
* How many diff rows are painted before the rest go behind a control.
|
|
52
|
+
*
|
|
53
|
+
* The same number `QueryConsole` caps a result set at, and for the same reason:
|
|
54
|
+
* past a few hundred rows a browser is painting a wall nobody reads, and the
|
|
55
|
+
* screen appears frozen — which is its own kind of dishonesty about what is
|
|
56
|
+
* happening. The remaining rows are one click away and the control says how many
|
|
57
|
+
* there are.
|
|
58
|
+
*
|
|
59
|
+
* WHY THIS IS NOT `capLines`, and it is worth being precise. `capLines` in the
|
|
60
|
+
* pipeline package bounds both axes — lines AND characters within a line — of
|
|
61
|
+
* text on its way into a durable checkpoint and a run row, because an unbounded
|
|
62
|
+
* string there makes the size of a write a property of somebody's source data.
|
|
63
|
+
* Neither half of that argument reaches here. The bodies have already been
|
|
64
|
+
* fetched whole, so nothing is saved by rendering fewer, and — this is the part
|
|
65
|
+
* that matters — a character cap would be actively WRONG: two lines that differ
|
|
66
|
+
* only past the cap would be truncated into equality and the diff would report
|
|
67
|
+
* them as unchanged. A diff view must never compare anything but the whole line.
|
|
68
|
+
* So long lines wrap, exactly as they do in the code editor, and the only cap is
|
|
69
|
+
* on rows.
|
|
70
|
+
*/
|
|
71
|
+
const DIFF_MAX_ROWS = 500;
|
|
72
|
+
export function RevisionHistory({ subject, current, ranVersion }) {
|
|
73
|
+
const client = useCatalogClient();
|
|
74
|
+
const revisions = useQuery({
|
|
75
|
+
queryKey: subject.kind === 'transform'
|
|
76
|
+
? catalogQueryKeys.transformRevisions(subject.id)
|
|
77
|
+
: savedQueryRevisionKey(subject.id),
|
|
78
|
+
queryFn: () => subject.kind === 'transform'
|
|
79
|
+
? client.listTransformRevisions(subject.id)
|
|
80
|
+
: client.listSavedQueryRevisions(subject.id),
|
|
81
|
+
});
|
|
82
|
+
const sides = useMemo(() => sidesFrom(revisions.data ?? [], current), [revisions.data, current]);
|
|
83
|
+
/**
|
|
84
|
+
* Which two are on screen, as VERSION NUMBERS rather than indices.
|
|
85
|
+
*
|
|
86
|
+
* `null` means "whatever the default is", so a background refetch that adds a
|
|
87
|
+
* newer revision moves the right-hand side onto it — which is what somebody
|
|
88
|
+
* who has not touched the selects expects. Storing an index instead would
|
|
89
|
+
* silently repoint both sides at different versions when the list grew, and an
|
|
90
|
+
* index is not a thing anybody chose.
|
|
91
|
+
*/
|
|
92
|
+
const [leftVersion, setLeftVersion] = useState(null);
|
|
93
|
+
const [rightVersion, setRightVersion] = useState(null);
|
|
94
|
+
const right = pick(sides, rightVersion) ?? sides[0];
|
|
95
|
+
const left = pick(sides, leftVersion) ?? pick(sides, ranVersion ?? null) ?? sides[1];
|
|
96
|
+
if (revisions.isPending) {
|
|
97
|
+
return _jsx(Notice, { children: "Reading the history\u2026" });
|
|
98
|
+
}
|
|
99
|
+
if (revisions.isError) {
|
|
100
|
+
return (_jsxs(Notice, { tone: "bad", children: [revisions.error instanceof Error ? revisions.error.message : 'Could not read the history.', _jsx("div", { className: "mt-2", children: _jsx(Button, { variant: "outline", size: "sm", onClick: () => revisions.refetch(), children: "Try again" }) })] }));
|
|
101
|
+
}
|
|
102
|
+
if (sides.length === 0) {
|
|
103
|
+
return _jsx(NoHistory, { subject: subject });
|
|
104
|
+
}
|
|
105
|
+
if (sides.length === 1 || !left || !right) {
|
|
106
|
+
return _jsx(OnlyOneVersion, { subject: subject, only: sides[0] });
|
|
107
|
+
}
|
|
108
|
+
return (_jsxs("div", { className: "space-y-3", children: [ranVersion !== undefined && !sides.some((side) => side.version === ranVersion) && (_jsxs(Notice, { tone: "warn", children: ["This load ran ", _jsxs("span", { className: "font-mono", children: ["v", ranVersion] }), ", which the recorded history does not contain \u2014 it predates this catalog keeping revisions, or it has been pushed out by the ", CATALOG_REVISION_LIMIT, " newer ones that are kept. Nothing below is the", ' ', body(subject.kind), " that produced that load."] })), _jsxs("div", { className: "flex flex-wrap items-end gap-2", children: [_jsx(SidePicker, { label: "Compare", ariaLabel: "Compare version", sides: sides, value: left.version, onChange: setLeftVersion }), _jsx("span", { className: cn('pb-1.5 font-mono text-[11px]', MUTED), children: "\u2192" }), _jsx(SidePicker, { label: "Against", ariaLabel: "Against version", sides: sides, value: right.version, onChange: setRightVersion })] }), _jsx(Authorship, { left: left, right: right }), _jsx(DiffBody, { before: left.body, after: right.body })] }));
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* The saved-query history key, which lives on the OTHER prefix.
|
|
112
|
+
*
|
|
113
|
+
* `savedQueryKeys.all` is `['catalog', 'saved-queries']` while everything in
|
|
114
|
+
* `catalogQueryKeys` is under `['nestjs-catalog', …]`. That split predates this
|
|
115
|
+
* screen and is not worth changing from here — what matters is that a query's
|
|
116
|
+
* history sits UNDER the key its list already uses, so the invalidation the save
|
|
117
|
+
* form already performs reaches the history too. Saving new SQL is exactly what
|
|
118
|
+
* cuts a revision, and a history that lagged its own subject would be showing
|
|
119
|
+
* yesterday's answer to today's question.
|
|
120
|
+
*/
|
|
121
|
+
function savedQueryRevisionKey(id) {
|
|
122
|
+
return ['catalog', 'saved-queries', id, 'revisions'];
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* The recorded versions, newest first, with the live row folded in when it is
|
|
126
|
+
* ahead of all of them.
|
|
127
|
+
*
|
|
128
|
+
* Sorted here rather than trusted from the route. The contract says newest
|
|
129
|
+
* first and the bundled store will honour it; a store somebody else wrote might
|
|
130
|
+
* not, and a diff screen that put v2 on the right and v7 on the left would show
|
|
131
|
+
* every addition as a deletion — a comparison that is exactly backwards and
|
|
132
|
+
* looks entirely plausible.
|
|
133
|
+
*/
|
|
134
|
+
function sidesFrom(revisions, current) {
|
|
135
|
+
const sides = revisions
|
|
136
|
+
.map((revision) => ({
|
|
137
|
+
version: revision.version,
|
|
138
|
+
body: revision.body,
|
|
139
|
+
authoredBy: revision.authoredBy,
|
|
140
|
+
authoredAt: revision.authoredAt,
|
|
141
|
+
live: false,
|
|
142
|
+
}))
|
|
143
|
+
.sort((a, b) => b.version - a.version);
|
|
144
|
+
if (current && !sides.some((side) => side.version === current.version)) {
|
|
145
|
+
sides.unshift({
|
|
146
|
+
version: current.version,
|
|
147
|
+
body: current.body,
|
|
148
|
+
authoredBy: null,
|
|
149
|
+
authoredAt: null,
|
|
150
|
+
live: true,
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
return sides;
|
|
154
|
+
}
|
|
155
|
+
function pick(sides, version) {
|
|
156
|
+
if (version === null)
|
|
157
|
+
return undefined;
|
|
158
|
+
return sides.find((side) => side.version === version);
|
|
159
|
+
}
|
|
160
|
+
function SidePicker({ label, ariaLabel, sides, value, onChange, }) {
|
|
161
|
+
return (_jsx(SelectField, { label: label, ariaLabel: ariaLabel, value: String(value),
|
|
162
|
+
// The select speaks strings and versions are numbers, so the parse happens
|
|
163
|
+
// here rather than anywhere a type assertion could hide it. A value that
|
|
164
|
+
// did not come from the options below cannot arrive, and if one somehow
|
|
165
|
+
// did, `Number` would produce NaN, `pick` would find nothing, and the
|
|
166
|
+
// default comparison would stand — rather than a blank panel.
|
|
167
|
+
onValueChange: (next) => onChange(Number(next)), className: "min-w-[10rem]", options: sides.map((side) => ({
|
|
168
|
+
value: String(side.version),
|
|
169
|
+
label: `v${side.version}`,
|
|
170
|
+
hint: side.live ? 'current, not yet recorded' : (side.authoredBy ?? undefined),
|
|
171
|
+
})) }));
|
|
172
|
+
}
|
|
173
|
+
/** Who wrote each side and when, which is half of what "why did this change" means. */
|
|
174
|
+
function Authorship({ left, right }) {
|
|
175
|
+
return (_jsxs("p", { className: cn('font-mono text-[10px] leading-relaxed', MUTED), children: ["v", left.version, " ", describeAuthor(left), " \u2192 v", right.version, " ", describeAuthor(right)] }));
|
|
176
|
+
}
|
|
177
|
+
function describeAuthor(side) {
|
|
178
|
+
if (side.live)
|
|
179
|
+
return '(current)';
|
|
180
|
+
const who = side.authoredBy ?? 'unknown';
|
|
181
|
+
// The locale's own format. A console rendering an ISO string at somebody is
|
|
182
|
+
// making them do arithmetic about their own timezone.
|
|
183
|
+
const when = side.authoredAt ? new Date(side.authoredAt).toLocaleString() : 'unknown date';
|
|
184
|
+
return `by ${who}, ${when}`;
|
|
185
|
+
}
|
|
186
|
+
export function DiffBody({ before, after }) {
|
|
187
|
+
const diff = useMemo(() => diffLines(before, after), [before, after]);
|
|
188
|
+
const sections = useMemo(() => foldUnchanged(diff.lines), [diff.lines]);
|
|
189
|
+
const [expanded, setExpanded] = useState(() => new Set());
|
|
190
|
+
const [showAllRows, setShowAllRows] = useState(false);
|
|
191
|
+
const rows = useMemo(() => sections.flatMap((section, index) => section.kind === 'shown' || expanded.has(index)
|
|
192
|
+
? section.lines.map((line) => ({ kind: 'line', line }))
|
|
193
|
+
: [{ kind: 'fold', index, count: section.lines.length }]), [sections, expanded]);
|
|
194
|
+
const visible = showAllRows ? rows : rows.slice(0, DIFF_MAX_ROWS);
|
|
195
|
+
const withheld = rows.length - visible.length;
|
|
196
|
+
return (_jsxs("div", { className: cn('overflow-hidden rounded-lg border', RULE, PANEL), children: [_jsxs("div", { className: cn('flex items-center gap-3 border-b px-3 py-1.5', RULE), children: [_jsx(GitCompare, { size: 11, className: MUTED }), diff.identical ? (
|
|
197
|
+
// The ONLY state that gets to say nothing changed, and it earns it:
|
|
198
|
+
// the two bodies are byte-for-byte the same. See this file's header
|
|
199
|
+
// for the three other nothings that must not borrow this sentence.
|
|
200
|
+
_jsx("span", { className: "font-mono text-[10px] text-zinc-500 dark:text-zinc-400", children: "These two versions are identical." })) : (_jsxs("span", { className: "font-mono text-[10px]", children: [_jsxs("span", { className: "text-emerald-600", children: ["+", diff.added] }), ' ', _jsxs("span", { className: "text-red-600", children: ["\u2212", diff.removed] })] }))] }), diff.alignment === 'coarse' && (_jsx("p", { className: "border-b border-amber-200 bg-amber-50/70 px-3 py-1.5 text-[11px] text-amber-800 dark:border-amber-900 dark:bg-amber-950/25 dark:text-amber-300", children: "These two versions are too far apart to line up line by line, so the whole changed region is shown as removed and re-added. Nothing below is wrong; it is blunter than usual." })), _jsx("div", { className: "overflow-x-auto", children: visible.map((row) => row.kind === 'fold' ? (_jsx(FoldRow, { count: row.count, onExpand: () => setExpanded((current) => new Set(current).add(row.index)) }, `fold-${row.index}`)) : (_jsx(DiffRow, { line: row.line }, rowKey(row.line)))) }), withheld > 0 && (_jsx("div", { className: cn('border-t px-3 py-2', RULE), children: _jsxs(Button, { variant: "outline", size: "sm", onClick: () => setShowAllRows(true), children: ["Show the remaining ", withheld, " lines"] }) }))] }));
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* A stable key for a diff row, out of the numbering it already carries.
|
|
204
|
+
*
|
|
205
|
+
* Not the array index, which is what this looked like first. A row's pair of
|
|
206
|
+
* line numbers is unique across the whole comparison and does not move when a
|
|
207
|
+
* fold above it opens: two removed lines have different `before`, two added
|
|
208
|
+
* lines have different `after`, and an unchanged line has both. An index key
|
|
209
|
+
* would renumber every row below an expanded fold, so React would reconcile
|
|
210
|
+
* hundreds of rows that did not change.
|
|
211
|
+
*/
|
|
212
|
+
function rowKey(line) {
|
|
213
|
+
return `${line.before ?? '-'}:${line.after ?? '-'}`;
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* One line.
|
|
217
|
+
*
|
|
218
|
+
* The `+`/`−`/space gutter is not decoration and it is not a duplicate of the
|
|
219
|
+
* colour: it is the only marker that survives a colourblind reader, a printout,
|
|
220
|
+
* a high-contrast theme and a screen reader, all of which the background tint
|
|
221
|
+
* does not. Diffs have been read this way for forty years, so it is also the
|
|
222
|
+
* marker nobody has to learn.
|
|
223
|
+
*
|
|
224
|
+
* `whitespace-pre-wrap break-words` matches the code editor exactly, which is
|
|
225
|
+
* what lets a four-hundred-character line be READ rather than truncated. See
|
|
226
|
+
* `DIFF_MAX_ROWS` for why truncating a line here would make the comparison lie.
|
|
227
|
+
*/
|
|
228
|
+
function DiffRow({ line }) {
|
|
229
|
+
return (_jsxs("div", { className: cn('flex items-start gap-2 px-2 font-mono text-[11px] leading-[1.5]', line.op === 'added' && 'bg-emerald-50 dark:bg-emerald-950/30', line.op === 'removed' && 'bg-red-50 dark:bg-red-950/30'), children: [_jsx("span", { className: cn('w-8 shrink-0 select-none text-right', MUTED), children: line.before ?? '' }), _jsx("span", { className: cn('w-8 shrink-0 select-none text-right', MUTED), children: line.after ?? '' }), _jsx("span", { className: cn('w-3 shrink-0 select-none', line.op === 'added' && 'text-emerald-600', line.op === 'removed' && 'text-red-600'), children: line.op === 'added' ? '+' : line.op === 'removed' ? '−' : ' ' }), _jsx("span", { className: "min-w-0 whitespace-pre-wrap break-words", children: line.text })] }));
|
|
230
|
+
}
|
|
231
|
+
/** A collapsed run of unchanged lines, and the way to see it anyway. */
|
|
232
|
+
function FoldRow({ count, onExpand }) {
|
|
233
|
+
return (_jsx("div", { className: cn('border-y bg-zinc-50/60 px-2 py-0.5 dark:bg-zinc-800/30', RULE), children: _jsxs(Button, { variant: "ghost", size: "sm", onClick: onExpand, className: "font-mono text-[10px] font-normal", children: ["\u22EF ", count, " unchanged ", count === 1 ? 'line' : 'lines'] }) }));
|
|
234
|
+
}
|
|
235
|
+
function Notice({ children, tone = 'plain', }) {
|
|
236
|
+
return (_jsx("div", { className: cn('rounded-lg border px-3 py-2 text-[11px] leading-relaxed', tone === 'plain' && cn(RULE, MUTED), tone === 'warn' &&
|
|
237
|
+
'border-amber-200 bg-amber-50/70 text-amber-800 dark:border-amber-900 dark:bg-amber-950/25 dark:text-amber-300', tone === 'bad' &&
|
|
238
|
+
'border-red-200 bg-red-50 text-red-700 dark:border-red-900 dark:bg-red-950/40 dark:text-red-300'), children: children }));
|
|
239
|
+
}
|
|
240
|
+
/** The word for the thing, so the empty states can be written once. */
|
|
241
|
+
function noun(kind) {
|
|
242
|
+
return kind === 'transform' ? 'transform' : 'saved query';
|
|
243
|
+
}
|
|
244
|
+
function body(kind) {
|
|
245
|
+
return kind === 'transform' ? 'code' : 'SQL';
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
248
|
+
* Nothing recorded — and the second sentence is the entire point of this
|
|
249
|
+
* component existing separately from the one below it.
|
|
250
|
+
*/
|
|
251
|
+
function NoHistory({ subject }) {
|
|
252
|
+
return (_jsxs("div", { className: cn('rounded-lg border border-dashed px-4 py-8 text-center text-sm', RULE, MUTED), children: [_jsx(History, { size: 16, className: "mx-auto mb-2", "aria-hidden": true }), _jsxs("p", { children: ["No history is recorded for ", _jsx("span", { className: "font-medium", children: subject.name }), "."] }), _jsxs("p", { className: "mx-auto mt-2 max-w-md text-[11px] leading-relaxed", children: ["That is not the same as saying nothing has changed. This ", noun(subject.kind), " was last edited before this catalog kept revisions, so the earlier ", body(subject.kind), " was overwritten and there is nothing left to compare against. The next save is recorded, and the", ' ', CATALOG_REVISION_LIMIT, " most recent are kept from then on."] })] }));
|
|
253
|
+
}
|
|
254
|
+
/** One version recorded. Also not a claim that nothing changed. */
|
|
255
|
+
function OnlyOneVersion({ subject, only }) {
|
|
256
|
+
return (_jsxs("div", { className: cn('rounded-lg border border-dashed px-4 py-8 text-center text-sm', RULE, MUTED), children: [_jsx(History, { size: 16, className: "mx-auto mb-2", "aria-hidden": true }), _jsxs("p", { children: ["One version of ", _jsx("span", { className: "font-medium", children: subject.name }), " is recorded", only ? _jsxs("span", { className: "font-mono", children: [" (v", only.version, ")"] }) : null, ", so there is nothing before it to compare against."] }), _jsxs("p", { className: "mx-auto mt-2 max-w-md text-[11px] leading-relaxed", children: ["Any earlier ", body(subject.kind), " was overwritten before this catalog kept revisions \u2014 again, not a statement that it never changed. The next save gives this screen two versions to work with; the ", CATALOG_REVISION_LIMIT, " most recent are kept."] })] }));
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* The history, in the panel every entry point opens it in.
|
|
260
|
+
*
|
|
261
|
+
* A `Sheet` rather than a route or a full-screen view, for the reason the sheet
|
|
262
|
+
* was built: the screen underneath — a half-edited transform, a connector list
|
|
263
|
+
* scrolled to the run somebody was reading — stays mounted, so closing this puts
|
|
264
|
+
* them back exactly where the question occurred to them rather than at the top
|
|
265
|
+
* of a list. `wide`, because a diff at 24rem wraps every line and stops being a
|
|
266
|
+
* diff.
|
|
267
|
+
*/
|
|
268
|
+
export function RevisionHistorySheet({ open, onOpenChange, ...props }) {
|
|
269
|
+
return (_jsx(Sheet, { open: open, onOpenChange: onOpenChange, title: `History · ${props.subject.name}`, width: "wide", description: props.ranVersion === undefined
|
|
270
|
+
? 'Every version saved, newest first.'
|
|
271
|
+
: `What changed between the ${body(props.subject.kind)} that ran and what would run now.`, children: open && _jsx(RevisionHistory, { ...props }) }));
|
|
272
|
+
}
|
|
273
|
+
/**
|
|
274
|
+
* The control that opens it, so the three entry points cannot drift into three
|
|
275
|
+
* different affordances for one thing.
|
|
276
|
+
*/
|
|
277
|
+
export function RevisionHistoryButton({ label = 'History', onClick, className, }) {
|
|
278
|
+
return (_jsxs(Button, { variant: "outline", size: "sm", onClick: onClick, className: className, children: [_jsx(History, { size: 12 }), label] }));
|
|
279
|
+
}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Two texts, lined up, computed in this file and nowhere else.
|
|
3
|
+
*
|
|
4
|
+
* WHY THIS IS HAND-ROLLED
|
|
5
|
+
* -----------------------
|
|
6
|
+
* The two strings this console ever diffs are a transform's code and a saved
|
|
7
|
+
* query's SQL. Those are the most sensitive strings in the product: a transform
|
|
8
|
+
* is executable code with the catalog's own database reachable from it, and a
|
|
9
|
+
* saved query is somebody's SQL against military logistics data — the column
|
|
10
|
+
* names alone describe a fleet. A diff library is a dependency that gets to see
|
|
11
|
+
* both, on every render, and "it only renders locally" is a property of the
|
|
12
|
+
* version you audited rather than of the package. There is no version of this
|
|
13
|
+
* feature worth a supply-chain question mark on that content, so there is no
|
|
14
|
+
* dependency here at all: `diffLines` is forty lines of dynamic programming with
|
|
15
|
+
* no imports, and the whole of what it can do is visible on this screen.
|
|
16
|
+
*
|
|
17
|
+
* It is also the cheaper answer. This package already declines dependencies it
|
|
18
|
+
* could plausibly justify — `charts/css.tsx` draws bars with divs, `ui/button.tsx`
|
|
19
|
+
* hand-rolls what `class-variance-authority` would compile to, and `export/pdf.ts`
|
|
20
|
+
* is a seam rather than a renderer — for the same reason each time: every
|
|
21
|
+
* consumer pays for it whether or not they render this screen.
|
|
22
|
+
*
|
|
23
|
+
* WHAT IT DOES NOT DO
|
|
24
|
+
* -------------------
|
|
25
|
+
* No word- or character-level diff inside a changed line, and no move detection.
|
|
26
|
+
* A changed line is reported as a removal and an addition, which is what a
|
|
27
|
+
* unified diff has always done and what the renderer colours. Both are real
|
|
28
|
+
* improvements somebody could make; neither is the question this screen exists
|
|
29
|
+
* to answer, which is "which lines are different between the version that ran
|
|
30
|
+
* and the version that is current".
|
|
31
|
+
*/
|
|
32
|
+
/**
|
|
33
|
+
* The largest DP table this will build, in cells.
|
|
34
|
+
*
|
|
35
|
+
* The comparison is O(n·m) in the CHANGED region only — the common prefix and
|
|
36
|
+
* suffix are trimmed first, so the ordinary case (somebody edited four lines of
|
|
37
|
+
* a three-hundred-line transform) is a handful of cells regardless of file size.
|
|
38
|
+
* This bound exists for the case that survives the trim: two bodies that share
|
|
39
|
+
* almost nothing, which is what a rewrite looks like.
|
|
40
|
+
*
|
|
41
|
+
* 1.5M cells is a `Uint32Array` of 6MB and roughly a 1,200×1,200 changed region.
|
|
42
|
+
* Past that the table costs more memory than the browser tab should spend on a
|
|
43
|
+
* comparison nobody could read anyway, so {@link diffLines} stops computing and
|
|
44
|
+
* SAYS it stopped — see `alignment`. A silent fallback would be the same failure
|
|
45
|
+
* `capLines` names one package over: a truncation nobody is told about.
|
|
46
|
+
*/
|
|
47
|
+
export declare const DIFF_MAX_CELLS = 1500000;
|
|
48
|
+
/** What happened to one line between the two bodies. */
|
|
49
|
+
export type DiffOp = 'same' | 'added' | 'removed';
|
|
50
|
+
export interface DiffLine {
|
|
51
|
+
op: DiffOp;
|
|
52
|
+
/** 1-based line number in the earlier body. Null on an added line. */
|
|
53
|
+
before: number | null;
|
|
54
|
+
/** 1-based line number in the later body. Null on a removed line. */
|
|
55
|
+
after: number | null;
|
|
56
|
+
text: string;
|
|
57
|
+
}
|
|
58
|
+
export interface LineDiff {
|
|
59
|
+
lines: DiffLine[];
|
|
60
|
+
added: number;
|
|
61
|
+
removed: number;
|
|
62
|
+
/**
|
|
63
|
+
* The two bodies are byte-for-byte the same.
|
|
64
|
+
*
|
|
65
|
+
* A separate field rather than `added === 0 && removed === 0`, because the
|
|
66
|
+
* caller has to distinguish "these two versions are identical" from "there is
|
|
67
|
+
* no second version to compare against", and only one of those is a statement
|
|
68
|
+
* about the texts. See `RevisionDiff`, where conflating them is the exact
|
|
69
|
+
* thing the empty states are written to avoid.
|
|
70
|
+
*/
|
|
71
|
+
identical: boolean;
|
|
72
|
+
/**
|
|
73
|
+
* How the lines were matched up.
|
|
74
|
+
*
|
|
75
|
+
* `exact` means every line was lined up against its counterpart. `coarse`
|
|
76
|
+
* means the changed region was past {@link DIFF_MAX_CELLS} and the whole of it
|
|
77
|
+
* is reported as removed-then-added — true, but blunter than it could be, and
|
|
78
|
+
* the screen says so rather than letting somebody read "everything changed" as
|
|
79
|
+
* a finding about their code.
|
|
80
|
+
*/
|
|
81
|
+
alignment: 'exact' | 'coarse';
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Line up two bodies.
|
|
85
|
+
*
|
|
86
|
+
* `before` is the earlier version, `after` the later one. The order matters to
|
|
87
|
+
* the reading and not to the algorithm: swapping them turns every addition into
|
|
88
|
+
* a removal, which is why the caller that pins "the version that ran" on the
|
|
89
|
+
* left is the one that gets a screen answering "what changed since".
|
|
90
|
+
*/
|
|
91
|
+
export declare function diffLines(before: string, after: string): LineDiff;
|
|
92
|
+
/** Lines to keep either side of a change before folding the rest away. */
|
|
93
|
+
export declare const DIFF_CONTEXT_LINES = 3;
|
|
94
|
+
/**
|
|
95
|
+
* The smallest run worth putting a button on.
|
|
96
|
+
*
|
|
97
|
+
* Folding two lines behind a control that says "2 unchanged lines" costs a row
|
|
98
|
+
* to save two, and it costs a click. Below this the run is simply shown.
|
|
99
|
+
*/
|
|
100
|
+
export declare const DIFF_MIN_FOLD = 4;
|
|
101
|
+
export type DiffSection = {
|
|
102
|
+
kind: 'shown';
|
|
103
|
+
lines: DiffLine[];
|
|
104
|
+
} | {
|
|
105
|
+
kind: 'folded';
|
|
106
|
+
lines: DiffLine[];
|
|
107
|
+
};
|
|
108
|
+
/**
|
|
109
|
+
* Collapse the long unchanged stretches, keeping context around every change.
|
|
110
|
+
*
|
|
111
|
+
* A transform can be hundreds of lines and the answer to "why did Tuesday's load
|
|
112
|
+
* differ from Monday's" is almost never more than a handful of them. Rendering
|
|
113
|
+
* all of it puts the four lines that matter somewhere in the middle of a wall
|
|
114
|
+
* and makes the reader scroll for them.
|
|
115
|
+
*
|
|
116
|
+
* Folded rather than dropped, and the sections carry their lines rather than a
|
|
117
|
+
* count, so the renderer can expand one in place. A diff that hides code with no
|
|
118
|
+
* way to see it is a diff you cannot trust, and this is code somebody is about
|
|
119
|
+
* to make a decision about.
|
|
120
|
+
*
|
|
121
|
+
* A run at the very start or end of the file gets no context on that side —
|
|
122
|
+
* there is no change up there to be in the context of.
|
|
123
|
+
*/
|
|
124
|
+
export declare function foldUnchanged(lines: DiffLine[], context?: number, minFold?: number): DiffSection[];
|
|
@@ -0,0 +1,318 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Two texts, lined up, computed in this file and nowhere else.
|
|
3
|
+
*
|
|
4
|
+
* WHY THIS IS HAND-ROLLED
|
|
5
|
+
* -----------------------
|
|
6
|
+
* The two strings this console ever diffs are a transform's code and a saved
|
|
7
|
+
* query's SQL. Those are the most sensitive strings in the product: a transform
|
|
8
|
+
* is executable code with the catalog's own database reachable from it, and a
|
|
9
|
+
* saved query is somebody's SQL against military logistics data — the column
|
|
10
|
+
* names alone describe a fleet. A diff library is a dependency that gets to see
|
|
11
|
+
* both, on every render, and "it only renders locally" is a property of the
|
|
12
|
+
* version you audited rather than of the package. There is no version of this
|
|
13
|
+
* feature worth a supply-chain question mark on that content, so there is no
|
|
14
|
+
* dependency here at all: `diffLines` is forty lines of dynamic programming with
|
|
15
|
+
* no imports, and the whole of what it can do is visible on this screen.
|
|
16
|
+
*
|
|
17
|
+
* It is also the cheaper answer. This package already declines dependencies it
|
|
18
|
+
* could plausibly justify — `charts/css.tsx` draws bars with divs, `ui/button.tsx`
|
|
19
|
+
* hand-rolls what `class-variance-authority` would compile to, and `export/pdf.ts`
|
|
20
|
+
* is a seam rather than a renderer — for the same reason each time: every
|
|
21
|
+
* consumer pays for it whether or not they render this screen.
|
|
22
|
+
*
|
|
23
|
+
* WHAT IT DOES NOT DO
|
|
24
|
+
* -------------------
|
|
25
|
+
* No word- or character-level diff inside a changed line, and no move detection.
|
|
26
|
+
* A changed line is reported as a removal and an addition, which is what a
|
|
27
|
+
* unified diff has always done and what the renderer colours. Both are real
|
|
28
|
+
* improvements somebody could make; neither is the question this screen exists
|
|
29
|
+
* to answer, which is "which lines are different between the version that ran
|
|
30
|
+
* and the version that is current".
|
|
31
|
+
*/
|
|
32
|
+
/**
|
|
33
|
+
* The largest DP table this will build, in cells.
|
|
34
|
+
*
|
|
35
|
+
* The comparison is O(n·m) in the CHANGED region only — the common prefix and
|
|
36
|
+
* suffix are trimmed first, so the ordinary case (somebody edited four lines of
|
|
37
|
+
* a three-hundred-line transform) is a handful of cells regardless of file size.
|
|
38
|
+
* This bound exists for the case that survives the trim: two bodies that share
|
|
39
|
+
* almost nothing, which is what a rewrite looks like.
|
|
40
|
+
*
|
|
41
|
+
* 1.5M cells is a `Uint32Array` of 6MB and roughly a 1,200×1,200 changed region.
|
|
42
|
+
* Past that the table costs more memory than the browser tab should spend on a
|
|
43
|
+
* comparison nobody could read anyway, so {@link diffLines} stops computing and
|
|
44
|
+
* SAYS it stopped — see `alignment`. A silent fallback would be the same failure
|
|
45
|
+
* `capLines` names one package over: a truncation nobody is told about.
|
|
46
|
+
*/
|
|
47
|
+
export const DIFF_MAX_CELLS = 1_500_000;
|
|
48
|
+
/**
|
|
49
|
+
* Split on `\n` alone, and keep whatever that leaves.
|
|
50
|
+
*
|
|
51
|
+
* A lone `\r` therefore stays inside the line text, so a body that changed from
|
|
52
|
+
* CRLF to LF reports every line as changed. That is noisy and it is also true:
|
|
53
|
+
* the stored bodies differ on every line, a connector pinned to the old version
|
|
54
|
+
* would run different bytes, and a diff that normalised the endings away would
|
|
55
|
+
* be answering a question nobody asked ("would these be the same if…") in place
|
|
56
|
+
* of the one they did.
|
|
57
|
+
*
|
|
58
|
+
* An empty body is zero lines rather than one empty line, so writing the first
|
|
59
|
+
* version of a transform reads as N additions rather than N additions and one
|
|
60
|
+
* mysterious deletion. A body ending in a newline genuinely does have a trailing
|
|
61
|
+
* empty line and keeps it.
|
|
62
|
+
*/
|
|
63
|
+
function splitLines(text) {
|
|
64
|
+
return text.length === 0 ? [] : text.split('\n');
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Line up two bodies.
|
|
68
|
+
*
|
|
69
|
+
* `before` is the earlier version, `after` the later one. The order matters to
|
|
70
|
+
* the reading and not to the algorithm: swapping them turns every addition into
|
|
71
|
+
* a removal, which is why the caller that pins "the version that ran" on the
|
|
72
|
+
* left is the one that gets a screen answering "what changed since".
|
|
73
|
+
*/
|
|
74
|
+
export function diffLines(before, after) {
|
|
75
|
+
const beforeLines = splitLines(before);
|
|
76
|
+
const afterLines = splitLines(after);
|
|
77
|
+
if (before === after) {
|
|
78
|
+
return {
|
|
79
|
+
lines: beforeLines.map((text, index) => ({
|
|
80
|
+
op: 'same',
|
|
81
|
+
before: index + 1,
|
|
82
|
+
after: index + 1,
|
|
83
|
+
text,
|
|
84
|
+
})),
|
|
85
|
+
added: 0,
|
|
86
|
+
removed: 0,
|
|
87
|
+
identical: true,
|
|
88
|
+
alignment: 'exact',
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
// The trim, which is what makes this cheap on the case that actually happens.
|
|
92
|
+
// A four-line edit inside a three-hundred-line transform leaves a DP table of
|
|
93
|
+
// sixteen cells; without it, ninety thousand.
|
|
94
|
+
let head = 0;
|
|
95
|
+
while (head < beforeLines.length &&
|
|
96
|
+
head < afterLines.length &&
|
|
97
|
+
beforeLines[head] === afterLines[head]) {
|
|
98
|
+
head += 1;
|
|
99
|
+
}
|
|
100
|
+
let tail = 0;
|
|
101
|
+
while (tail < beforeLines.length - head &&
|
|
102
|
+
tail < afterLines.length - head &&
|
|
103
|
+
beforeLines[beforeLines.length - 1 - tail] === afterLines[afterLines.length - 1 - tail]) {
|
|
104
|
+
tail += 1;
|
|
105
|
+
}
|
|
106
|
+
const beforeMiddle = beforeLines.slice(head, beforeLines.length - tail);
|
|
107
|
+
const afterMiddle = afterLines.slice(head, afterLines.length - tail);
|
|
108
|
+
const middle = beforeMiddle.length * afterMiddle.length > DIFF_MAX_CELLS
|
|
109
|
+
? coarse(beforeMiddle, afterMiddle, head)
|
|
110
|
+
: align(beforeMiddle, afterMiddle, head);
|
|
111
|
+
const lines = [
|
|
112
|
+
...beforeLines.slice(0, head).map((text, index) => sameLine(text, index + 1, index + 1)),
|
|
113
|
+
...middle.lines,
|
|
114
|
+
...beforeLines
|
|
115
|
+
.slice(beforeLines.length - tail)
|
|
116
|
+
.map((text, index) => sameLine(text, beforeLines.length - tail + index + 1, afterLines.length - tail + index + 1)),
|
|
117
|
+
];
|
|
118
|
+
return {
|
|
119
|
+
lines,
|
|
120
|
+
added: middle.added,
|
|
121
|
+
removed: middle.removed,
|
|
122
|
+
identical: false,
|
|
123
|
+
alignment: middle.alignment,
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
function sameLine(text, before, after) {
|
|
127
|
+
return { op: 'same', before, after, text };
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* The longest common subsequence of two line arrays, walked into a diff.
|
|
131
|
+
*
|
|
132
|
+
* The table is filled from the end so the walk can go forwards, which is what
|
|
133
|
+
* keeps the output in file order without a reversal at the end. `Uint32Array`
|
|
134
|
+
* rather than nested arrays because the table is the only thing here that has a
|
|
135
|
+
* size worth thinking about, and a flat typed array is one allocation.
|
|
136
|
+
*
|
|
137
|
+
* When neither direction is better the walk prefers the REMOVAL, which is what
|
|
138
|
+
* puts every deleted line of a hunk above every added one — the unified-diff
|
|
139
|
+
* order, and the order the renderer's red-then-green block depends on.
|
|
140
|
+
*/
|
|
141
|
+
function align(beforeMiddle, afterMiddle, offset) {
|
|
142
|
+
const m = beforeMiddle.length;
|
|
143
|
+
const n = afterMiddle.length;
|
|
144
|
+
const width = n + 1;
|
|
145
|
+
const table = lcsTable(beforeMiddle, afterMiddle);
|
|
146
|
+
const lines = [];
|
|
147
|
+
let added = 0;
|
|
148
|
+
let removed = 0;
|
|
149
|
+
let i = 0;
|
|
150
|
+
let j = 0;
|
|
151
|
+
while (i < m && j < n) {
|
|
152
|
+
if (beforeMiddle[i] === afterMiddle[j]) {
|
|
153
|
+
lines.push(sameLine(beforeMiddle[i] ?? '', offset + i + 1, offset + j + 1));
|
|
154
|
+
i += 1;
|
|
155
|
+
j += 1;
|
|
156
|
+
}
|
|
157
|
+
else if ((table[(i + 1) * width + j] ?? 0) >= (table[i * width + j + 1] ?? 0)) {
|
|
158
|
+
lines.push(removedLine(beforeMiddle[i] ?? '', offset + i + 1));
|
|
159
|
+
removed += 1;
|
|
160
|
+
i += 1;
|
|
161
|
+
}
|
|
162
|
+
else {
|
|
163
|
+
lines.push(addedLine(afterMiddle[j] ?? '', offset + j + 1));
|
|
164
|
+
added += 1;
|
|
165
|
+
j += 1;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
// Whatever is left when one side runs out. Removals first, again, so a hunk at
|
|
169
|
+
// the very end of the file reads the same way as one in the middle.
|
|
170
|
+
const tail = drain(beforeMiddle.slice(i), afterMiddle.slice(j), offset + i, offset + j);
|
|
171
|
+
lines.push(...tail.lines);
|
|
172
|
+
return {
|
|
173
|
+
lines,
|
|
174
|
+
added: added + tail.added,
|
|
175
|
+
removed: removed + tail.removed,
|
|
176
|
+
alignment: 'exact',
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* The remainder of one side, once the walk has exhausted the other.
|
|
181
|
+
*
|
|
182
|
+
* At most one of these two arrays is non-empty — the walk only stops when an
|
|
183
|
+
* index reaches its end — so this is not a second comparison. It is the same
|
|
184
|
+
* shape as {@link coarse}, and calling that would have been tempting; it is
|
|
185
|
+
* separate because `coarse` means "we declined to line these up" and this means
|
|
186
|
+
* "there was nothing left to line them up against", and a screen that reads
|
|
187
|
+
* `alignment` must not be told the first when the second happened.
|
|
188
|
+
*/
|
|
189
|
+
function drain(beforeRest, afterRest, beforeOffset, afterOffset) {
|
|
190
|
+
return {
|
|
191
|
+
lines: [
|
|
192
|
+
...beforeRest.map((text, index) => removedLine(text, beforeOffset + index + 1)),
|
|
193
|
+
...afterRest.map((text, index) => addedLine(text, afterOffset + index + 1)),
|
|
194
|
+
],
|
|
195
|
+
added: afterRest.length,
|
|
196
|
+
removed: beforeRest.length,
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* `table[i * width + j]` is the length of the longest common subsequence of
|
|
201
|
+
* `a.slice(i)` and `b.slice(j)`.
|
|
202
|
+
*
|
|
203
|
+
* Filled from the END, which is what lets {@link align} walk forwards and emit
|
|
204
|
+
* lines already in file order rather than reversing at the finish.
|
|
205
|
+
*/
|
|
206
|
+
function lcsTable(a, b) {
|
|
207
|
+
const width = b.length + 1;
|
|
208
|
+
const table = new Uint32Array((a.length + 1) * width);
|
|
209
|
+
for (let i = a.length - 1; i >= 0; i -= 1) {
|
|
210
|
+
for (let j = b.length - 1; j >= 0; j -= 1) {
|
|
211
|
+
table[i * width + j] =
|
|
212
|
+
a[i] === b[j]
|
|
213
|
+
? (table[(i + 1) * width + j + 1] ?? 0) + 1
|
|
214
|
+
: Math.max(table[(i + 1) * width + j] ?? 0, table[i * width + j + 1] ?? 0);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
return table;
|
|
218
|
+
}
|
|
219
|
+
function removedLine(text, before) {
|
|
220
|
+
return { op: 'removed', before, after: null, text };
|
|
221
|
+
}
|
|
222
|
+
function addedLine(text, after) {
|
|
223
|
+
return { op: 'added', before: null, after, text };
|
|
224
|
+
}
|
|
225
|
+
/** The whole changed region as one removal and one addition. See {@link DIFF_MAX_CELLS}. */
|
|
226
|
+
function coarse(beforeMiddle, afterMiddle, offset) {
|
|
227
|
+
return {
|
|
228
|
+
lines: [
|
|
229
|
+
...beforeMiddle.map((text, index) => ({
|
|
230
|
+
op: 'removed',
|
|
231
|
+
before: offset + index + 1,
|
|
232
|
+
after: null,
|
|
233
|
+
text,
|
|
234
|
+
})),
|
|
235
|
+
...afterMiddle.map((text, index) => ({
|
|
236
|
+
op: 'added',
|
|
237
|
+
before: null,
|
|
238
|
+
after: offset + index + 1,
|
|
239
|
+
text,
|
|
240
|
+
})),
|
|
241
|
+
],
|
|
242
|
+
added: afterMiddle.length,
|
|
243
|
+
removed: beforeMiddle.length,
|
|
244
|
+
alignment: 'coarse',
|
|
245
|
+
};
|
|
246
|
+
}
|
|
247
|
+
/** Lines to keep either side of a change before folding the rest away. */
|
|
248
|
+
export const DIFF_CONTEXT_LINES = 3;
|
|
249
|
+
/**
|
|
250
|
+
* The smallest run worth putting a button on.
|
|
251
|
+
*
|
|
252
|
+
* Folding two lines behind a control that says "2 unchanged lines" costs a row
|
|
253
|
+
* to save two, and it costs a click. Below this the run is simply shown.
|
|
254
|
+
*/
|
|
255
|
+
export const DIFF_MIN_FOLD = 4;
|
|
256
|
+
/**
|
|
257
|
+
* Collapse the long unchanged stretches, keeping context around every change.
|
|
258
|
+
*
|
|
259
|
+
* A transform can be hundreds of lines and the answer to "why did Tuesday's load
|
|
260
|
+
* differ from Monday's" is almost never more than a handful of them. Rendering
|
|
261
|
+
* all of it puts the four lines that matter somewhere in the middle of a wall
|
|
262
|
+
* and makes the reader scroll for them.
|
|
263
|
+
*
|
|
264
|
+
* Folded rather than dropped, and the sections carry their lines rather than a
|
|
265
|
+
* count, so the renderer can expand one in place. A diff that hides code with no
|
|
266
|
+
* way to see it is a diff you cannot trust, and this is code somebody is about
|
|
267
|
+
* to make a decision about.
|
|
268
|
+
*
|
|
269
|
+
* A run at the very start or end of the file gets no context on that side —
|
|
270
|
+
* there is no change up there to be in the context of.
|
|
271
|
+
*/
|
|
272
|
+
export function foldUnchanged(lines, context = DIFF_CONTEXT_LINES, minFold = DIFF_MIN_FOLD) {
|
|
273
|
+
const sections = [];
|
|
274
|
+
let shown = [];
|
|
275
|
+
const flush = () => {
|
|
276
|
+
if (shown.length > 0) {
|
|
277
|
+
sections.push({ kind: 'shown', lines: shown });
|
|
278
|
+
shown = [];
|
|
279
|
+
}
|
|
280
|
+
};
|
|
281
|
+
let index = 0;
|
|
282
|
+
while (index < lines.length) {
|
|
283
|
+
const line = lines[index];
|
|
284
|
+
if (!line)
|
|
285
|
+
break;
|
|
286
|
+
if (line.op !== 'same') {
|
|
287
|
+
shown.push(line);
|
|
288
|
+
index += 1;
|
|
289
|
+
continue;
|
|
290
|
+
}
|
|
291
|
+
const end = runEnd(lines, index);
|
|
292
|
+
const run = lines.slice(index, end);
|
|
293
|
+
// No context on a side there is no change on: a run touching the start of
|
|
294
|
+
// the file has nothing above it to be the context of, and neither does one
|
|
295
|
+
// touching the end.
|
|
296
|
+
const leading = index === 0 ? 0 : context;
|
|
297
|
+
const trailing = end === lines.length ? 0 : context;
|
|
298
|
+
if (run.length > leading + trailing + minFold) {
|
|
299
|
+
shown.push(...run.slice(0, leading));
|
|
300
|
+
flush();
|
|
301
|
+
sections.push({ kind: 'folded', lines: run.slice(leading, run.length - trailing) });
|
|
302
|
+
shown.push(...run.slice(run.length - trailing));
|
|
303
|
+
}
|
|
304
|
+
else {
|
|
305
|
+
shown.push(...run);
|
|
306
|
+
}
|
|
307
|
+
index = end;
|
|
308
|
+
}
|
|
309
|
+
flush();
|
|
310
|
+
return sections;
|
|
311
|
+
}
|
|
312
|
+
/** Where the run of unchanged lines starting at `start` stops. */
|
|
313
|
+
function runEnd(lines, start) {
|
|
314
|
+
let end = start;
|
|
315
|
+
while (end < lines.length && lines[end]?.op === 'same')
|
|
316
|
+
end += 1;
|
|
317
|
+
return end;
|
|
318
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -17,11 +17,13 @@ export { CATALOG_EVENT_META, type CatalogTraceSource, eventMeta, TraceExplorer,
|
|
|
17
17
|
export { ConnectionPanel, type ConnectionPanelProps, connectionOptionsFor, describeConnection, } from './ConnectionPanel';
|
|
18
18
|
export { type ColumnChoice, type ConnectorSchemaDiscovery, type DiscoveredColumn, type DiscoveredTypeDraft, initialChoices, PipelineConsole, type PipelineConsoleProps, proposalFrom, type SchemaDiscoveryBridge, type SchemaDrift, } from './PipelineConsole';
|
|
19
19
|
export { TransformEditor, type TransformEditorProps } from './TransformEditor';
|
|
20
|
+
export { DiffBody, RevisionHistory, type RevisionHistoryProps, RevisionHistoryButton, RevisionHistorySheet, type RevisionHistorySheetProps, type RevisionSubject, type RevisionSubjectKind, } from './diff/RevisionDiff';
|
|
21
|
+
export { DIFF_CONTEXT_LINES, DIFF_MAX_CELLS, DIFF_MIN_FOLD, type DiffLine, type DiffOp, type DiffSection, diffLines, foldUnchanged, type LineDiff, } from './diff/line-diff';
|
|
20
22
|
export { AccessConsole, type AccessConsoleProps } from './AccessConsole';
|
|
21
23
|
export { type CatalogWorkflow, describeDurability, type DurabilityCopy, isWorkflowNodeKind, newLocalId, nodeName, producedTypes, WORKFLOW_NODE_ID_PATTERN, WORKFLOW_NODE_KINDS, type WorkflowDurability, type WorkflowEdge, type WorkflowGraph, type WorkflowInput, type WorkflowNode, type WorkflowNodeKind, type WorkflowRun, type WorkflowRunNode, type WorkflowSinkNode, type WorkflowSourceNode, type WorkflowTransformNode, } from './workflow/model';
|
|
22
24
|
export { WORKFLOW_NAME } from './workflow/name';
|
|
23
25
|
export { canConnect, type ConnectionVerdict, edgeId, hasBlockingProblem, problemsByNode, type ValidateOptions, validateWorkflow, type WorkflowDraft, type WorkflowProblem, type WorkflowProblemCode, type WorkflowProblemLevel, wouldCycle, } from './workflow/validate';
|
|
24
|
-
export { type CatalogClient, type CatalogIdentity, type CatalogPeoplePage, type CatalogPersonRole, type CatalogPersonSummary, type CatalogPrincipalSummary, CatalogProvider, type CatalogProviderProps, type CatalogTransport, type ConnectionInput, type ConnectorInput, catalogQueryKeys, type PersonInput, type PersonUpsertResult, type PipelineCapabilities, type TransformInput, useCatalogClient, } from './context';
|
|
26
|
+
export { type CatalogClient, type CatalogIdentity, type CatalogRevision, type CatalogPeoplePage, type CatalogPersonRole, type CatalogPersonSummary, type CatalogPrincipalSummary, CatalogProvider, type CatalogProviderProps, type CatalogTransport, type ConnectionInput, type ConnectorInput, catalogQueryKeys, type PersonInput, type PersonUpsertResult, type PipelineCapabilities, type TransformInput, useCatalogClient, } from './context';
|
|
25
27
|
export { type AccessRoutes, accessRoutes, DEFAULT_ACCESS_BASE_PATH, DEFAULT_PIPELINE_BASE_PATH, DEFAULT_PUBLISH_BASE_PATH, embedRoutes, type PeopleQuery, type PipelineRoutes, pipelineRoutes, } from './routes';
|
|
26
28
|
export { ConfirmDialog } from './ui/dialog';
|
|
27
29
|
export { FieldGroup, TextAreaField, TextField } from './ui/field';
|
package/dist/index.js
CHANGED
|
@@ -41,6 +41,20 @@ export { ConnectionPanel, connectionOptionsFor, describeConnection, } from './Co
|
|
|
41
41
|
// worth nothing there if the only way to run them is to render it.
|
|
42
42
|
export { initialChoices, PipelineConsole, proposalFrom, } from './PipelineConsole';
|
|
43
43
|
export { TransformEditor } from './TransformEditor';
|
|
44
|
+
// Why one load came out different from the last one.
|
|
45
|
+
//
|
|
46
|
+
// The screens above already carry their own way in — the transform editor, the
|
|
47
|
+
// saved-query list, and the `code v3` on a connector run — so a host mounting
|
|
48
|
+
// this console needs none of this. It is exported for the host that wants the
|
|
49
|
+
// comparison somewhere else: beside its own deploy log, in an approval flow, or
|
|
50
|
+
// on a page this package does not ship.
|
|
51
|
+
//
|
|
52
|
+
// `diffLines` and `foldUnchanged` are pure and come with it deliberately. They
|
|
53
|
+
// are the whole of the algorithm, they take no dependency and reach no network,
|
|
54
|
+
// and a host that wants to render a comparison its own way should not have to
|
|
55
|
+
// choose between this package's markup and writing an LCS.
|
|
56
|
+
export { DiffBody, RevisionHistory, RevisionHistoryButton, RevisionHistorySheet, } from './diff/RevisionDiff';
|
|
57
|
+
export { DIFF_CONTEXT_LINES, DIFF_MAX_CELLS, DIFF_MIN_FOLD, diffLines, foldUnchanged, } from './diff/line-diff';
|
|
44
58
|
export { AccessConsole } from './AccessConsole';
|
|
45
59
|
// The authored graph: sources wired through transforms into sinks.
|
|
46
60
|
//
|
package/dist/routes.d.ts
CHANGED
|
@@ -92,6 +92,21 @@ export interface PipelineRoutes {
|
|
|
92
92
|
runs(): string;
|
|
93
93
|
transforms(): string;
|
|
94
94
|
transform(id: string): string;
|
|
95
|
+
/**
|
|
96
|
+
* Every version of a transform's code that was ever saved, newest first.
|
|
97
|
+
*
|
|
98
|
+
* A sub-resource of the transform rather than a `?version=` on it, because the
|
|
99
|
+
* question this answers is "what were all of them" — a screen comparing the
|
|
100
|
+
* version that ran against the version that is current has to see the list
|
|
101
|
+
* before it knows which two ids to name, and one request that answers that is
|
|
102
|
+
* cheaper than a list request plus two fetches.
|
|
103
|
+
*
|
|
104
|
+
* `CatalogTransform.version` is a counter over a row that is overwritten in
|
|
105
|
+
* place, so before this route existed the number on a run — `code v3` in the
|
|
106
|
+
* runs list — named code that no longer existed anywhere. The version stayed
|
|
107
|
+
* traceable and the code did not.
|
|
108
|
+
*/
|
|
109
|
+
transformRevisions(id: string): string;
|
|
95
110
|
tryTransform(): string;
|
|
96
111
|
/**
|
|
97
112
|
* Authored graphs of transforms. GET lists, POST creates or updates.
|
package/dist/routes.js
CHANGED
|
@@ -53,6 +53,22 @@ export const embedRoutes = {
|
|
|
53
53
|
chart: (id) => `/catalog/embed/charts/${encodeURIComponent(id)}`,
|
|
54
54
|
dashboard: (id) => `/catalog/embed/dashboards/${encodeURIComponent(id)}`,
|
|
55
55
|
};
|
|
56
|
+
/*
|
|
57
|
+
* A saved query's history is deliberately NOT here.
|
|
58
|
+
*
|
|
59
|
+
* `GET /catalog/saved-queries/:id/revisions` is served by the catalog library's
|
|
60
|
+
* own controller, so by this file's header it belongs beside `catalogRoutes` —
|
|
61
|
+
* and that is where it is: `catalogRoutes.savedQueryRevisions`. The note is here
|
|
62
|
+
* because a reader looking for the pair of it will find `transformRevisions` on
|
|
63
|
+
* `PipelineRoutes` below and reasonably wonder where the other half went. The
|
|
64
|
+
* split is the whole argument of this file: transforms are served by the host
|
|
65
|
+
* and move with the base path it chose; saved queries are served by the library
|
|
66
|
+
* and cannot move at all.
|
|
67
|
+
*
|
|
68
|
+
* A plain comment rather than a docblock on purpose — there is no declaration
|
|
69
|
+
* here for it to belong to, and a `/**` would attach itself to the constant
|
|
70
|
+
* below and describe the wrong thing in every editor tooltip.
|
|
71
|
+
*/
|
|
56
72
|
/** Where the pipeline endpoints sit unless the host says otherwise. */
|
|
57
73
|
export const DEFAULT_PIPELINE_BASE_PATH = '/pipeline';
|
|
58
74
|
/**
|
|
@@ -94,6 +110,7 @@ export function pipelineRoutes(basePath = DEFAULT_PIPELINE_BASE_PATH) {
|
|
|
94
110
|
runs: () => `${base}/runs`,
|
|
95
111
|
transforms: () => `${base}/transforms`,
|
|
96
112
|
transform: (id) => `${base}/transforms/${encodeURIComponent(id)}`,
|
|
113
|
+
transformRevisions: (id) => `${base}/transforms/${encodeURIComponent(id)}/revisions`,
|
|
97
114
|
tryTransform: () => `${base}/transforms/try`,
|
|
98
115
|
workflows: () => `${base}/workflows`,
|
|
99
116
|
workflow: (id) => `${base}/workflows/${encodeURIComponent(id)}`,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dudousxd/nestjs-catalog-react",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.15.0",
|
|
4
4
|
"description": "Ready-made React screens for @dudousxd/nestjs-catalog — a model manager and a generic object explorer you can drop into your own app shell.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Davide Carvalho",
|
|
@@ -106,7 +106,7 @@
|
|
|
106
106
|
"@tiptap/pm": "3.29.2",
|
|
107
107
|
"tiptap-markdown": "0.9.0",
|
|
108
108
|
"@tiptap/core": "3.29.2",
|
|
109
|
-
"@dudousxd/nestjs-catalog": "0.
|
|
109
|
+
"@dudousxd/nestjs-catalog": "0.12.0"
|
|
110
110
|
},
|
|
111
111
|
"dependencies": {
|
|
112
112
|
"clsx": "2.1.1",
|