@wener/common 2.0.1 → 2.0.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.
Files changed (107) hide show
  1. package/lib/cn/ChineseResidentIdNo.js +41 -0
  2. package/lib/cn/ChineseResidentIdNo.mod.js +1 -0
  3. package/lib/cn/{ResidentIdentityCardNumber.test.js → ChineseResidentIdNo.test.js} +7 -6
  4. package/lib/cn/DivisionCode.js +211 -300
  5. package/lib/cn/DivisionCode.mod.js +1 -0
  6. package/lib/cn/DivisionCode.test.js +9 -15
  7. package/lib/cn/{Mod11Checksum.js → Mod11.js} +1 -0
  8. package/lib/cn/{Mod31Checksum.js → Mod31.js} +1 -0
  9. package/lib/cn/UnifiedSocialCreditCode.js +130 -115
  10. package/lib/cn/UnifiedSocialCreditCode.mod.js +1 -0
  11. package/lib/cn/UnifiedSocialCreditCode.test.js +1 -1
  12. package/lib/cn/index.js +1 -3
  13. package/lib/cn/mod.js +6 -0
  14. package/lib/consola/formatLogObject.js +18 -6
  15. package/lib/dayjs/dayjs.js +38 -0
  16. package/lib/dayjs/formatDuration.js +58 -0
  17. package/lib/dayjs/formatDuration.test.js +90 -0
  18. package/lib/dayjs/index.js +3 -0
  19. package/lib/dayjs/parseDuration.js +32 -0
  20. package/lib/decimal/index.js +1 -0
  21. package/lib/decimal/parseDecimal.js +13 -0
  22. package/lib/{resource → foundation}/schema/SexType.js +5 -1
  23. package/lib/foundation/schema/index.js +1 -0
  24. package/lib/foundation/schema/parseSexType.js +18 -0
  25. package/lib/foundation/schema/types.js +5 -0
  26. package/lib/password/Password.js +10 -7
  27. package/lib/resource/ListQuery.js +119 -0
  28. package/lib/resource/index.js +1 -0
  29. package/lib/resource/schema/AnyResourceSchema.js +1 -1
  30. package/lib/resource/schema/index.js +5 -0
  31. package/lib/{resource/schema → schema}/SchemaRegistry.js +12 -5
  32. package/lib/schema/SchemaRegistry.mod.js +2 -0
  33. package/lib/schema/createSchemaData.js +1 -1
  34. package/lib/schema/getSchemaOptions.js +2 -2
  35. package/lib/schema/index.js +1 -0
  36. package/lib/utils/getEstimateProcessTime.js +20 -0
  37. package/lib/utils/index.js +1 -0
  38. package/package.json +23 -14
  39. package/src/cn/ChineseResidentIdNo.mod.ts +7 -0
  40. package/src/cn/ChineseResidentIdNo.test.ts +18 -0
  41. package/src/cn/ChineseResidentIdNo.ts +66 -0
  42. package/src/cn/DivisionCode.mod.ts +7 -0
  43. package/src/cn/DivisionCode.test.ts +3 -13
  44. package/src/cn/DivisionCode.ts +132 -195
  45. package/src/cn/{Mod11Checksum.ts → Mod11.ts} +3 -1
  46. package/src/cn/{Mod31Checksum.ts → Mod31.ts} +2 -0
  47. package/src/cn/UnifiedSocialCreditCode.mod.ts +7 -0
  48. package/src/cn/UnifiedSocialCreditCode.test.ts +2 -2
  49. package/src/cn/UnifiedSocialCreditCode.ts +105 -125
  50. package/src/cn/__snapshots__/ChineseResidentIdNo.test.ts.snap +14 -0
  51. package/src/cn/__snapshots__/UnifiedSocialCreditCode.test.ts.snap +18 -12
  52. package/src/cn/index.ts +1 -3
  53. package/src/cn/mod.ts +3 -0
  54. package/src/consola/formatLogObject.ts +12 -4
  55. package/src/dayjs/dayjs.ts +40 -0
  56. package/src/dayjs/formatDuration.test.ts +14 -0
  57. package/src/dayjs/formatDuration.ts +86 -0
  58. package/src/dayjs/index.ts +3 -0
  59. package/src/dayjs/parseDuration.ts +40 -0
  60. package/src/decimal/index.ts +1 -0
  61. package/src/decimal/parseDecimal.ts +16 -0
  62. package/src/foundation/schema/SexType.ts +21 -0
  63. package/src/foundation/schema/index.ts +1 -0
  64. package/src/foundation/schema/parseSexType.ts +19 -0
  65. package/src/foundation/schema/types.ts +8 -0
  66. package/src/password/Password.ts +2 -2
  67. package/src/resource/ListQuery.ts +53 -0
  68. package/src/resource/index.ts +1 -0
  69. package/src/resource/schema/AnyResourceSchema.ts +1 -1
  70. package/src/resource/schema/index.ts +5 -0
  71. package/src/schema/SchemaRegistry.mod.ts +1 -0
  72. package/src/{resource/schema → schema}/SchemaRegistry.ts +12 -8
  73. package/src/schema/createSchemaData.ts +1 -1
  74. package/src/schema/getSchemaOptions.ts +2 -2
  75. package/src/schema/index.ts +1 -0
  76. package/src/utils/getEstimateProcessTime.ts +36 -0
  77. package/src/utils/index.ts +1 -0
  78. package/lib/cn/ResidentIdentityCardNumber.js +0 -50
  79. package/lib/cn/formatDate.js +0 -13
  80. package/lib/cn/parseSex.js +0 -20
  81. package/lib/search/AdvanceSearch.js +0 -9
  82. package/lib/search/AdvanceSearch.test.js +0 -435
  83. package/lib/search/formatAdvanceSearch.js +0 -78
  84. package/lib/search/index.js +0 -1
  85. package/lib/search/optimizeAdvanceSearch.js +0 -143
  86. package/lib/search/parseAdvanceSearch.js +0 -20
  87. package/lib/search/parser.d.js +0 -1
  88. package/lib/search/parser.js +0 -3088
  89. package/lib/search/types.d.js +0 -1
  90. package/src/cn/ResidentIdentityCardNumber.test.ts +0 -17
  91. package/src/cn/ResidentIdentityCardNumber.ts +0 -96
  92. package/src/cn/__snapshots__/ResidentIdentityCardNumber.test.ts.snap +0 -15
  93. package/src/cn/formatDate.ts +0 -12
  94. package/src/cn/parseSex.ts +0 -13
  95. package/src/resource/schema/SexType.ts +0 -13
  96. package/src/search/AdvanceSearch.test.ts +0 -149
  97. package/src/search/AdvanceSearch.ts +0 -14
  98. package/src/search/Makefile +0 -2
  99. package/src/search/__snapshots__/AdvanceSearch.test.ts.snap +0 -675
  100. package/src/search/formatAdvanceSearch.ts +0 -52
  101. package/src/search/index.ts +0 -1
  102. package/src/search/optimizeAdvanceSearch.ts +0 -77
  103. package/src/search/parseAdvanceSearch.ts +0 -23
  104. package/src/search/parser.d.ts +0 -8
  105. package/src/search/parser.js +0 -2794
  106. package/src/search/parser.peggy +0 -237
  107. package/src/search/types.d.ts +0 -45
