transform

package
v5.0.9 Latest Latest
Warning

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

Go to latest
Published: Sep 12, 2022 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package transform package contains canonical implementations of Kazaam transforms.

Index

Constants

View Source
const (
	JSONNull = iota
	JSONString
	JSONInt
	JSONFloat
	JSONBool
)

Variables

View Source
var (
	ConditionalPathSkip = CPathSkipError("Conditional Path missing and without a default value")
	NonExistentPath     = RequireError("Path does not exist")
)

Functions

func Coalesce

func Coalesce(spec *Config, data []byte) ([]byte, error)

Coalesce checks multiple keys and returns the first matching key found in raw []byte.

func Concat

func Concat(spec *Config, data []byte) ([]byte, error)

Concat combines any specified fields and literal strings into a single string value with raw []byte.

func Conditional

func Conditional(spec *Config, data []byte) ([]byte, error)

Shift moves values from one provided json path to another in raw []byte.

func Default

func Default(spec *Config, data []byte) ([]byte, error)

Default sets specific value(s) in output json in raw []byte.

func DelJSONRaw

func DelJSONRaw(data []byte, path string, pathRequired bool) ([]byte, error)

func Delete

func Delete(spec *Config, data []byte) ([]byte, error)

Delete deletes keys in-place from the provided data if they exist keys are specified in an array under "keys" in the spec.

func Extract

func Extract(spec *Config, data []byte) ([]byte, error)

Extract returns the specified path as the top-level object in raw []byte.

func GetJSONRaw

func GetJSONRaw(data []byte, path string, pathRequired bool) ([]byte, error)

func HandleUnquotedStrings

func HandleUnquotedStrings(value []byte, dt jsonparser.ValueType) []byte

jsonparser strips quotes from returned strings, this adds them back

func Merge

func Merge(spec *Config, data []byte) ([]byte, error)

Merge joins multiple array values into array of objects with property names containing their matching array. Arrays should be the same length.

func Pass

func Pass(spec *Config, data []byte) ([]byte, error)

Pass performs no manipulation of the passed-in data. It is useful for testing/default behavior.

func SetJSONRaw

func SetJSONRaw(data, out []byte, path string) ([]byte, error)

func Shift

func Shift(spec *Config, data []byte) ([]byte, error)

Shift moves values from one provided json path to another in raw []byte.

func Size added in v5.0.4

func Size(spec *Config, data []byte) ([]byte, error)

func Steps

func Steps(spec *Config, data []byte) ([]byte, error)

Shift moves values from one provided json path to another in raw []byte.

func Timestamp

func Timestamp(spec *Config, data []byte) ([]byte, error)

Timestamp parses and formats timestamp strings using the golang syntax

func UUID

func UUID(spec *Config, data []byte) ([]byte, error)

UUID tries to generate a UUID based on spec components

Types

type BasicExpr

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

support for basic expression evaluation support. NOTE: expressions must evaluate to a bool value, i.e. true or false supports

! - unary not operator

&& - binary logical and || - binary logical or == - binary equality != - binary equality negated < - binary less than > - binary greater than <= - binary less than or equal to >= - binary greater than or equal to ( ) - parentheses grouping true - boolean true constant false - boolean false constant <number constants> - number constants <string constants> - string constants ( "" ) <func calls> - converter function call, f( jsonPath, stringArgs ) where, f is a converter id, jsonPath is a json path, and args are arguments to the converter <json path resolution> - a json path.. does not support path parameters, i.e. ? conditionals and converter extensions

func NewBasicExpr

func NewBasicExpr(data []byte, exprStr string) (expr *BasicExpr, err error)

json data for evaluating json paths, and the expression string to evaluate to a boolean true/false constant value err will be returned if the expression can't be parsed

func (*BasicExpr) Eval

func (expr *BasicExpr) Eval() (val bool, err error)

returns true|false, otherwise error if the expression can not be evaluated

type CPathSkipError

type CPathSkipError string

CPathNoDefaultError thrown when a path is missing, and marked conditional, and didn't have a default set

func (CPathSkipError) Error

func (c CPathSkipError) Error() string

type Config

type Config struct {
	Spec    *map[string]interface{} `json:"spec"`
	Require bool                    `json:"require,omitempty"`
	InPlace bool                    `json:"inplace,omitempty"`
}

