Validation for Action.values and malformed JSON
This commit is contained in:
@@ -6,11 +6,11 @@ import { validateOperations } from "./validateOperations";
|
||||
import { getOperatorByName } from "./getOperatorByName";
|
||||
|
||||
export async function traverseOperations(operations: Action[], input: PdfFile[], progressCallback: (state: Progress) => void): Promise<PdfFile[]> {
|
||||
|
||||
const validationResult = validateOperations(operations)
|
||||
const validationResult = validateOperations(operations);
|
||||
if(!validationResult.valid) {
|
||||
throw Error(validationResult.reason);
|
||||
return Promise.reject({validationError: validationResult.reason});
|
||||
}
|
||||
|
||||
const waitOperations = organizeWaitOperations(operations);
|
||||
|
||||
let results: PdfFile[] = [];
|
||||
|
||||
@@ -1,16 +1,35 @@
|
||||
import { Action } from "../../declarations/Action";
|
||||
import { getOperatorByName } from "./getOperatorByName";
|
||||
|
||||
export function validateOperations(actions: Action[]): { valid: boolean, reason?: string} {
|
||||
// TODO: Validate using inbuilt validators:
|
||||
/*
|
||||
validationResult = impose.validate()
|
||||
if(validationResult.valid) {
|
||||
// Check Next
|
||||
}
|
||||
else {
|
||||
return validationResult.reason
|
||||
}
|
||||
*/
|
||||
function validateOperation(actions: Action[]): { valid: boolean; reason?: string; } {
|
||||
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` }
|
||||
}
|
||||
const validationResult = new operator(action).validate();
|
||||
|
||||
if(!validationResult.valid) {
|
||||
return validationResult;
|
||||
}
|
||||
}
|
||||
|
||||
return { valid: true };
|
||||
if (action.actions) {
|
||||
const validationResult = validateOperation(action.actions);
|
||||
|
||||
if(!validationResult.valid) {
|
||||
return validationResult;
|
||||
}
|
||||
}
|
||||
}
|
||||
return { valid: true };
|
||||
}
|
||||
|
||||
return validateOperation(actions);
|
||||
}
|
||||
Reference in New Issue
Block a user