@rudderstack/workflow-engine
Version:
A generic workflow execution engine
55 lines • 2.8 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ComposableExecutorFactory = void 0;
const template_1 = require("../base/simple/executors/template");
const conditional_1 = require("./executors/conditional");
const custom_input_1 = require("./executors/custom_input");
const debuggable_1 = require("./executors/debuggable");
const error_wrap_1 = require("./executors/error_wrap");
const loop_1 = require("./executors/loop");
const factory_1 = require("../factory");
class ComposableExecutorFactory {
static async create(stepExecutor, options) {
const step = stepExecutor.getStep();
let composedStepExecutor = stepExecutor;
if (step.loopOverInput) {
composedStepExecutor = this.createLoopStepExecutor(composedStepExecutor, options);
}
if (step.inputTemplate) {
composedStepExecutor = this.createCustomInputStepExecutor(composedStepExecutor, options);
}
if (step.condition) {
composedStepExecutor = await this.createConditionalStepExecutor(composedStepExecutor, options);
}
if (step.debug) {
composedStepExecutor = new debuggable_1.DebuggableStepExecutor(composedStepExecutor);
}
composedStepExecutor = new error_wrap_1.ErrorWrapStepExecutor(composedStepExecutor);
return composedStepExecutor;
}
static createCustomInputStepExecutor(stepExecutor, options) {
const step = stepExecutor.getStep();
const templateExecutor = template_1.TemplateStepExecutorFactory.create(step, step.inputTemplate, options);
return new custom_input_1.CustomInputStepExecutor(templateExecutor, stepExecutor);
}
static async createConditionalStepExecutor(thenExecutor, options) {
const step = thenExecutor.getStep();
const condtionalExecutor = template_1.TemplateStepExecutorFactory.create(step, step.condition, options);
let elseExecutor;
if (step.else) {
elseExecutor = await factory_1.StepExecutorFactory.create(step.else, options);
}
return new conditional_1.ConditionalStepExecutor(condtionalExecutor, thenExecutor, elseExecutor);
}
static createLoopStepExecutor(stepExecutor, options) {
const step = stepExecutor.getStep();
let wrappedStepExecutor = stepExecutor;
if (step.loopCondition) {
const condtionalExecutor = template_1.TemplateStepExecutorFactory.create(step, step.loopCondition, options);
wrappedStepExecutor = new conditional_1.ConditionalStepExecutor(condtionalExecutor, wrappedStepExecutor);
}
return new loop_1.LoopStepExecutor(wrappedStepExecutor);
}
}
exports.ComposableExecutorFactory = ComposableExecutorFactory;
//# sourceMappingURL=factory.js.map