@dudousxd/nestjs-catalog-react 0.25.1 → 0.27.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.
@@ -1,5 +1,5 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
- import { isTransformLanguage } from '@dudousxd/nestjs-catalog/client';
2
+ import { isTransformLanguage, transformShape } from '@dudousxd/nestjs-catalog/client';
3
3
  import { useMutation } from '@tanstack/react-query';
4
4
  import { ArrowLeft, Play } from 'lucide-react';
5
5
  import { useState } from 'react';
@@ -10,6 +10,7 @@ import { CodeEditor } from './ui/code-editor';
10
10
  import { TRANSFORM_HIGHLIGHTED_AS } from './ui/code-languages';
11
11
  import { TextField } from './ui/field';
12
12
  import { SelectField } from './ui/select';
13
+ import { Tooltip } from './ui/tooltip';
13
14
  const MUTED = 'text-zinc-400 dark:text-zinc-500';
14
15
  const RULE = 'border-zinc-200 dark:border-zinc-800';
15
16
  const PANEL = 'bg-white dark:bg-zinc-900';
@@ -19,26 +20,48 @@ const PANEL = 'bg-white dark:bg-zinc-900';
19
20
  * Keyed by the language union rather than by `string`, so adding a language to
20
21
  * the library without a starter here is a type error rather than an editor that
21
22
  * silently opens empty.
23
+ *
24
+ * The JavaScript and TypeScript starters open in the **module shape** — a real
25
+ * function taking one object — because a starter is how a shape is actually
26
+ * adopted. Nobody reads a changelog to find out that a signature moved; they
27
+ * copy what the editor put in front of them, and every transform written from
28
+ * here on gains fields on that object for free.
29
+ *
30
+ * Nothing is migrated by this. An existing transform opens with its own saved
31
+ * code and keeps running exactly as it always has, in whichever shape it was
32
+ * written in; the starter is only what an empty editor is pre-filled with.
22
33
  */
