Documentation ¶
Index ¶
- Constants
- Variables
- func AssertKindsMatch(left, right Value) error
- func Compatible(val Value, kind Kind) bool
- func Escape(s string) string
- func IsDefined(val Value) bool
- func IsLookupSupported(left Value) bool
- func IsObjectLike(v Value) bool
- func IsSimpleKind(kind Kind) bool
- func Keys(right Value) ([]string, error)
- func KeysIfSupported(right Value) ([]string, error)
- func Match(pattern, value Value) (bool, error)
- func NativeValue(v Value) (any, bool, error)
- func NewErrPosition(pos Position, err error) error
- func TargetCompatible(schema Schema, target Value) bool
- func ToArray(v Value) ([]any, error)
- func ToBool(v Value) (bool, error)
- func ToFloat(v Value) (float64, error)
- func ToInt(v Value) (int64, error)
- func ToKind(v Value, kind Kind) (any, error)
- func ToString(v Value) (string, error)
- func Unquote(s string) (string, error)
- func WithCallPath(ctx context.Context) context.Context
- func WithDataIndexPath(ctx context.Context, idx int) context.Context
- func WithDataKeyPath(ctx context.Context, key string) context.Context
- func WithIndexPath(ctx context.Context, idx int) context.Context
- func WithKeyPath(ctx context.Context, key string) context.Context
- type Adder
- type AllBinaryOps
- type AllOps
- type AllUnaryOps
- type Ander
- type Array
- func (a Array) Add(right Value) (Value, error)
- func (a Array) Eq(right Value) (Value, error)
- func (a Array) GetUndefined() Value
- func (a Array) Index(idxValue Value) (Value, bool, error)
- func (a Array) IsDefined() bool
- func (a Array) Kind() Kind
- func (a Array) Len() (Value, error)
- func (a Array) NativeValue() (any, bool, error)
- func (a Array) Slice(start, end int) (Value, bool, error)
- func (a Array) String() string
- func (a Array) ToValues() []Value
- type ArraySchema
- type Boolean
- func (n Boolean) And(deferredRight Valuer) (Value, error)
- func (n Boolean) Eq(right Value) (Value, error)
- func (n Boolean) IsTrue() bool
- func (n Boolean) Kind() Kind
- func (n Boolean) NativeValue() (any, bool, error)
- func (n Boolean) Neq(right Value) (Value, error)
- func (n Boolean) Not() (Value, error)
- func (n Boolean) Or(deferredRight Valuer) (Value, error)
- func (n Boolean) String() string
- type CallArgument
- type Caller
- type Compatibler
- type Condition
- type Constraint
- type Constraints
- type CustomConstraint
- type Defaulter
- type Deferred
- func (d Deferred) Add(right Value) (Value, error)
- func (d Deferred) And(right Valuer) (Value, error)
- func (d Deferred) Call(ctx context.Context, args []CallArgument) (Value, bool, error)
- func (d Deferred) Default() (Value, bool, error)
- func (d Deferred) Div(right Value) (Value, error)
- func (d Deferred) Eq(right Value) (Value, error)
- func (d Deferred) Ge(right Value) (Value, error)
- func (d Deferred) Gt(right Value) (Value, error)
- func (d Deferred) Index(key Value) (Value, bool, error)
- func (d Deferred) Keys() ([]string, error)
- func (d Deferred) Kind() Kind
- func (d Deferred) Le(right Value) (Value, error)
- func (d Deferred) Len() (Value, error)
- func (d Deferred) LookupValue(key Value) (Value, bool, error)
- func (d Deferred) Lt(right Value) (Value, error)
- func (d Deferred) MarshalJSON() ([]byte, error)
- func (d Deferred) Mat(right Value) (Value, error)
- func (d Deferred) Match(value Value) (bool, error)
- func (d Deferred) Merge(val Value) (Value, error)
- func (d Deferred) Mul(right Value) (Value, error)
- func (d Deferred) NativeValue() (any, bool, error)
- func (d Deferred) Neq(right Value) (Value, error)
- func (d Deferred) Nmat(right Value) (Value, error)
- func (d Deferred) Not() (Value, error)
- func (d Deferred) Or(right Valuer) (Value, error)
- func (d Deferred) Slice(start, end int) (Value, bool, error)
- func (d Deferred) String() string
- func (d Deferred) Sub(right Value) (Value, error)
- func (d Deferred) ToFloat() (float64, error)
- func (d Deferred) ToInt() (int64, error)
- type DeferredAnder
- type DeferredOrer
- type Diver
- type Entry
- type Eqer
- type ErrMissingRequiredKeys
- type ErrPosition
- type ErrSchemaViolation
- type ErrUnknownField
- type ErrUnmatchedType
- type FuncSchema
- type Geer
- type Gter
- type Indexer
- type KeyList
- type Keyser
- type Kind
- type Leer
- type Lener
- type LookupValue
- type Lter
- type Matcher
- type Mater
- type Merger
- type Muler
- type Name
- type Names
- type Neqer
- type Nmater
- type Noter
- type Null
- type Number
- func (n Number) Add(right Value) (Value, error)
- func (n Number) Div(right Value) (Value, error)
- func (n Number) Eq(right Value) (Value, error)
- func (n Number) Ge(right Value) (Value, error)
- func (n Number) Gt(right Value) (Value, error)
- func (n Number) Kind() Kind
- func (n Number) Le(right Value) (Value, error)
- func (n Number) Lt(right Value) (Value, error)
- func (n Number) MarshalJSON() ([]byte, error)
- func (n Number) Mul(right Value) (Value, error)
- func (n Number) NativeValue() (any, bool, error)
- func (n Number) Neq(right Value) (Value, error)
- func (n Number) Sub(right Value) (Value, error)
- func (n Number) ToFloat() (float64, error)
- func (n Number) ToInt() (int64, error)
- type Object
- func (n *Object) Add(right Value) (Value, error)
- func (n *Object) Eq(right Value) (Value, error)
- func (n *Object) GetUndefined() Value
- func (n *Object) IsDefined() bool
- func (n *Object) Keys() ([]string, error)
- func (n *Object) Kind() Kind
- func (n *Object) Len() (Value, error)
- func (n *Object) LookupValue(key Value) (Value, bool, error)
- func (n *Object) MarshalJSON() ([]byte, error)
- func (n *Object) Merge(right Value) (Value, error)
- func (n *Object) NativeValue() (any, bool, error)
- func (n *Object) String() string
- type ObjectFunc
- type ObjectMerge
- type ObjectSchema
- type ObjectSchemaField
- type Operator
- type Orer
- type Path
- type PathElement
- type Position
- type RightMergePriority
- type RightMerger
- type Schema
- type Slicer
- type String
- func (s String) Add(right Value) (Value, error)
- func (s String) Eq(right Value) (Value, error)
- func (s String) Index(key Value) (Value, bool, error)
- func (s String) Kind() Kind
- func (s String) Len() (Value, error)
- func (s String) Mat(right Value) (Value, error)
- func (s String) Match(right Value) (bool, error)
- func (s String) NativeValue() (any, bool, error)
- func (s String) Neq(right Value) (Value, error)
- func (s String) Nmat(right Value) (Value, error)
- type Suber
- type Summary
- type TargetCompatibler
- type ToFloater
- type ToInter
- type ToNative
- type ToSchemaFunc
- type TypeSchema
- func (n *TypeSchema) And(right Value) (Value, error)
- func (n *TypeSchema) Call(ctx context.Context, args []CallArgument) (Value, bool, error)
- func (n *TypeSchema) Default() (Value, bool, error)
- func (n *TypeSchema) DefaultWithImplicit(renderImplicit bool) (Value, bool, error)
- func (n *TypeSchema) Eq(right Value) (Value, error)
- func (n *TypeSchema) Ge(right Value) (Value, error)
- func (n *TypeSchema) GetPath() Path
- func (n *TypeSchema) GetPositions() []Position
- func (n *TypeSchema) Gt(right Value) (Value, error)
- func (n *TypeSchema) Keys() (result []string, _ error)
- func (n *TypeSchema) Kind() Kind
- func (n *TypeSchema) Le(right Value) (Value, error)
- func (n *TypeSchema) LookupValue(key Value) (Value, bool, error)
- func (n *TypeSchema) Lt(right Value) (Value, error)
- func (n *TypeSchema) Mat(right Value) (Value, error)
- func (n *TypeSchema) Merge(right Value) (Value, error)
- func (n *TypeSchema) MergeType(rightSchema Schema) (Schema, error)
- func (n *TypeSchema) NativeValue() (any, bool, error)
- func (n *TypeSchema) Neq(right Value) (Value, error)
- func (n *TypeSchema) Nmat(right Value) (Value, error)
- func (n *TypeSchema) Or(right Value) (Value, error)
- func (n *TypeSchema) RightMerge(right Value) (Value, error)
- func (n *TypeSchema) RightMergePriority() RightMergePriority
- func (n *TypeSchema) String() string
- func (n *TypeSchema) TargetKind() Kind
- func (n *TypeSchema) ValidArrayItems() (result []Schema)
- func (n *TypeSchema) Validate(ctx context.Context, right Value) (Value, error)
- type Undefined
- func (u Undefined) Eq(v Value) (Value, error)
- func (u Undefined) IsDefined() bool
- func (u Undefined) Kind() Kind
- func (u Undefined) LookupValue(key Value) (Value, bool, error)
- func (u Undefined) Merge(val Value) (Value, error)
- func (u Undefined) NativeValue() (any, bool, error)
- func (u Undefined) RightMerge(val Value) (Value, error)
- func (u Undefined) RightMergePriority() RightMergePriority
- func (u Undefined) String() string
- type Value
- func Add(left, right Value) (Value, error)
- func And(left Value, right Valuer) (Value, error)
- func BinaryOperation(op Operator, left Value, deferredRight Valuer) (Value, error)
- func Call(ctx context.Context, value Value, args ...CallArgument) (_ Value, _ bool, ret error)
- func DefaultValue(v Value) (Value, bool, error)
- func Div(left, right Value) (Value, error)
- func Eq(left, right Value) (Value, error)
- func Ge(left, right Value) (Value, error)
- func GetUndefined(vals ...Value) Value
- func Gt(left, right Value) (Value, error)
- func Index(left, key Value) (Value, bool, error)
- func IsUndefined(vals ...Value) Value
- func Le(left, right Value) (Value, error)
- func Len(left Value) (Value, error)
- func Lookup(left, key Value) (Value, bool, error)
- func Lt(left, right Value) (Value, error)
- func Mat(left, right Value) (Value, error)
- func Merge(values ...Value) (result Value, err error)
- func MergeObjectMerger(left, right Value) (newValue Value, changed bool, _ error)
- func MergeObjects(left, right Value, allowNewKeys bool, merger ObjectMerge) (merged Value, changed bool, _ error)
- func Mul(left, right Value) (Value, error)
- func Neq(left, right Value) (Value, error)
- func NewDefault(pos Position, v Value) Value
- func NewMatchTypeWithDefault(pos Position, v Value) Value
- func NewValue(v any) Value
- func Nmat(left, right Value) (Value, error)
- func Not(right Value) (Value, error)
- func Or(left Value, right Valuer) (Value, error)
- func SchemaOr(left Schema, right Value) (Value, error)
- func Slice(left, start, end Value) (Value, bool, error)
- func Sub(left, right Value) (Value, error)
- func ToValueArray(v Value) ([]Value, error)
- func UnaryOperation(op Operator, val Value) (Value, error)
- func Validate(ctx context.Context, schema Value, v Value) (Value, error)
- type Valuer
Constants ¶
View Source
const ( MustBeIntOp = "mustBeInt" MustMatchAlternateOp = "mustMatchAlternate" MustMatchSchema = "mustMatchSchema" )
View Source
const ( UndefinedPriority = RightMergePriority(20) LoopControlPriority = RightMergePriority(10) DefaultedPriority = RightMergePriority(0) TypeSchemaPriority = RightMergePriority(5) )
View Source
const ( AddOp = Operator("+") SubOp = Operator("-") MulOp = Operator("*") DivOp = Operator("/") AndOp = Operator("&&") OrOp = Operator("||") LtOp = Operator("<") LeOp = Operator("<=") GtOp = Operator(">") GeOp = Operator(">=") EqOp = Operator("==") NeqOp = Operator("!=") NotOp = Operator("!") MatOp = Operator("=~") NmatOp = Operator("!~") )
Variables ¶
View Source
var ( True = Boolean(true) False = Boolean(false) )
View Source
var BuiltinKinds = []Kind{ NullKind, StringKind, BoolKind, NumberKind, ArrayKind, ObjectKind, FuncKind, SchemaKind, }
View Source
var ErrMustMatchAlternate = errors.New("must match alternate")
View Source
var NoPosition = Position{}
Functions ¶
func AssertKindsMatch ¶
func Compatible ¶
func IsLookupSupported ¶
func IsObjectLike ¶
func IsSimpleKind ¶
IsSimpleKind returns true if the kind is a string, number, or bool.
func KeysIfSupported ¶
func NewErrPosition ¶
func TargetCompatible ¶
Types ¶
type AllBinaryOps ¶
type AllOps ¶
type AllOps interface { AllUnaryOps AllBinaryOps Slicer Caller Indexer Lener LookupValue ToFloater ToInter ToNative Merger Defaulter Matcher Keyser }
type AllUnaryOps ¶
type ArraySchema ¶
type ArraySchema struct { Positions []Position `json:"-"` Description string `json:"description"` Valid []Schema `json:"valid"` }
func (*ArraySchema) ImpliedDefault ¶
func (n *ArraySchema) ImpliedDefault() (Value, bool, error)
func (*ArraySchema) Merge ¶
func (a *ArraySchema) Merge(right *ArraySchema) (*ArraySchema, error)
type CallArgument ¶
type Compatibler ¶
type Constraint ¶
func MustMatchAlternate ¶
func MustMatchAlternate() []Constraint
type Constraints ¶
type Constraints []Constraint
type CustomConstraint ¶
type CustomConstraint struct { CustomID string CustomDescription string Checker func(left Value) error }
func (*CustomConstraint) Check ¶
func (c *CustomConstraint) Check(left Value) error
func (*CustomConstraint) Description ¶
func (c *CustomConstraint) Description() string
func (*CustomConstraint) ID ¶
func (c *CustomConstraint) ID() string
func (*CustomConstraint) OpString ¶
func (c *CustomConstraint) OpString() string
func (*CustomConstraint) RightNative ¶
func (c *CustomConstraint) RightNative() (any, bool, error)
type DeferredAnder ¶
type DeferredOrer ¶
type ErrMissingRequiredKeys ¶
func (*ErrMissingRequiredKeys) Error ¶
func (e *ErrMissingRequiredKeys) Error() string
type ErrPosition ¶
func (*ErrPosition) Error ¶
func (e *ErrPosition) Error() string
func (*ErrPosition) Pos ¶
func (e *ErrPosition) Pos() Position
func (*ErrPosition) Unwrap ¶
func (e *ErrPosition) Unwrap() error
type ErrSchemaViolation ¶
func (*ErrSchemaViolation) Error ¶
func (e *ErrSchemaViolation) Error() string
func (*ErrSchemaViolation) Unwrap ¶
func (e *ErrSchemaViolation) Unwrap() error
type ErrUnknownField ¶
func (*ErrUnknownField) Error ¶
func (e *ErrUnknownField) Error() string
type ErrUnmatchedType ¶
func (*ErrUnmatchedType) Error ¶
func (e *ErrUnmatchedType) Error() string
func (*ErrUnmatchedType) Pos ¶
func (e *ErrUnmatchedType) Pos() Position
func (*ErrUnmatchedType) Unwrap ¶
func (e *ErrUnmatchedType) Unwrap() []error
type FuncSchema ¶
type FuncSchema struct { Args []ObjectSchemaField `json:"args"` ProfileNames Names `json:"profileNames"` Returns ToSchemaFunc `json:"returns,omitempty"` }
func (*FuncSchema) MarshalJSON ¶
func (f *FuncSchema) MarshalJSON() ([]byte, error)
type Object ¶
type Object struct {
Entries []Entry
}
func (*Object) GetUndefined ¶
func (*Object) MarshalJSON ¶
type ObjectFunc ¶
func (ObjectFunc) Call ¶
func (o ObjectFunc) Call(ctx context.Context, args []CallArgument) (Value, bool, error)
func (ObjectFunc) Kind ¶
func (o ObjectFunc) Kind() Kind
type ObjectSchema ¶
type ObjectSchema struct { Positions []Position `json:"-"` AllowNewKeys bool `json:"allowNewKeys"` Description string `json:"description"` Fields []ObjectSchemaField `json:"fields"` }
func (*ObjectSchema) ImpliedDefault ¶
func (n *ObjectSchema) ImpliedDefault() (Value, bool, error)
func (*ObjectSchema) Merge ¶
func (n *ObjectSchema) Merge(right *ObjectSchema) (*ObjectSchema, error)
type ObjectSchemaField ¶
type PathElement ¶
func (PathElement) Equals ¶
func (p PathElement) Equals(right PathElement) bool
type Position ¶
type RightMergePriority ¶
type RightMergePriority int
type RightMerger ¶
type RightMerger interface { RightMergePriority() RightMergePriority RightMerge(val Value) (Value, error) }
type TargetCompatibler ¶
type TypeSchema ¶
type TypeSchema struct { Positions []Position `json:"-"` KindValue Kind `json:"kindValue"` Object *ObjectSchema `json:"object"` Array *ArraySchema `json:"array"` FuncSchema *FuncSchema `json:"func"` Constraints []Constraint `json:"constraints"` Alternates []Schema `json:"alternates"` DefaultValue Value `json:"defaultValue"` Path Path `json:"path"` Reference bool `json:"reference"` // contains filtered or unexported fields }
func NewClosedObject ¶
func NewClosedObject() *TypeSchema
func NewOpenObject ¶
func NewOpenObject() *TypeSchema
func (*TypeSchema) Call ¶
func (n *TypeSchema) Call(ctx context.Context, args []CallArgument) (Value, bool, error)
func (*TypeSchema) DefaultWithImplicit ¶
func (n *TypeSchema) DefaultWithImplicit(renderImplicit bool) (Value, bool, error)
func (*TypeSchema) GetPath ¶
func (n *TypeSchema) GetPath() Path
func (*TypeSchema) GetPositions ¶
func (n *TypeSchema) GetPositions() []Position
func (*TypeSchema) Keys ¶
func (n *TypeSchema) Keys() (result []string, _ error)
func (*TypeSchema) Kind ¶
func (n *TypeSchema) Kind() Kind
func (*TypeSchema) LookupValue ¶
func (n *TypeSchema) LookupValue(key Value) (Value, bool, error)
func (*TypeSchema) NativeValue ¶
func (n *TypeSchema) NativeValue() (any, bool, error)
func (*TypeSchema) RightMerge ¶
func (n *TypeSchema) RightMerge(right Value) (Value, error)
func (*TypeSchema) RightMergePriority ¶
func (n *TypeSchema) RightMergePriority() RightMergePriority
func (*TypeSchema) String ¶
func (n *TypeSchema) String() string
func (*TypeSchema) TargetKind ¶
func (n *TypeSchema) TargetKind() Kind
func (*TypeSchema) ValidArrayItems ¶
func (n *TypeSchema) ValidArrayItems() (result []Schema)
type Undefined ¶
func (Undefined) RightMergePriority ¶
func (u Undefined) RightMergePriority() RightMergePriority
type Value ¶
type Value interface {
Kind() Kind
}
func BinaryOperation ¶
func GetUndefined ¶
func IsUndefined ¶
IsUndefined is a small helper to check if any of the passed values are undefined
func MergeObjectMerger ¶
func MergeObjects ¶
func NewDefault ¶
func NewMatchTypeWithDefault ¶
func ToValueArray ¶
Click to show internal directories.
Click to hide internal directories.