@geekbears/gb-mongoose-query-parser 1.3.38 → 1.3.40
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/.claude/settings.local.json +7 -0
- package/lib/query-parser-helper.js +13 -10
- package/lib/query-parser.js +9 -5
- package/lib/test.spec.js +5 -2
- package/package.json +9 -9
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.QueryParser = void 0;
|
|
4
7
|
const mongoose_1 = require("mongoose");
|
|
5
8
|
const lodash_1 = require("lodash");
|
|
6
9
|
const query_parser_1 = require("./query-parser");
|
|
7
10
|
const class_validator_1 = require("class-validator");
|
|
8
|
-
const
|
|
11
|
+
const moment_1 = __importDefault(require("moment"));
|
|
9
12
|
/**
|
|
10
13
|
* Helper class
|
|
11
14
|
* Implements the `MongooseQueryParser` and exposes a single method to execute queries on models
|
|
@@ -61,7 +64,7 @@ class QueryParser {
|
|
|
61
64
|
return { data: await QueryParser.parseQuery(model, query, count).exec() };
|
|
62
65
|
}
|
|
63
66
|
catch (error) {
|
|
64
|
-
throw new Error(error);
|
|
67
|
+
throw new Error(String(error));
|
|
65
68
|
}
|
|
66
69
|
}
|
|
67
70
|
/**
|
|
@@ -76,7 +79,7 @@ class QueryParser {
|
|
|
76
79
|
return { data: await QueryParser.parseQuery(model, query, count).exec() };
|
|
77
80
|
}
|
|
78
81
|
catch (error) {
|
|
79
|
-
throw new Error(error);
|
|
82
|
+
throw new Error(String(error));
|
|
80
83
|
}
|
|
81
84
|
}
|
|
82
85
|
/**
|
|
@@ -94,7 +97,7 @@ class QueryParser {
|
|
|
94
97
|
};
|
|
95
98
|
}
|
|
96
99
|
catch (error) {
|
|
97
|
-
throw new Error(error);
|
|
100
|
+
throw new Error(String(error));
|
|
98
101
|
}
|
|
99
102
|
}
|
|
100
103
|
/**
|
|
@@ -111,7 +114,7 @@ class QueryParser {
|
|
|
111
114
|
};
|
|
112
115
|
}
|
|
113
116
|
catch (error) {
|
|
114
|
-
throw new Error(error);
|
|
117
|
+
throw new Error(String(error));
|
|
115
118
|
}
|
|
116
119
|
}
|
|
117
120
|
/**
|
|
@@ -177,7 +180,7 @@ class QueryParser {
|
|
|
177
180
|
};
|
|
178
181
|
}
|
|
179
182
|
catch (error) {
|
|
180
|
-
throw new Error(error);
|
|
183
|
+
throw new Error(String(error));
|
|
181
184
|
}
|
|
182
185
|
}
|
|
183
186
|
/**
|
|
@@ -195,7 +198,7 @@ class QueryParser {
|
|
|
195
198
|
};
|
|
196
199
|
}
|
|
197
200
|
catch (error) {
|
|
198
|
-
throw new Error(error);
|
|
201
|
+
throw new Error(String(error));
|
|
199
202
|
}
|
|
200
203
|
}
|
|
201
204
|
/**
|
|
@@ -213,7 +216,7 @@ class QueryParser {
|
|
|
213
216
|
};
|
|
214
217
|
}
|
|
215
218
|
catch (error) {
|
|
216
|
-
throw new Error(error);
|
|
219
|
+
throw new Error(String(error));
|
|
217
220
|
}
|
|
218
221
|
}
|
|
219
222
|
/**
|
|
@@ -270,8 +273,8 @@ class QueryParser {
|
|
|
270
273
|
key !== '$regex' &&
|
|
271
274
|
key !== '$options' &&
|
|
272
275
|
this.isValidDateStr(value) &&
|
|
273
|
-
|
|
274
|
-
obj[key] =
|
|
276
|
+
(0, moment_1.default)(value).isValid()) {
|
|
277
|
+
obj[key] = (0, moment_1.default)(value).toDate();
|
|
275
278
|
}
|
|
276
279
|
else if (typeof value === 'object' && !validId && !(0, lodash_1.isNil)(value)) {
|
|
277
280
|
walk(obj[key]);
|
package/lib/query-parser.js
CHANGED
|
@@ -1,20 +1,23 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.MongooseQueryParser = void 0;
|
|
4
7
|
/* eslint-disable @typescript-eslint/no-unused-expressions */
|
|
5
8
|
/* eslint-disable @typescript-eslint/no-unsafe-return */
|
|
6
|
-
const
|
|
9
|
+
const moment_1 = __importDefault(require("moment"));
|
|
7
10
|
const qs_1 = require("qs");
|
|
8
11
|
const lodash_1 = require("lodash");
|
|
9
12
|
class MongooseQueryParser {
|
|
10
13
|
constructor(options = {}) {
|
|
11
14
|
this.options = options;
|
|
12
|
-
this.defaultDateFormat = [
|
|
15
|
+
this.defaultDateFormat = [moment_1.default.ISO_8601];
|
|
13
16
|
this.builtInCaster = {
|
|
14
17
|
// eslint-disable-next-line id-denylist
|
|
15
18
|
string: val => String(val),
|
|
16
19
|
date: val => {
|
|
17
|
-
const m =
|
|
20
|
+
const m = (0, moment_1.default)(val, this.options.dateFormat);
|
|
18
21
|
if (m.isValid()) {
|
|
19
22
|
return m.toDate();
|
|
20
23
|
}
|
|
@@ -111,7 +114,7 @@ class MongooseQueryParser {
|
|
|
111
114
|
return Number(value);
|
|
112
115
|
}
|
|
113
116
|
// Match dates
|
|
114
|
-
const m =
|
|
117
|
+
const m = (0, moment_1.default)(value, options.dateFormat);
|
|
115
118
|
if (m.isValid()) {
|
|
116
119
|
return m.toDate();
|
|
117
120
|
}
|
|
@@ -183,6 +186,7 @@ class MongooseQueryParser {
|
|
|
183
186
|
else if (!operator) {
|
|
184
187
|
return '$exists';
|
|
185
188
|
}
|
|
189
|
+
return '$eq';
|
|
186
190
|
}
|
|
187
191
|
/**
|
|
188
192
|
* cast select query to object like:
|
|
@@ -226,7 +230,7 @@ class MongooseQueryParser {
|
|
|
226
230
|
const [p, s] = qry.split('.', 2);
|
|
227
231
|
return s ? { path: p, select: s } : { path: p };
|
|
228
232
|
})
|
|
229
|
-
.reduce((prev, curr
|
|
233
|
+
.reduce((prev, curr) => {
|
|
230
234
|
// consolidate population array
|
|
231
235
|
const path = curr.path;
|
|
232
236
|
const select = curr.select;
|
package/lib/test.spec.js
CHANGED
|
@@ -8,6 +8,9 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
8
8
|
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
9
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
10
|
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
11
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
15
|
exports.Tester = void 0;
|
|
13
16
|
const mocha_1 = require("@testdeck/mocha");
|
|
@@ -15,7 +18,7 @@ const chai_1 = require("chai");
|
|
|
15
18
|
const _1 = require("./");
|
|
16
19
|
const mongoose_1 = require("mongoose");
|
|
17
20
|
const lodash_1 = require("lodash");
|
|
18
|
-
const
|
|
21
|
+
const moment_1 = __importDefault(require("moment"));
|
|
19
22
|
let Tester = class Tester {
|
|
20
23
|
generalParse() {
|
|
21
24
|
const parser = new _1.MongooseQueryParser();
|
|
@@ -200,7 +203,7 @@ let Tester = class Tester {
|
|
|
200
203
|
}
|
|
201
204
|
parseNestedFilter() {
|
|
202
205
|
const parser = new _1.MongooseQueryParser();
|
|
203
|
-
const now =
|
|
206
|
+
const now = (0, moment_1.default)();
|
|
204
207
|
const filter = {
|
|
205
208
|
dates: { startDate: { $gte: now.toDate() }, endDate: { $lte: now.add(1, 'day').toDate() } },
|
|
206
209
|
nested: {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@geekbears/gb-mongoose-query-parser",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.40",
|
|
4
4
|
"description": "Convert url query string to MongooseJs friendly query object including advanced filtering, sorting, population, deep population, string template, type casting and many more...",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"types": "./lib/index.d.ts",
|
|
@@ -35,22 +35,22 @@
|
|
|
35
35
|
"@types/chai": "^5.2.3",
|
|
36
36
|
"@types/lodash": "^4.17.24",
|
|
37
37
|
"@types/mocha": "^10.0.10",
|
|
38
|
-
"@types/node": "^25.
|
|
39
|
-
"@types/qs": "^6.
|
|
40
|
-
"@typescript-eslint/eslint-plugin": "^8.
|
|
41
|
-
"@typescript-eslint/parser": "^8.
|
|
38
|
+
"@types/node": "^25.6.0",
|
|
39
|
+
"@types/qs": "^6.15.0",
|
|
40
|
+
"@typescript-eslint/eslint-plugin": "^8.59.2",
|
|
41
|
+
"@typescript-eslint/parser": "^8.59.2",
|
|
42
42
|
"chai": "^6.2.2",
|
|
43
|
-
"eslint": "^10.0
|
|
43
|
+
"eslint": "^10.3.0",
|
|
44
44
|
"eslint-config-prettier": "^10.1.8",
|
|
45
45
|
"eslint-plugin-prettier": "^5.5.5",
|
|
46
46
|
"mocha": "^11.7.5",
|
|
47
|
-
"prettier": "^3.8.
|
|
47
|
+
"prettier": "^3.8.3",
|
|
48
48
|
"rimraf": "^6.1.3",
|
|
49
49
|
"ts-node": "^10.9.2",
|
|
50
|
-
"typescript": "^
|
|
50
|
+
"typescript": "^6.0.3"
|
|
51
51
|
},
|
|
52
52
|
"dependencies": {
|
|
53
|
-
"lodash": "^4.
|
|
53
|
+
"lodash": "^4.18.1",
|
|
54
54
|
"moment": "^2.30.1"
|
|
55
55
|
},
|
|
56
56
|
"peerDependencies": {
|