jsonpath

package
v0.1.8 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2025 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultFunctionRegistry = NewFunctionRegistry()

This contains the functions defined in the jsonpath spec

View Source
var ErrUnimplementedFeature = errors.New("unimplemented feature")

Functions

This section is empty.

Types

type ComparableEvaluator

type ComparableEvaluator interface {
	// The returned value must be cloned first if it is consumed
	//
	// TODO: see if it wouldn't be better to clone it by default as the value is
	// perhaps always consumed.
	Evaluate(ctx *RunContext, value iterator.Value) iterator.Value
}

type ComparisonEvaluator

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

func (ComparisonEvaluator) EvaluateTruth

func (e ComparisonEvaluator) EvaluateTruth(ctx *RunContext, value iterator.Value) bool

type ComparisonFlags

type ComparisonFlags uint8
const (
	CheckEquals ComparisonFlags = 1 << iota
	CheckLessThan
	NegateResult
)

type CompileQueryOption

type CompileQueryOption func(*compiler)

func WithStrictMode

func WithStrictMode(strictMode bool) CompileQueryOption

type Decision

type Decision uint8

Decision is a 3-valued type with possible values DontKnow, Yes, No. Sort of a boolean for undecided people...

const (
	DontKnow    Decision = 0
	Yes         Decision = 1
	No          Decision = 2
	NoMoreAfter Decision = 4
)

Possible values of Decision

func (Decision) IsMade

func (d Decision) IsMade() bool

IsMade is true if the Decision is not DontKnow

func (Decision) IsNo

func (d Decision) IsNo() bool

func (Decision) IsNoMoreAfter

func (d Decision) IsNoMoreAfter() bool

func (Decision) IsYes

func (d Decision) IsYes() bool

type DefaultSelectorRunner

type DefaultSelectorRunner struct{}

DefaultSelectorRunner is the default implementation of SelectorRunner. It selects nothing and is designed to be embedded in other implementation.

func (DefaultSelectorRunner) Lookahead

func (r DefaultSelectorRunner) Lookahead() int64

Lookahead returns 0.

func (DefaultSelectorRunner) ReversesSelection

func (r DefaultSelectorRunner) ReversesSelection() bool

func (DefaultSelectorRunner) SelectsFromIndex

func (r DefaultSelectorRunner) SelectsFromIndex(index, negIndex int64) Decision

SelectsFromIndex returns No.

func (DefaultSelectorRunner) SelectsFromKey

func (r DefaultSelectorRunner) SelectsFromKey(key string) Decision

SelectsFromKey returns No.

func (DefaultSelectorRunner) SelectsFromValue

func (r DefaultSelectorRunner) SelectsFromValue(ctx *RunContext, value iterator.Value) bool

SelectsFromValue returns false.

type DefaultSingularSelectorRunner

type DefaultSingularSelectorRunner struct{}

func (DefaultSingularSelectorRunner) SelectFromArray

func (DefaultSingularSelectorRunner) SelectFromObject

type FilterSelectorRunner

type FilterSelectorRunner struct {
	DefaultSelectorRunner
	// contains filtered or unexported fields
}

FilterSelectorRunner implements filters, i.e. selector that select a node depdending on a condition

func (FilterSelectorRunner) SelectsFromIndex

func (r FilterSelectorRunner) SelectsFromIndex(index, negIndex int64) Decision

func (FilterSelectorRunner) SelectsFromKey

func (r FilterSelectorRunner) SelectsFromKey(key string) Decision

func (FilterSelectorRunner) SelectsFromValue

func (r FilterSelectorRunner) SelectsFromValue(ctx *RunContext, value iterator.Value) bool

type FunctionArgumentRunner

type FunctionArgumentRunner interface {
	ComparableEvaluator
	LogicalEvaluator
	NodesResultEvaluator
}

type FunctionDef

type FunctionDef struct {
	Name       string
	InputTypes []Type
	OutputType Type
	Run        func([]any) any
}

type FunctionRegistry

