@interactive-inc/docs-client 0.0.5 → 0.0.7

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 (264) hide show
  1. package/README.md +3 -3
  2. package/build/index.d.ts +1921 -42
  3. package/build/index.js +4616 -39
  4. package/build/models.d.ts +34 -32
  5. package/build/models.js +219 -275
  6. package/package.json +4 -4
  7. package/tsup.config.ts +10 -0
  8. package/build/doc-client.d.ts +0 -59
  9. package/build/doc-client.d.ts.map +0 -1
  10. package/build/doc-client.js +0 -95
  11. package/build/doc-client.test.d.ts +0 -2
  12. package/build/doc-client.test.d.ts.map +0 -1
  13. package/build/doc-client.test.js +0 -38
  14. package/build/doc-directory-reference.d.ts +0 -65
  15. package/build/doc-directory-reference.d.ts.map +0 -1
  16. package/build/doc-directory-reference.js +0 -292
  17. package/build/doc-directory-reference.test.d.ts +0 -2
  18. package/build/doc-directory-reference.test.d.ts.map +0 -1
  19. package/build/doc-directory-reference.test.js +0 -100
  20. package/build/doc-file-index-reference.d.ts +0 -72
  21. package/build/doc-file-index-reference.d.ts.map +0 -1
  22. package/build/doc-file-index-reference.js +0 -191
  23. package/build/doc-file-index-reference.test.d.ts +0 -2
  24. package/build/doc-file-index-reference.test.d.ts.map +0 -1
  25. package/build/doc-file-index-reference.test.js +0 -77
  26. package/build/doc-file-md-reference.d.ts +0 -97
  27. package/build/doc-file-md-reference.d.ts.map +0 -1
  28. package/build/doc-file-md-reference.js +0 -297
  29. package/build/doc-file-md-reference.test.d.ts +0 -2
  30. package/build/doc-file-md-reference.test.d.ts.map +0 -1
  31. package/build/doc-file-md-reference.test.js +0 -465
  32. package/build/doc-file-relation-reference.d.ts +0 -54
  33. package/build/doc-file-relation-reference.d.ts.map +0 -1
  34. package/build/doc-file-relation-reference.js +0 -109
  35. package/build/doc-file-system-debug.d.ts +0 -81
  36. package/build/doc-file-system-debug.d.ts.map +0 -1
  37. package/build/doc-file-system-debug.js +0 -317
  38. package/build/doc-file-system.d.ts +0 -100
  39. package/build/doc-file-system.d.ts.map +0 -1
  40. package/build/doc-file-system.js +0 -210
  41. package/build/doc-file-tree-system.d.ts +0 -38
  42. package/build/doc-file-tree-system.d.ts.map +0 -1
  43. package/build/doc-file-tree-system.js +0 -153
  44. package/build/doc-file-tree-system.test.d.ts +0 -2
  45. package/build/doc-file-tree-system.test.d.ts.map +0 -1
  46. package/build/doc-file-tree-system.test.js +0 -105
  47. package/build/doc-file-unknown-reference.d.ts +0 -80
  48. package/build/doc-file-unknown-reference.d.ts.map +0 -1
  49. package/build/doc-file-unknown-reference.js +0 -181
  50. package/build/doc-file-unknown-reference.test.d.ts +0 -2
  51. package/build/doc-file-unknown-reference.test.d.ts.map +0 -1
  52. package/build/doc-file-unknown-reference.test.js +0 -73
  53. package/build/doc-markdown-system.d.ts +0 -44
  54. package/build/doc-markdown-system.d.ts.map +0 -1
  55. package/build/doc-markdown-system.js +0 -153
  56. package/build/doc-markdown-system.test.d.ts +0 -2
  57. package/build/doc-markdown-system.test.d.ts.map +0 -1
  58. package/build/doc-markdown-system.test.js +0 -124
  59. package/build/doc-path-system.d.ts +0 -43
  60. package/build/doc-path-system.d.ts.map +0 -1
  61. package/build/doc-path-system.js +0 -148
  62. package/build/doc-path-system.test.d.ts +0 -2
  63. package/build/doc-path-system.test.d.ts.map +0 -1
  64. package/build/doc-path-system.test.js +0 -67
  65. package/build/entities/doc-file-entity.d.ts +0 -5
  66. package/build/entities/doc-file-entity.d.ts.map +0 -1
  67. package/build/entities/doc-file-entity.js +0 -1
  68. package/build/entities/doc-file-index-entity.d.ts +0 -30
  69. package/build/entities/doc-file-index-entity.d.ts.map +0 -1
  70. package/build/entities/doc-file-index-entity.js +0 -49
  71. package/build/entities/doc-file-index-entity.test.d.ts +0 -2
  72. package/build/entities/doc-file-index-entity.test.d.ts.map +0 -1
  73. package/build/entities/doc-file-index-entity.test.js +0 -195
  74. package/build/entities/doc-file-md-entity.d.ts +0 -30
  75. package/build/entities/doc-file-md-entity.d.ts.map +0 -1
  76. package/build/entities/doc-file-md-entity.js +0 -49
  77. package/build/entities/doc-file-md-entity.test.d.ts +0 -2
  78. package/build/entities/doc-file-md-entity.test.d.ts.map +0 -1
  79. package/build/entities/doc-file-md-entity.test.js +0 -178
  80. package/build/entities/doc-file-unknown-entity.d.ts +0 -26
  81. package/build/entities/doc-file-unknown-entity.d.ts.map +0 -1
  82. package/build/entities/doc-file-unknown-entity.js +0 -45
  83. package/build/entities/doc-file-unknown-entity.test.d.ts +0 -2
  84. package/build/entities/doc-file-unknown-entity.test.d.ts.map +0 -1
  85. package/build/entities/doc-file-unknown-entity.test.js +0 -131
  86. package/build/index.d.ts.map +0 -1
  87. package/build/models.d.ts.map +0 -1
  88. package/build/types.d.ts +0 -154
  89. package/build/types.d.ts.map +0 -1
  90. package/build/types.js +0 -1
  91. package/build/values/doc-content-md-front-matter-value.d.ts +0 -49
  92. package/build/values/doc-content-md-front-matter-value.d.ts.map +0 -1
  93. package/build/values/doc-content-md-front-matter-value.js +0 -94
  94. package/build/values/doc-content-md-front-matter-value.test.d.ts +0 -2
  95. package/build/values/doc-content-md-front-matter-value.test.d.ts.map +0 -1
  96. package/build/values/doc-content-md-front-matter-value.test.js +0 -73
  97. package/build/values/doc-content-md-value.d.ts +0 -66
  98. package/build/values/doc-content-md-value.d.ts.map +0 -1
  99. package/build/values/doc-content-md-value.js +0 -218
  100. package/build/values/doc-content-md-value.test.d.ts +0 -2
  101. package/build/values/doc-content-md-value.test.d.ts.map +0 -1
  102. package/build/values/doc-content-md-value.test.js +0 -179
  103. package/build/values/doc-directory-path-value.d.ts +0 -89
  104. package/build/values/doc-directory-path-value.d.ts.map +0 -1
  105. package/build/values/doc-directory-path-value.js +0 -145
  106. package/build/values/doc-directory-path-value.test.d.ts +0 -2
  107. package/build/values/doc-directory-path-value.test.d.ts.map +0 -1
  108. package/build/values/doc-directory-path-value.test.js +0 -68
  109. package/build/values/doc-file-content-index-value.d.ts +0 -62
  110. package/build/values/doc-file-content-index-value.d.ts.map +0 -1
  111. package/build/values/doc-file-content-index-value.js +0 -134
  112. package/build/values/doc-file-content-index-value.test.d.ts +0 -2
  113. package/build/values/doc-file-content-index-value.test.d.ts.map +0 -1
  114. package/build/values/doc-file-content-index-value.test.js +0 -203
  115. package/build/values/doc-file-content-md-value.d.ts +0 -62
  116. package/build/values/doc-file-content-md-value.d.ts.map +0 -1
  117. package/build/values/doc-file-content-md-value.js +0 -139
  118. package/build/values/doc-file-content-md-value.test.d.ts +0 -2
  119. package/build/values/doc-file-content-md-value.test.d.ts.map +0 -1
  120. package/build/values/doc-file-content-md-value.test.js +0 -160
  121. package/build/values/doc-file-path-value.d.ts +0 -47
  122. package/build/values/doc-file-path-value.d.ts.map +0 -1
  123. package/build/values/doc-file-path-value.js +0 -83
  124. package/build/values/doc-file-path-value.test.d.ts +0 -2
  125. package/build/values/doc-file-path-value.test.d.ts.map +0 -1
  126. package/build/values/doc-file-path-value.test.js +0 -84
  127. package/build/values/doc-front-matter-index-value.d.ts +0 -66
  128. package/build/values/doc-front-matter-index-value.d.ts.map +0 -1
  129. package/build/values/doc-front-matter-index-value.js +0 -185
  130. package/build/values/doc-front-matter-index-value.test.d.ts +0 -2
  131. package/build/values/doc-front-matter-index-value.test.d.ts.map +0 -1
  132. package/build/values/doc-front-matter-index-value.test.js +0 -98
  133. package/build/values/doc-front-matter-md-value-accessor.test.d.ts +0 -2
  134. package/build/values/doc-front-matter-md-value-accessor.test.d.ts.map +0 -1
  135. package/build/values/doc-front-matter-md-value-accessor.test.js +0 -226
  136. package/build/values/doc-front-matter-md-value.d.ts +0 -80
  137. package/build/values/doc-front-matter-md-value.d.ts.map +0 -1
  138. package/build/values/doc-front-matter-md-value.js +0 -257
  139. package/build/values/doc-front-matter-md-value.test.d.ts +0 -2
  140. package/build/values/doc-front-matter-md-value.test.d.ts.map +0 -1
  141. package/build/values/doc-front-matter-md-value.test.js +0 -198
  142. package/build/values/doc-relation-field-value.d.ts +0 -57
  143. package/build/values/doc-relation-field-value.d.ts.map +0 -1
  144. package/build/values/doc-relation-field-value.js +0 -85
  145. package/build/values/doc-relation-field-value.test.d.ts +0 -2
  146. package/build/values/doc-relation-field-value.test.d.ts.map +0 -1
  147. package/build/values/doc-relation-field-value.test.js +0 -115
  148. package/build/values/doc-relation-file-value.d.ts +0 -33
  149. package/build/values/doc-relation-file-value.d.ts.map +0 -1
  150. package/build/values/doc-relation-file-value.js +0 -55
  151. package/build/values/doc-relation-file-value.test.d.ts +0 -2
  152. package/build/values/doc-relation-file-value.test.d.ts.map +0 -1
  153. package/build/values/doc-relation-file-value.test.js +0 -77
  154. package/build/values/doc-relation-value.d.ts +0 -34
  155. package/build/values/doc-relation-value.d.ts.map +0 -1
  156. package/build/values/doc-relation-value.js +0 -56
  157. package/build/values/doc-relation-value.test.d.ts +0 -2
  158. package/build/values/doc-relation-value.test.d.ts.map +0 -1
  159. package/build/values/doc-relation-value.test.js +0 -89
  160. package/build/values/doc-schema-field-boolean-multiple-value.d.ts +0 -23
  161. package/build/values/doc-schema-field-boolean-multiple-value.d.ts.map +0 -1
  162. package/build/values/doc-schema-field-boolean-multiple-value.js +0 -43
  163. package/build/values/doc-schema-field-boolean-multiple-value.test.d.ts +0 -2
  164. package/build/values/doc-schema-field-boolean-multiple-value.test.d.ts.map +0 -1
  165. package/build/values/doc-schema-field-boolean-multiple-value.test.js +0 -76
  166. package/build/values/doc-schema-field-boolean-single-value.d.ts +0 -23
  167. package/build/values/doc-schema-field-boolean-single-value.d.ts.map +0 -1
  168. package/build/values/doc-schema-field-boolean-single-value.js +0 -39
  169. package/build/values/doc-schema-field-boolean-single-value.test.d.ts +0 -2
  170. package/build/values/doc-schema-field-boolean-single-value.test.d.ts.map +0 -1
  171. package/build/values/doc-schema-field-boolean-single-value.test.js +0 -73
  172. package/build/values/doc-schema-field-factory.d.ts +0 -37
  173. package/build/values/doc-schema-field-factory.d.ts.map +0 -1
  174. package/build/values/doc-schema-field-factory.js +0 -151
  175. package/build/values/doc-schema-field-factory.test.d.ts +0 -2
  176. package/build/values/doc-schema-field-factory.test.d.ts.map +0 -1
  177. package/build/values/doc-schema-field-factory.test.js +0 -215
  178. package/build/values/doc-schema-field-number-multiple-value.d.ts +0 -23
  179. package/build/values/doc-schema-field-number-multiple-value.d.ts.map +0 -1
  180. package/build/values/doc-schema-field-number-multiple-value.js +0 -43
  181. package/build/values/doc-schema-field-number-multiple-value.test.d.ts +0 -2
  182. package/build/values/doc-schema-field-number-multiple-value.test.d.ts.map +0 -1
  183. package/build/values/doc-schema-field-number-multiple-value.test.js +0 -79
  184. package/build/values/doc-schema-field-number-single-value.d.ts +0 -23
  185. package/build/values/doc-schema-field-number-single-value.d.ts.map +0 -1
  186. package/build/values/doc-schema-field-number-single-value.js +0 -39
  187. package/build/values/doc-schema-field-number-single-value.test.d.ts +0 -2
  188. package/build/values/doc-schema-field-number-single-value.test.d.ts.map +0 -1
  189. package/build/values/doc-schema-field-number-single-value.test.js +0 -77
  190. package/build/values/doc-schema-field-relation-multiple-value.d.ts +0 -24
  191. package/build/values/doc-schema-field-relation-multiple-value.d.ts.map +0 -1
  192. package/build/values/doc-schema-field-relation-multiple-value.js +0 -46
  193. package/build/values/doc-schema-field-relation-multiple-value.test.d.ts +0 -2
  194. package/build/values/doc-schema-field-relation-multiple-value.test.d.ts.map +0 -1
  195. package/build/values/doc-schema-field-relation-multiple-value.test.js +0 -83
  196. package/build/values/doc-schema-field-relation-single-value.d.ts +0 -24
  197. package/build/values/doc-schema-field-relation-single-value.d.ts.map +0 -1
  198. package/build/values/doc-schema-field-relation-single-value.js +0 -42
  199. package/build/values/doc-schema-field-relation-single-value.test.d.ts +0 -2
  200. package/build/values/doc-schema-field-relation-single-value.test.d.ts.map +0 -1
  201. package/build/values/doc-schema-field-relation-single-value.test.js +0 -83
  202. package/build/values/doc-schema-field-select-number-multiple-value.d.ts +0 -25
  203. package/build/values/doc-schema-field-select-number-multiple-value.d.ts.map +0 -1
  204. package/build/values/doc-schema-field-select-number-multiple-value.js +0 -48
  205. package/build/values/doc-schema-field-select-number-multiple-value.test.d.ts +0 -2
  206. package/build/values/doc-schema-field-select-number-multiple-value.test.d.ts.map +0 -1
  207. package/build/values/doc-schema-field-select-number-multiple-value.test.js +0 -84
  208. package/build/values/doc-schema-field-select-number-single-value.d.ts +0 -25
  209. package/build/values/doc-schema-field-select-number-single-value.d.ts.map +0 -1
  210. package/build/values/doc-schema-field-select-number-single-value.js +0 -45
  211. package/build/values/doc-schema-field-select-number-single-value.test.d.ts +0 -2
  212. package/build/values/doc-schema-field-select-number-single-value.test.d.ts.map +0 -1
  213. package/build/values/doc-schema-field-select-number-single-value.test.js +0 -96
  214. package/build/values/doc-schema-field-select-text-multiple-value.d.ts +0 -25
  215. package/build/values/doc-schema-field-select-text-multiple-value.d.ts.map +0 -1
  216. package/build/values/doc-schema-field-select-text-multiple-value.js +0 -48
  217. package/build/values/doc-schema-field-select-text-multiple-value.test.d.ts +0 -2
  218. package/build/values/doc-schema-field-select-text-multiple-value.test.d.ts.map +0 -1
  219. package/build/values/doc-schema-field-select-text-multiple-value.test.js +0 -84
  220. package/build/values/doc-schema-field-select-text-single-value.d.ts +0 -25
  221. package/build/values/doc-schema-field-select-text-single-value.d.ts.map +0 -1
  222. package/build/values/doc-schema-field-select-text-single-value.js +0 -47
  223. package/build/values/doc-schema-field-select-text-single-value.test.d.ts +0 -2
  224. package/build/values/doc-schema-field-select-text-single-value.test.d.ts.map +0 -1
  225. package/build/values/doc-schema-field-select-text-single-value.test.js +0 -96
  226. package/build/values/doc-schema-field-text-multiple-value.d.ts +0 -23
  227. package/build/values/doc-schema-field-text-multiple-value.d.ts.map +0 -1
  228. package/build/values/doc-schema-field-text-multiple-value.js +0 -43
  229. package/build/values/doc-schema-field-text-multiple-value.test.d.ts +0 -2
  230. package/build/values/doc-schema-field-text-multiple-value.test.d.ts.map +0 -1
  231. package/build/values/doc-schema-field-text-multiple-value.test.js +0 -78
  232. package/build/values/doc-schema-field-text-single-value.d.ts +0 -23
  233. package/build/values/doc-schema-field-text-single-value.d.ts.map +0 -1
  234. package/build/values/doc-schema-field-text-single-value.js +0 -39
  235. package/build/values/doc-schema-field-text-single-value.test.d.ts +0 -2
  236. package/build/values/doc-schema-field-text-single-value.test.d.ts.map +0 -1
  237. package/build/values/doc-schema-field-text-single-value.test.js +0 -76
  238. package/build/values/doc-schema-field-type-value.d.ts +0 -61
  239. package/build/values/doc-schema-field-type-value.d.ts.map +0 -1
  240. package/build/values/doc-schema-field-type-value.js +0 -134
  241. package/build/values/doc-schema-field-type-value.test.d.ts +0 -2
  242. package/build/values/doc-schema-field-type-value.test.d.ts.map +0 -1
  243. package/build/values/doc-schema-field-type-value.test.js +0 -101
  244. package/build/values/doc-schema-field-value.d.ts +0 -45
  245. package/build/values/doc-schema-field-value.d.ts.map +0 -1
  246. package/build/values/doc-schema-field-value.js +0 -1
  247. package/build/values/doc-schema-value.d.ts +0 -99
  248. package/build/values/doc-schema-value.d.ts.map +0 -1
  249. package/build/values/doc-schema-value.js +0 -269
  250. package/build/values/doc-schema-value.test.d.ts +0 -2
  251. package/build/values/doc-schema-value.test.d.ts.map +0 -1
  252. package/build/values/doc-schema-value.test.js +0 -301
  253. package/build/values/doc-tree-directory-node-value.d.ts +0 -36
  254. package/build/values/doc-tree-directory-node-value.d.ts.map +0 -1
  255. package/build/values/doc-tree-directory-node-value.js +0 -71
  256. package/build/values/doc-tree-directory-node-value.test.d.ts +0 -2
  257. package/build/values/doc-tree-directory-node-value.test.d.ts.map +0 -1
  258. package/build/values/doc-tree-directory-node-value.test.js +0 -162
  259. package/build/values/doc-tree-file-node-value.d.ts +0 -33
  260. package/build/values/doc-tree-file-node-value.d.ts.map +0 -1
  261. package/build/values/doc-tree-file-node-value.js +0 -56
  262. package/build/values/doc-tree-file-node-value.test.d.ts +0 -2
  263. package/build/values/doc-tree-file-node-value.test.d.ts.map +0 -1
  264. package/build/values/doc-tree-file-node-value.test.js +0 -113
