@dudousxd/nestjs-catalog-react 0.17.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.
@@ -1,4 +1,5 @@
1
1
  import { type WorkflowEdge, type WorkflowIssueCode, type WorkflowNode } from '@dudousxd/nestjs-catalog/client';
2
+ import { type ShapeKnowledge } from './shape';
2
3
  /**
3
4
  * What is wrong with a graph, checked in the browser while it is being drawn.
4
5
  *
@@ -22,6 +23,13 @@ import { type WorkflowEdge, type WorkflowIssueCode, type WorkflowNode } from '@d
22
23
  * - **A sink with no object type.** Core's type requires `targetType` on a sink
23
24
  * but its validator never checks that the string is non-empty, and the server
24
25
  * refuses one that is. The check is additive, not contradictory.
26
+ * - **Whether a source's columns fit the type its sink writes.** Core validates
27
+ * topology, and topology cannot see a column: a sink wired to a source that
28
+ * supplies none of its fields is a perfectly well-formed graph. Answering it
29
+ * needs two things core has no access to — what discovery said the source
30
+ * reads, and what the catalog says the type is made of — so it lives in
31
+ * `shape.ts` and runs only when a caller supplies both. See that file's
32
+ * header for why the answer has three values and not two.
25
33
  *
26
34
  * Two sinks writing the same type is NOT in that list: core reports it itself,
27
35
  * as `duplicate-sink-type`, and is passed straight through.
@@ -38,7 +46,7 @@ export type WorkflowProblemLevel = 'error' | 'warning';
38
46
  * Core's are re-used verbatim rather than remapped so that a caller — or a test
39
47
  * — matching on a code matches the same string the server would have sent back.
40
48
  */
41
- export type WorkflowProblemCode = WorkflowIssueCode | 'missing-transform' | 'sink-has-no-type' | 'duplicate-sink-type';
49
+ export type WorkflowProblemCode = WorkflowIssueCode | 'missing-transform' | 'sink-has-no-type' | 'duplicate-sink-type' | 'shape-source-spelling' | 'shape-missing-column' | 'shape-unproven' | 'shape-not-checked';
42
50
  export interface WorkflowProblem {
43
51
  level: WorkflowProblemLevel;
44
52
  code: WorkflowProblemCode;
@@ -59,6 +67,17 @@ export interface ValidateOptions {
59
67
  * the list is passed in rather than assumed complete.
60
68
  */
61
69
  transformIds: ReadonlySet<string>;
70
+ /**
71
+ * What each source reads and what each type is made of, when the caller can
72
+ * say. Absent means the column checks in `shape.ts` do not run at all.
73
+ *
74
+ * Optional rather than required, and absent rather than empty: a caller with
75
+ * no discovery to offer has not learned that every graph is fine, it has not
76
+ * asked. An empty implementation would report the same silence while looking
77
+ * like an answer, which is the distinction this whole pair of modules is
78
+ * about.
79
+ */
80
+ shapes?: ShapeKnowledge;
62
81
  }
63
82
  /**
64
83
  * The identity React Flow needs, derived rather than stored.
@@ -1,6 +1,7 @@
1
1
  import { validateWorkflow as validateCoreWorkflow, } from '@dudousxd/nestjs-catalog/client';
2
2
  import { nodeName } from './model';
3
3
  import { WORKFLOW_NAME } from './name';
4
+ import { checkShapes } from './shape';
4
5
  /**
5
6
  * Core issues this canvas deliberately does not show, and the only place the two
6
7
  * validators disagree.
@@ -27,11 +28,25 @@ import { WORKFLOW_NAME } from './name';
27
28
  * that hides one of the server's answers is a screen that will eventually
28
29
  * promise a save the server refuses.
29
30
  */
30
- /** The wires an issue is really about, since core names nodes and not edges. */
31
+ /**
32
+ * The wires an issue is really about, since core names nodes and not edges.
33
+ *
34
+ * The two shape errors are here as well as core's three, because "this source
35
+ * does not supply that sink's columns" is a statement about the wire between
36
+ * them and the canvas should draw it that way. The two shape *warnings* are
37
+ * deliberately absent: a red wire is error styling, and the whole point of the
38
+ * third outcome is that it does not wear it.
39
+ */
40
+ const EDGE_CODES = new Set([
41
+ 'cycle',
42
+ 'self-edge',
43
+ 'duplicate-edge',
44
+ 'shape-source-spelling',
45
+ 'shape-missing-column',
46
+ ]);
31
47
  function edgesFor(code, nodeIds, edges) {
32
- if (code !== 'cycle' && code !== 'self-edge' && code !== 'duplicate-edge') {
48
+ if (!EDGE_CODES.has(code))
33
49
  return [];
34
- }
35
50
  const named = new Set(nodeIds);
36
51
  return edges
37
52
  .filter((edge) => named.has(edge.from) && named.has(edge.to))
@@ -105,8 +120,31 @@ export function validateWorkflow(draft, options) {
105
120
  });
106
121
  }
107
122
  }
123
+ // Last, and only when a caller supplied the two halves it needs. The columns
124
+ // are a different question from the wiring — a graph can be structurally
125
+ // perfect and still write nulls into every row — so it is asked whatever the
126
+ // checks above said, for the same reason they are asked whatever core said.
127
+ problems.push(...shapeProblems(draft, options));
108
128
  return problems;
109
129
  }
130
+ /**
131
+ * The column checks, with their wires filled in the same way everything else's
132
+ * are.
133
+ *
134
+ * `shape.ts` returns no edge ids of its own on purpose: `edgesFor` above is the
135
+ * one derivation of a wire from the nodes an issue names, and a second copy
136
+ * inside the shape module is exactly the drift this file's header is about. Which
137
+ * codes get a wire is therefore decided in one place, and the warnings are not
138
+ * among them.
139
+ */
140
+ function shapeProblems(draft, options) {
141
+ if (!options.shapes)
142
+ return [];
143
+ return checkShapes(draft.nodes, draft.edges, options.shapes).map((problem) => ({
144
+ ...problem,
145
+ edgeIds: edgesFor(problem.code, problem.nodeIds, draft.edges),
146
+ }));
147
+ }
110
148
  /**
111
149
  * Would adding `from -> to` close a loop?
112
150
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dudousxd/nestjs-catalog-react",
3
- "version": "0.17.0",
3
+ "version": "0.18.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.14.0"
113
+ "@dudousxd/nestjs-catalog": "0.15.0"
114
114
  },
115
115
  "dependencies": {
116
116
  "clsx": "2.1.1",