api

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2024 License: MIT Imports: 10 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Debug = false

Debug can be set on startup or by REPL command ":d"

View Source
var NoOutputValue = struct{}{}

NoOutputValue is a value to return from a function to prevent output.

View Source
var NoOutputValueString = "__NoOutputValueString"

Functions

This section is empty.

Types

type AccessPath added in v0.11.0

type AccessPath struct {
	Expression string
}

type Config

type Config struct {
	// Optional for initialization
	StartupScript string
	// Optional for command line mode
	RunScript string
	// Optional for remote client mode
	RemoteClient bool
	// Required for CORS
	Origin string
	// Optional when running as a service
	HttpAddr string
	// To configure custom plugins
	Plugins []Plugin
	// If set then this function is called on Start after all plugins are started
	Setup RuntimeSetupFunc
	// If set then this function is installed on the webserver to handle requests on "/" ( /v1 is used )
	HttpHandler http.Handler
}

func (Config) HostPort

func (c Config) HostPort() string

HostPort returns host:port

type EvalResult

type EvalResult struct {
	Error    string `json:"error"`
	Datatype string `json:"datatype"`
	RawData  any    `json:"-"`
}

type HoverResult

type HoverResult struct {
	Error    string `json:"error"`
	Markdown string `json:"markdown"`
	Datatype string `json:"datatype"`
}

type InspectResult

type InspectResult struct {
	Error    string                `json:"error"`
	Object   map[string]any        `json:"object"`
	Paths    map[string]AccessPath `json:"paths"`
	Datatype string                `json:"datatype"`
}

type LoginFunc added in v0.14.0

type LoginFunc func(username, password string) error

LoginFunc is used to call on the plugin when the user is providing credentials.

type NextPageFunc

type NextPageFunc[T any] func(input PagingState) ([]T, PagingState)

NextPageFunc fetches the next chunk of data (a page) and return the result with information about the next chunk (page).

type PageIterator

type PageIterator[T any] struct {
	State PagingState
	// contains filtered or unexported fields
}

func NewPagingIterator

func NewPagingIterator[T any](nexter NextPageFunc[T]) *PageIterator[T]

NewPagingIterator returns an iterator that uses a paging function get chunks of data.

func (*PageIterator[T]) Filter

func (i *PageIterator[T]) Filter(block func(each T) bool) (list []T)

Filter implements JS filter function

func (*PageIterator[T]) GetIndex

func (i *PageIterator[T]) GetIndex(idx int) T

func (*PageIterator[T]) HasNextPage

func (i *PageIterator[T]) HasNextPage() bool

func (*PageIterator[T]) Len

func (i *PageIterator[T]) Len() int

func (*PageIterator[T]) Map

func (i *PageIterator[T]) Map(block func(each T) any) (list []any)

Map implements JS map function

func (*PageIterator[T]) NextPage

func (i *PageIterator[T]) NextPage() []T

func (*PageIterator[T]) ToProxy

func (i *PageIterator[T]) ToProxy(vm *goja.Runtime) goja.Proxy

ToProxy returns a JS proxy that dispatching collection functions to the iterator

type PagingState

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

func (PagingState) Err

func (p PagingState) Err() error

func (PagingState) NextPageIndex

func (p PagingState) NextPageIndex() int

func (PagingState) NextPageToken

func (p PagingState) NextPageToken() string

func (PagingState) WithError

func (p PagingState) WithError(err error) PagingState

func (PagingState) WithNextPageToken

func (p PagingState) WithNextPageToken(token string) PagingState

func (PagingState) WithPageIndex

func (p PagingState) WithPageIndex(index int, done bool) PagingState

type Plugin

type Plugin interface {
	Namespace() string
	Init(ctx PluginContext) error
}

Plugin is the required interface for plugins that expose Javascript functions to the runtime. Each exposed method will be available. Methods should return two values, the last being the optional error.

type PluginContext added in v0.12.0

type PluginContext interface {
	// Set adds a value (value or function) to the Javascript VM namespace
	Set(name string, value any) error

	// OnLogin adds the loginHandler which is called when using the `:l (login)` feature.
	OnLogin(plugin Plugin, loginHandler LoginFunc)
}

type PrintFunc

type PrintFunc func(v any, b *strings.Builder)

PrintFunc is used to register a custom printer for a give typed value.

type ProgramContext added in v0.19.0

type ProgramContext struct {
}

func (ProgramContext) OnLogin added in v0.19.0

func (p ProgramContext) OnLogin(plugin Plugin, logincall LoginFunc)

OnLogin immediately askes for the credentials to setup the plugin

func (ProgramContext) Set added in v0.19.0

func (p ProgramContext) Set(name string, value any) error

Set is a no-op for programs

type RuntimeSetupFunc

type RuntimeSetupFunc func(ctx PluginContext) error

RuntimeSetupFunc is the signature of the Setup callback.

Jump to

Keyboard shortcuts

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