UNPKG

@conpago/mongo-cursor-pagination

Version:

Make it easy to return cursor-paginated results from a Mongo collection

53 lines (52 loc) 2.3 kB
import { AggregateParams, QueryParams, PaginationResponse, PaginatedField, QueryParamsMulti } from "../types"; /** * Helper function to encode pagination tokens. * * NOTE: this function modifies the passed-in `response` argument directly. * @param {QueryParams | AggregateParams} params * @param {Object} response The response * @returns void */ export declare function encodePaginationTokens(params: QueryParams | AggregateParams, response: PaginationResponse, multi?: boolean): void; /** * Parses the raw results from a find or aggregate query and generates a response object that * contain the various pagination properties * * @param {Object[]} results the results from a query * @param {QueryParams | AggregateParams} params The params originally passed to `find` or `aggregate` * * @return {Object} The object containing pagination properties */ export declare function prepareResponse(results: any[], params: QueryParams | AggregateParams, multi?: boolean): PaginationResponse; export type SearchArgs = PaginatedField & Pick<QueryParams, "previous">; /** * Generates a `$sort` object given the parameters * * @param {QueryParams | AggregateParams} params The params originally passed to `find` or `aggregate` * * @return {Object} a sort object */ export declare function generateSort(params: SearchArgs): Record<string, number>; export declare function generateSorts(params: QueryParamsMulti): any; /** * Generates a cursor query that provides the offset capabilities * * @param {Object} params The params originally passed to `find` or `aggregate` * * @return {Object} a cursor offset query */ export declare function generateCursorQuery(params: QueryParams | AggregateParams): object; type BigOrRow = Record<string, Record<"$gt" | "$lt" | "$eq", any>>; export declare function generateCursorQueryMulti(params: QueryParamsMulti): BigOrRow | { $or: BigOrRow[]; }; /** * response results can have additional fields that were not requested by user (for example, the * fields required to sort and paginate). If projected fields are nominated, return only these. */ export declare function filterProjectedFields({ projectedFields, results, sortCaseInsensitive, }: { projectedFields: any; results: any; sortCaseInsensitive: any; }): any; export {};