@dudousxd/nestjs-catalog-react 0.16.0 → 0.18.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. package/README.md +39 -13
  2. package/dist/ConnectionPanel.d.ts +11 -7
  3. package/dist/ConnectionPanel.js +65 -28
  4. package/dist/ObjectExplorer.js +424 -48
  5. package/dist/PipelineConsole.d.ts +23 -126
  6. package/dist/PipelineConsole.js +39 -551
  7. package/dist/QueryConsole.js +25 -17
  8. package/dist/SavedQueryPanel.js +1 -1
  9. package/dist/TransformEditor.js +12 -3
  10. package/dist/WorkflowCanvas.js +401 -29
  11. package/dist/bundler/index.d.ts +20 -0
  12. package/dist/bundler/index.js +20 -0
  13. package/dist/bundler/shiki-subset.d.ts +83 -0
  14. package/dist/bundler/shiki-subset.js +196 -0
  15. package/dist/context.d.ts +181 -38
  16. package/dist/context.js +44 -11
  17. package/dist/diff/RevisionDiff.d.ts +67 -4
  18. package/dist/diff/RevisionDiff.js +126 -91
  19. package/dist/index.d.ts +8 -5
  20. package/dist/index.js +56 -20
  21. package/dist/routes.d.ts +54 -13
  22. package/dist/routes.js +5 -4
  23. package/dist/schema-discovery.d.ts +216 -0
  24. package/dist/schema-discovery.js +225 -0
  25. package/dist/source-fields.d.ts +1 -12
  26. package/dist/source-fields.js +13 -16
  27. package/dist/ui/code-editor.d.ts +196 -8
  28. package/dist/ui/code-editor.js +184 -72
  29. package/dist/ui/code-languages.d.ts +80 -0
  30. package/dist/ui/code-languages.js +76 -0
  31. package/dist/ui/code-theme.d.ts +25 -0
  32. package/dist/ui/code-theme.js +26 -0
  33. package/dist/ui/dialog.d.ts +13 -1
  34. package/dist/ui/dialog.js +13 -2
  35. package/dist/workflow/graph.js +31 -9
  36. package/dist/workflow/index.d.ts +2 -0
  37. package/dist/workflow/index.js +7 -0
  38. package/dist/workflow/lifecycle.d.ts +164 -0
  39. package/dist/workflow/lifecycle.js +249 -0
  40. package/dist/workflow/model.d.ts +1 -1
  41. package/dist/workflow/nodes.js +10 -1
  42. package/dist/workflow/runs.d.ts +38 -0
  43. package/dist/workflow/runs.js +101 -0
  44. package/dist/workflow/shape.d.ts +169 -0
  45. package/dist/workflow/shape.js +249 -0
  46. package/dist/workflow/templates.d.ts +623 -0
  47. package/dist/workflow/templates.js +1092 -0
  48. package/dist/workflow/validate.d.ts +20 -1
  49. package/dist/workflow/validate.js +41 -3
  50. package/package.json +21 -17
  51. package/dist/diff/line-diff.d.ts +0 -124
  52. package/dist/diff/line-diff.js +0 -318
