ing
This commit is contained in:
parent
4f5f937901
commit
72e95d73d4
|
@ -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;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
export interface ApplicationStater {
|
||||
start(): void;
|
||||
run(): void;
|
||||
}
|
||||
|
||||
export default ApplicationStater;
|
||||
|
|
|
@ -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 = <TFunction extends Function>(clazz: Class, target: TFunction): TFunction | void => {
|
||||
console.log('Application');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export const Application = Decorator.create(ApplicationAnnotation);
|
||||
|
||||
export default Application;
|
|
@ -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 = <TFunction extends Function>(target: TFunction): TFunction | void => {
|
||||
console.log('ApplicationConfiguration');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export const ApplicationConfiguration = Decorator.create(ApplicationConfigurationAnnotation);
|
||||
|
||||
export default ApplicationConfiguration;
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
|
@ -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<TAnnotation extends Annotation>(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 (<EnvironmentCapable>registry).getEnvironment();
|
||||
}
|
||||
return new StandardEnvironment();
|
||||
}
|
||||
}
|
||||
|
||||
export default AnnotatedPouchDefinitionReader;
|
|
@ -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;
|
||||
|
|
|
@ -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 = <TFunction extends Function>(clazz: Class, target: TFunction): TFunction | void => {
|
||||
public onClassDecorator = <TFunction extends Function>(target: TFunction): TFunction | void => {
|
||||
console.log('Configuration');
|
||||
}
|
||||
|
||||
|
|
|
@ -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 = <T>(clazz: Class, target: Object, propertyKey: PropertyType,
|
||||
public onMethodDecorator = <T>(target: Object, propertyKey: PropertyType,
|
||||
descriptor: TypedPropertyDescriptor<T>): TypedPropertyDescriptor<T> | void => {
|
||||
console.log('Pouch');
|
||||
}
|
||||
|
|
|
@ -1,4 +1,22 @@
|
|||
import {
|
||||
ClassType,
|
||||
PropertyType,
|
||||
} from '@loafer/core/constants/types';
|
||||
|
||||
import {
|
||||
Class,
|
||||
} from '@loafer/core/reflect';
|
||||
|
||||
export interface Annotation {
|
||||
onClassDecorator?: <TFunction extends Function>(target: TFunction) => TFunction | void;
|
||||
onPropertyDecorator?: (target: Object, propertyKey: PropertyType) => void;
|
||||
onMethodDecorator?: <T>(target: Object, propertyKey: PropertyType,
|
||||
descriptor: TypedPropertyDescriptor<T>) => TypedPropertyDescriptor<T> | void;
|
||||
onParameterDecorator?: (target: Object, propertyKey: PropertyType, parameterIndex: number) => void;
|
||||
}
|
||||
|
||||
export abstract class Annotation {
|
||||
|
||||
}
|
||||
|
||||
export default Annotation;
|
||||
|
|
|
@ -9,9 +9,9 @@ import Annotation from '@loafer/core/annotation/Annotation';
|
|||
import DecoratorType from './DecoratorType';
|
||||
|
||||
export class Decorator {
|
||||
public static create = (Annotation: Construtorable<Annotation>) => {
|
||||
public static create = (AnnotationType: Construtorable<Annotation>) => {
|
||||
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);
|
||||
|
|
|
@ -1,18 +0,0 @@
|
|||
import {
|
||||
ClassType,
|
||||
PropertyType,
|
||||
} from '@loafer/core/constants/types';
|
||||
|
||||
import {
|
||||
Class,
|
||||
} from '@loafer/core/reflect';
|
||||
|
||||
export interface DecoratorHandler {
|
||||
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?: (clazz: Class, target: Object, propertyKey: PropertyType, parameterIndex: number) => void;
|
||||
}
|
||||
|
||||
export default DecoratorHandler;
|
|
@ -1,3 +1,2 @@
|
|||
export * from './Decorator';
|
||||
export * from './DecoratorHandler';
|
||||
export * from './DecoratorType';
|
||||
|
|
7
src/ts/@loafer/core/lang/IllegalArgumentException.ts
Normal file
7
src/ts/@loafer/core/lang/IllegalArgumentException.ts
Normal file
|
@ -0,0 +1,7 @@
|
|||
export class IllegalArgumentException extends Error {
|
||||
public constructor(message?: string) {
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
|
||||
export default IllegalArgumentException;
|
7
src/ts/@loafer/core/lang/IllegalStateException.ts
Normal file
7
src/ts/@loafer/core/lang/IllegalStateException.ts
Normal file
|
@ -0,0 +1,7 @@
|
|||
export class IllegalStateException extends Error {
|
||||
public constructor(message?: string) {
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
|
||||
export default IllegalStateException;
|
2
src/ts/@loafer/core/lang/index.ts
Normal file
2
src/ts/@loafer/core/lang/index.ts
Normal file
|
@ -0,0 +1,2 @@
|
|||
export * from './IllegalArgumentException';
|
||||
export * from './IllegalStateException';
|
132
src/ts/@loafer/core/util/Assert.ts
Normal file
132
src/ts/@loafer/core/util/Assert.ts
Normal file
|
@ -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<any, any> | Set<any>, 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<any, any> = collection;
|
||||
if (0 === map.size) {
|
||||
valid = false;
|
||||
}
|
||||
} else if (collection instanceof Set) {
|
||||
let set: Set<any> = 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;
|
223
src/ts/@loafer/core/util/StringUtils.ts
Normal file
223
src/ts/@loafer/core/util/StringUtils.ts
Normal file
|
@ -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;
|
2
src/ts/@loafer/core/util/index.ts
Normal file
2
src/ts/@loafer/core/util/index.ts
Normal file
|
@ -0,0 +1,2 @@
|
|||
export * from './Assert';
|
||||
export * from './StringUtils';
|
|
@ -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 = <T>(clazz: Class, target: Object, propertyKey: PropertyType,
|
||||
public onMethodDecorator = <T>(target: Object, propertyKey: PropertyType,
|
||||
descriptor: TypedPropertyDescriptor<T>): TypedPropertyDescriptor<T> | 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');
|
||||
}
|
||||
|
||||
|
|
|
@ -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 = <TFunction extends Function>(clazz: Class, target: TFunction): TFunction | void => {
|
||||
public onClassDecorator = <TFunction extends Function>(target: TFunction): TFunction | void => {
|
||||
console.log('Injectable');
|
||||
}
|
||||
|
||||
|
|
|
@ -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 = <T>(clazz: Class, target: Object, propertyKey: PropertyType,
|
||||
export class PostConstructAnnotation extends Annotation {
|
||||
public onMethodDecorator = <T>(target: Object, propertyKey: PropertyType,
|
||||
descriptor: TypedPropertyDescriptor<T>): TypedPropertyDescriptor<T> | void => {
|
||||
console.log('PostConstruct');
|
||||
}
|
||||
|
|
|
@ -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 = <T>(clazz: Class, target: Object, propertyKey: PropertyType,
|
||||
export class PreDestroyAnnotation extends Annotation {
|
||||
public onMethodDecorator = <T>(target: Object, propertyKey: PropertyType,
|
||||
descriptor: TypedPropertyDescriptor<T>): TypedPropertyDescriptor<T> | void => {
|
||||
console.log('PreDestroy');
|
||||
}
|
||||
|
|
|
@ -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 = <TFunction extends Function>(clazz: Class, target: TFunction): TFunction | void => {
|
||||
public onClassDecorator = <TFunction extends Function>(target: TFunction): TFunction | void => {
|
||||
console.log('Scope');
|
||||
}
|
||||
|
||||
|
|
|
@ -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');
|
||||
}
|
||||
|
||||
|
|
|
@ -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<PropertyType, Map<ClassType, PouchDefinition>>;
|
||||
// abstract class AbstractPouchFactory extends DefaultSingletonPouchRegistry implements PouchDefinitionRegistry {
|
||||
// protected pouchDefinitionMap: Map<PropertyType, Map<ClassType, PouchDefinition>>;
|
||||
|
||||
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<ClassType, PouchDefinition>, 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<ClassType, PouchDefinition>, 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;
|
||||
|
|
|
@ -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<PropertyType, InjectItem> = 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<PropertyType, InjectItem> = 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<number, InjectConfig>): void {
|
||||
// console.log('');
|
||||
// }
|
||||
// // private _injectDependencyParameter(target: object, propertyDescriptor: PropertyDescriptor,
|
||||
// // parameterConfigs: Map<number, InjectConfig>): 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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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<any>;
|
||||
private sagaMiddleware: SagaMiddleware<any>;
|
||||
|
@ -92,7 +89,7 @@ class OFApplication implements ApplicationStater {
|
|||
Application.run(OFApplication.prototype);
|
||||
}
|
||||
|
||||
public async start(): Promise<void> {
|
||||
public async run(): Promise<void> {
|
||||
try {
|
||||
this.container = await Platform.getAppContainer(this.config.container.placeholderID);
|
||||
this.displayLoading();
|
||||
|
|
|
@ -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';
|
||||
|
|
Loading…
Reference in New Issue
Block a user