@content-collections/core 0.8.2 → 0.9.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/dist/index.d.ts +55 -31
- package/dist/index.js +920 -846
- package/package.json +6 -5
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { StandardSchemaV1 } from '@standard-schema/spec';
|
|
2
|
+
import z__default, { ZodRawShape, z as z$1, ZodObject } from 'zod';
|
|
2
3
|
export * from 'zod';
|
|
3
4
|
|
|
4
5
|
type Options$2 = {
|
|
@@ -16,8 +17,14 @@ type GetTypeOfImport<T> = T extends Import<infer U> ? U : never;
|
|
|
16
17
|
declare function createDefaultImport<T>(path: string): Import<T>;
|
|
17
18
|
declare function createNamedImport<T>(name: string, path: string): Import<T>;
|
|
18
19
|
|
|
19
|
-
type
|
|
20
|
-
type Parser =
|
|
20
|
+
type ParseFn = (content: string) => Record<string, unknown> | Promise<Record<string, unknown>>;
|
|
21
|
+
type Parser = {
|
|
22
|
+
hasContent: boolean;
|
|
23
|
+
parse: ParseFn;
|
|
24
|
+
};
|
|
25
|
+
type PredefinedParsers = typeof parsers;
|
|
26
|
+
type PredefinedParser = keyof typeof parsers;
|
|
27
|
+
type ConfiguredParser = PredefinedParser | Parser;
|
|
21
28
|
declare function parseYaml(content: string): any;
|
|
22
29
|
declare function frontmatterParser(fileContent: string): {
|
|
23
30
|
content: string;
|
|
@@ -26,23 +33,28 @@ declare function frontmatterOnlyParser(fileContent: string): {
|
|
|
26
33
|
[key: string]: any;
|
|
27
34
|
};
|
|
28
35
|
declare const parsers: {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
36
|
+
frontmatter: {
|
|
37
|
+
hasContent: true;
|
|
38
|
+
parse: typeof frontmatterParser;
|
|
32
39
|
};
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
40
|
+
"frontmatter-only": {
|
|
41
|
+
hasContent: false;
|
|
42
|
+
parse: typeof frontmatterOnlyParser;
|
|
36
43
|
};
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
44
|
+
json: {
|
|
45
|
+
hasContent: false;
|
|
46
|
+
parse: (text: string, reviver?: (this: any, key: string, value: any) => any) => any;
|
|
40
47
|
};
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
48
|
+
yaml: {
|
|
49
|
+
hasContent: false;
|
|
50
|
+
parse: typeof parseYaml;
|
|
44
51
|
};
|
|
45
52
|
};
|
|
53
|
+
type DefineParserResult<TArgument extends Parser | ParseFn> = TArgument extends Function ? {
|
|
54
|
+
hasContent: false;
|
|
55
|
+
parse: ParseFn;
|
|
56
|
+
} : TArgument extends infer Parser ? Parser : never;
|
|
57
|
+
declare function defineParser<TArgument extends Parser | ParseFn>(parser: TArgument): DefineParserResult<TArgument>;
|
|
46
58
|
|
|
47
59
|
declare const literalSchema: z__default.ZodUnion<[z__default.ZodString, z__default.ZodNumber, z__default.ZodBoolean, z__default.ZodNull, z__default.ZodUndefined, z__default.ZodDate, z__default.ZodMap<z__default.ZodUnknown, z__default.ZodUnknown>, z__default.ZodSet<z__default.ZodUnknown>, z__default.ZodBigInt]>;
|
|
48
60
|
type Literal = z__default.infer<typeof literalSchema>;
|
|
@@ -64,18 +76,24 @@ type Meta = {
|
|
|
64
76
|
extension: string;
|
|
65
77
|
};
|
|
66
78
|
type WithContent = {
|
|
67
|
-
content:
|
|
79
|
+
content: string;
|
|
68
80
|
};
|
|
69
|
-
type AddContent<
|
|
70
|
-
content:
|
|
71
|
-
} ?
|
|
72
|
-
type
|
|
73
|
-
type
|
|
74
|
-
type
|
|
81
|
+
type AddContent<TOutput> = TOutput extends {
|
|
82
|
+
content: any;
|
|
83
|
+
} ? TOutput : TOutput & WithContent;
|
|
84
|
+
type GetParser<TParser extends ConfiguredParser> = TParser extends PredefinedParser ? PredefinedParsers[TParser] : TParser;
|
|
85
|
+
type HasContent<TParser extends ConfiguredParser> = GetParser<TParser>["hasContent"];
|
|
86
|
+
type LegacySchema<TResult extends ZodRawShape = ZodRawShape> = (z: Z) => TResult;
|
|
87
|
+
type TSchemaProp = StandardSchemaV1 | LegacySchema;
|
|
88
|
+
type GetLegacySchemaShape<LegacySchema> = LegacySchema extends (z: Z) => infer TObjectShape ? TObjectShape : never;
|
|
89
|
+
type GetOutputShape<TShape extends TSchemaProp> = TShape extends StandardSchemaV1 ? StandardSchemaV1.InferOutput<TShape> : TShape extends ZodObject<any> ? z$1.infer<TShape> : TShape extends LegacySchema ? z$1.infer<ZodObject<GetLegacySchemaShape<TShape>>> : never;
|
|
90
|
+
type GetOutput<TParser extends ConfiguredParser, TShape extends TSchemaProp, TOutput = GetOutputShape<TShape>> = HasContent<TParser> extends true ? AddContent<TOutput> : TOutput;
|
|
91
|
+
type Schema<TParser extends ConfiguredParser, TShape extends TSchemaProp> = GetOutput<TParser, TShape> & {
|
|
75
92
|
_meta: Meta;
|
|
76
93
|
};
|
|
94
|
+
type GetSchema<TCollection extends AnyCollection> = TCollection extends Collection<any, infer TSchema, any, any, any, any> ? GetOutputShape<TSchema> : never;
|
|
77
95
|
type Context<TSchema = unknown> = {
|
|
78
|
-
documents<TCollection extends AnyCollection>(collection: TCollection): Array<
|
|
96
|
+
documents<TCollection extends AnyCollection>(collection: TCollection): Array<GetSchema<TCollection>>;
|
|
79
97
|
cache: CacheFn;
|
|
80
98
|
collection: {
|
|
81
99
|
name: string;
|
|
@@ -84,23 +102,23 @@ type Context<TSchema = unknown> = {
|
|
|
84
102
|
};
|
|
85
103
|
};
|
|
86
104
|
type Z = typeof z$1;
|
|
87
|
-
type CollectionRequest<TName extends string, TShape extends
|
|
105
|
+
type CollectionRequest<TName extends string, TShape extends TSchemaProp, TParser, TSchema, TTransformResult, TDocument> = {
|
|
88
106
|
name: TName;
|
|
89
107
|
parser?: TParser;
|
|
90
108
|
typeName?: string;
|
|
91
|
-
schema:
|
|
109
|
+
schema: TShape;
|
|
92
110
|
transform?: (data: TSchema, context: Context<TSchema>) => TTransformResult;
|
|
93
111
|
directory: string;
|
|
94
112
|
include: string | string[];
|
|
95
113
|
exclude?: string | string[];
|
|
96
114
|
onSuccess?: (documents: Array<TDocument>) => void | Promise<void>;
|
|
97
115
|
};
|
|
98
|
-
type Collection<TName extends string, TShape extends
|
|
116
|
+
type Collection<TName extends string, TShape extends TSchemaProp, TParser extends ConfiguredParser, TSchema, TTransformResult, TDocument> = Omit<CollectionRequest<TName, TShape, TParser, TSchema, TTransformResult, TDocument>, "schema"> & {
|
|
99
117
|
typeName: string;
|
|
100
|
-
schema:
|
|
118
|
+
schema: StandardSchemaV1;
|
|
101
119
|
parser: TParser;
|
|
102
120
|
};
|
|
103
|
-
type AnyCollection = Collection<any,
|
|
121
|
+
type AnyCollection = Collection<any, TSchemaProp, ConfiguredParser, any, any, any>;
|
|
104
122
|
declare const InvalidReturnTypeSymbol: unique symbol;
|
|
105
123
|
type InvalidReturnType<TMessage extends string, TObject> = {
|
|
106
124
|
[InvalidReturnTypeSymbol]: TMessage;
|
|
@@ -109,7 +127,7 @@ type InvalidReturnType<TMessage extends string, TObject> = {
|
|
|
109
127
|
type ResolveImports<TTransformResult> = TTransformResult extends Import<any> ? GetTypeOfImport<TTransformResult> : TTransformResult extends Array<infer U> ? Array<ResolveImports<U>> : TTransformResult extends (...args: any[]) => any ? TTransformResult : TTransformResult extends object ? {
|
|
110
128
|
[K in keyof TTransformResult]: ResolveImports<TTransformResult[K]>;
|
|
111
129
|
} : TTransformResult;
|
|
112
|
-
declare function defineCollection<TName extends string, TShape extends
|
|
130
|
+
declare function defineCollection<TName extends string, TShape extends TSchemaProp, TParser extends ConfiguredParser = "frontmatter", TSchema = Schema<TParser, TShape>, TTransformResult = never, TDocument = [TTransformResult] extends [never] ? Schema<TParser, TShape> : Awaited<TTransformResult>, TResult = TDocument extends Serializable ? Collection<TName, TShape, TParser, TSchema, TTransformResult, ResolveImports<TDocument>> : InvalidReturnType<NotSerializableError, TDocument>>(collection: CollectionRequest<TName, TShape, TParser, TSchema, TTransformResult, TDocument>): TResult;
|
|
113
131
|
type Cache = "memory" | "file" | "none";
|
|
114
132
|
type Configuration<TCollections extends Array<AnyCollection>> = {
|
|
115
133
|
collections: TCollections;
|
|
@@ -132,7 +150,7 @@ type CollectionFile = {
|
|
|
132
150
|
type CollectionByName<TConfiguration extends AnyConfiguration> = {
|
|
133
151
|
[TCollection in TConfiguration["collections"][number] as TCollection["name"]]: TCollection;
|
|
134
152
|
};
|
|
135
|
-
type GetDocument<TCollection extends AnyCollection> = TCollection extends Collection<any,
|
|
153
|
+
type GetDocument<TCollection extends AnyCollection> = TCollection extends Collection<any, any, any, any, any, infer TDocument> ? TDocument : never;
|
|
136
154
|
type GetTypeByName<TConfiguration extends AnyConfiguration, TName extends keyof CollectionByName<TConfiguration>, TCollection = CollectionByName<TConfiguration>[TName]> = TCollection extends AnyCollection ? GetDocument<TCollection> : never;
|
|
137
155
|
|
|
138
156
|
type CollectorEvents = {
|
|
@@ -284,4 +302,10 @@ declare function createBuilder(configurationPath: string, options?: Options, emi
|
|
|
284
302
|
}>;
|
|
285
303
|
type Builder = Awaited<ReturnType<typeof createBuilder>>;
|
|
286
304
|
|
|
287
|
-
|
|
305
|
+
declare const deprecations: {
|
|
306
|
+
legacySchema: string;
|
|
307
|
+
};
|
|
308
|
+
type Deprecation = keyof typeof deprecations;
|
|
309
|
+
declare function suppressDeprecatedWarnings(...deprecations: Array<Deprecation | "all">): void;
|
|
310
|
+
|
|
311
|
+
export { type AnyCollection, type AnyConfiguration, type Builder, type BuilderEvents, CollectError, type Collection, type CollectionRequest, type Configuration, ConfigurationError, ConfigurationReloadError, type Context, type Document, type GetTypeByName, type Meta, type Modification, type Schema, TransformError, type Watcher, createBuilder, createDefaultImport, createNamedImport, defineCollection, defineConfig, defineParser, suppressDeprecatedWarnings };
|