Comparing version 0.3.0 to 0.3.1
@@ -5,3 +5,4 @@ "use strict"; | ||
const util_1 = require("util"); | ||
const handlers_1 = require("./handlers"); | ||
const assert = require("assert"); | ||
const aldo_compose_1 = require("aldo-compose"); | ||
const context_1 = require("./context"); | ||
@@ -26,4 +27,5 @@ const createDebugger = require("debug"); | ||
for (let fn of fns) { | ||
this._handlers.push(_ensureFunction(fn)); | ||
assert(typeof fn === 'function', `Function expected but got ${typeof fn}.`); | ||
debug(`use handler: ${fn.name || '<anonymous>'}`); | ||
this._handlers.push(fn); | ||
} | ||
@@ -39,4 +41,5 @@ return this; | ||
for (let fn of fns) { | ||
this._errorHandlers.push(_ensureFunction(fn)); | ||
assert(typeof fn === 'function', `Function expected but got ${typeof fn}.`); | ||
debug(`use error handler: ${fn.name || '<anonymous>'}`); | ||
this._errorHandlers.push(fn); | ||
} | ||
@@ -49,4 +52,4 @@ return this; | ||
callback() { | ||
var handleError = handlers_1.compose(this._errorHandlers.length > 0 ? this._errorHandlers : [_report]); | ||
var dispatch = handlers_1.compose(this._handlers); | ||
var handleError = aldo_compose_1.default(this._errorHandlers.length > 0 ? this._errorHandlers : [_report]); | ||
var dispatch = aldo_compose_1.default(this._handlers); | ||
return (req, res) => { | ||
@@ -73,4 +76,5 @@ var ctx = this._context.from(req, res); | ||
bind(prop, fn) { | ||
this._context.bind(prop, _ensureFunction(fn)); | ||
assert(typeof fn === 'function', `Function expected but got ${typeof fn}.`); | ||
debug(`set a private context attribute: ${prop}`); | ||
this._context.bind(prop, fn); | ||
return this; | ||
@@ -85,4 +89,4 @@ } | ||
set(prop, value) { | ||
debug(`set a shared context attribute: ${prop}`); | ||
this._context.set(prop, value); | ||
debug(`set a shared context attribute: ${prop}`); | ||
return this; | ||
@@ -117,22 +121,12 @@ } | ||
/** | ||
* Ensure the given argument is a function | ||
* Handle the error response | ||
* | ||
* @param arg | ||
* @private | ||
*/ | ||
function _ensureFunction(arg) { | ||
if (typeof arg === 'function') | ||
return arg; | ||
throw new TypeError(`Function expected but got ${typeof arg}.`); | ||
} | ||
/** | ||
* Send the error response | ||
* | ||
* @param error | ||
* @param ctx | ||
* @private | ||
*/ | ||
function _report({ error, res }) { | ||
function _report(error, { res }) { | ||
console.error(error); | ||
res.statusCode = error.status || 500; | ||
res.end(error.message); | ||
console.error(error); | ||
res.end(error.expose ? error.message : 'Internal Server Error'); | ||
} |
@@ -69,3 +69,2 @@ "use strict"; | ||
ctx.req = req; | ||
ctx.params = {}; | ||
return ctx; | ||
@@ -72,0 +71,0 @@ } |
{ | ||
"name": "aldo", | ||
"version": "0.3.0", | ||
"version": "0.3.1", | ||
"description": "Fast micro framework for Node.js 8+", | ||
@@ -15,2 +15,5 @@ "main": "lib/index.js", | ||
], | ||
"engines": { | ||
"node": ">=8.9" | ||
}, | ||
"repository": { | ||
@@ -41,4 +44,5 @@ "type": "git", | ||
"dependencies": { | ||
"aldo-compose": "^1.0.1", | ||
"debug": "^3.1.0" | ||
} | ||
} |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
1
12968
2
7
266
+ Addedaldo-compose@^1.0.1
+ Addedaldo-compose@1.0.1(transitive)