@@ -1,675 +0,0 @@
1
- // Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
2
-
3
- exports[`AdvanceSearch > should parse 1`] = `"-a"`;
4
-
5
- exports[`AdvanceSearch > should parse 2`] = `"-a"`;
6
-
7
- exports[`AdvanceSearch > should parse 3`] = `
8
- [
9
- {
10
- "negative": true,
11
- "type": "keyword",
12
- "value": "a",
13
- },
14
- ]
15
- `;
16
-
17
- exports[`AdvanceSearch > should parse 4`] = `"a"`;
18
-
19
- exports[`AdvanceSearch > should parse 5`] = `"a"`;
20
-
21
- exports[`AdvanceSearch > should parse 6`] = `
22
- [
23
- {
24
- "type": "keyword",
25
- "value": "a",
26
- },
27
- ]
28
- `;
29
-
30
- exports[`AdvanceSearch > should parse 7`] = `"a b"`;
31
-
32
- exports[`AdvanceSearch > should parse 8`] = `"a b"`;
33
-
34
- exports[`AdvanceSearch > should parse 9`] = `
35
- [
36
- {
37
- "type": "keyword",
38
- "value": "a",
39
- },
40
- {
41
- "type": "keyword",
42
- "value": "b",
43
- },
44
- ]
45
- `;
46
-
47
- exports[`AdvanceSearch > should parse 10`] = `"a -b"`;
48
-
49
- exports[`AdvanceSearch > should parse 11`] = `"a -b"`;
50
-
51
- exports[`AdvanceSearch > should parse 12`] = `
52
- [
53
- {
54
- "negative": false,
55
- "type": "keyword",
56
- "value": "a",
57
- },
58
- {
59
- "negative": true,
60
- "type": "keyword",
61
- "value": "b",
62
- },
63
- ]
64
- `;
65
-
66
- exports[`AdvanceSearch > should parse 13`] = `"a-b"`;
67
-
68
- exports[`AdvanceSearch > should parse 14`] = `"a-b"`;
69
-
70
- exports[`AdvanceSearch > should parse 15`] = `
71
- [
72
- {
73
- "negative": false,
74
- "type": "keyword",
75
- "value": "a-b",
76
- },
77
- ]
78
- `;
79
-
80
- exports[`AdvanceSearch > should parse 16`] = `"a"b"`;
81
-
82
- exports[`AdvanceSearch > should parse 17`] = `"a"b"`;
83
-
84
- exports[`AdvanceSearch > should parse 18`] = `
85
- [
86
- {
87
- "negative": false,
88
- "type": "keyword",
89
- "value": "a"b",
90
- },
91
- ]
92
- `;
93
-
94
- exports[`AdvanceSearch > should parse 19`] = `"a&b"`;
95
-
96
- exports[`AdvanceSearch > should parse 20`] = `"a&b"`;
97
-
98
- exports[`AdvanceSearch > should parse 21`] = `
99
- [
100
- {
101
- "type": "keyword",
102
- "value": "a&b",
103
- },
104
- ]
105
- `;
106
-
107
- exports[`AdvanceSearch > should parse 22`] = `"NOT a"`;
108
-
109
- exports[`AdvanceSearch > should parse 23`] = `"-a"`;
110
-
111
- exports[`AdvanceSearch > should parse 24`] = `
112
- [
113
- {
114
- "type": "not",
115
- "value": {
116
- "negative": false,
117
- "type": "keyword",
118
- "value": "a",
119
- },
120
- },
121
- ]
122
- `;
123
-
124
- exports[`AdvanceSearch > should parse 25`] = `"NOT -a"`;
125
-
126
- exports[`AdvanceSearch > should parse 26`] = `"a"`;
127
-
128
- exports[`AdvanceSearch > should parse 27`] = `
129
- [
130
- {
131
- "type": "not",
132
- "value": {
133
- "negative": true,
134
- "type": "keyword",
135
- "value": "a",
136
- },
137
- },
138
- ]
139
- `;
140
-
141
- exports[`AdvanceSearch > should parse 28`] = `"HELLO -WORLD"`;
142
-
143
- exports[`AdvanceSearch > should parse 29`] = `"HELLO -WORLD"`;
144
-
145
- exports[`AdvanceSearch > should parse 30`] = `
146
- [
147
- {
148
- "negative": false,
149
- "type": "keyword",
150
- "value": "HELLO",
151
- },
152
- {
153
- "negative": true,
154
- "type": "keyword",
155
- "value": "WORLD",
156
- },
157
- ]
158
- `;
159
-
160
- exports[`AdvanceSearch > should parse 31`] = `"(a)"`;
161
-
162
- exports[`AdvanceSearch > should parse 32`] = `"a"`;
163
-
164
- exports[`AdvanceSearch > should parse 33`] = `
165
- [
166
- {
167
- "type": "parentheses",
168
- "value": [
169
- {
170
- "negative": false,
171
- "type": "keyword",
172
- "value": "a",
173
- },
174
- ],
175
- },
176
- ]
177
- `;
178
-
179
- exports[`AdvanceSearch > should parse 34`] = `"(a OR B)"`;
180
-
181
- exports[`AdvanceSearch > should parse 35`] = `"a OR B"`;
182
-
183
- exports[`AdvanceSearch > should parse 36`] = `
184
- [
185
- {
186
- "type": "parentheses",
187
- "value": [
188
- {
189
- "operator": "or",
190
- "type": "logical",
191
- "value": [
192
- {
193
- "negative": false,
194
- "type": "keyword",
195
- "value": "a",
196
- },
197
- {
198
- "negative": false,
199
- "type": "keyword",
200
- "value": "B",
201
- },
202
- ],
203
- },
204
- ],
205
- },
206
- ]
207
- `;
208
-
209
- exports[`AdvanceSearch > should parse 37`] = `"A OR B"`;
210
-
211
- exports[`AdvanceSearch > should parse 38`] = `"A OR B"`;
212
-
213
- exports[`AdvanceSearch > should parse 39`] = `
214
- [
215
- {
216
- "operator": "or",
217
- "type": "logical",
218
- "value": [
219
- {
220
- "negative": false,
221
- "type": "keyword",
222
- "value": "A",
223
- },
224
- {
225
- "negative": false,
226
- "type": "keyword",
227
- "value": "B",
228
- },
229
- ],
230
- },
231
- ]
232
- `;
233
-
234
- exports[`AdvanceSearch > should parse 40`] = `"a:[1,2]"`;
235
-
236
- exports[`AdvanceSearch > should parse 41`] = `"a:[1,2]"`;
237
-
238
- exports[`AdvanceSearch > should parse 42`] = `
239
- [
240
- {
241
- "field": "a",
242
- "operator": "range",
243
- "type": "compare",
244
- "value": {
245
- "maximum": {
246
- "type": "literal",
247
- "value": 2,
248
- },
249
- "maximumExclusive": false,
250
- "minimum": {
251
- "type": "literal",
252
- "value": 1,
253
- },
254
- "minimumExclusive": false,
255
- "type": "range",
256
- },
257
- },
258
- ]
259
- `;
260
-
261
- exports[`AdvanceSearch > should parse 43`] = `"a:*..1"`;
262
-
263
- exports[`AdvanceSearch > should parse 44`] = `"a:*..1"`;
264
-
265
- exports[`AdvanceSearch > should parse 45`] = `
266
- [
267
- {
268
- "field": "a",
269
- "operator": "range",
270
- "type": "compare",
271
- "value": {
272
- "maximum": {
273
- "type": "literal",
274
- "value": 1,
275
- },
276
- "minimum": undefined,
277
- "type": "range",
278
- },
279
- },
280
- ]
281
- `;
282
-
283
- exports[`AdvanceSearch > should parse 46`] = `"a:ok a:=1 a:>1 a:<1 a:>=1 a:<=1 a:!=1 a:1..2 a:*..1 a:1..* a:[1,2] a:(1,2) a:[1,2) a:(1,2]"`;
284
-
285
- exports[`AdvanceSearch > should parse 47`] = `"a:ok a:=1 a:>1 a:<1 a:>=1 a:<=1 a:!=1 a:1..2 a:*..1 a:1..* a:[1,2] a:(1,2) a:[1,2) a:(1,2]"`;
286
-
287
- exports[`AdvanceSearch > should parse 48`] = `
288
- [
289
- {
290
- "field": "a",
291
- "operator": "match",
292
- "type": "compare",
293
- "value": {
294
- "type": "literal",
295
- "value": "ok",
296
- },
297
- },
298
- {
299
- "field": "a",
300
- "operator": "eq",
301
- "type": "compare",
302
- "value": {
303
- "type": "literal",
304
- "value": 1,
305
- },
306
- },
307
- {
308
- "field": "a",
309
- "operator": "gt",
310
- "type": "compare",
311
- "value": {
312
- "type": "literal",
313
- "value": 1,
314
- },
315
- },
316
- {
317
- "field": "a",
318
- "operator": "lt",
319
- "type": "compare",
320
- "value": {
321
- "type": "literal",
322
- "value": 1,
323
- },
324
- },
325
- {
326
- "negative": false,
327
- "type": "keyword",
328
- "value": "a:>=1",
329
- },
330
- {
331
- "negative": false,
332
- "type": "keyword",
333
- "value": "a:<=1",
334
- },
335
- {
336
- "field": "a",
337
- "operator": "ne",
338
- "type": "compare",
339
- "value": {
340
- "type": "literal",
341
- "value": 1,
342
- },
343
- },
344
- {
345
- "field": "a",
346
- "operator": "range",
347
- "type": "compare",
348
- "value": {
349
- "maximum": {
350
- "type": "literal",
351
- "value": 2,
352
- },
353
- "minimum": {
354
- "type": "literal",
355
- "value": 1,
356
- },
357
- "type": "range",
358
- },
359
- },
360
- {
361
- "field": "a",
362
- "operator": "range",
363
- "type": "compare",
364
- "value": {
365
- "maximum": {
366
- "type": "literal",
367
- "value": 1,
368
- },
369
- "minimum": undefined,
370
- "type": "range",
371
- },
372
- },
373
- {
374
- "field": "a",
375
- "operator": "range",
376
- "type": "compare",
377
- "value": {
378
- "maximum": undefined,
379
- "minimum": {
380
- "type": "literal",
381
- "value": 1,
382
- },
383
- "type": "range",
384
- },
385
- },
386
- {
387
- "field": "a",
388
- "operator": "range",
389
- "type": "compare",
390
- "value": {
391
- "maximum": {
392
- "type": "literal",
393
- "value": 2,
394
- },
395
- "maximumExclusive": false,
396
- "minimum": {
397
- "type": "literal",
398
- "value": 1,
399
- },
400
- "minimumExclusive": false,
401
- "type": "range",
402
- },
403
- },
404
- {
405
- "field": "a",
406
- "operator": "range",
407
- "type": "compare",
408
- "value": {
409
- "maximum": {
410
- "type": "literal",
411
- "value": 2,
412
- },
413
- "maximumExclusive": true,
414
- "minimum": {
415
- "type": "literal",
416
- "value": 1,
417
- },
418
- "minimumExclusive": true,
419
- "type": "range",
420
- },
421
- },
422
- {
423
- "field": "a",
424
- "operator": "range",
425
- "type": "compare",
426
- "value": {
427
- "maximum": {
428
- "type": "literal",
429
- "value": 2,
430
- },
431
- "maximumExclusive": true,
432
- "minimum": {
433
- "type": "literal",
434
- "value": 1,
435
- },
436
- "minimumExclusive": false,
437
- "type": "range",
438
- },
439
- },
440
- {
441
- "field": "a",
442
- "operator": "range",
443
- "type": "compare",
444
- "value": {
445
- "maximum": {
446
- "type": "literal",
447
- "value": 2,
448
- },
449
- "maximumExclusive": false,
450
- "minimum": {
451
- "type": "literal",
452
- "value": 1,
453
- },
454
- "minimumExclusive": true,
455
- "type": "range",
456
- },
457
- },
458
- ]
459
- `;
460
-
461
- exports[`AdvanceSearch > should parse 49`] = `"NOT (A B) AND (a:ok AND size:>1)"`;
462
-
463
- exports[`AdvanceSearch > should parse 50`] = `"NOT (A B) AND (a:ok AND size:>1)"`;
464
-
465
- exports[`AdvanceSearch > should parse 51`] = `
466
- [
467
- {
468
- "operator": "and",
469
- "type": "logical",
470
- "value": [
471
- {
472
- "type": "not",
473
- "value": {
474
- "type": "parentheses",
475
- "value": [
476
- {
477
- "negative": false,
478
- "type": "keyword",
479
- "value": "A",
480
- },
481
- {
482
- "negative": false,
483
- "type": "keyword",
484
- "value": "B",
485
- },
486
- ],
487
- },
488
- },
489
- {
490
- "type": "parentheses",
491
- "value": [
492
- {
493
- "operator": "and",
494
- "type": "logical",
495
- "value": [
496
- {
497
- "field": "a",
498
- "operator": "match",
499
- "type": "compare",
500
- "value": {
501
- "type": "literal",
502
- "value": "ok",
503
- },
504
- },
505
- {
506
- "field": "size",
507
- "operator": "gt",
508
- "type": "compare",
509
- "value": {
510
- "type": "literal",
511
- "value": 1,
512
- },
513
- },
514
- ],
515
- },
516
- ],
517
- },
518
- ],
519
- },
520
- ]
521
- `;
522
-
523
- exports[`AdvanceSearch > should parse 52`] = `"NOT -a"`;
524
-
525
- exports[`AdvanceSearch > should parse 53`] = `"a"`;
526
-
527
- exports[`AdvanceSearch > should parse 54`] = `
528
- [
529
- {
530
- "type": "not",
531
- "value": {
532
- "negative": true,
533
- "type": "keyword",
534
- "value": "a",
535
- },
536
- },
537
- ]
538
- `;
539
-
540
- exports[`AdvanceSearch > should parse 55`] = `"NOT (NOT -a)"`;
541
-
542
- exports[`AdvanceSearch > should parse 56`] = `"-a"`;
543
-
544
- exports[`AdvanceSearch > should parse 57`] = `
545
- [
546
- {
547
- "type": "not",
548
- "value": {
549
- "type": "parentheses",
550
- "value": [
551
- {
552
- "type": "not",
553
- "value": {
554
- "negative": true,
555
- "type": "keyword",
556
- "value": "a",
557
- },
558
- },
559
- ],
560
- },
561
- },
562
- ]
563
- `;
564
-
565
- exports[`AdvanceSearch > should parse 58`] = `"owner:=@me owner:=@me owner:!=@me"`;
566
-
567
- exports[`AdvanceSearch > should parse 59`] = `"owner:=@me owner:=@me owner:!=@me"`;
568
-
569
- exports[`AdvanceSearch > should parse 60`] = `
570
- [
571
- {
572
- "field": "owner",
573
- "operator": "eq",
574
- "type": "compare",
575
- "value": {
576
- "format": "mention",
577
- "value": "me",
578
- },
579
- },
580
- {
581
- "field": "owner",
582
- "operator": "eq",
583
- "type": "compare",
584
- "value": {
585
- "format": "mention",
586
- "value": "me",
587
- },
588
- },
589
- {
590
- "field": "owner",
591
- "operator": "ne",
592
- "type": "compare",
593
- "value": {
594
- "format": "mention",
595
- "value": "me",
596
- },
597
- },
598
- ]
599
- `;
600
-
601
- exports[`AdvanceSearch > should parse 61`] = `"@AI:"Where is my car""`;
602
-
603
- exports[`AdvanceSearch > should parse 62`] = `"@AI:"Where is my car""`;
604
-
605
- exports[`AdvanceSearch > should parse 63`] = `
606
- [
607
- {
608
- "field": "AI",
609
- "mention": true,
610
- "operator": "match",
611
- "type": "compare",
612
- "value": {
613
- "value": "Where is my car",
614
- },
615
- },
616
- ]
617
- `;
618
-
619
- exports[`AdvanceSearch > should parse 64`] = `"/* */ a"`;
620
-
621
- exports[`AdvanceSearch > should parse 65`] = `"a"`;
622
-
623
- exports[`AdvanceSearch > should parse 66`] = `
624
- [
625
- {
626
- "type": "comment",
627
- "value": "",
628
- },
629
- {
630
- "negative": false,
631
- "type": "keyword",
632
- "value": "a",
633
- },
634
- ]
635
- `;
636
-
637
- exports[`AdvanceSearch > should parse 67`] = `"/* Hint */ a"`;
638
-
639
- exports[`AdvanceSearch > should parse 68`] = `"/* Hint */ a"`;
640
-
641
- exports[`AdvanceSearch > should parse 69`] = `
642
- [
643
- {
644
- "type": "comment",
645
- "value": "Hint",
646
- },
647
- {
648
- "negative": false,
649
- "type": "keyword",
650
- "value": "a",
651
- },
652
- ]
653
- `;
654
-
655
- exports[`AdvanceSearch > should parse 70`] = `"/* a */ a /* b */"`;
656
-
657
- exports[`AdvanceSearch > should parse 71`] = `"/* a */ a /* b */"`;
658
-
659
- exports[`AdvanceSearch > should parse 72`] = `
660
- [
661
- {
662
- "type": "comment",
663
- "value": "a",
664
- },
665
- {
666
- "negative": false,
667
- "type": "keyword",
668
- "value": "a",
669
- },
670
- {
671
- "type": "comment",
672
- "value": "b",
673
- },
674
- ]
675
- `;
@@ -1,52 +0,0 @@
1
- import { match } from 'ts-pattern';
2
- import { AdvanceSearch } from './AdvanceSearch';
3
-
4
- export function formatAdvanceSearch(input: AdvanceSearch.Expr[]) {
5
- const OP = { match: ':', eq: ':=', ne: ':!=', gt: ':>', lt: ':<', gte: ':>=', lte: ':<=', range: ':' } as const;
6
-
7
- const _exprs = (s: AdvanceSearch.Expr[]): string => {
8
- return s.map(_expr).join(' ');
9
- };
10
- const _expr = (s: AdvanceSearch.Expr): string => {
11
- return match(s)
12
- .with({ type: 'keyword' }, ({ value, exact, negative }) => {
13
- return `${negative ? '-' : ''}${exact ? `"${value}"` : value}`;
14
- })
15
- .with({ type: 'logical' }, ({ operator, value }) => value.map(_expr).join(` ${operator.toLocaleUpperCase()} `))
16
- .with({ type: 'not' }, ({ value }) => `NOT ${_expr(value)}`)
17
- .with({ type: 'compare' }, ({ field, operator, value, negative, mention }) => {
18
- return `${negative ? '-' : ''}${mention ? '@' : ''}${field}${OP[operator]}${_value(value)}`;
19
- })
20
- .with({ type: 'comment' }, ({ value }) => `/* ${value} */`)
21
- .with({ type: 'parentheses' }, ({ value }) => `(${_exprs(value)})`)
22
- .exhaustive();
23
- };
24
-
25
- const _literal = (s: string | null | number) => {
26
- if (typeof s === 'string') {
27
- return s.includes(' ') ? `"${s}"` : s;
28
- }
29
- return JSON.stringify(s);
30
- };
31
- const _value = (v: AdvanceSearch.Value): string => {
32
- return match(v)
33
- .with({ type: 'range' }, ({ minimum, maximum, minimumExclusive, maximumExclusive }) => {
34
- if (minimumExclusive === undefined && maximumExclusive === undefined) {
35
- let min = minimum === undefined ? '*' : _value(minimum);
36
- let max = maximum === undefined ? '*' : _value(maximum);
37
- return `${min}..${max}`;
38
- }
39
- let min = minimum === undefined ? '' : _value(minimum);
40
- let max = maximum === undefined ? '' : _value(maximum);
41
- return `${minimumExclusive ? '(' : '['}${min},${max}${maximumExclusive ? ')' : ']'}`;
42
- })
43
- .with({ format: 'mention' }, ({ value }) => {
44
- return `@${value}`;
45
- })
46
- .otherwise((value) => {
47
- return _literal(value.value);
48
- });
49
- };
50
-
51
- return _exprs(input);
52
- }
@@ -1 +0,0 @@
1
- export { AdvanceSearch } from './AdvanceSearch';