2023-11-20 22:12:03 +01:00
|
|
|
import { Action } from "../../declarations/Action";
|
2023-11-20 22:43:09 +01:00
|
|
|
import { getOperatorByName } from "./getOperatorByName";
|
2023-11-20 22:12:03 +01:00
|
|
|
|
2023-11-21 22:27:01 +01:00
|
|
|
/** This function validates the "workflow-json" from the API */
|
2023-11-20 22:12:03 +01:00
|
|
|
export function validateOperations(actions: Action[]): { valid: boolean, reason?: string} {
|
2023-11-21 22:27:01 +01:00
|
|
|
for (const action of actions) {
|
|
|
|
if (action.type === "wait" || action.type === "done") {
|
|
|
|
// TODO: Validate these too ):
|
|
|
|
return { valid: true };
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
const operator = getOperatorByName(action.type);
|
|
|
|
if(!operator) {
|
|
|
|
return { valid: false, reason: `action.type ${action.type} does not exist` }
|
2023-11-20 22:43:09 +01:00
|
|
|
}
|
2023-11-21 22:27:01 +01:00
|
|
|
const validationResult = new operator(action).validate();
|
|
|
|
|
|
|
|
if(!validationResult.valid) {
|
|
|
|
return validationResult;
|
2023-11-20 22:43:09 +01:00
|
|
|
}
|
2023-11-21 22:27:01 +01:00
|
|
|
}
|
2023-11-20 22:43:09 +01:00
|
|
|
|
2023-11-21 22:27:01 +01:00
|
|
|
if (action.actions) {
|
|
|
|
const validationResult = validateOperations(action.actions);
|
2023-11-20 22:43:09 +01:00
|
|
|
|
2023-11-21 22:27:01 +01:00
|
|
|
if(!validationResult.valid) {
|
|
|
|
return validationResult;
|
2023-11-20 22:43:09 +01:00
|
|
|
}
|
2023-11-20 22:12:03 +01:00
|
|
|
}
|
2023-11-20 22:43:09 +01:00
|
|
|
}
|
2023-11-21 22:27:01 +01:00
|
|
|
return { valid: true };
|
2023-11-20 22:12:03 +01:00
|
|
|
}
|