feat: complate @ccms/web package

Signed-off-by: MiaoWoo <admin@yumc.pw>
This commit is contained in:
2020-06-30 16:02:39 +08:00
parent 0bc513d580
commit 36c9d4ad99
7 changed files with 327 additions and 56 deletions

View File

@@ -0,0 +1,27 @@
import { interfaces } from '../interfaces'
import { METADATA_KEY } from '../constants'
export function getControllerMetadatas(): interfaces.ControllerMetadata[] {
return Reflect.getMetadata(METADATA_KEY.Controller, Reflect) || []
}
export function addControllerMetadata(metadata: interfaces.ControllerMetadata) {
Reflect.defineMetadata(METADATA_KEY.Controller, [metadata, ...getControllerMetadatas()], Reflect)
}
export function getControllerActions(target: any): string[] {
return Reflect.getMetadata(METADATA_KEY.Action, target.constructor) || []
}
export function addControllerAction(target: any, propertyKey: string) {
Reflect.defineMetadata(METADATA_KEY.Action, [propertyKey, ...getControllerActions(target)], target.constructor)
}
export function getControllerMetadata(target: any): interfaces.ControllerMetadata {
return Reflect.getMetadata(METADATA_KEY.Controller, target)
}
export function getActionMetadata(target: any, propertyKey: string): interfaces.ActionMetadata {
return Reflect.getMetadata(METADATA_KEY.Action, target[propertyKey])
}
export function getActionParams(target: any, propertyKey: string): interfaces.ParamMetadata[] {
return Reflect.getMetadata(METADATA_KEY.Param, target[propertyKey]) || []
}
export function addActionParam(target: any, propertyKey: string, metadata: interfaces.ParamMetadata) {
Reflect.defineMetadata(METADATA_KEY.Param, [metadata, ...getActionParams(target, propertyKey)], target[propertyKey])
}