@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.
- package/README.md +39 -13
- package/dist/ConnectionPanel.d.ts +11 -7
- package/dist/ConnectionPanel.js +65 -28
- package/dist/ObjectExplorer.js +424 -48
- package/dist/PipelineConsole.d.ts +23 -126
- package/dist/PipelineConsole.js +39 -551
- package/dist/QueryConsole.js +25 -17
- package/dist/SavedQueryPanel.js +1 -1
- package/dist/TransformEditor.js +12 -3
- package/dist/WorkflowCanvas.js +401 -29
- package/dist/bundler/index.d.ts +20 -0
- package/dist/bundler/index.js +20 -0
- package/dist/bundler/shiki-subset.d.ts +83 -0
- package/dist/bundler/shiki-subset.js +196 -0
- package/dist/context.d.ts +181 -38
- package/dist/context.js +44 -11
- package/dist/diff/RevisionDiff.d.ts +67 -4
- package/dist/diff/RevisionDiff.js +126 -91
- package/dist/index.d.ts +8 -5
- package/dist/index.js +56 -20
- package/dist/routes.d.ts +54 -13
- package/dist/routes.js +5 -4
- package/dist/schema-discovery.d.ts +216 -0
- package/dist/schema-discovery.js +225 -0
- package/dist/source-fields.d.ts +1 -12
- package/dist/source-fields.js +13 -16
- package/dist/ui/code-editor.d.ts +196 -8
- package/dist/ui/code-editor.js +184 -72
- package/dist/ui/code-languages.d.ts +80 -0
- package/dist/ui/code-languages.js +76 -0
- package/dist/ui/code-theme.d.ts +25 -0
- package/dist/ui/code-theme.js +26 -0
- package/dist/ui/dialog.d.ts +13 -1
- package/dist/ui/dialog.js +13 -2
- package/dist/workflow/graph.js +31 -9
- package/dist/workflow/index.d.ts +2 -0
- package/dist/workflow/index.js +7 -0
- package/dist/workflow/lifecycle.d.ts +164 -0
- package/dist/workflow/lifecycle.js +249 -0
- package/dist/workflow/model.d.ts +1 -1
- package/dist/workflow/nodes.js +10 -1
- package/dist/workflow/runs.d.ts +38 -0
- package/dist/workflow/runs.js +101 -0
- package/dist/workflow/shape.d.ts +169 -0
- package/dist/workflow/shape.js +249 -0
- package/dist/workflow/templates.d.ts +623 -0
- package/dist/workflow/templates.js +1092 -0
- package/dist/workflow/validate.d.ts +20 -1
- package/dist/workflow/validate.js +41 -3
- package/package.json +21 -17
- package/dist/diff/line-diff.d.ts +0 -124
- package/dist/diff/line-diff.js +0 -318
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { useMutation } from '@tanstack/react-query';
|
|
3
|
+
import { CircleCheck, Loader2, ScanSearch, TriangleAlert } from 'lucide-react';
|
|
4
|
+
import { useState } from 'react';
|
|
5
|
+
import { cn } from './cn';
|
|
6
|
+
import { Button } from './ui/button';
|
|
7
|
+
const MUTED = 'text-zinc-400 dark:text-zinc-500';
|
|
8
|
+
const RULE = 'border-zinc-200 dark:border-zinc-800';
|
|
9
|
+
/**
|
|
10
|
+
* The discovery response, checked rather than assumed.
|
|
11
|
+
*
|
|
12
|
+
* The client returns `unknown` because this package must not import
|
|
13
|
+
* `@dudousxd/nestjs-catalog-pipeline` — it would drag database drivers behind
|
|
14
|
+
* optional imports into a browser bundle — so the shape above is a mirror of a
|
|
15
|
+
* contract held somewhere else. A mirror can fall behind: a console talking to
|
|
16
|
+
* an older server gets a body with no `columns`, and rendering it would throw
|
|
17
|
+
* somewhere deep in the table with a message about `undefined.map`.
|
|
18
|
+
*
|
|
19
|
+
* Checked at the seam, once, so the failure names itself. Only the fields this
|
|
20
|
+
* screen would crash without — validating every column here would be
|
|
21
|
+
* re-implementing the server's own shape in a place that cannot be kept honest.
|
|
22
|
+
*/
|
|
23
|
+
export function narrowDiscovery(answer) {
|
|
24
|
+
if (!answer || typeof answer !== 'object' || !Array.isArray(Reflect.get(answer, 'columns'))) {
|
|
25
|
+
throw new Error('The server answered the discovery request with something this console does not recognise. ' +
|
|
26
|
+
'It is most likely running a version of @dudousxd/nestjs-catalog-pipeline older than this ' +
|
|
27
|
+
'console expects.');
|
|
28
|
+
}
|
|
29
|
+
return Object.assign(Object.create(null), answer);
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Every type the catalog can hold, in the order a person scans for one.
|
|
33
|
+
*
|
|
34
|
+
* `unknown` is last and named plainly, because choosing it is a decision: the
|
|
35
|
+
* store gives it a TEXT column and stringifies whatever arrives. It is the right
|
|
36
|
+
* answer for a column nobody can classify and the wrong answer for one nobody
|
|
37
|
+
* looked at, which is exactly why discovery never picks it on anyone's behalf.
|
|
38
|
+
*/
|
|
39
|
+
const SCALAR_TYPES = [
|
|
40
|
+
'string',
|
|
41
|
+
'number',
|
|
42
|
+
'boolean',
|
|
43
|
+
'date',
|
|
44
|
+
'uuid',
|
|
45
|
+
'json',
|
|
46
|
+
'unknown',
|
|
47
|
+
];
|
|
48
|
+
/**
|
|
49
|
+
* Where the checkboxes start, and why the untyped ones start off.
|
|
50
|
+
*
|
|
51
|
+
* A column discovery could type is proposed; a column it could not is present,
|
|
52
|
+
* visible, and **excluded** until somebody says what it is. Pre-selecting it
|
|
53
|
+
* with a plausible default is the failure that matters — a wrong type becomes a
|
|
54
|
+
* wrong column in a lake nobody re-checks, and everything downstream reads it
|
|
55
|
+
* as fact rather than as the guess it was.
|
|
56
|
+
*
|
|
57
|
+
* Keyed by position rather than by name on purpose: `SELECT a.id, b.id` gives
|
|
58
|
+
* two columns called `id`, and a map would silently merge their choices.
|
|
59
|
+
*/
|
|
60
|
+
export function initialChoices(columns) {
|
|
61
|
+
return columns.map((column) => ({ include: column.type !== null, type: column.type ?? '' }));
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* The type this would create, and everything standing in the way of creating it.
|
|
65
|
+
*
|
|
66
|
+
* Pure, and separate from the panel, because these are the rules that decide
|
|
67
|
+
* whether a schema somebody approved is one the publish route will accept — and
|
|
68
|
+
* rules that live inside a component are rules only a rendered DOM can check.
|
|
69
|
+
*
|
|
70
|
+
* `columnName` is sent as well as `name`, and they are the same string. The
|
|
71
|
+
* publish service maps `columnName` to `sourceColumn` and `name` to the property
|
|
72
|
+
* itself, and the store reads records by property name; sending them equal is
|
|
73
|
+
* what makes a load match. See the server's `DiscoveredColumn.name`.
|
|
74
|
+
*/
|
|
75
|
+
export function proposalFrom(discovery, choices) {
|
|
76
|
+
const chosen = discovery.columns
|
|
77
|
+
.map((column, index) => ({ column, choice: choices[index] ?? { include: false, type: '' } }))
|
|
78
|
+
.filter((entry) => entry.choice.include);
|
|
79
|
+
const problems = [];
|
|
80
|
+
const untyped = chosen.filter((entry) => entry.choice.type === '');
|
|
81
|
+
if (untyped.length > 0) {
|
|
82
|
+
problems.push(`Choose a type for ${untyped.map((entry) => `"${entry.column.name}"`).join(', ')}, or leave ${untyped.length === 1 ? 'it' : 'them'} out.`);
|
|
83
|
+
}
|
|
84
|
+
const counts = new Map();
|
|
85
|
+
for (const entry of chosen) {
|
|
86
|
+
counts.set(entry.column.name, (counts.get(entry.column.name) ?? 0) + 1);
|
|
87
|
+
}
|
|
88
|
+
const duplicated = [...counts].filter(([, count]) => count > 1).map(([name]) => `"${name}"`);
|
|
89
|
+
if (duplicated.length > 0) {
|
|
90
|
+
problems.push(`${duplicated.join(', ')} appears more than once. A record is an object, so only one of them can survive — leave the others out.`);
|
|
91
|
+
}
|
|
92
|
+
const properties = [];
|
|
93
|
+
for (const entry of chosen) {
|
|
94
|
+
if (entry.choice.type === '')
|
|
95
|
+
continue;
|
|
96
|
+
properties.push({
|
|
97
|
+
name: entry.column.name,
|
|
98
|
+
columnName: entry.column.name,
|
|
99
|
+
type: entry.choice.type,
|
|
100
|
+
// Not stated is published nullable. A column marked NOT NULL that the
|
|
101
|
+
// source sometimes leaves empty is a load that fails at 3am; a nullable
|
|
102
|
+
// column that never holds a null costs nothing at all.
|
|
103
|
+
nullable: entry.column.nullable ?? true,
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
if (properties.length === 0) {
|
|
107
|
+
problems.push('Nothing is selected, and a type with no properties is refused.');
|
|
108
|
+
}
|
|
109
|
+
return { draft: { name: discovery.targetType, properties }, problems };
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* What the source looks like, offered to the person who has to name it.
|
|
113
|
+
*
|
|
114
|
+
* Only for a source node on a SAVED graph, and deliberately not only on a
|
|
115
|
+
* published one. Discovery reads the stored node, so there is nothing to read
|
|
116
|
+
* from a canvas nobody has saved — but requiring a published graph would be
|
|
117
|
+
* circular: a sink cannot commit into a type that does not exist, so the type
|
|
118
|
+
* has to be creatable before the graph is declared finished. `disabledReason`
|
|
119
|
+
* is how the caller states which of those two it is; a panel that simply hid
|
|
120
|
+
* itself would leave somebody hunting for a button that used to be there.
|
|
121
|
+
*
|
|
122
|
+
* The screen's job is to make the difference between what was *reported* and
|
|
123
|
+
* what was *inferred* impossible to miss, because that difference is the whole
|
|
124
|
+
* value of the report. A driver describing a `NUMERIC` column is the database
|
|
125
|
+
* speaking; forty records that all happened to hold a string is a sample, and
|
|
126
|
+
* the forty-first is where somebody finds out.
|
|
127
|
+
*/
|
|
128
|
+
export function SchemaDiscoveryPanel({ workflowId, nodeId, bridge, disabledReason, onDiscovered, }) {
|
|
129
|
+
// Counted rather than timestamped so a second discovery always remounts the
|
|
130
|
+
// table below, dropping the choices somebody made against a column list that
|
|
131
|
+
// no longer exists.
|
|
132
|
+
const [discovered, setDiscovered] = useState();
|
|
133
|
+
const discover = useMutation({
|
|
134
|
+
mutationFn: () => bridge.discover(workflowId, nodeId),
|
|
135
|
+
onSuccess: (value) => {
|
|
136
|
+
setDiscovered((previous) => ({ run: (previous?.run ?? 0) + 1, value }));
|
|
137
|
+
onDiscovered?.(nodeId, value);
|
|
138
|
+
},
|
|
139
|
+
});
|
|
140
|
+
return (_jsxs("div", { className: cn('rounded-md border border-dashed p-3', RULE), children: [_jsxs("div", { className: "flex flex-wrap items-center gap-2", children: [_jsxs(Button, { variant: "outline", size: "sm", onClick: () => discover.mutate(), disabled: discover.isPending || disabledReason !== undefined, children: [discover.isPending ? (_jsx(Loader2, { size: 12, className: "animate-spin" })) : (_jsx(ScanSearch, { size: 12 })), discover.isPending ? 'Reading the source…' : 'Discover schema'] }), _jsx("span", { className: cn('text-[11px]', MUTED), children: disabledReason ??
|
|
141
|
+
'Reads the source and reports its columns. Creates nothing on its own, and works on a draft — the type has to exist before a sink can commit into it.' })] }), discover.error ? (_jsx("p", { className: "mt-2 text-[11px] text-red-600", children: discover.error instanceof Error ? discover.error.message : 'Could not read the source.' })) : null, discovered && (_jsx(DiscoveredSchema, { discovery: discovered.value, createType: bridge.createType }, discovered.run))] }));
|
|
142
|
+
}
|
|
143
|
+
function DiscoveredSchema({ discovery, createType, }) {
|
|
144
|
+
const [choices, setChoices] = useState(() => initialChoices(discovery.columns));
|
|
145
|
+
const { draft, problems } = proposalFrom(discovery, choices);
|
|
146
|
+
const setChoice = (index, next) => setChoices((current) => current.map((choice, position) => (position === index ? { ...choice, ...next } : choice)));
|
|
147
|
+
return (_jsxs("div", { className: "mt-3 space-y-3", children: [_jsx("p", { className: cn('text-[11px]', MUTED), children: discovery.caveat }), discovery.targetType ? (_jsx(DriftReport, { drift: discovery.drift, targetType: discovery.targetType })) : (_jsx("p", { className: cn('text-[11px]', MUTED), children: "This graph has no sink naming an object type yet, so there is nothing to compare these columns against. Draw one and choose a type, and this becomes the way to create it." })), discovery.columns.length === 0 ? (_jsx("p", { className: cn('text-[11px]', MUTED), children: "No columns came back." })) : (_jsxs("table", { className: "w-full text-left text-[11px]", children: [_jsx("thead", { className: cn('font-mono uppercase tracking-[0.14em]', MUTED), children: _jsxs("tr", { children: [_jsx("th", { className: "w-6 pb-1 font-normal", children: _jsx("span", { className: "sr-only", children: "Include" }) }), _jsx("th", { className: "pb-1 font-normal", children: "Column" }), _jsx("th", { className: "pb-1 font-normal", children: "Type" }), _jsx("th", { className: "pb-1 font-normal", children: "Null" }), _jsx("th", { className: "pb-1 font-normal", children: "Source" })] }) }), _jsx("tbody", { children: discovery.columns.map((column, index) => (_jsx(ColumnRow
|
|
148
|
+
// The source may legally return two columns of one name, so the
|
|
149
|
+
// position has to be part of the key: on its own the name would
|
|
150
|
+
// collide, and React would reuse one row's choice for the other.
|
|
151
|
+
, { column: column, choice: choices[index] ?? { include: false, type: '' }, onChange: (next) => setChoice(index, next) }, `${column.name}-${index}`))) })] })), problems.map((problem) => (_jsxs("p", { className: "flex items-start gap-1.5 text-[11px] text-amber-600", children: [_jsx(TriangleAlert, { size: 11, className: "mt-0.5 shrink-0", "aria-hidden": true }), problem] }, problem))), discovery.targetType ? (_jsx(Confirmation, { discovery: discovery, draft: draft, problems: problems, createType: createType })) : null] }));
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* The act that creates the type — the only thing on this screen that writes.
|
|
155
|
+
*
|
|
156
|
+
* Its own component because it has three states and they are not variations on
|
|
157
|
+
* a button: nothing has been created yet, something has, or this console has no
|
|
158
|
+
* way to create anything and has to hand over the request instead.
|
|
159
|
+
*/
|
|
160
|
+
function Confirmation({ discovery, draft, problems, createType, }) {
|
|
161
|
+
const [created, setCreated] = useState(false);
|
|
162
|
+
const create = useMutation({
|
|
163
|
+
mutationFn: () => {
|
|
164
|
+
if (!createType)
|
|
165
|
+
return Promise.reject(new Error('This console cannot create types.'));
|
|
166
|
+
return createType(draft);
|
|
167
|
+
},
|
|
168
|
+
onSuccess: () => setCreated(true),
|
|
169
|
+
});
|
|
170
|
+
if (!createType)
|
|
171
|
+
return _jsx(UnwiredConfirmation, { draft: draft });
|
|
172
|
+
if (created) {
|
|
173
|
+
return (_jsxs("p", { className: "flex items-center gap-1.5 text-[11px] text-emerald-600", children: [_jsx(CircleCheck, { size: 11, "aria-hidden": true }), discovery.targetType, " now exists with ", draft.properties.length, " properties. Running this workflow will load into it."] }));
|
|
174
|
+
}
|
|
175
|
+
return (_jsxs("div", { className: "space-y-1", children: [_jsx(Button, { onClick: () => create.mutate(), disabled: problems.length > 0 || create.isPending, size: "sm", children: create.isPending
|
|
176
|
+
? 'Creating…'
|
|
177
|
+
: discovery.typeExists
|
|
178
|
+
? `Update ${discovery.targetType}`
|
|
179
|
+
: `Create ${discovery.targetType}` }), _jsx("p", { className: cn('text-[11px]', MUTED), children: discovery.typeExists
|
|
180
|
+
? 'Adds and retypes properties. Display names, descriptions and classifications somebody wrote are kept.'
|
|
181
|
+
: 'This is the act that creates the type. Nothing has been created up to here.' }), create.error ? (_jsx("p", { className: "text-[11px] text-red-600", children: create.error instanceof Error ? create.error.message : 'Could not create it.' })) : null] }));
|
|
182
|
+
}
|
|
183
|
+
/** One column, with the two decisions a person can make about it. */
|
|
184
|
+
function ColumnRow({ column, choice, onChange, }) {
|
|
185
|
+
return (_jsxs(_Fragment, { children: [_jsxs("tr", { className: cn('border-t', RULE), children: [_jsx("td", { className: "py-1 align-top", children: _jsx("input", { type: "checkbox", checked: choice.include, "aria-label": `Include ${column.name}`, onChange: (event) => onChange({ include: event.target.checked }) }) }), _jsx("td", { className: "py-1 align-top font-mono", children: column.name }), _jsxs("td", { className: "py-1 align-top", children: [_jsxs("select", { value: choice.type, "aria-label": `Type for ${column.name}`, onChange: (event) => {
|
|
186
|
+
const next = SCALAR_TYPES.find((scalar) => scalar === event.target.value);
|
|
187
|
+
onChange({ type: next ?? '' });
|
|
188
|
+
}, className: cn('rounded-sm border bg-transparent px-1 py-0.5 font-mono text-[11px]', RULE,
|
|
189
|
+
// The popup is the browser's, so its background is not this
|
|
190
|
+
// component's to style — but the options inherit the control's
|
|
191
|
+
// colour, and without an explicit dark background a dark theme
|
|
192
|
+
// renders light-on-light in some engines.
|
|
193
|
+
'text-zinc-900 dark:bg-zinc-900 dark:text-zinc-100', choice.type === '' && 'text-amber-600 dark:text-amber-500'), children: [_jsx("option", { value: "", children: "not typed" }), SCALAR_TYPES.map((scalar) => (_jsx("option", { value: scalar, children: scalar }, scalar)))] }), column.confidence === 'inferred' && (_jsx("span", { className: cn('ml-1.5 font-mono text-[10px]', MUTED), children: "inferred" }))] }), _jsx("td", { className: cn('py-1 align-top font-mono', MUTED), children: column.nullable === null ? 'not stated' : column.nullable ? 'nullable' : 'not null' }), _jsx("td", { className: cn('py-1 align-top font-mono', MUTED), children: column.sourceType })] }), column.note && (_jsxs("tr", { children: [_jsx("td", {}), _jsx("td", { colSpan: 4, className: "pb-1.5 text-[11px] text-amber-600", children: column.note })] }))] }));
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* What the source says now against what the type says now.
|
|
197
|
+
*
|
|
198
|
+
* The part worth having. A first discovery happens once per source; drift
|
|
199
|
+
* happens for as long as the pipeline exists, and every one of these is silent
|
|
200
|
+
* today — an added column is dropped by the store, a removed one loads as null,
|
|
201
|
+
* and a retyped one is coerced into whatever the catalog still believes.
|
|
202
|
+
*/
|
|
203
|
+
function DriftReport({ drift, targetType }) {
|
|
204
|
+
if (!drift) {
|
|
205
|
+
return (_jsxs("p", { className: cn('text-[11px]', MUTED), children: [targetType, " does not exist yet, so there is nothing to compare against."] }));
|
|
206
|
+
}
|
|
207
|
+
const quiet = drift.added.length === 0 && drift.removed.length === 0 && drift.retyped.length === 0;
|
|
208
|
+
if (quiet) {
|
|
209
|
+
return (_jsxs("p", { className: "flex items-center gap-1.5 text-[11px] text-emerald-600", children: [_jsx(CircleCheck, { size: 11, "aria-hidden": true }), "The source still matches ", targetType, "."] }));
|
|
210
|
+
}
|
|
211
|
+
return (_jsxs("div", { className: "space-y-1 rounded-md border border-amber-300 bg-amber-50 p-2 dark:border-amber-900 dark:bg-amber-950/30", children: [_jsxs("p", { className: "font-mono text-[10px] uppercase tracking-[0.14em] text-amber-700 dark:text-amber-400", children: ["Drift since ", targetType, " was written down"] }), drift.added.length > 0 && (_jsxs("p", { className: "text-[11px] text-amber-700 dark:text-amber-300", children: ["New in the source, and dropped by every load until the type has them:", ' ', _jsx("span", { className: "font-mono", children: drift.added.join(', ') })] })), drift.removed.length > 0 && (_jsxs("p", { className: "text-[11px] text-amber-700 dark:text-amber-300", children: ["On the type, absent from the source, so they load as null:", ' ', _jsx("span", { className: "font-mono", children: drift.removed.join(', ') })] })), drift.retyped.map((change) => (_jsxs("p", { className: "text-[11px] text-amber-700 dark:text-amber-300", children: [_jsx("span", { className: "font-mono", children: change.property }), " is ", change.now, " in the source and", ' ', change.was, " here \u2014 every load coerces it, and a value that will not convert becomes null."] }, change.property)))] }));
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* The confirmation, for a console whose host did not wire one.
|
|
215
|
+
*
|
|
216
|
+
* The request is printed rather than the button being greyed out with a
|
|
217
|
+
* shrug. Creating a type is a `PUT` a person can make with a terminal, and a
|
|
218
|
+
* host that deliberately kept type creation out of its console — because the
|
|
219
|
+
* publish route is owned by an application principal, or because schema changes
|
|
220
|
+
* go through review — has a reader here who still needs the body somebody
|
|
221
|
+
* approved on this screen.
|
|
222
|
+
*/
|
|
223
|
+
function UnwiredConfirmation({ draft }) {
|
|
224
|
+
return (_jsxs("div", { className: "space-y-1", children: [_jsx("p", { className: cn('text-[11px]', MUTED), children: "This console cannot create types \u2014 nothing is wired to the publish route. What was confirmed above is this request:" }), _jsx("pre", { className: cn('overflow-x-auto rounded-md border p-2 font-mono text-[10px]', RULE, 'bg-zinc-50 dark:bg-zinc-950'), children: `PUT /publish/${draft.name}/schema\n${JSON.stringify(draft, null, 2)}` })] }));
|
|
225
|
+
}
|
package/dist/source-fields.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ConnectorKind } from '@dudousxd/nestjs-catalog/client';
|
|
2
2
|
/** A select hands back a string. Narrow it rather than promise it is a kind. */
|
|
3
3
|
export declare function toConnectorKind(value: string): ConnectorKind;
|
|
4
4
|
/** The sources that can be asked what changed. The rest always read it all. */
|
|
@@ -68,17 +68,6 @@ export interface SourceConfigOptions {
|
|
|
68
68
|
* stale url on a SQL source, which reads as configuration somebody meant.
|
|
69
69
|
*/
|
|
70
70
|
export declare function sourceConfigFrom(kind: ConnectorKind, draft: SourceDraft, { viaConnection, incremental }: SourceConfigOptions): Record<string, unknown>;
|
|
71
|
-
/**
|
|
72
|
-
* Whether there is enough here to read anything at all.
|
|
73
|
-
*
|
|
74
|
-
* Only the fields without which there is nothing to attempt — a bucket cannot be
|
|
75
|
-
* defaulted the way a prefix can. Everything else is the server's to judge.
|
|
76
|
-
*/
|
|
77
|
-
export declare function sourceIsIncomplete(kind: ConnectorKind, draft: SourceDraft, viaConnection: boolean): boolean;
|
|
78
|
-
export declare function connectionOptions(kind: ConnectorKind, connections: CatalogConnection[]): {
|
|
79
|
-
value: string;
|
|
80
|
-
label: string;
|
|
81
|
-
}[];
|
|
82
71
|
/**
|
|
83
72
|
* The address fields for one kind.
|
|
84
73
|
*
|
package/dist/source-fields.js
CHANGED
|
@@ -162,24 +162,21 @@ export function sourceConfigFrom(kind, draft, { viaConnection, incremental }) {
|
|
|
162
162
|
return s3Config(draft, viaConnection);
|
|
163
163
|
return inlineConfig(draft);
|
|
164
164
|
}
|
|
165
|
-
|
|
166
|
-
*
|
|
165
|
+
/*
|
|
166
|
+
* `sourceIsIncomplete` and `connectionOptions` used to be here, and both went
|
|
167
|
+
* with the connector form that was their only caller.
|
|
168
|
+
*
|
|
169
|
+
* `sourceIsIncomplete` decided whether that form's Save button was pressable.
|
|
170
|
+
* A source node has no such gate and should not grow one: an unconfigured node
|
|
171
|
+
* is the normal state of a node somebody just added, `workflow/validate.ts`
|
|
172
|
+
* separates INCOMPLETE from WRONG for exactly that reason, and a second opinion
|
|
173
|
+
* held in this module would fire while the first is deliberately quiet.
|
|
167
174
|
*
|
|
168
|
-
*
|
|
169
|
-
*
|
|
175
|
+
* `connectionOptions` was the same filter as `connectionOptionsFor` in
|
|
176
|
+
* `ConnectionPanel.tsx` without the address hint. Two spellings of "connections
|
|
177
|
+
* of this kind" is how a rule ends up enforced on one screen; the one that is
|
|
178
|
+
* left is the one that can say which address it is offering.
|
|
170
179
|
*/
|
|
171
|
-
export function sourceIsIncomplete(kind, draft, viaConnection) {
|
|
172
|
-
if (kind === 's3' && !viaConnection)
|
|
173
|
-
return draft.bucket.trim().length === 0;
|
|
174
|
-
if (kind === 'http' && !viaConnection)
|
|
175
|
-
return draft.url.trim().length === 0;
|
|
176
|
-
return false;
|
|
177
|
-
}
|
|
178
|
-
export function connectionOptions(kind, connections) {
|
|
179
|
-
return connections
|
|
180
|
-
.filter((connection) => connection.kind === kind)
|
|
181
|
-
.map((connection) => ({ value: connection.id, label: connection.name }));
|
|
182
|
-
}
|
|
183
180
|
/**
|
|
184
181
|
* The address fields for one kind.
|
|
185
182
|
*
|
package/dist/ui/code-editor.d.ts
CHANGED
|
@@ -1,17 +1,205 @@
|
|
|
1
1
|
import type { KeyboardEvent, Ref } from 'react';
|
|
2
|
+
import type { CatalogCodeLanguage } from './code-languages';
|
|
3
|
+
import { type CodeThemeType } from './code-theme';
|
|
4
|
+
/**
|
|
5
|
+
* A code editor: `@pierre/diffs` in edit mode, wrapped so the rest of this
|
|
6
|
+
* package can hand it a string and get one back.
|
|
7
|
+
*
|
|
8
|
+
* WHAT THIS REPLACED, AND THE BUG THAT ENDED IT
|
|
9
|
+
* ---------------------------------------------
|
|
10
|
+
* A transparent `<textarea>` over a Prism-highlighted `<pre>`, both wearing
|
|
11
|
+
* `whitespace-pre-wrap break-words`. The docblock that used to be here argued
|
|
12
|
+
* that a textarea is the best plain-text input the platform has — caret,
|
|
13
|
+
* selection, undo, IME, accessibility, all free — and that argument was correct
|
|
14
|
+
* and is why it survived so long. What it did not account for is that a
|
|
15
|
+
* SOFT-WRAPPED textarea is not editing the lines you can see. `Home`, `End`,
|
|
16
|
+
* `Shift+End` and the vertical arrows all work on VISUAL rows, so a SQL line
|
|
17
|
+
* that wrapped after `checked_fields-` answered "select to the end of the line"
|
|
18
|
+
* with `checked_fields-`: one character more than the identifier, because the
|
|
19
|
+
* hyphen was the last glyph on that row. The same wrapping is why a thirteen-line
|
|
20
|
+
* query put the caret on a fourteenth line. Neither is a bug in the textarea;
|
|
21
|
+
* both are what soft wrap means when nothing on screen admits it is happening.
|
|
22
|
+
*
|
|
23
|
+
* The two layers were never the problem, which is worth recording because they
|
|
24
|
+
* were the obvious suspect. Measured in Chrome against this exact CSS, the
|
|
25
|
+
* `<pre>` and the `<textarea>` chose IDENTICAL break positions on 3,725 fuzzed
|
|
26
|
+
* bodies across fifteen container widths, and on tabs, CJK, emoji, RTL,
|
|
27
|
+
* combining marks, unbreakable runs, trailing spaces at a wrap point, blank
|
|
28
|
+
* lines and a trailing newline; overlaid, their glyphs coincided to the pixel.
|
|
29
|
+
* Aligning them harder would have fixed nothing.
|
|
30
|
+
*
|
|
31
|
+
* So the fix is {@link codeOptions}'s `overflow: 'scroll'` — real horizontal
|
|
32
|
+
* scrolling, one visual row per line — plus the line numbers a gutter-less box
|
|
33
|
+
* could never draw. Scrolling code well needs a document model, and that is what
|
|
34
|
+
* the dependency buys.
|
|
35
|
+
*
|
|
36
|
+
* THE HALF THAT FIX DID NOT COVER
|
|
37
|
+
* -------------------------------
|
|
38
|
+
* `overflow: 'scroll'` is an option about WRAPPING, and it buys exactly one
|
|
39
|
+
* axis. Inside the shadow root the dependency puts `overflow-x: scroll` on its
|
|
40
|
+
* `[data-code]` element and pairs it with `overflow-y: clip`, then lets that
|
|
41
|
+
* element size to the whole document — a sixty-line body makes it 1230px tall
|
|
42
|
+
* inside a 224px box. Nothing in `@pierre/diffs` scrolls vertically: `File` is
|
|
43
|
+
* the non-virtualised renderer and owns no vertical viewport, the only escape
|
|
44
|
+
* hatch it exposes is the `--diffs-overflow-override` custom property, and that
|
|
45
|
+
* substitutes into the X component alone. (Its `CodeView` is the virtualised
|
|
46
|
+
* scroller, but it is a multi-item viewer rather than a taller `File`.)
|
|
47
|
+
*
|
|
48
|
+
* So the vertical overflow lands on the FIRST ancestor with an opinion, and
|
|
49
|
+
* that was this component's own wrapper, wearing `overflow-hidden`. Measured in
|
|
50
|
+
* Chrome on a 61-line body in an `h-56` box: wrapper `clientHeight` 223,
|
|
51
|
+
* `scrollHeight` 1236, and walking every element from the last line up to
|
|
52
|
+
* `<html>` found not one with a user-scrollable Y axis. A real wheel event
|
|
53
|
+
* dispatched over the box through CDP moved `window.scrollY` from 0 to 270 and
|
|
54
|
+
* left the editor on line 1 — the page scrolled, the code did not, which is the
|
|
55
|
+
* report. `overflow: hidden` is defined as clipping WITHOUT offering a
|
|
56
|
+
* scrolling mechanism, so no wheel, trackpad, scrollbar or `PageDown` could
|
|
57
|
+
* reach line 61; only the browser's own caret-into-view scrolling could, which
|
|
58
|
+
* is why typing to the bottom appeared to work and dragging never did.
|
|
59
|
+
*
|
|
60
|
+
* The wrapper is ours and in the light DOM, so the repair is here rather than
|
|
61
|
+
* past a boundary host CSS cannot cross: `overflow-y-auto` makes it the
|
|
62
|
+
* vertical viewport the dependency declines to be, and `overflow-x-hidden`
|
|
63
|
+
* keeps it from becoming a SECOND horizontal scroller competing with the one
|
|
64
|
+
* `overflow: 'scroll'` created — `overflow-y: auto` beside an `overflow-x:
|
|
65
|
+
* visible` would compute that axis to `auto` too. Verified in Chrome after the
|
|
66
|
+
* change: a wheel down moves the box and leaves the page still, a horizontal
|
|
67
|
+
* wheel still scrolls the long first line, and lines stay unwrapped.
|
|
68
|
+
*
|
|
69
|
+
* One consequence worth knowing rather than discovering: the horizontal
|
|
70
|
+
* scrollbar belongs to `[data-code]`, which is document-height, so it is drawn
|
|
71
|
+
* at the bottom of the DOCUMENT and not at the bottom of the visible box. A
|
|
72
|
+
* horizontal wheel or trackpad swipe works from anywhere in the box; the
|
|
73
|
+
* scrollbar itself is only in view once you are scrolled to the end. Moving it
|
|
74
|
+
* would mean styling inside the shadow root, which nothing out here can do.
|
|
75
|
+
*
|
|
76
|
+
* WHAT CONTENTEDITABLE COSTS
|
|
77
|
+
* --------------------------
|
|
78
|
+
* `@pierre/diffs` edits through `contentEditable`, which the old docblock
|
|
79
|
+
* rejected outright. Measured rather than assumed — see `code-editor.spec.tsx`:
|
|
80
|
+
*
|
|
81
|
+
* - **Undo/redo, IME, selection, clipboard and word motion survive**, but as the
|
|
82
|
+
* editor's code rather than the browser's. Undo is a real edit stack, and
|
|
83
|
+
* {@link CodeEditorHandle.insertAtCursor} joins it — which the textarea's
|
|
84
|
+
* `selectionStart` splice never did, because React rewrote the whole value and
|
|
85
|
+
* the native undo stack lost its boundary.
|
|
86
|
+
* - **Tab indents instead of leaving.** That is correct for a code editor and it
|
|
87
|
+
* is also a keyboard trap, because the editor's `Escape` is bound to "simplify
|
|
88
|
+
* selection" rather than to letting go. {@link CodeEditor} adds the way out —
|
|
89
|
+
* see `onWrapperKeyDown`.
|
|
90
|
+
* - **Screen readers still get a labelled multiline textbox**, which is the part
|
|
91
|
+
* the old docblock feared most and is the part that turned out fine. Read out
|
|
92
|
+
* of Chrome's accessibility tree rather than guessed: the editable element is
|
|
93
|
+
* `role="textbox" aria-multiline="true" aria-label="<label>"`, and its
|
|
94
|
+
* accessible VALUE is the whole document — all six hundred lines of a
|
|
95
|
+
* six-hundred-line one, since nothing here is virtualised. That is why the
|
|
96
|
+
* label is passed as the file's `name`: the editor copies the name onto
|
|
97
|
+
* `aria-label`, and it is the element's only accessible name.
|
|
98
|
+
* - **What is genuinely gone is form-control semantics.** It is a `<div>`. There
|
|
99
|
+
* is no `value` property, no form participation, no `<label>` to associate,
|
|
100
|
+
* and each line is a row of per-token `<span>`s rather than one text node, so
|
|
101
|
+
* assistive line and word navigation runs over a token grid instead of over
|
|
102
|
+
* plain text. None of that is repaired here.
|
|
103
|
+
* - **The editor lives in a shadow root** (`<diffs-container>`), so nothing
|
|
104
|
+
* outside can style it, query it, or reach it with Testing Library. Specs go
|
|
105
|
+
* through {@link codeEditorRoot}.
|
|
106
|
+
* - **It does not render at all without layout** — canvas text metrics, a
|
|
107
|
+
* `ResizeObserver`, a real box. Under jsdom that means polyfills; see
|
|
108
|
+
* `code-editor-test-dom.ts`.
|
|
109
|
+
*/
|
|
110
|
+
/** What a caller can do to a live editor. */
|
|
111
|
+
export interface CodeEditorHandle {
|
|
112
|
+
focus(): void;
|
|
113
|
+
/**
|
|
114
|
+
* Replace the selection with `text`, as one undoable edit.
|
|
115
|
+
*
|
|
116
|
+
* The relations sidebar's click-to-insert. `applyEdits` joins the undo
|
|
117
|
+
* timeline, so an inserted table name comes back out with Ctrl+Z exactly like
|
|
118
|
+
* a typed one.
|
|
119
|
+
*/
|
|
120
|
+
insertAtCursor(text: string): void;
|
|
121
|
+
}
|
|
2
122
|
export interface CodeEditorProps {
|
|
3
123
|
value: string;
|
|
4
124
|
onChange: (next: string) => void;
|
|
5
|
-
/**
|
|
6
|
-
|
|
7
|
-
|
|
125
|
+
/**
|
|
126
|
+
* What to highlight it as — one of the four grammars this package ships.
|
|
127
|
+
*
|
|
128
|
+
* Not `string`, and that is a size decision as much as a typing one. Shiki
|
|
129
|
+
* knows ~240 languages and the bundle carries the ones named in
|
|
130
|
+
* `CATALOG_CODE_LANGUAGES`; a `language` outside that set would render as
|
|
131
|
+
* plain text with nothing on screen to say why. Narrowing the prop to
|
|
132
|
+
* {@link CatalogCodeLanguage} makes it a compile error at the call site
|
|
133
|
+
* instead — see `ui/code-languages.ts` for the rest of that argument.
|
|
134
|
+
*/
|
|
135
|
+
language: CatalogCodeLanguage;
|
|
136
|
+
/**
|
|
137
|
+
* Required, and it is the editable element's accessible name.
|
|
138
|
+
*
|
|
139
|
+
* Passed through as the file's `name`, because that is the string the editor
|
|
140
|
+
* copies onto `aria-label`. An unlabelled input is unusable by name, and the
|
|
141
|
+
* language is given separately, so the name is free to be a human phrase
|
|
142
|
+
* rather than a filename.
|
|
143
|
+
*/
|
|
8
144
|
label: string;
|
|
9
|
-
|
|
10
|
-
|
|
145
|
+
/**
|
|
146
|
+
* Keydown, from the wrapper and in the CAPTURE phase.
|
|
147
|
+
*
|
|
148
|
+
* Two facts make this the only workable shape. The editor's keymap binds a
|
|
149
|
+
* fixed set of built-in commands and "run this query" is not one of them, so a
|
|
150
|
+
* host shortcut has to be caught outside it — and events cross an open shadow
|
|
151
|
+
* boundary retargeted at the host, so the wrapper does see `⌘↵` typed inside
|
|
152
|
+
* the editor. But the editor ALREADY binds `⌘↵`, to "insert a blank line", and
|
|
153
|
+
* listening in the bubble phase would run the query and leave a blank line
|
|
154
|
+
* behind. Capture runs first, so a handler that calls `preventDefault` claims
|
|
155
|
+
* the key outright: {@link CodeEditor} stops propagation for it, and the
|
|
156
|
+
* keystroke never reaches the editor at all.
|
|
157
|
+
*/
|
|
158
|
+
onKeyDown?: (event: KeyboardEvent<HTMLDivElement>) => void;
|
|
159
|
+
handleRef?: Ref<CodeEditorHandle | null>;
|
|
11
160
|
/** Metrics differ by caller — the query box is roomier than a sample pane. */
|
|
12
161
|
className?: string;
|
|
13
|
-
padding?: string;
|
|
14
|
-
fontSize?: string;
|
|
15
162
|
readOnly?: boolean;
|
|
16
163
|
}
|
|
17
|
-
|
|
164
|
+
/**
|
|
165
|
+
* The options every code surface in this package shares.
|
|
166
|
+
*
|
|
167
|
+
* `overflow: 'scroll'` is the fix this file's header describes and must not
|
|
168
|
+
* become `'wrap'` without re-reading it. It is an option about WRAPPING, so what
|
|
169
|
+
* it settles is the horizontal axis and the meaning of `End`; the vertical one
|
|
170
|
+
* is the wrapper's job and is not decided here. Line numbers are the other half and are
|
|
171
|
+
* conspicuously ABSENT from this object: they are on unless `disableLineNumbers`
|
|
172
|
+
* turns them off, so the way to keep them is to not write it. `code-editor.spec`
|
|
173
|
+
* asserts both, because "an option nobody added" is not something a reader can
|
|
174
|
+
* see here.
|
|
175
|
+
*
|
|
176
|
+
* The file header is off because every caller draws its own — the query
|
|
177
|
+
* console's toolbar, the transform editor's "Code" strip — and a second filename
|
|
178
|
+
* bar inside those says nothing new.
|
|
179
|
+
*/
|
|
180
|
+
export declare function codeOptions(themeType: CodeThemeType): {
|
|
181
|
+
readonly overflow: "scroll";
|
|
182
|
+
readonly disableFileHeader: true;
|
|
183
|
+
readonly themeType: CodeThemeType;
|
|
184
|
+
};
|
|
185
|
+
export declare function CodeEditor({ value, onChange, language, label, onKeyDown, handleRef, className, readOnly, }: CodeEditorProps): import("react/jsx-runtime").JSX.Element;
|
|
186
|
+
/**
|
|
187
|
+
* The shadow root a code surface renders into.
|
|
188
|
+
*
|
|
189
|
+
* Exported from the component rather than rewritten in every spec, because the
|
|
190
|
+
* boundary is a property of the dependency and not of any one test: Testing
|
|
191
|
+
* Library's queries stop at the host element, so `getByLabelText` and
|
|
192
|
+
* `getByText` cannot see a single line of code. Everything that asserts on
|
|
193
|
+
* rendered code goes through here, and the day the tag name changes there is one
|
|
194
|
+
* place to fix.
|
|
195
|
+
*/
|
|
196
|
+
export declare function codeEditorRoot(container: ParentNode): ShadowRoot | null;
|
|
197
|
+
/**
|
|
198
|
+
* The code a surface is showing, as text.
|
|
199
|
+
*
|
|
200
|
+
* `[data-content]` rather than the whole `<pre>`, which also holds the line
|
|
201
|
+
* numbers — reading those back would make `'1select 1'` the expected value of a
|
|
202
|
+
* one-line query, and the first person to add a line would not know why the
|
|
203
|
+
* assertion moved.
|
|
204
|
+
*/
|
|
205
|
+
export declare function codeEditorText(container: ParentNode): string;
|