From cc491999bcfb6a4837eda9ed0368ad797c125dff Mon Sep 17 00:00:00 2001 From: derekpierre Date: Tue, 8 Oct 2024 12:04:29 -0400 Subject: [PATCH] Update refinement of if-then-else condition to report on specific condition exceeding max depth. --- .../src/conditions/schemas/if-then-else.ts | 25 ++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/packages/taco/src/conditions/schemas/if-then-else.ts b/packages/taco/src/conditions/schemas/if-then-else.ts index cbe35fc5..dc90ee99 100644 --- a/packages/taco/src/conditions/schemas/if-then-else.ts +++ b/packages/taco/src/conditions/schemas/if-then-else.ts @@ -18,9 +18,32 @@ export const ifThenElseConditionSchema: z.ZodSchema = z.lazy(() => elseCondition: z.union([anyConditionSchema, z.boolean()]), }) .refine( - (condition) => maxNestedDepth(2)(condition), + // already at 2nd level since checking member condition + (condition) => maxNestedDepth(2)(condition.ifCondition, 2), { message: 'Exceeded max nested depth of 2 for multi-condition type', + path: ['ifCondition'], + }, // Max nested depth of 2 + ) + .refine( + // already at 2nd level since checking member condition + (condition) => maxNestedDepth(2)(condition.thenCondition, 2), + { + message: 'Exceeded max nested depth of 2 for multi-condition type', + path: ['thenCondition'], + }, // Max nested depth of 2 + ) + .refine( + (condition) => { + if (typeof condition.elseCondition !== 'boolean') { + // already at 2nd level since checking member condition + return maxNestedDepth(2)(condition.elseCondition, 2); + } + return true; + }, + { + message: 'Exceeded max nested depth of 2 for multi-condition type', + path: ['elseCondition'], }, // Max nested depth of 2 ), );