mapeo-schema
Version:
JSON schema and flow types for Mapeo
905 lines (904 loc) • 80 kB
JavaScript
'use strict';
var formats = require('ajv/lib/compile/formats')();
var equal = require('ajv/lib/compile/equal');
var validate = (function() {
var refVal = [];
var refVal1 = {
"description": "Position details",
"type": "object",
"properties": {
"timestamp": {
"description": "Timestamp of when the current position was obtained",
"type": "number"
},
"mocked": {
"description": "`true` if the position was mocked",
"type": "boolean",
"default": false
},
"coords": {
"description": "Position details, should be self explanatory. Units in meters",
"type": "object",
"properties": {
"altitude": {
"type": "number"
},
"heading": {
"type": "number"
},
"longitude": {
"type": "number"
},
"speed": {
"type": "number"
},
"latitude": {
"type": "number"
},
"accuracy": {
"type": "number"
}
}
}
}
};
refVal[1] = refVal1;
return function validate(data, dataPath, parentData, parentDataProperty, rootData) {
'use strict'; /*# sourceURL=http://mapeo.world/schemas/observation.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) {
var data1 = data.lat;
if (data1 === undefined) {
valid1 = true;
} else {
var errs_1 = errors;
if (typeof data1 !== "number" && data1 !== null) {
validate.errors = [{
keyword: 'type',
dataPath: (dataPath || '') + '.lat',
schemaPath: '#/properties/lat/type',
params: {
type: 'number,null'
},
message: 'should be number,null'
}];
return false;
}
if (typeof data1 === "number") {
if (data1 > 90 || data1 !== data1) {
validate.errors = [{
keyword: 'maximum',
dataPath: (dataPath || '') + '.lat',
schemaPath: '#/properties/lat/maximum',
params: {
comparison: '<=',
limit: 90,
exclusive: false
},
message: 'should be <= 90'
}];
return false;
} else {
if (data1 < -90 || data1 !== data1) {
validate.errors = [{
keyword: 'minimum',
dataPath: (dataPath || '') + '.lat',
schemaPath: '#/properties/lat/minimum',
params: {
comparison: '>=',
limit: -90,
exclusive: false
},
message: 'should be >= -90'
}];
return false;
}
}
}
var valid1 = errors === errs_1;
}
if (valid1) {
var data1 = data.lon;
if (data1 === undefined) {
valid1 = true;
} else {
var errs_1 = errors;
if (typeof data1 !== "number" && data1 !== null) {
validate.errors = [{
keyword: 'type',
dataPath: (dataPath || '') + '.lon',
schemaPath: '#/properties/lon/type',
params: {
type: 'number,null'
},
message: 'should be number,null'
}];
return false;
}
if (typeof data1 === "number") {
if (data1 > 180 || data1 !== data1) {
validate.errors = [{
keyword: 'maximum',
dataPath: (dataPath || '') + '.lon',
schemaPath: '#/properties/lon/maximum',
params: {
comparison: '<=',
limit: 180,
exclusive: false
},
message: 'should be <= 180'
}];
return false;
} else {
if (data1 < -180 || data1 !== data1) {
validate.errors = [{
keyword: 'minimum',
dataPath: (dataPath || '') + '.lon',
schemaPath: '#/properties/lon/minimum',
params: {
comparison: '>=',
limit: -180,
exclusive: false
},
message: 'should be >= -180'
}];
return false;
}
}
}
var valid1 = errors === errs_1;
}
if (valid1) {
var data1 = data.metadata;
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;
var data2 = data1.position;
if (data2 === undefined) {
valid2 = true;
} else {
var errs_2 = errors;
var errs_3 = errors;
if ((data2 && typeof data2 === "object" && !Array.isArray(data2))) {
var errs__3 = errors;
var valid4 = true;
if (data2.timestamp === undefined) {
valid4 = true;
} else {
var errs_4 = errors;
if (typeof data2.timestamp !== "number") {
validate.errors = [{
keyword: 'type',
dataPath: (dataPath || '') + '.metadata.position.timestamp',
schemaPath: '#/definitions/position/properties/timestamp/type',
params: {
type: 'number'
},
message: 'should be number'
}];
return false;
}
var valid4 = errors === errs_4;
}
if (valid4) {
if (data2.mocked === undefined) {
valid4 = true;
} else {
var errs_4 = errors;
if (typeof data2.mocked !== "boolean") {
validate.errors = [{
keyword: 'type',
dataPath: (dataPath || '') + '.metadata.position.mocked',
schemaPath: '#/definitions/position/properties/mocked/type',
params: {
type: 'boolean'
},
message: 'should be boolean'
}];
return false;
}
var valid4 = errors === errs_4;
}
if (valid4) {
var data3 = data2.coords;
if (data3 === undefined) {
valid4 = true;
} else {
var errs_4 = errors;
if ((data3 && typeof data3 === "object" && !Array.isArray(data3))) {
var errs__4 = errors;
var valid5 = true;
if (data3.altitude === undefined) {
valid5 = true;
} else {
var errs_5 = errors;
if (typeof data3.altitude !== "number") {
validate.errors = [{
keyword: 'type',
dataPath: (dataPath || '') + '.metadata.position.coords.altitude',
schemaPath: '#/definitions/position/properties/coords/properties/altitude/type',
params: {
type: 'number'
},
message: 'should be number'
}];
return false;
}
var valid5 = errors === errs_5;
}
if (valid5) {
if (data3.heading === undefined) {
valid5 = true;
} else {
var errs_5 = errors;
if (typeof data3.heading !== "number") {
validate.errors = [{
keyword: 'type',
dataPath: (dataPath || '') + '.metadata.position.coords.heading',
schemaPath: '#/definitions/position/properties/coords/properties/heading/type',
params: {
type: 'number'
},
message: 'should be number'
}];
return false;
}
var valid5 = errors === errs_5;
}
if (valid5) {
if (data3.longitude === undefined) {
valid5 = true;
} else {
var errs_5 = errors;
if (typeof data3.longitude !== "number") {
validate.errors = [{
keyword: 'type',
dataPath: (dataPath || '') + '.metadata.position.coords.longitude',
schemaPath: '#/definitions/position/properties/coords/properties/longitude/type',
params: {
type: 'number'
},
message: 'should be number'
}];
return false;
}
var valid5 = errors === errs_5;
}
if (valid5) {
if (data3.speed === undefined) {
valid5 = true;
} else {
var errs_5 = errors;
if (typeof data3.speed !== "number") {
validate.errors = [{
keyword: 'type',
dataPath: (dataPath || '') + '.metadata.position.coords.speed',
schemaPath: '#/definitions/position/properties/coords/properties/speed/type',
params: {
type: 'number'
},
message: 'should be number'
}];
return false;
}
var valid5 = errors === errs_5;
}
if (valid5) {
if (data3.latitude === undefined) {
valid5 = true;
} else {
var errs_5 = errors;
if (typeof data3.latitude !== "number") {
validate.errors = [{
keyword: 'type',
dataPath: (dataPath || '') + '.metadata.position.coords.latitude',
schemaPath: '#/definitions/position/properties/coords/properties/latitude/type',
params: {
type: 'number'
},
message: 'should be number'
}];
return false;
}
var valid5 = errors === errs_5;
}
if (valid5) {
if (data3.accuracy === undefined) {
valid5 = true;
} else {
var errs_5 = errors;
if (typeof data3.accuracy !== "number") {
validate.errors = [{
keyword: 'type',
dataPath: (dataPath || '') + '.metadata.position.coords.accuracy',
schemaPath: '#/definitions/position/properties/coords/properties/accuracy/type',
params: {
type: 'number'
},
message: 'should be number'
}];
return false;
}
var valid5 = errors === errs_5;
}
}
}
}
}
}
} else {
validate.errors = [{
keyword: 'type',
dataPath: (dataPath || '') + '.metadata.position.coords',
schemaPath: '#/definitions/position/properties/coords/type',
params: {
type: 'object'
},
message: 'should be object'
}];
return false;
}
var valid4 = errors === errs_4;
}
}
}
} else {
validate.errors = [{
keyword: 'type',
dataPath: (dataPath || '') + '.metadata.position',
schemaPath: '#/definitions/position/type',
params: {
type: 'object'
},
message: 'should be object'
}];
return false;
}
var valid3 = errors === errs_3;
var valid2 = errors === errs_2;
}
if (valid2) {
var data2 = data1.lastSavedPosition;
if (data2 === undefined) {
valid2 = true;
} else {
var errs_2 = errors;
var errs_3 = errors;
if ((data2 && typeof data2 === "object" && !Array.isArray(data2))) {
var errs__3 = errors;
var valid4 = true;
if (data2.timestamp === undefined) {
valid4 = true;
} else {
var errs_4 = errors;
if (typeof data2.timestamp !== "number") {
validate.errors = [{
keyword: 'type',
dataPath: (dataPath || '') + '.metadata.lastSavedPosition.timestamp',
schemaPath: '#/definitions/position/properties/timestamp/type',
params: {
type: 'number'
},
message: 'should be number'
}];
return false;
}
var valid4 = errors === errs_4;
}
if (valid4) {
if (data2.mocked === undefined) {
valid4 = true;
} else {
var errs_4 = errors;
if (typeof data2.mocked !== "boolean") {
validate.errors = [{
keyword: 'type',
dataPath: (dataPath || '') + '.metadata.lastSavedPosition.mocked',
schemaPath: '#/definitions/position/properties/mocked/type',
params: {
type: 'boolean'
},
message: 'should be boolean'
}];
return false;
}
var valid4 = errors === errs_4;
}
if (valid4) {
var data3 = data2.coords;
if (data3 === undefined) {
valid4 = true;
} else {
var errs_4 = errors;
if ((data3 && typeof data3 === "object" && !Array.isArray(data3))) {
var errs__4 = errors;
var valid5 = true;
if (data3.altitude === undefined) {
valid5 = true;
} else {
var errs_5 = errors;
if (typeof data3.altitude !== "number") {
validate.errors = [{
keyword: 'type',
dataPath: (dataPath || '') + '.metadata.lastSavedPosition.coords.altitude',
schemaPath: '#/definitions/position/properties/coords/properties/altitude/type',
params: {
type: 'number'
},
message: 'should be number'
}];
return false;
}
var valid5 = errors === errs_5;
}
if (valid5) {
if (data3.heading === undefined) {
valid5 = true;
} else {
var errs_5 = errors;
if (typeof data3.heading !== "number") {
validate.errors = [{
keyword: 'type',
dataPath: (dataPath || '') + '.metadata.lastSavedPosition.coords.heading',
schemaPath: '#/definitions/position/properties/coords/properties/heading/type',
params: {
type: 'number'
},
message: 'should be number'
}];
return false;
}
var valid5 = errors === errs_5;
}
if (valid5) {
if (data3.longitude === undefined) {
valid5 = true;
} else {
var errs_5 = errors;
if (typeof data3.longitude !== "number") {
validate.errors = [{
keyword: 'type',
dataPath: (dataPath || '') + '.metadata.lastSavedPosition.coords.longitude',
schemaPath: '#/definitions/position/properties/coords/properties/longitude/type',
params: {
type: 'number'
},
message: 'should be number'
}];
return false;
}
var valid5 = errors === errs_5;
}
if (valid5) {
if (data3.speed === undefined) {
valid5 = true;
} else {
var errs_5 = errors;
if (typeof data3.speed !== "number") {
validate.errors = [{
keyword: 'type',
dataPath: (dataPath || '') + '.metadata.lastSavedPosition.coords.speed',
schemaPath: '#/definitions/position/properties/coords/properties/speed/type',
params: {
type: 'number'
},
message: 'should be number'
}];
return false;
}
var valid5 = errors === errs_5;
}
if (valid5) {
if (data3.latitude === undefined) {
valid5 = true;
} else {
var errs_5 = errors;
if (typeof data3.latitude !== "number") {
validate.errors = [{
keyword: 'type',
dataPath: (dataPath || '') + '.metadata.lastSavedPosition.coords.latitude',
schemaPath: '#/definitions/position/properties/coords/properties/latitude/type',
params: {
type: 'number'
},
message: 'should be number'
}];
return false;
}
var valid5 = errors === errs_5;
}
if (valid5) {
if (data3.accuracy === undefined) {
valid5 = true;
} else {
var errs_5 = errors;
if (typeof data3.accuracy !== "number") {
validate.errors = [{
keyword: 'type',
dataPath: (dataPath || '') + '.metadata.lastSavedPosition.coords.accuracy',
schemaPath: '#/definitions/position/properties/coords/properties/accuracy/type',
params: {
type: 'number'
},
message: 'should be number'
}];
return false;
}
var valid5 = errors === errs_5;
}
}
}
}
}
}