arrow-express
Advanced tools
Comparing version 2.0.0 to 2.1.0
import { RouteConfigurator } from "../route/route"; | ||
import Express from "express"; | ||
export type ControllerHandler<C = undefined, R = undefined> = (request: Express.Request, response: Express.Response, rootContext?: R) => Promise<C>; | ||
export declare class ControllerConfiguration<C = undefined, R = undefined> { | ||
export type ControllerHandler<Context = undefined, RootContext = undefined> = (request: Express.Request, response: Express.Response, rootContext?: RootContext) => Promise<Context>; | ||
export declare class ControllerConfiguration<Context = undefined, RootContext = undefined> { | ||
private _prefix; | ||
@@ -13,3 +13,3 @@ private _controllers; | ||
*/ | ||
registerController(controller: ControllerConfiguration<any, C>): this; | ||
registerController(controller: ControllerConfiguration<any, Context>): this; | ||
/** | ||
@@ -24,3 +24,3 @@ * Register array of controllers in controller | ||
*/ | ||
registerRoute(route: RouteConfigurator<C>): this; | ||
registerRoute(route: RouteConfigurator<Context, any>): this; | ||
/** | ||
@@ -30,3 +30,3 @@ * Register array of routes in controller | ||
*/ | ||
registerRoutes(...routes: RouteConfigurator<C, R>[]): this; | ||
registerRoutes(...routes: RouteConfigurator<Context, any>[]): this; | ||
/** | ||
@@ -41,8 +41,8 @@ * Register controller prefix which will be used by all routes | ||
*/ | ||
handler<NewContext>(handler: ControllerHandler<NewContext, R>): ControllerConfiguration<NewContext, R>; | ||
handler<NewContext>(handler: ControllerHandler<NewContext, RootContext>): ControllerConfiguration<NewContext, RootContext>; | ||
getPrefix(): string; | ||
getRoutes(): RouteConfigurator<C>[]; | ||
getControllers(): ControllerConfiguration<any, C>[]; | ||
getHandler(): ControllerHandler<C, R> | undefined; | ||
getRoutes(): RouteConfigurator<Context>[]; | ||
getControllers(): ControllerConfiguration<any, Context>[]; | ||
getHandler(): ControllerHandler<Context, RootContext> | undefined; | ||
} | ||
export declare function Controller<C = undefined, R = undefined>(): ControllerConfiguration<C, R>; |
import Express from "express"; | ||
export type RouteHandler<C = undefined, R = undefined> = (request: Express.Request, response: Express.Response, context: C) => R | Promise<R>; | ||
export type RouteHandler<RootContext = undefined, Response = undefined> = (request: Express.Request, response: Express.Response, context: RootContext) => Response | Promise<Response>; | ||
export type HttpMethod = "get" | "post" | "head" | "put" | "delete" | "options" | "patch"; | ||
export declare class RouteConfigurator<C = undefined, R = undefined> { | ||
export declare class RouteConfigurator<RootContext = undefined, Response = undefined> { | ||
private _method; | ||
@@ -22,3 +22,3 @@ private _path; | ||
*/ | ||
handler(handler: RouteHandler<C, R>): this; | ||
handler(handler: RouteHandler<RootContext, Response>): this; | ||
getMethod(): string; | ||
@@ -30,4 +30,4 @@ getPath(): string; | ||
*/ | ||
getRequestHandler(): RouteHandler<C, R>; | ||
getRequestHandler(): RouteHandler<RootContext, Response>; | ||
} | ||
export declare function Route<C = undefined, R = undefined>(): RouteConfigurator<C, R>; |
@@ -7,4 +7,4 @@ import { Route, RouteConfigurator } from "arrow-express"; | ||
export function GetMyselfRoute(userService: UserService): RouteConfigurator<UserContext> { | ||
return Route<UserContext>() | ||
export function GetMyselfRoute(userService: UserService): RouteConfigurator<UserContext, User> { | ||
return Route<UserContext, User>() | ||
.method("get") | ||
@@ -11,0 +11,0 @@ .path("myself") |
@@ -7,4 +7,4 @@ import { Route, RouteConfigurator } from "arrow-express"; | ||
export function GetUserByIdRoute(userService: UserService): RouteConfigurator<UserContext> { | ||
return Route<UserContext>() | ||
export function GetUserByIdRoute(userService: UserService): RouteConfigurator<UserContext, User> { | ||
return Route<UserContext, User>() | ||
.method("get") | ||
@@ -11,0 +11,0 @@ .path(":id") |
import { RouteConfigurator } from "../route/route"; | ||
import Express from "express"; | ||
export type ControllerHandler<C = undefined, R = undefined> = ( | ||
export type ControllerHandler<Context = undefined, RootContext = undefined> = ( | ||
request: Express.Request, | ||
response: Express.Response, | ||
rootContext?: R | ||
) => Promise<C>; | ||
rootContext?: RootContext | ||
) => Promise<Context>; | ||
export class ControllerConfiguration<C = undefined, R = undefined> { | ||
export class ControllerConfiguration<Context = undefined, RootContext = undefined> { | ||
private _prefix = ""; | ||
private _controllers: ControllerConfiguration<unknown, C>[] = []; | ||
private _routes: RouteConfigurator<C>[] = []; | ||
private _handler: ControllerHandler<C, R> | undefined; | ||
private _controllers: ControllerConfiguration<unknown, Context>[] = []; | ||
private _routes: RouteConfigurator<Context>[] = []; | ||
private _handler: ControllerHandler<Context, RootContext> | undefined; | ||
@@ -20,3 +20,3 @@ /** | ||
*/ | ||
registerController(controller: ControllerConfiguration<any, C>): this { | ||
registerController(controller: ControllerConfiguration<any, Context>): this { | ||
this._controllers.push(controller); | ||
@@ -39,3 +39,3 @@ return this; | ||
*/ | ||
registerRoute(route: RouteConfigurator<C>): this { | ||
registerRoute(route: RouteConfigurator<Context, any>): this { | ||
this._routes.push(route); | ||
@@ -49,3 +49,3 @@ return this; | ||
*/ | ||
registerRoutes(...routes: RouteConfigurator<C, R>[]): this { | ||
registerRoutes(...routes: RouteConfigurator<Context, any>[]): this { | ||
routes.forEach(this.registerRoute.bind(this)); | ||
@@ -67,5 +67,7 @@ return this; | ||
*/ | ||
handler<NewContext>(handler: ControllerHandler<NewContext, R>): ControllerConfiguration<NewContext, R> { | ||
this._handler = handler as unknown as ControllerHandler<C, R>; | ||
return this as unknown as ControllerConfiguration<NewContext, R>; | ||
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>; | ||
} | ||
@@ -77,11 +79,11 @@ | ||
getRoutes(): RouteConfigurator<C>[] { | ||
getRoutes(): RouteConfigurator<Context>[] { | ||
return this._routes; | ||
} | ||
getControllers(): ControllerConfiguration<any, C>[] { | ||
getControllers(): ControllerConfiguration<any, Context>[] { | ||
return this._controllers; | ||
} | ||
getHandler(): ControllerHandler<C, R> | undefined { | ||
getHandler(): ControllerHandler<Context, RootContext> | undefined { | ||
return this._handler; | ||
@@ -88,0 +90,0 @@ } |
import Express from "express"; | ||
export type RouteHandler<C = undefined, R = undefined> = ( | ||
export type RouteHandler<RootContext = undefined, Response = undefined> = ( | ||
request: Express.Request, | ||
response: Express.Response, | ||
context: C | ||
) => R | Promise<R>; | ||
context: RootContext | ||
) => Response | Promise<Response>; | ||
export type HttpMethod = "get" | "post" | "head" | "put" | "delete" | "options" | "patch"; | ||
export class RouteConfigurator<C = undefined, R = undefined> { | ||
export class RouteConfigurator<RootContext = undefined, Response = undefined> { | ||
private _method: HttpMethod; | ||
private _path: string; | ||
private _handler: RouteHandler<C, R>; | ||
private _handler: RouteHandler<RootContext, Response>; | ||
@@ -37,3 +37,3 @@ /** | ||
*/ | ||
handler(handler: RouteHandler<C, R>): this { | ||
handler(handler: RouteHandler<RootContext, Response>): this { | ||
this._handler = handler; | ||
@@ -55,3 +55,3 @@ return this; | ||
*/ | ||
getRequestHandler(): RouteHandler<C, R> { | ||
getRequestHandler(): RouteHandler<RootContext, Response> { | ||
return this._handler; | ||
@@ -58,0 +58,0 @@ } |
{ | ||
"name": "arrow-express", | ||
"version": "2.0.0", | ||
"version": "2.1.0", | ||
"description": "Library to bootstrap express applications with zero configuration", | ||
@@ -10,2 +10,9 @@ "main": "dist/index.js", | ||
}, | ||
"scripts": { | ||
"build": "tsc --declaration --project tsconfig.json", | ||
"test": "jest", | ||
"test:watch": "jest --watch", | ||
"test:coverage": "jest --coverage", | ||
"lint": "./node_modules/.bin/eslint ." | ||
}, | ||
"repository": { | ||
@@ -45,10 +52,3 @@ "type": "git", | ||
}, | ||
"homepage": "https://github.com/Mighty683/arrow-express#readme", | ||
"scripts": { | ||
"build": "tsc --declaration --project tsconfig.json", | ||
"test": "jest", | ||
"test:watch": "jest --watch", | ||
"test:coverage": "jest --coverage", | ||
"lint": "./node_modules/.bin/eslint ." | ||
} | ||
} | ||
"homepage": "https://github.com/Mighty683/arrow-express#readme" | ||
} |
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
796435
15800