gscdump 1.0.2 → 1.0.3

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.
@@ -1,1978 +1,6 @@
1
- import { format } from "date-fns/format";
2
- import { subDays } from "date-fns/subDays";
3
- const PST_FORMATTER = new Intl.DateTimeFormat("en-CA", {
4
- timeZone: "America/Los_Angeles",
5
- year: "numeric",
6
- month: "2-digit",
7
- day: "2-digit"
8
- });
9
- function pstDateParts(d = /* @__PURE__ */ new Date()) {
10
- const parts = PST_FORMATTER.formatToParts(d);
11
- const get = (t) => Number(parts.find((p) => p.type === t).value);
12
- return {
13
- year: get("year"),
14
- month: get("month"),
15
- day: get("day")
16
- };
17
- }
18
- function currentPstDate() {
19
- const { year, month, day } = pstDateParts();
20
- return `${year}-${String(month).padStart(2, "0")}-${String(day).padStart(2, "0")}`;
21
- }
22
- function daysAgoPst(n) {
23
- const { year, month, day } = pstDateParts();
24
- return format(subDays(new Date(year, month - 1, day, 12), n), "yyyy-MM-dd");
25
- }
26
- const MS_PER_DAY = 864e5;
27
- function toIsoDate(d) {
28
- return d.toISOString().slice(0, 10);
29
- }
30
- function addDays(dateStr, n) {
31
- return toIsoDate(new Date(Date.parse(`${dateStr}T00:00:00Z`) + n * MS_PER_DAY));
32
- }
33
- function ok(value) {
34
- return {
35
- ok: true,
36
- value
37
- };
38
- }
39
- function err(error) {
40
- return {
41
- ok: false,
42
- error
43
- };
44
- }
45
- function unwrapResult(result, toError) {
46
- if (result.ok) return result.value;
47
- throw toError(result.error);
48
- }
49
- var countries_default = [
50
- {
51
- "name": "Afghanistan",
52
- "alpha-2": "AF",
53
- "alpha-3": "AFG",
54
- "country-code": "004"
55
- },
56
- {
57
- "name": "Åland Islands",
58
- "alpha-2": "AX",
59
- "alpha-3": "ALA",
60
- "country-code": "248"
61
- },
62
- {
63
- "name": "Albania",
64
- "alpha-2": "AL",
65
- "alpha-3": "ALB",
66
- "country-code": "008"
67
- },
68
- {
69
- "name": "Algeria",
70
- "alpha-2": "DZ",
71
- "alpha-3": "DZA",
72
- "country-code": "012"
73
- },
74
- {
75
- "name": "American Samoa",
76
- "alpha-2": "AS",
77
- "alpha-3": "ASM",
78
- "country-code": "016"
79
- },
80
- {
81
- "name": "Andorra",
82
- "alpha-2": "AD",
83
- "alpha-3": "AND",
84
- "country-code": "020"
85
- },
86
- {
87
- "name": "Angola",
88
- "alpha-2": "AO",
89
- "alpha-3": "AGO",
90
- "country-code": "024"
91
- },
92
- {
93
- "name": "Anguilla",
94
- "alpha-2": "AI",
95
- "alpha-3": "AIA",
96
- "country-code": "660"
97
- },
98
- {
99
- "name": "Antarctica",
100
- "alpha-2": "AQ",
101
- "alpha-3": "ATA",
102
- "country-code": "010"
103
- },
104
- {
105
- "name": "Antigua and Barbuda",
106
- "alpha-2": "AG",
107
- "alpha-3": "ATG",
108
- "country-code": "028"
109
- },
110
- {
111
- "name": "Argentina",
112
- "alpha-2": "AR",
113
- "alpha-3": "ARG",
114
- "country-code": "032"
115
- },
116
- {
117
- "name": "Armenia",
118
- "alpha-2": "AM",
119
- "alpha-3": "ARM",
120
- "country-code": "051"
121
- },
122
- {
123
- "name": "Aruba",
124
- "alpha-2": "AW",
125
- "alpha-3": "ABW",
126
- "country-code": "533"
127
- },
128
- {
129
- "name": "Australia",
130
- "alpha-2": "AU",
131
- "alpha-3": "AUS",
132
- "country-code": "036"
133
- },
134
- {
135
- "name": "Austria",
136
- "alpha-2": "AT",
137
- "alpha-3": "AUT",
138
- "country-code": "040"
139
- },
140
- {
141
- "name": "Azerbaijan",
142
- "alpha-2": "AZ",
143
- "alpha-3": "AZE",
144
- "country-code": "031"
145
- },
146
- {
147
- "name": "Bahamas",
148
- "alpha-2": "BS",
149
- "alpha-3": "BHS",
150
- "country-code": "044"
151
- },
152
- {
153
- "name": "Bahrain",
154
- "alpha-2": "BH",
155
- "alpha-3": "BHR",
156
- "country-code": "048"
157
- },
158
- {
159
- "name": "Bangladesh",
160
- "alpha-2": "BD",
161
- "alpha-3": "BGD",
162
- "country-code": "050"
163
- },
164
- {
165
- "name": "Barbados",
166
- "alpha-2": "BB",
167
- "alpha-3": "BRB",
168
- "country-code": "052"
169
- },
170
- {
171
- "name": "Belarus",
172
- "alpha-2": "BY",
173
- "alpha-3": "BLR",
174
- "country-code": "112"
175
- },
176
- {
177
- "name": "Belgium",
178
- "alpha-2": "BE",
179
- "alpha-3": "BEL",
180
- "country-code": "056"
181
- },
182
- {
183
- "name": "Belize",
184
- "alpha-2": "BZ",
185
- "alpha-3": "BLZ",
186
- "country-code": "084"
187
- },
188
- {
189
- "name": "Benin",
190
- "alpha-2": "BJ",
191
- "alpha-3": "BEN",
192
- "country-code": "204"
193
- },
194
- {
195
- "name": "Bermuda",
196
- "alpha-2": "BM",
197
- "alpha-3": "BMU",
198
- "country-code": "060"
199
- },
200
- {
201
- "name": "Bhutan",
202
- "alpha-2": "BT",
203
- "alpha-3": "BTN",
204
- "country-code": "064"
205
- },
206
- {
207
- "name": "Bolivia (Plurinational State of)",
208
- "alpha-2": "BO",
209
- "alpha-3": "BOL",
210
- "country-code": "068"
211
- },
212
- {
213
- "name": "Bonaire, Sint Eustatius and Saba",
214
- "alpha-2": "BQ",
215
- "alpha-3": "BES",
216
- "country-code": "535"
217
- },
218
- {
219
- "name": "Bosnia and Herzegovina",
220
- "alpha-2": "BA",
221
- "alpha-3": "BIH",
222
- "country-code": "070"
223
- },
224
- {
225
- "name": "Botswana",
226
- "alpha-2": "BW",
227
- "alpha-3": "BWA",
228
- "country-code": "072"
229
- },
230
- {
231
- "name": "Bouvet Island",
232
- "alpha-2": "BV",
233
- "alpha-3": "BVT",
234
- "country-code": "074"
235
- },
236
- {
237
- "name": "Brazil",
238
- "alpha-2": "BR",
239
- "alpha-3": "BRA",
240
- "country-code": "076"
241
- },
242
- {
243
- "name": "British Indian Ocean Territory",
244
- "alpha-2": "IO",
245
- "alpha-3": "IOT",
246
- "country-code": "086"
247
- },
248
- {
249
- "name": "Brunei Darussalam",
250
- "alpha-2": "BN",
251
- "alpha-3": "BRN",
252
- "country-code": "096"
253
- },
254
- {
255
- "name": "Bulgaria",
256
- "alpha-2": "BG",
257
- "alpha-3": "BGR",
258
- "country-code": "100"
259
- },
260
- {
261
- "name": "Burkina Faso",
262
- "alpha-2": "BF",
263
- "alpha-3": "BFA",
264
- "country-code": "854"
265
- },
266
- {
267
- "name": "Burundi",
268
- "alpha-2": "BI",
269
- "alpha-3": "BDI",
270
- "country-code": "108"
271
- },
272
- {
273
- "name": "Cabo Verde",
274
- "alpha-2": "CV",
275
- "alpha-3": "CPV",
276
- "country-code": "132"
277
- },
278
- {
279
- "name": "Cambodia",
280
- "alpha-2": "KH",
281
- "alpha-3": "KHM",
282
- "country-code": "116"
283
- },
284
- {
285
- "name": "Cameroon",
286
- "alpha-2": "CM",
287
- "alpha-3": "CMR",
288
- "country-code": "120"
289
- },
290
- {
291
- "name": "Canada",
292
- "alpha-2": "CA",
293
- "alpha-3": "CAN",
294
- "country-code": "124"
295
- },
296
- {
297
- "name": "Cayman Islands",
298
- "alpha-2": "KY",
299
- "alpha-3": "CYM",
300
- "country-code": "136"
301
- },
302
- {
303
- "name": "Central African Republic",
304
- "alpha-2": "CF",
305
- "alpha-3": "CAF",
306
- "country-code": "140"
307
- },
308
- {
309
- "name": "Chad",
310
- "alpha-2": "TD",
311
- "alpha-3": "TCD",
312
- "country-code": "148"
313
- },
314
- {
315
- "name": "Chile",
316
- "alpha-2": "CL",
317
- "alpha-3": "CHL",
318
- "country-code": "152"
319
- },
320
- {
321
- "name": "China",
322
- "alpha-2": "CN",
323
- "alpha-3": "CHN",
324
- "country-code": "156"
325
- },
326
- {
327
- "name": "Christmas Island",
328
- "alpha-2": "CX",
329
- "alpha-3": "CXR",
330
- "country-code": "162"
331
- },
332
- {
333
- "name": "Cocos (Keeling) Islands",
334
- "alpha-2": "CC",
335
- "alpha-3": "CCK",
336
- "country-code": "166"
337
- },
338
- {
339
- "name": "Colombia",
340
- "alpha-2": "CO",
341
- "alpha-3": "COL",
342
- "country-code": "170"
343
- },
344
- {
345
- "name": "Comoros",
346
- "alpha-2": "KM",
347
- "alpha-3": "COM",
348
- "country-code": "174"
349
- },
350
- {
351
- "name": "Congo",
352
- "alpha-2": "CG",
353
- "alpha-3": "COG",
354
- "country-code": "178"
355
- },
356
- {
357
- "name": "Congo, Democratic Republic of the",
358
- "alpha-2": "CD",
359
- "alpha-3": "COD",
360
- "country-code": "180"
361
- },
362
- {
363
- "name": "Cook Islands",
364
- "alpha-2": "CK",
365
- "alpha-3": "COK",
366
- "country-code": "184"
367
- },
368
- {
369
- "name": "Costa Rica",
370
- "alpha-2": "CR",
371
- "alpha-3": "CRI",
372
- "country-code": "188"
373
- },
374
- {
375
- "name": "Côte d'Ivoire",
376
- "alpha-2": "CI",
377
- "alpha-3": "CIV",
378
- "country-code": "384"
379
- },
380
- {
381
- "name": "Croatia",
382
- "alpha-2": "HR",
383
- "alpha-3": "HRV",
384
- "country-code": "191"
385
- },
386
- {
387
- "name": "Cuba",
388
- "alpha-2": "CU",
389
- "alpha-3": "CUB",
390
- "country-code": "192"
391
- },
392
- {
393
- "name": "Curaçao",
394
- "alpha-2": "CW",
395
- "alpha-3": "CUW",
396
- "country-code": "531"
397
- },
398
- {
399
- "name": "Cyprus",
400
- "alpha-2": "CY",
401
- "alpha-3": "CYP",
402
- "country-code": "196"
403
- },
404
- {
405
- "name": "Czechia",
406
- "alpha-2": "CZ",
407
- "alpha-3": "CZE",
408
- "country-code": "203"
409
- },
410
- {
411
- "name": "Denmark",
412
- "alpha-2": "DK",
413
- "alpha-3": "DNK",
414
- "country-code": "208"
415
- },
416
- {
417
- "name": "Djibouti",
418
- "alpha-2": "DJ",
419
- "alpha-3": "DJI",
420
- "country-code": "262"
421
- },
422
- {
423
- "name": "Dominica",
424
- "alpha-2": "DM",
425
- "alpha-3": "DMA",
426
- "country-code": "212"
427
- },
428
- {
429
- "name": "Dominican Republic",
430
- "alpha-2": "DO",
431
- "alpha-3": "DOM",
432
- "country-code": "214"
433
- },
434
- {
435
- "name": "Ecuador",
436
- "alpha-2": "EC",
437
- "alpha-3": "ECU",
438
- "country-code": "218"
439
- },
440
- {
441
- "name": "Egypt",
442
- "alpha-2": "EG",
443
- "alpha-3": "EGY",
444
- "country-code": "818"
445
- },
446
- {
447
- "name": "El Salvador",
448
- "alpha-2": "SV",
449
- "alpha-3": "SLV",
450
- "country-code": "222"
451
- },
452
- {
453
- "name": "Equatorial Guinea",
454
- "alpha-2": "GQ",
455
- "alpha-3": "GNQ",
456
- "country-code": "226"
457
- },
458
- {
459
- "name": "Eritrea",
460
- "alpha-2": "ER",
461
- "alpha-3": "ERI",
462
- "country-code": "232"
463
- },
464
- {
465
- "name": "Estonia",
466
- "alpha-2": "EE",
467
- "alpha-3": "EST",
468
- "country-code": "233"
469
- },
470
- {
471
- "name": "Eswatini",
472
- "alpha-2": "SZ",
473
- "alpha-3": "SWZ",
474
- "country-code": "748"
475
- },
476
- {
477
- "name": "Ethiopia",
478
- "alpha-2": "ET",
479
- "alpha-3": "ETH",
480
- "country-code": "231"
481
- },
482
- {
483
- "name": "Falkland Islands (Malvinas)",
484
- "alpha-2": "FK",
485
- "alpha-3": "FLK",
486
- "country-code": "238"
487
- },
488
- {
489
- "name": "Faroe Islands",
490
- "alpha-2": "FO",
491
- "alpha-3": "FRO",
492
- "country-code": "234"
493
- },
494
- {
495
- "name": "Fiji",
496
- "alpha-2": "FJ",
497
- "alpha-3": "FJI",
498
- "country-code": "242"
499
- },
500
- {
501
- "name": "Finland",
502
- "alpha-2": "FI",
503
- "alpha-3": "FIN",
504
- "country-code": "246"
505
- },
506
- {
507
- "name": "France",
508
- "alpha-2": "FR",
509
- "alpha-3": "FRA",
510
- "country-code": "250"
511
- },
512
- {
513
- "name": "French Guiana",
514
- "alpha-2": "GF",
515
- "alpha-3": "GUF",
516
- "country-code": "254"
517
- },
518
- {
519
- "name": "French Polynesia",
520
- "alpha-2": "PF",
521
- "alpha-3": "PYF",
522
- "country-code": "258"
523
- },
524
- {
525
- "name": "French Southern Territories",
526
- "alpha-2": "TF",
527
- "alpha-3": "ATF",
528
- "country-code": "260"
529
- },
530
- {
531
- "name": "Gabon",
532
- "alpha-2": "GA",
533
- "alpha-3": "GAB",
534
- "country-code": "266"
535
- },
536
- {
537
- "name": "Gambia",
538
- "alpha-2": "GM",
539
- "alpha-3": "GMB",
540
- "country-code": "270"
541
- },
542
- {
543
- "name": "Georgia",
544
- "alpha-2": "GE",
545
- "alpha-3": "GEO",
546
- "country-code": "268"
547
- },
548
- {
549
- "name": "Germany",
550
- "alpha-2": "DE",
551
- "alpha-3": "DEU",
552
- "country-code": "276"
553
- },
554
- {
555
- "name": "Ghana",
556
- "alpha-2": "GH",
557
- "alpha-3": "GHA",
558
- "country-code": "288"
559
- },
560
- {
561
- "name": "Gibraltar",
562
- "alpha-2": "GI",
563
- "alpha-3": "GIB",
564
- "country-code": "292"
565
- },
566
- {
567
- "name": "Greece",
568
- "alpha-2": "GR",
569
- "alpha-3": "GRC",
570
- "country-code": "300"
571
- },
572
- {
573
- "name": "Greenland",
574
- "alpha-2": "GL",
575
- "alpha-3": "GRL",
576
- "country-code": "304"
577
- },
578
- {
579
- "name": "Grenada",
580
- "alpha-2": "GD",
581
- "alpha-3": "GRD",
582
- "country-code": "308"
583
- },
584
- {
585
- "name": "Guadeloupe",
586
- "alpha-2": "GP",
587
- "alpha-3": "GLP",
588
- "country-code": "312"
589
- },
590
- {
591
- "name": "Guam",
592
- "alpha-2": "GU",
593
- "alpha-3": "GUM",
594
- "country-code": "316"
595
- },
596
- {
597
- "name": "Guatemala",
598
- "alpha-2": "GT",
599
- "alpha-3": "GTM",
600
- "country-code": "320"
601
- },
602
- {
603
- "name": "Guernsey",
604
- "alpha-2": "GG",
605
- "alpha-3": "GGY",
606
- "country-code": "831"
607
- },
608
- {
609
- "name": "Guinea",
610
- "alpha-2": "GN",
611
- "alpha-3": "GIN",
612
- "country-code": "324"
613
- },
614
- {
615
- "name": "Guinea-Bissau",
616
- "alpha-2": "GW",
617
- "alpha-3": "GNB",
618
- "country-code": "624"
619
- },
620
- {
621
- "name": "Guyana",
622
- "alpha-2": "GY",
623
- "alpha-3": "GUY",
624
- "country-code": "328"
625
- },
626
- {
627
- "name": "Haiti",
628
- "alpha-2": "HT",
629
- "alpha-3": "HTI",
630
- "country-code": "332"
631
- },
632
- {
633
- "name": "Heard Island and McDonald Islands",
634
- "alpha-2": "HM",
635
- "alpha-3": "HMD",
636
- "country-code": "334"
637
- },
638
- {
639
- "name": "Holy See",
640
- "alpha-2": "VA",
641
- "alpha-3": "VAT",
642
- "country-code": "336"
643
- },
644
- {
645
- "name": "Honduras",
646
- "alpha-2": "HN",
647
- "alpha-3": "HND",
648
- "country-code": "340"
649
- },
650
- {
651
- "name": "Hong Kong",
652
- "alpha-2": "HK",
653
- "alpha-3": "HKG",
654
- "country-code": "344"
655
- },
656
- {
657
- "name": "Hungary",
658
- "alpha-2": "HU",
659
- "alpha-3": "HUN",
660
- "country-code": "348"
661
- },
662
- {
663
- "name": "Iceland",
664
- "alpha-2": "IS",
665
- "alpha-3": "ISL",
666
- "country-code": "352"
667
- },
668
- {
669
- "name": "India",
670
- "alpha-2": "IN",
671
- "alpha-3": "IND",
672
- "country-code": "356"
673
- },
674
- {
675
- "name": "Indonesia",
676
- "alpha-2": "ID",
677
- "alpha-3": "IDN",
678
- "country-code": "360"
679
- },
680
- {
681
- "name": "Iran (Islamic Republic of)",
682
- "alpha-2": "IR",
683
- "alpha-3": "IRN",
684
- "country-code": "364"
685
- },
686
- {
687
- "name": "Iraq",
688
- "alpha-2": "IQ",
689
- "alpha-3": "IRQ",
690
- "country-code": "368"
691
- },
692
- {
693
- "name": "Ireland",
694
- "alpha-2": "IE",
695
- "alpha-3": "IRL",
696
- "country-code": "372"
697
- },
698
- {
699
- "name": "Isle of Man",
700
- "alpha-2": "IM",
701
- "alpha-3": "IMN",
702
- "country-code": "833"
703
- },
704
- {
705
- "name": "Israel",
706
- "alpha-2": "IL",
707
- "alpha-3": "ISR",
708
- "country-code": "376"
709
- },
710
- {
711
- "name": "Italy",
712
- "alpha-2": "IT",
713
- "alpha-3": "ITA",
714
- "country-code": "380"
715
- },
716
- {
717
- "name": "Jamaica",
718
- "alpha-2": "JM",
719
- "alpha-3": "JAM",
720
- "country-code": "388"
721
- },
722
- {
723
- "name": "Japan",
724
- "alpha-2": "JP",
725
- "alpha-3": "JPN",
726
- "country-code": "392"
727
- },
728
- {
729
- "name": "Jersey",
730
- "alpha-2": "JE",
731
- "alpha-3": "JEY",
732
- "country-code": "832"
733
- },
734
- {
735
- "name": "Jordan",
736
- "alpha-2": "JO",
737
- "alpha-3": "JOR",
738
- "country-code": "400"
739
- },
740
- {
741
- "name": "Kazakhstan",
742
- "alpha-2": "KZ",
743
- "alpha-3": "KAZ",
744
- "country-code": "398"
745
- },
746
- {
747
- "name": "Kenya",
748
- "alpha-2": "KE",
749
- "alpha-3": "KEN",
750
- "country-code": "404"
751
- },
752
- {
753
- "name": "Kiribati",
754
- "alpha-2": "KI",
755
- "alpha-3": "KIR",
756
- "country-code": "296"
757
- },
758
- {
759
- "name": "Korea (Democratic People's Republic of)",
760
- "alpha-2": "KP",
761
- "alpha-3": "PRK",
762
- "country-code": "408"
763
- },
764
- {
765
- "name": "Korea, Republic of",
766
- "alpha-2": "KR",
767
- "alpha-3": "KOR",
768
- "country-code": "410"
769
- },
770
- {
771
- "name": "Kuwait",
772
- "alpha-2": "KW",
773
- "alpha-3": "KWT",
774
- "country-code": "414"
775
- },
776
- {
777
- "name": "Kyrgyzstan",
778
- "alpha-2": "KG",
779
- "alpha-3": "KGZ",
780
- "country-code": "417"
781
- },
782
- {
783
- "name": "Lao People's Democratic Republic",
784
- "alpha-2": "LA",
785
- "alpha-3": "LAO",
786
- "country-code": "418"
787
- },
788
- {
789
- "name": "Latvia",
790
- "alpha-2": "LV",
791
- "alpha-3": "LVA",
792
- "country-code": "428"
793
- },
794
- {
795
- "name": "Lebanon",
796
- "alpha-2": "LB",
797
- "alpha-3": "LBN",
798
- "country-code": "422"
799
- },
800
- {
801
- "name": "Lesotho",
802
- "alpha-2": "LS",
803
- "alpha-3": "LSO",
804
- "country-code": "426"
805
- },
806
- {
807
- "name": "Liberia",
808
- "alpha-2": "LR",
809
- "alpha-3": "LBR",
810
- "country-code": "430"
811
- },
812
- {
813
- "name": "Libya",
814
- "alpha-2": "LY",
815
- "alpha-3": "LBY",
816
- "country-code": "434"
817
- },
818
- {
819
- "name": "Liechtenstein",
820
- "alpha-2": "LI",
821
- "alpha-3": "LIE",
822
- "country-code": "438"
823
- },
824
- {
825
- "name": "Lithuania",
826
- "alpha-2": "LT",
827
- "alpha-3": "LTU",
828
- "country-code": "440"
829
- },
830
- {
831
- "name": "Luxembourg",
832
- "alpha-2": "LU",
833
- "alpha-3": "LUX",
834
- "country-code": "442"
835
- },
836
- {
837
- "name": "Macao",
838
- "alpha-2": "MO",
839
- "alpha-3": "MAC",
840
- "country-code": "446"
841
- },
842
- {
843
- "name": "Madagascar",
844
- "alpha-2": "MG",
845
- "alpha-3": "MDG",
846
- "country-code": "450"
847
- },
848
- {
849
- "name": "Malawi",
850
- "alpha-2": "MW",
851
- "alpha-3": "MWI",
852
- "country-code": "454"
853
- },
854
- {
855
- "name": "Malaysia",
856
- "alpha-2": "MY",
857
- "alpha-3": "MYS",
858
- "country-code": "458"
859
- },
860
- {
861
- "name": "Maldives",
862
- "alpha-2": "MV",
863
- "alpha-3": "MDV",
864
- "country-code": "462"
865
- },
866
- {
867
- "name": "Mali",
868
- "alpha-2": "ML",
869
- "alpha-3": "MLI",
870
- "country-code": "466"
871
- },
872
- {
873
- "name": "Malta",
874
- "alpha-2": "MT",
875
- "alpha-3": "MLT",
876
- "country-code": "470"
877
- },
878
- {
879
- "name": "Marshall Islands",
880
- "alpha-2": "MH",
881
- "alpha-3": "MHL",
882
- "country-code": "584"
883
- },
884
- {
885
- "name": "Martinique",
886
- "alpha-2": "MQ",
887
- "alpha-3": "MTQ",
888
- "country-code": "474"
889
- },
890
- {
891
- "name": "Mauritania",
892
- "alpha-2": "MR",
893
- "alpha-3": "MRT",
894
- "country-code": "478"
895
- },
896
- {
897
- "name": "Mauritius",
898
- "alpha-2": "MU",
899
- "alpha-3": "MUS",
900
- "country-code": "480"
901
- },
902
- {
903
- "name": "Mayotte",
904
- "alpha-2": "YT",
905
- "alpha-3": "MYT",
906
- "country-code": "175"
907
- },
908
- {
909
- "name": "Mexico",
910
- "alpha-2": "MX",
911
- "alpha-3": "MEX",
912
- "country-code": "484"
913
- },
914
- {
915
- "name": "Micronesia (Federated States of)",
916
- "alpha-2": "FM",
917
- "alpha-3": "FSM",
918
- "country-code": "583"
919
- },
920
- {
921
- "name": "Moldova, Republic of",
922
- "alpha-2": "MD",
923
- "alpha-3": "MDA",
924
- "country-code": "498"
925
- },
926
- {
927
- "name": "Monaco",
928
- "alpha-2": "MC",
929
- "alpha-3": "MCO",
930
- "country-code": "492"
931
- },
932
- {
933
- "name": "Mongolia",
934
- "alpha-2": "MN",
935
- "alpha-3": "MNG",
936
- "country-code": "496"
937
- },
938
- {
939
- "name": "Montenegro",
940
- "alpha-2": "ME",
941
- "alpha-3": "MNE",
942
- "country-code": "499"
943
- },
944
- {
945
- "name": "Montserrat",
946
- "alpha-2": "MS",
947
- "alpha-3": "MSR",
948
- "country-code": "500"
949
- },
950
- {
951
- "name": "Morocco",
952
- "alpha-2": "MA",
953
- "alpha-3": "MAR",
954
- "country-code": "504"
955
- },
956
- {
957
- "name": "Mozambique",
958
- "alpha-2": "MZ",
959
- "alpha-3": "MOZ",
960
- "country-code": "508"
961
- },
962
- {
963
- "name": "Myanmar",
964
- "alpha-2": "MM",
965
- "alpha-3": "MMR",
966
- "country-code": "104"
967
- },
968
- {
969
- "name": "Namibia",
970
- "alpha-2": "NA",
971
- "alpha-3": "NAM",
972
- "country-code": "516"
973
- },
974
- {
975
- "name": "Nauru",
976
- "alpha-2": "NR",
977
- "alpha-3": "NRU",
978
- "country-code": "520"
979
- },
980
- {
981
- "name": "Nepal",
982
- "alpha-2": "NP",
983
- "alpha-3": "NPL",
984
- "country-code": "524"
985
- },
986
- {
987
- "name": "Netherlands",
988
- "alpha-2": "NL",
989
- "alpha-3": "NLD",
990
- "country-code": "528"
991
- },
992
- {
993
- "name": "New Caledonia",
994
- "alpha-2": "NC",
995
- "alpha-3": "NCL",
996
- "country-code": "540"
997
- },
998
- {
999
- "name": "New Zealand",
1000
- "alpha-2": "NZ",
1001
- "alpha-3": "NZL",
1002
- "country-code": "554"
1003
- },
1004
- {
1005
- "name": "Nicaragua",
1006
- "alpha-2": "NI",
1007
- "alpha-3": "NIC",
1008
- "country-code": "558"
1009
- },
1010
- {
1011
- "name": "Niger",
1012
- "alpha-2": "NE",
1013
- "alpha-3": "NER",
1014
- "country-code": "562"
1015
- },
1016
- {
1017
- "name": "Nigeria",
1018
- "alpha-2": "NG",
1019
- "alpha-3": "NGA",
1020
- "country-code": "566"
1021
- },
1022
- {
1023
- "name": "Niue",
1024
- "alpha-2": "NU",
1025
- "alpha-3": "NIU",
1026
- "country-code": "570"
1027
- },
1028
- {
1029
- "name": "Norfolk Island",
1030
- "alpha-2": "NF",
1031
- "alpha-3": "NFK",
1032
- "country-code": "574"
1033
- },
1034
- {
1035
- "name": "North Macedonia",
1036
- "alpha-2": "MK",
1037
- "alpha-3": "MKD",
1038
- "country-code": "807"
1039
- },
1040
- {
1041
- "name": "Northern Mariana Islands",
1042
- "alpha-2": "MP",
1043
- "alpha-3": "MNP",
1044
- "country-code": "580"
1045
- },
1046
- {
1047
- "name": "Norway",
1048
- "alpha-2": "NO",
1049
- "alpha-3": "NOR",
1050
- "country-code": "578"
1051
- },
1052
- {
1053
- "name": "Oman",
1054
- "alpha-2": "OM",
1055
- "alpha-3": "OMN",
1056
- "country-code": "512"
1057
- },
1058
- {
1059
- "name": "Pakistan",
1060
- "alpha-2": "PK",
1061
- "alpha-3": "PAK",
1062
- "country-code": "586"
1063
- },
1064
- {
1065
- "name": "Palau",
1066
- "alpha-2": "PW",
1067
- "alpha-3": "PLW",
1068
- "country-code": "585"
1069
- },
1070
- {
1071
- "name": "Palestine, State of",
1072
- "alpha-2": "PS",
1073
- "alpha-3": "PSE",
1074
- "country-code": "275"
1075
- },
1076
- {
1077
- "name": "Panama",
1078
- "alpha-2": "PA",
1079
- "alpha-3": "PAN",
1080
- "country-code": "591"
1081
- },
1082
- {
1083
- "name": "Papua New Guinea",
1084
- "alpha-2": "PG",
1085
- "alpha-3": "PNG",
1086
- "country-code": "598"
1087
- },
1088
- {
1089
- "name": "Paraguay",
1090
- "alpha-2": "PY",
1091
- "alpha-3": "PRY",
1092
- "country-code": "600"
1093
- },
1094
- {
1095
- "name": "Peru",
1096
- "alpha-2": "PE",
1097
- "alpha-3": "PER",
1098
- "country-code": "604"
1099
- },
1100
- {
1101
- "name": "Philippines",
1102
- "alpha-2": "PH",
1103
- "alpha-3": "PHL",
1104
- "country-code": "608"
1105
- },
1106
- {
1107
- "name": "Pitcairn",
1108
- "alpha-2": "PN",
1109
- "alpha-3": "PCN",
1110
- "country-code": "612"
1111
- },
1112
- {
1113
- "name": "Poland",
1114
- "alpha-2": "PL",
1115
- "alpha-3": "POL",
1116
- "country-code": "616"
1117
- },
1118
- {
1119
- "name": "Portugal",
1120
- "alpha-2": "PT",
1121
- "alpha-3": "PRT",
1122
- "country-code": "620"
1123
- },
1124
- {
1125
- "name": "Puerto Rico",
1126
- "alpha-2": "PR",
1127
- "alpha-3": "PRI",
1128
- "country-code": "630"
1129
- },
1130
- {
1131
- "name": "Qatar",
1132
- "alpha-2": "QA",
1133
- "alpha-3": "QAT",
1134
- "country-code": "634"
1135
- },
1136
- {
1137
- "name": "Réunion",
1138
- "alpha-2": "RE",
1139
- "alpha-3": "REU",
1140
- "country-code": "638"
1141
- },
1142
- {
1143
- "name": "Romania",
1144
- "alpha-2": "RO",
1145
- "alpha-3": "ROU",
1146
- "country-code": "642"
1147
- },
1148
- {
1149
- "name": "Russian Federation",
1150
- "alpha-2": "RU",
1151
- "alpha-3": "RUS",
1152
- "country-code": "643"
1153
- },
1154
- {
1155
- "name": "Rwanda",
1156
- "alpha-2": "RW",
1157
- "alpha-3": "RWA",
1158
- "country-code": "646"
1159
- },
1160
- {
1161
- "name": "Saint Barthélemy",
1162
- "alpha-2": "BL",
1163
- "alpha-3": "BLM",
1164
- "country-code": "652"
1165
- },
1166
- {
1167
- "name": "Saint Helena, Ascension and Tristan da Cunha",
1168
- "alpha-2": "SH",
1169
- "alpha-3": "SHN",
1170
- "country-code": "654"
1171
- },
1172
- {
1173
- "name": "Saint Kitts and Nevis",
1174
- "alpha-2": "KN",
1175
- "alpha-3": "KNA",
1176
- "country-code": "659"
1177
- },
1178
- {
1179
- "name": "Saint Lucia",
1180
- "alpha-2": "LC",
1181
- "alpha-3": "LCA",
1182
- "country-code": "662"
1183
- },
1184
- {
1185
- "name": "Saint Martin (French part)",
1186
- "alpha-2": "MF",
1187
- "alpha-3": "MAF",
1188
- "country-code": "663"
1189
- },
1190
- {
1191
- "name": "Saint Pierre and Miquelon",
1192
- "alpha-2": "PM",
1193
- "alpha-3": "SPM",
1194
- "country-code": "666"
1195
- },
1196
- {
1197
- "name": "Saint Vincent and the Grenadines",
1198
- "alpha-2": "VC",
1199
- "alpha-3": "VCT",
1200
- "country-code": "670"
1201
- },
1202
- {
1203
- "name": "Samoa",
1204
- "alpha-2": "WS",
1205
- "alpha-3": "WSM",
1206
- "country-code": "882"
1207
- },
1208
- {
1209
- "name": "San Marino",
1210
- "alpha-2": "SM",
1211
- "alpha-3": "SMR",
1212
- "country-code": "674"
1213
- },
1214
- {
1215
- "name": "Sao Tome and Principe",
1216
- "alpha-2": "ST",
1217
- "alpha-3": "STP",
1218
- "country-code": "678"
1219
- },
1220
- {
1221
- "name": "Saudi Arabia",
1222
- "alpha-2": "SA",
1223
- "alpha-3": "SAU",
1224
- "country-code": "682"
1225
- },
1226
- {
1227
- "name": "Senegal",
1228
- "alpha-2": "SN",
1229
- "alpha-3": "SEN",
1230
- "country-code": "686"
1231
- },
1232
- {
1233
- "name": "Serbia",
1234
- "alpha-2": "RS",
1235
- "alpha-3": "SRB",
1236
- "country-code": "688"
1237
- },
1238
- {
1239
- "name": "Seychelles",
1240
- "alpha-2": "SC",
1241
- "alpha-3": "SYC",
1242
- "country-code": "690"
1243
- },
1244
- {
1245
- "name": "Sierra Leone",
1246
- "alpha-2": "SL",
1247
- "alpha-3": "SLE",
1248
- "country-code": "694"
1249
- },
1250
- {
1251
- "name": "Singapore",
1252
- "alpha-2": "SG",
1253
- "alpha-3": "SGP",
1254
- "country-code": "702"
1255
- },
1256
- {
1257
- "name": "Sint Maarten (Dutch part)",
1258
- "alpha-2": "SX",
1259
- "alpha-3": "SXM",
1260
- "country-code": "534"
1261
- },
1262
- {
1263
- "name": "Slovakia",
1264
- "alpha-2": "SK",
1265
- "alpha-3": "SVK",
1266
- "country-code": "703"
1267
- },
1268
- {
1269
- "name": "Slovenia",
1270
- "alpha-2": "SI",
1271
- "alpha-3": "SVN",
1272
- "country-code": "705"
1273
- },
1274
- {
1275
- "name": "Solomon Islands",
1276
- "alpha-2": "SB",
1277
- "alpha-3": "SLB",
1278
- "country-code": "090"
1279
- },
1280
- {
1281
- "name": "Somalia",
1282
- "alpha-2": "SO",
1283
- "alpha-3": "SOM",
1284
- "country-code": "706"
1285
- },
1286
- {
1287
- "name": "South Africa",
1288
- "alpha-2": "ZA",
1289
- "alpha-3": "ZAF",
1290
- "country-code": "710"
1291
- },
1292
- {
1293
- "name": "South Georgia and the South Sandwich Islands",
1294
- "alpha-2": "GS",
1295
- "alpha-3": "SGS",
1296
- "country-code": "239"
1297
- },
1298
- {
1299
- "name": "South Sudan",
1300
- "alpha-2": "SS",
1301
- "alpha-3": "SSD",
1302
- "country-code": "728"
1303
- },
1304
- {
1305
- "name": "Spain",
1306
- "alpha-2": "ES",
1307
- "alpha-3": "ESP",
1308
- "country-code": "724"
1309
- },
1310
- {
1311
- "name": "Sri Lanka",
1312
- "alpha-2": "LK",
1313
- "alpha-3": "LKA",
1314
- "country-code": "144"
1315
- },
1316
- {
1317
- "name": "Sudan",
1318
- "alpha-2": "SD",
1319
- "alpha-3": "SDN",
1320
- "country-code": "729"
1321
- },
1322
- {
1323
- "name": "Suriname",
1324
- "alpha-2": "SR",
1325
- "alpha-3": "SUR",
1326
- "country-code": "740"
1327
- },
1328
- {
1329
- "name": "Svalbard and Jan Mayen",
1330
- "alpha-2": "SJ",
1331
- "alpha-3": "SJM",
1332
- "country-code": "744"
1333
- },
1334
- {
1335
- "name": "Sweden",
1336
- "alpha-2": "SE",
1337
- "alpha-3": "SWE",
1338
- "country-code": "752"
1339
- },
1340
- {
1341
- "name": "Switzerland",
1342
- "alpha-2": "CH",
1343
- "alpha-3": "CHE",
1344
- "country-code": "756"
1345
- },
1346
- {
1347
- "name": "Syrian Arab Republic",
1348
- "alpha-2": "SY",
1349
- "alpha-3": "SYR",
1350
- "country-code": "760"
1351
- },
1352
- {
1353
- "name": "Taiwan",
1354
- "alpha-2": "TW",
1355
- "alpha-3": "TWN",
1356
- "country-code": "158"
1357
- },
1358
- {
1359
- "name": "Tajikistan",
1360
- "alpha-2": "TJ",
1361
- "alpha-3": "TJK",
1362
- "country-code": "762"
1363
- },
1364
- {
1365
- "name": "Tanzania, United Republic of",
1366
- "alpha-2": "TZ",
1367
- "alpha-3": "TZA",
1368
- "country-code": "834"
1369
- },
1370
- {
1371
- "name": "Thailand",
1372
- "alpha-2": "TH",
1373
- "alpha-3": "THA",
1374
- "country-code": "764"
1375
- },
1376
- {
1377
- "name": "Timor-Leste",
1378
- "alpha-2": "TL",
1379
- "alpha-3": "TLS",
1380
- "country-code": "626"
1381
- },
1382
- {
1383
- "name": "Togo",
1384
- "alpha-2": "TG",
1385
- "alpha-3": "TGO",
1386
- "country-code": "768"
1387
- },
1388
- {
1389
- "name": "Tokelau",
1390
- "alpha-2": "TK",
1391
- "alpha-3": "TKL",
1392
- "country-code": "772"
1393
- },
1394
- {
1395
- "name": "Tonga",
1396
- "alpha-2": "TO",
1397
- "alpha-3": "TON",
1398
- "country-code": "776"
1399
- },
1400
- {
1401
- "name": "Trinidad and Tobago",
1402
- "alpha-2": "TT",
1403
- "alpha-3": "TTO",
1404
- "country-code": "780"
1405
- },
1406
- {
1407
- "name": "Tunisia",
1408
- "alpha-2": "TN",
1409
- "alpha-3": "TUN",
1410
- "country-code": "788"
1411
- },
1412
- {
1413
- "name": "Turkey",
1414
- "alpha-2": "TR",
1415
- "alpha-3": "TUR",
1416
- "country-code": "792"
1417
- },
1418
- {
1419
- "name": "Turkmenistan",
1420
- "alpha-2": "TM",
1421
- "alpha-3": "TKM",
1422
- "country-code": "795"
1423
- },
1424
- {
1425
- "name": "Turks and Caicos Islands",
1426
- "alpha-2": "TC",
1427
- "alpha-3": "TCA",
1428
- "country-code": "796"
1429
- },
1430
- {
1431
- "name": "Tuvalu",
1432
- "alpha-2": "TV",
1433
- "alpha-3": "TUV",
1434
- "country-code": "798"
1435
- },
1436
- {
1437
- "name": "Uganda",
1438
- "alpha-2": "UG",
1439
- "alpha-3": "UGA",
1440
- "country-code": "800"
1441
- },
1442
- {
1443
- "name": "Ukraine",
1444
- "alpha-2": "UA",
1445
- "alpha-3": "UKR",
1446
- "country-code": "804"
1447
- },
1448
- {
1449
- "name": "United Arab Emirates",
1450
- "alpha-2": "AE",
1451
- "alpha-3": "ARE",
1452
- "country-code": "784"
1453
- },
1454
- {
1455
- "name": "United Kingdom",
1456
- "alpha-2": "GB",
1457
- "alpha-3": "GBR",
1458
- "country-code": "826"
1459
- },
1460
- {
1461
- "name": "America",
1462
- "alpha-2": "US",
1463
- "alpha-3": "USA",
1464
- "country-code": "840"
1465
- },
1466
- {
1467
- "name": "United States Minor Outlying Islands",
1468
- "alpha-2": "UM",
1469
- "alpha-3": "UMI",
1470
- "country-code": "581"
1471
- },
1472
- {
1473
- "name": "Uruguay",
1474
- "alpha-2": "UY",
1475
- "alpha-3": "URY",
1476
- "country-code": "858"
1477
- },
1478
- {
1479
- "name": "Uzbekistan",
1480
- "alpha-2": "UZ",
1481
- "alpha-3": "UZB",
1482
- "country-code": "860"
1483
- },
1484
- {
1485
- "name": "Vanuatu",
1486
- "alpha-2": "VU",
1487
- "alpha-3": "VUT",
1488
- "country-code": "548"
1489
- },
1490
- {
1491
- "name": "Venezuela (Bolivarian Republic of)",
1492
- "alpha-2": "VE",
1493
- "alpha-3": "VEN",
1494
- "country-code": "862"
1495
- },
1496
- {
1497
- "name": "Vietnam",
1498
- "alpha-2": "VN",
1499
- "alpha-3": "VNM",
1500
- "country-code": "704"
1501
- },
1502
- {
1503
- "name": "Virgin Islands (British)",
1504
- "alpha-2": "VG",
1505
- "alpha-3": "VGB",
1506
- "country-code": "092"
1507
- },
1508
- {
1509
- "name": "Virgin Islands (U.S.)",
1510
- "alpha-2": "VI",
1511
- "alpha-3": "VIR",
1512
- "country-code": "850"
1513
- },
1514
- {
1515
- "name": "Wallis and Futuna",
1516
- "alpha-2": "WF",
1517
- "alpha-3": "WLF",
1518
- "country-code": "876"
1519
- },
1520
- {
1521
- "name": "Western Sahara",
1522
- "alpha-2": "EH",
1523
- "alpha-3": "ESH",
1524
- "country-code": "732"
1525
- },
1526
- {
1527
- "name": "Yemen",
1528
- "alpha-2": "YE",
1529
- "alpha-3": "YEM",
1530
- "country-code": "887"
1531
- },
1532
- {
1533
- "name": "Zambia",
1534
- "alpha-2": "ZM",
1535
- "alpha-3": "ZMB",
1536
- "country-code": "894"
1537
- },
1538
- {
1539
- "name": "Zimbabwe",
1540
- "alpha-2": "ZW",
1541
- "alpha-3": "ZWE",
1542
- "country-code": "716"
1543
- }
1544
- ];
1545
- const Devices = {
1546
- MOBILE: "MOBILE",
1547
- DESKTOP: "DESKTOP",
1548
- TABLET: "TABLET"
1549
- };
1550
- const SearchTypes = {
1551
- WEB: "web",
1552
- IMAGE: "image",
1553
- VIDEO: "video",
1554
- NEWS: "news",
1555
- DISCOVER: "discover",
1556
- GOOGLE_NEWS: "googleNews"
1557
- };
1558
- const Countries = Object.fromEntries(countries_default.map((c) => [c["alpha-3"], c["alpha-3"].toLowerCase()]));
1559
- const TIME_AXIS_DIMENSIONS$1 = /* @__PURE__ */ new Set(["date", "hour"]);
1560
- const queryErrors = {
1561
- missingDateRange() {
1562
- return {
1563
- kind: "missing-date-range",
1564
- message: "Date range required: use .where(between(date, start, end)) or .where(and(gte(date, start), lte(date, end)))"
1565
- };
1566
- },
1567
- invalidRowLimit(value) {
1568
- return {
1569
- kind: "invalid-row-limit",
1570
- value,
1571
- message: `rowLimit must be a positive integer, got ${value}`
1572
- };
1573
- },
1574
- invalidStartRow(value) {
1575
- return {
1576
- kind: "invalid-start-row",
1577
- value,
1578
- message: `startRow must be a non-negative integer, got ${value}`
1579
- };
1580
- },
1581
- hourDimensionRequiresHourlyState() {
1582
- return {
1583
- kind: "invalid-data-state",
1584
- message: "hour dimension requires dataState: \"hourly_all\""
1585
- };
1586
- },
1587
- hourlyStateRequiresHourDimension() {
1588
- return {
1589
- kind: "invalid-data-state",
1590
- message: "dataState: \"hourly_all\" requires grouping by hour dimension"
1591
- };
1592
- },
1593
- byPropertyUnsupportedSearchType() {
1594
- return {
1595
- kind: "invalid-aggregation-type",
1596
- message: "aggregationType: \"byProperty\" is not supported for type \"discover\" or \"googleNews\""
1597
- };
1598
- },
1599
- byPropertyNotAllowedWithPage() {
1600
- return {
1601
- kind: "invalid-aggregation-type",
1602
- message: "aggregationType: \"byProperty\" is not allowed when grouping or filtering by page"
1603
- };
1604
- },
1605
- byNewsShowcaseRequiresSearchType() {
1606
- return {
1607
- kind: "invalid-aggregation-type",
1608
- message: "aggregationType: \"byNewsShowcasePanel\" requires type \"discover\" or \"googleNews\""
1609
- };
1610
- },
1611
- byNewsShowcaseNotAllowedWithPage() {
1612
- return {
1613
- kind: "invalid-aggregation-type",
1614
- message: "aggregationType: \"byNewsShowcasePanel\" is not allowed when grouping or filtering by page"
1615
- };
1616
- },
1617
- byNewsShowcaseRequiresShowcaseFilter() {
1618
- return {
1619
- kind: "invalid-aggregation-type",
1620
- message: "aggregationType: \"byNewsShowcasePanel\" requires a searchAppearance equals \"NEWS_SHOWCASE\" filter and no other searchAppearance filter"
1621
- };
1622
- },
1623
- invalidBuilderState(cause) {
1624
- return {
1625
- kind: "invalid-builder-state",
1626
- cause,
1627
- message: "Invalid state"
1628
- };
1629
- },
1630
- malformedFilterLeaf() {
1631
- return {
1632
- kind: "invalid-filter",
1633
- message: "Malformed filter: each filter leaf requires a string `dimension` and `operator`"
1634
- };
1635
- },
1636
- unsupportedCapability(capability, context) {
1637
- return {
1638
- kind: "unsupported-capability",
1639
- capability,
1640
- context,
1641
- message: `${context} requires ${capability} capability`
1642
- };
1643
- },
1644
- unresolvableDataset(dimensions, filterDims = []) {
1645
- const grouped = dimensions.filter((d) => !TIME_AXIS_DIMENSIONS$1.has(d));
1646
- const filtered = filterDims.filter((d) => !TIME_AXIS_DIMENSIONS$1.has(d));
1647
- return {
1648
- kind: "unresolvable-dataset",
1649
- dimensions,
1650
- filterDims,
1651
- message: `Cannot resolve a [${grouped.join(", ")}] breakdown filtered by [${filtered.join(", ")}] from stored data: these dimensions live in separate per-dimension tables. Only the live GSC API computes cross-dimension aggregates.`
1652
- };
1653
- }
1654
- };
1655
- const QUERY_ERROR_KINDS = /* @__PURE__ */ new Set([
1656
- "missing-date-range",
1657
- "invalid-row-limit",
1658
- "invalid-start-row",
1659
- "invalid-data-state",
1660
- "invalid-aggregation-type",
1661
- "invalid-builder-state",
1662
- "invalid-filter",
1663
- "unsupported-capability",
1664
- "unresolvable-dataset"
1665
- ]);
1666
- function isQueryError(value) {
1667
- return typeof value === "object" && value !== null && QUERY_ERROR_KINDS.has(value.kind) && typeof value.message === "string";
1668
- }
1669
- var UnsupportedLogicalCapabilityError = class extends Error {
1670
- queryError;
1671
- constructor(capability, context) {
1672
- const error = queryErrors.unsupportedCapability(capability, context);
1673
- super(error.message);
1674
- this.name = "UnsupportedLogicalCapabilityError";
1675
- this.queryError = error;
1676
- }
1677
- };
1678
- var UnresolvableDatasetError = class extends Error {
1679
- queryError;
1680
- constructor(dimensions, filterDims = []) {
1681
- const error = queryErrors.unresolvableDataset(dimensions, filterDims);
1682
- super(error.message);
1683
- this.name = "UnresolvableDatasetError";
1684
- this.queryError = error;
1685
- }
1686
- };
1687
- function queryErrorToException(error) {
1688
- switch (error.kind) {
1689
- case "unsupported-capability": return new UnsupportedLogicalCapabilityError(error.capability, error.context);
1690
- case "unresolvable-dataset": return new UnresolvableDatasetError(error.dimensions, error.filterDims);
1691
- default: {
1692
- const exception = new Error(error.message);
1693
- if ("cause" in error && error.cause !== void 0) exception.cause = error.cause;
1694
- exception.queryError = error;
1695
- return exception;
1696
- }
1697
- }
1698
- }
1699
- const DATE_OPERATORS = [
1700
- "gte",
1701
- "gt",
1702
- "lte",
1703
- "lt",
1704
- "between"
1705
- ];
1706
- const METRIC_OPERATORS = [
1707
- "metricGte",
1708
- "metricGt",
1709
- "metricLte",
1710
- "metricLt",
1711
- "metricBetween"
1712
- ];
1713
- const SPECIAL_OPERATORS = ["topLevel"];
1714
- const QUERY_PARAMS = ["searchType"];
1715
- const FILTER_METRICS = [
1716
- "clicks",
1717
- "impressions",
1718
- "ctr",
1719
- "position"
1720
- ];
1721
- function isDateOperator(op) {
1722
- return DATE_OPERATORS.includes(op);
1723
- }
1724
- function isMetricOperator(op) {
1725
- return METRIC_OPERATORS.includes(op);
1726
- }
1727
- function isSpecialOperator(op) {
1728
- return SPECIAL_OPERATORS.includes(op);
1729
- }
1730
- function isQueryParam(value) {
1731
- return QUERY_PARAMS.includes(value);
1732
- }
1733
- function isMetric(value) {
1734
- return FILTER_METRICS.includes(value);
1735
- }
1736
- function isRegexOperator(op) {
1737
- return op === "includingRegex" || op === "excludingRegex";
1738
- }
1739
- const KNOWN_SEARCH_TYPES = new Set(Object.values(SearchTypes));
1740
- function isWireGroupType(type) {
1741
- return type === "and" || type === "or";
1742
- }
1743
- function convertWireLeaf(alt) {
1744
- if (!alt.column || !alt.type || isWireGroupType(alt.type)) return null;
1745
- const f = {
1746
- dimension: alt.column,
1747
- operator: alt.type,
1748
- expression: alt.type === "between" ? alt.from ?? "" : alt.value ?? ""
1749
- };
1750
- if (alt.type === "between" && alt.to) f.expression2 = alt.to;
1751
- return f;
1752
- }
1753
- function convertWireGroup(alt) {
1754
- if (!isWireGroupType(alt.type)) {
1755
- const leaf = convertWireLeaf(alt);
1756
- return leaf ? { _filters: [leaf] } : null;
1757
- }
1758
- const leaves = [];
1759
- const nested = [];
1760
- for (const child of alt.filters ?? []) if (isWireGroupType(child.type)) {
1761
- const sub = convertWireGroup(child);
1762
- if (sub) nested.push(sub);
1763
- } else {
1764
- const leaf = convertWireLeaf(child);
1765
- if (leaf) leaves.push(leaf);
1766
- }
1767
- if (leaves.length === 0 && nested.length === 0) return null;
1768
- return {
1769
- _filters: leaves,
1770
- _nestedGroups: nested.length > 0 ? nested : void 0,
1771
- _groupType: alt.type
1772
- };
1773
- }
1774
- function isWireFilter(input) {
1775
- if (!input || typeof input !== "object") return false;
1776
- const o = input;
1777
- if ("_filters" in o) return false;
1778
- return "type" in o && typeof o.type === "string" || "filters" in o && Array.isArray(o.filters);
1779
- }
1780
- function normalizeFilter(input) {
1781
- if (!input) return void 0;
1782
- if (isWireFilter(input)) return convertWireGroup(input) ?? void 0;
1783
- if (typeof input === "object" && Array.isArray(input._filters)) return input;
1784
- }
1785
- function normalizeOrderBy(orderBy) {
1786
- const spec = Array.isArray(orderBy) ? orderBy[0] : orderBy;
1787
- if (!spec || typeof spec !== "object") return void 0;
1788
- const o = spec;
1789
- if (typeof o.column !== "string" || o.column.length === 0) return void 0;
1790
- const dir = typeof o.dir === "string" ? o.dir.toLowerCase() === "asc" ? "asc" : "desc" : o.desc === false ? "asc" : "desc";
1791
- return {
1792
- column: o.column,
1793
- dir
1794
- };
1795
- }
1796
- function hasMalformedFilterLeaf(filter) {
1797
- if (!filter || typeof filter !== "object") return false;
1798
- if (Array.isArray(filter._filters)) {
1799
- for (const leaf of filter._filters) if (!leaf || typeof leaf !== "object" || typeof leaf.operator !== "string" || typeof leaf.dimension !== "string") return true;
1800
- }
1801
- if (Array.isArray(filter._nestedGroups)) {
1802
- for (const group of filter._nestedGroups) if (hasMalformedFilterLeaf(group)) return true;
1803
- }
1804
- return false;
1805
- }
1806
- function normalizeBuilderStateResult(state) {
1807
- if (!state || typeof state !== "object") return err(queryErrors.invalidBuilderState(state));
1808
- const s = state;
1809
- const filter = normalizeFilter(s.filter);
1810
- if (hasMalformedFilterLeaf(filter)) return err(queryErrors.malformedFilterLeaf());
1811
- const normalized = {
1812
- dimensions: Array.isArray(s.dimensions) ? s.dimensions : [],
1813
- metrics: s.metrics,
1814
- filter,
1815
- orderBy: normalizeOrderBy(s.orderBy),
1816
- rowLimit: s.rowLimit,
1817
- startRow: s.startRow,
1818
- dataState: s.dataState,
1819
- aggregationType: s.aggregationType
1820
- };
1821
- if (typeof s.searchType === "string" && KNOWN_SEARCH_TYPES.has(s.searchType)) normalized.searchType = s.searchType;
1822
- return ok(normalized);
1823
- }
1824
- function normalizeBuilderState(state) {
1825
- return unwrapResult(normalizeBuilderStateResult(state), queryErrorToException);
1826
- }
1827
- function extractSpecialFilters(filter) {
1828
- if (!filter || !Array.isArray(filter._filters)) return {};
1829
- let startDate;
1830
- let endDate;
1831
- let searchType;
1832
- const otherFilters = [];
1833
- const cleanedNestedGroups = [];
1834
- for (const f of filter._filters) if (f.dimension === "date" && isDateOperator(f.operator)) switch (f.operator) {
1835
- case "gte":
1836
- startDate = f.expression;
1837
- break;
1838
- case "gt":
1839
- startDate = addDays(f.expression, 1);
1840
- break;
1841
- case "lte":
1842
- endDate = f.expression;
1843
- break;
1844
- case "lt":
1845
- endDate = addDays(f.expression, -1);
1846
- break;
1847
- case "between":
1848
- startDate = f.expression;
1849
- endDate = f.expression2;
1850
- break;
1851
- }
1852
- else if (isQueryParam(f.dimension)) {
1853
- if (f.dimension === "searchType") searchType = f.expression;
1854
- } else if (isMetricOperator(f.operator) || isSpecialOperator(f.operator)) otherFilters.push(f);
1855
- else otherFilters.push(f);
1856
- if (filter._nestedGroups) for (const nested of filter._nestedGroups) {
1857
- const extracted = extractSpecialFilters(nested);
1858
- if (!startDate && extracted.startDate) startDate = extracted.startDate;
1859
- if (!endDate && extracted.endDate) endDate = extracted.endDate;
1860
- if (!searchType && extracted.searchType) searchType = extracted.searchType;
1861
- if (extracted.dimensionFilter) cleanedNestedGroups.push(extracted.dimensionFilter);
1862
- }
1863
- const dimensionFilter = otherFilters.length > 0 || cleanedNestedGroups.length > 0 ? {
1864
- ...filter,
1865
- _filters: otherFilters,
1866
- _nestedGroups: cleanedNestedGroups.length > 0 ? cleanedNestedGroups : void 0
1867
- } : void 0;
1868
- return {
1869
- startDate,
1870
- endDate,
1871
- searchType,
1872
- dimensionFilter
1873
- };
1874
- }
1875
- function extractDateRange(input) {
1876
- const { startDate, endDate } = extractSpecialFilters(normalizeFilter(input));
1877
- return {
1878
- startDate,
1879
- endDate
1880
- };
1881
- }
1882
- function extractMetricFilters(input) {
1883
- const filter = normalizeFilter(input);
1884
- if (!filter) return [];
1885
- const metricFilters = filter._filters.filter((f) => isMetricOperator(f.operator));
1886
- const nested = filter._nestedGroups?.flatMap((g) => extractMetricFilters(g)) ?? [];
1887
- return [...metricFilters, ...nested];
1888
- }
1889
- function extractSpecialOperatorFilters(input) {
1890
- const filter = normalizeFilter(input);
1891
- if (!filter) return [];
1892
- const special = filter._filters.filter((f) => isSpecialOperator(f.operator));
1893
- const nested = filter._nestedGroups?.flatMap((g) => extractSpecialOperatorFilters(g)) ?? [];
1894
- return [...special, ...nested];
1895
- }
1896
- function extractSearchType(state) {
1897
- if (!state) return void 0;
1898
- if (state.searchType && KNOWN_SEARCH_TYPES.has(state.searchType)) return state.searchType;
1899
- const filter = state.filter;
1900
- const raw = extractSpecialFilters(normalizeFilter(filter)).searchType;
1901
- if (typeof raw !== "string" || raw.length === 0) return void 0;
1902
- return KNOWN_SEARCH_TYPES.has(raw) ? raw : void 0;
1903
- }
1904
- function resolveToBodyResult(state) {
1905
- const { startDate, endDate, searchType, dimensionFilter } = extractSpecialFilters(state.filter);
1906
- if (!startDate || !endDate) return err(queryErrors.missingDateRange());
1907
- const body = {
1908
- dimensions: state.dimensions,
1909
- startDate,
1910
- endDate
1911
- };
1912
- const resolvedType = state.searchType ?? searchType;
1913
- if (resolvedType) body.type = resolvedType;
1914
- if (state.rowLimit !== void 0) {
1915
- if (!Number.isInteger(state.rowLimit) || state.rowLimit < 1) return err(queryErrors.invalidRowLimit(state.rowLimit));
1916
- body.rowLimit = state.rowLimit;
1917
- }
1918
- if (state.startRow !== void 0) {
1919
- if (!Number.isInteger(state.startRow) || state.startRow < 0) return err(queryErrors.invalidStartRow(state.startRow));
1920
- if (state.startRow > 0) body.startRow = state.startRow;
1921
- }
1922
- const hasHour = state.dimensions?.includes("hour");
1923
- if (hasHour && state.dataState !== "hourly_all") return err(queryErrors.hourDimensionRequiresHourlyState());
1924
- if (state.dataState === "hourly_all" && !hasHour) return err(queryErrors.hourlyStateRequiresHourDimension());
1925
- if (state.dataState) body.dataState = state.dataState;
1926
- const filterGroups = resolveFilter(dimensionFilter);
1927
- if (filterGroups.length > 0) body.dimensionFilterGroups = filterGroups;
1928
- if (state.aggregationType) {
1929
- const groupsByPage = (body.dimensions ?? []).includes("page");
1930
- const apiLeafFilters = filterGroups.flatMap((g) => g.filters ?? []);
1931
- const filtersByPage = apiLeafFilters.some((f) => f.dimension === "page");
1932
- if (state.aggregationType === "byProperty") {
1933
- if (body.type === "discover" || body.type === "googleNews") return err(queryErrors.byPropertyUnsupportedSearchType());
1934
- if (groupsByPage || filtersByPage) return err(queryErrors.byPropertyNotAllowedWithPage());
1935
- }
1936
- if (state.aggregationType === "byNewsShowcasePanel") {
1937
- if (body.type !== "discover" && body.type !== "googleNews") return err(queryErrors.byNewsShowcaseRequiresSearchType());
1938
- if (groupsByPage || filtersByPage) return err(queryErrors.byNewsShowcaseNotAllowedWithPage());
1939
- const saFilters = apiLeafFilters.filter((f) => f.dimension === "searchAppearance");
1940
- const hasNewsShowcase = saFilters.some((f) => f.operator === "equals" && f.expression === "NEWS_SHOWCASE");
1941
- const hasOther = saFilters.some((f) => !(f.operator === "equals" && f.expression === "NEWS_SHOWCASE"));
1942
- if (!hasNewsShowcase || hasOther) return err(queryErrors.byNewsShowcaseRequiresShowcaseFilter());
1943
- }
1944
- body.aggregationType = state.aggregationType;
1945
- }
1946
- return ok(body);
1947
- }
1948
- function resolveToBody(state) {
1949
- return unwrapResult(resolveToBodyResult(state), queryErrorToException);
1950
- }
1951
- function isApiFilter(f) {
1952
- return !isMetricOperator(f.operator) && !isSpecialOperator(f.operator);
1953
- }
1954
- function resolveFilter(filter) {
1955
- if (!filter) return [];
1956
- const groups = [];
1957
- const groupType = filter._groupType ?? "and";
1958
- const apiFilters = filter._filters.filter(isApiFilter);
1959
- if (groupType === "or") {
1960
- if (apiFilters.length > 0) groups.push({
1961
- groupType: "or",
1962
- filters: apiFilters.map((f) => ({
1963
- dimension: f.dimension,
1964
- operator: f.operator,
1965
- expression: f.expression
1966
- }))
1967
- });
1968
- } else if (apiFilters.length > 0) groups.push({ filters: apiFilters.map((f) => ({
1969
- dimension: f.dimension,
1970
- operator: f.operator,
1971
- expression: f.expression
1972
- })) });
1973
- if (filter._nestedGroups) for (const nested of filter._nestedGroups) groups.push(...resolveFilter(nested));
1974
- return groups;
1975
- }
1
+ import { Countries, DATE_OPERATORS, Devices, SearchTypes, UnresolvableDatasetError, UnsupportedLogicalCapabilityError, extractDateRange, extractMetricFilters, extractSearchType, extractSpecialOperatorFilters, isQueryError, normalizeBuilderState, normalizeBuilderStateResult, normalizeFilter, queryErrorToException, queryErrors, resolveToBody, resolveToBodyResult } from "../_chunks/resolver.mjs";
2
+ import { currentPstDate, daysAgoPst } from "../_chunks/dayjs.mjs";
3
+ import { buildLogicalComparisonPlan, buildLogicalComparisonPlanResult, buildLogicalPlan, buildLogicalPlanResult } from "./plan.mjs";
1976
4
  function isDimensionString(v) {
1977
5
  return typeof v === "string";
1978
6
  }
