dbgate-filterparser 5.1.1 → 5.1.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/datetimeParser.js +13 -1
- package/lib/parseFilter.js +13 -1
- package/package.json +3 -3
package/lib/datetimeParser.js
CHANGED
|
@@ -162,12 +162,24 @@ const unaryCondition = conditionType => () => {
|
|
|
162
162
|
},
|
|
163
163
|
};
|
|
164
164
|
};
|
|
165
|
+
const sqlTemplate = templateSql => {
|
|
166
|
+
return {
|
|
167
|
+
conditionType: 'rawTemplate',
|
|
168
|
+
templateSql,
|
|
169
|
+
expr: {
|
|
170
|
+
exprType: 'placeholder',
|
|
171
|
+
},
|
|
172
|
+
};
|
|
173
|
+
};
|
|
165
174
|
const createParser = () => {
|
|
166
175
|
const langDef = {
|
|
167
176
|
comma: () => (0, common_1.word)(','),
|
|
168
177
|
not: () => (0, common_1.word)('NOT'),
|
|
169
178
|
notNull: r => r.not.then(r.null).map(unaryCondition('isNotNull')),
|
|
170
179
|
null: () => (0, common_1.word)('NULL').map(unaryCondition('isNull')),
|
|
180
|
+
sql: () => (0, common_1.token)(parsimmon_1.default.regexp(/\{(.*?)\}/, 1))
|
|
181
|
+
.map(sqlTemplate)
|
|
182
|
+
.desc('sql literal'),
|
|
171
183
|
yearNum: () => parsimmon_1.default.regexp(/\d\d\d\d/).map(yearCondition()),
|
|
172
184
|
yearMonthNum: () => parsimmon_1.default.regexp(/\d\d\d\d-\d\d?/).map(yearMonthCondition()),
|
|
173
185
|
yearMonthDayNum: () => parsimmon_1.default.regexp(/\d\d\d\d-\d\d?-\d\d?/).map(yearMonthDayCondition()),
|
|
@@ -207,7 +219,7 @@ const createParser = () => {
|
|
|
207
219
|
ge: r => (0, common_1.word)('>=').then(r.valueStart).map(binaryCondition('>=')),
|
|
208
220
|
lt: r => (0, common_1.word)('<').then(r.valueStart).map(binaryCondition('<')),
|
|
209
221
|
gt: r => (0, common_1.word)('>').then(r.valueEnd).map(binaryCondition('>')),
|
|
210
|
-
element: r => parsimmon_1.default.alt(r.yearMonthDaySecond, r.yearMonthDayMinute, r.yearMonthDayNum, r.yearMonthNum, r.yearNum, r.yesterday, r.today, r.tomorrow, r.lastWeek, r.thisWeek, r.nextWeek, r.lastMonth, r.thisMonth, r.nextMonth, r.lastYear, r.thisYear, r.nextYear, r.null, r.notNull, r.le, r.lt, r.ge, r.gt).trim(common_1.whitespace),
|
|
222
|
+
element: r => parsimmon_1.default.alt(r.yearMonthDaySecond, r.yearMonthDayMinute, r.yearMonthDayNum, r.yearMonthNum, r.yearNum, r.yesterday, r.today, r.tomorrow, r.lastWeek, r.thisWeek, r.nextWeek, r.lastMonth, r.thisMonth, r.nextMonth, r.lastYear, r.thisYear, r.nextYear, r.null, r.notNull, r.le, r.lt, r.ge, r.gt, r.sql).trim(common_1.whitespace),
|
|
211
223
|
factor: r => r.element.sepBy(common_1.whitespace).map(compoudCondition('$and')),
|
|
212
224
|
list: r => r.factor.sepBy(r.comma).map(compoudCondition('$or')),
|
|
213
225
|
};
|
package/lib/parseFilter.js
CHANGED
|
@@ -64,6 +64,15 @@ const negateCondition = condition => {
|
|
|
64
64
|
condition,
|
|
65
65
|
};
|
|
66
66
|
};
|
|
67
|
+
const sqlTemplate = templateSql => {
|
|
68
|
+
return {
|
|
69
|
+
conditionType: 'rawTemplate',
|
|
70
|
+
templateSql,
|
|
71
|
+
expr: {
|
|
72
|
+
exprType: 'placeholder',
|
|
73
|
+
},
|
|
74
|
+
};
|
|
75
|
+
};
|
|
67
76
|
const createParser = (filterType) => {
|
|
68
77
|
const langDef = {
|
|
69
78
|
string1: () => (0, common_1.token)(parsimmon_1.default.regexp(/"((?:\\.|.)*?)"/, 1))
|
|
@@ -82,6 +91,9 @@ const createParser = (filterType) => {
|
|
|
82
91
|
.map(Number)
|
|
83
92
|
.desc('number'),
|
|
84
93
|
noQuotedString: () => parsimmon_1.default.regexp(/[^\s^,^'^"]+/).desc('string unquoted'),
|
|
94
|
+
sql: () => (0, common_1.token)(parsimmon_1.default.regexp(/\{(.*?)\}/, 1))
|
|
95
|
+
.map(sqlTemplate)
|
|
96
|
+
.desc('sql literal'),
|
|
85
97
|
value: r => parsimmon_1.default.alt(...allowedValues.map(x => r[x])),
|
|
86
98
|
valueTestEq: r => r.value.map(binaryCondition('=')),
|
|
87
99
|
valueTestStr: r => r.value.map(likeCondition('like', '%#VALUE#%')),
|
|
@@ -119,7 +131,7 @@ const createParser = (filterType) => {
|
|
|
119
131
|
if (filterType == 'number') {
|
|
120
132
|
allowedValues.push('string1Num', 'string2Num', 'number');
|
|
121
133
|
}
|
|
122
|
-
const allowedElements = ['null', 'notNull', 'eq', 'ne', 'ne2'];
|
|
134
|
+
const allowedElements = ['null', 'notNull', 'eq', 'ne', 'ne2', 'sql'];
|
|
123
135
|
if (filterType == 'number' || filterType == 'datetime' || filterType == 'eval') {
|
|
124
136
|
allowedElements.push('le', 'ge', 'lt', 'gt');
|
|
125
137
|
}
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "5.1.
|
|
2
|
+
"version": "5.1.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": "^5.1.
|
|
16
|
+
"dbgate-types": "^5.1.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": "^5.1.
|
|
25
|
+
"dbgate-tools": "^5.1.3",
|
|
26
26
|
"lodash": "^4.17.21",
|
|
27
27
|
"moment": "^2.24.0",
|
|
28
28
|
"parsimmon": "^1.13.0"
|