Documentation
¶
Overview ¶
Package jsvm implements pluggable utilities for binding a JS goja runtime to the PocketBase instance (loading migrations, attaching to app hooks, etc.).
Example:
jsvm.MustRegister(app, jsvm.Config{
WatchHooks: true,
})
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func MustRegister ¶
MustRegister registers the jsvm plugin in the provided app instance and panics if it fails.
Example usage:
jsvm.MustRegister(app, jsvm.Config{})
Types ¶
type Config ¶
type Config struct {
// 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 "pb_data/../pb_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 `^.*(\.pb\.js|\.pb\.ts)$`, aka. any
// HookdsDir file ending in ".pb.js" or ".pb.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 "pb_data/../pb_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 "pb_data".
//
// 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 FieldMapper ¶
type FieldMapper struct {
}
FieldMapper provides custom mapping between Go and JavaScript property names.
It is similar to the builtin "uncapFieldNameMapper" but also converts all uppercase identifiers to their lowercase equivalent (eg. "GET" -> "get").
func (FieldMapper) FieldName ¶
func (u FieldMapper) FieldName(_ reflect.Type, f reflect.StructField) string
FieldName implements the [FieldNameMapper.FieldName] interface method.
func (FieldMapper) MethodName ¶
MethodName implements the [FieldNameMapper.MethodName] interface method.