@@ -2201,170 +229,6 @@ function between(column, start, end) {
2201
229
  function topLevel(column) {
2202
230
  return leafFilter(column.dimension, "topLevel", "");
2203
231
  }
2204
- function collectInternalFilters(filter) {
2205
- if (!filter || !("_filters" in filter)) return [];
2206
- const flat = filter._filters;
2207
- const nested = filter._nestedGroups?.flatMap((group) => collectInternalFilters(group)) ?? [];
2208
- return [...flat, ...nested];
2209
- }
2210
- function inferDataset(dimensions, filterDims = []) {
2211
- const allDims = /* @__PURE__ */ new Set([...dimensions, ...filterDims]);
2212
- const has = (dimension) => allDims.has(dimension);
2213
- if (has("searchAppearance")) {
2214
- if (has("page") && (has("query") || has("queryCanonical"))) return "search_appearance_page_queries";
2215
- if (has("page")) return "search_appearance_pages";
2216
- if (has("query") || has("queryCanonical")) return "search_appearance_queries";
2217
- return "search_appearance";
2218
- }
2219
- if (has("page") && (has("query") || has("queryCanonical"))) return "page_queries";
2220
- if (has("query") || has("queryCanonical")) return "queries";
2221
- if (has("page")) return "pages";
2222
- if (has("country")) return "countries";
2223
- if (has("device")) return "dates";
2224
- return "dates";
2225
- }
2226
- const RESOLVABLE_DIMENSION_FAMILIES = [
2227
- /* @__PURE__ */ new Set([
2228
- "page",
2229
- "query",
2230
- "queryCanonical"
2231
- ]),
2232
- /* @__PURE__ */ new Set(["country"]),
2233
- /* @__PURE__ */ new Set([
2234
- "searchAppearance",
2235
- "page",
2236
- "query",
2237
- "queryCanonical"
2238
- ])
2239
- ];
2240
- const TIME_AXIS_DIMENSIONS = /* @__PURE__ */ new Set(["date", "hour"]);
2241
- function isDatasetResolvable(dimensions, filterDims = []) {
2242
- const needed = new Set([...dimensions, ...filterDims].filter((d) => !TIME_AXIS_DIMENSIONS.has(d)));
2243
- if (needed.size === 0) return true;
2244
- return RESOLVABLE_DIMENSION_FAMILIES.some((family) => [...needed].every((d) => family.has(d)));
2245
- }
2246
- function isDimensionLeaf(filter) {
2247
- if (isMetric(filter.dimension)) return false;
2248
- if (filter.dimension === "date" && isDateOperator(filter.operator)) return false;
2249
- if (filter.operator === "topLevel" || filter.operator.startsWith("metric")) return false;
2250
- if (isQueryParam(filter.dimension)) return false;
2251
- return true;
2252
- }
2253
- function toLogicalDimensionFilter(filter) {
2254
- return {
2255
- dimension: filter.dimension,
2256
- operator: filter.operator,
2257
- expression: filter.expression,
2258
- expression2: filter.expression2
2259
- };
2260
- }
2261
- function buildDimensionFilterTree(filter) {
2262
- if (!filter || !("_filters" in filter)) return void 0;
2263
- const groupType = filter._groupType ?? "and";
2264
- const children = [];
2265
- for (const f of filter._filters) {
2266
- if (!isDimensionLeaf(f)) continue;
2267
- children.push({
2268
- kind: "leaf",
2269
- filter: toLogicalDimensionFilter(f)
2270
- });
2271
- }
2272
- for (const g of filter._nestedGroups ?? []) {
2273
- const sub = buildDimensionFilterTree(g);
2274
- if (sub) children.push(sub);
2275
- }
2276
- if (children.length === 0) return void 0;
2277
- if (children.length === 1) return children[0];
2278
- return {
2279
- kind: "group",
2280
- groupType,
2281
- children
2282
- };
2283
- }
2284
- function buildLogicalPlanResult(state, capabilities = {}) {
2285
- const normalizedFilter = normalizeFilter(state.filter);
2286
- const { startDate, endDate } = extractDateRange(normalizedFilter);
2287
- if (!startDate || !endDate) return err(queryErrors.missingDateRange());
2288
- const allFilters = collectInternalFilters(normalizedFilter);
2289
- if (!capabilities.regex && allFilters.some((f) => isDimensionLeaf(f) && isRegexOperator(f.operator))) return err(queryErrors.unsupportedCapability("regex", "logical plan"));
2290
- const metricFilters = extractMetricFilters(normalizedFilter);
2291
- const specialFilters = extractSpecialOperatorFilters(normalizedFilter);
2292
- const prefilters = extractMetricFilters(normalizeFilter(state.prefilter));
2293
- const queryParams = {};
2294
- const dimensionFilters = [];
2295
- for (const filter of allFilters) {
2296
- if (isMetric(filter.dimension)) continue;
2297
- if (filter.dimension === "date" && isDateOperator(filter.operator)) continue;
2298
- if (filter.operator === "topLevel" || filter.operator.startsWith("metric")) continue;
2299
- if (isQueryParam(filter.dimension)) {
2300
- queryParams[filter.dimension] = filter.expression;
2301
- continue;
2302
- }
2303
- dimensionFilters.push({
2304
- dimension: filter.dimension,
2305
- operator: filter.operator,
2306
- expression: filter.expression,
2307
- expression2: filter.expression2
2308
- });
2309
- }
2310
- const dimensionFilterTree = buildDimensionFilterTree(normalizedFilter);
2311
- const filterDims = dimensionFilters.map((filter) => filter.dimension);
2312
- if (!isDatasetResolvable(state.dimensions, filterDims)) return err(queryErrors.unresolvableDataset(state.dimensions, filterDims));
2313
- return ok({
2314
- dataset: inferDataset(state.dimensions, filterDims),
2315
- dimensions: [...state.dimensions],
2316
- groupByDimensions: state.dimensions.filter((d) => d !== "date"),
2317
- hasDate: state.dimensions.includes("date"),
2318
- metrics: state.metrics ? [...state.metrics] : [
2319
- "clicks",
2320
- "impressions",
2321
- "ctr",
2322
- "position"
2323
- ],
2324
- dateRange: {
2325
- startDate,
2326
- endDate
2327
- },
2328
- dimensionFilters,
2329
- dimensionFilterTree,
2330
- metricFilters: metricFilters.map((filter) => ({
2331
- metric: filter.dimension,
2332
- operator: filter.operator,
2333
- expression: Number(filter.expression),
2334
- expression2: filter.expression2 == null ? void 0 : Number(filter.expression2)
2335
- })),
2336
- prefilters: prefilters.map((filter) => ({
2337
- metric: filter.dimension,
2338
- operator: filter.operator,
2339
- expression: Number(filter.expression),
2340
- expression2: filter.expression2 == null ? void 0 : Number(filter.expression2)
2341
- })),
2342
- specialFilters: { topLevel: specialFilters.some((filter) => filter.operator === "topLevel") },
2343
- queryParams,
2344
- orderBy: state.orderBy,
2345
- rowLimit: state.rowLimit,
2346
- startRow: state.startRow
2347
- });
2348
- }
2349
- function buildLogicalPlan(state, capabilities = {}) {
2350
- return unwrapResult(buildLogicalPlanResult(state, capabilities), queryErrorToException);
2351
- }
2352
- function buildLogicalComparisonPlanResult(current, previous, capabilities = {}, comparisonFilter) {
2353
- if (!capabilities.comparisonJoin) return err(queryErrors.unsupportedCapability("comparisonJoin", "logical comparison plan"));
2354
- const currentResult = buildLogicalPlanResult(current, capabilities);
2355
- if (!currentResult.ok) return currentResult;
2356
- const previousResult = buildLogicalPlanResult(previous, capabilities);
2357
- if (!previousResult.ok) return previousResult;
2358
- if (currentResult.value.dataset !== previousResult.value.dataset && !capabilities.multiDataset) return err(queryErrors.unsupportedCapability("multiDataset", "logical comparison plan"));
2359
- return ok({
2360
- current: currentResult.value,
2361
- previous: previousResult.value,
2362
- comparisonFilter
2363
- });
2364
- }
2365
- function buildLogicalComparisonPlan(current, previous, capabilities = {}, comparisonFilter) {
2366
- return unwrapResult(buildLogicalComparisonPlanResult(current, previous, capabilities, comparisonFilter), queryErrorToException);
2367
- }
2368
232
  function today() {
2369
233
  return currentPstDate();
2370
234
  }