added jsvm binding
This commit is contained in:
parent
132a8c0aab
commit
085fb1601e
File diff suppressed because it is too large
Load Diff
|
@ -153,6 +153,32 @@ type appWithoutHooks = Omit<pocketbase.PocketBase, ` + "`on${string}`" + `>
|
||||||
*/
|
*/
|
||||||
declare var $app: appWithoutHooks
|
declare var $app: appWithoutHooks
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ` + "`$template`" + ` is a global helper to load and cache HTML templates on the fly.
|
||||||
|
*
|
||||||
|
* The templates uses the standard Go [html/template](https://pkg.go.dev/html/template)
|
||||||
|
* and [text/template](https://pkg.go.dev/text/template) package syntax.
|
||||||
|
*
|
||||||
|
* Example:
|
||||||
|
*
|
||||||
|
* ` + "```" + `js
|
||||||
|
* routerAdd("get", "/hello", (c) => {
|
||||||
|
* const html = $template.loadFiles(
|
||||||
|
* "views/layout.html",
|
||||||
|
* "views/content.html",
|
||||||
|
* ).render({"name": "John"})
|
||||||
|
*
|
||||||
|
* return c.html(200, html)
|
||||||
|
* })
|
||||||
|
* ` + "```" + `
|
||||||
|
*
|
||||||
|
* _Note that this method is available only in pb_hooks context._
|
||||||
|
*
|
||||||
|
* @namespace
|
||||||
|
* @group PocketBase
|
||||||
|
*/
|
||||||
|
declare var $template: template.Registry
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* arrayOf creates a placeholder array of the specified models.
|
* arrayOf creates a placeholder array of the specified models.
|
||||||
* Usually used to populate DB result into an array of models.
|
* Usually used to populate DB result into an array of models.
|
||||||
|
@ -811,6 +837,7 @@ func main() {
|
||||||
"github.com/pocketbase/dbx": {"*"},
|
"github.com/pocketbase/dbx": {"*"},
|
||||||
"github.com/pocketbase/pocketbase/tools/security": {"*"},
|
"github.com/pocketbase/pocketbase/tools/security": {"*"},
|
||||||
"github.com/pocketbase/pocketbase/tools/filesystem": {"*"},
|
"github.com/pocketbase/pocketbase/tools/filesystem": {"*"},
|
||||||
|
"github.com/pocketbase/pocketbase/tools/template": {"*"},
|
||||||
"github.com/pocketbase/pocketbase/tokens": {"*"},
|
"github.com/pocketbase/pocketbase/tokens": {"*"},
|
||||||
"github.com/pocketbase/pocketbase/apis": {"*"},
|
"github.com/pocketbase/pocketbase/apis": {"*"},
|
||||||
"github.com/pocketbase/pocketbase/forms": {"*"},
|
"github.com/pocketbase/pocketbase/forms": {"*"},
|
||||||
|
|
|
@ -29,6 +29,7 @@ import (
|
||||||
"github.com/pocketbase/pocketbase/core"
|
"github.com/pocketbase/pocketbase/core"
|
||||||
m "github.com/pocketbase/pocketbase/migrations"
|
m "github.com/pocketbase/pocketbase/migrations"
|
||||||
"github.com/pocketbase/pocketbase/plugins/jsvm/internal/types/generated"
|
"github.com/pocketbase/pocketbase/plugins/jsvm/internal/types/generated"
|
||||||
|
"github.com/pocketbase/pocketbase/tools/template"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -199,11 +200,12 @@ func (p *plugin) registerHooks() error {
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
|
|
||||||
// this is safe to be shared across multiple vms
|
// safe to be shared across multiple vms
|
||||||
registry := new(require.Registry)
|
requireRegistry := new(require.Registry)
|
||||||
|
templateRegistry := template.NewRegistry()
|
||||||
|
|
||||||
sharedBinds := func(vm *goja.Runtime) {
|
sharedBinds := func(vm *goja.Runtime) {
|
||||||
registry.Enable(vm)
|
requireRegistry.Enable(vm)
|
||||||
console.Enable(vm)
|
console.Enable(vm)
|
||||||
process.Enable(vm)
|
process.Enable(vm)
|
||||||
baseBinds(vm)
|
baseBinds(vm)
|
||||||
|
@ -214,6 +216,7 @@ func (p *plugin) registerHooks() error {
|
||||||
apisBinds(vm)
|
apisBinds(vm)
|
||||||
httpClientBinds(vm)
|
httpClientBinds(vm)
|
||||||
vm.Set("$app", p.app)
|
vm.Set("$app", p.app)
|
||||||
|
vm.Set("$template", templateRegistry)
|
||||||
}
|
}
|
||||||
|
|
||||||
// initiliaze the executor vms
|
// initiliaze the executor vms
|
||||||
|
|
Loading…
Reference in New Issue