meta

package
v0.0.0-...-2bc12df Latest Latest
Warning

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

Go to latest
Published: Mar 18, 2021 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type SatisfyingValueSchema

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

SatisfyingValueSchema represents a high-level schema of a given leaf's satisfying values. It is used to generate value schema predicates by validating its representative values against the provided schema using a JSON schema validator.

SatisfyingValueSchema is an immutable type.

func NewSatisfyingValueSchema

func NewSatisfyingValueSchema() SatisfyingValueSchema

func (SatisfyingValueSchema) AddArray

AddArray adds an array to svs

func (SatisfyingValueSchema) AddObject

AddObject adds an object with the specified key to svs

func (SatisfyingValueSchema) EndsWithAnything

func (svs SatisfyingValueSchema) EndsWithAnything() SatisfyingValueSchema

EndsWithAnything indicates that the svs can end with any value

func (SatisfyingValueSchema) EndsWithArray

func (svs SatisfyingValueSchema) EndsWithArray() SatisfyingValueSchema

EndsWithArray indicates that the svs ends with an array

func (SatisfyingValueSchema) EndsWithObject

func (svs SatisfyingValueSchema) EndsWithObject() SatisfyingValueSchema

EndsWithObject indicates that the svs ends with an object

func (SatisfyingValueSchema) EndsWithPrimitiveValue

func (svs SatisfyingValueSchema) EndsWithPrimitiveValue() SatisfyingValueSchema

EndsWithPrimitiveValue indicates that the svs ends with a primitive value

type SchemaPredicate

type SchemaPredicate = func(ValueSchema) bool

func MakeSchemaPredicate

func MakeSchemaPredicate(svs SatisfyingValueSchema) SchemaPredicate

type ValuePredicate

type ValuePredicate interface {
	rql.ValuePredicate
	SchemaPredicate(SatisfyingValueSchema) SchemaPredicate
}

ValuePredicate is a wrapper to rql.ValuePredicate that includes an additional SchemaPredicate method. All rql.ValuePredicate implementations should embed the ValuePredicateBase type.

RQL users should only care about EvalValueSchema. However, walking a JSON schema is much harder than walking a JSON object so we have to implement EvalValueSchema in a different way than EvalValue. That way is taking advantage of JSON schema validators. Here's how it works.

Given a value predicate AST, assume that all negatable value predicate expressions are in reduced form (meaning all "NOT" operators are of the form ["NOT", ValuePredicate]). Consider a leaf in this tree (a ValuePredicate node or a "NOT" node). Then the leaf's satisfying value schema (SVS) is the schema of all satisfying values of the predicate generated by the leaf-AST [the AST consisting of all nodes up to this leaf ignoring any intermediate "AND"/"OR" operators].

As an example, consider the following AST:

["object",
	[["key", "foo"],
	["array",
		["some",
		["OR",
			["number", ["=", 5]]]]]],
			["NOT", ["number", [">", 5]]]]]]]

Then the leaves are the "number" and "NOT" nodes under the "OR". Their SVS' are

  • ".foo[] nil" for the "number" node. To see why, notice that this leaf's AST is ["object", [["key", "foo"], ["array", ["some", ["number", ["=", 5]]]]] And {"foo": [5]} is a satisfying value for the leaf-AST's predicate. In fact, all satisfying values will have the general form {"foo": [nil]} (primitive types are normalized to "nil"). We can write this as ".foo[] nil".

  • ".foo[] *" for the "NOT" node. To see why, notice that the leaf AST is ["object", [["key", "foo"], ["array", ["some", ["NOT", ["number", [">", 5]]]]]] And that {"foo": [6]}, {"foo": [[]]}, {"foo": [{}]} are several satisfying values for the leaf-AST's predicate. In fact, all satisfying values will have the general form {"foo": [*]} where "*" means that the value inside the array can be anything, e.g. an "object", "array" or a primitive value. We can write this as ".foo[] *"

Now let svs be the leaf's SVS. Then its schema predicate will return true iff the schema supports svs. The AST's final schema predicate will be an "AND"/"OR" of all the generated leaves' schema predicates as specified in the AST. If the AST doesn't have any "AND"/"OR" operators, then the schema predicate is just the leaf's schema predicate.

We'll need to traverse the AST to correctly evaluate SVS' and combine the generated schema predicates. meta.SchemaPredicate lets us do exactly that.

type ValuePredicateBase

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

All ValuePredicate implementations should extend this class

func NewValuePredicate

func NewValuePredicate(p ValuePredicate) *ValuePredicateBase

func (*ValuePredicateBase) EvalValueSchema

func (p *ValuePredicateBase) EvalValueSchema(rawSchema *plugin.JSONSchema) bool

type ValueSchema

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

ValueSchema represents a metadata value schema. It is a wrapper for plugin.JSONSchema.

func NewValueSchema

func NewValueSchema(s *plugin.JSONSchema) ValueSchema

func (ValueSchema) String

func (s ValueSchema) String() string

String() is implemented to make test-failure output more readable

func (ValueSchema) Supports

func (s ValueSchema) Supports(svs SatisfyingValueSchema) bool

Jump to

Keyboard shortcuts

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