From f87fb32913bd3d6eb920f64138c2d6edf69002f0 Mon Sep 17 00:00:00 2001 From: Felix Kaspar Date: Thu, 28 Dec 2023 02:15:14 +0100 Subject: [PATCH] commented ts-typeguard & improved validation error --- shared-operations/src/workflow/validateOperations.ts | 8 ++++---- shared-operations/src/wrappers/PdfFileJoi.ts | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/shared-operations/src/workflow/validateOperations.ts b/shared-operations/src/workflow/validateOperations.ts index ad322628f..e0d3dbb44 100644 --- a/shared-operations/src/workflow/validateOperations.ts +++ b/shared-operations/src/workflow/validateOperations.ts @@ -36,8 +36,8 @@ export function validateOperations(actions: Action[]): { valid: boolean, reason? for (const afterDoneChild of done[childAction.values.id]?.actions || []) { const receivingOperator = getOperatorByName(afterDoneChild.type); - if (!receivingOperator) { - return { valid: false, reason: `The receiving operator ${afterDoneChild.type} does not exist.` }; + if (receivingOperator === undefined) { + return { valid: false, reason: `action.type ${afterDoneChild.type} does not exist.` }; } else if (!ioCompatible(operator, receivingOperator)) { 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 { const receivingOperator = getOperatorByName(childAction.type); - if (!receivingOperator) { - return { valid: false, reason: `The receiving operator ${childAction.type} does not exist.` }; + if (receivingOperator === undefined) { + return { valid: false, reason: `action.type ${childAction.type} does not exist.` }; } else if (!ioCompatible(operator, receivingOperator)) { return { valid: false, reason: `Ouput of action ${action.type} is not compatible with input of action ${childAction.type}` }; } diff --git a/shared-operations/src/wrappers/PdfFileJoi.ts b/shared-operations/src/wrappers/PdfFileJoi.ts index 427ba2228..adb02c713 100644 --- a/shared-operations/src/wrappers/PdfFileJoi.ts +++ b/shared-operations/src/wrappers/PdfFileJoi.ts @@ -22,6 +22,6 @@ export const JoiPDFFileSchema = Joi.custom((value: Express.Multer.File[] /* <- a } }, "pdffile validation"); -function isPdfFileArray(value: any): value is PdfFile[] { - return value.every((e: PdfFile) => e instanceof 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) => e instanceof PdfFile) +} \ No newline at end of file