import express from 'express' ; import { EndResult , JSONResult , RedirectResult , RenderResult , SendFileResult , SendResult , SendStatusResult , RenderResultCallback , SendFileResultCallback } from './results' ; import { OutgoingHttpHeaders } from 'http' ; interface HttpContext { req : express . Request ; res : express . Response ; } interface Context { req : express . Request ; res : express . Response ; inject < S > ( key ) : S ; } export class BaseController { context ? : Context ; get httpContext ( ) : HttpContext | undefined { console . warn ( 'BaseController#httpContext will be deprecated from v1.0.0. Please use BaseController#context.' ) ; if ( this . context == null ) return ; return { req : this . context . req , res : this . context . res } ; } get injector ( ) : ( ( key : string ) => any ) | undefined { console . warn ( 'BaseController#injector will be deprecated from v1.0.0. Please use BaseController#context.inject.' ) ; if ( this . context == null ) return ; return this . context . inject ; } set injector ( injector ) { console . warn ( 'BaseController#injector will be deprecated from v1.0.0. Please use BaseController#context.inject.' ) ; if ( this . context != null && injector != null ) { this . context . inject = injector ; } } inject < S > ( key ) { console . warn ( 'BaseController#inject will be deprecated from v1.0.0. Please use BaseController#context.inject.' ) ; if ( this . injector == null ) throw new Error ( 'Injector is not set.' ) ; return this . injector ( key ) ; } end < D > ( data , encoding ? , status ? , headers ? ) { return new EndResult ( data , encoding , status , headers ) ; } json < D > ( data , status ? , headers ? ) { return new JSONResult ( data , status , headers ) ; } redirect ( location , status ? , headers ? ) { return new RedirectResult ( location , status , headers ) ; } render < D > ( view , locals ? , callback ? , status ? , headers ? ) { return new RenderResult ( view , locals , callback , status , headers ) ; } sendFile ( filePath , options ? , callback ? , status ? , headers ? ) { return new SendFileResult ( filePath , options , callback , status , headers ) ; } send < D > ( data , status ? , headers ? ) { return new SendResult ( data , status , headers ) ; } sendStatus ( status , headers ? ) { return new SendStatusResult ( status , headers ) ; } }