@hattip/compose
Advanced tools
Comparing version 0.0.5 to 0.0.6
@@ -21,4 +21,6 @@ import { AdapterRequestContext, HattipHandler } from '@hattip/core'; | ||
declare type RequestHandlerStack = MaybeRequestHandler | RequestHandlerStack[]; | ||
declare type PartialHandler = (context: RequestContext) => Response | void | Promise<Response | void>; | ||
declare function composePartial(handlers: RequestHandlerStack[], next?: () => Promise<Response>): PartialHandler; | ||
declare function compose(...handlers: RequestHandlerStack[]): HattipHandler; | ||
export { MaybeAsyncResponse, MaybeRequestHandler, MaybeRespone, RequestContext, RequestHandler, RequestHandlerStack, ResponseConvertible, ResponseLike, compose }; | ||
export { MaybeAsyncResponse, MaybeRequestHandler, MaybeRespone, PartialHandler, RequestContext, RequestHandler, RequestHandlerStack, ResponseConvertible, ResponseLike, compose, composePartial }; |
@@ -23,3 +23,4 @@ "use strict"; | ||
__export(src_exports, { | ||
compose: () => compose | ||
compose: () => compose, | ||
composePartial: () => composePartial | ||
}); | ||
@@ -31,3 +32,3 @@ module.exports = __toCommonJS(src_exports); | ||
} | ||
function compose(...handlers) { | ||
function composePartial(handlers, next) { | ||
const flatHandlers = handlers.flat().filter(Boolean); | ||
@@ -46,4 +47,7 @@ flatHandlers.unshift((context) => { | ||
}; | ||
}, finalHandler); | ||
}, next ? (_) => next() : (_) => void 0); | ||
} | ||
function compose(...handlers) { | ||
return composePartial([...handlers, finalHandler]); | ||
} | ||
function wrap(handler) { | ||
@@ -76,3 +80,4 @@ return async (context) => { | ||
0 && (module.exports = { | ||
compose | ||
compose, | ||
composePartial | ||
}); |
{ | ||
"name": "@hattip/compose", | ||
"version": "0.0.5", | ||
"description": "Middleware system for HatTip", | ||
"version": "0.0.6", | ||
"files": [ | ||
@@ -19,3 +20,3 @@ "dist", | ||
"@cyco130/eslint-config": "^2.0.0", | ||
"@hattip/core": "0.0.5", | ||
"@hattip/core": "0.0.6", | ||
"eslint": "^8.18.0", | ||
@@ -26,3 +27,3 @@ "node-fetch": "^3.2.6", | ||
"typescript": "^4.7.4", | ||
"vitest": "^0.15.2" | ||
"vitest": "^0.16.0" | ||
}, | ||
@@ -29,0 +30,0 @@ "scripts": { |
Sorry, the diff of this file is not supported yet
9734
156