@interactive-inc/docs-client 1.1.1 → 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/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/models.ts
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: z.string().min(1),
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: z.string().min(1),
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
- z.string(),
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(0, endIndex + separator.length + 1).replaceAll(separator, "").trim();
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 typedSchema = draft;
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: typedSchema
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
@@ -1450,64 +1482,6 @@ var DocFileIndexMetaValue = class _DocFileIndexMetaValue {
1450
1482
  {}
1451
1483
  );
1452
1484
  }
1453
- /**
1454
- * Extract icon
1455
- */
1456
- static extractIcon(data, config) {
1457
- if ("icon" in data && typeof data.icon === "string") {
1458
- return data.icon;
1459
- }
1460
- return config.defaultIndexIcon;
1461
- }
1462
- /**
1463
- * Extract schema part
1464
- */
1465
- static extractSchema(record, customSchema) {
1466
- const hasSchema = "schema" in record;
1467
- if (hasSchema === false) {
1468
- return _DocFileIndexMetaValue.emptySchema(customSchema);
1469
- }
1470
- if (typeof record.schema !== "object" || record.schema === null) {
1471
- return _DocFileIndexMetaValue.emptySchema(customSchema);
1472
- }
1473
- return _DocFileIndexMetaValue.normalizeSchema(
1474
- record.schema,
1475
- customSchema
1476
- );
1477
- }
1478
- /**
1479
- * Normalize entire schema
1480
- */
1481
- static normalizeSchema(schema, customSchema) {
1482
- const factory = new DocFileIndexSchemaFieldFactory();
1483
- if (Object.keys(customSchema).length === 0) {
1484
- const dynamicRecord = {};
1485
- for (const key of Object.keys(schema)) {
1486
- const schemaValue = schema[key];
1487
- if (schemaValue !== void 0 && schemaValue !== null) {
1488
- const field = factory.from(key, schemaValue);
1489
- const normalizedValue = {
1490
- ...field.value,
1491
- required: field.value.required ?? false
1492
- };
1493
- dynamicRecord[key] = normalizedValue;
1494
- }
1495
- }
1496
- return dynamicRecord;
1497
- }
1498
- const record = {};
1499
- const customSchemaKeys = Object.keys(customSchema);
1500
- for (const key of customSchemaKeys) {
1501
- const schemaValue = schema[key];
1502
- const field = factory.from(key, schemaValue);
1503
- const normalizedValue = {
1504
- ...field.value,
1505
- required: field.value.required ?? false
1506
- };
1507
- record[key] = normalizedValue;
1508
- }
1509
- return record;
1510
- }
1511
1485
  static emptySchema(customSchema) {
1512
1486
  const record = {};
1513
1487
  const customSchemaKeys = Object.keys(customSchema);
@@ -1523,6 +1497,30 @@ var DocFileIndexMetaValue = class _DocFileIndexMetaValue {
1523
1497
  }
1524
1498
  return record;
1525
1499
  }
1500
+ static extractIcon(record, config) {
1501
+ if (typeof record.icon === "string") {
1502
+ return record.icon;
1503
+ }
1504
+ return config.defaultIndexIcon;
1505
+ }
1506
+ static extractSchema(record, customSchema) {
1507
+ if (typeof record.schema === "object" && record.schema !== null && !Array.isArray(record.schema)) {
1508
+ const rawSchema = record.schema;
1509
+ const normalizedSchema = {};
1510
+ for (const key of Object.keys(rawSchema)) {
1511
+ const field = rawSchema[key];
1512
+ normalizedSchema[key] = {
1513
+ ...field,
1514
+ required: field.required ?? false,
1515
+ title: field.title ?? null,
1516
+ description: field.description ?? null,
1517
+ default: field.default ?? null
1518
+ };
1519
+ }
1520
+ return normalizedSchema;
1521
+ }
1522
+ return _DocFileIndexMetaValue.emptySchema(customSchema);
1523
+ }
1526
1524
  };
1527
1525
 
1528
1526
  // lib/values/doc-file-index-content-value.ts
