dbgate-filterparser 5.1.0 → 5.1.2

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.
@@ -154,9 +154,32 @@ const binaryCondition = operator => value => ({
154
154
  value,
155
155
  },
156
156
  });
157
+ const unaryCondition = conditionType => () => {
158
+ return {
159
+ conditionType,
160
+ expr: {
161
+ exprType: 'placeholder',
162
+ },
163
+ };
164
+ };
165
+ const sqlTemplate = templateSql => {
166
+ return {
167
+ conditionType: 'rawTemplate',
168
+ templateSql,
169
+ expr: {
170
+ exprType: 'placeholder',
171
+ },
172
+ };
173
+ };
157
174
  const createParser = () => {
158
175
  const langDef = {
159
176
  comma: () => (0, common_1.word)(','),
177
+ not: () => (0, common_1.word)('NOT'),
178
+ notNull: r => r.not.then(r.null).map(unaryCondition('isNotNull')),
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'),
160
183
  yearNum: () => parsimmon_1.default.regexp(/\d\d\d\d/).map(yearCondition()),
161
184
  yearMonthNum: () => parsimmon_1.default.regexp(/\d\d\d\d-\d\d?/).map(yearMonthCondition()),
162
185
  yearMonthDayNum: () => parsimmon_1.default.regexp(/\d\d\d\d-\d\d?-\d\d?/).map(yearMonthDayCondition()),
@@ -196,7 +219,7 @@ const createParser = () => {
196
219
  ge: r => (0, common_1.word)('>=').then(r.valueStart).map(binaryCondition('>=')),
197
220
  lt: r => (0, common_1.word)('<').then(r.valueStart).map(binaryCondition('<')),
198
221
  gt: r => (0, common_1.word)('>').then(r.valueEnd).map(binaryCondition('>')),
199
- 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.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),
200
223
  factor: r => r.element.sepBy(common_1.whitespace).map(compoudCondition('$and')),
201
224
  list: r => r.factor.sepBy(r.comma).map(compoudCondition('$or')),
202
225
  };
@@ -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.0",
2
+ "version": "5.1.2",
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.0",
16
+ "dbgate-types": "^5.1.2",
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.0",
25
+ "dbgate-tools": "^5.1.2",
26
26
  "lodash": "^4.17.21",
27
27
  "moment": "^2.24.0",
28
28
  "parsimmon": "^1.13.0"