mongoose-geojson-schema
Advanced tools
Comparing version 1.0.0 to 1.0.1
@@ -19,3 +19,3 @@ /** | ||
if (typeof crs !== 'object' && crs !== null) { | ||
throw new mongoose.SchemaType.CastError('Crs must be an object or null'); | ||
throw new mongoose.Error('Crs must be an object or null'); | ||
} | ||
@@ -26,15 +26,15 @@ if (crs === null) { | ||
if (!crs.type) { | ||
throw new mongoose.SchemaType.CastError('Crs must have a type'); | ||
throw new mongoose.Error('Crs must have a type'); | ||
} | ||
if (crs.type !== 'name' && crs.type !== 'link') { | ||
throw new mongoose.SchemaType.CastError('Crs must be either a name or link'); | ||
throw new mongoose.Error('Crs must be either a name or link'); | ||
} | ||
if (!crs.properties) { | ||
throw new mongoose.SchemaType.CastError('Crs must contain a properties object'); | ||
throw new mongoose.Error('Crs must contain a properties object'); | ||
} | ||
if (crs.type === 'name' && !crs.properties.name) { | ||
throw new mongoose.SchemaType.CastError('Crs specified by name must have a name property'); | ||
throw new mongoose.Error('Crs specified by name must have a name property'); | ||
} | ||
if (crs.type === 'link' && !crs.properties.href || crs.type === 'link' && !crs.properties.type) { | ||
throw new mongoose.SchemaType.CastError('Crs specified by link must have a name and href property'); | ||
throw new mongoose.Error('Crs specified by link must have a name and href property'); | ||
} | ||
@@ -55,11 +55,11 @@ } | ||
if (typeof coordinates !== 'object') { | ||
throw new mongoose.SchemaType.CastError('Point' + coordinates + ' must be an array'); | ||
throw new mongoose.Error('Point ' + coordinates + ' must be an array'); | ||
} | ||
// must have 2/3 points | ||
if (coordinates.length < 2 || coordinates.length > 3) { | ||
throw new mongoose.SchemaType.CastError('Point' + coordinates + ' must contain two coordinates'); | ||
throw new mongoose.Error('Point' + coordinates + ' must contain two or three coordinates'); | ||
} | ||
// longitude must be within bounds | ||
if (typeof coordinates[0] !== 'number' || typeof coordinates[1] !== 'number') { | ||
throw new mongoose.SchemaType.CastError('Point must have two numbers'); | ||
throw new mongoose.Error('Point must have two numbers'); | ||
} | ||
@@ -69,7 +69,7 @@ if (!crs) { | ||
if (coordinates[0] > 180 || coordinates[0] < -180) { | ||
throw new mongoose.SchemaType.CastError('Point', coordinates[0] + ' should be within the boundaries of latitude'); | ||
throw new mongoose.Error('Point' + coordinates[0] + ' should be within the boundaries of latitude'); | ||
} | ||
// latitude must be within bounds | ||
if (coordinates[1] > 90 || coordinates[1] < -90) { | ||
throw new mongoose.SchemaType.CastError('Point', coordinates[1] + ' should be within the boundaries of latitude'); | ||
throw new mongoose.Error('Point' + coordinates[1] + ' should be within the boundaries of latitude'); | ||
} | ||
@@ -83,7 +83,7 @@ } | ||
if (!point.type) { | ||
throw new mongoose.SchemaType.CastError('Point must have a type'); | ||
throw new mongoose.Error('Point', point.type, 'point.type'); | ||
} | ||
// type must be Point | ||
if (point.type !== 'Point') { | ||
throw new mongoose.SchemaType.CastError('Point type must be Point'); | ||
throw new mongoose.Error('Point type must be Point'); | ||
} | ||
@@ -123,10 +123,10 @@ // check for crs | ||
if (typeof multipoint.coordinates !== 'object') { | ||
throw new mongoose.SchemaType.CastError('MultiPoint must be an array'); | ||
throw new mongoose.Error('MultiPoint must be an array'); | ||
} | ||
if (!multipoint.type) { | ||
throw new mongoose.SchemaType.CastError('MultiPoint must have a type'); | ||
throw new mongoose.Error('MultiPoint must have a type'); | ||
} | ||
// type must be MultiPoint | ||
if (multipoint.type !== 'MultiPoint') { | ||
throw new mongoose.SchemaType.CastError('MultiPoint type must be MultiPoint'); | ||
throw new mongoose.Error('MultiPoint type must be MultiPoint'); | ||
} | ||
@@ -163,11 +163,11 @@ // check for crs | ||
if (!linestring.type) { | ||
throw new mongoose.SchemaType.CastError('LineString must have a type'); | ||
throw new mongoose.Error('LineString must have a type'); | ||
} | ||
// type must be LineString | ||
if (linestring.type !== 'LineString') { | ||
throw new mongoose.SchemaType.CastError('LineString type must be LineString'); | ||
throw new mongoose.Error('LineString type must be LineString'); | ||
} | ||
// must have at least two Points | ||
if (linestring.coordinates.length < 2) { | ||
throw new mongoose.SchemaType.CastError('LineString type must have at least two Points'); | ||
throw new mongoose.Error('LineString type must have at least two Points'); | ||
} | ||
@@ -205,10 +205,10 @@ // check for crs | ||
if (typeof multilinestring.coordinates !== 'object') { | ||
throw new mongoose.SchemaType.CastError('MultiLineString must be an array'); | ||
throw new mongoose.Error('MultiLineString must be an array'); | ||
} | ||
if (!multilinestring.type) { | ||
throw new mongoose.SchemaType.CastError('MultiLineString', multilinestring.type + ' must have a type'); | ||
throw new mongoose.Error('MultiLineString', multilinestring.type + ' must have a type'); | ||
} | ||
// type must be MultiLineString | ||
if (multilinestring.type !== 'MultiLineString') { | ||
throw new mongoose.SchemaType.CastError('MultiLineString type must be MultiLineString'); | ||
throw new mongoose.Error('MultiLineString type must be MultiLineString'); | ||
} | ||
@@ -243,7 +243,7 @@ validateMultiLineString(multilinestring.coordinates); | ||
if (coordinates[i].length < 4) { | ||
throw new mongoose.SchemaType.CastError('Each Polygon LinearRing must have at least four elements'); | ||
throw new mongoose.Error('Each Polygon LinearRing must have at least four elements'); | ||
} | ||
// the LinearRing objects must have identical start and end values | ||
if (!arraysEqual(coordinates[i][0], coordinates[i][coordinates[i].length-1])) { | ||
throw new mongoose.SchemaType.CastError('Each Polygon LinearRing must have an identical first and last point'); | ||
throw new mongoose.Error('Each Polygon LinearRing must have an identical first and last point'); | ||
} | ||
@@ -259,7 +259,7 @@ // otherwise the LinearRings must correspond to a LineString | ||
if (!polygon.type) { | ||
throw new mongoose.SchemaType.CastError('Polygon', polygon.type + ' must have a type'); | ||
throw new mongoose.Error('Polygon', polygon.type + ' must have a type'); | ||
} | ||
// type must be Polygon | ||
if (polygon.type !== 'Polygon') { | ||
throw new mongoose.SchemaType.CastError('Polygon type must be Polygon'); | ||
throw new mongoose.Error('Polygon type must be Polygon'); | ||
} | ||
@@ -297,10 +297,10 @@ // check for crs | ||
if (typeof multipolygon.coordinates !== 'object') { | ||
throw new mongoose.SchemaType.CastError('MultiPolygon must be an array'); | ||
throw new mongoose.Error('MultiPolygon must be an array'); | ||
} | ||
if (!multipolygon.type) { | ||
throw new mongoose.SchemaType.CastError('MultiPolygon must have a type'); | ||
throw new mongoose.Error('MultiPolygon must have a type'); | ||
} | ||
// type must be Polygon | ||
if (multipolygon.type !== 'MultiPolygon') { | ||
throw new mongoose.SchemaType.CastError('MultiPolygon type must be MultiPolygon'); | ||
throw new mongoose.Error('MultiPolygon type must be MultiPolygon'); | ||
} | ||
@@ -348,3 +348,3 @@ // check for crs | ||
default: | ||
throw new mongoose.SchemaType.CastError('Geometry must have a valid type'); | ||
throw new mongoose.Error('Geometry must have a valid type'); | ||
} | ||
@@ -359,3 +359,3 @@ } | ||
if (!geometry.type) { | ||
throw new mongoose.SchemaType.CastError('Geometry must must have a type'); | ||
throw new mongoose.Error('Geometry must must have a type'); | ||
} | ||
@@ -393,3 +393,3 @@ // check for crs | ||
if (typeof geometrycollection.geometries !== 'object') { | ||
throw new mongoose.SchemaType.CastError('GeometryCollection must be an array'); | ||
throw new mongoose.Error('GeometryCollection must be an array'); | ||
} | ||
@@ -418,10 +418,10 @@ // check for crs | ||
if (!feature.type) { | ||
throw new mongoose.SchemaType.CastError('Feature must have a type'); | ||
throw new mongoose.Error('Feature must have a type'); | ||
} | ||
// type must be Feature | ||
if (feature.type !== 'Feature') { | ||
throw new mongoose.SchemaType.CastError('Feature type must be Feature'); | ||
throw new mongoose.Error('Feature type must be Feature'); | ||
} | ||
if (!feature.geometry) { | ||
throw new mongoose.SchemaType.CastError('Feature must have a geometry'); | ||
throw new mongoose.Error('Feature must have a geometry'); | ||
} | ||
@@ -465,10 +465,10 @@ // check for crs | ||
if (!featurecollection.type) { | ||
throw new mongoose.SchemaType.CastError('FeatureCollection must have a type'); | ||
throw new mongoose.Error('FeatureCollection must have a type'); | ||
} | ||
// type must be Polygon | ||
if (featurecollection.type !== 'FeatureCollection') { | ||
throw new mongoose.SchemaType.CastError('FeatureCollection type must be FeatureCollection'); | ||
throw new mongoose.Error('FeatureCollection type must be FeatureCollection'); | ||
} | ||
if (!featurecollection.features) { | ||
throw new mongoose.SchemaType.CastError('FeatureCollections must have a features object'); | ||
throw new mongoose.Error('FeatureCollections must have a features object'); | ||
} | ||
@@ -475,0 +475,0 @@ // check for crs |
{ | ||
"name": "mongoose-geojson-schema", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "Schema definitions for GeoJSON types for use with Mongoose JS", | ||
@@ -5,0 +5,0 @@ "main": "GeoJSON.js", |
@@ -100,3 +100,3 @@ /** | ||
var error = geoJSON.validateSync(); | ||
expect(error.errors.point.message).to.contain('Cast to Point failed for value'); | ||
expect(error.errors.point.reason.message).to.contain('Crs specified by name must have a name property'); | ||
}); | ||
@@ -109,3 +109,3 @@ | ||
var error = geoJSON.validateSync(); | ||
expect(error.errors.point.message).to.contain('Cast to Point failed for value'); | ||
expect(error.errors.point.reason.message).to.contain('should be within the boundaries of latitude'); | ||
}); | ||
@@ -118,3 +118,3 @@ | ||
var error = geoJSON.validateSync(); | ||
expect(error.errors.point.message).to.contain('Cast to Point failed for value'); | ||
expect(error.errors.point.reason.message).to.contain('must contain two or three coordinates'); | ||
}); | ||
@@ -126,3 +126,3 @@ | ||
var error = geoJSON.validateSync(); | ||
expect(error.errors.point.message).to.contain('Cast to Point failed for value'); | ||
expect(error.errors.point.reason.message).to.contain('Point type must be Point'); | ||
}); | ||
@@ -158,3 +158,3 @@ | ||
var error = geoJSON.validateSync(); | ||
expect(error.errors.multipoint.message).to.contain('Cast to MultiPoint failed for value '); | ||
expect(error.errors.multipoint.reason.message).to.contain('must contain two or three coordinates'); | ||
}); | ||
@@ -166,3 +166,3 @@ | ||
var error = geoJSON.validateSync(); | ||
expect(error.errors.multipoint.message).to.contain('Cast to MultiPoint failed for value '); | ||
expect(error.errors.multipoint.reason.message).to.contain('MultiPoint type must be MultiPoint'); | ||
}); | ||
@@ -199,3 +199,3 @@ | ||
var error = geoJSON.validateSync(); | ||
expect(error.errors.linestring.message).to.contain('Cast to LineString failed for value'); | ||
expect(error.errors.linestring.reason.message).to.contain('must contain two or three coordinates'); | ||
}); | ||
@@ -207,3 +207,3 @@ | ||
var error = geoJSON.validateSync(); | ||
expect(error.errors.linestring.message).to.contain('Cast to LineString failed for value'); | ||
expect(error.errors.linestring.reason.message).to.contain('LineString type must be LineString'); | ||
}); | ||
@@ -215,3 +215,3 @@ | ||
var error = geoJSON.validateSync(); | ||
expect(error.errors.linestring.message).to.contain('Cast to LineString failed for value'); | ||
expect(error.errors.linestring.reason.message).to.contain('LineString type must have at least two Points'); | ||
}); | ||
@@ -255,3 +255,3 @@ | ||
var error = geoJSON.validateSync(); | ||
expect(error.errors.multilinestring.message).to.contain('Cast to MultiLineString failed for value'); | ||
expect(error.errors.multilinestring.reason.message).to.contain('must contain two or three coordinates'); | ||
}); | ||
@@ -263,3 +263,3 @@ | ||
var error = geoJSON.validateSync(); | ||
expect(error.errors.multilinestring.message).to.contain('Cast to MultiLineString failed for value'); | ||
expect(error.errors.multilinestring.reason.message).to.contain('MultiLineString type must be MultiLineString'); | ||
}); | ||
@@ -306,3 +306,3 @@ | ||
var error = geoJSON.validateSync(); | ||
expect(error.errors.polygon.message).to.contain('Cast to Polygon failed for value'); | ||
expect(error.errors.polygon.reason.message).to.contain('Each Polygon LinearRing must have an identical first and last point'); | ||
}); | ||
@@ -314,3 +314,3 @@ | ||
var error = geoJSON.validateSync(); | ||
expect(error.errors.polygon.message).to.contain('Cast to Polygon failed for value'); | ||
expect(error.errors.polygon.reason.message).to.contain('Polygon type must be Polygon'); | ||
}); | ||
@@ -368,7 +368,7 @@ | ||
it("should fail with a badly formed MultiPolygon", function () { | ||
multiPolygonData.multipolygon.coordinates[0][2] = 12345349884848; | ||
multiPolygonData.multipolygon.coordinates[0][3] = 9845674598; | ||
multiPolygonData.multipolygon.coordinates[0][0][2] = 12345349884848; | ||
multiPolygonData.multipolygon.coordinates[0][0][3] = 9845674598; | ||
var geoJSON = new GeoJSON(multiPolygonData); | ||
var error = geoJSON.validateSync(); | ||
expect(error.errors.multipolygon.message).to.contain('Cast to MultiPolygon failed for value'); | ||
expect(error.errors.multipolygon.reason.message).to.contain('Each Polygon LinearRing must have an identical first and last point'); | ||
}); | ||
@@ -380,3 +380,3 @@ | ||
var error = geoJSON.validateSync(); | ||
expect(error.errors.multipolygon.message).to.contain('Cast to MultiPolygon failed for value'); | ||
expect(error.errors.multipolygon.reason.message).to.contain('MultiPolygon type must be MultiPolygon'); | ||
}); | ||
@@ -434,3 +434,3 @@ | ||
var error = geoJSON.validateSync(); | ||
expect(error.errors.geometry.message).to.contain('Cast to Geometry failed for value'); | ||
expect(error.errors.geometry.reason.message).to.contain('must contain two or three coordinates'); | ||
}); | ||
@@ -442,3 +442,3 @@ | ||
var error = geoJSON.validateSync(); | ||
expect(error.errors.geometry.message).to.contain('Cast to Geometry failed for value'); | ||
expect(error.errors.geometry.reason.message).to.contain('Geometry must have a valid type'); | ||
}); | ||
@@ -555,3 +555,3 @@ | ||
var error = geoJSON.validateSync(); | ||
expect(error.errors.geometrycollection.message).to.contain('Cast to GeometryCollection failed for value'); | ||
expect(error.errors.geometrycollection.reason.message).to.contain('must contain two or three coordinates'); | ||
}); | ||
@@ -563,3 +563,3 @@ | ||
var error = geoJSON.validateSync(); | ||
expect(error.errors.geometrycollection.message).to.contain('Cast to GeometryCollection failed for value'); | ||
expect(error.errors.geometrycollection.reason.message).to.contain('Geometry must have a valid type'); | ||
}); | ||
@@ -611,3 +611,3 @@ | ||
var error = geoJSON.validateSync(); | ||
expect(error.errors.feature.message).to.contain('Cast to Feature failed for value'); | ||
expect(error.errors.feature.reason.message).to.contain('Each Polygon LinearRing must have an identical first and last point'); | ||
}); | ||
@@ -619,3 +619,3 @@ | ||
var error = geoJSON.validateSync(); | ||
expect(error.errors.feature.message).to.contain('Cast to Feature failed for value'); | ||
expect(error.errors.feature.reason.message).to.contain('Geometry must have a valid type'); | ||
}); | ||
@@ -672,3 +672,3 @@ | ||
var error = geoJSON.validateSync(); | ||
expect(error.errors.featurecollection.message).to.contain('Cast to FeatureCollection failed for value'); | ||
expect(error.errors.featurecollection.reason.message).to.contain('Each Polygon LinearRing must have an identical first and last point'); | ||
}); | ||
@@ -680,3 +680,3 @@ | ||
var error = geoJSON.validateSync(); | ||
expect(error.errors.featurecollection.message).to.contain('Cast to FeatureCollection failed for value'); | ||
expect(error.errors.featurecollection.reason.message).to.contain('Geometry must have a valid type'); | ||
}); | ||
@@ -683,0 +683,0 @@ |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
0
40376