@nestjstools/messaging
Version:
Simplifies asynchronous and synchronous message handling with support for buses, handlers, channels, and consumers. Build scalable, decoupled applications with ease and reliability.
69 lines • 3.33 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.MessagingExceptionListener = exports.MessagingNormalizer = exports.MessagingMiddleware = exports.MessageConsumer = exports.MessageBusFactory = exports.ChannelFactory = exports.MessageHandler = exports.MESSAGING_MESSAGE_METADATA = exports.MESSAGING_EXCEPTION_LISTENER_METADATA = exports.MESSAGING_NORMALIZER_METADATA = exports.MESSAGING_MIDDLEWARE_METADATA = exports.MESSAGE_CONSUMER_METADATA = exports.MESSAGE_BUS_FACTORY_METADATA = exports.CHANNEL_FACTORY_METADATA = exports.MESSAGE_HANDLER_METADATA = void 0;
exports.DenormalizeMessage = DenormalizeMessage;
exports.MESSAGE_HANDLER_METADATA = 'MESSAGE_HANDLER_METADATA';
exports.CHANNEL_FACTORY_METADATA = 'CHANNEL_FACTORY_METADATA';
exports.MESSAGE_BUS_FACTORY_METADATA = 'MESSAGE_BUS_FACTORY_METADATA';
exports.MESSAGE_CONSUMER_METADATA = 'MESSAGE_CONSUMER_METADATA';
exports.MESSAGING_MIDDLEWARE_METADATA = 'MESSAGING_MIDDLEWARE_METADATA';
exports.MESSAGING_NORMALIZER_METADATA = 'MESSAGING_NORMALIZER_METADATA';
exports.MESSAGING_EXCEPTION_LISTENER_METADATA = 'MESSAGING_EXCEPTION_LISTENER_METADATA';
exports.MESSAGING_MESSAGE_METADATA = 'MESSAGING_MESSAGE_METADATA';
const MessageHandler = (...routingKey) => {
return (target) => {
Reflect.defineMetadata(exports.MESSAGE_HANDLER_METADATA, routingKey, target);
};
};
exports.MessageHandler = MessageHandler;
const ChannelFactory = (channelConfig) => {
return (target) => {
Reflect.defineMetadata(exports.CHANNEL_FACTORY_METADATA, channelConfig, target);
};
};
exports.ChannelFactory = ChannelFactory;
const MessageBusFactory = (channel) => {
classValidator(channel, 'Channel');
return (target) => {
Reflect.defineMetadata(exports.MESSAGE_BUS_FACTORY_METADATA, channel, target);
};
};
exports.MessageBusFactory = MessageBusFactory;
const MessageConsumer = (channel) => {
classValidator(channel, 'Channel');
return (target) => {
Reflect.defineMetadata(exports.MESSAGE_CONSUMER_METADATA, channel, target);
};
};
exports.MessageConsumer = MessageConsumer;
const MessagingMiddleware = (name) => {
return (target) => {
Reflect.defineMetadata(exports.MESSAGING_MIDDLEWARE_METADATA, name ?? target.name, target);
};
};
exports.MessagingMiddleware = MessagingMiddleware;
const MessagingNormalizer = (name) => {
return (target) => {
Reflect.defineMetadata(exports.MESSAGING_NORMALIZER_METADATA, name ?? target.name, target);
};
};
exports.MessagingNormalizer = MessagingNormalizer;
const MessagingExceptionListener = () => {
return (target) => {
Reflect.defineMetadata(exports.MESSAGING_EXCEPTION_LISTENER_METADATA, target.name, target);
};
};
exports.MessagingExceptionListener = MessagingExceptionListener;
function DenormalizeMessage() {
return (target, propertyKey, parameterIndex) => {
const paramTypes = Reflect.getMetadata('design:paramtypes', target, propertyKey);
const type = paramTypes[parameterIndex];
Reflect.defineMetadata('message:type', type, target, propertyKey);
};
}
const classValidator = (value, type) => {
if (Object.getPrototypeOf(value).name !== type) {
throw new Error(`Given value must be instance of [${type}]`);
}
};
//# sourceMappingURL=decorator.js.map