@evergis/common 1.0.3 → 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.
@@ -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 required",
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];
@@ -385,393 +404,422 @@ class ClientStyleValidator {
385
404
  .every(e => typeof e === "string"));
386
405
  }
387
406
  isZoomInterpolate(value) {
388
- return Array.isArray(value) && value[0] === "interpolate" && Array.isArray(value[2]) && value[2][0] === "zoom";
407
+ return Array.isArray(value) && value[0] === "interpolate" && isEqual(value[2], ["zoom"]);
389
408
  }
390
- validateSupportedConcatExpression(key, value) {
409
+ validateSupportedConcatExpression(path, key, value) {
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
+ return this.errors.length === errorsCount;
414
437
  }
415
- validateSupportedMatchExpression(key, value) {
438
+ validateSupportedMatchExpression(path, key, value) {
439
+ const errorsCount = this.errors.length;
416
440
  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;
441
+ this.errors.push({
442
+ path: `${path}.${key}`,
443
+ message: "Expression not supported",
444
+ });
421
445
  }
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;
446
+ else if (!expression.isExpression(value)) {
447
+ this.errors.push({
448
+ path: `${path}.${key}`,
449
+ message: "Not an expression",
450
+ });
427
451
  }
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");
452
+ else {
453
+ const result = value[0] === "match" &&
454
+ Array.isArray(value[1]) &&
455
+ value[1].length === 2 &&
456
+ value[1][0] === "get" &&
457
+ typeof value[1][1] === "string" &&
458
+ value.length > 3 &&
459
+ value.length % 2 !== 0 &&
460
+ value
461
+ .slice(2)
462
+ .every(e => typeof e === "number" ||
463
+ typeof e === "string" ||
464
+ (key === "text-field" && this.validateSupportedConcatExpression(path, key, e)));
465
+ if (!result) {
466
+ this.errors.push({
467
+ path: `${path}.${key}`,
468
+ message: "Invalid expression",
469
+ });
443
470
  }
444
471
  }
445
- return result;
472
+ return this.errors.length === errorsCount;
446
473
  }
447
- validateSupportedCaseExpression(key, value) {
474
+ validateSupportedCaseExpression(path, key, value) {
475
+ const errorsCount = this.errors.length;
448
476
  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;
477
+ this.errors.push({
478
+ path: `${path}.${key}`,
479
+ message: "Expression not supported",
480
+ });
453
481
  }
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;
482
+ else if (!expression.isExpression(value)) {
483
+ this.errors.push({
484
+ path: `${path}.${key}`,
485
+ message: "Not an expression",
486
+ });
459
487
  }
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
488
+ else {
489
+ const result = value[0] === "case" &&
490
+ value.length > 3 &&
491
+ value.length % 2 === 0 &&
492
+ value
470
493
  .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");
494
+ .filter((_, i) => i % 2 === 0 && i < value.slice(1).length - 1)
495
+ .every(e => Array.isArray(e) &&
496
+ e[0] === "all" &&
497
+ e.length > 1 &&
498
+ e
499
+ .slice(1)
500
+ .every(ce => Array.isArray(ce) &&
501
+ ce.length === 3 &&
502
+ [">=", ">", "<", "<="].includes(ce[0]) &&
503
+ ce[1][0] === "get" &&
504
+ typeof ce[1][1] === "string" &&
505
+ typeof ce[2] === "number")) &&
506
+ value
507
+ .slice(1)
508
+ .filter((_, i) => i % 2 !== 0)
509
+ .every(e => typeof e === "number" ||
510
+ typeof e === "string" ||
511
+ (key === "text-field" && this.validateSupportedConcatExpression(path, key, e))) &&
512
+ (typeof value[value.slice(1).length - 1] === "number" ||
513
+ typeof value[value.slice(1).length - 1] === "string" ||
514
+ (key === "text-field" && this.validateSupportedConcatExpression(path, key, value)));
515
+ if (!result) {
516
+ this.errors.push({
517
+ path: `${path}.${key}`,
518
+ message: "Invalid expression",
519
+ });
489
520
  }
490
521
  }
491
- return result;
522
+ return this.errors.length === errorsCount;
492
523
  }
493
- validateSupportedStepExpression(key, value) {
524
+ validateSupportedStepExpression(path, key, value) {
525
+ const errorsCount = this.errors.length;
494
526
  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;
527
+ this.errors.push({
528
+ path: `${path}.${key}`,
529
+ message: "Expression not supported",
530
+ });
499
531
  }
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;
532
+ else if (!expression.isExpression(value)) {
533
+ this.errors.push({
534
+ path: `${path}.${key}`,
535
+ message: "Not an expression",
536
+ });
505
537
  }
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");
538
+ else {
539
+ const result = value[0] === "step" &&
540
+ Array.isArray(value[1]) &&
541
+ value[1].length === 2 &&
542
+ value[1][0] === "get" &&
543
+ typeof value[1][1] === "string" &&
544
+ value.length > 3 &&
545
+ value.length % 2 !== 0 &&
546
+ value
547
+ .slice(2)
548
+ .filter((_, i) => i % 2 === 0)
549
+ .every(e => typeof e === "number" ||
550
+ typeof e === "string" ||
551
+ (key === "text-field" && this.validateSupportedConcatExpression(path, key, e))) &&
552
+ value
553
+ .slice(2)
554
+ .filter((_, i) => i % 2 !== 0)
555
+ .every(e => typeof e === "number");
556
+ if (!result) {
557
+ this.errors.push({
558
+ path: `${path}.${key}`,
559
+ message: "Invalid expression",
560
+ });
526
561
  }
527
562
  }
528
- return result;
563
+ return this.errors.length === errorsCount;
529
564
  }
530
- validateLinearZoomInterpolate(key, value) {
531
- return (this.getSpecPropValueOptions(key)?.interpolateExpressionSupport &&
532
- isEqual(value[0], "interpolate") &&
533
- isEqual(value[1], ["linear"]) &&
565
+ validateInterpolateInputs(value) {
566
+ return value
567
+ .slice(3)
568
+ .filter((_, i) => i % 2 === 0)
569
+ .every(e => typeof e === "number");
570
+ }
571
+ validateZoomInterpolateConsistency(path, key, value) {
572
+ return (this.validateInterpolateInputs(value) &&
534
573
  isEqual(value[2], ["zoom"]) &&
535
574
  value.length % 2 !== 0 &&
536
575
  value.length > 4 &&
537
- value
538
- .slice(3)
539
- .filter((_, i) => i % 2 === 0)
540
- .every(e => typeof e === "number") &&
541
576
  value
542
577
  .slice(3)
543
578
  .filter((_, i) => i % 2 !== 0)
544
579
  .every(e => {
545
580
  return (typeof e === "number" ||
546
581
  typeof e === "string" ||
547
- this.validateSupportedExpression(key, e, true) ||
548
- (key === "text-field" && this.validateSupportedConcatExpression(key, e)));
582
+ this.validateSupportedExpression(path, key, e, true) ||
583
+ (key === "text-field" && this.validateSupportedConcatExpression(path, key, e)));
549
584
  }));
550
585
  }
551
- validateExponentialZoomInterpolate(key, value) {
586
+ validateLinearZoomInterpolate(path, key, value) {
587
+ return (this.getSpecPropValueOptions(key)?.interpolateExpressionSupport &&
588
+ isEqual(value[0], "interpolate") &&
589
+ isEqual(value[1], ["linear"]) &&
590
+ this.validateZoomInterpolateConsistency(path, key, value));
591
+ }
592
+ validateExponentialZoomInterpolate(path, key, value) {
552
593
  return (this.getSpecPropValueOptions(key)?.interpolateExpressionSupport &&
553
594
  isEqual(value[0], "interpolate") &&
554
595
  Array.isArray(value[1]) &&
555
596
  value[1].length === 2 &&
556
597
  value[1][0] === "exponential" &&
557
598
  typeof value[1][1] === "number" &&
558
- isEqual(value[2], ["zoom"]) &&
559
- value.length % 2 !== 0 &&
560
- value.length > 4 &&
561
- value
562
- .slice(3)
563
- .filter((_, i) => i % 2 === 0)
564
- .every(e => typeof e === "number") &&
565
- value
566
- .slice(3)
567
- .filter((_, i) => i % 2 !== 0)
568
- .every(e => {
569
- return (typeof e === "number" ||
570
- typeof e === "string" ||
571
- this.validateSupportedExpression(key, e, true) ||
572
- (key === "text-field" && this.validateSupportedConcatExpression(key, e)));
573
- }));
599
+ this.validateZoomInterpolateConsistency(path, key, value));
574
600
  }
575
- validateCubicBezierZoomInterpolate(key, value) {
601
+ validateCubicBezierZoomInterpolate(path, key, value) {
576
602
  return (this.getSpecPropValueOptions(key)?.interpolateExpressionSupport &&
577
603
  isEqual(value[0], "interpolate") &&
578
604
  Array.isArray(value[1]) &&
579
605
  value[1].length === 5 &&
580
606
  value[1][0] === "cubic-bezier" &&
581
607
  value[1].slice(1).every(e => typeof e === "number") &&
582
- isEqual(value[2], ["zoom"]) &&
583
- value.length % 2 !== 0 &&
584
- value.length > 4 &&
585
- value
586
- .slice(3)
587
- .filter((_, i) => i % 2 === 0)
588
- .every(e => typeof e === "number") &&
589
- value
590
- .slice(3)
591
- .filter((_, i) => i % 2 !== 0)
592
- .every(e => {
593
- return (typeof e === "number" ||
594
- typeof e === "string" ||
595
- this.validateSupportedExpression(key, e, true) ||
596
- (key === "text-field" && this.validateSupportedConcatExpression(key, e)));
597
- }));
608
+ this.validateZoomInterpolateConsistency(path, key, value));
598
609
  }
599
- validateLinearDataInterpolate(key, value) {
600
- return (this.getSpecPropValueOptions(key)?.dataExpressionSupport &&
601
- isEqual(value[0], "interpolate") &&
602
- isEqual(value[1], ["linear"]) &&
610
+ validateDataInterpolateConsistency(path, key, value) {
611
+ return (this.validateInterpolateInputs(value) &&
603
612
  Array.isArray(value[2]) &&
604
613
  value[2].length === 2 &&
605
614
  value[2][0] === "get" &&
606
615
  typeof value[2][1] === "string" &&
607
616
  value.length % 2 !== 0 &&
608
617
  value.length > 4 &&
609
- value
610
- .slice(3)
611
- .filter((_, i) => i % 2 === 0)
612
- .every(e => typeof e === "number") &&
613
618
  value
614
619
  .slice(3)
615
620
  .filter((_, i) => i % 2 !== 0)
616
621
  .every(e => typeof e === "number" ||
617
622
  typeof e === "string" ||
618
- (key === "text-field" && this.validateSupportedConcatExpression(key, e))));
623
+ (key === "text-field" && this.validateSupportedConcatExpression(path, key, e))));
624
+ }
625
+ validateLinearDataInterpolate(path, key, value) {
626
+ return (this.getSpecPropValueOptions(key)?.dataExpressionSupport &&
627
+ isEqual(value[0], "interpolate") &&
628
+ isEqual(value[1], ["linear"]) &&
629
+ this.validateDataInterpolateConsistency(path, key, value));
619
630
  }
620
- validateExponentialDataInterpolate(key, value) {
631
+ validateExponentialDataInterpolate(path, key, value) {
621
632
  return (this.getSpecPropValueOptions(key)?.dataExpressionSupport &&
622
633
  isEqual(value[0], "interpolate") &&
623
634
  Array.isArray(value[1]) &&
624
635
  value[1].length === 2 &&
625
636
  value[1][0] === "exponential" &&
626
637
  typeof value[1][1] === "number" &&
627
- Array.isArray(value[2]) &&
628
- value[2].length === 2 &&
629
- value[2][0] === "get" &&
630
- typeof value[2][1] === "string" &&
631
- value.length % 2 !== 0 &&
632
- value.length > 4 &&
633
- value
634
- .slice(3)
635
- .filter((_, i) => i % 2 === 0)
636
- .every(e => typeof e === "number") &&
637
- value
638
- .slice(3)
639
- .filter((_, i) => i % 2 !== 0)
640
- .every(e => typeof e === "number" ||
641
- typeof e === "string" ||
642
- (key === "text-field" && this.validateSupportedConcatExpression(key, e))));
638
+ this.validateDataInterpolateConsistency(path, key, value));
643
639
  }
644
- validateCubicBezierDataInterpolate(key, value) {
640
+ validateCubicBezierDataInterpolate(path, key, value) {
645
641
  return (this.getSpecPropValueOptions(key)?.dataExpressionSupport &&
646
642
  isEqual(value[0], "interpolate") &&
647
643
  Array.isArray(value[1]) &&
648
644
  value[1].length === 5 &&
649
645
  value[1][0] === "cubic-bezier" &&
650
646
  value[1].slice(1).every(e => typeof e === "number") &&
651
- Array.isArray(value[2]) &&
652
- value[2].length === 2 &&
653
- value[2][0] === "get" &&
654
- typeof value[2][1] === "string" &&
655
- value.length % 2 !== 0 &&
656
- value.length > 4 &&
657
- value
658
- .slice(3)
659
- .filter((_, i) => i % 2 === 0)
660
- .every(e => typeof e === "number") &&
661
- value
662
- .slice(3)
663
- .filter((_, i) => i % 2 !== 0)
664
- .every(e => typeof e === "number" ||
665
- typeof e === "string" ||
666
- (key === "text-field" && this.validateSupportedConcatExpression(key, e))));
667
- }
668
- validateZoomInterpolate(key, value) {
669
- return (this.validateLinearZoomInterpolate(key, value) ||
670
- this.validateExponentialZoomInterpolate(key, value) ||
671
- this.validateCubicBezierZoomInterpolate(key, value));
647
+ this.validateDataInterpolateConsistency(path, key, value));
672
648
  }
673
- validateDataInterpolate(key, value) {
674
- return (this.validateLinearDataInterpolate(key, value) ||
675
- this.validateExponentialDataInterpolate(key, value) ||
676
- this.validateCubicBezierDataInterpolate(key, value));
649
+ validateZoomInterpolate(path, key, value) {
650
+ const isAllowedInterpolate = this.getSpecPropValueOptions(key)?.interpolateExpressionSupport && isEqual(value[0], "interpolate");
651
+ if (!isAllowedInterpolate) {
652
+ return;
653
+ }
654
+ if (isEqual(value[1], ["linear"])) {
655
+ this.validateLinearZoomInterpolate(path, key, value);
656
+ }
657
+ if (isEqual(value[1], ["exponential"])) {
658
+ this.validateExponentialZoomInterpolate(path, key, value);
659
+ }
660
+ if (isEqual(value[1], ["cubic-bezier"])) {
661
+ this.validateCubicBezierZoomInterpolate(path, key, value);
662
+ }
677
663
  }
678
- validateSupportedInterpolateExpression(key, value, excludeZoomInterpolate) {
679
- 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;
664
+ validateDataInterpolate(path, key, value) {
665
+ const isAllowedInterpolate = this.getSpecPropValueOptions(key)?.dataExpressionSupport && isEqual(value[0], "interpolate");
666
+ if (!isAllowedInterpolate) {
667
+ return;
684
668
  }
685
- if (key === "heatmap-color") {
686
- const isColorValid = this.isHeatmapColorValid(value);
687
- if (!isColorValid) {
688
- if (this.options.verbose) {
689
- console.error("Validate supported interpolate expression:", "invalid color value", key, value, "\n");
690
- }
691
- }
692
- return this.isHeatmapColorValid(value);
669
+ if (isEqual(value[1], ["linear"])) {
670
+ this.validateLinearDataInterpolate(path, key, value);
693
671
  }
694
- if (!this.getSpecPropValueOptions(key)?.interpolateExpressionSupport &&
695
- !this.getSpecPropValueOptions(key)?.dataExpressionSupport) {
696
- if (this.options.verbose) {
697
- console.error("Validate supported interpolate expression:", "interpolate not supported", key, value, "\n");
698
- }
672
+ if (isEqual(value[1], ["exponential"])) {
673
+ this.validateExponentialDataInterpolate(path, key, value);
699
674
  }
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
- }
675
+ if (isEqual(value[1], ["cubic-bezier"])) {
676
+ this.validateCubicBezierDataInterpolate(path, key, value);
705
677
  }
706
- return result;
707
678
  }
708
- validateSupportedExpression(key, value, excludeZoomInterpolate) {
679
+ validateSupportedInterpolateExpression(path, key, value, excludeZoomInterpolate) {
680
+ const errorsCount = this.errors.length;
681
+ const propValueOptions = this.getSpecPropValueOptions(key);
709
682
  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;
683
+ this.errors.push({
684
+ path: `${path}.${key}`,
685
+ message: "Not an expression",
686
+ });
687
+ }
688
+ else if (key === "heatmap-color" && !this.isHeatmapColorValid(value)) {
689
+ this.errors.push({
690
+ path: `${path}.${key}`,
691
+ message: "Invalid color value",
692
+ });
693
+ }
694
+ else if (!propValueOptions?.interpolateExpressionSupport && !propValueOptions?.dataExpressionSupport) {
695
+ this.errors.push({
696
+ path: `${path}.${key}`,
697
+ message: "Interpolate not supported",
698
+ });
699
+ }
700
+ else if (!excludeZoomInterpolate) {
701
+ this.validateZoomInterpolate(path, key, value);
714
702
  }
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");
720
- }
721
- return false;
703
+ else {
704
+ this.validateDataInterpolate(path, key, value);
722
705
  }
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;
706
+ return this.errors.length === errorsCount;
707
+ }
708
+ validateSupportedExpression(path, key, value, excludeZoomInterpolate) {
709
+ const errorsCount = this.errors.length;
710
+ if (!expression.isExpression(value)) {
711
+ this.errors.push({
712
+ path: `${path}.${key}`,
713
+ message: "Not an expression",
714
+ });
715
+ }
716
+ else {
717
+ const expressionType = value[0];
718
+ if (typeof expressionType !== "string" || !["match", "case", "step", "interpolate", "concat"].includes(expressionType)) {
719
+ this.errors.push({
720
+ path: `${path}.${key}`,
721
+ message: "Expression type not supported (supported types: \"match\", \"case\", \"step\", \"interpolate\", \"concat\")",
722
+ });
723
+ }
724
+ else {
725
+ switch (expressionType) {
726
+ case "match":
727
+ this.validateSupportedMatchExpression(path, key, value);
728
+ break;
729
+ case "case":
730
+ this.validateSupportedCaseExpression(path, key, value);
731
+ break;
732
+ case "step":
733
+ this.validateSupportedStepExpression(path, key, value);
734
+ break;
735
+ case "concat":
736
+ this.validateSupportedConcatExpression(path, key, value);
737
+ break;
738
+ case "interpolate":
739
+ this.validateSupportedInterpolateExpression(path, key, value, excludeZoomInterpolate);
740
+ break;
741
+ }
742
+ }
736
743
  }
744
+ return this.errors.length === errorsCount;
737
745
  }
738
- validateTransitionValue(key, value) {
746
+ validateTransitionValue(path, key, value) {
747
+ const errorsCount = this.errors.length;
739
748
  const propValueOptions = this.getSpecPropValueOptions(key.replace(/-transition$/, ""));
740
749
  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;
750
+ this.errors.push({
751
+ path: `${path}.${key}`,
752
+ message: "Transition not supported",
753
+ });
745
754
  }
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");
755
+ else {
756
+ const result = isObject$1(value) &&
757
+ (("delay" in value && typeof value.delay === "number") ||
758
+ ("duration" in value && typeof value.duration === "number"));
759
+ if (!result) {
760
+ this.errors.push({
761
+ path: `${path}.${key}`,
762
+ message: "Invalid transition value",
763
+ });
752
764
  }
753
765
  }
754
- return result;
766
+ return this.errors.length === errorsCount;
755
767
  }
756
- validateSpecPropValue(key, value) {
768
+ validateSpecPropValue(path, key, value) {
757
769
  if (key.endsWith("-transition")) {
758
- return this.validateTransitionValue(key, value);
770
+ this.validateTransitionValue(path, key, value);
771
+ return;
759
772
  }
760
773
  const propValueOptions = this.getSpecPropValueOptions(key);
774
+ const isExpression = expression.isExpression(value);
761
775
  if (!propValueOptions) {
762
- return (typeof value === "string" ||
776
+ const result = (typeof value === "string" ||
763
777
  typeof value === "number" ||
764
778
  typeof value === "boolean" ||
765
779
  (Array.isArray(value) && value.every(item => typeof item === "number")) ||
766
780
  (Array.isArray(value) && value.every(item => typeof item === "string")) ||
767
- expression.isExpression(value));
781
+ isExpression);
782
+ if (!result) {
783
+ this.errors.push({
784
+ path: `${path}.${key}`,
785
+ message: "Invalid value",
786
+ });
787
+ }
788
+ return;
768
789
  }
769
790
  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));
791
+ if (!propValueOptions.arrayOnly) {
792
+ const result = (typeof value === propValueOptions.valueTypeAllowed ||
793
+ (Array.isArray(value) && value.every(item => typeof item === propValueOptions.valueTypeAllowed)));
794
+ if (!result) {
795
+ this.errors.push({
796
+ path: `${path}.${key}`,
797
+ message: `Only values of type ${propValueOptions.valueTypeAllowed} allowed`,
798
+ });
799
+ }
800
+ }
801
+ else {
802
+ const result = Array.isArray(value) && value.every(item => typeof item === propValueOptions.valueTypeAllowed);
803
+ if (!result) {
804
+ this.errors.push({
805
+ path: `${path}.${key}`,
806
+ message: `Only array of values of type ${propValueOptions.valueTypeAllowed} allowed`,
807
+ });
808
+ }
809
+ }
810
+ return;
811
+ }
812
+ if (isExpression) {
813
+ this.validateSupportedExpression(path, key, value);
814
+ return;
815
+ }
816
+ if (typeof value !== propValueOptions.valueTypeAllowed) {
817
+ this.errors.push({
818
+ path: `${path}.${key}`,
819
+ message: "Invalid value type",
820
+ });
821
+ return;
773
822
  }
774
- return typeof value === propValueOptions.valueTypeAllowed || this.validateSupportedExpression(key, value);
775
823
  }
776
824
  }
777
825