dbgate-filterparser 6.5.6 → 6.6.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/lib/parseFilter.js +31 -13
- package/package.json +3 -3
package/lib/parseFilter.js
CHANGED
|
@@ -8,9 +8,10 @@ const parsimmon_1 = __importDefault(require("parsimmon"));
|
|
|
8
8
|
const moment_1 = __importDefault(require("moment"));
|
|
9
9
|
const common_1 = require("./common");
|
|
10
10
|
const dbgate_tools_1 = require("dbgate-tools");
|
|
11
|
-
const binaryCondition = (operator,
|
|
11
|
+
const binaryCondition = (operator, filterBehaviour = {}) => value => {
|
|
12
|
+
const { passNumbers, allowNumberDualTesting } = filterBehaviour;
|
|
12
13
|
const numValue = (0, dbgate_tools_1.parseNumberSafe)(value);
|
|
13
|
-
if (
|
|
14
|
+
if (allowNumberDualTesting &&
|
|
14
15
|
// @ts-ignore
|
|
15
16
|
!isNaN(numValue)) {
|
|
16
17
|
return {
|
|
@@ -41,6 +42,20 @@ const binaryCondition = (operator, numberDualTesting = false) => value => {
|
|
|
41
42
|
],
|
|
42
43
|
};
|
|
43
44
|
}
|
|
45
|
+
// @ts-ignore
|
|
46
|
+
if (passNumbers && !isNaN(numValue)) {
|
|
47
|
+
return {
|
|
48
|
+
conditionType: 'binary',
|
|
49
|
+
operator,
|
|
50
|
+
left: {
|
|
51
|
+
exprType: 'placeholder',
|
|
52
|
+
},
|
|
53
|
+
right: {
|
|
54
|
+
exprType: 'value',
|
|
55
|
+
value: numValue,
|
|
56
|
+
},
|
|
57
|
+
};
|
|
58
|
+
}
|
|
44
59
|
return {
|
|
45
60
|
conditionType: 'binary',
|
|
46
61
|
operator,
|
|
@@ -381,17 +396,17 @@ const createParser = (filterBehaviour) => {
|
|
|
381
396
|
null: () => (0, common_1.word)('NULL').map(unaryCondition('isNull')),
|
|
382
397
|
isEmpty: r => r.empty.map(unaryCondition('isEmpty')),
|
|
383
398
|
isNotEmpty: r => r.not.then(r.empty).map(unaryCondition('isNotEmpty')),
|
|
384
|
-
true: () => parsimmon_1.default.regexp(/true/i).map(binaryFixedValueCondition('1')),
|
|
385
|
-
false: () => parsimmon_1.default.regexp(/false/i).map(binaryFixedValueCondition('0')),
|
|
399
|
+
true: () => parsimmon_1.default.regexp(/true/i).map(binaryFixedValueCondition(filterBehaviour.passBooleans ? true : '1')),
|
|
400
|
+
false: () => parsimmon_1.default.regexp(/false/i).map(binaryFixedValueCondition(filterBehaviour.passBooleans ? false : '0')),
|
|
386
401
|
trueNum: () => (0, common_1.word)('1').map(binaryFixedValueCondition('1')),
|
|
387
402
|
falseNum: () => (0, common_1.word)('0').map(binaryFixedValueCondition('0')),
|
|
388
|
-
eq: r => (0, common_1.word)('=').then(r.value).map(binaryCondition('=', filterBehaviour
|
|
389
|
-
ne: r => (0, common_1.word)('!=').then(r.value).map(binaryCondition('<>', filterBehaviour
|
|
390
|
-
ne2: r => (0, common_1.word)('<>').then(r.value).map(binaryCondition('<>', filterBehaviour
|
|
391
|
-
le: r => (0, common_1.word)('<=').then(r.value).map(binaryCondition('<=', filterBehaviour
|
|
392
|
-
ge: r => (0, common_1.word)('>=').then(r.value).map(binaryCondition('>=', filterBehaviour
|
|
393
|
-
lt: r => (0, common_1.word)('<').then(r.value).map(binaryCondition('<', filterBehaviour
|
|
394
|
-
gt: r => (0, common_1.word)('>').then(r.value).map(binaryCondition('>', filterBehaviour
|
|
403
|
+
eq: r => (0, common_1.word)('=').then(r.value).map(binaryCondition('=', filterBehaviour)),
|
|
404
|
+
ne: r => (0, common_1.word)('!=').then(r.value).map(binaryCondition('<>', filterBehaviour)),
|
|
405
|
+
ne2: r => (0, common_1.word)('<>').then(r.value).map(binaryCondition('<>', filterBehaviour)),
|
|
406
|
+
le: r => (0, common_1.word)('<=').then(r.value).map(binaryCondition('<=', filterBehaviour)),
|
|
407
|
+
ge: r => (0, common_1.word)('>=').then(r.value).map(binaryCondition('>=', filterBehaviour)),
|
|
408
|
+
lt: r => (0, common_1.word)('<').then(r.value).map(binaryCondition('<', filterBehaviour)),
|
|
409
|
+
gt: r => (0, common_1.word)('>').then(r.value).map(binaryCondition('>', filterBehaviour)),
|
|
395
410
|
startsWith: r => (0, common_1.word)('^').then(r.value).map(likeCondition('like', '#VALUE#%')),
|
|
396
411
|
endsWith: r => (0, common_1.word)('$').then(r.value).map(likeCondition('like', '%#VALUE#')),
|
|
397
412
|
contains: r => (0, common_1.word)('+').then(r.value).map(likeCondition('like', '%#VALUE#%')),
|
|
@@ -422,8 +437,11 @@ const createParser = (filterBehaviour) => {
|
|
|
422
437
|
if (filterBehaviour.supportExistsTesting) {
|
|
423
438
|
allowedElements.push('exists', 'notExists');
|
|
424
439
|
}
|
|
425
|
-
if (filterBehaviour.
|
|
426
|
-
allowedElements.push('emptyArray'
|
|
440
|
+
if (filterBehaviour.supportEmptyArrayTesting) {
|
|
441
|
+
allowedElements.push('emptyArray');
|
|
442
|
+
}
|
|
443
|
+
if (filterBehaviour.supportNotEmptyArrayTesting) {
|
|
444
|
+
allowedElements.push('notEmptyArray');
|
|
427
445
|
}
|
|
428
446
|
if (filterBehaviour.supportNullTesting) {
|
|
429
447
|
allowedElements.push('null', 'notNull');
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "6.
|
|
2
|
+
"version": "6.6.1",
|
|
3
3
|
"name": "dbgate-filterparser",
|
|
4
4
|
"main": "lib/index.js",
|
|
5
5
|
"typings": "lib/index.d.ts",
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"lib"
|
|
14
14
|
],
|
|
15
15
|
"devDependencies": {
|
|
16
|
-
"dbgate-types": "^6.
|
|
16
|
+
"dbgate-types": "^6.6.1",
|
|
17
17
|
"@types/jest": "^25.1.4",
|
|
18
18
|
"@types/node": "^13.7.0",
|
|
19
19
|
"jest": "^28.1.3",
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
24
|
"@types/parsimmon": "^1.10.1",
|
|
25
|
-
"dbgate-tools": "^6.
|
|
25
|
+
"dbgate-tools": "^6.6.1",
|
|
26
26
|
"lodash": "^4.17.21",
|
|
27
27
|
"date-fns": "^4.1.0",
|
|
28
28
|
"moment": "^2.24.0",
|