@dudousxd/nestjs-catalog-react 0.17.0 → 0.19.0-preview.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 (54) hide show
  1. package/README.md +39 -13
  2. package/dist/CatalogManager.d.ts +23 -1
  3. package/dist/CatalogManager.js +76 -13
  4. package/dist/ConnectionPanel.d.ts +11 -7
  5. package/dist/ConnectionPanel.js +78 -149
  6. package/dist/LoadedBySection.d.ts +39 -0
  7. package/dist/LoadedBySection.js +143 -0
  8. package/dist/PipelineConsole.d.ts +23 -126
  9. package/dist/PipelineConsole.js +39 -551
  10. package/dist/WorkflowCanvas.d.ts +16 -0
  11. package/dist/WorkflowCanvas.js +1064 -64
  12. package/dist/connection-form.d.ts +241 -0
  13. package/dist/connection-form.js +235 -0
  14. package/dist/context.d.ts +236 -38
  15. package/dist/context.js +46 -11
  16. package/dist/index.d.ts +10 -3
  17. package/dist/index.js +63 -14
  18. package/dist/routes.d.ts +84 -13
  19. package/dist/routes.js +7 -4
  20. package/dist/schema-discovery.d.ts +232 -0
  21. package/dist/schema-discovery.js +225 -0
  22. package/dist/source-connection.d.ts +82 -0
  23. package/dist/source-connection.js +176 -0
  24. package/dist/source-fields.d.ts +16 -14
  25. package/dist/source-fields.js +28 -18
  26. package/dist/ui/code-editor.d.ts +44 -2
  27. package/dist/ui/code-editor.js +10 -2
  28. package/dist/ui/combobox.d.ts +97 -0
  29. package/dist/ui/combobox.js +80 -0
  30. package/dist/ui/dialog.d.ts +13 -1
  31. package/dist/ui/dialog.js +13 -2
  32. package/dist/workflow/edges.d.ts +110 -0
  33. package/dist/workflow/edges.js +112 -0
  34. package/dist/workflow/graph.d.ts +39 -1
  35. package/dist/workflow/graph.js +212 -52
  36. package/dist/workflow/index.d.ts +8 -0
  37. package/dist/workflow/index.js +12 -0
  38. package/dist/workflow/lifecycle.d.ts +135 -0
  39. package/dist/workflow/lifecycle.js +216 -0
  40. package/dist/workflow/model.d.ts +17 -3
  41. package/dist/workflow/model.js +7 -2
  42. package/dist/workflow/nodes.d.ts +4 -1
  43. package/dist/workflow/nodes.js +198 -10
  44. package/dist/workflow/runs.d.ts +38 -0
  45. package/dist/workflow/runs.js +101 -0
  46. package/dist/workflow/shape.d.ts +169 -0
  47. package/dist/workflow/shape.js +249 -0
  48. package/dist/workflow/templates.d.ts +623 -0
  49. package/dist/workflow/templates.js +1102 -0
  50. package/dist/workflow/validate.d.ts +20 -1
  51. package/dist/workflow/validate.js +52 -3
  52. package/dist/workflow/wiring.d.ts +84 -0
  53. package/dist/workflow/wiring.js +254 -0
  54. package/package.json +9 -9
@@ -3,40 +3,29 @@ import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
3
3
  import { CircleCheck, CircleX, KeyRound, Loader2, Pencil, Plug, Plus, Trash2, Waypoints, } from 'lucide-react';
4
4
  import { useState } from 'react';
5
5
  import { cn } from './cn';
6
- import { catalogQueryKeys, useCatalogClient } from './context';
6
+ import { CONNECTION_KIND_OPTIONS, ConnectionCheckResult, ConnectionKindFields, connectionConfigFor, connectionDraftFrom, connectionIsIncomplete, configString as text, toConnectableKind, } from './connection-form';
7
+ import { catalogQueryKeys, useCatalogClient, } from './context';
7
8
  import { ConfirmDialog } from './ui/dialog';
8
- import { FieldGroup, TextField } from './ui/field';
9
+ import { TextField } from './ui/field';
9
10
  import { SelectField } from './ui/select';
10
- import { Switch } from './ui/switch';
11
11
  import { Tooltip } from './ui/tooltip';
12
+ import { nodeName } from './workflow/model';
13
+ import { WORKFLOW_NAME } from './workflow/name';
12
14
  const MUTED = 'text-zinc-400 dark:text-zinc-500';
13
15
  const RULE = 'border-zinc-200 dark:border-zinc-800';
14
16
  const PANEL = 'bg-white dark:bg-zinc-900';
15
- /**
16
- * The kinds worth naming once and reusing.
17
+ /*
18
+ * The kinds, the draft, the per-kind fields and the two rules about what a
19
+ * connection needs all moved to `connection-form.tsx`, and the move is the
20
+ * point rather than tidiness: the source node's inspector creates a connection
21
+ * without leaving the canvas now, so there are two screens asking what an S3
22
+ * connection needs. Two copies would mean the one updated second is quietly the
23
+ * one that is right — which is the argument `source-fields.tsx` already makes
24
+ * about the other half of the same question.
17
25
  *
18
- * Deliberately three of the five a connector can be, and the two that are
19
- * missing are missing for the same reason the checker refuses to probe them: a
20
- * file's path and a set of pasted records belong to the load, not to a shared
21
- * address. A connection there would be a name with no address behind it, and a
22
- * "Test connection" that always passes is worse than no button — it teaches
23
- * people that a green tick means nothing.
26
+ * A plain comment rather than a docblock: there is no declaration left here for
27
+ * one to attach to, and a `/**` would describe the constant below it.
24
28
  */
