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