@metamask/utils 5.0.2 → 6.0.0

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,1491 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.JSON_VALIDATION_FIXTURES = exports.CHARACTER_MAP = exports.JSON_RPC_PENDING_RESPONSE_FIXTURES = exports.JSON_RPC_RESPONSE_FIXTURES = exports.JSON_RPC_ERROR_FIXTURES = exports.JSON_RPC_FAILURE_FIXTURES = exports.JSON_RPC_SUCCESS_FIXTURES = exports.JSON_RPC_REQUEST_FIXTURES = exports.JSON_RPC_NOTIFICATION_FIXTURES = exports.JSON_FIXTURES = void 0;
4
+ exports.JSON_FIXTURES = {
5
+ valid: [
6
+ null,
7
+ { a: 1 },
8
+ ['a', 2, null],
9
+ [{ a: null, b: 2, c: [{ foo: 'bar' }] }],
10
+ ],
11
+ invalid: [undefined, Symbol('bar'), () => 'foo', [{ a: undefined }]],
12
+ };
13
+ exports.JSON_RPC_NOTIFICATION_FIXTURES = {
14
+ valid: [
15
+ {
16
+ jsonrpc: '2.0',
17
+ method: 'notify',
18
+ },
19
+ {
20
+ jsonrpc: '2.0',
21
+ method: 'notify',
22
+ params: {
23
+ foo: 'bar',
24
+ },
25
+ },
26
+ {
27
+ jsonrpc: '2.0',
28
+ method: 'notify',
29
+ params: ['foo'],
30
+ },
31
+ ],
32
+ invalid: [
33
+ {},
34
+ [],
35
+ true,
36
+ false,
37
+ null,
38
+ undefined,
39
+ 1,
40
+ 'foo',
41
+ {
42
+ id: 1,
43
+ jsonrpc: '2.0',
44
+ method: 'notify',
45
+ },
46
+ {
47
+ jsonrpc: '1.0',
48
+ method: 'notify',
49
+ },
50
+ {
51
+ jsonrpc: 2.0,
52
+ method: 'notify',
53
+ },
54
+ {
55
+ jsonrpc: '2.0',
56
+ method: {},
57
+ },
58
+ {
59
+ jsonrpc: '2.0',
60
+ method: [],
61
+ },
62
+ {
63
+ jsonrpc: '2.0',
64
+ method: true,
65
+ },
66
+ {
67
+ jsonrpc: '2.0',
68
+ method: false,
69
+ },
70
+ {
71
+ jsonrpc: '2.0',
72
+ method: null,
73
+ },
74
+ {
75
+ jsonrpc: '2.0',
76
+ method: undefined,
77
+ },
78
+ {
79
+ jsonrpc: '2.0',
80
+ method: 1,
81
+ },
82
+ {
83
+ jsonrpc: '2.0',
84
+ method: 'notify',
85
+ params: true,
86
+ },
87
+ {
88
+ jsonrpc: '2.0',
89
+ method: 'notify',
90
+ params: false,
91
+ },
92
+ {
93
+ jsonrpc: '2.0',
94
+ method: 'notify',
95
+ params: null,
96
+ },
97
+ {
98
+ jsonrpc: '2.0',
99
+ method: 'notify',
100
+ params: 1,
101
+ },
102
+ {
103
+ jsonrpc: '2.0',
104
+ method: 'notify',
105
+ params: '',
106
+ },
107
+ ],
108
+ };
109
+ exports.JSON_RPC_REQUEST_FIXTURES = {
110
+ valid: [
111
+ {
112
+ jsonrpc: '2.0',
113
+ method: 'notify',
114
+ id: 1,
115
+ },
116
+ {
117
+ jsonrpc: '2.0',
118
+ method: 'notify',
119
+ id: '1',
120
+ params: {
121
+ foo: 'bar',
122
+ },
123
+ },
124
+ {
125
+ jsonrpc: '2.0',
126
+ method: 'notify',
127
+ id: 'foo',
128
+ params: ['foo'],
129
+ },
130
+ {
131
+ jsonrpc: '2.0',
132
+ method: 'notify',
133
+ id: null,
134
+ },
135
+ ],
136
+ invalid: [
137
+ {},
138
+ [],
139
+ true,
140
+ false,
141
+ null,
142
+ undefined,
143
+ 1,
144
+ 'foo',
145
+ {
146
+ id: 1,
147
+ jsonrpc: '1.0',
148
+ method: 'notify',
149
+ },
150
+ {
151
+ id: 1,
152
+ jsonrpc: 2.0,
153
+ method: 'notify',
154
+ },
155
+ {
156
+ id: 1,
157
+ jsonrpc: '2.0',
158
+ method: {},
159
+ },
160
+ {
161
+ id: 1,
162
+ jsonrpc: '2.0',
163
+ method: [],
164
+ },
165
+ {
166
+ id: 1,
167
+ jsonrpc: '2.0',
168
+ method: true,
169
+ },
170
+ {
171
+ id: 1,
172
+ jsonrpc: '2.0',
173
+ method: false,
174
+ },
175
+ {
176
+ id: 1,
177
+ jsonrpc: '2.0',
178
+ method: null,
179
+ },
180
+ {
181
+ id: 1,
182
+ jsonrpc: '2.0',
183
+ method: undefined,
184
+ },
185
+ {
186
+ id: 1,
187
+ jsonrpc: '2.0',
188
+ method: 1,
189
+ },
190
+ {
191
+ id: 1,
192
+ jsonrpc: '2.0',
193
+ method: 'notify',
194
+ params: true,
195
+ },
196
+ {
197
+ id: 1,
198
+ jsonrpc: '2.0',
199
+ method: 'notify',
200
+ params: false,
201
+ },
202
+ {
203
+ id: 1,
204
+ jsonrpc: '2.0',
205
+ method: 'notify',
206
+ params: null,
207
+ },
208
+ {
209
+ id: 1,
210
+ jsonrpc: '2.0',
211
+ method: 'notify',
212
+ params: 1,
213
+ },
214
+ {
215
+ id: 1,
216
+ jsonrpc: '2.0',
217
+ method: 'notify',
218
+ params: '',
219
+ },
220
+ ],
221
+ };
222
+ exports.JSON_RPC_SUCCESS_FIXTURES = {
223
+ valid: [
224
+ {
225
+ id: 1,
226
+ jsonrpc: '2.0',
227
+ result: 'foo',
228
+ },
229
+ {
230
+ id: '1',
231
+ jsonrpc: '2.0',
232
+ result: {
233
+ foo: 'bar',
234
+ },
235
+ },
236
+ {
237
+ id: 'foo',
238
+ jsonrpc: '2.0',
239
+ result: null,
240
+ },
241
+ {
242
+ id: 1,
243
+ jsonrpc: '2.0',
244
+ result: [
245
+ {
246
+ foo: 'bar',
247
+ },
248
+ ],
249
+ },
250
+ ],
251
+ invalid: [
252
+ {},
253
+ [],
254
+ true,
255
+ false,
256
+ null,
257
+ undefined,
258
+ 1,
259
+ 'foo',
260
+ {
261
+ jsonrpc: '2.0',
262
+ result: 'foo',
263
+ },
264
+ {
265
+ id: 1,
266
+ result: 'foo',
267
+ },
268
+ {
269
+ id: 1,
270
+ jsonrpc: '2.0',
271
+ },
272
+ {
273
+ id: 1,
274
+ jsonrpc: '1.0',
275
+ result: 'foo',
276
+ },
277
+ {
278
+ id: 1,
279
+ jsonrpc: 2.0,
280
+ result: 'foo',
281
+ },
282
+ {
283
+ id: 1,
284
+ jsonrpc: '2.0',
285
+ result: undefined,
286
+ },
287
+ {
288
+ id: {},
289
+ jsonrpc: '2.0',
290
+ result: 'foo',
291
+ },
292
+ {
293
+ id: [],
294
+ jsonrpc: '2.0',
295
+ result: 'foo',
296
+ },
297
+ {
298
+ id: true,
299
+ jsonrpc: '2.0',
300
+ result: 'foo',
301
+ },
302
+ {
303
+ id: false,
304
+ jsonrpc: '2.0',
305
+ result: 'foo',
306
+ },
307
+ {
308
+ id: undefined,
309
+ jsonrpc: '2.0',
310
+ result: 'foo',
311
+ },
312
+ ],
313
+ };
314
+ exports.JSON_RPC_FAILURE_FIXTURES = {
315
+ valid: [
316
+ {
317
+ id: 1,
318
+ jsonrpc: '2.0',
319
+ error: {
320
+ code: -32000,
321
+ message: 'Internal error',
322
+ },
323
+ },
324
+ {
325
+ id: '1',
326
+ jsonrpc: '2.0',
327
+ error: {
328
+ code: -32001,
329
+ message: 'Internal error',
330
+ data: {
331
+ foo: 'bar',
332
+ },
333
+ },
334
+ },
335
+ {
336
+ id: 'foo',
337
+ jsonrpc: '2.0',
338
+ error: {
339
+ code: -32002,
340
+ message: 'Internal error',
341
+ data: ['foo'],
342
+ stack: 'bar',
343
+ },
344
+ },
345
+ {
346
+ id: 'foo',
347
+ jsonrpc: '2.0',
348
+ error: {
349
+ code: -32000,
350
+ message: 'Internal error',
351
+ data: 'foo',
352
+ },
353
+ },
354
+ {
355
+ id: 'foo',
356
+ jsonrpc: '2.0',
357
+ error: {
358
+ code: -32000,
359
+ message: 'Internal error',
360
+ data: 1,
361
+ },
362
+ },
363
+ ],
364
+ invalid: [
365
+ {},
366
+ [],
367
+ true,
368
+ false,
369
+ null,
370
+ undefined,
371
+ 1,
372
+ 'foo',
373
+ {
374
+ jsonrpc: '2.0',
375
+ error: {
376
+ code: -32000,
377
+ message: 'Internal error',
378
+ },
379
+ },
380
+ {
381
+ id: 1,
382
+ error: {
383
+ code: -32000,
384
+ message: 'Internal error',
385
+ },
386
+ },
387
+ {
388
+ id: 1,
389
+ jsonrpc: '2.0',
390
+ },
391
+ {
392
+ id: {},
393
+ jsonrpc: '2.0',
394
+ error: {
395
+ code: -32000,
396
+ message: 'Internal error',
397
+ },
398
+ },
399
+ {
400
+ id: [],
401
+ jsonrpc: '2.0',
402
+ error: {
403
+ code: -32000,
404
+ message: 'Internal error',
405
+ },
406
+ },
407
+ {
408
+ id: true,
409
+ jsonrpc: '2.0',
410
+ error: {
411
+ code: -32000,
412
+ message: 'Internal error',
413
+ },
414
+ },
415
+ {
416
+ id: false,
417
+ jsonrpc: '2.0',
418
+ error: {
419
+ code: -32000,
420
+ message: 'Internal error',
421
+ },
422
+ },
423
+ {
424
+ id: undefined,
425
+ jsonrpc: '2.0',
426
+ error: {
427
+ code: -32000,
428
+ message: 'Internal error',
429
+ },
430
+ },
431
+ {
432
+ id: 1,
433
+ jsonrpc: '1.0',
434
+ error: {
435
+ code: -32000,
436
+ message: 'Internal error',
437
+ },
438
+ },
439
+ {
440
+ id: 1,
441
+ jsonrpc: 2.0,
442
+ error: {
443
+ code: -32000,
444
+ message: 'Internal error',
445
+ },
446
+ },
447
+ {
448
+ id: 1,
449
+ jsonrpc: {},
450
+ error: {
451
+ code: -32000,
452
+ message: 'Internal error',
453
+ },
454
+ },
455
+ {
456
+ id: 1,
457
+ jsonrpc: [],
458
+ error: {
459
+ code: -32000,
460
+ message: 'Internal error',
461
+ },
462
+ },
463
+ {
464
+ id: 1,
465
+ jsonrpc: true,
466
+ error: {
467
+ code: -32000,
468
+ message: 'Internal error',
469
+ },
470
+ },
471
+ {
472
+ id: 1,
473
+ jsonrpc: false,
474
+ error: {
475
+ code: -32000,
476
+ message: 'Internal error',
477
+ },
478
+ },
479
+ {
480
+ id: 1,
481
+ jsonrpc: null,
482
+ error: {
483
+ code: -32000,
484
+ message: 'Internal error',
485
+ },
486
+ },
487
+ {
488
+ id: 1,
489
+ jsonrpc: undefined,
490
+ error: {
491
+ code: -32000,
492
+ message: 'Internal error',
493
+ },
494
+ },
495
+ {
496
+ id: 1,
497
+ jsonrpc: '2.0',
498
+ error: {
499
+ code: -32000,
500
+ },
501
+ },
502
+ {
503
+ id: 1,
504
+ jsonrpc: '2.0',
505
+ error: {
506
+ message: 'Internal error',
507
+ },
508
+ },
509
+ {
510
+ id: 1,
511
+ jsonrpc: '2.0',
512
+ error: [],
513
+ },
514
+ {
515
+ id: 1,
516
+ jsonrpc: '2.0',
517
+ error: {},
518
+ },
519
+ {
520
+ id: 1,
521
+ jsonrpc: '2.0',
522
+ error: true,
523
+ },
524
+ {
525
+ id: 1,
526
+ jsonrpc: '2.0',
527
+ error: false,
528
+ },
529
+ {
530
+ id: 1,
531
+ jsonrpc: '2.0',
532
+ error: null,
533
+ },
534
+ {
535
+ id: 1,
536
+ jsonrpc: '2.0',
537
+ error: undefined,
538
+ },
539
+ {
540
+ id: 1,
541
+ jsonrpc: '2.0',
542
+ error: 'foo',
543
+ },
544
+ {
545
+ id: 1,
546
+ jsonrpc: '2.0',
547
+ error: 1,
548
+ },
549
+ {
550
+ id: 1,
551
+ jsonrpc: '2.0',
552
+ error: {
553
+ code: {},
554
+ message: 'Internal error',
555
+ },
556
+ },
557
+ {
558
+ id: 1,
559
+ jsonrpc: '2.0',
560
+ error: {
561
+ code: [],
562
+ message: 'Internal error',
563
+ },
564
+ },
565
+ {
566
+ id: 1,
567
+ jsonrpc: '2.0',
568
+ error: {
569
+ code: true,
570
+ message: 'Internal error',
571
+ },
572
+ },
573
+ {
574
+ id: 1,
575
+ jsonrpc: '2.0',
576
+ error: {
577
+ code: false,
578
+ message: 'Internal error',
579
+ },
580
+ },
581
+ {
582
+ id: 1,
583
+ jsonrpc: '2.0',
584
+ error: {
585
+ code: null,
586
+ message: 'Internal error',
587
+ },
588
+ },
589
+ {
590
+ id: 1,
591
+ jsonrpc: '2.0',
592
+ error: {
593
+ code: undefined,
594
+ message: 'Internal error',
595
+ },
596
+ },
597
+ {
598
+ id: 1,
599
+ jsonrpc: '2.0',
600
+ error: {
601
+ code: 'foo',
602
+ message: 'Internal error',
603
+ },
604
+ },
605
+ {
606
+ id: 1,
607
+ jsonrpc: '2.0',
608
+ error: {
609
+ code: -32000,
610
+ message: {},
611
+ },
612
+ },
613
+ {
614
+ id: 1,
615
+ jsonrpc: '2.0',
616
+ error: {
617
+ code: -32000,
618
+ message: [],
619
+ },
620
+ },
621
+ {
622
+ id: 1,
623
+ jsonrpc: '2.0',
624
+ error: {
625
+ code: -32000,
626
+ message: true,
627
+ },
628
+ },
629
+ {
630
+ id: 1,
631
+ jsonrpc: '2.0',
632
+ error: {
633
+ code: -32000,
634
+ message: false,
635
+ },
636
+ },
637
+ {
638
+ id: 1,
639
+ jsonrpc: '2.0',
640
+ error: {
641
+ code: -32000,
642
+ message: null,
643
+ },
644
+ },
645
+ {
646
+ id: 1,
647
+ jsonrpc: '2.0',
648
+ error: {
649
+ code: -32000,
650
+ message: undefined,
651
+ },
652
+ },
653
+ ],
654
+ };
655
+ exports.JSON_RPC_ERROR_FIXTURES = {
656
+ valid: exports.JSON_RPC_FAILURE_FIXTURES.valid.map((fixture) => fixture.error),
657
+ invalid: [
658
+ {},
659
+ [],
660
+ true,
661
+ false,
662
+ null,
663
+ undefined,
664
+ 1,
665
+ 'foo',
666
+ {
667
+ code: {},
668
+ message: 'Internal error',
669
+ },
670
+ {
671
+ code: [],
672
+ message: 'Internal error',
673
+ },
674
+ {
675
+ code: true,
676
+ message: 'Internal error',
677
+ },
678
+ {
679
+ code: false,
680
+ message: 'Internal error',
681
+ },
682
+ {
683
+ code: null,
684
+ message: 'Internal error',
685
+ },
686
+ {
687
+ code: undefined,
688
+ message: 'Internal error',
689
+ },
690
+ {
691
+ code: 'foo',
692
+ message: 'Internal error',
693
+ },
694
+ {
695
+ code: -32000,
696
+ message: {},
697
+ },
698
+ {
699
+ code: -32000,
700
+ message: [],
701
+ },
702
+ {
703
+ code: -32000,
704
+ message: true,
705
+ },
706
+ {
707
+ code: -32000,
708
+ message: false,
709
+ },
710
+ {
711
+ code: -32000,
712
+ message: null,
713
+ },
714
+ {
715
+ code: -32000,
716
+ message: undefined,
717
+ },
718
+ {
719
+ code: -32000.5,
720
+ message: undefined,
721
+ },
722
+ ],
723
+ };
724
+ exports.JSON_RPC_RESPONSE_FIXTURES = {
725
+ valid: [
726
+ ...exports.JSON_RPC_SUCCESS_FIXTURES.valid,
727
+ ...exports.JSON_RPC_FAILURE_FIXTURES.valid,
728
+ ],
729
+ invalid: [
730
+ ...exports.JSON_RPC_SUCCESS_FIXTURES.invalid,
731
+ ...exports.JSON_RPC_FAILURE_FIXTURES.invalid,
732
+ ],
733
+ };
734
+ exports.JSON_RPC_PENDING_RESPONSE_FIXTURES = {
735
+ valid: [
736
+ ...exports.JSON_RPC_SUCCESS_FIXTURES.valid,
737
+ ...exports.JSON_RPC_FAILURE_FIXTURES.valid,
738
+ {
739
+ id: 1,
740
+ jsonrpc: '2.0',
741
+ },
742
+ {
743
+ id: 1,
744
+ jsonrpc: '2.0',
745
+ error: undefined,
746
+ },
747
+ {
748
+ id: 1,
749
+ jsonrpc: '2.0',
750
+ result: undefined,
751
+ },
752
+ {
753
+ id: 1,
754
+ jsonrpc: '2.0',
755
+ result: undefined,
756
+ error: undefined,
757
+ },
758
+ {
759
+ id: 1,
760
+ jsonrpc: '2.0',
761
+ result: {
762
+ foo: 'bar',
763
+ },
764
+ error: {
765
+ code: -32000,
766
+ message: 'Internal error',
767
+ },
768
+ },
769
+ ],
770
+ invalid: [
771
+ {},
772
+ [],
773
+ true,
774
+ false,
775
+ null,
776
+ undefined,
777
+ 1,
778
+ 'foo',
779
+ {
780
+ jsonrpc: '2.0',
781
+ error: {
782
+ code: -32000,
783
+ message: 'Internal error',
784
+ },
785
+ },
786
+ {
787
+ id: 1,
788
+ error: {
789
+ code: -32000,
790
+ message: 'Internal error',
791
+ },
792
+ },
793
+ {
794
+ id: {},
795
+ jsonrpc: '2.0',
796
+ error: {
797
+ code: -32000,
798
+ message: 'Internal error',
799
+ },
800
+ },
801
+ {
802
+ id: [],
803
+ jsonrpc: '2.0',
804
+ error: {
805
+ code: -32000,
806
+ message: 'Internal error',
807
+ },
808
+ },
809
+ {
810
+ id: true,
811
+ jsonrpc: '2.0',
812
+ error: {
813
+ code: -32000,
814
+ message: 'Internal error',
815
+ },
816
+ },
817
+ {
818
+ id: false,
819
+ jsonrpc: '2.0',
820
+ error: {
821
+ code: -32000,
822
+ message: 'Internal error',
823
+ },
824
+ },
825
+ {
826
+ id: undefined,
827
+ jsonrpc: '2.0',
828
+ error: {
829
+ code: -32000,
830
+ message: 'Internal error',
831
+ },
832
+ },
833
+ {
834
+ id: 1,
835
+ jsonrpc: '1.0',
836
+ error: {
837
+ code: -32000,
838
+ message: 'Internal error',
839
+ },
840
+ },
841
+ {
842
+ id: 1,
843
+ jsonrpc: 2.0,
844
+ error: {
845
+ code: -32000,
846
+ message: 'Internal error',
847
+ },
848
+ },
849
+ {
850
+ id: 1,
851
+ jsonrpc: {},
852
+ error: {
853
+ code: -32000,
854
+ message: 'Internal error',
855
+ },
856
+ },
857
+ {
858
+ id: 1,
859
+ jsonrpc: [],
860
+ error: {
861
+ code: -32000,
862
+ message: 'Internal error',
863
+ },
864
+ },
865
+ {
866
+ id: 1,
867
+ jsonrpc: true,
868
+ error: {
869
+ code: -32000,
870
+ message: 'Internal error',
871
+ },
872
+ },
873
+ {
874
+ id: 1,
875
+ jsonrpc: false,
876
+ error: {
877
+ code: -32000,
878
+ message: 'Internal error',
879
+ },
880
+ },
881
+ {
882
+ id: 1,
883
+ jsonrpc: null,
884
+ error: {
885
+ code: -32000,
886
+ message: 'Internal error',
887
+ },
888
+ },
889
+ {
890
+ id: 1,
891
+ jsonrpc: undefined,
892
+ error: {
893
+ code: -32000,
894
+ message: 'Internal error',
895
+ },
896
+ },
897
+ {
898
+ id: 1,
899
+ jsonrpc: '2.0',
900
+ error: {
901
+ code: -32000,
902
+ },
903
+ },
904
+ {
905
+ id: 1,
906
+ jsonrpc: '2.0',
907
+ error: {
908
+ message: 'Internal error',
909
+ },
910
+ },
911
+ {
912
+ id: 1,
913
+ jsonrpc: '2.0',
914
+ error: [],
915
+ },
916
+ {
917
+ id: 1,
918
+ jsonrpc: '2.0',
919
+ error: {},
920
+ },
921
+ {
922
+ id: 1,
923
+ jsonrpc: '2.0',
924
+ error: true,
925
+ },
926
+ {
927
+ id: 1,
928
+ jsonrpc: '2.0',
929
+ error: false,
930
+ },
931
+ {
932
+ id: 1,
933
+ jsonrpc: '2.0',
934
+ error: null,
935
+ },
936
+ {
937
+ id: 1,
938
+ jsonrpc: '2.0',
939
+ error: 'foo',
940
+ },
941
+ {
942
+ id: 1,
943
+ jsonrpc: '2.0',
944
+ error: 1,
945
+ },
946
+ {
947
+ id: 1,
948
+ jsonrpc: '2.0',
949
+ error: {
950
+ code: {},
951
+ message: 'Internal error',
952
+ },
953
+ },
954
+ {
955
+ id: 1,
956
+ jsonrpc: '2.0',
957
+ error: {
958
+ code: [],
959
+ message: 'Internal error',
960
+ },
961
+ },
962
+ {
963
+ id: 1,
964
+ jsonrpc: '2.0',
965
+ error: {
966
+ code: true,
967
+ message: 'Internal error',
968
+ },
969
+ },
970
+ {
971
+ id: 1,
972
+ jsonrpc: '2.0',
973
+ error: {
974
+ code: false,
975
+ message: 'Internal error',
976
+ },
977
+ },
978
+ {
979
+ id: 1,
980
+ jsonrpc: '2.0',
981
+ error: {
982
+ code: null,
983
+ message: 'Internal error',
984
+ },
985
+ },
986
+ {
987
+ id: 1,
988
+ jsonrpc: '2.0',
989
+ error: {
990
+ code: undefined,
991
+ message: 'Internal error',
992
+ },
993
+ },
994
+ {
995
+ id: 1,
996
+ jsonrpc: '2.0',
997
+ error: {
998
+ code: 'foo',
999
+ message: 'Internal error',
1000
+ },
1001
+ },
1002
+ {
1003
+ id: 1,
1004
+ jsonrpc: '2.0',
1005
+ error: {
1006
+ code: -32000,
1007
+ message: {},
1008
+ },
1009
+ },
1010
+ {
1011
+ id: 1,
1012
+ jsonrpc: '2.0',
1013
+ error: {
1014
+ code: -32000,
1015
+ message: [],
1016
+ },
1017
+ },
1018
+ {
1019
+ id: 1,
1020
+ jsonrpc: '2.0',
1021
+ error: {
1022
+ code: -32000,
1023
+ message: true,
1024
+ },
1025
+ },
1026
+ {
1027
+ id: 1,
1028
+ jsonrpc: '2.0',
1029
+ error: {
1030
+ code: -32000,
1031
+ message: false,
1032
+ },
1033
+ },
1034
+ {
1035
+ id: 1,
1036
+ jsonrpc: '2.0',
1037
+ error: {
1038
+ code: -32000,
1039
+ message: null,
1040
+ },
1041
+ },
1042
+ {
1043
+ id: 1,
1044
+ jsonrpc: '2.0',
1045
+ error: {
1046
+ code: -32000,
1047
+ message: undefined,
1048
+ },
1049
+ },
1050
+ ],
1051
+ };
1052
+ /* eslint-disable @typescript-eslint/naming-convention */
1053
+ exports.CHARACTER_MAP = {
1054
+ '"': '\\"',
1055
+ '\\': '\\\\',
1056
+ '\x00': '\\u0000',
1057
+ '\x01': '\\u0001',
1058
+ '\x02': '\\u0002',
1059
+ '\x03': '\\u0003',
1060
+ '\x04': '\\u0004',
1061
+ '\x05': '\\u0005',
1062
+ '\x06': '\\u0006',
1063
+ '\x07': '\\u0007',
1064
+ '\x08': '\\b',
1065
+ '\x09': '\\t',
1066
+ '\x0A': '\\n',
1067
+ '\x0B': '\\u000b',
1068
+ '\x0C': '\\f',
1069
+ '\x0D': '\\r',
1070
+ '\x0E': '\\u000e',
1071
+ '\x0F': '\\u000f',
1072
+ '\x10': '\\u0010',
1073
+ '\x11': '\\u0011',
1074
+ '\x12': '\\u0012',
1075
+ '\x13': '\\u0013',
1076
+ '\x14': '\\u0014',
1077
+ '\x15': '\\u0015',
1078
+ '\x16': '\\u0016',
1079
+ '\x17': '\\u0017',
1080
+ '\x18': '\\u0018',
1081
+ '\x19': '\\u0019',
1082
+ '\x1A': '\\u001a',
1083
+ '\x1B': '\\u001b',
1084
+ '\x1C': '\\u001c',
1085
+ '\x1D': '\\u001d',
1086
+ '\x1E': '\\u001e',
1087
+ '\x1F': '\\u001f',
1088
+ };
1089
+ /* eslint-enable @typescript-eslint/naming-convention */
1090
+ const DIRECT_CIRCULAR_REFERENCE_ARRAY = [];
1091
+ DIRECT_CIRCULAR_REFERENCE_ARRAY.push(DIRECT_CIRCULAR_REFERENCE_ARRAY);
1092
+ const INDIRECT_CIRCULAR_REFERENCE_ARRAY = [];
1093
+ INDIRECT_CIRCULAR_REFERENCE_ARRAY.push([[INDIRECT_CIRCULAR_REFERENCE_ARRAY]]);
1094
+ const DIRECT_CIRCULAR_REFERENCE_OBJECT = {};
1095
+ DIRECT_CIRCULAR_REFERENCE_OBJECT.prop = DIRECT_CIRCULAR_REFERENCE_OBJECT;
1096
+ const INDIRECT_CIRCULAR_REFERENCE_OBJECT = {
1097
+ p1: {
1098
+ p2: {
1099
+ get p3() {
1100
+ return INDIRECT_CIRCULAR_REFERENCE_OBJECT;
1101
+ },
1102
+ },
1103
+ },
1104
+ };
1105
+ const TO_JSON_CIRCULAR_REFERENCE = {
1106
+ toJSON() {
1107
+ return {};
1108
+ },
1109
+ };
1110
+ const CIRCULAR_REFERENCE = { prop: TO_JSON_CIRCULAR_REFERENCE };
1111
+ TO_JSON_CIRCULAR_REFERENCE.toJSON = function () {
1112
+ return CIRCULAR_REFERENCE;
1113
+ };
1114
+ const DUPLICATE_DATE = new Date();
1115
+ const DUPLICATE_OBJECT = {
1116
+ value: 'foo',
1117
+ };
1118
+ const DUPLICATE_REFERENCE = {
1119
+ a: DUPLICATE_DATE,
1120
+ b: DUPLICATE_DATE,
1121
+ c: DUPLICATE_DATE,
1122
+ testOne: DUPLICATE_OBJECT,
1123
+ testTwo: DUPLICATE_OBJECT,
1124
+ testThree: {
1125
+ nestedObjectTest: {
1126
+ multipleTimes: {
1127
+ valueOne: DUPLICATE_OBJECT,
1128
+ valueTwo: DUPLICATE_OBJECT,
1129
+ valueThree: DUPLICATE_OBJECT,
1130
+ valueFour: DUPLICATE_OBJECT,
1131
+ valueFive: DUPLICATE_DATE,
1132
+ valueSix: {},
1133
+ },
1134
+ },
1135
+ },
1136
+ testFour: {},
1137
+ testFive: {
1138
+ something: null,
1139
+ somethingElse: null,
1140
+ anotherValue: null,
1141
+ somethingAgain: DUPLICATE_OBJECT,
1142
+ anotherOne: {
1143
+ nested: {
1144
+ multipleTimes: {
1145
+ valueOne: DUPLICATE_OBJECT,
1146
+ },
1147
+ },
1148
+ },
1149
+ },
1150
+ };
1151
+ const REVOKED_ARRAY_PROXY = Proxy.revocable([], {});
1152
+ REVOKED_ARRAY_PROXY.revoke();
1153
+ const REVOKED_OBJECT_PROXY = Proxy.revocable({}, {});
1154
+ REVOKED_OBJECT_PROXY.revoke();
1155
+ exports.JSON_VALIDATION_FIXTURES = [
1156
+ {
1157
+ value: {
1158
+ a: 'bc',
1159
+ },
1160
+ valid: true,
1161
+ size: 10,
1162
+ },
1163
+ {
1164
+ value: {
1165
+ a: 1234,
1166
+ },
1167
+ valid: true,
1168
+ size: 10,
1169
+ },
1170
+ {
1171
+ value: {
1172
+ a: 'bcšečf',
1173
+ },
1174
+ valid: true,
1175
+ size: 16,
1176
+ },
1177
+ {
1178
+ value: [
1179
+ -5e-11, 5e-9, 0.000000000001, -0.00000000009, 100000.00000008, -100.88888,
1180
+ 0.333, 1000000000000,
1181
+ ],
1182
+ valid: true,
1183
+ size: 73,
1184
+ },
1185
+ {
1186
+ value: {
1187
+ data: {
1188
+ account: {
1189
+ /* eslint-disable @typescript-eslint/naming-convention */
1190
+ __typename: 'Account',
1191
+ registrations: [
1192
+ {
1193
+ __typename: 'Registration',
1194
+ domain: {
1195
+ __typename: 'Domain',
1196
+ isMigrated: true,
1197
+ labelName: 'mycrypto',
1198
+ labelhash: '0x9a781ca0d227debc3ee76d547c960b0803a6c9f58c6d3b4722f12ede7e6ef7c9',
1199
+ name: 'mycrypto.eth',
1200
+ parent: { __typename: 'Domain', name: 'eth' },
1201
+ },
1202
+ expiryDate: '1754111315',
1203
+ },
1204
+ ],
1205
+ /* eslint-enable @typescript-eslint/naming-convention */
1206
+ },
1207
+ moreComplexity: {
1208
+ numbers: [
1209
+ -5e-11, 5e-9, 0.000000000001, -0.00000000009, 100000.00000008,
1210
+ -100.88888, 0.333, 1000000000000,
1211
+ ],
1212
+ moreNestedObjects: {
1213
+ nestedAgain: {
1214
+ nestedAgain: {
1215
+ andAgain: {
1216
+ andAgain: {
1217
+ value: true,
1218
+ again: {
1219
+ value: false,
1220
+ },
1221
+ },
1222
+ },
1223
+ },
1224
+ },
1225
+ },
1226
+ differentEncodings: {
1227
+ ascii: '!"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~',
1228
+ utf8: 'šđćčžЀЂЇЄЖФћΣΩδλ',
1229
+ mixed: 'ABCDEFGHIJ KLMNOPQRST UVWXYZšđćč žЀЂЇЄЖФћΣΩδλ',
1230
+ specialCharacters: '"\\\n\r\t',
1231
+ stringWithSpecialEscapedCharacters: "this\nis\nsome\"'string\r\nwith\tspecial\\escaped\tcharacters'",
1232
+ },
1233
+ specialObjectsTypesAndValues: {
1234
+ t: [true, true, true],
1235
+ f: [false, false, false],
1236
+ nulls: [null, null, null],
1237
+ undef: null,
1238
+ mixed: [
1239
+ null,
1240
+ null,
1241
+ null,
1242
+ null,
1243
+ null,
1244
+ true,
1245
+ null,
1246
+ false,
1247
+ null,
1248
+ null,
1249
+ ],
1250
+ inObject: {
1251
+ valueOne: null,
1252
+ valueTwo: null,
1253
+ t: true,
1254
+ f: false,
1255
+ },
1256
+ dates: {
1257
+ someDate: new Date(),
1258
+ someOther: new Date(2022, 0, 2, 15, 4, 5),
1259
+ invalidDate: new Date('bad-date-format'),
1260
+ },
1261
+ },
1262
+ },
1263
+ },
1264
+ },
1265
+ valid: true,
1266
+ size: 1288,
1267
+ },
1268
+ {
1269
+ value: {
1270
+ dates: {
1271
+ someDate: new Date(),
1272
+ someOther: new Date(2022, 0, 2, 15, 4, 5),
1273
+ invalidDate: new Date('bad-date-format'),
1274
+ },
1275
+ },
1276
+ valid: true,
1277
+ size: 107,
1278
+ },
1279
+ {
1280
+ value: ['foo', 'bar', null, ['foo', 'bar', null]],
1281
+ valid: true,
1282
+ size: 37,
1283
+ },
1284
+ {
1285
+ value: null,
1286
+ valid: true,
1287
+ size: 4,
1288
+ },
1289
+ {
1290
+ value: true,
1291
+ valid: true,
1292
+ size: 4,
1293
+ },
1294
+ {
1295
+ value: false,
1296
+ valid: true,
1297
+ size: 5,
1298
+ },
1299
+ {
1300
+ value: 'str',
1301
+ valid: true,
1302
+ size: 5,
1303
+ },
1304
+ {
1305
+ value: 123,
1306
+ valid: true,
1307
+ size: 3,
1308
+ },
1309
+ {
1310
+ value: {
1311
+ a: undefined,
1312
+ },
1313
+ valid: false,
1314
+ size: 0,
1315
+ },
1316
+ {
1317
+ value: {
1318
+ levelOne: {
1319
+ levelTwo: {
1320
+ levelThree: {
1321
+ levelFour: {
1322
+ levelFive: () => {
1323
+ return 'anything';
1324
+ },
1325
+ },
1326
+ },
1327
+ },
1328
+ },
1329
+ },
1330
+ valid: false,
1331
+ size: 0,
1332
+ },
1333
+ {
1334
+ value: {
1335
+ mySymbol: Symbol('MySymbol'),
1336
+ },
1337
+ valid: false,
1338
+ size: 0,
1339
+ },
1340
+ {
1341
+ value: [
1342
+ function () {
1343
+ return 'whatever';
1344
+ },
1345
+ ],
1346
+ valid: false,
1347
+ size: 0,
1348
+ },
1349
+ // These tests are taken from ECMA TC39 (test262) test scenarios used for
1350
+ // testing the `JSON.stringify` function.
1351
+ // https://github.com/tc39/test262/tree/main/test/built-ins/JSON/stringify
1352
+ /* eslint-disable no-new-wrappers */
1353
+ {
1354
+ value: new Boolean(true),
1355
+ valid: true,
1356
+ size: 4,
1357
+ },
1358
+ {
1359
+ value: { key: new Boolean(false) },
1360
+ valid: true,
1361
+ size: 13,
1362
+ },
1363
+ {
1364
+ value: new Boolean(false),
1365
+ valid: true,
1366
+ size: 5,
1367
+ },
1368
+ {
1369
+ value: new Number(3.14),
1370
+ valid: true,
1371
+ size: 4,
1372
+ },
1373
+ {
1374
+ value: new String('str'),
1375
+ valid: true,
1376
+ size: 5,
1377
+ },
1378
+ /* eslint-enable no-new-wrappers */
1379
+ {
1380
+ value: -0,
1381
+ valid: true,
1382
+ size: 1,
1383
+ },
1384
+ {
1385
+ value: ['-0', 0, -0],
1386
+ valid: true,
1387
+ size: 10,
1388
+ },
1389
+ {
1390
+ value: { key: -0 },
1391
+ valid: true,
1392
+ size: 9,
1393
+ },
1394
+ {
1395
+ value: Infinity,
1396
+ valid: false,
1397
+ size: 0,
1398
+ },
1399
+ {
1400
+ value: { key: -Infinity },
1401
+ valid: false,
1402
+ size: 0,
1403
+ },
1404
+ {
1405
+ value: exports.CHARACTER_MAP,
1406
+ valid: true,
1407
+ size: 593,
1408
+ },
1409
+ {
1410
+ value: Object.keys(exports.CHARACTER_MAP).join(''),
1411
+ valid: true,
1412
+ size: 178,
1413
+ },
1414
+ {
1415
+ value: Object.keys(exports.CHARACTER_MAP).reverse().join(''),
1416
+ valid: true,
1417
+ size: 178,
1418
+ },
1419
+ {
1420
+ value: Object.values(exports.CHARACTER_MAP).join(''),
1421
+ valid: true,
1422
+ size: 214,
1423
+ },
1424
+ {
1425
+ value: Object.values(exports.CHARACTER_MAP).reverse().join(''),
1426
+ valid: true,
1427
+ size: 214,
1428
+ },
1429
+ {
1430
+ value: {
1431
+ toJSON: null,
1432
+ },
1433
+ valid: true,
1434
+ size: 15,
1435
+ },
1436
+ {
1437
+ value: { toJSON: false },
1438
+ valid: true,
1439
+ size: 16,
1440
+ },
1441
+ {
1442
+ value: { toJSON: [] },
1443
+ valid: true,
1444
+ size: 13,
1445
+ },
1446
+ {
1447
+ value: DUPLICATE_REFERENCE,
1448
+ valid: true,
1449
+ size: 552,
1450
+ },
1451
+ {
1452
+ value: { a: { b: REVOKED_OBJECT_PROXY.proxy } },
1453
+ valid: false,
1454
+ size: 0,
1455
+ },
1456
+ {
1457
+ value: {
1458
+ get key() {
1459
+ throw new Error();
1460
+ },
1461
+ },
1462
+ valid: false,
1463
+ size: 0,
1464
+ },
1465
+ {
1466
+ value: undefined,
1467
+ valid: false,
1468
+ size: 0,
1469
+ },
1470
+ {
1471
+ value: DIRECT_CIRCULAR_REFERENCE_ARRAY,
1472
+ valid: false,
1473
+ size: 0,
1474
+ },
1475
+ {
1476
+ value: INDIRECT_CIRCULAR_REFERENCE_ARRAY,
1477
+ valid: false,
1478
+ size: 0,
1479
+ },
1480
+ {
1481
+ value: DIRECT_CIRCULAR_REFERENCE_OBJECT,
1482
+ valid: false,
1483
+ size: 0,
1484
+ },
1485
+ {
1486
+ value: INDIRECT_CIRCULAR_REFERENCE_OBJECT,
1487
+ valid: false,
1488
+ size: 0,
1489
+ },
1490
+ ];
1491
+ //# sourceMappingURL=json.js.map