ing
This commit is contained in:
parent
eebefb6ee7
commit
2bc88e7a3d
8
src/ts/@loafer/context/AppContext.ts
Normal file
8
src/ts/@loafer/context/AppContext.ts
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
import PouchFactory from '@loafer/pouches/factory/PouchFactory';
|
||||||
|
import DefaultPouchFactory from '@loafer/pouches/factory/implement/DefaultPouchFactory';
|
||||||
|
|
||||||
|
interface AppContext extends PouchFactory {
|
||||||
|
getPouchFactory(): DefaultPouchFactory;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default AppContext;
|
2
src/ts/@loafer/context/constants/reflect.ts
Normal file
2
src/ts/@loafer/context/constants/reflect.ts
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
export const CONTEXT_CONFIGURATION_DEFINITION = 'loafer:context/configuration_definition';
|
||||||
|
export const CONTEXT_INJECTABLE_DEFINITION = 'loafer:context/injectable_definition';
|
31
src/ts/@loafer/context/decorator/Configuration.ts
Normal file
31
src/ts/@loafer/context/decorator/Configuration.ts
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
import createDecorator from '@loafer/core/util/decorators/createDecorator';
|
||||||
|
import ConfigurationDefinition from '@loafer/context/definition/ConfigurationDefinition';
|
||||||
|
import { getConfigurationDefinition } from '@loafer/context/util/metadata';
|
||||||
|
|
||||||
|
import GetAppContext from '@loafer/context';
|
||||||
|
import { DEFAULT_QUALIFIER, InjectableSterotype } from '@loafer/pouches/constants';
|
||||||
|
import DefaultPouchFactory from '@loafer/pouches/factory/implement/DefaultPouchFactory';
|
||||||
|
import PouchDefinitionRegistry from '@loafer/pouches/factory/registry/PouchDefinitionRegistry';
|
||||||
|
|
||||||
|
const Configuration = (qualifier: string | symbol = DEFAULT_QUALIFIER ) => createDecorator('Configuration', {
|
||||||
|
classDecorator: <TFunction extends Function>(target: TFunction): TFunction | void => {
|
||||||
|
let configurationDefinition: ConfigurationDefinition = getConfigurationDefinition(target.prototype, false);
|
||||||
|
if (undefined !== configurationDefinition) {
|
||||||
|
throw new Error('Cannot apply @Injectable or @Injectable stereotype decorator multiple times.');
|
||||||
|
}
|
||||||
|
|
||||||
|
configurationDefinition = getConfigurationDefinition(target, true);
|
||||||
|
configurationDefinition.Stereotype = InjectableSterotype.CONFIGURATION;
|
||||||
|
configurationDefinition.Qualifier = qualifier;
|
||||||
|
|
||||||
|
let pouchFactory: DefaultPouchFactory = GetAppContext().getPouchFactory();
|
||||||
|
let pouchDefinitionRegistry = <PouchDefinitionRegistry>pouchFactory;
|
||||||
|
pouchDefinitionRegistry.registerPouchDefinition(configurationDefinition);
|
||||||
|
|
||||||
|
return target;
|
||||||
|
},
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
export default Configuration;
|
30
src/ts/@loafer/context/decorator/Injectable.ts
Normal file
30
src/ts/@loafer/context/decorator/Injectable.ts
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
import createDecorator from '@loafer/core/util/decorators/createDecorator';
|
||||||
|
import InjectableDefinition from '@loafer/context/definition/InjectableDefinition';
|
||||||
|
import { getInjectableDefinition } from '@loafer/context/util/metadata';
|
||||||
|
|
||||||
|
import GetAppContext from '@loafer/context';
|
||||||
|
import { DEFAULT_QUALIFIER } from '@loafer/pouches/constants';
|
||||||
|
import DefaultPouchFactory from '@loafer/pouches/factory/implement/DefaultPouchFactory';
|
||||||
|
import PouchDefinitionRegistry from '@loafer/pouches/factory/registry/PouchDefinitionRegistry';
|
||||||
|
|
||||||
|
const Injectable = (qualifier: string | symbol = DEFAULT_QUALIFIER ) => createDecorator('Injectable', {
|
||||||
|
classDecorator: <TFunction extends Function>(target: TFunction): TFunction | void => {
|
||||||
|
let injectableDefinition: InjectableDefinition = getInjectableDefinition(target.prototype, false);
|
||||||
|
if (undefined !== injectableDefinition) {
|
||||||
|
throw new Error('Cannot apply @Injectable decorator multiple times.');
|
||||||
|
}
|
||||||
|
|
||||||
|
injectableDefinition = getInjectableDefinition(target, true);
|
||||||
|
injectableDefinition.Qualifier = qualifier;
|
||||||
|
|
||||||
|
let pouchFactory: DefaultPouchFactory = GetAppContext().getPouchFactory();
|
||||||
|
let pouchDefinitionRegistry = <PouchDefinitionRegistry>pouchFactory;
|
||||||
|
pouchDefinitionRegistry.registerPouchDefinition(injectableDefinition);
|
||||||
|
|
||||||
|
return target;
|
||||||
|
},
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
export default Injectable;
|
16
src/ts/@loafer/context/decorator/PostConstruct.ts
Normal file
16
src/ts/@loafer/context/decorator/PostConstruct.ts
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
import createDecorator from '@loafer/core/util/decorators/createDecorator';
|
||||||
|
import InjectableDefinition from '@loafer/context/definition/InjectableDefinition';
|
||||||
|
import { getInjectableDefinition } from '@loafer/context/util/metadata';
|
||||||
|
|
||||||
|
const PostConstruct = createDecorator('PostConstruct', {
|
||||||
|
methodDecorator: (target: Object, propertyKey: string, descriptor: TypedPropertyDescriptor<any>): TypedPropertyDescriptor<any> => {
|
||||||
|
let injectableDefinition = getInjectableDefinition(target, false);
|
||||||
|
if (undefined === injectableDefinition) {
|
||||||
|
throw new Error('Cannot apply @PostConstruct decorator on the not @Injectable or @Injectable stereotype class.');
|
||||||
|
}
|
||||||
|
injectableDefinition.addPostConstruct(propertyKey);
|
||||||
|
return descriptor;
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
export default PostConstruct;
|
18
src/ts/@loafer/context/decorator/Pouch.ts
Normal file
18
src/ts/@loafer/context/decorator/Pouch.ts
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
import createDecorator from '@loafer/core/util/decorators/createDecorator';
|
||||||
|
import ConfigurationDefinition from '@loafer/context/definition/ConfigurationDefinition';
|
||||||
|
import { getConfigurationDefinition } from '@loafer/context/util/metadata';
|
||||||
|
import { InjectableSterotype } from '@loafer/pouches/constants';
|
||||||
|
import PouchConfig from '@loafer/context/decorator/PouchConfig';
|
||||||
|
|
||||||
|
const Pouch = (pouchConfig: PouchConfig = {}) => createDecorator('Pouch', {
|
||||||
|
methodDecorator: (target: Object, propertyKey: string, descriptor: TypedPropertyDescriptor<any>): TypedPropertyDescriptor<any> => {
|
||||||
|
let configurationDefinition: ConfigurationDefinition = getConfigurationDefinition(target, false);
|
||||||
|
if (undefined === configurationDefinition || InjectableSterotype.CONFIGURATION !== configurationDefinition.Stereotype) {
|
||||||
|
throw new Error('Cannot apply @Pouch decorator on not @Configuration class.');
|
||||||
|
}
|
||||||
|
configurationDefinition.addPouch(propertyKey, pouchConfig);
|
||||||
|
return descriptor;
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
export default Pouch;
|
16
src/ts/@loafer/context/decorator/PreDestroy.ts
Normal file
16
src/ts/@loafer/context/decorator/PreDestroy.ts
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
import createDecorator from '@loafer/core/util/decorators/createDecorator';
|
||||||
|
import InjectableDefinition from '@loafer/context/definition/InjectableDefinition';
|
||||||
|
import { getInjectableDefinition } from '@loafer/context/util/metadata';
|
||||||
|
|
||||||
|
const PreDestroy = createDecorator('PreDestroy', {
|
||||||
|
methodDecorator: (target: Object, propertyKey: string, descriptor: TypedPropertyDescriptor<any>): TypedPropertyDescriptor<any> => {
|
||||||
|
let injectableDefinition = getInjectableDefinition(target, false);
|
||||||
|
if (undefined === injectableDefinition) {
|
||||||
|
throw new Error('Cannot apply @PreDestroy decorator on the not @Injectable or @Injectable stereotype class.');
|
||||||
|
}
|
||||||
|
injectableDefinition.addPreDestroy(propertyKey);
|
||||||
|
return descriptor;
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
export default PreDestroy;
|
17
src/ts/@loafer/context/decorator/Scope.ts
Normal file
17
src/ts/@loafer/context/decorator/Scope.ts
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
import createDecorator from '@loafer/core/util/decorators/createDecorator';
|
||||||
|
import InjectableDefinition from '@loafer/context/definition/InjectableDefinition';
|
||||||
|
import { getInjectableDefinition } from '@loafer/context/util/metadata';
|
||||||
|
import { PouchScope } from '@loafer/pouches/constants';
|
||||||
|
|
||||||
|
const Scope = (scope: PouchScope = PouchScope.SINGLETON) => createDecorator('Scope', {
|
||||||
|
classDecorator: <TFunction extends Function>(target: TFunction): TFunction | void => {
|
||||||
|
let injectableDefinition = getInjectableDefinition(target.prototype, false);
|
||||||
|
if (undefined === injectableDefinition) {
|
||||||
|
throw new Error('Cannot apply @Scope decorator on the not @Injectable or @Injectable stereotype class.');
|
||||||
|
}
|
||||||
|
injectableDefinition.Scope = scope;
|
||||||
|
return target;
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
export default Scope;
|
31
src/ts/@loafer/context/decorator/Service.ts
Normal file
31
src/ts/@loafer/context/decorator/Service.ts
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
import createDecorator from '@loafer/core/util/decorators/createDecorator';
|
||||||
|
import InjectableDefinition from '@loafer/context/definition/InjectableDefinition';
|
||||||
|
import { getInjectableDefinition } from '@loafer/context/util/metadata';
|
||||||
|
|
||||||
|
import GetAppContext from '@loafer/context';
|
||||||
|
import { DEFAULT_QUALIFIER, InjectableSterotype } from '@loafer/pouches/constants';
|
||||||
|
import DefaultPouchFactory from '@loafer/pouches/factory/implement/DefaultPouchFactory';
|
||||||
|
import PouchDefinitionRegistry from '@loafer/pouches/factory/registry/PouchDefinitionRegistry';
|
||||||
|
|
||||||
|
const Service = (qualifier: string | symbol = DEFAULT_QUALIFIER ) => createDecorator('Service', {
|
||||||
|
classDecorator: <TFunction extends Function>(target: TFunction): TFunction | void => {
|
||||||
|
let injectableDefinition: InjectableDefinition = getInjectableDefinition(target.prototype, false);
|
||||||
|
if (undefined !== injectableDefinition) {
|
||||||
|
throw new Error('Cannot apply @Injectable or @Injectable stereotype decorator multiple times.');
|
||||||
|
}
|
||||||
|
|
||||||
|
injectableDefinition = getInjectableDefinition(target, true);
|
||||||
|
injectableDefinition.Stereotype = InjectableSterotype.SERVICE;
|
||||||
|
injectableDefinition.Qualifier = qualifier;
|
||||||
|
|
||||||
|
let pouchFactory: DefaultPouchFactory = GetAppContext().getPouchFactory();
|
||||||
|
let pouchDefinitionRegistry = <PouchDefinitionRegistry>pouchFactory;
|
||||||
|
pouchDefinitionRegistry.registerPouchDefinition(injectableDefinition);
|
||||||
|
|
||||||
|
return target;
|
||||||
|
},
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
export default Service;
|
32
src/ts/@loafer/context/definition/ConfigurationDefinition.ts
Normal file
32
src/ts/@loafer/context/definition/ConfigurationDefinition.ts
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
import { DESIGN_RETURNTYPE } from '@loafer/core/constants';
|
||||||
|
import InjectableDefinition from '@loafer/context/definition/InjectableDefinition';
|
||||||
|
import PouchConfig from '@loafer/context/decorator/PouchConfig';
|
||||||
|
|
||||||
|
class ConfigurationDefinition extends InjectableDefinition {
|
||||||
|
protected _qualifier: string | symbol = undefined;
|
||||||
|
protected _pouchMap: Map<string, PouchConfig>;
|
||||||
|
|
||||||
|
public constructor(type: Object) {
|
||||||
|
super(type);
|
||||||
|
}
|
||||||
|
|
||||||
|
public addPouch(propertyKey: string, pouchConfig: PouchConfig): void {
|
||||||
|
if (undefined === this._pouchMap) {
|
||||||
|
this._pouchMap = new Map();
|
||||||
|
}
|
||||||
|
let returnType: any = Reflect.getMetadata(DESIGN_RETURNTYPE, this._type, propertyKey);
|
||||||
|
|
||||||
|
if (undefined === pouchConfig.type) {
|
||||||
|
pouchConfig.type = returnType;
|
||||||
|
}
|
||||||
|
|
||||||
|
this._pouchMap.set(propertyKey, pouchConfig);
|
||||||
|
}
|
||||||
|
|
||||||
|
public get Pouches(): Map<string, PouchConfig> {
|
||||||
|
return this._pouchMap;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
export default ConfigurationDefinition;
|
75
src/ts/@loafer/context/definition/InjectableDefinition.ts
Normal file
75
src/ts/@loafer/context/definition/InjectableDefinition.ts
Normal file
|
@ -0,0 +1,75 @@
|
||||||
|
import PouchDefinition from '@loafer/pouches/factory/config/PouchDefinition';
|
||||||
|
import { InjectableSterotype, PouchScope } from '@loafer/pouches/constants';
|
||||||
|
|
||||||
|
class InjectableDefinition implements PouchDefinition {
|
||||||
|
protected _type: Object;
|
||||||
|
protected _stereotype: InjectableSterotype;
|
||||||
|
protected _scope: PouchScope = PouchScope.SINGLETON;
|
||||||
|
protected _qualifier: string | symbol = undefined;
|
||||||
|
protected _postConstruct: Set<string> = undefined;
|
||||||
|
protected _preDestroy: Set<string> = undefined;
|
||||||
|
|
||||||
|
public constructor(type: Object) {
|
||||||
|
this._type = type;
|
||||||
|
this._stereotype = InjectableSterotype.INJECTABLE;
|
||||||
|
}
|
||||||
|
|
||||||
|
public get Type(): Object {
|
||||||
|
return this._type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public get Stereotype(): InjectableSterotype {
|
||||||
|
return this._stereotype;
|
||||||
|
}
|
||||||
|
|
||||||
|
public set Stereotype(stereotype: InjectableSterotype) {
|
||||||
|
this._stereotype = stereotype;
|
||||||
|
}
|
||||||
|
|
||||||
|
public get Scope(): PouchScope {
|
||||||
|
return this._scope;
|
||||||
|
}
|
||||||
|
|
||||||
|
public set Scope(scope: PouchScope) {
|
||||||
|
this._scope = scope;
|
||||||
|
}
|
||||||
|
|
||||||
|
public get Qualifier(): string | symbol {
|
||||||
|
return this._qualifier;
|
||||||
|
}
|
||||||
|
|
||||||
|
public set Qualifier(qualifier: string | symbol) {
|
||||||
|
this._qualifier = qualifier;
|
||||||
|
}
|
||||||
|
|
||||||
|
public get PostConstruct(): Set<string> {
|
||||||
|
return this._postConstruct;
|
||||||
|
}
|
||||||
|
|
||||||
|
public addPostConstruct(postConstruct: string): void {
|
||||||
|
if (undefined === this._postConstruct) {
|
||||||
|
this._postConstruct = new Set();
|
||||||
|
}
|
||||||
|
this._postConstruct.add(postConstruct);
|
||||||
|
}
|
||||||
|
|
||||||
|
public get PreDestroy(): Set<string> {
|
||||||
|
return this._preDestroy;
|
||||||
|
}
|
||||||
|
|
||||||
|
public addPreDestroy(preDestroy: string): void {
|
||||||
|
if (undefined === this._preDestroy) {
|
||||||
|
this._preDestroy = new Set();
|
||||||
|
}
|
||||||
|
this._preDestroy.add(preDestroy);
|
||||||
|
}
|
||||||
|
|
||||||
|
public isSingleton(): boolean {
|
||||||
|
return this._scope === PouchScope.SINGLETON;
|
||||||
|
}
|
||||||
|
public isTransient(): boolean {
|
||||||
|
return this._scope === PouchScope.TRANSIENT;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default InjectableDefinition;
|
30
src/ts/@loafer/context/implement/DefaultAppContext.ts
Normal file
30
src/ts/@loafer/context/implement/DefaultAppContext.ts
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
import {
|
||||||
|
Construtorable,
|
||||||
|
} from '@loafer/core/constants';
|
||||||
|
|
||||||
|
import AppContext from '@loafer/context/AppContext';
|
||||||
|
|
||||||
|
import DefaultPouchFactory from '@loafer/pouches/factory/implement/DefaultPouchFactory';
|
||||||
|
|
||||||
|
class DefaultAppContext implements AppContext {
|
||||||
|
private readonly pouchFactory: DefaultPouchFactory;
|
||||||
|
|
||||||
|
public constructor() {
|
||||||
|
this.pouchFactory = new DefaultPouchFactory();
|
||||||
|
}
|
||||||
|
|
||||||
|
public getPouchFactory(): DefaultPouchFactory {
|
||||||
|
return this.pouchFactory;
|
||||||
|
}
|
||||||
|
|
||||||
|
public getPouch<T>(type: Construtorable<T>, ...args: any[]): T {
|
||||||
|
return this.pouchFactory.getPouch(type, args);
|
||||||
|
}
|
||||||
|
|
||||||
|
public getPouchByQualifier<T>(type: Construtorable<T>, qualifier: string | symbol, ...args: any[]): T {
|
||||||
|
return this.pouchFactory.getPouchByQualifier(type, qualifier, args);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
export default DefaultAppContext;
|
13
src/ts/@loafer/context/index.ts
Normal file
13
src/ts/@loafer/context/index.ts
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
import AppContext from '@loafer/context/AppContext';
|
||||||
|
import DefaultAppContext from '@loafer/context/implement/DefaultAppContext';
|
||||||
|
|
||||||
|
let _appContext: AppContext = undefined;
|
||||||
|
|
||||||
|
const GetAppContext = (): AppContext => {
|
||||||
|
if (undefined === _appContext) {
|
||||||
|
_appContext = new DefaultAppContext();
|
||||||
|
}
|
||||||
|
return _appContext;
|
||||||
|
};
|
||||||
|
|
||||||
|
export default GetAppContext;
|
6
src/ts/@loafer/context/util/metadata/configuration.ts
Normal file
6
src/ts/@loafer/context/util/metadata/configuration.ts
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
import getClassMetadata from '@loafer/core/util/metadata/getClassMetadata';
|
||||||
|
import { CONTEXT_INJECTABLE_DEFINITION } from '@loafer/context/constants';
|
||||||
|
import ConfigurationDefinition from '@loafer/context/definition/ConfigurationDefinition';
|
||||||
|
|
||||||
|
export const getConfigurationDefinition = (target: Object, isCreate: boolean = false) =>
|
||||||
|
getClassMetadata(target, CONTEXT_INJECTABLE_DEFINITION, ConfigurationDefinition, isCreate);
|
|
@ -1 +1,2 @@
|
||||||
export * from './configuration';
|
export * from './configuration';
|
||||||
|
export * from './injectable';
|
6
src/ts/@loafer/context/util/metadata/injectable.ts
Normal file
6
src/ts/@loafer/context/util/metadata/injectable.ts
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
import getClassMetadata from '@loafer/core/util/metadata/getClassMetadata';
|
||||||
|
import { CONTEXT_INJECTABLE_DEFINITION } from '@loafer/context/constants';
|
||||||
|
import InjectableDefinition from '@loafer/context/definition/InjectableDefinition';
|
||||||
|
|
||||||
|
export const getInjectableDefinition = (target: Object, isCreate: boolean = false) =>
|
||||||
|
getClassMetadata(target, CONTEXT_INJECTABLE_DEFINITION, InjectableDefinition, isCreate);
|
|
@ -1,4 +1,4 @@
|
||||||
export type Newable<T> = {new(...args: any[]): T};
|
export type Construtorable<T> = {new(...args: any[]): T};
|
||||||
|
|
||||||
export enum DecoratorType {
|
export enum DecoratorType {
|
||||||
CLASS,
|
CLASS,
|
23
src/ts/@loafer/core/util/metadata/getClassMetadata.ts
Normal file
23
src/ts/@loafer/core/util/metadata/getClassMetadata.ts
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
export type MetadataDefinable<T> = {new(target: Function): T};
|
||||||
|
|
||||||
|
const getClassMetadata = <DefinitionType>(target: Object,
|
||||||
|
metadataKey: any,
|
||||||
|
definitionType: MetadataDefinable<DefinitionType>,
|
||||||
|
isCreate: boolean = false): DefinitionType => {
|
||||||
|
|
||||||
|
let definition: DefinitionType;
|
||||||
|
if (Reflect.hasOwnMetadata(metadataKey, target) !== true) {
|
||||||
|
if (!isCreate) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
definition = Object.create(definitionType.prototype);
|
||||||
|
definition.constructor.call(definition, target);
|
||||||
|
|
||||||
|
Reflect.defineMetadata(metadataKey, definition, target);
|
||||||
|
} else {
|
||||||
|
definition = Reflect.getMetadata(metadataKey, target);
|
||||||
|
}
|
||||||
|
return definition;
|
||||||
|
};
|
||||||
|
|
||||||
|
export default getClassMetadata;
|
5
src/ts/@loafer/pouches/constants/index.ts
Normal file
5
src/ts/@loafer/pouches/constants/index.ts
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
export * from './reflect';
|
||||||
|
export * from './stereotype';
|
||||||
|
export * from './types';
|
||||||
|
|
||||||
|
export const DEFAULT_QUALIFIER = Symbol('__DEFAULT_QUALIFIER__');
|
1
src/ts/@loafer/pouches/constants/reflect.ts
Normal file
1
src/ts/@loafer/pouches/constants/reflect.ts
Normal file
|
@ -0,0 +1 @@
|
||||||
|
export const POUCH_INJECT_DEFINITION = 'loafer:pouch/inject_definition';
|
11
src/ts/@loafer/pouches/constants/stereotype.ts
Normal file
11
src/ts/@loafer/pouches/constants/stereotype.ts
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
export enum InjectableSterotype {
|
||||||
|
INJECTABLE = 'Injectable',
|
||||||
|
CONFIGURATION = 'Configuration',
|
||||||
|
SERVICE = 'Service',
|
||||||
|
}
|
||||||
|
|
||||||
|
export enum InjectSterotype {
|
||||||
|
INJECT = 'Inject',
|
||||||
|
VALUE = 'Value',
|
||||||
|
}
|
||||||
|
|
4
src/ts/@loafer/pouches/constants/types.ts
Normal file
4
src/ts/@loafer/pouches/constants/types.ts
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
export enum PouchScope {
|
||||||
|
SINGLETON = 'Singleton',
|
||||||
|
TRANSIENT = 'Transient',
|
||||||
|
}
|
18
src/ts/@loafer/pouches/decorator/Inject.ts
Normal file
18
src/ts/@loafer/pouches/decorator/Inject.ts
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
import InjectConfig from '@loafer/pouches/decorator/InjectConfig';
|
||||||
|
import InjectDefinition from '@loafer/pouches/definition/InjectDefinition';
|
||||||
|
import createDecorator from '@loafer/core/util/decorators/createDecorator';
|
||||||
|
import { getInjectDefinition } from '@loafer/pouches/util/metadata';
|
||||||
|
|
||||||
|
const Inject = (injectConfig: InjectConfig = {}) => createDecorator('Inject', {
|
||||||
|
propertyDecorator: (target: Object, propertyKey: string | symbol): void => {
|
||||||
|
let injectDefinition: InjectDefinition = getInjectDefinition(target, true);
|
||||||
|
injectDefinition.addInject(injectConfig, propertyKey);
|
||||||
|
},
|
||||||
|
parameterDecorator: (target: Object, propertyKey: string | symbol, parameterIndex: number): void => {
|
||||||
|
let injectDefinition: InjectDefinition = getInjectDefinition(target, true);
|
||||||
|
injectDefinition.addInject(injectConfig, propertyKey, parameterIndex);
|
||||||
|
},
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
export default Inject;
|
17
src/ts/@loafer/pouches/decorator/Value.ts
Normal file
17
src/ts/@loafer/pouches/decorator/Value.ts
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
import InjectDefinition from '@loafer/pouches/definition/InjectDefinition';
|
||||||
|
import createDecorator from '@loafer/core/util/decorators/createDecorator';
|
||||||
|
import { getInjectDefinition } from '@loafer/pouches/util/metadata';
|
||||||
|
|
||||||
|
const Value = (value: string) => createDecorator('Value', {
|
||||||
|
propertyDecorator: (target: Object, propertyKey: string | symbol): void => {
|
||||||
|
let injectDefinition: InjectDefinition = getInjectDefinition(target, true);
|
||||||
|
injectDefinition.addValue(value, propertyKey);
|
||||||
|
},
|
||||||
|
parameterDecorator: (target: Object, propertyKey: string | symbol, parameterIndex: number): void => {
|
||||||
|
let injectDefinition: InjectDefinition = getInjectDefinition(target, true);
|
||||||
|
injectDefinition.addValue(value, propertyKey, parameterIndex);
|
||||||
|
},
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
export default Value;
|
|
@ -1,15 +1,16 @@
|
||||||
import * as METADATA from '../constants';
|
import * as METADATA from '@loafer/pouches/constants';
|
||||||
import { POUCH_DEFAULT_QUALIFIER } from '../constants';
|
import { DEFAULT_QUALIFIER, InjectSterotype } from '@loafer/pouches/constants';
|
||||||
import InjectConfig from '../decorator/InjectConfig';
|
import InjectConfig from '@loafer/pouches/decorator/InjectConfig';
|
||||||
import * as CoreConstants from '@overflow/commons/core/constants';
|
import * as CoreConstants from '@loafer/core/constants';
|
||||||
|
|
||||||
export interface InjectItem {
|
export interface InjectItem {
|
||||||
|
stereotype: InjectSterotype;
|
||||||
decoratorType: CoreConstants.DecoratorType;
|
decoratorType: CoreConstants.DecoratorType;
|
||||||
propertyConfig?: InjectConfig;
|
propertyConfig?: InjectConfig;
|
||||||
parameterConfigMap?: Map<number, InjectConfig>;
|
parameterConfigMap?: Map<number, InjectConfig>;
|
||||||
}
|
}
|
||||||
|
|
||||||
class PouchInjectDefinition {
|
class InjectDefinition {
|
||||||
protected target: Object;
|
protected target: Object;
|
||||||
protected injectMap: Map<string | symbol, InjectItem>;
|
protected injectMap: Map<string | symbol, InjectItem>;
|
||||||
|
|
||||||
|
@ -27,7 +28,7 @@ class PouchInjectDefinition {
|
||||||
*/
|
*/
|
||||||
public addInject(injectConfig: InjectConfig, propertyKey: string | symbol, parameterIndex?: number): void {
|
public addInject(injectConfig: InjectConfig, propertyKey: string | symbol, parameterIndex?: number): void {
|
||||||
if (undefined === injectConfig.qualifier) {
|
if (undefined === injectConfig.qualifier) {
|
||||||
injectConfig.qualifier = POUCH_DEFAULT_QUALIFIER;
|
injectConfig.qualifier = DEFAULT_QUALIFIER;
|
||||||
}
|
}
|
||||||
if (undefined === injectConfig.required) {
|
if (undefined === injectConfig.required) {
|
||||||
injectConfig.required = false;
|
injectConfig.required = false;
|
||||||
|
@ -40,7 +41,25 @@ class PouchInjectDefinition {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private addInjectParameter(injectConfig: InjectConfig, propertyKey: string | symbol, parameterIndex: number): void {
|
/**
|
||||||
|
* addValue
|
||||||
|
*/
|
||||||
|
public addValue(value: string, propertyKey: string | symbol, parameterIndex?: number): void {
|
||||||
|
if(typeof parameterIndex === 'number') {
|
||||||
|
this.addValueParameter(value, propertyKey, parameterIndex);
|
||||||
|
} else {
|
||||||
|
this.addValueProperty(value, propertyKey);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private addValueProperty(value: string, propertyKey: string | symbol): void {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
private addInjectParameter(injectConfig: InjectConfig,
|
||||||
|
propertyKey: string | symbol, parameterIndex: number): void {
|
||||||
let injectItem: InjectItem;
|
let injectItem: InjectItem;
|
||||||
let parameterTypes: any[] = Reflect.getMetadata(CoreConstants.DESIGN_PARAMTYPES, this.target, propertyKey);
|
let parameterTypes: any[] = Reflect.getMetadata(CoreConstants.DESIGN_PARAMTYPES, this.target, propertyKey);
|
||||||
|
|
||||||
|
@ -52,6 +71,7 @@ class PouchInjectDefinition {
|
||||||
injectItem = this.injectMap.get(propertyKey);
|
injectItem = this.injectMap.get(propertyKey);
|
||||||
} else {
|
} else {
|
||||||
injectItem = {
|
injectItem = {
|
||||||
|
stereotype: InjectSterotype.INJECT,
|
||||||
decoratorType: CoreConstants.DecoratorType.PARAMETER,
|
decoratorType: CoreConstants.DecoratorType.PARAMETER,
|
||||||
};
|
};
|
||||||
this.injectMap.set(propertyKey, injectItem);
|
this.injectMap.set(propertyKey, injectItem);
|
||||||
|
@ -81,6 +101,7 @@ class PouchInjectDefinition {
|
||||||
}
|
}
|
||||||
|
|
||||||
let injectItem: InjectItem = {
|
let injectItem: InjectItem = {
|
||||||
|
stereotype: InjectSterotype.INJECT,
|
||||||
decoratorType: CoreConstants.DecoratorType.PROPERTY,
|
decoratorType: CoreConstants.DecoratorType.PROPERTY,
|
||||||
propertyConfig: injectConfig,
|
propertyConfig: injectConfig,
|
||||||
};
|
};
|
||||||
|
@ -90,4 +111,4 @@ class PouchInjectDefinition {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default PouchInjectDefinition;
|
export default InjectDefinition;
|
9
src/ts/@loafer/pouches/factory/PouchFactory.ts
Normal file
9
src/ts/@loafer/pouches/factory/PouchFactory.ts
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
import { Construtorable } from '@loafer/core/constants';
|
||||||
|
|
||||||
|
interface PouchFactory {
|
||||||
|
getPouch<T>(type: Construtorable<T>, ...args: any[]): T;
|
||||||
|
getPouchByQualifier<T>(type: Construtorable<T>, qualifier: string | symbol, ...args: any[]): T;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
export default PouchFactory;
|
16
src/ts/@loafer/pouches/factory/config/PouchDefinition.ts
Normal file
16
src/ts/@loafer/pouches/factory/config/PouchDefinition.ts
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
import { InjectableSterotype, PouchScope } from '@loafer/pouches/constants';
|
||||||
|
|
||||||
|
interface PouchDefinition {
|
||||||
|
readonly Type: Object;
|
||||||
|
Stereotype: InjectableSterotype;
|
||||||
|
Scope: PouchScope;
|
||||||
|
Qualifier: string | symbol;
|
||||||
|
readonly PostConstruct: Set<string>;
|
||||||
|
readonly PreDestroy: Set<string>;
|
||||||
|
addPostConstruct(postConstruct: string): void;
|
||||||
|
addPreDestroy(preDestroy: string): void;
|
||||||
|
isSingleton(): boolean;
|
||||||
|
isTransient(): boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default PouchDefinition;
|
|
@ -0,0 +1,55 @@
|
||||||
|
import * as METADATA from '@loafer/pouches/constants';
|
||||||
|
|
||||||
|
import {
|
||||||
|
Construtorable,
|
||||||
|
DecoratorType,
|
||||||
|
} from '@loafer/core/constants';
|
||||||
|
|
||||||
|
import {
|
||||||
|
PouchScope,
|
||||||
|
DEFAULT_QUALIFIER,
|
||||||
|
} from '@loafer/pouches/constants';
|
||||||
|
|
||||||
|
import PouchFactory from '@loafer/pouches/factory/PouchFactory';
|
||||||
|
import PouchDefinition from '@loafer/pouches/factory/config/PouchDefinition';
|
||||||
|
import PouchDefinitionRegistry from '@loafer/pouches/factory/registry/PouchDefinitionRegistry';
|
||||||
|
|
||||||
|
class DefaultPouchFactory implements PouchFactory, PouchDefinitionRegistry {
|
||||||
|
public constructor() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public getPouch<T>(type: Construtorable<T>, ...args: any[]): T {
|
||||||
|
let qualifier = DEFAULT_QUALIFIER;
|
||||||
|
return this.getPouchByQualifier(type, qualifier, args);
|
||||||
|
}
|
||||||
|
|
||||||
|
public getPouchByQualifier<T>(type: Construtorable<T>, qualifier: string | symbol, ...args: any[]): T {
|
||||||
|
let clazz: Function = type.prototype;
|
||||||
|
let instance: T;
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
public registerPouchDefinition(pouchDefinition: PouchDefinition): void {
|
||||||
|
let type = pouchDefinition.Type;
|
||||||
|
let qualifier = pouchDefinition.Qualifier;
|
||||||
|
|
||||||
|
}
|
||||||
|
public removePouchDefinition(type: Object, qualifier?: string | symbol): void {
|
||||||
|
|
||||||
|
}
|
||||||
|
public getPouchDefinition(type: Object, qualifier?: string | symbol): PouchDefinition {
|
||||||
|
|
||||||
|
}
|
||||||
|
public hasPouchDefinition(type: Object, qualifier?: string | symbol): boolean {
|
||||||
|
|
||||||
|
}
|
||||||
|
public getPouchDefinitions(): PouchDefinition[] {
|
||||||
|
|
||||||
|
}
|
||||||
|
public getPouchDefinitionCount(): number {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
export default DefaultPouchFactory;
|
|
@ -0,0 +1,13 @@
|
||||||
|
import { Construtorable } from '@loafer/core/constants';
|
||||||
|
import PouchDefinition from '@loafer/pouches/factory/config/PouchDefinition';
|
||||||
|
|
||||||
|
interface PouchDefinitionRegistry {
|
||||||
|
registerPouchDefinition(pouchDefinition: PouchDefinition): void;
|
||||||
|
removePouchDefinition(type: Object, qualifier?: string | symbol): void;
|
||||||
|
getPouchDefinition(type: Object, qualifier?: string | symbol): PouchDefinition;
|
||||||
|
hasPouchDefinition(type: Object, qualifier?: string | symbol): boolean;
|
||||||
|
getPouchDefinitions(): PouchDefinition[];
|
||||||
|
getPouchDefinitionCount(): number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default PouchDefinitionRegistry;
|
|
@ -1,2 +1 @@
|
||||||
export * from './inject';
|
export * from './inject';
|
||||||
export * from './pouch';
|
|
8
src/ts/@loafer/pouches/util/metadata/inject.ts
Normal file
8
src/ts/@loafer/pouches/util/metadata/inject.ts
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
import getClassMetadata from '@loafer/core/util/metadata/getClassMetadata';
|
||||||
|
|
||||||
|
import { POUCH_INJECT_DEFINITION } from '@loafer/pouches/constants';
|
||||||
|
import InjectDefinition from '@loafer/pouches/definition/InjectDefinition';
|
||||||
|
|
||||||
|
export const getInjectDefinition =
|
||||||
|
(target: Object, isCreate: boolean = false) =>
|
||||||
|
getClassMetadata(target, POUCH_INJECT_DEFINITION, InjectDefinition, isCreate);
|
|
@ -1,39 +0,0 @@
|
||||||
import { SagaIterator } from 'redux-saga';
|
|
||||||
import { call, Effect, fork, put, takeLatest } from 'redux-saga/effects';
|
|
||||||
|
|
||||||
|
|
||||||
import AppContext from '@overflow/commons/context/AppContext';
|
|
||||||
import Action from '@overflow/commons/redux/Action';
|
|
||||||
|
|
||||||
import ApiKey from '../../api/model/ApiKey';
|
|
||||||
import ApiKeyService from '../../api/service/ApiKeyService';
|
|
||||||
import * as ReadActions from '../action/read';
|
|
||||||
import ReadPayload from '../payload/ReadPayload';
|
|
||||||
|
|
||||||
function* read(action: Action<ReadPayload>): SagaIterator {
|
|
||||||
try {
|
|
||||||
const {domain} = action.payload;
|
|
||||||
// yield put({
|
|
||||||
// type: types.SENDING_REQUEST,
|
|
||||||
// payload: {sendingRequest: true},
|
|
||||||
// });
|
|
||||||
let apiKeyService = AppContext.getInstance().getPouch(ApiKeyService);
|
|
||||||
const retApikey = yield call({context: apiKeyService, fn: apiKeyService.read}, domain);
|
|
||||||
|
|
||||||
// if (responseBody.token === undefined) {
|
|
||||||
// throw new Error(MESSAGES.UNABLE_TO_FIND_TOKEN_IN_LOGIN_RESPONSE);
|
|
||||||
// }
|
|
||||||
yield put(ReadActions.requestSuccess(retApikey));
|
|
||||||
} catch (e) {
|
|
||||||
yield put(ReadActions.requestFailure(e));
|
|
||||||
} finally {
|
|
||||||
// yield put({
|
|
||||||
// type: types.SENDING_REQUEST,
|
|
||||||
// payload: {sendingRequest: false},
|
|
||||||
// });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export function* watchRead(): SagaIterator {
|
|
||||||
yield takeLatest(ReadActions.REQUEST, read);
|
|
||||||
}
|
|
|
@ -1,39 +0,0 @@
|
||||||
import { SagaIterator } from 'redux-saga';
|
|
||||||
import { call, Effect, fork, put, takeLatest } from 'redux-saga/effects';
|
|
||||||
|
|
||||||
|
|
||||||
import AppContext from '@overflow/commons/context/AppContext';
|
|
||||||
import Action from '@overflow/commons/redux/Action';
|
|
||||||
|
|
||||||
import ApiKey from '../../api/model/ApiKey';
|
|
||||||
import ApiKeyService from '../../api/service/ApiKeyService';
|
|
||||||
import * as RegistActions from '../action/regist';
|
|
||||||
import RegistPayload from '../payload/RegistPayload';
|
|
||||||
|
|
||||||
function* regist(action: Action<RegistPayload>): SagaIterator {
|
|
||||||
try {
|
|
||||||
const {apiKey} = action.payload;
|
|
||||||
// yield put({
|
|
||||||
// type: types.SENDING_REQUEST,
|
|
||||||
// payload: {sendingRequest: true},
|
|
||||||
// });
|
|
||||||
let apiKeyService: ApiKeyService = AppContext.getInstance().getPouch(ApiKeyService);
|
|
||||||
const retApikey = yield call({context: apiKeyService, fn: apiKeyService.regist}, apiKey);
|
|
||||||
|
|
||||||
// if (responseBody.token === undefined) {
|
|
||||||
// throw new Error(MESSAGES.UNABLE_TO_FIND_TOKEN_IN_LOGIN_RESPONSE);
|
|
||||||
// }
|
|
||||||
yield put(RegistActions.requestSuccess(retApikey));
|
|
||||||
} catch (e) {
|
|
||||||
yield put(RegistActions.requestFailure(e));
|
|
||||||
} finally {
|
|
||||||
// yield put({
|
|
||||||
// type: types.SENDING_REQUEST,
|
|
||||||
// payload: {sendingRequest: false},
|
|
||||||
// });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export function* watchRegist(): SagaIterator {
|
|
||||||
yield takeLatest(RegistActions.REQUEST, regist);
|
|
||||||
}
|
|
|
@ -1,5 +1,5 @@
|
||||||
import Configuration from '@overflow/commons/context/decorator/Configuration';
|
import Configuration from '@loafer/context/decorator/Configuration';
|
||||||
import Pouch from '@overflow/commons/context/decorator/Pouch';
|
import Pouch from '@loafer/context/decorator/Pouch';
|
||||||
import WebSocketRPC from '@overflow/commons/websocket/WebSocketRPC';
|
import WebSocketRPC from '@overflow/commons/websocket/WebSocketRPC';
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -42,8 +42,8 @@ import {
|
||||||
import * as injectTapEventPlugin from 'react-tap-event-plugin';
|
import * as injectTapEventPlugin from 'react-tap-event-plugin';
|
||||||
|
|
||||||
import Platform from '@overflow/commons/platform';
|
import Platform from '@overflow/commons/platform';
|
||||||
import AppContext from '@overflow/commons/context/AppContext';
|
import AppContext from '@loafer/context/AppContext';
|
||||||
import * as AppContextLifecycleActions from '@overflow/commons/context/redux/action/lifecycle';
|
import * as AppContextLifecycleActions from '@loafer/context/redux/action/lifecycle';
|
||||||
import WebSocketRPC from '@overflow/commons/websocket/WebSocketRPC';
|
import WebSocketRPC from '@overflow/commons/websocket/WebSocketRPC';
|
||||||
import ReducerContext from '@overflow/commons/redux/ReducerContext';
|
import ReducerContext from '@overflow/commons/redux/ReducerContext';
|
||||||
import { SagaWatcher } from '@overflow/commons/redux-saga';
|
import { SagaWatcher } from '@overflow/commons/redux-saga';
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import Inject from '../context/pouches/decorator/Inject';
|
import Inject from '@loafer/pouches/decorator/Inject';
|
||||||
import WebSocketRPC from '../websocket/WebSocketRPC';
|
import WebSocketRPC from '../websocket/WebSocketRPC';
|
||||||
|
|
||||||
abstract class Service {
|
abstract class Service {
|
||||||
|
|
|
@ -1,42 +0,0 @@
|
||||||
import * as CoreConstants from '@overflow/commons/core/constants';
|
|
||||||
import PouchFactory from './pouches/factory/PouchFactory';
|
|
||||||
|
|
||||||
class AppContext {
|
|
||||||
private static _instance: AppContext;
|
|
||||||
private _pouchFactory: PouchFactory;
|
|
||||||
|
|
||||||
public constructor() {
|
|
||||||
this._pouchFactory = new PouchFactory();
|
|
||||||
}
|
|
||||||
|
|
||||||
public get PouchFactory(): PouchFactory {
|
|
||||||
return this._pouchFactory;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* getPouch
|
|
||||||
*/
|
|
||||||
public getPouch<T>(type: CoreConstants.Newable<T>, ...args: any[]): T {
|
|
||||||
return this._pouchFactory.getPouch(type, args);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* getPouchByQualifier
|
|
||||||
*/
|
|
||||||
public getPouchByQualifier<T>(type: CoreConstants.Newable<T>, qualifier: string | symbol, ...args: any[]): T {
|
|
||||||
return this._pouchFactory.getPouchByQualifier(type, qualifier, args);
|
|
||||||
}
|
|
||||||
|
|
||||||
public destroy(): void {
|
|
||||||
console.log('AppContext has been destroyed.');
|
|
||||||
}
|
|
||||||
|
|
||||||
public static getInstance(): AppContext {
|
|
||||||
if (undefined === AppContext._instance) {
|
|
||||||
AppContext._instance = new AppContext();
|
|
||||||
}
|
|
||||||
return AppContext._instance;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export default AppContext;
|
|
|
@ -1,46 +0,0 @@
|
||||||
import { POUCH_DEFAULT_QUALIFIER } from '../pouches/constants';
|
|
||||||
import PouchConfig from '../decorator/PouchConfig';
|
|
||||||
import * as CoreConstants from '@overflow/commons/core/constants';
|
|
||||||
|
|
||||||
class ConfigurationDefinition {
|
|
||||||
protected _type: Function;
|
|
||||||
protected _qualifier: string | symbol = undefined;
|
|
||||||
protected _pouchMap: Map<string, PouchConfig>;
|
|
||||||
|
|
||||||
public constructor(type: Function) {
|
|
||||||
this._type = type;
|
|
||||||
this._qualifier = POUCH_DEFAULT_QUALIFIER;
|
|
||||||
}
|
|
||||||
|
|
||||||
public get type(): Function {
|
|
||||||
return this._type;
|
|
||||||
}
|
|
||||||
|
|
||||||
public get qualifier(): string | symbol {
|
|
||||||
return this._qualifier;
|
|
||||||
}
|
|
||||||
|
|
||||||
public set qualifier(qualifier: string | symbol) {
|
|
||||||
this._qualifier = qualifier;
|
|
||||||
}
|
|
||||||
|
|
||||||
public addPouch(propertyKey: string, pouchConfig: PouchConfig): void {
|
|
||||||
if (undefined === this._pouchMap) {
|
|
||||||
this._pouchMap = new Map();
|
|
||||||
}
|
|
||||||
let returnType: any = Reflect.getMetadata(CoreConstants.DESIGN_RETURNTYPE, this._type, propertyKey);
|
|
||||||
|
|
||||||
if (undefined === pouchConfig.type) {
|
|
||||||
pouchConfig.type = returnType;
|
|
||||||
}
|
|
||||||
|
|
||||||
this._pouchMap.set(propertyKey, pouchConfig);
|
|
||||||
}
|
|
||||||
|
|
||||||
public get Pouches(): Map<string, PouchConfig> {
|
|
||||||
return this._pouchMap;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
export default ConfigurationDefinition;
|
|
|
@ -1,2 +0,0 @@
|
||||||
export const CONTEXT_CONFIGURATION_DEFINITION = 'overflow:context/configuration_definition';
|
|
||||||
export const CONTEXT_POUCH_DEFINITION = 'overflow:context/pouch_definition';
|
|
|
@ -1,20 +0,0 @@
|
||||||
import ConfigurationDefinition from '../config/ConfigurationDefinition';
|
|
||||||
|
|
||||||
import createDecorator from '../../util/decorators/createDecorator';
|
|
||||||
import { getConfigurationDefinition } from '../util/metadata';
|
|
||||||
|
|
||||||
const Configuration = createDecorator('Configuration', {
|
|
||||||
classDecorator: <TFunction extends Function>(target: TFunction): TFunction | void => {
|
|
||||||
let configurationDefinition: ConfigurationDefinition = getConfigurationDefinition(target, false);
|
|
||||||
if (undefined !== configurationDefinition) {
|
|
||||||
throw new Error('Cannot apply @Configuration decorator multiple times.');
|
|
||||||
}
|
|
||||||
|
|
||||||
configurationDefinition = getConfigurationDefinition(target, true);
|
|
||||||
|
|
||||||
return target;
|
|
||||||
},
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
export default Configuration;
|
|
|
@ -1,21 +0,0 @@
|
||||||
import PouchConfig from './PouchConfig';
|
|
||||||
import ConfigurationDefinition from '../config/ConfigurationDefinition';
|
|
||||||
import createDecorator from '@overflow/commons/util/decorators/createDecorator';
|
|
||||||
|
|
||||||
import { getConfigurationDefinition } from '../util/metadata';
|
|
||||||
|
|
||||||
|
|
||||||
const Pouch = (pouchConfig: PouchConfig = {}) => createDecorator('Pouch', {
|
|
||||||
methodDecorator: (target: Object, propertyKey: string, descriptor: TypedPropertyDescriptor<any>): TypedPropertyDescriptor<any> => {
|
|
||||||
let configurationDefinition: ConfigurationDefinition = getConfigurationDefinition(target, false);
|
|
||||||
if (undefined === configurationDefinition) {
|
|
||||||
throw new Error('Cannot apply @Pouch decorator on the not @Configuration class.');
|
|
||||||
}
|
|
||||||
|
|
||||||
configurationDefinition.addPouch(propertyKey, pouchConfig);
|
|
||||||
|
|
||||||
return descriptor;
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
export default Pouch;
|
|
|
@ -1,59 +0,0 @@
|
||||||
import { PouchScope, POUCH_DEFAULT_QUALIFIER } from '../constants';
|
|
||||||
|
|
||||||
class PouchDefinition {
|
|
||||||
protected _type: Object;
|
|
||||||
protected _scope: PouchScope = PouchScope.SINGLETON;
|
|
||||||
protected _qualifier: string | symbol = undefined;
|
|
||||||
protected _postConstruct: Set<string> = undefined;
|
|
||||||
protected _preDestroy: Set<string> = undefined;
|
|
||||||
|
|
||||||
public constructor(type: Object) {
|
|
||||||
this._type = type;
|
|
||||||
this._qualifier = POUCH_DEFAULT_QUALIFIER;
|
|
||||||
}
|
|
||||||
|
|
||||||
public get type(): Object {
|
|
||||||
return this._type;
|
|
||||||
}
|
|
||||||
|
|
||||||
public get scope(): PouchScope {
|
|
||||||
return this._scope;
|
|
||||||
}
|
|
||||||
|
|
||||||
public set scope(scope: PouchScope) {
|
|
||||||
this._scope = scope;
|
|
||||||
}
|
|
||||||
|
|
||||||
public get qualifier(): string | symbol {
|
|
||||||
return this._qualifier;
|
|
||||||
}
|
|
||||||
|
|
||||||
public set qualifier(qualifier: string | symbol) {
|
|
||||||
this._qualifier = qualifier;
|
|
||||||
}
|
|
||||||
|
|
||||||
public get postConstruct(): Set<string> {
|
|
||||||
return this._postConstruct;
|
|
||||||
}
|
|
||||||
|
|
||||||
public addPostConstruct(postConstruct: string): void {
|
|
||||||
if (undefined === this._postConstruct) {
|
|
||||||
this._postConstruct = new Set();
|
|
||||||
}
|
|
||||||
this._postConstruct.add(postConstruct);
|
|
||||||
}
|
|
||||||
|
|
||||||
public get preDestroy(): Set<string> {
|
|
||||||
return this._preDestroy;
|
|
||||||
}
|
|
||||||
|
|
||||||
public addPreDestroy(preDestroy: string): void {
|
|
||||||
if (undefined === this._preDestroy) {
|
|
||||||
this._preDestroy = new Set();
|
|
||||||
}
|
|
||||||
this._preDestroy.add(preDestroy);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
export default PouchDefinition;
|
|
|
@ -1,2 +0,0 @@
|
||||||
export * from './reflect';
|
|
||||||
export * from './types';
|
|
|
@ -1,5 +0,0 @@
|
||||||
// used to store types to be injected
|
|
||||||
export const POUCH_DEFINITION = 'loafer:pouch:definition';
|
|
||||||
|
|
||||||
// used to store types to be injected
|
|
||||||
export const POUCH_INJECT_DEFINITION = 'loafer:pouch:inject_definition';
|
|
|
@ -1,7 +0,0 @@
|
||||||
export const POUCH_DEFAULT_QUALIFIER = Symbol('__QUALIFIER__');
|
|
||||||
|
|
||||||
export enum PouchScope {
|
|
||||||
SINGLETON,
|
|
||||||
TRANSIENT,
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,21 +0,0 @@
|
||||||
import * as METADATA from '../constants';
|
|
||||||
import { POUCH_DEFAULT_QUALIFIER } from '../constants';
|
|
||||||
import InjectConfig from './InjectConfig';
|
|
||||||
import PouchInjectDefinition from '../config/PouchInjectDefinition';
|
|
||||||
import createDecorator from '@overflow/commons/util/decorators/createDecorator';
|
|
||||||
import { getPouchInjectDefinition } from '../util/metadata';
|
|
||||||
|
|
||||||
const Inject = (injectConfig: InjectConfig = {}) => createDecorator('Inject', {
|
|
||||||
propertyDecorator: (target: Object, propertyKey: string | symbol): void => {
|
|
||||||
let pouchInjectDefinition: PouchInjectDefinition = getPouchInjectDefinition(target, true);
|
|
||||||
pouchInjectDefinition.addInject(injectConfig, propertyKey);
|
|
||||||
},
|
|
||||||
parameterDecorator: (target: Object, propertyKey: string | symbol, parameterIndex: number): void => {
|
|
||||||
let pouchInjectDefinition: PouchInjectDefinition = getPouchInjectDefinition(target, true);
|
|
||||||
pouchInjectDefinition.addInject(injectConfig, propertyKey, parameterIndex);
|
|
||||||
},
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
export default Inject;
|
|
|
@ -1,21 +0,0 @@
|
||||||
import * as METADATA from '../constants';
|
|
||||||
import PouchDefinition from '../config/PouchDefinition';
|
|
||||||
import createDecorator from '@overflow/commons/util/decorators/createDecorator';
|
|
||||||
import { getPouchDefinition } from '../util/metadata';
|
|
||||||
|
|
||||||
const Injectable = createDecorator('Injectable', {
|
|
||||||
classDecorator: <TFunction extends Function>(target: TFunction): TFunction | void => {
|
|
||||||
let pouchDefinition: PouchDefinition = getPouchDefinition(target, false);
|
|
||||||
if (undefined !== pouchDefinition) {
|
|
||||||
throw new Error('Cannot apply @injectable decorator multiple times.');
|
|
||||||
}
|
|
||||||
|
|
||||||
pouchDefinition = getPouchDefinition(target.prototype, true);
|
|
||||||
|
|
||||||
return target;
|
|
||||||
},
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
export default Injectable;
|
|
|
@ -1,17 +0,0 @@
|
||||||
import * as METADATA from '../constants';
|
|
||||||
import PouchDefinition from '../config/PouchDefinition';
|
|
||||||
import createDecorator from '@overflow/commons/util/decorators/createDecorator';
|
|
||||||
import { getPouchDefinition } from '../util/metadata';
|
|
||||||
|
|
||||||
const PostConstruct = createDecorator('PostConstruct', {
|
|
||||||
methodDecorator: (target: Object, propertyKey: string, descriptor: TypedPropertyDescriptor<any>): TypedPropertyDescriptor<any> => {
|
|
||||||
let pouchDefinition = getPouchDefinition(target, false);
|
|
||||||
if (undefined === pouchDefinition) {
|
|
||||||
throw new Error('Cannot apply @PostConstruct decorator on the not @Injectable class.');
|
|
||||||
}
|
|
||||||
pouchDefinition.addPostConstruct(propertyKey);
|
|
||||||
return descriptor;
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
export default PostConstruct;
|
|
|
@ -1,17 +0,0 @@
|
||||||
import * as METADATA from '../constants';
|
|
||||||
import PouchDefinition from '../config/PouchDefinition';
|
|
||||||
import createDecorator from '@overflow/commons/util/decorators/createDecorator';
|
|
||||||
import { getPouchDefinition } from '../util/metadata';
|
|
||||||
|
|
||||||
const PreDestroy = createDecorator('PreDestroy', {
|
|
||||||
methodDecorator: (target: Object, propertyKey: string, descriptor: TypedPropertyDescriptor<any>): TypedPropertyDescriptor<any> => {
|
|
||||||
let pouchDefinition = getPouchDefinition(target, false);
|
|
||||||
if (undefined === pouchDefinition) {
|
|
||||||
throw new Error('Cannot apply @PreDestroy decorator on the not @Injectable class.');
|
|
||||||
}
|
|
||||||
pouchDefinition.addPreDestroy(propertyKey);
|
|
||||||
return descriptor;
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
export default PreDestroy;
|
|
|
@ -1,21 +0,0 @@
|
||||||
import * as METADATA from '../constants';
|
|
||||||
import PouchDefinition from '../config/PouchDefinition';
|
|
||||||
import createDecorator from '@overflow/commons/util/decorators/createDecorator';
|
|
||||||
import { getPouchDefinition } from '../util/metadata';
|
|
||||||
|
|
||||||
const Qualifier = (value: string | symbol) => createDecorator('Qualifier', {
|
|
||||||
classDecorator: <TFunction extends Function>(target: TFunction): TFunction | void => {
|
|
||||||
let pouchDefinition = getPouchDefinition(target, false);
|
|
||||||
if (undefined === pouchDefinition) {
|
|
||||||
throw new Error('Cannot apply @Qualifier decorator on the not @Injectable class.');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (undefined !== pouchDefinition.qualifier) {
|
|
||||||
throw new Error('Cannot apply @Qualifier decorator multiple times.');
|
|
||||||
}
|
|
||||||
pouchDefinition.qualifier = value;
|
|
||||||
return target;
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
export default Qualifier;
|
|
|
@ -1,18 +0,0 @@
|
||||||
import * as METADATA from '../constants';
|
|
||||||
import PouchDefinition from '../config/PouchDefinition';
|
|
||||||
import { PouchScope } from '../constants';
|
|
||||||
import createDecorator from '@overflow/commons/util/decorators/createDecorator';
|
|
||||||
import { getPouchDefinition } from '../util/metadata';
|
|
||||||
|
|
||||||
const Scope = (value: PouchScope = PouchScope.SINGLETON) => createDecorator('Scope', {
|
|
||||||
classDecorator: <TFunction extends Function>(target: TFunction): TFunction | void => {
|
|
||||||
let pouchDefinition = getPouchDefinition(target, false);
|
|
||||||
if (undefined === pouchDefinition) {
|
|
||||||
throw new Error('Cannot apply @Scope decorator on the not @Injectable class.');
|
|
||||||
}
|
|
||||||
pouchDefinition.scope = value;
|
|
||||||
return target;
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
export default Scope;
|
|
|
@ -1,194 +0,0 @@
|
||||||
import { DecoratorType, Newable } from '@overflow/commons/core/constants';
|
|
||||||
import * as METADATA from '../constants';
|
|
||||||
|
|
||||||
import {
|
|
||||||
PouchScope,
|
|
||||||
POUCH_DEFAULT_QUALIFIER,
|
|
||||||
} from '../constants';
|
|
||||||
|
|
||||||
import PouchDefinition from '../config/PouchDefinition';
|
|
||||||
|
|
||||||
import PouchInjectDefinition, {
|
|
||||||
InjectItem,
|
|
||||||
} from '../config/PouchInjectDefinition';
|
|
||||||
|
|
||||||
import InjectConfig from '../decorator/InjectConfig';
|
|
||||||
|
|
||||||
class PouchFactory {
|
|
||||||
private pouchDefinitionMap: Map<Function, PouchDefinition>;
|
|
||||||
private pouchInstanceMap: Map<Function, Map<string | symbol, any>>;
|
|
||||||
|
|
||||||
public constructor() {
|
|
||||||
this.pouchDefinitionMap = new Map();
|
|
||||||
this.pouchInstanceMap = new Map();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* getPouch
|
|
||||||
*/
|
|
||||||
public getPouch<T>(type: Newable<T>, ...args: any[]): T {
|
|
||||||
let qualifier = POUCH_DEFAULT_QUALIFIER;
|
|
||||||
return this.getPouchByQualifier(type, qualifier, args);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* getPouchByQualifier
|
|
||||||
*/
|
|
||||||
public getPouchByQualifier<T>(type: Newable<T>, qualifier: string | symbol, ...args: any[]): T {
|
|
||||||
let clazz: Function = type.prototype;
|
|
||||||
|
|
||||||
let instance = this._getPouch(clazz, qualifier, args);
|
|
||||||
|
|
||||||
return instance;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* registerPouch
|
|
||||||
*/
|
|
||||||
public registerPouch(pouch: any, qualifier: string | symbol = POUCH_DEFAULT_QUALIFIER): void {
|
|
||||||
let clazz = Object.getPrototypeOf(pouch);
|
|
||||||
this._putPouchInstance(clazz, qualifier, pouch);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* registerPouch
|
|
||||||
*/
|
|
||||||
public registerPouchDefinition<T>(type: Newable<T>, pouchDefinition: PouchDefinition): void {
|
|
||||||
let clazz: Function = type.prototype;
|
|
||||||
if (this.pouchDefinitionMap.has(clazz)) {
|
|
||||||
throw new Error(`Pouch Definition of [${clazz.name}] is already exist.`);
|
|
||||||
}
|
|
||||||
this.pouchDefinitionMap.set(clazz, pouchDefinition);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected getPouchDefinition(clazz: Function): PouchDefinition {
|
|
||||||
let pouchDefinition: PouchDefinition = this.pouchDefinitionMap.get(clazz);
|
|
||||||
if (undefined !== pouchDefinition) {
|
|
||||||
return pouchDefinition;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Reflect.hasOwnMetadata(METADATA.POUCH_DEFINITION, clazz) !== true) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
pouchDefinition = Reflect.getMetadata(METADATA.POUCH_DEFINITION, clazz);
|
|
||||||
this.pouchDefinitionMap.set(clazz, pouchDefinition);
|
|
||||||
|
|
||||||
return pouchDefinition;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
protected getPouchInjectDefinition(clazz: Function): PouchInjectDefinition {
|
|
||||||
if (Reflect.hasOwnMetadata(METADATA.POUCH_INJECT_DEFINITION, clazz) !== true) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
let pouchInjectDefinition: PouchInjectDefinition = Reflect.getMetadata(METADATA.POUCH_INJECT_DEFINITION, clazz);
|
|
||||||
|
|
||||||
return pouchInjectDefinition;
|
|
||||||
}
|
|
||||||
|
|
||||||
private _getPouch(clazz: Function, qualifier: string | symbol, ...args: any[]): any {
|
|
||||||
let pouchDefinition: PouchDefinition = this.getPouchDefinition(clazz);
|
|
||||||
|
|
||||||
let instance: any;
|
|
||||||
if (null == pouchDefinition) {
|
|
||||||
if (this._hasPouchInstance(clazz, qualifier)) {
|
|
||||||
instance = this._getPouchInstance(clazz, qualifier);
|
|
||||||
} else {
|
|
||||||
instance = this._newInstance(clazz, pouchDefinition, args);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (pouchDefinition.scope === PouchScope.TRANSIENT) {
|
|
||||||
instance = this._newInstance(clazz, pouchDefinition, args);
|
|
||||||
} else {
|
|
||||||
if (this._hasPouchInstance(clazz, qualifier)) {
|
|
||||||
return this._getPouchInstance(clazz, qualifier);
|
|
||||||
}
|
|
||||||
instance = this._newInstance(clazz, pouchDefinition, args);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return instance;
|
|
||||||
}
|
|
||||||
|
|
||||||
private _newInstance(clazz: Function, pouchDefinition: PouchDefinition, ...args: any[]): any {
|
|
||||||
let instance: any;
|
|
||||||
instance = Object.create(clazz);
|
|
||||||
instance.constructor.apply(instance, args);
|
|
||||||
|
|
||||||
this._injectDependency(instance, clazz);
|
|
||||||
|
|
||||||
return instance;
|
|
||||||
}
|
|
||||||
|
|
||||||
private _injectDependency(target: object, clazz: Function): void {
|
|
||||||
if (clazz.constructor === Object) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
let pouchInjectDefinition: PouchInjectDefinition = this.getPouchInjectDefinition(clazz);
|
|
||||||
if (null !== pouchInjectDefinition) {
|
|
||||||
let injectors: Map<string | symbol, InjectItem> = pouchInjectDefinition.injectors;
|
|
||||||
let propertyDescriptor: any;
|
|
||||||
injectors.forEach((injectItem, key, map) => {
|
|
||||||
propertyDescriptor = Object.getOwnPropertyDescriptor(target, key);
|
|
||||||
|
|
||||||
switch (injectItem.decoratorType) {
|
|
||||||
case DecoratorType.PROPERTY:
|
|
||||||
this._injectDependencyProperty(target, clazz, key, propertyDescriptor, injectItem.propertyConfig);
|
|
||||||
break;
|
|
||||||
case DecoratorType.PARAMETER:
|
|
||||||
this._injectDependencyParameter(target, propertyDescriptor, injectItem.parameterConfigMap);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
this._injectDependency(target, Object.getPrototypeOf(clazz));
|
|
||||||
}
|
|
||||||
|
|
||||||
private _injectDependencyProperty(target: object, clazz: Function, propertyKey: string | symbol,
|
|
||||||
propertyDescriptor: PropertyDescriptor, injectConfig: InjectConfig): void {
|
|
||||||
let instance = this.getPouch(injectConfig.type, injectConfig.qualifier);
|
|
||||||
if (injectConfig.required && undefined === instance) {
|
|
||||||
throw new Error(`Pouch which used by [${clazz.name}.${propertyKey}] is not exist in the context.`);
|
|
||||||
}
|
|
||||||
target[propertyKey] = instance;
|
|
||||||
}
|
|
||||||
|
|
||||||
private _injectDependencyParameter(target: object, propertyDescriptor: PropertyDescriptor,
|
|
||||||
parameterConfigs: Map<number, InjectConfig>): void {
|
|
||||||
console.log('');
|
|
||||||
}
|
|
||||||
|
|
||||||
private _hasPouchInstance(clazz: Function, qualifier: string | symbol): boolean {
|
|
||||||
if (!this.pouchInstanceMap.has(clazz) || !this.pouchInstanceMap.get(clazz).has(qualifier)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
private _getPouchInstance(clazz: Function, qualifier: string | symbol): any {
|
|
||||||
if (!this._hasPouchInstance(clazz, qualifier)) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return this.pouchInstanceMap.get(clazz).get(qualifier);
|
|
||||||
}
|
|
||||||
|
|
||||||
private _putPouchInstance(clazz: Function, qualifier: string | symbol, instance: any): void {
|
|
||||||
let instanceMap: Map<string | symbol, any> = this.pouchInstanceMap.get(clazz);
|
|
||||||
|
|
||||||
if (undefined === instanceMap) {
|
|
||||||
instanceMap = new Map();
|
|
||||||
this.pouchInstanceMap.set(clazz, instanceMap);
|
|
||||||
}
|
|
||||||
|
|
||||||
instanceMap.set(qualifier, instance);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
export default PouchFactory;
|
|
|
@ -1,8 +0,0 @@
|
||||||
import getClassMetadata from '@overflow/commons/util/metadata/getClassMetadata';
|
|
||||||
|
|
||||||
import * as METADATA from '../../constants';
|
|
||||||
import PouchInjectDefinition from '../../config/PouchInjectDefinition';
|
|
||||||
|
|
||||||
export const getPouchInjectDefinition =
|
|
||||||
<TFunction extends Function>(target: TFunction | Object, isCreate: boolean = false) =>
|
|
||||||
getClassMetadata(target, METADATA.POUCH_INJECT_DEFINITION, PouchInjectDefinition, isCreate);
|
|
|
@ -1,8 +0,0 @@
|
||||||
import getClassMetadata from '@overflow/commons/util/metadata/getClassMetadata';
|
|
||||||
|
|
||||||
import * as METADATA from '../../constants';
|
|
||||||
import PouchDefinition from '../../config/PouchDefinition';
|
|
||||||
|
|
||||||
export const getPouchDefinition =
|
|
||||||
<TFunction extends Function>(target: TFunction | Object, isCreate: boolean = false) =>
|
|
||||||
getClassMetadata(target, METADATA.POUCH_DEFINITION, PouchDefinition, isCreate);
|
|
|
@ -1,9 +0,0 @@
|
||||||
import getClassMetadata from '@overflow/commons/util/metadata/getClassMetadata';
|
|
||||||
|
|
||||||
import * as METADATA from '../../constants';
|
|
||||||
import ConfigurationDefinition from '../../config/ConfigurationDefinition';
|
|
||||||
|
|
||||||
export const getConfigurationDefinition =
|
|
||||||
<TFunction extends Function>(target: TFunction | Object, isCreate: boolean = false) =>
|
|
||||||
getClassMetadata(target, METADATA.CONTEXT_CONFIGURATION_DEFINITION, ConfigurationDefinition, isCreate);
|
|
||||||
|
|
|
@ -1,3 +0,0 @@
|
||||||
import { SagaIterator } from 'redux-saga';
|
|
||||||
|
|
||||||
export type SagaWatcher = () => SagaIterator;
|
|
22
src/ts/@overflow/commons/redux/action/asyncRequest.ts
Normal file
22
src/ts/@overflow/commons/redux/action/asyncRequest.ts
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
import Action from '@overflow/commons/redux/Action';
|
||||||
|
import AsyncRequestPayload from '../payload/AsyncRequestPayload';
|
||||||
|
|
||||||
|
// Action Type
|
||||||
|
export type REQUEST = '@@overflow/anync/REQUEST';
|
||||||
|
|
||||||
|
export const REQUEST: REQUEST = '@@overflow/anync/REQUEST';
|
||||||
|
|
||||||
|
// Action Creater
|
||||||
|
export type request = (service: string, method: string, requestType: string, ...args: any[]) => Action<AsyncRequestPayload>;
|
||||||
|
|
||||||
|
export const request: request = (service: string, method: string, requestType: string, ...args: any[]): Action<AsyncRequestPayload> => {
|
||||||
|
return {
|
||||||
|
type: REQUEST,
|
||||||
|
payload: {
|
||||||
|
service: service,
|
||||||
|
method: method,
|
||||||
|
requestType: requestType,
|
||||||
|
args: args,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
};
|
|
@ -0,0 +1,10 @@
|
||||||
|
import Action from '@overflow/commons/redux/Action';
|
||||||
|
|
||||||
|
interface AsyncRequestPayload {
|
||||||
|
service: string;
|
||||||
|
method: string;
|
||||||
|
requestType: string;
|
||||||
|
args?: any[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export default AsyncRequestPayload;
|
|
@ -1,24 +1,21 @@
|
||||||
import { SagaIterator } from 'redux-saga';
|
import { SagaIterator } from 'redux-saga';
|
||||||
import { call, Effect, fork, put, takeLatest } from 'redux-saga/effects';
|
import { call, Effect, fork, put, takeEvery } from 'redux-saga/effects';
|
||||||
|
|
||||||
import { SagaWatcher } from '@overflow/commons/redux-saga';
|
import AppContext from '@loafer/context/AppContext';
|
||||||
|
|
||||||
import AppContext from '@overflow/commons/context/AppContext';
|
|
||||||
import Action from '@overflow/commons/redux/Action';
|
import Action from '@overflow/commons/redux/Action';
|
||||||
|
|
||||||
import Member from '../../api/model/Member';
|
import * as AsyncRequestActions from '../action/asyncRequest';
|
||||||
import MemberService from '../../api/service/MemberService';
|
import AsyncRequestPayload from '../payload/AsyncRequestPayload';
|
||||||
import * as SigninActions from '../action/signIn';
|
|
||||||
import SigninPayload from '../payload/SignInPayload';
|
|
||||||
|
|
||||||
function* signin(action: Action<SigninPayload>): SagaIterator {
|
function* request(action: Action<AsyncRequestPayload>): SagaIterator {
|
||||||
try {
|
try {
|
||||||
const {signinId, signinPw} = action.payload;
|
const {service, method, requestType, args} = action.payload;
|
||||||
// yield put({
|
// yield put({
|
||||||
// type: types.SENDING_REQUEST,
|
// type: types.SENDING_REQUEST,
|
||||||
// payload: {sendingRequest: true},
|
// payload: {sendingRequest: true},
|
||||||
// });
|
// });
|
||||||
let memberService = AppContext.getInstance().getPouch(MemberService);
|
let serviceInstance = AppContext.getInstance().getService(service);
|
||||||
|
|
||||||
|
|
||||||
const member = yield call({context: memberService, fn: memberService.signin}, signinId, signinPw);
|
const member = yield call({context: memberService, fn: memberService.signin}, signinId, signinPw);
|
||||||
|
|
||||||
|
@ -36,8 +33,8 @@ function* signin(action: Action<SigninPayload>): SagaIterator {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function* watchSignin(): SagaIterator {
|
function* watchAsyncRequest(): SagaIterator {
|
||||||
yield takeLatest(SigninActions.REQUEST, signin);
|
yield takeEvery(AsyncRequestActions.REQUEST, request);
|
||||||
}
|
}
|
||||||
|
|
||||||
const sagaWatchers: SagaWatcher[] = [watchSignin];
|
const sagaWatchers: SagaWatcher[] = [watchSignin];
|
|
@ -1,24 +0,0 @@
|
||||||
export type MetadataDefinable<T> = {new(target: Function): T};
|
|
||||||
|
|
||||||
const getClassMetadata = <TFunction extends Function, DefinitionType>(target: TFunction | Object,
|
|
||||||
metadataKey: any,
|
|
||||||
definitionType: MetadataDefinable<DefinitionType>,
|
|
||||||
isCreate: boolean = false): DefinitionType => {
|
|
||||||
|
|
||||||
let clazz = target instanceof Function ? target.prototype : target;
|
|
||||||
let definition: DefinitionType;
|
|
||||||
if (Reflect.hasOwnMetadata(metadataKey, clazz) !== true) {
|
|
||||||
if (!isCreate) {
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
definition = Object.create(definitionType.prototype);
|
|
||||||
definition.constructor.call(definition, clazz);
|
|
||||||
|
|
||||||
Reflect.defineMetadata(metadataKey, definition, clazz);
|
|
||||||
} else {
|
|
||||||
definition = Reflect.getMetadata(metadataKey, clazz);
|
|
||||||
}
|
|
||||||
return definition;
|
|
||||||
};
|
|
||||||
|
|
||||||
export default getClassMetadata;
|
|
|
@ -1,39 +0,0 @@
|
||||||
import { SagaIterator } from 'redux-saga';
|
|
||||||
import { call, Effect, fork, put, takeLatest } from 'redux-saga/effects';
|
|
||||||
|
|
||||||
|
|
||||||
import AppContext from '@overflow/commons/context/AppContext';
|
|
||||||
import Action from '@overflow/commons/redux/Action';
|
|
||||||
|
|
||||||
import DomainMember from '../../api/model/DomainMember';
|
|
||||||
import DomainMemberService from '../../api/service/DomainMemberService';
|
|
||||||
import * as MemberRegistActions from '../action/member_regist';
|
|
||||||
import MemberRegistPayload from '../payload/MemberRegistPayload';
|
|
||||||
|
|
||||||
function* regist(action: Action<MemberRegistPayload>): SagaIterator {
|
|
||||||
try {
|
|
||||||
const dm = action.payload.domainMember;
|
|
||||||
// yield put({
|
|
||||||
// type: types.SENDING_REQUEST,
|
|
||||||
// payload: {sendingRequest: true},
|
|
||||||
// });
|
|
||||||
let domainMemberService = AppContext.getInstance().getPouch(DomainMemberService);
|
|
||||||
yield call({context: domainMemberService, fn: domainMemberService.regist}, dm);
|
|
||||||
|
|
||||||
// if (responseBody.token === undefined) {
|
|
||||||
// throw new Error(MESSAGES.UNABLE_TO_FIND_TOKEN_IN_LOGIN_RESPONSE);
|
|
||||||
// }
|
|
||||||
yield put(MemberRegistActions.requestSuccess());
|
|
||||||
} catch (e) {
|
|
||||||
yield put(MemberRegistActions.requestFailure(e));
|
|
||||||
} finally {
|
|
||||||
// yield put({
|
|
||||||
// type: types.SENDING_REQUEST,
|
|
||||||
// payload: {sendingRequest: false},
|
|
||||||
// });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export function* watchRegist(): SagaIterator {
|
|
||||||
yield takeLatest(MemberRegistActions.REQUEST, regist);
|
|
||||||
}
|
|
|
@ -1,39 +0,0 @@
|
||||||
import { SagaIterator } from 'redux-saga';
|
|
||||||
import { call, Effect, fork, put, takeLatest } from 'redux-saga/effects';
|
|
||||||
|
|
||||||
|
|
||||||
import AppContext from '@overflow/commons/context/AppContext';
|
|
||||||
import Action from '@overflow/commons/redux/Action';
|
|
||||||
|
|
||||||
import Domain from '../../api/model/Domain';
|
|
||||||
import DomainService from '../../api/service/DomainService';
|
|
||||||
import * as RegistActions from '../action/regist';
|
|
||||||
import RegistPayload from '../payload/RegistPayload';
|
|
||||||
|
|
||||||
function* regist(action: Action<RegistPayload>): SagaIterator {
|
|
||||||
try {
|
|
||||||
const dm = action.payload.domain;
|
|
||||||
// yield put({
|
|
||||||
// type: types.SENDING_REQUEST,
|
|
||||||
// payload: {sendingRequest: true},
|
|
||||||
// });
|
|
||||||
let domainService = AppContext.getInstance().getPouch(DomainService);
|
|
||||||
yield call({context: domainService, fn: domainService.regist}, dm);
|
|
||||||
|
|
||||||
// if (responseBody.token === undefined) {
|
|
||||||
// throw new Error(MESSAGES.UNABLE_TO_FIND_TOKEN_IN_LOGIN_RESPONSE);
|
|
||||||
// }
|
|
||||||
yield put(RegistActions.requestSuccess());
|
|
||||||
} catch (e) {
|
|
||||||
yield put(RegistActions.requestFailure(e));
|
|
||||||
} finally {
|
|
||||||
// yield put({
|
|
||||||
// type: types.SENDING_REQUEST,
|
|
||||||
// payload: {sendingRequest: false},
|
|
||||||
// });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export function* watchRegist(): SagaIterator {
|
|
||||||
yield takeLatest(RegistActions.REQUEST, regist);
|
|
||||||
}
|
|
|
@ -1,44 +0,0 @@
|
||||||
/**
|
|
||||||
* Created by geek on 17. 7. 4.
|
|
||||||
*/
|
|
||||||
|
|
||||||
import { SagaIterator } from 'redux-saga';
|
|
||||||
import { call, Effect, fork, put, takeLatest } from 'redux-saga/effects';
|
|
||||||
|
|
||||||
|
|
||||||
import AppContext from '@overflow/commons/context/AppContext';
|
|
||||||
import Action from '@overflow/commons/redux/Action';
|
|
||||||
|
|
||||||
import EmailAuth from '@overflow/email/api/model/EmailAuth';
|
|
||||||
|
|
||||||
import EmailAuthService from '@overflow/email/api/service/EmailAuthService';
|
|
||||||
import * as ModifyAction from '../action/modify';
|
|
||||||
import ModifyPayload from '../payload/ModifyPayload';
|
|
||||||
|
|
||||||
function* modify(action: Action<ModifyPayload>): SagaIterator {
|
|
||||||
try {
|
|
||||||
const ea = action.payload.emailAuth;
|
|
||||||
// yield put({
|
|
||||||
// type: types.SENDING_REQUEST,
|
|
||||||
// payload: {sendingRequest: true},
|
|
||||||
// });
|
|
||||||
let emailAuthService = AppContext.getInstance().getPouch(EmailAuthService);
|
|
||||||
const emailAuth = yield call({context: emailAuthService, fn: emailAuthService.modify}, ea);
|
|
||||||
|
|
||||||
// if (responseBody.token === undefined) {
|
|
||||||
// throw new Error(MESSAGES.UNABLE_TO_FIND_TOKEN_IN_LOGIN_RESPONSE);
|
|
||||||
// }
|
|
||||||
yield put(ModifyAction.requestSuccess(emailAuth));
|
|
||||||
} catch (e) {
|
|
||||||
yield put(ModifyAction.requestFailure(e));
|
|
||||||
} finally {
|
|
||||||
// yield put({
|
|
||||||
// type: types.SENDING_REQUEST,
|
|
||||||
// payload: {sendingRequest: false},
|
|
||||||
// });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export function* watchModify(): SagaIterator {
|
|
||||||
yield takeLatest(ModifyAction.REQUEST, modify);
|
|
||||||
}
|
|
|
@ -1,40 +0,0 @@
|
||||||
import { SagaIterator } from 'redux-saga';
|
|
||||||
import { call, Effect, fork, put, takeLatest } from 'redux-saga/effects';
|
|
||||||
|
|
||||||
|
|
||||||
import AppContext from '@overflow/commons/context/AppContext';
|
|
||||||
import Action from '@overflow/commons/redux/Action';
|
|
||||||
|
|
||||||
import EmailAuth from '@overflow/email/api/model/EmailAuth';
|
|
||||||
|
|
||||||
import EmailAuthService from '@overflow/email/api/service/EmailAuthService';
|
|
||||||
import * as ReadAction from '../action/read';
|
|
||||||
import ReadPayload from '../payload/ReadPayload';
|
|
||||||
|
|
||||||
function* read(action: Action<ReadPayload>): SagaIterator {
|
|
||||||
try {
|
|
||||||
const id = action.payload.id;
|
|
||||||
// yield put({
|
|
||||||
// type: types.SENDING_REQUEST,
|
|
||||||
// payload: {sendingRequest: true},
|
|
||||||
// });
|
|
||||||
let emailAuthService = AppContext.getInstance().getPouch(EmailAuthService);
|
|
||||||
const emailAuth = yield call({context: emailAuthService, fn: emailAuthService.read}, id);
|
|
||||||
|
|
||||||
// if (responseBody.token === undefined) {
|
|
||||||
// throw new Error(MESSAGES.UNABLE_TO_FIND_TOKEN_IN_LOGIN_RESPONSE);
|
|
||||||
// }
|
|
||||||
yield put(ReadAction.requestSuccess(emailAuth));
|
|
||||||
} catch (e) {
|
|
||||||
yield put(ReadAction.requestFailure(e));
|
|
||||||
} finally {
|
|
||||||
// yield put({
|
|
||||||
// type: types.SENDING_REQUEST,
|
|
||||||
// payload: {sendingRequest: false},
|
|
||||||
// });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export function* watchRead(): SagaIterator {
|
|
||||||
yield takeLatest(ReadAction.REQUEST, read);
|
|
||||||
}
|
|
|
@ -1,40 +0,0 @@
|
||||||
import { SagaIterator } from 'redux-saga';
|
|
||||||
import { call, Effect, fork, put, takeLatest } from 'redux-saga/effects';
|
|
||||||
|
|
||||||
|
|
||||||
import AppContext from '@overflow/commons/context/AppContext';
|
|
||||||
import Action from '@overflow/commons/redux/Action';
|
|
||||||
|
|
||||||
import EmailAuth from '@overflow/email/api/model/EmailAuth';
|
|
||||||
|
|
||||||
import EmailAuthService from '@overflow/email/api/service/EmailAuthService';
|
|
||||||
import * as ReadByAuthKeyAction from '../action/read_by_auth_key';
|
|
||||||
import ReadByAuthKeyPayload from '../payload/ReadByAuthKeyPayload';
|
|
||||||
|
|
||||||
function* readByAuthKey(action: Action<ReadByAuthKeyPayload>): SagaIterator {
|
|
||||||
try {
|
|
||||||
const authKey = action.payload.authKey;
|
|
||||||
// yield put({
|
|
||||||
// type: types.SENDING_REQUEST,
|
|
||||||
// payload: {sendingRequest: true},
|
|
||||||
// });
|
|
||||||
let emailAuthService = AppContext.getInstance().getPouch(EmailAuthService);
|
|
||||||
const emailAuth = yield call({context: emailAuthService, fn: emailAuthService.readByAuthKey}, authKey);
|
|
||||||
|
|
||||||
// if (responseBody.token === undefined) {
|
|
||||||
// throw new Error(MESSAGES.UNABLE_TO_FIND_TOKEN_IN_LOGIN_RESPONSE);
|
|
||||||
// }
|
|
||||||
yield put(ReadByAuthKeyAction.requestSuccess(emailAuth));
|
|
||||||
} catch (e) {
|
|
||||||
yield put(ReadByAuthKeyAction.requestFailure(e));
|
|
||||||
} finally {
|
|
||||||
// yield put({
|
|
||||||
// type: types.SENDING_REQUEST,
|
|
||||||
// payload: {sendingRequest: false},
|
|
||||||
// });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export function* watchReadByAuthKey(): SagaIterator {
|
|
||||||
yield takeLatest(ReadByAuthKeyAction.REQUEST, readByAuthKey);
|
|
||||||
}
|
|
|
@ -1,40 +0,0 @@
|
||||||
import { SagaIterator } from 'redux-saga';
|
|
||||||
import { call, Effect, fork, put, takeLatest } from 'redux-saga/effects';
|
|
||||||
|
|
||||||
|
|
||||||
import AppContext from '@overflow/commons/context/AppContext';
|
|
||||||
import Action from '@overflow/commons/redux/Action';
|
|
||||||
|
|
||||||
import EmailAuth from '@overflow/email/api/model/EmailAuth';
|
|
||||||
|
|
||||||
import EmailAuthService from '@overflow/email/api/service/EmailAuthService';
|
|
||||||
import * as ReadByMemberAction from '../action/read_by_member';
|
|
||||||
import ReadByMemberPayload from '../payload/ReadByMemberPayload';
|
|
||||||
|
|
||||||
function* readByMember(action: Action<ReadByMemberPayload>): SagaIterator {
|
|
||||||
try {
|
|
||||||
const id = action.payload.memberId;
|
|
||||||
// yield put({
|
|
||||||
// type: types.SENDING_REQUEST,
|
|
||||||
// payload: {sendingRequest: true},
|
|
||||||
// });
|
|
||||||
let emailAuthService = AppContext.getInstance().getPouch(EmailAuthService);
|
|
||||||
const emailAuths = yield call({context: emailAuthService, fn: emailAuthService.readByMember}, id);
|
|
||||||
|
|
||||||
// if (responseBody.token === undefined) {
|
|
||||||
// throw new Error(MESSAGES.UNABLE_TO_FIND_TOKEN_IN_LOGIN_RESPONSE);
|
|
||||||
// }
|
|
||||||
yield put(ReadByMemberAction.requestSuccess(emailAuths));
|
|
||||||
} catch (e) {
|
|
||||||
yield put(ReadByMemberAction.requestFailure(e));
|
|
||||||
} finally {
|
|
||||||
// yield put({
|
|
||||||
// type: types.SENDING_REQUEST,
|
|
||||||
// payload: {sendingRequest: false},
|
|
||||||
// });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export function* watchReadByMember(): SagaIterator {
|
|
||||||
yield takeLatest(ReadByMemberAction.REQUEST, readByMember);
|
|
||||||
}
|
|
|
@ -1,40 +0,0 @@
|
||||||
import { SagaIterator } from 'redux-saga';
|
|
||||||
import { call, Effect, fork, put, takeLatest } from 'redux-saga/effects';
|
|
||||||
|
|
||||||
|
|
||||||
import AppContext from '@overflow/commons/context/AppContext';
|
|
||||||
import Action from '@overflow/commons/redux/Action';
|
|
||||||
|
|
||||||
import EmailAuth from '@overflow/email/api/model/EmailAuth';
|
|
||||||
|
|
||||||
import EmailAuthService from '@overflow/email/api/service/EmailAuthService';
|
|
||||||
import * as SendEmailAction from '../action/send_email_by_member';
|
|
||||||
import SendEmailPayload from '../payload/SendEmailByMemberPayload';
|
|
||||||
|
|
||||||
function* sendEmail(action: Action<SendEmailPayload>): SagaIterator {
|
|
||||||
try {
|
|
||||||
const {memberId, email} = action.payload;
|
|
||||||
// yield put({
|
|
||||||
// type: types.SENDING_REQUEST,
|
|
||||||
// payload: {sendingRequest: true},
|
|
||||||
// });
|
|
||||||
let emailAuthService = AppContext.getInstance().getPouch(EmailAuthService);
|
|
||||||
const emailAuth = yield call({context: emailAuthService, fn: emailAuthService.sendEmailByMember}, memberId, email);
|
|
||||||
|
|
||||||
// if (responseBody.token === undefined) {
|
|
||||||
// throw new Error(MESSAGES.UNABLE_TO_FIND_TOKEN_IN_LOGIN_RESPONSE);
|
|
||||||
// }
|
|
||||||
yield put(SendEmailAction.requestSuccess(emailAuth));
|
|
||||||
} catch (e) {
|
|
||||||
yield put(SendEmailAction.requestFailure(e));
|
|
||||||
} finally {
|
|
||||||
// yield put({
|
|
||||||
// type: types.SENDING_REQUEST,
|
|
||||||
// payload: {sendingRequest: false},
|
|
||||||
// });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export function* watchSendEmail(): SagaIterator {
|
|
||||||
yield takeLatest(SendEmailAction.REQUEST, sendEmail);
|
|
||||||
}
|
|
|
@ -1,39 +0,0 @@
|
||||||
import { SagaIterator } from 'redux-saga';
|
|
||||||
import { call, Effect, fork, put, takeLatest } from 'redux-saga/effects';
|
|
||||||
|
|
||||||
|
|
||||||
import AppContext from '@overflow/commons/context/AppContext';
|
|
||||||
import Action from '@overflow/commons/redux/Action';
|
|
||||||
|
|
||||||
import InfraHost from '../../api/model/InfraHost';
|
|
||||||
import InfraHostService from '../../api/service/InfraHostService';
|
|
||||||
import * as ReadActions from '../action/host_read';
|
|
||||||
import HostReadPayload from '../payload/HostReadPayload';
|
|
||||||
|
|
||||||
function* read(action: Action<HostReadPayload>): SagaIterator {
|
|
||||||
try {
|
|
||||||
const {id} = action.payload;
|
|
||||||
// yield put({
|
|
||||||
// type: types.SENDING_REQUEST,
|
|
||||||
// payload: {sendingRequest: true},
|
|
||||||
// });
|
|
||||||
let infraHostService = AppContext.getInstance().getPouch(InfraHostService);
|
|
||||||
const retApikey = yield call({context: infraHostService, fn: infraHostService.read}, id);
|
|
||||||
|
|
||||||
// if (responseBody.token === undefined) {
|
|
||||||
// throw new Error(MESSAGES.UNABLE_TO_FIND_TOKEN_IN_LOGIN_RESPONSE);
|
|
||||||
// }
|
|
||||||
yield put(ReadActions.requestSuccess(retApikey));
|
|
||||||
} catch (e) {
|
|
||||||
yield put(ReadActions.requestFailure(e));
|
|
||||||
} finally {
|
|
||||||
// yield put({
|
|
||||||
// type: types.SENDING_REQUEST,
|
|
||||||
// payload: {sendingRequest: false},
|
|
||||||
// });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export function* watchHostRead(): SagaIterator {
|
|
||||||
yield takeLatest(ReadActions.REQUEST, read);
|
|
||||||
}
|
|
|
@ -1,39 +0,0 @@
|
||||||
import { SagaIterator } from 'redux-saga';
|
|
||||||
import { call, Effect, fork, put, takeLatest } from 'redux-saga/effects';
|
|
||||||
|
|
||||||
|
|
||||||
import AppContext from '@overflow/commons/context/AppContext';
|
|
||||||
import Action from '@overflow/commons/redux/Action';
|
|
||||||
|
|
||||||
import InfraHost from '../../api/model/InfraHost';
|
|
||||||
import InfraHostService from '../../api/service/InfraHostService';
|
|
||||||
import * as RegistActions from '../action/host_regist';
|
|
||||||
import HostRegistPayload from '../payload/HostRegistPayload';
|
|
||||||
|
|
||||||
function* regist(action: Action<HostRegistPayload>): SagaIterator {
|
|
||||||
try {
|
|
||||||
const {infraHost} = action.payload;
|
|
||||||
// yield put({
|
|
||||||
// type: types.SENDING_REQUEST,
|
|
||||||
// payload: {sendingRequest: true},
|
|
||||||
// });
|
|
||||||
let infraHostService = AppContext.getInstance().getPouch(InfraHostService);
|
|
||||||
const retApikey = yield call({context: infraHostService, fn: infraHostService.regist}, infraHost);
|
|
||||||
|
|
||||||
// if (responseBody.token === undefined) {
|
|
||||||
// throw new Error(MESSAGES.UNABLE_TO_FIND_TOKEN_IN_LOGIN_RESPONSE);
|
|
||||||
// }
|
|
||||||
yield put(RegistActions.requestSuccess(retApikey));
|
|
||||||
} catch (e) {
|
|
||||||
yield put(RegistActions.requestFailure(e));
|
|
||||||
} finally {
|
|
||||||
// yield put({
|
|
||||||
// type: types.SENDING_REQUEST,
|
|
||||||
// payload: {sendingRequest: false},
|
|
||||||
// });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export function* watchHostRegist(): SagaIterator {
|
|
||||||
yield takeLatest(RegistActions.REQUEST, regist);
|
|
||||||
}
|
|
|
@ -1,39 +0,0 @@
|
||||||
import { SagaIterator } from 'redux-saga';
|
|
||||||
import { call, Effect, fork, put, takeLatest } from 'redux-saga/effects';
|
|
||||||
|
|
||||||
|
|
||||||
import AppContext from '@overflow/commons/context/AppContext';
|
|
||||||
import Action from '@overflow/commons/redux/Action';
|
|
||||||
|
|
||||||
import InfraMachine from '../../api/model/InfraMachine';
|
|
||||||
import InfraMachineService from '../../api/service/InfraMachineService';
|
|
||||||
import * as ReadActions from '../action/machine_read';
|
|
||||||
import MachineReadPayload from '../payload/MachineReadPayload';
|
|
||||||
|
|
||||||
function* read(action: Action<MachineReadPayload>): SagaIterator {
|
|
||||||
try {
|
|
||||||
const {id} = action.payload;
|
|
||||||
// yield put({
|
|
||||||
// type: types.SENDING_REQUEST,
|
|
||||||
// payload: {sendingRequest: true},
|
|
||||||
// });
|
|
||||||
let infraMachineService = AppContext.getInstance().getPouch(InfraMachineService);
|
|
||||||
const retApikey = yield call({context: infraMachineService, fn: infraMachineService.read}, id);
|
|
||||||
|
|
||||||
// if (responseBody.token === undefined) {
|
|
||||||
// throw new Error(MESSAGES.UNABLE_TO_FIND_TOKEN_IN_LOGIN_RESPONSE);
|
|
||||||
// }
|
|
||||||
yield put(ReadActions.requestSuccess(retApikey));
|
|
||||||
} catch (e) {
|
|
||||||
yield put(ReadActions.requestFailure(e));
|
|
||||||
} finally {
|
|
||||||
// yield put({
|
|
||||||
// type: types.SENDING_REQUEST,
|
|
||||||
// payload: {sendingRequest: false},
|
|
||||||
// });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export function* watchMachineRead(): SagaIterator {
|
|
||||||
yield takeLatest(ReadActions.REQUEST, read);
|
|
||||||
}
|
|
|
@ -1,40 +0,0 @@
|
||||||
import { SagaIterator } from 'redux-saga';
|
|
||||||
import { call, Effect, fork, put, takeLatest } from 'redux-saga/effects';
|
|
||||||
|
|
||||||
|
|
||||||
import AppContext from '@overflow/commons/context/AppContext';
|
|
||||||
import Action from '@overflow/commons/redux/Action';
|
|
||||||
|
|
||||||
import InfraMachine from '../../api/model/InfraMachine';
|
|
||||||
import InfraMachineService from '../../api/service/InfraMachineService';
|
|
||||||
import * as RegistActions from '../action/machine_regist';
|
|
||||||
import MachineRegistPayload from '../payload/MachineRegistPayload';
|
|
||||||
|
|
||||||
function* regist(action: Action<MachineRegistPayload>): SagaIterator {
|
|
||||||
try {
|
|
||||||
const {infraMachine} = action.payload;
|
|
||||||
// yield put({
|
|
||||||
// type: types.SENDING_REQUEST,
|
|
||||||
// payload: {sendingRequest: true},
|
|
||||||
// });
|
|
||||||
|
|
||||||
let infraMachineService = AppContext.getInstance().getPouch(InfraMachineService);
|
|
||||||
const retApikey = yield call({context: infraMachineService, fn: infraMachineService.regist}, infraMachine);
|
|
||||||
|
|
||||||
// if (responseBody.token === undefined) {
|
|
||||||
// throw new Error(MESSAGES.UNABLE_TO_FIND_TOKEN_IN_LOGIN_RESPONSE);
|
|
||||||
// }
|
|
||||||
yield put(RegistActions.requestSuccess(retApikey));
|
|
||||||
} catch (e) {
|
|
||||||
yield put(RegistActions.requestFailure(e));
|
|
||||||
} finally {
|
|
||||||
// yield put({
|
|
||||||
// type: types.SENDING_REQUEST,
|
|
||||||
// payload: {sendingRequest: false},
|
|
||||||
// });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export function* watchMachineRegist(): SagaIterator {
|
|
||||||
yield takeLatest(RegistActions.REQUEST, regist);
|
|
||||||
}
|
|
|
@ -1,39 +0,0 @@
|
||||||
import { SagaIterator } from 'redux-saga';
|
|
||||||
import { call, Effect, fork, put, takeLatest } from 'redux-saga/effects';
|
|
||||||
|
|
||||||
|
|
||||||
import AppContext from '@overflow/commons/context/AppContext';
|
|
||||||
import Action from '@overflow/commons/redux/Action';
|
|
||||||
|
|
||||||
import InfraOSApplication from '../../api/model/InfraOSApplication';
|
|
||||||
import InfraOSApplicationService from '../../api/service/InfraOSApplicationService';
|
|
||||||
import * as ReadActions from '../action/os_application_read';
|
|
||||||
import OSApplicationReadPayload from '../payload/OSApplicationReadPayload';
|
|
||||||
|
|
||||||
function* read(action: Action<OSApplicationReadPayload>): SagaIterator {
|
|
||||||
try {
|
|
||||||
const {id} = action.payload;
|
|
||||||
// yield put({
|
|
||||||
// type: types.SENDING_REQUEST,
|
|
||||||
// payload: {sendingRequest: true},
|
|
||||||
// });
|
|
||||||
let infraOSApplicationService = AppContext.getInstance().getPouch(InfraOSApplicationService);
|
|
||||||
const retApikey = yield call({context: infraOSApplicationService, fn: infraOSApplicationService.read}, id);
|
|
||||||
|
|
||||||
// if (responseBody.token === undefined) {
|
|
||||||
// throw new Error(MESSAGES.UNABLE_TO_FIND_TOKEN_IN_LOGIN_RESPONSE);
|
|
||||||
// }
|
|
||||||
yield put(ReadActions.requestSuccess(retApikey));
|
|
||||||
} catch (e) {
|
|
||||||
yield put(ReadActions.requestFailure(e));
|
|
||||||
} finally {
|
|
||||||
// yield put({
|
|
||||||
// type: types.SENDING_REQUEST,
|
|
||||||
// payload: {sendingRequest: false},
|
|
||||||
// });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export function* watchOSApplicationRead(): SagaIterator {
|
|
||||||
yield takeLatest(ReadActions.REQUEST, read);
|
|
||||||
}
|
|
|
@ -1,39 +0,0 @@
|
||||||
import { SagaIterator } from 'redux-saga';
|
|
||||||
import { call, Effect, fork, put, takeLatest } from 'redux-saga/effects';
|
|
||||||
|
|
||||||
|
|
||||||
import AppContext from '@overflow/commons/context/AppContext';
|
|
||||||
import Action from '@overflow/commons/redux/Action';
|
|
||||||
|
|
||||||
import InfraOSApplication from '../../api/model/InfraOSApplication';
|
|
||||||
import InfraOSApplicationService from '../../api/service/InfraOSApplicationService';
|
|
||||||
import * as RegistActions from '../action/os_application_regist';
|
|
||||||
import OSApplicationRegistPayload from '../payload/OSApplicationRegistPayload';
|
|
||||||
|
|
||||||
function* regist(action: Action<OSApplicationRegistPayload>): SagaIterator {
|
|
||||||
try {
|
|
||||||
const {infraOSApplication} = action.payload;
|
|
||||||
// yield put({
|
|
||||||
// type: types.SENDING_REQUEST,
|
|
||||||
// payload: {sendingRequest: true},
|
|
||||||
// });
|
|
||||||
let infraOSApplicationService = AppContext.getInstance().getPouch(InfraOSApplicationService);
|
|
||||||
const retApikey = yield call({context: infraOSApplicationService, fn: infraOSApplicationService.regist}, infraOSApplication);
|
|
||||||
|
|
||||||
// if (responseBody.token === undefined) {
|
|
||||||
// throw new Error(MESSAGES.UNABLE_TO_FIND_TOKEN_IN_LOGIN_RESPONSE);
|
|
||||||
// }
|
|
||||||
yield put(RegistActions.requestSuccess(retApikey));
|
|
||||||
} catch (e) {
|
|
||||||
yield put(RegistActions.requestFailure(e));
|
|
||||||
} finally {
|
|
||||||
// yield put({
|
|
||||||
// type: types.SENDING_REQUEST,
|
|
||||||
// payload: {sendingRequest: false},
|
|
||||||
// });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export function* watchOSApplicationRegist(): SagaIterator {
|
|
||||||
yield takeLatest(RegistActions.REQUEST, regist);
|
|
||||||
}
|
|
|
@ -1,39 +0,0 @@
|
||||||
import { SagaIterator } from 'redux-saga';
|
|
||||||
import { call, Effect, fork, put, takeLatest } from 'redux-saga/effects';
|
|
||||||
|
|
||||||
|
|
||||||
import AppContext from '@overflow/commons/context/AppContext';
|
|
||||||
import Action from '@overflow/commons/redux/Action';
|
|
||||||
|
|
||||||
import InfraOSDaemon from '../../api/model/InfraOSDaemon';
|
|
||||||
import InfraOSDaemonService from '../../api/service/InfraOSDaemonService';
|
|
||||||
import * as ReadActions from '../action/os_daemon_read';
|
|
||||||
import OSDaemonReadPayload from '../payload/OSDaemonReadPayload';
|
|
||||||
|
|
||||||
function* read(action: Action<OSDaemonReadPayload>): SagaIterator {
|
|
||||||
try {
|
|
||||||
const {id} = action.payload;
|
|
||||||
// yield put({
|
|
||||||
// type: types.SENDING_REQUEST,
|
|
||||||
// payload: {sendingRequest: true},
|
|
||||||
// });
|
|
||||||
let infraOSDaemonService = AppContext.getInstance().getPouch(InfraOSDaemonService);
|
|
||||||
const retApikey = yield call({context: infraOSDaemonService, fn: infraOSDaemonService.read}, id);
|
|
||||||
|
|
||||||
// if (responseBody.token === undefined) {
|
|
||||||
// throw new Error(MESSAGES.UNABLE_TO_FIND_TOKEN_IN_LOGIN_RESPONSE);
|
|
||||||
// }
|
|
||||||
yield put(ReadActions.requestSuccess(retApikey));
|
|
||||||
} catch (e) {
|
|
||||||
yield put(ReadActions.requestFailure(e));
|
|
||||||
} finally {
|
|
||||||
// yield put({
|
|
||||||
// type: types.SENDING_REQUEST,
|
|
||||||
// payload: {sendingRequest: false},
|
|
||||||
// });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export function* watchOSDaemonRead(): SagaIterator {
|
|
||||||
yield takeLatest(ReadActions.REQUEST, read);
|
|
||||||
}
|
|
|
@ -1,39 +0,0 @@
|
||||||
import { SagaIterator } from 'redux-saga';
|
|
||||||
import { call, Effect, fork, put, takeLatest } from 'redux-saga/effects';
|
|
||||||
|
|
||||||
|
|
||||||
import AppContext from '@overflow/commons/context/AppContext';
|
|
||||||
import Action from '@overflow/commons/redux/Action';
|
|
||||||
|
|
||||||
import InfraOSDaemon from '../../api/model/InfraOSDaemon';
|
|
||||||
import InfraOSDaemonService from '../../api/service/InfraOSDaemonService';
|
|
||||||
import * as RegistActions from '../action/os_daemon_regist';
|
|
||||||
import OSDaemonRegistPayload from '../payload/OSDaemonRegistPayload';
|
|
||||||
|
|
||||||
function* regist(action: Action<OSDaemonRegistPayload>): SagaIterator {
|
|
||||||
try {
|
|
||||||
const {infraOSDaemon} = action.payload;
|
|
||||||
// yield put({
|
|
||||||
// type: types.SENDING_REQUEST,
|
|
||||||
// payload: {sendingRequest: true},
|
|
||||||
// });
|
|
||||||
let infraOSDaemonService = AppContext.getInstance().getPouch(InfraOSDaemonService);
|
|
||||||
const retApikey = yield call({context: infraOSDaemonService, fn: infraOSDaemonService.regist}, infraOSDaemon);
|
|
||||||
|
|
||||||
// if (responseBody.token === undefined) {
|
|
||||||
// throw new Error(MESSAGES.UNABLE_TO_FIND_TOKEN_IN_LOGIN_RESPONSE);
|
|
||||||
// }
|
|
||||||
yield put(RegistActions.requestSuccess(retApikey));
|
|
||||||
} catch (e) {
|
|
||||||
yield put(RegistActions.requestFailure(e));
|
|
||||||
} finally {
|
|
||||||
// yield put({
|
|
||||||
// type: types.SENDING_REQUEST,
|
|
||||||
// payload: {sendingRequest: false},
|
|
||||||
// });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export function* watchOSDaemonRegist(): SagaIterator {
|
|
||||||
yield takeLatest(RegistActions.REQUEST, regist);
|
|
||||||
}
|
|
|
@ -1,39 +0,0 @@
|
||||||
import { SagaIterator } from 'redux-saga';
|
|
||||||
import { call, Effect, fork, put, takeLatest } from 'redux-saga/effects';
|
|
||||||
|
|
||||||
|
|
||||||
import AppContext from '@overflow/commons/context/AppContext';
|
|
||||||
import Action from '@overflow/commons/redux/Action';
|
|
||||||
|
|
||||||
import InfraOSPort from '../../api/model/InfraOSPort';
|
|
||||||
import InfraOSPortService from '../../api/service/InfraOSPortService';
|
|
||||||
import * as ReadActions from '../action/os_port_read';
|
|
||||||
import OSPortReadPayload from '../payload/OSPortReadPayload';
|
|
||||||
|
|
||||||
function* read(action: Action<OSPortReadPayload>): SagaIterator {
|
|
||||||
try {
|
|
||||||
const {id} = action.payload;
|
|
||||||
// yield put({
|
|
||||||
// type: types.SENDING_REQUEST,
|
|
||||||
// payload: {sendingRequest: true},
|
|
||||||
// });
|
|
||||||
let infraOSPortService = AppContext.getInstance().getPouch(InfraOSPortService);
|
|
||||||
const retApikey = yield call({context: infraOSPortService, fn: infraOSPortService.read}, id);
|
|
||||||
|
|
||||||
// if (responseBody.token === undefined) {
|
|
||||||
// throw new Error(MESSAGES.UNABLE_TO_FIND_TOKEN_IN_LOGIN_RESPONSE);
|
|
||||||
// }
|
|
||||||
yield put(ReadActions.requestSuccess(retApikey));
|
|
||||||
} catch (e) {
|
|
||||||
yield put(ReadActions.requestFailure(e));
|
|
||||||
} finally {
|
|
||||||
// yield put({
|
|
||||||
// type: types.SENDING_REQUEST,
|
|
||||||
// payload: {sendingRequest: false},
|
|
||||||
// });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export function* watchOSPortRead(): SagaIterator {
|
|
||||||
yield takeLatest(ReadActions.REQUEST, read);
|
|
||||||
}
|
|
|
@ -1,39 +0,0 @@
|
||||||
import { SagaIterator } from 'redux-saga';
|
|
||||||
import { call, Effect, fork, put, takeLatest } from 'redux-saga/effects';
|
|
||||||
|
|
||||||
|
|
||||||
import AppContext from '@overflow/commons/context/AppContext';
|
|
||||||
import Action from '@overflow/commons/redux/Action';
|
|
||||||
|
|
||||||
import InfraOSPort from '../../api/model/InfraOSPort';
|
|
||||||
import InfraOSPortService from '../../api/service/InfraOSPortService';
|
|
||||||
import * as RegistActions from '../action/os_port_regist';
|
|
||||||
import OSPortRegistPayload from '../payload/OSPortRegistPayload';
|
|
||||||
|
|
||||||
function* regist(action: Action<OSPortRegistPayload>): SagaIterator {
|
|
||||||
try {
|
|
||||||
const {infraOSPort} = action.payload;
|
|
||||||
// yield put({
|
|
||||||
// type: types.SENDING_REQUEST,
|
|
||||||
// payload: {sendingRequest: true},
|
|
||||||
// });
|
|
||||||
let infraOSPortService = AppContext.getInstance().getPouch(InfraOSPortService);
|
|
||||||
const retApikey = yield call({context: infraOSPortService, fn: infraOSPortService.regist}, infraOSPort);
|
|
||||||
|
|
||||||
// if (responseBody.token === undefined) {
|
|
||||||
// throw new Error(MESSAGES.UNABLE_TO_FIND_TOKEN_IN_LOGIN_RESPONSE);
|
|
||||||
// }
|
|
||||||
yield put(RegistActions.requestSuccess(retApikey));
|
|
||||||
} catch (e) {
|
|
||||||
yield put(RegistActions.requestFailure(e));
|
|
||||||
} finally {
|
|
||||||
// yield put({
|
|
||||||
// type: types.SENDING_REQUEST,
|
|
||||||
// payload: {sendingRequest: false},
|
|
||||||
// });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export function* watchOSPortRegist(): SagaIterator {
|
|
||||||
yield takeLatest(RegistActions.REQUEST, regist);
|
|
||||||
}
|
|
|
@ -1,39 +0,0 @@
|
||||||
import { SagaIterator } from 'redux-saga';
|
|
||||||
import { call, Effect, fork, put, takeLatest } from 'redux-saga/effects';
|
|
||||||
|
|
||||||
|
|
||||||
import AppContext from '@overflow/commons/context/AppContext';
|
|
||||||
import Action from '@overflow/commons/redux/Action';
|
|
||||||
|
|
||||||
import InfraOS from '../../api/model/InfraOS';
|
|
||||||
import InfraOSService from '../../api/service/InfraOSService';
|
|
||||||
import * as ReadActions from '../action/os_read';
|
|
||||||
import OSReadPayload from '../payload/OSReadPayload';
|
|
||||||
|
|
||||||
function* read(action: Action<OSReadPayload>): SagaIterator {
|
|
||||||
try {
|
|
||||||
const {id} = action.payload;
|
|
||||||
// yield put({
|
|
||||||
// type: types.SENDING_REQUEST,
|
|
||||||
// payload: {sendingRequest: true},
|
|
||||||
// });
|
|
||||||
let infraOSService = AppContext.getInstance().getPouch(InfraOSService);
|
|
||||||
const retApikey = yield call({context: infraOSService, fn: infraOSService.read}, id);
|
|
||||||
|
|
||||||
// if (responseBody.token === undefined) {
|
|
||||||
// throw new Error(MESSAGES.UNABLE_TO_FIND_TOKEN_IN_LOGIN_RESPONSE);
|
|
||||||
// }
|
|
||||||
yield put(ReadActions.requestSuccess(retApikey));
|
|
||||||
} catch (e) {
|
|
||||||
yield put(ReadActions.requestFailure(e));
|
|
||||||
} finally {
|
|
||||||
// yield put({
|
|
||||||
// type: types.SENDING_REQUEST,
|
|
||||||
// payload: {sendingRequest: false},
|
|
||||||
// });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export function* watchOSRead(): SagaIterator {
|
|
||||||
yield takeLatest(ReadActions.REQUEST, read);
|
|
||||||
}
|
|
|
@ -1,39 +0,0 @@
|
||||||
import { SagaIterator } from 'redux-saga';
|
|
||||||
import { call, Effect, fork, put, takeLatest } from 'redux-saga/effects';
|
|
||||||
|
|
||||||
|
|
||||||
import AppContext from '@overflow/commons/context/AppContext';
|
|
||||||
import Action from '@overflow/commons/redux/Action';
|
|
||||||
|
|
||||||
import InfraOS from '../../api/model/InfraOS';
|
|
||||||
import InfraOSService from '../../api/service/InfraOSService';
|
|
||||||
import * as RegistActions from '../action/os_regist';
|
|
||||||
import OSRegistPayload from '../payload/OSRegistPayload';
|
|
||||||
|
|
||||||
function* regist(action: Action<OSRegistPayload>): SagaIterator {
|
|
||||||
try {
|
|
||||||
const {infraOS} = action.payload;
|
|
||||||
// yield put({
|
|
||||||
// type: types.SENDING_REQUEST,
|
|
||||||
// payload: {sendingRequest: true},
|
|
||||||
// });
|
|
||||||
let infraOSService = AppContext.getInstance().getPouch(InfraOSService);
|
|
||||||
const retApikey = yield call({context: infraOSService, fn: infraOSService.regist}, infraOS);
|
|
||||||
|
|
||||||
// if (responseBody.token === undefined) {
|
|
||||||
// throw new Error(MESSAGES.UNABLE_TO_FIND_TOKEN_IN_LOGIN_RESPONSE);
|
|
||||||
// }
|
|
||||||
yield put(RegistActions.requestSuccess(retApikey));
|
|
||||||
} catch (e) {
|
|
||||||
yield put(RegistActions.requestFailure(e));
|
|
||||||
} finally {
|
|
||||||
// yield put({
|
|
||||||
// type: types.SENDING_REQUEST,
|
|
||||||
// payload: {sendingRequest: false},
|
|
||||||
// });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export function* watchOSRegist(): SagaIterator {
|
|
||||||
yield takeLatest(RegistActions.REQUEST, regist);
|
|
||||||
}
|
|
|
@ -1,39 +0,0 @@
|
||||||
import { SagaIterator } from 'redux-saga';
|
|
||||||
import { call, Effect, fork, put, takeLatest } from 'redux-saga/effects';
|
|
||||||
|
|
||||||
|
|
||||||
import AppContext from '@overflow/commons/context/AppContext';
|
|
||||||
import Action from '@overflow/commons/redux/Action';
|
|
||||||
|
|
||||||
import Infra from '../../api/model/Infra';
|
|
||||||
import InfraService from '../../api/service/InfraService';
|
|
||||||
import * as ReadActions from '../action/os_read';
|
|
||||||
import ReadPayload from '../payload/ReadPayload';
|
|
||||||
|
|
||||||
function* read(action: Action<ReadPayload>): SagaIterator {
|
|
||||||
try {
|
|
||||||
const {id} = action.payload;
|
|
||||||
// yield put({
|
|
||||||
// type: types.SENDING_REQUEST,
|
|
||||||
// payload: {sendingRequest: true},
|
|
||||||
// });
|
|
||||||
let infraService = AppContext.getInstance().getPouch(InfraService);
|
|
||||||
const retApikey = yield call({context: infraService, fn: infraService.read}, id);
|
|
||||||
|
|
||||||
// if (responseBody.token === undefined) {
|
|
||||||
// throw new Error(MESSAGES.UNABLE_TO_FIND_TOKEN_IN_LOGIN_RESPONSE);
|
|
||||||
// }
|
|
||||||
yield put(ReadActions.requestSuccess(retApikey));
|
|
||||||
} catch (e) {
|
|
||||||
yield put(ReadActions.requestFailure(e));
|
|
||||||
} finally {
|
|
||||||
// yield put({
|
|
||||||
// type: types.SENDING_REQUEST,
|
|
||||||
// payload: {sendingRequest: false},
|
|
||||||
// });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export function* watchRead(): SagaIterator {
|
|
||||||
yield takeLatest(ReadActions.REQUEST, read);
|
|
||||||
}
|
|
|
@ -1,39 +0,0 @@
|
||||||
import { SagaIterator } from 'redux-saga';
|
|
||||||
import { call, Effect, fork, put, takeLatest } from 'redux-saga/effects';
|
|
||||||
|
|
||||||
|
|
||||||
import AppContext from '@overflow/commons/context/AppContext';
|
|
||||||
import Action from '@overflow/commons/redux/Action';
|
|
||||||
|
|
||||||
import Infra from '../../api/model/Infra';
|
|
||||||
import InfraService from '../../api/service/InfraService';
|
|
||||||
import * as RegistActions from '../action/os_regist';
|
|
||||||
import RegistPayload from '../payload/RegistPayload';
|
|
||||||
|
|
||||||
function* regist(action: Action<RegistPayload>): SagaIterator {
|
|
||||||
try {
|
|
||||||
const {infra} = action.payload;
|
|
||||||
// yield put({
|
|
||||||
// type: types.SENDING_REQUEST,
|
|
||||||
// payload: {sendingRequest: true},
|
|
||||||
// });
|
|
||||||
let infraService = AppContext.getInstance().getPouch(InfraService);
|
|
||||||
const retApikey = yield call({context: infraService, fn: infraService.regist}, infra);
|
|
||||||
|
|
||||||
// if (responseBody.token === undefined) {
|
|
||||||
// throw new Error(MESSAGES.UNABLE_TO_FIND_TOKEN_IN_LOGIN_RESPONSE);
|
|
||||||
// }
|
|
||||||
yield put(RegistActions.requestSuccess(retApikey));
|
|
||||||
} catch (e) {
|
|
||||||
yield put(RegistActions.requestFailure(e));
|
|
||||||
} finally {
|
|
||||||
// yield put({
|
|
||||||
// type: types.SENDING_REQUEST,
|
|
||||||
// payload: {sendingRequest: false},
|
|
||||||
// });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export function* watchRegist(): SagaIterator {
|
|
||||||
yield takeLatest(RegistActions.REQUEST, regist);
|
|
||||||
}
|
|
|
@ -1,39 +0,0 @@
|
||||||
import { SagaIterator } from 'redux-saga';
|
|
||||||
import { call, Effect, fork, put, takeLatest } from 'redux-saga/effects';
|
|
||||||
|
|
||||||
|
|
||||||
import AppContext from '@overflow/commons/context/AppContext';
|
|
||||||
import Action from '@overflow/commons/redux/Action';
|
|
||||||
|
|
||||||
import InfraService from '../../api/model/InfraService';
|
|
||||||
import InfraServiceService from '../../api/service/InfraServiceService';
|
|
||||||
import * as ReadActions from '../action/service_read';
|
|
||||||
import ServiceReadPayload from '../payload/ServiceReadPayload';
|
|
||||||
|
|
||||||
function* read(action: Action<ServiceReadPayload>): SagaIterator {
|
|
||||||
try {
|
|
||||||
const {id} = action.payload;
|
|
||||||
// yield put({
|
|
||||||
// type: types.SENDING_REQUEST,
|
|
||||||
// payload: {sendingRequest: true},
|
|
||||||
// });
|
|
||||||
let infraServiceService = AppContext.getInstance().getPouch(InfraServiceService);
|
|
||||||
const retApikey = yield call({context: infraServiceService, fn: infraServiceService.read}, id);
|
|
||||||
|
|
||||||
// if (responseBody.token === undefined) {
|
|
||||||
// throw new Error(MESSAGES.UNABLE_TO_FIND_TOKEN_IN_LOGIN_RESPONSE);
|
|
||||||
// }
|
|
||||||
yield put(ReadActions.requestSuccess(retApikey));
|
|
||||||
} catch (e) {
|
|
||||||
yield put(ReadActions.requestFailure(e));
|
|
||||||
} finally {
|
|
||||||
// yield put({
|
|
||||||
// type: types.SENDING_REQUEST,
|
|
||||||
// payload: {sendingRequest: false},
|
|
||||||
// });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export function* watchServiceRead(): SagaIterator {
|
|
||||||
yield takeLatest(ReadActions.REQUEST, read);
|
|
||||||
}
|
|
|
@ -1,39 +0,0 @@
|
||||||
import { SagaIterator } from 'redux-saga';
|
|
||||||
import { call, Effect, fork, put, takeLatest } from 'redux-saga/effects';
|
|
||||||
|
|
||||||
|
|
||||||
import AppContext from '@overflow/commons/context/AppContext';
|
|
||||||
import Action from '@overflow/commons/redux/Action';
|
|
||||||
|
|
||||||
import InfraService from '../../api/model/InfraService';
|
|
||||||
import InfraServiceService from '../../api/service/InfraServiceService';
|
|
||||||
import * as RegistActions from '../action/service_regist';
|
|
||||||
import ServiceRegistPayload from '../payload/ServiceRegistPayload';
|
|
||||||
|
|
||||||
function* regist(action: Action<ServiceRegistPayload>): SagaIterator {
|
|
||||||
try {
|
|
||||||
const {infraService} = action.payload;
|
|
||||||
// yield put({
|
|
||||||
// type: types.SENDING_REQUEST,
|
|
||||||
// payload: {sendingRequest: true},
|
|
||||||
// });
|
|
||||||
let infraServiceService = AppContext.getInstance().getPouch(InfraServiceService);
|
|
||||||
const retApikey = yield call({context: infraServiceService, fn: infraServiceService.regist}, infraService);
|
|
||||||
|
|
||||||
// if (responseBody.token === undefined) {
|
|
||||||
// throw new Error(MESSAGES.UNABLE_TO_FIND_TOKEN_IN_LOGIN_RESPONSE);
|
|
||||||
// }
|
|
||||||
yield put(RegistActions.requestSuccess(retApikey));
|
|
||||||
} catch (e) {
|
|
||||||
yield put(RegistActions.requestFailure(e));
|
|
||||||
} finally {
|
|
||||||
// yield put({
|
|
||||||
// type: types.SENDING_REQUEST,
|
|
||||||
// payload: {sendingRequest: false},
|
|
||||||
// });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export function* watchServiceRegist(): SagaIterator {
|
|
||||||
yield takeLatest(RegistActions.REQUEST, regist);
|
|
||||||
}
|
|
|
@ -1,42 +1,8 @@
|
||||||
import Action from '@overflow/commons/redux/Action';
|
|
||||||
import Member from '@overflow/member/api/model/Member';
|
|
||||||
|
|
||||||
import SigninPayload from '../payload/SignInPayload';
|
|
||||||
|
|
||||||
// Action Type
|
// Action Type
|
||||||
export type REQUEST = '@overflow/member/signin/REQUEST';
|
export type REQUEST = '@overflow/member/signin/REQUEST';
|
||||||
export type REQUEST_SUCCESS = '@overflow/member/signin/REQUEST_SUCCESS';
|
export type REQUEST_SUCCESS = '@overflow/member/signin/REQUEST/SUCCESS';
|
||||||
export type REQUEST_FAILURE = '@overflow/member/signin/REQUEST_FAILURE';
|
export type REQUEST_FAILURE = '@overflow/member/signin/REQUEST/FAILURE';
|
||||||
|
|
||||||
export const REQUEST: REQUEST = '@overflow/member/signin/REQUEST';
|
export const REQUEST: REQUEST = '@overflow/member/signin/REQUEST';
|
||||||
export const REQUEST_SUCCESS: REQUEST_SUCCESS = '@overflow/member/signin/REQUEST_SUCCESS';
|
export const REQUEST_SUCCESS: REQUEST_SUCCESS = '@overflow/member/signin/REQUEST/SUCCESS';
|
||||||
export const REQUEST_FAILURE: REQUEST_FAILURE = '@overflow/member/signin/REQUEST_FAILURE';
|
export const REQUEST_FAILURE: REQUEST_FAILURE = '@overflow/member/signin/REQUEST/FAILURE';
|
||||||
|
|
||||||
// Action Creater
|
|
||||||
export type request = (signinId: string, signinPw: string) => Action<SigninPayload>;
|
|
||||||
export type requestSuccess = (member: Member) => Action<Member>;
|
|
||||||
export type requestFailure = (error: Error) => Action;
|
|
||||||
|
|
||||||
export const request: request = (signinId: string, signinPw: string): Action<SigninPayload> => {
|
|
||||||
return {
|
|
||||||
type: REQUEST,
|
|
||||||
payload: {
|
|
||||||
signinId: signinId,
|
|
||||||
signinPw: signinPw,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
export const requestSuccess: requestSuccess = (member: Member): Action<Member> => {
|
|
||||||
return {
|
|
||||||
type: REQUEST_SUCCESS,
|
|
||||||
payload: member,
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
export const requestFailure: requestFailure = (error: Error): Action => {
|
|
||||||
return {
|
|
||||||
type: REQUEST_FAILURE,
|
|
||||||
error: error,
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
|
@ -1,39 +0,0 @@
|
||||||
import { SagaIterator } from 'redux-saga';
|
|
||||||
import { call, Effect, fork, put, takeLatest } from 'redux-saga/effects';
|
|
||||||
|
|
||||||
|
|
||||||
import AppContext from '@overflow/commons/context/AppContext';
|
|
||||||
import Action from '@overflow/commons/redux/Action';
|
|
||||||
|
|
||||||
import Member from '../../api/model/Member';
|
|
||||||
import MemberService from '../../api/service/MemberService';
|
|
||||||
import * as ModifyActions from '../action/modify';
|
|
||||||
import ModifyPayload from '../payload/ModifyPayload';
|
|
||||||
|
|
||||||
function* modify(action: Action<ModifyPayload>): SagaIterator {
|
|
||||||
try {
|
|
||||||
const tempMember = action.payload.member;
|
|
||||||
// yield put({
|
|
||||||
// type: types.SENDING_REQUEST,
|
|
||||||
// payload: {sendingRequest: true},
|
|
||||||
// });
|
|
||||||
let memberService = AppContext.getInstance().getPouch(MemberService);
|
|
||||||
const member = yield call({context: memberService, fn: memberService.modify}, tempMember);
|
|
||||||
|
|
||||||
// if (responseBody.token === undefined) {
|
|
||||||
// throw new Error(MESSAGES.UNABLE_TO_FIND_TOKEN_IN_LOGIN_RESPONSE);
|
|
||||||
// }
|
|
||||||
yield put(ModifyActions.requestSuccess(member));
|
|
||||||
} catch (e) {
|
|
||||||
yield put(ModifyActions.requestFailure(e));
|
|
||||||
} finally {
|
|
||||||
// yield put({
|
|
||||||
// type: types.SENDING_REQUEST,
|
|
||||||
// payload: {sendingRequest: false},
|
|
||||||
// });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export function* watchModify(): SagaIterator {
|
|
||||||
yield takeLatest(ModifyActions.REQUEST, modify);
|
|
||||||
}
|
|
|
@ -1,39 +0,0 @@
|
||||||
import { SagaIterator } from 'redux-saga';
|
|
||||||
import { call, Effect, fork, put, takeLatest } from 'redux-saga/effects';
|
|
||||||
|
|
||||||
|
|
||||||
import AppContext from '@overflow/commons/context/AppContext';
|
|
||||||
import Action from '@overflow/commons/redux/Action';
|
|
||||||
|
|
||||||
import Member from '../../api/model/Member';
|
|
||||||
import MemberService from '../../api/service/MemberService';
|
|
||||||
import * as ReadActions from '../action/read';
|
|
||||||
import ReadPayload from '../payload/ReadPayload';
|
|
||||||
|
|
||||||
function* read(action: Action<ReadPayload>): SagaIterator {
|
|
||||||
try {
|
|
||||||
const id = action.payload.id;
|
|
||||||
// yield put({
|
|
||||||
// type: types.SENDING_REQUEST,
|
|
||||||
// payload: {sendingRequest: true},
|
|
||||||
// });
|
|
||||||
let memberService = AppContext.getInstance().getPouch(MemberService);
|
|
||||||
const member = yield call({context: memberService, fn: memberService.read}, id);
|
|
||||||
|
|
||||||
// if (responseBody.token === undefined) {
|
|
||||||
// throw new Error(MESSAGES.UNABLE_TO_FIND_TOKEN_IN_LOGIN_RESPONSE);
|
|
||||||
// }
|
|
||||||
yield put(ReadActions.requestSuccess(member));
|
|
||||||
} catch (e) {
|
|
||||||
yield put(ReadActions.requestFailure(e));
|
|
||||||
} finally {
|
|
||||||
// yield put({
|
|
||||||
// type: types.SENDING_REQUEST,
|
|
||||||
// payload: {sendingRequest: false},
|
|
||||||
// });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export function* watchRead(): SagaIterator {
|
|
||||||
yield takeLatest(ReadActions.REQUEST, read);
|
|
||||||
}
|
|
|
@ -1,27 +0,0 @@
|
||||||
import Action from '@overflow/commons/redux/Action';
|
|
||||||
import Member from '@overflow/member/api/model/Member';
|
|
||||||
|
|
||||||
import SignoutActionTypes from '../action/signOut';
|
|
||||||
import SigninState, { defaultState as signinDefaultState } from '../state/SignIn';
|
|
||||||
|
|
||||||
export type reducer = (state: SigninState, action: Action) => SigninState;
|
|
||||||
|
|
||||||
export const reducer: reducer = (state: SigninState = signinDefaultState, action: Action): SigninState => {
|
|
||||||
switch (action.type) {
|
|
||||||
case SignoutActionTypes.REQUEST_SUCCESS:
|
|
||||||
{
|
|
||||||
const aaa: SigninState = {
|
|
||||||
...state,
|
|
||||||
isAuthenticated: true,
|
|
||||||
};
|
|
||||||
|
|
||||||
return aaa;
|
|
||||||
}
|
|
||||||
case SignoutActionTypes.REQUEST_FAILURE:
|
|
||||||
{
|
|
||||||
return state;
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
return state;
|
|
||||||
}
|
|
||||||
};
|
|
|
@ -1,29 +0,0 @@
|
||||||
import Action from '@overflow/commons/redux/Action';
|
|
||||||
import Member from '@overflow/member/api/model/Member';
|
|
||||||
|
|
||||||
import SignupActionTypes from '../action/signUp';
|
|
||||||
import SignupState, { defaultState as signupDefaultState } from '../state/SignUp';
|
|
||||||
|
|
||||||
export type reducer = (state: SignupState, action: Action<Member | Error>) => SignupState;
|
|
||||||
|
|
||||||
export const reducer: reducer = (state: SignupState = signupDefaultState, action: Action<Member | Error>): SignupState => {
|
|
||||||
switch (action.type) {
|
|
||||||
case SignupActionTypes.REQUEST_SUCCESS:
|
|
||||||
{
|
|
||||||
let member = (<Action<Member>>action).payload;
|
|
||||||
|
|
||||||
const aaa: SignupState = {
|
|
||||||
...state,
|
|
||||||
isRegistered: true,
|
|
||||||
};
|
|
||||||
|
|
||||||
return aaa;
|
|
||||||
}
|
|
||||||
case SignupActionTypes.REQUEST_FAILURE:
|
|
||||||
{
|
|
||||||
return state;
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
return state;
|
|
||||||
}
|
|
||||||
};
|
|
|
@ -1,39 +0,0 @@
|
||||||
import { SagaIterator } from 'redux-saga';
|
|
||||||
import { call, Effect, fork, put, takeLatest } from 'redux-saga/effects';
|
|
||||||
|
|
||||||
|
|
||||||
import AppContext from '@overflow/commons/context/AppContext';
|
|
||||||
import Action from '@overflow/commons/redux/Action';
|
|
||||||
|
|
||||||
import NoAuthProbe from '../../api/model/NoAuthProbe';
|
|
||||||
import NoAuthProbeService from '../../api/service/NoAuthProbeService';
|
|
||||||
import * as ReadActions from '../action/read';
|
|
||||||
import ReadPayload from '../payload/ReadPayload';
|
|
||||||
|
|
||||||
function* read(action: Action<ReadPayload>): SagaIterator {
|
|
||||||
try {
|
|
||||||
const {id} = action.payload;
|
|
||||||
// yield put({
|
|
||||||
// type: types.SENDING_REQUEST,
|
|
||||||
// payload: {sendingRequest: true},
|
|
||||||
// });
|
|
||||||
let noAuthProbeService = AppContext.getInstance().getPouch(NoAuthProbeService);
|
|
||||||
const retApikey = yield call({context: noAuthProbeService, fn: noAuthProbeService.read}, id);
|
|
||||||
|
|
||||||
// if (responseBody.token === undefined) {
|
|
||||||
// throw new Error(MESSAGES.UNABLE_TO_FIND_TOKEN_IN_LOGIN_RESPONSE);
|
|
||||||
// }
|
|
||||||
yield put(ReadActions.requestSuccess(retApikey));
|
|
||||||
} catch (e) {
|
|
||||||
yield put(ReadActions.requestFailure(e));
|
|
||||||
} finally {
|
|
||||||
// yield put({
|
|
||||||
// type: types.SENDING_REQUEST,
|
|
||||||
// payload: {sendingRequest: false},
|
|
||||||
// });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export function* watchRead(): SagaIterator {
|
|
||||||
yield takeLatest(ReadActions.REQUEST, read);
|
|
||||||
}
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user