@activepieces/shared
Advanced tools
Comparing version 0.3.30 to 0.3.31
{ | ||
"name": "@activepieces/shared", | ||
"version": "0.3.30", | ||
"version": "0.3.31", | ||
"type": "commonjs", | ||
@@ -5,0 +5,0 @@ "dependencies": { |
import { FlowOperationRequest } from './flow-operations'; | ||
import { Action, ActionType } from './actions/action'; | ||
import { Action, ActionType, BranchAction, LoopOnItemsAction } from './actions/action'; | ||
import { Trigger, TriggerType } from './triggers/trigger'; | ||
@@ -9,3 +9,5 @@ import { FlowVersion } from './flow-version'; | ||
declare function getAllSteps(flowVersion: FlowVersion): (Action | Trigger)[]; | ||
declare function getAllChildSteps(action: LoopOnItemsAction | BranchAction): (Action)[]; | ||
declare function getStep(flowVersion: FlowVersion, stepName: string): Action | Trigger | undefined; | ||
declare function isChildOf(parent: LoopOnItemsAction | BranchAction, child: Action): boolean; | ||
export declare const flowHelper: { | ||
@@ -18,4 +20,6 @@ isValid: typeof isValid; | ||
getUsedPieces: typeof getUsedPieces; | ||
isChildOf: typeof isChildOf; | ||
getAllChildSteps: typeof getAllChildSteps; | ||
clone: (flowVersion: FlowVersion) => FlowVersion; | ||
}; | ||
export {}; |
@@ -85,2 +85,10 @@ "use strict"; | ||
} | ||
function getAllChildSteps(action) { | ||
switch (action.type) { | ||
case action_1.ActionType.LOOP_ON_ITEMS: | ||
return traverseInternal(action.firstLoopAction); | ||
default: | ||
return [...traverseInternal(action.onSuccessAction), ...traverseInternal(action.onFailureAction)]; | ||
} | ||
} | ||
function getStep(flowVersion, stepName) { | ||
@@ -133,2 +141,25 @@ return getAllSteps(flowVersion).find((step) => step.name === stepName); | ||
} | ||
function moveAction(flowVersion, request) { | ||
const steps = getAllSteps(flowVersion); | ||
const sourceStep = steps.find(step => step.name === request.name); | ||
if (!sourceStep || !isAction(sourceStep === null || sourceStep === void 0 ? void 0 : sourceStep.type)) { | ||
throw new activepieces_error_1.ActivepiecesError({ | ||
code: activepieces_error_1.ErrorCode.FLOW_OPERATION_INVALID, | ||
params: {} | ||
}, `Source step ${request.name} not found`); | ||
} | ||
const destinationStep = steps.find(step => step.name === request.newParentStep); | ||
if (!destinationStep) { | ||
throw new activepieces_error_1.ActivepiecesError({ | ||
code: activepieces_error_1.ErrorCode.FLOW_OPERATION_INVALID, | ||
params: {} | ||
}, `Destination step ${request.newParentStep} not found`); | ||
} | ||
deleteAction(flowVersion, { name: request.name }); | ||
addAction(flowVersion, { | ||
action: sourceStep, | ||
parentStep: request.newParentStep, | ||
stepLocationRelativeToParent: request.stepLocationRelativeToNewParent | ||
}); | ||
} | ||
function addAction(flowVersion, request) { | ||
@@ -189,3 +220,3 @@ const parentStep = getAllSteps(flowVersion).find(step => step.name === request.parentStep); | ||
} | ||
function createAction(request, { nextAction, onSuccessAction, onFailureAction, firstLoopAction }) { | ||
function createAction(request, { nextAction }) { | ||
var _a; | ||
@@ -201,6 +232,6 @@ const baseProperties = { | ||
case action_1.ActionType.BRANCH: | ||
action = Object.assign(Object.assign({}, baseProperties), { onFailureAction: onFailureAction, onSuccessAction: onSuccessAction, type: action_1.ActionType.BRANCH, settings: request.settings }); | ||
action = Object.assign(Object.assign({}, baseProperties), { onFailureAction: request.onFailureAction, onSuccessAction: request.onSuccessAction, type: action_1.ActionType.BRANCH, settings: request.settings }); | ||
break; | ||
case action_1.ActionType.LOOP_ON_ITEMS: | ||
action = Object.assign(Object.assign({}, baseProperties), { firstLoopAction: firstLoopAction, type: action_1.ActionType.LOOP_ON_ITEMS, settings: request.settings }); | ||
action = Object.assign(Object.assign({}, baseProperties), { firstLoopAction: request.firstLoopAction, type: action_1.ActionType.LOOP_ON_ITEMS, settings: request.settings }); | ||
break; | ||
@@ -219,2 +250,14 @@ case action_1.ActionType.PIECE: | ||
} | ||
function isChildOf(parent, child) { | ||
switch (parent.type) { | ||
case action_1.ActionType.LOOP_ON_ITEMS: { | ||
const children = getAllChildSteps(parent); | ||
return children.findIndex(c => c.name === child.name) > -1; | ||
} | ||
default: { | ||
const children = [...getAllChildSteps(parent), ...getAllChildSteps(parent)]; | ||
return children.findIndex(c => c.name === child.name) > -1; | ||
} | ||
} | ||
} | ||
function createTrigger(name, request, nextAction) { | ||
@@ -249,2 +292,5 @@ var _a; | ||
switch (operation.type) { | ||
case flow_operations_1.FlowOperationType.MOVE_ACTION: | ||
moveAction(clonedVersion, operation.request); | ||
break; | ||
case flow_operations_1.FlowOperationType.LOCK_FLOW: | ||
@@ -268,4 +314,2 @@ clonedVersion.state = flow_version_1.FlowVersionState.LOCKED; | ||
break; | ||
default: | ||
throw new Error('Unknown operation type'); | ||
} | ||
@@ -279,2 +323,4 @@ clonedVersion.valid = isValid(clonedVersion); | ||
getUsedPieces: getUsedPieces, | ||
isChildOf: isChildOf, | ||
getAllChildSteps: getAllChildSteps, | ||
clone: (flowVersion) => { | ||
@@ -281,0 +327,0 @@ return JSON.parse(JSON.stringify(flowVersion)); |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.FlowOperationRequest = exports.UpdateTriggerRequest = exports.AddActionRequest = exports.UpdateActionRequest = exports.DeleteActionRequest = exports.ChangeNameRequest = exports.ChangeFolderRequest = exports.ImportFlowRequest = exports.LockFlowRequest = exports.StepLocationRelativeToParent = exports.FlowOperationType = void 0; | ||
exports.FlowOperationRequest = exports.UpdateTriggerRequest = exports.AddActionRequest = exports.MoveActionRequest = exports.UpdateActionRequest = exports.DeleteActionRequest = exports.ChangeNameRequest = exports.ChangeFolderRequest = exports.ImportFlowRequest = exports.LockFlowRequest = exports.StepLocationRelativeToParent = exports.FlowOperationType = void 0; | ||
const action_1 = require("./actions/action"); | ||
@@ -11,4 +11,5 @@ const trigger_1 = require("./triggers/trigger"); | ||
FlowOperationType["CHANGE_FOLDER"] = "CHANGE_FOLDER"; | ||
FlowOperationType["CHANGE_NAME"] = "CHANGE_NAME"; | ||
FlowOperationType["MOVE_ACTION"] = "MOVE_ACTION"; | ||
FlowOperationType["IMPORT_FLOW"] = "IMPORT_FLOW"; | ||
FlowOperationType["CHANGE_NAME"] = "CHANGE_NAME"; | ||
FlowOperationType["UPDATE_TRIGGER"] = "UPDATE_TRIGGER"; | ||
@@ -44,2 +45,7 @@ FlowOperationType["ADD_ACTION"] = "ADD_ACTION"; | ||
exports.UpdateActionRequest = typebox_1.Type.Union([action_1.CodeActionSchema, action_1.LoopOnItemsActionSchema, action_1.PieceActionSchema, action_1.BranchActionSchema, action_1.MissingActionSchema]); | ||
exports.MoveActionRequest = typebox_1.Type.Object({ | ||
name: typebox_1.Type.String(), | ||
newParentStep: typebox_1.Type.String(), | ||
stepLocationRelativeToNewParent: typebox_1.Type.Optional(typebox_1.Type.Enum(StepLocationRelativeToParent)) | ||
}); | ||
exports.AddActionRequest = typebox_1.Type.Object({ | ||
@@ -53,2 +59,6 @@ parentStep: typebox_1.Type.String(), | ||
typebox_1.Type.Object({ | ||
type: typebox_1.Type.Literal(FlowOperationType.MOVE_ACTION), | ||
request: exports.MoveActionRequest | ||
}), | ||
typebox_1.Type.Object({ | ||
type: typebox_1.Type.Literal(FlowOperationType.LOCK_FLOW), | ||
@@ -55,0 +65,0 @@ request: exports.LockFlowRequest |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
268486
3779