Revert "fix(core): 🚑 Fix for calculating durability of a provider"

This commit is contained in:
Kamil Mysliwiec
2023-02-06 13:16:13 +01:00
committed by GitHub
parent 0a3a87673a
commit b82d055a52
2 changed files with 19 additions and 332 deletions

View File

@@ -203,18 +203,15 @@ export class InstanceWrapper<T = any> {
if (!isUndefined(this.isTreeDurable)) {
return this.isTreeDurable;
}
if (this.scope === Scope.REQUEST) {
this.isTreeDurable = this.durable === undefined ? false : this.durable;
if (this.isTreeDurable) {
this.printIntrospectedAsDurable();
}
if (this.durable === true) {
this.isTreeDurable = true;
this.printIntrospectedAsDurable();
return this.isTreeDurable;
}
const isStatic = this.isDependencyTreeStatic();
if (isStatic) {
return false;
}
const isTreeNonDurable = this.introspectDepsAttribute(
(collection, registry) =>
collection.some(
@@ -224,7 +221,7 @@ export class InstanceWrapper<T = any> {
),
lookupRegistry,
);
this.isTreeDurable = !isTreeNonDurable;
this.isTreeDurable = !isTreeNonDurable && this.durable !== false;
if (this.isTreeDurable) {
this.printIntrospectedAsDurable();
}
@@ -246,23 +243,25 @@ export class InstanceWrapper<T = any> {
const { dependencies, properties, enhancers } =
this[INSTANCE_METADATA_SYMBOL];
let introspectionResult = dependencies
? callback(dependencies, lookupRegistry)
: false;
let introspectionResult =
(dependencies && callback(dependencies, lookupRegistry)) || !dependencies;
if (introspectionResult || !(properties || enhancers)) {
if (!introspectionResult || !(properties || enhancers)) {
return introspectionResult;
}
introspectionResult = properties
? callback(
const propertiesHosts = (properties || []).map(item => item.wrapper);
introspectionResult =
introspectionResult &&
((properties &&
callback(
properties.map(item => item.wrapper),
lookupRegistry,
)
: false;
if (introspectionResult || !enhancers) {
)) ||
!properties);
if (!introspectionResult || !enhancers) {
return introspectionResult;
}
return enhancers ? callback(enhancers, lookupRegistry) : false;
return callback(enhancers, lookupRegistry);
}
public isDependencyTreeStatic(lookupRegistry: string[] = []): boolean {
@@ -274,10 +273,10 @@ export class InstanceWrapper<T = any> {
this.printIntrospectedAsRequestScoped();
return this.isTreeStatic;
}
this.isTreeStatic = !this.introspectDepsAttribute(
this.isTreeStatic = this.introspectDepsAttribute(
(collection, registry) =>
collection.some(
(item: InstanceWrapper) => !item.isDependencyTreeStatic(registry),
collection.every((item: InstanceWrapper) =>
item.isDependencyTreeStatic(registry),
),
lookupRegistry,
);

View File

@@ -39,68 +39,7 @@ describe('InstanceWrapper', () => {
expect(wrapper.isDependencyTreeStatic()).to.be.false;
});
});
describe('when request scoped durable', () => {
it('should return false', () => {
const wrapper = new InstanceWrapper({
scope: Scope.REQUEST,
durable: true,
});
expect(wrapper.isDependencyTreeStatic()).to.be.false;
});
});
describe('when request scoped explicit non durable', () => {
it('should return false', () => {
const wrapper = new InstanceWrapper({
scope: Scope.REQUEST,
durable: false,
});
expect(wrapper.isDependencyTreeStatic()).to.be.false;
});
});
describe('when default', () => {
it('should return true', () => {
const wrapper = new InstanceWrapper({});
expect(wrapper.isDependencyTreeStatic()).to.be.true;
});
});
describe('when statically scoped', () => {
describe('dependencies, properties, enhancers', () => {
describe('dependecies non static, properties static, enhancers static', () => {
it('should return false', () => {
const wrapper = new InstanceWrapper();
wrapper.addCtorMetadata(
0,
new InstanceWrapper({ scope: Scope.REQUEST }),
);
wrapper.addPropertiesMetadata('key1', new InstanceWrapper());
wrapper.addEnhancerMetadata(new InstanceWrapper());
expect(wrapper.isDependencyTreeStatic()).to.be.false;
});
});
describe('dependecies static, properties non static, enhancers static', () => {
it('should return false', () => {
const wrapper = new InstanceWrapper();
wrapper.addCtorMetadata(0, new InstanceWrapper());
wrapper.addPropertiesMetadata(
'key1',
new InstanceWrapper({ scope: Scope.REQUEST }),
);
wrapper.addEnhancerMetadata(new InstanceWrapper());
expect(wrapper.isDependencyTreeStatic()).to.be.false;
});
});
describe('dependecies static, properties static, enhancers non static', () => {
it('should return false', () => {
const wrapper = new InstanceWrapper();
wrapper.addCtorMetadata(0, new InstanceWrapper());
wrapper.addPropertiesMetadata('key1', new InstanceWrapper());
wrapper.addEnhancerMetadata(
new InstanceWrapper({ scope: Scope.REQUEST }),
);
expect(wrapper.isDependencyTreeStatic()).to.be.false;
});
});
});
describe('dependencies', () => {
describe('when each is static', () => {
it('should return true', () => {
@@ -177,157 +116,8 @@ describe('InstanceWrapper', () => {
expect(wrapper.isDependencyTreeDurable()).to.be.true;
});
});
describe('when request scoped and non durable', () => {
it('should return false', () => {
const wrapper = new InstanceWrapper({
scope: Scope.REQUEST,
});
expect(wrapper.isDependencyTreeDurable()).to.be.false;
});
});
describe('when request scoped and explicit non durable', () => {
it('should return false', () => {
const wrapper = new InstanceWrapper({
scope: Scope.REQUEST,
durable: false,
});
expect(wrapper.isDependencyTreeDurable()).to.be.false;
});
});
describe('when default scope', () => {
it('should return false', () => {
const wrapper = new InstanceWrapper();
expect(wrapper.isDependencyTreeDurable()).to.be.false;
});
});
describe('when statically scoped', () => {
describe('dependencies, properties, enhancers', () => {
describe('dependecies non durable, properties non durable, enhancers durable', () => {
it('should return false', () => {
const wrapper = new InstanceWrapper();
wrapper.addCtorMetadata(
0,
new InstanceWrapper({ scope: Scope.REQUEST }),
);
wrapper.addCtorMetadata(1, new InstanceWrapper());
wrapper.addPropertiesMetadata('key1', new InstanceWrapper());
wrapper.addEnhancerMetadata(new InstanceWrapper());
expect(wrapper.isDependencyTreeDurable()).to.be.false;
});
});
describe('dependecies non durable, properties durable, enhancers durable', () => {
it('should return false', () => {
const wrapper = new InstanceWrapper();
wrapper.addCtorMetadata(
0,
new InstanceWrapper({ scope: Scope.REQUEST }),
);
wrapper.addCtorMetadata(1, new InstanceWrapper());
wrapper.addPropertiesMetadata(
'key1',
new InstanceWrapper({ scope: Scope.REQUEST }),
);
wrapper.addEnhancerMetadata(new InstanceWrapper());
expect(wrapper.isDependencyTreeDurable()).to.be.false;
});
});
describe('dependecies non durable, properties durable', () => {
it('should return false', () => {
const wrapper = new InstanceWrapper();
wrapper.addCtorMetadata(
0,
new InstanceWrapper({ scope: Scope.REQUEST }),
);
wrapper.addCtorMetadata(1, new InstanceWrapper());
wrapper.addPropertiesMetadata('key1', new InstanceWrapper());
wrapper.addPropertiesMetadata(
'key2',
new InstanceWrapper({ scope: Scope.REQUEST, durable: true }),
);
expect(wrapper.isDependencyTreeDurable()).to.be.false;
});
});
describe('properties durable, enhancers non durable', () => {
it('should return false', () => {
const wrapper = new InstanceWrapper();
wrapper.addPropertiesMetadata('key1', new InstanceWrapper());
wrapper.addPropertiesMetadata(
'key2',
new InstanceWrapper({ scope: Scope.REQUEST, durable: true }),
);
wrapper.addEnhancerMetadata(
new InstanceWrapper({ scope: Scope.REQUEST }),
);
expect(wrapper.isDependencyTreeDurable()).to.be.false;
});
});
describe('dependencies durable, enhancers non durable', () => {
it('should return false', () => {
const wrapper = new InstanceWrapper();
wrapper.addCtorMetadata(
0,
new InstanceWrapper({ scope: Scope.REQUEST, durable: true }),
);
wrapper.addEnhancerMetadata(
new InstanceWrapper({ scope: Scope.REQUEST }),
);
expect(wrapper.isDependencyTreeDurable()).to.be.false;
});
});
});
describe('dependencies', () => {
describe('when wrapper is non durable and dependecy is static', () => {
it('should return false', () => {
const wrapper = new InstanceWrapper({ scope: Scope.REQUEST });
wrapper.addCtorMetadata(0, new InstanceWrapper());
expect(wrapper.isDependencyTreeDurable()).to.be.false;
});
});
describe('when wrapper is durable and dependecy is static', () => {
it('should return true', () => {
const wrapper = new InstanceWrapper({
scope: Scope.REQUEST,
durable: true,
});
wrapper.addCtorMetadata(0, new InstanceWrapper());
expect(wrapper.isDependencyTreeDurable()).to.be.true;
});
});
describe('when wrapper is non durable and dependecy is durable', () => {
it('should return false', () => {
const wrapper = new InstanceWrapper({
scope: Scope.REQUEST,
});
wrapper.addCtorMetadata(
0,
new InstanceWrapper({ scope: Scope.REQUEST, durable: true }),
);
expect(wrapper.isDependencyTreeDurable()).to.be.false;
});
});
describe('when wrapper is durable and dependecy is static', () => {
it('should return true', () => {
const wrapper = new InstanceWrapper({
scope: Scope.REQUEST,
durable: true,
});
wrapper.addCtorMetadata(0, new InstanceWrapper());
expect(wrapper.isDependencyTreeDurable()).to.be.true;
});
});
describe('when wrapper is durable and dependecy is non durable', () => {
it('should return true', () => {
const wrapper = new InstanceWrapper({
scope: Scope.REQUEST,
durable: true,
});
wrapper.addCtorMetadata(
0,
new InstanceWrapper({ scope: Scope.REQUEST }),
);
expect(wrapper.isDependencyTreeDurable()).to.be.true;
});
});
describe('when each is static', () => {
it('should return false', () => {
const wrapper = new InstanceWrapper();
@@ -384,58 +174,6 @@ describe('InstanceWrapper', () => {
});
});
describe('properties', () => {
describe('when wrapper is non durable and dependecy is static', () => {
it('should return false', () => {
const wrapper = new InstanceWrapper({ scope: Scope.REQUEST });
wrapper.addPropertiesMetadata('key1', new InstanceWrapper());
expect(wrapper.isDependencyTreeDurable()).to.be.false;
});
});
describe('when wrapper is durable and dependecy is static', () => {
it('should return true', () => {
const wrapper = new InstanceWrapper({
scope: Scope.REQUEST,
durable: true,
});
wrapper.addPropertiesMetadata('key1', new InstanceWrapper());
expect(wrapper.isDependencyTreeDurable()).to.be.true;
});
});
describe('when wrapper is non durable and dependecy is durable', () => {
it('should return false', () => {
const wrapper = new InstanceWrapper({
scope: Scope.REQUEST,
});
wrapper.addPropertiesMetadata(
'key1',
new InstanceWrapper({ scope: Scope.REQUEST, durable: true }),
);
expect(wrapper.isDependencyTreeDurable()).to.be.false;
});
});
describe('when wrapper is durable and dependecy is static', () => {
it('should return true', () => {
const wrapper = new InstanceWrapper({
scope: Scope.REQUEST,
durable: true,
});
wrapper.addPropertiesMetadata('key1', new InstanceWrapper());
expect(wrapper.isDependencyTreeDurable()).to.be.true;
});
});
describe('when wrapper is durable and dependecy is non durable', () => {
it('should return true', () => {
const wrapper = new InstanceWrapper({
scope: Scope.REQUEST,
durable: true,
});
wrapper.addPropertiesMetadata(
'key1',
new InstanceWrapper({ scope: Scope.REQUEST }),
);
expect(wrapper.isDependencyTreeDurable()).to.be.true;
});
});
describe('when each is static', () => {
it('should return false', () => {
const wrapper = new InstanceWrapper();
@@ -483,56 +221,6 @@ describe('InstanceWrapper', () => {
});
});
describe('enhancers', () => {
describe('when wrapper is non durable and dependecy is static', () => {
it('should return false', () => {
const wrapper = new InstanceWrapper({ scope: Scope.REQUEST });
wrapper.addEnhancerMetadata(new InstanceWrapper());
expect(wrapper.isDependencyTreeDurable()).to.be.false;
});
});
describe('when wrapper is durable and dependecy is static', () => {
it('should return true', () => {
const wrapper = new InstanceWrapper({
scope: Scope.REQUEST,
durable: true,
});
wrapper.addEnhancerMetadata(new InstanceWrapper());
expect(wrapper.isDependencyTreeDurable()).to.be.true;
});
});
describe('when wrapper is non durable and dependecy is durable', () => {
it('should return false', () => {
const wrapper = new InstanceWrapper({
scope: Scope.REQUEST,
});
wrapper.addEnhancerMetadata(
new InstanceWrapper({ scope: Scope.REQUEST, durable: true }),
);
expect(wrapper.isDependencyTreeDurable()).to.be.false;
});
});
describe('when wrapper is durable and dependecy is static', () => {
it('should return true', () => {
const wrapper = new InstanceWrapper({
scope: Scope.REQUEST,
durable: true,
});
wrapper.addEnhancerMetadata(new InstanceWrapper());
expect(wrapper.isDependencyTreeDurable()).to.be.true;
});
});
describe('when wrapper is durable and dependecy is non durable', () => {
it('should return true', () => {
const wrapper = new InstanceWrapper({
scope: Scope.REQUEST,
durable: true,
});
wrapper.addEnhancerMetadata(
new InstanceWrapper({ scope: Scope.REQUEST }),
);
expect(wrapper.isDependencyTreeDurable()).to.be.true;
});
});
describe('when each is static', () => {
it('should return false', () => {
const wrapper = new InstanceWrapper();