commented ts-typeguard & improved validation error

This commit is contained in:
Felix Kaspar 2023-12-28 02:15:14 +01:00
parent 8d9c24b09b
commit f87fb32913
2 changed files with 7 additions and 7 deletions

View File

@ -36,8 +36,8 @@ export function validateOperations(actions: Action[]): { valid: boolean, reason?
for (const afterDoneChild of done[childAction.values.id]?.actions || []) { for (const afterDoneChild of done[childAction.values.id]?.actions || []) {
const receivingOperator = getOperatorByName(afterDoneChild.type); const receivingOperator = getOperatorByName(afterDoneChild.type);
if (!receivingOperator) { if (receivingOperator === undefined) {
return { valid: false, reason: `The receiving operator ${afterDoneChild.type} does not exist.` }; return { valid: false, reason: `action.type ${afterDoneChild.type} does not exist.` };
} else if (!ioCompatible(operator, receivingOperator)) { } else if (!ioCompatible(operator, receivingOperator)) {
return { valid: false, reason: `Ouput of action ${action.type} is not compatible with input of action ${afterDoneChild.type}` }; return { valid: false, reason: `Ouput of action ${action.type} is not compatible with input of action ${afterDoneChild.type}` };
} }
@ -48,8 +48,8 @@ export function validateOperations(actions: Action[]): { valid: boolean, reason?
} }
else { else {
const receivingOperator = getOperatorByName(childAction.type); const receivingOperator = getOperatorByName(childAction.type);
if (!receivingOperator) { if (receivingOperator === undefined) {
return { valid: false, reason: `The receiving operator ${childAction.type} does not exist.` }; return { valid: false, reason: `action.type ${childAction.type} does not exist.` };
} else if (!ioCompatible(operator, receivingOperator)) { } else if (!ioCompatible(operator, receivingOperator)) {
return { valid: false, reason: `Ouput of action ${action.type} is not compatible with input of action ${childAction.type}` }; return { valid: false, reason: `Ouput of action ${action.type} is not compatible with input of action ${childAction.type}` };
} }

View File

@ -22,6 +22,6 @@ export const JoiPDFFileSchema = Joi.custom((value: Express.Multer.File[] /* <- a
} }
}, "pdffile validation"); }, "pdffile validation");
function isPdfFileArray(value: any): value is PdfFile[] { function isPdfFileArray(value: any[]): value is PdfFile[] { // "is" is a ts-typeguard - https://www.typescriptlang.org/docs/handbook/advanced-types.html#user-defined-type-guards
return value.every((e: PdfFile) => e instanceof PdfFile) return value.every((e) => e instanceof PdfFile)
} }