Update declarations to correspond with mongoose-paginate-v2 module.

This commit is contained in:
Wouter R
2018-12-05 11:40:07 +01:00
parent 5380cf2a25
commit ad776bc550
3 changed files with 39 additions and 10 deletions
+20 -3
View File
@@ -1,15 +1,31 @@
// Type definitions for mongoose-paginate 5.0.0
// Type definitions for mongoose-paginate-v2 1.0.13
// Project: https://github.com/edwardhotchkiss/mongoose-paginate
// Definitions by: Linus Brolin <https://github.com/linusbrolin>, simonxca <https://github.com/simonxca>
// Definitions by: Linus Brolin <https://github.com/linusbrolin>
// simonxca <https://github.com/simonxca>
// woutgg <https://github.com/woutgg>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.3
//
// Based on type declarations for mongoose-paginate 5.0.0.
/// <reference types="mongoose" />
declare module 'mongoose' {
export interface CustomLabels {
totalDocs?: string,
limit?: string,
page?: string,
totalPages?: string,
docs?: string,
nextPage?: string,
prevPage?: string,
}
export interface PaginateOptions {
select?: Object | string;
sort?: Object | string;
customLabels?: CustomLabels,
collation?: CollationOptions,
populate?: Array<Object> | Array<string> | Object | string;
lean?: boolean;
leanWithId?: boolean;
@@ -25,6 +41,7 @@ declare module 'mongoose' {
page?: number;
pages?: number;
offset?: number;
[customLabel: string]: Array<T> | number | undefined;
}
interface PaginateModel<T extends Document> extends Model<T> {
@@ -44,7 +61,7 @@ declare module 'mongoose' {
skipInit?: boolean): U;
}
declare module 'mongoose-paginate' {
declare module 'mongoose-paginate-v2' {
import mongoose = require('mongoose');
var _: (schema: mongoose.Schema) => void;
export = _;
@@ -43,12 +43,22 @@ router.get('/users.json', function(req: Request, res: Response) {
let options: PaginateOptions = {} as PaginateOptions;
options.select = 'email username';
options.sort = { 'username': (descending ? -1 : 1) };
options.collation = { locale: 'en_US', strength: 1 };
options.populate = '';
options.lean = true;
options.leanWithId = false;
options.offset = 0;
options.page = 1;
options.limit = 10;
options.customLabels = {
totalDocs: 'totalDocsCustom',
limit: 'limitCustom',
page: 'pageCustom',
totalPages: 'totalPagesCustom',
docs: 'docsCustom',
nextPage: 'nextPageCustom',
prevPage: 'prevPageCustom'
};
UserModel
.paginate({}, options, (err: any, value: PaginateResult<User>) => {
@@ -57,13 +67,15 @@ router.get('/users.json', function(req: Request, res: Response) {
return res.status(500).send(err);
}
console.log('total: ' + value.total);
console.log('limit: ' + value.limit);
console.log('page: ' + value.page);
console.log('pages: ' + value.pages);
console.log('totalDocs: ' + value.totalDocsCustom);
console.log('limit: ' + value.limitCustom);
console.log('page: ' + value.pageCustom);
console.log('nextPage: ' + value.nextPageCustom);
console.log('prevPage: ' + value.prevPageCustom);
console.log('totalPages: ' + value.totalPagesCustom);
console.log('offset: ' + value.offset);
console.log('docs: ');
console.dir(value.docs);
console.dir(value.docsCustom);
return res.json(value);
});
+2 -2
View File
@@ -18,6 +18,6 @@
},
"files": [
"index.d.ts",
"mongoose-paginate-tests.ts"
"mongoose-paginate-v2-tests.ts"
]
}
}