Closed duongkhoangiam closed 3 years ago
@duongkhoangiam Not now. Contributions are welcome.
@aravindnc, could you pease review the following index.d.ts? I just referenced mongoose-paginate-v2 to make the type file.
// Type definitions for mongoose-paginate-v2 1.3
// Project: https://github.com/webgangster/mongoose-paginate-v2
// Definitions by: Linus Brolin <https://github.com/linusbrolin>
// simonxca <https://github.com/simonxca>
// woutgg <https://github.com/woutgg>
// oktapodia <https://github.com/oktapodia>
// Dongjun Lee <https://github.com/ChazEpps>
// gamsterX <https://github.com/gamsterx>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// Minimum TypeScript Version: 3.2
//
// 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;
pagingCounter?: string;
hasPrevPage?: string;
hasNextPage?: string;
}
interface PaginateOptions {
/* tslint:disable-next-line: ban-types */
sort?: Object | string;
offset?: number;
page?: number;
limit?: number;
customLabels?: CustomLabels;
/* If pagination is set to `false`, it will return all docs without adding limit condition. (Default: `true`) */
pagination?: boolean;
allowDiskUse?: boolean;
countQuery?: Object;
}
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<any>;
/** optional query options like sort, limit, etc */
options?: any;
/** deep populate */
populate?: QueryPopulateOptions | QueryPopulateOptions[];
}
interface AggregatePaginateResult<T> {
docs: T[];
totalDocs: number;
limit: number;
page?: number;
totalPages: number;
nextPage?: number | null;
prevPage?: number | null;
pagingCounter: number;
hasPrevPage: boolean;
hasNextPage: boolean;
// meta?: any;
// [customLabel: string]: T[] | number | boolean | null | undefined;
}
interface AggregatePaginateModel<T extends Document> extends Model<T> {
aggregatePaginate(
query?: mongoose.Aggregate<T>,
options?: PaginateOptions,
callback?: (err: any, result: AggregatePaginateResult<T>) => void
): Promise<AggregatePaginateResult<T>>;
}
function model(
name: string,
schema?: Schema,
collection?: string,
skipInit?: boolean
): AggregatePaginateModel<any>;
}
import mongoose = require('mongoose');
declare function _(schema: mongoose.Schema): void;
export = _;
declare namespace _ {
const aggregatePaginate: { options: mongoose.PaginateOptions };
}
@knyuwork Thanks for this. But I'm not so experienced with TS. Let's wait for some other person to review it.
@knyuwork, thank you!
The type definition looks good except that these two lines should be deleted:
// meta?: any;
// [customLabel: string]: T[] | number | boolean | null | undefined;
This plugin does not support meta
. So these comments are irrelevant.
Do you have any plan to submit this to DefinitelyTyped
any time soon?
Thank you.
This was never published on DefinitelyTyped, is it normal? The definition seems ok, @knyuwork should I submit it or will you do it?
Just a detail, if found a small bug:
interface AggregatePaginateModel<T extends Document> extends Model<T> {
aggregatePaginate(
query?: mongoose.Aggregate<T[]>,
options?: PaginateOptions,
callback?: (err: any, result: AggregatePaginateResult<T>) => void
): Promise<AggregatePaginateResult<T>>;
}
Parameter query should be T[] because an aggregate is always an array of Documents.
@aravindnc types are added in DefinitelyTyped. This issue can be closed.
Thanks for the contribution @acrilex1
This library support typescript ?