nerdgram1337 1.6.1 → 1.7.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.
package/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  `nerdgram` is the command-line client for [NerdGram1337](https://github.com/NetworkNerd1337/NerdGram1337), a local app for [Mermaid](https://mermaid.js.org/) diagrams. The npm package name is `nerdgram1337`. The command it installs is `nerdgram`.
4
4
 
5
- List, search, and edit diagrams on a NerdGram server that is already running. `lint` and `render` of a `.mmd` file that is already on disk do not need the server.
5
+ List, search, and edit diagrams on a NerdGram server that is already running. `lint` and `render` of a `.mmd` file that is already on disk do not need the server. `convert` of a saved export does not need the server.
6
6
 
7
7
  ## Install
8
8
 
@@ -34,6 +34,7 @@ nerdgram search Atlanta
34
34
  nerdgram get Welcome.mmd -o Welcome.mmd
35
35
  nerdgram put Notes.mmd ./Notes.mmd
36
36
  nerdgram lint Welcome.mmd
37
+ nerdgram convert netbox export.json -o campus.network.json
37
38
  nerdgram diff Welcome.mmd --from current --to current --format md
38
39
  nerdgram baseline Welcome.mmd --name "Baseline"
39
40
  nerdgram replace CORE-SW1 ATL-CORE-01 --dry-run
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  readFile,
3
3
  writeFile
4
- } from "./chunk-JL7RYIQE.js";
4
+ } from "./chunk-6ELR2KYA.js";
5
5
  import {
6
6
  REPO_ROOT,
7
7
  ensureDataRoot,
@@ -12,12 +12,13 @@ import {
12
12
  resolveSafePath,
13
13
  toRelativePath
14
14
  } from "./chunk-KA5X3YY6.js";
15
- import "./chunk-5C6VO4LC.js";
15
+ import "./chunk-BW6ANOTX.js";
16
16
  import {
17
17
  applyDiagramPatch,
18
18
  diagramConfigKey,
19
19
  parseDiagram
20
20
  } from "./chunk-6LCHDAAN.js";
21
+ import "./chunk-MLKGABMK.js";
21
22
 
22
23
  // server/src/templates.ts
23
24
  import fs from "node:fs/promises";
@@ -0,0 +1,78 @@
1
+ import {
2
+ dataFail
3
+ } from "./chunk-6ELR2KYA.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
+ };
@@ -23,6 +23,10 @@ import {
23
23
  textFiles,
24
24
  toRelativePath
25
25
  } from "./chunk-KA5X3YY6.js";
26
+ import {
27
+ clickTargetKind,
28
+ resolveDiagramTarget
29
+ } from "./chunk-BW6ANOTX.js";
26
30
 
27
31
  // server/src/fsStore.ts
28
32
  import fs2 from "node:fs/promises";
