UNPKG

validatorshield

Version:

Universal validation (frontend + backend) with TypeScript. Includes common rules and Sequelize-backed async rules (unique, exists).

24 lines (23 loc) 906 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.createPrismaAdapter = createPrismaAdapter; function createPrismaAdapter(prisma) { return { async unique(table, column, value) { const model = prisma[table]; if (!model || typeof model.findFirst !== 'function') { throw new Error(`Prisma model '${table}' not found`); } const result = await model.findFirst({ where: { [column]: value } }); return !result; }, async exists(table, column, value) { const model = prisma[table]; if (!model || typeof model.findFirst !== 'function') { throw new Error(`Prisma model '${table}' not found`); } const result = await model.findFirst({ where: { [column]: value } }); return !!result; }, }; }