type FunctionRegistry interface {
	GetFunctionDef(name string) *FunctionDef
	AddFunctionDef(def FunctionDef) error
}

func NewFunctionRegistry

func NewFunctionRegistry() FunctionRegistry

type FunctionRunner

type FunctionRunner struct {
	*FunctionDef
	// contains filtered or unexported fields
}

func (FunctionRunner) Evaluate

func (r FunctionRunner) Evaluate(ctx *RunContext, val iterator.Value) iterator.Value

func (FunctionRunner) EvaluateNodesResult

func (r FunctionRunner) EvaluateNodesResult(ctx *RunContext, val iterator.Value) NodesResult

func (FunctionRunner) EvaluateTruth

func (r FunctionRunner) EvaluateTruth(ctx *RunContext, val iterator.Value) bool

type IndexSelectorRunner

type IndexSelectorRunner struct {
	DefaultSelectorRunner
	// contains filtered or unexported fields
}

IndexSelectorRunner implements the selector that selects an item at a given index in an array. That index can be negative (-1 means the last item, -2 the one before last etc).

func (IndexSelectorRunner) Lookahead

func (r IndexSelectorRunner) Lookahead() int64

Lookahead returns a non-zero value of the index of the selector is negative.

func (IndexSelectorRunner) SelectsFromIndex

func (r IndexSelectorRunner) SelectsFromIndex(index, negIndex int64) Decision

type IndexSingularSelectorRunner

type IndexSingularSelectorRunner struct {
	DefaultSingularSelectorRunner
	// contains filtered or unexported fields
}

func (IndexSingularSelectorRunner) SelectFromArray

func (r IndexSingularSelectorRunner) SelectFromArray(arr *iterator.Array) iterator.Value

type InnerQueryRunner

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

func (InnerQueryRunner) MapValue

func (r InnerQueryRunner) MapValue(ctx *RunContext, value iterator.Value, next valueProcessor) bool

type InnerSingularQueryRunner

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

func (InnerSingularQueryRunner) Evaluate

type LiteralEvaluator

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

func (LiteralEvaluator) Evaluate

func (e LiteralEvaluator) Evaluate(ctx *RunContext, value iterator.Value) iterator.Value

type LogicalAndEvaluator

type LogicalAndEvaluator struct {
	Arguments []LogicalEvaluator
}

func (LogicalAndEvaluator) EvaluateTruth

func (e LogicalAndEvaluator) EvaluateTruth(ctx *RunContext, value iterator.Value) bool

type LogicalArgumentRunner

type LogicalArgumentRunner struct {
	LogicalEvaluator
}

func (LogicalArgumentRunner) Evaluate

func (LogicalArgumentRunner) EvaluateNodesResult

func (r LogicalArgumentRunner) EvaluateNodesResult(ctx *RunContext, val iterator.Value) NodesResult

type LogicalEvaluator

type LogicalEvaluator interface {

	// EvaluateTruth returns true if the value fulfils the condition.
	// It should keep value untouched.
	EvaluateTruth(ctx *RunContext, value iterator.Value) bool
}

type LogicalNotEvaluator

type LogicalNotEvaluator struct {
	Argument LogicalEvaluator
}

func (LogicalNotEvaluator) EvaluateTruth

func (e LogicalNotEvaluator) EvaluateTruth(ctx *RunContext, value iterator.Value) bool

type LogicalOrEvaluator

type LogicalOrEvaluator struct {
	Arguments []LogicalEvaluator
}

func (LogicalOrEvaluator) EvaluateTruth

func (e LogicalOrEvaluator) EvaluateTruth(ctx *RunContext, value iterator.Value) bool

type MainQueryRunner

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

func CompileQuery

func CompileQuery(query ast.Query, options ...CompileQueryOption) (MainQueryRunner, error)

CompileQuery compiles a JSON query AST to a QueryRunner.

func (MainQueryRunner) EvaluateNodesResult

func (r MainQueryRunner) EvaluateNodesResult(value iterator.Value) NodesResult

func (MainQueryRunner) Transform

