@interactive-inc/docs-client 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.
Files changed (268) hide show
  1. package/README.md +228 -0
  2. package/build/doc-client.d.ts +59 -0
  3. package/build/doc-client.d.ts.map +1 -0
  4. package/build/doc-client.js +95 -0
  5. package/build/doc-client.test.d.ts +2 -0
  6. package/build/doc-client.test.d.ts.map +1 -0
  7. package/build/doc-client.test.js +38 -0
  8. package/build/doc-directory-reference.d.ts +65 -0
  9. package/build/doc-directory-reference.d.ts.map +1 -0
  10. package/build/doc-directory-reference.js +292 -0
  11. package/build/doc-directory-reference.test.d.ts +2 -0
  12. package/build/doc-directory-reference.test.d.ts.map +1 -0
  13. package/build/doc-directory-reference.test.js +100 -0
  14. package/build/doc-file-index-reference.d.ts +72 -0
  15. package/build/doc-file-index-reference.d.ts.map +1 -0
  16. package/build/doc-file-index-reference.js +191 -0
  17. package/build/doc-file-index-reference.test.d.ts +2 -0
  18. package/build/doc-file-index-reference.test.d.ts.map +1 -0
  19. package/build/doc-file-index-reference.test.js +77 -0
  20. package/build/doc-file-md-reference.d.ts +97 -0
  21. package/build/doc-file-md-reference.d.ts.map +1 -0
  22. package/build/doc-file-md-reference.js +297 -0
  23. package/build/doc-file-md-reference.test.d.ts +2 -0
  24. package/build/doc-file-md-reference.test.d.ts.map +1 -0
  25. package/build/doc-file-md-reference.test.js +465 -0
  26. package/build/doc-file-relation-reference.d.ts +54 -0
  27. package/build/doc-file-relation-reference.d.ts.map +1 -0
  28. package/build/doc-file-relation-reference.js +109 -0
  29. package/build/doc-file-system-debug.d.ts +81 -0
  30. package/build/doc-file-system-debug.d.ts.map +1 -0
  31. package/build/doc-file-system-debug.js +317 -0
  32. package/build/doc-file-system.d.ts +100 -0
  33. package/build/doc-file-system.d.ts.map +1 -0
  34. package/build/doc-file-system.js +210 -0
  35. package/build/doc-file-tree-system.d.ts +38 -0
  36. package/build/doc-file-tree-system.d.ts.map +1 -0
  37. package/build/doc-file-tree-system.js +153 -0
  38. package/build/doc-file-tree-system.test.d.ts +2 -0
  39. package/build/doc-file-tree-system.test.d.ts.map +1 -0
  40. package/build/doc-file-tree-system.test.js +105 -0
  41. package/build/doc-file-unknown-reference.d.ts +80 -0
  42. package/build/doc-file-unknown-reference.d.ts.map +1 -0
  43. package/build/doc-file-unknown-reference.js +181 -0
  44. package/build/doc-file-unknown-reference.test.d.ts +2 -0
  45. package/build/doc-file-unknown-reference.test.d.ts.map +1 -0
  46. package/build/doc-file-unknown-reference.test.js +73 -0
  47. package/build/doc-markdown-system.d.ts +44 -0
  48. package/build/doc-markdown-system.d.ts.map +1 -0
  49. package/build/doc-markdown-system.js +153 -0
  50. package/build/doc-markdown-system.test.d.ts +2 -0
  51. package/build/doc-markdown-system.test.d.ts.map +1 -0
  52. package/build/doc-markdown-system.test.js +124 -0
  53. package/build/doc-path-system.d.ts +43 -0
  54. package/build/doc-path-system.d.ts.map +1 -0
  55. package/build/doc-path-system.js +148 -0
  56. package/build/doc-path-system.test.d.ts +2 -0
  57. package/build/doc-path-system.test.d.ts.map +1 -0
  58. package/build/doc-path-system.test.js +67 -0
  59. package/build/entities/doc-file-entity.d.ts +5 -0
  60. package/build/entities/doc-file-entity.d.ts.map +1 -0
  61. package/build/entities/doc-file-entity.js +1 -0
  62. package/build/entities/doc-file-index-entity.d.ts +30 -0
  63. package/build/entities/doc-file-index-entity.d.ts.map +1 -0
  64. package/build/entities/doc-file-index-entity.js +49 -0
  65. package/build/entities/doc-file-index-entity.test.d.ts +2 -0
  66. package/build/entities/doc-file-index-entity.test.d.ts.map +1 -0
  67. package/build/entities/doc-file-index-entity.test.js +195 -0
  68. package/build/entities/doc-file-md-entity.d.ts +30 -0
  69. package/build/entities/doc-file-md-entity.d.ts.map +1 -0
  70. package/build/entities/doc-file-md-entity.js +49 -0
  71. package/build/entities/doc-file-md-entity.test.d.ts +2 -0
  72. package/build/entities/doc-file-md-entity.test.d.ts.map +1 -0
  73. package/build/entities/doc-file-md-entity.test.js +178 -0
  74. package/build/entities/doc-file-unknown-entity.d.ts +26 -0
  75. package/build/entities/doc-file-unknown-entity.d.ts.map +1 -0
  76. package/build/entities/doc-file-unknown-entity.js +45 -0
  77. package/build/entities/doc-file-unknown-entity.test.d.ts +2 -0
  78. package/build/entities/doc-file-unknown-entity.test.d.ts.map +1 -0
  79. package/build/entities/doc-file-unknown-entity.test.js +131 -0
  80. package/build/index.d.ts +42 -0
  81. package/build/index.d.ts.map +1 -0
  82. package/build/index.js +39 -24064
  83. package/build/models.d.ts +818 -0
  84. package/build/models.d.ts.map +1 -0
  85. package/build/models.js +312 -0
  86. package/build/types.d.ts +154 -0
  87. package/build/types.d.ts.map +1 -0
  88. package/build/types.js +1 -0
  89. package/build/values/doc-content-md-front-matter-value.d.ts +49 -0
  90. package/build/values/doc-content-md-front-matter-value.d.ts.map +1 -0
  91. package/build/values/doc-content-md-front-matter-value.js +94 -0
  92. package/build/values/doc-content-md-front-matter-value.test.d.ts +2 -0
  93. package/build/values/doc-content-md-front-matter-value.test.d.ts.map +1 -0
  94. package/build/values/doc-content-md-front-matter-value.test.js +73 -0
  95. package/build/values/doc-content-md-value.d.ts +66 -0
  96. package/build/values/doc-content-md-value.d.ts.map +1 -0
  97. package/build/values/doc-content-md-value.js +218 -0
  98. package/build/values/doc-content-md-value.test.d.ts +2 -0
  99. package/build/values/doc-content-md-value.test.d.ts.map +1 -0
  100. package/build/values/doc-content-md-value.test.js +179 -0
  101. package/build/values/doc-directory-path-value.d.ts +89 -0
  102. package/build/values/doc-directory-path-value.d.ts.map +1 -0
  103. package/build/values/doc-directory-path-value.js +145 -0
  104. package/build/values/doc-directory-path-value.test.d.ts +2 -0
  105. package/build/values/doc-directory-path-value.test.d.ts.map +1 -0
  106. package/build/values/doc-directory-path-value.test.js +68 -0
  107. package/build/values/doc-file-content-index-value.d.ts +62 -0
  108. package/build/values/doc-file-content-index-value.d.ts.map +1 -0
  109. package/build/values/doc-file-content-index-value.js +134 -0
  110. package/build/values/doc-file-content-index-value.test.d.ts +2 -0
  111. package/build/values/doc-file-content-index-value.test.d.ts.map +1 -0
  112. package/build/values/doc-file-content-index-value.test.js +203 -0
  113. package/build/values/doc-file-content-md-value.d.ts +62 -0
  114. package/build/values/doc-file-content-md-value.d.ts.map +1 -0
  115. package/build/values/doc-file-content-md-value.js +139 -0
  116. package/build/values/doc-file-content-md-value.test.d.ts +2 -0
  117. package/build/values/doc-file-content-md-value.test.d.ts.map +1 -0
  118. package/build/values/doc-file-content-md-value.test.js +160 -0
  119. package/build/values/doc-file-path-value.d.ts +47 -0
  120. package/build/values/doc-file-path-value.d.ts.map +1 -0
  121. package/build/values/doc-file-path-value.js +83 -0
  122. package/build/values/doc-file-path-value.test.d.ts +2 -0
  123. package/build/values/doc-file-path-value.test.d.ts.map +1 -0
  124. package/build/values/doc-file-path-value.test.js +84 -0
  125. package/build/values/doc-front-matter-index-value.d.ts +66 -0
  126. package/build/values/doc-front-matter-index-value.d.ts.map +1 -0
  127. package/build/values/doc-front-matter-index-value.js +185 -0
  128. package/build/values/doc-front-matter-index-value.test.d.ts +2 -0
  129. package/build/values/doc-front-matter-index-value.test.d.ts.map +1 -0
  130. package/build/values/doc-front-matter-index-value.test.js +98 -0
  131. package/build/values/doc-front-matter-md-value-accessor.test.d.ts +2 -0
  132. package/build/values/doc-front-matter-md-value-accessor.test.d.ts.map +1 -0
  133. package/build/values/doc-front-matter-md-value-accessor.test.js +226 -0
  134. package/build/values/doc-front-matter-md-value.d.ts +80 -0
  135. package/build/values/doc-front-matter-md-value.d.ts.map +1 -0
  136. package/build/values/doc-front-matter-md-value.js +257 -0
  137. package/build/values/doc-front-matter-md-value.test.d.ts +2 -0
  138. package/build/values/doc-front-matter-md-value.test.d.ts.map +1 -0
  139. package/build/values/doc-front-matter-md-value.test.js +198 -0
  140. package/build/values/doc-relation-field-value.d.ts +57 -0
  141. package/build/values/doc-relation-field-value.d.ts.map +1 -0
  142. package/build/values/doc-relation-field-value.js +85 -0
  143. package/build/values/doc-relation-field-value.test.d.ts +2 -0
  144. package/build/values/doc-relation-field-value.test.d.ts.map +1 -0
  145. package/build/values/doc-relation-field-value.test.js +115 -0
  146. package/build/values/doc-relation-file-value.d.ts +33 -0
  147. package/build/values/doc-relation-file-value.d.ts.map +1 -0
  148. package/build/values/doc-relation-file-value.js +55 -0
  149. package/build/values/doc-relation-file-value.test.d.ts +2 -0
  150. package/build/values/doc-relation-file-value.test.d.ts.map +1 -0
  151. package/build/values/doc-relation-file-value.test.js +77 -0
  152. package/build/values/doc-relation-value.d.ts +34 -0
  153. package/build/values/doc-relation-value.d.ts.map +1 -0
  154. package/build/values/doc-relation-value.js +56 -0
  155. package/build/values/doc-relation-value.test.d.ts +2 -0
  156. package/build/values/doc-relation-value.test.d.ts.map +1 -0
  157. package/build/values/doc-relation-value.test.js +89 -0
  158. package/build/values/doc-schema-field-boolean-multiple-value.d.ts +23 -0
  159. package/build/values/doc-schema-field-boolean-multiple-value.d.ts.map +1 -0
  160. package/build/values/doc-schema-field-boolean-multiple-value.js +43 -0
  161. package/build/values/doc-schema-field-boolean-multiple-value.test.d.ts +2 -0
  162. package/build/values/doc-schema-field-boolean-multiple-value.test.d.ts.map +1 -0
  163. package/build/values/doc-schema-field-boolean-multiple-value.test.js +76 -0
  164. package/build/values/doc-schema-field-boolean-single-value.d.ts +23 -0
  165. package/build/values/doc-schema-field-boolean-single-value.d.ts.map +1 -0
  166. package/build/values/doc-schema-field-boolean-single-value.js +39 -0
  167. package/build/values/doc-schema-field-boolean-single-value.test.d.ts +2 -0
  168. package/build/values/doc-schema-field-boolean-single-value.test.d.ts.map +1 -0
  169. package/build/values/doc-schema-field-boolean-single-value.test.js +73 -0
  170. package/build/values/doc-schema-field-factory.d.ts +37 -0
  171. package/build/values/doc-schema-field-factory.d.ts.map +1 -0
  172. package/build/values/doc-schema-field-factory.js +151 -0
  173. package/build/values/doc-schema-field-factory.test.d.ts +2 -0
  174. package/build/values/doc-schema-field-factory.test.d.ts.map +1 -0
  175. package/build/values/doc-schema-field-factory.test.js +215 -0
  176. package/build/values/doc-schema-field-number-multiple-value.d.ts +23 -0
  177. package/build/values/doc-schema-field-number-multiple-value.d.ts.map +1 -0
  178. package/build/values/doc-schema-field-number-multiple-value.js +43 -0
  179. package/build/values/doc-schema-field-number-multiple-value.test.d.ts +2 -0
  180. package/build/values/doc-schema-field-number-multiple-value.test.d.ts.map +1 -0
  181. package/build/values/doc-schema-field-number-multiple-value.test.js +79 -0
  182. package/build/values/doc-schema-field-number-single-value.d.ts +23 -0
  183. package/build/values/doc-schema-field-number-single-value.d.ts.map +1 -0
  184. package/build/values/doc-schema-field-number-single-value.js +39 -0
  185. package/build/values/doc-schema-field-number-single-value.test.d.ts +2 -0
  186. package/build/values/doc-schema-field-number-single-value.test.d.ts.map +1 -0
  187. package/build/values/doc-schema-field-number-single-value.test.js +77 -0
  188. package/build/values/doc-schema-field-relation-multiple-value.d.ts +24 -0
  189. package/build/values/doc-schema-field-relation-multiple-value.d.ts.map +1 -0
  190. package/build/values/doc-schema-field-relation-multiple-value.js +46 -0
  191. package/build/values/doc-schema-field-relation-multiple-value.test.d.ts +2 -0
  192. package/build/values/doc-schema-field-relation-multiple-value.test.d.ts.map +1 -0
  193. package/build/values/doc-schema-field-relation-multiple-value.test.js +83 -0
  194. package/build/values/doc-schema-field-relation-single-value.d.ts +24 -0
  195. package/build/values/doc-schema-field-relation-single-value.d.ts.map +1 -0
  196. package/build/values/doc-schema-field-relation-single-value.js +42 -0
  197. package/build/values/doc-schema-field-relation-single-value.test.d.ts +2 -0
  198. package/build/values/doc-schema-field-relation-single-value.test.d.ts.map +1 -0
  199. package/build/values/doc-schema-field-relation-single-value.test.js +83 -0
  200. package/build/values/doc-schema-field-select-number-multiple-value.d.ts +25 -0
  201. package/build/values/doc-schema-field-select-number-multiple-value.d.ts.map +1 -0
  202. package/build/values/doc-schema-field-select-number-multiple-value.js +48 -0
  203. package/build/values/doc-schema-field-select-number-multiple-value.test.d.ts +2 -0
  204. package/build/values/doc-schema-field-select-number-multiple-value.test.d.ts.map +1 -0
  205. package/build/values/doc-schema-field-select-number-multiple-value.test.js +84 -0
  206. package/build/values/doc-schema-field-select-number-single-value.d.ts +25 -0
  207. package/build/values/doc-schema-field-select-number-single-value.d.ts.map +1 -0
  208. package/build/values/doc-schema-field-select-number-single-value.js +45 -0
  209. package/build/values/doc-schema-field-select-number-single-value.test.d.ts +2 -0
  210. package/build/values/doc-schema-field-select-number-single-value.test.d.ts.map +1 -0
  211. package/build/values/doc-schema-field-select-number-single-value.test.js +96 -0
  212. package/build/values/doc-schema-field-select-text-multiple-value.d.ts +25 -0
  213. package/build/values/doc-schema-field-select-text-multiple-value.d.ts.map +1 -0
  214. package/build/values/doc-schema-field-select-text-multiple-value.js +48 -0
  215. package/build/values/doc-schema-field-select-text-multiple-value.test.d.ts +2 -0
  216. package/build/values/doc-schema-field-select-text-multiple-value.test.d.ts.map +1 -0
  217. package/build/values/doc-schema-field-select-text-multiple-value.test.js +84 -0
  218. package/build/values/doc-schema-field-select-text-single-value.d.ts +25 -0
  219. package/build/values/doc-schema-field-select-text-single-value.d.ts.map +1 -0
  220. package/build/values/doc-schema-field-select-text-single-value.js +47 -0
  221. package/build/values/doc-schema-field-select-text-single-value.test.d.ts +2 -0
  222. package/build/values/doc-schema-field-select-text-single-value.test.d.ts.map +1 -0
  223. package/build/values/doc-schema-field-select-text-single-value.test.js +96 -0
  224. package/build/values/doc-schema-field-text-multiple-value.d.ts +23 -0
  225. package/build/values/doc-schema-field-text-multiple-value.d.ts.map +1 -0
  226. package/build/values/doc-schema-field-text-multiple-value.js +43 -0
  227. package/build/values/doc-schema-field-text-multiple-value.test.d.ts +2 -0
  228. package/build/values/doc-schema-field-text-multiple-value.test.d.ts.map +1 -0
  229. package/build/values/doc-schema-field-text-multiple-value.test.js +78 -0
  230. package/build/values/doc-schema-field-text-single-value.d.ts +23 -0
  231. package/build/values/doc-schema-field-text-single-value.d.ts.map +1 -0
  232. package/build/values/doc-schema-field-text-single-value.js +39 -0
  233. package/build/values/doc-schema-field-text-single-value.test.d.ts +2 -0
  234. package/build/values/doc-schema-field-text-single-value.test.d.ts.map +1 -0
  235. package/build/values/doc-schema-field-text-single-value.test.js +76 -0
  236. package/build/values/doc-schema-field-type-value.d.ts +61 -0
  237. package/build/values/doc-schema-field-type-value.d.ts.map +1 -0
  238. package/build/values/doc-schema-field-type-value.js +134 -0
  239. package/build/values/doc-schema-field-type-value.test.d.ts +2 -0
  240. package/build/values/doc-schema-field-type-value.test.d.ts.map +1 -0
  241. package/build/values/doc-schema-field-type-value.test.js +101 -0
  242. package/build/values/doc-schema-field-value.d.ts +45 -0
  243. package/build/values/doc-schema-field-value.d.ts.map +1 -0
  244. package/build/values/doc-schema-field-value.js +1 -0
  245. package/build/values/doc-schema-value.d.ts +99 -0
  246. package/build/values/doc-schema-value.d.ts.map +1 -0
  247. package/build/values/doc-schema-value.js +269 -0
  248. package/build/values/doc-schema-value.test.d.ts +2 -0
  249. package/build/values/doc-schema-value.test.d.ts.map +1 -0
  250. package/build/values/doc-schema-value.test.js +301 -0
  251. package/build/values/doc-tree-directory-node-value.d.ts +36 -0
  252. package/build/values/doc-tree-directory-node-value.d.ts.map +1 -0
  253. package/build/values/doc-tree-directory-node-value.js +71 -0
  254. package/build/values/doc-tree-directory-node-value.test.d.ts +2 -0
  255. package/build/values/doc-tree-directory-node-value.test.d.ts.map +1 -0
  256. package/build/values/doc-tree-directory-node-value.test.js +162 -0
  257. package/build/values/doc-tree-file-node-value.d.ts +33 -0
  258. package/build/values/doc-tree-file-node-value.d.ts.map +1 -0
  259. package/build/values/doc-tree-file-node-value.js +56 -0
  260. package/build/values/doc-tree-file-node-value.test.d.ts +2 -0
  261. package/build/values/doc-tree-file-node-value.test.d.ts.map +1 -0
  262. package/build/values/doc-tree-file-node-value.test.js +113 -0
  263. package/debug/debug.ts +108 -0
  264. package/package.json +7 -45
  265. package/bin/docs.js +0 -3
  266. package/build/assets/index.css +0 -1
  267. package/build/assets/index.js +0 -298
  268. package/build/index.html +0 -13
