@furystack/inject
Advanced tools
Comparing version 4.0.18 to 4.0.19
@@ -22,3 +22,3 @@ "use strict"; | ||
dependencies: (meta && | ||
meta.map(param => { | ||
meta.map((param) => { | ||
return param; | ||
@@ -25,0 +25,0 @@ })) || |
@@ -18,5 +18,5 @@ "use strict"; | ||
/** */ | ||
const singletons = Array.from(this.cachedSingletons.entries()).map(e => e[1]); | ||
const singletons = Array.from(this.cachedSingletons.entries()).map((e) => e[1]); | ||
const disposeRequests = singletons | ||
.filter(s => s !== this) | ||
.filter((s) => s !== this) | ||
.map(async (s) => { | ||
@@ -43,3 +43,3 @@ if (s.dispose) { | ||
throw Error(`No metadata found for '${ctor.name}'. Dependencies: ${dependencies | ||
.map(d => d.name) | ||
.map((d) => d.name) | ||
.join(',')}. Be sure that it's decorated with '@Injectable()' or added explicitly with SetInstance()`); | ||
@@ -52,5 +52,5 @@ } | ||
const invalidDeps = meta.dependencies | ||
.map(dep => ({ meta: Injector.meta.get(dep), dep })) | ||
.filter(m => m.meta && (m.meta.options.lifetime === 'scoped' || m.meta.options.lifetime === 'transient')) | ||
.map(i => i.meta && `${i.dep.name}:${i.meta.options.lifetime}`); | ||
.map((dep) => ({ meta: Injector.meta.get(dep), dep })) | ||
.filter((m) => m.meta && (m.meta.options.lifetime === 'scoped' || m.meta.options.lifetime === 'transient')) | ||
.map((i) => i.meta && `${i.dep.name}:${i.meta.options.lifetime}`); | ||
if (invalidDeps.length) { | ||
@@ -62,5 +62,5 @@ throw Error(`Injector error: Singleton type '${ctor.name}' depends on non-singleton injectables: ${invalidDeps.join(',')}`); | ||
const invalidDeps = meta.dependencies | ||
.map(dep => ({ meta: Injector.meta.get(dep), dep })) | ||
.filter(m => m.meta && m.meta.options.lifetime === 'transient') | ||
.map(i => i.meta && `${i.dep.name}:${i.meta.options.lifetime}`); | ||
.map((dep) => ({ meta: Injector.meta.get(dep), dep })) | ||
.filter((m) => m.meta && m.meta.options.lifetime === 'transient') | ||
.map((i) => i.meta && `${i.dep.name}:${i.meta.options.lifetime}`); | ||
if (invalidDeps.length) { | ||
@@ -77,3 +77,3 @@ throw Error(`Injector error: Scoped type '${ctor.name}' depends on transient injectables: ${invalidDeps.join(',')}`); | ||
} | ||
const deps = meta.dependencies.map(dep => this.getInstance(dep, [...dependencies, ctor])); | ||
const deps = meta.dependencies.map((dep) => this.getInstance(dep, [...dependencies, ctor])); | ||
const newInstance = new ctor(...deps); | ||
@@ -97,3 +97,3 @@ if (meta.options.lifetime !== 'transient') { | ||
dependencies: (meta && | ||
meta.map(param => { | ||
meta.map((param) => { | ||
return param; | ||
@@ -100,0 +100,0 @@ })) || |
@@ -43,3 +43,3 @@ "use strict"; | ||
it('Should throw an error when setting an Injector instance', () => { | ||
utils_1.using(new injector_1.Injector(), i => { | ||
utils_1.using(new injector_1.Injector(), (i) => { | ||
expect(() => i.setExplicitInstance(new injector_1.Injector())).toThrowError('Cannot set an injector instance as injectable'); | ||
@@ -136,3 +136,3 @@ }); | ||
}); | ||
it('Should dispose cached entries on dispose and tolerate non-disposable ones', done => { | ||
it('Should dispose cached entries on dispose and tolerate non-disposable ones', (done) => { | ||
class TestDisposable { | ||
@@ -151,3 +151,3 @@ dispose() { | ||
it('Remove should remove an entity from the cached singletons list', () => { | ||
utils_1.using(new injector_1.Injector(), i => { | ||
utils_1.using(new injector_1.Injector(), (i) => { | ||
i.setExplicitInstance({}, Object); | ||
@@ -160,3 +160,3 @@ i.remove(Object); | ||
it('Requesting an Injector instance should return self', () => { | ||
utils_1.using(new injector_1.Injector(), i => { | ||
utils_1.using(new injector_1.Injector(), (i) => { | ||
expect(i.getInstance(injector_1.Injector)).toBe(i); | ||
@@ -168,3 +168,3 @@ }); | ||
} | ||
utils_1.using(new injector_1.Injector(), i => { | ||
utils_1.using(new injector_1.Injector(), (i) => { | ||
expect(() => i.getInstance(UndecoratedTestClass, [injector_1.Injector])).toThrowError(`No metadata found for 'UndecoratedTestClass'. Dependencies: Injector. Be sure that it's decorated with '@Injectable()' or added explicitly with SetInstance()`); | ||
@@ -188,3 +188,3 @@ }); | ||
], St1); | ||
utils_1.using(new injector_1.Injector(), i => { | ||
utils_1.using(new injector_1.Injector(), (i) => { | ||
expect(() => i.getInstance(St1)).toThrowError(`Injector error: Singleton type 'St1' depends on non-singleton injectables: Trs1:transient`); | ||
@@ -208,3 +208,3 @@ }); | ||
], St2); | ||
utils_1.using(new injector_1.Injector(), i => { | ||
utils_1.using(new injector_1.Injector(), (i) => { | ||
expect(() => i.getInstance(St2)).toThrowError(`Injector error: Singleton type 'St2' depends on non-singleton injectables: Sc1:scoped`); | ||
@@ -228,3 +228,3 @@ }); | ||
], Sc2); | ||
utils_1.using(new injector_1.Injector(), i => { | ||
utils_1.using(new injector_1.Injector(), (i) => { | ||
expect(() => i.getInstance(Sc2)).toThrowError(`Injector error: Scoped type 'Sc2' depends on transient injectables: Tr2:transient`); | ||
@@ -231,0 +231,0 @@ }); |
{ | ||
"name": "@furystack/inject", | ||
"version": "4.0.18", | ||
"version": "4.0.19", | ||
"description": "Core FuryStack package", | ||
@@ -29,3 +29,3 @@ "main": "dist/index.js", | ||
"dependencies": { | ||
"@furystack/utils": "^1.1.11", | ||
"@furystack/utils": "^1.1.12", | ||
"reflect-metadata": "^0.1.13", | ||
@@ -38,3 +38,3 @@ "tslib": "^1.11.1" | ||
"typings": "./dist/index.d.ts", | ||
"gitHead": "da155803c6c0122eb2285825d39d621fda637b28" | ||
"gitHead": "f83552be5dc0d48b087781b583111a4c88188082" | ||
} |
@@ -31,3 +31,3 @@ import 'reflect-metadata' | ||
(meta && | ||
(meta as any[]).map(param => { | ||
(meta as any[]).map((param) => { | ||
return param | ||
@@ -34,0 +34,0 @@ })) || |
@@ -39,3 +39,3 @@ import { Disposable, using, usingAsync } from '@furystack/utils' | ||
it('Should throw an error when setting an Injector instance', () => { | ||
using(new Injector(), i => { | ||
using(new Injector(), (i) => { | ||
expect(() => i.setExplicitInstance(new Injector())).toThrowError('Cannot set an injector instance as injectable') | ||
@@ -114,3 +114,3 @@ }) | ||
it('Should dispose cached entries on dispose and tolerate non-disposable ones', done => { | ||
it('Should dispose cached entries on dispose and tolerate non-disposable ones', (done) => { | ||
class TestDisposable implements Disposable { | ||
@@ -123,3 +123,3 @@ public dispose() { | ||
usingAsync(new Injector(), async i => { | ||
usingAsync(new Injector(), async (i) => { | ||
i.setExplicitInstance(new TestDisposable()) | ||
@@ -131,3 +131,3 @@ i.setExplicitInstance(new TestInstance()) | ||
it('Remove should remove an entity from the cached singletons list', () => { | ||
using(new Injector(), i => { | ||
using(new Injector(), (i) => { | ||
i.setExplicitInstance({}, Object) | ||
@@ -141,3 +141,3 @@ i.remove(Object) | ||
it('Requesting an Injector instance should return self', () => { | ||
using(new Injector(), i => { | ||
using(new Injector(), (i) => { | ||
expect(i.getInstance(Injector)).toBe(i) | ||
@@ -149,3 +149,3 @@ }) | ||
class UndecoratedTestClass {} | ||
using(new Injector(), i => { | ||
using(new Injector(), (i) => { | ||
expect(() => i.getInstance(UndecoratedTestClass, [Injector])).toThrowError( | ||
@@ -166,3 +166,3 @@ `No metadata found for 'UndecoratedTestClass'. Dependencies: Injector. Be sure that it's decorated with '@Injectable()' or added explicitly with SetInstance()`, | ||
using(new Injector(), i => { | ||
using(new Injector(), (i) => { | ||
expect(() => i.getInstance(St1)).toThrowError( | ||
@@ -183,3 +183,3 @@ `Injector error: Singleton type 'St1' depends on non-singleton injectables: Trs1:transient`, | ||
using(new Injector(), i => { | ||
using(new Injector(), (i) => { | ||
expect(() => i.getInstance(St2)).toThrowError( | ||
@@ -200,3 +200,3 @@ `Injector error: Singleton type 'St2' depends on non-singleton injectables: Sc1:scoped`, | ||
using(new Injector(), i => { | ||
using(new Injector(), (i) => { | ||
expect(() => i.getInstance(Sc2)).toThrowError( | ||
@@ -203,0 +203,0 @@ `Injector error: Scoped type 'Sc2' depends on transient injectables: Tr2:transient`, |
@@ -11,6 +11,6 @@ import { Disposable } from '@furystack/utils' | ||
/** */ | ||
const singletons = Array.from(this.cachedSingletons.entries()).map(e => e[1]) | ||
const singletons = Array.from(this.cachedSingletons.entries()).map((e) => e[1]) | ||
const disposeRequests = singletons | ||
.filter(s => s !== this) | ||
.map(async s => { | ||
.filter((s) => s !== this) | ||
.map(async (s) => { | ||
if (s.dispose) { | ||
@@ -58,3 +58,3 @@ return s.dispose() || Promise.resolve() | ||
`No metadata found for '${ctor.name}'. Dependencies: ${dependencies | ||
.map(d => d.name) | ||
.map((d) => d.name) | ||
.join(',')}. Be sure that it's decorated with '@Injectable()' or added explicitly with SetInstance()`, | ||
@@ -69,5 +69,5 @@ ) | ||
const invalidDeps = meta.dependencies | ||
.map(dep => ({ meta: Injector.meta.get(dep), dep })) | ||
.filter(m => m.meta && (m.meta.options.lifetime === 'scoped' || m.meta.options.lifetime === 'transient')) | ||
.map(i => i.meta && `${i.dep.name}:${i.meta.options.lifetime}`) | ||
.map((dep) => ({ meta: Injector.meta.get(dep), dep })) | ||
.filter((m) => m.meta && (m.meta.options.lifetime === 'scoped' || m.meta.options.lifetime === 'transient')) | ||
.map((i) => i.meta && `${i.dep.name}:${i.meta.options.lifetime}`) | ||
if (invalidDeps.length) { | ||
@@ -82,5 +82,5 @@ throw Error( | ||
const invalidDeps = meta.dependencies | ||
.map(dep => ({ meta: Injector.meta.get(dep), dep })) | ||
.filter(m => m.meta && m.meta.options.lifetime === 'transient') | ||
.map(i => i.meta && `${i.dep.name}:${i.meta.options.lifetime}`) | ||
.map((dep) => ({ meta: Injector.meta.get(dep), dep })) | ||
.filter((m) => m.meta && m.meta.options.lifetime === 'transient') | ||
.map((i) => i.meta && `${i.dep.name}:${i.meta.options.lifetime}`) | ||
if (invalidDeps.length) { | ||
@@ -101,3 +101,3 @@ throw Error( | ||
} | ||
const deps = meta.dependencies.map(dep => this.getInstance(dep, [...dependencies, ctor])) | ||
const deps = meta.dependencies.map((dep) => this.getInstance(dep, [...dependencies, ctor])) | ||
const newInstance = new ctor(...deps) | ||
@@ -123,3 +123,3 @@ if (meta.options.lifetime !== 'transient') { | ||
(meta && | ||
(meta as any[]).map(param => { | ||
(meta as any[]).map((param) => { | ||
return param | ||
@@ -126,0 +126,0 @@ })) || |
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
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
69473
Updated@furystack/utils@^1.1.12