@ark7/router
Advanced tools
Comparing version 1.0.3 to 1.0.5
@@ -10,2 +10,3 @@ import 'reflect-metadata'; | ||
} | ||
export declare function injectHandler(handler: string): (ctx: any, next: any) => Promise<void>; | ||
/** | ||
@@ -15,2 +16,3 @@ * Metadata injected to the A7Controller class. | ||
export declare class A7ControllerMetadata { | ||
private className; | ||
/** Global middlewares applied to all the handlers. */ | ||
@@ -22,3 +24,3 @@ private middlewares; | ||
private routerOptions; | ||
constructor( | ||
constructor(className: string, | ||
/** Global middlewares applied to all the handlers. */ | ||
@@ -25,0 +27,0 @@ middlewares?: Router.IMiddleware[], |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.METADATA_KEY = exports.A7ControllerSubsidiary = exports.A7ControllerSubsidiaryType = exports.A7ControllerMetadata = exports.Method = void 0; | ||
exports.METADATA_KEY = exports.A7ControllerSubsidiary = exports.A7ControllerSubsidiaryType = exports.A7ControllerMetadata = exports.injectHandler = exports.Method = void 0; | ||
require("reflect-metadata"); | ||
@@ -15,2 +15,9 @@ const _ = require("underscore"); | ||
})(Method = exports.Method || (exports.Method = {})); | ||
function injectHandler(handler) { | ||
return async (ctx, next) => { | ||
ctx.handler = handler; | ||
await next(); | ||
}; | ||
} | ||
exports.injectHandler = injectHandler; | ||
/** | ||
@@ -20,3 +27,3 @@ * Metadata injected to the A7Controller class. | ||
class A7ControllerMetadata { | ||
constructor( | ||
constructor(className, | ||
/** Global middlewares applied to all the handlers. */ | ||
@@ -28,2 +35,3 @@ middlewares = [], | ||
routerOptions = {}) { | ||
this.className = className; | ||
this.middlewares = middlewares; | ||
@@ -35,3 +43,3 @@ this.subsidiaries = subsidiaries; | ||
var _a; | ||
return (_a = Reflect.getMetadata(exports.METADATA_KEY, cls)) !== null && _a !== void 0 ? _a : new A7ControllerMetadata(); | ||
return ((_a = Reflect.getMetadata(exports.METADATA_KEY, cls)) !== null && _a !== void 0 ? _a : new A7ControllerMetadata(cls.name)); | ||
} | ||
@@ -47,3 +55,6 @@ koaRouter(controller) { | ||
if (subsidiary.path != null) { | ||
koaRouter[subsidiary.method](subsidiary.name, subsidiary.path, subsidiary.composedMiddleware.bind(controller)); | ||
koaRouter[subsidiary.method](subsidiary.name, subsidiary.path, utils_1.compose([ | ||
injectHandler(`${this.className}.${subsidiary.name}`), | ||
subsidiary.composedMiddleware, | ||
]).bind(controller)); | ||
} | ||
@@ -79,3 +90,3 @@ break; | ||
clone() { | ||
return new A7ControllerMetadata(_.clone(this.middlewares), _.clone(this.subsidiaries), _.clone(this.routerOptions)); | ||
return new A7ControllerMetadata(this.className, _.clone(this.middlewares), _.clone(this.subsidiaries), _.clone(this.routerOptions)); | ||
} | ||
@@ -82,0 +93,0 @@ getSubsidiaryByName(name) { |
{ | ||
"name": "@ark7/router", | ||
"version": "1.0.3", | ||
"version": "1.0.5", | ||
"description": "Ark7 Router layer framework.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
91982
694