package/build/index.js CHANGED
@@ -1,39 +1,4616 @@
1
- export { DocClient } from "./doc-client";
2
- export { DocDirectoryReference } from "./doc-directory-reference";
3
- export { DocFileIndexReference } from "./doc-file-index-reference";
4
- export { DocFileMdReference } from "./doc-file-md-reference";
5
- export { DocFileRelationReference } from "./doc-file-relation-reference";
6
- export { DocFileSystem } from "./doc-file-system";
7
- export { DocFileTreeSystem as FileTreeSystem } from "./doc-file-tree-system";
8
- export { DocFileUnknownReference } from "./doc-file-unknown-reference";
9
- export { DocMarkdownSystem } from "./doc-markdown-system";
10
- export { DocPathSystem } from "./doc-path-system";
11
- export { DocFileIndexEntity } from "./entities/doc-file-index-entity";
12
- export { DocFileMdEntity } from "./entities/doc-file-md-entity";
13
- export { DocFileUnknownEntity } from "./entities/doc-file-unknown-entity";
14
- export * from "./models";
15
- export { DocContentMdValue } from "./values/doc-content-md-value";
16
- export { DocDirectoryPathValue } from "./values/doc-directory-path-value";
17
- export { DocFileContentIndexValue } from "./values/doc-file-content-index-value";
18
- export { DocFileContentMdValue } from "./values/doc-file-content-md-value";
19
- export { DocFilePathValue } from "./values/doc-file-path-value";
20
- export { DocFrontMatterIndexValue } from "./values/doc-front-matter-index-value";
21
- export { DocFrontMatterMdValue } from "./values/doc-front-matter-md-value";
22
- export { DocRelationFileValue } from "./values/doc-relation-file-value";
23
- export { DocRelationValue } from "./values/doc-relation-value";
24
- export { DocSchemaFieldBooleanMultipleValue } from "./values/doc-schema-field-boolean-multiple-value";
25
- export { DocSchemaFieldBooleanSingleValue } from "./values/doc-schema-field-boolean-single-value";
26
- export { DocSchemaFieldFactory } from "./values/doc-schema-field-factory";
27
- export { DocSchemaFieldNumberMultipleValue } from "./values/doc-schema-field-number-multiple-value";
28
- export { DocSchemaFieldNumberSingleValue } from "./values/doc-schema-field-number-single-value";
29
- export { DocSchemaFieldRelationMultipleValue } from "./values/doc-schema-field-relation-multiple-value";
30
- export { DocSchemaFieldRelationSingleValue } from "./values/doc-schema-field-relation-single-value";
31
- export { DocSchemaFieldSelectNumberMultipleValue } from "./values/doc-schema-field-select-number-multiple-value";
32
- export { DocSchemaFieldSelectNumberSingleValue } from "./values/doc-schema-field-select-number-single-value";
33
- export { DocSchemaFieldSelectTextMultipleValue } from "./values/doc-schema-field-select-text-multiple-value";
34
- export { DocSchemaFieldSelectTextSingleValue } from "./values/doc-schema-field-select-text-single-value";
35
- export { DocSchemaFieldTextMultipleValue } from "./values/doc-schema-field-text-multiple-value";
36
- export { DocSchemaFieldTextSingleValue } from "./values/doc-schema-field-text-single-value";
37
- export { DocSchemaValue } from "./values/doc-schema-value";
38
- export { DocTreeDirectoryNodeValue } from "./values/doc-tree-directory-node-value";
39
- export { DocTreeFileNodeValue } from "./values/doc-tree-file-node-value";
1
+ // lib/models.ts
2
+ import { z } from "zod/v4";
3
+ var zDocFilePath = z.object({
4
+ name: z.string(),
5
+ path: z.string(),
6
+ fullPath: z.string(),
7
+ nameWithExtension: z.string()
8
+ });
9
+ var zDocSchemaFieldTypeText = z.literal("text");
10
+ var zDocSchemaFieldTypeNumber = z.literal("number");
11
+ var zDocSchemaFieldTypeBoolean = z.literal("boolean");
12
+ var zDocSchemaFieldTypeMultiText = z.literal("multi-text");
13
+ var zDocSchemaFieldTypeMultiNumber = z.literal("multi-number");
14
+ var zDocSchemaFieldTypeMultiBoolean = z.literal("multi-boolean");
15
+ var zDocSchemaFieldTypeRelation = z.literal("relation");
16
+ var zDocSchemaFieldTypeMultiRelation = z.literal("multi-relation");
17
+ var zDocSchemaFieldTypeSelectText = z.literal("select-text");
18
+ var zDocSchemaFieldTypeSelectNumber = z.literal("select-number");
19
+ var zDocSchemaFieldTypeMultiSelectText = z.literal("multi-select-text");
20
+ var zDocSchemaFieldTypeMultiSelectNumber = z.literal("multi-select-number");
21
+ var zDocSchemaFieldType = z.union([
22
+ zDocSchemaFieldTypeText,
23
+ zDocSchemaFieldTypeNumber,
24
+ zDocSchemaFieldTypeBoolean,
25
+ zDocSchemaFieldTypeMultiText,
26
+ zDocSchemaFieldTypeMultiNumber,
27
+ zDocSchemaFieldTypeMultiBoolean,
28
+ zDocSchemaFieldTypeRelation,
29
+ zDocSchemaFieldTypeMultiRelation,
30
+ zDocSchemaFieldTypeSelectText,
31
+ zDocSchemaFieldTypeSelectNumber,
32
+ zDocSchemaFieldTypeMultiSelectText,
33
+ zDocSchemaFieldTypeMultiSelectNumber
34
+ ]);
35
+ var zDocSchemaFieldText = z.object({
36
+ type: zDocSchemaFieldTypeText,
37
+ required: z.boolean(),
38
+ title: z.string().nullable(),
39
+ description: z.string().nullable(),
40
+ default: z.string().nullable()
41
+ });
42
+ var zDocSchemaFieldNumber = z.object({
43
+ type: zDocSchemaFieldTypeNumber,
44
+ required: z.boolean(),
45
+ title: z.string().nullable(),
46
+ description: z.string().nullable(),
47
+ default: z.number().nullable()
48
+ });
49
+ var zDocSchemaFieldBoolean = z.object({
50
+ type: zDocSchemaFieldTypeBoolean,
51
+ required: z.boolean(),
52
+ title: z.string().nullable(),
53
+ description: z.string().nullable(),
54
+ default: z.boolean().nullable()
55
+ });
56
+ var zDocSchemaFieldMultiText = z.object({
57
+ type: zDocSchemaFieldTypeMultiText,
58
+ required: z.boolean(),
59
+ title: z.string().nullable(),
60
+ description: z.string().nullable(),
61
+ default: z.array(z.string()).nullable()
62
+ });
63
+ var zDocSchemaFieldMultiNumber = z.object({
64
+ type: zDocSchemaFieldTypeMultiNumber,
65
+ required: z.boolean(),
66
+ title: z.string().nullable(),
67
+ description: z.string().nullable(),
68
+ default: z.array(z.number()).nullable()
69
+ });
70
+ var zDocSchemaFieldMultiBoolean = z.object({
71
+ type: zDocSchemaFieldTypeMultiBoolean,
72
+ required: z.boolean(),
73
+ title: z.string().nullable(),
74
+ description: z.string().nullable(),
75
+ default: z.array(z.boolean()).nullable()
76
+ });
77
+ var zDocSchemaFieldRelation = z.object({
78
+ type: zDocSchemaFieldTypeRelation,
79
+ required: z.boolean(),
80
+ title: z.string().nullable(),
81
+ description: z.string().nullable(),
82
+ path: z.string().min(1),
83
+ default: z.string().nullable()
84
+ });
85
+ var zDocSchemaFieldMultiRelation = z.object({
86
+ type: zDocSchemaFieldTypeMultiRelation,
87
+ required: z.boolean(),
88
+ title: z.string().nullable(),
89
+ description: z.string().nullable(),
90
+ path: z.string().min(1),
91
+ default: z.array(z.string()).nullable()
92
+ });
93
+ var zDocSchemaFieldSelectText = z.object({
94
+ type: zDocSchemaFieldTypeSelectText,
95
+ required: z.boolean(),
96
+ title: z.string().nullable(),
97
+ description: z.string().nullable(),
98
+ options: z.array(z.string()),
99
+ default: z.string().nullable()
100
+ });
101
+ var zDocSchemaFieldSelectNumber = z.object({
102
+ type: zDocSchemaFieldTypeSelectNumber,
103
+ required: z.boolean(),
104
+ title: z.string().nullable(),
105
+ description: z.string().nullable(),
106
+ options: z.array(z.number()),
107
+ default: z.number().nullable()
108
+ });
109
+ var zDocSchemaFieldMultiSelectText = z.object({
110
+ type: zDocSchemaFieldTypeMultiSelectText,
111
+ required: z.boolean(),
112
+ title: z.string().nullable(),
113
+ description: z.string().nullable(),
114
+ options: z.array(z.string()),
115
+ default: z.array(z.string()).nullable()
116
+ });
117
+ var zDocSchemaFieldMultiSelectNumber = z.object({
118
+ type: zDocSchemaFieldTypeMultiSelectNumber,
119
+ required: z.boolean(),
120
+ title: z.string().nullable(),
121
+ description: z.string().nullable(),
122
+ options: z.array(z.number()),
123
+ default: z.array(z.number()).nullable()
124
+ });
125
+ var zDocSchemaField = z.union([
126
+ zDocSchemaFieldText,
127
+ zDocSchemaFieldNumber,
128
+ zDocSchemaFieldBoolean,
129
+ zDocSchemaFieldMultiText,
130
+ zDocSchemaFieldMultiNumber,
131
+ zDocSchemaFieldMultiBoolean,
132
+ zDocSchemaFieldRelation,
133
+ zDocSchemaFieldMultiRelation,
134
+ zDocSchemaFieldSelectText,
135
+ zDocSchemaFieldSelectNumber,
136
+ zDocSchemaFieldMultiSelectText,
137
+ zDocSchemaFieldMultiSelectNumber
138
+ ]);
139
+ var zDocFileMdFrontMatter = z.record(
140
+ z.string(),
141
+ z.union([
142
+ z.string(),
143
+ z.boolean(),
144
+ z.number(),
145
+ z.array(z.string()),
146
+ z.array(z.number()),
147
+ z.array(z.boolean()),
148
+ z.record(z.string(), z.unknown()),
149
+ z.null()
150
+ ])
151
+ );
152
+ var zDocSchema = z.record(z.string(), zDocSchemaField);
153
+ var zDocFileIndexFrontMatter = z.object({
154
+ type: z.literal("index-frontmatter"),
155
+ icon: z.string(),
156
+ schema: zDocSchema
157
+ });
158
+ var zDocRelationField = z.object({
159
+ fieldName: z.string(),
160
+ filePath: z.string(),
161
+ isArray: z.boolean()
162
+ });
163
+ var zDocRelationFile = z.object({
164
+ name: z.string(),
165
+ label: z.string().nullable(),
166
+ value: z.string().nullable(),
167
+ path: z.string().nullable()
168
+ });
169
+ var zDocRelation = z.object({
170
+ path: z.string(),
171
+ files: z.array(zDocRelationFile)
172
+ });
173
+ var zDocFileContentMd = z.object({
174
+ type: z.literal("markdown-content"),
175
+ body: z.string(),
176
+ title: z.string(),
177
+ description: z.string(),
178
+ frontMatter: zDocFileMdFrontMatter
179
+ });
180
+ var zDocFileContentIndex = z.object({
181
+ type: z.literal("markdown-index"),
182
+ body: z.string(),
183
+ title: z.string(),
184
+ description: z.string(),
185
+ frontMatter: zDocFileIndexFrontMatter
186
+ });
187
+ var zDocFileIndex = z.object({
188
+ type: z.literal("index"),
189
+ path: zDocFilePath,
190
+ content: zDocFileContentIndex,
191
+ isArchived: z.boolean()
192
+ });
193
+ var zDocFileUnknown = z.object({
194
+ type: z.literal("unknown"),
195
+ path: zDocFilePath,
196
+ content: z.string(),
197
+ extension: z.string(),
198
+ isArchived: z.boolean()
199
+ });
200
+ var zDocFileMd = z.object({
201
+ type: z.literal("markdown"),
202
+ path: zDocFilePath,
203
+ content: zDocFileContentMd,
204
+ isArchived: z.boolean()
205
+ });
206
+ var zDocFile = z.union([zDocFileIndex, zDocFileMd, zDocFileUnknown]);
207
+ var zDocTreeFileNode = z.object({
208
+ type: z.literal("file"),
209
+ name: z.string(),
210
+ path: z.string(),
211
+ icon: z.string(),
212
+ title: z.string()
213
+ });
214
+ var zDocTreeDirectoryNode = z.lazy(() => {
215
+ return z.object({
216
+ type: z.literal("directory"),
217
+ name: z.string(),
218
+ path: z.string(),
219
+ icon: z.string(),
220
+ title: z.string(),
221
+ children: z.array(z.union([zDocTreeFileNode, zDocTreeDirectoryNode]))
222
+ });
223
+ });
224
+ var zDocTreeNode = z.union([zDocTreeFileNode, zDocTreeDirectoryNode]);
225
+
226
+ // lib/doc-markdown-system.ts
227
+ var DocMarkdownSystem = class {
228
+ frontMatterSeparator = "---";
229
+ constructor() {
230
+ Object.freeze(this);
231
+ }
232
+ /**
233
+ * FrontMatterの区切り線を検出
234
+ */
235
+ detectFrontMatterSeparator(text) {
236
+ const firstLine = text.split("\n")[0];
237
+ if (firstLine?.match(/^-{3,}$/)) {
238
+ return firstLine;
239
+ }
240
+ return this.frontMatterSeparator;
241
+ }
242
+ /**
243
+ * FrontMatterを抽出
244
+ */
245
+ extractFrontMatter(text) {
246
+ const separator = this.detectFrontMatterSeparator(text);
247
+ if (!text.startsWith(separator)) {
248
+ return null;
249
+ }
250
+ const endIndex = text.indexOf(`
251
+ ${separator}`, separator.length);
252
+ if (endIndex === -1) {
253
+ return null;
254
+ }
255
+ return text.slice(0, endIndex + separator.length + 1);
256
+ }
257
+ /**
258
+ * FrontMatterを除去したbody(titleとdescriptionを含む)
259
+ */
260
+ extractBody(text) {
261
+ const frontMatter = this.extractFrontMatter(text);
262
+ if (!frontMatter) {
263
+ return text;
264
+ }
265
+ return text.slice(frontMatter.length).trim();
266
+ }
267
+ /**
268
+ * タイトル
269
+ */
270
+ extractTitle(text) {
271
+ const body = this.extractBody(text);
272
+ const titleMatch = body.match(/^#\s+(.+)$/m);
273
+ return titleMatch?.[1] ?? null;
274
+ }
275
+ /**
276
+ * 説明(タイトルの後の最初の段落)
277
+ */
278
+ extractDescription(text) {
279
+ const title = this.extractTitle(text);
280
+ if (!title) {
281
+ return null;
282
+ }
283
+ const body = this.extractBody(text);
284
+ const lines = body.split("\n");
285
+ const titleIndex = lines.findIndex((line) => line.match(/^#\s+/));
286
+ if (titleIndex === -1) {
287
+ return null;
288
+ }
289
+ const descIndex = this.skipEmptyLines(lines, titleIndex + 1);
290
+ if (descIndex < lines.length && !lines[descIndex]?.startsWith("#")) {
291
+ return lines[descIndex] ?? null;
292
+ }
293
+ return null;
294
+ }
295
+ /**
296
+ * body内のタイトルを更新
297
+ */
298
+ updateTitle(text, newTitle) {
299
+ const body = this.extractBody(text);
300
+ const lines = body.split("\n");
301
+ const titleIndex = lines.findIndex((line) => line.match(/^#\s+/));
302
+ if (titleIndex !== -1) {
303
+ lines[titleIndex] = `# ${newTitle}`;
304
+ } else {
305
+ lines.unshift(`# ${newTitle}`, "");
306
+ }
307
+ const updatedBody = lines.join("\n");
308
+ const frontMatter = this.extractFrontMatter(text);
309
+ return frontMatter ? `${frontMatter}
310
+ ${updatedBody}` : updatedBody;
311
+ }
312
+ /**
313
+ * body内の説明を更新
314
+ */
315
+ updateDescription(text, newDescription, defaultTitle) {
316
+ const body = this.extractBody(text);
317
+ const lines = body.split("\n");
318
+ const titleIndex = lines.findIndex((line) => line.match(/^#\s+/));
319
+ let updatedBody;
320
+ if (titleIndex === -1) {
321
+ updatedBody = `# ${defaultTitle}
322
+
323
+ ${newDescription}
324
+
325
+ ${body}`.trim();
326
+ } else {
327
+ const descIndex = this.skipEmptyLines(lines, titleIndex + 1);
328
+ if (descIndex < lines.length && lines[descIndex] && !lines[descIndex].startsWith("#")) {
329
+ lines[descIndex] = newDescription;
330
+ } else {
331
+ lines.splice(titleIndex + 1, 0, "", newDescription);
332
+ }
333
+ updatedBody = lines.join("\n");
334
+ }
335
+ const frontMatter = this.extractFrontMatter(text);
336
+ return frontMatter ? `${frontMatter}
337
+ ${updatedBody}` : updatedBody;
338
+ }
339
+ /**
340
+ * 空行をスキップ
341
+ */
342
+ skipEmptyLines(lines, startIndex) {
343
+ let index = startIndex;
344
+ while (index < lines.length) {
345
+ const line = lines[index];
346
+ if (line === void 0 || line.trim() !== "") {
347
+ break;
348
+ }
349
+ index++;
350
+ }
351
+ return index;
352
+ }
353
+ /**
354
+ * Markdownテキストを生成(タイトル + 説明 + body)
355
+ */
356
+ static from(title, description, body) {
357
+ const parts = [];
358
+ if (title) {
359
+ parts.push(`# ${title}`);
360
+ }
361
+ if (description) {
362
+ if (title) parts.push("");
363
+ parts.push(description);
364
+ }
365
+ if (body) {
366
+ if (title || description) parts.push("");
367
+ parts.push(body);
368
+ }
369
+ return parts.join("\n");
370
+ }
371
+ };
372
+
373
+ // lib/values/doc-front-matter-md-value.ts
374
+ import { stringify as stringify2 } from "yaml";
375
+
376
+ // lib/values/doc-content-md-front-matter-value.ts
377
+ import { parse, stringify } from "yaml";
378
+ var DocContentMdFrontMatterValue = class _DocContentMdFrontMatterValue {
379
+ data;
380
+ yamlText;
381
+ constructor(data, yamlText = "") {
382
+ this.data = data;
383
+ this.yamlText = yamlText;
384
+ }
385
+ /**
386
+ * YAMLテキストからフロントマターインスタンスを作成
387
+ */
388
+ static fromYamlText(yamlText) {
389
+ if (!yamlText || typeof yamlText !== "string" || !yamlText.trim()) {
390
+ return new _DocContentMdFrontMatterValue({}, "");
391
+ }
392
+ const parsed = parse(yamlText) || {};
393
+ return new _DocContentMdFrontMatterValue(parsed, yamlText);
394
+ }
395
+ /**
396
+ * Markdownテキストからフロントマターインスタンスを作成
397
+ */
398
+ static fromMarkdown(markdownText) {
399
+ if (!markdownText || !markdownText.startsWith("---")) {
400
+ return _DocContentMdFrontMatterValue.empty();
401
+ }
402
+ const startIndex = markdownText.indexOf("---");
403
+ const endIndex = markdownText.indexOf("---", startIndex + 3);
404
+ if (endIndex === -1) {
405
+ return _DocContentMdFrontMatterValue.empty();
406
+ }
407
+ const yamlText = markdownText.slice(startIndex + 3, endIndex).trim();
408
+ return _DocContentMdFrontMatterValue.fromYamlText(yamlText);
409
+ }
410
+ /**
411
+ * 空のフロントマターインスタンスを作成
412
+ */
413
+ static empty() {
414
+ return new _DocContentMdFrontMatterValue(null, "");
415
+ }
416
+ /**
417
+ * フロントマターデータからインスタンスを作成
418
+ */
419
+ static fromFrontMatter(data) {
420
+ const instance = new _DocContentMdFrontMatterValue(data, "");
421
+ const yamlText = instance.frontMatterText();
422
+ return new _DocContentMdFrontMatterValue(data, yamlText);
423
+ }
424
+ /**
425
+ * フロントマターをYAMLテキストに変換
426
+ */
427
+ frontMatterText() {
428
+ if (this.data === null || Object.keys(this.data).length === 0) return "";
429
+ return stringify(this.data).trim();
430
+ }
431
+ /**
432
+ * フロントマターを更新した新しいインスタンスを作成
433
+ */
434
+ update(draft) {
435
+ const updatedData = { ...this.data || {} };
436
+ for (const [key, value] of Object.entries(draft)) {
437
+ updatedData[key] = value;
438
+ }
439
+ return _DocContentMdFrontMatterValue.fromFrontMatter(updatedData);
440
+ }
441
+ /**
442
+ * フロントマターが空かどうか
443
+ */
444
+ isEmpty() {
445
+ return this.data === null || Object.keys(this.data).length === 0;
446
+ }
447
+ /**
448
+ * 指定したキーの値を取得
449
+ */
450
+ get(key) {
451
+ return this.data?.[key];
452
+ }
453
+ /**
454
+ * 指定したキーが存在するか
455
+ */
456
+ has(key) {
457
+ return this.data !== null && key in this.data;
458
+ }
459
+ /**
460
+ * フロントマターのキー一覧を取得
461
+ */
462
+ keys() {
463
+ return this.data ? Object.keys(this.data) : [];
464
+ }
465
+ };
466
+
467
+ // lib/values/doc-content-md-value.ts
468
+ var DocContentMdValue = class _DocContentMdValue {
469
+ constructor(text) {
470
+ this.text = text;
471
+ }
472
+ /**
473
+ * Front Matter
474
+ */
475
+ get frontMatter() {
476
+ return DocContentMdFrontMatterValue.fromMarkdown(this.text);
477
+ }
478
+ /**
479
+ * body
480
+ */
481
+ get content() {
482
+ if (!this.text || typeof this.text !== "string") {
483
+ return this.text || "";
484
+ }
485
+ if (!this.text.startsWith("---")) {
486
+ return this.text;
487
+ }
488
+ const startIndex = this.text.indexOf("---");
489
+ const endIndex = this.text.indexOf("---", startIndex + 3);
490
+ if (endIndex === -1) {
491
+ return this.text;
492
+ }
493
+ let content = this.text.slice(endIndex + 3);
494
+ if (this.text.slice(endIndex + 3).startsWith("\n\n")) {
495
+ content = `
496
+ ${this.text.slice(endIndex + 4).trim()}`;
497
+ } else {
498
+ content = this.text.slice(endIndex + 3).trim();
499
+ }
500
+ return content.trim();
501
+ }
502
+ /**
503
+ * title
504
+ */
505
+ get title() {
506
+ const content = this.content;
507
+ if (!content || typeof content !== "string") {
508
+ return "";
509
+ }
510
+ const titleMatch = content.match(/^#\s+(.*?)$/m);
511
+ if (!titleMatch || !titleMatch[1]) {
512
+ return "";
513
+ }
514
+ return titleMatch[1].trim();
515
+ }
516
+ /**
517
+ * H1の次の段落、またはH1がない場合は最初の段落をdescriptionとして取得する
518
+ */
519
+ get description() {
520
+ const content = this.content;
521
+ const h1Match = content.match(/^#\s+(.+)$/m);
522
+ let searchContent;
523
+ if (h1Match) {
524
+ const h1EndIndex = (h1Match.index ?? 0) + h1Match[0].length;
525
+ searchContent = content.substring(h1EndIndex);
526
+ } else {
527
+ searchContent = content;
528
+ }
529
+ const paragraphMatch = searchContent.match(
530
+ /^\s*\n*([^#\n*-][^\n]*(?:\n(?![#\s*-])[^\n]*)*)/m
531
+ );
532
+ return paragraphMatch ? paragraphMatch[1]?.trim() ?? null : null;
533
+ }
534
+ /**
535
+ * 新しいフロントマターとコンテンツでMarkdownインスタンスを作成
536
+ */
537
+ static fromProps(props) {
538
+ const contentOpenMarkdown = new _DocContentMdValue(props.content);
539
+ const existingContent = contentOpenMarkdown.content;
540
+ const frontMatterInstance = DocContentMdFrontMatterValue.fromFrontMatter(
541
+ props.frontMatter
542
+ );
543
+ const frontMatterText = frontMatterInstance.frontMatterText();
544
+ let markdownText;
545
+ if (frontMatterText) {
546
+ markdownText = `---
547
+ ${frontMatterText}
548
+ ---
549
+
550
+ ${existingContent}`.trim();
551
+ } else {
552
+ markdownText = existingContent;
553
+ }
554
+ return new _DocContentMdValue(markdownText);
555
+ }
556
+ /**
557
+ * 現在のフロントマターをYAMLテキストに変換する
558
+ */
559
+ frontMatterToText() {
560
+ return this.frontMatter.frontMatterText();
561
+ }
562
+ /**
563
+ * 現在のフロントマターを更新して新しいMarkdownテキストを生成
564
+ */
565
+ updateFrontMatter(draft) {
566
+ const updatedFrontMatter = this.frontMatter.update(draft);
567
+ return _DocContentMdValue.fromProps({
568
+ frontMatter: updatedFrontMatter.data || {},
569
+ content: this.content
570
+ }).text;
571
+ }
572
+ /**
573
+ * 新しいフロントマターでOpenMarkdownインスタンスを作成
574
+ */
575
+ withFrontMatter(frontMatter) {
576
+ return _DocContentMdValue.fromProps({
577
+ frontMatter,
578
+ content: this.content
579
+ });
580
+ }
581
+ /**
582
+ * フロントマターを更新した新しいOpenMarkdownインスタンスを作成
583
+ */
584
+ withUpdatedFrontMatter(draft) {
585
+ const updatedFrontMatter = this.frontMatter.update(draft);
586
+ return this.withFrontMatter(updatedFrontMatter.data || {});
587
+ }
588
+ /**
589
+ * マークダウンをtitle、description、本文の3つの部分に分離する
590
+ */
591
+ parseContentParts() {
592
+ const content = this.content;
593
+ const h1Match = content.match(/^#\s+(.+)$/m);
594
+ if (!h1Match) {
595
+ const paragraphMatch2 = content.match(
596
+ /^(\s*)([^#\n*-][^\n]*(?:\n(?![#\s*-])[^\n]*)*)(.*)/ms
597
+ );
598
+ if (paragraphMatch2) {
599
+ const [, , descriptionPart, remaining] = paragraphMatch2;
600
+ return {
601
+ title: null,
602
+ description: descriptionPart?.trim() ?? "",
603
+ body: remaining?.trim() ?? ""
604
+ };
605
+ }
606
+ return {
607
+ title: null,
608
+ description: null,
609
+ body: content.trim()
610
+ };
611
+ }
612
+ const title = h1Match[1]?.trim() ?? "";
613
+ const h1EndIndex = (h1Match.index ?? 0) + h1Match[0].length;
614
+ const afterH1 = content.substring(h1EndIndex);
615
+ const paragraphMatch = afterH1.match(
616
+ /^(\s*\n*)([^#\n*-][^\n]*(?:\n(?![#\s*-])[^\n]*)*)(.*)/ms
617
+ );
618
+ if (paragraphMatch) {
619
+ const [, , descriptionPart, remaining] = paragraphMatch;
620
+ return {
621
+ title,
622
+ description: descriptionPart?.trim() ?? "",
623
+ body: remaining?.trim() ?? ""
624
+ };
625
+ }
626
+ return {
627
+ title,
628
+ description: null,
629
+ body: afterH1.trim()
630
+ };
631
+ }
632
+ /**
633
+ * title、description、本文からマークダウンを構築する
634
+ */
635
+ buildContent(title, description, body) {
636
+ const parts = [];
637
+ if (title) {
638
+ parts.push(`# ${title}`);
639
+ }
640
+ if (description) {
641
+ parts.push(description);
642
+ }
643
+ if (body) {
644
+ parts.push(body);
645
+ }
646
+ return parts.join("\n\n");
647
+ }
648
+ /**
649
+ * H1タイトルを更新した新しいOpenMarkdownインスタンスを作成
650
+ */
651
+ withTitle(newTitle) {
652
+ const { description, body } = this.parseContentParts();
653
+ const updatedContent = this.buildContent(newTitle, description, body);
654
+ const frontMatterData = this.frontMatter.data !== null ? this.frontMatter.data : {};
655
+ return _DocContentMdValue.fromProps({
656
+ frontMatter: frontMatterData,
657
+ content: updatedContent
658
+ });
659
+ }
660
+ /**
661
+ * H1の次のdescription段落を更新した新しいOpenMarkdownインスタンスを作成
662
+ * @param newDescription 新しいdescription
663
+ * @param defaultTitle H1がない場合に使用するデフォルトタイトル
664
+ */
665
+ withDescription(newDescription, defaultTitle) {
666
+ const { title, body } = this.parseContentParts();
667
+ const finalTitle = title || defaultTitle;
668
+ if (!finalTitle) {
669
+ return this;
670
+ }
671
+ const updatedContent = this.buildContent(finalTitle, newDescription, body);
672
+ const frontMatterData = this.frontMatter.data !== null ? this.frontMatter.data : {};
673
+ return _DocContentMdValue.fromProps({
674
+ frontMatter: frontMatterData,
675
+ content: updatedContent
676
+ });
677
+ }
678
+ };
679
+
680
+ // lib/values/doc-schema-field-boolean-multiple-value.ts
681
+ var DocSchemaFieldBooleanMultipleValue = class {
682
+ constructor(key, value) {
683
+ this.key = key;
684
+ this.value = value;
685
+ Object.freeze(this);
686
+ Object.freeze(this.value);
687
+ if (this.value.default) {
688
+ Object.freeze(this.value.default);
689
+ }
690
+ }
691
+ get type() {
692
+ return this.value.type;
693
+ }
694
+ get required() {
695
+ return this.value.required;
696
+ }
697
+ get title() {
698
+ return this.value.title ?? "";
699
+ }
700
+ get description() {
701
+ return this.value.description ?? "";
702
+ }
703
+ get default() {
704
+ return this.value.default;
705
+ }
706
+ isArray = true;
707
+ isSingle = false;
708
+ isBoolean = true;
709
+ /**
710
+ * 値を検証する
711
+ */
712
+ validate(value) {
713
+ return Array.isArray(value) && value.every((v) => typeof v === "boolean");
714
+ }
715
+ toJson() {
716
+ return { ...this.value };
717
+ }
718
+ };
719
+
720
+ // lib/values/doc-schema-field-boolean-single-value.ts
721
+ var DocSchemaFieldBooleanSingleValue = class {
722
+ constructor(key, value) {
723
+ this.key = key;
724
+ this.value = value;
725
+ Object.freeze(this);
726
+ }
727
+ get type() {
728
+ return this.value.type;
729
+ }
730
+ get required() {
731
+ return this.value.required;
732
+ }
733
+ get title() {
734
+ return this.value.title ?? "";
735
+ }
736
+ get description() {
737
+ return this.value.description ?? "";
738
+ }
739
+ get default() {
740
+ return this.value.default;
741
+ }
742
+ isArray = false;
743
+ isSingle = true;
744
+ isBoolean = true;
745
+ toJson() {
746
+ return { ...this.value };
747
+ }
748
+ /**
749
+ * 値の型を検証する
750
+ */
751
+ validate(value) {
752
+ return typeof value === "boolean";
753
+ }
754
+ };
755
+
756
+ // lib/values/doc-schema-field-number-multiple-value.ts
757
+ var DocSchemaFieldNumberMultipleValue = class {
758
+ constructor(key, value) {
759
+ this.key = key;
760
+ this.value = value;
761
+ Object.freeze(this);
762
+ Object.freeze(this.value);
763
+ if (this.value.default) {
764
+ Object.freeze(this.value.default);
765
+ }
766
+ }
767
+ get type() {
768
+ return this.value.type;
769
+ }
770
+ get required() {
771
+ return this.value.required;
772
+ }
773
+ get title() {
774
+ return this.value.title ?? "";
775
+ }
776
+ get description() {
777
+ return this.value.description ?? "";
778
+ }
779
+ get default() {
780
+ return this.value.default;
781
+ }
782
+ isArray = true;
783
+ isSingle = false;
784
+ isNumber = true;
785
+ /**
786
+ * 値を検証する
787
+ */
788
+ validate(value) {
789
+ return Array.isArray(value) && value.every((v) => typeof v === "number");
790
+ }
791
+ toJson() {
792
+ return { ...this.value };
793
+ }
794
+ };
795
+
796
+ // lib/values/doc-schema-field-number-single-value.ts
797
+ var DocSchemaFieldNumberSingleValue = class {
798
+ constructor(key, value) {
799
+ this.key = key;
800
+ this.value = value;
801
+ Object.freeze(this);
802
+ }
803
+ get type() {
804
+ return this.value.type;
805
+ }
806
+ get required() {
807
+ return this.value.required;
808
+ }
809
+ get title() {
810
+ return this.value.title ?? "";
811
+ }
812
+ get description() {
813
+ return this.value.description ?? "";
814
+ }
815
+ get default() {
816
+ return this.value.default;
817
+ }
818
+ isArray = false;
819
+ isSingle = true;
820
+ isNumber = true;
821
+ toJson() {
822
+ return { ...this.value };
823
+ }
824
+ /**
825
+ * 値の型を検証する
826
+ */
827
+ validate(value) {
828
+ return typeof value === "number";
829
+ }
830
+ };
831
+
832
+ // lib/values/doc-schema-field-relation-multiple-value.ts
833
+ var DocSchemaFieldRelationMultipleValue = class {
834
+ constructor(key, value) {
835
+ this.key = key;
836
+ this.value = value;
837
+ Object.freeze(this.value);
838
+ if (this.value.default && Array.isArray(this.value.default)) {
839
+ Object.freeze(this.value.default);
840
+ }
841
+ Object.freeze(this);
842
+ }
843
+ get type() {
844
+ return this.value.type;
845
+ }
846
+ get required() {
847
+ return this.value.required;
848
+ }
849
+ get title() {
850
+ return this.value.title ?? "";
851
+ }
852
+ get description() {
853
+ return this.value.description ?? "";
854
+ }
855
+ get default() {
856
+ return this.value.default;
857
+ }
858
+ get path() {
859
+ return this.value.path;
860
+ }
861
+ isArray = true;
862
+ isSingle = false;
863
+ isRelation = true;
864
+ /**
865
+ * 値を検証する
866
+ */
867
+ validate(value) {
868
+ return Array.isArray(value) && value.every((v) => typeof v === "string");
869
+ }
870
+ toJson() {
871
+ return { ...this.value };
872
+ }
873
+ };
874
+
875
+ // lib/values/doc-schema-field-relation-single-value.ts
876
+ var DocSchemaFieldRelationSingleValue = class {
877
+ constructor(key, value) {
878
+ this.key = key;
879
+ this.value = value;
880
+ Object.freeze(this);
881
+ }
882
+ get type() {
883
+ return this.value.type;
884
+ }
885
+ get required() {
886
+ return this.value.required;
887
+ }
888
+ get title() {
889
+ return this.value.title ?? "";
890
+ }
891
+ get description() {
892
+ return this.value.description ?? "";
893
+ }
894
+ get default() {
895
+ return this.value.default;
896
+ }
897
+ get path() {
898
+ return this.value.path;
899
+ }
900
+ isArray = false;
901
+ isSingle = true;
902
+ isRelation = true;
903
+ toJson() {
904
+ return { ...this.value };
905
+ }
906
+ /**
907
+ * 値の型を検証する
908
+ */
909
+ validate(value) {
910
+ return typeof value === "string";
911
+ }
912
+ };
913
+
914
+ // lib/values/doc-schema-field-select-number-multiple-value.ts
915
+ var DocSchemaFieldSelectNumberMultipleValue = class {
916
+ constructor(key, value) {
917
+ this.key = key;
918
+ this.value = value;
919
+ Object.freeze(this);
920
+ Object.freeze(this.value);
921
+ Object.freeze(this.value.options);
922
+ if (this.value.default && Array.isArray(this.value.default)) {
923
+ Object.freeze(this.value.default);
924
+ }
925
+ }
926
+ get type() {
927
+ return this.value.type;
928
+ }
929
+ get required() {
930
+ return this.value.required;
931
+ }
932
+ get title() {
933
+ return this.value.title ?? "";
934
+ }
935
+ get description() {
936
+ return this.value.description ?? "";
937
+ }
938
+ get default() {
939
+ return this.value.default;
940
+ }
941
+ get options() {
942
+ return this.value.options;
943
+ }
944
+ isArray = true;
945
+ isSingle = false;
946
+ isSelect = true;
947
+ isNumberSelect = true;
948
+ /**
949
+ * 値を検証する
950
+ */
951
+ validate(value) {
952
+ return Array.isArray(value) && value.every((v) => typeof v === "number");
953
+ }
954
+ toJson() {
955
+ return { ...this.value };
956
+ }
957
+ };
958
+
959
+ // lib/values/doc-schema-field-select-number-single-value.ts
960
+ var DocSchemaFieldSelectNumberSingleValue = class {
961
+ constructor(key, value) {
962
+ this.key = key;
963
+ this.value = value;
964
+ Object.freeze(this);
965
+ Object.freeze(this.value);
966
+ Object.freeze(this.value.options);
967
+ }
968
+ get type() {
969
+ return this.value.type;
970
+ }
971
+ get required() {
972
+ return this.value.required;
973
+ }
974
+ get title() {
975
+ return this.value.title ?? "";
976
+ }
977
+ get description() {
978
+ return this.value.description ?? "";
979
+ }
980
+ get default() {
981
+ return this.value.default;
982
+ }
983
+ get options() {
984
+ return this.value.options;
985
+ }
986
+ isArray = false;
987
+ isSingle = true;
988
+ isSelect = true;
989
+ isNumberSelect = true;
990
+ /**
991
+ * 値を検証する
992
+ */
993
+ validate(value) {
994
+ return typeof value === "number";
995
+ }
996
+ toJson() {
997
+ return { ...this.value };
998
+ }
999
+ };
1000
+
1001
+ // lib/values/doc-schema-field-select-text-multiple-value.ts
1002
+ var DocSchemaFieldSelectTextMultipleValue = class {
1003
+ constructor(key, value) {
1004
+ this.key = key;
1005
+ this.value = value;
1006
+ Object.freeze(this);
1007
+ Object.freeze(this.value);
1008
+ Object.freeze(this.value.options);
1009
+ if (this.value.default && Array.isArray(this.value.default)) {
1010
+ Object.freeze(this.value.default);
1011
+ }
1012
+ }
1013
+ get type() {
1014
+ return this.value.type;
1015
+ }
1016
+ get required() {
1017
+ return this.value.required;
1018
+ }
1019
+ get title() {
1020
+ return this.value.title ?? "";
1021
+ }
1022
+ get description() {
1023
+ return this.value.description ?? "";
1024
+ }
1025
+ get default() {
1026
+ return this.value.default;
1027
+ }
1028
+ get options() {
1029
+ return this.value.options;
1030
+ }
1031
+ isArray = true;
1032
+ isSingle = false;
1033
+ isSelect = true;
1034
+ isTextSelect = true;
1035
+ /**
1036
+ * 値を検証する
1037
+ */
1038
+ validate(value) {
1039
+ return Array.isArray(value) && value.every((v) => typeof v === "string");
1040
+ }
1041
+ toJson() {
1042
+ return { ...this.value };
1043
+ }
1044
+ };
1045
+
1046
+ // lib/values/doc-schema-field-select-text-single-value.ts
1047
+ var DocSchemaFieldSelectTextSingleValue = class {
1048
+ constructor(key, value) {
1049
+ this.key = key;
1050
+ this.value = value;
1051
+ if (this.value.options) {
1052
+ Object.freeze(this.value.options);
1053
+ }
1054
+ Object.freeze(this.value);
1055
+ Object.freeze(this);
1056
+ }
1057
+ get type() {
1058
+ return this.value.type;
1059
+ }
1060
+ get required() {
1061
+ return this.value.required;
1062
+ }
1063
+ get title() {
1064
+ return this.value.title ?? "";
1065
+ }
1066
+ get description() {
1067
+ return this.value.description ?? "";
1068
+ }
1069
+ get default() {
1070
+ return this.value.default;
1071
+ }
1072
+ get options() {
1073
+ return this.value.options;
1074
+ }
1075
+ isArray = false;
1076
+ isSingle = true;
1077
+ isSelect = true;
1078
+ isTextSelect = true;
1079
+ toJson() {
1080
+ return { ...this.value };
1081
+ }
1082
+ /**
1083
+ * 値の型を検証する
1084
+ */
1085
+ validate(value) {
1086
+ return typeof value === "string";
1087
+ }
1088
+ };
1089
+
1090
+ // lib/values/doc-schema-field-text-multiple-value.ts
1091
+ var DocSchemaFieldTextMultipleValue = class {
1092
+ constructor(key, value) {
1093
+ this.key = key;
1094
+ this.value = value;
1095
+ Object.freeze(this);
1096
+ Object.freeze(this.value);
1097
+ if (this.value.default) {
1098
+ Object.freeze(this.value.default);
1099
+ }
1100
+ }
1101
+ get type() {
1102
+ return this.value.type;
1103
+ }
1104
+ get required() {
1105
+ return this.value.required;
1106
+ }
1107
+ get title() {
1108
+ return this.value.title ?? "";
1109
+ }
1110
+ get description() {
1111
+ return this.value.description ?? "";
1112
+ }
1113
+ get default() {
1114
+ return this.value.default;
1115
+ }
1116
+ isArray = true;
1117
+ isSingle = false;
1118
+ isText = true;
1119
+ toJson() {
1120
+ return { ...this.value };
1121
+ }
1122
+ /**
1123
+ * 値の型を検証する
1124
+ */
1125
+ validate(value) {
1126
+ return Array.isArray(value) && value.every((v) => typeof v === "string");
1127
+ }
1128
+ };
1129
+
1130
+ // lib/values/doc-schema-field-text-single-value.ts
1131
+ var DocSchemaFieldTextSingleValue = class {
1132
+ constructor(key, value) {
1133
+ this.key = key;
1134
+ this.value = value;
1135
+ Object.freeze(this);
1136
+ }
1137
+ get type() {
1138
+ return this.value.type;
1139
+ }
1140
+ get required() {
1141
+ return this.value.required;
1142
+ }
1143
+ get title() {
1144
+ return this.value.title ?? "";
1145
+ }
1146
+ get description() {
1147
+ return this.value.description ?? "";
1148
+ }
1149
+ get default() {
1150
+ return this.value.default;
1151
+ }
1152
+ isArray = false;
1153
+ isSingle = true;
1154
+ isText = true;
1155
+ toJson() {
1156
+ return { ...this.value };
1157
+ }
1158
+ /**
1159
+ * 値の型を検証する
1160
+ */
1161
+ validate(value) {
1162
+ return typeof value === "string";
1163
+ }
1164
+ };
1165
+
1166
+ // lib/values/doc-schema-field-type-value.ts
1167
+ var DocSchemaFieldTypeValue = class _DocSchemaFieldTypeValue {
1168
+ constructor(value) {
1169
+ this.value = value;
1170
+ zDocSchemaFieldType.parse(value);
1171
+ Object.freeze(this);
1172
+ }
1173
+ /**
1174
+ * タイプ値を取得
1175
+ */
1176
+ get type() {
1177
+ return this.value;
1178
+ }
1179
+ /**
1180
+ * テキスト型かどうか
1181
+ */
1182
+ get isText() {
1183
+ return this.value === "text";
1184
+ }
1185
+ /**
1186
+ * 数値型かどうか
1187
+ */
1188
+ get isNumber() {
1189
+ return this.value === "number";
1190
+ }
1191
+ /**
1192
+ * ブール型かどうか
1193
+ */
1194
+ get isBoolean() {
1195
+ return this.value === "boolean";
1196
+ }
1197
+ /**
1198
+ * 選択型(単一)かどうか
1199
+ */
1200
+ get isSelect() {
1201
+ return this.value === "select-text" || this.value === "select-number";
1202
+ }
1203
+ /**
1204
+ * リレーション型かどうか
1205
+ */
1206
+ get isRelation() {
1207
+ return this.value === "relation" || this.value === "multi-relation";
1208
+ }
1209
+ /**
1210
+ * 配列型かどうか
1211
+ */
1212
+ get isArray() {
1213
+ return this.value === "multi-text" || this.value === "multi-number" || this.value === "multi-boolean" || this.value === "multi-relation" || this.value === "multi-select-text" || this.value === "multi-select-number";
1214
+ }
1215
+ /**
1216
+ * 単一値型かどうか
1217
+ */
1218
+ get isSingle() {
1219
+ return !this.isArray;
1220
+ }
1221
+ /**
1222
+ * 基本型を取得(multi-textの場合はtext)
1223
+ */
1224
+ get baseType() {
1225
+ if (this.value.startsWith("multi-")) {
1226
+ return this.value.replace("multi-", "");
1227
+ }
1228
+ if (this.value.startsWith("select-")) {
1229
+ return this.value.replace("select-", "");
1230
+ }
1231
+ return this.value;
1232
+ }
1233
+ /**
1234
+ * デフォルト値を取得
1235
+ */
1236
+ getDefaultValue() {
1237
+ if (this.isArray) return [];
1238
+ if (this.isText) return "";
1239
+ if (this.isNumber) return 0;
1240
+ if (this.isBoolean) return false;
1241
+ if (this.isRelation) return "";
1242
+ return "";
1243
+ }
1244
+ /**
1245
+ * 値の検証
1246
+ */
1247
+ validateValue(value) {
1248
+ if (this.isArray) {
1249
+ if (!Array.isArray(value)) return false;
1250
+ const baseType = this.baseType;
1251
+ return value.every((item) => {
1252
+ if (baseType === "text") return typeof item === "string";
1253
+ if (baseType === "number") return typeof item === "number";
1254
+ if (baseType === "boolean") return typeof item === "boolean";
1255
+ return true;
1256
+ });
1257
+ }
1258
+ if (this.isText) return typeof value === "string";
1259
+ if (this.isNumber) return typeof value === "number";
1260
+ if (this.isBoolean) return typeof value === "boolean";
1261
+ if (this.isRelation) return typeof value === "string";
1262
+ return true;
1263
+ }
1264
+ /**
1265
+ * 文字列から生成
1266
+ */
1267
+ static from(type) {
1268
+ const validatedType = zDocSchemaFieldType.parse(type);
1269
+ return new _DocSchemaFieldTypeValue(validatedType);
1270
+ }
1271
+ /**
1272
+ * JSON形式に変換
1273
+ */
1274
+ toJson() {
1275
+ return this.value;
1276
+ }
1277
+ };
1278
+
1279
+ // lib/values/doc-schema-field-factory.ts
1280
+ var DocSchemaFieldFactory = class {
1281
+ constructor() {
1282
+ Object.freeze(this);
1283
+ }
1284
+ /**
1285
+ * スキーマエントリから適切な型のフィールドを生成
1286
+ */
1287
+ fromSchemaEntry(key, field) {
1288
+ if (field.type === "text") {
1289
+ return new DocSchemaFieldTextSingleValue(key, field);
1290
+ }
1291
+ if (field.type === "multi-text") {
1292
+ return new DocSchemaFieldTextMultipleValue(key, field);
1293
+ }
1294
+ if (field.type === "number") {
1295
+ return new DocSchemaFieldNumberSingleValue(key, field);
1296
+ }
1297
+ if (field.type === "multi-number") {
1298
+ return new DocSchemaFieldNumberMultipleValue(key, field);
1299
+ }
1300
+ if (field.type === "boolean") {
1301
+ return new DocSchemaFieldBooleanSingleValue(key, field);
1302
+ }
1303
+ if (field.type === "multi-boolean") {
1304
+ return new DocSchemaFieldBooleanMultipleValue(key, field);
1305
+ }
1306
+ if (field.type === "select-text") {
1307
+ return new DocSchemaFieldSelectTextSingleValue(key, field);
1308
+ }
1309
+ if (field.type === "select-number") {
1310
+ return new DocSchemaFieldSelectNumberSingleValue(key, field);
1311
+ }
1312
+ if (field.type === "multi-select-text") {
1313
+ return new DocSchemaFieldSelectTextMultipleValue(key, field);
1314
+ }
1315
+ if (field.type === "multi-select-number") {
1316
+ return new DocSchemaFieldSelectNumberMultipleValue(key, field);
1317
+ }
1318
+ if (field.type === "relation") {
1319
+ return new DocSchemaFieldRelationSingleValue(key, field);
1320
+ }
1321
+ if (field.type === "multi-relation") {
1322
+ return new DocSchemaFieldRelationMultipleValue(key, field);
1323
+ }
1324
+ throw new Error("Unknown field type");
1325
+ }
1326
+ /**
1327
+ * 未検証のデータから正規化して生成
1328
+ */
1329
+ fromUnknown(key, data) {
1330
+ const normalized = this.normalizeField(data);
1331
+ const validated = zDocSchemaField.parse(normalized);
1332
+ return this.fromSchemaEntry(key, validated);
1333
+ }
1334
+ /**
1335
+ * フィールド定義を正規化
1336
+ */
1337
+ normalizeField(field) {
1338
+ if (!field || typeof field !== "object") {
1339
+ return this.createDefaultTextField();
1340
+ }
1341
+ const fieldType = this.getFieldProperty(field, "type");
1342
+ const fieldRequired = this.getFieldProperty(field, "required");
1343
+ const fieldTitle = this.getFieldProperty(field, "title");
1344
+ const fieldDescription = this.getFieldProperty(field, "description");
1345
+ const fieldDefault = this.getFieldProperty(field, "default");
1346
+ const normalizedType = this.normalizeType(fieldType);
1347
+ const typeValue = DocSchemaFieldTypeValue.from(normalizedType);
1348
+ const baseField = {
1349
+ type: normalizedType,
1350
+ required: fieldRequired ?? false,
1351
+ title: fieldTitle,
1352
+ description: fieldDescription,
1353
+ default: fieldDefault
1354
+ };
1355
+ return {
1356
+ ...baseField,
1357
+ ...this.getTypeSpecificDefaults(field, typeValue)
1358
+ };
1359
+ }
1360
+ /**
1361
+ * デフォルトのテキストフィールドを作成
1362
+ */
1363
+ createDefaultTextField() {
1364
+ return {
1365
+ type: "text",
1366
+ required: false,
1367
+ title: "",
1368
+ description: "",
1369
+ default: ""
1370
+ };
1371
+ }
1372
+ /**
1373
+ * 型名を正規化
1374
+ */
1375
+ normalizeType(type) {
1376
+ if (typeof type !== "string") return "text";
1377
+ if (type === "string") return "text";
1378
+ if (type === "multi-string") return "multi-text";
1379
+ return type;
1380
+ }
1381
+ /**
1382
+ * オブジェクトからプロパティを安全に取得
1383
+ */
1384
+ getFieldProperty(obj, key) {
1385
+ if (Object.hasOwn(obj, key)) {
1386
+ return Object.getOwnPropertyDescriptor(obj, key)?.value;
1387
+ }
1388
+ return null;
1389
+ }
1390
+ /**
1391
+ * 型固有のデフォルト値を取得(イミュータブル)
1392
+ */
1393
+ getTypeSpecificDefaults(field, fieldType) {
1394
+ const defaults = {};
1395
+ if (fieldType.isRelation) {
1396
+ defaults.path = this.getFieldProperty(field, "path") ?? "";
1397
+ }
1398
+ if (fieldType.isSelect) {
1399
+ defaults.options = this.getFieldProperty(field, "options") ?? [];
1400
+ }
1401
+ return defaults;
1402
+ }
1403
+ };
1404
+
1405
+ // lib/values/doc-front-matter-md-value.ts
1406
+ var DocFrontMatterMdValue = class _DocFrontMatterMdValue {
1407
+ constructor(value) {
1408
+ this.value = value;
1409
+ zDocFileMdFrontMatter.parse(value);
1410
+ Object.freeze(this);
1411
+ }
1412
+ toJson() {
1413
+ return this.value;
1414
+ }
1415
+ toYaml() {
1416
+ return stringify2(this.value).trim();
1417
+ }
1418
+ /**
1419
+ * Markdownテキストから生成
1420
+ */
1421
+ static from(markdownText) {
1422
+ const openMarkdown = new DocContentMdValue(markdownText);
1423
+ const rawData = openMarkdown.frontMatter.data || {};
1424
+ const data = zDocFileMdFrontMatter.parse(rawData);
1425
+ return new _DocFrontMatterMdValue(data);
1426
+ }
1427
+ /**
1428
+ * 空のFrontMatterを生成
1429
+ */
1430
+ static empty() {
1431
+ return new _DocFrontMatterMdValue({});
1432
+ }
1433
+ /**
1434
+ * データから直接生成
1435
+ */
1436
+ static fromData(data) {
1437
+ const validatedData = zDocFileMdFrontMatter.parse(data);
1438
+ return new _DocFrontMatterMdValue(validatedData);
1439
+ }
1440
+ /**
1441
+ * スキーマフィールドに基づいてデフォルト値を生成する
1442
+ */
1443
+ static generateDefaultValueFromSchemaField(fieldDef) {
1444
+ if (fieldDef.type === "text") {
1445
+ return fieldDef.default ?? "";
1446
+ }
1447
+ if (fieldDef.type === "boolean") {
1448
+ return fieldDef.default ?? false;
1449
+ }
1450
+ if (fieldDef.type === "number") {
1451
+ return fieldDef.default ?? 0;
1452
+ }
1453
+ if (fieldDef.type === "multi-text" || fieldDef.type === "multi-number" || fieldDef.type === "multi-boolean" || fieldDef.type === "multi-relation") {
1454
+ return fieldDef.default ?? [];
1455
+ }
1456
+ if (fieldDef.type === "relation") {
1457
+ return fieldDef.default ?? null;
1458
+ }
1459
+ return null;
1460
+ }
1461
+ /**
1462
+ * 単一のプロパティを更新した新しいインスタンスを返す
1463
+ * スキーマに基づいて型を検証し、スキーマのフィールドのみを含む新しいインスタンスを生成
1464
+ */
1465
+ withProperty(key, value, schema) {
1466
+ const currentData = this.toJson();
1467
+ const fieldValue = schema.field(key);
1468
+ if (fieldValue === null) {
1469
+ return this;
1470
+ }
1471
+ if (!this.validateFieldValue(key, value, fieldValue)) {
1472
+ return this;
1473
+ }
1474
+ const draft = {};
1475
+ for (const field of schema.fields) {
1476
+ const fieldKey = field.key;
1477
+ if (fieldKey === key) {
1478
+ draft[fieldKey] = value;
1479
+ } else if (fieldKey in currentData) {
1480
+ const value2 = currentData[fieldKey];
1481
+ if (value2 !== void 0) {
1482
+ draft[fieldKey] = value2;
1483
+ }
1484
+ } else {
1485
+ draft[fieldKey] = field.toJson().default;
1486
+ }
1487
+ }
1488
+ return new _DocFrontMatterMdValue(draft);
1489
+ }
1490
+ /**
1491
+ * フィールド値の検証
1492
+ */
1493
+ validateFieldValue(key, value, fieldDef) {
1494
+ try {
1495
+ const factory = new DocSchemaFieldFactory();
1496
+ const schemaField = factory.fromSchemaEntry(key, fieldDef);
1497
+ return schemaField.validate(value);
1498
+ } catch {
1499
+ return false;
1500
+ }
1501
+ }
1502
+ /**
1503
+ * テキスト型のプロパティを取得
1504
+ */
1505
+ text(key) {
1506
+ const value = this.value[key];
1507
+ const validator = new DocSchemaFieldTextSingleValue(key, {
1508
+ type: "text",
1509
+ required: false,
1510
+ title: null,
1511
+ description: null,
1512
+ default: null
1513
+ });
1514
+ return validator.validate(value) && typeof value === "string" ? value : null;
1515
+ }
1516
+ /**
1517
+ * 数値型のプロパティを取得
1518
+ */
1519
+ number(key) {
1520
+ const value = this.value[key];
1521
+ const validator = new DocSchemaFieldNumberSingleValue(key, {
1522
+ type: "number",
1523
+ required: false,
1524
+ title: null,
1525
+ description: null,
1526
+ default: null
1527
+ });
1528
+ return validator.validate(value) && typeof value === "number" ? value : null;
1529
+ }
1530
+ /**
1531
+ * 真偽値型のプロパティを取得
1532
+ */
1533
+ boolean(key) {
1534
+ const value = this.value[key];
1535
+ const validator = new DocSchemaFieldBooleanSingleValue(key, {
1536
+ type: "boolean",
1537
+ required: false,
1538
+ title: null,
1539
+ description: null,
1540
+ default: null
1541
+ });
1542
+ return validator.validate(value) && typeof value === "boolean" ? value : null;
1543
+ }
1544
+ /**
1545
+ * 単一リレーション型のプロパティを取得
1546
+ */
1547
+ relation(key) {
1548
+ const value = this.value[key];
1549
+ const validator = new DocSchemaFieldTextSingleValue(key, {
1550
+ type: "text",
1551
+ required: false,
1552
+ title: null,
1553
+ description: null,
1554
+ default: null
1555
+ });
1556
+ return validator.validate(value) && typeof value === "string" ? value : null;
1557
+ }
1558
+ /**
1559
+ * 複数リレーション型のプロパティを取得
1560
+ */
1561
+ multiRelation(key) {
1562
+ const value = this.value[key];
1563
+ const validator = new DocSchemaFieldTextMultipleValue(key, {
1564
+ type: "multi-text",
1565
+ required: false,
1566
+ title: null,
1567
+ description: null,
1568
+ default: null
1569
+ });
1570
+ return validator.validate(value) && Array.isArray(value) ? value : [];
1571
+ }
1572
+ /**
1573
+ * 複数テキスト型のプロパティを取得
1574
+ */
1575
+ multiText(key) {
1576
+ const value = this.value[key];
1577
+ const validator = new DocSchemaFieldTextMultipleValue(key, {
1578
+ type: "multi-text",
1579
+ required: false,
1580
+ title: null,
1581
+ description: null,
1582
+ default: null
1583
+ });
1584
+ return validator.validate(value) && Array.isArray(value) ? value : [];
1585
+ }
1586
+ /**
1587
+ * 複数数値型のプロパティを取得
1588
+ */
1589
+ multiNumber(key) {
1590
+ const value = this.value[key];
1591
+ const validator = new DocSchemaFieldNumberMultipleValue(key, {
1592
+ type: "multi-number",
1593
+ required: false,
1594
+ title: null,
1595
+ description: null,
1596
+ default: null
1597
+ });
1598
+ return validator.validate(value) && Array.isArray(value) ? value : [];
1599
+ }
1600
+ /**
1601
+ * 複数真偽値型のプロパティを取得
1602
+ */
1603
+ multiBoolean(key) {
1604
+ const value = this.value[key];
1605
+ const validator = new DocSchemaFieldBooleanMultipleValue(key, {
1606
+ type: "multi-boolean",
1607
+ required: false,
1608
+ title: null,
1609
+ description: null,
1610
+ default: null
1611
+ });
1612
+ return validator.validate(value) && Array.isArray(value) ? value : [];
1613
+ }
1614
+ /**
1615
+ * プロパティが存在するかチェック
1616
+ */
1617
+ has(key) {
1618
+ return key in this.value && this.value[key] !== void 0;
1619
+ }
1620
+ /**
1621
+ * すべてのキーを取得
1622
+ */
1623
+ get keys() {
1624
+ return Object.keys(this.value);
1625
+ }
1626
+ };
1627
+
1628
+ // lib/values/doc-file-content-md-value.ts
1629
+ var DocFileContentMdValue = class _DocFileContentMdValue {
1630
+ constructor(value) {
1631
+ this.value = value;
1632
+ zDocFileContentMd.parse(value);
1633
+ Object.freeze(this);
1634
+ }
1635
+ /**
1636
+ * コンテンツ本文(frontMatterを含まない)
1637
+ */
1638
+ get body() {
1639
+ return this.value.body;
1640
+ }
1641
+ /**
1642
+ * タイトル
1643
+ */
1644
+ get title() {
1645
+ return this.value.title;
1646
+ }
1647
+ /**
1648
+ * 説明
1649
+ */
1650
+ get description() {
1651
+ return this.value.description;
1652
+ }
1653
+ /**
1654
+ * FrontMatter
1655
+ */
1656
+ get frontMatter() {
1657
+ return new DocFrontMatterMdValue(this.value.frontMatter);
1658
+ }
1659
+ /**
1660
+ * タイトルを更新
1661
+ */
1662
+ withTitle(title) {
1663
+ const fullText = this.toText();
1664
+ const engine = new DocMarkdownSystem();
1665
+ const updatedText = engine.updateTitle(fullText, title);
1666
+ const updatedBody = engine.extractBody(updatedText);
1667
+ return new _DocFileContentMdValue({
1668
+ type: "markdown-content",
1669
+ body: updatedBody,
1670
+ title,
1671
+ description: this.description,
1672
+ frontMatter: this.value.frontMatter
1673
+ });
1674
+ }
1675
+ /**
1676
+ * 説明を更新
1677
+ */
1678
+ withDescription(description, defaultTitle) {
1679
+ const fullText = this.toText();
1680
+ const engine = new DocMarkdownSystem();
1681
+ const updatedText = engine.updateDescription(
1682
+ fullText,
1683
+ description,
1684
+ defaultTitle || this.title
1685
+ );
1686
+ const updatedBody = engine.extractBody(updatedText);
1687
+ return new _DocFileContentMdValue({
1688
+ type: "markdown-content",
1689
+ body: updatedBody,
1690
+ title: this.title,
1691
+ description,
1692
+ frontMatter: this.value.frontMatter
1693
+ });
1694
+ }
1695
+ /**
1696
+ * コンテンツを更新
1697
+ */
1698
+ withContent(content) {
1699
+ const engine = new DocMarkdownSystem();
1700
+ return new _DocFileContentMdValue({
1701
+ type: "markdown-content",
1702
+ body: content,
1703
+ title: engine.extractTitle(content) || "",
1704
+ description: engine.extractDescription(content) || "",
1705
+ frontMatter: this.value.frontMatter
1706
+ });
1707
+ }
1708
+ /**
1709
+ * FrontMatterを更新
1710
+ */
1711
+ withFrontMatter(frontMatter) {
1712
+ return new _DocFileContentMdValue({
1713
+ type: "markdown-content",
1714
+ body: this.body,
1715
+ title: this.title,
1716
+ description: this.description,
1717
+ frontMatter: frontMatter.value
1718
+ });
1719
+ }
1720
+ /**
1721
+ * Markdownテキストから生成
1722
+ */
1723
+ static fromMarkdown(markdown) {
1724
+ const engine = new DocMarkdownSystem();
1725
+ const frontMatter = DocFrontMatterMdValue.from(markdown);
1726
+ return new _DocFileContentMdValue({
1727
+ type: "markdown-content",
1728
+ body: engine.extractBody(markdown),
1729
+ title: engine.extractTitle(markdown) || "",
1730
+ description: engine.extractDescription(markdown) || "",
1731
+ frontMatter: frontMatter.value
1732
+ });
1733
+ }
1734
+ /**
1735
+ * 完全なMarkdownテキストを生成
1736
+ */
1737
+ toMarkdownText() {
1738
+ return DocMarkdownSystem.from(this.title, this.description, this.body);
1739
+ }
1740
+ /**
1741
+ * FrontMatterとbodyを結合した完全なテキストを生成
1742
+ */
1743
+ toText() {
1744
+ return `---
1745
+ ${this.frontMatter.toYaml()}
1746
+ ---
1747
+
1748
+ ${this.body}`;
1749
+ }
1750
+ /**
1751
+ * 空のコンテンツを生成
1752
+ */
1753
+ static empty(title) {
1754
+ return new _DocFileContentMdValue({
1755
+ type: "markdown-content",
1756
+ body: `# ${title}`,
1757
+ title,
1758
+ description: "",
1759
+ frontMatter: {}
1760
+ });
1761
+ }
1762
+ /**
1763
+ * JSON形式で出力
1764
+ */
1765
+ toJson() {
1766
+ return this.value;
1767
+ }
1768
+ };
1769
+
1770
+ // lib/entities/doc-file-md-entity.ts
1771
+ var DocFileMdEntity = class _DocFileMdEntity {
1772
+ constructor(value) {
1773
+ this.value = value;
1774
+ zDocFileMd.parse(value);
1775
+ Object.freeze(this);
1776
+ }
1777
+ /**
1778
+ * コンテンツ
1779
+ */
1780
+ get content() {
1781
+ return new DocFileContentMdValue(this.value.content);
1782
+ }
1783
+ /**
1784
+ * パス情報
1785
+ */
1786
+ get path() {
1787
+ return this.value.path;
1788
+ }
1789
+ /**
1790
+ * コンテンツを更新
1791
+ */
1792
+ withContent(content) {
1793
+ return new _DocFileMdEntity({
1794
+ ...this.value,
1795
+ content: content.value
1796
+ });
1797
+ }
1798
+ /**
1799
+ * パスを更新
1800
+ */
1801
+ withPath(path) {
1802
+ return new _DocFileMdEntity({
1803
+ ...this.value,
1804
+ path
1805
+ });
1806
+ }
1807
+ /**
1808
+ * JSON形式に変換
1809
+ */
1810
+ toJson() {
1811
+ return this.value;
1812
+ }
1813
+ };
1814
+
1815
+ // lib/values/doc-file-path-value.ts
1816
+ var DocFilePathValue = class _DocFilePathValue {
1817
+ constructor(value, pathSystem) {
1818
+ this.value = value;
1819
+ zDocFilePath.parse(value);
1820
+ this.pathSystem = pathSystem;
1821
+ Object.freeze(this);
1822
+ }
1823
+ pathSystem;
1824
+ /**
1825
+ * ファイル名(拡張子なし)
1826
+ */
1827
+ get name() {
1828
+ return this.value.name;
1829
+ }
1830
+ /**
1831
+ * ファイルパス(相対パス)
1832
+ */
1833
+ get path() {
1834
+ return this.value.path;
1835
+ }
1836
+ /**
1837
+ * ファイル名(拡張子付き)
1838
+ */
1839
+ get nameWithExtension() {
1840
+ return this.value.nameWithExtension;
1841
+ }
1842
+ /**
1843
+ * フルパス(絶対パス)
1844
+ */
1845
+ get fullPath() {
1846
+ return this.value.fullPath;
1847
+ }
1848
+ /**
1849
+ * ディレクトリパス
1850
+ */
1851
+ get directoryPath() {
1852
+ return this.pathSystem.dirname(this.path);
1853
+ }
1854
+ /**
1855
+ * 拡張子
1856
+ */
1857
+ get extension() {
1858
+ return this.pathSystem.extname(this.nameWithExtension);
1859
+ }
1860
+ /**
1861
+ * アーカイブされているかどうか
1862
+ */
1863
+ get isArchived() {
1864
+ return this.path.includes("/.archive/");
1865
+ }
1866
+ /**
1867
+ * 相対パスからインスタンスを生成(DI対応)
1868
+ */
1869
+ static fromPathWithSystem(filePath, pathSystem, basePath) {
1870
+ const nameWithExtension = pathSystem.basename(filePath);
1871
+ let name = pathSystem.basename(filePath, pathSystem.extname(filePath));
1872
+ if (name === "index" && filePath.includes("/")) {
1873
+ const parentDir = pathSystem.dirname(filePath);
1874
+ name = pathSystem.basename(parentDir);
1875
+ }
1876
+ const fullPath = basePath ? pathSystem.join(basePath, filePath) : pathSystem.resolve(filePath);
1877
+ return new _DocFilePathValue(
1878
+ {
1879
+ name,
1880
+ path: filePath,
1881
+ fullPath,
1882
+ nameWithExtension
1883
+ },
1884
+ pathSystem
1885
+ );
1886
+ }
1887
+ /**
1888
+ * JSON形式で出力
1889
+ */
1890
+ toJson() {
1891
+ return this.value;
1892
+ }
1893
+ };
1894
+
1895
+ // lib/values/doc-relation-file-value.ts
1896
+ var DocRelationFileValue = class _DocRelationFileValue {
1897
+ constructor(value) {
1898
+ this.value = value;
1899
+ zDocRelationFile.parse(value);
1900
+ Object.freeze(this);
1901
+ Object.freeze(this.value);
1902
+ }
1903
+ /**
1904
+ * ファイルパス
1905
+ */
1906
+ get id() {
1907
+ return this.value.name;
1908
+ }
1909
+ /**
1910
+ * スラッグ
1911
+ */
1912
+ get slug() {
1913
+ return this.value.name;
1914
+ }
1915
+ /**
1916
+ * 表示用ラベル
1917
+ */
1918
+ get label() {
1919
+ return this.value.label || this.value.name;
1920
+ }
1921
+ /**
1922
+ * ファイルパスとタイトルから生成
1923
+ */
1924
+ static from(filePath, title) {
1925
+ const fileName = _DocRelationFileValue.extractFileName(filePath);
1926
+ return new _DocRelationFileValue({
1927
+ name: fileName,
1928
+ label: title || fileName,
1929
+ value: null,
1930
+ path: null
1931
+ });
1932
+ }
1933
+ /**
1934
+ * ファイルパスからファイル名を抽出(拡張子なし)
1935
+ */
1936
+ static extractFileName(filePath) {
1937
+ return filePath.split("/").pop()?.replace(".md", "") || filePath;
1938
+ }
1939
+ /**
1940
+ * JSON形式に変換
1941
+ */
1942
+ toJson() {
1943
+ return { ...this.value };
1944
+ }
1945
+ };
1946
+
1947
+ // lib/values/doc-relation-value.ts
1948
+ var DocRelationValue = class _DocRelationValue {
1949
+ constructor(value) {
1950
+ this.value = value;
1951
+ zDocRelation.parse(value);
1952
+ Object.freeze(this);
1953
+ Object.freeze(this.value);
1954
+ }
1955
+ /**
1956
+ * リレーションパス
1957
+ */
1958
+ get path() {
1959
+ return this.value.path;
1960
+ }
1961
+ /**
1962
+ * リレーション対象ファイル一覧(値オブジェクト)
1963
+ */
1964
+ get files() {
1965
+ return this.value.files.map((file) => new DocRelationFileValue(file));
1966
+ }
1967
+ /**
1968
+ * ファイル数を取得
1969
+ */
1970
+ get fileCount() {
1971
+ return this.files.length;
1972
+ }
1973
+ /**
1974
+ * 空かどうか
1975
+ */
1976
+ get isEmpty() {
1977
+ return this.files.length === 0;
1978
+ }
1979
+ /**
1980
+ * 空のリレーションエンティティを作成
1981
+ */
1982
+ static empty(path) {
1983
+ return new _DocRelationValue({
1984
+ path,
1985
+ files: []
1986
+ });
1987
+ }
1988
+ /**
1989
+ * JSON形式で出力
1990
+ */
1991
+ toJson() {
1992
+ return {
1993
+ path: this.path,
1994
+ files: this.files.map((file) => file.toJson())
1995
+ };
1996
+ }
1997
+ };
1998
+
1999
+ // lib/doc-file-relation-reference.ts
2000
+ var DocFileRelationReference = class {
2001
+ constructor(props) {
2002
+ this.props = props;
2003
+ this.pathSystem = props.pathSystem;
2004
+ Object.freeze(this);
2005
+ }
2006
+ pathSystem;
2007
+ get fileSystem() {
2008
+ return this.props.fileSystem;
2009
+ }
2010
+ get basePath() {
2011
+ return this.fileSystem.getBasePath();
2012
+ }
2013
+ /**
2014
+ * リレーションパス
2015
+ */
2016
+ get path() {
2017
+ return this.props.filePath;
2018
+ }
2019
+ /**
2020
+ * フルパス
2021
+ */
2022
+ get fullPath() {
2023
+ return this.pathSystem.join(
2024
+ this.fileSystem.getBasePath(),
2025
+ this.props.filePath
2026
+ );
2027
+ }
2028
+ async read() {
2029
+ const files = await this.readFiles();
2030
+ return new DocRelationValue({
2031
+ path: this.path,
2032
+ files: files.map((value) => value.toJson())
2033
+ });
2034
+ }
2035
+ /**
2036
+ * リレーションファイルの一覧を読み込む
2037
+ */
2038
+ async readFiles() {
2039
+ const exists = await this.fileSystem.exists(this.path);
2040
+ if (!exists) {
2041
+ return [];
2042
+ }
2043
+ const filePaths = await this.fileSystem.readDirectoryFilePaths(this.path);
2044
+ const files = [];
2045
+ for (const filePath of filePaths) {
2046
+ const file = await this.readFile(filePath);
2047
+ if (file === null) continue;
2048
+ files.push(file);
2049
+ }
2050
+ return files;
2051
+ }
2052
+ /**
2053
+ * 単一のリレーションファイルを読み込む
2054
+ */
2055
+ async readFile(filePath) {
2056
+ if (filePath.includes("index.md")) {
2057
+ return null;
2058
+ }
2059
+ const content = await this.fileSystem.readFile(filePath);
2060
+ if (content === null) {
2061
+ return null;
2062
+ }
2063
+ const contentValue = DocFileContentMdValue.fromMarkdown(content);
2064
+ const pathValue = DocFilePathValue.fromPathWithSystem(
2065
+ filePath,
2066
+ this.pathSystem,
2067
+ this.basePath
2068
+ );
2069
+ const fileEntity = new DocFileMdEntity({
2070
+ type: "markdown",
2071
+ content: contentValue.value,
2072
+ path: pathValue.value,
2073
+ isArchived: false
2074
+ });
2075
+ return DocRelationFileValue.from(filePath, fileEntity.value.content.title);
2076
+ }
2077
+ /**
2078
+ * ファイルの存在確認
2079
+ */
2080
+ async exists(slug) {
2081
+ const filePath = `${this.path}/${slug}.md`;
2082
+ return this.fileSystem.exists(filePath);
2083
+ }
2084
+ /**
2085
+ * ファイル名の一覧を取得(拡張子なし)
2086
+ */
2087
+ async readSlugs() {
2088
+ const files = await this.readFiles();
2089
+ return files.map((file) => file.id);
2090
+ }
2091
+ /**
2092
+ * ファイル数を取得
2093
+ */
2094
+ async count() {
2095
+ const files = await this.readFiles();
2096
+ return files.length;
2097
+ }
2098
+ /**
2099
+ * 空かどうかを確認
2100
+ */
2101
+ async isEmpty() {
2102
+ const count = await this.count();
2103
+ return count === 0;
2104
+ }
2105
+ };
2106
+
2107
+ // lib/values/doc-front-matter-index-value.ts
2108
+ import { parse as parse2, stringify as stringify3 } from "yaml";
2109
+
2110
+ // lib/values/doc-schema-value.ts
2111
+ var DocSchemaValue = class _DocSchemaValue {
2112
+ constructor(value) {
2113
+ this.value = value;
2114
+ zDocSchema.parse(value);
2115
+ Object.freeze(this.value);
2116
+ Object.freeze(this);
2117
+ }
2118
+ /**
2119
+ * フィールド名の一覧を取得
2120
+ */
2121
+ get fieldNames() {
2122
+ return Object.keys(this.value);
2123
+ }
2124
+ /**
2125
+ * 指定されたフィールド名のフィールドを取得
2126
+ */
2127
+ field(name) {
2128
+ const fieldDef = this.value[name];
2129
+ if (fieldDef === void 0) {
2130
+ return null;
2131
+ }
2132
+ const factory = new DocSchemaFieldFactory();
2133
+ return factory.fromSchemaEntry(name, fieldDef);
2134
+ }
2135
+ get fields() {
2136
+ const factory = new DocSchemaFieldFactory();
2137
+ return this.fieldNames.map((name) => {
2138
+ const fieldValue = this.value[name];
2139
+ if (!fieldValue) {
2140
+ throw new Error(`Field ${name} not found in schema`);
2141
+ }
2142
+ return factory.fromSchemaEntry(name, fieldValue);
2143
+ });
2144
+ }
2145
+ get relationFields() {
2146
+ return this.fields.filter((t) => {
2147
+ return t instanceof DocSchemaFieldRelationSingleValue || t instanceof DocSchemaFieldRelationMultipleValue;
2148
+ });
2149
+ }
2150
+ /**
2151
+ * 空のスキーマエンティティを作成
2152
+ */
2153
+ static empty() {
2154
+ return new _DocSchemaValue({});
2155
+ }
2156
+ /**
2157
+ * スキーマからリレーションパスを抽出
2158
+ */
2159
+ extractRelationPaths() {
2160
+ if (!this.value) return /* @__PURE__ */ new Set();
2161
+ const uniqueRelationPaths = /* @__PURE__ */ new Set();
2162
+ for (const field of Object.values(this.value)) {
2163
+ if (this.isRelationField(field) && "path" in field) {
2164
+ uniqueRelationPaths.add(field.path);
2165
+ }
2166
+ }
2167
+ return uniqueRelationPaths;
2168
+ }
2169
+ /**
2170
+ * フィールドがリレーション型かどうかを判定
2171
+ */
2172
+ isRelationField(field) {
2173
+ return field.type === "relation" || field.type === "multi-relation";
2174
+ }
2175
+ /**
2176
+ * リレーションオプションを作成
2177
+ */
2178
+ createRelationOption(filePath, title) {
2179
+ const fileName = this.extractFileName(filePath);
2180
+ return zDocRelationFile.parse({
2181
+ name: fileName,
2182
+ label: title || fileName,
2183
+ value: fileName,
2184
+ path: filePath
2185
+ });
2186
+ }
2187
+ /**
2188
+ * ファイルをスキップすべきかどうかを判定
2189
+ */
2190
+ shouldSkipFile(filePath) {
2191
+ return filePath.endsWith("index.md") || filePath.endsWith("README.md");
2192
+ }
2193
+ /**
2194
+ * 値を指定された型に変換する(デフォルト値フォールバック付き)
2195
+ */
2196
+ convertValue(value, targetType, defaultValue) {
2197
+ if (this.isNullOrUndefined(value)) {
2198
+ return defaultValue;
2199
+ }
2200
+ try {
2201
+ return this.convertByType(value, targetType, defaultValue);
2202
+ } catch {
2203
+ return defaultValue;
2204
+ }
2205
+ }
2206
+ /**
2207
+ * 型別の変換処理
2208
+ */
2209
+ convertByType(value, targetType, defaultValue) {
2210
+ if (targetType === "text") {
2211
+ return this.convertToString(value, defaultValue);
2212
+ }
2213
+ if (targetType === "number") {
2214
+ return this.convertToNumber(value, defaultValue);
2215
+ }
2216
+ if (targetType === "boolean") {
2217
+ return this.convertToBoolean(value, defaultValue);
2218
+ }
2219
+ if (targetType === "multi-text" || targetType === "array") {
2220
+ return this.convertToArray(value, defaultValue);
2221
+ }
2222
+ if (targetType === "relation") {
2223
+ return this.convertToRelation(value, defaultValue);
2224
+ }
2225
+ if (targetType === "multi-relation") {
2226
+ return this.convertToMultiRelation(value, defaultValue);
2227
+ }
2228
+ return defaultValue;
2229
+ }
2230
+ /**
2231
+ * 文字列型への変換
2232
+ */
2233
+ convertToString(value, defaultValue) {
2234
+ if (typeof value === "string") return value;
2235
+ if (typeof value === "number") return String(value);
2236
+ if (typeof value === "boolean") return String(value);
2237
+ return defaultValue;
2238
+ }
2239
+ /**
2240
+ * 数値型への変換
2241
+ */
2242
+ convertToNumber(value, defaultValue) {
2243
+ if (typeof value === "number") return value;
2244
+ if (typeof value === "string") {
2245
+ const parsed = Number(value);
2246
+ return Number.isNaN(parsed) ? defaultValue : parsed;
2247
+ }
2248
+ if (typeof value === "boolean") return value ? 1 : 0;
2249
+ return defaultValue;
2250
+ }
2251
+ /**
2252
+ * ブール型への変換
2253
+ */
2254
+ convertToBoolean(value, defaultValue) {
2255
+ if (typeof value === "boolean") return value;
2256
+ if (typeof value === "string") {
2257
+ const lower = value.toLowerCase();
2258
+ if (lower === "true" || lower === "1") return true;
2259
+ if (lower === "false" || lower === "0") return false;
2260
+ return defaultValue;
2261
+ }
2262
+ if (typeof value === "number") return value !== 0;
2263
+ return defaultValue;
2264
+ }
2265
+ /**
2266
+ * 配列型への変換
2267
+ */
2268
+ convertToArray(value, defaultValue) {
2269
+ if (Array.isArray(value)) return value;
2270
+ if (typeof value === "string") {
2271
+ return value.split(",").map((item) => item.trim());
2272
+ }
2273
+ return defaultValue;
2274
+ }
2275
+ /**
2276
+ * リレーション型への変換
2277
+ */
2278
+ convertToRelation(value, defaultValue) {
2279
+ if (typeof value === "string") {
2280
+ return this.extractFileNameFromPath(value);
2281
+ }
2282
+ return defaultValue;
2283
+ }
2284
+ /**
2285
+ * マルチリレーション型への変換
2286
+ */
2287
+ convertToMultiRelation(value, defaultValue) {
2288
+ if (Array.isArray(value)) {
2289
+ return value.filter((item) => typeof item === "string").map((item) => this.extractFileNameFromPath(item));
2290
+ }
2291
+ if (typeof value === "string") {
2292
+ return value.split(",").map((item) => this.extractFileNameFromPath(item.trim()));
2293
+ }
2294
+ return defaultValue;
2295
+ }
2296
+ /**
2297
+ * パスからファイル名を抽出(拡張子除去)
2298
+ */
2299
+ extractFileNameFromPath(path) {
2300
+ const fileName = path.split("/").pop() || path;
2301
+ return fileName.replace(/\.md$/, "");
2302
+ }
2303
+ /**
2304
+ * スキーマベースでFrontMatterを補完する
2305
+ */
2306
+ getCompleteFrontMatter(rawFrontMatter) {
2307
+ const defaultFrontMatter = this.generateDefaultFrontMatter();
2308
+ return this.mergePreservingExistingValues(
2309
+ defaultFrontMatter,
2310
+ rawFrontMatter
2311
+ );
2312
+ }
2313
+ /**
2314
+ * スキーマからデフォルトFrontMatterを生成
2315
+ */
2316
+ generateDefaultFrontMatter() {
2317
+ if (!this.value) return {};
2318
+ const defaultFrontMatter = {};
2319
+ for (const [key, field] of Object.entries(this.value)) {
2320
+ defaultFrontMatter[key] = DocFrontMatterMdValue.generateDefaultValueFromSchemaField(field);
2321
+ }
2322
+ return zDocFileMdFrontMatter.parse(defaultFrontMatter);
2323
+ }
2324
+ /**
2325
+ * 既存の値を保持しながらマージ
2326
+ */
2327
+ mergePreservingExistingValues(defaults, existing) {
2328
+ const result = { ...defaults };
2329
+ if (existing && typeof existing === "object") {
2330
+ const validatedData = zDocFileMdFrontMatter.parse(existing);
2331
+ for (const [key, value] of Object.entries(validatedData)) {
2332
+ if (value !== void 0 && value !== null) {
2333
+ result[key] = value;
2334
+ }
2335
+ }
2336
+ }
2337
+ return result;
2338
+ }
2339
+ /**
2340
+ * ファイルパスからファイル名を抽出(拡張子なし)
2341
+ */
2342
+ extractFileName(filePath) {
2343
+ return filePath.split("/").pop()?.replace(".md", "") || filePath;
2344
+ }
2345
+ /**
2346
+ * nullまundefinedのチェック
2347
+ */
2348
+ isNullOrUndefined(value) {
2349
+ return value === null || value === void 0;
2350
+ }
2351
+ toJson() {
2352
+ return this.value;
2353
+ }
2354
+ };
2355
+
2356
+ // lib/values/doc-front-matter-index-value.ts
2357
+ var DocFrontMatterIndexValue = class _DocFrontMatterIndexValue {
2358
+ constructor(value) {
2359
+ this.value = value;
2360
+ zDocFileIndexFrontMatter.parse(value);
2361
+ Object.freeze(this);
2362
+ }
2363
+ /**
2364
+ * アイコンを取得
2365
+ */
2366
+ get icon() {
2367
+ return this.value.icon;
2368
+ }
2369
+ /**
2370
+ * スキーマを取得
2371
+ */
2372
+ get schema() {
2373
+ return new DocSchemaValue(this.value.schema);
2374
+ }
2375
+ /**
2376
+ * iconフィールドを更新
2377
+ */
2378
+ withIcon(value) {
2379
+ if (typeof value !== "string") {
2380
+ return this;
2381
+ }
2382
+ const currentData = this.toJson();
2383
+ return _DocFrontMatterIndexValue.fromRecord({
2384
+ ...currentData,
2385
+ icon: value
2386
+ });
2387
+ }
2388
+ /**
2389
+ * schemaフィールドを更新
2390
+ */
2391
+ withSchema(value) {
2392
+ if (typeof value !== "object" || value === null) {
2393
+ return this;
2394
+ }
2395
+ const currentData = this.toJson();
2396
+ return _DocFrontMatterIndexValue.fromRecord({
2397
+ ...currentData,
2398
+ schema: _DocFrontMatterIndexValue.createSchema(value)
2399
+ });
2400
+ }
2401
+ /**
2402
+ * JSON形式で出力
2403
+ */
2404
+ toJson() {
2405
+ return this.value;
2406
+ }
2407
+ /**
2408
+ * YAML形式で出力
2409
+ */
2410
+ toYaml() {
2411
+ const yamlData = {
2412
+ icon: this.value.icon,
2413
+ schema: this.value.schema
2414
+ };
2415
+ return stringify3(yamlData).trim();
2416
+ }
2417
+ /**
2418
+ * スキーマ全体を正規化
2419
+ */
2420
+ static createSchema(schema) {
2421
+ if (typeof schema !== "object" || schema === null) {
2422
+ return {};
2423
+ }
2424
+ const schemaObj = schema;
2425
+ const record = {};
2426
+ for (const [key, value] of Object.entries(schemaObj)) {
2427
+ const normalizedField = _DocFrontMatterIndexValue.createSchemaField(
2428
+ key,
2429
+ value
2430
+ );
2431
+ if (normalizedField === null) continue;
2432
+ record[key] = normalizedField;
2433
+ }
2434
+ return record;
2435
+ }
2436
+ /**
2437
+ * スキーマフィールドを正規化
2438
+ */
2439
+ static createSchemaField(key, value) {
2440
+ try {
2441
+ const factory = new DocSchemaFieldFactory();
2442
+ const fieldValue = factory.fromUnknown(key, value);
2443
+ return fieldValue.toJson();
2444
+ } catch {
2445
+ return null;
2446
+ }
2447
+ }
2448
+ /**
2449
+ * Markdownテキストから生成(不完全なデータも処理可能)
2450
+ */
2451
+ static from(markdownText) {
2452
+ if (!markdownText.startsWith("---")) {
2453
+ return _DocFrontMatterIndexValue.empty();
2454
+ }
2455
+ const endIndex = markdownText.indexOf("\n---", 3);
2456
+ if (endIndex === -1) {
2457
+ return _DocFrontMatterIndexValue.empty();
2458
+ }
2459
+ const frontMatterText = markdownText.slice(4, endIndex).trim();
2460
+ try {
2461
+ const data = parse2(frontMatterText) || {};
2462
+ return _DocFrontMatterIndexValue.fromRecord(data);
2463
+ } catch {
2464
+ return _DocFrontMatterIndexValue.empty();
2465
+ }
2466
+ }
2467
+ /**
2468
+ * データから直接生成(不完全なデータも処理可能)
2469
+ */
2470
+ static fromRecord(record) {
2471
+ if (typeof record !== "object") {
2472
+ return _DocFrontMatterIndexValue.empty();
2473
+ }
2474
+ const icon = _DocFrontMatterIndexValue.extractIcon(record);
2475
+ const schema = _DocFrontMatterIndexValue.extractSchema(record);
2476
+ const frontMatter = {
2477
+ type: "index-frontmatter",
2478
+ icon,
2479
+ schema
2480
+ };
2481
+ try {
2482
+ const validated = zDocFileIndexFrontMatter.parse(frontMatter);
2483
+ return new _DocFrontMatterIndexValue(validated);
2484
+ } catch {
2485
+ return _DocFrontMatterIndexValue.empty();
2486
+ }
2487
+ }
2488
+ /**
2489
+ * 空のFrontMatterを生成
2490
+ */
2491
+ static empty() {
2492
+ return new _DocFrontMatterIndexValue({
2493
+ type: "index-frontmatter",
2494
+ icon: "",
2495
+ schema: {}
2496
+ });
2497
+ }
2498
+ /**
2499
+ * アイコンを抽出
2500
+ */
2501
+ static extractIcon(data) {
2502
+ if ("icon" in data && typeof data.icon === "string") {
2503
+ return data.icon;
2504
+ }
2505
+ return _DocFrontMatterIndexValue.getDefaultIcon();
2506
+ }
2507
+ /**
2508
+ * スキーマを抽出
2509
+ */
2510
+ static extractSchema(data) {
2511
+ const hasSchema = "schema" in data;
2512
+ if (!hasSchema) {
2513
+ return {};
2514
+ }
2515
+ if (typeof data.schema !== "object") {
2516
+ return {};
2517
+ }
2518
+ if (data.schema === null) {
2519
+ return {};
2520
+ }
2521
+ return _DocFrontMatterIndexValue.createSchema(data.schema);
2522
+ }
2523
+ /**
2524
+ * デフォルトのアイコンを取得
2525
+ */
2526
+ static getDefaultIcon() {
2527
+ return "\u{1F4C3}";
2528
+ }
2529
+ };
2530
+
2531
+ // lib/values/doc-file-content-index-value.ts
2532
+ var DocFileContentIndexValue = class _DocFileContentIndexValue {
2533
+ constructor(value) {
2534
+ this.value = value;
2535
+ zDocFileContentIndex.parse(value);
2536
+ Object.freeze(this);
2537
+ }
2538
+ /**
2539
+ * コンテンツ本文(frontMatterを含まない)
2540
+ */
2541
+ get body() {
2542
+ return this.value.body;
2543
+ }
2544
+ /**
2545
+ * タイトル
2546
+ */
2547
+ get title() {
2548
+ return this.value.title;
2549
+ }
2550
+ /**
2551
+ * 説明
2552
+ */
2553
+ get description() {
2554
+ return this.value.description;
2555
+ }
2556
+ /**
2557
+ * FrontMatter
2558
+ */
2559
+ get frontMatter() {
2560
+ return new DocFrontMatterIndexValue(this.value.frontMatter);
2561
+ }
2562
+ /**
2563
+ * タイトルを更新
2564
+ */
2565
+ withTitle(title) {
2566
+ const fullText = this.toText();
2567
+ const engine = new DocMarkdownSystem();
2568
+ const updatedText = engine.updateTitle(fullText, title);
2569
+ const updatedBody = engine.extractBody(updatedText);
2570
+ return new _DocFileContentIndexValue({
2571
+ type: "markdown-index",
2572
+ body: updatedBody,
2573
+ title,
2574
+ description: this.description,
2575
+ frontMatter: this.value.frontMatter
2576
+ });
2577
+ }
2578
+ /**
2579
+ * 説明を更新
2580
+ */
2581
+ withDescription(description, defaultTitle) {
2582
+ const fullText = this.toText();
2583
+ const engine = new DocMarkdownSystem();
2584
+ const updatedText = engine.updateDescription(
2585
+ fullText,
2586
+ description,
2587
+ defaultTitle || this.title
2588
+ );
2589
+ const updatedBody = engine.extractBody(updatedText);
2590
+ return new _DocFileContentIndexValue({
2591
+ type: "markdown-index",
2592
+ body: updatedBody,
2593
+ title: this.title,
2594
+ description,
2595
+ frontMatter: this.value.frontMatter
2596
+ });
2597
+ }
2598
+ /**
2599
+ * Markdownテキストから生成
2600
+ */
2601
+ static fromMarkdown(markdown) {
2602
+ const engine = new DocMarkdownSystem();
2603
+ const frontMatter = DocFrontMatterIndexValue.from(markdown);
2604
+ return new _DocFileContentIndexValue({
2605
+ type: "markdown-index",
2606
+ body: engine.extractBody(markdown),
2607
+ title: engine.extractTitle(markdown) || "",
2608
+ description: engine.extractDescription(markdown) || "",
2609
+ frontMatter: frontMatter.toJson()
2610
+ });
2611
+ }
2612
+ /**
2613
+ * 完全なMarkdownテキストを生成
2614
+ */
2615
+ toMarkdownText() {
2616
+ return DocMarkdownSystem.from(this.title, this.description, this.body);
2617
+ }
2618
+ /**
2619
+ * コンテンツを更新
2620
+ */
2621
+ withContent(content) {
2622
+ const engine = new DocMarkdownSystem();
2623
+ return new _DocFileContentIndexValue({
2624
+ type: "markdown-index",
2625
+ body: content,
2626
+ title: engine.extractTitle(content) || "",
2627
+ description: engine.extractDescription(content) || "",
2628
+ frontMatter: this.value.frontMatter
2629
+ });
2630
+ }
2631
+ /**
2632
+ * FrontMatterを更新
2633
+ */
2634
+ withFrontMatter(frontMatter) {
2635
+ return new _DocFileContentIndexValue({
2636
+ type: "markdown-index",
2637
+ body: this.body,
2638
+ title: this.title,
2639
+ description: this.description,
2640
+ frontMatter: frontMatter.toJson()
2641
+ });
2642
+ }
2643
+ /**
2644
+ * デフォルトのindex.mdコンテンツを生成
2645
+ */
2646
+ static empty(directoryName) {
2647
+ const content = `---
2648
+ title: "${directoryName}"
2649
+ description: ""
2650
+ icon: ""
2651
+ schema: {}
2652
+ ---
2653
+
2654
+ # ${directoryName}
2655
+ `;
2656
+ return _DocFileContentIndexValue.fromMarkdown(content);
2657
+ }
2658
+ /**
2659
+ * FrontMatterとbodyを結合した完全なテキストを生成
2660
+ */
2661
+ toText() {
2662
+ return `---
2663
+ ${this.frontMatter.toYaml()}
2664
+ ---
2665
+
2666
+ ${this.body}`;
2667
+ }
2668
+ /**
2669
+ * JSON形式で出力
2670
+ */
2671
+ toJson() {
2672
+ return this.value;
2673
+ }
2674
+ };
2675
+
2676
+ // lib/entities/doc-file-index-entity.ts
2677
+ var DocFileIndexEntity = class _DocFileIndexEntity {
2678
+ constructor(value) {
2679
+ this.value = value;
2680
+ zDocFileIndex.parse(value);
2681
+ Object.freeze(this);
2682
+ }
2683
+ /**
2684
+ * コンテンツ
2685
+ */
2686
+ get content() {
2687
+ return new DocFileContentIndexValue(this.value.content);
2688
+ }
2689
+ /**
2690
+ * パス情報
2691
+ */
2692
+ get path() {
2693
+ return this.value.path;
2694
+ }
2695
+ /**
2696
+ * コンテンツを更新
2697
+ */
2698
+ withContent(content) {
2699
+ return new _DocFileIndexEntity({
2700
+ ...this.value,
2701
+ content: content.value
2702
+ });
2703
+ }
2704
+ /**
2705
+ * パスを更新
2706
+ */
2707
+ withPath(path) {
2708
+ return new _DocFileIndexEntity({
2709
+ ...this.value,
2710
+ path
2711
+ });
2712
+ }
2713
+ /**
2714
+ * indexFileSchemaの形式に変換
2715
+ */
2716
+ toJson() {
2717
+ return this.value;
2718
+ }
2719
+ };
2720
+
2721
+ // lib/doc-file-index-reference.ts
2722
+ var DocFileIndexReference = class _DocFileIndexReference {
2723
+ constructor(props) {
2724
+ this.props = props;
2725
+ this.pathSystem = props.pathSystem;
2726
+ Object.freeze(this);
2727
+ }
2728
+ pathSystem;
2729
+ get fileSystem() {
2730
+ return this.props.fileSystem;
2731
+ }
2732
+ get basePath() {
2733
+ return this.fileSystem.getBasePath();
2734
+ }
2735
+ get filePath() {
2736
+ return this.props.path;
2737
+ }
2738
+ get fileFullPath() {
2739
+ return this.pathSystem.join(this.basePath, this.filePath);
2740
+ }
2741
+ get durectoryPath() {
2742
+ return this.pathSystem.dirname(this.filePath);
2743
+ }
2744
+ async read() {
2745
+ const content = await this.fileSystem.readFile(this.filePath);
2746
+ if (content === null) {
2747
+ const dirName = this.filePath.split("/").pop() || "directory";
2748
+ const pathValue2 = DocFilePathValue.fromPathWithSystem(
2749
+ this.filePath,
2750
+ this.pathSystem,
2751
+ this.fileSystem.getBasePath()
2752
+ );
2753
+ const contentValue2 = DocFileContentIndexValue.empty(dirName);
2754
+ return new DocFileIndexEntity({
2755
+ type: "index",
2756
+ path: pathValue2.toJson(),
2757
+ content: contentValue2.toJson(),
2758
+ isArchived: false
2759
+ });
2760
+ }
2761
+ const pathValue = DocFilePathValue.fromPathWithSystem(
2762
+ this.filePath,
2763
+ this.pathSystem,
2764
+ this.fileSystem.getBasePath()
2765
+ );
2766
+ const contentValue = DocFileContentIndexValue.fromMarkdown(content);
2767
+ return new DocFileIndexEntity({
2768
+ type: "index",
2769
+ path: pathValue.toJson(),
2770
+ content: contentValue.toJson(),
2771
+ isArchived: false
2772
+ });
2773
+ }
2774
+ /**
2775
+ * ファイルの内容を読み込む
2776
+ */
2777
+ async readContent() {
2778
+ const entity = await this.read();
2779
+ if (entity instanceof Error) {
2780
+ return entity;
2781
+ }
2782
+ return entity.value.content.body;
2783
+ }
2784
+ /**
2785
+ * ファイルに内容を書き込む
2786
+ */
2787
+ async writeContent(content) {
2788
+ await this.fileSystem.writeFile(this.filePath, content);
2789
+ }
2790
+ /**
2791
+ * Entityを書き込む
2792
+ */
2793
+ async write(entity) {
2794
+ const content = entity.content.toText();
2795
+ await this.fileSystem.writeFile(this.filePath, content);
2796
+ }
2797
+ /**
2798
+ * 新しいファイルをデフォルトコンテンツで作成
2799
+ */
2800
+ async writeDefault() {
2801
+ const dirPath = this.pathSystem.dirname(this.filePath);
2802
+ const dirName = this.pathSystem.basename(dirPath) || "\u30C7\u30A3\u30EC\u30AF\u30C8\u30EA";
2803
+ const defaultContent = [
2804
+ `# ${dirName}`,
2805
+ "",
2806
+ `${dirName}\u306B\u95A2\u3059\u308B\u6982\u8981\u3092\u3053\u3053\u306B\u8A18\u8F09\u3057\u3066\u304F\u3060\u3055\u3044\u3002`
2807
+ ].join("\n");
2808
+ await this.fileSystem.writeFile(this.filePath, defaultContent);
2809
+ }
2810
+ /**
2811
+ * ファイルを削除
2812
+ */
2813
+ async delete() {
2814
+ return await this.fileSystem.deleteFile(this.filePath);
2815
+ }
2816
+ /**
2817
+ * ファイルが存在するか確認
2818
+ */
2819
+ async exists() {
2820
+ return this.fileSystem.exists(this.filePath);
2821
+ }
2822
+ async relations() {
2823
+ const indexFile = await this.read();
2824
+ if (indexFile instanceof Error) {
2825
+ return [];
2826
+ }
2827
+ const schema = indexFile.content.frontMatter.value.schema;
2828
+ if (!schema) {
2829
+ return [];
2830
+ }
2831
+ const relationFields = Object.entries(schema).filter(([_key, field]) => {
2832
+ return field.type === "relation" || field.type === "multi-relation";
2833
+ });
2834
+ return relationFields.map(([, field]) => {
2835
+ if ((field.type === "relation" || field.type === "multi-relation") && field.path) {
2836
+ return new DocFileRelationReference({
2837
+ filePath: field.path,
2838
+ fileSystem: this.fileSystem,
2839
+ pathSystem: this.pathSystem
2840
+ });
2841
+ }
2842
+ throw new Error("Unexpected field type or missing path");
2843
+ });
2844
+ }
2845
+ async readRelations() {
2846
+ const relations = await this.relations();
2847
+ const files = [];
2848
+ for (const relation of relations) {
2849
+ const entity = await relation.read();
2850
+ if (entity === null) continue;
2851
+ files.push(entity);
2852
+ }
2853
+ return files;
2854
+ }
2855
+ /**
2856
+ * ファイルのサイズを取得(バイト単位)
2857
+ */
2858
+ async size() {
2859
+ return this.fileSystem.getFileSize(this.filePath);
2860
+ }
2861
+ /**
2862
+ * ファイルの最終更新日時を取得
2863
+ */
2864
+ async lastModified() {
2865
+ return this.fileSystem.getFileModifiedTime(this.filePath);
2866
+ }
2867
+ /**
2868
+ * ファイルの作成日時を取得
2869
+ */
2870
+ async createdAt() {
2871
+ return this.fileSystem.getFileCreatedTime(this.filePath);
2872
+ }
2873
+ /**
2874
+ * ファイルをアーカイブに移動し、新しい参照を返す
2875
+ */
2876
+ async archive(archiveDirectoryName = "_") {
2877
+ const dirPath = this.pathSystem.dirname(this.filePath);
2878
+ const fileName = this.pathSystem.basename(this.filePath);
2879
+ const archivePath = this.pathSystem.join(
2880
+ dirPath,
2881
+ archiveDirectoryName,
2882
+ fileName
2883
+ );
2884
+ await this.fileSystem.moveFile(this.filePath, archivePath);
2885
+ return new _DocFileIndexReference({
2886
+ path: archivePath,
2887
+ fileSystem: this.fileSystem,
2888
+ pathSystem: this.pathSystem
2889
+ });
2890
+ }
2891
+ /**
2892
+ * ファイルをアーカイブから復元し、新しい参照を返す
2893
+ */
2894
+ async restore(archiveDirectoryName = "_") {
2895
+ const dirPath = this.pathSystem.dirname(this.filePath);
2896
+ const parentDirName = this.pathSystem.basename(dirPath);
2897
+ if (parentDirName !== archiveDirectoryName) {
2898
+ throw new Error(
2899
+ `\u30D5\u30A1\u30A4\u30EB\u306F\u30A2\u30FC\u30AB\u30A4\u30D6\u30C7\u30A3\u30EC\u30AF\u30C8\u30EA\u306B\u3042\u308A\u307E\u305B\u3093: ${this.filePath}`
2900
+ );
2901
+ }
2902
+ const fileName = this.pathSystem.basename(this.filePath);
2903
+ const restorePath = this.pathSystem.join(
2904
+ this.pathSystem.dirname(dirPath),
2905
+ fileName
2906
+ );
2907
+ await this.fileSystem.moveFile(this.filePath, restorePath);
2908
+ return new _DocFileIndexReference({
2909
+ path: restorePath,
2910
+ fileSystem: this.fileSystem,
2911
+ pathSystem: this.pathSystem
2912
+ });
2913
+ }
2914
+ };
2915
+
2916
+ // lib/doc-file-md-reference.ts
2917
+ var DocFileMdReference = class _DocFileMdReference {
2918
+ constructor(props) {
2919
+ this.props = props;
2920
+ this.pathSystem = props.pathSystem;
2921
+ Object.freeze(this);
2922
+ }
2923
+ pathSystem;
2924
+ get fileSystem() {
2925
+ return this.props.fileSystem;
2926
+ }
2927
+ get basePath() {
2928
+ return this.fileSystem.getBasePath();
2929
+ }
2930
+ get path() {
2931
+ return this.props.path;
2932
+ }
2933
+ get fullPath() {
2934
+ return this.pathSystem.join(this.basePath, this.path);
2935
+ }
2936
+ get directoryPath() {
2937
+ return this.pathSystem.dirname(this.path);
2938
+ }
2939
+ get archivedPath() {
2940
+ return this.pathSystem.join(this.directoryPath, "_", this.nameWithExtension);
2941
+ }
2942
+ get name() {
2943
+ return this.pathSystem.basename(this.path, ".md");
2944
+ }
2945
+ get nameWithExtension() {
2946
+ return `${this.name}.md`;
2947
+ }
2948
+ directory() {
2949
+ return new DocDirectoryReference({
2950
+ archiveDirectoryName: "_",
2951
+ indexFileName: "index.md",
2952
+ fileSystem: this.fileSystem,
2953
+ path: this.directoryPath,
2954
+ pathSystem: this.pathSystem
2955
+ });
2956
+ }
2957
+ async read() {
2958
+ const content = await this.fileSystem.readFile(this.path);
2959
+ const actualPath = this.path;
2960
+ if (content === null) {
2961
+ const content2 = await this.fileSystem.readFile(this.archivedPath);
2962
+ if (content2 !== null) {
2963
+ const contentValue2 = DocFileContentMdValue.fromMarkdown(content2);
2964
+ const pathValue2 = DocFilePathValue.fromPathWithSystem(
2965
+ actualPath,
2966
+ this.pathSystem,
2967
+ this.basePath
2968
+ );
2969
+ return new DocFileMdEntity({
2970
+ type: "markdown",
2971
+ content: contentValue2.value,
2972
+ path: pathValue2.value,
2973
+ isArchived: true
2974
+ });
2975
+ }
2976
+ }
2977
+ if (content === null) {
2978
+ return new Error(`File not found at ${this.path} or in archive.`);
2979
+ }
2980
+ const contentValue = DocFileContentMdValue.fromMarkdown(content);
2981
+ const pathValue = DocFilePathValue.fromPathWithSystem(
2982
+ actualPath,
2983
+ this.pathSystem,
2984
+ this.basePath
2985
+ );
2986
+ const isInArchiveDir = this.path.includes("/_/") || this.path.startsWith("_/");
2987
+ return new DocFileMdEntity({
2988
+ type: "markdown",
2989
+ content: contentValue.value,
2990
+ path: pathValue.value,
2991
+ isArchived: isInArchiveDir
2992
+ });
2993
+ }
2994
+ /**
2995
+ * ファイルの内容を読み込む
2996
+ */
2997
+ async readContent() {
2998
+ const entity = await this.read();
2999
+ if (entity instanceof Error) {
3000
+ return entity;
3001
+ }
3002
+ return entity.value.content.body;
3003
+ }
3004
+ /**
3005
+ * ファイルに内容を書き込む
3006
+ */
3007
+ async writeContent(content) {
3008
+ return await this.fileSystem.writeFile(this.path, content);
3009
+ }
3010
+ /**
3011
+ * Entityを書き込む
3012
+ */
3013
+ async write(entity) {
3014
+ const content = entity.content.toText();
3015
+ return await this.fileSystem.writeFile(this.path, content);
3016
+ }
3017
+ /**
3018
+ * 新しいファイルをデフォルトコンテンツで作成
3019
+ */
3020
+ async writeDefault() {
3021
+ const fileName = this.pathSystem.basename(this.path, ".md");
3022
+ const defaultContent = [
3023
+ `# ${fileName}`,
3024
+ "",
3025
+ "\u3053\u3053\u306B\u5185\u5BB9\u3092\u8A18\u8F09\u3057\u3066\u304F\u3060\u3055\u3044\u3002"
3026
+ ].join("\n");
3027
+ return await this.fileSystem.writeFile(this.path, defaultContent);
3028
+ }
3029
+ /**
3030
+ * ファイルを削除
3031
+ */
3032
+ async delete() {
3033
+ return await this.fileSystem.deleteFile(this.path);
3034
+ }
3035
+ /**
3036
+ * ファイルが存在するか確認(アーカイブも含む)
3037
+ */
3038
+ async exists() {
3039
+ if (await this.fileSystem.exists(this.path)) {
3040
+ return true;
3041
+ }
3042
+ const dirPath = this.pathSystem.dirname(this.path);
3043
+ const fileName = this.pathSystem.basename(this.path);
3044
+ const archivePath = this.pathSystem.join(dirPath, "_", fileName);
3045
+ return this.fileSystem.exists(archivePath);
3046
+ }
3047
+ /**
3048
+ * ファイルをコピー
3049
+ */
3050
+ async copyTo(destinationPath) {
3051
+ await this.fileSystem.copyFile(this.path, destinationPath);
3052
+ }
3053
+ /**
3054
+ * ファイルを移動
3055
+ */
3056
+ async moveTo(destinationPath) {
3057
+ await this.fileSystem.moveFile(this.path, destinationPath);
3058
+ }
3059
+ /**
3060
+ * ファイルのサイズを取得(バイト単位)
3061
+ */
3062
+ async size() {
3063
+ return this.fileSystem.getFileSize(this.path);
3064
+ }
3065
+ /**
3066
+ * ファイルの最終更新日時を取得
3067
+ */
3068
+ async lastModified() {
3069
+ return this.fileSystem.getFileModifiedTime(this.path);
3070
+ }
3071
+ /**
3072
+ * ファイルの作成日時を取得
3073
+ */
3074
+ async createdAt() {
3075
+ return this.fileSystem.getFileCreatedTime(this.path);
3076
+ }
3077
+ /**
3078
+ * ファイルをアーカイブに移動し、新しい参照を返す
3079
+ */
3080
+ async archive(archiveDirectoryName = "_") {
3081
+ const dirPath = this.pathSystem.dirname(this.path);
3082
+ const fileName = this.pathSystem.basename(this.path);
3083
+ const archivePath = this.pathSystem.join(
3084
+ dirPath,
3085
+ archiveDirectoryName,
3086
+ fileName
3087
+ );
3088
+ await this.moveTo(archivePath);
3089
+ return new _DocFileMdReference({
3090
+ path: archivePath,
3091
+ fileSystem: this.fileSystem,
3092
+ pathSystem: this.pathSystem
3093
+ });
3094
+ }
3095
+ /**
3096
+ * ファイルをアーカイブから復元し、新しい参照を返す
3097
+ */
3098
+ async restore(archiveDirectoryName = "_") {
3099
+ const dirPath = this.pathSystem.dirname(this.path);
3100
+ const parentDirName = this.pathSystem.basename(dirPath);
3101
+ if (parentDirName !== archiveDirectoryName) {
3102
+ throw new Error(
3103
+ `\u30D5\u30A1\u30A4\u30EB\u306F\u30A2\u30FC\u30AB\u30A4\u30D6\u30C7\u30A3\u30EC\u30AF\u30C8\u30EA\u306B\u3042\u308A\u307E\u305B\u3093: ${this.path}`
3104
+ );
3105
+ }
3106
+ const fileName = this.pathSystem.basename(this.path);
3107
+ const restorePath = this.pathSystem.join(
3108
+ this.pathSystem.dirname(dirPath),
3109
+ fileName
3110
+ );
3111
+ await this.moveTo(restorePath);
3112
+ return new _DocFileMdReference({
3113
+ path: restorePath,
3114
+ fileSystem: this.fileSystem,
3115
+ pathSystem: this.pathSystem
3116
+ });
3117
+ }
3118
+ /**
3119
+ * スキーマに基づいてリレーションを取得する
3120
+ */
3121
+ async relation(key) {
3122
+ const file = await this.read();
3123
+ if (file instanceof Error) {
3124
+ return file;
3125
+ }
3126
+ const relationValue = file.content.frontMatter.relation(key);
3127
+ if (relationValue === null) {
3128
+ return null;
3129
+ }
3130
+ const indexFile = await this.getDirectoryIndex();
3131
+ if (!indexFile) {
3132
+ return null;
3133
+ }
3134
+ const schemaData = indexFile.content.frontMatter.value.schema;
3135
+ if (!schemaData || typeof schemaData !== "object" || Array.isArray(schemaData)) {
3136
+ return null;
3137
+ }
3138
+ const schema = new DocSchemaValue(schemaData);
3139
+ const field = schema.field(key);
3140
+ if (!field || !("path" in field) || !field.path) {
3141
+ return null;
3142
+ }
3143
+ const fullPath = this.pathSystem.join(field.path, `${relationValue}.md`);
3144
+ return new _DocFileMdReference({
3145
+ path: fullPath,
3146
+ fileSystem: this.fileSystem,
3147
+ pathSystem: this.pathSystem
3148
+ });
3149
+ }
3150
+ /**
3151
+ * 同じディレクトリのindex.mdを取得する
3152
+ */
3153
+ async getDirectoryIndex() {
3154
+ const indexPath = this.pathSystem.join(this.directoryPath, "index.md");
3155
+ const indexRef = new _DocFileMdReference({
3156
+ path: indexPath,
3157
+ fileSystem: this.fileSystem,
3158
+ pathSystem: this.pathSystem
3159
+ });
3160
+ const indexFile = await indexRef.read();
3161
+ if (indexFile instanceof Error) {
3162
+ return null;
3163
+ }
3164
+ return indexFile;
3165
+ }
3166
+ /**
3167
+ * 複数のリレーションを取得する
3168
+ */
3169
+ async relations(key) {
3170
+ return this.multiRelation(key);
3171
+ }
3172
+ /**
3173
+ * スキーマに基づいて複数のリレーションを取得する
3174
+ */
3175
+ async multiRelation(key) {
3176
+ const file = await this.read();
3177
+ if (file instanceof Error) {
3178
+ return [];
3179
+ }
3180
+ const relationValues = file.content.frontMatter.multiRelation(key);
3181
+ if (relationValues.length === 0) {
3182
+ return [];
3183
+ }
3184
+ const indexFile = await this.getDirectoryIndex();
3185
+ if (!indexFile) {
3186
+ return [];
3187
+ }
3188
+ const schemaData = indexFile.content.frontMatter.value.schema;
3189
+ if (!schemaData || typeof schemaData !== "object" || Array.isArray(schemaData)) {
3190
+ return [];
3191
+ }
3192
+ const schema = new DocSchemaValue(schemaData);
3193
+ const field = schema.field(key);
3194
+ if (!field || !("path" in field) || !field.path) {
3195
+ return [];
3196
+ }
3197
+ return relationValues.map((relationValue) => {
3198
+ const fullPath = this.pathSystem.join(field.path, `${relationValue}.md`);
3199
+ return new _DocFileMdReference({
3200
+ path: fullPath,
3201
+ fileSystem: this.fileSystem,
3202
+ pathSystem: this.pathSystem
3203
+ });
3204
+ });
3205
+ }
3206
+ };
3207
+
3208
+ // lib/entities/doc-file-unknown-entity.ts
3209
+ var DocFileUnknownEntity = class _DocFileUnknownEntity {
3210
+ constructor(value) {
3211
+ this.value = value;
3212
+ zDocFileUnknown.parse(value);
3213
+ Object.freeze(this);
3214
+ }
3215
+ /**
3216
+ * コンテンツ
3217
+ */
3218
+ get content() {
3219
+ return this.value.content;
3220
+ }
3221
+ /**
3222
+ * パス情報
3223
+ */
3224
+ get path() {
3225
+ return this.value.path;
3226
+ }
3227
+ /**
3228
+ * コンテンツを更新
3229
+ */
3230
+ withContent(content) {
3231
+ return new _DocFileUnknownEntity({
3232
+ ...this.value,
3233
+ content
3234
+ });
3235
+ }
3236
+ /**
3237
+ * パスを更新
3238
+ */
3239
+ withPath(path) {
3240
+ return new _DocFileUnknownEntity({
3241
+ ...this.value,
3242
+ path
3243
+ });
3244
+ }
3245
+ toJson() {
3246
+ return this.value;
3247
+ }
3248
+ };
3249
+
3250
+ // lib/doc-file-unknown-reference.ts
3251
+ var DocFileUnknownReference = class _DocFileUnknownReference {
3252
+ constructor(props) {
3253
+ this.props = props;
3254
+ this.pathSystem = props.pathSystem;
3255
+ Object.freeze(this);
3256
+ }
3257
+ pathSystem;
3258
+ get fileSystem() {
3259
+ return this.props.fileSystem;
3260
+ }
3261
+ get basePath() {
3262
+ return this.fileSystem.getBasePath();
3263
+ }
3264
+ get path() {
3265
+ return this.props.path;
3266
+ }
3267
+ get directoryPath() {
3268
+ return this.pathSystem.dirname(this.path);
3269
+ }
3270
+ get fileFullPath() {
3271
+ return this.pathSystem.join(this.basePath, this.path);
3272
+ }
3273
+ get durectoryPath() {
3274
+ return this.pathSystem.dirname(this.path);
3275
+ }
3276
+ directory() {
3277
+ return new DocDirectoryReference({
3278
+ archiveDirectoryName: "_",
3279
+ indexFileName: "index.md",
3280
+ fileSystem: this.fileSystem,
3281
+ path: this.directoryPath,
3282
+ pathSystem: this.pathSystem
3283
+ });
3284
+ }
3285
+ async read() {
3286
+ const content = await this.fileSystem.readFile(this.path);
3287
+ if (content === null) {
3288
+ return new Error(`File not found at ${this.path}.`);
3289
+ }
3290
+ const isInArchiveDir = this.path.includes("/_/") || this.path.startsWith("_/");
3291
+ if (this.path.endsWith(".md")) {
3292
+ const contentValue = DocFileContentMdValue.fromMarkdown(content);
3293
+ const pathValue2 = DocFilePathValue.fromPathWithSystem(
3294
+ this.path,
3295
+ this.pathSystem,
3296
+ this.basePath
3297
+ );
3298
+ return new DocFileMdEntity({
3299
+ type: "markdown",
3300
+ content: contentValue.value,
3301
+ path: pathValue2.value,
3302
+ isArchived: isInArchiveDir
3303
+ });
3304
+ }
3305
+ const pathValue = DocFilePathValue.fromPathWithSystem(
3306
+ this.path,
3307
+ this.pathSystem,
3308
+ this.basePath
3309
+ );
3310
+ const extension = this.pathSystem.extname(this.path).substring(1);
3311
+ return new DocFileUnknownEntity({
3312
+ type: "unknown",
3313
+ path: pathValue.value,
3314
+ content,
3315
+ extension,
3316
+ isArchived: isInArchiveDir
3317
+ });
3318
+ }
3319
+ /**
3320
+ * ファイルの内容を読み込む
3321
+ */
3322
+ async readContent() {
3323
+ const entity = await this.read();
3324
+ if (entity instanceof Error) {
3325
+ return entity;
3326
+ }
3327
+ if (typeof entity.value.content === "string") {
3328
+ return entity.value.content;
3329
+ }
3330
+ return entity.value.content.body;
3331
+ }
3332
+ /**
3333
+ * ファイルに内容を書き込む
3334
+ */
3335
+ async writeContent(content) {
3336
+ await this.fileSystem.writeFile(this.path, content);
3337
+ }
3338
+ /**
3339
+ * Entityを書き込む
3340
+ */
3341
+ async write(entity) {
3342
+ await this.fileSystem.writeFile(this.path, entity.value.content);
3343
+ }
3344
+ /**
3345
+ * 生のコンテンツを書き込む
3346
+ */
3347
+ async writeRaw(content) {
3348
+ await this.fileSystem.writeFile(this.path, content);
3349
+ }
3350
+ /**
3351
+ * ファイルを削除
3352
+ */
3353
+ async delete() {
3354
+ return await this.fileSystem.deleteFile(this.path);
3355
+ }
3356
+ /**
3357
+ * ファイルが存在するか確認
3358
+ */
3359
+ async exists() {
3360
+ return this.fileSystem.exists(this.path);
3361
+ }
3362
+ /**
3363
+ * ファイルをコピー
3364
+ */
3365
+ async copyTo(destinationPath) {
3366
+ await this.fileSystem.copyFile(this.path, destinationPath);
3367
+ }
3368
+ /**
3369
+ * ファイルを移動
3370
+ */
3371
+ async moveTo(destinationPath) {
3372
+ await this.fileSystem.moveFile(this.path, destinationPath);
3373
+ }
3374
+ /**
3375
+ * ファイルのサイズを取得(バイト単位)
3376
+ */
3377
+ async size() {
3378
+ return this.fileSystem.getFileSize(this.path);
3379
+ }
3380
+ /**
3381
+ * ファイルの最終更新日時を取得
3382
+ */
3383
+ async lastModified() {
3384
+ return this.fileSystem.getFileModifiedTime(this.path);
3385
+ }
3386
+ /**
3387
+ * ファイルの作成日時を取得
3388
+ */
3389
+ async createdAt() {
3390
+ return this.fileSystem.getFileCreatedTime(this.path);
3391
+ }
3392
+ /**
3393
+ * ファイルをアーカイブに移動し、新しい参照を返す
3394
+ */
3395
+ async archive(archiveDirectoryName = "_") {
3396
+ const dirPath = this.pathSystem.dirname(this.path);
3397
+ const fileName = this.pathSystem.basename(this.path);
3398
+ const archivePath = this.pathSystem.join(
3399
+ dirPath,
3400
+ archiveDirectoryName,
3401
+ fileName
3402
+ );
3403
+ await this.moveTo(archivePath);
3404
+ return new _DocFileUnknownReference({
3405
+ path: archivePath,
3406
+ fileSystem: this.fileSystem,
3407
+ pathSystem: this.pathSystem
3408
+ });
3409
+ }
3410
+ /**
3411
+ * ファイルをアーカイブから復元し、新しい参照を返す
3412
+ */
3413
+ async restore(archiveDirectoryName = "_") {
3414
+ const dirPath = this.pathSystem.dirname(this.path);
3415
+ const parentDirName = this.pathSystem.basename(dirPath);
3416
+ if (parentDirName !== archiveDirectoryName) {
3417
+ throw new Error(
3418
+ `\u30D5\u30A1\u30A4\u30EB\u306F\u30A2\u30FC\u30AB\u30A4\u30D6\u30C7\u30A3\u30EC\u30AF\u30C8\u30EA\u306B\u3042\u308A\u307E\u305B\u3093: ${this.path}`
3419
+ );
3420
+ }
3421
+ const fileName = this.pathSystem.basename(this.path);
3422
+ const restorePath = this.pathSystem.join(
3423
+ this.pathSystem.dirname(dirPath),
3424
+ fileName
3425
+ );
3426
+ await this.moveTo(restorePath);
3427
+ return new _DocFileUnknownReference({
3428
+ path: restorePath,
3429
+ fileSystem: this.fileSystem,
3430
+ pathSystem: this.pathSystem
3431
+ });
3432
+ }
3433
+ };
3434
+
3435
+ // lib/doc-directory-reference.ts
3436
+ var DocDirectoryReference = class _DocDirectoryReference {
3437
+ constructor(props) {
3438
+ this.props = props;
3439
+ this.pathSystem = props.pathSystem;
3440
+ Object.freeze(this);
3441
+ }
3442
+ pathSystem;
3443
+ get fileSystem() {
3444
+ return this.props.fileSystem;
3445
+ }
3446
+ get basePath() {
3447
+ return this.fileSystem.getBasePath();
3448
+ }
3449
+ get relativePath() {
3450
+ return this.props.path;
3451
+ }
3452
+ get absolutePath() {
3453
+ return this.pathSystem.join(this.basePath, this.relativePath);
3454
+ }
3455
+ get indexFileName() {
3456
+ return this.props.indexFileName;
3457
+ }
3458
+ get indexFilePath() {
3459
+ return this.pathSystem.join(
3460
+ this.basePath,
3461
+ this.relativePath,
3462
+ this.props.indexFileName
3463
+ );
3464
+ }
3465
+ get archiveDirectoryName() {
3466
+ return this.props.archiveDirectoryName;
3467
+ }
3468
+ async fileNames() {
3469
+ const filePaths = await this.fileSystem.readDirectoryFilePaths(
3470
+ this.relativePath
3471
+ );
3472
+ return filePaths.map((p) => this.pathSystem.basename(p)).filter((name) => name.includes("."));
3473
+ }
3474
+ async archivedFileNames() {
3475
+ const archivePath = this.pathSystem.join(
3476
+ this.relativePath,
3477
+ this.archiveDirectoryName
3478
+ );
3479
+ const filePaths = await this.fileSystem.readDirectoryFilePaths(archivePath);
3480
+ return filePaths.map((p) => this.pathSystem.basename(p)).filter((name) => name.includes("."));
3481
+ }
3482
+ async *filesGenerator() {
3483
+ const fileNames = await this.fileNames();
3484
+ for (const fileName of fileNames) {
3485
+ if (fileName === "index.md") continue;
3486
+ if (fileName.endsWith(".md")) {
3487
+ yield new DocFileMdReference({
3488
+ path: this.pathSystem.join(this.relativePath, fileName),
3489
+ fileSystem: this.fileSystem,
3490
+ pathSystem: this.pathSystem
3491
+ });
3492
+ continue;
3493
+ }
3494
+ yield new DocFileUnknownReference({
3495
+ path: this.pathSystem.join(this.relativePath, fileName),
3496
+ fileSystem: this.fileSystem,
3497
+ pathSystem: this.pathSystem
3498
+ });
3499
+ }
3500
+ const archivedFileNames = await this.archivedFileNames();
3501
+ for (const fileName of archivedFileNames) {
3502
+ if (fileName === "index.md") continue;
3503
+ if (fileName.endsWith(".md")) {
3504
+ yield new DocFileMdReference({
3505
+ path: this.pathSystem.join(
3506
+ this.relativePath,
3507
+ this.archiveDirectoryName,
3508
+ fileName
3509
+ ),
3510
+ fileSystem: this.fileSystem,
3511
+ pathSystem: this.pathSystem
3512
+ });
3513
+ continue;
3514
+ }
3515
+ yield new DocFileUnknownReference({
3516
+ path: this.pathSystem.join(
3517
+ this.relativePath,
3518
+ this.archiveDirectoryName,
3519
+ fileName
3520
+ ),
3521
+ fileSystem: this.fileSystem,
3522
+ pathSystem: this.pathSystem
3523
+ });
3524
+ }
3525
+ }
3526
+ async *mdFilesGenerator() {
3527
+ const files = this.filesGenerator();
3528
+ for await (const file of files) {
3529
+ if (file instanceof DocFileMdReference) {
3530
+ yield file;
3531
+ }
3532
+ }
3533
+ }
3534
+ async files() {
3535
+ const files = [];
3536
+ for await (const file of this.filesGenerator()) {
3537
+ files.push(file);
3538
+ }
3539
+ return files;
3540
+ }
3541
+ async mdFiles() {
3542
+ const files = [];
3543
+ for await (const file of this.filesGenerator()) {
3544
+ if (file instanceof DocFileUnknownReference) continue;
3545
+ files.push(file);
3546
+ }
3547
+ return files;
3548
+ }
3549
+ file(fileName) {
3550
+ const filePath = this.pathSystem.join(this.relativePath, fileName);
3551
+ if (fileName.endsWith(".md")) {
3552
+ return new DocFileMdReference({
3553
+ path: filePath,
3554
+ fileSystem: this.fileSystem,
3555
+ pathSystem: this.pathSystem
3556
+ });
3557
+ }
3558
+ return new DocFileUnknownReference({
3559
+ path: filePath,
3560
+ fileSystem: this.fileSystem,
3561
+ pathSystem: this.pathSystem
3562
+ });
3563
+ }
3564
+ mdFile(fileName) {
3565
+ return new DocFileMdReference({
3566
+ path: this.pathSystem.join(this.relativePath, fileName),
3567
+ fileSystem: this.fileSystem,
3568
+ pathSystem: this.pathSystem
3569
+ });
3570
+ }
3571
+ async readFiles() {
3572
+ const entities = [];
3573
+ for await (const file of this.filesGenerator()) {
3574
+ const entity = await file.read();
3575
+ if (entity instanceof Error) continue;
3576
+ entities.push(entity);
3577
+ }
3578
+ return entities;
3579
+ }
3580
+ async readMdFiles() {
3581
+ const entities = [];
3582
+ for await (const file of this.filesGenerator()) {
3583
+ const entity = await file.read();
3584
+ if (entity instanceof Error) continue;
3585
+ if (entity instanceof DocFileUnknownEntity) continue;
3586
+ entities.push(entity);
3587
+ }
3588
+ return entities;
3589
+ }
3590
+ async readUnknownFiles() {
3591
+ const entities = [];
3592
+ for await (const file of this.filesGenerator()) {
3593
+ const entity = await file.read();
3594
+ if (entity instanceof Error) continue;
3595
+ if (entity instanceof DocFileMdEntity) continue;
3596
+ entities.push(entity);
3597
+ }
3598
+ return entities;
3599
+ }
3600
+ /**
3601
+ * サブディレクトリ名の一覧を取得
3602
+ */
3603
+ async directoryNames() {
3604
+ const allFileNames = await this.fileSystem.readDirectoryFileNames(
3605
+ this.relativePath
3606
+ );
3607
+ const directoryNames = [];
3608
+ for (const fileName of allFileNames) {
3609
+ if (fileName.startsWith(this.archiveDirectoryName)) continue;
3610
+ const filePath = this.pathSystem.join(this.relativePath, fileName);
3611
+ const isDirectory = await this.fileSystem.isDirectory(filePath);
3612
+ if (isDirectory) {
3613
+ directoryNames.push(fileName);
3614
+ }
3615
+ }
3616
+ return directoryNames;
3617
+ }
3618
+ /**
3619
+ * サブディレクトリの参照を取得
3620
+ */
3621
+ async directories() {
3622
+ const directoryNames = await this.directoryNames();
3623
+ return directoryNames.map((dirName) => {
3624
+ const dirPath = this.pathSystem.join(this.relativePath, dirName);
3625
+ return new _DocDirectoryReference({
3626
+ path: dirPath,
3627
+ indexFileName: this.indexFileName,
3628
+ archiveDirectoryName: this.archiveDirectoryName,
3629
+ fileSystem: this.fileSystem,
3630
+ pathSystem: this.pathSystem
3631
+ });
3632
+ });
3633
+ }
3634
+ /**
3635
+ * 単一のサブディレクトリ参照を取得
3636
+ */
3637
+ directory(directoryName) {
3638
+ const dirPath = this.pathSystem.join(this.relativePath, directoryName);
3639
+ return new _DocDirectoryReference({
3640
+ path: dirPath,
3641
+ indexFileName: this.indexFileName,
3642
+ archiveDirectoryName: this.archiveDirectoryName,
3643
+ fileSystem: this.fileSystem,
3644
+ pathSystem: this.pathSystem
3645
+ });
3646
+ }
3647
+ indexFile() {
3648
+ return new DocFileIndexReference({
3649
+ path: this.pathSystem.join(this.relativePath, this.indexFileName),
3650
+ fileSystem: this.fileSystem,
3651
+ pathSystem: this.pathSystem
3652
+ });
3653
+ }
3654
+ async readIndexFile() {
3655
+ const ref = this.indexFile();
3656
+ return ref.read();
3657
+ }
3658
+ async writeFile(entity) {
3659
+ const filePath = this.pathSystem.join(
3660
+ this.relativePath,
3661
+ entity.value.path.nameWithExtension
3662
+ );
3663
+ let content = null;
3664
+ if (entity instanceof DocFileUnknownEntity) {
3665
+ content = entity.value.content;
3666
+ }
3667
+ if (entity instanceof DocFileIndexEntity) {
3668
+ content = entity.content.toText();
3669
+ }
3670
+ if (entity instanceof DocFileMdEntity) {
3671
+ content = entity.content.toText();
3672
+ }
3673
+ if (content === null) {
3674
+ return new Error("Entity content is undefined");
3675
+ }
3676
+ await this.fileSystem.writeFile(filePath, content);
3677
+ return null;
3678
+ }
3679
+ async exists() {
3680
+ return await this.fileSystem.exists(this.relativePath);
3681
+ }
3682
+ /**
3683
+ * 一意なファイル名を生成する
3684
+ */
3685
+ async generateUniqueFileName(prefix = "document") {
3686
+ const now = /* @__PURE__ */ new Date();
3687
+ const timestamp = now.toISOString().slice(0, 19).replace(/[:-]/g, "");
3688
+ let counter = 0;
3689
+ let fileName;
3690
+ do {
3691
+ const suffix = counter > 0 ? `-${counter}` : "";
3692
+ fileName = `${prefix}-${timestamp}${suffix}.md`;
3693
+ counter++;
3694
+ } while (await this.fileExists(fileName));
3695
+ return fileName;
3696
+ }
3697
+ /**
3698
+ * 指定されたファイル名のファイルが存在するかチェック
3699
+ */
3700
+ async fileExists(fileName) {
3701
+ const filePath = this.pathSystem.join(this.relativePath, fileName);
3702
+ return await this.fileSystem.exists(filePath);
3703
+ }
3704
+ /**
3705
+ * 新しいMarkdownファイルを作成する
3706
+ */
3707
+ async createMdFile(fileName) {
3708
+ const actualFileName = fileName || await this.generateUniqueFileName("document");
3709
+ const mdFileName = actualFileName.endsWith(".md") ? actualFileName : `${actualFileName}.md`;
3710
+ const filePath = this.pathSystem.join(this.relativePath, mdFileName);
3711
+ const fileRef = new DocFileMdReference({
3712
+ path: filePath,
3713
+ fileSystem: this.fileSystem,
3714
+ pathSystem: this.pathSystem
3715
+ });
3716
+ await fileRef.writeDefault();
3717
+ return fileRef;
3718
+ }
3719
+ };
3720
+
3721
+ // lib/values/doc-tree-file-node-value.ts
3722
+ var DocTreeFileNodeValue = class _DocTreeFileNodeValue {
3723
+ constructor(props) {
3724
+ this.props = props;
3725
+ Object.freeze(this);
3726
+ }
3727
+ get name() {
3728
+ return this.props.name;
3729
+ }
3730
+ get path() {
3731
+ return this.props.path;
3732
+ }
3733
+ get icon() {
3734
+ return this.props.icon;
3735
+ }
3736
+ get title() {
3737
+ return this.props.title;
3738
+ }
3739
+ get type() {
3740
+ return "file";
3741
+ }
3742
+ /**
3743
+ * プレーンオブジェクトに変換
3744
+ */
3745
+ toJson() {
3746
+ return {
3747
+ name: this.name,
3748
+ path: this.path,
3749
+ type: "file",
3750
+ icon: this.icon,
3751
+ title: this.title
3752
+ };
3753
+ }
3754
+ /**
3755
+ * プロパティから作成
3756
+ */
3757
+ static from(props) {
3758
+ return new _DocTreeFileNodeValue(props);
3759
+ }
3760
+ /**
3761
+ * JSONオブジェクトから作成
3762
+ */
3763
+ static fromJson(json) {
3764
+ const parsed = zDocTreeFileNode.parse(json);
3765
+ return new _DocTreeFileNodeValue({
3766
+ name: parsed.name,
3767
+ path: parsed.path,
3768
+ icon: parsed.icon,
3769
+ title: parsed.title
3770
+ });
3771
+ }
3772
+ };
3773
+
3774
+ // lib/values/doc-tree-directory-node-value.ts
3775
+ var DocTreeDirectoryNodeValue = class _DocTreeDirectoryNodeValue {
3776
+ constructor(props) {
3777
+ this.props = props;
3778
+ Object.freeze(this);
3779
+ Object.freeze(this.props);
3780
+ Object.freeze(this.props.children);
3781
+ }
3782
+ get name() {
3783
+ return this.props.name;
3784
+ }
3785
+ get path() {
3786
+ return this.props.path;
3787
+ }
3788
+ get icon() {
3789
+ return this.props.icon;
3790
+ }
3791
+ get title() {
3792
+ return this.props.title;
3793
+ }
3794
+ get children() {
3795
+ return this.props.children;
3796
+ }
3797
+ get type() {
3798
+ return "directory";
3799
+ }
3800
+ /**
3801
+ * プレーンオブジェクトに変換
3802
+ */
3803
+ toJson() {
3804
+ return {
3805
+ name: this.name,
3806
+ path: this.path,
3807
+ type: "directory",
3808
+ icon: this.icon,
3809
+ title: this.title,
3810
+ children: this.children.map((child) => child.toJson())
3811
+ };
3812
+ }
3813
+ /**
3814
+ * プロパティから作成
3815
+ */
3816
+ static from(props) {
3817
+ return new _DocTreeDirectoryNodeValue(props);
3818
+ }
3819
+ /**
3820
+ * JSONオブジェクトから作成
3821
+ */
3822
+ static fromJson(json) {
3823
+ const parsed = zDocTreeDirectoryNode.parse(json);
3824
+ return new _DocTreeDirectoryNodeValue({
3825
+ name: parsed.name,
3826
+ path: parsed.path,
3827
+ icon: parsed.icon,
3828
+ title: parsed.title,
3829
+ children: parsed.children.map((child) => {
3830
+ const parsedChild = zDocTreeNode.parse(child);
3831
+ if (parsedChild.type === "file") {
3832
+ return DocTreeFileNodeValue.fromJson(parsedChild);
3833
+ }
3834
+ return _DocTreeDirectoryNodeValue.fromJson(parsedChild);
3835
+ })
3836
+ });
3837
+ }
3838
+ };
3839
+
3840
+ // lib/doc-file-tree-system.ts
3841
+ var DocFileTreeSystem = class {
3842
+ constructor(props) {
3843
+ this.props = props;
3844
+ Object.freeze(this);
3845
+ }
3846
+ /**
3847
+ * ファイルツリーを再帰的に構築
3848
+ */
3849
+ async buildFileTree(directoryPath = "") {
3850
+ const fileNames = await this.props.fileSystem.readDirectoryFileNames(directoryPath);
3851
+ const results = [];
3852
+ for (const fileName of fileNames) {
3853
+ if (fileName.startsWith("_")) continue;
3854
+ const filePath = directoryPath ? this.props.pathSystem.join(directoryPath, fileName) : fileName;
3855
+ const isDirectory = await this.props.fileSystem.isDirectory(filePath);
3856
+ if (!isDirectory) {
3857
+ const fileNode = await this.createFileNode(fileName, filePath);
3858
+ results.push(fileNode);
3859
+ continue;
3860
+ }
3861
+ const directoryNode = await this.createDirectoryNode(fileName, filePath);
3862
+ results.push(directoryNode);
3863
+ }
3864
+ return results;
3865
+ }
3866
+ /**
3867
+ * ファイルノードを作成
3868
+ */
3869
+ async createFileNode(fileName, filePath) {
3870
+ let title = fileName;
3871
+ let icon = "";
3872
+ if (fileName.endsWith(".md")) {
3873
+ const mdFile = this.createMdFileReference(filePath);
3874
+ if (await mdFile.exists()) {
3875
+ const entity = await mdFile.read();
3876
+ if (!(entity instanceof Error)) {
3877
+ title = entity.value.content.title || fileName;
3878
+ }
3879
+ }
3880
+ icon = "\u{1F4C4}";
3881
+ } else {
3882
+ icon = "\u{1F4C4}";
3883
+ }
3884
+ return DocTreeFileNodeValue.from({
3885
+ name: fileName,
3886
+ path: filePath,
3887
+ icon,
3888
+ title
3889
+ });
3890
+ }
3891
+ /**
3892
+ * ディレクトリノードを作成
3893
+ */
3894
+ async createDirectoryNode(fileName, filePath) {
3895
+ let title = fileName;
3896
+ let icon = "\u{1F4C1}";
3897
+ const indexFile = this.createIndexFileReference(filePath);
3898
+ if (await indexFile.exists()) {
3899
+ const entity = await indexFile.read();
3900
+ title = entity.value.content.title || fileName;
3901
+ icon = entity.value.content.frontMatter.icon || "\u{1F4C1}";
3902
+ }
3903
+ const children = await this.buildFileTree(filePath);
3904
+ return DocTreeDirectoryNodeValue.from({
3905
+ name: fileName,
3906
+ path: filePath,
3907
+ icon,
3908
+ title,
3909
+ children
3910
+ });
3911
+ }
3912
+ /**
3913
+ * インデックスファイル参照を作成
3914
+ */
3915
+ createIndexFileReference(directoryPath) {
3916
+ const indexPath = directoryPath === "" ? this.props.indexFileName : `${directoryPath}/${this.props.indexFileName}`;
3917
+ return new DocFileIndexReference({
3918
+ path: indexPath,
3919
+ fileSystem: this.props.fileSystem,
3920
+ pathSystem: this.props.pathSystem
3921
+ });
3922
+ }
3923
+ /**
3924
+ * MDファイル参照を作成
3925
+ */
3926
+ createMdFileReference(path) {
3927
+ return new DocFileMdReference({
3928
+ path,
3929
+ fileSystem: this.props.fileSystem,
3930
+ pathSystem: this.props.pathSystem
3931
+ });
3932
+ }
3933
+ /**
3934
+ * ディレクトリツリーを再帰的に構築(ディレクトリのみ)
3935
+ */
3936
+ async buildDirectoryTree(directoryPath = "") {
3937
+ const fileNames = await this.props.fileSystem.readDirectoryFileNames(directoryPath);
3938
+ const results = [];
3939
+ for (const fileName of fileNames) {
3940
+ if (fileName.startsWith("_")) continue;
3941
+ const filePath = directoryPath ? this.props.pathSystem.join(directoryPath, fileName) : fileName;
3942
+ const isDirectory = await this.props.fileSystem.isDirectory(filePath);
3943
+ if (!isDirectory) continue;
3944
+ const directoryNode = await this.createDirectoryNodeForTree(
3945
+ fileName,
3946
+ filePath
3947
+ );
3948
+ results.push(directoryNode);
3949
+ }
3950
+ return results;
3951
+ }
3952
+ /**
3953
+ * ディレクトリツリー用のディレクトリノードを作成
3954
+ */
3955
+ async createDirectoryNodeForTree(fileName, filePath) {
3956
+ let title = fileName;
3957
+ let icon = "\u{1F4C1}";
3958
+ const indexFile = this.createIndexFileReference(filePath);
3959
+ if (await indexFile.exists()) {
3960
+ const entity = await indexFile.read();
3961
+ title = entity.value.content.title || fileName;
3962
+ icon = entity.value.content.frontMatter.icon || "\u{1F4C1}";
3963
+ }
3964
+ const children = await this.buildDirectoryTree(filePath);
3965
+ return DocTreeDirectoryNodeValue.from({
3966
+ name: fileName,
3967
+ path: filePath,
3968
+ icon,
3969
+ title,
3970
+ children
3971
+ });
3972
+ }
3973
+ };
3974
+
3975
+ // lib/doc-path-system.ts
3976
+ var DocPathSystem = class {
3977
+ separator = "/";
3978
+ /**
3979
+ * パスを結合
3980
+ */
3981
+ join(...paths) {
3982
+ const parts = [];
3983
+ for (const path of paths) {
3984
+ if (path === "") continue;
3985
+ const segments = path.split(this.separator).filter(Boolean);
3986
+ parts.push(...segments);
3987
+ }
3988
+ if (parts.length === 0) {
3989
+ return ".";
3990
+ }
3991
+ const isAbsolute = paths[0]?.startsWith(this.separator);
3992
+ const joined = parts.join(this.separator);
3993
+ return isAbsolute ? `${this.separator}${joined}` : joined;
3994
+ }
3995
+ /**
3996
+ * ファイル名を取得(拡張子付き)
3997
+ */
3998
+ basename(path, ext) {
3999
+ const segments = path.split(this.separator);
4000
+ const filename = segments[segments.length - 1] || "";
4001
+ if (ext && filename.endsWith(ext)) {
4002
+ return filename.slice(0, -ext.length);
4003
+ }
4004
+ return filename;
4005
+ }
4006
+ /**
4007
+ * ディレクトリ名を取得
4008
+ */
4009
+ dirname(path) {
4010
+ const segments = path.split(this.separator);
4011
+ if (segments.length <= 1) {
4012
+ return ".";
4013
+ }
4014
+ segments.pop();
4015
+ const dir = segments.join(this.separator);
4016
+ return dir || ".";
4017
+ }
4018
+ /**
4019
+ * 拡張子を取得
4020
+ */
4021
+ extname(path) {
4022
+ const basename = this.basename(path);
4023
+ const lastDot = basename.lastIndexOf(".");
4024
+ if (lastDot <= 0) {
4025
+ return "";
4026
+ }
4027
+ return basename.slice(lastDot);
4028
+ }
4029
+ /**
4030
+ * 相対パスを計算
4031
+ */
4032
+ relative(from, to) {
4033
+ const fromSegments = from.split(this.separator).filter(Boolean);
4034
+ const toSegments = to.split(this.separator).filter(Boolean);
4035
+ let commonLength = 0;
4036
+ for (let i = 0; i < Math.min(fromSegments.length, toSegments.length); i++) {
4037
+ if (fromSegments[i] === toSegments[i]) {
4038
+ commonLength++;
4039
+ } else {
4040
+ break;
4041
+ }
4042
+ }
4043
+ const upCount = fromSegments.length - commonLength;
4044
+ const upSegments = Array(upCount).fill("..");
4045
+ const downSegments = toSegments.slice(commonLength);
4046
+ const segments = [...upSegments, ...downSegments];
4047
+ return segments.length > 0 ? segments.join(this.separator) : ".";
4048
+ }
4049
+ /**
4050
+ * 絶対パスに変換
4051
+ */
4052
+ resolve(...paths) {
4053
+ let resolved = "";
4054
+ for (const path of paths) {
4055
+ if (path.startsWith(this.separator)) {
4056
+ resolved = path;
4057
+ } else if (path !== "") {
4058
+ resolved = resolved ? this.join(resolved, path) : path;
4059
+ }
4060
+ }
4061
+ return resolved || ".";
4062
+ }
4063
+ /**
4064
+ * パスを正規化
4065
+ */
4066
+ normalize(path) {
4067
+ const isAbsolute = path.startsWith(this.separator);
4068
+ const segments = path.split(this.separator).filter(Boolean);
4069
+ const normalized = [];
4070
+ for (const segment of segments) {
4071
+ if (segment === "..") {
4072
+ if (normalized.length > 0 && normalized[normalized.length - 1] !== "..") {
4073
+ normalized.pop();
4074
+ } else if (!isAbsolute) {
4075
+ normalized.push("..");
4076
+ }
4077
+ } else if (segment !== ".") {
4078
+ normalized.push(segment);
4079
+ }
4080
+ }
4081
+ if (normalized.length === 0) {
4082
+ return isAbsolute ? this.separator : ".";
4083
+ }
4084
+ const result = normalized.join(this.separator);
4085
+ return isAbsolute ? `${this.separator}${result}` : result;
4086
+ }
4087
+ /**
4088
+ * パスが絶対パスかどうか
4089
+ */
4090
+ isAbsolute(path) {
4091
+ return path.startsWith(this.separator);
4092
+ }
4093
+ /**
4094
+ * パスのセパレータ
4095
+ */
4096
+ get sep() {
4097
+ return this.separator;
4098
+ }
4099
+ };
4100
+
4101
+ // lib/doc-client.ts
4102
+ var DocClient = class {
4103
+ fileSystem;
4104
+ pathSystem;
4105
+ markdownSystem;
4106
+ fileTreeSystem;
4107
+ indexFileName;
4108
+ archiveDirectoryName;
4109
+ constructor(props) {
4110
+ this.fileSystem = props.fileSystem;
4111
+ this.pathSystem = props.pathSystem ?? new DocPathSystem();
4112
+ this.markdownSystem = props.markdownSystem ?? new DocMarkdownSystem();
4113
+ this.indexFileName = props.indexFileName ?? "index.md";
4114
+ this.archiveDirectoryName = props.archiveDirectoryName ?? "_";
4115
+ this.fileTreeSystem = props.fileTreeSystem ?? new DocFileTreeSystem({
4116
+ fileSystem: this.fileSystem,
4117
+ pathSystem: this.pathSystem,
4118
+ indexFileName: this.indexFileName,
4119
+ archiveDirectoryName: this.archiveDirectoryName
4120
+ });
4121
+ }
4122
+ basePath() {
4123
+ return this.fileSystem.getBasePath();
4124
+ }
4125
+ /**
4126
+ * ファイル参照を取得
4127
+ */
4128
+ file(relativePath) {
4129
+ if (relativePath.endsWith(".md")) {
4130
+ return this.mdFile(relativePath);
4131
+ }
4132
+ return new DocFileUnknownReference({
4133
+ path: relativePath,
4134
+ fileSystem: this.fileSystem,
4135
+ pathSystem: this.pathSystem
4136
+ });
4137
+ }
4138
+ /**
4139
+ * Markdownファイル参照を取得
4140
+ */
4141
+ mdFile(relativePath) {
4142
+ return new DocFileMdReference({
4143
+ path: relativePath,
4144
+ fileSystem: this.fileSystem,
4145
+ pathSystem: this.pathSystem
4146
+ });
4147
+ }
4148
+ /**
4149
+ * インデックスファイル参照を取得
4150
+ */
4151
+ indexFile(directoryPath) {
4152
+ const indexPath = directoryPath === "" ? this.indexFileName : `${directoryPath}/${this.indexFileName}`;
4153
+ return new DocFileIndexReference({
4154
+ path: indexPath,
4155
+ fileSystem: this.fileSystem,
4156
+ pathSystem: this.pathSystem
4157
+ });
4158
+ }
4159
+ /**
4160
+ * ディレクトリ参照を取得
4161
+ */
4162
+ directory(relativePath) {
4163
+ return new DocDirectoryReference({
4164
+ path: relativePath,
4165
+ indexFileName: this.indexFileName,
4166
+ archiveDirectoryName: this.archiveDirectoryName,
4167
+ fileSystem: this.fileSystem,
4168
+ pathSystem: this.pathSystem
4169
+ });
4170
+ }
4171
+ /**
4172
+ * ファイルツリーを取得
4173
+ */
4174
+ async fileTree(directoryPath = "") {
4175
+ const results = await this.fileTreeSystem.buildFileTree(directoryPath);
4176
+ return results.map((node) => node.toJson());
4177
+ }
4178
+ /**
4179
+ * ディレクトリツリーを取得(ディレクトリのみ)
4180
+ */
4181
+ async directoryTree(directoryPath = "") {
4182
+ const results = await this.fileTreeSystem.buildDirectoryTree(directoryPath);
4183
+ return results.map((node) => node.toJson());
4184
+ }
4185
+ };
4186
+
4187
+ // lib/doc-file-system.ts
4188
+ import fs from "fs/promises";
4189
+ var DocFileSystem = class {
4190
+ basePath;
4191
+ pathSystem;
4192
+ constructor(props) {
4193
+ this.basePath = props.basePath;
4194
+ this.pathSystem = props.pathSystem;
4195
+ }
4196
+ /**
4197
+ * 指定されたパスのファイルの内容を読み込む
4198
+ */
4199
+ async readFile(relativePath) {
4200
+ const exists = await this.exists(relativePath);
4201
+ if (!exists) return null;
4202
+ const fullPath = this.pathSystem.join(this.basePath, relativePath);
4203
+ try {
4204
+ return await fs.readFile(fullPath, "utf-8");
4205
+ } catch {
4206
+ return null;
4207
+ }
4208
+ }
4209
+ /**
4210
+ * 指定されたパスのファイルに内容を書き込む(必要に応じてディレクトリも作成)
4211
+ */
4212
+ async writeFile(relativePath, content) {
4213
+ const fullPath = this.pathSystem.join(this.basePath, relativePath);
4214
+ const dirPath = this.pathSystem.dirname(fullPath);
4215
+ try {
4216
+ await fs.mkdir(dirPath, { recursive: true });
4217
+ await fs.writeFile(fullPath, content, "utf-8");
4218
+ } catch (error) {
4219
+ if (error instanceof Error) {
4220
+ throw error;
4221
+ }
4222
+ throw new Error(`Failed to write file at ${fullPath}`);
4223
+ }
4224
+ }
4225
+ /**
4226
+ * 指定されたパスのファイルを削除
4227
+ */
4228
+ async deleteFile(relativePath) {
4229
+ try {
4230
+ const fullPath = this.pathSystem.join(this.basePath, relativePath);
4231
+ await fs.unlink(fullPath);
4232
+ return null;
4233
+ } catch (error) {
4234
+ return new Error(`Failed to delete file at ${relativePath}: ${error}`);
4235
+ }
4236
+ }
4237
+ /**
4238
+ * 指定されたパスのファイル名を取得
4239
+ */
4240
+ readFileName(relativePath) {
4241
+ return this.pathSystem.basename(relativePath);
4242
+ }
4243
+ /**
4244
+ * 指定されたパスのファイル拡張子を取得
4245
+ */
4246
+ readFileExtension(relativePath) {
4247
+ return this.pathSystem.extname(relativePath);
4248
+ }
4249
+ /**
4250
+ * 指定されたパスのファイルが存在するディレクトリパスを取得
4251
+ */
4252
+ readFileDirectory(relativePath) {
4253
+ return this.pathSystem.dirname(relativePath);
4254
+ }
4255
+ /**
4256
+ * ディレクトリ内のエントリ一覧を取得
4257
+ */
4258
+ async readDirectoryFileNames(relativePath = "") {
4259
+ const fullPath = this.pathSystem.join(this.basePath, relativePath);
4260
+ try {
4261
+ return await fs.readdir(fullPath);
4262
+ } catch {
4263
+ return [];
4264
+ }
4265
+ }
4266
+ async readDirectoryFilePaths(relativePath) {
4267
+ const fileNames = await this.readDirectoryFileNames(relativePath);
4268
+ return fileNames.map(
4269
+ (fileName) => this.pathSystem.join(relativePath, fileName)
4270
+ );
4271
+ }
4272
+ /**
4273
+ * 指定パスがディレクトリかチェック
4274
+ */
4275
+ async isDirectory(relativePath) {
4276
+ try {
4277
+ const fullPath = this.pathSystem.join(this.basePath, relativePath);
4278
+ const stats = await fs.stat(fullPath);
4279
+ return stats.isDirectory();
4280
+ } catch {
4281
+ return false;
4282
+ }
4283
+ }
4284
+ /**
4285
+ * 指定パスがファイルかチェック
4286
+ */
4287
+ async isFile(relativePath) {
4288
+ try {
4289
+ const fullPath = this.pathSystem.join(this.basePath, relativePath);
4290
+ const stats = await fs.stat(fullPath);
4291
+ return stats.isFile();
4292
+ } catch {
4293
+ return false;
4294
+ }
4295
+ }
4296
+ /**
4297
+ * ファイルまたはディレクトリが存在するかチェック
4298
+ */
4299
+ async exists(relativePath) {
4300
+ try {
4301
+ const fullPath = this.pathSystem.join(this.basePath, relativePath);
4302
+ await fs.access(fullPath);
4303
+ return true;
4304
+ } catch {
4305
+ return false;
4306
+ }
4307
+ }
4308
+ /**
4309
+ * ディレクトリが存在するかチェック
4310
+ */
4311
+ async directoryExists(relativePath) {
4312
+ return this.isDirectory(relativePath);
4313
+ }
4314
+ /**
4315
+ * ファイルが存在するかチェック
4316
+ */
4317
+ async fileExists(relativePath) {
4318
+ return this.isFile(relativePath);
4319
+ }
4320
+ /**
4321
+ * ベースパスを取得
4322
+ */
4323
+ getBasePath() {
4324
+ return this.basePath;
4325
+ }
4326
+ /**
4327
+ * 相対パスを絶対パスに変換
4328
+ */
4329
+ resolve(relativePath) {
4330
+ return this.pathSystem.join(this.basePath, relativePath);
4331
+ }
4332
+ /**
4333
+ * ディレクトリを作成する
4334
+ */
4335
+ async createDirectory(relativePath) {
4336
+ const fullPath = this.pathSystem.join(this.basePath, relativePath);
4337
+ await fs.mkdir(fullPath, { recursive: true });
4338
+ }
4339
+ /**
4340
+ * ファイルのサイズを取得(バイト単位)
4341
+ */
4342
+ async getFileSize(relativePath) {
4343
+ const fullPath = this.pathSystem.join(this.basePath, relativePath);
4344
+ const stats = await fs.stat(fullPath);
4345
+ return stats.size;
4346
+ }
4347
+ /**
4348
+ * ディレクトリが存在しない場合は作成する
4349
+ */
4350
+ async ensureDirectoryExists(relativePath) {
4351
+ if (!await this.exists(relativePath)) {
4352
+ await this.createDirectory(relativePath);
4353
+ }
4354
+ }
4355
+ /**
4356
+ * ファイルをコピー
4357
+ */
4358
+ async copyFile(sourcePath, destinationPath) {
4359
+ const sourceFullPath = this.pathSystem.join(this.basePath, sourcePath);
4360
+ const destFullPath = this.pathSystem.join(this.basePath, destinationPath);
4361
+ await fs.copyFile(sourceFullPath, destFullPath);
4362
+ }
4363
+ /**
4364
+ * ファイルを移動
4365
+ */
4366
+ async moveFile(sourcePath, destinationPath) {
4367
+ const sourceFullPath = this.pathSystem.join(this.basePath, sourcePath);
4368
+ const destFullPath = this.pathSystem.join(this.basePath, destinationPath);
4369
+ await fs.rename(sourceFullPath, destFullPath);
4370
+ }
4371
+ /**
4372
+ * ファイルの最終更新日時を取得
4373
+ */
4374
+ async getFileModifiedTime(relativePath) {
4375
+ const fullPath = this.pathSystem.join(this.basePath, relativePath);
4376
+ const stats = await fs.stat(fullPath);
4377
+ return stats.mtime;
4378
+ }
4379
+ /**
4380
+ * ファイルの作成日時を取得
4381
+ */
4382
+ async getFileCreatedTime(relativePath) {
4383
+ const fullPath = this.pathSystem.join(this.basePath, relativePath);
4384
+ const stats = await fs.stat(fullPath);
4385
+ return stats.birthtime;
4386
+ }
4387
+ };
4388
+
4389
+ // lib/values/doc-directory-path-value.ts
4390
+ var DocDirectoryPathValue = class _DocDirectoryPathValue {
4391
+ constructor(value, pathSystem) {
4392
+ this.value = value;
4393
+ this.pathSystem = pathSystem;
4394
+ Object.freeze(this);
4395
+ }
4396
+ pathSystem;
4397
+ /**
4398
+ * 相対ディレクトリパス
4399
+ */
4400
+ get path() {
4401
+ return this.value.path;
4402
+ }
4403
+ /**
4404
+ * ディレクトリ名
4405
+ */
4406
+ get name() {
4407
+ return this.value.name;
4408
+ }
4409
+ /**
4410
+ * 親ディレクトリパスを取得
4411
+ */
4412
+ get parent() {
4413
+ if (this.path === "." || this.path === "") {
4414
+ return null;
4415
+ }
4416
+ const parentPath = this.pathSystem.dirname(this.path);
4417
+ const parentName = parentPath === "." ? "" : this.pathSystem.basename(parentPath);
4418
+ return new _DocDirectoryPathValue(
4419
+ {
4420
+ path: parentPath,
4421
+ name: parentName,
4422
+ fullPath: this.pathSystem.dirname(this.fullPath)
4423
+ },
4424
+ this.pathSystem
4425
+ );
4426
+ }
4427
+ /**
4428
+ * 親ディレクトリパス
4429
+ */
4430
+ get parentPath() {
4431
+ return this.pathSystem.dirname(this.path);
4432
+ }
4433
+ /**
4434
+ * 深さ(ディレクトリの階層数)
4435
+ */
4436
+ get depth() {
4437
+ if (this.path === "." || this.path === "") {
4438
+ return 0;
4439
+ }
4440
+ return this.path.split(this.pathSystem.sep).filter(Boolean).length;
4441
+ }
4442
+ /**
4443
+ * パスセグメント(ディレクトリの配列)
4444
+ */
4445
+ get segments() {
4446
+ return this.path.split(this.pathSystem.sep).filter(Boolean);
4447
+ }
4448
+ /**
4449
+ * ルートからの相対パス(先頭のスラッシュなし)
4450
+ */
4451
+ get normalizedPath() {
4452
+ return this.path.replace(/^\/+/, "");
4453
+ }
4454
+ /**
4455
+ * アーカイブディレクトリかどうか(ディレクトリ名が「_」の場合)
4456
+ */
4457
+ get isArchived() {
4458
+ return this.name === "_";
4459
+ }
4460
+ /**
4461
+ * 隠しディレクトリかどうか
4462
+ */
4463
+ get isHidden() {
4464
+ return this.name.startsWith(".");
4465
+ }
4466
+ /**
4467
+ * ルートディレクトリかどうか
4468
+ */
4469
+ get isRoot() {
4470
+ return this.path === "." || this.path === "";
4471
+ }
4472
+ /**
4473
+ * 絶対パス
4474
+ */
4475
+ get fullPath() {
4476
+ return this.value.fullPath;
4477
+ }
4478
+ /**
4479
+ * インデックスファイルのパスを取得
4480
+ */
4481
+ get indexFile() {
4482
+ return DocFilePathValue.fromPathWithSystem(
4483
+ this.pathSystem.join(this.path, "index.md"),
4484
+ this.pathSystem,
4485
+ this.pathSystem.dirname(this.fullPath)
4486
+ );
4487
+ }
4488
+ /**
4489
+ * ファイルパスを作成
4490
+ */
4491
+ file(fileName) {
4492
+ return DocFilePathValue.fromPathWithSystem(
4493
+ this.pathSystem.join(this.path, fileName),
4494
+ this.pathSystem,
4495
+ this.pathSystem.dirname(this.fullPath)
4496
+ );
4497
+ }
4498
+ /**
4499
+ * サブディレクトリのパスを作成
4500
+ */
4501
+ subdirectory(dirName) {
4502
+ const subPath = this.pathSystem.join(this.path, dirName);
4503
+ return new _DocDirectoryPathValue(
4504
+ {
4505
+ path: subPath,
4506
+ name: dirName,
4507
+ fullPath: this.pathSystem.join(this.fullPath, dirName)
4508
+ },
4509
+ this.pathSystem
4510
+ );
4511
+ }
4512
+ /**
4513
+ * 相対パスからインスタンスを生成(DI対応)
4514
+ */
4515
+ static fromPathWithSystem(dirPath, basePath, pathSystem) {
4516
+ const name = dirPath === "." ? "" : pathSystem.basename(dirPath);
4517
+ const fullPath = dirPath === "." ? basePath : pathSystem.join(basePath, dirPath);
4518
+ return new _DocDirectoryPathValue(
4519
+ {
4520
+ path: dirPath,
4521
+ name,
4522
+ fullPath
4523
+ },
4524
+ pathSystem
4525
+ );
4526
+ }
4527
+ /**
4528
+ * JSON形式で出力
4529
+ */
4530
+ toJson() {
4531
+ return this.value;
4532
+ }
4533
+ /**
4534
+ * パスが等しいかどうか
4535
+ */
4536
+ equals(other) {
4537
+ return this.path === other.path;
4538
+ }
4539
+ /**
4540
+ * 指定されたディレクトリがこのディレクトリの子孫かどうか
4541
+ */
4542
+ contains(other) {
4543
+ const relative = this.pathSystem.relative(this.path, other.path);
4544
+ return !relative.startsWith("..") && relative !== "";
4545
+ }
4546
+ };
4547
+ export {
4548
+ DocClient,
4549
+ DocContentMdValue,
4550
+ DocDirectoryPathValue,
4551
+ DocDirectoryReference,
4552
+ DocFileContentIndexValue,
4553
+ DocFileContentMdValue,
4554
+ DocFileIndexEntity,
4555
+ DocFileIndexReference,
4556
+ DocFileMdEntity,
4557
+ DocFileMdReference,
4558
+ DocFilePathValue,
4559
+ DocFileRelationReference,
4560
+ DocFileSystem,
4561
+ DocFileUnknownEntity,
4562
+ DocFileUnknownReference,
4563
+ DocFrontMatterIndexValue,
4564
+ DocFrontMatterMdValue,
4565
+ DocMarkdownSystem,
4566
+ DocPathSystem,
4567
+ DocRelationFileValue,
4568
+ DocRelationValue,
4569
+ DocSchemaFieldBooleanMultipleValue,
4570
+ DocSchemaFieldBooleanSingleValue,
4571
+ DocSchemaFieldFactory,
4572
+ DocSchemaFieldNumberMultipleValue,
4573
+ DocSchemaFieldNumberSingleValue,
4574
+ DocSchemaFieldRelationMultipleValue,
4575
+ DocSchemaFieldRelationSingleValue,
4576
+ DocSchemaFieldSelectNumberMultipleValue,
4577
+ DocSchemaFieldSelectNumberSingleValue,
4578
+ DocSchemaFieldSelectTextMultipleValue,
4579
+ DocSchemaFieldSelectTextSingleValue,
4580
+ DocSchemaFieldTextMultipleValue,
4581
+ DocSchemaFieldTextSingleValue,
4582
+ DocSchemaValue,
4583
+ DocTreeDirectoryNodeValue,
4584
+ DocTreeFileNodeValue,
4585
+ DocFileTreeSystem as FileTreeSystem,
4586
+ zDocFile,
4587
+ zDocFileContentIndex,
4588
+ zDocFileContentMd,
4589
+ zDocFileIndex,
4590
+ zDocFileIndexFrontMatter,
4591
+ zDocFileMd,
4592
+ zDocFileMdFrontMatter,
4593
+ zDocFilePath,
4594
+ zDocFileUnknown,
4595
+ zDocRelation,
4596
+ zDocRelationField,
4597
+ zDocRelationFile,
4598
+ zDocSchema,
4599
+ zDocSchemaField,
4600
+ zDocSchemaFieldBoolean,
4601
+ zDocSchemaFieldMultiBoolean,
4602
+ zDocSchemaFieldMultiNumber,
4603
+ zDocSchemaFieldMultiRelation,
4604
+ zDocSchemaFieldMultiSelectNumber,
4605
+ zDocSchemaFieldMultiSelectText,
4606
+ zDocSchemaFieldMultiText,
4607
+ zDocSchemaFieldNumber,
4608
+ zDocSchemaFieldRelation,
4609
+ zDocSchemaFieldSelectNumber,
4610
+ zDocSchemaFieldSelectText,
4611
+ zDocSchemaFieldText,
4612
+ zDocSchemaFieldType,
4613
+ zDocTreeDirectoryNode,
4614
+ zDocTreeFileNode,
4615
+ zDocTreeNode
4616
+ };