diff --git a/.changeset/short-ads-kick.md b/.changeset/short-ads-kick.md new file mode 100644 index 00000000..e8490064 --- /dev/null +++ b/.changeset/short-ads-kick.md @@ -0,0 +1,5 @@ +--- +"@inversifyjs/core": minor +--- + +Updated `ClassMetadata` with `scope`. diff --git a/packages/container/libraries/core/src/metadata/actions/updateMaybeClassMetadataConstructorArgument.spec.ts b/packages/container/libraries/core/src/metadata/actions/updateMaybeClassMetadataConstructorArgument.spec.ts index 52faeaae..741e18a4 100644 --- a/packages/container/libraries/core/src/metadata/actions/updateMaybeClassMetadataConstructorArgument.spec.ts +++ b/packages/container/libraries/core/src/metadata/actions/updateMaybeClassMetadataConstructorArgument.spec.ts @@ -1,5 +1,6 @@ import { afterAll, beforeAll, describe, expect, it, jest } from '@jest/globals'; +import { MaybeClassMetadataFixtures } from '../fixtures/MaybeClassMetadataFixtures'; import { ClassElementMetadataKind } from '../models/ClassElementMetadataKind'; import { ManagedClassElementMetadata } from '../models/ManagedClassElementMetadata'; import { MaybeClassElementMetadata } from '../models/MaybeClassElementMetadata'; @@ -19,23 +20,9 @@ describe(updateMaybeClassMetadataConstructorArgument.name, () => { beforeAll(() => { updateMetadataMock = jest.fn(); - classMetadataFixture = { - constructorArguments: [], - lifecycle: { - postConstructMethodName: undefined, - preDestroyMethodName: undefined, - }, - properties: new Map(), - }; + classMetadataFixture = MaybeClassMetadataFixtures.any; - originalClassMetadataFixture = { - constructorArguments: [], - lifecycle: { - postConstructMethodName: undefined, - preDestroyMethodName: undefined, - }, - properties: new Map(), - }; + originalClassMetadataFixture = MaybeClassMetadataFixtures.any; indexFixture = 0; }); diff --git a/packages/container/libraries/core/src/metadata/actions/updateMaybeClassMetadataPostConstructor.spec.ts b/packages/container/libraries/core/src/metadata/actions/updateMaybeClassMetadataPostConstructor.spec.ts index 5b1ba464..bad951df 100644 --- a/packages/container/libraries/core/src/metadata/actions/updateMaybeClassMetadataPostConstructor.spec.ts +++ b/packages/container/libraries/core/src/metadata/actions/updateMaybeClassMetadataPostConstructor.spec.ts @@ -2,6 +2,7 @@ import { beforeAll, describe, expect, it } from '@jest/globals'; import { InversifyCoreError } from '../../error/models/InversifyCoreError'; import { InversifyCoreErrorKind } from '../../error/models/InversifyCoreErrorKind'; +import { MaybeClassMetadataFixtures } from '../fixtures/MaybeClassMetadataFixtures'; import { MaybeClassMetadata } from '../models/MaybeClassMetadata'; import { updateMaybeClassMetadataPostConstructor } from './updateMaybeClassMetadataPostConstructor'; @@ -11,14 +12,7 @@ describe(updateMaybeClassMetadataPostConstructor.name, () => { let methodNameFixture: string | symbol; beforeAll(() => { - metadataFixture = { - constructorArguments: [], - lifecycle: { - postConstructMethodName: undefined, - preDestroyMethodName: undefined, - }, - properties: new Map(), - }; + metadataFixture = MaybeClassMetadataFixtures.any; methodNameFixture = Symbol(); }); @@ -40,6 +34,7 @@ describe(updateMaybeClassMetadataPostConstructor.name, () => { preDestroyMethodName: undefined, }, properties: new Map(), + scope: undefined, }; expect(result).toStrictEqual(expected); @@ -59,6 +54,7 @@ describe(updateMaybeClassMetadataPostConstructor.name, () => { preDestroyMethodName: undefined, }, properties: new Map(), + scope: undefined, }; methodNameFixture = Symbol(); }); diff --git a/packages/container/libraries/core/src/metadata/actions/updateMaybeClassMetadataPreDestroy.spec.ts b/packages/container/libraries/core/src/metadata/actions/updateMaybeClassMetadataPreDestroy.spec.ts index 9e6127f0..332a8464 100644 --- a/packages/container/libraries/core/src/metadata/actions/updateMaybeClassMetadataPreDestroy.spec.ts +++ b/packages/container/libraries/core/src/metadata/actions/updateMaybeClassMetadataPreDestroy.spec.ts @@ -18,6 +18,7 @@ describe(updateMaybeClassMetadataPreDestroy.name, () => { preDestroyMethodName: undefined, }, properties: new Map(), + scope: undefined, }; methodNameFixture = Symbol(); }); @@ -40,6 +41,7 @@ describe(updateMaybeClassMetadataPreDestroy.name, () => { preDestroyMethodName: methodNameFixture, }, properties: new Map(), + scope: undefined, }; expect(result).toStrictEqual(expected); @@ -59,6 +61,7 @@ describe(updateMaybeClassMetadataPreDestroy.name, () => { preDestroyMethodName: 'postConstructorMethodName', }, properties: new Map(), + scope: undefined, }; methodNameFixture = Symbol(); }); diff --git a/packages/container/libraries/core/src/metadata/actions/updateMaybeClassMetadataProperty.spec.ts b/packages/container/libraries/core/src/metadata/actions/updateMaybeClassMetadataProperty.spec.ts index 08276146..f0d9f6a8 100644 --- a/packages/container/libraries/core/src/metadata/actions/updateMaybeClassMetadataProperty.spec.ts +++ b/packages/container/libraries/core/src/metadata/actions/updateMaybeClassMetadataProperty.spec.ts @@ -1,5 +1,6 @@ import { afterAll, beforeAll, describe, expect, it, jest } from '@jest/globals'; +import { MaybeClassMetadataFixtures } from '../fixtures/MaybeClassMetadataFixtures'; import { ClassElementMetadataKind } from '../models/ClassElementMetadataKind'; import { ManagedClassElementMetadata } from '../models/ManagedClassElementMetadata'; import { MaybeClassElementMetadata } from '../models/MaybeClassElementMetadata'; @@ -19,23 +20,9 @@ describe(updateMaybeClassMetadataProperty.name, () => { beforeAll(() => { updateMetadataMock = jest.fn(); - classMetadataFixture = { - constructorArguments: [], - lifecycle: { - postConstructMethodName: undefined, - preDestroyMethodName: undefined, - }, - properties: new Map(), - }; + classMetadataFixture = MaybeClassMetadataFixtures.any; - originalClassMetadataFixture = { - constructorArguments: [], - lifecycle: { - postConstructMethodName: undefined, - preDestroyMethodName: undefined, - }, - properties: new Map(), - }; + originalClassMetadataFixture = MaybeClassMetadataFixtures.any; propertyKeyFixture = 'property-key-fixture'; }); diff --git a/packages/container/libraries/core/src/metadata/calculations/getClassMetadata.spec.ts b/packages/container/libraries/core/src/metadata/calculations/getClassMetadata.spec.ts index bc49cc3a..2c780139 100644 --- a/packages/container/libraries/core/src/metadata/calculations/getClassMetadata.spec.ts +++ b/packages/container/libraries/core/src/metadata/calculations/getClassMetadata.spec.ts @@ -13,6 +13,7 @@ jest.mock('./isPendingClassMetadata'); jest.mock('./throwAtInvalidClassMetadata'); import { classMetadataReflectKey } from '../../reflectMetadata/data/classMetadataReflectKey'; +import { ClassMetadataFixtures } from '../fixtures/ClassMetadataFixtures'; import { ClassMetadata } from '../models/ClassMetadata'; import { assertConstructorMetadataArrayFilled } from './assertConstructorMetadataArrayFilled'; import { getClassMetadata } from './getClassMetadata'; @@ -35,14 +36,7 @@ describe(getClassMetadata.name, () => { beforeAll(() => { errorFixture = new Error('error-fixture-message'); - metadataFixture = { - constructorArguments: [], - lifecycle: { - postConstructMethodName: undefined, - preDestroyMethodName: undefined, - }, - properties: new Map(), - }; + metadataFixture = ClassMetadataFixtures.any; ( getReflectMetadata as jest.Mock @@ -109,6 +103,7 @@ describe(getClassMetadata.name, () => { preDestroyMethodName: undefined, }, properties: new Map(), + scope: undefined, }; ( diff --git a/packages/container/libraries/core/src/metadata/calculations/getDefaultClassMetadata.spec.ts b/packages/container/libraries/core/src/metadata/calculations/getDefaultClassMetadata.spec.ts index 5bce99b7..3250ac21 100644 --- a/packages/container/libraries/core/src/metadata/calculations/getDefaultClassMetadata.spec.ts +++ b/packages/container/libraries/core/src/metadata/calculations/getDefaultClassMetadata.spec.ts @@ -19,6 +19,7 @@ describe(getDefaultClassMetadata.name, () => { preDestroyMethodName: undefined, }, properties: new Map(), + scope: undefined, }; expect(result).toStrictEqual(expected); diff --git a/packages/container/libraries/core/src/metadata/calculations/getDefaultClassMetadata.ts b/packages/container/libraries/core/src/metadata/calculations/getDefaultClassMetadata.ts index 3aadece8..ced0edc0 100644 --- a/packages/container/libraries/core/src/metadata/calculations/getDefaultClassMetadata.ts +++ b/packages/container/libraries/core/src/metadata/calculations/getDefaultClassMetadata.ts @@ -8,5 +8,6 @@ export function getDefaultClassMetadata(): ClassMetadata { preDestroyMethodName: undefined, }, properties: new Map(), + scope: undefined, }; } diff --git a/packages/container/libraries/core/src/metadata/calculations/throwAtInvalidClassMetadata.spec.ts b/packages/container/libraries/core/src/metadata/calculations/throwAtInvalidClassMetadata.spec.ts index 3bd58f2f..f3dbc810 100644 --- a/packages/container/libraries/core/src/metadata/calculations/throwAtInvalidClassMetadata.spec.ts +++ b/packages/container/libraries/core/src/metadata/calculations/throwAtInvalidClassMetadata.spec.ts @@ -4,6 +4,7 @@ import { Newable } from '@inversifyjs/common'; import { InversifyCoreError } from '../../error/models/InversifyCoreError'; import { InversifyCoreErrorKind } from '../../error/models/InversifyCoreErrorKind'; +import { ClassMetadataFixtures } from '../fixtures/ClassMetadataFixtures'; import { ClassMetadata } from '../models/ClassMetadata'; import { MaybeClassElementMetadata } from '../models/MaybeClassElementMetadata'; import { MaybeClassElementMetadataKind } from '../models/MaybeClassElementMetadataKind'; @@ -17,14 +18,7 @@ describe(throwAtInvalidClassMetadata.name, () => { beforeAll(() => { typefixture = class Foo {}; - classMetadataFixure = { - constructorArguments: [], - lifecycle: { - postConstructMethodName: undefined, - preDestroyMethodName: undefined, - }, - properties: new Map(), - }; + classMetadataFixure = ClassMetadataFixtures.any; }); describe('when called', () => { @@ -93,6 +87,7 @@ This might be caused by one of the following reasons: preDestroyMethodName: undefined, }, properties: new Map([[invalidPropertyName, maybeClassElementMetadata]]), + scope: undefined, }; }); diff --git a/packages/container/libraries/core/src/metadata/decorators/inject.int.spec.ts b/packages/container/libraries/core/src/metadata/decorators/inject.int.spec.ts index b49dfc4f..e103f7b2 100644 --- a/packages/container/libraries/core/src/metadata/decorators/inject.int.spec.ts +++ b/packages/container/libraries/core/src/metadata/decorators/inject.int.spec.ts @@ -80,6 +80,7 @@ describe(inject.name, () => { }, ], ]), + scope: undefined, }; expect(result).toStrictEqual(expected); diff --git a/packages/container/libraries/core/src/metadata/decorators/injectFrom.int.spec.ts b/packages/container/libraries/core/src/metadata/decorators/injectFrom.int.spec.ts index 0eba3cab..1e7f08a9 100644 --- a/packages/container/libraries/core/src/metadata/decorators/injectFrom.int.spec.ts +++ b/packages/container/libraries/core/src/metadata/decorators/injectFrom.int.spec.ts @@ -54,6 +54,7 @@ describe(injectFrom.name, () => { preDestroyMethodName: undefined, }, properties: new Map(), + scope: undefined, }; expect(result).toStrictEqual(expected); @@ -127,6 +128,7 @@ describe(injectFrom.name, () => { }, ], ]), + scope: undefined, }; expect(result).toStrictEqual(expected); @@ -276,6 +278,7 @@ describe(injectFrom.name, () => { ['bar', expectedBarPropertyMetadata], ['baz', expectedBazPropertyMetadata], ]), + scope: undefined, }; expect(result).toStrictEqual(expectedClassMetadata); @@ -325,6 +328,7 @@ describe(injectFrom.name, () => { preDestroyMethodName: undefined, }, properties: new Map(), + scope: undefined, }; expect(result).toStrictEqual(expected); @@ -392,6 +396,7 @@ describe(injectFrom.name, () => { }, ], ]), + scope: undefined, }; expect(result).toStrictEqual(expectedClassMetadata); @@ -461,6 +466,7 @@ describe(injectFrom.name, () => { }, ], ]), + scope: undefined, }; expect(result).toStrictEqual(expectedClassMetadata); }); @@ -586,6 +592,7 @@ describe(injectFrom.name, () => { }, ], ]), + scope: undefined, }; expect(result).toStrictEqual(expectedClassMetadata); diff --git a/packages/container/libraries/core/src/metadata/decorators/injectFrom.ts b/packages/container/libraries/core/src/metadata/decorators/injectFrom.ts index 9bf39480..2674189d 100644 --- a/packages/container/libraries/core/src/metadata/decorators/injectFrom.ts +++ b/packages/container/libraries/core/src/metadata/decorators/injectFrom.ts @@ -42,6 +42,7 @@ function composeUpdateReflectMetadataCallback( baseTypeClassMetadata, typeMetadata, ), + scope: typeMetadata.scope, }); return callback; diff --git a/packages/container/libraries/core/src/metadata/decorators/multiInject.int.spec.ts b/packages/container/libraries/core/src/metadata/decorators/multiInject.int.spec.ts index 28946696..365754f1 100644 --- a/packages/container/libraries/core/src/metadata/decorators/multiInject.int.spec.ts +++ b/packages/container/libraries/core/src/metadata/decorators/multiInject.int.spec.ts @@ -80,6 +80,7 @@ describe(multiInject.name, () => { }, ], ]), + scope: undefined, }; expect(result).toStrictEqual(expected); diff --git a/packages/container/libraries/core/src/metadata/decorators/named.int.spec.ts b/packages/container/libraries/core/src/metadata/decorators/named.int.spec.ts index 031f3dbc..487d4761 100644 --- a/packages/container/libraries/core/src/metadata/decorators/named.int.spec.ts +++ b/packages/container/libraries/core/src/metadata/decorators/named.int.spec.ts @@ -76,6 +76,7 @@ describe(named.name, () => { }, ], ]), + scope: undefined, }; expect(result).toStrictEqual(expected); diff --git a/packages/container/libraries/core/src/metadata/decorators/optional.int.spec.ts b/packages/container/libraries/core/src/metadata/decorators/optional.int.spec.ts index 36662569..fa35b9c4 100644 --- a/packages/container/libraries/core/src/metadata/decorators/optional.int.spec.ts +++ b/packages/container/libraries/core/src/metadata/decorators/optional.int.spec.ts @@ -76,6 +76,7 @@ describe(optional.name, () => { }, ], ]), + scope: undefined, }; expect(result).toStrictEqual(expected); diff --git a/packages/container/libraries/core/src/metadata/decorators/postConstruct.int.spec.ts b/packages/container/libraries/core/src/metadata/decorators/postConstruct.int.spec.ts index 284d8e01..2b7ca1c9 100644 --- a/packages/container/libraries/core/src/metadata/decorators/postConstruct.int.spec.ts +++ b/packages/container/libraries/core/src/metadata/decorators/postConstruct.int.spec.ts @@ -29,6 +29,7 @@ describe(postConstruct.name, () => { preDestroyMethodName: undefined, }, properties: new Map(), + scope: undefined, }; expect(result).toStrictEqual(expected); diff --git a/packages/container/libraries/core/src/metadata/decorators/preDestroy.int.spec.ts b/packages/container/libraries/core/src/metadata/decorators/preDestroy.int.spec.ts index db5475f5..38785d47 100644 --- a/packages/container/libraries/core/src/metadata/decorators/preDestroy.int.spec.ts +++ b/packages/container/libraries/core/src/metadata/decorators/preDestroy.int.spec.ts @@ -29,6 +29,7 @@ describe(preDestroy.name, () => { preDestroyMethodName: 'initialize', }, properties: new Map(), + scope: undefined, }; expect(result).toStrictEqual(expected); diff --git a/packages/container/libraries/core/src/metadata/decorators/tagged.int.spec.ts b/packages/container/libraries/core/src/metadata/decorators/tagged.int.spec.ts index 2ce68970..0c6dd682 100644 --- a/packages/container/libraries/core/src/metadata/decorators/tagged.int.spec.ts +++ b/packages/container/libraries/core/src/metadata/decorators/tagged.int.spec.ts @@ -76,6 +76,7 @@ describe(tagged.name, () => { }, ], ]), + scope: undefined, }; expect(result).toStrictEqual(expected); diff --git a/packages/container/libraries/core/src/metadata/decorators/targetName.int.spec.ts b/packages/container/libraries/core/src/metadata/decorators/targetName.int.spec.ts index b661f5fc..f54fe862 100644 --- a/packages/container/libraries/core/src/metadata/decorators/targetName.int.spec.ts +++ b/packages/container/libraries/core/src/metadata/decorators/targetName.int.spec.ts @@ -76,6 +76,7 @@ describe(targetName.name, () => { }, ], ]), + scope: undefined, }; expect(result).toStrictEqual(expected); diff --git a/packages/container/libraries/core/src/metadata/decorators/unmanaged.int.spec.ts b/packages/container/libraries/core/src/metadata/decorators/unmanaged.int.spec.ts index 79539c75..ce820190 100644 --- a/packages/container/libraries/core/src/metadata/decorators/unmanaged.int.spec.ts +++ b/packages/container/libraries/core/src/metadata/decorators/unmanaged.int.spec.ts @@ -60,6 +60,7 @@ describe(unmanaged.name, () => { }, ], ]), + scope: undefined, }; expect(result).toStrictEqual(expected); diff --git a/packages/container/libraries/core/src/metadata/fixtures/ClassMetadataFixtures.ts b/packages/container/libraries/core/src/metadata/fixtures/ClassMetadataFixtures.ts index 1b5cdc55..5f2bcfbd 100644 --- a/packages/container/libraries/core/src/metadata/fixtures/ClassMetadataFixtures.ts +++ b/packages/container/libraries/core/src/metadata/fixtures/ClassMetadataFixtures.ts @@ -9,6 +9,7 @@ export class ClassMetadataFixtures { preDestroyMethodName: undefined, }, properties: new Map(), + scope: undefined, }; return fixture; diff --git a/packages/container/libraries/core/src/metadata/fixtures/MaybeClassMetadataFixtures.ts b/packages/container/libraries/core/src/metadata/fixtures/MaybeClassMetadataFixtures.ts new file mode 100644 index 00000000..81843747 --- /dev/null +++ b/packages/container/libraries/core/src/metadata/fixtures/MaybeClassMetadataFixtures.ts @@ -0,0 +1,17 @@ +import { MaybeClassMetadata } from '../models/MaybeClassMetadata'; + +export class MaybeClassMetadataFixtures { + public static get any(): MaybeClassMetadata { + const fixture: MaybeClassMetadata = { + constructorArguments: [], + lifecycle: { + postConstructMethodName: undefined, + preDestroyMethodName: undefined, + }, + properties: new Map(), + scope: undefined, + }; + + return fixture; + } +} diff --git a/packages/container/libraries/core/src/metadata/models/ClassMetadata.ts b/packages/container/libraries/core/src/metadata/models/ClassMetadata.ts index 03bc3d09..7b82b43f 100644 --- a/packages/container/libraries/core/src/metadata/models/ClassMetadata.ts +++ b/packages/container/libraries/core/src/metadata/models/ClassMetadata.ts @@ -1,3 +1,4 @@ +import { BindingScope } from '../../binding/models/BindingScope'; import { ClassElementMetadata } from './ClassElementMetadata'; import { ClassMetadataLifecycle } from './ClassMetadataLifecycle'; @@ -5,4 +6,5 @@ export interface ClassMetadata { constructorArguments: ClassElementMetadata[]; lifecycle: ClassMetadataLifecycle; properties: Map; + scope: BindingScope | undefined; } diff --git a/packages/container/libraries/core/src/metadata/models/MaybeClassMetadata.ts b/packages/container/libraries/core/src/metadata/models/MaybeClassMetadata.ts index e233c4f2..31162aa2 100644 --- a/packages/container/libraries/core/src/metadata/models/MaybeClassMetadata.ts +++ b/packages/container/libraries/core/src/metadata/models/MaybeClassMetadata.ts @@ -1,3 +1,4 @@ +import { BindingScope } from '../../binding/models/BindingScope'; import { ClassMetadataLifecycle } from './ClassMetadataLifecycle'; import { MaybeClassElementMetadata } from './MaybeClassElementMetadata'; @@ -5,4 +6,5 @@ export interface MaybeClassMetadata { constructorArguments: MaybeClassElementMetadata[]; lifecycle: ClassMetadataLifecycle; properties: Map; + scope: BindingScope | undefined; } diff --git a/packages/container/libraries/core/src/planning/calculations/plan.spec.ts b/packages/container/libraries/core/src/planning/calculations/plan.spec.ts index b0798883..29e24447 100644 --- a/packages/container/libraries/core/src/planning/calculations/plan.spec.ts +++ b/packages/container/libraries/core/src/planning/calculations/plan.spec.ts @@ -13,6 +13,7 @@ import { InstanceBinding } from '../../binding/models/InstanceBinding'; import { ServiceRedirectionBinding } from '../../binding/models/ServiceRedirectionBinding'; import { SingleInmutableLinkedList } from '../../common/models/SingleInmutableLinkedList'; import { Writable } from '../../common/models/Writable'; +import { ClassMetadataFixtures } from '../../metadata/fixtures/ClassMetadataFixtures'; import { ClassElementMetadataKind } from '../../metadata/models/ClassElementMetadataKind'; import { ClassMetadata } from '../../metadata/models/ClassMetadata'; import { ManagedClassElementMetadata } from '../../metadata/models/ManagedClassElementMetadata'; @@ -286,14 +287,7 @@ describe(plan.name, () => { let result: unknown; beforeAll(() => { - classMetadataFixture = { - constructorArguments: [], - lifecycle: { - postConstructMethodName: undefined, - preDestroyMethodName: undefined, - }, - properties: new Map(), - }; + classMetadataFixture = ClassMetadataFixtures.any; instanceBindingFixture = { cache: { isRight: true, @@ -424,6 +418,7 @@ describe(plan.name, () => { preDestroyMethodName: undefined, }, properties: new Map([[propertyKey, propertyMetadata]]), + scope: undefined, }; instanceBindingFixture = { cache: { @@ -633,6 +628,7 @@ describe(plan.name, () => { preDestroyMethodName: undefined, }, properties: new Map([[propertyKey, propertyMetadata]]), + scope: undefined, }; instanceBindingFixture = { cache: { @@ -846,6 +842,7 @@ describe(plan.name, () => { preDestroyMethodName: undefined, }, properties: new Map([[propertyKey, propertyMetadata]]), + scope: undefined, }; instanceBindingFixture = { cache: { @@ -1055,6 +1052,7 @@ describe(plan.name, () => { preDestroyMethodName: undefined, }, properties: new Map([[propertyKey, propertyArgumentMetadata]]), + scope: undefined, }; instanceBindingFixture = { cache: {