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