@mastra/core
Version:
Mastra is a framework for building AI-powered applications and agents with a modern TypeScript stack.
62 lines (60 loc) • 1.98 kB
JavaScript
;
// src/utils/zod-utils.ts
function isZodType(value) {
return typeof value === "object" && value !== null && "_def" in value && "parse" in value && typeof value.parse === "function" && "safeParse" in value && typeof value.safeParse === "function";
}
function getZodTypeName(schema) {
const schemaAny = schema;
if (schemaAny._def?.typeName) {
return schemaAny._def.typeName;
}
const zod4Type = schemaAny._def?.type;
if (typeof zod4Type === "string" && zod4Type) {
return "Zod" + zod4Type.charAt(0).toUpperCase() + zod4Type.slice(1);
}
return void 0;
}
function isZodArray(value) {
if (!isZodType(value)) return false;
return getZodTypeName(value) === "ZodArray";
}
function isZodObject(value) {
if (!isZodType(value)) return false;
return getZodTypeName(value) === "ZodObject";
}
function getZodDef(schema) {
const schemaAny = schema;
return schemaAny._zod?.def ?? schemaAny._def;
}
function getZodInnerType(schema, typeName) {
const schemaAny = schema;
if (typeName === "ZodNullable" || typeName === "ZodOptional" || typeName === "ZodDefault") {
return schemaAny._zod?.def?.innerType ?? schemaAny._def?.innerType;
}
if (typeName === "ZodEffects") {
return schemaAny._zod?.def?.schema ?? schemaAny._def?.schema;
}
if (typeName === "ZodBranded") {
return schemaAny._zod?.def?.type ?? schemaAny._def?.type;
}
return void 0;
}
function unwrapZodType(schema) {
let current = schema;
while (true) {
const typeName = getZodTypeName(current);
if (!typeName) break;
const inner = getZodInnerType(current, typeName);
if (!inner) break;
current = inner;
}
return current;
}
exports.getZodDef = getZodDef;
exports.getZodInnerType = getZodInnerType;
exports.getZodTypeName = getZodTypeName;
exports.isZodArray = isZodArray;
exports.isZodObject = isZodObject;
exports.unwrapZodType = unwrapZodType;
//# sourceMappingURL=chunk-RLPRSIR2.cjs.map
//# sourceMappingURL=chunk-RLPRSIR2.cjs.map