Skip to content

Commit 4cc224e

Browse files
authored
fix(content): update type definition for QueryBuilder.fetch() (#825)
1 parent 1f4a5d2 commit 4cc224e

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

packages/content/types/content.d.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,22 @@ import type { QueryBuilder } from './query-builder'
33

44
export type contentFunc = (...args: Array<string | Object>) => QueryBuilder;
55

6-
export interface IContentDocument extends Record<string, any> {
6+
export interface IContentDocumentBase extends Record<string, any> {
77
dir: string;
88
path: string;
99
extension: '.md' | '.json' | '.yaml' | '.xml' | '.csv' | string;
1010
slug: string;
11+
createdAt: Date | string;
12+
updatedAt: Date | string;
13+
body?: object;
14+
toc?: {
15+
id: string;
16+
depth: number;
17+
text: string;
18+
}[];
19+
}
20+
21+
export interface IContentDocument extends IContentDocumentBase {
1122
createdAt: Date;
1223
updatedAt: Date;
1324
}

packages/content/types/query-builder.d.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import type { IContentDocument } from './content';
1+
import type { IContentDocumentBase } from "./content";
2+
23
interface QueryBuilderOptions {
34
query: any;
45
path: string;
@@ -7,6 +8,11 @@ interface QueryBuilderOptions {
78
postprocess?: any[];
89
}
910

11+
interface FetchReturn extends IContentDocumentBase {
12+
createdAt: string;
13+
updatedAt: string;
14+
}
15+
1016
export class QueryBuilder {
1117
constructor(
1218
{ query, path, init, text, postprocess }: QueryBuilderOptions,
@@ -77,6 +83,6 @@ export class QueryBuilder {
7783
* Collect data and apply process filters
7884
* @returns processed data
7985
*/
80-
fetch(): Promise<IContentDocument | IContentDocument[]>;
81-
fetch<T>(): Promise<(T & IContentDocument) | (T & IContentDocument)[]>;
86+
fetch(): Promise<FetchReturn | FetchReturn[]>;
87+
fetch<T>(): Promise<(T & FetchReturn) | (T & FetchReturn)[]>;
8288
}

0 commit comments

Comments
 (0)