nerdgram1337 1.4.8 → 1.5.1

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.
@@ -376,6 +376,13 @@ function diagramInitConfig(source, fallbackTheme = FALLBACK_THEME) {
376
376
  init.fontFamily = fontFamily || DEFAULT_FONT_FAMILY;
377
377
  return init;
378
378
  }
379
+ var NODE_LABEL_WRAP_WIDTH = 480;
380
+ function withNodeLabelRoom(config) {
381
+ const current = config.flowchart;
382
+ const block = current && typeof current === "object" && !Array.isArray(current) ? { ...current } : {};
383
+ if (block.wrappingWidth != null) return config;
384
+ return { ...config, flowchart: { ...block, wrappingWidth: NODE_LABEL_WRAP_WIDTH } };
385
+ }
379
386
  function newlineOf(source) {
380
387
  return source.includes("\r\n") ? "\r\n" : "\n";
381
388
  }
@@ -636,6 +643,7 @@ export {
636
643
  parseDiagram,
637
644
  diagramConfigKey,
638
645
  diagramInitConfig,
646
+ withNodeLabelRoom,
639
647
  applyDiagramPatch,
640
648
  literalLocator,
641
649
  searchMatchLabel,
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  readFile,
3
3
  writeFile
4
- } from "./chunk-I5EOFHBL.js";
4
+ } from "./chunk-JL7RYIQE.js";
5
5
  import {
6
6
  REPO_ROOT,
7
7
  ensureDataRoot,
@@ -11,13 +11,13 @@ import {
11
11
  resolveAvailablePath,
12
12
  resolveSafePath,
13
13
  toRelativePath
14
- } from "./chunk-ULY5YEBR.js";
14
+ } from "./chunk-KA5X3YY6.js";
15
15
  import "./chunk-5C6VO4LC.js";
16
16
  import {
17
17
  applyDiagramPatch,
18
18
  diagramConfigKey,
19
19
  parseDiagram
20
- } from "./chunk-AFGGIQ22.js";
20
+ } from "./chunk-6LCHDAAN.js";
21
21
 
22
22
  // server/src/templates.ts
23
23
  import fs from "node:fs/promises";
@@ -1,17 +1,131 @@
1
1
  import {
2
2
  locateParseError
3
- } from "./chunk-54BVSMKR.js";
3
+ } from "./chunk-WCRNLGMN.js";
4
4
  import {
5
5
  httpFail,
6
6
  sanitizeThumbnailSvg
7
- } from "./chunk-ULY5YEBR.js";
7
+ } from "./chunk-KA5X3YY6.js";
8
8
  import {
9
- diagramInitConfig
10
- } from "./chunk-AFGGIQ22.js";
9
+ diagramInitConfig,
10
+ withNodeLabelRoom
11
+ } from "./chunk-6LCHDAAN.js";
11
12
 
12
13
  // server/src/renderDiagram.ts
13
14
  import { createRequire } from "node:module";
14
15
  import puppeteer from "puppeteer";
