@dudousxd/nestjs-catalog-react 0.18.0 → 0.19.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 (40) hide show
  1. package/dist/CatalogManager.d.ts +23 -1
  2. package/dist/CatalogManager.js +76 -13
  3. package/dist/ConnectionPanel.js +15 -123
  4. package/dist/LoadedBySection.d.ts +39 -0
  5. package/dist/LoadedBySection.js +143 -0
  6. package/dist/WorkflowCanvas.d.ts +16 -0
  7. package/dist/WorkflowCanvas.js +1026 -78
  8. package/dist/connection-form.d.ts +241 -0
  9. package/dist/connection-form.js +235 -0
  10. package/dist/context.d.ts +78 -4
  11. package/dist/context.js +11 -0
  12. package/dist/index.d.ts +5 -1
  13. package/dist/index.js +23 -0
  14. package/dist/routes.d.ts +30 -0
  15. package/dist/routes.js +2 -0
  16. package/dist/schema-discovery.d.ts +17 -1
  17. package/dist/schema-discovery.js +3 -3
  18. package/dist/source-connection.d.ts +82 -0
  19. package/dist/source-connection.js +176 -0
  20. package/dist/source-fields.d.ts +15 -2
  21. package/dist/source-fields.js +15 -2
  22. package/dist/ui/combobox.d.ts +97 -0
  23. package/dist/ui/combobox.js +80 -0
  24. package/dist/workflow/edges.d.ts +110 -0
  25. package/dist/workflow/edges.js +112 -0
  26. package/dist/workflow/graph.d.ts +63 -2
  27. package/dist/workflow/graph.js +322 -43
  28. package/dist/workflow/index.d.ts +7 -1
  29. package/dist/workflow/index.js +10 -5
  30. package/dist/workflow/lifecycle.d.ts +0 -29
  31. package/dist/workflow/lifecycle.js +2 -35
  32. package/dist/workflow/model.d.ts +28 -3
  33. package/dist/workflow/model.js +12 -2
  34. package/dist/workflow/nodes.d.ts +4 -1
  35. package/dist/workflow/nodes.js +226 -11
  36. package/dist/workflow/templates.js +21 -0
  37. package/dist/workflow/validate.js +11 -0
  38. package/dist/workflow/wiring.d.ts +84 -0
  39. package/dist/workflow/wiring.js +254 -0
  40. package/package.json +8 -8
package/dist/index.js CHANGED
@@ -5,6 +5,12 @@ export { EditableField } from './EditableField';
5
5
  // own type panel out of this package's parts should not have to rebuild the one
6
6
  // section that can say an incremental load of a type is currently refused.
7
7
  export { DELETE_STRATEGIES, LoadExpectationSection, } from './LoadExpectationSection';
8
+ // Mounted on the Model screen too, directly above the expectation section — the
9
+ // two are one question in two halves: who loads this type, and what is checked
10
+ // when they do. `loadersOf` is exported beside the component because it is the
11
+ // whole rule (a graph's SINKS decide, not its stored `targetType`), and a host
12
+ // that renders its own row wants the rule rather than a second reading of it.
13
+ export { LoadedBySection, loadersOf, } from './LoadedBySection';
8
14
  export { cn } from './cn';
9
15
  export { ObjectExplorer } from './ObjectExplorer';
10
16
  export { DashboardBoard } from './DashboardBoard';
@@ -36,6 +42,22 @@ export { CATALOG_EVENT_META, eventMeta, TraceExplorer, useTraceSource, } from '.
36
42
  // `WorkflowCanvas`, on the `/workflow` subpath, and this is the two shared
37
43
  // objects it borrows.
38
44
  export { ConnectionPanel, connectionOptionsFor, describeConnection, } from './ConnectionPanel';
45
+ // What a connection IS, as data: which kinds can be one, what each needs, and
46
+ // the two rules — completeness, and the redaction placeholder — that decide
47
+ // whether a form may send one.
48
+ //
49
+ // Exported because there are two forms now. The console's is here; the source
50
+ // node's inspector on the canvas has its own, behind the `/workflow` subpath,
51
+ // and a host assembling a third should be reading these rather than restating
52
+ // what an S3 connection needs.
53
+ export { CONNECTABLE_KINDS, CONNECTION_KIND_OPTIONS, CONNECTION_KINDS, ConnectionCheckResult, ConnectionKindFields, connectableSpec, connectionConfigFor, connectionDraftFrom, connectionIsIncomplete, redactedCredentialIn, toConnectableKind, } from './connection-form';
54
+ // Creating a connection from wherever a source is being configured.
55
+ //
56
+ // On the root entry and not behind `/workflow`, for the reason
57
+ // `SchemaDiscoveryPanel` is: it imports no React Flow, and it is the other half
58
+ // of the same offer — the sink's panel makes the type, this makes the address. A
59
+ // host assembling its own source inspector should be able to mount either.
60
+ export { SourceConnectionCreator } from './source-connection';
39
61
  export { PipelineConsole, } from './PipelineConsole';
