Comparing version 1.1.1 to 2.0.0
@@ -1,5 +0,24 @@ | ||
import Promise = require('any-promise'); | ||
export interface NextFunction<T> { | ||
(): Promise<T>; | ||
} | ||
export declare function compose<T>(middleware: Array<(...args: any[]) => T | Promise<T>>): (...args: any[]) => Promise<T>; | ||
export declare type NextFunction<R> = () => Promise<R>; | ||
export declare type Middleware5<T1, T2, T3, T4, T5, R> = (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5, next: NextFunction<R>) => R | Promise<R>; | ||
export declare type Middleware4<T1, T2, T3, T4, R> = (arg1: T1, arg2: T2, arg3: T3, arg4: T4, next: NextFunction<R>) => R | Promise<R>; | ||
export declare type Middleware3<T1, T2, T3, R> = (arg1: T1, arg2: T2, arg3: T3, next: NextFunction<R>) => R | Promise<R>; | ||
export declare type Middleware2<T1, T2, R> = (arg1: T1, arg2: T2, next: NextFunction<R>) => R | Promise<R>; | ||
export declare type Middleware1<T1, R> = (arg1: T1, next: NextFunction<R>) => R | Promise<R>; | ||
export declare type Middleware0<R> = (next: NextFunction<R>) => R | Promise<R>; | ||
export declare type Middleware<R> = (...args: any[]) => R | Promise<R>; | ||
export declare type OutFunction5<T1, T2, T3, T4, T5, R> = (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5, next: Middleware5<T1, T2, T3, T4, T5, R>) => Promise<R>; | ||
export declare type OutFunction4<T1, T2, T3, T4, R> = (arg1: T1, arg2: T2, arg3: T3, arg4: T4, next: Middleware4<T1, T2, T3, T4, R>) => Promise<R>; | ||
export declare type OutFunction3<T1, T2, T3, R> = (arg1: T1, arg2: T2, arg3: T3, next: Middleware3<T1, T2, T3, R>) => Promise<R>; | ||
export declare type OutFunction2<T1, T2, R> = (arg1: T1, arg2: T2, next: Middleware2<T1, T2, R>) => Promise<R>; | ||
export declare type OutFunction1<T1, R> = (arg1: T1, next: Middleware1<T1, R>) => Promise<R>; | ||
export declare type OutFunction0<R> = (next: Middleware0<R>) => Promise<R>; | ||
export declare type OutFunction<R> = (...args: any[]) => Promise<R>; | ||
/** | ||
* Compose an array of middleware functions into a chain. | ||
*/ | ||
export declare function compose<R>(middleware: Array<Middleware0<R>>): OutFunction0<R>; | ||
export declare function compose<T1, R>(middleware: Array<Middleware1<T1, R>>): OutFunction1<T1, R>; | ||
export declare function compose<T1, T2, R>(middleware: Array<Middleware2<T1, T2, R>>): OutFunction2<T1, T2, R>; | ||
export declare function compose<T1, T2, T3, R>(middleware: Array<Middleware3<T1, T2, T3, R>>): OutFunction3<T1, T2, T3, R>; | ||
export declare function compose<T1, T2, T3, T4, R>(middleware: Array<Middleware4<T1, T2, T3, T4, R>>): OutFunction4<T1, T2, T3, T4, R>; | ||
export declare function compose<T1, T2, T3, T4, T5, R>(middleware: Array<Middleware5<T1, T2, T3, T4, T5, R>>): OutFunction5<T1, T2, T3, T4, T5, R>; |
"use strict"; | ||
var Promise = require('any-promise'); | ||
function compose(middleware) { | ||
@@ -16,3 +15,3 @@ if (!Array.isArray(middleware)) { | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
args[_i - 0] = arguments[_i]; | ||
args[_i] = arguments[_i]; | ||
} | ||
@@ -32,4 +31,4 @@ var index = -1; | ||
return resolve(fn.apply(void 0, args.concat([function next() { | ||
return dispatch(pos + 1); | ||
}]))); | ||
return dispatch(pos + 1); | ||
}]))); | ||
}); | ||
@@ -36,0 +35,0 @@ } |
"use strict"; | ||
var test = require('blue-tape'); | ||
var Promise = require('any-promise'); | ||
var index_1 = require('./index'); | ||
var test = require("blue-tape"); | ||
var index_1 = require("./index"); | ||
test('async middleware', function (t) { | ||
@@ -40,3 +39,3 @@ t.test('middleware', function (t) { | ||
arr.push(1); | ||
return next().catch(function (err) { | ||
return next().catch(function () { | ||
arr.push(3); | ||
@@ -61,11 +60,7 @@ }); | ||
t.test('throw when input is not an array', function (t) { | ||
t.throws(function () { | ||
index_1.compose('test'); | ||
}, 'Expected middleware to be an array, got string'); | ||
t.throws(function () { return index_1.compose('test'); }, 'Expected middleware to be an array, got string'); | ||
t.end(); | ||
}); | ||
t.test('throw when values are not functions', function (t) { | ||
t.throws(function () { | ||
index_1.compose([1, 2, 3]); | ||
}, 'Expected middleware to contain functions, got number'); | ||
t.throws(function () { return index_1.compose([1, 2, 3]); }, 'Expected middleware to contain functions, got number'); | ||
t.end(); | ||
@@ -75,5 +70,3 @@ }); | ||
var fn = index_1.compose([]); | ||
t.throws(function () { | ||
fn(true); | ||
}, 'Expected the last argument to be `next()`, got boolean'); | ||
t.throws(function () { return fn(true); }, 'Expected the last argument to be `next()`, got boolean'); | ||
t.end(); | ||
@@ -80,0 +73,0 @@ }); |
{ | ||
"name": "throwback", | ||
"version": "1.1.1", | ||
"version": "2.0.0", | ||
"description": "An asynchronous middleware pattern", | ||
@@ -13,3 +13,3 @@ "main": "dist/index.js", | ||
"scripts": { | ||
"lint": "# TODO", | ||
"lint": "tslint \"src/**/*.ts\"", | ||
"build": "rm -rf dist && tsc", | ||
@@ -44,3 +44,3 @@ "test-spec": "blue-tape 'dist/**/*.spec.js' | tap-spec", | ||
"devDependencies": { | ||
"blue-tape": "^0.2.0", | ||
"blue-tape": "^1.0.0", | ||
"bluebird": "^3.3.5", | ||
@@ -50,8 +50,7 @@ "chai": "^3.2.0", | ||
"tap-spec": "^4.1.1", | ||
"typescript": "^1.5.3", | ||
"typings": "^1.3.0" | ||
}, | ||
"dependencies": { | ||
"any-promise": "^1.3.0" | ||
"tslint": "^4.3.1", | ||
"tslint-config-standard": "^2.0.0", | ||
"typescript": "^2.0.3", | ||
"typings": "^2.1.0" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
Found 1 instance in 1 package
20781
0
9
144
0
67
9
- Removedany-promise@^1.3.0
- Removedany-promise@1.3.0(transitive)