validation

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 19, 2026 License: MIT Imports: 2 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package validation supplies deterministic, payload-private validation results.

Index

Constants

View Source
const DefaultClauseSteps uint64 = 100000
View Source
const DefaultTotalSteps uint64 = 1000000

Variables

This section is empty.

Functions

func CheckFold

func CheckFold[R any](v Check, cs CheckCases[R]) R

CheckFold reduces Check by one-level case analysis.

func CombinationEqual

func CombinationEqual(a, b Combination) bool

CombinationEqual reports structural equality of a and b.

func CombinationEqualWith

func CombinationEqualWith(a, b Combination, ov CombinationEqOverrides) bool

CombinationEqualWith reports structural equality of a and b under ov.

func CombinationFold

func CombinationFold[R any](v Combination, cs CombinationCases[R]) R

CombinationFold reduces Combination by one-level case analysis.

func StateEqual

func StateEqual(a, b State) bool

StateEqual reports structural equality of a and b.

func StateEqualWith

func StateEqualWith(a, b State, ov StateEqOverrides) bool

StateEqualWith reports structural equality of a and b under ov.

func StateFold

func StateFold[R any](s State, cs StateCases[R]) R

StateFold reduces State by one-level case analysis.

func StateName

func StateName(state State) string

Types

type All

type All struct{}

type AtLeastOne

type AtLeastOne struct{}

type Budget

type Budget struct {
	// contains filtered or unexported fields
}

Budget belongs to one validation execution. It is not shared across threads. Each clause has an independent meter and draws from this common total.

func NewBudget

func NewBudget(schema Limits, caller Limits) *Budget

func (*Budget) BeginClause

func (b *Budget) BeginClause(schemaOverride uint64) *Meter

BeginClause accepts an optional schema-declared per-where override. A caller cap remains effective even when the schema overrides its default clause cap.

func (*Budget) BeginStructure

func (b *Budget) BeginStructure() *Meter

BeginStructure charges traversal/transfer work to the validation total, not to any individual where clause. Its allowance can never exceed that total.

func (*Budget) Used

func (b *Budget) Used() uint64

type Check

type Check interface {
	// contains filtered or unexported methods
}

Check is one evaluated where clause, not one diagnostic per Boolean operand.

func Combine

func Combine(mode Combination, checks []Check, detail Diagnostic) Check

type CheckCases

type CheckCases[R any] struct {
	Satisfied func() R
	Violated  func(Detail Diagnostic) R
	Undecided func(Detail Diagnostic) R
}

CheckCases selects one handler per Check variant for CheckFold.

type Combination

type Combination interface {
	// contains filtered or unexported methods
}

Combination operates on already evaluated predicates. The expression evaluator separately controls short-circuiting and deterministic budgets.

type CombinationCases

type CombinationCases[R any] struct {
	All        func() R
	AtLeastOne func() R
	OnlyOne    func() R
}

CombinationCases selects one handler per Combination variant for CombinationFold.

type CombinationEqOverrides

type CombinationEqOverrides struct {
	All        func(x, y All) (eq, handled bool)
	AtLeastOne func(x, y AtLeastOne) (eq, handled bool)
	OnlyOne    func(x, y OnlyOne) (eq, handled bool)
}

CombinationEqOverrides carries optional per-variant hooks for CombinationEqualWith. A hook returning handled=false falls through to the derived comparison.

type Diagnostic

type Diagnostic struct {
	Code      string   `json:"code"`
	Paths     []string `json:"paths"`
	Predicate string   `json:"predicate"`
	Message   string   `json:"message"`
}

Diagnostic deliberately has no payload field. A caller must explicitly implement the schema's opt-in message expression to include a payload value.

type Indeterminate

type Indeterminate struct{}

type Invalid

type Invalid struct{}

type Limits

type Limits struct {
	Total  uint64
	Clause uint64
}

Limits use zero for unspecified, never to request unlimited execution.

type Meter

type Meter struct {
	// contains filtered or unexported fields
}

func (*Meter) Nested

func (m *Meter) Nested(schemaOverride uint64) *Meter

Nested gives a refinement invoked during another predicate its own local limit while charging every enclosing meter. It cannot reset/relax a caller's allowance. Failure exhausts only this scope, leaving cheaper enclosing work possible when the enclosing budget still has room.

func (*Meter) Step

func (m *Meter) Step(cost uint64) error

Step charges before an operation. An unaffordable operation is not executed; the exhausted meter stays exhausted, but does not consume another clause's allowance. Integer subtraction avoids overflow even at uint64 maximum.

func (*Meter) Used

func (m *Meter) Used() uint64

type OnlyOne

type OnlyOne struct{}

type Report

type Report struct {
	// contains filtered or unexported fields
}

Report is immutable to callers. Accessors copy diagnostics and nested paths.

func Collect

func Collect(checks []Check) Report

Collect aggregates independent clauses without discarding a known violation when another predicate cannot finish. Input order is diagnostic order.

func MergeReports

func MergeReports(reports ...Report) Report

MergeReports combines independently produced reports without losing either diagnostics or an incomplete result. Invalid dominates indeterminate, just as Collect does for individual checks.

func (Report) Diagnostics

func (r Report) Diagnostics() []Diagnostic

func (Report) Incomplete

func (r Report) Incomplete() bool

func (Report) MarshalJSON

func (r Report) MarshalJSON() ([]byte, error)

func (Report) State

func (r Report) State() State

type Satisfied

type Satisfied struct{}

type State

type State interface {
	// contains filtered or unexported methods
}

State has three distinct outcomes. Invalid dominates unknown when aggregating separate where clauses, while predicate combinators have their own truth rules.

type StateCases

type StateCases[R any] struct {
	Valid         func() R
	Invalid       func() R
	Indeterminate func() R
}

StateCases selects one handler per State variant for StateFold.

type StateEqOverrides

type StateEqOverrides struct {
	Valid         func(x, y Valid) (eq, handled bool)
	Invalid       func(x, y Invalid) (eq, handled bool)
	Indeterminate func(x, y Indeterminate) (eq, handled bool)
}

StateEqOverrides carries optional per-variant hooks for StateEqualWith. A hook returning handled=false falls through to the derived comparison.

type Undecided

type Undecided struct {
	Detail Diagnostic
}

type Valid

type Valid struct{}

type Violated

type Violated struct {
	Detail Diagnostic
}

Jump to

Keyboard shortcuts

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