@ai2070/l0
Version:
L0: The Missing Reliability Substrate for AI
34 lines • 1.04 kB
JavaScript
export function isZodSchema(value) {
if (!value || typeof value !== "object")
return false;
const schema = value;
return (typeof schema.parse === "function" &&
typeof schema.safeParse === "function" &&
"_def" in schema);
}
export function isZodError(error) {
if (!error || typeof error !== "object")
return false;
const err = error;
return (err.name === "ZodError" &&
Array.isArray(err.issues) &&
typeof err.format === "function");
}
export function safeParse(schema, data) {
const result = schema.safeParse(data);
return result;
}
export function getZodErrorMessages(error) {
return error.issues.map((issue) => {
const path = issue.path.length > 0 ? `${issue.path.join(".")}: ` : "";
return `${path}${issue.message}`;
});
}
export function flattenZodError(error) {
const flat = error.flatten();
return {
formErrors: flat.formErrors,
fieldErrors: flat.fieldErrors,
};
}
//# sourceMappingURL=zodCompat.js.map