@koopjs/featureserver
Advanced tools
Comparing version 5.1.0 to 6.0.0
{ | ||
"name": "@koopjs/featureserver", | ||
"version": "5.1.0", | ||
"version": "6.0.0", | ||
"description": "*An open source implementation of the GeoServices specification*", | ||
@@ -28,3 +28,2 @@ "main": "src/index.js", | ||
"@terraformer/spatial": "^2.0.7", | ||
"chalk": "^4.0.0", | ||
"chroma-js": "^2.0.0", | ||
@@ -31,0 +30,0 @@ "esri-extent": "^1.1.1", |
module.exports = { | ||
CURRENT_VERSION: 10.51, | ||
FULL_VERSION: '10.5.1' | ||
FULL_VERSION: '10.5.1', | ||
MAX_RECORD_COUNT: 2000, | ||
}; |
@@ -13,3 +13,5 @@ module.exports = { | ||
...(require('./data-type-utils')), | ||
...(require('./renderers')) | ||
...(require('./renderers')), | ||
...(require('./validate-inputs')), | ||
...(require('./normalize-request-params')) | ||
}; |
@@ -53,6 +53,2 @@ const _ = require('lodash'); | ||
if (key === 'limit') { | ||
delete this.resultRecordCount; | ||
} | ||
delete this[key]; | ||
@@ -59,0 +55,0 @@ } |
133
src/route.js
@@ -1,3 +0,2 @@ | ||
const joi = require('joi'); | ||
const geojsonhint = require('geojson-validation'); | ||
const _ = require('lodash'); | ||
const layerInfo = require('./layer-metadata'); | ||
@@ -13,20 +12,9 @@ const query = require('./query'); | ||
const responseHandler = require('./response-handler'); | ||
const { validateInputs, normalizeRequestParameters } = require('./helpers'); | ||
const queryParamSchema = joi.object({ | ||
limit: joi.number().optional(), | ||
resultRecordCount: joi.number().optional() | ||
}).unknown(); | ||
const geojsonMetadataSchema = joi.object({ | ||
maxRecordCount: joi.number().prefs({ convert: false }).optional().default(2000) | ||
}).unknown(); | ||
module.exports = function route (req, res, geojson = {}) { | ||
module.exports = function route(req, res, geojson = {}) { | ||
const { | ||
params: { | ||
method | ||
}, | ||
params: { method }, | ||
url, | ||
originalUrl, | ||
path | ||
} = req; | ||
@@ -36,12 +24,14 @@ | ||
if (shouldValidateGeojson()) { | ||
validateGeojson(geojson, path); | ||
} | ||
try { | ||
const metadata = validateGeojsonMetadata(geojson.metadata); | ||
const queryParams = validateAndCoerceQueryParams(req.query, metadata); | ||
const params = normalizeRequestParameters( | ||
req.query, | ||
req.body, | ||
_.get(geojson, 'metadata.maxRecordCount'), | ||
); | ||
geojson = { ...geojson, metadata }; | ||
req = { ...req, query: queryParams }; | ||
validateInputs(params, geojson); | ||
req = { ...req, query: params }; | ||
geojson.metadata = geojson.metadata || { maxRecordCount: 2000 }; | ||
let result; | ||
@@ -56,5 +46,5 @@ | ||
} else if (isLayersMetadataRequest(route)) { | ||
result = layersInfo(geojson, queryParams); | ||
result = layersInfo(geojson, params); | ||
} else if (isRelationshipsMetadataRequest(route)) { | ||
result = relationshipsInfo(geojson, queryParams); | ||
result = relationshipsInfo(geojson, params); | ||
} else if (isLayerMetadataRequest(route)) { | ||
@@ -71,92 +61,57 @@ result = layerInfo(geojson, req); | ||
logger.debug(error); | ||
return responseHandler(req, res, error.code || 500, { error: error.message }); | ||
return responseHandler(req, res, error.code || 500, { | ||
error: error.message, | ||
}); | ||
} | ||
}; | ||
function handleMethodRequest ({ method, geojson, req }) { | ||
function handleMethodRequest({ method, geojson, req }) { | ||
if (method === 'query') { | ||
return query(geojson, req.query); | ||
} else if (method === 'queryRelatedRecords') { | ||
return queryRelatedRecords(geojson, req.query); | ||
} else if (method === 'generateRenderer') { | ||
return generateRenderer(geojson, req.query); | ||
} else if (method === 'info') { | ||
return layerInfo(geojson, req); | ||
} | ||
const error = new Error('Method not supported'); | ||
error.code = 400; | ||
throw error; | ||
} | ||
function shouldValidateGeojson () { | ||
const { | ||
KOOP_LOG_LEVEL, | ||
LOG_LEVEL | ||
} = process.env; | ||
return LOG_LEVEL === 'debug' || KOOP_LOG_LEVEL === 'debug'; | ||
} | ||
function validateGeojson (geojson, path) { | ||
const geojsonErrors = geojsonhint.valid(geojson, true); | ||
if (geojsonErrors.length > 0) { | ||
logger.debug(`Source data for ${path} contains invalid GeoJSON; ${geojsonErrors[0]}`); | ||
if (method === 'queryRelatedRecords') { | ||
return queryRelatedRecords(geojson, req.query); | ||
} | ||
} | ||
function validateGeojsonMetadata (metadata = {}) { | ||
const { error, value } = geojsonMetadataSchema.validate(metadata); | ||
if (error) { | ||
error.code = 500; | ||
throw error; | ||
if (method === 'generateRenderer') { | ||
return generateRenderer(geojson, req.query); | ||
} | ||
return value; | ||
} | ||
function validateAndCoerceQueryParams (queryParams, { maxRecordCount }) { | ||
const { error, value: query } = queryParamSchema.validate(queryParams); | ||
if (error) { | ||
error.code = 400; | ||
throw error; | ||
if (method === 'info') { | ||
return layerInfo(geojson, req); | ||
} | ||
const { limit, resultRecordCount } = query; | ||
query.limit = limit || resultRecordCount || maxRecordCount; | ||
return Object.keys(query).reduce((acc, key) => { | ||
const value = query[key]; | ||
if (value === 'false') acc[key] = false; | ||
else if (value === 'true') acc[key] = true; | ||
else { | ||
acc[key] = tryParse(value); | ||
} | ||
return acc; | ||
}, {}); | ||
const error = new Error('Method not supported'); | ||
error.code = 400; | ||
throw error; | ||
} | ||
function tryParse (value) { | ||
try { | ||
return JSON.parse(value); | ||
} catch (e) { | ||
return value; | ||
} | ||
} | ||
function isRestInfoRequest (url) { | ||
function isRestInfoRequest(url) { | ||
return /\/rest\/info$/i.test(url); | ||
} | ||
function isServerMetadataRequest (url) { | ||
return /\/FeatureServer$/i.test(url) || /\/FeatureServer\/info$/i.test(url) || /\/FeatureServer\/($|\?)/.test(url); | ||
function isServerMetadataRequest(url) { | ||
return ( | ||
/\/FeatureServer$/i.test(url) || | ||
/\/FeatureServer\/info$/i.test(url) || | ||
/\/FeatureServer\/($|\?)/.test(url) | ||
); | ||
} | ||
function isLayersMetadataRequest (url) { | ||
function isLayersMetadataRequest(url) { | ||
return /\/FeatureServer\/layers$/i.test(url); | ||
} | ||
function isRelationshipsMetadataRequest (url) { | ||
function isRelationshipsMetadataRequest(url) { | ||
return /\/FeatureServer\/relationships$/i.test(url); | ||
} | ||
function isLayerMetadataRequest (url) { | ||
return /\/FeatureServer\/\d+$/i.test(url) || /\/FeatureServer\/\d+\/info$/i.test(url) || /\/FeatureServer\/\d+\/$/.test(url); | ||
function isLayerMetadataRequest(url) { | ||
return ( | ||
/\/FeatureServer\/\d+$/i.test(url) || | ||
/\/FeatureServer\/\d+\/info$/i.test(url) || | ||
/\/FeatureServer\/\d+\/$/.test(url) | ||
); | ||
} |
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
96217
10
54
2412
- Removedchalk@^4.0.0
- Removedchalk@4.1.2(transitive)
- Removedhas-flag@4.0.0(transitive)
- Removedsupports-color@7.2.0(transitive)