dbgate-filterparser 4.3.0 → 4.4.0-alpha.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/common.js +1 -0
- package/lib/filterTool.js +3 -2
- package/lib/getFilterType.js +5 -4
- package/lib/index.js +13 -6
- package/lib/mongoParser.js +22 -21
- package/lib/parseFilter.js +38 -37
- package/lib/parserFilter.test.js +1 -1
- package/package.json +4 -4
package/lib/common.js
CHANGED
|
@@ -3,6 +3,7 @@ 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.interpretEscapes = exports.word = exports.token = exports.whitespace = void 0;
|
|
6
7
|
const parsimmon_1 = __importDefault(require("parsimmon"));
|
|
7
8
|
exports.whitespace = parsimmon_1.default.regexp(/\s*/m);
|
|
8
9
|
function token(parser) {
|
package/lib/filterTool.js
CHANGED
|
@@ -3,13 +3,14 @@ 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
7
|
const dbgate_tools_1 = require("dbgate-tools");
|
|
7
8
|
const moment_1 = __importDefault(require("moment"));
|
|
8
9
|
function getFilterValueExpression(value, dataType) {
|
|
9
10
|
if (value == null)
|
|
10
11
|
return 'NULL';
|
|
11
|
-
if (dbgate_tools_1.isTypeDateTime(dataType))
|
|
12
|
-
return moment_1.default(value).format('YYYY-MM-DD HH:mm:ss');
|
|
12
|
+
if ((0, dbgate_tools_1.isTypeDateTime)(dataType))
|
|
13
|
+
return (0, moment_1.default)(value).format('YYYY-MM-DD HH:mm:ss');
|
|
13
14
|
return `="${value}"`;
|
|
14
15
|
}
|
|
15
16
|
exports.getFilterValueExpression = getFilterValueExpression;
|
package/lib/getFilterType.js
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getFilterType = void 0;
|
|
3
4
|
const dbgate_tools_1 = require("dbgate-tools");
|
|
4
5
|
function getFilterType(dataType) {
|
|
5
6
|
if (!dataType)
|
|
6
7
|
return 'string';
|
|
7
|
-
if (dbgate_tools_1.isTypeNumber(dataType))
|
|
8
|
+
if ((0, dbgate_tools_1.isTypeNumber)(dataType))
|
|
8
9
|
return 'number';
|
|
9
|
-
if (dbgate_tools_1.isTypeString(dataType))
|
|
10
|
+
if ((0, dbgate_tools_1.isTypeString)(dataType))
|
|
10
11
|
return 'string';
|
|
11
|
-
if (dbgate_tools_1.isTypeLogical(dataType))
|
|
12
|
+
if ((0, dbgate_tools_1.isTypeLogical)(dataType))
|
|
12
13
|
return 'logical';
|
|
13
|
-
if (dbgate_tools_1.isTypeDateTime(dataType))
|
|
14
|
+
if ((0, dbgate_tools_1.isTypeDateTime)(dataType))
|
|
14
15
|
return 'datetime';
|
|
15
16
|
return 'string';
|
|
16
17
|
}
|
package/lib/index.js
CHANGED
|
@@ -1,8 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
function
|
|
3
|
-
|
|
4
|
-
}
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
10
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
|
+
};
|
|
5
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
13
|
+
__exportStar(require("./parseFilter"), exports);
|
|
14
|
+
__exportStar(require("./getFilterType"), exports);
|
|
15
|
+
__exportStar(require("./filterTool"), exports);
|
package/lib/mongoParser.js
CHANGED
|
@@ -3,6 +3,7 @@ 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.mongoParser = void 0;
|
|
6
7
|
const parsimmon_1 = __importDefault(require("parsimmon"));
|
|
7
8
|
const common_1 = require("./common");
|
|
8
9
|
const operatorCondition = operator => value => ({
|
|
@@ -61,39 +62,39 @@ const negateCondition = condition => ({
|
|
|
61
62
|
});
|
|
62
63
|
const createParser = () => {
|
|
63
64
|
const langDef = {
|
|
64
|
-
string1: () => common_1.token(parsimmon_1.default.regexp(/"((?:\\.|.)*?)"/, 1))
|
|
65
|
+
string1: () => (0, common_1.token)(parsimmon_1.default.regexp(/"((?:\\.|.)*?)"/, 1))
|
|
65
66
|
.map(common_1.interpretEscapes)
|
|
66
67
|
.desc('string quoted'),
|
|
67
|
-
string2: () => common_1.token(parsimmon_1.default.regexp(/'((?:\\.|.)*?)'/, 1))
|
|
68
|
+
string2: () => (0, common_1.token)(parsimmon_1.default.regexp(/'((?:\\.|.)*?)'/, 1))
|
|
68
69
|
.map(common_1.interpretEscapes)
|
|
69
70
|
.desc('string quoted'),
|
|
70
|
-
number: () => common_1.token(parsimmon_1.default.regexp(/-?(0|[1-9][0-9]*)([.][0-9]+)?([eE][+-]?[0-9]+)?/))
|
|
71
|
+
number: () => (0, common_1.token)(parsimmon_1.default.regexp(/-?(0|[1-9][0-9]*)([.][0-9]+)?([eE][+-]?[0-9]+)?/))
|
|
71
72
|
.map(Number)
|
|
72
73
|
.desc('number'),
|
|
73
|
-
objectid: () => common_1.token(parsimmon_1.default.regexp(/[0-9a-f]{24}/)).desc('ObjectId'),
|
|
74
|
+
objectid: () => (0, common_1.token)(parsimmon_1.default.regexp(/[0-9a-f]{24}/)).desc('ObjectId'),
|
|
74
75
|
noQuotedString: () => parsimmon_1.default.regexp(/[^\s^,^'^"]+/).desc('string unquoted'),
|
|
75
76
|
value: r => parsimmon_1.default.alt(r.objectid, r.string1, r.string2, r.number, r.noQuotedString),
|
|
76
77
|
valueTestObjectId: r => r.objectid.map(objectIdTestCondition()),
|
|
77
78
|
valueTestNum: r => r.number.map(numberTestCondition()),
|
|
78
79
|
valueTest: r => r.value.map(regexCondition('.*#VALUE#.*')),
|
|
79
|
-
comma: () => common_1.word(','),
|
|
80
|
-
not: () => common_1.word('NOT'),
|
|
80
|
+
comma: () => (0, common_1.word)(','),
|
|
81
|
+
not: () => (0, common_1.word)('NOT'),
|
|
81
82
|
notExists: r => r.not.then(r.exists).map(testCondition('$exists', false)),
|
|
82
|
-
exists: () => common_1.word('EXISTS').map(testCondition('$exists', true)),
|
|
83
|
-
true: () => common_1.word('TRUE').map(testCondition('$eq', true)),
|
|
84
|
-
false: () => common_1.word('FALSE').map(testCondition('$eq', false)),
|
|
85
|
-
eq: r => common_1.word('=').then(r.value).map(operatorCondition('$eq')),
|
|
86
|
-
ne: r => common_1.word('!=').then(r.value).map(operatorCondition('$ne')),
|
|
87
|
-
lt: r => common_1.word('<').then(r.value).map(operatorCondition('$lt')),
|
|
88
|
-
gt: r => common_1.word('>').then(r.value).map(operatorCondition('$gt')),
|
|
89
|
-
le: r => common_1.word('<=').then(r.value).map(operatorCondition('$lte')),
|
|
90
|
-
ge: r => common_1.word('>=').then(r.value).map(operatorCondition('$gte')),
|
|
91
|
-
startsWith: r => common_1.word('^').then(r.value).map(regexCondition('#VALUE#.*')),
|
|
92
|
-
endsWith: r => common_1.word('$').then(r.value).map(regexCondition('.*#VALUE#')),
|
|
93
|
-
contains: r => common_1.word('+').then(r.value).map(regexCondition('.*#VALUE#.*')),
|
|
94
|
-
startsWithNot: r => common_1.word('!^').then(r.value).map(regexCondition('#VALUE#.*')).map(negateCondition),
|
|
95
|
-
endsWithNot: r => common_1.word('!$').then(r.value).map(regexCondition('.*#VALUE#')).map(negateCondition),
|
|
96
|
-
containsNot: r => common_1.word('~').then(r.value).map(regexCondition('.*#VALUE#.*')).map(negateCondition),
|
|
83
|
+
exists: () => (0, common_1.word)('EXISTS').map(testCondition('$exists', true)),
|
|
84
|
+
true: () => (0, common_1.word)('TRUE').map(testCondition('$eq', true)),
|
|
85
|
+
false: () => (0, common_1.word)('FALSE').map(testCondition('$eq', false)),
|
|
86
|
+
eq: r => (0, common_1.word)('=').then(r.value).map(operatorCondition('$eq')),
|
|
87
|
+
ne: r => (0, common_1.word)('!=').then(r.value).map(operatorCondition('$ne')),
|
|
88
|
+
lt: r => (0, common_1.word)('<').then(r.value).map(operatorCondition('$lt')),
|
|
89
|
+
gt: r => (0, common_1.word)('>').then(r.value).map(operatorCondition('$gt')),
|
|
90
|
+
le: r => (0, common_1.word)('<=').then(r.value).map(operatorCondition('$lte')),
|
|
91
|
+
ge: r => (0, common_1.word)('>=').then(r.value).map(operatorCondition('$gte')),
|
|
92
|
+
startsWith: r => (0, common_1.word)('^').then(r.value).map(regexCondition('#VALUE#.*')),
|
|
93
|
+
endsWith: r => (0, common_1.word)('$').then(r.value).map(regexCondition('.*#VALUE#')),
|
|
94
|
+
contains: r => (0, common_1.word)('+').then(r.value).map(regexCondition('.*#VALUE#.*')),
|
|
95
|
+
startsWithNot: r => (0, common_1.word)('!^').then(r.value).map(regexCondition('#VALUE#.*')).map(negateCondition),
|
|
96
|
+
endsWithNot: r => (0, common_1.word)('!$').then(r.value).map(regexCondition('.*#VALUE#')).map(negateCondition),
|
|
97
|
+
containsNot: r => (0, common_1.word)('~').then(r.value).map(regexCondition('.*#VALUE#.*')).map(negateCondition),
|
|
97
98
|
element: r => parsimmon_1.default.alt(r.exists, r.notExists, r.true, r.false, r.eq, r.ne, r.lt, r.gt, r.le, r.ge, r.startsWith, r.endsWith, r.contains, r.startsWithNot, r.endsWithNot, r.containsNot, r.valueTestObjectId, r.valueTestNum, r.valueTest).trim(common_1.whitespace),
|
|
98
99
|
factor: r => r.element.sepBy(common_1.whitespace).map(compoudCondition('$and')),
|
|
99
100
|
list: r => r.factor.sepBy(r.comma).map(compoudCondition('$or')),
|
package/lib/parseFilter.js
CHANGED
|
@@ -3,6 +3,7 @@ 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.parseFilter = void 0;
|
|
6
7
|
const parsimmon_1 = __importDefault(require("parsimmon"));
|
|
7
8
|
const moment_1 = __importDefault(require("moment"));
|
|
8
9
|
const common_1 = require("./common");
|
|
@@ -134,7 +135,7 @@ const createDateIntervalCondition = (start, end) => {
|
|
|
134
135
|
return createIntervalCondition(start.format('YYYY-MM-DDTHH:mm:ss.SSS'), end.format('YYYY-MM-DDTHH:mm:ss.SSS'));
|
|
135
136
|
};
|
|
136
137
|
const fixedMomentIntervalCondition = (intervalType, diff) => () => {
|
|
137
|
-
return createDateIntervalCondition(moment_1.default().add(intervalType, diff).startOf(intervalType), moment_1.default().add(intervalType, diff).endOf(intervalType));
|
|
138
|
+
return createDateIntervalCondition((0, moment_1.default)().add(intervalType, diff).startOf(intervalType), (0, moment_1.default)().add(intervalType, diff).endOf(intervalType));
|
|
138
139
|
};
|
|
139
140
|
const yearMonthDayMinuteCondition = () => value => {
|
|
140
141
|
const m = value.match(/(\d\d\d\d)-(\d\d?)-(\d\d?)\s+(\d\d?):(\d\d?)/);
|
|
@@ -144,7 +145,7 @@ const yearMonthDayMinuteCondition = () => value => {
|
|
|
144
145
|
const hour = m[4];
|
|
145
146
|
const minute = m[5];
|
|
146
147
|
const dateObject = new Date(year, month - 1, day, hour, minute);
|
|
147
|
-
return createDateIntervalCondition(moment_1.default(dateObject).startOf('minute'), moment_1.default(dateObject).endOf('minute'));
|
|
148
|
+
return createDateIntervalCondition((0, moment_1.default)(dateObject).startOf('minute'), (0, moment_1.default)(dateObject).endOf('minute'));
|
|
148
149
|
};
|
|
149
150
|
const yearMonthDaySecondCondition = () => value => {
|
|
150
151
|
const m = value.match(/(\d\d\d\d)-(\d\d?)-(\d\d?)(T|\s+)(\d\d?):(\d\d?):(\d\d?)/);
|
|
@@ -155,23 +156,23 @@ const yearMonthDaySecondCondition = () => value => {
|
|
|
155
156
|
const minute = m[6];
|
|
156
157
|
const second = m[7];
|
|
157
158
|
const dateObject = new Date(year, month - 1, day, hour, minute, second);
|
|
158
|
-
return createDateIntervalCondition(moment_1.default(dateObject).startOf('second'), moment_1.default(dateObject).endOf('second'));
|
|
159
|
+
return createDateIntervalCondition((0, moment_1.default)(dateObject).startOf('second'), (0, moment_1.default)(dateObject).endOf('second'));
|
|
159
160
|
};
|
|
160
161
|
const createParser = (filterType) => {
|
|
161
162
|
const langDef = {
|
|
162
|
-
string1: () => common_1.token(parsimmon_1.default.regexp(/"((?:\\.|.)*?)"/, 1))
|
|
163
|
+
string1: () => (0, common_1.token)(parsimmon_1.default.regexp(/"((?:\\.|.)*?)"/, 1))
|
|
163
164
|
.map(common_1.interpretEscapes)
|
|
164
165
|
.desc('string quoted'),
|
|
165
|
-
string2: () => common_1.token(parsimmon_1.default.regexp(/'((?:\\.|.)*?)'/, 1))
|
|
166
|
+
string2: () => (0, common_1.token)(parsimmon_1.default.regexp(/'((?:\\.|.)*?)'/, 1))
|
|
166
167
|
.map(common_1.interpretEscapes)
|
|
167
168
|
.desc('string quoted'),
|
|
168
|
-
string1Num: () => common_1.token(parsimmon_1.default.regexp(/"-?(0|[1-9][0-9]*)([.][0-9]+)?([eE][+-]?[0-9]+)?"/, 1))
|
|
169
|
+
string1Num: () => (0, common_1.token)(parsimmon_1.default.regexp(/"-?(0|[1-9][0-9]*)([.][0-9]+)?([eE][+-]?[0-9]+)?"/, 1))
|
|
169
170
|
.map(Number)
|
|
170
171
|
.desc('numer quoted'),
|
|
171
|
-
string2Num: () => common_1.token(parsimmon_1.default.regexp(/'-?(0|[1-9][0-9]*)([.][0-9]+)?([eE][+-]?[0-9]+)?'/, 1))
|
|
172
|
+
string2Num: () => (0, common_1.token)(parsimmon_1.default.regexp(/'-?(0|[1-9][0-9]*)([.][0-9]+)?([eE][+-]?[0-9]+)?'/, 1))
|
|
172
173
|
.map(Number)
|
|
173
174
|
.desc('numer quoted'),
|
|
174
|
-
number: () => common_1.token(parsimmon_1.default.regexp(/-?(0|[1-9][0-9]*)([.][0-9]+)?([eE][+-]?[0-9]+)?/))
|
|
175
|
+
number: () => (0, common_1.token)(parsimmon_1.default.regexp(/-?(0|[1-9][0-9]*)([.][0-9]+)?([eE][+-]?[0-9]+)?/))
|
|
175
176
|
.map(Number)
|
|
176
177
|
.desc('number'),
|
|
177
178
|
noQuotedString: () => parsimmon_1.default.regexp(/[^\s^,^'^"]+/).desc('string unquoted'),
|
|
@@ -183,25 +184,25 @@ const createParser = (filterType) => {
|
|
|
183
184
|
value: r => parsimmon_1.default.alt(...allowedValues.map(x => r[x])),
|
|
184
185
|
valueTestEq: r => r.value.map(binaryCondition('=')),
|
|
185
186
|
valueTestStr: r => r.value.map(likeCondition('like', '%#VALUE#%')),
|
|
186
|
-
comma: () => common_1.word(','),
|
|
187
|
-
not: () => common_1.word('NOT'),
|
|
187
|
+
comma: () => (0, common_1.word)(','),
|
|
188
|
+
not: () => (0, common_1.word)('NOT'),
|
|
188
189
|
notNull: r => r.not.then(r.null).map(unaryCondition('isNotNull')),
|
|
189
|
-
null: () => common_1.word('NULL').map(unaryCondition('isNull')),
|
|
190
|
-
empty: () => common_1.word('EMPTY').map(unaryCondition('isEmpty')),
|
|
190
|
+
null: () => (0, common_1.word)('NULL').map(unaryCondition('isNull')),
|
|
191
|
+
empty: () => (0, common_1.word)('EMPTY').map(unaryCondition('isEmpty')),
|
|
191
192
|
notEmpty: r => r.not.then(r.empty).map(unaryCondition('isNotEmpty')),
|
|
192
|
-
true: () => common_1.word('TRUE').map(binaryFixedValueCondition(1)),
|
|
193
|
-
false: () => common_1.word('FALSE').map(binaryFixedValueCondition(0)),
|
|
194
|
-
trueNum: () => common_1.word('1').map(binaryFixedValueCondition(1)),
|
|
195
|
-
falseNum: () => common_1.word('0').map(binaryFixedValueCondition(0)),
|
|
196
|
-
this: () => common_1.word('THIS'),
|
|
197
|
-
last: () => common_1.word('LAST'),
|
|
198
|
-
next: () => common_1.word('NEXT'),
|
|
199
|
-
week: () => common_1.word('WEEK'),
|
|
200
|
-
month: () => common_1.word('MONTH'),
|
|
201
|
-
year: () => common_1.word('YEAR'),
|
|
202
|
-
yesterday: () => common_1.word('YESTERDAY').map(fixedMomentIntervalCondition('day', -1)),
|
|
203
|
-
today: () => common_1.word('TODAY').map(fixedMomentIntervalCondition('day', 0)),
|
|
204
|
-
tomorrow: () => common_1.word('TOMORROW').map(fixedMomentIntervalCondition('day', 1)),
|
|
193
|
+
true: () => (0, common_1.word)('TRUE').map(binaryFixedValueCondition(1)),
|
|
194
|
+
false: () => (0, common_1.word)('FALSE').map(binaryFixedValueCondition(0)),
|
|
195
|
+
trueNum: () => (0, common_1.word)('1').map(binaryFixedValueCondition(1)),
|
|
196
|
+
falseNum: () => (0, common_1.word)('0').map(binaryFixedValueCondition(0)),
|
|
197
|
+
this: () => (0, common_1.word)('THIS'),
|
|
198
|
+
last: () => (0, common_1.word)('LAST'),
|
|
199
|
+
next: () => (0, common_1.word)('NEXT'),
|
|
200
|
+
week: () => (0, common_1.word)('WEEK'),
|
|
201
|
+
month: () => (0, common_1.word)('MONTH'),
|
|
202
|
+
year: () => (0, common_1.word)('YEAR'),
|
|
203
|
+
yesterday: () => (0, common_1.word)('YESTERDAY').map(fixedMomentIntervalCondition('day', -1)),
|
|
204
|
+
today: () => (0, common_1.word)('TODAY').map(fixedMomentIntervalCondition('day', 0)),
|
|
205
|
+
tomorrow: () => (0, common_1.word)('TOMORROW').map(fixedMomentIntervalCondition('day', 1)),
|
|
205
206
|
lastWeek: r => r.last.then(r.week).map(fixedMomentIntervalCondition('week', -1)),
|
|
206
207
|
thisWeek: r => r.this.then(r.week).map(fixedMomentIntervalCondition('week', 0)),
|
|
207
208
|
nextWeek: r => r.next.then(r.week).map(fixedMomentIntervalCondition('week', 1)),
|
|
@@ -211,18 +212,18 @@ const createParser = (filterType) => {
|
|
|
211
212
|
lastYear: r => r.last.then(r.year).map(fixedMomentIntervalCondition('year', -1)),
|
|
212
213
|
thisYear: r => r.this.then(r.year).map(fixedMomentIntervalCondition('year', 0)),
|
|
213
214
|
nextYear: r => r.next.then(r.year).map(fixedMomentIntervalCondition('year', 1)),
|
|
214
|
-
eq: r => common_1.word('=').then(r.value).map(binaryCondition('=')),
|
|
215
|
-
ne: r => common_1.word('!=').then(r.value).map(binaryCondition('<>')),
|
|
216
|
-
lt: r => common_1.word('<').then(r.value).map(binaryCondition('<')),
|
|
217
|
-
gt: r => common_1.word('>').then(r.value).map(binaryCondition('>')),
|
|
218
|
-
le: r => common_1.word('<=').then(r.value).map(binaryCondition('<=')),
|
|
219
|
-
ge: r => common_1.word('>=').then(r.value).map(binaryCondition('>=')),
|
|
220
|
-
startsWith: r => common_1.word('^').then(r.value).map(likeCondition('like', '#VALUE#%')),
|
|
221
|
-
endsWith: r => common_1.word('$').then(r.value).map(likeCondition('like', '%#VALUE#')),
|
|
222
|
-
contains: r => common_1.word('+').then(r.value).map(likeCondition('like', '%#VALUE#%')),
|
|
223
|
-
startsWithNot: r => common_1.word('!^').then(r.value).map(likeCondition('like', '#VALUE#%')).map(negateCondition),
|
|
224
|
-
endsWithNot: r => common_1.word('!$').then(r.value).map(likeCondition('like', '%#VALUE#')).map(negateCondition),
|
|
225
|
-
containsNot: r => common_1.word('~').then(r.value).map(likeCondition('like', '%#VALUE#%')).map(negateCondition),
|
|
215
|
+
eq: r => (0, common_1.word)('=').then(r.value).map(binaryCondition('=')),
|
|
216
|
+
ne: r => (0, common_1.word)('!=').then(r.value).map(binaryCondition('<>')),
|
|
217
|
+
lt: r => (0, common_1.word)('<').then(r.value).map(binaryCondition('<')),
|
|
218
|
+
gt: r => (0, common_1.word)('>').then(r.value).map(binaryCondition('>')),
|
|
219
|
+
le: r => (0, common_1.word)('<=').then(r.value).map(binaryCondition('<=')),
|
|
220
|
+
ge: r => (0, common_1.word)('>=').then(r.value).map(binaryCondition('>=')),
|
|
221
|
+
startsWith: r => (0, common_1.word)('^').then(r.value).map(likeCondition('like', '#VALUE#%')),
|
|
222
|
+
endsWith: r => (0, common_1.word)('$').then(r.value).map(likeCondition('like', '%#VALUE#')),
|
|
223
|
+
contains: r => (0, common_1.word)('+').then(r.value).map(likeCondition('like', '%#VALUE#%')),
|
|
224
|
+
startsWithNot: r => (0, common_1.word)('!^').then(r.value).map(likeCondition('like', '#VALUE#%')).map(negateCondition),
|
|
225
|
+
endsWithNot: r => (0, common_1.word)('!$').then(r.value).map(likeCondition('like', '%#VALUE#')).map(negateCondition),
|
|
226
|
+
containsNot: r => (0, common_1.word)('~').then(r.value).map(likeCondition('like', '%#VALUE#%')).map(negateCondition),
|
|
226
227
|
element: r => parsimmon_1.default.alt(...allowedElements.map(x => r[x])).trim(common_1.whitespace),
|
|
227
228
|
factor: r => r.element.sepBy(common_1.whitespace).map(compoudCondition('and')),
|
|
228
229
|
list: r => r.factor.sepBy(r.comma).map(compoudCondition('or')),
|
package/lib/parserFilter.test.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const parseFilter_1 = require("./parseFilter");
|
|
4
4
|
test('parse string', () => {
|
|
5
|
-
const ast = parseFilter_1.parseFilter('"123"', 'string');
|
|
5
|
+
const ast = (0, parseFilter_1.parseFilter)('"123"', 'string');
|
|
6
6
|
console.log(JSON.stringify(ast));
|
|
7
7
|
expect(ast).toEqual({
|
|
8
8
|
conditionType: 'like',
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "4.
|
|
2
|
+
"version": "4.4.0-alpha.1",
|
|
3
3
|
"name": "dbgate-filterparser",
|
|
4
4
|
"main": "lib/index.js",
|
|
5
5
|
"typings": "lib/index.d.ts",
|
|
@@ -13,16 +13,16 @@
|
|
|
13
13
|
"lib"
|
|
14
14
|
],
|
|
15
15
|
"devDependencies": {
|
|
16
|
-
"dbgate-types": "^4.
|
|
16
|
+
"dbgate-types": "^4.4.0-alpha.1",
|
|
17
17
|
"@types/jest": "^25.1.4",
|
|
18
18
|
"@types/node": "^13.7.0",
|
|
19
19
|
"jest": "^24.9.0",
|
|
20
20
|
"ts-jest": "^25.2.1",
|
|
21
|
-
"typescript": "^
|
|
21
|
+
"typescript": "^4.4.3"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
24
|
"@types/parsimmon": "^1.10.1",
|
|
25
|
-
"dbgate-tools": "^4.
|
|
25
|
+
"dbgate-tools": "^4.4.0-alpha.1",
|
|
26
26
|
"lodash": "^4.17.21",
|
|
27
27
|
"moment": "^2.24.0",
|
|
28
28
|
"parsimmon": "^1.13.0"
|