UNPKG

dino-express

Version:

DinO enabled REST framework based on express

65 lines (64 loc) 2.68 kB
import { type ApplicationContext, type EnvironmentConfiguration } from 'dino-core'; import { type NextFunction } from 'express'; import { type OpenAPI } from 'openapi-types'; import { type EventProducerInterface } from './events/EventProducerInterface'; import { type Response, type ResponsePayload } from './Response'; import { type DinoExpressRequest, type ResponseValidator } from './Types'; /** * Handles the route subject to the client request, it does act as a express middleware. * */ export declare class RouteHandler { private readonly path; private readonly serverType; private readonly responseValidator; private readonly applicationContext; private readonly requestBodyParser; protected readonly api: OpenAPI.Operation<object>; protected readonly environment: EnvironmentConfiguration; protected readonly eventProducer: EventProducerInterface; protected requestHandler: any; constructor(path: string, api: OpenAPI.Operation<object>, applicationContext: ApplicationContext, responseValidator: ResponseValidator, environment: EnvironmentConfiguration, eventProducer: EventProducerInterface); /** * Handle the request from the client forwarding the request to the Interface that implement the * method defined on the API operation identifier. * * @param {any} req the express request object * @param {any} res the express response object * @param {Function} next a callback to propagate the handling action to the next middleware. * * @public */ handle(req: DinoExpressRequest, res: Response, next: NextFunction): void; protected doHandleRequest(req: DinoExpressRequest, requestHandler: any): any; /** * Collect the parameters defined as part of the OpenAPI definition. * @param {Object} req the express request */ private collectParameters; protected handleApiResponse(answer: ResponsePayload | Promise<ResponsePayload>, res: Response, next: NextFunction): Promise<void>; private handleError; private sendResponse; private normaliseResponse; /** * * @param method the request method * @deprecated use getHandler */ protected ensureInterface(method: string): Promise<any>; /** * Lookup the handler for the current API request defined either by method or operationId . * @returns {Interface} * * @private */ protected getHandler(method: string): Promise<any>; private validateOperationId; /** * Define tge scope as transient so that a new instance will be created for every request * * @static * @public */ static scope(): string; }