typebox

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package typebox ports the parts of TypeBox 1.3.27 Value that PiG needs over JSON Schema data: Check, Errors, Clean, Default and Clone, with the format registry and the keyword spellings TypeBox accepts.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Check

func Check(schema, value any) bool

Check is Value.Check: whether value matches schema. A schema the validator cannot compile matches nothing.

func Clean

func Clean(schema, value any) any

Clean is Value.Clean (value/clean): it removes the properties and tuple elements schema does not evaluate. It mutates value and returns the result.

func Clone

func Clone(value any) any

Clone is Value.Clone: a deep copy of a JSON value; objects keep their kind (map or ordered object).

func CompilePattern

func CompilePattern(pattern string) (*regexp.Regexp, error)

CompilePattern is regexp.Compile for a schema's pattern text (patternProperties keys and the like), cached so a schema checked again does not compile its patterns again. A *regexp.Regexp is safe for concurrent use.

func CompilerSchema

func CompilerSchema(value any) any

CompilerSchema translates the positional items and dependencies TypeBox accepts alongside current JSON Schema keywords into their draft-2020 spellings for the validator, without changing the schema used for conversion or error traversal.

func Default

func Default(schema, value any) any

Default is Value.Default (value/default): it fills absent values that have a schema default. It mutates value and returns the result; an absent root is passed as nil and returned as nil when schema gives it no default.

func Formats

func Formats() map[string]func(string) bool

Formats returns the formats of typebox's registry that Pig ports, by name. Every call returns the same map.

func Plain

func Plain(value any) any

Plain returns value with every *chordjson.Object as a map[string]any and every Go number as float64, the form the validator reads. Other values are returned as they are.

func RegisterFormats

func RegisterFormats(compiler *jsonschema.Compiler)

RegisterFormats makes the compiler assert the typebox formats.

Types

type Checker

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

Checker is Check for one schema compiled once: Value.Check on a schema a caller holds does not serialize it again for every value. A schema the validator cannot compile matches nothing.

func NewChecker

func NewChecker(schema any) *Checker

NewChecker compiles schema (through the compiled-schema cache) for repeated checks.

func (*Checker) Check

func (checker *Checker) Check(value any) bool

Check is Value.Check against the compiled schema.

type Ordered

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

Ordered is a schema object read from JSON with its members in the order they were declared in, which TypeBox visits them in (properties, patternProperties, dependencies) and JSON.stringify writes them in. It keeps the members as a map as well, built once when the schema is decoded, so a reader looks a member up, or asks for its map, without copying. An Ordered is immutable after NewOrdered: it is safe for concurrent readers and is released with the schema holding it.

func NewOrdered

func NewOrdered(keys []string, members map[string]any) *Ordered

NewOrdered is the object whose members are members, listed in keys order. Neither is changed afterwards by the caller.

func (*Ordered) Get

func (o *Ordered) Get(key string) (any, bool)

Get is the member under key.

func (*Ordered) Keys

func (o *Ordered) Keys() []string

Keys are the members' names in declaration order. The slice is shared: do not change it.

func (*Ordered) Len

func (o *Ordered) Len() int

Len is the number of members.

func (*Ordered) Map

func (o *Ordered) Map() map[string]any

Map is the members by name. The map is shared: do not change it.

type ValueError

type ValueError struct {
	Keyword      string
	SchemaPath   string
	InstancePath string
	Message      string
	// contains filtered or unexported fields
}

ValueError is one error of Errors, as TypeBox reports it: the keyword that failed, the schema path of the failing schema, the instance path of the failing value ("" for the root; member names appended unescaped, as TypeBox does) and the en_US message.

func Errors

func Errors(schema, value any) []ValueError

Errors is Value.Errors(schema, value).

func (ValueError) ParamsObject

func (e ValueError) ParamsObject() *chordjson.Object

ParamsObject is the error's params object, its members in the order TypeBox writes them (empty for none).

Directories

Path Synopsis
Package engine is TypeBox 1.3.27's type-system engine (build/type/{action,engine,extends,script} and the parts of build/type/types and build/system the engine uses), ported once for the host.
Package engine is TypeBox 1.3.27's type-system engine (build/type/{action,engine,extends,script} and the parts of build/type/types and build/system the engine uses), ported once for the host.

Jump to

Keyboard shortcuts

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