@featurevisor/core
Version:
Core package of Featurevisor for Node.js usage
32 lines • 1.17 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.getGroupZodSchema = getGroupZodSchema;
const zod_1 = require("zod");
function getGroupZodSchema(projectConfig, datasource, availableFeatureKeys) {
const groupZodSchema = zod_1.z
.object({
description: zod_1.z.string(),
slots: zod_1.z
.array(zod_1.z
.object({
feature: zod_1.z
.string()
.optional()
.refine((value) => {
if (value && availableFeatureKeys.indexOf(value) === -1) {
return false;
}
return true;
}, (value) => ({ message: `Unknown feature "${value}"` })),
percentage: zod_1.z.number().min(0).max(100),
})
.strict())
.refine((value) => {
const totalPercentage = value.reduce((acc, slot) => acc + slot.percentage, 0);
return totalPercentage === 100;
}, { message: "Total percentage of all slots is not 100" }),
})
.strict();
return groupZodSchema;
}
//# sourceMappingURL=groupSchema.js.map