@andrew_l/mongo-pagination 0.3.22 → 0.4.0
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/dist/_chunks/QueryPaginator.d.mts +198 -0
- package/dist/_chunks/QueryPaginator.d.mts.map +1 -0
- package/dist/_chunks/withMongoosePagination.mjs +489 -0
- package/dist/_chunks/withMongoosePagination.mjs.map +1 -0
- package/dist/index.d.mts +13 -14
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +36 -46
- package/dist/index.mjs.map +1 -1
- package/dist/mongoose-7.d.mts +9 -12
- package/dist/mongoose-7.d.mts.map +1 -0
- package/dist/mongoose-7.mjs +14 -27
- package/dist/mongoose-7.mjs.map +1 -1
- package/dist/mongoose-8.d.mts +9 -12
- package/dist/mongoose-8.d.mts.map +1 -0
- package/dist/mongoose-8.mjs +14 -27
- package/dist/mongoose-8.mjs.map +1 -1
- package/package.json +14 -11
- package/dist/index.cjs +0 -56
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.cts +0 -150
- package/dist/index.d.ts +0 -150
- package/dist/mongoose-7.cjs +0 -36
- package/dist/mongoose-7.cjs.map +0 -1
- package/dist/mongoose-7.d.cts +0 -16
- package/dist/mongoose-7.d.ts +0 -16
- package/dist/mongoose-8.cjs +0 -36
- package/dist/mongoose-8.cjs.map +0 -1
- package/dist/mongoose-8.d.cts +0 -16
- package/dist/mongoose-8.d.ts +0 -16
- package/dist/shared/mongo-pagination.Ckfb2fG8.mjs +0 -663
- package/dist/shared/mongo-pagination.Ckfb2fG8.mjs.map +0 -1
- package/dist/shared/mongo-pagination.D7Mb8JCq.d.cts +0 -195
- package/dist/shared/mongo-pagination.D7Mb8JCq.d.mts +0 -195
- package/dist/shared/mongo-pagination.D7Mb8JCq.d.ts +0 -195
- package/dist/shared/mongo-pagination.odJCU2tV.cjs +0 -676
- package/dist/shared/mongo-pagination.odJCU2tV.cjs.map +0 -1
|
@@ -1,195 +0,0 @@
|
|
|
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 CRC of the model name, used for verify the model.
|
|
34
|
-
*/
|
|
35
|
-
modelNameCRC: number;
|
|
36
|
-
/**
|
|
37
|
-
* The sorting direction used for pagination building pagination query.
|
|
38
|
-
*/
|
|
39
|
-
sortDirection: Record<string, any>;
|
|
40
|
-
/**
|
|
41
|
-
* The sorting values associated with the pagination.
|
|
42
|
-
*/
|
|
43
|
-
sortValues: Record<string, any>;
|
|
44
|
-
/**
|
|
45
|
-
* The payload of the token, which can contain any associated metadata or data (may be `null`).
|
|
46
|
-
*/
|
|
47
|
-
payload: Record<string, any> | null;
|
|
48
|
-
constructor(options?: Partial<TokenOptions>);
|
|
49
|
-
/**
|
|
50
|
-
* Retrieves the string representation of token.
|
|
51
|
-
*/
|
|
52
|
-
stringify(): string;
|
|
53
|
-
/**
|
|
54
|
-
* Retrieves binary buffer representation of token.
|
|
55
|
-
*/
|
|
56
|
-
buffer(): Uint8Array;
|
|
57
|
-
/**
|
|
58
|
-
* Encode token from provided value
|
|
59
|
-
*/
|
|
60
|
-
static from(value: string | Buffer | Uint8Array): Token;
|
|
61
|
-
}
|
|
62
|
-
/**
|
|
63
|
-
* Parses a token from provided value.
|
|
64
|
-
* @group Utils
|
|
65
|
-
*/
|
|
66
|
-
declare function parseToken(value: string | Buffer): Token;
|
|
67
|
-
/**
|
|
68
|
-
* Create a token with pagination and metadata information.
|
|
69
|
-
* This holds the token data, including sorting details, and any payload.
|
|
70
|
-
*
|
|
71
|
-
* @group Utils
|
|
72
|
-
*/
|
|
73
|
-
declare function createToken(options?: Partial<TokenOptions>): Token;
|
|
74
|
-
|
|
75
|
-
declare namespace QueryAdapter {
|
|
76
|
-
type Options = {
|
|
77
|
-
sort?: Sort;
|
|
78
|
-
limit?: number;
|
|
79
|
-
};
|
|
80
|
-
type Filter = Record<string, any>;
|
|
81
|
-
interface QueryAdapter<T = any> {
|
|
82
|
-
getModelName(): string;
|
|
83
|
-
getOptions(): Options;
|
|
84
|
-
getFilter(): Filter;
|
|
85
|
-
setOptions(options: Options): void;
|
|
86
|
-
setFilter(filter: Filter): void;
|
|
87
|
-
toArray(): Promise<T[]>;
|
|
88
|
-
stream(): Readable;
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
interface QueryPaginatorOptions {
|
|
93
|
-
/**
|
|
94
|
-
* An optional list of fields used for building pagination query.
|
|
95
|
-
*/
|
|
96
|
-
paginationFields?: string[];
|
|
97
|
-
/**
|
|
98
|
-
* The token to start the pagination from, if available.
|
|
99
|
-
*/
|
|
100
|
-
next?: string | Buffer | null;
|
|
101
|
-
/**
|
|
102
|
-
* A callback function executed before the query is performed.
|
|
103
|
-
*/
|
|
104
|
-
preQuery?: (this: QueryPaginator) => void;
|
|
105
|
-
/**
|
|
106
|
-
* A callback function executed after the query is performed.
|
|
107
|
-
*/
|
|
108
|
-
postQuery?: (this: QueryPaginator) => void;
|
|
109
|
-
/** @internal */
|
|
110
|
-
debugQuery?: boolean;
|
|
111
|
-
}
|
|
112
|
-
interface QueryPaginatorMeta {
|
|
113
|
-
/**
|
|
114
|
-
* Indicates whether there is a next page available.
|
|
115
|
-
*/
|
|
116
|
-
hasNext: boolean;
|
|
117
|
-
/**
|
|
118
|
-
* The token for the next page, or `null` if there is no next page.
|
|
119
|
-
*/
|
|
120
|
-
next: string | null;
|
|
121
|
-
}
|
|
122
|
-
interface QueryPaginatorResult<T> {
|
|
123
|
-
/**
|
|
124
|
-
* The list of items for the current page.
|
|
125
|
-
*/
|
|
126
|
-
items: T[];
|
|
127
|
-
/**
|
|
128
|
-
* Metadata providing information about pagination, such as whether more pages are available.
|
|
129
|
-
*/
|
|
130
|
-
metadata: QueryPaginatorMeta;
|
|
131
|
-
}
|
|
132
|
-
/**
|
|
133
|
-
* A generic class for handling query pagination.
|
|
134
|
-
*
|
|
135
|
-
* Look at `withMongoPagination` and `withMongoosePagination`
|
|
136
|
-
*
|
|
137
|
-
* @group Main
|
|
138
|
-
*/
|
|
139
|
-
declare class QueryPaginator<T = any> {
|
|
140
|
-
private query;
|
|
141
|
-
private hooks;
|
|
142
|
-
private next;
|
|
143
|
-
private previous?;
|
|
144
|
-
private resHasNext;
|
|
145
|
-
private resLastItem;
|
|
146
|
-
private paginationFields;
|
|
147
|
-
private tweaked;
|
|
148
|
-
private debugQuery;
|
|
149
|
-
getMetadata: () => QueryPaginatorMeta;
|
|
150
|
-
constructor(query: QueryAdapter.QueryAdapter, { paginationFields, postQuery, preQuery, next: previousToken, debugQuery, }?: QueryPaginatorOptions);
|
|
151
|
-
/**
|
|
152
|
-
* Retrieves metadata about the current state of pagination.
|
|
153
|
-
*/
|
|
154
|
-
get metadata(): QueryPaginatorMeta;
|
|
155
|
-
/**
|
|
156
|
-
* Indicates whether there is a next page available.
|
|
157
|
-
*/
|
|
158
|
-
get hasNext(): boolean;
|
|
159
|
-
/**
|
|
160
|
-
* Retrieves the token for the next page.
|
|
161
|
-
*/
|
|
162
|
-
get nextToken(): Token;
|
|
163
|
-
/**
|
|
164
|
-
* Retrieves the string representation of the next page token.
|
|
165
|
-
* If there is no next page, returns `null`.
|
|
166
|
-
*/
|
|
167
|
-
get nextTokenString(): string | null;
|
|
168
|
-
/**
|
|
169
|
-
* Retrieves the token for the previous page.
|
|
170
|
-
*/
|
|
171
|
-
get prevToken(): Token | null;
|
|
172
|
-
/**
|
|
173
|
-
* Retrieves the string representation of the previous page token.
|
|
174
|
-
*/
|
|
175
|
-
get prevTokenString(): string | null;
|
|
176
|
-
getQuery(): QueryAdapter.QueryAdapter<any>;
|
|
177
|
-
pre(hookName: string, fn: Function): this;
|
|
178
|
-
post(hookName: string, fn: Function): this;
|
|
179
|
-
stream(): Promise<internal.Transform>;
|
|
180
|
-
/** @internal */
|
|
181
|
-
maybeTweak(): this;
|
|
182
|
-
/** @internal */
|
|
183
|
-
tweak(): this;
|
|
184
|
-
/** @internal */
|
|
185
|
-
_handleResult(items: any[]): QueryPaginatorResult<any>;
|
|
186
|
-
/**
|
|
187
|
-
* Executes the query and returns the results along with pagination metadata.
|
|
188
|
-
*/
|
|
189
|
-
exec(): Promise<QueryPaginatorResult<T>>;
|
|
190
|
-
then: Promise<QueryPaginatorResult<T>>["then"];
|
|
191
|
-
cath: Promise<QueryPaginatorResult<T>>["catch"];
|
|
192
|
-
finally: Promise<QueryPaginatorResult<T>>["finally"];
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
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, parseToken as p };
|