arrow-express
Advanced tools
Comparing version 1.1.1 to 1.2.0
@@ -24,3 +24,3 @@ import Express from "express"; | ||
*/ | ||
registerController(controller: ControllerConfiguration): AppConfigurator; | ||
registerController(controller: ControllerConfiguration<any>): AppConfigurator; | ||
/** | ||
@@ -30,3 +30,3 @@ * Register list of controllers in application. | ||
*/ | ||
registerControllers(...controllers: ControllerConfiguration[]): AppConfigurator; | ||
registerControllers(...controllers: ControllerConfiguration<any>[]): AppConfigurator; | ||
private printExpressConfig; | ||
@@ -33,0 +33,0 @@ private startControllers; |
import Express from "express"; | ||
export type RouteHandler<C = unknown> = (request: Express.Request, response: Express.Response, context?: C) => unknown; | ||
export type RouteHandler<C = unknown, R = unknown> = (request: Express.Request, response: Express.Response, context?: C) => R | Promise<R>; | ||
export type HttpMethod = "get" | "post" | "head" | "put" | "delete" | "options" | "patch"; | ||
export declare class RouteConfigurator<C = unknown> { | ||
export declare class RouteConfigurator<C = unknown, R = unknown> { | ||
private _method; | ||
@@ -22,3 +22,3 @@ private _path; | ||
*/ | ||
handler(handler: RouteHandler<C>): this; | ||
handler(handler: RouteHandler<C, R>): this; | ||
getMethod(): string; | ||
@@ -30,4 +30,4 @@ getPath(): string; | ||
*/ | ||
getRequestHandler(): RouteHandler<C>; | ||
getRequestHandler(): RouteHandler<C, R>; | ||
} | ||
export declare function Route<C>(): RouteConfigurator<C>; | ||
export declare function Route<C, R>(): RouteConfigurator<C, R>; |
import Express from "express"; | ||
import { ControllerConfiguration } from "../controller/controller"; | ||
import { RouteHandler, RouteConfigurator } from "../route/route"; | ||
import { RouteConfigurator } from "../route/route"; | ||
import { RequestError } from "../error/request.error"; | ||
@@ -10,3 +10,3 @@ import { ConfigurationError } from "../error/configuration.error"; | ||
private readonly _express: Express.Application; | ||
private readonly _controllers: ControllerConfiguration[] = []; | ||
private readonly _controllers: ControllerConfiguration<any>[] = []; | ||
private readonly logRequests: boolean; | ||
@@ -47,3 +47,3 @@ private _configured: boolean; | ||
*/ | ||
registerController(controller: ControllerConfiguration): AppConfigurator { | ||
registerController(controller: ControllerConfiguration<any>): AppConfigurator { | ||
this._controllers.push(controller); | ||
@@ -57,3 +57,3 @@ return this; | ||
*/ | ||
registerControllers(...controllers: ControllerConfiguration[]): AppConfigurator { | ||
registerControllers(...controllers: ControllerConfiguration<any>[]): AppConfigurator { | ||
controllers.forEach(controller => this.registerController(controller)); | ||
@@ -60,0 +60,0 @@ return this; |
import Express from "express"; | ||
export type RouteHandler<C = unknown> = (request: Express.Request, response: Express.Response, context?: C) => unknown; | ||
export type RouteHandler<C = unknown, R = unknown> = ( | ||
request: Express.Request, | ||
response: Express.Response, | ||
context?: C | ||
) => R | Promise<R>; | ||
export type HttpMethod = "get" | "post" | "head" | "put" | "delete" | "options" | "patch"; | ||
export class RouteConfigurator<C = unknown> { | ||
export class RouteConfigurator<C = unknown, R = unknown> { | ||
private _method: HttpMethod; | ||
private _path: string; | ||
private _handler: RouteHandler<C>; | ||
private _handler: RouteHandler<C, R>; | ||
@@ -33,3 +37,3 @@ /** | ||
*/ | ||
handler(handler: RouteHandler<C>): this { | ||
handler(handler: RouteHandler<C, R>): this { | ||
this._handler = handler; | ||
@@ -51,3 +55,3 @@ return this; | ||
*/ | ||
getRequestHandler(): RouteHandler<C> { | ||
getRequestHandler(): RouteHandler<C, R> { | ||
return this._handler; | ||
@@ -57,4 +61,4 @@ } | ||
export function Route<C>(): RouteConfigurator<C> { | ||
return new RouteConfigurator<C>(); | ||
export function Route<C, R>(): RouteConfigurator<C, R> { | ||
return new RouteConfigurator<C, R>(); | ||
} |
{ | ||
"name": "arrow-express", | ||
"version": "1.1.1", | ||
"version": "1.2.0", | ||
"description": "Library to bootstrap express applications with zero configuration", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
792249
15735