40
62
  // The schema-discovery seam, whole.
41
63
  //
@@ -133,6 +155,7 @@ embedRoutes, pipelineRoutes, } from './routes';
133
155
  export { ConfirmDialog } from './ui/dialog';
134
156
  export { FieldGroup, TextAreaField, TextField } from './ui/field';
135
157
  export { Select, SelectField } from './ui/select';
158
+ export { Combobox, ComboboxField } from './ui/combobox';
136
159
  export { Switch } from './ui/switch';
137
160
  export { Sheet } from './ui/sheet';
138
161
  // `codeEditorRoot` and `codeEditorText` come with it because the editor renders
package/dist/routes.d.ts CHANGED
@@ -96,9 +96,39 @@ export declare const DEFAULT_PUBLISH_BASE_PATH = "/publish";
96
96
  export declare const DEFAULT_ACCESS_BASE_PATH = "/access";
97
97
  export interface PipelineRoutes {
98
98
  capabilities(): string;
99
+ /**
100
+ * What a call node could be pointed at: every workflow the live fleet
101
+ * announces it can execute.
102
+ *
103
+ * Beside `capabilities` and NOT part of it, because the two have opposite
104
+ * lifetimes. Capabilities report what resolved in the server process and
105
+ * cannot change without a redeploy; this is a snapshot of live workers with a
106
+ * resolution of about one heartbeat. A screen caching the second the way it
107
+ * caches the first would show the fleet as it was when the tab opened.
108
+ */
109
+ callableWorkflows(): string;
99
110
  connections(): string;
100
111
  connection(id: string): string;
101
112
  checkConnection(id: string): string;
113
+ /**
114
+ * Reach a connection that has not been saved yet.
115
+ *
116
+ * A sibling of {@link PipelineRoutes.checkConnection} and not the same route
117
+ * with an absent id, because the two ask for different scopes and the
118
+ * difference is the point: checking a SAVED connection reaches an address
119
+ * somebody with `catalog:write` already chose and wrote down, so it asks only
120
+ * `catalog:read`; this one reaches an address supplied in the request, which
121
+ * under `catalog:read` would be a port scanner for anybody who may look at the
122
+ * catalog. It therefore asks `catalog:write`.
123
+ *
124
+ * The server declares its handler BEFORE `connections/:id/check`, because Nest
125
+ * matches in declaration order and `:id` captures the literal "check" happily.
126
+ * Nothing on this side can enforce that, and it is written down here because a
127
+ * console that gets a 404 from this path is most likely talking to a server
128
+ * where the two were reordered — which reads like a missing feature rather
129
+ * than like a routing bug.
130
+ */
131
+ checkUnsavedConnection(): string;
102
132
  /**
103
133
  * Which pipelines read through a connection. Named, so a refusal can say.
104
134
  *
package/dist/routes.js CHANGED
@@ -132,9 +132,11 @@ export function pipelineRoutes(basePath = DEFAULT_PIPELINE_BASE_PATH) {
132
132
  const expectations = pipelineExpectationRoutes(base);
133
133
  return {
134
134
  capabilities: () => `${base}/capabilities`,
135
+ callableWorkflows: () => `${base}/callable-workflows`,
135
136
  connections: () => `${base}/connections`,
136
137
  connection: (id) => `${base}/connections/${encodeURIComponent(id)}`,
137
138
  checkConnection: (id) => `${base}/connections/${encodeURIComponent(id)}/check`,
139
+ checkUnsavedConnection: () => `${base}/connections/check`,
138
140
  connectionWorkflows: (id) => `${base}/connections/${encodeURIComponent(id)}/workflows`,
139
141
  connectors: () => `${base}/connectors`,
140
142
  runs: () => `${base}/runs`,
@@ -190,12 +190,28 @@ export declare function proposalFrom(discovery: ConnectorSchemaDiscovery, choice
190
190
  * speaking; forty records that all happened to hold a string is a sample, and
191
191
  * the forty-first is where somebody finds out.
192
192
  */
193
- export declare function SchemaDiscoveryPanel({ workflowId, nodeId, bridge, disabledReason, onDiscovered, }: {
193
+ export declare function SchemaDiscoveryPanel({ workflowId, nodeId, bridge, disabledReason, onSave, saving, onDiscovered, }: {
194
194
  workflowId: string;
195
195
  nodeId: string;
196
196
  bridge: SchemaDiscoveryBridge;
197
197
  /** Why the button cannot be pressed, said out loud. Absent means it can. */
198
198
  disabledReason?: string;
199
+ /**
200
+ * Do the thing `disabledReason` asks for, from here.
201
+ *
202
+ * Both reasons this panel can be disabled for are "save it first", and until
203
+ * this existed the panel said so while the save control lived in a header the
204
+ * panel is not even in — the inspector is a side sheet over the canvas. A
205
+ * reader was being told to do something with no way to do it where they were
206
+ * standing, and the report that produced was "it's disabled and I can't see
207
+ * anything" rather than "ah, I should save".
208
+ *
209
+ * Optional because a host may mount this panel somewhere with no draft behind
210
+ * it; the sentence alone is still correct, just less useful.
211
+ */
212
+ onSave?: () => void;
213
+ /** Whether that save is in flight, so the button says so rather than lying. */
214
+ saving?: boolean;
199
215
  /**
200
216
  * Told to whoever mounted this, because the answer outlives the panel.
201
217
  *
@@ -1,6 +1,6 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
2
  import { useMutation } from '@tanstack/react-query';
3
- import { CircleCheck, Loader2, ScanSearch, TriangleAlert } from 'lucide-react';
3
+ import { CircleCheck, Loader2, Save, ScanSearch, TriangleAlert } from 'lucide-react';
4
4
  import { useState } from 'react';
5
5
  import { cn } from './cn';
6
6
  import { Button } from './ui/button';
@@ -125,7 +125,7 @@ export function proposalFrom(discovery, choices) {
125
125
  * speaking; forty records that all happened to hold a string is a sample, and
126
126
  * the forty-first is where somebody finds out.
127
127
  */
128
- export function SchemaDiscoveryPanel({ workflowId, nodeId, bridge, disabledReason, onDiscovered, }) {
128
+ export function SchemaDiscoveryPanel({ workflowId, nodeId, bridge, disabledReason, onSave, saving = false, onDiscovered, }) {
129
129
  // Counted rather than timestamped so a second discovery always remounts the
130
130
  // table below, dropping the choices somebody made against a column list that
131
131
  // no longer exists.
@@ -138,7 +138,7 @@ export function SchemaDiscoveryPanel({ workflowId, nodeId, bridge, disabledReaso
138
138
  },
139
139
  });
140
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))] }));
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.' }), disabledReason !== undefined && onSave && (_jsxs(Button, { variant: "secondary", size: "sm", onClick: onSave, disabled: saving, children: [saving ? _jsx(Loader2, { size: 12, className: "animate-spin" }) : _jsx(Save, { size: 12 }), saving ? 'Saving…' : 'Save now'] }))] }), disabledReason !== undefined && onSave && (_jsx("p", { className: cn('mt-1.5 text-[11px]', MUTED), children: "Saving stores the graph as a draft. It does not publish it, and nothing runs because of 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
142
  }
