@nymphjs/query-parser 1.0.0-beta.13 → 1.0.0-beta.131
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/CHANGELOG.md +499 -0
- package/README.md +64 -50
- package/dist/index.d.ts +4 -0
- package/dist/index.js +4 -1
- package/dist/index.js.map +1 -1
- package/dist/queryParser.js +953 -0
- package/dist/queryParser.js.map +1 -0
- package/dist/queryParser.test.js +1686 -0
- package/dist/queryParser.test.js.map +1 -0
- package/jest.config.js +31 -5
- package/package.json +35 -34
- package/src/index.ts +2 -2
- package/src/queryParser.test.ts +1106 -164
- package/src/queryParser.ts +425 -140
- package/tsconfig.json +7 -4
- package/typedoc.json +4 -0
- package/lib/index.d.ts +0 -4
- package/lib/index.js +0 -25
- package/lib/index.js.map +0 -1
- package/lib/queryParser.js +0 -672
- package/lib/queryParser.js.map +0 -1
- package/lib/queryParser.test.js +0 -856
- package/lib/queryParser.test.js.map +0 -1
- package/webpack.config.js +0 -28
- /package/{lib → dist}/queryParser.d.ts +0 -0
- /package/{lib → dist}/queryParser.test.d.ts +0 -0
package/lib/queryParser.js
DELETED
|
@@ -1,672 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const splitn_1 = __importDefault(require("@sciactive/splitn"));
|
|
7
|
-
function queryParser({ query, entityClass, defaultFields = ['name'], qrefMap = {}, bareHandler = (input, _class, defaultFields = ['name']) => {
|
|
8
|
-
if (!input.match(/[_%]/)) {
|
|
9
|
-
input = `%${input}%`;
|
|
10
|
-
}
|
|
11
|
-
if (defaultFields.length) {
|
|
12
|
-
return {
|
|
13
|
-
type: '|',
|
|
14
|
-
ilike: defaultFields.map((field) => [field, input]),
|
|
15
|
-
};
|
|
16
|
-
}
|
|
17
|
-
return {};
|
|
18
|
-
}, }) {
|
|
19
|
-
const options = { class: entityClass };
|
|
20
|
-
return [
|
|
21
|
-
options,
|
|
22
|
-
...selectorsParser({
|
|
23
|
-
query,
|
|
24
|
-
entityClass,
|
|
25
|
-
type: '&',
|
|
26
|
-
defaultFields,
|
|
27
|
-
qrefMap,
|
|
28
|
-
options,
|
|
29
|
-
bareHandler,
|
|
30
|
-
}),
|
|
31
|
-
];
|
|
32
|
-
}
|
|
33
|
-
exports.default = queryParser;
|
|
34
|
-
function selectorsParser({ query, entityClass, type, defaultFields, qrefMap, options, bareHandler, }) {
|
|
35
|
-
const selector = { type };
|
|
36
|
-
let curQuery = query;
|
|
37
|
-
const subSelectorPairs = [];
|
|
38
|
-
let inQuote = false;
|
|
39
|
-
let nesting = 0;
|
|
40
|
-
let currentStart = null;
|
|
41
|
-
for (let i = 0; i < curQuery.length; i++) {
|
|
42
|
-
if (curQuery[i] === '"') {
|
|
43
|
-
if (!inQuote) {
|
|
44
|
-
inQuote = true;
|
|
45
|
-
}
|
|
46
|
-
else if (curQuery[i - 1] !== '\\') {
|
|
47
|
-
inQuote = false;
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
else if (inQuote) {
|
|
51
|
-
continue;
|
|
52
|
-
}
|
|
53
|
-
else if (curQuery[i] === '(') {
|
|
54
|
-
if (currentStart == null) {
|
|
55
|
-
currentStart = i;
|
|
56
|
-
}
|
|
57
|
-
else {
|
|
58
|
-
nesting++;
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
else if (curQuery[i] === ')') {
|
|
62
|
-
if (nesting === 0) {
|
|
63
|
-
if (currentStart == null) {
|
|
64
|
-
}
|
|
65
|
-
else {
|
|
66
|
-
subSelectorPairs.push([currentStart, i + 1]);
|
|
67
|
-
currentStart = null;
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
else {
|
|
71
|
-
nesting--;
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
if (subSelectorPairs.length) {
|
|
76
|
-
selector.selector = [];
|
|
77
|
-
subSelectorPairs.reverse();
|
|
78
|
-
for (let pair of subSelectorPairs) {
|
|
79
|
-
let selectorQuery = curQuery.slice(pair[0] + 1, pair[1] - 1);
|
|
80
|
-
curQuery = curQuery.slice(0, pair[0]) + curQuery.slice(pair[1]);
|
|
81
|
-
let type = '&';
|
|
82
|
-
if (selectorQuery.startsWith('&')) {
|
|
83
|
-
selectorQuery = selectorQuery.slice(1);
|
|
84
|
-
}
|
|
85
|
-
else if (selectorQuery.startsWith('!&')) {
|
|
86
|
-
type = '!&';
|
|
87
|
-
selectorQuery = selectorQuery.slice(2);
|
|
88
|
-
}
|
|
89
|
-
else if (selectorQuery.startsWith('|')) {
|
|
90
|
-
type = '|';
|
|
91
|
-
selectorQuery = selectorQuery.slice(1);
|
|
92
|
-
}
|
|
93
|
-
else if (selectorQuery.startsWith('!|')) {
|
|
94
|
-
type = '!|';
|
|
95
|
-
selectorQuery = selectorQuery.slice(2);
|
|
96
|
-
}
|
|
97
|
-
else if (selectorQuery.startsWith('!')) {
|
|
98
|
-
type = '!&';
|
|
99
|
-
selectorQuery = selectorQuery.slice(1);
|
|
100
|
-
}
|
|
101
|
-
selector.selector.push(...selectorsParser({
|
|
102
|
-
query: selectorQuery,
|
|
103
|
-
entityClass,
|
|
104
|
-
type,
|
|
105
|
-
defaultFields,
|
|
106
|
-
qrefMap,
|
|
107
|
-
bareHandler,
|
|
108
|
-
}));
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
curQuery = selectorParser({
|
|
112
|
-
query: curQuery,
|
|
113
|
-
selector,
|
|
114
|
-
qrefMap,
|
|
115
|
-
bareHandler,
|
|
116
|
-
});
|
|
117
|
-
if (options) {
|
|
118
|
-
const limitRegex = /(?: |^)limit:(\d+)(?= |$)/;
|
|
119
|
-
const limitMatch = curQuery.match(limitRegex);
|
|
120
|
-
if (limitMatch) {
|
|
121
|
-
options.limit = Number(limitMatch[1]);
|
|
122
|
-
}
|
|
123
|
-
curQuery = curQuery.replace(limitRegex, '');
|
|
124
|
-
const offsetRegex = /(?: |^)offset:(\d+)(?= |$)/;
|
|
125
|
-
const offsetMatch = curQuery.match(offsetRegex);
|
|
126
|
-
if (offsetMatch) {
|
|
127
|
-
options.offset = Number(offsetMatch[1]);
|
|
128
|
-
}
|
|
129
|
-
curQuery = curQuery.replace(offsetRegex, '');
|
|
130
|
-
const reverseRegex = /(?: |^)reverse:(true|false|1|0)(?= |$)/;
|
|
131
|
-
const reverseMatch = curQuery.match(reverseRegex);
|
|
132
|
-
if (reverseMatch) {
|
|
133
|
-
options.reverse = reverseMatch[1] === 'true' || reverseMatch[1] === '1';
|
|
134
|
-
}
|
|
135
|
-
curQuery = curQuery.replace(reverseRegex, '');
|
|
136
|
-
}
|
|
137
|
-
curQuery = curQuery.trim();
|
|
138
|
-
if (curQuery.length) {
|
|
139
|
-
const bareSelector = bareHandler(curQuery, entityClass, defaultFields);
|
|
140
|
-
if (Object.keys(bareSelector).length) {
|
|
141
|
-
return [
|
|
142
|
-
...(Object.keys(selector).length > 1 ? [selector] : []),
|
|
143
|
-
{
|
|
144
|
-
type: '|',
|
|
145
|
-
...bareSelector,
|
|
146
|
-
},
|
|
147
|
-
];
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
if ('selector' in selector &&
|
|
151
|
-
selector.selector.length === 1 &&
|
|
152
|
-
Object.keys(selector).length === 2 &&
|
|
153
|
-
(selector.type === '&' || selector.type === '|')) {
|
|
154
|
-
return selector.selector;
|
|
155
|
-
}
|
|
156
|
-
return [selector];
|
|
157
|
-
}
|
|
158
|
-
function selectorParser({ query, selector, qrefMap, bareHandler, }) {
|
|
159
|
-
let curQuery = query;
|
|
160
|
-
const qrefRegex = /(?: |^)(\w+)!?<\{(\w+) (.*?[^\\])\}>(?= |$)/g;
|
|
161
|
-
const qrefMatch = curQuery.match(qrefRegex);
|
|
162
|
-
if (qrefMatch) {
|
|
163
|
-
selector.qref = [];
|
|
164
|
-
selector['!qref'] = [];
|
|
165
|
-
for (let match of qrefMatch) {
|
|
166
|
-
try {
|
|
167
|
-
let [name, value] = (0, splitn_1.default)(match.trim().slice(0, -1), '<', 2);
|
|
168
|
-
value = unQuoteCurlies(value.slice(1, -1));
|
|
169
|
-
let [className, qrefQuery] = value.split(' ', 2);
|
|
170
|
-
const EntityClass = qrefMap[className].class;
|
|
171
|
-
if (EntityClass == null) {
|
|
172
|
-
continue;
|
|
173
|
-
}
|
|
174
|
-
const qref = queryParser({
|
|
175
|
-
query: qrefQuery,
|
|
176
|
-
entityClass: EntityClass,
|
|
177
|
-
defaultFields: qrefMap[className].defaultFields,
|
|
178
|
-
qrefMap,
|
|
179
|
-
bareHandler,
|
|
180
|
-
});
|
|
181
|
-
if (name.endsWith('!')) {
|
|
182
|
-
selector['!qref'].push([name.slice(0, -1), qref]);
|
|
183
|
-
}
|
|
184
|
-
else {
|
|
185
|
-
selector.qref.push([name, qref]);
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
catch (e) {
|
|
189
|
-
continue;
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
if (!selector.qref.length) {
|
|
193
|
-
delete selector.qref;
|
|
194
|
-
}
|
|
195
|
-
if (!selector['!qref'].length) {
|
|
196
|
-
delete selector['!qref'];
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
curQuery = curQuery.replace(qrefRegex, '');
|
|
200
|
-
const equalRegex = /(?: |^)(\w+)!?=(""|".*?[^\\]"|[^ ]+)(?= |$)/g;
|
|
201
|
-
const equalMatch = curQuery.match(equalRegex);
|
|
202
|
-
if (equalMatch) {
|
|
203
|
-
selector.equal = [];
|
|
204
|
-
selector['!equal'] = [];
|
|
205
|
-
for (let match of equalMatch) {
|
|
206
|
-
try {
|
|
207
|
-
let [name, value] = match.trim().split('=', 2);
|
|
208
|
-
try {
|
|
209
|
-
if (name.endsWith('!')) {
|
|
210
|
-
selector['!equal'].push([name.slice(0, -1), JSON.parse(value)]);
|
|
211
|
-
}
|
|
212
|
-
else {
|
|
213
|
-
selector.equal.push([name, JSON.parse(value)]);
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
catch (e) {
|
|
217
|
-
if (name.endsWith('!')) {
|
|
218
|
-
selector['!equal'].push([name.slice(0, -1), unQuoteString(value)]);
|
|
219
|
-
}
|
|
220
|
-
else {
|
|
221
|
-
selector.equal.push([name, unQuoteString(value)]);
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
catch (e) {
|
|
226
|
-
continue;
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
if (!selector.equal.length) {
|
|
230
|
-
delete selector.equal;
|
|
231
|
-
}
|
|
232
|
-
if (!selector['!equal'].length) {
|
|
233
|
-
delete selector['!equal'];
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
curQuery = curQuery.replace(equalRegex, '');
|
|
237
|
-
const refRegex = /(?: |^)(\w+)!?<\{([0-9a-f]{24})\}>(?= |$)/g;
|
|
238
|
-
const refMatch = curQuery.match(refRegex);
|
|
239
|
-
if (refMatch) {
|
|
240
|
-
selector.ref = [];
|
|
241
|
-
selector['!ref'] = [];
|
|
242
|
-
for (let match of refMatch) {
|
|
243
|
-
try {
|
|
244
|
-
let [name, value] = match.trim().slice(0, -1).split('<', 2);
|
|
245
|
-
if (name.endsWith('!')) {
|
|
246
|
-
selector['!ref'].push([name.slice(0, -1), value.slice(1, -1)]);
|
|
247
|
-
}
|
|
248
|
-
else {
|
|
249
|
-
selector.ref.push([name, value.slice(1, -1)]);
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
catch (e) {
|
|
253
|
-
continue;
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
if (!selector.ref.length) {
|
|
257
|
-
delete selector.ref;
|
|
258
|
-
}
|
|
259
|
-
if (!selector['!ref'].length) {
|
|
260
|
-
delete selector['!ref'];
|
|
261
|
-
}
|
|
262
|
-
}
|
|
263
|
-
curQuery = curQuery.replace(refRegex, '');
|
|
264
|
-
const containRegex = /(?: |^)(\w+)!?(<.*?[^\\]>)(?= |$)/g;
|
|
265
|
-
const containMatch = curQuery.match(containRegex);
|
|
266
|
-
if (containMatch) {
|
|
267
|
-
selector.contain = [];
|
|
268
|
-
selector['!contain'] = [];
|
|
269
|
-
for (let match of containMatch) {
|
|
270
|
-
try {
|
|
271
|
-
let [name, value] = match.trim().slice(0, -1).split('<', 2);
|
|
272
|
-
try {
|
|
273
|
-
if (name.endsWith('!')) {
|
|
274
|
-
selector['!contain'].push([
|
|
275
|
-
name.slice(0, -1),
|
|
276
|
-
JSON.parse(unQuoteAngles(value)),
|
|
277
|
-
]);
|
|
278
|
-
}
|
|
279
|
-
else {
|
|
280
|
-
selector.contain.push([name, JSON.parse(unQuoteAngles(value))]);
|
|
281
|
-
}
|
|
282
|
-
}
|
|
283
|
-
catch (e) {
|
|
284
|
-
if (name.endsWith('!')) {
|
|
285
|
-
selector['!contain'].push([
|
|
286
|
-
name.slice(0, -1),
|
|
287
|
-
unQuoteAngles(value),
|
|
288
|
-
]);
|
|
289
|
-
}
|
|
290
|
-
else {
|
|
291
|
-
selector.contain.push([name, unQuoteAngles(value)]);
|
|
292
|
-
}
|
|
293
|
-
}
|
|
294
|
-
}
|
|
295
|
-
catch (e) {
|
|
296
|
-
continue;
|
|
297
|
-
}
|
|
298
|
-
}
|
|
299
|
-
if (!selector.contain.length) {
|
|
300
|
-
delete selector.contain;
|
|
301
|
-
}
|
|
302
|
-
if (!selector['!contain'].length) {
|
|
303
|
-
delete selector['!contain'];
|
|
304
|
-
}
|
|
305
|
-
}
|
|
306
|
-
curQuery = curQuery.replace(containRegex, '');
|
|
307
|
-
const posixRegex = /(?: |^)(\w+)!?~(\/\/|\/.*?[^\\]\/)i?(?= |$)/g;
|
|
308
|
-
const posixMatch = curQuery.match(posixRegex);
|
|
309
|
-
if (posixMatch) {
|
|
310
|
-
selector.match = [];
|
|
311
|
-
selector['!match'] = [];
|
|
312
|
-
selector.imatch = [];
|
|
313
|
-
selector['!imatch'] = [];
|
|
314
|
-
for (let match of posixMatch) {
|
|
315
|
-
try {
|
|
316
|
-
let [name, value] = match.trim().split('~', 2);
|
|
317
|
-
if (name.endsWith('!')) {
|
|
318
|
-
if (value.endsWith('i')) {
|
|
319
|
-
selector['!imatch'].push([
|
|
320
|
-
name.slice(0, -1),
|
|
321
|
-
value.replace(/^\/|\/i$/g, ''),
|
|
322
|
-
]);
|
|
323
|
-
}
|
|
324
|
-
else {
|
|
325
|
-
selector['!match'].push([
|
|
326
|
-
name.slice(0, -1),
|
|
327
|
-
value.replace(/^\/|\/$/g, ''),
|
|
328
|
-
]);
|
|
329
|
-
}
|
|
330
|
-
}
|
|
331
|
-
else {
|
|
332
|
-
if (value.endsWith('i')) {
|
|
333
|
-
selector.imatch.push([name, value.replace(/^\/|\/i$/g, '')]);
|
|
334
|
-
}
|
|
335
|
-
else {
|
|
336
|
-
selector.match.push([name, value.replace(/^\/|\/$/g, '')]);
|
|
337
|
-
}
|
|
338
|
-
}
|
|
339
|
-
}
|
|
340
|
-
catch (e) {
|
|
341
|
-
continue;
|
|
342
|
-
}
|
|
343
|
-
}
|
|
344
|
-
if (!selector.match.length) {
|
|
345
|
-
delete selector.match;
|
|
346
|
-
}
|
|
347
|
-
if (!selector['!match'].length) {
|
|
348
|
-
delete selector['!match'];
|
|
349
|
-
}
|
|
350
|
-
if (!selector.imatch.length) {
|
|
351
|
-
delete selector.imatch;
|
|
352
|
-
}
|
|
353
|
-
if (!selector['!imatch'].length) {
|
|
354
|
-
delete selector['!imatch'];
|
|
355
|
-
}
|
|
356
|
-
}
|
|
357
|
-
curQuery = curQuery.replace(posixRegex, '');
|
|
358
|
-
const likeRegex = /(?: |^)(\w+)!?~(""i?|".*?[^\\]"i?|[^ ]+)(?= |$)/g;
|
|
359
|
-
const likeMatch = curQuery.match(likeRegex);
|
|
360
|
-
if (likeMatch) {
|
|
361
|
-
selector.like = [];
|
|
362
|
-
selector['!like'] = [];
|
|
363
|
-
selector.ilike = [];
|
|
364
|
-
selector['!ilike'] = [];
|
|
365
|
-
for (let match of likeMatch) {
|
|
366
|
-
try {
|
|
367
|
-
let [name, value] = match.trim().split('~', 2);
|
|
368
|
-
if (name.endsWith('!')) {
|
|
369
|
-
if (value.endsWith('"i')) {
|
|
370
|
-
selector['!ilike'].push([
|
|
371
|
-
name.slice(0, -1),
|
|
372
|
-
unQuoteString(value.slice(0, -1)),
|
|
373
|
-
]);
|
|
374
|
-
}
|
|
375
|
-
else {
|
|
376
|
-
selector['!like'].push([name.slice(0, -1), unQuoteString(value)]);
|
|
377
|
-
}
|
|
378
|
-
}
|
|
379
|
-
else {
|
|
380
|
-
if (value.endsWith('"i')) {
|
|
381
|
-
selector.ilike.push([name, unQuoteString(value.slice(0, -1))]);
|
|
382
|
-
}
|
|
383
|
-
else {
|
|
384
|
-
selector.like.push([name, unQuoteString(value)]);
|
|
385
|
-
}
|
|
386
|
-
}
|
|
387
|
-
}
|
|
388
|
-
catch (e) {
|
|
389
|
-
continue;
|
|
390
|
-
}
|
|
391
|
-
}
|
|
392
|
-
if (!selector.like.length) {
|
|
393
|
-
delete selector.like;
|
|
394
|
-
}
|
|
395
|
-
if (!selector['!like'].length) {
|
|
396
|
-
delete selector['!like'];
|
|
397
|
-
}
|
|
398
|
-
if (!selector.ilike.length) {
|
|
399
|
-
delete selector.ilike;
|
|
400
|
-
}
|
|
401
|
-
if (!selector['!ilike'].length) {
|
|
402
|
-
delete selector['!ilike'];
|
|
403
|
-
}
|
|
404
|
-
}
|
|
405
|
-
curQuery = curQuery.replace(likeRegex, '');
|
|
406
|
-
const guidRegex = /(?: |^)\{!?([0-9a-f]{24})\}(?= |$)/g;
|
|
407
|
-
const guidMatch = curQuery.match(guidRegex);
|
|
408
|
-
if (guidMatch) {
|
|
409
|
-
selector.guid = [];
|
|
410
|
-
selector['!guid'] = [];
|
|
411
|
-
for (let match of guidMatch) {
|
|
412
|
-
try {
|
|
413
|
-
let guid = match.trim().replace(/^\{|\}$/g, '');
|
|
414
|
-
if (guid.startsWith('!')) {
|
|
415
|
-
selector['!guid'].push(guid.slice(1));
|
|
416
|
-
}
|
|
417
|
-
else {
|
|
418
|
-
selector.guid.push(guid);
|
|
419
|
-
}
|
|
420
|
-
}
|
|
421
|
-
catch (e) {
|
|
422
|
-
continue;
|
|
423
|
-
}
|
|
424
|
-
}
|
|
425
|
-
if (!selector.guid.length) {
|
|
426
|
-
delete selector.guid;
|
|
427
|
-
}
|
|
428
|
-
if (!selector['!guid'].length) {
|
|
429
|
-
delete selector['!guid'];
|
|
430
|
-
}
|
|
431
|
-
}
|
|
432
|
-
curQuery = curQuery.replace(guidRegex, '');
|
|
433
|
-
const truthyRegex = /(?: |^)\[(!?\w+)\](?= |$)/g;
|
|
434
|
-
const truthyMatch = curQuery.match(truthyRegex);
|
|
435
|
-
if (truthyMatch) {
|
|
436
|
-
selector.truthy = [];
|
|
437
|
-
selector['!truthy'] = [];
|
|
438
|
-
for (let match of truthyMatch) {
|
|
439
|
-
try {
|
|
440
|
-
let name = match.trim().replace(/^\[|\]$/g, '');
|
|
441
|
-
if (name.startsWith('!')) {
|
|
442
|
-
selector['!truthy'].push(name.slice(1));
|
|
443
|
-
}
|
|
444
|
-
else {
|
|
445
|
-
selector.truthy.push(name);
|
|
446
|
-
}
|
|
447
|
-
}
|
|
448
|
-
catch (e) {
|
|
449
|
-
continue;
|
|
450
|
-
}
|
|
451
|
-
}
|
|
452
|
-
if (!selector.truthy.length) {
|
|
453
|
-
delete selector.truthy;
|
|
454
|
-
}
|
|
455
|
-
if (!selector['!truthy'].length) {
|
|
456
|
-
delete selector['!truthy'];
|
|
457
|
-
}
|
|
458
|
-
}
|
|
459
|
-
curQuery = curQuery.replace(truthyRegex, '');
|
|
460
|
-
const tagRegex = /(?: |^)<(!?\w+)>(?= |$)/g;
|
|
461
|
-
const tagMatch = curQuery.match(tagRegex);
|
|
462
|
-
if (tagMatch) {
|
|
463
|
-
selector.tag = [];
|
|
464
|
-
selector['!tag'] = [];
|
|
465
|
-
for (let match of tagMatch) {
|
|
466
|
-
try {
|
|
467
|
-
let name = match.trim().replace(/^<|>$/g, '');
|
|
468
|
-
if (name.startsWith('!')) {
|
|
469
|
-
selector['!tag'].push(name.slice(1));
|
|
470
|
-
}
|
|
471
|
-
else {
|
|
472
|
-
selector.tag.push(name);
|
|
473
|
-
}
|
|
474
|
-
}
|
|
475
|
-
catch (e) {
|
|
476
|
-
continue;
|
|
477
|
-
}
|
|
478
|
-
}
|
|
479
|
-
if (!selector.tag.length) {
|
|
480
|
-
delete selector.tag;
|
|
481
|
-
}
|
|
482
|
-
if (!selector['!tag'].length) {
|
|
483
|
-
delete selector['!tag'];
|
|
484
|
-
}
|
|
485
|
-
}
|
|
486
|
-
curQuery = curQuery.replace(tagRegex, '');
|
|
487
|
-
const gtRegex = /(?: |^)(\w+)>(-?\d+(?:\.\d+)?)(?= |$)/g;
|
|
488
|
-
const gtMatch = curQuery.match(gtRegex);
|
|
489
|
-
if (gtMatch) {
|
|
490
|
-
selector.gt = [];
|
|
491
|
-
for (let match of gtMatch) {
|
|
492
|
-
try {
|
|
493
|
-
let [name, value] = match.trim().split('>', 2);
|
|
494
|
-
selector.gt.push([name, Number(value)]);
|
|
495
|
-
}
|
|
496
|
-
catch (e) {
|
|
497
|
-
continue;
|
|
498
|
-
}
|
|
499
|
-
}
|
|
500
|
-
if (!selector.gt.length) {
|
|
501
|
-
delete selector.gt;
|
|
502
|
-
}
|
|
503
|
-
}
|
|
504
|
-
curQuery = curQuery.replace(gtRegex, '');
|
|
505
|
-
const gtRelativeRegex = /(?: |^)(\w+)>(\w+|"[^"]+")(?= |$)/g;
|
|
506
|
-
const gtRelativeMatch = curQuery.match(gtRelativeRegex);
|
|
507
|
-
if (gtRelativeMatch) {
|
|
508
|
-
if (selector.gt == null) {
|
|
509
|
-
selector.gt = [];
|
|
510
|
-
}
|
|
511
|
-
for (let match of gtRelativeMatch) {
|
|
512
|
-
try {
|
|
513
|
-
let [name, value] = match.trim().split('>', 2);
|
|
514
|
-
selector.gt.push([
|
|
515
|
-
name,
|
|
516
|
-
null,
|
|
517
|
-
value.replace(/"/g, ''),
|
|
518
|
-
]);
|
|
519
|
-
}
|
|
520
|
-
catch (e) {
|
|
521
|
-
continue;
|
|
522
|
-
}
|
|
523
|
-
}
|
|
524
|
-
if (!selector.gt.length) {
|
|
525
|
-
delete selector.gt;
|
|
526
|
-
}
|
|
527
|
-
}
|
|
528
|
-
curQuery = curQuery.replace(gtRelativeRegex, '');
|
|
529
|
-
const gteRegex = /(?: |^)(\w+)>=(-?\d+(?:\.\d+)?)(?= |$)/g;
|
|
530
|
-
const gteMatch = curQuery.match(gteRegex);
|
|
531
|
-
if (gteMatch) {
|
|
532
|
-
selector.gte = [];
|
|
533
|
-
for (let match of gteMatch) {
|
|
534
|
-
try {
|
|
535
|
-
let [name, value] = match.trim().split('>=', 2);
|
|
536
|
-
selector.gte.push([name, Number(value)]);
|
|
537
|
-
}
|
|
538
|
-
catch (e) {
|
|
539
|
-
continue;
|
|
540
|
-
}
|
|
541
|
-
}
|
|
542
|
-
if (!selector.gte.length) {
|
|
543
|
-
delete selector.gte;
|
|
544
|
-
}
|
|
545
|
-
}
|
|
546
|
-
curQuery = curQuery.replace(gteRegex, '');
|
|
547
|
-
const gteRelativeRegex = /(?: |^)(\w+)>=(\w+|"[^"]+")(?= |$)/g;
|
|
548
|
-
const gteRelativeMatch = curQuery.match(gteRelativeRegex);
|
|
549
|
-
if (gteRelativeMatch) {
|
|
550
|
-
if (selector.gte == null) {
|
|
551
|
-
selector.gte = [];
|
|
552
|
-
}
|
|
553
|
-
for (let match of gteRelativeMatch) {
|
|
554
|
-
try {
|
|
555
|
-
let [name, value] = match.trim().split('>=', 2);
|
|
556
|
-
selector.gte.push([
|
|
557
|
-
name,
|
|
558
|
-
null,
|
|
559
|
-
value.replace(/"/g, ''),
|
|
560
|
-
]);
|
|
561
|
-
}
|
|
562
|
-
catch (e) {
|
|
563
|
-
continue;
|
|
564
|
-
}
|
|
565
|
-
}
|
|
566
|
-
if (!selector.gte.length) {
|
|
567
|
-
delete selector.gte;
|
|
568
|
-
}
|
|
569
|
-
}
|
|
570
|
-
curQuery = curQuery.replace(gteRelativeRegex, '');
|
|
571
|
-
const ltRegex = /(?: |^)(\w+)<(-?\d+(?:\.\d+)?)(?= |$)/g;
|
|
572
|
-
const ltMatch = curQuery.match(ltRegex);
|
|
573
|
-
if (ltMatch) {
|
|
574
|
-
selector.lt = [];
|
|
575
|
-
for (let match of ltMatch) {
|
|
576
|
-
try {
|
|
577
|
-
let [name, value] = match.trim().split('<', 2);
|
|
578
|
-
selector.lt.push([name, Number(value)]);
|
|
579
|
-
}
|
|
580
|
-
catch (e) {
|
|
581
|
-
continue;
|
|
582
|
-
}
|
|
583
|
-
}
|
|
584
|
-
if (!selector.lt.length) {
|
|
585
|
-
delete selector.lt;
|
|
586
|
-
}
|
|
587
|
-
}
|
|
588
|
-
curQuery = curQuery.replace(ltRegex, '');
|
|
589
|
-
const ltRelativeRegex = /(?: |^)(\w+)<(\w+|"[^"]+")(?= |$)/g;
|
|
590
|
-
const ltRelativeMatch = curQuery.match(ltRelativeRegex);
|
|
591
|
-
if (ltRelativeMatch) {
|
|
592
|
-
if (selector.lt == null) {
|
|
593
|
-
selector.lt = [];
|
|
594
|
-
}
|
|
595
|
-
for (let match of ltRelativeMatch) {
|
|
596
|
-
try {
|
|
597
|
-
let [name, value] = match.trim().split('<', 2);
|
|
598
|
-
selector.lt.push([
|
|
599
|
-
name,
|
|
600
|
-
null,
|
|
601
|
-
value.replace(/"/g, ''),
|
|
602
|
-
]);
|
|
603
|
-
}
|
|
604
|
-
catch (e) {
|
|
605
|
-
continue;
|
|
606
|
-
}
|
|
607
|
-
}
|
|
608
|
-
if (!selector.lt.length) {
|
|
609
|
-
delete selector.lt;
|
|
610
|
-
}
|
|
611
|
-
}
|
|
612
|
-
curQuery = curQuery.replace(ltRelativeRegex, '');
|
|
613
|
-
const lteRegex = /(?: |^)(\w+)<=(-?\d+(?:\.\d+)?)(?= |$)/g;
|
|
614
|
-
const lteMatch = curQuery.match(lteRegex);
|
|
615
|
-
if (lteMatch) {
|
|
616
|
-
selector.lte = [];
|
|
617
|
-
for (let match of lteMatch) {
|
|
618
|
-
try {
|
|
619
|
-
let [name, value] = match.trim().split('<=', 2);
|
|
620
|
-
selector.lte.push([name, Number(value)]);
|
|
621
|
-
}
|
|
622
|
-
catch (e) {
|
|
623
|
-
continue;
|
|
624
|
-
}
|
|
625
|
-
}
|
|
626
|
-
if (!selector.lte.length) {
|
|
627
|
-
delete selector.lte;
|
|
628
|
-
}
|
|
629
|
-
}
|
|
630
|
-
curQuery = curQuery.replace(lteRegex, '');
|
|
631
|
-
const lteRelativeRegex = /(?: |^)(\w+)<=(\w+|"[^"]+")(?= |$)/g;
|
|
632
|
-
const lteRelativeMatch = curQuery.match(lteRelativeRegex);
|
|
633
|
-
if (lteRelativeMatch) {
|
|
634
|
-
if (selector.lte == null) {
|
|
635
|
-
selector.lte = [];
|
|
636
|
-
}
|
|
637
|
-
for (let match of lteRelativeMatch) {
|
|
638
|
-
try {
|
|
639
|
-
let [name, value] = match.trim().split('<=', 2);
|
|
640
|
-
selector.lte.push([
|
|
641
|
-
name,
|
|
642
|
-
null,
|
|
643
|
-
value.replace(/"/g, ''),
|
|
644
|
-
]);
|
|
645
|
-
}
|
|
646
|
-
catch (e) {
|
|
647
|
-
continue;
|
|
648
|
-
}
|
|
649
|
-
}
|
|
650
|
-
if (!selector.lte.length) {
|
|
651
|
-
delete selector.lte;
|
|
652
|
-
}
|
|
653
|
-
}
|
|
654
|
-
curQuery = curQuery.replace(lteRelativeRegex, '');
|
|
655
|
-
return curQuery.trim();
|
|
656
|
-
}
|
|
657
|
-
function unQuoteString(input) {
|
|
658
|
-
if (input.match(/^".*?[^\\]"$/)) {
|
|
659
|
-
return input.slice(1, -1).replace(/\\"/g, '"').replace(/\\\\/g, '\\');
|
|
660
|
-
}
|
|
661
|
-
return input;
|
|
662
|
-
}
|
|
663
|
-
function unQuoteAngles(input) {
|
|
664
|
-
return input.replace(/\\</g, '<').replace(/\\>/g, '>').replace(/\\\\/g, '\\');
|
|
665
|
-
}
|
|
666
|
-
function unQuoteCurlies(input) {
|
|
667
|
-
return input
|
|
668
|
-
.replace(/\\\{/g, '{')
|
|
669
|
-
.replace(/\\\}/g, '}')
|
|
670
|
-
.replace(/\\\\/g, '\\');
|
|
671
|
-
}
|
|
672
|
-
//# sourceMappingURL=queryParser.js.map
|