@nymphjs/query-parser 1.0.0-beta.98 → 1.0.0-beta.99

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