@@ -1019,6 +1023,457 @@ function registerNeighborParser(parser) {
1019
1023
  registerNeighborParser(ciscoCdpParser);
1020
1024
  registerNeighborParser(lldpParser);
1021
1025
 
1026
+ // server/src/network/ip.ts
1027
+ function parseIpv4(address) {
1028
+ const match = /^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/.exec(address.trim());
1029
+ if (!match) return null;
1030
+ let value = 0;
1031
+ for (let index = 1; index <= 4; index += 1) {
1032
+ const octet = match[index] ?? "";
1033
+ if (octet.length > 1 && octet.startsWith("0")) return null;
1034
+ const number = Number(octet);
1035
+ if (!Number.isInteger(number) || number < 0 || number > 255) return null;
1036
+ value = value << 8 | number;
1037
+ }
1038
+ return value >>> 0;
1039
+ }
1040
+ function formatIpv4(value) {
1041
+ return `${value >>> 24 & 255}.${value >>> 16 & 255}.${value >>> 8 & 255}.${value & 255}`;
1042
+ }
1043
+ function parseIpv6(address) {
1044
+ let text = address.trim().toLowerCase();
1045
+ if (!text || text.length > 64 || text.includes("%") || /\s/.test(text)) return null;
1046
+ if (text.includes(".")) {
1047
+ const lastColon = text.lastIndexOf(":");
1048
+ if (lastColon < 0) return null;
1049
+ const v4 = parseIpv4(text.slice(lastColon + 1));
1050
+ if (v4 == null) return null;
1051
+ const hi = (v4 >>> 16 & 65535).toString(16);
1052
+ const lo = (v4 & 65535).toString(16);
1053
+ text = `${text.slice(0, lastColon)}:${hi}:${lo}`;
1054
+ }
1055
+ if (text.includes(":::")) return null;
1056
+ const pieces = text.split("::");
1057
+ if (pieces.length > 2) return null;
1058
+ const parseSide = (part) => {
1059
+ if (!part) return [];
1060
+ const groups = part.split(":");
1061
+ const out = [];
1062
+ for (const group of groups) {
1063
+ if (!/^[0-9a-f]{1,4}$/.test(group)) return null;
1064
+ out.push(Number.parseInt(group, 16));
1065
+ }
1066
+ return out;
1067
+ };
1068
+ const left = parseSide(pieces[0] ?? "");
1069
+ if (!left) return null;
1070
+ if (pieces.length === 1) {
1071
+ if (left.length !== 8) return null;
1072
+ return Uint16Array.from(left);
1073
+ }
1074
+ const right = parseSide(pieces[1] ?? "");
1075
+ if (!right) return null;
1076
+ const missing = 8 - left.length - right.length;
1077
+ if (missing < 1) return null;
1078
+ return Uint16Array.from([...left, ...new Array(missing).fill(0), ...right]);
1079
+ }
1080
+ function formatIpv6(groups) {
1081
+ let bestStart = -1;
1082
+ let bestLength = 0;
1083
+ let runStart = -1;
1084
+ for (let index = 0; index <= groups.length; index += 1) {
1085
+ const zero = index < groups.length && groups[index] === 0;
1086
+ if (zero && runStart < 0) runStart = index;
1087
+ if (!zero && runStart >= 0) {
1088
+ const length = index - runStart;
1089
+ if (length > bestLength) {
1090
+ bestStart = runStart;
1091
+ bestLength = length;
1092
+ }
1093
+ runStart = -1;
1094
+ }
1095
+ }
1096
+ const hex = (group) => group.toString(16);
1097
+ if (bestLength < 2) return [...groups].map(hex).join(":");
1098
+ const left = [...groups.slice(0, bestStart)].map(hex).join(":");
1099
+ const right = [...groups.slice(bestStart + bestLength)].map(hex).join(":");
1100
+ return `${left}::${right}`;
1101
+ }
1102
+ function canonicalIp(address, family) {
1103
+ if (family === "ipv4") {
1104
+ const value = parseIpv4(address);
1105
+ return value == null ? null : formatIpv4(value);
1106
+ }
1107
+ const groups = parseIpv6(address);
1108
+ return groups ? formatIpv6(groups) : null;
1109
+ }
1110
+
1111
+ // server/src/network/validate.ts
1112
+ var DEVICE_FIELDS = /* @__PURE__ */ new Set(["name", "platform", "model", "role", "site", "managementIp", "diagram"]);
1113
+ var INTERFACE_FIELDS = /* @__PURE__ */ new Set([
1114
+ "device",
1115
+ "name",
1116
+ "description",
1117
+ "speed",
1118
+ "adminStatus",
1119
+ "operStatus",
1120
+ "ipv4",
1121
+ "ipv6",
1122
+ "vrf",
1123
+ "switchportMode",
1124
+ "accessVlan",
1125
+ "trunkVlans",
1126
+ "nativeVlan",
1127
+ "lag"
1128
+ ]);
1129
+ var ADDRESS_FIELDS = /* @__PURE__ */ new Set(["address", "prefix"]);
1130
+ var LINK_FIELDS = /* @__PURE__ */ new Set(["a", "b", "label", "inferred"]);
1131
+ var ENDPOINT_FIELDS = /* @__PURE__ */ new Set(["device", "interface"]);
1132
+ var VLAN_FIELDS = /* @__PURE__ */ new Set(["id", "name"]);
1133
+ var ROOT_FIELDS = /* @__PURE__ */ new Set(["schemaVersion", "format", "devices", "interfaces", "links", "vlans", "neighbors"]);
1134
+ var NEIGHBOR_FIELDS = /* @__PURE__ */ new Set(["cdp", "lldp", "localDevice"]);
1135
+ function validateNetwork(value) {
1136
+ const issues = [];
1137
+ if (!isRecord2(value)) {
1138
+ issues.push({ path: "", message: "Network data must be a JSON object." });
1139
+ return { document: null, issues };
1140
+ }
1141
+ rejectUnknown(value, ROOT_FIELDS, "", issues);
1142
+ if (value.schemaVersion !== 1) {
1143
+ issues.push({ path: "/schemaVersion", message: "schemaVersion must be 1." });
1144
+ }
1145
+ if (value.format != null && value.format !== "network") {
1146
+ issues.push({ path: "/format", message: 'format must be "network" when it is set.' });
1147
+ }
1148
+ const devices = readDevices(value.devices, issues);
1149
+ const interfaces = readInterfaces(value.interfaces, issues);
1150
+ const links = value.links == null ? [] : readLinks(value.links, issues);
1151
+ const vlans = value.vlans == null ? [] : readVlans(value.vlans, issues);
1152
+ const neighbors = readNeighbors(value.neighbors, issues);
1153
+ if (issues.length > 0 || !devices || !interfaces || !links || !vlans || !neighbors) {
1154
+ return { document: null, issues };
1155
+ }
1156
+ const names = /* @__PURE__ */ new Map();
1157
+ devices.forEach((device, index) => {
1158
+ const key = device.name.toLowerCase();
1159
+ const previous = names.get(key);
1160
+ if (previous != null) {
1161
+ issues.push({ path: `/devices/${index}/name`, message: `duplicate device "${previous}".` });
1162
+ return;
1163
+ }
1164
+ names.set(key, device.name);
1165
+ });
1166
+ interfaces.forEach((item, index) => {
1167
+ if (!names.has(item.device.toLowerCase())) {
1168
+ issues.push({ path: `/interfaces/${index}/device`, message: `no device named "${item.device}".` });
1169
+ }
1170
+ });
1171
+ links.forEach((link, index) => {
1172
+ for (const side of ["a", "b"]) {
1173
+ const end = link[side];
1174
+ if (!names.has(end.device.toLowerCase())) {
1175
+ issues.push({ path: `/links/${index}/${side}/device`, message: `no device named "${end.device}".` });
1176
+ }
1177
+ }
1178
+ });
1179
+ if (issues.length > 0) return { document: null, issues };
1180
+ return {
1181
+ document: { schemaVersion: 1, devices, interfaces, links, vlans, neighbors },
1182
+ issues: []
1183
+ };
1184
+ }
1185
+ function readDevices(value, issues) {
1186
+ if (!Array.isArray(value)) {
1187
+ issues.push({ path: "/devices", message: "devices must be an array." });
1188
+ return null;
1189
+ }
1190
+ let ok = true;
1191
+ const devices = [];
1192
+ value.forEach((item, index) => {
1193
+ const path5 = `/devices/${index}`;
1194
+ if (!isRecord2(item)) {
1195
+ issues.push({ path: path5, message: "must be an object." });
1196
+ ok = false;
1197
+ return;
1198
+ }
1199
+ rejectUnknown(item, DEVICE_FIELDS, path5, issues);
1200
+ const name = requiredString(item.name, `${path5}/name`, "name", issues);
1201
+ if (!name) {
1202
+ ok = false;
1203
+ return;
1204
+ }
1205
+ const diagram = childDiagram(item.diagram, `${path5}/diagram`, issues);
1206
+ if (diagram == null) {
1207
+ ok = false;
1208
+ return;
1209
+ }
1210
+ devices.push({
1211
+ name,
1212
+ platform: optionalString(item.platform, `${path5}/platform`, "platform", issues),
1213
+ model: optionalString(item.model, `${path5}/model`, "model", issues),
1214
+ role: optionalString(item.role, `${path5}/role`, "role", issues),
1215
+ site: optionalString(item.site, `${path5}/site`, "site", issues),
1216
+ managementIp: optionalString(item.managementIp, `${path5}/managementIp`, "managementIp", issues),
1217
+ diagram
1218
+ });
1219
+ });
1220
+ return ok && !issues.some((issue) => issue.path.startsWith("/devices/")) ? devices : null;
1221
+ }
1222
+ function readInterfaces(value, issues) {
1223
+ if (!Array.isArray(value)) {
1224
+ issues.push({ path: "/interfaces", message: "interfaces must be an array." });
1225
+ return null;
1226
+ }
1227
+ const interfaces = [];
1228
+ let ok = true;
1229
+ value.forEach((item, index) => {
1230
+ const path5 = `/interfaces/${index}`;
1231
+ if (!isRecord2(item)) {
1232
+ issues.push({ path: path5, message: "must be an object." });
1233
+ ok = false;
1234
+ return;
1235
+ }
1236
+ rejectUnknown(item, INTERFACE_FIELDS, path5, issues);
1237
+ const device = requiredString(item.device, `${path5}/device`, "device", issues);
1238
+ const name = requiredString(item.name, `${path5}/name`, "name", issues);
1239
+ const adminStatus = statusOf(item.adminStatus, `${path5}/adminStatus`, "adminStatus", issues);
1240
+ const operStatus = statusOf(item.operStatus, `${path5}/operStatus`, "operStatus", issues);
1241
+ const ipv4 = item.ipv4 == null ? [] : readAddresses(item.ipv4, `${path5}/ipv4`, "ipv4", issues);
1242
+ const ipv6 = item.ipv6 == null ? [] : readAddresses(item.ipv6, `${path5}/ipv6`, "ipv6", issues);
1243
+ const mode = switchportOf(item.switchportMode, `${path5}/switchportMode`, issues);
1244
+ const accessVlan = item.accessVlan == null ? null : vlanId(item.accessVlan, `${path5}/accessVlan`, issues);
1245
+ const nativeVlan = item.nativeVlan == null ? null : vlanId(item.nativeVlan, `${path5}/nativeVlan`, issues);
1246
+ const trunkVlans = item.trunkVlans == null ? null : readVlanList(item.trunkVlans, `${path5}/trunkVlans`, issues);
1247
+ if (!device || !name || adminStatus == null || operStatus == null || !ipv4 || !ipv6 || mode == null) {
1248
+ ok = false;
1249
+ return;
1250
+ }
1251
+ if (item.accessVlan != null && accessVlan == null || item.nativeVlan != null && nativeVlan == null) ok = false;
1252
+ if (item.trunkVlans != null && !trunkVlans) ok = false;
1253
+ interfaces.push({
1254
+ device,
1255
+ name,
1256
+ description: optionalString(item.description, `${path5}/description`, "description", issues),
1257
+ speed: optionalString(item.speed, `${path5}/speed`, "speed", issues),
1258
+ adminStatus,
1259
+ operStatus,
1260
+ ipv4,
1261
+ ipv6,
1262
+ vrf: optionalString(item.vrf, `${path5}/vrf`, "vrf", issues),
1263
+ switchportMode: mode,
1264
+ accessVlan,
1265
+ trunkVlans,
1266
+ nativeVlan,
1267
+ lag: optionalString(item.lag, `${path5}/lag`, "lag", issues)
1268
+ });
1269
+ });
1270
+ return ok ? interfaces : null;
1271
+ }
1272
+ function readAddresses(value, path5, family, issues) {
1273
+ if (!Array.isArray(value)) {
1274
+ issues.push({ path: path5, message: `${family} must be an array.` });
1275
+ return null;
1276
+ }
1277
+ const max = family === "ipv4" ? 32 : 128;
1278
+ const addresses = [];
1279
+ let ok = true;
1280
+ value.forEach((item, index) => {
1281
+ const itemPath = `${path5}/${index}`;
1282
+ if (!isRecord2(item)) {
1283
+ issues.push({ path: itemPath, message: "must be an object with address and prefix." });
1284
+ ok = false;
1285
+ return;
1286
+ }
1287
+ rejectUnknown(item, ADDRESS_FIELDS, itemPath, issues);
1288
+ const address = requiredString(item.address, `${itemPath}/address`, "address", issues);
1289
+ const prefixOk = Number.isInteger(item.prefix) && item.prefix >= 0 && item.prefix <= max;
1290
+ if (!prefixOk) {
1291
+ issues.push({ path: `${itemPath}/prefix`, message: `prefix must be an integer from 0 to ${max}.` });
1292
+ ok = false;
1293
+ }
1294
+ if (!address) {
1295
+ ok = false;
1296
+ return;
1297
+ }
1298
+ if (!canonicalIp(address, family)) {
1299
+ issues.push({
1300
+ path: `${itemPath}/address`,
1301
+ message: family === "ipv4" ? "address must be an IPv4 address." : "address must be an IPv6 address."
1302
+ });
1303
+ ok = false;
1304
+ return;
1305
+ }
1306
+ if (prefixOk) addresses.push({ address, prefix: item.prefix });
1307
+ });
1308
+ return ok ? addresses : null;
1309
+ }
1310
+ function readLinks(value, issues) {
1311
+ if (!Array.isArray(value)) {
1312
+ issues.push({ path: "/links", message: "links must be an array." });
1313
+ return null;
1314
+ }
1315
+ const links = [];
1316
+ let ok = true;
1317
+ value.forEach((item, index) => {
1318
+ const path5 = `/links/${index}`;
1319
+ if (!isRecord2(item)) {
1320
+ issues.push({ path: path5, message: "must be an object with a and b." });
1321
+ ok = false;
1322
+ return;
1323
+ }
1324
+ rejectUnknown(item, LINK_FIELDS, path5, issues);
1325
+ const a = readEndpoint(item.a, `${path5}/a`, issues);
1326
+ const b = readEndpoint(item.b, `${path5}/b`, issues);
1327
+ if (!a || !b) {
1328
+ ok = false;
1329
+ return;
1330
+ }
1331
+ const inferred = optionalFlag(item.inferred, `${path5}/inferred`, "inferred", issues);
1332
+ if (inferred == null) {
1333
+ ok = false;
1334
+ return;
1335
+ }
1336
+ links.push({
1337
+ a,
1338
+ b,
1339
+ label: optionalString(item.label, `${path5}/label`, "label", issues),
1340
+ inferred
1341
+ });
1342
+ });
1343
+ return ok ? links : null;
1344
+ }
1345
+ function readEndpoint(value, path5, issues) {
1346
+ if (!isRecord2(value)) {
1347
+ issues.push({ path: path5, message: "must be an object with device and interface." });
1348
+ return null;
1349
+ }
1350
+ rejectUnknown(value, ENDPOINT_FIELDS, path5, issues);
1351
+ const device = requiredString(value.device, `${path5}/device`, "device", issues);
1352
+ const iface = requiredString(value.interface, `${path5}/interface`, "interface", issues);
1353
+ if (!device || !iface) return null;
1354
+ return { device, interface: iface };
1355
+ }
1356
+ function readVlanList(value, path5, issues) {
1357
+ if (!Array.isArray(value)) {
1358
+ issues.push({ path: path5, message: "trunkVlans must be an array of VLAN ids." });
1359
+ return null;
1360
+ }
1361
+ const ids = [];
1362
+ let ok = true;
1363
+ value.forEach((item, index) => {
1364
+ const id = vlanId(item, `${path5}/${index}`, issues);
1365
+ if (id == null) ok = false;
1366
+ else ids.push(id);
1367
+ });
1368
+ return ok ? ids : null;
1369
+ }
1370
+ function readVlans(value, issues) {
1371
+ if (!Array.isArray(value)) {
1372
+ issues.push({ path: "/vlans", message: "vlans must be an array." });
1373
+ return null;
1374
+ }
1375
+ const vlans = [];
1376
+ const seen = /* @__PURE__ */ new Set();
1377
+ let ok = true;
1378
+ value.forEach((item, index) => {
1379
+ const path5 = `/vlans/${index}`;
1380
+ if (!isRecord2(item)) {
1381
+ issues.push({ path: path5, message: "must be an object." });
1382
+ ok = false;
1383
+ return;
1384
+ }
1385
+ rejectUnknown(item, VLAN_FIELDS, path5, issues);
1386
+ const id = vlanId(item.id, `${path5}/id`, issues);
1387
+ if (id == null) {
1388
+ ok = false;
1389
+ return;
1390
+ }
1391
+ if (seen.has(id)) issues.push({ path: `${path5}/id`, message: `duplicate VLAN ${id}.` });
1392
+ seen.add(id);
1393
+ vlans.push({ id, name: optionalString(item.name, `${path5}/name`, "name", issues) });
1394
+ });
1395
+ return ok ? vlans : null;
1396
+ }
1397
+ function readNeighbors(value, issues) {
1398
+ if (value == null) return { cdp: "", lldp: "", localDevice: "" };
1399
+ if (!isRecord2(value)) {
1400
+ issues.push({ path: "/neighbors", message: "neighbors must be an object." });
1401
+ return null;
1402
+ }
1403
+ rejectUnknown(value, NEIGHBOR_FIELDS, "/neighbors", issues);
1404
+ return {
1405
+ cdp: optionalString(value.cdp, "/neighbors/cdp", "cdp", issues),
1406
+ lldp: optionalString(value.lldp, "/neighbors/lldp", "lldp", issues),
1407
+ localDevice: optionalString(value.localDevice, "/neighbors/localDevice", "localDevice", issues)
1408
+ };
1409
+ }
1410
+ function statusOf(value, path5, label, issues) {
1411
+ if (value == null || value === "") return "";
1412
+ if (value === "up" || value === "down") return value;
1413
+ issues.push({ path: path5, message: `${label} must be up or down.` });
1414
+ return null;
1415
+ }
1416
+ function switchportOf(value, path5, issues) {
1417
+ if (value == null || value === "") return "";
1418
+ if (value === "access" || value === "trunk") return value;
1419
+ issues.push({ path: path5, message: "switchportMode must be access or trunk." });
1420
+ return null;
1421
+ }
1422
+ function vlanId(value, path5, issues) {
1423
+ if (typeof value === "number" && Number.isInteger(value) && value >= 1 && value <= 4094) return value;
1424
+ issues.push({ path: path5, message: "must be an integer from 1 to 4094." });
1425
+ return null;
1426
+ }
1427
+ function requiredString(value, path5, label, issues) {
1428
+ if (typeof value !== "string" || !value.trim()) {
1429
+ issues.push({ path: path5, message: `${label} is required.` });
1430
+ return "";
1431
+ }
1432
+ return value.trim();
1433
+ }
1434
+ function childDiagram(value, path5, issues) {
1435
+ if (value == null || value === "") return "";
1436
+ if (typeof value !== "string") {
1437
+ issues.push({ path: path5, message: "diagram must be a string." });
1438
+ return null;
1439
+ }
1440
+ const trimmed = value.trim();
1441
+ if (!trimmed) return "";
1442
+ if (/[\u0000-\u001f"\\?#]/.test(trimmed) || clickTargetKind(trimmed) === "unsafe" || clickTargetKind(trimmed) === "external") {
1443
+ issues.push({ path: path5, message: "diagram must be a workspace .mmd path." });
1444
+ return null;
1445
+ }
1446
+ const resolved = resolveDiagramTarget(trimmed, "");
1447
+ if (!resolved.ok) {
1448
+ issues.push({ path: path5, message: "diagram must be a workspace .mmd path." });
1449
+ return null;
1450
+ }
1451
+ return resolved.path;
1452
+ }
1453
+ function optionalFlag(value, path5, label, issues) {
1454
+ if (value == null) return false;
1455
+ if (typeof value === "boolean") return value;
1456
+ issues.push({ path: path5, message: `${label} must be a boolean.` });
1457
+ return null;
1458
+ }
1459
+ function optionalString(value, path5, label, issues) {
1460
+ if (value == null || value === "") return "";
1461
+ if (typeof value !== "string") {
1462
+ issues.push({ path: path5, message: `${label} must be a string.` });
1463
+ return "";
1464
+ }
1465
+ return value.trim();
1466
+ }
1467
+ function rejectUnknown(value, allowed, path5, issues) {
1468
+ for (const key of Object.keys(value)) {
1469
+ if (allowed.has(key)) continue;
1470
+ issues.push({ path: path5 ? `${path5}/${key}` : `/${key}`, message: `unexpected property "${key}".` });
1471
+ }
1472
+ }
1473
+ function isRecord2(value) {
1474
+ return Boolean(value) && typeof value === "object" && !Array.isArray(value);
1475
+ }
1476
+
1022
1477
  // server/src/diagramData.ts
1023
1478
  var DATA_LIMITS = {
1024
1479
  maxChars: 512 * 1024,
@@ -1068,6 +1523,9 @@ var SHAPE_FIELDS = {
1068
1523
  ]
1069
1524
  };
1070
1525
  var EDGE_FIELDS = SHAPE_FIELDS.edges;
1526
+ function dataFail(status, message, code, details) {
1527
+ return Object.assign(new Error(message), { status, code, details });
1528
+ }
1071
1529
 
1072
1530
  // server/src/diagramSightings.ts
1073
1531
  import path from "node:path";
@@ -1469,7 +1927,7 @@ async function writeFile(relativePath, content, options = {}) {
1469
1927
  await atomicWriteText(abs, content);
1470
1928
  await dropThumbnail(relative);
1471
1929
  const stat = await fs2.stat(abs);
1472
- const search = await import("./chunk-LYMG57VV.js");
1930
+ const search = await import("./chunk-R3RZTEM3.js");
1473
1931
  await search.rememberSearchEntry(relative, content, stat.mtimeMs, stat.size);
1474
1932
  await noteDiagramSighting({ path: relative, hash: hashContent(content) });
1475
1933
  noteSync({ kind: "content", summary: `Update ${relative}` });
@@ -1482,12 +1940,15 @@ async function writeFile(relativePath, content, options = {}) {
1482
1940
  };
1483
1941
  }
1484
1942
  function noteSync(change) {
1485
- void import("./chunk-LXSDAIF4.js").then((mod) => mod.noteLocalChange(change)).catch(() => {
1943
+ void import("./chunk-7GEA3JEU.js").then((mod) => mod.noteLocalChange(change)).catch(() => {
1486
1944
  console.error("GitHub sync could not record a local change");
1487
1945
  });
1488
1946
  }
1489
1947
 
1490
1948
  export {
1949
+ canonicalIp,
1950
+ validateNetwork,
1951
+ dataFail,
1491
1952
  buildTree,
1492
1953
  readFile,
1493
1954
  writeFile
@@ -1,12 +1,14 @@
1
- import "./chunk-JL7RYIQE.js";
1
+ import "./chunk-5IHMGYXV.js";
2
+ import "./chunk-6ELR2KYA.js";
2
3
  import {
3
4
  ensureDataRoot,
4
5
  getMetaPath,
5
6
  httpFail,
6
7
  isDataFileName
7
8
  } from "./chunk-KA5X3YY6.js";
8
- import "./chunk-5C6VO4LC.js";
9
+ import "./chunk-BW6ANOTX.js";
9
10
  import "./chunk-6LCHDAAN.js";
11
+ import "./chunk-MLKGABMK.js";
10
12
 
11
13
  // server/src/sync/engine.ts
12
14
  import fsp2 from "node:fs/promises";