zod-opts
Version:
node.js CLI option parser / validator using Zod
71 lines (70 loc) • 2.25 kB
TypeScript
/**
* Zod v3/v4 compatibility layer
*
* v3: Access schema definition via schema._def
* v4: Access schema definition via schema._zod.def
*/
import type { ZodTypeAny } from "zod";
export declare function isRecord(value: unknown): value is Record<string, unknown>;
export interface SchemaDef extends Record<string, unknown> {
typeName?: string;
type?: string | ZodTypeAny;
innerType?: ZodTypeAny;
schema?: ZodTypeAny;
inner?: ZodTypeAny;
in?: ZodTypeAny;
defaultValue?: unknown;
options?: ZodTypeAny[];
values?: unknown[];
entries?: Record<string, unknown>;
element?: unknown;
description?: string;
}
export declare function isZodSchema(value: unknown): value is ZodTypeAny;
/**
* Check if the schema is Zod v4
* v4 has the "_zod" property
*/
export declare function isZodV4(schema: ZodTypeAny): boolean;
/**
* Get the definition object from a schema
* v3: schema._def
* v4: schema._zod.def
*/
export declare function getDef(schema: ZodTypeAny): SchemaDef;
/**
* Get the type name of a schema (returns v3 format)
* v3: def.typeName (e.g., "ZodString")
* v4: def.type (e.g., "string") -> converted to v3 format
*/
export declare function getTypeName(schema: ZodTypeAny): string;
/**
* Get the inner type definition from a schema that has innerType
*/
export declare function getInnerTypeDef(schema: ZodTypeAny): SchemaDef | undefined;
/**
* Get the inner type from a schema that has innerType
*/
export declare function getInnerType(schema: ZodTypeAny): ZodTypeAny | undefined;
/**
* Get the default value from a schema
* v3: defaultValue is a function
* v4: defaultValue is a direct value
*/
export declare function getDefaultValue(schema: ZodTypeAny): unknown;
/**
* Get union options from a union schema
*/
export declare function getUnionOptions(schema: ZodTypeAny): ZodTypeAny[];
/**
* Get enum values from an enum schema
*/
export declare function getEnumValues(schema: ZodTypeAny): string[] | undefined;
/**
* Get the element type from an array schema
*/
export declare function getArrayElementType(schema: ZodTypeAny): ZodTypeAny | undefined;
/**
* Get the description from a schema
*/
export declare function getDescription(schema: ZodTypeAny): string | undefined;