moleculer-db
moleculer-db copied to clipboard
Can private methods be used without sanitizeParams?
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?
Hm, I don't know right now. I have to think it over.
Why else the private methods should be documented?
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.
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?
No any exact reason.
So, any ideas on this?
If we change it, it will cause breaking changes.
Ok, so this cannot be done or has some meaning and it has to be paused to the next major release?
We can do it, just we should update the major version. Could you make a PR?
I will think about that, if I find some time to do that...
PR made :)