ing
This commit is contained in:
parent
4992e39e3f
commit
14f3fa4b1e
|
@ -1,28 +1,30 @@
|
|||
import createDecorator from '@loafer/core/util/decorators/createDecorator';
|
||||
import ConfigurationDefinition from '@loafer/context/definition/ConfigurationDefinition';
|
||||
import { getInjectableDefinition } from '@loafer/pouches/util/metadata';
|
||||
import {
|
||||
PropertyType,
|
||||
} from '@loafer/core/constants/types';
|
||||
|
||||
import GetAppContext from '@loafer/context';
|
||||
import { InjectableSterotype } from '@loafer/pouches/constants';
|
||||
import DefaultPouchFactory from '@loafer/pouches/factory/implement/DefaultPouchFactory';
|
||||
import PouchDefinitionRegistry from '@loafer/pouches/factory/registry/PouchDefinitionRegistry';
|
||||
import { validateQualifier } from '@loafer/pouches/util/qualifier';
|
||||
import {
|
||||
Decorator,
|
||||
DecoratorHandler,
|
||||
} from '@loafer/core/decorator';
|
||||
|
||||
const App = (qualifier?: string | symbol ) => createDecorator('App', {
|
||||
classDecorator: <TFunction extends Function>(target: TFunction): TFunction | void => {
|
||||
let configurationDefinition = getInjectableDefinition(target.prototype, ConfigurationDefinition, false);
|
||||
if (undefined !== configurationDefinition) {
|
||||
throw new Error('Cannot apply @Injectable or @Injectable stereotype decorator multiple times.');
|
||||
}
|
||||
import {
|
||||
Class,
|
||||
} from '@loafer/core/reflect';
|
||||
|
||||
configurationDefinition = getInjectableDefinition(target.prototype, ConfigurationDefinition, true);
|
||||
configurationDefinition.Stereotype = InjectableSterotype.APP;
|
||||
configurationDefinition.Qualifier = validateQualifier(target.prototype, qualifier);
|
||||
import {
|
||||
InjectableAnnotation,
|
||||
} from '@loafer/pouches/decorator/Injectable';
|
||||
|
||||
return target;
|
||||
},
|
||||
export class AppAnnotation extends InjectableAnnotation implements DecoratorHandler {
|
||||
public constructor(qualifier?: PropertyType) {
|
||||
super(qualifier);
|
||||
}
|
||||
public onClassDecorator = <TFunction extends Function>(clazz: Class, target: TFunction): TFunction | void => {
|
||||
console.log('App');
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
export const App = Decorator.create(AppAnnotation);
|
||||
|
||||
export default App;
|
||||
|
|
|
@ -1,28 +1,30 @@
|
|||
import createDecorator from '@loafer/core/util/decorators/createDecorator';
|
||||
import ConfigurationDefinition from '@loafer/context/definition/ConfigurationDefinition';
|
||||
import { getInjectableDefinition } from '@loafer/pouches/util/metadata';
|
||||
import {
|
||||
PropertyType,
|
||||
} from '@loafer/core/constants/types';
|
||||
|
||||
import GetAppContext from '@loafer/context';
|
||||
import { InjectableSterotype } from '@loafer/pouches/constants';
|
||||
import DefaultPouchFactory from '@loafer/pouches/factory/implement/DefaultPouchFactory';
|
||||
import PouchDefinitionRegistry from '@loafer/pouches/factory/registry/PouchDefinitionRegistry';
|
||||
import { validateQualifier } from '@loafer/pouches/util/qualifier';
|
||||
import {
|
||||
Decorator,
|
||||
DecoratorHandler,
|
||||
} from '@loafer/core/decorator';
|
||||
|
||||
const Configuration = (qualifier?: string | symbol ) => createDecorator('Configuration', {
|
||||
classDecorator: <TFunction extends Function>(target: TFunction): TFunction | void => {
|
||||
let configurationDefinition: ConfigurationDefinition = getInjectableDefinition(target.prototype, ConfigurationDefinition, false);
|
||||
if (undefined !== configurationDefinition) {
|
||||
throw new Error('Cannot apply @Injectable or @Injectable stereotype decorator multiple times.');
|
||||
}
|
||||
import {
|
||||
Class,
|
||||
} from '@loafer/core/reflect';
|
||||
|
||||
configurationDefinition = getInjectableDefinition(target.prototype, ConfigurationDefinition, true);
|
||||
configurationDefinition.Stereotype = InjectableSterotype.CONFIGURATION;
|
||||
configurationDefinition.Qualifier = validateQualifier(target.prototype, qualifier);
|
||||
import {
|
||||
InjectableAnnotation,
|
||||
} from '@loafer/pouches/decorator/Injectable';
|
||||
|
||||
return target;
|
||||
},
|
||||
export class ConfigurationAnnotation extends InjectableAnnotation implements DecoratorHandler {
|
||||
public constructor(qualifier?: PropertyType) {
|
||||
super(qualifier);
|
||||
}
|
||||
public onClassDecorator = <TFunction extends Function>(clazz: Class, target: TFunction): TFunction | void => {
|
||||
console.log('Configuration');
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
export const Configuration = Decorator.create(ConfigurationAnnotation);
|
||||
|
||||
export default Configuration;
|
||||
|
|
|
@ -1,20 +1,36 @@
|
|||
import createDecorator from '@loafer/core/util/decorators/createDecorator';
|
||||
import {
|
||||
ClassType,
|
||||
PropertyType,
|
||||
} from '@loafer/core/constants/types';
|
||||
|
||||
import ConfigurationDefinition from '@loafer/context/definition/ConfigurationDefinition';
|
||||
import PouchConfig from '@loafer/context/decorator/PouchConfig';
|
||||
import {
|
||||
Decorator,
|
||||
DecoratorHandler,
|
||||
} from '@loafer/core/decorator';
|
||||
|
||||
import { getInjectableDefinition } from '@loafer/pouches/util/metadata';
|
||||
import { InjectableSterotype } from '@loafer/pouches/constants';
|
||||
import {
|
||||
Class,
|
||||
} from '@loafer/core/reflect';
|
||||
|
||||
const Pouch = (pouchConfig: PouchConfig = {}) => createDecorator('Pouch', {
|
||||
methodDecorator: (target: Object, propertyKey: string, descriptor: TypedPropertyDescriptor<any>): TypedPropertyDescriptor<any> => {
|
||||
let configurationDefinition: ConfigurationDefinition = getInjectableDefinition(target, ConfigurationDefinition, false);
|
||||
if (undefined === configurationDefinition || InjectableSterotype.CONFIGURATION !== configurationDefinition.Stereotype) {
|
||||
throw new Error('Cannot apply @Pouch decorator on not @Configuration class.');
|
||||
}
|
||||
configurationDefinition.addPouch(propertyKey, pouchConfig);
|
||||
return descriptor;
|
||||
},
|
||||
});
|
||||
export interface PouchConfig {
|
||||
qualifier?: PropertyType;
|
||||
type?: ClassType;
|
||||
}
|
||||
|
||||
export class PouchAnnotation implements DecoratorHandler {
|
||||
private readonly Qualifier: PropertyType;
|
||||
private readonly Type: ClassType;
|
||||
public constructor(config: PouchConfig = {}) {
|
||||
this.Qualifier = config.qualifier;
|
||||
this.Type = config.type;
|
||||
}
|
||||
|
||||
public onMethodDecorator = <T>(clazz: Class, target: Object, propertyKey: PropertyType,
|
||||
descriptor: TypedPropertyDescriptor<T>): TypedPropertyDescriptor<T> | void => {
|
||||
console.log('Pouch');
|
||||
}
|
||||
}
|
||||
|
||||
export const Pouch = Decorator.create(PouchAnnotation);
|
||||
|
||||
export default Pouch;
|
||||
|
|
|
@ -1,8 +0,0 @@
|
|||
import { ClassType, PropertyType } from '@loafer/core/constants';
|
||||
|
||||
interface PouchConfig {
|
||||
qualifier?: PropertyType;
|
||||
type?: ClassType;
|
||||
}
|
||||
|
||||
export default PouchConfig;
|
|
@ -1,28 +0,0 @@
|
|||
import createDecorator from '@loafer/core/util/decorators/createDecorator';
|
||||
import InjectableDefinition from '@loafer/pouches/definition/InjectableDefinition';
|
||||
import { getInjectableDefinition } from '@loafer/pouches/util/metadata';
|
||||
|
||||
import GetAppContext from '@loafer/context';
|
||||
import { InjectableSterotype } from '@loafer/pouches/constants';
|
||||
import { validateQualifier } from '@loafer/pouches/util/qualifier';
|
||||
import DefaultPouchFactory from '@loafer/pouches/factory/implement/DefaultPouchFactory';
|
||||
import PouchDefinitionRegistry from '@loafer/pouches/factory/registry/PouchDefinitionRegistry';
|
||||
|
||||
const Service = (qualifier?: string | symbol ) => createDecorator('Service', {
|
||||
classDecorator: <TFunction extends Function>(target: TFunction): TFunction | void => {
|
||||
let injectableDefinition: InjectableDefinition = getInjectableDefinition(target.prototype, InjectableDefinition, false);
|
||||
if (undefined !== injectableDefinition) {
|
||||
throw new Error('Cannot apply @Injectable or @Injectable stereotype decorator multiple times.');
|
||||
}
|
||||
|
||||
injectableDefinition = getInjectableDefinition(target.prototype, InjectableDefinition, true);
|
||||
injectableDefinition.Stereotype = InjectableSterotype.SERVICE;
|
||||
injectableDefinition.Qualifier = validateQualifier(target.prototype, qualifier);
|
||||
|
||||
return target;
|
||||
},
|
||||
|
||||
});
|
||||
|
||||
|
||||
export default Service;
|
|
@ -1,13 +0,0 @@
|
|||
import AppContext from '@loafer/context/AppContext';
|
||||
import DefaultAppContext from '@loafer/context/implement/DefaultAppContext';
|
||||
|
||||
let _appContext: AppContext = undefined;
|
||||
|
||||
const GetAppContext = (): AppContext => {
|
||||
if (undefined === _appContext) {
|
||||
_appContext = new DefaultAppContext();
|
||||
}
|
||||
return _appContext;
|
||||
};
|
||||
|
||||
export default GetAppContext;
|
|
@ -21,20 +21,21 @@ export class Decorator {
|
|||
reflection = new Reflection(type);
|
||||
Reflect.defineMetadata(ReflectConstants.REFLECT_META, reflection, type);
|
||||
}
|
||||
let clazz: Class = reflection.getClass();
|
||||
|
||||
switch(decoratorType) {
|
||||
case DecoratorType.CLASS:
|
||||
reflection.addClassAnnotation(annotation);
|
||||
return annotation.onClassDecorator.apply(annotation, decoratorArgs);
|
||||
return annotation.onClassDecorator.call(annotation, clazz, decoratorArgs[0]);
|
||||
case DecoratorType.PROPERTY:
|
||||
reflection.addPropertyAnnotation(annotation, decoratorArgs[1]);
|
||||
return annotation.onPropertyDecorator.apply(annotation, decoratorArgs);
|
||||
return annotation.onPropertyDecorator.call(annotation, clazz, decoratorArgs[0], decoratorArgs[1]);
|
||||
case DecoratorType.METHOD:
|
||||
reflection.addMethodAnnotation(annotation, decoratorArgs[1]);
|
||||
return annotation.onMethodDecorator.apply(annotation, decoratorArgs);
|
||||
return annotation.onMethodDecorator.call(annotation, clazz, decoratorArgs[0], decoratorArgs[1], decoratorArgs[2]);
|
||||
case DecoratorType.PARAMETER:
|
||||
reflection.addParameterAnnotation(annotation, decoratorArgs[1], decoratorArgs[2]);
|
||||
return annotation.onParameterDecorator.apply(annotation, decoratorArgs);
|
||||
return annotation.onParameterDecorator.call(annotation, clazz, decoratorArgs[0], decoratorArgs[1], decoratorArgs[2]);
|
||||
default:
|
||||
}
|
||||
};
|
||||
|
|
|
@ -1,9 +1,18 @@
|
|||
import {
|
||||
ClassType,
|
||||
PropertyType,
|
||||
} from '@loafer/core/constants/types';
|
||||
|
||||
import {
|
||||
Class,
|
||||
} from '@loafer/core/reflect';
|
||||
|
||||
export interface DecoratorHandler {
|
||||
onClassDecorator?: <TFunction extends Function>(target: TFunction) => TFunction | void;
|
||||
onPropertyDecorator?: (target: Object, propertyKey: string | symbol) => void;
|
||||
onMethodDecorator?: <T>(target: Object, propertyKey: string | symbol,
|
||||
onClassDecorator?: <TFunction extends Function>(clazz: Class, target: TFunction) => TFunction | void;
|
||||
onPropertyDecorator?: (clazz: Class, target: Object, propertyKey: PropertyType) => void;
|
||||
onMethodDecorator?: <T>(clazz: Class, target: Object, propertyKey: PropertyType,
|
||||
descriptor: TypedPropertyDescriptor<T>) => TypedPropertyDescriptor<T> | void;
|
||||
onParameterDecorator?: (target: Object, propertyKey: string | symbol, parameterIndex: number) => void;
|
||||
onParameterDecorator?: (clazz: Class, target: Object, propertyKey: PropertyType, parameterIndex: number) => void;
|
||||
}
|
||||
|
||||
export default DecoratorHandler;
|
||||
|
|
|
@ -1,25 +1,47 @@
|
|||
import InjectConfig from '@loafer/pouches/decorator/InjectConfig';
|
||||
import InjectDefinition from '@loafer/pouches/definition/InjectDefinition';
|
||||
import createDecorator from '@loafer/core/util/decorators/createDecorator';
|
||||
import { getInjectDefinition } from '@loafer/pouches/util/metadata';
|
||||
import {
|
||||
ClassType,
|
||||
DESIGN_TYPE,
|
||||
PropertyType,
|
||||
} from '@loafer/core/constants';
|
||||
const Inject = (injectConfig: InjectConfig = {}) => createDecorator('Inject', {
|
||||
propertyDecorator: (target: Object, propertyKey: string | symbol): void => {
|
||||
let injectDefinition: InjectDefinition = getInjectDefinition(target, InjectDefinition, true);
|
||||
injectDefinition.addInject(injectConfig, propertyKey);
|
||||
},
|
||||
parameterDecorator: (target: Object, propertyKey: string | symbol, parameterIndex: number): void => {
|
||||
let injectDefinition: InjectDefinition = getInjectDefinition(target, InjectDefinition, true);
|
||||
injectDefinition.addInject(injectConfig, propertyKey, parameterIndex);
|
||||
},
|
||||
} from '@loafer/core/constants/types';
|
||||
|
||||
});
|
||||
import {
|
||||
Decorator,
|
||||
DecoratorHandler,
|
||||
} from '@loafer/core/decorator';
|
||||
|
||||
import {
|
||||
Class,
|
||||
} from '@loafer/core/reflect';
|
||||
|
||||
export interface InjectConfig {
|
||||
qualifier?: PropertyType;
|
||||
required?: boolean;
|
||||
type?: ClassType;
|
||||
}
|
||||
|
||||
export class InjectAnnotation implements DecoratorHandler {
|
||||
private readonly Qualifier: PropertyType;
|
||||
private readonly Required: boolean;
|
||||
private readonly Type: ClassType;
|
||||
|
||||
public constructor(config: InjectConfig = {}) {
|
||||
this.Qualifier = config.qualifier;
|
||||
this.Required = config.required;
|
||||
this.Type = config.type;
|
||||
}
|
||||
|
||||
public onPropertyDecorator = (clazz: Class, target: Object, propertyKey: PropertyType): void => {
|
||||
console.log('Inject');
|
||||
}
|
||||
public onMethodDecorator = <T>(clazz: Class, target: Object, propertyKey: PropertyType,
|
||||
descriptor: TypedPropertyDescriptor<T>): TypedPropertyDescriptor<T> | void => {
|
||||
console.log('Inject');
|
||||
}
|
||||
public onParameterDecorator = (clazz: Class, target: Object, propertyKey: PropertyType, parameterIndex: number): void => {
|
||||
console.log('Inject');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export const Inject = Decorator.create(InjectAnnotation);
|
||||
|
||||
export default Inject;
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -1,9 +0,0 @@
|
|||
import { ClassType, PropertyType } from '@loafer/core/constants';
|
||||
|
||||
interface InjectConfig {
|
||||
qualifier?: PropertyType;
|
||||
required?: boolean;
|
||||
clazz?: ClassType;
|
||||
}
|
||||
|
||||
export default InjectConfig;
|
|
@ -1,26 +1,28 @@
|
|||
import createDecorator from '@loafer/core/util/decorators/createDecorator';
|
||||
import InjectableDefinition from '@loafer/pouches/definition/InjectableDefinition';
|
||||
import { getInjectableDefinition } from '@loafer/pouches/util/metadata';
|
||||
import {
|
||||
PropertyType,
|
||||
} from '@loafer/core/constants/types';
|
||||
|
||||
import GetAppContext from '@loafer/context';
|
||||
import { validateQualifier } from '@loafer/pouches/util/qualifier';
|
||||
import DefaultPouchFactory from '@loafer/pouches/factory/implement/DefaultPouchFactory';
|
||||
import PouchDefinitionRegistry from '@loafer/pouches/factory/registry/PouchDefinitionRegistry';
|
||||
import {
|
||||
Decorator,
|
||||
DecoratorHandler,
|
||||
} from '@loafer/core/decorator';
|
||||
|
||||
const Injectable = (qualifier?: string | symbol ) => createDecorator('Injectable', {
|
||||
classDecorator: <TFunction extends Function>(target: TFunction): TFunction | void => {
|
||||
let injectableDefinition: InjectableDefinition = getInjectableDefinition(target.prototype, InjectableDefinition, false);
|
||||
if (undefined !== injectableDefinition) {
|
||||
throw new Error('Cannot apply @Injectable decorator multiple times.');
|
||||
}
|
||||
import {
|
||||
Class,
|
||||
} from '@loafer/core/reflect';
|
||||
|
||||
injectableDefinition = getInjectableDefinition(target.prototype, InjectableDefinition, true);
|
||||
injectableDefinition.Qualifier = validateQualifier(target.prototype, qualifier);
|
||||
export class InjectableAnnotation implements DecoratorHandler {
|
||||
private readonly Qualifier: PropertyType;
|
||||
|
||||
return target;
|
||||
},
|
||||
public constructor(qualifier?: PropertyType) {
|
||||
this.Qualifier = qualifier;
|
||||
}
|
||||
public onClassDecorator = <TFunction extends Function>(clazz: Class, target: TFunction): TFunction | void => {
|
||||
console.log('Injectable');
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
export const Injectable = Decorator.create(InjectableAnnotation);
|
||||
|
||||
export default Injectable;
|
||||
|
|
|
@ -1,16 +1,23 @@
|
|||
import createDecorator from '@loafer/core/util/decorators/createDecorator';
|
||||
import InjectableDefinition from '@loafer/pouches/definition/InjectableDefinition';
|
||||
import { getInjectableDefinition } from '@loafer/pouches/util/metadata';
|
||||
import {
|
||||
PropertyType,
|
||||
} from '@loafer/core/constants/types';
|
||||
|
||||
const PostConstruct = createDecorator('PostConstruct', {
|
||||
methodDecorator: (target: Object, propertyKey: string, descriptor: TypedPropertyDescriptor<any>): TypedPropertyDescriptor<any> => {
|
||||
let injectableDefinition = getInjectableDefinition(target, InjectableDefinition, false);
|
||||
if (undefined === injectableDefinition) {
|
||||
throw new Error('Cannot apply @PostConstruct decorator on the not @Injectable or @Injectable stereotype class.');
|
||||
}
|
||||
injectableDefinition.addPostConstruct(propertyKey);
|
||||
return descriptor;
|
||||
},
|
||||
});
|
||||
import {
|
||||
Decorator,
|
||||
DecoratorHandler,
|
||||
} from '@loafer/core/decorator';
|
||||
|
||||
import {
|
||||
Class,
|
||||
} from '@loafer/core/reflect';
|
||||
|
||||
export class PostConstructAnnotation implements DecoratorHandler {
|
||||
public onMethodDecorator = <T>(clazz: Class, target: Object, propertyKey: PropertyType,
|
||||
descriptor: TypedPropertyDescriptor<T>): TypedPropertyDescriptor<T> | void => {
|
||||
console.log('PostConstruct');
|
||||
}
|
||||
}
|
||||
|
||||
export const PostConstruct = Decorator.create(PostConstructAnnotation);
|
||||
|
||||
export default PostConstruct;
|
||||
|
|
|
@ -1,16 +1,23 @@
|
|||
import createDecorator from '@loafer/core/util/decorators/createDecorator';
|
||||
import InjectableDefinition from '@loafer/pouches/definition/InjectableDefinition';
|
||||
import { getInjectableDefinition } from '@loafer/pouches/util/metadata';
|
||||
import {
|
||||
PropertyType,
|
||||
} from '@loafer/core/constants/types';
|
||||
|
||||
const PreDestroy = createDecorator('PreDestroy', {
|
||||
methodDecorator: (target: Object, propertyKey: string, descriptor: TypedPropertyDescriptor<any>): TypedPropertyDescriptor<any> => {
|
||||
let injectableDefinition = getInjectableDefinition(target, InjectableDefinition, false);
|
||||
if (undefined === injectableDefinition) {
|
||||
throw new Error('Cannot apply @PreDestroy decorator on the not @Injectable or @Injectable stereotype class.');
|
||||
}
|
||||
injectableDefinition.addPreDestroy(propertyKey);
|
||||
return descriptor;
|
||||
},
|
||||
});
|
||||
import {
|
||||
Decorator,
|
||||
DecoratorHandler,
|
||||
} from '@loafer/core/decorator';
|
||||
|
||||
import {
|
||||
Class,
|
||||
} from '@loafer/core/reflect';
|
||||
|
||||
export class PreDestroyAnnotation implements DecoratorHandler {
|
||||
public onMethodDecorator = <T>(clazz: Class, target: Object, propertyKey: PropertyType,
|
||||
descriptor: TypedPropertyDescriptor<T>): TypedPropertyDescriptor<T> | void => {
|
||||
console.log('PreDestroy');
|
||||
}
|
||||
}
|
||||
|
||||
export const PreDestroy = Decorator.create(PreDestroyAnnotation);
|
||||
|
||||
export default PreDestroy;
|
||||
|
|
|
@ -1,17 +1,28 @@
|
|||
import createDecorator from '@loafer/core/util/decorators/createDecorator';
|
||||
import InjectableDefinition from '@loafer/pouches/definition/InjectableDefinition';
|
||||
import { getInjectableDefinition } from '@loafer/pouches/util/metadata';
|
||||
import { PouchScope } from '@loafer/pouches/constants';
|
||||
import {
|
||||
PropertyType,
|
||||
} from '@loafer/core/constants/types';
|
||||
|
||||
const Scope = (scope: PouchScope = PouchScope.SINGLETON) => createDecorator('Scope', {
|
||||
classDecorator: <TFunction extends Function>(target: TFunction): TFunction | void => {
|
||||
let injectableDefinition = getInjectableDefinition(target.prototype, InjectableDefinition, false);
|
||||
if (undefined === injectableDefinition) {
|
||||
throw new Error('Cannot apply @Scope decorator on the not @Injectable or @Injectable stereotype class.');
|
||||
}
|
||||
injectableDefinition.Scope = scope;
|
||||
return target;
|
||||
},
|
||||
});
|
||||
import {
|
||||
Decorator,
|
||||
DecoratorHandler,
|
||||
} from '@loafer/core/decorator';
|
||||
|
||||
import {
|
||||
Class,
|
||||
} from '@loafer/core/reflect';
|
||||
|
||||
export class ScopeAnnotation implements DecoratorHandler {
|
||||
private readonly Qualifier: PropertyType;
|
||||
|
||||
public constructor(qualifier?: PropertyType) {
|
||||
this.Qualifier = qualifier;
|
||||
}
|
||||
public onClassDecorator = <TFunction extends Function>(clazz: Class, target: TFunction): TFunction | void => {
|
||||
console.log('Scope');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export const Scope = Decorator.create(ScopeAnnotation);
|
||||
|
||||
export default Scope;
|
||||
|
|
|
@ -1,17 +1,33 @@
|
|||
import InjectDefinition from '@loafer/pouches/definition/InjectDefinition';
|
||||
import createDecorator from '@loafer/core/util/decorators/createDecorator';
|
||||
import { getInjectDefinition } from '@loafer/pouches/util/metadata';
|
||||
import {
|
||||
ClassType,
|
||||
PropertyType,
|
||||
} from '@loafer/core/constants/types';
|
||||
|
||||
const Value = (value: string) => createDecorator('Value', {
|
||||
propertyDecorator: (target: Object, propertyKey: string | symbol): void => {
|
||||
let injectDefinition: InjectDefinition = getInjectDefinition(target, InjectDefinition, true);
|
||||
injectDefinition.addValue(value, propertyKey);
|
||||
},
|
||||
parameterDecorator: (target: Object, propertyKey: string | symbol, parameterIndex: number): void => {
|
||||
let injectDefinition: InjectDefinition = getInjectDefinition(target, InjectDefinition, true);
|
||||
injectDefinition.addValue(value, propertyKey, parameterIndex);
|
||||
},
|
||||
import {
|
||||
Decorator,
|
||||
DecoratorHandler,
|
||||
} from '@loafer/core/decorator';
|
||||
|
||||
});
|
||||
import {
|
||||
Class,
|
||||
} from '@loafer/core/reflect';
|
||||
|
||||
export class ValueAnnotation implements DecoratorHandler {
|
||||
private readonly Value: PropertyType;
|
||||
|
||||
public constructor(value: PropertyType) {
|
||||
this.Value = value;
|
||||
}
|
||||
|
||||
public onPropertyDecorator = (clazz: Class, target: Object, propertyKey: PropertyType): void => {
|
||||
console.log('Value');
|
||||
}
|
||||
public onParameterDecorator = (clazz: Class, target: Object, propertyKey: PropertyType, parameterIndex: number): void => {
|
||||
console.log('Value');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export const Value = Decorator.create(ValueAnnotation);
|
||||
|
||||
export default Value;
|
||||
|
|
|
@ -1,2 +0,0 @@
|
|||
export * from './inject';
|
||||
export * from './injectable';
|
|
@ -1,11 +0,0 @@
|
|||
import { ClassType } from '@loafer/core/constants';
|
||||
import getClassMetadata, {
|
||||
MetadataDefinable,
|
||||
} from '@loafer/core/util/metadata/getClassMetadata';
|
||||
|
||||
import { POUCH_INJECT_DEFINITION } from '@loafer/pouches/constants';
|
||||
import InjectDefinition from '@loafer/pouches/definition/InjectDefinition';
|
||||
|
||||
export const getInjectDefinition =
|
||||
<T>(clazz: ClassType, definitionType: MetadataDefinable<T>, isCreate: boolean = false) =>
|
||||
getClassMetadata(clazz, POUCH_INJECT_DEFINITION, definitionType, isCreate);
|
|
@ -1,9 +0,0 @@
|
|||
import { ClassType } from '@loafer/core/constants';
|
||||
import getClassMetadata, {
|
||||
MetadataDefinable,
|
||||
} from '@loafer/core/util/metadata/getClassMetadata';
|
||||
import { POUCH_INJECTABLE_DEFINITION } from '@loafer/pouches/constants';
|
||||
import InjectableDefinition from '@loafer/pouches/definition/InjectableDefinition';
|
||||
|
||||
export const getInjectableDefinition = <T>(clazz: ClassType, definitionType: MetadataDefinable<T>, isCreate: boolean = false) =>
|
||||
getClassMetadata(clazz, POUCH_INJECTABLE_DEFINITION, definitionType, isCreate);
|
Loading…
Reference in New Issue
Block a user