Documentation
¶
Index ¶
- Variables
- func AddCheck[T interface{ ... }](schema T, check core.ZodCheck) core.ZodType[any]
- func ApplyChecks[T any](value T, checks []core.ZodCheck, ctx *core.ParseContext) (T, error)
- func CheckAborted(x core.ParsePayload, startIndex int) bool
- func Clone[T interface{ ... }](schema T, modifyDef func(*core.ZodTypeDef)) core.ZodType[any]
- func ConvertToConstraintType[T any, R any](result any, ctx *core.ParseContext, expectedType core.ZodTypeCode) (R, error)
- func CopyInternalsState(target *core.ZodTypeInternals, source *core.ZodTypeInternals)
- func CreateInternalsWithState(source *core.ZodTypeInternals, typeName core.ZodTypeCode) *core.ZodTypeInternals
- func InitZodType[T core.ZodType[any]](schema T, def *core.ZodTypeDef)
- func IsValidSchemaType(value any) bool
- func MergeInternalsState(target *core.ZodTypeInternals, source *core.ZodTypeInternals)
- func NewBaseZodTypeInternals(typeName core.ZodTypeCode) core.ZodTypeInternals
- func ParseComplex[T any](input any, internals *core.ZodTypeInternals, expectedType core.ZodTypeCode, ...) (any, error)
- func ParseComplexStrict[T any, R any](input R, internals *core.ZodTypeInternals, expectedType core.ZodTypeCode, ...) (R, error)
- func ParsePrimitive[T any, R any](input any, internals *core.ZodTypeInternals, expectedType core.ZodTypeCode, ...) (R, error)
- func ParsePrimitiveStrict[T any, R any](input R, internals *core.ZodTypeInternals, expectedType core.ZodTypeCode, ...) (R, error)
- func ProcessSchemaParams(params ...core.SchemaParams) map[string]any
- func RunChecks(checks []core.ZodCheck, payload *core.ParsePayload, ctx ...*core.ParseContext) *core.ParsePayload
- func RunChecksOnValue(value any, checks []core.ZodCheck, payload *core.ParsePayload, ...) *core.ParsePayload
- func WithAbort() core.SchemaParams
- func WithDescription(description string) core.SchemaParams
- func WithError(message string) core.SchemaParams
Constants ¶
This section is empty.
Variables ¶
var (
ErrUnableToConvert = errors.New("unable to convert value to expected type")
)
Static error variables
Functions ¶
func AddCheck ¶
func AddCheck[T interface{ GetInternals() *core.ZodTypeInternals }](schema T, check core.ZodCheck) core.ZodType[any]
AddCheck adds a validation check to any ZodType and returns new instance Uses core's Clone() method for efficient state management
func ApplyChecks ¶ added in v0.3.0
ApplyChecks provides universal validation and transformation for any type Handles validation logic common across all types and applies transformations Returns the potentially modified value after running checks (e.g., overwrite transforms)
func CheckAborted ¶
func CheckAborted(x core.ParsePayload, startIndex int) bool
CheckAborted checks if parsing should be aborted Returns true if any issue from startIndex onwards has Continue set to false
func Clone ¶
func Clone[T interface{ GetInternals() *core.ZodTypeInternals }](schema T, modifyDef func(*core.ZodTypeDef)) core.ZodType[any]
Clone creates a new instance of any ZodType with optional definition modifications Uses core's Clone() method for efficient deep cloning
func ConvertToConstraintType ¶ added in v0.3.0
func ConvertToConstraintType[T any, R any]( result any, ctx *core.ParseContext, expectedType core.ZodTypeCode, ) (R, error)
ConvertToConstraintType provides universal type conversion for constraint types (T | *T). This function handles the common pattern where a schema can output either T or *T.
T – base type (bool, string, int64, float64, etc.) R – constraint type (must be T | *T) result – parsed result from engine (T or nil) ctx – parse context for error reporting expectedType – type code for error messages
func CopyInternalsState ¶ added in v0.3.0
func CopyInternalsState(target *core.ZodTypeInternals, source *core.ZodTypeInternals)
CopyInternalsState efficiently copies state from source to target internals Uses core's Clone() method as the foundation
func CreateInternalsWithState ¶ added in v0.3.0
func CreateInternalsWithState(source *core.ZodTypeInternals, typeName core.ZodTypeCode) *core.ZodTypeInternals
CreateInternalsWithState creates new internals with copied state from source Provides a convenient way to create new internals with existing state
func InitZodType ¶
func InitZodType[T core.ZodType[any]](schema T, def *core.ZodTypeDef)
InitZodType initializes the common fields of a ZodType using core convenience methods This function sets up the basic internal structure for any schema type
func IsValidSchemaType ¶
IsValidSchemaType checks if a value implements the core ZodType interface Useful for runtime type checking and validation
func MergeInternalsState ¶ added in v0.3.0
func MergeInternalsState(target *core.ZodTypeInternals, source *core.ZodTypeInternals)
MergeInternalsState merges state from source into target using core convenience methods Preserves target's core identity while adding source's modifiers and configuration
func NewBaseZodTypeInternals ¶
func NewBaseZodTypeInternals(typeName core.ZodTypeCode) core.ZodTypeInternals
NewBaseZodTypeInternals creates basic ZodTypeInternals structure Provides a foundation for custom schema type implementations
func ParseComplex ¶ added in v0.3.0
func ParseComplex[T any]( input any, internals *core.ZodTypeInternals, expectedType core.ZodTypeCode, typeExtractor func(any) (T, bool), ptrExtractor func(any) (*T, bool), validator func(T, []core.ZodCheck, *core.ParseContext) (T, error), ctx ...*core.ParseContext, ) (any, error)
ParseComplex provides unified parsing for complex types (struct, slice, map, interface{}, etc.). Automatically handles optional/nilable/default/prefault/transform modifiers with optimal performance.
T – complex Go type (struct, slice, map, custom types, etc.) input – raw user input, supports T, *T, and convertible types internals – schema internals containing validation rules and modifiers expectedType – type code for error messages typeExtractor – function to extract value of type T from input ptrExtractor – function to extract pointer to T from input validator – optional validation function for applying checks ctx – parsing context (optional variadic parameter)
func ParseComplexStrict ¶ added in v0.4.0
func ParseComplexStrict[T any, R any]( input R, internals *core.ZodTypeInternals, expectedType core.ZodTypeCode, typeExtractor func(any) (T, bool), ptrExtractor func(any) (*T, bool), validator func(T, []core.ZodCheck, *core.ParseContext) (T, error), ctx ...*core.ParseContext, ) (R, error)
ParseComplexStrict provides optimized, type-safe parsing for complex types with compile-time guarantees. Uses Go 1.24 generics to eliminate unnecessary type conversions and function call overhead. Implements zero-overhead fast paths for common validation scenarios.
T – complex Go type (struct, slice, map, custom types, etc.) R – constraint type (T | *T) for type-safe output input – input already typed as R (compile-time guarantee) internals – schema internals containing validation rules and modifiers expectedType – type code for error messages typeExtractor – function to extract value of type T from input ptrExtractor – function to extract pointer to T from input validator – validation function for applying checks to T values ctx – parsing context (optional variadic parameter)
func ParsePrimitive ¶ added in v0.2.3
func ParsePrimitive[T any, R any]( input any, internals *core.ZodTypeInternals, expectedType core.ZodTypeCode, validator func(T, []core.ZodCheck, *core.ParseContext) (T, error), converter func(any, *core.ParseContext, core.ZodTypeCode) (R, error), ctx ...*core.ParseContext, ) (R, error)
ParsePrimitive provides unified, type-safe parsing for primitive types. Automatically handles optional/nilable/default/prefault/transform modifiers with optimal performance.
T – primitive Go type (bool, string, int64, float64, etc.) R – constraint type (T | *T) for type-safe output input – raw user input, supports T, *T, and coercible types internals – schema internals containing validation rules and modifiers expectedType – type code for error messages validator – validation function for applying checks to T values converter – function to convert parsed result to constraint type R ctx – parsing context (optional variadic parameter)
func ParsePrimitiveStrict ¶ added in v0.4.0
func ParsePrimitiveStrict[T any, R any]( input R, internals *core.ZodTypeInternals, expectedType core.ZodTypeCode, validator func(T, []core.ZodCheck, *core.ParseContext) (T, error), ctx ...*core.ParseContext, ) (R, error)
ParsePrimitiveStrict provides optimized, type-safe parsing for primitive types with compile-time guarantees. Uses Go 1.24 generics to eliminate unnecessary type conversions and function call overhead. Implements zero-overhead fast paths for common validation scenarios.
T – primitive Go type (bool, string, int64, float64, etc.) R – constraint type (T | *T) for type-safe output input – input already typed as R (compile-time guarantee) internals – schema internals containing validation rules and modifiers expectedType – type code for error messages validator – validation function for applying checks to T values ctx – parsing context (optional variadic parameter)
func ProcessSchemaParams ¶
func ProcessSchemaParams(params ...core.SchemaParams) map[string]any
ProcessSchemaParams processes schema parameters and returns a configuration map Uses structx to handle parameter conversion and mapx for merging
func RunChecks ¶
func RunChecks(checks []core.ZodCheck, payload *core.ParsePayload, ctx ...*core.ParseContext) *core.ParsePayload
RunChecks executes all validation checks on a payload's value This is the primary method for running checks within the parsing pipeline Returns the payload for method chaining and consistent API
func RunChecksOnValue ¶
func RunChecksOnValue(value any, checks []core.ZodCheck, payload *core.ParsePayload, ctx ...*core.ParseContext) *core.ParsePayload
RunChecksOnValue executes all validation checks on a specific value Returns the payload for consistent API and error checking
func WithAbort ¶
func WithAbort() core.SchemaParams
WithAbort creates a SchemaParams with abort on error enabled Convenient helper for configuring early termination on validation failure
func WithDescription ¶
func WithDescription(description string) core.SchemaParams
WithDescription creates a SchemaParams with description Convenient helper for adding documentation to schemas
func WithError ¶
func WithError(message string) core.SchemaParams
WithError creates a SchemaParams with custom error message Convenient helper for creating schema with custom error handling
Types ¶
This section is empty.