@dudousxd/nestjs-catalog-react 0.1.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 (239) hide show
  1. package/LICENSE-bklit +21 -0
  2. package/README.md +282 -0
  3. package/dist/AccessConsole.d.ts +40 -0
  4. package/dist/AccessConsole.js +160 -0
  5. package/dist/CatalogManager.d.ts +12 -0
  6. package/dist/CatalogManager.js +123 -0
  7. package/dist/ConnectionPanel.d.ts +41 -0
  8. package/dist/ConnectionPanel.js +228 -0
  9. package/dist/CoverageLedger.d.ts +16 -0
  10. package/dist/CoverageLedger.js +16 -0
  11. package/dist/DashboardBoard.d.ts +10 -0
  12. package/dist/DashboardBoard.js +206 -0
  13. package/dist/EditableField.d.ts +18 -0
  14. package/dist/EditableField.js +61 -0
  15. package/dist/FlowView.d.ts +13 -0
  16. package/dist/FlowView.js +93 -0
  17. package/dist/GovernanceTimeline.d.ts +16 -0
  18. package/dist/GovernanceTimeline.js +93 -0
  19. package/dist/ObjectExplorer.d.ts +9 -0
  20. package/dist/ObjectExplorer.js +153 -0
  21. package/dist/PipelineConsole.d.ts +20 -0
  22. package/dist/PipelineConsole.js +272 -0
  23. package/dist/QueryConsole.d.ts +11 -0
  24. package/dist/QueryConsole.js +144 -0
  25. package/dist/SavedQueryPanel.d.ts +16 -0
  26. package/dist/SavedQueryPanel.js +78 -0
  27. package/dist/TraceExplorer.d.ts +54 -0
  28. package/dist/TraceExplorer.js +342 -0
  29. package/dist/TransformEditor.d.ts +23 -0
  30. package/dist/TransformEditor.js +129 -0
  31. package/dist/WorkflowCanvas.d.ts +24 -0
  32. package/dist/WorkflowCanvas.js +701 -0
  33. package/dist/charts/bklit/animation.d.ts +19 -0
  34. package/dist/charts/bklit/animation.js +28 -0
  35. package/dist/charts/bklit/area-chart-loading.d.ts +33 -0
  36. package/dist/charts/bklit/area-chart-loading.js +30 -0
  37. package/dist/charts/bklit/area-chart.d.ts +47 -0
  38. package/dist/charts/bklit/area-chart.js +65 -0
  39. package/dist/charts/bklit/area-gradient-defs.d.ts +28 -0
  40. package/dist/charts/bklit/area-gradient-defs.js +23 -0
  41. package/dist/charts/bklit/area.d.ts +75 -0
  42. package/dist/charts/bklit/area.js +112 -0
  43. package/dist/charts/bklit/bar-chart-loading.d.ts +16 -0
  44. package/dist/charts/bklit/bar-chart-loading.js +22 -0
  45. package/dist/charts/bklit/bar-chart.d.ts +54 -0
  46. package/dist/charts/bklit/bar-chart.js +440 -0
  47. package/dist/charts/bklit/bar-depth-geometry.d.ts +41 -0
  48. package/dist/charts/bklit/bar-depth-geometry.js +46 -0
  49. package/dist/charts/bklit/bar-squares-layout.d.ts +36 -0
  50. package/dist/charts/bklit/bar-squares-layout.js +46 -0
  51. package/dist/charts/bklit/bar-squares.d.ts +48 -0
  52. package/dist/charts/bklit/bar-squares.js +206 -0
  53. package/dist/charts/bklit/bar-x-axis.d.ts +13 -0
  54. package/dist/charts/bklit/bar-x-axis.js +81 -0
  55. package/dist/charts/bklit/bar-y-axis.d.ts +11 -0
  56. package/dist/charts/bklit/bar-y-axis.js +72 -0
  57. package/dist/charts/bklit/bar.d.ts +40 -0
  58. package/dist/charts/bklit/bar.js +207 -0
  59. package/dist/charts/bklit/chart-child-passthrough.d.ts +25 -0
  60. package/dist/charts/bklit/chart-child-passthrough.js +82 -0
  61. package/dist/charts/bklit/chart-config-context.d.ts +34 -0
  62. package/dist/charts/bklit/chart-config-context.js +55 -0
  63. package/dist/charts/bklit/chart-context.d.ts +207 -0
  64. package/dist/charts/bklit/chart-context.js +200 -0
  65. package/dist/charts/bklit/chart-defs.d.ts +21 -0
  66. package/dist/charts/bklit/chart-defs.js +57 -0
  67. package/dist/charts/bklit/chart-formatters.d.ts +16 -0
  68. package/dist/charts/bklit/chart-formatters.js +26 -0
  69. package/dist/charts/bklit/chart-legend-hover.d.ts +21 -0
  70. package/dist/charts/bklit/chart-legend-hover.js +26 -0
  71. package/dist/charts/bklit/chart-loading-label.d.ts +9 -0
  72. package/dist/charts/bklit/chart-loading-label.js +29 -0
  73. package/dist/charts/bklit/chart-phase.d.ts +39 -0
  74. package/dist/charts/bklit/chart-phase.js +20 -0
  75. package/dist/charts/bklit/chart-reveal-clip.d.ts +32 -0
  76. package/dist/charts/bklit/chart-reveal-clip.js +23 -0
  77. package/dist/charts/bklit/dash-tail-stroke.d.ts +17 -0
  78. package/dist/charts/bklit/dash-tail-stroke.js +21 -0
  79. package/dist/charts/bklit/decimate-time-series.d.ts +18 -0
  80. package/dist/charts/bklit/decimate-time-series.js +120 -0
  81. package/dist/charts/bklit/fade-edges.d.ts +42 -0
  82. package/dist/charts/bklit/fade-edges.js +34 -0
  83. package/dist/charts/bklit/filter-data-by-x-domain.d.ts +13 -0
  84. package/dist/charts/bklit/filter-data-by-x-domain.js +50 -0
  85. package/dist/charts/bklit/generate-chart-skeleton-data.d.ts +24 -0
  86. package/dist/charts/bklit/generate-chart-skeleton-data.js +33 -0
  87. package/dist/charts/bklit/grid.d.ts +57 -0
  88. package/dist/charts/bklit/grid.js +88 -0
  89. package/dist/charts/bklit/highlight-segment-bounds.d.ts +26 -0
  90. package/dist/charts/bklit/highlight-segment-bounds.js +35 -0
  91. package/dist/charts/bklit/highlight-segment.d.ts +30 -0
  92. package/dist/charts/bklit/highlight-segment.js +22 -0
  93. package/dist/charts/bklit/indicator-fade.d.ts +23 -0
  94. package/dist/charts/bklit/indicator-fade.js +41 -0
  95. package/dist/charts/bklit/line-chart-loading.d.ts +33 -0
  96. package/dist/charts/bklit/line-chart-loading.js +30 -0
  97. package/dist/charts/bklit/line-chart.d.ts +45 -0
  98. package/dist/charts/bklit/line-chart.js +99 -0
  99. package/dist/charts/bklit/line-loading-pulse.d.ts +19 -0
  100. package/dist/charts/bklit/line-loading-pulse.js +132 -0
  101. package/dist/charts/bklit/line-loading-timing.d.ts +18 -0
  102. package/dist/charts/bklit/line-loading-timing.js +18 -0
  103. package/dist/charts/bklit/line-series-terminal-marker.d.ts +15 -0
  104. package/dist/charts/bklit/line-series-terminal-marker.js +54 -0
  105. package/dist/charts/bklit/line.d.ts +63 -0
  106. package/dist/charts/bklit/line.js +104 -0
  107. package/dist/charts/bklit/loading-sweep.d.ts +65 -0
  108. package/dist/charts/bklit/loading-sweep.js +182 -0
  109. package/dist/charts/bklit/motion-utils.d.ts +17 -0
  110. package/dist/charts/bklit/motion-utils.js +27 -0
  111. package/dist/charts/bklit/path-stroke-utils.d.ts +28 -0
  112. package/dist/charts/bklit/path-stroke-utils.js +64 -0
  113. package/dist/charts/bklit/pattern-area.d.ts +20 -0
  114. package/dist/charts/bklit/pattern-area.js +27 -0
  115. package/dist/charts/bklit/pattern-preset.d.ts +34 -0
  116. package/dist/charts/bklit/pattern-preset.js +82 -0
  117. package/dist/charts/bklit/projection-config.d.ts +19 -0
  118. package/dist/charts/bklit/projection-config.js +88 -0
  119. package/dist/charts/bklit/projection-line-end-marker.d.ts +14 -0
  120. package/dist/charts/bklit/projection-line-end-marker.js +35 -0
  121. package/dist/charts/bklit/projection-line.d.ts +39 -0
  122. package/dist/charts/bklit/projection-line.js +87 -0
  123. package/dist/charts/bklit/projection-utils.d.ts +54 -0
  124. package/dist/charts/bklit/projection-utils.js +252 -0
  125. package/dist/charts/bklit/reference-area-config.d.ts +18 -0
  126. package/dist/charts/bklit/reference-area-config.js +47 -0
  127. package/dist/charts/bklit/reference-area-registration-context.d.ts +7 -0
  128. package/dist/charts/bklit/reference-area-registration-context.js +15 -0
  129. package/dist/charts/bklit/series-bar-layout.d.ts +26 -0
  130. package/dist/charts/bklit/series-bar-layout.js +39 -0
  131. package/dist/charts/bklit/series-dash-tail-overlay.d.ts +16 -0
  132. package/dist/charts/bklit/series-dash-tail-overlay.js +47 -0
  133. package/dist/charts/bklit/series-highlight-layer.d.ts +31 -0
  134. package/dist/charts/bklit/series-highlight-layer.js +20 -0
  135. package/dist/charts/bklit/series-hover-dim.d.ts +28 -0
  136. package/dist/charts/bklit/series-hover-dim.js +34 -0
  137. package/dist/charts/bklit/series-markers.d.ts +13 -0
  138. package/dist/charts/bklit/series-markers.js +106 -0
  139. package/dist/charts/bklit/series-path-utils.d.ts +18 -0
  140. package/dist/charts/bklit/series-path-utils.js +68 -0
  141. package/dist/charts/bklit/series-point-marker.d.ts +47 -0
  142. package/dist/charts/bklit/series-point-marker.js +47 -0
  143. package/dist/charts/bklit/static-chart-preview-context.d.ts +15 -0
  144. package/dist/charts/bklit/static-chart-preview-context.js +20 -0
  145. package/dist/charts/bklit/time-series-chart-shell.d.ts +46 -0
  146. package/dist/charts/bklit/time-series-chart-shell.js +398 -0
  147. package/dist/charts/bklit/tooltip/chart-tooltip.d.ts +75 -0
  148. package/dist/charts/bklit/tooltip/chart-tooltip.js +158 -0
  149. package/dist/charts/bklit/tooltip/date-ticker.d.ts +10 -0
  150. package/dist/charts/bklit/tooltip/date-ticker.js +85 -0
  151. package/dist/charts/bklit/tooltip/index.d.ts +15 -0
  152. package/dist/charts/bklit/tooltip/index.js +15 -0
  153. package/dist/charts/bklit/tooltip/tooltip-box.d.ts +56 -0
  154. package/dist/charts/bklit/tooltip/tooltip-box.js +122 -0
  155. package/dist/charts/bklit/tooltip/tooltip-content.d.ts +26 -0
  156. package/dist/charts/bklit/tooltip/tooltip-content.js +8 -0
  157. package/dist/charts/bklit/tooltip/tooltip-dot.d.ts +27 -0
  158. package/dist/charts/bklit/tooltip/tooltip-dot.js +62 -0
  159. package/dist/charts/bklit/tooltip/tooltip-indicator.d.ts +44 -0
  160. package/dist/charts/bklit/tooltip/tooltip-indicator.js +73 -0
  161. package/dist/charts/bklit/use-animated-series-path.d.ts +18 -0
  162. package/dist/charts/bklit/use-animated-series-path.js +101 -0
  163. package/dist/charts/bklit/use-animated-y-domains.d.ts +13 -0
  164. package/dist/charts/bklit/use-animated-y-domains.js +158 -0
  165. package/dist/charts/bklit/use-chart-interaction.d.ts +40 -0
  166. package/dist/charts/bklit/use-chart-interaction.js +252 -0
  167. package/dist/charts/bklit/use-chart-phase-orchestrator.d.ts +22 -0
  168. package/dist/charts/bklit/use-chart-phase-orchestrator.js +147 -0
  169. package/dist/charts/bklit/use-enter-complete.d.ts +16 -0
  170. package/dist/charts/bklit/use-enter-complete.js +22 -0
  171. package/dist/charts/bklit/use-grid-shimmer.d.ts +15 -0
  172. package/dist/charts/bklit/use-grid-shimmer.js +71 -0
  173. package/dist/charts/bklit/use-highlight-segment.d.ts +22 -0
  174. package/dist/charts/bklit/use-highlight-segment.js +42 -0
  175. package/dist/charts/bklit/use-mount-progress.d.ts +12 -0
  176. package/dist/charts/bklit/use-mount-progress.js +30 -0
  177. package/dist/charts/bklit/use-scheduled-tooltip.d.ts +8 -0
  178. package/dist/charts/bklit/use-scheduled-tooltip.js +84 -0
  179. package/dist/charts/bklit/visx-pattern.d.ts +27 -0
  180. package/dist/charts/bklit/visx-pattern.js +28 -0
  181. package/dist/charts/bklit/x-axis.d.ts +26 -0
  182. package/dist/charts/bklit/x-axis.js +423 -0
  183. package/dist/charts/bklit/y-axis-scales.d.ts +34 -0
  184. package/dist/charts/bklit/y-axis-scales.js +80 -0
  185. package/dist/charts/bklit/y-axis-ticks.d.ts +20 -0
  186. package/dist/charts/bklit/y-axis-ticks.js +32 -0
  187. package/dist/charts/bklit/y-domain-utils.d.ts +26 -0
  188. package/dist/charts/bklit/y-domain-utils.js +96 -0
  189. package/dist/charts/bklit.d.ts +2 -0
  190. package/dist/charts/bklit.js +90 -0
  191. package/dist/charts/components/shimmering-text.d.ts +31 -0
  192. package/dist/charts/components/shimmering-text.js +39 -0
  193. package/dist/charts/css.d.ts +35 -0
  194. package/dist/charts/css.js +64 -0
  195. package/dist/charts/recharts.d.ts +28 -0
  196. package/dist/charts/recharts.js +48 -0
  197. package/dist/charts/registry.d.ts +34 -0
  198. package/dist/charts/registry.js +60 -0
  199. package/dist/charts/skeleton.d.ts +55 -0
  200. package/dist/charts/skeleton.js +66 -0
  201. package/dist/cn.d.ts +10 -0
  202. package/dist/cn.js +13 -0
  203. package/dist/context.d.ts +346 -0
  204. package/dist/context.js +95 -0
  205. package/dist/index.d.ts +30 -0
  206. package/dist/index.js +65 -0
  207. package/dist/routes.d.ts +70 -0
  208. package/dist/routes.js +73 -0
  209. package/dist/source-fields.d.ts +111 -0
  210. package/dist/source-fields.js +204 -0
  211. package/dist/ui/chart.d.ts +54 -0
  212. package/dist/ui/chart.js +122 -0
  213. package/dist/ui/dialog.d.ts +27 -0
  214. package/dist/ui/dialog.js +24 -0
  215. package/dist/ui/field.d.ts +29 -0
  216. package/dist/ui/field.js +31 -0
  217. package/dist/ui/select.d.ts +42 -0
  218. package/dist/ui/select.js +30 -0
  219. package/dist/ui/sheet.d.ts +38 -0
  220. package/dist/ui/sheet.js +37 -0
  221. package/dist/ui/switch.d.ts +17 -0
  222. package/dist/ui/switch.js +14 -0
  223. package/dist/ui/tabs.d.ts +30 -0
  224. package/dist/ui/tabs.js +36 -0
  225. package/dist/ui/tooltip.d.ts +37 -0
  226. package/dist/ui/tooltip.js +43 -0
  227. package/dist/workflow/graph.d.ts +112 -0
  228. package/dist/workflow/graph.js +297 -0
  229. package/dist/workflow/index.d.ts +16 -0
  230. package/dist/workflow/index.js +16 -0
  231. package/dist/workflow/model.d.ts +151 -0
  232. package/dist/workflow/model.js +97 -0
  233. package/dist/workflow/name.d.ts +28 -0
  234. package/dist/workflow/name.js +28 -0
  235. package/dist/workflow/nodes.d.ts +40 -0
  236. package/dist/workflow/nodes.js +86 -0
  237. package/dist/workflow/validate.d.ts +104 -0
  238. package/dist/workflow/validate.js +199 -0
  239. package/package.json +148 -0
