@ewb/mongoose-query 1.0.0 → 1.0.1
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/README.md +24 -35
- package/lib/Query.d.ts +60 -77
- package/lib/Query.js +227 -307
- package/lib/QueryError.d.ts +16 -50
- package/lib/QueryError.js +52 -62
- package/lib/QueryHandler.d.ts +47 -59
- package/lib/QueryHandler.js +250 -297
- package/lib/QueryHistory.d.ts +75 -76
- package/lib/QueryHistory.js +137 -154
- package/lib/QueryModel.d.ts +65 -80
- package/lib/QueryModel.js +214 -201
- package/lib/index.d.ts +9 -10
- package/lib/index.js +6 -32
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/lib/utils/Query.utils.d.ts +49 -0
- package/lib/utils/Query.utils.js +143 -0
- package/lib/{constants.d.ts → utils/constants.d.ts} +2 -2
- package/lib/utils/constants.js +2 -0
- package/lib/utils/types.d.ts +11 -0
- package/lib/utils/types.js +1 -0
- package/lib/utils/utils.d.ts +8 -0
- package/lib/{utils.js → utils/utils.js} +38 -44
- package/package.json +4 -4
- package/lib/ExpressHandler.d.ts +0 -30
- package/lib/ExpressHandler.js +0 -215
- package/lib/ExpressHandler.js.map +0 -1
- package/lib/ModelQuery.d.ts +0 -24
- package/lib/ModelQuery.js +0 -80
- package/lib/ModelQuery.js.map +0 -1
- package/lib/Query.js.map +0 -1
- package/lib/QueryError.js.map +0 -1
- package/lib/QueryExpressHandler.d.ts +0 -50
- package/lib/QueryExpressHandler.js +0 -383
- package/lib/QueryExpressHandler.js.map +0 -1
- package/lib/QueryExpressSubHandler.d.ts +0 -20
- package/lib/QueryExpressSubHandler.js +0 -137
- package/lib/QueryExpressSubHandler.js.map +0 -1
- package/lib/QueryHandler.js.map +0 -1
- package/lib/QueryHistory.js.map +0 -1
- package/lib/QueryModel.js.map +0 -1
- package/lib/constants.js +0 -6
- package/lib/constants.js.map +0 -1
- package/lib/declarations.d.ts +0 -16
- package/lib/declarations.js +0 -3
- package/lib/declarations.js.map +0 -1
- package/lib/error/ExpressError.d.ts +0 -44
- package/lib/error/ExpressError.js +0 -39
- package/lib/error/ExpressError.js.map +0 -1
- package/lib/error/QueryError.d.ts +0 -47
- package/lib/error/QueryError.js +0 -50
- package/lib/error/QueryError.js.map +0 -1
- package/lib/error/QueryExpressError.d.ts +0 -46
- package/lib/error/QueryExpressError.js +0 -39
- package/lib/error/QueryExpressError.js.map +0 -1
- package/lib/error/V1Error.d.ts +0 -12
- package/lib/error/V1Error.js +0 -27
- package/lib/error/V1Error.js.map +0 -1
- package/lib/error/error.handler.d.ts +0 -3
- package/lib/error/error.handler.js +0 -30
- package/lib/error/error.handler.js.map +0 -1
- package/lib/index.js.map +0 -1
- package/lib/statics.d.ts +0 -17
- package/lib/statics.js +0 -35
- package/lib/statics.js.map +0 -1
- package/lib/utils.d.ts +0 -3
- package/lib/utils.js.map +0 -1
package/lib/Query.js
CHANGED
|
@@ -1,307 +1,227 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
this.
|
|
17
|
-
this.
|
|
18
|
-
this.
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
this.
|
|
22
|
-
this.
|
|
23
|
-
this.
|
|
24
|
-
this.
|
|
25
|
-
this.
|
|
26
|
-
this.
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
this.
|
|
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
|
-
|
|
192
|
-
return
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
addRoot(query) {
|
|
231
|
-
this._root = Object.assign(Object.assign({}, (this._root || {})), query);
|
|
232
|
-
return this._root;
|
|
233
|
-
}
|
|
234
|
-
addRootNext(query) {
|
|
235
|
-
this._rootNext = Object.assign(Object.assign({}, (this._rootNext || {})), query);
|
|
236
|
-
return this._rootNext;
|
|
237
|
-
}
|
|
238
|
-
removeQuery(key) {
|
|
239
|
-
// @ts-ignore
|
|
240
|
-
if (key in this._query) {
|
|
241
|
-
delete this._query[key];
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
deleteKeysFromRoot(keys) {
|
|
245
|
-
if (this._root) {
|
|
246
|
-
for (const key of keys) {
|
|
247
|
-
// @ts-ignore
|
|
248
|
-
if (key in this._root) {
|
|
249
|
-
delete this._root[key];
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
addToModelQuery(key, query) {
|
|
255
|
-
const modelKeys = key;
|
|
256
|
-
const keys = Array.isArray(modelKeys)
|
|
257
|
-
? modelKeys
|
|
258
|
-
: [modelKeys];
|
|
259
|
-
for (const modelKey of keys) {
|
|
260
|
-
if (this._addToModelQuery[modelKey]) {
|
|
261
|
-
// @ts-ignore
|
|
262
|
-
this._addToModelQuery[modelKey] = Object.assign(Object.assign({}, this._addToModelQuery[modelKey]), query);
|
|
263
|
-
}
|
|
264
|
-
else {
|
|
265
|
-
// @ts-ignore
|
|
266
|
-
this._addToModelQuery[modelKey] = Object.assign({}, query);
|
|
267
|
-
}
|
|
268
|
-
}
|
|
269
|
-
}
|
|
270
|
-
createQuery({ param, query, noRoot, } = {}) {
|
|
271
|
-
if (param) {
|
|
272
|
-
this.parameter = param;
|
|
273
|
-
}
|
|
274
|
-
const queryArray = [];
|
|
275
|
-
const root = this.root;
|
|
276
|
-
if (!noRoot && root && Object.keys(root).length > 0) {
|
|
277
|
-
queryArray.push(root);
|
|
278
|
-
}
|
|
279
|
-
if (!noRoot && this._rootNext && Object.keys(this._rootNext).length > 0) {
|
|
280
|
-
queryArray.push(this._rootNext);
|
|
281
|
-
this._rootNext = null;
|
|
282
|
-
}
|
|
283
|
-
if (Object.keys(this._query).length > 0 ||
|
|
284
|
-
Object.keys(this._$Query).length > 0) {
|
|
285
|
-
const addQuery = query
|
|
286
|
-
? query.reduce((obj, key) => {
|
|
287
|
-
if (typeof this._query[key] !== 'undefined') {
|
|
288
|
-
obj[key] = this._query[key];
|
|
289
|
-
}
|
|
290
|
-
return obj;
|
|
291
|
-
}, Object.assign({}, this._$Query))
|
|
292
|
-
: Object.assign(Object.assign({}, this._$Query), this._query);
|
|
293
|
-
if (Object.keys(addQuery).length > 0) {
|
|
294
|
-
queryArray.push(addQuery);
|
|
295
|
-
}
|
|
296
|
-
}
|
|
297
|
-
const mQuery = queryArray.length > 1 ? { $and: queryArray } : queryArray[0] || {};
|
|
298
|
-
if (this._or.length > 0) {
|
|
299
|
-
return {
|
|
300
|
-
$or: [...this._or, mQuery],
|
|
301
|
-
};
|
|
302
|
-
}
|
|
303
|
-
return mQuery || {};
|
|
304
|
-
}
|
|
305
|
-
}
|
|
306
|
-
exports.Query = Query;
|
|
307
|
-
//# sourceMappingURL=Query.js.map
|
|
1
|
+
import mongoSanitize from 'express-mongo-sanitize';
|
|
2
|
+
import { mongooseQueryOptions, mongooseQueryWithOperation, } from './utils/Query.utils';
|
|
3
|
+
export class Query {
|
|
4
|
+
constructor(queries) {
|
|
5
|
+
this._root = null;
|
|
6
|
+
this._rootNext = null;
|
|
7
|
+
this._rootPopulate = [];
|
|
8
|
+
this._or = [];
|
|
9
|
+
this._model = undefined;
|
|
10
|
+
this._addToModelQuery = {};
|
|
11
|
+
this._export = false;
|
|
12
|
+
this._projection = undefined;
|
|
13
|
+
this._query = {};
|
|
14
|
+
this.sort = [];
|
|
15
|
+
this._select = [];
|
|
16
|
+
this.hasTextSearch = false;
|
|
17
|
+
this.options = {};
|
|
18
|
+
this.populate = [];
|
|
19
|
+
const query = Object.assign({}, queries);
|
|
20
|
+
const { limit, skip, sort, select, populate, page } = mongooseQueryOptions(query);
|
|
21
|
+
this._limit = limit;
|
|
22
|
+
this._skip = skip;
|
|
23
|
+
this.sort = sort;
|
|
24
|
+
this._select = select;
|
|
25
|
+
this.populate = populate;
|
|
26
|
+
this.page = page;
|
|
27
|
+
const textQuery = this.mongooseTextSearch(query);
|
|
28
|
+
const operations = this.mongooseQueryWithOperations(query);
|
|
29
|
+
const sanitized = this.sanitizedQuery(query);
|
|
30
|
+
if (textQuery) {
|
|
31
|
+
this.hasTextSearch = true;
|
|
32
|
+
}
|
|
33
|
+
this._query = { ...operations, ...sanitized, ...textQuery };
|
|
34
|
+
}
|
|
35
|
+
get skip() {
|
|
36
|
+
return this._skip;
|
|
37
|
+
}
|
|
38
|
+
get limit() {
|
|
39
|
+
return this._limit;
|
|
40
|
+
}
|
|
41
|
+
get root() {
|
|
42
|
+
const root = this._root;
|
|
43
|
+
if (this._model && this._addToModelQuery[this._model]) {
|
|
44
|
+
if (root) {
|
|
45
|
+
return {
|
|
46
|
+
$and: [root, this._addToModelQuery[this._model]],
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
return this._addToModelQuery[this._model];
|
|
50
|
+
}
|
|
51
|
+
return root;
|
|
52
|
+
}
|
|
53
|
+
get query() {
|
|
54
|
+
return { ...this._query };
|
|
55
|
+
}
|
|
56
|
+
get model() {
|
|
57
|
+
return this._model;
|
|
58
|
+
}
|
|
59
|
+
set model(value) {
|
|
60
|
+
this._model = value;
|
|
61
|
+
}
|
|
62
|
+
get rootPopulate() {
|
|
63
|
+
return this._rootPopulate;
|
|
64
|
+
}
|
|
65
|
+
get select() {
|
|
66
|
+
return this._select;
|
|
67
|
+
}
|
|
68
|
+
get or() {
|
|
69
|
+
return this._or;
|
|
70
|
+
}
|
|
71
|
+
get export() {
|
|
72
|
+
return this._export;
|
|
73
|
+
}
|
|
74
|
+
set export(value) {
|
|
75
|
+
this._export = value;
|
|
76
|
+
}
|
|
77
|
+
get projection() {
|
|
78
|
+
return this._projection;
|
|
79
|
+
}
|
|
80
|
+
set projection(value) {
|
|
81
|
+
this._projection = value;
|
|
82
|
+
}
|
|
83
|
+
setSkipAndLimit(skip, limit) {
|
|
84
|
+
this._skip = skip;
|
|
85
|
+
this._limit = limit;
|
|
86
|
+
}
|
|
87
|
+
setQuery(key, value) {
|
|
88
|
+
this._query[key] = value;
|
|
89
|
+
}
|
|
90
|
+
addOr(query) {
|
|
91
|
+
this._or.push(query);
|
|
92
|
+
}
|
|
93
|
+
defaultSelect(select) {
|
|
94
|
+
if (this._select.length !== 0)
|
|
95
|
+
return;
|
|
96
|
+
this._select = select;
|
|
97
|
+
}
|
|
98
|
+
addPopulate(populate) {
|
|
99
|
+
this._rootPopulate.push(...(Array.isArray(populate) ? populate : [populate]));
|
|
100
|
+
}
|
|
101
|
+
addRoot(query) {
|
|
102
|
+
this._root = {
|
|
103
|
+
...(this._root || {}),
|
|
104
|
+
...query,
|
|
105
|
+
};
|
|
106
|
+
return this._root;
|
|
107
|
+
}
|
|
108
|
+
addRootNext(query) {
|
|
109
|
+
this._rootNext = {
|
|
110
|
+
...(this._rootNext || {}),
|
|
111
|
+
...query,
|
|
112
|
+
};
|
|
113
|
+
return this._rootNext;
|
|
114
|
+
}
|
|
115
|
+
removeQuery(key) {
|
|
116
|
+
return this.deleteKeysFromQuery(key);
|
|
117
|
+
}
|
|
118
|
+
deleteKeysFromQuery(key) {
|
|
119
|
+
if (key in this._query) {
|
|
120
|
+
delete this._query[key];
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
deleteKeysFromRoot(keys) {
|
|
124
|
+
if (this._root) {
|
|
125
|
+
for (const key of keys) {
|
|
126
|
+
if (key in this._root) {
|
|
127
|
+
delete this._root[key];
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
addToModelQuery(key, query) {
|
|
133
|
+
const modelKeys = key;
|
|
134
|
+
const keys = Array.isArray(modelKeys)
|
|
135
|
+
? modelKeys
|
|
136
|
+
: [modelKeys];
|
|
137
|
+
for (const modelKey of keys) {
|
|
138
|
+
if (this._addToModelQuery[modelKey]) {
|
|
139
|
+
this._addToModelQuery[modelKey] = {
|
|
140
|
+
...this._addToModelQuery[modelKey],
|
|
141
|
+
...query,
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
else {
|
|
145
|
+
this._addToModelQuery[modelKey] = { ...query };
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
createQuery({ param, query, noRoot, } = {}) {
|
|
150
|
+
if (param) {
|
|
151
|
+
this.model = param;
|
|
152
|
+
}
|
|
153
|
+
const queryArray = [];
|
|
154
|
+
const root = this.root;
|
|
155
|
+
if (!noRoot && root && Object.keys(root).length > 0) {
|
|
156
|
+
queryArray.push(root);
|
|
157
|
+
}
|
|
158
|
+
if (!noRoot && this._rootNext && Object.keys(this._rootNext).length > 0) {
|
|
159
|
+
queryArray.push(this._rootNext);
|
|
160
|
+
this._rootNext = null;
|
|
161
|
+
}
|
|
162
|
+
if (Object.keys(this._query).length > 0) {
|
|
163
|
+
const addQuery = query
|
|
164
|
+
? query.reduce((obj, key) => {
|
|
165
|
+
if (typeof this._query[key] !== 'undefined') {
|
|
166
|
+
obj[key] = this._query[key];
|
|
167
|
+
}
|
|
168
|
+
return obj;
|
|
169
|
+
}, {})
|
|
170
|
+
: { ...this._query };
|
|
171
|
+
if (Object.keys(addQuery).length > 0) {
|
|
172
|
+
queryArray.push(addQuery);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
const mQuery = queryArray.length > 1 ? { $and: queryArray } : queryArray[0] || {};
|
|
176
|
+
if (this._or.length > 0) {
|
|
177
|
+
return {
|
|
178
|
+
$or: [...this._or, mQuery],
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
return mQuery || {};
|
|
182
|
+
}
|
|
183
|
+
mongooseTextSearch(query) {
|
|
184
|
+
const _query = {};
|
|
185
|
+
if ('$text' in query) {
|
|
186
|
+
if (query.$text) {
|
|
187
|
+
_query['$text'] = { $search: query.$text };
|
|
188
|
+
this.options['score'] = { $meta: 'textScore' };
|
|
189
|
+
}
|
|
190
|
+
delete query.$text;
|
|
191
|
+
}
|
|
192
|
+
return _query;
|
|
193
|
+
}
|
|
194
|
+
mongooseQueryWithOperations(query) {
|
|
195
|
+
const operationQuery = {};
|
|
196
|
+
for (const key in query) {
|
|
197
|
+
if (query.hasOwnProperty(key)) {
|
|
198
|
+
const str = String(query[key]);
|
|
199
|
+
if (key[0] === '$') {
|
|
200
|
+
if (typeof query[key] !== 'string')
|
|
201
|
+
continue;
|
|
202
|
+
const { field, value } = mongooseQueryWithOperation(operationQuery, key, str);
|
|
203
|
+
if (field) {
|
|
204
|
+
operationQuery[field] = value;
|
|
205
|
+
}
|
|
206
|
+
delete query[key];
|
|
207
|
+
}
|
|
208
|
+
else if (key[0] === '!') {
|
|
209
|
+
operationQuery[key.slice(1)] = { $ne: str };
|
|
210
|
+
delete query[key];
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
return operationQuery;
|
|
215
|
+
}
|
|
216
|
+
sanitizedQuery(query) {
|
|
217
|
+
const cleanedQuery = {};
|
|
218
|
+
for (const key in query) {
|
|
219
|
+
if (query.hasOwnProperty(key)) {
|
|
220
|
+
if (typeof query[key] !== 'string' || query[key] !== '') {
|
|
221
|
+
cleanedQuery[key] = query[key];
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
return mongoSanitize.sanitize(cleanedQuery, { replaceWith: '_' });
|
|
226
|
+
}
|
|
227
|
+
}
|
package/lib/QueryError.d.ts
CHANGED
|
@@ -1,50 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
links?: {
|
|
18
|
-
self?: IQueryErrorLink | string;
|
|
19
|
-
};
|
|
20
|
-
status: string;
|
|
21
|
-
code: C;
|
|
22
|
-
title?: string;
|
|
23
|
-
detail?: string;
|
|
24
|
-
source?: {
|
|
25
|
-
pointer?: string;
|
|
26
|
-
parameter?: string;
|
|
27
|
-
header?: string;
|
|
28
|
-
body?: string;
|
|
29
|
-
};
|
|
30
|
-
meta?: object;
|
|
31
|
-
}
|
|
32
|
-
export interface IQueryErrorLink {
|
|
33
|
-
href: string;
|
|
34
|
-
title?: string;
|
|
35
|
-
describedBy?: string;
|
|
36
|
-
meta: {
|
|
37
|
-
count: number;
|
|
38
|
-
};
|
|
39
|
-
}
|
|
40
|
-
export declare type IQueryErrorOptional = Pick<IQueryError<QueryErrorCode>, 'meta' | 'title' | 'detail' | 'links' | 'source'>;
|
|
41
|
-
export declare class QueryError<R extends IQueryErrorExpressRequest, C extends string> extends Error {
|
|
42
|
-
private req;
|
|
43
|
-
readonly code: C;
|
|
44
|
-
readonly optional: IQueryErrorOptional;
|
|
45
|
-
readonly status: number;
|
|
46
|
-
constructor(req: R, code: C, optional?: IQueryErrorOptional);
|
|
47
|
-
toJSON(): IQueryError<C>;
|
|
48
|
-
static catch<R extends IQueryErrorExpressRequest, C extends string>(req: R, e: Error | QueryError<R, C>): QueryError<R, C>;
|
|
49
|
-
static getStatusFromCode<C extends string>(code: C): 500 | 404 | 400 | 440 | 501;
|
|
50
|
-
}
|
|
1
|
+
import mongoose from 'mongoose';
|
|
2
|
+
interface ErrorOpts {
|
|
3
|
+
message?: string;
|
|
4
|
+
detail?: string;
|
|
5
|
+
errors?: Omit<ErrorOpts, 'errors'>[];
|
|
6
|
+
error?: any;
|
|
7
|
+
}
|
|
8
|
+
export declare class QueryError<R extends object, C extends string> extends Error {
|
|
9
|
+
readonly status: number;
|
|
10
|
+
readonly detail?: string;
|
|
11
|
+
readonly errors?: ErrorOpts[];
|
|
12
|
+
constructor(status: number, message: string, opts?: Pick<ErrorOpts, 'detail' | 'errors' | 'error'>);
|
|
13
|
+
static catch<R extends object, C extends string>(e: Error | QueryError<R, C>): QueryError<R, C>;
|
|
14
|
+
static getData(error: mongoose.Error): [number, ErrorOpts];
|
|
15
|
+
}
|
|
16
|
+
export {};
|