1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.ListenerMetadataExplorer = void 0;
|
4 | const shared_utils_1 = require("@nestjs/common/utils/shared.utils");
|
5 | const constants_1 = require("./constants");
|
6 | const pattern_handler_enum_1 = require("./enums/pattern-handler.enum");
|
7 | class ListenerMetadataExplorer {
|
8 | constructor(metadataScanner) {
|
9 | this.metadataScanner = metadataScanner;
|
10 | }
|
11 | explore(instance) {
|
12 | const instancePrototype = Object.getPrototypeOf(instance);
|
13 | return this.metadataScanner.scanFromPrototype(instance, instancePrototype, method => this.exploreMethodMetadata(instancePrototype, method));
|
14 | }
|
15 | exploreMethodMetadata(instancePrototype, methodKey) {
|
16 | const targetCallback = instancePrototype[methodKey];
|
17 | const handlerType = Reflect.getMetadata(constants_1.PATTERN_HANDLER_METADATA, targetCallback);
|
18 | if ((0, shared_utils_1.isUndefined)(handlerType)) {
|
19 | return;
|
20 | }
|
21 | const patterns = Reflect.getMetadata(constants_1.PATTERN_METADATA, targetCallback);
|
22 | const transport = Reflect.getMetadata(constants_1.TRANSPORT_METADATA, targetCallback);
|
23 | const extras = Reflect.getMetadata(constants_1.PATTERN_EXTRAS_METADATA, targetCallback);
|
24 | return {
|
25 | methodKey,
|
26 | targetCallback,
|
27 | patterns,
|
28 | transport,
|
29 | extras,
|
30 | isEventHandler: handlerType === pattern_handler_enum_1.PatternHandler.EVENT,
|
31 | };
|
32 | }
|
33 | *scanForClientHooks(instance) {
|
34 | for (const propertyKey in instance) {
|
35 | if ((0, shared_utils_1.isFunction)(propertyKey)) {
|
36 | continue;
|
37 | }
|
38 | const property = String(propertyKey);
|
39 | const isClient = Reflect.getMetadata(constants_1.CLIENT_METADATA, instance, property);
|
40 | if ((0, shared_utils_1.isUndefined)(isClient)) {
|
41 | continue;
|
42 | }
|
43 | const metadata = Reflect.getMetadata(constants_1.CLIENT_CONFIGURATION_METADATA, instance, property);
|
44 | yield { property, metadata };
|
45 | }
|
46 | }
|
47 | }
|
48 | exports.ListenerMetadataExplorer = ListenerMetadataExplorer;
|