25
- const CONNECTABLE_KINDS = ['http', 'sql', 's3'];
26
- /** A select hands back a string. Narrow it rather than promise it is a kind. */
27
- function toConnectableKind(value) {
28
- return CONNECTABLE_KINDS.find((kind) => kind === value) ?? 'http';
29
- }
30
- const KIND_OPTIONS = [
31
- { value: 'http', label: 'HTTP — a JSON endpoint' },
32
- { value: 'sql', label: 'SQL — a database' },
33
- { value: 's3', label: 'S3 — a bucket, or anything S3-compatible' },
34
- ];
35
- /** Read a string out of a stored config without believing it is one. */
36
- function text(config, key) {
37
- const value = config[key];
38
- return typeof value === 'string' ? value : '';
39
- }
40
29
  /**
41
30
  * One line saying what a connection actually points at.
42
31
  *
@@ -63,13 +52,38 @@ export function describeConnection(connection) {
63
52
  }
64
53
  return text(config, 'url') || 'no URL configured';
65
54
  }
55
+ /**
56
+ * Which pipelines read through a connection, derived from the graphs on screen.
57
+ *
58
+ * A hint, and the server's `connectionWorkflows` is the authority — it also
59
+ * folds in a source that names a connector in `config.connectorId` and inherits
60
+ * the connection from it, which nothing this console writes produces but an
61
+ * upgraded deployment can still hold. So this is what the card shows and the
62
+ * server's answer is what a refusal prints; the two can only disagree by this
63
+ * one under-reporting, which is why the delete dialog asks rather than deciding.
64
+ */
65
+ function usersOf(workflows, connectionId) {
66
+ const uses = [];
67
+ for (const workflow of workflows) {
68
+ const node = workflow.nodes.find((candidate) => candidate.kind === 'source' && candidate.connectionId === connectionId);
69
+ if (!node)
70
+ continue;
71
+ uses.push({
72
+ id: workflow.id,
73
+ name: workflow.name,
74
+ status: workflow.status,
75
+ through: `"${nodeName(node)}"`,
76
+ });
77
+ }
78
+ return uses;
79
+ }
66
80
  /**
67
81
  * Named, reusable sources — and a button that finds out whether they answer.
68
82
  *
69
83
  * The reason this screen is worth having at all is the test. Before it, the
70
84
  * only way to learn that a host was wrong, a credential missing or a bucket
71
85
  * spelled differently was to run a load and read the failure — which happens on
72
- * a schedule, hours after somebody typed it, and is attributed to a connector
86
+ * a schedule, hours after somebody typed it, and is attributed to the pipeline
73
87
  * rather than to the address it borrowed.
74
88
  */
75
89
  export function ConnectionPanel({ canEdit = true }) {
@@ -81,16 +95,21 @@ export function ConnectionPanel({ canEdit = true }) {
81
95
  queryFn: () => client.listConnections(),
82
96
  });
83
97
  // One request for every card's "used by", rather than one per card. The
