staticbackendhq / core

Backend server API handling user mgmt, database, storage and real-time component
https://staticbackend.com
MIT License
682 stars 66 forks source link

[Refactoring] Add helper functions process #96

Closed g41797 closed 4 months ago

g41797 commented 1 year ago

Current code for adding helper functions

    if err := env.addHelpers(vm); err != nil {
        return err
    }
    if err := env.addDatabaseFunctions(vm); err != nil {
        return err
    }
    if err := env.addVolatileFunctions(vm); err != nil {
        return err
    }
    if err := env.addSearch(vm); err != nil {
        return err
    }
    if err := env.addSendMail(vm); err != nil {
        return err
    }

Helper functions may be moved to separated package and added to functions registry via init()

Within Execute - add registered functions

Core code will be more clear

Also it will allow to add custom helper functions

dstpierre commented 1 year ago

Hey there, I'm not sure I fully understand what you're proposing.

Those expored functions are already just wrapper around existing functionalities. Take the Emailer.Send you just added, the glue code is to handle the translation between goja types and Go's, that's mostly it.

I'm not sure I see the benefits of moving that glue code outside the function package.

Maybe having a file in the function package with all that glue code, removing it from runtime.go, say something like exposed.go (for lack of better word for now haha) and moving all those env.addX there and have one function call from the Execute function say: env.setuop() or whatever.

This could be a nice refactor. Can you showcase what you're referring to by having them in their own package, can you give an example for instance of what could be customized?

g41797 commented 1 year ago

Possibly separated package it too much Later I'll try to implement this staff in exposed.go