Browse Source

Remove all mappings other than helper/type_mapping

pull/292/head
Julian Simioni 9 years ago
parent
commit
68c9661c70
  1. 20
      helper/geojsonify.js
  2. 4
      helper/query_parser.js
  3. 4
      helper/types.js
  4. 15
      query/layers.js
  5. 14
      query/sources.js
  6. 16
      query/types.js
  7. 3
      sanitiser/_ids.js
  8. 5
      sanitiser/reverse.js
  9. 5
      sanitiser/search.js
  10. 5
      test/unit/helper/query_parser.js
  11. 23
      test/unit/query/types.js
  12. 1
      test/unit/run.js
  13. 4
      test/unit/sanitiser/_ids.js
  14. 3
      test/unit/sanitiser/_layers.js
  15. 3
      test/unit/sanitiser/_sources.js

20
helper/geojsonify.js

@ -2,7 +2,8 @@
var GeoJSON = require('geojson'),
extent = require('geojson-extent'),
outputGenerator = require('./outputGenerator'),
logger = require('pelias-logger').get('api');
logger = require('pelias-logger').get('api'),
type_mapping = require('./type_mapping');
// Properties to be copied
var DETAILS_PROPS = [
@ -22,22 +23,9 @@ var DETAILS_PROPS = [
];
var SOURCES = {
'geoname': 'gn',
'osmnode': 'osm',
'osmway': 'osm',
'admin0': 'qs',
'admin1': 'qs',
'admin2': 'qs',
'neighborhood': 'qs',
'locality': 'qs',
'local_admin': 'qs',
'osmaddress': 'osm',
'openaddresses': 'oa'
};
function lookupSource(src) {
return SOURCES.hasOwnProperty(src._type) ? SOURCES[src._type] : src._type;
var sources = type_mapping.type_to_source;
return sources.hasOwnProperty(src._type) ? sources[src._type] : src._type;
}
function lookupLayer(src) {

4
helper/query_parser.js

@ -1,7 +1,7 @@
var parser = require('addressit');
var extend = require('extend');
var layers_map = require('../query/layers');
var type_mapping = require('../helper/type_mapping');
var delim = ',';
module.exports = {};
@ -9,7 +9,7 @@ module.exports = {};
module.exports.get_layers = function get_layers(query) {
if (query.length <= 3 ) {
// no address parsing required
return layers_map.coarse;
return type_mapping.layer_to_type.coarse;
}
};

4
helper/types.js

@ -1,4 +1,4 @@
var valid_types = require( '../query/types' );
var type_mapping = require( '../helper/type_mapping' );
/**
* Calculate the set-style intersection of two arrays
@ -24,7 +24,7 @@ module.exports = function calculate_types(clean_types) {
* perform a set intersection of their specified types
*/
if (clean_types.from_layers || clean_types.from_sources) {
var types = valid_types;
var types = type_mapping.types_list;
if (clean_types.from_layers) {
types = intersection(types, clean_types.from_layers);

15
query/layers.js

@ -1,15 +0,0 @@
/*
* Mapping from data layers to type values
*/
module.exports = {
'venue': ['geoname','osmnode','osmway'],
'address': ['osmaddress','openaddresses'],
'country': ['admin0'],
'region': ['admin1'],
'county': ['admin2'],
'locality': ['locality'],
'localadmin': ['local_admin'],
'neighbourhood': ['neighborhood'],
'coarse': ['admin0','admin1','admin2','neighborhood','locality','local_admin'],
};

14
query/sources.js

@ -1,14 +0,0 @@
/*
* Mapping from data sources to type values
*/
module.exports = {
'gn' : ['geoname'],
'geonames' : ['geoname'],
'oa' : ['openaddresses'],
'openaddresses' : ['openaddresses'],
'qs' : ['admin0', 'admin1', 'admin2', 'neighborhood', 'locality', 'local_admin'],
'quattroshapes' : ['admin0', 'admin1', 'admin2', 'neighborhood', 'locality', 'local_admin'],
'osm' : ['osmaddress', 'osmnode', 'osmway'],
'openstreetmap' : ['osmaddress', 'osmnode', 'osmway']
};

16
query/types.js

@ -1,16 +0,0 @@
// querable types
module.exports = [
'geoname',
'osmnode',
'osmway',
'admin0',
'admin1',
'admin2',
'neighborhood',
'locality',
'local_admin',
'osmaddress',
'openaddresses'
];

3
sanitiser/_ids.js

@ -1,6 +1,7 @@
var _ = require('lodash'),
check = require('check-types'),
types = require('../query/types');
type_mapping = require('../helper/type_mapping'),
types = type_mapping.types_list;
var ID_DELIM = ':';

5
sanitiser/reverse.js

@ -1,9 +1,10 @@
var type_mapping = require('../helper/type_mapping');
var sanitizeAll = require('../sanitiser/sanitizeAll'),
sanitizers = {
singleScalarParameters: require('../sanitiser/_single_scalar_parameters'),
layers: require('../sanitiser/_targets')('layers', require('../query/layers')),
sources: require('../sanitiser/_targets')('sources', require('../query/sources')),
layers: require('../sanitiser/_targets')('layers', type_mapping.layer_to_type),
sources: require('../sanitiser/_targets')('sources', type_mapping.source_to_type),
size: require('../sanitiser/_size'),
private: require('../sanitiser/_flag_bool')('private', false),
geo_reverse: require('../sanitiser/_geo_reverse'),

5
sanitiser/search.js

@ -1,11 +1,12 @@
var type_mapping = require('../helper/type_mapping');
var sanitizeAll = require('../sanitiser/sanitizeAll'),
sanitizers = {
singleScalarParameters: require('../sanitiser/_single_scalar_parameters'),
text: require('../sanitiser/_text'),
size: require('../sanitiser/_size'),
layers: require('../sanitiser/_targets')('layers', require( '../query/layers' )),
sources: require('../sanitiser/_targets')('sources', require( '../query/sources' )),
layers: require('../sanitiser/_targets')('layers', type_mapping.layer_to_type),
sources: require('../sanitiser/_targets')('sources', type_mapping.source_to_type),
private: require('../sanitiser/_flag_bool')('private', false),
geo_search: require('../sanitiser/_geo_search'),
boundary_country: require('../sanitiser/_boundary_country'),

5
test/unit/helper/query_parser.js

@ -1,6 +1,7 @@
var parser = require('../../../helper/query_parser');
var layers_map = require('../../../query/layers');
var type_mapping = require('../../../helper/type_mapping');
var layers_map = type_mapping.layer_to_type;
module.exports.tests = {};

23
test/unit/query/types.js

@ -1,23 +0,0 @@
var types = require('../../../query/types');
module.exports.tests = {};
module.exports.tests.interface = function(test, common) {
test('valid interface', function(t) {
t.true(Array.isArray(types), 'valid array');
t.equal(types.length, 11, 'valid array');
t.end();
});
};
module.exports.all = function (tape, common) {
function test(name, testFunction) {
return tape('types ' + name, testFunction);
}
for( var testCase in module.exports.tests ){
module.exports.tests[testCase](test, common);
}
};

1
test/unit/run.js

@ -17,7 +17,6 @@ var tests = [
require('./sanitiser/_layers'),
require('./sanitiser/reverse'),
require('./sanitiser/place'),
require('./query/types'),
require('./query/search'),
require('./query/autocomplete'),
require('./query/reverse'),

4
test/unit/sanitiser/_ids.js

@ -1,7 +1,7 @@
var sanitize = require('../../../sanitiser/_ids');
var delimiter = ':';
var types = require('../../../query/types');
var type_mapping = require('../../../helper/type_mapping');
var inputs = {
valid: [ 'geoname:1', 'osmnode:2', 'admin0:53', 'osmway:44', 'geoname:5' ],
invalid: [ ':', '', '::', 'geoname:', ':234', 'gibberish:23' ]
@ -13,7 +13,7 @@ var formatError = function(input) {
var lengthError = 'invalid param \'ids\': length must be >0';
var defaultMissingTypeError = function(input) {
var type = input.split(delimiter)[0];
return type + ' is invalid. It must be one of these values - [' + types.join(', ') + ']';
return type + ' is invalid. It must be one of these values - [' + type_mapping.types_list.join(', ') + ']';
};
module.exports.tests = {};

3
test/unit/sanitiser/_layers.js

@ -1,5 +1,6 @@
var type_mapping = require('../../../helper/type_mapping');
var sanitize = require('../../../sanitiser/_targets')('layers', require('../../../query/layers'));
var sanitize = require('../../../sanitiser/_targets')('layers', type_mapping.layer_to_type);
module.exports.tests = {};

3
test/unit/sanitiser/_sources.js

@ -1,4 +1,5 @@
var sanitize = require( '../../../sanitiser/_targets' )('sources', require('../../../query/sources'));
var type_mapping = require('../../../helper/type_mapping');
var sanitize = require( '../../../sanitiser/_targets' )('sources', type_mapping.source_to_type);
var success_messages = { error: false };

Loading…
Cancel
Save