@interactive-inc/docs-client 1.1.2 → 2.0.0
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 +448 -0
- package/build/{doc-file-system-DEmPPJPE.d.ts → doc-file-system-z2sEMkq0.d.ts} +5 -5
- package/build/{doc-file-system.interface-C5vpYrOL.d.ts → doc-file-system.interface-CmQywbuP.d.ts} +3 -2
- package/build/file-system-json.d.ts +52 -8
- package/build/file-system-json.js +122 -65
- package/build/file-system-mock.d.ts +1 -1
- package/build/file-system-mock.js +8 -3
- package/build/file-system-node.d.ts +2 -2
- package/build/file-system-node.js +14 -12
- package/build/file-system-octokit.d.ts +7 -2
- package/build/file-system-octokit.js +42 -34
- package/build/file-system.d.ts +4 -4
- package/build/file-system.js +13 -12
- package/build/index.d.ts +99 -217
- package/build/index.js +512 -701
- package/build/models.d.ts +81 -1
- package/build/models.js +14 -15
- package/package.json +46 -17
- package/.env.local +0 -3
- package/tmp/docs-studio/files/a.md +0 -9
- package/tmp/docs-studio/pages/delete-document.md +0 -7
- package/tmp/docs-studio/pages/document-editor.md +0 -9
- package/tmp/docs-studio/pages/edit-document-content.md +0 -7
- package/tmp/docs-studio/pages/index.md +0 -14
package/build/index.js
CHANGED
|
@@ -1,7 +1,45 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import { stringify, parse } from 'yaml';
|
|
3
3
|
|
|
4
|
-
// lib/
|
|
4
|
+
// lib/create-safe-proxy.ts
|
|
5
|
+
function isAsyncIterator(value) {
|
|
6
|
+
return value !== null && typeof value === "object" && Symbol.asyncIterator in value;
|
|
7
|
+
}
|
|
8
|
+
function createSafeProxy(target) {
|
|
9
|
+
return new Proxy(target, {
|
|
10
|
+
get(obj, prop, receiver) {
|
|
11
|
+
if (prop === "safe") return receiver;
|
|
12
|
+
const value = Reflect.get(obj, prop, receiver);
|
|
13
|
+
if (typeof value !== "function") return value;
|
|
14
|
+
return (...args) => {
|
|
15
|
+
const callResult = value.apply(obj, args);
|
|
16
|
+
if (callResult instanceof Promise) {
|
|
17
|
+
return callResult.catch((error) => {
|
|
18
|
+
return error instanceof Error ? error : new Error(String(error));
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
if (isAsyncIterator(callResult)) {
|
|
22
|
+
return safeAsyncIterator(callResult);
|
|
23
|
+
}
|
|
24
|
+
return callResult;
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
async function* safeAsyncIterator(iterable) {
|
|
30
|
+
const iterator = iterable[Symbol.asyncIterator]();
|
|
31
|
+
while (true) {
|
|
32
|
+
let next;
|
|
33
|
+
try {
|
|
34
|
+
next = await iterator.next();
|
|
35
|
+
} catch (error) {
|
|
36
|
+
yield error instanceof Error ? error : new Error(String(error));
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
if (next.done) return;
|
|
40
|
+
yield next.value;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
5
43
|
var zDocFilePath = z.object({
|
|
6
44
|
name: z.string(),
|
|
7
45
|
path: z.string(),
|
|
@@ -18,9 +56,7 @@ var zDocMetaFieldTypeMultiText = z.literal("multi-text");
|
|
|
18
56
|
var zDocMetaFieldTypeMultiNumber = z.literal("multi-number");
|
|
19
57
|
var zDocMetaFieldTypeMultiRelation = z.literal("multi-relation");
|
|
20
58
|
var zDocMetaFieldTypeMultiSelectText = z.literal("multi-select-text");
|
|
21
|
-
var zDocMetaFieldTypeMultiSelectNumber = z.literal(
|
|
22
|
-
"multi-select-number"
|
|
23
|
-
);
|
|
59
|
+
var zDocMetaFieldTypeMultiSelectNumber = z.literal("multi-select-number");
|
|
24
60
|
z.union([
|
|
25
61
|
zDocMetaFieldTypeText,
|
|
26
62
|
zDocMetaFieldTypeNumber,
|
|
@@ -74,7 +110,8 @@ var zDocSchemaFieldRelation = z.object({
|
|
|
74
110
|
required: z.boolean(),
|
|
75
111
|
title: z.string().nullable(),
|
|
76
112
|
description: z.string().nullable(),
|
|
77
|
-
path
|
|
113
|
+
// 空文字は path 未設定のプレースホルダとして許容する(empty() が生成する)
|
|
114
|
+
path: z.string(),
|
|
78
115
|
default: z.string().nullable()
|
|
79
116
|
});
|
|
80
117
|
var zDocSchemaFieldMultiRelation = z.object({
|
|
@@ -82,7 +119,8 @@ var zDocSchemaFieldMultiRelation = z.object({
|
|
|
82
119
|
required: z.boolean(),
|
|
83
120
|
title: z.string().nullable(),
|
|
84
121
|
description: z.string().nullable(),
|
|
85
|
-
path
|
|
122
|
+
// 空文字は path 未設定のプレースホルダとして許容する(empty() が生成する)
|
|
123
|
+
path: z.string(),
|
|
86
124
|
default: z.array(z.string()).nullable()
|
|
87
125
|
});
|
|
88
126
|
var zDocSchemaFieldSelectText = z.object({
|
|
@@ -155,14 +193,8 @@ var zDocMetaField = z.union([
|
|
|
155
193
|
zDocMetaFieldMultiRelation
|
|
156
194
|
]);
|
|
157
195
|
var zDocFileMdMeta = z.record(z.string(), zDocMetaField);
|
|
158
|
-
var zDocFileMdMetaInput = z.record(
|
|
159
|
-
|
|
160
|
-
zDocMetaField.or(z.undefined())
|
|
161
|
-
);
|
|
162
|
-
var zDocFileIndexSchema = z.record(
|
|
163
|
-
z.string(),
|
|
164
|
-
zDocFileIndexSchemaField
|
|
165
|
-
);
|
|
196
|
+
var zDocFileMdMetaInput = z.record(z.string(), zDocMetaField.or(z.undefined()));
|
|
197
|
+
var zDocFileIndexSchema = z.record(z.string(), zDocFileIndexSchemaField);
|
|
166
198
|
var zDocFileIndexSchemaInput = z.record(
|
|
167
199
|
z.string(),
|
|
168
200
|
zDocFileIndexSchemaField.or(z.undefined())
|
|
@@ -322,7 +354,12 @@ var zDocClientConfig = z.object({
|
|
|
322
354
|
archiveDirectoryName: z.string(),
|
|
323
355
|
defaultDirectoryName: z.string(),
|
|
324
356
|
indexMetaIncludes: z.array(z.string()),
|
|
325
|
-
directoryExcludes: z.array(z.string())
|
|
357
|
+
directoryExcludes: z.array(z.string()),
|
|
358
|
+
metaFileName: z.string().optional()
|
|
359
|
+
});
|
|
360
|
+
var zDocDirectoryMeta = z.object({
|
|
361
|
+
icon: z.string().nullable().optional(),
|
|
362
|
+
schema: zDocFileIndexSchema.optional()
|
|
326
363
|
});
|
|
327
364
|
|
|
328
365
|
// lib/modules/markdown-system/doc-markdown-system.ts
|
|
@@ -354,7 +391,7 @@ ${separator}`, separator.length);
|
|
|
354
391
|
if (endIndex === -1) {
|
|
355
392
|
return null;
|
|
356
393
|
}
|
|
357
|
-
return text.slice(
|
|
394
|
+
return text.slice(separator.length + 1, endIndex).trim();
|
|
358
395
|
}
|
|
359
396
|
/**
|
|
360
397
|
* Extract body without FrontMatter (includes title and description)
|
|
@@ -471,6 +508,7 @@ ${text}`.trim();
|
|
|
471
508
|
// lib/constants.ts
|
|
472
509
|
var INDEX_META = "index-meta";
|
|
473
510
|
var DOC_NODE_TYPE_DIRECTORY = "directory";
|
|
511
|
+
var META_FILE_NAME = ".meta.json";
|
|
474
512
|
|
|
475
513
|
// lib/values/doc-schema-field/doc-schema-field-boolean-value.ts
|
|
476
514
|
var DocSchemaFieldBooleanValue = class _DocSchemaFieldBooleanValue {
|
|
@@ -1302,7 +1340,6 @@ var DocFileIndexSchemaValue = class _DocFileIndexSchemaValue {
|
|
|
1302
1340
|
}
|
|
1303
1341
|
/**
|
|
1304
1342
|
* Create empty schema entity
|
|
1305
|
-
* biome-ignore lint/complexity/noBannedTypes: {} as DocCustomSchema
|
|
1306
1343
|
*/
|
|
1307
1344
|
static empty() {
|
|
1308
1345
|
return new _DocFileIndexSchemaValue({}, {});
|
|
@@ -1364,12 +1401,15 @@ var DocFileIndexMetaValue = class _DocFileIndexMetaValue {
|
|
|
1364
1401
|
* Allows accepting Record<string, unknown> schemas from external sources
|
|
1365
1402
|
*/
|
|
1366
1403
|
withUnknownSchema(draft) {
|
|
1367
|
-
const
|
|
1404
|
+
const parseResult = zDocFileIndexSchema.safeParse(draft);
|
|
1405
|
+
if (parseResult.success === false) {
|
|
1406
|
+
throw new Error(`Invalid schema format: ${parseResult.error.message}`);
|
|
1407
|
+
}
|
|
1368
1408
|
return new _DocFileIndexMetaValue(
|
|
1369
1409
|
{
|
|
1370
1410
|
type: INDEX_META,
|
|
1371
1411
|
icon: this.value.icon,
|
|
1372
|
-
schema:
|
|
1412
|
+
schema: parseResult.data
|
|
1373
1413
|
},
|
|
1374
1414
|
{},
|
|
1375
1415
|
this.config,
|
|
@@ -1413,10 +1453,7 @@ var DocFileIndexMetaValue = class _DocFileIndexMetaValue {
|
|
|
1413
1453
|
*/
|
|
1414
1454
|
static fromRecord(record, customSchema, config) {
|
|
1415
1455
|
const icon = _DocFileIndexMetaValue.extractIcon(record, config);
|
|
1416
|
-
const indexSchema = _DocFileIndexMetaValue.extractSchema(
|
|
1417
|
-
record,
|
|
1418
|
-
customSchema
|
|
1419
|
-
);
|
|
1456
|
+
const indexSchema = _DocFileIndexMetaValue.extractSchema(record, customSchema);
|
|
1420
1457
|
const additionalProperties = {};
|
|
1421
1458
|
for (const key of config.indexMetaIncludes) {
|
|
1422
1459
|
if (key in record && key !== "icon" && key !== "schema") {
|
|
@@ -1428,12 +1465,7 @@ var DocFileIndexMetaValue = class _DocFileIndexMetaValue {
|
|
|
1428
1465
|
icon,
|
|
1429
1466
|
schema: indexSchema
|
|
1430
1467
|
};
|
|
1431
|
-
return new _DocFileIndexMetaValue(
|
|
1432
|
-
indexMeta,
|
|
1433
|
-
customSchema,
|
|
1434
|
-
config,
|
|
1435
|
-
additionalProperties
|
|
1436
|
-
);
|
|
1468
|
+
return new _DocFileIndexMetaValue(indexMeta, customSchema, config, additionalProperties);
|
|
1437
1469
|
}
|
|
1438
1470
|
/**
|
|
1439
1471
|
* Generate empty FrontMatter
|
|
@@ -1465,19 +1497,17 @@ var DocFileIndexMetaValue = class _DocFileIndexMetaValue {
|
|
|
1465
1497
|
}
|
|
1466
1498
|
return record;
|
|
1467
1499
|
}
|
|
1468
|
-
// biome-ignore lint/correctness/noUnusedPrivateClassMembers: Used in fromRecord static method
|
|
1469
1500
|
static extractIcon(record, config) {
|
|
1470
1501
|
if (typeof record.icon === "string") {
|
|
1471
1502
|
return record.icon;
|
|
1472
1503
|
}
|
|
1473
1504
|
return config.defaultIndexIcon;
|
|
1474
1505
|
}
|
|
1475
|
-
// biome-ignore lint/correctness/noUnusedPrivateClassMembers: Used in fromRecord static method
|
|
1476
1506
|
static extractSchema(record, customSchema) {
|
|
1477
1507
|
if (typeof record.schema === "object" && record.schema !== null && !Array.isArray(record.schema)) {
|
|
1478
1508
|
const rawSchema = record.schema;
|
|
1479
1509
|
const normalizedSchema = {};
|
|
1480
|
-
for (const key
|
|
1510
|
+
for (const key of Object.keys(rawSchema)) {
|
|
1481
1511
|
const field = rawSchema[key];
|
|
1482
1512
|
normalizedSchema[key] = {
|
|
1483
1513
|
...field,
|
|
@@ -1524,11 +1554,7 @@ var DocFileIndexContentValue = class _DocFileIndexContentValue {
|
|
|
1524
1554
|
* FrontMatter
|
|
1525
1555
|
*/
|
|
1526
1556
|
meta() {
|
|
1527
|
-
return new DocFileIndexMetaValue(
|
|
1528
|
-
this.value.meta,
|
|
1529
|
-
this.customSchema,
|
|
1530
|
-
this.config
|
|
1531
|
-
);
|
|
1557
|
+
return new DocFileIndexMetaValue(this.value.meta, this.customSchema, this.config);
|
|
1532
1558
|
}
|
|
1533
1559
|
/**
|
|
1534
1560
|
* Update title
|
|
@@ -1547,11 +1573,7 @@ var DocFileIndexContentValue = class _DocFileIndexContentValue {
|
|
|
1547
1573
|
*/
|
|
1548
1574
|
withDescription(description, defaultTitle) {
|
|
1549
1575
|
const engine = new DocMarkdownSystem();
|
|
1550
|
-
const updatedBody = engine.updateDescription(
|
|
1551
|
-
this.body,
|
|
1552
|
-
description,
|
|
1553
|
-
defaultTitle || this.title
|
|
1554
|
-
);
|
|
1576
|
+
const updatedBody = engine.updateDescription(this.body, description, defaultTitle || this.title);
|
|
1555
1577
|
return new _DocFileIndexContentValue(
|
|
1556
1578
|
{
|
|
1557
1579
|
...this.value,
|
|
@@ -1567,18 +1589,37 @@ var DocFileIndexContentValue = class _DocFileIndexContentValue {
|
|
|
1567
1589
|
*/
|
|
1568
1590
|
static fromMarkdown(markdown, customSchema, config) {
|
|
1569
1591
|
const engine = new DocMarkdownSystem();
|
|
1570
|
-
const frontMatter = DocFileIndexMetaValue.from(
|
|
1571
|
-
|
|
1592
|
+
const frontMatter = DocFileIndexMetaValue.from(markdown, customSchema, config);
|
|
1593
|
+
return new _DocFileIndexContentValue(
|
|
1594
|
+
{
|
|
1595
|
+
type: "markdown-index",
|
|
1596
|
+
body: engine.extractBody(markdown),
|
|
1597
|
+
title: engine.extractTitle(markdown) || "",
|
|
1598
|
+
description: engine.extractDescription(markdown) || "",
|
|
1599
|
+
meta: frontMatter.toJson()
|
|
1600
|
+
},
|
|
1572
1601
|
customSchema,
|
|
1573
1602
|
config
|
|
1574
1603
|
);
|
|
1604
|
+
}
|
|
1605
|
+
/**
|
|
1606
|
+
* Generate from Markdown text with .meta.json
|
|
1607
|
+
* FrontMatter is ignored, only body/title/description are extracted
|
|
1608
|
+
*/
|
|
1609
|
+
static fromMarkdownWithDirectoryMeta(markdown, customSchema, config, directoryMeta) {
|
|
1610
|
+
const engine = new DocMarkdownSystem();
|
|
1611
|
+
const meta = {
|
|
1612
|
+
type: "index-meta",
|
|
1613
|
+
icon: directoryMeta.icon ?? config.defaultIndexIcon,
|
|
1614
|
+
schema: directoryMeta.schema ?? {}
|
|
1615
|
+
};
|
|
1575
1616
|
return new _DocFileIndexContentValue(
|
|
1576
1617
|
{
|
|
1577
1618
|
type: "markdown-index",
|
|
1578
1619
|
body: engine.extractBody(markdown),
|
|
1579
1620
|
title: engine.extractTitle(markdown) || "",
|
|
1580
1621
|
description: engine.extractDescription(markdown) || "",
|
|
1581
|
-
meta
|
|
1622
|
+
meta
|
|
1582
1623
|
},
|
|
1583
1624
|
customSchema,
|
|
1584
1625
|
config
|
|
@@ -1636,8 +1677,26 @@ schema: {}
|
|
|
1636
1677
|
|
|
1637
1678
|
# ${directoryName}
|
|
1638
1679
|
`;
|
|
1639
|
-
return _DocFileIndexContentValue.fromMarkdown(
|
|
1640
|
-
|
|
1680
|
+
return _DocFileIndexContentValue.fromMarkdown(content, customSchema, config);
|
|
1681
|
+
}
|
|
1682
|
+
/**
|
|
1683
|
+
* Generate default index.md content with .meta.json
|
|
1684
|
+
*/
|
|
1685
|
+
static emptyWithDirectoryMeta(directoryName, customSchema, config, directoryMeta) {
|
|
1686
|
+
const meta = {
|
|
1687
|
+
type: "index-meta",
|
|
1688
|
+
icon: directoryMeta.icon ?? config.defaultIndexIcon,
|
|
1689
|
+
schema: directoryMeta.schema ?? {}
|
|
1690
|
+
};
|
|
1691
|
+
return new _DocFileIndexContentValue(
|
|
1692
|
+
{
|
|
1693
|
+
type: "markdown-index",
|
|
1694
|
+
body: `# ${directoryName}
|
|
1695
|
+
`,
|
|
1696
|
+
title: directoryName,
|
|
1697
|
+
description: "",
|
|
1698
|
+
meta
|
|
1699
|
+
},
|
|
1641
1700
|
customSchema,
|
|
1642
1701
|
config
|
|
1643
1702
|
);
|
|
@@ -1692,11 +1751,7 @@ var DocFileIndexEntity = class _DocFileIndexEntity {
|
|
|
1692
1751
|
* Content
|
|
1693
1752
|
*/
|
|
1694
1753
|
get content() {
|
|
1695
|
-
return new DocFileIndexContentValue(
|
|
1696
|
-
this.value.content,
|
|
1697
|
-
this.customSchema,
|
|
1698
|
-
this.config
|
|
1699
|
-
);
|
|
1754
|
+
return new DocFileIndexContentValue(this.value.content, this.customSchema, this.config);
|
|
1700
1755
|
}
|
|
1701
1756
|
/**
|
|
1702
1757
|
* Path information
|
|
@@ -1748,6 +1803,7 @@ var DocFilePathValue = class _DocFilePathValue {
|
|
|
1748
1803
|
this.value = value;
|
|
1749
1804
|
zDocFilePath.parse(value);
|
|
1750
1805
|
this.pathSystem = pathSystem;
|
|
1806
|
+
Object.freeze(this.value);
|
|
1751
1807
|
Object.freeze(this);
|
|
1752
1808
|
}
|
|
1753
1809
|
pathSystem;
|
|
@@ -1791,13 +1847,13 @@ var DocFilePathValue = class _DocFilePathValue {
|
|
|
1791
1847
|
* Whether the file is archived
|
|
1792
1848
|
*/
|
|
1793
1849
|
get isArchived() {
|
|
1794
|
-
return this.path.includes("
|
|
1850
|
+
return this.path.includes("/_/") || this.path.startsWith("_/");
|
|
1795
1851
|
}
|
|
1796
1852
|
/**
|
|
1797
1853
|
* Export as JSON format
|
|
1798
1854
|
*/
|
|
1799
1855
|
toJson() {
|
|
1800
|
-
return this.value;
|
|
1856
|
+
return { ...this.value };
|
|
1801
1857
|
}
|
|
1802
1858
|
/**
|
|
1803
1859
|
* Create instance from relative path (DI support)
|
|
@@ -1841,9 +1897,7 @@ var DocCustomSchemaFieldBooleanValue = class _DocCustomSchemaFieldBooleanValue {
|
|
|
1841
1897
|
return zDocMetaFieldBoolean.parse(value);
|
|
1842
1898
|
} catch {
|
|
1843
1899
|
if (this.value.required) {
|
|
1844
|
-
throw new Error(
|
|
1845
|
-
`required field "${this.key.toString()}" is missing or invalid`
|
|
1846
|
-
);
|
|
1900
|
+
throw new Error(`required field "${this.key.toString()}" is missing or invalid`);
|
|
1847
1901
|
}
|
|
1848
1902
|
return _DocCustomSchemaFieldBooleanValue.defaultValue();
|
|
1849
1903
|
}
|
|
@@ -1875,9 +1929,7 @@ var DocCustomSchemaFieldMultiNumberValue = class _DocCustomSchemaFieldMultiNumbe
|
|
|
1875
1929
|
return zDocMetaFieldMultiNumber.parse(value);
|
|
1876
1930
|
} catch {
|
|
1877
1931
|
if (this.value.required) {
|
|
1878
|
-
throw new Error(
|
|
1879
|
-
`required field "${this.key.toString()}" is missing or invalid`
|
|
1880
|
-
);
|
|
1932
|
+
throw new Error(`required field "${this.key.toString()}" is missing or invalid`);
|
|
1881
1933
|
}
|
|
1882
1934
|
return _DocCustomSchemaFieldMultiNumberValue.defaultValue();
|
|
1883
1935
|
}
|
|
@@ -1909,9 +1961,7 @@ var DocCustomSchemaFieldMultiRelationValue = class _DocCustomSchemaFieldMultiRel
|
|
|
1909
1961
|
return zDocMetaFieldMultiRelation.parse(value);
|
|
1910
1962
|
} catch {
|
|
1911
1963
|
if (this.value.required) {
|
|
1912
|
-
throw new Error(
|
|
1913
|
-
`required field "${this.key.toString()}" is missing or invalid`
|
|
1914
|
-
);
|
|
1964
|
+
throw new Error(`required field "${this.key.toString()}" is missing or invalid`);
|
|
1915
1965
|
}
|
|
1916
1966
|
return _DocCustomSchemaFieldMultiRelationValue.defaultValue();
|
|
1917
1967
|
}
|
|
@@ -1943,9 +1993,7 @@ var DocCustomSchemaFieldMultiSelectNumberValue = class _DocCustomSchemaFieldMult
|
|
|
1943
1993
|
return zDocMetaFieldMultiSelectNumber.parse(value);
|
|
1944
1994
|
} catch {
|
|
1945
1995
|
if (this.value.required) {
|
|
1946
|
-
throw new Error(
|
|
1947
|
-
`required field "${this.key.toString()}" is missing or invalid`
|
|
1948
|
-
);
|
|
1996
|
+
throw new Error(`required field "${this.key.toString()}" is missing or invalid`);
|
|
1949
1997
|
}
|
|
1950
1998
|
return _DocCustomSchemaFieldMultiSelectNumberValue.defaultValue();
|
|
1951
1999
|
}
|
|
@@ -1977,9 +2025,7 @@ var DocCustomSchemaFieldMultiSelectTextValue = class _DocCustomSchemaFieldMultiS
|
|
|
1977
2025
|
return zDocMetaFieldMultiSelectText.parse(value);
|
|
1978
2026
|
} catch {
|
|
1979
2027
|
if (this.value.required) {
|
|
1980
|
-
throw new Error(
|
|
1981
|
-
`required field "${this.key.toString()}" is missing or invalid`
|
|
1982
|
-
);
|
|
2028
|
+
throw new Error(`required field "${this.key.toString()}" is missing or invalid`);
|
|
1983
2029
|
}
|
|
1984
2030
|
return _DocCustomSchemaFieldMultiSelectTextValue.defaultValue();
|
|
1985
2031
|
}
|
|
@@ -2011,9 +2057,7 @@ var DocCustomSchemaFieldMultiTextValue = class _DocCustomSchemaFieldMultiTextVal
|
|
|
2011
2057
|
return zDocMetaFieldMultiText.parse(value);
|
|
2012
2058
|
} catch {
|
|
2013
2059
|
if (this.value.required) {
|
|
2014
|
-
throw new Error(
|
|
2015
|
-
`required field "${this.key.toString()}" is missing or invalid`
|
|
2016
|
-
);
|
|
2060
|
+
throw new Error(`required field "${this.key.toString()}" is missing or invalid`);
|
|
2017
2061
|
}
|
|
2018
2062
|
return _DocCustomSchemaFieldMultiTextValue.defaultValue();
|
|
2019
2063
|
}
|
|
@@ -2045,9 +2089,7 @@ var DocCustomSchemaFieldNumberValue = class _DocCustomSchemaFieldNumberValue {
|
|
|
2045
2089
|
return zDocMetaFieldNumber.parse(value);
|
|
2046
2090
|
} catch {
|
|
2047
2091
|
if (this.value.required) {
|
|
2048
|
-
throw new Error(
|
|
2049
|
-
`required field "${this.key.toString()}" is missing or invalid`
|
|
2050
|
-
);
|
|
2092
|
+
throw new Error(`required field "${this.key.toString()}" is missing or invalid`);
|
|
2051
2093
|
}
|
|
2052
2094
|
return _DocCustomSchemaFieldNumberValue.defaultValue();
|
|
2053
2095
|
}
|
|
@@ -2079,9 +2121,7 @@ var DocCustomSchemaFieldRelationValue = class _DocCustomSchemaFieldRelationValue
|
|
|
2079
2121
|
return zDocMetaFieldRelation.parse(value);
|
|
2080
2122
|
} catch {
|
|
2081
2123
|
if (this.value.required) {
|
|
2082
|
-
throw new Error(
|
|
2083
|
-
`required field "${this.key.toString()}" is missing or invalid`
|
|
2084
|
-
);
|
|
2124
|
+
throw new Error(`required field "${this.key.toString()}" is missing or invalid`);
|
|
2085
2125
|
}
|
|
2086
2126
|
return _DocCustomSchemaFieldRelationValue.defaultValue();
|
|
2087
2127
|
}
|
|
@@ -2113,9 +2153,7 @@ var DocCustomSchemaFieldSelectNumberValue = class _DocCustomSchemaFieldSelectNum
|
|
|
2113
2153
|
return zDocMetaFieldSelectNumber.parse(value);
|
|
2114
2154
|
} catch {
|
|
2115
2155
|
if (this.value.required) {
|
|
2116
|
-
throw new Error(
|
|
2117
|
-
`required field "${this.key.toString()}" is missing or invalid`
|
|
2118
|
-
);
|
|
2156
|
+
throw new Error(`required field "${this.key.toString()}" is missing or invalid`);
|
|
2119
2157
|
}
|
|
2120
2158
|
return _DocCustomSchemaFieldSelectNumberValue.defaultValue();
|
|
2121
2159
|
}
|
|
@@ -2147,9 +2185,7 @@ var DocCustomSchemaFieldSelectTextValue = class _DocCustomSchemaFieldSelectTextV
|
|
|
2147
2185
|
return zDocMetaFieldSelectText.parse(value);
|
|
2148
2186
|
} catch {
|
|
2149
2187
|
if (this.value.required) {
|
|
2150
|
-
throw new Error(
|
|
2151
|
-
`required field "${this.key.toString()}" is missing or invalid`
|
|
2152
|
-
);
|
|
2188
|
+
throw new Error(`required field "${this.key.toString()}" is missing or invalid`);
|
|
2153
2189
|
}
|
|
2154
2190
|
return _DocCustomSchemaFieldSelectTextValue.defaultValue();
|
|
2155
2191
|
}
|
|
@@ -2181,9 +2217,7 @@ var DocCustomSchemaFieldTextValue = class _DocCustomSchemaFieldTextValue {
|
|
|
2181
2217
|
return zDocMetaFieldText.parse(value);
|
|
2182
2218
|
} catch {
|
|
2183
2219
|
if (this.value.required) {
|
|
2184
|
-
throw new Error(
|
|
2185
|
-
`required field "${this.key.toString()}" is missing or invalid`
|
|
2186
|
-
);
|
|
2220
|
+
throw new Error(`required field "${this.key.toString()}" is missing or invalid`);
|
|
2187
2221
|
}
|
|
2188
2222
|
return _DocCustomSchemaFieldTextValue.defaultValue();
|
|
2189
2223
|
}
|
|
@@ -2246,10 +2280,7 @@ var DocMetaFieldBooleanValue = class _DocMetaFieldBooleanValue {
|
|
|
2246
2280
|
}
|
|
2247
2281
|
type = "boolean";
|
|
2248
2282
|
static from(key, value) {
|
|
2249
|
-
return new _DocMetaFieldBooleanValue(
|
|
2250
|
-
key,
|
|
2251
|
-
zDocMetaFieldBoolean.parse(value)
|
|
2252
|
-
);
|
|
2283
|
+
return new _DocMetaFieldBooleanValue(key, zDocMetaFieldBoolean.parse(value));
|
|
2253
2284
|
}
|
|
2254
2285
|
static default(key) {
|
|
2255
2286
|
return new _DocMetaFieldBooleanValue(key, false);
|
|
@@ -2269,10 +2300,7 @@ var DocMetaFieldMultiNumberValue = class _DocMetaFieldMultiNumberValue {
|
|
|
2269
2300
|
}
|
|
2270
2301
|
type = "multi-number";
|
|
2271
2302
|
static from(key, value) {
|
|
2272
|
-
return new _DocMetaFieldMultiNumberValue(
|
|
2273
|
-
key,
|
|
2274
|
-
zDocMetaFieldMultiNumber.parse(value)
|
|
2275
|
-
);
|
|
2303
|
+
return new _DocMetaFieldMultiNumberValue(key, zDocMetaFieldMultiNumber.parse(value));
|
|
2276
2304
|
}
|
|
2277
2305
|
static default(key) {
|
|
2278
2306
|
return new _DocMetaFieldMultiNumberValue(key, []);
|
|
@@ -2292,10 +2320,7 @@ var DocMetaFieldMultiRelationValue = class _DocMetaFieldMultiRelationValue {
|
|
|
2292
2320
|
}
|
|
2293
2321
|
type = "multi-relation";
|
|
2294
2322
|
static from(key, value) {
|
|
2295
|
-
return new _DocMetaFieldMultiRelationValue(
|
|
2296
|
-
key,
|
|
2297
|
-
zDocMetaFieldMultiRelation.parse(value)
|
|
2298
|
-
);
|
|
2323
|
+
return new _DocMetaFieldMultiRelationValue(key, zDocMetaFieldMultiRelation.parse(value));
|
|
2299
2324
|
}
|
|
2300
2325
|
static default(key) {
|
|
2301
2326
|
return new _DocMetaFieldMultiRelationValue(key, []);
|
|
@@ -2338,10 +2363,7 @@ var DocMetaFieldMultiSelectTextValue = class _DocMetaFieldMultiSelectTextValue {
|
|
|
2338
2363
|
}
|
|
2339
2364
|
type = "multi-select-text";
|
|
2340
2365
|
static from(key, value) {
|
|
2341
|
-
return new _DocMetaFieldMultiSelectTextValue(
|
|
2342
|
-
key,
|
|
2343
|
-
zDocMetaFieldMultiSelectText.parse(value)
|
|
2344
|
-
);
|
|
2366
|
+
return new _DocMetaFieldMultiSelectTextValue(key, zDocMetaFieldMultiSelectText.parse(value));
|
|
2345
2367
|
}
|
|
2346
2368
|
static default(key) {
|
|
2347
2369
|
return new _DocMetaFieldMultiSelectTextValue(key, []);
|
|
@@ -2361,10 +2383,7 @@ var DocMetaFieldMultiTextValue = class _DocMetaFieldMultiTextValue {
|
|
|
2361
2383
|
}
|
|
2362
2384
|
type = "multi-text";
|
|
2363
2385
|
static from(key, value) {
|
|
2364
|
-
return new _DocMetaFieldMultiTextValue(
|
|
2365
|
-
key,
|
|
2366
|
-
zDocMetaFieldMultiText.parse(value)
|
|
2367
|
-
);
|
|
2386
|
+
return new _DocMetaFieldMultiTextValue(key, zDocMetaFieldMultiText.parse(value));
|
|
2368
2387
|
}
|
|
2369
2388
|
static default(key) {
|
|
2370
2389
|
return new _DocMetaFieldMultiTextValue(key, []);
|
|
@@ -2404,10 +2423,7 @@ var DocMetaFieldRelationValue = class _DocMetaFieldRelationValue {
|
|
|
2404
2423
|
}
|
|
2405
2424
|
type = "relation";
|
|
2406
2425
|
static from(key, value) {
|
|
2407
|
-
return new _DocMetaFieldRelationValue(
|
|
2408
|
-
key,
|
|
2409
|
-
zDocMetaFieldRelation.parse(value)
|
|
2410
|
-
);
|
|
2426
|
+
return new _DocMetaFieldRelationValue(key, zDocMetaFieldRelation.parse(value));
|
|
2411
2427
|
}
|
|
2412
2428
|
static default(key) {
|
|
2413
2429
|
return new _DocMetaFieldRelationValue(key, null);
|
|
@@ -2427,10 +2443,7 @@ var DocMetaFieldSelectNumberValue = class _DocMetaFieldSelectNumberValue {
|
|
|
2427
2443
|
}
|
|
2428
2444
|
type = "select-number";
|
|
2429
2445
|
static from(key, value) {
|
|
2430
|
-
return new _DocMetaFieldSelectNumberValue(
|
|
2431
|
-
key,
|
|
2432
|
-
zDocMetaFieldSelectNumber.parse(value)
|
|
2433
|
-
);
|
|
2446
|
+
return new _DocMetaFieldSelectNumberValue(key, zDocMetaFieldSelectNumber.parse(value));
|
|
2434
2447
|
}
|
|
2435
2448
|
static default(key) {
|
|
2436
2449
|
return new _DocMetaFieldSelectNumberValue(key, null);
|
|
@@ -2450,10 +2463,7 @@ var DocMetaFieldSelectTextValue = class _DocMetaFieldSelectTextValue {
|
|
|
2450
2463
|
}
|
|
2451
2464
|
type = "select-text";
|
|
2452
2465
|
static from(key, value) {
|
|
2453
|
-
return new _DocMetaFieldSelectTextValue(
|
|
2454
|
-
key,
|
|
2455
|
-
zDocMetaFieldSelectText.parse(value)
|
|
2456
|
-
);
|
|
2466
|
+
return new _DocMetaFieldSelectTextValue(key, zDocMetaFieldSelectText.parse(value));
|
|
2457
2467
|
}
|
|
2458
2468
|
static default(key) {
|
|
2459
2469
|
return new _DocMetaFieldSelectTextValue(key, null);
|
|
@@ -2564,7 +2574,7 @@ var DocFileMdMetaValue = class _DocFileMdMetaValue {
|
|
|
2564
2574
|
constructor(value, customSchema) {
|
|
2565
2575
|
this.value = value;
|
|
2566
2576
|
this.customSchema = customSchema;
|
|
2567
|
-
for (const key
|
|
2577
|
+
for (const key of Object.keys(customSchema)) {
|
|
2568
2578
|
const field = customSchema[key];
|
|
2569
2579
|
if (field.required && !(key in value)) {
|
|
2570
2580
|
throw new Error(`Required field "${key}" is missing`);
|
|
@@ -2696,10 +2706,7 @@ var DocFileMdMetaValue = class _DocFileMdMetaValue {
|
|
|
2696
2706
|
const value = customSchemaField.validate(record[key]);
|
|
2697
2707
|
validatedRecord[key] = value;
|
|
2698
2708
|
}
|
|
2699
|
-
return new _DocFileMdMetaValue(
|
|
2700
|
-
validatedRecord,
|
|
2701
|
-
customSchema
|
|
2702
|
-
);
|
|
2709
|
+
return new _DocFileMdMetaValue(validatedRecord, customSchema);
|
|
2703
2710
|
}
|
|
2704
2711
|
static empty(customSchema) {
|
|
2705
2712
|
const record = {};
|
|
@@ -2775,11 +2782,7 @@ var DocFileMdContentValue = class _DocFileMdContentValue {
|
|
|
2775
2782
|
withDescription(description, defaultTitle) {
|
|
2776
2783
|
const fullText = this.toText();
|
|
2777
2784
|
const engine = new DocMarkdownSystem();
|
|
2778
|
-
const updatedText = engine.updateDescription(
|
|
2779
|
-
fullText,
|
|
2780
|
-
description,
|
|
2781
|
-
defaultTitle || this.title
|
|
2782
|
-
);
|
|
2785
|
+
const updatedText = engine.updateDescription(fullText, description, defaultTitle || this.title);
|
|
2783
2786
|
const updatedBody = engine.extractBody(updatedText);
|
|
2784
2787
|
return new _DocFileMdContentValue(
|
|
2785
2788
|
{
|
|
@@ -2936,15 +2939,9 @@ var DocFileMdEntity = class _DocFileMdEntity {
|
|
|
2936
2939
|
withPath(pathOrUpdater) {
|
|
2937
2940
|
if (typeof pathOrUpdater === "function") {
|
|
2938
2941
|
const updatedPath = pathOrUpdater(this.path);
|
|
2939
|
-
return new _DocFileMdEntity(
|
|
2940
|
-
{ ...this.value, path: updatedPath },
|
|
2941
|
-
this.customSchema
|
|
2942
|
-
);
|
|
2942
|
+
return new _DocFileMdEntity({ ...this.value, path: updatedPath }, this.customSchema);
|
|
2943
2943
|
}
|
|
2944
|
-
return new _DocFileMdEntity(
|
|
2945
|
-
{ ...this.value, path: pathOrUpdater },
|
|
2946
|
-
this.customSchema
|
|
2947
|
-
);
|
|
2944
|
+
return new _DocFileMdEntity({ ...this.value, path: pathOrUpdater }, this.customSchema);
|
|
2948
2945
|
}
|
|
2949
2946
|
withMeta(metaOrUpdater) {
|
|
2950
2947
|
if (typeof metaOrUpdater === "function") {
|
|
@@ -3040,7 +3037,6 @@ var DocRelationFileValue = class _DocRelationFileValue {
|
|
|
3040
3037
|
path: null
|
|
3041
3038
|
});
|
|
3042
3039
|
}
|
|
3043
|
-
// biome-ignore lint/correctness/noUnusedPrivateClassMembers: Used in from static method
|
|
3044
3040
|
static extractFileName(filePath) {
|
|
3045
3041
|
if (!filePath) {
|
|
3046
3042
|
return filePath;
|
|
@@ -3115,40 +3111,28 @@ var DocFileRelationReference = class {
|
|
|
3115
3111
|
Object.freeze(this);
|
|
3116
3112
|
}
|
|
3117
3113
|
pathSystem;
|
|
3114
|
+
get safe() {
|
|
3115
|
+
return createSafeProxy(this);
|
|
3116
|
+
}
|
|
3118
3117
|
get fileSystem() {
|
|
3119
3118
|
return this.props.fileSystem;
|
|
3120
3119
|
}
|
|
3121
3120
|
get basePath() {
|
|
3122
3121
|
return this.fileSystem.getBasePath();
|
|
3123
3122
|
}
|
|
3124
|
-
/**
|
|
3125
|
-
* Relation path
|
|
3126
|
-
*/
|
|
3127
3123
|
get path() {
|
|
3128
3124
|
return this.props.filePath;
|
|
3129
3125
|
}
|
|
3130
|
-
/**
|
|
3131
|
-
* Full path
|
|
3132
|
-
*/
|
|
3133
3126
|
get fullPath() {
|
|
3134
|
-
return this.pathSystem.join(
|
|
3135
|
-
this.fileSystem.getBasePath(),
|
|
3136
|
-
this.props.filePath
|
|
3137
|
-
);
|
|
3127
|
+
return this.pathSystem.join(this.fileSystem.getBasePath(), this.props.filePath);
|
|
3138
3128
|
}
|
|
3139
3129
|
async read() {
|
|
3140
3130
|
const files = await this.readFiles();
|
|
3141
|
-
if (files instanceof Error) {
|
|
3142
|
-
return files;
|
|
3143
|
-
}
|
|
3144
3131
|
return new DocRelationValue({
|
|
3145
3132
|
path: this.path,
|
|
3146
3133
|
files: files.map((value) => value.toJson())
|
|
3147
3134
|
});
|
|
3148
3135
|
}
|
|
3149
|
-
/**
|
|
3150
|
-
* Read list of relation files
|
|
3151
|
-
*/
|
|
3152
3136
|
async readFiles() {
|
|
3153
3137
|
const exists = await this.fileSystem.exists(this.path);
|
|
3154
3138
|
if (!exists) {
|
|
@@ -3156,14 +3140,11 @@ var DocFileRelationReference = class {
|
|
|
3156
3140
|
}
|
|
3157
3141
|
const filePaths = await this.fileSystem.readDirectoryFilePaths(this.path);
|
|
3158
3142
|
if (filePaths instanceof Error) {
|
|
3159
|
-
|
|
3143
|
+
throw filePaths;
|
|
3160
3144
|
}
|
|
3161
3145
|
const files = [];
|
|
3162
3146
|
for (const filePath of filePaths) {
|
|
3163
3147
|
const file = await this.readFile(filePath);
|
|
3164
|
-
if (file instanceof Error) {
|
|
3165
|
-
return file;
|
|
3166
|
-
}
|
|
3167
3148
|
if (file === null) {
|
|
3168
3149
|
continue;
|
|
3169
3150
|
}
|
|
@@ -3171,9 +3152,6 @@ var DocFileRelationReference = class {
|
|
|
3171
3152
|
}
|
|
3172
3153
|
return files;
|
|
3173
3154
|
}
|
|
3174
|
-
/**
|
|
3175
|
-
* Read single relation file
|
|
3176
|
-
*/
|
|
3177
3155
|
async readFile(filePath) {
|
|
3178
3156
|
if (filePath.includes("index.md")) {
|
|
3179
3157
|
return null;
|
|
@@ -3183,17 +3161,13 @@ var DocFileRelationReference = class {
|
|
|
3183
3161
|
}
|
|
3184
3162
|
const content = await this.fileSystem.readFile(filePath);
|
|
3185
3163
|
if (content instanceof Error) {
|
|
3186
|
-
|
|
3164
|
+
throw content;
|
|
3187
3165
|
}
|
|
3188
3166
|
if (content === null) {
|
|
3189
3167
|
return null;
|
|
3190
3168
|
}
|
|
3191
3169
|
const contentValue = DocFileMdContentValue.fromMarkdown(content, {});
|
|
3192
|
-
const pathValue = DocFilePathValue.fromPathWithSystem(
|
|
3193
|
-
filePath,
|
|
3194
|
-
this.pathSystem,
|
|
3195
|
-
this.basePath
|
|
3196
|
-
);
|
|
3170
|
+
const pathValue = DocFilePathValue.fromPathWithSystem(filePath, this.pathSystem, this.basePath);
|
|
3197
3171
|
const fileEntity = new DocFileMdEntity(
|
|
3198
3172
|
{
|
|
3199
3173
|
type: "markdown",
|
|
@@ -3205,42 +3179,21 @@ var DocFileRelationReference = class {
|
|
|
3205
3179
|
);
|
|
3206
3180
|
return DocRelationFileValue.from(filePath, fileEntity.value.content.title);
|
|
3207
3181
|
}
|
|
3208
|
-
/**
|
|
3209
|
-
* Check if file exists
|
|
3210
|
-
*/
|
|
3211
3182
|
async exists(slug) {
|
|
3212
3183
|
const filePath = `${this.path}/${slug}.md`;
|
|
3213
3184
|
return this.fileSystem.exists(filePath);
|
|
3214
3185
|
}
|
|
3215
|
-
/**
|
|
3216
|
-
* Get list of file names (without extension)
|
|
3217
|
-
*/
|
|
3218
3186
|
async readSlugs() {
|
|
3219
3187
|
const files = await this.readFiles();
|
|
3220
|
-
if (files instanceof Error) {
|
|
3221
|
-
return files;
|
|
3222
|
-
}
|
|
3223
3188
|
return files.map((file) => file.id);
|
|
3224
3189
|
}
|
|
3225
|
-
/**
|
|
3226
|
-
* Get file count
|
|
3227
|
-
*/
|
|
3228
3190
|
async count() {
|
|
3229
3191
|
const files = await this.readFiles();
|
|
3230
|
-
if (files instanceof Error) {
|
|
3231
|
-
return files;
|
|
3232
|
-
}
|
|
3233
3192
|
return files.length;
|
|
3234
3193
|
}
|
|
3235
|
-
/**
|
|
3236
|
-
* Check if empty
|
|
3237
|
-
*/
|
|
3238
3194
|
async isEmpty() {
|
|
3239
|
-
const
|
|
3240
|
-
|
|
3241
|
-
return count;
|
|
3242
|
-
}
|
|
3243
|
-
return count === 0;
|
|
3195
|
+
const fileCount = await this.count();
|
|
3196
|
+
return fileCount === 0;
|
|
3244
3197
|
}
|
|
3245
3198
|
};
|
|
3246
3199
|
|
|
@@ -3254,6 +3207,9 @@ var DocFileIndexReference = class _DocFileIndexReference {
|
|
|
3254
3207
|
}
|
|
3255
3208
|
pathSystem;
|
|
3256
3209
|
customSchema;
|
|
3210
|
+
get safe() {
|
|
3211
|
+
return createSafeProxy(this);
|
|
3212
|
+
}
|
|
3257
3213
|
get fileSystem() {
|
|
3258
3214
|
return this.props.fileSystem;
|
|
3259
3215
|
}
|
|
@@ -3266,13 +3222,14 @@ var DocFileIndexReference = class _DocFileIndexReference {
|
|
|
3266
3222
|
get fileFullPath() {
|
|
3267
3223
|
return this.pathSystem.join(this.basePath, this.filePath);
|
|
3268
3224
|
}
|
|
3269
|
-
get
|
|
3225
|
+
get directoryPath() {
|
|
3270
3226
|
return this.pathSystem.dirname(this.filePath);
|
|
3271
3227
|
}
|
|
3272
3228
|
async read() {
|
|
3229
|
+
const directoryMeta = await this.readDirectoryMeta();
|
|
3273
3230
|
const content = await this.fileSystem.readFile(this.filePath);
|
|
3274
3231
|
if (content instanceof Error) {
|
|
3275
|
-
|
|
3232
|
+
throw content;
|
|
3276
3233
|
}
|
|
3277
3234
|
if (content === null) {
|
|
3278
3235
|
const dirPath = this.pathSystem.dirname(this.filePath);
|
|
@@ -3282,11 +3239,12 @@ var DocFileIndexReference = class _DocFileIndexReference {
|
|
|
3282
3239
|
this.pathSystem,
|
|
3283
3240
|
this.fileSystem.getBasePath()
|
|
3284
3241
|
);
|
|
3285
|
-
const contentValue2 = DocFileIndexContentValue.
|
|
3242
|
+
const contentValue2 = directoryMeta ? DocFileIndexContentValue.emptyWithDirectoryMeta(
|
|
3286
3243
|
dirName,
|
|
3287
3244
|
this.customSchema,
|
|
3288
|
-
this.props.config
|
|
3289
|
-
|
|
3245
|
+
this.props.config,
|
|
3246
|
+
directoryMeta
|
|
3247
|
+
) : DocFileIndexContentValue.empty(dirName, this.customSchema, this.props.config);
|
|
3290
3248
|
return new DocFileIndexEntity(
|
|
3291
3249
|
{
|
|
3292
3250
|
type: "index",
|
|
@@ -3302,11 +3260,12 @@ var DocFileIndexReference = class _DocFileIndexReference {
|
|
|
3302
3260
|
this.pathSystem,
|
|
3303
3261
|
this.fileSystem.getBasePath()
|
|
3304
3262
|
);
|
|
3305
|
-
const contentValue = DocFileIndexContentValue.
|
|
3263
|
+
const contentValue = directoryMeta ? DocFileIndexContentValue.fromMarkdownWithDirectoryMeta(
|
|
3306
3264
|
content,
|
|
3307
3265
|
this.customSchema,
|
|
3308
|
-
this.props.config
|
|
3309
|
-
|
|
3266
|
+
this.props.config,
|
|
3267
|
+
directoryMeta
|
|
3268
|
+
) : DocFileIndexContentValue.fromMarkdown(content, this.customSchema, this.props.config);
|
|
3310
3269
|
return new DocFileIndexEntity(
|
|
3311
3270
|
{
|
|
3312
3271
|
type: "index",
|
|
@@ -3317,21 +3276,38 @@ var DocFileIndexReference = class _DocFileIndexReference {
|
|
|
3317
3276
|
this.customSchema
|
|
3318
3277
|
);
|
|
3319
3278
|
}
|
|
3279
|
+
async readDirectoryMeta() {
|
|
3280
|
+
const metaFileName = this.props.config.metaFileName ?? ".meta.json";
|
|
3281
|
+
const metaPath = this.pathSystem.join(this.directoryPath, metaFileName);
|
|
3282
|
+
const metaContent = await this.fileSystem.readFile(metaPath);
|
|
3283
|
+
if (metaContent instanceof Error) {
|
|
3284
|
+
return null;
|
|
3285
|
+
}
|
|
3286
|
+
if (metaContent === null || metaContent === "") {
|
|
3287
|
+
return null;
|
|
3288
|
+
}
|
|
3289
|
+
let parsed;
|
|
3290
|
+
try {
|
|
3291
|
+
parsed = JSON.parse(metaContent);
|
|
3292
|
+
} catch {
|
|
3293
|
+
return null;
|
|
3294
|
+
}
|
|
3295
|
+
const parseResult = zDocDirectoryMeta.safeParse(parsed);
|
|
3296
|
+
if (parseResult.success === false) {
|
|
3297
|
+
return null;
|
|
3298
|
+
}
|
|
3299
|
+
return parseResult.data;
|
|
3300
|
+
}
|
|
3320
3301
|
async readSchemaValue() {
|
|
3321
|
-
|
|
3322
|
-
|
|
3302
|
+
try {
|
|
3303
|
+
const indexFile = await this.read();
|
|
3304
|
+
return indexFile.content.meta().schema().value;
|
|
3305
|
+
} catch {
|
|
3323
3306
|
return {};
|
|
3324
3307
|
}
|
|
3325
|
-
return indexFile.content.meta().schema().value;
|
|
3326
3308
|
}
|
|
3327
|
-
/**
|
|
3328
|
-
* Read file content
|
|
3329
|
-
*/
|
|
3330
3309
|
async readContent() {
|
|
3331
3310
|
const entity = await this.read();
|
|
3332
|
-
if (entity instanceof Error) {
|
|
3333
|
-
return entity;
|
|
3334
|
-
}
|
|
3335
3311
|
return entity.value.content.body;
|
|
3336
3312
|
}
|
|
3337
3313
|
/**
|
|
@@ -3360,22 +3336,19 @@ var DocFileIndexReference = class _DocFileIndexReference {
|
|
|
3360
3336
|
this.customSchema
|
|
3361
3337
|
);
|
|
3362
3338
|
}
|
|
3363
|
-
/**
|
|
3364
|
-
* Write content to file
|
|
3365
|
-
*/
|
|
3366
3339
|
async writeContent(content) {
|
|
3367
|
-
|
|
3340
|
+
const writeResult = await this.fileSystem.writeFile(this.filePath, content);
|
|
3341
|
+
if (writeResult instanceof Error) {
|
|
3342
|
+
throw writeResult;
|
|
3343
|
+
}
|
|
3368
3344
|
}
|
|
3369
|
-
/**
|
|
3370
|
-
* Write entity
|
|
3371
|
-
*/
|
|
3372
3345
|
async write(entity) {
|
|
3373
3346
|
const content = entity.content.toText();
|
|
3374
|
-
|
|
3347
|
+
const writeResult = await this.fileSystem.writeFile(this.filePath, content);
|
|
3348
|
+
if (writeResult instanceof Error) {
|
|
3349
|
+
throw writeResult;
|
|
3350
|
+
}
|
|
3375
3351
|
}
|
|
3376
|
-
/**
|
|
3377
|
-
* Create new file with default content
|
|
3378
|
-
*/
|
|
3379
3352
|
async writeDefault() {
|
|
3380
3353
|
const dirPath = this.pathSystem.dirname(this.filePath);
|
|
3381
3354
|
const dirName = this.pathSystem.basename(dirPath) || this.props.config.defaultDirectoryName;
|
|
@@ -3384,32 +3357,22 @@ var DocFileIndexReference = class _DocFileIndexReference {
|
|
|
3384
3357
|
"",
|
|
3385
3358
|
`Please describe the overview of ${dirName} here.`
|
|
3386
3359
|
].join("\n");
|
|
3387
|
-
const writeResult = await this.fileSystem.writeFile(
|
|
3388
|
-
this.filePath,
|
|
3389
|
-
defaultContent
|
|
3390
|
-
);
|
|
3360
|
+
const writeResult = await this.fileSystem.writeFile(this.filePath, defaultContent);
|
|
3391
3361
|
if (writeResult instanceof Error) {
|
|
3392
|
-
|
|
3362
|
+
throw writeResult;
|
|
3393
3363
|
}
|
|
3394
|
-
return null;
|
|
3395
3364
|
}
|
|
3396
|
-
/**
|
|
3397
|
-
* Delete file
|
|
3398
|
-
*/
|
|
3399
3365
|
async delete() {
|
|
3400
|
-
|
|
3366
|
+
const deleteResult = await this.fileSystem.deleteFile(this.filePath);
|
|
3367
|
+
if (deleteResult instanceof Error) {
|
|
3368
|
+
throw deleteResult;
|
|
3369
|
+
}
|
|
3401
3370
|
}
|
|
3402
|
-
/**
|
|
3403
|
-
* Check if file exists
|
|
3404
|
-
*/
|
|
3405
3371
|
async exists() {
|
|
3406
3372
|
return this.fileSystem.exists(this.filePath);
|
|
3407
3373
|
}
|
|
3408
3374
|
async relations() {
|
|
3409
3375
|
const indexFile = await this.read();
|
|
3410
|
-
if (indexFile instanceof Error) {
|
|
3411
|
-
return indexFile;
|
|
3412
|
-
}
|
|
3413
3376
|
const schema = indexFile.content.meta().schema();
|
|
3414
3377
|
if (!schema) {
|
|
3415
3378
|
return [];
|
|
@@ -3419,11 +3382,14 @@ var DocFileIndexReference = class _DocFileIndexReference {
|
|
|
3419
3382
|
for (const key of fieldKeys) {
|
|
3420
3383
|
const fieldValue = schema.value[key];
|
|
3421
3384
|
if (fieldValue === void 0) continue;
|
|
3422
|
-
|
|
3423
|
-
|
|
3385
|
+
let path = null;
|
|
3386
|
+
if (fieldValue.type === "relation") {
|
|
3387
|
+
path = schema.relation(key).path;
|
|
3388
|
+
}
|
|
3389
|
+
if (fieldValue.type === "multi-relation") {
|
|
3390
|
+
path = schema.multiRelation(key).path;
|
|
3424
3391
|
}
|
|
3425
|
-
|
|
3426
|
-
const path = field.path;
|
|
3392
|
+
if (path === null) continue;
|
|
3427
3393
|
const fileRef = new DocFileRelationReference({
|
|
3428
3394
|
filePath: path,
|
|
3429
3395
|
fileSystem: this.fileSystem,
|
|
@@ -3435,55 +3401,44 @@ var DocFileIndexReference = class _DocFileIndexReference {
|
|
|
3435
3401
|
}
|
|
3436
3402
|
async readRelations() {
|
|
3437
3403
|
const relations = await this.relations();
|
|
3438
|
-
if (relations instanceof Error) {
|
|
3439
|
-
return relations;
|
|
3440
|
-
}
|
|
3441
3404
|
const files = [];
|
|
3442
3405
|
for (const relation of relations) {
|
|
3443
|
-
|
|
3444
|
-
|
|
3445
|
-
continue;
|
|
3446
|
-
|
|
3447
|
-
|
|
3406
|
+
try {
|
|
3407
|
+
const entity = await relation.read();
|
|
3408
|
+
if (entity === null) continue;
|
|
3409
|
+
files.push(entity);
|
|
3410
|
+
} catch {
|
|
3448
3411
|
continue;
|
|
3449
3412
|
}
|
|
3450
|
-
files.push(entity);
|
|
3451
3413
|
}
|
|
3452
3414
|
return files;
|
|
3453
3415
|
}
|
|
3454
|
-
/**
|
|
3455
|
-
* Get file size in bytes
|
|
3456
|
-
*/
|
|
3457
3416
|
async size() {
|
|
3458
|
-
|
|
3417
|
+
const fileSize = await this.fileSystem.getFileSize(this.filePath);
|
|
3418
|
+
if (fileSize instanceof Error) {
|
|
3419
|
+
throw fileSize;
|
|
3420
|
+
}
|
|
3421
|
+
return fileSize;
|
|
3459
3422
|
}
|
|
3460
|
-
/**
|
|
3461
|
-
* Get last modified date
|
|
3462
|
-
*/
|
|
3463
3423
|
async lastModified() {
|
|
3464
|
-
|
|
3424
|
+
const updatedTime = await this.fileSystem.getFileUpdatedTime(this.filePath);
|
|
3425
|
+
if (updatedTime instanceof Error) {
|
|
3426
|
+
throw updatedTime;
|
|
3427
|
+
}
|
|
3428
|
+
return updatedTime;
|
|
3465
3429
|
}
|
|
3466
|
-
/**
|
|
3467
|
-
* Get file creation date
|
|
3468
|
-
*/
|
|
3469
3430
|
async createdAt() {
|
|
3470
|
-
|
|
3431
|
+
const createdTime = await this.fileSystem.getFileCreatedTime(this.filePath);
|
|
3432
|
+
if (createdTime instanceof Error) {
|
|
3433
|
+
throw createdTime;
|
|
3434
|
+
}
|
|
3435
|
+
return createdTime;
|
|
3471
3436
|
}
|
|
3472
|
-
/**
|
|
3473
|
-
* Move file to archive and return new reference
|
|
3474
|
-
*/
|
|
3475
3437
|
async archive(archiveDirectoryName = this.props.config.archiveDirectoryName) {
|
|
3476
3438
|
const dirPath = this.pathSystem.dirname(this.filePath);
|
|
3477
3439
|
const fileName = this.pathSystem.basename(this.filePath);
|
|
3478
|
-
const archivePath = this.pathSystem.join(
|
|
3479
|
-
|
|
3480
|
-
archiveDirectoryName,
|
|
3481
|
-
fileName
|
|
3482
|
-
);
|
|
3483
|
-
const moveResult = await this.fileSystem.moveFile(
|
|
3484
|
-
this.filePath,
|
|
3485
|
-
archivePath
|
|
3486
|
-
);
|
|
3440
|
+
const archivePath = this.pathSystem.join(dirPath, archiveDirectoryName, fileName);
|
|
3441
|
+
const moveResult = await this.fileSystem.moveFile(this.filePath, archivePath);
|
|
3487
3442
|
if (moveResult instanceof Error) {
|
|
3488
3443
|
throw moveResult;
|
|
3489
3444
|
}
|
|
@@ -3495,9 +3450,6 @@ var DocFileIndexReference = class _DocFileIndexReference {
|
|
|
3495
3450
|
config: this.props.config
|
|
3496
3451
|
});
|
|
3497
3452
|
}
|
|
3498
|
-
/**
|
|
3499
|
-
* Restore file from archive and return new reference
|
|
3500
|
-
*/
|
|
3501
3453
|
async restore(archiveDirectoryName = this.props.config.archiveDirectoryName) {
|
|
3502
3454
|
const dirPath = this.pathSystem.dirname(this.filePath);
|
|
3503
3455
|
const parentDirName = this.pathSystem.basename(dirPath);
|
|
@@ -3505,14 +3457,8 @@ var DocFileIndexReference = class _DocFileIndexReference {
|
|
|
3505
3457
|
throw new Error(`File is not in archive directory: ${this.filePath}`);
|
|
3506
3458
|
}
|
|
3507
3459
|
const fileName = this.pathSystem.basename(this.filePath);
|
|
3508
|
-
const restorePath = this.pathSystem.join(
|
|
3509
|
-
|
|
3510
|
-
fileName
|
|
3511
|
-
);
|
|
3512
|
-
const moveResult = await this.fileSystem.moveFile(
|
|
3513
|
-
this.filePath,
|
|
3514
|
-
restorePath
|
|
3515
|
-
);
|
|
3460
|
+
const restorePath = this.pathSystem.join(this.pathSystem.dirname(dirPath), fileName);
|
|
3461
|
+
const moveResult = await this.fileSystem.moveFile(this.filePath, restorePath);
|
|
3516
3462
|
if (moveResult instanceof Error) {
|
|
3517
3463
|
throw moveResult;
|
|
3518
3464
|
}
|
|
@@ -3582,6 +3528,9 @@ var DocFileUnknownReference = class _DocFileUnknownReference {
|
|
|
3582
3528
|
}
|
|
3583
3529
|
pathSystem;
|
|
3584
3530
|
customSchema;
|
|
3531
|
+
get safe() {
|
|
3532
|
+
return createSafeProxy(this);
|
|
3533
|
+
}
|
|
3585
3534
|
get fileSystem() {
|
|
3586
3535
|
return this.props.fileSystem;
|
|
3587
3536
|
}
|
|
@@ -3622,22 +3571,18 @@ var DocFileUnknownReference = class _DocFileUnknownReference {
|
|
|
3622
3571
|
});
|
|
3623
3572
|
}
|
|
3624
3573
|
async read() {
|
|
3574
|
+
if (this.path.endsWith(".md")) {
|
|
3575
|
+
throw new Error("Use DocFileMdReference to read Markdown files.");
|
|
3576
|
+
}
|
|
3625
3577
|
const content = await this.fileSystem.readFile(this.path);
|
|
3626
3578
|
if (content instanceof Error) {
|
|
3627
|
-
|
|
3579
|
+
throw content;
|
|
3628
3580
|
}
|
|
3629
3581
|
if (content === null) {
|
|
3630
|
-
|
|
3582
|
+
throw new Error(`File not found at ${this.path}.`);
|
|
3631
3583
|
}
|
|
3632
3584
|
const isInArchiveDir = this.path.includes("/_/") || this.path.startsWith("_/");
|
|
3633
|
-
|
|
3634
|
-
throw new Error("Use DocFileMdReference to read Markdown files.");
|
|
3635
|
-
}
|
|
3636
|
-
const pathValue = DocFilePathValue.fromPathWithSystem(
|
|
3637
|
-
this.path,
|
|
3638
|
-
this.pathSystem,
|
|
3639
|
-
this.basePath
|
|
3640
|
-
);
|
|
3585
|
+
const pathValue = DocFilePathValue.fromPathWithSystem(this.path, this.pathSystem, this.basePath);
|
|
3641
3586
|
const extension = this.pathSystem.extname(this.path).substring(1);
|
|
3642
3587
|
return new DocFileUnknownEntity({
|
|
3643
3588
|
type: "unknown",
|
|
@@ -3647,25 +3592,15 @@ var DocFileUnknownReference = class _DocFileUnknownReference {
|
|
|
3647
3592
|
isArchived: isInArchiveDir
|
|
3648
3593
|
});
|
|
3649
3594
|
}
|
|
3650
|
-
/**
|
|
3651
|
-
* Read file content
|
|
3652
|
-
*/
|
|
3653
3595
|
async readContent() {
|
|
3654
3596
|
const entity = await this.read();
|
|
3655
|
-
if (entity instanceof Error) {
|
|
3656
|
-
return entity;
|
|
3657
|
-
}
|
|
3658
3597
|
return entity.value.content;
|
|
3659
3598
|
}
|
|
3660
3599
|
/**
|
|
3661
3600
|
* Create empty DocFileUnknownEntity
|
|
3662
3601
|
*/
|
|
3663
3602
|
empty() {
|
|
3664
|
-
const pathValue = DocFilePathValue.fromPathWithSystem(
|
|
3665
|
-
this.path,
|
|
3666
|
-
this.pathSystem,
|
|
3667
|
-
this.basePath
|
|
3668
|
-
);
|
|
3603
|
+
const pathValue = DocFilePathValue.fromPathWithSystem(this.path, this.pathSystem, this.basePath);
|
|
3669
3604
|
const extension = this.pathSystem.extname(this.path).substring(1);
|
|
3670
3605
|
return new DocFileUnknownEntity({
|
|
3671
3606
|
type: "unknown",
|
|
@@ -3675,81 +3610,71 @@ var DocFileUnknownReference = class _DocFileUnknownReference {
|
|
|
3675
3610
|
isArchived: false
|
|
3676
3611
|
});
|
|
3677
3612
|
}
|
|
3678
|
-
/**
|
|
3679
|
-
* Write content to file
|
|
3680
|
-
*/
|
|
3681
3613
|
async writeContent(content) {
|
|
3682
|
-
|
|
3614
|
+
const writeResult = await this.fileSystem.writeFile(this.path, content);
|
|
3615
|
+
if (writeResult instanceof Error) {
|
|
3616
|
+
throw writeResult;
|
|
3617
|
+
}
|
|
3683
3618
|
}
|
|
3684
|
-
/**
|
|
3685
|
-
* Write entity
|
|
3686
|
-
*/
|
|
3687
3619
|
async write(entity) {
|
|
3688
|
-
|
|
3620
|
+
const writeResult = await this.fileSystem.writeFile(this.path, entity.value.content);
|
|
3621
|
+
if (writeResult instanceof Error) {
|
|
3622
|
+
throw writeResult;
|
|
3623
|
+
}
|
|
3689
3624
|
}
|
|
3690
|
-
/**
|
|
3691
|
-
* Write raw content
|
|
3692
|
-
*/
|
|
3693
3625
|
async writeRaw(content) {
|
|
3694
|
-
|
|
3626
|
+
const writeResult = await this.fileSystem.writeFile(this.path, content);
|
|
3627
|
+
if (writeResult instanceof Error) {
|
|
3628
|
+
throw writeResult;
|
|
3629
|
+
}
|
|
3695
3630
|
}
|
|
3696
|
-
/**
|
|
3697
|
-
* Delete file
|
|
3698
|
-
*/
|
|
3699
3631
|
async delete() {
|
|
3700
|
-
|
|
3632
|
+
const deleteResult = await this.fileSystem.deleteFile(this.path);
|
|
3633
|
+
if (deleteResult instanceof Error) {
|
|
3634
|
+
throw deleteResult;
|
|
3635
|
+
}
|
|
3701
3636
|
}
|
|
3702
|
-
/**
|
|
3703
|
-
* Check if file exists
|
|
3704
|
-
*/
|
|
3705
3637
|
async exists() {
|
|
3706
3638
|
return this.fileSystem.exists(this.path);
|
|
3707
3639
|
}
|
|
3708
|
-
/**
|
|
3709
|
-
* Copy file
|
|
3710
|
-
*/
|
|
3711
3640
|
async copyTo(destinationPath) {
|
|
3712
|
-
|
|
3641
|
+
const copyResult = await this.fileSystem.copyFile(this.path, destinationPath);
|
|
3642
|
+
if (copyResult instanceof Error) {
|
|
3643
|
+
throw copyResult;
|
|
3644
|
+
}
|
|
3713
3645
|
}
|
|
3714
|
-
/**
|
|
3715
|
-
* Move file
|
|
3716
|
-
*/
|
|
3717
3646
|
async moveTo(destinationPath) {
|
|
3718
|
-
|
|
3647
|
+
const moveResult = await this.fileSystem.moveFile(this.path, destinationPath);
|
|
3648
|
+
if (moveResult instanceof Error) {
|
|
3649
|
+
throw moveResult;
|
|
3650
|
+
}
|
|
3719
3651
|
}
|
|
3720
|
-
/**
|
|
3721
|
-
* Get file size in bytes
|
|
3722
|
-
*/
|
|
3723
3652
|
async size() {
|
|
3724
|
-
|
|
3653
|
+
const fileSize = await this.fileSystem.getFileSize(this.path);
|
|
3654
|
+
if (fileSize instanceof Error) {
|
|
3655
|
+
throw fileSize;
|
|
3656
|
+
}
|
|
3657
|
+
return fileSize;
|
|
3725
3658
|
}
|
|
3726
|
-
/**
|
|
3727
|
-
* Get file last modified time
|
|
3728
|
-
*/
|
|
3729
3659
|
async lastModified() {
|
|
3730
|
-
|
|
3660
|
+
const updatedTime = await this.fileSystem.getFileUpdatedTime(this.path);
|
|
3661
|
+
if (updatedTime instanceof Error) {
|
|
3662
|
+
throw updatedTime;
|
|
3663
|
+
}
|
|
3664
|
+
return updatedTime;
|
|
3731
3665
|
}
|
|
3732
|
-
/**
|
|
3733
|
-
* Get file creation time
|
|
3734
|
-
*/
|
|
3735
3666
|
async createdAt() {
|
|
3736
|
-
|
|
3667
|
+
const createdTime = await this.fileSystem.getFileCreatedTime(this.path);
|
|
3668
|
+
if (createdTime instanceof Error) {
|
|
3669
|
+
throw createdTime;
|
|
3670
|
+
}
|
|
3671
|
+
return createdTime;
|
|
3737
3672
|
}
|
|
3738
|
-
/**
|
|
3739
|
-
* Move file to archive and return new reference
|
|
3740
|
-
*/
|
|
3741
3673
|
async archive(archiveDirectoryName = this.props.config.archiveDirectoryName) {
|
|
3742
3674
|
const dirPath = this.pathSystem.dirname(this.path);
|
|
3743
3675
|
const fileName = this.pathSystem.basename(this.path);
|
|
3744
|
-
const archivePath = this.pathSystem.join(
|
|
3745
|
-
|
|
3746
|
-
archiveDirectoryName,
|
|
3747
|
-
fileName
|
|
3748
|
-
);
|
|
3749
|
-
const moveResult = await this.moveTo(archivePath);
|
|
3750
|
-
if (moveResult instanceof Error) {
|
|
3751
|
-
throw moveResult;
|
|
3752
|
-
}
|
|
3676
|
+
const archivePath = this.pathSystem.join(dirPath, archiveDirectoryName, fileName);
|
|
3677
|
+
await this.moveTo(archivePath);
|
|
3753
3678
|
return new _DocFileUnknownReference({
|
|
3754
3679
|
path: archivePath,
|
|
3755
3680
|
fileSystem: this.fileSystem,
|
|
@@ -3758,9 +3683,6 @@ var DocFileUnknownReference = class _DocFileUnknownReference {
|
|
|
3758
3683
|
customSchema: this.customSchema
|
|
3759
3684
|
});
|
|
3760
3685
|
}
|
|
3761
|
-
/**
|
|
3762
|
-
* Restore file from archive and return new reference
|
|
3763
|
-
*/
|
|
3764
3686
|
async restore(archiveDirectoryName = this.props.config.archiveDirectoryName) {
|
|
3765
3687
|
const dirPath = this.pathSystem.dirname(this.path);
|
|
3766
3688
|
const parentDirName = this.pathSystem.basename(dirPath);
|
|
@@ -3768,14 +3690,8 @@ var DocFileUnknownReference = class _DocFileUnknownReference {
|
|
|
3768
3690
|
throw new Error(`File is not in archive directory: ${this.path}`);
|
|
3769
3691
|
}
|
|
3770
3692
|
const fileName = this.pathSystem.basename(this.path);
|
|
3771
|
-
const restorePath = this.pathSystem.join(
|
|
3772
|
-
|
|
3773
|
-
fileName
|
|
3774
|
-
);
|
|
3775
|
-
const moveResult = await this.moveTo(restorePath);
|
|
3776
|
-
if (moveResult instanceof Error) {
|
|
3777
|
-
throw moveResult;
|
|
3778
|
-
}
|
|
3693
|
+
const restorePath = this.pathSystem.join(this.pathSystem.dirname(dirPath), fileName);
|
|
3694
|
+
await this.moveTo(restorePath);
|
|
3779
3695
|
return new _DocFileUnknownReference({
|
|
3780
3696
|
path: restorePath,
|
|
3781
3697
|
fileSystem: this.fileSystem,
|
|
@@ -3796,6 +3712,9 @@ var DocDirectoryReference = class _DocDirectoryReference {
|
|
|
3796
3712
|
}
|
|
3797
3713
|
pathSystem;
|
|
3798
3714
|
customSchema;
|
|
3715
|
+
get safe() {
|
|
3716
|
+
return createSafeProxy(this);
|
|
3717
|
+
}
|
|
3799
3718
|
get fileSystem() {
|
|
3800
3719
|
return this.props.fileSystem;
|
|
3801
3720
|
}
|
|
@@ -3827,11 +3746,7 @@ var DocDirectoryReference = class _DocDirectoryReference {
|
|
|
3827
3746
|
return this.props.indexFileName;
|
|
3828
3747
|
}
|
|
3829
3748
|
get indexFilePath() {
|
|
3830
|
-
return this.pathSystem.join(
|
|
3831
|
-
this.basePath,
|
|
3832
|
-
this.relativePath,
|
|
3833
|
-
this.props.indexFileName
|
|
3834
|
-
);
|
|
3749
|
+
return this.pathSystem.join(this.basePath, this.relativePath, this.props.indexFileName);
|
|
3835
3750
|
}
|
|
3836
3751
|
get archiveDirectoryName() {
|
|
3837
3752
|
return this.props.archiveDirectoryName;
|
|
@@ -3840,19 +3755,14 @@ var DocDirectoryReference = class _DocDirectoryReference {
|
|
|
3840
3755
|
return this.pathSystem.basename(this.path);
|
|
3841
3756
|
}
|
|
3842
3757
|
async fileNames() {
|
|
3843
|
-
const filePaths = await this.fileSystem.readDirectoryFilePaths(
|
|
3844
|
-
this.relativePath
|
|
3845
|
-
);
|
|
3758
|
+
const filePaths = await this.fileSystem.readDirectoryFilePaths(this.relativePath);
|
|
3846
3759
|
if (filePaths instanceof Error) {
|
|
3847
|
-
|
|
3760
|
+
throw filePaths;
|
|
3848
3761
|
}
|
|
3849
3762
|
return filePaths.map((p) => this.pathSystem.basename(p)).filter((name) => name.includes("."));
|
|
3850
3763
|
}
|
|
3851
3764
|
async archivedFileNames() {
|
|
3852
|
-
const archivePath = this.pathSystem.join(
|
|
3853
|
-
this.relativePath,
|
|
3854
|
-
this.archiveDirectoryName
|
|
3855
|
-
);
|
|
3765
|
+
const archivePath = this.pathSystem.join(this.relativePath, this.archiveDirectoryName);
|
|
3856
3766
|
const filePaths = await this.fileSystem.readDirectoryFilePaths(archivePath);
|
|
3857
3767
|
if (filePaths instanceof Error) {
|
|
3858
3768
|
return [];
|
|
@@ -3860,10 +3770,9 @@ var DocDirectoryReference = class _DocDirectoryReference {
|
|
|
3860
3770
|
return filePaths.map((p) => this.pathSystem.basename(p)).filter((name) => name.includes("."));
|
|
3861
3771
|
}
|
|
3862
3772
|
async *filesGenerator() {
|
|
3863
|
-
const
|
|
3864
|
-
|
|
3865
|
-
|
|
3866
|
-
if (fileName === "index.md") continue;
|
|
3773
|
+
const allFileNames = await this.fileNames();
|
|
3774
|
+
for (const fileName of allFileNames) {
|
|
3775
|
+
if (fileName === this.indexFileName) continue;
|
|
3867
3776
|
if (fileName.endsWith(".md")) {
|
|
3868
3777
|
yield new DocFileMdReference({
|
|
3869
3778
|
path: this.pathSystem.join(this.relativePath, fileName),
|
|
@@ -3882,17 +3791,12 @@ var DocDirectoryReference = class _DocDirectoryReference {
|
|
|
3882
3791
|
customSchema: this.customSchema
|
|
3883
3792
|
});
|
|
3884
3793
|
}
|
|
3885
|
-
const
|
|
3886
|
-
|
|
3887
|
-
for (const fileName of archivedFileNames) {
|
|
3794
|
+
const archivedNames = await this.archivedFileNames();
|
|
3795
|
+
for (const fileName of archivedNames) {
|
|
3888
3796
|
if (fileName === this.indexFileName) continue;
|
|
3889
3797
|
if (fileName.endsWith(".md")) {
|
|
3890
3798
|
yield new DocFileMdReference({
|
|
3891
|
-
path: this.pathSystem.join(
|
|
3892
|
-
this.relativePath,
|
|
3893
|
-
this.archiveDirectoryName,
|
|
3894
|
-
fileName
|
|
3895
|
-
),
|
|
3799
|
+
path: this.pathSystem.join(this.relativePath, this.archiveDirectoryName, fileName),
|
|
3896
3800
|
fileSystem: this.fileSystem,
|
|
3897
3801
|
pathSystem: this.pathSystem,
|
|
3898
3802
|
customSchema: this.customSchema,
|
|
@@ -3901,11 +3805,7 @@ var DocDirectoryReference = class _DocDirectoryReference {
|
|
|
3901
3805
|
continue;
|
|
3902
3806
|
}
|
|
3903
3807
|
yield new DocFileUnknownReference({
|
|
3904
|
-
path: this.pathSystem.join(
|
|
3905
|
-
this.relativePath,
|
|
3906
|
-
this.archiveDirectoryName,
|
|
3907
|
-
fileName
|
|
3908
|
-
),
|
|
3808
|
+
path: this.pathSystem.join(this.relativePath, this.archiveDirectoryName, fileName),
|
|
3909
3809
|
fileSystem: this.fileSystem,
|
|
3910
3810
|
pathSystem: this.pathSystem,
|
|
3911
3811
|
config: this.props.config,
|
|
@@ -3914,29 +3814,22 @@ var DocDirectoryReference = class _DocDirectoryReference {
|
|
|
3914
3814
|
}
|
|
3915
3815
|
}
|
|
3916
3816
|
async *mdFilesGenerator() {
|
|
3917
|
-
const
|
|
3918
|
-
for await (const file of generator) {
|
|
3919
|
-
if (file instanceof Error) {
|
|
3920
|
-
yield file;
|
|
3921
|
-
return;
|
|
3922
|
-
}
|
|
3817
|
+
for await (const file of this.filesGenerator()) {
|
|
3923
3818
|
if (file instanceof DocFileMdReference) {
|
|
3924
3819
|
yield file;
|
|
3925
3820
|
}
|
|
3926
3821
|
}
|
|
3927
3822
|
}
|
|
3928
3823
|
async files() {
|
|
3929
|
-
const
|
|
3824
|
+
const allFiles = [];
|
|
3930
3825
|
for await (const ref of this.filesGenerator()) {
|
|
3931
|
-
|
|
3932
|
-
files.push(ref);
|
|
3826
|
+
allFiles.push(ref);
|
|
3933
3827
|
}
|
|
3934
|
-
return
|
|
3828
|
+
return allFiles;
|
|
3935
3829
|
}
|
|
3936
3830
|
async mdFiles() {
|
|
3937
3831
|
const refs = [];
|
|
3938
3832
|
for await (const file of this.mdFilesGenerator()) {
|
|
3939
|
-
if (file instanceof Error) continue;
|
|
3940
3833
|
refs.push(file);
|
|
3941
3834
|
}
|
|
3942
3835
|
return refs;
|
|
@@ -3972,63 +3865,61 @@ var DocDirectoryReference = class _DocDirectoryReference {
|
|
|
3972
3865
|
async readFiles() {
|
|
3973
3866
|
const entities = [];
|
|
3974
3867
|
for await (const file of this.filesGenerator()) {
|
|
3975
|
-
|
|
3976
|
-
|
|
3977
|
-
|
|
3868
|
+
try {
|
|
3869
|
+
const entity = await file.read();
|
|
3870
|
+
entities.push(entity);
|
|
3871
|
+
} catch {
|
|
3872
|
+
continue;
|
|
3873
|
+
}
|
|
3978
3874
|
}
|
|
3979
3875
|
return entities;
|
|
3980
3876
|
}
|
|
3981
3877
|
async readMdFiles() {
|
|
3982
3878
|
const entities = [];
|
|
3983
3879
|
for await (const file of this.filesGenerator()) {
|
|
3984
|
-
|
|
3985
|
-
|
|
3986
|
-
|
|
3987
|
-
|
|
3880
|
+
try {
|
|
3881
|
+
const entity = await file.read();
|
|
3882
|
+
if (entity instanceof DocFileUnknownEntity) continue;
|
|
3883
|
+
entities.push(entity);
|
|
3884
|
+
} catch {
|
|
3885
|
+
continue;
|
|
3886
|
+
}
|
|
3988
3887
|
}
|
|
3989
3888
|
return entities;
|
|
3990
3889
|
}
|
|
3991
3890
|
async readUnknownFiles() {
|
|
3992
3891
|
const entities = [];
|
|
3993
3892
|
for await (const file of this.filesGenerator()) {
|
|
3994
|
-
|
|
3995
|
-
|
|
3996
|
-
|
|
3997
|
-
|
|
3893
|
+
try {
|
|
3894
|
+
const entity = await file.read();
|
|
3895
|
+
if (entity instanceof DocFileMdEntity) continue;
|
|
3896
|
+
entities.push(entity);
|
|
3897
|
+
} catch {
|
|
3898
|
+
continue;
|
|
3899
|
+
}
|
|
3998
3900
|
}
|
|
3999
3901
|
return entities;
|
|
4000
3902
|
}
|
|
4001
|
-
/**
|
|
4002
|
-
* Get list of subdirectory names
|
|
4003
|
-
*/
|
|
4004
3903
|
async directoryNames() {
|
|
4005
|
-
const allFileNames = await this.fileSystem.readDirectoryFileNames(
|
|
4006
|
-
this.relativePath
|
|
4007
|
-
);
|
|
3904
|
+
const allFileNames = await this.fileSystem.readDirectoryFileNames(this.relativePath);
|
|
4008
3905
|
if (allFileNames instanceof Error) {
|
|
4009
3906
|
return [];
|
|
4010
3907
|
}
|
|
4011
|
-
const
|
|
3908
|
+
const names = [];
|
|
4012
3909
|
for (const fileName of allFileNames) {
|
|
4013
|
-
if (fileName
|
|
3910
|
+
if (fileName === this.archiveDirectoryName) continue;
|
|
4014
3911
|
if (this.props.config.directoryExcludes.includes(fileName)) continue;
|
|
4015
3912
|
const filePath = this.pathSystem.join(this.relativePath, fileName);
|
|
4016
3913
|
const isDirectory = await this.fileSystem.isDirectory(filePath);
|
|
4017
3914
|
if (isDirectory) {
|
|
4018
|
-
|
|
3915
|
+
names.push(fileName);
|
|
4019
3916
|
}
|
|
4020
3917
|
}
|
|
4021
|
-
return
|
|
3918
|
+
return names;
|
|
4022
3919
|
}
|
|
4023
|
-
/**
|
|
4024
|
-
* Get subdirectory references
|
|
4025
|
-
*/
|
|
4026
3920
|
async directories() {
|
|
4027
|
-
const
|
|
4028
|
-
|
|
4029
|
-
return [];
|
|
4030
|
-
}
|
|
4031
|
-
return directoryNames.map((dirName) => {
|
|
3921
|
+
const names = await this.directoryNames();
|
|
3922
|
+
return names.map((dirName) => {
|
|
4032
3923
|
const dirPath = this.pathSystem.join(this.relativePath, dirName);
|
|
4033
3924
|
return new _DocDirectoryReference({
|
|
4034
3925
|
path: dirPath,
|
|
@@ -4077,10 +3968,7 @@ var DocDirectoryReference = class _DocDirectoryReference {
|
|
|
4077
3968
|
return this.indexFile().read();
|
|
4078
3969
|
}
|
|
4079
3970
|
async writeFile(entity) {
|
|
4080
|
-
const filePath = this.pathSystem.join(
|
|
4081
|
-
this.relativePath,
|
|
4082
|
-
entity.value.path.nameWithExtension
|
|
4083
|
-
);
|
|
3971
|
+
const filePath = this.pathSystem.join(this.relativePath, entity.value.path.nameWithExtension);
|
|
4084
3972
|
let content = null;
|
|
4085
3973
|
if (entity instanceof DocFileUnknownEntity) {
|
|
4086
3974
|
content = entity.value.content;
|
|
@@ -4092,20 +3980,16 @@ var DocDirectoryReference = class _DocDirectoryReference {
|
|
|
4092
3980
|
content = entity.content().toText();
|
|
4093
3981
|
}
|
|
4094
3982
|
if (content === null) {
|
|
4095
|
-
|
|
3983
|
+
throw new Error("Entity content is undefined");
|
|
4096
3984
|
}
|
|
4097
3985
|
const writeResult = await this.fileSystem.writeFile(filePath, content);
|
|
4098
3986
|
if (writeResult instanceof Error) {
|
|
4099
|
-
|
|
3987
|
+
throw writeResult;
|
|
4100
3988
|
}
|
|
4101
|
-
return null;
|
|
4102
3989
|
}
|
|
4103
3990
|
async exists() {
|
|
4104
3991
|
return await this.fileSystem.exists(this.relativePath);
|
|
4105
3992
|
}
|
|
4106
|
-
/**
|
|
4107
|
-
* Create new Markdown file
|
|
4108
|
-
*/
|
|
4109
3993
|
async createMdFile(fileName) {
|
|
4110
3994
|
const actualFileName = fileName || this.uniqueFileName("document");
|
|
4111
3995
|
const mdFileName = actualFileName.endsWith(".md") ? actualFileName : `${actualFileName}.md`;
|
|
@@ -4117,15 +4001,9 @@ var DocDirectoryReference = class _DocDirectoryReference {
|
|
|
4117
4001
|
pathSystem: this.pathSystem,
|
|
4118
4002
|
config: this.props.config
|
|
4119
4003
|
});
|
|
4120
|
-
|
|
4121
|
-
if (writeResult instanceof Error) {
|
|
4122
|
-
throw writeResult;
|
|
4123
|
-
}
|
|
4004
|
+
await fileRef.writeDefault();
|
|
4124
4005
|
return fileRef;
|
|
4125
4006
|
}
|
|
4126
|
-
/**
|
|
4127
|
-
* Generate unique filename
|
|
4128
|
-
*/
|
|
4129
4007
|
uniqueFileName(prefix = "document") {
|
|
4130
4008
|
const [uuid] = crypto.randomUUID().split("-");
|
|
4131
4009
|
return `${prefix}-${uuid}.md`;
|
|
@@ -4142,6 +4020,9 @@ var DocFileMdReference = class _DocFileMdReference {
|
|
|
4142
4020
|
}
|
|
4143
4021
|
pathSystem;
|
|
4144
4022
|
customSchema;
|
|
4023
|
+
get safe() {
|
|
4024
|
+
return createSafeProxy(this);
|
|
4025
|
+
}
|
|
4145
4026
|
get fileSystem() {
|
|
4146
4027
|
return this.props.fileSystem;
|
|
4147
4028
|
}
|
|
@@ -4178,21 +4059,18 @@ var DocFileMdReference = class _DocFileMdReference {
|
|
|
4178
4059
|
async read() {
|
|
4179
4060
|
const content = await this.fileSystem.readFile(this.path);
|
|
4180
4061
|
if (content instanceof Error) {
|
|
4181
|
-
|
|
4062
|
+
throw content;
|
|
4182
4063
|
}
|
|
4183
4064
|
const actualPath = this.path;
|
|
4184
4065
|
if (content === null) {
|
|
4185
4066
|
const archivedContent = await this.fileSystem.readFile(this.archivedPath);
|
|
4186
4067
|
if (archivedContent instanceof Error) {
|
|
4187
|
-
|
|
4068
|
+
throw archivedContent;
|
|
4188
4069
|
}
|
|
4189
4070
|
if (archivedContent !== null) {
|
|
4190
|
-
const contentValue2 = DocFileMdContentValue.fromMarkdown(
|
|
4191
|
-
archivedContent,
|
|
4192
|
-
this.customSchema
|
|
4193
|
-
);
|
|
4071
|
+
const contentValue2 = DocFileMdContentValue.fromMarkdown(archivedContent, this.customSchema);
|
|
4194
4072
|
const pathValue2 = DocFilePathValue.fromPathWithSystem(
|
|
4195
|
-
|
|
4073
|
+
this.archivedPath,
|
|
4196
4074
|
this.pathSystem,
|
|
4197
4075
|
this.basePath
|
|
4198
4076
|
);
|
|
@@ -4208,12 +4086,9 @@ var DocFileMdReference = class _DocFileMdReference {
|
|
|
4208
4086
|
}
|
|
4209
4087
|
}
|
|
4210
4088
|
if (content === null) {
|
|
4211
|
-
|
|
4089
|
+
throw new Error(`File not found at ${this.path} or in archive.`);
|
|
4212
4090
|
}
|
|
4213
|
-
const contentValue = DocFileMdContentValue.fromMarkdown(
|
|
4214
|
-
content,
|
|
4215
|
-
this.customSchema
|
|
4216
|
-
);
|
|
4091
|
+
const contentValue = DocFileMdContentValue.fromMarkdown(content, this.customSchema);
|
|
4217
4092
|
const pathValue = DocFilePathValue.fromPathWithSystem(
|
|
4218
4093
|
actualPath,
|
|
4219
4094
|
this.pathSystem,
|
|
@@ -4230,14 +4105,8 @@ var DocFileMdReference = class _DocFileMdReference {
|
|
|
4230
4105
|
this.customSchema
|
|
4231
4106
|
);
|
|
4232
4107
|
}
|
|
4233
|
-
/**
|
|
4234
|
-
* Read file content
|
|
4235
|
-
*/
|
|
4236
4108
|
async readText() {
|
|
4237
4109
|
const entity = await this.read();
|
|
4238
|
-
if (entity instanceof Error) {
|
|
4239
|
-
return entity;
|
|
4240
|
-
}
|
|
4241
4110
|
return entity.value.content.body;
|
|
4242
4111
|
}
|
|
4243
4112
|
/**
|
|
@@ -4245,11 +4114,7 @@ var DocFileMdReference = class _DocFileMdReference {
|
|
|
4245
4114
|
*/
|
|
4246
4115
|
empty() {
|
|
4247
4116
|
const contentValue = DocFileMdContentValue.empty("", this.customSchema);
|
|
4248
|
-
const pathValue = DocFilePathValue.fromPathWithSystem(
|
|
4249
|
-
this.path,
|
|
4250
|
-
this.pathSystem,
|
|
4251
|
-
this.basePath
|
|
4252
|
-
);
|
|
4117
|
+
const pathValue = DocFilePathValue.fromPathWithSystem(this.path, this.pathSystem, this.basePath);
|
|
4253
4118
|
return new DocFileMdEntity(
|
|
4254
4119
|
{
|
|
4255
4120
|
type: "markdown",
|
|
@@ -4260,65 +4125,50 @@ var DocFileMdReference = class _DocFileMdReference {
|
|
|
4260
4125
|
this.customSchema
|
|
4261
4126
|
);
|
|
4262
4127
|
}
|
|
4263
|
-
/**
|
|
4264
|
-
* Write entity
|
|
4265
|
-
*/
|
|
4266
4128
|
async write(entity) {
|
|
4267
4129
|
const content = entity.content().toText();
|
|
4268
4130
|
const writeResult = await this.fileSystem.writeFile(this.path, content);
|
|
4269
4131
|
if (writeResult instanceof Error) {
|
|
4270
|
-
|
|
4132
|
+
throw writeResult;
|
|
4271
4133
|
}
|
|
4272
|
-
return null;
|
|
4273
4134
|
}
|
|
4274
4135
|
async writeText(text) {
|
|
4275
|
-
|
|
4136
|
+
const writeResult = await this.fileSystem.writeFile(this.path, text);
|
|
4137
|
+
if (writeResult instanceof Error) {
|
|
4138
|
+
throw writeResult;
|
|
4139
|
+
}
|
|
4276
4140
|
}
|
|
4277
|
-
/**
|
|
4278
|
-
* Create new file with default content
|
|
4279
|
-
*/
|
|
4280
4141
|
async writeDefault() {
|
|
4281
4142
|
const fileName = this.pathSystem.basename(this.path, ".md");
|
|
4282
|
-
const defaultContent = [
|
|
4283
|
-
|
|
4284
|
-
|
|
4285
|
-
|
|
4286
|
-
|
|
4287
|
-
return await this.fileSystem.writeFile(this.path, defaultContent);
|
|
4143
|
+
const defaultContent = [`# ${fileName}`, "", "Write your content here."].join("\n");
|
|
4144
|
+
const writeResult = await this.fileSystem.writeFile(this.path, defaultContent);
|
|
4145
|
+
if (writeResult instanceof Error) {
|
|
4146
|
+
throw writeResult;
|
|
4147
|
+
}
|
|
4288
4148
|
}
|
|
4289
|
-
/**
|
|
4290
|
-
* Delete file
|
|
4291
|
-
*/
|
|
4292
4149
|
async delete() {
|
|
4293
|
-
|
|
4150
|
+
const deleteResult = await this.fileSystem.deleteFile(this.path);
|
|
4151
|
+
if (deleteResult instanceof Error) {
|
|
4152
|
+
throw deleteResult;
|
|
4153
|
+
}
|
|
4294
4154
|
}
|
|
4295
|
-
/**
|
|
4296
|
-
* Copy file
|
|
4297
|
-
*/
|
|
4298
4155
|
async copyTo(destinationPath) {
|
|
4299
|
-
|
|
4156
|
+
const copyResult = await this.fileSystem.copyFile(this.path, destinationPath);
|
|
4157
|
+
if (copyResult instanceof Error) {
|
|
4158
|
+
throw copyResult;
|
|
4159
|
+
}
|
|
4300
4160
|
}
|
|
4301
|
-
/**
|
|
4302
|
-
* Move file
|
|
4303
|
-
*/
|
|
4304
4161
|
async moveTo(destinationPath) {
|
|
4305
|
-
|
|
4162
|
+
const moveResult = await this.fileSystem.moveFile(this.path, destinationPath);
|
|
4163
|
+
if (moveResult instanceof Error) {
|
|
4164
|
+
throw moveResult;
|
|
4165
|
+
}
|
|
4306
4166
|
}
|
|
4307
|
-
/**
|
|
4308
|
-
* Move file to archive and return new reference
|
|
4309
|
-
*/
|
|
4310
4167
|
async archive(archiveDirectoryName = this.props.config.archiveDirectoryName) {
|
|
4311
4168
|
const dirPath = this.pathSystem.dirname(this.path);
|
|
4312
4169
|
const fileName = this.pathSystem.basename(this.path);
|
|
4313
|
-
const archivePath = this.pathSystem.join(
|
|
4314
|
-
|
|
4315
|
-
archiveDirectoryName,
|
|
4316
|
-
fileName
|
|
4317
|
-
);
|
|
4318
|
-
const moveResult = await this.moveTo(archivePath);
|
|
4319
|
-
if (moveResult instanceof Error) {
|
|
4320
|
-
throw moveResult;
|
|
4321
|
-
}
|
|
4170
|
+
const archivePath = this.pathSystem.join(dirPath, archiveDirectoryName, fileName);
|
|
4171
|
+
await this.moveTo(archivePath);
|
|
4322
4172
|
return new _DocFileMdReference({
|
|
4323
4173
|
path: archivePath,
|
|
4324
4174
|
fileSystem: this.fileSystem,
|
|
@@ -4327,9 +4177,6 @@ var DocFileMdReference = class _DocFileMdReference {
|
|
|
4327
4177
|
config: this.props.config
|
|
4328
4178
|
});
|
|
4329
4179
|
}
|
|
4330
|
-
/**
|
|
4331
|
-
* Restore file from archive and return new reference
|
|
4332
|
-
*/
|
|
4333
4180
|
async restore(archiveDirectoryName = this.props.config.archiveDirectoryName) {
|
|
4334
4181
|
const dirPath = this.pathSystem.dirname(this.path);
|
|
4335
4182
|
const parentDirName = this.pathSystem.basename(dirPath);
|
|
@@ -4337,14 +4184,8 @@ var DocFileMdReference = class _DocFileMdReference {
|
|
|
4337
4184
|
throw new Error(`File is not in archive directory: ${this.path}`);
|
|
4338
4185
|
}
|
|
4339
4186
|
const fileName = this.pathSystem.basename(this.path);
|
|
4340
|
-
const restorePath = this.pathSystem.join(
|
|
4341
|
-
|
|
4342
|
-
fileName
|
|
4343
|
-
);
|
|
4344
|
-
const moveResult = await this.moveTo(restorePath);
|
|
4345
|
-
if (moveResult instanceof Error) {
|
|
4346
|
-
throw moveResult;
|
|
4347
|
-
}
|
|
4187
|
+
const restorePath = this.pathSystem.join(this.pathSystem.dirname(dirPath), fileName);
|
|
4188
|
+
await this.moveTo(restorePath);
|
|
4348
4189
|
return new _DocFileMdReference({
|
|
4349
4190
|
path: restorePath,
|
|
4350
4191
|
fileSystem: this.fileSystem,
|
|
@@ -4353,23 +4194,26 @@ var DocFileMdReference = class _DocFileMdReference {
|
|
|
4353
4194
|
config: this.props.config
|
|
4354
4195
|
});
|
|
4355
4196
|
}
|
|
4356
|
-
/**
|
|
4357
|
-
* Get file size in bytes
|
|
4358
|
-
*/
|
|
4359
4197
|
async size() {
|
|
4360
|
-
|
|
4198
|
+
const fileSize = await this.fileSystem.getFileSize(this.path);
|
|
4199
|
+
if (fileSize instanceof Error) {
|
|
4200
|
+
throw fileSize;
|
|
4201
|
+
}
|
|
4202
|
+
return fileSize;
|
|
4361
4203
|
}
|
|
4362
|
-
/**
|
|
4363
|
-
* Get file last modified time
|
|
4364
|
-
*/
|
|
4365
4204
|
async lastModified() {
|
|
4366
|
-
|
|
4205
|
+
const updatedTime = await this.fileSystem.getFileUpdatedTime(this.path);
|
|
4206
|
+
if (updatedTime instanceof Error) {
|
|
4207
|
+
throw updatedTime;
|
|
4208
|
+
}
|
|
4209
|
+
return updatedTime;
|
|
4367
4210
|
}
|
|
4368
|
-
/**
|
|
4369
|
-
* Get file creation time
|
|
4370
|
-
*/
|
|
4371
4211
|
async createdAt() {
|
|
4372
|
-
|
|
4212
|
+
const createdTime = await this.fileSystem.getFileCreatedTime(this.path);
|
|
4213
|
+
if (createdTime instanceof Error) {
|
|
4214
|
+
throw createdTime;
|
|
4215
|
+
}
|
|
4216
|
+
return createdTime;
|
|
4373
4217
|
}
|
|
4374
4218
|
directory() {
|
|
4375
4219
|
const paths = this.directoryPath.split(this.pathSystem.separator);
|
|
@@ -4395,15 +4239,9 @@ var DocFileMdReference = class _DocFileMdReference {
|
|
|
4395
4239
|
config: this.props.config
|
|
4396
4240
|
});
|
|
4397
4241
|
}
|
|
4398
|
-
/**
|
|
4399
|
-
* Get relation based on schema
|
|
4400
|
-
*/
|
|
4401
4242
|
async relation(key, targetSchema) {
|
|
4402
4243
|
const file = await this.read();
|
|
4403
|
-
|
|
4404
|
-
return file;
|
|
4405
|
-
}
|
|
4406
|
-
const relationValue = file.content().meta().field(key);
|
|
4244
|
+
const relationValue = file.content().meta().relation(key);
|
|
4407
4245
|
if (relationValue === null) {
|
|
4408
4246
|
return null;
|
|
4409
4247
|
}
|
|
@@ -4412,40 +4250,37 @@ var DocFileMdReference = class _DocFileMdReference {
|
|
|
4412
4250
|
return null;
|
|
4413
4251
|
}
|
|
4414
4252
|
const indexFile = await indexRef.read();
|
|
4415
|
-
if (indexFile instanceof Error) {
|
|
4416
|
-
return null;
|
|
4417
|
-
}
|
|
4418
4253
|
const schemaValue = indexFile.content.meta().schema();
|
|
4419
|
-
const fieldValue = schemaValue.value[key];
|
|
4254
|
+
const fieldValue = schemaValue.value[String(key)];
|
|
4420
4255
|
if (!fieldValue || fieldValue.type !== "relation") {
|
|
4421
4256
|
return null;
|
|
4422
4257
|
}
|
|
4423
|
-
const
|
|
4424
|
-
|
|
4425
|
-
);
|
|
4426
|
-
const relationField = schemaField;
|
|
4427
|
-
let resolvedPath = relationField.path;
|
|
4428
|
-
if (relationField.path.startsWith("..")) {
|
|
4429
|
-
resolvedPath = this.pathSystem.join(
|
|
4430
|
-
this.directoryPath,
|
|
4431
|
-
relationField.path
|
|
4432
|
-
);
|
|
4433
|
-
resolvedPath = this.pathSystem.normalize(resolvedPath);
|
|
4434
|
-
}
|
|
4258
|
+
const relationField = schemaValue.relation(key);
|
|
4259
|
+
const resolvedPath = this.resolveRelationDirectory(relationField.path);
|
|
4435
4260
|
const fullPath = this.pathSystem.join(resolvedPath, `${relationValue}.md`);
|
|
4436
4261
|
return new _DocFileMdReference({
|
|
4437
4262
|
path: fullPath,
|
|
4438
4263
|
fileSystem: this.fileSystem,
|
|
4439
4264
|
pathSystem: this.pathSystem,
|
|
4440
|
-
customSchema: targetSchema
|
|
4265
|
+
customSchema: targetSchema ?? {},
|
|
4441
4266
|
config: this.props.config
|
|
4442
4267
|
});
|
|
4443
4268
|
}
|
|
4444
4269
|
/**
|
|
4445
|
-
*
|
|
4270
|
+
* スキーマで定義された relation の path を解決する。
|
|
4271
|
+
* ".." 始まりの相対パスはファイルのディレクトリ基準で正規化する
|
|
4446
4272
|
*/
|
|
4273
|
+
resolveRelationDirectory(schemaPath) {
|
|
4274
|
+
if (schemaPath.startsWith("..")) {
|
|
4275
|
+
return this.pathSystem.normalize(this.pathSystem.join(this.directoryPath, schemaPath));
|
|
4276
|
+
}
|
|
4277
|
+
return schemaPath;
|
|
4278
|
+
}
|
|
4447
4279
|
async directoryIndex() {
|
|
4448
|
-
const
|
|
4280
|
+
const indexFileName = this.props.config.indexFileName;
|
|
4281
|
+
const archiveDirectoryName = this.props.config.archiveDirectoryName;
|
|
4282
|
+
const metaFileName = this.props.config.metaFileName ?? META_FILE_NAME;
|
|
4283
|
+
const indexPath = this.pathSystem.join(this.directoryPath, indexFileName);
|
|
4449
4284
|
const exists = await this.fileSystem.exists(indexPath);
|
|
4450
4285
|
if (exists) {
|
|
4451
4286
|
return new DocFileIndexReference({
|
|
@@ -4456,10 +4291,21 @@ var DocFileMdReference = class _DocFileMdReference {
|
|
|
4456
4291
|
config: this.props.config
|
|
4457
4292
|
});
|
|
4458
4293
|
}
|
|
4294
|
+
const metaPath = this.pathSystem.join(this.directoryPath, metaFileName);
|
|
4295
|
+
const metaExists = await this.fileSystem.exists(metaPath);
|
|
4296
|
+
if (metaExists) {
|
|
4297
|
+
return new DocFileIndexReference({
|
|
4298
|
+
path: indexPath,
|
|
4299
|
+
fileSystem: this.fileSystem,
|
|
4300
|
+
pathSystem: this.pathSystem,
|
|
4301
|
+
customSchema: this.customSchema,
|
|
4302
|
+
config: this.props.config
|
|
4303
|
+
});
|
|
4304
|
+
}
|
|
4459
4305
|
const archivedIndexPath = this.pathSystem.join(
|
|
4460
4306
|
this.directoryPath,
|
|
4461
|
-
|
|
4462
|
-
|
|
4307
|
+
archiveDirectoryName,
|
|
4308
|
+
indexFileName
|
|
4463
4309
|
);
|
|
4464
4310
|
const archivedExists = await this.fileSystem.exists(archivedIndexPath);
|
|
4465
4311
|
if (archivedExists) {
|
|
@@ -4473,20 +4319,9 @@ var DocFileMdReference = class _DocFileMdReference {
|
|
|
4473
4319
|
}
|
|
4474
4320
|
return null;
|
|
4475
4321
|
}
|
|
4476
|
-
/**
|
|
4477
|
-
* Get multiple relations based on schema
|
|
4478
|
-
*/
|
|
4479
4322
|
async relations(key, customSchema) {
|
|
4480
4323
|
const file = await this.read();
|
|
4481
|
-
|
|
4482
|
-
return [];
|
|
4483
|
-
}
|
|
4484
|
-
const meta = file.content().meta();
|
|
4485
|
-
const schemaField = meta.schemaField(key);
|
|
4486
|
-
if (schemaField.type !== "multi-relation") {
|
|
4487
|
-
return [];
|
|
4488
|
-
}
|
|
4489
|
-
const fileNames = meta.multiRelation(key);
|
|
4324
|
+
const fileNames = file.content().meta().multiRelation(key);
|
|
4490
4325
|
if (fileNames === null) {
|
|
4491
4326
|
return [];
|
|
4492
4327
|
}
|
|
@@ -4495,41 +4330,30 @@ var DocFileMdReference = class _DocFileMdReference {
|
|
|
4495
4330
|
return [];
|
|
4496
4331
|
}
|
|
4497
4332
|
const indexFile = await indexRef.read();
|
|
4498
|
-
|
|
4333
|
+
const indexSchema = indexFile.content.meta().schema();
|
|
4334
|
+
const fieldValue = indexSchema.value[String(key)];
|
|
4335
|
+
if (!fieldValue || fieldValue.type !== "multi-relation") {
|
|
4499
4336
|
return [];
|
|
4500
4337
|
}
|
|
4501
|
-
const indexSchema = indexFile.content.meta().schema();
|
|
4502
4338
|
const indexSchemaField = indexSchema.multiRelation(key);
|
|
4339
|
+
const resolvedPath = this.resolveRelationDirectory(indexSchemaField.path);
|
|
4503
4340
|
return fileNames.map((fileName) => {
|
|
4504
|
-
const resolvedPath = indexSchemaField.path;
|
|
4505
4341
|
const fullPath = this.pathSystem.join(resolvedPath, `${fileName}.md`);
|
|
4506
4342
|
return new _DocFileMdReference({
|
|
4507
4343
|
path: fullPath,
|
|
4508
4344
|
fileSystem: this.fileSystem,
|
|
4509
4345
|
pathSystem: this.pathSystem,
|
|
4510
|
-
customSchema: customSchema
|
|
4346
|
+
customSchema: customSchema ?? {},
|
|
4511
4347
|
config: this.props.config
|
|
4512
4348
|
});
|
|
4513
4349
|
});
|
|
4514
4350
|
}
|
|
4515
|
-
/**
|
|
4516
|
-
* File: Markdown > FrontMatter
|
|
4517
|
-
*/
|
|
4518
4351
|
async readFrontMatter() {
|
|
4519
4352
|
const entity = await this.read();
|
|
4520
|
-
if (entity instanceof Error) {
|
|
4521
|
-
return entity;
|
|
4522
|
-
}
|
|
4523
4353
|
return entity.content().meta();
|
|
4524
4354
|
}
|
|
4525
|
-
/**
|
|
4526
|
-
* File: Markdown > FrontMatter
|
|
4527
|
-
*/
|
|
4528
4355
|
async updateFrontMatter(key, value) {
|
|
4529
4356
|
const entity = await this.read();
|
|
4530
|
-
if (entity instanceof Error) {
|
|
4531
|
-
return entity;
|
|
4532
|
-
}
|
|
4533
4357
|
const frontMatter = entity.content().meta();
|
|
4534
4358
|
const draftFrontMatter = frontMatter.withProperty(key, value);
|
|
4535
4359
|
const draftContent = entity.content().withMeta(draftFrontMatter);
|
|
@@ -4678,6 +4502,8 @@ var DocFileTreeSystem = class {
|
|
|
4678
4502
|
for (const fileName of fileNames) {
|
|
4679
4503
|
if (fileName === this.props.archiveDirectoryName) continue;
|
|
4680
4504
|
if (this.config.directoryExcludes.includes(fileName)) continue;
|
|
4505
|
+
const metaFileName = this.config.metaFileName ?? ".meta.json";
|
|
4506
|
+
if (fileName === metaFileName) continue;
|
|
4681
4507
|
const filePath = directoryPath ? this.props.pathSystem.join(directoryPath, fileName) : fileName;
|
|
4682
4508
|
const isDirectory = await this.props.fileSystem.isDirectory(filePath);
|
|
4683
4509
|
if (!isDirectory) {
|
|
@@ -4688,7 +4514,7 @@ var DocFileTreeSystem = class {
|
|
|
4688
4514
|
results.push(fileNode);
|
|
4689
4515
|
continue;
|
|
4690
4516
|
}
|
|
4691
|
-
const directoryNode = await this.createDirectoryNode(fileName, filePath);
|
|
4517
|
+
const directoryNode = await this.createDirectoryNode(fileName, filePath, false);
|
|
4692
4518
|
if (directoryNode instanceof Error) {
|
|
4693
4519
|
return directoryNode;
|
|
4694
4520
|
}
|
|
@@ -4700,58 +4526,70 @@ var DocFileTreeSystem = class {
|
|
|
4700
4526
|
* Create file node
|
|
4701
4527
|
*/
|
|
4702
4528
|
async createFileNode(fileName, filePath) {
|
|
4703
|
-
|
|
4704
|
-
let icon = "";
|
|
4705
|
-
if (fileName.endsWith(".md")) {
|
|
4706
|
-
const mdFile = this.createMdFileReference(filePath);
|
|
4707
|
-
if (await mdFile.exists()) {
|
|
4708
|
-
const entity = await mdFile.read();
|
|
4709
|
-
if (!(entity instanceof Error)) {
|
|
4710
|
-
title = entity.value.content.title || fileName;
|
|
4711
|
-
}
|
|
4712
|
-
}
|
|
4713
|
-
icon = "\u{1F4C4}";
|
|
4714
|
-
} else {
|
|
4715
|
-
icon = "\u{1F4C4}";
|
|
4716
|
-
}
|
|
4529
|
+
const title = await this.readFileTitle(fileName, filePath);
|
|
4717
4530
|
return DocTreeFileNodeValue.from({
|
|
4718
4531
|
name: fileName,
|
|
4719
4532
|
path: filePath,
|
|
4720
|
-
icon,
|
|
4533
|
+
icon: "\u{1F4C4}",
|
|
4721
4534
|
title
|
|
4722
4535
|
});
|
|
4723
4536
|
}
|
|
4537
|
+
/**
|
|
4538
|
+
* Read title from a file
|
|
4539
|
+
*/
|
|
4540
|
+
async readFileTitle(fileName, filePath) {
|
|
4541
|
+
if (!fileName.endsWith(".md")) {
|
|
4542
|
+
return fileName;
|
|
4543
|
+
}
|
|
4544
|
+
const mdFile = this.createMdFileReference(filePath);
|
|
4545
|
+
if (!await mdFile.exists()) {
|
|
4546
|
+
return fileName;
|
|
4547
|
+
}
|
|
4548
|
+
try {
|
|
4549
|
+
const entity = await mdFile.read();
|
|
4550
|
+
return entity.value.content.title || fileName;
|
|
4551
|
+
} catch {
|
|
4552
|
+
return fileName;
|
|
4553
|
+
}
|
|
4554
|
+
}
|
|
4724
4555
|
/**
|
|
4725
4556
|
* Create directory node
|
|
4726
4557
|
*/
|
|
4727
|
-
async createDirectoryNode(fileName, filePath) {
|
|
4728
|
-
|
|
4729
|
-
|
|
4730
|
-
|
|
4731
|
-
if (await indexFile.exists()) {
|
|
4732
|
-
const entity = await indexFile.read();
|
|
4733
|
-
if (entity instanceof Error) {
|
|
4734
|
-
return entity;
|
|
4735
|
-
}
|
|
4736
|
-
title = entity.value.content.title || fileName;
|
|
4737
|
-
const content = entity.content;
|
|
4738
|
-
const frontMatter = content.meta();
|
|
4739
|
-
if (frontMatter) {
|
|
4740
|
-
icon = frontMatter.icon || this.config.defaultIndexIcon;
|
|
4741
|
-
}
|
|
4558
|
+
async createDirectoryNode(fileName, filePath, directoryOnly) {
|
|
4559
|
+
const indexInfo = await this.readDirectoryIndexInfo(fileName, filePath);
|
|
4560
|
+
if (indexInfo instanceof Error) {
|
|
4561
|
+
return indexInfo;
|
|
4742
4562
|
}
|
|
4743
|
-
const children = await this.buildFileTree(filePath);
|
|
4563
|
+
const children = directoryOnly ? await this.buildDirectoryTree(filePath) : await this.buildFileTree(filePath);
|
|
4744
4564
|
if (children instanceof Error) {
|
|
4745
4565
|
return children;
|
|
4746
4566
|
}
|
|
4747
4567
|
return DocTreeDirectoryNodeValue.from({
|
|
4748
4568
|
name: fileName,
|
|
4749
4569
|
path: filePath,
|
|
4750
|
-
icon,
|
|
4751
|
-
title,
|
|
4570
|
+
icon: indexInfo.icon,
|
|
4571
|
+
title: indexInfo.title,
|
|
4752
4572
|
children
|
|
4753
4573
|
});
|
|
4754
4574
|
}
|
|
4575
|
+
/**
|
|
4576
|
+
* Read title and icon from directory index file
|
|
4577
|
+
*/
|
|
4578
|
+
async readDirectoryIndexInfo(fileName, filePath) {
|
|
4579
|
+
const indexFile = this.createIndexFileReference(filePath);
|
|
4580
|
+
if (!await indexFile.exists()) {
|
|
4581
|
+
return { title: fileName, icon: this.config.defaultIndexIcon };
|
|
4582
|
+
}
|
|
4583
|
+
try {
|
|
4584
|
+
const entity = await indexFile.read();
|
|
4585
|
+
const title = entity.value.content.title || fileName;
|
|
4586
|
+
const frontMatter = entity.content.meta();
|
|
4587
|
+
const icon = frontMatter?.icon || this.config.defaultIndexIcon;
|
|
4588
|
+
return { title, icon };
|
|
4589
|
+
} catch (error) {
|
|
4590
|
+
return error instanceof Error ? error : new Error(String(error));
|
|
4591
|
+
}
|
|
4592
|
+
}
|
|
4755
4593
|
/**
|
|
4756
4594
|
* Create index file reference
|
|
4757
4595
|
*/
|
|
@@ -4789,13 +4627,12 @@ var DocFileTreeSystem = class {
|
|
|
4789
4627
|
for (const fileName of fileNames) {
|
|
4790
4628
|
if (fileName === this.props.archiveDirectoryName) continue;
|
|
4791
4629
|
if (this.config.directoryExcludes.includes(fileName)) continue;
|
|
4630
|
+
const metaFileName = this.config.metaFileName ?? ".meta.json";
|
|
4631
|
+
if (fileName === metaFileName) continue;
|
|
4792
4632
|
const filePath = directoryPath ? this.props.pathSystem.join(directoryPath, fileName) : fileName;
|
|
4793
4633
|
const isDirectory = await this.props.fileSystem.isDirectory(filePath);
|
|
4794
4634
|
if (!isDirectory) continue;
|
|
4795
|
-
const directoryNode = await this.
|
|
4796
|
-
fileName,
|
|
4797
|
-
filePath
|
|
4798
|
-
);
|
|
4635
|
+
const directoryNode = await this.createDirectoryNode(fileName, filePath, true);
|
|
4799
4636
|
if (directoryNode instanceof Error) {
|
|
4800
4637
|
return directoryNode;
|
|
4801
4638
|
}
|
|
@@ -4803,42 +4640,16 @@ var DocFileTreeSystem = class {
|
|
|
4803
4640
|
}
|
|
4804
4641
|
return results;
|
|
4805
4642
|
}
|
|
4806
|
-
/**
|
|
4807
|
-
* Create directory node for directory tree
|
|
4808
|
-
*/
|
|
4809
|
-
async createDirectoryNodeForTree(fileName, filePath) {
|
|
4810
|
-
let title = fileName;
|
|
4811
|
-
let icon = this.config.defaultIndexIcon;
|
|
4812
|
-
const indexFile = this.createIndexFileReference(filePath);
|
|
4813
|
-
if (await indexFile.exists()) {
|
|
4814
|
-
const entity = await indexFile.read();
|
|
4815
|
-
if (entity instanceof Error) {
|
|
4816
|
-
return entity;
|
|
4817
|
-
}
|
|
4818
|
-
title = entity.value.content.title || fileName;
|
|
4819
|
-
const content = entity.content;
|
|
4820
|
-
const frontMatter = content.meta();
|
|
4821
|
-
if (frontMatter && typeof frontMatter === "object" && "icon" in frontMatter) {
|
|
4822
|
-
icon = frontMatter.icon || this.config.defaultIndexIcon;
|
|
4823
|
-
}
|
|
4824
|
-
}
|
|
4825
|
-
const children = await this.buildDirectoryTree(filePath);
|
|
4826
|
-
if (children instanceof Error) {
|
|
4827
|
-
return children;
|
|
4828
|
-
}
|
|
4829
|
-
return DocTreeDirectoryNodeValue.from({
|
|
4830
|
-
name: fileName,
|
|
4831
|
-
path: filePath,
|
|
4832
|
-
icon,
|
|
4833
|
-
title,
|
|
4834
|
-
children
|
|
4835
|
-
});
|
|
4836
|
-
}
|
|
4837
4643
|
};
|
|
4838
4644
|
|
|
4839
4645
|
// lib/modules/path-system/doc-path-system.ts
|
|
4840
|
-
var DocPathSystem = class {
|
|
4646
|
+
var DocPathSystem = class _DocPathSystem {
|
|
4841
4647
|
separator = "/";
|
|
4648
|
+
constructor() {
|
|
4649
|
+
if (new.target === _DocPathSystem) {
|
|
4650
|
+
Object.freeze(this);
|
|
4651
|
+
}
|
|
4652
|
+
}
|
|
4842
4653
|
/**
|
|
4843
4654
|
* Join paths
|
|
4844
4655
|
*/
|
|
@@ -4894,8 +4705,8 @@ var DocPathSystem = class {
|
|
|
4894
4705
|
* Calculate relative path
|
|
4895
4706
|
*/
|
|
4896
4707
|
relative(from, to) {
|
|
4897
|
-
const fromSegments = from.split(this.separator).filter(
|
|
4898
|
-
const toSegments = to.split(this.separator).filter(
|
|
4708
|
+
const fromSegments = from.split(this.separator).filter((s) => s !== "" && s !== ".");
|
|
4709
|
+
const toSegments = to.split(this.separator).filter((s) => s !== "" && s !== ".");
|
|
4899
4710
|
let commonLength = 0;
|
|
4900
4711
|
for (let i = 0; i < Math.min(fromSegments.length, toSegments.length); i++) {
|
|
4901
4712
|
if (fromSegments[i] === toSegments[i]) {
|
|
@@ -4973,9 +4784,10 @@ var DocClient = class {
|
|
|
4973
4784
|
archiveDirectoryName: "_",
|
|
4974
4785
|
defaultDirectoryName: "Directory",
|
|
4975
4786
|
indexMetaIncludes: [],
|
|
4976
|
-
directoryExcludes: [".vitepress"]
|
|
4787
|
+
directoryExcludes: [".vitepress"],
|
|
4788
|
+
metaFileName: ".meta.json"
|
|
4977
4789
|
};
|
|
4978
|
-
this.config =
|
|
4790
|
+
this.config = zDocClientConfig.parse({ ...defaultConfig, ...props.config });
|
|
4979
4791
|
const fileTreeSystem = new DocFileTreeSystem({
|
|
4980
4792
|
fileSystem: this.fileSystem,
|
|
4981
4793
|
pathSystem: this.pathSystem,
|
|
@@ -4984,17 +4796,21 @@ var DocClient = class {
|
|
|
4984
4796
|
config: this.config
|
|
4985
4797
|
});
|
|
4986
4798
|
this.fileTreeSystem = props.fileTreeSystem ?? fileTreeSystem;
|
|
4799
|
+
Object.freeze(this);
|
|
4800
|
+
}
|
|
4801
|
+
get safe() {
|
|
4802
|
+
return createSafeProxy(this);
|
|
4987
4803
|
}
|
|
4988
4804
|
basePath() {
|
|
4989
4805
|
return this.fileSystem.getBasePath();
|
|
4990
4806
|
}
|
|
4991
|
-
/**
|
|
4992
|
-
* Get file reference
|
|
4993
|
-
*/
|
|
4994
4807
|
file(relativePath, customSchema) {
|
|
4995
4808
|
const fileName = this.pathSystem.basename(relativePath);
|
|
4996
4809
|
if (fileName === this.config.indexFileName) {
|
|
4997
4810
|
const dirPath = this.pathSystem.dirname(relativePath);
|
|
4811
|
+
if (customSchema === void 0) {
|
|
4812
|
+
return this.indexFile(dirPath === "." ? "" : dirPath);
|
|
4813
|
+
}
|
|
4998
4814
|
return this.indexFile(dirPath === "." ? "" : dirPath, customSchema);
|
|
4999
4815
|
}
|
|
5000
4816
|
if (relativePath.endsWith(".md")) {
|
|
@@ -5011,9 +4827,6 @@ var DocClient = class {
|
|
|
5011
4827
|
customSchema: {}
|
|
5012
4828
|
});
|
|
5013
4829
|
}
|
|
5014
|
-
/**
|
|
5015
|
-
* Markdown file reference
|
|
5016
|
-
*/
|
|
5017
4830
|
mdFile(relativePath, customSchema) {
|
|
5018
4831
|
const normalizedPath = relativePath.endsWith(".md") ? relativePath : `${relativePath}.md`;
|
|
5019
4832
|
if (customSchema === void 0) {
|
|
@@ -5033,9 +4846,6 @@ var DocClient = class {
|
|
|
5033
4846
|
config: this.config
|
|
5034
4847
|
});
|
|
5035
4848
|
}
|
|
5036
|
-
/**
|
|
5037
|
-
* Index file reference
|
|
5038
|
-
*/
|
|
5039
4849
|
indexFile(relativePath, customSchema) {
|
|
5040
4850
|
const indexPath = relativePath === "" ? this.config.indexFileName : `${relativePath}/${this.config.indexFileName}`;
|
|
5041
4851
|
if (customSchema === void 0) {
|
|
@@ -5055,9 +4865,6 @@ var DocClient = class {
|
|
|
5055
4865
|
config: this.config
|
|
5056
4866
|
});
|
|
5057
4867
|
}
|
|
5058
|
-
/**
|
|
5059
|
-
* Directory reference
|
|
5060
|
-
*/
|
|
5061
4868
|
directory(relativePath, customSchema) {
|
|
5062
4869
|
if (customSchema === void 0) {
|
|
5063
4870
|
return new DocDirectoryReference({
|
|
@@ -5081,18 +4888,18 @@ var DocClient = class {
|
|
|
5081
4888
|
});
|
|
5082
4889
|
}
|
|
5083
4890
|
async fileTree(directoryPath = "") {
|
|
5084
|
-
const
|
|
5085
|
-
if (
|
|
5086
|
-
throw
|
|
4891
|
+
const treeNodes = await this.fileTreeSystem.buildFileTree(directoryPath);
|
|
4892
|
+
if (treeNodes instanceof Error) {
|
|
4893
|
+
throw treeNodes;
|
|
5087
4894
|
}
|
|
5088
|
-
return
|
|
4895
|
+
return treeNodes.map((node) => node.toJson());
|
|
5089
4896
|
}
|
|
5090
4897
|
async directoryTree(directoryPath = "") {
|
|
5091
|
-
const
|
|
5092
|
-
if (
|
|
5093
|
-
throw
|
|
4898
|
+
const treeNodes = await this.fileTreeSystem.buildDirectoryTree(directoryPath);
|
|
4899
|
+
if (treeNodes instanceof Error) {
|
|
4900
|
+
throw treeNodes;
|
|
5094
4901
|
}
|
|
5095
|
-
return
|
|
4902
|
+
return treeNodes.map((node) => node.toJson());
|
|
5096
4903
|
}
|
|
5097
4904
|
};
|
|
5098
4905
|
|
|
@@ -5303,7 +5110,7 @@ var DocCustomSchemaFieldValue = class {
|
|
|
5303
5110
|
return zDocMetaFieldText.parse(value);
|
|
5304
5111
|
} catch {
|
|
5305
5112
|
if (this.value.required) {
|
|
5306
|
-
|
|
5113
|
+
throw new Error(`required field "${this.fieldType()}" is missing or invalid`);
|
|
5307
5114
|
}
|
|
5308
5115
|
return null;
|
|
5309
5116
|
}
|
|
@@ -5313,7 +5120,7 @@ var DocCustomSchemaFieldValue = class {
|
|
|
5313
5120
|
return zDocMetaFieldNumber.parse(value);
|
|
5314
5121
|
} catch {
|
|
5315
5122
|
if (this.value.required) {
|
|
5316
|
-
|
|
5123
|
+
throw new Error(`required field "${this.fieldType()}" is missing or invalid`);
|
|
5317
5124
|
}
|
|
5318
5125
|
return null;
|
|
5319
5126
|
}
|
|
@@ -5323,7 +5130,7 @@ var DocCustomSchemaFieldValue = class {
|
|
|
5323
5130
|
return zDocMetaFieldBoolean.parse(value);
|
|
5324
5131
|
} catch {
|
|
5325
5132
|
if (this.value.required) {
|
|
5326
|
-
|
|
5133
|
+
throw new Error(`required field "${this.fieldType()}" is missing or invalid`);
|
|
5327
5134
|
}
|
|
5328
5135
|
return null;
|
|
5329
5136
|
}
|
|
@@ -5333,7 +5140,7 @@ var DocCustomSchemaFieldValue = class {
|
|
|
5333
5140
|
return zDocMetaFieldSelectText.parse(value);
|
|
5334
5141
|
} catch {
|
|
5335
5142
|
if (this.value.required) {
|
|
5336
|
-
|
|
5143
|
+
throw new Error(`required field "${this.fieldType()}" is missing or invalid`);
|
|
5337
5144
|
}
|
|
5338
5145
|
return null;
|
|
5339
5146
|
}
|
|
@@ -5343,7 +5150,7 @@ var DocCustomSchemaFieldValue = class {
|
|
|
5343
5150
|
return zDocMetaFieldSelectNumber.parse(value);
|
|
5344
5151
|
} catch {
|
|
5345
5152
|
if (this.value.required) {
|
|
5346
|
-
|
|
5153
|
+
throw new Error(`required field "${this.fieldType()}" is missing or invalid`);
|
|
5347
5154
|
}
|
|
5348
5155
|
return null;
|
|
5349
5156
|
}
|
|
@@ -5353,7 +5160,7 @@ var DocCustomSchemaFieldValue = class {
|
|
|
5353
5160
|
return zDocMetaFieldRelation.parse(value);
|
|
5354
5161
|
} catch {
|
|
5355
5162
|
if (this.value.required) {
|
|
5356
|
-
|
|
5163
|
+
throw new Error(`required field "${this.fieldType()}" is missing or invalid`);
|
|
5357
5164
|
}
|
|
5358
5165
|
return null;
|
|
5359
5166
|
}
|
|
@@ -5363,7 +5170,7 @@ var DocCustomSchemaFieldValue = class {
|
|
|
5363
5170
|
return zDocMetaFieldMultiText.parse(value);
|
|
5364
5171
|
} catch {
|
|
5365
5172
|
if (this.value.required) {
|
|
5366
|
-
|
|
5173
|
+
throw new Error(`required field "${this.fieldType()}" is missing or invalid`);
|
|
5367
5174
|
}
|
|
5368
5175
|
return null;
|
|
5369
5176
|
}
|
|
@@ -5373,7 +5180,7 @@ var DocCustomSchemaFieldValue = class {
|
|
|
5373
5180
|
return zDocMetaFieldMultiNumber.parse(value);
|
|
5374
5181
|
} catch {
|
|
5375
5182
|
if (this.value.required) {
|
|
5376
|
-
|
|
5183
|
+
throw new Error(`required field "${this.fieldType()}" is missing or invalid`);
|
|
5377
5184
|
}
|
|
5378
5185
|
return null;
|
|
5379
5186
|
}
|
|
@@ -5383,7 +5190,7 @@ var DocCustomSchemaFieldValue = class {
|
|
|
5383
5190
|
return zDocMetaFieldMultiSelectText.parse(value);
|
|
5384
5191
|
} catch {
|
|
5385
5192
|
if (this.value.required) {
|
|
5386
|
-
|
|
5193
|
+
throw new Error(`required field "${this.fieldType()}" is missing or invalid`);
|
|
5387
5194
|
}
|
|
5388
5195
|
return null;
|
|
5389
5196
|
}
|
|
@@ -5393,7 +5200,7 @@ var DocCustomSchemaFieldValue = class {
|
|
|
5393
5200
|
return zDocMetaFieldMultiSelectNumber.parse(value);
|
|
5394
5201
|
} catch {
|
|
5395
5202
|
if (this.value.required) {
|
|
5396
|
-
|
|
5203
|
+
throw new Error(`required field "${this.fieldType()}" is missing or invalid`);
|
|
5397
5204
|
}
|
|
5398
5205
|
return null;
|
|
5399
5206
|
}
|
|
@@ -5403,13 +5210,16 @@ var DocCustomSchemaFieldValue = class {
|
|
|
5403
5210
|
return zDocMetaFieldMultiRelation.parse(value);
|
|
5404
5211
|
} catch {
|
|
5405
5212
|
if (this.value.required) {
|
|
5406
|
-
|
|
5213
|
+
throw new Error(`required field "${this.fieldType()}" is missing or invalid`);
|
|
5407
5214
|
}
|
|
5408
5215
|
return null;
|
|
5409
5216
|
}
|
|
5410
5217
|
}
|
|
5411
5218
|
throw new Error("Unknown field type");
|
|
5412
5219
|
}
|
|
5220
|
+
fieldType() {
|
|
5221
|
+
return this.value.type;
|
|
5222
|
+
}
|
|
5413
5223
|
};
|
|
5414
5224
|
|
|
5415
5225
|
// lib/values/doc-directory-path-value.ts
|
|
@@ -5417,6 +5227,7 @@ var DocDirectoryPathValue = class _DocDirectoryPathValue {
|
|
|
5417
5227
|
constructor(value, pathSystem) {
|
|
5418
5228
|
this.value = value;
|
|
5419
5229
|
this.pathSystem = pathSystem;
|
|
5230
|
+
Object.freeze(this.value);
|
|
5420
5231
|
Object.freeze(this);
|
|
5421
5232
|
}
|
|
5422
5233
|
/**
|
|
@@ -5553,7 +5364,7 @@ var DocDirectoryPathValue = class _DocDirectoryPathValue {
|
|
|
5553
5364
|
* Export as JSON format
|
|
5554
5365
|
*/
|
|
5555
5366
|
toJson() {
|
|
5556
|
-
return this.value;
|
|
5367
|
+
return { ...this.value };
|
|
5557
5368
|
}
|
|
5558
5369
|
/**
|
|
5559
5370
|
* Check if paths are equal
|
|
@@ -5566,7 +5377,7 @@ var DocDirectoryPathValue = class _DocDirectoryPathValue {
|
|
|
5566
5377
|
*/
|
|
5567
5378
|
contains(other) {
|
|
5568
5379
|
const relative = this.pathSystem.relative(this.path, other.path);
|
|
5569
|
-
return !relative.startsWith("..") && relative !== "";
|
|
5380
|
+
return !relative.startsWith("..") && relative !== "" && relative !== ".";
|
|
5570
5381
|
}
|
|
5571
5382
|
};
|
|
5572
5383
|
|
|
@@ -5650,4 +5461,4 @@ var DocRelationFieldValue = class _DocRelationFieldValue {
|
|
|
5650
5461
|
}
|
|
5651
5462
|
};
|
|
5652
5463
|
|
|
5653
|
-
export { DocClient, DocCustomSchemaFieldValue, DocDirectoryPathValue, DocDirectoryReference, DocFileIndexContentValue, DocFileIndexEntity, DocFileIndexMetaValue, DocFileIndexReference, DocFileIndexSchemaValue, DocFileMdContentValue, DocFileMdEntity, DocFileMdMetaValue, DocFileMdReference, DocFilePathValue, DocFileRelationReference, DocFileTreeSystem, DocFileUnknownEntity, DocFileUnknownReference, DocMarkdownSystem, DocPathSystem, DocPathSystemMock, DocRelationFieldValue, DocRelationFileValue, DocRelationValue, DocTreeDirectoryNodeValue, DocTreeFileNodeValue, assertType, defaultTestConfig, defineSchema, docCustomSchemaField, expectType };
|
|
5464
|
+
export { DocClient, DocCustomSchemaFieldValue, DocDirectoryPathValue, DocDirectoryReference, DocFileIndexContentValue, DocFileIndexEntity, DocFileIndexMetaValue, DocFileIndexReference, DocFileIndexSchemaValue, DocFileMdContentValue, DocFileMdEntity, DocFileMdMetaValue, DocFileMdReference, DocFilePathValue, DocFileRelationReference, DocFileTreeSystem, DocFileUnknownEntity, DocFileUnknownReference, DocMarkdownSystem, DocPathSystem, DocPathSystemMock, DocRelationFieldValue, DocRelationFileValue, DocRelationValue, DocTreeDirectoryNodeValue, DocTreeFileNodeValue, assertType, createSafeProxy, defaultTestConfig, defineSchema, docCustomSchemaField, expectType };
|