core

package
v0.18.0 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2023 License: Apache-2.0 Imports: 10 Imported by: 113

Documentation

Index

Constants

View Source
const (
	IgnorableVariable = "_"
)
View Source
const MaxArgs = 65536

Variables

View Source
var (
	ErrMissedArgument        = errors.New("missed argument")
	ErrInvalidArgument       = errors.New("invalid argument")
	ErrInvalidArgumentNumber = errors.New("invalid argument number")
	ErrInvalidType           = errors.New("invalid type")
	ErrInvalidOperation      = errors.New("invalid operation")
	ErrNotFound              = errors.New("not found")
	ErrNotUnique             = errors.New("not unique")
	ErrTerminated            = errors.New("operation is terminated")
	ErrUnexpected            = errors.New("unexpected error")
	ErrTimeout               = errors.New("operation timed out")
	ErrNotImplemented        = errors.New("not implemented")
	ErrNotSupported          = errors.New("not supported")
	ErrNoMoreData            = errors.New("no more data")
	ErrInvalidPath           = errors.New("cannot read property")
	ErrDone                  = errors.New("operation done")
)

Functions

func Error

func Error(err error, msg string) error

func Errorf added in v0.4.0

func Errorf(err error, format string, args ...interface{}) error

func Errors

func Errors(err ...error) error

func ForEach added in v0.12.0

func ForEach(ctx context.Context, iter Iterator, predicate func(value Value, key Value) bool) error

func IsDone added in v0.16.0

func IsDone(err error) bool

func IsNil

func IsNil(input interface{}) bool

func IsNoMoreData added in v0.8.0

func IsNoMoreData(err error) bool

func IsTypeOf

func IsTypeOf(value Value, check Type) bool

IsTypeOf return true when value's type is equal to check type. Returns false, otherwise.

func NewRootScope

func NewRootScope() (*Scope, CloseFunc)

func NumberBoundaries added in v0.8.0

func NumberBoundaries(input float64) (max float64, min float64)

func NumberLowerBoundary added in v0.9.0

func NumberLowerBoundary(input float64) float64

func NumberUpperBoundary added in v0.9.0

func NumberUpperBoundary(input float64) float64

func ParamsFrom

func ParamsFrom(ctx context.Context) (map[string]Value, error)

func ParamsWith

func ParamsWith(ctx context.Context, params map[string]Value) context.Context

func Random added in v0.8.0

func Random(max float64, min float64) float64

func Random2 added in v0.15.0

func Random2(mid float64) float64

func RandomDefault added in v0.14.0

func RandomDefault() float64

func SourceError

func SourceError(src SourceMap, err error) error

func TypeError

func TypeError(actual Type, expected ...Type) error

func ValidateArgs

func ValidateArgs(args []Value, minimum, maximum int) error

func ValidateType

func ValidateType(value Value, required ...Type) error

ValidateType checks the match of value's type and required types.

func ValidateValueTypePairs added in v0.5.0

func ValidateValueTypePairs(pairs ...PairValueType) error

ValidateValueTypePairs validate pairs of Values and Types. Returns error when type didn't match

Types

type BaseType added in v0.7.0

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

func (BaseType) Equals added in v0.7.0

func (t BaseType) Equals(other Type) bool

func (BaseType) ID added in v0.7.0

func (t BaseType) ID() int64

func (BaseType) String added in v0.7.0

func (t BaseType) String() string

type Cloneable

type Cloneable interface {
	Value
	Clone() Cloneable
}

type CloseFunc

type CloseFunc func() error

type Expression

type Expression interface {
	Exec(ctx context.Context, scope *Scope) (Value, error)
}

func AsExpression added in v0.16.0

func AsExpression(fn func(ctx context.Context, scope *Scope) (Value, error)) Expression

type ExpressionFn added in v0.16.0

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

func (*ExpressionFn) Exec added in v0.16.0

func (f *ExpressionFn) Exec(ctx context.Context, scope *Scope) (Value, error)

type Function

type Function = func(ctx context.Context, args ...Value) (Value, error)

Function is a common interface for all functions of FQL.

type Functions added in v0.8.0

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

Functions is a container for functions.

func NewFunctions added in v0.10.0

func NewFunctions() *Functions

NewFunctions returns new empty Functions.

func NewFunctionsFromMap added in v0.10.0

func NewFunctionsFromMap(funcs map[string]Function) *Functions

NewFunctionsFromMap creates new Functions from map, where key is the name of the function and value is the function.

func (*Functions) Get added in v0.10.0

func (fns *Functions) Get(name string) (Function, bool)

Get returns the function with the given name. If the function does not exist it returns nil, false.

func (*Functions) Names added in v0.10.0

func (fns *Functions) Names() []string

Names returns the names of the internal functions.

func (*Functions) Set added in v0.10.0

func (fns *Functions) Set(name string, fn Function)

Set sets the function with the given name. If the function with the such name already exists it will be overwritten.

func (*Functions) Unset added in v0.10.0

func (fns *Functions) Unset(name string)

Unset delete the function with the given name.

type Getter added in v0.6.0

type Getter interface {
	GetIn(ctx context.Context, path []Value) (Value, PathError)
}

Getter represents an interface of complex types that needs to be used to read values by path. The interface is created to let user-defined types be used in dot notation data access.

type GetterFn added in v0.16.0