16
+
17
+ // server/src/edgeLabelPadding.ts
18
+ function repairSvgMarkup(svg) {
19
+ let next = svg;
20
+ if (next.includes("xlink:") && !/xmlns:xlink\s*=/.test(next)) {
21
+ next = next.replace(/<svg\b/, '<svg xmlns:xlink="http://www.w3.org/1999/xlink"');
22
+ }
23
+ return next.replace(/<br\b([^>]*?)>/gi, (_full, attrs) => {
24
+ const body = attrs.replace(/\s*\/\s*$/, "");
25
+ return `<br${body}/>`;
26
+ });
27
+ }
28
+ function padEdgeLabelBoxes(root) {
29
+ const pad = 6;
30
+ const mark = "data-nerdgram-pad";
31
+ const readPx = (value) => {
32
+ if (!value) return 0;
33
+ const n = Number.parseFloat(value);
34
+ return Number.isFinite(n) ? n : 0;
35
+ };
36
+ const trimNum = (value) => String(Math.round(value * 100) / 100);
37
+ const writePx = (current, next) => {
38
+ const unit = current?.trim().toLowerCase().endsWith("px") ? "px" : "";
39
+ return `${trimNum(next)}${unit}`;
40
+ };
41
+ const shiftTranslateX = (el, dx) => {
42
+ const raw = el.getAttribute("transform") ?? "";
43
+ const match = /translate\(\s*(-?[\d.]+)(?:[,\s]+(-?[\d.]+))?\s*\)/.exec(raw);
44
+ if (!match || match[1] == null) return;
45
+ const x = Number(match[1]) + dx;
46
+ const y = match[2] ?? "0";
47
+ el.setAttribute("transform", raw.replace(match[0], `translate(${trimNum(x)}, ${y})`));
48
+ };
49
+ const appendStyle = (el, addition) => {
50
+ const style = el.getAttribute("style") ?? "";
51
+ if (/padding\s*:/.test(style)) return;
52
+ el.setAttribute("style", style.trim() ? `${style.replace(/;\s*$/, "")};${addition}` : addition);
53
+ };
54
+ for (const group of root.querySelectorAll("g.edgeLabel")) {
55
+ if (group.getAttribute(mark) === "1") continue;
56
+ const foreign = group.querySelector("foreignObject");
57
+ if (foreign) {
58
+ const widthAttr2 = foreign.getAttribute("width");
59
+ const width2 = readPx(widthAttr2);
60
+ if (!(width2 > 0)) continue;
61
+ foreign.setAttribute("width", writePx(widthAttr2, width2 + pad * 2));
62
+ shiftTranslateX(group.querySelector("g.label") ?? group, -pad);
63
+ const tagged = foreign.getElementsByTagName?.("p");
64
+ const paragraphs = tagged ? [...tagged] : [...foreign.querySelectorAll("*")].filter((el) => (el.localName ?? "").toLowerCase() === "p");
65
+ if (paragraphs.length > 0) {
66
+ for (const paragraph of paragraphs) appendStyle(paragraph, `padding:0 ${pad}px`);
67
+ } else {
68
+ const background = foreign.querySelector(".labelBkg") ?? foreign.querySelector("div");
69
+ if (background) appendStyle(background, `padding:0 ${pad}px`);
70
+ }
71
+ group.setAttribute(mark, "1");
72
+ continue;
73
+ }
74
+ const rect = group.querySelector("rect");
75
+ if (!rect) continue;
76
+ const widthAttr = rect.getAttribute("width");
77
+ const width = readPx(widthAttr);
78
+ if (!(width > 0)) continue;
79
+ const xAttr = rect.getAttribute("x");
80
+ const x = readPx(xAttr);
81
+ const text = group.querySelector("text");
82
+ const box = text && typeof text.getBBox === "function" ? text.getBBox() : null;
83
+ let extra = pad;
84
+ if (box && box.width > 1) {
85
+ extra = pad - (width - box.width) / 2;
86
+ if (extra <= 0.5) {
87
+ group.setAttribute(mark, "1");
88
+ continue;
89
+ }
90
+ }
91
+ rect.setAttribute("x", writePx(xAttr, x - extra));
92
+ rect.setAttribute("width", writePx(widthAttr, width + extra * 2));
93
+ group.setAttribute(mark, "1");
94
+ }
95
+ }
96
+ function padEdgeLabelSvg(svg) {
97
+ if (!svg.includes("edgeLabel")) return repairSvgMarkup(svg);
98
+ const prepared = repairSvgMarkup(svg);
99
+ const g = globalThis;
100
+ if (!g.DOMParser || !g.XMLSerializer) return prepared;
101
+ const doc = new g.DOMParser().parseFromString(prepared, "image/svg+xml");
102
+ if (doc.querySelector("parsererror")) return prepared;
103
+ padEdgeLabelBoxes(doc);
104
+ return repairSvgMarkup(new g.XMLSerializer().serializeToString(doc.documentElement));
105
+ }
106
+ function svgXmlError(svg) {
107
+ const text = svg.trim();
108
+ if (!text.includes("<svg") || text.includes("<parsererror")) {
109
+ return "Rendered SVG is not well-formed XML.";
110
+ }
111
+ if (/<br\b(?![^>]*\/>)[^>]*>/i.test(text)) {
112
+ return "Rendered SVG is not well-formed XML. Opening and ending tag mismatch: br and p.";
113
+ }
114
+ const g = globalThis;
115
+ if (!g.DOMParser) return null;
116
+ const doc = new g.DOMParser().parseFromString(text, "image/svg+xml");
117
+ const err = doc.querySelector("parsererror");
118
+ if (err) {
119
+ const message = (err.textContent ?? "").replace(/\s+/g, " ").trim();
120
+ return message.slice(0, 300) || "Rendered SVG is not well-formed XML.";
121
+ }
122
+ if (doc.documentElement?.localName && doc.documentElement.localName !== "svg") {
123
+ return "Rendered SVG is not well-formed XML.";
124
+ }
125
+ return null;
126
+ }
127
+
128
+ // server/src/renderDiagram.ts
15
129
  var require2 = createRequire(import.meta.url);
