arrow-express
Advanced tools
Comparing version 2.1.5 to 2.1.6
import { RouteConfigurator } from "../route/route"; | ||
import Express from "express"; | ||
export type ControllerHandler<Context = unknown, RootContext = unknown> = (request: Express.Request, response: Express.Response, rootContext?: RootContext) => Promise<Context>; | ||
export declare class ControllerConfiguration<Context = unknown, RootContext = unknown> { | ||
export declare class ControllerConfiguration<C = unknown, R = unknown> { | ||
private _prefix; | ||
@@ -13,3 +13,3 @@ private _controllers; | ||
*/ | ||
registerController(controller: ControllerConfiguration<any, Context>): this; | ||
registerController(controller: ControllerConfiguration<any, GetFinalControllerContext<C, R>>): this; | ||
/** | ||
@@ -19,3 +19,3 @@ * Register array of controllers in controller | ||
*/ | ||
registerControllers(...controllers: ControllerConfiguration<any, Context>[]): this; | ||
registerControllers(...controllers: ControllerConfiguration<any, GetFinalControllerContext<C, R>>[]): this; | ||
/** | ||
@@ -25,3 +25,3 @@ * Register route in controller | ||
*/ | ||
registerRoute(route: RouteConfigurator<Context, any>): this; | ||
registerRoute(route: RouteConfigurator<GetFinalControllerContext<C, R>, any>): this; | ||
/** | ||
@@ -31,3 +31,3 @@ * Register array of routes in controller | ||
*/ | ||
registerRoutes(...routes: RouteConfigurator<Context, any>[]): this; | ||
registerRoutes(...routes: RouteConfigurator<C, any>[]): this; | ||
/** | ||
@@ -42,8 +42,10 @@ * Register controller prefix which will be used by all routes | ||
*/ | ||
handler<NewContext>(handler: ControllerHandler<NewContext, RootContext>): ControllerConfiguration<NewContext, RootContext>; | ||
handler<NewContext>(handler: ControllerHandler<NewContext, R>): ControllerConfiguration<NewContext, R>; | ||
getPrefix(): string; | ||
getRoutes(): RouteConfigurator<Context>[]; | ||
getControllers(): ControllerConfiguration<any, Context>[]; | ||
getHandler(): ControllerHandler<Context, RootContext> | undefined; | ||
getRoutes(): RouteConfigurator<GetFinalControllerContext<C, R>>[]; | ||
getControllers(): ControllerConfiguration<any, GetFinalControllerContext<C, R>>[]; | ||
getHandler(): ControllerHandler<GetFinalControllerContext<C, R>, R> | undefined; | ||
} | ||
export declare function Controller<C = unknown, R = unknown>(): ControllerConfiguration<C, R>; | ||
export declare function Controller<C = unknown, R = unknown>(): ControllerConfiguration<GetFinalControllerContext<C, R>, R>; | ||
type GetFinalControllerContext<Context, RootContext> = Context extends unknown ? RootContext : Context; | ||
export {}; |
@@ -9,8 +9,7 @@ import { RouteConfigurator } from "../route/route"; | ||
) => Promise<Context>; | ||
export class ControllerConfiguration<Context = unknown, RootContext = unknown> { | ||
export class ControllerConfiguration<C = unknown, R = unknown> { | ||
private _prefix = ""; | ||
private _controllers: ControllerConfiguration<any, Context>[] = []; | ||
private _routes: RouteConfigurator<Context>[] = []; | ||
private _handler: ControllerHandler<Context, RootContext> | undefined; | ||
private _controllers: ControllerConfiguration<any, GetFinalControllerContext<C, R>>[] = []; | ||
private _routes: RouteConfigurator<GetFinalControllerContext<C, R>>[] = []; | ||
private _handler: ControllerHandler<GetFinalControllerContext<C, R>, R> | undefined; | ||
@@ -21,3 +20,3 @@ /** | ||
*/ | ||
registerController(controller: ControllerConfiguration<any, Context>): this { | ||
registerController(controller: ControllerConfiguration<any, GetFinalControllerContext<C, R>>): this { | ||
this._controllers.push(controller); | ||
@@ -31,3 +30,3 @@ return this; | ||
*/ | ||
registerControllers(...controllers: ControllerConfiguration<any, Context>[]): this { | ||
registerControllers(...controllers: ControllerConfiguration<any, GetFinalControllerContext<C, R>>[]): this { | ||
controllers.forEach(this.registerController.bind(this)); | ||
@@ -41,3 +40,3 @@ return this; | ||
*/ | ||
registerRoute(route: RouteConfigurator<Context, any>): this { | ||
registerRoute(route: RouteConfigurator<GetFinalControllerContext<C, R>, any>): this { | ||
this._routes.push(route); | ||
@@ -51,3 +50,3 @@ return this; | ||
*/ | ||
registerRoutes(...routes: RouteConfigurator<Context, any>[]): this { | ||
registerRoutes(...routes: RouteConfigurator<C, any>[]): this { | ||
routes.forEach(this.registerRoute.bind(this)); | ||
@@ -69,7 +68,5 @@ return this; | ||
*/ | ||
handler<NewContext>( | ||
handler: ControllerHandler<NewContext, RootContext> | ||
): ControllerConfiguration<NewContext, RootContext> { | ||
this._handler = handler as unknown as ControllerHandler<Context, RootContext>; | ||
return this as unknown as ControllerConfiguration<NewContext, RootContext>; | ||
handler<NewContext>(handler: ControllerHandler<NewContext, R>): ControllerConfiguration<NewContext, R> { | ||
this._handler = handler as unknown as ControllerHandler<GetFinalControllerContext<C, R>, R>; | ||
return this as unknown as ControllerConfiguration<NewContext, R>; | ||
} | ||
@@ -81,11 +78,11 @@ | ||
getRoutes(): RouteConfigurator<Context>[] { | ||
getRoutes(): RouteConfigurator<GetFinalControllerContext<C, R>>[] { | ||
return this._routes; | ||
} | ||
getControllers(): ControllerConfiguration<any, Context>[] { | ||
getControllers(): ControllerConfiguration<any, GetFinalControllerContext<C, R>>[] { | ||
return this._controllers; | ||
} | ||
getHandler(): ControllerHandler<Context, RootContext> | undefined { | ||
getHandler(): ControllerHandler<GetFinalControllerContext<C, R>, R> | undefined { | ||
return this._handler; | ||
@@ -95,4 +92,6 @@ } | ||
export function Controller<C = unknown, R = unknown>(): ControllerConfiguration<C, R> { | ||
return new ControllerConfiguration<C, R>(); | ||
export function Controller<C = unknown, R = unknown>(): ControllerConfiguration<GetFinalControllerContext<C, R>, R> { | ||
return new ControllerConfiguration<GetFinalControllerContext<C, R>, R>(); | ||
} | ||
type GetFinalControllerContext<Context, RootContext> = Context extends unknown ? RootContext : Context; |
{ | ||
"name": "arrow-express", | ||
"version": "2.1.5", | ||
"version": "2.1.6", | ||
"description": "Library to bootstrap express applications with zero configuration", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
799892
15827