@@ -0,0 +1,164 @@
1
+ /**
2
+ * What happens to a graph after it is drawn: publish it, schedule it, run it.
3
+ *
4
+ * WHY THESE ARE ONE MODULE AND NOT PART OF THE CANVAS
5
+ * ---------------------------------------------------
6
+ * They arrived together, from a screen that no longer exists. Publishing,
7
+ * scheduling and running-with-an-acknowledgement all used to be connector
8
+ * concerns reached from `#connectors`; the connector stopped being something
9
+ * anybody authors, so all three landed on the graph. Putting them in the canvas
10
+ * file would have added four dialogs and three mutations to a component that is
11
+ * already the largest thing in this package, and none of them touch React Flow —
12
+ * which is also what lets this module be imported without a canvas at all.
13
+ *
14
+ * THE ONE THING TO BE CAREFUL WITH
15
+ * --------------------------------
16
+ * `expectShrink`. It is the only way an operator can re-drive a load the
17
+ * row-count bound refused, and it exists on exactly one route now. The
18
+ * alternative, when it is not reachable, is not "the load stays refused" — it is
19
+ * somebody raising `rowCount.maxShrink` in the type's policy, which stands the
20
+ * guard down for every future load of that type instead of for the one snapshot
21
+ * in front of them. So it is a visible control, it says what it does where it is
22
+ * used, and it will not send a blank reason.
23
+ */
24
+ import { type WorkflowRunOptions } from '../context';
25
+ import type { CatalogWorkflow, WorkflowRun } from './model';
26
+ /**
27
+ * Who a graph is attributed to when nobody drew it.
28
+ *
29
+ * `ConnectorAdoption` wraps a pre-workflow connector into the graph it always
30
+ * was, at boot, and publishes it — so an operator on an upgraded deployment
31
+ * opens this screen and finds pipelines marked `ready` that they never drew and
32
+ * never declared finished. That is worth saying out loud rather than leaving
33
+ * them to infer it from a description.
34
+ *
35
+ * Matched on `createdBy` rather than on the generated description, because a
36
+ * connector that carried a description of its own keeps it — so the description
37
+ * is silent on exactly the graphs that had the most history behind them. The
38
+ * string is the server's `ADOPTION_ACTOR`, and it is a copy: a rename there
39
+ * makes this badge disappear rather than lie, which is the failure mode to
40
+ * prefer between the two.
41
+ */
42
+ export declare const WORKFLOW_ADOPTION_ACTOR = "connector-adoption";
43
+ export declare function wasAdopted(workflow: Pick<CatalogWorkflow, 'createdBy'>): boolean;
44
+ /**
45
+ * Whether a failure is the row-count bound refusing a load, rather than
46
+ * anything else that can go wrong in a run.
47
+ *
48
+ * Matched on the label the refusal names, which is the one token in that
49
+ * sentence that is not prose: the message ends by telling the reader to set
50
+ * `_expectShrink` in the load's labels or raise `rowCount.maxShrink`, and this
51
+ * screen is the place that can do the first of those in one click.
52
+ *
53
+ * A miss costs nothing — the acknowledgement control is on screen regardless,
54
+ * and this only decides whether the refusal itself grows a way straight into it.
55
+ * That is deliberately the weaker of the two paths: a console that could offer
56
+ * the escape hatch *only* after a refusal would be a console where an operator
57
+ * who already knows a truncation is coming has to trigger a failed load first.
58
+ */
59
+ export declare function refusedForShrink(message: string | undefined): boolean;
60
+ /**
61
+ * Draft or ready, and — where it applies — who decided.
62
+ *
63
+ * Rendered even for `draft`, which is the status a screen is tempted to leave
64
+ * unsaid because it is the default. It is not decoration: a draft cannot be
65
+ * scheduled and does not run on its own, so "why did my pipeline not fire last
66
+ * night" has its answer here.
67
+ */
68
+ export declare function WorkflowStatusBadge({ workflow }: {
69
+ workflow: CatalogWorkflow;
70
+ }): import("react/jsx-runtime").JSX.Element;
71
+ /**
72
+ * The paragraph the badge cannot hold.
73
+ *
74
+ * On screen rather than in a tooltip, and only for an adopted graph, because a
75
+ * tooltip is something you find when you already suspect there is something to
76
+ * find. Somebody opening a pipeline they have never seen and being told it is
77
+ * `ready` has no reason to hover anything.
78
+ */
79
+ export declare function AdoptionNote({ workflow }: {
80
+ workflow: CatalogWorkflow;
81
+ }): import("react/jsx-runtime").JSX.Element | null;
82
+ /**
83
+ * Publish, or take it back to draft.
84
+ *
85
+ * Publishing is not offered while the canvas has unsaved edits, and that is the
86
+ * one place on this screen where blocking is right: publishing validates the
87
+ * STORED graph, so pressing it with edits on screen would report on a shape
88
+ * nobody is looking at — and, worse, would succeed on it.
89
+ *
90
+ * The local checks do not gate it. They cannot see which types exist or who may
91
+ * write to them, and a rule that is subtly wrong here would become a graph
92
+ * nobody can publish with no error to read. The server refuses, in its own
93
+ * words, and those words are what gets rendered.
94
+ */
95
+ export declare function PublishControls({ workflow, dirty, canEdit, onPublished, }: {
96
+ workflow: CatalogWorkflow;
97
+ dirty: boolean;
98
+ canEdit: boolean;
99
+ onPublished: (workflow: CatalogWorkflow) => void;
100
+ }): import("react/jsx-runtime").JSX.Element;
101
+ /**
102
+ * Run it now, and the one thing a run may be told about itself.
103
+ *
104
+ * Two controls rather than one, and deliberately not a checkbox tucked beside
105
+ * the button: an acknowledgement that a load is expected to lose most of its
106
+ * rows is not a preference, it is a statement somebody signs. The second control
107
+ * opens a dialog that says exactly what it is about to do and refuses to submit
108
+ * without a reason — the reason is written into the snapshot's labels and is the
109
+ * only answer anybody will have in six months to "why was this load allowed to
110
+ * collapse?".
111
+ *
112
+ * It is on screen always, not only after a refusal. An operator who already
113
+ * knows a base is being cut should not have to trigger a failed load first in
114
+ * order to be offered the way through it.
115
+ */
116
+ export declare function RunControls({ workflowId, dirty, canEdit, running, durabilityDetail, acknowledging, onAcknowledgingChange, onRun, }: {
117
+ workflowId: string | undefined;
118
+ dirty: boolean;
119
+ canEdit: boolean;
120
+ running: boolean;
121
+ durabilityDetail: string;
122
+ /**
123
+ * Whether the acknowledgement dialog is open, held by the CALLER.
124
+ *
125
+ * Controlled rather than internal because there are two ways in and they are
126
+ * in different parts of the screen: the icon button here, and the refusal
127
+ * note that appears after a load the bound turned away — which is the moment
128
+ * somebody most needs it and is nowhere near this row of buttons.
129
+ */
130
+ acknowledging: boolean;
131
+ onAcknowledgingChange: (open: boolean) => void;
132
+ onRun: (options?: WorkflowRunOptions) => void;
133
+ }): import("react/jsx-runtime").JSX.Element;
134
+ /**
135
+ * When this graph runs on its own.
136
+ *
137
+ * Its own write, `PUT workflows/:id/schedule`, rather than fields folded into
138
+ * the save the canvas performs on every drag — a cron that rides along with an
139
+ * autosave is one a stale tab can silently revert.
140
+ *
141
+ * The `warning` is the reason this panel does not just show a text box. There
142
+ * are several ways to store a cron that will never fire — the graph is a draft,
143
+ * the graph is disabled, the expression does not parse — and the incident behind
144
+ * this route is a scheduler that logged it was watching schedules every 30
145
+ * seconds while parsing nothing. The server names which one, and this prints it.
146
+ */
147
+ export declare function SchedulePanel({ workflow, canEdit, onScheduled, }: {
148
+ workflow: CatalogWorkflow;
149
+ canEdit: boolean;
150
+ onScheduled: (workflow: CatalogWorkflow) => void;
151
+ }): import("react/jsx-runtime").JSX.Element;
152
+ /**
153
+ * A run that was refused by the row-count bound, with the way through it.
154
+ *
155
+ * The refusal itself is the server's sentence and is printed whole. What this
156
+ * adds is the one action that answers it, at the moment somebody is reading the
157
+ * reason — because the alternative they will otherwise reach for is the type's
158
+ * policy, which is the wrong lever and the hard one to put back.
159
+ */
160
+ export declare function ShrinkRefusalNote({ run, error, onAcknowledge, }: {
161
+ run: WorkflowRun | null;
162
+ error: unknown;
163
+ onAcknowledge: () => void;
164
+ }): import("react/jsx-runtime").JSX.Element | null;
@@ -0,0 +1,249 @@
1
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
+ /**
3
+ * What happens to a graph after it is drawn: publish it, schedule it, run it.
4
+ *
5
+ * WHY THESE ARE ONE MODULE AND NOT PART OF THE CANVAS
6
+ * ---------------------------------------------------
7
+ * They arrived together, from a screen that no longer exists. Publishing,
8
+ * scheduling and running-with-an-acknowledgement all used to be connector
9
+ * concerns reached from `#connectors`; the connector stopped being something
10
+ * anybody authors, so all three landed on the graph. Putting them in the canvas
11
+ * file would have added four dialogs and three mutations to a component that is
12
+ * already the largest thing in this package, and none of them touch React Flow —
13
+ * which is also what lets this module be imported without a canvas at all.
14
+ *
15
+ * THE ONE THING TO BE CAREFUL WITH
16
+ * --------------------------------
17
+ * `expectShrink`. It is the only way an operator can re-drive a load the
18
+ * row-count bound refused, and it exists on exactly one route now. The
19
+ * alternative, when it is not reachable, is not "the load stays refused" — it is
20
+ * somebody raising `rowCount.maxShrink` in the type's policy, which stands the
21
+ * guard down for every future load of that type instead of for the one snapshot
22
+ * in front of them. So it is a visible control, it says what it does where it is
23
+ * used, and it will not send a blank reason.
24
+ */
25
+ import { useMutation, useQueryClient } from '@tanstack/react-query';
26
+ import { CircleCheck, Clock, Loader2, Play, Sparkles, TriangleAlert, Undo2, Upload, } from 'lucide-react';
27
+ import { useState } from 'react';
28
+ import { cn } from '../cn';
29
+ import { catalogQueryKeys, useCatalogClient, } from '../context';
30
+ import { Button } from '../ui/button';
31
+ import { ConfirmDialog } from '../ui/dialog';
32
+ import { TextAreaField, TextField } from '../ui/field';
33
+ import { Switch } from '../ui/switch';
34
+ import { Tooltip } from '../ui/tooltip';
35
+ import { WORKFLOW_NAME } from './name';
36
+ const MUTED = 'text-zinc-400 dark:text-zinc-500';
37
+ const RULE = 'border-zinc-200 dark:border-zinc-800';
38
+ const PANEL = 'bg-white dark:bg-zinc-900';
39
+ /**
40
+ * Who a graph is attributed to when nobody drew it.
41
+ *
42
+ * `ConnectorAdoption` wraps a pre-workflow connector into the graph it always
43
+ * was, at boot, and publishes it — so an operator on an upgraded deployment
44
+ * opens this screen and finds pipelines marked `ready` that they never drew and
45
+ * never declared finished. That is worth saying out loud rather than leaving
46
+ * them to infer it from a description.
47
+ *
48
+ * Matched on `createdBy` rather than on the generated description, because a
49
+ * connector that carried a description of its own keeps it — so the description
50
+ * is silent on exactly the graphs that had the most history behind them. The
51
+ * string is the server's `ADOPTION_ACTOR`, and it is a copy: a rename there
52
+ * makes this badge disappear rather than lie, which is the failure mode to
53
+ * prefer between the two.
54
+ */
55
+ export const WORKFLOW_ADOPTION_ACTOR = 'connector-adoption';
56
+ export function wasAdopted(workflow) {
57
+ return workflow.createdBy === WORKFLOW_ADOPTION_ACTOR;
58
+ }
59
+ /**
60
+ * Whether a failure is the row-count bound refusing a load, rather than
61
+ * anything else that can go wrong in a run.
62
+ *
63
+ * Matched on the label the refusal names, which is the one token in that
64
+ * sentence that is not prose: the message ends by telling the reader to set
65
+ * `_expectShrink` in the load's labels or raise `rowCount.maxShrink`, and this
66
+ * screen is the place that can do the first of those in one click.
67
+ *
68
+ * A miss costs nothing — the acknowledgement control is on screen regardless,
69
+ * and this only decides whether the refusal itself grows a way straight into it.
70
+ * That is deliberately the weaker of the two paths: a console that could offer
71
+ * the escape hatch *only* after a refusal would be a console where an operator
72
+ * who already knows a truncation is coming has to trigger a failed load first.
73
+ */
74
+ export function refusedForShrink(message) {
75
+ return typeof message === 'string' && message.includes('_expectShrink');
76
+ }
77
+ /**
78
+ * Draft or ready, and — where it applies — who decided.
79
+ *
80
+ * Rendered even for `draft`, which is the status a screen is tempted to leave
81
+ * unsaid because it is the default. It is not decoration: a draft cannot be
82
+ * scheduled and does not run on its own, so "why did my pipeline not fire last
83
+ * night" has its answer here.
84
+ */
85
+ export function WorkflowStatusBadge({ workflow }) {
86
+ const ready = workflow.status === 'ready';
87
+ return (_jsxs("span", { className: "flex flex-wrap items-center gap-1.5", children: [_jsx(Tooltip, { content: ready
88
+ ? `Declared finished, and validated when it was. It runs as a connector of its own, and only a ready ${WORKFLOW_NAME.singular} can be scheduled.`
89
+ : 'Being drawn. It saves without being validated — that is what a draft is for — and it neither runs on a schedule nor mints anything. Publishing is where the checks are answered for real.', children: _jsx("span", { className: cn('cursor-help rounded-sm px-1.5 py-0.5 font-mono text-[10px] uppercase tracking-[0.12em]', ready
90
+ ? 'bg-emerald-100 text-emerald-800 dark:bg-emerald-950 dark:text-emerald-300'
91
+ : 'bg-zinc-100 text-zinc-600 dark:bg-zinc-800 dark:text-zinc-300'), children: workflow.status }) }), !workflow.enabled && (_jsx(Tooltip, { content: "Turned off. It keeps its configuration, its schedule and its incremental watermark, and refuses to fire.", children: _jsx("span", { className: cn('cursor-help rounded-sm bg-zinc-100 px-1.5 py-0.5 font-mono text-[10px] uppercase tracking-[0.12em]', 'text-zinc-600 dark:bg-zinc-800 dark:text-zinc-300'), children: "disabled" }) })), wasAdopted(workflow) && (_jsx(Tooltip, { content: `Nobody drew this. It was a connector from before a ${WORKFLOW_NAME.singular} was the only thing anybody authors, and it was wrapped into this graph at boot — one source, optionally one transform, one sink — and published as ready without a person declaring it finished. It keeps the connector's id, so its run history and its incremental watermark carry over. Worth reading before you trust the shape.`, children: _jsxs("span", { className: "flex cursor-help items-center gap-1 rounded-sm bg-sky-100 px-1.5 py-0.5 font-mono text-[10px] uppercase tracking-[0.12em] text-sky-800 dark:bg-sky-950 dark:text-sky-300", children: [_jsx(Sparkles, { size: 9, "aria-hidden": true }), "adopted"] }) }))] }));
92
+ }
93
+ /**
94
+ * The paragraph the badge cannot hold.
95
+ *
96
+ * On screen rather than in a tooltip, and only for an adopted graph, because a
97
+ * tooltip is something you find when you already suspect there is something to
98
+ * find. Somebody opening a pipeline they have never seen and being told it is
99
+ * `ready` has no reason to hover anything.
100
+ */
101
+ export function AdoptionNote({ workflow }) {
102
+ if (!wasAdopted(workflow))
103
+ return null;
104
+ return (_jsxs("div", { className: cn('mt-2.5 flex flex-wrap items-baseline gap-x-2 rounded-md border px-2.5 py-1.5', 'border-sky-200 bg-sky-50 text-sky-900', 'dark:border-sky-900 dark:bg-sky-950/40 dark:text-sky-200'), children: [_jsx("p", { className: "font-mono text-[10px] uppercase tracking-[0.14em]", children: "adopted at boot" }), _jsxs("p", { className: "text-[11px] leading-relaxed", children: ["This graph was not drawn by anybody. A connector that predates ", WORKFLOW_NAME.plural, " was wrapped into it and published as ", _jsx("em", { children: "ready" }), " automatically, so \"ready\" here means \"it validated\", not \"somebody looked at it and said it was finished\". Its run history and incremental watermark carried over with the connector's id."] })] }));
105
+ }
106
+ /**
107
+ * Publish, or take it back to draft.
108
+ *
109
+ * Publishing is not offered while the canvas has unsaved edits, and that is the
110
+ * one place on this screen where blocking is right: publishing validates the
111
+ * STORED graph, so pressing it with edits on screen would report on a shape
112
+ * nobody is looking at — and, worse, would succeed on it.
113
+ *
114
+ * The local checks do not gate it. They cannot see which types exist or who may
115
+ * write to them, and a rule that is subtly wrong here would become a graph
116
+ * nobody can publish with no error to read. The server refuses, in its own
117
+ * words, and those words are what gets rendered.
118
+ */
119
+ export function PublishControls({ workflow, dirty, canEdit, onPublished, }) {
120
+ const client = useCatalogClient();
121
+ const queryClient = useQueryClient();
122
+ const [confirmingUnpublish, setConfirmingUnpublish] = useState(false);
123
+ const invalidate = () => {
124
+ queryClient.invalidateQueries({ queryKey: catalogQueryKeys.workflows });
125
+ // The connector is minted, disabled or removed by these two, and it is
126
+ // where the run history is keyed — a stale read shows a pipeline that is
127
+ // ready beside "nothing runs this yet".
128
+ queryClient.invalidateQueries({ queryKey: catalogQueryKeys.connectors });
129
+ };
130
+ const publish = useMutation({
131
+ mutationFn: () => client.publishWorkflow(workflow.id),
132
+ onSuccess: (saved) => {
133
+ onPublished(saved);
134
+ invalidate();
135
+ },
136
+ });
137
+ const unpublish = useMutation({
138
+ mutationFn: () => client.unpublishWorkflow(workflow.id),
139
+ onSuccess: (saved) => {
140
+ setConfirmingUnpublish(false);
141
+ onPublished(saved);
142
+ invalidate();
143
+ },
144
+ });
145
+ return (_jsxs(_Fragment, { children: [workflow.status === 'ready' ? (_jsx(Tooltip, { content: "Back to draft. The connector it runs as is disabled and keeps its id, its run history and its watermark, so publishing again resumes this workflow rather than starting a second one beside it.", children: _jsxs(Button, { variant: "outline", size: "sm", onClick: () => setConfirmingUnpublish(true), disabled: !canEdit || unpublish.isPending, children: [unpublish.isPending ? (_jsx(Loader2, { size: 12, className: "animate-spin" })) : (_jsx(Undo2, { size: 12 })), "Unpublish"] }) })) : (_jsx(Tooltip, { content: dirty
146
+ ? 'Save first — publishing validates the stored graph, not what is on screen.'
147
+ : `Declare it finished. The server validates it and, if it passes, mints the connector this ${WORKFLOW_NAME.singular} runs as — which is what makes it schedulable and what a run history is keyed on.`, children: _jsxs(Button, { size: "sm", onClick: () => publish.mutate(), disabled: !canEdit || dirty || publish.isPending, children: [publish.isPending ? (_jsx(Loader2, { size: 12, className: "animate-spin" })) : (_jsx(Upload, { size: 12 })), "Publish"] }) })), _jsx(Refusal, { lead: "Publishing was refused:", error: publish.error }), !confirmingUnpublish && _jsx(Refusal, { lead: "Could not unpublish it:", error: unpublish.error }), _jsx(ConfirmDialog, { open: confirmingUnpublish, onOpenChange: setConfirmingUnpublish, destructive: false, title: `Take "${workflow.name}" back to draft?`, description: "It stops running: the connector behind it is disabled, and a schedule on it will not fire. Nothing is lost \u2014 the id, the run history and the incremental watermark stay, so publishing again picks the same workflow back up rather than starting a second one from the beginning.", confirmLabel: unpublish.isPending ? 'Unpublishing…' : 'Unpublish', pending: unpublish.isPending, onConfirm: () => unpublish.mutate(), error: reasonFrom(unpublish.error) })] }));
148
+ }
149
+ /** What went wrong, in the server's words, or nothing at all. */
150
+ function Refusal({ lead, error }) {
151
+ const reason = reasonFrom(error);
152
+ if (!reason)
153
+ return null;
154
+ return (_jsxs("p", { className: "basis-full text-[11px] text-red-600", children: [lead, " ", reason] }));
155
+ }
156
+ /**
157
+ * The sentence out of a rejection, or `undefined` when nothing was rejected.
158
+ *
159
+ * One place, because the alternative is the nested ternary this file had three
160
+ * copies of — and the branch that is easy to get wrong is the middle one: a
161
+ * rejection that is not an `Error` still has to say something, or a refusal
162
+ * renders as blank space where a reason belongs.
163
+ */
164
+ function reasonFrom(error) {
165
+ if (!error)
166
+ return undefined;
167
+ return error instanceof Error ? error.message : 'no reason given.';
168
+ }
169
+ /**
170
+ * Run it now, and the one thing a run may be told about itself.
171
+ *
172
+ * Two controls rather than one, and deliberately not a checkbox tucked beside
173
+ * the button: an acknowledgement that a load is expected to lose most of its
174
+ * rows is not a preference, it is a statement somebody signs. The second control
175
+ * opens a dialog that says exactly what it is about to do and refuses to submit
176
+ * without a reason — the reason is written into the snapshot's labels and is the
177
+ * only answer anybody will have in six months to "why was this load allowed to
178
+ * collapse?".
179
+ *
180
+ * It is on screen always, not only after a refusal. An operator who already
181
+ * knows a base is being cut should not have to trigger a failed load first in
182
+ * order to be offered the way through it.
183
+ */
184
+ export function RunControls({ workflowId, dirty, canEdit, running, durabilityDetail, acknowledging, onAcknowledgingChange, onRun, }) {
185
+ const [reason, setReason] = useState('');
186
+ const blocked = !canEdit || !workflowId || dirty || running;
187
+ return (_jsxs(_Fragment, { children: [_jsx(Tooltip, { content: dirty
188
+ ? 'Save first — a run executes the stored graph, not what is on screen.'
189
+ : durabilityDetail, children: _jsxs(Button, { variant: "outline", size: "sm", onClick: () => onRun(), disabled: blocked, children: [running ? _jsx(Loader2, { size: 12, className: "animate-spin" }) : _jsx(Play, { size: 12 }), "Run"] }) }), _jsx(Tooltip, { content: "Run, saying up front that this load is expected to lose rows. Use it when a source really was truncated or cut back \u2014 it stands the row-count bound down for this one snapshot instead of for every future load of the type.", children: _jsx(Button, { variant: "outline", size: "icon", "aria-label": "Run, acknowledging that this load is expected to lose rows", onClick: () => {
190
+ setReason('');
191
+ onAcknowledgingChange(true);
192
+ }, disabled: blocked, children: _jsx(TriangleAlert, { size: 12 }) }) }), _jsx(ConfirmDialog, { open: acknowledging, onOpenChange: onAcknowledgingChange, destructive: false, title: "Run, expecting this load to shrink?", description: _jsxs("span", { className: "block space-y-2.5", children: [_jsxs("span", { className: "block", children: ["A load that loses more rows than the type allows is refused and the previous snapshot keeps serving \u2014 because a broken ", _jsx("code", { children: "WHERE" }), ", a source-side filter change and a partial outage all look exactly like this, and the data would be fresh and wrong."] }), _jsxs("span", { className: "block", children: ["This acknowledgement stands that bound down ", _jsx("strong", { children: "for this run only" }), ". The alternative \u2014 raising the type's ", _jsx("code", { children: "rowCount.maxShrink" }), " \u2014 turns the guard off for every load of it from now on, including the ones nobody is watching."] }), _jsx(TextAreaField, { label: "Why is this load expected to lose rows?", value: reason, onChange: setReason, rows: 3, placeholder: "e.g. Hurlburt was cut from the feed on the 3rd; this is the first load without it.", hint: "Stored in the snapshot's labels, so the load itself carries the answer. A blank reason is refused \u2014 an acknowledgement nobody can explain later is worth nothing." })] }), confirmLabel: running ? 'Running…' : 'Run with this reason', pending: running, confirmDisabled: reason.trim().length === 0, onConfirm: () => {
193
+ onAcknowledgingChange(false);
194
+ onRun({ expectShrink: reason.trim() });
195
+ } })] }));
196
+ }
197
+ /**
198
+ * When this graph runs on its own.
199
+ *
200
+ * Its own write, `PUT workflows/:id/schedule`, rather than fields folded into
201
+ * the save the canvas performs on every drag — a cron that rides along with an
202
+ * autosave is one a stale tab can silently revert.
203
+ *
204
+ * The `warning` is the reason this panel does not just show a text box. There
205
+ * are several ways to store a cron that will never fire — the graph is a draft,
206
+ * the graph is disabled, the expression does not parse — and the incident behind
207
+ * this route is a scheduler that logged it was watching schedules every 30
208
+ * seconds while parsing nothing. The server names which one, and this prints it.
209
+ */
210
+ export function SchedulePanel({ workflow, canEdit, onScheduled, }) {
211
+ const client = useCatalogClient();
212
+ const queryClient = useQueryClient();
213
+ const [schedule, setSchedule] = useState(workflow.schedule ?? '');
214
+ const [enabled, setEnabled] = useState(workflow.enabled);
215
+ const save = useMutation({
216
+ mutationFn: () => client.scheduleWorkflow(workflow.id, { schedule, enabled }),
217
+ onSuccess: (saved) => {
218
+ onScheduled(saved);
219
+ queryClient.invalidateQueries({ queryKey: catalogQueryKeys.workflows });
220
+ queryClient.invalidateQueries({ queryKey: catalogQueryKeys.connectors });
221
+ },
222
+ });
223
+ const changed = schedule !== (workflow.schedule ?? '') || enabled !== workflow.enabled;
224
+ return (_jsxs("section", { className: cn('rounded-lg border p-3', RULE, PANEL), children: [_jsxs("h2", { className: cn('flex items-center gap-1.5 font-mono text-[10px] uppercase tracking-[0.14em]', MUTED), children: [_jsx(Clock, { size: 10, "aria-hidden": true }), "Schedule"] }), _jsxs("div", { className: "mt-2 space-y-2", children: [_jsx(TextField, { label: "Cron", value: schedule, onChange: setSchedule, placeholder: "0 3 * * *", disabled: !canEdit, hint: "Empty means this only runs when somebody presses Run." }), _jsx(Switch, { checked: enabled, onCheckedChange: setEnabled, label: "Enabled", hint: "Off keeps the cron, the configuration and the watermark, and refuses to fire.", disabled: !canEdit }), canEdit && (_jsxs(Button, { variant: "outline", size: "sm", onClick: () => save.mutate(), disabled: !changed || save.isPending, children: [save.isPending ? _jsx(Loader2, { size: 12, className: "animate-spin" }) : null, changed ? 'Save schedule' : 'Schedule saved'] }))] }), workflow.status !== 'ready' && (_jsx("p", { className: "mt-2 text-[11px] leading-relaxed text-amber-700 dark:text-amber-400", children: "This is a draft, so nothing here will fire whatever the cron says. Publish it first \u2014 scheduling a graph nobody has declared finished is a load nobody approved." })), save.data?.warning ? (_jsxs("p", { className: "mt-2 flex items-start gap-1.5 text-[11px] leading-relaxed text-amber-700 dark:text-amber-400", children: [_jsx(TriangleAlert, { size: 11, className: "mt-0.5 shrink-0", "aria-hidden": true }), save.data.warning] })) : null, save.isSuccess && !save.data?.warning && !changed && (_jsxs("p", { className: "mt-2 flex items-center gap-1.5 text-[11px] text-emerald-600", children: [_jsx(CircleCheck, { size: 11, "aria-hidden": true }), "Stored. The scheduler reads this graph, not the connector behind it."] })), save.error && (_jsx("p", { className: "mt-2 text-[11px] text-red-600", children: save.error instanceof Error ? save.error.message : 'Could not store the schedule.' }))] }));
225
+ }
226
+ /**
227
+ * A run that was refused by the row-count bound, with the way through it.
228
+ *
229
+ * The refusal itself is the server's sentence and is printed whole. What this
230
+ * adds is the one action that answers it, at the moment somebody is reading the
231
+ * reason — because the alternative they will otherwise reach for is the type's
232
+ * policy, which is the wrong lever and the hard one to put back.
233
+ */
234
+ export function ShrinkRefusalNote({ run, error, onAcknowledge, }) {
235
+ const message = error instanceof Error ? error.message : (run?.error ?? runNodeError(run) ?? undefined);
236
+ if (!refusedForShrink(message))
237
+ return null;
238
+ return (_jsxs("div", { className: "mt-2 rounded-md border border-amber-300 bg-amber-50 px-3 py-2 dark:border-amber-900 dark:bg-amber-950/30", children: [_jsx("p", { className: "text-[11px] leading-relaxed text-amber-800 dark:text-amber-200", children: message }), _jsx("p", { className: "mt-1.5 text-[11px] leading-relaxed text-amber-700 dark:text-amber-300", children: "If the load is right, re-drive it with a reason. That acknowledges this snapshot and nothing else \u2014 raising the type's bound would stand the guard down for every load of it from now on." }), _jsxs(Button, { variant: "outline", size: "sm", className: "mt-2", onClick: onAcknowledge, children: [_jsx(TriangleAlert, { size: 12 }), "Re-run, acknowledging the shrink"] })] }));
239
+ }
240
+ /**
241
+ * The first node error in a run, when the run itself carries none.
242
+ *
243
+ * A sink that refuses is one failed node in an otherwise ordinary run, and
244
+ * depending on whether the graph ran durably the refusal can land on the node
245
+ * rather than on the run. Reading both is cheaper than caring which.
246
+ */
247
+ function runNodeError(run) {
248
+ return run?.nodes.find((node) => typeof node.error === 'string' && node.error.length > 0)?.error;
249
+ }
@@ -18,7 +18,7 @@
18
18
  * executes it, it belongs to core; if only this screen has an opinion about it,
