@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/classification/ClientStyleValidator/ClientStyleValidator.d.ts +4 -4
- package/dist/classification/ClientStyleValidator/types.d.ts +8 -2
- package/dist/common.esm.js +399 -229
- package/dist/common.esm.js.map +1 -1
- package/dist/index.js +399 -229
- package/dist/index.js.map +1 -1
- package/package.json +7 -4
package/dist/common.esm.js
CHANGED
|
@@ -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,
|
|
354
|
+
/* eslint-disable max-lines, class-methods-use-this, @typescript-eslint/no-magic-numbers */
|
|
351
355
|
class ClientStyleValidator {
|
|
352
|
-
|
|
353
|
-
constructor(
|
|
354
|
-
this.
|
|
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
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
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
|
-
|
|
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
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
412
|
+
this.errors.push({
|
|
413
|
+
path: `${path}.${key}`,
|
|
414
|
+
message: "Supported only for \`text-field\`",
|
|
415
|
+
});
|
|
396
416
|
}
|
|
397
|
-
if (!expression.isExpression(value)) {
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
417
|
+
else if (!expression.isExpression(value)) {
|
|
418
|
+
this.errors.push({
|
|
419
|
+
path: `${path}.${key}`,
|
|
420
|
+
message: "Not an expression",
|
|
421
|
+
});
|
|
402
422
|
}
|
|
403
|
-
|
|
404
|
-
value
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
if (
|
|
410
|
-
|
|
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
|
-
|
|
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
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
443
|
+
this.errors.push({
|
|
444
|
+
path: `${path}.${key}`,
|
|
445
|
+
message: "Expression not supported",
|
|
446
|
+
});
|
|
421
447
|
}
|
|
422
|
-
if (!expression.isExpression(value)) {
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
448
|
+
else if (!expression.isExpression(value)) {
|
|
449
|
+
this.errors.push({
|
|
450
|
+
path: `${path}.${key}`,
|
|
451
|
+
message: "Not an expression",
|
|
452
|
+
});
|
|
427
453
|
}
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
if (
|
|
442
|
-
|
|
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
|
-
|
|
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
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
481
|
+
this.errors.push({
|
|
482
|
+
path: `${path}.${key}`,
|
|
483
|
+
message: "Expression not supported",
|
|
484
|
+
});
|
|
453
485
|
}
|
|
454
|
-
if (!expression.isExpression(value)) {
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
486
|
+
else if (!expression.isExpression(value)) {
|
|
487
|
+
this.errors.push({
|
|
488
|
+
path: `${path}.${key}`,
|
|
489
|
+
message: "Not an expression",
|
|
490
|
+
});
|
|
459
491
|
}
|
|
460
|
-
|
|
461
|
-
value
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
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
|
-
.
|
|
472
|
-
|
|
473
|
-
[
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
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
|
-
|
|
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
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
533
|
+
this.errors.push({
|
|
534
|
+
path: `${path}.${key}`,
|
|
535
|
+
message: "Expression not supported",
|
|
536
|
+
});
|
|
499
537
|
}
|
|
500
|
-
if (!expression.isExpression(value)) {
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
538
|
+
else if (!expression.isExpression(value)) {
|
|
539
|
+
this.errors.push({
|
|
540
|
+
path: `${path}.${key}`,
|
|
541
|
+
message: "Not an expression",
|
|
542
|
+
});
|
|
505
543
|
}
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
if (
|
|
525
|
-
|
|
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
|
-
|
|
569
|
+
if (returnStatus) {
|
|
570
|
+
return this.errors.length === errorsCount;
|
|
571
|
+
}
|
|
529
572
|
}
|
|
530
|
-
validateLinearZoomInterpolate(key, value) {
|
|
531
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
670
|
-
|
|
671
|
-
this.
|
|
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
|
-
|
|
675
|
-
|
|
676
|
-
this.
|
|
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
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
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
|
-
|
|
689
|
-
|
|
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
|
-
|
|
697
|
-
|
|
698
|
-
|
|
814
|
+
this.errors.push({
|
|
815
|
+
path: `${path}.${key}`,
|
|
816
|
+
message: "Interpolate not supported",
|
|
817
|
+
});
|
|
699
818
|
}
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
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
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
832
|
+
this.errors.push({
|
|
833
|
+
path: `${path}.${key}`,
|
|
834
|
+
message: "Not an expression",
|
|
835
|
+
});
|
|
714
836
|
}
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
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
|
-
|
|
724
|
-
|
|
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
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
874
|
+
this.errors.push({
|
|
875
|
+
path: `${path}.${key}`,
|
|
876
|
+
message: "Transition not supported",
|
|
877
|
+
});
|
|
745
878
|
}
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
("
|
|
749
|
-
|
|
750
|
-
if (
|
|
751
|
-
|
|
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
|
-
|
|
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
|
-
|
|
759
|
-
}
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
typeof value === "
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
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
|
|