@dooc-dev/dooc 0.0.4 → 0.0.6
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/dist/cli.js +157 -58
- package/dist/code-worker.global.js +152 -0
- package/dist/code.global.js +101 -101
- package/dist/compiler/asset-references.d.ts +4 -0
- package/dist/compiler/asset-references.js +117 -0
- package/dist/compiler/bundle-urls.d.ts +1 -1
- package/dist/compiler/bundle-urls.js +17 -5
- package/dist/compiler/check.js +10 -5
- package/dist/compiler/code-languages.js +7 -2
- package/dist/compiler/compile.d.ts +5 -0
- package/dist/compiler/compile.js +117 -12
- package/dist/compiler/config.js +2 -1
- package/dist/compiler/dxf.d.ts +1 -0
- package/dist/compiler/dxf.js +81 -0
- package/dist/compiler/export.d.ts +4 -0
- package/dist/compiler/export.js +147 -0
- package/dist/compiler/figures.js +43 -10
- package/dist/compiler/files.js +82 -41
- package/dist/compiler/fonts.js +4 -1
- package/dist/compiler/icons.d.ts +1 -1
- package/dist/compiler/icons.js +11 -2
- package/dist/compiler/ignored-files.d.ts +5 -0
- package/dist/compiler/ignored-files.js +98 -0
- package/dist/compiler/locales.js +13 -8
- package/dist/compiler/ops.d.ts +6 -0
- package/dist/compiler/ops.js +99 -8
- package/dist/compiler/subformat-schema.d.ts +14 -0
- package/dist/compiler/subformat-schema.js +92 -0
- package/dist/compiler/subformats.d.ts +22 -0
- package/dist/compiler/subformats.js +339 -0
- package/dist/compiler/textfile.js +3 -0
- package/dist/compiler/theme-variants.js +5 -2
- package/dist/core/code-file.js +7 -5
- package/dist/core/code-grammars.d.ts +5 -0
- package/dist/core/code-grammars.js +34 -0
- package/dist/core/content-metadata.d.ts +16 -6
- package/dist/core/content-metadata.js +283 -17
- package/dist/core/content-types.d.ts +4 -2
- package/dist/core/escape-html.d.ts +1 -0
- package/dist/core/escape-html.js +1 -0
- package/dist/core/figure-frame.js +20 -2
- package/dist/core/file-embed.js +7 -3
- package/dist/core/files.d.ts +2 -1
- package/dist/core/files.js +6 -8
- package/dist/core/flow-base-css.generated.js +1 -1
- package/dist/core/html.d.ts +4 -1
- package/dist/core/html.js +11 -10
- package/dist/core/icons.d.ts +3 -0
- package/dist/core/icons.js +3 -0
- package/dist/core/json-tools.d.ts +1 -0
- package/dist/core/json-tools.js +12 -0
- package/dist/core/language.js +5 -2
- package/dist/core/markdown.js +3 -1
- package/dist/core/previewers.d.ts +8 -0
- package/dist/core/previewers.js +2 -0
- package/dist/core/routing.d.ts +5 -2
- package/dist/core/routing.js +17 -5
- package/dist/core/schema-fields.d.ts +13 -0
- package/dist/core/schema-fields.js +175 -0
- package/dist/core/schema-graph-mount.js +26 -3
- package/dist/core/schema-refs.d.ts +8 -0
- package/dist/core/schema-refs.js +82 -0
- package/dist/core/subformat-record.d.ts +3 -0
- package/dist/core/subformat-record.js +131 -0
- package/dist/core/subformats.d.ts +43 -0
- package/dist/core/subformats.js +81 -0
- package/dist/core/toc-ui.js +26 -24
- package/dist/edit.global.js +326 -118
- package/dist/flow.global.js +3 -3
- package/dist/graph/abnfDiagram-S7VZAUFO-ASBULSKE.js +1 -0
- package/dist/graph/architecture-WOLXFQ4H-V57EDXXY.js +1 -0
- package/dist/graph/architectureDiagram-YGSQEFNW-GIMP347N.js +36 -0
- package/dist/graph/blockDiagram-APKKGZFW-RDL2T4JW.js +140 -0
- package/dist/graph/bpmnIcons-APHXDYXF-TWOSQNUQ.js +1 -0
- package/dist/graph/c4Diagram-KJ2TOQU5-75LIUC4F.js +38 -0
- package/dist/graph/chunk-26TUJSYJ.js +1 -0
- package/dist/graph/chunk-3LU66YMI.js +1 -0
- package/dist/graph/chunk-3RNHDNP5.js +1 -0
- package/dist/graph/chunk-3Y2PDVDE.js +1 -0
- package/dist/graph/chunk-3YJHMOOA.js +3 -0
- package/dist/graph/chunk-4KILFWYV.js +339 -0
- package/dist/graph/chunk-4QDE4SUK.js +1 -0
- package/dist/graph/chunk-5OO6DATX.js +1 -0
- package/dist/graph/chunk-5UUEAHTN.js +1 -0
- package/dist/graph/chunk-6T55RVVR.js +1 -0
- package/dist/graph/chunk-ARAJTKOH.js +2 -0
- package/dist/graph/chunk-BBD5CEDC.js +72 -0
- package/dist/graph/chunk-BVXT562I.js +1 -0
- package/dist/graph/chunk-BZAMCJ6B.js +32 -0
- package/dist/graph/chunk-C6J4A356.js +15 -0
- package/dist/graph/chunk-EG5UVNOC.js +213 -0
- package/dist/graph/chunk-GF4TOPUK.js +1 -0
- package/dist/graph/chunk-GYT4IYBZ.js +1 -0
- package/dist/graph/chunk-HJG2HUYJ.js +88 -0
- package/dist/graph/chunk-HOPPTA6H.js +62 -0
- package/dist/graph/chunk-I3DMZIHV.js +1 -0
- package/dist/graph/chunk-IC23EEF6.js +1 -0
- package/dist/graph/chunk-ISO77HML.js +1 -0
- package/dist/graph/chunk-JD7ZBJD2.js +1 -0
- package/dist/graph/chunk-JRSH5GNS.js +1 -0
- package/dist/graph/chunk-JSHWCPFJ.js +1 -0
- package/dist/graph/chunk-K2KLZU7M.js +10 -0
- package/dist/graph/chunk-K4I76XBX.js +14 -0
- package/dist/graph/chunk-KT4VPQD5.js +135 -0
- package/dist/graph/chunk-KU6GTEMS.js +1 -0
- package/dist/graph/chunk-LT6LXKCR.js +136 -0
- package/dist/graph/chunk-MPR575IN.js +1 -0
- package/dist/graph/chunk-N3OHKGRZ.js +1 -0
- package/dist/graph/chunk-O656ZI37.js +1 -0
- package/dist/graph/chunk-OFZLK5G4.js +1 -0
- package/dist/graph/chunk-PDH25ALM.js +2 -0
- package/dist/graph/chunk-PW2RGZ3O.js +1 -0
- package/dist/graph/chunk-QCJUF4YA.js +1 -0
- package/dist/graph/chunk-QEEA3KYY.js +2 -0
- package/dist/graph/chunk-QYAXYFNI.js +1 -0
- package/dist/graph/chunk-QYTM6GY3.js +1 -0
- package/dist/graph/chunk-R63JUMUK.js +1 -0
- package/dist/graph/chunk-SCEY3ZPT.js +1 -0
- package/dist/graph/chunk-VM2H7G2R.js +1 -0
- package/dist/graph/chunk-XQS73SBQ.js +1 -0
- package/dist/graph/chunk-YCRLJT2S.js +1 -0
- package/dist/graph/chunk-Z4FIZ7CR.js +1 -0
- package/dist/graph/chunk-ZMCB7VP2.js +1 -0
- package/dist/graph/chunk-ZSZXN4BT.js +2 -0
- package/dist/graph/classDiagram-v2-L25IHNXF-JL7LVDZH.js +217 -0
- package/dist/graph/cose-bilkent-JH36ORCC-PNM3EYPB.js +1 -0
- package/dist/graph/cynefin-EF2NZ3EQ-PSXP3DXL.js +1 -0
- package/dist/graph/cynefinDiagram-L36ESFBY-QVY54CXO.js +62 -0
- package/dist/graph/dagre-SPEB5RXH-HPGQXBZJ.js +4 -0
- package/dist/graph/diagram-3B7GL73J-DWH5WS2P.js +200 -0
- package/dist/graph/diagram-DNEMPZML-TEGH2U5I.js +24 -0
- package/dist/graph/diagram-L3MUGCDN-X4MREUWR.js +41 -0
- package/dist/graph/diagram-LA4NIPWU-NXT746HG.js +24 -0
- package/dist/graph/diagram-MHCOC4E2-JGHXSAGS.js +3 -0
- package/dist/graph/diagram-XPFHEONP-ZHZPBLT4.js +30 -0
- package/dist/graph/ebnfDiagram-UZSYDL2S-SMF6KJ43.js +1 -0
- package/dist/graph/elk-XV6XMXQE-AZ4HLCWI.js +27 -0
- package/dist/graph/erDiagram-EYBAPDEH-B3JNJ357.js +99 -0
- package/dist/graph/eventmodeling-K75KTNOO-WG6DDYMC.js +1 -0
- package/dist/graph/flowDiagram-MALGAFMO-2R7EYAQI.js +1 -0
- package/dist/graph/ganttDiagram-23REXITY-YXBYWFOJ.js +292 -0
- package/dist/graph/gitGraph-VSP46ZUC-VBFWJBBT.js +1 -0
- package/dist/graph/gitGraphDiagram-STJD7YCW-4FZDCFGV.js +106 -0
- package/dist/graph/info-OHQRW6UA-ALVDUVYV.js +1 -0
- package/dist/graph/infoDiagram-KBXO4MBG-7EHX2GQG.js +2 -0
- package/dist/graph/ishikawaDiagram-M35NCXHK-FRZD2PWQ.js +70 -0
- package/dist/graph/journeyDiagram-OPLOXDXO-7Z66JCPR.js +139 -0
- package/dist/graph/kanban-definition-BZKZHSQY-NN5AIKTE.js +89 -0
- package/dist/graph/katex-DXDNVO6V.js +257 -0
- package/dist/graph/mindmap-definition-I2QAS2VK-HDPCABN2.js +98 -0
- package/dist/graph/packet-JDAUHWVQ-5MQIBWAH.js +1 -0
- package/dist/graph/pegDiagram-FD4XPPHP-H2BFNCKT.js +1 -0
- package/dist/graph/pie-XZMESJXO-T5VRKHVT.js +1 -0
- package/dist/graph/pieDiagram-J4AKIIQI-O3NJSVD3.js +39 -0
- package/dist/graph/quadrantDiagram-XTYBLID2-TMTZJI3P.js +7 -0
- package/dist/graph/radar-ABXABTNO-C6FXIBYW.js +1 -0
- package/dist/graph/railroad-I3PHUGI6-ZSO5JXB3.js +1 -0
- package/dist/graph/railroad-abnf-LNEFI6M7-CI4GQRHB.js +1 -0
- package/dist/graph/railroad-ebnf-DWYD2UWJ-MUENNCGK.js +1 -0
- package/dist/graph/railroad-peg-JR7BVNR7-N3X5GGIX.js +1 -0
- package/dist/graph/railroadDiagram-MRQ6NCDL-JHWS23UO.js +1 -0
- package/dist/graph/requirementDiagram-Y7LWUY3S-7DVLPO4B.js +84 -0
- package/dist/graph/sankeyDiagram-WGJFYUXA-Z5L4R5TR.js +40 -0
- package/dist/graph/schema-graph-global.js +639 -0
- package/dist/graph/sequenceDiagram-5NDRBG5M-RCTU25NT.js +169 -0
- package/dist/graph/sizeCapture-INFHLROL-RROY32P5.js +1 -0
- package/dist/graph/stateDiagram-v2-FJ4FJNEA-BXUSPWDK.js +291 -0
- package/dist/graph/swimlanes-UMQ2AFYF-LDD74Q2S.js +1 -0
- package/dist/graph/swimlanesDiagram-OMPLPG4O-ZYULLJSU.js +8 -0
- package/dist/graph/timeline-definition-SEUHKTQE-ZQSMIVAS.js +120 -0
- package/dist/graph/treeView-D4JQ5SDB-42S7U73N.js +1 -0
- package/dist/graph/treemap-SAJKECNS-RUBYQ7XF.js +1 -0
- package/dist/graph/usecaseDiagram-AFA6YXN4-57RDRYXF.js +370 -0
- package/dist/graph/vennDiagram-NNMJR3RB-5C3LVAV6.js +34 -0
- package/dist/graph/wardley-7MLQ67FV-NV5HXTTC.js +1 -0
- package/dist/graph/wardleyDiagram-S7YFUSEH-6D5BKXHM.js +78 -0
- package/dist/graph/xychartDiagram-GGNKY7IX-6ET3ZM67.js +7 -0
- package/dist/mcp.js +54 -12
- package/dist/plugins/index.d.ts +1 -0
- package/dist/plugins/transport.d.ts +22 -0
- package/dist/plugins/transport.js +1 -0
- package/dist/plugins.global.js +95 -0
- package/dist/subformats.global.js +21 -0
- package/dist/ui.global.js +80 -60
- package/dist/viewer/build-plugins.d.ts +7 -0
- package/dist/viewer/build-plugins.js +70 -0
- package/dist/viewer/build.d.ts +11 -0
- package/dist/viewer/build.js +52 -11
- package/dist/viewer/code-file.js +7 -2
- package/dist/viewer/editor-tools.d.ts +7 -7
- package/dist/viewer/editor-tools.js +36 -5
- package/dist/viewer/figure-preview.d.ts +4 -0
- package/dist/viewer/figure-preview.js +54 -0
- package/dist/viewer/font-picker.js +5 -1
- package/dist/viewer/git-diff.d.ts +3 -0
- package/dist/viewer/git-diff.js +47 -0
- package/dist/viewer/hmr.js +8 -4
- package/dist/viewer/i18n.js +7 -5
- package/dist/viewer/language-picker.d.ts +2 -2
- package/dist/viewer/language-picker.js +26 -9
- package/dist/viewer/lazy-preview.d.ts +2 -0
- package/dist/viewer/lazy-preview.js +43 -0
- package/dist/viewer/locales/eng.json +95 -10
- package/dist/viewer/locales/jpn.json +96 -11
- package/dist/viewer/locales/zho.json +96 -11
- package/dist/viewer/nav-focus.js +8 -1
- package/dist/viewer/nav-update.d.ts +2 -0
- package/dist/viewer/nav-update.js +117 -0
- package/dist/viewer/plugin-blocks.js +1 -1
- package/dist/viewer/plugin-style.d.ts +1 -0
- package/dist/viewer/plugin-style.js +82 -0
- package/dist/viewer/plugins.js +1 -1
- package/dist/viewer/resize.d.ts +0 -2
- package/dist/viewer/resize.js +2 -98
- package/dist/viewer/resource-library.d.ts +11 -9
- package/dist/viewer/resource-library.js +181 -31
- package/dist/viewer/search.d.ts +4 -2
- package/dist/viewer/search.js +252 -53
- package/dist/viewer/serve.d.ts +11 -5
- package/dist/viewer/serve.js +913 -295
- package/dist/viewer/site-icon.js +13 -6
- package/dist/viewer/site-title.js +15 -2
- package/dist/viewer/textfile.d.ts +5 -0
- package/dist/viewer/textfile.js +34 -2
- package/dist/viewer/theme-picker.d.ts +2 -0
- package/dist/viewer/theme-picker.js +24 -8
- package/dist/viewer/workspace.d.ts +2 -0
- package/dist/viewer/workspace.js +46 -1
- package/package.json +27 -10
- package/dist/compiler/bundle.d.ts +0 -2
- package/dist/compiler/bundle.js +0 -100
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { spawnSync } from "node:child_process";
|
|
2
|
+
import { existsSync, readFileSync, realpathSync, statSync } from "node:fs";
|
|
3
|
+
import { dirname, join, posix, relative, resolve, sep } from "node:path";
|
|
4
|
+
import ignore, {} from "ignore";
|
|
5
|
+
let cached;
|
|
6
|
+
/** Share Git checks within one synchronous read, never across requests or writes. */
|
|
7
|
+
export const withIgnoredFilesCache = (read) => {
|
|
8
|
+
if (cached)
|
|
9
|
+
return read();
|
|
10
|
+
cached = new Map();
|
|
11
|
+
try {
|
|
12
|
+
return read();
|
|
13
|
+
}
|
|
14
|
+
finally {
|
|
15
|
+
cached = undefined;
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
/** Use Git's tracked-file and exclude rules; standalone folders use their .gitignore files. */
|
|
19
|
+
export const ignoredFiles = (root, files) => {
|
|
20
|
+
if (!cached)
|
|
21
|
+
return readIgnoredFiles(root, files);
|
|
22
|
+
const key = resolve(root);
|
|
23
|
+
let known = cached.get(key);
|
|
24
|
+
if (!known) {
|
|
25
|
+
known = new Map();
|
|
26
|
+
cached.set(key, known);
|
|
27
|
+
}
|
|
28
|
+
const missing = [...new Set(files.filter((file) => !known.has(file)))];
|
|
29
|
+
if (missing.length) {
|
|
30
|
+
const ignored = readIgnoredFiles(root, missing);
|
|
31
|
+
for (const file of missing)
|
|
32
|
+
known.set(file, ignored.has(file));
|
|
33
|
+
}
|
|
34
|
+
return new Set(files.filter((file) => known.get(file)));
|
|
35
|
+
};
|
|
36
|
+
const readIgnoredFiles = (root, files) => {
|
|
37
|
+
if (!files.length)
|
|
38
|
+
return new Set();
|
|
39
|
+
const hasGit = (directory) => existsSync(join(directory, ".git", "HEAD")) ||
|
|
40
|
+
statSync(join(directory, ".git"), { throwIfNoEntry: false })?.isFile();
|
|
41
|
+
let repository = resolve(root);
|
|
42
|
+
while (!hasGit(repository) && dirname(repository) !== repository)
|
|
43
|
+
repository = dirname(repository);
|
|
44
|
+
const inRepository = hasGit(repository);
|
|
45
|
+
if (inRepository) {
|
|
46
|
+
const result = spawnSync("git", ["-C", root, "check-ignore", "--stdin", "-z"], {
|
|
47
|
+
input: `${files.join("\0")}\0`,
|
|
48
|
+
encoding: "utf8",
|
|
49
|
+
timeout: 2_000,
|
|
50
|
+
maxBuffer: 5_000_000,
|
|
51
|
+
windowsHide: true,
|
|
52
|
+
});
|
|
53
|
+
if (result.status === 0 || result.status === 1)
|
|
54
|
+
return new Set(result.stdout.split("\0").filter(Boolean));
|
|
55
|
+
if (result.error?.code !== "ENOENT")
|
|
56
|
+
throw new Error(`Cannot check ignored files: ${result.error?.message ?? result.stderr.trim()}`);
|
|
57
|
+
}
|
|
58
|
+
const ignoreRoot = inRepository ? repository : root;
|
|
59
|
+
const prefix = relative(ignoreRoot, root).split(sep).join("/");
|
|
60
|
+
const rules = new Map();
|
|
61
|
+
const readRules = (directory) => {
|
|
62
|
+
let matcher = rules.get(directory);
|
|
63
|
+
if (!matcher) {
|
|
64
|
+
const path = join(ignoreRoot, directory, ".gitignore");
|
|
65
|
+
matcher = ignore().add(existsSync(path) ? readFileSync(path, "utf8") : "");
|
|
66
|
+
rules.set(directory, matcher);
|
|
67
|
+
}
|
|
68
|
+
return matcher;
|
|
69
|
+
};
|
|
70
|
+
return new Set(files.filter((file) => {
|
|
71
|
+
const normalized = posix.join(prefix, file);
|
|
72
|
+
const parts = normalized.replace(/\/$/, "").split("/");
|
|
73
|
+
const matchers = [];
|
|
74
|
+
for (let i = 0; i < parts.length; i++) {
|
|
75
|
+
const directory = parts.slice(0, i).join("/");
|
|
76
|
+
matchers.push(readRules(directory));
|
|
77
|
+
let ignored = false;
|
|
78
|
+
for (const [base, matcher] of matchers.entries()) {
|
|
79
|
+
const path = parts.slice(base, i + 1).join("/") +
|
|
80
|
+
(i < parts.length - 1 || file.endsWith("/") ? "/" : "");
|
|
81
|
+
const result = matcher.test(path);
|
|
82
|
+
if (result.ignored || result.unignored)
|
|
83
|
+
ignored = result.ignored;
|
|
84
|
+
}
|
|
85
|
+
if (ignored)
|
|
86
|
+
return true;
|
|
87
|
+
}
|
|
88
|
+
return false;
|
|
89
|
+
}));
|
|
90
|
+
};
|
|
91
|
+
export const assertNotIgnored = (root, file) => {
|
|
92
|
+
const path = join(root, file);
|
|
93
|
+
const resolved = existsSync(path)
|
|
94
|
+
? relative(realpathSync(root), realpathSync(path)).split(sep).join("/")
|
|
95
|
+
: file;
|
|
96
|
+
if (ignoredFiles(root, [...new Set([file, resolved])]).size)
|
|
97
|
+
throw new Error(`Referenced file is ignored by Git ignore rules: ${file}`);
|
|
98
|
+
};
|
package/dist/compiler/locales.js
CHANGED
|
@@ -5,6 +5,7 @@ import { isDocId } from "../core/content-metadata.js";
|
|
|
5
5
|
import { localFile } from "../core/files.js";
|
|
6
6
|
import { contentLanguageCode, DEFAULT_LANG } from "../core/language.js";
|
|
7
7
|
import { parseDoc } from "./dialect.js";
|
|
8
|
+
import { ignoredFiles } from "./ignored-files.js";
|
|
8
9
|
import { isContentLanguage } from "./language-codes.js";
|
|
9
10
|
import { docFile, readManifest } from "./manifest.js";
|
|
10
11
|
import { assembleDoc } from "./serialize.js";
|
|
@@ -32,14 +33,18 @@ export const siteContentLanguages = (root, manifest = readManifest(root)) => man
|
|
|
32
33
|
...translationLanguages(root),
|
|
33
34
|
]),
|
|
34
35
|
];
|
|
35
|
-
export const translationFiles = (root) =>
|
|
36
|
-
const
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
36
|
+
export const translationFiles = (root) => {
|
|
37
|
+
const files = translationLanguages(root).flatMap((language) => {
|
|
38
|
+
const directory = `locales/${language}`;
|
|
39
|
+
return readdirSync(textfilePath(root, directory), { recursive: true, withFileTypes: true })
|
|
40
|
+
.filter((entry) => entry.isFile() && entry.name.endsWith(".md"))
|
|
41
|
+
.map((entry) => relative(root, join(entry.parentPath, entry.name)).replaceAll("\\", "/"))
|
|
42
|
+
.filter(localFile)
|
|
43
|
+
.sort();
|
|
44
|
+
});
|
|
45
|
+
const ignored = ignoredFiles(root, files);
|
|
46
|
+
return files.filter((file) => !ignored.has(file));
|
|
47
|
+
};
|
|
43
48
|
export const setDocTranslation = (root, sourceLanguage, id, language, added) => {
|
|
44
49
|
if (!isDocId(id))
|
|
45
50
|
throw new Error("Invalid document id");
|
package/dist/compiler/ops.d.ts
CHANGED
|
@@ -19,6 +19,12 @@ export declare const createDocOps: (root: string) => {
|
|
|
19
19
|
addFile: (name: string, title: string, parent?: string) => OpResult<{
|
|
20
20
|
id: string;
|
|
21
21
|
}>;
|
|
22
|
+
addSubformat: (ext: string, title: string, parent?: string) => OpResult<{
|
|
23
|
+
id: string;
|
|
24
|
+
}>;
|
|
25
|
+
renameSubformat: (id: string, title: string) => OpResult<{
|
|
26
|
+
id: string;
|
|
27
|
+
}>;
|
|
22
28
|
move: (id: string, parent?: string, index?: number) => OpResult<{
|
|
23
29
|
id: string;
|
|
24
30
|
}>;
|
package/dist/compiler/ops.js
CHANGED
|
@@ -2,13 +2,13 @@
|
|
|
2
2
|
// add / remove figures). Shared by the viewer's edit API, the CLI (doc / figure) and MCP.
|
|
3
3
|
// Failures are returned as { error, status } (status is HTTP-like) with no partial updates.
|
|
4
4
|
import { existsSync, mkdirSync, readdirSync, readFileSync, renameSync, unlinkSync, writeFileSync, } from "node:fs";
|
|
5
|
-
import { dirname, join } from "node:path";
|
|
6
|
-
import { flattenTree, insertDoc, isDocId, moveDoc, removeDoc, renameDoc, } from "../core/content-metadata.js";
|
|
7
|
-
import { defaultFilePath, docIconFile, isDocumentFileName, parseFileLayout, } from "../core/files.js";
|
|
5
|
+
import { dirname, join, posix } from "node:path";
|
|
6
|
+
import { flattenTree, insertDoc, isDocId, moveDoc, removeDoc, renameDoc, subformatPageId, } from "../core/content-metadata.js";
|
|
7
|
+
import { defaultFilePath, docIconFile, fileDocumentId, isDocumentFileName, parseFileLayout, } from "../core/files.js";
|
|
8
8
|
import { parseDocLink } from "../core/routing.js";
|
|
9
9
|
import { collectDocLinks, compileSite } from "./compile.js";
|
|
10
10
|
import { figureName, figureUploadName } from "./figures.js";
|
|
11
|
-
import { projectFiles, rewriteFileLinks } from "./files.js";
|
|
11
|
+
import { filesSnapshot, projectFiles, rewriteFileLinks, updateFiles } from "./files.js";
|
|
12
12
|
import { translationFile, translationFiles, translationLanguages } from "./locales.js";
|
|
13
13
|
import { docFile, readManifest, writeManifest } from "./manifest.js";
|
|
14
14
|
import { assembleDoc } from "./serialize.js";
|
|
@@ -27,7 +27,10 @@ export const createDocOps = (root) => {
|
|
|
27
27
|
? { error: manifest.errors.join(" / "), status: 409 }
|
|
28
28
|
: manifest;
|
|
29
29
|
};
|
|
30
|
-
const existingDoc = (id) => typeof id === "string" &&
|
|
30
|
+
const existingDoc = (id) => typeof id === "string" &&
|
|
31
|
+
isDocId(id) &&
|
|
32
|
+
!flattenTree(readManifest(root).tree).some((node) => node.id === id && node.subformat) &&
|
|
33
|
+
existsSync(docPath(id))
|
|
31
34
|
? { id }
|
|
32
35
|
: { error: `doc "${String(id)}" not found`, status: 404 };
|
|
33
36
|
// Include extracted callout sources and unregistered Markdown files in reference checks.
|
|
@@ -56,11 +59,20 @@ export const createDocOps = (root) => {
|
|
|
56
59
|
if (isOpError(loaded)) {
|
|
57
60
|
return loaded;
|
|
58
61
|
}
|
|
62
|
+
if (loaded.format === "nested") {
|
|
63
|
+
const file = loaded.files?.defaultLayout !== false
|
|
64
|
+
? defaultFilePath(filename ?? `${id}.md`)
|
|
65
|
+
: `content/${filename ?? `${id}.md`}`;
|
|
66
|
+
id = fileDocumentId(file);
|
|
67
|
+
loaded.files ??= parseFileLayout({});
|
|
68
|
+
loaded.files.documents[id] = file;
|
|
69
|
+
}
|
|
59
70
|
const tree = insertDoc(loaded.tree, id, parent);
|
|
60
71
|
if (!tree) {
|
|
61
72
|
return { error: `duplicate id "${id}" or missing parent "${parent}"`, status: 409 };
|
|
62
73
|
}
|
|
63
|
-
if (
|
|
74
|
+
if (loaded.format !== "nested" &&
|
|
75
|
+
(filename !== undefined || loaded.files?.defaultLayout !== false)) {
|
|
64
76
|
loaded.files ??= parseFileLayout({});
|
|
65
77
|
loaded.files.documents[id] = loaded.files.defaultLayout
|
|
66
78
|
? defaultFilePath(filename ?? `${id}.md`)
|
|
@@ -92,6 +104,37 @@ export const createDocOps = (root) => {
|
|
|
92
104
|
id = `${stem}-${index}`;
|
|
93
105
|
return add(id, title, parent, name);
|
|
94
106
|
};
|
|
107
|
+
const addSubformat = (ext, title, parent) => {
|
|
108
|
+
const loaded = loadTree();
|
|
109
|
+
if (isOpError(loaded))
|
|
110
|
+
return loaded;
|
|
111
|
+
if (!loaded.subformats?.some((format) => format.ext === ext) || !title.trim())
|
|
112
|
+
return { error: "Choose an existing subformat and enter a title", status: 400 };
|
|
113
|
+
const id = subformatPageId(ext);
|
|
114
|
+
const tree = insertDoc(loaded.tree, id, parent, { subformat: ext, title: title.trim() });
|
|
115
|
+
if (!tree)
|
|
116
|
+
return { error: "Page already exists or parent is missing", status: 409 };
|
|
117
|
+
writeManifest(root, tree, loaded);
|
|
118
|
+
return { id };
|
|
119
|
+
};
|
|
120
|
+
const renameSubformat = (id, title) => {
|
|
121
|
+
const loaded = loadTree();
|
|
122
|
+
if (isOpError(loaded))
|
|
123
|
+
return loaded;
|
|
124
|
+
if (!title.trim())
|
|
125
|
+
return { error: "title is required", status: 400 };
|
|
126
|
+
const visit = (nodes) => nodes.some((node) => {
|
|
127
|
+
if (node.id === id && node.subformat) {
|
|
128
|
+
node.title = title.trim();
|
|
129
|
+
return true;
|
|
130
|
+
}
|
|
131
|
+
return visit(node.children);
|
|
132
|
+
});
|
|
133
|
+
if (!visit(loaded.tree))
|
|
134
|
+
return { error: "Subformat page not found", status: 404 };
|
|
135
|
+
writeManifest(root, loaded.tree, loaded);
|
|
136
|
+
return { id };
|
|
137
|
+
};
|
|
95
138
|
/**
|
|
96
139
|
* Reorders and reparents. Rewrites only dooc.yaml. Omitted index = after the last child
|
|
97
140
|
* of parent.
|
|
@@ -125,6 +168,37 @@ export const createDocOps = (root) => {
|
|
|
125
168
|
if (newId === "" || newId === oldId) {
|
|
126
169
|
return { id: oldId, updatedRefs: 0 };
|
|
127
170
|
}
|
|
171
|
+
const manifest = readManifest(root);
|
|
172
|
+
if (manifest.format === "nested") {
|
|
173
|
+
const name = newId.endsWith(".md") ? newId : `${newId}.md`;
|
|
174
|
+
if (!isDocumentFileName(name))
|
|
175
|
+
return { error: "Enter a Markdown file name", status: 400 };
|
|
176
|
+
try {
|
|
177
|
+
const file = docFile(oldId, manifest.files);
|
|
178
|
+
const next = posix.join(posix.dirname(file), name);
|
|
179
|
+
const moves = new Map([[file, next]]);
|
|
180
|
+
const updatedRefs = referenceFiles().filter((path) => {
|
|
181
|
+
const raw = readFileSync(textfilePath(root, path), "utf8");
|
|
182
|
+
return rewriteFileLinks(raw, moves) !== raw;
|
|
183
|
+
}).length;
|
|
184
|
+
updateFiles(root, {
|
|
185
|
+
action: "rename",
|
|
186
|
+
file,
|
|
187
|
+
name,
|
|
188
|
+
revision: filesSnapshot(root).revision,
|
|
189
|
+
});
|
|
190
|
+
return {
|
|
191
|
+
id: fileDocumentId(next),
|
|
192
|
+
updatedRefs,
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
catch (error) {
|
|
196
|
+
return {
|
|
197
|
+
error: error instanceof Error ? error.message : String(error),
|
|
198
|
+
status: 409,
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
}
|
|
128
202
|
if (!isDocId(newId)) {
|
|
129
203
|
return { error: "id must be a slug (lowercase alphanumerics, hyphens)", status: 400 };
|
|
130
204
|
}
|
|
@@ -204,6 +278,22 @@ export const createDocOps = (root) => {
|
|
|
204
278
|
* referencedBy. parent = the deleted doc's parent.
|
|
205
279
|
*/
|
|
206
280
|
const remove = (id, force = false) => {
|
|
281
|
+
const manifest = loadTree();
|
|
282
|
+
if (isOpError(manifest))
|
|
283
|
+
return manifest;
|
|
284
|
+
const page = flattenTree(manifest.tree).find((node) => node.id === id && node.subformat);
|
|
285
|
+
if (page) {
|
|
286
|
+
const tree = removeDoc(manifest.tree, id);
|
|
287
|
+
if (!tree)
|
|
288
|
+
return { error: "doc has children (move / delete them first)", status: 409 };
|
|
289
|
+
const removedIcon = iconPath(id);
|
|
290
|
+
if (manifest.files?.icons)
|
|
291
|
+
delete manifest.files.icons[id];
|
|
292
|
+
writeManifest(root, tree, manifest);
|
|
293
|
+
if (existsSync(removedIcon))
|
|
294
|
+
unlinkSync(removedIcon);
|
|
295
|
+
return { parent: page.parent, danglingRefs: 0 };
|
|
296
|
+
}
|
|
207
297
|
const target = existingDoc(id);
|
|
208
298
|
if (isOpError(target)) {
|
|
209
299
|
return target;
|
|
@@ -245,7 +335,6 @@ export const createDocOps = (root) => {
|
|
|
245
335
|
delete loaded.files.documents[id];
|
|
246
336
|
if (loaded.files.icons)
|
|
247
337
|
delete loaded.files.icons[id];
|
|
248
|
-
loaded.files.order = loaded.files.order.filter((file) => join(root, file) !== removedPath);
|
|
249
338
|
}
|
|
250
339
|
writeManifest(root, tree, loaded);
|
|
251
340
|
unlinkSync(removedPath);
|
|
@@ -277,7 +366,7 @@ export const createDocOps = (root) => {
|
|
|
277
366
|
const addFigure = (file, data) => {
|
|
278
367
|
const upload = figureUploadName(file);
|
|
279
368
|
if (!upload) {
|
|
280
|
-
return { error: "specify an
|
|
369
|
+
return { error: "specify an image / html / video / pdf / dxf file", status: 400 };
|
|
281
370
|
}
|
|
282
371
|
if (data.length === 0 ||
|
|
283
372
|
(upload.endsWith(".svg") && !data.toString("utf8").includes("<svg"))) {
|
|
@@ -352,6 +441,8 @@ export const createDocOps = (root) => {
|
|
|
352
441
|
figureFiles,
|
|
353
442
|
add,
|
|
354
443
|
addFile,
|
|
444
|
+
addSubformat,
|
|
445
|
+
renameSubformat,
|
|
355
446
|
move,
|
|
356
447
|
rename,
|
|
357
448
|
remove,
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { AnySchemaObject, ValidateFunction } from "ajv";
|
|
2
|
+
import { type SchemaContext } from "../core/schema-refs.js";
|
|
3
|
+
interface SchemaSource {
|
|
4
|
+
root: string;
|
|
5
|
+
file: string;
|
|
6
|
+
domains?: readonly string[];
|
|
7
|
+
}
|
|
8
|
+
export declare const compileSubformatSchema: (content: string, source?: SchemaSource) => {
|
|
9
|
+
schema: AnySchemaObject;
|
|
10
|
+
validate: ValidateFunction;
|
|
11
|
+
context: SchemaContext;
|
|
12
|
+
dependencies: Map<string, string>;
|
|
13
|
+
};
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { realpathSync } from "node:fs";
|
|
2
|
+
import { relative } from "node:path";
|
|
3
|
+
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
4
|
+
import { Ajv2020, MissingRefError } from "ajv/dist/2020.js";
|
|
5
|
+
import addFormats from "ajv-formats";
|
|
6
|
+
import { schemaObject } from "../core/schema-fields.js";
|
|
7
|
+
import { visitSchema } from "../core/schema-refs.js";
|
|
8
|
+
import { SUBFORMAT_SCHEMA_VERSION } from "../core/subformats.js";
|
|
9
|
+
import { readTextfile, textfilePath } from "./textfile.js";
|
|
10
|
+
const cache = new Map();
|
|
11
|
+
export const compileSubformatSchema = (content, source) => {
|
|
12
|
+
const uri = source
|
|
13
|
+
? pathToFileURL(textfilePath(source.root, source.file)).href
|
|
14
|
+
: "file:///schema.json";
|
|
15
|
+
const key = JSON.stringify([uri, source?.domains ?? [], content]);
|
|
16
|
+
const read = (uri) => {
|
|
17
|
+
if (!source)
|
|
18
|
+
throw new Error("A schema file path is required to resolve external references");
|
|
19
|
+
try {
|
|
20
|
+
const url = new URL(uri);
|
|
21
|
+
if (url.protocol === "file:") {
|
|
22
|
+
if (url.search)
|
|
23
|
+
throw new Error("Local schema references cannot contain a query");
|
|
24
|
+
return readTextfile(source.root, relative(realpathSync(source.root), fileURLToPath(url)).replaceAll("\\", "/"));
|
|
25
|
+
}
|
|
26
|
+
if (!/^https?:$/.test(url.protocol))
|
|
27
|
+
throw new Error("Schema references require a local file or HTTPS URL");
|
|
28
|
+
return readTextfile(source.root, url.href, false, source.domains);
|
|
29
|
+
}
|
|
30
|
+
catch (error) {
|
|
31
|
+
throw new Error(`Cannot load schema ${uri}: ${error instanceof Error ? error.message : String(error)}`);
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
const cached = cache.get(key);
|
|
35
|
+
if (cached && [...cached.dependencies].every(([uri, text]) => read(uri) === text))
|
|
36
|
+
return cached;
|
|
37
|
+
const schema = JSON.parse(content);
|
|
38
|
+
if (!schemaObject(schema) || schema.$async)
|
|
39
|
+
throw new Error("Use a synchronous JSON object schema");
|
|
40
|
+
const context = { uri, schemas: {} };
|
|
41
|
+
const dependencies = new Map();
|
|
42
|
+
const ajv = new Ajv2020({ allErrors: true, strict: true, ownProperties: true });
|
|
43
|
+
addFormats.default(ajv);
|
|
44
|
+
// Ajv resolves anchors but omits their annotation keyword from the 2020-12 vocabulary.
|
|
45
|
+
ajv.addKeyword({ keyword: "$anchor", schemaType: "string" });
|
|
46
|
+
const add = (schema, uri) => {
|
|
47
|
+
if (typeof schema !== "boolean" && !schemaObject(schema))
|
|
48
|
+
throw new Error("Expected a JSON schema object or boolean");
|
|
49
|
+
visitSchema(schema, uri, (node, base) => {
|
|
50
|
+
if (node.$async)
|
|
51
|
+
throw new Error("Use a synchronous JSON object schema");
|
|
52
|
+
if (node.$schema !== undefined && node.$schema !== SUBFORMAT_SCHEMA_VERSION)
|
|
53
|
+
throw new Error(`Use JSON Schema 2020-12: ${SUBFORMAT_SCHEMA_VERSION}`);
|
|
54
|
+
if (/^https?:/.test(uri) &&
|
|
55
|
+
(new URL(base).protocol === "file:" ||
|
|
56
|
+
(typeof node.$ref === "string" &&
|
|
57
|
+
new URL(node.$ref, base).protocol === "file:")))
|
|
58
|
+
throw new Error("Remote schemas cannot reference local files");
|
|
59
|
+
});
|
|
60
|
+
context.schemas[uri] = schema;
|
|
61
|
+
const compiled = schemaObject(schema) && typeof schema.$id === "string"
|
|
62
|
+
? { ...schema, $id: new URL(schema.$id, uri).href }
|
|
63
|
+
: schema;
|
|
64
|
+
ajv.addSchema(compiled, uri);
|
|
65
|
+
if (schemaObject(schema) && typeof schema.$anchor === "string")
|
|
66
|
+
ajv.addSchema(compiled, new URL(`#${schema.$anchor}`, schemaObject(compiled) && typeof compiled.$id === "string" ? compiled.$id : uri).href);
|
|
67
|
+
};
|
|
68
|
+
add(schema, uri);
|
|
69
|
+
let validate;
|
|
70
|
+
for (;;) {
|
|
71
|
+
try {
|
|
72
|
+
validate = ajv.getSchema(uri);
|
|
73
|
+
break;
|
|
74
|
+
}
|
|
75
|
+
catch (error) {
|
|
76
|
+
if (!(error instanceof MissingRefError) || ajv.refs[error.missingSchema])
|
|
77
|
+
throw error;
|
|
78
|
+
if (dependencies.size >= 64)
|
|
79
|
+
throw new Error("A schema may reference at most 64 external files");
|
|
80
|
+
const text = read(error.missingSchema);
|
|
81
|
+
dependencies.set(error.missingSchema, text);
|
|
82
|
+
add(JSON.parse(text), error.missingSchema);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
if (!validate)
|
|
86
|
+
throw new Error("Schema could not be compiled");
|
|
87
|
+
const result = { schema, validate, context, dependencies };
|
|
88
|
+
if (cache.size >= 32)
|
|
89
|
+
cache.clear();
|
|
90
|
+
cache.set(key, result);
|
|
91
|
+
return result;
|
|
92
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { ValidateFunction } from "ajv";
|
|
2
|
+
import { type Subformat, type SubformatCollection, type SubformatField } from "../core/subformats.js";
|
|
3
|
+
export { compileSubformatSchema } from "./subformat-schema.js";
|
|
4
|
+
export interface LoadedSubformat extends Subformat {
|
|
5
|
+
fields: SubformatField[];
|
|
6
|
+
template: string;
|
|
7
|
+
validate: ValidateFunction;
|
|
8
|
+
}
|
|
9
|
+
export declare const loadSubformat: (root: string, config: Subformat, domains?: readonly string[]) => LoadedSubformat;
|
|
10
|
+
export declare const validateSubformatRecord: (format: LoadedSubformat, data: Record<string, unknown>) => void;
|
|
11
|
+
export declare const isSubformatSchemaFile: (root: string, file: string, domains?: readonly string[]) => boolean;
|
|
12
|
+
export declare const validateSubformatFile: (root: string, file: string, content: string, domains?: readonly string[]) => void;
|
|
13
|
+
export declare const subformatResponse: (root: string, input: Record<string, unknown> | undefined, domains?: readonly string[]) => {
|
|
14
|
+
status: number;
|
|
15
|
+
body: {
|
|
16
|
+
content?: string;
|
|
17
|
+
data?: Record<string, unknown>;
|
|
18
|
+
collection?: SubformatCollection;
|
|
19
|
+
error?: string;
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
export { parseSubformatRecord } from "../core/subformat-record.js";
|