jsvm

package
v0.0.0-...-c627d9c Latest Latest
Warning

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

Go to latest
Published: Jan 23, 2023 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package jsvm implements optional utilities for binding a JS goja runtime to the PocketBase instance (loading migrations, attaching to app hooks, etc.).

Currently it provides the following plugins:

1. JS Migrations loader:

jsvm.MustRegisterMigrations(app, &jsvm.MigrationsOptions{
	Dir: "custom_js_migrations_dir_path", // default to "pb_data/../pb_migrations"
})

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MustRegisterMigrations

func MustRegisterMigrations(app core.App, options *MigrationsOptions)

MustRegisterMigrations registers the migrations loader plugin to the provided app instance and panics if it fails.

Internally it calls RegisterMigrations(app, options).

If options is nil, by default the js files from pb_data/migrations are loaded. Set custom options.Dir if you want to change it to some other directory.

func NewBaseVM

func NewBaseVM() *goja.Runtime

func RegisterMigrations

func RegisterMigrations(app core.App, options *MigrationsOptions) error

RegisterMigrations registers the plugin to the provided app instance.

If options is nil, by default the js files from pb_data/migrations are loaded. Set custom options.Dir if you want to change it to some other directory.

Types

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

func (u FieldMapper) MethodName(_ reflect.Type, m reflect.Method) string

MethodName implements the [FieldNameMapper.MethodName] interface method.

type MigrationsOptions

type MigrationsOptions struct {
	// Dir specifies the directory with the JS migrations.
	//
	// If not set it fallbacks to a relative "pb_data/../pb_migrations" directory.
	Dir string
}

MigrationsOptions defines optional struct to customize the default migrations loader behavior.

Jump to

Keyboard shortcuts

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