require ( 'source-map-support' ) . install ( ) ; import { IAppContainer , IDino } from '../modules/interfaces' ; import { DataUtility } from '../modules/utility' ; import { Errors } from '../modules/constants' ; import { RouteNotFoundMiddleware } from '../modules/builtin/middlewares' ; import { AppContainer } from '../modules/core' ; /**
 * Creates dino instance
 */ export class Dino implements IDino { private appContainer : IAppContainer ; private isBinded = false ; /**
     * app - ExpressApp
     * , baseUri - application mounted path
     */ constructor ( app , baseUri ) { this . appContainer = AppContainer . create ( app ) ; this . appContainer . baseUri = baseUri ; this . appContainer . routeNotFoundMiddleware = RouteNotFoundMiddleware ; } /**
     * Register API controller
     */ registerController < T > ( controller ) { this . appContainer . controllers . push ( controller ) ; } /**
     * Register RequestStart middleware
     */ requestStart < T > ( middleware ) { this . appContainer . startMiddleware . push ( middleware ) ; } /**
     * Register RequestEnd middleware
     */ requestEnd < T > ( middleware ) { this . appContainer . endMiddleware . push ( middleware ) ; } /**
     * Register ServerError middleware
     */ serverError < T > ( middleware ) { this . appContainer . errorMiddleware . push ( middleware ) ; } /**
     * Register ApplicationStart middleware
     */ applicationStart < T > ( middleware ) { this . appContainer . appStartMiddleware . push ( middleware ) ; } /**
     * Register ApplicationError controller
     */ registerApplicationError < T > ( type ) { this . appContainer . errorController = type ; } /**
     * Register express Router handler
     */ useRouter ( cb ) { this . appContainer . useRouter = cb ; } /**
     * RouteNotFoundMiddleware is unregistered
     */ disableRouteNotFoundException ( ) { this . appContainer . routeNotFoundMiddleware = undefined ; } /**
     * Reserved for future use
     */ enableUserIdentity ( ) { this . appContainer . enableTaskContext = true ; } /**
     * Configures Dino to use DIFramework
     */ dependencyResolver < T > ( injector , cb ) { this . appContainer . diContainer = injector ; this . appContainer . diResolveCallback = cb ; } Throws Throws Throws bind ( ) { if ( this . isBinded ) { throw new Error ( Errors . dinoAlreadyBinded ) ; } if ( DataUtility . isUndefinedOrNull ( this . appContainer . baseUri ) ) { throw new Error ( Errors . baseUriInvalid ) ; } if ( DataUtility . isUndefinedOrNull ( this . appContainer . useRouter ) ) { throw new Error ( Errors . routerNotRegistered ) ; } this . isBinded = true ; this . appContainer . build ( ) ; } }