@evergis/common 1.0.3 → 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/LICENSE +21 -21
- package/README.md +1 -1
- 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 +6 -3
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,
|
|
356
|
+
/* eslint-disable max-lines, class-methods-use-this, @typescript-eslint/no-magic-numbers */
|
|
353
357
|
class ClientStyleValidator {
|
|
354
|
-
|
|
355
|
-
constructor(
|
|
356
|
-
this.
|
|
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
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
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
|
-
|
|
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
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
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
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
419
|
+
else if (!mapboxGlStyleSpec.expression.isExpression(value)) {
|
|
420
|
+
this.errors.push({
|
|
421
|
+
path: `${path}.${key}`,
|
|
422
|
+
message: "Not an expression",
|
|
423
|
+
});
|
|
404
424
|
}
|
|
405
|
-
|
|
406
|
-
value
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
if (
|
|
412
|
-
|
|
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
|
-
|
|
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
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
445
|
+
this.errors.push({
|
|
446
|
+
path: `${path}.${key}`,
|
|
447
|
+
message: "Expression not supported",
|
|
448
|
+
});
|
|
423
449
|
}
|
|
424
|
-
if (!mapboxGlStyleSpec.expression.isExpression(value)) {
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
450
|
+
else if (!mapboxGlStyleSpec.expression.isExpression(value)) {
|
|
451
|
+
this.errors.push({
|
|
452
|
+
path: `${path}.${key}`,
|
|
453
|
+
message: "Not an expression",
|
|
454
|
+
});
|
|
429
455
|
}
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
if (
|
|
444
|
-
|
|
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
|
-
|
|
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
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
483
|
+
this.errors.push({
|
|
484
|
+
path: `${path}.${key}`,
|
|
485
|
+
message: "Expression not supported",
|
|
486
|
+
});
|
|
455
487
|
}
|
|
456
|
-
if (!mapboxGlStyleSpec.expression.isExpression(value)) {
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
488
|
+
else if (!mapboxGlStyleSpec.expression.isExpression(value)) {
|
|
489
|
+
this.errors.push({
|
|
490
|
+
path: `${path}.${key}`,
|
|
491
|
+
message: "Not an expression",
|
|
492
|
+
});
|
|
461
493
|
}
|
|
462
|
-
|
|
463
|
-
value
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
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
|
-
.
|
|
474
|
-
|
|
475
|
-
[
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
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
|
-
|
|
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
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
535
|
+
this.errors.push({
|
|
536
|
+
path: `${path}.${key}`,
|
|
537
|
+
message: "Expression not supported",
|
|
538
|
+
});
|
|
501
539
|
}
|
|
502
|
-
if (!mapboxGlStyleSpec.expression.isExpression(value)) {
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
540
|
+
else if (!mapboxGlStyleSpec.expression.isExpression(value)) {
|
|
541
|
+
this.errors.push({
|
|
542
|
+
path: `${path}.${key}`,
|
|
543
|
+
message: "Not an expression",
|
|
544
|
+
});
|
|
507
545
|
}
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
if (
|
|
527
|
-
|
|
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
|
-
|
|
571
|
+
if (returnStatus) {
|
|
572
|
+
return this.errors.length === errorsCount;
|
|
573
|
+
}
|
|
531
574
|
}
|
|
532
|
-
validateLinearZoomInterpolate(key, value) {
|
|
533
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
672
|
-
|
|
673
|
-
this.
|
|
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
|
-
|
|
677
|
-
|
|
678
|
-
this.
|
|
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
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
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
|
-
|
|
691
|
-
|
|
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
|
-
|
|
699
|
-
|
|
700
|
-
|
|
816
|
+
this.errors.push({
|
|
817
|
+
path: `${path}.${key}`,
|
|
818
|
+
message: "Interpolate not supported",
|
|
819
|
+
});
|
|
701
820
|
}
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
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
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
834
|
+
this.errors.push({
|
|
835
|
+
path: `${path}.${key}`,
|
|
836
|
+
message: "Not an expression",
|
|
837
|
+
});
|
|
716
838
|
}
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
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
|
-
|
|
726
|
-
|
|
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
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
876
|
+
this.errors.push({
|
|
877
|
+
path: `${path}.${key}`,
|
|
878
|
+
message: "Transition not supported",
|
|
879
|
+
});
|
|
747
880
|
}
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
("
|
|
751
|
-
|
|
752
|
-
if (
|
|
753
|
-
|
|
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
|
-
|
|
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
|
-
|
|
761
|
-
}
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
typeof value === "
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
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
|
|