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.
@@ -0,0 +1,87 @@
1
+ import {
2
+ EXPORTER_INFRA,
3
+ assertExporterModule,
4
+ exporterBasenames,
5
+ exporterById,
6
+ exporterDirectory,
7
+ installedExporters,
8
+ listExporterInfo,
9
+ loadExporters,
10
+ loadedExporterIds,
11
+ runExport
12
+ } from "./chunk-KIK3WXJL.js";
13
+ import {
14
+ labelFromPath,
15
+ parseNetworkDocument,
16
+ readDiagramNetwork
17
+ } from "./chunk-WYQ4QDCF.js";
18
+ import {
19
+ EXPORT_MAX_DEVICES,
20
+ EXPORT_MAX_INPUT_BYTES,
21
+ EXPORT_MAX_LINKS,
22
+ assertExportInputSize,
23
+ exporterFail,
24
+ isRecord,
25
+ mappingRowsFromUnknown
26
+ } from "./chunk-ARL7TA3D.js";
27
+ import "./chunk-M63FV47T.js";
28
+ import "./chunk-BW6ANOTX.js";
29
+ import "./chunk-6LCHDAAN.js";
30
+ import "./chunk-MLKGABMK.js";
31
+
32
+ // server/src/exporters/request.ts
33
+ function own(record, key) {
34
+ return Object.prototype.hasOwnProperty.call(record, key);
35
+ }
36
+ async function prepareExport(options) {
37
+ assertExportInputSize(options.bytes);
38
+ const record = isRecord(options.body) ? options.body : null;
39
+ let label = "nerdgram";
40
+ let mapping = null;
41
+ let mappingDocument = null;
42
+ if (record && own(record, "mapping")) {
43
+ if (Array.isArray(record.mapping)) mapping = mappingRowsFromUnknown(record.mapping);
44
+ else mappingDocument = record.mapping;
45
+ }
46
+ if (record && typeof record.label === "string" && record.label.trim()) label = record.label.trim();
47
+ let document;
48
+ if (record && typeof record.path === "string" && record.path.trim()) {
49
+ const filePath = record.path.trim();
50
+ if (!options.readText) throw exporterFail(400, "path is only valid for a workspace file.");
51
+ if (filePath.toLowerCase().endsWith(".mmd")) {
52
+ const loaded = await readDiagramNetwork(filePath, options.readText);
53
+ document = loaded.document;
54
+ label = loaded.label;
55
+ } else if (filePath.toLowerCase().endsWith(".network.json")) {
56
+ const text = await options.readText(filePath).catch(() => {
57
+ throw exporterFail(400, `Could not read ${filePath}.`);
58
+ });
59
+ document = parseNetworkDocument(text);
60
+ label = labelFromPath(filePath);
61
+ } else {
62
+ throw exporterFail(400, "path must be a diagram or a .network.json file.");
63
+ }
64
+ } else if (record && own(record, "input")) {
65
+ document = parseNetworkDocument(JSON.stringify(record.input));
66
+ } else {
67
+ document = parseNetworkDocument(JSON.stringify(options.body));
68
+ }
69
+ return runExport(options.target, document, { label, mapping }, mappingDocument);
70
+ }
71
+ export {
72
+ EXPORTER_INFRA,
73
+ EXPORT_MAX_DEVICES,
74
+ EXPORT_MAX_INPUT_BYTES,
75
+ EXPORT_MAX_LINKS,
76
+ assertExportInputSize,
77
+ assertExporterModule,
78
+ exporterBasenames,
79
+ exporterById,
80
+ exporterDirectory,
81
+ installedExporters,
82
+ listExporterInfo,
83
+ loadExporters,
84
+ loadedExporterIds,
85
+ prepareExport,
86
+ runExport
87
+ };
@@ -0,0 +1,70 @@
1
+ // server/src/readError.ts
2
+ var READ_REASONS = {
3
+ EIO: "The file may still be syncing or the folder may be unavailable on this computer",
4
+ EACCES: "This computer does not have permission to read the file",
5
+ EPERM: "This computer does not have permission to read the file",
6
+ ENOENT: "The file was removed or renamed before it could be read",
7
+ EBUSY: "The file is busy and could not be read",
8
+ ETIMEDOUT: "Reading the file timed out. The folder may be slow or unavailable"
9
+ };
10
+ var KNOWN_READ_ERRNOS = new Set(Object.keys(READ_REASONS));
11
+ function isKnownReadErrno(code) {
12
+ return KNOWN_READ_ERRNOS.has(code);
13
+ }
14
+ function fileLabel(filePath) {
15
+ const absolute = filePath.startsWith("/") || /^[A-Za-z]:[\\/]/.test(filePath);
16
+ if (!absolute) return filePath || "diagram";
17
+ const slash = Math.max(filePath.lastIndexOf("/"), filePath.lastIndexOf("\\"));
18
+ const name = slash >= 0 ? filePath.slice(slash + 1) : filePath;
19
+ return name || filePath;
20
+ }
21
+ function unreadableWarning(filePath, code) {
22
+ const suffix = code ? ` (${code})` : "";
23
+ return `Couldn't read ${fileLabel(filePath)}${suffix}.`;
24
+ }
25
+ function warnUnreadable(items) {
26
+ for (const item of items) console.warn(unreadableWarning(item.path, item.code));
27
+ }
28
+ function unreadableMessage(filePath, code) {
29
+ const reason = READ_REASONS[code] ?? "The file could not be read";
30
+ const suffix = code ? ` (${code})` : "";
31
+ return `Couldn't read \`${fileLabel(filePath)}\`. ${reason}${suffix}.`;
32
+ }
33
+ function detailsErrno(err) {
34
+ if (!err || typeof err !== "object" || !("details" in err)) return "";
35
+ const details = err.details;
36
+ if (!details || typeof details !== "object" || !("errno" in details)) return "";
37
+ const errno = details.errno;
38
+ return typeof errno === "string" ? errno : "";
39
+ }
40
+ function errnoInText(err) {
41
+ const message = err instanceof Error ? err.message : "";
42
+ const match = message.match(/\b(EIO|EACCES|EPERM|ENOENT|EBUSY|ETIMEDOUT)\b/);
43
+ return match?.[1] ?? "";
44
+ }
45
+ function errnoFrom(err) {
46
+ const fromDetails = detailsErrno(err);
47
+ if (/^E[A-Z0-9]+$/.test(fromDetails)) return fromDetails;
48
+ if (err && typeof err === "object" && "code" in err) {
49
+ const code = String(err.code);
50
+ if (/^E[A-Z0-9]+$/.test(code)) return code;
51
+ }
52
+ return errnoInText(err);
53
+ }
54
+ function isMissingFile(err) {
55
+ if (!err || typeof err !== "object") return false;
56
+ if ("code" in err && err.code === "not_found") return true;
57
+ return "status" in err && err.status === 404;
58
+ }
59
+ function reportUnreadable(filePath, err) {
60
+ const code = errnoFrom(err) || (isMissingFile(err) ? "ENOENT" : "");
61
+ return { path: filePath, code, message: unreadableMessage(filePath, code) };
62
+ }
63
+
64
+ export {
65
+ isKnownReadErrno,
66
+ warnUnreadable,
67
+ unreadableMessage,
68
+ errnoFrom,
69
+ reportUnreadable
70
+ };