@mapbox/mapbox-gl-style-spec 14.16.0-beta.2 → 14.16.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.
@@ -4,6 +4,7 @@ import validate from './validate';
4
4
 
5
5
  import type {StyleReference} from '../reference/latest';
6
6
  import type {StyleSpecification} from '../types';
7
+ import type {StylePropertySpecification} from '../style-spec';
7
8
 
8
9
  type ProjectionValidatorOptions = {
9
10
  key: string;
@@ -15,8 +16,7 @@ type ProjectionValidatorOptions = {
15
16
  export default function validateProjection(options: ProjectionValidatorOptions): ValidationError[] {
16
17
  const projection = options.value;
17
18
  const styleSpec = options.styleSpec;
18
- // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
19
- const projectionSpec = styleSpec.projection;
19
+ const projectionSpec = styleSpec.projection as Record<PropertyKey, StylePropertySpecification>;
20
20
  const style = options.style;
21
21
 
22
22
  if (isObject(projection)) {
@@ -26,7 +26,7 @@ export default function validateProjection(options: ProjectionValidatorOptions):
26
26
  errors = errors.concat(validate({
27
27
  key,
28
28
  value: projection[key],
29
- // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access
29
+
30
30
  valueSpec: projectionSpec[key],
31
31
  style,
32
32
  styleSpec
@@ -7,13 +7,15 @@ import {supportsLightExpression, supportsPropertyExpression, supportsZoomExpress
7
7
  import {isGlobalPropertyConstant, isFeatureConstant, isStateConstant} from '../expression/is_constant';
8
8
  import {createPropertyExpression, isExpression} from '../expression/index';
9
9
 
10
+ import type {Expression} from '../expression/expression';
10
11
  import type {StyleReference} from '../reference/latest';
12
+ import type {StylePropertySpecification} from '../style-spec';
11
13
  import type {StyleSpecification, LayerSpecification} from '../types';
12
14
 
13
15
  export type PropertyValidatorOptions = {
14
16
  key: string;
15
17
  value: unknown;
16
- valueSpec?: unknown;
18
+ valueSpec?: StylePropertySpecification;
17
19
  style: Partial<StyleSpecification>;
18
20
  styleSpec: StyleReference;
19
21
  objectKey?: string;
@@ -28,29 +30,24 @@ export default function validateProperty(options: PropertyValidatorOptions, prop
28
30
  const styleSpec = options.styleSpec;
29
31
  const value = options.value;
30
32
  const propertyKey = options.objectKey;
31
- // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
32
- const layerSpec = styleSpec[`${propertyType}_${options.layerType}`];
33
+ const layerSpec = styleSpec[`${propertyType}_${options.layerType}`] as Record<string, StylePropertySpecification> | undefined;
33
34
 
34
35
  if (!layerSpec) return [];
35
36
 
36
37
  const useThemeMatch = propertyKey.match(/^(.*)-use-theme$/);
37
- // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
38
38
  if (useThemeMatch && layerSpec[useThemeMatch[1]]) {
39
- if (isExpression(value)) {
39
+ if (isExpression(deepUnbundle(value))) {
40
40
  const errors: ValidationError[] = [];
41
41
  return errors.concat(validate({
42
- key: options.key,
42
+ key,
43
43
  value,
44
44
  valueSpec: {
45
- "type": "string",
46
- "expression": {
47
- "interpolated": false,
48
- "parameters": [
49
- "zoom",
50
- "feature"
51
- ]
45
+ type: 'string',
46
+ expression: {
47
+ interpolated: false,
48
+ parameters: ['zoom', 'feature']
52
49
  },
53
- "property-type": "data-driven"
50
+ 'property-type': 'data-driven'
54
51
  },
55
52
  style,
56
53
  styleSpec,
@@ -59,6 +56,7 @@ export default function validateProperty(options: PropertyValidatorOptions, prop
59
56
  propertyKey
60
57
  }));
61
58
  }
59
+
62
60
  return validate({
63
61
  key,
64
62
  value,
@@ -69,7 +67,6 @@ export default function validateProperty(options: PropertyValidatorOptions, prop
69
67
  }
70
68
 
71
69
  const transitionMatch = propertyKey.match(/^(.*)-transition$/);
72
- // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
73
70
  if (propertyType === 'paint' && transitionMatch && layerSpec[transitionMatch[1]] && layerSpec[transitionMatch[1]].transition) {
74
71
  return validate({
75
72
  key,
@@ -81,14 +78,12 @@ export default function validateProperty(options: PropertyValidatorOptions, prop
81
78
  });
82
79
  }
83
80
 
84
- // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access
85
81
  const valueSpec = options.valueSpec || layerSpec[propertyKey];
86
82
  if (!valueSpec) {
87
83
  return [new ValidationWarning(key, value, `unknown property "${propertyKey}"`)];
88
84
  }
89
85
 
90
86
  let tokenMatch: RegExpExecArray | undefined;
91
- // eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-member-access
92
87
  if (isString(value) && supportsPropertyExpression(valueSpec) && !valueSpec.tokens && (tokenMatch = /^{([^}]+)}$/.exec(value))) {
93
88
  const example = `\`{ "type": "identity", "property": ${tokenMatch ? JSON.stringify(tokenMatch[1]) : '"_"'} }\``;
94
89
  return [new ValidationError(
@@ -107,17 +102,15 @@ export default function validateProperty(options: PropertyValidatorOptions, prop
107
102
  errors.push(new ValidationError(key, value, '"text-font" does not support identity functions'));
108
103
  }
109
104
  } else if (options.layerType === 'model' && propertyType === 'paint' && layer && layer.layout && layer.layout.hasOwnProperty('model-id')) {
110
- // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
111
105
  if (supportsPropertyExpression(valueSpec) && (supportsLightExpression(valueSpec) || supportsZoomExpression(valueSpec))) {
112
106
  // Performance related style spec limitation: zoom and light expressions are not allowed for e.g. trees.
113
- // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
114
107
  const expression = createPropertyExpression(deepUnbundle(value), valueSpec);
115
- // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access
116
- const expressionObj = (expression.value as any).expression || (expression.value as any)._styleExpression.expression;
117
108
 
118
- // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
109
+ const expressionValue = expression.value as {expression?: Expression} | {_styleExpression?: {expression?: Expression}};
110
+ const expressionObj = ('expression' in expressionValue && expressionValue.expression) ||
111
+ ('_styleExpression' in expressionValue && expressionValue._styleExpression && expressionValue._styleExpression.expression);
112
+
119
113
  if (expressionObj && !isGlobalPropertyConstant(expressionObj, ['measure-light'])) {
120
- // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
121
114
  if (propertyKey !== 'model-emissive-strength' || (!isFeatureConstant(expressionObj) || !isStateConstant(expressionObj))) {
122
115
  errors.push(new ValidationError(key, value, `${propertyKey} does not support measure-light expressions when the model layer source is vector tile or GeoJSON.`));
123
116
  }
@@ -128,7 +121,6 @@ export default function validateProperty(options: PropertyValidatorOptions, prop
128
121
  return errors.concat(validate({
129
122
  key: options.key,
130
123
  value,
131
- // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
132
124
  valueSpec,
133
125
  style,
134
126
  styleSpec,
@@ -4,6 +4,7 @@ import {getType, isObject} from '../util/get_type';
4
4
 
5
5
  import type {StyleReference} from '../reference/latest';
6
6
  import type {StyleSpecification} from '../types';
7
+ import type {StylePropertySpecification} from '../style-spec';
7
8
 
8
9
  type RainValidatorOptions = {
9
10
  key: string;
@@ -16,8 +17,7 @@ export default function validateRain(options: RainValidatorOptions): ValidationE
16
17
  const rain = options.value;
17
18
  const style = options.style;
18
19
  const styleSpec = options.styleSpec;
19
- // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
20
- const rainSpec = styleSpec.rain;
20
+ const rainSpec = styleSpec.rain as Record<PropertyKey, StylePropertySpecification>;
21
21
 
22
22
  if (rain === undefined) {
23
23
  return [];
@@ -31,7 +31,6 @@ export default function validateRain(options: RainValidatorOptions): ValidationE
31
31
  for (const key in rain) {
32
32
  const transitionMatch = key.match(/^(.*)-transition$/);
33
33
 
34
- // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
35
34
  if (transitionMatch && rainSpec[transitionMatch[1]] && rainSpec[transitionMatch[1]].transition) {
36
35
  errors = errors.concat(validate({
37
36
  key,
@@ -41,12 +40,11 @@ export default function validateRain(options: RainValidatorOptions): ValidationE
41
40
  style,
42
41
  styleSpec
43
42
  }));
44
- // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
45
43
  } else if (rainSpec[key]) {
46
44
  errors = errors.concat(validate({
47
45
  key,
48
46
  value: rain[key],
49
- // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access
47
+
50
48
  valueSpec: rainSpec[key],
51
49
  style,
52
50
  styleSpec
@@ -4,6 +4,7 @@ import {getType, isObject} from '../util/get_type';
4
4
 
5
5
  import type {StyleReference} from '../reference/latest';
6
6
  import type {StyleSpecification} from '../types';
7
+ import type {StylePropertySpecification} from '../style-spec';
7
8
 
8
9
  type SnowValidatorOptions = {
9
10
  key: string;
@@ -16,8 +17,7 @@ export default function validateSnow(options: SnowValidatorOptions): ValidationE
16
17
  const snow = options.value;
17
18
  const style = options.style;
18
19
  const styleSpec = options.styleSpec;
19
- // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
20
- const snowSpec = styleSpec.snow;
20
+ const snowSpec = styleSpec.snow as Record<PropertyKey, StylePropertySpecification>;
21
21
 
22
22
  if (snow === undefined) {
23
23
  return [];
@@ -31,7 +31,6 @@ export default function validateSnow(options: SnowValidatorOptions): ValidationE
31
31
  for (const key in snow) {
32
32
  const transitionMatch = key.match(/^(.*)-transition$/);
33
33
 
34
- // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
35
34
  if (transitionMatch && snowSpec[transitionMatch[1]] && snowSpec[transitionMatch[1]].transition) {
36
35
  errors = errors.concat(validate({
37
36
  key,
@@ -41,12 +40,11 @@ export default function validateSnow(options: SnowValidatorOptions): ValidationE
41
40
  style,
42
41
  styleSpec
43
42
  }));
44
- // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
45
43
  } else if (snowSpec[key]) {
46
44
  errors = errors.concat(validate({
47
45
  key,
48
46
  value: snow[key],
49
- // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access
47
+
50
48
  valueSpec: snowSpec[key],
51
49
  style,
52
50
  styleSpec
@@ -135,17 +135,15 @@ export default function validateSource(options: SourceValidatorOptions): Validat
135
135
  }
136
136
 
137
137
  function getSourceTypeValues(styleSpec: StyleReference): string[] {
138
- // eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access
139
- return styleSpec.source.reduce((memo: string[], source: string) => {
140
- // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
141
- const sourceType = styleSpec[source];
142
- // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
138
+ const sourceArray = styleSpec.source as string[];
139
+ return sourceArray.reduce((memo: string[], source: string) => {
140
+
141
+ const sourceType = (styleSpec as Record<string, unknown>)[source] as {type: {type: string; values?: Record<string, unknown>}};
143
142
  if (sourceType.type.type === 'enum') {
144
- // eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-member-access
145
- memo = memo.concat(Object.keys(sourceType.type.values));
143
+ memo = memo.concat(Object.keys(sourceType.type.values || {}));
146
144
  }
147
145
  return memo;
148
- }, []) as string[];
146
+ }, []);
149
147
  }
150
148
 
151
149
  type PromoteIdValidatorOptions = {