dbgate-filterparser 6.3.2 → 6.3.3
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/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/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "6.3.
|
|
2
|
+
"version": "6.3.3",
|
|
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.3.
|
|
16
|
+
"dbgate-types": "^6.3.3",
|
|
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.3.
|
|
25
|
+
"dbgate-tools": "^6.3.3",
|
|
26
26
|
"lodash": "^4.17.21",
|
|
27
27
|
"date-fns": "^4.1.0",
|
|
28
28
|
"moment": "^2.24.0",
|