84
- // connectors list is loaded by the sibling tab anyway, so this is usually a
85
- // cache hit, and a per-card fetch would put N requests behind a screen whose
86
- // whole job is to be quick to glance at.
87
- const { data: connectors = [] } = useQuery({
88
- queryKey: catalogQueryKeys.connectors,
89
- queryFn: () => client.listConnectors(),
98
+ // pipelines list is loaded by the canvas anyway, so this is usually a cache
99
+ // hit, and a per-card fetch would put N requests behind a screen whose whole
100
+ // job is to be quick to glance at.
101
+ //
102
+ // Workflows and not connectors, because that is what a reader recognises and
103
+ // what a refusal has to name. There is also nothing else left to ask: a
104
+ // connector's `connectionId` describes what a graph's source node already
105
+ // says, and the graph is the thing somebody would go and change.
106
+ const { data: workflows = [] } = useQuery({
107
+ queryKey: catalogQueryKeys.workflows,
108
+ queryFn: () => client.listWorkflows(),
90
109
  });
91
110
  const invalidate = () => {
92
111
  queryClient.invalidateQueries({ queryKey: catalogQueryKeys.connections });
93
- queryClient.invalidateQueries({ queryKey: catalogQueryKeys.connectors });
112
+ queryClient.invalidateQueries({ queryKey: catalogQueryKeys.workflows });
94
113
  };
95
114
  if (editing) {
96
115
  return (_jsx(ConnectionForm, { connection: editing === 'new' ? undefined : editing, onClose: () => setEditing(null), onSaved: () => {
@@ -98,7 +117,7 @@ export function ConnectionPanel({ canEdit = true }) {
98
117
  invalidate();
99
118
  } }));
100
119
  }
101
- return (_jsxs("div", { className: "mt-6 space-y-3", children: [canEdit && (_jsxs("button", { type: "button", onClick: () => setEditing('new'), className: cn('flex items-center gap-1.5 rounded-md border px-3 py-1.5 text-xs', RULE, 'hover:bg-zinc-50 dark:hover:bg-zinc-800'), children: [_jsx(Plus, { size: 12 }), "New connection"] })), isPending && (_jsx("p", { className: cn('rounded-lg border border-dashed px-4 py-12 text-center text-sm', RULE, MUTED), children: "Reading connections\u2026" })), isError && (_jsx("p", { className: "rounded-lg border border-red-200 bg-red-50 px-4 py-8 text-center text-sm text-red-700 dark:border-red-900 dark:bg-red-950/40 dark:text-red-300", children: "Could not read the connections. This is not the same as having none \u2014 nothing here is safe to act on until it loads." })), !isPending && !isError && connections.length === 0 && (_jsx("p", { className: cn('rounded-lg border border-dashed px-4 py-12 text-center text-sm', RULE, MUTED), children: "No connections yet. A connector can still carry its own address \u2014 a connection is worth making when more than one of them shares it." })), connections.map((connection) => (_jsx(ConnectionCard, { connection: connection, users: connectors.filter((c) => c.connectionId === connection.id), canEdit: canEdit, onEdit: () => setEditing(connection), onChanged: invalidate }, connection.id)))] }));
120
+ return (_jsxs("div", { className: "mt-6 space-y-3", children: [canEdit && (_jsxs("button", { type: "button", onClick: () => setEditing('new'), className: cn('flex items-center gap-1.5 rounded-md border px-3 py-1.5 text-xs', RULE, 'hover:bg-zinc-50 dark:hover:bg-zinc-800'), children: [_jsx(Plus, { size: 12 }), "New connection"] })), isPending && (_jsx("p", { className: cn('rounded-lg border border-dashed px-4 py-12 text-center text-sm', RULE, MUTED), children: "Reading connections\u2026" })), isError && (_jsx("p", { className: "rounded-lg border border-red-200 bg-red-50 px-4 py-8 text-center text-sm text-red-700 dark:border-red-900 dark:bg-red-950/40 dark:text-red-300", children: "Could not read the connections. This is not the same as having none \u2014 nothing here is safe to act on until it loads." })), !isPending && !isError && connections.length === 0 && (_jsx("p", { className: cn('rounded-lg border border-dashed px-4 py-12 text-center text-sm', RULE, MUTED), children: "No connections yet. A source node can still carry its own address \u2014 a connection is worth making when more than one of them shares it." })), connections.map((connection) => (_jsx(ConnectionCard, { connection: connection, users: usersOf(workflows, connection.id), canEdit: canEdit, onEdit: () => setEditing(connection), onChanged: invalidate }, connection.id)))] }));
102
121
  }
103
122
  /**
104
123
  * Who this connection is: name, kind, who reads through it, what it addresses.
@@ -107,7 +126,7 @@ export function ConnectionPanel({ canEdit = true }) {
107
126
  * property worth showing, so it is shown rather than described in a doc.
108
127
  */
109
128
  function ConnectionIdentity({ connection, users, }) {
110
- return (_jsxs("div", { className: "min-w-0", children: [_jsxs("div", { className: "flex flex-wrap items-center gap-2", children: [_jsx(Plug, { size: 13, className: MUTED }), _jsx("span", { className: "text-sm font-medium", children: connection.name }), _jsx("span", { className: "rounded-sm bg-zinc-100 px-1.5 py-0.5 font-mono text-[10px] uppercase dark:bg-zinc-800", children: connection.kind }), users.length > 0 && (_jsx(Tooltip, { content: `Read through by ${users.map((c) => c.name).join(', ')}. Moving this address moves all of them at once, which is the point.`, children: _jsxs("span", { className: cn('flex cursor-help items-center gap-1 font-mono text-[10px]', MUTED), children: [_jsx(Waypoints, { size: 10 }), users.length] }) }))] }), _jsx("div", { className: cn('mt-1 font-mono text-[11px]', MUTED), children: describeConnection(connection) }), connection.description && (_jsx("p", { className: cn('mt-1 text-[11px]', MUTED), children: connection.description })), connection.secretEnvVar && (_jsx(Tooltip, { content: "The catalog stores the NAME of this variable, never its value. A leaked catalog database gives away the shape of the integration, not the keys to it.", children: _jsxs("div", { className: cn('mt-1 flex w-fit cursor-help items-center gap-1 font-mono text-[10px]', MUTED), children: [_jsx(KeyRound, { size: 10 }), connection.secretEnvVar] }) }))] }));
129
+ return (_jsxs("div", { className: "min-w-0", children: [_jsxs("div", { className: "flex flex-wrap items-center gap-2", children: [_jsx(Plug, { size: 13, className: MUTED }), _jsx("span", { className: "text-sm font-medium", children: connection.name }), _jsx("span", { className: "rounded-sm bg-zinc-100 px-1.5 py-0.5 font-mono text-[10px] uppercase dark:bg-zinc-800", children: connection.kind }), users.length > 0 && (_jsx(Tooltip, { content: `Read through by ${users.map((use) => use.name).join(', ')}. Moving this address moves all of them at once, which is the point.`, children: _jsxs("span", { className: cn('flex cursor-help items-center gap-1 font-mono text-[10px]', MUTED), children: [_jsx(Waypoints, { size: 10 }), users.length] }) }))] }), _jsx("div", { className: cn('mt-1 font-mono text-[11px]', MUTED), children: describeConnection(connection) }), connection.description && (_jsx("p", { className: cn('mt-1 text-[11px]', MUTED), children: connection.description })), connection.secretEnvVar && (_jsx(Tooltip, { content: "The catalog stores the NAME of this variable, never its value. A leaked catalog database gives away the shape of the integration, not the keys to it.", children: _jsxs("div", { className: cn('mt-1 flex w-fit cursor-help items-center gap-1 font-mono text-[10px]', MUTED), children: [_jsx(KeyRound, { size: 10 }), connection.secretEnvVar] }) }))] }));
111
130
  }
112
131
  /**
113
132
  * What the last check found, from the stored fields.
@@ -121,18 +140,6 @@ function StoredCheckSummary({ connection }) {
121
140
  return null;
122
141
  return (_jsxs("div", { className: cn('mt-3 flex items-center gap-2 border-t pt-3 text-[11px]', RULE), children: [connection.lastCheckOk ? (_jsx(CircleCheck, { size: 12, "aria-hidden": true, className: "text-emerald-600" })) : (_jsx(CircleX, { size: 12, "aria-hidden": true, className: "text-red-600" })), _jsx("span", { className: "sr-only", children: connection.lastCheckOk ? 'Reachable: ' : 'Unreachable: ' }), _jsx("span", { className: MUTED, children: connection.lastCheckOk ? 'Reached' : (connection.lastCheckError ?? 'Could not reach it') }), _jsx("span", { className: cn('ml-auto font-mono text-[10px]', MUTED), children: new Date(connection.lastCheckedAt).toLocaleString() })] }));
123
142
  }
124
- /**
125
- * What a check that just ran found, in the checker's own words.
126
- *
127
- * A server version, a bucket and whether anything is under the prefix, an HTTP
128
- * status. That sentence is the whole product of the button; "OK" would prove
129
- * only that something is listening on a port.
130
- */
131
- function LiveCheckResult({ result }) {
132
- return (_jsx("div", { className: cn('mt-3 rounded-md border px-3 py-2 text-[11px]', result.ok
133
- ? 'border-emerald-200 bg-emerald-50 text-emerald-800 dark:border-emerald-900 dark:bg-emerald-950/40 dark:text-emerald-300'
134
- : 'border-red-200 bg-red-50 text-red-700 dark:border-red-900 dark:bg-red-950/40 dark:text-red-300'), children: _jsxs("div", { className: "flex items-start gap-2", children: [result.ok ? (_jsx(CircleCheck, { size: 13, "aria-hidden": true, className: "mt-px shrink-0" })) : (_jsx(CircleX, { size: 13, "aria-hidden": true, className: "mt-px shrink-0" })), _jsxs("div", { className: "min-w-0", children: [_jsx("div", { className: "font-medium", children: result.ok ? 'Reached it.' : 'Could not reach it.' }), _jsx("div", { className: "mt-0.5 font-mono leading-relaxed", children: result.detail }), result.error && (_jsx("div", { className: "mt-1 font-mono leading-relaxed opacity-80", children: result.error })), _jsxs("div", { className: "mt-1 font-mono text-[10px] opacity-70", children: [result.elapsedMs, " ms"] })] })] }) }));
135
- }
136
143
  /**
137
144
  * Why a delete would be refused, said before it is attempted.
138
145
  *
@@ -142,7 +149,7 @@ function LiveCheckResult({ result }) {
142
149
  */
143
150
  function deleteRefusalMessage(blockedBy, error) {
144
151
  if (blockedBy && blockedBy.length > 0) {
145
- return (_jsxs(_Fragment, { children: ["Refused: still read through by ", blockedBy.map((c) => c.name).join(', '), ". Point", ' ', blockedBy.length === 1 ? 'it' : 'them', " elsewhere first."] }));
152
+ return (_jsxs(_Fragment, { children: ["Refused: still read through by", ' ', blockedBy.map((use) => `${use.name} (${use.through})`).join(', '), ". Point", ' ', blockedBy.length === 1 ? 'it' : 'them', " elsewhere first."] }));
146
153
  }
147
154
  if (error && !blockedBy) {
148
155
  return error instanceof Error ? error.message : 'Could not delete it.';
@@ -157,15 +164,15 @@ function deleteRefusalMessage(blockedBy, error) {
157
164
  */
158
165
  function ConnectionCardActions({ connection, users, canEdit, testing, onTest, onEdit, onAskDelete, }) {
159
166
  return (_jsxs("div", { className: "flex shrink-0 items-center gap-1", children: [_jsxs("button", { type: "button", onClick: onTest, disabled: testing, className: cn('flex items-center gap-1.5 rounded-md border px-3 py-1.5 text-xs disabled:opacity-40', RULE, 'hover:bg-zinc-50 dark:hover:bg-zinc-800'), children: [testing ? _jsx(Loader2, { size: 12, className: "animate-spin" }) : _jsx(Plug, { size: 12 }), testing ? 'Reaching…' : 'Test connection'] }), canEdit && (_jsxs(_Fragment, { children: [_jsx(Tooltip, { content: `Edit ${connection.name}`, children: _jsx("button", { type: "button", onClick: onEdit, "aria-label": `Edit ${connection.name}`, className: cn('rounded-sm p-1.5 hover:text-sky-600', MUTED), children: _jsx(Pencil, { size: 12 }) }) }), _jsx(Tooltip, { content: users.length > 0
160
- ? `${users.length} connector${users.length === 1 ? '' : 's'} read through this. Deleting it is refused while that is true.`
167
+ ? `${users.length} ${users.length === 1 ? WORKFLOW_NAME.singular : WORKFLOW_NAME.plural} read through this. Deleting it is refused while that is true.`
161
168
  : `Delete ${connection.name}`, children: _jsx("button", { type: "button", onClick: onAskDelete, "aria-label": `Delete ${connection.name}`, className: cn('rounded-sm p-1.5 hover:text-red-600', MUTED), children: _jsx(Trash2, { size: 12 }) }) })] }))] }));
162
169
  }
163
170
  /** What deleting would actually cost, named readers and all, before it is tried. */
164
171
  function deleteConsequence(users) {
165
172
  if (users.length === 0) {
166
- return 'Nothing reads through it. The connectors that used to are unaffected; only this address and the name of its credential variable go.';
173
+ return 'Nothing reads through it. Anything that used to is unaffected; only this address and the name of its credential variable go.';
167
174
  }
168
- return (_jsxs(_Fragment, { children: [users.length, " connector", users.length === 1 ? '' : 's', " read through this connection \u2014", ' ', users.map((c) => c.name).join(', '), ". Deleting it would leave", ' ', users.length === 1 ? 'it' : 'them', " without an address, and that is discovered on the next scheduled run rather than now. The server refuses while this is true."] }));
175
+ return (_jsxs(_Fragment, { children: [users.length, " ", users.length === 1 ? WORKFLOW_NAME.singular : WORKFLOW_NAME.plural, " read through this connection \u2014 ", users.map((use) => use.name).join(', '), ". Deleting it would leave", ' ', users.length === 1 ? 'it' : 'them', " without an address, and that is discovered on the next scheduled run rather than now. The server refuses while this is true."] }));
169
176
  }
170
177
  function ConnectionCard({ connection, users, canEdit, onEdit, onChanged, }) {
171
178
  const client = useCatalogClient();
@@ -182,11 +189,12 @@ function ConnectionCard({ connection, users, canEdit, onEdit, onChanged, }) {
182
189
  mutationFn: async () => {
183
190
  const result = await client.deleteConnection(connection.id);
184
191
  if (!result.deleted) {
185
- // The store refuses while connectors still read through it. Asking who
192
+ // The store refuses while anything still reads through it. Asking who
186
193
  // they are is the difference between "it would not delete" and a
187
- // sentence somebody can act on — and it is the server's answer, not the
188
- // list this page happened to load a minute ago.
189
- setBlockedBy(await client.connectionConnectors(connection.id));
194
+ // sentence somebody can act on — and it is the server's answer, which
195
+ // sees a source reaching this connection through an inherited connector
196
+ // as well as one naming it outright. The card's own count does not.
197
+ setBlockedBy(await client.connectionWorkflows(connection.id));
190
198
  throw new Error('Still in use.');
191
199
  }
192
200
  return result;
@@ -201,108 +209,25 @@ function ConnectionCard({ connection, users, canEdit, onEdit, onChanged, }) {
201
209
  setBlockedBy(null);
202
210
  remove.reset();
203
211
  setConfirming(true);
204
- } })] }), !result && _jsx(StoredCheckSummary, { connection: connection }), result && _jsx(LiveCheckResult, { result: result }), check.error && !result && (_jsx("p", { className: "mt-3 text-[11px] text-red-600", children: check.error instanceof Error ? check.error.message : 'The check itself failed.' })), _jsx(ConfirmDialog, { open: confirming, onOpenChange: (open) => {
212
+ } })] }), !result && _jsx(StoredCheckSummary, { connection: connection }), result && _jsx(ConnectionCheckResult, { result: result }), check.error && !result && (_jsx("p", { className: "mt-3 text-[11px] text-red-600", children: check.error instanceof Error ? check.error.message : 'The check itself failed.' })), _jsx(ConfirmDialog, { open: confirming, onOpenChange: (open) => {
205
213
  setConfirming(open);
206
214
  if (!open)
207
215
  setBlockedBy(null);
208
216
  }, title: `Delete ${connection.name}?`, description: deleteConsequence(users), confirmLabel: remove.isPending ? 'Deleting…' : 'Delete', pending: remove.isPending, onConfirm: () => remove.mutate(), error: deleteRefusalMessage(blockedBy, remove.error) })] }));
