nerdgram1337 1.6.1 → 1.8.5

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.
@@ -7,7 +7,7 @@ import {
7
7
  isDiagramLink,
8
8
  parseClickLine,
9
9
  resolveDiagramTarget
10
- } from "./chunk-5C6VO4LC.js";
10
+ } from "./chunk-BW6ANOTX.js";
11
11
  import {
12
12
  ELK_NODE_PLACEMENTS,
13
13
  FLOWCHART_CURVES,
@@ -113,7 +113,7 @@ function normalizeLintRules(value) {
113
113
  }
114
114
  return out;
115
115
  }
116
- function lintDiagram(source, options = {}) {
116
+ function lintDiagramContent(source, options = {}) {
117
117
  const enabled = normalizeLintRules(options.rules);
118
118
  const diagnostics = [];
119
119
  if (enabled["front-matter"]) diagnostics.push(...lintFrontMatter(source));
@@ -123,9 +123,6 @@ function lintDiagram(source, options = {}) {
123
123
  if (enabled["unlabeled-endpoint"]) diagnostics.push(...unlabeledEndpoints(model));
124
124
  if (enabled["unused-class"]) diagnostics.push(...unusedClasses(model));
125
125
  if (enabled["undefined-class"]) diagnostics.push(...undefinedClasses(source, model));
126
- if (enabled["broken-click"] && options.diagramPaths) {
127
- diagnostics.push(...brokenClicks(model, options.diagramPaths, options.sourcePath ?? ""));
128
- }
129
126
  if (model.kind === "class" && (enabled["duplicate-class"] || enabled["undeclared-class"])) {
130
127
  const classDiagram = scanClassDiagram(source);
131
128
  if (enabled["duplicate-class"]) diagnostics.push(...duplicateClasses(classDiagram));
@@ -146,6 +143,17 @@ function lintDiagram(source, options = {}) {
146
143
  if (enabled["duplicate-sibling"]) diagnostics.push(...outline.duplicates);
147
144
  if (enabled["empty-node"]) diagnostics.push(...outline.empties);
148
145
  }
146
+ return { diagnostics, clicks: model.clicks };
147
+ }
148
+ function brokenClickFindings(clicks, paths, sourcePath) {
149
+ return brokenClicks(clicks, paths, sourcePath);
150
+ }
151
+ function lintDiagram(source, options = {}) {
152
+ const enabled = normalizeLintRules(options.rules);
153
+ const { diagnostics, clicks } = lintDiagramContent(source, options);
154
+ if (enabled["broken-click"] && options.diagramPaths) {
155
+ diagnostics.push(...brokenClickFindings(clicks, options.diagramPaths, options.sourcePath ?? ""));
156
+ }
149
157
  diagnostics.sort((a, b) => a.from - b.from || a.line - b.line || a.ruleId.localeCompare(b.ruleId));
150
158
  return diagnostics;
151
159
  }
@@ -400,9 +408,9 @@ function undefinedClasses(source, model) {
400
408
  }
401
409
  return diagnostics;
402
410
  }
403
- function brokenClicks(model, paths, sourcePath) {
411
+ function brokenClicks(clicks, paths, sourcePath) {
404
412
  const diagnostics = [];
405
- for (const click of model.clicks) {
413
+ for (const click of clicks) {
406
414
  if (diagramTargetExists(click.target, paths, sourcePath)) continue;
407
415
  const resolved = resolveDiagramTarget(click.target, sourcePath);
408
416
  const message = resolved.ok === false && resolved.reason === "escape" ? `The click link "${click.target}" leaves the workspace and does not match a diagram.` : `The click link "${click.target}" does not match a diagram in this workspace.`;
@@ -1976,7 +1984,12 @@ async function lintDiagramSource(source, options = {}) {
1976
1984
  );
1977
1985
  return omitMutedWarnings(source, combined);
1978
1986
  }
1987
+
1979
1988
  export {
1980
- lintDiagramSource,
1981
- mermaidSyntaxDiagnostic
1989
+ LINT_RULE_IDS,
1990
+ lintDiagramContent,
1991
+ brokenClickFindings,
1992
+ warningsMuted,
1993
+ mermaidSyntaxDiagnostic,
1994
+ lintDiagramSource
1982
1995
  };
@@ -0,0 +1,14 @@
1
+ // server/src/dataFiles.ts
2
+ var DATA_FILE_EXTENSIONS = [".network.json", ".csv", ".json", ".cdp", ".lldp"];
3
+ function dataFileExtension(name) {
4
+ const lower = name.toLowerCase();
5
+ return DATA_FILE_EXTENSIONS.find((ext) => lower.endsWith(ext)) ?? "";
6
+ }
7
+ function isDataFileName(name) {
8
+ return dataFileExtension(name) !== "";
9
+ }
10
+
11
+ export {
12
+ dataFileExtension,
13
+ isDataFileName
14
+ };
@@ -0,0 +1,9 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __export = (target, all) => {
3
+ for (var name in all)
4
+ __defProp(target, name, { get: all[name], enumerable: true });
5
+ };
6
+
7
+ export {
8
+ __export
9
+ };
@@ -0,0 +1,196 @@
1
+ import {
2
+ reportUnreadable
3
+ } from "./chunk-GK3V52XM.js";
4
+ import {
5
+ LINT_RULE_IDS,
6
+ brokenClickFindings,
7
+ lintDiagramContent,
8
+ mermaidSyntaxDiagnostic,
9
+ warningsMuted
10
+ } from "./chunk-M4HT24R6.js";
11
+
12
+ // server/src/diagramLintCache.ts
13
+ import { createHash } from "node:crypto";
14
+ var CONCURRENCY = 4;
15
+ var entries = /* @__PURE__ */ new Map();
16
+ var pathSetHash = "";
17
+ var rulesKey = "";
18
+ var last = null;
19
+ var stale = false;
20
+ var inflight = null;
21
+ function invalidateDiagramLint(paths) {
22
+ if (!paths) {
23
+ entries.clear();
24
+ pathSetHash = "";
25
+ if (last) stale = true;
26
+ return;
27
+ }
28
+ let changed = false;
29
+ for (const item of paths) {
30
+ if (entries.delete(item)) changed = true;
31
+ }
32
+ if (changed && last) stale = true;
33
+ }
34
+ function clearDiagramLintCache() {
35
+ entries.clear();
36
+ pathSetHash = "";
37
+ rulesKey = "";
38
+ last = null;
39
+ stale = false;
40
+ }
41
+ function diagramLintSummary() {
42
+ if (!last) {
43
+ return {
44
+ status: "not-checked",
45
+ checkedAt: null,
46
+ stale: false,
47
+ checked: null,
48
+ errors: null,
49
+ warnings: null,
50
+ unreadable: null,
51
+ muted: null,
52
+ diagrams: null
53
+ };
54
+ }
55
+ let errors = 0;
56
+ let warnings = 0;
57
+ const diagrams = last.diagrams.map((diagram) => {
58
+ const diagramErrors = diagram.diagnostics.filter((item) => item.severity === "error").length;
59
+ const diagramWarnings = diagram.diagnostics.length - diagramErrors;
60
+ errors += diagramErrors;
61
+ warnings += diagramWarnings;
62
+ return { path: diagram.path, errors: diagramErrors, warnings: diagramWarnings };
63
+ });
64
+ return {
65
+ status: "ready",
66
+ checkedAt: last.cachedAt,
67
+ stale,
68
+ checked: last.checked,
69
+ errors,
70
+ warnings,
71
+ unreadable: last.unreadable.length,
72
+ muted: last.muted.length,
73
+ diagrams
74
+ };
75
+ }
76
+ function hashText(text) {
77
+ return createHash("sha256").update(text, "utf8").digest("hex");
78
+ }
79
+ function hashPaths(paths) {
80
+ return createHash("sha256").update(paths.join("\n"), "utf8").digest("hex");
81
+ }
82
+ async function pool(items, limit, run) {
83
+ let next = 0;
84
+ const workers = Array.from({ length: Math.min(limit, items.length) }, async () => {
85
+ while (next < items.length) {
86
+ const index = next;
87
+ next += 1;
88
+ const item = items[index];
89
+ if (item !== void 0) await run(item);
90
+ }
91
+ });
92
+ await Promise.all(workers);
93
+ }
94
+ function visibleDiagnostics(entry, paths, sourcePath) {
95
+ const links = brokenClickFindings(entry.clicks, paths, sourcePath);
96
+ const combined = [...entry.diagnostics, ...links];
97
+ const kept = entry.muted ? combined.filter((item) => item.severity !== "warning") : combined;
98
+ kept.sort((a, b) => a.from - b.from || a.line - b.line || a.ruleId.localeCompare(b.ruleId));
99
+ return kept;
100
+ }
101
+ async function execute(input) {
102
+ const started = Date.now();
103
+ const signature = LINT_RULE_IDS.join(",");
104
+ if (rulesKey && rulesKey !== signature) {
105
+ entries.clear();
106
+ pathSetHash = "";
107
+ }
108
+ rulesKey = signature;
109
+ const paths = input.files.map((file) => file.path);
110
+ const nextHash = hashPaths(paths);
111
+ let relinted = 0;
112
+ const unreadable = [];
113
+ const seen = new Set(paths);
114
+ await pool(input.files, CONCURRENCY, async (file) => {
115
+ let stat;
116
+ try {
117
+ stat = await input.stat(file.path);
118
+ } catch (err) {
119
+ unreadable.push(reportUnreadable(file.path, err));
120
+ entries.delete(file.path);
121
+ return;
122
+ }
123
+ if (!stat) {
124
+ unreadable.push(reportUnreadable(file.path, Object.assign(new Error("missing"), { code: "ENOENT" })));
125
+ entries.delete(file.path);
126
+ return;
127
+ }
128
+ const cached = entries.get(file.path);
129
+ if (cached && cached.size === stat.size && cached.mtimeMs === stat.mtimeMs) return;
130
+ let content;
131
+ try {
132
+ content = (await input.read(file.path)).content;
133
+ } catch (err) {
134
+ unreadable.push(reportUnreadable(file.path, err));
135
+ entries.delete(file.path);
136
+ return;
137
+ }
138
+ const digest = hashText(content);
139
+ if (cached && cached.hash === digest) {
140
+ entries.set(file.path, { ...cached, size: stat.size, mtimeMs: stat.mtimeMs });
141
+ return;
142
+ }
143
+ const parsed = lintDiagramContent(content);
144
+ const syntax = await mermaidSyntaxDiagnostic(content);
145
+ const diagnostics = syntax ? [...parsed.diagnostics, syntax] : parsed.diagnostics;
146
+ entries.set(file.path, {
147
+ size: stat.size,
148
+ mtimeMs: stat.mtimeMs,
149
+ hash: digest,
150
+ diagnostics,
151
+ clicks: parsed.clicks,
152
+ muted: warningsMuted(content)
153
+ });
154
+ relinted += 1;
155
+ });
156
+ for (const key of [...entries.keys()]) {
157
+ if (!seen.has(key)) entries.delete(key);
158
+ }
159
+ const muted = [];
160
+ const diagrams = [];
161
+ for (const filePath of paths) {
162
+ const entry = entries.get(filePath);
163
+ if (!entry) continue;
164
+ if (entry.muted) muted.push(filePath);
165
+ const diagnostics = visibleDiagnostics(entry, paths, filePath);
166
+ if (diagnostics.length > 0) diagrams.push({ path: filePath, diagnostics });
167
+ }
168
+ pathSetHash = nextHash;
169
+ const result = {
170
+ checked: paths.length,
171
+ relinted,
172
+ durationMs: Date.now() - started,
173
+ cachedAt: (/* @__PURE__ */ new Date()).toISOString(),
174
+ diagrams,
175
+ unreadable,
176
+ muted
177
+ };
178
+ last = result;
179
+ stale = false;
180
+ return result;
181
+ }
182
+ function lintWorkspaceCached(input) {
183
+ if (!inflight) {
184
+ inflight = execute(input).finally(() => {
185
+ inflight = null;
186
+ });
187
+ }
188
+ return inflight;
189
+ }
190
+
191
+ export {
192
+ invalidateDiagramLint,
193
+ clearDiagramLintCache,
194
+ diagramLintSummary,
195
+ lintWorkspaceCached
196
+ };
@@ -0,0 +1,21 @@
1
+ import {
2
+ labelFromPath,
3
+ parseNetworkDocument,
4
+ readDiagramNetwork,
5
+ readMappingFile,
6
+ readNetworkFile,
7
+ siblingNetworkPath
8
+ } from "./chunk-WYQ4QDCF.js";
9
+ import "./chunk-ARL7TA3D.js";
10
+ import "./chunk-M63FV47T.js";
11
+ import "./chunk-BW6ANOTX.js";
12
+ import "./chunk-6LCHDAAN.js";
13
+ import "./chunk-MLKGABMK.js";
14
+ export {
15
+ labelFromPath,
16
+ parseNetworkDocument,
17
+ readDiagramNetwork,
18
+ readMappingFile,
19
+ readNetworkFile,
20
+ siblingNetworkPath
21
+ };
@@ -0,0 +1,78 @@
1
+ import {
2
+ dataFail
3
+ } from "./chunk-ARL7TA3D.js";
4
+
5
+ // server/src/diagramDataFiles.ts
6
+ function importInputFromBody(body) {
7
+ if (typeof body.text !== "string") throw dataFail(400, "text must be a string.", "invalid");
8
+ const input = { text: body.text };
9
+ if (body.format != null) {
10
+ if (typeof body.format !== "string") throw dataFail(400, "format must be a string.", "invalid");
11
+ input.format = body.format;
12
+ }
13
+ if (body.shape != null) {
14
+ if (typeof body.shape !== "string") throw dataFail(400, "shape must be a string.", "invalid");
15
+ input.shape = body.shape;
16
+ }
17
+ if (body.mapping != null) input.mapping = body.mapping;
18
+ if (body.edgesText != null) {
19
+ if (typeof body.edgesText !== "string") throw dataFail(400, "edgesText must be a string.", "invalid");
20
+ input.edgesText = body.edgesText;
21
+ }
22
+ if (body.edgesFormat != null) {
23
+ if (typeof body.edgesFormat !== "string") throw dataFail(400, "edgesFormat must be a string.", "invalid");
24
+ input.edgesFormat = body.edgesFormat;
25
+ }
26
+ if (body.edgesMapping != null) input.edgesMapping = body.edgesMapping;
27
+ if (body.direction != null) {
28
+ if (typeof body.direction !== "string") throw dataFail(400, "direction must be a string.", "invalid");
29
+ input.direction = body.direction;
30
+ }
31
+ if (body.grouping != null) {
32
+ if (typeof body.grouping !== "boolean") throw dataFail(400, "grouping must be a boolean.", "invalid");
33
+ input.grouping = body.grouping;
34
+ }
35
+ if (body.title != null) {
36
+ if (typeof body.title !== "string") throw dataFail(400, "title must be a string.", "invalid");
37
+ input.title = body.title;
38
+ }
39
+ if (body.description != null) {
40
+ if (typeof body.description !== "string") throw dataFail(400, "description must be a string.", "invalid");
41
+ input.description = body.description;
42
+ }
43
+ if (body.sourceFile != null) {
44
+ if (typeof body.sourceFile !== "string") throw dataFail(400, "sourceFile must be a string.", "invalid");
45
+ input.sourceFile = body.sourceFile;
46
+ }
47
+ if (body.edgesFile != null) {
48
+ if (typeof body.edgesFile !== "string") throw dataFail(400, "edgesFile must be a string.", "invalid");
49
+ input.edgesFile = body.edgesFile;
50
+ }
51
+ if (body.localDevice != null) {
52
+ if (typeof body.localDevice !== "string") throw dataFail(400, "localDevice must be a string.", "invalid");
53
+ input.localDevice = body.localDevice;
54
+ }
55
+ if (body.groupBy != null) {
56
+ if (typeof body.groupBy !== "string") throw dataFail(400, "groupBy must be a string.", "invalid");
57
+ input.groupBy = body.groupBy;
58
+ }
59
+ if (body.view != null) {
60
+ if (typeof body.view !== "string") throw dataFail(400, "view must be a string.", "invalid");
61
+ input.view = body.view;
62
+ }
63
+ if (body.includeDown != null) {
64
+ if (typeof body.includeDown !== "boolean") throw dataFail(400, "includeDown must be a boolean.", "invalid");
65
+ input.includeDown = body.includeDown;
66
+ }
67
+ if (body.vlan != null) {
68
+ if (typeof body.vlan !== "number" || !Number.isInteger(body.vlan)) {
69
+ throw dataFail(400, "vlan must be an integer from 1 to 4094.", "invalid");
70
+ }
71
+ input.vlan = body.vlan;
72
+ }
73
+ return input;
74
+ }
75
+
76
+ export {
77
+ importInputFromBody
78
+ };
@@ -0,0 +1,85 @@
1
+ import {
2
+ assertExportInputSize,
3
+ exporterFail,
4
+ parseMappingText,
5
+ readDataSource,
6
+ validateNetwork
7
+ } from "./chunk-ARL7TA3D.js";
8
+
9
+ // server/src/exporters/resolve.ts
10
+ import fs from "node:fs/promises";
11
+ import path from "node:path";
12
+ function labelFromPath(filePath) {
13
+ const base = path.basename(filePath);
14
+ return base.replace(/\.network\.json$/i, "").replace(/\.mmd$/i, "") || "nerdgram";
15
+ }
16
+ function parseNetworkDocument(text) {
17
+ assertExportInputSize(Buffer.byteLength(text));
18
+ const trimmed = text.replace(/^\uFEFF/, "").trim();
19
+ if (!trimmed) throw exporterFail(400, "The network document is empty.");
20
+ let parsed;
21
+ try {
22
+ parsed = JSON.parse(trimmed);
23
+ } catch {
24
+ throw exporterFail(400, "The network document is not valid JSON.");
25
+ }
26
+ const validated = validateNetwork(parsed);
27
+ if (!validated.document) {
28
+ const first = validated.issues[0];
29
+ const where = first?.path ? `${first.path}: ` : "";
30
+ throw exporterFail(400, `${where}${first?.message ?? "The network document does not match the schema."}`);
31
+ }
32
+ return validated.document;
33
+ }
34
+ function siblingNetworkPath(diagramPath, content) {
35
+ const source = readDataSource(content);
36
+ if (source?.file && source.file.toLowerCase().endsWith(".network.json")) {
37
+ return { kind: "recorded", path: source.file };
38
+ }
39
+ const stem = labelFromPath(diagramPath);
40
+ const dir = path.posix.dirname(diagramPath.split(path.sep).join("/"));
41
+ const name = `${stem}.network.json`;
42
+ const next = !dir || dir === "." ? name : `${dir}/${name}`;
43
+ return { kind: "stem", path: next };
44
+ }
45
+ async function readNetworkFile(filePath) {
46
+ let text;
47
+ try {
48
+ text = await fs.readFile(filePath, "utf8");
49
+ } catch {
50
+ throw exporterFail(400, `Could not read ${filePath}.`);
51
+ }
52
+ return { document: parseNetworkDocument(text), label: labelFromPath(filePath) };
53
+ }
54
+ async function readDiagramNetwork(diagramPath, readText) {
55
+ let content;
56
+ try {
57
+ content = await readText(diagramPath);
58
+ } catch {
59
+ throw exporterFail(400, `Could not read ${diagramPath}.`);
60
+ }
61
+ const sibling = siblingNetworkPath(diagramPath, content);
62
+ let text;
63
+ try {
64
+ text = await readText(sibling.path);
65
+ } catch {
66
+ if (sibling.kind === "recorded") {
67
+ throw exporterFail(400, `The diagram records network JSON at ${sibling.path}, and that file is not there.`);
68
+ }
69
+ throw exporterFail(400, "This diagram has no network JSON.");
70
+ }
71
+ return { document: parseNetworkDocument(text), label: labelFromPath(diagramPath) };
72
+ }
73
+ async function readMappingFile(filePath) {
74
+ const text = await fs.readFile(filePath, "utf8");
75
+ return parseMappingText(text);
76
+ }
77
+
78
+ export {
79
+ labelFromPath,
80
+ parseNetworkDocument,
81
+ siblingNetworkPath,
82
+ readNetworkFile,
83
+ readDiagramNetwork,
84
+ readMappingFile
85
+ };
@@ -0,0 +1,15 @@
1
+ import {
2
+ installedExporters,
3
+ outputDirectory,
4
+ runExport
5
+ } from "./chunk-KIK3WXJL.js";
6
+ import "./chunk-ARL7TA3D.js";
7
+ import "./chunk-M63FV47T.js";
8
+ import "./chunk-BW6ANOTX.js";
9
+ import "./chunk-6LCHDAAN.js";
10
+ import "./chunk-MLKGABMK.js";
11
+ export {
12
+ installedExporters,
13
+ outputDirectory,
14
+ runExport
15
+ };