next-safe-action
Version:
Type safe and validated Server Actions in your Next.js project.
33 lines (32 loc) • 632 B
JavaScript
// src/adapters/yup.ts
import { ValidationError } from "yup";
var YupAdapter = class {
async validate(schema, data) {
try {
const result = await schema.validate(data, { strict: true });
return {
success: true,
data: result,
};
} catch (e) {
if (e instanceof ValidationError) {
const { message, path } = e;
return {
success: false,
issues: [
{
message,
path: path && path.length > 0 ? path.split(".") : void 0,
},
],
};
}
throw e;
}
}
};
function yupAdapter() {
return new YupAdapter();
}
export { yupAdapter };
//# sourceMappingURL=yup.mjs.map