209
217
  }
210
- /**
211
- * Only the config fields the chosen kind actually reads.
212
- *
213
- * Carrying the rest would leave a stale bucket on an HTTP connection, which
214
- * reads as configuration somebody meant rather than as a leftover from a
215
- * dropdown they changed.
216
- */
217
- function connectionConfigFor(kind, draft) {
218
- if (kind === 's3') {
219
- return {
220
- bucket: draft.bucket,
221
- ...(draft.endpoint ? { endpoint: draft.endpoint } : {}),
222
- ...(draft.region ? { region: draft.region } : {}),
223
- ...(draft.forcePathStyle ? { forcePathStyle: true } : {}),
224
- };
225
- }
226
- return draft.url ? { url: draft.url } : {};
227
- }
228
- /**
229
- * Whether there is not yet enough here to save.
230
- *
231
- * A SQL connection needs one of its two addresses and neither is more correct:
232
- * the variable is the right answer in a deployment, the inline URL is the one
233
- * that gets somebody running locally in a minute.
234
- */
235
- function connectionIsIncomplete(kind, draft) {
236
- if (draft.name.trim().length === 0)
237
- return true;
238
- if (kind === 's3')
239
- return draft.bucket.trim().length === 0;
240
- if (kind === 'http')
241
- return draft.url.trim().length === 0;
242
- return draft.url.trim().length === 0 && draft.secretEnvVar.trim().length === 0;
243
- }
244
- /** A base URL, and the token sent against it. */
245
- function HttpFields({ draft, update }) {
246
- return (_jsxs(_Fragment, { children: [_jsx(TextField, { label: "URL", value: draft.url, onChange: (url) => update({ url }), placeholder: "https://api.example.mil/v1", hint: "The base the connectors reading through this will hang their paths off." }), _jsx(TextField, { label: "Credential env var", value: draft.secretEnvVar, onChange: (secretEnvVar) => update({ secretEnvVar }), placeholder: "Optional \u2014 sent as a bearer token" })] }));
247
- }
248
- /**
249
- * The connection string, and nothing beside it.
250
- *
251
- * This was two fields — an inline URL and the name of an environment variable
252
- * holding one — presented side by side with a paragraph explaining when each
253
- * applied. Two doors for one decision, and only one of them worked for a
254
- * database with a password, which is every database anybody connects to. The
255
- * question it produced was "what is this second field", which is the form
256
- * asking the reader to understand its implementation.
257
- *
258
- * One field now. Whether the URL may REST in the catalog's own table is the
259
- * store's decision (`allowInlineCredentials`) and not something to ask on a
260
- * form — and it is a decision about the deployment, not about this connection.
261
- * The server refuses and says why if the answer is no, which is a better place
262
- * to learn it than a hint nobody reads until afterwards.
263
- *
264
- * `secretEnvVar` still exists on the model and is still what a hardened
265
- * deployment should use; it is not on this screen. A host that wants it back
266
- * has the field on the record.
267
- */
268
- function SqlFields({ draft, update }) {
269
- return (_jsx(FieldGroup, { title: "Address", hint: "The connection string, as your database gives it to you. It is served back redacted, so the password never travels in a response \u2014 but it does rest in this catalog's own table, and a deployment can refuse that.", children: _jsx(TextField, { label: "Connection URL", value: draft.url, onChange: (url) => update({ url }), placeholder: "mysql://user:pass@host:3306/database" }) }));
270
- }
271
- /** A bucket, plus everything needed to address a non-AWS one. */
272
- function S3Fields({ draft, update }) {
273
- return (_jsxs(FieldGroup, { title: "Bucket", children: [_jsxs("div", { className: "grid gap-3 sm:grid-cols-2", children: [_jsx(TextField, { label: "Bucket", value: draft.bucket, onChange: (bucket) => update({ bucket }), placeholder: "fleet-drops" }), _jsx(TextField, { label: "Region", value: draft.region, onChange: (region) => update({ region }), placeholder: "Blank uses the environment's" }), _jsx(TextField, { label: "Endpoint", value: draft.endpoint, onChange: (endpoint) => update({ endpoint }), placeholder: "MinIO, e.g. http://localhost:9000" }), _jsx(TextField, { label: "Env var holding accessKeyId:secretAccessKey", value: draft.secretEnvVar, onChange: (secretEnvVar) => update({ secretEnvVar }), placeholder: "Optional", hint: "Leave blank anywhere the pod has its own role \u2014 those credentials rotate, and a static pair named here would not." })] }), _jsx(Switch, { checked: draft.forcePathStyle, onCheckedChange: (forcePathStyle) => update({ forcePathStyle }), label: "Path-style addressing", hint: "MinIO needs it; AWS does not." })] }));
274
- }
275
- /** The address fields for whichever kind is selected, and only those. */
276
- function ConnectionKindFields({ kind, draft, update, }) {
277
- if (kind === 'http')
278
- return _jsx(HttpFields, { draft: draft, update: update });
279
- if (kind === 'sql')
280
- return _jsx(SqlFields, { draft: draft, update: update });
281
- return _jsx(S3Fields, { draft: draft, update: update });
282
- }
283
218
  /**
284
219
  * Create or edit one.
285
220
  *
286
221
  * The form carries the address and the credential variable and nothing about
287
222
  * any particular load — no query, no prefix, no path. That split is the whole
288
- * point of the concept: five connectors reading one database used to hold five
223
+ * point of the concept: five pipelines reading one database used to hold five
289
224
  * copies of its URL, and moving the database meant editing five rows nobody
290
225
  * could find.
291
226
  */
