@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/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 required",
|
|
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];
|
|
@@ -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" &&
|
|
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
|
-
|
|
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
|
-
return
|
|
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
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
441
|
+
this.errors.push({
|
|
442
|
+
path: `${path}.${key}`,
|
|
443
|
+
message: "Expression not supported",
|
|
444
|
+
});
|
|
421
445
|
}
|
|
422
|
-
if (!expression.isExpression(value)) {
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
446
|
+
else if (!expression.isExpression(value)) {
|
|
447
|
+
this.errors.push({
|
|
448
|
+
path: `${path}.${key}`,
|
|
449
|
+
message: "Not an expression",
|
|
450
|
+
});
|
|
427
451
|
}
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
if (
|
|
442
|
-
|
|
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
|
|
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
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
477
|
+
this.errors.push({
|
|
478
|
+
path: `${path}.${key}`,
|
|
479
|
+
message: "Expression not supported",
|
|
480
|
+
});
|
|
453
481
|
}
|
|
454
|
-
if (!expression.isExpression(value)) {
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
482
|
+
else if (!expression.isExpression(value)) {
|
|
483
|
+
this.errors.push({
|
|
484
|
+
path: `${path}.${key}`,
|
|
485
|
+
message: "Not an expression",
|
|
486
|
+
});
|
|
459
487
|
}
|
|
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
|
|
488
|
+
else {
|
|
489
|
+
const result = value[0] === "case" &&
|
|
490
|
+
value.length > 3 &&
|
|
491
|
+
value.length % 2 === 0 &&
|
|
492
|
+
value
|
|
470
493
|
.slice(1)
|
|
471
|
-
.
|
|
472
|
-
|
|
473
|
-
[
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
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
|
|
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
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
527
|
+
this.errors.push({
|
|
528
|
+
path: `${path}.${key}`,
|
|
529
|
+
message: "Expression not supported",
|
|
530
|
+
});
|
|
499
531
|
}
|
|
500
|
-
if (!expression.isExpression(value)) {
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
532
|
+
else if (!expression.isExpression(value)) {
|
|
533
|
+
this.errors.push({
|
|
534
|
+
path: `${path}.${key}`,
|
|
535
|
+
message: "Not an expression",
|
|
536
|
+
});
|
|
505
537
|
}
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
if (
|
|
525
|
-
|
|
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
|
|
563
|
+
return this.errors.length === errorsCount;
|
|
529
564
|
}
|
|
530
|
-
|
|
531
|
-
return
|
|
532
|
-
|
|
533
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
600
|
-
return (this.
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
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
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
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 (
|
|
686
|
-
|
|
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 (
|
|
695
|
-
|
|
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
|
-
|
|
701
|
-
|
|
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
|
-
|
|
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
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
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
|
-
|
|
716
|
-
|
|
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
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
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
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
750
|
+
this.errors.push({
|
|
751
|
+
path: `${path}.${key}`,
|
|
752
|
+
message: "Transition not supported",
|
|
753
|
+
});
|
|
745
754
|
}
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
("
|
|
749
|
-
|
|
750
|
-
if (
|
|
751
|
-
|
|
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
|
|
766
|
+
return this.errors.length === errorsCount;
|
|
755
767
|
}
|
|
756
|
-
validateSpecPropValue(key, value) {
|
|
768
|
+
validateSpecPropValue(path, key, value) {
|
|
757
769
|
if (key.endsWith("-transition")) {
|
|
758
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
771
|
-
|
|
772
|
-
|
|
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
|
|