@@ -1556,11 +1554,7 @@ var DocFileIndexContentValue = class _DocFileIndexContentValue {
1556
1554
  * FrontMatter
1557
1555
  */
1558
1556
  meta() {
1559
- return new DocFileIndexMetaValue(
1560
- this.value.meta,
1561
- this.customSchema,
1562
- this.config
1563
- );
1557
+ return new DocFileIndexMetaValue(this.value.meta, this.customSchema, this.config);
1564
1558
  }
1565
1559
  /**
1566
1560
  * Update title
@@ -1579,11 +1573,7 @@ var DocFileIndexContentValue = class _DocFileIndexContentValue {
1579
1573
  */
1580
1574
  withDescription(description, defaultTitle) {
1581
1575
  const engine = new DocMarkdownSystem();
1582
- const updatedBody = engine.updateDescription(
1583
- this.body,
1584
- description,
1585
- defaultTitle || this.title
1586
- );
1576
+ const updatedBody = engine.updateDescription(this.body, description, defaultTitle || this.title);
1587
1577
  return new _DocFileIndexContentValue(
1588
1578
  {
1589
1579
  ...this.value,
@@ -1599,18 +1589,37 @@ var DocFileIndexContentValue = class _DocFileIndexContentValue {
1599
1589
  */
1600
1590
  static fromMarkdown(markdown, customSchema, config) {
1601
1591
  const engine = new DocMarkdownSystem();
1602
- const frontMatter = DocFileIndexMetaValue.from(
1603
- markdown,
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
+ },
1604
1601
  customSchema,
1605
1602
  config
1606
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
+ };
1607
1616
  return new _DocFileIndexContentValue(
1608
1617
  {
1609
1618
  type: "markdown-index",
1610
1619
  body: engine.extractBody(markdown),
1611
1620
  title: engine.extractTitle(markdown) || "",
1612
1621
  description: engine.extractDescription(markdown) || "",
1613
- meta: frontMatter.toJson()
1622
+ meta
1614
1623
  },
1615
1624
  customSchema,
1616
1625
  config
@@ -1668,8 +1677,26 @@ schema: {}
1668
1677
 
1669
1678
  # ${directoryName}
1670
1679
  `;
1671
- return _DocFileIndexContentValue.fromMarkdown(
1672
- content,
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
+ },
1673
1700
  customSchema,
1674
1701
  config
1675
1702
  );
@@ -1724,11 +1751,7 @@ var DocFileIndexEntity = class _DocFileIndexEntity {
1724
1751
  * Content
1725
1752
  */
1726
1753
  get content() {
1727
- return new DocFileIndexContentValue(
1728
- this.value.content,
1729
- this.customSchema,
1730
- this.config
1731
- );
1754
+ return new DocFileIndexContentValue(this.value.content, this.customSchema, this.config);
1732
1755
  }
1733
1756
  /**
1734
1757
  * Path information
@@ -1780,6 +1803,7 @@ var DocFilePathValue = class _DocFilePathValue {
1780
1803
  this.value = value;
1781
1804
  zDocFilePath.parse(value);
1782
1805
  this.pathSystem = pathSystem;
1806
+ Object.freeze(this.value);
1783
1807
  Object.freeze(this);
1784
1808
  }
1785
1809
  pathSystem;
@@ -1823,13 +1847,13 @@ var DocFilePathValue = class _DocFilePathValue {
1823
1847
  * Whether the file is archived
1824
1848
  */
1825
1849
  get isArchived() {
1826
- return this.path.includes("/.archive/");
1850
+ return this.path.includes("/_/") || this.path.startsWith("_/");
1827
1851
  }
1828
1852
  /**
1829
1853
  * Export as JSON format
1830
1854
  */
1831
1855
  toJson() {
1832
- return this.value;
1856
+ return { ...this.value };
1833
1857
  }
1834
1858
  /**
1835
1859
  * Create instance from relative path (DI support)
@@ -1873,9 +1897,7 @@ var DocCustomSchemaFieldBooleanValue = class _DocCustomSchemaFieldBooleanValue {
1873
1897
  return zDocMetaFieldBoolean.parse(value);
1874
1898
  } catch {
1875
1899
  if (this.value.required) {
1876
- throw new Error(
1877
- `required field "${this.key.toString()}" is missing or invalid`
1878
- );
1900
+ throw new Error(`required field "${this.key.toString()}" is missing or invalid`);
1879
1901
  }
1880
1902
  return _DocCustomSchemaFieldBooleanValue.defaultValue();
1881
1903
  }
@@ -1907,9 +1929,7 @@ var DocCustomSchemaFieldMultiNumberValue = class _DocCustomSchemaFieldMultiNumbe
1907
1929
  return zDocMetaFieldMultiNumber.parse(value);
1908
1930
  } catch {
1909
1931
  if (this.value.required) {
1910
- throw new Error(
1911
- `required field "${this.key.toString()}" is missing or invalid`
1912
- );
1932
+ throw new Error(`required field "${this.key.toString()}" is missing or invalid`);
1913
1933
  }
1914
1934
  return _DocCustomSchemaFieldMultiNumberValue.defaultValue();
1915
1935
  }
@@ -1941,9 +1961,7 @@ var DocCustomSchemaFieldMultiRelationValue = class _DocCustomSchemaFieldMultiRel
1941
1961
  return zDocMetaFieldMultiRelation.parse(value);
1942
1962
  } catch {
1943
1963
  if (this.value.required) {
1944
- throw new Error(
1945
- `required field "${this.key.toString()}" is missing or invalid`
1946
- );
1964
+ throw new Error(`required field "${this.key.toString()}" is missing or invalid`);
1947
1965
  }
1948
1966
  return _DocCustomSchemaFieldMultiRelationValue.defaultValue();
1949
1967
  }
@@ -1975,9 +1993,7 @@ var DocCustomSchemaFieldMultiSelectNumberValue = class _DocCustomSchemaFieldMult
1975
1993
  return zDocMetaFieldMultiSelectNumber.parse(value);
1976
1994
  } catch {
1977
1995
  if (this.value.required) {
1978
- throw new Error(
1979
- `required field "${this.key.toString()}" is missing or invalid`
1980
- );
1996
+ throw new Error(`required field "${this.key.toString()}" is missing or invalid`);
1981
1997
  }
1982
1998
  return _DocCustomSchemaFieldMultiSelectNumberValue.defaultValue();
1983
1999
  }
@@ -2009,9 +2025,7 @@ var DocCustomSchemaFieldMultiSelectTextValue = class _DocCustomSchemaFieldMultiS
2009
2025
  return zDocMetaFieldMultiSelectText.parse(value);
2010
2026
  } catch {
2011
2027
  if (this.value.required) {
2012
- throw new Error(
2013
- `required field "${this.key.toString()}" is missing or invalid`
2014
- );
2028
+ throw new Error(`required field "${this.key.toString()}" is missing or invalid`);
2015
2029
  }
2016
2030
  return _DocCustomSchemaFieldMultiSelectTextValue.defaultValue();
2017
2031
  }
@@ -2043,9 +2057,7 @@ var DocCustomSchemaFieldMultiTextValue = class _DocCustomSchemaFieldMultiTextVal
2043
2057
  return zDocMetaFieldMultiText.parse(value);
2044
2058
  } catch {
2045
2059
  if (this.value.required) {
2046
- throw new Error(
2047
- `required field "${this.key.toString()}" is missing or invalid`
2048
- );
2060
+ throw new Error(`required field "${this.key.toString()}" is missing or invalid`);
2049
2061
  }
2050
2062
  return _DocCustomSchemaFieldMultiTextValue.defaultValue();
2051
2063
  }
@@ -2077,9 +2089,7 @@ var DocCustomSchemaFieldNumberValue = class _DocCustomSchemaFieldNumberValue {
2077
2089
  return zDocMetaFieldNumber.parse(value);
2078
2090
  } catch {
2079
2091
  if (this.value.required) {
2080
- throw new Error(
2081
- `required field "${this.key.toString()}" is missing or invalid`
2082
- );
2092
+ throw new Error(`required field "${this.key.toString()}" is missing or invalid`);
2083
2093
  }
2084
2094
  return _DocCustomSchemaFieldNumberValue.defaultValue();
2085
2095
  }
@@ -2111,9 +2121,7 @@ var DocCustomSchemaFieldRelationValue = class _DocCustomSchemaFieldRelationValue
2111
2121
  return zDocMetaFieldRelation.parse(value);
2112
2122
  } catch {
2113
2123
  if (this.value.required) {
2114
- throw new Error(
2115
- `required field "${this.key.toString()}" is missing or invalid`
2116
- );
2124
+ throw new Error(`required field "${this.key.toString()}" is missing or invalid`);
2117
2125
  }
2118
2126
  return _DocCustomSchemaFieldRelationValue.defaultValue();
2119
2127
  }
@@ -2145,9 +2153,7 @@ var DocCustomSchemaFieldSelectNumberValue = class _DocCustomSchemaFieldSelectNum
2145
2153
  return zDocMetaFieldSelectNumber.parse(value);
2146
2154
  } catch {
2147
2155
  if (this.value.required) {
2148
- throw new Error(
2149
- `required field "${this.key.toString()}" is missing or invalid`
2150
- );
2156
+ throw new Error(`required field "${this.key.toString()}" is missing or invalid`);
2151
2157
  }
2152
2158
  return _DocCustomSchemaFieldSelectNumberValue.defaultValue();
2153
2159
  }
@@ -2179,9 +2185,7 @@ var DocCustomSchemaFieldSelectTextValue = class _DocCustomSchemaFieldSelectTextV
2179
2185
  return zDocMetaFieldSelectText.parse(value);
2180
2186
  } catch {
2181
2187
  if (this.value.required) {
2182
- throw new Error(
2183
- `required field "${this.key.toString()}" is missing or invalid`
2184
- );
2188
+ throw new Error(`required field "${this.key.toString()}" is missing or invalid`);
2185
2189
  }
2186
2190
  return _DocCustomSchemaFieldSelectTextValue.defaultValue();
2187
2191
  }
@@ -2213,9 +2217,7 @@ var DocCustomSchemaFieldTextValue = class _DocCustomSchemaFieldTextValue {
2213
2217
  return zDocMetaFieldText.parse(value);
2214
2218
  } catch {
2215
2219
  if (this.value.required) {
2216
- throw new Error(
2217
- `required field "${this.key.toString()}" is missing or invalid`
2218
- );
2220
+ throw new Error(`required field "${this.key.toString()}" is missing or invalid`);
2219
2221
  }
2220
2222
  return _DocCustomSchemaFieldTextValue.defaultValue();
2221
2223
  }
@@ -2278,10 +2280,7 @@ var DocMetaFieldBooleanValue = class _DocMetaFieldBooleanValue {
2278
2280
  }
2279
2281
  type = "boolean";
2280
2282
  static from(key, value) {
2281
- return new _DocMetaFieldBooleanValue(
2282
- key,
2283
- zDocMetaFieldBoolean.parse(value)
2284
- );
2283
+ return new _DocMetaFieldBooleanValue(key, zDocMetaFieldBoolean.parse(value));
2285
2284
  }
2286
2285
  static default(key) {
2287
2286
  return new _DocMetaFieldBooleanValue(key, false);
@@ -2301,10 +2300,7 @@ var DocMetaFieldMultiNumberValue = class _DocMetaFieldMultiNumberValue {
2301
2300
  }
2302
2301
  type = "multi-number";
2303
2302
  static from(key, value) {
2304
- return new _DocMetaFieldMultiNumberValue(
2305
- key,
2306
- zDocMetaFieldMultiNumber.parse(value)
2307
- );
2303
+ return new _DocMetaFieldMultiNumberValue(key, zDocMetaFieldMultiNumber.parse(value));
2308
2304
  }
2309
2305
  static default(key) {
2310
2306
  return new _DocMetaFieldMultiNumberValue(key, []);
@@ -2324,10 +2320,7 @@ var DocMetaFieldMultiRelationValue = class _DocMetaFieldMultiRelationValue {
2324
2320
  }
2325
2321
  type = "multi-relation";
2326
2322
  static from(key, value) {
2327
- return new _DocMetaFieldMultiRelationValue(
2328
- key,
2329
- zDocMetaFieldMultiRelation.parse(value)
2330
- );
2323
+ return new _DocMetaFieldMultiRelationValue(key, zDocMetaFieldMultiRelation.parse(value));
2331
2324
  }
2332
2325
  static default(key) {
2333
2326
  return new _DocMetaFieldMultiRelationValue(key, []);
@@ -2370,10 +2363,7 @@ var DocMetaFieldMultiSelectTextValue = class _DocMetaFieldMultiSelectTextValue {
2370
2363
  }
2371
2364
  type = "multi-select-text";
2372
2365
  static from(key, value) {
2373
- return new _DocMetaFieldMultiSelectTextValue(
2374
- key,
2375
- zDocMetaFieldMultiSelectText.parse(value)
2376
- );
2366
+ return new _DocMetaFieldMultiSelectTextValue(key, zDocMetaFieldMultiSelectText.parse(value));
2377
2367
  }
2378
2368
  static default(key) {
2379
2369
  return new _DocMetaFieldMultiSelectTextValue(key, []);
@@ -2393,10 +2383,7 @@ var DocMetaFieldMultiTextValue = class _DocMetaFieldMultiTextValue {
2393
2383
  }
2394
2384
  type = "multi-text";
2395
2385
  static from(key, value) {
2396
- return new _DocMetaFieldMultiTextValue(
2397
- key,
2398
- zDocMetaFieldMultiText.parse(value)
2399
- );
2386
+ return new _DocMetaFieldMultiTextValue(key, zDocMetaFieldMultiText.parse(value));
2400
2387
  }
2401
2388
  static default(key) {
2402
2389
  return new _DocMetaFieldMultiTextValue(key, []);
@@ -2436,10 +2423,7 @@ var DocMetaFieldRelationValue = class _DocMetaFieldRelationValue {
2436
2423
  }
2437
2424
  type = "relation";
2438
2425
  static from(key, value) {
2439
- return new _DocMetaFieldRelationValue(
2440
- key,
2441
- zDocMetaFieldRelation.parse(value)
2442
- );
2426
+ return new _DocMetaFieldRelationValue(key, zDocMetaFieldRelation.parse(value));
2443
2427
  }
2444
2428
  static default(key) {
2445
2429
  return new _DocMetaFieldRelationValue(key, null);
@@ -2459,10 +2443,7 @@ var DocMetaFieldSelectNumberValue = class _DocMetaFieldSelectNumberValue {
2459
2443
  }
2460
2444
  type = "select-number";
2461
2445
  static from(key, value) {
2462
- return new _DocMetaFieldSelectNumberValue(
2463
- key,
2464
- zDocMetaFieldSelectNumber.parse(value)
2465
- );
2446
+ return new _DocMetaFieldSelectNumberValue(key, zDocMetaFieldSelectNumber.parse(value));
2466
2447
  }
2467
2448
  static default(key) {
2468
2449
  return new _DocMetaFieldSelectNumberValue(key, null);
@@ -2482,10 +2463,7 @@ var DocMetaFieldSelectTextValue = class _DocMetaFieldSelectTextValue {
2482
2463
  }
2483
2464
  type = "select-text";
2484
2465
  static from(key, value) {
2485
- return new _DocMetaFieldSelectTextValue(
2486
- key,
2487
- zDocMetaFieldSelectText.parse(value)
2488
- );
2466
+ return new _DocMetaFieldSelectTextValue(key, zDocMetaFieldSelectText.parse(value));
2489
2467
  }
2490
2468
  static default(key) {
2491
2469
  return new _DocMetaFieldSelectTextValue(key, null);
@@ -2596,7 +2574,12 @@ var DocFileMdMetaValue = class _DocFileMdMetaValue {
2596
2574
  constructor(value, customSchema) {
2597
2575
  this.value = value;
2598
2576
  this.customSchema = customSchema;
2599
- this.validateValue(value, customSchema);
2577
+ for (const key of Object.keys(customSchema)) {
2578
+ const field = customSchema[key];
2579
+ if (field.required && !(key in value)) {
2580
+ throw new Error(`Required field "${key}" is missing`);
2581
+ }
2582
+ }
2600
2583
  Object.freeze(this);
2601
2584
  }
2602
2585
  get keys() {
@@ -2698,23 +2681,6 @@ var DocFileMdMetaValue = class _DocFileMdMetaValue {
2698
2681
  toYaml() {
2699
2682
  return stringify(this.value).trim();
2700
2683
  }
2701
- validateValue(value, schema) {
2702
- if (Object.keys(schema).length === 0) {
2703
- return;
2704
- }
2705
- const keys = Object.keys(schema);
2706
- for (const key of keys) {
2707
- const schemaField = schema[key];
2708
- const fieldValue = this.getValueField(value, key);
2709
- if (schemaField.required && fieldValue === void 0) {
2710
- throw new Error(`Required field "${key}" is missing`);
2711
- }
2712
- if (fieldValue !== void 0) {
2713
- const factory = new DocMetaFieldFactory();
2714
- factory.fromType(key, schemaField.type, fieldValue);
2715
- }
2716
- }
2717
- }
2718
2684
  getValueField(value, key) {
2719
2685
  const record = value;
2720
2686
  return record[key];
@@ -2740,10 +2706,7 @@ var DocFileMdMetaValue = class _DocFileMdMetaValue {
2740
2706
  const value = customSchemaField.validate(record[key]);
2741
2707
  validatedRecord[key] = value;
2742
2708
  }
2743
- return new _DocFileMdMetaValue(
2744
- validatedRecord,
2745
- customSchema
2746
- );
2709
+ return new _DocFileMdMetaValue(validatedRecord, customSchema);
2747
2710
  }
2748
2711
  static empty(customSchema) {
2749
2712
  const record = {};
@@ -2819,11 +2782,7 @@ var DocFileMdContentValue = class _DocFileMdContentValue {
2819
2782
  withDescription(description, defaultTitle) {
2820
2783
  const fullText = this.toText();
2821
2784
  const engine = new DocMarkdownSystem();
2822
- const updatedText = engine.updateDescription(
2823
- fullText,
2824
- description,
2825
- defaultTitle || this.title
2826
- );
2785
+ const updatedText = engine.updateDescription(fullText, description, defaultTitle || this.title);
2827
2786
  const updatedBody = engine.extractBody(updatedText);
2828
2787
  return new _DocFileMdContentValue(
2829
2788
  {
@@ -2980,15 +2939,9 @@ var DocFileMdEntity = class _DocFileMdEntity {
2980
2939
  withPath(pathOrUpdater) {
2981
2940
  if (typeof pathOrUpdater === "function") {
2982
2941
  const updatedPath = pathOrUpdater(this.path);
2983
- return new _DocFileMdEntity(
2984
- { ...this.value, path: updatedPath },
2985
- this.customSchema
2986
- );
2942
+ return new _DocFileMdEntity({ ...this.value, path: updatedPath }, this.customSchema);
2987
2943
  }
2988
- return new _DocFileMdEntity(
2989
- { ...this.value, path: pathOrUpdater },
2990
- this.customSchema
2991
- );
2944
+ return new _DocFileMdEntity({ ...this.value, path: pathOrUpdater }, this.customSchema);
2992
2945
  }
2993
2946
  withMeta(metaOrUpdater) {
2994
2947
  if (typeof metaOrUpdater === "function") {
@@ -3072,12 +3025,6 @@ var DocRelationFileValue = class _DocRelationFileValue {
3072
3025
  toJson() {
3073
3026
  return { ...this.value };
3074
3027
  }
3075
- /**
3076
- * Extract file name from file path (without extension)
3077
- */
3078
- static extractFileName(filePath) {
3079
- return filePath.split("/").pop()?.replace(".md", "") || filePath;
3080
- }
3081
3028
  /**
3082
3029
  * Create from file path and title
3083
3030
  */
@@ -3090,6 +3037,18 @@ var DocRelationFileValue = class _DocRelationFileValue {
3090
3037
  path: null
3091
3038
  });
3092
3039
  }
3040
+ static extractFileName(filePath) {
3041
+ if (!filePath) {
3042
+ return filePath;
3043
+ }
3044
+ const lastSlash = filePath.lastIndexOf("/");
3045
+ const fileNameWithExt = lastSlash >= 0 ? filePath.slice(lastSlash + 1) : filePath;
3046
+ const lastDot = fileNameWithExt.lastIndexOf(".");
3047
+ if (lastDot > 0) {
3048
+ return fileNameWithExt.slice(0, lastDot);
3049
+ }
3050
+ return fileNameWithExt;
3051
+ }
3093
3052
  };
3094
3053
 
3095
3054
  // lib/values/doc-relation-value.ts
@@ -3152,40 +3111,28 @@ var DocFileRelationReference = class {
3152
3111
  Object.freeze(this);
3153
3112
  }
3154
3113
  pathSystem;
3114
+ get safe() {
3115
+ return createSafeProxy(this);
3116
+ }
3155
3117
  get fileSystem() {
3156
3118
  return this.props.fileSystem;
3157
3119
  }
3158
3120
  get basePath() {
3159
3121
  return this.fileSystem.getBasePath();
3160
3122
  }
3161
- /**
3162
- * Relation path
3163
- */
3164
3123
  get path() {
3165
3124
  return this.props.filePath;
3166
3125
  }
3167
- /**
3168
- * Full path
3169
- */
3170
3126
  get fullPath() {
3171
- return this.pathSystem.join(
3172
- this.fileSystem.getBasePath(),
3173
- this.props.filePath
3174
- );
3127
+ return this.pathSystem.join(this.fileSystem.getBasePath(), this.props.filePath);
3175
3128
  }
3176
3129
  async read() {
3177
3130
  const files = await this.readFiles();
3178
- if (files instanceof Error) {
3179
- return files;
3180
- }
3181
3131
  return new DocRelationValue({
3182
3132
  path: this.path,
3183
3133
  files: files.map((value) => value.toJson())
3184
3134
  });
3185
3135
  }
3186
- /**
3187
- * Read list of relation files
3188
- */
3189
3136
  async readFiles() {
3190
3137
  const exists = await this.fileSystem.exists(this.path);
3191
3138
  if (!exists) {
@@ -3193,14 +3140,11 @@ var DocFileRelationReference = class {
3193
3140
  }
3194
3141
  const filePaths = await this.fileSystem.readDirectoryFilePaths(this.path);
3195
3142
  if (filePaths instanceof Error) {
3196
- return filePaths;
3143
+ throw filePaths;
3197
3144
  }
3198
3145
  const files = [];
3199
3146
  for (const filePath of filePaths) {
3200
3147
  const file = await this.readFile(filePath);
3201
- if (file instanceof Error) {
3202
- return file;
3203
- }
3204
3148
  if (file === null) {
3205
3149
  continue;
3206
3150
  }
@@ -3208,9 +3152,6 @@ var DocFileRelationReference = class {
3208
3152
  }
3209
3153
  return files;
3210
3154
  }
3211
- /**
3212
- * Read single relation file
3213
- */
3214
3155
  async readFile(filePath) {
3215
3156
  if (filePath.includes("index.md")) {
3216
3157
  return null;
@@ -3220,17 +3161,13 @@ var DocFileRelationReference = class {
3220
3161
  }
3221
3162
  const content = await this.fileSystem.readFile(filePath);
3222
3163
  if (content instanceof Error) {
3223
- return content;
3164
+ throw content;
3224
3165
  }
3225
3166
  if (content === null) {
3226
3167
  return null;
3227
3168
  }
3228
3169
  const contentValue = DocFileMdContentValue.fromMarkdown(content, {});
3229
- const pathValue = DocFilePathValue.fromPathWithSystem(
3230
- filePath,
3231
- this.pathSystem,
3232
- this.basePath
3233
- );
3170
+ const pathValue = DocFilePathValue.fromPathWithSystem(filePath, this.pathSystem, this.basePath);
3234
3171
  const fileEntity = new DocFileMdEntity(
3235
3172
  {
3236
3173
  type: "markdown",
@@ -3242,42 +3179,21 @@ var DocFileRelationReference = class {
3242
3179
  );
3243
3180
  return DocRelationFileValue.from(filePath, fileEntity.value.content.title);
3244
3181
  }
3245
- /**
3246
- * Check if file exists
3247
- */
3248
3182
  async exists(slug) {
3249
3183
  const filePath = `${this.path}/${slug}.md`;
3250
3184
  return this.fileSystem.exists(filePath);
3251
3185
  }
3252
- /**
3253
- * Get list of file names (without extension)
3254
- */
3255
3186
  async readSlugs() {
3256
3187
  const files = await this.readFiles();
3257
- if (files instanceof Error) {
3258
- return files;
3259
- }
3260
3188
  return files.map((file) => file.id);
3261
3189
  }
3262
- /**
3263
- * Get file count
3264
- */
3265
3190
  async count() {
3266
3191
  const files = await this.readFiles();
3267
- if (files instanceof Error) {
3268
- return files;
3269
- }
3270
3192
  return files.length;
3271
3193
  }
3272
- /**
3273
- * Check if empty
3274
- */
3275
3194
  async isEmpty() {
3276
- const count = await this.count();
3277
- if (count instanceof Error) {
3278
- return count;
3279
- }
3280
- return count === 0;
3195
+ const fileCount = await this.count();
3196
+ return fileCount === 0;
3281
3197
  }
3282
3198
  };
3283
3199
 
@@ -3291,6 +3207,9 @@ var DocFileIndexReference = class _DocFileIndexReference {
3291
3207
  }
3292
3208
  pathSystem;
3293
3209
  customSchema;
3210
+ get safe() {
3211
+ return createSafeProxy(this);
3212
+ }
3294
3213
  get fileSystem() {
3295
3214
  return this.props.fileSystem;
3296
3215
  }
@@ -3303,13 +3222,14 @@ var DocFileIndexReference = class _DocFileIndexReference {
3303
3222
  get fileFullPath() {
3304
3223
  return this.pathSystem.join(this.basePath, this.filePath);
3305
3224
  }
3306
- get durectoryPath() {
3225
+ get directoryPath() {
3307
3226
  return this.pathSystem.dirname(this.filePath);
3308
3227
  }
3309
3228
  async read() {
3229
+ const directoryMeta = await this.readDirectoryMeta();
3310
3230
  const content = await this.fileSystem.readFile(this.filePath);
3311
3231
  if (content instanceof Error) {
3312
- return content;
3232
+ throw content;
3313
3233
  }
3314
3234
  if (content === null) {
3315
3235
  const dirPath = this.pathSystem.dirname(this.filePath);
@@ -3319,11 +3239,12 @@ var DocFileIndexReference = class _DocFileIndexReference {
3319
3239
  this.pathSystem,
3320
3240
  this.fileSystem.getBasePath()
3321
3241
  );
3322
- const contentValue2 = DocFileIndexContentValue.empty(
3242
+ const contentValue2 = directoryMeta ? DocFileIndexContentValue.emptyWithDirectoryMeta(
3323
3243
  dirName,
3324
3244
  this.customSchema,
3325
- this.props.config
3326
- );
3245
+ this.props.config,
3246
+ directoryMeta
3247
+ ) : DocFileIndexContentValue.empty(dirName, this.customSchema, this.props.config);
3327
3248
  return new DocFileIndexEntity(
3328
3249
  {
3329
3250
  type: "index",
@@ -3339,11 +3260,12 @@ var DocFileIndexReference = class _DocFileIndexReference {
3339
3260
  this.pathSystem,
3340
3261
  this.fileSystem.getBasePath()
3341
3262
  );
3342
- const contentValue = DocFileIndexContentValue.fromMarkdown(
3263
+ const contentValue = directoryMeta ? DocFileIndexContentValue.fromMarkdownWithDirectoryMeta(
3343
3264
  content,
3344
3265
  this.customSchema,
3345
- this.props.config
3346
- );
3266
+ this.props.config,
3267
+ directoryMeta
3268
+ ) : DocFileIndexContentValue.fromMarkdown(content, this.customSchema, this.props.config);
3347
3269
  return new DocFileIndexEntity(
3348
3270
  {
3349
3271
  type: "index",
@@ -3354,21 +3276,38 @@ var DocFileIndexReference = class _DocFileIndexReference {
3354
3276
  this.customSchema
3355
3277
  );
3356
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
+ }
3357
3301
  async readSchemaValue() {
3358
- const indexFile = await this.read();
3359
- if (indexFile instanceof Error) {
3302
+ try {
3303
+ const indexFile = await this.read();
3304
+ return indexFile.content.meta().schema().value;
3305
+ } catch {
3360
3306
  return {};
3361
3307
  }
3362
- return indexFile.content.meta().schema().value;
3363
3308
  }
3364
- /**
3365
- * Read file content
3366
- */
3367
3309
  async readContent() {
3368
3310
  const entity = await this.read();
3369
- if (entity instanceof Error) {
3370
- return entity;
3371
- }
3372
3311
  return entity.value.content.body;
3373
3312
  }
3374
3313
  /**
@@ -3397,22 +3336,19 @@ var DocFileIndexReference = class _DocFileIndexReference {
3397
3336
  this.customSchema
3398
3337
  );
3399
3338
  }
3400
- /**
3401
- * Write content to file
3402
- */
3403
3339
  async writeContent(content) {
3404
- return await this.fileSystem.writeFile(this.filePath, content);
3340
+ const writeResult = await this.fileSystem.writeFile(this.filePath, content);
3341
+ if (writeResult instanceof Error) {
3342
+ throw writeResult;
3343
+ }
3405
3344
  }
3406
- /**
3407
- * Write entity
3408
- */
3409
3345
  async write(entity) {
3410
3346
  const content = entity.content.toText();
3411
- return await this.fileSystem.writeFile(this.filePath, content);
3347
+ const writeResult = await this.fileSystem.writeFile(this.filePath, content);
3348
+ if (writeResult instanceof Error) {
3349
+ throw writeResult;
3350
+ }
3412
3351
  }
3413
- /**
3414
- * Create new file with default content
3415
- */
3416
3352
  async writeDefault() {
3417
3353
  const dirPath = this.pathSystem.dirname(this.filePath);
3418
3354
  const dirName = this.pathSystem.basename(dirPath) || this.props.config.defaultDirectoryName;
@@ -3421,32 +3357,22 @@ var DocFileIndexReference = class _DocFileIndexReference {
3421
3357
  "",
3422
3358
  `Please describe the overview of ${dirName} here.`
3423
3359
  ].join("\n");
3424
- const writeResult = await this.fileSystem.writeFile(
3425
- this.filePath,
3426
- defaultContent
3427
- );
3360
+ const writeResult = await this.fileSystem.writeFile(this.filePath, defaultContent);
3428
3361
  if (writeResult instanceof Error) {
3429
- return writeResult;
3362
+ throw writeResult;
3430
3363
  }
3431
- return null;
3432
3364
  }
3433
- /**
3434
- * Delete file
3435
- */
3436
3365
  async delete() {
3437
- return await this.fileSystem.deleteFile(this.filePath);
3366
+ const deleteResult = await this.fileSystem.deleteFile(this.filePath);
3367
+ if (deleteResult instanceof Error) {
3368
+ throw deleteResult;
3369
+ }
3438
3370
  }
3439
- /**
3440
- * Check if file exists
3441
- */
3442
3371
  async exists() {
3443
3372
  return this.fileSystem.exists(this.filePath);
3444
3373
  }
3445
3374
  async relations() {
3446
3375
  const indexFile = await this.read();
3447
- if (indexFile instanceof Error) {
3448
- return indexFile;
3449
- }
3450
3376
  const schema = indexFile.content.meta().schema();
3451
3377
  if (!schema) {
3452
3378
  return [];
@@ -3456,11 +3382,14 @@ var DocFileIndexReference = class _DocFileIndexReference {
3456
3382
  for (const key of fieldKeys) {
3457
3383
  const fieldValue = schema.value[key];
3458
3384
  if (fieldValue === void 0) continue;
3459
- if (fieldValue.type !== "relation" && fieldValue.type !== "multi-relation") {
3460
- continue;
3385
+ let path = null;
3386
+ if (fieldValue.type === "relation") {
3387
+ path = schema.relation(key).path;
3461
3388
  }
3462
- const field = schema.field(key);
3463
- const path = field.path;
3389
+ if (fieldValue.type === "multi-relation") {
3390
+ path = schema.multiRelation(key).path;
3391
+ }
3392
+ if (path === null) continue;
3464
3393
  const fileRef = new DocFileRelationReference({
3465
3394
  filePath: path,
3466
3395
  fileSystem: this.fileSystem,
@@ -3472,55 +3401,44 @@ var DocFileIndexReference = class _DocFileIndexReference {
3472
3401
  }
3473
3402
  async readRelations() {
3474
3403
  const relations = await this.relations();
3475
- if (relations instanceof Error) {
3476
- return relations;
3477
- }
3478
3404
  const files = [];
3479
3405
  for (const relation of relations) {
3480
- const entity = await relation.read();
3481
- if (entity === null) {
3482
- continue;
3483
- }
3484
- if (entity instanceof Error) {
3406
+ try {
3407
+ const entity = await relation.read();
3408
+ if (entity === null) continue;
3409
+ files.push(entity);
3410
+ } catch {
3485
3411
  continue;
3486
3412
  }
3487
- files.push(entity);
3488
3413
  }
3489
3414
  return files;
3490
3415
  }
3491
- /**
3492
- * Get file size in bytes
3493
- */
3494
3416
  async size() {
3495
- return this.fileSystem.getFileSize(this.filePath);
3417
+ const fileSize = await this.fileSystem.getFileSize(this.filePath);
3418
+ if (fileSize instanceof Error) {
3419
+ throw fileSize;
3420
+ }
3421
+ return fileSize;
3496
3422
  }
3497
- /**
3498
- * Get last modified date
3499
- */
3500
3423
  async lastModified() {
3501
- return this.fileSystem.getFileUpdatedTime(this.filePath);
3424
+ const updatedTime = await this.fileSystem.getFileUpdatedTime(this.filePath);
3425
+ if (updatedTime instanceof Error) {
3426
+ throw updatedTime;
3427
+ }
3428
+ return updatedTime;
3502
3429
  }
3503
- /**
3504
- * Get file creation date
3505
- */
3506
3430
  async createdAt() {
3507
- return this.fileSystem.getFileCreatedTime(this.filePath);
3431
+ const createdTime = await this.fileSystem.getFileCreatedTime(this.filePath);
3432
+ if (createdTime instanceof Error) {
3433
+ throw createdTime;
3434
+ }
3435
+ return createdTime;
3508
3436
  }
3509
- /**
3510
- * Move file to archive and return new reference
3511
- */
3512
3437
  async archive(archiveDirectoryName = this.props.config.archiveDirectoryName) {
3513
3438
  const dirPath = this.pathSystem.dirname(this.filePath);
3514
3439
  const fileName = this.pathSystem.basename(this.filePath);
3515
- const archivePath = this.pathSystem.join(
3516
- dirPath,
3517
- archiveDirectoryName,
3518
- fileName
3519
- );
3520
- const moveResult = await this.fileSystem.moveFile(
3521
- this.filePath,
3522
- archivePath
3523
- );
3440
+ const archivePath = this.pathSystem.join(dirPath, archiveDirectoryName, fileName);
3441
+ const moveResult = await this.fileSystem.moveFile(this.filePath, archivePath);
3524
3442
  if (moveResult instanceof Error) {
3525
3443
  throw moveResult;
3526
3444
  }
@@ -3532,9 +3450,6 @@ var DocFileIndexReference = class _DocFileIndexReference {
3532
3450
  config: this.props.config
3533
3451
  });
3534
3452
  }
3535
- /**
3536
- * Restore file from archive and return new reference
3537
- */
3538
3453
  async restore(archiveDirectoryName = this.props.config.archiveDirectoryName) {
3539
3454
  const dirPath = this.pathSystem.dirname(this.filePath);
3540
3455
  const parentDirName = this.pathSystem.basename(dirPath);
@@ -3542,14 +3457,8 @@ var DocFileIndexReference = class _DocFileIndexReference {
3542
3457
  throw new Error(`File is not in archive directory: ${this.filePath}`);
3543
3458
  }
3544
3459
  const fileName = this.pathSystem.basename(this.filePath);
3545
- const restorePath = this.pathSystem.join(
3546
- this.pathSystem.dirname(dirPath),
3547
- fileName
3548
- );
3549
- const moveResult = await this.fileSystem.moveFile(
3550
- this.filePath,
3551
- restorePath
3552
- );
3460
+ const restorePath = this.pathSystem.join(this.pathSystem.dirname(dirPath), fileName);
3461
+ const moveResult = await this.fileSystem.moveFile(this.filePath, restorePath);
3553
3462
  if (moveResult instanceof Error) {
3554
3463
  throw moveResult;
3555
3464
  }
@@ -3619,6 +3528,9 @@ var DocFileUnknownReference = class _DocFileUnknownReference {
3619
3528
  }
3620
3529
  pathSystem;
3621
3530
  customSchema;
3531
+ get safe() {
3532
+ return createSafeProxy(this);
3533
+ }
3622
3534
  get fileSystem() {
3623
3535
  return this.props.fileSystem;
3624
3536
  }
@@ -3659,22 +3571,18 @@ var DocFileUnknownReference = class _DocFileUnknownReference {
3659
3571
  });
3660
3572
  }
3661
3573
  async read() {
3574
+ if (this.path.endsWith(".md")) {
3575
+ throw new Error("Use DocFileMdReference to read Markdown files.");
3576
+ }
3662
3577
  const content = await this.fileSystem.readFile(this.path);
3663
3578
  if (content instanceof Error) {
3664
- return content;
3579
+ throw content;
3665
3580
  }
3666
3581
  if (content === null) {
3667
- return new Error(`File not found at ${this.path}.`);
3582
+ throw new Error(`File not found at ${this.path}.`);
3668
3583
  }
3669
3584
  const isInArchiveDir = this.path.includes("/_/") || this.path.startsWith("_/");
3670
- if (this.path.endsWith(".md")) {
3671
- throw new Error("Use DocFileMdReference to read Markdown files.");
3672
- }
3673
- const pathValue = DocFilePathValue.fromPathWithSystem(
3674
- this.path,
3675
- this.pathSystem,
3676
- this.basePath
3677
- );
3585
+ const pathValue = DocFilePathValue.fromPathWithSystem(this.path, this.pathSystem, this.basePath);
3678
3586
  const extension = this.pathSystem.extname(this.path).substring(1);
3679
3587
  return new DocFileUnknownEntity({
3680
3588
  type: "unknown",
@@ -3684,25 +3592,15 @@ var DocFileUnknownReference = class _DocFileUnknownReference {
3684
3592
  isArchived: isInArchiveDir
3685
3593
  });
3686
3594
  }
3687
- /**
3688
- * Read file content
3689
- */
3690
3595
  async readContent() {
3691
3596
  const entity = await this.read();
3692
- if (entity instanceof Error) {
3693
- return entity;
3694
- }
3695
3597
  return entity.value.content;
3696
3598
  }
3697
3599
  /**
3698
3600
  * Create empty DocFileUnknownEntity
3699
3601
  */
3700
3602
  empty() {
3701
- const pathValue = DocFilePathValue.fromPathWithSystem(
3702
- this.path,
3703
- this.pathSystem,
3704
- this.basePath
3705
- );
3603
+ const pathValue = DocFilePathValue.fromPathWithSystem(this.path, this.pathSystem, this.basePath);
3706
3604
  const extension = this.pathSystem.extname(this.path).substring(1);
3707
3605
  return new DocFileUnknownEntity({
3708
3606
  type: "unknown",
@@ -3712,81 +3610,71 @@ var DocFileUnknownReference = class _DocFileUnknownReference {
3712
3610
  isArchived: false
3713
3611
  });
3714
3612
  }
3715
- /**
3716
- * Write content to file
3717
- */
3718
3613
  async writeContent(content) {
3719
- return await this.fileSystem.writeFile(this.path, content);
3614
+ const writeResult = await this.fileSystem.writeFile(this.path, content);
3615
+ if (writeResult instanceof Error) {
3616
+ throw writeResult;
3617
+ }
3720
3618
  }
3721
- /**
3722
- * Write entity
3723
- */
3724
3619
  async write(entity) {
3725
- return await this.fileSystem.writeFile(this.path, entity.value.content);
3620
+ const writeResult = await this.fileSystem.writeFile(this.path, entity.value.content);
3621
+ if (writeResult instanceof Error) {
3622
+ throw writeResult;
3623
+ }
3726
3624
  }
3727
- /**
3728
- * Write raw content
3729
- */
3730
3625
  async writeRaw(content) {
3731
- return await this.fileSystem.writeFile(this.path, content);
3626
+ const writeResult = await this.fileSystem.writeFile(this.path, content);
3627
+ if (writeResult instanceof Error) {
3628
+ throw writeResult;
3629
+ }
3732
3630
  }
3733
- /**
3734
- * Delete file
3735
- */
3736
3631
  async delete() {
3737
- return await this.fileSystem.deleteFile(this.path);
3632
+ const deleteResult = await this.fileSystem.deleteFile(this.path);
3633
+ if (deleteResult instanceof Error) {
3634
+ throw deleteResult;
3635
+ }
3738
3636
  }
3739
- /**
3740
- * Check if file exists
3741
- */
3742
3637
  async exists() {
3743
3638
  return this.fileSystem.exists(this.path);
3744
3639
  }
3745
- /**
3746
- * Copy file
3747
- */
3748
3640
  async copyTo(destinationPath) {
3749
- return await this.fileSystem.copyFile(this.path, destinationPath);
3641
+ const copyResult = await this.fileSystem.copyFile(this.path, destinationPath);
3642
+ if (copyResult instanceof Error) {
3643
+ throw copyResult;
3644
+ }
3750
3645
  }
3751
- /**
3752
- * Move file
3753
- */
3754
3646
  async moveTo(destinationPath) {
3755
- return await this.fileSystem.moveFile(this.path, destinationPath);
3647
+ const moveResult = await this.fileSystem.moveFile(this.path, destinationPath);
3648
+ if (moveResult instanceof Error) {
3649
+ throw moveResult;
3650
+ }
3756
3651
  }
3757
- /**
3758
- * Get file size in bytes
3759
- */
3760
3652
  async size() {
3761
- return this.fileSystem.getFileSize(this.path);
3653
+ const fileSize = await this.fileSystem.getFileSize(this.path);
3654
+ if (fileSize instanceof Error) {
3655
+ throw fileSize;
3656
+ }
3657
+ return fileSize;
3762
3658
  }
3763
- /**
3764
- * Get file last modified time
3765
- */
3766
3659
  async lastModified() {
3767
- return this.fileSystem.getFileUpdatedTime(this.path);
3660
+ const updatedTime = await this.fileSystem.getFileUpdatedTime(this.path);
3661
+ if (updatedTime instanceof Error) {
3662
+ throw updatedTime;
3663
+ }
3664
+ return updatedTime;
3768
3665
  }
3769
- /**
3770
- * Get file creation time
3771
- */
3772
3666
  async createdAt() {
3773
- return this.fileSystem.getFileCreatedTime(this.path);
3667
+ const createdTime = await this.fileSystem.getFileCreatedTime(this.path);
3668
+ if (createdTime instanceof Error) {
3669
+ throw createdTime;
3670
+ }
3671
+ return createdTime;
3774
3672
  }
3775
- /**
3776
- * Move file to archive and return new reference
3777
- */
3778
3673
  async archive(archiveDirectoryName = this.props.config.archiveDirectoryName) {
3779
3674
  const dirPath = this.pathSystem.dirname(this.path);
3780
3675
  const fileName = this.pathSystem.basename(this.path);
3781
- const archivePath = this.pathSystem.join(
3782
- dirPath,
3783
- archiveDirectoryName,
3784
- fileName
3785
- );
3786
- const moveResult = await this.moveTo(archivePath);
3787
- if (moveResult instanceof Error) {
3788
- throw moveResult;
3789
- }
3676
+ const archivePath = this.pathSystem.join(dirPath, archiveDirectoryName, fileName);
3677
+ await this.moveTo(archivePath);
3790
3678
  return new _DocFileUnknownReference({
3791
3679
  path: archivePath,
3792
3680
  fileSystem: this.fileSystem,
@@ -3795,9 +3683,6 @@ var DocFileUnknownReference = class _DocFileUnknownReference {
3795
3683
  customSchema: this.customSchema
3796
3684
  });
3797
3685
  }
3798
- /**
3799
- * Restore file from archive and return new reference
3800
- */
3801
3686
  async restore(archiveDirectoryName = this.props.config.archiveDirectoryName) {
3802
3687
  const dirPath = this.pathSystem.dirname(this.path);
3803
3688
  const parentDirName = this.pathSystem.basename(dirPath);
@@ -3805,14 +3690,8 @@ var DocFileUnknownReference = class _DocFileUnknownReference {
3805
3690
  throw new Error(`File is not in archive directory: ${this.path}`);
3806
3691
  }
3807
3692
  const fileName = this.pathSystem.basename(this.path);
3808
- const restorePath = this.pathSystem.join(
3809
- this.pathSystem.dirname(dirPath),
3810
- fileName
3811
- );
3812
- const moveResult = await this.moveTo(restorePath);
3813
- if (moveResult instanceof Error) {
3814
- throw moveResult;
3815
- }
3693
+ const restorePath = this.pathSystem.join(this.pathSystem.dirname(dirPath), fileName);
3694
+ await this.moveTo(restorePath);
3816
3695
  return new _DocFileUnknownReference({
3817
3696
  path: restorePath,
3818
3697
  fileSystem: this.fileSystem,
@@ -3833,6 +3712,9 @@ var DocDirectoryReference = class _DocDirectoryReference {
3833
3712
  }
3834
3713
  pathSystem;
3835
3714
  customSchema;
3715
+ get safe() {
3716
+ return createSafeProxy(this);
3717
+ }
3836
3718
  get fileSystem() {
3837
3719
  return this.props.fileSystem;
3838
3720
  }
@@ -3864,11 +3746,7 @@ var DocDirectoryReference = class _DocDirectoryReference {
3864
3746
  return this.props.indexFileName;
3865
3747
  }
3866
3748
  get indexFilePath() {
3867
- return this.pathSystem.join(
3868
- this.basePath,
3869
- this.relativePath,
3870
- this.props.indexFileName
3871
- );
3749
+ return this.pathSystem.join(this.basePath, this.relativePath, this.props.indexFileName);
3872
3750
  }
3873
3751
  get archiveDirectoryName() {
3874
3752
  return this.props.archiveDirectoryName;
@@ -3877,19 +3755,14 @@ var DocDirectoryReference = class _DocDirectoryReference {
3877
3755
  return this.pathSystem.basename(this.path);
3878
3756
  }
3879
3757
  async fileNames() {
3880
- const filePaths = await this.fileSystem.readDirectoryFilePaths(
3881
- this.relativePath
3882
- );
3758
+ const filePaths = await this.fileSystem.readDirectoryFilePaths(this.relativePath);
3883
3759
  if (filePaths instanceof Error) {
3884
- return filePaths;
3760
+ throw filePaths;
3885
3761
  }
3886
3762
  return filePaths.map((p) => this.pathSystem.basename(p)).filter((name) => name.includes("."));
3887
3763
  }
3888
3764
  async archivedFileNames() {
3889
- const archivePath = this.pathSystem.join(
3890
- this.relativePath,
3891
- this.archiveDirectoryName
3892
- );
3765
+ const archivePath = this.pathSystem.join(this.relativePath, this.archiveDirectoryName);
3893
3766
  const filePaths = await this.fileSystem.readDirectoryFilePaths(archivePath);
3894
3767
  if (filePaths instanceof Error) {
3895
3768
  return [];
@@ -3897,10 +3770,9 @@ var DocDirectoryReference = class _DocDirectoryReference {
3897
3770
  return filePaths.map((p) => this.pathSystem.basename(p)).filter((name) => name.includes("."));
3898
3771
  }
3899
3772
  async *filesGenerator() {
3900
- const fileNames = await this.fileNames();
3901
- if (fileNames instanceof Error) return;
3902
- for (const fileName of fileNames) {
3903
- if (fileName === "index.md") continue;
3773
+ const allFileNames = await this.fileNames();
3774
+ for (const fileName of allFileNames) {
3775
+ if (fileName === this.indexFileName) continue;
3904
3776
  if (fileName.endsWith(".md")) {
3905
3777
  yield new DocFileMdReference({
3906
3778
  path: this.pathSystem.join(this.relativePath, fileName),
@@ -3919,17 +3791,12 @@ var DocDirectoryReference = class _DocDirectoryReference {
3919
3791
  customSchema: this.customSchema
3920
3792
  });
3921
3793
  }
3922
- const archivedFileNames = await this.archivedFileNames();
3923
- if (archivedFileNames instanceof Error) return;
3924
- for (const fileName of archivedFileNames) {
3794
+ const archivedNames = await this.archivedFileNames();
3795
+ for (const fileName of archivedNames) {
3925
3796
  if (fileName === this.indexFileName) continue;
3926
3797
  if (fileName.endsWith(".md")) {
3927
3798
  yield new DocFileMdReference({
3928
- path: this.pathSystem.join(
3929
- this.relativePath,
3930
- this.archiveDirectoryName,
3931
- fileName
3932
- ),
3799
+ path: this.pathSystem.join(this.relativePath, this.archiveDirectoryName, fileName),
3933
3800
  fileSystem: this.fileSystem,
3934
3801
  pathSystem: this.pathSystem,
3935
3802
  customSchema: this.customSchema,
@@ -3938,11 +3805,7 @@ var DocDirectoryReference = class _DocDirectoryReference {
3938
3805
  continue;
3939
3806
  }
3940
3807
  yield new DocFileUnknownReference({
3941
- path: this.pathSystem.join(
3942
- this.relativePath,
3943
- this.archiveDirectoryName,
3944
- fileName
3945
- ),
3808
+ path: this.pathSystem.join(this.relativePath, this.archiveDirectoryName, fileName),
3946
3809
  fileSystem: this.fileSystem,
3947
3810
  pathSystem: this.pathSystem,
3948
3811
  config: this.props.config,
@@ -3951,29 +3814,22 @@ var DocDirectoryReference = class _DocDirectoryReference {
3951
3814
  }
3952
3815
  }
3953
3816
  async *mdFilesGenerator() {
3954
- const generator = this.filesGenerator();
3955
- for await (const file of generator) {
3956
- if (file instanceof Error) {
3957
- yield file;
3958
- return;
3959
- }
3817
+ for await (const file of this.filesGenerator()) {
3960
3818
  if (file instanceof DocFileMdReference) {
3961
3819
  yield file;
3962
3820
  }
3963
3821
  }
3964
3822
  }
3965
3823
  async files() {
3966
- const files = [];
3824
+ const allFiles = [];
3967
3825
  for await (const ref of this.filesGenerator()) {
3968
- if (ref instanceof Error) continue;
3969
- files.push(ref);
3826
+ allFiles.push(ref);
3970
3827
  }
3971
- return files;
3828
+ return allFiles;
3972
3829
  }
3973
3830
  async mdFiles() {
3974
3831
  const refs = [];
3975
3832
  for await (const file of this.mdFilesGenerator()) {
3976
- if (file instanceof Error) continue;
3977
3833
  refs.push(file);
3978
3834
  }
3979
3835
  return refs;
@@ -4009,63 +3865,61 @@ var DocDirectoryReference = class _DocDirectoryReference {
4009
3865
  async readFiles() {
4010
3866
  const entities = [];
4011
3867
  for await (const file of this.filesGenerator()) {
4012
- const entity = await file.read();
4013
- if (entity instanceof Error) continue;
4014
- entities.push(entity);
3868
+ try {
3869
+ const entity = await file.read();
3870
+ entities.push(entity);
3871
+ } catch {
3872
+ continue;
3873
+ }
4015
3874
  }
4016
3875
  return entities;
4017
3876
  }
4018
3877
  async readMdFiles() {
4019
3878
  const entities = [];
4020
3879
  for await (const file of this.filesGenerator()) {
4021
- const entity = await file.read();
4022
- if (entity instanceof Error) continue;
4023
- if (entity instanceof DocFileUnknownEntity) continue;
4024
- entities.push(entity);
3880
+ try {
3881
+ const entity = await file.read();
3882
+ if (entity instanceof DocFileUnknownEntity) continue;
3883
+ entities.push(entity);
3884
+ } catch {
3885
+ continue;
3886
+ }
4025
3887
  }
4026
3888
  return entities;
4027
3889
  }
4028
3890
  async readUnknownFiles() {
4029
3891
  const entities = [];
4030
3892
  for await (const file of this.filesGenerator()) {
4031
- const entity = await file.read();
4032
- if (entity instanceof Error) continue;
4033
- if (entity instanceof DocFileMdEntity) continue;
4034
- entities.push(entity);
3893
+ try {
3894
+ const entity = await file.read();
3895
+ if (entity instanceof DocFileMdEntity) continue;
3896
+ entities.push(entity);
3897
+ } catch {
3898
+ continue;
3899
+ }
4035
3900
  }
4036
3901
  return entities;
4037
3902
  }
4038
- /**
4039
- * Get list of subdirectory names
4040
- */
4041
3903
  async directoryNames() {
4042
- const allFileNames = await this.fileSystem.readDirectoryFileNames(
4043
- this.relativePath
4044
- );
3904
+ const allFileNames = await this.fileSystem.readDirectoryFileNames(this.relativePath);
4045
3905
  if (allFileNames instanceof Error) {
4046
3906
  return [];
4047
3907
  }
4048
- const directoryNames = [];
3908
+ const names = [];
4049
3909
  for (const fileName of allFileNames) {
4050
- if (fileName.startsWith(this.archiveDirectoryName)) continue;
3910
+ if (fileName === this.archiveDirectoryName) continue;
4051
3911
  if (this.props.config.directoryExcludes.includes(fileName)) continue;
4052
3912
  const filePath = this.pathSystem.join(this.relativePath, fileName);
4053
3913
  const isDirectory = await this.fileSystem.isDirectory(filePath);
4054
3914
  if (isDirectory) {
4055
- directoryNames.push(fileName);
3915
+ names.push(fileName);
4056
3916
  }
4057
3917
  }
4058
- return directoryNames;
3918
+ return names;
4059
3919
  }
4060
- /**
4061
- * Get subdirectory references
4062
- */
4063
3920
  async directories() {
4064
- const directoryNames = await this.directoryNames();
4065
- if (directoryNames instanceof Error) {
4066
- return [];
4067
- }
4068
- return directoryNames.map((dirName) => {
3921
+ const names = await this.directoryNames();
3922
+ return names.map((dirName) => {
4069
3923
  const dirPath = this.pathSystem.join(this.relativePath, dirName);
4070
3924
  return new _DocDirectoryReference({
4071
3925
  path: dirPath,
@@ -4114,10 +3968,7 @@ var DocDirectoryReference = class _DocDirectoryReference {
4114
3968
  return this.indexFile().read();
4115
3969
  }
4116
3970
  async writeFile(entity) {
4117
- const filePath = this.pathSystem.join(
4118
- this.relativePath,
4119
- entity.value.path.nameWithExtension
4120
- );
3971
+ const filePath = this.pathSystem.join(this.relativePath, entity.value.path.nameWithExtension);
4121
3972
  let content = null;
4122
3973
  if (entity instanceof DocFileUnknownEntity) {
4123
3974
  content = entity.value.content;
@@ -4129,20 +3980,16 @@ var DocDirectoryReference = class _DocDirectoryReference {
4129
3980
  content = entity.content().toText();
4130
3981
  }
4131
3982
  if (content === null) {
4132
- return new Error("Entity content is undefined");
3983
+ throw new Error("Entity content is undefined");
4133
3984
  }
4134
3985
  const writeResult = await this.fileSystem.writeFile(filePath, content);
4135
3986
  if (writeResult instanceof Error) {
4136
- return writeResult;
3987
+ throw writeResult;
4137
3988
  }
4138
- return null;
4139
3989
  }
4140
3990
  async exists() {
4141
3991
  return await this.fileSystem.exists(this.relativePath);
4142
3992
  }
4143
- /**
4144
- * Create new Markdown file
4145
- */
4146
3993
  async createMdFile(fileName) {
4147
3994
  const actualFileName = fileName || this.uniqueFileName("document");
4148
3995
  const mdFileName = actualFileName.endsWith(".md") ? actualFileName : `${actualFileName}.md`;
@@ -4154,15 +4001,9 @@ var DocDirectoryReference = class _DocDirectoryReference {
4154
4001
  pathSystem: this.pathSystem,
4155
4002
  config: this.props.config
4156
4003
  });
4157
- const writeResult = await fileRef.writeDefault();
4158
- if (writeResult instanceof Error) {
4159
- throw writeResult;
4160
- }
4004
+ await fileRef.writeDefault();
4161
4005
  return fileRef;
4162
4006
  }
4163
- /**
4164
- * Generate unique filename
4165
- */
4166
4007
  uniqueFileName(prefix = "document") {
4167
4008
  const [uuid] = crypto.randomUUID().split("-");
4168
4009
  return `${prefix}-${uuid}.md`;
@@ -4179,6 +4020,9 @@ var DocFileMdReference = class _DocFileMdReference {
4179
4020
  }
4180
4021
  pathSystem;
4181
4022
  customSchema;
4023
+ get safe() {
4024
+ return createSafeProxy(this);
4025
+ }
4182
4026
  get fileSystem() {
4183
4027
  return this.props.fileSystem;
4184
4028
  }
@@ -4215,21 +4059,18 @@ var DocFileMdReference = class _DocFileMdReference {
4215
4059
  async read() {
4216
4060
  const content = await this.fileSystem.readFile(this.path);
4217
4061
  if (content instanceof Error) {
4218
- return content;
4062
+ throw content;
4219
4063
  }
4220
4064
  const actualPath = this.path;
4221
4065
  if (content === null) {
4222
4066
  const archivedContent = await this.fileSystem.readFile(this.archivedPath);
4223
4067
  if (archivedContent instanceof Error) {
4224
- return archivedContent;
4068
+ throw archivedContent;
4225
4069
  }
4226
4070
  if (archivedContent !== null) {
4227
- const contentValue2 = DocFileMdContentValue.fromMarkdown(
4228
- archivedContent,
4229
- this.customSchema
4230
- );
4071
+ const contentValue2 = DocFileMdContentValue.fromMarkdown(archivedContent, this.customSchema);
4231
4072
  const pathValue2 = DocFilePathValue.fromPathWithSystem(
4232
- actualPath,
4073
+ this.archivedPath,
4233
4074
  this.pathSystem,
4234
4075
  this.basePath
4235
4076
  );
@@ -4245,12 +4086,9 @@ var DocFileMdReference = class _DocFileMdReference {
4245
4086
  }
4246
4087
  }
4247
4088
  if (content === null) {
4248
- return new Error(`File not found at ${this.path} or in archive.`);
4089
+ throw new Error(`File not found at ${this.path} or in archive.`);
4249
4090
  }
4250
- const contentValue = DocFileMdContentValue.fromMarkdown(
4251
- content,
4252
- this.customSchema
4253
- );
4091
+ const contentValue = DocFileMdContentValue.fromMarkdown(content, this.customSchema);
4254
4092
  const pathValue = DocFilePathValue.fromPathWithSystem(
4255
4093
  actualPath,
4256
4094
  this.pathSystem,
@@ -4267,14 +4105,8 @@ var DocFileMdReference = class _DocFileMdReference {
4267
4105
  this.customSchema
4268
4106
  );
4269
4107
  }
4270
- /**
4271
- * Read file content
4272
- */
4273
4108
  async readText() {
4274
4109
  const entity = await this.read();
4275
- if (entity instanceof Error) {
4276
- return entity;
4277
- }
4278
4110
  return entity.value.content.body;
4279
4111
  }
4280
4112
  /**
@@ -4282,11 +4114,7 @@ var DocFileMdReference = class _DocFileMdReference {
4282
4114
  */
4283
4115
  empty() {
4284
4116
  const contentValue = DocFileMdContentValue.empty("", this.customSchema);
4285
- const pathValue = DocFilePathValue.fromPathWithSystem(
4286
- this.path,
4287
- this.pathSystem,
4288
- this.basePath
4289
- );
4117
+ const pathValue = DocFilePathValue.fromPathWithSystem(this.path, this.pathSystem, this.basePath);
4290
4118
  return new DocFileMdEntity(
4291
4119
  {
4292
4120
  type: "markdown",
@@ -4297,65 +4125,50 @@ var DocFileMdReference = class _DocFileMdReference {
4297
4125
  this.customSchema
4298
4126
  );
4299
4127
  }
4300
- /**
4301
- * Write entity
4302
- */
4303
4128
  async write(entity) {
4304
4129
  const content = entity.content().toText();
4305
4130
  const writeResult = await this.fileSystem.writeFile(this.path, content);
4306
4131
  if (writeResult instanceof Error) {
4307
- return writeResult;
4132
+ throw writeResult;
4308
4133
  }
4309
- return null;
4310
4134
  }
4311
4135
  async writeText(text) {
4312
- return await this.fileSystem.writeFile(this.path, text);
4136
+ const writeResult = await this.fileSystem.writeFile(this.path, text);
4137
+ if (writeResult instanceof Error) {
4138
+ throw writeResult;
4139
+ }
4313
4140
  }
4314
- /**
4315
- * Create new file with default content
4316
- */
4317
4141
  async writeDefault() {
4318
4142
  const fileName = this.pathSystem.basename(this.path, ".md");
4319
- const defaultContent = [
4320
- `# ${fileName}`,
4321
- "",
4322
- "Write your content here."
4323
- ].join("\n");
4324
- 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
+ }
4325
4148
  }
4326
- /**
4327
- * Delete file
4328
- */
4329
4149
  async delete() {
4330
- return await this.fileSystem.deleteFile(this.path);
4150
+ const deleteResult = await this.fileSystem.deleteFile(this.path);
4151
+ if (deleteResult instanceof Error) {
4152
+ throw deleteResult;
4153
+ }
4331
4154
  }
4332
- /**
4333
- * Copy file
4334
- */
4335
4155
  async copyTo(destinationPath) {
4336
- return await this.fileSystem.copyFile(this.path, destinationPath);
4156
+ const copyResult = await this.fileSystem.copyFile(this.path, destinationPath);
4157
+ if (copyResult instanceof Error) {
4158
+ throw copyResult;
4159
+ }
4337
4160
  }
4338
- /**
4339
- * Move file
4340
- */
4341
4161
  async moveTo(destinationPath) {
4342
- return await this.fileSystem.moveFile(this.path, destinationPath);
4162
+ const moveResult = await this.fileSystem.moveFile(this.path, destinationPath);
4163
+ if (moveResult instanceof Error) {
4164
+ throw moveResult;
4165
+ }
4343
4166
  }
4344
- /**
4345
- * Move file to archive and return new reference
4346
- */
4347
4167
  async archive(archiveDirectoryName = this.props.config.archiveDirectoryName) {
4348
4168
  const dirPath = this.pathSystem.dirname(this.path);
4349
4169
  const fileName = this.pathSystem.basename(this.path);
4350
- const archivePath = this.pathSystem.join(
4351
- dirPath,
4352
- archiveDirectoryName,
4353
- fileName
4354
- );
4355
- const moveResult = await this.moveTo(archivePath);
4356
- if (moveResult instanceof Error) {
4357
- throw moveResult;
4358
- }
4170
+ const archivePath = this.pathSystem.join(dirPath, archiveDirectoryName, fileName);
4171
+ await this.moveTo(archivePath);
4359
4172
  return new _DocFileMdReference({
4360
4173
  path: archivePath,
4361
4174
  fileSystem: this.fileSystem,
@@ -4364,9 +4177,6 @@ var DocFileMdReference = class _DocFileMdReference {
4364
4177
  config: this.props.config
4365
4178
  });
4366
4179
  }
4367
- /**
4368
- * Restore file from archive and return new reference
4369
- */
4370
4180
  async restore(archiveDirectoryName = this.props.config.archiveDirectoryName) {
4371
4181
  const dirPath = this.pathSystem.dirname(this.path);
4372
4182
  const parentDirName = this.pathSystem.basename(dirPath);
@@ -4374,14 +4184,8 @@ var DocFileMdReference = class _DocFileMdReference {
4374
4184
  throw new Error(`File is not in archive directory: ${this.path}`);
4375
4185
  }
4376
4186
  const fileName = this.pathSystem.basename(this.path);
4377
- const restorePath = this.pathSystem.join(
4378
- this.pathSystem.dirname(dirPath),
4379
- fileName
4380
- );
4381
- const moveResult = await this.moveTo(restorePath);
4382
- if (moveResult instanceof Error) {
4383
- throw moveResult;
4384
- }
4187
+ const restorePath = this.pathSystem.join(this.pathSystem.dirname(dirPath), fileName);
4188
+ await this.moveTo(restorePath);
4385
4189
  return new _DocFileMdReference({
4386
4190
  path: restorePath,
4387
4191
  fileSystem: this.fileSystem,
@@ -4390,23 +4194,26 @@ var DocFileMdReference = class _DocFileMdReference {
4390
4194
  config: this.props.config
4391
4195
  });
4392
4196
  }
4393
- /**
4394
- * Get file size in bytes
4395
- */
4396
4197
  async size() {
4397
- return this.fileSystem.getFileSize(this.path);
4198
+ const fileSize = await this.fileSystem.getFileSize(this.path);
4199
+ if (fileSize instanceof Error) {
4200
+ throw fileSize;
4201
+ }
4202
+ return fileSize;
4398
4203
  }
4399
- /**
4400
- * Get file last modified time
4401
- */
4402
4204
  async lastModified() {
4403
- return this.fileSystem.getFileUpdatedTime(this.path);
4205
+ const updatedTime = await this.fileSystem.getFileUpdatedTime(this.path);
4206
+ if (updatedTime instanceof Error) {
4207
+ throw updatedTime;
4208
+ }
4209
+ return updatedTime;
4404
4210
  }
4405
- /**
4406
- * Get file creation time
4407
- */
4408
4211
  async createdAt() {
4409
- return this.fileSystem.getFileCreatedTime(this.path);
4212
+ const createdTime = await this.fileSystem.getFileCreatedTime(this.path);
4213
+ if (createdTime instanceof Error) {
4214
+ throw createdTime;
4215
+ }
4216
+ return createdTime;
4410
4217
  }
4411
4218
  directory() {
4412
4219
  const paths = this.directoryPath.split(this.pathSystem.separator);
@@ -4432,15 +4239,9 @@ var DocFileMdReference = class _DocFileMdReference {
4432
4239
  config: this.props.config
4433
4240
  });
4434
4241
  }
4435
- /**
4436
- * Get relation based on schema
4437
- */
4438
4242
  async relation(key, targetSchema) {
4439
4243
  const file = await this.read();
4440
- if (file instanceof Error) {
4441
- return file;
4442
- }
4443
- const relationValue = file.content().meta().field(key);
4244
+ const relationValue = file.content().meta().relation(key);
4444
4245
  if (relationValue === null) {
4445
4246
  return null;
4446
4247
  }
@@ -4449,40 +4250,37 @@ var DocFileMdReference = class _DocFileMdReference {
4449
4250
  return null;
4450
4251
  }
4451
4252
  const indexFile = await indexRef.read();
4452
- if (indexFile instanceof Error) {
4453
- return null;
4454
- }
4455
4253
  const schemaValue = indexFile.content.meta().schema();
4456
- const fieldValue = schemaValue.value[key];
4254
+ const fieldValue = schemaValue.value[String(key)];
4457
4255
  if (!fieldValue || fieldValue.type !== "relation") {
4458
4256
  return null;
4459
4257
  }
4460
- const schemaField = schemaValue.field(
4461
- key
4462
- );
4463
- const relationField = schemaField;
4464
- let resolvedPath = relationField.path;
4465
- if (relationField.path.startsWith("..")) {
4466
- resolvedPath = this.pathSystem.join(
4467
- this.directoryPath,
4468
- relationField.path
4469
- );
4470
- resolvedPath = this.pathSystem.normalize(resolvedPath);
4471
- }
4258
+ const relationField = schemaValue.relation(key);
4259
+ const resolvedPath = this.resolveRelationDirectory(relationField.path);
4472
4260
  const fullPath = this.pathSystem.join(resolvedPath, `${relationValue}.md`);
4473
4261
  return new _DocFileMdReference({
4474
4262
  path: fullPath,
4475
4263
  fileSystem: this.fileSystem,
4476
4264
  pathSystem: this.pathSystem,
4477
- customSchema: targetSchema || {},
4265
+ customSchema: targetSchema ?? {},
4478
4266
  config: this.props.config
4479
4267
  });
4480
4268
  }
4481
4269
  /**
4482
- * Get index.md in the same directory
4270
+ * スキーマで定義された relation の path を解決する。
4271
+ * ".." 始まりの相対パスはファイルのディレクトリ基準で正規化する
4483
4272
  */
4273
+ resolveRelationDirectory(schemaPath) {
4274
+ if (schemaPath.startsWith("..")) {
4275
+ return this.pathSystem.normalize(this.pathSystem.join(this.directoryPath, schemaPath));
4276
+ }
4277
+ return schemaPath;
4278
+ }
4484
4279
  async directoryIndex() {
4485
- const indexPath = this.pathSystem.join(this.directoryPath, "index.md");
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);
4486
4284
  const exists = await this.fileSystem.exists(indexPath);
4487
4285
  if (exists) {
4488
4286
  return new DocFileIndexReference({
@@ -4493,10 +4291,21 @@ var DocFileMdReference = class _DocFileMdReference {
4493
4291
  config: this.props.config
4494
4292
  });
4495
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
+ }
4496
4305
  const archivedIndexPath = this.pathSystem.join(
4497
4306
  this.directoryPath,
4498
- "_",
4499
- "index.md"
4307
+ archiveDirectoryName,
4308
+ indexFileName
4500
4309
  );
4501
4310
  const archivedExists = await this.fileSystem.exists(archivedIndexPath);
4502
4311
  if (archivedExists) {
@@ -4510,20 +4319,9 @@ var DocFileMdReference = class _DocFileMdReference {
4510
4319
  }
4511
4320
  return null;
4512
4321
  }
4513
- /**
4514
- * Get multiple relations based on schema
4515
- */
4516
4322
  async relations(key, customSchema) {
4517
4323
  const file = await this.read();
4518
- if (file instanceof Error) {
4519
- return [];
4520
- }
4521
- const meta = file.content().meta();
4522
- const schemaField = meta.schemaField(key);
4523
- if (schemaField.type !== "multi-relation") {
4524
- return [];
4525
- }
4526
- const fileNames = meta.multiRelation(key);
4324
+ const fileNames = file.content().meta().multiRelation(key);
4527
4325
  if (fileNames === null) {
4528
4326
  return [];
4529
4327
  }
@@ -4532,41 +4330,30 @@ var DocFileMdReference = class _DocFileMdReference {
4532
4330
  return [];
4533
4331
  }
4534
4332
  const indexFile = await indexRef.read();
4535
- if (indexFile instanceof Error) {
4333
+ const indexSchema = indexFile.content.meta().schema();
4334
+ const fieldValue = indexSchema.value[String(key)];
4335
+ if (!fieldValue || fieldValue.type !== "multi-relation") {
4536
4336
  return [];
4537
4337
  }
4538
- const indexSchema = indexFile.content.meta().schema();
4539
4338
  const indexSchemaField = indexSchema.multiRelation(key);
4339
+ const resolvedPath = this.resolveRelationDirectory(indexSchemaField.path);
4540
4340
  return fileNames.map((fileName) => {
4541
- const resolvedPath = indexSchemaField.path;
4542
4341
  const fullPath = this.pathSystem.join(resolvedPath, `${fileName}.md`);
4543
4342
  return new _DocFileMdReference({
4544
4343
  path: fullPath,
4545
4344
  fileSystem: this.fileSystem,
4546
4345
  pathSystem: this.pathSystem,
4547
- customSchema: customSchema || {},
4346
+ customSchema: customSchema ?? {},
4548
4347
  config: this.props.config
4549
4348
  });
4550
4349
  });
4551
4350
  }
4552
- /**
4553
- * File: Markdown > FrontMatter
4554
- */
4555
4351
  async readFrontMatter() {
4556
4352
  const entity = await this.read();
4557
- if (entity instanceof Error) {
4558
- return entity;
4559
- }
4560
4353
  return entity.content().meta();
4561
4354
  }
4562
- /**
4563
- * File: Markdown > FrontMatter
4564
- */
4565
4355
  async updateFrontMatter(key, value) {
4566
4356
  const entity = await this.read();
4567
- if (entity instanceof Error) {
4568
- return entity;
4569
- }
4570
4357
  const frontMatter = entity.content().meta();
4571
4358
  const draftFrontMatter = frontMatter.withProperty(key, value);
4572
4359
  const draftContent = entity.content().withMeta(draftFrontMatter);
@@ -4715,6 +4502,8 @@ var DocFileTreeSystem = class {
4715
4502
  for (const fileName of fileNames) {
4716
4503
  if (fileName === this.props.archiveDirectoryName) continue;
4717
4504
  if (this.config.directoryExcludes.includes(fileName)) continue;
4505
+ const metaFileName = this.config.metaFileName ?? ".meta.json";
4506
+ if (fileName === metaFileName) continue;
4718
4507
  const filePath = directoryPath ? this.props.pathSystem.join(directoryPath, fileName) : fileName;
4719
4508
  const isDirectory = await this.props.fileSystem.isDirectory(filePath);
4720
4509
  if (!isDirectory) {
@@ -4725,7 +4514,7 @@ var DocFileTreeSystem = class {
4725
4514
  results.push(fileNode);
4726
4515
  continue;
4727
4516
  }
4728
- const directoryNode = await this.createDirectoryNode(fileName, filePath);
4517
+ const directoryNode = await this.createDirectoryNode(fileName, filePath, false);
4729
4518
  if (directoryNode instanceof Error) {
4730
4519
  return directoryNode;
4731
4520
  }
@@ -4737,58 +4526,70 @@ var DocFileTreeSystem = class {
4737
4526
  * Create file node
4738
4527
  */
4739
4528
  async createFileNode(fileName, filePath) {
4740
- let title = fileName;
4741
- let icon = "";
4742
- if (fileName.endsWith(".md")) {
4743
- const mdFile = this.createMdFileReference(filePath);
4744
- if (await mdFile.exists()) {
4745
- const entity = await mdFile.read();
4746
- if (!(entity instanceof Error)) {
4747
- title = entity.value.content.title || fileName;
4748
- }
4749
- }
4750
- icon = "\u{1F4C4}";
4751
- } else {
4752
- icon = "\u{1F4C4}";
4753
- }
4529
+ const title = await this.readFileTitle(fileName, filePath);
4754
4530
  return DocTreeFileNodeValue.from({
4755
4531
  name: fileName,
4756
4532
  path: filePath,
4757
- icon,
4533
+ icon: "\u{1F4C4}",
4758
4534
  title
4759
4535
  });
4760
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
+ }
4761
4555
  /**
4762
4556
  * Create directory node
4763
4557
  */
4764
- async createDirectoryNode(fileName, filePath) {
4765
- let title = fileName;
4766
- let icon = this.config.defaultIndexIcon;
4767
- const indexFile = this.createIndexFileReference(filePath);
4768
- if (await indexFile.exists()) {
4769
- const entity = await indexFile.read();
4770
- if (entity instanceof Error) {
4771
- return entity;
4772
- }
4773
- title = entity.value.content.title || fileName;
4774
- const content = entity.content;
4775
- const frontMatter = content.meta();
4776
- if (frontMatter) {
4777
- icon = frontMatter.icon || this.config.defaultIndexIcon;
4778
- }
4558
+ async createDirectoryNode(fileName, filePath, directoryOnly) {
4559
+ const indexInfo = await this.readDirectoryIndexInfo(fileName, filePath);
4560
+ if (indexInfo instanceof Error) {
4561
+ return indexInfo;
4779
4562
  }
4780
- const children = await this.buildFileTree(filePath);
4563
+ const children = directoryOnly ? await this.buildDirectoryTree(filePath) : await this.buildFileTree(filePath);
4781
4564
  if (children instanceof Error) {
4782
4565
  return children;
4783
4566
  }
4784
4567
  return DocTreeDirectoryNodeValue.from({
4785
4568
  name: fileName,
4786
4569
  path: filePath,
4787
- icon,
4788
- title,
4570
+ icon: indexInfo.icon,
4571
+ title: indexInfo.title,
4789
4572
  children
4790
4573
  });
4791
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
+ }
4792
4593
  /**
4793
4594
  * Create index file reference
4794
4595
  */
@@ -4826,13 +4627,12 @@ var DocFileTreeSystem = class {
4826
4627
  for (const fileName of fileNames) {
4827
4628
  if (fileName === this.props.archiveDirectoryName) continue;
4828
4629
  if (this.config.directoryExcludes.includes(fileName)) continue;
4630
+ const metaFileName = this.config.metaFileName ?? ".meta.json";
4631
+ if (fileName === metaFileName) continue;
4829
4632
  const filePath = directoryPath ? this.props.pathSystem.join(directoryPath, fileName) : fileName;
4830
4633
  const isDirectory = await this.props.fileSystem.isDirectory(filePath);
4831
4634
  if (!isDirectory) continue;
4832
- const directoryNode = await this.createDirectoryNodeForTree(
4833
- fileName,
4834
- filePath
4835
- );
4635
+ const directoryNode = await this.createDirectoryNode(fileName, filePath, true);
4836
4636
  if (directoryNode instanceof Error) {
4837
4637
  return directoryNode;
4838
4638
  }
@@ -4840,42 +4640,16 @@ var DocFileTreeSystem = class {
4840
4640
  }
4841
4641
  return results;
4842
4642
  }
4843
- /**
4844
- * Create directory node for directory tree
4845
- */
4846
- async createDirectoryNodeForTree(fileName, filePath) {
4847
- let title = fileName;
4848
- let icon = this.config.defaultIndexIcon;
4849
- const indexFile = this.createIndexFileReference(filePath);
4850
- if (await indexFile.exists()) {
4851
- const entity = await indexFile.read();
4852
- if (entity instanceof Error) {
4853
- return entity;
4854
- }
4855
- title = entity.value.content.title || fileName;
4856
- const content = entity.content;
4857
- const frontMatter = content.meta();
4858
- if (frontMatter && typeof frontMatter === "object" && "icon" in frontMatter) {
4859
- icon = frontMatter.icon || this.config.defaultIndexIcon;
4860
- }
4861
- }
4862
- const children = await this.buildDirectoryTree(filePath);
4863
- if (children instanceof Error) {
4864
- return children;
4865
- }
4866
- return DocTreeDirectoryNodeValue.from({
4867
- name: fileName,
4868
- path: filePath,
4869
- icon,
4870
- title,
4871
- children
4872
- });
4873
- }
4874
4643
  };
4875
4644
 
4876
4645
  // lib/modules/path-system/doc-path-system.ts
4877
- var DocPathSystem = class {
4646
+ var DocPathSystem = class _DocPathSystem {
4878
4647
  separator = "/";
4648
+ constructor() {
4649
+ if (new.target === _DocPathSystem) {
4650
+ Object.freeze(this);
4651
+ }
4652
+ }
4879
4653
  /**
4880
4654
  * Join paths
4881
4655
  */
@@ -4931,8 +4705,8 @@ var DocPathSystem = class {
4931
4705
  * Calculate relative path
4932
4706
  */
4933
4707
  relative(from, to) {
4934
- const fromSegments = from.split(this.separator).filter(Boolean);
4935
- const toSegments = to.split(this.separator).filter(Boolean);
4708
+ const fromSegments = from.split(this.separator).filter((s) => s !== "" && s !== ".");
4709
+ const toSegments = to.split(this.separator).filter((s) => s !== "" && s !== ".");
4936
4710
  let commonLength = 0;
4937
4711
  for (let i = 0; i < Math.min(fromSegments.length, toSegments.length); i++) {
4938
4712
  if (fromSegments[i] === toSegments[i]) {
@@ -5010,9 +4784,10 @@ var DocClient = class {
5010
4784
  archiveDirectoryName: "_",
5011
4785
  defaultDirectoryName: "Directory",
5012
4786
  indexMetaIncludes: [],
5013
- directoryExcludes: [".vitepress"]
4787
+ directoryExcludes: [".vitepress"],
4788
+ metaFileName: ".meta.json"
5014
4789
  };
5015
- this.config = props.config ? zDocClientConfig.parse(props.config) : defaultConfig;
4790
+ this.config = zDocClientConfig.parse({ ...defaultConfig, ...props.config });
5016
4791
  const fileTreeSystem = new DocFileTreeSystem({
5017
4792
  fileSystem: this.fileSystem,
5018
4793
  pathSystem: this.pathSystem,
@@ -5021,17 +4796,21 @@ var DocClient = class {
5021
4796
  config: this.config
5022
4797
  });
5023
4798
  this.fileTreeSystem = props.fileTreeSystem ?? fileTreeSystem;
4799
+ Object.freeze(this);
4800
+ }
4801
+ get safe() {
4802
+ return createSafeProxy(this);
5024
4803
  }
5025
4804
  basePath() {
5026
4805
  return this.fileSystem.getBasePath();
5027
4806
  }
5028
- /**
5029
- * Get file reference
5030
- */
5031
4807
  file(relativePath, customSchema) {
5032
4808
  const fileName = this.pathSystem.basename(relativePath);
5033
4809
  if (fileName === this.config.indexFileName) {
5034
4810
  const dirPath = this.pathSystem.dirname(relativePath);
4811
+ if (customSchema === void 0) {
4812
+ return this.indexFile(dirPath === "." ? "" : dirPath);
4813
+ }
5035
4814
  return this.indexFile(dirPath === "." ? "" : dirPath, customSchema);
5036
4815
  }
5037
4816
  if (relativePath.endsWith(".md")) {
@@ -5048,9 +4827,6 @@ var DocClient = class {
5048
4827
  customSchema: {}
5049
4828
  });
5050
4829
  }
5051
- /**
5052
- * Markdown file reference
5053
- */
5054
4830
  mdFile(relativePath, customSchema) {
5055
4831
  const normalizedPath = relativePath.endsWith(".md") ? relativePath : `${relativePath}.md`;
5056
4832
  if (customSchema === void 0) {
@@ -5070,9 +4846,6 @@ var DocClient = class {
5070
4846
  config: this.config
5071
4847
  });
5072
4848
  }
5073
- /**
5074
- * Index file reference
5075
- */
5076
4849
  indexFile(relativePath, customSchema) {
5077
4850
  const indexPath = relativePath === "" ? this.config.indexFileName : `${relativePath}/${this.config.indexFileName}`;
5078
4851
  if (customSchema === void 0) {
@@ -5092,9 +4865,6 @@ var DocClient = class {
5092
4865
  config: this.config
5093
4866
  });
5094
4867
  }
5095
- /**
5096
- * Directory reference
5097
- */
5098
4868
  directory(relativePath, customSchema) {
5099
4869
  if (customSchema === void 0) {
5100
4870
  return new DocDirectoryReference({
@@ -5118,18 +4888,18 @@ var DocClient = class {
5118
4888
  });
5119
4889
  }
5120
4890
  async fileTree(directoryPath = "") {
5121
- const results = await this.fileTreeSystem.buildFileTree(directoryPath);
5122
- if (results instanceof Error) {
5123
- throw results;
4891
+ const treeNodes = await this.fileTreeSystem.buildFileTree(directoryPath);
4892
+ if (treeNodes instanceof Error) {
4893
+ throw treeNodes;
5124
4894
  }
5125
- return results.map((node) => node.toJson());
4895
+ return treeNodes.map((node) => node.toJson());
5126
4896
  }
5127
4897
  async directoryTree(directoryPath = "") {
5128
- const results = await this.fileTreeSystem.buildDirectoryTree(directoryPath);
5129
- if (results instanceof Error) {
5130
- throw results;
4898
+ const treeNodes = await this.fileTreeSystem.buildDirectoryTree(directoryPath);
4899
+ if (treeNodes instanceof Error) {
4900
+ throw treeNodes;
5131
4901
  }
5132
- return results.map((node) => node.toJson());
4902
+ return treeNodes.map((node) => node.toJson());
5133
4903
  }
5134
4904
  };
5135
4905
 
@@ -5340,7 +5110,7 @@ var DocCustomSchemaFieldValue = class {
5340
5110
  return zDocMetaFieldText.parse(value);
5341
5111
  } catch {
5342
5112
  if (this.value.required) {
5343
- return DocMetaFieldTextValue.defaultValue();
5113
+ throw new Error(`required field "${this.fieldType()}" is missing or invalid`);
5344
5114
  }
5345
5115
  return null;
5346
5116
  }
@@ -5350,7 +5120,7 @@ var DocCustomSchemaFieldValue = class {
5350
5120
  return zDocMetaFieldNumber.parse(value);
5351
5121
  } catch {
5352
5122
  if (this.value.required) {
5353
- return DocMetaFieldNumberValue.defaultValue();
5123
+ throw new Error(`required field "${this.fieldType()}" is missing or invalid`);
5354
5124
  }
5355
5125
  return null;
5356
5126
  }
@@ -5360,7 +5130,7 @@ var DocCustomSchemaFieldValue = class {
5360
5130
  return zDocMetaFieldBoolean.parse(value);
5361
5131
  } catch {
5362
5132
  if (this.value.required) {
5363
- return DocMetaFieldBooleanValue.defaultValue();
5133
+ throw new Error(`required field "${this.fieldType()}" is missing or invalid`);
5364
5134
  }
5365
5135
  return null;
5366
5136
  }
@@ -5370,7 +5140,7 @@ var DocCustomSchemaFieldValue = class {
5370
5140
  return zDocMetaFieldSelectText.parse(value);
5371
5141
  } catch {
5372
5142
  if (this.value.required) {
5373
- return DocMetaFieldSelectTextValue.defaultValue();
5143
+ throw new Error(`required field "${this.fieldType()}" is missing or invalid`);
5374
5144
  }
5375
5145
  return null;
5376
5146
  }
@@ -5380,7 +5150,7 @@ var DocCustomSchemaFieldValue = class {
5380
5150
  return zDocMetaFieldSelectNumber.parse(value);
5381
5151
  } catch {
5382
5152
  if (this.value.required) {
5383
- return DocMetaFieldSelectNumberValue.defaultValue();
5153
+ throw new Error(`required field "${this.fieldType()}" is missing or invalid`);
5384
5154
  }
5385
5155
  return null;
5386
5156
  }
@@ -5390,7 +5160,7 @@ var DocCustomSchemaFieldValue = class {
5390
5160
  return zDocMetaFieldRelation.parse(value);
5391
5161
  } catch {
5392
5162
  if (this.value.required) {
5393
- return DocMetaFieldRelationValue.defaultValue();
5163
+ throw new Error(`required field "${this.fieldType()}" is missing or invalid`);
5394
5164
  }
5395
5165
  return null;
5396
5166
  }
@@ -5400,7 +5170,7 @@ var DocCustomSchemaFieldValue = class {
5400
5170
  return zDocMetaFieldMultiText.parse(value);
5401
5171
  } catch {
5402
5172
  if (this.value.required) {
5403
- return DocMetaFieldMultiTextValue.defaultValue();
5173
+ throw new Error(`required field "${this.fieldType()}" is missing or invalid`);
5404
5174
  }
5405
5175
  return null;
5406
5176
  }
@@ -5410,7 +5180,7 @@ var DocCustomSchemaFieldValue = class {
5410
5180
  return zDocMetaFieldMultiNumber.parse(value);
5411
5181
  } catch {
5412
5182
  if (this.value.required) {
5413
- return DocMetaFieldMultiNumberValue.defaultValue();
5183
+ throw new Error(`required field "${this.fieldType()}" is missing or invalid`);
5414
5184
  }
5415
5185
  return null;
5416
5186
  }
@@ -5420,7 +5190,7 @@ var DocCustomSchemaFieldValue = class {
5420
5190
  return zDocMetaFieldMultiSelectText.parse(value);
5421
5191
  } catch {
5422
5192
  if (this.value.required) {
5423
- return DocMetaFieldMultiSelectTextValue.defaultValue();
5193
+ throw new Error(`required field "${this.fieldType()}" is missing or invalid`);
5424
5194
  }
5425
5195
  return null;
5426
5196
  }
@@ -5430,7 +5200,7 @@ var DocCustomSchemaFieldValue = class {
5430
5200
  return zDocMetaFieldMultiSelectNumber.parse(value);
5431
5201
  } catch {
5432
5202
  if (this.value.required) {
5433
- return DocMetaFieldMultiSelectNumberValue.defaultValue();
5203
+ throw new Error(`required field "${this.fieldType()}" is missing or invalid`);
5434
5204
  }
5435
5205
  return null;
5436
5206
  }
@@ -5440,13 +5210,16 @@ var DocCustomSchemaFieldValue = class {
5440
5210
  return zDocMetaFieldMultiRelation.parse(value);
5441
5211
  } catch {
5442
5212
  if (this.value.required) {
5443
- return DocMetaFieldMultiRelationValue.defaultValue();
5213
+ throw new Error(`required field "${this.fieldType()}" is missing or invalid`);
5444
5214
  }
5445
5215
  return null;
5446
5216
  }
5447
5217
  }
5448
5218
  throw new Error("Unknown field type");
5449
5219
  }
5220
+ fieldType() {
5221
+ return this.value.type;
5222
+ }
5450
5223
  };
5451
5224
 
5452
5225
  // lib/values/doc-directory-path-value.ts
@@ -5454,6 +5227,7 @@ var DocDirectoryPathValue = class _DocDirectoryPathValue {
5454
5227
  constructor(value, pathSystem) {
5455
5228
  this.value = value;
5456
5229
  this.pathSystem = pathSystem;
5230
+ Object.freeze(this.value);
5457
5231
  Object.freeze(this);
5458
5232
  }
5459
5233
  /**
@@ -5590,7 +5364,7 @@ var DocDirectoryPathValue = class _DocDirectoryPathValue {
5590
5364
  * Export as JSON format
5591
5365
  */
5592
5366
  toJson() {
5593
- return this.value;
5367
+ return { ...this.value };
5594
5368
  }
5595
5369
  /**
5596
5370
  * Check if paths are equal
@@ -5603,7 +5377,7 @@ var DocDirectoryPathValue = class _DocDirectoryPathValue {
5603
5377
  */
5604
5378
  contains(other) {
5605
5379
  const relative = this.pathSystem.relative(this.path, other.path);
5606
- return !relative.startsWith("..") && relative !== "";
5380
+ return !relative.startsWith("..") && relative !== "" && relative !== ".";
5607
5381
  }
5608
5382
  };
5609
5383
 
@@ -5687,4 +5461,4 @@ var DocRelationFieldValue = class _DocRelationFieldValue {
5687
5461
  }
5688
5462
  };
5689
5463
 
5690
- 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 };