292
227
  function ConnectionForm({ connection, onClose, onSaved, }) {
293
228
  const client = useCatalogClient();
294
- const config = connection?.config ?? {};
295
229
  const [kind, setKind] = useState(toConnectableKind(connection?.kind ?? 'http'));
296
- const [draft, setDraft] = useState({
297
- name: connection?.name ?? '',
298
- description: connection?.description ?? '',
299
- url: text(config, 'url'),
300
- bucket: text(config, 'bucket'),
301
- endpoint: text(config, 'endpoint'),
302
- region: text(config, 'region'),
303
- forcePathStyle: config.forcePathStyle === true,
304
- secretEnvVar: connection?.secretEnvVar ?? '',
305
- });
230
+ const [draft, setDraft] = useState(() => connectionDraftFrom(connection));
306
231
  const update = (patch) => setDraft({ ...draft, ...patch });
307
232
  const save = useMutation({
308
233
  mutationFn: () => {
@@ -322,16 +247,20 @@ function ConnectionForm({ connection, onClose, onSaved, }) {
322
247
  return (_jsxs("form", { className: cn('mt-6 space-y-4 rounded-lg border p-4', RULE, PANEL), onSubmit: (event) => {
323
248
  event.preventDefault();
324
249
  save.mutate();
325
- }, children: [_jsxs("div", { className: "grid gap-3 sm:grid-cols-3", children: [_jsx(TextField, { label: "Name", value: draft.name, onChange: (name) => update({ name }), placeholder: "Fleet warehouse" }), _jsx(TextField, { label: "Description", value: draft.description, onChange: (description) => update({ description }), placeholder: "What lives behind it (optional)" }), _jsx(SelectField, { label: "Kind", ariaLabel: "Connection kind", value: kind, onValueChange: (value) => setKind(toConnectableKind(value)), options: KIND_OPTIONS })] }), _jsx(ConnectionKindFields, { kind: kind, draft: draft, update: update }), _jsxs("div", { className: "flex items-center gap-2", children: [_jsx("button", { type: "submit", disabled: save.isPending || incomplete, className: "rounded-md bg-zinc-950 px-3 py-1.5 text-xs text-zinc-50 disabled:opacity-40 dark:bg-zinc-100 dark:text-zinc-950", children: save.isPending ? 'Saving…' : connection ? 'Save changes' : 'Save connection' }), _jsx("button", { type: "button", onClick: onClose, className: cn('rounded-md px-3 py-1.5 text-xs', MUTED), children: "Cancel" }), _jsx("span", { className: cn('text-[11px]', MUTED), children: "Saving does not reach it. Test the connection from its card." })] }), save.error && (_jsx("p", { className: "text-[11px] text-red-600", children: save.error instanceof Error ? save.error.message : 'Could not save.' }))] }));
250
+ }, children: [_jsxs("div", { className: "grid gap-3 sm:grid-cols-3", children: [_jsx(TextField, { label: "Name", value: draft.name, onChange: (name) => update({ name }), placeholder: "Fleet warehouse" }), _jsx(TextField, { label: "Description", value: draft.description, onChange: (description) => update({ description }), placeholder: "What lives behind it (optional)" }), _jsx(SelectField, { label: "Kind", ariaLabel: "Connection kind", value: kind, onValueChange: (value) => setKind(toConnectableKind(value)), options: CONNECTION_KIND_OPTIONS })] }), _jsx(ConnectionKindFields, { kind: kind, draft: draft, update: update }), _jsxs("div", { className: "flex items-center gap-2", children: [_jsx("button", { type: "submit", disabled: save.isPending || incomplete, className: "rounded-md bg-zinc-950 px-3 py-1.5 text-xs text-zinc-50 disabled:opacity-40 dark:bg-zinc-100 dark:text-zinc-950", children: save.isPending ? 'Saving…' : connection ? 'Save changes' : 'Save connection' }), _jsx("button", { type: "button", onClick: onClose, className: cn('rounded-md px-3 py-1.5 text-xs', MUTED), children: "Cancel" }), _jsx("span", { className: cn('text-[11px]', MUTED), children: "Saving does not reach it. Test the connection from its card." })] }), save.error && (_jsx("p", { className: "text-[11px] text-red-600", children: save.error instanceof Error ? save.error.message : 'Could not save.' }))] }));
326
251
  }
