mirror of
https://github.com/Stirling-Tools/Stirling-PDF.git
synced 2025-06-23 07:55:07 +00:00
fixed nested function in workflow validator
This commit is contained in:
parent
58c08821d2
commit
26dcc4843e
@ -1,35 +1,32 @@
|
|||||||
import { Action } from "../../declarations/Action";
|
import { Action } from "../../declarations/Action";
|
||||||
import { getOperatorByName } from "./getOperatorByName";
|
import { getOperatorByName } from "./getOperatorByName";
|
||||||
|
|
||||||
|
/** This function validates the "workflow-json" from the API */
|
||||||
export function validateOperations(actions: Action[]): { valid: boolean, reason?: string} {
|
export function validateOperations(actions: Action[]): { valid: boolean, reason?: string} {
|
||||||
function validateOperation(actions: Action[]): { valid: boolean; reason?: string; } {
|
for (const action of actions) {
|
||||||
for (const action of actions) {
|
if (action.type === "wait" || action.type === "done") {
|
||||||
if (action.type === "wait" || action.type === "done") {
|
// TODO: Validate these too ):
|
||||||
// TODO: Validate these too ):
|
return { valid: true };
|
||||||
return { valid: true };
|
}
|
||||||
|
else {
|
||||||
|
const operator = getOperatorByName(action.type);
|
||||||
|
if(!operator) {
|
||||||
|
return { valid: false, reason: `action.type ${action.type} does not exist` }
|
||||||
}
|
}
|
||||||
else {
|
const validationResult = new operator(action).validate();
|
||||||
const operator = getOperatorByName(action.type);
|
|
||||||
if(!operator) {
|
|
||||||
return { valid: false, reason: `action.type ${action.type} does not exist` }
|
|
||||||
}
|
|
||||||
const validationResult = new operator(action).validate();
|
|
||||||
|
|
||||||
if(!validationResult.valid) {
|
if(!validationResult.valid) {
|
||||||
return validationResult;
|
return validationResult;
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (action.actions) {
|
|
||||||
const validationResult = validateOperation(action.actions);
|
|
||||||
|
|
||||||
if(!validationResult.valid) {
|
|
||||||
return validationResult;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return { valid: true };
|
|
||||||
}
|
|
||||||
|
|
||||||
return validateOperation(actions);
|
if (action.actions) {
|
||||||
|
const validationResult = validateOperations(action.actions);
|
||||||
|
|
||||||
|
if(!validationResult.valid) {
|
||||||
|
return validationResult;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return { valid: true };
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user