jsvm

package
v1.3.7 Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2026 License: GPL-3.0 Imports: 33 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MustRegister

func MustRegister(app core.App, config Config)

MustRegister registers the jsvm plugin in the provided app instance and panics if it fails.

Example usage:

jsvm.MustRegister(app, jsvm.Config{
	OnInit: func(vm *goja.Runtime) {
		// register custom bindings
		vm.Set("myCustomVar", 123)
	},
})

func Register

func Register(app core.App, config Config) error

Register registers the jsvm plugin in the provided app instance.

func RegisterWithRepo

func RegisterWithRepo(app core.App, config Config, repoManager *repo.RepositoryManager) error

RegisterWithRepo registers the jsvm plugin in the provided app instance with repository manager.

Types

type Config

type Config struct {
	// OnInit is an optional function that will be called
	// after a JS runtime is initialized, allowing you to
	// attach custom Go variables and functions.
	OnInit func(vm *goja.Runtime)

	// RouteRegister is a function to register custom routes from plugins
	RouteRegister func(method, path string, handler func() (interface{}, error)) error

	// HooksWatch enables auto app restarts when a JS app hook file changes.
	//
	// Note that currently the application cannot be automatically restarted on Windows
	// because the restart process relies on execve.
	HooksWatch bool

	// HooksDir specifies the JS app hooks directory.
	//
	// If not set it fallbacks to a relative "./hooks" directory.
	HooksDir string

	// HooksFilesPattern specifies a regular expression pattern that
	// identify which file to load by the hook vm(s).
	//
	// If not set it fallbacks to `^.*(\.plugin\.js|\.plugin\.ts)$`, aka. any
	// HooksDir file ending in ".plugin.js" or ".plugin.ts" (the last one is to enforce IDE linters).
	HooksFilesPattern string

	// HooksPoolSize specifies how many goja.Runtime instances to prewarm
	// and keep for the JS app hooks gorotines execution.
	//
	// Zero or negative value means that it will create a new goja.Runtime
	// on every fired goroutine.
	HooksPoolSize int

	// MigrationsDir specifies the JS migrations directory.
	//
	// If not set it fallbacks to a relative "./migrations" directory.
	MigrationsDir string

	// If not set it fallbacks to `^.*(\.js|\.ts)$`, aka. any MigrationDir file
	// ending in ".js" or ".ts" (the last one is to enforce IDE linters).
	MigrationsFilesPattern string

	// TypesDir specifies the directory where to store the embedded
	// TypeScript declarations file.
	//
	// If not set it fallbacks to ".".
	//
	// Note: Avoid using the same directory as the HooksDir when HooksWatch is enabled
	// to prevent unnecessary app restarts when the types file is initially created.
	TypesDir string
}

Config defines the config options of the jsvm plugin.

type MigrationEntry

type MigrationEntry struct {
	Name string
	Up   func(core.App) error
	Down func(core.App) error
}

MigrationEntry 存储迁移信息

Jump to

Keyboard shortcuts

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