@@ -0,0 +1,297 @@
1
+ import { workflowRunOrder } from '@dudousxd/nestjs-catalog/client';
2
+ import { MarkerType } from '@xyflow/react';
3
+ import { nodeName, } from './model';
4
+ import { edgeId } from './validate';
5
+ /**
6
+ * Turning the stored graph into what React Flow draws, and back.
7
+ *
8
+ * Kept out of the screen because the two models genuinely differ and the
9
+ * conversion is where that difference is allowed to live. React Flow wants
10
+ * `source`/`target` on an edge and a `data` bag on a node; the executable model
11
+ * wants `from`/`to` and named fields. Letting React Flow's vocabulary leak into
12
+ * what gets saved would tie the wire format to a rendering library, and the
13
+ * next person swapping the canvas would be migrating a database.
14
+ */
15
+ /**
16
+ * Fixed node dimensions, used by the layout below.
17
+ *
18
+ * Declared rather than measured because layout runs before React Flow has
19
+ * measured anything — on a graph loaded from the server, or one somebody just
20
+ * pasted — and a layout that waits for measurements draws every node stacked at
21
+ * the origin for one frame, which reads as a broken canvas.
22
+ */
23
+ export const NODE_WIDTH = 224;
24
+ export const NODE_HEIGHT = 80;
25
+ const COLUMN_GAP = 96;
26
+ const ROW_GAP = 32;
27
+ /**
28
+ * The second line on a node, per kind.
29
+ *
30
+ * A source reads its own description off itself rather than off a connector it
31
+ * points at: a source *is* the reading half of a connector — a kind, an optional
32
+ * named connection, a config — and pointing one at a whole connector would be
33
+ * circular, since a connector references a workflow.
34
+ */
35
+ function subtitleFor(node, describe) {
36
+ if (node.kind === 'source') {
37
+ const kind = typeof node.sourceKind === 'string' ? node.sourceKind : '';
38
+ if (kind.length === 0)
39
+ return 'no source kind chosen';
40
+ const connection = describe.connectionName(node.connectionId);
41
+ if (connection)
42
+ return `${kind} · ${connection}`;
43
+ return node.mode === 'incremental' ? `${kind} · incremental` : kind;
44
+ }
45
+ if (node.kind === 'sink') {
46
+ const type = typeof node.targetType === 'string' ? node.targetType.trim() : '';
47
+ return type.length > 0 ? `commits ${type}` : 'no object type chosen';
48
+ }
49
+ return describe.transformName(node.transformId) ?? 'no transform chosen';
50
+ }
51
+ /**
52
+ * The sentence a screen reader reads when a node takes focus.
53
+ *
54
+ * Assembled here rather than left to React Flow's default, which announces
55
+ * nothing but a node id. Everything that makes the node meaningful — what it
56
+ * does, what feeds it, whether it is broken — has to be in this string, because
57
+ * on a canvas it is the only thing a screen reader user gets.
58
+ */
59
+ function ariaLabelFor(node, data, incoming, outgoing) {
60
+ const parts = [`${node.kind} node, ${data.label}, ${data.subtitle}`];
61
+ parts.push(incoming.length === 0 ? 'nothing feeds it' : `fed by ${incoming.join(', ')}`);
62
+ parts.push(outgoing.length === 0 ? 'feeds nothing' : `feeds ${outgoing.join(', ')}`);
63
+ if (data.run)
64
+ parts.push(`last run ${data.run.status}`);
65
+ for (const problem of data.problems)
66
+ parts.push(problem.message);
67
+ return parts.join('. ');
68
+ }
69
+ export function toFlowNodes(nodes, edges, describe, problemsFor, runFor) {
70
+ const labelOf = new Map(nodes.map((node) => [node.id, nodeName(node)]));
71
+ const names = (ids) => ids.map((id) => labelOf.get(id) ?? id);
72
+ return nodes.map((node) => {
73
+ const data = {
74
+ kind: node.kind,
75
+ label: nodeName(node),
76
+ subtitle: subtitleFor(node, describe),
77
+ problems: problemsFor.get(node.id) ?? [],
78
+ run: runFor.get(node.id),
79
+ };
80
+ const incoming = names(edges.filter((edge) => edge.to === node.id).map((edge) => edge.from));
81
+ const outgoing = names(edges.filter((edge) => edge.from === node.id).map((edge) => edge.to));
82
+ return {
83
+ id: node.id,
84
+ type: 'workflowNode',
85
+ // Defaulted only as a last resort: `layoutIfUnarranged` is what is meant
86
+ // to have supplied one, and a node reaching here without a position would
87
+ // otherwise land on top of whatever else is at the origin.
88
+ position: node.position ?? { x: 0, y: 0 },
89
+ // Declared, not left to measurement.
90
+ //
91
+ // The minimap reads its rectangles from the node objects handed to React
92
+ // Flow — `getNodeDimensions(userNode)` — not from what the DOM turned out
93
+ // to be, and it draws nothing for a node with no dimensions. Without
94
+ // these the canvas rendered perfectly and the overview beside it was a
95
+ // blank white box, which reads as "this graph is empty" rather than as a
96
+ // missing prop. They are the same numbers the layout already spaces nodes
97
+ // by, so the map matches the canvas instead of approximating it.
98
+ width: NODE_WIDTH,
99
+ height: NODE_HEIGHT,
100
+ data,
101
+ ariaLabel: ariaLabelFor(node, data, incoming, outgoing),
102
+ // React Flow's default role for a node is "group", which a screen reader
103
+ // announces as a container rather than as something you can act on. These
104
+ // nodes are the interactive objects on the screen.
105
+ ariaRole: 'button',
106
+ };
107
+ });
108
+ }
109
+ export function defaultLabel(kind) {
110
+ if (kind === 'source')
111
+ return 'Source';
112
+ if (kind === 'sink')
113
+ return 'Sink';
114
+ return 'Transform';
115
+ }
116
+ export function toFlowEdges(edges, nodes, brokenEdgeIds) {
117
+ const labelOf = new Map(nodes.map((node) => [node.id, nodeName(node)]));
118
+ return edges.map((edge) => {
119
+ const from = labelOf.get(edge.from) ?? edge.from;
120
+ const to = labelOf.get(edge.to) ?? edge.to;
121
+ const id = edgeId(edge);
122
+ const broken = brokenEdgeIds.has(id);
123
+ return {
124
+ id,
125
+ source: edge.from,
126
+ target: edge.to,
127
+ type: 'smoothstep',
128
+ // An arrowhead, because "the output of this feeds that" is directional and
129
+ // a plain line says only that two nodes are related.
130
+ markerEnd: { type: MarkerType.ArrowClosed, width: 14, height: 14 },
131
+ ariaLabel: `the output of ${from} feeds ${to}${broken ? ', part of a loop' : ''}`,
132
+ // An inline stroke rather than a class, because the stroke lands on an
133
+ // SVG `<path>` React Flow owns: a Tailwind class on the edge wrapper does
134
+ // not reach it, and inventing a stylesheet rule would mean this package
135
+ // ships CSS for the first time just to colour one line.
136
+ style: broken ? { stroke: '#ef4444', strokeWidth: 2 } : undefined,
137
+ };
138
+ });
139
+ }
140
+ /**
141
+ * Which column each node belongs in, left to right.
142
+ *
143
+ * Built on core's `workflowRunOrder`, which is already topologically sorted and
144
+ * is the same function the runner uses to decide what happens when. Taking the
145
+ * order from there rather than computing a second one means the picture and the
146
+ * execution agree by construction: a node drawn to the right of another really
147
+ * does run after it.
148
+ *
149
+ * `workflowRunOrder` throws on a graph it will not run, which is a graph
150
+ * somebody is in the middle of drawing — half-wired, or with a loop they are
151
+ * about to remove. That is exactly when a canvas most needs to draw, so the
152
+ * fallback below layers the graph by longest path anyway, capping the relaxation
153
+ * at the node count so a cycle cannot spin it forever.
154
+ */
155
+ function columnsFor(nodes, edges) {
156
+ const incoming = new Map();
157
+ for (const node of nodes)
158
+ incoming.set(node.id, []);
159
+ for (const edge of edges) {
160
+ const list = incoming.get(edge.to);
161
+ if (list)
162
+ list.push(edge.from);
163
+ }
164
+ const column = new Map();
165
+ const place = (id) => {
166
+ const feeders = incoming.get(id) ?? [];
167
+ const depth = feeders.length === 0 ? 0 : Math.max(...feeders.map((from) => (column.get(from) ?? 0) + 1));
168
+ column.set(id, Math.max(depth, column.get(id) ?? 0));
169
+ };
170
+ try {
171
+ // Topological order, so one pass is exact: everything feeding a node has
172
+ // already been placed by the time the node is reached.
173
+ for (const entry of workflowRunOrder({ nodes, edges }))
174
+ place(entry.node.id);
175
+ return column;
176
+ }
177
+ catch {
178
+ // The graph is not runnable yet. Relax repeatedly instead; with no cycle
179
+ // this settles in at most one pass per node, and with a cycle the cap is
180
+ // what stops it. Nodes on the cycle end up wherever the cap left them, so a
181
+ // graph with a loop still draws — badly — rather than hanging while
182
+ // somebody is trying to see the loop they need to remove.
183
+ for (let pass = 0; pass < nodes.length + 1; pass += 1) {
184
+ const before = [...column.values()].join(',');
185
+ for (const node of nodes)
186
+ place(node.id);
187
+ if ([...column.values()].join(',') === before)
188
+ break;
189
+ }
190
+ for (const node of nodes)
191
+ if (!column.has(node.id))
192
+ column.set(node.id, 0);
193
+ return column;
194
+ }
195
+ }
196
+ /**
197
+ * Lay the graph out left to right, one column per dependency depth.
198
+ *
199
+ * Sources end up on the left, every wire points right, and **every sink is put
200
+ * in the last column** — past the deepest node in the graph — because a sink is
201
+ * where a branch ends and the arrangement is the only thing that communicates
202
+ * direction. A reader who cannot tell which way the graph flows has to fall back
203
+ * on the wiring rail, and at that point the canvas is decoration. With several
204
+ * sinks that matters more, not less: "everything ends at the right" is how the
205
+ * shape is read at a glance.
206
+ *
207
+ * The positions this produces are then draggable and saved like any others.
208
+ */
209
+ export function layout(nodes, edges) {
210
+ const column = columnsFor(nodes, edges);
211
+ // Measured over everything that is not a sink, then sinks go one past it. A
212
+ // sink fed by a short branch would otherwise sit level with a transform that
213
+ // runs later on a longer one, and "the ends are on the right" would stop being
214
+ // true of the picture. Sinks share a column with each other, which is correct:
215
+ // several sinks are several endings, and they are read as a column of them.
216
+ const deepestBeforeSinks = Math.max(0, ...nodes.filter((node) => node.kind !== 'sink').map((node) => column.get(node.id) ?? 0));
217
+ const sinkColumn = nodes.some((node) => node.kind !== 'sink') ? deepestBeforeSinks + 1 : 0;
218
+ const rows = new Map();
219
+ return nodes.map((node) => {
220
+ const placed = node.kind === 'sink' ? sinkColumn : (column.get(node.id) ?? 0);
221
+ const row = rows.get(placed) ?? 0;
222
+ rows.set(placed, row + 1);
223
+ return {
224
+ ...node,
225
+ position: {
226
+ x: placed * (NODE_WIDTH + COLUMN_GAP),
227
+ y: row * (NODE_HEIGHT + ROW_GAP),
228
+ },
229
+ };
230
+ });
231
+ }
232
+ /**
233
+ * Arrange a graph that nobody has arranged, and leave one that somebody has.
234
+ *
235
+ * Graphs arrive from the API as often as they are drawn — created by a
236
+ * scheduler, promoted from another environment, written by a script — and none
237
+ * of those set positions. `position` is optional in the executable model
238
+ * precisely because it means nothing to execution, so an unset one is normal
239
+ * rather than exceptional. Drawing those at the origin puts every node on top of
240
+ * the first one, and the graph then reads as something it is not: a sink stacked
241
+ * under a source draws its inbound edge doubling back across the canvas, which
242
+ * looks exactly like a cycle. A DAG that renders as apparently cyclic is wrong
243
+ * by definition.
244
+ *
245
+ * Two triggers, not one. Any node **missing** a position is the obvious case.
246
+ * Two nodes sharing **the same** position is the other, and it is included
247
+ * because a server that defaults a missing position to `{0, 0}` produces
248
+ * collisions rather than absences, and the two are the same problem wearing
249
+ * different clothes. Nobody drags two boxes onto the same pixel, so treating an
250
+ * exact collision as "never arranged" costs nothing real.
251
+ *
252
+ * All-or-nothing on purpose. Positioning only the unplaced nodes relative to
253
+ * hand-placed ones produces a worse arrangement than either — the new ones land
254
+ * in columns that mean nothing next to the old ones — so either the layout is
255
+ * authored or it is derived.
256
+ *
257
+ * This runs when a workflow is loaded, and does **not** mark the draft as
258
+ * modified: the result is a pure function of the graph, so it re-derives
259
+ * identically next time and there is nothing to lose by not saving it. Somebody
260
+ * who then drags a node has authored a layout, and that one is saved.
261
+ */
262
+ export function layoutIfUnarranged(nodes, edges) {
263
+ const seen = new Set();
264
+ let arranged = true;
265
+ for (const node of nodes) {
266
+ const position = node.position;
267
+ if (!position || typeof position.x !== 'number' || typeof position.y !== 'number') {
268
+ arranged = false;
269
+ break;
270
+ }
271
+ const key = `${position.x},${position.y}`;
272
+ if (seen.has(key)) {
273
+ arranged = false;
274
+ break;
275
+ }
276
+ seen.add(key);
277
+ }
278
+ return arranged ? nodes : layout(nodes, edges);
279
+ }
280
+ /**
281
+ * Where to drop a node somebody just added.
282
+ *
283
+ * To the right of everything that already exists, rather than at the origin,
284
+ * because dropping it at the origin puts it underneath whatever is already
285
+ * there and reads as "the button did nothing".
286
+ */
287
+ export function nextPosition(nodes) {
288
+ if (nodes.length === 0)
289
+ return { x: 0, y: 0 };
290
+ const xs = nodes.map((node) => node.position?.x ?? 0);
291
+ const right = Math.max(...xs);
292
+ const inColumn = xs.filter((x) => x === right);
293
+ return {
294
+ x: right + NODE_WIDTH + COLUMN_GAP,
295
+ y: inColumn.length * (NODE_HEIGHT + ROW_GAP),
296
+ };
297
+ }
@@ -0,0 +1,16 @@
1
+ /**
2
+ * `@dudousxd/nestjs-catalog-react/workflow` — the canvas itself.
3
+ *
4
+ * A subpath rather than a name on the root entry point, for the same reason the
5
+ * chart renderers have one: this module imports `@xyflow/react`, which is an
6
+ * **optional** peer dependency. Anything reachable from the root entry is
7
+ * resolved by the host's bundler whether or not the host ever renders it, so a
8
+ * root export would turn "optional" into "required to build", and every host
9
+ * that only wants the object explorer would be installing a graph library.
10
+ *
11
+ * The graph model, the working name and the validation rules stay on the root
12
+ * entry — none of them import React Flow, and a host should be able to check a
13
+ * graph, or name one, without pulling in a canvas to do it.
14
+ */
15
+ export { WorkflowCanvas, type WorkflowCanvasProps } from '../WorkflowCanvas';
16
+ export { layout, layoutIfUnarranged, NODE_HEIGHT, NODE_WIDTH, type WorkflowFlowEdge, type WorkflowFlowNode, type WorkflowNodeData, } from './graph';
@@ -0,0 +1,16 @@
1
+ /**
2
+ * `@dudousxd/nestjs-catalog-react/workflow` — the canvas itself.
3
+ *
4
+ * A subpath rather than a name on the root entry point, for the same reason the
5
+ * chart renderers have one: this module imports `@xyflow/react`, which is an
6
+ * **optional** peer dependency. Anything reachable from the root entry is
7
+ * resolved by the host's bundler whether or not the host ever renders it, so a
8
+ * root export would turn "optional" into "required to build", and every host
9
+ * that only wants the object explorer would be installing a graph library.
10
+ *
11
+ * The graph model, the working name and the validation rules stay on the root
12
+ * entry — none of them import React Flow, and a host should be able to check a
13
+ * graph, or name one, without pulling in a canvas to do it.
14
+ */
15
+ export { WorkflowCanvas } from '../WorkflowCanvas';
16
+ export { layout, layoutIfUnarranged, NODE_HEIGHT, NODE_WIDTH, } from './graph';
@@ -0,0 +1,151 @@
1
+ /**
2
+ * The graph model this screen is written against.
3
+ *
4
+ * This file used to *declare* the model, because the executable one did not
5
+ * exist yet. It does now, so everything that describes a node, an edge or a
6
+ * graph is re-exported from `@dudousxd/nestjs-catalog/client` rather than
7
+ * restated here. A second declaration of a wire format is a second thing to
8
+ * keep in step, and the first time it drifts the canvas draws a graph the
9
+ * server will not run.
10
+ *
11
+ * `/client` rather than the package root on purpose: the root entry point pulls
12
+ * in NestJS and MikroORM, and this is browser code. `/client` is types plus a
13
+ * handful of pure functions, and is published precisely so a canvas can share
14
+ * the server's rules without shipping the server.
15
+ *
16
+ * What is still declared here is the short list below, and each entry says why
17
+ * core does not own it. The rule is simple: if the server persists it or
18
+ * executes it, it belongs to core; if only this screen has an opinion about it,
19
+ * it belongs here.
20
+ */
21
+ export type { CatalogWorkflow, WorkflowEdge, WorkflowGraph, WorkflowNode, WorkflowNodeKind, WorkflowSinkNode, WorkflowSourceNode, WorkflowTransformNode, } from '@dudousxd/nestjs-catalog/client';
22
+ export { isWorkflowNodeKind, WORKFLOW_NODE_ID_PATTERN, WORKFLOW_NODE_KINDS, } from '@dudousxd/nestjs-catalog/client';
23
+ import { type WorkflowNode } from '@dudousxd/nestjs-catalog/client';
24
+ /**
25
+ * What a caller may set.
26
+ *
27
+ * Authored fields only, never state: `version`, `graphHash`, `createdBy` and the
28
+ * timestamps are consequences the server writes, and a form that could send them
29
+ * would let somebody claim a graph was authored by someone else.
30
+ *
31
+ * There is deliberately **no `targetType` here.** The type a workflow produces
32
+ * is set on each sink node, because the sink is the node that commits — see
33
+ * {@link WorkflowSinkNode}. A graph may now have several sinks writing several
34
+ * types, so one field on the workflow could only ever name one of them.
35
+ */
36
+ export interface WorkflowInput {
37
+ /** Present when editing. Absent creates a new workflow. */
38
+ id?: string;
39
+ name: string;
40
+ description?: string;
41
+ nodes: WorkflowNode[];
42
+ edges: Array<{
43
+ from: string;
44
+ to: string;
45
+ }>;
46
+ }
47
+ /**
48
+ * Whether this deployment can checkpoint between nodes.
49
+ *
50
+ * Core has {@link CatalogWorkflowCapabilities}, which answers `durable` or
51
+ * `inline` and nothing else. This shape keeps a third answer — the field being
52
+ * absent — because a server that predates it has not said, and a console that
53
+ * reads silence as "no durable engine" is asserting something it was never told.
54
+ * The screen renders all three states distinctly; see `describeDurability`.
55
+ */
56
+ export interface WorkflowDurability {
57
+ available: boolean;
58
+ /**
59
+ * What is providing it, when the server can say. Shown because "durable" on
60
+ * its own is a claim, and naming the engine makes it checkable.
61
+ */
62
+ engine?: string;
63
+ }
64
+ /** The three answers, as prose the screen can render without branching twice. */
65
+ export interface DurabilityCopy {
66
+ state: 'durable' | 'inline' | 'unknown';
67
+ label: string;
68
+ detail: string;
69
+ }
70
+ export declare function describeDurability(durability: WorkflowDurability | undefined): DurabilityCopy;
71
+ /**
72
+ * The outcome of running a graph, node by node.
73
+ *
74
+ * Not in core, and this is the one place where that is a statement rather than
75
+ * an omission: core models what a *connector* run records ({@link ConnectorRun}
76
+ * plus `nodeOutcomes`), and this is the shape the workflow run endpoint answers
77
+ * with — every node of the graph in run order, including the ones that never
78
+ * got an outcome because the run stopped before them.
79
+ *
80
+ * Per node rather than one status for the whole run, for two reasons that have
81
+ * both become load-bearing. The durable claim is only visible per node: "resumes
82
+ * at node seven" is prose until a screen can show which node was seven and that
83
+ * the six before it did not run again. And a graph may now commit several types
84
+ * at several sinks, each independently — so "the run succeeded" is not a fact
85
+ * about the run, it is a fact about each sink, and only the per-node list can
86
+ * say which ones committed.
87
+ */
88
+ export interface WorkflowRun {
89
+ id: string;
90
+ workflowId: string;
91
+ /** The snapshot this run wrote, which is also the durable run id. */
92
+ snapshotId: string;
93
+ /**
94
+ * The whole run's outcome, which is `failed` if **any** sink failed. A run
95
+ * that committed `Mvr` and could not commit `Subwo` is a failed run that
96
+ * happens to have written something, and calling it succeeded is exactly the
97
+ * kind of half-truth the per-sink list below exists to prevent.
98
+ */
99
+ status: 'running' | 'succeeded' | 'failed';
100
+ /**
101
+ * Whether this particular run was checkpointed. Recorded per run, not read
102
+ * from capabilities, because a deployment can gain or lose its durable engine
103
+ * between one run and the next and the older run is still what it was.
104
+ */
105
+ durable: boolean;
106
+ nodes: WorkflowRunNode[];
107
+ startedAt: string;
108
+ finishedAt?: string;
109
+ error?: string;
110
+ }
111
+ export interface WorkflowRunNode {
112
+ nodeId: string;
113
+ status: 'pending' | 'running' | 'succeeded' | 'failed' | 'skipped';
114
+ /**
115
+ * True when the durable engine replayed a completed step instead of running
116
+ * it again. This is the single most useful fact on a resumed run and there is
117
+ * nowhere else to read it from.
118
+ */
119
+ replayed?: boolean;
120
+ rows?: number;
121
+ error?: string;
122
+ startedAt?: string;
123
+ finishedAt?: string;
124
+ }
125
+ /**
126
+ * A stable id for a node the person just drew.
127
+ *
128
+ * Checked against core's {@link WORKFLOW_NODE_ID_PATTERN} rather than assumed to
129
+ * fit it: a node id becomes a durable step name and part of the key its staged
130
+ * rows are stored under, so an id the server refuses is a graph that cannot be
131
+ * saved at all, reported as a validation error about a field nobody typed.
132
+ */
133
+ export declare function newLocalId(prefix: string): string;
134
+ /**
135
+ * What a node is called on screen.
136
+ *
137
+ * `name` is typed `string` and is checked at run time anyway, because this
138
+ * arrives over HTTP: a server that has not yet been updated sends nodes without
139
+ * one, and `undefined.trim()` inside a render is a blank canvas rather than a
140
+ * node with a dull label.
141
+ */
142
+ export declare function nodeName(node: WorkflowNode): string;
143
+ /**
144
+ * Every object type this graph commits, in sink order.
145
+ *
146
+ * A list rather than a single value, because a workflow may have several sinks
147
+ * and the whole point of that is one expensive read feeding several outputs.
148
+ * Anything wanting to *summarise* what a graph produces reads this; nothing sets
149
+ * a type through it, because a type is set on the sink that commits it.
150
+ */
151
+ export declare function producedTypes(nodes: WorkflowNode[]): string[];
@@ -0,0 +1,97 @@
1
+ /**
2
+ * The graph model this screen is written against.
3
+ *
4
+ * This file used to *declare* the model, because the executable one did not
5
+ * exist yet. It does now, so everything that describes a node, an edge or a
6
+ * graph is re-exported from `@dudousxd/nestjs-catalog/client` rather than
7
+ * restated here. A second declaration of a wire format is a second thing to
8
+ * keep in step, and the first time it drifts the canvas draws a graph the
9
+ * server will not run.
10
+ *
11
+ * `/client` rather than the package root on purpose: the root entry point pulls
12
+ * in NestJS and MikroORM, and this is browser code. `/client` is types plus a
13
+ * handful of pure functions, and is published precisely so a canvas can share
14
+ * the server's rules without shipping the server.
15
+ *
16
+ * What is still declared here is the short list below, and each entry says why
17
+ * core does not own it. The rule is simple: if the server persists it or
18
+ * executes it, it belongs to core; if only this screen has an opinion about it,
19
+ * it belongs here.
20
+ */
21
+ export { isWorkflowNodeKind, WORKFLOW_NODE_ID_PATTERN, WORKFLOW_NODE_KINDS, } from '@dudousxd/nestjs-catalog/client';
22
+ import { WORKFLOW_NODE_ID_PATTERN } from '@dudousxd/nestjs-catalog/client';
23
+ export function describeDurability(durability) {
24
+ if (!durability) {
25
+ return {
26
+ state: 'unknown',
27
+ label: 'checkpointing: not reported',
28
+ detail: 'This deployment did not say whether a durable engine is wired up. Assume there is none: a run that fails part-way will start again from the beginning. Treating silence as "resumable" is how a graph gets built that nobody can restart.',
29
+ };
30
+ }
31
+ if (durability.available) {
32
+ return {
33
+ state: 'durable',
34
+ label: durability.engine ? `checkpointing: ${durability.engine}` : 'checkpointing: on',
35
+ detail: 'Every node runs as its own durable step. A ten-node graph that fails at node seven resumes at node seven — the first six are not re-run, and whatever they wrote is not written twice.',
36
+ };
37
+ }
38
+ return {
39
+ state: 'inline',
40
+ label: 'checkpointing: off',
41
+ detail: 'No durable engine is available here, so the whole graph runs inline in one process. A failure at node seven re-runs the graph from node one, and nothing between nodes is checkpointed.',
42
+ };
43
+ }
44
+ /**
45
+ * A stable id for a node the person just drew.
46
+ *
47
+ * Checked against core's {@link WORKFLOW_NODE_ID_PATTERN} rather than assumed to
48
+ * fit it: a node id becomes a durable step name and part of the key its staged
49
+ * rows are stored under, so an id the server refuses is a graph that cannot be
50
+ * saved at all, reported as a validation error about a field nobody typed.
51
+ */
52
+ export function newLocalId(prefix) {
53
+ // `crypto.randomUUID` is not universally present in the browsers this package
54
+ // supports (it needs a secure context), and a canvas that throws while adding
55
+ // a node is worse than one with slightly less pretty ids. The fallback only
56
+ // has to be unique within one unsaved draft — the server keeps whatever it is
57
+ // sent, so both branches have to satisfy the pattern.
58
+ const random = typeof crypto !== 'undefined' && typeof crypto.randomUUID === 'function'
59
+ ? crypto.randomUUID()
60
+ : `${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 10)}`;
61
+ const id = `${prefix}_${random}`;
62
+ if (WORKFLOW_NODE_ID_PATTERN.test(id))
63
+ return id;
64
+ // Only reachable if a future prefix carries something outside the alphabet.
65
+ // Stripping is better than shipping an id the server will refuse.
66
+ return `${prefix.replace(/[^A-Za-z0-9_-]/g, '')}_${random}`.slice(0, 64);
67
+ }
68
+ /**
69
+ * What a node is called on screen.
70
+ *
71
+ * `name` is typed `string` and is checked at run time anyway, because this
72
+ * arrives over HTTP: a server that has not yet been updated sends nodes without
73
+ * one, and `undefined.trim()` inside a render is a blank canvas rather than a
74
+ * node with a dull label.
75
+ */
76
+ export function nodeName(node) {
77
+ return typeof node.name === 'string' && node.name.trim().length > 0 ? node.name.trim() : node.id;
78
+ }
79
+ /**
80
+ * Every object type this graph commits, in sink order.
81
+ *
82
+ * A list rather than a single value, because a workflow may have several sinks
83
+ * and the whole point of that is one expensive read feeding several outputs.
84
+ * Anything wanting to *summarise* what a graph produces reads this; nothing sets
85
+ * a type through it, because a type is set on the sink that commits it.
86
+ */
87
+ export function producedTypes(nodes) {
88
+ const types = [];
89
+ for (const node of nodes) {
90
+ if (node.kind !== 'sink')
91
+ continue;
92
+ const type = typeof node.targetType === 'string' ? node.targetType.trim() : '';
93
+ if (type.length > 0 && !types.includes(type))
94
+ types.push(type);
95
+ }
96
+ return types;
97
+ }
@@ -0,0 +1,28 @@
1
+ /**
2
+ * What this thing is called, in one place.
3
+ *
4
+ * A constant rather than the word typed into thirty JSX strings, because the
5
+ * name is not settled: the model for this graph is being defined in
6
+ * `@dudousxd/nestjs-catalog` in parallel, and whatever it lands on is the name
7
+ * that should win. Renaming then is one edit here.
8
+ *
9
+ * It is deliberately **not** "Flow". `FlowView` in this package is a *derived*
10
+ * picture: it reconstructs who feeds what from the audit trail, and its own
11
+ * comment argues that inferring the graph from what publishers actually did is
12
+ * "more truthful than a diagram someone has to remember to update". This screen
13
+ * is the exact opposite — a graph somebody authors by hand and the server then
14
+ * executes. Two screens sharing a name while making opposite claims about where
15
+ * the truth lives is how people end up trusting the wrong one.
16
+ *
17
+ * "Workflow" is the working choice, and the overlap with the durable engine's
18
+ * own "workflow" is intended rather than accidental: a workflow here compiles
19
+ * to exactly one durable workflow, whose steps are this graph's nodes. The noun
20
+ * is the same because the thing is the same, one layer up. If the model agent
21
+ * picks something else, change these four strings.
22
+ */
23
+ export declare const WORKFLOW_NAME: {
24
+ readonly singular: "workflow";
25
+ readonly plural: "workflows";
26
+ readonly title: "Workflow";
27
+ readonly titlePlural: "Workflows";
28
+ };
@@ -0,0 +1,28 @@
1
+ /**
2
+ * What this thing is called, in one place.
3
+ *
4
+ * A constant rather than the word typed into thirty JSX strings, because the
5
+ * name is not settled: the model for this graph is being defined in
6
+ * `@dudousxd/nestjs-catalog` in parallel, and whatever it lands on is the name
7
+ * that should win. Renaming then is one edit here.
8
+ *
9
+ * It is deliberately **not** "Flow". `FlowView` in this package is a *derived*
10
+ * picture: it reconstructs who feeds what from the audit trail, and its own
11
+ * comment argues that inferring the graph from what publishers actually did is
12
+ * "more truthful than a diagram someone has to remember to update". This screen
13
+ * is the exact opposite — a graph somebody authors by hand and the server then
14
+ * executes. Two screens sharing a name while making opposite claims about where
15
+ * the truth lives is how people end up trusting the wrong one.
16
+ *
17
+ * "Workflow" is the working choice, and the overlap with the durable engine's
18
+ * own "workflow" is intended rather than accidental: a workflow here compiles
19
+ * to exactly one durable workflow, whose steps are this graph's nodes. The noun
20
+ * is the same because the thing is the same, one layer up. If the model agent
21
+ * picks something else, change these four strings.
22
+ */
23
+ export const WORKFLOW_NAME = {
24
+ singular: 'workflow',
25
+ plural: 'workflows',
26
+ title: 'Workflow',
27
+ titlePlural: 'Workflows',
28
+ };