Skip to content

Commit

Permalink
Update refinement of if-then-else condition to report on specific con…
Browse files Browse the repository at this point in the history
…dition exceeding max depth.
  • Loading branch information
derekpierre committed Oct 8, 2024
1 parent 3eb7c4b commit cc49199
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion packages/taco/src/conditions/schemas/if-then-else.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
),
);
Expand Down

0 comments on commit cc49199

Please sign in to comment.