Documentation ¶
Index ¶
- func AdaptEvent[T any](a *EventAdapter, ev event.Event[T], eventType string, ...)
- func AdaptNoArgEvent(a *EventAdapter, ev event.NoArgEvent, eventType string, ...)
- func DoAsync[T any](runtime *goja.Runtime, runOnLoop ScheduleFunctionNoError, cb AsyncCallback[T]) goja.Value
- func DoAsyncWithTransformer[T any](runtime *goja.Runtime, runOnLoop ScheduleFunctionNoError, ...) goja.Value
- func SerializeTime(vm *goja.Runtime, d time.Time) goja.Value
- func ValidateAndSanitizeNickname(vm *goja.Runtime, nicknameString string) string
- func ValidateBananoAddress(vm *goja.Runtime, address string, errorMessage string)
- type AsyncCallback
- type AsyncCallbackWithTransformer
- type AsyncContext
- type AsyncTypeError
- type EventAdapter
- type PromiseResultTransformer
- type ScheduleFunction
- type ScheduleFunctionNoError
- type UserSerializer
- type UserSerializerImplementation
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 ¶
SerializeTime converts a time.Time to a JavaScript Date object
func ValidateAndSanitizeNickname ¶
ValidateAndSanitizeNickname validates and sanitizes the given nickname, returning the sanitized string.
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 ¶
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 ¶
ScheduleFunction is a function that may be called to add tasks to an application's event loop
type ScheduleFunctionNoError ¶
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 ¶
BuildUserGetter builds a JS function that can be passed as a getter to (*goja.Object).DefineAccessorProperty
func (*UserSerializerImplementation) SerializeUser ¶
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