@nucypher/taco
Version:
### [`nucypher/taco-web`](../../README.md)
37 lines • 1.42 kB
JavaScript
import { z } from 'zod';
import { maxNestedDepth } from '../multi-condition';
import { baseConditionSchema } from './common';
import { anyConditionSchema } from './utils';
export const IfThenElseConditionType = 'if-then-else';
export const ifThenElseConditionSchema = z.lazy(() => baseConditionSchema
.extend({
conditionType: z
.literal(IfThenElseConditionType)
.default(IfThenElseConditionType),
ifCondition: anyConditionSchema,
thenCondition: anyConditionSchema,
elseCondition: z.union([anyConditionSchema, z.boolean()]),
})
.refine(
// 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'],
})
.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'],
})
.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'],
}));
//# sourceMappingURL=if-then-else.js.map