func (r MainQueryRunner) Transform(in <-chan token.Token, out token.WriteStream)

func (MainQueryRunner) TransformValue

func (r MainQueryRunner) TransformValue(value iterator.Value, out token.WriteStream)

type NameSelectorRunner

type NameSelectorRunner struct {
	DefaultSelectorRunner
	// contains filtered or unexported fields
}

NameSelectorRunner implements the SelectorRunner that selects a value in an object by the name of its key.

func (NameSelectorRunner) SelectsFromKey

func (r NameSelectorRunner) SelectsFromKey(key string) Decision

SelectsFromKey returns Yes if key is the name that can be selected, else No.

type NameSingularSelectorRunner

type NameSingularSelectorRunner struct {
	DefaultSingularSelectorRunner
	// contains filtered or unexported fields
}

func (NameSingularSelectorRunner) SelectFromObject

func (r NameSingularSelectorRunner) SelectFromObject(obj *iterator.Object) iterator.Value

type NodesArgumentRunner

type NodesArgumentRunner struct {
	QueryEvaluator
}

func (NodesArgumentRunner) Evaluate

type NodesResult

type NodesResult interface {
	ForEachNode(func(iterator.Value) bool)
}

type NodesResultEvaluator

type NodesResultEvaluator interface {
	EvaluateNodesResult(ctx *RunContext, value iterator.Value) NodesResult
}

type QueryEvaluator

type QueryEvaluator struct {
	ValueMapper
}

func (QueryEvaluator) EvaluateNodesResult

func (e QueryEvaluator) EvaluateNodesResult(ctx *RunContext, value iterator.Value) NodesResult

func (QueryEvaluator) EvaluateTruth

func (e QueryEvaluator) EvaluateTruth(ctx *RunContext, value iterator.Value) bool

func (QueryEvaluator) TransformValue

func (e QueryEvaluator) TransformValue(ctx *RunContext, value iterator.Value, out token.WriteStream)

type QueryRunner

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

func (QueryRunner) MapValue

func (r QueryRunner) MapValue(ctx *RunContext, value iterator.Value, next valueProcessor) bool

type ReverseSliceSelectorRunner

type ReverseSliceSelectorRunner struct {
	DefaultSelectorRunner
	// contains filtered or unexported fields
}

SliceSelectorRunner implements the selector that selects a slice of an array. A slice is defined by 3 integer values start, end, step. Start and end may be negative in which case they are counted from the end of the array starting from -1.

Note that the compiler never creates an instance of ReverseSliceSelectorRunner where step >= 0, so the implementation assumes step < 0. For positive steps, there is a separate implementation called SliceSelectorRunner.

func (ReverseSliceSelectorRunner) Lookahead

func (r ReverseSliceSelectorRunner) Lookahead() int64

Lookahead returns a value that allows deciding whether we have reached the start or end index of the slice.

func (ReverseSliceSelectorRunner) ReversesSelection

func (r ReverseSliceSelectorRunner) ReversesSelection() bool

ReversesSelection returns true

func (ReverseSliceSelectorRunner) SelectsFromIndex

func (r ReverseSliceSelectorRunner) SelectsFromIndex(index, negIndex int64) Decision

SelectsFromIndex returns Yes or No, depending on whether the index is part of the reverse slice.

type RunContext

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

type SegmentRunner

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

SegmentRunner implements the runner of a query segment

type SelectorRunner