143
143
  function DiscoveredSchema({ discovery, createType, }) {
144
144
  const [choices, setChoices] = useState(() => initialChoices(discovery.columns));
@@ -0,0 +1,82 @@
1
+ import type { CatalogConnection } from '@dudousxd/nestjs-catalog/client';
2
+ import { type ConnectableKind } from './connection-form';
3
+ /**
4
+ * Making the address a source reads through, without leaving the canvas.
5
+ *
6
+ * THE HALF THAT WAS MISSING
7
+ * -------------------------
8
+ * The sink node can already create the thing it needs: the schema-discovery
9
+ * panel turns confirmed columns into an object type, on a draft, without going
10
+ * anywhere. The source node could only ever *choose* an address. With no
11
+ * connection of the right kind, the picker above this said so and stopped —
12
+ * leave the graph, open the Connections tab, make one, come back, find the node
13
+ * again. Everything in between is where a train of thought goes to die.
14
+ *
15
+ * WHY THIS IS NOT AN ORDINARY "QUICK ADD"
16
+ * ---------------------------------------
17
+ * A connection is the credential and the address boundary. Every protection the
18
+ * Connections screen has, it has for a reason somebody learned, and an inline
19
+ * form that dropped any of them would be the place a password gets pasted into
20
+ * what looks like an ordinary field. So, in full:
21
+ *
22
+ * - **The fields are the Connections screen's fields**, from
23
+ * `connection-form.tsx`, per kind and derived from `CONNECTOR_KINDS`. Not a
24
+ * reduced set: a "quick" form that omitted the credential variable would
25
+ * teach people to put the credential in the URL.
26
+ * - **Test before save.** `POST pipeline/connections/check` reaches an address
27
+ * that has not been stored, which exists precisely because the field most
28
+ * likely to be wrong is the one nobody can verify by reading it — and because
29
+ * a connection saved to discover a typo is a row somebody has to remember to
30
+ * delete. A failed check comes back with the password, the query string and
31
+ * the fragment removed and the host and the user kept, which is what makes it
32
+ * worth showing at all.
33
+ * - **The refusal is surfaced, never worked around.** A deployment with
34
+ * `allowInlineCredentials` off refuses a URL carrying a password, and its
35
+ * message names the field to use instead. It is printed here verbatim. This
36
+ * form has no way of its own around it and must not grow one: the flag is a
37
+ * property of the deployment — of which database these rows land in — and a
38
+ * console that quietly re-routed the credential somewhere else would be
39
+ * answering a question nobody asked it.
40
+ * - **The placeholder is never sent as a secret.** See
41
+ * {@link redactedCredentialIn}. This form creates, so there is no stored row
42
+ * behind what it posts and nothing on the server to restore the real
43
+ * credential from — a pasted `REDACTED` would simply become the password.
44
+ *
45
+ * WHAT IT DOES TO THE DRAFT, DECIDED RATHER THAN DEFAULTED
46
+ * --------------------------------------------------------
47
+ * The new connection is selected onto the node immediately. Creating one from a
48
+ * node and then not attaching it is the same trip to another screen, only
49
+ * shorter: the picker directly above would list the connection somebody had just
50
+ * made from this node, still saying the node reads through none of them.
51
+ *
52
+ * That selection is a real edit to the graph, so it marks the draft dirty, and
53
+ * it does so through the inspector's own `push` rather than through any path of
54
+ * its own. Nothing here is special-cased: typing a URL into the very same node
55
+ * dirties it identically. It matters because `dirty` is what disables schema
56
+ * discovery lower down the same panel, and the complaint on record about that
57
+ * message is that it names saving without offering it. So the confirmation below
58
+ * says what happened *and* what it costs, in one breath, rather than leaving
59
+ * somebody to infer it from a control that has gone quiet. What it must not do
60
+ * is pretend the graph is unchanged — a selection that did not dirty the draft
61
+ * is a selection lost on the next reload.
62
+ */
63
+ export declare function SourceConnectionCreator({ kind, canEdit, hasOptions, onCreated, }: {
64
+ /**
65
+ * The source node's own kind, which is what decides the fields.
66
+ *
67
+ * Not asked again on this form. A second kind dropdown could disagree with the
68
+ * node it is standing in, and the connection it produced would then be
69
+ * invisible in the picker above — filtered out for being the wrong kind by a
70
+ * screen that had just offered to make it.
71
+ *
72
+ * {@link ConnectableKind} rather than `ConnectorKind`, and that narrowing is
73
+ * `usesConnection`'s: a file path and pasted records belong to the load, so
74
+ * there is no shared address to make.
75
+ */
76
+ kind: ConnectableKind;
77
+ canEdit: boolean;
78
+ /** Whether the picker above has anything in it. Changes the wording only. */
79
+ hasOptions: boolean;
80
+ /** Attach it to the node. The caller decides what that does to the draft. */
81
+ onCreated: (connection: CatalogConnection) => void;
82
+ }): import("react/jsx-runtime").JSX.Element | null;
@@ -0,0 +1,176 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useMutation, useQueryClient } from '@tanstack/react-query';
3
+ import { Loader2, Plug, Plus } from 'lucide-react';
4
+ import { useState } from 'react';
5
+ import { cn } from './cn';
6
+ import { ConnectionCheckResult, ConnectionKindFields, connectableSpec, connectionConfigFor, connectionDraftFrom, connectionIsIncomplete, redactedCredentialIn, } from './connection-form';
7
+ import { catalogQueryKeys, useCatalogClient } from './context';
8
+ import { Button } from './ui/button';
9
+ import { TextField } from './ui/field';
10
+ import { WORKFLOW_NAME } from './workflow/name';
11
+ const MUTED = 'text-zinc-400 dark:text-zinc-500';
12
+ const RULE = 'border-zinc-200 dark:border-zinc-800';
13
+ const REFUSAL = 'text-[11px] leading-relaxed text-red-600 dark:text-red-400';
14
+ /**
15
+ * Making the address a source reads through, without leaving the canvas.
16
+ *
17
+ * THE HALF THAT WAS MISSING
18
+ * -------------------------
19
+ * The sink node can already create the thing it needs: the schema-discovery
20
+ * panel turns confirmed columns into an object type, on a draft, without going
21
+ * anywhere. The source node could only ever *choose* an address. With no
22
+ * connection of the right kind, the picker above this said so and stopped —
23
+ * leave the graph, open the Connections tab, make one, come back, find the node
24
+ * again. Everything in between is where a train of thought goes to die.
25
+ *
26
+ * WHY THIS IS NOT AN ORDINARY "QUICK ADD"
27
+ * ---------------------------------------
28
+ * A connection is the credential and the address boundary. Every protection the
29
+ * Connections screen has, it has for a reason somebody learned, and an inline
30
+ * form that dropped any of them would be the place a password gets pasted into
31
+ * what looks like an ordinary field. So, in full:
32
+ *
33
+ * - **The fields are the Connections screen's fields**, from
34
+ * `connection-form.tsx`, per kind and derived from `CONNECTOR_KINDS`. Not a
35
+ * reduced set: a "quick" form that omitted the credential variable would
36
+ * teach people to put the credential in the URL.
37
+ * - **Test before save.** `POST pipeline/connections/check` reaches an address
38
+ * that has not been stored, which exists precisely because the field most
39
+ * likely to be wrong is the one nobody can verify by reading it — and because
40
+ * a connection saved to discover a typo is a row somebody has to remember to
41
+ * delete. A failed check comes back with the password, the query string and
42
+ * the fragment removed and the host and the user kept, which is what makes it
43
+ * worth showing at all.
44
+ * - **The refusal is surfaced, never worked around.** A deployment with
45
+ * `allowInlineCredentials` off refuses a URL carrying a password, and its
46
+ * message names the field to use instead. It is printed here verbatim. This
47
+ * form has no way of its own around it and must not grow one: the flag is a
48
+ * property of the deployment — of which database these rows land in — and a
49
+ * console that quietly re-routed the credential somewhere else would be
50
+ * answering a question nobody asked it.
51
+ * - **The placeholder is never sent as a secret.** See
52
+ * {@link redactedCredentialIn}. This form creates, so there is no stored row
53
+ * behind what it posts and nothing on the server to restore the real
54
+ * credential from — a pasted `REDACTED` would simply become the password.
55
+ *
56
+ * WHAT IT DOES TO THE DRAFT, DECIDED RATHER THAN DEFAULTED
57
+ * --------------------------------------------------------
58
+ * The new connection is selected onto the node immediately. Creating one from a
59
+ * node and then not attaching it is the same trip to another screen, only
60
+ * shorter: the picker directly above would list the connection somebody had just
61
+ * made from this node, still saying the node reads through none of them.
62
+ *
63
+ * That selection is a real edit to the graph, so it marks the draft dirty, and
64
+ * it does so through the inspector's own `push` rather than through any path of
65
+ * its own. Nothing here is special-cased: typing a URL into the very same node
66
+ * dirties it identically. It matters because `dirty` is what disables schema
67
+ * discovery lower down the same panel, and the complaint on record about that
68
+ * message is that it names saving without offering it. So the confirmation below
69
+ * says what happened *and* what it costs, in one breath, rather than leaving
70
+ * somebody to infer it from a control that has gone quiet. What it must not do
71
+ * is pretend the graph is unchanged — a selection that did not dirty the draft
72
+ * is a selection lost on the next reload.
73
+ */
74
+ export function SourceConnectionCreator({ kind, canEdit, hasOptions, onCreated, }) {
75
+ const [open, setOpen] = useState(false);
76
+ /**
77
+ * The last one made here, kept after the form closes.
78
+ *
79
+ * The note it carries is the only place the cost of the selection is stated,
80
+ * and the form it was made on is gone by then.
81
+ */
82
+ const [created, setCreated] = useState(null);
83
+ if (!canEdit)
84
+ return null;
85
+ if (open) {
86
+ return (_jsx(InlineConnectionForm, { kind: kind, onCancel: () => setOpen(false), onSaved: (connection) => {
87
+ setCreated(connection);
88
+ setOpen(false);
89
+ onCreated(connection);
90
+ } }));
91
+ }
92
+ return (_jsxs("div", { className: "space-y-2", children: [_jsxs(Button, { variant: "outline", size: "sm", onClick: () => setOpen(true), children: [_jsx(Plus, { size: 12 }), hasOptions ? 'New connection' : `Make the first ${kind} connection`] }), created && (_jsxs("p", { className: cn('text-[11px] leading-relaxed', MUTED), children: [_jsxs("span", { className: "font-medium text-emerald-700 dark:text-emerald-400", children: ["\"", created.name, "\" was created"] }), ' ', "and this node reads through it. That is a change to the graph like any other, so this", ' ', WORKFLOW_NAME.singular, " now has unsaved edits \u2014 save it before asking the source what columns it has, since discovery reads the stored node."] }))] }));
93
+ }
94
+ /**
95
+ * The form itself: a name, the kind's address fields, a test and a save.
96
+ *
97
+ * Its own component so the disclosure above stays a disclosure. It also gives
98
+ * the draft the right lifetime — cancelling unmounts this, so a half-typed
99
+ * password does not sit in memory behind a collapsed button waiting to be
100
+ * reopened and saved by somebody who has forgotten what is in it.
101
+ */
102
+ function InlineConnectionForm({ kind, onCancel, onSaved, }) {
103
+ const client = useCatalogClient();
104
+ const queryClient = useQueryClient();
105
+ const [draft, setDraft] = useState(() => connectionDraftFrom());
106
+ /**
107
+ * A refusal this form made itself, before anything was sent.
108
+ *
109
+ * Separate state from `save.error` because it is not a failed request —
110
+ * nothing was posted. Folding the two together would give a sentence about
111
+ * what somebody pasted the wording of a server that might be worth retrying.
112
+ */
113
+ const [refusal, setRefusal] = useState(null);
114
+ const config = connectionConfigFor(kind, draft);
115
+ const input = () => ({
116
+ // No `id`, and that absence is load-bearing: the server restores a stored
117
+ // credential where a caller posted back the redaction of one, and it can
118
+ // only do that for a connection it can look up. A create has none, so what
119
+ // is typed here is exactly what is reached and exactly what is stored.
120
+ name: draft.name.trim(),
121
+ description: draft.description.trim() || undefined,
122
+ kind,
123
+ config,
124
+ secretEnvVar: draft.secretEnvVar.trim() || undefined,
125
+ });
126
+ const check = useMutation({
127
+ mutationFn: () => client.checkUnsavedConnection(input()),
128
+ });
129
+ const save = useMutation({
130
+ mutationFn: () => client.saveConnection(input()),
131
+ onSuccess: (connection) => {
132
+ // Written into the cache as well as invalidated, for the same reason the
133
+ // canvas does it after creating a transform: the picker above resolves its
134
+ // options out of this list, and selecting an id that is not in it yet
135
+ // shows "Configure the address here" for one render — telling somebody the
136
+ // node uses no connection immediately after they made one.
137
+ queryClient.setQueryData(catalogQueryKeys.connections, (current) => [
138
+ ...(current ?? []),
139
+ connection,
140
+ ]);
141
+ queryClient.invalidateQueries({ queryKey: catalogQueryKeys.connections });
142
+ onSaved(connection);
143
+ },
144
+ });
145
+ const update = (patch) => {
146
+ setDraft({ ...draft, ...patch });
147
+ // Whatever was refused or reached was about the address as it was. Leaving
148
+ // either beside an edited field is how a green tick comes to be read as
149
+ // covering a URL nobody has tested.
150
+ setRefusal(null);
151
+ check.reset();
152
+ };
153
+ const attempt = () => {
154
+ const placeholder = redactedCredentialIn(config);
155
+ if (placeholder) {
156
+ setRefusal(`The ${placeholder} you pasted has "REDACTED" where its password goes. That is what this catalog shows in place of a stored password, not the password itself — saving it would store the word. Paste the address with the real credential, or name the environment variable that holds it.`);
157
+ return;
158
+ }
159
+ setRefusal(null);
160
+ save.mutate();
161
+ };
162
+ return (
163
+ // A fieldset with a legend, and it earns both rather than decorating them.
164
+ // This form stands inside the source inspector, which already has a "Name"
165
+ // field of its own and — while the node carries its own address — a "URL" as
166
+ // well. The labels here are deliberately the Connections screen's labels,
167
+ // because there is one answer to what an HTTP connection needs; what stops
168
+ // the two "URL"s from reading as the same question is that this one sits
169
+ // inside something named, for a screen reader as much as for a reader.
170
+ _jsxs("fieldset", { className: cn('space-y-3 rounded-md border p-3', RULE), children: [_jsxs("legend", { className: cn('px-1 font-mono text-[10px] uppercase tracking-[0.14em]', MUTED), children: ["New ", kind, " connection"] }), _jsxs("p", { className: cn('text-[11px] leading-relaxed', MUTED), children: ["A ", kind, " connection, made here and used by this node. It is an object of its own once it is saved \u2014 other sources can read through it, and moving the address later moves all of them at once, which is the point of naming it."] }), _jsxs("div", { className: "grid gap-3 sm:grid-cols-2", children: [_jsx(TextField, { label: "Name", value: draft.name, onChange: (name) => update({ name }), placeholder: "Fleet warehouse", hint: "What the picker above will call it." }), _jsx(TextField, { label: "Description", value: draft.description, onChange: (description) => update({ description }), placeholder: "What lives behind it (optional)" })] }), _jsx(ConnectionKindFields, { kind: kind, draft: draft, update: update }), _jsxs("div", { className: "flex flex-wrap items-center gap-2", children: [_jsxs(Button, { variant: "outline", size: "sm", onClick: () => check.mutate(),
171
+ // The ADDRESS has to be there; the name does not. Testing is about
172
+ // whether the host answers, and refusing to reach it until a box that
173
+ // has nothing to do with reaching it is filled in is how a check that
174
+ // costs nothing goes unpressed.
175
+ disabled: check.isPending || connectableSpec(kind).isIncomplete(draft), children: [check.isPending ? _jsx(Loader2, { size: 12, className: "animate-spin" }) : _jsx(Plug, { size: 12 }), check.isPending ? 'Reaching…' : 'Test connection'] }), _jsx(Button, { size: "sm", onClick: attempt, disabled: save.isPending || connectionIsIncomplete(kind, draft), children: save.isPending ? 'Saving…' : 'Save and use it' }), _jsx(Button, { variant: "ghost", size: "sm", onClick: onCancel, children: "Cancel" })] }), _jsx("p", { className: cn('text-[11px] leading-relaxed', MUTED), children: "Testing reaches the address and stores nothing. Writing a row proves nothing about whether the host behind it answers, and finding that out afterwards means a load failing on a schedule hours later." }), check.data && _jsx(ConnectionCheckResult, { result: check.data }), check.error && !check.data && (_jsx("p", { className: REFUSAL, children: check.error instanceof Error ? check.error.message : 'The check itself failed.' })), refusal && _jsx("p", { className: REFUSAL, children: refusal }), save.error && !refusal && (_jsx("p", { className: REFUSAL, children: save.error instanceof Error ? save.error.message : 'It could not be saved.' }))] }));
176
+ }
@@ -1,10 +1,23 @@
1
1
  import type { ConnectorKind } from '@dudousxd/nestjs-catalog/client';
