@webpieces/nx-webpieces-rules 0.4.853 → 0.4.855
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.
- package/README.md +14 -0
- package/executors.json +5 -0
- package/package.json +7 -7
- package/src/executors/generate/executor.js +31 -55
- package/src/executors/generate/executor.js.map +1 -1
- package/src/executors/runtime-wiring-check/executor.d.ts +10 -0
- package/src/executors/runtime-wiring-check/executor.js +42 -0
- package/src/executors/runtime-wiring-check/executor.js.map +1 -0
- package/src/executors/runtime-wiring-check/schema.json +14 -0
- package/src/executors/validate-api-lib-tag/executor.js +5 -3
- package/src/executors/validate-api-lib-tag/executor.js.map +1 -1
- package/src/executors/validate-api-relations/executor.js +11 -8
- package/src/executors/validate-api-relations/executor.js.map +1 -1
- package/src/executors/validate-architecture-unchanged/executor.d.ts +1 -1
- package/src/executors/validate-architecture-unchanged/executor.js +22 -24
- package/src/executors/validate-architecture-unchanged/executor.js.map +1 -1
- package/src/index.d.ts +1 -0
- package/src/index.js +5 -1
- package/src/index.js.map +1 -1
- package/src/lib/api-usage/api-contract-approval.d.ts +7 -0
- package/src/lib/api-usage/api-contract-approval.js +50 -0
- package/src/lib/api-usage/api-contract-approval.js.map +1 -0
- package/src/lib/api-usage/api-contract-evidence.d.ts +6 -0
- package/src/lib/api-usage/api-contract-evidence.js +41 -0
- package/src/lib/api-usage/api-contract-evidence.js.map +1 -0
- package/src/lib/api-usage/api-relations-validator.d.ts +13 -2
- package/src/lib/api-usage/api-relations-validator.js +23 -0
- package/src/lib/api-usage/api-relations-validator.js.map +1 -1
- package/src/lib/api-usage/api-relations.d.ts +3 -0
- package/src/lib/api-usage/api-relations.js.map +1 -1
- package/src/lib/api-usage/api-scanner.d.ts +40 -0
- package/src/lib/api-usage/api-scanner.js +7 -1
- package/src/lib/api-usage/api-scanner.js.map +1 -1
- package/src/lib/graph-comparator.js +11 -1
- package/src/lib/graph-comparator.js.map +1 -1
- package/src/lib/graph-filter.client.d.ts +40 -0
- package/src/lib/graph-filter.client.js +190 -0
- package/src/lib/graph-filter.client.js.map +1 -0
- package/src/lib/graph-level-bands.d.ts +0 -18
- package/src/lib/graph-level-bands.js +4 -3
- package/src/lib/graph-level-bands.js.map +1 -1
- package/src/lib/graph-loader.js +12 -6
- package/src/lib/graph-loader.js.map +1 -1
- package/src/lib/graph-navigation.d.ts +5 -0
- package/src/lib/graph-navigation.js +102 -0
- package/src/lib/graph-navigation.js.map +1 -0
- package/src/lib/graph-node-menu.d.ts +1 -0
- package/src/lib/graph-node-menu.js +29 -0
- package/src/lib/graph-node-menu.js.map +1 -1
- package/src/lib/graph-render-model.d.ts +32 -0
- package/src/lib/graph-render-model.js +76 -0
- package/src/lib/graph-render-model.js.map +1 -0
- package/src/lib/graph-sorter.d.ts +2 -0
- package/src/lib/graph-sorter.js.map +1 -1
- package/src/lib/graph-visualizer.client.d.ts +14 -73
- package/src/lib/graph-visualizer.client.js +71 -243
- package/src/lib/graph-visualizer.client.js.map +1 -1
- package/src/lib/graph-visualizer.d.ts +8 -15
- package/src/lib/graph-visualizer.js +48 -26
- package/src/lib/graph-visualizer.js.map +1 -1
- package/src/lib/runtime-details.d.ts +13 -0
- package/src/lib/runtime-details.js +191 -0
- package/src/lib/runtime-details.js.map +1 -0
- package/src/lib/runtime-graph-model.d.ts +4 -1
- package/src/lib/runtime-graph-model.js.map +1 -1
- package/src/lib/runtime-graph.js +10 -4
- package/src/lib/runtime-graph.js.map +1 -1
- package/src/lib/runtime-html-page.d.ts +7 -3
- package/src/lib/runtime-html-page.js +19 -6
- package/src/lib/runtime-html-page.js.map +1 -1
- package/src/lib/runtime-visualizer.client.d.ts +8 -19
- package/src/lib/runtime-visualizer.client.js +28 -41
- package/src/lib/runtime-visualizer.client.js.map +1 -1
- package/src/lib/runtime-visualizer.d.ts +3 -45
- package/src/lib/runtime-visualizer.js +77 -79
- package/src/lib/runtime-visualizer.js.map +1 -1
- package/src/lib/runtime-viz-theme.js +4 -3
- package/src/lib/runtime-viz-theme.js.map +1 -1
- package/src/lib/runtime-wiring/DeclarationCompileAssertions.d.ts +4 -0
- package/src/lib/runtime-wiring/DeclarationCompileAssertions.js +27 -0
- package/src/lib/runtime-wiring/DeclarationCompileAssertions.js.map +1 -0
- package/src/lib/runtime-wiring/approved-graph.d.ts +8 -0
- package/src/lib/runtime-wiring/approved-graph.js +115 -0
- package/src/lib/runtime-wiring/approved-graph.js.map +1 -0
- package/src/lib/runtime-wiring/assembler.d.ts +24 -0
- package/src/lib/runtime-wiring/assembler.js +116 -0
- package/src/lib/runtime-wiring/assembler.js.map +1 -0
- package/src/lib/runtime-wiring/codec.d.ts +14 -0
- package/src/lib/runtime-wiring/codec.js +162 -0
- package/src/lib/runtime-wiring/codec.js.map +1 -0
- package/src/lib/runtime-wiring/declaration.d.ts +68 -0
- package/src/lib/runtime-wiring/declaration.js +88 -0
- package/src/lib/runtime-wiring/declaration.js.map +1 -0
- package/src/lib/runtime-wiring/source-extractor.d.ts +28 -0
- package/src/lib/runtime-wiring/source-extractor.js +253 -0
- package/src/lib/runtime-wiring/source-extractor.js.map +1 -0
- package/src/lib/runtime-wiring/source-values.d.ts +21 -0
- package/src/lib/runtime-wiring/source-values.js +204 -0
- package/src/lib/runtime-wiring/source-values.js.map +1 -0
- package/src/lib/runtime-wiring/verification.d.ts +9 -0
- package/src/lib/runtime-wiring/verification.js +56 -0
- package/src/lib/runtime-wiring/verification.js.map +1 -0
- package/src/plugin.d.ts +0 -21
- package/src/plugin.js +12 -7
- package/src/plugin.js.map +1 -1
- package/src/runtime-wiring-targets.d.ts +7 -0
- package/src/runtime-wiring-targets.js +58 -0
- package/src/runtime-wiring-targets.js.map +1 -0
- package/src/validation-targets.js +10 -2
- package/src/validation-targets.js.map +1 -1
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/** Plain browser helpers shared by architecture and runtime; no CommonJS imports. */
|
|
3
|
+
class WpGraphChain {
|
|
4
|
+
model;
|
|
5
|
+
inNodes = new Map();
|
|
6
|
+
outNodes = new Map();
|
|
7
|
+
constructor(model) {
|
|
8
|
+
this.model = model;
|
|
9
|
+
const ids = new Set(model.nodes.map((node) => node.id));
|
|
10
|
+
for (const edge of model.edges) {
|
|
11
|
+
if (!ids.has(edge.from) || !ids.has(edge.to))
|
|
12
|
+
continue;
|
|
13
|
+
this.add(this.outNodes, edge.from, edge.to);
|
|
14
|
+
this.add(this.inNodes, edge.to, edge.from);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
add(map, from, to) {
|
|
18
|
+
if (!map.has(from))
|
|
19
|
+
map.set(from, new Set());
|
|
20
|
+
map.get(from)?.add(to);
|
|
21
|
+
}
|
|
22
|
+
nodes(anchor) {
|
|
23
|
+
const retained = new Set();
|
|
24
|
+
if (!this.model.nodes.some((node) => node.id === anchor))
|
|
25
|
+
return retained;
|
|
26
|
+
for (const direction of [this.inNodes, this.outNodes]) {
|
|
27
|
+
const visited = new Set([anchor]);
|
|
28
|
+
const stack = [anchor];
|
|
29
|
+
while (stack.length > 0) {
|
|
30
|
+
const id = stack.pop();
|
|
31
|
+
retained.add(id);
|
|
32
|
+
for (const next of direction.get(id) ?? []) {
|
|
33
|
+
if (visited.has(next))
|
|
34
|
+
continue;
|
|
35
|
+
visited.add(next);
|
|
36
|
+
stack.push(next);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return retained;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
class WpRenderBand {
|
|
44
|
+
level;
|
|
45
|
+
nodeNames;
|
|
46
|
+
constructor(level, nodeNames) {
|
|
47
|
+
this.level = level;
|
|
48
|
+
this.nodeNames = nodeNames;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
/** Original records plus fresh ranks: removed nodes cannot reappear via a rank/edge. */
|
|
52
|
+
class WpFilteredDot {
|
|
53
|
+
model;
|
|
54
|
+
constructor(model) {
|
|
55
|
+
this.model = model;
|
|
56
|
+
}
|
|
57
|
+
render(retained) {
|
|
58
|
+
const nodes = this.model.nodes.filter((node) => retained.has(node.id));
|
|
59
|
+
const edges = this.model.edges.filter((edge) => retained.has(edge.from) && retained.has(edge.to));
|
|
60
|
+
const bands = this.model.bands
|
|
61
|
+
.map((band) => new WpRenderBand(band.level, band.nodeNames.filter((id) => retained.has(id))))
|
|
62
|
+
.filter((band) => band.nodeNames.length > 0);
|
|
63
|
+
return (this.model.header +
|
|
64
|
+
nodes.map((node) => node.dot).join('') +
|
|
65
|
+
this.bandDot(bands) +
|
|
66
|
+
edges.map((edge) => edge.dot).join('') +
|
|
67
|
+
this.model.footer);
|
|
68
|
+
}
|
|
69
|
+
bandDot(bands) {
|
|
70
|
+
const nodeAttrs = '[style=invis, shape=point, width=0.01, height=0.01, label="", class="wp-layout"]';
|
|
71
|
+
const edgeAttrs = '[style=invis, class="wp-layout"]';
|
|
72
|
+
let dot = '';
|
|
73
|
+
for (const band of bands) {
|
|
74
|
+
const anchor = `__wp_layout_L${band.level}`;
|
|
75
|
+
dot += ` "${anchor}" ${nodeAttrs};\n { rank=same; "${anchor}"; `;
|
|
76
|
+
dot += band.nodeNames.map((id) => `${JSON.stringify(id)}; `).join('') + '}\n';
|
|
77
|
+
}
|
|
78
|
+
for (let i = 0; i + 1 < bands.length; i++) {
|
|
79
|
+
const upper = bands[i];
|
|
80
|
+
const lower = bands[i + 1];
|
|
81
|
+
const from = `__wp_layout_L${upper.level}`;
|
|
82
|
+
const to = `__wp_layout_L${lower.level}`;
|
|
83
|
+
if (upper.nodeNames.length <= 10 && lower.nodeNames.length <= 10) {
|
|
84
|
+
dot += ` "${from}" -> "${to}" ${edgeAttrs};\n`;
|
|
85
|
+
continue;
|
|
86
|
+
}
|
|
87
|
+
const spacer = `__wp_layout_spacer_L${upper.level}_L${lower.level}`;
|
|
88
|
+
dot += ` "${spacer}" ${nodeAttrs};\n { rank=same; "${spacer}"; }\n`;
|
|
89
|
+
dot += ` "${from}" -> "${spacer}" ${edgeAttrs};\n "${spacer}" -> "${to}" ${edgeAttrs};\n`;
|
|
90
|
+
}
|
|
91
|
+
return dot;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
/** Page-owned state survives replacements; rendering failures leave the usable SVG intact. */
|
|
95
|
+
class WpFilterPage {
|
|
96
|
+
model;
|
|
97
|
+
chain;
|
|
98
|
+
locked = null;
|
|
99
|
+
anchor = null;
|
|
100
|
+
retained;
|
|
101
|
+
viz = null;
|
|
102
|
+
constructor(model) {
|
|
103
|
+
this.model = model;
|
|
104
|
+
this.chain = new WpGraphChain(model);
|
|
105
|
+
this.retained = new Set(model.nodes.map((node) => node.id));
|
|
106
|
+
}
|
|
107
|
+
render() {
|
|
108
|
+
document
|
|
109
|
+
.getElementById('wp-filter-off')
|
|
110
|
+
?.addEventListener('click', () => this.filter(null));
|
|
111
|
+
this.wireControls();
|
|
112
|
+
Viz.instance()
|
|
113
|
+
.then((viz) => {
|
|
114
|
+
this.viz = viz;
|
|
115
|
+
this.filter(null);
|
|
116
|
+
})
|
|
117
|
+
// webpieces-disable no-any-unknown -- promise rejections may carry any JavaScript value
|
|
118
|
+
.catch((err) => this.error(err instanceof Error ? err : new Error(String(err))));
|
|
119
|
+
}
|
|
120
|
+
captureBinding(_svg) { return () => { }; }
|
|
121
|
+
wireControls() { }
|
|
122
|
+
prepareSvg(_svg) { }
|
|
123
|
+
filterItem(name) {
|
|
124
|
+
return new WpNodeMenuItem(this.anchor === null ? 'Filter Unconnected' : 'Turn off Filter', () => this.filter(this.anchor === null ? name : null));
|
|
125
|
+
}
|
|
126
|
+
filter(anchor) {
|
|
127
|
+
if (this.viz === null)
|
|
128
|
+
return;
|
|
129
|
+
const host = document.getElementById('graph');
|
|
130
|
+
if (host === null)
|
|
131
|
+
return;
|
|
132
|
+
const retained = anchor === null
|
|
133
|
+
? new Set(this.model.nodes.map((node) => node.id))
|
|
134
|
+
: this.chain.nodes(anchor);
|
|
135
|
+
const previousAnchor = this.anchor;
|
|
136
|
+
const previousRetained = this.retained;
|
|
137
|
+
const previousSvg = host.querySelector('svg');
|
|
138
|
+
const rollback = this.captureBinding(previousSvg);
|
|
139
|
+
// eslint-disable-next-line @webpieces/no-unmanaged-exceptions -- browser transaction restores the previous usable graph on failure
|
|
140
|
+
try {
|
|
141
|
+
const dot = anchor === null
|
|
142
|
+
? this.model.fullDot
|
|
143
|
+
: new WpFilteredDot(this.model).render(retained);
|
|
144
|
+
const svg = this.viz.renderSVGElement(dot);
|
|
145
|
+
this.prepareSvg(svg);
|
|
146
|
+
WpNodeMenu.close();
|
|
147
|
+
this.anchor = anchor;
|
|
148
|
+
this.retained = retained;
|
|
149
|
+
host.replaceChildren(svg);
|
|
150
|
+
this.wireSvg(svg);
|
|
151
|
+
this.indicator();
|
|
152
|
+
this.error(null);
|
|
153
|
+
// webpieces-disable no-any-unknown -- JavaScript may throw any value at this browser boundary
|
|
154
|
+
}
|
|
155
|
+
catch (err) {
|
|
156
|
+
//const error = toError(err);
|
|
157
|
+
this.anchor = previousAnchor;
|
|
158
|
+
this.retained = previousRetained;
|
|
159
|
+
if (previousSvg !== null)
|
|
160
|
+
host.replaceChildren(previousSvg);
|
|
161
|
+
else
|
|
162
|
+
host.replaceChildren();
|
|
163
|
+
rollback();
|
|
164
|
+
this.error(err instanceof Error ? err : new Error(String(err)));
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
indicator() {
|
|
168
|
+
const status = document.getElementById('wp-filter-status');
|
|
169
|
+
const label = document.getElementById('wp-filter-anchor');
|
|
170
|
+
if (status !== null)
|
|
171
|
+
status.hidden = this.anchor === null;
|
|
172
|
+
if (label !== null)
|
|
173
|
+
label.textContent = this.anchor;
|
|
174
|
+
if (this.anchor !== null)
|
|
175
|
+
document.getElementById('wp-filter-off')?.focus();
|
|
176
|
+
else
|
|
177
|
+
document.querySelector('#graph g.wp-node-clickable')?.focus();
|
|
178
|
+
}
|
|
179
|
+
error(err) {
|
|
180
|
+
const el = document.getElementById('wp-graph-error');
|
|
181
|
+
if (el === null)
|
|
182
|
+
return;
|
|
183
|
+
el.hidden = err === null;
|
|
184
|
+
el.textContent =
|
|
185
|
+
err === null
|
|
186
|
+
? ''
|
|
187
|
+
: `Graph rendering failed: ${err.message}. Try Turn off Filter or reload the page.`;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
//# sourceMappingURL=graph-filter.client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"graph-filter.client.js","sourceRoot":"","sources":["../../../../../../packages/tooling/nx-webpieces-rules/src/lib/graph-filter.client.ts"],"names":[],"mappings":";AAAA,qFAAqF;AACrF,MAAM,YAAY;IAIe;IAHpB,OAAO,GAAG,IAAI,GAAG,EAAuB,CAAC;IACzC,QAAQ,GAAG,IAAI,GAAG,EAAuB,CAAC;IAEnD,YAA6B,KAAsB;QAAtB,UAAK,GAAL,KAAK,CAAiB;QAC/C,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC;QACxD,KAAK,MAAM,IAAI,IAAI,KAAK,CAAC,KAAK,EAAE,CAAC;YAC7B,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC;gBAAE,SAAS;YACvD,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,EAAE,CAAC,CAAC;YAC5C,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,EAAE,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;QAC/C,CAAC;IACL,CAAC;IAEO,GAAG,CAAC,GAA6B,EAAE,IAAY,EAAE,EAAU;QAC/D,IAAI,CAAC,GAAG,CA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;YAAE,MAAM,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,KAAK,IAAI,CAAC;QAC1D,IAAI,KAAK,KAAK,IAAI;YAAE,KAAK,CAAC,WAAW,GAAG,IAAI,CAAC,MAAM,CAAC;QACpD,IAAI,IAAI,CAAC,MAAM,KAAK,IAAI;YAAE,QAAQ,CAAC,cAAc,CAAC,eAAe,CAAC,EAAE,KAAK,EAAE,CAAC;;YACvE,QAAQ,CAAC,aAAa,CAAc,4BAA4B,CAAC,EAAE,KAAK,EAAE,CAAC;IACpF,CAAC;IAEO,KAAK,CAAC,GAAiB;QAC3B,MAAM,EAAE,GAAG,QAAQ,CAAC,cAAc,CAAC,gBAAgB,CAAC,CAAC;QACrD,IAAI,EAAE,KAAK,IAAI;YAAE,OAAO;QACxB,EAAE,CAAC,MAAM,GAAG,GAAG,KAAK,IAAI,CAAC;QACzB,EAAE,CAAC,WAAW;YACV,GAAG,KAAK,IAAI;gBACR,CAAC,CAAC,EAAE;gBACJ,CAAC,CAAC,2BAA2B,GAAG,CAAC,OAAO,2CAA2C,CAAC;IAChG,CAAC;CACJ","sourcesContent":["/** Plain browser helpers shared by architecture and runtime; no CommonJS imports. */\nclass WpGraphChain {\n readonly inNodes = new Map<string, Set<string>>();\n readonly outNodes = new Map<string, Set<string>>();\n\n constructor(private readonly model: RenderModelJson) {\n const ids = new Set(model.nodes.map((node) => node.id));\n for (const edge of model.edges) {\n if (!ids.has(edge.from) || !ids.has(edge.to)) continue;\n this.add(this.outNodes, edge.from, edge.to);\n this.add(this.inNodes, edge.to, edge.from);\n }\n }\n\n private add(map: Map<string, Set<string>>, from: string, to: string): void {\n if (!map.has(from)) map.set(from, new Set());\n map.get(from)?.add(to);\n }\n\n nodes(anchor: string): Set<string> {\n const retained = new Set<string>();\n if (!this.model.nodes.some((node) => node.id === anchor)) return retained;\n for (const direction of [this.inNodes, this.outNodes]) {\n const visited = new Set([anchor]);\n const stack = [anchor];\n while (stack.length > 0) {\n const id = stack.pop() as string;\n retained.add(id);\n for (const next of direction.get(id) ?? []) {\n if (visited.has(next)) continue;\n visited.add(next);\n stack.push(next);\n }\n }\n }\n return retained;\n }\n}\n\nclass WpRenderBand {\n constructor(\n readonly level: number,\n readonly nodeNames: string[],\n ) {}\n}\n\n/** Original records plus fresh ranks: removed nodes cannot reappear via a rank/edge. */\nclass WpFilteredDot {\n constructor(private readonly model: RenderModelJson) {}\n\n render(retained: Set<string>): string {\n const nodes = this.model.nodes.filter((node) => retained.has(node.id));\n const edges = this.model.edges.filter(\n (edge) => retained.has(edge.from) && retained.has(edge.to),\n );\n const bands = this.model.bands\n .map(\n (band) =>\n new WpRenderBand(\n band.level,\n band.nodeNames.filter((id) => retained.has(id)),\n ),\n )\n .filter((band) => band.nodeNames.length > 0);\n return (\n this.model.header +\n nodes.map((node) => node.dot).join('') +\n this.bandDot(bands) +\n edges.map((edge) => edge.dot).join('') +\n this.model.footer\n );\n }\n\n private bandDot(bands: WpRenderBand[]): string {\n const nodeAttrs =\n '[style=invis, shape=point, width=0.01, height=0.01, label=\"\", class=\"wp-layout\"]';\n const edgeAttrs = '[style=invis, class=\"wp-layout\"]';\n let dot = '';\n for (const band of bands) {\n const anchor = `__wp_layout_L${band.level}`;\n dot += ` \"${anchor}\" ${nodeAttrs};\\n { rank=same; \"${anchor}\"; `;\n dot += band.nodeNames.map((id) => `${JSON.stringify(id)}; `).join('') + '}\\n';\n }\n for (let i = 0; i + 1 < bands.length; i++) {\n const upper = bands[i];\n const lower = bands[i + 1];\n const from = `__wp_layout_L${upper.level}`;\n const to = `__wp_layout_L${lower.level}`;\n if (upper.nodeNames.length <= 10 && lower.nodeNames.length <= 10) {\n dot += ` \"${from}\" -> \"${to}\" ${edgeAttrs};\\n`;\n continue;\n }\n const spacer = `__wp_layout_spacer_L${upper.level}_L${lower.level}`;\n dot += ` \"${spacer}\" ${nodeAttrs};\\n { rank=same; \"${spacer}\"; }\\n`;\n dot += ` \"${from}\" -> \"${spacer}\" ${edgeAttrs};\\n \"${spacer}\" -> \"${to}\" ${edgeAttrs};\\n`;\n }\n return dot;\n }\n}\n\n/** Page-owned state survives replacements; rendering failures leave the usable SVG intact. */\nabstract class WpFilterPage {\n protected readonly chain: WpGraphChain;\n protected locked: string | null = null;\n protected anchor: string | null = null;\n protected retained: Set<string>;\n private viz: VizInstance | null = null;\n\n constructor(protected readonly model: RenderModelJson) {\n this.chain = new WpGraphChain(model);\n this.retained = new Set(model.nodes.map((node) => node.id));\n }\n\n render(): void {\n document\n .getElementById('wp-filter-off')\n ?.addEventListener('click', () => this.filter(null));\n this.wireControls();\n Viz.instance()\n .then((viz) => {\n this.viz = viz;\n this.filter(null);\n })\n // webpieces-disable no-any-unknown -- promise rejections may carry any JavaScript value\n .catch((err: unknown): void =>\n this.error(err instanceof Error ? err : new Error(String(err))),\n );\n }\n\n protected captureBinding(_svg: SVGSVGElement | null): () => void { return (): void => {}; }\n protected wireControls(): void {}\n protected abstract wireSvg(svg: SVGSVGElement): void;\n protected prepareSvg(_svg: SVGSVGElement): void {}\n\n filterItem(name: string): WpNodeMenuItem {\n return new WpNodeMenuItem(\n this.anchor === null ? 'Filter Unconnected' : 'Turn off Filter',\n () => this.filter(this.anchor === null ? name : null),\n );\n }\n\n filter(anchor: string | null): void {\n if (this.viz === null) return;\n const host = document.getElementById('graph');\n if (host === null) return;\n const retained =\n anchor === null\n ? new Set(this.model.nodes.map((node) => node.id))\n : this.chain.nodes(anchor);\n const previousAnchor = this.anchor;\n const previousRetained = this.retained;\n const previousSvg = host.querySelector('svg');\n const rollback = this.captureBinding(previousSvg);\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions -- browser transaction restores the previous usable graph on failure\n try {\n const dot =\n anchor === null\n ? this.model.fullDot\n : new WpFilteredDot(this.model).render(retained);\n const svg = this.viz.renderSVGElement(dot);\n this.prepareSvg(svg);\n WpNodeMenu.close();\n this.anchor = anchor;\n this.retained = retained;\n host.replaceChildren(svg);\n this.wireSvg(svg);\n this.indicator();\n this.error(null);\n // webpieces-disable no-any-unknown -- JavaScript may throw any value at this browser boundary\n } catch (err: unknown) {\n //const error = toError(err);\n this.anchor = previousAnchor;\n this.retained = previousRetained;\n if (previousSvg !== null) host.replaceChildren(previousSvg);\n else host.replaceChildren();\n rollback();\n this.error(err instanceof Error ? err : new Error(String(err)));\n }\n }\n\n private indicator(): void {\n const status = document.getElementById('wp-filter-status');\n const label = document.getElementById('wp-filter-anchor');\n if (status !== null) status.hidden = this.anchor === null;\n if (label !== null) label.textContent = this.anchor;\n if (this.anchor !== null) document.getElementById('wp-filter-off')?.focus();\n else document.querySelector<SVGGElement>('#graph g.wp-node-clickable')?.focus();\n }\n\n private error(err: Error | null): void {\n const el = document.getElementById('wp-graph-error');\n if (el === null) return;\n el.hidden = err === null;\n el.textContent =\n err === null\n ? ''\n : `Graph rendering failed: ${err.message}. Try Turn off Filter or reload the page.`;\n }\n}\n"]}
|
|
@@ -1,21 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Level bands for the architecture graph.
|
|
3
|
-
*
|
|
4
|
-
* Every row of architecture/dependencies.html is ONE dependency level: the highest level on top,
|
|
5
|
-
* descending as you read down, L0 — the foundation everything is built on — always last.
|
|
6
|
-
*
|
|
7
|
-
* `{ rank=same; ... }` alone does not deliver that, and assuming it did was the bug. It ties a
|
|
8
|
-
* level's boxes to one row but says nothing about where that row goes, so graphviz derived each
|
|
9
|
-
* row's position from the edges. A level containing a box with no visible edges — a leaf sdk, an
|
|
10
|
-
* api-lib whose only consumers are hidden — is unconstrained, so it was placed at the top rank and
|
|
11
|
-
* dragged its ENTIRE level up with it (verified against graphviz: that is what put the L0 sdks in
|
|
12
|
-
* the top row, and what parked an L0 lib in the same row as the L6 servers).
|
|
13
|
-
*
|
|
14
|
-
* So the ordering is STATED here rather than inferred: one invisible anchor per band, sitting in
|
|
15
|
-
* that band's rank set, chained top-to-bottom with invisible edges. Ranks are then a function of
|
|
16
|
-
* level and nothing else. The anchors — never the real boxes — carry the chain, so no fake
|
|
17
|
-
* dependency is ever drawn between two projects.
|
|
18
|
-
*/
|
|
19
1
|
/**
|
|
20
2
|
* One horizontal band of the graph: every visible project sharing a dependency level, plus the
|
|
21
3
|
* invisible anchor that pins the band's vertical position.
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LevelBandLayout = exports.LevelBand = void 0;
|
|
4
|
+
const dot_syntax_1 = require("./dot-syntax");
|
|
2
5
|
/**
|
|
3
6
|
* Level bands for the architecture graph.
|
|
4
7
|
*
|
|
@@ -17,8 +20,6 @@
|
|
|
17
20
|
* level and nothing else. The anchors — never the real boxes — carry the chain, so no fake
|
|
18
21
|
* dependency is ever drawn between two projects.
|
|
19
22
|
*/
|
|
20
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
-
exports.LevelBandLayout = exports.LevelBand = void 0;
|
|
22
23
|
/**
|
|
23
24
|
* A band bigger than this gets a blank spacer band inserted next to it, so the long edges leaving a
|
|
24
25
|
* crowded row have vertical room to fan out instead of cutting straight through the row below.
|
|
@@ -66,7 +67,7 @@ class LevelBandLayout {
|
|
|
66
67
|
dot += ` "${band.anchorName()}" ${LAYOUT_NODE_ATTRS};\n`;
|
|
67
68
|
dot += ` { rank=same; "${band.anchorName()}"; `;
|
|
68
69
|
for (const name of band.nodeNames)
|
|
69
|
-
dot += `"${name}"; `;
|
|
70
|
+
dot += `"${(0, dot_syntax_1.dotValue)(name)}"; `;
|
|
70
71
|
dot += '}\n';
|
|
71
72
|
}
|
|
72
73
|
for (let i = 0; i + 1 < bands.length; i++) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"graph-level-bands.js","sourceRoot":"","sources":["../../../../../../packages/tooling/nx-webpieces-rules/src/lib/graph-level-bands.ts"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"graph-level-bands.js","sourceRoot":"","sources":["../../../../../../packages/tooling/nx-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AAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;QAChD,CAAC;QACD,OAAO,GAAG,CAAC;IACf,CAAC;IAED;;;;;OAKG;IACK,OAAO,CAAC,KAAgB,EAAE,KAAgB;QAC9C,MAAM,OAAO,GAAG,KAAK,CAAC,SAAS,CAAC,MAAM,GAAG,oBAAoB;eACtD,KAAK,CAAC,SAAS,CAAC,MAAM,GAAG,oBAAoB,CAAC;QACrD,IAAI,CAAC,OAAO,EAAE,CAAC;YACX,OAAO,MAAM,KAAK,CAAC,UAAU,EAAE,SAAS,KAAK,CAAC,UAAU,EAAE,KAAK,iBAAiB,KAAK,CAAC;QAC1F,CAAC;QACD,MAAM,MAAM,GAAG,uBAAuB,KAAK,CAAC,KAAK,KAAK,KAAK,CAAC,KAAK,EAAE,CAAC;QACpE,OAAO,MAAM,MAAM,KAAK,iBAAiB,KAAK;cACxC,mBAAmB,MAAM,QAAQ;cACjC,MAAM,KAAK,CAAC,UAAU,EAAE,SAAS,MAAM,KAAK,iBAAiB,KAAK;cAClE,MAAM,MAAM,SAAS,KAAK,CAAC,UAAU,EAAE,KAAK,iBAAiB,KAAK,CAAC;IAC7E,CAAC;CACJ;AAtCD,0CAsCC","sourcesContent":["import { dotValue } from './dot-syntax';\n\n/**\n * Level bands for the architecture graph.\n *\n * Every row of architecture/dependencies.html is ONE dependency level: the highest level on top,\n * descending as you read down, L0 — the foundation everything is built on — always last.\n *\n * `{ rank=same; ... }` alone does not deliver that, and assuming it did was the bug. It ties a\n * level's boxes to one row but says nothing about where that row goes, so graphviz derived each\n * row's position from the edges. A level containing a box with no visible edges — a leaf sdk, an\n * api-lib whose only consumers are hidden — is unconstrained, so it was placed at the top rank and\n * dragged its ENTIRE level up with it (verified against graphviz: that is what put the L0 sdks in\n * the top row, and what parked an L0 lib in the same row as the L6 servers).\n *\n * So the ordering is STATED here rather than inferred: one invisible anchor per band, sitting in\n * that band's rank set, chained top-to-bottom with invisible edges. Ranks are then a function of\n * level and nothing else. The anchors — never the real boxes — carry the chain, so no fake\n * dependency is ever drawn between two projects.\n */\n\n/**\n * A band bigger than this gets a blank spacer band inserted next to it, so the long edges leaving a\n * crowded row have vertical room to fan out instead of cutting straight through the row below.\n * Eleven-plus boxes in a row is where that became unreadable in practice.\n */\nconst SPACER_MIN_BAND_SIZE = 10;\n\n/**\n * The class stamped on every node and edge that exists ONLY to pin the layout. Graphviz drops\n * `style=invis` elements from its SVG entirely, so nothing carrying this class reaches the page\n * today; the class is how the DOT tells the browser client which elements are scaffolding, and the\n * client skips them when indexing so an anchor can never be walked as a dependency.\n */\nconst LAYOUT_CLASS = 'wp-layout';\n\n/** Attributes shared by every invisible layout node (rank anchors and spacer bands). */\nconst LAYOUT_NODE_ATTRS =\n `[style=invis, shape=point, width=0.01, height=0.01, label=\"\", class=\"${LAYOUT_CLASS}\"]`;\n\n/** Attributes for the invisible edges that force one band strictly above the next. */\nconst LAYOUT_EDGE_ATTRS = `[style=invis, class=\"${LAYOUT_CLASS}\"]`;\n\n/**\n * One horizontal band of the graph: every visible project sharing a dependency level, plus the\n * invisible anchor that pins the band's vertical position.\n */\nexport class LevelBand {\n level: number;\n /** Short names of the visible projects on this level, sorted for deterministic output. */\n nodeNames: string[];\n\n constructor(level: number, nodeNames: string[]) {\n this.level = level;\n this.nodeNames = nodeNames;\n }\n\n anchorName(): string {\n return `__wp_layout_L${this.level}`;\n }\n}\n\n/** Emits the DOT that pins each band to its own rank, in descending level order. */\nexport class LevelBandLayout {\n /**\n * @param bands the visible projects grouped by level, HIGHEST LEVEL FIRST. Levels need not be\n * contiguous — only the levels actually present get a band, and the chain links\n * whichever ones exist.\n */\n dot(bands: LevelBand[]): string {\n let dot = '';\n for (const band of bands) {\n dot += ` \"${band.anchorName()}\" ${LAYOUT_NODE_ATTRS};\\n`;\n dot += ` { rank=same; \"${band.anchorName()}\"; `;\n for (const name of band.nodeNames) dot += `\"${dotValue(name)}\"; `;\n dot += '}\\n';\n }\n for (let i = 0; i + 1 < bands.length; i++) {\n dot += this.bandGap(bands[i], bands[i + 1]);\n }\n return dot;\n }\n\n /**\n * The ordering chain between two adjacent bands. When either band is crowded\n * (> SPACER_MIN_BAND_SIZE boxes), an empty spacer band goes between them: the edges leaving a\n * wide row then have a whole rank of vertical room to fan out in, instead of being drawn\n * straight through the row below.\n */\n private bandGap(upper: LevelBand, lower: LevelBand): string {\n const crowded = upper.nodeNames.length > SPACER_MIN_BAND_SIZE\n || lower.nodeNames.length > SPACER_MIN_BAND_SIZE;\n if (!crowded) {\n return ` \"${upper.anchorName()}\" -> \"${lower.anchorName()}\" ${LAYOUT_EDGE_ATTRS};\\n`;\n }\n const spacer = `__wp_layout_spacer_L${upper.level}_L${lower.level}`;\n return ` \"${spacer}\" ${LAYOUT_NODE_ATTRS};\\n`\n + ` { rank=same; \"${spacer}\"; }\\n`\n + ` \"${upper.anchorName()}\" -> \"${spacer}\" ${LAYOUT_EDGE_ATTRS};\\n`\n + ` \"${spacer}\" -> \"${lower.anchorName()}\" ${LAYOUT_EDGE_ATTRS};\\n`;\n }\n}\n"]}
|
package/src/lib/graph-loader.js
CHANGED
|
@@ -48,15 +48,15 @@ exports.AI_INSTRUCTIONS = "Each project's shortDescription is only a summary. BE
|
|
|
48
48
|
'project and what does not), and read its designFile to understand the DI design ' +
|
|
49
49
|
'before reading the code. Use the entries in `commands` to regenerate these files ' +
|
|
50
50
|
'or display any of the graphs in a browser. To hide a project (its box AND every ' +
|
|
51
|
-
|
|
51
|
+
'edge touching it) from BOTH rendered architecture graphs, add the nx tag ' +
|
|
52
52
|
"'drawOnGraph:false' to that project's project.json tags and regenerate; it stays " +
|
|
53
53
|
'in this file (marked "drawOnGraph": false) but is omitted from the HTML. A role:server ' +
|
|
54
54
|
'with no webpiecesRuntime package anywhere in its dependency closure and no apiRelations is ' +
|
|
55
55
|
'omitted from the RUNTIME drawing the same way — it speaks none of the webpieces runtime, so ' +
|
|
56
|
-
|
|
56
|
+
"it can only ever draw as a disconnected box; it stays in both JSON files. An API's endpoints " +
|
|
57
57
|
'(name, kind, path, httpMethod, parameters, queueName, caller) are NOT in this file: ' +
|
|
58
58
|
'`apiContractFiles` maps each API to its generated contract file, apis/<ApiName>.json relative to ' +
|
|
59
|
-
|
|
59
|
+
"this file — read that file for the API's endpoints.";
|
|
60
60
|
/**
|
|
61
61
|
* Commands embedded in dependencies.json so AI (and humans) know how to
|
|
62
62
|
* regenerate and DISPLAY the architecture + design graphs. These work in any
|
|
@@ -65,7 +65,7 @@ exports.AI_INSTRUCTIONS = "Each project's shortDescription is only a summary. BE
|
|
|
65
65
|
exports.GRAPH_COMMANDS = {
|
|
66
66
|
regenerateArchitecture: 'pnpm nx run architecture:generate — rewrites architecture/dependencies.json, ' +
|
|
67
67
|
'architecture/apis/<ApiName>.json and architecture/runtime-dependencies.json; run after ' +
|
|
68
|
-
'
|
|
68
|
+
'reviewing project runtime-deps.json and API contract candidates into architecture/apis; generation reads approvals and never approves endpoint changes',
|
|
69
69
|
visualizeArchitecture: 'pnpm nx run architecture:visualize — opens the monorepo dependency graph (this file) ' +
|
|
70
70
|
'as HTML in a browser from saved data, without refreshing; freshness unknown',
|
|
71
71
|
visualizeRuntimeArchitecture: 'pnpm nx run architecture:visualize-runtime — opens the runtime microservice call graph ' +
|
|
@@ -126,7 +126,9 @@ function loadBlessedGraph(workspaceRoot, graphPath = exports.DEFAULT_GRAPH_PATH)
|
|
|
126
126
|
throw movedApiContractsError(fullPath, graphPath);
|
|
127
127
|
}
|
|
128
128
|
if (parsed !== null && typeof parsed === 'object' && 'projects' in parsed) {
|
|
129
|
-
return new DependenciesFile(typeof parsed.aiInstructions === 'string' ? parsed.aiInstructions : '', parsed.commands !== null && typeof parsed.commands === 'object'
|
|
129
|
+
return new DependenciesFile(typeof parsed.aiInstructions === 'string' ? parsed.aiInstructions : '', parsed.commands !== null && typeof parsed.commands === 'object'
|
|
130
|
+
? parsed.commands
|
|
131
|
+
: {}, parsed.projects, parsed.apiContractFiles !== null && typeof parsed.apiContractFiles === 'object'
|
|
130
132
|
? parsed.apiContractFiles
|
|
131
133
|
: {},
|
|
132
134
|
// Absent in any file written before external systems could be declared; an empty
|
|
@@ -154,7 +156,9 @@ function loadBlessedGraph(workspaceRoot, graphPath = exports.DEFAULT_GRAPH_PATH)
|
|
|
154
156
|
function movedApiContractsError(fullPath, graphPath) {
|
|
155
157
|
const apisDir = path.join(path.dirname(graphPath), api_contract_files_1.API_CONTRACTS_DIR);
|
|
156
158
|
return new rules_config_1.RuleFailError(api_contract_files_1.API_CONTRACT_FILES_RULE, `${fullPath} still carries the \`apiContracts\` key. It moved: each API's contract now lives in ` +
|
|
157
|
-
`${apisDir}/<ApiName>.json, and dependencies.json only links to it under \`apiContractFiles\`.`, undefined, undefined, [
|
|
159
|
+
`${apisDir}/<ApiName>.json, and dependencies.json only links to it under \`apiContractFiles\`.`, undefined, undefined, [
|
|
160
|
+
new rules_config_1.Option(`Explicitly move each saved apiContracts.<ApiName> value into ${apisDir}/<ApiName>.json, replace apiContracts with reviewed apiContractFiles entries mapping each name to apis/<ApiName>.json, preserve externalSystems, and approve runtime-deps.json for all runtime owners. Then run pnpm nx run architecture:generate and review the result.`, true),
|
|
161
|
+
]);
|
|
158
162
|
}
|
|
159
163
|
/**
|
|
160
164
|
* Format the dependencies file as JSON with multi-line arrays for readability
|
|
@@ -245,6 +249,8 @@ function formatEntryLines(entry) {
|
|
|
245
249
|
pushOptionalField(lines, 'responsibilitiesFile', entry.responsibilitiesFile);
|
|
246
250
|
pushOptionalField(lines, 'designFile', entry.designFile);
|
|
247
251
|
pushApiRelationsField(lines, entry.apiRelations);
|
|
252
|
+
pushOptionalField(lines, 'runtimeDeclaration', entry.runtimeDeclaration);
|
|
253
|
+
pushOptionalBooleanField(lines, 'runtimeComposition', entry.runtimeComposition);
|
|
248
254
|
if (entry.dependsOn.length === 0) {
|
|
249
255
|
lines.push(` "dependsOn": []`);
|
|
250
256
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"graph-loader.js","sourceRoot":"","sources":["../../../../../../packages/tooling/nx-webpieces-rules/src/lib/graph-loader.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;;;AAgGH,4CAuCC;AAqMD,8BA0BC;AAKD,0CAMC;;AA/WD,+CAAyB;AACzB,mDAA6B;AAE7B,0DAAgE;AAEhE,6DAAkF;AAElF,wCAAqC;AAErC;;GAEG;AACU,QAAA,kBAAkB,GAAG,gCAAgC,CAAC;AAEnE;;;GAGG;AACU,QAAA,eAAe,GACxB,sFAAsF;IACtF,oFAAoF;IACpF,kFAAkF;IAClF,mFAAmF;IACnF,kFAAkF;IAClF,2EAA2E;IAC3E,mFAAmF;IACnF,yFAAyF;IACzF,6FAA6F;IAC7F,8FAA8F;IAC9F,gGAAgG;IAChG,sFAAsF;IACtF,mGAAmG;IACnG,sDAAsD,CAAC;AAO3D;;;;GAIG;AACU,QAAA,cAAc,GAAe;IACtC,sBAAsB,EAClB,+EAA+E;QAC/E,yFAAyF;QACzF,sEAAsE;IAC1E,qBAAqB,EACjB,uFAAuF;QACvF,6EAA6E;IACjF,4BAA4B,EACxB,yFAAyF;QACzF,6EAA6E;IACjF,iBAAiB,EACb,yEAAyE;QACzE,gEAAgE;IACpE,eAAe,EACX,wFAAwF;QACxF,6FAA6F;CACpG,CAAC;AAEF;;GAEG;AACH,MAAa,gBAAgB;IAEL;IACA;IACA;IAMA;IAMA;IAfpB,YACoB,cAAsB,EACtB,QAAoB,EACpB,QAAuB;IACvC;;;;OAIG;IACa,mBAAwC,EAAE;IAC1D;;;;OAIG;IACa,kBAAuC,EAAE;QAdzC,mBAAc,GAAd,cAAc,CAAQ;QACtB,aAAQ,GAAR,QAAQ,CAAY;QACpB,aAAQ,GAAR,QAAQ,CAAe;QAMvB,qBAAgB,GAAhB,gBAAgB,CAA0B;QAM1C,oBAAe,GAAf,eAAe,CAA0B;IA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B,IAAI,gBAAgB,CAAC,uBAAe,EAAE,sBAAc,EAAE,WAAW,EAAE,gBAAgB,EAAE,eAAe,CAAC,CACxG,CAAC;IACF,EAAE,CAAC,aAAa,CAAC,QAAQ,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;AACjD,CAAC;AAED;;GAEG;AACH,SAAgB,eAAe,CAC3B,aAAqB,EACrB,YAAoB,0BAAkB;IAEtC,MAAM,QAAQ,GAAG,IAAI,CAAC,IAAI,CAAC,aAAa,EAAE,SAAS,CAAC,CAAC;IACrD,OAAO,EAAE,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC;AACnC,CAAC","sourcesContent":["/**\n * Graph Loader\n *\n * Handles loading and saving the blessed dependency graph file.\n * The graph is stored at architecture/dependencies.json in the workspace root.\n *\n * File format (schema aimed at AI consumers):\n * {\n * \"aiInstructions\": \"...how AI should use the per-project fields...\",\n * \"apiContractFiles\": { \"<ApiName>\": \"apis/<ApiName>.json\" },\n * \"projects\": {\n * \"<project>\": { level, framework, shortDescription,\n * responsibilitiesFile, designFile, dependsOn }\n * }\n * }\n *\n * `framework` is the project's libType — the SET of runtime environments it is\n * validated to run in, drawn from browser | react | angular | node | express\n * (e.g. [\"browser\",\"node\"]). It comes from the project's `framework:` nx tags\n * and is enforced across edges by the `library-types-match-client` rule.\n *\n * The legacy format (flat { \"<project>\": { level, dependsOn } } map) is still\n * readable so validation against a pre-upgrade file produces a clean\n * \"re-run architecture:generate\" diff instead of a parse failure.\n */\n\nimport * as fs from 'fs';\nimport * as path from 'path';\nimport type { EnhancedGraph, GraphEntry } from './graph-sorter';\nimport { RuleFailError, Option } from '@webpieces/rules-config';\nimport type { ExternalSystemDecls, ProjectApiRelations } from './api-usage/api-relations';\nimport { API_CONTRACT_FILES_RULE, API_CONTRACTS_DIR } from './api-contract-files';\nimport type { ApiContractFileRefs } from './api-contract-files';\nimport { toError } from '../toError';\n\n/**\n * Default path for the dependencies file (relative to workspace root)\n */\nexport const DEFAULT_GRAPH_PATH = 'architecture/dependencies.json';\n\n/**\n * Top-level instructions embedded in dependencies.json telling AI how to use\n * the per-project metadata fields.\n */\nexport const AI_INSTRUCTIONS =\n \"Each project's shortDescription is only a summary. BEFORE adding code to a project, \" +\n 'read its responsibilitiesFile for the full responsibilities (what belongs in that ' +\n 'project and what does not), and read its designFile to understand the DI design ' +\n 'before reading the code. Use the entries in `commands` to regenerate these files ' +\n 'or display any of the graphs in a browser. To hide a project (its box AND every ' +\n \"edge touching it) from BOTH rendered architecture graphs, add the nx tag \" +\n \"'drawOnGraph:false' to that project's project.json tags and regenerate; it stays \" +\n 'in this file (marked \"drawOnGraph\": false) but is omitted from the HTML. A role:server ' +\n 'with no webpiecesRuntime package anywhere in its dependency closure and no apiRelations is ' +\n 'omitted from the RUNTIME drawing the same way — it speaks none of the webpieces runtime, so ' +\n 'it can only ever draw as a disconnected box; it stays in both JSON files. An API\\'s endpoints ' +\n '(name, kind, path, httpMethod, parameters, queueName, caller) are NOT in this file: ' +\n '`apiContractFiles` maps each API to its generated contract file, apis/<ApiName>.json relative to ' +\n 'this file — read that file for the API\\'s endpoints.';\n\n/**\n * Named command → \"command — what it does\" map embedded in dependencies.json.\n */\nexport type CommandMap = Record<string, string>;\n\n/**\n * Commands embedded in dependencies.json so AI (and humans) know how to\n * regenerate and DISPLAY the architecture + design graphs. These work in any\n * repo consuming @webpieces/nx-webpieces-rules.\n */\nexport const GRAPH_COMMANDS: CommandMap = {\n regenerateArchitecture:\n 'pnpm nx run architecture:generate — rewrites architecture/dependencies.json, ' +\n 'architecture/apis/<ApiName>.json and architecture/runtime-dependencies.json; run after ' +\n 'adding/removing project dependencies or changing an API\\'s endpoints',\n visualizeArchitecture:\n 'pnpm nx run architecture:visualize — opens the monorepo dependency graph (this file) ' +\n 'as HTML in a browser from saved data, without refreshing; freshness unknown',\n visualizeRuntimeArchitecture:\n 'pnpm nx run architecture:visualize-runtime — opens the runtime microservice call graph ' +\n 'as HTML in a browser from saved data, without refreshing; freshness unknown',\n regenerateDesigns:\n \"pnpm nx run-many --target=di-graph-generate — rewrites every project's \" +\n 'design.json/design.md (also runs automatically on every build)',\n visualizeDesign:\n \"pnpm wp-design-visualize <project> — opens a project's DI designs (its designFile) as \" +\n 'HTML, one graph per controller with the controller at the top; no args = interactive picker',\n};\n\n/**\n * The full contents of architecture/dependencies.json.\n */\nexport class DependenciesFile {\n constructor(\n public readonly aiInstructions: string,\n public readonly commands: CommandMap,\n public readonly projects: EnhancedGraph,\n /**\n * apiClassName -> its contract file (`apis/<ApiName>.json`, relative to this file's\n * directory). Only the LINK lives here, so adding an endpoint never changes dependencies.json;\n * the contract itself is read with ApiContractFiles.load.\n */\n public readonly apiContractFiles: ApiContractFileRefs = {},\n /**\n * Declared external systems (databases, buckets, ...) keyed by identity. MUST be persisted:\n * the runtime graph is derived from the committed files, so a declaration that is scanned but\n * not written would make generate and validate disagree.\n */\n public readonly externalSystems: ExternalSystemDecls = {}\n ) {}\n}\n\n/**\n * Load the blessed graph from disk. Understands both the current wrapper\n * format and the legacy flat map (which loads with empty aiInstructions).\n *\n * @param workspaceRoot - Absolute path to workspace root\n * @param graphPath - Relative path to graph file (default: architecture/dependencies.json)\n * @returns The blessed graph file, or null if it doesn't exist\n */\nexport function loadBlessedGraph(\n workspaceRoot: string,\n graphPath: string = DEFAULT_GRAPH_PATH\n): DependenciesFile | null {\n const fullPath = path.join(workspaceRoot, graphPath);\n\n if (!fs.existsSync(fullPath)) {\n return null;\n }\n\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions\n try {\n const content = fs.readFileSync(fullPath, 'utf-8');\n const parsed = JSON.parse(content);\n if (parsed !== null && typeof parsed === 'object' && 'apiContracts' in parsed) {\n throw movedApiContractsError(fullPath, graphPath);\n }\n if (parsed !== null && typeof parsed === 'object' && 'projects' in parsed) {\n return new DependenciesFile(\n typeof parsed.aiInstructions === 'string' ? parsed.aiInstructions : '',\n parsed.commands !== null && typeof parsed.commands === 'object' ? (parsed.commands as CommandMap) : {},\n parsed.projects as EnhancedGraph,\n parsed.apiContractFiles !== null && typeof parsed.apiContractFiles === 'object'\n ? (parsed.apiContractFiles as ApiContractFileRefs)\n : {},\n // Absent in any file written before external systems could be declared; an empty\n // table simply draws no shaped nodes, which is exactly the old rendering.\n parsed.externalSystems !== null && typeof parsed.externalSystems === 'object'\n ? (parsed.externalSystems as ExternalSystemDecls)\n : {}\n );\n }\n // Legacy flat format: the whole object is the project map\n return new DependenciesFile('', {}, parsed as EnhancedGraph);\n } catch (err: unknown) {\n const error = toError(err);\n if (error instanceof RuleFailError) throw error;\n throw new Error(`Failed to load graph from ${fullPath}`, { cause: error });\n }\n}\n\n/**\n * The endpoint table moved out of dependencies.json (#949). A file still carrying `apiContracts` was\n * written by an older generator; it is REJECTED rather than read, so there is one place a contract\n * lives and the runtime graph can never read a stale copy of it.\n */\n// webpieces-disable no-function-outside-class -- error builder for loadBlessedGraph, module-scope like its siblings\nfunction movedApiContractsError(fullPath: string, graphPath: string): RuleFailError {\n const apisDir = path.join(path.dirname(graphPath), API_CONTRACTS_DIR);\n return new RuleFailError(\n API_CONTRACT_FILES_RULE,\n `${fullPath} still carries the \\`apiContracts\\` key. It moved: each API's contract now lives in ` +\n `${apisDir}/<ApiName>.json, and dependencies.json only links to it under \\`apiContractFiles\\`.`,\n undefined,\n undefined,\n [new Option('Regenerate the architecture files and commit the result: pnpm nx run architecture:generate', true)],\n );\n}\n\n/**\n * Format the dependencies file as JSON with multi-line arrays for readability\n */\nfunction formatGraphJson(file: DependenciesFile): string {\n const lines: string[] = ['{'];\n lines.push(` \"aiInstructions\": ${JSON.stringify(file.aiInstructions)},`);\n lines.push(` \"commands\": {`);\n const commandNames = Object.keys(file.commands);\n commandNames.forEach((name: string, index: number) => {\n const comma = index === commandNames.length - 1 ? '' : ',';\n lines.push(` ${JSON.stringify(name)}: ${JSON.stringify(file.commands[name])}${comma}`);\n });\n lines.push(` },`);\n lines.push(...apiContractFilesLines(file.apiContractFiles));\n lines.push(...externalSystemsLines(file.externalSystems));\n lines.push(` \"projects\": {`);\n\n const keys = Object.keys(file.projects).sort();\n keys.forEach((key: string, index: number) => {\n const entry = file.projects[key];\n const isLast = index === keys.length - 1;\n const comma = isLast ? '' : ',';\n\n lines.push(` ${JSON.stringify(key)}: {`);\n lines.push(...formatEntryLines(entry));\n lines.push(` }${comma}`);\n });\n\n lines.push(' }');\n lines.push('}');\n return lines.join('\\n') + '\\n';\n}\n\n/**\n * The `\"apiContractFiles\": {...}` block (4-space indent), with a trailing comma since `projects`\n * always follows it. Omitted entirely when empty. Keys are sorted, so the output is deterministic.\n */\n// webpieces-disable no-function-outside-class -- module-scope formatter, matches the sibling formatters here\nfunction apiContractFilesLines(refs: ApiContractFileRefs): string[] {\n if (Object.keys(refs).length === 0) return [];\n const sorted: ApiContractFileRefs = {};\n for (const api of Object.keys(refs).sort()) sorted[api] = refs[api];\n const pretty = JSON.stringify(sorted, null, 4).split('\\n');\n return pretty.map((line: string, index: number) => {\n const prefix = index === 0 ? '\"apiContractFiles\": ' : '';\n const suffix = index === pretty.length - 1 ? ',' : '';\n return ` ${prefix}${line}${suffix}`;\n });\n}\n\n/**\n * The `\"externalSystems\": {...}` block (4-space indent), with a trailing comma since `projects`\n * always follows. Omitted entirely when empty, so a repo that declares none keeps the exact file\n * shape it had before this existed — which is what makes adopting it a no-op diff.\n */\n// webpieces-disable no-function-outside-class -- module-scope formatter, matches the sibling formatters here\nfunction externalSystemsLines(systems: ExternalSystemDecls): string[] {\n if (Object.keys(systems).length === 0) return [];\n const sorted: ExternalSystemDecls = {};\n for (const identity of Object.keys(systems).sort()) sorted[identity] = systems[identity];\n const pretty = JSON.stringify(sorted, null, 4).split('\\n');\n return pretty.map((line: string, index: number) => {\n const prefix = index === 0 ? '\"externalSystems\": ' : '';\n const suffix = index === pretty.length - 1 ? ',' : '';\n return ` ${prefix}${line}${suffix}`;\n });\n}\n\n/**\n * Format one project entry's fields (12-space indent). Optional metadata\n * fields are only emitted when present.\n */\nfunction formatEntryLines(entry: GraphEntry): string[] {\n const lines: string[] = [];\n lines.push(` \"level\": ${entry.level},`);\n\n pushOptionalArrayField(lines, 'framework', entry.framework);\n pushOptionalField(lines, 'role', entry.role);\n // Right after role — role says what the project IS, this says what runtime it speaks. MUST be\n // persisted: validate re-derives the runtime graph from this file, so a field written only\n // in-memory by generate would make the two derive different graphs.\n pushOptionalArrayField(lines, 'webpiecesRuntime', entry.webpiecesRuntime);\n pushOptionalField(lines, 'serviceName', entry.serviceName);\n pushOptionalCallsServiceField(lines, entry.callsService);\n pushOptionalBooleanField(lines, 'drawOnGraph', entry.drawOnGraph);\n // MUST be persisted: validate re-derives the runtime graph from this file, so a cut written only\n // in-memory by generate would make generate and validate level (and cycle-check) different graphs.\n pushOptionalArrayField(lines, 'cutLegacyCycle', entry.cutLegacyCycle);\n pushOptionalField(lines, 'shortDescription', entry.shortDescription);\n pushOptionalField(lines, 'responsibilitiesFile', entry.responsibilitiesFile);\n pushOptionalField(lines, 'designFile', entry.designFile);\n pushApiRelationsField(lines, entry.apiRelations);\n\n if (entry.dependsOn.length === 0) {\n lines.push(` \"dependsOn\": []`);\n } else {\n lines.push(` \"dependsOn\": [`);\n entry.dependsOn.forEach((dep: string, depIndex: number) => {\n const depComma = depIndex === entry.dependsOn.length - 1 ? '' : ',';\n lines.push(` ${JSON.stringify(dep)}${depComma}`);\n });\n lines.push(` ]`);\n }\n return lines;\n}\n\n/**\n * Emit one optional string field (12-space indent), skipped when undefined.\n */\nfunction pushOptionalField(lines: string[], field: string, value: string | undefined): void {\n if (value !== undefined) {\n lines.push(` ${JSON.stringify(field)}: ${JSON.stringify(value)},`);\n }\n}\n\n/**\n * Emit the optional `callsService` field (12-space indent). Unlike serviceName it may be EITHER a\n * single service name (string) OR an { apiClassName: serviceName } map, so it is emitted with\n * JSON.stringify to cover both inline. MUST be persisted here: the runtime graph's target resolution\n * reads it back from the committed dependencies.json during validate — dropping it would make\n * generate (which enriches it in-memory) and validate (which loads this file) derive different graphs.\n */\n// webpieces-disable no-function-outside-class -- module-scope formatter, matches the sibling push*Field helpers here\nfunction pushOptionalCallsServiceField(\n lines: string[],\n value: string | Record<string, string> | undefined,\n): void {\n if (value !== undefined) {\n lines.push(` \"callsService\": ${JSON.stringify(value)},`);\n }\n}\n\n/**\n * Emit one optional boolean field (12-space indent) as a raw JSON boolean\n * (e.g. `\"drawOnGraph\": false,`), skipped when undefined.\n */\n// webpieces-disable no-function-outside-class -- module-scope formatter, matches the sibling push*Field helpers here\nfunction pushOptionalBooleanField(lines: string[], field: string, value: boolean | undefined): void {\n if (value !== undefined) {\n lines.push(` ${JSON.stringify(field)}: ${JSON.stringify(value)},`);\n }\n}\n\n/**\n * Emit one optional string-array field (12-space indent) as a compact inline\n * JSON array (e.g. `\"framework\": [\"browser\",\"node\"],`), skipped when undefined.\n */\nfunction pushOptionalArrayField(lines: string[], field: string, value: string[] | undefined): void {\n if (value !== undefined) {\n lines.push(` ${JSON.stringify(field)}: ${JSON.stringify(value)},`);\n }\n}\n\n/**\n * Emit the optional `apiRelations` object (pretty, multi-line, reindented under\n * the 12-space entry block) with a trailing comma, since `dependsOn` always\n * follows it. Skipped when absent/empty so plain-lib-only projects stay compact.\n * The scanner already sorts owners + refs, so the JSON is deterministic.\n */\n// webpieces-disable no-function-outside-class -- module-scope formatter, matches the sibling push*Field helpers here\nfunction pushApiRelationsField(lines: string[], value: ProjectApiRelations | undefined): void {\n if (value === undefined || Object.keys(value).length === 0) return;\n const pretty = JSON.stringify(value, null, 4).split('\\n');\n pretty.forEach((line: string, index: number) => {\n const prefix = index === 0 ? '\"apiRelations\": ' : '';\n const suffix = index === pretty.length - 1 ? ',' : '';\n lines.push(` ${prefix}${line}${suffix}`);\n });\n}\n\n/**\n * Save the graph to disk in the wrapper format with the standard aiInstructions.\n *\n * @param graph - The enriched project graph to save\n * @param workspaceRoot - Absolute path to workspace root\n * @param graphPath - Relative path to graph file (default: architecture/dependencies.json)\n */\nexport function saveGraph(\n graph: EnhancedGraph,\n workspaceRoot: string,\n graphPath: string = DEFAULT_GRAPH_PATH,\n apiContractFiles: ApiContractFileRefs = {},\n externalSystems: ExternalSystemDecls = {}\n): void {\n const fullPath = path.join(workspaceRoot, graphPath);\n const dir = path.dirname(fullPath);\n\n // Ensure directory exists\n if (!fs.existsSync(dir)) {\n fs.mkdirSync(dir, { recursive: true });\n }\n\n // Sort keys for deterministic output\n const sortedGraph: EnhancedGraph = {};\n const sortedKeys = Object.keys(graph).sort();\n for (const key of sortedKeys) {\n sortedGraph[key] = graph[key];\n }\n\n const content = formatGraphJson(\n new DependenciesFile(AI_INSTRUCTIONS, GRAPH_COMMANDS, sortedGraph, apiContractFiles, externalSystems)\n );\n fs.writeFileSync(fullPath, content, 'utf-8');\n}\n\n/**\n * Check if the graph file exists\n */\nexport function graphFileExists(\n workspaceRoot: string,\n graphPath: string = DEFAULT_GRAPH_PATH\n): boolean {\n const fullPath = path.join(workspaceRoot, graphPath);\n return fs.existsSync(fullPath);\n}\n"]}
|
|
1
|
+
{"version":3,"file":"graph-loader.js","sourceRoot":"","sources":["../../../../../../packages/tooling/nx-webpieces-rules/src/lib/graph-loader.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;;;AAgGH,4CAyCC;AAkND,8BAgCC;AAKD,0CAMC;;AApYD,+CAAyB;AACzB,mDAA6B;AAE7B,0DAAgE;AAEhE,6DAAkF;AAElF,wCAAqC;AAErC;;GAEG;AACU,QAAA,kBAAkB,GAAG,gCAAgC,CAAC;AAEnE;;;GAGG;AACU,QAAA,eAAe,GACxB,sFAAsF;IACtF,oFAAoF;IACpF,kFAAkF;IAClF,mFAAmF;IACnF,kFAAkF;IAClF,2EAA2E;IAC3E,mFAAmF;IACnF,yFAAyF;IACzF,6FAA6F;IAC7F,8FAA8F;IAC9F,+FAA+F;IAC/F,sFAAsF;IACtF,mGAAmG;IACnG,qDAAqD,CAAC;AAO1D;;;;GAIG;AACU,QAAA,cAAc,GAAe;IACtC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P,CAAC;AAED;;;;;;GAMG;AACH,SAAgB,SAAS,CACrB,KAAoB,EACpB,aAAqB,EACrB,YAAoB,0BAAkB,EACtC,mBAAwC,EAAE,EAC1C,kBAAuC,EAAE;IAEzC,MAAM,QAAQ,GAAG,IAAI,CAAC,IAAI,CAAC,aAAa,EAAE,SAAS,CAAC,CAAC;IACrD,MAAM,GAAG,GAAG,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;IAEnC,0BAA0B;IAC1B,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;QACtB,EAAE,CAAC,SAAS,CAAC,GAAG,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IAC3C,CAAC;IAED,qCAAqC;IACrC,MAAM,WAAW,GAAkB,EAAE,CAAC;IACtC,MAAM,UAAU,GAAG,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,IAAI,EAAE,CAAC;IAC7C,KAAK,MAAM,GAAG,IAAI,UAAU,EAAE,CAAC;QAC3B,WAAW,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC;IAClC,CAAC;IAED,MAAM,OAAO,GAAG,eAAe,CAC3B,IAAI,gBAAgB,CAChB,uBAAe,EACf,sBAAc,EACd,WAAW,EACX,gBAAgB,EAChB,eAAe,CAClB,CACJ,CAAC;IACF,EAAE,CAAC,aAAa,CAAC,QAAQ,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;AACjD,CAAC;AAED;;GAEG;AACH,SAAgB,eAAe,CAC3B,aAAqB,EACrB,YAAoB,0BAAkB;IAEtC,MAAM,QAAQ,GAAG,IAAI,CAAC,IAAI,CAAC,aAAa,EAAE,SAAS,CAAC,CAAC;IACrD,OAAO,EAAE,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC;AACnC,CAAC","sourcesContent":["/**\n * Graph Loader\n *\n * Handles loading and saving the blessed dependency graph file.\n * The graph is stored at architecture/dependencies.json in the workspace root.\n *\n * File format (schema aimed at AI consumers):\n * {\n * \"aiInstructions\": \"...how AI should use the per-project fields...\",\n * \"apiContractFiles\": { \"<ApiName>\": \"apis/<ApiName>.json\" },\n * \"projects\": {\n * \"<project>\": { level, framework, shortDescription,\n * responsibilitiesFile, designFile, dependsOn }\n * }\n * }\n *\n * `framework` is the project's libType — the SET of runtime environments it is\n * validated to run in, drawn from browser | react | angular | node | express\n * (e.g. [\"browser\",\"node\"]). It comes from the project's `framework:` nx tags\n * and is enforced across edges by the `library-types-match-client` rule.\n *\n * The legacy format (flat { \"<project>\": { level, dependsOn } } map) is still\n * readable so validation against a pre-upgrade file produces a clean\n * \"re-run architecture:generate\" diff instead of a parse failure.\n */\n\nimport * as fs from 'fs';\nimport * as path from 'path';\nimport type { EnhancedGraph, GraphEntry } from './graph-sorter';\nimport { RuleFailError, Option } from '@webpieces/rules-config';\nimport type { ExternalSystemDecls, ProjectApiRelations } from './api-usage/api-relations';\nimport { API_CONTRACT_FILES_RULE, API_CONTRACTS_DIR } from './api-contract-files';\nimport type { ApiContractFileRefs } from './api-contract-files';\nimport { toError } from '../toError';\n\n/**\n * Default path for the dependencies file (relative to workspace root)\n */\nexport const DEFAULT_GRAPH_PATH = 'architecture/dependencies.json';\n\n/**\n * Top-level instructions embedded in dependencies.json telling AI how to use\n * the per-project metadata fields.\n */\nexport const AI_INSTRUCTIONS =\n \"Each project's shortDescription is only a summary. BEFORE adding code to a project, \" +\n 'read its responsibilitiesFile for the full responsibilities (what belongs in that ' +\n 'project and what does not), and read its designFile to understand the DI design ' +\n 'before reading the code. Use the entries in `commands` to regenerate these files ' +\n 'or display any of the graphs in a browser. To hide a project (its box AND every ' +\n 'edge touching it) from BOTH rendered architecture graphs, add the nx tag ' +\n \"'drawOnGraph:false' to that project's project.json tags and regenerate; it stays \" +\n 'in this file (marked \"drawOnGraph\": false) but is omitted from the HTML. A role:server ' +\n 'with no webpiecesRuntime package anywhere in its dependency closure and no apiRelations is ' +\n 'omitted from the RUNTIME drawing the same way — it speaks none of the webpieces runtime, so ' +\n \"it can only ever draw as a disconnected box; it stays in both JSON files. An API's endpoints \" +\n '(name, kind, path, httpMethod, parameters, queueName, caller) are NOT in this file: ' +\n '`apiContractFiles` maps each API to its generated contract file, apis/<ApiName>.json relative to ' +\n \"this file — read that file for the API's endpoints.\";\n\n/**\n * Named command → \"command — what it does\" map embedded in dependencies.json.\n */\nexport type CommandMap = Record<string, string>;\n\n/**\n * Commands embedded in dependencies.json so AI (and humans) know how to\n * regenerate and DISPLAY the architecture + design graphs. These work in any\n * repo consuming @webpieces/nx-webpieces-rules.\n */\nexport const GRAPH_COMMANDS: CommandMap = {\n regenerateArchitecture:\n 'pnpm nx run architecture:generate — rewrites architecture/dependencies.json, ' +\n 'architecture/apis/<ApiName>.json and architecture/runtime-dependencies.json; run after ' +\n 'reviewing project runtime-deps.json and API contract candidates into architecture/apis; generation reads approvals and never approves endpoint changes',\n visualizeArchitecture:\n 'pnpm nx run architecture:visualize — opens the monorepo dependency graph (this file) ' +\n 'as HTML in a browser from saved data, without refreshing; freshness unknown',\n visualizeRuntimeArchitecture:\n 'pnpm nx run architecture:visualize-runtime — opens the runtime microservice call graph ' +\n 'as HTML in a browser from saved data, without refreshing; freshness unknown',\n regenerateDesigns:\n \"pnpm nx run-many --target=di-graph-generate — rewrites every project's \" +\n 'design.json/design.md (also runs automatically on every build)',\n visualizeDesign:\n \"pnpm wp-design-visualize <project> — opens a project's DI designs (its designFile) as \" +\n 'HTML, one graph per controller with the controller at the top; no args = interactive picker',\n};\n\n/**\n * The full contents of architecture/dependencies.json.\n */\nexport class DependenciesFile {\n constructor(\n public readonly aiInstructions: string,\n public readonly commands: CommandMap,\n public readonly projects: EnhancedGraph,\n /**\n * apiClassName -> its contract file (`apis/<ApiName>.json`, relative to this file's\n * directory). Only the LINK lives here, so adding an endpoint never changes dependencies.json;\n * the contract itself is read with ApiContractFiles.load.\n */\n public readonly apiContractFiles: ApiContractFileRefs = {},\n /**\n * Declared external systems (databases, buckets, ...) keyed by identity. MUST be persisted:\n * the runtime graph is derived from the committed files, so a declaration that is scanned but\n * not written would make generate and validate disagree.\n */\n public readonly externalSystems: ExternalSystemDecls = {},\n ) {}\n}\n\n/**\n * Load the blessed graph from disk. Understands both the current wrapper\n * format and the legacy flat map (which loads with empty aiInstructions).\n *\n * @param workspaceRoot - Absolute path to workspace root\n * @param graphPath - Relative path to graph file (default: architecture/dependencies.json)\n * @returns The blessed graph file, or null if it doesn't exist\n */\nexport function loadBlessedGraph(\n workspaceRoot: string,\n graphPath: string = DEFAULT_GRAPH_PATH,\n): DependenciesFile | null {\n const fullPath = path.join(workspaceRoot, graphPath);\n\n if (!fs.existsSync(fullPath)) {\n return null;\n }\n\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions\n try {\n const content = fs.readFileSync(fullPath, 'utf-8');\n const parsed = JSON.parse(content);\n if (parsed !== null && typeof parsed === 'object' && 'apiContracts' in parsed) {\n throw movedApiContractsError(fullPath, graphPath);\n }\n if (parsed !== null && typeof parsed === 'object' && 'projects' in parsed) {\n return new DependenciesFile(\n typeof parsed.aiInstructions === 'string' ? parsed.aiInstructions : '',\n parsed.commands !== null && typeof parsed.commands === 'object'\n ? (parsed.commands as CommandMap)\n : {},\n parsed.projects as EnhancedGraph,\n parsed.apiContractFiles !== null && typeof parsed.apiContractFiles === 'object'\n ? (parsed.apiContractFiles as ApiContractFileRefs)\n : {},\n // Absent in any file written before external systems could be declared; an empty\n // table simply draws no shaped nodes, which is exactly the old rendering.\n parsed.externalSystems !== null && typeof parsed.externalSystems === 'object'\n ? (parsed.externalSystems as ExternalSystemDecls)\n : {},\n );\n }\n // Legacy flat format: the whole object is the project map\n return new DependenciesFile('', {}, parsed as EnhancedGraph);\n } catch (err: unknown) {\n const error = toError(err);\n if (error instanceof RuleFailError) throw error;\n throw new Error(`Failed to load graph from ${fullPath}`, { cause: error });\n }\n}\n\n/**\n * The endpoint table moved out of dependencies.json (#949). A file still carrying `apiContracts` was\n * written by an older generator; it is REJECTED rather than read, so there is one place a contract\n * lives and the runtime graph can never read a stale copy of it.\n */\n// webpieces-disable no-function-outside-class -- error builder for loadBlessedGraph, module-scope like its siblings\nfunction movedApiContractsError(fullPath: string, graphPath: string): RuleFailError {\n const apisDir = path.join(path.dirname(graphPath), API_CONTRACTS_DIR);\n return new RuleFailError(\n API_CONTRACT_FILES_RULE,\n `${fullPath} still carries the \\`apiContracts\\` key. It moved: each API's contract now lives in ` +\n `${apisDir}/<ApiName>.json, and dependencies.json only links to it under \\`apiContractFiles\\`.`,\n undefined,\n undefined,\n [\n new Option(\n `Explicitly move each saved apiContracts.<ApiName> value into ${apisDir}/<ApiName>.json, replace apiContracts with reviewed apiContractFiles entries mapping each name to apis/<ApiName>.json, preserve externalSystems, and approve runtime-deps.json for all runtime owners. Then run pnpm nx run architecture:generate and review the result.`,\n true,\n ),\n ],\n );\n}\n\n/**\n * Format the dependencies file as JSON with multi-line arrays for readability\n */\nfunction formatGraphJson(file: DependenciesFile): string {\n const lines: string[] = ['{'];\n lines.push(` \"aiInstructions\": ${JSON.stringify(file.aiInstructions)},`);\n lines.push(` \"commands\": {`);\n const commandNames = Object.keys(file.commands);\n commandNames.forEach((name: string, index: number) => {\n const comma = index === commandNames.length - 1 ? '' : ',';\n lines.push(\n ` ${JSON.stringify(name)}: ${JSON.stringify(file.commands[name])}${comma}`,\n );\n });\n lines.push(` },`);\n lines.push(...apiContractFilesLines(file.apiContractFiles));\n lines.push(...externalSystemsLines(file.externalSystems));\n lines.push(` \"projects\": {`);\n\n const keys = Object.keys(file.projects).sort();\n keys.forEach((key: string, index: number) => {\n const entry = file.projects[key];\n const isLast = index === keys.length - 1;\n const comma = isLast ? '' : ',';\n\n lines.push(` ${JSON.stringify(key)}: {`);\n lines.push(...formatEntryLines(entry));\n lines.push(` }${comma}`);\n });\n\n lines.push(' }');\n lines.push('}');\n return lines.join('\\n') + '\\n';\n}\n\n/**\n * The `\"apiContractFiles\": {...}` block (4-space indent), with a trailing comma since `projects`\n * always follows it. Omitted entirely when empty. Keys are sorted, so the output is deterministic.\n */\n// webpieces-disable no-function-outside-class -- module-scope formatter, matches the sibling formatters here\nfunction apiContractFilesLines(refs: ApiContractFileRefs): string[] {\n if (Object.keys(refs).length === 0) return [];\n const sorted: ApiContractFileRefs = {};\n for (const api of Object.keys(refs).sort()) sorted[api] = refs[api];\n const pretty = JSON.stringify(sorted, null, 4).split('\\n');\n return pretty.map((line: string, index: number) => {\n const prefix = index === 0 ? '\"apiContractFiles\": ' : '';\n const suffix = index === pretty.length - 1 ? ',' : '';\n return ` ${prefix}${line}${suffix}`;\n });\n}\n\n/**\n * The `\"externalSystems\": {...}` block (4-space indent), with a trailing comma since `projects`\n * always follows. Omitted entirely when empty, so a repo that declares none keeps the exact file\n * shape it had before this existed — which is what makes adopting it a no-op diff.\n */\n// webpieces-disable no-function-outside-class -- module-scope formatter, matches the sibling formatters here\nfunction externalSystemsLines(systems: ExternalSystemDecls): string[] {\n if (Object.keys(systems).length === 0) return [];\n const sorted: ExternalSystemDecls = {};\n for (const identity of Object.keys(systems).sort()) sorted[identity] = systems[identity];\n const pretty = JSON.stringify(sorted, null, 4).split('\\n');\n return pretty.map((line: string, index: number) => {\n const prefix = index === 0 ? '\"externalSystems\": ' : '';\n const suffix = index === pretty.length - 1 ? ',' : '';\n return ` ${prefix}${line}${suffix}`;\n });\n}\n\n/**\n * Format one project entry's fields (12-space indent). Optional metadata\n * fields are only emitted when present.\n */\nfunction formatEntryLines(entry: GraphEntry): string[] {\n const lines: string[] = [];\n lines.push(` \"level\": ${entry.level},`);\n\n pushOptionalArrayField(lines, 'framework', entry.framework);\n pushOptionalField(lines, 'role', entry.role);\n // Right after role — role says what the project IS, this says what runtime it speaks. MUST be\n // persisted: validate re-derives the runtime graph from this file, so a field written only\n // in-memory by generate would make the two derive different graphs.\n pushOptionalArrayField(lines, 'webpiecesRuntime', entry.webpiecesRuntime);\n pushOptionalField(lines, 'serviceName', entry.serviceName);\n pushOptionalCallsServiceField(lines, entry.callsService);\n pushOptionalBooleanField(lines, 'drawOnGraph', entry.drawOnGraph);\n // MUST be persisted: validate re-derives the runtime graph from this file, so a cut written only\n // in-memory by generate would make generate and validate level (and cycle-check) different graphs.\n pushOptionalArrayField(lines, 'cutLegacyCycle', entry.cutLegacyCycle);\n pushOptionalField(lines, 'shortDescription', entry.shortDescription);\n pushOptionalField(lines, 'responsibilitiesFile', entry.responsibilitiesFile);\n pushOptionalField(lines, 'designFile', entry.designFile);\n pushApiRelationsField(lines, entry.apiRelations);\n pushOptionalField(lines, 'runtimeDeclaration', entry.runtimeDeclaration);\n pushOptionalBooleanField(lines, 'runtimeComposition', entry.runtimeComposition);\n\n if (entry.dependsOn.length === 0) {\n lines.push(` \"dependsOn\": []`);\n } else {\n lines.push(` \"dependsOn\": [`);\n entry.dependsOn.forEach((dep: string, depIndex: number) => {\n const depComma = depIndex === entry.dependsOn.length - 1 ? '' : ',';\n lines.push(` ${JSON.stringify(dep)}${depComma}`);\n });\n lines.push(` ]`);\n }\n return lines;\n}\n\n/**\n * Emit one optional string field (12-space indent), skipped when undefined.\n */\nfunction pushOptionalField(lines: string[], field: string, value: string | undefined): void {\n if (value !== undefined) {\n lines.push(` ${JSON.stringify(field)}: ${JSON.stringify(value)},`);\n }\n}\n\n/**\n * Emit the optional `callsService` field (12-space indent). Unlike serviceName it may be EITHER a\n * single service name (string) OR an { apiClassName: serviceName } map, so it is emitted with\n * JSON.stringify to cover both inline. MUST be persisted here: the runtime graph's target resolution\n * reads it back from the committed dependencies.json during validate — dropping it would make\n * generate (which enriches it in-memory) and validate (which loads this file) derive different graphs.\n */\n// webpieces-disable no-function-outside-class -- module-scope formatter, matches the sibling push*Field helpers here\nfunction pushOptionalCallsServiceField(\n lines: string[],\n value: string | Record<string, string> | undefined,\n): void {\n if (value !== undefined) {\n lines.push(` \"callsService\": ${JSON.stringify(value)},`);\n }\n}\n\n/**\n * Emit one optional boolean field (12-space indent) as a raw JSON boolean\n * (e.g. `\"drawOnGraph\": false,`), skipped when undefined.\n */\n// webpieces-disable no-function-outside-class -- module-scope formatter, matches the sibling push*Field helpers here\nfunction pushOptionalBooleanField(\n lines: string[],\n field: string,\n value: boolean | undefined,\n): void {\n if (value !== undefined) {\n lines.push(` ${JSON.stringify(field)}: ${JSON.stringify(value)},`);\n }\n}\n\n/**\n * Emit one optional string-array field (12-space indent) as a compact inline\n * JSON array (e.g. `\"framework\": [\"browser\",\"node\"],`), skipped when undefined.\n */\nfunction pushOptionalArrayField(lines: string[], field: string, value: string[] | undefined): void {\n if (value !== undefined) {\n lines.push(` ${JSON.stringify(field)}: ${JSON.stringify(value)},`);\n }\n}\n\n/**\n * Emit the optional `apiRelations` object (pretty, multi-line, reindented under\n * the 12-space entry block) with a trailing comma, since `dependsOn` always\n * follows it. Skipped when absent/empty so plain-lib-only projects stay compact.\n * The scanner already sorts owners + refs, so the JSON is deterministic.\n */\n// webpieces-disable no-function-outside-class -- module-scope formatter, matches the sibling push*Field helpers here\nfunction pushApiRelationsField(lines: string[], value: ProjectApiRelations | undefined): void {\n if (value === undefined || Object.keys(value).length === 0) return;\n const pretty = JSON.stringify(value, null, 4).split('\\n');\n pretty.forEach((line: string, index: number) => {\n const prefix = index === 0 ? '\"apiRelations\": ' : '';\n const suffix = index === pretty.length - 1 ? ',' : '';\n lines.push(` ${prefix}${line}${suffix}`);\n });\n}\n\n/**\n * Save the graph to disk in the wrapper format with the standard aiInstructions.\n *\n * @param graph - The enriched project graph to save\n * @param workspaceRoot - Absolute path to workspace root\n * @param graphPath - Relative path to graph file (default: architecture/dependencies.json)\n */\nexport function saveGraph(\n graph: EnhancedGraph,\n workspaceRoot: string,\n graphPath: string = DEFAULT_GRAPH_PATH,\n apiContractFiles: ApiContractFileRefs = {},\n externalSystems: ExternalSystemDecls = {},\n): void {\n const fullPath = path.join(workspaceRoot, graphPath);\n const dir = path.dirname(fullPath);\n\n // Ensure directory exists\n if (!fs.existsSync(dir)) {\n fs.mkdirSync(dir, { recursive: true });\n }\n\n // Sort keys for deterministic output\n const sortedGraph: EnhancedGraph = {};\n const sortedKeys = Object.keys(graph).sort();\n for (const key of sortedKeys) {\n sortedGraph[key] = graph[key];\n }\n\n const content = formatGraphJson(\n new DependenciesFile(\n AI_INSTRUCTIONS,\n GRAPH_COMMANDS,\n sortedGraph,\n apiContractFiles,\n externalSystems,\n ),\n );\n fs.writeFileSync(fullPath, content, 'utf-8');\n}\n\n/**\n * Check if the graph file exists\n */\nexport function graphFileExists(\n workspaceRoot: string,\n graphPath: string = DEFAULT_GRAPH_PATH,\n): boolean {\n const fullPath = path.join(workspaceRoot, graphPath);\n return fs.existsSync(fullPath);\n}\n"]}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GraphNavigation = void 0;
|
|
4
|
+
/** Shared local-file navigation. Reset restores readable scale; Fit is an explicit overview. */
|
|
5
|
+
class GraphNavigation {
|
|
6
|
+
styles() {
|
|
7
|
+
return `
|
|
8
|
+
#graph { overflow: auto; max-height: 75vh; text-align: left; touch-action: pan-x pan-y; }
|
|
9
|
+
#graph svg { max-width: none; max-height: none; display: block; }
|
|
10
|
+
.wp-navigation { display: flex; gap: 8px; align-items: center; margin: 10px 0; }
|
|
11
|
+
.wp-navigation button { padding: 6px 12px; cursor: pointer; }
|
|
12
|
+
.wp-graph-details { position: fixed; z-index: 1100; box-sizing: border-box; max-width: min(520px, calc(100vw - 24px)); max-height: min(480px, calc(100vh - 24px)); overflow: auto; background: white; padding: 12px; border: 1px solid #aaa; border-radius: 6px; box-shadow: 0 4px 16px #0003; font: 14px/1.5 Arial, sans-serif; overflow-wrap: anywhere; }
|
|
13
|
+
.wp-graph-details li { margin-bottom: 8px; }
|
|
14
|
+
.wp-api-detail { cursor: pointer; text-decoration: underline; }
|
|
15
|
+
.wp-api-detail:focus { outline: 2px solid #1565c0; }
|
|
16
|
+
`;
|
|
17
|
+
}
|
|
18
|
+
script() {
|
|
19
|
+
return `new (${GraphNavigationController.toString()})();`;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
exports.GraphNavigation = GraphNavigation;
|
|
23
|
+
/** Serialized browser controller; dependencies are native DOM APIs only. */
|
|
24
|
+
class GraphNavigationController {
|
|
25
|
+
host = document.getElementById('graph');
|
|
26
|
+
toolbar = document.createElement('nav');
|
|
27
|
+
status = document.createElement('output');
|
|
28
|
+
svg = null;
|
|
29
|
+
scale = 1;
|
|
30
|
+
constructor() {
|
|
31
|
+
if (this.host === null)
|
|
32
|
+
return;
|
|
33
|
+
this.toolbar.className = 'wp-navigation';
|
|
34
|
+
this.toolbar.setAttribute('aria-label', 'Graph navigation');
|
|
35
|
+
this.host.before(this.toolbar);
|
|
36
|
+
this.button('Zoom in', () => this.zoom(1.25));
|
|
37
|
+
this.button('Zoom out', () => this.zoom(0.8));
|
|
38
|
+
this.button('Readable reset', () => this.reset());
|
|
39
|
+
this.button('Fit overview', () => this.fit());
|
|
40
|
+
this.toolbar.append(this.status);
|
|
41
|
+
new MutationObserver(() => this.attach()).observe(this.host, { childList: true });
|
|
42
|
+
this.attach();
|
|
43
|
+
window.addEventListener('resize', () => this.changed());
|
|
44
|
+
this.host.addEventListener('scroll', () => this.changed());
|
|
45
|
+
}
|
|
46
|
+
button(label, action) {
|
|
47
|
+
const button = document.createElement('button');
|
|
48
|
+
button.type = 'button';
|
|
49
|
+
button.textContent = label;
|
|
50
|
+
button.addEventListener('click', action);
|
|
51
|
+
this.toolbar.append(button);
|
|
52
|
+
}
|
|
53
|
+
changed() {
|
|
54
|
+
document.dispatchEvent(new Event('wp-graph-transform'));
|
|
55
|
+
}
|
|
56
|
+
resize() {
|
|
57
|
+
if (this.svg === null)
|
|
58
|
+
return;
|
|
59
|
+
const box = this.svg.viewBox.baseVal;
|
|
60
|
+
this.svg.style.width = `${box.width * this.scale}px`;
|
|
61
|
+
this.svg.style.height = `${box.height * this.scale}px`;
|
|
62
|
+
this.status.textContent = `${Math.round(this.scale * 100)}%`;
|
|
63
|
+
this.changed();
|
|
64
|
+
}
|
|
65
|
+
zoom(factor) {
|
|
66
|
+
if (this.host === null)
|
|
67
|
+
return;
|
|
68
|
+
const before = this.scale;
|
|
69
|
+
this.scale = Math.max(0.1, Math.min(4, this.scale * factor));
|
|
70
|
+
const centerX = this.host.scrollLeft + this.host.clientWidth / 2;
|
|
71
|
+
const centerY = this.host.scrollTop + this.host.clientHeight / 2;
|
|
72
|
+
this.resize();
|
|
73
|
+
this.host.scrollLeft = (centerX * this.scale) / before - this.host.clientWidth / 2;
|
|
74
|
+
this.host.scrollTop = (centerY * this.scale) / before - this.host.clientHeight / 2;
|
|
75
|
+
}
|
|
76
|
+
reset() {
|
|
77
|
+
this.scale = 1;
|
|
78
|
+
this.resize();
|
|
79
|
+
this.scrollOrigin();
|
|
80
|
+
}
|
|
81
|
+
scrollOrigin() {
|
|
82
|
+
if (this.host === null)
|
|
83
|
+
return;
|
|
84
|
+
this.host.scrollLeft = 0;
|
|
85
|
+
this.host.scrollTop = 0;
|
|
86
|
+
}
|
|
87
|
+
fit() {
|
|
88
|
+
if (this.svg === null || this.host === null)
|
|
89
|
+
return;
|
|
90
|
+
this.scale = Math.min(1, this.host.clientWidth / this.svg.viewBox.baseVal.width, this.host.clientHeight / this.svg.viewBox.baseVal.height);
|
|
91
|
+
this.resize();
|
|
92
|
+
this.scrollOrigin();
|
|
93
|
+
}
|
|
94
|
+
attach() {
|
|
95
|
+
const next = this.host?.querySelector('svg');
|
|
96
|
+
if (next === null || next === undefined || next === this.svg)
|
|
97
|
+
return;
|
|
98
|
+
this.svg = next;
|
|
99
|
+
this.reset();
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
//# sourceMappingURL=graph-navigation.js.map
|