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. 2
      query/types.js
  3. 8
      sanitiser/_id.js
  4. 8
      sanitiser/_layers.js
  5. 2
      test/unit/helper/types.js
  6. 8
      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) { module.exports = function calculate_types(clean_types) {
if (!clean_types) { if (!clean_types) {

2
query/indeces.js → query/types.js

@ -1,5 +1,5 @@
// querable indeces // querable types
module.exports = [ module.exports = [
'geoname', 'geoname',

8
sanitiser/_id.js

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

8
sanitiser/_layers.js

@ -1,6 +1,6 @@
var isObject = require('is-object'), var isObject = require('is-object'),
indeces = require('../query/indeces'), types = require('../query/types'),
get_layers = require('../helper/layers'); get_layers = require('../helper/layers');
// validate inputs, convert types and apply defaults // validate inputs, convert types and apply defaults
@ -23,7 +23,7 @@ function sanitize( req ){
// decide which layers can be queried // decide which layers can be queried
var alias_layers = ['poi', 'admin', 'address']; var alias_layers = ['poi', 'admin', 'address'];
var alias_indeces = indeces.concat(alias_layers); var alias_types = types.concat(alias_layers);
// parse GET params // parse GET params
var layers = params.layers.split(',').map( function( layer ){ var layers = params.layers.split(',').map( function( layer ){
@ -32,10 +32,10 @@ function sanitize( req ){
// validate layer names // validate layer names
for( var x=0; x<layers.length; x++ ){ for( var x=0; x<layers.length; x++ ){
if( -1 === alias_indeces.indexOf( layers[x] ) ){ if( -1 === alias_types.indexOf( layers[x] ) ){
return { return {
'error': true, '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 types = require('../../../helper/types');
var valid_types = require( '../../../query/indeces' ); var valid_types = require( '../../../query/types' );
module.exports.tests = {}; module.exports.tests = {};
module.exports.tests.no_cleaned_types = function(test, common) { module.exports.tests.no_cleaned_types = function(test, common) {

8
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 = {};
module.exports.tests.interface = function(test, common) { module.exports.tests.interface = function(test, common) {
test('valid interface', function(t) { test('valid interface', function(t) {
t.true(Array.isArray(indeces), 'valid array'); t.true(Array.isArray(types), 'valid array');
t.equal(indeces.length, 11, 'valid array'); t.equal(types.length, 11, 'valid array');
t.end(); t.end();
}); });
}; };
@ -14,7 +14,7 @@ module.exports.tests.interface = function(test, common) {
module.exports.all = function (tape, common) { module.exports.all = function (tape, common) {
function test(name, testFunction) { function test(name, testFunction) {
return tape('indeces ' + name, testFunction); return tape('types ' + name, testFunction);
} }
for( var testCase in module.exports.tests ){ for( var testCase in module.exports.tests ){

2
test/unit/run.js

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

4
test/unit/sanitiser/place.js

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

1
test/unit/sanitiser/reverse.js

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

Loading…
Cancel
Save