UNPKG

@nestjstools/messaging-bootstrap

Version:

A lightweight NestJS utility to bootstrap messaging-based apps with HTTP and microservice modes, built on top of @nestjstools/messaging.

61 lines 2.85 kB
"use strict"; var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; var AppWrapperModule_1; Object.defineProperty(exports, "__esModule", { value: true }); exports.MessagingBootstrap = void 0; const core_1 = require("@nestjs/core"); const common_1 = require("@nestjs/common"); const messaging_1 = require("@nestjstools/messaging"); const MESSAGING_IOC_CONFIG = 'messenger_CHANNELS'; let AppWrapperModule = AppWrapperModule_1 = class AppWrapperModule { static init(module, messagingModuleOptions) { const modules = [module]; if (messagingModuleOptions?.extensions) { modules.push(...messagingModuleOptions.extensions); } if (messagingModuleOptions) { const { extensions, ...cleanConfig } = messagingModuleOptions; modules.push(messaging_1.MessagingModule.forRoot(cleanConfig)); } return { module: AppWrapperModule_1, imports: modules, }; } }; AppWrapperModule = AppWrapperModule_1 = __decorate([ (0, common_1.Module)({}) ], AppWrapperModule); class MessagingBootstrap { static async createNestMicroserviceWithMessagingConsumer(module, options) { const app = await core_1.NestFactory.createMicroservice(AppWrapperModule.init(module, options?.messaging), options?.nestMicroserviceOptions); const messagingConfig = await app.get(MESSAGING_IOC_CONFIG); messagingConfig.map(v => { v.config.enableConsumer = true; return v; }); return app; } static async createNestApplicationWithMessaging(module, httpAdapterOrOptions, maybeOptions) { let httpAdapter; let options; if (httpAdapterOrOptions && 'getType' in httpAdapterOrOptions) { httpAdapter = httpAdapterOrOptions; options = maybeOptions; } else { httpAdapter = undefined; options = httpAdapterOrOptions; } return httpAdapter ? core_1.NestFactory.create(AppWrapperModule.init(module, options?.messaging), httpAdapter, options?.nestApplicationOptions) : core_1.NestFactory.create(AppWrapperModule.init(module, options?.messaging), options?.nestApplicationOptions); } } exports.MessagingBootstrap = MessagingBootstrap; //# sourceMappingURL=bootstrap.js.map