gojautil

package
v0.0.0-...-e9c30ff Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2024 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AdaptEvent

func AdaptEvent[T any](a *EventAdapter, ev event.Event[T], eventType string, transformArgFn func(*goja.Runtime, T) *goja.Object)

AdaptEvent sets an EventAdapter to adapt an event.Event, exposing an event of type `eventType` to the scripting runtime

func AdaptNoArgEvent

func AdaptNoArgEvent(a *EventAdapter, ev event.NoArgEvent, eventType string, transformArgFn func(*goja.Runtime) *goja.Object)

AdaptNoArgEvent sets an EventAdapter to adapt an event.NoArgEvent, exposing an event of type `eventType` to the scripting runtime

func DoAsync

func DoAsync[T any](runtime *goja.Runtime, runOnLoop ScheduleFunctionNoError, cb AsyncCallback[T]) goja.Value

DoAsync schedules a function to run asynchronously and returns a Promise to track it

func DoAsyncWithTransformer

func DoAsyncWithTransformer[T any](runtime *goja.Runtime, runOnLoop ScheduleFunctionNoError, cb AsyncCallbackWithTransformer[T]) goja.Value

DoAsyncWithTransformer schedules a function to run asynchronously and returns a Promise to track it The transformer returned by the async function will be run synchronously in the goja event loop

func SerializeTime

func SerializeTime(vm *goja.Runtime, d time.Time) goja.Value

SerializeTime converts a time.Time to a JavaScript Date object

func ValidateAndSanitizeNickname

func ValidateAndSanitizeNickname(vm *goja.Runtime, nicknameString string) string

ValidateAndSanitizeNickname validates and sanitizes the given nickname, returning the sanitized string.

func ValidateBananoAddress

func ValidateBananoAddress(vm *goja.Runtime, address string, errorMessage string)

ValidateBananoAddress panics with a TypeError containing the given message, if the given address is not a valid Banano address

Types

type AsyncCallback

type AsyncCallback[T any] func(asyncContext AsyncContext) T

AsyncCallback is a function that should run asynchronously

type AsyncCallbackWithTransformer

type AsyncCallbackWithTransformer[T any] func(asyncContext AsyncContext) (T, PromiseResultTransformer[T])

AsyncCallbackWithTransformer is a function that should run asynchronously and returns a PromiseResultTransformer

type AsyncContext

type AsyncContext struct{}

AsyncContext is a type used mainly to encourage the exclusive use of some functions inside of an AsyncCallback

func (AsyncContext) NewGoError

func (AsyncContext) NewGoError(err error) error

NewGoError wraps an error so that it will later be converted, by DoAsync functions, into a Goja runtime Go error (via runtime.NewGoError) The returned value should immediately be fed to panic()

func (AsyncContext) NewTypeError

func (AsyncContext) NewTypeError(args ...interface{}) *AsyncTypeError

NewTypeError wraps an error so that it will later be converted, by DoAsync functions, into a Goja runtime type error (via runtime.NewTypeError) The returned value should immediately be fed to panic()

type AsyncTypeError

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

AsyncTypeError is a temporary representation of a Goja type error, that will later be converted when the promise is rejected

type EventAdapter

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

EventAdapter adapts a series of event.Event to events that can be used in goja scripts

func NewEventAdapter

func NewEventAdapter(schedule ScheduleFunction) *EventAdapter

NewEventAdapter returns a new EventAdapter

func (*EventAdapter) AddEventListener

func (a *EventAdapter) AddEventListener(call goja.FunctionCall) goja.Value

AddEventListener should be exposed to the goja runtime so scripts can attach event handlers

func (*EventAdapter) RemoveEventListener

func (a *EventAdapter) RemoveEventListener(call goja.FunctionCall) goja.Value

RemoveEventListener should be exposed to the goja runtime so scripts can detach event handlers

func (*EventAdapter) StartOrResume

func (a *EventAdapter) StartOrResume(ctx context.Context, wg *sync.WaitGroup, runtime *goja.Runtime)

StartOrResume should be called when execution starts/resumes with a different context StartOrResume may be safely called multiple times in a row

type PromiseResultTransformer

type PromiseResultTransformer[T any] func(*goja.Runtime, T) interface{}

PromiseResultTransformer is a function that runs synchronously in the JS event loop and transforms the result of an asynchronous promise before it is provided to the JS runtime

type ScheduleFunction

type ScheduleFunction func(func(vm *goja.Runtime) error)

ScheduleFunction is a function that may be called to add tasks to an application's event loop

type ScheduleFunctionNoError

type ScheduleFunctionNoError func(func(vm *goja.Runtime))

ScheduleFunctionNoError is a function that may be called to add tasks to an application's event loop

type UserSerializer

type UserSerializer interface {
	SerializeUser(vm *goja.Runtime, user auth.User) goja.Value
	BuildUserGetter(vm *goja.Runtime, user auth.User) goja.Value
}

UserSerializer serializes users in the JS context of a JAF application

type UserSerializerImplementation

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

UserSerializerImplementation is an implementation of UserSerializer that allows for setting the execution context

func NewUserSerializer

func NewUserSerializer(userCache usercache.UserCache) *UserSerializerImplementation

NewUserSerializer creates a new UserSerializerImplementation

func (*UserSerializerImplementation) BuildUserGetter

func (s *UserSerializerImplementation) BuildUserGetter(vm *goja.Runtime, user auth.User) goja.Value

BuildUserGetter builds a JS function that can be passed as a getter to (*goja.Object).DefineAccessorProperty

func (*UserSerializerImplementation) SerializeUser

func (s *UserSerializerImplementation) SerializeUser(vm *goja.Runtime, user auth.User) goja.Value

SerializeUser converts an auth.User into a JS land object

func (*UserSerializerImplementation) SetContext

func (s *UserSerializerImplementation) SetContext(ctx context.Context)

SetContext should be called with the most recent execution context for an application, every time it changes

Jump to

Keyboard shortcuts

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