jsrun

package
v0.3.7 Latest Latest
Warning

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

Go to latest
Published: Aug 2, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package jsrun holds the pure, host-testable core of the js plugin: it runs a user JavaScript snippet in an embedded goja interpreter, exposing a narrow, capability-gated host API (remote_exec, kv, log) injected by the caller. It imports nothing WASM-specific so it can be unit tested on the host toolchain.

Index

Constants

This section is empty.

Variables

View Source
var ErrTimeout = errors.New("jsrun: script timed out")

ErrTimeout is returned when the script exceeds its time budget.

Functions

This section is empty.

Types

type HostAPI

type HostAPI interface {
	RemoteExec(script string) RemoteResult
	KVGet(key string) (value string, found bool, err error)
	KVPut(key, value string) error
	Log(msg string)
}

HostAPI is the capability surface exposed to scripts. The plugin implements it over honey host functions; tests implement it with fakes.

type RemoteResult

type RemoteResult struct {
	Stdout   string
	Stderr   string
	ExitCode int
	Failed   bool
	Changed  bool
	Error    string
}

RemoteResult is the value returned to JS from host.remote_exec.

type Result

type Result struct {
	// Value is the script's completion value, exported to a Go value.
	Value any
	// JSON is Value rendered for the plugin's stdout: a string passes through
	// verbatim, anything else is JSON-encoded; undefined/null yields "".
	JSON string
}

Result is the outcome of running a script.

func Run

func Run(ctx context.Context, code string, args map[string]any, host HostAPI, timeout time.Duration) (Result, error)

Run executes code with args bound to a global `args` object and the host API bound to globals `host`, `kv`, and `log`. A zero timeout means no deadline.

Jump to

Keyboard shortcuts

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