@interactive-inc/docs-client 0.0.4 → 0.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +228 -0
- package/build/doc-client.d.ts +59 -0
- package/build/doc-client.d.ts.map +1 -0
- package/build/doc-client.js +95 -0
- package/build/doc-client.test.d.ts +2 -0
- package/build/doc-client.test.d.ts.map +1 -0
- package/build/doc-client.test.js +38 -0
- package/build/doc-directory-reference.d.ts +65 -0
- package/build/doc-directory-reference.d.ts.map +1 -0
- package/build/doc-directory-reference.js +292 -0
- package/build/doc-directory-reference.test.d.ts +2 -0
- package/build/doc-directory-reference.test.d.ts.map +1 -0
- package/build/doc-directory-reference.test.js +100 -0
- package/build/doc-file-index-reference.d.ts +72 -0
- package/build/doc-file-index-reference.d.ts.map +1 -0
- package/build/doc-file-index-reference.js +191 -0
- package/build/doc-file-index-reference.test.d.ts +2 -0
- package/build/doc-file-index-reference.test.d.ts.map +1 -0
- package/build/doc-file-index-reference.test.js +77 -0
- package/build/doc-file-md-reference.d.ts +97 -0
- package/build/doc-file-md-reference.d.ts.map +1 -0
- package/build/doc-file-md-reference.js +297 -0
- package/build/doc-file-md-reference.test.d.ts +2 -0
- package/build/doc-file-md-reference.test.d.ts.map +1 -0
- package/build/doc-file-md-reference.test.js +465 -0
- package/build/doc-file-relation-reference.d.ts +54 -0
- package/build/doc-file-relation-reference.d.ts.map +1 -0
- package/build/doc-file-relation-reference.js +109 -0
- package/build/doc-file-system-debug.d.ts +81 -0
- package/build/doc-file-system-debug.d.ts.map +1 -0
- package/build/doc-file-system-debug.js +317 -0
- package/build/doc-file-system.d.ts +100 -0
- package/build/doc-file-system.d.ts.map +1 -0
- package/build/doc-file-system.js +210 -0
- package/build/doc-file-tree-system.d.ts +38 -0
- package/build/doc-file-tree-system.d.ts.map +1 -0
- package/build/doc-file-tree-system.js +153 -0
- package/build/doc-file-tree-system.test.d.ts +2 -0
- package/build/doc-file-tree-system.test.d.ts.map +1 -0
- package/build/doc-file-tree-system.test.js +105 -0
- package/build/doc-file-unknown-reference.d.ts +80 -0
- package/build/doc-file-unknown-reference.d.ts.map +1 -0
- package/build/doc-file-unknown-reference.js +181 -0
- package/build/doc-file-unknown-reference.test.d.ts +2 -0
- package/build/doc-file-unknown-reference.test.d.ts.map +1 -0
- package/build/doc-file-unknown-reference.test.js +73 -0
- package/build/doc-markdown-system.d.ts +44 -0
- package/build/doc-markdown-system.d.ts.map +1 -0
- package/build/doc-markdown-system.js +153 -0
- package/build/doc-markdown-system.test.d.ts +2 -0
- package/build/doc-markdown-system.test.d.ts.map +1 -0
- package/build/doc-markdown-system.test.js +124 -0
- package/build/doc-path-system.d.ts +43 -0
- package/build/doc-path-system.d.ts.map +1 -0
- package/build/doc-path-system.js +148 -0
- package/build/doc-path-system.test.d.ts +2 -0
- package/build/doc-path-system.test.d.ts.map +1 -0
- package/build/doc-path-system.test.js +67 -0
- package/build/entities/doc-file-entity.d.ts +5 -0
- package/build/entities/doc-file-entity.d.ts.map +1 -0
- package/build/entities/doc-file-entity.js +1 -0
- package/build/entities/doc-file-index-entity.d.ts +30 -0
- package/build/entities/doc-file-index-entity.d.ts.map +1 -0
- package/build/entities/doc-file-index-entity.js +49 -0
- package/build/entities/doc-file-index-entity.test.d.ts +2 -0
- package/build/entities/doc-file-index-entity.test.d.ts.map +1 -0
- package/build/entities/doc-file-index-entity.test.js +195 -0
- package/build/entities/doc-file-md-entity.d.ts +30 -0
- package/build/entities/doc-file-md-entity.d.ts.map +1 -0
- package/build/entities/doc-file-md-entity.js +49 -0
- package/build/entities/doc-file-md-entity.test.d.ts +2 -0
- package/build/entities/doc-file-md-entity.test.d.ts.map +1 -0
- package/build/entities/doc-file-md-entity.test.js +178 -0
- package/build/entities/doc-file-unknown-entity.d.ts +26 -0
- package/build/entities/doc-file-unknown-entity.d.ts.map +1 -0
- package/build/entities/doc-file-unknown-entity.js +45 -0
- package/build/entities/doc-file-unknown-entity.test.d.ts +2 -0
- package/build/entities/doc-file-unknown-entity.test.d.ts.map +1 -0
- package/build/entities/doc-file-unknown-entity.test.js +131 -0
- package/build/index.d.ts +42 -0
- package/build/index.d.ts.map +1 -0
- package/build/index.js +39 -24064
- package/build/models.d.ts +818 -0
- package/build/models.d.ts.map +1 -0
- package/build/models.js +312 -0
- package/build/types.d.ts +154 -0
- package/build/types.d.ts.map +1 -0
- package/build/types.js +1 -0
- package/build/values/doc-content-md-front-matter-value.d.ts +49 -0
- package/build/values/doc-content-md-front-matter-value.d.ts.map +1 -0
- package/build/values/doc-content-md-front-matter-value.js +94 -0
- package/build/values/doc-content-md-front-matter-value.test.d.ts +2 -0
- package/build/values/doc-content-md-front-matter-value.test.d.ts.map +1 -0
- package/build/values/doc-content-md-front-matter-value.test.js +73 -0
- package/build/values/doc-content-md-value.d.ts +66 -0
- package/build/values/doc-content-md-value.d.ts.map +1 -0
- package/build/values/doc-content-md-value.js +218 -0
- package/build/values/doc-content-md-value.test.d.ts +2 -0
- package/build/values/doc-content-md-value.test.d.ts.map +1 -0
- package/build/values/doc-content-md-value.test.js +179 -0
- package/build/values/doc-directory-path-value.d.ts +89 -0
- package/build/values/doc-directory-path-value.d.ts.map +1 -0
- package/build/values/doc-directory-path-value.js +145 -0
- package/build/values/doc-directory-path-value.test.d.ts +2 -0
- package/build/values/doc-directory-path-value.test.d.ts.map +1 -0
- package/build/values/doc-directory-path-value.test.js +68 -0
- package/build/values/doc-file-content-index-value.d.ts +62 -0
- package/build/values/doc-file-content-index-value.d.ts.map +1 -0
- package/build/values/doc-file-content-index-value.js +134 -0
- package/build/values/doc-file-content-index-value.test.d.ts +2 -0
- package/build/values/doc-file-content-index-value.test.d.ts.map +1 -0
- package/build/values/doc-file-content-index-value.test.js +203 -0
- package/build/values/doc-file-content-md-value.d.ts +62 -0
- package/build/values/doc-file-content-md-value.d.ts.map +1 -0
- package/build/values/doc-file-content-md-value.js +139 -0
- package/build/values/doc-file-content-md-value.test.d.ts +2 -0
- package/build/values/doc-file-content-md-value.test.d.ts.map +1 -0
- package/build/values/doc-file-content-md-value.test.js +160 -0
- package/build/values/doc-file-path-value.d.ts +47 -0
- package/build/values/doc-file-path-value.d.ts.map +1 -0
- package/build/values/doc-file-path-value.js +83 -0
- package/build/values/doc-file-path-value.test.d.ts +2 -0
- package/build/values/doc-file-path-value.test.d.ts.map +1 -0
- package/build/values/doc-file-path-value.test.js +84 -0
- package/build/values/doc-front-matter-index-value.d.ts +66 -0
- package/build/values/doc-front-matter-index-value.d.ts.map +1 -0
- package/build/values/doc-front-matter-index-value.js +185 -0
- package/build/values/doc-front-matter-index-value.test.d.ts +2 -0
- package/build/values/doc-front-matter-index-value.test.d.ts.map +1 -0
- package/build/values/doc-front-matter-index-value.test.js +98 -0
- package/build/values/doc-front-matter-md-value-accessor.test.d.ts +2 -0
- package/build/values/doc-front-matter-md-value-accessor.test.d.ts.map +1 -0
- package/build/values/doc-front-matter-md-value-accessor.test.js +226 -0
- package/build/values/doc-front-matter-md-value.d.ts +80 -0
- package/build/values/doc-front-matter-md-value.d.ts.map +1 -0
- package/build/values/doc-front-matter-md-value.js +257 -0
- package/build/values/doc-front-matter-md-value.test.d.ts +2 -0
- package/build/values/doc-front-matter-md-value.test.d.ts.map +1 -0
- package/build/values/doc-front-matter-md-value.test.js +198 -0
- package/build/values/doc-relation-field-value.d.ts +57 -0
- package/build/values/doc-relation-field-value.d.ts.map +1 -0
- package/build/values/doc-relation-field-value.js +85 -0
- package/build/values/doc-relation-field-value.test.d.ts +2 -0
- package/build/values/doc-relation-field-value.test.d.ts.map +1 -0
- package/build/values/doc-relation-field-value.test.js +115 -0
- package/build/values/doc-relation-file-value.d.ts +33 -0
- package/build/values/doc-relation-file-value.d.ts.map +1 -0
- package/build/values/doc-relation-file-value.js +55 -0
- package/build/values/doc-relation-file-value.test.d.ts +2 -0
- package/build/values/doc-relation-file-value.test.d.ts.map +1 -0
- package/build/values/doc-relation-file-value.test.js +77 -0
- package/build/values/doc-relation-value.d.ts +34 -0
- package/build/values/doc-relation-value.d.ts.map +1 -0
- package/build/values/doc-relation-value.js +56 -0
- package/build/values/doc-relation-value.test.d.ts +2 -0
- package/build/values/doc-relation-value.test.d.ts.map +1 -0
- package/build/values/doc-relation-value.test.js +89 -0
- package/build/values/doc-schema-field-boolean-multiple-value.d.ts +23 -0
- package/build/values/doc-schema-field-boolean-multiple-value.d.ts.map +1 -0
- package/build/values/doc-schema-field-boolean-multiple-value.js +43 -0
- package/build/values/doc-schema-field-boolean-multiple-value.test.d.ts +2 -0
- package/build/values/doc-schema-field-boolean-multiple-value.test.d.ts.map +1 -0
- package/build/values/doc-schema-field-boolean-multiple-value.test.js +76 -0
- package/build/values/doc-schema-field-boolean-single-value.d.ts +23 -0
- package/build/values/doc-schema-field-boolean-single-value.d.ts.map +1 -0
- package/build/values/doc-schema-field-boolean-single-value.js +39 -0
- package/build/values/doc-schema-field-boolean-single-value.test.d.ts +2 -0
- package/build/values/doc-schema-field-boolean-single-value.test.d.ts.map +1 -0
- package/build/values/doc-schema-field-boolean-single-value.test.js +73 -0
- package/build/values/doc-schema-field-factory.d.ts +37 -0
- package/build/values/doc-schema-field-factory.d.ts.map +1 -0
- package/build/values/doc-schema-field-factory.js +151 -0
- package/build/values/doc-schema-field-factory.test.d.ts +2 -0
- package/build/values/doc-schema-field-factory.test.d.ts.map +1 -0
- package/build/values/doc-schema-field-factory.test.js +215 -0
- package/build/values/doc-schema-field-number-multiple-value.d.ts +23 -0
- package/build/values/doc-schema-field-number-multiple-value.d.ts.map +1 -0
- package/build/values/doc-schema-field-number-multiple-value.js +43 -0
- package/build/values/doc-schema-field-number-multiple-value.test.d.ts +2 -0
- package/build/values/doc-schema-field-number-multiple-value.test.d.ts.map +1 -0
- package/build/values/doc-schema-field-number-multiple-value.test.js +79 -0
- package/build/values/doc-schema-field-number-single-value.d.ts +23 -0
- package/build/values/doc-schema-field-number-single-value.d.ts.map +1 -0
- package/build/values/doc-schema-field-number-single-value.js +39 -0
- package/build/values/doc-schema-field-number-single-value.test.d.ts +2 -0
- package/build/values/doc-schema-field-number-single-value.test.d.ts.map +1 -0
- package/build/values/doc-schema-field-number-single-value.test.js +77 -0
- package/build/values/doc-schema-field-relation-multiple-value.d.ts +24 -0
- package/build/values/doc-schema-field-relation-multiple-value.d.ts.map +1 -0
- package/build/values/doc-schema-field-relation-multiple-value.js +46 -0
- package/build/values/doc-schema-field-relation-multiple-value.test.d.ts +2 -0
- package/build/values/doc-schema-field-relation-multiple-value.test.d.ts.map +1 -0
- package/build/values/doc-schema-field-relation-multiple-value.test.js +83 -0
- package/build/values/doc-schema-field-relation-single-value.d.ts +24 -0
- package/build/values/doc-schema-field-relation-single-value.d.ts.map +1 -0
- package/build/values/doc-schema-field-relation-single-value.js +42 -0
- package/build/values/doc-schema-field-relation-single-value.test.d.ts +2 -0
- package/build/values/doc-schema-field-relation-single-value.test.d.ts.map +1 -0
- package/build/values/doc-schema-field-relation-single-value.test.js +83 -0
- package/build/values/doc-schema-field-select-number-multiple-value.d.ts +25 -0
- package/build/values/doc-schema-field-select-number-multiple-value.d.ts.map +1 -0
- package/build/values/doc-schema-field-select-number-multiple-value.js +48 -0
- package/build/values/doc-schema-field-select-number-multiple-value.test.d.ts +2 -0
- package/build/values/doc-schema-field-select-number-multiple-value.test.d.ts.map +1 -0
- package/build/values/doc-schema-field-select-number-multiple-value.test.js +84 -0
- package/build/values/doc-schema-field-select-number-single-value.d.ts +25 -0
- package/build/values/doc-schema-field-select-number-single-value.d.ts.map +1 -0
- package/build/values/doc-schema-field-select-number-single-value.js +45 -0
- package/build/values/doc-schema-field-select-number-single-value.test.d.ts +2 -0
- package/build/values/doc-schema-field-select-number-single-value.test.d.ts.map +1 -0
- package/build/values/doc-schema-field-select-number-single-value.test.js +96 -0
- package/build/values/doc-schema-field-select-text-multiple-value.d.ts +25 -0
- package/build/values/doc-schema-field-select-text-multiple-value.d.ts.map +1 -0
- package/build/values/doc-schema-field-select-text-multiple-value.js +48 -0
- package/build/values/doc-schema-field-select-text-multiple-value.test.d.ts +2 -0
- package/build/values/doc-schema-field-select-text-multiple-value.test.d.ts.map +1 -0
- package/build/values/doc-schema-field-select-text-multiple-value.test.js +84 -0
- package/build/values/doc-schema-field-select-text-single-value.d.ts +25 -0
- package/build/values/doc-schema-field-select-text-single-value.d.ts.map +1 -0
- package/build/values/doc-schema-field-select-text-single-value.js +47 -0
- package/build/values/doc-schema-field-select-text-single-value.test.d.ts +2 -0
- package/build/values/doc-schema-field-select-text-single-value.test.d.ts.map +1 -0
- package/build/values/doc-schema-field-select-text-single-value.test.js +96 -0
- package/build/values/doc-schema-field-text-multiple-value.d.ts +23 -0
- package/build/values/doc-schema-field-text-multiple-value.d.ts.map +1 -0
- package/build/values/doc-schema-field-text-multiple-value.js +43 -0
- package/build/values/doc-schema-field-text-multiple-value.test.d.ts +2 -0
- package/build/values/doc-schema-field-text-multiple-value.test.d.ts.map +1 -0
- package/build/values/doc-schema-field-text-multiple-value.test.js +78 -0
- package/build/values/doc-schema-field-text-single-value.d.ts +23 -0
- package/build/values/doc-schema-field-text-single-value.d.ts.map +1 -0
- package/build/values/doc-schema-field-text-single-value.js +39 -0
- package/build/values/doc-schema-field-text-single-value.test.d.ts +2 -0
- package/build/values/doc-schema-field-text-single-value.test.d.ts.map +1 -0
- package/build/values/doc-schema-field-text-single-value.test.js +76 -0
- package/build/values/doc-schema-field-type-value.d.ts +61 -0
- package/build/values/doc-schema-field-type-value.d.ts.map +1 -0
- package/build/values/doc-schema-field-type-value.js +134 -0
- package/build/values/doc-schema-field-type-value.test.d.ts +2 -0
- package/build/values/doc-schema-field-type-value.test.d.ts.map +1 -0
- package/build/values/doc-schema-field-type-value.test.js +101 -0
- package/build/values/doc-schema-field-value.d.ts +45 -0
- package/build/values/doc-schema-field-value.d.ts.map +1 -0
- package/build/values/doc-schema-field-value.js +1 -0
- package/build/values/doc-schema-value.d.ts +99 -0
- package/build/values/doc-schema-value.d.ts.map +1 -0
- package/build/values/doc-schema-value.js +269 -0
- package/build/values/doc-schema-value.test.d.ts +2 -0
- package/build/values/doc-schema-value.test.d.ts.map +1 -0
- package/build/values/doc-schema-value.test.js +301 -0
- package/build/values/doc-tree-directory-node-value.d.ts +36 -0
- package/build/values/doc-tree-directory-node-value.d.ts.map +1 -0
- package/build/values/doc-tree-directory-node-value.js +71 -0
- package/build/values/doc-tree-directory-node-value.test.d.ts +2 -0
- package/build/values/doc-tree-directory-node-value.test.d.ts.map +1 -0
- package/build/values/doc-tree-directory-node-value.test.js +162 -0
- package/build/values/doc-tree-file-node-value.d.ts +33 -0
- package/build/values/doc-tree-file-node-value.d.ts.map +1 -0
- package/build/values/doc-tree-file-node-value.js +56 -0
- package/build/values/doc-tree-file-node-value.test.d.ts +2 -0
- package/build/values/doc-tree-file-node-value.test.d.ts.map +1 -0
- package/build/values/doc-tree-file-node-value.test.js +113 -0
- package/debug/debug.ts +108 -0
- package/package.json +7 -45
- package/bin/docs.js +0 -3
- package/build/assets/index.css +0 -1
- package/build/assets/index.js +0 -298
- package/build/index.html +0 -13
|
@@ -0,0 +1,292 @@
|
|
|
1
|
+
import { DocFileIndexReference } from "./doc-file-index-reference";
|
|
2
|
+
import { DocFileMdReference } from "./doc-file-md-reference";
|
|
3
|
+
import { DocFileUnknownReference } from "./doc-file-unknown-reference";
|
|
4
|
+
import { DocFileIndexEntity } from "./entities/doc-file-index-entity";
|
|
5
|
+
import { DocFileMdEntity } from "./entities/doc-file-md-entity";
|
|
6
|
+
import { DocFileUnknownEntity } from "./entities/doc-file-unknown-entity";
|
|
7
|
+
/**
|
|
8
|
+
* ディレクトリの参照
|
|
9
|
+
*/
|
|
10
|
+
export class DocDirectoryReference {
|
|
11
|
+
props;
|
|
12
|
+
pathSystem;
|
|
13
|
+
constructor(props) {
|
|
14
|
+
this.props = props;
|
|
15
|
+
this.pathSystem = props.pathSystem;
|
|
16
|
+
Object.freeze(this);
|
|
17
|
+
}
|
|
18
|
+
get fileSystem() {
|
|
19
|
+
return this.props.fileSystem;
|
|
20
|
+
}
|
|
21
|
+
get basePath() {
|
|
22
|
+
return this.fileSystem.getBasePath();
|
|
23
|
+
}
|
|
24
|
+
get relativePath() {
|
|
25
|
+
return this.props.path;
|
|
26
|
+
}
|
|
27
|
+
get absolutePath() {
|
|
28
|
+
return this.pathSystem.join(this.basePath, this.relativePath);
|
|
29
|
+
}
|
|
30
|
+
get indexFileName() {
|
|
31
|
+
return this.props.indexFileName;
|
|
32
|
+
}
|
|
33
|
+
get indexFilePath() {
|
|
34
|
+
return this.pathSystem.join(this.basePath, this.relativePath, this.props.indexFileName);
|
|
35
|
+
}
|
|
36
|
+
get archiveDirectoryName() {
|
|
37
|
+
return this.props.archiveDirectoryName;
|
|
38
|
+
}
|
|
39
|
+
async fileNames() {
|
|
40
|
+
const filePaths = await this.fileSystem.readDirectoryFilePaths(this.relativePath);
|
|
41
|
+
return filePaths
|
|
42
|
+
.map((p) => this.pathSystem.basename(p))
|
|
43
|
+
.filter((name) => name.includes("."));
|
|
44
|
+
}
|
|
45
|
+
async archivedFileNames() {
|
|
46
|
+
const archivePath = this.pathSystem.join(this.relativePath, this.archiveDirectoryName);
|
|
47
|
+
const filePaths = await this.fileSystem.readDirectoryFilePaths(archivePath);
|
|
48
|
+
return filePaths
|
|
49
|
+
.map((p) => this.pathSystem.basename(p))
|
|
50
|
+
.filter((name) => name.includes("."));
|
|
51
|
+
}
|
|
52
|
+
async *filesGenerator() {
|
|
53
|
+
const fileNames = await this.fileNames();
|
|
54
|
+
// 通常のファイルを処理
|
|
55
|
+
for (const fileName of fileNames) {
|
|
56
|
+
if (fileName === "index.md")
|
|
57
|
+
continue;
|
|
58
|
+
if (fileName.endsWith(".md")) {
|
|
59
|
+
yield new DocFileMdReference({
|
|
60
|
+
path: this.pathSystem.join(this.relativePath, fileName),
|
|
61
|
+
fileSystem: this.fileSystem,
|
|
62
|
+
pathSystem: this.pathSystem,
|
|
63
|
+
});
|
|
64
|
+
continue;
|
|
65
|
+
}
|
|
66
|
+
yield new DocFileUnknownReference({
|
|
67
|
+
path: this.pathSystem.join(this.relativePath, fileName),
|
|
68
|
+
fileSystem: this.fileSystem,
|
|
69
|
+
pathSystem: this.pathSystem,
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
// アーカイブされたファイルを処理
|
|
73
|
+
const archivedFileNames = await this.archivedFileNames();
|
|
74
|
+
for (const fileName of archivedFileNames) {
|
|
75
|
+
if (fileName === "index.md")
|
|
76
|
+
continue;
|
|
77
|
+
if (fileName.endsWith(".md")) {
|
|
78
|
+
yield new DocFileMdReference({
|
|
79
|
+
path: this.pathSystem.join(this.relativePath, this.archiveDirectoryName, fileName),
|
|
80
|
+
fileSystem: this.fileSystem,
|
|
81
|
+
pathSystem: this.pathSystem,
|
|
82
|
+
});
|
|
83
|
+
continue;
|
|
84
|
+
}
|
|
85
|
+
yield new DocFileUnknownReference({
|
|
86
|
+
path: this.pathSystem.join(this.relativePath, this.archiveDirectoryName, fileName),
|
|
87
|
+
fileSystem: this.fileSystem,
|
|
88
|
+
pathSystem: this.pathSystem,
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
async *mdFilesGenerator() {
|
|
93
|
+
const files = this.filesGenerator();
|
|
94
|
+
for await (const file of files) {
|
|
95
|
+
if (file instanceof DocFileMdReference) {
|
|
96
|
+
yield file;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
async files() {
|
|
101
|
+
const files = [];
|
|
102
|
+
for await (const file of this.filesGenerator()) {
|
|
103
|
+
files.push(file);
|
|
104
|
+
}
|
|
105
|
+
return files;
|
|
106
|
+
}
|
|
107
|
+
async mdFiles() {
|
|
108
|
+
const files = [];
|
|
109
|
+
for await (const file of this.filesGenerator()) {
|
|
110
|
+
if (file instanceof DocFileUnknownReference)
|
|
111
|
+
continue;
|
|
112
|
+
files.push(file);
|
|
113
|
+
}
|
|
114
|
+
return files;
|
|
115
|
+
}
|
|
116
|
+
file(fileName) {
|
|
117
|
+
const filePath = this.pathSystem.join(this.relativePath, fileName);
|
|
118
|
+
if (fileName.endsWith(".md")) {
|
|
119
|
+
return new DocFileMdReference({
|
|
120
|
+
path: filePath,
|
|
121
|
+
fileSystem: this.fileSystem,
|
|
122
|
+
pathSystem: this.pathSystem,
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
return new DocFileUnknownReference({
|
|
126
|
+
path: filePath,
|
|
127
|
+
fileSystem: this.fileSystem,
|
|
128
|
+
pathSystem: this.pathSystem,
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
mdFile(fileName) {
|
|
132
|
+
return new DocFileMdReference({
|
|
133
|
+
path: this.pathSystem.join(this.relativePath, fileName),
|
|
134
|
+
fileSystem: this.fileSystem,
|
|
135
|
+
pathSystem: this.pathSystem,
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
async readFiles() {
|
|
139
|
+
const entities = [];
|
|
140
|
+
for await (const file of this.filesGenerator()) {
|
|
141
|
+
const entity = await file.read();
|
|
142
|
+
if (entity instanceof Error)
|
|
143
|
+
continue;
|
|
144
|
+
entities.push(entity);
|
|
145
|
+
}
|
|
146
|
+
return entities;
|
|
147
|
+
}
|
|
148
|
+
async readMdFiles() {
|
|
149
|
+
const entities = [];
|
|
150
|
+
for await (const file of this.filesGenerator()) {
|
|
151
|
+
const entity = await file.read();
|
|
152
|
+
if (entity instanceof Error)
|
|
153
|
+
continue;
|
|
154
|
+
if (entity instanceof DocFileUnknownEntity)
|
|
155
|
+
continue;
|
|
156
|
+
entities.push(entity);
|
|
157
|
+
}
|
|
158
|
+
return entities;
|
|
159
|
+
}
|
|
160
|
+
async readUnknownFiles() {
|
|
161
|
+
const entities = [];
|
|
162
|
+
for await (const file of this.filesGenerator()) {
|
|
163
|
+
const entity = await file.read();
|
|
164
|
+
if (entity instanceof Error)
|
|
165
|
+
continue;
|
|
166
|
+
if (entity instanceof DocFileMdEntity)
|
|
167
|
+
continue;
|
|
168
|
+
entities.push(entity);
|
|
169
|
+
}
|
|
170
|
+
return entities;
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* サブディレクトリ名の一覧を取得
|
|
174
|
+
*/
|
|
175
|
+
async directoryNames() {
|
|
176
|
+
const allFileNames = await this.fileSystem.readDirectoryFileNames(this.relativePath);
|
|
177
|
+
const directoryNames = [];
|
|
178
|
+
for (const fileName of allFileNames) {
|
|
179
|
+
// アーカイブディレクトリは除外
|
|
180
|
+
if (fileName.startsWith(this.archiveDirectoryName))
|
|
181
|
+
continue;
|
|
182
|
+
const filePath = this.pathSystem.join(this.relativePath, fileName);
|
|
183
|
+
const isDirectory = await this.fileSystem.isDirectory(filePath);
|
|
184
|
+
if (isDirectory) {
|
|
185
|
+
directoryNames.push(fileName);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
return directoryNames;
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* サブディレクトリの参照を取得
|
|
192
|
+
*/
|
|
193
|
+
async directories() {
|
|
194
|
+
const directoryNames = await this.directoryNames();
|
|
195
|
+
return directoryNames.map((dirName) => {
|
|
196
|
+
const dirPath = this.pathSystem.join(this.relativePath, dirName);
|
|
197
|
+
return new DocDirectoryReference({
|
|
198
|
+
path: dirPath,
|
|
199
|
+
indexFileName: this.indexFileName,
|
|
200
|
+
archiveDirectoryName: this.archiveDirectoryName,
|
|
201
|
+
fileSystem: this.fileSystem,
|
|
202
|
+
pathSystem: this.pathSystem,
|
|
203
|
+
});
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* 単一のサブディレクトリ参照を取得
|
|
208
|
+
*/
|
|
209
|
+
directory(directoryName) {
|
|
210
|
+
const dirPath = this.pathSystem.join(this.relativePath, directoryName);
|
|
211
|
+
return new DocDirectoryReference({
|
|
212
|
+
path: dirPath,
|
|
213
|
+
indexFileName: this.indexFileName,
|
|
214
|
+
archiveDirectoryName: this.archiveDirectoryName,
|
|
215
|
+
fileSystem: this.fileSystem,
|
|
216
|
+
pathSystem: this.pathSystem,
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
indexFile() {
|
|
220
|
+
return new DocFileIndexReference({
|
|
221
|
+
path: this.pathSystem.join(this.relativePath, this.indexFileName),
|
|
222
|
+
fileSystem: this.fileSystem,
|
|
223
|
+
pathSystem: this.pathSystem,
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
async readIndexFile() {
|
|
227
|
+
const ref = this.indexFile();
|
|
228
|
+
return ref.read();
|
|
229
|
+
}
|
|
230
|
+
async writeFile(entity) {
|
|
231
|
+
const filePath = this.pathSystem.join(this.relativePath, entity.value.path.nameWithExtension);
|
|
232
|
+
let content = null;
|
|
233
|
+
if (entity instanceof DocFileUnknownEntity) {
|
|
234
|
+
content = entity.value.content;
|
|
235
|
+
}
|
|
236
|
+
if (entity instanceof DocFileIndexEntity) {
|
|
237
|
+
content = entity.content.toText();
|
|
238
|
+
}
|
|
239
|
+
if (entity instanceof DocFileMdEntity) {
|
|
240
|
+
content = entity.content.toText();
|
|
241
|
+
}
|
|
242
|
+
if (content === null) {
|
|
243
|
+
return new Error("Entity content is undefined");
|
|
244
|
+
}
|
|
245
|
+
await this.fileSystem.writeFile(filePath, content);
|
|
246
|
+
return null;
|
|
247
|
+
}
|
|
248
|
+
async exists() {
|
|
249
|
+
return await this.fileSystem.exists(this.relativePath);
|
|
250
|
+
}
|
|
251
|
+
/**
|
|
252
|
+
* 一意なファイル名を生成する
|
|
253
|
+
*/
|
|
254
|
+
async generateUniqueFileName(prefix = "document") {
|
|
255
|
+
const now = new Date();
|
|
256
|
+
const timestamp = now.toISOString().slice(0, 19).replace(/[:-]/g, "");
|
|
257
|
+
let counter = 0;
|
|
258
|
+
let fileName;
|
|
259
|
+
do {
|
|
260
|
+
const suffix = counter > 0 ? `-${counter}` : "";
|
|
261
|
+
fileName = `${prefix}-${timestamp}${suffix}.md`;
|
|
262
|
+
counter++;
|
|
263
|
+
} while (await this.fileExists(fileName));
|
|
264
|
+
return fileName;
|
|
265
|
+
}
|
|
266
|
+
/**
|
|
267
|
+
* 指定されたファイル名のファイルが存在するかチェック
|
|
268
|
+
*/
|
|
269
|
+
async fileExists(fileName) {
|
|
270
|
+
const filePath = this.pathSystem.join(this.relativePath, fileName);
|
|
271
|
+
return await this.fileSystem.exists(filePath);
|
|
272
|
+
}
|
|
273
|
+
/**
|
|
274
|
+
* 新しいMarkdownファイルを作成する
|
|
275
|
+
*/
|
|
276
|
+
async createMdFile(fileName) {
|
|
277
|
+
const actualFileName = fileName || (await this.generateUniqueFileName("document"));
|
|
278
|
+
// .mdが付いていない場合は追加
|
|
279
|
+
const mdFileName = actualFileName.endsWith(".md")
|
|
280
|
+
? actualFileName
|
|
281
|
+
: `${actualFileName}.md`;
|
|
282
|
+
const filePath = this.pathSystem.join(this.relativePath, mdFileName);
|
|
283
|
+
const fileRef = new DocFileMdReference({
|
|
284
|
+
path: filePath,
|
|
285
|
+
fileSystem: this.fileSystem,
|
|
286
|
+
pathSystem: this.pathSystem,
|
|
287
|
+
});
|
|
288
|
+
// デフォルトコンテンツでファイルを作成
|
|
289
|
+
await fileRef.writeDefault();
|
|
290
|
+
return fileRef;
|
|
291
|
+
}
|
|
292
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"doc-directory-reference.test.d.ts","sourceRoot":"","sources":["../lib/doc-directory-reference.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { expect, test } from "bun:test";
|
|
2
|
+
import { DocDirectoryReference } from "./doc-directory-reference";
|
|
3
|
+
import { DocPathSystem } from "./doc-path-system";
|
|
4
|
+
test("DocDirectoryReference - directoryNames メソッドでサブディレクトリ名を取得できる", async () => {
|
|
5
|
+
const mockFileSystem = {
|
|
6
|
+
getBasePath: () => "/test",
|
|
7
|
+
readDirectoryFileNames: async (path) => {
|
|
8
|
+
if (path === "docs") {
|
|
9
|
+
return ["file1.md", "subdir1", "subdir2", "_archive", "file2.txt"];
|
|
10
|
+
}
|
|
11
|
+
return [];
|
|
12
|
+
},
|
|
13
|
+
isDirectory: async (path) => {
|
|
14
|
+
return ["docs/subdir1", "docs/subdir2", "docs/_archive"].includes(path);
|
|
15
|
+
},
|
|
16
|
+
};
|
|
17
|
+
const pathSystem = new DocPathSystem();
|
|
18
|
+
const dirRef = new DocDirectoryReference({
|
|
19
|
+
path: "docs",
|
|
20
|
+
indexFileName: "index.md",
|
|
21
|
+
archiveDirectoryName: "_",
|
|
22
|
+
fileSystem: mockFileSystem,
|
|
23
|
+
pathSystem,
|
|
24
|
+
});
|
|
25
|
+
const dirNames = await dirRef.directoryNames();
|
|
26
|
+
expect(dirNames.length).toBe(2); // _archiveは除外
|
|
27
|
+
expect(dirNames).toContain("subdir1");
|
|
28
|
+
expect(dirNames).toContain("subdir2");
|
|
29
|
+
expect(dirNames).not.toContain("_archive");
|
|
30
|
+
expect(dirNames).not.toContain("file1.md");
|
|
31
|
+
expect(dirNames).not.toContain("file2.txt");
|
|
32
|
+
});
|
|
33
|
+
test("DocDirectoryReference - directories メソッドでサブディレクトリ参照を取得できる", async () => {
|
|
34
|
+
const mockFileSystem = {
|
|
35
|
+
getBasePath: () => "/test",
|
|
36
|
+
readDirectoryFileNames: async (path) => {
|
|
37
|
+
if (path === "docs") {
|
|
38
|
+
return ["subdir1", "subdir2", "_archive"];
|
|
39
|
+
}
|
|
40
|
+
return [];
|
|
41
|
+
},
|
|
42
|
+
isDirectory: async (path) => {
|
|
43
|
+
return ["docs/subdir1", "docs/subdir2", "docs/_archive"].includes(path);
|
|
44
|
+
},
|
|
45
|
+
};
|
|
46
|
+
const pathSystem = new DocPathSystem();
|
|
47
|
+
const dirRef = new DocDirectoryReference({
|
|
48
|
+
path: "docs",
|
|
49
|
+
indexFileName: "index.md",
|
|
50
|
+
archiveDirectoryName: "_",
|
|
51
|
+
fileSystem: mockFileSystem,
|
|
52
|
+
pathSystem,
|
|
53
|
+
});
|
|
54
|
+
const directories = await dirRef.directories();
|
|
55
|
+
expect(directories.length).toBe(2); // _archiveは除外
|
|
56
|
+
expect(directories[0]).toBeInstanceOf(DocDirectoryReference);
|
|
57
|
+
expect(directories[0].relativePath).toBe("docs/subdir1");
|
|
58
|
+
expect(directories[1].relativePath).toBe("docs/subdir2");
|
|
59
|
+
});
|
|
60
|
+
test("DocDirectoryReference - 空のディレクトリでも正常に動作する", async () => {
|
|
61
|
+
const mockFileSystem = {
|
|
62
|
+
getBasePath: () => "/test",
|
|
63
|
+
readDirectoryFileNames: async (_path) => {
|
|
64
|
+
return []; // 空のディレクトリ
|
|
65
|
+
},
|
|
66
|
+
isDirectory: async (_path) => {
|
|
67
|
+
return false;
|
|
68
|
+
},
|
|
69
|
+
};
|
|
70
|
+
const pathSystem = new DocPathSystem();
|
|
71
|
+
const dirRef = new DocDirectoryReference({
|
|
72
|
+
path: "empty",
|
|
73
|
+
indexFileName: "index.md",
|
|
74
|
+
archiveDirectoryName: "_",
|
|
75
|
+
fileSystem: mockFileSystem,
|
|
76
|
+
pathSystem,
|
|
77
|
+
});
|
|
78
|
+
const dirNames = await dirRef.directoryNames();
|
|
79
|
+
const directories = await dirRef.directories();
|
|
80
|
+
expect(dirNames.length).toBe(0);
|
|
81
|
+
expect(directories.length).toBe(0);
|
|
82
|
+
});
|
|
83
|
+
test("DocDirectoryReference - directory メソッドで単一のサブディレクトリ参照を取得できる", () => {
|
|
84
|
+
const mockFileSystem = {
|
|
85
|
+
getBasePath: () => "/test",
|
|
86
|
+
};
|
|
87
|
+
const pathSystem = new DocPathSystem();
|
|
88
|
+
const dirRef = new DocDirectoryReference({
|
|
89
|
+
path: "docs",
|
|
90
|
+
indexFileName: "index.md",
|
|
91
|
+
archiveDirectoryName: "_",
|
|
92
|
+
fileSystem: mockFileSystem,
|
|
93
|
+
pathSystem,
|
|
94
|
+
});
|
|
95
|
+
const subdir = dirRef.directory("guides");
|
|
96
|
+
expect(subdir).toBeInstanceOf(DocDirectoryReference);
|
|
97
|
+
expect(subdir.relativePath).toBe("docs/guides");
|
|
98
|
+
expect(subdir.indexFileName).toBe("index.md");
|
|
99
|
+
expect(subdir.archiveDirectoryName).toBe("_");
|
|
100
|
+
});
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { DocFileRelationReference } from "./doc-file-relation-reference";
|
|
2
|
+
import type { DocFileSystem } from "./doc-file-system";
|
|
3
|
+
import type { DocPathSystem } from "./doc-path-system";
|
|
4
|
+
import { DocFileIndexEntity } from "./entities/doc-file-index-entity";
|
|
5
|
+
import type { DocRelationValue } from "./values/doc-relation-value";
|
|
6
|
+
type Props = {
|
|
7
|
+
path: string;
|
|
8
|
+
fileSystem: DocFileSystem;
|
|
9
|
+
pathSystem: DocPathSystem;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* ファイルを表すクラス
|
|
13
|
+
*/
|
|
14
|
+
export declare class DocFileIndexReference {
|
|
15
|
+
private readonly props;
|
|
16
|
+
private readonly pathSystem;
|
|
17
|
+
constructor(props: Props);
|
|
18
|
+
get fileSystem(): DocFileSystem;
|
|
19
|
+
get basePath(): string;
|
|
20
|
+
get filePath(): string;
|
|
21
|
+
get fileFullPath(): string;
|
|
22
|
+
get durectoryPath(): string;
|
|
23
|
+
read(): Promise<DocFileIndexEntity>;
|
|
24
|
+
/**
|
|
25
|
+
* ファイルの内容を読み込む
|
|
26
|
+
*/
|
|
27
|
+
readContent(): Promise<Error | string>;
|
|
28
|
+
/**
|
|
29
|
+
* ファイルに内容を書き込む
|
|
30
|
+
*/
|
|
31
|
+
writeContent(content: string): Promise<void>;
|
|
32
|
+
/**
|
|
33
|
+
* Entityを書き込む
|
|
34
|
+
*/
|
|
35
|
+
write(entity: DocFileIndexEntity): Promise<void>;
|
|
36
|
+
/**
|
|
37
|
+
* 新しいファイルをデフォルトコンテンツで作成
|
|
38
|
+
*/
|
|
39
|
+
writeDefault(): Promise<void>;
|
|
40
|
+
/**
|
|
41
|
+
* ファイルを削除
|
|
42
|
+
*/
|
|
43
|
+
delete(): Promise<Error | null>;
|
|
44
|
+
/**
|
|
45
|
+
* ファイルが存在するか確認
|
|
46
|
+
*/
|
|
47
|
+
exists(): Promise<boolean>;
|
|
48
|
+
relations(): Promise<DocFileRelationReference[]>;
|
|
49
|
+
readRelations(): Promise<DocRelationValue[]>;
|
|
50
|
+
/**
|
|
51
|
+
* ファイルのサイズを取得(バイト単位)
|
|
52
|
+
*/
|
|
53
|
+
size(): Promise<number>;
|
|
54
|
+
/**
|
|
55
|
+
* ファイルの最終更新日時を取得
|
|
56
|
+
*/
|
|
57
|
+
lastModified(): Promise<Date>;
|
|
58
|
+
/**
|
|
59
|
+
* ファイルの作成日時を取得
|
|
60
|
+
*/
|
|
61
|
+
createdAt(): Promise<Date>;
|
|
62
|
+
/**
|
|
63
|
+
* ファイルをアーカイブに移動し、新しい参照を返す
|
|
64
|
+
*/
|
|
65
|
+
archive(archiveDirectoryName?: string): Promise<DocFileIndexReference>;
|
|
66
|
+
/**
|
|
67
|
+
* ファイルをアーカイブから復元し、新しい参照を返す
|
|
68
|
+
*/
|
|
69
|
+
restore(archiveDirectoryName?: string): Promise<DocFileIndexReference>;
|
|
70
|
+
}
|
|
71
|
+
export {};
|
|
72
|
+
//# sourceMappingURL=doc-file-index-reference.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"doc-file-index-reference.d.ts","sourceRoot":"","sources":["../lib/doc-file-index-reference.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,MAAM,+BAA+B,CAAA;AACxE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AACtD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AACtD,OAAO,EAAE,kBAAkB,EAAE,MAAM,kCAAkC,CAAA;AAGrE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAA;AAEnE,KAAK,KAAK,GAAG;IACX,IAAI,EAAE,MAAM,CAAA;IACZ,UAAU,EAAE,aAAa,CAAA;IACzB,UAAU,EAAE,aAAa,CAAA;CAC1B,CAAA;AAED;;GAEG;AACH,qBAAa,qBAAqB;IAGpB,OAAO,CAAC,QAAQ,CAAC,KAAK;IAFlC,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAe;IAE1C,YAA6B,KAAK,EAAE,KAAK,EAGxC;IAED,IAAI,UAAU,IAAI,aAAa,CAE9B;IAED,IAAI,QAAQ,IAAI,MAAM,CAErB;IAED,IAAI,QAAQ,IAAI,MAAM,CAErB;IAED,IAAI,YAAY,IAAI,MAAM,CAEzB;IAED,IAAI,aAAa,IAAI,MAAM,CAE1B;IAEK,IAAI,IAAI,OAAO,CAAC,kBAAkB,CAAC,CAgCxC;IAED;;OAEG;IACG,WAAW,IAAI,OAAO,CAAC,KAAK,GAAG,MAAM,CAAC,CAM3C;IAED;;OAEG;IACG,YAAY,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAEjD;IAED;;OAEG;IACG,KAAK,CAAC,MAAM,EAAE,kBAAkB,GAAG,OAAO,CAAC,IAAI,CAAC,CAGrD;IAED;;OAEG;IACG,YAAY,IAAI,OAAO,CAAC,IAAI,CAAC,CASlC;IAED;;OAEG;IACG,MAAM,IAAI,OAAO,CAAC,KAAK,GAAG,IAAI,CAAC,CAEpC;IAED;;OAEG;IACG,MAAM,IAAI,OAAO,CAAC,OAAO,CAAC,CAE/B;IAEK,SAAS,IAAI,OAAO,CAAC,wBAAwB,EAAE,CAAC,CA4BrD;IAEK,aAAa,IAAI,OAAO,CAAC,gBAAgB,EAAE,CAAC,CAYjD;IAED;;OAEG;IACG,IAAI,IAAI,OAAO,CAAC,MAAM,CAAC,CAE5B;IAED;;OAEG;IACG,YAAY,IAAI,OAAO,CAAC,IAAI,CAAC,CAElC;IAED;;OAEG;IACG,SAAS,IAAI,OAAO,CAAC,IAAI,CAAC,CAE/B;IAED;;OAEG;IACG,OAAO,CAAC,oBAAoB,SAAM,GAAG,OAAO,CAAC,qBAAqB,CAAC,CAkBxE;IAED;;OAEG;IACG,OAAO,CAAC,oBAAoB,SAAM,GAAG,OAAO,CAAC,qBAAqB,CAAC,CA0BxE;CACF"}
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
import { DocFileRelationReference } from "./doc-file-relation-reference";
|
|
2
|
+
import { DocFileIndexEntity } from "./entities/doc-file-index-entity";
|
|
3
|
+
import { DocFileContentIndexValue } from "./values/doc-file-content-index-value";
|
|
4
|
+
import { DocFilePathValue } from "./values/doc-file-path-value";
|
|
5
|
+
/**
|
|
6
|
+
* ファイルを表すクラス
|
|
7
|
+
*/
|
|
8
|
+
export class DocFileIndexReference {
|
|
9
|
+
props;
|
|
10
|
+
pathSystem;
|
|
11
|
+
constructor(props) {
|
|
12
|
+
this.props = props;
|
|
13
|
+
this.pathSystem = props.pathSystem;
|
|
14
|
+
Object.freeze(this);
|
|
15
|
+
}
|
|
16
|
+
get fileSystem() {
|
|
17
|
+
return this.props.fileSystem;
|
|
18
|
+
}
|
|
19
|
+
get basePath() {
|
|
20
|
+
return this.fileSystem.getBasePath();
|
|
21
|
+
}
|
|
22
|
+
get filePath() {
|
|
23
|
+
return this.props.path;
|
|
24
|
+
}
|
|
25
|
+
get fileFullPath() {
|
|
26
|
+
return this.pathSystem.join(this.basePath, this.filePath);
|
|
27
|
+
}
|
|
28
|
+
get durectoryPath() {
|
|
29
|
+
return this.pathSystem.dirname(this.filePath);
|
|
30
|
+
}
|
|
31
|
+
async read() {
|
|
32
|
+
const content = await this.fileSystem.readFile(this.filePath);
|
|
33
|
+
if (content === null) {
|
|
34
|
+
const dirName = this.filePath.split("/").pop() || "directory";
|
|
35
|
+
const pathValue = DocFilePathValue.fromPathWithSystem(this.filePath, this.pathSystem, this.fileSystem.getBasePath());
|
|
36
|
+
const contentValue = DocFileContentIndexValue.empty(dirName);
|
|
37
|
+
return new DocFileIndexEntity({
|
|
38
|
+
type: "index",
|
|
39
|
+
path: pathValue.toJson(),
|
|
40
|
+
content: contentValue.toJson(),
|
|
41
|
+
isArchived: false,
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
const pathValue = DocFilePathValue.fromPathWithSystem(this.filePath, this.pathSystem, this.fileSystem.getBasePath());
|
|
45
|
+
const contentValue = DocFileContentIndexValue.fromMarkdown(content);
|
|
46
|
+
return new DocFileIndexEntity({
|
|
47
|
+
type: "index",
|
|
48
|
+
path: pathValue.toJson(),
|
|
49
|
+
content: contentValue.toJson(),
|
|
50
|
+
isArchived: false,
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* ファイルの内容を読み込む
|
|
55
|
+
*/
|
|
56
|
+
async readContent() {
|
|
57
|
+
const entity = await this.read();
|
|
58
|
+
if (entity instanceof Error) {
|
|
59
|
+
return entity;
|
|
60
|
+
}
|
|
61
|
+
return entity.value.content.body;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* ファイルに内容を書き込む
|
|
65
|
+
*/
|
|
66
|
+
async writeContent(content) {
|
|
67
|
+
await this.fileSystem.writeFile(this.filePath, content);
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Entityを書き込む
|
|
71
|
+
*/
|
|
72
|
+
async write(entity) {
|
|
73
|
+
const content = entity.content.toText();
|
|
74
|
+
await this.fileSystem.writeFile(this.filePath, content);
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* 新しいファイルをデフォルトコンテンツで作成
|
|
78
|
+
*/
|
|
79
|
+
async writeDefault() {
|
|
80
|
+
const dirPath = this.pathSystem.dirname(this.filePath);
|
|
81
|
+
const dirName = this.pathSystem.basename(dirPath) || "ディレクトリ";
|
|
82
|
+
const defaultContent = [
|
|
83
|
+
`# ${dirName}`,
|
|
84
|
+
"",
|
|
85
|
+
`${dirName}に関する概要をここに記載してください。`,
|
|
86
|
+
].join("\n");
|
|
87
|
+
await this.fileSystem.writeFile(this.filePath, defaultContent);
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* ファイルを削除
|
|
91
|
+
*/
|
|
92
|
+
async delete() {
|
|
93
|
+
return await this.fileSystem.deleteFile(this.filePath);
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* ファイルが存在するか確認
|
|
97
|
+
*/
|
|
98
|
+
async exists() {
|
|
99
|
+
return this.fileSystem.exists(this.filePath);
|
|
100
|
+
}
|
|
101
|
+
async relations() {
|
|
102
|
+
const indexFile = await this.read();
|
|
103
|
+
if (indexFile instanceof Error) {
|
|
104
|
+
return [];
|
|
105
|
+
}
|
|
106
|
+
const schema = indexFile.content.frontMatter.value.schema;
|
|
107
|
+
if (!schema) {
|
|
108
|
+
return [];
|
|
109
|
+
}
|
|
110
|
+
const relationFields = Object.entries(schema).filter(([_key, field]) => {
|
|
111
|
+
return field.type === "relation" || field.type === "multi-relation";
|
|
112
|
+
});
|
|
113
|
+
return relationFields.map(([, field]) => {
|
|
114
|
+
if ((field.type === "relation" || field.type === "multi-relation") &&
|
|
115
|
+
field.path) {
|
|
116
|
+
return new DocFileRelationReference({
|
|
117
|
+
filePath: field.path,
|
|
118
|
+
fileSystem: this.fileSystem,
|
|
119
|
+
pathSystem: this.pathSystem,
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
throw new Error("Unexpected field type or missing path");
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
async readRelations() {
|
|
126
|
+
const relations = await this.relations();
|
|
127
|
+
const files = [];
|
|
128
|
+
for (const relation of relations) {
|
|
129
|
+
const entity = await relation.read();
|
|
130
|
+
if (entity === null)
|
|
131
|
+
continue;
|
|
132
|
+
files.push(entity);
|
|
133
|
+
}
|
|
134
|
+
return files;
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* ファイルのサイズを取得(バイト単位)
|
|
138
|
+
*/
|
|
139
|
+
async size() {
|
|
140
|
+
return this.fileSystem.getFileSize(this.filePath);
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* ファイルの最終更新日時を取得
|
|
144
|
+
*/
|
|
145
|
+
async lastModified() {
|
|
146
|
+
return this.fileSystem.getFileModifiedTime(this.filePath);
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* ファイルの作成日時を取得
|
|
150
|
+
*/
|
|
151
|
+
async createdAt() {
|
|
152
|
+
return this.fileSystem.getFileCreatedTime(this.filePath);
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* ファイルをアーカイブに移動し、新しい参照を返す
|
|
156
|
+
*/
|
|
157
|
+
async archive(archiveDirectoryName = "_") {
|
|
158
|
+
const dirPath = this.pathSystem.dirname(this.filePath);
|
|
159
|
+
const fileName = this.pathSystem.basename(this.filePath);
|
|
160
|
+
const archivePath = this.pathSystem.join(dirPath, archiveDirectoryName, fileName);
|
|
161
|
+
// ファイルを移動
|
|
162
|
+
await this.fileSystem.moveFile(this.filePath, archivePath);
|
|
163
|
+
// 新しいパスで参照を作成
|
|
164
|
+
return new DocFileIndexReference({
|
|
165
|
+
path: archivePath,
|
|
166
|
+
fileSystem: this.fileSystem,
|
|
167
|
+
pathSystem: this.pathSystem,
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* ファイルをアーカイブから復元し、新しい参照を返す
|
|
172
|
+
*/
|
|
173
|
+
async restore(archiveDirectoryName = "_") {
|
|
174
|
+
const dirPath = this.pathSystem.dirname(this.filePath);
|
|
175
|
+
const parentDirName = this.pathSystem.basename(dirPath);
|
|
176
|
+
// 親ディレクトリがアーカイブディレクトリでない場合はエラー
|
|
177
|
+
if (parentDirName !== archiveDirectoryName) {
|
|
178
|
+
throw new Error(`ファイルはアーカイブディレクトリにありません: ${this.filePath}`);
|
|
179
|
+
}
|
|
180
|
+
const fileName = this.pathSystem.basename(this.filePath);
|
|
181
|
+
const restorePath = this.pathSystem.join(this.pathSystem.dirname(dirPath), fileName);
|
|
182
|
+
// ファイルを移動
|
|
183
|
+
await this.fileSystem.moveFile(this.filePath, restorePath);
|
|
184
|
+
// 新しいパスで参照を作成
|
|
185
|
+
return new DocFileIndexReference({
|
|
186
|
+
path: restorePath,
|
|
187
|
+
fileSystem: this.fileSystem,
|
|
188
|
+
pathSystem: this.pathSystem,
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"doc-file-index-reference.test.d.ts","sourceRoot":"","sources":["../lib/doc-file-index-reference.test.ts"],"names":[],"mappings":""}
|