diff --git a/types/mongoose-paginate-v2/index.d.ts b/types/mongoose-paginate-v2/index.d.ts index 02a1f18b6d..4012d9a59b 100644 --- a/types/mongoose-paginate-v2/index.d.ts +++ b/types/mongoose-paginate-v2/index.d.ts @@ -11,72 +11,74 @@ // Based on type declarations for mongoose-paginate 5.0.0. declare module 'mongoose' { - interface CustomLabels { - totalDocs?: string; - limit?: string; - page?: string; - totalPages?: string; - docs?: string; - nextPage?: string; - prevPage?: string; - } + interface CustomLabels { + totalDocs?: string; + limit?: string; + page?: string; + totalPages?: string; + docs?: string; + nextPage?: string; + prevPage?: string; + } - interface ReadOptions { - pref: string; - tags?: any[]; - } + interface ReadOptions { + pref: string; + tags?: any[]; + } - interface PaginateOptions { - /* tslint:disable-next-line: ban-types */ - select?: Object | string; - /* tslint:disable-next-line: ban-types */ - sort?: Object | string; - customLabels?: CustomLabels; - collation?: CollationOptions; - /* tslint:disable-next-line: ban-types */ - populate?: Object[] | string[] | Object | string | QueryPopulateOptions; - lean?: boolean; - leanWithId?: boolean; - offset?: number; - page?: number; - limit?: number; - read?: ReadOptions; - } + interface PaginateOptions { + /* tslint:disable-next-line: ban-types */ + select?: Object | string; + /* tslint:disable-next-line: ban-types */ + sort?: Object | string; + customLabels?: CustomLabels; + collation?: CollationOptions; + /* tslint:disable-next-line: ban-types */ + populate?: Object[] | string[] | Object | string | QueryPopulateOptions; + lean?: boolean; + leanWithId?: boolean; + offset?: number; + page?: number; + limit?: number; + read?: ReadOptions; + /* If pagination is set to `false`, it will return all docs without adding limit condition. (Default: `true`) */ + pagination?: boolean; + } - interface QueryPopulateOptions { - /** space delimited path(s) to populate */ - path: string; - /** optional fields to select */ - select?: any; - /** optional query conditions to match */ - match?: any; - /** optional model to use for population */ - model?: string | Model; - /** optional query options like sort, limit, etc */ - options?: any; - /** deep populate */ - populate?: QueryPopulateOptions | QueryPopulateOptions[]; - } + interface QueryPopulateOptions { + /** space delimited path(s) to populate */ + path: string; + /** optional fields to select */ + select?: any; + /** optional query conditions to match */ + match?: any; + /** optional model to use for population */ + model?: string | Model; + /** optional query options like sort, limit, etc */ + options?: any; + /** deep populate */ + populate?: QueryPopulateOptions | QueryPopulateOptions[]; + } - interface PaginateResult { - docs: T[]; - total: number; - limit: number; - page?: number; - pages?: number; - offset?: number; - [customLabel: string]: T[] | number | undefined; - } + interface PaginateResult { + docs: T[]; + total: number; + limit: number; + page?: number; + pages?: number; + offset?: number; + [customLabel: string]: T[] | number | undefined; + } - interface PaginateModel extends Model { - paginate(query?: object, options?: PaginateOptions, callback?: (err: any, result: PaginateResult) => void): Promise>; - } + interface PaginateModel extends Model { + paginate( + query?: object, + options?: PaginateOptions, + callback?: (err: any, result: PaginateResult) => void, + ): Promise>; + } - function model( - name: string, - schema?: Schema, - collection?: string, - skipInit?: boolean): PaginateModel; + function model(name: string, schema?: Schema, collection?: string, skipInit?: boolean): PaginateModel; } import mongoose = require('mongoose'); diff --git a/types/mongoose-paginate-v2/mongoose-paginate-v2-tests.ts b/types/mongoose-paginate-v2/mongoose-paginate-v2-tests.ts index 4928b4f008..0e4f8b7bf4 100644 --- a/types/mongoose-paginate-v2/mongoose-paginate-v2-tests.ts +++ b/types/mongoose-paginate-v2/mongoose-paginate-v2-tests.ts @@ -2,28 +2,21 @@ * Created by Linus Brolin . */ -import { - Schema, - model, - PaginateModel, - PaginateOptions, - PaginateResult, - Document -} from 'mongoose'; +import { Schema, model, PaginateModel, PaginateOptions, PaginateResult, Document } from 'mongoose'; import mongoosePaginate = require('mongoose-paginate'); import { Router, Request, Response } from 'express'; //#region Test Models interface User extends Document { - email: string; - username: string; - password: string; + email: string; + username: string; + password: string; } const UserSchema: Schema = new Schema({ - email: String, - username: String, - password: String + email: String, + username: String, + password: String, }); UserSchema.plugin(mongoosePaginate); @@ -40,11 +33,12 @@ router.get('/users.json', (req: Request, res: Response) => { const descending = true; const options: PaginateOptions = {}; options.select = 'email username'; - options.sort = { username: (descending ? -1 : 1) }; + options.sort = { username: descending ? -1 : 1 }; options.collation = { locale: 'en_US', strength: 1 }; + options.pagination = false; options.populate = ''; options.populate = { - path: '', + path: '', }; options.lean = true; options.leanWithId = false; @@ -58,11 +52,10 @@ router.get('/users.json', (req: Request, res: Response) => { totalPages: 'totalPagesCustom', docs: 'docsCustom', nextPage: 'nextPageCustom', - prevPage: 'prevPageCustom' + prevPage: 'prevPageCustom', }; - UserModel - .paginate({}, options, (err: any, value: PaginateResult) => { + UserModel.paginate({}, options, (err: any, value: PaginateResult) => { if (err) { console.log(err); return res.status(500).send(err);