23
34
  const STARTERS = {
24
- typescript: `// \`records\` is the batch the connector fetched.
25
- // Types are stripped, never checked — the try pane is what catches a mistake.
35
+ // The type import is `import type`, and that is load-bearing rather than
36
+ // stylistic: the stripper erases the whole statement, so nothing tries to
37
+ // resolve the package inside a child process that has no `node_modules`. The
38
+ // same specifier as a value import would fail at run time.
39
+ typescript: `import type { CatalogTransformFunction } from '@dudousxd/nestjs-catalog/client';
40
+
41
+ // Types here are erased before this runs, and never checked — a wrong one is a
42
+ // squiggle in your editor, not a failed run. The try pane is what catches it.
26
43
  type Source = { tag: string; risk: string; kind: string };
27
44
 
28
- return (records as Source[]).map((r) => ({
29
- assetId: r.tag,
30
- riskScore: Number(r.risk),
31
- vehicleTypeName: r.kind.toUpperCase(),
32
- critical: Number(r.risk) >= 80,
33
- }));`,
34
- javascript: `// \`records\` is the batch the connector fetched.
35
- // Return the rows to store — the keys must be property names of the target type.
36
- return records.map((r) => ({
37
- assetId: r.tag,
38
- riskScore: Number(r.risk),
39
- vehicleTypeName: String(r.kind).toUpperCase(),
40
- critical: Number(r.risk) >= 80,
41
- }));`,
45
+ const transform: CatalogTransformFunction<Source> = ({ records, context }) =>
46
+ records.map((r) => ({
47
+ assetId: r.tag,
48
+ riskScore: Number(r.risk),
49
+ vehicleTypeName: r.kind.toUpperCase(),
50
+ critical: Number(r.risk) >= 80,
51
+ }));
52
+
53
+ export default transform;`,
54
+ javascript: `// One object in, the rows to store out. \`records\` is the batch the connector
55
+ // fetched; \`context\` carries the run, the counts and the admitted env vars.
56
+ // The keys you return must be property names of the target type.
57
+ export default function transform({ records, context }) {
58
+ return records.map((r) => ({
59
+ assetId: r.tag,
60
+ riskScore: Number(r.risk),
61
+ vehicleTypeName: String(r.kind).toUpperCase(),
62
+ critical: Number(r.risk) >= 80,
63
+ }));
64
+ }`,
42
65
  python: `# \`records\` is the batch the connector fetched.
43
66
  # Return the rows to store — the keys must be property names of the target type.
44
67
  log("mapping", len(records), "records")
@@ -73,6 +96,32 @@ const SAMPLE = `[
73
96
  function TryOutput({ result, error }) {
74
97
  return (_jsxs("div", { className: "max-h-64 overflow-auto p-3", children: [error ? (_jsx("p", { className: "font-mono text-[11px] leading-relaxed text-red-600", children: error instanceof Error ? error.message : 'It failed.' })) : null, result && (_jsxs(_Fragment, { children: [result.logs.length > 0 && (_jsx("pre", { className: cn('mb-2 whitespace-pre-wrap font-mono text-[10px]', MUTED), children: result.logs.join('\n') })), result.rows.length === 0 ? (_jsx("p", { className: "text-[11px] text-amber-600", children: "It ran and returned no rows. A connector using this would commit an empty snapshot." })) : (_jsx("pre", { className: "whitespace-pre-wrap font-mono text-[11px]", children: JSON.stringify(result.rows, null, 2) })), _jsxs("p", { className: cn('mt-2 font-mono text-[10px]', MUTED), children: [result.rows.length, " rows \u00B7 ", result.elapsedMs, "ms"] })] })), !result && !error && (_jsx("p", { className: cn('py-4 text-center text-[11px]', MUTED), children: "Run it to see what it produces." }))] }));
75
98
  }
99
+ /**
100
+ * Which shape the runner will read this code as, decided by the runner's own
101
+ * rule.
102
+ *
103
+ * `transformShape` is imported from the library rather than re-derived here, and
104
+ * that is the entire point of the control. A badge that reasoned about the code
105
+ * independently would be a second opinion, and the day the two disagreed the
106
+ * badge would be reassuring somebody about a run that did the other thing.
107
+ *
108
+ * Shown at all because the two shapes are otherwise invisible: the editor is a
109
+ * text box, and "this ran as a bare body" is something an author currently only
110
+ * learns from a syntax error. Neither shape is marked as wrong — the bare body
111
+ * is supported, not deprecated — so this states a fact and stays out of the way.
112
+ *
113
+ * Not shown for Python, which has one shape and no rule: its harness writes the
114
+ * `def` itself, so there is nothing here for an author to have got wrong.
115
+ */
116
+ function ShapeBadge({ language, code }) {
117
+ if (language === 'python')
118
+ return null;
119
+ const shape = transformShape(code);
120
+ const isModule = shape === 'module';
121
+ return (_jsx(Tooltip, { content: isModule
122
+ ? 'A top-level `export`, so this is imported as a module and its default export (or an export named `transform`) is called with one object: { records, context }. Fields can be added to that object later without changing this signature.'
123
+ : 'No top-level `export`, so this runs as the body of a function that already has `records` and `context` in scope. Supported and unchanged — `export default function transform({ records, context })` is the shape that can gain fields later.', children: _jsx("span", { className: cn('cursor-default rounded border px-1.5 py-0.5 font-mono text-[10px] uppercase tracking-[0.14em]', RULE, MUTED), children: isModule ? 'function' : 'bare body' }) }));
124
+ }
76
125
  /**
77
126
  * Save, and what saving will do.
78
127
  *
@@ -142,7 +191,7 @@ export function TransformEditor({ transform, languages, pythonPackages = [], onC
142
191
  }, options: languages.map((option) => ({
143
192
  value: option,
144
193
  label: option,
145
- })) })] }), _jsxs("div", { className: "grid gap-3 lg:grid-cols-2", children: [_jsxs("div", { className: cn('overflow-hidden rounded-lg border', RULE, PANEL), children: [_jsxs("div", { className: cn('flex items-center justify-between border-b px-3 py-1.5', RULE), children: [_jsx("span", { className: cn('font-mono text-[10px] uppercase tracking-[0.14em]', MUTED), children: "Code" }), _jsx("span", { className: cn('font-mono text-[10px]', MUTED), children: language === 'python' && pythonPackages.length > 0
194
+ })) })] }), _jsxs("div", { className: "grid gap-3 lg:grid-cols-2", children: [_jsxs("div", { className: cn('overflow-hidden rounded-lg border', RULE, PANEL), children: [_jsxs("div", { className: cn('flex items-center justify-between border-b px-3 py-1.5', RULE), children: [_jsxs("div", { className: "flex items-center gap-2", children: [_jsx("span", { className: cn('font-mono text-[10px] uppercase tracking-[0.14em]', MUTED), children: "Code" }), _jsx(ShapeBadge, { language: language, code: code })] }), _jsx("span", { className: cn('font-mono text-[10px]', MUTED), children: language === 'python' && pythonPackages.length > 0
146
195
  ? `imports: ${pythonPackages.join(', ')}`
147
196
  : '⌘↵ to try' })] }), _jsx(CodeEditor, { value: code, onChange: setCode, onKeyDown: onKeyDown,
148
197
  // A table rather than the `language === 'python' ? 'python' : 'tsx'`
@@ -7,7 +7,7 @@ import { Background, BackgroundVariant, ConnectionLineType, Controls, MiniMap, P
7
7
  // See src/styles.d.ts for why `tsc` tolerates this import.
8
8
  import '@xyflow/react/dist/style.css';
9
9
  import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
10
- import { ArrowRight, ChevronDown, CircleAlert, CircleDashed, Code2, Database, ExternalLink, Filter, GitBranch, Info, LayoutGrid, Loader2, Maximize2, Minimize2, PanelRight, Plug, Plus, Repeat, Save, Trash2, TriangleAlert, Unplug, X, } from 'lucide-react';
10
+ import { ArrowRight, ChevronDown, CircleAlert, CircleDashed, Code2, Database, ExternalLink, Filter, GitBranch, Info, LayoutGrid, Loader2, Maximize2, Minimize2, PanelRight, Plug, Plus, Repeat, Save, TextCursorInput, Trash2, TriangleAlert, Unplug, X, } from 'lucide-react';
11
11
  import { AnimatePresence, motion, useReducedMotion } from 'motion/react';
12
12
  import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
13
13
  import { connectionOptionsFor } from './ConnectionPanel';
@@ -32,7 +32,7 @@ import { defaultLabel, describeFilterPredicate, flowingEdgeIds, layout, layoutIf
32
32
  import { HistoryControls, keepKnown, namesOf, nodeEditAction, reverted, snapshotOf, undone, useUndoShortcut, useUnsavedGuard, withEdit, } from './workflow/history';
33
33
  import { PublishControls, RunControls, SchedulePanel, ShrinkRefusalNote, WorkflowStatusBadge, } from './workflow/lifecycle';
34
34
  import { CanvasContextMenu, NodeActionsToolbar } from './workflow/menu';
35
- import { WORKFLOW_BRANCH_LABELS, WORKFLOW_CALL_MODES, WORKFLOW_FILTER_MAX_DEPTH, WORKFLOW_FILTER_MAX_VALUES, WORKFLOW_FILTER_OPERATORS, WORKFLOW_NODE_KINDS, callableWorkflowBlock, describeDurability, isWorkflowBranchLabel, isWorkflowFilterOperator, isWorkflowFilterPredicateKind, isWorkflowNodeKind, isWorkflowPredicateKind, newLocalId, nodeName, producedTypes, unreachableFilterPredicateKind, unreachableNodeKind, unreachablePredicateKind, workflowCallMode, workflowNarrowedTypes, } from './workflow/model';
35
+ import { WORKFLOW_BRANCH_LABELS, WORKFLOW_CALL_MODES, WORKFLOW_FILTER_MAX_DEPTH, WORKFLOW_FILTER_MAX_VALUES, WORKFLOW_FILTER_OPERATORS, WORKFLOW_NODE_KINDS, WORKFLOW_RENAME_MAX_COLUMNS, callableWorkflowBlock, describeDurability, isWorkflowBranchLabel, isWorkflowFilterOperator, isWorkflowFilterPredicateKind, isWorkflowNodeKind, isWorkflowPredicateKind, isWorkflowRenameUnnamed, newLocalId, nodeName, producedTypes, renameColumnRefusals, unreachableFilterPredicateKind, unreachableNodeKind, unreachablePredicateKind, workflowCallMode, workflowKnownColumns, workflowNarrowedTypes, workflowRenameUnnamed, } from './workflow/model';
36
36
  import { WORKFLOW_NAME } from './workflow/name';
37
37
  import { WorkflowNodeProvider, workflowNodeTypes } from './workflow/nodes';
38
38
  import { freeSpot, placeNextTo } from './workflow/place';
@@ -460,6 +460,11 @@ const ADD_NODE = {
460
460
  label: 'Filter',
461
461
  hint: 'Drops the rows that fail a test you write here. Unlike an If, every box still runs — there are simply fewer rows in them from this point on.',
462
462
  },
463
+ rename: {
464
+ icon: TextCursorInput,
465
+ label: 'Rename',
466
+ hint: 'Renames columns, and nothing else. No code, no child process — a pure rename rewrites the staged column list and leaves every row exactly where it is. It can also drop the columns you do not name, which does cost a pass over the rows.',
467
+ },
463
468
  };
464
469
  /**
465
470
  * The value the workflow picker uses for "start a fresh one".
@@ -873,6 +878,11 @@ function miniMapColor(data) {
873
878
  // that answer that question in completely different ways.
874
879
  if (kind === 'filter')
875
880
  return '#f43f5e';
881
+ // Teal-500, the rename's own accent. Deliberately not the violet a transform
882
+ // gets: a rename is the node that is *provably* cheap, and an overview where
883
+ // it reads as another piece of user code hides the one thing worth seeing.
884
+ if (kind === 'rename')
885
+ return '#14b8a6';
876
886
  return '#8b5cf6';
877
887
  }
878
888
  /**
@@ -3384,6 +3394,62 @@ function RowCountPredicateFields({ predicate, canEdit, onChange, }) {
3384
3394
  * question is live — offering them on a filter that narrows nothing would train
3385
3395
  * people to flip them.
3386
3396
  */
3397
+ /**
3398
+ * The rename node's form: a list of columns, and one decision about the rest.
3399
+ *
3400
+ * ## Why the list is local state and the record is not
3401
+ *
3402
+ * The model is a `Record<string, string>`, which is the right shape to store —
3403
+ * a key cannot appear twice, so "two renames of the same source column" is
3404
+ * unrepresentable rather than merely refused. It is the wrong shape to *edit*:
3405
+ * a half-typed key is a key, and rebuilding the record on every keystroke would
3406
+ * collapse two rows the moment they were briefly equal — most obviously the two
3407
+ * blank rows you get by pressing "Add column" twice.
3408
+ *
3409
+ * So the rows are held here, in order, and the record is derived from them. The
3410
+ * one thing that can diverge is two rows naming the same source column, and
3411
+ * that is said out loud below rather than silently resolved.
3412
+ *
3413
+ * ## What the panel can tell somebody that a transform's could not
3414
+ *
3415
+ * Which columns actually reach this node — sometimes. `workflowKnownColumns` is
3416
+ * exact downstream of a rename that drops what it does not name, unknown
3417
+ * everywhere else, and the difference is stated rather than papered over. This
3418
+ * is the whole payoff of the node being data instead of code, so the panel
3419
+ * should say it in as many words.
3420
+ */
3421
+ function RenameInspector({ node, graph, canEdit, onChange, }) {
3422
+ const map = node.columns ?? {};
3423
+ const [rows, setRows] = useState(() => {
3424
+ const entries = Object.entries(map).map(([from, to]) => ({ from, to }));
3425
+ return entries.length > 0 ? entries : [{ from: '', to: '' }];
3426
+ });
3427
+ const commit = (next) => {
3428
+ setRows(next);
3429
+ const columns = {};
3430
+ for (const row of next)
3431
+ columns[row.from] = row.to;
3432
+ onChange({ ...node, columns });
3433
+ };
3434
+ const setUnnamed = (value) => {
3435
+ if (!isWorkflowRenameUnnamed(value))
3436
+ return;
3437
+ // Stored absent for `keep`, so the default has one spelling and picking up
3438
+ // this release cannot renumber a graph nobody edited. The boundary
3439
+ // normalises the same way.
3440
+ onChange({ ...node, unnamed: value === 'drop' ? 'drop' : undefined });
3441
+ };
3442
+ const dropping = workflowRenameUnnamed(node) === 'drop';
3443
+ const known = workflowKnownColumns(graph, node.id);
3444
+ const refusals = renameColumnRefusals(map);
3445
+ const duplicated = rows
3446
+ .map((row) => row.from)
3447
+ .filter((from, at, all) => from.length > 0 && all.indexOf(from) !== at);
3448
+ return (_jsxs("div", { className: "space-y-3", children: [_jsxs(FieldGroup, { title: "Columns", hint: _jsxs(_Fragment, { children: ["The name the records arrive with, and the name they leave with. The old name is whatever the source actually calls it \u2014 ", _jsx("code", { children: "Mgmt Cd" }), " and ", _jsx("code", { children: "VEH Type Name" }), " are fine. The new one has to be a name a column can have: letters, digits and underscore, starting with a letter or an underscore."] }), children: [rows.map((row, index) => (_jsxs("div", { className: "flex items-end gap-2", children: [_jsx("div", { className: "min-w-0 flex-1", children: _jsx(TextField, { label: index === 0 ? 'In the source' : '', value: row.from, placeholder: "Mgmt Cd", disabled: !canEdit, onChange: (from) => commit(rows.map((each, at) => (at === index ? { ...each, from } : each))) }) }), _jsx("div", { className: "min-w-0 flex-1", children: _jsx(TextField, { label: index === 0 ? 'Becomes' : '', value: row.to, placeholder: "mgmtCd", disabled: !canEdit, onChange: (to) => commit(rows.map((each, at) => (at === index ? { ...each, to } : each))) }) }), canEdit && rows.length > 1 && (_jsx(Button, { variant: "ghost", size: "sm", className: "shrink-0", onClick: () => commit(rows.filter((_, at) => at !== index)), children: "Remove" }))] }, index))), canEdit && (_jsx(Button, { variant: "outline", size: "sm", onClick: () => commit([...rows, { from: '', to: '' }]), disabled: rows.length >= WORKFLOW_RENAME_MAX_COLUMNS, children: "Add column" }))] }), _jsx(SelectField, { label: "Columns you did not name", ariaLabel: "What happens to the columns this node does not rename", value: workflowRenameUnnamed(node), onValueChange: setUnnamed, disabled: !canEdit, options: [
3449
+ { value: 'keep', label: 'Pass through unchanged', hint: 'no data moves' },
3450
+ { value: 'drop', label: 'Drop them', hint: 'rebuilds every row' },
3451
+ ] }), _jsx("p", { className: cn('text-[11px] leading-relaxed', MUTED), children: dropping ? (_jsxs(_Fragment, { children: ["This node ", _jsx("strong", { children: "also removes" }), " every column it does not name, so what reaches the sink is exactly the ", Object.keys(map).length, " new name", Object.keys(map).length === 1 ? '' : 's', " above. That is a projection as well as a rename, and it costs a pass over the rows \u2014 a staged batch keeps its values in positional arrays, and taking a column out moves every one of them."] })) : (_jsxs(_Fragment, { children: ["Nothing else changes. A staged batch names its columns once and keeps the values in positional arrays, so renaming one rewrites a handful of strings and", ' ', _jsx("strong", { children: "moves no data at all" }), " \u2014 which is why this is a node rather than four lines of JavaScript in a transform."] })) }), refusals.length > 0 && (_jsx("p", { className: "text-[11px] leading-relaxed text-amber-600 dark:text-amber-400", children: refusals.join(' ') })), duplicated.length > 0 && (_jsxs("p", { className: "text-[11px] leading-relaxed text-amber-600 dark:text-amber-400", children: [duplicated.map((from) => `“${from}”`).join(', '), " appears more than once on the left. A column can only be renamed to one thing, so only the last row naming it is stored."] })), known ? (_jsxs("p", { className: cn('text-[11px] leading-relaxed', MUTED), children: ["A rename above this node drops the columns it does not name, so the graph knows exactly what arrives here:", ' ', _jsx("span", { className: "font-mono", children: [...known].join(', ') || 'nothing at all' }), ". A row on the left naming anything else is refused when this graph is saved, rather than found out when the column comes back empty."] })) : (_jsx("p", { className: cn('text-[11px] leading-relaxed', MUTED), children: "The graph cannot say which columns reach this node \u2014 a source discovers its shape against the live system, and a transform is code. So the old names are taken on trust, and the run says out loud if one of them was in no row." }))] }));
3452
+ }
3387
3453
  function FilterInspector({ node, graph, canEdit, onChange, }) {
3388
3454
  // Core's answer, not this file's. A canvas that worked out its own set would
3389
3455
  // offer acknowledgements the server then refuses, which is a person ticking a
@@ -3715,6 +3781,13 @@ function KindInspector({ node, graph, transforms, connections, typeOptions, canE
3715
3781
  // `WorkflowFilterNode.narrows`.
3716
3782
  return (_jsx(FilterInspector, { node: node, graph: graph, canEdit: canEdit, onChange: onChange }, node.id));
3717
3783
  }
3784
+ if (node.kind === 'rename') {
3785
+ // Given the whole graph for the same reason the filter inspector is, and
3786
+ // with a different question in mind: the one thing a declarative rename
3787
+ // buys is that the graph can sometimes say exactly which columns reach this
3788
+ // node. See `workflowKnownColumns`.
3789
+ return (_jsx(RenameInspector, { node: node, graph: graph, canEdit: canEdit, onChange: onChange }, node.id));
3790
+ }
3718
3791
  if (node.kind === 'sink') {
3719
3792
  return (_jsx(SinkInspector, { node: node, typeOptions: typeOptions, canEdit: canEdit, modelHref: modelHref, onChange: onChange }));
3720
3793
  }
@@ -76,6 +76,21 @@ export function newNodeOfKind(kind, id, position, name) {
76
76
  position,
77
77
  };
78
78
  }
79
+ if (kind === 'rename') {
80
+ // One entry with both halves blank, and the validator refuses it by name
81
+ // from the moment the node is dropped — the same stance `filter` takes and
82
+ // for the same reason. An empty map is representable and is exactly the
83
+ // dangerous state: with unnamed columns kept it is a node that draws as
84
+ // finished and does nothing, and with them dropped it deletes every column
85
+ // of every row. So the node starts visibly incomplete rather than
86
+ // invisibly inert.
87
+ //
88
+ // `unnamed` is left absent, which means keep. A rename that started by
89
+ // dropping everything it does not name would be a projection wearing the
90
+ // word "rename", and somebody would find that out by looking at a committed
91
+ // snapshot.
92
+ return { id, name, kind: 'rename', columns: { '': '' }, position };
93
+ }
79
94
  if (kind === 'sink') {
80
95
  return { id, name, kind: 'sink', targetType: '', position };
81
96
  }
@@ -1,6 +1,6 @@
1
1
  import { WORKFLOW_NODE_HEIGHT, WORKFLOW_NODE_WIDTH, workflowColumnX, workflowRowY, workflowRunOrder, } from '@dudousxd/nestjs-catalog/client';
2
2
  import { MarkerType } from '@xyflow/react';
3
- import { nodeName, unreachableFilterPredicateKind, unreachableNodeKind, unreachablePredicateKind, workflowCallMode, } from './model';
3
+ import { nodeName, unreachableFilterPredicateKind, unreachableNodeKind, unreachablePredicateKind, workflowCallMode, workflowRenameUnnamed, } from './model';
4
4
  import { edgeId } from './validate';
5
5
  /**
6
6
  * Turning the stored graph into what React Flow draws, and back.
@@ -52,6 +52,8 @@ function subtitleFor(node, describe) {
52
52
  return ifSubtitle(node);
53
53
  if (node.kind === 'filter')
54
54
  return filterSubtitle(node);
55
+ if (node.kind === 'rename')
56
+ return renameSubtitle(node);
55
57
  if (node.kind === 'transform') {
56
58
  return describe.transformName(node.transformId) ?? 'no transform chosen';
57
59
  }
@@ -92,6 +94,28 @@ function filterSubtitle(node) {
92
94
  return `keeps rows matching ${leaves} conditions`;
93
95
  return `keeps ${describeFilterPredicate(predicate)}`;
94
96
  }
97
+ /**
98
+ * A rename's face: how many columns, and whether anything else survives.
99
+ *
100
+ * The disposition is on the face rather than only in the inspector because it is
101
+ * the difference between a node that renames and a node that also *deletes* —
102
+ * and a graph where those two look identical is one where a column disappears
103
+ * from a published type with nothing on the canvas to point at.
104
+ *
105
+ * One rename is spelled out, because the overwhelmingly common node has one or
106
+ * two entries and `Mgmt Cd -> mgmtCd` is the whole content of it.
107
+ */
108
+ function renameSubtitle(node) {
109
+ const entries = Object.entries(node.columns ?? {}).filter(([from, to]) => from.length > 0 && to.length > 0);
110
+ const dropped = workflowRenameUnnamed(node) === 'drop';
111
+ if (entries.length === 0)
112
+ return 'no columns named';
113
+ const first = entries[0];
114
+ const what = entries.length === 1 && first
115
+ ? `${first[0]} \u2192 ${first[1]}`
116
+ : `renames ${entries.length} columns`;
117
+ return dropped ? `${what}, drops the rest` : what;
118
+ }
95
119
  /** How many comparisons a predicate is made of, groups not counted. */
96
120
  function countFilterLeaves(predicate) {
97
121
  if (predicate.kind === 'all' || predicate.kind === 'any') {
@@ -335,6 +359,8 @@ export function defaultLabel(kind) {
335
359
  return 'If';
336
360
  if (kind === 'filter')
337
361
  return 'Filter';
362
+ if (kind === 'rename')
363
+ return 'Rename';
338
364
  if (kind === 'transform')
339
365
  return 'Transform';
340
366
  return unreachableNodeKind(kind, 'defaultLabel');
@@ -18,8 +18,8 @@
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 { CallableWorkflowBlock, CallableWorkflowDisagreement, CallableWorkflowRef, CatalogWorkflow, CatalogWorkflowRelease, WorkflowBranchLabel, WorkflowEdge, WorkflowCallMode, WorkflowCallNode, WorkflowEnvPredicate, WorkflowFilterAll, WorkflowFilterAny, WorkflowFilterComparison, WorkflowFilterGroup, WorkflowFilterNode, WorkflowFilterOneOf, WorkflowFilterOperator, WorkflowFilterPredicate, WorkflowFilterPredicateKind, WorkflowFilterPresence, WorkflowFilterValue, WorkflowGraph, WorkflowIfNode, WorkflowIfPredicate, WorkflowNode, WorkflowNodeKind, WorkflowPredicateKind, WorkflowRowCountPredicate, WorkflowSinkNode, WorkflowSkipReason, WorkflowSourceNode, WorkflowTransformNode, } from '@dudousxd/nestjs-catalog/client';
22
- export { callableWorkflowBlock, isWorkflowBranchLabel, isWorkflowFilterOperator, isWorkflowFilterPredicate, isWorkflowFilterPredicateKind, isWorkflowFilterValue, isWorkflowNodeKind, isWorkflowPredicateKind, WORKFLOW_CALL_MODES, unreachableCallMode, workflowCallMode, unreachableFilterOperator, unreachableFilterPredicateKind, unreachableNodeKind, unreachablePredicateKind, workflowNarrowedTypes, WORKFLOW_BRANCH_LABELS, WORKFLOW_FILTER_COLUMN_PATTERN, WORKFLOW_FILTER_MAX_DEPTH, WORKFLOW_FILTER_MAX_VALUES, WORKFLOW_FILTER_OPERATORS, WORKFLOW_FILTER_PREDICATE_KINDS, WORKFLOW_PREDICATE_KINDS, WORKFLOW_NODE_ID_PATTERN, WORKFLOW_NODE_KINDS, } from '@dudousxd/nestjs-catalog/client';
21
+ export type { CallableWorkflowBlock, CallableWorkflowDisagreement, CallableWorkflowRef, CatalogWorkflow, CatalogWorkflowRelease, WorkflowBranchLabel, WorkflowEdge, WorkflowCallMode, WorkflowCallNode, WorkflowEnvPredicate, WorkflowFilterAll, WorkflowFilterAny, WorkflowFilterComparison, WorkflowFilterGroup, WorkflowFilterNode, WorkflowFilterOneOf, WorkflowFilterOperator, WorkflowFilterPredicate, WorkflowFilterPredicateKind, WorkflowFilterPresence, WorkflowFilterValue, WorkflowGraph, WorkflowIfNode, WorkflowIfPredicate, WorkflowNode, WorkflowNodeKind, WorkflowPredicateKind, WorkflowRenameNode, WorkflowRenameUnnamed, WorkflowRowCountPredicate, WorkflowSinkNode, WorkflowSkipReason, WorkflowSourceNode, WorkflowTransformNode, } from '@dudousxd/nestjs-catalog/client';
22
+ export { callableWorkflowBlock, isWorkflowBranchLabel, isWorkflowFilterOperator, isWorkflowFilterPredicate, isWorkflowFilterPredicateKind, isWorkflowFilterValue, isWorkflowNodeKind, isWorkflowPredicateKind, isWorkflowRenameUnnamed, renameColumnRefusals, workflowKnownColumns, workflowRenameUnnamed, WORKFLOW_CALL_MODES, unreachableCallMode, workflowCallMode, unreachableFilterOperator, unreachableFilterPredicateKind, unreachableNodeKind, unreachablePredicateKind, unreachableRenameUnnamed, workflowNarrowedTypes, WORKFLOW_BRANCH_LABELS, WORKFLOW_FILTER_COLUMN_PATTERN, WORKFLOW_FILTER_MAX_DEPTH, WORKFLOW_FILTER_MAX_VALUES, WORKFLOW_FILTER_OPERATORS, WORKFLOW_FILTER_PREDICATE_KINDS, WORKFLOW_PREDICATE_KINDS, WORKFLOW_RENAME_MAX_COLUMNS, WORKFLOW_RENAME_UNNAMED, WORKFLOW_NODE_ID_PATTERN, WORKFLOW_NODE_KINDS, } from '@dudousxd/nestjs-catalog/client';
23
23
  import { type WorkflowBranchLabel, type WorkflowNode, type WorkflowSkipReason } from '@dudousxd/nestjs-catalog/client';
24
24
  /**
25
25
  * What a caller may set.
@@ -23,19 +23,25 @@ export {
23
23
  // not a copy: the picker greys an entry out and the server reasons about the
24
24
  // same list, and two copies of that rule is a picker that eventually offers
25
25
  // something the rest of the system will not accept.
26
- callableWorkflowBlock, isWorkflowBranchLabel, isWorkflowFilterOperator, isWorkflowFilterPredicate, isWorkflowFilterPredicateKind, isWorkflowFilterValue, isWorkflowNodeKind, isWorkflowPredicateKind,
26
+ callableWorkflowBlock, isWorkflowBranchLabel, isWorkflowFilterOperator, isWorkflowFilterPredicate, isWorkflowFilterPredicateKind, isWorkflowFilterValue, isWorkflowNodeKind, isWorkflowPredicateKind, isWorkflowRenameUnnamed,
27
+ // The rename rules, core's for the reason every rule here is core's: a form
28
+ // that checked a target name against its own copy of the identifier pattern
29
+ // would accept a name the server refuses, after Save — and `workflowKnownColumns`
30
+ // is what lets the inspector say which columns actually reach a node instead of
31
+ // guessing.
32
+ renameColumnRefusals, workflowKnownColumns, workflowRenameUnnamed,
27
33
  // The two wire formats a call node can be authored in, plus the reader that
28
34
  // applies the default. Core's, not a copy, for the reason every rule here is:
29
35
  // an inspector offering a mode the runner cannot build a payload for is a
30
36
  // graph somebody saves and a child run that fails, and a screen carrying its
31
37
  // own `?? 'envelope'` would eventually disagree with `workflowGraphHash` and
32
38
  // show unsaved changes on a graph nobody edited.
33
- WORKFLOW_CALL_MODES, unreachableCallMode, workflowCallMode, unreachableFilterOperator, unreachableFilterPredicateKind, unreachableNodeKind, unreachablePredicateKind,
39
+ WORKFLOW_CALL_MODES, unreachableCallMode, workflowCallMode, unreachableFilterOperator, unreachableFilterPredicateKind, unreachableNodeKind, unreachablePredicateKind, unreachableRenameUnnamed,
34
40
  // Core's, not a copy, for the reason every other rule here is core's: the
35
41
  // inspector has to offer exactly the acknowledgements `validateWorkflow`
36
42
  // requires, and a screen that worked out its own list would offer a set the
37
43
  // server then refuses — with the person having ticked a box to be told no.
38
- workflowNarrowedTypes, WORKFLOW_BRANCH_LABELS, WORKFLOW_FILTER_COLUMN_PATTERN, WORKFLOW_FILTER_MAX_DEPTH, WORKFLOW_FILTER_MAX_VALUES, WORKFLOW_FILTER_OPERATORS, WORKFLOW_FILTER_PREDICATE_KINDS, WORKFLOW_PREDICATE_KINDS, WORKFLOW_NODE_ID_PATTERN, WORKFLOW_NODE_KINDS, } from '@dudousxd/nestjs-catalog/client';
44
+ workflowNarrowedTypes, WORKFLOW_BRANCH_LABELS, WORKFLOW_FILTER_COLUMN_PATTERN, WORKFLOW_FILTER_MAX_DEPTH, WORKFLOW_FILTER_MAX_VALUES, WORKFLOW_FILTER_OPERATORS, WORKFLOW_FILTER_PREDICATE_KINDS, WORKFLOW_PREDICATE_KINDS, WORKFLOW_RENAME_MAX_COLUMNS, WORKFLOW_RENAME_UNNAMED, WORKFLOW_NODE_ID_PATTERN, WORKFLOW_NODE_KINDS, } from '@dudousxd/nestjs-catalog/client';
39
45
  import { WORKFLOW_NODE_ID_PATTERN, } from '@dudousxd/nestjs-catalog/client';
40
46
  export function describeDurability(durability) {
41
47
  if (!durability) {
@@ -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, CircleSlash, Code2, Database, ExternalLink, Filter, GitBranch, Loader2, Plug, Repeat, TriangleAlert, } from 'lucide-react';
3
+ import { CircleAlert, CircleCheck, CircleSlash, Code2, Database, ExternalLink, Filter, GitBranch, Loader2, Plug, Repeat, TextCursorInput, TriangleAlert, } from 'lucide-react';
4
4
  import { motion, useReducedMotion } from 'motion/react';
5
5
  import { createContext, useContext, } from 'react';
6
6
  import { cn } from '../cn';
@@ -97,6 +97,19 @@ const KIND_STYLE = {
97
97
  icon: Filter,
98
98
  noun: 'filter',
99
99
  },
100
+ // Teal and a label-shaped mark. A rename is the one node that changes neither
101
+ // which rows exist nor which boxes run — it changes what the columns are
102
+ // *called* — so it deliberately shares nothing with the two subtraction
103
+ // colours beside it. It also has to be told apart from a transform at a
104
+ // glance, because the whole reason it is not one is that it is cheap and
105
+ // provable, and a canvas where the two read alike hides exactly that.
106
+ rename: {
107
+ accent: 'bg-gradient-to-b from-teal-400 to-teal-600',
108
+ chip: 'text-teal-700 dark:text-teal-300',
109
+ wash: 'bg-teal-50/70 dark:bg-teal-950/30',
110
+ icon: TextCursorInput,
111
+ noun: 'rename',
112
+ },
100
113
  };
101
114
  /**
102
115
  * Handles are styled larger than React Flow's default 6px dot.
@@ -87,6 +87,15 @@ const NODE_FACTORIES = {
87
87
  // impossible: the template would be shipping a graph that shrinks a published
88
88
  // type, with nobody having chosen it.
89
89
  filter: (id, name, init) => ({ id, name, kind: 'filter', ...init }),
90
+ // `rename` arrived fourth, and the map stopped the build a fourth time.
91
+ //
92
+ // Unused by every template below for the same reason `filter` is, one step
93
+ // sharper: a rename map is a list of one source system's own spellings of its
94
+ // own headers. `Mgmt Cd` is a fact about one Air Force fleet export and about
95
+ // nothing else, so a template that prefilled one would be renaming columns
96
+ // that do not exist in whatever the reader wired up — and the symptom of that
97
+ // is not an error, it is a target column absent from every row.
98
+ rename: (id, name, init) => ({ id, name, kind: 'rename', ...init }),
90
99
  };
91
100
  /* -------------------------------------------------------------------------- */
92
101
  /* Starter transform code */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dudousxd/nestjs-catalog-react",
3
- "version": "0.25.1",
3
+ "version": "0.27.0",
4
4
  "description": "Ready-made React screens for @dudousxd/nestjs-catalog — a model manager and a generic object explorer you can drop into your own app shell.",
5
5
  "license": "MIT",
6
6
  "author": "Davide Carvalho",
@@ -110,7 +110,7 @@
110
110
  "tailwind-merge": "3.4.1",
111
111
  "tiptap-markdown": "0.9.0",
112
112
  "typescript": "5.9.3",
113
- "@dudousxd/nestjs-catalog": "0.21.0"
113
+ "@dudousxd/nestjs-catalog": "0.23.0"
114
114
  },
115
115
  "dependencies": {
116
116
  "clsx": "2.1.1",