Documentation ¶
Overview ¶
Package query provides a parser for the right-hand side query part of the bloblang spec. This is useful as a separate package as it is used in isolation within interpolation functions.
Index ¶
- Variables
- func ErrFrom(err error, from Function) error
- func ExecToBytes(fn Function, ctx FunctionContext) []byte
- func ExecToString(fn Function, ctx FunctionContext) string
- func IClone(root interface{}) interface{}
- func IGetBool(v interface{}) (bool, error)
- func IGetBytes(v interface{}) ([]byte, error)
- func IGetInt(v interface{}) (int64, error)
- func IGetNumber(v interface{}) (float64, error)
- func IGetString(v interface{}) (string, error)
- func IGetTimestamp(v interface{}) (time.Time, error)
- func IIsNull(i interface{}) bool
- func ISanitize(i interface{}) interface{}
- func IToBool(v interface{}) (bool, error)
- func IToBytes(i interface{}) []byte
- func IToInt(v interface{}) (int64, error)
- func IToNumber(v interface{}) (float64, error)
- func IToString(i interface{}) string
- func ListFunctions() []string
- func ListMethods() []string
- func NewArrayLiteral(values ...interface{}) interface{}
- func NewMapLiteral(values [][2]interface{}) (interface{}, error)
- func RegisterFunction(spec FunctionSpec, autoResolveFunctionArgs bool, ctor FunctionCtor, ...) struct{}
- func SliceToDotPath(path ...string) string
- type ArgCheckFn
- func ExpectAllStringArgs() ArgCheckFn
- func ExpectAtLeastOneArg() ArgCheckFn
- func ExpectBetweenNAndMArgs(n, m int) ArgCheckFn
- func ExpectBoolArg(i int) ArgCheckFn
- func ExpectFloatArg(i int) ArgCheckFn
- func ExpectFunctionArg(i int) ArgCheckFn
- func ExpectIntArg(i int) ArgCheckFn
- func ExpectNArgs(i int) ArgCheckFn
- func ExpectOneOrZeroArgs() ArgCheckFn
- func ExpectStringArg(i int) ArgCheckFn
- type ArithmeticOperator
- type Delete
- type ElseIf
- type ErrRecoverable
- type ExampleSpec
- type Function
- func ClosureFunction(annotation string, exec func(ctx FunctionContext) (interface{}, error), ...) Function
- func DeprecatedFunction(name, arg string) (Function, bool)
- func InitFunction(name string, args ...interface{}) (Function, error)
- func InitMethod(name string, target Function, args ...interface{}) (Function, error)
- func NewArithmeticExpression(fns []Function, ops []ArithmeticOperator) (Function, error)
- func NewFieldFunction(pathStr string) Function
- func NewGetMethod(target Function, path string) (Function, error)
- func NewIfFunction(queryFn, ifFn Function, elseIfs []ElseIf, elseFn Function) Function
- func NewMapMethod(target, mapArg Function) (Function, error)
- func NewMatchFunction(contextFn Function, cases ...MatchCase) Function
- func NewNamedContextFieldFunction(namedContext, pathStr string) Function
- func NewNamedContextFunction(name string, fn Function) Function
- func NewVarFunction(path string) Function
- func Not(fn Function) Function
- type FunctionCategory
- type FunctionContext
- func (ctx FunctionContext) IncrStackCount() (FunctionContext, int)
- func (ctx FunctionContext) NamedValue(name string) (interface{}, bool)
- func (ctx FunctionContext) PopValue() (*interface{}, FunctionContext)
- func (ctx FunctionContext) Value() *interface{}
- func (ctx FunctionContext) WithNamedValue(name string, value interface{}) FunctionContext
- func (ctx FunctionContext) WithValue(value interface{}) FunctionContext
- func (ctx FunctionContext) WithValueFunc(fn func() *interface{}) FunctionContext
- type FunctionCtor
- type FunctionSet
- func (f *FunctionSet) Add(spec FunctionSpec, ctor FunctionCtor, autoResolveFunctionArgs bool, ...) error
- func (f *FunctionSet) Docs() []FunctionSpec
- func (f *FunctionSet) Init(name string, args ...interface{}) (Function, error)
- func (f *FunctionSet) List() []string
- func (f *FunctionSet) NoMessage() *FunctionSet
- func (f *FunctionSet) OnlyPure() *FunctionSet
- func (f *FunctionSet) Without(functions ...string) *FunctionSet
- type FunctionSpec
- type Iterable
- type Iterator
- type Literal
- type MatchCase
- type MessageBatch
- type MethodCatSpec
- type MethodCategory
- type MethodCtor
- type MethodSet
- func (m *MethodSet) Add(spec MethodSpec, ctor MethodCtor, autoResolveFunctionArgs bool, ...) error
- func (m *MethodSet) Docs() []MethodSpec
- func (m *MethodSet) Init(name string, target Function, args ...interface{}) (Function, error)
- func (m *MethodSet) List() []string
- func (m *MethodSet) Without(methods ...string) *MethodSet
- type MethodSpec
- type NamedContextFunction
- type Nothing
- type Status
- type TargetPath
- type TargetType
- type TargetsContext
- func (ctx TargetsContext) MainContext() []TargetPath
- func (ctx TargetsContext) NamedContext(name string) []TargetPath
- func (ctx TargetsContext) PopContext() TargetsContext
- func (ctx TargetsContext) Value() []TargetPath
- func (ctx TargetsContext) WithContextAsNamed(name string) TargetsContext
- func (ctx TargetsContext) WithValues(paths []TargetPath) TargetsContext
- func (ctx TargetsContext) WithValuesAsContext() TargetsContext
- type TypeError
- type TypeMismatch
- type ValueType
Constants ¶
This section is empty.
Variables ¶
var AllFunctions = NewFunctionSet()
AllFunctions is a set containing every single function declared by this package, and any globally declared plugin methods.
var AllMethods = NewMethodSet()
AllMethods is a set containing every single method declared by this package, and any globally declared plugin methods.
var ErrDivideByZero = errors.New("attempted to divide by zero")
ErrDivideByZero occurs when an arithmetic operator is prevented from dividing a value by zero.
var (
ErrNoContext = errors.New("context was undefined")
)
Common query errors.
Functions ¶
func ExecToBytes ¶
func ExecToBytes(fn Function, ctx FunctionContext) []byte
ExecToBytes returns a byte slice from a function exection.
func ExecToString ¶
func ExecToString(fn Function, ctx FunctionContext) string
ExecToString returns a string from a function exection.
func IClone ¶
func IClone(root interface{}) interface{}
IClone performs a deep copy of a generic value.
func IGetBytes ¶ added in v3.40.0
IGetBytes takes a boxed value and attempts to return a byte slice value. Returns an error if the value is not a string or byte slice.
func IGetNumber ¶
IGetNumber takes a boxed value and attempts to extract a number (float64) from it.
func IGetString ¶
IGetString takes a boxed value and attempts to return a string value. Returns an error if the value is not a string or byte slice.
func IGetTimestamp ¶ added in v3.40.0
IGetTimestamp takes a boxed value and attempts to coerce it into a timestamp, either by interpretting a numerical value as a unix timestamp, or by parsing a string value as RFC3339Nano.
func IIsNull ¶
func IIsNull(i interface{}) bool
IIsNull returns whether a bloblang type is null, this includes Delete and Nothing types.
func ISanitize ¶
func ISanitize(i interface{}) interface{}
ISanitize takes a boxed value of any type and attempts to convert it into one of the following types: string, []byte, int64, uint64, float64, bool, []interface{}, map[string]interface{}, Delete, Nothing.
func IToBool ¶
IToBool takes a boxed value and attempts to extract a boolean from it or parse it into a bool.
func IToBytes ¶
func IToBytes(i interface{}) []byte
IToBytes takes a boxed value of any type and attempts to convert it into a byte slice.
func IToInt ¶ added in v3.30.0
IToInt takes a boxed value and attempts to extract a number (int64) from it or parse one.
func IToNumber ¶
IToNumber takes a boxed value and attempts to extract a number (float64) from it or parse one.
func IToString ¶
func IToString(i interface{}) string
IToString takes a boxed value of any type and attempts to convert it into a string.
func ListFunctions ¶
func ListFunctions() []string
ListFunctions returns a slice of function names, sorted alphabetically.
func ListMethods ¶
func ListMethods() []string
ListMethods returns a slice of method names, sorted alphabetically.
func NewArrayLiteral ¶ added in v3.25.0
func NewArrayLiteral(values ...interface{}) interface{}
NewArrayLiteral creates an array literal from a slice of values. If all values are static then a static []interface{} value is returned. However, if any values are dynamic a Function is returned.
func NewMapLiteral ¶ added in v3.25.0
func NewMapLiteral(values [][2]interface{}) (interface{}, error)
NewMapLiteral creates a map literal from a slice of key/value pairs. If all keys and values are static then a static map[string]interface{} value is returned. However, if any keys or values are dynamic a Function is returned.
func RegisterFunction ¶
func RegisterFunction(spec FunctionSpec, autoResolveFunctionArgs bool, ctor FunctionCtor, checks ...ArgCheckFn) struct{}
RegisterFunction to be accessible from Bloblang queries. Returns an empty struct in order to allow inline calls.
func SliceToDotPath ¶ added in v3.43.1
SliceToDotPath returns a valid dot path from a slice of path segments.
Types ¶
type ArgCheckFn ¶
type ArgCheckFn func(args []interface{}) error
ArgCheckFn is an optional argument type checker for a function constructor.
func ExpectAllStringArgs ¶
func ExpectAllStringArgs() ArgCheckFn
ExpectAllStringArgs returns an error if any argument is not a string type (or a byte slice that can be converted).
func ExpectAtLeastOneArg ¶
func ExpectAtLeastOneArg() ArgCheckFn
ExpectAtLeastOneArg returns an error unless >0 arguments are specified.
func ExpectBetweenNAndMArgs ¶ added in v3.27.0
func ExpectBetweenNAndMArgs(n, m int) ArgCheckFn
ExpectBetweenNAndMArgs returns an error unless between N and M arguments are specified.
func ExpectBoolArg ¶
func ExpectBoolArg(i int) ArgCheckFn
ExpectBoolArg returns an error if an argument i is not a boolean type.
func ExpectFloatArg ¶
func ExpectFloatArg(i int) ArgCheckFn
ExpectFloatArg returns an error if an argument i is not a float type.
func ExpectFunctionArg ¶ added in v3.32.0
func ExpectFunctionArg(i int) ArgCheckFn
ExpectFunctionArg ensures that parameters are query functions. If the argument is a static value it will be converted into a literal function.
func ExpectIntArg ¶
func ExpectIntArg(i int) ArgCheckFn
ExpectIntArg returns an error if an argument i is not an integer type.
func ExpectNArgs ¶
func ExpectNArgs(i int) ArgCheckFn
ExpectNArgs returns an error unless exactly N arguments are specified.
func ExpectOneOrZeroArgs ¶
func ExpectOneOrZeroArgs() ArgCheckFn
ExpectOneOrZeroArgs returns an error if more than one arg is specified.
func ExpectStringArg ¶
func ExpectStringArg(i int) ArgCheckFn
ExpectStringArg returns an error if an argument i is not a string type (or a byte slice that can be converted).
type ArithmeticOperator ¶ added in v3.25.0
type ArithmeticOperator int
ArithmeticOperator represents an arithmetic operation that combines the results of two query functions.
const ( ArithmeticAdd ArithmeticOperator = iota ArithmeticSub ArithmeticDiv ArithmeticMul ArithmeticMod ArithmeticEq ArithmeticNeq ArithmeticGt ArithmeticLt ArithmeticGte ArithmeticLte ArithmeticAnd ArithmeticOr ArithmeticPipe )
All arithmetic operators.
func (ArithmeticOperator) String ¶ added in v3.43.1
func (o ArithmeticOperator) String() string
type Delete ¶
type Delete *struct{}
Delete is a special type that serializes to `null` when forced but indicates a target should be deleted.
type ErrRecoverable ¶
type ErrRecoverable struct { Recovered interface{} Err error }
ErrRecoverable represents a function execution error that can optionally be recovered into a zero-value.
func (*ErrRecoverable) Error ¶
func (e *ErrRecoverable) Error() string
Error implements the standard error interface.
func (*ErrRecoverable) Unwrap ¶ added in v3.25.0
func (e *ErrRecoverable) Unwrap() error
Unwrap the error.
type ExampleSpec ¶ added in v3.26.0
ExampleSpec provides a mapping example and some input/output results to display.
func NewExampleSpec ¶ added in v3.26.0
func NewExampleSpec(summary, mapping string, results ...string) ExampleSpec
NewExampleSpec creates a new example spec.
type Function ¶
type Function interface { // Execute this function for a message of a batch. Exec(ctx FunctionContext) (interface{}, error) // Annotation returns a string token to identify the function within error // messages. The returned token is not valid Bloblang and cannot be used to // recreate the function. Annotation() string // Returns a list of targets that this function attempts (or may attempt) to // access. A context must be provided that describes the current execution // context that this function will be executed upon, which is how it is able // to determine the full path and origin of values that it targets. // // A new context is returned which should be provided to methods that act // upon this function when querying their own targets. QueryTargets(ctx TargetsContext) (TargetsContext, []TargetPath) }
Function takes a set of contextual arguments and returns the result of the query.
func ClosureFunction ¶ added in v3.25.0
func ClosureFunction( annotation string, exec func(ctx FunctionContext) (interface{}, error), queryTargets func(ctx TargetsContext) (TargetsContext, []TargetPath), ) Function
ClosureFunction allows you to define a Function using closures, this is a convenient constructor for function implementations that don't manage complex state.
func DeprecatedFunction ¶ added in v3.25.0
DeprecatedFunction attempts to initialize a (now deprecated) old-syntax function.
func InitFunction ¶ added in v3.25.0
InitFunction attempts to initialise a function by its name and arguments.
func InitMethod ¶ added in v3.25.0
InitMethod attempts to initialise a method by its name, target function and arguments.
func NewArithmeticExpression ¶ added in v3.25.0
func NewArithmeticExpression(fns []Function, ops []ArithmeticOperator) (Function, error)
NewArithmeticExpression creates a single query function from a list of child functions and the arithmetic operator types that chain them together. The length of functions must be exactly one fewer than the length of operators.
func NewFieldFunction ¶ added in v3.25.0
NewFieldFunction creates a query function that returns a field from the current context.
func NewGetMethod ¶ added in v3.25.0
NewGetMethod creates a new get method.
func NewIfFunction ¶ added in v3.25.0
NewIfFunction creates a logical if expression from a query which should return a boolean value. If the returned boolean is true then the ifFn is executed and returned, otherwise elseFn is executed and returned.
func NewMapMethod ¶ added in v3.25.0
NewMapMethod attempts to create a map method.
func NewMatchFunction ¶ added in v3.25.0
NewMatchFunction takes a contextual mapping and a list of MatchCases, when the function is executed
func NewNamedContextFieldFunction ¶ added in v3.43.0
NewNamedContextFieldFunction creates a query function that attempts to return a field from a named context.
func NewNamedContextFunction ¶ added in v3.43.0
NewNamedContextFunction wraps a function and ensures that when the function is executed with a new context the context is captured under a new name, with the "main" context left intact.
func NewVarFunction ¶ added in v3.25.0
NewVarFunction creates a new variable function.
type FunctionCategory ¶ added in v3.26.0
type FunctionCategory string
FunctionCategory is an abstract title for functions of a similar purpose.
var ( FunctionCategoryGeneral FunctionCategory = "General" FunctionCategoryMessage FunctionCategory = "Message Info" FunctionCategoryEnvironment FunctionCategory = "Environment" FunctionCategoryDeprecated FunctionCategory = "Deprecated" FunctionCategoryPlugin FunctionCategory = "Plugin" )
Function categories.
type FunctionContext ¶
type FunctionContext struct { Maps map[string]Function Vars map[string]interface{} Index int MsgBatch MessageBatch Legacy bool // Reference new message being mapped NewMsg types.Part // contains filtered or unexported fields }
FunctionContext provides access to a range of query targets for functions to reference.
func (FunctionContext) IncrStackCount ¶ added in v3.45.0
func (ctx FunctionContext) IncrStackCount() (FunctionContext, int)
IncrStackCount increases the count stored in the function context of how many maps we've entered and returns the current count. nolint:gocritic // Ignore unnamedResult false positive
func (FunctionContext) NamedValue ¶ added in v3.43.0
func (ctx FunctionContext) NamedValue(name string) (interface{}, bool)
NamedValue returns the value of a named context if it exists.
func (FunctionContext) PopValue ¶ added in v3.43.0
func (ctx FunctionContext) PopValue() (*interface{}, FunctionContext)
PopValue returns the current default value, and a function context with the top value removed from the context stack. If the value returned is the absolute root value function then the context returned is unchanged. If there is no current default value then a nil value is returned and the context returned is unchanged.
func (FunctionContext) Value ¶
func (ctx FunctionContext) Value() *interface{}
Value returns a lazily evaluated context value. A context value is not always available and can therefore be nil.
func (FunctionContext) WithNamedValue ¶ added in v3.43.0
func (ctx FunctionContext) WithNamedValue(name string, value interface{}) FunctionContext
WithNamedValue returns a FunctionContext with a named value.
func (FunctionContext) WithValue ¶ added in v3.28.0
func (ctx FunctionContext) WithValue(value interface{}) FunctionContext
WithValue returns a function context with a new value.
func (FunctionContext) WithValueFunc ¶ added in v3.33.0
func (ctx FunctionContext) WithValueFunc(fn func() *interface{}) FunctionContext
WithValueFunc returns a function context with a new value func.
type FunctionCtor ¶
FunctionCtor constructs a new function from input arguments.
type FunctionSet ¶ added in v3.39.0
type FunctionSet struct {
// contains filtered or unexported fields
}
FunctionSet contains an explicit set of functions to be available in a Bloblang query.
func NewFunctionSet ¶ added in v3.52.0
func NewFunctionSet() *FunctionSet
NewFunctionSet creates a function set without any functions in it.
func (*FunctionSet) Add ¶ added in v3.39.0
func (f *FunctionSet) Add(spec FunctionSpec, ctor FunctionCtor, autoResolveFunctionArgs bool, checks ...ArgCheckFn) error
Add a new function to this set by providing a spec (name and documentation), a constructor to be called for each instantiation of the function, and information regarding the arguments of the function.
func (*FunctionSet) Docs ¶ added in v3.39.0
func (f *FunctionSet) Docs() []FunctionSpec
Docs returns a slice of function specs, which document each function.
func (*FunctionSet) Init ¶ added in v3.39.0
func (f *FunctionSet) Init(name string, args ...interface{}) (Function, error)
Init attempts to initialize a function of the set by name and zero or more arguments.
func (*FunctionSet) List ¶ added in v3.39.0
func (f *FunctionSet) List() []string
List returns a slice of function names in alphabetical order.
func (*FunctionSet) NoMessage ¶ added in v3.47.0
func (f *FunctionSet) NoMessage() *FunctionSet
NoMessage creates a clone of the function set that can be mutated in isolation, where all message access functions are removed.
func (*FunctionSet) OnlyPure ¶ added in v3.47.0
func (f *FunctionSet) OnlyPure() *FunctionSet
OnlyPure creates a clone of the function set that can be mutated in isolation, where all impure functions are removed.
func (*FunctionSet) Without ¶ added in v3.39.0
func (f *FunctionSet) Without(functions ...string) *FunctionSet
Without creates a clone of the function set that can be mutated in isolation, where a variadic list of functions will be excluded from the set.
type FunctionSpec ¶ added in v3.26.0
type FunctionSpec struct { // The release status of the function. Status Status // A category to place the function within. Category FunctionCategory // Name of the function (as it appears in config). Name string // Description of the functions purpose (in markdown). Description string // Examples shows general usage for the function. Examples []ExampleSpec // Impure indicates that a function accesses or interacts with the // environment, and is therefore unsafe. Impure bool }
FunctionSpec describes a Bloblang function.
func FunctionDocs ¶ added in v3.26.0
func FunctionDocs() []FunctionSpec
FunctionDocs returns a slice of specs, one for each function.
func NewDeprecatedFunctionSpec ¶ added in v3.26.0
func NewDeprecatedFunctionSpec(name, description string, examples ...ExampleSpec) FunctionSpec
NewDeprecatedFunctionSpec creates a new function spec that is deprecated.
func NewFunctionSpec ¶ added in v3.26.0
func NewFunctionSpec(category FunctionCategory, name, description string, examples ...ExampleSpec) FunctionSpec
NewFunctionSpec creates a new function spec.
func NewHiddenFunctionSpec ¶ added in v3.33.0
func NewHiddenFunctionSpec(name string) FunctionSpec
NewHiddenFunctionSpec creates a new function spec that is hidden from the docs.
func (FunctionSpec) Beta ¶ added in v3.28.0
func (s FunctionSpec) Beta() FunctionSpec
Beta flags the function as a beta component.
func (FunctionSpec) MarkImpure ¶ added in v3.47.0
func (s FunctionSpec) MarkImpure() FunctionSpec
MarkImpure flags the function as being impure, meaning it access or interacts with the environment.
type Iterable ¶ added in v3.47.0
type Iterable interface { // TryIterate attempts to create an iterator that walks the function result. // Some functions will be unable to provide an iterator due to either the // context or function arguments provided, therefore it's possible that a // static value will be returned instead. TryIterate(ctx FunctionContext) (Iterator, interface{}, error) }
Iterable is an interface implemented by Bloblang functions that are able to expose their results as an interator, allowing for more efficient chaining of array based methods.
type Iterator ¶ added in v3.47.0
type Iterator interface { // Next provides the next element of the iterator, or an error. When the // iterator has reached the end ErrEndOfIter is returned. Next() (interface{}, error) // Len provides a static length of the iterator when possible. Len() (int, bool) }
Iterator allows traversal of a Bloblang function result in iterations.
type Literal ¶ added in v3.25.0
type Literal struct { Value interface{} // contains filtered or unexported fields }
Literal wraps a static value and returns it for each invocation of the function.
func NewLiteralFunction ¶ added in v3.25.0
NewLiteralFunction creates a query function that returns a static, literal value.
func (*Literal) Annotation ¶ added in v3.43.1
Annotation returns a token identifier of the function.
func (*Literal) Exec ¶ added in v3.25.0
func (l *Literal) Exec(ctx FunctionContext) (interface{}, error)
Exec returns a literal value.
func (*Literal) QueryTargets ¶ added in v3.25.0
func (l *Literal) QueryTargets(ctx TargetsContext) (TargetsContext, []TargetPath)
QueryTargets returns nothing.
type MatchCase ¶ added in v3.25.0
type MatchCase struct {
// contains filtered or unexported fields
}
MatchCase represents a single match case of a match expression, where a case query is checked and, if true, the underlying query is executed and returned.
func NewMatchCase ¶ added in v3.25.0
NewMatchCase creates a single match case of a match expression, where a case query is checked and, if true, the underlying query is executed and returned.
type MessageBatch ¶
MessageBatch is an interface type to be given to a query function, it allows the function to resolve fields and metadata from a Benthos message batch.
type MethodCatSpec ¶ added in v3.26.0
type MethodCatSpec struct { Category MethodCategory Description string Examples []ExampleSpec }
MethodCatSpec describes how a method behaves in the context of a given category.
type MethodCategory ¶ added in v3.26.0
type MethodCategory string
MethodCategory is an abstract title for methods of a similar purpose.
var ( MethodCategoryStrings MethodCategory = "String Manipulation" MethodCategoryNumbers MethodCategory = "Number Manipulation" MethodCategoryTime MethodCategory = "Timestamp Manipulation" MethodCategoryRegexp MethodCategory = "Regular Expressions" MethodCategoryEncoding MethodCategory = "Encoding and Encryption" MethodCategoryCoercion MethodCategory = "Type Coercion" MethodCategoryParsing MethodCategory = "Parsing" MethodCategoryObjectAndArray MethodCategory = "Object & Array Manipulation" MethodCategoryDeprecated MethodCategory = "Deprecated" MethodCategoryPlugin MethodCategory = "Plugin" )
Method categories.
type MethodCtor ¶
MethodCtor constructs a new method from a target function and input args.
type MethodSet ¶ added in v3.39.0
type MethodSet struct {
// contains filtered or unexported fields
}
MethodSet contains an explicit set of methods to be available in a Bloblang query.
func NewMethodSet ¶ added in v3.52.0
func NewMethodSet() *MethodSet
NewMethodSet creates a method set without any methods in it.
func (*MethodSet) Add ¶ added in v3.39.0
func (m *MethodSet) Add(spec MethodSpec, ctor MethodCtor, autoResolveFunctionArgs bool, checks ...ArgCheckFn) error
Add a new method to this set by providing a spec (name and documentation), a constructor to be called for each instantiation of the method, and information regarding the arguments of the method.
func (*MethodSet) Docs ¶ added in v3.39.0
func (m *MethodSet) Docs() []MethodSpec
Docs returns a slice of method specs, which document each method.
func (*MethodSet) Init ¶ added in v3.39.0
Init attempts to initialize a method of the set by name from a target function and zero or more arguments.
type MethodSpec ¶ added in v3.26.0
type MethodSpec struct { // The release status of the function. Status Status // Name of the method (as it appears in config). Name string // Description of the method purpose (in markdown). Description string // Examples shows general usage for the method. Examples []ExampleSpec // Categories that this method fits within. Categories []MethodCatSpec }
MethodSpec describes a Bloblang method.
func MethodDocs ¶ added in v3.26.0
func MethodDocs() []MethodSpec
MethodDocs returns a slice of specs, one for each method.
func NewDeprecatedMethodSpec ¶ added in v3.26.0
func NewDeprecatedMethodSpec(name, description string, examples ...ExampleSpec) MethodSpec
NewDeprecatedMethodSpec creates a new method spec that is deprecated. The method will not appear in docs or searches but will still be usable in mappings.
func NewHiddenMethodSpec ¶ added in v3.33.0
func NewHiddenMethodSpec(name string) MethodSpec
NewHiddenMethodSpec creates a new method spec that is hidden from docs.
func NewMethodSpec ¶ added in v3.26.0
func NewMethodSpec(name, description string, examples ...ExampleSpec) MethodSpec
NewMethodSpec creates a new method spec.
func (MethodSpec) Beta ¶ added in v3.28.0
func (m MethodSpec) Beta() MethodSpec
Beta flags the function as a beta component.
func (MethodSpec) InCategory ¶ added in v3.26.0
func (m MethodSpec) InCategory(category MethodCategory, description string, examples ...ExampleSpec) MethodSpec
InCategory describes the methods behaviour in the context of a given category, methods can belong to multiple categories. For example, the `contains` method behaves differently in the object and array category versus the strings one, but belongs in both.
type NamedContextFunction ¶ added in v3.43.0
type NamedContextFunction struct {
// contains filtered or unexported fields
}
NamedContextFunction wraps a query function in a mechanism that captures the current context under an alias.
func (*NamedContextFunction) Annotation ¶ added in v3.43.1
func (n *NamedContextFunction) Annotation() string
Annotation returns the annotation of the underlying function.
func (*NamedContextFunction) Exec ¶ added in v3.43.0
func (n *NamedContextFunction) Exec(ctx FunctionContext) (interface{}, error)
Exec executes the wrapped query function with the context captured under an alias.
func (*NamedContextFunction) Name ¶ added in v3.43.0
func (n *NamedContextFunction) Name() string
Name returns the alias under which the context will be captured.
func (*NamedContextFunction) QueryTargets ¶ added in v3.43.0
func (n *NamedContextFunction) QueryTargets(ctx TargetsContext) (TargetsContext, []TargetPath)
QueryTargets provides a summary of which fields the underlying query function targets.
type Nothing ¶
type Nothing *struct{}
Nothing is a special type that serializes to `null` when forced but indicates a query should be disregarded (and not mapped).
type TargetPath ¶ added in v3.25.0
type TargetPath struct { Type TargetType Path []string }
TargetPath represents a target type and segmented path that a query function references. An empty path indicates the root of the type is targetted.
func NewTargetPath ¶ added in v3.25.0
func NewTargetPath(t TargetType, path ...string) TargetPath
NewTargetPath constructs a new target path from a type and zero or more path segments.
type TargetType ¶ added in v3.25.0
type TargetType int
TargetType represents a query target type, which is a source of information that a query might require, such as metadata, structured message contents, the context, etc.
const ( TargetMetadata TargetType = iota TargetValue TargetVariable )
TargetTypes
type TargetsContext ¶ added in v3.26.0
TargetsContext describes the current Bloblang execution environment from the perspective of a particular query function in a way that allows it to determine which values it is targetting and the origins of those values.
The environment consists of named maps that are globally accessible, the current value that is being executed upon by methods (when applicable), the general (main) context (referenced by the keyword `this`) and any other named contexts accessible at this point.
Since it's possible for any query function to reference and return multiple target candidates (match expressions, etc) then each context and the current value are lists of paths, each being a candidate at runtime.
func (TargetsContext) MainContext ¶ added in v3.43.0
func (ctx TargetsContext) MainContext() []TargetPath
MainContext returns the path of the main context.
func (TargetsContext) NamedContext ¶ added in v3.43.0
func (ctx TargetsContext) NamedContext(name string) []TargetPath
NamedContext returns the path of a named context if it exists.
func (TargetsContext) PopContext ¶ added in v3.43.0
func (ctx TargetsContext) PopContext() TargetsContext
PopContext returns a targets context with the latest context dropped and the previous (when applicable) returned.
func (TargetsContext) Value ¶ added in v3.43.0
func (ctx TargetsContext) Value() []TargetPath
Value returns the current value of the targets context, which is the path(s) being executed upon by methods.
func (TargetsContext) WithContextAsNamed ¶ added in v3.43.0
func (ctx TargetsContext) WithContextAsNamed(name string) TargetsContext
WithContextAsNamed moves the latest context into a named context and returns the context prior to that one to the main context. This is a way for named context mappings to correct the contexts so that the child query function returns the right paths.
func (TargetsContext) WithValues ¶ added in v3.43.0
func (ctx TargetsContext) WithValues(paths []TargetPath) TargetsContext
WithValues returns a targets context where the current value being executed upon by methods is set to something new.
func (TargetsContext) WithValuesAsContext ¶ added in v3.43.0
func (ctx TargetsContext) WithValuesAsContext() TargetsContext
WithValuesAsContext returns a targets context where the current value being executed upon by methods is now the main context. This happens when a query function is executed as a method, or within branches of match expressions.
type TypeError ¶
TypeError represents an error where a value of a type was required for a function, method or operator but instead a different type was found.
func NewTypeError ¶
NewTypeError creates a new type error.
func NewTypeErrorFrom ¶ added in v3.43.1
NewTypeErrorFrom creates a new type error with an annotation of the query that provided the wrong type.
type TypeMismatch ¶
type TypeMismatch struct { Lfn Function Rfn Function Left ValueType Right ValueType Operation string }
TypeMismatch represents an error where two values should be a comparable type but are not.
func NewTypeMismatch ¶
func NewTypeMismatch(operation string, lfn, rfn Function, left, right interface{}) *TypeMismatch
NewTypeMismatch creates a new type mismatch error.
func (*TypeMismatch) Error ¶
func (t *TypeMismatch) Error() string
Error implements the standard error interface.
type ValueType ¶
type ValueType string
ValueType represents a discrete value type supported by Bloblang queries.
var ( ValueString ValueType = "string" ValueBytes ValueType = "bytes" ValueNumber ValueType = "number" ValueBool ValueType = "bool" ValueArray ValueType = "array" ValueObject ValueType = "object" ValueNull ValueType = "null" ValueDelete ValueType = "delete" ValueNothing ValueType = "nothing" ValueUnknown ValueType = "unknown" )
ValueType variants.