engine

package
v0.11.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 3, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package engine provides the core parsing and validation engine for GoZod schemas.

Index

Constants

This section is empty.

Variables

View Source
var ErrUnableToConvert = errors.New("unable to convert value to expected type")

ErrUnableToConvert indicates a type conversion failure.

Functions

func AddCheck

func AddCheck[T interface{ Internals() *core.ZodTypeInternals }](
	schema T,
	check core.ZodCheck,
) core.ZodType[any]

AddCheck adds a validation check and returns a new schema instance (copy-on-write).

func ApplyChecks added in v0.3.0

func ApplyChecks[T any](value T, checks []core.ZodCheck, ctx *core.ParseContext) (T, error)

ApplyChecks validates a value against checks and applies transformations.

func Clone

func Clone[T interface{ Internals() *core.ZodTypeInternals }](
	schema T,
	modify func(*core.ZodTypeDef),
) core.ZodType[any]

Clone creates a new schema instance with optional definition modifications (copy-on-write).

func ConvertToConstraintType added in v0.3.0

func ConvertToConstraintType[T any, R any](
	result any,
	ctx *core.ParseContext,
	expectedType core.ZodTypeCode,
) (R, error)

ConvertToConstraintType converts a parsed result to constraint type R (T, *T, or **T).

func CopyInternalsState added in v0.3.0

func CopyInternalsState(dst, src *core.ZodTypeInternals)

CopyInternalsState copies all state from src to dst.

func CreateInternalsWithState added in v0.3.0

func CreateInternalsWithState(src *core.ZodTypeInternals, typeName core.ZodTypeCode) *core.ZodTypeInternals

CreateInternalsWithState creates new internals with state cloned from src.

func ExplicitlyAborted added in v0.9.1

func ExplicitlyAborted(x core.ParsePayload, start int) bool

ExplicitlyAborted reports whether any issue from start onwards signals an explicit abort (Continue=false). Only issues from checks with Abort:true have Continue=false; regular check failures have Continue=true and do not trigger this (Zod v4: explicitlyAborted, commit 5b574501).

func InitZodType

func InitZodType[T core.ZodType[any]](schema T, def *core.ZodTypeDef)

InitZodType initializes the common fields of a ZodType.

func MergeInternalsState added in v0.3.0

func MergeInternalsState(dst, src *core.ZodTypeInternals)

MergeInternalsState merges state from src into dst, preserving dst's identity.

func NewBaseZodTypeInternals

func NewBaseZodTypeInternals(typeName core.ZodTypeCode) core.ZodTypeInternals

NewBaseZodTypeInternals creates a ZodTypeInternals with initialized collections.

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, etc.). It handles optional/nilable/default/prefault/transform modifiers automatically.

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 type-safe parsing for complex types with compile-time guarantees.

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. It handles optional/nilable/default/prefault/transform modifiers automatically.

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 type-safe parsing for primitive types with compile-time guarantees.

func ProcessNilModifiers added in v0.11.7

func ProcessNilModifiers[T any](
	input any,
	internals *core.ZodTypeInternals,
	expectedType core.ZodTypeCode,
	ctx *core.ParseContext,
) (any, bool, error)

ProcessNilModifiers applies the shared ordered modifier semantics for schemas with custom parse loops.

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.

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.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL