UNPKG

@mbc-cqrs-serverless/core

Version:
91 lines 4.86 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; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.CommandModule = void 0; const common_1 = require("@nestjs/common"); const services_1 = require("../services"); const command_event_handler_1 = require("./command.event.handler"); const command_module_definition_1 = require("./command.module-definition"); const command_service_1 = require("./command.service"); const data_service_1 = require("./data.service"); const data_sync_dds_handler_1 = require("./handlers/data-sync-dds.handler"); const history_service_1 = require("./history.service"); const repository_1 = require("./repository"); const ttl_service_1 = require("./ttl.service"); let CommandModule = class CommandModule extends command_module_definition_1.ConfigurableModuleClass { static register(options) { const module = super.register(options); const { tableName, dataSyncHandlers = [], registerHandlerProviders = true, registerEventHandlerAlias = true, } = options; // A module that defers the alias to another owner cannot run its own // data-sync handlers on the asynchronous (Step Functions) pipeline — that // pipeline only invokes the alias owner's CommandService. Fail fast rather // than dropping them silently for async commands. if (!registerEventHandlerAlias && dataSyncHandlers.length > 0) { throw new Error(`[${tableName}] dataSyncHandlers were provided together with ` + `registerEventHandlerAlias:false. These handlers would not run on the ` + `asynchronous (Step Functions) data-sync pipeline, which only invokes the ` + `owner of the '${tableName}_CommandEventHandler' alias. Register them on ` + `the alias-owning module instead.`); } if (registerEventHandlerAlias) { module.providers.push({ // data-sync-handler uses dynamic command event handler to handle step function events of command execution provide: tableName + '_CommandEventHandler', useExisting: command_event_handler_1.CommandEventHandler, }); } // When false, the handlers are provided by the importing (domain) module so // they can resolve domain-scoped tokens; CommandService still resolves them // globally via ModuleRef.get(HandlerClass, { strict: false }). if (registerHandlerProviders) { module.providers.push(...dataSyncHandlers); } return { ...module, }; } /** * Not supported. The `<tableName>_CommandEventHandler` alias and * dataSyncHandlers wiring must be composed at build time (the table name is a * deploy-time constant), which the inherited async builder cannot do — it * would silently produce a module with no alias, failing the Step Functions * data-sync pipeline at runtime. Use {@link CommandModule.register} (domain * modules compose it via `buildDomainCommandModule`). */ static registerAsync() { throw new Error('CommandModule.registerAsync() is not supported: the table name must be ' + 'known at build time to register the `<tableName>_CommandEventHandler` ' + 'alias. Use CommandModule.register(), or a domain module that composes it ' + 'via buildDomainCommandModule.'); } }; exports.CommandModule = CommandModule; exports.CommandModule = CommandModule = __decorate([ (0, common_1.Module)({ imports: [], providers: [ services_1.ExplorerService, command_service_1.CommandService, data_service_1.DataService, ttl_service_1.TtlService, history_service_1.HistoryService, command_event_handler_1.CommandEventHandler, data_sync_dds_handler_1.DataSyncDdsHandler, repository_1.Repository, ], exports: [ command_service_1.CommandService, data_service_1.DataService, history_service_1.HistoryService, command_event_handler_1.CommandEventHandler, ttl_service_1.TtlService, repository_1.Repository, ], }) ], CommandModule); //# sourceMappingURL=command.module.js.map