@interactive-inc/docs-client 0.0.13 → 0.0.15
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 +219 -22
- 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
|
*/
|
|
@@ -541,7 +578,7 @@ type DocTreeNode = DocTreeFileNode | DocTreeDirectoryNode;
|
|
|
541
578
|
/**
|
|
542
579
|
* Index file type
|
|
543
580
|
*/
|
|
544
|
-
type DocFileIndex<T extends DocCustomSchema> = {
|
|
581
|
+
type DocFileIndex<T extends DocCustomSchema = DocCustomSchema> = {
|
|
545
582
|
type: "index";
|
|
546
583
|
path: DocFilePath;
|
|
547
584
|
isArchived: boolean;
|
|
@@ -579,11 +616,11 @@ type DocFileUnknown = z.infer<typeof zDocFileUnknown>;
|
|
|
579
616
|
/**
|
|
580
617
|
* File union type (index.md, regular md, other)
|
|
581
618
|
*/
|
|
582
|
-
type DocFile<T extends DocCustomSchema> = DocFileIndex<T> | DocFileMd<T> | DocFileUnknown;
|
|
619
|
+
type DocFile<T extends DocCustomSchema = DocCustomSchema> = DocFileIndex<T> | DocFileMd<T> | DocFileUnknown;
|
|
583
620
|
/**
|
|
584
621
|
* Directory FrontMatter type
|
|
585
622
|
*/
|
|
586
|
-
type DocFileIndexMeta<T extends DocCustomSchema> = {
|
|
623
|
+
type DocFileIndexMeta<T extends DocCustomSchema = DocCustomSchema> = {
|
|
587
624
|
type: "index-meta";
|
|
588
625
|
icon: string | null;
|
|
589
626
|
schema: DocFileIndexSchema<keyof T>;
|
|
@@ -607,7 +644,7 @@ type DocFilePath = z.infer<typeof zDocFilePath>;
|
|
|
607
644
|
/**
|
|
608
645
|
* Markdown content information type
|
|
609
646
|
*/
|
|
610
|
-
type DocFileMdContent<T extends DocCustomSchema> = {
|
|
647
|
+
type DocFileMdContent<T extends DocCustomSchema = DocCustomSchema> = {
|
|
611
648
|
type: "markdown-content";
|
|
612
649
|
body: string;
|
|
613
650
|
title: string;
|
|
@@ -617,7 +654,7 @@ type DocFileMdContent<T extends DocCustomSchema> = {
|
|
|
617
654
|
/**
|
|
618
655
|
* Index file content information type
|
|
619
656
|
*/
|
|
620
|
-
type DocFileIndexContent<T extends DocCustomSchema> = {
|
|
657
|
+
type DocFileIndexContent<T extends DocCustomSchema = DocCustomSchema> = {
|
|
621
658
|
type: "markdown-index";
|
|
622
659
|
body: string;
|
|
623
660
|
title: string;
|
|
@@ -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
|
*/
|
|
@@ -866,6 +903,11 @@ declare class DocFileIndexMetaValue<T extends DocCustomSchema> {
|
|
|
866
903
|
* Update schema field
|
|
867
904
|
*/
|
|
868
905
|
withSchema(value: DocFileIndexSchema<keyof T>): DocFileIndexMetaValue<T>;
|
|
906
|
+
/**
|
|
907
|
+
* Return a new instance with an unknown schema
|
|
908
|
+
* Allows accepting Record<string, unknown> schemas from external sources
|
|
909
|
+
*/
|
|
910
|
+
withUnknownSchema(newSchema: Record<string, unknown>): DocFileIndexMetaValue<DocCustomSchema>;
|
|
869
911
|
/**
|
|
870
912
|
* Output in JSON format
|
|
871
913
|
*/
|
|
@@ -1076,6 +1118,11 @@ declare class DocFileMdMetaValue<T extends DocCustomSchema> {
|
|
|
1076
1118
|
* Return a new instance with a single property updated
|
|
1077
1119
|
*/
|
|
1078
1120
|
withProperty<K extends keyof T>(key: K, value: BaseFieldValueType<ExtractFieldType<T[K]>>): DocFileMdMetaValue<T>;
|
|
1121
|
+
/**
|
|
1122
|
+
* Return a new instance with an unknown schema
|
|
1123
|
+
* Allows accepting Record<string, unknown> schemas from external sources
|
|
1124
|
+
*/
|
|
1125
|
+
withUnknownSchema(newSchema: Record<string, unknown>): DocFileMdMetaValue<DocCustomSchema>;
|
|
1079
1126
|
schemaField<K extends keyof T>(key: K): T[K];
|
|
1080
1127
|
field<K extends keyof T>(key: K): FieldValueType<ExtractFieldType<T[K]>, ExtractRequired<T[K]>>;
|
|
1081
1128
|
relation(key: keyof T): DocMetaFieldRelation;
|
|
@@ -1714,4 +1761,154 @@ declare class DocFileSystemDebug extends DocFileSystem {
|
|
|
1714
1761
|
|
|
1715
1762
|
type DocFileEntity<T extends DocCustomSchema> = DocFileMdEntity<T> | DocFileIndexEntity<T> | DocFileUnknownEntity;
|
|
1716
1763
|
|
|
1717
|
-
|
|
1764
|
+
/**
|
|
1765
|
+
* Schema builder
|
|
1766
|
+
* Build schemas in a chain style
|
|
1767
|
+
*
|
|
1768
|
+
* @example
|
|
1769
|
+
* const schema = new SchemaBuilder()
|
|
1770
|
+
* .text("title", true)
|
|
1771
|
+
* .multiRelation("features", true)
|
|
1772
|
+
* .selectText("priority", false)
|
|
1773
|
+
* .build()
|
|
1774
|
+
*/
|
|
1775
|
+
declare class SchemaBuilder<T extends DocCustomSchema> {
|
|
1776
|
+
private schema;
|
|
1777
|
+
constructor(schema?: T);
|
|
1778
|
+
text<K extends string>(key: K, required: boolean): SchemaBuilder<T & Record<K, {
|
|
1779
|
+
type: "text";
|
|
1780
|
+
required: boolean;
|
|
1781
|
+
}>>;
|
|
1782
|
+
number<K extends string>(key: K, required: boolean): SchemaBuilder<T & Record<K, {
|
|
1783
|
+
type: "number";
|
|
1784
|
+
required: boolean;
|
|
1785
|
+
}>>;
|
|
1786
|
+
boolean<K extends string>(key: K, required: boolean): SchemaBuilder<T & Record<K, {
|
|
1787
|
+
type: "boolean";
|
|
1788
|
+
required: boolean;
|
|
1789
|
+
}>>;
|
|
1790
|
+
relation<K extends string>(key: K, required: boolean): SchemaBuilder<T & Record<K, {
|
|
1791
|
+
type: "relation";
|
|
1792
|
+
required: boolean;
|
|
1793
|
+
}>>;
|
|
1794
|
+
multiRelation<K extends string>(key: K, required: boolean): SchemaBuilder<T & Record<K, {
|
|
1795
|
+
type: "multi-relation";
|
|
1796
|
+
required: boolean;
|
|
1797
|
+
}>>;
|
|
1798
|
+
selectText<K extends string>(key: K, required: boolean): SchemaBuilder<T & Record<K, {
|
|
1799
|
+
type: "select-text";
|
|
1800
|
+
required: boolean;
|
|
1801
|
+
}>>;
|
|
1802
|
+
selectNumber<K extends string>(key: K, required: boolean): SchemaBuilder<T & Record<K, {
|
|
1803
|
+
type: "select-number";
|
|
1804
|
+
required: boolean;
|
|
1805
|
+
}>>;
|
|
1806
|
+
multiText<K extends string>(key: K, required: boolean): SchemaBuilder<T & Record<K, {
|
|
1807
|
+
type: "multi-text";
|
|
1808
|
+
required: boolean;
|
|
1809
|
+
}>>;
|
|
1810
|
+
multiNumber<K extends string>(key: K, required: boolean): SchemaBuilder<T & Record<K, {
|
|
1811
|
+
type: "multi-number";
|
|
1812
|
+
required: boolean;
|
|
1813
|
+
}>>;
|
|
1814
|
+
multiSelectText<K extends string>(key: K, required: boolean): SchemaBuilder<T & Record<K, {
|
|
1815
|
+
type: "multi-select-text";
|
|
1816
|
+
required: boolean;
|
|
1817
|
+
}>>;
|
|
1818
|
+
multiSelectNumber<K extends string>(key: K, required: boolean): SchemaBuilder<T & Record<K, {
|
|
1819
|
+
type: "multi-select-number";
|
|
1820
|
+
required: boolean;
|
|
1821
|
+
}>>;
|
|
1822
|
+
build(): T;
|
|
1823
|
+
}
|
|
1824
|
+
|
|
1825
|
+
/**
|
|
1826
|
+
* Function that only performs type checking (does nothing at runtime)
|
|
1827
|
+
*/
|
|
1828
|
+
declare function expectType<T>(_value: T): void;
|
|
1829
|
+
/**
|
|
1830
|
+
* Type-level assertion
|
|
1831
|
+
* Compiles only when Equals<T, U> is true
|
|
1832
|
+
*/
|
|
1833
|
+
declare function assertType<_T extends true>(): void;
|
|
1834
|
+
/**
|
|
1835
|
+
* Default configuration for tests
|
|
1836
|
+
*/
|
|
1837
|
+
declare const defaultTestConfig: {
|
|
1838
|
+
defaultIndexIcon: string;
|
|
1839
|
+
indexFileName: string;
|
|
1840
|
+
archiveDirectoryName: string;
|
|
1841
|
+
defaultDirectoryName: string;
|
|
1842
|
+
indexMetaIncludes: never[];
|
|
1843
|
+
directoryExcludes: string[];
|
|
1844
|
+
};
|
|
1845
|
+
/**
|
|
1846
|
+
* Helper function for defining schemas
|
|
1847
|
+
* Enables type completion while defining schemas
|
|
1848
|
+
*
|
|
1849
|
+
* @example
|
|
1850
|
+
* const mySchema = defineSchema({
|
|
1851
|
+
* title: { type: "text", required: true },
|
|
1852
|
+
* priority: { type: "select-text", required: false },
|
|
1853
|
+
* features: { type: "multi-relation", required: true }
|
|
1854
|
+
* })
|
|
1855
|
+
*
|
|
1856
|
+
* type MyDoc = InferDocFileMd<typeof mySchema>
|
|
1857
|
+
*/
|
|
1858
|
+
declare function defineSchema<T extends DocCustomSchema>(schema: T): T;
|
|
1859
|
+
/**
|
|
1860
|
+
* Infers DocFileMd type from the result of defineSchema
|
|
1861
|
+
*/
|
|
1862
|
+
type InferDocFileMd<T> = T extends DocCustomSchema ? DocFileMd<T> : never;
|
|
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(newSchema) {
|
|
1277
|
+
const typedSchema = newSchema;
|
|
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(newSchema) {
|
|
2880
|
+
const typedSchema = newSchema;
|
|
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")
|