Skip to content

Commit

Permalink
Merge pull request #193 from inversify/feat/update-class-metadata-wit…
Browse files Browse the repository at this point in the history
…h-scope

Update ClassMetadata with scope
  • Loading branch information
notaphplover authored Dec 16, 2024
2 parents a7c0cfa + 78009ee commit ea78d04
Show file tree
Hide file tree
Showing 25 changed files with 71 additions and 64 deletions.
5 changes: 5 additions & 0 deletions .changeset/short-ads-kick.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@inversifyjs/core": minor
---

Updated `ClassMetadata` with `scope`.
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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;
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -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();
});

Expand All @@ -40,6 +34,7 @@ describe(updateMaybeClassMetadataPostConstructor.name, () => {
preDestroyMethodName: undefined,
},
properties: new Map(),
scope: undefined,
};

expect(result).toStrictEqual(expected);
Expand All @@ -59,6 +54,7 @@ describe(updateMaybeClassMetadataPostConstructor.name, () => {
preDestroyMethodName: undefined,
},
properties: new Map(),
scope: undefined,
};
methodNameFixture = Symbol();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ describe(updateMaybeClassMetadataPreDestroy.name, () => {
preDestroyMethodName: undefined,
},
properties: new Map(),
scope: undefined,
};
methodNameFixture = Symbol();
});
Expand All @@ -40,6 +41,7 @@ describe(updateMaybeClassMetadataPreDestroy.name, () => {
preDestroyMethodName: methodNameFixture,
},
properties: new Map(),
scope: undefined,
};

expect(result).toStrictEqual(expected);
Expand All @@ -59,6 +61,7 @@ describe(updateMaybeClassMetadataPreDestroy.name, () => {
preDestroyMethodName: 'postConstructorMethodName',
},
properties: new Map(),
scope: undefined,
};
methodNameFixture = Symbol();
});
Expand Down
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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';
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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<typeof getReflectMetadata>
Expand Down Expand Up @@ -109,6 +103,7 @@ describe(getClassMetadata.name, () => {
preDestroyMethodName: undefined,
},
properties: new Map(),
scope: undefined,
};

(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ describe(getDefaultClassMetadata.name, () => {
preDestroyMethodName: undefined,
},
properties: new Map(),
scope: undefined,
};

expect(result).toStrictEqual(expected);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ export function getDefaultClassMetadata(): ClassMetadata {
preDestroyMethodName: undefined,
},
properties: new Map(),
scope: undefined,
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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', () => {
Expand Down Expand Up @@ -93,6 +87,7 @@ This might be caused by one of the following reasons:
preDestroyMethodName: undefined,
},
properties: new Map([[invalidPropertyName, maybeClassElementMetadata]]),
scope: undefined,
};
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ describe(inject.name, () => {
},
],
]),
scope: undefined,
};

expect(result).toStrictEqual(expected);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ describe(injectFrom.name, () => {
preDestroyMethodName: undefined,
},
properties: new Map(),
scope: undefined,
};

expect(result).toStrictEqual(expected);
Expand Down Expand Up @@ -127,6 +128,7 @@ describe(injectFrom.name, () => {
},
],
]),
scope: undefined,
};

expect(result).toStrictEqual(expected);
Expand Down Expand Up @@ -276,6 +278,7 @@ describe(injectFrom.name, () => {
['bar', expectedBarPropertyMetadata],
['baz', expectedBazPropertyMetadata],
]),
scope: undefined,
};

expect(result).toStrictEqual(expectedClassMetadata);
Expand Down Expand Up @@ -325,6 +328,7 @@ describe(injectFrom.name, () => {
preDestroyMethodName: undefined,
},
properties: new Map(),
scope: undefined,
};

expect(result).toStrictEqual(expected);
Expand Down Expand Up @@ -392,6 +396,7 @@ describe(injectFrom.name, () => {
},
],
]),
scope: undefined,
};

expect(result).toStrictEqual(expectedClassMetadata);
Expand Down Expand Up @@ -461,6 +466,7 @@ describe(injectFrom.name, () => {
},
],
]),
scope: undefined,
};
expect(result).toStrictEqual(expectedClassMetadata);
});
Expand Down Expand Up @@ -586,6 +592,7 @@ describe(injectFrom.name, () => {
},
],
]),
scope: undefined,
};

expect(result).toStrictEqual(expectedClassMetadata);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ function composeUpdateReflectMetadataCallback(
baseTypeClassMetadata,
typeMetadata,
),
scope: typeMetadata.scope,
});

return callback;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ describe(multiInject.name, () => {
},
],
]),
scope: undefined,
};

expect(result).toStrictEqual(expected);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ describe(named.name, () => {
},
],
]),
scope: undefined,
};

expect(result).toStrictEqual(expected);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ describe(optional.name, () => {
},
],
]),
scope: undefined,
};

expect(result).toStrictEqual(expected);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ describe(postConstruct.name, () => {
preDestroyMethodName: undefined,
},
properties: new Map(),
scope: undefined,
};

expect(result).toStrictEqual(expected);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ describe(preDestroy.name, () => {
preDestroyMethodName: 'initialize',
},
properties: new Map(),
scope: undefined,
};

expect(result).toStrictEqual(expected);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ describe(tagged.name, () => {
},
],
]),
scope: undefined,
};

expect(result).toStrictEqual(expected);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ describe(targetName.name, () => {
},
],
]),
scope: undefined,
};

expect(result).toStrictEqual(expected);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ describe(unmanaged.name, () => {
},
],
]),
scope: undefined,
};

expect(result).toStrictEqual(expected);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export class ClassMetadataFixtures {
preDestroyMethodName: undefined,
},
properties: new Map(),
scope: undefined,
};

return fixture;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { BindingScope } from '../../binding/models/BindingScope';
import { ClassElementMetadata } from './ClassElementMetadata';
import { ClassMetadataLifecycle } from './ClassMetadataLifecycle';

export interface ClassMetadata {
constructorArguments: ClassElementMetadata[];
lifecycle: ClassMetadataLifecycle;
properties: Map<string | symbol, ClassElementMetadata>;
scope: BindingScope | undefined;
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { BindingScope } from '../../binding/models/BindingScope';
import { ClassMetadataLifecycle } from './ClassMetadataLifecycle';
import { MaybeClassElementMetadata } from './MaybeClassElementMetadata';

export interface MaybeClassMetadata {
constructorArguments: MaybeClassElementMetadata[];
lifecycle: ClassMetadataLifecycle;
properties: Map<string | symbol, MaybeClassElementMetadata>;
scope: BindingScope | undefined;
}
Loading

0 comments on commit ea78d04

Please sign in to comment.