@tepez/mongo-cursor-pagination 8.0.1 → 8.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/index.d.ts +91 -0
- package/package.json +3 -2
package/index.d.ts
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Based on https://github.com/mixmaxhq/mongo-cursor-pagination/blob/v7.3.1/README.md
|
|
3
|
+
*/
|
|
4
|
+
declare module '@tepez/mongo-cursor-pagination' {
|
|
5
|
+
import { Document, FilterQuery, LeanDocument, Schema } from 'mongoose';
|
|
6
|
+
type MongoosePlugin = Parameters<Schema['plugin']>[0]
|
|
7
|
+
|
|
8
|
+
export interface ICursorPaginationMongoosePluginOptions {
|
|
9
|
+
/**
|
|
10
|
+
* custom function name
|
|
11
|
+
* @default paginate
|
|
12
|
+
*/
|
|
13
|
+
name?: string
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface IPaginateOptions<T extends Document> {
|
|
17
|
+
/**
|
|
18
|
+
* The find query
|
|
19
|
+
*/
|
|
20
|
+
query: FilterQuery<T>
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* The page size. Must be between 1 and `config.MAX_LIMIT`.
|
|
24
|
+
*/
|
|
25
|
+
limit: number
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Fields to query in the Mongo object format, e.g. {_id: 1, timestamp :1}.
|
|
29
|
+
* @default query all fields.
|
|
30
|
+
*/
|
|
31
|
+
fields?: any
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* The field name to query the range for. The field must be:
|
|
35
|
+
* 1. Orderable. We must sort by this value. If duplicate values for paginatedField field
|
|
36
|
+
* exist, the results will be secondarily ordered by the _id.
|
|
37
|
+
* 2. Indexed. For large collections, this should be indexed for query performance.
|
|
38
|
+
* 3. Immutable. If the value changes between paged queries, it could appear twice.
|
|
39
|
+
* 4. Complete. A value must exist for all documents.
|
|
40
|
+
* The default is to use the Mongo built-in '_id' field, which satisfies the above criteria.
|
|
41
|
+
* The only reason to NOT use the Mongo _id field is if you chose to implement your own ids.
|
|
42
|
+
* @default _id
|
|
43
|
+
*/
|
|
44
|
+
paginatedField?: string
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* True to sort using paginatedField ascending
|
|
48
|
+
* @default false - descending
|
|
49
|
+
*/
|
|
50
|
+
sortAscending?: boolean
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* The value to start querying the page.
|
|
54
|
+
*/
|
|
55
|
+
next?: string
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* The value to start querying previous page.
|
|
59
|
+
*/
|
|
60
|
+
previous?: string
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export interface IPaginateResult<T extends Document> {
|
|
64
|
+
results: LeanDocument<T>[]
|
|
65
|
+
previous?: string
|
|
66
|
+
/**
|
|
67
|
+
* base64 encoded
|
|
68
|
+
* Contains the ID of the last object in the page
|
|
69
|
+
*/
|
|
70
|
+
next: string
|
|
71
|
+
hasNext: boolean
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export interface ICursorPaginationExtendedModel<T extends Document> {
|
|
75
|
+
paginate(options: IPaginateOptions<T>): IPaginateResult<T>
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export const mongoosePlugin: MongoosePlugin
|
|
79
|
+
|
|
80
|
+
export const config: {
|
|
81
|
+
/**
|
|
82
|
+
* @default 50
|
|
83
|
+
*/
|
|
84
|
+
DEFAULT_LIMIT: number
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* @default 300
|
|
88
|
+
*/
|
|
89
|
+
MAX_LIMIT: number
|
|
90
|
+
}
|
|
91
|
+
}
|
package/package.json
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tepez/mongo-cursor-pagination",
|
|
3
|
-
"version": "8.0.
|
|
3
|
+
"version": "8.0.2",
|
|
4
4
|
"description": "Make it easy to return cursor-paginated results from a Mongo collection",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"files": [
|
|
7
7
|
"index.js",
|
|
8
8
|
"dist",
|
|
9
|
-
"src"
|
|
9
|
+
"src",
|
|
10
|
+
"index.d.ts"
|
|
10
11
|
],
|
|
11
12
|
"scripts": {
|
|
12
13
|
"babelBuild": "babel src -d dist/node",
|