transform

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2020 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// FinalOutput is the special name of a Decl that is designated for the output
	// for an omni schema.
	FinalOutput = "FINAL_OUTPUT"
)

Variables

This section is empty.

Functions

func NewParseCtx

func NewParseCtx(
	transformCtx *transformctx.Ctx,
	customFuncs customfuncs.CustomFuncs,
	customParseFuncs CustomParseFuncs) *parseCtx

NewParseCtx creates new context for parsing and transforming a *Node (and its sub-tree) into an output record.

Types

type CustomFuncDecl

type CustomFuncDecl struct {
	Name        string  `json:"name,omitempty"`
	Args        []*Decl `json:"args,omitempty"`
	IgnoreError bool    `json:"ignore_error,omitempty"`
	// contains filtered or unexported fields
}

CustomFuncDecl is the decl for a "custom_func".

func (CustomFuncDecl) MarshalJSON

func (d CustomFuncDecl) MarshalJSON() ([]byte, error)

MarshalJSON is the custom JSON marshaler for CustomFuncDecl.

type CustomParseFuncType

type CustomParseFuncType func(*transformctx.Ctx, *idr.Node) (interface{}, error)

CustomParseFuncType represents a custom_parse function type.

type CustomParseFuncs

type CustomParseFuncs = map[string]CustomParseFuncType

CustomParseFuncs is a map from custom_parse names to an actual custom parse functions.

type Decl

type Decl struct {
	// Const indicates the input element is a cost.
	Const *string `json:"const,omitempty"`
	// External indicates the input element is from an external property.
	External *string `json:"external,omitempty"`
	// XPath specifies an xpath for an input element.
	XPath *string `json:"xpath,omitempty"`
	// XPathDynamic specifies a dynamically constructed xpath for an input element.
	XPathDynamic *Decl `json:"xpath_dynamic,omitempty"`
	// CustomFunc specifies the input element is a custom function.
	CustomFunc *CustomFuncDecl `json:"custom_func,omitempty"`
	// CustomParse specifies the input element is to be custom parsed.
	CustomParse *string `json:"custom_parse,omitempty"`
	// Template specifies the input element is a template.
	Template *string `json:"template,omitempty"`
	// Object specifies the input element is an object.
	Object map[string]*Decl `json:"object,omitempty"`
	// Array specifies the input element is an array.
	Array []*Decl `json:"array,omitempty"`
	// ResultType specifies the desired output type of an element.
	ResultType *ResultType `json:"type,omitempty"`
	// NoTrim specifies space trimming in string value of the output element.
	NoTrim bool `json:"no_trim,omitempty"`
	// KeepEmptyOrNull specifies whether or not keep an empty/null output or not.
	KeepEmptyOrNull bool `json:"keep_empty_or_null,omitempty"`
	// contains filtered or unexported fields
}

Decl is the type for omni schema's `transform_declarations` declarations.

func ValidateTransformDeclarations

func ValidateTransformDeclarations(
	schemaContent []byte, customFuncs customfuncs.CustomFuncs, customParseFuncs CustomParseFuncs) (*Decl, error)

ValidateTransformDeclarations validates `transform_declarations` section of an omni schema and returns the `FINAL_OUTPUT` corresponding Decl.

func (Decl) MarshalJSON

func (d Decl) MarshalJSON() ([]byte, error)

MarshalJSON is the custom JSON marshaler for Decl.

type Kind

type Kind string

Kind specifies the types of omni schema's input elements. Note in an actual schema, there is no such a field 'kind'. Kind is inferred.

const (
	// KindConst and rest are kinds for all transform decls.
	KindConst       Kind = "const"
	KindExternal    Kind = "external"
	KindField       Kind = "field"
	KindObject      Kind = "object"
	KindArray       Kind = "array"
	KindCustomFunc  Kind = "custom_func"
	KindCustomParse Kind = "custom_parse"
	KindTemplate    Kind = "template"
)

type ResultType

type ResultType string

ResultType specifies the types of omni schema's output elements. It corresponds to schema's 'type' field.

const (
	// ResultTypeInt and rest are the possible ResultType values.
	ResultTypeInt     ResultType = "int"
	ResultTypeFloat   ResultType = "float"
	ResultTypeBoolean ResultType = "boolean"
	ResultTypeString  ResultType = "string"
)

Jump to

Keyboard shortcuts

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