@injex/core
Advanced tools
Comparing version 3.0.0-alpha.2 to 3.0.0-alpha.3
@@ -11,1 +11,4 @@ import { ModuleName } from "./interfaces"; | ||
} | ||
export declare class FactoryModuleNotExistsError extends Error { | ||
constructor(factory: any); | ||
} |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.InvalidPluginError = exports.DuplicateDefinitionError = exports.InitializeMuduleError = void 0; | ||
exports.FactoryModuleNotExistsError = exports.InvalidPluginError = exports.DuplicateDefinitionError = exports.InitializeMuduleError = void 0; | ||
var tslib_1 = require("tslib"); | ||
@@ -25,3 +25,3 @@ var stdlib_1 = require("@injex/stdlib"); | ||
function InvalidPluginError(plugin) { | ||
return _super.call(this, "Plugin " + stdlib_1.getConstructorName(plugin) + " is not valid. Make sure the 'apply' method exist.") || this; | ||
return _super.call(this, "Plugin " + stdlib_1.getConstructorName(plugin) + " is not valid. Make sure the 'apply' method exists.") || this; | ||
} | ||
@@ -31,2 +31,10 @@ return InvalidPluginError; | ||
exports.InvalidPluginError = InvalidPluginError; | ||
var FactoryModuleNotExistsError = /** @class */ (function (_super) { | ||
tslib_1.__extends(FactoryModuleNotExistsError, _super); | ||
function FactoryModuleNotExistsError(factory) { | ||
return _super.call(this, (typeof factory === "string" ? factory : factory.name) + " is not a factory module.") || this; | ||
} | ||
return FactoryModuleNotExistsError; | ||
}(Error)); | ||
exports.FactoryModuleNotExistsError = FactoryModuleNotExistsError; | ||
//# sourceMappingURL=errors.js.map |
export { define } from "./decorators/define"; | ||
export { inject } from "./decorators/inject"; | ||
export { injectFactory } from "./decorators/injectFactory"; | ||
export { injectAlias } from "./decorators/injectAlias"; | ||
@@ -4,0 +5,0 @@ export { singleton } from "./decorators/singleton"; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Injex = exports.errors = exports.Logger = exports.LogLevel = exports.lazy = exports.alias = exports.bootstrap = exports.init = exports.singleton = exports.injectAlias = exports.inject = exports.define = void 0; | ||
exports.Injex = exports.errors = exports.Logger = exports.LogLevel = exports.lazy = exports.alias = exports.bootstrap = exports.init = exports.singleton = exports.injectAlias = exports.injectFactory = exports.inject = exports.define = void 0; | ||
var tslib_1 = require("tslib"); | ||
@@ -9,2 +9,4 @@ var define_1 = require("./decorators/define"); | ||
Object.defineProperty(exports, "inject", { enumerable: true, get: function () { return inject_1.inject; } }); | ||
var injectFactory_1 = require("./decorators/injectFactory"); | ||
Object.defineProperty(exports, "injectFactory", { enumerable: true, get: function () { return injectFactory_1.injectFactory; } }); | ||
var injectAlias_1 = require("./decorators/injectAlias"); | ||
@@ -11,0 +13,0 @@ Object.defineProperty(exports, "injectAlias", { enumerable: true, get: function () { return injectAlias_1.injectAlias; } }); |
@@ -269,3 +269,3 @@ "use strict"; | ||
} | ||
else if (moduleNameOrType instanceof Function) { | ||
else if (moduleNameOrType instanceof Function && metadataHandlers_1.default.hasMetadata(moduleNameOrType.prototype)) { | ||
var metadata = metadataHandlers_1.default.getMetadata(moduleNameOrType.prototype); | ||
@@ -281,12 +281,7 @@ return this._modules.get(metadata.name); | ||
var aliasDependencies = meta.aliasDependencies || []; | ||
var self = _this; | ||
var factoryDependencies = meta.factoryDependencies || []; | ||
var _loop_1 = function (label, value) { | ||
Object.defineProperty(module, label, { | ||
configurable: true, | ||
set: function (val) { | ||
Object.defineProperty(module, label, { get: function () { return val; } }); | ||
}, | ||
get: function () { | ||
return self.get(value) || null; | ||
} | ||
get: function () { return _this.get(value) || null; } | ||
}); | ||
@@ -301,8 +296,3 @@ }; | ||
configurable: true, | ||
set: function (val) { | ||
Object.defineProperty(module, label, { get: function () { return val; } }); | ||
}, | ||
get: function () { | ||
return self.getAlias(alias, keyBy); | ||
} | ||
get: function () { return _this.getAlias(alias, keyBy); } | ||
}); | ||
@@ -314,2 +304,17 @@ }; | ||
} | ||
var _loop_3 = function (label, value) { | ||
var factory = _this.get(value); | ||
if (!factory) { | ||
throw new errors_1.FactoryModuleNotExistsError(value); | ||
} | ||
var item = factory(); | ||
Object.defineProperty(module, label, { | ||
configurable: true, | ||
get: function () { return stdlib_1.isPromise(item) ? item.then(function (instance) { return instance; }) : item; } | ||
}); | ||
}; | ||
for (var _d = 0, factoryDependencies_1 = factoryDependencies; _d < factoryDependencies_1.length; _d++) { | ||
var _e = factoryDependencies_1[_d], label = _e.label, value = _e.value; | ||
_loop_3(label, value); | ||
} | ||
}); | ||
@@ -316,0 +321,0 @@ }; |
@@ -23,2 +23,3 @@ import { Hook, IConstructor, LogLevel } from "@injex/stdlib"; | ||
aliasDependencies?: IAliasDependency[]; | ||
factoryDependencies?: IDependency[]; | ||
aliases?: string[]; | ||
@@ -25,0 +26,0 @@ initMethod?: string; |
{ | ||
"name": "@injex/core", | ||
"version": "3.0.0-alpha.2", | ||
"version": "3.0.0-alpha.3", | ||
"description": "Simple, Decorated, Pluggable dependency-injection framework for TypeScript apps", | ||
@@ -46,3 +46,3 @@ "keywords": [ | ||
"dependencies": { | ||
"@injex/stdlib": "^3.0.0-alpha.2", | ||
"@injex/stdlib": "^3.0.0-alpha.3", | ||
"tslib": "^2.1.0" | ||
@@ -56,3 +56,3 @@ }, | ||
}, | ||
"gitHead": "cd07a11f02aa1fdbe3f457079975da0416d17e07" | ||
"gitHead": "86a0a794d83de779592ba2dc9534e214b72428c9" | ||
} |
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
54093
48
773
Updated@injex/stdlib@^3.0.0-alpha.3