diff --git a/src/ts/@loafer/application/Application.ts b/src/ts/@loafer/application/Application.ts index 9675f0a..2d220d6 100644 --- a/src/ts/@loafer/application/Application.ts +++ b/src/ts/@loafer/application/Application.ts @@ -2,32 +2,34 @@ import { ClassType, } from '@loafer/core/constants/types'; -import AppContext from '@loafer/context/AppContext'; -import DefaultAppContext from '@loafer/context/implement/DefaultAppContext'; +import AnnotationConfigApplicationContext from '@loafer/context/annotation/AnnotationConfigApplicationContext'; import ApplicationStater from '@loafer/application/ApplicationStater'; class Application { - private appContext: AppContext; + // private appContext: AppContext; private appClass: ClassType; - private appInstance: ApplicationStater; + // private appInstance: ApplicationStater; public constructor(clazz: ClassType) { this.appClass = clazz; } - public run(): AppContext { - this.appContext = new DefaultAppContext(); - this.appInstance = this.appContext.getPouchByClass(this.appClass, undefined); + public run(): void { + let context: AnnotationConfigApplicationContext = new AnnotationConfigApplicationContext(); + context.register(AppConfig.prototype); + context.refresh(); - this.appInstance.start(); - - return this.appContext; + context.getPouch('entitlement'); } - public static run(clazz: ClassType): AppContext { - return new Application(clazz).run(); + public static run(clazz: ClassType): void { + new Application(clazz).run(); } } +export class AppConfig { + +} + export default Application; diff --git a/src/ts/@loafer/application/ApplicationStater.ts b/src/ts/@loafer/application/ApplicationStater.ts index c4d7952..3f5bca2 100644 --- a/src/ts/@loafer/application/ApplicationStater.ts +++ b/src/ts/@loafer/application/ApplicationStater.ts @@ -1,5 +1,5 @@ export interface ApplicationStater { - start(): void; + run(): void; } export default ApplicationStater; diff --git a/src/ts/@loafer/application/decorator/Application.ts b/src/ts/@loafer/application/decorator/Application.ts deleted file mode 100644 index fbdc5e2..0000000 --- a/src/ts/@loafer/application/decorator/Application.ts +++ /dev/null @@ -1,30 +0,0 @@ -import { - PropertyType, -} from '@loafer/core/constants/types'; - -import { - Decorator, - DecoratorHandler, - } from '@loafer/core/decorator'; - -import { - Class, -} from '@loafer/core/reflect'; - -import { - ConfigurationAnnotation, -} from '@loafer/context/decorator/Configuration'; - -export class ApplicationAnnotation extends ConfigurationAnnotation implements DecoratorHandler { - public constructor(qualifier?: PropertyType) { - super(qualifier); - } - public onClassDecorator = (clazz: Class, target: TFunction): TFunction | void => { - console.log('Application'); - } - -} - -export const Application = Decorator.create(ApplicationAnnotation); - -export default Application; diff --git a/src/ts/@loafer/application/decorator/ApplicationConfiguration.ts b/src/ts/@loafer/application/decorator/ApplicationConfiguration.ts new file mode 100644 index 0000000..30083e5 --- /dev/null +++ b/src/ts/@loafer/application/decorator/ApplicationConfiguration.ts @@ -0,0 +1,25 @@ +import { + PropertyType, +} from '@loafer/core/constants/types'; + +import { + Decorator, +} from '@loafer/core/decorator'; + +import { + ConfigurationAnnotation, +} from '@loafer/context/decorator/Configuration'; + +export class ApplicationConfigurationAnnotation extends ConfigurationAnnotation { + public constructor(qualifier?: PropertyType) { + super(qualifier); + } + public onClassDecorator = (target: TFunction): TFunction | void => { + console.log('ApplicationConfiguration'); + } + +} + +export const ApplicationConfiguration = Decorator.create(ApplicationConfigurationAnnotation); + +export default ApplicationConfiguration; diff --git a/src/ts/@loafer/context/ApplicationContext.ts b/src/ts/@loafer/context/ApplicationContext.ts index d1bf503..9f00d6f 100644 --- a/src/ts/@loafer/context/ApplicationContext.ts +++ b/src/ts/@loafer/context/ApplicationContext.ts @@ -1,22 +1,22 @@ -import { - PropertyType, -} from '@loafer/core/constants/types'; +// import { +// PropertyType, +// } from '@loafer/core/constants/types'; -import EnvironmentCapable from '@loafer/core/env/EnvironmentCapable'; +// import EnvironmentCapable from '@loafer/core/env/EnvironmentCapable'; -import PouchFactory from '@loafer/pouches/factory/PouchFactory'; -import DefaultPouchFactory from '@loafer/pouches/factory/implement/DefaultPouchFactory'; -import ListablePouchFactory from '@loafer/pouches/factory/ListablePouchFactory'; -import HierarchicalPouchFactory from '@loafer/pouches/factory/HierarchicalPouchFactory'; -import InjectCapablePouchFactory from '@loafer/pouches/factory/config/InjectCapablePouchFactory'; +// import PouchFactory from '@loafer/pouches/factory/PouchFactory'; +// import DefaultPouchFactory from '@loafer/pouches/factory/implement/DefaultPouchFactory'; +// import ListablePouchFactory from '@loafer/pouches/factory/ListablePouchFactory'; +// import HierarchicalPouchFactory from '@loafer/pouches/factory/HierarchicalPouchFactory'; +// import InjectCapablePouchFactory from '@loafer/pouches/factory/config/InjectCapablePouchFactory'; -export interface ApplicationContext extends EnvironmentCapable, ListablePouchFactory, HierarchicalPouchFactory { - getId?(): PropertyType; - getApplicationName(): string; - getDisplayName(): string; - getParent?(): ApplicationContext; +// export interface ApplicationContext extends EnvironmentCapable, ListablePouchFactory, HierarchicalPouchFactory { +// getId?(): PropertyType; +// getApplicationName(): string; +// getDisplayName(): string; +// getParent?(): ApplicationContext; - getInjectCapablePouchFactory(): InjectCapablePouchFactory; -} +// getInjectCapablePouchFactory(): InjectCapablePouchFactory; +// } -export default ApplicationContext; +// export default ApplicationContext; diff --git a/src/ts/@loafer/context/ConfigurableApplicationContext.ts b/src/ts/@loafer/context/ConfigurableApplicationContext.ts index 12bbe03..5ed2510 100644 --- a/src/ts/@loafer/context/ConfigurableApplicationContext.ts +++ b/src/ts/@loafer/context/ConfigurableApplicationContext.ts @@ -1,11 +1,11 @@ -import { - PropertyType, -} from '@loafer/core/constants/types'; -import ConfigurableEnvironment from '@loafer/core/env/ConfigurableEnvironment'; -import ApplicationContext from '@loafer/context/ApplicationContext'; -import Lifecycle from '@loafer/context/Lifecycle'; +// import { +// PropertyType, +// } from '@loafer/core/constants/types'; +// import ConfigurableEnvironment from '@loafer/core/env/ConfigurableEnvironment'; +// import ApplicationContext from '@loafer/context/ApplicationContext'; +// import Lifecycle from '@loafer/context/Lifecycle'; -export interface ConfigurableApplicationContext extends ApplicationContext, Lifecycle { -} +// export interface ConfigurableApplicationContext extends ApplicationContext, Lifecycle { +// } -export default ConfigurableApplicationContext; +// export default ConfigurableApplicationContext; diff --git a/src/ts/@loafer/context/DefaultAppContext.ts b/src/ts/@loafer/context/DefaultAppContext.ts deleted file mode 100644 index 54d3058..0000000 --- a/src/ts/@loafer/context/DefaultAppContext.ts +++ /dev/null @@ -1,30 +0,0 @@ -import { - ClassType, - PropertyType, -} from '@loafer/core/constants/types'; - -import ApplicationContext from '@loafer/context/ApplicationContext'; - -import DefaultPouchFactory from '@loafer/pouches/factory/implement/DefaultPouchFactory'; - -class DefaultAppContext implements ApplicationContext { - private readonly pouchFactory: DefaultPouchFactory; - - public constructor() { - this.pouchFactory = new DefaultPouchFactory(); - } - - public getPouchFactory(): DefaultPouchFactory { - return this.pouchFactory; - } - - public getPouch(qualifier: PropertyType, clazz: ClassType, ...args: any[]): any { - return this.pouchFactory.getPouch(qualifier, clazz, args); - } - public getPouchByClass(clazz: ClassType, qualifier: PropertyType, ...args: any[]): any { - return this.pouchFactory.getPouchByClass(clazz, qualifier, args); - } - -} - -export default DefaultAppContext; diff --git a/src/ts/@loafer/context/annotation/AnnotatedPouchDefinitionReader.ts b/src/ts/@loafer/context/annotation/AnnotatedPouchDefinitionReader.ts new file mode 100644 index 0000000..0576d25 --- /dev/null +++ b/src/ts/@loafer/context/annotation/AnnotatedPouchDefinitionReader.ts @@ -0,0 +1,97 @@ +import { + ClassType, + PropertyType, +} from '@loafer/core/constants/types'; + +import { + Assert, +} from '@loafer/core/util'; + +import { + Annotation, +} from '@loafer/core/annotation'; + + + +import GenericApplicationContext from '@loafer/context/support/GenericApplicationContext'; + +export class AnnotatedPouchDefinitionReader { + private readonly registry: PouchDefinitionRegistry; + private pouchNameGenerator: PouchNameGenerator = new AnnotationPouchNameGenerator(); + private scopeMetadataResolver: ScopeMetadataResolver = new AnnotationScopeMetadataResolver(); + private conditionEvaluator: ConditionEvaluator; + + + public constructor(registry: PouchDefinitionRegistry, environment?: Environment) { + if (undefined === environment) { + environment = this.getOrCreateEnvironment(registry); + } + Assert.notNull(registry, 'PouchDefinitionRegistry must not be null'); + Assert.notNull(environment, 'Environment must not be null'); + this.registry = registry; + this.conditionEvaluator = new ConditionEvaluator(registry, environment, null); + AnnotationConfigUtils.registerAnnotationConfigProcessors(this.registry); + } + + public getRegistry(): PouchDefinitionRegistry { + return this.registry; + } + + public setEnvironment(environment: Environment): void { + this.conditionEvaluator = new ConditionEvaluator(this.registry, environment, null); + } + + public setPouchNameGenerator(pouchNameGenerator: PouchNameGenerator): void { + this.pouchNameGenerator = (pouchNameGenerator !== null ? pouchNameGenerator : new AnnotationPouchNameGenerator()); + } + + public setScopeMetadataResolver(scopeMetadataResolver: ScopeMetadataResolver): void { + this.scopeMetadataResolver = + (scopeMetadataResolver !== null ? scopeMetadataResolver : new AnnotationScopeMetadataResolver()); + } + + + public register(...annotatedClasses: ClassType[]): void { + annotatedClasses.forEach(annotatedClass => { + this.registerPouch(annotatedClass); + }); + } + + public registerPouch(annotatedClass: ClassType, name: PropertyType, ...qualifiers: TAnnotation[]): void { + let abd: AnnotatedGenericPouchDefinition = new AnnotatedGenericPouchDefinition(annotatedClass); + if (this.conditionEvaluator.shouldSkip(abd.getMetadata())) { + return; + } + + let scopeMetadata: ScopeMetadata = this.scopeMetadataResolver.resolveScopeMetadata(abd); + abd.setScope(scopeMetadata.getScopeName()); + let pouchName: string = (name !== null ? name : this.pouchNameGenerator.generatePouchName(abd, this.registry)); + AnnotationConfigUtils.processCommonDefinitionAnnotations(abd); + if (qualifiers !== undefined) { + qualifiers.forEach((qualifier, index, array) => { + if (Primary.class === qualifier) { + abd.setPrimary(true); + } else if (Lazy.class === qualifier) { + abd.setLazyInit(true); + } else { + abd.addQualifier(new AutowireCandidateQualifier(qualifier)); + } + }); + } + + let definitionHolder: PouchDefinitionHolder = new PouchDefinitionHolder(abd, pouchName); + definitionHolder = AnnotationConfigUtils.applyScopedProxyMode(scopeMetadata, definitionHolder, this.registry); + PouchDefinitionReaderUtils.registerPouchDefinition(definitionHolder, this.registry); + } + + + private static getOrCreateEnvironment(registry: PouchDefinitionRegistry): Environment { + Assert.notNull(registry, 'PouchDefinitionRegistry must not be null'); + if (registry instanceof EnvironmentCapable) { + return (registry).getEnvironment(); + } + return new StandardEnvironment(); + } +} + +export default AnnotatedPouchDefinitionReader; diff --git a/src/ts/@loafer/context/annotation/AnnotationConfigApplicationContext.ts b/src/ts/@loafer/context/annotation/AnnotationConfigApplicationContext.ts index ac62273..b372f90 100644 --- a/src/ts/@loafer/context/annotation/AnnotationConfigApplicationContext.ts +++ b/src/ts/@loafer/context/annotation/AnnotationConfigApplicationContext.ts @@ -1,7 +1,21 @@ +import { + ClassType, +} from '@loafer/core/constants/types'; + +import { + Assert, +} from '@loafer/core/util'; + import GenericApplicationContext from '@loafer/context/support/GenericApplicationContext'; export class AnnotationConfigApplicationContext extends GenericApplicationContext { + private readonly reader: AnnotatedBeanDefinitionReader; + + public register(...annotatedClasses: ClassType[]): void { + Assert.notEmpty(annotatedClasses, 'At least one annotated class must be specified'); + this.reader.register(annotatedClasses); + } } export default AnnotationConfigApplicationContext; diff --git a/src/ts/@loafer/context/decorator/Configuration.ts b/src/ts/@loafer/context/decorator/Configuration.ts index d98dc45..4ede10a 100644 --- a/src/ts/@loafer/context/decorator/Configuration.ts +++ b/src/ts/@loafer/context/decorator/Configuration.ts @@ -4,22 +4,17 @@ import { import { Decorator, - DecoratorHandler, } from '@loafer/core/decorator'; -import { - Class, -} from '@loafer/core/reflect'; - import { InjectableAnnotation, } from '@loafer/pouches/decorator/Injectable'; -export class ConfigurationAnnotation extends InjectableAnnotation implements DecoratorHandler { +export class ConfigurationAnnotation extends InjectableAnnotation { public constructor(qualifier?: PropertyType) { super(qualifier); } - public onClassDecorator = (clazz: Class, target: TFunction): TFunction | void => { + public onClassDecorator = (target: TFunction): TFunction | void => { console.log('Configuration'); } diff --git a/src/ts/@loafer/context/decorator/Pouch.ts b/src/ts/@loafer/context/decorator/Pouch.ts index 56a7c80..d7daea0 100644 --- a/src/ts/@loafer/context/decorator/Pouch.ts +++ b/src/ts/@loafer/context/decorator/Pouch.ts @@ -5,21 +5,16 @@ import { import { Decorator, - DecoratorHandler, } from '@loafer/core/decorator'; import Annotation from '@loafer/core/annotation/Annotation'; -import { - Class, -} from '@loafer/core/reflect'; - export interface PouchConfig { qualifier?: PropertyType; type?: ClassType; } -export class PouchAnnotation extends Annotation implements DecoratorHandler { +export class PouchAnnotation extends Annotation { private readonly Qualifier: PropertyType; private readonly Type: ClassType; public constructor(config: PouchConfig = {}) { @@ -28,7 +23,7 @@ export class PouchAnnotation extends Annotation implements DecoratorHandler { this.Type = config.type; } - public onMethodDecorator = (clazz: Class, target: Object, propertyKey: PropertyType, + public onMethodDecorator = (target: Object, propertyKey: PropertyType, descriptor: TypedPropertyDescriptor): TypedPropertyDescriptor | void => { console.log('Pouch'); } diff --git a/src/ts/@loafer/core/annotation/Annotation.ts b/src/ts/@loafer/core/annotation/Annotation.ts index 80a7d03..edd977f 100644 --- a/src/ts/@loafer/core/annotation/Annotation.ts +++ b/src/ts/@loafer/core/annotation/Annotation.ts @@ -1,4 +1,22 @@ +import { + ClassType, + PropertyType, +} from '@loafer/core/constants/types'; + +import { + Class, +} from '@loafer/core/reflect'; + +export interface Annotation { + onClassDecorator?: (target: TFunction) => TFunction | void; + onPropertyDecorator?: (target: Object, propertyKey: PropertyType) => void; + onMethodDecorator?: (target: Object, propertyKey: PropertyType, + descriptor: TypedPropertyDescriptor) => TypedPropertyDescriptor | void; + onParameterDecorator?: (target: Object, propertyKey: PropertyType, parameterIndex: number) => void; +} + export abstract class Annotation { + } export default Annotation; diff --git a/src/ts/@loafer/core/decorator/Decorator.ts b/src/ts/@loafer/core/decorator/Decorator.ts index 475b9a5..679067d 100644 --- a/src/ts/@loafer/core/decorator/Decorator.ts +++ b/src/ts/@loafer/core/decorator/Decorator.ts @@ -9,9 +9,9 @@ import Annotation from '@loafer/core/annotation/Annotation'; import DecoratorType from './DecoratorType'; export class Decorator { - public static create = (Annotation: Construtorable) => { + public static create = (AnnotationType: Construtorable) => { return (...handlerArgs: any[]) => { - let annotation = new Annotation(...handlerArgs); + let annotation: Annotation = new AnnotationType(...handlerArgs); return (...decoratorArgs: any[]) => { let decoratorType: DecoratorType = Decorator._detectDecoratorType(name, annotation, decoratorArgs); diff --git a/src/ts/@loafer/core/decorator/DecoratorHandler.ts b/src/ts/@loafer/core/decorator/DecoratorHandler.ts deleted file mode 100644 index 096eac6..0000000 --- a/src/ts/@loafer/core/decorator/DecoratorHandler.ts +++ /dev/null @@ -1,18 +0,0 @@ -import { - ClassType, - PropertyType, -} from '@loafer/core/constants/types'; - -import { - Class, -} from '@loafer/core/reflect'; - -export interface DecoratorHandler { - onClassDecorator?: (clazz: Class, target: TFunction) => TFunction | void; - onPropertyDecorator?: (clazz: Class, target: Object, propertyKey: PropertyType) => void; - onMethodDecorator?: (clazz: Class, target: Object, propertyKey: PropertyType, - descriptor: TypedPropertyDescriptor) => TypedPropertyDescriptor | void; - onParameterDecorator?: (clazz: Class, target: Object, propertyKey: PropertyType, parameterIndex: number) => void; -} - -export default DecoratorHandler; diff --git a/src/ts/@loafer/core/decorator/index.ts b/src/ts/@loafer/core/decorator/index.ts index 86bd007..7aeca8a 100644 --- a/src/ts/@loafer/core/decorator/index.ts +++ b/src/ts/@loafer/core/decorator/index.ts @@ -1,3 +1,2 @@ export * from './Decorator'; -export * from './DecoratorHandler'; export * from './DecoratorType'; diff --git a/src/ts/@loafer/core/lang/IllegalArgumentException.ts b/src/ts/@loafer/core/lang/IllegalArgumentException.ts new file mode 100644 index 0000000..1d14339 --- /dev/null +++ b/src/ts/@loafer/core/lang/IllegalArgumentException.ts @@ -0,0 +1,7 @@ +export class IllegalArgumentException extends Error { + public constructor(message?: string) { + super(message); + } +} + +export default IllegalArgumentException; diff --git a/src/ts/@loafer/core/lang/IllegalStateException.ts b/src/ts/@loafer/core/lang/IllegalStateException.ts new file mode 100644 index 0000000..c651878 --- /dev/null +++ b/src/ts/@loafer/core/lang/IllegalStateException.ts @@ -0,0 +1,7 @@ +export class IllegalStateException extends Error { + public constructor(message?: string) { + super(message); + } +} + +export default IllegalStateException; diff --git a/src/ts/@loafer/core/lang/index.ts b/src/ts/@loafer/core/lang/index.ts new file mode 100644 index 0000000..972d2f8 --- /dev/null +++ b/src/ts/@loafer/core/lang/index.ts @@ -0,0 +1,2 @@ +export * from './IllegalArgumentException'; +export * from './IllegalStateException'; diff --git a/src/ts/@loafer/core/util/Assert.ts b/src/ts/@loafer/core/util/Assert.ts new file mode 100644 index 0000000..1d68e39 --- /dev/null +++ b/src/ts/@loafer/core/util/Assert.ts @@ -0,0 +1,132 @@ +import { + ClassType, +} from '@loafer/core/constants/types'; + +import { + IllegalStateException, + IllegalArgumentException, +} from '@loafer/core/lang'; + +import { + StringUtils, +} from '@loafer/core/util'; + +export abstract class Assert { + public static state(expression: boolean, message: string): void { + if (!expression) { + throw new IllegalStateException(message); + } + } + + public static isTrue(expression: boolean, message: string): void { + if (!expression) { + throw new IllegalArgumentException(message); + } + } + + public static isNull(object: any, message: string): void { + if (object !== null) { + throw new IllegalArgumentException(message); + } + } + + public static notNull(object: any, message: string): void { + if (object == null) { + throw new IllegalArgumentException(message); + } + } + + public static hasLength(text: string, message: string): void { + if (!StringUtils.hasLength(text)) { + throw new IllegalArgumentException(message); + } + } + + public static hasText(text: string, message: string): void { + if (!StringUtils.hasText(text)) { + throw new IllegalArgumentException(message); + } + } + + + public static doesNotContain(textToSearch: string, substring: string, message: string): void { + if (StringUtils.hasLength(textToSearch) && StringUtils.hasLength(substring) && + textToSearch.includes(substring)) { + throw new IllegalArgumentException(message); + } + } + + public static notEmpty(collection: any[] | Map | Set, message: string): void { + if (undefined === collection || null === collection) { + throw new IllegalArgumentException(message); + } + let valid = true; + if (collection instanceof Array) { + let array: any[] = collection; + if (0 === collection.length) { + valid = false; + } + } else if (collection instanceof Map) { + let map: Map = collection; + if (0 === map.size) { + valid = false; + } + } else if (collection instanceof Set) { + let set: Set = collection; + if (0 === set.size) { + valid = false; + } + } else { + valid = false; + } + if (!valid) { + throw new IllegalArgumentException(message); + } + } + + public static noNullElements(array: any[], message: string): void { + if (array !== null) { + array.forEach(element => { + if (element === null) { + throw new IllegalArgumentException(message); + } + }); + } + } + + public static isInstanceOf(type: ClassType, obj: any, message: string = ''): void { + Assert.notNull(type, 'Type to check against must not be null'); + if (!(obj instanceof type.constructor)) { + Assert.instanceCheckFailed(type, obj, message); + } + } + + private static instanceCheckFailed(type: ClassType, obj: any, message: string): void { + let className = (obj !== undefined && obj !== null ? Object.getPrototypeOf(obj).constructor.name : 'null'); + let result = ''; + let defaultMessage = true; + if (StringUtils.hasLength(message)) { + if (Assert.endsWithSeparator(message)) { + result = message + ' '; + } else { + result = Assert.messageWithTypeName(message, className); + defaultMessage = false; + } + } + if (defaultMessage) { + result = result + (`Object of class [${className}] must be an instance of ${type}`); + } + throw new IllegalArgumentException(result); + } + + private static endsWithSeparator(message: string): boolean { + return (message.endsWith(':') || message.endsWith(';') || message.endsWith(',') || message.endsWith('.')); + } + + private static messageWithTypeName(message: string, typeName: string): string { + return message + (message.endsWith(' ') ? '' : ': ') + typeName; + } + +} + +export default Assert; diff --git a/src/ts/@loafer/core/util/StringUtils.ts b/src/ts/@loafer/core/util/StringUtils.ts new file mode 100644 index 0000000..77e10e6 --- /dev/null +++ b/src/ts/@loafer/core/util/StringUtils.ts @@ -0,0 +1,223 @@ +import { + IllegalStateException, + IllegalArgumentException, +} from '@loafer/core/lang'; + + +export abstract class StringUtils { + private static readonly FOLDER_SEPARATOR: string = '/'; + + private static readonly WINDOWS_FOLDER_SEPARATOR: string = '\\'; + + private static readonly TOP_PATH: string = '..'; + + private static readonly CURRENT_PATH: string = '.'; + + private static readonly EXTENSION_SEPARATOR: string = '.'; + + + public static isEmpty(str: any): boolean { + return (undefined === str || null === str || '' === str); + } + + public static hasLength(str: string): boolean { + return (undefined !== str && null !== str && str.length > 0); + } + + public static hasText(str: string): boolean { + if (!StringUtils.hasLength(str)) { + return false; + } + return str.trim() !== ''; + } + + public static containsWhitespace(str: string): boolean { + if (!StringUtils.hasLength(str)) { + return false; + } + + return str.replace(/^\s+|\s+$/gm, '').length === 0; + } + + public static trimWhitespace(str: string): string { + if (!StringUtils.hasLength(str)) { + return str; + } + + return str.trim(); + } + + public static trimAllWhitespace(str: string): string { + if (!StringUtils.hasLength(str)) { + return str; + } + + return str.replace(/\s/g, ''); + } + + public static trimLeadingWhitespace(str: string): string { + if (!StringUtils.hasLength(str)) { + return str; + } + + return str.replace(/^\s+/gm, ''); + } + + public static trimTrailingWhitespace(str: string): string { + if (!StringUtils.hasLength(str)) { + return str; + } + + return str.replace(/^\s+$/gm, ''); + } + + public static trimLeadingCharacter(str: string, leadingCharacter: string): string { + if (!StringUtils.hasLength(str)) { + return str; + } + + return str.replace(new RegExp('^[' + leadingCharacter + ']+'), ''); + } + + public static trimTrailingCharacter(str: string, trailingCharacter: string): string { + if (!StringUtils.hasLength(str)) { + return str; + } + + return str.replace(new RegExp('[' + trailingCharacter + ']+$'), ''); + } + + + public static startsWithIgnoreCase(str: string, prefix: string): boolean { + if (undefined === str || null === str || undefined === prefix || null === prefix) { + return false; + } + if (str.startsWith(prefix)) { + return true; + } + if (str.length < prefix.length) { + return false; + } + + const lcStr = str.substring(0, prefix.length).toLowerCase(); + const lcPrefix = prefix.toLowerCase(); + return lcStr === lcPrefix; + } + + public static endsWithIgnoreCase(str: string, suffix: string): boolean { + if (str == null || suffix == null) { + return false; + } + if (str.endsWith(suffix)) { + return true; + } + if (str.length < suffix.length) { + return false; + } + + const lcStr = str.substring(str.length - suffix.length).toLowerCase(); + const lcSuffix = suffix.toLowerCase(); + return lcStr === lcSuffix; + } + + public static substringMatch(str: string, index: number, substring: string): boolean { + return str.includes(substring); + } + + public static countOccurrencesOf(str: string, sub: string): number { + if (!StringUtils.hasLength(str) || !StringUtils.hasLength(sub)) { + return 0; + } + + return (str.match(new RegExp(sub, 'gi')) || []).length; + } + + public static replace(inString: string, oldPattern: string, newPattern: string): string { + if (!StringUtils.hasLength(inString) || !StringUtils.hasLength(oldPattern) || newPattern == null) { + return inString; + } + return inString.replace(new RegExp(oldPattern, 'g'), newPattern); + } + + public static delete(inString: string, pattern: string): string { + return StringUtils.replace(inString, pattern, ''); + } + + public static deleteAny(inString: string, charsToDelete: string): string { + if (!StringUtils.hasLength(inString) || !StringUtils.hasLength(charsToDelete)) { + return inString; + } + + return inString.replace(new RegExp('^[' + charsToDelete + ']+'), ''); + } + + + public static quote(str: string): string { + return (str !== null ? '\'' + str + '\'' : null); + } + + public static quoteIfString(obj: any): any { + return (typeof obj === 'string' ? StringUtils.quote(obj) : obj); + } + + public static unqualify(qualifiedName: string, separator: string = '.'): string { + return qualifiedName.substring(qualifiedName.lastIndexOf(separator) + 1); + } + + + public static capitalize(str: string): string { + return StringUtils.changeFirstCharacterCase(str, true); + } + + public static uncapitalize(str: string): string { + return StringUtils.changeFirstCharacterCase(str, false); + } + + private static changeFirstCharacterCase(str: string, capitalize: boolean): string { + if (!StringUtils.hasLength(str)) { + return str; + } + + return capitalize ? str.charAt(0).toUpperCase() + str.slice(1) : str.charAt(0).toLowerCase() + str.slice(1); + } + + public static getFilename(path: string): string { + if (path === null) { + return null; + } + + return path.split(StringUtils.WINDOWS_FOLDER_SEPARATOR).pop().split(StringUtils.FOLDER_SEPARATOR).pop(); + } + + public static getFilenameExtension(path: string): string { + if (path == null) { + return null; + } + + return StringUtils.getFilename(path).split(StringUtils.EXTENSION_SEPARATOR).pop(); + } + + public static stripFilenameExtension(path: string): string { + if (path == null) { + return null; + } + + return path.replace(new RegExp('[' + StringUtils.EXTENSION_SEPARATOR + StringUtils.getFilenameExtension(path) + ']+$'), ''); + } + + public static applyRelativePath(path: string, relativePath: string): string { + let separatorIndex = path.lastIndexOf(StringUtils.FOLDER_SEPARATOR); + if (separatorIndex !== -1) { + let newPath = path.substring(0, separatorIndex); + if (!relativePath.startsWith(StringUtils.FOLDER_SEPARATOR)) { + newPath += StringUtils.FOLDER_SEPARATOR; + } + return newPath + relativePath; + } else { + return relativePath; + } + } + +} + +export default StringUtils; diff --git a/src/ts/@loafer/core/util/index.ts b/src/ts/@loafer/core/util/index.ts new file mode 100644 index 0000000..f207af9 --- /dev/null +++ b/src/ts/@loafer/core/util/index.ts @@ -0,0 +1,2 @@ +export * from './Assert'; +export * from './StringUtils'; diff --git a/src/ts/@loafer/pouches/decorator/Inject.ts b/src/ts/@loafer/pouches/decorator/Inject.ts index c9f4441..12a6ab7 100644 --- a/src/ts/@loafer/pouches/decorator/Inject.ts +++ b/src/ts/@loafer/pouches/decorator/Inject.ts @@ -5,22 +5,17 @@ import { import { Decorator, - DecoratorHandler, } from '@loafer/core/decorator'; import Annotation from '@loafer/core/annotation/Annotation'; -import { - Class, -} from '@loafer/core/reflect'; - export interface InjectConfig { qualifier?: PropertyType; required?: boolean; type?: ClassType; } -export class InjectAnnotation extends Annotation implements DecoratorHandler { +export class InjectAnnotation extends Annotation { private readonly Qualifier: PropertyType; private readonly Required: boolean; private readonly Type: ClassType; @@ -32,14 +27,14 @@ export class InjectAnnotation extends Annotation implements DecoratorHandler { this.Type = config.type; } - public onPropertyDecorator = (clazz: Class, target: Object, propertyKey: PropertyType): void => { + public onPropertyDecorator = (target: Object, propertyKey: PropertyType): void => { console.log('Inject'); } - public onMethodDecorator = (clazz: Class, target: Object, propertyKey: PropertyType, + public onMethodDecorator = (target: Object, propertyKey: PropertyType, descriptor: TypedPropertyDescriptor): TypedPropertyDescriptor | void => { console.log('Inject'); } - public onParameterDecorator = (clazz: Class, target: Object, propertyKey: PropertyType, parameterIndex: number): void => { + public onParameterDecorator = (target: Object, propertyKey: PropertyType, parameterIndex: number): void => { console.log('Inject'); } diff --git a/src/ts/@loafer/pouches/decorator/Injectable.ts b/src/ts/@loafer/pouches/decorator/Injectable.ts index bd20245..fc47027 100644 --- a/src/ts/@loafer/pouches/decorator/Injectable.ts +++ b/src/ts/@loafer/pouches/decorator/Injectable.ts @@ -4,23 +4,18 @@ import { import { Decorator, - DecoratorHandler, } from '@loafer/core/decorator'; import Annotation from '@loafer/core/annotation/Annotation'; -import { - Class, -} from '@loafer/core/reflect'; - -export class InjectableAnnotation extends Annotation implements DecoratorHandler { +export class InjectableAnnotation extends Annotation { private readonly Qualifier: PropertyType; public constructor(qualifier?: PropertyType) { super(); this.Qualifier = qualifier; } - public onClassDecorator = (clazz: Class, target: TFunction): TFunction | void => { + public onClassDecorator = (target: TFunction): TFunction | void => { console.log('Injectable'); } diff --git a/src/ts/@loafer/pouches/decorator/PostConstruct.ts b/src/ts/@loafer/pouches/decorator/PostConstruct.ts index 3a25638..a9f2feb 100644 --- a/src/ts/@loafer/pouches/decorator/PostConstruct.ts +++ b/src/ts/@loafer/pouches/decorator/PostConstruct.ts @@ -4,17 +4,12 @@ import { import { Decorator, - DecoratorHandler, } from '@loafer/core/decorator'; import Annotation from '@loafer/core/annotation/Annotation'; -import { - Class, -} from '@loafer/core/reflect'; - -export class PostConstructAnnotation extends Annotation implements DecoratorHandler { - public onMethodDecorator = (clazz: Class, target: Object, propertyKey: PropertyType, +export class PostConstructAnnotation extends Annotation { + public onMethodDecorator = (target: Object, propertyKey: PropertyType, descriptor: TypedPropertyDescriptor): TypedPropertyDescriptor | void => { console.log('PostConstruct'); } diff --git a/src/ts/@loafer/pouches/decorator/PreDestroy.ts b/src/ts/@loafer/pouches/decorator/PreDestroy.ts index d3989c7..da9abfc 100644 --- a/src/ts/@loafer/pouches/decorator/PreDestroy.ts +++ b/src/ts/@loafer/pouches/decorator/PreDestroy.ts @@ -4,17 +4,12 @@ import { import { Decorator, - DecoratorHandler, } from '@loafer/core/decorator'; import Annotation from '@loafer/core/annotation/Annotation'; -import { - Class, -} from '@loafer/core/reflect'; - -export class PreDestroyAnnotation extends Annotation implements DecoratorHandler { - public onMethodDecorator = (clazz: Class, target: Object, propertyKey: PropertyType, +export class PreDestroyAnnotation extends Annotation { + public onMethodDecorator = (target: Object, propertyKey: PropertyType, descriptor: TypedPropertyDescriptor): TypedPropertyDescriptor | void => { console.log('PreDestroy'); } diff --git a/src/ts/@loafer/pouches/decorator/Scope.ts b/src/ts/@loafer/pouches/decorator/Scope.ts index 5cbfd3e..8d45d88 100644 --- a/src/ts/@loafer/pouches/decorator/Scope.ts +++ b/src/ts/@loafer/pouches/decorator/Scope.ts @@ -4,23 +4,18 @@ import { import { Decorator, - DecoratorHandler, } from '@loafer/core/decorator'; -import { - Class, -} from '@loafer/core/reflect'; - import Annotation from '@loafer/core/annotation/Annotation'; -export class ScopeAnnotation extends Annotation implements DecoratorHandler { +export class ScopeAnnotation extends Annotation { private readonly Qualifier: PropertyType; public constructor(qualifier?: PropertyType) { super(); this.Qualifier = qualifier; } - public onClassDecorator = (clazz: Class, target: TFunction): TFunction | void => { + public onClassDecorator = (target: TFunction): TFunction | void => { console.log('Scope'); } diff --git a/src/ts/@loafer/pouches/decorator/Value.ts b/src/ts/@loafer/pouches/decorator/Value.ts index 19f314c..bce24a8 100644 --- a/src/ts/@loafer/pouches/decorator/Value.ts +++ b/src/ts/@loafer/pouches/decorator/Value.ts @@ -5,16 +5,11 @@ import { import { Decorator, - DecoratorHandler, } from '@loafer/core/decorator'; import Annotation from '@loafer/core/annotation/Annotation'; -import { - Class, -} from '@loafer/core/reflect'; - -export class ValueAnnotation extends Annotation implements DecoratorHandler { +export class ValueAnnotation extends Annotation { private readonly Value: PropertyType; public constructor(value: PropertyType) { @@ -22,10 +17,10 @@ export class ValueAnnotation extends Annotation implements DecoratorHandler { this.Value = value; } - public onPropertyDecorator = (clazz: Class, target: Object, propertyKey: PropertyType): void => { + public onPropertyDecorator = (target: Object, propertyKey: PropertyType): void => { console.log('Value'); } - public onParameterDecorator = (clazz: Class, target: Object, propertyKey: PropertyType, parameterIndex: number): void => { + public onParameterDecorator = (target: Object, propertyKey: PropertyType, parameterIndex: number): void => { console.log('Value'); } diff --git a/src/ts/@loafer/pouches/factory/implement/AbstractPouchFactory.ts b/src/ts/@loafer/pouches/factory/implement/AbstractPouchFactory.ts index 8d2867f..2669063 100644 --- a/src/ts/@loafer/pouches/factory/implement/AbstractPouchFactory.ts +++ b/src/ts/@loafer/pouches/factory/implement/AbstractPouchFactory.ts @@ -1,98 +1,98 @@ -import { - ClassType, - PropertyType, -} from '@loafer/core/constants/types'; +// import { +// ClassType, +// PropertyType, +// } from '@loafer/core/constants/types'; -import PouchDefinition from '@loafer/pouches/factory/config/PouchDefinition'; -import PouchDefinitionRegistry from '@loafer/pouches/factory/registry/PouchDefinitionRegistry'; -import DefaultSingletonPouchRegistry from '@loafer/pouches/factory/implement/DefaultSingletonPouchRegistry'; +// import PouchDefinition from '@loafer/pouches/factory/config/PouchDefinition'; +// import PouchDefinitionRegistry from '@loafer/pouches/factory/registry/PouchDefinitionRegistry'; +// import DefaultSingletonPouchRegistry from '@loafer/pouches/factory/implement/DefaultSingletonPouchRegistry'; -abstract class AbstractPouchFactory extends DefaultSingletonPouchRegistry implements PouchDefinitionRegistry { - protected pouchDefinitionMap: Map>; +// abstract class AbstractPouchFactory extends DefaultSingletonPouchRegistry implements PouchDefinitionRegistry { +// protected pouchDefinitionMap: Map>; - public constructor() { - super(); - this.pouchDefinitionMap = new Map(); - } +// public constructor() { +// super(); +// this.pouchDefinitionMap = new Map(); +// } - public registerPouchDefinition(pouchDefinition: PouchDefinition): void { - let clazz = pouchDefinition.Clazz; - // let qualifier = validateQualifier(clazz, pouchDefinition.Qualifier); +// public registerPouchDefinition(pouchDefinition: PouchDefinition): void { +// let clazz = pouchDefinition.Clazz; +// // let qualifier = validateQualifier(clazz, pouchDefinition.Qualifier); - // if (this.hasPouchDefinition(qualifier, clazz)) { - // throw new Error(`Pouch Definition[${clazz.constructor.name}:${qualifier}] is exist already`); - // } - // let map = this.pouchDefinitionMap.get(qualifier); - // if (undefined === map) { - // map = new Map(); - // this.pouchDefinitionMap.set(qualifier, map); - // } - // map.set(clazz, pouchDefinition); - } +// // if (this.hasPouchDefinition(qualifier, clazz)) { +// // throw new Error(`Pouch Definition[${clazz.constructor.name}:${qualifier}] is exist already`); +// // } +// // let map = this.pouchDefinitionMap.get(qualifier); +// // if (undefined === map) { +// // map = new Map(); +// // this.pouchDefinitionMap.set(qualifier, map); +// // } +// // map.set(clazz, pouchDefinition); +// } - public getPouchDefinition(qualifier: PropertyType, clazz?: ClassType): PouchDefinition { - if (!this.pouchDefinitionMap.has(qualifier)) { - return undefined; - } - let map = this.pouchDefinitionMap.get(qualifier); - let count = map.size; - let pouchDefinition: PouchDefinition; - try { - pouchDefinition = this._getDefinition(map, clazz); - } catch(e) { - console.log(`Type of Pouch Definition[${qualifier}] cannot be specified (count:${count})`); - } - return pouchDefinition; - } +// public getPouchDefinition(qualifier: PropertyType, clazz?: ClassType): PouchDefinition { +// if (!this.pouchDefinitionMap.has(qualifier)) { +// return undefined; +// } +// let map = this.pouchDefinitionMap.get(qualifier); +// let count = map.size; +// let pouchDefinition: PouchDefinition; +// try { +// pouchDefinition = this._getDefinition(map, clazz); +// } catch(e) { +// console.log(`Type of Pouch Definition[${qualifier}] cannot be specified (count:${count})`); +// } +// return pouchDefinition; +// } - public getPouchDefinitionByClass(clazz: ClassType, qualifier?: PropertyType): PouchDefinition { - // const _qualifier = validateQualifier(clazz, qualifier); - return this.getPouchDefinition(qualifier, clazz); - } +// public getPouchDefinitionByClass(clazz: ClassType, qualifier?: PropertyType): PouchDefinition { +// // const _qualifier = validateQualifier(clazz, qualifier); +// return this.getPouchDefinition(qualifier, clazz); +// } - public hasPouchDefinition(qualifier: PropertyType, clazz?: ClassType): boolean { - return undefined === this.getPouchDefinition(qualifier, clazz) ? false : true; - } - public hasPouchDefinitionByClass(clazz: ClassType, qualifier?: PropertyType): boolean { - // const _qualifier = validateQualifier(clazz, qualifier); +// public hasPouchDefinition(qualifier: PropertyType, clazz?: ClassType): boolean { +// return undefined === this.getPouchDefinition(qualifier, clazz) ? false : true; +// } +// public hasPouchDefinitionByClass(clazz: ClassType, qualifier?: PropertyType): boolean { +// // const _qualifier = validateQualifier(clazz, qualifier); - return this.hasPouchDefinition(qualifier, clazz); - } +// return this.hasPouchDefinition(qualifier, clazz); +// } - public removePouchDefinition(qualifier: PropertyType, clazz?: ClassType): void { +// public removePouchDefinition(qualifier: PropertyType, clazz?: ClassType): void { - if (!this.hasPouchDefinition(qualifier, clazz)) { - console.log(`Pouch Definition[${clazz.constructor.name}:${qualifier}] is not exist`); - return; - } - this.pouchDefinitionMap.get(qualifier).delete(clazz); - if (0 === this.pouchDefinitionMap.get(qualifier).size) { - this.pouchDefinitionMap.delete(qualifier); - } - } +// if (!this.hasPouchDefinition(qualifier, clazz)) { +// console.log(`Pouch Definition[${clazz.constructor.name}:${qualifier}] is not exist`); +// return; +// } +// this.pouchDefinitionMap.get(qualifier).delete(clazz); +// if (0 === this.pouchDefinitionMap.get(qualifier).size) { +// this.pouchDefinitionMap.delete(qualifier); +// } +// } - public removePouchDefinitionByClass(clazz: ClassType, qualifier?: PropertyType): void { - // const _qualifier = validateQualifier(clazz, qualifier); - // this.removePouchDefinition(_qualifier, clazz); - } +// public removePouchDefinitionByClass(clazz: ClassType, qualifier?: PropertyType): void { +// // const _qualifier = validateQualifier(clazz, qualifier); +// // this.removePouchDefinition(_qualifier, clazz); +// } - private _getDefinition(map: Map, clazz?: ClassType): PouchDefinition { - if (undefined !== clazz) { - return map.get(clazz); - } - const count = map.size; - if (1 < count) { - throw new Error('Type of Pouch Definition cannot be specified.'); - } - for (let value of Array.from(map.values())) { - return value; - } - } -} +// private _getDefinition(map: Map, clazz?: ClassType): PouchDefinition { +// if (undefined !== clazz) { +// return map.get(clazz); +// } +// const count = map.size; +// if (1 < count) { +// throw new Error('Type of Pouch Definition cannot be specified.'); +// } +// for (let value of Array.from(map.values())) { +// return value; +// } +// } +// } -export default AbstractPouchFactory; +// export default AbstractPouchFactory; diff --git a/src/ts/@loafer/pouches/factory/implement/DefaultPouchFactory.ts b/src/ts/@loafer/pouches/factory/implement/DefaultPouchFactory.ts index 1df9eba..1d78653 100644 --- a/src/ts/@loafer/pouches/factory/implement/DefaultPouchFactory.ts +++ b/src/ts/@loafer/pouches/factory/implement/DefaultPouchFactory.ts @@ -1,115 +1,115 @@ -import { - ClassType, - PropertyType, -} from '@loafer/core/constants/types'; +// import { +// ClassType, +// PropertyType, +// } from '@loafer/core/constants/types'; -import { - PouchScope, -} from '@loafer/pouches/constants/types'; +// import { +// PouchScope, +// } from '@loafer/pouches/constants/types'; -import PouchFactory from '@loafer/pouches/factory/PouchFactory'; -import AbstractPouchFactory from '@loafer/pouches/factory/implement/AbstractPouchFactory'; -import PouchDefinition from '@loafer/pouches/factory/config/PouchDefinition'; -import PouchDefinitionRegistry from '@loafer/pouches/factory/registry/PouchDefinitionRegistry'; +// import PouchFactory from '@loafer/pouches/factory/PouchFactory'; +// import AbstractPouchFactory from '@loafer/pouches/factory/implement/AbstractPouchFactory'; +// import PouchDefinition from '@loafer/pouches/factory/config/PouchDefinition'; +// import PouchDefinitionRegistry from '@loafer/pouches/factory/registry/PouchDefinitionRegistry'; -class DefaultPouchFactory extends AbstractPouchFactory implements PouchFactory, PouchDefinitionRegistry { - public constructor() { - super(); - } - public getPouch(qualifier: PropertyType, clazz: ClassType, ...args: any[]): any { - let pouchDefinition = this._getPouchDefinition(qualifier, clazz); - if (undefined === pouchDefinition) { - throw new Error(`This class[${clazz.constructor.name}:${qualifier}] is not pouch.`); - } +// class DefaultPouchFactory extends AbstractPouchFactory implements PouchFactory, PouchDefinitionRegistry { +// public constructor() { +// super(); +// } +// public getPouch(qualifier: PropertyType, clazz: ClassType, ...args: any[]): any { +// let pouchDefinition = this._getPouchDefinition(qualifier, clazz); +// if (undefined === pouchDefinition) { +// throw new Error(`This class[${clazz.constructor.name}:${qualifier}] is not pouch.`); +// } - return this._getPouch(pouchDefinition, ...args); - } - public getPouchByClass(clazz: ClassType, qualifier: PropertyType, ...args: any[]): any { - // let _qualifier = validateQualifier(clazz, qualifier); +// return this._getPouch(pouchDefinition, ...args); +// } +// public getPouchByClass(clazz: ClassType, qualifier: PropertyType, ...args: any[]): any { +// // let _qualifier = validateQualifier(clazz, qualifier); - // let pouchDefinition = this._getPouchDefinition(_qualifier, clazz); - // if (undefined === pouchDefinition) { - // throw new Error(`This class[${clazz.constructor.name}:${qualifier}] is not pouch.`); - // } +// // let pouchDefinition = this._getPouchDefinition(_qualifier, clazz); +// // if (undefined === pouchDefinition) { +// // throw new Error(`This class[${clazz.constructor.name}:${qualifier}] is not pouch.`); +// // } - // return this._getPouch(pouchDefinition, ...args); - } +// // return this._getPouch(pouchDefinition, ...args); +// } - private _getPouchDefinition(qualifier: PropertyType, clazz: ClassType): PouchDefinition { - let pouchDefinition = this.getPouchDefinition(qualifier, clazz); +// private _getPouchDefinition(qualifier: PropertyType, clazz: ClassType): PouchDefinition { +// let pouchDefinition = this.getPouchDefinition(qualifier, clazz); - if (undefined === pouchDefinition) { - // pouchDefinition = this._getInjectableDefinition(clazz); - if (undefined !== pouchDefinition) { - this.registerPouchDefinition(pouchDefinition); - } - } +// if (undefined === pouchDefinition) { +// // pouchDefinition = this._getInjectableDefinition(clazz); +// if (undefined !== pouchDefinition) { +// this.registerPouchDefinition(pouchDefinition); +// } +// } - return pouchDefinition; - } +// return pouchDefinition; +// } - private _getPouch(pouchDefinition: PouchDefinition, ...args: any[]): any { - let instance; - if (pouchDefinition.isSingleton()) { - instance = this.getSingleton(pouchDefinition.Qualifier, pouchDefinition.Clazz); - if (undefined !== instance) { - return instance; - } - } - instance = Object.create(pouchDefinition.Clazz); - instance.constructor.apply(instance, ...args); +// private _getPouch(pouchDefinition: PouchDefinition, ...args: any[]): any { +// let instance; +// if (pouchDefinition.isSingleton()) { +// instance = this.getSingleton(pouchDefinition.Qualifier, pouchDefinition.Clazz); +// if (undefined !== instance) { +// return instance; +// } +// } +// instance = Object.create(pouchDefinition.Clazz); +// instance.constructor.apply(instance, ...args); - this._injectDependency(instance, pouchDefinition.Clazz); - } +// this._injectDependency(instance, pouchDefinition.Clazz); +// } - private _injectDependency(instance: any, clazz: ClassType): void { - if (clazz.constructor === Object) { - return; - } +// private _injectDependency(instance: any, clazz: ClassType): void { +// if (clazz.constructor === Object) { +// return; +// } - // let injectDefinition: InjectDefinition = this._getInjectDefinition(clazz); - // if (undefined !== injectDefinition) { - // let injectors: Map = injectDefinition.injectors; - // let propertyDescriptor: PropertyDescriptor; - // injectors.forEach((injectItem, key, map) => { - // propertyDescriptor = Object.getOwnPropertyDescriptor(clazz, key); +// // let injectDefinition: InjectDefinition = this._getInjectDefinition(clazz); +// // if (undefined !== injectDefinition) { +// // let injectors: Map = injectDefinition.injectors; +// // let propertyDescriptor: PropertyDescriptor; +// // injectors.forEach((injectItem, key, map) => { +// // propertyDescriptor = Object.getOwnPropertyDescriptor(clazz, key); - // switch (injectItem.decoratorType) { - // case DecoratorType.PROPERTY: - // this._injectDependencyProperty(instance, clazz, key, propertyDescriptor, injectItem.propertyConfig); - // break; - // case DecoratorType.PARAMETER: - // this._injectDependencyParameter(instance, propertyDescriptor, injectItem.parameterConfigMap); - // break; - // default: - // break; - // } - // }); - // } - // this._injectDependency(instance, Object.getPrototypeOf(clazz)); - } +// // switch (injectItem.decoratorType) { +// // case DecoratorType.PROPERTY: +// // this._injectDependencyProperty(instance, clazz, key, propertyDescriptor, injectItem.propertyConfig); +// // break; +// // case DecoratorType.PARAMETER: +// // this._injectDependencyParameter(instance, propertyDescriptor, injectItem.parameterConfigMap); +// // break; +// // default: +// // break; +// // } +// // }); +// // } +// // this._injectDependency(instance, Object.getPrototypeOf(clazz)); +// } - // private _injectDependencyProperty(instance: any, clazz: ClassType, propertyKey: PropertyType, - // propertyDescriptor: PropertyDescriptor, injectConfig: InjectConfig): void { - // let pouch = this.getPouchByClass(injectConfig.clazz, injectConfig.qualifier); - // if (injectConfig.required && undefined === instance) { - // throw new Error(`Pouch which used by [${clazz.constructor.name}.${propertyKey}] is not exist in the context.`); - // } - // instance[propertyKey] = pouch; - // } +// // private _injectDependencyProperty(instance: any, clazz: ClassType, propertyKey: PropertyType, +// // propertyDescriptor: PropertyDescriptor, injectConfig: InjectConfig): void { +// // let pouch = this.getPouchByClass(injectConfig.clazz, injectConfig.qualifier); +// // if (injectConfig.required && undefined === instance) { +// // throw new Error(`Pouch which used by [${clazz.constructor.name}.${propertyKey}] is not exist in the context.`); +// // } +// // instance[propertyKey] = pouch; +// // } - // private _injectDependencyParameter(target: object, propertyDescriptor: PropertyDescriptor, - // parameterConfigs: Map): void { - // console.log(''); - // } +// // private _injectDependencyParameter(target: object, propertyDescriptor: PropertyDescriptor, +// // parameterConfigs: Map): void { +// // console.log(''); +// // } - // private _getInjectableDefinition(clazz: ClassType): InjectableDefinition { - // return Reflect.getMetadata(POUCH_INJECTABLE_DEFINITION, clazz); - // } +// // private _getInjectableDefinition(clazz: ClassType): InjectableDefinition { +// // return Reflect.getMetadata(POUCH_INJECTABLE_DEFINITION, clazz); +// // } - // private _getInjectDefinition(clazz: ClassType): InjectDefinition { - // return Reflect.getMetadata(POUCH_INJECT_DEFINITION, clazz); - // } -} +// // private _getInjectDefinition(clazz: ClassType): InjectDefinition { +// // return Reflect.getMetadata(POUCH_INJECT_DEFINITION, clazz); +// // } +// } -export default DefaultPouchFactory; +// export default DefaultPouchFactory; diff --git a/src/ts/@loafer/pouches/factory/support/AbstractInjectCapablePouchFactory.ts b/src/ts/@loafer/pouches/factory/support/AbstractInjectCapablePouchFactory.ts index 0443a9d..e87d481 100644 --- a/src/ts/@loafer/pouches/factory/support/AbstractInjectCapablePouchFactory.ts +++ b/src/ts/@loafer/pouches/factory/support/AbstractInjectCapablePouchFactory.ts @@ -1,7 +1,7 @@ import AliasRegistry from '@loafer/core/AliasRegistry'; import PouchDefinition from '@loafer/pouches/factory/config/PouchDefinition'; -export abstract class AbstractInjectCapablePouchFactory extends AliasRegistry { +export abstract class AbstractInjectCapablePouchFactory implements AliasRegistry { } export default AbstractInjectCapablePouchFactory; diff --git a/src/ts/@loafer/pouches/factory/support/DefaultListablePouchFactory.ts b/src/ts/@loafer/pouches/factory/support/DefaultListablePouchFactory.ts index 7831f4d..eb3b9ca 100644 --- a/src/ts/@loafer/pouches/factory/support/DefaultListablePouchFactory.ts +++ b/src/ts/@loafer/pouches/factory/support/DefaultListablePouchFactory.ts @@ -1,7 +1,7 @@ import AliasRegistry from '@loafer/core/AliasRegistry'; import PouchDefinition from '@loafer/pouches/factory/config/PouchDefinition'; -export class DefaultListablePouchFactory extends AliasRegistry { +export class DefaultListablePouchFactory implements AliasRegistry { } export default DefaultListablePouchFactory; diff --git a/src/ts/@overflow/app/index.tsx b/src/ts/@overflow/app/index.tsx index aa760cd..c30e49f 100644 --- a/src/ts/@overflow/app/index.tsx +++ b/src/ts/@overflow/app/index.tsx @@ -44,9 +44,7 @@ import * as injectTapEventPlugin from 'react-tap-event-plugin'; import Application from '@loafer/application/Application'; import ApplicationStater from '@loafer/application/ApplicationStater'; import Platform from '@overflow/commons/platform'; -import App from '@loafer/application/decorator/App'; import Inject from '@loafer/pouches/decorator/Inject'; -import AppContext from '@loafer/context/AppContext'; import WebSocketRPC from '@overflow/commons/websocket/WebSocketRPC'; import ReducerContext from '@overflow/commons/redux/ReducerContext'; @@ -68,15 +66,14 @@ declare global { injectTapEventPlugin(); -@App() class OFApplication implements ApplicationStater { private static isProduction:boolean = process.env.NODE_ENV === 'production' ? true : false; private static useReduxDevTools:boolean = window.devToolsExtension && !OFApplication.isProduction ? true : false; private config: Config; private container: HTMLElement; - @Inject() - private context: AppContext; + // @Inject() + // private context: AppContext; private rpcClient: WebSocketRPC; private store: Store; private sagaMiddleware: SagaMiddleware; @@ -92,7 +89,7 @@ class OFApplication implements ApplicationStater { Application.run(OFApplication.prototype); } - public async start(): Promise { + public async run(): Promise { try { this.container = await Platform.getAppContainer(this.config.container.placeholderID); this.displayLoading(); diff --git a/src/ts/@overflow/commons/redux/saga/asyncRequest.ts b/src/ts/@overflow/commons/redux/saga/asyncRequest.ts index 3766d3f..36dee53 100644 --- a/src/ts/@overflow/commons/redux/saga/asyncRequest.ts +++ b/src/ts/@overflow/commons/redux/saga/asyncRequest.ts @@ -1,7 +1,6 @@ import { SagaIterator } from 'redux-saga'; import { call, Effect, fork, put, takeEvery } from 'redux-saga/effects'; -import AppContext from '@loafer/context/AppContext'; import { SagaWatcher } from '@overflow/commons/constant'; import Action from '@overflow/commons/redux/Action'; import * as AsyncRequestActions from '@overflow/commons/redux/action/asyncRequest';