@methodus/framework-injection
Advanced tools
| import 'reflect-metadata'; | ||
| export interface DIapi { | ||
| resolve<T = any>(token: string | any): T; | ||
| register<T = any>(token: string | any, target: unknown): void; | ||
| registerInstance(token: string, target: unknown): void; | ||
| } | ||
| export declare const Injector: DIapi; |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.Injector = void 0; | ||
| require("reflect-metadata"); | ||
| var tsyringe_1 = require("tsyringe"); | ||
| var bridge = { Injector: tsyringe_1.container }; | ||
| if (global) { | ||
| if (!global.METHODUS_DI) { | ||
| global.METHODUS_DI = bridge; | ||
| } | ||
| bridge = global.METHODUS_DI; | ||
| } | ||
| if (!bridge.Injector) { | ||
| bridge.Injector = tsyringe_1.container; | ||
| } | ||
| exports.Injector = bridge.Injector; |
@@ -10,3 +10,3 @@ "use strict"; | ||
| var __exportStar = (this && this.__exportStar) || function(m, exports) { | ||
| for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p); | ||
| for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); | ||
| }; | ||
@@ -13,0 +13,0 @@ Object.defineProperty(exports, "__esModule", { value: true }); |
@@ -10,3 +10,3 @@ "use strict"; | ||
| var __exportStar = (this && this.__exportStar) || function(m, exports) { | ||
| for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p); | ||
| for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); | ||
| }; | ||
@@ -13,0 +13,0 @@ Object.defineProperty(exports, "__esModule", { value: true }); |
@@ -10,3 +10,3 @@ "use strict"; | ||
| var __exportStar = (this && this.__exportStar) || function(m, exports) { | ||
| for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p); | ||
| for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); | ||
| }; | ||
@@ -13,0 +13,0 @@ Object.defineProperty(exports, "__esModule", { value: true }); |
@@ -0,1 +1,2 @@ | ||
| import 'reflect-metadata'; | ||
| export declare function Inject(name?: string, propertyName?: string): any; |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.Inject = void 0; | ||
| var injector_1 = require("../injector"); | ||
| require("reflect-metadata"); | ||
| var container_1 = require("../container"); | ||
| function Inject(name, propertyName) { | ||
@@ -12,3 +13,3 @@ return function (target, propertyKey, parameterIndex) { | ||
| if (propertyName) { | ||
| target.prototype[propertyName] = injector_1.Injector.get(constructorArgs[parameterIndex]); | ||
| target.prototype[propertyName] = container_1.Injector.resolve(constructorArgs[parameterIndex]); | ||
| } | ||
@@ -15,0 +16,0 @@ else { |
@@ -5,6 +5,6 @@ "use strict"; | ||
| require("reflect-metadata"); | ||
| var injector_1 = require("../injector"); | ||
| var container_1 = require("../container"); | ||
| function Injectable(name) { | ||
| function DecoratorFactory(cls) { | ||
| injector_1.Injector.inject(injector_1.RegistrationTypes.Service, cls, name); | ||
| container_1.Injector.register(name || cls, { useClass: cls }); | ||
| return cls; | ||
@@ -11,0 +11,0 @@ } |
@@ -5,3 +5,3 @@ "use strict"; | ||
| require("reflect-metadata"); | ||
| var injector_1 = require("../injector"); | ||
| var container_1 = require("../container"); | ||
| var ANNOTATIONS = '__annotations__'; | ||
@@ -14,3 +14,3 @@ function Singleton(name) { | ||
| annotations.push('singleton'); | ||
| injector_1.Injector.inject(injector_1.RegistrationTypes.Service, cls, name); | ||
| container_1.Injector.register(name || cls, { useValue: new cls() }); | ||
| return cls; | ||
@@ -17,0 +17,0 @@ } |
+8
-6
@@ -39,4 +39,6 @@ "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| var injector_1 = require("./injector"); | ||
| var container_1 = require("./container"); | ||
| var di_test_1 = require("./di.test"); | ||
| var mo = new di_test_1.Main(new di_test_1.ClassA(), new di_test_1.ClassB()); | ||
| console.log(mo); | ||
| describe('Injection decorators', function () { | ||
@@ -46,5 +48,5 @@ it('Create server', function () { return __awaiter(void 0, void 0, void 0, function () { | ||
| return __generator(this, function (_a) { | ||
| mainModule = injector_1.Injector.get(di_test_1.Main); | ||
| aModule = injector_1.Injector.get(di_test_1.ClassA); | ||
| bModule = injector_1.Injector.get(di_test_1.ClassB); | ||
| mainModule = container_1.Injector.resolve('Main'); | ||
| aModule = container_1.Injector.resolve('ClassA'); | ||
| bModule = container_1.Injector.resolve('ClassB'); | ||
| expect(mainModule).toBeDefined(); | ||
@@ -59,5 +61,5 @@ expect(aModule).toBeDefined(); | ||
| return __generator(this, function (_a) { | ||
| mainModule = injector_1.Injector.get(di_test_1.Main); | ||
| mainModule = container_1.Injector.resolve('Main'); | ||
| result = mainModule.add(2, 3); | ||
| expect(module).toBeDefined(); | ||
| expect(mainModule).toBeDefined(); | ||
| expect(result).toBe(11); | ||
@@ -64,0 +66,0 @@ return [2]; |
@@ -9,5 +9,5 @@ export declare class ClassA { | ||
| serviceA?: ClassA; | ||
| serviceB: ClassB; | ||
| serviceB?: ClassB; | ||
| constructor(serviceA: ClassA, serviceB: ClassB); | ||
| add(a: number, b: number): number; | ||
| } |
+7
-9
@@ -16,3 +16,3 @@ "use strict"; | ||
| exports.Main = exports.ClassB = exports.ClassA = void 0; | ||
| var decorators_1 = require("./decorators"); | ||
| var index_1 = require("./index"); | ||
| var ClassA = (function () { | ||
@@ -25,3 +25,3 @@ function ClassA() { | ||
| ClassA = __decorate([ | ||
| decorators_1.Injectable('ClassA') | ||
| index_1.default.Injectable('ClassA') | ||
| ], ClassA); | ||
@@ -38,3 +38,3 @@ return ClassA; | ||
| ClassB = __decorate([ | ||
| decorators_1.Injectable('ClassB') | ||
| index_1.default.Injectable('ClassB') | ||
| ], ClassB); | ||
@@ -46,12 +46,10 @@ return ClassB; | ||
| function Main(serviceA, serviceB) { | ||
| this.serviceB = serviceB; | ||
| } | ||
| Main.prototype.add = function (a, b) { | ||
| var _a; | ||
| return this.serviceA.getSum(a, b) + ((_a = this.serviceB) === null || _a === void 0 ? void 0 : _a.getSum(a, b)); | ||
| return this.serviceA.getSum(a, b) + this.serviceB.getSum(a, b); | ||
| }; | ||
| Main = __decorate([ | ||
| decorators_1.Singleton('Main'), | ||
| __param(0, decorators_1.Inject('ClassA', 'serviceA')), | ||
| __param(1, decorators_1.Inject('ClassB')), | ||
| index_1.default.Singleton('Main'), | ||
| __param(0, index_1.default.Inject('ClassA')), | ||
| __param(1, index_1.default.Inject('ClassB')), | ||
| __metadata("design:paramtypes", [ClassA, | ||
@@ -58,0 +56,0 @@ ClassB]) |
+4
-5
@@ -1,8 +0,7 @@ | ||
| import { InjectorType as _InjectorType, RegistrationTypes as _RegistrationTypes } from './injector'; | ||
| import { Inject as _Inject, Injectable as _Injectable, Singleton as _Singleton } from './decorators'; | ||
| import 'reflect-metadata'; | ||
| import { ClientContainer as _ClientContainer, ServerContainer as _ServerContainer } from './containers'; | ||
| import { Injectable as _Injectable, Singleton as _Singleton, Inject as _Inject } from './decorators'; | ||
| import { DIapi } from './container'; | ||
| declare namespace injection { | ||
| const Injector: _InjectorType; | ||
| const InjectorType: typeof _InjectorType; | ||
| const RegistrationTypes: typeof _RegistrationTypes; | ||
| const Injector: DIapi; | ||
| const Inject: typeof _Inject; | ||
@@ -9,0 +8,0 @@ const Injectable: typeof _Injectable; |
+4
-5
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| var injector_1 = require("./injector"); | ||
| require("reflect-metadata"); | ||
| var containers_1 = require("./containers"); | ||
| var decorators_1 = require("./decorators"); | ||
| var containers_1 = require("./containers"); | ||
| var container_1 = require("./container"); | ||
| var injection; | ||
| (function (injection) { | ||
| injection.Injector = injector_1.Injector; | ||
| injection.InjectorType = injector_1.InjectorType; | ||
| injection.RegistrationTypes = injector_1.RegistrationTypes; | ||
| injection.Injector = container_1.Injector; | ||
| injection.Inject = decorators_1.Inject; | ||
@@ -12,0 +11,0 @@ injection.Injectable = decorators_1.Injectable; |
@@ -18,5 +18,6 @@ "use strict"; | ||
| }; | ||
| var __spread = (this && this.__spread) || function () { | ||
| for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i])); | ||
| return ar; | ||
| var __spreadArray = (this && this.__spreadArray) || function (to, from) { | ||
| for (var i = 0, il = from.length, j = to.length; i < il; i++, j++) | ||
| to[j] = from[i]; | ||
| return to; | ||
| }; | ||
@@ -96,7 +97,7 @@ Object.defineProperty(exports, "__esModule", { value: true }); | ||
| if (annotations && annotations.indexOf('singleton') === -1) { | ||
| return new ((_a = record.token).bind.apply(_a, __spread([void 0], record.deps)))(); | ||
| return new ((_a = record.token).bind.apply(_a, __spreadArray([void 0], __read(record.deps))))(); | ||
| } | ||
| else { | ||
| if (!this.singletons[record.token]) { | ||
| this.singletons[record.token] = new ((_b = record.token).bind.apply(_b, __spread([void 0], record.deps)))(); | ||
| this.singletons[record.token] = new ((_b = record.token).bind.apply(_b, __spreadArray([void 0], __read(record.deps))))(); | ||
| } | ||
@@ -103,0 +104,0 @@ return this.singletons[record.token]; |
+27
-8
| { | ||
| "name": "@methodus/framework-injection", | ||
| "version": "7.0.11", | ||
| "version": "8.0.2", | ||
| "description": "Dependency injection for methodus", | ||
@@ -27,8 +27,13 @@ "main": "dist/index.js", | ||
| "license": "BSD-3-Clause", | ||
| "docs": { | ||
| "content": [ | ||
| "readme.md" | ||
| ] | ||
| }, | ||
| "scripts": { | ||
| "test": "jest --silent && yarn coverage", | ||
| "coverage": "cp ./coverage/coverage-final.json ../../../coverage/coverage-injection.json", | ||
| "build": "rimraf ./dist && tsc", | ||
| "docs": "../../../node_modules/.bin/rimraf ../../../docs/modules/framework/injection && ../../../node_modules/.bin/typedoc && node ../../../docs/docs.js modules/framework/injection", | ||
| "format": "prettier -c --write ./src" | ||
| "test": "yarn jest --coverage && yarn run coverage", | ||
| "coverage": "yarn cpr ./coverage/coverage-final.json ../../../coverage/coverage-injection.json -o", | ||
| "build": "yarn rimraf ./dist && yarn tsc", | ||
| "docs": "yarn rimraf ../../../docs/modules/framework/injection && yarn typedoc && node ../../../docs/docs.js modules/framework/injection", | ||
| "format": "yarn prettier -c --write ./src" | ||
| }, | ||
@@ -39,5 +44,19 @@ "publishConfig": { | ||
| "dependencies": { | ||
| "@methodus/framework-commons": "^7.0.10" | ||
| "@methodus/framework-commons": "^8.0.2", | ||
| "reflect-metadata": "^0.1.13", | ||
| "tsyringe": "^4.3.0" | ||
| }, | ||
| "gitHead": "e3d15e3950a8347222e5994be1e2b97a5bdd0f74" | ||
| "devDependencies": { | ||
| "@types/jest": "^26.0.15", | ||
| "@types/node": "^10.0.0", | ||
| "cpr": "^3.0.1", | ||
| "docsify": "^4.10.2", | ||
| "jest": "^26.6.3", | ||
| "rimraf": "^3.0.1", | ||
| "ts-jest": "^26.4.4", | ||
| "typedoc": "^0.17.8", | ||
| "typedoc-plugin-markdown": "^2.3.1", | ||
| "typescript": "^4.1.2" | ||
| }, | ||
| "gitHead": "04fe808ebdbada8ac78c8589ec98e480ed29c938" | ||
| } |
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
26982
4.27%36
5.88%572
4.38%3
200%10
Infinity%+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
- Removed