Skip to content

Commit

Permalink
fix(content): update type definition for QueryBuilder.fetch() (#825)
Browse files Browse the repository at this point in the history
  • Loading branch information
Yz4230 committed Oct 21, 2021
1 parent 1f4a5d2 commit 4cc224e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
13 changes: 12 additions & 1 deletion packages/content/types/content.d.ts
Expand Up @@ -3,11 +3,22 @@ import type { QueryBuilder } from './query-builder'

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

export interface IContentDocument extends Record<string, any> {
export interface IContentDocumentBase extends Record<string, any> {
dir: string;
path: string;
extension: '.md' | '.json' | '.yaml' | '.xml' | '.csv' | string;
slug: string;
createdAt: Date | string;
updatedAt: Date | string;
body?: object;
toc?: {
id: string;
depth: number;
text: string;
}[];
}

export interface IContentDocument extends IContentDocumentBase {
createdAt: Date;
updatedAt: Date;
}
Expand Down
12 changes: 9 additions & 3 deletions packages/content/types/query-builder.d.ts
@@ -1,4 +1,5 @@
import type { IContentDocument } from './content';
import type { IContentDocumentBase } from "./content";

interface QueryBuilderOptions {
query: any;
path: string;
Expand All @@ -7,6 +8,11 @@ interface QueryBuilderOptions {
postprocess?: any[];
}

interface FetchReturn extends IContentDocumentBase {
createdAt: string;
updatedAt: string;
}

export class QueryBuilder {
constructor(
{ query, path, init, text, postprocess }: QueryBuilderOptions,
Expand Down Expand Up @@ -77,6 +83,6 @@ export class QueryBuilder {
* Collect data and apply process filters
* @returns processed data
*/
fetch(): Promise<IContentDocument | IContentDocument[]>;
fetch<T>(): Promise<(T & IContentDocument) | (T & IContentDocument)[]>;
fetch(): Promise<FetchReturn | FetchReturn[]>;
fetch<T>(): Promise<(T & FetchReturn) | (T & FetchReturn)[]>;
}

0 comments on commit 4cc224e

Please sign in to comment.