From 7f97e76275a950e8215a4ae1453a4936e7604f3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roberto=20Pintos=20L=C3=B3pez?= Date: Sat, 11 Jan 2025 18:54:16 +0100 Subject: [PATCH] feat(core): remove target name modules --- .changeset/calm-fireants-tie.md | 5 + .changeset/orange-carrots-hang.md | 5 + .changeset/tender-chairs-divide.md | 5 + .changeset/warm-candles-prove.md | 5 + .../container/libraries/core/src/index.ts | 4 - ...decrementPendingClassMetadataCount.spec.ts | 1 - ...beClassMetadataConstructorArgument.spec.ts | 1 - .../updateMaybeClassMetadataProperty.spec.ts | 1 - .../actions/updateMetadataName.spec.ts | 2 - .../actions/updateMetadataOptional.spec.ts | 2 - .../actions/updateMetadataTag.spec.ts | 2 - .../actions/updateMetadataTargetName.spec.ts | 92 ----- .../actions/updateMetadataTargetName.ts | 26 -- ...adataFromMaybeClassElementMetadata.spec.ts | 1 - ...etadataFromTypescriptParameterType.spec.ts | 1 - ...mentMetadataFromTypescriptParameterType.ts | 1 - .../buildDefaultManagedMetadata.spec.ts | 1 - .../buildDefaultManagedMetadata.ts | 1 - ...ldDefaultMaybeClassElementMetadata.spec.ts | 1 - .../buildDefaultMaybeClassElementMetadata.ts | 1 - ...edMetadataFromMaybeManagedMetadata.spec.ts | 2 - ...adataFromMaybeClassElementMetadata.spec.ts | 1 - ...edMetadataFromMaybeManagedMetadata.spec.ts | 14 - ...managedMetadataFromMaybeManagedMetadata.ts | 5 +- .../getExtendedConstructorArguments.spec.ts | 4 - .../getExtendedProperties.spec.ts | 5 - .../throwAtInvalidClassMetadata.spec.ts | 1 - .../metadata/decorators/inject.int.spec.ts | 4 - .../decorators/injectFrom.int.spec.ts | 16 - .../decorators/multiInject.int.spec.ts | 4 - .../src/metadata/decorators/named.int.spec.ts | 4 - .../metadata/decorators/optional.int.spec.ts | 4 - .../metadata/decorators/tagged.int.spec.ts | 4 - .../decorators/targetName.int.spec.ts | 85 ---- .../metadata/decorators/targetName.spec.ts | 373 ------------------ .../src/metadata/decorators/targetName.ts | 43 -- .../ManagedClassElementMetadataFixtures.ts | 1 - ...aybeManagedClassElementMetadataFixtures.ts | 1 - .../models/ManagedClassElementMetadata.ts | 2 - .../MaybeManagedClassElementMetadata.ts | 2 - .../src/metadata/models/MetadataTargetName.ts | 1 - .../src/planning/calculations/plan.spec.ts | 6 - .../actions/setInstanceProperties.spec.ts | 1 - .../actions/setInstanceProperties.ts | 9 +- 44 files changed, 24 insertions(+), 726 deletions(-) create mode 100644 .changeset/calm-fireants-tie.md create mode 100644 .changeset/orange-carrots-hang.md create mode 100644 .changeset/tender-chairs-divide.md create mode 100644 .changeset/warm-candles-prove.md delete mode 100644 packages/container/libraries/core/src/metadata/actions/updateMetadataTargetName.spec.ts delete mode 100644 packages/container/libraries/core/src/metadata/actions/updateMetadataTargetName.ts delete mode 100644 packages/container/libraries/core/src/metadata/decorators/targetName.int.spec.ts delete mode 100644 packages/container/libraries/core/src/metadata/decorators/targetName.spec.ts delete mode 100644 packages/container/libraries/core/src/metadata/decorators/targetName.ts delete mode 100644 packages/container/libraries/core/src/metadata/models/MetadataTargetName.ts diff --git a/.changeset/calm-fireants-tie.md b/.changeset/calm-fireants-tie.md new file mode 100644 index 00000000..1292f2e3 --- /dev/null +++ b/.changeset/calm-fireants-tie.md @@ -0,0 +1,5 @@ +--- +"@inversifyjs/core": major +--- + +Removed `MetadataTargetName` diff --git a/.changeset/orange-carrots-hang.md b/.changeset/orange-carrots-hang.md new file mode 100644 index 00000000..386a0885 --- /dev/null +++ b/.changeset/orange-carrots-hang.md @@ -0,0 +1,5 @@ +--- +"@inversifyjs/core": major +--- + +Updated `ManagedClassElementMetadata` with no `targetName` diff --git a/.changeset/tender-chairs-divide.md b/.changeset/tender-chairs-divide.md new file mode 100644 index 00000000..8c9c2e02 --- /dev/null +++ b/.changeset/tender-chairs-divide.md @@ -0,0 +1,5 @@ +--- +"@inversifyjs/core": major +--- + +Updated `MaybeManagedClassElementMetadata` with no `targetName` diff --git a/.changeset/warm-candles-prove.md b/.changeset/warm-candles-prove.md new file mode 100644 index 00000000..f9ccbc6f --- /dev/null +++ b/.changeset/warm-candles-prove.md @@ -0,0 +1,5 @@ +--- +"@inversifyjs/core": major +--- + +Removed `targetName` diff --git a/packages/container/libraries/core/src/index.ts b/packages/container/libraries/core/src/index.ts index f9f1ea74..0b9f4391 100644 --- a/packages/container/libraries/core/src/index.ts +++ b/packages/container/libraries/core/src/index.ts @@ -38,7 +38,6 @@ import { optional } from './metadata/decorators/optional'; import { postConstruct } from './metadata/decorators/postConstruct'; import { preDestroy } from './metadata/decorators/preDestroy'; import { tagged } from './metadata/decorators/tagged'; -import { targetName } from './metadata/decorators/targetName'; import { unmanaged } from './metadata/decorators/unmanaged'; import { ClassElementMetadata } from './metadata/models/ClassElementMetadata'; import { ClassElementMetadataKind } from './metadata/models/ClassElementMetadataKind'; @@ -47,7 +46,6 @@ import { ClassMetadataLifecycle } from './metadata/models/ClassMetadataLifecycle import { ManagedClassElementMetadata } from './metadata/models/ManagedClassElementMetadata'; import { MetadataName } from './metadata/models/MetadataName'; import { MetadataTag } from './metadata/models/MetadataTag'; -import { MetadataTargetName } from './metadata/models/MetadataTargetName'; import { UnmanagedClassElementMetadata } from './metadata/models/UnmanagedClassElementMetadata'; import { plan } from './planning/calculations/plan'; import { BaseBindingNode } from './planning/models/BaseBindingNode'; @@ -101,7 +99,6 @@ export type { ManagedClassElementMetadata, MetadataName, MetadataTag, - MetadataTargetName, OptionalGetOptions, PlanBindingNode, PlanParams, @@ -144,6 +141,5 @@ export { resolveModuleDeactivations, resolveServiceDeactivations, tagged, - targetName, unmanaged, }; diff --git a/packages/container/libraries/core/src/metadata/actions/decrementPendingClassMetadataCount.spec.ts b/packages/container/libraries/core/src/metadata/actions/decrementPendingClassMetadataCount.spec.ts index 5274ff42..639b42e9 100644 --- a/packages/container/libraries/core/src/metadata/actions/decrementPendingClassMetadataCount.spec.ts +++ b/packages/container/libraries/core/src/metadata/actions/decrementPendingClassMetadataCount.spec.ts @@ -27,7 +27,6 @@ describe(decrementPendingClassMetadataCount.name, () => { name: undefined, optional: false, tags: new Map(), - targetName: undefined, }; }); 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 741e18a4..5542db2b 100644 --- a/packages/container/libraries/core/src/metadata/actions/updateMaybeClassMetadataConstructorArgument.spec.ts +++ b/packages/container/libraries/core/src/metadata/actions/updateMaybeClassMetadataConstructorArgument.spec.ts @@ -38,7 +38,6 @@ describe(updateMaybeClassMetadataConstructorArgument.name, () => { name: undefined, optional: false, tags: new Map(), - targetName: undefined, value: 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 f0d9f6a8..3be94415 100644 --- a/packages/container/libraries/core/src/metadata/actions/updateMaybeClassMetadataProperty.spec.ts +++ b/packages/container/libraries/core/src/metadata/actions/updateMaybeClassMetadataProperty.spec.ts @@ -38,7 +38,6 @@ describe(updateMaybeClassMetadataProperty.name, () => { name: undefined, optional: false, tags: new Map(), - targetName: undefined, value: Symbol(), }; diff --git a/packages/container/libraries/core/src/metadata/actions/updateMetadataName.spec.ts b/packages/container/libraries/core/src/metadata/actions/updateMetadataName.spec.ts index b5454750..46e6b2a4 100644 --- a/packages/container/libraries/core/src/metadata/actions/updateMetadataName.spec.ts +++ b/packages/container/libraries/core/src/metadata/actions/updateMetadataName.spec.ts @@ -21,7 +21,6 @@ describe(updateMetadataName.name, () => { name: undefined, optional: false, tags: new Map(), - targetName: undefined, value: 'service-id', }; nameFixture = 'name-fixture'; @@ -59,7 +58,6 @@ describe(updateMetadataName.name, () => { name: 'name-fixture', optional: false, tags: new Map(), - targetName: undefined, value: 'service-id', }; nameFixture = 'name-fixture'; diff --git a/packages/container/libraries/core/src/metadata/actions/updateMetadataOptional.spec.ts b/packages/container/libraries/core/src/metadata/actions/updateMetadataOptional.spec.ts index bb0c6599..27203d4b 100644 --- a/packages/container/libraries/core/src/metadata/actions/updateMetadataOptional.spec.ts +++ b/packages/container/libraries/core/src/metadata/actions/updateMetadataOptional.spec.ts @@ -19,7 +19,6 @@ describe(updateMetadataOptional.name, () => { name: undefined, optional: false, tags: new Map(), - targetName: undefined, value: 'service-id', }; }); @@ -55,7 +54,6 @@ describe(updateMetadataOptional.name, () => { name: undefined, optional: true, tags: new Map(), - targetName: undefined, value: 'service-id', }; }); diff --git a/packages/container/libraries/core/src/metadata/actions/updateMetadataTag.spec.ts b/packages/container/libraries/core/src/metadata/actions/updateMetadataTag.spec.ts index c7aae687..0d164ae9 100644 --- a/packages/container/libraries/core/src/metadata/actions/updateMetadataTag.spec.ts +++ b/packages/container/libraries/core/src/metadata/actions/updateMetadataTag.spec.ts @@ -22,7 +22,6 @@ describe(updateMetadataTag.name, () => { name: undefined, optional: false, tags: new Map(), - targetName: undefined, value: 'service-id', }; keyFixture = 'tag-fixture'; @@ -62,7 +61,6 @@ describe(updateMetadataTag.name, () => { name: undefined, optional: false, tags: new Map([['tag-fixture', Symbol()]]), - targetName: undefined, value: 'service-id', }; keyFixture = 'tag-fixture'; diff --git a/packages/container/libraries/core/src/metadata/actions/updateMetadataTargetName.spec.ts b/packages/container/libraries/core/src/metadata/actions/updateMetadataTargetName.spec.ts deleted file mode 100644 index 33e0fa1f..00000000 --- a/packages/container/libraries/core/src/metadata/actions/updateMetadataTargetName.spec.ts +++ /dev/null @@ -1,92 +0,0 @@ -import { beforeAll, describe, expect, it } from '@jest/globals'; - -import { InversifyCoreError } from '../../error/models/InversifyCoreError'; -import { InversifyCoreErrorKind } from '../../error/models/InversifyCoreErrorKind'; -import { ClassElementMetadataKind } from '../models/ClassElementMetadataKind'; -import { ManagedClassElementMetadata } from '../models/ManagedClassElementMetadata'; -import { MaybeManagedClassElementMetadata } from '../models/MaybeManagedClassElementMetadata'; -import { MetadataTargetName } from '../models/MetadataTargetName'; -import { updateMetadataTargetName } from './updateMetadataTargetName'; - -describe(updateMetadataTargetName.name, () => { - describe('having metadata with no target name', () => { - let metadataFixture: - | ManagedClassElementMetadata - | MaybeManagedClassElementMetadata; - let targetNameFixture: MetadataTargetName; - - beforeAll(() => { - metadataFixture = { - kind: ClassElementMetadataKind.singleInjection, - name: undefined, - optional: false, - tags: new Map(), - targetName: undefined, - value: 'service-id', - }; - targetNameFixture = 'target-name-fixture'; - }); - - describe('when called', () => { - let result: unknown; - - beforeAll(() => { - result = updateMetadataTargetName(targetNameFixture)(metadataFixture); - }); - - it('should return metadata', () => { - const expected: - | ManagedClassElementMetadata - | MaybeManagedClassElementMetadata = { - ...metadataFixture, - targetName: targetNameFixture, - }; - - expect(result).toStrictEqual(expected); - }); - }); - }); - - describe('having metadata with target name', () => { - let metadataFixture: - | ManagedClassElementMetadata - | MaybeManagedClassElementMetadata; - let targetNameFixture: MetadataTargetName; - - beforeAll(() => { - metadataFixture = { - kind: ClassElementMetadataKind.singleInjection, - name: undefined, - optional: false, - tags: new Map(), - targetName: 'target-name-fixture', - value: 'service-id', - }; - targetNameFixture = 'target-name-fixture'; - }); - - describe('when called', () => { - let result: unknown; - - beforeAll(() => { - try { - updateMetadataTargetName(targetNameFixture)(metadataFixture); - } catch (error: unknown) { - result = error; - } - }); - - it('should throw InversifyCoreError', () => { - const expectedErrorProperties: Partial = { - kind: InversifyCoreErrorKind.injectionDecoratorConflict, - message: 'Unexpected duplicated targetName decorator', - }; - - expect(result).toBeInstanceOf(InversifyCoreError); - expect(result).toStrictEqual( - expect.objectContaining(expectedErrorProperties), - ); - }); - }); - }); -}); diff --git a/packages/container/libraries/core/src/metadata/actions/updateMetadataTargetName.ts b/packages/container/libraries/core/src/metadata/actions/updateMetadataTargetName.ts deleted file mode 100644 index ea1c61ee..00000000 --- a/packages/container/libraries/core/src/metadata/actions/updateMetadataTargetName.ts +++ /dev/null @@ -1,26 +0,0 @@ -import { InversifyCoreError } from '../../error/models/InversifyCoreError'; -import { InversifyCoreErrorKind } from '../../error/models/InversifyCoreErrorKind'; -import { ManagedClassElementMetadata } from '../models/ManagedClassElementMetadata'; -import { MaybeManagedClassElementMetadata } from '../models/MaybeManagedClassElementMetadata'; -import { MetadataTargetName } from '../models/MetadataTargetName'; - -export function updateMetadataTargetName( - targetName: MetadataTargetName, -): ( - metadata: ManagedClassElementMetadata | MaybeManagedClassElementMetadata, -) => ManagedClassElementMetadata | MaybeManagedClassElementMetadata { - return ( - metadata: ManagedClassElementMetadata | MaybeManagedClassElementMetadata, - ): ManagedClassElementMetadata | MaybeManagedClassElementMetadata => { - if (metadata.targetName !== undefined) { - throw new InversifyCoreError( - InversifyCoreErrorKind.injectionDecoratorConflict, - 'Unexpected duplicated targetName decorator', - ); - } - - metadata.targetName = targetName; - - return metadata; - }; -} diff --git a/packages/container/libraries/core/src/metadata/calculations/buildClassElementMetadataFromMaybeClassElementMetadata.spec.ts b/packages/container/libraries/core/src/metadata/calculations/buildClassElementMetadataFromMaybeClassElementMetadata.spec.ts index ce3774ff..de5e824b 100644 --- a/packages/container/libraries/core/src/metadata/calculations/buildClassElementMetadataFromMaybeClassElementMetadata.spec.ts +++ b/packages/container/libraries/core/src/metadata/calculations/buildClassElementMetadataFromMaybeClassElementMetadata.spec.ts @@ -91,7 +91,6 @@ describe(buildClassElementMetadataFromMaybeClassElementMetadata.name, () => { name: undefined, optional: false, tags: new Map(), - targetName: undefined, }; }); diff --git a/packages/container/libraries/core/src/metadata/calculations/buildClassElementMetadataFromTypescriptParameterType.spec.ts b/packages/container/libraries/core/src/metadata/calculations/buildClassElementMetadataFromTypescriptParameterType.spec.ts index 38623ecb..6b81c38c 100644 --- a/packages/container/libraries/core/src/metadata/calculations/buildClassElementMetadataFromTypescriptParameterType.spec.ts +++ b/packages/container/libraries/core/src/metadata/calculations/buildClassElementMetadataFromTypescriptParameterType.spec.ts @@ -26,7 +26,6 @@ describe(buildClassElementMetadataFromTypescriptParameterType.name, () => { name: undefined, optional: false, tags: new Map(), - targetName: undefined, value: typeFixture, }; diff --git a/packages/container/libraries/core/src/metadata/calculations/buildClassElementMetadataFromTypescriptParameterType.ts b/packages/container/libraries/core/src/metadata/calculations/buildClassElementMetadataFromTypescriptParameterType.ts index c85e0d86..be747205 100644 --- a/packages/container/libraries/core/src/metadata/calculations/buildClassElementMetadataFromTypescriptParameterType.ts +++ b/packages/container/libraries/core/src/metadata/calculations/buildClassElementMetadataFromTypescriptParameterType.ts @@ -12,7 +12,6 @@ export function buildClassElementMetadataFromTypescriptParameterType( name: undefined, optional: false, tags: new Map(), - targetName: undefined, value: type, }; } diff --git a/packages/container/libraries/core/src/metadata/calculations/buildDefaultManagedMetadata.spec.ts b/packages/container/libraries/core/src/metadata/calculations/buildDefaultManagedMetadata.spec.ts index 45a24629..8d452c87 100644 --- a/packages/container/libraries/core/src/metadata/calculations/buildDefaultManagedMetadata.spec.ts +++ b/packages/container/libraries/core/src/metadata/calculations/buildDefaultManagedMetadata.spec.ts @@ -31,7 +31,6 @@ describe(buildDefaultManagedMetadata.name, () => { name: undefined, optional: false, tags: new Map(), - targetName: undefined, value: serviceIdentifierFixture, }; diff --git a/packages/container/libraries/core/src/metadata/calculations/buildDefaultManagedMetadata.ts b/packages/container/libraries/core/src/metadata/calculations/buildDefaultManagedMetadata.ts index a38697e5..cc02fbef 100644 --- a/packages/container/libraries/core/src/metadata/calculations/buildDefaultManagedMetadata.ts +++ b/packages/container/libraries/core/src/metadata/calculations/buildDefaultManagedMetadata.ts @@ -14,7 +14,6 @@ export function buildDefaultManagedMetadata( name: undefined, optional: false, tags: new Map(), - targetName: undefined, value: serviceIdentifier, }; } diff --git a/packages/container/libraries/core/src/metadata/calculations/buildDefaultMaybeClassElementMetadata.spec.ts b/packages/container/libraries/core/src/metadata/calculations/buildDefaultMaybeClassElementMetadata.spec.ts index 9a4ac70d..4ae695df 100644 --- a/packages/container/libraries/core/src/metadata/calculations/buildDefaultMaybeClassElementMetadata.spec.ts +++ b/packages/container/libraries/core/src/metadata/calculations/buildDefaultMaybeClassElementMetadata.spec.ts @@ -18,7 +18,6 @@ describe(buildDefaultMaybeClassElementMetadata.name, () => { name: undefined, optional: false, tags: new Map(), - targetName: undefined, }; expect(result).toStrictEqual(expected); diff --git a/packages/container/libraries/core/src/metadata/calculations/buildDefaultMaybeClassElementMetadata.ts b/packages/container/libraries/core/src/metadata/calculations/buildDefaultMaybeClassElementMetadata.ts index 345c7c9e..9c84fc21 100644 --- a/packages/container/libraries/core/src/metadata/calculations/buildDefaultMaybeClassElementMetadata.ts +++ b/packages/container/libraries/core/src/metadata/calculations/buildDefaultMaybeClassElementMetadata.ts @@ -7,6 +7,5 @@ export function buildDefaultMaybeClassElementMetadata(): MaybeManagedClassElemen name: undefined, optional: false, tags: new Map(), - targetName: undefined, }; } diff --git a/packages/container/libraries/core/src/metadata/calculations/buildManagedMetadataFromMaybeManagedMetadata.spec.ts b/packages/container/libraries/core/src/metadata/calculations/buildManagedMetadataFromMaybeManagedMetadata.spec.ts index f7e1b0e0..85e4f244 100644 --- a/packages/container/libraries/core/src/metadata/calculations/buildManagedMetadataFromMaybeManagedMetadata.spec.ts +++ b/packages/container/libraries/core/src/metadata/calculations/buildManagedMetadataFromMaybeManagedMetadata.spec.ts @@ -27,7 +27,6 @@ describe(buildManagedMetadataFromMaybeManagedMetadata.name, () => { name: 'name-fixture', optional: true, tags: new Map(), - targetName: 'target-name-fixture', }; kindFixture = ClassElementMetadataKind.singleInjection; @@ -57,7 +56,6 @@ describe(buildManagedMetadataFromMaybeManagedMetadata.name, () => { name: metadataFixture.name, optional: metadataFixture.optional, tags: metadataFixture.tags, - targetName: metadataFixture.targetName, value: serviceIdentifierFixture, }; diff --git a/packages/container/libraries/core/src/metadata/calculations/buildMaybeClassElementMetadataFromMaybeClassElementMetadata.spec.ts b/packages/container/libraries/core/src/metadata/calculations/buildMaybeClassElementMetadataFromMaybeClassElementMetadata.spec.ts index 7af393e9..3171041d 100644 --- a/packages/container/libraries/core/src/metadata/calculations/buildMaybeClassElementMetadataFromMaybeClassElementMetadata.spec.ts +++ b/packages/container/libraries/core/src/metadata/calculations/buildMaybeClassElementMetadataFromMaybeClassElementMetadata.spec.ts @@ -72,7 +72,6 @@ describe( name: undefined, optional: false, tags: new Map([['foo', 'bar']]), - targetName: undefined, value: 'service-identifier', }; updateMetadataMock = jest.fn(); diff --git a/packages/container/libraries/core/src/metadata/calculations/buildUnmanagedMetadataFromMaybeManagedMetadata.spec.ts b/packages/container/libraries/core/src/metadata/calculations/buildUnmanagedMetadataFromMaybeManagedMetadata.spec.ts index 41b401d1..1b227e0b 100644 --- a/packages/container/libraries/core/src/metadata/calculations/buildUnmanagedMetadataFromMaybeManagedMetadata.spec.ts +++ b/packages/container/libraries/core/src/metadata/calculations/buildUnmanagedMetadataFromMaybeManagedMetadata.spec.ts @@ -22,7 +22,6 @@ describe(buildUnmanagedMetadataFromMaybeManagedMetadata.name, () => { name: 'name-fixture', optional: false, tags: new Map(), - targetName: undefined, }, ], [ @@ -32,7 +31,6 @@ describe(buildUnmanagedMetadataFromMaybeManagedMetadata.name, () => { name: undefined, optional: true, tags: new Map(), - targetName: undefined, }, ], [ @@ -42,17 +40,6 @@ describe(buildUnmanagedMetadataFromMaybeManagedMetadata.name, () => { name: undefined, optional: false, tags: new Map([['foo', 'bar']]), - targetName: undefined, - }, - ], - [ - 'with targetName', - { - kind: MaybeClassElementMetadataKind.unknown, - name: undefined, - optional: false, - tags: new Map(), - targetName: 'target-name-fixture', }, ], ])( @@ -112,7 +99,6 @@ describe(buildUnmanagedMetadataFromMaybeManagedMetadata.name, () => { name: undefined, optional: false, tags: new Map(), - targetName: undefined, }; }); diff --git a/packages/container/libraries/core/src/metadata/calculations/buildUnmanagedMetadataFromMaybeManagedMetadata.ts b/packages/container/libraries/core/src/metadata/calculations/buildUnmanagedMetadataFromMaybeManagedMetadata.ts index 42b153b8..943d1622 100644 --- a/packages/container/libraries/core/src/metadata/calculations/buildUnmanagedMetadataFromMaybeManagedMetadata.ts +++ b/packages/container/libraries/core/src/metadata/calculations/buildUnmanagedMetadataFromMaybeManagedMetadata.ts @@ -25,9 +25,6 @@ function hasManagedMetadata( metadata: MaybeManagedClassElementMetadata | ManagedClassElementMetadata, ): boolean { return ( - metadata.name !== undefined || - metadata.optional || - metadata.tags.size > 0 || - metadata.targetName !== undefined + metadata.name !== undefined || metadata.optional || metadata.tags.size > 0 ); } diff --git a/packages/container/libraries/core/src/metadata/calculations/getExtendedConstructorArguments.spec.ts b/packages/container/libraries/core/src/metadata/calculations/getExtendedConstructorArguments.spec.ts index 70c115b8..6470553c 100644 --- a/packages/container/libraries/core/src/metadata/calculations/getExtendedConstructorArguments.spec.ts +++ b/packages/container/libraries/core/src/metadata/calculations/getExtendedConstructorArguments.spec.ts @@ -60,7 +60,6 @@ describe(getExtendedConstructorArguments.name, () => { name: undefined, optional: false, tags: new Map(), - targetName: undefined, value: 'service-identifier-2', }, ], @@ -73,7 +72,6 @@ describe(getExtendedConstructorArguments.name, () => { name: undefined, optional: false, tags: new Map(), - targetName: undefined, value: 'service-identifier-1', }, ], @@ -98,7 +96,6 @@ describe(getExtendedConstructorArguments.name, () => { name: undefined, optional: false, tags: new Map(), - targetName: undefined, value: 'service-identifier-1', }, { @@ -106,7 +103,6 @@ describe(getExtendedConstructorArguments.name, () => { name: undefined, optional: false, tags: new Map(), - targetName: undefined, value: 'service-identifier-2', }, ]); diff --git a/packages/container/libraries/core/src/metadata/calculations/getExtendedProperties.spec.ts b/packages/container/libraries/core/src/metadata/calculations/getExtendedProperties.spec.ts index 31c4de88..59b7bfc4 100644 --- a/packages/container/libraries/core/src/metadata/calculations/getExtendedProperties.spec.ts +++ b/packages/container/libraries/core/src/metadata/calculations/getExtendedProperties.spec.ts @@ -59,7 +59,6 @@ describe(getExtendedProperties.name, () => { name: undefined, optional: false, tags: new Map(), - targetName: undefined, value: 'base-service-identifier-1', }, ], @@ -70,7 +69,6 @@ describe(getExtendedProperties.name, () => { name: undefined, optional: false, tags: new Map(), - targetName: undefined, value: 'base-service-identifier-2', }, ], @@ -86,7 +84,6 @@ describe(getExtendedProperties.name, () => { name: undefined, optional: false, tags: new Map(), - targetName: undefined, value: 'service-identifier-1', }, ], @@ -115,7 +112,6 @@ describe(getExtendedProperties.name, () => { name: undefined, optional: false, tags: new Map(), - targetName: undefined, value: 'service-identifier-1', }, ], @@ -126,7 +122,6 @@ describe(getExtendedProperties.name, () => { name: undefined, optional: false, tags: new Map(), - targetName: undefined, value: 'base-service-identifier-2', }, ], 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 f3dbc810..1c9821c9 100644 --- a/packages/container/libraries/core/src/metadata/calculations/throwAtInvalidClassMetadata.spec.ts +++ b/packages/container/libraries/core/src/metadata/calculations/throwAtInvalidClassMetadata.spec.ts @@ -71,7 +71,6 @@ This might be caused by one of the following reasons: name: undefined, optional: false, tags: new Map(), - targetName: undefined, }; constructorClassMetadata[invalidConstructorIndex] = 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 e103f7b2..d63948b6 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 @@ -40,7 +40,6 @@ describe(inject.name, () => { name: undefined, optional: false, tags: new Map(), - targetName: undefined, value: 'firstParam', }, { @@ -48,7 +47,6 @@ describe(inject.name, () => { name: undefined, optional: false, tags: new Map(), - targetName: undefined, value: 'secondParam', }, ], @@ -64,7 +62,6 @@ describe(inject.name, () => { name: undefined, optional: false, tags: new Map(), - targetName: undefined, value: 'bar', }, ], @@ -75,7 +72,6 @@ describe(inject.name, () => { name: undefined, optional: false, tags: new Map(), - targetName: undefined, value: 'baz', }, ], 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 1e7f08a9..7c74ca5a 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 @@ -107,7 +107,6 @@ describe(injectFrom.name, () => { name: undefined, optional: false, tags: new Map(), - targetName: undefined, value: constructorArgumentServiceId, }, ], @@ -123,7 +122,6 @@ describe(injectFrom.name, () => { name: undefined, optional: false, tags: new Map(), - targetName: undefined, value: propertyServiceId, }, ], @@ -238,7 +236,6 @@ describe(injectFrom.name, () => { name: undefined, optional: false, tags: new Map(), - targetName: undefined, value: 'barParam-param-child', }; expectedConstructorArguments[2] = { @@ -246,7 +243,6 @@ describe(injectFrom.name, () => { name: undefined, optional: false, tags: new Map(), - targetName: undefined, value: 'bazParam-param-child', }; @@ -255,7 +251,6 @@ describe(injectFrom.name, () => { name: undefined, optional: false, tags: new Map(), - targetName: undefined, value: 'bar-property-child', }; @@ -264,7 +259,6 @@ describe(injectFrom.name, () => { name: undefined, optional: false, tags: new Map(), - targetName: undefined, value: 'baz-property-child', }; @@ -375,7 +369,6 @@ describe(injectFrom.name, () => { name: undefined, optional: false, tags: new Map(), - targetName: undefined, value: 'sample-param', }, ], @@ -391,7 +384,6 @@ describe(injectFrom.name, () => { name: undefined, optional: false, tags: new Map(), - targetName: undefined, value: 'sample-service', }, ], @@ -445,7 +437,6 @@ describe(injectFrom.name, () => { name: undefined, optional: false, tags: new Map(), - targetName: undefined, value: 'sample-param', }, ], @@ -461,7 +452,6 @@ describe(injectFrom.name, () => { name: undefined, optional: false, tags: new Map(), - targetName: undefined, value: 'sample-service', }, ], @@ -533,7 +523,6 @@ describe(injectFrom.name, () => { name: undefined, optional: false, tags: new Map(), - targetName: undefined, value: 'fooParam-param-base', }, { @@ -541,7 +530,6 @@ describe(injectFrom.name, () => { name: undefined, optional: false, tags: new Map(), - targetName: undefined, value: 'barParam-param-child', }, { @@ -549,7 +537,6 @@ describe(injectFrom.name, () => { name: undefined, optional: false, tags: new Map(), - targetName: undefined, value: 'bazParam-param-child', }, ], @@ -565,7 +552,6 @@ describe(injectFrom.name, () => { name: undefined, optional: false, tags: new Map(), - targetName: undefined, value: 'foo-property-base', }, ], @@ -576,7 +562,6 @@ describe(injectFrom.name, () => { name: undefined, optional: false, tags: new Map(), - targetName: undefined, value: 'bar-property-child', }, ], @@ -587,7 +572,6 @@ describe(injectFrom.name, () => { name: undefined, optional: false, tags: new Map(), - targetName: undefined, value: 'baz-property-child', }, ], 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 365754f1..eb5e9e51 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 @@ -40,7 +40,6 @@ describe(multiInject.name, () => { name: undefined, optional: false, tags: new Map(), - targetName: undefined, value: 'firstParam', }, { @@ -48,7 +47,6 @@ describe(multiInject.name, () => { name: undefined, optional: false, tags: new Map(), - targetName: undefined, value: 'secondParam', }, ], @@ -64,7 +62,6 @@ describe(multiInject.name, () => { name: undefined, optional: false, tags: new Map(), - targetName: undefined, value: 'bar', }, ], @@ -75,7 +72,6 @@ describe(multiInject.name, () => { name: undefined, optional: false, tags: new Map(), - targetName: undefined, value: 'baz', }, ], 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 487d4761..5705d090 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 @@ -40,14 +40,12 @@ describe(named.name, () => { name: 'firstParam', optional: false, tags: new Map(), - targetName: undefined, }, { kind: MaybeClassElementMetadataKind.unknown, name: 'secondParam', optional: false, tags: new Map(), - targetName: undefined, }, ], lifecycle: { @@ -62,7 +60,6 @@ describe(named.name, () => { name: 'bar', optional: false, tags: new Map(), - targetName: undefined, }, ], [ @@ -72,7 +69,6 @@ describe(named.name, () => { name: 'baz', optional: false, tags: new Map(), - targetName: undefined, }, ], ]), 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 fa35b9c4..63a8f15e 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 @@ -40,14 +40,12 @@ describe(optional.name, () => { name: undefined, optional: true, tags: new Map(), - targetName: undefined, }, { kind: MaybeClassElementMetadataKind.unknown, name: undefined, optional: true, tags: new Map(), - targetName: undefined, }, ], lifecycle: { @@ -62,7 +60,6 @@ describe(optional.name, () => { name: undefined, optional: true, tags: new Map(), - targetName: undefined, }, ], [ @@ -72,7 +69,6 @@ describe(optional.name, () => { name: undefined, optional: true, tags: new Map(), - targetName: undefined, }, ], ]), 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 0c6dd682..f0a661c4 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 @@ -40,14 +40,12 @@ describe(tagged.name, () => { name: undefined, optional: false, tags: new Map([['firstParam', 'firstParam-value']]), - targetName: undefined, }, { kind: MaybeClassElementMetadataKind.unknown, name: undefined, optional: false, tags: new Map([['secondParam', 'secondParam-value']]), - targetName: undefined, }, ], lifecycle: { @@ -62,7 +60,6 @@ describe(tagged.name, () => { name: undefined, optional: false, tags: new Map([['bar', 'bar-value']]), - targetName: undefined, }, ], [ @@ -72,7 +69,6 @@ describe(tagged.name, () => { name: undefined, optional: false, tags: new Map([['baz', 'baz-value']]), - targetName: undefined, }, ], ]), 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 deleted file mode 100644 index f54fe862..00000000 --- a/packages/container/libraries/core/src/metadata/decorators/targetName.int.spec.ts +++ /dev/null @@ -1,85 +0,0 @@ -import { beforeAll, describe, expect, it } from '@jest/globals'; - -import 'reflect-metadata'; - -import { getReflectMetadata } from '@inversifyjs/reflect-metadata-utils'; - -import { classMetadataReflectKey } from '../../reflectMetadata/data/classMetadataReflectKey'; -import { MaybeClassElementMetadataKind } from '../models/MaybeClassElementMetadataKind'; -import { MaybeClassMetadata } from '../models/MaybeClassMetadata'; -import { targetName } from './targetName'; - -describe(targetName.name, () => { - describe('when called', () => { - let result: unknown; - - beforeAll(() => { - class Foo { - @targetName('bar') - public readonly bar!: string; - - @targetName('baz') - public readonly baz!: string; - - constructor( - @targetName('firstParam') - public firstParam: number, - @targetName('secondParam') - public secondParam: number, - ) {} - } - - result = getReflectMetadata(Foo, classMetadataReflectKey); - }); - - it('should return expected metadata', () => { - const expected: MaybeClassMetadata = { - constructorArguments: [ - { - kind: MaybeClassElementMetadataKind.unknown, - name: undefined, - optional: false, - tags: new Map(), - targetName: 'firstParam', - }, - { - kind: MaybeClassElementMetadataKind.unknown, - name: undefined, - optional: false, - tags: new Map(), - targetName: 'secondParam', - }, - ], - lifecycle: { - postConstructMethodName: undefined, - preDestroyMethodName: undefined, - }, - properties: new Map([ - [ - 'bar', - { - kind: MaybeClassElementMetadataKind.unknown, - name: undefined, - optional: false, - tags: new Map(), - targetName: 'bar', - }, - ], - [ - 'baz', - { - kind: MaybeClassElementMetadataKind.unknown, - name: undefined, - optional: false, - tags: new Map(), - targetName: 'baz', - }, - ], - ]), - scope: undefined, - }; - - expect(result).toStrictEqual(expected); - }); - }); -}); diff --git a/packages/container/libraries/core/src/metadata/decorators/targetName.spec.ts b/packages/container/libraries/core/src/metadata/decorators/targetName.spec.ts deleted file mode 100644 index 27a80948..00000000 --- a/packages/container/libraries/core/src/metadata/decorators/targetName.spec.ts +++ /dev/null @@ -1,373 +0,0 @@ -import { afterAll, beforeAll, describe, expect, it, jest } from '@jest/globals'; - -jest.mock('../actions/updateMetadataTargetName'); -jest.mock( - '../calculations/buildMaybeClassElementMetadataFromMaybeClassElementMetadata', -); -jest.mock('../calculations/handleInjectionError'); -jest.mock('./injectBase'); - -import { incrementPendingClassMetadataCount } from '../actions/incrementPendingClassMetadataCount'; -import { updateMetadataTargetName } from '../actions/updateMetadataTargetName'; -import { buildMaybeClassElementMetadataFromMaybeClassElementMetadata } from '../calculations/buildMaybeClassElementMetadataFromMaybeClassElementMetadata'; -import { handleInjectionError } from '../calculations/handleInjectionError'; -import { ManagedClassElementMetadata } from '../models/ManagedClassElementMetadata'; -import { MaybeClassElementMetadata } from '../models/MaybeClassElementMetadata'; -import { MaybeManagedClassElementMetadata } from '../models/MaybeManagedClassElementMetadata'; -import { injectBase } from './injectBase'; -import { targetName } from './targetName'; - -describe(targetName.name, () => { - let updateMetadataNameResultMock: jest.Mock< - ( - metadata: ManagedClassElementMetadata | MaybeManagedClassElementMetadata, - ) => ManagedClassElementMetadata | MaybeManagedClassElementMetadata - >; - - beforeAll(() => { - updateMetadataNameResultMock = jest.fn(); - - ( - updateMetadataTargetName as jest.Mock - ).mockReturnValue(updateMetadataNameResultMock); - }); - - describe('having a non undefined propertyKey and an undefined parameterIndex', () => { - let targetFixture: object; - let propertyKeyFixture: string | symbol; - - beforeAll(() => { - targetFixture = class {}; - propertyKeyFixture = 'property-key'; - }); - - describe('when called', () => { - let nameFixture: string; - let injectBaseDecoratorMock: jest.Mock< - ParameterDecorator & PropertyDecorator - > & - ParameterDecorator & - PropertyDecorator; - - let updateMetadataMock: jest.Mock< - ( - classElementMetadata: MaybeClassElementMetadata | undefined, - ) => ManagedClassElementMetadata | MaybeManagedClassElementMetadata - >; - - let result: unknown; - - beforeAll(() => { - nameFixture = 'name-fixture'; - injectBaseDecoratorMock = jest.fn() as jest.Mock< - ParameterDecorator & PropertyDecorator - > & - ParameterDecorator & - PropertyDecorator; - - updateMetadataMock = jest.fn(); - - ( - buildMaybeClassElementMetadataFromMaybeClassElementMetadata as jest.Mock< - typeof buildMaybeClassElementMetadataFromMaybeClassElementMetadata - > - ).mockReturnValueOnce(updateMetadataMock); - - (injectBase as jest.Mock).mockReturnValueOnce( - injectBaseDecoratorMock, - ); - - result = targetName(nameFixture)(targetFixture, propertyKeyFixture); - }); - - afterAll(() => { - jest.clearAllMocks(); - }); - - it('should call buildMaybeClassElementMetadataFromMaybeClassElementMetadata()', () => { - expect( - buildMaybeClassElementMetadataFromMaybeClassElementMetadata, - ).toHaveBeenCalledTimes(1); - expect( - buildMaybeClassElementMetadataFromMaybeClassElementMetadata, - ).toHaveBeenCalledWith(expect.any(Function)); - }); - - it('should call injectBase()', () => { - expect(injectBase).toHaveBeenCalledTimes(1); - expect(injectBase).toHaveBeenCalledWith( - updateMetadataMock, - incrementPendingClassMetadataCount, - ); - }); - - it('should call injectBaseDecorator()', () => { - expect(injectBaseDecoratorMock).toHaveBeenCalledTimes(1); - expect(injectBaseDecoratorMock).toHaveBeenCalledWith( - targetFixture, - propertyKeyFixture, - ); - }); - - it('should return undefined', () => { - expect(result).toBeUndefined(); - }); - }); - - describe('when called, and injectBase throws an Error', () => { - let nameFixture: string; - let errorFixture: Error; - let updateMetadataMock: jest.Mock< - ( - classElementMetadata: MaybeClassElementMetadata | undefined, - ) => ManagedClassElementMetadata | MaybeManagedClassElementMetadata - >; - - let result: unknown; - - beforeAll(() => { - nameFixture = 'name-fixture'; - errorFixture = new Error('message-error-fixture'); - updateMetadataMock = jest.fn(); - - ( - buildMaybeClassElementMetadataFromMaybeClassElementMetadata as jest.Mock< - typeof buildMaybeClassElementMetadataFromMaybeClassElementMetadata - > - ).mockReturnValueOnce(updateMetadataMock); - - (injectBase as jest.Mock).mockImplementation( - (): never => { - throw errorFixture; - }, - ); - - ( - handleInjectionError as jest.Mock - ).mockImplementation( - ( - _target: object, - _propertyKey: string | symbol | undefined, - _parameterIndex: number | undefined, - error: unknown, - ): never => { - throw error; - }, - ); - - try { - targetName(nameFixture)(targetFixture, propertyKeyFixture); - } catch (error: unknown) { - result = error; - } - }); - - afterAll(() => { - jest.clearAllMocks(); - }); - - it('should call buildMaybeClassElementMetadataFromMaybeClassElementMetadata()', () => { - expect( - buildMaybeClassElementMetadataFromMaybeClassElementMetadata, - ).toHaveBeenCalledTimes(1); - expect( - buildMaybeClassElementMetadataFromMaybeClassElementMetadata, - ).toHaveBeenCalledWith(expect.any(Function)); - }); - - it('should call injectBase()', () => { - expect(injectBase).toHaveBeenCalledTimes(1); - expect(injectBase).toHaveBeenCalledWith( - updateMetadataMock, - incrementPendingClassMetadataCount, - ); - }); - - it('should throw handleInjectionError()', () => { - expect(handleInjectionError).toHaveBeenCalledTimes(1); - expect(handleInjectionError).toHaveBeenCalledWith( - targetFixture, - propertyKeyFixture, - undefined, - errorFixture, - ); - }); - - it('should throw an Error', () => { - expect(result).toBe(errorFixture); - }); - }); - }); - - describe('having an undefined propertyKey and an non undefined parameterIndex', () => { - let targetFixture: object; - let paramIndexFixture: number; - - beforeAll(() => { - targetFixture = class {}; - paramIndexFixture = 0; - }); - - describe('when called', () => { - let nameFixture: string; - let injectBaseDecoratorMock: jest.Mock< - ParameterDecorator & PropertyDecorator - > & - ParameterDecorator & - PropertyDecorator; - - let updateMetadataMock: jest.Mock< - ( - classElementMetadata: MaybeClassElementMetadata | undefined, - ) => ManagedClassElementMetadata | MaybeManagedClassElementMetadata - >; - - let result: unknown; - - beforeAll(() => { - nameFixture = 'name-fixture'; - injectBaseDecoratorMock = jest.fn() as jest.Mock< - ParameterDecorator & PropertyDecorator - > & - ParameterDecorator & - PropertyDecorator; - - updateMetadataMock = jest.fn(); - - ( - buildMaybeClassElementMetadataFromMaybeClassElementMetadata as jest.Mock< - typeof buildMaybeClassElementMetadataFromMaybeClassElementMetadata - > - ).mockReturnValueOnce(updateMetadataMock); - - (injectBase as jest.Mock).mockReturnValueOnce( - injectBaseDecoratorMock, - ); - - result = targetName(nameFixture)( - targetFixture, - undefined, - paramIndexFixture, - ); - }); - - afterAll(() => { - jest.clearAllMocks(); - }); - - it('should call buildMaybeClassElementMetadataFromMaybeClassElementMetadata()', () => { - expect( - buildMaybeClassElementMetadataFromMaybeClassElementMetadata, - ).toHaveBeenCalledTimes(1); - expect( - buildMaybeClassElementMetadataFromMaybeClassElementMetadata, - ).toHaveBeenCalledWith(expect.any(Function)); - }); - - it('should call injectBase()', () => { - expect(injectBase).toHaveBeenCalledTimes(1); - expect(injectBase).toHaveBeenCalledWith( - updateMetadataMock, - incrementPendingClassMetadataCount, - ); - }); - - it('should call injectBaseDecorator()', () => { - expect(injectBaseDecoratorMock).toHaveBeenCalledTimes(1); - expect(injectBaseDecoratorMock).toHaveBeenCalledWith( - targetFixture, - undefined, - paramIndexFixture, - ); - }); - - it('should return undefined', () => { - expect(result).toBeUndefined(); - }); - }); - - describe('when called, and injectBase throws an Error', () => { - let nameFixture: string; - let errorFixture: Error; - let updateMetadataMock: jest.Mock< - ( - classElementMetadata: MaybeClassElementMetadata | undefined, - ) => ManagedClassElementMetadata | MaybeManagedClassElementMetadata - >; - - let result: unknown; - - beforeAll(() => { - nameFixture = 'name-fixture'; - errorFixture = new Error('message-error-fixture'); - updateMetadataMock = jest.fn(); - - ( - buildMaybeClassElementMetadataFromMaybeClassElementMetadata as jest.Mock< - typeof buildMaybeClassElementMetadataFromMaybeClassElementMetadata - > - ).mockReturnValueOnce(updateMetadataMock); - - (injectBase as jest.Mock).mockImplementation( - (): never => { - throw errorFixture; - }, - ); - - ( - handleInjectionError as jest.Mock - ).mockImplementation( - ( - _target: object, - _propertyKey: string | symbol | undefined, - _parameterIndex: number | undefined, - error: unknown, - ): never => { - throw error; - }, - ); - - try { - targetName(nameFixture)(targetFixture, undefined, paramIndexFixture); - } catch (error: unknown) { - result = error; - } - }); - - afterAll(() => { - jest.clearAllMocks(); - }); - - it('should call buildMaybeClassElementMetadataFromMaybeClassElementMetadata()', () => { - expect( - buildMaybeClassElementMetadataFromMaybeClassElementMetadata, - ).toHaveBeenCalledTimes(1); - expect( - buildMaybeClassElementMetadataFromMaybeClassElementMetadata, - ).toHaveBeenCalledWith(expect.any(Function)); - }); - - it('should call injectBase()', () => { - expect(injectBase).toHaveBeenCalledTimes(1); - expect(injectBase).toHaveBeenCalledWith( - updateMetadataMock, - incrementPendingClassMetadataCount, - ); - }); - - it('should throw handleInjectionError()', () => { - expect(handleInjectionError).toHaveBeenCalledTimes(1); - expect(handleInjectionError).toHaveBeenCalledWith( - targetFixture, - undefined, - paramIndexFixture, - errorFixture, - ); - }); - - it('should throw an Error', () => { - expect(result).toBe(errorFixture); - }); - }); - }); -}); diff --git a/packages/container/libraries/core/src/metadata/decorators/targetName.ts b/packages/container/libraries/core/src/metadata/decorators/targetName.ts deleted file mode 100644 index 4b18aacb..00000000 --- a/packages/container/libraries/core/src/metadata/decorators/targetName.ts +++ /dev/null @@ -1,43 +0,0 @@ -import { incrementPendingClassMetadataCount } from '../actions/incrementPendingClassMetadataCount'; -import { updateMetadataTargetName } from '../actions/updateMetadataTargetName'; -import { buildMaybeClassElementMetadataFromMaybeClassElementMetadata } from '../calculations/buildMaybeClassElementMetadataFromMaybeClassElementMetadata'; -import { handleInjectionError } from '../calculations/handleInjectionError'; -import { ManagedClassElementMetadata } from '../models/ManagedClassElementMetadata'; -import { MaybeClassElementMetadata } from '../models/MaybeClassElementMetadata'; -import { MaybeManagedClassElementMetadata } from '../models/MaybeManagedClassElementMetadata'; -import { MetadataTargetName } from '../models/MetadataTargetName'; -import { injectBase } from './injectBase'; - -export function targetName( - targetName: MetadataTargetName, -): ParameterDecorator & PropertyDecorator { - const updateMetadata: ( - metadata: MaybeClassElementMetadata | undefined, - ) => ManagedClassElementMetadata | MaybeManagedClassElementMetadata = - buildMaybeClassElementMetadataFromMaybeClassElementMetadata( - updateMetadataTargetName(targetName), - ); - - return ( - target: object, - propertyKey: string | symbol | undefined, - parameterIndex?: number, - ): void => { - try { - if (parameterIndex === undefined) { - injectBase(updateMetadata, incrementPendingClassMetadataCount)( - target, - propertyKey as string | symbol, - ); - } else { - injectBase(updateMetadata, incrementPendingClassMetadataCount)( - target, - propertyKey, - parameterIndex, - ); - } - } catch (error: unknown) { - handleInjectionError(target, propertyKey, parameterIndex, error); - } - }; -} diff --git a/packages/container/libraries/core/src/metadata/fixtures/ManagedClassElementMetadataFixtures.ts b/packages/container/libraries/core/src/metadata/fixtures/ManagedClassElementMetadataFixtures.ts index a60930c4..054aae9d 100644 --- a/packages/container/libraries/core/src/metadata/fixtures/ManagedClassElementMetadataFixtures.ts +++ b/packages/container/libraries/core/src/metadata/fixtures/ManagedClassElementMetadataFixtures.ts @@ -8,7 +8,6 @@ export class ManagedClassElementMetadataFixtures { name: undefined, optional: false, tags: new Map(), - targetName: undefined, value: Symbol(), }; } diff --git a/packages/container/libraries/core/src/metadata/fixtures/MaybeManagedClassElementMetadataFixtures.ts b/packages/container/libraries/core/src/metadata/fixtures/MaybeManagedClassElementMetadataFixtures.ts index 813d66a8..93bcdac4 100644 --- a/packages/container/libraries/core/src/metadata/fixtures/MaybeManagedClassElementMetadataFixtures.ts +++ b/packages/container/libraries/core/src/metadata/fixtures/MaybeManagedClassElementMetadataFixtures.ts @@ -8,7 +8,6 @@ export class MaybeManagedClassElementMetadataFixtures { name: undefined, optional: false, tags: new Map(), - targetName: undefined, }; } } diff --git a/packages/container/libraries/core/src/metadata/models/ManagedClassElementMetadata.ts b/packages/container/libraries/core/src/metadata/models/ManagedClassElementMetadata.ts index 5387ee31..e3d2e517 100644 --- a/packages/container/libraries/core/src/metadata/models/ManagedClassElementMetadata.ts +++ b/packages/container/libraries/core/src/metadata/models/ManagedClassElementMetadata.ts @@ -4,7 +4,6 @@ import { BaseClassElementMetadata } from './BaseClassElementMetadata'; import { ClassElementMetadataKind } from './ClassElementMetadataKind'; import { MetadataName } from './MetadataName'; import { MetadataTag } from './MetadataTag'; -import { MetadataTargetName } from './MetadataTargetName'; export interface ManagedClassElementMetadata extends BaseClassElementMetadata< @@ -15,6 +14,5 @@ export interface ManagedClassElementMetadata name: MetadataName | undefined; optional: boolean; tags: Map; - targetName: MetadataTargetName | undefined; value: ServiceIdentifier | LazyServiceIdentifier; } diff --git a/packages/container/libraries/core/src/metadata/models/MaybeManagedClassElementMetadata.ts b/packages/container/libraries/core/src/metadata/models/MaybeManagedClassElementMetadata.ts index 6ac2684b..b890a925 100644 --- a/packages/container/libraries/core/src/metadata/models/MaybeManagedClassElementMetadata.ts +++ b/packages/container/libraries/core/src/metadata/models/MaybeManagedClassElementMetadata.ts @@ -2,12 +2,10 @@ import { BaseClassElementMetadata } from './BaseClassElementMetadata'; import { MaybeClassElementMetadataKind } from './MaybeClassElementMetadataKind'; import { MetadataName } from './MetadataName'; import { MetadataTag } from './MetadataTag'; -import { MetadataTargetName } from './MetadataTargetName'; export interface MaybeManagedClassElementMetadata extends BaseClassElementMetadata { name: MetadataName | undefined; optional: boolean; tags: Map; - targetName: MetadataTargetName | undefined; } diff --git a/packages/container/libraries/core/src/metadata/models/MetadataTargetName.ts b/packages/container/libraries/core/src/metadata/models/MetadataTargetName.ts deleted file mode 100644 index 51c5f33b..00000000 --- a/packages/container/libraries/core/src/metadata/models/MetadataTargetName.ts +++ /dev/null @@ -1 +0,0 @@ -export type MetadataTargetName = string; 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 29e24447..027b65e4 100644 --- a/packages/container/libraries/core/src/planning/calculations/plan.spec.ts +++ b/packages/container/libraries/core/src/planning/calculations/plan.spec.ts @@ -399,7 +399,6 @@ describe(plan.name, () => { name: undefined, optional: false, tags: new Map(), - targetName: undefined, value: 'constructor-param-service-id', }; propertyKey = 'property-key'; @@ -408,7 +407,6 @@ describe(plan.name, () => { name: undefined, optional: false, tags: new Map(), - targetName: undefined, value: 'property-param-service-id', }; classMetadataFixture = { @@ -607,7 +605,6 @@ describe(plan.name, () => { name: undefined, optional: false, tags: new Map(), - targetName: undefined, value: new LazyServiceIdentifier( () => 'constructor-param-service-id', ), @@ -618,7 +615,6 @@ describe(plan.name, () => { name: undefined, optional: false, tags: new Map(), - targetName: undefined, value: new LazyServiceIdentifier(() => 'property-param-service-id'), }; classMetadataFixture = { @@ -823,7 +819,6 @@ describe(plan.name, () => { name: undefined, optional: false, tags: new Map(), - targetName: undefined, value: 'constructor-param-service-id', }; propertyKey = 'property-key'; @@ -832,7 +827,6 @@ describe(plan.name, () => { name: undefined, optional: false, tags: new Map(), - targetName: undefined, value: 'property-param-service-id', }; classMetadataFixture = { diff --git a/packages/container/libraries/core/src/resolution/actions/setInstanceProperties.spec.ts b/packages/container/libraries/core/src/resolution/actions/setInstanceProperties.spec.ts index 5e304578..0b404894 100644 --- a/packages/container/libraries/core/src/resolution/actions/setInstanceProperties.spec.ts +++ b/packages/container/libraries/core/src/resolution/actions/setInstanceProperties.spec.ts @@ -138,7 +138,6 @@ describe(setInstanceProperties.name, () => { name: undefined, optional: false, tags: new Map(), - targetName: undefined, value: 'service-id', }, ], diff --git a/packages/container/libraries/core/src/resolution/actions/setInstanceProperties.ts b/packages/container/libraries/core/src/resolution/actions/setInstanceProperties.ts index 46d95675..02d6dccc 100644 --- a/packages/container/libraries/core/src/resolution/actions/setInstanceProperties.ts +++ b/packages/container/libraries/core/src/resolution/actions/setInstanceProperties.ts @@ -37,15 +37,12 @@ export function setInstanceProperties( } if (metadata.kind !== ClassElementMetadataKind.unmanaged) { - const propertyName: string | symbol = - metadata.targetName ?? propertyKey; + instance[propertyKey] = resolveServiceNode(params, propertyNode); - instance[propertyName] = resolveServiceNode(params, propertyNode); - - if (isPromise(instance[propertyName])) { + if (isPromise(instance[propertyKey])) { propertyAssignmentPromises.push( (async () => { - instance[propertyName] = await instance[propertyName]; + instance[propertyKey] = await instance[propertyKey]; })(), ); }