@nucypher/taco
Version:
### [`nucypher/taco-web`](../../README.md)
36 lines • 1.5 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.compoundConditionSchema = exports.CompoundConditionType = void 0;
const zod_1 = require("zod");
const multi_condition_1 = require("../multi-condition");
const common_1 = require("./common");
const utils_1 = require("./utils");
exports.CompoundConditionType = 'compound';
exports.compoundConditionSchema = zod_1.z.lazy(() => common_1.baseConditionSchema
.extend({
conditionType: zod_1.z
.literal(exports.CompoundConditionType)
.default(exports.CompoundConditionType),
operator: zod_1.z.enum(['and', 'or', 'not']),
operands: zod_1.z.array(utils_1.anyConditionSchema).min(1).max(5),
})
.refine((condition) => {
// 'and' and 'or' operators must have at least 2 operands
if (['and', 'or'].includes(condition.operator)) {
return condition.operands.length >= 2;
}
// 'not' operator must have exactly 1 operand
if (condition.operator === 'not') {
return condition.operands.length === 1;
}
// We test positive cases exhaustively, so we return false here:
return false;
}, ({ operands, operator }) => ({
message: `Invalid number of operands ${operands.length} for operator "${operator}"`,
path: ['operands'],
}))
.refine((condition) => (0, multi_condition_1.maxNestedDepth)(2)(condition), {
message: 'Exceeded max nested depth of 2 for multi-condition type',
path: ['operands'],
}));
//# sourceMappingURL=compound.js.map