327
252
  /**
328
- * The options a connector form offers for "read through".
253
+ * The options a source node offers for "read through".
254
+ *
255
+ * Exported because the canvas's source inspector lives in another file and this
256
+ * list has one rule that must not be duplicated: only connections of the same
257
+ * kind. A source reading S3 through a database connection is not a
258
+ * configuration anybody meant, and it would fail at run time with an error about
259
+ * a missing bucket rather than about the mistake.
329
260
  *
330
- * Exported because the connector form lives in another file and this list has
331
- * one rule that must not be duplicated: only connections of the same kind. A
332
- * connector reading S3 through a database connection is not a configuration
333
- * anybody meant, and it would fail at run time with an error about a missing
334
- * bucket rather than about the mistake.
261
+ * The hint is `describeConnection`, which is why this is here and not beside the
262
+ * other source fields: the address is the thing that distinguishes two
263
+ * connections with similar names, and it is the connection that knows it.
335
264
  */
336
265
  export function connectionOptionsFor(kind, connections) {
337
266
  return connections
@@ -0,0 +1,39 @@
1
+ import { type CatalogWorkflow } from './workflow/model';
2
+ export interface LoadedBySectionProps {
3
+ typeName: string;
4
+ /** What a person calls the type. The sentences here are about the type. */
5
+ displayName: string;
6
+ /**
7
+ * Where a graph lives, if the host mounts a screen for one. Receives the
8
+ * workflow's id. Omit and the rows stay rows.
9
+ */
10
+ workflowHref?: (workflowId: string) => string;
11
+ }
12
+ /**
13
+ * One graph that commits this type, with what it would take for it to run.
14
+ *
15
+ * Derived rather than stored, and computed here rather than asked of the server:
16
+ * the workflow list is already a query this console makes, and a per-type route
17
+ * would be a second answer to a question the sinks already answer.
18
+ */
19
+ interface Loader {
20
+ id: string;
21
+ name: string;
22
+ /** What stops it running, or nothing at all when the answer is "it runs". */
23
+ standing: string;
24
+ /** Whether `standing` is the reason it does NOT currently load anything. */
25
+ idle: boolean;
26
+ /** The other types this same graph commits. Empty when it commits only this one. */
27
+ alsoCommits: string[];
28
+ }
29
+ /**
30
+ * Every graph whose sinks commit this type.
31
+ *
32
+ * A whitespace-only `targetType` on a sink is not a match, which
33
+ * `producedTypes` already handles by dropping it — a half-configured sink names
34
+ * nothing, and treating a blank as a match would attach every unfinished graph
35
+ * in the deployment to whichever type happened to sort first.
36
+ */
37
+ export declare function loadersOf(workflows: CatalogWorkflow[], typeName: string): Loader[];
38
+ export declare function LoadedBySection({ typeName, displayName, workflowHref }: LoadedBySectionProps): import("react/jsx-runtime").JSX.Element;
39
+ export {};
@@ -0,0 +1,143 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useQuery } from '@tanstack/react-query';
3
+ import { ArrowUpRight, CalendarClock, PauseCircle } from 'lucide-react';
4
+ import { useMemo } from 'react';
5
+ import { cn } from './cn';
6
+ import { catalogQueryKeys, useCatalogClient } from './context';
7
+ import { producedTypes } from './workflow/model';
8
+ import { WORKFLOW_NAME } from './workflow/name';
9
+ /**
10
+ * What loads this type — the answer the model screen could not give.
11
+ *
12
+ * A sink node knows exactly which type it commits, and until this section
13
+ * existed that knowledge only ever pointed one way: you could stand on a graph
14
+ * and read off the type, and standing on the type there was nothing at all. The
15
+ * question a deployment actually asks is the second one — *there is an `af_fleet`
16
+ * workflow, how is it tied to this type* — and it was answerable only by opening
17
+ * every graph in turn.
18
+ *
19
+ * ## Why the list may be empty, plural, and still incomplete
20
+ *
21
+ * These three are not edge cases to be tidied away; they are what the answer is,
22
+ * and the section says all three out loud rather than implying a single owner.
23
+ *
24
+ * - **Plural.** Several graphs may commit one type, and one graph may commit
25
+ * several — a sink is what commits, and a graph may hold more than one. So the
26
+ * membership test is `producedTypes(nodes)` over the sinks rather than
27
+ * {@link CatalogWorkflow.targetType}, which is one stored string and can only
28
+ * ever name one of them.
29
+ * - **Empty.** A type with no graph behind it is an ordinary state, not a
30
+ * fault: it may be loaded by an application, or not loaded at all yet.
31
+ * - **Incomplete, always.** An application holding a `catalog:write` key can
32
+ * `POST` straight to the publish API, and no workflow will ever explain that
33
+ * load. So the note below is rendered in *both* states — the empty one and the
34
+ * populated one — because a list of two that quietly omits a third writer is
35
+ * more misleading than a list of none.
36
+ *
37
+ * ## What each row does and does not claim
38
+ *
39
+ * Naming a type at a sink is not the same as loading it. A draft is not
40
+ * scheduled, a disabled graph does not run, and a published graph with no cron
41
+ * runs only when somebody presses Run. Each row therefore says which of those it
42
+ * is, because "loaded by af_fleet" beside a graph nobody has published is the
43
+ * kind of half-truth that gets read off a screen and believed.
44
+ *
45
+ * ## Where the link goes, and why the host decides
46
+ *
47
+ * `workflowHref` is the host's, in the shape `explorerHref` already established
48
+ * on this screen: this package does not know where — or whether — a host mounts
49
+ * a canvas. Omit it and the rows render as plain rows rather than as dead links,
50
+ * which is the rule `search-console.tsx` argues for a row that has nowhere to go.
51
+ */
52
+ const MUTED = 'text-zinc-400 dark:text-zinc-500';
53
+ const SECONDARY = 'text-zinc-500 dark:text-zinc-400';
54
+ const PANEL = 'bg-white dark:bg-zinc-900';
55
+ const RULE = 'border-zinc-200 dark:border-zinc-800';
56
+ /**
57
+ * Whether this graph would run on its own, and what says so.
58
+ *
59
+ * Four states rather than a status badge, because `status` alone answers the
60
+ * wrong question here. A reader on the model screen is asking "does this type
61
+ * get refreshed", and a graph can be `ready` and still never run — `enabled` is
62
+ * false, or nothing ever set a cron on it. Reporting `ready` for all three would
63
+ * be the screen agreeing with a schedule that does not exist, which is the
64
+ * incident `CatalogWorkflow.schedule` carries its own warning about.
65
+ */
66
+ function standingOf(workflow) {
67
+ if (workflow.status !== 'ready') {
68
+ return {
69
+ standing: 'draft — nobody has published it, so nothing schedules it',
70
+ idle: true,
71
+ };
72
+ }
73
+ if (!workflow.enabled) {
74
+ return { standing: 'published, but turned off', idle: true };
75
+ }
76
+ const schedule = workflow.schedule?.trim();
77
+ if (!schedule) {
78
+ return { standing: 'published, and runs only when somebody starts it', idle: false };
79
+ }
80
+ return { standing: `runs on ${schedule}`, idle: false };
81
+ }
82
+ /**
83
+ * Every graph whose sinks commit this type.
84
+ *
85
+ * A whitespace-only `targetType` on a sink is not a match, which
86
+ * `producedTypes` already handles by dropping it — a half-configured sink names
87
+ * nothing, and treating a blank as a match would attach every unfinished graph
88
+ * in the deployment to whichever type happened to sort first.
89
+ */
90
+ export function loadersOf(workflows, typeName) {
91
+ const loaders = [];
92
+ for (const workflow of workflows) {
93
+ const produces = producedTypes(workflow.nodes);
94
+ if (!produces.includes(typeName))
95
+ continue;
96
+ loaders.push({
97
+ id: workflow.id,
98
+ name: workflow.name,
99
+ ...standingOf(workflow),
100
+ alsoCommits: produces.filter((produced) => produced !== typeName),
101
+ });
102
+ }
103
+ return loaders;
104
+ }
105
+ export function LoadedBySection({ typeName, displayName, workflowHref }) {
106
+ const client = useCatalogClient();
107
+ const { data: workflows, isPending, isError, error, } = useQuery({
108
+ queryKey: catalogQueryKeys.workflows,
109
+ queryFn: () => client.listWorkflows(),
110
+ // Not retried, for the reason `LoadExpectationSection` gives beside the same
111
+ // decision: the likely failure is a host that mounts no pipeline endpoints,
112
+ // and four attempts at a 404 is half a minute of a section saying nothing
113
+ // before it says that.
114
+ retry: false,
115
+ });
116
+ const loaders = useMemo(() => (workflows ? loadersOf(workflows, typeName) : []), [workflows, typeName]);
117
+ return (_jsxs("section", { className: "mt-10", children: [_jsxs("div", { className: "mb-3", children: [_jsx("h2", { className: cn('font-mono text-[11px] uppercase tracking-[0.16em]', MUTED), children: "Loaded by" }), _jsxs("p", { className: cn('mt-1 text-xs', MUTED), children: ["Which authored ", WORKFLOW_NAME.plural, " commit into ", displayName, ", read from their sink nodes. Not the whole answer \u2014 see below."] })] }), isPending && (_jsxs("p", { className: cn('font-mono text-xs', MUTED), children: ["Reading the ", WORKFLOW_NAME.plural, "\u2026"] })), isError && (_jsxs("div", { className: cn('rounded-lg border px-4 py-3', RULE, PANEL), children: [_jsxs("p", { className: "text-sm", children: ["Could not read the ", WORKFLOW_NAME.plural, "."] }), _jsxs("p", { className: cn('mt-1 text-xs', SECONDARY), children: ["They are served by the pipeline endpoints, which are the host's rather than this library's \u2014 this deployment may not mount them, or this account may not read them. Nothing here says what loads ", displayName, "; in particular this is ", _jsx("em", { children: "not" }), " the same answer as \"nothing does\"."] }), error instanceof Error && (_jsx("p", { className: cn('mt-1 font-mono text-[11px]', MUTED), children: error.message }))] })), workflows &&
118
+ (loaders.length === 0 ? (_jsxs("p", { className: cn('rounded-lg border border-dashed px-4 py-6 text-center text-sm', RULE, MUTED), children: ["No ", WORKFLOW_NAME.singular, " in this catalog commits ", displayName, "."] })) : (_jsx("ul", { className: "space-y-1.5", children: loaders.map((loader) => (_jsx(LoaderRow, { loader: loader, href: workflowHref?.(loader.id), displayName: displayName }, loader.id))) }))), workflows && (_jsxs("p", { className: cn('mt-2 text-[11px] leading-relaxed', MUTED), children: ["An application holding a key of its own can publish straight into ", displayName, " through the publish API, and such a load is authored nowhere in this catalog \u2014 so it cannot appear above, whether the list is empty or not. What did land, and when, is on the type's freshness note and in Activity."] }))] }));
119
+ }
120
+ /**
121
+ * One graph, as a row.
122
+ *
123
+ * The link wraps the NAME only, and the standing sits outside it. Wrapping both
124
+ * would fold "draft — nobody has published it" into the link's accessible name,
125
+ * so a screen reader would announce the whole sentence as the destination — and
126
+ * two rows whose names differ only after forty characters are two links nobody
127
+ * can tell apart by ear.
128
+ */
129
+ function LoaderRow({ loader, href, displayName, }) {
130
+ return (_jsxs("li", { className: cn('flex flex-wrap items-center gap-x-2 gap-y-1 rounded-md border px-3 py-2', RULE, PANEL,
131
+ // Dimmed, not dropped: a draft that commits this type is the answer to
132
+ // "somebody is building one", which is a different and more useful
133
+ // answer than an empty list.
134
+ loader.idle && 'opacity-70'), children: [href ? (_jsxs("a", { href: href, "aria-label": `${loader.name} — open the ${WORKFLOW_NAME.singular} that commits ${displayName}`, className: cn('flex items-center gap-1.5 rounded-sm text-sm outline-none', 'hover:text-sky-700 focus-visible:ring-2 focus-visible:ring-sky-500/40 dark:hover:text-sky-400'), children: [loader.name, _jsx(ArrowUpRight, { size: 13, "aria-hidden": true, className: MUTED })] })) : (
135
+ // A plain row, never an anchor to nowhere: the host mounts no screen for
136
+ // a graph, and a link that looks live and goes nowhere is worse than
137
+ // text.
138
+ _jsx("span", { className: "text-sm", children: loader.name })), _jsxs("span", { className: cn('flex items-center gap-1 font-mono text-[10px]', MUTED), children: [loader.idle ? (_jsx(PauseCircle, { size: 11, "aria-hidden": true })) : (_jsx(CalendarClock, { size: 11, "aria-hidden": true })), loader.standing] }), loader.alsoCommits.length > 0 && (
139
+ // Said because it changes what a run of this graph means: it is one read
140
+ // feeding several outputs, so a failure here may leave the other types
141
+ // committed. `WorkflowRun.status` is failed if any sink failed.
142
+ _jsxs("span", { className: cn('font-mono text-[10px]', SECONDARY), children: ["also commits ", loader.alsoCommits.join(', ')] }))] }));
143
+ }