@mapbox/mapbox-gl-style-spec 14.12.0-beta.1 → 14.13.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/composite.ts +2 -0
- package/deref.ts +5 -5
- package/diff.ts +21 -21
- package/dist/index.cjs +455 -241
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +64 -30
- package/dist/index.es.js +455 -241
- package/dist/index.es.js.map +1 -1
- package/error/validation_error.ts +1 -3
- package/expression/definitions/assertion.ts +2 -1
- package/expression/definitions/at.ts +1 -1
- package/expression/definitions/at_interpolated.ts +1 -1
- package/expression/definitions/case.ts +3 -1
- package/expression/definitions/coalesce.ts +1 -0
- package/expression/definitions/coercion.ts +3 -1
- package/expression/definitions/collator.ts +2 -1
- package/expression/definitions/comparison.ts +15 -1
- package/expression/definitions/config.ts +33 -10
- package/expression/definitions/distance.ts +6 -4
- package/expression/definitions/format.ts +3 -2
- package/expression/definitions/index.ts +29 -3
- package/expression/definitions/index_of.ts +1 -0
- package/expression/definitions/interpolate.ts +5 -1
- package/expression/definitions/let.ts +1 -0
- package/expression/definitions/literal.ts +3 -3
- package/expression/definitions/match.ts +5 -3
- package/expression/definitions/number_format.ts +3 -4
- package/expression/definitions/slice.ts +1 -0
- package/expression/definitions/step.ts +1 -0
- package/expression/definitions/var.ts +1 -0
- package/expression/definitions/within.ts +6 -2
- package/expression/expression.ts +3 -0
- package/expression/index.ts +18 -3
- package/expression/is_constant.ts +4 -0
- package/expression/parsing_context.ts +1 -1
- package/expression/types/formatted.ts +1 -1
- package/expression/types/image_variant.ts +2 -2
- package/expression/types.ts +9 -0
- package/expression/values.ts +1 -3
- package/feature_filter/convert.ts +13 -6
- package/feature_filter/index.ts +16 -0
- package/format.ts +1 -0
- package/function/convert.ts +5 -1
- package/function/index.ts +28 -0
- package/group_by_layout.ts +17 -8
- package/migrate/expressions.ts +2 -2
- package/migrate/v8.ts +9 -0
- package/migrate/v9.ts +1 -0
- package/migrate.ts +1 -0
- package/package.json +1 -1
- package/read_style.ts +1 -0
- package/reference/latest.ts +1 -0
- package/reference/v8.json +209 -21
- package/types.ts +21 -2
- package/union-to-intersection.ts +1 -1
- package/util/color.ts +85 -69
- package/util/extend.ts +1 -0
- package/util/geometry_util.ts +7 -8
- package/util/interpolate.ts +0 -4
- package/validate/validate.ts +6 -0
- package/validate/validate_array.ts +2 -0
- package/validate/validate_enum.ts +1 -0
- package/validate/validate_expression.ts +4 -0
- package/validate/validate_filter.ts +4 -2
- package/validate/validate_fog.ts +3 -0
- package/validate/validate_function.ts +7 -2
- package/validate/validate_iconset.ts +1 -0
- package/validate/validate_layer.ts +1 -0
- package/validate/validate_light.ts +3 -0
- package/validate/validate_lights.ts +27 -21
- package/validate/validate_model.ts +4 -0
- package/validate/validate_object.ts +2 -2
- package/validate/validate_projection.ts +1 -0
- package/validate/validate_property.ts +4 -0
- package/validate/validate_rain.ts +3 -0
- package/validate/validate_snow.ts +3 -0
- package/validate/validate_source.ts +8 -6
- package/validate/validate_terrain.ts +4 -0
- package/validate_mapbox_api_supported.ts +30 -19
- package/validate_style.ts +1 -0
- package/visit.ts +3 -1
|
@@ -15,12 +15,14 @@ export default function validateLights(options: Options): Array<ValidationError>
|
|
|
15
15
|
let errors = [];
|
|
16
16
|
|
|
17
17
|
if (!light) {
|
|
18
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
18
19
|
return errors;
|
|
19
20
|
}
|
|
20
21
|
|
|
21
22
|
const type = getType(light);
|
|
22
23
|
if (type !== 'object') {
|
|
23
24
|
errors = errors.concat([new ValidationError('light-3d', light, `object expected, ${type} found`)]);
|
|
25
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
24
26
|
return errors;
|
|
25
27
|
}
|
|
26
28
|
|
|
@@ -33,6 +35,7 @@ export default function validateLights(options: Options): Array<ValidationError>
|
|
|
33
35
|
for (const key of ['type', 'id']) {
|
|
34
36
|
if (!(key in light)) {
|
|
35
37
|
errors = errors.concat([new ValidationError('light-3d', light, `missing property ${key} on light`)]);
|
|
38
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
36
39
|
return errors;
|
|
37
40
|
}
|
|
38
41
|
}
|
|
@@ -51,6 +54,7 @@ export default function validateLights(options: Options): Array<ValidationError>
|
|
|
51
54
|
const lightType = `properties_light_${light['type']}`;
|
|
52
55
|
if (!(lightType in styleSpec)) {
|
|
53
56
|
errors = errors.concat([new ValidationError('light-3d', light, `Invalid light type ${light['type']}`)]);
|
|
57
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
54
58
|
return errors;
|
|
55
59
|
}
|
|
56
60
|
|
|
@@ -62,10 +66,30 @@ export default function validateLights(options: Options): Array<ValidationError>
|
|
|
62
66
|
const propertiesType = getType(properties);
|
|
63
67
|
if (propertiesType !== 'object') {
|
|
64
68
|
errors = errors.concat([new ValidationError('properties', properties, `object expected, ${propertiesType} found`)]);
|
|
69
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
65
70
|
return errors;
|
|
66
71
|
}
|
|
67
72
|
for (const propertyKey in properties) {
|
|
68
|
-
|
|
73
|
+
const transitionMatch = propertyKey.match(/^(.*)-transition$/);
|
|
74
|
+
const useThemeMatch = propertyKey.match(/^(.*)-use-theme$/);
|
|
75
|
+
|
|
76
|
+
if (useThemeMatch && lightPropertySpec[useThemeMatch[1]]) {
|
|
77
|
+
errors = errors.concat(validate({
|
|
78
|
+
key,
|
|
79
|
+
value: properties[propertyKey],
|
|
80
|
+
valueSpec: {type: 'string'},
|
|
81
|
+
style,
|
|
82
|
+
styleSpec
|
|
83
|
+
}));
|
|
84
|
+
} else if (transitionMatch && lightPropertySpec[transitionMatch[1]] && lightPropertySpec[transitionMatch[1]].transition) {
|
|
85
|
+
errors = errors.concat(validate({
|
|
86
|
+
key,
|
|
87
|
+
value: light[key],
|
|
88
|
+
valueSpec: styleSpec.transition,
|
|
89
|
+
style,
|
|
90
|
+
styleSpec
|
|
91
|
+
}));
|
|
92
|
+
} else if (!lightPropertySpec[propertyKey]) {
|
|
69
93
|
errors = errors.concat([new ValidationWarning(options.key, properties[propertyKey], `unknown property "${propertyKey}"`)]);
|
|
70
94
|
} else {
|
|
71
95
|
errors = errors.concat(validate({
|
|
@@ -78,26 +102,7 @@ export default function validateLights(options: Options): Array<ValidationError>
|
|
|
78
102
|
}
|
|
79
103
|
}
|
|
80
104
|
} else {
|
|
81
|
-
|
|
82
|
-
const useThemeMatch = key.match(/^(.*)-use-theme$/);
|
|
83
|
-
|
|
84
|
-
if (useThemeMatch && lightSpec[useThemeMatch[1]]) {
|
|
85
|
-
errors = errors.concat(validate({
|
|
86
|
-
key,
|
|
87
|
-
value: light[key],
|
|
88
|
-
valueSpec: {type: 'string'},
|
|
89
|
-
style,
|
|
90
|
-
styleSpec
|
|
91
|
-
}));
|
|
92
|
-
} else if (transitionMatch && lightSpec[transitionMatch[1]] && lightSpec[transitionMatch[1]].transition) {
|
|
93
|
-
errors = errors.concat(validate({
|
|
94
|
-
key,
|
|
95
|
-
value: light[key],
|
|
96
|
-
valueSpec: styleSpec.transition,
|
|
97
|
-
style,
|
|
98
|
-
styleSpec
|
|
99
|
-
}));
|
|
100
|
-
} else if (lightSpec[key]) {
|
|
105
|
+
if (lightSpec[key]) {
|
|
101
106
|
errors = errors.concat(validate({
|
|
102
107
|
key,
|
|
103
108
|
value: light[key],
|
|
@@ -111,5 +116,6 @@ export default function validateLights(options: Options): Array<ValidationError>
|
|
|
111
116
|
}
|
|
112
117
|
}
|
|
113
118
|
|
|
119
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
114
120
|
return errors;
|
|
115
121
|
}
|
|
@@ -9,6 +9,7 @@ export function isValidUrl(str: string, allowRelativeUrls: boolean): boolean {
|
|
|
9
9
|
try {
|
|
10
10
|
new URL(str, isRelative && allowRelativeUrls ? 'http://example.com' : undefined);
|
|
11
11
|
return true;
|
|
12
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
12
13
|
} catch (_: any) {
|
|
13
14
|
return false;
|
|
14
15
|
}
|
|
@@ -19,12 +20,14 @@ export default function validateModel(options: ValidationOptions): Array<Validat
|
|
|
19
20
|
let errors = [];
|
|
20
21
|
|
|
21
22
|
if (!url) {
|
|
23
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
22
24
|
return errors;
|
|
23
25
|
}
|
|
24
26
|
|
|
25
27
|
const type = getType(url);
|
|
26
28
|
if (type !== 'string') {
|
|
27
29
|
errors = errors.concat([new ValidationError(options.key, url, `string expected, "${type}" found`)]);
|
|
30
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
28
31
|
return errors;
|
|
29
32
|
}
|
|
30
33
|
|
|
@@ -32,5 +35,6 @@ export default function validateModel(options: ValidationOptions): Array<Validat
|
|
|
32
35
|
errors = errors.concat([new ValidationError(options.key, url, `invalid url "${url}"`)]);
|
|
33
36
|
}
|
|
34
37
|
|
|
38
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
35
39
|
return errors;
|
|
36
40
|
}
|
|
@@ -7,7 +7,7 @@ import type {LayerSpecification} from '../types';
|
|
|
7
7
|
|
|
8
8
|
type Options = ValidationOptions & {
|
|
9
9
|
layer?: LayerSpecification;
|
|
10
|
-
objectElementValidators?:
|
|
10
|
+
objectElementValidators?: object;
|
|
11
11
|
};
|
|
12
12
|
|
|
13
13
|
export default function validateObject(options: Options): Array<ValidationError> {
|
|
@@ -17,7 +17,7 @@ export default function validateObject(options: Options): Array<ValidationError>
|
|
|
17
17
|
const elementValidators = options.objectElementValidators || {};
|
|
18
18
|
const style = options.style;
|
|
19
19
|
const styleSpec = options.styleSpec;
|
|
20
|
-
let errors = [];
|
|
20
|
+
let errors: ValidationError[] = [];
|
|
21
21
|
|
|
22
22
|
const type = getType(object);
|
|
23
23
|
if (type !== 'object') {
|
|
@@ -28,5 +28,6 @@ export default function validateProjection(options: ValidationOptions): Array<Va
|
|
|
28
28
|
errors = errors.concat([new ValidationError('projection', projection, `object or string expected, ${rootType} found`)]);
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
31
32
|
return errors;
|
|
32
33
|
}
|
|
@@ -12,6 +12,7 @@ import type {ValidationOptions} from './validate';
|
|
|
12
12
|
export type PropertyValidationOptions = ValidationOptions & {
|
|
13
13
|
objectKey: string;
|
|
14
14
|
layerType: string;
|
|
15
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
15
16
|
layer: any;
|
|
16
17
|
};
|
|
17
18
|
|
|
@@ -30,6 +31,7 @@ export default function validateProperty(options: PropertyValidationOptions, pro
|
|
|
30
31
|
if (propertyType === 'paint' && useThemeMatch && layerSpec[useThemeMatch[1]]) {
|
|
31
32
|
if (isExpression(value)) {
|
|
32
33
|
const errors = [];
|
|
34
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
33
35
|
return errors.concat(validate({
|
|
34
36
|
key: options.key,
|
|
35
37
|
value,
|
|
@@ -99,6 +101,7 @@ export default function validateProperty(options: PropertyValidationOptions, pro
|
|
|
99
101
|
if (supportsPropertyExpression(valueSpec) && (supportsLightExpression(valueSpec) || supportsZoomExpression(valueSpec))) {
|
|
100
102
|
// Performance related style spec limitation: zoom and light expressions are not allowed for e.g. trees.
|
|
101
103
|
const expression = createPropertyExpression(deepUnbundle(value), valueSpec);
|
|
104
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
102
105
|
const expressionObj = (expression.value as any).expression || (expression.value as any)._styleExpression.expression;
|
|
103
106
|
|
|
104
107
|
if (expressionObj && !isGlobalPropertyConstant(expressionObj, ['measure-light'])) {
|
|
@@ -109,6 +112,7 @@ export default function validateProperty(options: PropertyValidationOptions, pro
|
|
|
109
112
|
}
|
|
110
113
|
}
|
|
111
114
|
|
|
115
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
112
116
|
return errors.concat(validate({
|
|
113
117
|
key: options.key,
|
|
114
118
|
value,
|
|
@@ -13,9 +13,11 @@ export default function validateRain(options: ValidationOptions): Array<Validati
|
|
|
13
13
|
|
|
14
14
|
const rootType = getType(rain);
|
|
15
15
|
if (rain === undefined) {
|
|
16
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
16
17
|
return errors;
|
|
17
18
|
} else if (rootType !== 'object') {
|
|
18
19
|
errors = errors.concat([new ValidationError('rain', rain, `object expected, ${rootType} found`)]);
|
|
20
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
19
21
|
return errors;
|
|
20
22
|
}
|
|
21
23
|
|
|
@@ -43,5 +45,6 @@ export default function validateRain(options: ValidationOptions): Array<Validati
|
|
|
43
45
|
}
|
|
44
46
|
}
|
|
45
47
|
|
|
48
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
46
49
|
return errors;
|
|
47
50
|
}
|
|
@@ -13,9 +13,11 @@ export default function validateSnow(options: ValidationOptions): Array<Validati
|
|
|
13
13
|
|
|
14
14
|
const rootType = getType(snow);
|
|
15
15
|
if (snow === undefined) {
|
|
16
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
16
17
|
return errors;
|
|
17
18
|
} else if (rootType !== 'object') {
|
|
18
19
|
errors = errors.concat([new ValidationError('snow', snow, `object expected, ${rootType} found`)]);
|
|
20
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
19
21
|
return errors;
|
|
20
22
|
}
|
|
21
23
|
|
|
@@ -43,5 +45,6 @@ export default function validateSnow(options: ValidationOptions): Array<Validati
|
|
|
43
45
|
}
|
|
44
46
|
}
|
|
45
47
|
|
|
48
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
46
49
|
return errors;
|
|
47
50
|
}
|
|
@@ -26,7 +26,7 @@ export default function validateSource(options: ValidationOptions): Array<Valida
|
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
const type = unbundle(value.type) as string;
|
|
29
|
-
let errors = [];
|
|
29
|
+
let errors: ValidationError[] = [];
|
|
30
30
|
|
|
31
31
|
if (['vector', 'raster', 'raster-dem', 'raster-array'].includes(type)) {
|
|
32
32
|
if (!value.url && !value.tiles) {
|
|
@@ -48,7 +48,6 @@ export default function validateSource(options: ValidationOptions): Array<Valida
|
|
|
48
48
|
objectElementValidators
|
|
49
49
|
}));
|
|
50
50
|
return errors;
|
|
51
|
-
|
|
52
51
|
case 'geojson':
|
|
53
52
|
errors = validateObject({
|
|
54
53
|
key,
|
|
@@ -58,6 +57,7 @@ export default function validateSource(options: ValidationOptions): Array<Valida
|
|
|
58
57
|
styleSpec,
|
|
59
58
|
objectElementValidators
|
|
60
59
|
});
|
|
60
|
+
|
|
61
61
|
if (value.cluster) {
|
|
62
62
|
for (const prop in value.clusterProperties) {
|
|
63
63
|
const [operator, mapExpr] = value.clusterProperties[prop];
|
|
@@ -75,8 +75,8 @@ export default function validateSource(options: ValidationOptions): Array<Valida
|
|
|
75
75
|
}));
|
|
76
76
|
}
|
|
77
77
|
}
|
|
78
|
-
return errors;
|
|
79
78
|
|
|
79
|
+
return errors;
|
|
80
80
|
case 'video':
|
|
81
81
|
return validateObject({
|
|
82
82
|
key,
|
|
@@ -110,7 +110,8 @@ export default function validateSource(options: ValidationOptions): Array<Valida
|
|
|
110
110
|
}
|
|
111
111
|
|
|
112
112
|
function getSourceTypeValues(styleSpec: StyleReference) {
|
|
113
|
-
|
|
113
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
114
|
+
return styleSpec.source.reduce((memo: string[], source: string) => {
|
|
114
115
|
const sourceType = styleSpec[source];
|
|
115
116
|
if (sourceType.type.type === 'enum') {
|
|
116
117
|
memo = memo.concat(Object.keys(sourceType.type.values));
|
|
@@ -126,7 +127,7 @@ function validatePromoteId({
|
|
|
126
127
|
if (getType(value) === 'string') {
|
|
127
128
|
return validateString({key, value});
|
|
128
129
|
} else if (Array.isArray(value)) {
|
|
129
|
-
const errors = [];
|
|
130
|
+
const errors: ValidationError[] = [];
|
|
130
131
|
const unbundledValue = deepUnbundle(value);
|
|
131
132
|
const expression = createExpression(unbundledValue);
|
|
132
133
|
if (expression.result === 'error') {
|
|
@@ -144,10 +145,11 @@ function validatePromoteId({
|
|
|
144
145
|
|
|
145
146
|
return errors;
|
|
146
147
|
} else {
|
|
147
|
-
const errors = [];
|
|
148
|
+
const errors: ValidationError[] = [];
|
|
148
149
|
for (const prop in value) {
|
|
149
150
|
errors.push(...validatePromoteId({key: `${key}.${prop}`, value: value[prop]}));
|
|
150
151
|
}
|
|
152
|
+
|
|
151
153
|
return errors;
|
|
152
154
|
}
|
|
153
155
|
}
|
|
@@ -15,11 +15,14 @@ export default function validateTerrain(options: ValidationOptions): Array<Valid
|
|
|
15
15
|
|
|
16
16
|
const rootType = getType(terrain);
|
|
17
17
|
if (terrain === undefined) {
|
|
18
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
18
19
|
return errors;
|
|
19
20
|
} else if (rootType === 'null') {
|
|
21
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
20
22
|
return errors;
|
|
21
23
|
} else if (rootType !== 'object') {
|
|
22
24
|
errors = errors.concat([new ValidationError('terrain', terrain, `object expected, ${rootType} found`)]);
|
|
25
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
23
26
|
return errors;
|
|
24
27
|
}
|
|
25
28
|
|
|
@@ -68,5 +71,6 @@ export default function validateTerrain(options: ValidationOptions): Array<Valid
|
|
|
68
71
|
}
|
|
69
72
|
}
|
|
70
73
|
|
|
74
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
71
75
|
return errors;
|
|
72
76
|
}
|
|
@@ -4,7 +4,19 @@ import readStyle from './read_style';
|
|
|
4
4
|
import ValidationError from './error/validation_error';
|
|
5
5
|
import getType from './util/get_type';
|
|
6
6
|
|
|
7
|
+
import type {StyleReference} from './reference/latest';
|
|
7
8
|
import type {ValidationErrors} from './validate_style.min';
|
|
9
|
+
import type {
|
|
10
|
+
StyleSpecification,
|
|
11
|
+
SourceSpecification,
|
|
12
|
+
SourcesSpecification,
|
|
13
|
+
ImportSpecification
|
|
14
|
+
} from './types';
|
|
15
|
+
|
|
16
|
+
type MapboxStyleSpecification = StyleSpecification & {
|
|
17
|
+
visibility?: 'public' | 'private';
|
|
18
|
+
protected?: boolean;
|
|
19
|
+
};
|
|
8
20
|
|
|
9
21
|
const SUPPORTED_SPEC_VERSION = 8;
|
|
10
22
|
const MAX_SOURCES_IN_STYLE = 15;
|
|
@@ -14,17 +26,17 @@ function isValid(value: string | null | undefined, regex: RegExp): boolean {
|
|
|
14
26
|
return !!value.match(regex);
|
|
15
27
|
}
|
|
16
28
|
|
|
17
|
-
function getSourceCount(source:
|
|
18
|
-
if (source
|
|
29
|
+
function getSourceCount(source: SourceSpecification): number {
|
|
30
|
+
if ('url' in source) {
|
|
19
31
|
return source.url.split(',').length;
|
|
20
32
|
} else {
|
|
21
33
|
return 0;
|
|
22
34
|
}
|
|
23
35
|
}
|
|
24
36
|
|
|
25
|
-
function getAllowedKeyErrors(obj:
|
|
37
|
+
function getAllowedKeyErrors(obj: object, keys: string[], path?: string | null): Array<ValidationError> {
|
|
26
38
|
const allowed = new Set(keys);
|
|
27
|
-
const errors = [];
|
|
39
|
+
const errors: ValidationError[] = [];
|
|
28
40
|
Object.keys(obj).forEach(k => {
|
|
29
41
|
if (!allowed.has(k)) {
|
|
30
42
|
const prop = path ? `${path}.${k}` : null;
|
|
@@ -34,9 +46,9 @@ function getAllowedKeyErrors(obj: any, keys: Array<any>, path?: string | null):
|
|
|
34
46
|
return errors;
|
|
35
47
|
}
|
|
36
48
|
|
|
37
|
-
const acceptedSourceTypes = new Set([
|
|
38
|
-
function getSourceErrors(source:
|
|
39
|
-
const errors = [];
|
|
49
|
+
const acceptedSourceTypes = new Set<SourceSpecification['type']>(['vector', 'raster', 'raster-dem', 'raster-array', 'model', 'batched-model']);
|
|
50
|
+
function getSourceErrors(source: SourceSpecification, i: number): Array<ValidationError> {
|
|
51
|
+
const errors: ValidationError[] = [];
|
|
40
52
|
|
|
41
53
|
/*
|
|
42
54
|
* Inlined sources are not supported by the Mapbox Styles API, so only
|
|
@@ -48,7 +60,7 @@ function getSourceErrors(source: any, i: number): Array<ValidationError> {
|
|
|
48
60
|
/*
|
|
49
61
|
* "type" is required and must be one of "vector", "raster", "raster-dem", "raster-array"
|
|
50
62
|
*/
|
|
51
|
-
if (!acceptedSourceTypes.has(String(source.type))) {
|
|
63
|
+
if (!acceptedSourceTypes.has(String(source.type) as SourceSpecification['type'])) {
|
|
52
64
|
errors.push(new ValidationError(`sources[${i}].type`, source.type, `Expected one of [${Array.from(acceptedSourceTypes).join(", ")}]`));
|
|
53
65
|
}
|
|
54
66
|
|
|
@@ -59,22 +71,22 @@ function getSourceErrors(source: any, i: number): Array<ValidationError> {
|
|
|
59
71
|
* mapbox://mapbox.abcd1234,penny.abcd1234
|
|
60
72
|
*/
|
|
61
73
|
const sourceUrlPattern = /^mapbox:\/\/([^/]*)$/;
|
|
62
|
-
if (!
|
|
63
|
-
errors.push(new ValidationError(`sources[${i}].url`, source.url, 'Expected a valid Mapbox tileset url'));
|
|
74
|
+
if (!('url' in source) || !isValid(source.url, sourceUrlPattern)) {
|
|
75
|
+
errors.push(new ValidationError(`sources[${i}].url`, (source as {url?: string}).url, 'Expected a valid Mapbox tileset url'));
|
|
64
76
|
}
|
|
65
77
|
|
|
66
78
|
return errors;
|
|
67
79
|
}
|
|
68
80
|
|
|
69
81
|
function getMaxSourcesErrors(sourcesCount: number): Array<ValidationError> {
|
|
70
|
-
const errors = [];
|
|
82
|
+
const errors: ValidationError[] = [];
|
|
71
83
|
if (sourcesCount > MAX_SOURCES_IN_STYLE) {
|
|
72
84
|
errors.push(new ValidationError('sources', null, `Styles must contain ${MAX_SOURCES_IN_STYLE} or fewer sources`));
|
|
73
85
|
}
|
|
74
86
|
return errors;
|
|
75
87
|
}
|
|
76
88
|
|
|
77
|
-
function getSourcesErrors(sources:
|
|
89
|
+
function getSourcesErrors(sources: SourcesSpecification): {
|
|
78
90
|
errors: Array<ValidationError>;
|
|
79
91
|
sourcesCount: number;
|
|
80
92
|
} {
|
|
@@ -95,14 +107,11 @@ function getSourcesErrors(sources: any): {
|
|
|
95
107
|
return {errors, sourcesCount};
|
|
96
108
|
}
|
|
97
109
|
|
|
98
|
-
function getImportErrors(imports:
|
|
99
|
-
errors: Array<ValidationError>;
|
|
100
|
-
sourcesCount: number;
|
|
101
|
-
} {
|
|
110
|
+
function getImportErrors(imports: ImportSpecification[] = []): {errors: Array<ValidationError>; sourcesCount: number} {
|
|
102
111
|
let errors: Array<ValidationError> = [];
|
|
103
112
|
|
|
104
113
|
let sourcesCount = 0;
|
|
105
|
-
const validateImports = (imports:
|
|
114
|
+
const validateImports = (imports: ImportSpecification[] = []) => {
|
|
106
115
|
for (const importSpec of imports) {
|
|
107
116
|
const style = importSpec.data;
|
|
108
117
|
if (!style) continue;
|
|
@@ -129,7 +138,7 @@ function getImportErrors(imports: Array<any> = []): {
|
|
|
129
138
|
return {errors, sourcesCount};
|
|
130
139
|
}
|
|
131
140
|
|
|
132
|
-
function getRootErrors(style:
|
|
141
|
+
function getRootErrors(style: MapboxStyleSpecification, specKeys: string[]): Array<ValidationError> {
|
|
133
142
|
const errors = [];
|
|
134
143
|
|
|
135
144
|
/*
|
|
@@ -195,6 +204,7 @@ function getRootErrors(style: any, specKeys: Array<any>): Array<ValidationError>
|
|
|
195
204
|
errors.push(new ValidationError('protected', style.protected, 'Style protection must be true or false'));
|
|
196
205
|
}
|
|
197
206
|
|
|
207
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
198
208
|
return errors;
|
|
199
209
|
}
|
|
200
210
|
|
|
@@ -208,11 +218,12 @@ function getRootErrors(style: any, specKeys: Array<any>): Array<ValidationError>
|
|
|
208
218
|
* var validateMapboxApiSupported = require('mapbox-gl-style-spec/lib/validate_style_mapbox_api_supported.js');
|
|
209
219
|
* var errors = validateMapboxApiSupported(style);
|
|
210
220
|
*/
|
|
211
|
-
export default function validateMapboxApiSupported(style:
|
|
221
|
+
export default function validateMapboxApiSupported(style: MapboxStyleSpecification, styleSpec: StyleReference = v8): ValidationErrors {
|
|
212
222
|
let s = style;
|
|
213
223
|
try {
|
|
214
224
|
s = readStyle(s);
|
|
215
225
|
} catch (e) {
|
|
226
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
216
227
|
return [e];
|
|
217
228
|
}
|
|
218
229
|
|
package/validate_style.ts
CHANGED
package/visit.ts
CHANGED
|
@@ -11,11 +11,13 @@ import type {
|
|
|
11
11
|
function getPropertyReference(propertyName: string): StylePropertySpecification {
|
|
12
12
|
for (let i = 0; i < Reference.layout.length; i++) {
|
|
13
13
|
for (const key in Reference[Reference.layout[i]]) {
|
|
14
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
14
15
|
if (key === propertyName) return Reference[Reference.layout[i]][key];
|
|
15
16
|
}
|
|
16
17
|
}
|
|
17
18
|
for (let i = 0; i < Reference.paint.length; i++) {
|
|
18
19
|
for (const key in Reference[Reference.paint[i]]) {
|
|
20
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
19
21
|
if (key === propertyName) return Reference[Reference.paint[i]][key];
|
|
20
22
|
}
|
|
21
23
|
}
|
|
@@ -57,7 +59,7 @@ export function eachProperty(
|
|
|
57
59
|
) {
|
|
58
60
|
function inner(layer: LayerSpecification, propertyType: 'paint' | 'layout') {
|
|
59
61
|
if (layer.type === 'slot' || layer.type === 'clip') return;
|
|
60
|
-
const properties =
|
|
62
|
+
const properties = layer[propertyType];
|
|
61
63
|
if (!properties) return;
|
|
62
64
|
Object.keys(properties).forEach((key) => {
|
|
63
65
|
callback({
|