dataquery

package
v0.4.2 Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2024 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DelayedEvalType = encapsulator.NewCodec("data", &encapsulator.CapsuleOps[DelayedEval]{
	CustomExpressionDecoder: func(expr hcl.Expression, ctx *hcl.EvalContext) (value *DelayedEval, diags diagnostics.Diag) {

		val, diag := expr.Value(JqEvalContext(ctx))
		diags = diagnostics.Diag(diag)
		if diags.HasErrors() {
			return
		}
		value = &DelayedEval{
			val:      val,
			srcRange: expr.Range().Ptr(),
		}
		return
	},
	ConversionTo: func(dst cty.Type) func(cty.Value, cty.Path) (*DelayedEval, error) {
		if dst.Equals(plugin.EncapsulatedData.CtyType()) {
			return func(v cty.Value, p cty.Path) (*DelayedEval, error) {
				return &DelayedEval{
					evaluated: true,
					data:      *plugin.EncapsulatedData.MustFromCty(v),
				}, nil
			}
		}
		return nil
	},
	ConversionFrom: func(src cty.Type) func(*DelayedEval, cty.Path) (cty.Value, error) {
		if src.Equals(plugin.EncapsulatedData.CtyType()) {
			return func(de *DelayedEval, p cty.Path) (cty.Value, error) {
				if !de.evaluated {
					return cty.NullVal(plugin.EncapsulatedData.CtyType()), p.NewErrorf("Attempted to encode non-evaluated DelayedEval object")
				}
				return plugin.EncapsulatedData.ToCty(&de.data), nil
			}
		}
		return nil
	},
})

DelayedEvalType is type that transports plugin.Data objects inside of the arguments/configuration of the plugin Capable of evaluating queries inside of self, evaluated just before sending the data to the plugin (`vars` have already processed the data)

View Source
var JqQueryType = encapsulator.NewCodec("jq query", &encapsulator.CapsuleOps[JqQuery]{
	CustomExpressionDecoder: func(expr hcl.Expression, evalCtx *hcl.EvalContext) (val *JqQuery, diags diagnostics.Diag) {
		queryVal, diag := expr.Value(evalCtx)
		if diags.Extend(diag) {
			return
		}
		if queryVal.IsNull() || !queryVal.Type().Equals(cty.String) {
			diags.Append(&hcl.Diagnostic{
				Severity:    hcl.DiagError,
				Summary:     "Invalid argument type",
				Detail:      "A string is required",
				Subject:     expr.Range().Ptr(),
				Expression:  expr,
				EvalContext: evalCtx,
			})
			return
		}

		val = &JqQuery{
			JqQueryDefinition: &JqQueryDefinition{
				query:    queryVal.AsString(),
				srcRange: expr.Range().Ptr(),
			},
		}
		val.parseOnce = utils.OnceVal(val.parse)
		return
	},
	ConversionFrom: func(src cty.Type) func(*JqQuery, cty.Path) (cty.Value, error) {
		if src.Equals(plugin.EncapsulatedData.CtyType()) {
			return func(jq *JqQuery, p cty.Path) (cty.Value, error) {
				if !jq.Evaluated {
					return cty.NilVal, p.NewErrorf("Attempted to encode non-evaluated JqQuery")
				}
				return plugin.EncapsulatedData.ValToCty(jq.Result), nil
			}
		}
		return nil
	},
})

Functions

func JqEvalContext

func JqEvalContext(base *hcl.EvalContext) (evalCtx *hcl.EvalContext)

Adds "query_jq" function to the eval context

Types

type DelayedEval

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

func (*DelayedEval) CustomEval

func (d *DelayedEval) CustomEval(ctx context.Context, dataCtx plugin.MapData) (result cty.Value, diags diagnostics.Diag)

func (*DelayedEval) Result

func (d *DelayedEval) Result() plugin.Data

type JqQuery

type JqQuery struct {
	*JqQueryDefinition
	Evaluated bool
	Result    plugin.Data
}

type JqQueryDefinition

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

func (*JqQueryDefinition) CustomEval

func (q *JqQueryDefinition) CustomEval(ctx context.Context, dataCtx plugin.MapData) (result cty.Value, diags diagnostics.Diag)

func (*JqQueryDefinition) Eval

func (q *JqQueryDefinition) Eval(ctx context.Context, dataCtx plugin.MapData) (result *JqQuery, diags diagnostics.Diag)

Jump to

Keyboard shortcuts

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