@dooc-dev/dooc 0.0.7 → 0.0.9

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.
Files changed (304) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +16 -18
  3. package/dist/client.global.js +1 -0
  4. package/dist/code-worker.global.js +11 -11
  5. package/dist/code.global.js +75 -75
  6. package/dist/edit.global.js +234 -231
  7. package/dist/{compiler → engine/compiler}/bundle-urls.js +1 -4
  8. package/dist/{compiler → engine/compiler}/check-prose.d.ts +1 -1
  9. package/dist/{compiler → engine/compiler}/check-prose.js +1 -1
  10. package/dist/{compiler → engine/compiler}/check.js +15 -27
  11. package/dist/{compiler → engine/compiler}/code-blocks.js +3 -1
  12. package/dist/{compiler → engine/compiler}/code-languages.js +1 -2
  13. package/dist/{compiler → engine/compiler}/compile.d.ts +5 -4
  14. package/dist/{compiler → engine/compiler}/compile.js +91 -32
  15. package/dist/{compiler → engine/compiler}/config.js +1 -3
  16. package/dist/{compiler → engine/compiler}/dialect.d.ts +1 -3
  17. package/dist/{compiler → engine/compiler}/dialect.js +8 -52
  18. package/dist/{compiler → engine/compiler}/dxf.js +1 -1
  19. package/dist/{compiler → engine/compiler}/export.js +15 -8
  20. package/dist/{compiler → engine/compiler}/figures.js +26 -22
  21. package/dist/{compiler → engine/compiler}/file-cache.d.ts +1 -2
  22. package/dist/{compiler → engine/compiler}/file-cache.js +8 -15
  23. package/dist/{compiler → engine/compiler}/files.js +49 -38
  24. package/dist/{compiler → engine/compiler}/fonts.js +1 -3
  25. package/dist/{compiler → engine/compiler}/from-mdast.js +1 -1
  26. package/dist/engine/compiler/host.d.ts +10 -0
  27. package/dist/engine/compiler/host.js +16 -0
  28. package/dist/{compiler → engine/compiler}/icons.d.ts +3 -0
  29. package/dist/{compiler → engine/compiler}/icons.js +28 -10
  30. package/dist/{compiler → engine/compiler}/ignored-files.d.ts +2 -0
  31. package/dist/{compiler → engine/compiler}/ignored-files.js +12 -3
  32. package/dist/{compiler → engine/compiler}/locales.js +2 -8
  33. package/dist/{compiler → engine/compiler}/manifest.d.ts +3 -2
  34. package/dist/engine/compiler/manifest.js +46 -0
  35. package/dist/{compiler → engine/compiler}/ops.d.ts +4 -1
  36. package/dist/{compiler → engine/compiler}/ops.js +36 -21
  37. package/dist/engine/compiler/schema-file-references.d.ts +2 -0
  38. package/dist/engine/compiler/schema-file-references.js +82 -0
  39. package/dist/engine/compiler/serialize.d.ts +2 -0
  40. package/dist/engine/compiler/serialize.js +5 -0
  41. package/dist/{compiler → engine/compiler}/subformat-schema.js +1 -3
  42. package/dist/{compiler → engine/compiler}/subformats.d.ts +10 -0
  43. package/dist/{compiler → engine/compiler}/subformats.js +122 -18
  44. package/dist/{compiler → engine/compiler}/textfile-remote.js +1 -2
  45. package/dist/{compiler → engine/compiler}/textfile.js +4 -6
  46. package/dist/{compiler → engine/compiler}/theme-variants.js +1 -1
  47. package/dist/{compiler → engine/compiler}/zip.js +1 -1
  48. package/dist/{core → engine/core}/blocks.d.ts +6 -4
  49. package/dist/{core → engine/core}/content-metadata.d.ts +6 -1
  50. package/dist/{core → engine/core}/content-metadata.js +84 -18
  51. package/dist/{core → engine/core}/content-types.d.ts +4 -2
  52. package/dist/{core → engine/core}/html.d.ts +7 -0
  53. package/dist/{core → engine/core}/html.js +44 -3
  54. package/dist/{core → engine/core}/icons.d.ts +3 -0
  55. package/dist/engine/core/icons.js +20 -0
  56. package/dist/{core → engine/core}/routing.d.ts +2 -0
  57. package/dist/{core → engine/core}/routing.js +9 -0
  58. package/dist/{core → engine/core}/schema-refs.d.ts +1 -1
  59. package/dist/{core → engine/core}/schema-refs.js +3 -1
  60. package/dist/engine/core/subformat-references.d.ts +5 -0
  61. package/dist/engine/core/subformat-references.js +33 -0
  62. package/dist/{core → engine/core}/subformats.d.ts +7 -0
  63. package/dist/{core → engine/core}/subformats.js +5 -1
  64. package/dist/{core → engine/core}/taxonomy.d.ts +2 -3
  65. package/dist/{core → engine/core}/taxonomy.js +1 -5
  66. package/dist/flow.global.js +306 -306
  67. package/dist/frontend/application-request.d.ts +14 -0
  68. package/dist/frontend/application-request.js +36 -0
  69. package/dist/frontend/document-application.d.ts +200 -0
  70. package/dist/{viewer/serve.js → frontend/document-application.js} +1611 -1670
  71. package/dist/frontend/figure-preview.d.ts +4 -0
  72. package/dist/{viewer → frontend}/figure-preview.js +4 -4
  73. package/dist/{viewer → frontend}/file-references.d.ts +1 -1
  74. package/dist/{viewer → frontend}/file-references.js +3 -3
  75. package/dist/{viewer → frontend}/font-picker.d.ts +1 -1
  76. package/dist/{viewer → frontend}/font-settings.d.ts +1 -1
  77. package/dist/{viewer → frontend}/language-picker.js +112 -18
  78. package/dist/{viewer → frontend}/locales/eng.json +16 -2
  79. package/dist/{viewer → frontend}/locales/jpn.json +16 -2
  80. package/dist/{viewer → frontend}/locales/zho.json +16 -2
  81. package/dist/{viewer → frontend}/nav-focus.js +2 -0
  82. package/dist/{viewer → frontend}/plugin-blocks.js +2 -2
  83. package/dist/{viewer → frontend}/resize.js +14 -2
  84. package/dist/frontend/resource-download.d.ts +2 -0
  85. package/dist/frontend/resource-download.js +43 -0
  86. package/dist/{viewer → frontend}/resource-library.d.ts +9 -2
  87. package/dist/{viewer → frontend}/resource-library.js +133 -37
  88. package/dist/{core → frontend}/schema-graph-flow.d.ts +1 -1
  89. package/dist/{core → frontend}/schema-graph-flow.js +1 -1
  90. package/dist/{viewer → frontend}/search.d.ts +2 -2
  91. package/dist/{viewer → frontend}/search.js +26 -8
  92. package/dist/graph/schema-graph-global.js +17 -17
  93. package/dist/install.sh +68 -0
  94. package/dist/plugins.global.js +62 -62
  95. package/dist/{viewer → server}/assets.d.ts +2 -0
  96. package/dist/server/assets.js +7 -0
  97. package/dist/{viewer → server}/build-plugins.js +4 -4
  98. package/dist/{viewer → server}/build.d.ts +2 -1
  99. package/dist/{viewer → server}/build.js +31 -15
  100. package/dist/{cli.js → server/cli.js} +199 -66
  101. package/dist/server/editor-tools.d.ts +1 -0
  102. package/dist/server/editor-tools.js +1 -0
  103. package/dist/{viewer → server}/extension-pack.js +2 -2
  104. package/dist/{viewer → server}/extensions.d.ts +1 -1
  105. package/dist/{viewer → server}/extensions.js +3 -3
  106. package/dist/server/git-diff.d.ts +10 -0
  107. package/dist/{viewer → server}/git-diff.js +45 -10
  108. package/dist/server/git-origin.d.ts +4 -0
  109. package/dist/server/git-origin.js +103 -0
  110. package/dist/server/git.d.ts +9 -0
  111. package/dist/{viewer → server}/git.js +50 -6
  112. package/dist/server/history.d.ts +14 -0
  113. package/dist/server/history.js +205 -0
  114. package/dist/{viewer → server}/hmr.d.ts +0 -22
  115. package/dist/server/hmr.js +168 -0
  116. package/dist/server/index.d.ts +17 -0
  117. package/dist/{index.js → server/index.js} +16 -16
  118. package/dist/{viewer → server}/ja-lint.d.ts +1 -1
  119. package/dist/{viewer → server}/languages.d.ts +1 -1
  120. package/dist/{viewer → server}/languages.js +3 -3
  121. package/dist/{mcp.d.ts → server/mcp.d.ts} +2 -2
  122. package/dist/{mcp.js → server/mcp.js} +60 -21
  123. package/dist/{viewer → server}/plugin-config.d.ts +2 -2
  124. package/dist/{viewer → server}/plugin-config.js +2 -2
  125. package/dist/{plugins → server/plugins}/local-storage.d.ts +1 -1
  126. package/dist/{plugins → server/plugins}/local-storage.js +1 -1
  127. package/dist/{plugins → server/plugins}/runtime.d.ts +4 -4
  128. package/dist/{plugins → server/plugins}/runtime.js +4 -4
  129. package/dist/{viewer → server}/plugins.d.ts +3 -3
  130. package/dist/{viewer → server}/plugins.js +14 -13
  131. package/dist/server/resource-library.d.ts +1 -0
  132. package/dist/server/resource-library.js +1 -0
  133. package/dist/server/self.d.ts +5 -0
  134. package/dist/server/self.js +98 -0
  135. package/dist/server/serve.d.ts +61 -0
  136. package/dist/server/serve.js +503 -0
  137. package/dist/server/static-client.d.ts +4 -0
  138. package/dist/server/static-client.js +117 -0
  139. package/dist/server/workspace-server.d.ts +16 -0
  140. package/dist/server/workspace-server.js +266 -0
  141. package/dist/{viewer → server}/workspace.d.ts +6 -1
  142. package/dist/{viewer → server}/workspace.js +46 -0
  143. package/dist/subformats.global.js +92 -6
  144. package/dist/ui.global.js +85 -72
  145. package/dist/workspace/client.d.ts +13 -0
  146. package/dist/workspace/client.js +114 -0
  147. package/dist/{viewer → workspace}/code-file.d.ts +1 -1
  148. package/dist/{viewer → workspace}/code-file.js +7 -7
  149. package/dist/workspace/connection.d.ts +27 -0
  150. package/dist/workspace/connection.js +38 -0
  151. package/dist/{viewer → workspace}/editor-tools.d.ts +7 -1
  152. package/dist/{viewer → workspace}/editor-tools.js +12 -9
  153. package/dist/{viewer → workspace}/git-types.d.ts +7 -0
  154. package/dist/workspace/github.d.ts +4 -0
  155. package/dist/workspace/github.js +99 -0
  156. package/dist/workspace/history.d.ts +46 -0
  157. package/dist/workspace/history.js +86 -0
  158. package/dist/workspace/protocol.d.ts +38 -0
  159. package/dist/workspace/protocol.js +20 -0
  160. package/dist/workspace/resource-download.d.ts +1 -0
  161. package/dist/workspace/resource-download.js +8 -0
  162. package/dist/workspace/server.d.ts +9 -0
  163. package/dist/workspace/server.js +48 -0
  164. package/dist/{viewer → workspace}/site-icon.js +9 -10
  165. package/dist/{viewer → workspace}/site-title.js +6 -7
  166. package/dist/{viewer → workspace}/textfile.d.ts +1 -1
  167. package/dist/{viewer → workspace}/textfile.js +5 -5
  168. package/dist/workspace-worker.global.js +2859 -0
  169. package/package.json +35 -20
  170. package/dist/compiler/manifest.js +0 -37
  171. package/dist/compiler/serialize.d.ts +0 -3
  172. package/dist/compiler/serialize.js +0 -16
  173. package/dist/core/icons.js +0 -5
  174. package/dist/index.d.ts +0 -17
  175. package/dist/viewer/assets.js +0 -3
  176. package/dist/viewer/figure-preview.d.ts +0 -4
  177. package/dist/viewer/git-diff.d.ts +0 -6
  178. package/dist/viewer/git.d.ts +0 -5
  179. package/dist/viewer/hmr.js +0 -341
  180. package/dist/viewer/serve.d.ts +0 -216
  181. /package/dist/{compiler → engine/compiler}/asset-references.d.ts +0 -0
  182. /package/dist/{compiler → engine/compiler}/asset-references.js +0 -0
  183. /package/dist/{compiler → engine/compiler}/bundle-urls.d.ts +0 -0
  184. /package/dist/{compiler → engine/compiler}/check-types.d.ts +0 -0
  185. /package/dist/{compiler → engine/compiler}/check-types.js +0 -0
  186. /package/dist/{compiler → engine/compiler}/check.d.ts +0 -0
  187. /package/dist/{compiler → engine/compiler}/code-blocks.d.ts +0 -0
  188. /package/dist/{compiler → engine/compiler}/code-languages.d.ts +0 -0
  189. /package/dist/{compiler → engine/compiler}/config.d.ts +0 -0
  190. /package/dist/{compiler → engine/compiler}/drawio.d.ts +0 -0
  191. /package/dist/{compiler → engine/compiler}/drawio.js +0 -0
  192. /package/dist/{compiler → engine/compiler}/dxf.d.ts +0 -0
  193. /package/dist/{compiler → engine/compiler}/export.d.ts +0 -0
  194. /package/dist/{compiler → engine/compiler}/figures.d.ts +0 -0
  195. /package/dist/{compiler → engine/compiler}/files.d.ts +0 -0
  196. /package/dist/{compiler → engine/compiler}/fonts.d.ts +0 -0
  197. /package/dist/{compiler → engine/compiler}/format.d.ts +0 -0
  198. /package/dist/{compiler → engine/compiler}/format.js +0 -0
  199. /package/dist/{compiler → engine/compiler}/from-mdast.d.ts +0 -0
  200. /package/dist/{compiler → engine/compiler}/language-codes.d.ts +0 -0
  201. /package/dist/{compiler → engine/compiler}/language-codes.js +0 -0
  202. /package/dist/{compiler → engine/compiler}/locales.d.ts +0 -0
  203. /package/dist/{compiler → engine/compiler}/public-file.d.ts +0 -0
  204. /package/dist/{compiler → engine/compiler}/public-file.js +0 -0
  205. /package/dist/{compiler → engine/compiler}/subformat-schema.d.ts +0 -0
  206. /package/dist/{compiler → engine/compiler}/terms.d.ts +0 -0
  207. /package/dist/{compiler → engine/compiler}/terms.js +0 -0
  208. /package/dist/{compiler → engine/compiler}/textfile-remote.d.ts +0 -0
  209. /package/dist/{compiler → engine/compiler}/textfile.d.ts +0 -0
  210. /package/dist/{compiler → engine/compiler}/theme-variants.d.ts +0 -0
  211. /package/dist/{compiler → engine/compiler}/zip.d.ts +0 -0
  212. /package/dist/{core → engine/core}/blocks.js +0 -0
  213. /package/dist/{core → engine/core}/code-file.d.ts +0 -0
  214. /package/dist/{core → engine/core}/code-file.js +0 -0
  215. /package/dist/{core → engine/core}/code-grammars.d.ts +0 -0
  216. /package/dist/{core → engine/core}/code-grammars.js +0 -0
  217. /package/dist/{core → engine/core}/content-types.js +0 -0
  218. /package/dist/{core → engine/core}/escape-html.d.ts +0 -0
  219. /package/dist/{core → engine/core}/escape-html.js +0 -0
  220. /package/dist/{core → engine/core}/extension-package.d.ts +0 -0
  221. /package/dist/{core → engine/core}/extension-package.js +0 -0
  222. /package/dist/{core → engine/core}/figure-frame.d.ts +0 -0
  223. /package/dist/{core → engine/core}/figure-frame.js +0 -0
  224. /package/dist/{core → engine/core}/file-embed.d.ts +0 -0
  225. /package/dist/{core → engine/core}/file-embed.js +0 -0
  226. /package/dist/{core → engine/core}/files.d.ts +0 -0
  227. /package/dist/{core → engine/core}/files.js +0 -0
  228. /package/dist/{core → engine/core}/graph-common.d.ts +0 -0
  229. /package/dist/{core → engine/core}/graph-common.js +0 -0
  230. /package/dist/{core → engine/core}/graph.d.ts +0 -0
  231. /package/dist/{core → engine/core}/graph.js +0 -0
  232. /package/dist/{core → engine/core}/inline.d.ts +0 -0
  233. /package/dist/{core → engine/core}/inline.js +0 -0
  234. /package/dist/{core → engine/core}/json-tools.d.ts +0 -0
  235. /package/dist/{core → engine/core}/json-tools.js +0 -0
  236. /package/dist/{core → engine/core}/language.d.ts +0 -0
  237. /package/dist/{core → engine/core}/language.js +0 -0
  238. /package/dist/{core → engine/core}/languages/ja.d.ts +0 -0
  239. /package/dist/{core → engine/core}/languages/ja.js +0 -0
  240. /package/dist/{core → engine/core}/markdown.d.ts +0 -0
  241. /package/dist/{core → engine/core}/markdown.js +0 -0
  242. /package/dist/{core → engine/core}/previewers.d.ts +0 -0
  243. /package/dist/{core → engine/core}/previewers.js +0 -0
  244. /package/dist/{core → engine/core}/schema-comments.d.ts +0 -0
  245. /package/dist/{core → engine/core}/schema-comments.js +0 -0
  246. /package/dist/{core → engine/core}/schema-fields.d.ts +0 -0
  247. /package/dist/{core → engine/core}/schema-fields.js +0 -0
  248. /package/dist/{core → engine/core}/schema-graph.d.ts +0 -0
  249. /package/dist/{core → engine/core}/schema-graph.js +0 -0
  250. /package/dist/{core → engine/core}/subformat-record.d.ts +0 -0
  251. /package/dist/{core → engine/core}/subformat-record.js +0 -0
  252. /package/dist/{core → engine/core}/term-reference.d.ts +0 -0
  253. /package/dist/{core → engine/core}/term-reference.js +0 -0
  254. /package/dist/{core → engine/core}/textfile.d.ts +0 -0
  255. /package/dist/{core → engine/core}/textfile.js +0 -0
  256. /package/dist/{core → engine/core}/theme-variants.d.ts +0 -0
  257. /package/dist/{core → engine/core}/theme-variants.js +0 -0
  258. /package/dist/{core → engine/core}/workspace.d.ts +0 -0
  259. /package/dist/{core → engine/core}/workspace.js +0 -0
  260. /package/dist/{viewer → frontend}/bundle-network.d.ts +0 -0
  261. /package/dist/{viewer → frontend}/bundle-network.js +0 -0
  262. /package/dist/{core → frontend}/flow-base-css.generated.d.ts +0 -0
  263. /package/dist/{core → frontend}/flow-base-css.generated.js +0 -0
  264. /package/dist/{core → frontend}/flow-css.d.ts +0 -0
  265. /package/dist/{core → frontend}/flow-css.js +0 -0
  266. /package/dist/{viewer → frontend}/font-picker.js +0 -0
  267. /package/dist/{viewer → frontend}/font-settings.js +0 -0
  268. /package/dist/{viewer → frontend}/i18n.d.ts +0 -0
  269. /package/dist/{viewer → frontend}/i18n.js +0 -0
  270. /package/dist/{viewer → frontend}/language-picker.d.ts +0 -0
  271. /package/dist/{viewer → frontend}/lazy-preview.d.ts +0 -0
  272. /package/dist/{viewer → frontend}/lazy-preview.js +0 -0
  273. /package/dist/{viewer → frontend}/nav-focus.d.ts +0 -0
  274. /package/dist/{viewer → frontend}/nav-update.d.ts +0 -0
  275. /package/dist/{viewer → frontend}/nav-update.js +0 -0
  276. /package/dist/{viewer → frontend}/plugin-blocks.d.ts +0 -0
  277. /package/dist/{viewer → frontend}/plugin-style.d.ts +0 -0
  278. /package/dist/{viewer → frontend}/plugin-style.js +0 -0
  279. /package/dist/{viewer → frontend}/plugin-view.d.ts +0 -0
  280. /package/dist/{viewer → frontend}/plugin-view.js +0 -0
  281. /package/dist/{viewer → frontend}/resize.d.ts +0 -0
  282. /package/dist/{core → frontend}/schema-graph-mount.d.ts +0 -0
  283. /package/dist/{core → frontend}/schema-graph-mount.js +0 -0
  284. /package/dist/{core → frontend}/table-ui.d.ts +0 -0
  285. /package/dist/{core → frontend}/table-ui.js +0 -0
  286. /package/dist/{core → frontend}/terms-ui.d.ts +0 -0
  287. /package/dist/{core → frontend}/terms-ui.js +0 -0
  288. /package/dist/{viewer → frontend}/theme-picker.d.ts +0 -0
  289. /package/dist/{viewer → frontend}/theme-picker.js +0 -0
  290. /package/dist/{core → frontend}/toc-ui.d.ts +0 -0
  291. /package/dist/{core → frontend}/toc-ui.js +0 -0
  292. /package/dist/{core → frontend}/video-ui.d.ts +0 -0
  293. /package/dist/{core → frontend}/video-ui.js +0 -0
  294. /package/dist/{viewer → server}/build-plugins.d.ts +0 -0
  295. /package/dist/{cli.d.ts → server/cli.d.ts} +0 -0
  296. /package/dist/{viewer → server}/extension-pack.d.ts +0 -0
  297. /package/dist/{viewer → server}/fonts/LICENSE.txt +0 -0
  298. /package/dist/{viewer → server}/fonts/udev-gothic-regular.woff2 +0 -0
  299. /package/dist/{viewer → server}/fonts.d.ts +0 -0
  300. /package/dist/{viewer → server}/fonts.js +0 -0
  301. /package/dist/{viewer → server}/ja-lint.js +0 -0
  302. /package/dist/{viewer → workspace}/git-types.js +0 -0
  303. /package/dist/{viewer → workspace}/site-icon.d.ts +0 -0
  304. /package/dist/{viewer → workspace}/site-title.d.ts +0 -0
