@dudousxd/nestjs-catalog-react 0.16.0 → 0.18.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. package/README.md +39 -13
  2. package/dist/ConnectionPanel.d.ts +11 -7
  3. package/dist/ConnectionPanel.js +65 -28
  4. package/dist/ObjectExplorer.js +424 -48
  5. package/dist/PipelineConsole.d.ts +23 -126
  6. package/dist/PipelineConsole.js +39 -551
  7. package/dist/QueryConsole.js +25 -17
  8. package/dist/SavedQueryPanel.js +1 -1
  9. package/dist/TransformEditor.js +12 -3
  10. package/dist/WorkflowCanvas.js +401 -29
  11. package/dist/bundler/index.d.ts +20 -0
  12. package/dist/bundler/index.js +20 -0
  13. package/dist/bundler/shiki-subset.d.ts +83 -0
  14. package/dist/bundler/shiki-subset.js +196 -0
  15. package/dist/context.d.ts +181 -38
  16. package/dist/context.js +44 -11
  17. package/dist/diff/RevisionDiff.d.ts +67 -4
  18. package/dist/diff/RevisionDiff.js +126 -91
  19. package/dist/index.d.ts +8 -5
  20. package/dist/index.js +56 -20
  21. package/dist/routes.d.ts +54 -13
  22. package/dist/routes.js +5 -4
  23. package/dist/schema-discovery.d.ts +216 -0
  24. package/dist/schema-discovery.js +225 -0
  25. package/dist/source-fields.d.ts +1 -12
  26. package/dist/source-fields.js +13 -16
  27. package/dist/ui/code-editor.d.ts +196 -8
  28. package/dist/ui/code-editor.js +184 -72
  29. package/dist/ui/code-languages.d.ts +80 -0
  30. package/dist/ui/code-languages.js +76 -0
  31. package/dist/ui/code-theme.d.ts +25 -0
  32. package/dist/ui/code-theme.js +26 -0
  33. package/dist/ui/dialog.d.ts +13 -1
  34. package/dist/ui/dialog.js +13 -2
  35. package/dist/workflow/graph.js +31 -9
  36. package/dist/workflow/index.d.ts +2 -0
  37. package/dist/workflow/index.js +7 -0
  38. package/dist/workflow/lifecycle.d.ts +164 -0
  39. package/dist/workflow/lifecycle.js +249 -0
  40. package/dist/workflow/model.d.ts +1 -1
  41. package/dist/workflow/nodes.js +10 -1
  42. package/dist/workflow/runs.d.ts +38 -0
  43. package/dist/workflow/runs.js +101 -0
  44. package/dist/workflow/shape.d.ts +169 -0
  45. package/dist/workflow/shape.js +249 -0
  46. package/dist/workflow/templates.d.ts +623 -0
  47. package/dist/workflow/templates.js +1092 -0
  48. package/dist/workflow/validate.d.ts +20 -1
  49. package/dist/workflow/validate.js +41 -3
  50. package/package.json +21 -17
  51. package/dist/diff/line-diff.d.ts +0 -124
  52. package/dist/diff/line-diff.js +0 -318
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()),
@@ -54,13 +55,9 @@ export function CatalogProvider({ transport, pipelineBasePath = DEFAULT_PIPELINE
54
55
  listConnections: () => transport.get(pipeline.connections()),
55
56
  saveConnection: (input) => transport.post(pipeline.connections(), input),
56
57
  checkConnection: (id) => transport.post(pipeline.checkConnection(id), {}),
57
- connectionConnectors: (id) => transport.get(pipeline.connectionConnectors(id)),
58
+ connectionWorkflows: (id) => transport.get(pipeline.connectionWorkflows(id)),
58
59
  deleteConnection: (id) => transport.delete(pipeline.connection(id)),
59
60
  listConnectors: () => transport.get(pipeline.connectors()),
60
- saveConnector: (input) => transport.post(pipeline.connectors(), input),
61
- deleteConnector: (id) => transport.delete(pipeline.connector(id)),
62
- runConnector: (id) => transport.post(pipeline.runConnector(id), {}),
63
- discoverConnectorSchema: (id) => transport.post(pipeline.discoverConnectorSchema(id), {}),
64
61
  publishType: (name, schema) => {
65
62
  if (!transport.put) {
66
63
  throw new Error('This transport cannot PUT, so it cannot publish a type. Implement `put` on the ' +
@@ -91,8 +88,31 @@ export function CatalogProvider({ transport, pipelineBasePath = DEFAULT_PIPELINE
91
88
  tryTransform: (input) => transport.post(pipeline.tryTransform(), input),
92
89
  listWorkflows: () => transport.get(pipeline.workflows()),
93
90
  saveWorkflow: (input) => transport.post(pipeline.workflows(), input),
91
+ publishWorkflow: (id) => transport.post(pipeline.publishWorkflow(id), {}),
92
+ unpublishWorkflow: (id) => transport.post(pipeline.unpublishWorkflow(id), {}),
94
93
  deleteWorkflow: (id) => transport.delete(pipeline.workflow(id)),
95
- runWorkflow: (id) => transport.post(pipeline.runWorkflow(id), {}),
94
+ // The two fields are spread conditionally rather than sent as
95
+ // `undefined`, and for `expectShrink` that is the whole contract: the
96
+ // server distinguishes a body with no such key — nobody said anything,
97
+ // let the bound decide — from one carrying an empty string, which is an
98
+ // acknowledgement with no reason behind it and is refused with a 400
99
+ // asking for one. A transport that serialises `undefined` as `null`, or
100
+ // one that drops it, would flatten those two into each other.
101
+ runWorkflow: (id, options) => transport.post(pipeline.runWorkflow(id), {
102
+ ...(options?.snapshotId === undefined ? {} : { snapshotId: options.snapshotId }),
103
+ ...(options && 'expectShrink' in options && options.expectShrink !== undefined
104
+ ? { expectShrink: options.expectShrink }
105
+ : {}),
106
+ }),
107
+ scheduleWorkflow: (id, input) => {
108
+ if (!transport.put) {
109
+ throw new Error('This transport cannot PUT, so it cannot set a schedule. Implement `put` on the ' +
110
+ 'transport you passed to CatalogProvider — a schedule is an idempotent upsert of ' +
111
+ 'the fields it names, which is why the route is a PUT and not a POST.');
112
+ }
113
+ return transport.put(pipeline.workflowSchedule(id), input);
114
+ },
115
+ discoverSourceSchema: (workflowId, nodeId) => transport.post(pipeline.discoverSourceSchema(workflowId, nodeId), {}),
96
116
  listPrincipals: () => transport.get(access.principals()),
97
117
  listPeople: (query) => transport.get(access.people(query)),
98
118
  upsertPerson: (input) => transport.post(access.people(), input),
@@ -112,6 +132,14 @@ export const catalogQueryKeys = {
112
132
  all: ['nestjs-catalog'],
113
133
  snapshot: ['nestjs-catalog', 'snapshot'],
114
134
  objects: (type, params) => ['nestjs-catalog', 'objects', type, params],
135
+ /**
136
+ * A type's loads, keyed by type and NOT by the read's parameters.
137
+ *
138
+ * The list is a property of the type, so paging, sorting and filtering must
139
+ * not re-ask for it — keyed under `objects(type, params)` it would be fetched
140
+ * again on every keystroke of a search box.
141
+ */
142
+ objectSnapshots: (type) => ['nestjs-catalog', 'objects', type, 'snapshots'],
115
143
  /**
116
144
  * Keyed on the term, so react-query caches per term and a backspace shows the
117
145
  * previous answer instantly instead of re-asking.
@@ -126,11 +154,16 @@ export const catalogQueryKeys = {
126
154
  search: (term, limit) => ['nestjs-catalog', 'search', term, limit ?? null],
127
155
  /**
128
156
  * The pipeline keys are nested under one prefix so a host — or a screen that
129
- * just ran a connector — can invalidate the whole of it at once. Running a
130
- * connector changes the runs, the connector's own last-run fields, and the
131
- * catalog snapshot the load wrote into, and invalidating them one by one is
132
- * how a list ends up showing a run that finished next to a connector that
133
- * still says it never has.
157
+ * just ran a pipeline — can invalidate the whole of it at once. Running one
158
+ * changes the runs, the connector's own last-run fields, and the catalog
159
+ * snapshot the load wrote into, and invalidating them one by one is how a
160
+ * screen ends up showing a run that finished next to a pipeline that still
161
+ * says it never has.
162
+ *
163
+ * `connectors` is still here and is still worth invalidating, even though
164
+ * nothing authors one any more: publishing a graph MINTS one, unpublishing
165
+ * disables it, and deleting takes it away — so the read that says which id a
166
+ * run history is keyed on goes stale on all three.
134
167
  */
135
168
  pipeline: ['nestjs-catalog', 'pipeline'],
136
169
  capabilities: ['nestjs-catalog', 'pipeline', 'capabilities'],
@@ -1,4 +1,4 @@
1
- import { type DiffLine, type DiffSection } from './line-diff';
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
- export declare function DiffBody({ before, after }: {
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 };
@@ -1,14 +1,17 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { CATALOG_REVISION_LIMIT } from '@dudousxd/nestjs-catalog/client';
3
+ import { parseDiffFromFile } from '@pierre/diffs';
4
+ import { MultiFileDiff } from '@pierre/diffs/react';
3
5
  import { useQuery } from '@tanstack/react-query';
4
6
  import { GitCompare, History } from 'lucide-react';
5
7
  import { useMemo, useState } from 'react';
6
8
  import { cn } from '../cn';
7
9
  import { catalogQueryKeys, useCatalogClient } from '../context';
8
10
  import { Button } from '../ui/button';
11
+ import { codeOptions } from '../ui/code-editor';
12
+ import { useCodeThemeType } from '../ui/code-theme';
9
13
  import { SelectField } from '../ui/select';
10
14
  import { Sheet } from '../ui/sheet';
11
- import { diffLines, foldUnchanged } from './line-diff';
12
15
  /**
13
16
  * Why a load came out different from the last one.
14
17
  *
@@ -47,29 +50,11 @@ import { diffLines, foldUnchanged } from './line-diff';
47
50
  const MUTED = 'text-zinc-400 dark:text-zinc-500';
48
51
  const RULE = 'border-zinc-200 dark:border-zinc-800';
49
52
  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 }) {
53
+ /** What a side is picked by. Versions are numbers and the buffer is not. */
54
+ function keyOf(side) {
55
+ return side.origin === 'buffer' ? 'buffer' : String(side.version);
56
+ }
57
+ export function RevisionHistory({ subject, current, buffer, ranVersion }) {
73
58
  const client = useCatalogClient();
74
59
  const revisions = useQuery({
75
60
  queryKey: subject.kind === 'transform'
@@ -79,20 +64,26 @@ export function RevisionHistory({ subject, current, ranVersion }) {
79
64
  ? client.listTransformRevisions(subject.id)
80
65
  : client.listSavedQueryRevisions(subject.id),
81
66
  });
82
- const sides = useMemo(() => sidesFrom(revisions.data ?? [], current), [revisions.data, current]);
67
+ const sides = useMemo(() => sidesFrom(revisions.data ?? [], current, buffer), [revisions.data, current, buffer]);
83
68
  /**
84
- * Which two are on screen, as VERSION NUMBERS rather than indices.
69
+ * Which two are on screen, as SIDE KEYS rather than indices.
85
70
  *
86
71
  * `null` means "whatever the default is", so a background refetch that adds a
87
72
  * newer revision moves the right-hand side onto it — which is what somebody
88
73
  * who has not touched the selects expects. Storing an index instead would
89
74
  * silently repoint both sides at different versions when the list grew, and an
90
75
  * index is not a thing anybody chose.
76
+ *
77
+ * A key rather than a version number because the buffer has no version, and a
78
+ * `number | null` state could not tell "the unsaved buffer" apart from "no
79
+ * choice made yet".
91
80
  */
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];
81
+ const [leftKey, setLeftKey] = useState(null);
82
+ const [rightKey, setRightKey] = useState(null);
83
+ const right = pick(sides, rightKey) ?? sides[0];
84
+ const left = pick(sides, leftKey) ??
85
+ pick(sides, ranVersion === undefined ? null : String(ranVersion)) ??
86
+ sides[1];
96
87
  if (revisions.isPending) {
97
88
  return _jsx(Notice, { children: "Reading the history\u2026" });
98
89
  }
@@ -105,7 +96,7 @@ export function RevisionHistory({ subject, current, ranVersion }) {
105
96
  if (sides.length === 1 || !left || !right) {
106
97
  return _jsx(OnlyOneVersion, { subject: subject, only: sides[0] });
107
98
  }
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 })] }));
99
+ 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: keyOf(left), onChange: setLeftKey }), _jsx("span", { className: cn('pb-1.5 font-mono text-[11px]', MUTED), children: "\u2192" }), _jsx(SidePicker, { label: "Against", ariaLabel: "Against version", sides: sides, value: keyOf(right), onChange: setRightKey })] }), _jsx(Authorship, { left: left, right: right }), _jsx(DiffBody, { before: left.body, after: right.body, ...(subject.kind === 'saved-query' ? { language: 'sql' } : {}), name: subject.name })] }));
109
100
  }
