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
|
14 | .getAllMethodNames(instancePrototype)
|
15 | .map(method => this.exploreMethodMetadata(instancePrototype, method))
|
16 | .filter(metadata => metadata);
|
17 | }
|
18 | exploreMethodMetadata(instancePrototype, methodKey) {
|
19 | const targetCallback = instancePrototype[methodKey];
|
20 | const handlerType = Reflect.getMetadata(constants_1.PATTERN_HANDLER_METADATA, targetCallback);
|
21 | if ((0, shared_utils_1.isUndefined)(handlerType)) {
|
22 | return;
|
23 | }
|
24 | const patterns = Reflect.getMetadata(constants_1.PATTERN_METADATA, targetCallback);
|
25 | const transport = Reflect.getMetadata(constants_1.TRANSPORT_METADATA, targetCallback);
|
26 | const extras = Reflect.getMetadata(constants_1.PATTERN_EXTRAS_METADATA, targetCallback);
|
27 | return {
|
28 | methodKey,
|
29 | targetCallback,
|
30 | patterns,
|
31 | transport,
|
32 | extras,
|
33 | isEventHandler: handlerType === pattern_handler_enum_1.PatternHandler.EVENT,
|
34 | };
|
35 | }
|
36 | *scanForClientHooks(instance) {
|
37 | for (const propertyKey in instance) {
|
38 | if ((0, shared_utils_1.isFunction)(propertyKey)) {
|
39 | continue;
|
40 | }
|
41 | const property = String(propertyKey);
|
42 | const isClient = Reflect.getMetadata(constants_1.CLIENT_METADATA, instance, property);
|
43 | if ((0, shared_utils_1.isUndefined)(isClient)) {
|
44 | continue;
|
45 | }
|
46 | const metadata = Reflect.getMetadata(constants_1.CLIENT_CONFIGURATION_METADATA, instance, property);
|
47 | yield { property, metadata };
|
48 | }
|
49 | }
|
50 | }
|
51 | exports.ListenerMetadataExplorer = ListenerMetadataExplorer;
|