dino-express
Version:
DinO enabled REST framework based on express
59 lines (58 loc) • 2.38 kB
TypeScript
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 serverType;
private readonly path;
private readonly api;
private readonly responseValidator;
private readonly applicationContext;
private readonly environment;
private readonly requestBodyParser;
protected readonly eventProducer: EventProducerInterface;
private _interface;
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;
_doHandleRequest(req: DinoExpressRequest): 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;
/**
* Lookup the interface that can handle the defined operationId for the API.
* @returns {Interface}
*
* @private
*/
private ensureInterface;
private validateOperationId;
/**
* Define tge scope as transient so that a new instance will be created for every request
*
* @static
* @public
*/
static scope(): string;
}