110
101
  /**
111
102
  * The saved-query history key, which lives on the OTHER prefix.
@@ -131,51 +122,72 @@ function savedQueryRevisionKey(id) {
131
122
  * every addition as a deletion — a comparison that is exactly backwards and
132
123
  * looks entirely plausible.
133
124
  */
134
- function sidesFrom(revisions, current) {
125
+ function sidesFrom(revisions, current, buffer) {
135
126
  const sides = revisions
136
127
  .map((revision) => ({
128
+ origin: 'recorded',
137
129
  version: revision.version,
138
130
  body: revision.body,
139
131
  authoredBy: revision.authoredBy,
140
132
  authoredAt: revision.authoredAt,
141
- live: false,
142
133
  }))
143
134
  .sort((a, b) => b.version - a.version);
144
135
  if (current && !sides.some((side) => side.version === current.version)) {
145
136
  sides.unshift({
137
+ origin: 'current',
146
138
  version: current.version,
147
139
  body: current.body,
148
140
  authoredBy: null,
149
141
  authoredAt: null,
150
- live: true,
142
+ });
143
+ }
144
+ // Only with something to compare against — see `RevisionHistoryProps.buffer`.
145
+ if (buffer && sides.length > 0) {
146
+ sides.unshift({
147
+ origin: 'buffer',
148
+ version: null,
149
+ body: buffer.body,
150
+ authoredBy: null,
151
+ authoredAt: null,
151
152
  });
152
153
  }
153
154
  return sides;
154
155
  }
155
- function pick(sides, version) {
156
- if (version === null)
156
+ function pick(sides, key) {
157
+ if (key === null)
157
158
  return undefined;
158
- return sides.find((side) => side.version === version);
159
+ return sides.find((side) => keyOf(side) === key);
159
160
  }
160
161
  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),
162
+ return (_jsx(SelectField, { label: label, ariaLabel: ariaLabel, value: value,
163
+ // No parse. The select speaks strings and so does a side key, which is
164
+ // half the reason the key exists: the version was `Number`-ed back out of
165
+ // this callback, and the buffer has no number to produce.
166
+ onValueChange: onChange, className: "min-w-[10rem]", options: sides.map((side) => ({
167
+ value: keyOf(side),
168
+ label: labelOf(side),
169
+ hint: hintOf(side),
171
170
  })) }));
172
171
  }
