mirror of
https://github.com/pocketbase/pocketbase.git
synced 2025-02-09 12:14:03 +02:00
added bindings
This commit is contained in:
parent
543fb350ec
commit
70151a3c19
@ -9,6 +9,7 @@ import (
|
||||
"net/http"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
"strings"
|
||||
"time"
|
||||
@ -460,10 +461,32 @@ func filesystemBinds(vm *goja.Runtime) {
|
||||
obj.Set("fileFromMultipart", filesystem.NewFileFromMultipart)
|
||||
}
|
||||
|
||||
func filepathBinds(vm *goja.Runtime) {
|
||||
obj := vm.NewObject()
|
||||
vm.Set("$filepath", obj)
|
||||
|
||||
obj.Set("base", filepath.Base)
|
||||
obj.Set("clean", filepath.Clean)
|
||||
obj.Set("dir", filepath.Dir)
|
||||
obj.Set("ext", filepath.Ext)
|
||||
obj.Set("fromSlash", filepath.FromSlash)
|
||||
obj.Set("glob", filepath.Glob)
|
||||
obj.Set("isAbs", filepath.IsAbs)
|
||||
obj.Set("join", filepath.Join)
|
||||
obj.Set("match", filepath.Match)
|
||||
obj.Set("rel", filepath.Rel)
|
||||
obj.Set("split", filepath.Split)
|
||||
obj.Set("splitList", filepath.SplitList)
|
||||
obj.Set("toSlash", filepath.ToSlash)
|
||||
obj.Set("walk", filepath.Walk)
|
||||
obj.Set("walkDir", filepath.WalkDir)
|
||||
}
|
||||
|
||||
func osBinds(vm *goja.Runtime) {
|
||||
obj := vm.NewObject()
|
||||
vm.Set("$os", obj)
|
||||
|
||||
obj.Set("args", os.Args)
|
||||
obj.Set("exec", exec.Command)
|
||||
obj.Set("exit", os.Exit)
|
||||
obj.Set("getenv", os.Getenv)
|
||||
|
@ -1229,6 +1229,16 @@ func TestRouterBinds(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestFilepathBindsCount(t *testing.T) {
|
||||
app, _ := tests.NewTestApp()
|
||||
defer app.Cleanup()
|
||||
|
||||
vm := goja.New()
|
||||
filepathBinds(vm)
|
||||
|
||||
testBindsCount(vm, "$filepath", 15, t)
|
||||
}
|
||||
|
||||
func TestOsBindsCount(t *testing.T) {
|
||||
app, _ := tests.NewTestApp()
|
||||
defer app.Cleanup()
|
||||
@ -1236,5 +1246,5 @@ func TestOsBindsCount(t *testing.T) {
|
||||
vm := goja.New()
|
||||
osBinds(vm)
|
||||
|
||||
testBindsCount(vm, "$os", 15, t)
|
||||
testBindsCount(vm, "$os", 16, t)
|
||||
}
|
||||
|
7550
plugins/jsvm/internal/types/generated/types.d.ts
vendored
7550
plugins/jsvm/internal/types/generated/types.d.ts
vendored
File diff suppressed because it is too large
Load Diff
@ -515,6 +515,34 @@ declare namespace $filesystem {
|
||||
let fileFromMultipart: filesystem.newFileFromMultipart
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
// filepathBinds
|
||||
// -------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* ` + "`$filepath`" + ` defines common helpers for manipulating filename
|
||||
* paths in a way compatible with the target operating system-defined file paths.
|
||||
*
|
||||
* @group PocketBase
|
||||
*/
|
||||
declare namespace $filepath {
|
||||
export let base: filepath.base
|
||||
export let clean: filepath.clean
|
||||
export let dir: filepath.dir
|
||||
export let ext: filepath.ext
|
||||
export let fromSlash: filepath.fromSlash
|
||||
export let glob: filepath.glob
|
||||
export let isAbs: filepath.isAbs
|
||||
export let join: filepath.join
|
||||
export let match: filepath.match
|
||||
export let rel: filepath.rel
|
||||
export let split: filepath.split
|
||||
export let splitList: filepath.splitList
|
||||
export let toSlash: filepath.toSlash
|
||||
export let walk: filepath.walk
|
||||
export let walkDir: filepath.walkDir
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
// osBinds
|
||||
// -------------------------------------------------------------------
|
||||
@ -527,6 +555,7 @@ declare namespace $filesystem {
|
||||
*/
|
||||
declare namespace $os {
|
||||
export let exec: exec.command
|
||||
export let args: os.args
|
||||
export let exit: os.exit
|
||||
export let getenv: os.getenv
|
||||
export let dirFS: os.dirFS
|
||||
@ -870,6 +899,7 @@ func main() {
|
||||
"github.com/pocketbase/pocketbase/apis": {"*"},
|
||||
"github.com/pocketbase/pocketbase/forms": {"*"},
|
||||
"github.com/pocketbase/pocketbase": {"*"},
|
||||
"path/filepath": {"*"},
|
||||
"os": {"*"},
|
||||
"os/exec": {"Command"},
|
||||
},
|
||||
|
@ -143,8 +143,13 @@ func (p *plugin) registerMigrations() error {
|
||||
process.Enable(vm)
|
||||
baseBinds(vm)
|
||||
dbxBinds(vm)
|
||||
filesystemBinds(vm)
|
||||
securityBinds(vm)
|
||||
// note: disallow for now and give the authors of custom SaaS offerings
|
||||
// some time to adjust their code to avoid eventual security issues
|
||||
//
|
||||
// osBinds(vm)
|
||||
// filepathBinds(vm)
|
||||
// httpClientBinds(vm)
|
||||
|
||||
vm.Set("migrate", func(up, down func(db dbx.Builder) error) {
|
||||
m.AppMigrations.Register(up, down, file)
|
||||
@ -213,9 +218,11 @@ func (p *plugin) registerHooks() error {
|
||||
dbxBinds(vm)
|
||||
filesystemBinds(vm)
|
||||
securityBinds(vm)
|
||||
osBinds(vm)
|
||||
filepathBinds(vm)
|
||||
httpClientBinds(vm)
|
||||
formsBinds(vm)
|
||||
apisBinds(vm)
|
||||
httpClientBinds(vm)
|
||||
vm.Set("$app", p.app)
|
||||
vm.Set("$template", templateRegistry)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user