UNPKG

1.69 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.GatewayMetadataExplorer = void 0;
4const shared_utils_1 = require("@nestjs/common/utils/shared.utils");
5const constants_1 = require("./constants");
6class GatewayMetadataExplorer {
7 constructor(metadataScanner) {
8 this.metadataScanner = metadataScanner;
9 }
10 explore(instance) {
11 const instancePrototype = Object.getPrototypeOf(instance);
12 return this.metadataScanner
13 .getAllMethodNames(instancePrototype)
14 .map(method => this.exploreMethodMetadata(instancePrototype, method))
15 .filter(metadata => metadata);
16 }
17 exploreMethodMetadata(instancePrototype, methodName) {
18 const callback = instancePrototype[methodName];
19 const isMessageMapping = Reflect.getMetadata(constants_1.MESSAGE_MAPPING_METADATA, callback);
20 if ((0, shared_utils_1.isUndefined)(isMessageMapping)) {
21 return null;
22 }
23 const message = Reflect.getMetadata(constants_1.MESSAGE_METADATA, callback);
24 return {
25 callback,
26 message,
27 methodName,
28 };
29 }
30 *scanForServerHooks(instance) {
31 for (const propertyKey in instance) {
32 if ((0, shared_utils_1.isFunction)(propertyKey)) {
33 continue;
34 }
35 const property = String(propertyKey);
36 const isServer = Reflect.getMetadata(constants_1.GATEWAY_SERVER_METADATA, instance, property);
37 if (!(0, shared_utils_1.isUndefined)(isServer)) {
38 yield property;
39 }
40 }
41 }
42}
43exports.GatewayMetadataExplorer = GatewayMetadataExplorer;