@injex/core
Advanced tools
Comparing version 2.1.0 to 3.0.0-alpha.0
@@ -12,3 +12,3 @@ "use strict"; | ||
for (var i = 0, len = names.length; i < len; i++) { | ||
metadataHandlers_1.default.pushMetadata(targetConstructor, "aliases", names[i]); | ||
metadataHandlers_1.default.pushMetadata(targetConstructor.prototype, "aliases", names[i]); | ||
} | ||
@@ -15,0 +15,0 @@ }; |
@@ -1,1 +0,2 @@ | ||
export declare function bootstrap(): (targetConstructor: any) => void; | ||
import { IConstructor } from "@injex/stdlib"; | ||
export declare function bootstrap(): (targetConstructor: IConstructor) => void; |
@@ -8,6 +8,6 @@ "use strict"; | ||
return function (targetConstructor) { | ||
metadataHandlers_1.default.setMetadata(targetConstructor, "item", targetConstructor); | ||
metadataHandlers_1.default.setMetadata(targetConstructor, "name", constants_1.bootstrapSymbol); | ||
metadataHandlers_1.default.setMetadata(targetConstructor, "bootstrap", true); | ||
metadataHandlers_1.default.setMetadata(targetConstructor, "singleton", true); | ||
metadataHandlers_1.default.setMetadata(targetConstructor.prototype, "item", targetConstructor); | ||
metadataHandlers_1.default.setMetadata(targetConstructor.prototype, "name", constants_1.bootstrapSymbol); | ||
metadataHandlers_1.default.setMetadata(targetConstructor.prototype, "bootstrap", true); | ||
metadataHandlers_1.default.setMetadata(targetConstructor.prototype, "singleton", true); | ||
}; | ||
@@ -14,0 +14,0 @@ } |
@@ -1,1 +0,2 @@ | ||
export declare function define(name?: string): (targetConstructor: any) => void; | ||
import { IConstructor } from "@injex/stdlib"; | ||
export declare function define(name?: string): (targetConstructor: IConstructor) => void; |
@@ -11,4 +11,4 @@ "use strict"; | ||
return function (targetConstructor) { | ||
metadataHandlers_1.default.setMetadata(targetConstructor, "item", targetConstructor); | ||
metadataHandlers_1.default.setMetadata(targetConstructor, "name", getDependencyName(targetConstructor, name)); | ||
metadataHandlers_1.default.setMetadata(targetConstructor.prototype, "item", targetConstructor); | ||
metadataHandlers_1.default.setMetadata(targetConstructor.prototype, "name", getDependencyName(targetConstructor, name)); | ||
}; | ||
@@ -15,0 +15,0 @@ } |
@@ -7,3 +7,3 @@ "use strict"; | ||
return function (targetPrototype, methodName) { | ||
metadataHandlers_1.default.setMetadata(targetPrototype.constructor, "initMethod", methodName); | ||
metadataHandlers_1.default.setMetadata(targetPrototype, "initMethod", methodName); | ||
}; | ||
@@ -10,0 +10,0 @@ } |
@@ -1,1 +0,1 @@ | ||
export declare function inject(dependencyNameOrType?: any): (targetPrototype: any, dependency: string) => void; | ||
export declare function inject(dependencyNameOrType?: any): (targetPrototype: object, dependency: string) => void; |
@@ -7,3 +7,3 @@ "use strict"; | ||
return function (targetPrototype, dependency) { | ||
metadataHandlers_1.default.pushMetadata(targetPrototype.constructor, "dependencies", { | ||
metadataHandlers_1.default.pushMetadata(targetPrototype, "dependencies", { | ||
label: dependency, | ||
@@ -10,0 +10,0 @@ value: dependencyNameOrType || dependency |
@@ -1,1 +0,1 @@ | ||
export declare function injectAlias(alias: string, keyBy?: string): (targetPrototype: any, dependency: string) => void; | ||
export declare function injectAlias(alias: string, keyBy?: string): (targetPrototype: object, dependency: string) => void; |
@@ -7,3 +7,3 @@ "use strict"; | ||
return function (targetPrototype, dependency) { | ||
metadataHandlers_1.default.pushMetadata(targetPrototype.constructor, "aliasDependencies", { | ||
metadataHandlers_1.default.pushMetadata(targetPrototype, "aliasDependencies", { | ||
label: dependency, | ||
@@ -10,0 +10,0 @@ alias: alias, |
@@ -7,4 +7,4 @@ "use strict"; | ||
return function (targetConstructor) { | ||
metadataHandlers_1.default.setMetadata(targetConstructor, "lazy", true); | ||
metadataHandlers_1.default.setMetadata(targetConstructor, "singleton", true); | ||
metadataHandlers_1.default.setMetadata(targetConstructor.prototype, "lazy", true); | ||
metadataHandlers_1.default.setMetadata(targetConstructor.prototype, "singleton", true); | ||
}; | ||
@@ -11,0 +11,0 @@ } |
@@ -1,1 +0,2 @@ | ||
export declare function singleton(): (targetConstructor: any) => void; | ||
import { IConstructor } from "@injex/stdlib"; | ||
export declare function singleton(): (targetConstructor: IConstructor) => void; |
@@ -7,3 +7,3 @@ "use strict"; | ||
return function (targetConstructor) { | ||
metadataHandlers_1.default.setMetadata(targetConstructor, "singleton", true); | ||
metadataHandlers_1.default.setMetadata(targetConstructor.prototype, "singleton", true); | ||
}; | ||
@@ -10,0 +10,0 @@ } |
@@ -123,3 +123,3 @@ "use strict"; | ||
InjexContainer.prototype._createModule = function (item) { | ||
var metadata = metadataHandlers_1.default.getMetadata(item); | ||
var metadata = metadataHandlers_1.default.getMetadata(item.prototype); | ||
this._throwIfModuleExists(metadata.name); | ||
@@ -170,3 +170,3 @@ var module; | ||
Ctor = _a.sent(); | ||
lazyMetadata = metadataHandlers_1.default.getMetadata(Ctor); | ||
lazyMetadata = metadataHandlers_1.default.getMetadata(Ctor.prototype); | ||
lazyInstance = self._createInstance(Ctor, args); | ||
@@ -236,14 +236,27 @@ self._injectModuleDependencies(lazyInstance, lazyMetadata); | ||
InjexContainer.prototype._invokeModuleInitMethod = function (module, metadata) { | ||
if (metadata.initMethod && stdlib_1.isFunction(module[metadata.initMethod])) { | ||
try { | ||
return module[metadata.initMethod](); | ||
var chain = []; | ||
metadataHandlers_1.default.forEachProtoMetadata(module, function (_, meta) { | ||
if ((meta === null || meta === void 0 ? void 0 : meta.initMethod) && chain.indexOf(meta.initMethod) < 0) { | ||
chain.push(meta.initMethod); | ||
} | ||
catch (e) { | ||
this._onInitModuleError(metadata, e); | ||
}); | ||
try { | ||
var promises = []; | ||
for (var i = chain.length - 1; i >= 0; i--) { | ||
var res = module[chain[i]].call(module); | ||
if (stdlib_1.isPromise(res)) { | ||
promises.push(res); | ||
} | ||
} | ||
if (promises.length) { | ||
return Promise.all(promises); | ||
} | ||
} | ||
catch (e) { | ||
this._onInitModuleError(metadata.name, e); | ||
} | ||
}; | ||
InjexContainer.prototype._onInitModuleError = function (metadata, err) { | ||
InjexContainer.prototype._onInitModuleError = function (moduleName, err) { | ||
this._logger.error(err); | ||
throw new errors_1.InitializeMuduleError(metadata.name); | ||
throw new errors_1.InitializeMuduleError(moduleName); | ||
}; | ||
@@ -260,3 +273,3 @@ InjexContainer.prototype._createInstance = function (construct, args) { | ||
else if (moduleNameOrType instanceof Function) { | ||
var metadata = metadataHandlers_1.default.getMetadata(moduleNameOrType); | ||
var metadata = metadataHandlers_1.default.getMetadata(moduleNameOrType.prototype); | ||
return this._modules.get(metadata.name); | ||
@@ -267,23 +280,27 @@ } | ||
InjexContainer.prototype._injectModuleDependencies = function (module, metadata) { | ||
var dependencies = metadata.dependencies || []; | ||
var aliasDependencies = metadata.aliasDependencies || []; | ||
for (var _i = 0, dependencies_1 = dependencies; _i < dependencies_1.length; _i++) { | ||
var _a = dependencies_1[_i], label = _a.label, value = _a.value; | ||
var dependency = this.get(value); | ||
if (!dependency) { | ||
throw new errors_1.ModuleDependencyNotFoundError(metadata.name, value); | ||
var _this = this; | ||
metadataHandlers_1.default.forEachProtoMetadata(module, function (_, meta) { | ||
var dependencies = meta.dependencies || []; | ||
var aliasDependencies = meta.aliasDependencies || []; | ||
for (var _i = 0, dependencies_1 = dependencies; _i < dependencies_1.length; _i++) { | ||
var _a = dependencies_1[_i], label = _a.label, value = _a.value; | ||
var dependency = _this.get(value); | ||
if (!dependency) { | ||
throw new errors_1.ModuleDependencyNotFoundError(metadata.name, value); | ||
} | ||
module[label] = dependency; | ||
} | ||
module[label] = dependency; | ||
} | ||
for (var _b = 0, aliasDependencies_1 = aliasDependencies; _b < aliasDependencies_1.length; _b++) { | ||
var _c = aliasDependencies_1[_b], label = _c.label, alias = _c.alias, keyBy = _c.keyBy; | ||
module[label] = this.getAlias(alias, keyBy); | ||
} | ||
for (var _b = 0, aliasDependencies_1 = aliasDependencies; _b < aliasDependencies_1.length; _b++) { | ||
var _c = aliasDependencies_1[_b], label = _c.label, alias = _c.alias, keyBy = _c.keyBy; | ||
module[label] = _this.getAlias(alias, keyBy); | ||
} | ||
}); | ||
}; | ||
InjexContainer.prototype._register = function (item) { | ||
if (!item || !metadataHandlers_1.default.hasMetadata(item)) { | ||
var _a; | ||
if ((_a = !(item === null || item === void 0 ? void 0 : item.prototype)) !== null && _a !== void 0 ? _a : !metadataHandlers_1.default.hasMetadata(item.prototype)) { | ||
return; | ||
} | ||
var metadata = metadataHandlers_1.default.getMetadata(item); | ||
if (item !== metadata.item) { | ||
var metadata = metadataHandlers_1.default.getMetadata(item.prototype); | ||
if (!metadata.name) { | ||
return; | ||
@@ -290,0 +307,0 @@ } |
@@ -55,2 +55,4 @@ import { Hook, IConstructor, LogLevel } from "@injex/stdlib"; | ||
} | ||
export declare type Factory<T> = (...args: any[]) => T; | ||
export declare type AsyncFactory<T> = (...args: any[]) => Promise<T>; | ||
export declare type AliasFactory<K extends string, T> = { | ||
@@ -57,0 +59,0 @@ [key in K]: (...args: any[]) => T; |
{ | ||
"name": "@injex/core", | ||
"version": "2.1.0", | ||
"version": "3.0.0-alpha.0", | ||
"description": "Simple, Decorated, Pluggable dependency-injection framework for TypeScript apps", | ||
@@ -46,3 +46,3 @@ "keywords": [ | ||
"dependencies": { | ||
"@injex/stdlib": "^2.1.0", | ||
"@injex/stdlib": "^3.0.0-alpha.0", | ||
"tslib": "^2.0.1" | ||
@@ -56,3 +56,3 @@ }, | ||
}, | ||
"gitHead": "1e2aaf520e73125f5108801bbc9c8c15550c5349" | ||
"gitHead": "c52d04648f8dbd81e09f5e09f7770e55eac2014f" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
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
49320
706
1
+ Added@injex/stdlib@3.5.1(transitive)
+ Addedreflect-metadata@0.1.14(transitive)
- Removed@injex/stdlib@2.1.0(transitive)
Updated@injex/stdlib@^3.0.0-alpha.0