simple-boot-core
Advanced tools
Comparing version 1.0.41 to 1.0.42
@@ -7,3 +7,3 @@ import 'reflect-metadata'; | ||
} | ||
export type SituationType = string | InjectSituationType | ExceptionHandlerSituationType; | ||
export type SituationType = string | Symbol | ConstructorType<any> | InjectSituationType | ExceptionHandlerSituationType; | ||
export declare class SituationTypeContainer { | ||
@@ -28,4 +28,6 @@ situationType: SituationType; | ||
scheme?: string; | ||
symbol?: Symbol; | ||
type?: ConstructorType<any>; | ||
situationType?: SituationType; | ||
argument?: any; | ||
applyProxy?: { | ||
@@ -32,0 +34,0 @@ type: ConstructorType<ProxyHandler<any>>; |
@@ -14,3 +14,3 @@ import { ConstructorType, GenericClassDecorator, ReflectMethod } from '../../types/Types'; | ||
}; | ||
export type RouteProperty = ConstructorType<Object> | RoteAndFilter | [ConstructorType<Object> | RoteAndFilter, any] | RouteTargetMethod | string; | ||
export type RouteProperty = ConstructorType<Object> | RoteAndFilter | [ConstructorType<Object> | RoteAndFilter, any] | RouteTargetMethod | string | Symbol; | ||
export type Route = { | ||
@@ -26,4 +26,4 @@ [name: string]: RouteProperty; | ||
export declare const RouterMetadataKey: unique symbol; | ||
export declare function Router(target: ConstructorType<any>): void; | ||
export declare function Router(config: RouterConfig): GenericClassDecorator<ConstructorType<any>>; | ||
export declare function Router(target: ConstructorType<any> | Function): void; | ||
export declare function Router(config: RouterConfig): GenericClassDecorator<ConstructorType<any> | Function>; | ||
export declare const getRouter: (target: ConstructorType<any> | Function | any) => RouterConfig | undefined; | ||
@@ -30,0 +30,0 @@ type RouteConfig = { |
@@ -7,14 +7,17 @@ import 'reflect-metadata'; | ||
} | ||
export declare const sims: Map<ConstructorType<any>, Set<ConstructorType<any>>>; | ||
export declare const sims: Map<Function | ConstructorType<any>, Set<Function | ConstructorType<any>>>; | ||
export interface SimConfig { | ||
scheme?: string; | ||
symbol?: Symbol | (Symbol[]); | ||
scheme?: string | (string[]); | ||
scope?: Lifecycle; | ||
type?: ConstructorType<any> | ConstructorType<any>[]; | ||
using?: (ConstructorType<any>)[]; | ||
autoStart?: boolean; | ||
proxy?: ((ProxyHandler<any> | ConstructorType<any> | Function)) | (ProxyHandler<any> | ConstructorType<any> | Function)[]; | ||
type?: (ConstructorType<any> | Function) | (ConstructorType<any> | Function)[]; | ||
using?: (ConstructorType<any> | Function) | (ConstructorType<any> | Function)[]; | ||
} | ||
export declare const SimMetadataKey: unique symbol; | ||
export declare function Sim(target: ConstructorType<any>): void; | ||
export declare function Sim(config: SimConfig): GenericClassDecorator<ConstructorType<any>>; | ||
export declare function Sim(target: ConstructorType<any> | Function): void; | ||
export declare function Sim(config: SimConfig): GenericClassDecorator<ConstructorType<any> | Function>; | ||
export declare const getSim: (target: ConstructorType<any> | Function | any) => SimConfig | undefined; | ||
export declare const PostConstruct: (target: any, propertyKey: string, descriptor: PropertyDescriptor) => void; | ||
export declare const getPostConstruct: (target: any, propertyKey: string) => any; |
@@ -15,2 +15,3 @@ "use strict"; | ||
var _a; | ||
config.scope = (_a = config === null || config === void 0 ? void 0 : config.scope) !== null && _a !== void 0 ? _a : Lifecycle.Singleton; | ||
ReflectUtils_1.ReflectUtils.defineMetadata(exports.SimMetadataKey, config, target); | ||
@@ -24,3 +25,2 @@ var adding = function (targetKey, target) { | ||
}; | ||
config.scope = (_a = config === null || config === void 0 ? void 0 : config.scope) !== null && _a !== void 0 ? _a : Lifecycle.Singleton; | ||
if (Array.isArray(config === null || config === void 0 ? void 0 : config.type)) { | ||
@@ -56,3 +56,4 @@ config === null || config === void 0 ? void 0 : config.type.forEach(function (it) { | ||
} | ||
catch (e) { } | ||
catch (e) { | ||
} | ||
}; | ||
@@ -59,0 +60,0 @@ exports.getSim = getSim; |
{ | ||
"name": "simple-boot-core", | ||
"version": "1.0.41", | ||
"version": "1.0.42", | ||
"main": "SimpleApplication.js", | ||
@@ -49,4 +49,4 @@ "license": "MIT", | ||
"build": "rm -rf dist && tsc --sourceMap false --outDir dist --declarationDir dist", | ||
"npm-build": "rm -rf dist && tsc --sourceMap false --outDir dist --declarationDir dist && cp package.json dist && cp README.MD dist", | ||
"npm-publish": "npm run npm-build && npm publish ./dist", | ||
"npm:build": "rm -rf dist && tsc --sourceMap false --outDir dist --declarationDir dist && cp package.json dist && cp README.MD dist", | ||
"npm:publish": "npm run npm:build && npm publish ./dist", | ||
"tsc": "tsc", | ||
@@ -53,0 +53,0 @@ "tsc:watch": "rm -rf ./dist && mkdir dist && cp package.json dist && tsc --watch --sourceMap true", |
@@ -92,2 +92,27 @@ SIMPLE-BOOT-CORE | ||
``` | ||
## SimConfig | ||
```typescript | ||
export enum Lifecycle { | ||
/** | ||
* The default registration scope, Each resolve will return the same instance (including resolves from child containers) | ||
*/ | ||
Singleton = 'Singleton', | ||
/** | ||
* a new instance will be created with each resolve | ||
*/ | ||
Transient = 'Transient' | ||
} | ||
export interface SimConfig { | ||
symbol?: Symbol | (Symbol[]); | ||
scheme?: string | (string[]); | ||
scope?: Lifecycle; | ||
autoStart?: boolean; // auto start = auto new | ||
proxy?: ((ProxyHandler<any> | ConstructorType<any> | Function)) | (ProxyHandler<any> | ConstructorType<any> | Function)[]; | ||
type?: (ConstructorType<any> | Function) | (ConstructorType<any> | Function)[]; | ||
using?: (ConstructorType<any> | Function) | (ConstructorType<any> | Function)[]; | ||
} | ||
@Sim({...config}) | ||
class test {} | ||
``` | ||
</details> | ||
@@ -94,0 +119,0 @@ |
@@ -10,4 +10,4 @@ import { Intent } from '../intent/Intent'; | ||
activeRouterModule?: RouterModule<SimAtomic, any>; | ||
constructor(simstanceManager: SimstanceManager, rootRouter?: ConstructorType<any> | undefined); | ||
routingMap(prefix?: string, router?: ConstructorType<any> | undefined): { | ||
constructor(simstanceManager: SimstanceManager, rootRouter?: Function | ConstructorType<any> | undefined); | ||
routingMap(prefix?: string, router?: Function | ConstructorType<any> | undefined): { | ||
[key: string]: string | any; | ||
@@ -14,0 +14,0 @@ }; |
@@ -104,5 +104,2 @@ "use strict"; | ||
} | ||
return [4, new Promise(function (r) { return setTimeout(r, 0); })]; | ||
case 1: | ||
_v.sent(); | ||
routers = []; | ||
@@ -112,36 +109,36 @@ routerAtomic = new SimAtomic_1.SimAtomic(this.rootRouter, this.simstanceManager); | ||
executeModule = this.getExecuteModule(routerAtomic, intent, routers); | ||
if (!(executeModule === null || executeModule === void 0 ? void 0 : executeModule.router)) return [3, 14]; | ||
if (!(executeModule === null || executeModule === void 0 ? void 0 : executeModule.router)) return [3, 13]; | ||
executeModule.routerChains = routers; | ||
if (!(((_a = executeModule.routerChains) === null || _a === void 0 ? void 0 : _a.length) && ((_b = executeModule.routerChains) === null || _b === void 0 ? void 0 : _b.length) > 0)) return [3, 5]; | ||
if (!(((_a = executeModule.routerChains) === null || _a === void 0 ? void 0 : _a.length) && ((_b = executeModule.routerChains) === null || _b === void 0 ? void 0 : _b.length) > 0)) return [3, 4]; | ||
i = 0; | ||
_v.label = 2; | ||
case 2: | ||
if (!(i < executeModule.routerChains.length)) return [3, 5]; | ||
_v.label = 1; | ||
case 1: | ||
if (!(i < executeModule.routerChains.length)) return [3, 4]; | ||
current = executeModule.routerChains[i]; | ||
next = executeModule.routerChains[i + 1]; | ||
value = current.value; | ||
if (!next) return [3, 4]; | ||
if (!next) return [3, 3]; | ||
return [4, ((_c = value === null || value === void 0 ? void 0 : value.canActivate) === null || _c === void 0 ? void 0 : _c.call(value, intent, (_d = next === null || next === void 0 ? void 0 : next.value) !== null && _d !== void 0 ? _d : null))]; | ||
case 2: | ||
_v.sent(); | ||
_v.label = 3; | ||
case 3: | ||
_v.sent(); | ||
_v.label = 4; | ||
i++; | ||
return [3, 1]; | ||
case 4: | ||
i++; | ||
return [3, 2]; | ||
case 5: | ||
this.activeRouterModule = executeModule; | ||
if (!!(executeModule === null || executeModule === void 0 ? void 0 : executeModule.module)) return [3, 7]; | ||
if (!!(executeModule === null || executeModule === void 0 ? void 0 : executeModule.module)) return [3, 6]; | ||
routerChain = executeModule.routerChains[executeModule.routerChains.length - 1]; | ||
return [4, ((_f = (_e = routerChain === null || routerChain === void 0 ? void 0 : routerChain.value) === null || _e === void 0 ? void 0 : _e.canActivate) === null || _f === void 0 ? void 0 : _f.call(_e, intent, executeModule.getModuleInstance()))]; | ||
case 5: | ||
_v.sent(); | ||
return [3, 8]; | ||
case 6: | ||
_v.sent(); | ||
return [3, 9]; | ||
case 7: | ||
module_1 = null; | ||
module_1 = executeModule.getModuleInstance(); | ||
return [4, ((_j = (_h = (_g = executeModule.router) === null || _g === void 0 ? void 0 : _g.value) === null || _h === void 0 ? void 0 : _h.canActivate) === null || _j === void 0 ? void 0 : _j.call(_h, intent, module_1))]; | ||
case 7: | ||
_v.sent(); | ||
_v.label = 8; | ||
case 8: | ||
_v.sent(); | ||
_v.label = 9; | ||
case 9: | ||
otherStorage = new Map(); | ||
@@ -188,20 +185,20 @@ otherStorage.set(Intent_1.Intent, intent); | ||
_i = 0, _t = Array.from(OnRoute_1.onRoutes); | ||
_v.label = 10; | ||
case 10: | ||
if (!(_i < _t.length)) return [3, 13]; | ||
_v.label = 9; | ||
case 9: | ||
if (!(_i < _t.length)) return [3, 12]; | ||
_u = _t[_i], key = _u[0], value = _u[1]; | ||
return [5, _loop_1(key, value)]; | ||
case 10: | ||
_v.sent(); | ||
_v.label = 11; | ||
case 11: | ||
_v.sent(); | ||
_v.label = 12; | ||
case 12: | ||
_i++; | ||
return [3, 10]; | ||
case 13: return [2, this.activeRouterModule]; | ||
return [3, 9]; | ||
case 12: return [2, this.activeRouterModule]; | ||
case 13: | ||
if (!(routers.length && routers.length > 0)) return [3, 17]; | ||
i = 0; | ||
_v.label = 14; | ||
case 14: | ||
if (!(routers.length && routers.length > 0)) return [3, 18]; | ||
i = 0; | ||
_v.label = 15; | ||
case 15: | ||
if (!(i < routers.length)) return [3, 18]; | ||
if (!(i < routers.length)) return [3, 17]; | ||
current = routers[i]; | ||
@@ -211,9 +208,9 @@ next = routers[i + 1]; | ||
return [4, ((_r = value === null || value === void 0 ? void 0 : value.canActivate) === null || _r === void 0 ? void 0 : _r.call(value, intent, (_s = next === null || next === void 0 ? void 0 : next.value) !== null && _s !== void 0 ? _s : null))]; | ||
case 15: | ||
_v.sent(); | ||
_v.label = 16; | ||
case 16: | ||
_v.sent(); | ||
_v.label = 17; | ||
i++; | ||
return [3, 14]; | ||
case 17: | ||
i++; | ||
return [3, 15]; | ||
case 18: | ||
routerModule = new RouterModule_1.RouterModule(this.simstanceManager, rootRouter, undefined, routers); | ||
@@ -291,3 +288,3 @@ this.activeRouterModule = routerModule; | ||
var _this = this; | ||
var _a; | ||
var _a, _b; | ||
var child; | ||
@@ -300,2 +297,5 @@ var data; | ||
} | ||
else if (typeof routeElement === 'symbol') { | ||
child = (_a = this.simstanceManager.findFirstSim(routeElement)) === null || _a === void 0 ? void 0 : _a.type; | ||
} | ||
else if (typeof routeElement === 'string') { | ||
@@ -325,3 +325,3 @@ return this.findRouteProperty(route, routeElement, intent); | ||
else if (typeof routeElement === 'object' && 'target' in routeElement && 'propertyKeys' in routeElement) { | ||
var noAccept = (_a = routeElement.filters) === null || _a === void 0 ? void 0 : _a.filter(function (it) { return it; }).some(function (it) { var _a; return ((_a = (typeof it === 'function' ? _this.simstanceManager.getOrNewSim(it) : it)) === null || _a === void 0 ? void 0 : _a.isAccept(intent)) === false; }); | ||
var noAccept = (_b = routeElement.filters) === null || _b === void 0 ? void 0 : _b.filter(function (it) { return it; }).some(function (it) { var _a; return ((_a = (typeof it === 'function' ? _this.simstanceManager.getOrNewSim(it) : it)) === null || _a === void 0 ? void 0 : _a.isAccept(intent)) === false; }); | ||
if (!noAccept) { | ||
@@ -328,0 +328,0 @@ child = routeElement.target; |
@@ -8,3 +8,3 @@ import { ConstructorType } from '../types/Types'; | ||
router?: R | undefined; | ||
module?: ConstructorType<M> | undefined; | ||
module?: Function | ConstructorType<M> | undefined; | ||
routerChains: R[]; | ||
@@ -17,3 +17,3 @@ pathData?: { | ||
propertyKeys?: (string | symbol)[]; | ||
constructor(simstanceManager: SimstanceManager, router?: R | undefined, module?: ConstructorType<M> | undefined, routerChains?: R[]); | ||
constructor(simstanceManager: SimstanceManager, router?: R | undefined, module?: Function | ConstructorType<M> | undefined, routerChains?: R[]); | ||
getModuleInstance<T = M>(): T | undefined; | ||
@@ -20,0 +20,0 @@ executeModuleProperty(propertyKey: string | symbol, ...param: any[]): any; |
@@ -14,8 +14,8 @@ import 'reflect-metadata'; | ||
routerManager: RouterManager; | ||
rootRouter?: ConstructorType<Object>; | ||
rootRouter?: ConstructorType<Object> | Function; | ||
option: SimOption; | ||
constructor(); | ||
constructor(option: SimOption); | ||
constructor(rootRouter?: ConstructorType<Object>); | ||
constructor(rootRouter?: ConstructorType<Object>, option?: SimOption); | ||
constructor(rootRouter?: ConstructorType<Object> | Function); | ||
constructor(rootRouter?: ConstructorType<Object> | Function, option?: SimOption); | ||
getSimstanceManager(): SimstanceManager; | ||
@@ -25,5 +25,5 @@ getIntentManager(): IntentManager; | ||
run(otherInstanceSim?: Map<ConstructorType<any>, any>): SimstanceManager; | ||
simAtomic<T>(type: ConstructorType<T>): SimAtomic<T>; | ||
simAtomic<T>(type: ConstructorType<T> | Function): SimAtomic<T>; | ||
getInstance<T>(type: ConstructorType<T>): NonNullable<T>; | ||
sim<T>(type: ConstructorType<T>): T | undefined; | ||
sim<T>(type: ConstructorType<T> | Function): T | undefined; | ||
publishIntent(i: string, data?: any): any[]; | ||
@@ -30,0 +30,0 @@ publishIntent(i: Intent): any[]; |
@@ -54,3 +54,3 @@ "use strict"; | ||
else { | ||
throw new SimNoSuch_1.SimNoSuch('SimNoSuch: no simple instance. ' + 'name:' + ((_b = (_a = type === null || type === void 0 ? void 0 : type.prototype) === null || _a === void 0 ? void 0 : _a.constructor) === null || _b === void 0 ? void 0 : _b.name) + ',' + type); | ||
throw new SimNoSuch_1.SimNoSuch('SimNoSuch: no simple instance(getInstance) ' + 'name:' + ((_b = (_a = type === null || type === void 0 ? void 0 : type.prototype) === null || _a === void 0 ? void 0 : _a.constructor) === null || _b === void 0 ? void 0 : _b.name) + ',' + type); | ||
} | ||
@@ -57,0 +57,0 @@ }; |
import { ConstructorType } from '../types/Types'; | ||
import { SimConfig } from '../decorators/SimDecorator'; | ||
import { SimstanceManager } from './SimstanceManager'; | ||
export declare class SimAtomic<T = object> { | ||
type: ConstructorType<T>; | ||
type: ConstructorType<T> | Function; | ||
private simstanceManager; | ||
constructor(type: ConstructorType<T>, simstanceManager: SimstanceManager); | ||
getConfig<C = any>(key?: symbol): C | undefined; | ||
constructor(type: ConstructorType<T> | Function, simstanceManager: SimstanceManager); | ||
getConfig(): SimConfig | undefined; | ||
getConfig<C = any>(key: symbol): C | undefined; | ||
getConfigs(): any[]; | ||
get value(): T | undefined; | ||
} |
@@ -6,2 +6,3 @@ "use strict"; | ||
var ReflectUtils_1 = require("../utils/reflect/ReflectUtils"); | ||
var ConvertUtils_1 = require("../utils/convert/ConvertUtils"); | ||
var SimAtomic = (function () { | ||
@@ -21,3 +22,12 @@ function SimAtomic(type, simstanceManager) { | ||
get: function () { | ||
return this.simstanceManager.getOrNewSim(this.type); | ||
var _a; | ||
var types = ConvertUtils_1.ConvertUtils.flatArray((_a = this.getConfig()) === null || _a === void 0 ? void 0 : _a.type); | ||
types.push(this.type); | ||
for (var _i = 0, types_1 = types; _i < types_1.length; _i++) { | ||
var typeElement = types_1[_i]; | ||
var instance = this.simstanceManager.getOrNewSim(typeElement, this.type); | ||
if (instance) { | ||
return instance; | ||
} | ||
} | ||
}, | ||
@@ -24,0 +34,0 @@ enumerable: false, |
@@ -17,23 +17,24 @@ import 'reflect-metadata'; | ||
constructor(option: SimOption); | ||
get storage(): Map<ConstructorType<any>, Map<ConstructorType<any>, any>>; | ||
get storage(): Map<Function | ConstructorType<any>, Map<Function | ConstructorType<any>, any>>; | ||
getSimAtomics(): SimAtomic[]; | ||
getSimConfig(scheme: string | undefined): SimAtomic<any>[]; | ||
findFirstSim({ scheme, type }: { | ||
getSimConfig(schemeOrSymbol: string | Symbol | undefined): SimAtomic<any>[]; | ||
findFirstSim<T = any>(symbol: Symbol): SimAtomic<T> | undefined; | ||
findFirstSim<T = any>(data: { | ||
scheme?: string; | ||
type?: ConstructorType<any>; | ||
}): SimAtomic<any> | undefined; | ||
getStoreSets<T>(targetKey: ConstructorType<T>): { | ||
type: ConstructorType<T>; | ||
}): SimAtomic<T> | undefined; | ||
getStoreSets<T>(targetKey: ConstructorType<T> | Function): { | ||
type: ConstructorType<T> | Function; | ||
instance?: T; | ||
}[]; | ||
getStoreSet<T>(targetKey: ConstructorType<T>, target?: ConstructorType<any>): { | ||
type: ConstructorType<T>; | ||
getStoreSet<T>(targetKey: ConstructorType<T> | Function, target?: ConstructorType<any> | Function): { | ||
type: ConstructorType<T> | Function; | ||
instance?: T; | ||
} | undefined; | ||
getStoreInstance<T>(targetKey: ConstructorType<T>, target?: ConstructorType<any>): T | undefined; | ||
getOrNewSim<T>(target?: ConstructorType<T>): T | undefined; | ||
register(keyType: ConstructorType<any>, regTyps: Set<ConstructorType<any>>): void; | ||
set(targetKey: ConstructorType<any>, obj: any, target?: ConstructorType<any>): void; | ||
resolve<T>(targetKey: ConstructorType<any>, target?: ConstructorType<any>): T; | ||
newSim<T>(target: ConstructorType<T>, simCreateAfter?: (data: T) => void, otherStorage?: Map<ConstructorType<any>, any>): T; | ||
getOrNewSim<T>(target?: ConstructorType<T> | Function, originTypeTarget?: Function | ConstructorType<T> | undefined): T | undefined; | ||
register(keyType: ConstructorType<any> | Function, regTyps: Set<ConstructorType<any> | Function>): void; | ||
set(targetKey: ConstructorType<any> | Function, obj: any, target?: ConstructorType<any> | Function): void; | ||
resolve<T>(targetKey: ConstructorType<any> | Function, target?: ConstructorType<any> | Function): T; | ||
newSim<T = any>(target: ConstructorType<T> | Function, simCreateAfter?: (data: T) => void, otherStorage?: Map<ConstructorType<any>, any>): T; | ||
callBindPostConstruct(obj: any): void; | ||
@@ -40,0 +41,0 @@ executeBindParameterSimPromise({ target, targetKey, firstCheckMaker }: { |
@@ -58,2 +58,3 @@ "use strict"; | ||
var SimProxyHandler_1 = require("../proxy/SimProxyHandler"); | ||
var ConvertUtils_1 = require("../utils/convert/ConvertUtils"); | ||
var SimstanceManager = (function () { | ||
@@ -78,3 +79,3 @@ function SimstanceManager(option) { | ||
var r = []; | ||
Array.from(this._storage.values()).forEach(function (it) { | ||
Array.from(this.storage.values()).forEach(function (it) { | ||
r.push.apply(r, Array.from(Array.from(it.keys())).map(function (sit) { return new SimAtomic_1.SimAtomic(sit, _this); })); | ||
@@ -84,16 +85,34 @@ }); | ||
}; | ||
SimstanceManager.prototype.getSimConfig = function (scheme) { | ||
SimstanceManager.prototype.getSimConfig = function (schemeOrSymbol) { | ||
var newVar = this.getSimAtomics().filter(function (it) { | ||
var _a; | ||
return scheme && it && scheme === ((_a = it === null || it === void 0 ? void 0 : it.getConfig()) === null || _a === void 0 ? void 0 : _a.scheme); | ||
var config = it === null || it === void 0 ? void 0 : it.getConfig(); | ||
var symbols = ConvertUtils_1.ConvertUtils.flatArray(config === null || config === void 0 ? void 0 : config.symbol); | ||
var schemes = ConvertUtils_1.ConvertUtils.flatArray(config === null || config === void 0 ? void 0 : config.scheme); | ||
if (typeof schemeOrSymbol === 'symbol') { | ||
return schemeOrSymbol && it && symbols.includes(schemeOrSymbol); | ||
} | ||
else if (typeof schemeOrSymbol === 'string') { | ||
return schemeOrSymbol && it && schemes.includes(schemeOrSymbol); | ||
} | ||
else { | ||
return false; | ||
} | ||
}) || []; | ||
return newVar; | ||
}; | ||
SimstanceManager.prototype.findFirstSim = function (_a) { | ||
var scheme = _a.scheme, type = _a.type; | ||
if (scheme || type) { | ||
SimstanceManager.prototype.findFirstSim = function (data) { | ||
if (data) { | ||
var simAtomics = this.getSimAtomics(); | ||
var find = simAtomics.find(function (it) { | ||
var _a; | ||
var b = (scheme ? scheme === ((_a = it.getConfig()) === null || _a === void 0 ? void 0 : _a.scheme) : true) && (type ? it.type === type : true); | ||
var b = false; | ||
var config = it.getConfig(); | ||
var symbols = ConvertUtils_1.ConvertUtils.flatArray(config === null || config === void 0 ? void 0 : config.symbol); | ||
var schemes = ConvertUtils_1.ConvertUtils.flatArray(config === null || config === void 0 ? void 0 : config.scheme); | ||
if (typeof data === 'symbol') { | ||
b = symbols.includes(data); | ||
} | ||
else { | ||
var _a = data, scheme = _a.scheme, type = _a.type; | ||
b = (scheme ? schemes.includes(scheme) : true) && (type ? it.type === type : true); | ||
} | ||
return b; | ||
@@ -118,7 +137,8 @@ }); | ||
}; | ||
SimstanceManager.prototype.getOrNewSim = function (target) { | ||
SimstanceManager.prototype.getOrNewSim = function (target, originTypeTarget) { | ||
if (originTypeTarget === void 0) { originTypeTarget = target; } | ||
if (target) { | ||
var registed = this.getStoreSet(target); | ||
var registed = this.getStoreSet(target, originTypeTarget); | ||
if ((registed === null || registed === void 0 ? void 0 : registed.type) && !(registed === null || registed === void 0 ? void 0 : registed.instance)) { | ||
return this.resolve(target); | ||
return this.resolve(target, originTypeTarget); | ||
} | ||
@@ -130,3 +150,3 @@ return registed === null || registed === void 0 ? void 0 : registed.instance; | ||
var _a; | ||
var itemMap = (_a = this._storage.get(keyType)) !== null && _a !== void 0 ? _a : new Map(); | ||
var itemMap = (_a = this.storage.get(keyType)) !== null && _a !== void 0 ? _a : new Map(); | ||
regTyps.forEach(function (it) { | ||
@@ -137,3 +157,3 @@ if (!itemMap.has(it)) { | ||
}); | ||
this._storage.set(keyType, itemMap); | ||
this.storage.set(keyType, itemMap); | ||
}; | ||
@@ -164,3 +184,3 @@ SimstanceManager.prototype.set = function (targetKey, obj, target) { | ||
} | ||
var simNoSuch = new SimNoSuch_1.SimNoSuch('SimNoSuch: no simple instance ' + 'name:' + ((_d = (_c = targetKey === null || targetKey === void 0 ? void 0 : targetKey.prototype) === null || _c === void 0 ? void 0 : _c.constructor) === null || _d === void 0 ? void 0 : _d.name) + ',' + targetKey); | ||
var simNoSuch = new SimNoSuch_1.SimNoSuch('SimNoSuch: no simple instance(resolve) ' + 'name:' + ((_d = (_c = targetKey === null || targetKey === void 0 ? void 0 : targetKey.prototype) === null || _c === void 0 ? void 0 : _c.constructor) === null || _d === void 0 ? void 0 : _d.name) + ',' + targetKey); | ||
console.error(simNoSuch); | ||
@@ -170,4 +190,17 @@ throw simNoSuch; | ||
SimstanceManager.prototype.newSim = function (target, simCreateAfter, otherStorage) { | ||
var _this = this; | ||
var r = new (target.bind.apply(target, __spreadArray([void 0], this.getParameterSim({ target: target }, otherStorage), false)))(); | ||
var p = this.proxy(r); | ||
var config = (0, SimDecorator_1.getSim)(target); | ||
if (config === null || config === void 0 ? void 0 : config.proxy) { | ||
var proxys = Array.isArray(config.proxy) ? config.proxy : [config.proxy]; | ||
proxys.forEach(function (it) { | ||
if (typeof it === 'object') { | ||
p = new Proxy(p, it); | ||
} | ||
else { | ||
p = new Proxy(p, _this.getOrNewSim(it)); | ||
} | ||
}); | ||
} | ||
simCreateAfter === null || simCreateAfter === void 0 ? void 0 : simCreateAfter(p); | ||
@@ -242,3 +275,3 @@ this.callBindPostConstruct(p); | ||
var obj = otherStorage === null || otherStorage === void 0 ? void 0 : otherStorage.get(token); | ||
if (token === Array && (inject_1.type || inject_1.scheme)) { | ||
if (token === Array && (inject_1.type || inject_1.scheme || inject_1.symbol)) { | ||
var p = []; | ||
@@ -248,2 +281,5 @@ if (inject_1.type) { | ||
} | ||
if (inject_1.symbol) { | ||
p.push.apply(p, _this.getSimConfig(inject_1.symbol).map(function (it) { return it.value; })); | ||
} | ||
if (inject_1.scheme) { | ||
@@ -261,3 +297,10 @@ p.push.apply(p, _this.getSimConfig(inject_1.scheme).map(function (it) { return it.value; })); | ||
else if (situations && situations.length > 0) { | ||
var find = situations.find(function (a) { return a.situationType === inject_1.situationType; }); | ||
var find = situations.find(function (a) { | ||
if (a.index !== undefined) { | ||
return a.situationType === inject_1.situationType && a.index === idx; | ||
} | ||
else { | ||
return a.situationType === inject_1.situationType; | ||
} | ||
}); | ||
if (find) { | ||
@@ -269,3 +312,3 @@ obj = find.data; | ||
if (!obj) { | ||
var findFirstSim = _this.findFirstSim({ scheme: inject_1.scheme, type: inject_1.type }); | ||
var findFirstSim = inject_1.symbol ? _this.findFirstSim(inject_1.symbol) : _this.findFirstSim({ scheme: inject_1.scheme, type: inject_1.type }); | ||
obj = findFirstSim ? _this.resolve((_b = findFirstSim === null || findFirstSim === void 0 ? void 0 : findFirstSim.type) !== null && _b !== void 0 ? _b : token) : _this.resolve(token); | ||
@@ -320,2 +363,8 @@ } | ||
this.callBindPostConstruct(this); | ||
this.getSimAtomics().forEach(function (it) { | ||
var _a; | ||
if ((_a = it.getConfig()) === null || _a === void 0 ? void 0 : _a.autoStart) { | ||
it.value; | ||
} | ||
}); | ||
}; | ||
@@ -322,0 +371,0 @@ return SimstanceManager; |
@@ -12,2 +12,3 @@ export declare class ConvertUtils { | ||
static toObject(obj: any): any; | ||
static flatArray<T>(data?: T | T[]): (T extends readonly (infer InnerArr)[] ? InnerArr : T)[]; | ||
static iteratorToArray<T>(it: any): T[]; | ||
@@ -14,0 +15,0 @@ static toJson(obj: any): string; |
@@ -66,2 +66,6 @@ "use strict"; | ||
}; | ||
ConvertUtils.flatArray = function (data) { | ||
var datas = (Array.isArray(data) ? data : (data ? [data] : [])); | ||
return datas.flat(); | ||
}; | ||
ConvertUtils.iteratorToArray = function (it) { | ||
@@ -68,0 +72,0 @@ return Array.from(it); |
@@ -8,5 +8,5 @@ import { ConstructorType } from '../../types/Types'; | ||
static seal<T>(target: T): T; | ||
static isPrototypeOfTarget(start: ConstructorType<any> | null | undefined, target: any | null | undefined): boolean; | ||
static getPrototypeOfDepth(target: any, dest: ConstructorType<any> | null | undefined): object[]; | ||
static getAllProtoType(start: ConstructorType<any> | null | undefined): ConstructorType<any>[]; | ||
static isPrototypeOfTarget(start: ConstructorType<any> | Function | null | undefined, target: any | null | undefined): boolean; | ||
static getPrototypeOfDepth(target: any, dest: ConstructorType<any> | Function | null | undefined): object[]; | ||
static getAllProtoType(start: ConstructorType<any> | Function): (ConstructorType<any> | Function)[]; | ||
static getPrototypeOf(start: any): any; | ||
@@ -13,0 +13,0 @@ static getPrototypeKeyMap(target: any): Map<Function, string>; |
@@ -74,8 +74,12 @@ "use strict"; | ||
ObjectUtils.getAllProtoType = function (start) { | ||
var protos = []; | ||
while (start) { | ||
protos.push(start); | ||
start = Object.getPrototypeOf(start); | ||
} | ||
return protos; | ||
var depth = function (target, bowl) { | ||
if (bowl === void 0) { bowl = []; } | ||
if (target.prototype) { | ||
bowl.push(target); | ||
depth(Object.getPrototypeOf(target), bowl); | ||
} | ||
return bowl; | ||
}; | ||
var d = depth(start); | ||
return d; | ||
}; | ||
@@ -82,0 +86,0 @@ ObjectUtils.getPrototypeOf = function (start) { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
155225
82
3194
405