1.58 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.EventPattern = void 0;
4const shared_utils_1 = require("@nestjs/common/utils/shared.utils");
5const constants_1 = require("../constants");
6const pattern_handler_enum_1 = require("../enums/pattern-handler.enum");
7/**
8 * Subscribes to incoming events which fulfils chosen pattern.
9 *
10 * @publicApi
11 */
12const EventPattern = (metadata, transportOrExtras, maybeExtras) => {
13 let transport;
14 let extras;
15 if (((0, shared_utils_1.isNumber)(transportOrExtras) || (0, shared_utils_1.isSymbol)(transportOrExtras)) &&
16 (0, shared_utils_1.isNil)(maybeExtras)) {
17 transport = transportOrExtras;
18 }
19 else if ((0, shared_utils_1.isObject)(transportOrExtras) && (0, shared_utils_1.isNil)(maybeExtras)) {
20 extras = transportOrExtras;
21 }
22 else {
23 transport = transportOrExtras;
24 extras = maybeExtras;
25 }
26 return (target, key, descriptor) => {
27 Reflect.defineMetadata(constants_1.PATTERN_METADATA, [].concat(metadata), descriptor.value);
28 Reflect.defineMetadata(constants_1.PATTERN_HANDLER_METADATA, pattern_handler_enum_1.PatternHandler.EVENT, descriptor.value);
29 Reflect.defineMetadata(constants_1.TRANSPORT_METADATA, transport, descriptor.value);
30 Reflect.defineMetadata(constants_1.PATTERN_EXTRAS_METADATA, {
31 ...Reflect.getMetadata(constants_1.PATTERN_EXTRAS_METADATA, descriptor.value),
32 ...extras,
33 }, descriptor.value);
34 return descriptor;
35 };
36};
37exports.EventPattern = EventPattern;