1
0
mirror of https://github.com/pocketbase/pocketbase.git synced 2024-11-25 09:21:11 +02:00

enabled tokens binds and removed primitive constructors overwrites

This commit is contained in:
Gani Georgiev 2023-07-29 13:56:31 +03:00
parent 1bbba7a0ae
commit 0a4fdc17a5
4 changed files with 2985 additions and 3006 deletions

View File

@ -260,29 +260,6 @@ func wrapMiddlewares(executors *vmsPool, rawMiddlewares ...goja.Value) ([]echo.M
func baseBinds(vm *goja.Runtime) {
vm.SetFieldNameMapper(FieldMapper{})
// override primitive class constructors to return pointers
// (this is useful when unmarshaling or scaning a db result)
vm.Set("__numberPointer", func(arg float64) *float64 {
return &arg
})
vm.Set("__stringPointer", func(arg string) *string {
return &arg
})
vm.Set("__boolPointer", func(arg bool) *bool {
return &arg
})
vm.RunString(`
this.Number = function(arg) {
return __numberPointer(arg)
}
this.String = function(arg) {
return __stringPointer(arg)
}
this.Boolean = function(arg) {
return __boolPointer(arg)
}
`)
vm.Set("arrayOf", func(model any) any {
mt := reflect.TypeOf(model)
st := reflect.SliceOf(mt)

View File

@ -45,7 +45,7 @@ func TestBaseBindsCount(t *testing.T) {
vm := goja.New()
baseBinds(vm)
testBindsCount(vm, "this", 16, t)
testBindsCount(vm, "this", 13, t)
}
func TestBaseBindsRecord(t *testing.T) {

File diff suppressed because it is too large Load Diff

View File

@ -143,6 +143,7 @@ func (p *plugin) registerMigrations() error {
process.Enable(vm)
baseBinds(vm)
dbxBinds(vm)
tokensBinds(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
@ -222,6 +223,7 @@ func (p *plugin) registerHooks() error {
baseBinds(vm)
dbxBinds(vm)
filesystemBinds(vm)
tokensBinds(vm)
securityBinds(vm)
osBinds(vm)
filepathBinds(vm)