@interactive-inc/docs-client 0.0.14 → 0.0.16
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.d.ts +215 -18
- package/build/index.js +202 -0
- package/debug/debug.ts +32 -10
- package/package.json +1 -1
package/build/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
-
import { zDocClientConfig,
|
|
3
|
-
export { zDocCustomSchema, zDocFile, zDocFileIndex, zDocFileIndexContent, zDocFileIndexMeta, zDocFileIndexMetaInput, zDocFileIndexSchema, zDocFileIndexSchemaInput, zDocFileMd, zDocFileMdContent, zDocFileMdContentInput, zDocFileMdInput, zDocFileMdMeta, zDocFileMdMetaInput, zDocMetaFieldTypeMultiNumber, zDocMetaFieldTypeMultiRelation, zDocMetaFieldTypeMultiSelectNumber, zDocMetaFieldTypeMultiSelectText, zDocMetaFieldTypeMultiText, zDocTreeDirectoryNode, zDocTreeFileNode, zDocTreeNode } from './models.js';
|
|
2
|
+
import { zDocClientConfig, zDocFilePath, zDocMetaFieldRelation, zDocMetaFieldMultiRelation, zDocMetaFieldText, zDocMetaFieldNumber, zDocMetaFieldBoolean, zDocMetaFieldMultiText, zDocMetaFieldMultiNumber, zDocMetaFieldMultiBoolean, zDocFileUnknown, zDocFileIndexSchemaField, zDocSchemaFieldText, zDocSchemaFieldNumber, zDocSchemaFieldBoolean, zDocSchemaFieldRelation, zDocSchemaFieldSelectText, zDocSchemaFieldSelectNumber, zDocSchemaFieldMultiText, zDocSchemaFieldMultiNumber, zDocSchemaFieldMultiRelation, zDocSchemaFieldMultiSelectText, zDocSchemaFieldMultiSelectNumber, zDocRelation, zDocRelationFile, zDocMetaField, zDocMetaFieldSelectText, zDocMetaFieldSelectNumber, zDocMetaFieldMultiSelectText, zDocMetaFieldMultiSelectNumber, zDocMetaFieldTypeText, zDocMetaFieldTypeNumber, zDocMetaFieldTypeBoolean, zDocMetaFieldTypeSelectText, zDocMetaFieldTypeSelectNumber, zDocMetaFieldTypeRelation, zDocMetaFieldType, zDocRelationField } from './models.js';
|
|
3
|
+
export { zDocCustomSchema, zDocCustomSchemaField, zDocCustomSchemaFieldBoolean, zDocCustomSchemaFieldMultiNumber, zDocCustomSchemaFieldMultiRelation, zDocCustomSchemaFieldMultiSelectNumber, zDocCustomSchemaFieldMultiSelectText, zDocCustomSchemaFieldMultiText, zDocCustomSchemaFieldNumber, zDocCustomSchemaFieldRelation, zDocCustomSchemaFieldSelectNumber, zDocCustomSchemaFieldSelectText, zDocCustomSchemaFieldText, zDocFile, zDocFileIndex, zDocFileIndexContent, zDocFileIndexMeta, zDocFileIndexMetaInput, zDocFileIndexSchema, zDocFileIndexSchemaInput, zDocFileMd, zDocFileMdContent, zDocFileMdContentInput, zDocFileMdInput, zDocFileMdMeta, zDocFileMdMetaInput, zDocMetaFieldTypeMultiNumber, zDocMetaFieldTypeMultiRelation, zDocMetaFieldTypeMultiSelectNumber, zDocMetaFieldTypeMultiSelectText, zDocMetaFieldTypeMultiText, zDocTreeDirectoryNode, zDocTreeFileNode, zDocTreeNode } from './models.js';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Path operations system
|
|
@@ -481,17 +481,50 @@ type DocMetaFieldTypeRelation = z.infer<typeof zDocMetaFieldTypeRelation>;
|
|
|
481
481
|
* Schema field type
|
|
482
482
|
*/
|
|
483
483
|
type DocMetaFieldType = z.infer<typeof zDocMetaFieldType>;
|
|
484
|
-
type DocCustomSchemaFieldText =
|
|
485
|
-
type
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
type
|
|
489
|
-
type
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
type
|
|
493
|
-
type
|
|
494
|
-
|
|
484
|
+
type DocCustomSchemaFieldText = {
|
|
485
|
+
type: "text";
|
|
486
|
+
required: boolean;
|
|
487
|
+
};
|
|
488
|
+
type DocCustomSchemaFieldNumber = {
|
|
489
|
+
type: "number";
|
|
490
|
+
required: boolean;
|
|
491
|
+
};
|
|
492
|
+
type DocCustomSchemaFieldBoolean = {
|
|
493
|
+
type: "boolean";
|
|
494
|
+
required: boolean;
|
|
495
|
+
};
|
|
496
|
+
type DocCustomSchemaFieldRelation = {
|
|
497
|
+
type: "relation";
|
|
498
|
+
required: boolean;
|
|
499
|
+
};
|
|
500
|
+
type DocCustomSchemaFieldSelectText = {
|
|
501
|
+
type: "select-text";
|
|
502
|
+
required: boolean;
|
|
503
|
+
};
|
|
504
|
+
type DocCustomSchemaFieldSelectNumber = {
|
|
505
|
+
type: "select-number";
|
|
506
|
+
required: boolean;
|
|
507
|
+
};
|
|
508
|
+
type DocCustomSchemaFieldMultiText = {
|
|
509
|
+
type: "multi-text";
|
|
510
|
+
required: boolean;
|
|
511
|
+
};
|
|
512
|
+
type DocCustomSchemaFieldMultiNumber = {
|
|
513
|
+
type: "multi-number";
|
|
514
|
+
required: boolean;
|
|
515
|
+
};
|
|
516
|
+
type DocCustomSchemaFieldMultiRelation = {
|
|
517
|
+
type: "multi-relation";
|
|
518
|
+
required: boolean;
|
|
519
|
+
};
|
|
520
|
+
type DocCustomSchemaFieldMultiSelectText = {
|
|
521
|
+
type: "multi-select-text";
|
|
522
|
+
required: boolean;
|
|
523
|
+
};
|
|
524
|
+
type DocCustomSchemaFieldMultiSelectNumber = {
|
|
525
|
+
type: "multi-select-number";
|
|
526
|
+
required: boolean;
|
|
527
|
+
};
|
|
495
528
|
/**
|
|
496
529
|
* Schema field type
|
|
497
530
|
*/
|
|
@@ -504,7 +537,11 @@ type DocFileIndexSchema<T extends RecordKey> = Record<T, DocFileIndexSchemaField
|
|
|
504
537
|
* Schema field to override
|
|
505
538
|
* ex: { xxx: { type: "text", required: true } }
|
|
506
539
|
*/
|
|
507
|
-
type DocCustomSchemaField =
|
|
540
|
+
type DocCustomSchemaField = DocCustomSchemaFieldText | DocCustomSchemaFieldNumber | DocCustomSchemaFieldBoolean | DocCustomSchemaFieldRelation | DocCustomSchemaFieldSelectText | DocCustomSchemaFieldSelectNumber | DocCustomSchemaFieldMultiText | DocCustomSchemaFieldMultiNumber | DocCustomSchemaFieldMultiRelation | DocCustomSchemaFieldMultiSelectText | DocCustomSchemaFieldMultiSelectNumber;
|
|
541
|
+
/**
|
|
542
|
+
* Type literal for field types
|
|
543
|
+
*/
|
|
544
|
+
type DocFieldTypeLiteral = "text" | "number" | "boolean" | "relation" | "multi-text" | "multi-number" | "multi-relation" | "select-text" | "select-number" | "multi-select-text" | "multi-select-number";
|
|
508
545
|
/**
|
|
509
546
|
* Minimal schema definition type
|
|
510
547
|
*/
|
|
@@ -566,7 +603,7 @@ type MultiRelationKeys<T extends DocCustomSchema> = {
|
|
|
566
603
|
/**
|
|
567
604
|
* Markdown file type (excluding index.md)
|
|
568
605
|
*/
|
|
569
|
-
type DocFileMd<T extends DocCustomSchema
|
|
606
|
+
type DocFileMd<T extends DocCustomSchema> = {
|
|
570
607
|
type: "markdown";
|
|
571
608
|
path: DocFilePath;
|
|
572
609
|
isArchived: boolean;
|
|
@@ -671,12 +708,12 @@ type OptionalKeys<T extends DocCustomSchema> = {
|
|
|
671
708
|
type SchemaToValueType<T extends DocCustomSchema> = {
|
|
672
709
|
[K in RequiredKeys<T>]: BaseFieldValueType<ExtractFieldType<T[K]>>;
|
|
673
710
|
} & {
|
|
674
|
-
[K in OptionalKeys<T>]?: BaseFieldValueType<ExtractFieldType<T[K]
|
|
711
|
+
[K in OptionalKeys<T>]?: BaseFieldValueType<ExtractFieldType<T[K]>> | null;
|
|
675
712
|
};
|
|
676
713
|
/**
|
|
677
714
|
* Helper type for type-safe property access
|
|
678
715
|
*/
|
|
679
|
-
type GetValueType<T extends DocCustomSchema, K extends keyof T> = K extends RequiredKeys<T> ? BaseFieldValueType<ExtractFieldType<T[K]>> : BaseFieldValueType<ExtractFieldType<T[K]>> | undefined;
|
|
716
|
+
type GetValueType<T extends DocCustomSchema, K extends keyof T> = K extends RequiredKeys<T> ? BaseFieldValueType<ExtractFieldType<T[K]>> : BaseFieldValueType<ExtractFieldType<T[K]>> | undefined | null;
|
|
680
717
|
/**
|
|
681
718
|
* Type definitions for DocFileIndexSchema
|
|
682
719
|
*/
|
|
@@ -687,6 +724,10 @@ type GetIndexFieldType<Schema extends DocFileIndexSchema<RecordKey>, K extends k
|
|
|
687
724
|
type GetIndexFieldValueType<Schema extends DocFileIndexSchema<RecordKey>, K extends keyof Schema> = Schema[K] extends {
|
|
688
725
|
type: infer Type;
|
|
689
726
|
} ? Type extends "text" ? DocSchemaFieldTextValue<K> : Type extends "number" ? DocSchemaFieldNumberValue<K> : Type extends "boolean" ? DocSchemaFieldBooleanValue<K> : Type extends "relation" ? DocSchemaFieldRelationValue<K> : Type extends "select-text" ? DocSchemaFieldSelectTextValue<K> : Type extends "select-number" ? DocSchemaFieldSelectNumberValue<K> : Type extends "multi-text" ? DocSchemaFieldMultiTextValue<K> : Type extends "multi-number" ? DocSchemaFieldMultiNumberValue<K> : Type extends "multi-relation" ? DocSchemaFieldMultiRelationValue<K> : Type extends "multi-select-text" ? DocSchemaFieldMultiSelectTextValue<K> : Type extends "multi-select-number" ? DocSchemaFieldMultiSelectNumberValue<K> : never : never;
|
|
727
|
+
/**
|
|
728
|
+
* Infers DocFileMd type from the result of defineSchema
|
|
729
|
+
*/
|
|
730
|
+
type InferDocFileMd<T> = T extends DocCustomSchema ? DocFileMd<T> : never;
|
|
690
731
|
|
|
691
732
|
/**
|
|
692
733
|
* Relation file
|
|
@@ -866,6 +907,11 @@ declare class DocFileIndexMetaValue<T extends DocCustomSchema> {
|
|
|
866
907
|
* Update schema field
|
|
867
908
|
*/
|
|
868
909
|
withSchema(value: DocFileIndexSchema<keyof T>): DocFileIndexMetaValue<T>;
|
|
910
|
+
/**
|
|
911
|
+
* Return a new instance with an unknown schema
|
|
912
|
+
* Allows accepting Record<string, unknown> schemas from external sources
|
|
913
|
+
*/
|
|
914
|
+
withUnknownSchema(draft: Record<string, unknown>): DocFileIndexMetaValue<DocCustomSchema>;
|
|
869
915
|
/**
|
|
870
916
|
* Output in JSON format
|
|
871
917
|
*/
|
|
@@ -1076,6 +1122,11 @@ declare class DocFileMdMetaValue<T extends DocCustomSchema> {
|
|
|
1076
1122
|
* Return a new instance with a single property updated
|
|
1077
1123
|
*/
|
|
1078
1124
|
withProperty<K extends keyof T>(key: K, value: BaseFieldValueType<ExtractFieldType<T[K]>>): DocFileMdMetaValue<T>;
|
|
1125
|
+
/**
|
|
1126
|
+
* Return a new instance with an unknown schema
|
|
1127
|
+
* Allows accepting Record<string, unknown> schemas from external sources
|
|
1128
|
+
*/
|
|
1129
|
+
withUnknownSchema(draft: Record<string, unknown>): DocFileMdMetaValue<DocCustomSchema>;
|
|
1079
1130
|
schemaField<K extends keyof T>(key: K): T[K];
|
|
1080
1131
|
field<K extends keyof T>(key: K): FieldValueType<ExtractFieldType<T[K]>, ExtractRequired<T[K]>>;
|
|
1081
1132
|
relation(key: keyof T): DocMetaFieldRelation;
|
|
@@ -1714,4 +1765,150 @@ declare class DocFileSystemDebug extends DocFileSystem {
|
|
|
1714
1765
|
|
|
1715
1766
|
type DocFileEntity<T extends DocCustomSchema> = DocFileMdEntity<T> | DocFileIndexEntity<T> | DocFileUnknownEntity;
|
|
1716
1767
|
|
|
1717
|
-
|
|
1768
|
+
/**
|
|
1769
|
+
* Schema builder
|
|
1770
|
+
* Build schemas in a chain style
|
|
1771
|
+
*
|
|
1772
|
+
* @example
|
|
1773
|
+
* const schema = new SchemaBuilder()
|
|
1774
|
+
* .text("title", true)
|
|
1775
|
+
* .multiRelation("features", true)
|
|
1776
|
+
* .selectText("priority", false)
|
|
1777
|
+
* .build()
|
|
1778
|
+
*/
|
|
1779
|
+
declare class SchemaBuilder<T extends DocCustomSchema> {
|
|
1780
|
+
private schema;
|
|
1781
|
+
constructor(schema?: T);
|
|
1782
|
+
text<K extends string>(key: K, required: boolean): SchemaBuilder<T & Record<K, {
|
|
1783
|
+
type: "text";
|
|
1784
|
+
required: boolean;
|
|
1785
|
+
}>>;
|
|
1786
|
+
number<K extends string>(key: K, required: boolean): SchemaBuilder<T & Record<K, {
|
|
1787
|
+
type: "number";
|
|
1788
|
+
required: boolean;
|
|
1789
|
+
}>>;
|
|
1790
|
+
boolean<K extends string>(key: K, required: boolean): SchemaBuilder<T & Record<K, {
|
|
1791
|
+
type: "boolean";
|
|
1792
|
+
required: boolean;
|
|
1793
|
+
}>>;
|
|
1794
|
+
relation<K extends string>(key: K, required: boolean): SchemaBuilder<T & Record<K, {
|
|
1795
|
+
type: "relation";
|
|
1796
|
+
required: boolean;
|
|
1797
|
+
}>>;
|
|
1798
|
+
multiRelation<K extends string>(key: K, required: boolean): SchemaBuilder<T & Record<K, {
|
|
1799
|
+
type: "multi-relation";
|
|
1800
|
+
required: boolean;
|
|
1801
|
+
}>>;
|
|
1802
|
+
selectText<K extends string>(key: K, required: boolean): SchemaBuilder<T & Record<K, {
|
|
1803
|
+
type: "select-text";
|
|
1804
|
+
required: boolean;
|
|
1805
|
+
}>>;
|
|
1806
|
+
selectNumber<K extends string>(key: K, required: boolean): SchemaBuilder<T & Record<K, {
|
|
1807
|
+
type: "select-number";
|
|
1808
|
+
required: boolean;
|
|
1809
|
+
}>>;
|
|
1810
|
+
multiText<K extends string>(key: K, required: boolean): SchemaBuilder<T & Record<K, {
|
|
1811
|
+
type: "multi-text";
|
|
1812
|
+
required: boolean;
|
|
1813
|
+
}>>;
|
|
1814
|
+
multiNumber<K extends string>(key: K, required: boolean): SchemaBuilder<T & Record<K, {
|
|
1815
|
+
type: "multi-number";
|
|
1816
|
+
required: boolean;
|
|
1817
|
+
}>>;
|
|
1818
|
+
multiSelectText<K extends string>(key: K, required: boolean): SchemaBuilder<T & Record<K, {
|
|
1819
|
+
type: "multi-select-text";
|
|
1820
|
+
required: boolean;
|
|
1821
|
+
}>>;
|
|
1822
|
+
multiSelectNumber<K extends string>(key: K, required: boolean): SchemaBuilder<T & Record<K, {
|
|
1823
|
+
type: "multi-select-number";
|
|
1824
|
+
required: boolean;
|
|
1825
|
+
}>>;
|
|
1826
|
+
build(): T;
|
|
1827
|
+
}
|
|
1828
|
+
|
|
1829
|
+
/**
|
|
1830
|
+
* Function that only performs type checking (does nothing at runtime)
|
|
1831
|
+
*/
|
|
1832
|
+
declare function expectType<T>(_value: T): void;
|
|
1833
|
+
/**
|
|
1834
|
+
* Type-level assertion
|
|
1835
|
+
* Compiles only when Equals<T, U> is true
|
|
1836
|
+
*/
|
|
1837
|
+
declare function assertType<_T extends true>(): void;
|
|
1838
|
+
/**
|
|
1839
|
+
* Default configuration for tests
|
|
1840
|
+
*/
|
|
1841
|
+
declare const defaultTestConfig: {
|
|
1842
|
+
defaultIndexIcon: string;
|
|
1843
|
+
indexFileName: string;
|
|
1844
|
+
archiveDirectoryName: string;
|
|
1845
|
+
defaultDirectoryName: string;
|
|
1846
|
+
indexMetaIncludes: never[];
|
|
1847
|
+
directoryExcludes: string[];
|
|
1848
|
+
};
|
|
1849
|
+
/**
|
|
1850
|
+
* Helper function for defining schemas
|
|
1851
|
+
* Enables type completion while defining schemas
|
|
1852
|
+
*
|
|
1853
|
+
* @example
|
|
1854
|
+
* const mySchema = defineSchema({
|
|
1855
|
+
* title: { type: "text", required: true },
|
|
1856
|
+
* priority: { type: "select-text", required: false },
|
|
1857
|
+
* features: { type: "multi-relation", required: true }
|
|
1858
|
+
* })
|
|
1859
|
+
*
|
|
1860
|
+
* type MyDoc = InferDocFileMd<typeof mySchema>
|
|
1861
|
+
*/
|
|
1862
|
+
declare function defineSchema<T extends DocCustomSchema>(schema: T): T;
|
|
1863
|
+
/**
|
|
1864
|
+
* Helper functions for field definitions
|
|
1865
|
+
* Use when finer control is needed
|
|
1866
|
+
*/
|
|
1867
|
+
declare const docCustomSchemaField: {
|
|
1868
|
+
readonly text: (required: boolean) => {
|
|
1869
|
+
type: "text";
|
|
1870
|
+
required: boolean;
|
|
1871
|
+
};
|
|
1872
|
+
readonly number: (required: boolean) => {
|
|
1873
|
+
type: "number";
|
|
1874
|
+
required: boolean;
|
|
1875
|
+
};
|
|
1876
|
+
readonly boolean: (required: boolean) => {
|
|
1877
|
+
type: "boolean";
|
|
1878
|
+
required: boolean;
|
|
1879
|
+
};
|
|
1880
|
+
readonly relation: (required: boolean) => {
|
|
1881
|
+
type: "relation";
|
|
1882
|
+
required: boolean;
|
|
1883
|
+
};
|
|
1884
|
+
readonly multiRelation: (required: boolean) => {
|
|
1885
|
+
type: "multi-relation";
|
|
1886
|
+
required: boolean;
|
|
1887
|
+
};
|
|
1888
|
+
readonly selectText: (required: boolean) => {
|
|
1889
|
+
type: "select-text";
|
|
1890
|
+
required: boolean;
|
|
1891
|
+
};
|
|
1892
|
+
readonly selectNumber: (required: boolean) => {
|
|
1893
|
+
type: "select-number";
|
|
1894
|
+
required: boolean;
|
|
1895
|
+
};
|
|
1896
|
+
readonly multiText: (required: boolean) => {
|
|
1897
|
+
type: "multi-text";
|
|
1898
|
+
required: boolean;
|
|
1899
|
+
};
|
|
1900
|
+
readonly multiNumber: (required: boolean) => {
|
|
1901
|
+
type: "multi-number";
|
|
1902
|
+
required: boolean;
|
|
1903
|
+
};
|
|
1904
|
+
readonly multiSelectText: (required: boolean) => {
|
|
1905
|
+
type: "multi-select-text";
|
|
1906
|
+
required: boolean;
|
|
1907
|
+
};
|
|
1908
|
+
readonly multiSelectNumber: (required: boolean) => {
|
|
1909
|
+
type: "multi-select-number";
|
|
1910
|
+
required: boolean;
|
|
1911
|
+
};
|
|
1912
|
+
};
|
|
1913
|
+
|
|
1914
|
+
export { type BaseFieldValueType, DocClient, type DocClientConfig, type DocCustomSchema, type DocCustomSchemaField, type DocCustomSchemaFieldBoolean, type DocCustomSchemaFieldMultiNumber, type DocCustomSchemaFieldMultiRelation, type DocCustomSchemaFieldMultiSelectNumber, type DocCustomSchemaFieldMultiSelectText, type DocCustomSchemaFieldMultiText, type DocCustomSchemaFieldNumber, type DocCustomSchemaFieldRelation, type DocCustomSchemaFieldSelectNumber, type DocCustomSchemaFieldSelectText, type DocCustomSchemaFieldText, type DocDirectory, DocDirectoryReference, type DocFieldTypeLiteral, type DocFile, type DocFileEntity, type DocFileIndex, type DocFileIndexContent, DocFileIndexEntity, type DocFileIndexMeta, DocFileIndexReference, type DocFileIndexSchema, type DocFileIndexSchemaField, type DocFileMd, type DocFileMdContent, DocFileMdEntity, type DocFileMdMeta, DocFileMdReference, type DocFilePath, DocFileRelationReference, DocFileSystem, DocFileSystemDebug, type DocFileUnknown, DocFileUnknownEntity, DocFileUnknownReference, DocMarkdownSystem, type DocMetaField, type DocMetaFieldBoolean, type DocMetaFieldMultiBoolean, type DocMetaFieldMultiNumber, type DocMetaFieldMultiRelation, type DocMetaFieldMultiSelectNumber, type DocMetaFieldMultiSelectText, type DocMetaFieldMultiText, type DocMetaFieldNumber, type DocMetaFieldRelation, type DocMetaFieldSelectNumber, type DocMetaFieldSelectText, type DocMetaFieldText, type DocMetaFieldType, type DocMetaFieldTypeBoolean, type DocMetaFieldTypeNumber, type DocMetaFieldTypeRelation, type DocMetaFieldTypeSelectNumber, type DocMetaFieldTypeSelectText, type DocMetaFieldTypeText, DocPathSystem, type DocRelation, type DocRelationField, type DocRelationFile, type DocSchemaFieldBoolean, type DocSchemaFieldMultiNumber, type DocSchemaFieldMultiRelation, type DocSchemaFieldMultiSelectNumber, type DocSchemaFieldMultiSelectText, type DocSchemaFieldMultiText, type DocSchemaFieldNumber, type DocSchemaFieldRelation, type DocSchemaFieldSelectNumber, type DocSchemaFieldSelectText, type DocSchemaFieldText, type DocSchemaRelationFieldUnion, type DocTreeDirectoryNode, type DocTreeFileNode, type DocTreeNode, type Equals, type ExtractFieldType, type ExtractIndexFieldType, type ExtractRequired, type FieldValueType, DocFileTreeSystem as FileTreeSystem, type GetIndexFieldType, type GetIndexFieldValueType, type GetValueType, type InferDocFileMd, type MultiRelationKeys, type OptionalKeys, type RecordKey, type RelationKeys, type RequiredKeys, SchemaBuilder, type SchemaToValueType, assertType, defaultTestConfig, defineSchema, docCustomSchemaField, expectType, zDocClientConfig, zDocFileIndexSchemaField, zDocFilePath, zDocFileUnknown, zDocMetaField, zDocMetaFieldBoolean, zDocMetaFieldMultiBoolean, zDocMetaFieldMultiNumber, zDocMetaFieldMultiRelation, zDocMetaFieldMultiSelectNumber, zDocMetaFieldMultiSelectText, zDocMetaFieldMultiText, zDocMetaFieldNumber, zDocMetaFieldRelation, zDocMetaFieldSelectNumber, zDocMetaFieldSelectText, zDocMetaFieldText, zDocMetaFieldType, zDocMetaFieldTypeBoolean, zDocMetaFieldTypeNumber, zDocMetaFieldTypeRelation, zDocMetaFieldTypeSelectNumber, zDocMetaFieldTypeSelectText, zDocMetaFieldTypeText, zDocRelation, zDocRelationField, zDocRelationFile, zDocSchemaFieldBoolean, zDocSchemaFieldMultiNumber, zDocSchemaFieldMultiRelation, zDocSchemaFieldMultiSelectNumber, zDocSchemaFieldMultiSelectText, zDocSchemaFieldMultiText, zDocSchemaFieldNumber, zDocSchemaFieldRelation, zDocSchemaFieldSelectNumber, zDocSchemaFieldSelectText, zDocSchemaFieldText };
|
package/build/index.js
CHANGED
|
@@ -1269,6 +1269,24 @@ var DocFileMdMetaValue = class _DocFileMdMetaValue {
|
|
|
1269
1269
|
this.customSchema
|
|
1270
1270
|
);
|
|
1271
1271
|
}
|
|
1272
|
+
/**
|
|
1273
|
+
* Return a new instance with an unknown schema
|
|
1274
|
+
* Allows accepting Record<string, unknown> schemas from external sources
|
|
1275
|
+
*/
|
|
1276
|
+
withUnknownSchema(draft) {
|
|
1277
|
+
const typedSchema = draft;
|
|
1278
|
+
const newValue = {};
|
|
1279
|
+
for (const key in typedSchema) {
|
|
1280
|
+
if (key in this.value) {
|
|
1281
|
+
const unknownValue = this.value;
|
|
1282
|
+
newValue[key] = unknownValue[key];
|
|
1283
|
+
}
|
|
1284
|
+
}
|
|
1285
|
+
return new _DocFileMdMetaValue(
|
|
1286
|
+
newValue,
|
|
1287
|
+
typedSchema
|
|
1288
|
+
);
|
|
1289
|
+
}
|
|
1272
1290
|
schemaField(key) {
|
|
1273
1291
|
const field = this.customSchema[key];
|
|
1274
1292
|
if (field === void 0) {
|
|
@@ -2854,6 +2872,23 @@ var DocFileIndexMetaValue = class _DocFileIndexMetaValue {
|
|
|
2854
2872
|
this.additionalProperties
|
|
2855
2873
|
);
|
|
2856
2874
|
}
|
|
2875
|
+
/**
|
|
2876
|
+
* Return a new instance with an unknown schema
|
|
2877
|
+
* Allows accepting Record<string, unknown> schemas from external sources
|
|
2878
|
+
*/
|
|
2879
|
+
withUnknownSchema(draft) {
|
|
2880
|
+
const typedSchema = draft;
|
|
2881
|
+
return new _DocFileIndexMetaValue(
|
|
2882
|
+
{
|
|
2883
|
+
type: "index-meta",
|
|
2884
|
+
icon: this.value.icon,
|
|
2885
|
+
schema: typedSchema
|
|
2886
|
+
},
|
|
2887
|
+
{},
|
|
2888
|
+
this.config,
|
|
2889
|
+
this.additionalProperties
|
|
2890
|
+
);
|
|
2891
|
+
}
|
|
2857
2892
|
/**
|
|
2858
2893
|
* Output in JSON format
|
|
2859
2894
|
*/
|
|
@@ -5271,6 +5306,167 @@ var DocFileSystemDebug = class _DocFileSystemDebug extends DocFileSystem {
|
|
|
5271
5306
|
}
|
|
5272
5307
|
}
|
|
5273
5308
|
};
|
|
5309
|
+
|
|
5310
|
+
// lib/schema-builder.ts
|
|
5311
|
+
var SchemaBuilder = class _SchemaBuilder {
|
|
5312
|
+
constructor(schema = {}) {
|
|
5313
|
+
this.schema = schema;
|
|
5314
|
+
}
|
|
5315
|
+
text(key, required) {
|
|
5316
|
+
return new _SchemaBuilder({
|
|
5317
|
+
...this.schema,
|
|
5318
|
+
[key]: { type: "text", required }
|
|
5319
|
+
});
|
|
5320
|
+
}
|
|
5321
|
+
number(key, required) {
|
|
5322
|
+
return new _SchemaBuilder({
|
|
5323
|
+
...this.schema,
|
|
5324
|
+
[key]: { type: "number", required }
|
|
5325
|
+
});
|
|
5326
|
+
}
|
|
5327
|
+
boolean(key, required) {
|
|
5328
|
+
return new _SchemaBuilder({
|
|
5329
|
+
...this.schema,
|
|
5330
|
+
[key]: { type: "boolean", required }
|
|
5331
|
+
});
|
|
5332
|
+
}
|
|
5333
|
+
relation(key, required) {
|
|
5334
|
+
return new _SchemaBuilder({
|
|
5335
|
+
...this.schema,
|
|
5336
|
+
[key]: { type: "relation", required }
|
|
5337
|
+
});
|
|
5338
|
+
}
|
|
5339
|
+
multiRelation(key, required) {
|
|
5340
|
+
return new _SchemaBuilder({
|
|
5341
|
+
...this.schema,
|
|
5342
|
+
[key]: { type: "multi-relation", required }
|
|
5343
|
+
});
|
|
5344
|
+
}
|
|
5345
|
+
selectText(key, required) {
|
|
5346
|
+
return new _SchemaBuilder({
|
|
5347
|
+
...this.schema,
|
|
5348
|
+
[key]: { type: "select-text", required }
|
|
5349
|
+
});
|
|
5350
|
+
}
|
|
5351
|
+
selectNumber(key, required) {
|
|
5352
|
+
return new _SchemaBuilder({
|
|
5353
|
+
...this.schema,
|
|
5354
|
+
[key]: { type: "select-number", required }
|
|
5355
|
+
});
|
|
5356
|
+
}
|
|
5357
|
+
multiText(key, required) {
|
|
5358
|
+
return new _SchemaBuilder({
|
|
5359
|
+
...this.schema,
|
|
5360
|
+
[key]: { type: "multi-text", required }
|
|
5361
|
+
});
|
|
5362
|
+
}
|
|
5363
|
+
multiNumber(key, required) {
|
|
5364
|
+
return new _SchemaBuilder({
|
|
5365
|
+
...this.schema,
|
|
5366
|
+
[key]: { type: "multi-number", required }
|
|
5367
|
+
});
|
|
5368
|
+
}
|
|
5369
|
+
multiSelectText(key, required) {
|
|
5370
|
+
return new _SchemaBuilder({
|
|
5371
|
+
...this.schema,
|
|
5372
|
+
[key]: { type: "multi-select-text", required }
|
|
5373
|
+
});
|
|
5374
|
+
}
|
|
5375
|
+
multiSelectNumber(key, required) {
|
|
5376
|
+
return new _SchemaBuilder({
|
|
5377
|
+
...this.schema,
|
|
5378
|
+
[key]: { type: "multi-select-number", required }
|
|
5379
|
+
});
|
|
5380
|
+
}
|
|
5381
|
+
build() {
|
|
5382
|
+
return this.schema;
|
|
5383
|
+
}
|
|
5384
|
+
};
|
|
5385
|
+
|
|
5386
|
+
// lib/utils.ts
|
|
5387
|
+
function expectType(_value) {
|
|
5388
|
+
}
|
|
5389
|
+
function assertType() {
|
|
5390
|
+
}
|
|
5391
|
+
var defaultTestConfig = {
|
|
5392
|
+
defaultIndexIcon: "\u{1F4C1}",
|
|
5393
|
+
indexFileName: "index.md",
|
|
5394
|
+
archiveDirectoryName: "_",
|
|
5395
|
+
defaultDirectoryName: "Directory",
|
|
5396
|
+
indexMetaIncludes: [],
|
|
5397
|
+
directoryExcludes: [".vitepress"]
|
|
5398
|
+
};
|
|
5399
|
+
function defineSchema(schema) {
|
|
5400
|
+
return schema;
|
|
5401
|
+
}
|
|
5402
|
+
var docCustomSchemaField = {
|
|
5403
|
+
text(required) {
|
|
5404
|
+
return {
|
|
5405
|
+
type: "text",
|
|
5406
|
+
required
|
|
5407
|
+
};
|
|
5408
|
+
},
|
|
5409
|
+
number(required) {
|
|
5410
|
+
return {
|
|
5411
|
+
type: "number",
|
|
5412
|
+
required
|
|
5413
|
+
};
|
|
5414
|
+
},
|
|
5415
|
+
boolean(required) {
|
|
5416
|
+
return {
|
|
5417
|
+
type: "boolean",
|
|
5418
|
+
required
|
|
5419
|
+
};
|
|
5420
|
+
},
|
|
5421
|
+
relation(required) {
|
|
5422
|
+
return {
|
|
5423
|
+
type: "relation",
|
|
5424
|
+
required
|
|
5425
|
+
};
|
|
5426
|
+
},
|
|
5427
|
+
multiRelation(required) {
|
|
5428
|
+
return {
|
|
5429
|
+
type: "multi-relation",
|
|
5430
|
+
required
|
|
5431
|
+
};
|
|
5432
|
+
},
|
|
5433
|
+
selectText(required) {
|
|
5434
|
+
return {
|
|
5435
|
+
type: "select-text",
|
|
5436
|
+
required
|
|
5437
|
+
};
|
|
5438
|
+
},
|
|
5439
|
+
selectNumber(required) {
|
|
5440
|
+
return {
|
|
5441
|
+
type: "select-number",
|
|
5442
|
+
required
|
|
5443
|
+
};
|
|
5444
|
+
},
|
|
5445
|
+
multiText(required) {
|
|
5446
|
+
return {
|
|
5447
|
+
type: "multi-text",
|
|
5448
|
+
required
|
|
5449
|
+
};
|
|
5450
|
+
},
|
|
5451
|
+
multiNumber(required) {
|
|
5452
|
+
return {
|
|
5453
|
+
type: "multi-number",
|
|
5454
|
+
required
|
|
5455
|
+
};
|
|
5456
|
+
},
|
|
5457
|
+
multiSelectText(required) {
|
|
5458
|
+
return {
|
|
5459
|
+
type: "multi-select-text",
|
|
5460
|
+
required
|
|
5461
|
+
};
|
|
5462
|
+
},
|
|
5463
|
+
multiSelectNumber(required) {
|
|
5464
|
+
return {
|
|
5465
|
+
type: "multi-select-number",
|
|
5466
|
+
required
|
|
5467
|
+
};
|
|
5468
|
+
}
|
|
5469
|
+
};
|
|
5274
5470
|
export {
|
|
5275
5471
|
DocClient,
|
|
5276
5472
|
DocDirectoryReference,
|
|
@@ -5286,6 +5482,12 @@ export {
|
|
|
5286
5482
|
DocMarkdownSystem,
|
|
5287
5483
|
DocPathSystem,
|
|
5288
5484
|
DocFileTreeSystem as FileTreeSystem,
|
|
5485
|
+
SchemaBuilder,
|
|
5486
|
+
assertType,
|
|
5487
|
+
defaultTestConfig,
|
|
5488
|
+
defineSchema,
|
|
5489
|
+
docCustomSchemaField,
|
|
5490
|
+
expectType,
|
|
5289
5491
|
zDocClientConfig,
|
|
5290
5492
|
zDocCustomSchema,
|
|
5291
5493
|
zDocCustomSchemaField,
|
package/debug/debug.ts
CHANGED
|
@@ -1,17 +1,19 @@
|
|
|
1
1
|
import { DocClient } from "@/doc-client"
|
|
2
2
|
import { DocFileSystem } from "@/doc-file-system"
|
|
3
|
+
import { SchemaBuilder } from "@/schema-builder"
|
|
4
|
+
import { defineSchema, docCustomSchemaField } from "@/utils"
|
|
3
5
|
|
|
4
6
|
const client = new DocClient({
|
|
5
7
|
fileSystem: new DocFileSystem({ basePath: "../../docs" }),
|
|
6
8
|
})
|
|
7
9
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
required: true,
|
|
12
|
-
},
|
|
10
|
+
// Method 1: Using defineSchema (recommended)
|
|
11
|
+
const pageSchema = defineSchema({
|
|
12
|
+
features: docCustomSchemaField.multiRelation(true),
|
|
13
13
|
})
|
|
14
14
|
|
|
15
|
+
const pagesRef = client.directory("docs-studio/pages", pageSchema)
|
|
16
|
+
|
|
15
17
|
const mdFileRef = await pagesRef.mdFile("document-editor")
|
|
16
18
|
|
|
17
19
|
const mdFile = await mdFileRef.read()
|
|
@@ -20,6 +22,8 @@ if (mdFile instanceof Error) {
|
|
|
20
22
|
throw mdFile
|
|
21
23
|
}
|
|
22
24
|
|
|
25
|
+
const _features = mdFile.content.meta().field("features")
|
|
26
|
+
|
|
23
27
|
mdFile.withContent(
|
|
24
28
|
mdFile.content.withMetaProperty("features", [
|
|
25
29
|
"edit-document-content",
|
|
@@ -28,13 +32,31 @@ mdFile.withContent(
|
|
|
28
32
|
]),
|
|
29
33
|
)
|
|
30
34
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
type: "boolean",
|
|
35
|
-
},
|
|
35
|
+
// Method 2: Using field helpers
|
|
36
|
+
const featureSchema = defineSchema({
|
|
37
|
+
"is-done": docCustomSchemaField.boolean(true),
|
|
36
38
|
})
|
|
37
39
|
|
|
40
|
+
const relations = await mdFileRef.relations("features", featureSchema)
|
|
41
|
+
|
|
38
42
|
const file = await relations[0].read()
|
|
39
43
|
|
|
40
44
|
console.log("relations", file)
|
|
45
|
+
|
|
46
|
+
// Method 3: Using SchemaBuilder
|
|
47
|
+
const fooSchema = new SchemaBuilder()
|
|
48
|
+
.multiRelation("feature", true)
|
|
49
|
+
.text("priority", false)
|
|
50
|
+
.build()
|
|
51
|
+
|
|
52
|
+
const fooRef = client.directory("docs-studio/files", fooSchema)
|
|
53
|
+
|
|
54
|
+
const aaa = await fooRef.mdFile("a")
|
|
55
|
+
|
|
56
|
+
const fooFile = await aaa.read()
|
|
57
|
+
|
|
58
|
+
if (fooFile instanceof Error) {
|
|
59
|
+
throw fooFile
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
fooFile.content.meta().field("feature")
|