engine

package
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Feb 13, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

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 CheckAborted

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

CheckAborted reports whether any issue from start onwards signals an abort.

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 InitZodType

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

InitZodType initializes the common fields of a ZodType.

func IsValidSchemaType

func IsValidSchemaType(value any) bool

IsValidSchemaType reports whether value implements core.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 ProcessSchemaParams

func ProcessSchemaParams(params ...core.SchemaParams) map[string]any

ProcessSchemaParams merges schema parameters into a configuration map.

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.

func WithAbort

func WithAbort() core.SchemaParams

WithAbort creates a SchemaParams with abort-on-error enabled.

func WithDescription

func WithDescription(desc string) core.SchemaParams

WithDescription creates a SchemaParams with a description.

func WithError

func WithError(message string) core.SchemaParams

WithError creates a SchemaParams with a custom error message.

Types

This section is empty.

Jump to

Keyboard shortcuts

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