moleculer-db icon indicating copy to clipboard operation
moleculer-db copied to clipboard

Can private methods be used without sanitizeParams?

Open HighSoftWare96 opened this issue 5 years ago • 11 comments

Hi, I've noticed that private methods like _find or _create are documented in the wiki. I personally have used them in my project for overriding the default actions of the Db Adapter adding or removing something in the endpoint but at the end using the relative private method to accomplish the main goal of the action. Something like this:

// ...
actions: {
   find: {
    params: // ...
    handler(ctx): {
       // do something more ...
       return this._find(ctx, params).then(
           // do something else
       )
    }
   },
}

The problem is that sometimes the params for the private method are not quite correct and calling the private method without calling sanitizeParams can bring to unexpected results.. I was wondering: may be the case to move the sanitizeParams inside the private method so when I try to override some default action I can be sure that the params are correctly parsed?

HighSoftWare96 avatar Jan 29 '20 09:01 HighSoftWare96

Hm, I don't know right now. I have to think it over.

icebob avatar Jan 30 '20 12:01 icebob

Why else the private methods should be documented?

HighSoftWare96 avatar Jan 30 '20 19:01 HighSoftWare96

They are not private methods, just I don't want to cause a breaking change with them. E.g if users (using the previous version of DB service) created create, update...etc methods in their services, and they switched to the newer version, it would cause problems because their custom methods overwrite these new internal methods.

icebob avatar Jan 30 '20 20:01 icebob

Mm.. maybe I explained that badly, the propose is only to move the parsingParams inside the private methods.... Is there an actual problem in this? At least you get the params passed to the methods treated just like they were parameters passed directly to the pure API action... Is there an exact propose for the parsingParams to being out of the private methods?

HighSoftWare96 avatar Jan 30 '20 23:01 HighSoftWare96

No any exact reason.

icebob avatar Jan 31 '20 19:01 icebob

So, any ideas on this?

HighSoftWare96 avatar Feb 25 '20 14:02 HighSoftWare96

If we change it, it will cause breaking changes.

icebob avatar Feb 25 '20 17:02 icebob

Ok, so this cannot be done or has some meaning and it has to be paused to the next major release?

HighSoftWare96 avatar Feb 26 '20 17:02 HighSoftWare96

We can do it, just we should update the major version. Could you make a PR?

icebob avatar Feb 26 '20 17:02 icebob

I will think about that, if I find some time to do that...

HighSoftWare96 avatar Feb 26 '20 18:02 HighSoftWare96

PR made :)

HighSoftWare96 avatar Feb 29 '20 10:02 HighSoftWare96