dbgate-filterparser 6.3.2 → 6.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/lib/filterTool.d.ts +4 -0
- package/lib/filterTool.js +31 -1
- package/lib/parseFilter.js +17 -3
- package/package.json +3 -3
package/lib/filterTool.d.ts
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
import { Condition } from 'dbgate-sqltree';
|
|
1
2
|
export type FilterMultipleValuesMode = 'is' | 'is_not' | 'contains' | 'begins' | 'ends';
|
|
2
3
|
export declare function getFilterValueExpression(value: any, dataType?: any): string;
|
|
3
4
|
export declare function createMultiLineFilter(mode: FilterMultipleValuesMode, text: string): string;
|
|
5
|
+
export declare function compileCompoudEvalCondition(filters: {
|
|
6
|
+
[column: string]: string;
|
|
7
|
+
}): Condition;
|
package/lib/filterTool.js
CHANGED
|
@@ -3,10 +3,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.createMultiLineFilter = exports.getFilterValueExpression = void 0;
|
|
6
|
+
exports.compileCompoudEvalCondition = exports.createMultiLineFilter = exports.getFilterValueExpression = void 0;
|
|
7
7
|
const dbgate_tools_1 = require("dbgate-tools");
|
|
8
8
|
const date_fns_1 = require("date-fns");
|
|
9
9
|
const isString_1 = __importDefault(require("lodash/isString"));
|
|
10
|
+
const cloneDeepWith_1 = __importDefault(require("lodash/cloneDeepWith"));
|
|
11
|
+
const parseFilter_1 = require("./parseFilter");
|
|
10
12
|
function getDateStringWithoutTimeZone(dateString) {
|
|
11
13
|
if ((0, isString_1.default)(dateString)) {
|
|
12
14
|
return dateString.replace(/Z|([+-]\d{2}:\d{2})$/, '');
|
|
@@ -67,3 +69,31 @@ function createMultiLineFilter(mode, text) {
|
|
|
67
69
|
return res;
|
|
68
70
|
}
|
|
69
71
|
exports.createMultiLineFilter = createMultiLineFilter;
|
|
72
|
+
function compileCompoudEvalCondition(filters) {
|
|
73
|
+
if (!filters)
|
|
74
|
+
return null;
|
|
75
|
+
const conditions = [];
|
|
76
|
+
for (const name in filters) {
|
|
77
|
+
try {
|
|
78
|
+
const condition = (0, parseFilter_1.parseFilter)(filters[name], dbgate_tools_1.evalFilterBehaviour);
|
|
79
|
+
const replaced = (0, cloneDeepWith_1.default)(condition, (expr) => {
|
|
80
|
+
if (expr.exprType == 'placeholder')
|
|
81
|
+
return {
|
|
82
|
+
exprType: 'column',
|
|
83
|
+
columnName: name,
|
|
84
|
+
};
|
|
85
|
+
});
|
|
86
|
+
conditions.push(replaced);
|
|
87
|
+
}
|
|
88
|
+
catch (err) {
|
|
89
|
+
// filter parse error - ignore filter
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
if (conditions.length == 0)
|
|
93
|
+
return null;
|
|
94
|
+
return {
|
|
95
|
+
conditionType: 'and',
|
|
96
|
+
conditions,
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
exports.compileCompoudEvalCondition = compileCompoudEvalCondition;
|
package/lib/parseFilter.js
CHANGED
|
@@ -51,6 +51,17 @@ const binaryCondition = (operator, numberDualTesting = false) => value => {
|
|
|
51
51
|
},
|
|
52
52
|
};
|
|
53
53
|
};
|
|
54
|
+
const simpleEqualCondition = () => value => ({
|
|
55
|
+
conditionType: 'binary',
|
|
56
|
+
operator: '=',
|
|
57
|
+
left: {
|
|
58
|
+
exprType: 'placeholder',
|
|
59
|
+
},
|
|
60
|
+
right: {
|
|
61
|
+
exprType: 'value',
|
|
62
|
+
value,
|
|
63
|
+
},
|
|
64
|
+
});
|
|
54
65
|
const likeCondition = (conditionType, likeString) => value => ({
|
|
55
66
|
conditionType,
|
|
56
67
|
left: {
|
|
@@ -299,6 +310,7 @@ const createParser = (filterBehaviour) => {
|
|
|
299
310
|
.map(Number)
|
|
300
311
|
.desc('number'),
|
|
301
312
|
objectid: () => (0, common_1.token)(parsimmon_1.default.regexp(/ObjectId\(['"]?[0-9a-f]{24}['"]?\)/)).desc('ObjectId'),
|
|
313
|
+
objectidstr: () => (0, common_1.token)(parsimmon_1.default.regexp(/[0-9a-f]{24}/)).desc('ObjectId string'),
|
|
302
314
|
hexstring: () => (0, common_1.token)(parsimmon_1.default.regexp(/0x(([0-9a-fA-F][0-9a-fA-F])+)/, 1))
|
|
303
315
|
.map(x => ({
|
|
304
316
|
type: 'Buffer',
|
|
@@ -312,6 +324,7 @@ const createParser = (filterBehaviour) => {
|
|
|
312
324
|
value: r => parsimmon_1.default.alt(...allowedValues.map(x => r[x])),
|
|
313
325
|
valueTestEq: r => r.value.map(binaryCondition('=')),
|
|
314
326
|
hexTestEq: r => r.hexstring.map(binaryCondition('=')),
|
|
327
|
+
valueTestObjectIdStr: r => r.objectidstr.map(simpleEqualCondition()),
|
|
315
328
|
valueTestStr: r => r.value.map(likeCondition('like', '%#VALUE#%')),
|
|
316
329
|
valueTestNum: r => r.number.map(numberTestCondition()),
|
|
317
330
|
valueTestObjectId: r => r.objectid.map(objectIdTestCondition()),
|
|
@@ -439,12 +452,13 @@ const createParser = (filterBehaviour) => {
|
|
|
439
452
|
allowedElements.push('true', 'false', 'trueNum', 'falseNum');
|
|
440
453
|
}
|
|
441
454
|
}
|
|
442
|
-
if (filterBehaviour.allowNumberDualTesting) {
|
|
443
|
-
allowedElements.push('valueTestNum');
|
|
444
|
-
}
|
|
445
455
|
if (filterBehaviour.allowObjectIdTesting) {
|
|
456
|
+
allowedElements.push('valueTestObjectIdStr');
|
|
446
457
|
allowedElements.push('valueTestObjectId');
|
|
447
458
|
}
|
|
459
|
+
if (filterBehaviour.allowNumberDualTesting) {
|
|
460
|
+
allowedElements.push('valueTestNum');
|
|
461
|
+
}
|
|
448
462
|
// must be last
|
|
449
463
|
if (filterBehaviour.allowStringToken) {
|
|
450
464
|
allowedElements.push('valueTestStr');
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "6.
|
|
2
|
+
"version": "6.4.0",
|
|
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.4.0",
|
|
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.4.0",
|
|
26
26
|
"lodash": "^4.17.21",
|
|
27
27
|
"date-fns": "^4.1.0",
|
|
28
28
|
"moment": "^2.24.0",
|