type GetterFn func(ctx context.Context, path []Value, src Getter) (Value, PathError)

GetterFn represents a type of helper functions that implement complex path resolutions.

type GetterPathIterator added in v0.16.0

type GetterPathIterator interface {
	Path() []Value
	Current() Value
	CurrentIndex() int
}

type Iterable added in v0.7.0

type Iterable interface {
	Iterate(ctx context.Context) (Iterator, error)
}

Iterable represents an interface of a value that can be iterated by using an iterator.

type Iterator added in v0.7.0

type Iterator interface {
	Next(ctx context.Context) (value Value, key Value, err error)
}

Iterator represents an interface of a value iterator. When iterator is exhausted it must return None as a value.

type Namespace added in v0.8.0

type Namespace interface {
	Namespace(name string) Namespace
	RegisterFunction(name string, fun Function) error
	RegisterFunctions(funs *Functions) error
	RegisteredFunctions() []string
	RemoveFunction(name string)
}

type NativePathError added in v0.16.0

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

NativePathError represents a default implementation of GetterError interface.

func (*NativePathError) Cause added in v0.16.0

func (e *NativePathError) Cause() error

func (*NativePathError) Error added in v0.16.0

func (e *NativePathError) Error() string

func (*NativePathError) Format added in v0.16.0

func (e *NativePathError) Format(path []Value) string

func (*NativePathError) Segment added in v0.16.0

func (e *NativePathError) Segment() int

type PairValueType added in v0.5.0

type PairValueType struct {
	Value Value
	Types []Type
}

PairValueType is a supporting structure that used in validateValueTypePairs.

func NewPairValueType added in v0.10.0

func NewPairValueType(value Value, types ...Type) PairValueType

NewPairValueType it's a shortcut for creating a new PairValueType.

The common pattern of using PairValueType is: ```

pairs := []core.PairValueType{
    core.PairValueType{args[0], []core.Type{types.String}},               // go vet warning
    core.PairValueType{Value: args[1], Types: []core.Type{types.Binary}}, // too long
}

``` With NewPairValueType there is no need to type `[]core.Type{...}` and code becomes more readable and maintainable.

That is how the code above looks like with NewPairValueType: ```

pairs := []core.PairValueType{
    core.NewPairValueType(args[0], types.String),
    core.NewPairValueType(args[1], types.Binary),
}

```

type PathError added in v0.16.0

type PathError interface {
	error
	Cause() error
	Segment() int
	Format(path []Value) string
}

PathError represents an interface of error type which returned when an error occurs during an execution of Getter.GetIn or Setter.SetIn functions and contains segment of a given path that caused the error.

func NewPathError added in v0.16.0

func NewPathError(err error, segment int) PathError

NewPathError is a constructor function of NativePathError struct.

func NewPathErrorFrom added in v0.16.0

func NewPathErrorFrom(err PathError, segment int) PathError

NewPathErrorFrom is a constructor function of NativePathError struct that accepts nested PathError and original segment index. It sums indexes to get the correct one that points to original path.

type Predicate added in v0.16.0

type Predicate interface {
	Expression
	Eval(ctx context.Context, left, right Value) (Value, error)
}

type RootScope added in v0.5.0

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

func (*RootScope) AddDisposable added in v0.5.0

func (s *RootScope) AddDisposable(disposable io.Closer)

func (*RootScope) Close added in v0.5.0

func (s *RootScope) Close() error

type Scope

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

func (*Scope) Fork

func (s *Scope) Fork() *Scope

func (*Scope) GetVariable

func (s *Scope) GetVariable(name string) (Value, error)

func (*Scope) HasVariable

func (s *Scope) HasVariable(name string) bool

func (*Scope) MustGetVariable added in v0.5.0

func (s *Scope) MustGetVariable(name string) Value

func (*Scope) SetVariable

func (s *Scope) SetVariable(name string, val Value) error

func (*Scope) UpdateVariable added in v0.5.0

func (s *Scope) UpdateVariable(name string, val Value) error

type Setter added in v0.6.0

type Setter interface {
	SetIn(ctx context.Context, path []Value, value Value) PathError
}

Setter represents an interface of complex types that needs to be used to write values by path. The interface is created to let user-defined types be used in dot notation assignment.

type SourceErrorDetail added in v0.15.0

type SourceErrorDetail struct {
	BaseError    error
	ComputeError error
	// contains filtered or unexported fields
}

func (*SourceErrorDetail) Error added in v0.15.0

func (e *SourceErrorDetail) Error() string

type SourceMap

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

func NewSourceMap

func NewSourceMap(text string, line, col int) SourceMap

func (SourceMap) Column

func (s SourceMap) Column() int

func (SourceMap) Line

func (s SourceMap) Line() int

func (SourceMap) String

func (s SourceMap) String() string

type Type

type Type interface {
	ID() int64
	String() string
	Equals(other Type) bool
}

func NewType added in v0.7.0

func NewType(name string) Type

type Value

type Value interface {
	json.Marshaler
	Type() Type
	String() string
	Compare(other Value) int64
	Unwrap() interface{}
	Hash() uint64
	Copy() Value
}

Value represents an interface of any type that needs to be used during runtime

func ParamFrom

func ParamFrom(ctx context.Context, name string) (Value, error)

Jump to

Keyboard shortcuts

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