UNPKG

@rudderstack/workflow-engine

Version:
55 lines 2.44 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.BatchStepExecutorFactory = void 0; const common_1 = require("../../../common"); const errors_1 = require("../../../errors"); const default_batch_workflow_executor_1 = require("./default_batch_workflow_executor"); const simple_batch_executor_1 = require("./simple_batch_executor"); const step_executor_1 = require("./step_executor"); const factory_1 = require("../../factory"); class BatchStepExecutorFactory { static async create(step, options) { if (step.executor) { const executor = options.currentBindings[step.executor]; if (typeof executor?.execute !== 'function') { throw new errors_1.StepCreationError(`Invalid batch executor: ${step.executor}`, step.name); } return new step_executor_1.BatchStepExecutor(step, executor); } const defaultExecutor = await this.createDefaultBatchWorkflowExecutor(step, options); return new step_executor_1.BatchStepExecutor(step, defaultExecutor); } static async createFilterMapExecutor(stepName, config, options) { const filterStep = { name: stepName, type: common_1.StepType.Simple, loopOverInput: true, }; if (config.filter) { filterStep.loopCondition = config.filter; } if (config.map) { filterStep.template = config.map; } else { filterStep.identity = true; } return factory_1.StepExecutorFactory.create(filterStep, options); } static async createSimpleBatchExecutors(step, options) { const batches = step.batches; return Promise.all(batches.map(async (config) => { let filterMapExector; if (config.filter) { filterMapExector = await this.createFilterMapExecutor(`${step.name}-batch-${config.key}`, config, options); } return new simple_batch_executor_1.SimpleBatchExecutor(config, filterMapExector); })); } static async createDefaultBatchWorkflowExecutor(step, options) { const executors = await this.createSimpleBatchExecutors(step, options); return new default_batch_workflow_executor_1.DefaultBatchWorkflowExecutor(executors); } } exports.BatchStepExecutorFactory = BatchStepExecutorFactory; //# sourceMappingURL=factory.js.map