import * as plugins from './typedrequest.plugins'; type THandlerFunction = ( requestArg: T['request'] ) => Promise; /** * typed handler for dealing with typed requests */ export class TypedHandler { public method: string; private handlerFunction: THandlerFunction; constructor(methodArg: T['method'], handlerFunctionArg: THandlerFunction) { this.method = methodArg; this.handlerFunction = handlerFunctionArg; } /** * adds a response to the typedRequest * @param typedRequestArg */ public async addResponse(typedRequestArg: T) { if (typedRequestArg.method !== this.method) { throw new Error( 'this handler has been given a wrong method to answer to. Please use a TypedRouter to filter requests' ); } const response = await this.handlerFunction(typedRequestArg.request); typedRequestArg.response = response; return typedRequestArg; } }