Documentation
¶
Overview ¶
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. The extension SDKs (Go, Rust, Python) call it through one blocking host request at schema-build time instead of carrying ports of it, so Type.Pick, Type.Mapped, Type.Script and the rest return, byte for byte, what Pi's `Type` returns: the enumerable members in the order JavaScript enumerates them and the hidden members (`~kind`, `~optional`, ...) the later calls read.
The engine works on JavaScript values, because TypeBox's own code does: a schema is an object that has hidden (non-enumerable) members, a context is a plain object of named schemas, and a script parser's intermediate results are arrays, booleans, strings and schemas in one list. Value is that model: nil is null, Undef is undefined, bool, float64, string, *big.Int (bigint), []any (array), *Obj (object) and *Opaque (a function or other value the engine only passes through).
Index ¶
- Variables
- func C(s string) parser
- func Call(member string, args []any) (result any, err error)
- func Clone(value any) any
- func Decode(text string) (value any, err error)
- func Discard(value any, keys ...string) any
- func Encode(value any) string
- func Has(member string) bool
- func Members() []string
- func Serve(request []byte) []byte
- func Update(current any, hidden, enumerable any) any
- type Error
- type Obj
- func (o *Obj) EnumKeys() []string
- func (o *Obj) Enumerable(name string) bool
- func (o *Obj) Get(name string) (any, bool)
- func (o *Obj) Has(name string) bool
- func (o *Obj) Keys() []string
- func (o *Obj) Set(name string, value any)
- func (o *Obj) SetHidden(name string, value any)
- func (o *Obj) Value(name string) any
- type Opaque
Constants ¶
This section is empty.
Variables ¶
var Undef = &undefined{}
Undef is JavaScript's undefined.
Functions ¶
func Call ¶
Call runs the member of TypeBox's `Type` namespace named member on args, as JavaScript would: arguments past the end are undefined, and what TypeBox throws comes back as an *Error. The result is the JavaScript value.
func Clone ¶
Clone is Memory.Clone: a deep copy. A schema object (one that has `~kind` or `~unsafe`) keeps its hidden members; any other object keeps only its enumerable members; the unsafe key names are dropped.
func Discard ¶
Discard is Memory.Discard(value, keys): a copy without the named members, hidden ones kept as hidden, values cloned.
Types ¶
type Error ¶
type Error struct{ Name, Message string }
Error is a JavaScript exception: the name of the error constructor and the message `error.message` has.
type Obj ¶
type Obj struct {
// contains filtered or unexported fields
}
Obj is a JavaScript object: own members in insertion order, each enumerable or hidden. Keys and EnumKeys list them as JavaScript does (array-index keys ascending first, the rest in insertion order).
func Create ¶
Create is Memory.Create(hidden, enumerable, options): `{...enumerable, ...options}` with the hidden members defined non-enumerable.
func NewObj ¶
NewObj returns an object whose enumerable members are the key, value pairs, in that order (a later pair for a key replaces the earlier one in place).
func (*Obj) Enumerable ¶
Enumerable reports whether an own member exists and is enumerable.
func (*Obj) Set ¶
Set defines an enumerable member: replaced in place when it exists, appended otherwise.
type Opaque ¶
type Opaque struct {
// Raw is the wire text it came in as (empty for a prototype member); it is written back as it was.
Raw string
}
Opaque is a value the engine never looks into: a function of the extension process (a refinement's check) or an Object.prototype member read through `in`. It has `typeof` "function", so no guard takes it for an object.