-
Notifications
You must be signed in to change notification settings - Fork 92
/
Copy pathindex.d.ts
191 lines (180 loc) · 5.11 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
declare module 'mongoose' {
interface CustomLabels<T = string | undefined | boolean> {
totalDocs?: T;
docs?: T;
limit?: T;
page?: T;
nextPage?: T;
prevPage?: T;
hasNextPage?: T;
hasPrevPage?: T;
totalPages?: T;
pagingCounter?: T;
meta?: T;
}
interface ReadOptions {
pref: string;
tags?: any[] | undefined;
}
interface PaginateOptions {
select?: object | string | undefined;
collation?: import('mongodb').CollationOptions | undefined;
sort?: object | string | undefined;
populate?:
| PopulateOptions[]
| string[]
| PopulateOptions
| string
| PopulateOptions
| undefined;
projection?: any;
lean?: boolean | undefined;
leanWithId?: boolean | undefined;
leanWithVirtuals?: boolean | undefined;
offset?: number | undefined;
page?: number | undefined;
limit?: number | undefined;
customLabels?: CustomLabels | undefined;
/* If pagination is set to `false`, it will return all docs without adding limit condition. (Default: `true`) */
pagination?: boolean | undefined;
useEstimatedCount?: boolean | undefined;
useCustomCountFn?: (() => Promise<number>) | undefined;
forceCountFn?: boolean | undefined;
allowDiskUse?: boolean | undefined;
read?: ReadOptions | undefined;
options?: QueryOptions | undefined;
}
interface SubPaginateOptions {
select?: object | string | undefined;
populate?:
| PopulateOptions[]
| string[]
| PopulateOptions
| string
| PopulateOptions
| undefined;
pagination?: boolean | undefined;
read?: ReadOptions | undefined;
pagingOptions: SubDocumentPagingOptions | undefined;
}
interface SubDocumentPagingOptions {
populate?:
| PopulateOptions[]
| string[]
| PopulateOptions
| string
| PopulateOptions
| undefined;
page?: number | undefined;
limit?: number | undefined;
}
interface PaginateResult<T> {
docs: T[];
totalDocs: number;
limit: number;
hasPrevPage: boolean;
hasNextPage: boolean;
page?: number | undefined;
totalPages: number;
offset: number;
prevPage?: number | null | undefined;
nextPage?: number | null | undefined;
pagingCounter: number;
meta?: any;
[customLabel: string]: T[] | number | boolean | null | undefined;
}
type PaginateDocument<
T,
TMethods,
TQueryHelpers,
O extends PaginateOptions = {}
> = O['lean'] extends true
? O['leanWithId'] extends true
? T & { id: string }
: O['leanWithVirtuals'] extends true
? T & { [key: string]: any }
: T
: HydratedDocument<T, TMethods, TQueryHelpers>;
interface PaginateModel<T, TQueryHelpers = {}, TMethods = {}>
extends Model<T, TQueryHelpers, TMethods> {
paginate<O extends PaginateOptions>(
query?: FilterQuery<T>,
options?: O,
callback?: (
err: any,
result: PaginateResult<PaginateDocument<T, TMethods, TQueryHelpers, O>>
) => void
): Promise<PaginateResult<PaginateDocument<T, TMethods, TQueryHelpers, O>>>;
paginate<UserType = T, O extends PaginateOptions = PaginateOptions>(
query?: FilterQuery<T>,
options?: O,
callback?: (
err: any,
result: PaginateResult<
PaginateDocument<UserType, TMethods, TQueryHelpers, O>
>
) => void
): Promise<
PaginateResult<PaginateDocument<UserType, TMethods, TQueryHelpers, O>>
>;
paginate<UserType = T>(
query?: FilterQuery<T>,
options?: PaginateOptions,
callback?: (
err: any,
result: PaginateResult<
PaginateDocument<UserType, TMethods, TQueryHelpers, PaginateOptions>
>
) => void
): Promise<
PaginateResult<
PaginateDocument<UserType, TMethods, TQueryHelpers, PaginateOptions>
>
>;
}
// @ts-ignore
interface Query<
ResultType,
DocType,
THelpers = NonNullable<unknown>,
RawDocType = DocType,
QueryOp = 'find',
TInstanceMethods = Record<string, never>
> {
paginate<O extends PaginateOptions>(
options?: O
): Promise<
PaginateResult<
PaginateDocument<RawDocType, TInstanceMethods, THelpers, O>
>
>;
paginate<
UserType = ResultType,
O extends PaginateOptions = PaginateOptions
>(
options?: O
): Promise<
PaginateResult<PaginateDocument<UserType, TInstanceMethods, THelpers, O>>
>;
paginate<UserType = ResultType>(
options?: PaginateOptions
): Promise<
PaginateResult<
PaginateDocument<UserType, TInstanceMethods, THelpers, PaginateOptions>
>
>;
}
}
import mongoose = require('mongoose');
declare function _(schema: mongoose.Schema): void;
export = _;
declare namespace _ {
const paginate: { options: mongoose.PaginateOptions };
const paginateSubDocs: { options: mongoose.PaginateOptions };
class PaginationParameters<T, O extends mongoose.PaginateOptions> {
constructor(request: { query?: Record<string, any> });
getOptions: () => O;
getQuery: () => mongoose.FilterQuery<T>;
get: () => [mongoose.FilterQuery<T>, O];
}
}