chaosrouter
Advanced tools
Comparing version 0.2.7 to 0.2.8
@@ -77,3 +77,2 @@ | ||
var variables = {}; | ||
if (data === null || path.indexOf('/') === 0) { | ||
@@ -94,2 +93,16 @@ data = this.config; | ||
var last_seg; | ||
function getDirectives(data) { | ||
var directives = {}; | ||
for (var k in data) { | ||
if (k.indexOf(ChaosRouter.directivePrefix) === 0) { | ||
directives[k.slice(2)] = data[k]; | ||
delete data[k]; | ||
} | ||
} | ||
return directives; | ||
} | ||
var directives = {}; | ||
var validates = []; | ||
for (var i in segs) { | ||
@@ -122,3 +135,3 @@ var seg = segs[i]; | ||
data = vkey === null ? null : data[vkey]; | ||
if (data === null) | ||
@@ -134,2 +147,7 @@ return false; | ||
} | ||
// Attach the parent validations to this layer | ||
if(directives.validate) { | ||
data['#_validate'] = directives.validate.concat( data['#_validate'] || [] ); | ||
} | ||
directives = getDirectives(data); | ||
} | ||
@@ -139,10 +157,2 @@ last_seg = seg; | ||
var directives = {}; | ||
for (var k in data) { | ||
if (k.indexOf(ChaosRouter.directivePrefix) === 0) { | ||
directives[k.slice(2)] = data[k]; | ||
delete data[k]; | ||
} | ||
} | ||
if (directives['base'] === undefined) | ||
@@ -221,3 +231,3 @@ var config = extend({}, data); | ||
function validationErrorResponse(check, command) { | ||
if (check.error && check.message) | ||
if (check !== undefined && check.error && check.message) | ||
return check; | ||
@@ -241,13 +251,23 @@ else { | ||
var next = function () { | ||
self.runMethod(executes, i+1, resp); | ||
}; | ||
var args = []; | ||
if (typeof exec === 'string') { | ||
// If [exec] is a string, just do a *fill* on [exec] | ||
var check = fill(exec, this); | ||
if (check === true) | ||
if (check !== true) { | ||
resp(validationErrorResponse(check, exec)); | ||
} | ||
// If it is the last exececutable, respond; | ||
// else continue through the list. | ||
if(executes.length === i+1) | ||
resp(); | ||
else | ||
resp(validationErrorResponse(check, exec)); | ||
next(); | ||
return; | ||
} | ||
var args = []; | ||
if (Array.isArray(exec)) { | ||
else if (Array.isArray(exec)) { | ||
// If [exec] is an array, use the first item as the function | ||
// name, and following items as arguments. | ||
if (exec.length === 0) | ||
@@ -263,2 +283,3 @@ return resp({ | ||
else { | ||
// If [exec] is not a string or an array, respond with an error. | ||
return resp({ | ||
@@ -270,7 +291,4 @@ "error": "Routing Syntax Error", | ||
var next = function () { | ||
self.runMethod(executes, i+1, resp); | ||
}; | ||
if (typeof exec === 'function') | ||
// If the original [exec] was an array, and the n | ||
cmd = exec; | ||
@@ -287,9 +305,11 @@ else { | ||
if (typeof cmd !== 'function') | ||
throw Error("'"+cmd+"' is not a function. Found type '"+(typeof cmd)+"'"); | ||
throw Error("'"+exec+"' is not a function. Found type '"+(typeof cmd)+"'"); | ||
} | ||
args = this.recursiveFill(args, this.args); | ||
cmd.call(this, args, resp, function (check) { | ||
if (check === true) | ||
if (check === true) { | ||
next(); | ||
} | ||
else | ||
@@ -296,0 +316,0 @@ resp(validationErrorResponse(check, exec)); |
{ | ||
"name": "chaosrouter", | ||
"version": "0.2.7", | ||
"version": "0.2.8", | ||
"description": "ERROR: No README data found!", | ||
@@ -5,0 +5,0 @@ "main": "chaosrouter.js", |
34
tests.js
@@ -170,6 +170,6 @@ | ||
test_endpoint('/get/people', null, function(result) { | ||
if (Object.keys(result).length < 80) { | ||
return ["Unexpected result", result]; | ||
} | ||
return true; | ||
if (Object.keys(result).length < 80) { | ||
return ["Unexpected result", result]; | ||
} | ||
return true; | ||
}) | ||
@@ -208,7 +208,7 @@ | ||
test_endpoint('/get/responses/dynamic', { | ||
"name": { | ||
"first": "Ricky", | ||
"last": "Bobby", | ||
"full": "Ricky Bobby" | ||
} | ||
"name": { | ||
"first": "Ricky", | ||
"last": "Bobby", | ||
"full": "Ricky Bobby" | ||
} | ||
}, function (result) { | ||
@@ -222,5 +222,5 @@ if (result.first === undefined) { | ||
test_endpoint('/get/responses/dynamic', { | ||
"name": { | ||
"test": "< exact" | ||
} | ||
"name": { | ||
"test": "< exact" | ||
} | ||
}, function (result) { | ||
@@ -276,2 +276,8 @@ if (result.test !== "< exact") { | ||
test_endpoint('/get/test_validate/multi_level/level_two', null, function (result) { | ||
if (result.message !== "Failed at rule = Failed at level 1") | ||
return ["Unexpected result", result]; | ||
return true; | ||
}); | ||
// test_endpoint('/get/trigger/400', null, function (result) { | ||
@@ -283,3 +289,3 @@ // if (result.status !== true) | ||
log.info("Waiting for", tests.length, "to be fullfilled") | ||
log.info("Waiting for", tests.length, "to be fulfilled") | ||
return Promise.all(tests).then(function(all) { | ||
@@ -295,3 +301,3 @@ // trx.commit(); | ||
}, function(err) { | ||
log.error("Refject failure"); | ||
log.error("Reject failure"); | ||
log.error(err); | ||
@@ -298,0 +304,0 @@ knex.destroy(); |
18600
618
4