feat: complate @ccms/web package
Signed-off-by: MiaoWoo <admin@yumc.pw>
This commit is contained in:
27
packages/web/src/decorators/utils.ts
Normal file
27
packages/web/src/decorators/utils.ts
Normal 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])
|
||||
}
|
||||
Reference in New Issue
Block a user