19
19
  * it belongs here.
20
20
  */
21
- export type { CatalogWorkflow, WorkflowEdge, WorkflowGraph, WorkflowNode, WorkflowNodeKind, WorkflowSinkNode, WorkflowSourceNode, WorkflowTransformNode, } from '@dudousxd/nestjs-catalog/client';
21
+ export type { CallableWorkflowRef, CatalogWorkflow, WorkflowEdge, WorkflowCallNode, WorkflowGraph, WorkflowNode, WorkflowNodeKind, WorkflowSinkNode, WorkflowSourceNode, WorkflowTransformNode, } from '@dudousxd/nestjs-catalog/client';
22
22
  export { isWorkflowNodeKind, WORKFLOW_NODE_ID_PATTERN, WORKFLOW_NODE_KINDS, } from '@dudousxd/nestjs-catalog/client';
23
23
  import { type WorkflowNode } from '@dudousxd/nestjs-catalog/client';
24
24
  /**
@@ -1,6 +1,6 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { Handle, Position } from '@xyflow/react';
3
- import { CircleAlert, CircleCheck, Code2, Database, Loader2, Plug, Repeat, TriangleAlert, } from 'lucide-react';
3
+ import { CircleAlert, CircleCheck, Code2, Database, ExternalLink, Loader2, Plug, Repeat, TriangleAlert, } from 'lucide-react';
4
4
  import { createContext, useContext } from 'react';
5
5
  import { cn } from '../cn';
6
6
  import { Tooltip } from '../ui/tooltip';
@@ -37,6 +37,15 @@ const KIND_STYLE = {
37
37
  icon: Database,
38
38
  noun: 'sink',
39
39
  },
40
+ // Amber and its own icon, because a call is the one node whose work does not
41
+ // happen here: the box on the canvas is a handle on a workflow somebody else
42
+ // owns, and it should not read as another transform.
43
+ call: {
44
+ accent: 'bg-amber-500',
45
+ chip: 'text-amber-700 dark:text-amber-300',
46
+ icon: ExternalLink,
47
+ noun: 'call',
48
+ },
40
49
  };
41
50
  /**
42
51
  * Handles are styled larger than React Flow's default 6px dot.
@@ -0,0 +1,38 @@
1
+ /**
2
+ * What a published graph runs as, and what it has done lately.
3
+ *
4
+ * WHY A CONNECTOR IS STILL ON SCREEN AT ALL
5
+ * -----------------------------------------
6
+ * Because it is the id everything else is keyed on. A connector is no longer
7
+ * something anybody creates — publishing a graph mints one, deleting the graph
8
+ * removes it, and there is no route that makes one directly — but the run
9
+ * history and the incremental watermark hang off that id, and the connector is
10
+ * what a scheduled fire is attributed to. An internal record no screen exposes
11
+ * is one an operator debugs by opening the database.
12
+ *
13
+ * So this panel is a READ and says so. There is no run button here (the run
14
+ * button is on the graph), no delete (deleting the graph is what removes it) and
15
+ * no edit (every field it used to hold is a node on the canvas now). Where one
16
+ * of those used to be, the panel says where the action went instead of quietly
17
+ * not being there.
18
+ *
19
+ * **Nothing here prints a config.** The server redacts a URL password on the way
20
+ * out and `allowInlineCredentials` decides whether one may be stored at all, so
21
+ * the honest thing for a screen is not to render the field: showing `REDACTED`
22
+ * beside a real host teaches people the console shows credentials, and the day
23
+ * one is not redacted is the day somebody screenshots it.
24
+ */
25
+ import type { CatalogTransform } from '@dudousxd/nestjs-catalog/client';
26
+ /**
27
+ * The connector this graph runs as, and its recent loads.
28
+ *
29
+ * Rendered for a stored graph only. A draft has nothing behind it — that is
30
+ * what a draft is — and an empty "Runs as" panel over a canvas somebody is
31
+ * still drawing would be a permanent heading nobody reads.
32
+ */
33
+ export declare function RunsAsPanel({ workflowId, status, transforms, }: {
34
+ workflowId: string;
35
+ status: 'draft' | 'ready';
36
+ /** The transforms this graph names, so a run's `code v3` can be compared. */
37
+ transforms: CatalogTransform[];
38
+ }): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,101 @@
1
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
+ import { useQuery } from '@tanstack/react-query';
3
+ import { CircleCheck, CircleX, Loader2, RefreshCw } from 'lucide-react';
4
+ import { useMemo, useState } from 'react';
5
+ import { cn } from '../cn';
6
+ import { catalogQueryKeys, useCatalogClient } from '../context';
7
+ import { RevisionHistorySheet } from '../diff/RevisionDiff';
8
+ import { Tooltip } from '../ui/tooltip';
9
+ import { WORKFLOW_NAME } from './name';
10
+ const MUTED = 'text-zinc-400 dark:text-zinc-500';
11
+ const RULE = 'border-zinc-200 dark:border-zinc-800';
12
+ const PANEL = 'bg-white dark:bg-zinc-900';
13
+ /**
14
+ * The connector this graph runs as, and its recent loads.
15
+ *
16
+ * Rendered for a stored graph only. A draft has nothing behind it — that is
17
+ * what a draft is — and an empty "Runs as" panel over a canvas somebody is
18
+ * still drawing would be a permanent heading nobody reads.
19
+ */
20
+ export function RunsAsPanel({ workflowId, status, transforms, }) {
21
+ const client = useCatalogClient();
22
+ const { data: connectors = [], isPending } = useQuery({
23
+ queryKey: catalogQueryKeys.connectors,
24
+ queryFn: () => client.listConnectors(),
25
+ });
26
+ const connector = useMemo(() => connectors.find((candidate) => candidate.workflowId === workflowId), [connectors, workflowId]);
27
+ return (_jsxs("section", { className: cn('rounded-lg border p-3', RULE, PANEL), children: [_jsx("h2", { className: cn('font-mono text-[10px] uppercase tracking-[0.14em]', MUTED), children: "Runs as" }), isPending && _jsx("p", { className: cn('mt-2 text-[11px]', MUTED), children: "Reading\u2026" }), !isPending && !connector && (_jsx("p", { className: cn('mt-2 text-[11px] leading-relaxed', MUTED), children: status === 'ready'
28
+ ? `This ${WORKFLOW_NAME.singular} is ready but nothing is running it yet. That is unusual — publishing is what mints the connector a run history is keyed on — and it is worth a look before trusting a schedule on it.`
29
+ : `Nothing yet. Publishing is what mints the connector this ${WORKFLOW_NAME.singular} runs as; until then a run is something you press, and there is no history to key.` })), connector && _jsx(ConnectorIdentity, { connector: connector }), connector && _jsx(RecentRuns, { connectorId: connector.id, transforms: transforms })] }));
30
+ }
31
+ /**
32
+ * The connector's id and state, and nothing else.
33
+ *
34
+ * The id is the load-bearing part: it is what `GET pipeline/runs?connector=` is
35
+ * keyed on and what an operator greps a log for. Its name and target type are
36
+ * the graph's, restated, so they are not repeated here.
37
+ */
38
+ function ConnectorIdentity({ connector }) {
39
+ return (_jsxs("div", { className: "mt-2 space-y-1", children: [_jsx(Tooltip, { content: "The id the run history, the incremental watermark and the singleton lock are all keyed on. It survives an unpublish and a re-publish, which is what makes those three carry over.", children: _jsx("div", { className: cn('flex cursor-help items-center gap-1.5 font-mono text-[10px]', MUTED), children: _jsx("span", { className: "truncate", children: connector.id }) }) }), _jsxs("div", { className: "flex flex-wrap items-center gap-1.5", children: [connector.mode === 'incremental' && (_jsx(Tooltip, { content: "Reads only what changed since the last run, and carries the rest forward. The position is kept per source node.", children: _jsxs("span", { className: cn('flex cursor-help items-center gap-1 font-mono text-[10px]', MUTED), children: [_jsx(RefreshCw, { size: 10 }), "incremental"] }) })), !connector.enabled && (_jsx(Tooltip, { content: "Disabled. Unpublishing does this, and it is why the id and the history survive one.", children: _jsx("span", { className: "cursor-help rounded-sm bg-zinc-100 px-1.5 py-0.5 font-mono text-[10px] uppercase dark:bg-zinc-800", children: "disabled" }) }))] }), _jsxs("p", { className: cn('text-[10px] leading-relaxed', MUTED), children: ["Read-only. Running, scheduling and deleting are all done on the ", WORKFLOW_NAME.singular, ' ', "above \u2014 this row is minted by publishing it and removed with it."] })] }));
40
+ }
41
+ /**
42
+ * What this workflow has done lately, and the way from a load to the code that
43
+ * produced it.
44
+ *
45
+ * The `code v3` on a row is a control rather than a fact: it is where the
46
+ * question "why did this load come out different" actually occurs to somebody,
47
+ * and making the number the way in means nobody has to carry it to another
48
+ * screen and pick it out of a dropdown — which is the step where you pick the
49
+ * wrong one and conclude the code was fine.
50
+ *
51
+ * It is only a control when the answer is unambiguous. A run records ONE
52
+ * `transformVersion`, which meant something exact when a connector had at most
53
+ * one transform; a graph may run three in a row, and offering a comparison
54
+ * against whichever one this screen happened to pick first would be worse than
55
+ * offering none. So the compare is available for a graph with exactly one
56
+ * transform, and the version is plain text otherwise.
57
+ */
58
+ function RecentRuns({ connectorId, transforms, }) {
59
+ const client = useCatalogClient();
60
+ const [comparing, setComparing] = useState(null);
61
+ const { data: runs = [] } = useQuery({
62
+ queryKey: catalogQueryKeys.runs(connectorId),
63
+ queryFn: () => client.listRuns(connectorId),
64
+ });
65
+ const only = transforms.length === 1 ? transforms[0] : undefined;
66
+ if (runs.length === 0) {
67
+ return _jsx("p", { className: cn('mt-2 text-[11px]', MUTED), children: "No runs recorded against it yet." });
68
+ }
69
+ return (_jsxs(_Fragment, { children: [_jsxs("div", { className: cn('mt-3 border-t pt-2', RULE), children: [_jsx("div", { className: cn('mb-1.5 font-mono text-[10px] uppercase tracking-[0.14em]', MUTED), children: "Recent runs" }), _jsx("div", { className: "space-y-1", children: runs.slice(0, 4).map((entry) => (_jsx(Tooltip, { content: entry.error ? (_jsx("span", { className: "font-mono text-[11px]", children: entry.error })) : (_jsx("span", { className: "font-mono text-[11px]", children: entry.logs.slice(-3).join('\n') || 'No logs.' })), children: _jsxs("div", { className: "flex cursor-help flex-wrap items-center gap-1.5 text-[11px]", children: [_jsxs("span", { className: "sr-only", children: [entry.status, ": "] }), _jsx(RunStatusIcon, { status: entry.status }), _jsx("span", { className: "truncate font-mono text-[10px]", children: entry.snapshotId }), _jsxs("span", { className: cn('font-mono text-[10px]', MUTED), children: [entry.fetched, " fetched \u00B7 ", entry.written, " written"] }), _jsx(RanCodeVersion, { version: entry.transformVersion, comparable: only !== undefined, onCompare: setComparing })] }) }, entry.id))) })] }), only && (_jsx(RevisionHistorySheet, { open: comparing !== null, onOpenChange: (open) => {
70
+ if (!open)
71
+ setComparing(null);
72
+ }, subject: { kind: 'transform', id: only.id, name: only.name }, current: { version: only.version, body: only.code }, ranVersion: comparing ?? undefined }))] }));
73
+ }
74
+ function RunStatusIcon({ status }) {
75
+ if (status === 'succeeded')
76
+ return _jsx(CircleCheck, { size: 11, "aria-hidden": true, className: "text-emerald-600" });
77
+ if (status === 'failed')
78
+ return _jsx(CircleX, { size: 11, "aria-hidden": true, className: "text-red-600" });
79
+ return _jsx(Loader2, { size: 11, "aria-hidden": true, className: "animate-spin text-sky-600" });
80
+ }
81
+ /**
82
+ * `code v3` on a run, as a way into the comparison rather than as a fact.
83
+ *
84
+ * Still only text when there is nothing on the other side: a pipeline with no
85
+ * transform never records a version, a version whose transform has since been
86
+ * deleted has no current code to compare against, and a graph with several
87
+ * transforms has no single answer to which one this number names. A control that
88
+ * opens an empty panel — or the wrong one — is a control that teaches people to
89
+ * stop pressing it.
90
+ */
91
+ function RanCodeVersion({ version, comparable, onCompare, }) {
92
+ if (version === undefined)
93
+ return null;
94
+ if (!comparable)
95
+ return _jsxs("span", { className: cn('font-mono text-[10px]', MUTED), children: ["code v", version] });
96
+ return (
97
+ // Inside the tooltip's trigger rather than beside it, because this row IS
98
+ // the trigger: pulling the button out would put a gap in the hover target
99
+ // exactly where the pointer is heading. A click inside it bubbles normally.
100
+ _jsxs("button", { type: "button", onClick: () => onCompare(version), "aria-label": `Compare the code that ran (v${version}) with the current code`, className: cn('rounded-sm px-1 font-mono text-[10px] underline decoration-dotted underline-offset-2', MUTED, 'hover:text-sky-600'), children: ["code v", version] }));
101
+ }