173
172
  /** Who wrote each side and when, which is half of what "why did this change" means. */
174
173
  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)] }));
174
+ return (_jsxs("p", { className: cn('font-mono text-[10px] leading-relaxed', MUTED), children: [labelOf(left), " ", describeAuthor(left), " \u2192 ", labelOf(right), " ", describeAuthor(right)] }));
175
+ }
176
+ /** What a side is called. The buffer is named by what it is, having no number. */
177
+ function labelOf(side) {
178
+ return side.origin === 'buffer' ? 'Unsaved edits' : `v${side.version}`;
179
+ }
180
+ function hintOf(side) {
181
+ if (side.origin === 'buffer')
182
+ return 'in the editor, not saved';
183
+ if (side.origin === 'current')
184
+ return 'current, not yet recorded';
185
+ return side.authoredBy ?? undefined;
176
186
  }
177
187
  function describeAuthor(side) {
178
- if (side.live)
188
+ if (side.origin === 'buffer')
189
+ return '(this browser tab)';
190
+ if (side.origin === 'current')
179
191
  return '(current)';
180
192
  const who = side.authoredBy ?? 'unknown';
181
193
  // The locale's own format. A console rendering an ISO string at somebody is
@@ -183,54 +195,77 @@ function describeAuthor(side) {
183
195
  const when = side.authoredAt ? new Date(side.authoredAt).toLocaleString() : 'unknown date';
184
196
  return `by ${who}, ${when}`;
185
197
  }
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
198
  /**
203
- * A stable key for a diff row, out of the numbering it already carries.
199
+ * The comparison itself.
200
+ *
201
+ * Split out from the fetching above so it can be rendered — and tested — from
202
+ * two plain strings, which is what the thing actually being asserted is.
203
+ *
204
+ * WHY THIS IS NO LONGER HAND-ROLLED
205
+ * ---------------------------------
206
+ * It used to be `line-diff.ts` — forty lines of LCS, a fold, and a row
207
+ * renderer — whose docblock argued that the two strings a catalog diffs are a
208
+ * transform's code and somebody's SQL against military logistics data, and that
209
+ * there was no version of this screen worth a supply-chain question mark on
210
+ * that content, so there was no dependency at all. That argument is dead, and it
211
+ * was not this file that killed it: `@pierre/diffs` is now the EDITOR, so it
212
+ * already sees every one of those strings on every keystroke. Keeping a second,
213
+ * weaker differ beside it to avoid a dependency that is already there would buy
214
+ * nothing and cost a divergence — two components disagreeing about what changed,
215
+ * which is the one thing a diff must not do. `line-diff.ts` and its spec are
216
+ * gone; the argument went with them rather than being left standing next to a
217
+ * package that refutes it.
218
+ *
219
+ * What is lost with it: the `coarse` fallback past `DIFF_MAX_CELLS` and the
220
+ * explicit row cap. Both were bounds on a hand-rolled algorithm. The renderer
221
+ * here is virtualised — it draws the rows in view and no more — so the wall of
222
+ * paint the cap existed to prevent is not reachable the same way.
204
223
  *
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.
224
+ * What is gained: word-level highlighting inside a changed line, which the old
225
+ * one explicitly could not do and which is most of the value when the answer to
226
+ * "why did Tuesday's load differ" is one renamed column.
211
227
  */
212
- function rowKey(line) {
213
- return `${line.before ?? '-'}:${line.after ?? '-'}`;
214
- }
228
+ export function DiffBody({ before, after,
215
229
  /**
216
- * One line.
230
+ * What to highlight it as.
217
231
  *
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.
232
+ * Optional and defaulting to nothing, because this component is reached from
233
+ * both subjects: a transform's code could be any of three languages and the
234
+ * sheet does not carry which, while a saved query is always SQL. Left unset,
235
+ * the name below carries no extension and the diff renders unhighlighted —
236
+ * which is honest, and better than colouring Python as SQL.
223
237
  *
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.
238
+ * Narrowed to {@link CatalogCodeLanguage} rather than left as `string`,
239
+ * because only the grammars in `ui/code-languages.ts` are in the bundle: a
240
+ * name outside them would render exactly like the `undefined` above, and the
241
+ * two nothings mean opposite things.
227
242
  */
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'] }) }));
243
+ language, name = 'version', }) {
244
+ const themeType = useCodeThemeType();
245
+ /**
246
+ * The counts in the header, from the same parse the renderer performs.
247
+ *
248
+ * Recomputed here rather than read off the rendered DOM, and that is the
249
+ * cheap half: `parseDiffFromFile` is memoised on the two bodies, and the
250
+ * hunks carry their own `+`/`-` line counts. `identical` is "no hunks", which
251
+ * is the only thing that means byte-for-byte equal — see this file's header
252
+ * for the three other nothings that must not borrow that sentence.
253
+ */
254
+ const summary = useMemo(() => {
255
+ const parsed = parseDiffFromFile({ name, contents: before, ...(language ? { lang: language } : {}) }, { name, contents: after, ...(language ? { lang: language } : {}) });
256
+ let added = 0;
257
+ let removed = 0;
258
+ for (const hunk of parsed.hunks) {
259
+ added += hunk.additionLines;
260
+ removed += hunk.deletionLines;
261
+ }
262
+ return { added, removed, identical: parsed.hunks.length === 0 };
263
+ }, [before, after, language, name]);
264
+ 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 }), summary.identical ? (_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: ["+", summary.added] }), ' ', _jsxs("span", { className: "text-red-600", children: ["\u2212", summary.removed] })] }))] }), _jsx(MultiFileDiff, { oldFile: { name, contents: before, ...(language ? { lang: language } : {}) }, newFile: { name, contents: after, ...(language ? { lang: language } : {}) },
265
+ // `unified`, not `split`: this sheet is already the width it is, and a
266
+ // side-by-side diff of code at half of it wraps every line back into the
267
+ // shape the editor was rewritten to escape.
268
+ options: { ...codeOptions(themeType), diffStyle: 'unified' } })] }));
234
269
  }
