UNPKG

mapeo-schema

Version:

JSON schema and flow types for Mapeo

525 lines 21.5 kB
'use strict'; var formats = require('ajv/lib/compile/formats')(); 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/filter.json */ var vErrors = null; var errors = 0; if ((data && typeof data === "object" && !Array.isArray(data))) { if (true) { var errs__0 = errors; var valid1 = true; 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.version === undefined) { valid1 = false; validate.errors = [{ keyword: 'required', dataPath: (dataPath || '') + "", schemaPath: '#/required', params: { missingProperty: 'version' }, message: 'should have required property \'version\'' }]; return false; } else { var errs_1 = errors; if (typeof data.version !== "string") { validate.errors = [{ keyword: 'type', dataPath: (dataPath || '') + '.version', schemaPath: '#/properties/version/type', params: { type: 'string' }, message: 'should be string' }]; return false; } var valid1 = errors === errs_1; } if (valid1) { var data1 = data.created_at; if (data1 === undefined) { valid1 = false; validate.errors = [{ keyword: 'required', dataPath: (dataPath || '') + "", schemaPath: '#/required', params: { missingProperty: 'created_at' }, message: 'should have required property \'created_at\'' }]; return false; } else { var errs_1 = errors; if (errors === errs_1) { if (typeof data1 === "string") { if (!formats['date-time'].test(data1)) { validate.errors = [{ keyword: 'format', dataPath: (dataPath || '') + '.created_at', schemaPath: '#/properties/created_at/format', params: { format: 'date-time' }, message: 'should match format "date-time"' }]; return false; } } else { validate.errors = [{ keyword: 'type', dataPath: (dataPath || '') + '.created_at', schemaPath: '#/properties/created_at/type', params: { type: 'string' }, message: 'should be string' }]; return false; } } var valid1 = errors === errs_1; } if (valid1) { var data1 = data.timestamp; if (data1 === undefined) { valid1 = true; } else { var errs_1 = errors; if (errors === errs_1) { if (typeof data1 === "string") { if (!formats['date-time'].test(data1)) { validate.errors = [{ keyword: 'format', dataPath: (dataPath || '') + '.timestamp', schemaPath: '#/properties/timestamp/format', params: { format: 'date-time' }, message: 'should match format "date-time"' }]; return false; } } else { validate.errors = [{ keyword: 'type', dataPath: (dataPath || '') + '.timestamp', schemaPath: '#/properties/timestamp/type', params: { type: 'string' }, message: 'should be string' }]; return false; } } var valid1 = errors === errs_1; } if (valid1) { if (data.userId === undefined) { valid1 = true; } else { var errs_1 = errors; if (typeof data.userId !== "string") { validate.errors = [{ keyword: 'type', dataPath: (dataPath || '') + '.userId', schemaPath: '#/properties/userId/type', params: { type: 'string' }, message: 'should be string' }]; return false; } var valid1 = errors === errs_1; } if (valid1) { if (data.deviceId === undefined) { valid1 = true; } else { var errs_1 = errors; if (typeof data.deviceId !== "string") { validate.errors = [{ keyword: 'type', dataPath: (dataPath || '') + '.deviceId', schemaPath: '#/properties/deviceId/type', params: { type: 'string' }, message: 'should be string' }]; return false; } var valid1 = errors === errs_1; } if (valid1) { var data1 = data.type; if (data1 === undefined) { valid1 = false; validate.errors = [{ keyword: 'required', dataPath: (dataPath || '') + "", schemaPath: '#/required', params: { missingProperty: 'type' }, message: 'should have required property \'type\'' }]; return false; } else { var errs_1 = errors; if (typeof data1 !== "string") { validate.errors = [{ keyword: 'type', dataPath: (dataPath || '') + '.type', schemaPath: '#/properties/type/type', params: { type: 'string' }, message: 'should be string' }]; return false; } var schema1 = validate.schema.properties.type.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 || '') + '.type', schemaPath: '#/properties/type/enum', params: { allowedValues: schema1 }, message: 'should be equal to one of the allowed values' }]; return false; } var valid1 = errors === errs_1; } if (valid1) { var data1 = data.links; 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 || '') + '.links[' + i1 + ']', schemaPath: '#/properties/links/items/type', params: { type: 'string' }, message: 'should be string' }]; 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 || '') + '.links', schemaPath: '#/properties/links/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 || '') + '.links', schemaPath: '#/properties/links/type', params: { type: 'array' }, message: 'should be array' }]; return false; } var valid1 = errors === errs_1; } if (valid1) { var data1 = data.schemaVersion; if (data1 === undefined) { valid1 = false; validate.errors = [{ keyword: 'required', dataPath: (dataPath || '') + "", schemaPath: '#/required', params: { missingProperty: 'schemaVersion' }, message: 'should have required property \'schemaVersion\'' }]; return false; } 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.filter === undefined) { valid1 = false; validate.errors = [{ keyword: 'required', dataPath: (dataPath || '') + "", schemaPath: '#/required', params: { missingProperty: 'filter' }, message: 'should have required property \'filter\'' }]; return false; } else { var errs_1 = errors; if (!Array.isArray(data.filter)) { validate.errors = [{ keyword: 'type', dataPath: (dataPath || '') + '.filter', schemaPath: '#/properties/filter/type', params: { type: 'array' }, message: 'should be array' }]; 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; } } } } } } } } } } } } } 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/filter.json", "title": "Filter", "description": "A filter is a saved view of data in the Mapeo database, filtered by tag or date. E.g. a filter could define observations between two dates, or only observations with the tag `public=true`", "type": "object", "properties": { "id": { "description": "Unique value that identifies this element", "type": "string" }, "version": { "description": "Unique value that identifies this particular version of this element", "type": "string" }, "created_at": { "description": "RFC3339-formatted datetime of when the first version of the element was created", "type": "string", "format": "date-time" }, "timestamp": { "description": "RFC3339-formatted datetime of when this version of the element was created", "type": "string", "format": "date-time" }, "userId": { "description": "ID of the user who edited/created this record", "type": "string" }, "deviceId": { "description": "ID of the device that made this edit", "type": "string" }, "type": { "description": "Must be `filter`", "type": "string", "enum": ["filter"] }, "links": { "description": "Version ids of the previous document versions this one is replacing", "type": "array", "uniqueItems": true, "items": { "type": "string" } }, "schemaVersion": { "description": "Version of this schema. Should increment for breaking changes to the schema", "type": "number", "minimum": 1, "enum": [1] }, "filter": { "type": "array", "description": "A filter expression as defined in https://docs.mapbox.com/mapbox-gl-js/style-spec/#other-filter but where the special fields `$type` refers to the mapeo type (observation, node, way etc) and `$id` is the mapeo id." }, "name": { "type": "string", "description": "A human-readable name for this filter." } }, "required": ["id", "version", "created_at", "type", "schemaVersion", "filter", "name"] }; validate.errors = null; module.exports = validate;