@mapbox/mapbox-gl-style-spec 14.4.0 → 14.5.0
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/bin/gl-style-composite.js +0 -5
- package/bin/gl-style-format.js +0 -5
- package/bin/gl-style-migrate.js +0 -5
- package/bin/gl-style-validate.js +0 -5
- package/{composite.js → composite.ts} +1 -1
- package/data/{extent.js → extent.ts} +0 -2
- package/{deref.js → deref.ts} +7 -9
- package/{diff.js → diff.ts} +44 -21
- package/dist/index.cjs +794 -1226
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1746 -0
- package/dist/index.es.js +794 -1226
- package/dist/index.es.js.map +1 -1
- package/{empty.js → empty.ts} +1 -2
- package/error/{parsing_error.js → parsing_error.ts} +0 -2
- package/error/{validation_error.js → validation_error.ts} +5 -5
- package/expression/{compound_expression.js → compound_expression.ts} +29 -19
- package/expression/definitions/{assertion.js → assertion.ts} +16 -13
- package/expression/definitions/{at.js → at.ts} +12 -13
- package/expression/definitions/{case.js → case.ts} +12 -11
- package/expression/definitions/{coalesce.js → coalesce.ts} +11 -11
- package/expression/definitions/{coercion.js → coercion.ts} +21 -20
- package/expression/definitions/{collator.js → collator.ts} +11 -11
- package/expression/definitions/{comparison.js → comparison.ts} +30 -24
- package/expression/definitions/{config.js → config.ts} +16 -16
- package/expression/definitions/{distance.js → distance.ts} +60 -52
- package/expression/definitions/{format.js → format.ts} +26 -15
- package/expression/definitions/{image.js → image.ts} +12 -12
- package/expression/definitions/{in.js → in.ts} +22 -13
- package/expression/definitions/{index.js → index.ts} +70 -83
- package/expression/definitions/{index_of.js → index_of.ts} +24 -15
- package/expression/definitions/{interpolate.js → interpolate.ts} +44 -25
- package/expression/definitions/{length.js → length.ts} +11 -10
- package/expression/definitions/{let.js → let.ts} +10 -7
- package/expression/definitions/{literal.js → literal.ts} +11 -12
- package/expression/definitions/{match.js → match.ts} +25 -15
- package/expression/definitions/{number_format.js → number_format.ts} +10 -10
- package/expression/definitions/{slice.js → slice.ts} +23 -15
- package/expression/definitions/{step.js → step.ts} +14 -12
- package/expression/definitions/{var.js → var.ts} +5 -7
- package/expression/definitions/{within.js → within.ts} +41 -29
- package/expression/{evaluation_context.js → evaluation_context.ts} +26 -23
- package/expression/expression.ts +29 -0
- package/expression/{index.js → index.ts} +208 -110
- package/expression/{is_constant.js → is_constant.ts} +5 -7
- package/expression/{parsing_context.js → parsing_context.ts} +47 -34
- package/expression/{parsing_error.js → parsing_error.ts} +0 -2
- package/expression/{runtime_error.js → runtime_error.ts} +0 -2
- package/expression/{scope.js → scope.ts} +5 -5
- package/expression/{stops.js → stops.ts} +2 -4
- package/expression/types/{collator.js → collator.ts} +1 -3
- package/expression/types/{formatted.js → formatted.ts} +8 -7
- package/expression/types/{resolved_image.js → resolved_image.ts} +5 -7
- package/expression/{types.js → types.ts} +53 -45
- package/expression/{values.js → values.ts} +12 -12
- package/feature_filter/{convert.js → convert.ts} +19 -18
- package/feature_filter/{index.js → index.ts} +39 -21
- package/{format.js → format.ts} +3 -3
- package/function/{convert.js → convert.ts} +44 -44
- package/function/{index.js → index.ts} +12 -12
- package/{group_by_layout.js → group_by_layout.ts} +11 -8
- package/migrate/{expressions.js → expressions.ts} +7 -16
- package/migrate/{v8.js → v8.ts} +2 -2
- package/migrate/{v9.js → v9.ts} +2 -2
- package/{migrate.js → migrate.ts} +3 -3
- package/package.json +19 -18
- package/{read_style.js → read_style.ts} +5 -4
- package/reference/latest.ts +5 -0
- package/reference/v8.json +264 -7
- package/rollup.config.js +6 -24
- package/{style-spec.js → style-spec.ts} +41 -36
- package/test.js +3 -2
- package/types/config_options.ts +13 -0
- package/types/lut.ts +7 -0
- package/types/tile_id.ts +5 -0
- package/{types.js → types.ts} +527 -165
- package/util/{color.js → color.ts} +89 -3
- package/util/{color_spaces.js → color_spaces.ts} +12 -14
- package/util/{deep_equal.js → deep_equal.ts} +1 -3
- package/util/{extend.js → extend.ts} +1 -3
- package/util/{geometry_util.js → geometry_util.ts} +23 -11
- package/util/{get_type.js → get_type.ts} +1 -3
- package/util/{interpolate.js → interpolate.ts} +1 -3
- package/util/{properties.js → properties.ts} +5 -4
- package/util/{random.js → random.ts} +0 -2
- package/util/{ref_properties.js → ref_properties.ts} +0 -1
- package/util/{result.js → result.ts} +7 -5
- package/util/{unbundle_jsonlint.js → unbundle_jsonlint.ts} +5 -5
- package/validate/{validate.js → validate.ts} +33 -35
- package/validate/{validate_array.js → validate_array.ts} +5 -7
- package/validate/{validate_boolean.js → validate_boolean.ts} +3 -5
- package/validate/{validate_color.js → validate_color.ts} +3 -5
- package/validate/{validate_enum.js → validate_enum.ts} +4 -5
- package/validate/{validate_expression.js → validate_expression.ts} +7 -9
- package/validate/{validate_filter.js → validate_filter.ts} +16 -12
- package/validate/{validate_fog.js → validate_fog.ts} +4 -6
- package/validate/validate_formatted.ts +13 -0
- package/validate/{validate_function.js → validate_function.ts} +14 -16
- package/validate/{validate_glyphs_url.js → validate_glyphs_url.ts} +3 -5
- package/validate/validate_image.ts +13 -0
- package/validate/{validate_import.js → validate_import.ts} +6 -8
- package/validate/{validate_layer.js → validate_layer.ts} +17 -15
- package/validate/{validate_layout_property.js → validate_layout_property.ts} +3 -5
- package/validate/{validate_light.js → validate_light.ts} +4 -6
- package/validate/{validate_lights.js → validate_lights.ts} +7 -9
- package/validate/{validate_model.js → validate_model.ts} +4 -6
- package/validate/{validate_number.js → validate_number.ts} +4 -6
- package/validate/{validate_object.js → validate_object.ts} +5 -8
- package/validate/{validate_paint_property.js → validate_paint_property.ts} +3 -5
- package/validate/{validate_projection.js → validate_projection.ts} +4 -6
- package/validate/{validate_property.js → validate_property.ts} +15 -15
- package/validate/{validate_source.js → validate_source.ts} +16 -13
- package/validate/validate_string.ts +16 -0
- package/validate/validate_style.ts +33 -0
- package/validate/{validate_terrain.js → validate_terrain.ts} +5 -7
- package/{validate_mapbox_api_supported.js → validate_mapbox_api_supported.ts} +22 -18
- package/{validate_style.min.js → validate_style.min.ts} +20 -21
- package/{validate_style.js → validate_style.ts} +9 -9
- package/{visit.js → visit.ts} +22 -17
- package/.eslintrc +0 -10
- package/expression/expression.js +0 -28
- package/flow-typed/cheap-ruler.js +0 -25
- package/flow-typed/geojson.js +0 -44
- package/flow-typed/gl-matrix.js +0 -119
- package/flow-typed/gl.js +0 -5
- package/flow-typed/intl.js +0 -58
- package/flow-typed/kdbush.js +0 -9
- package/flow-typed/mapbox-gl-supported.js +0 -16
- package/flow-typed/mapbox-unitbezier.js +0 -14
- package/flow-typed/offscreen-canvas.js +0 -9
- package/flow-typed/pbf.js +0 -26
- package/flow-typed/point-geometry.js +0 -46
- package/flow-typed/potpack.js +0 -13
- package/flow-typed/tiny-sdf.js +0 -31
- package/flow-typed/tracked_parameters_proxy.js +0 -82
- package/flow-typed/vector-tile.js +0 -49
- package/flow-typed/webgl2.js +0 -41
- package/reference/latest.js +0 -7
- package/validate/validate_formatted.js +0 -15
- package/validate/validate_image.js +0 -15
- package/validate/validate_string.js +0 -18
- package/validate/validate_style.js +0 -29
|
@@ -1,27 +1,25 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
import {isExpression} from '../expression/index.js';
|
|
10
|
-
import {unbundle, deepUnbundle} from '../util/unbundle_jsonlint.js';
|
|
1
|
+
import ValidationError from '../error/validation_error';
|
|
2
|
+
import getType from '../util/get_type';
|
|
3
|
+
import validate from './validate';
|
|
4
|
+
import validateObject from './validate_object';
|
|
5
|
+
import validateArray from './validate_array';
|
|
6
|
+
import validateNumber from './validate_number';
|
|
7
|
+
import {isExpression} from '../expression/index';
|
|
8
|
+
import {unbundle, deepUnbundle} from '../util/unbundle_jsonlint';
|
|
11
9
|
import {
|
|
12
10
|
supportsPropertyExpression,
|
|
13
11
|
supportsZoomExpression,
|
|
14
12
|
supportsInterpolation
|
|
15
|
-
} from '../util/properties
|
|
13
|
+
} from '../util/properties';
|
|
16
14
|
|
|
17
|
-
import type {ValidationOptions} from './validate
|
|
15
|
+
import type {ValidationOptions} from './validate';
|
|
18
16
|
|
|
19
17
|
export default function validateFunction(options: ValidationOptions): any {
|
|
20
18
|
const functionValueSpec = options.valueSpec;
|
|
21
19
|
const functionType = unbundle(options.value.type);
|
|
22
20
|
let stopKeyType;
|
|
23
|
-
let stopDomainValues:
|
|
24
|
-
let previousStopDomainValue:
|
|
21
|
+
let stopDomainValues: Partial<Record<string | number, boolean>> = {};
|
|
22
|
+
let previousStopDomainValue: unknown | null | undefined;
|
|
25
23
|
let previousStopDomainZoom;
|
|
26
24
|
|
|
27
25
|
const isZoomFunction = functionType !== 'categorical' && options.value.property === undefined;
|
|
@@ -195,10 +193,10 @@ export default function validateFunction(options: ValidationOptions): any {
|
|
|
195
193
|
previousStopDomainValue = value;
|
|
196
194
|
}
|
|
197
195
|
|
|
198
|
-
if (functionType === 'categorical' && (value
|
|
196
|
+
if (functionType === 'categorical' && (value as any) in stopDomainValues) {
|
|
199
197
|
return [new ValidationError(options.key, reportValue, 'stop domain values must be unique')];
|
|
200
198
|
} else {
|
|
201
|
-
stopDomainValues[(value
|
|
199
|
+
stopDomainValues[(value as any)] = true;
|
|
202
200
|
}
|
|
203
201
|
|
|
204
202
|
return [];
|
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
import ValidationError from '../error/validation_error';
|
|
2
|
+
import validateString from './validate_string';
|
|
2
3
|
|
|
3
|
-
import
|
|
4
|
-
import validateString from './validate_string.js';
|
|
5
|
-
|
|
6
|
-
import type {ValidationOptions} from './validate.js';
|
|
4
|
+
import type {ValidationOptions} from './validate';
|
|
7
5
|
|
|
8
6
|
export default function(options: ValidationOptions): Array<ValidationError> {
|
|
9
7
|
const value = options.value;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import validateExpression from './validate_expression';
|
|
2
|
+
import validateString from './validate_string';
|
|
3
|
+
|
|
4
|
+
import type {ValidationOptions} from './validate';
|
|
5
|
+
import type ValidationError from '../error/validation_error';
|
|
6
|
+
|
|
7
|
+
export default function validateImage(options: ValidationOptions): Array<ValidationError> {
|
|
8
|
+
if (validateString(options).length === 0) {
|
|
9
|
+
return [];
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
return validateExpression(options);
|
|
13
|
+
}
|
|
@@ -1,12 +1,10 @@
|
|
|
1
|
-
|
|
1
|
+
import extend from '../util/extend';
|
|
2
|
+
import validateStyle from './validate_style';
|
|
3
|
+
import validateObject from './validate_object';
|
|
4
|
+
import ValidationError from '../error/validation_error';
|
|
5
|
+
import {unbundle} from '../util/unbundle_jsonlint';
|
|
2
6
|
|
|
3
|
-
import
|
|
4
|
-
import validateStyle from './validate_style.js';
|
|
5
|
-
import validateObject from './validate_object.js';
|
|
6
|
-
import ValidationError from '../error/validation_error.js';
|
|
7
|
-
import {unbundle} from '../util/unbundle_jsonlint.js';
|
|
8
|
-
|
|
9
|
-
import type {ValidationOptions} from './validate.js';
|
|
7
|
+
import type {ValidationOptions} from './validate';
|
|
10
8
|
|
|
11
9
|
export default function validateImport(options: ValidationOptions): ValidationError[] {
|
|
12
10
|
const {value, styleSpec} = options;
|
|
@@ -1,21 +1,19 @@
|
|
|
1
|
-
|
|
1
|
+
import ValidationError from '../error/validation_error';
|
|
2
|
+
import {unbundle} from '../util/unbundle_jsonlint';
|
|
3
|
+
import validateObject from './validate_object';
|
|
4
|
+
import validateFilter from './validate_filter';
|
|
5
|
+
import validatePaintProperty from './validate_paint_property';
|
|
6
|
+
import validateLayoutProperty from './validate_layout_property';
|
|
7
|
+
import validateSpec from './validate';
|
|
8
|
+
import extend from '../util/extend';
|
|
2
9
|
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
5
|
-
import validateObject from './validate_object.js';
|
|
6
|
-
import validateFilter from './validate_filter.js';
|
|
7
|
-
import validatePaintProperty from './validate_paint_property.js';
|
|
8
|
-
import validateLayoutProperty from './validate_layout_property.js';
|
|
9
|
-
import validateSpec from './validate.js';
|
|
10
|
-
import extend from '../util/extend.js';
|
|
11
|
-
|
|
12
|
-
import type {ValidationOptions} from './validate.js';
|
|
13
|
-
import type {LayerSpecification} from '../types.js';
|
|
10
|
+
import type {ValidationOptions} from './validate';
|
|
11
|
+
import type {LayerSpecification} from '../types';
|
|
14
12
|
|
|
15
13
|
type Options = ValidationOptions & {
|
|
16
14
|
value: LayerSpecification;
|
|
17
15
|
arrayIndex: number;
|
|
18
|
-
}
|
|
16
|
+
};
|
|
19
17
|
|
|
20
18
|
export default function validateLayer(options: Options): Array<ValidationError> {
|
|
21
19
|
let errors = [];
|
|
@@ -36,7 +34,7 @@ export default function validateLayer(options: Options): Array<ValidationError>
|
|
|
36
34
|
for (let i = 0; i < options.arrayIndex; i++) {
|
|
37
35
|
const otherLayer = style.layers[i];
|
|
38
36
|
if (unbundle(otherLayer.id) === layerId) {
|
|
39
|
-
//
|
|
37
|
+
// @ts-expect-error - TS2339 - Property '__line__' does not exist on type 'string'.
|
|
40
38
|
errors.push(new ValidationError(key, layer.id, `duplicate layer id "${layer.id}", previously used at line ${otherLayer.id.__line__}`));
|
|
41
39
|
}
|
|
42
40
|
}
|
|
@@ -58,7 +56,6 @@ export default function validateLayer(options: Options): Array<ValidationError>
|
|
|
58
56
|
if (!parent) {
|
|
59
57
|
if (typeof ref === 'string')
|
|
60
58
|
errors.push(new ValidationError(key, layer.ref, `ref layer "${ref}" not found`));
|
|
61
|
-
// $FlowFixMe[prop-missing] - ref is not defined on the LayerSpecification subtypes
|
|
62
59
|
} else if (parent.ref) {
|
|
63
60
|
errors.push(new ValidationError(key, layer.ref, 'ref cannot reference another ref layer'));
|
|
64
61
|
} else {
|
|
@@ -80,9 +77,11 @@ export default function validateLayer(options: Options): Array<ValidationError>
|
|
|
80
77
|
errors.push(new ValidationError(key, layer, `layer "${layer.id}" must specify a "source-layer"`));
|
|
81
78
|
} else if (sourceType === 'raster-dem' && type !== 'hillshade') {
|
|
82
79
|
errors.push(new ValidationError(key, layer.source, 'raster-dem source can only be used with layer type \'hillshade\'.'));
|
|
80
|
+
// @ts-expect-error - TS2345 - Argument of type 'unknown' is not assignable to parameter of type 'string'.
|
|
83
81
|
} else if (sourceType === 'raster-array' && !['raster', 'raster-particle'].includes(type)) {
|
|
84
82
|
errors.push(new ValidationError(key, layer.source, `raster-array source can only be used with layer type \'raster\'.`));
|
|
85
83
|
} else if (type === 'line' && layer.paint && (layer.paint['line-gradient'] || layer.paint['line-trim-offset']) &&
|
|
84
|
+
// @ts-expect-error - TS2339 - Property 'lineMetrics' does not exist on type 'SourceSpecification'.
|
|
86
85
|
(sourceType !== 'geojson' || !source.lineMetrics)) {
|
|
87
86
|
errors.push(new ValidationError(key, layer, `layer "${layer.id}" specifies a line-gradient, which requires a GeoJSON source with \`lineMetrics\` enabled.`));
|
|
88
87
|
} else if (type === 'raster-particle' && sourceType !== 'raster-array') {
|
|
@@ -110,6 +109,7 @@ export default function validateLayer(options: Options): Array<ValidationError>
|
|
|
110
109
|
valueSpec: styleSpec.layer.type,
|
|
111
110
|
style: options.style,
|
|
112
111
|
styleSpec: options.styleSpec,
|
|
112
|
+
// @ts-expect-error - TS2353 - Object literal may only specify known properties, and 'object' does not exist in type 'ValidationOptions'.
|
|
113
113
|
object: layer,
|
|
114
114
|
objectKey: 'type'
|
|
115
115
|
});
|
|
@@ -119,6 +119,7 @@ export default function validateLayer(options: Options): Array<ValidationError>
|
|
|
119
119
|
},
|
|
120
120
|
layout(options) {
|
|
121
121
|
return validateObject({
|
|
122
|
+
// @ts-expect-error - TS2353 - Object literal may only specify known properties, and 'layer' does not exist in type 'Options'.
|
|
122
123
|
layer,
|
|
123
124
|
key: options.key,
|
|
124
125
|
value: options.value,
|
|
@@ -134,6 +135,7 @@ export default function validateLayer(options: Options): Array<ValidationError>
|
|
|
134
135
|
},
|
|
135
136
|
paint(options) {
|
|
136
137
|
return validateObject({
|
|
138
|
+
// @ts-expect-error - TS2353 - Object literal may only specify known properties, and 'layer' does not exist in type 'Options'.
|
|
137
139
|
layer,
|
|
138
140
|
key: options.key,
|
|
139
141
|
value: options.value,
|
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
import validateProperty from './validate_property';
|
|
2
2
|
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
import type ValidationError from '../error/validation_error.js';
|
|
6
|
-
import type {PropertyValidationOptions} from './validate_property.js';
|
|
3
|
+
import type ValidationError from '../error/validation_error';
|
|
4
|
+
import type {PropertyValidationOptions} from './validate_property';
|
|
7
5
|
|
|
8
6
|
export default function validateLayoutProperty(options: PropertyValidationOptions): Array<ValidationError> {
|
|
9
7
|
return validateProperty(options, 'layout');
|
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
import ValidationError from '../error/validation_error';
|
|
2
|
+
import getType from '../util/get_type';
|
|
3
|
+
import validate from './validate';
|
|
2
4
|
|
|
3
|
-
import
|
|
4
|
-
import getType from '../util/get_type.js';
|
|
5
|
-
import validate from './validate.js';
|
|
6
|
-
|
|
7
|
-
import type {ValidationOptions} from './validate.js';
|
|
5
|
+
import type {ValidationOptions} from './validate';
|
|
8
6
|
|
|
9
7
|
export default function validateLight(options: ValidationOptions): Array<ValidationError> {
|
|
10
8
|
const light = options.value;
|
|
@@ -1,15 +1,13 @@
|
|
|
1
|
-
|
|
1
|
+
import {default as ValidationError, ValidationWarning} from '../error/validation_error';
|
|
2
|
+
import getType from '../util/get_type';
|
|
3
|
+
import validate from './validate';
|
|
4
|
+
import {unbundle} from '../util/unbundle_jsonlint';
|
|
2
5
|
|
|
3
|
-
import {
|
|
4
|
-
import getType from '../util/get_type.js';
|
|
5
|
-
import validate from './validate.js';
|
|
6
|
-
import {unbundle} from '../util/unbundle_jsonlint.js';
|
|
7
|
-
|
|
8
|
-
import type {ValidationOptions} from './validate.js';
|
|
6
|
+
import type {ValidationOptions} from './validate';
|
|
9
7
|
|
|
10
8
|
type Options = ValidationOptions & {
|
|
11
9
|
arrayIndex: number;
|
|
12
|
-
}
|
|
10
|
+
};
|
|
13
11
|
|
|
14
12
|
export default function validateLights(options: Options): Array<ValidationError> {
|
|
15
13
|
const light = options.value;
|
|
@@ -43,7 +41,7 @@ export default function validateLights(options: Options): Array<ValidationError>
|
|
|
43
41
|
const lightType = unbundle(light.type);
|
|
44
42
|
const otherLight = lights[i];
|
|
45
43
|
if (unbundle(otherLight.type) === lightType) {
|
|
46
|
-
//
|
|
44
|
+
// @ts-expect-error - TS2339 - Property '__line__' does not exist on type 'string'.
|
|
47
45
|
errors.push(new ValidationError(key, light.id, `duplicate light type "${light.type}", previously defined at line ${otherLight.id.__line__}`));
|
|
48
46
|
}
|
|
49
47
|
}
|
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
import ValidationError from '../error/validation_error';
|
|
2
|
+
import getType from '../util/get_type';
|
|
2
3
|
|
|
3
|
-
import
|
|
4
|
-
import getType from '../util/get_type.js';
|
|
5
|
-
|
|
6
|
-
import type {ValidationOptions} from './validate.js';
|
|
4
|
+
import type {ValidationOptions} from './validate';
|
|
7
5
|
|
|
8
6
|
// Allow any URL, use dummy base, if it's a relative URL
|
|
9
7
|
export function isValidUrl(str: string, allowRelativeUrls: boolean): boolean {
|
|
@@ -11,7 +9,7 @@ export function isValidUrl(str: string, allowRelativeUrls: boolean): boolean {
|
|
|
11
9
|
try {
|
|
12
10
|
new URL(str, isRelative && allowRelativeUrls ? 'http://example.com' : undefined);
|
|
13
11
|
return true;
|
|
14
|
-
} catch (_) {
|
|
12
|
+
} catch (_: any) {
|
|
15
13
|
return false;
|
|
16
14
|
}
|
|
17
15
|
}
|
|
@@ -1,13 +1,11 @@
|
|
|
1
|
-
|
|
1
|
+
import getType from '../util/get_type';
|
|
2
|
+
import ValidationError from '../error/validation_error';
|
|
2
3
|
|
|
3
|
-
import
|
|
4
|
-
import ValidationError from '../error/validation_error.js';
|
|
5
|
-
|
|
6
|
-
import type {ValidationOptions} from './validate.js';
|
|
4
|
+
import type {ValidationOptions} from './validate';
|
|
7
5
|
|
|
8
6
|
type Options = ValidationOptions & {
|
|
9
7
|
arrayIndex: number;
|
|
10
|
-
}
|
|
8
|
+
};
|
|
11
9
|
|
|
12
10
|
export default function validateNumber(options: Options): Array<ValidationError> {
|
|
13
11
|
const key = options.key;
|
|
@@ -1,13 +1,11 @@
|
|
|
1
|
-
|
|
1
|
+
import {default as ValidationError, ValidationWarning} from '../error/validation_error';
|
|
2
|
+
import getType from '../util/get_type';
|
|
3
|
+
import validateSpec from './validate';
|
|
2
4
|
|
|
3
|
-
import {
|
|
4
|
-
import getType from '../util/get_type.js';
|
|
5
|
-
import validateSpec from './validate.js';
|
|
6
|
-
|
|
7
|
-
import type {ValidationOptions} from './validate.js';
|
|
5
|
+
import type {ValidationOptions} from './validate';
|
|
8
6
|
|
|
9
7
|
type Options = ValidationOptions & {
|
|
10
|
-
objectElementValidators?:
|
|
8
|
+
objectElementValidators?: any;
|
|
11
9
|
};
|
|
12
10
|
|
|
13
11
|
export default function validateObject(options: Options): Array<ValidationError> {
|
|
@@ -52,7 +50,6 @@ export default function validateObject(options: Options): Array<ValidationError>
|
|
|
52
50
|
styleSpec,
|
|
53
51
|
object,
|
|
54
52
|
objectKey
|
|
55
|
-
// $FlowFixMe[extra-arg]
|
|
56
53
|
}, object));
|
|
57
54
|
}
|
|
58
55
|
|
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
import validateProperty from './validate_property';
|
|
2
2
|
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
import type ValidationError from '../error/validation_error.js';
|
|
6
|
-
import type {PropertyValidationOptions} from './validate_property.js';
|
|
3
|
+
import type ValidationError from '../error/validation_error';
|
|
4
|
+
import type {PropertyValidationOptions} from './validate_property';
|
|
7
5
|
|
|
8
6
|
export default function validatePaintProperty(options: PropertyValidationOptions): Array<ValidationError> {
|
|
9
7
|
return validateProperty(options, 'paint');
|
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
import ValidationError from '../error/validation_error';
|
|
2
|
+
import getType from '../util/get_type';
|
|
3
|
+
import validate from './validate';
|
|
2
4
|
|
|
3
|
-
import
|
|
4
|
-
import getType from '../util/get_type.js';
|
|
5
|
-
import validate from './validate.js';
|
|
6
|
-
|
|
7
|
-
import type {ValidationOptions} from './validate.js';
|
|
5
|
+
import type {ValidationOptions} from './validate';
|
|
8
6
|
|
|
9
7
|
export default function validateProjection(options: ValidationOptions): Array<ValidationError> {
|
|
10
8
|
const projection = options.value;
|
|
@@ -1,21 +1,19 @@
|
|
|
1
|
-
|
|
1
|
+
import validate from './validate';
|
|
2
|
+
import {default as ValidationError, ValidationWarning} from '../error/validation_error';
|
|
3
|
+
import getType from '../util/get_type';
|
|
4
|
+
import {isFunction} from '../function/index';
|
|
5
|
+
import {unbundle, deepUnbundle} from '../util/unbundle_jsonlint';
|
|
6
|
+
import {supportsLightExpression, supportsPropertyExpression, supportsZoomExpression} from '../util/properties';
|
|
7
|
+
import {isGlobalPropertyConstant, isFeatureConstant, isStateConstant} from '../expression/is_constant';
|
|
2
8
|
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
5
|
-
import getType from '../util/get_type.js';
|
|
6
|
-
import {isFunction} from '../function/index.js';
|
|
7
|
-
import {unbundle, deepUnbundle} from '../util/unbundle_jsonlint.js';
|
|
8
|
-
import {supportsLightExpression, supportsPropertyExpression, supportsZoomExpression} from '../util/properties.js';
|
|
9
|
-
import {isGlobalPropertyConstant, isFeatureConstant, isStateConstant} from '../expression/is_constant.js';
|
|
10
|
-
|
|
11
|
-
import type {ValidationOptions} from './validate.js';
|
|
12
|
-
import {createPropertyExpression} from '../expression/index.js';
|
|
9
|
+
import type {ValidationOptions} from './validate';
|
|
10
|
+
import {createPropertyExpression} from '../expression/index';
|
|
13
11
|
|
|
14
12
|
export type PropertyValidationOptions = ValidationOptions & {
|
|
15
13
|
objectKey: string;
|
|
16
14
|
layerType: string;
|
|
17
|
-
layer:
|
|
18
|
-
}
|
|
15
|
+
layer: any;
|
|
16
|
+
};
|
|
19
17
|
|
|
20
18
|
export default function validateProperty(options: PropertyValidationOptions, propertyType: string): Array<ValidationError> {
|
|
21
19
|
const key = options.key;
|
|
@@ -44,7 +42,8 @@ export default function validateProperty(options: PropertyValidationOptions, pro
|
|
|
44
42
|
return [new ValidationWarning(key, value, `unknown property "${propertyKey}"`)];
|
|
45
43
|
}
|
|
46
44
|
|
|
47
|
-
|
|
45
|
+
// @ts-expect-error - TS2702 - 'RegExp' only refers to a type, but is being used as a namespace here.
|
|
46
|
+
let tokenMatch: RegExp.matchResult | null | undefined;
|
|
48
47
|
if (getType(value) === 'string' && supportsPropertyExpression(valueSpec) && !valueSpec.tokens && (tokenMatch = /^{([^}]+)}$/.exec(value))) {
|
|
49
48
|
const example = `\`{ "type": "identity", "property": ${tokenMatch ? JSON.stringify(tokenMatch[1]) : '"_"'} }\``;
|
|
50
49
|
return [new ValidationError(
|
|
@@ -66,7 +65,7 @@ export default function validateProperty(options: PropertyValidationOptions, pro
|
|
|
66
65
|
if (supportsPropertyExpression(valueSpec) && (supportsLightExpression(valueSpec) || supportsZoomExpression(valueSpec))) {
|
|
67
66
|
// Performance related style spec limitation: zoom and light expressions are not allowed for e.g. trees.
|
|
68
67
|
const expression = createPropertyExpression(deepUnbundle(value), valueSpec);
|
|
69
|
-
const expressionObj = (expression.value
|
|
68
|
+
const expressionObj = (expression.value as any).expression || (expression.value as any)._styleExpression.expression;
|
|
70
69
|
|
|
71
70
|
if (expressionObj && !isGlobalPropertyConstant(expressionObj, ['measure-light'])) {
|
|
72
71
|
if (propertyKey !== 'model-emissive-strength' || (!isFeatureConstant(expressionObj) || !isStateConstant(expressionObj))) {
|
|
@@ -82,6 +81,7 @@ export default function validateProperty(options: PropertyValidationOptions, pro
|
|
|
82
81
|
valueSpec,
|
|
83
82
|
style,
|
|
84
83
|
styleSpec,
|
|
84
|
+
// @ts-expect-error - TS2353 - Object literal may only specify known properties, and 'expressionContext' does not exist in type 'ValidationOptions'.
|
|
85
85
|
expressionContext: 'property',
|
|
86
86
|
propertyType,
|
|
87
87
|
propertyKey
|
|
@@ -1,15 +1,13 @@
|
|
|
1
|
-
|
|
1
|
+
import {default as ValidationError, ValidationWarning} from '../error/validation_error';
|
|
2
|
+
import {unbundle} from '../util/unbundle_jsonlint';
|
|
3
|
+
import validateObject from './validate_object';
|
|
4
|
+
import validateEnum from './validate_enum';
|
|
5
|
+
import validateExpression from './validate_expression';
|
|
6
|
+
import validateString from './validate_string';
|
|
7
|
+
import getType from '../util/get_type';
|
|
2
8
|
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import validateObject from './validate_object.js';
|
|
6
|
-
import validateEnum from './validate_enum.js';
|
|
7
|
-
import validateExpression from './validate_expression.js';
|
|
8
|
-
import validateString from './validate_string.js';
|
|
9
|
-
import getType from '../util/get_type.js';
|
|
10
|
-
|
|
11
|
-
import type {StyleReference} from '../reference/latest.js';
|
|
12
|
-
import type {ValidationOptions} from './validate.js';
|
|
9
|
+
import type {StyleReference} from '../reference/latest';
|
|
10
|
+
import type {ValidationOptions} from './validate';
|
|
13
11
|
|
|
14
12
|
const objectElementValidators = {
|
|
15
13
|
promoteId: validatePromoteId
|
|
@@ -28,6 +26,7 @@ export default function validateSource(options: ValidationOptions): Array<Valida
|
|
|
28
26
|
const type = unbundle(value.type);
|
|
29
27
|
let errors = [];
|
|
30
28
|
|
|
29
|
+
// @ts-expect-error - TS2345 - Argument of type 'unknown' is not assignable to parameter of type 'string'.
|
|
31
30
|
if (['vector', 'raster', 'raster-dem', 'raster-array'].includes(type)) {
|
|
32
31
|
if (!value.url && !value.tiles) {
|
|
33
32
|
errors.push(new ValidationWarning(key, value, 'Either "url" or "tiles" is required.'));
|
|
@@ -110,7 +109,8 @@ export default function validateSource(options: ValidationOptions): Array<Valida
|
|
|
110
109
|
}
|
|
111
110
|
|
|
112
111
|
function getSourceTypeValues(styleSpec: StyleReference) {
|
|
113
|
-
|
|
112
|
+
// @ts-expect-error - TS2347 - Untyped function calls may not accept type arguments.
|
|
113
|
+
return styleSpec.source.reduce<Array<any>>((memo, source) => {
|
|
114
114
|
const sourceType = styleSpec[source];
|
|
115
115
|
if (sourceType.type.type === 'enum') {
|
|
116
116
|
memo = memo.concat(Object.keys(sourceType.type.values));
|
|
@@ -119,7 +119,10 @@ function getSourceTypeValues(styleSpec: StyleReference) {
|
|
|
119
119
|
}, []);
|
|
120
120
|
}
|
|
121
121
|
|
|
122
|
-
function validatePromoteId({
|
|
122
|
+
function validatePromoteId({
|
|
123
|
+
key,
|
|
124
|
+
value,
|
|
125
|
+
}: Partial<ValidationOptions>) {
|
|
123
126
|
if (getType(value) === 'string') {
|
|
124
127
|
return validateString({key, value});
|
|
125
128
|
} else {
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import getType from '../util/get_type';
|
|
2
|
+
import ValidationError from '../error/validation_error';
|
|
3
|
+
|
|
4
|
+
import type {ValidationOptions} from './validate';
|
|
5
|
+
|
|
6
|
+
export default function validateString(options: Partial<ValidationOptions>): Array<ValidationError> {
|
|
7
|
+
const value = options.value;
|
|
8
|
+
const key = options.key;
|
|
9
|
+
const type = getType(value);
|
|
10
|
+
|
|
11
|
+
if (type !== 'string') {
|
|
12
|
+
return [new ValidationError(key, value, `string expected, ${type} found`)];
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
return [];
|
|
16
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import validate from './validate';
|
|
2
|
+
import latestStyleSpec from '../reference/latest';
|
|
3
|
+
import validateGlyphsURL from './validate_glyphs_url';
|
|
4
|
+
|
|
5
|
+
import ValidationError from '../error/validation_error';
|
|
6
|
+
|
|
7
|
+
import type {ValidationOptions} from './validate';
|
|
8
|
+
import type {StyleSpecification} from '../types';
|
|
9
|
+
|
|
10
|
+
type StyleValidationOptions = {
|
|
11
|
+
key?: ValidationOptions['key'];
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export default function validateStyle(
|
|
15
|
+
style: StyleSpecification,
|
|
16
|
+
styleSpec: any = latestStyleSpec,
|
|
17
|
+
options: StyleValidationOptions = {},
|
|
18
|
+
): ValidationError[] {
|
|
19
|
+
const errors = validate({
|
|
20
|
+
key: options.key || '',
|
|
21
|
+
value: style,
|
|
22
|
+
valueSpec: styleSpec.$root,
|
|
23
|
+
styleSpec,
|
|
24
|
+
style,
|
|
25
|
+
// @ts-expect-error - TS2353 - Object literal may only specify known properties, and 'objectElementValidators' does not exist in type 'ValidationOptions'.
|
|
26
|
+
objectElementValidators: {
|
|
27
|
+
glyphs: validateGlyphsURL,
|
|
28
|
+
'*': () => []
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
return errors;
|
|
33
|
+
}
|
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
import {default as ValidationError, ValidationWarning} from '../error/validation_error';
|
|
2
|
+
import validate from './validate';
|
|
3
|
+
import getType from '../util/get_type';
|
|
4
|
+
import {unbundle} from '../util/unbundle_jsonlint';
|
|
2
5
|
|
|
3
|
-
import {
|
|
4
|
-
import validate from './validate.js';
|
|
5
|
-
import getType from '../util/get_type.js';
|
|
6
|
-
import {unbundle} from '../util/unbundle_jsonlint.js';
|
|
7
|
-
|
|
8
|
-
import type {ValidationOptions} from './validate.js';
|
|
6
|
+
import type {ValidationOptions} from './validate';
|
|
9
7
|
|
|
10
8
|
export default function validateTerrain(options: ValidationOptions): Array<ValidationError> {
|
|
11
9
|
const terrain = options.value;
|
|
@@ -1,22 +1,20 @@
|
|
|
1
|
-
|
|
1
|
+
import {validateStyle} from './validate_style.min';
|
|
2
|
+
import {v8} from './style-spec';
|
|
3
|
+
import readStyle from './read_style';
|
|
4
|
+
import ValidationError from './error/validation_error';
|
|
5
|
+
import getType from './util/get_type';
|
|
2
6
|
|
|
3
|
-
import {
|
|
4
|
-
import {v8} from './style-spec.js';
|
|
5
|
-
import readStyle from './read_style.js';
|
|
6
|
-
import ValidationError from './error/validation_error.js';
|
|
7
|
-
import getType from './util/get_type.js';
|
|
8
|
-
|
|
9
|
-
import type {ValidationErrors} from './validate_style.min.js';
|
|
7
|
+
import type {ValidationErrors} from './validate_style.min';
|
|
10
8
|
|
|
11
9
|
const SUPPORTED_SPEC_VERSION = 8;
|
|
12
10
|
const MAX_SOURCES_IN_STYLE = 15;
|
|
13
11
|
|
|
14
|
-
function isValid(value:
|
|
12
|
+
function isValid(value: string | null | undefined, regex: RegExp): boolean {
|
|
15
13
|
if (!value || getType(value) !== 'string') return true;
|
|
16
14
|
return !!value.match(regex);
|
|
17
15
|
}
|
|
18
16
|
|
|
19
|
-
function getSourceCount(source:
|
|
17
|
+
function getSourceCount(source: any): number {
|
|
20
18
|
if (source.url) {
|
|
21
19
|
return source.url.split(',').length;
|
|
22
20
|
} else {
|
|
@@ -24,7 +22,7 @@ function getSourceCount(source: Object): number {
|
|
|
24
22
|
}
|
|
25
23
|
}
|
|
26
24
|
|
|
27
|
-
function getAllowedKeyErrors(obj:
|
|
25
|
+
function getAllowedKeyErrors(obj: any, keys: Array<any>, path?: string | null): Array<ValidationError> {
|
|
28
26
|
const allowed = new Set(keys);
|
|
29
27
|
const errors = [];
|
|
30
28
|
Object.keys(obj).forEach(k => {
|
|
@@ -37,7 +35,7 @@ function getAllowedKeyErrors(obj: Object, keys: Array<*>, path: ?string): Array<
|
|
|
37
35
|
}
|
|
38
36
|
|
|
39
37
|
const acceptedSourceTypes = new Set(["vector", "raster", "raster-dem", "raster-array", "model", "batched-model"]);
|
|
40
|
-
function getSourceErrors(source:
|
|
38
|
+
function getSourceErrors(source: any, i: number): Array<ValidationError> {
|
|
41
39
|
const errors = [];
|
|
42
40
|
|
|
43
41
|
/*
|
|
@@ -76,7 +74,10 @@ function getMaxSourcesErrors(sourcesCount: number): Array<ValidationError> {
|
|
|
76
74
|
return errors;
|
|
77
75
|
}
|
|
78
76
|
|
|
79
|
-
function getSourcesErrors(sources:
|
|
77
|
+
function getSourcesErrors(sources: any): {
|
|
78
|
+
errors: Array<ValidationError>;
|
|
79
|
+
sourcesCount: number;
|
|
80
|
+
} {
|
|
80
81
|
const errors = [];
|
|
81
82
|
let sourcesCount = 0;
|
|
82
83
|
|
|
@@ -94,11 +95,14 @@ function getSourcesErrors(sources: Object): {errors: Array<ValidationError>, sou
|
|
|
94
95
|
return {errors, sourcesCount};
|
|
95
96
|
}
|
|
96
97
|
|
|
97
|
-
function getImportErrors(imports: Array<
|
|
98
|
+
function getImportErrors(imports: Array<any> = []): {
|
|
99
|
+
errors: Array<ValidationError>;
|
|
100
|
+
sourcesCount: number;
|
|
101
|
+
} {
|
|
98
102
|
let errors: Array<ValidationError> = [];
|
|
99
103
|
|
|
100
104
|
let sourcesCount = 0;
|
|
101
|
-
const validateImports = (imports: Array<
|
|
105
|
+
const validateImports = (imports: Array<any> = []) => {
|
|
102
106
|
for (const importSpec of imports) {
|
|
103
107
|
const style = importSpec.data;
|
|
104
108
|
if (!style) continue;
|
|
@@ -125,7 +129,7 @@ function getImportErrors(imports: Array<Object> = []): {errors: Array<Validation
|
|
|
125
129
|
return {errors, sourcesCount};
|
|
126
130
|
}
|
|
127
131
|
|
|
128
|
-
function getRootErrors(style:
|
|
132
|
+
function getRootErrors(style: any, specKeys: Array<any>): Array<ValidationError> {
|
|
129
133
|
const errors = [];
|
|
130
134
|
|
|
131
135
|
/*
|
|
@@ -204,11 +208,11 @@ function getRootErrors(style: Object, specKeys: Array<any>): Array<ValidationErr
|
|
|
204
208
|
* var validateMapboxApiSupported = require('mapbox-gl-style-spec/lib/validate_style_mapbox_api_supported.js');
|
|
205
209
|
* var errors = validateMapboxApiSupported(style);
|
|
206
210
|
*/
|
|
207
|
-
export default function validateMapboxApiSupported(style:
|
|
211
|
+
export default function validateMapboxApiSupported(style: any, styleSpec: any = v8): ValidationErrors {
|
|
208
212
|
let s = style;
|
|
209
213
|
try {
|
|
210
214
|
s = readStyle(s);
|
|
211
|
-
} catch (e) {
|
|
215
|
+
} catch (e: any) {
|
|
212
216
|
return [e];
|
|
213
217
|
}
|
|
214
218
|
|