@zenweb/controller
Version:
Zenweb Controller module
63 lines (62 loc) • 2.13 kB
TypeScript
import { Middleware } from '@zenweb/core';
import { RouterMethod, RouterPath } from '@zenweb/router';
import { ControllerOption, MappingItem } from './types.js';
export declare const mappingDecorator: {
wrap: (cb?: import("decorator-make").MethodDecoratorCallback<MappingItem> | undefined) => (target: Object, propertyKey: string | symbol, descriptor_or_paramtypes?: PropertyDescriptor | any[]) => void;
decorate: (target: Object, propertyKey: string | symbol, descriptor_or_paramtypes?: PropertyDescriptor | any[]) => void;
getMethods: (target: Object) => MappingItem[];
};
/**
* 路由映射
* 如果方法中存在参数,则自动注入
*
* @param arg0.method HTTP 方法,默认 GET
* @param arg0.path 路径,默认 /{方法名}
* @param arg0.middleware 中间件
* @param arg0.prefix 路径前缀,只有 `path` 为 `string` 才有效,正则则忽略
*
* #### 在 TypeScript 中使用
* ```ts
* class Target {
* \@mapping(opt?) someMethod(ctx: Context) {}
* }
* ```
*
* #### 在 JavaScript 中使用
* ```js
* class Target {
* someMethod(ctx) {}
* }
* mapping(opt?)(Target.prototype, 'someMethod', [Context]);
* ```
*/
export declare function mapping({ method, path, prefix, middleware, }?: {
method?: RouterMethod | RouterMethod[];
path?: RouterPath;
prefix?: string;
middleware?: Middleware | Middleware[];
}): (target: Object, propertyKey: string | symbol, descriptor_or_paramtypes?: PropertyDescriptor | any[]) => void;
export declare const controllerDecorator: {
wrap: (cb?: import("decorator-make").ClassDecoratorCallback<ControllerOption> | undefined) => (target: Object) => void;
decorate: (target: Object) => void;
getValue: (target: Object) => ControllerOption | undefined;
getParams: (target: Object) => unknown[];
};
/**
* 控制器选项
*
* #### 在 TypeScript 中使用
* ```ts
* \@controller(opt?)
* class Target {
* }
* ```
*
* #### 在 JavaScript 中使用
* ```js
* class Target {
* }
* controller(opt?)(Target);
* ```
*/
export declare function controller(opt: ControllerOption): (target: Object) => void;