@evergis/common 1.0.4-alpha.1 → 1.0.4-alpha.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.
- package/dist/classification/ClientStyleValidator/ClientStyleValidator.d.ts +3 -0
- package/dist/common.esm.js +119 -241
- package/dist/common.esm.js.map +1 -1
- package/dist/index.js +119 -241
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -371,7 +371,7 @@ class ClientStyleValidator {
|
|
|
371
371
|
errors: [
|
|
372
372
|
{
|
|
373
373
|
path: `item[${noPaintItemIndex}]`,
|
|
374
|
-
message: "The `paint` prop is
|
|
374
|
+
message: "The `paint` prop is required",
|
|
375
375
|
},
|
|
376
376
|
],
|
|
377
377
|
};
|
|
@@ -406,9 +406,9 @@ class ClientStyleValidator {
|
|
|
406
406
|
.every(e => typeof e === "string"));
|
|
407
407
|
}
|
|
408
408
|
isZoomInterpolate(value) {
|
|
409
|
-
return Array.isArray(value) && value[0] === "interpolate" &&
|
|
409
|
+
return Array.isArray(value) && value[0] === "interpolate" && lodash.isEqual(value[2], ["zoom"]);
|
|
410
410
|
}
|
|
411
|
-
validateSupportedConcatExpression(path, key, value
|
|
411
|
+
validateSupportedConcatExpression(path, key, value) {
|
|
412
412
|
const errorsCount = this.errors.length;
|
|
413
413
|
if (key !== "text-field") {
|
|
414
414
|
this.errors.push({
|
|
@@ -435,11 +435,9 @@ class ClientStyleValidator {
|
|
|
435
435
|
});
|
|
436
436
|
}
|
|
437
437
|
}
|
|
438
|
-
|
|
439
|
-
return this.errors.length === errorsCount;
|
|
440
|
-
}
|
|
438
|
+
return this.errors.length === errorsCount;
|
|
441
439
|
}
|
|
442
|
-
validateSupportedMatchExpression(path, key, value
|
|
440
|
+
validateSupportedMatchExpression(path, key, value) {
|
|
443
441
|
const errorsCount = this.errors.length;
|
|
444
442
|
if (!this.getSpecPropValueOptions(key)?.dataExpressionSupport) {
|
|
445
443
|
this.errors.push({
|
|
@@ -465,7 +463,7 @@ class ClientStyleValidator {
|
|
|
465
463
|
.slice(2)
|
|
466
464
|
.every(e => typeof e === "number" ||
|
|
467
465
|
typeof e === "string" ||
|
|
468
|
-
(key === "text-field" && this.validateSupportedConcatExpression(path, key, e
|
|
466
|
+
(key === "text-field" && this.validateSupportedConcatExpression(path, key, e)));
|
|
469
467
|
if (!result) {
|
|
470
468
|
this.errors.push({
|
|
471
469
|
path: `${path}.${key}`,
|
|
@@ -473,11 +471,9 @@ class ClientStyleValidator {
|
|
|
473
471
|
});
|
|
474
472
|
}
|
|
475
473
|
}
|
|
476
|
-
|
|
477
|
-
return this.errors.length === errorsCount;
|
|
478
|
-
}
|
|
474
|
+
return this.errors.length === errorsCount;
|
|
479
475
|
}
|
|
480
|
-
validateSupportedCaseExpression(path, key, value
|
|
476
|
+
validateSupportedCaseExpression(path, key, value) {
|
|
481
477
|
const errorsCount = this.errors.length;
|
|
482
478
|
if (!this.getSpecPropValueOptions(key)?.dataExpressionSupport) {
|
|
483
479
|
this.errors.push({
|
|
@@ -514,10 +510,10 @@ class ClientStyleValidator {
|
|
|
514
510
|
.filter((_, i) => i % 2 !== 0)
|
|
515
511
|
.every(e => typeof e === "number" ||
|
|
516
512
|
typeof e === "string" ||
|
|
517
|
-
(key === "text-field" && this.validateSupportedConcatExpression(path, key, e
|
|
513
|
+
(key === "text-field" && this.validateSupportedConcatExpression(path, key, e))) &&
|
|
518
514
|
(typeof value[value.slice(1).length - 1] === "number" ||
|
|
519
515
|
typeof value[value.slice(1).length - 1] === "string" ||
|
|
520
|
-
(key === "text-field" && this.validateSupportedConcatExpression(path, key, value
|
|
516
|
+
(key === "text-field" && this.validateSupportedConcatExpression(path, key, value)));
|
|
521
517
|
if (!result) {
|
|
522
518
|
this.errors.push({
|
|
523
519
|
path: `${path}.${key}`,
|
|
@@ -525,11 +521,9 @@ class ClientStyleValidator {
|
|
|
525
521
|
});
|
|
526
522
|
}
|
|
527
523
|
}
|
|
528
|
-
|
|
529
|
-
return this.errors.length === errorsCount;
|
|
530
|
-
}
|
|
524
|
+
return this.errors.length === errorsCount;
|
|
531
525
|
}
|
|
532
|
-
validateSupportedStepExpression(path, key, value
|
|
526
|
+
validateSupportedStepExpression(path, key, value) {
|
|
533
527
|
const errorsCount = this.errors.length;
|
|
534
528
|
if (!this.getSpecPropValueOptions(key)?.dataExpressionSupport) {
|
|
535
529
|
this.errors.push({
|
|
@@ -556,7 +550,7 @@ class ClientStyleValidator {
|
|
|
556
550
|
.filter((_, i) => i % 2 === 0)
|
|
557
551
|
.every(e => typeof e === "number" ||
|
|
558
552
|
typeof e === "string" ||
|
|
559
|
-
(key === "text-field" && this.validateSupportedConcatExpression(path, key, e
|
|
553
|
+
(key === "text-field" && this.validateSupportedConcatExpression(path, key, e))) &&
|
|
560
554
|
value
|
|
561
555
|
.slice(2)
|
|
562
556
|
.filter((_, i) => i % 2 !== 0)
|
|
@@ -568,251 +562,138 @@ class ClientStyleValidator {
|
|
|
568
562
|
});
|
|
569
563
|
}
|
|
570
564
|
}
|
|
571
|
-
|
|
572
|
-
return this.errors.length === errorsCount;
|
|
573
|
-
}
|
|
565
|
+
return this.errors.length === errorsCount;
|
|
574
566
|
}
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
567
|
+
validateInterpolateInputs(value) {
|
|
568
|
+
return value
|
|
569
|
+
.slice(3)
|
|
570
|
+
.filter((_, i) => i % 2 === 0)
|
|
571
|
+
.every(e => typeof e === "number");
|
|
572
|
+
}
|
|
573
|
+
validateZoomInterpolateConsistency(path, key, value) {
|
|
574
|
+
return (this.validateInterpolateInputs(value) &&
|
|
580
575
|
lodash.isEqual(value[2], ["zoom"]) &&
|
|
581
576
|
value.length % 2 !== 0 &&
|
|
582
577
|
value.length > 4 &&
|
|
583
|
-
value
|
|
584
|
-
.slice(3)
|
|
585
|
-
.filter((_, i) => i % 2 === 0)
|
|
586
|
-
.every(e => typeof e === "number") &&
|
|
587
578
|
value
|
|
588
579
|
.slice(3)
|
|
589
580
|
.filter((_, i) => i % 2 !== 0)
|
|
590
581
|
.every(e => {
|
|
591
582
|
return (typeof e === "number" ||
|
|
592
583
|
typeof e === "string" ||
|
|
593
|
-
this.validateSupportedExpression(path, key, e, true
|
|
594
|
-
(key === "text-field" && this.validateSupportedConcatExpression(path, key, e
|
|
584
|
+
this.validateSupportedExpression(path, key, e, true) ||
|
|
585
|
+
(key === "text-field" && this.validateSupportedConcatExpression(path, key, e)));
|
|
595
586
|
}));
|
|
596
|
-
if (!result) {
|
|
597
|
-
this.errors.push({
|
|
598
|
-
path: `${path}.${key}`,
|
|
599
|
-
message: "Invalid expression",
|
|
600
|
-
});
|
|
601
|
-
}
|
|
602
|
-
if (returnStatus) {
|
|
603
|
-
return this.errors.length === errorsCount;
|
|
604
|
-
}
|
|
605
587
|
}
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
588
|
+
validateLinearZoomInterpolate(path, key, value) {
|
|
589
|
+
return (this.getSpecPropValueOptions(key)?.interpolateExpressionSupport &&
|
|
590
|
+
lodash.isEqual(value[0], "interpolate") &&
|
|
591
|
+
lodash.isEqual(value[1], ["linear"]) &&
|
|
592
|
+
this.validateZoomInterpolateConsistency(path, key, value));
|
|
593
|
+
}
|
|
594
|
+
validateExponentialZoomInterpolate(path, key, value) {
|
|
595
|
+
return (this.getSpecPropValueOptions(key)?.interpolateExpressionSupport &&
|
|
609
596
|
lodash.isEqual(value[0], "interpolate") &&
|
|
610
597
|
Array.isArray(value[1]) &&
|
|
611
598
|
value[1].length === 2 &&
|
|
612
599
|
value[1][0] === "exponential" &&
|
|
613
600
|
typeof value[1][1] === "number" &&
|
|
614
|
-
|
|
615
|
-
value.length % 2 !== 0 &&
|
|
616
|
-
value.length > 4 &&
|
|
617
|
-
value
|
|
618
|
-
.slice(3)
|
|
619
|
-
.filter((_, i) => i % 2 === 0)
|
|
620
|
-
.every(e => typeof e === "number") &&
|
|
621
|
-
value
|
|
622
|
-
.slice(3)
|
|
623
|
-
.filter((_, i) => i % 2 !== 0)
|
|
624
|
-
.every(e => {
|
|
625
|
-
return (typeof e === "number" ||
|
|
626
|
-
typeof e === "string" ||
|
|
627
|
-
this.validateSupportedExpression(path, key, e, true, true) ||
|
|
628
|
-
(key === "text-field" && this.validateSupportedConcatExpression(path, key, e, true)));
|
|
629
|
-
}));
|
|
630
|
-
if (!result) {
|
|
631
|
-
this.errors.push({
|
|
632
|
-
path: `${path}.${key}`,
|
|
633
|
-
message: "Invalid expression",
|
|
634
|
-
});
|
|
635
|
-
}
|
|
636
|
-
if (returnStatus) {
|
|
637
|
-
return this.errors.length === errorsCount;
|
|
638
|
-
}
|
|
601
|
+
this.validateZoomInterpolateConsistency(path, key, value));
|
|
639
602
|
}
|
|
640
|
-
validateCubicBezierZoomInterpolate(path, key, value
|
|
641
|
-
|
|
642
|
-
const result = (this.getSpecPropValueOptions(key)?.interpolateExpressionSupport &&
|
|
603
|
+
validateCubicBezierZoomInterpolate(path, key, value) {
|
|
604
|
+
return (this.getSpecPropValueOptions(key)?.interpolateExpressionSupport &&
|
|
643
605
|
lodash.isEqual(value[0], "interpolate") &&
|
|
644
606
|
Array.isArray(value[1]) &&
|
|
645
607
|
value[1].length === 5 &&
|
|
646
608
|
value[1][0] === "cubic-bezier" &&
|
|
647
609
|
value[1].slice(1).every(e => typeof e === "number") &&
|
|
648
|
-
|
|
649
|
-
value.length % 2 !== 0 &&
|
|
650
|
-
value.length > 4 &&
|
|
651
|
-
value
|
|
652
|
-
.slice(3)
|
|
653
|
-
.filter((_, i) => i % 2 === 0)
|
|
654
|
-
.every(e => typeof e === "number") &&
|
|
655
|
-
value
|
|
656
|
-
.slice(3)
|
|
657
|
-
.filter((_, i) => i % 2 !== 0)
|
|
658
|
-
.every(e => {
|
|
659
|
-
return (typeof e === "number" ||
|
|
660
|
-
typeof e === "string" ||
|
|
661
|
-
this.validateSupportedExpression(path, key, e, true, true) ||
|
|
662
|
-
(key === "text-field" && this.validateSupportedConcatExpression(path, key, e, true)));
|
|
663
|
-
}));
|
|
664
|
-
if (!result) {
|
|
665
|
-
this.errors.push({
|
|
666
|
-
path: `${path}.${key}`,
|
|
667
|
-
message: "Invalid expression",
|
|
668
|
-
});
|
|
669
|
-
}
|
|
670
|
-
if (returnStatus) {
|
|
671
|
-
return this.errors.length === errorsCount;
|
|
672
|
-
}
|
|
610
|
+
this.validateZoomInterpolateConsistency(path, key, value));
|
|
673
611
|
}
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
const result = (this.getSpecPropValueOptions(key)?.dataExpressionSupport &&
|
|
677
|
-
lodash.isEqual(value[0], "interpolate") &&
|
|
678
|
-
lodash.isEqual(value[1], ["linear"]) &&
|
|
612
|
+
validateDataInterpolateConsistency(path, key, value) {
|
|
613
|
+
return (this.validateInterpolateInputs(value) &&
|
|
679
614
|
Array.isArray(value[2]) &&
|
|
680
615
|
value[2].length === 2 &&
|
|
681
616
|
value[2][0] === "get" &&
|
|
682
617
|
typeof value[2][1] === "string" &&
|
|
683
618
|
value.length % 2 !== 0 &&
|
|
684
619
|
value.length > 4 &&
|
|
685
|
-
value
|
|
686
|
-
.slice(3)
|
|
687
|
-
.filter((_, i) => i % 2 === 0)
|
|
688
|
-
.every(e => typeof e === "number") &&
|
|
689
620
|
value
|
|
690
621
|
.slice(3)
|
|
691
622
|
.filter((_, i) => i % 2 !== 0)
|
|
692
623
|
.every(e => typeof e === "number" ||
|
|
693
624
|
typeof e === "string" ||
|
|
694
|
-
(key === "text-field" && this.validateSupportedConcatExpression(path, key, e
|
|
695
|
-
if (!result) {
|
|
696
|
-
this.errors.push({
|
|
697
|
-
path: `${path}.${key}`,
|
|
698
|
-
message: "Invalid expression",
|
|
699
|
-
});
|
|
700
|
-
}
|
|
701
|
-
if (returnStatus) {
|
|
702
|
-
return this.errors.length === errorsCount;
|
|
703
|
-
}
|
|
625
|
+
(key === "text-field" && this.validateSupportedConcatExpression(path, key, e))));
|
|
704
626
|
}
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
627
|
+
validateLinearDataInterpolate(path, key, value) {
|
|
628
|
+
return (this.getSpecPropValueOptions(key)?.dataExpressionSupport &&
|
|
629
|
+
lodash.isEqual(value[0], "interpolate") &&
|
|
630
|
+
lodash.isEqual(value[1], ["linear"]) &&
|
|
631
|
+
this.validateDataInterpolateConsistency(path, key, value));
|
|
632
|
+
}
|
|
633
|
+
validateExponentialDataInterpolate(path, key, value) {
|
|
634
|
+
return (this.getSpecPropValueOptions(key)?.dataExpressionSupport &&
|
|
708
635
|
lodash.isEqual(value[0], "interpolate") &&
|
|
709
636
|
Array.isArray(value[1]) &&
|
|
710
637
|
value[1].length === 2 &&
|
|
711
638
|
value[1][0] === "exponential" &&
|
|
712
639
|
typeof value[1][1] === "number" &&
|
|
713
|
-
|
|
714
|
-
value[2].length === 2 &&
|
|
715
|
-
value[2][0] === "get" &&
|
|
716
|
-
typeof value[2][1] === "string" &&
|
|
717
|
-
value.length % 2 !== 0 &&
|
|
718
|
-
value.length > 4 &&
|
|
719
|
-
value
|
|
720
|
-
.slice(3)
|
|
721
|
-
.filter((_, i) => i % 2 === 0)
|
|
722
|
-
.every(e => typeof e === "number") &&
|
|
723
|
-
value
|
|
724
|
-
.slice(3)
|
|
725
|
-
.filter((_, i) => i % 2 !== 0)
|
|
726
|
-
.every(e => typeof e === "number" ||
|
|
727
|
-
typeof e === "string" ||
|
|
728
|
-
(key === "text-field" && this.validateSupportedConcatExpression(path, key, e, true))));
|
|
729
|
-
if (!result) {
|
|
730
|
-
this.errors.push({
|
|
731
|
-
path: `${path}.${key}`,
|
|
732
|
-
message: "Invalid expression",
|
|
733
|
-
});
|
|
734
|
-
}
|
|
735
|
-
if (returnStatus) {
|
|
736
|
-
return this.errors.length === errorsCount;
|
|
737
|
-
}
|
|
640
|
+
this.validateDataInterpolateConsistency(path, key, value));
|
|
738
641
|
}
|
|
739
|
-
validateCubicBezierDataInterpolate(path, key, value
|
|
740
|
-
|
|
741
|
-
const result = (this.getSpecPropValueOptions(key)?.dataExpressionSupport &&
|
|
642
|
+
validateCubicBezierDataInterpolate(path, key, value) {
|
|
643
|
+
return (this.getSpecPropValueOptions(key)?.dataExpressionSupport &&
|
|
742
644
|
lodash.isEqual(value[0], "interpolate") &&
|
|
743
645
|
Array.isArray(value[1]) &&
|
|
744
646
|
value[1].length === 5 &&
|
|
745
647
|
value[1][0] === "cubic-bezier" &&
|
|
746
648
|
value[1].slice(1).every(e => typeof e === "number") &&
|
|
747
|
-
|
|
748
|
-
value[2].length === 2 &&
|
|
749
|
-
value[2][0] === "get" &&
|
|
750
|
-
typeof value[2][1] === "string" &&
|
|
751
|
-
value.length % 2 !== 0 &&
|
|
752
|
-
value.length > 4 &&
|
|
753
|
-
value
|
|
754
|
-
.slice(3)
|
|
755
|
-
.filter((_, i) => i % 2 === 0)
|
|
756
|
-
.every(e => typeof e === "number") &&
|
|
757
|
-
value
|
|
758
|
-
.slice(3)
|
|
759
|
-
.filter((_, i) => i % 2 !== 0)
|
|
760
|
-
.every(e => typeof e === "number" ||
|
|
761
|
-
typeof e === "string" ||
|
|
762
|
-
(key === "text-field" && this.validateSupportedConcatExpression(path, key, e, true))));
|
|
763
|
-
if (!result) {
|
|
764
|
-
this.errors.push({
|
|
765
|
-
path: `${path}.${key}`,
|
|
766
|
-
message: "Invalid expression",
|
|
767
|
-
});
|
|
768
|
-
}
|
|
769
|
-
if (returnStatus) {
|
|
770
|
-
return this.errors.length === errorsCount;
|
|
771
|
-
}
|
|
649
|
+
this.validateDataInterpolateConsistency(path, key, value));
|
|
772
650
|
}
|
|
773
651
|
validateZoomInterpolate(path, key, value) {
|
|
774
652
|
const isAllowedInterpolate = this.getSpecPropValueOptions(key)?.interpolateExpressionSupport && lodash.isEqual(value[0], "interpolate");
|
|
775
|
-
if (isAllowedInterpolate
|
|
653
|
+
if (!isAllowedInterpolate) {
|
|
654
|
+
return;
|
|
655
|
+
}
|
|
656
|
+
if (lodash.isEqual(value[1], ["linear"])) {
|
|
776
657
|
this.validateLinearZoomInterpolate(path, key, value);
|
|
777
658
|
}
|
|
778
|
-
|
|
659
|
+
if (lodash.isEqual(value[1], ["exponential"])) {
|
|
779
660
|
this.validateExponentialZoomInterpolate(path, key, value);
|
|
780
661
|
}
|
|
781
|
-
|
|
662
|
+
if (lodash.isEqual(value[1], ["cubic-bezier"])) {
|
|
782
663
|
this.validateCubicBezierZoomInterpolate(path, key, value);
|
|
783
664
|
}
|
|
784
665
|
}
|
|
785
666
|
validateDataInterpolate(path, key, value) {
|
|
786
667
|
const isAllowedInterpolate = this.getSpecPropValueOptions(key)?.dataExpressionSupport && lodash.isEqual(value[0], "interpolate");
|
|
787
|
-
if (isAllowedInterpolate
|
|
668
|
+
if (!isAllowedInterpolate) {
|
|
669
|
+
return;
|
|
670
|
+
}
|
|
671
|
+
if (lodash.isEqual(value[1], ["linear"])) {
|
|
788
672
|
this.validateLinearDataInterpolate(path, key, value);
|
|
789
673
|
}
|
|
790
|
-
|
|
674
|
+
if (lodash.isEqual(value[1], ["exponential"])) {
|
|
791
675
|
this.validateExponentialDataInterpolate(path, key, value);
|
|
792
676
|
}
|
|
793
|
-
|
|
677
|
+
if (lodash.isEqual(value[1], ["cubic-bezier"])) {
|
|
794
678
|
this.validateCubicBezierDataInterpolate(path, key, value);
|
|
795
679
|
}
|
|
796
680
|
}
|
|
797
|
-
validateSupportedInterpolateExpression(path, key, value, excludeZoomInterpolate
|
|
681
|
+
validateSupportedInterpolateExpression(path, key, value, excludeZoomInterpolate) {
|
|
798
682
|
const errorsCount = this.errors.length;
|
|
683
|
+
const propValueOptions = this.getSpecPropValueOptions(key);
|
|
799
684
|
if (!mapboxGlStyleSpec.expression.isExpression(value)) {
|
|
800
685
|
this.errors.push({
|
|
801
686
|
path: `${path}.${key}`,
|
|
802
687
|
message: "Not an expression",
|
|
803
688
|
});
|
|
804
689
|
}
|
|
805
|
-
else if (key === "heatmap-color") {
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
message: "Invalid color value",
|
|
811
|
-
});
|
|
812
|
-
}
|
|
690
|
+
else if (key === "heatmap-color" && !this.isHeatmapColorValid(value)) {
|
|
691
|
+
this.errors.push({
|
|
692
|
+
path: `${path}.${key}`,
|
|
693
|
+
message: "Invalid color value",
|
|
694
|
+
});
|
|
813
695
|
}
|
|
814
|
-
else if (!
|
|
815
|
-
!this.getSpecPropValueOptions(key)?.dataExpressionSupport) {
|
|
696
|
+
else if (!propValueOptions?.interpolateExpressionSupport && !propValueOptions?.dataExpressionSupport) {
|
|
816
697
|
this.errors.push({
|
|
817
698
|
path: `${path}.${key}`,
|
|
818
699
|
message: "Interpolate not supported",
|
|
@@ -824,11 +705,9 @@ class ClientStyleValidator {
|
|
|
824
705
|
else {
|
|
825
706
|
this.validateDataInterpolate(path, key, value);
|
|
826
707
|
}
|
|
827
|
-
|
|
828
|
-
return this.errors.length === errorsCount;
|
|
829
|
-
}
|
|
708
|
+
return this.errors.length === errorsCount;
|
|
830
709
|
}
|
|
831
|
-
validateSupportedExpression(path, key, value, excludeZoomInterpolate
|
|
710
|
+
validateSupportedExpression(path, key, value, excludeZoomInterpolate) {
|
|
832
711
|
const errorsCount = this.errors.length;
|
|
833
712
|
if (!mapboxGlStyleSpec.expression.isExpression(value)) {
|
|
834
713
|
this.errors.push({
|
|
@@ -838,8 +717,7 @@ class ClientStyleValidator {
|
|
|
838
717
|
}
|
|
839
718
|
else {
|
|
840
719
|
const expressionType = value[0];
|
|
841
|
-
if (typeof expressionType !== "string" ||
|
|
842
|
-
!["match", "case", "step", "interpolate", "concat"].includes(expressionType)) {
|
|
720
|
+
if (typeof expressionType !== "string" || !["match", "case", "step", "interpolate", "concat"].includes(expressionType)) {
|
|
843
721
|
this.errors.push({
|
|
844
722
|
path: `${path}.${key}`,
|
|
845
723
|
message: "Expression type not supported (supported types: \"match\", \"case\", \"step\", \"interpolate\", \"concat\")",
|
|
@@ -865,11 +743,9 @@ class ClientStyleValidator {
|
|
|
865
743
|
}
|
|
866
744
|
}
|
|
867
745
|
}
|
|
868
|
-
|
|
869
|
-
return this.errors.length === errorsCount;
|
|
870
|
-
}
|
|
746
|
+
return this.errors.length === errorsCount;
|
|
871
747
|
}
|
|
872
|
-
validateTransitionValue(path, key, value
|
|
748
|
+
validateTransitionValue(path, key, value) {
|
|
873
749
|
const errorsCount = this.errors.length;
|
|
874
750
|
const propValueOptions = this.getSpecPropValueOptions(key.replace(/-transition$/, ""));
|
|
875
751
|
if (propValueOptions && propValueOptions.transitionable === false) {
|
|
@@ -889,60 +765,62 @@ class ClientStyleValidator {
|
|
|
889
765
|
});
|
|
890
766
|
}
|
|
891
767
|
}
|
|
892
|
-
|
|
893
|
-
return this.errors.length === errorsCount;
|
|
894
|
-
}
|
|
768
|
+
return this.errors.length === errorsCount;
|
|
895
769
|
}
|
|
896
770
|
validateSpecPropValue(path, key, value) {
|
|
897
771
|
if (key.endsWith("-transition")) {
|
|
898
772
|
this.validateTransitionValue(path, key, value);
|
|
773
|
+
return;
|
|
774
|
+
}
|
|
775
|
+
const propValueOptions = this.getSpecPropValueOptions(key);
|
|
776
|
+
const isExpression = mapboxGlStyleSpec.expression.isExpression(value);
|
|
777
|
+
if (!propValueOptions) {
|
|
778
|
+
const result = (typeof value === "string" ||
|
|
779
|
+
typeof value === "number" ||
|
|
780
|
+
typeof value === "boolean" ||
|
|
781
|
+
(Array.isArray(value) && value.every(item => typeof item === "number")) ||
|
|
782
|
+
(Array.isArray(value) && value.every(item => typeof item === "string")) ||
|
|
783
|
+
isExpression);
|
|
784
|
+
if (!result) {
|
|
785
|
+
this.errors.push({
|
|
786
|
+
path: `${path}.${key}`,
|
|
787
|
+
message: "Invalid value",
|
|
788
|
+
});
|
|
789
|
+
}
|
|
790
|
+
return;
|
|
899
791
|
}
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
typeof value === "number" ||
|
|
905
|
-
typeof value === "boolean" ||
|
|
906
|
-
(Array.isArray(value) && value.every(item => typeof item === "number")) ||
|
|
907
|
-
(Array.isArray(value) && value.every(item => typeof item === "string")) ||
|
|
908
|
-
mapboxGlStyleSpec.expression.isExpression(value));
|
|
792
|
+
if (propValueOptions.arrayValue) {
|
|
793
|
+
if (!propValueOptions.arrayOnly) {
|
|
794
|
+
const result = (typeof value === propValueOptions.valueTypeAllowed ||
|
|
795
|
+
(Array.isArray(value) && value.every(item => typeof item === propValueOptions.valueTypeAllowed)));
|
|
909
796
|
if (!result) {
|
|
910
797
|
this.errors.push({
|
|
911
798
|
path: `${path}.${key}`,
|
|
912
|
-
message:
|
|
799
|
+
message: `Only values of type ${propValueOptions.valueTypeAllowed} allowed`,
|
|
913
800
|
});
|
|
914
801
|
}
|
|
915
802
|
}
|
|
916
|
-
else
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
message: `Only values of type ${propValueOptions.valueTypeAllowed} allowed`,
|
|
924
|
-
});
|
|
925
|
-
}
|
|
926
|
-
}
|
|
927
|
-
else {
|
|
928
|
-
const result = Array.isArray(value) && value.every(item => typeof item === propValueOptions.valueTypeAllowed);
|
|
929
|
-
if (!result) {
|
|
930
|
-
this.errors.push({
|
|
931
|
-
path: `${path}.${key}`,
|
|
932
|
-
message: `Only array of values of type ${propValueOptions.valueTypeAllowed} allowed`,
|
|
933
|
-
});
|
|
934
|
-
}
|
|
803
|
+
else {
|
|
804
|
+
const result = Array.isArray(value) && value.every(item => typeof item === propValueOptions.valueTypeAllowed);
|
|
805
|
+
if (!result) {
|
|
806
|
+
this.errors.push({
|
|
807
|
+
path: `${path}.${key}`,
|
|
808
|
+
message: `Only array of values of type ${propValueOptions.valueTypeAllowed} allowed`,
|
|
809
|
+
});
|
|
935
810
|
}
|
|
936
811
|
}
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
812
|
+
return;
|
|
813
|
+
}
|
|
814
|
+
if (isExpression) {
|
|
815
|
+
this.validateSupportedExpression(path, key, value);
|
|
816
|
+
return;
|
|
817
|
+
}
|
|
818
|
+
if (typeof value !== propValueOptions.valueTypeAllowed) {
|
|
819
|
+
this.errors.push({
|
|
820
|
+
path: `${path}.${key}`,
|
|
821
|
+
message: "Invalid value type",
|
|
822
|
+
});
|
|
823
|
+
return;
|
|
946
824
|
}
|
|
947
825
|
}
|
|
948
826
|
}
|