import {ConstructorType, PojoType} from "../../../type/type" import {IComponent, IController, IDao, IResource, IService} from "../../../type/interface" import DecorateRegistCenter from "../../DecorateRegistCenter" import ControllerComponent from '../../../type/impl/component/ControllerComponent' import ResourceMapping from "../../../type/impl/component/ResourceMapping" import ServiceComponent from "../../../type/impl/component/ServiceComponent" import NormalComponent from '../../../type/impl/component/NormalComponent' import DaoComponent from "../../../type/impl/component/DaoComponent" import {ComponentScopes} from "../../../enum" import Scoper from "../../../type/impl/component/Scoper" export function Component(name?: string): Function{ return function(constructor: ConstructorType): void{ const option: IComponent = new NormalComponent({ name, cost: constructor }) DecorateRegistCenter.registComponents(option) } } export function Controller(route: string): Function{ return function(constructor: ConstructorType): void{ const option: IController = new ControllerComponent({ route, cost: constructor }) DecorateRegistCenter.registComponents(option) } } export function Service(name?: string): Function{ return function(constructor: ConstructorType): void{ const option: IService = new ServiceComponent({ name, cost: constructor }) DecorateRegistCenter.registComponents(option) } } export function Dao(name?: string): Function{ return function(constructor: ConstructorType): void{ const option: IDao = new DaoComponent({ name, cost: constructor }) DecorateRegistCenter.registComponents(option) } } export function Resource(mappingName: string): Function{ return function(prototype: any, propName: string): void{ const option: IResource = new ResourceMapping({ mappingName, propName, caller: (typeof prototype === 'object') ? prototype.constructor : prototype }) DecorateRegistCenter.registResourceMappings(option) } } export function Scope(scope: ComponentScopes = ComponentScopes.SINGLETON): Function{ return function(constructor: ConstructorType): void{ DecorateRegistCenter.registScopes(new Scoper(constructor, scope)) } } export function UnEnum(target: PojoType, name: string): void{ if(target && name){ const description = Object.getOwnPropertyDescriptor(target, name) const newDescription = Object.assign({}, description, { enumable: false }) Object.defineProperty(target, name, newDescription) } }