@saptools/service-flow 0.1.61 → 0.1.62
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/CHANGELOG.md +5 -0
- package/dist/cli.js +10 -5
- package/dist/cli.js.map +1 -1
- package/package.json +1 -1
- package/src/output/mermaid-output.ts +9 -4
package/package.json
CHANGED
|
@@ -1,16 +1,21 @@
|
|
|
1
1
|
import type { TraceResult } from '../types.js';
|
|
2
|
-
function safe(value: string): string {
|
|
3
|
-
return value.replace(/[^\w-]/g, '_').slice(0, 60);
|
|
4
|
-
}
|
|
5
2
|
function label(trace: TraceResult, idOrLabel: string): string {
|
|
6
3
|
const node = trace.nodes.find((item) => item.id === idOrLabel || item.label === idOrLabel);
|
|
7
4
|
return String(node?.label ?? idOrLabel);
|
|
8
5
|
}
|
|
9
6
|
export function renderMermaid(trace: TraceResult): string {
|
|
7
|
+
const ids = new Map<string, string>();
|
|
8
|
+
const nodeId = (value: string): string => {
|
|
9
|
+
const existing = ids.get(value);
|
|
10
|
+
if (existing) return existing;
|
|
11
|
+
const id = `n${ids.size}`;
|
|
12
|
+
ids.set(value, id);
|
|
13
|
+
return id;
|
|
14
|
+
};
|
|
10
15
|
const lines = ['flowchart TD'];
|
|
11
16
|
for (const e of trace.edges)
|
|
12
17
|
lines.push(
|
|
13
|
-
` ${
|
|
18
|
+
` ${nodeId(e.from)}["${label(trace, e.from)}"] -->|${e.type}| ${nodeId(e.to)}["${label(trace, e.to)}"]`
|
|
14
19
|
);
|
|
15
20
|
return `${lines.join('\n')}\n`;
|
|
16
21
|
}
|