@mastra/core
Version:
Mastra is a framework for building AI-powered applications and agents with a modern TypeScript stack.
63 lines • 2.61 kB
TypeScript
import type { z } from 'zod/v4';
type ZodTypeAny = z.ZodType<any, any>;
type ZodObjectAny = z.ZodObject<any>;
type ZodArrayAny = z.ZodArray<any>;
/**
* Checks if a value is a Zod type
* @param value - The value to check
* @returns True if the value is a Zod type, false otherwise
*/
export declare function isZodType(value: unknown): value is ZodTypeAny;
/**
* Get the Zod typeName from a schema, compatible with both Zod 3 and Zod 4.
* Uses string-based typeName instead of instanceof to avoid dual-package hazard
* where multiple Zod instances can cause instanceof checks to fail.
*
* Zod 3 uses `_def.typeName` with values like "ZodString", "ZodOptional", etc.
* Zod 4 uses `_def.type` with lowercase values like "string", "optional", etc.
*
* This function normalizes to Zod 3 format (e.g., "ZodString") for compatibility.
*
* @param schema - The Zod schema to get the type name from
* @returns The Zod type name string (e.g., "ZodString", "ZodOptional") or undefined
*/
export declare function getZodTypeName(schema: ZodTypeAny): string | undefined;
/**
* Check if a value is a ZodArray type
* @param value - The value to check (can be any type)
* @returns True if the value is a ZodArray
*/
export declare function isZodArray(value: unknown): value is ZodArrayAny;
/**
* Check if a value is a ZodObject type
* @param value - The value to check (can be any type)
* @returns True if the value is a ZodObject
*/
export declare function isZodObject(value: unknown): value is ZodObjectAny;
/**
* Get the def object from a Zod schema, compatible with both Zod 3 and Zod 4.
* @param schema - The Zod schema
* @returns The def object
*/
export declare function getZodDef(schema: ZodTypeAny): any;
/**
* Get the inner type from a wrapper schema (nullable, optional, default, effects, branded).
* Compatible with both Zod 3 and Zod 4.
*
* @param schema - The wrapper Zod schema
* @param typeName - The Zod type name of the wrapper (e.g., "ZodOptional")
* @returns The inner schema, or undefined if not found
*/
export declare function getZodInnerType(schema: z.ZodTypeAny, typeName: string): z.ZodTypeAny | undefined;
/**
* Unwraps Zod wrapper types (optional, nullable, default, effects, branded)
* to find the base schema type. Compatible with both Zod 3 and Zod 4.
*
* For example, `z.array(z.string()).nullish().default([])` unwraps to `z.array(z.string())`.
*
* @param schema - The Zod schema to unwrap
* @returns The innermost base schema
*/
export declare function unwrapZodType(schema: z.ZodTypeAny): z.ZodTypeAny;
export {};
//# sourceMappingURL=zod-utils.d.ts.map