@@ -22,7 +22,10 @@ export declare const createDocOps: (root: string) => {
22
22
  addSubformat: (ext: string, title: string, parent?: string) => OpResult<{
23
23
  id: string;
24
24
  }>;
25
- renameSubformat: (id: string, title: string) => OpResult<{
25
+ addLibrary: (view: string, title: string, parent?: string) => OpResult<{
26
+ id: string;
27
+ }>;
28
+ setTitle: (id: string, title: string) => OpResult<{
26
29
  id: string;
27
30
  }>;
28
31
  move: (id: string, parent?: string, index?: number) => OpResult<{
@@ -1,17 +1,16 @@
1
1
  // Write operations on the docs root (create / move / rename / delete docs and save body text;
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
- import { existsSync, mkdirSync, readdirSync, readFileSync, renameSync, unlinkSync, writeFileSync, } from "node:fs";
5
- import { dirname, join, posix } from "node:path";
6
- import { flattenTree, insertDoc, isDocId, moveDoc, removeDoc, renameDoc, subformatPageId, } from "../core/content-metadata.js";
4
+ import { flattenTree, insertDoc, isDocId, isLibraryView, libraryPageId, moveDoc, removeDoc, renameDoc, subformatPageId, } from "../core/content-metadata.js";
7
5
  import { defaultFilePath, docIconFile, fileDocumentId, isDocumentFileName, parseFileLayout, } from "../core/files.js";
8
6
  import { parseDocLink } from "../core/routing.js";
9
7
  import { collectDocLinks, compileSite } from "./compile.js";
10
8
  import { figureName, figureUploadName } from "./figures.js";
11
9
  import { filesSnapshot, projectFiles, rewriteFileLinks, updateFiles } from "./files.js";
10
+ import { dirname, existsSync, join, mkdirSync, posix, readdirSync, readFileSync, renameSync, unlinkSync, writeFileSync, } from "./host.js";
11
+ import { ownsDocIcon } from "./icons.js";
12
12
  import { translationFile, translationFiles, translationLanguages } from "./locales.js";
13
13
  import { docFile, readManifest, writeManifest } from "./manifest.js";
14
- import { assembleDoc } from "./serialize.js";
15
14
  import { textfilePath } from "./textfile.js";
16
15
  export const isOpError = (r) => typeof r === "object" && r != null && "error" in r;
17
16
  export { assembleDoc } from "./serialize.js";
@@ -29,7 +28,7 @@ export const createDocOps = (root) => {
29
28
  };
30
29
  const existingDoc = (id) => typeof id === "string" &&
31
30
  isDocId(id) &&
32
- !flattenTree(readManifest(root).tree).some((node) => node.id === id && node.subformat) &&
31
+ !flattenTree(readManifest(root).tree).some((node) => node.id === id && (node.subformat || node.library)) &&
33
32
  existsSync(docPath(id))
34
33
  ? { id }
35
34
  : { error: `doc "${String(id)}" not found`, status: 404 };
@@ -67,7 +66,8 @@ export const createDocOps = (root) => {
67
66
  loaded.files ??= parseFileLayout({});
68
67
  loaded.files.documents[id] = file;
69
68
  }
70
- const tree = insertDoc(loaded.tree, id, parent);
69
+ // Only the nested manifest stores document titles.
70
+ const tree = insertDoc(loaded.tree, id, parent, { title });
71
71
  if (!tree) {
72
72
  return { error: `duplicate id "${id}" or missing parent "${parent}"`, status: 409 };
73
73
  }
@@ -82,7 +82,7 @@ export const createDocOps = (root) => {
82
82
  if (existsSync(file))
83
83
  return { error: "File already exists", status: 409 };
84
84
  mkdirSync(dirname(file), { recursive: true });
85
- writeFileSync(file, assembleDoc({ title }, ""), { flag: "wx" });
85
+ writeFileSync(file, "", { flag: "wx" });
86
86
  writeManifest(root, tree, loaded);
87
87
  return { id };
88
88
  };
@@ -117,21 +117,34 @@ export const createDocOps = (root) => {
117
117
  writeManifest(root, tree, loaded);
118
118
  return { id };
119
119
  };
120
- const renameSubformat = (id, title) => {
120
+ const addLibrary = (view, title, parent) => {
121
+ const loaded = loadTree();
122
+ if (isOpError(loaded))
123
+ return loaded;
124
+ if (!isLibraryView(view) || !title.trim())
125
+ return { error: "Choose a library view and enter a title", status: 400 };
126
+ const id = libraryPageId(view);
127
+ const tree = insertDoc(loaded.tree, id, parent, { library: view, title: title.trim() });
128
+ if (!tree)
129
+ return { error: "Page already exists or parent is missing", status: 409 };
130
+ writeManifest(root, tree, loaded);
131
+ return { id };
132
+ };
133
+ const setTitle = (id, title) => {
121
134
  const loaded = loadTree();
122
135
  if (isOpError(loaded))
123
136
  return loaded;
124
137
  if (!title.trim())
125
138
  return { error: "title is required", status: 400 };
126
139
  const visit = (nodes) => nodes.some((node) => {
127
- if (node.id === id && node.subformat) {
140
+ if (node.id === id) {
128
141
  node.title = title.trim();
129
142
  return true;
130
143
  }
131
144
  return visit(node.children);
132
145
  });
133
146
  if (!visit(loaded.tree))
134
- return { error: "Subformat page not found", status: 404 };
147
+ return { error: "Page not found", status: 404 };
135
148
  writeManifest(root, loaded.tree, loaded);
136
149
  return { id };
137
150
  };
@@ -281,16 +294,16 @@ export const createDocOps = (root) => {
281
294
  const manifest = loadTree();
282
295
  if (isOpError(manifest))
283
296
  return manifest;
284
- const page = flattenTree(manifest.tree).find((node) => node.id === id && node.subformat);
297
+ const page = flattenTree(manifest.tree).find((node) => node.id === id && (node.subformat || node.library));
285
298
  if (page) {
286
299
  const tree = removeDoc(manifest.tree, id);
287
300
  if (!tree)
288
301
  return { error: "doc has children (move / delete them first)", status: 409 };
289
- const removedIcon = iconPath(id);
302
+ const removedIcon = ownsDocIcon(id, manifest) ? iconPath(id) : undefined;
290
303
  if (manifest.files?.icons)
291
304
  delete manifest.files.icons[id];
292
305
  writeManifest(root, tree, manifest);
293
- if (existsSync(removedIcon))
306
+ if (removedIcon && existsSync(removedIcon))
294
307
  unlinkSync(removedIcon);
295
308
  return { parent: page.parent, danglingRefs: 0 };
296
309
  }
@@ -330,7 +343,7 @@ export const createDocOps = (root) => {
330
343
  }
331
344
  const parent = flattenTree(loaded.tree).find((n) => n.id === id)?.parent;
332
345
  const removedPath = docPath(id);
333
- const removedIcon = iconPath(id);
346
+ const removedIcon = ownsDocIcon(id, loaded) ? iconPath(id) : undefined;
334
347
  if (loaded.files) {
335
348
  delete loaded.files.documents[id];
336
349
  if (loaded.files.icons)
@@ -338,7 +351,7 @@ export const createDocOps = (root) => {
338
351
  }
339
352
  writeManifest(root, tree, loaded);
340
353
  unlinkSync(removedPath);
341
- if (existsSync(removedIcon)) {
354
+ if (removedIcon && existsSync(removedIcon)) {
342
355
  unlinkSync(removedIcon);
343
356
  }
344
357
  for (const file of removed.slice(1)) {
@@ -348,7 +361,7 @@ export const createDocOps = (root) => {
348
361
  }
349
362
  return { parent, danglingRefs: referencedBy.length };
350
363
  };
351
- /** Overwrites an existing doc's full raw text (including front-matter). */
364
+ /** Overwrites an existing doc's full raw text. */
352
365
  const write = (id, raw) => {
353
366
  const target = existingDoc(id);
354
367
  if (isOpError(target)) {
@@ -389,19 +402,20 @@ export const createDocOps = (root) => {
389
402
  writeFileSync(target, data, { flag: "wx" });
390
403
  return { file: path.split("/").pop(), path };
391
404
  }
392
- mkdirSync(figuresDir, { recursive: true });
393
- const taken = new Map(readdirSync(figuresDir).map((f) => [figureName(f), f]));
405
+ const directory = textfilePath(root, "figures");
406
+ mkdirSync(directory, { recursive: true });
407
+ const taken = new Map(readdirSync(directory).map((f) => [figureName(f), f]));
394
408
  const ext = upload.slice(figureName(upload).length);
395
409
  let name = figureName(upload);
396
410
  for (let i = 2; taken.has(name); i += 1) {
397
411
  const existing = taken.get(name);
398
412
  if (existing === `${name}${ext}` &&
399
- readFileSync(join(figuresDir, existing)).equals(data)) {
413
+ readFileSync(textfilePath(root, `figures/${existing}`)).equals(data)) {
400
414
  return { file: existing };
401
415
  }
402
416
  name = `${figureName(upload)}-${i}`;
403
417
  }
404
- writeFileSync(join(figuresDir, `${name}${ext}`), data);
418
+ writeFileSync(textfilePath(root, `figures/${name}${ext}`), data, { flag: "wx" });
405
419
  return { file: `${name}${ext}` };
406
420
  };
407
421
  /** Files in figures/ (figure name → file). */
@@ -442,7 +456,8 @@ export const createDocOps = (root) => {
442
456
  add,
443
457
  addFile,
444
458
  addSubformat,
445
- renameSubformat,
459
+ addLibrary,
460
+ setTitle,
446
461
  move,
447
462
  rename,
448
463
  remove,
@@ -0,0 +1,2 @@
1
+ /** Rewrite only schema positions in registered local schemas and their local dependencies. */
2
+ export declare const rewriteSchemaFiles: (root: string, registered: readonly string[], files: readonly string[], moves: ReadonlyMap<string, string>) => Map<string, string>;
@@ -0,0 +1,82 @@
1
+ import { schemaObject } from "../core/schema-fields.js";
2
+ import { visitSchema } from "../core/schema-refs.js";
3
+ import { posix, readFileSync } from "./host.js";
4
+ import { textfilePath } from "./textfile.js";
5
+ /** Rewrite only schema positions in registered local schemas and their local dependencies. */
6
+ export const rewriteSchemaFiles = (root, registered, files, moves) => {
7
+ const writes = new Map();
8
+ if (!moves.size)
9
+ return writes;
10
+ const uri = (file) => `file:///${file.split("/").map(encodeURIComponent).join("/")}`;
11
+ const local = (url) => url.protocol === "file:" && !url.host && !url.search
12
+ ? decodeURIComponent(url.pathname.slice(1))
13
+ : undefined;
14
+ const available = new Set(files);
15
+ const pending = new Set(registered.filter((file) => available.has(file)));
16
+ const sources = new Map();
17
+ for (const file of pending) {
18
+ const raw = readFileSync(textfilePath(root, file), "utf8");
19
+ let schema;
20
+ try {
21
+ schema = JSON.parse(raw);
22
+ }
23
+ catch {
24
+ // Malformed schemas have no safely editable references; keep their bytes intact.
25
+ continue;
26
+ }
27
+ if (!schemaObject(schema))
28
+ continue;
29
+ sources.set(file, { raw, schema });
30
+ visitSchema(schema, uri(file), (node, base) => {
31
+ for (const key of ["$ref", "$dynamicRef"]) {
32
+ if (typeof node[key] !== "string")
33
+ continue;
34
+ const target = local(new URL(node[key], base));
35
+ if (target && available.has(target))
36
+ pending.add(target);
37
+ }
38
+ });
39
+ }
40
+ const bases = new WeakMap();
41
+ const resources = new Map();
42
+ for (const [file, { schema }] of sources) {
43
+ visitSchema(schema, uri(moves.get(file) ?? file), (node, base) => bases.set(node, base));
44
+ visitSchema(schema, uri(file), (node, base) => {
45
+ if (node === schema || typeof node.$id === "string")
46
+ resources.set(base, bases.get(node));
47
+ });
48
+ }
49
+ for (const [file, { raw, schema }] of sources) {
50
+ let changed = false;
51
+ visitSchema(schema, uri(file), (node, base) => {
52
+ const nextBase = bases.get(node);
53
+ for (const key of ["$ref", "$dynamicRef"]) {
54
+ const ref = node[key];
55
+ if (typeof ref !== "string")
56
+ continue;
57
+ const target = new URL(ref, base);
58
+ const path = local(target);
59
+ if (path === undefined)
60
+ continue;
61
+ const fragment = target.hash;
62
+ target.hash = "";
63
+ const destination = new URL(resources.get(target.href) ?? uri(moves.get(path) ?? path));
64
+ destination.hash = fragment;
65
+ if (new URL(ref, nextBase).href === destination.href)
66
+ continue;
67
+ const owner = new URL(nextBase);
68
+ node[key] = ref.startsWith("file:")
69
+ ? destination.href
70
+ : (owner.pathname === destination.pathname
71
+ ? ""
72
+ : posix.relative(posix.dirname(owner.pathname), destination.pathname)) +
73
+ destination.hash;
74
+ changed = true;
75
+ }
76
+ });
77
+ if (changed)
78
+ writes.set(file, JSON.stringify(schema, null, raw.match(/\n([\t ]+)"/)?.[1] ?? 2) +
79
+ (raw.endsWith("\n") ? "\n" : ""));
80
+ }
81
+ return writes;
82
+ };
@@ -0,0 +1,2 @@
1
+ /** Body md → full file text (normalized to one trailing newline). */
2
+ export declare const assembleDoc: (body: string) => string;
@@ -0,0 +1,5 @@
1
+ /** Body md → full file text (normalized to one trailing newline). */
2
+ export const assembleDoc = (body) => {
3
+ const b = body.replace(/\n+$/, "");
4
+ return b === "" ? "" : `${b}\n`;
5
+ };
@@ -1,11 +1,9 @@
1
- import { realpathSync } from "node:fs";
2
- import { relative } from "node:path";
3
- import { fileURLToPath, pathToFileURL } from "node:url";
4
1
  import { Ajv2020, MissingRefError } from "ajv/dist/2020.js";
5
2
  import addFormats from "ajv-formats";
6
3
  import { schemaObject } from "../core/schema-fields.js";
7
4
  import { visitSchema } from "../core/schema-refs.js";
8
5
  import { SUBFORMAT_SCHEMA_VERSION } from "../core/subformats.js";
6
+ import { fileURLToPath, pathToFileURL, realpathSync, relative } from "./host.js";
9
7
  import { readTextfile, textfilePath } from "./textfile.js";
10
8
  const cache = new Map();
11
9
  export const compileSubformatSchema = (content, source) => {
@@ -1,4 +1,5 @@
1
1
  import type { ValidateFunction } from "ajv";
2
+ import type { SchemaModel } from "../core/schema-graph.js";
2
3
  import { type Subformat, type SubformatCollection, type SubformatField } from "../core/subformats.js";
3
4
  export { compileSubformatSchema } from "./subformat-schema.js";
4
5
  export interface LoadedSubformat extends Subformat {
@@ -6,6 +7,8 @@ export interface LoadedSubformat extends Subformat {
6
7
  template: string;
7
8
  validate: ValidateFunction;
8
9
  }
10
+ /** Markup of a subformat's configured icon; throws when the file is not a usable SVG. */
11
+ export declare const subformatIconSvg: (root: string, config: Subformat) => string | undefined;
9
12
  export declare const loadSubformat: (root: string, config: Subformat, domains?: readonly string[]) => LoadedSubformat;
10
13
  export declare const validateSubformatRecord: (format: LoadedSubformat, data: Record<string, unknown>) => void;
11
14
  export declare const isSubformatSchemaFile: (root: string, file: string, domains?: readonly string[]) => boolean;
@@ -13,6 +16,7 @@ export declare const validateSubformatFile: (root: string, file: string, content
13
16
  export declare const subformatResponse: (root: string, input: Record<string, unknown> | undefined, domains?: readonly string[]) => {
14
17
  status: number;
15
18
  body: {
19
+ file?: string;
16
20
  content?: string;
17
21
  data?: Record<string, unknown>;
18
22
  collection?: SubformatCollection;
@@ -20,3 +24,9 @@ export declare const subformatResponse: (root: string, input: Record<string, unk
20
24
  };
21
25
  };
22
26
  export { parseSubformatRecord } from "../core/subformat-record.js";
27
+ /**
28
+ * Relations between subformats as a schemath model: one table per subformat, one field per
29
+ * top-level property. A property is a relation when it follows a `$ref` into another subformat's
30
+ * schema file, or when its string pattern ends with a registered record extension (`\\.ext$`).
31
+ */
32
+ export declare const subformatRelations: (root: string, configs: readonly Subformat[], domains?: readonly string[]) => SchemaModel;
@@ -1,18 +1,27 @@
1
- import { existsSync } from "node:fs";
2
- import { pathToFileURL } from "node:url";
3
- import { isDeepStrictEqual } from "node:util";
4
1
  import { stringify as stringifyToml } from "smol-toml";
5
2
  import { Document, isSeq, parseDocument, stringify as stringifyYaml, visit } from "yaml";
6
- import { flattenTree, MANIFEST_FILE, subformatPageId } from "../core/content-metadata.js";
3
+ import { flattenTree, subformatPageId } from "../core/content-metadata.js";
7
4
  import { fileExtension } from "../core/files.js";
5
+ import { schemaObject } from "../core/schema-fields.js";
8
6
  import { schemaResolver } from "../core/schema-refs.js";
9
7
  import { parseSubformatRecord, setSubformatValue } from "../core/subformat-record.js";
10
8
  import { parseSubformats, SUBFORMAT_SCHEMA_TEMPLATE, } from "../core/subformats.js";
11
9
  import { filesSnapshot, managedFile } from "./files.js";
12
- import { parseManifestText, readManifest } from "./manifest.js";
10
+ import { existsSync, isDeepStrictEqual, pathToFileURL } from "./host.js";
11
+ import { squareSvg } from "./icons.js";
12
+ import { manifestFile, parseManifestText, readManifest } from "./manifest.js";
13
13
  import { compileSubformatSchema } from "./subformat-schema.js";
14
14
  import { readTextfile, textfilePath, writeTextfile } from "./textfile.js";
15
15
  export { compileSubformatSchema } from "./subformat-schema.js";
16
+ /** Markup of a subformat's configured icon; throws when the file is not a usable SVG. */
17
+ export const subformatIconSvg = (root, config) => {
18
+ if (!config.icon)
19
+ return undefined;
20
+ const svg = squareSvg(readTextfile(root, config.icon));
21
+ if (!svg)
22
+ throw new Error(`${config.icon}: expected an SVG with a viewBox or width and height`);
23
+ return svg;
24
+ };
16
25
  export const loadSubformat = (root, config, domains = []) => {
17
26
  const content = readTextfile(root, config.schema);
18
27
  const { schema, validate, context } = compileSubformatSchema(content, {
@@ -22,11 +31,25 @@ export const loadSubformat = (root, config, domains = []) => {
22
31
  });
23
32
  const resolve = schemaResolver(schema, context);
24
33
  // shortcut: controls use top-level properties and refs; extend extraction for composed schemas.
34
+ const recordFiles = (ext) => {
35
+ try {
36
+ return filesSnapshot(root)
37
+ .files.map((file) => file.path)
38
+ .filter((file) => fileExtension(file) === ext && file !== config.schema);
39
+ }
40
+ catch {
41
+ // Without a readable workspace the field stays a plain value.
42
+ return [];
43
+ }
44
+ };
25
45
  const fields = Object.entries(resolve(schema).properties ?? {}).flatMap(([name, definition]) => {
26
46
  if (!definition || typeof definition !== "object")
27
47
  return [];
28
48
  const property = resolve(definition);
29
49
  const values = property.enum;
50
+ const reference = typeof property.pattern === "string"
51
+ ? /\\\.([\w-]+)\$$/.exec(property.pattern)?.[1]
52
+ : undefined;
30
53
  return [
31
54
  {
32
55
  name,
@@ -43,6 +66,7 @@ export const loadSubformat = (root, config, domains = []) => {
43
66
  ? { format: property.format }
44
67
  : {}),
45
68
  ...(property.readOnly === true ? { readOnly: true } : {}),
69
+ ...(reference ? { options: recordFiles(reference) } : {}),
46
70
  },
47
71
  ];
48
72
  });
@@ -155,8 +179,8 @@ export const subformatResponse = (root, input, domains = []) => {
155
179
  typeof input.value !== "string" ||
156
180
  (input.base !== null && typeof input.base !== "string"))
157
181
  throw new Error("A layout key, value and previous value are required");
158
- const raw = readTextfile(root, MANIFEST_FILE);
159
- const manifest = parseManifestText(raw);
182
+ const raw = readTextfile(root, manifestFile(root));
183
+ const manifest = parseManifestText(raw, manifestFile(root));
160
184
  if (manifest.errors.length)
161
185
  throw new Error(manifest.errors.join("\n"));
162
186
  const index = manifest.subformats?.findIndex((format) => format.ext === input.ext) ?? -1;
@@ -180,15 +204,15 @@ export const subformatResponse = (root, input, domains = []) => {
180
204
  const document = parseDocument(raw);
181
205
  const section = manifest.format === "nested" ? "json_subformats" : "subformats";
182
206
  document.setIn([section, index, "layouts", key], input.value);
183
- if (!writeTextfile(root, MANIFEST_FILE, document.toString(), raw))
207
+ if (!writeTextfile(root, manifestFile(root), document.toString(), raw))
184
208
  return { status: 409, body: { error: "Manifest changed externally. Try again." } };
185
- return { status: 200, body: {} };
209
+ return { status: 200, body: { file: manifestFile(root) } };
186
210
  }
187
211
  if (input?.action === "delete") {
188
212
  if (typeof input.ext !== "string")
189
213
  throw new Error("A subformat extension is required");
190
- const raw = readTextfile(root, MANIFEST_FILE);
191
- const manifest = parseManifestText(raw);
214
+ const raw = readTextfile(root, manifestFile(root));
215
+ const manifest = parseManifestText(raw, manifestFile(root));
192
216
  if (manifest.errors.length)
193
217
  throw new Error(manifest.errors.join("\n"));
194
218
  const index = manifest.subformats?.findIndex((format) => format.ext === input.ext) ?? -1;
@@ -217,16 +241,16 @@ export const subformatResponse = (root, input, domains = []) => {
217
241
  if (!nested && document.hasIn(["files", "icons", id]))
218
242
  document.deleteIn(["files", "icons", id]);
219
243
  const content = document.toString();
220
- const next = parseManifestText(content);
244
+ const next = parseManifestText(content, manifestFile(root));
221
245
  if (next.errors.length)
222
246
  throw new Error(next.errors.join("\n"));
223
- if (!writeTextfile(root, MANIFEST_FILE, content, raw))
247
+ if (!writeTextfile(root, manifestFile(root), content, raw))
224
248
  return { status: 409, body: { error: "Manifest changed externally. Try again." } };
225
- return { status: 200, body: {} };
249
+ return { status: 200, body: { file: manifestFile(root) } };
226
250
  }
227
251
  if (input?.action === "register") {
228
- const raw = readTextfile(root, MANIFEST_FILE);
229
- const manifest = parseManifestText(raw);
252
+ const raw = readTextfile(root, manifestFile(root));
253
+ const manifest = parseManifestText(raw, manifestFile(root));
230
254
  if (manifest.errors.length)
231
255
  throw new Error(manifest.errors.join("\n"));
232
256
  const schema = input.schema === undefined || input.schema === ""
@@ -271,7 +295,7 @@ export const subformatResponse = (root, input, domains = []) => {
271
295
  document.addIn([key], config);
272
296
  else
273
297
  document.set(key, [config]);
274
- if (!writeTextfile(root, MANIFEST_FILE, document.toString(), raw))
298
+ if (!writeTextfile(root, manifestFile(root), document.toString(), raw))
275
299
  return { status: 409, body: { error: "Manifest changed externally. Try again." } };
276
300
  return {
277
301
  status: 200,
@@ -311,7 +335,8 @@ export const subformatResponse = (root, input, domains = []) => {
311
335
  throw new Error("Subformat schema is not available in the workspace");
312
336
  const format = loadSubformat(root, config, domains);
313
337
  const field = format.fields.find((field) => field.name === input.field);
314
- if (field?.readOnly || !field?.enum?.some((value) => value === input.value))
338
+ if (field?.readOnly ||
339
+ !(field?.enum ?? field?.options)?.some((value) => value === input.value))
315
340
  throw new Error("Choose a writable enum value defined by the schema");
316
341
  const current = readTextfile(root, input.file);
317
342
  if (current !== input.base)
@@ -337,3 +362,82 @@ export const subformatResponse = (root, input, domains = []) => {
337
362
  }
338
363
  };
339
364
  export { parseSubformatRecord } from "../core/subformat-record.js";
365
+ /**
366
+ * Relations between subformats as a schemath model: one table per subformat, one field per
367
+ * top-level property. A property is a relation when it follows a `$ref` into another subformat's
368
+ * schema file, or when its string pattern ends with a registered record extension (`\\.ext$`).
369
+ */
370
+ export const subformatRelations = (root, configs, domains = []) => {
371
+ const loaded = configs.flatMap((config) => {
372
+ try {
373
+ const compiled = compileSubformatSchema(readTextfile(root, config.schema), {
374
+ root,
375
+ file: config.schema,
376
+ domains,
377
+ });
378
+ return [{ ext: config.ext, ...compiled }];
379
+ }
380
+ catch {
381
+ // Broken schemas are reported by the resource index.
382
+ return [];
383
+ }
384
+ });
385
+ const owners = new Map(loaded.map(({ ext, context }) => [context.uri, ext]));
386
+ const model = { groups: [], tables: [], edges: [] };
387
+ for (const { ext, schema, context } of loaded) {
388
+ const resolve = schemaResolver(schema, context);
389
+ const fields = [];
390
+ for (const [name, definition] of Object.entries(resolve(schema).properties ?? {})) {
391
+ const targets = new Set();
392
+ let list = false;
393
+ const seen = new Set();
394
+ const walk = (value) => {
395
+ const node = resolve(value, (uri) => {
396
+ const owner = owners.get(uri.split("#")[0] ?? "");
397
+ if (owner && owner !== ext)
398
+ targets.add(owner);
399
+ });
400
+ if (seen.has(value))
401
+ return node;
402
+ seen.add(value);
403
+ const suffix = typeof node.pattern === "string" && /\\\.([\w-]+)\$$/.exec(node.pattern)?.[1];
404
+ if (suffix && loaded.some((item) => item.ext === suffix))
405
+ targets.add(suffix);
406
+ for (const key of ["anyOf", "oneOf", "allOf"])
407
+ if (Array.isArray(node[key]))
408
+ for (const child of node[key])
409
+ walk(child);
410
+ // Nested objects count for their top-level field (`listeners[].target`).
411
+ if (schemaObject(node.properties))
412
+ for (const child of Object.values(node.properties))
413
+ walk(child);
414
+ if (node.items !== undefined) {
415
+ list = true;
416
+ walk(node.items);
417
+ }
418
+ return node;
419
+ };
420
+ const property = walk(definition);
421
+ const type = Array.isArray(property.enum)
422
+ ? property.enum.map((value) => JSON.stringify(value)).join("|")
423
+ : property.format === "date" || property.format === "date-time"
424
+ ? "timestamp"
425
+ : property.type === "string"
426
+ ? "string"
427
+ : property.type === "number" || property.type === "integer"
428
+ ? "number"
429
+ : property.type === "boolean"
430
+ ? "bool"
431
+ : "json";
432
+ for (const to of targets)
433
+ model.edges.push({ from: ext, fieldIndex: fields.length, field: name, to, list });
434
+ fields.push(targets.size
435
+ ? { name, kind: list ? "fkList" : "fk", targets: [...targets] }
436
+ : { name, kind: "scalar", type });
437
+ }
438
+ model.tables.push({ name: ext, fields, notes: [] });
439
+ // One group per table: the layout derives its columns from inter-group edges.
440
+ model.groups.push({ tables: [ext] });
441
+ }
442
+ return model;
443
+ };
@@ -1,6 +1,5 @@
1
- import { execFileSync } from "node:child_process";
2
1
  import { allowedPreviewUrl } from "../core/previewers.js";
3
- import { fetchPublicFile } from "./public-file.js";
2
+ import { execFileSync, fetchPublicFile } from "./host.js";
4
3
  export class TextfileUnavailable extends Error {
5
4
  reason;
6
5
  constructor(reason) {
@@ -1,9 +1,6 @@
1
- import { randomUUID } from "node:crypto";
2
- import { linkSync, lstatSync, mkdirSync, readFileSync, realpathSync, renameSync, rmSync, statSync, writeFileSync, } from "node:fs";
3
- import { open, stat } from "node:fs/promises";
4
- import { dirname, isAbsolute, join, relative, resolve, sep } from "node:path";
5
1
  import { isRemoteTextfile, parseTextfileRange } from "../core/textfile.js";
6
- import { assertNotIgnored } from "./ignored-files.js";
2
+ import { dirname, isAbsolute, join, linkSync, lstatSync, mkdirSync, open, randomUUID, readFileSync, realpathSync, relative, renameSync, resolve, rmSync, sep, stat, statSync, writeFileSync, } from "./host.js";
3
+ import { assertNotIgnored, withinRead } from "./ignored-files.js";
7
4
  import { readRemoteTextfile, readRemoteTextfileAsync } from "./textfile-remote.js";
8
5
  export { parseTextfileRange } from "../core/textfile.js";
9
6
  /** Select whole lines, preserving their original separators and excluding the final separator. */
@@ -25,7 +22,8 @@ export const selectTextfileRange = (text, range) => {
25
22
  return text.slice(from, starts[end] ?? text.length).replace(/(?:\r\n|\n|\r)$/, "");
26
23
  };
27
24
  /** Embedded files must stay inside the docs root, including symlink targets. */
28
- export const textfilePath = (root, file) => {
25
+ export const textfilePath = (root, file) => withinRead(`path\0${root}\0${file}`, () => resolveTextfilePath(root, file));
26
+ const resolveTextfilePath = (root, file) => {
29
27
  if (!file.trim() ||
30
28
  /^[a-z][a-z\d+.-]*:/i.test(file) ||
31
29
  /[\0\r\n]/.test(file) ||
@@ -1,6 +1,6 @@
1
- import { existsSync, readdirSync } from "node:fs";
2
1
  import { localFile } from "../core/files.js";
3
2
  import { themeVariantFile } from "../core/theme-variants.js";
3
+ import { existsSync, readdirSync } from "./host.js";
4
4
  import { ignoredFiles } from "./ignored-files.js";
5
5
  import { readManifest } from "./manifest.js";
6
6
  import { textfilePath } from "./textfile.js";
@@ -2,7 +2,7 @@
2
2
  // dependency.
3
3
  // shortcut: no ZIP64 support = can't handle more than 4GB / 65535 entries; switch to a library if
4
4
  // the docs root outgrows that.
5
- import { crc32, deflateRawSync } from "node:zlib";
5
+ import { crc32, deflateRawSync } from "./host.js";
6
6
  // Fixed date (1980-01-01 00:00) = the same input yields the same zip (reproducible).
7
7
  const DOS_DATE = (0 << 9) | (1 << 5) | 1;
8
8
  export const zip = (entries) => {
@@ -21,6 +21,8 @@ export type CalloutItem = {
21
21
  ordered?: boolean;
22
22
  };
23
23
  export type Block = {
24
+ sourceFile?: string;
25
+ } & ({
24
26
  type: "themeVariants";
25
27
  default: Block;
26
28
  variants: Record<string, Block>;
@@ -36,7 +38,7 @@ export type Block = {
36
38
  blocks: Block[];
37
39
  } | {
38
40
  type: "h";
39
- level: 1 | 2 | 3;
41
+ level: 1 | 2 | 3 | 4 | 5 | 6;
40
42
  text: string;
41
43
  slug: string;
42
44
  } | {
@@ -88,10 +90,10 @@ export type Block = {
88
90
  caption?: string;
89
91
  graph: GraphModel;
90
92
  source?: string;
91
- };
93
+ });
92
94
  export interface TocEntry {
93
- /** heading depth (1 = `#`, 2 = `##`, 3 = `###`) */
94
- depth: 1 | 2 | 3;
95
+ /** heading depth (1 = `#` … 6 = `######`) */
96
+ depth: 1 | 2 | 3 | 4 | 5 | 6;
95
97
  text: string;
96
98
  slug: string;
97
99
  }