@evergis/common 1.0.2 → 1.0.4-alpha.1

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/index.js CHANGED
@@ -63,6 +63,7 @@ const SPEC_PROP_VALUE_OPTIONS = {
63
63
  transitionable: true,
64
64
  valueTypeAllowed: "number",
65
65
  arrayValue: true,
66
+ arrayOnly: true,
66
67
  },
67
68
  // fill
68
69
  "fill-color": {
@@ -152,6 +153,7 @@ const SPEC_PROP_VALUE_OPTIONS = {
152
153
  transitionable: true,
153
154
  valueTypeAllowed: "number",
154
155
  arrayValue: true,
156
+ arrayOnly: true,
155
157
  },
156
158
  // icon
157
159
  "icon-image": {
@@ -184,6 +186,7 @@ const SPEC_PROP_VALUE_OPTIONS = {
184
186
  transitionable: true,
185
187
  valueTypeAllowed: "number",
186
188
  arrayValue: true,
189
+ arrayOnly: true,
187
190
  },
188
191
  "icon-halo-color": {
189
192
  dataExpressionSupport: true,
@@ -284,6 +287,7 @@ const SPEC_PROP_VALUE_OPTIONS = {
284
287
  transitionable: true,
285
288
  valueTypeAllowed: "number",
286
289
  arrayValue: true,
290
+ arrayOnly: true,
287
291
  },
288
292
  "text-halo-color": {
289
293
  dataExpressionSupport: true,
@@ -349,23 +353,38 @@ const SPEC_PROP_VALUE_OPTIONS = {
349
353
  },
350
354
  };
351
355
 
352
- /* eslint-disable max-lines, no-console, class-methods-use-this, @typescript-eslint/no-magic-numbers */
356
+ /* eslint-disable max-lines, class-methods-use-this, @typescript-eslint/no-magic-numbers */
353
357
  class ClientStyleValidator {
354
- options;
355
- constructor(options) {
356
- this.options = options || {};
358
+ errors;
359
+ constructor() {
360
+ this.errors = [];
357
361
  }
358
362
  validate(clientStyle) {
363
+ this.errors = [];
359
364
  if (lodash.isNil(clientStyle) || lodash.isEmpty(clientStyle) || lodash.isNil(clientStyle?.items) || lodash.isEmpty(clientStyle?.items)) {
360
- return true;
365
+ return { valid: true, errors: [] };
361
366
  }
362
- if (clientStyle.items.some(item => lodash.isNil(item.paint))) {
363
- if (this.options.verbose) {
364
- console.error("Validate client style:", "`paint` prop is mandatory", "\n");
365
- }
366
- return false;
367
+ const noPaintItemIndex = clientStyle.items.findIndex(item => lodash.isNil(item.paint));
368
+ if (noPaintItemIndex > -1) {
369
+ return {
370
+ valid: false,
371
+ errors: [
372
+ {
373
+ path: `item[${noPaintItemIndex}]`,
374
+ message: "The `paint` prop is mandatory",
375
+ },
376
+ ],
377
+ };
367
378
  }
368
- return clientStyle.items.every(item => Object.entries({ ...item.layout, ...item.paint }).every(([key, value]) => this.validateSpecPropValue(key, value)));
379
+ clientStyle.items.forEach((item, itemIndex) => {
380
+ Object.entries({ ...item.layout }).forEach(([key, value]) => {
381
+ this.validateSpecPropValue(`item[${itemIndex}].layout`, key, value);
382
+ });
383
+ Object.entries({ ...item.paint }).forEach(([key, value]) => {
384
+ this.validateSpecPropValue(`item[${itemIndex}].paint`, key, value);
385
+ });
386
+ });
387
+ return { valid: this.errors.length === 0, errors: this.errors };
369
388
  }
370
389
  getSpecPropValueOptions(key) {
371
390
  return SPEC_PROP_VALUE_OPTIONS[key];
@@ -389,148 +408,173 @@ class ClientStyleValidator {
389
408
  isZoomInterpolate(value) {
390
409
  return Array.isArray(value) && value[0] === "interpolate" && Array.isArray(value[2]) && value[2][0] === "zoom";
391
410
  }
392
- validateSupportedConcatExpression(key, value) {
411
+ validateSupportedConcatExpression(path, key, value, returnStatus) {
412
+ const errorsCount = this.errors.length;
393
413
  if (key !== "text-field") {
394
- if (this.options.verbose) {
395
- console.error("Validate supported concat expression:", "supported only for `text-field`", key, value, "\n");
396
- }
397
- return false;
414
+ this.errors.push({
415
+ path: `${path}.${key}`,
416
+ message: "Supported only for \`text-field\`",
417
+ });
398
418
  }
399
- if (!mapboxGlStyleSpec.expression.isExpression(value)) {
400
- if (this.options.verbose) {
401
- console.error("Validate supported concat expression:", "not an expression", key, value, "\n");
402
- }
403
- return false;
419
+ else if (!mapboxGlStyleSpec.expression.isExpression(value)) {
420
+ this.errors.push({
421
+ path: `${path}.${key}`,
422
+ message: "Not an expression",
423
+ });
404
424
  }
405
- const result = value[0] === "concat" &&
406
- value.length > 2 &&
407
- value
408
- .slice(1)
409
- .every(i => typeof i === "string" || (Array.isArray(i) && i[0] === "get" && typeof i[1] === "string"));
410
- if (!result) {
411
- if (this.options.verbose) {
412
- console.error("Validate supported concat expression:", "invalid expression", key, value, "\n");
425
+ else {
426
+ const result = value[0] === "concat" &&
427
+ value.length > 2 &&
428
+ value
429
+ .slice(1)
430
+ .every(i => typeof i === "string" || (Array.isArray(i) && i[0] === "get" && typeof i[1] === "string"));
431
+ if (!result) {
432
+ this.errors.push({
433
+ path: `${path}.${key}`,
434
+ message: "Invalid expression",
435
+ });
413
436
  }
414
437
  }
415
- return result;
438
+ if (returnStatus) {
439
+ return this.errors.length === errorsCount;
440
+ }
416
441
  }
417
- validateSupportedMatchExpression(key, value) {
442
+ validateSupportedMatchExpression(path, key, value, returnStatus) {
443
+ const errorsCount = this.errors.length;
418
444
  if (!this.getSpecPropValueOptions(key)?.dataExpressionSupport) {
419
- if (this.options.verbose) {
420
- console.error("Validate supported match expression:", "expression not supported", key, value, "\n");
421
- }
422
- return false;
445
+ this.errors.push({
446
+ path: `${path}.${key}`,
447
+ message: "Expression not supported",
448
+ });
423
449
  }
424
- if (!mapboxGlStyleSpec.expression.isExpression(value)) {
425
- if (this.options.verbose) {
426
- console.error("Validate supported match expression:", "not an expression", key, value, "\n");
427
- }
428
- return false;
450
+ else if (!mapboxGlStyleSpec.expression.isExpression(value)) {
451
+ this.errors.push({
452
+ path: `${path}.${key}`,
453
+ message: "Not an expression",
454
+ });
429
455
  }
430
- const result = value[0] === "match" &&
431
- Array.isArray(value[1]) &&
432
- value[1].length === 2 &&
433
- value[1][0] === "get" &&
434
- typeof value[1][1] === "string" &&
435
- value.length > 3 &&
436
- value.length % 2 !== 0 &&
437
- value
438
- .slice(2)
439
- .every(e => typeof e === "number" ||
440
- typeof e === "string" ||
441
- (key === "text-field" && this.validateSupportedConcatExpression(key, e)));
442
- if (!result) {
443
- if (this.options.verbose) {
444
- console.error("Validate supported match expression:", "invalid expression", key, value, "\n");
456
+ else {
457
+ const result = value[0] === "match" &&
458
+ Array.isArray(value[1]) &&
459
+ value[1].length === 2 &&
460
+ value[1][0] === "get" &&
461
+ typeof value[1][1] === "string" &&
462
+ value.length > 3 &&
463
+ value.length % 2 !== 0 &&
464
+ value
465
+ .slice(2)
466
+ .every(e => typeof e === "number" ||
467
+ typeof e === "string" ||
468
+ (key === "text-field" && this.validateSupportedConcatExpression(path, key, e, true)));
469
+ if (!result) {
470
+ this.errors.push({
471
+ path: `${path}.${key}`,
472
+ message: "Invalid expression",
473
+ });
445
474
  }
446
475
  }
447
- return result;
476
+ if (returnStatus) {
477
+ return this.errors.length === errorsCount;
478
+ }
448
479
  }
449
- validateSupportedCaseExpression(key, value) {
480
+ validateSupportedCaseExpression(path, key, value, returnStatus) {
481
+ const errorsCount = this.errors.length;
450
482
  if (!this.getSpecPropValueOptions(key)?.dataExpressionSupport) {
451
- if (this.options.verbose) {
452
- console.error("Validate supported case expression:", "expression not supported", key, value, "\n");
453
- }
454
- return false;
483
+ this.errors.push({
484
+ path: `${path}.${key}`,
485
+ message: "Expression not supported",
486
+ });
455
487
  }
456
- if (!mapboxGlStyleSpec.expression.isExpression(value)) {
457
- if (this.options.verbose) {
458
- console.error("Validate supported case expression:", "not an expression", key, value, "\n");
459
- }
460
- return false;
488
+ else if (!mapboxGlStyleSpec.expression.isExpression(value)) {
489
+ this.errors.push({
490
+ path: `${path}.${key}`,
491
+ message: "Not an expression",
492
+ });
461
493
  }
462
- const result = value[0] === "case" &&
463
- value.length > 3 &&
464
- value.length % 2 === 0 &&
465
- value
466
- .slice(1)
467
- .filter((_, i) => i % 2 === 0 && i < value.slice(1).length - 1)
468
- .every(e => Array.isArray(e) &&
469
- e[0] === "all" &&
470
- e.length > 1 &&
471
- e
494
+ else {
495
+ const result = value[0] === "case" &&
496
+ value.length > 3 &&
497
+ value.length % 2 === 0 &&
498
+ value
472
499
  .slice(1)
473
- .every(ce => Array.isArray(ce) &&
474
- ce.length === 3 &&
475
- [">=", ">", "<", "<="].includes(ce[0]) &&
476
- ce[1][0] === "get" &&
477
- typeof ce[1][1] === "string" &&
478
- typeof ce[2] === "number")) &&
479
- value
480
- .slice(1)
481
- .filter((_, i) => i % 2 !== 0)
482
- .every(e => typeof e === "number" ||
483
- typeof e === "string" ||
484
- (key === "text-field" && this.validateSupportedConcatExpression(key, e))) &&
485
- (typeof value[value.slice(1).length - 1] === "number" ||
486
- typeof value[value.slice(1).length - 1] === "string" ||
487
- (key === "text-field" && this.validateSupportedConcatExpression(key, value)));
488
- if (!result) {
489
- if (this.options.verbose) {
490
- console.error("Validate supported case expression:", "invalid expression", key, value, "\n");
500
+ .filter((_, i) => i % 2 === 0 && i < value.slice(1).length - 1)
501
+ .every(e => Array.isArray(e) &&
502
+ e[0] === "all" &&
503
+ e.length > 1 &&
504
+ e
505
+ .slice(1)
506
+ .every(ce => Array.isArray(ce) &&
507
+ ce.length === 3 &&
508
+ [">=", ">", "<", "<="].includes(ce[0]) &&
509
+ ce[1][0] === "get" &&
510
+ typeof ce[1][1] === "string" &&
511
+ typeof ce[2] === "number")) &&
512
+ value
513
+ .slice(1)
514
+ .filter((_, i) => i % 2 !== 0)
515
+ .every(e => typeof e === "number" ||
516
+ typeof e === "string" ||
517
+ (key === "text-field" && this.validateSupportedConcatExpression(path, key, e, true))) &&
518
+ (typeof value[value.slice(1).length - 1] === "number" ||
519
+ typeof value[value.slice(1).length - 1] === "string" ||
520
+ (key === "text-field" && this.validateSupportedConcatExpression(path, key, value, true)));
521
+ if (!result) {
522
+ this.errors.push({
523
+ path: `${path}.${key}`,
524
+ message: "Invalid expression",
525
+ });
491
526
  }
492
527
  }
493
- return result;
528
+ if (returnStatus) {
529
+ return this.errors.length === errorsCount;
530
+ }
494
531
  }
495
- validateSupportedStepExpression(key, value) {
532
+ validateSupportedStepExpression(path, key, value, returnStatus) {
533
+ const errorsCount = this.errors.length;
496
534
  if (!this.getSpecPropValueOptions(key)?.dataExpressionSupport) {
497
- if (this.options.verbose) {
498
- console.error("Validate supported step expression:", "expression not supported", key, value, "\n");
499
- }
500
- return false;
535
+ this.errors.push({
536
+ path: `${path}.${key}`,
537
+ message: "Expression not supported",
538
+ });
501
539
  }
502
- if (!mapboxGlStyleSpec.expression.isExpression(value)) {
503
- if (this.options.verbose) {
504
- console.error("Validate supported step expression:", "not an expression", key, value, "\n");
505
- }
506
- return false;
540
+ else if (!mapboxGlStyleSpec.expression.isExpression(value)) {
541
+ this.errors.push({
542
+ path: `${path}.${key}`,
543
+ message: "Not an expression",
544
+ });
507
545
  }
508
- const result = value[0] === "step" &&
509
- Array.isArray(value[1]) &&
510
- value[1].length === 2 &&
511
- value[1][0] === "get" &&
512
- typeof value[1][1] === "string" &&
513
- value.length > 3 &&
514
- value.length % 2 !== 0 &&
515
- value
516
- .slice(2)
517
- .filter((_, i) => i % 2 === 0)
518
- .every(e => typeof e === "number" ||
519
- typeof e === "string" ||
520
- (key === "text-field" && this.validateSupportedConcatExpression(key, e))) &&
521
- value
522
- .slice(2)
523
- .filter((_, i) => i % 2 !== 0)
524
- .every(e => typeof e === "number");
525
- if (!result) {
526
- if (this.options.verbose) {
527
- console.error("Validate supported step expression:", "invalid expression", key, value, "\n");
546
+ else {
547
+ const result = value[0] === "step" &&
548
+ Array.isArray(value[1]) &&
549
+ value[1].length === 2 &&
550
+ value[1][0] === "get" &&
551
+ typeof value[1][1] === "string" &&
552
+ value.length > 3 &&
553
+ value.length % 2 !== 0 &&
554
+ value
555
+ .slice(2)
556
+ .filter((_, i) => i % 2 === 0)
557
+ .every(e => typeof e === "number" ||
558
+ typeof e === "string" ||
559
+ (key === "text-field" && this.validateSupportedConcatExpression(path, key, e, true))) &&
560
+ value
561
+ .slice(2)
562
+ .filter((_, i) => i % 2 !== 0)
563
+ .every(e => typeof e === "number");
564
+ if (!result) {
565
+ this.errors.push({
566
+ path: `${path}.${key}`,
567
+ message: "Invalid expression",
568
+ });
528
569
  }
529
570
  }
530
- return result;
571
+ if (returnStatus) {
572
+ return this.errors.length === errorsCount;
573
+ }
531
574
  }
532
- validateLinearZoomInterpolate(key, value) {
533
- return (this.getSpecPropValueOptions(key)?.interpolateExpressionSupport &&
575
+ validateLinearZoomInterpolate(path, key, value, returnStatus) {
576
+ const errorsCount = this.errors.length;
577
+ const result = (this.getSpecPropValueOptions(key)?.interpolateExpressionSupport &&
534
578
  lodash.isEqual(value[0], "interpolate") &&
535
579
  lodash.isEqual(value[1], ["linear"]) &&
536
580
  lodash.isEqual(value[2], ["zoom"]) &&
@@ -546,12 +590,22 @@ class ClientStyleValidator {
546
590
  .every(e => {
547
591
  return (typeof e === "number" ||
548
592
  typeof e === "string" ||
549
- this.validateSupportedExpression(key, e, true) ||
550
- (key === "text-field" && this.validateSupportedConcatExpression(key, e)));
593
+ this.validateSupportedExpression(path, key, e, true, true) ||
594
+ (key === "text-field" && this.validateSupportedConcatExpression(path, key, e, true)));
551
595
  }));
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
+ }
552
605
  }
553
- validateExponentialZoomInterpolate(key, value) {
554
- return (this.getSpecPropValueOptions(key)?.interpolateExpressionSupport &&
606
+ validateExponentialZoomInterpolate(path, key, value, returnStatus) {
607
+ const errorsCount = this.errors.length;
608
+ const result = (this.getSpecPropValueOptions(key)?.interpolateExpressionSupport &&
555
609
  lodash.isEqual(value[0], "interpolate") &&
556
610
  Array.isArray(value[1]) &&
557
611
  value[1].length === 2 &&
@@ -570,12 +624,22 @@ class ClientStyleValidator {
570
624
  .every(e => {
571
625
  return (typeof e === "number" ||
572
626
  typeof e === "string" ||
573
- this.validateSupportedExpression(key, e, true) ||
574
- (key === "text-field" && this.validateSupportedConcatExpression(key, e)));
627
+ this.validateSupportedExpression(path, key, e, true, true) ||
628
+ (key === "text-field" && this.validateSupportedConcatExpression(path, key, e, true)));
575
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
+ }
576
639
  }
577
- validateCubicBezierZoomInterpolate(key, value) {
578
- return (this.getSpecPropValueOptions(key)?.interpolateExpressionSupport &&
640
+ validateCubicBezierZoomInterpolate(path, key, value, returnStatus) {
641
+ const errorsCount = this.errors.length;
642
+ const result = (this.getSpecPropValueOptions(key)?.interpolateExpressionSupport &&
579
643
  lodash.isEqual(value[0], "interpolate") &&
580
644
  Array.isArray(value[1]) &&
581
645
  value[1].length === 5 &&
@@ -594,12 +658,22 @@ class ClientStyleValidator {
594
658
  .every(e => {
595
659
  return (typeof e === "number" ||
596
660
  typeof e === "string" ||
597
- this.validateSupportedExpression(key, e, true) ||
598
- (key === "text-field" && this.validateSupportedConcatExpression(key, e)));
661
+ this.validateSupportedExpression(path, key, e, true, true) ||
662
+ (key === "text-field" && this.validateSupportedConcatExpression(path, key, e, true)));
599
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
+ }
600
673
  }
601
- validateLinearDataInterpolate(key, value) {
602
- return (this.getSpecPropValueOptions(key)?.dataExpressionSupport &&
674
+ validateLinearDataInterpolate(path, key, value, returnStatus) {
675
+ const errorsCount = this.errors.length;
676
+ const result = (this.getSpecPropValueOptions(key)?.dataExpressionSupport &&
603
677
  lodash.isEqual(value[0], "interpolate") &&
604
678
  lodash.isEqual(value[1], ["linear"]) &&
605
679
  Array.isArray(value[2]) &&
@@ -617,10 +691,20 @@ class ClientStyleValidator {
617
691
  .filter((_, i) => i % 2 !== 0)
618
692
  .every(e => typeof e === "number" ||
619
693
  typeof e === "string" ||
620
- (key === "text-field" && this.validateSupportedConcatExpression(key, e))));
694
+ (key === "text-field" && this.validateSupportedConcatExpression(path, key, e, true))));
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
+ }
621
704
  }
622
- validateExponentialDataInterpolate(key, value) {
623
- return (this.getSpecPropValueOptions(key)?.dataExpressionSupport &&
705
+ validateExponentialDataInterpolate(path, key, value, returnStatus) {
706
+ const errorsCount = this.errors.length;
707
+ const result = (this.getSpecPropValueOptions(key)?.dataExpressionSupport &&
624
708
  lodash.isEqual(value[0], "interpolate") &&
625
709
  Array.isArray(value[1]) &&
626
710
  value[1].length === 2 &&
@@ -641,10 +725,20 @@ class ClientStyleValidator {
641
725
  .filter((_, i) => i % 2 !== 0)
642
726
  .every(e => typeof e === "number" ||
643
727
  typeof e === "string" ||
644
- (key === "text-field" && this.validateSupportedConcatExpression(key, e))));
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
+ }
645
738
  }
646
- validateCubicBezierDataInterpolate(key, value) {
647
- return (this.getSpecPropValueOptions(key)?.dataExpressionSupport &&
739
+ validateCubicBezierDataInterpolate(path, key, value, returnStatus) {
740
+ const errorsCount = this.errors.length;
741
+ const result = (this.getSpecPropValueOptions(key)?.dataExpressionSupport &&
648
742
  lodash.isEqual(value[0], "interpolate") &&
649
743
  Array.isArray(value[1]) &&
650
744
  value[1].length === 5 &&
@@ -665,115 +759,191 @@ class ClientStyleValidator {
665
759
  .filter((_, i) => i % 2 !== 0)
666
760
  .every(e => typeof e === "number" ||
667
761
  typeof e === "string" ||
668
- (key === "text-field" && this.validateSupportedConcatExpression(key, e))));
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
+ }
669
772
  }
670
- validateZoomInterpolate(key, value) {
671
- return (this.validateLinearZoomInterpolate(key, value) ||
672
- this.validateExponentialZoomInterpolate(key, value) ||
673
- this.validateCubicBezierZoomInterpolate(key, value));
773
+ validateZoomInterpolate(path, key, value) {
774
+ const isAllowedInterpolate = this.getSpecPropValueOptions(key)?.interpolateExpressionSupport && lodash.isEqual(value[0], "interpolate");
775
+ if (isAllowedInterpolate && lodash.isEqual(value[1], ["linear"])) {
776
+ this.validateLinearZoomInterpolate(path, key, value);
777
+ }
778
+ else if (isAllowedInterpolate && lodash.isEqual(value[1], ["exponential"])) {
779
+ this.validateExponentialZoomInterpolate(path, key, value);
780
+ }
781
+ else if (isAllowedInterpolate && lodash.isEqual(value[1], ["cubic-bezier"])) {
782
+ this.validateCubicBezierZoomInterpolate(path, key, value);
783
+ }
674
784
  }
675
- validateDataInterpolate(key, value) {
676
- return (this.validateLinearDataInterpolate(key, value) ||
677
- this.validateExponentialDataInterpolate(key, value) ||
678
- this.validateCubicBezierDataInterpolate(key, value));
785
+ validateDataInterpolate(path, key, value) {
786
+ const isAllowedInterpolate = this.getSpecPropValueOptions(key)?.dataExpressionSupport && lodash.isEqual(value[0], "interpolate");
787
+ if (isAllowedInterpolate && lodash.isEqual(value[1], ["linear"])) {
788
+ this.validateLinearDataInterpolate(path, key, value);
789
+ }
790
+ else if (isAllowedInterpolate && lodash.isEqual(value[1], ["exponential"])) {
791
+ this.validateExponentialDataInterpolate(path, key, value);
792
+ }
793
+ else if (isAllowedInterpolate && lodash.isEqual(value[1], ["cubic-bezier"])) {
794
+ this.validateCubicBezierDataInterpolate(path, key, value);
795
+ }
679
796
  }
680
- validateSupportedInterpolateExpression(key, value, excludeZoomInterpolate) {
797
+ validateSupportedInterpolateExpression(path, key, value, excludeZoomInterpolate, returnStatus) {
798
+ const errorsCount = this.errors.length;
681
799
  if (!mapboxGlStyleSpec.expression.isExpression(value)) {
682
- if (this.options.verbose) {
683
- console.error("Validate supported interpolate expression:", "not an expression", key, value, "\n");
684
- }
685
- return false;
800
+ this.errors.push({
801
+ path: `${path}.${key}`,
802
+ message: "Not an expression",
803
+ });
686
804
  }
687
- if (key === "heatmap-color") {
805
+ else if (key === "heatmap-color") {
688
806
  const isColorValid = this.isHeatmapColorValid(value);
689
807
  if (!isColorValid) {
690
- if (this.options.verbose) {
691
- console.error("Validate supported interpolate expression:", "invalid color value", key, value, "\n");
692
- }
808
+ this.errors.push({
809
+ path: `${path}.${key}`,
810
+ message: "Invalid color value",
811
+ });
693
812
  }
694
- return this.isHeatmapColorValid(value);
695
813
  }
696
- if (!this.getSpecPropValueOptions(key)?.interpolateExpressionSupport &&
814
+ else if (!this.getSpecPropValueOptions(key)?.interpolateExpressionSupport &&
697
815
  !this.getSpecPropValueOptions(key)?.dataExpressionSupport) {
698
- if (this.options.verbose) {
699
- console.error("Validate supported interpolate expression:", "interpolate not supported", key, value, "\n");
700
- }
816
+ this.errors.push({
817
+ path: `${path}.${key}`,
818
+ message: "Interpolate not supported",
819
+ });
701
820
  }
702
- const result = (!excludeZoomInterpolate && this.validateZoomInterpolate(key, value)) || this.validateDataInterpolate(key, value);
703
- if (!result) {
704
- if (this.options.verbose) {
705
- console.error("Validate supported interpolate expression:", "invalid expression", key, value, "\n");
706
- }
821
+ else if (!excludeZoomInterpolate) {
822
+ this.validateZoomInterpolate(path, key, value);
823
+ }
824
+ else {
825
+ this.validateDataInterpolate(path, key, value);
826
+ }
827
+ if (returnStatus) {
828
+ return this.errors.length === errorsCount;
707
829
  }
708
- return result;
709
830
  }
710
- validateSupportedExpression(key, value, excludeZoomInterpolate) {
831
+ validateSupportedExpression(path, key, value, excludeZoomInterpolate, returnStatus) {
832
+ const errorsCount = this.errors.length;
711
833
  if (!mapboxGlStyleSpec.expression.isExpression(value)) {
712
- if (this.options.verbose) {
713
- console.error("Validate supported expression:", "not an expression", key, value, "\n");
714
- }
715
- return false;
834
+ this.errors.push({
835
+ path: `${path}.${key}`,
836
+ message: "Not an expression",
837
+ });
716
838
  }
717
- const expressionType = value[0];
718
- if (typeof expressionType !== "string" ||
719
- !["match", "case", "step", "interpolate", "concat"].includes(expressionType)) {
720
- if (this.options.verbose) {
721
- console.error("Validate supported expression:", "expression type not supported", key, value, "\n");
839
+ else {
840
+ const expressionType = value[0];
841
+ if (typeof expressionType !== "string" ||
842
+ !["match", "case", "step", "interpolate", "concat"].includes(expressionType)) {
843
+ this.errors.push({
844
+ path: `${path}.${key}`,
845
+ message: "Expression type not supported (supported types: \"match\", \"case\", \"step\", \"interpolate\", \"concat\")",
846
+ });
847
+ }
848
+ else {
849
+ switch (expressionType) {
850
+ case "match":
851
+ this.validateSupportedMatchExpression(path, key, value);
852
+ break;
853
+ case "case":
854
+ this.validateSupportedCaseExpression(path, key, value);
855
+ break;
856
+ case "step":
857
+ this.validateSupportedStepExpression(path, key, value);
858
+ break;
859
+ case "concat":
860
+ this.validateSupportedConcatExpression(path, key, value);
861
+ break;
862
+ case "interpolate":
863
+ this.validateSupportedInterpolateExpression(path, key, value, excludeZoomInterpolate);
864
+ break;
865
+ }
722
866
  }
723
- return false;
724
867
  }
725
- switch (expressionType) {
726
- case "match":
727
- return this.validateSupportedMatchExpression(key, value);
728
- case "case":
729
- return this.validateSupportedCaseExpression(key, value);
730
- case "step":
731
- return this.validateSupportedStepExpression(key, value);
732
- case "concat":
733
- return this.validateSupportedConcatExpression(key, value);
734
- case "interpolate":
735
- return this.validateSupportedInterpolateExpression(key, value, excludeZoomInterpolate);
736
- default:
737
- return false;
868
+ if (returnStatus) {
869
+ return this.errors.length === errorsCount;
738
870
  }
739
871
  }
740
- validateTransitionValue(key, value) {
872
+ validateTransitionValue(path, key, value, returnStatus) {
873
+ const errorsCount = this.errors.length;
741
874
  const propValueOptions = this.getSpecPropValueOptions(key.replace(/-transition$/, ""));
742
875
  if (propValueOptions && propValueOptions.transitionable === false) {
743
- if (this.options.verbose) {
744
- console.error("Validate transition value:", "transition not supported", key, value, "\n");
745
- }
746
- return false;
876
+ this.errors.push({
877
+ path: `${path}.${key}`,
878
+ message: "Transition not supported",
879
+ });
747
880
  }
748
- const result = lodash.isObject(value) &&
749
- (("delay" in value && typeof value.delay === "number") ||
750
- ("duration" in value && typeof value.duration === "number"));
751
- if (!result) {
752
- if (this.options.verbose) {
753
- console.error("Validate transition value:", "invalid transition value", key, value, "\n");
881
+ else {
882
+ const result = lodash.isObject(value) &&
883
+ (("delay" in value && typeof value.delay === "number") ||
884
+ ("duration" in value && typeof value.duration === "number"));
885
+ if (!result) {
886
+ this.errors.push({
887
+ path: `${path}.${key}`,
888
+ message: "Invalid transition value",
889
+ });
754
890
  }
755
891
  }
756
- return result;
892
+ if (returnStatus) {
893
+ return this.errors.length === errorsCount;
894
+ }
757
895
  }
758
- validateSpecPropValue(key, value) {
896
+ validateSpecPropValue(path, key, value) {
759
897
  if (key.endsWith("-transition")) {
760
- return this.validateTransitionValue(key, value);
761
- }
762
- const propValueOptions = this.getSpecPropValueOptions(key);
763
- if (!propValueOptions) {
764
- return (typeof value === "string" ||
765
- typeof value === "number" ||
766
- typeof value === "boolean" ||
767
- (Array.isArray(value) && value.every(item => typeof item === "number")) ||
768
- (Array.isArray(value) && value.every(item => typeof item === "string")) ||
769
- mapboxGlStyleSpec.expression.isExpression(value));
770
- }
771
- if (propValueOptions.arrayValue) {
772
- return (typeof value === propValueOptions.valueTypeAllowed ||
773
- (Array.isArray(value) && value.every(item => typeof item === propValueOptions.valueTypeAllowed)) ||
774
- this.validateSupportedExpression(key, value));
775
- }
776
- return typeof value === propValueOptions.valueTypeAllowed || this.validateSupportedExpression(key, value);
898
+ this.validateTransitionValue(path, key, value);
899
+ }
900
+ else {
901
+ const propValueOptions = this.getSpecPropValueOptions(key);
902
+ if (!propValueOptions) {
903
+ const result = (typeof value === "string" ||
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));
909
+ if (!result) {
910
+ this.errors.push({
911
+ path: `${path}.${key}`,
912
+ message: "Invalid value",
913
+ });
914
+ }
915
+ }
916
+ else if (propValueOptions.arrayValue) {
917
+ if (!propValueOptions.arrayOnly) {
918
+ const result = (typeof value === propValueOptions.valueTypeAllowed ||
919
+ (Array.isArray(value) && value.every(item => typeof item === propValueOptions.valueTypeAllowed)));
920
+ if (!result) {
921
+ this.errors.push({
922
+ path: `${path}.${key}`,
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
+ }
935
+ }
936
+ }
937
+ else if (mapboxGlStyleSpec.expression.isExpression(value)) {
938
+ this.validateSupportedExpression(path, key, value);
939
+ }
940
+ else if (typeof value !== propValueOptions.valueTypeAllowed) {
941
+ this.errors.push({
942
+ path: `${path}.${key}`,
943
+ message: "Invalid value type",
944
+ });
945
+ }
946
+ }
777
947
  }
778
948
  }
779
949