UNPKG

mapeo-schema

Version:

JSON schema and flow types for Mapeo

612 lines 25.8 kB
'use strict'; var equal = require('ajv/lib/compile/equal'); var validate = (function() { var refVal = []; return function validate(data, dataPath, parentData, parentDataProperty, rootData) { 'use strict'; /*# sourceURL=http://mapeo.world/schemas/preset.json */ var vErrors = null; var errors = 0; if ((data && typeof data === "object" && !Array.isArray(data))) { if (true) { var errs__0 = errors; var valid1 = true; for (var key0 in data) { var isAdditional0 = !(false || validate.schema.properties.hasOwnProperty(key0)); if (isAdditional0) { valid1 = false; validate.errors = [{ keyword: 'additionalProperties', dataPath: (dataPath || '') + "", schemaPath: '#/additionalProperties', params: { additionalProperty: '' + key0 + '' }, message: 'should NOT have additional properties' }]; return false; break; } } if (valid1) { var data1 = data.schemaVersion; if (data1 === undefined) { valid1 = true; } else { var errs_1 = errors; if (typeof data1 === "number") { if (data1 < 1 || data1 !== data1) { validate.errors = [{ keyword: 'minimum', dataPath: (dataPath || '') + '.schemaVersion', schemaPath: '#/properties/schemaVersion/minimum', params: { comparison: '>=', limit: 1, exclusive: false }, message: 'should be >= 1' }]; return false; } } else { validate.errors = [{ keyword: 'type', dataPath: (dataPath || '') + '.schemaVersion', schemaPath: '#/properties/schemaVersion/type', params: { type: 'number' }, message: 'should be number' }]; return false; } if (errors === errs_1) { var schema1 = validate.schema.properties.schemaVersion.enum; var valid1; valid1 = false; for (var i1 = 0; i1 < schema1.length; i1++) if (equal(data1, schema1[i1])) { valid1 = true; break; } if (!valid1) { validate.errors = [{ keyword: 'enum', dataPath: (dataPath || '') + '.schemaVersion', schemaPath: '#/properties/schemaVersion/enum', params: { allowedValues: schema1 }, message: 'should be equal to one of the allowed values' }]; return false; } } var valid1 = errors === errs_1; } if (valid1) { if (data.id === undefined) { valid1 = false; validate.errors = [{ keyword: 'required', dataPath: (dataPath || '') + "", schemaPath: '#/required', params: { missingProperty: 'id' }, message: 'should have required property \'id\'' }]; return false; } else { var errs_1 = errors; if (typeof data.id !== "string") { validate.errors = [{ keyword: 'type', dataPath: (dataPath || '') + '.id', schemaPath: '#/properties/id/type', params: { type: 'string' }, message: 'should be string' }]; return false; } var valid1 = errors === errs_1; } if (valid1) { if (data.name === undefined) { valid1 = false; validate.errors = [{ keyword: 'required', dataPath: (dataPath || '') + "", schemaPath: '#/required', params: { missingProperty: 'name' }, message: 'should have required property \'name\'' }]; return false; } else { var errs_1 = errors; if (typeof data.name !== "string") { validate.errors = [{ keyword: 'type', dataPath: (dataPath || '') + '.name', schemaPath: '#/properties/name/type', params: { type: 'string' }, message: 'should be string' }]; return false; } var valid1 = errors === errs_1; } if (valid1) { var data1 = data.geometry; if (data1 === undefined) { valid1 = false; validate.errors = [{ keyword: 'required', dataPath: (dataPath || '') + "", schemaPath: '#/required', params: { missingProperty: 'geometry' }, message: 'should have required property \'geometry\'' }]; return false; } else { var errs_1 = errors; if (Array.isArray(data1)) { if (data1.length < 1) { validate.errors = [{ keyword: 'minItems', dataPath: (dataPath || '') + '.geometry', schemaPath: '#/properties/geometry/minItems', params: { limit: 1 }, message: 'should NOT have fewer than 1 items' }]; return false; } else { var errs__1 = errors; var valid1; for (var i1 = 0; i1 < data1.length; i1++) { var data2 = data1[i1]; var errs_2 = errors; if (typeof data2 !== "string") { validate.errors = [{ keyword: 'type', dataPath: (dataPath || '') + '.geometry[' + i1 + ']', schemaPath: '#/properties/geometry/items/type', params: { type: 'string' }, message: 'should be string' }]; return false; } var schema2 = validate.schema.properties.geometry.items.enum; var valid2; valid2 = false; for (var i2 = 0; i2 < schema2.length; i2++) if (equal(data2, schema2[i2])) { valid2 = true; break; } if (!valid2) { validate.errors = [{ keyword: 'enum', dataPath: (dataPath || '') + '.geometry[' + i1 + ']', schemaPath: '#/properties/geometry/items/enum', params: { allowedValues: schema2 }, message: 'should be equal to one of the allowed values' }]; return false; } var valid2 = errors === errs_2; if (!valid2) break; } if (errs__1 == errors) { var i = data1.length, valid1 = true, j; if (i > 1) { var itemIndices = {}, item; for (; i--;) { var item = data1[i]; if (typeof item !== "string") continue; if (typeof itemIndices[item] == 'number') { valid1 = false; j = itemIndices[item]; break; } itemIndices[item] = i; } } if (!valid1) { validate.errors = [{ keyword: 'uniqueItems', dataPath: (dataPath || '') + '.geometry', schemaPath: '#/properties/geometry/uniqueItems', params: { i: i, j: j }, message: 'should NOT have duplicate items (items ## ' + j + ' and ' + i + ' are identical)' }]; return false; } } } } else { validate.errors = [{ keyword: 'type', dataPath: (dataPath || '') + '.geometry', schemaPath: '#/properties/geometry/type', params: { type: 'array' }, message: 'should be array' }]; return false; } var valid1 = errors === errs_1; } if (valid1) { var data1 = data.tags; if (data1 === undefined) { valid1 = false; validate.errors = [{ keyword: 'required', dataPath: (dataPath || '') + "", schemaPath: '#/required', params: { missingProperty: 'tags' }, message: 'should have required property \'tags\'' }]; return false; } else { var errs_1 = errors; if ((data1 && typeof data1 === "object" && !Array.isArray(data1))) { var errs__1 = errors; var valid2 = true; } else { validate.errors = [{ keyword: 'type', dataPath: (dataPath || '') + '.tags', schemaPath: '#/properties/tags/type', params: { type: 'object' }, message: 'should be object' }]; return false; } var valid1 = errors === errs_1; } if (valid1) { var data1 = data.addTags; if (data1 === undefined) { valid1 = true; } else { var errs_1 = errors; if ((data1 && typeof data1 === "object" && !Array.isArray(data1))) { var errs__1 = errors; var valid2 = true; } else { validate.errors = [{ keyword: 'type', dataPath: (dataPath || '') + '.addTags', schemaPath: '#/properties/addTags/type', params: { type: 'object' }, message: 'should be object' }]; return false; } var valid1 = errors === errs_1; } if (valid1) { var data1 = data.removeTags; if (data1 === undefined) { valid1 = true; } else { var errs_1 = errors; if ((data1 && typeof data1 === "object" && !Array.isArray(data1))) { var errs__1 = errors; var valid2 = true; } else { validate.errors = [{ keyword: 'type', dataPath: (dataPath || '') + '.removeTags', schemaPath: '#/properties/removeTags/type', params: { type: 'object' }, message: 'should be object' }]; return false; } var valid1 = errors === errs_1; } if (valid1) { var data1 = data.fields; if (data1 === undefined) { valid1 = true; } else { var errs_1 = errors; if (Array.isArray(data1)) { var errs__1 = errors; var valid1; for (var i1 = 0; i1 < data1.length; i1++) { var errs_2 = errors; if (typeof data1[i1] !== "string") { validate.errors = [{ keyword: 'type', dataPath: (dataPath || '') + '.fields[' + i1 + ']', schemaPath: '#/properties/fields/items/type', params: { type: 'string' }, message: 'should be string' }]; return false; } var valid2 = errors === errs_2; if (!valid2) break; } } else { validate.errors = [{ keyword: 'type', dataPath: (dataPath || '') + '.fields', schemaPath: '#/properties/fields/type', params: { type: 'array' }, message: 'should be array' }]; return false; } var valid1 = errors === errs_1; } if (valid1) { var data1 = data.additionalFields; if (data1 === undefined) { valid1 = true; } else { var errs_1 = errors; if (Array.isArray(data1)) { var errs__1 = errors; var valid1; for (var i1 = 0; i1 < data1.length; i1++) { var errs_2 = errors; if (typeof data1[i1] !== "string") { validate.errors = [{ keyword: 'type', dataPath: (dataPath || '') + '.additionalFields[' + i1 + ']', schemaPath: '#/properties/additionalFields/items/type', params: { type: 'string' }, message: 'should be string' }]; return false; } var valid2 = errors === errs_2; if (!valid2) break; } } else { validate.errors = [{ keyword: 'type', dataPath: (dataPath || '') + '.additionalFields', schemaPath: '#/properties/additionalFields/type', params: { type: 'array' }, message: 'should be array' }]; return false; } var valid1 = errors === errs_1; } if (valid1) { if (data.icon === undefined) { valid1 = true; } else { var errs_1 = errors; if (typeof data.icon !== "string") { validate.errors = [{ keyword: 'type', dataPath: (dataPath || '') + '.icon', schemaPath: '#/properties/icon/type', params: { type: 'string' }, message: 'should be string' }]; return false; } var valid1 = errors === errs_1; } if (valid1) { var data1 = data.terms; if (data1 === undefined) { valid1 = true; } else { var errs_1 = errors; if (Array.isArray(data1)) { var errs__1 = errors; var valid1; for (var i1 = 0; i1 < data1.length; i1++) { var errs_2 = errors; if (typeof data1[i1] !== "string") { validate.errors = [{ keyword: 'type', dataPath: (dataPath || '') + '.terms[' + i1 + ']', schemaPath: '#/properties/terms/items/type', params: { type: 'string' }, message: 'should be string' }]; return false; } var valid2 = errors === errs_2; if (!valid2) break; } } else { validate.errors = [{ keyword: 'type', dataPath: (dataPath || '') + '.terms', schemaPath: '#/properties/terms/type', params: { type: 'array' }, message: 'should be array' }]; return false; } var valid1 = errors === errs_1; } if (valid1) { var data1 = data.sort; if (data1 === undefined) { valid1 = true; } else { var errs_1 = errors; if ((typeof data1 !== "number" || (data1 % 1) || data1 !== data1)) { validate.errors = [{ keyword: 'type', dataPath: (dataPath || '') + '.sort', schemaPath: '#/properties/sort/type', params: { type: 'integer' }, message: 'should be integer' }]; return false; } var valid1 = errors === errs_1; } } } } } } } } } } } } } } } else { validate.errors = [{ keyword: 'type', dataPath: (dataPath || '') + "", schemaPath: '#/type', params: { type: 'object' }, message: 'should be object' }]; return false; } validate.errors = vErrors; return errors === 0; }; })(); validate.schema = { "$schema": "http://json-schema.org/draft-07/schema#", "$id": "http://mapeo.world/schemas/preset.json", "title": "Preset", "description": "Presets define how map entities are displayed to the user. They define the icon used on the map, and the fields / questions shown to the user when they create or edit the entity on the map. The `tags` property of a preset is used to match the preset with observations, nodes, ways and relations. If multiple presets match, the one that matches the most tags is used.", "type": "object", "additionalProperties": false, "properties": { "schemaVersion": { "description": "Version of schema. Should increment for breaking changes to the schema", "type": "number", "minimum": 1, "meta:enum": { "1": "Current schema version is `1`" }, "enum": [1] }, "id": { "description": "Unique value that identifies this element", "type": "string" }, "name": { "description": "Name for the feature in default language.", "type": "string" }, "geometry": { "description": "Valid geometry types for the feature - this preset will only match features of this geometry type `\"point\", \"vertex\", \"line\", \"area\", \"relation\"`", "type": "array", "minItems": 1, "uniqueItems": true, "items": { "type": "string", "enum": ["point", "vertex", "line", "area", "relation"] } }, "tags": { "description": "The tags are used to match the preset to existing map entities. You can match based on multiple tags E.g. if you have existing points with the tags `nature:tree` and `species:oak` then you can add both these tags here in order to match only oak trees.", "type": "object", "properties": {}, "additionalProperties": true }, "addTags": { "description": "Tags that are added when changing to the preset (default is the same value as 'tags')", "type": "object", "properties": {}, "additionalProperties": true }, "removeTags": { "description": "Tags that are removed when changing to another preset (default is the same value as 'addTags' which in turn defaults to 'tags')", "type": "object", "properties": {}, "additionalProperties": true }, "fields": { "description": "IDs of fields to displayed to the user when the preset is created or edited", "type": "array", "items": { "type": "string" } }, "additionalFields": { "description": "Additional fields to display (used internally by Mapeo Desktop, no need to define this in preset)", "type": "array", "items": { "type": "string" } }, "icon": { "description": "ID of preset icon which represents this preset", "type": "string" }, "terms": { "description": "Synonyms or related terms (used for search)", "type": "array", "items": { "type": "string" } }, "sort": { "description": "When presets are displayed as a list, defines the order it should be sorted. Presets with lowest sort numbers are displayed first", "type": "integer" } }, "required": ["id", "name", "geometry", "tags"] }; validate.errors = null; module.exports = validate;