@andrew_l/mongo-pagination 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +101 -0
- package/dist/index.cjs +55 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +150 -0
- package/dist/index.d.mts +150 -0
- package/dist/index.d.ts +150 -0
- package/dist/index.mjs +49 -0
- package/dist/index.mjs.map +1 -0
- package/dist/mongoose-7.cjs +36 -0
- package/dist/mongoose-7.cjs.map +1 -0
- package/dist/mongoose-7.d.cts +16 -0
- package/dist/mongoose-7.d.mts +16 -0
- package/dist/mongoose-7.d.ts +16 -0
- package/dist/mongoose-7.mjs +34 -0
- package/dist/mongoose-7.mjs.map +1 -0
- package/dist/mongoose-8.cjs +36 -0
- package/dist/mongoose-8.cjs.map +1 -0
- package/dist/mongoose-8.d.cts +16 -0
- package/dist/mongoose-8.d.mts +16 -0
- package/dist/mongoose-8.d.ts +16 -0
- package/dist/mongoose-8.mjs +34 -0
- package/dist/mongoose-8.mjs.map +1 -0
- package/dist/shared/mongo-pagination.BU3-d0QB.d.cts +194 -0
- package/dist/shared/mongo-pagination.BU3-d0QB.d.mts +194 -0
- package/dist/shared/mongo-pagination.BU3-d0QB.d.ts +194 -0
- package/dist/shared/mongo-pagination.CHC5agt7.cjs +666 -0
- package/dist/shared/mongo-pagination.CHC5agt7.cjs.map +1 -0
- package/dist/shared/mongo-pagination.YG1DNE27.mjs +654 -0
- package/dist/shared/mongo-pagination.YG1DNE27.mjs.map +1 -0
- package/package.json +61 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":["../src/QueryAdapterMongodb.ts","../src/withMongoPagination.ts"],"sourcesContent":["import type { FindCursor, FindOptions } from 'mongodb';\nimport type { Readable } from 'node:stream';\nimport type { QueryAdapter } from './QueryAdapter';\n\nexport class QueryAdapterMongodb<T = any>\n implements QueryAdapter.QueryAdapter<T>\n{\n constructor(private cursor: FindCursor) {}\n\n getModelName(): string {\n return this.cursor.namespace.collection!;\n }\n\n getOptions(): QueryAdapter.Options {\n const findOptions = (this.cursor as any).findOptions as FindOptions;\n\n return {\n limit: findOptions.limit,\n sort: findOptions.sort,\n };\n }\n\n getFilter(): QueryAdapter.Filter {\n return (this.cursor as any).cursorFilter;\n }\n\n setOptions({ limit, sort }: QueryAdapter.Options): void {\n if (limit !== undefined) this.cursor.limit(limit);\n if (sort !== undefined) this.cursor.sort(sort);\n }\n\n setFilter(filter: QueryAdapter.Filter): void {\n this.cursor.filter(filter);\n }\n\n toArray(): Promise<T[]> {\n return this.cursor.toArray();\n }\n\n stream(): Readable {\n return this.cursor.stream();\n }\n}\n","import type { FindCursor } from 'mongodb';\nimport { QueryAdapterMongodb } from './QueryAdapterMongodb';\nimport { QueryPaginator, type QueryPaginatorOptions } from './QueryPaginator';\n\ntype ExtractSchema<T> = T extends FindCursor<infer X> ? X : never;\n\n/**\n * Enhances a MongoDB `FindCursor` with pagination capabilities.\n *\n * @param cursor - The MongoDB cursor to be paginated.\n * @param [options] - Optional configuration for pagination.\n *\n * @example\n * // Basic usage with a MongoDB cursor:\n * import { MongoClient } from 'mongodb';\n *\n * async function paginateCollection() {\n * const client = new MongoClient('mongodb://localhost:27017');\n * await client.connect();\n *\n * const db = client.db('exampleDb');\n * const collection = db.collection('exampleCollection');\n *\n * const cursor = collection.find({ status: 'active' });\n *\n * const paginator = withMongoPagination(cursor, {\n * paginationFields: ['_id'],\n * next: null,\n * });\n *\n * const result = await paginator.exec();\n * console.log(result.items); // Logs the items for the current page\n * console.log(result.metadata); // Logs pagination metadata\n * }\n *\n *\n * @example\n * // Using a custom preQuery callback:\n * const paginator = withMongoPagination(cursor, {\n * preQuery: function () {\n * console.log('Executing query...');\n * },\n * });\n *\n * const result = await paginator.exec();\n * console.log(result.items);\n *\n * @group Main\n */\nexport function withMongoPagination<T extends FindCursor>(\n cursor: T,\n options?: QueryPaginatorOptions,\n): QueryPaginator<ExtractSchema<T>> {\n const adapter = new QueryAdapterMongodb(cursor);\n const pagin = new QueryPaginator(adapter, options);\n\n return pagin;\n}\n"],"names":[],"mappings":";;;;;;;;;AAIO,MAAM,mBAEb,CAAA;AAAA,EACE,YAAoB,MAAoB,EAAA;AAApB,IAAA,IAAA,CAAA,MAAA,GAAA,MAAA,CAAA;AAAA,GAAqB;AAAA,EAEzC,YAAuB,GAAA;AACrB,IAAO,OAAA,IAAA,CAAK,OAAO,SAAU,CAAA,UAAA,CAAA;AAAA,GAC/B;AAAA,EAEA,UAAmC,GAAA;AACjC,IAAM,MAAA,WAAA,GAAe,KAAK,MAAe,CAAA,WAAA,CAAA;AAEzC,IAAO,OAAA;AAAA,MACL,OAAO,WAAY,CAAA,KAAA;AAAA,MACnB,MAAM,WAAY,CAAA,IAAA;AAAA,KACpB,CAAA;AAAA,GACF;AAAA,EAEA,SAAiC,GAAA;AAC/B,IAAA,OAAQ,KAAK,MAAe,CAAA,YAAA,CAAA;AAAA,GAC9B;AAAA,EAEA,UAAW,CAAA,EAAE,KAAO,EAAA,IAAA,EAAoC,EAAA;AACtD,IAAA,IAAI,KAAU,KAAA,KAAA,CAAA,EAAgB,IAAA,CAAA,MAAA,CAAO,MAAM,KAAK,CAAA,CAAA;AAChD,IAAA,IAAI,IAAS,KAAA,KAAA,CAAA,EAAgB,IAAA,CAAA,MAAA,CAAO,KAAK,IAAI,CAAA,CAAA;AAAA,GAC/C;AAAA,EAEA,UAAU,MAAmC,EAAA;AAC3C,IAAK,IAAA,CAAA,MAAA,CAAO,OAAO,MAAM,CAAA,CAAA;AAAA,GAC3B;AAAA,EAEA,OAAwB,GAAA;AACtB,IAAO,OAAA,IAAA,CAAK,OAAO,OAAQ,EAAA,CAAA;AAAA,GAC7B;AAAA,EAEA,MAAmB,GAAA;AACjB,IAAO,OAAA,IAAA,CAAK,OAAO,MAAO,EAAA,CAAA;AAAA,GAC5B;AACF;;ACOgB,SAAA,mBAAA,CACd,QACA,OACkC,EAAA;AAClC,EAAM,MAAA,OAAA,GAAU,IAAI,mBAAA,CAAoB,MAAM,CAAA,CAAA;AAC9C,EAAA,MAAM,KAAQ,GAAA,IAAI,cAAe,CAAA,OAAA,EAAS,OAAO,CAAA,CAAA;AAEjD,EAAO,OAAA,KAAA,CAAA;AACT;;;;"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const withMongoosePagination = require('./shared/mongo-pagination.CHC5agt7.cjs');
|
|
4
|
+
require('@andrew_l/toolkit');
|
|
5
|
+
require('kareem');
|
|
6
|
+
require('mongodb');
|
|
7
|
+
require('@andrew_l/tl-pack');
|
|
8
|
+
require('debug');
|
|
9
|
+
require('node:stream');
|
|
10
|
+
|
|
11
|
+
function setupPlugin(mongoose) {
|
|
12
|
+
const Query = mongoose.Query;
|
|
13
|
+
Query.prototype.paginator = paginator;
|
|
14
|
+
Query.prototype.paginatorNext = paginatorNext;
|
|
15
|
+
}
|
|
16
|
+
function paginator(options = {}) {
|
|
17
|
+
const query = this;
|
|
18
|
+
if (arguments.length === 0 && query._paginator) {
|
|
19
|
+
return query._paginator;
|
|
20
|
+
}
|
|
21
|
+
query._paginator = withMongoosePagination.withMongoosePagination(query, options);
|
|
22
|
+
return query._paginator;
|
|
23
|
+
}
|
|
24
|
+
function paginatorNext(nextToken) {
|
|
25
|
+
const query = this;
|
|
26
|
+
if (arguments.length === 0 && query._paginator) {
|
|
27
|
+
return query._paginator;
|
|
28
|
+
}
|
|
29
|
+
query._paginator = withMongoosePagination.withMongoosePagination(query, {
|
|
30
|
+
next: nextToken
|
|
31
|
+
});
|
|
32
|
+
return query._paginator;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
module.exports = setupPlugin;
|
|
36
|
+
//# sourceMappingURL=mongoose-7.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mongoose-7.cjs","sources":["../src/mongoose-7.ts"],"sourcesContent":["import type { Query } from 'mongoose';\nimport type { QueryPaginator, QueryPaginatorOptions } from './QueryPaginator';\nimport { withMongoosePagination } from './withMongoosePagination';\n\ntype MongooseQuery = Query<any, any> & {\n /** @internal */\n _paginator?: QueryPaginator;\n};\n\nexport default function setupPlugin(mongoose: any) {\n const Query = mongoose.Query;\n\n Query.prototype.paginator = paginator;\n Query.prototype.paginatorNext = paginatorNext;\n}\n\nfunction paginator(this: MongooseQuery, options: QueryPaginatorOptions = {}) {\n const query = this;\n\n if (arguments.length === 0 && query._paginator) {\n return query._paginator;\n }\n\n query._paginator = withMongoosePagination(query, options);\n\n return query._paginator;\n}\n\nfunction paginatorNext(this: MongooseQuery, nextToken: string) {\n const query = this;\n\n if (arguments.length === 0 && query._paginator) {\n return query._paginator;\n }\n\n query._paginator = withMongoosePagination(query, {\n next: nextToken,\n });\n\n return query._paginator;\n}\n\ndeclare module 'mongoose' {\n /**\n * Patch original mongoose types\n */\n // @ts-expect-error\n interface Query<ResultType, DocType, THelpers = {}, RawDocType = DocType> {\n paginator(options?: QueryPaginatorOptions): QueryPaginator<ResultType>;\n paginatorNext(nextToken: string): QueryPaginator<ResultType>;\n }\n}\n"],"names":["withMongoosePagination"],"mappings":";;;;;;;;;;AASA,SAAwB,YAAY,QAAe,EAAA;AACjD,EAAA,MAAM,QAAQ,QAAS,CAAA,KAAA,CAAA;AAEvB,EAAA,KAAA,CAAM,UAAU,SAAY,GAAA,SAAA,CAAA;AAC5B,EAAA,KAAA,CAAM,UAAU,aAAgB,GAAA,aAAA,CAAA;AAClC,CAAA;AAEA,SAAS,SAAA,CAA+B,OAAiC,GAAA,EAAI,EAAA;AAC3E,EAAA,MAAM,KAAQ,GAAA,IAAA,CAAA;AAEd,EAAA,IAAI,SAAU,CAAA,MAAA,KAAW,CAAK,IAAA,KAAA,CAAM,UAAY,EAAA;AAC9C,IAAA,OAAO,KAAM,CAAA,UAAA,CAAA;AAAA,GACf;AAEA,EAAM,KAAA,CAAA,UAAA,GAAaA,6CAAuB,CAAA,KAAA,EAAO,OAAO,CAAA,CAAA;AAExD,EAAA,OAAO,KAAM,CAAA,UAAA,CAAA;AACf,CAAA;AAEA,SAAS,cAAmC,SAAmB,EAAA;AAC7D,EAAA,MAAM,KAAQ,GAAA,IAAA,CAAA;AAEd,EAAA,IAAI,SAAU,CAAA,MAAA,KAAW,CAAK,IAAA,KAAA,CAAM,UAAY,EAAA;AAC9C,IAAA,OAAO,KAAM,CAAA,UAAA,CAAA;AAAA,GACf;AAEA,EAAM,KAAA,CAAA,UAAA,GAAaA,8CAAuB,KAAO,EAAA;AAAA,IAC/C,IAAM,EAAA,SAAA;AAAA,GACP,CAAA,CAAA;AAED,EAAA,OAAO,KAAM,CAAA,UAAA,CAAA;AACf;;;;"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { a as QueryPaginatorOptions, b as QueryPaginator } from './shared/mongo-pagination.BU3-d0QB.cjs';
|
|
2
|
+
import 'node:stream';
|
|
3
|
+
import 'mongodb';
|
|
4
|
+
|
|
5
|
+
declare function setupPlugin(mongoose: any): void;
|
|
6
|
+
declare module 'mongoose' {
|
|
7
|
+
/**
|
|
8
|
+
* Patch original mongoose types
|
|
9
|
+
*/
|
|
10
|
+
interface Query<ResultType, DocType, THelpers = {}, RawDocType = DocType> {
|
|
11
|
+
paginator(options?: QueryPaginatorOptions): QueryPaginator<ResultType>;
|
|
12
|
+
paginatorNext(nextToken: string): QueryPaginator<ResultType>;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export { setupPlugin as default };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { a as QueryPaginatorOptions, b as QueryPaginator } from './shared/mongo-pagination.BU3-d0QB.mjs';
|
|
2
|
+
import 'node:stream';
|
|
3
|
+
import 'mongodb';
|
|
4
|
+
|
|
5
|
+
declare function setupPlugin(mongoose: any): void;
|
|
6
|
+
declare module 'mongoose' {
|
|
7
|
+
/**
|
|
8
|
+
* Patch original mongoose types
|
|
9
|
+
*/
|
|
10
|
+
interface Query<ResultType, DocType, THelpers = {}, RawDocType = DocType> {
|
|
11
|
+
paginator(options?: QueryPaginatorOptions): QueryPaginator<ResultType>;
|
|
12
|
+
paginatorNext(nextToken: string): QueryPaginator<ResultType>;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export { setupPlugin as default };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { a as QueryPaginatorOptions, b as QueryPaginator } from './shared/mongo-pagination.BU3-d0QB.js';
|
|
2
|
+
import 'node:stream';
|
|
3
|
+
import 'mongodb';
|
|
4
|
+
|
|
5
|
+
declare function setupPlugin(mongoose: any): void;
|
|
6
|
+
declare module 'mongoose' {
|
|
7
|
+
/**
|
|
8
|
+
* Patch original mongoose types
|
|
9
|
+
*/
|
|
10
|
+
interface Query<ResultType, DocType, THelpers = {}, RawDocType = DocType> {
|
|
11
|
+
paginator(options?: QueryPaginatorOptions): QueryPaginator<ResultType>;
|
|
12
|
+
paginatorNext(nextToken: string): QueryPaginator<ResultType>;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export { setupPlugin as default };
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { w as withMongoosePagination } from './shared/mongo-pagination.YG1DNE27.mjs';
|
|
2
|
+
import '@andrew_l/toolkit';
|
|
3
|
+
import 'kareem';
|
|
4
|
+
import 'mongodb';
|
|
5
|
+
import '@andrew_l/tl-pack';
|
|
6
|
+
import 'debug';
|
|
7
|
+
import 'node:stream';
|
|
8
|
+
|
|
9
|
+
function setupPlugin(mongoose) {
|
|
10
|
+
const Query = mongoose.Query;
|
|
11
|
+
Query.prototype.paginator = paginator;
|
|
12
|
+
Query.prototype.paginatorNext = paginatorNext;
|
|
13
|
+
}
|
|
14
|
+
function paginator(options = {}) {
|
|
15
|
+
const query = this;
|
|
16
|
+
if (arguments.length === 0 && query._paginator) {
|
|
17
|
+
return query._paginator;
|
|
18
|
+
}
|
|
19
|
+
query._paginator = withMongoosePagination(query, options);
|
|
20
|
+
return query._paginator;
|
|
21
|
+
}
|
|
22
|
+
function paginatorNext(nextToken) {
|
|
23
|
+
const query = this;
|
|
24
|
+
if (arguments.length === 0 && query._paginator) {
|
|
25
|
+
return query._paginator;
|
|
26
|
+
}
|
|
27
|
+
query._paginator = withMongoosePagination(query, {
|
|
28
|
+
next: nextToken
|
|
29
|
+
});
|
|
30
|
+
return query._paginator;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export { setupPlugin as default };
|
|
34
|
+
//# sourceMappingURL=mongoose-7.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mongoose-7.mjs","sources":["../src/mongoose-7.ts"],"sourcesContent":["import type { Query } from 'mongoose';\nimport type { QueryPaginator, QueryPaginatorOptions } from './QueryPaginator';\nimport { withMongoosePagination } from './withMongoosePagination';\n\ntype MongooseQuery = Query<any, any> & {\n /** @internal */\n _paginator?: QueryPaginator;\n};\n\nexport default function setupPlugin(mongoose: any) {\n const Query = mongoose.Query;\n\n Query.prototype.paginator = paginator;\n Query.prototype.paginatorNext = paginatorNext;\n}\n\nfunction paginator(this: MongooseQuery, options: QueryPaginatorOptions = {}) {\n const query = this;\n\n if (arguments.length === 0 && query._paginator) {\n return query._paginator;\n }\n\n query._paginator = withMongoosePagination(query, options);\n\n return query._paginator;\n}\n\nfunction paginatorNext(this: MongooseQuery, nextToken: string) {\n const query = this;\n\n if (arguments.length === 0 && query._paginator) {\n return query._paginator;\n }\n\n query._paginator = withMongoosePagination(query, {\n next: nextToken,\n });\n\n return query._paginator;\n}\n\ndeclare module 'mongoose' {\n /**\n * Patch original mongoose types\n */\n // @ts-expect-error\n interface Query<ResultType, DocType, THelpers = {}, RawDocType = DocType> {\n paginator(options?: QueryPaginatorOptions): QueryPaginator<ResultType>;\n paginatorNext(nextToken: string): QueryPaginator<ResultType>;\n }\n}\n"],"names":[],"mappings":";;;;;;;;AASA,SAAwB,YAAY,QAAe,EAAA;AACjD,EAAA,MAAM,QAAQ,QAAS,CAAA,KAAA,CAAA;AAEvB,EAAA,KAAA,CAAM,UAAU,SAAY,GAAA,SAAA,CAAA;AAC5B,EAAA,KAAA,CAAM,UAAU,aAAgB,GAAA,aAAA,CAAA;AAClC,CAAA;AAEA,SAAS,SAAA,CAA+B,OAAiC,GAAA,EAAI,EAAA;AAC3E,EAAA,MAAM,KAAQ,GAAA,IAAA,CAAA;AAEd,EAAA,IAAI,SAAU,CAAA,MAAA,KAAW,CAAK,IAAA,KAAA,CAAM,UAAY,EAAA;AAC9C,IAAA,OAAO,KAAM,CAAA,UAAA,CAAA;AAAA,GACf;AAEA,EAAM,KAAA,CAAA,UAAA,GAAa,sBAAuB,CAAA,KAAA,EAAO,OAAO,CAAA,CAAA;AAExD,EAAA,OAAO,KAAM,CAAA,UAAA,CAAA;AACf,CAAA;AAEA,SAAS,cAAmC,SAAmB,EAAA;AAC7D,EAAA,MAAM,KAAQ,GAAA,IAAA,CAAA;AAEd,EAAA,IAAI,SAAU,CAAA,MAAA,KAAW,CAAK,IAAA,KAAA,CAAM,UAAY,EAAA;AAC9C,IAAA,OAAO,KAAM,CAAA,UAAA,CAAA;AAAA,GACf;AAEA,EAAM,KAAA,CAAA,UAAA,GAAa,uBAAuB,KAAO,EAAA;AAAA,IAC/C,IAAM,EAAA,SAAA;AAAA,GACP,CAAA,CAAA;AAED,EAAA,OAAO,KAAM,CAAA,UAAA,CAAA;AACf;;;;"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const withMongoosePagination = require('./shared/mongo-pagination.CHC5agt7.cjs');
|
|
4
|
+
require('@andrew_l/toolkit');
|
|
5
|
+
require('kareem');
|
|
6
|
+
require('mongodb');
|
|
7
|
+
require('@andrew_l/tl-pack');
|
|
8
|
+
require('debug');
|
|
9
|
+
require('node:stream');
|
|
10
|
+
|
|
11
|
+
function setupPlugin(mongoose) {
|
|
12
|
+
const Query = mongoose.Query;
|
|
13
|
+
Query.prototype.paginator = paginator;
|
|
14
|
+
Query.prototype.paginatorNext = paginatorNext;
|
|
15
|
+
}
|
|
16
|
+
function paginator(options = {}) {
|
|
17
|
+
const query = this;
|
|
18
|
+
if (arguments.length === 0 && query._paginator) {
|
|
19
|
+
return query._paginator;
|
|
20
|
+
}
|
|
21
|
+
query._paginator = withMongoosePagination.withMongoosePagination(query, options);
|
|
22
|
+
return query._paginator;
|
|
23
|
+
}
|
|
24
|
+
function paginatorNext(nextToken) {
|
|
25
|
+
const query = this;
|
|
26
|
+
if (arguments.length === 0 && query._paginator) {
|
|
27
|
+
return query._paginator;
|
|
28
|
+
}
|
|
29
|
+
query._paginator = withMongoosePagination.withMongoosePagination(query, {
|
|
30
|
+
next: nextToken
|
|
31
|
+
});
|
|
32
|
+
return query._paginator;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
module.exports = setupPlugin;
|
|
36
|
+
//# sourceMappingURL=mongoose-8.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mongoose-8.cjs","sources":["../src/mongoose-8.ts"],"sourcesContent":["import type { Query } from 'mongoose';\nimport type { QueryPaginator, QueryPaginatorOptions } from './QueryPaginator';\nimport { withMongoosePagination } from './withMongoosePagination';\n\ntype MongooseQuery = Query<any, any> & {\n /** @internal */\n _paginator?: QueryPaginator;\n};\n\nexport default function setupPlugin(mongoose: any) {\n const Query = mongoose.Query;\n\n Query.prototype.paginator = paginator;\n Query.prototype.paginatorNext = paginatorNext;\n}\n\nfunction paginator(this: MongooseQuery, options: QueryPaginatorOptions = {}) {\n const query = this;\n\n if (arguments.length === 0 && query._paginator) {\n return query._paginator;\n }\n\n query._paginator = withMongoosePagination(query, options);\n\n return query._paginator;\n}\n\nfunction paginatorNext(this: MongooseQuery, nextToken: string) {\n const query = this;\n\n if (arguments.length === 0 && query._paginator) {\n return query._paginator;\n }\n\n query._paginator = withMongoosePagination(query, {\n next: nextToken,\n });\n\n return query._paginator;\n}\n\ndeclare module 'mongoose' {\n /**\n * Patch original mongoose types\n */\n // @ts-expect-error\n class Query<\n ResultType,\n DocType,\n THelpers = {},\n RawDocType = unknown,\n QueryOp = 'find',\n TInstanceMethods = Record<string, never>,\n > implements SessionOperation\n {\n paginator(options?: QueryPaginatorOptions): QueryPaginator<ResultType>;\n paginatorNext(nextToken: string): QueryPaginator<ResultType>;\n }\n}\n"],"names":["withMongoosePagination"],"mappings":";;;;;;;;;;AASA,SAAwB,YAAY,QAAe,EAAA;AACjD,EAAA,MAAM,QAAQ,QAAS,CAAA,KAAA,CAAA;AAEvB,EAAA,KAAA,CAAM,UAAU,SAAY,GAAA,SAAA,CAAA;AAC5B,EAAA,KAAA,CAAM,UAAU,aAAgB,GAAA,aAAA,CAAA;AAClC,CAAA;AAEA,SAAS,SAAA,CAA+B,OAAiC,GAAA,EAAI,EAAA;AAC3E,EAAA,MAAM,KAAQ,GAAA,IAAA,CAAA;AAEd,EAAA,IAAI,SAAU,CAAA,MAAA,KAAW,CAAK,IAAA,KAAA,CAAM,UAAY,EAAA;AAC9C,IAAA,OAAO,KAAM,CAAA,UAAA,CAAA;AAAA,GACf;AAEA,EAAM,KAAA,CAAA,UAAA,GAAaA,6CAAuB,CAAA,KAAA,EAAO,OAAO,CAAA,CAAA;AAExD,EAAA,OAAO,KAAM,CAAA,UAAA,CAAA;AACf,CAAA;AAEA,SAAS,cAAmC,SAAmB,EAAA;AAC7D,EAAA,MAAM,KAAQ,GAAA,IAAA,CAAA;AAEd,EAAA,IAAI,SAAU,CAAA,MAAA,KAAW,CAAK,IAAA,KAAA,CAAM,UAAY,EAAA;AAC9C,IAAA,OAAO,KAAM,CAAA,UAAA,CAAA;AAAA,GACf;AAEA,EAAM,KAAA,CAAA,UAAA,GAAaA,8CAAuB,KAAO,EAAA;AAAA,IAC/C,IAAM,EAAA,SAAA;AAAA,GACP,CAAA,CAAA;AAED,EAAA,OAAO,KAAM,CAAA,UAAA,CAAA;AACf;;;;"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { a as QueryPaginatorOptions, b as QueryPaginator } from './shared/mongo-pagination.BU3-d0QB.cjs';
|
|
2
|
+
import 'node:stream';
|
|
3
|
+
import 'mongodb';
|
|
4
|
+
|
|
5
|
+
declare function setupPlugin(mongoose: any): void;
|
|
6
|
+
declare module 'mongoose' {
|
|
7
|
+
/**
|
|
8
|
+
* Patch original mongoose types
|
|
9
|
+
*/
|
|
10
|
+
class Query<ResultType, DocType, THelpers = {}, RawDocType = unknown, QueryOp = 'find', TInstanceMethods = Record<string, never>> implements SessionOperation {
|
|
11
|
+
paginator(options?: QueryPaginatorOptions): QueryPaginator<ResultType>;
|
|
12
|
+
paginatorNext(nextToken: string): QueryPaginator<ResultType>;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export { setupPlugin as default };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { a as QueryPaginatorOptions, b as QueryPaginator } from './shared/mongo-pagination.BU3-d0QB.mjs';
|
|
2
|
+
import 'node:stream';
|
|
3
|
+
import 'mongodb';
|
|
4
|
+
|
|
5
|
+
declare function setupPlugin(mongoose: any): void;
|
|
6
|
+
declare module 'mongoose' {
|
|
7
|
+
/**
|
|
8
|
+
* Patch original mongoose types
|
|
9
|
+
*/
|
|
10
|
+
class Query<ResultType, DocType, THelpers = {}, RawDocType = unknown, QueryOp = 'find', TInstanceMethods = Record<string, never>> implements SessionOperation {
|
|
11
|
+
paginator(options?: QueryPaginatorOptions): QueryPaginator<ResultType>;
|
|
12
|
+
paginatorNext(nextToken: string): QueryPaginator<ResultType>;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export { setupPlugin as default };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { a as QueryPaginatorOptions, b as QueryPaginator } from './shared/mongo-pagination.BU3-d0QB.js';
|
|
2
|
+
import 'node:stream';
|
|
3
|
+
import 'mongodb';
|
|
4
|
+
|
|
5
|
+
declare function setupPlugin(mongoose: any): void;
|
|
6
|
+
declare module 'mongoose' {
|
|
7
|
+
/**
|
|
8
|
+
* Patch original mongoose types
|
|
9
|
+
*/
|
|
10
|
+
class Query<ResultType, DocType, THelpers = {}, RawDocType = unknown, QueryOp = 'find', TInstanceMethods = Record<string, never>> implements SessionOperation {
|
|
11
|
+
paginator(options?: QueryPaginatorOptions): QueryPaginator<ResultType>;
|
|
12
|
+
paginatorNext(nextToken: string): QueryPaginator<ResultType>;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export { setupPlugin as default };
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { w as withMongoosePagination } from './shared/mongo-pagination.YG1DNE27.mjs';
|
|
2
|
+
import '@andrew_l/toolkit';
|
|
3
|
+
import 'kareem';
|
|
4
|
+
import 'mongodb';
|
|
5
|
+
import '@andrew_l/tl-pack';
|
|
6
|
+
import 'debug';
|
|
7
|
+
import 'node:stream';
|
|
8
|
+
|
|
9
|
+
function setupPlugin(mongoose) {
|
|
10
|
+
const Query = mongoose.Query;
|
|
11
|
+
Query.prototype.paginator = paginator;
|
|
12
|
+
Query.prototype.paginatorNext = paginatorNext;
|
|
13
|
+
}
|
|
14
|
+
function paginator(options = {}) {
|
|
15
|
+
const query = this;
|
|
16
|
+
if (arguments.length === 0 && query._paginator) {
|
|
17
|
+
return query._paginator;
|
|
18
|
+
}
|
|
19
|
+
query._paginator = withMongoosePagination(query, options);
|
|
20
|
+
return query._paginator;
|
|
21
|
+
}
|
|
22
|
+
function paginatorNext(nextToken) {
|
|
23
|
+
const query = this;
|
|
24
|
+
if (arguments.length === 0 && query._paginator) {
|
|
25
|
+
return query._paginator;
|
|
26
|
+
}
|
|
27
|
+
query._paginator = withMongoosePagination(query, {
|
|
28
|
+
next: nextToken
|
|
29
|
+
});
|
|
30
|
+
return query._paginator;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export { setupPlugin as default };
|
|
34
|
+
//# sourceMappingURL=mongoose-8.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mongoose-8.mjs","sources":["../src/mongoose-8.ts"],"sourcesContent":["import type { Query } from 'mongoose';\nimport type { QueryPaginator, QueryPaginatorOptions } from './QueryPaginator';\nimport { withMongoosePagination } from './withMongoosePagination';\n\ntype MongooseQuery = Query<any, any> & {\n /** @internal */\n _paginator?: QueryPaginator;\n};\n\nexport default function setupPlugin(mongoose: any) {\n const Query = mongoose.Query;\n\n Query.prototype.paginator = paginator;\n Query.prototype.paginatorNext = paginatorNext;\n}\n\nfunction paginator(this: MongooseQuery, options: QueryPaginatorOptions = {}) {\n const query = this;\n\n if (arguments.length === 0 && query._paginator) {\n return query._paginator;\n }\n\n query._paginator = withMongoosePagination(query, options);\n\n return query._paginator;\n}\n\nfunction paginatorNext(this: MongooseQuery, nextToken: string) {\n const query = this;\n\n if (arguments.length === 0 && query._paginator) {\n return query._paginator;\n }\n\n query._paginator = withMongoosePagination(query, {\n next: nextToken,\n });\n\n return query._paginator;\n}\n\ndeclare module 'mongoose' {\n /**\n * Patch original mongoose types\n */\n // @ts-expect-error\n class Query<\n ResultType,\n DocType,\n THelpers = {},\n RawDocType = unknown,\n QueryOp = 'find',\n TInstanceMethods = Record<string, never>,\n > implements SessionOperation\n {\n paginator(options?: QueryPaginatorOptions): QueryPaginator<ResultType>;\n paginatorNext(nextToken: string): QueryPaginator<ResultType>;\n }\n}\n"],"names":[],"mappings":";;;;;;;;AASA,SAAwB,YAAY,QAAe,EAAA;AACjD,EAAA,MAAM,QAAQ,QAAS,CAAA,KAAA,CAAA;AAEvB,EAAA,KAAA,CAAM,UAAU,SAAY,GAAA,SAAA,CAAA;AAC5B,EAAA,KAAA,CAAM,UAAU,aAAgB,GAAA,aAAA,CAAA;AAClC,CAAA;AAEA,SAAS,SAAA,CAA+B,OAAiC,GAAA,EAAI,EAAA;AAC3E,EAAA,MAAM,KAAQ,GAAA,IAAA,CAAA;AAEd,EAAA,IAAI,SAAU,CAAA,MAAA,KAAW,CAAK,IAAA,KAAA,CAAM,UAAY,EAAA;AAC9C,IAAA,OAAO,KAAM,CAAA,UAAA,CAAA;AAAA,GACf;AAEA,EAAM,KAAA,CAAA,UAAA,GAAa,sBAAuB,CAAA,KAAA,EAAO,OAAO,CAAA,CAAA;AAExD,EAAA,OAAO,KAAM,CAAA,UAAA,CAAA;AACf,CAAA;AAEA,SAAS,cAAmC,SAAmB,EAAA;AAC7D,EAAA,MAAM,KAAQ,GAAA,IAAA,CAAA;AAEd,EAAA,IAAI,SAAU,CAAA,MAAA,KAAW,CAAK,IAAA,KAAA,CAAM,UAAY,EAAA;AAC9C,IAAA,OAAO,KAAM,CAAA,UAAA,CAAA;AAAA,GACf;AAEA,EAAM,KAAA,CAAA,UAAA,GAAa,uBAAuB,KAAO,EAAA;AAAA,IAC/C,IAAM,EAAA,SAAA;AAAA,GACP,CAAA,CAAA;AAED,EAAA,OAAO,KAAM,CAAA,UAAA,CAAA;AACf;;;;"}
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
import internal, { Readable } from 'node:stream';
|
|
2
|
+
import { Sort } from 'mongodb';
|
|
3
|
+
|
|
4
|
+
interface TokenOptions {
|
|
5
|
+
/**
|
|
6
|
+
* The schema version of the token.
|
|
7
|
+
*/
|
|
8
|
+
schemaVersion: number;
|
|
9
|
+
/**
|
|
10
|
+
* The name of the model the token is related to.
|
|
11
|
+
*/
|
|
12
|
+
modelName?: string;
|
|
13
|
+
/**
|
|
14
|
+
* The sorting direction used to building pagination query.
|
|
15
|
+
*/
|
|
16
|
+
sortDirection?: Record<string, any>;
|
|
17
|
+
/**
|
|
18
|
+
* The values associated with sorting.
|
|
19
|
+
* Used in conjunction with `sortDirection` to building range query.
|
|
20
|
+
*/
|
|
21
|
+
sortValues?: Record<string, any>;
|
|
22
|
+
/**
|
|
23
|
+
* The payload of the token. Contains additional data or metadata (can be `null`).
|
|
24
|
+
*/
|
|
25
|
+
payload: Record<string, any> | null;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Represents a token with pagination and metadata information.
|
|
29
|
+
* This class holds the token data, including sorting details, and any payload.
|
|
30
|
+
*/
|
|
31
|
+
declare class Token {
|
|
32
|
+
/**
|
|
33
|
+
* The schema version of the token.
|
|
34
|
+
*/
|
|
35
|
+
schemaVersion: number;
|
|
36
|
+
/**
|
|
37
|
+
* The CRC of the model name, used for verify the model.
|
|
38
|
+
*/
|
|
39
|
+
modelNameCRC: number;
|
|
40
|
+
/**
|
|
41
|
+
* The sorting direction used for pagination building pagination query.
|
|
42
|
+
*/
|
|
43
|
+
sortDirection: Record<string, any>;
|
|
44
|
+
/**
|
|
45
|
+
* The sorting values associated with the pagination.
|
|
46
|
+
*/
|
|
47
|
+
sortValues: Record<string, any>;
|
|
48
|
+
/**
|
|
49
|
+
* The payload of the token, which can contain any associated metadata or data (may be `null`).
|
|
50
|
+
*/
|
|
51
|
+
payload: Record<string, any> | null;
|
|
52
|
+
constructor(options?: Partial<TokenOptions>);
|
|
53
|
+
/**
|
|
54
|
+
* Retrieves the string representation of token.
|
|
55
|
+
*/
|
|
56
|
+
stringify(): string;
|
|
57
|
+
/**
|
|
58
|
+
* Retrieves binary buffer representation of token.
|
|
59
|
+
*/
|
|
60
|
+
buffer(): Buffer;
|
|
61
|
+
/**
|
|
62
|
+
* Encode token from provided value
|
|
63
|
+
*/
|
|
64
|
+
static from(value: string | Buffer): Token;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Create a token with pagination and metadata information.
|
|
68
|
+
* This holds the token data, including sorting details, and any payload.
|
|
69
|
+
*
|
|
70
|
+
* @group Utils
|
|
71
|
+
*/
|
|
72
|
+
declare function createToken(options?: Partial<TokenOptions>): Token;
|
|
73
|
+
|
|
74
|
+
declare namespace QueryAdapter {
|
|
75
|
+
type Options = {
|
|
76
|
+
sort?: Sort;
|
|
77
|
+
limit?: number;
|
|
78
|
+
};
|
|
79
|
+
type Filter = Record<string, any>;
|
|
80
|
+
interface QueryAdapter<T = any> {
|
|
81
|
+
getModelName(): string;
|
|
82
|
+
getOptions(): Options;
|
|
83
|
+
getFilter(): Filter;
|
|
84
|
+
setOptions(options: Options): void;
|
|
85
|
+
setFilter(filter: Filter): void;
|
|
86
|
+
toArray(): Promise<T[]>;
|
|
87
|
+
stream(): Readable;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
interface QueryPaginatorOptions {
|
|
92
|
+
/**
|
|
93
|
+
* An optional list of fields used for building pagination query.
|
|
94
|
+
*/
|
|
95
|
+
paginationFields?: string[];
|
|
96
|
+
/**
|
|
97
|
+
* The token to start the pagination from, if available.
|
|
98
|
+
*/
|
|
99
|
+
next?: string | Buffer | null;
|
|
100
|
+
/**
|
|
101
|
+
* A callback function executed before the query is performed.
|
|
102
|
+
*/
|
|
103
|
+
preQuery?: (this: QueryPaginator) => void;
|
|
104
|
+
/**
|
|
105
|
+
* A callback function executed after the query is performed.
|
|
106
|
+
*/
|
|
107
|
+
postQuery?: (this: QueryPaginator) => void;
|
|
108
|
+
/** @internal */
|
|
109
|
+
debugQuery?: boolean;
|
|
110
|
+
}
|
|
111
|
+
interface QueryPaginatorMeta {
|
|
112
|
+
/**
|
|
113
|
+
* Indicates whether there is a next page available.
|
|
114
|
+
*/
|
|
115
|
+
hasNext: boolean;
|
|
116
|
+
/**
|
|
117
|
+
* The token for the next page, or `null` if there is no next page.
|
|
118
|
+
*/
|
|
119
|
+
next: string | null;
|
|
120
|
+
}
|
|
121
|
+
interface QueryPaginatorResult<T> {
|
|
122
|
+
/**
|
|
123
|
+
* The list of items for the current page.
|
|
124
|
+
*/
|
|
125
|
+
items: T[];
|
|
126
|
+
/**
|
|
127
|
+
* Metadata providing information about pagination, such as whether more pages are available.
|
|
128
|
+
*/
|
|
129
|
+
metadata: QueryPaginatorMeta;
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* A generic class for handling query pagination.
|
|
133
|
+
*
|
|
134
|
+
* Look at `withMongoPagination` and `withMongoosePagination`
|
|
135
|
+
*
|
|
136
|
+
* @group Main
|
|
137
|
+
*/
|
|
138
|
+
declare class QueryPaginator<T = any> {
|
|
139
|
+
private query;
|
|
140
|
+
private hooks;
|
|
141
|
+
private next;
|
|
142
|
+
private previous?;
|
|
143
|
+
private resHasNext;
|
|
144
|
+
private resLastItem;
|
|
145
|
+
private paginationFields;
|
|
146
|
+
private tweaked;
|
|
147
|
+
private debugQuery;
|
|
148
|
+
getMetadata: () => QueryPaginatorMeta;
|
|
149
|
+
constructor(query: QueryAdapter.QueryAdapter, { paginationFields, postQuery, preQuery, next: previousToken, debugQuery, }?: QueryPaginatorOptions);
|
|
150
|
+
/**
|
|
151
|
+
* Retrieves metadata about the current state of pagination.
|
|
152
|
+
*/
|
|
153
|
+
get metadata(): QueryPaginatorMeta;
|
|
154
|
+
/**
|
|
155
|
+
* Indicates whether there is a next page available.
|
|
156
|
+
*/
|
|
157
|
+
get hasNext(): boolean;
|
|
158
|
+
/**
|
|
159
|
+
* Retrieves the token for the next page.
|
|
160
|
+
*/
|
|
161
|
+
get nextToken(): Token;
|
|
162
|
+
/**
|
|
163
|
+
* Retrieves the string representation of the next page token.
|
|
164
|
+
* If there is no next page, returns `null`.
|
|
165
|
+
*/
|
|
166
|
+
get nextTokenString(): string | null;
|
|
167
|
+
/**
|
|
168
|
+
* Retrieves the token for the previous page.
|
|
169
|
+
*/
|
|
170
|
+
get prevToken(): Token | null;
|
|
171
|
+
/**
|
|
172
|
+
* Retrieves the string representation of the previous page token.
|
|
173
|
+
*/
|
|
174
|
+
get prevTokenString(): string | null;
|
|
175
|
+
getQuery(): QueryAdapter.QueryAdapter<any>;
|
|
176
|
+
pre(hookName: string, fn: Function): this;
|
|
177
|
+
post(hookName: string, fn: Function): this;
|
|
178
|
+
stream(): Promise<internal.Transform>;
|
|
179
|
+
/** @internal */
|
|
180
|
+
maybeTweak(): this;
|
|
181
|
+
/** @internal */
|
|
182
|
+
tweak(): this;
|
|
183
|
+
/** @internal */
|
|
184
|
+
_handleResult(items: any[]): QueryPaginatorResult<any>;
|
|
185
|
+
/**
|
|
186
|
+
* Executes the query and returns the results along with pagination metadata.
|
|
187
|
+
*/
|
|
188
|
+
exec(): Promise<QueryPaginatorResult<T>>;
|
|
189
|
+
then: Promise<QueryPaginatorResult<T>>["then"];
|
|
190
|
+
cath: Promise<QueryPaginatorResult<T>>["catch"];
|
|
191
|
+
finally: Promise<QueryPaginatorResult<T>>["finally"];
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
export { QueryAdapter as Q, Token as T, type QueryPaginatorOptions as a, QueryPaginator as b, type QueryPaginatorMeta as c, type QueryPaginatorResult as d, createToken as e, type TokenOptions as f };
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
import internal, { Readable } from 'node:stream';
|
|
2
|
+
import { Sort } from 'mongodb';
|
|
3
|
+
|
|
4
|
+
interface TokenOptions {
|
|
5
|
+
/**
|
|
6
|
+
* The schema version of the token.
|
|
7
|
+
*/
|
|
8
|
+
schemaVersion: number;
|
|
9
|
+
/**
|
|
10
|
+
* The name of the model the token is related to.
|
|
11
|
+
*/
|
|
12
|
+
modelName?: string;
|
|
13
|
+
/**
|
|
14
|
+
* The sorting direction used to building pagination query.
|
|
15
|
+
*/
|
|
16
|
+
sortDirection?: Record<string, any>;
|
|
17
|
+
/**
|
|
18
|
+
* The values associated with sorting.
|
|
19
|
+
* Used in conjunction with `sortDirection` to building range query.
|
|
20
|
+
*/
|
|
21
|
+
sortValues?: Record<string, any>;
|
|
22
|
+
/**
|
|
23
|
+
* The payload of the token. Contains additional data or metadata (can be `null`).
|
|
24
|
+
*/
|
|
25
|
+
payload: Record<string, any> | null;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Represents a token with pagination and metadata information.
|
|
29
|
+
* This class holds the token data, including sorting details, and any payload.
|
|
30
|
+
*/
|
|
31
|
+
declare class Token {
|
|
32
|
+
/**
|
|
33
|
+
* The schema version of the token.
|
|
34
|
+
*/
|
|
35
|
+
schemaVersion: number;
|
|
36
|
+
/**
|
|
37
|
+
* The CRC of the model name, used for verify the model.
|
|
38
|
+
*/
|
|
39
|
+
modelNameCRC: number;
|
|
40
|
+
/**
|
|
41
|
+
* The sorting direction used for pagination building pagination query.
|
|
42
|
+
*/
|
|
43
|
+
sortDirection: Record<string, any>;
|
|
44
|
+
/**
|
|
45
|
+
* The sorting values associated with the pagination.
|
|
46
|
+
*/
|
|
47
|
+
sortValues: Record<string, any>;
|
|
48
|
+
/**
|
|
49
|
+
* The payload of the token, which can contain any associated metadata or data (may be `null`).
|
|
50
|
+
*/
|
|
51
|
+
payload: Record<string, any> | null;
|
|
52
|
+
constructor(options?: Partial<TokenOptions>);
|
|
53
|
+
/**
|
|
54
|
+
* Retrieves the string representation of token.
|
|
55
|
+
*/
|
|
56
|
+
stringify(): string;
|
|
57
|
+
/**
|
|
58
|
+
* Retrieves binary buffer representation of token.
|
|
59
|
+
*/
|
|
60
|
+
buffer(): Buffer;
|
|
61
|
+
/**
|
|
62
|
+
* Encode token from provided value
|
|
63
|
+
*/
|
|
64
|
+
static from(value: string | Buffer): Token;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Create a token with pagination and metadata information.
|
|
68
|
+
* This holds the token data, including sorting details, and any payload.
|
|
69
|
+
*
|
|
70
|
+
* @group Utils
|
|
71
|
+
*/
|
|
72
|
+
declare function createToken(options?: Partial<TokenOptions>): Token;
|
|
73
|
+
|
|
74
|
+
declare namespace QueryAdapter {
|
|
75
|
+
type Options = {
|
|
76
|
+
sort?: Sort;
|
|
77
|
+
limit?: number;
|
|
78
|
+
};
|
|
79
|
+
type Filter = Record<string, any>;
|
|
80
|
+
interface QueryAdapter<T = any> {
|
|
81
|
+
getModelName(): string;
|
|
82
|
+
getOptions(): Options;
|
|
83
|
+
getFilter(): Filter;
|
|
84
|
+
setOptions(options: Options): void;
|
|
85
|
+
setFilter(filter: Filter): void;
|
|
86
|
+
toArray(): Promise<T[]>;
|
|
87
|
+
stream(): Readable;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
interface QueryPaginatorOptions {
|
|
92
|
+
/**
|
|
93
|
+
* An optional list of fields used for building pagination query.
|
|
94
|
+
*/
|
|
95
|
+
paginationFields?: string[];
|
|
96
|
+
/**
|
|
97
|
+
* The token to start the pagination from, if available.
|
|
98
|
+
*/
|
|
99
|
+
next?: string | Buffer | null;
|
|
100
|
+
/**
|
|
101
|
+
* A callback function executed before the query is performed.
|
|
102
|
+
*/
|
|
103
|
+
preQuery?: (this: QueryPaginator) => void;
|
|
104
|
+
/**
|
|
105
|
+
* A callback function executed after the query is performed.
|
|
106
|
+
*/
|
|
107
|
+
postQuery?: (this: QueryPaginator) => void;
|
|
108
|
+
/** @internal */
|
|
109
|
+
debugQuery?: boolean;
|
|
110
|
+
}
|
|
111
|
+
interface QueryPaginatorMeta {
|
|
112
|
+
/**
|
|
113
|
+
* Indicates whether there is a next page available.
|
|
114
|
+
*/
|
|
115
|
+
hasNext: boolean;
|
|
116
|
+
/**
|
|
117
|
+
* The token for the next page, or `null` if there is no next page.
|
|
118
|
+
*/
|
|
119
|
+
next: string | null;
|
|
120
|
+
}
|
|
121
|
+
interface QueryPaginatorResult<T> {
|
|
122
|
+
/**
|
|
123
|
+
* The list of items for the current page.
|
|
124
|
+
*/
|
|
125
|
+
items: T[];
|
|
126
|
+
/**
|
|
127
|
+
* Metadata providing information about pagination, such as whether more pages are available.
|
|
128
|
+
*/
|
|
129
|
+
metadata: QueryPaginatorMeta;
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* A generic class for handling query pagination.
|
|
133
|
+
*
|
|
134
|
+
* Look at `withMongoPagination` and `withMongoosePagination`
|
|
135
|
+
*
|
|
136
|
+
* @group Main
|
|
137
|
+
*/
|
|
138
|
+
declare class QueryPaginator<T = any> {
|
|
139
|
+
private query;
|
|
140
|
+
private hooks;
|
|
141
|
+
private next;
|
|
142
|
+
private previous?;
|
|
143
|
+
private resHasNext;
|
|
144
|
+
private resLastItem;
|
|
145
|
+
private paginationFields;
|
|
146
|
+
private tweaked;
|
|
147
|
+
private debugQuery;
|
|
148
|
+
getMetadata: () => QueryPaginatorMeta;
|
|
149
|
+
constructor(query: QueryAdapter.QueryAdapter, { paginationFields, postQuery, preQuery, next: previousToken, debugQuery, }?: QueryPaginatorOptions);
|
|
150
|
+
/**
|
|
151
|
+
* Retrieves metadata about the current state of pagination.
|
|
152
|
+
*/
|
|
153
|
+
get metadata(): QueryPaginatorMeta;
|
|
154
|
+
/**
|
|
155
|
+
* Indicates whether there is a next page available.
|
|
156
|
+
*/
|
|
157
|
+
get hasNext(): boolean;
|
|
158
|
+
/**
|
|
159
|
+
* Retrieves the token for the next page.
|
|
160
|
+
*/
|
|
161
|
+
get nextToken(): Token;
|
|
162
|
+
/**
|
|
163
|
+
* Retrieves the string representation of the next page token.
|
|
164
|
+
* If there is no next page, returns `null`.
|
|
165
|
+
*/
|
|
166
|
+
get nextTokenString(): string | null;
|
|
167
|
+
/**
|
|
168
|
+
* Retrieves the token for the previous page.
|
|
169
|
+
*/
|
|
170
|
+
get prevToken(): Token | null;
|
|
171
|
+
/**
|
|
172
|
+
* Retrieves the string representation of the previous page token.
|
|
173
|
+
*/
|
|
174
|
+
get prevTokenString(): string | null;
|
|
175
|
+
getQuery(): QueryAdapter.QueryAdapter<any>;
|
|
176
|
+
pre(hookName: string, fn: Function): this;
|
|
177
|
+
post(hookName: string, fn: Function): this;
|
|
178
|
+
stream(): Promise<internal.Transform>;
|
|
179
|
+
/** @internal */
|
|
180
|
+
maybeTweak(): this;
|
|
181
|
+
/** @internal */
|
|
182
|
+
tweak(): this;
|
|
183
|
+
/** @internal */
|
|
184
|
+
_handleResult(items: any[]): QueryPaginatorResult<any>;
|
|
185
|
+
/**
|
|
186
|
+
* Executes the query and returns the results along with pagination metadata.
|
|
187
|
+
*/
|
|
188
|
+
exec(): Promise<QueryPaginatorResult<T>>;
|
|
189
|
+
then: Promise<QueryPaginatorResult<T>>["then"];
|
|
190
|
+
cath: Promise<QueryPaginatorResult<T>>["catch"];
|
|
191
|
+
finally: Promise<QueryPaginatorResult<T>>["finally"];
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
export { QueryAdapter as Q, Token as T, type QueryPaginatorOptions as a, QueryPaginator as b, type QueryPaginatorMeta as c, type QueryPaginatorResult as d, createToken as e, type TokenOptions as f };
|