engine

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: 13 Imported by: 0

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

Constants

This section is empty.

Variables

View Source
var Undef = &undefined{}

Undef is JavaScript's undefined.

Functions

func C

func C(s string) parser

func Call

func Call(member string, args []any) (result any, err error)

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

func Clone(value any) any

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 Decode

func Decode(text string) (value any, err error)

Decode reads one wire value.

func Discard

func Discard(value any, keys ...string) any

Discard is Memory.Discard(value, keys): a copy without the named members, hidden ones kept as hidden, values cloned.

func Encode

func Encode(value any) string

Encode writes a value in the wire form.

func Has

func Has(member string) bool

Has reports whether member is served by the engine.

func Members

func Members() []string

Members lists the members the engine serves.

func Serve

func Serve(request []byte) []byte

Serve answers one engine request: `{"member": "...", "args": [<wire>, ...]}` with `{"value": <wire>}`, or `{"error": {"name": "...", "message": "..."}}` for what TypeBox throws. A request that is not that is an error too.

func Update

func Update(current any, hidden, enumerable any) any

Update is Memory.Update(current, hidden, enumerable): a clone of current with the hidden members defined non-enumerable and the enumerable ones defined enumerable (in place when they exist).

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.

func (*Error) Error

func (e *Error) Error() string

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 Assign

func Assign(left, right any) *Obj

Assign is Memory.Assign(left, right): `{...left, ...right}`.

func Create

func Create(hidden *Obj, enumerable *Obj, options any) *Obj

Create is Memory.Create(hidden, enumerable, options): `{...enumerable, ...options}` with the hidden members defined non-enumerable.

func NewObj

func NewObj(pairs ...any) *Obj

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) EnumKeys

func (o *Obj) EnumKeys() []string

EnumKeys is Object.keys.

func (*Obj) Enumerable

func (o *Obj) Enumerable(name string) bool

Enumerable reports whether an own member exists and is enumerable.

func (*Obj) Get

func (o *Obj) Get(name string) (any, bool)

Get returns an own member (hidden ones too).

func (*Obj) Has

func (o *Obj) Has(name string) bool

Has reports an own member, hidden or not.

func (*Obj) Keys

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

Keys is Object.getOwnPropertyNames: every own member name, hidden ones included.

func (*Obj) Set

func (o *Obj) Set(name string, value any)

Set defines an enumerable member: replaced in place when it exists, appended otherwise.

func (*Obj) SetHidden

func (o *Obj) SetHidden(name string, value any)

SetHidden defines a non-enumerable member.

func (*Obj) Value

func (o *Obj) Value(name string) any

Value is an own member's value, undefined when absent (the read `obj[name]` of a member that exists or not).

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.

Jump to

Keyboard shortcuts

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