@maplibre/maplibre-gl-style-spec
Advanced tools
Comparing version 21.2.0 to 22.0.0
@@ -5,3 +5,3 @@ #!/usr/bin/env node | ||
import minimist from 'minimist'; | ||
import format from '../src/format'; | ||
import {format} from '../src/format'; | ||
const argv = minimist(process.argv.slice(2)); | ||
@@ -8,0 +8,0 @@ |
@@ -5,4 +5,4 @@ #!/usr/bin/env node | ||
import minimist from 'minimist'; | ||
import format from '../src/format'; | ||
import migrate from '../src/migrate'; | ||
import {format} from '../src/format'; | ||
import {migrate} from '../src/migrate'; | ||
const argv = minimist(process.argv.slice(2)); | ||
@@ -9,0 +9,0 @@ |
@@ -5,3 +5,3 @@ #!/usr/bin/env node | ||
import rw from 'rw'; | ||
import validate from '../src/validate_style'; | ||
import {validateStyle as validate} from '../src/validate_style'; | ||
@@ -8,0 +8,0 @@ const argv = minimist(process.argv.slice(2), { |
{ | ||
"name": "@maplibre/maplibre-gl-style-spec", | ||
"description": "a specification for maplibre styles", | ||
"version": "21.2.0", | ||
"version": "22.0.0", | ||
"author": "MapLibre", | ||
@@ -73,15 +73,15 @@ "keywords": [ | ||
"@types/jest": "^29.5.14", | ||
"@types/node": "^22.8.7", | ||
"@typescript-eslint/eslint-plugin": "^8.12.2", | ||
"@typescript-eslint/parser": "^8.12.2", | ||
"@types/node": "^22.9.0", | ||
"@typescript-eslint/eslint-plugin": "^8.13.0", | ||
"@typescript-eslint/parser": "^8.13.0", | ||
"dts-bundle-generator": "^9.5.1", | ||
"eslint": "^9.14.0", | ||
"eslint-plugin-jest": "^28.8.3", | ||
"eslint-plugin-jest": "^28.9.0", | ||
"eslint-plugin-jsdoc": "^50.4.3", | ||
"glob": "^11.0.0", | ||
"globals": "^15.11.0", | ||
"globals": "^15.12.0", | ||
"jest": "^29.7.0", | ||
"jest-canvas-mock": "^2.5.2", | ||
"jest-environment-jsdom": "^29.7.0", | ||
"rollup": "^4.24.3", | ||
"rollup": "^4.25.0", | ||
"rollup-plugin-preserve-shebang": "^1.0.1", | ||
@@ -88,0 +88,0 @@ "semver": "^7.6.3", |
@@ -1,2 +0,2 @@ | ||
import declass from './declass'; | ||
import {declassStyle} from './declass'; | ||
@@ -19,3 +19,3 @@ describe('declass', () => { | ||
const declassed = declass(style, ['one']); | ||
const declassed = declassStyle(style, ['one']); | ||
@@ -51,3 +51,3 @@ expect(declassed).not.toBe(style); | ||
expect(declass(style, ['one'])).toEqual({ | ||
expect(declassStyle(style, ['one'])).toEqual({ | ||
layers: [{ | ||
@@ -83,3 +83,3 @@ id: 'a', | ||
expect(declass(style, ['one', 'two'])).toEqual({ | ||
expect(declassStyle(style, ['one', 'two'])).toEqual({ | ||
layers: [{ | ||
@@ -110,3 +110,3 @@ id: 'a', | ||
expect(declass(style, ['one'])).toEqual({ | ||
expect(declassStyle(style, ['one'])).toEqual({ | ||
layers: [{ | ||
@@ -113,0 +113,0 @@ id: 'a', |
import extend from './util/extend'; | ||
import {extendBy} from './util/extend'; | ||
export default declassStyle; | ||
/** | ||
@@ -21,4 +19,4 @@ * Returns a new style with the given 'paint classes' merged into each layer's | ||
*/ | ||
function declassStyle(style, classes) { | ||
return extend({}, style, { | ||
export function declassStyle(style, classes) { | ||
return extendBy({}, style, { | ||
layers: style.layers.map((layer) => { | ||
@@ -40,5 +38,5 @@ const result = classes.reduce(declassLayer, layer); | ||
function declassLayer(layer, klass) { | ||
return extend({}, layer, { | ||
paint: extend({}, layer.paint, layer[`paint.${klass}`]) | ||
return extendBy({}, layer, { | ||
paint: extendBy({}, layer.paint, layer[`paint.${klass}`]) | ||
}); | ||
} |
@@ -1,6 +0,6 @@ | ||
import deref from './deref'; | ||
import {derefLayers} from './deref'; | ||
describe('deref', () => { | ||
test('derefs a ref layer which follows its parent', () => { | ||
expect(deref([ | ||
expect(derefLayers([ | ||
{ | ||
@@ -27,3 +27,3 @@ 'id': 'parent', | ||
test('derefs a ref layer which precedes its parent', () => { | ||
expect(deref([ | ||
expect(derefLayers([ | ||
{ | ||
@@ -30,0 +30,0 @@ 'id': 'child', |
import refProperties from './util/ref_properties'; | ||
import {refProperties} from './util/ref_properties'; | ||
@@ -22,4 +22,2 @@ function deref(layer, parent) { | ||
export default derefLayers; | ||
/** | ||
@@ -38,3 +36,3 @@ * Given an array of layers, some of which may contain `ref` properties | ||
*/ | ||
function derefLayers(layers) { | ||
export function derefLayers(layers) { | ||
layers = layers.slice(); | ||
@@ -41,0 +39,0 @@ |
@@ -1,2 +0,2 @@ | ||
import diffStyles from './diff'; | ||
import {diff} from './diff'; | ||
import {StyleSpecification} from './types.g'; | ||
@@ -6,3 +6,3 @@ | ||
test('layers id equal', () => { | ||
expect(diffStyles({ | ||
expect(diff({ | ||
layers: [{id: 'a'}] | ||
@@ -15,3 +15,3 @@ } as StyleSpecification, { | ||
test('version not equal', () => { | ||
expect(diffStyles({ | ||
expect(diff({ | ||
version: 7, | ||
@@ -28,3 +28,3 @@ layers: [{id: 'a'}] | ||
test('add layer at the end', () => { | ||
expect(diffStyles({ | ||
expect(diff({ | ||
layers: [{id: 'a'}] | ||
@@ -39,3 +39,3 @@ } as StyleSpecification, { | ||
test('add layer at the beginning', () => { | ||
expect(diffStyles({ | ||
expect(diff({ | ||
layers: [{id: 'b'}] | ||
@@ -50,3 +50,3 @@ } as StyleSpecification, { | ||
test('remove layer', () => { | ||
expect(diffStyles({ | ||
expect(diff({ | ||
layers: [{id: 'a'}, {id: 'b', source: 'foo', nested: [1]}] | ||
@@ -61,3 +61,3 @@ } as StyleSpecification, { | ||
test('remove and add layer', () => { | ||
expect(diffStyles({ | ||
expect(diff({ | ||
layers: [{id: 'a'}, {id: 'b'}] | ||
@@ -73,3 +73,3 @@ } as StyleSpecification, { | ||
test('set paint property', () => { | ||
expect(diffStyles({ | ||
expect(diff({ | ||
layers: [{id: 'a', paint: {foo: 1}}] | ||
@@ -84,3 +84,3 @@ } as any as StyleSpecification, { | ||
test('set paint property with light', () => { | ||
expect(diffStyles({ | ||
expect(diff({ | ||
layers: [{id: 'a', 'paint.light': {foo: 1}}] | ||
@@ -95,3 +95,3 @@ } as any as StyleSpecification, { | ||
test('set paint property with ramp', () => { | ||
expect(diffStyles({ | ||
expect(diff({ | ||
layers: [{id: 'a', paint: {foo: {ramp: [1, 2]}}}] | ||
@@ -106,3 +106,3 @@ } as any as StyleSpecification, { | ||
test('set layout property', () => { | ||
expect(diffStyles({ | ||
expect(diff({ | ||
layers: [{id: 'a', layout: {foo: 1}}] | ||
@@ -117,3 +117,3 @@ } as any as StyleSpecification, { | ||
test('set filter', () => { | ||
expect(diffStyles({ | ||
expect(diff({ | ||
layers: [{id: 'a', filter: ['==', 'foo', 'bar']}] | ||
@@ -128,3 +128,3 @@ } as StyleSpecification, { | ||
test('remove source', () => { | ||
expect(diffStyles({ | ||
expect(diff({ | ||
sources: {foo: 1} | ||
@@ -139,3 +139,3 @@ } as any as StyleSpecification, { | ||
test('add source', () => { | ||
expect(diffStyles({ | ||
expect(diff({ | ||
sources: {} | ||
@@ -150,3 +150,3 @@ } as StyleSpecification, { | ||
test('set goejson source data', () => { | ||
expect(diffStyles({ | ||
expect(diff({ | ||
sources: { | ||
@@ -183,3 +183,3 @@ foo: { | ||
test('remove and add source', () => { | ||
expect(diffStyles({ | ||
expect(diff({ | ||
sources: { | ||
@@ -210,3 +210,3 @@ foo: { | ||
test('remove and add source with clusterRadius', () => { | ||
expect(diffStyles({ | ||
expect(diff({ | ||
sources: { | ||
@@ -240,3 +240,3 @@ foo: { | ||
test('remove and add source without clusterRadius', () => { | ||
expect(diffStyles({ | ||
expect(diff({ | ||
sources: { | ||
@@ -269,3 +269,3 @@ foo: { | ||
test('global metadata', () => { | ||
expect(diffStyles({} as StyleSpecification, { | ||
expect(diff({} as StyleSpecification, { | ||
metadata: {'maplibre:author': 'nobody'} | ||
@@ -276,3 +276,3 @@ } as StyleSpecification)).toEqual([]); | ||
test('layer metadata', () => { | ||
expect(diffStyles({ | ||
expect(diff({ | ||
layers: [{id: 'a', metadata: {'maplibre:group': 'Group Name'}}] | ||
@@ -285,3 +285,3 @@ } as StyleSpecification, { | ||
test('set center', () => { | ||
expect(diffStyles({ | ||
expect(diff({ | ||
center: [0, 0] | ||
@@ -296,3 +296,3 @@ } as StyleSpecification, { | ||
test('set centerAltitude to undefined', () => { | ||
expect(diffStyles({ | ||
expect(diff({ | ||
centerAltitude: 1 | ||
@@ -306,3 +306,3 @@ } as StyleSpecification, { | ||
test('set centerAltitude', () => { | ||
expect(diffStyles({ | ||
expect(diff({ | ||
centerAltitude: 0 | ||
@@ -317,3 +317,3 @@ } as StyleSpecification, { | ||
test('set zoom', () => { | ||
expect(diffStyles({ | ||
expect(diff({ | ||
zoom: 12 | ||
@@ -328,3 +328,3 @@ } as StyleSpecification, { | ||
test('set bearing', () => { | ||
expect(diffStyles({ | ||
expect(diff({ | ||
bearing: 0 | ||
@@ -339,3 +339,3 @@ } as StyleSpecification, { | ||
test('set pitch', () => { | ||
expect(diffStyles({ | ||
expect(diff({ | ||
pitch: 0 | ||
@@ -350,3 +350,3 @@ } as StyleSpecification, { | ||
test('set roll to undefined', () => { | ||
expect(diffStyles({ | ||
expect(diff({ | ||
roll: 1 | ||
@@ -360,3 +360,3 @@ } as StyleSpecification, { | ||
test('set roll', () => { | ||
expect(diffStyles({ | ||
expect(diff({ | ||
roll: 0 | ||
@@ -371,3 +371,3 @@ } as StyleSpecification, { | ||
test('no changes in light', () => { | ||
expect(diffStyles({ | ||
expect(diff({ | ||
light: { | ||
@@ -391,3 +391,3 @@ anchor: 'map', | ||
test('set light anchor', () => { | ||
expect(diffStyles({ | ||
expect(diff({ | ||
light: {anchor: 'map'} | ||
@@ -402,3 +402,3 @@ } as StyleSpecification, { | ||
test('set light color', () => { | ||
expect(diffStyles({ | ||
expect(diff({ | ||
light: {color: 'white'} | ||
@@ -413,3 +413,3 @@ } as StyleSpecification, { | ||
test('set light position', () => { | ||
expect(diffStyles({ | ||
expect(diff({ | ||
light: {position: [0, 1, 0]} | ||
@@ -424,3 +424,3 @@ } as StyleSpecification, { | ||
test('set light intensity', () => { | ||
expect(diffStyles({ | ||
expect(diff({ | ||
light: {intensity: 1} | ||
@@ -435,3 +435,3 @@ } as StyleSpecification, { | ||
test('set light anchor and color', () => { | ||
expect(diffStyles({ | ||
expect(diff({ | ||
light: { | ||
@@ -461,3 +461,3 @@ anchor: 'map', | ||
test('add and remove layer on source change', () => { | ||
expect(diffStyles({ | ||
expect(diff({ | ||
layers: [{id: 'a', source: 'source-one'}] | ||
@@ -473,3 +473,3 @@ } as StyleSpecification, { | ||
test('add and remove layer on type change', () => { | ||
expect(diffStyles({ | ||
expect(diff({ | ||
layers: [{id: 'a', type: 'fill'}] | ||
@@ -485,3 +485,3 @@ } as StyleSpecification, { | ||
test('add and remove layer on source-layer change', () => { | ||
expect(diffStyles({ | ||
expect(diff({ | ||
layers: [{id: 'a', source: 'a', 'source-layer': 'layer-one'}] | ||
@@ -497,3 +497,3 @@ } as StyleSpecification, { | ||
test('add and remove layers on different order and type', () => { | ||
expect(diffStyles({ | ||
expect(diff({ | ||
layers: [ | ||
@@ -519,3 +519,3 @@ {id: 'b'}, | ||
test('add and remove layer and source on source data change', () => { | ||
expect(diffStyles({ | ||
expect(diff({ | ||
sources: {foo: {data: 1}, bar: {}}, | ||
@@ -543,3 +543,3 @@ layers: [ | ||
test('set transition', () => { | ||
expect(diffStyles({ | ||
expect(diff({ | ||
sources: {foo: {data: 1}, bar: {}}, | ||
@@ -561,3 +561,3 @@ layers: [ | ||
test('no sprite change', () => { | ||
expect(diffStyles({ | ||
expect(diff({ | ||
sprite: 'a' | ||
@@ -570,3 +570,3 @@ } as StyleSpecification, { | ||
test('set sprite', () => { | ||
expect(diffStyles({ | ||
expect(diff({ | ||
sprite: 'a' | ||
@@ -581,3 +581,3 @@ } as StyleSpecification, { | ||
test('set sprite for multiple sprites', () => { | ||
expect(diffStyles({ | ||
expect(diff({ | ||
sprite: 'a' | ||
@@ -592,3 +592,3 @@ } as StyleSpecification, { | ||
test('no glyphs change', () => { | ||
expect(diffStyles({ | ||
expect(diff({ | ||
glyphs: 'a' | ||
@@ -601,3 +601,3 @@ } as StyleSpecification, { | ||
test('set glyphs', () => { | ||
expect(diffStyles({ | ||
expect(diff({ | ||
glyphs: 'a' | ||
@@ -612,3 +612,3 @@ } as StyleSpecification, { | ||
test('remove terrain', () => { | ||
expect(diffStyles({ | ||
expect(diff({ | ||
terrain: { | ||
@@ -625,3 +625,3 @@ source: 'maplibre-dem', | ||
test('add terrain', () => { | ||
expect(diffStyles({ | ||
expect(diff({ | ||
} as StyleSpecification, | ||
@@ -639,3 +639,3 @@ { | ||
test('set sky', () => { | ||
expect(diffStyles({ | ||
expect(diff({ | ||
} as StyleSpecification, | ||
@@ -653,12 +653,11 @@ { | ||
test('set projection', () => { | ||
expect(diffStyles({ | ||
expect(diff({ | ||
} as StyleSpecification, | ||
{ | ||
projection: { | ||
type: 'globe' | ||
} | ||
projection: {type: ['vertical-perspective', 'mercator', 0.5]} | ||
} as StyleSpecification)).toEqual([ | ||
{command: 'setProjection', args: [{type: 'globe'}]}, | ||
{command: 'setProjection', args: [{type: ['vertical-perspective', 'mercator', 0.5]}]}, | ||
]); | ||
}); | ||
}); |
import {GeoJSONSourceSpecification, LayerSpecification, LightSpecification, ProjectionSpecification, SkySpecification, SourceSpecification, SpriteSpecification, StyleSpecification, TerrainSpecification, TransitionSpecification} from './types.g'; | ||
import isEqual from './util/deep_equal'; | ||
import {deepEqual} from './util/deep_equal'; | ||
@@ -70,3 +70,3 @@ /** | ||
if (!Object.prototype.hasOwnProperty.call(before[sourceId], prop)) continue; | ||
if (prop !== 'data' && !isEqual(before[sourceId][prop], after[sourceId][prop])) { | ||
if (prop !== 'data' && !deepEqual(before[sourceId][prop], after[sourceId][prop])) { | ||
return false; | ||
@@ -77,3 +77,3 @@ } | ||
if (!Object.prototype.hasOwnProperty.call(after[sourceId], prop)) continue; | ||
if (prop !== 'data' && !isEqual(before[sourceId][prop], after[sourceId][prop])) { | ||
if (prop !== 'data' && !deepEqual(before[sourceId][prop], after[sourceId][prop])) { | ||
return false; | ||
@@ -104,3 +104,3 @@ } | ||
addSource(sourceId, after, commands); | ||
} else if (!isEqual(before[sourceId], after[sourceId])) { | ||
} else if (!deepEqual(before[sourceId], after[sourceId])) { | ||
if (before[sourceId].type === 'geojson' && after[sourceId].type === 'geojson' && canUpdateGeoJSON(before, after, sourceId)) { | ||
@@ -122,3 +122,3 @@ addCommand(commands, {command: 'setGeoJSONSourceData', args: [sourceId, (after[sourceId] as GeoJSONSourceSpecification).data]}); | ||
if (!Object.prototype.hasOwnProperty.call(before, prop)) continue; | ||
if (!isEqual(before[prop], after[prop])) { | ||
if (!deepEqual(before[prop], after[prop])) { | ||
commands.push({command, args: [layerId, prop, after[prop], klass]}); | ||
@@ -129,3 +129,3 @@ } | ||
if (!Object.prototype.hasOwnProperty.call(after, prop) || Object.prototype.hasOwnProperty.call(before, prop)) continue; | ||
if (!isEqual(before[prop], after[prop])) { | ||
if (!deepEqual(before[prop], after[prop])) { | ||
commands.push({command, args: [layerId, prop, after[prop], klass]}); | ||
@@ -210,7 +210,7 @@ } | ||
// no need to update if previously added (new or moved) | ||
if (clean[layerId] || isEqual(beforeLayer, afterLayer)) continue; | ||
if (clean[layerId] || deepEqual(beforeLayer, afterLayer)) continue; | ||
// If source, source-layer, or type have changes, then remove the layer | ||
// and add it back 'from scratch'. | ||
if (!isEqual(beforeLayer.source, afterLayer.source) || !isEqual(beforeLayer['source-layer'], afterLayer['source-layer']) || !isEqual(beforeLayer.type, afterLayer.type)) { | ||
if (!deepEqual(beforeLayer.source, afterLayer.source) || !deepEqual(beforeLayer['source-layer'], afterLayer['source-layer']) || !deepEqual(beforeLayer.type, afterLayer.type)) { | ||
addCommand(commands, {command: 'removeLayer', args: [layerId]}); | ||
@@ -227,6 +227,6 @@ // we add the layer back at the same position it was already in, so | ||
diffLayerPropertyChanges(beforeLayer.paint, afterLayer.paint, commands, layerId, null, 'setPaintProperty'); | ||
if (!isEqual(beforeLayer.filter, afterLayer.filter)) { | ||
if (!deepEqual(beforeLayer.filter, afterLayer.filter)) { | ||
addCommand(commands, {command: 'setFilter', args: [layerId, afterLayer.filter]}); | ||
} | ||
if (!isEqual(beforeLayer.minzoom, afterLayer.minzoom) || !isEqual(beforeLayer.maxzoom, afterLayer.maxzoom)) { | ||
if (!deepEqual(beforeLayer.minzoom, afterLayer.minzoom) || !deepEqual(beforeLayer.maxzoom, afterLayer.maxzoom)) { | ||
addCommand(commands, {command: 'setLayerZoomRange', args: [layerId, afterLayer.minzoom, afterLayer.maxzoom]}); | ||
@@ -242,3 +242,3 @@ } | ||
diffLayerPropertyChanges(beforeLayer[prop], afterLayer[prop], commands, layerId, prop.slice(6), 'setPaintProperty'); | ||
} else if (!isEqual(beforeLayer[prop], afterLayer[prop])) { | ||
} else if (!deepEqual(beforeLayer[prop], afterLayer[prop])) { | ||
addCommand(commands, {command: 'setLayerProperty', args: [layerId, prop, afterLayer[prop]]}); | ||
@@ -253,3 +253,3 @@ } | ||
diffLayerPropertyChanges(beforeLayer[prop], afterLayer[prop], commands, layerId, prop.slice(6), 'setPaintProperty'); | ||
} else if (!isEqual(beforeLayer[prop], afterLayer[prop])) { | ||
} else if (!deepEqual(beforeLayer[prop], afterLayer[prop])) { | ||
addCommand(commands, {command: 'setLayerProperty', args: [layerId, prop, afterLayer[prop]]}); | ||
@@ -279,3 +279,3 @@ } | ||
*/ | ||
function diffStyles(before: StyleSpecification, after: StyleSpecification): DiffCommand<DiffOperations>[] { | ||
export function diff(before: StyleSpecification, after: StyleSpecification): DiffCommand<DiffOperations>[] { | ||
if (!before) return [{command: 'setStyle', args: [after]}]; | ||
@@ -287,42 +287,42 @@ | ||
// Handle changes to top-level properties | ||
if (!isEqual(before.version, after.version)) { | ||
if (!deepEqual(before.version, after.version)) { | ||
return [{command: 'setStyle', args: [after]}]; | ||
} | ||
if (!isEqual(before.center, after.center)) { | ||
if (!deepEqual(before.center, after.center)) { | ||
commands.push({command: 'setCenter', args: [after.center]}); | ||
} | ||
if (!isEqual(before.centerAltitude, after.centerAltitude)) { | ||
if (!deepEqual(before.centerAltitude, after.centerAltitude)) { | ||
commands.push({command: 'setCenterAltitude', args: [after.centerAltitude]}); | ||
} | ||
if (!isEqual(before.zoom, after.zoom)) { | ||
if (!deepEqual(before.zoom, after.zoom)) { | ||
commands.push({command: 'setZoom', args: [after.zoom]}); | ||
} | ||
if (!isEqual(before.bearing, after.bearing)) { | ||
if (!deepEqual(before.bearing, after.bearing)) { | ||
commands.push({command: 'setBearing', args: [after.bearing]}); | ||
} | ||
if (!isEqual(before.pitch, after.pitch)) { | ||
if (!deepEqual(before.pitch, after.pitch)) { | ||
commands.push({command: 'setPitch', args: [after.pitch]}); | ||
} | ||
if (!isEqual(before.roll, after.roll)) { | ||
if (!deepEqual(before.roll, after.roll)) { | ||
commands.push({command: 'setRoll', args: [after.roll]}); | ||
} | ||
if (!isEqual(before.sprite, after.sprite)) { | ||
if (!deepEqual(before.sprite, after.sprite)) { | ||
commands.push({command: 'setSprite', args: [after.sprite]}); | ||
} | ||
if (!isEqual(before.glyphs, after.glyphs)) { | ||
if (!deepEqual(before.glyphs, after.glyphs)) { | ||
commands.push({command: 'setGlyphs', args: [after.glyphs]}); | ||
} | ||
if (!isEqual(before.transition, after.transition)) { | ||
if (!deepEqual(before.transition, after.transition)) { | ||
commands.push({command: 'setTransition', args: [after.transition]}); | ||
} | ||
if (!isEqual(before.light, after.light)) { | ||
if (!deepEqual(before.light, after.light)) { | ||
commands.push({command: 'setLight', args: [after.light]}); | ||
} | ||
if (!isEqual(before.terrain, after.terrain)) { | ||
if (!deepEqual(before.terrain, after.terrain)) { | ||
commands.push({command: 'setTerrain', args: [after.terrain]}); | ||
} | ||
if (!isEqual(before.sky, after.sky)) { | ||
if (!deepEqual(before.sky, after.sky)) { | ||
commands.push({command: 'setSky', args: [after.sky]}); | ||
} | ||
if (!isEqual(before.projection, after.projection)) { | ||
if (!deepEqual(before.projection, after.projection)) { | ||
commands.push({command: 'setProjection', args: [after.projection]}); | ||
@@ -368,3 +368,1 @@ } | ||
} | ||
export default diffStyles; |
@@ -1,3 +0,3 @@ | ||
import emptyStyle from './empty'; | ||
import validateStyleMin from './validate_style.min'; | ||
import {emptyStyle} from './empty'; | ||
import {validateStyleMin} from './validate_style.min'; | ||
@@ -4,0 +4,0 @@ describe('empty', () => { |
@@ -1,5 +0,5 @@ | ||
import latest from './reference/latest'; | ||
import {latest} from './reference/latest'; | ||
import {StyleSpecification} from './types.g'; | ||
export default function emptyStyle(): StyleSpecification { | ||
export function emptyStyle(): StyleSpecification { | ||
const style = {}; | ||
@@ -9,5 +9,5 @@ | ||
for (const styleKey in latest['$root']) { | ||
const spec = latest['$root'][styleKey]; | ||
const specification = latest['$root'][styleKey]; | ||
if (spec.required) { | ||
if (specification.required) { | ||
let value = null; | ||
@@ -17,3 +17,3 @@ if (styleKey === 'version') { | ||
} else { | ||
if (spec.type === 'array') { | ||
if (specification.type === 'array') { | ||
value = []; | ||
@@ -20,0 +20,0 @@ } else { |
// Note: Do not inherit from Error. It breaks when transpiling to ES5. | ||
export default class ParsingError { | ||
export class ParsingError { | ||
message: string; | ||
@@ -5,0 +5,0 @@ error: Error; |
// Note: Do not inherit from Error. It breaks when transpiling to ES5. | ||
export default class ValidationError { | ||
export class ValidationError { | ||
message: string; | ||
@@ -5,0 +5,0 @@ identifier: string; |
@@ -1,2 +0,2 @@ | ||
import {toString, | ||
import {typeToString, | ||
NumberType, | ||
@@ -11,16 +11,15 @@ StringType, | ||
array, | ||
toString as typeToString, | ||
} from './types'; | ||
import ParsingContext from './parsing_context'; | ||
import EvaluationContext from './evaluation_context'; | ||
import {ParsingContext} from './parsing_context'; | ||
import {EvaluationContext} from './evaluation_context'; | ||
import {expressions} from './definitions/index'; | ||
import CollatorExpression from './definitions/collator'; | ||
import Within from './definitions/within'; | ||
import Literal from './definitions/literal'; | ||
import Assertion from './definitions/assertion'; | ||
import Coercion from './definitions/coercion'; | ||
import Var from './definitions/var'; | ||
import Distance from './definitions/distance'; | ||
import {CollatorExpression} from './definitions/collator'; | ||
import {Within} from './definitions/within'; | ||
import {Literal} from './definitions/literal'; | ||
import {Assertion} from './definitions/assertion'; | ||
import {Coercion} from './definitions/coercion'; | ||
import {Var} from './definitions/var'; | ||
import {Distance} from './definitions/distance'; | ||
@@ -31,4 +30,5 @@ import type {Expression, ExpressionRegistry} from './expression'; | ||
import {typeOf, Color, validateRGBA, toString as valueToString} from './values'; | ||
import RuntimeError from './runtime_error'; | ||
import {typeOf, validateRGBA, valueToString} from './values'; | ||
import {RuntimeError} from './runtime_error'; | ||
import {Color} from './types/color'; | ||
@@ -46,3 +46,3 @@ export type Varargs = { | ||
class CompoundExpression implements Expression { | ||
export class CompoundExpression implements Expression { | ||
name: string; | ||
@@ -156,3 +156,3 @@ type: Type; | ||
if (!parsed) return null; | ||
actualTypes.push(toString(parsed.type)); | ||
actualTypes.push(typeToString(parsed.type)); | ||
} | ||
@@ -653,5 +653,5 @@ context.error(`Expected arguments of type ${signatures}, but found (${actualTypes.join(', ')}) instead.`); | ||
if (Array.isArray(signature)) { | ||
return `(${signature.map(toString).join(', ')})`; | ||
return `(${signature.map(typeToString).join(', ')})`; | ||
} else { | ||
return `(${toString(signature.type)}...)`; | ||
return `(${typeToString(signature.type)}...)`; | ||
} | ||
@@ -759,2 +759,1 @@ } | ||
export {isFeatureConstant, isGlobalPropertyConstant, isStateConstant, isExpressionConstant}; | ||
export default CompoundExpression; |
@@ -9,11 +9,11 @@ | ||
checkSubtype, | ||
toString, | ||
typeToString, | ||
array | ||
} from '../types'; | ||
import RuntimeError from '../runtime_error'; | ||
import {RuntimeError} from '../runtime_error'; | ||
import {typeOf} from '../values'; | ||
import type {Expression} from '../expression'; | ||
import type ParsingContext from '../parsing_context'; | ||
import type EvaluationContext from '../evaluation_context'; | ||
import type {ParsingContext} from '../parsing_context'; | ||
import type {EvaluationContext} from '../evaluation_context'; | ||
import type {Type} from '../types'; | ||
@@ -28,3 +28,3 @@ | ||
class Assertion implements Expression { | ||
export class Assertion implements Expression { | ||
type: Type; | ||
@@ -94,3 +94,3 @@ args: Array<Expression>; | ||
} else if (i === this.args.length - 1) { | ||
throw new RuntimeError(`Expected value to be of type ${toString(this.type)}, but found ${toString(typeOf(value))} instead.`); | ||
throw new RuntimeError(`Expected value to be of type ${typeToString(this.type)}, but found ${typeToString(typeOf(value))} instead.`); | ||
} | ||
@@ -110,3 +110,1 @@ } | ||
} | ||
export default Assertion; |
import {array, ValueType, NumberType} from '../types'; | ||
import RuntimeError from '../runtime_error'; | ||
import {RuntimeError} from '../runtime_error'; | ||
import type {Expression} from '../expression'; | ||
import type ParsingContext from '../parsing_context'; | ||
import type EvaluationContext from '../evaluation_context'; | ||
import type {ParsingContext} from '../parsing_context'; | ||
import type {EvaluationContext} from '../evaluation_context'; | ||
import type {Type, ArrayType} from '../types'; | ||
import type {Value} from '../values'; | ||
class At implements Expression { | ||
export class At implements Expression { | ||
type: Type; | ||
@@ -64,2 +64,1 @@ index: Expression; | ||
export default At; |
@@ -5,4 +5,4 @@ | ||
import type {Expression} from '../expression'; | ||
import type ParsingContext from '../parsing_context'; | ||
import type EvaluationContext from '../evaluation_context'; | ||
import type {ParsingContext} from '../parsing_context'; | ||
import type {EvaluationContext} from '../evaluation_context'; | ||
import type {Type} from '../types'; | ||
@@ -12,3 +12,3 @@ | ||
class Case implements Expression { | ||
export class Case implements Expression { | ||
type: Type; | ||
@@ -78,2 +78,1 @@ | ||
export default Case; |
import {checkSubtype, ValueType} from '../types'; | ||
import ResolvedImage from '../types/resolved_image'; | ||
import {ResolvedImage} from '../types/resolved_image'; | ||
import type {Expression} from '../expression'; | ||
import type ParsingContext from '../parsing_context'; | ||
import type EvaluationContext from '../evaluation_context'; | ||
import type {ParsingContext} from '../parsing_context'; | ||
import type {EvaluationContext} from '../evaluation_context'; | ||
import type {Type} from '../types'; | ||
class Coalesce implements Expression { | ||
export class Coalesce implements Expression { | ||
type: Type; | ||
@@ -83,2 +83,1 @@ args: Array<Expression>; | ||
export default Coalesce; |
import {BooleanType, ColorType, NumberType, StringType, ValueType} from '../types'; | ||
import {Color, Padding, VariableAnchorOffsetCollection, toString as valueToString, validateRGBA} from '../values'; | ||
import RuntimeError from '../runtime_error'; | ||
import Formatted from '../types/formatted'; | ||
import ResolvedImage from '../types/resolved_image'; | ||
import {valueToString, validateRGBA} from '../values'; | ||
import {RuntimeError} from '../runtime_error'; | ||
import {Formatted} from '../types/formatted'; | ||
import {ResolvedImage} from '../types/resolved_image'; | ||
import {Color} from '../types/color'; | ||
import {Padding} from '../types/padding'; | ||
import {VariableAnchorOffsetCollection} from '../types/variable_anchor_offset_collection'; | ||
import type {Expression} from '../expression'; | ||
import type ParsingContext from '../parsing_context'; | ||
import type EvaluationContext from '../evaluation_context'; | ||
import type {ParsingContext} from '../parsing_context'; | ||
import type {EvaluationContext} from '../evaluation_context'; | ||
import type {Type} from '../types'; | ||
@@ -26,3 +29,3 @@ | ||
*/ | ||
class Coercion implements Expression { | ||
export class Coercion implements Expression { | ||
type: Type; | ||
@@ -127,2 +130,4 @@ args: Array<Expression>; | ||
return ResolvedImage.fromString(valueToString(this.args[0].evaluate(ctx))); | ||
case 'projectionDefinition': | ||
return this.args[0].evaluate(ctx); | ||
default: | ||
@@ -142,2 +147,1 @@ return valueToString(this.args[0].evaluate(ctx)); | ||
export default Coercion; |
import {StringType, BooleanType, CollatorType} from '../types'; | ||
import Collator from '../types/collator'; | ||
import {Collator} from '../types/collator'; | ||
import type {Expression} from '../expression'; | ||
import type EvaluationContext from '../evaluation_context'; | ||
import type ParsingContext from '../parsing_context'; | ||
import type {EvaluationContext} from '../evaluation_context'; | ||
import type {ParsingContext} from '../parsing_context'; | ||
import type {Type} from '../types'; | ||
export default class CollatorExpression implements Expression { | ||
export class CollatorExpression implements Expression { | ||
type: Type; | ||
@@ -11,0 +11,0 @@ caseSensitive: Expression; |
@@ -1,9 +0,9 @@ | ||
import {toString, ValueType, BooleanType, CollatorType} from '../types'; | ||
import Assertion from './assertion'; | ||
import {typeToString, ValueType, BooleanType, CollatorType} from '../types'; | ||
import {Assertion} from './assertion'; | ||
import {typeOf} from '../values'; | ||
import RuntimeError from '../runtime_error'; | ||
import {RuntimeError} from '../runtime_error'; | ||
import type {Expression} from '../expression'; | ||
import type EvaluationContext from '../evaluation_context'; | ||
import type ParsingContext from '../parsing_context'; | ||
import type {EvaluationContext} from '../evaluation_context'; | ||
import type {ParsingContext} from '../parsing_context'; | ||
import type {Type} from '../types'; | ||
@@ -87,3 +87,3 @@ | ||
if (!isComparableType(op, lhs.type)) { | ||
return context.concat(1).error(`"${op}" comparisons are not supported for type '${toString(lhs.type)}'.`) as null; | ||
return context.concat(1).error(`"${op}" comparisons are not supported for type '${typeToString(lhs.type)}'.`) as null; | ||
} | ||
@@ -93,3 +93,3 @@ let rhs = context.parse(args[2], 2, ValueType); | ||
if (!isComparableType(op, rhs.type)) { | ||
return context.concat(2).error(`"${op}" comparisons are not supported for type '${toString(rhs.type)}'.`) as null; | ||
return context.concat(2).error(`"${op}" comparisons are not supported for type '${typeToString(rhs.type)}'.`) as null; | ||
} | ||
@@ -102,3 +102,3 @@ | ||
) { | ||
return context.error(`Cannot compare types '${toString(lhs.type)}' and '${toString(rhs.type)}'.`) as null; | ||
return context.error(`Cannot compare types '${typeToString(lhs.type)}' and '${typeToString(rhs.type)}'.`) as null; | ||
} | ||
@@ -105,0 +105,0 @@ |
import TinyQueue from 'tinyqueue'; | ||
import {Expression} from '../expression'; | ||
import ParsingContext from '../parsing_context'; | ||
import {ParsingContext} from '../parsing_context'; | ||
import {NumberType, Type} from '../types'; | ||
import {isValue} from '../values'; | ||
import EvaluationContext from '../evaluation_context'; | ||
import {EvaluationContext} from '../evaluation_context'; | ||
import {BBox, boxWithinBox, getLngLatFromTileCoord, pointWithinPolygon, segmentIntersectSegment, updateBBox} from '../../util/geometry_util'; | ||
import {classifyRings} from '../../util/classify_rings'; | ||
import CheapRuler from '../../util/cheap_ruler'; | ||
import {CheapRuler} from '../../util/cheap_ruler'; | ||
@@ -535,3 +535,3 @@ type SimpleGeometry = GeoJSON.Polygon | GeoJSON.LineString | GeoJSON.Point; | ||
class Distance implements Expression { | ||
export class Distance implements Expression { | ||
type: Type; | ||
@@ -582,3 +582,1 @@ geojson: GeoJSON.GeoJSON; | ||
} | ||
export default Distance; |
@@ -10,8 +10,8 @@ import { | ||
} from '../types'; | ||
import Formatted, {FormattedSection} from '../types/formatted'; | ||
import {toString, typeOf} from '../values'; | ||
import {Formatted, FormattedSection} from '../types/formatted'; | ||
import {valueToString, typeOf} from '../values'; | ||
import type {Expression} from '../expression'; | ||
import type EvaluationContext from '../evaluation_context'; | ||
import type ParsingContext from '../parsing_context'; | ||
import type {EvaluationContext} from '../evaluation_context'; | ||
import type {ParsingContext} from '../parsing_context'; | ||
import type {Type} from '../types'; | ||
@@ -28,3 +28,3 @@ | ||
export default class FormatExpression implements Expression { | ||
export class FormatExpression implements Expression { | ||
type: Type; | ||
@@ -102,3 +102,3 @@ sections: Array<FormattedSectionExpression>; | ||
return new FormattedSection( | ||
toString(evaluatedContent), | ||
valueToString(evaluatedContent), | ||
null, | ||
@@ -105,0 +105,0 @@ section.scale ? section.scale.evaluate(ctx) : null, |
import {ResolvedImageType, StringType} from '../types'; | ||
import ResolvedImage from '../types/resolved_image'; | ||
import {ResolvedImage} from '../types/resolved_image'; | ||
import type {Expression} from '../expression'; | ||
import type EvaluationContext from '../evaluation_context'; | ||
import type ParsingContext from '../parsing_context'; | ||
import type {EvaluationContext} from '../evaluation_context'; | ||
import type {ParsingContext} from '../parsing_context'; | ||
import type {Type} from '../types'; | ||
export default class ImageExpression implements Expression { | ||
export class ImageExpression implements Expression { | ||
type: Type; | ||
@@ -11,0 +11,0 @@ input: Expression; |
@@ -6,3 +6,3 @@ import { | ||
NullType, | ||
toString, | ||
typeToString, | ||
NumberType, | ||
@@ -12,11 +12,11 @@ isValidType, | ||
} from '../types'; | ||
import RuntimeError from '../runtime_error'; | ||
import {RuntimeError} from '../runtime_error'; | ||
import {typeOf} from '../values'; | ||
import type {Expression} from '../expression'; | ||
import type ParsingContext from '../parsing_context'; | ||
import type EvaluationContext from '../evaluation_context'; | ||
import type {ParsingContext} from '../parsing_context'; | ||
import type {EvaluationContext} from '../evaluation_context'; | ||
import type {Type} from '../types'; | ||
class In implements Expression { | ||
export class In implements Expression { | ||
type: Type; | ||
@@ -44,3 +44,3 @@ needle: Expression; | ||
if (!isValidType(needle.type, [BooleanType, StringType, NumberType, NullType, ValueType])) { | ||
return context.error(`Expected first argument to be of type boolean, string, number or null, but found ${toString(needle.type)} instead`) as null; | ||
return context.error(`Expected first argument to be of type boolean, string, number or null, but found ${typeToString(needle.type)} instead`) as null; | ||
} | ||
@@ -58,7 +58,7 @@ | ||
if (!isValidNativeType(needle, ['boolean', 'string', 'number', 'null'])) { | ||
throw new RuntimeError(`Expected first argument to be of type boolean, string, number or null, but found ${toString(typeOf(needle))} instead.`); | ||
throw new RuntimeError(`Expected first argument to be of type boolean, string, number or null, but found ${typeToString(typeOf(needle))} instead.`); | ||
} | ||
if (!isValidNativeType(haystack, ['string', 'array'])) { | ||
throw new RuntimeError(`Expected second argument to be of type array or string, but found ${toString(typeOf(haystack))} instead.`); | ||
throw new RuntimeError(`Expected second argument to be of type array or string, but found ${typeToString(typeOf(haystack))} instead.`); | ||
} | ||
@@ -79,2 +79,1 @@ | ||
export default In; |
@@ -6,3 +6,3 @@ import { | ||
NullType, | ||
toString, | ||
typeToString, | ||
NumberType, | ||
@@ -12,11 +12,11 @@ isValidType, | ||
} from '../types'; | ||
import RuntimeError from '../runtime_error'; | ||
import {RuntimeError} from '../runtime_error'; | ||
import {typeOf} from '../values'; | ||
import type {Expression} from '../expression'; | ||
import type ParsingContext from '../parsing_context'; | ||
import type EvaluationContext from '../evaluation_context'; | ||
import type {ParsingContext} from '../parsing_context'; | ||
import type {EvaluationContext} from '../evaluation_context'; | ||
import type {Type} from '../types'; | ||
class IndexOf implements Expression { | ||
export class IndexOf implements Expression { | ||
type: Type; | ||
@@ -45,3 +45,3 @@ needle: Expression; | ||
if (!isValidType(needle.type, [BooleanType, StringType, NumberType, NullType, ValueType])) { | ||
return context.error(`Expected first argument to be of type boolean, string, number or null, but found ${toString(needle.type)} instead`) as null; | ||
return context.error(`Expected first argument to be of type boolean, string, number or null, but found ${typeToString(needle.type)} instead`) as null; | ||
} | ||
@@ -63,3 +63,3 @@ | ||
if (!isValidNativeType(needle, ['boolean', 'string', 'number', 'null'])) { | ||
throw new RuntimeError(`Expected first argument to be of type boolean, string, number or null, but found ${toString(typeOf(needle))} instead.`); | ||
throw new RuntimeError(`Expected first argument to be of type boolean, string, number or null, but found ${typeToString(typeOf(needle))} instead.`); | ||
} | ||
@@ -83,3 +83,3 @@ | ||
} else { | ||
throw new RuntimeError(`Expected second argument to be of type array or string, but found ${toString(typeOf(haystack))} instead.`); | ||
throw new RuntimeError(`Expected second argument to be of type array or string, but found ${typeToString(typeOf(haystack))} instead.`); | ||
} | ||
@@ -101,2 +101,1 @@ } | ||
export default IndexOf; |
import Let from './let'; | ||
import Var from './var'; | ||
import Literal from './literal'; | ||
import Assertion from './assertion'; | ||
import Coercion from './coercion'; | ||
import At from './at'; | ||
import In from './in'; | ||
import IndexOf from './index_of'; | ||
import Match from './match'; | ||
import Case from './case'; | ||
import Slice from './slice'; | ||
import Step from './step'; | ||
import Interpolate from './interpolate'; | ||
import Coalesce from './coalesce'; | ||
import {Let} from './let'; | ||
import {Var} from './var'; | ||
import {Literal} from './literal'; | ||
import {Assertion} from './assertion'; | ||
import {Coercion} from './coercion'; | ||
import {At} from './at'; | ||
import {In} from './in'; | ||
import {IndexOf} from './index_of'; | ||
import {Match} from './match'; | ||
import {Case} from './case'; | ||
import {Slice} from './slice'; | ||
import {Step} from './step'; | ||
import {Interpolate} from './interpolate'; | ||
import {Coalesce} from './coalesce'; | ||
import { | ||
@@ -24,9 +24,9 @@ Equals, | ||
} from './comparison'; | ||
import CollatorExpression from './collator'; | ||
import NumberFormat from './number_format'; | ||
import FormatExpression from './format'; | ||
import ImageExpression from './image'; | ||
import Length from './length'; | ||
import Within from './within'; | ||
import Distance from './distance'; | ||
import {CollatorExpression} from './collator'; | ||
import {NumberFormat} from './number_format'; | ||
import {FormatExpression} from './format'; | ||
import {ImageExpression} from './image'; | ||
import {Length} from './length'; | ||
import {Within} from './within'; | ||
import {Distance} from './distance'; | ||
@@ -74,3 +74,1 @@ import type {ExpressionRegistry} from '../expression'; | ||
}; | ||
export default expressions; |
import UnitBezier from '@mapbox/unitbezier'; | ||
import interpolate from '../../util/interpolate'; | ||
import {array, ArrayType, ColorType, ColorTypeT, NumberType, NumberTypeT, PaddingType, PaddingTypeT, VariableAnchorOffsetCollectionType, VariableAnchorOffsetCollectionTypeT, toString, verifyType} from '../types'; | ||
import {array, ArrayType, ColorType, ColorTypeT, NumberType, NumberTypeT, PaddingType, PaddingTypeT, VariableAnchorOffsetCollectionType, VariableAnchorOffsetCollectionTypeT, typeToString, verifyType, ProjectionDefinitionType} from '../types'; | ||
import {findStopLessThanOrEqualTo} from '../stops'; | ||
import {Color} from '../types/color'; | ||
import {interpolateArray, interpolateNumber} from '../../util/interpolate-primitives'; | ||
import {Padding} from '../types/padding'; | ||
import {VariableAnchorOffsetCollection} from '../types/variable_anchor_offset_collection'; | ||
import {ProjectionDefinition} from '../types/projection_definition'; | ||
import type {Stops} from '../stops'; | ||
import type {Expression} from '../expression'; | ||
import type ParsingContext from '../parsing_context'; | ||
import type EvaluationContext from '../evaluation_context'; | ||
import type {Type} from '../types'; | ||
import type {ParsingContext} from '../parsing_context'; | ||
import type {EvaluationContext} from '../evaluation_context'; | ||
import type {ProjectionDefinitionTypeT, Type} from '../types'; | ||
@@ -22,5 +26,4 @@ export type InterpolationType = { | ||
}; | ||
type InterpolatedValueType = NumberTypeT | ColorTypeT | PaddingTypeT | VariableAnchorOffsetCollectionTypeT | ArrayType<NumberTypeT>; | ||
class Interpolate implements Expression { | ||
type InterpolatedValueType = NumberTypeT | ColorTypeT | ProjectionDefinitionTypeT | PaddingTypeT | VariableAnchorOffsetCollectionTypeT | ArrayType<NumberTypeT>; | ||
export class Interpolate implements Expression { | ||
type: InterpolatedValueType; | ||
@@ -130,3 +133,2 @@ | ||
} | ||
const parsed = context.parse(value, valueKey, outputType); | ||
@@ -139,2 +141,3 @@ if (!parsed) return null; | ||
if (!verifyType(outputType, NumberType) && | ||
!verifyType(outputType, ProjectionDefinitionType) && | ||
!verifyType(outputType, ColorType) && | ||
@@ -145,3 +148,3 @@ !verifyType(outputType, PaddingType) && | ||
) { | ||
return context.error(`Type ${toString(outputType)} is not interpolatable.`) as null; | ||
return context.error(`Type ${typeToString(outputType)} is not interpolatable.`) as null; | ||
} | ||
@@ -180,7 +183,20 @@ | ||
case 'interpolate': | ||
return interpolate[this.type.kind](outputLower, outputUpper, t); | ||
switch (this.type.kind) { | ||
case 'number': | ||
return interpolateNumber(outputLower, outputUpper, t) | ||
case 'color': | ||
return Color.interpolate(outputLower, outputUpper, t); | ||
case 'padding': | ||
return Padding.interpolate(outputLower, outputUpper, t); | ||
case 'variableAnchorOffsetCollection': | ||
return VariableAnchorOffsetCollection.interpolate(outputLower, outputUpper, t); | ||
case 'array': | ||
return interpolateArray(outputLower, outputUpper, t); | ||
case 'projectionDefinition': | ||
return ProjectionDefinition.interpolate(outputLower, outputUpper, t); | ||
} | ||
case 'interpolate-hcl': | ||
return interpolate.color(outputLower, outputUpper, t, 'hcl'); | ||
return Color.interpolate(outputLower, outputUpper, t, 'hcl'); | ||
case 'interpolate-lab': | ||
return interpolate.color(outputLower, outputUpper, t, 'lab'); | ||
return Color.interpolate(outputLower, outputUpper, t, 'lab'); | ||
} | ||
@@ -249,2 +265,8 @@ } | ||
export default Interpolate; | ||
export const interpolateFactory = { | ||
color: Color.interpolate, | ||
number: interpolateNumber, | ||
padding: Padding.interpolate, | ||
variableAnchorOffsetCollection: VariableAnchorOffsetCollection.interpolate, | ||
array: interpolateArray | ||
} |
@@ -1,12 +0,12 @@ | ||
import {NumberType, toString} from '../types'; | ||
import {NumberType, typeToString} from '../types'; | ||
import {typeOf} from '../values'; | ||
import RuntimeError from '../runtime_error'; | ||
import {RuntimeError} from '../runtime_error'; | ||
import type {Expression} from '../expression'; | ||
import type ParsingContext from '../parsing_context'; | ||
import type EvaluationContext from '../evaluation_context'; | ||
import type {ParsingContext} from '../parsing_context'; | ||
import type {EvaluationContext} from '../evaluation_context'; | ||
import type {Type} from '../types'; | ||
class Length implements Expression { | ||
export class Length implements Expression { | ||
type: Type; | ||
@@ -28,3 +28,3 @@ input: Expression; | ||
if (input.type.kind !== 'array' && input.type.kind !== 'string' && input.type.kind !== 'value') | ||
return context.error(`Expected argument of type string or array, but found ${toString(input.type)} instead.`) as null; | ||
return context.error(`Expected argument of type string or array, but found ${typeToString(input.type)} instead.`) as null; | ||
@@ -42,3 +42,3 @@ return new Length(input); | ||
} else { | ||
throw new RuntimeError(`Expected value to be of type string or array, but found ${toString(typeOf(input))} instead.`); | ||
throw new RuntimeError(`Expected value to be of type string or array, but found ${typeToString(typeOf(input))} instead.`); | ||
} | ||
@@ -56,2 +56,1 @@ } | ||
export default Length; |
import type {Type} from '../types'; | ||
import type {Expression} from '../expression'; | ||
import type ParsingContext from '../parsing_context'; | ||
import type EvaluationContext from '../evaluation_context'; | ||
import type {ParsingContext} from '../parsing_context'; | ||
import type {EvaluationContext} from '../evaluation_context'; | ||
class Let implements Expression { | ||
export class Let implements Expression { | ||
type: Type; | ||
@@ -60,3 +60,1 @@ bindings: Array<[string, Expression]>; | ||
} | ||
export default Let; |
@@ -6,5 +6,5 @@ import {isValue, typeOf} from '../values'; | ||
import type {Expression} from '../expression'; | ||
import type ParsingContext from '../parsing_context'; | ||
import type {ParsingContext} from '../parsing_context'; | ||
class Literal implements Expression { | ||
export class Literal implements Expression { | ||
type: Type; | ||
@@ -54,2 +54,1 @@ value: Value; | ||
export default Literal; |
@@ -8,4 +8,4 @@ | ||
import type {Expression} from '../expression'; | ||
import type ParsingContext from '../parsing_context'; | ||
import type EvaluationContext from '../evaluation_context'; | ||
import type {ParsingContext} from '../parsing_context'; | ||
import type {EvaluationContext} from '../evaluation_context'; | ||
@@ -17,3 +17,3 @@ // Map input label values to output expression index | ||
class Match implements Expression { | ||
export class Match implements Expression { | ||
type: Type; | ||
@@ -120,2 +120,1 @@ inputType: Type; | ||
export default Match; |
import {StringType, NumberType} from '../types'; | ||
import type {Expression} from '../expression'; | ||
import type EvaluationContext from '../evaluation_context'; | ||
import type ParsingContext from '../parsing_context'; | ||
import type {EvaluationContext} from '../evaluation_context'; | ||
import type {ParsingContext} from '../parsing_context'; | ||
import type {Type} from '../types'; | ||
@@ -27,3 +27,3 @@ | ||
export default class NumberFormat implements Expression { | ||
export class NumberFormat implements Expression { | ||
type: Type; | ||
@@ -30,0 +30,0 @@ number: Expression; |
@@ -6,15 +6,15 @@ import { | ||
array, | ||
toString, | ||
typeToString, | ||
isValidType, | ||
isValidNativeType, | ||
} from '../types'; | ||
import RuntimeError from '../runtime_error'; | ||
import {RuntimeError} from '../runtime_error'; | ||
import {typeOf} from '../values'; | ||
import type {Expression} from '../expression'; | ||
import type ParsingContext from '../parsing_context'; | ||
import type EvaluationContext from '../evaluation_context'; | ||
import type {ParsingContext} from '../parsing_context'; | ||
import type {EvaluationContext} from '../evaluation_context'; | ||
import type {Type} from '../types'; | ||
class Slice implements Expression { | ||
export class Slice implements Expression { | ||
type: Type; | ||
@@ -44,3 +44,3 @@ input: Expression; | ||
if (!isValidType(input.type, [array(ValueType), StringType, ValueType])) { | ||
return context.error(`Expected first argument to be of type array or string, but found ${toString(input.type)} instead`) as null; | ||
return context.error(`Expected first argument to be of type array or string, but found ${typeToString(input.type)} instead`) as null; | ||
} | ||
@@ -72,3 +72,3 @@ | ||
} else { | ||
throw new RuntimeError(`Expected first argument to be of type array or string, but found ${toString(typeOf(input))} instead.`); | ||
throw new RuntimeError(`Expected first argument to be of type array or string, but found ${typeToString(typeOf(input))} instead.`); | ||
} | ||
@@ -90,2 +90,1 @@ } | ||
export default Slice; |
@@ -7,7 +7,7 @@ import {NumberType} from '../types'; | ||
import type {Expression} from '../expression'; | ||
import type ParsingContext from '../parsing_context'; | ||
import type EvaluationContext from '../evaluation_context'; | ||
import type {ParsingContext} from '../parsing_context'; | ||
import type {EvaluationContext} from '../evaluation_context'; | ||
import type {Type} from '../types'; | ||
class Step implements Expression { | ||
export class Step implements Expression { | ||
type: Type; | ||
@@ -108,2 +108,1 @@ | ||
export default Step; |
import type {Type} from '../types'; | ||
import type {Expression} from '../expression'; | ||
import type ParsingContext from '../parsing_context'; | ||
import type EvaluationContext from '../evaluation_context'; | ||
import type {ParsingContext} from '../parsing_context'; | ||
import type {EvaluationContext} from '../evaluation_context'; | ||
class Var implements Expression { | ||
export class Var implements Expression { | ||
type: Type; | ||
@@ -40,2 +40,1 @@ name: string; | ||
export default Var; |
@@ -5,4 +5,4 @@ import {isValue} from '../values'; | ||
import type {Expression} from '../expression'; | ||
import type ParsingContext from '../parsing_context'; | ||
import type EvaluationContext from '../evaluation_context'; | ||
import type {ParsingContext} from '../parsing_context'; | ||
import type {EvaluationContext} from '../evaluation_context'; | ||
import {ICanonicalTileID} from '../../tiles_and_coordinates'; | ||
@@ -147,3 +147,3 @@ import {BBox, EXTENT, boxWithinBox, getTileCoordinates, lineStringWithinPolygon, lineStringWithinPolygons, pointWithinPolygon, pointWithinPolygons, updateBBox} from '../../util/geometry_util'; | ||
class Within implements Expression { | ||
export class Within implements Expression { | ||
type: Type; | ||
@@ -212,3 +212,1 @@ geojson: GeoJSON.GeoJSON; | ||
} | ||
export default Within; |
@@ -1,2 +0,1 @@ | ||
import {Color} from './values'; | ||
import type {FormattedSection} from './types/formatted'; | ||
@@ -6,2 +5,3 @@ import type {GlobalProperties, Feature, FeatureState} from './index'; | ||
import {hasMultipleOuterRings} from '../util/classify_rings'; | ||
import {Color} from './types/color'; | ||
@@ -19,3 +19,3 @@ const geometryTypes = ['Unknown', 'Point', 'LineString', 'Polygon']; | ||
class EvaluationContext { | ||
export class EvaluationContext { | ||
globals: GlobalProperties; | ||
@@ -89,3 +89,3 @@ feature: Feature; | ||
if (!cached) { | ||
cached = this._parseColorCache[input] = Color.parse(input) as Color; | ||
cached = this._parseColorCache[input] = Color.parse(input); | ||
} | ||
@@ -95,3 +95,1 @@ return cached; | ||
} | ||
export default EvaluationContext; |
import {createPropertyExpression, Feature, GlobalProperties, StylePropertyExpression} from '../expression'; | ||
import definitions from './definitions'; | ||
import {expressions} from './definitions'; | ||
import v8 from '../reference/v8.json' with {type: 'json'}; | ||
import {createExpression, ICanonicalTileID, StyleExpression, StylePropertySpecification} from '..'; | ||
import ParsingError from './parsing_error'; | ||
import {VariableAnchorOffsetCollection} from './values'; | ||
import {ExpressionParsingError} from './parsing_error'; | ||
import {getGeometry} from '../../test/lib/geometry'; | ||
import {VariableAnchorOffsetCollection} from './types/variable_anchor_offset_collection'; | ||
// filter out internal "error" and "filter-*" expressions from definition list | ||
const filterExpressionRegex = /filter-/; | ||
const definitionList = Object.keys(definitions).filter((expression) => { | ||
const definitionList = Object.keys(expressions).filter((expression) => { | ||
return expression !== 'error' && !filterExpressionRegex.exec(expression); | ||
@@ -37,3 +37,3 @@ }).sort(); | ||
expect(result).toBe('error'); | ||
expect((value as ParsingError[])).toHaveLength(1); | ||
expect((value as ExpressionParsingError[])).toHaveLength(1); | ||
expect(value[0].message).toBe('"interpolate" expressions cannot be used with this property'); | ||
@@ -633,1 +633,41 @@ }); | ||
}); | ||
describe('projection expression', () => { | ||
test('step', () => { | ||
const response = createExpression(['step', ['zoom'], 'vertical-perspective', 10, 'mercator']); | ||
if (response.result === 'success') { | ||
expect(response.value.evaluate({zoom: 5})).toBe('vertical-perspective'); | ||
expect(response.value.evaluate({zoom: 10})).toBe('mercator'); | ||
expect(response.value.evaluate({zoom: 11})).toBe('mercator'); | ||
} else { | ||
throw new Error('Failed to parse Step expression'); | ||
} | ||
}) | ||
test('step array', () => { | ||
const response = createExpression(['step', ['zoom'], ['literal', ['vertical-perspective', 'mercator', 0.5]], 10, 'mercator'], v8.projection.type as StylePropertySpecification); | ||
if (response.result === 'success') { | ||
expect(response.value.evaluate({zoom: 5})).toStrictEqual(['vertical-perspective', 'mercator', 0.5]); | ||
expect(response.value.evaluate({zoom: 10})).toBe('mercator'); | ||
expect(response.value.evaluate({zoom: 11})).toBe('mercator'); | ||
} else { | ||
throw new Error('Failed to parse Step expression'); | ||
} | ||
}) | ||
test('interpolate', () => { | ||
const response = createExpression(['interpolate', ['linear'], ['zoom'], 8, 'vertical-perspective', 10, 'mercator'], v8.projection.type as StylePropertySpecification); | ||
if (response.result === 'success') { | ||
expect(response.value.evaluate({zoom: 5})).toBe('vertical-perspective'); | ||
expect(response.value.evaluate({zoom: 9})).toEqual({from: 'vertical-perspective', to: 'mercator', transition: 0.5}); | ||
expect(response.value.evaluate({zoom: 11})).toBe('mercator'); | ||
} else { | ||
throw new Error('Failed to parse Interpolate expression'); | ||
} | ||
}) | ||
}); |
import type {Type} from './types'; | ||
import type ParsingContext from './parsing_context'; | ||
import type EvaluationContext from './evaluation_context'; | ||
import type {ParsingContext} from './parsing_context'; | ||
import type {EvaluationContext} from './evaluation_context'; | ||
@@ -5,0 +5,0 @@ /** |
import extend from '../util/extend'; | ||
import ExpressionParsingError from './parsing_error'; | ||
import ParsingContext from './parsing_context'; | ||
import EvaluationContext from './evaluation_context'; | ||
import {extendBy} from '../util/extend'; | ||
import {ExpressionParsingError} from './parsing_error'; | ||
import {ParsingContext} from './parsing_context'; | ||
import {EvaluationContext} from './evaluation_context'; | ||
import CompoundExpression, {isFeatureConstant, | ||
import {CompoundExpression, isFeatureConstant, | ||
isGlobalPropertyConstant, | ||
@@ -13,22 +13,29 @@ isStateConstant, | ||
import Step from './definitions/step'; | ||
import Interpolate from './definitions/interpolate'; | ||
import Coalesce from './definitions/coalesce'; | ||
import Let from './definitions/let'; | ||
import definitions from './definitions'; | ||
import {Step} from './definitions/step'; | ||
import {Interpolate} from './definitions/interpolate'; | ||
import {Coalesce} from './definitions/coalesce'; | ||
import {Let} from './definitions/let'; | ||
import {expressions} from './definitions'; | ||
import RuntimeError from './runtime_error'; | ||
import {RuntimeError} from './runtime_error'; | ||
import {success, error} from '../util/result'; | ||
import {supportsPropertyExpression, supportsZoomExpression, supportsInterpolation} from '../util/properties'; | ||
import type {Type, EvaluationKind} from './types'; | ||
import {ColorType, StringType, NumberType, BooleanType, ValueType, FormattedType, PaddingType, ResolvedImageType, VariableAnchorOffsetCollectionType, array, type Type, type EvaluationKind, ProjectionDefinitionType} from './types'; | ||
import type {Value} from './values'; | ||
import type {Expression} from './expression'; | ||
import type {StylePropertySpecification} from '..'; | ||
import {type StylePropertySpecification} from '..'; | ||
import type {Result} from '../util/result'; | ||
import type {InterpolationType} from './definitions/interpolate'; | ||
import type {PropertyValueSpecification, VariableAnchorOffsetCollectionSpecification} from '../types.g'; | ||
import type {PaddingSpecification, PropertyValueSpecification, VariableAnchorOffsetCollectionSpecification} from '../types.g'; | ||
import type {FormattedSection} from './types/formatted'; | ||
import type {Point2D} from '../point2d'; | ||
import {ICanonicalTileID} from '../tiles_and_coordinates'; | ||
import {isFunction, createFunction} from '../function'; | ||
import {Color} from './types/color'; | ||
import {Padding} from './types/padding'; | ||
import {VariableAnchorOffsetCollection} from './types/variable_anchor_offset_collection'; | ||
import {ProjectionDefinition} from './types/projection_definition'; | ||
export type Feature = { | ||
@@ -130,3 +137,3 @@ readonly type: 0 | 1 | 2 | 3 | 'Unknown' | 'Point' | 'MultiPoint' | 'LineString' | 'MultiLineString' | 'Polygon' | 'MultiPolygon'; | ||
return Array.isArray(expression) && expression.length > 0 && | ||
typeof expression[0] === 'string' && expression[0] in definitions; | ||
typeof expression[0] === 'string' && expression[0] in expressions; | ||
} | ||
@@ -144,3 +151,3 @@ | ||
export function createExpression(expression: unknown, propertySpec?: StylePropertySpecification | null): Result<StyleExpression, Array<ExpressionParsingError>> { | ||
const parser = new ParsingContext(definitions, isExpressionConstant, [], propertySpec ? getExpectedType(propertySpec) : undefined); | ||
const parser = new ParsingContext(expressions, isExpressionConstant, [], propertySpec ? getExpectedType(propertySpec) : undefined); | ||
@@ -339,5 +346,2 @@ // For string-valued properties, coerce to string at the top level rather than asserting. | ||
import {isFunction, createFunction} from '../function'; | ||
import {Color, VariableAnchorOffsetCollection} from './values'; | ||
// serialization wrapper for old-style stop functions normalized to the | ||
@@ -357,3 +361,3 @@ // expression interface | ||
this._specification = specification; | ||
extend(this, createFunction(this._parameters, this._specification)); | ||
extendBy(this, createFunction(this._parameters, this._specification)); | ||
} | ||
@@ -396,5 +400,7 @@ | ||
} else if (specification.type === 'padding' && (typeof value === 'number' || Array.isArray(value))) { | ||
constant = Padding.parse(value as (number | number[])); | ||
constant = Padding.parse(value as PaddingSpecification); | ||
} else if (specification.type === 'variableAnchorOffsetCollection' && Array.isArray(value)) { | ||
constant = VariableAnchorOffsetCollection.parse(value as VariableAnchorOffsetCollectionSpecification); | ||
} else if (specification.type === 'projectionDefinition' && typeof value === 'string') { | ||
constant = ProjectionDefinition.parse(value); | ||
} | ||
@@ -449,6 +455,2 @@ return { | ||
import {ColorType, StringType, NumberType, BooleanType, ValueType, FormattedType, PaddingType, ResolvedImageType, VariableAnchorOffsetCollectionType, array} from './types'; | ||
import Padding from '../util/padding'; | ||
import {ICanonicalTileID} from '../tiles_and_coordinates'; | ||
function getExpectedType(spec: StylePropertySpecification): Type { | ||
@@ -463,2 +465,3 @@ const types = { | ||
padding: PaddingType, | ||
projectionDefinition: ProjectionDefinitionType, | ||
resolvedImage: ResolvedImageType, | ||
@@ -487,2 +490,4 @@ variableAnchorOffsetCollection: VariableAnchorOffsetCollectionType | ||
return VariableAnchorOffsetCollection.parse(spec.default) || null; | ||
} else if (spec.type === 'projectionDefinition') { | ||
return ProjectionDefinition.parse(spec.default) || null; | ||
} else if (spec.default === undefined) { | ||
@@ -489,0 +494,0 @@ return null; |
@@ -1,8 +0,8 @@ | ||
import Scope from './scope'; | ||
import {Scope} from './scope'; | ||
import {checkSubtype} from './types'; | ||
import ExpressionParsingError from './parsing_error'; | ||
import Literal from './definitions/literal'; | ||
import Assertion from './definitions/assertion'; | ||
import Coercion from './definitions/coercion'; | ||
import EvaluationContext from './evaluation_context'; | ||
import {ExpressionParsingError} from './parsing_error'; | ||
import {Literal} from './definitions/literal'; | ||
import {Assertion} from './definitions/assertion'; | ||
import {Coercion} from './definitions/coercion'; | ||
import {EvaluationContext} from './evaluation_context'; | ||
@@ -16,3 +16,3 @@ import type {Expression, ExpressionRegistry} from './expression'; | ||
*/ | ||
class ParsingContext { | ||
export class ParsingContext { | ||
registry: ExpressionRegistry; | ||
@@ -124,2 +124,4 @@ path: Array<number>; | ||
parsed = annotate(parsed, expected, options.typeAnnotation || 'assert'); | ||
} else if ((expected.kind === 'projectionDefinition') && (actual.kind === 'string' || actual.kind === 'array')) { | ||
parsed = annotate(parsed, expected, options.typeAnnotation || 'coerce'); | ||
} else if ((expected.kind === 'color' || expected.kind === 'formatted' || expected.kind === 'resolvedImage') && (actual.kind === 'value' || actual.kind === 'string')) { | ||
@@ -210,2 +212,1 @@ parsed = annotate(parsed, expected, options.typeAnnotation || 'coerce'); | ||
export default ParsingContext; |
@@ -1,2 +0,2 @@ | ||
class ExpressionParsingError extends Error { | ||
export class ExpressionParsingError extends Error { | ||
key: string; | ||
@@ -10,3 +10,1 @@ message: string; | ||
} | ||
export default ExpressionParsingError; |
@@ -1,2 +0,2 @@ | ||
class RuntimeError { | ||
export class RuntimeError { | ||
name: string; | ||
@@ -14,3 +14,1 @@ message: string; | ||
} | ||
export default RuntimeError; |
@@ -7,3 +7,3 @@ import type {Expression} from './expression'; | ||
*/ | ||
class Scope { | ||
export class Scope { | ||
parent: Scope; | ||
@@ -34,3 +34,1 @@ bindings: {[_: string]: Expression}; | ||
} | ||
export default Scope; |
@@ -1,2 +0,2 @@ | ||
import RuntimeError from './runtime_error'; | ||
import {RuntimeError} from './runtime_error'; | ||
@@ -3,0 +3,0 @@ import type {Expression} from './expression'; |
@@ -16,2 +16,5 @@ export type NullTypeT = { | ||
}; | ||
export type ProjectionDefinitionTypeT = { | ||
kind: 'projectionDefinition'; | ||
}; | ||
export type ObjectTypeT = { | ||
@@ -44,3 +47,3 @@ kind: 'object'; | ||
export type Type = NullTypeT | NumberTypeT | StringTypeT | BooleanTypeT | ColorTypeT | ObjectTypeT | ValueTypeT | | ||
export type Type = NullTypeT | NumberTypeT | StringTypeT | BooleanTypeT | ColorTypeT | ProjectionDefinitionTypeT | ObjectTypeT | ValueTypeT | | ||
ArrayType | ErrorTypeT | CollatorTypeT | FormattedTypeT | PaddingTypeT | ResolvedImageTypeT | VariableAnchorOffsetCollectionTypeT; | ||
@@ -61,2 +64,3 @@ | ||
export const ColorType = {kind: 'color'} as ColorTypeT; | ||
export const ProjectionDefinitionType = {kind: 'projectionDefinition'} as ProjectionDefinitionTypeT; | ||
export const ObjectType = {kind: 'object'} as ObjectTypeT; | ||
@@ -79,5 +83,5 @@ export const ValueType = {kind: 'value'} as ValueTypeT; | ||
export function toString(type: Type): string { | ||
export function typeToString(type: Type): string { | ||
if (type.kind === 'array') { | ||
const itemType = toString(type.itemType); | ||
const itemType = typeToString(type.itemType); | ||
return typeof type.N === 'number' ? | ||
@@ -97,2 +101,3 @@ `array<${itemType}, ${type.N}>` : | ||
ColorType, | ||
ProjectionDefinitionType, | ||
FormattedType, | ||
@@ -131,3 +136,3 @@ ObjectType, | ||
return `Expected ${toString(expected)} but found ${toString(t)} instead.`; | ||
return `Expected ${typeToString(expected)} but found ${typeToString(t)} instead.`; | ||
} | ||
@@ -134,0 +139,0 @@ |
@@ -25,3 +25,3 @@ // Flow type declarations for Intl cribbed from | ||
export default class Collator { | ||
export class Collator { | ||
locale: string | null; | ||
@@ -28,0 +28,0 @@ sensitivity: 'base' | 'accent' | 'case' | 'variant'; |
@@ -1,3 +0,3 @@ | ||
import type Color from '../../util/color'; | ||
import type ResolvedImage from '../types/resolved_image'; | ||
import type {Color} from '../../expression/types/color'; | ||
import type {ResolvedImage} from '../types/resolved_image'; | ||
@@ -20,3 +20,3 @@ export class FormattedSection { | ||
export default class Formatted { | ||
export class Formatted { | ||
sections: Array<FormattedSection>; | ||
@@ -23,0 +23,0 @@ |
@@ -6,3 +6,3 @@ export type ResolvedImageOptions = { | ||
export default class ResolvedImage { | ||
export class ResolvedImage { | ||
name: string; | ||
@@ -9,0 +9,0 @@ available: boolean; |
import Color from '../util/color'; | ||
import Collator from './types/collator'; | ||
import Formatted from './types/formatted'; | ||
import Padding from '../util/padding'; | ||
import VariableAnchorOffsetCollection from '../util/variable_anchor_offset_collection'; | ||
import ResolvedImage from './types/resolved_image'; | ||
import {NullType, NumberType, StringType, BooleanType, ColorType, ObjectType, ValueType, CollatorType, FormattedType, ResolvedImageType, array, PaddingType, VariableAnchorOffsetCollectionType} from './types'; | ||
import {Color} from './types/color'; | ||
import {Collator} from './types/collator'; | ||
import {Formatted} from './types/formatted'; | ||
import {Padding} from './types/padding'; | ||
import {VariableAnchorOffsetCollection} from './types/variable_anchor_offset_collection'; | ||
import {ResolvedImage} from './types/resolved_image'; | ||
import {ProjectionDefinition} from './types/projection_definition'; | ||
import {NullType, NumberType, StringType, BooleanType, ColorType, ObjectType, ValueType, CollatorType, FormattedType, ResolvedImageType, array, PaddingType, VariableAnchorOffsetCollectionType, ProjectionDefinitionType} from './types'; | ||
@@ -31,3 +32,3 @@ import type {Type} from './types'; | ||
export type Value = null | string | boolean | number | Color | Collator | Formatted | Padding | ResolvedImage | VariableAnchorOffsetCollection | ReadonlyArray<Value> | { | ||
export type Value = null | string | boolean | number | Color | ProjectionDefinition | Collator | Formatted | Padding | ResolvedImage | VariableAnchorOffsetCollection | ReadonlyArray<Value> | { | ||
readonly [x: string]: Value; | ||
@@ -41,2 +42,3 @@ }; | ||
typeof mixed === 'number' || | ||
mixed instanceof ProjectionDefinition || | ||
mixed instanceof Color || | ||
@@ -79,2 +81,4 @@ mixed instanceof Collator || | ||
return ColorType; | ||
} else if (value instanceof ProjectionDefinition) { | ||
return ProjectionDefinitionType; | ||
} else if (value instanceof Collator) { | ||
@@ -112,3 +116,3 @@ return CollatorType; | ||
export function toString(value: Value) { | ||
export function valueToString(value: Value) { | ||
const type = typeof value; | ||
@@ -119,3 +123,3 @@ if (value === null) { | ||
return String(value); | ||
} else if (value instanceof Color || value instanceof Formatted || value instanceof Padding || value instanceof VariableAnchorOffsetCollection || value instanceof ResolvedImage) { | ||
} else if (value instanceof Color || value instanceof ProjectionDefinition || value instanceof Formatted || value instanceof Padding || value instanceof VariableAnchorOffsetCollection || value instanceof ResolvedImage) { | ||
return value.toString(); | ||
@@ -126,3 +130,1 @@ } else { | ||
} | ||
export {Color, Collator, Padding, VariableAnchorOffsetCollection}; |
@@ -55,3 +55,3 @@ import {isExpressionFilter} from './index'; | ||
*/ | ||
export default function convertFilter(filter: FilterSpecification, expectedTypes: ExpectedTypes = {}): ExpressionFilterSpecification { | ||
export function convertFilter(filter: FilterSpecification, expectedTypes: ExpectedTypes = {}): ExpressionFilterSpecification { | ||
if (isExpressionFilter(filter)) return filter; | ||
@@ -58,0 +58,0 @@ if (!filter) return true; |
@@ -1,4 +0,4 @@ | ||
import {default as createFilter, isExpressionFilter} from '.'; | ||
import {featureFilter, isExpressionFilter} from '.'; | ||
import convertFilter from './convert'; | ||
import {convertFilter} from './convert'; | ||
import {ICanonicalTileID} from '../tiles_and_coordinates'; | ||
@@ -86,3 +86,3 @@ import {ExpressionFilterSpecification, ExpressionInputType, ExpressionSpecification, FilterSpecification} from '../types.g'; | ||
test('expression, zoom', () => { | ||
const f = createFilter(['>=', ['number', ['get', 'x']], ['zoom']]).filter; | ||
const f = featureFilter(['>=', ['number', ['get', 'x']], ['zoom']]).filter; | ||
expect(f({zoom: 1}, {properties: {x: 0}} as any as Feature)).toBe(false); | ||
@@ -98,3 +98,3 @@ expect(f({zoom: 1}, {properties: {x: 1.5}} as any as Feature)).toBe(true); | ||
jest.spyOn(console, 'warn').mockImplementation(() => { }); | ||
const f = createFilter(['==', ['string', ['get', 'x']], ['string', ['get', 'y']]]).filter; | ||
const f = featureFilter(['==', ['string', ['get', 'x']], ['string', ['get', 'y']]]).filter; | ||
expect(f({zoom: 0}, {properties: {x: 1, y: 1}} as any as Feature)).toBe(false); | ||
@@ -108,3 +108,3 @@ expect(f({zoom: 0}, {properties: {x: '1', y: '1'}} as any as Feature)).toBe(true); | ||
test('expression, collator comparison', () => { | ||
const caseSensitive = createFilter(['==', ['string', ['get', 'x']], ['string', ['get', 'y']], ['collator', {'case-sensitive': true}]]).filter; | ||
const caseSensitive = featureFilter(['==', ['string', ['get', 'x']], ['string', ['get', 'y']], ['collator', {'case-sensitive': true}]]).filter; | ||
expect(caseSensitive({zoom: 0}, {properties: {x: 'a', y: 'b'}} as any as Feature)).toBe(false); | ||
@@ -114,3 +114,3 @@ expect(caseSensitive({zoom: 0}, {properties: {x: 'a', y: 'A'}} as any as Feature)).toBe(false); | ||
const caseInsensitive = createFilter(['==', ['string', ['get', 'x']], ['string', ['get', 'y']], ['collator', {'case-sensitive': false}]]).filter; | ||
const caseInsensitive = featureFilter(['==', ['string', ['get', 'x']], ['string', ['get', 'y']], ['collator', {'case-sensitive': false}]]).filter; | ||
expect(caseInsensitive({zoom: 0}, {properties: {x: 'a', y: 'b'}} as any as Feature)).toBe(false); | ||
@@ -122,19 +122,19 @@ expect(caseInsensitive({zoom: 0}, {properties: {x: 'a', y: 'A'}} as any as Feature)).toBe(true); | ||
test('expression, any/all', () => { | ||
expect(createFilter(['all']).filter(undefined, undefined)).toBe(true); | ||
expect(createFilter(['all', true]).filter(undefined, undefined)).toBe(true); | ||
expect(createFilter(['all', true, false]).filter(undefined, undefined)).toBe(false); | ||
expect(createFilter(['all', true, true]).filter(undefined, undefined)).toBe(true); | ||
expect(createFilter(['any']).filter(undefined, undefined)).toBe(false); | ||
expect(createFilter(['any', true]).filter(undefined, undefined)).toBe(true); | ||
expect(createFilter(['any', true, false]).filter(undefined, undefined)).toBe(true); | ||
expect(createFilter(['any', false, false]).filter(undefined, undefined)).toBe(false); | ||
expect(featureFilter(['all']).filter(undefined, undefined)).toBe(true); | ||
expect(featureFilter(['all', true]).filter(undefined, undefined)).toBe(true); | ||
expect(featureFilter(['all', true, false]).filter(undefined, undefined)).toBe(false); | ||
expect(featureFilter(['all', true, true]).filter(undefined, undefined)).toBe(true); | ||
expect(featureFilter(['any']).filter(undefined, undefined)).toBe(false); | ||
expect(featureFilter(['any', true]).filter(undefined, undefined)).toBe(true); | ||
expect(featureFilter(['any', true, false]).filter(undefined, undefined)).toBe(true); | ||
expect(featureFilter(['any', false, false]).filter(undefined, undefined)).toBe(false); | ||
}); | ||
test('expression, literal', () => { | ||
expect(createFilter(['literal', true]).filter(undefined, undefined)).toBe(true); | ||
expect(createFilter(['literal', false]).filter(undefined, undefined)).toBe(false); | ||
expect(featureFilter(['literal', true]).filter(undefined, undefined)).toBe(true); | ||
expect(featureFilter(['literal', false]).filter(undefined, undefined)).toBe(false); | ||
}); | ||
test('expression, match', () => { | ||
const match = createFilter(['match', ['get', 'x'], ['a', 'b', 'c'], true, false]).filter; | ||
const match = featureFilter(['match', ['get', 'x'], ['a', 'b', 'c'], true, false]).filter; | ||
expect(match(undefined, {properties: {x: 'a'}} as any as Feature)).toBe(true); | ||
@@ -147,11 +147,11 @@ expect(match(undefined, {properties: {x: 'c'}} as any as Feature)).toBe(true); | ||
expect(() => { | ||
createFilter(['==', ['number', ['get', 'x']], ['string', ['get', 'y']]]); | ||
featureFilter(['==', ['number', ['get', 'x']], ['string', ['get', 'y']]]); | ||
}).toThrow(); | ||
expect(() => { | ||
createFilter(['number', ['get', 'x']]); | ||
featureFilter(['number', ['get', 'x']]); | ||
}).toThrow(); | ||
expect(() => { | ||
createFilter(['boolean', ['get', 'x']]); | ||
featureFilter(['boolean', ['get', 'x']]); | ||
}).not.toThrow(); | ||
@@ -162,3 +162,3 @@ | ||
test('expression, within', () => { | ||
const withinFilter = createFilter(['within', {'type': 'Polygon', 'coordinates': [[[0, 0], [5, 0], [5, 5], [0, 5], [0, 0]]]}]); | ||
const withinFilter = featureFilter(['within', {'type': 'Polygon', 'coordinates': [[[0, 0], [5, 0], [5, 5], [0, 5], [0, 0]]]}]); | ||
expect(withinFilter.needGeometry).toBe(true); | ||
@@ -181,3 +181,3 @@ const canonical = {z: 3, x: 3, y: 3} as ICanonicalTileID; | ||
legacyFilterTests(createFilter); | ||
legacyFilterTests(featureFilter); | ||
@@ -219,3 +219,3 @@ }); | ||
const converted = convertFilter(f); | ||
return createFilter(converted); | ||
return featureFilter(converted); | ||
}); | ||
@@ -230,3 +230,3 @@ | ||
const converted = convertFilter(filter); | ||
const f = createFilter(converted).filter; | ||
const f = featureFilter(converted).filter; | ||
@@ -233,0 +233,0 @@ expect(f({zoom: 0}, {properties: {x: 0, y: 1, z: 1}} as any as Feature)).toBe(true); |
@@ -18,6 +18,3 @@ import {createExpression} from '../expression'; | ||
export default createFilter; | ||
export {isExpressionFilter}; | ||
function isExpressionFilter(filter: any): filter is ExpressionFilterSpecification { | ||
export function isExpressionFilter(filter: any): filter is ExpressionFilterSpecification { | ||
if (filter === true || filter === false) { | ||
@@ -84,3 +81,3 @@ return true; | ||
*/ | ||
function createFilter(filter: any): FeatureFilter { | ||
export function featureFilter(filter: any): FeatureFilter { | ||
if (filter === null || filter === undefined) { | ||
@@ -87,0 +84,0 @@ return {filter: () => true, needGeometry: false}; |
@@ -1,2 +0,2 @@ | ||
import format from './format'; | ||
import {format} from './format'; | ||
@@ -3,0 +3,0 @@ function roundtrip(style) { |
import reference from './reference/latest'; | ||
import {latest} from './reference/latest'; | ||
import stringifyPretty from 'json-stringify-pretty-compact'; | ||
@@ -41,7 +41,7 @@ | ||
*/ | ||
function format(style, space = 2) { | ||
style = sortKeysBy(style, reference.$root); | ||
export function format(style, space = 2) { | ||
style = sortKeysBy(style, latest.$root); | ||
if (style.layers) { | ||
style.layers = style.layers.map((layer) => sortKeysBy(layer, reference.layer)); | ||
style.layers = style.layers.map((layer) => sortKeysBy(layer, latest.layer)); | ||
} | ||
@@ -52,2 +52,1 @@ | ||
export default format; |
import type {StylePropertySpecification} from '..'; | ||
export default convertFunction; | ||
function convertLiteral(value) { | ||
@@ -10,3 +8,3 @@ return typeof value === 'object' ? ['literal', value] : value; | ||
function convertFunction(parameters: any, propertySpec: StylePropertySpecification) { | ||
export function convertFunction(parameters: any, propertySpec: StylePropertySpecification) { | ||
let stops = parameters.stops; | ||
@@ -13,0 +11,0 @@ if (!stops) { |
import {expectToMatchColor} from '../../test/lib/util'; | ||
import {createFunction} from './index'; | ||
import Color from '../util/color'; | ||
import Formatted from '../expression/types/formatted'; | ||
import Padding from '../util/padding'; | ||
import {Color} from '../expression/types/color'; | ||
import {Formatted} from '../expression/types/formatted'; | ||
import {Padding} from '../expression/types/padding'; | ||
@@ -7,0 +7,0 @@ describe('binary search', () => { |
@@ -1,11 +0,10 @@ | ||
import Color from '../util/color'; | ||
import extend from '../util/extend'; | ||
import getType from '../util/get_type'; | ||
import interpolate, {isSupportedInterpolationColorSpace} from '../util/interpolate'; | ||
import Interpolate from '../expression/definitions/interpolate'; | ||
import Formatted from '../expression/types/formatted'; | ||
import ResolvedImage from '../expression/types/resolved_image'; | ||
import {Color, isSupportedInterpolationColorSpace} from '../expression/types/color'; | ||
import {extendBy} from '../util/extend'; | ||
import {getType} from '../util/get_type'; | ||
import {Interpolate, interpolateFactory} from '../expression/definitions/interpolate'; | ||
import {Formatted} from '../expression/types/formatted'; | ||
import {ResolvedImage} from '../expression/types/resolved_image'; | ||
import {supportsInterpolation} from '../util/properties'; | ||
import {findStopLessThanOrEqualTo} from '../expression/stops'; | ||
import Padding from '../util/padding'; | ||
import {Padding} from '../expression/types/padding'; | ||
@@ -30,3 +29,3 @@ export function isFunction(value) { | ||
parameters = extend({}, parameters); | ||
parameters = extendBy({}, parameters); | ||
@@ -178,3 +177,3 @@ if (parameters.stops) { | ||
const outputUpper = parameters.stops[index + 1][1]; | ||
const interp = interpolate[propertySpec.type] || identityFunction; | ||
const interp = interpolateFactory[propertySpec.type] || identityFunction; | ||
@@ -181,0 +180,0 @@ if (typeof outputLower.evaluate === 'function') { |
@@ -1,2 +0,2 @@ | ||
import group from './group_by_layout'; | ||
import {groupByLayout} from './group_by_layout'; | ||
@@ -13,9 +13,9 @@ describe('group by layout', () => { | ||
}; | ||
expect(group([a, b], {})).toEqual([[a, b]]); | ||
expect(group([a, b], {})[0][0]).toBe(a); | ||
expect(group([a, b], {})[0][1]).toBe(b); | ||
expect(groupByLayout([a, b], {})).toEqual([[a, b]]); | ||
expect(groupByLayout([a, b], {})[0][0]).toBe(a); | ||
expect(groupByLayout([a, b], {})[0][1]).toBe(b); | ||
}); | ||
test('group does not group unrelated layers', () => { | ||
expect(group([ | ||
expect(groupByLayout([ | ||
{ | ||
@@ -41,3 +41,3 @@ 'id': 'parent', | ||
test('group works even for differing layout key orders', () => { | ||
expect(group([ | ||
expect(groupByLayout([ | ||
{ | ||
@@ -44,0 +44,0 @@ 'id': 'parent', |
import refProperties from './util/ref_properties'; | ||
import {refProperties} from './util/ref_properties'; | ||
@@ -34,4 +34,2 @@ function stringify(obj) { | ||
export default groupByLayout; | ||
/** | ||
@@ -52,3 +50,3 @@ * Given an array of layers, return an array of arrays of layers where all | ||
*/ | ||
function groupByLayout(layers, cachedKeys) { | ||
export function groupByLayout(layers, cachedKeys) { | ||
const groups = {}; | ||
@@ -55,0 +53,0 @@ |
@@ -72,3 +72,4 @@ | ||
'variableAnchorOffsetCollection', | ||
'sprite' | ||
'sprite', | ||
'projectionDefinition' | ||
]); | ||
@@ -75,0 +76,0 @@ const keys = [ |
103
src/index.ts
@@ -0,1 +1,44 @@ | ||
import v8Spec from './reference/v8.json' with {type: 'json'}; | ||
const v8 = v8Spec as any; | ||
import latest from './reference/latest'; | ||
import {derefLayers} from './deref'; | ||
import {diff} from './diff'; | ||
import {ValidationError} from './error/validation_error'; | ||
import {ParsingError} from './error/parsing_error'; | ||
import {FeatureState, StyleExpression, isExpression, isZoomExpression, createExpression, createPropertyExpression, normalizePropertyExpression, ZoomConstantExpression, ZoomDependentExpression, StylePropertyFunction, Feature, GlobalProperties, SourceExpression, CompositeExpression, StylePropertyExpression} from './expression'; | ||
import {featureFilter, isExpressionFilter} from './feature_filter'; | ||
import {convertFilter} from './feature_filter/convert'; | ||
import {Color} from './expression/types/color'; | ||
import {Padding} from './expression/types/padding'; | ||
import {VariableAnchorOffsetCollection} from './expression/types/variable_anchor_offset_collection'; | ||
import {Formatted, FormattedSection} from './expression/types/formatted'; | ||
import {createFunction, isFunction} from './function'; | ||
import {convertFunction} from './function/convert'; | ||
import {eachSource, eachLayer, eachProperty} from './visit'; | ||
import {ResolvedImage} from './expression/types/resolved_image'; | ||
import {supportsPropertyExpression} from './util/properties'; | ||
import {IMercatorCoordinate, ICanonicalTileID, ILngLat, ILngLatLike} from './tiles_and_coordinates'; | ||
import {EvaluationContext} from './expression/evaluation_context'; | ||
import {FormattedType, NullType, Type, typeToString, ColorType, ProjectionDefinitionType} from './expression/types'; | ||
import {expressions} from './expression/definitions'; | ||
import {Interpolate} from './expression/definitions/interpolate'; | ||
import {interpolateFactory, type InterpolationType} from './expression/definitions/interpolate'; | ||
import {groupByLayout} from './group_by_layout'; | ||
import {emptyStyle} from './empty'; | ||
import {validateStyleMin} from './validate_style.min'; | ||
import {Step} from './expression/definitions/step'; | ||
import {typeOf} from './expression/values'; | ||
import {FormatExpression} from './expression/definitions/format'; | ||
import {Literal} from './expression/definitions/literal'; | ||
import {CompoundExpression} from './expression/compound_expression'; | ||
import {ColorSpecification, PaddingSpecification, ProjectionDefinitionSpecification, VariableAnchorOffsetCollectionSpecification} from './types.g'; | ||
import {format} from './format'; | ||
import {validate} from './validate/validate'; | ||
import {migrate} from './migrate'; | ||
import {classifyRings} from './util/classify_rings'; | ||
import {ProjectionDefinition} from './expression/types/projection_definition'; | ||
type ExpressionType = 'data-driven' | 'cross-faded' | 'cross-faded-data-driven' | 'color-ramp' | 'data-constant' | 'constant'; | ||
@@ -40,3 +83,3 @@ type ExpressionParameters = Array<'zoom' | 'feature' | 'feature-state' | 'heatmap-density' | 'line-progress'>; | ||
transition: boolean; | ||
default?: string; | ||
default?: ColorSpecification; | ||
overridable: boolean; | ||
@@ -64,3 +107,3 @@ } | { | ||
transition: boolean; | ||
default?: number | Array<number>; | ||
default?: PaddingSpecification; | ||
} | { | ||
@@ -72,47 +115,10 @@ type: 'variableAnchorOffsetCollection'; | ||
default?: VariableAnchorOffsetCollectionSpecification; | ||
} | { | ||
type: 'projectionDefinition'; | ||
'property-type': ExpressionType; | ||
expression?: ExpressionSpecificationDefinition; | ||
transition: boolean; | ||
default?: ProjectionDefinitionSpecification; | ||
}; | ||
import v8Spec from './reference/v8.json' with {type: 'json'}; | ||
const v8 = v8Spec as any; | ||
import latest from './reference/latest'; | ||
import derefLayers from './deref'; | ||
import diff from './diff'; | ||
import ValidationError from './error/validation_error'; | ||
import ParsingError from './error/parsing_error'; | ||
import {FeatureState, StyleExpression, isExpression, isZoomExpression, createExpression, createPropertyExpression, normalizePropertyExpression, ZoomConstantExpression, ZoomDependentExpression, StylePropertyFunction, Feature, GlobalProperties, SourceExpression, CompositeExpression, StylePropertyExpression} from './expression'; | ||
import featureFilter, {isExpressionFilter} from './feature_filter'; | ||
import convertFilter from './feature_filter/convert'; | ||
import Color from './util/color'; | ||
import Padding from './util/padding'; | ||
import VariableAnchorOffsetCollection from './util/variable_anchor_offset_collection'; | ||
import Formatted, {FormattedSection} from './expression/types/formatted'; | ||
import {createFunction, isFunction} from './function'; | ||
import convertFunction from './function/convert'; | ||
import {eachSource, eachLayer, eachProperty} from './visit'; | ||
import ResolvedImage from './expression/types/resolved_image'; | ||
import {supportsPropertyExpression} from './util/properties'; | ||
import {IMercatorCoordinate, ICanonicalTileID, ILngLat, ILngLatLike} from './tiles_and_coordinates'; | ||
import EvaluationContext from './expression/evaluation_context'; | ||
import {FormattedType, NullType, Type, toString, ColorType} from './expression/types'; | ||
import interpolates, {interpolateFactory} from './util/interpolate'; | ||
import {expressions} from './expression/definitions'; | ||
import Interpolate from './expression/definitions/interpolate'; | ||
import type {InterpolationType} from './expression/definitions/interpolate'; | ||
import groupByLayout from './group_by_layout'; | ||
import emptyStyle from './empty'; | ||
import validateStyleMin from './validate_style.min'; | ||
import Step from './expression/definitions/step'; | ||
import {typeOf} from './expression/values'; | ||
import FormatExpression from './expression/definitions/format'; | ||
import Literal from './expression/definitions/literal'; | ||
import CompoundExpression from './expression/compound_expression'; | ||
import {VariableAnchorOffsetCollectionSpecification} from './types.g'; | ||
import format from './format'; | ||
import validate from './validate/validate'; | ||
import migrate from './migrate'; | ||
import {classifyRings} from './util/classify_rings'; | ||
const expression = { | ||
@@ -145,2 +151,3 @@ StyleExpression, | ||
FeatureState, | ||
ProjectionDefinition, | ||
Color, | ||
@@ -174,3 +181,2 @@ Step, | ||
interpolateFactory, | ||
validateStyleMin, | ||
@@ -192,3 +198,3 @@ groupByLayout, | ||
typeOf, | ||
toString, | ||
typeToString as toString, | ||
format, | ||
@@ -199,4 +205,5 @@ validate, | ||
ProjectionDefinitionType, | ||
ColorType, | ||
interpolates, | ||
interpolateFactory as interpolates, | ||
v8, | ||
@@ -203,0 +210,0 @@ NullType, |
@@ -1,5 +0,5 @@ | ||
import migrate from './migrate'; | ||
import {migrate} from './migrate'; | ||
import * as spec from '.'; | ||
import v8 from './reference/v8.json' with {type: 'json'}; | ||
import validate from './validate_style'; | ||
import {validateStyle} from './validate_style'; | ||
@@ -110,3 +110,3 @@ describe('migrate', () => { | ||
]); | ||
expect(validate(migrated, v8)).toEqual([]); | ||
expect(validateStyle(migrated, v8)).toEqual([]); | ||
}); | ||
@@ -113,0 +113,0 @@ |
import migrateToV8 from './migrate/v8'; | ||
import migrateToExpressions from './migrate/expressions'; | ||
import migrateColors from './migrate/migrate_colors'; | ||
import {migrateV8} from './migrate/v8'; | ||
import {expressions} from './migrate/expressions'; | ||
import {migrateColors} from './migrate/migrate_colors'; | ||
import {eachProperty} from './visit'; | ||
@@ -19,7 +19,7 @@ import type {StyleSpecification} from './types.g'; | ||
*/ | ||
export default function migrate(style: StyleSpecification): StyleSpecification { | ||
export function migrate(style: StyleSpecification): StyleSpecification { | ||
let migrated = false; | ||
if (style.version as any === 7) { | ||
style = migrateToV8(style); | ||
style = migrateV8(style); | ||
migrated = true; | ||
@@ -29,3 +29,3 @@ } | ||
if (style.version === 8) { | ||
migrated = !!migrateToExpressions(style); | ||
migrated = !!expressions(style); | ||
migrated = true; | ||
@@ -32,0 +32,0 @@ } |
import {eachLayer, eachProperty} from '../visit'; | ||
import {isExpression} from '../expression'; | ||
import convertFunction, {convertTokenString} from '../function/convert'; | ||
import convertFilter from '../feature_filter/convert'; | ||
import {convertFunction, convertTokenString} from '../function/convert'; | ||
import {convertFilter} from '../feature_filter/convert'; | ||
@@ -15,3 +15,3 @@ import type {FilterSpecification, LayerSpecification, StyleSpecification} from '../types.g'; | ||
*/ | ||
export default function expressions(style: StyleSpecification) { | ||
export function expressions(style: StyleSpecification) { | ||
const converted = []; | ||
@@ -18,0 +18,0 @@ |
@@ -1,2 +0,2 @@ | ||
import migrateColors from './migrate_colors'; | ||
import {migrateColors} from './migrate_colors'; | ||
@@ -3,0 +3,0 @@ describe('migrate colors', () => { |
@@ -7,3 +7,3 @@ /** | ||
*/ | ||
export default function migrateColors<T>(colorToMigrate: T): T { | ||
export function migrateColors<T>(colorToMigrate: T): T { | ||
return JSON.parse(migrateHslColors(JSON.stringify(colorToMigrate))); | ||
@@ -10,0 +10,0 @@ } |
@@ -1,2 +0,2 @@ | ||
import migrate from './v8'; | ||
import {migrateV8 as migrate} from './v8'; | ||
@@ -3,0 +3,0 @@ describe('migrate v8', () => { |
@@ -37,3 +37,3 @@ | ||
export default function migrateV8(style: StyleSpecification) { | ||
export function migrateV8(style: StyleSpecification) { | ||
style.version = 8; | ||
@@ -40,0 +40,0 @@ |
@@ -1,6 +0,6 @@ | ||
import ParsingError from './error/parsing_error'; | ||
import {ParsingError} from './error/parsing_error'; | ||
import jsonlint from '@mapbox/jsonlint-lines-primitives'; | ||
import type {StyleSpecification} from './types.g'; | ||
export default function readStyle(style: StyleSpecification | string | Buffer): StyleSpecification { | ||
export function readStyle(style: StyleSpecification | string | Buffer): StyleSpecification { | ||
if (style instanceof String || typeof style === 'string' || style instanceof Buffer) { | ||
@@ -7,0 +7,0 @@ try { |
import spec from './v8.json' with { type: 'json' }; | ||
export default spec as any; | ||
import latest from './v8.json' with { type: 'json' }; | ||
export {latest} | ||
export default latest as any |
@@ -6,2 +6,5 @@ // Generated code; do not edit. Edit build/generate-style-spec.ts instead. | ||
export type ProjectionDefinitionT = [string, string, number]; | ||
export type ProjectionDefinitionSpecification = string | ProjectionDefinitionT | PropertyValueSpecification<ProjectionDefinitionT> | ||
export type PaddingSpecification = number | number[]; | ||
@@ -87,3 +90,3 @@ | ||
| ['interpolate', InterpolationSpecification, number | ExpressionSpecification, | ||
...(number | number[] | ColorSpecification | ExpressionSpecification)[]] // alternating number and number | number[] | ColorSpecification | ||
...(number | number[] | ColorSpecification | ExpressionSpecification | ProjectionDefinitionSpecification )[]] // alternating number and number | number[] | ColorSpecification | ||
| ['interpolate-hcl', InterpolationSpecification, number | ExpressionSpecification, | ||
@@ -235,2 +238,6 @@ ...(number | ColorSpecification)[]] // alternating number and ColorSpecificaton | ||
export type ProjectionSpecification = { | ||
"type"?: PropertyValueSpecification<ProjectionDefinitionSpecification> | ||
}; | ||
export type TerrainSpecification = { | ||
@@ -241,6 +248,2 @@ "source": string, | ||
export type ProjectionSpecification = { | ||
"type"?: "mercator" | "globe" | "vertical-perspective" | ||
}; | ||
export type VectorSourceSpecification = { | ||
@@ -247,0 +250,0 @@ "type": "vector", |
@@ -10,3 +10,3 @@ // This is taken from https://github.com/mapbox/cheap-ruler/ in order to take only the relevant parts | ||
export default class CheapRuler { | ||
export class CheapRuler { | ||
private kx: number; | ||
@@ -13,0 +13,0 @@ private ky: number; |
@@ -6,3 +6,4 @@ /** | ||
*/ | ||
function deepEqual(a?: unknown | null, b?: unknown | null): boolean { | ||
export function deepEqual(a?: unknown | null, b?: unknown | null): boolean { | ||
if (Array.isArray(a)) { | ||
@@ -25,4 +26,2 @@ if (!Array.isArray(b) || a.length !== b.length) return false; | ||
return a === b; | ||
} | ||
export default deepEqual; | ||
} |
@@ -1,2 +0,2 @@ | ||
export default function extendBy(output: any, ...inputs: Array<any>) { | ||
export function extendBy(output: any, ...inputs: Array<any>) { | ||
for (const input of inputs) { | ||
@@ -3,0 +3,0 @@ for (const k in input) { |
@@ -1,2 +0,2 @@ | ||
export default function getType(val: unknown): string { | ||
export function getType(val: unknown): string { | ||
if (val instanceof Number) { | ||
@@ -3,0 +3,0 @@ return 'number'; |
const refProperties = ['type', 'source', 'source-layer', 'minzoom', 'maxzoom', 'filter', 'layout']; | ||
export default refProperties; | ||
export const refProperties = ['type', 'source', 'source-layer', 'minzoom', 'maxzoom', 'filter', 'layout']; |
import validateConstants from './validate/validate_constants'; | ||
import validate from './validate/validate'; | ||
import latestStyleSpec from './reference/latest'; | ||
import {validateConstants} from './validate/validate_constants'; | ||
import {validate} from './validate/validate'; | ||
import {latest} from './reference/latest'; | ||
import validateSource from './validate/validate_source'; | ||
import validateLight from './validate/validate_light'; | ||
import validateSky from './validate/validate_sky'; | ||
import validateTerrain from './validate/validate_terrain'; | ||
import validateLayer from './validate/validate_layer'; | ||
import validateFilter from './validate/validate_filter'; | ||
import validatePaintProperty from './validate/validate_paint_property'; | ||
import validateLayoutProperty from './validate/validate_layout_property'; | ||
import validateSprite from './validate/validate_sprite'; | ||
import validateGlyphsUrl from './validate/validate_glyphs_url'; | ||
import ValidationError from './error/validation_error'; | ||
import {validateSource} from './validate/validate_source'; | ||
import {validateLight} from './validate/validate_light'; | ||
import {validateSky} from './validate/validate_sky'; | ||
import {validateTerrain} from './validate/validate_terrain'; | ||
import {validateLayer} from './validate/validate_layer'; | ||
import {validateFilter} from './validate/validate_filter'; | ||
import {validatePaintProperty} from './validate/validate_paint_property'; | ||
import {validateLayoutProperty} from './validate/validate_layout_property'; | ||
import {validateSprite} from './validate/validate_sprite'; | ||
import {validateGlyphsUrl} from './validate/validate_glyphs_url'; | ||
import {ValidationError} from './error/validation_error'; | ||
import type {StyleSpecification} from './types.g'; | ||
@@ -31,3 +31,3 @@ | ||
*/ | ||
function validateStyleMin(style: StyleSpecification, styleSpec = latestStyleSpec): Array<ValidationError> { | ||
export function validateStyleMin(style: StyleSpecification, styleSpec = latest): Array<ValidationError> { | ||
@@ -95,3 +95,1 @@ let errors: ValidationError[] = []; | ||
} | ||
export default validateStyleMin; |
import validateStyleMin from './validate_style.min'; | ||
import {validateStyleMin} from './validate_style.min'; | ||
import {v8, ValidationError} from '.'; | ||
import readStyle from './read_style'; | ||
import {readStyle} from './read_style'; | ||
import type {StyleSpecification} from './types.g'; | ||
@@ -21,3 +21,3 @@ | ||
export default function validateStyle(style: StyleSpecification | string | Buffer, styleSpec = v8): Array<ValidationError> { | ||
export function validateStyle(style: StyleSpecification | string | Buffer, styleSpec = v8): Array<ValidationError> { | ||
let s = style; | ||
@@ -24,0 +24,0 @@ |
@@ -1,5 +0,5 @@ | ||
import getType from '../util/get_type'; | ||
import ValidationError from '../error/validation_error'; | ||
import {getType} from '../util/get_type'; | ||
import {ValidationError} from '../error/validation_error'; | ||
export default function validateArray(options) { | ||
export function validateArray(options) { | ||
const array = options.value; | ||
@@ -6,0 +6,0 @@ const arraySpec = options.valueSpec; |
import getType from '../util/get_type'; | ||
import ValidationError from '../error/validation_error'; | ||
import {getType} from '../util/get_type'; | ||
import {ValidationError} from '../error/validation_error'; | ||
export default function validateBoolean(options) { | ||
export function validateBoolean(options) { | ||
const value = options.value; | ||
@@ -7,0 +7,0 @@ const key = options.key; |
@@ -1,2 +0,2 @@ | ||
import validateColor from './validate_color'; | ||
import {validateColor} from './validate_color'; | ||
@@ -3,0 +3,0 @@ describe('validateColor function', () => { |
@@ -1,6 +0,6 @@ | ||
import ValidationError from '../error/validation_error'; | ||
import getType from '../util/get_type'; | ||
import Color from '../util/color'; | ||
import {ValidationError} from '../error/validation_error'; | ||
import {getType} from '../util/get_type'; | ||
import {Color} from '../expression/types/color'; | ||
export default function validateColor(options) { | ||
export function validateColor(options) { | ||
const key = options.key; | ||
@@ -7,0 +7,0 @@ const value = options.value; |
import ValidationError from '../error/validation_error'; | ||
import {ValidationError} from '../error/validation_error'; | ||
export default function validateConstants(options) { | ||
export function validateConstants(options) { | ||
const key = options.key; | ||
@@ -6,0 +6,0 @@ const constants = options.value; |
import ValidationError from '../error/validation_error'; | ||
import {ValidationError} from '../error/validation_error'; | ||
import {unbundle} from '../util/unbundle_jsonlint'; | ||
export default function validateEnum(options) { | ||
export function validateEnum(options) { | ||
const key = options.key; | ||
@@ -7,0 +7,0 @@ const value = options.value; |
@@ -1,2 +0,2 @@ | ||
import ValidationError from '../error/validation_error'; | ||
import {ValidationError} from '../error/validation_error'; | ||
@@ -12,3 +12,3 @@ import {createExpression, createPropertyExpression} from '../expression'; | ||
export default function validateExpression(options: any): Array<ValidationError> { | ||
export function validateExpression(options: any): Array<ValidationError> { | ||
const expression = (options.expressionContext === 'property' ? createPropertyExpression : createExpression)(deepUnbundle(options.value), options.valueSpec); | ||
@@ -15,0 +15,0 @@ if (expression.result === 'error') { |
import ValidationError from '../error/validation_error'; | ||
import validateExpression from './validate_expression'; | ||
import validateEnum from './validate_enum'; | ||
import getType from '../util/get_type'; | ||
import {ValidationError} from '../error/validation_error'; | ||
import {validateExpression} from './validate_expression'; | ||
import {validateEnum} from './validate_enum'; | ||
import {getType} from '../util/get_type'; | ||
import {unbundle, deepUnbundle} from '../util/unbundle_jsonlint'; | ||
import extend from '../util/extend'; | ||
import {extendBy as extend} from '../util/extend'; | ||
import {isExpressionFilter} from '../feature_filter'; | ||
export default function validateFilter(options) { | ||
export function validateFilter(options) { | ||
if (isExpressionFilter(deepUnbundle(options.value))) { | ||
@@ -12,0 +12,0 @@ return validateExpression(extend({}, options, { |
@@ -1,5 +0,5 @@ | ||
import validateExpression from './validate_expression'; | ||
import validateString from './validate_string'; | ||
import {validateExpression} from './validate_expression'; | ||
import {validateString} from './validate_string'; | ||
export default function validateFormatted(options: any) { | ||
export function validateFormatted(options: any) { | ||
if (validateString(options).length === 0) { | ||
@@ -6,0 +6,0 @@ return []; |
import ValidationError from '../error/validation_error'; | ||
import getType from '../util/get_type'; | ||
import validateObject from './validate_object'; | ||
import validateArray from './validate_array'; | ||
import validateNumber from './validate_number'; | ||
import {ValidationError} from '../error/validation_error'; | ||
import {getType} from '../util/get_type'; | ||
import {validateObject} from './validate_object'; | ||
import {validateArray} from './validate_array'; | ||
import {validateNumber} from './validate_number'; | ||
import {isExpression} from '../expression'; | ||
@@ -15,3 +15,3 @@ import {unbundle, deepUnbundle} from '../util/unbundle_jsonlint'; | ||
export default function validateFunction(options): Array<ValidationError> { | ||
export function validateFunction(options): Array<ValidationError> { | ||
const functionValueSpec = options.valueSpec; | ||
@@ -18,0 +18,0 @@ const functionType = unbundle(options.value.type); |
import ValidationError from '../error/validation_error'; | ||
import validateString from './validate_string'; | ||
import {ValidationError} from '../error/validation_error'; | ||
import {validateString} from './validate_string'; | ||
export default function validateGlyphsUrl(options) { | ||
export function validateGlyphsUrl(options) { | ||
const value = options.value; | ||
@@ -7,0 +7,0 @@ const key = options.key; |
@@ -1,5 +0,5 @@ | ||
import validateExpression from './validate_expression'; | ||
import validateString from './validate_string'; | ||
import {validateExpression} from './validate_expression'; | ||
import {validateString} from './validate_string'; | ||
export default function validateImage(options: any) { | ||
export function validateImage(options: any) { | ||
if (validateString(options).length === 0) { | ||
@@ -6,0 +6,0 @@ return []; |
import ValidationError from '../error/validation_error'; | ||
import {ValidationError} from '../error/validation_error'; | ||
import {unbundle} from '../util/unbundle_jsonlint'; | ||
import validateObject from './validate_object'; | ||
import validateFilter from './validate_filter'; | ||
import validatePaintProperty from './validate_paint_property'; | ||
import validateLayoutProperty from './validate_layout_property'; | ||
import extend from '../util/extend'; | ||
import {validateObject} from './validate_object'; | ||
import {validateFilter} from './validate_filter'; | ||
import {validatePaintProperty} from './validate_paint_property'; | ||
import {validateLayoutProperty} from './validate_layout_property'; | ||
import {extendBy as extend} from '../util/extend'; | ||
export default function validateLayer(options) { | ||
export function validateLayer(options) { | ||
let errors = []; | ||
@@ -12,0 +12,0 @@ |
import validateProperty from './validate_property'; | ||
import {validateProperty} from './validate_property'; | ||
export default function validateLayoutProperty(options) { | ||
export function validateLayoutProperty(options) { | ||
return validateProperty(options, 'layout'); | ||
} |
@@ -1,5 +0,5 @@ | ||
import ValidationError from '../error/validation_error'; | ||
import getType from '../util/get_type'; | ||
import {ValidationError} from '../error/validation_error'; | ||
import {getType} from '../util/get_type'; | ||
export default function validateLight(options) { | ||
export function validateLight(options) { | ||
const light = options.value; | ||
@@ -6,0 +6,0 @@ const styleSpec = options.styleSpec; |
import getType from '../util/get_type'; | ||
import ValidationError from '../error/validation_error'; | ||
import {getType} from '../util/get_type'; | ||
import {ValidationError} from '../error/validation_error'; | ||
export default function validateNumber(options) { | ||
export function validateNumber(options) { | ||
const key = options.key; | ||
@@ -7,0 +7,0 @@ const value = options.value; |
import ValidationError from '../error/validation_error'; | ||
import getType from '../util/get_type'; | ||
import {ValidationError} from '../error/validation_error'; | ||
import {getType} from '../util/get_type'; | ||
export default function validateObject(options): Array<ValidationError> { | ||
export function validateObject(options): Array<ValidationError> { | ||
const key = options.key; | ||
@@ -7,0 +7,0 @@ const object = options.value; |
@@ -1,23 +0,23 @@ | ||
import validateSpec from './validate'; | ||
import validatePadding from './validate_padding'; | ||
import {validate} from './validate'; | ||
import {validatePadding} from './validate_padding'; | ||
describe('Validate Padding', () => { | ||
test('Should return error if type is not number or array', () => { | ||
let errors = validatePadding({validateSpec, key: 'padding', value: '3'}); | ||
let errors = validatePadding({validateSpec: validate, key: 'padding', value: '3'}); | ||
expect(errors).toHaveLength(1); | ||
expect(errors[0].message).toBe('padding: number expected, string found'); | ||
errors = validatePadding({validateSpec, key: 'padding', value: true}); | ||
errors = validatePadding({validateSpec: validate, key: 'padding', value: true}); | ||
expect(errors).toHaveLength(1); | ||
expect(errors[0].message).toBe('padding: number expected, boolean found'); | ||
errors = validatePadding({validateSpec, key: 'padding', value: null}); | ||
errors = validatePadding({validateSpec: validate, key: 'padding', value: null}); | ||
expect(errors).toHaveLength(1); | ||
expect(errors[0].message).toBe('padding: number expected, null found'); | ||
errors = validatePadding({validateSpec, key: 'padding', value: {x: 1, y: 1}}); | ||
errors = validatePadding({validateSpec: validate, key: 'padding', value: {x: 1, y: 1}}); | ||
expect(errors).toHaveLength(1); | ||
expect(errors[0].message).toBe('padding: number expected, object found'); | ||
errors = validatePadding({validateSpec, key: 'padding', value: NaN}); | ||
errors = validatePadding({validateSpec: validate, key: 'padding', value: NaN}); | ||
expect(errors).toHaveLength(1); | ||
@@ -28,3 +28,3 @@ expect(errors[0].message).toBe('padding: number expected, NaN found'); | ||
test('Should pass if type is number', () => { | ||
const errors = validatePadding({validateSpec, key: 'padding', value: 1}); | ||
const errors = validatePadding({validateSpec: validate, key: 'padding', value: 1}); | ||
expect(errors).toHaveLength(0); | ||
@@ -34,11 +34,11 @@ }); | ||
test('Should return error if array length is invalid', () => { | ||
let errors = validatePadding({validateSpec, key: 'padding', value: []}); | ||
let errors = validatePadding({validateSpec: validate, key: 'padding', value: []}); | ||
expect(errors).toHaveLength(1); | ||
expect(errors[0].message).toBe('padding: padding requires 1 to 4 values; 0 values found'); | ||
errors = validatePadding({validateSpec, key: 'padding', value: [1, 1, 1, 1, 1]}); | ||
errors = validatePadding({validateSpec: validate, key: 'padding', value: [1, 1, 1, 1, 1]}); | ||
expect(errors).toHaveLength(1); | ||
expect(errors[0].message).toBe('padding: padding requires 1 to 4 values; 5 values found'); | ||
errors = validatePadding({validateSpec, key: 'padding', value: [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]}); | ||
errors = validatePadding({validateSpec: validate, key: 'padding', value: [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]}); | ||
expect(errors).toHaveLength(1); | ||
@@ -49,23 +49,23 @@ expect(errors[0].message).toBe('padding: padding requires 1 to 4 values; 12 values found'); | ||
test('Should return error if array contains non-numeric values', () => { | ||
let errors = validatePadding({validateSpec, key: 'padding', value: ['1']}); | ||
let errors = validatePadding({validateSpec: validate, key: 'padding', value: ['1']}); | ||
expect(errors).toHaveLength(1); | ||
expect(errors[0].message).toBe('padding[0]: number expected, string found'); | ||
errors = validatePadding({validateSpec, key: 'padding', value: [true]}); | ||
errors = validatePadding({validateSpec: validate, key: 'padding', value: [true]}); | ||
expect(errors).toHaveLength(1); | ||
expect(errors[0].message).toBe('padding[0]: number expected, boolean found'); | ||
errors = validatePadding({validateSpec, key: 'padding', value: [NaN]}); | ||
errors = validatePadding({validateSpec: validate, key: 'padding', value: [NaN]}); | ||
expect(errors).toHaveLength(1); | ||
expect(errors[0].message).toBe('padding[0]: number expected, NaN found'); | ||
errors = validatePadding({validateSpec, key: 'padding', value: [{x: 1}]}); | ||
errors = validatePadding({validateSpec: validate, key: 'padding', value: [{x: 1}]}); | ||
expect(errors).toHaveLength(1); | ||
expect(errors[0].message).toBe('padding[0]: number expected, object found'); | ||
errors = validatePadding({validateSpec, key: 'padding', value: [1, 3, false]}); | ||
errors = validatePadding({validateSpec: validate, key: 'padding', value: [1, 3, false]}); | ||
expect(errors).toHaveLength(1); | ||
expect(errors[0].message).toBe('padding[2]: number expected, boolean found'); | ||
errors = validatePadding({validateSpec, key: 'padding', value: ['1', 3, false]}); | ||
errors = validatePadding({validateSpec: validate, key: 'padding', value: ['1', 3, false]}); | ||
expect(errors).toHaveLength(2); | ||
@@ -77,11 +77,11 @@ expect(errors[0].message).toBe('padding[0]: number expected, string found'); | ||
test('Should pass if type is numeric array', () => { | ||
let errors = validatePadding({validateSpec, key: 'padding', value: [1]}); | ||
let errors = validatePadding({validateSpec: validate, key: 'padding', value: [1]}); | ||
expect(errors).toHaveLength(0); | ||
errors = validatePadding({validateSpec, key: 'padding', value: [1, 1]}); | ||
errors = validatePadding({validateSpec: validate, key: 'padding', value: [1, 1]}); | ||
expect(errors).toHaveLength(0); | ||
errors = validatePadding({validateSpec, key: 'padding', value: [1, 1, 1]}); | ||
errors = validatePadding({validateSpec: validate, key: 'padding', value: [1, 1, 1]}); | ||
expect(errors).toHaveLength(0); | ||
errors = validatePadding({validateSpec, key: 'padding', value: [1, 1, 1, 1]}); | ||
errors = validatePadding({validateSpec: validate, key: 'padding', value: [1, 1, 1, 1]}); | ||
expect(errors).toHaveLength(0); | ||
}); | ||
}); |
@@ -1,6 +0,6 @@ | ||
import ValidationError from '../error/validation_error'; | ||
import getType from '../util/get_type'; | ||
import validateNumber from './validate_number'; | ||
import {ValidationError} from '../error/validation_error'; | ||
import {getType} from '../util/get_type'; | ||
import {validateNumber} from './validate_number'; | ||
export default function validatePadding(options) { | ||
export function validatePadding(options) { | ||
const key = options.key; | ||
@@ -7,0 +7,0 @@ const value = options.value; |
import validateProperty from './validate_property'; | ||
import {validateProperty} from './validate_property'; | ||
export default function validatePaintProperty(options) { | ||
export function validatePaintProperty(options) { | ||
return validateProperty(options, 'paint'); | ||
} |
@@ -1,3 +0,3 @@ | ||
import validateProjection from './validate_projection'; | ||
import validateSpec from './validate'; | ||
import {validateProjection} from './validate_projection'; | ||
import {validate} from './validate'; | ||
import v8 from '../reference/v8.json' with {type: 'json'}; | ||
@@ -8,3 +8,3 @@ import {ProjectionSpecification} from '../types.g'; | ||
it('Should pass when value is undefined', () => { | ||
const errors = validateProjection({validateSpec, value: undefined, styleSpec: v8, style: {} as any}); | ||
const errors = validateProjection({validateSpec: validate, value: undefined, styleSpec: v8, style: {} as any}); | ||
expect(errors).toHaveLength(0); | ||
@@ -14,3 +14,3 @@ }); | ||
test('Should return error when value is not an object', () => { | ||
const errors = validateProjection({validateSpec, value: '' as unknown as ProjectionSpecification, styleSpec: v8, style: {} as any}); | ||
const errors = validateProjection({validateSpec: validate, value: '' as unknown as ProjectionSpecification, styleSpec: v8, style: {} as any}); | ||
expect(errors).toHaveLength(1); | ||
@@ -22,20 +22,39 @@ expect(errors[0].message).toContain('object'); | ||
test('Should return error in case of unknown property', () => { | ||
const errors = validateProjection({validateSpec, value: {a: 1} as any, styleSpec: v8, style: {} as any}); | ||
const errors = validateProjection({validateSpec: validate, value: {a: 1} as any, styleSpec: v8, style: {} as any}); | ||
expect(errors).toHaveLength(1); | ||
expect(errors[0].message).toContain('a'); | ||
expect(errors[0].message).toContain('unknown'); | ||
expect(errors[0].message).toContain('a: unknown property \"a\"'); | ||
}); | ||
test('Should return errors according to spec violations', () => { | ||
const errors = validateProjection({validateSpec, value: {type: 1 as any}, styleSpec: v8, style: {} as any}); | ||
const errors = validateProjection({validateSpec: validate, value: {type: 1 as any}, styleSpec: v8, style: {} as any}); | ||
expect(errors).toHaveLength(1); | ||
expect(errors[0].message).toBe('type: expected one of [mercator, globe, vertical-perspective], 1 found'); | ||
expect(errors[0].message).toBe('type: projection expected, invalid type \"number\" found'); | ||
}); | ||
test('Should pass if everything is according to spec', () => { | ||
let errors = validateProjection({validateSpec, value: {type: 'globe'}, styleSpec: v8, style: {} as any}); | ||
test('Should return error when value is null', () => { | ||
const errors = validateProjection({validateSpec: validate, value: null as any, styleSpec: v8, style: {} as any}); | ||
expect(errors).toHaveLength(1); | ||
expect(errors[0].message).toContain('projection: object expected, null found'); | ||
}); | ||
test('Should pass step function', () => { | ||
const errors = validateProjection({validateSpec: validate, value: {'type': ['step', ['zoom'], 'vertical-perspective', 10, 'mercator']}, styleSpec: v8, style: {} as any}); | ||
expect(errors).toHaveLength(0); | ||
errors = validateProjection({validateSpec, value: {type: 'mercator'}, styleSpec: v8, style: {} as any}); | ||
}); | ||
test('Should pass string value', () => { | ||
const errors = validateProjection({validateSpec: validate, value: {'type': 'mercator'}, styleSpec: v8, style: {} as any}); | ||
expect(errors).toHaveLength(0); | ||
}); | ||
test('Should pass if [proj, proj, number]', () => { | ||
const errors = validateProjection({validateSpec: validate, value: {'type': ['mercator', 'mercator', 0.3]}, styleSpec: v8, style: {} as any}); | ||
expect(errors).toHaveLength(0); | ||
}); | ||
test('should parse interpolate', () => { | ||
const errors = validateProjection({validateSpec: validate, value: {'type': ['interpolate', ['linear'], ['zoom'], 0, 'mercator', 5, 'vertical-perspective']}, styleSpec: v8, style: {} as any}); | ||
expect(errors).toHaveLength(0); | ||
}); | ||
}); |
@@ -1,3 +0,3 @@ | ||
import ValidationError from '../error/validation_error'; | ||
import getType from '../util/get_type'; | ||
import {ValidationError} from '../error/validation_error'; | ||
import {getType} from '../util/get_type'; | ||
import v8 from '../reference/v8.json' with {type: 'json'}; | ||
@@ -14,3 +14,3 @@ import {ProjectionSpecification, StyleSpecification} from '../types.g'; | ||
export default function validateProjection(options: ValidateProjectionOptions) { | ||
export function validateProjection(options: ValidateProjectionOptions) { | ||
const projection = options.value; | ||
@@ -17,0 +17,0 @@ const styleSpec = options.styleSpec; |
import ValidationError from '../error/validation_error'; | ||
import getType from '../util/get_type'; | ||
import {ValidationError} from '../error/validation_error'; | ||
import {getType} from '../util/get_type'; | ||
import {isFunction} from '../function'; | ||
@@ -8,3 +8,3 @@ import {unbundle, deepUnbundle} from '../util/unbundle_jsonlint'; | ||
export default function validateProperty(options, propertyType) { | ||
export function validateProperty(options, propertyType) { | ||
const key = options.key; | ||
@@ -11,0 +11,0 @@ const validateSpec = options.validateSpec; |
@@ -1,4 +0,4 @@ | ||
import validateSpec from './validate'; | ||
import {validate} from './validate'; | ||
import v8 from '../reference/v8.json' with {type: 'json'}; | ||
import validateRasterDEMSource from './validate_raster_dem_source'; | ||
import {validateRasterDEMSource} from './validate_raster_dem_source'; | ||
import {RasterDEMSourceSpecification} from '../types.g'; | ||
@@ -14,3 +14,3 @@ | ||
test('Should pass when value is undefined', () => { | ||
const errors = validateRasterDEMSource({validateSpec, value: undefined, styleSpec: v8, style: {} as any}); | ||
const errors = validateRasterDEMSource({validateSpec: validate, value: undefined, styleSpec: v8, style: {} as any}); | ||
expect(errors).toHaveLength(0); | ||
@@ -20,3 +20,3 @@ }); | ||
test('Should return error when value is not an object', () => { | ||
const errors = validateRasterDEMSource({validateSpec, value: '' as unknown as RasterDEMSourceSpecification, styleSpec: v8, style: {} as any}); | ||
const errors = validateRasterDEMSource({validateSpec: validate, value: '' as unknown as RasterDEMSourceSpecification, styleSpec: v8, style: {} as any}); | ||
expect(errors).toHaveLength(1); | ||
@@ -28,3 +28,3 @@ expect(errors[0].message).toContain('object'); | ||
test('Should return error in case of unknown property', () => { | ||
const errors = validateRasterDEMSource({validateSpec, value: {a: 1} as any, styleSpec: v8, style: {} as any}); | ||
const errors = validateRasterDEMSource({validateSpec: validate, value: {a: 1} as any, styleSpec: v8, style: {} as any}); | ||
expect(errors).toHaveLength(1); | ||
@@ -36,3 +36,3 @@ expect(errors[0].message).toContain('a'); | ||
test('Should return errors according to spec violations', () => { | ||
const errors = validateRasterDEMSource({validateSpec, value: {type: 'raster-dem', url: {} as any, tiles: {} as any, encoding: 'foo' as any}, styleSpec: v8, style: {} as any}); | ||
const errors = validateRasterDEMSource({validateSpec: validate, value: {type: 'raster-dem', url: {} as any, tiles: {} as any, encoding: 'foo' as any}, styleSpec: v8, style: {} as any}); | ||
expect(errors).toHaveLength(3); | ||
@@ -45,3 +45,3 @@ checkErrorMessage(errors[0].message, 'url', 'string', 'object'); | ||
test('Should return errors when custom encoding values are set but encoding is "mapbox"', () => { | ||
const errors = validateRasterDEMSource({validateSpec, value: {type: 'raster-dem', encoding: 'mapbox', 'redFactor': 1.0, 'greenFactor': 1.0, 'blueFactor': 1.0, 'baseShift': 1.0}, styleSpec: v8, style: {} as any}); | ||
const errors = validateRasterDEMSource({validateSpec: validate, value: {type: 'raster-dem', encoding: 'mapbox', 'redFactor': 1.0, 'greenFactor': 1.0, 'blueFactor': 1.0, 'baseShift': 1.0}, styleSpec: v8, style: {} as any}); | ||
expect(errors).toHaveLength(4); | ||
@@ -55,3 +55,3 @@ checkErrorMessage(errors[0].message, 'redFactor', 'custom', 'mapbox'); | ||
test('Should return errors when custom encoding values are set but encoding is "terrarium"', () => { | ||
const errors = validateRasterDEMSource({validateSpec, value: {type: 'raster-dem', encoding: 'terrarium', 'redFactor': 1.0, 'greenFactor': 1.0, 'blueFactor': 1.0, 'baseShift': 1.0}, styleSpec: v8, style: {} as any}); | ||
const errors = validateRasterDEMSource({validateSpec: validate, value: {type: 'raster-dem', encoding: 'terrarium', 'redFactor': 1.0, 'greenFactor': 1.0, 'blueFactor': 1.0, 'baseShift': 1.0}, styleSpec: v8, style: {} as any}); | ||
expect(errors).toHaveLength(4); | ||
@@ -65,3 +65,3 @@ checkErrorMessage(errors[0].message, 'redFactor', 'custom', 'terrarium'); | ||
test('Should pass when custom encoding values are set and encoding is "custom"', () => { | ||
const errors = validateRasterDEMSource({validateSpec, value: {type: 'raster-dem', encoding: 'custom', 'redFactor': 1.0, 'greenFactor': 1.0, 'blueFactor': 1.0, 'baseShift': 1.0}, styleSpec: v8, style: {} as any}); | ||
const errors = validateRasterDEMSource({validateSpec: validate, value: {type: 'raster-dem', encoding: 'custom', 'redFactor': 1.0, 'greenFactor': 1.0, 'blueFactor': 1.0, 'baseShift': 1.0}, styleSpec: v8, style: {} as any}); | ||
expect(errors).toHaveLength(0); | ||
@@ -71,5 +71,5 @@ }); | ||
test('Should pass if everything is according to spec', () => { | ||
const errors = validateRasterDEMSource({validateSpec, value: {type: 'raster-dem'}, styleSpec: v8, style: {} as any}); | ||
const errors = validateRasterDEMSource({validateSpec: validate, value: {type: 'raster-dem'}, styleSpec: v8, style: {} as any}); | ||
expect(errors).toHaveLength(0); | ||
}); | ||
}); |
@@ -1,3 +0,3 @@ | ||
import ValidationError from '../error/validation_error'; | ||
import getType from '../util/get_type'; | ||
import {ValidationError} from '../error/validation_error'; | ||
import {getType} from '../util/get_type'; | ||
import type {RasterDEMSourceSpecification, StyleSpecification} from '../types.g'; | ||
@@ -15,3 +15,3 @@ import v8 from '../reference/v8.json' with {type: 'json'}; | ||
export default function validateRasterDEMSource( | ||
export function validateRasterDEMSource( | ||
options: ValidateRasterDENSourceOptions | ||
@@ -18,0 +18,0 @@ ): ValidationError[] { |
@@ -1,3 +0,3 @@ | ||
import validateSky from './validate_sky'; | ||
import validateSpec from './validate'; | ||
import {validateSky} from './validate_sky'; | ||
import {validate} from './validate'; | ||
import v8 from '../reference/v8.json' with {type: 'json'}; | ||
@@ -8,3 +8,3 @@ import {SkySpecification} from '../types.g'; | ||
it('Should pass when value is undefined', () => { | ||
const errors = validateSky({validateSpec, value: undefined, styleSpec: v8, style: {} as any}); | ||
const errors = validateSky({validateSpec: validate, value: undefined, styleSpec: v8, style: {} as any}); | ||
expect(errors).toHaveLength(0); | ||
@@ -14,3 +14,3 @@ }); | ||
test('Should return error when value is not an object', () => { | ||
const errors = validateSky({validateSpec, value: '' as unknown as SkySpecification, styleSpec: v8, style: {} as any}); | ||
const errors = validateSky({validateSpec: validate, value: '' as unknown as SkySpecification, styleSpec: v8, style: {} as any}); | ||
expect(errors).toHaveLength(1); | ||
@@ -22,3 +22,3 @@ expect(errors[0].message).toContain('object'); | ||
test('Should return error in case of unknown property', () => { | ||
const errors = validateSky({validateSpec, value: {a: 1} as any, styleSpec: v8, style: {} as any}); | ||
const errors = validateSky({validateSpec: validate, value: {a: 1} as any, styleSpec: v8, style: {} as any}); | ||
expect(errors).toHaveLength(1); | ||
@@ -30,3 +30,3 @@ expect(errors[0].message).toContain('a'); | ||
test('Should return errors according to spec violations', () => { | ||
const errors = validateSky({validateSpec, value: {'sky-color': 1 as any, 'fog-color': 2 as any, 'horizon-fog-blend': {} as any, 'fog-ground-blend': 'foo' as any}, styleSpec: v8, style: {} as any}); | ||
const errors = validateSky({validateSpec: validate, value: {'sky-color': 1 as any, 'fog-color': 2 as any, 'horizon-fog-blend': {} as any, 'fog-ground-blend': 'foo' as any}, styleSpec: v8, style: {} as any}); | ||
expect(errors).toHaveLength(4); | ||
@@ -40,3 +40,3 @@ expect(errors[0].message).toBe('sky-color: color expected, number found'); | ||
test('Should pass if everything is according to spec', () => { | ||
const errors = validateSky({validateSpec, value: {'sky-color': 'red', 'fog-color': '#123456', 'horizon-fog-blend': 1, 'fog-ground-blend': 0}, styleSpec: v8, style: {} as any}); | ||
const errors = validateSky({validateSpec: validate, value: {'sky-color': 'red', 'fog-color': '#123456', 'horizon-fog-blend': 1, 'fog-ground-blend': 0}, styleSpec: v8, style: {} as any}); | ||
expect(errors).toHaveLength(0); | ||
@@ -43,0 +43,0 @@ }); |
@@ -1,3 +0,3 @@ | ||
import ValidationError from '../error/validation_error'; | ||
import getType from '../util/get_type'; | ||
import {ValidationError} from '../error/validation_error'; | ||
import {getType} from '../util/get_type'; | ||
import v8 from '../reference/v8.json' with {type: 'json'}; | ||
@@ -14,3 +14,3 @@ import {SkySpecification, StyleSpecification} from '../types.g'; | ||
export default function validateSky(options: ValidateSkyOptions) { | ||
export function validateSky(options: ValidateSkyOptions) { | ||
const sky = options.value; | ||
@@ -17,0 +17,0 @@ const styleSpec = options.styleSpec; |
import ValidationError from '../error/validation_error'; | ||
import {ValidationError} from '../error/validation_error'; | ||
import {unbundle} from '../util/unbundle_jsonlint'; | ||
import validateObject from './validate_object'; | ||
import validateEnum from './validate_enum'; | ||
import validateExpression from './validate_expression'; | ||
import validateString from './validate_string'; | ||
import getType from '../util/get_type'; | ||
import validateRasterDEMSource from './validate_raster_dem_source'; | ||
import {validateObject} from './validate_object'; | ||
import {validateEnum} from './validate_enum'; | ||
import {validateExpression} from './validate_expression'; | ||
import {validateString} from './validate_string'; | ||
import {getType} from '../util/get_type'; | ||
import {validateRasterDEMSource} from './validate_raster_dem_source'; | ||
@@ -15,3 +15,3 @@ const objectElementValidators = { | ||
export default function validateSource(options) { | ||
export function validateSource(options) { | ||
const value = options.value; | ||
@@ -18,0 +18,0 @@ const key = options.key; |
@@ -1,19 +0,19 @@ | ||
import validateSprite from './validate_sprite'; | ||
import validateSpec from './validate'; | ||
import {validateSprite} from './validate_sprite'; | ||
import {validate} from './validate'; | ||
describe('Validate Sprite', () => { | ||
test('Should return error if type is not string or array', () => { | ||
let errors = validateSprite({validateSpec, key: 'sprite', value: 3}); | ||
let errors = validateSprite({validateSpec: validate, key: 'sprite', value: 3}); | ||
expect(errors).toHaveLength(1); | ||
expect(errors[0].message).toBe('sprite: string expected, number found'); | ||
errors = validateSprite({validateSpec, key: 'sprite', value: true}); | ||
errors = validateSprite({validateSpec: validate, key: 'sprite', value: true}); | ||
expect(errors).toHaveLength(1); | ||
expect(errors[0].message).toBe('sprite: string expected, boolean found'); | ||
errors = validateSprite({validateSpec, key: 'sprite', value: null}); | ||
errors = validateSprite({validateSpec: validate, key: 'sprite', value: null}); | ||
expect(errors).toHaveLength(1); | ||
expect(errors[0].message).toBe('sprite: string expected, null found'); | ||
errors = validateSprite({validateSpec, key: 'sprite', value: {x: 1, y: 1}}); | ||
errors = validateSprite({validateSpec: validate, key: 'sprite', value: {x: 1, y: 1}}); | ||
expect(errors).toHaveLength(1); | ||
@@ -24,3 +24,3 @@ expect(errors[0].message).toBe('sprite: string expected, object found'); | ||
test('Should pass if type is string', () => { | ||
const errors = validateSprite({validateSpec, key: 'sprite', value: 'url'}); | ||
const errors = validateSprite({validateSpec: validate, key: 'sprite', value: 'url'}); | ||
expect(errors).toHaveLength(0); | ||
@@ -30,19 +30,19 @@ }); | ||
test('Should return error if array contains non-object values', () => { | ||
let errors = validateSprite({validateSpec, key: 'sprite', value: ['1']}); | ||
let errors = validateSprite({validateSpec: validate, key: 'sprite', value: ['1']}); | ||
expect(errors).toHaveLength(1); | ||
expect(errors[0].message).toBe('sprite[0]: object expected, string found'); | ||
errors = validateSprite({validateSpec, key: 'sprite', value: [true]}); | ||
errors = validateSprite({validateSpec: validate, key: 'sprite', value: [true]}); | ||
expect(errors).toHaveLength(1); | ||
expect(errors[0].message).toBe('sprite[0]: object expected, boolean found'); | ||
errors = validateSprite({validateSpec, key: 'sprite', value: [3]}); | ||
errors = validateSprite({validateSpec: validate, key: 'sprite', value: [3]}); | ||
expect(errors).toHaveLength(1); | ||
expect(errors[0].message).toBe('sprite[0]: object expected, number found'); | ||
errors = validateSprite({validateSpec, key: 'sprite', value: [{id: 'id1', url: 'url1'}, {id: 'id2', url: 'url2'}, false]}); | ||
errors = validateSprite({validateSpec: validate, key: 'sprite', value: [{id: 'id1', url: 'url1'}, {id: 'id2', url: 'url2'}, false]}); | ||
expect(errors).toHaveLength(1); | ||
expect(errors[0].message).toBe('sprite[2]: object expected, boolean found'); | ||
errors = validateSprite({validateSpec, key: 'sprite', value: ['string', {id: 'id1', url: 'url1'}, {id: 'id2', url: 'url2'}, false]}); | ||
errors = validateSprite({validateSpec: validate, key: 'sprite', value: ['string', {id: 'id1', url: 'url1'}, {id: 'id2', url: 'url2'}, false]}); | ||
expect(errors).toHaveLength(2); | ||
@@ -54,3 +54,3 @@ expect(errors[0].message).toBe('sprite[0]: object expected, string found'); | ||
test('Should return error if array\'s objects are not of form {id: string, url: string}', () => { | ||
let errors = validateSprite({validateSpec, key: 'sprite', value: [{id: 2, url: 2}]}); | ||
let errors = validateSprite({validateSpec: validate, key: 'sprite', value: [{id: 2, url: 2}]}); | ||
expect(errors).toHaveLength(2); | ||
@@ -60,3 +60,3 @@ expect(errors[0].message).toBe('sprite[0].id: string expected, number found'); | ||
errors = validateSprite({validateSpec, key: 'sprite', value: [{test: 'string'}]}); | ||
errors = validateSprite({validateSpec: validate, key: 'sprite', value: [{test: 'string'}]}); | ||
expect(errors).toHaveLength(3); | ||
@@ -69,3 +69,3 @@ expect(errors[0].message).toBe('sprite[0]: unknown property "test"'); | ||
test('Should return error if array\'s objects contain duplicated IDs or URLs', () => { | ||
const errors = validateSprite({validateSpec, key: 'sprite', value: [{id: 'id1', url: 'url1'}, {id: 'id1', url: 'url1'}]}); | ||
const errors = validateSprite({validateSpec: validate, key: 'sprite', value: [{id: 'id1', url: 'url1'}, {id: 'id1', url: 'url1'}]}); | ||
expect(errors).toHaveLength(2); | ||
@@ -77,5 +77,5 @@ expect(errors[0].message).toBe('sprite: all the sprites\' ids must be unique, but id1 is duplicated'); | ||
test('Should pass if correct array of objects', () => { | ||
const errors = validateSprite({validateSpec, key: 'sprite', value: [{id: 'id1', url: 'url1'}, {id: 'id2', url: 'url2'}, {id: 'id3', url: 'url3'}]}); | ||
const errors = validateSprite({validateSpec: validate, key: 'sprite', value: [{id: 'id1', url: 'url1'}, {id: 'id2', url: 'url2'}, {id: 'id3', url: 'url3'}]}); | ||
expect(errors).toHaveLength(0); | ||
}); | ||
}); |
@@ -1,4 +0,4 @@ | ||
import validateObject from './validate_object'; | ||
import validateString from './validate_string'; | ||
import ValidationError from '../error/validation_error'; | ||
import {validateObject} from './validate_object'; | ||
import {validateString} from './validate_string'; | ||
import {ValidationError} from '../error/validation_error'; | ||
@@ -11,3 +11,3 @@ interface ValidateSpriteOptions { | ||
export default function validateSprite(options: ValidateSpriteOptions) { | ||
export function validateSprite(options: ValidateSpriteOptions) { | ||
let errors = []; | ||
@@ -14,0 +14,0 @@ |
import getType from '../util/get_type'; | ||
import ValidationError from '../error/validation_error'; | ||
import {getType} from '../util/get_type'; | ||
import {ValidationError} from '../error/validation_error'; | ||
export default function validateString(options) { | ||
export function validateString(options) { | ||
const value = options.value; | ||
@@ -7,0 +7,0 @@ const key = options.key; |
@@ -1,3 +0,3 @@ | ||
import validateSpec from './validate'; | ||
import validateTerrain from './validate_terrain'; | ||
import {validate} from './validate'; | ||
import {validateTerrain} from './validate_terrain'; | ||
import v8 from '../reference/v8.json' with {type: 'json'}; | ||
@@ -7,3 +7,3 @@ | ||
test('Should return error in case terrain is not an object', () => { | ||
const errors = validateTerrain({validateSpec, value: 1 as any, styleSpec: v8, style: {} as any}); | ||
const errors = validateTerrain({validateSpec: validate, value: 1 as any, styleSpec: v8, style: {} as any}); | ||
expect(errors).toHaveLength(1); | ||
@@ -16,3 +16,3 @@ expect(errors[0].message).toContain('number'); | ||
test('Should return error in case terrain source is not a string', () => { | ||
const errors = validateTerrain({validateSpec, value: {source: 1 as any}, styleSpec: v8, style: {} as any}); | ||
const errors = validateTerrain({validateSpec: validate, value: {source: 1 as any}, styleSpec: v8, style: {} as any}); | ||
expect(errors).toHaveLength(1); | ||
@@ -25,3 +25,3 @@ expect(errors[0].message).toContain('number'); | ||
test('Should return error in case of unknown property', () => { | ||
const errors = validateTerrain({validateSpec, value: {a: 1} as any, styleSpec: v8, style: {} as any}); | ||
const errors = validateTerrain({validateSpec: validate, value: {a: 1} as any, styleSpec: v8, style: {} as any}); | ||
expect(errors).toHaveLength(1); | ||
@@ -33,3 +33,3 @@ expect(errors[0].message).toContain('a'); | ||
test('Should return errors according to spec violations', () => { | ||
const errors = validateTerrain({validateSpec, value: {source: 1 as any, exaggeration: {} as any}, styleSpec: v8, style: {} as any}); | ||
const errors = validateTerrain({validateSpec: validate, value: {source: 1 as any, exaggeration: {} as any}, styleSpec: v8, style: {} as any}); | ||
expect(errors).toHaveLength(2); | ||
@@ -45,5 +45,5 @@ expect(errors[0].message).toContain('number'); | ||
test('Should pass if everything is according to spec', () => { | ||
const errors = validateTerrain({validateSpec, value: {source: 'source-id', exaggeration: 0.2}, styleSpec: v8, style: {} as any}); | ||
const errors = validateTerrain({validateSpec: validate, value: {source: 'source-id', exaggeration: 0.2}, styleSpec: v8, style: {} as any}); | ||
expect(errors).toHaveLength(0); | ||
}); | ||
}); |
@@ -1,7 +0,7 @@ | ||
import ValidationError from '../error/validation_error'; | ||
import getType from '../util/get_type'; | ||
import {ValidationError} from '../error/validation_error'; | ||
import {getType} from '../util/get_type'; | ||
import type {StyleSpecification, TerrainSpecification} from '../types.g'; | ||
import v8 from '../reference/v8.json' with {type: 'json'}; | ||
export default function validateTerrain( | ||
export function validateTerrain( | ||
options: {value: TerrainSpecification; styleSpec: typeof v8; style: StyleSpecification; validateSpec: Function} | ||
@@ -8,0 +8,0 @@ ): ValidationError[] { |
@@ -1,4 +0,4 @@ | ||
import validate from './validate'; | ||
import validateVariableAnchorOffsetCollection from './validate_variable_anchor_offset_collection'; | ||
import latestStyleSpec from '../reference/latest'; | ||
import {validate} from './validate'; | ||
import {validateVariableAnchorOffsetCollection} from './validate_variable_anchor_offset_collection'; | ||
import {latest} from '../reference/latest'; | ||
@@ -8,3 +8,3 @@ describe('Validate variableAnchorOffsetCollection', () => { | ||
validateSpec: validate, | ||
styleSpec: latestStyleSpec, | ||
styleSpec: latest, | ||
key: 'myProp', | ||
@@ -11,0 +11,0 @@ }; |
@@ -1,7 +0,7 @@ | ||
import ValidationError from '../error/validation_error'; | ||
import getType from '../util/get_type'; | ||
import validateArray from './validate_array'; | ||
import validateEnum from './validate_enum'; | ||
import {ValidationError} from '../error/validation_error'; | ||
import {getType} from '../util/get_type'; | ||
import {validateArray} from './validate_array'; | ||
import {validateEnum} from './validate_enum'; | ||
export default function validateVariableAnchorOffsetCollection(options): ValidationError[] { | ||
export function validateVariableAnchorOffsetCollection(options): ValidationError[] { | ||
const key = options.key; | ||
@@ -8,0 +8,0 @@ const value = options.value; |
import extend from '../util/extend'; | ||
import {extendBy} from '../util/extend'; | ||
import {unbundle, deepUnbundle} from '../util/unbundle_jsonlint'; | ||
@@ -7,25 +7,26 @@ import {isExpression} from '../expression'; | ||
import validateFunction from './validate_function'; | ||
import validateExpression from './validate_expression'; | ||
import validateObject from './validate_object'; | ||
import validateArray from './validate_array'; | ||
import validateBoolean from './validate_boolean'; | ||
import validateNumber from './validate_number'; | ||
import validateColor from './validate_color'; | ||
import validateConstants from './validate_constants'; | ||
import validateEnum from './validate_enum'; | ||
import validateFilter from './validate_filter'; | ||
import validateLayer from './validate_layer'; | ||
import validateSource from './validate_source'; | ||
import validateLight from './validate_light'; | ||
import validateSky from './validate_sky'; | ||
import validateTerrain from './validate_terrain'; | ||
import validateString from './validate_string'; | ||
import validateFormatted from './validate_formatted'; | ||
import validateImage from './validate_image'; | ||
import validatePadding from './validate_padding'; | ||
import validateVariableAnchorOffsetCollection from './validate_variable_anchor_offset_collection'; | ||
import validateSprite from './validate_sprite'; | ||
import ValidationError from '../error/validation_error'; | ||
import validateProjection from './validate_projection'; | ||
import {validateFunction} from './validate_function'; | ||
import {validateExpression} from './validate_expression'; | ||
import {validateObject} from './validate_object'; | ||
import {validateArray} from './validate_array'; | ||
import {validateBoolean} from './validate_boolean'; | ||
import {validateNumber} from './validate_number'; | ||
import {validateColor} from './validate_color'; | ||
import {validateConstants} from './validate_constants'; | ||
import {validateEnum} from './validate_enum'; | ||
import {validateFilter} from './validate_filter'; | ||
import {validateLayer} from './validate_layer'; | ||
import {validateSource} from './validate_source'; | ||
import {validateLight} from './validate_light'; | ||
import {validateSky} from './validate_sky'; | ||
import {validateTerrain} from './validate_terrain'; | ||
import {validateString} from './validate_string'; | ||
import {validateFormatted} from './validate_formatted'; | ||
import {validateImage} from './validate_image'; | ||
import {validatePadding} from './validate_padding'; | ||
import {validateVariableAnchorOffsetCollection} from './validate_variable_anchor_offset_collection'; | ||
import {validateSprite} from './validate_sprite'; | ||
import {ValidationError} from '../error/validation_error'; | ||
import {validateProjection} from './validate_projection'; | ||
import {validateProjectionDefinition} from './validate_projectiondefinition'; | ||
@@ -51,2 +52,3 @@ const VALIDATORS = { | ||
'projection': validateProjection, | ||
'projectionDefinition': validateProjectionDefinition, | ||
'string': validateString, | ||
@@ -76,3 +78,3 @@ 'formatted': validateFormatted, | ||
*/ | ||
export default function validate(options: { | ||
export function validate(options: { | ||
key: any; | ||
@@ -100,3 +102,3 @@ value: any; | ||
} else { | ||
const valid = validateObject(extend({}, options, { | ||
const valid = validateObject(extendBy({}, options, { | ||
valueSpec: valueSpec.type ? styleSpec[valueSpec.type] : valueSpec | ||
@@ -103,0 +105,0 @@ })); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
9231455
165
103884