@dakohhh/mongoose-paginator
Version:
Mongoose-Class-Paginator is a lightweight, flexible, and TypeScript-friendly pagination utility for Mongoose models. It provides a class-based approach to handling database pagination with support for filtering, sorting, population, projection, and metada
70 lines • 2.47 kB
TypeScript
import { FilterQuery, Model, SortOrder, PopulateOptions } from "mongoose";
export interface IPaginateArgs<T> {
filter?: FilterQuery<T>;
sort?: Record<string, SortOrder>;
projection?: string | string[] | Record<string, number | boolean | string | object>;
populate?: PopulateOptions | PopulateOptions[];
lean?: boolean;
}
export interface IPaginationMeta {
total?: number;
lastPage?: number;
currentPage?: number;
perPage?: number;
prev?: number | null;
next?: number | null;
nextCursor?: string | null;
}
export interface IPaginationResult<T> {
data: T[];
meta: IPaginationMeta;
}
export interface IBasePaginator<T> {
model: Model<T>;
args: IPaginateArgs<T>;
setArgs: (args: IPaginateArgs<T>) => this;
paginate: () => Promise<IPaginationResult<T>>;
}
export declare class BasePaginator<T> implements IBasePaginator<T> {
model: Model<T>;
args: IPaginateArgs<T>;
constructor(model: Model<T>, args?: IPaginateArgs<T>);
setArgs(args: IPaginateArgs<T>): this;
paginate(): Promise<IPaginationResult<T>>;
}
export declare class PageNumberPaginator<T> extends BasePaginator<T> {
private page;
private limit;
constructor(model: Model<T>, page?: number, limit?: number, args?: IPaginateArgs<T>);
private getSkip;
paginate(): Promise<IPaginationResult<T>>;
setPage(page: number): this;
setLimit(limit: number): this;
setArgs(args: IPaginateArgs<T>): this;
}
export declare class OffsetPaginator<T> extends BasePaginator<T> {
private offset;
private limit;
constructor(model: Model<T>, offset: number, limit: number, args?: IPaginateArgs<T>);
setOffset(offset: number): this;
setLimit(limit: number): this;
paginate(): Promise<IPaginationResult<T>>;
}
export declare class CursorPaginator<T> extends BasePaginator<T> {
private cursor;
private limit;
constructor(model: Model<T>, cursor: string | null, limit: number, args?: IPaginateArgs<T>);
setCursor(cursor: string): this;
setLimit(limit: number): this;
paginate(): Promise<IPaginationResult<T>>;
}
export declare class MongoosePaginatorError extends Error {
constructor(message: string);
}
/**
* @deprecated Please use `PageNumberPaginator` instead.
* This will be removed in version 1.1.
*/
declare const PaginatorDeprecationNotice: typeof PageNumberPaginator;
export { PaginatorDeprecationNotice as Paginator };
//# sourceMappingURL=index.d.ts.map