Config contains the options that dictate the behavior of a transform. The internal `spec` object can be an arbitrary json configuration for the transform.

type JSONPathConverter

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

func NewJSONPathConverter

func NewJSONPathConverter(converter string) *JSONPathConverter

type JSONPathParameters

type JSONPathParameters struct {
	// contains filtered or unexported fields
}
  [jsonPath]?[conditional]|[converter]
	e.g. root.node1[1].property ? root.node0.prop1 == "true" | regex remove_commas

	the path will be broken into 3 components:
	1. the json parser path to the node value
    2. the conditional component
  	3. and a series of converter expressions to pipe the value through.

	The conditional component has 4 forms:

	root.prop1 ?
								// if the value exists, return it, otherwise skip it, regardless on
								// whether paths are required.
	root.prop1 ? defaultVal
								// if value exists, use that, otherwise return the default value. this is JSON syntax
								// so strings, will require double quotes.
	root.prop1 ? root.node1.prop2 == true :
								// if value exists, and the expression is true, return the existing value
								// if the value exists, and the expression is false, skip the existing value
								// note that the : is required here to end the expression.
	root.prop1 ? root.node1.prop2 == true : defaultValue
								// if the value exists, and the expression is true, return the existing value
								// if the value exists and the expression is false,
								// return the default value (JSON syntax)

	Conditional Expressions support  () , <, >, >=, <=, ==, !=, !, true, false, && and ||
	Conditional expressions must evaluate to a boolean true or false value.
	Identifiers in the expression are assumed to be JSON paths within the document, and will evaluate
	to their current value.  Only non composite JSON values are supported: boolean, number,
	string (i.e. not arrays or objects).

	Function calls of the form  <converter name>( json.path, "converter arguments")   are also supported, e.g.
		root.prop1 ? ston(root.node1.prop1) == 3 && regex(root.node2.prop2,"remove_commas) == "1000" :

	The converters component will define a series of value conversions

func NewJSONPathParameters

func NewJSONPathParameters(data []byte, path string) *JSONPathParameters

type JSONValue

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

func GetJsonPathValue

func GetJsonPathValue(jsonData []byte, path string) (value *JSONValue, err error)

returns a Value (json value type) from the json data byte array, and string path

func NewJSONValue

func NewJSONValue(data []byte) (value *JSONValue, err error)

returns a Value (json value type) from the byte array data for a value

func (*JSONValue) GetBoolValue

func (v *JSONValue) GetBoolValue() bool

func (*JSONValue) GetData

func (v *JSONValue) GetData() []byte

func (*JSONValue) GetFloatValue

func (v *JSONValue) GetFloatValue() float64

func (*JSONValue) GetIntValue

func (v *JSONValue) GetIntValue() int64

func (*JSONValue) GetNumber

func (v *JSONValue) GetNumber() json.Number

func (*JSONValue) GetQuotedStringValue

func (v *JSONValue) GetQuotedStringValue() string

func (*JSONValue) GetStringValue

func (v *JSONValue) GetStringValue() string

func (*JSONValue) GetType

func (v *JSONValue) GetType() int

func (*JSONValue) GetValue

func (v *JSONValue) GetValue() interface{}

func (*JSONValue) IsBool

func (v *JSONValue) IsBool() bool

func (*JSONValue) IsNull

func (v *JSONValue) IsNull() bool

func (*JSONValue) IsNumber

func (v *JSONValue) IsNumber() bool

func (*JSONValue) IsString

func (v *JSONValue) IsString() bool

func (*JSONValue) SetFloatStringPrecision

func (v *JSONValue) SetFloatStringPrecision(p int)

func (*JSONValue) String

func (v *JSONValue) String() string

type ParseError

type ParseError string

ParseError should be thrown when there is an issue with parsing any of the specification or data

func (ParseError) Error

func (p ParseError) Error() string

type RequireError

type RequireError string

RequireError should be thrown if a required key is missing in the data

func (RequireError) Error

func (r RequireError) Error() string

type SpecError

type SpecError string

SpecError should be thrown if the spec for a transform is malformed

func (SpecError) Error

func (s SpecError) Error() string

type TransformFunc

type TransformFunc func(spec *Config, data []byte) ([]byte, error)

Jump to

Keyboard shortcuts

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