Browse Source

Rename query/indidces to query/types

It didn't really contain a list of indices.
pull/221/head
Julian Simioni 9 years ago
parent
commit
2ebc935295
  1. 2
      helper/types.js
  2. 4
      query/types.js
  3. 8
      sanitiser/_id.js
  4. 8
      sanitiser/_layers.js
  5. 2
      test/unit/helper/types.js
  6. 10
      test/unit/query/types.js
  7. 2
      test/unit/run.js
  8. 4
      test/unit/sanitiser/place.js
  9. 1
      test/unit/sanitiser/reverse.js

2
helper/types.js

@ -1,4 +1,4 @@
var valid_types = require( '../query/indeces' );
var valid_types = require( '../query/types' );
module.exports = function calculate_types(clean_types) {
if (!clean_types) {

4
query/indeces.js → query/types.js

@ -1,5 +1,5 @@
// querable indeces
// querable types
module.exports = [
'geoname',
@ -13,4 +13,4 @@ module.exports = [
'local_admin',
'osmaddress',
'openaddresses'
];
];

8
sanitiser/_id.js

@ -7,7 +7,7 @@ var isObject = require('is-object');
function sanitize( req ){
req.clean = req.clean || {};
var params = req.query;
var indeces = require('../query/indeces');
var types = require('../query/types');
var delim = ':';
// ensure params is a valid object
@ -55,9 +55,9 @@ function sanitize( req ){
if('string' !== typeof type || !type.length){
return errormessage(thisparam);
}
// type text must be one of the indeces
if(indeces.indexOf(type) === -1){
return errormessage('type', type + ' is invalid. It must be one of these values - [' + indeces.join(', ') + ']');
// type text must be one of the types
if(types.indexOf(type) === -1){
return errormessage('type', type + ' is invalid. It must be one of these values - [' + types.join(', ') + ']');
}
req.clean.ids.push({
id: id,

8
sanitiser/_layers.js

@ -1,6 +1,6 @@
var isObject = require('is-object'),
indeces = require('../query/indeces'),
types = require('../query/types'),
get_layers = require('../helper/layers');
// validate inputs, convert types and apply defaults
@ -23,7 +23,7 @@ function sanitize( req ){
// decide which layers can be queried
var alias_layers = ['poi', 'admin', 'address'];
var alias_indeces = indeces.concat(alias_layers);
var alias_types = types.concat(alias_layers);
// parse GET params
var layers = params.layers.split(',').map( function( layer ){
@ -32,10 +32,10 @@ function sanitize( req ){
// validate layer names
for( var x=0; x<layers.length; x++ ){
if( -1 === alias_indeces.indexOf( layers[x] ) ){
if( -1 === alias_types.indexOf( layers[x] ) ){
return {
'error': true,
'message': 'invalid param \'layers\': must be one or more of ' + alias_indeces.join(',')
'message': 'invalid param \'layers\': must be one or more of ' + alias_types.join(',')
};
}
}

2
test/unit/helper/types.js

@ -1,6 +1,6 @@
var types = require('../../../helper/types');
var valid_types = require( '../../../query/indeces' );
var valid_types = require( '../../../query/types' );
module.exports.tests = {};
module.exports.tests.no_cleaned_types = function(test, common) {

10
test/unit/query/indeces.js → test/unit/query/types.js

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

2
test/unit/run.js

@ -11,7 +11,7 @@ var tests = [
require('./sanitiser/search'),
require('./sanitiser/reverse'),
require('./sanitiser/place'),
require('./query/indeces'),
require('./query/types'),
require('./query/sort'),
require('./query/search'),
require('./query/reverse'),

4
test/unit/sanitiser/place.js

@ -2,14 +2,14 @@
var place = require('../../../sanitiser/place'),
_sanitize = place.sanitize,
middleware = place.middleware,
indeces = require('../../../query/indeces'),
types = require('../../../query/types'),
delimiter = ':',
defaultLengthError = function(input) { return 'invalid param \''+ input + '\': text length, must be >0'; },
defaultFormatError = 'invalid: must be of the format type:id for ex: \'geoname:4163334\'',
defaultError = 'invalid param \'id\': text length, must be >0',
defaultMissingTypeError = function(input) {
var type = input.split(delimiter)[0];
return type + ' is invalid. It must be one of these values - [' + indeces.join(', ') + ']'; },
return type + ' is invalid. It must be one of these values - [' + types.join(', ') + ']'; },
defaultClean = { ids: [ { id: '123', type: 'geoname' } ], details: true },
sanitize = function(query, cb) { _sanitize({'query':query}, cb); },
inputs = {

1
test/unit/sanitiser/reverse.js

@ -13,7 +13,6 @@ var suggest = require('../../../sanitiser/reverse'),
categories: []
},
sanitize = function(query, cb) { _sanitize({'query':query}, cb); };
var all_layers = ( '../../query/indeces' );
module.exports.tests = {};

Loading…
Cancel
Save