@@ -0,0 +1,465 @@
1
+ import { expect, test } from "bun:test";
2
+ import { DocFileMdReference } from "./doc-file-md-reference";
3
+ import { DocFileSystemDebug } from "./doc-file-system-debug";
4
+ import { DocPathSystem } from "./doc-path-system";
5
+ import { DocFileMdEntity } from "./entities/doc-file-md-entity";
6
+ import { DocFilePathValue } from "./values/doc-file-path-value";
7
+ test("DocFileMdReference - writeメソッドがフロントマターを含む完全なテキストを書き込む", async () => {
8
+ const fileSystem = DocFileSystemDebug.createWithFiles({
9
+ fileContents: {
10
+ "docs/products/entities/user-entity.md": [
11
+ "---",
12
+ "type: entity",
13
+ "title: ユーザー",
14
+ "---",
15
+ "",
16
+ "# ユーザー",
17
+ "",
18
+ "ユーザーの説明",
19
+ ].join("\n"),
20
+ },
21
+ });
22
+ const ref = new DocFileMdReference({
23
+ path: "docs/products/entities/user-entity.md",
24
+ fileSystem,
25
+ pathSystem: fileSystem.getPathSystem(),
26
+ });
27
+ // 既存のエンティティを読み込む
28
+ const entity = await ref.read();
29
+ if (entity instanceof Error) {
30
+ throw entity;
31
+ }
32
+ expect(entity).toBeInstanceOf(DocFileMdEntity);
33
+ // タイトルを更新
34
+ const updatedEntity = entity.withContent(entity.content.withTitle("新しいタイトル"));
35
+ // ファイルに書き込む
36
+ await ref.write(updatedEntity);
37
+ // ファイルの内容を確認
38
+ const writtenContent = fileSystem.getFileContent("docs/products/entities/user-entity.md");
39
+ expect(writtenContent).toBeTruthy();
40
+ // フロントマターが保持されていることを確認
41
+ expect(writtenContent).toContain("---");
42
+ expect(writtenContent).toContain("type: entity");
43
+ expect(writtenContent).toContain("title: ユーザー");
44
+ // タイトルが更新されていることを確認
45
+ expect(writtenContent).toContain("# 新しいタイトル");
46
+ });
47
+ test("DocFileMdReference - readメソッドが正しくエンティティを返す", async () => {
48
+ const fileSystem = DocFileSystemDebug.createWithFiles({
49
+ fileContents: {
50
+ "docs/features/login.md": [
51
+ "---",
52
+ "type: feature",
53
+ "status: in-progress",
54
+ "---",
55
+ "",
56
+ "# ログイン機能",
57
+ "",
58
+ "ユーザーがシステムにログインする機能",
59
+ ].join("\n"),
60
+ },
61
+ });
62
+ const ref = new DocFileMdReference({
63
+ path: "docs/features/login.md",
64
+ fileSystem,
65
+ pathSystem: fileSystem.getPathSystem(),
66
+ });
67
+ const entity = await ref.read();
68
+ if (entity instanceof Error) {
69
+ throw entity;
70
+ }
71
+ expect(entity).toBeInstanceOf(DocFileMdEntity);
72
+ // コンテンツの確認
73
+ expect(entity.content.title).toBe("ログイン機能");
74
+ // bodyにはタイトルと説明が含まれる
75
+ expect(entity.content.body).toBe("# ログイン機能\n\nユーザーがシステムにログインする機能");
76
+ expect(entity.content.description).toBe("ユーザーがシステムにログインする機能");
77
+ expect(entity.content.frontMatter.value.type).toBe("feature");
78
+ expect(entity.content.frontMatter.value.status).toBe("in-progress");
79
+ });
80
+ test("DocFileMdReference - 新規ファイルの作成", async () => {
81
+ const fileSystem = DocFileSystemDebug.createWithFiles({});
82
+ const ref = new DocFileMdReference({
83
+ path: "docs/products/values/price-value.md",
84
+ fileSystem,
85
+ pathSystem: fileSystem.getPathSystem(),
86
+ });
87
+ // 新しいエンティティを作成
88
+ const pathValue = DocFilePathValue.fromPathWithSystem("docs/products/values/price-value.md", fileSystem.getPathSystem());
89
+ const entity = new DocFileMdEntity({
90
+ type: "markdown",
91
+ path: pathValue.value,
92
+ content: {
93
+ type: "markdown-content",
94
+ title: "価格",
95
+ body: "# 価格\n\n商品の価格を表す値オブジェクト",
96
+ description: "商品の価格を表す値オブジェクト",
97
+ frontMatter: {
98
+ value: {
99
+ type: "value-object",
100
+ attributes: ["amount", "currency"],
101
+ },
102
+ },
103
+ },
104
+ isArchived: false,
105
+ });
106
+ // ファイルに書き込む
107
+ await ref.write(entity);
108
+ // ファイルの内容を確認
109
+ const writtenContent = fileSystem.getFileContent("docs/products/values/price-value.md");
110
+ expect(writtenContent).toBeTruthy();
111
+ // 内容の確認
112
+ expect(writtenContent).toContain("---");
113
+ expect(writtenContent).toContain("type: value-object");
114
+ // YAMLの配列は複数行形式で出力される
115
+ expect(writtenContent).toContain("attributes:");
116
+ expect(writtenContent).toContain("- amount");
117
+ expect(writtenContent).toContain("- currency");
118
+ expect(writtenContent).toContain("# 価格");
119
+ expect(writtenContent).toContain("商品の価格を表す値オブジェクト");
120
+ });
121
+ // リレーション関連のテスト
122
+ test("getDirectoryIndex メソッドはディレクトリのindex.mdを返す", async () => {
123
+ const files = {
124
+ "products/doc-browser/pages/index.md": `---
125
+ schema:
126
+ features:
127
+ type: multi-relation
128
+ path: docs/products/doc-browser/features
129
+ required: false
130
+ title: Features
131
+ description: List of features
132
+ default: []
133
+ ---
134
+ # Pages`,
135
+ "products/doc-browser/pages/home.md": `---
136
+ features:
137
+ - list-documents
138
+ - create-document
139
+ ---
140
+ # Home Page`,
141
+ };
142
+ const pathSystem = new DocPathSystem();
143
+ const mockFileSystem = {
144
+ getBasePath: () => "",
145
+ readFile: async (path) => {
146
+ // アーカイブチェックも含む
147
+ if (files[path])
148
+ return files[path];
149
+ // アーカイブパスをチェック
150
+ const dirPath = pathSystem.dirname(path);
151
+ const fileName = pathSystem.basename(path);
152
+ const archivePath = pathSystem.join(dirPath, "_", fileName);
153
+ return files[archivePath] || null;
154
+ },
155
+ exists: async (path) => path in files,
156
+ pathSystem,
157
+ };
158
+ const fileSystem = mockFileSystem;
159
+ const fileRef = new DocFileMdReference({
160
+ path: "products/doc-browser/pages/home.md",
161
+ fileSystem: fileSystem,
162
+ pathSystem: pathSystem,
163
+ });
164
+ const indexFile = await fileRef.getDirectoryIndex();
165
+ expect(indexFile).not.toBeNull();
166
+ expect(indexFile?.content.frontMatter.value.schema).toBeDefined();
167
+ });
168
+ test("getDirectoryIndex メソッドはindex.mdがない場合nullを返す", async () => {
169
+ const files = {
170
+ "products/doc-browser/pages/home.md": `# Home Page`,
171
+ };
172
+ const pathSystem = new DocPathSystem();
173
+ const mockFileSystem = {
174
+ getBasePath: () => "",
175
+ readFile: async (path) => {
176
+ // アーカイブチェックも含む
177
+ if (files[path])
178
+ return files[path];
179
+ // アーカイブパスをチェック
180
+ const dirPath = pathSystem.dirname(path);
181
+ const fileName = pathSystem.basename(path);
182
+ const archivePath = pathSystem.join(dirPath, "_", fileName);
183
+ return files[archivePath] || null;
184
+ },
185
+ exists: async (path) => path in files,
186
+ pathSystem,
187
+ };
188
+ const fileSystem = mockFileSystem;
189
+ const fileRef = new DocFileMdReference({
190
+ path: "products/doc-browser/pages/home.md",
191
+ fileSystem: fileSystem,
192
+ pathSystem: pathSystem,
193
+ });
194
+ const indexFile = await fileRef.getDirectoryIndex();
195
+ expect(indexFile).toBeNull();
196
+ });
197
+ test("relation メソッドはスキーマに基づいてリレーションを解決する", async () => {
198
+ const files = {
199
+ "products/doc-browser/pages/index.md": `---
200
+ schema:
201
+ author:
202
+ type: relation
203
+ path: users
204
+ required: false
205
+ title: Author
206
+ description: Document author
207
+ default: null
208
+ ---
209
+ # Pages`,
210
+ "products/doc-browser/pages/home.md": `---
211
+ author: john-doe
212
+ ---
213
+ # Home Page`,
214
+ "users/john-doe.md": `# John Doe`,
215
+ };
216
+ const pathSystem = new DocPathSystem();
217
+ const mockFileSystem = {
218
+ getBasePath: () => "",
219
+ readFile: async (path) => {
220
+ // アーカイブチェックも含む
221
+ if (files[path])
222
+ return files[path];
223
+ // アーカイブパスをチェック
224
+ const dirPath = pathSystem.dirname(path);
225
+ const fileName = pathSystem.basename(path);
226
+ const archivePath = pathSystem.join(dirPath, "_", fileName);
227
+ return files[archivePath] || null;
228
+ },
229
+ exists: async (path) => path in files,
230
+ pathSystem,
231
+ };
232
+ const fileSystem = mockFileSystem;
233
+ const fileRef = new DocFileMdReference({
234
+ path: "products/doc-browser/pages/home.md",
235
+ fileSystem: fileSystem,
236
+ pathSystem: pathSystem,
237
+ });
238
+ const relationRef = await fileRef.relation("author");
239
+ expect(relationRef).not.toBeNull();
240
+ expect(relationRef).not.toBeInstanceOf(Error);
241
+ if (relationRef && !(relationRef instanceof Error)) {
242
+ expect(relationRef.path).toBe("users/john-doe.md");
243
+ const relationFile = await relationRef.read();
244
+ expect(relationFile).not.toBeInstanceOf(Error);
245
+ if (!(relationFile instanceof Error)) {
246
+ expect(relationFile.content.title).toBe("John Doe");
247
+ }
248
+ }
249
+ });
250
+ test("relation メソッドはスキーマがない場合nullを返す", async () => {
251
+ const files = {
252
+ "products/doc-browser/pages/home.md": `---
253
+ author: users/john-doe
254
+ ---
255
+ # Home Page`,
256
+ "users/john-doe.md": `# John Doe`,
257
+ };
258
+ const pathSystem = new DocPathSystem();
259
+ const mockFileSystem = {
260
+ getBasePath: () => "",
261
+ readFile: async (path) => {
262
+ // アーカイブチェックも含む
263
+ if (files[path])
264
+ return files[path];
265
+ // アーカイブパスをチェック
266
+ const dirPath = pathSystem.dirname(path);
267
+ const fileName = pathSystem.basename(path);
268
+ const archivePath = pathSystem.join(dirPath, "_", fileName);
269
+ return files[archivePath] || null;
270
+ },
271
+ exists: async (path) => path in files,
272
+ pathSystem,
273
+ };
274
+ const fileSystem = mockFileSystem;
275
+ const fileRef = new DocFileMdReference({
276
+ path: "products/doc-browser/pages/home.md",
277
+ fileSystem: fileSystem,
278
+ pathSystem: pathSystem,
279
+ });
280
+ const relationRef = await fileRef.relation("author");
281
+ expect(relationRef).toBeNull();
282
+ });
283
+ test("multiRelation メソッドは複数のリレーションを解決する", async () => {
284
+ const files = {
285
+ "products/doc-browser/pages/index.md": `---
286
+ schema:
287
+ features:
288
+ type: multi-relation
289
+ path: docs/products/doc-browser/features
290
+ required: false
291
+ title: Features
292
+ description: List of features
293
+ default: []
294
+ ---
295
+ # Pages`,
296
+ "products/doc-browser/pages/home.md": `---
297
+ features:
298
+ - list-documents
299
+ - create-document
300
+ - delete-document
301
+ ---
302
+ # Home Page`,
303
+ "docs/products/doc-browser/features/list-documents.md": `# List Documents`,
304
+ "docs/products/doc-browser/features/create-document.md": `# Create Document`,
305
+ "docs/products/doc-browser/features/delete-document.md": `# Delete Document`,
306
+ };
307
+ const pathSystem = new DocPathSystem();
308
+ const mockFileSystem = {
309
+ getBasePath: () => "",
310
+ readFile: async (path) => {
311
+ // アーカイブチェックも含む
312
+ if (files[path])
313
+ return files[path];
314
+ // アーカイブパスをチェック
315
+ const dirPath = pathSystem.dirname(path);
316
+ const fileName = pathSystem.basename(path);
317
+ const archivePath = pathSystem.join(dirPath, "_", fileName);
318
+ return files[archivePath] || null;
319
+ },
320
+ exists: async (path) => path in files,
321
+ pathSystem,
322
+ };
323
+ const fileSystem = mockFileSystem;
324
+ const fileRef = new DocFileMdReference({
325
+ path: "products/doc-browser/pages/home.md",
326
+ fileSystem: fileSystem,
327
+ pathSystem: pathSystem,
328
+ });
329
+ const relationRefs = await fileRef.multiRelation("features");
330
+ expect(relationRefs).toHaveLength(3);
331
+ expect(relationRefs[0].path).toBe("docs/products/doc-browser/features/list-documents.md");
332
+ expect(relationRefs[1].path).toBe("docs/products/doc-browser/features/create-document.md");
333
+ expect(relationRefs[2].path).toBe("docs/products/doc-browser/features/delete-document.md");
334
+ });
335
+ test("multiRelation メソッドは空のリレーションで空配列を返す", async () => {
336
+ const files = {
337
+ "products/doc-browser/pages/index.md": `---
338
+ schema:
339
+ features:
340
+ type: multi-relation
341
+ path: docs/products/doc-browser/features
342
+ required: false
343
+ title: Features
344
+ description: List of features
345
+ default: []
346
+ ---
347
+ # Pages`,
348
+ "products/doc-browser/pages/home.md": `---
349
+ features: []
350
+ ---
351
+ # Home Page`,
352
+ };
353
+ const pathSystem = new DocPathSystem();
354
+ const mockFileSystem = {
355
+ getBasePath: () => "",
356
+ readFile: async (path) => {
357
+ // アーカイブチェックも含む
358
+ if (files[path])
359
+ return files[path];
360
+ // アーカイブパスをチェック
361
+ const dirPath = pathSystem.dirname(path);
362
+ const fileName = pathSystem.basename(path);
363
+ const archivePath = pathSystem.join(dirPath, "_", fileName);
364
+ return files[archivePath] || null;
365
+ },
366
+ exists: async (path) => path in files,
367
+ pathSystem,
368
+ };
369
+ const fileSystem = mockFileSystem;
370
+ const fileRef = new DocFileMdReference({
371
+ path: "products/doc-browser/pages/home.md",
372
+ fileSystem: fileSystem,
373
+ pathSystem: pathSystem,
374
+ });
375
+ const relationRefs = await fileRef.multiRelation("features");
376
+ expect(relationRefs).toEqual([]);
377
+ });
378
+ test("relation メソッドはリレーションフィールドでない場合nullを返す", async () => {
379
+ const files = {
380
+ "products/doc-browser/pages/index.md": `---
381
+ schema:
382
+ title:
383
+ type: text
384
+ required: true
385
+ title: Title
386
+ description: Page title
387
+ default: ""
388
+ ---
389
+ # Pages`,
390
+ "products/doc-browser/pages/home.md": `---
391
+ title: ホームページ
392
+ ---
393
+ # Home Page`,
394
+ };
395
+ const pathSystem = new DocPathSystem();
396
+ const mockFileSystem = {
397
+ getBasePath: () => "",
398
+ readFile: async (path) => {
399
+ // アーカイブチェックも含む
400
+ if (files[path])
401
+ return files[path];
402
+ // アーカイブパスをチェック
403
+ const dirPath = pathSystem.dirname(path);
404
+ const fileName = pathSystem.basename(path);
405
+ const archivePath = pathSystem.join(dirPath, "_", fileName);
406
+ return files[archivePath] || null;
407
+ },
408
+ exists: async (path) => path in files,
409
+ pathSystem,
410
+ };
411
+ const fileSystem = mockFileSystem;
412
+ const fileRef = new DocFileMdReference({
413
+ path: "products/doc-browser/pages/home.md",
414
+ fileSystem: fileSystem,
415
+ pathSystem: pathSystem,
416
+ });
417
+ const relationRef = await fileRef.relation("title");
418
+ expect(relationRef).toBeNull();
419
+ });
420
+ test("index.mdがアーカイブにある場合も取得できる", async () => {
421
+ const files = {
422
+ "products/doc-browser/pages/_/index.md": `---
423
+ schema:
424
+ features:
425
+ type: multi-relation
426
+ path: docs/products/doc-browser/features
427
+ required: false
428
+ title: Features
429
+ description: List of features
430
+ default: []
431
+ ---
432
+ # Pages (Archived)`,
433
+ "products/doc-browser/pages/home.md": `---
434
+ features:
435
+ - list-documents
436
+ ---
437
+ # Home Page`,
438
+ };
439
+ const pathSystem = new DocPathSystem();
440
+ const mockFileSystem = {
441
+ getBasePath: () => "",
442
+ readFile: async (path) => {
443
+ // アーカイブチェックも含む
444
+ if (files[path])
445
+ return files[path];
446
+ // アーカイブパスをチェック
447
+ const dirPath = pathSystem.dirname(path);
448
+ const fileName = pathSystem.basename(path);
449
+ const archivePath = pathSystem.join(dirPath, "_", fileName);
450
+ return files[archivePath] || null;
451
+ },
452
+ exists: async (path) => path in files,
453
+ pathSystem,
454
+ };
455
+ const fileSystem = mockFileSystem;
456
+ const fileRef = new DocFileMdReference({
457
+ path: "products/doc-browser/pages/home.md",
458
+ fileSystem: fileSystem,
459
+ pathSystem: pathSystem,
460
+ });
461
+ const indexFile = await fileRef.getDirectoryIndex();
462
+ expect(indexFile).not.toBeNull();
463
+ // アーカイブのindex.mdが取得できることを確認
464
+ expect(indexFile?.content.frontMatter.value.schema).toBeDefined();
465
+ });
@@ -0,0 +1,54 @@
1
+ import type { DocFileSystem } from "./doc-file-system";
2
+ import type { DocPathSystem } from "./doc-path-system";
3
+ import { DocRelationFileValue } from "./values/doc-relation-file-value";
4
+ import { DocRelationValue } from "./values/doc-relation-value";
5
+ type Props = {
6
+ filePath: string;
7
+ fileSystem: DocFileSystem;
8
+ pathSystem: DocPathSystem;
9
+ };
10
+ /**
11
+ * リレーションファイルの参照
12
+ */
13
+ export declare class DocFileRelationReference {
14
+ private readonly props;
15
+ private readonly pathSystem;
16
+ constructor(props: Props);
17
+ get fileSystem(): DocFileSystem;
18
+ get basePath(): string;
19
+ /**
20
+ * リレーションパス
21
+ */
22
+ get path(): string;
23
+ /**
24
+ * フルパス
25
+ */
26
+ get fullPath(): string;
27
+ read(): Promise<DocRelationValue | null>;
28
+ /**
29
+ * リレーションファイルの一覧を読み込む
30
+ */
31
+ readFiles(): Promise<DocRelationFileValue[]>;
32
+ /**
33
+ * 単一のリレーションファイルを読み込む
34
+ */
35
+ readFile(filePath: string): Promise<DocRelationFileValue | null>;
36
+ /**
37
+ * ファイルの存在確認
38
+ */
39
+ exists(slug: string): Promise<boolean>;
40
+ /**
41
+ * ファイル名の一覧を取得(拡張子なし)
42
+ */
43
+ readSlugs(): Promise<string[]>;
44
+ /**
45
+ * ファイル数を取得
46
+ */
47
+ count(): Promise<number>;
48
+ /**
49
+ * 空かどうかを確認
50
+ */
51
+ isEmpty(): Promise<boolean>;
52
+ }
53
+ export {};
54
+ //# sourceMappingURL=doc-file-relation-reference.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"doc-file-relation-reference.d.ts","sourceRoot":"","sources":["../lib/doc-file-relation-reference.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AACtD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AAKtD,OAAO,EAAE,oBAAoB,EAAE,MAAM,kCAAkC,CAAA;AACvE,OAAO,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAA;AAE9D,KAAK,KAAK,GAAG;IACX,QAAQ,EAAE,MAAM,CAAA;IAChB,UAAU,EAAE,aAAa,CAAA;IACzB,UAAU,EAAE,aAAa,CAAA;CAC1B,CAAA;AAED;;GAEG;AACH,qBAAa,wBAAwB;IAGvB,OAAO,CAAC,QAAQ,CAAC,KAAK;IAFlC,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAe;IAE1C,YAA6B,KAAK,EAAE,KAAK,EAGxC;IAED,IAAI,UAAU,IAAI,aAAa,CAE9B;IAED,IAAI,QAAQ,IAAI,MAAM,CAErB;IAED;;OAEG;IACH,IAAI,IAAI,IAAI,MAAM,CAEjB;IAED;;OAEG;IACH,IAAI,QAAQ,IAAI,MAAM,CAKrB;IAEK,IAAI,IAAI,OAAO,CAAC,gBAAgB,GAAG,IAAI,CAAC,CAO7C;IAED;;OAEG;IACG,SAAS,IAAI,OAAO,CAAC,oBAAoB,EAAE,CAAC,CAkBjD;IAED;;OAEG;IACG,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,oBAAoB,GAAG,IAAI,CAAC,CAyBrE;IAED;;OAEG;IACG,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAG3C;IAED;;OAEG;IACG,SAAS,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC,CAGnC;IAED;;OAEG;IACG,KAAK,IAAI,OAAO,CAAC,MAAM,CAAC,CAG7B;IAED;;OAEG;IACG,OAAO,IAAI,OAAO,CAAC,OAAO,CAAC,CAGhC;CACF"}
@@ -0,0 +1,109 @@
1
+ import { DocFileMdEntity } from "./entities/doc-file-md-entity";
2
+ import { DocFileContentMdValue } from "./values/doc-file-content-md-value";
3
+ import { DocFilePathValue } from "./values/doc-file-path-value";
4
+ import { DocRelationFileValue } from "./values/doc-relation-file-value";
5
+ import { DocRelationValue } from "./values/doc-relation-value";
6
+ /**
7
+ * リレーションファイルの参照
8
+ */
9
+ export class DocFileRelationReference {
10
+ props;
11
+ pathSystem;
12
+ constructor(props) {
13
+ this.props = props;
14
+ this.pathSystem = props.pathSystem;
15
+ Object.freeze(this);
16
+ }
17
+ get fileSystem() {
18
+ return this.props.fileSystem;
19
+ }
20
+ get basePath() {
21
+ return this.fileSystem.getBasePath();
22
+ }
23
+ /**
24
+ * リレーションパス
25
+ */
26
+ get path() {
27
+ return this.props.filePath;
28
+ }
29
+ /**
30
+ * フルパス
31
+ */
32
+ get fullPath() {
33
+ return this.pathSystem.join(this.fileSystem.getBasePath(), this.props.filePath);
34
+ }
35
+ async read() {
36
+ const files = await this.readFiles();
37
+ return new DocRelationValue({
38
+ path: this.path,
39
+ files: files.map((value) => value.toJson()),
40
+ });
41
+ }
42
+ /**
43
+ * リレーションファイルの一覧を読み込む
44
+ */
45
+ async readFiles() {
46
+ const exists = await this.fileSystem.exists(this.path);
47
+ if (!exists) {
48
+ return [];
49
+ }
50
+ const filePaths = await this.fileSystem.readDirectoryFilePaths(this.path);
51
+ const files = [];
52
+ for (const filePath of filePaths) {
53
+ const file = await this.readFile(filePath);
54
+ if (file === null)
55
+ continue;
56
+ files.push(file);
57
+ }
58
+ return files;
59
+ }
60
+ /**
61
+ * 単一のリレーションファイルを読み込む
62
+ */
63
+ async readFile(filePath) {
64
+ if (filePath.includes("index.md")) {
65
+ return null;
66
+ }
67
+ const content = await this.fileSystem.readFile(filePath);
68
+ if (content === null) {
69
+ return null;
70
+ }
71
+ const contentValue = DocFileContentMdValue.fromMarkdown(content);
72
+ const pathValue = DocFilePathValue.fromPathWithSystem(filePath, this.pathSystem, this.basePath);
73
+ const fileEntity = new DocFileMdEntity({
74
+ type: "markdown",
75
+ content: contentValue.value,
76
+ path: pathValue.value,
77
+ isArchived: false,
78
+ });
79
+ return DocRelationFileValue.from(filePath, fileEntity.value.content.title);
80
+ }
81
+ /**
82
+ * ファイルの存在確認
83
+ */
84
+ async exists(slug) {
85
+ const filePath = `${this.path}/${slug}.md`;
86
+ return this.fileSystem.exists(filePath);
87
+ }
88
+ /**
89
+ * ファイル名の一覧を取得(拡張子なし)
90
+ */
91
+ async readSlugs() {
92
+ const files = await this.readFiles();
93
+ return files.map((file) => file.id);
94
+ }
95
+ /**
96
+ * ファイル数を取得
97
+ */
98
+ async count() {
99
+ const files = await this.readFiles();
100
+ return files.length;
101
+ }
102
+ /**
103
+ * 空かどうかを確認
104
+ */
105
+ async isEmpty() {
106
+ const count = await this.count();
107
+ return count === 0;
108
+ }
109
+ }