@activepieces/shared
Advanced tools
Comparing version 0.3.45 to 0.3.46
{ | ||
"name": "@activepieces/shared", | ||
"version": "0.3.45", | ||
"version": "0.3.46", | ||
"type": "commonjs", | ||
@@ -5,0 +5,0 @@ "dependencies": { |
@@ -21,2 +21,3 @@ import { FlowOperationRequest } from './flow-operations'; | ||
declare function isChildOf(parent: LoopOnItemsAction | BranchAction, child: Action): boolean; | ||
export declare function getImportOperations(step: Action | Trigger | undefined): (FlowOperationRequest)[]; | ||
export declare const flowHelper: { | ||
@@ -29,2 +30,3 @@ isValid: typeof isValid; | ||
getUsedPieces: typeof getUsedPieces; | ||
getImportOperations: typeof getImportOperations; | ||
getAllSubFlowSteps: ({ subFlowStartStep }: GetAllSubFlowSteps) => Step[]; | ||
@@ -31,0 +33,0 @@ getStepFromSubFlow: ({ subFlowStartStep, stepName }: GetStepFromSubFlow) => Step | undefined; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.flowHelper = void 0; | ||
exports.flowHelper = exports.getImportOperations = void 0; | ||
const flow_operations_1 = require("./flow-operations"); | ||
@@ -173,2 +173,9 @@ const action_1 = require("./actions/action"); | ||
} | ||
const childOperation = []; | ||
const clonedSourceStep = JSON.parse(JSON.stringify(sourceStep)); | ||
if (clonedSourceStep.type === action_1.ActionType.LOOP_ON_ITEMS || clonedSourceStep.type === action_1.ActionType.BRANCH) { | ||
// Don't Clone the next action for first step only | ||
clonedSourceStep.nextAction = undefined; | ||
childOperation.push(...getImportOperations(clonedSourceStep)); | ||
} | ||
deleteAction(flowVersion, { name: request.name }); | ||
@@ -180,2 +187,6 @@ addAction(flowVersion, { | ||
}); | ||
childOperation.forEach(operation => { | ||
flowVersion = exports.flowHelper.apply(flowVersion, operation); | ||
}); | ||
return flowVersion; | ||
} | ||
@@ -301,9 +312,83 @@ function addAction(flowVersion, request) { | ||
} | ||
function getImportOperations(step) { | ||
const steps = []; | ||
while (step) { | ||
if (step.nextAction) { | ||
steps.push({ | ||
type: flow_operations_1.FlowOperationType.ADD_ACTION, | ||
request: { | ||
parentStep: step.name, | ||
action: keepBaseAction(step.nextAction), | ||
}, | ||
}); | ||
} | ||
if (step.type === action_1.ActionType.BRANCH) { | ||
if (step.onFailureAction) { | ||
steps.push({ | ||
type: flow_operations_1.FlowOperationType.ADD_ACTION, | ||
request: { | ||
parentStep: step.name, | ||
stepLocationRelativeToParent: flow_operations_1.StepLocationRelativeToParent.INSIDE_FALSE_BRANCH, | ||
action: keepBaseAction(step.onFailureAction), | ||
}, | ||
}); | ||
steps.push(...getImportOperations(step.onFailureAction)); | ||
} | ||
if (step.onSuccessAction) { | ||
steps.push({ | ||
type: flow_operations_1.FlowOperationType.ADD_ACTION, | ||
request: { | ||
parentStep: step.name, | ||
stepLocationRelativeToParent: flow_operations_1.StepLocationRelativeToParent.INSIDE_TRUE_BRANCH, | ||
action: keepBaseAction(step.onSuccessAction), | ||
}, | ||
}); | ||
steps.push(...getImportOperations(step.onSuccessAction)); | ||
} | ||
} | ||
if (step.type === action_1.ActionType.LOOP_ON_ITEMS && step.firstLoopAction) { | ||
steps.push({ | ||
type: flow_operations_1.FlowOperationType.ADD_ACTION, | ||
request: { | ||
parentStep: step.name, | ||
stepLocationRelativeToParent: flow_operations_1.StepLocationRelativeToParent.INSIDE_LOOP, | ||
action: keepBaseAction(step.firstLoopAction), | ||
}, | ||
}); | ||
steps.push(...getImportOperations(step.firstLoopAction)); | ||
} | ||
step = step.nextAction; | ||
} | ||
return steps; | ||
} | ||
exports.getImportOperations = getImportOperations; | ||
// It's better to use switch case, to enforce that all actions are covered | ||
// TODO this can be simplified | ||
function keepBaseAction(action) { | ||
const commonProps = { | ||
name: action.name, | ||
displayName: action.displayName, | ||
valid: action.valid, | ||
}; | ||
switch (action.type) { | ||
case action_1.ActionType.BRANCH: | ||
// PICK type and settings from action | ||
return Object.assign({ type: action_1.ActionType.BRANCH, settings: action.settings }, commonProps); | ||
case action_1.ActionType.LOOP_ON_ITEMS: | ||
return Object.assign({ type: action_1.ActionType.LOOP_ON_ITEMS, settings: action.settings }, commonProps); | ||
case action_1.ActionType.CODE: | ||
return Object.assign({ type: action.type, settings: Object.assign(Object.assign({}, action.settings), { artifactPackagedId: undefined, artifactSourceId: undefined }) }, commonProps); | ||
case action_1.ActionType.PIECE: | ||
return Object.assign({ type: action.type, settings: action.settings }, commonProps); | ||
case action_1.ActionType.MISSING: | ||
return Object.assign({ type: action.type, settings: action.settings }, commonProps); | ||
} | ||
} | ||
exports.flowHelper = { | ||
isValid: isValid, | ||
apply(flowVersion, operation) { | ||
const clonedVersion = JSON.parse(JSON.stringify(flowVersion)); | ||
let clonedVersion = JSON.parse(JSON.stringify(flowVersion)); | ||
switch (operation.type) { | ||
case flow_operations_1.FlowOperationType.MOVE_ACTION: | ||
moveAction(clonedVersion, operation.request); | ||
clonedVersion = moveAction(clonedVersion, operation.request); | ||
break; | ||
@@ -336,2 +421,3 @@ case flow_operations_1.FlowOperationType.LOCK_FLOW: | ||
getUsedPieces, | ||
getImportOperations, | ||
getAllSubFlowSteps, | ||
@@ -338,0 +424,0 @@ getStepFromSubFlow, |
Sorry, the diff of this file is not supported yet
293724
4130