@zenweb/controller
Advanced tools
@@ -8,3 +8,4 @@ /// <reference types="koa__router" /> | ||
| middleware?: Router.Middleware[]; | ||
| handle: () => Promise<void> | void; | ||
| handle: (...args: any[]) => Promise<void> | void; | ||
| params: any[]; | ||
| } | ||
@@ -31,2 +32,3 @@ export declare class Controller { | ||
| * 路由映射 | ||
| * 如果方法中存在参数,则自动注入 | ||
| * @param method HTTP 方法 | ||
@@ -33,0 +35,0 @@ * @param path 路径。如不指定则使用方法名 |
@@ -44,2 +44,3 @@ "use strict"; | ||
| * 路由映射 | ||
| * 如果方法中存在参数,则自动注入 | ||
| * @param method HTTP 方法 | ||
@@ -51,2 +52,3 @@ * @param path 路径。如不指定则使用方法名 | ||
| return function (target, propertyKey, descriptor) { | ||
| const params = Reflect.getMetadata('design:paramtypes', target, propertyKey) || []; | ||
| addControllerMapping(target, { | ||
@@ -57,2 +59,3 @@ method, | ||
| handle: descriptor.value, | ||
| params, | ||
| }); | ||
@@ -89,3 +92,4 @@ }; | ||
| const controller = await ctx.injector.getInstance(target); | ||
| await item.handle.call(controller); | ||
| const args = await Promise.all(item.params.map(i => ctx.injector.getInstance(i))); | ||
| await item.handle.apply(controller, args); | ||
| }); | ||
@@ -92,0 +96,0 @@ } |
+2
-2
| { | ||
| "name": "@zenweb/controller", | ||
| "version": "3.0.1", | ||
| "version": "3.1.0", | ||
| "description": "Zenweb Controller module", | ||
@@ -28,3 +28,3 @@ "exports": "./dist/index.js", | ||
| "@zenweb/core": "^2.4.1", | ||
| "@zenweb/inject": "^1.0.0", | ||
| "@zenweb/inject": "^3.1.0", | ||
| "@zenweb/router": "^3.0.0" | ||
@@ -31,0 +31,0 @@ }, |
+2
-2
@@ -30,4 +30,4 @@ # zenweb controller | ||
| @mapping() | ||
| simple() { | ||
| this.ctx.body = 'simple'; | ||
| simple(ctx: Context) { // 也可以通过方法的参数自动注入 | ||
| ctx.body = 'simple'; | ||
| } | ||
@@ -34,0 +34,0 @@ |
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
8507
4.96%189
3.28%