engine

package
v0.0.0-...-de24375 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ProtoMarshaller = &protojson.MarshalOptions{
		AllowPartial: true,
	}

	ProtoUnmarshaller = &protojson.UnmarshalOptions{
		AllowPartial:   true,
		DiscardUnknown: true,
	}
)
View Source
var (
	ErrRetryEval = errors.New("retry eval")
	ErrSkip      = errors.New("skip eval")
)

Functions

func IsTruthy

func IsTruthy(a any) bool

func JSONVal

func JSONVal(o any) pongo2.Context

func MergeTemplateContexts

func MergeTemplateContexts(c ...pongo2.Context) pongo2.Context

func NodeToTemplate

func NodeToTemplate(node *html.Node) *v1beta1.HTMLNodeTemplateData

func ProtoJSONVal

func ProtoJSONVal(msg proto.Message) pongo2.Context

func UpdateHTML

func UpdateHTML(doc *goquery.Selection, sel DOMQuery, u UpdateHTMLFunc) error

func UpdateHTMLString

func UpdateHTMLString(html string, sel DOMQuery, u UpdateHTMLFunc) (*goquery.Selection, error)

Types

type Browser

type Browser interface {
	RefreshPage(ctx context.Context, content *string) error
	URL(ctx context.Context) (string, error)
	Exists(ctx context.Context, sel string) bool
	Navigate(ctx context.Context, addr string) error
	WriteInput(ctx context.Context, selector, content string) error
	Content(ctx context.Context, selector string) ([]*v1beta1.HTMLNodeTemplateData, error)
}

func NewBrowser

func NewBrowser() Browser

type Context

type Context struct {
	context.Context
	TemplateData *TemplateData
	Stream       renderer.Stream
	Evaluator    Evaluator
	Browser      Browser
	// contains filtered or unexported fields
}

func NewContext

func NewContext(parent context.Context, str renderer.Stream, eval Evaluator, o ContextOpts) (*Context, error)

func (*Context) Copy

func (c *Context) Copy() *Context

func (*Context) RefreshPageState

func (c *Context) RefreshPageState() error

func (*Context) SaveHTML

func (c *Context) SaveHTML(_ context.Context, fp, content string) error

func (*Context) Screenshot

func (c *Context) Screenshot(ctx context.Context, name string) (string, error)

func (*Context) WithContext

func (c *Context) WithContext(ctx context.Context) *Context

func (*Context) WithTimeout

func (c *Context) WithTimeout(to time.Duration) (*Context, context.CancelFunc)

type ContextOpts

type ContextOpts struct {
	ScreenshotDir string
	// Where to save all the HTML files prior to every step run.
	HTMLDir string
}

type DOMDataWriter

type DOMDataWriter interface {
	GetQueries() []DOMQuery
}

DOMDataWriter represents anything that writes data into the DOM. Something like a mouse click, is not a DOMDataWriter.

type DOMQuery

type DOMQuery interface {
	fmt.Stringer
	Query(doc *goquery.Selection) []*goquery.Selection
}

DOMQuery returns a list of selected HTML nodes given a query.

type EachSelector

type EachSelector struct {
	*v1beta1.EachSelector
}

func NewEachSelector

func NewEachSelector(c *v1beta1.EachSelector) *EachSelector

func (*EachSelector) Query

func (e *EachSelector) Query(doc *goquery.Selection) []*goquery.Selection

type EvalHandle

type EvalHandle interface {
	Cancel(err error)
	Done() <-chan struct{}
	Err() error
	// Cause can be nil if the context is Done but no error occurred.
	Cause() error
	Instruction() Instruction
}

func EvalAsync

func EvalAsync(c *Context, act Instruction, to time.Duration) EvalHandle

type Evaluator

type Evaluator interface {
	Eval(c *Context, i Instruction) EvalHandle
}

Evaluator evaluates and tracks Instruction's that have been previously evaluated.

func NewEvaluator

func NewEvaluator(eq EventQueue, to time.Duration) Evaluator

type Event

type Event interface {
	fmt.Stringer
	// contains filtered or unexported methods
}

type EventQueue

type EventQueue chan Event

func NewEventQueue

func NewEventQueue() EventQueue

type Instruction

type Instruction interface {
	fmt.Stringer
	GetId() string
	Eval(c *Context, to time.Duration) error
}

Instruction is an individual pieces of work to be evaluated at runtime. Every Instruction should have their Eval method called via the Evaluator rather than calling it directly.

type NextInstructionEvent

type NextInstructionEvent struct {
	// The Instruction that is now running.
	Instruction Instruction
	Context     *Context
}

func (*NextInstructionEvent) String

func (c *NextInstructionEvent) String() string

type PathNode

type PathNode interface {
	// IsReady lets the Decider know that the PathNode is either  ready
	// to be taken, or is not ready to be taken.
	IsReady(c *Context) bool
}

type StringSelector

type StringSelector string

func (StringSelector) Query

func (StringSelector) String

func (s StringSelector) String() string

type TemplateData

type TemplateData struct {
	*v1beta1.ScriptTemplateData
}

func (*TemplateData) Copy

func (t *TemplateData) Copy() *TemplateData

func (*TemplateData) ForEach

func (t *TemplateData) ForEach(key string, f func(r *TemplateData))

func (*TemplateData) GetStepVal

func (t *TemplateData) GetStepVal(id string) string

func (*TemplateData) Merge

func (t *TemplateData) Merge(m ...*TemplateData) *TemplateData

func (*TemplateData) SetStepVal

func (t *TemplateData) SetStepVal(id, val string)

type TemplateRenderer

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

func CompileTemplate

func CompileTemplate(expr string) (*TemplateRenderer, error)

func (*TemplateRenderer) Render

func (t *TemplateRenderer) Render(d *TemplateData) string

type UpdateHTMLFunc

type UpdateHTMLFunc func(sel *goquery.Selection) error

Jump to

Keyboard shortcuts

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