chaosrouter
Advanced tools
Comparing version 0.2.1 to 0.2.2
@@ -43,3 +43,3 @@ | ||
this.basepath = setdefault(opts.basepath, '/'); | ||
this.defaultExec = setdefault(opts.defaultExec, null); | ||
this.defaultExec = opts.defaultExec; | ||
@@ -56,2 +56,3 @@ if (opts.defaultExec === undefined) | ||
} | ||
ChaosRouter.directivePrefix = '#_'; | ||
ChaosRouter.prototype.__directives__ = {}; | ||
@@ -135,3 +136,3 @@ ChaosRouter.prototype.directive = function (name, fn) { | ||
for (var k in data) { | ||
if (k.indexOf('#_') === 0) { | ||
if (k.indexOf(ChaosRouter.directivePrefix) === 0) { | ||
directives[k.slice(2)] = data[k]; | ||
@@ -167,5 +168,6 @@ delete data[k]; | ||
this.__methods__ = router.__methods__; | ||
this.defaultExec = router.defaultExec; | ||
this.args = {}; | ||
this.directives = directives; | ||
if (this.directives['execute'] === undefined) | ||
this.directives['execute'] = [[router.defaultExec]]; | ||
} | ||
@@ -260,20 +262,25 @@ Endpoint.prototype.directive = function (name, fn) { | ||
}; | ||
try { | ||
cmd = eval("self.__methods__."+exec); | ||
} catch (err) { | ||
return Promise.reject(err); | ||
} | ||
if (typeof cmd !== 'function') | ||
throw new Error("'"+cmd+"' is not a function. Found type '"+(typeof cmd)+"'"); | ||
if (typeof exec === 'function') | ||
cmd = exec; | ||
else { | ||
args = this.recursiveFill(args, this); | ||
cmd.call(self, args, resp, function (check) { | ||
if (check === true) | ||
next(); | ||
else | ||
resp(validationErrorResponse(check, exec)); | ||
}); | ||
try { | ||
cmd = eval("self.__methods__."+exec); | ||
} catch (err) { | ||
return resp({ | ||
"error": err.name, | ||
"message": err.message | ||
}); | ||
} | ||
if (typeof cmd !== 'function') | ||
throw Error("'"+cmd+"' is not a function. Found type '"+(typeof cmd)+"'"); | ||
} | ||
args = this.recursiveFill(args, this); | ||
cmd.call(this, args, resp, function (check) { | ||
if (check === true) | ||
next(); | ||
else | ||
resp(validationErrorResponse(check, exec)); | ||
}); | ||
} | ||
@@ -344,10 +351,5 @@ Endpoint.prototype.runAll = function(executables, cb) { | ||
return f(error); | ||
var execute = self.directives['execute']; | ||
if ( execute ) | ||
self.runAll(execute, f); | ||
else | ||
self.defaultExec.call(self, [], f); | ||
self.runAll(self.directives['execute'], f); | ||
}); | ||
}, f); | ||
}, f).catch(r); | ||
}); | ||
@@ -354,0 +356,0 @@ } |
{ | ||
"name": "chaosrouter", | ||
"version": "0.2.1", | ||
"version": "0.2.2", | ||
"description": "ERROR: No README data found!", | ||
@@ -5,0 +5,0 @@ "main": "chaosrouter.js", |
14
tests.js
@@ -132,4 +132,5 @@ | ||
function test_endpoint( endpoint, data, cb ) { | ||
if (data) | ||
extend(data, { "db": test_endpoint.db }); | ||
if (!data) | ||
data = {}; | ||
extend(data, { "db": test_endpoint.db }); | ||
@@ -262,6 +263,8 @@ tests.push(new Promise(function(f,r) { | ||
trx.commit(); | ||
log.info("Waiting for", tests.length, "to be fullfilled") | ||
return Promise.all(tests); | ||
}).then(function(all) { | ||
return Promise.all(tests).then(function(all) { | ||
// trx.commit(); | ||
// return Promise.resolve(); | ||
}); | ||
}).then(function() { | ||
log.info("Passes", passes); | ||
@@ -272,2 +275,3 @@ log.error("Failures", failures); | ||
}, function(err) { | ||
log.error("Refject failure"); | ||
log.error(err); | ||
@@ -274,0 +278,0 @@ knex.destroy(); |
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
16924
570