mirror of
https://github.com/nestjs/nest.git
synced 2026-02-22 23:41:40 +00:00
Compare commits
2 Commits
v10.4.17
...
fix/instan
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f273041594 | ||
|
|
da8ebded25 |
@@ -39,25 +39,36 @@ export class ListenerMetadataExplorer {
|
||||
const instancePrototype = Object.getPrototypeOf(instance);
|
||||
return this.metadataScanner
|
||||
.getAllMethodNames(instancePrototype)
|
||||
.map(method => this.exploreMethodMetadata(instancePrototype, method))
|
||||
.map(method =>
|
||||
this.exploreMethodMetadata(instance, instancePrototype, method),
|
||||
)
|
||||
.filter(metadata => metadata);
|
||||
}
|
||||
|
||||
public exploreMethodMetadata(
|
||||
instance: Controller,
|
||||
instancePrototype: object,
|
||||
methodKey: string,
|
||||
): EventOrMessageListenerDefinition {
|
||||
const targetCallback = instancePrototype[methodKey];
|
||||
const prototypeCallback = instancePrototype[methodKey];
|
||||
const handlerType = Reflect.getMetadata(
|
||||
PATTERN_HANDLER_METADATA,
|
||||
targetCallback,
|
||||
prototypeCallback,
|
||||
);
|
||||
if (isUndefined(handlerType)) {
|
||||
return;
|
||||
}
|
||||
const patterns = Reflect.getMetadata(PATTERN_METADATA, targetCallback);
|
||||
const transport = Reflect.getMetadata(TRANSPORT_METADATA, targetCallback);
|
||||
const extras = Reflect.getMetadata(PATTERN_EXTRAS_METADATA, targetCallback);
|
||||
const patterns = Reflect.getMetadata(PATTERN_METADATA, prototypeCallback);
|
||||
const transport = Reflect.getMetadata(
|
||||
TRANSPORT_METADATA,
|
||||
prototypeCallback,
|
||||
);
|
||||
const extras = Reflect.getMetadata(
|
||||
PATTERN_EXTRAS_METADATA,
|
||||
prototypeCallback,
|
||||
);
|
||||
|
||||
const targetCallback = instance[methodKey];
|
||||
return {
|
||||
methodKey,
|
||||
targetCallback,
|
||||
|
||||
@@ -71,6 +71,7 @@ describe('ListenerMetadataExplorer', () => {
|
||||
});
|
||||
it(`should return undefined when "handlerType" metadata is undefined`, () => {
|
||||
const metadata = instance.exploreMethodMetadata(
|
||||
test,
|
||||
Object.getPrototypeOf(test),
|
||||
'noPattern',
|
||||
);
|
||||
@@ -80,6 +81,7 @@ describe('ListenerMetadataExplorer', () => {
|
||||
describe('@MessagePattern', () => {
|
||||
it(`should return pattern properties when "handlerType" metadata is not undefined`, () => {
|
||||
const metadata = instance.exploreMethodMetadata(
|
||||
test,
|
||||
Object.getPrototypeOf(test),
|
||||
'testMessage',
|
||||
);
|
||||
@@ -96,6 +98,7 @@ describe('ListenerMetadataExplorer', () => {
|
||||
});
|
||||
it(`should return multiple patterns when more than one is declared`, () => {
|
||||
const metadata = instance.exploreMethodMetadata(
|
||||
test,
|
||||
Object.getPrototypeOf(test),
|
||||
'testMultipleMessage',
|
||||
);
|
||||
@@ -116,6 +119,7 @@ describe('ListenerMetadataExplorer', () => {
|
||||
describe('@EventPattern', () => {
|
||||
it(`should return pattern properties when "handlerType" metadata is not undefined`, () => {
|
||||
const metadata = instance.exploreMethodMetadata(
|
||||
test,
|
||||
Object.getPrototypeOf(test),
|
||||
'testEvent',
|
||||
);
|
||||
@@ -132,6 +136,7 @@ describe('ListenerMetadataExplorer', () => {
|
||||
});
|
||||
it(`should return multiple patterns when more than one is declared`, () => {
|
||||
const metadata = instance.exploreMethodMetadata(
|
||||
test,
|
||||
Object.getPrototypeOf(test),
|
||||
'testMultipleEvent',
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user