235
270
  function Notice({ children, tone = 'plain', }) {
236
271
  return (_jsx("div", { className: cn('rounded-lg border px-3 py-2 text-[11px] leading-relaxed', tone === 'plain' && cn(RULE, MUTED), tone === 'warn' &&
@@ -253,7 +288,7 @@ function NoHistory({ subject }) {
253
288
  }
254
289
  /** One version recorded. Also not a claim that nothing changed. */
255
290
  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."] })] }));
291
+ 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: [" (", labelOf(only), ")"] }) : 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
292
  }
258
293
  /**
259
294
  * The history, in the panel every entry point opens it in.
package/dist/index.d.ts CHANGED
@@ -16,22 +16,25 @@ export { CatalogSearch, type CatalogSearchProps } from './search-console';
16
16
  export { SavedQueryPanel } from './SavedQueryPanel';
17
17
  export { CATALOG_EVENT_META, type CatalogTraceSource, eventMeta, TraceExplorer, useTraceSource, } from './TraceExplorer';
18
18
  export { ConnectionPanel, type ConnectionPanelProps, connectionOptionsFor, describeConnection, } from './ConnectionPanel';
19
- export { type ColumnChoice, type ConnectorSchemaDiscovery, type DiscoveredColumn, type DiscoveredTypeDraft, initialChoices, PipelineConsole, type PipelineConsoleProps, proposalFrom, type SchemaDiscoveryBridge, type SchemaDrift, } from './PipelineConsole';
19
+ export { PipelineConsole, type PipelineConsoleProps, } from './PipelineConsole';
20
+ export { type ColumnChoice, type ConnectorSchemaDiscovery, type DiscoveredColumn, type DiscoveredTypeDraft, initialChoices, narrowDiscovery, proposalFrom, type SchemaDiscoveryBridge, SchemaDiscoveryPanel, type SchemaDrift, } from './schema-discovery';
20
21
  export { TransformEditor, type TransformEditorProps } from './TransformEditor';
21
22
  export { DiffBody, RevisionHistory, type RevisionHistoryProps, RevisionHistoryButton, RevisionHistorySheet, type RevisionHistorySheetProps, type RevisionSubject, type RevisionSubjectKind, } from './diff/RevisionDiff';
22
- export { DIFF_CONTEXT_LINES, DIFF_MAX_CELLS, DIFF_MIN_FOLD, type DiffLine, type DiffOp, type DiffSection, diffLines, foldUnchanged, type LineDiff, } from './diff/line-diff';
23
23
  export { AccessConsole, type AccessConsoleProps } from './AccessConsole';
24
- 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';
24
+ export { type CallableWorkflowRef, type CatalogWorkflow, describeDurability, type DurabilityCopy, isWorkflowNodeKind, newLocalId, nodeName, producedTypes, WORKFLOW_NODE_ID_PATTERN, WORKFLOW_NODE_KINDS, type WorkflowCallNode, 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';
25
25
  export { WORKFLOW_NAME } from './workflow/name';
26
+ export { checkShapes, type ShapeKnowledge, type SourceColumn, type SourceShape, type TargetProperty, type TargetShape, } from './workflow/shape';
26
27
  export { canConnect, type ConnectionVerdict, edgeId, hasBlockingProblem, problemsByNode, type ValidateOptions, validateWorkflow, type WorkflowDraft, type WorkflowProblem, type WorkflowProblemCode, type WorkflowProblemLevel, wouldCycle, } from './workflow/validate';
27
- 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 DeleteReconciliation, type LoadExpectation, type LoadExpectationInput, type ResolvedLoadExpectation, type RowCountBound, type StoredLoadExpectation, type PersonInput, type PersonUpsertResult, type PipelineCapabilities, type TransformInput, useCatalogClient, } from './context';
28
+ export { attachTransformIds, buildWorkflowTemplate, type EnrichOptions, enrichWithLookup, fanOutTypes, type FanOutOptions, type FanOutTarget, FILE_DROP_KINDS, type FileDropOptions, joinSources, type JoinOptions, loadFileDrop, type PeriodicFullReloadOptions, periodicFullReload, planIsRunnable, planToWorkflowInput, refuseUnusableColumnNames, RELOAD_CADENCE_IDS, RELOAD_CADENCES, type ReloadCadence, replicateTable, type ReplicateTableOptions, SOURCE_KINDS, type TemplateDeclaration, type TemplateExpectation, type TemplateOutcome, type TemplatePlan, type TemplateRefusal, type TemplateRefusalCode, type TemplateRequest, type TemplateSchedule, type TemplateTransformRequest, withinMsFor, WORKFLOW_TEMPLATE_IDS, WORKFLOW_TEMPLATES, type WorkflowTemplateId, type WorkflowTemplateMeta, } from './workflow/templates';
29
+ export { type CatalogClient, type CatalogIdentity, type CatalogRevision, type CatalogPeoplePage, type CatalogPersonRole, type CatalogPersonSummary, type CatalogPrincipalSummary, CatalogProvider, type CatalogProviderProps, type CatalogTransport, type ConnectionInput, type ConnectionUse, catalogQueryKeys, type DeleteReconciliation, type LoadExpectation, type LoadExpectationInput, type ResolvedLoadExpectation, type RowCountBound, type StoredLoadExpectation, type PersonInput, type PersonUpsertResult, type PipelineCapabilities, type ScheduledWorkflow, type TransformInput, type WorkflowRunOptions, type WorkflowScheduleInput, useCatalogClient, } from './context';
28
30
  export { type AccessRoutes, accessRoutes, DEFAULT_ACCESS_BASE_PATH, DEFAULT_PIPELINE_BASE_PATH, DEFAULT_PUBLISH_BASE_PATH, embedRoutes, type PeopleQuery, type PipelineRoutes, pipelineRoutes, } from './routes';
29
31
  export { ConfirmDialog } from './ui/dialog';
30
32
  export { FieldGroup, TextAreaField, TextField } from './ui/field';
31
33
  export { Select, SelectField, type SelectOption } from './ui/select';
32
34
  export { Switch } from './ui/switch';
33
35
  export { Sheet } from './ui/sheet';
34
- export { CodeEditor, type CodeEditorProps } from './ui/code-editor';
36
+ export { CodeEditor, type CodeEditorHandle, type CodeEditorProps, codeEditorRoot, codeEditorText, } from './ui/code-editor';
37
+ export { CATALOG_CODE_LANGUAGES, CATALOG_CODE_THEMES, type CatalogCodeLanguage, type CatalogCodeTheme, TRANSFORM_HIGHLIGHTED_AS, } from './ui/code-languages';
35
38
  export { RichTextField, RichTextView, type RichTextFieldProps, } from './ui/rich-text-field';
36
39
  export { Button, type ButtonProps, type ButtonSize, type ButtonVariant } from './ui/button';
37
40
  export { Tabs, TabsList, TabsPanel, TabsTab } from './ui/tabs';