2
+ import { type ConnectableKind } from './connection-form';
2
3
  /** A select hands back a string. Narrow it rather than promise it is a kind. */
3
4
  export declare function toConnectorKind(value: string): ConnectorKind;
4
5
  /** The sources that can be asked what changed. The rest always read it all. */
5
6
  export declare function readsIncrementally(kind: ConnectorKind): boolean;
6
- /** Which kinds can borrow an address from a named connection. */
7
- export declare function usesConnection(kind: ConnectorKind): boolean;
7
+ /**
8
+ * Which kinds can borrow an address from a named connection.
9
+ *
10
+ * Asked of `connection-form.tsx` rather than answered here with a list of
11
+ * three, because that module now has to answer the same question to decide
12
+ * whether it can offer to CREATE one — and two lists is how a picker comes to be
13
+ * offered for a kind whose form has no fields, or withheld for one that does.
14
+ *
15
+ * A type predicate, and that is what it is for: the source inspector renders the
16
+ * picker behind this call, and the creator beside it takes a {@link
17
+ * ConnectableKind}. Narrowing here is what makes those two the same decision
18
+ * rather than two that happen to agree today.
19
+ */
20
+ export declare function usesConnection(kind: ConnectorKind): kind is ConnectableKind;
8
21
  export declare const KIND_OPTIONS: {
9
22
  value: string;
10
23
  label: string;
@@ -1,6 +1,7 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { CONNECTOR_KINDS } from '@dudousxd/nestjs-catalog/client';
3
3
  import { cn } from './cn';
4
+ import { CONNECTION_KINDS } from './connection-form';
4
5
  import { FieldGroup, TextAreaField, TextField } from './ui/field';
5
6
  import { SelectField } from './ui/select';
6
7
  import { Switch } from './ui/switch';
@@ -29,9 +30,21 @@ export function toConnectorKind(value) {
29
30
  export function readsIncrementally(kind) {
30
31
  return kind === 'sql' || kind === 's3';
31
32
  }
32
- /** Which kinds can borrow an address from a named connection. */
33
+ /**
34
+ * Which kinds can borrow an address from a named connection.
35
+ *
36
+ * Asked of `connection-form.tsx` rather than answered here with a list of
37
+ * three, because that module now has to answer the same question to decide
38
+ * whether it can offer to CREATE one — and two lists is how a picker comes to be
39
+ * offered for a kind whose form has no fields, or withheld for one that does.
40
+ *
41
+ * A type predicate, and that is what it is for: the source inspector renders the
42
+ * picker behind this call, and the creator beside it takes a {@link
43
+ * ConnectableKind}. Narrowing here is what makes those two the same decision
44
+ * rather than two that happen to agree today.
45
+ */
33
46
  export function usesConnection(kind) {
34
- return kind === 'http' || kind === 'sql' || kind === 's3';
47
+ return CONNECTION_KINDS[kind].connectable;
35
48
  }
36
49
  export const KIND_OPTIONS = [
37
50
  { value: 'http', label: 'HTTP — a JSON endpoint' },
@@ -0,0 +1,97 @@
1
+ import { type ReactNode } from 'react';
2
+ /**
3
+ * A searchable select that is also a text box, vendored in the shadcn style on
4
+ * Base UI's `Autocomplete`.
5
+ *
6
+ * ## Why not {@link Select}
7
+ *
8
+ * `Select` is a closed set: it renders a button, and every choice is one of the
9
+ * rows. That is right for a mode or a kind, where the options are three and
10
+ * written in this repository. It is wrong for a list a *deployment* supplies —
11
+ * a fleet announcing three hundred workflows renders three hundred rows in a
12
+ * popup with no way to narrow them, and a field whose only gesture is "scroll
13
+ * until you see it" is a field people give up on.
14
+ *
15
+ * ## Why `Autocomplete` and not `Combobox`
16
+ *
17
+ * Base UI ships both, and the difference is exactly the one that matters here.
18
+ * `Combobox` has a *selected value* — its input is a query over a closed list
19
+ * and what you end up with is one of the items. `Autocomplete` has no selected
20
+ * value at all: the input's text **is** the value, and the list is a set of
21
+ * suggestions over it. So a name nobody announced can still be typed, which is
22
+ * the property the call node cannot lose — a deployment whose workers are too
23
+ * old announces little or nothing, and a picker that became the only path would
24
+ * make that node unusable there.
25
+ *
26
+ * That is the whole reason this component exists rather than a `searchable`
27
+ * flag on `Select`: the two differ in what they can *express*, not in how they
28
+ * look.
29
+ *
30
+ * ## Picking is not typing, and the caller is told which happened
31
+ *
32
+ * {@link ComboboxProps.onValueChange} fires for keystrokes; {@link
33
+ * ComboboxProps.onSelect} fires for a committed row. Base UI also fills the
34
+ * input on an item press, which arrives as a value change with the reason
35
+ * `item-press`, and that one is dropped on the floor here — otherwise a caller
36
+ * that writes two fields from one row (`name` **and** `version`) would have the
37
+ * second immediately overwritten by the keystroke-shaped event for the first.
38
+ */
39
+ export interface ComboOption {
40
+ /** What {@link ComboboxProps.onSelect} hands back, and the row's identity. */
41
+ value: string;
42
+ /** Shown, and the first thing the query matches against. */
43
+ label: string;
44
+ /** A second line under the label — where a row says what it *is*. */
45
+ hint?: string;
46
+ /**
47
+ * Extra text the query also matches, shown nowhere.
48
+ *
49
+ * A workflow is looked for by its group or by what it does at least as often
50
+ * as by the exact name somebody has half-remembered, and a search that only
51
+ * matched the label would answer "no results" to a perfectly good query.
52
+ */
53
+ keywords?: string;
54
+ /**
55
+ * Offered, greyed, and refused.
56
+ *
57
+ * Never a reason to omit the row: a picker that silently drops what it cannot
58
+ * accept is one you cannot tell apart from a picker that never heard of it.
59
+ * A disabled row owes a reason, which is what {@link hint} is for.
60
+ */
61
+ disabled?: boolean;
62
+ }
63
+ export interface ComboboxProps {
64
+ /** The text in the box, which IS the value. Controlled. */
65
+ value: string;
66
+ /** A keystroke, a paste, a clear — anything the person typed. */
67
+ onValueChange: (value: string) => void;
68
+ /**
69
+ * A row was committed, by pointer or by <kbd>Enter</kbd>.
70
+ *
71
+ * Separate from {@link onValueChange} because a row can mean more than the
72
+ * text it puts in the box: the call node writes a version from it as well as
73
+ * a name, and it must write both in one update.
74
+ */
75
+ onSelect?: (option: ComboOption) => void;
76
+ options: ComboOption[];
77
+ /** Shown when the query matches nothing. Not optional in spirit: an empty popup is a dead end. */
78
+ emptyMessage?: ReactNode;
79
+ placeholder?: string;
80
+ disabled?: boolean;
81
+ /**
82
+ * The accessible name, for a bare combobox with no `<label>` around it.
83
+ * {@link ComboboxField} wraps one in a real label instead, and leaves this off.
84
+ */
85
+ ariaLabel?: string;
86
+ className?: string;
87
+ }
88
+ export declare function Combobox({ value, onValueChange, onSelect, options, emptyMessage, placeholder, disabled, ariaLabel, className, }: ComboboxProps): import("react/jsx-runtime").JSX.Element;
89
+ /**
90
+ * A {@link Combobox} with a label above it, matching `TextField` — and a real
91
+ * `<label>`, because unlike `Select` this renders an `<input>` and a label
92
+ * therefore names it natively.
93
+ */
94
+ export declare function ComboboxField({ label, hint, ...props }: Omit<ComboboxProps, 'ariaLabel'> & {
95
+ label: string;
96
+ hint?: ReactNode;
97
+ }): import("react/jsx-runtime").JSX.Element;