UNPKG

@rudderstack/workflow-engine

Version:
46 lines 2.34 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.SimpleStepExecutorFactory = void 0; const path_1 = require("path"); const utils_1 = require("../../../common/utils"); const workflow_1 = require("../../../workflow"); const executors_1 = require("./executors"); const function_1 = require("./executors/function"); const identity_1 = require("./executors/identity"); const template_1 = require("./executors/template"); class SimpleStepExecutorFactory { static async create(step, options) { if (step.identity) { return new identity_1.IdentityStepExecutor(step); } if (step.externalWorkflow) { return this.createExternalWorkflowEngineExecutor(step, options); } if (step.functionName) { return new function_1.FunctionStepExecutor(step, options.currentBindings); } if (step.templatePath) { // eslint-disable-next-line no-param-reassign step.template = await this.extractTemplate(options.rootPath, step.templatePath); } return template_1.TemplateStepExecutorFactory.create(step, step.template, options); } static extractTemplate(rootPath, templatePath) { return utils_1.CommonUtils.readFile((0, path_1.join)(rootPath, templatePath)); } static async createExternalWorkflowEngineExecutor(step, options) { const externalWorkflowConfig = step.externalWorkflow; const externalWorkflowPath = (0, path_1.join)(options.rootPath, externalWorkflowConfig.path); const externalWorkflowRootPath = (0, path_1.join)(options.rootPath, externalWorkflowConfig.rootPath ?? ''); const externalWorkflow = await workflow_1.WorkflowUtils.createWorkflowFromFilePath(externalWorkflowPath); externalWorkflow.bindings = (externalWorkflow.bindings ?? []).concat(externalWorkflowConfig.bindings ?? []); const externalWorkflowEngine = await workflow_1.WorkflowEngineFactory.create(externalWorkflow, { ...options, parentBindings: options.currentBindings, rootPath: externalWorkflowRootPath, }); return new executors_1.ExternalWorkflowStepExecutor(externalWorkflowEngine, step); } } exports.SimpleStepExecutorFactory = SimpleStepExecutorFactory; //# sourceMappingURL=factory.js.map