Copy mongoose-paginate declaration to mongoose-paginate-v2.

This commit is contained in:
Wouter R
2018-12-05 11:15:50 +01:00
parent e1a9b84984
commit 5380cf2a25
4 changed files with 224 additions and 0 deletions
+51
View File
@@ -0,0 +1,51 @@
// Type definitions for mongoose-paginate 5.0.0
// Project: https://github.com/edwardhotchkiss/mongoose-paginate
// Definitions by: Linus Brolin <https://github.com/linusbrolin>, simonxca <https://github.com/simonxca>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.3
/// <reference types="mongoose" />
declare module 'mongoose' {
export interface PaginateOptions {
select?: Object | string;
sort?: Object | string;
populate?: Array<Object> | Array<string> | Object | string;
lean?: boolean;
leanWithId?: boolean;
offset?: number;
page?: number;
limit?: number;
}
export interface PaginateResult<T> {
docs: Array<T>;
total: number;
limit: number;
page?: number;
pages?: number;
offset?: number;
}
interface PaginateModel<T extends Document> extends Model<T> {
paginate(query?: Object, options?: PaginateOptions, callback?: (err: any, result: PaginateResult<T>) => void): Promise<PaginateResult<T>>;
}
export function model<T extends Document>(
name: string,
schema?: Schema,
collection?: string,
skipInit?: boolean): PaginateModel<T>;
export function model<T extends Document, U extends PaginateModel<T>>(
name: string,
schema?: Schema,
collection?: string,
skipInit?: boolean): U;
}
declare module 'mongoose-paginate' {
import mongoose = require('mongoose');
var _: (schema: mongoose.Schema) => void;
export = _;
}
@@ -0,0 +1,71 @@
/**
* Created by Linus Brolin <https://github.com/linusbrolin/>.
*/
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;
}
const UserSchema: Schema = new Schema({
email: String,
username: String,
password: String
});
UserSchema.plugin(mongoosePaginate);
interface UserModel<T extends Document> extends PaginateModel<T> {};
let UserModel: UserModel<User> = model<User>('User', UserSchema) as UserModel<User>;
//#endregion
//#region Test Paginate
let router: Router = Router();
router.get('/users.json', function(req: Request, res: Response) {
let descending: boolean = true;
let options: PaginateOptions = {} as PaginateOptions;
options.select = 'email username';
options.sort = { 'username': (descending ? -1 : 1) };
options.populate = '';
options.lean = true;
options.leanWithId = false;
options.offset = 0;
options.page = 1;
options.limit = 10;
UserModel
.paginate({}, options, (err: any, value: PaginateResult<User>) => {
if (err) {
console.log(err);
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('offset: ' + value.offset);
console.log('docs: ');
console.dir(value.docs);
return res.json(value);
});
});
//#endregion
+23
View File
@@ -0,0 +1,23 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": false,
"strictFunctionTypes": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"mongoose-paginate-tests.ts"
]
}
+79
View File
@@ -0,0 +1,79 @@
{
"extends": "dtslint/dt.json",
"rules": {
"adjacent-overload-signatures": false,
"array-type": false,
"arrow-return-shorthand": false,
"ban-types": false,
"callable-types": false,
"comment-format": false,
"dt-header": false,
"eofline": false,
"export-just-namespace": false,
"import-spacing": false,
"interface-name": false,
"interface-over-type-literal": false,
"jsdoc-format": false,
"max-line-length": false,
"member-access": false,
"new-parens": false,
"no-any-union": false,
"no-boolean-literal-compare": false,
"no-conditional-assignment": false,
"no-consecutive-blank-lines": false,
"no-construct": false,
"no-declare-current-package": false,
"no-duplicate-imports": false,
"no-duplicate-variable": false,
"no-empty-interface": false,
"no-for-in-array": false,
"no-inferrable-types": false,
"no-internal-module": false,
"no-irregular-whitespace": false,
"no-mergeable-namespace": false,
"no-misused-new": false,
"no-namespace": false,
"no-object-literal-type-assertion": false,
"no-padding": false,
"no-redundant-jsdoc": false,
"no-redundant-jsdoc-2": false,
"no-redundant-undefined": false,
"no-reference-import": false,
"no-relative-import-in-test": false,
"no-self-import": false,
"no-single-declare-module": false,
"no-string-throw": false,
"no-unnecessary-callback-wrapper": false,
"no-unnecessary-class": false,
"no-unnecessary-generics": false,
"no-unnecessary-qualifier": false,
"no-unnecessary-type-assertion": false,
"no-useless-files": false,
"no-var-keyword": false,
"no-var-requires": false,
"no-void-expression": false,
"no-trailing-whitespace": false,
"object-literal-key-quotes": false,
"object-literal-shorthand": false,
"one-line": false,
"one-variable-per-declaration": false,
"only-arrow-functions": false,
"prefer-conditional-expression": false,
"prefer-const": false,
"prefer-declare-function": false,
"prefer-for-of": false,
"prefer-method-signature": false,
"prefer-template": false,
"radix": false,
"semicolon": false,
"space-before-function-paren": false,
"space-within-parens": false,
"strict-export-declare-modifiers": false,
"trim-file": false,
"triple-equals": false,
"typedef-whitespace": false,
"unified-signatures": false,
"void-return": false,
"whitespace": false
}
}