16
130
  var MAX_RENDER_SOURCE_CHARS = 512 * 1024;
17
131
  var MAX_RENDER_SVG_CHARS = 2e6;
@@ -96,7 +210,7 @@ function plainError(err) {
96
210
  return message.replace(/\s+/g, " ").trim().slice(0, 400) || "Mermaid could not render that diagram.";
97
211
  }
98
212
  async function draw(page, source, background) {
99
- const init = diagramInitConfig(source);
213
+ const init = withNodeLabelRoom(diagramInitConfig(source));
100
214
  init.startOnLoad = false;
101
215
  init.securityLevel = "strict";
102
216
  init.suppressErrorRendering = true;
@@ -107,14 +221,20 @@ async function draw(page, source, background) {
107
221
  );
108
222
  await page.addScriptTag({ path: mermaidScript() });
109
223
  const drawn = await page.evaluate(
110
- async (code, mermaidConfig, fill) => {
224
+ async (code, mermaidConfig, fill, padSource) => {
225
+ const padSvg = new Function(
226
+ "svg",
227
+ `var __name = function (target) { return target; };
228
+ ${padSource}
229
+ return padEdgeLabelSvg(svg);`
230
+ );
111
231
  const api = window.mermaid;
112
232
  if (!api) return { ok: false, message: "Mermaid did not load", loc: null, token: void 0 };
113
233
  document.body.style.background = fill;
114
234
  api.initialize(mermaidConfig);
115
235
  try {
116
236
  const rendered = await api.render("nerdgram-render", code);
117
- return { ok: true, svg: rendered.svg };
237
+ return { ok: true, svg: padSvg(rendered.svg) };
118
238
  } catch (err) {
119
239
  const hash = err && typeof err === "object" && "hash" in err ? err.hash : void 0;
120
240
  const loc = hash?.loc;
@@ -133,7 +253,10 @@ async function draw(page, source, background) {
133
253
  },
134
254
  source,
135
255
  config,
136
- background
256
+ background,
257
+ `${repairSvgMarkup.toString()}
258
+ ${padEdgeLabelBoxes.toString()}
259
+ ${padEdgeLabelSvg.toString()}`
137
260
  );
138
261
  if (!drawn.ok) {
139
262
  const parsed = drawn.loc != null || /parse error on line/i.test(drawn.message);
@@ -170,6 +293,18 @@ async function rasterize(page, svg, background) {
170
293
  const png = await frame.screenshot({ type: "png", omitBackground: false });
171
294
  return Buffer.from(png);
172
295
  }
296
+ async function xmlErrorOnPage(page, svg) {
297
+ const message = await page.evaluate((markup) => {
298
+ const g = globalThis;
299
+ const doc = new g.DOMParser().parseFromString(markup, "image/svg+xml");
300
+ const err = doc.querySelector("parsererror");
301
+ if (err || doc.documentElement?.localName !== "svg") {
302
+ return (err?.textContent || "Rendered SVG is not well-formed XML.").replace(/\s+/g, " ").trim().slice(0, 300);
303
+ }
304
+ return "";
305
+ }, svg);
306
+ return message || null;
307
+ }
173
308
  async function renderOnce(input) {
174
309
  const source = assertSource(input.source);
175
310
  if (input.format !== "svg" && input.format !== "png") {
@@ -194,6 +329,8 @@ async function renderOnce(input) {
194
329
  if (/<script[\s>/]/i.test(cleaned)) {
195
330
  throw httpFail(400, "Rendered SVG was rejected.", "invalid");
196
331
  }
332
+ const markupError = svgXmlError(cleaned) ?? await xmlErrorOnPage(page, cleaned);
333
+ if (markupError) throw httpFail(500, markupError, "invalid");
197
334
  if (input.format === "svg") {
198
335
  return { format: "svg", contentType: "image/svg+xml; charset=utf-8", body: Buffer.from(cleaned, "utf8") };
199
336
  }
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  isMermaidEnvironmentError,
3
3
  locateParseError
4
- } from "./chunk-54BVSMKR.js";
4
+ } from "./chunk-WCRNLGMN.js";
5
5
  import {
6
6
  diagramTargetExists,
7
7
  isDiagramLink,
@@ -17,7 +17,7 @@ import {
17
17
  diagramConfigKey,
18
18
  matchFrontMatter,
19
19
  parseDiagram
20
- } from "./chunk-AFGGIQ22.js";
20
+ } from "./chunk-6LCHDAAN.js";
21
21
 
22
22
  // server/src/mermaidSyntax.ts
23
23
  import mermaid from "mermaid";
@@ -22,7 +22,7 @@ import {
22
22
  safeStorageKey,
23
23
  textFiles,
24
24
  toRelativePath
25
- } from "./chunk-ULY5YEBR.js";
25
+ } from "./chunk-KA5X3YY6.js";
26
26
 
27
27
  // server/src/fsStore.ts
28
28
  import fs2 from "node:fs/promises";
@@ -1469,7 +1469,7 @@ async function writeFile(relativePath, content, options = {}) {
1469
1469
  await atomicWriteText(abs, content);
1470
1470
  await dropThumbnail(relative);
1471
1471
  const stat = await fs2.stat(abs);
1472
- const search = await import("./chunk-WSGEBKT4.js");
1472
+ const search = await import("./chunk-LYMG57VV.js");
1473
1473
  await search.rememberSearchEntry(relative, content, stat.mtimeMs, stat.size);
1474
1474
  await noteDiagramSighting({ path: relative, hash: hashContent(content) });
1475
1475
  noteSync({ kind: "content", summary: `Update ${relative}` });
@@ -1482,7 +1482,7 @@ async function writeFile(relativePath, content, options = {}) {
1482
1482
  };
1483
1483
  }
1484
1484
  function noteSync(change) {
1485
- void import("./chunk-JUCAQ6EJ.js").then((mod) => mod.noteLocalChange(change)).catch(() => {
1485
+ void import("./chunk-LXSDAIF4.js").then((mod) => mod.noteLocalChange(change)).catch(() => {
1486
1486
  console.error("GitHub sync could not record a local change");
1487
1487
  });
1488
1488
  }
@@ -1,12 +1,12 @@
1
- import "./chunk-I5EOFHBL.js";
1
+ import "./chunk-JL7RYIQE.js";
2
2
  import {
3
3
  ensureDataRoot,
4
4
  getMetaPath,
5
5
  httpFail,
6
6
  isDataFileName
7
- } from "./chunk-ULY5YEBR.js";
7
+ } from "./chunk-KA5X3YY6.js";
8
8
  import "./chunk-5C6VO4LC.js";
9
- import "./chunk-AFGGIQ22.js";
9
+ import "./chunk-6LCHDAAN.js";
10
10
 
11
11
  // server/src/sync/engine.ts
12
12
  import fsp2 from "node:fs/promises";
@@ -799,24 +799,66 @@ async function copyDataToMirror(dataRoot, dir) {
799
799
  async function commitMirror(dir, message, parents) {
800
800
  const matrix = await git.statusMatrix({ fs: nodeFs, dir });
801
801
  let dirty = false;
802
- for (const [filepath, head, workdir, stage] of matrix) {
803
- if (head === 1 && workdir === 1 && stage === 1) continue;
804
- if (head === 0 && workdir === 0) continue;
802
+ for (const [filepath, head2, workdir, stage] of matrix) {
803
+ if (head2 === 1 && workdir === 1 && stage === 1) continue;
804
+ if (head2 === 0 && workdir === 0) continue;
805
805
  dirty = true;
806
806
  if (workdir === 0) await git.remove({ fs: nodeFs, dir, filepath });
807
807
  else await git.add({ fs: nodeFs, dir, filepath });
808
808
  }
809
809
  if (!dirty && !parents) return null;
810
+ const head = await headOid(dir);
811
+ const parentOids = parents && parents.length > 0 ? parents : head ? [head] : [];
812
+ const text = message.trim() || "Update diagrams";
813
+ const onlyParentIsHead = parentOids.length === 1 && parentOids[0] === head;
814
+ if (!parents || onlyParentIsHead) {
815
+ try {
816
+ return await git.commit({
817
+ fs: nodeFs,
818
+ dir,
819
+ message: text,
820
+ author: PERSON,
821
+ committer: PERSON,
822
+ parent: parents,
823
+ disallowEmpty: parentOids.length === 1
824
+ });
825
+ } catch (err) {
826
+ if (isEmptyCommit(err)) return null;
827
+ throw err;
828
+ }
829
+ }
810
830
  const oid = await git.commit({
811
831
  fs: nodeFs,
812
832
  dir,
813
- message: message.trim() || "Update diagrams",
833
+ message: text,
814
834
  author: PERSON,
815
835
  committer: PERSON,
816
- parent: parents
836
+ parent: parents,
837
+ noUpdateBranch: true
838
+ });
839
+ if (parentOids.length === 1) {
840
+ const [created, parentCommit] = await Promise.all([
841
+ git.readCommit({ fs: nodeFs, dir, oid }),
842
+ git.readCommit({ fs: nodeFs, dir, oid: parentOids[0] })
843
+ ]);
844
+ if (created.commit.tree === parentCommit.commit.tree) return null;
845
+ }
846
+ const branch = await git.currentBranch({ fs: nodeFs, dir, fullname: true });
847
+ await git.writeRef({
848
+ fs: nodeFs,
849
+ dir,
850
+ ref: typeof branch === "string" ? branch : "HEAD",
851
+ value: oid,
852
+ force: true
817
853
  });
818
854
  return oid;
819
855
  }
856
+ function isEmptyCommit(err) {
857
+ if (!err || typeof err !== "object") return false;
858
+ const code = "code" in err ? String(err.code) : "";
859
+ const name = "name" in err ? String(err.name) : "";
860
+ return code === "EmptyCommitError" || name === "EmptyCommitError";
861
+ }
820
862
  async function fetchRemote(dir) {
821
863
  try {
822
864
  await git.fetch({
@@ -956,6 +998,7 @@ async function deleteExtra(mirror, dir, desired) {
956
998
 
957
999
  // server/src/sync/engine.ts
958
1000
  var suppress = 0;
1001
+ var noteGeneration = 0;
959
1002
  var timer = null;
960
1003
  var summaries = [];
961
1004
  var structuralPending = false;
@@ -971,8 +1014,12 @@ function noteLocalChange(change) {
971
1014
  }
972
1015
  async function recordChange(change) {
973
1016
  if (suppress > 0) return;
1017
+ const generation = noteGeneration;
974
1018
  const config = await loadConfig();
975
1019
  if (!config.enabled || suppress > 0) return;
1020
+ if (!await workspaceDiffersFromHead()) return;
1021
+ if (suppress > 0) return;
1022
+ if (generation !== noteGeneration && !await workspaceDiffersFromHead()) return;
976
1023
  if (change.summary && !summaries.includes(change.summary)) summaries.push(change.summary);
977
1024
  if (change.kind === "structural") {
978
1025
  structuralPending = true;
@@ -981,6 +1028,13 @@ async function recordChange(change) {
981
1028
  }
982
1029
  if (!structuralPending) schedule(idleMs());
983
1030
  }
1031
+ async function workspaceDiffersFromHead() {
1032
+ try {
1033
+ return await copyWouldChange();
1034
+ } catch {
1035
+ return true;
1036
+ }
1037
+ }
984
1038
  async function syncNow() {
985
1039
  return exclusive(async () => {
986
1040
  const config = await loadConfig();
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  buildTree,
3
3
  readFile
4
- } from "./chunk-I5EOFHBL.js";
4
+ } from "./chunk-JL7RYIQE.js";
5
5
  import {
6
6
  atomicWriteJson,
7
7
  getDataRoot,
@@ -9,14 +9,14 @@ import {
9
9
  httpFail,
10
10
  readJsonFile,
11
11
  rewriteMovedPath
12
- } from "./chunk-ULY5YEBR.js";
12
+ } from "./chunk-KA5X3YY6.js";
13
13
  import "./chunk-5C6VO4LC.js";
14
14
  import {
15
15
  literalLocator,
16
16
  matchDiagramSearch,
17
17
  parseDiagram,
18
18
  searchMatchLabel
19
- } from "./chunk-AFGGIQ22.js";
19
+ } from "./chunk-6LCHDAAN.js";
20
20
 
21
21
  // server/src/search.ts
22
22
  import path from "node:path";
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  matchFrontMatter
3
- } from "./chunk-AFGGIQ22.js";
3
+ } from "./chunk-6LCHDAAN.js";
4
4
 
5
5
  // server/src/parseError.ts
6
6
  function locateParseError(error, source) {
package/dist/cli.js CHANGED
@@ -26,6 +26,7 @@ var BOOL_FLAGS = /* @__PURE__ */ new Set([
26
26
  "with-data",
27
27
  "keep-data",
28
28
  "include-down",
29
+ "create-only",
29
30
  "version"
30
31
  ]);
31
32
  var HELP = `nerdgram \u2014 automation client for NerdGram1337
@@ -68,11 +69,14 @@ Flags
68
69
  diagnostics, folders, files, and the rest of the payload).
69
70
  Failure is {"ok":false,"error","status"} on stdout.
70
71
  --include-down Network data. Draw shutdown and down interfaces. Off by default.
72
+ --create-only Create the diagram and return 409 when the path exists.
73
+ Without this flag, generate creates the diagram or updates
74
+ the generated block and the data file beside it.
71
75
  --vlan <1-4094> Layer 2 network view. Keep links that carry this VLAN id.
72
76
  --group-by <value>
73
77
  cdp and lldp: platform or capability.
74
78
  network with --view l3: vrf.
75
- network with --view l2: site or role.
79
+ network with --view l2: site, role, or platform.
76
80
  --view <l3|l2> generate --format network only. l3 is subnets. l2 is VLANs,
77
81
  trunks, and LAGs. refresh rejects --view. The view is stored
78
82
  in the diagram.
@@ -108,16 +112,16 @@ not changed. --undo restores that replace and skips a file edited since.
108
112
  `;
109
113
  var renderModule = null;
110
114
  function loadRender() {
111
- renderModule ??= import("./chunk-GQKUFF4P.js");
115
+ renderModule ??= import("./chunk-BCO66AYP.js");
112
116
  return renderModule;
113
117
  }
114
118
  async function loadLint() {
115
- return import("./chunk-XJTF2GUE.js");
119
+ return import("./chunk-FIAVRIHI.js");
116
120
  }
117
121
  async function templateCommand(parsed, io) {
118
122
  const sub = parsed.positionals[0] ?? "";
119
123
  const target = parsed.positionals[1] ?? "";
120
- const templates = await import("./chunk-TQHP2K7Q.js");
124
+ const templates = await import("./chunk-AWVTRON2.js");
121
125
  try {
122
126
  if (sub === "save") {
123
127
  if (!target) throw new CliError("Usage: nerdgram template save <diagram> [--name name] [--replace]");
@@ -162,6 +166,13 @@ var CliError = class extends Error {
162
166
  this.details = details;
163
167
  }
164
168
  };
169
+ function failureStatus(err) {
170
+ if (err instanceof CliError && typeof err.status === "number") return err.status;
171
+ if (err && typeof err === "object" && "status" in err && typeof err.status === "number") {
172
+ return err.status;
173
+ }
174
+ return "error";
175
+ }
165
176
  function formatRowIssues(errors) {
166
177
  if (!Array.isArray(errors)) return [];
167
178
  const lines = [];
@@ -554,8 +565,9 @@ async function generateCommand(parsed, io) {
554
565
  const vlanText = flagString(parsed.flags, "vlan");
555
566
  if (vlanText != null && !/^\d+$/.test(vlanText)) throw new CliError("vlan must be an integer from 1 to 4094.");
556
567
  const text = await fs.readFile(dataFile, "utf8");
568
+ const createOnly = parsed.flags.get("create-only") === true;
557
569
  const { base, token } = configOf(parsed.flags, io.env);
558
- const result = await callApi(base, requireToken(token), "POST", "/api/v1/generate", {
570
+ const result = await callApi(base, requireToken(token), "POST", createOnly ? "/api/v1/generate" : "/api/v1/generate/upsert", {
559
571
  path: diagramPath,
560
572
  text,
561
573
  format,
@@ -569,7 +581,8 @@ async function generateCommand(parsed, io) {
569
581
  ...vlanText != null ? { vlan: Number(vlanText) } : {}
570
582
  });
571
583
  const body = result.json;
572
- writeOut(io, isJson(parsed.flags), body, `Created ${body.path}${body.dataPath ? ` from ${body.dataPath}` : ""}`);
584
+ const verb = body.created === false ? "Updated" : "Created";
585
+ writeOut(io, isJson(parsed.flags), body, `${verb} ${body.path}${body.dataPath ? ` from ${body.dataPath}` : ""}`);
573
586
  }
574
587
  async function diffCommand(parsed, io) {
575
588
  const itemPath = parsed.positionals[0];
@@ -842,11 +855,10 @@ async function main(argv, io = {}) {
842
855
  }
843
856
  } catch (err) {
844
857
  const message = err instanceof Error ? err.message : String(err);
845
- const status = err instanceof CliError ? err.status : void 0;
846
858
  if (isJson(parsed.flags)) {
847
859
  const errors = err instanceof CliError && Array.isArray(err.details?.errors) ? err.details.errors : void 0;
848
860
  streams.stdout(
849
- `${JSON.stringify({ ok: false, error: message, status: status ?? null, ...errors ? { errors } : {} })}
861
+ `${JSON.stringify({ ok: false, error: message, status: failureStatus(err), ...errors ? { errors } : {} })}
850
862
  `
851
863
  );
852
864
  } else streams.stderr(`${message}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nerdgram1337",
3
- "version": "1.4.8",
3
+ "version": "1.5.1",
4
4
  "description": "Command-line client for a local NerdGram1337 server",
5
5
  "type": "module",
6
6
  "license": "MIT",
File without changes