js

package
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2023 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const (
	RuntimeTTL = 5 * time.Minute
)

Variables

View Source
var (
	// InterruptedMessage is the string value of Interrupted.
	InterruptedMessage = "RuntimeError: timeout"

	// Interrupted is returned by Exec if the execution is
	// interrupted.
	Interrupted = errors.New(InterruptedMessage)
)
View Source
var DefaultConfig = Config{Source: ""}
View Source
var DefaultLibraryProvider = MakeFileLibraryProvider(".")

Functions

func MakeFileLibraryProvider

func MakeFileLibraryProvider(dir string) func(*Interpreter, string) (string, error)

DefaultProvider is a method that Provide will use if the interpreter's Provider is nil.

This method barely supports names that are URLs with protocols of "file", "http", and "https". There currently is no additional control when using HTTP/HTTPS.

func WithMaxRuntimes

func WithMaxRuntimes(n int) func(*Interpreter) error

Types

type Config

type Config struct {
	Source string `json:"source,omitempty"`
}

Config can be passed into NewFilter() in order to configure the behavior of the sender.

func NewConfig

func NewConfig(config interface{}) (*Config, error)

func (*Config) FromJSON

func (c *Config) FromJSON(in string) error

func (*Config) FromYAML

func (c *Config) FromYAML(in string) error

func (*Config) JSON

func (c *Config) JSON() (string, error)

func (*Config) String

func (c *Config) String() string

func (*Config) Validate

func (c *Config) Validate() error

Validate will validate configs

func (Config) WithDefaults

func (c Config) WithDefaults() *Config

WithDefaults will set default values

func (*Config) YAML

func (c *Config) YAML() (string, error)

type Filter

type Filter struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func NewFilter

func NewFilter(tid tenant.Id, plugin string, name string, config interface{}, secrets secret.Vault, tableSyncer syncer.DeltaSyncer) (*Filter, error)

func (*Filter) Config added in v0.2.1

func (f *Filter) Config() interface{}

func (*Filter) EventErrorCount added in v1.1.2

func (f *Filter) EventErrorCount() int

func (*Filter) EventErrorVelocity added in v1.1.2

func (f *Filter) EventErrorVelocity() int

func (*Filter) EventFilterCount added in v1.1.2

func (f *Filter) EventFilterCount() int

func (*Filter) EventFilterVelocity added in v1.1.2

func (f *Filter) EventFilterVelocity() int

func (*Filter) EventSuccessCount added in v1.1.2

func (f *Filter) EventSuccessCount() int

func (*Filter) EventSuccessVelocity added in v1.1.2

func (f *Filter) EventSuccessVelocity() int

func (*Filter) EventTs added in v1.1.2

func (f *Filter) EventTs() int64

func (*Filter) Filter

func (f *Filter) Filter(evt event.Event) []event.Event

Filter executes javascript transformation

func (*Filter) Hash added in v1.1.2

func (f *Filter) Hash() string

func (*Filter) Name added in v0.2.1

func (f *Filter) Name() string

func (*Filter) Plugin added in v0.2.1

func (f *Filter) Plugin() string

func (*Filter) Tenant added in v0.3.0

func (f *Filter) Tenant() tenant.Id

type Interpreter

type Interpreter struct {
	sync.Mutex
	// Provider is a pluggable library provider, which can be used
	// instead of (or in addition to) the standard Provide method,
	// which will just use DefaultProvider if this Provider is
	// nil.
	//
	// A problem: For a multitenant service, we need some access
	// control. If a single LibraryProvider will provide all the
	// libraries for all tenants, we need a mechanism to provide
	// access control.  We could add another parameter that
	// carries the required data (something related to tenant
	// name), but it's hard to provide something generic.  With
	// trepidation, perhaps just use a Value in the ctx?
	LibraryProvider func(interpreter *Interpreter, libraryName string) (string, error)
	EnvSetter       func(o *goja.Runtime, env map[string]interface{})
	// contains filtered or unexported fields
}

Interpreter implements an interpreter based on Goja, which is a Go implementation of ECMAScript 5.1+.

See https://github.com/dop251/goja.

func NewInterpreter

func NewInterpreter(options ...func(*Interpreter) error) (*Interpreter, error)

func (*Interpreter) Compile

func (interpreter *Interpreter) Compile(code string) (interface{}, error)

Compile calls goja.Compile after compiling libraries if any. This method can block if the interpreter's library Provider blocks in order to obtain external libraries.

func (*Interpreter) CompileLibrary

func (interpreter *Interpreter) CompileLibrary(name, src string) (interface{}, error)

CompileLibraries checks any libraries at LibrarySources.

This method originally precompiled these libraries, but goja doesn't currently support combining ast.Programs. So we won't actually use anything we precompile! Perhaps in the future. But we can at least check that the libraries do in fact compile.

func (*Interpreter) Exec

func (interpreter *Interpreter) Exec(evt event.Event, code string) ([]event.Event, error)

func (*Interpreter) ProvideLibrary

func (interpreter *Interpreter) ProvideLibrary(name string) (string, error)

ProvideLibrary resolves the library name into a library.

We experimented with other approaches including returning parsed code and a struct representing a library. Probably will want to move back in that direction.

type Program

type Program struct {
	*goja.Program
	// contains filtered or unexported fields
}

Interpreter implements an interpreter based on Goja, which is a Go implementation of ECMAScript 5.1+.

See https://github.com/dop251/goja.

type Runtime

type Runtime struct {
	*goja.Runtime
	// contains filtered or unexported fields
}

Interpreter implements an interpreter based on Goja, which is a Go implementation of ECMAScript 5.1+.

See https://github.com/dop251/goja.

Jump to

Keyboard shortcuts

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