type SelectorRunner interface {

	// Lookahead returns the number of extra number of array items we need to
	// know about in order to make a decision about a negative index selector.
	// If the returned number is 0 then it means there is no need to look ahead
	// at all.
	//
	// For example in the query $[-4:], the lookahead is 4.  This is because if
	// we know that there are at least 4 more items in the array after the
	// current one, it won't be selected.
	//
	// Knowing the lookahead value allows executing such queries in a streaming
	// manner, without loading the whole array into memory, just a slice of size
	// lookahead.
	Lookahead() int64

	// SelectsFromKey makes a Decision on whether the current object item is
	// selected based on its key.  If no decision can be made then it should
	// return DontKnow.
	SelectsFromKey(key string) Decision

	// SelectsFromKey makes a Decision on whether the current array item is
	// selected based on its index or negative index.  If no decision can be
	// made then it should return DontKnow.
	//
	// The value negIndex is negative and is meant to represent the index from
	// the end of the array, starting at -1.
	//
	// The negative index (negIndex) is not necessarily correct but the
	// following can be assumed, given that N is the value returned by
	// Lookahead() and I is the real negative index:
	//   - if negIndex >= -N then negIndex == I
	//   - if negIndex < -N then I < -N
	SelectsFromIndex(index, negIndex int64) Decision

	// Selects decides whether the current item in an object or array should be
	// selected, based on its value.  It is only called if either SelectsFromKey
	// or SelectsFromIndex returned DontKnow and it makes the final decision.
	//
	// Selects should promise not to advance Value, so it must clone it first if
	// it wants to look inside.
	SelectsFromValue(ctx *RunContext, value iterator.Value) bool

	// ReversesSelection returns true if the selector should output the values
	// it selects in reverse order. This is taylor-made for slice selectors with
	// a negative step.
	ReversesSelection() bool
}

SelectorRunner is the interface used to run selectors.

type SingularQueryRunner

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

func (SingularQueryRunner) Evaluate

func (r SingularQueryRunner) Evaluate(ctx *RunContext, value iterator.Value) iterator.Value

type SingularSelectorRunner

type SingularSelectorRunner interface {
	SelectFromObject(*iterator.Object) iterator.Value
	SelectFromArray(*iterator.Array) iterator.Value
}

type SliceSelectorRunner

type SliceSelectorRunner struct {
	DefaultSelectorRunner
	// contains filtered or unexported fields
}

SliceSelectorRunner implements the selector that selects a slice of an array. A slice is defined by 3 integer values start, end, step. Start and end may be negative in which case they are counted from the end of the array starting from -1.

Note that the compiler never creates an instance of SliceSelectorRunner where step <= 0, so the implementation assumes step > 0. For negative steps, there is a separate implementation called ReverseSliceSelectorRunner.

func (SliceSelectorRunner) Lookahead

func (r SliceSelectorRunner) Lookahead() int64

Lookahead returns a value that allows deciding whether we have reached the start or end index of the slice.

func (SliceSelectorRunner) SelectsFromIndex

func (r SliceSelectorRunner) SelectsFromIndex(index, negIndex int64) Decision

SelectsFromIndex returns Yes or No, depending on whether the index is part of the slice.

type Type

type Type uint8
const (
	ValueType Type = iota
	LogicalType
	NodesType
)

func (Type) ConvertsTo

func (t Type) ConvertsTo(u Type) bool

func (Type) String

func (t Type) String() string

type ValueArgumentRunner

type ValueArgumentRunner struct {
	ComparableEvaluator
}

func (ValueArgumentRunner) EvaluateNodesResult

func (r ValueArgumentRunner) EvaluateNodesResult(ctx *RunContext, val iterator.Value) NodesResult

func (ValueArgumentRunner) EvaluateTruth

func (r ValueArgumentRunner) EvaluateTruth(ctx *RunContext, val iterator.Value) bool

type ValueMapper

type ValueMapper interface {
	MapValue(ctx *RunContext, value iterator.Value, next valueProcessor) bool
}

type WildcardSelectorRunner

type WildcardSelectorRunner struct {
	DefaultSelectorRunner
}

WildcardSelectorRunner implements the wildcard selector, which selects all values in an object and all items in an array.

func (WildcardSelectorRunner) SelectsFromIndex

func (r WildcardSelectorRunner) SelectsFromIndex(index, negIndex int64) Decision

SelectsFromIndex returns Yes

func (WildcardSelectorRunner) SelectsFromKey

func (r WildcardSelectorRunner) SelectsFromKey(key string) Decision

SelectsFromKey returns Yes

Jump to

Keyboard shortcuts

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