From bb00e1b207b6657b972cca4683977f442ab88ced Mon Sep 17 00:00:00 2001 From: Aleksandr Date: Sat, 6 Jul 2024 21:39:28 +0300 Subject: [PATCH] add `use` method --- src/handler.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/handler.ts b/src/handler.ts index 51b7493..d7d44d2 100644 --- a/src/handler.ts +++ b/src/handler.ts @@ -2,6 +2,7 @@ import { ControlFlow, Break, Continue } from "./control_flow" // Typescript lacks shadowing, so code sometimes can be stupid to avoid it +type Mapper = (inp: Handler) => Handler export type HandlerFn = (req: C, next: Endpoint) => Promise> export type InputHandler = HandlerFn | Handler @@ -35,6 +36,10 @@ export class Handler { this.fn = fn } + use(f: Mapper): Handler { + return f(this) + } + then(next: InputHandler): Handler { return new Handler(then(this, next)) }