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