Please answer the following questions for yourself before submitting an issue.
According to the documentation, setting an action to false in a service should disable a defined action provided from a mixin.
For example, the actions, remove, list, and find are still available to a custom service using the moleculer-db mixin and the following settings:
actions: {
// disabled default actions
remove: false,
list: false,
find: false
}
Running the command actions in the REPL shows these actions as still being available.
I'm toying around with a set of CQRS services I created; the command side is using eventstore and is responsible for creates, updates, and deletes to my domain model while a query side is responsible for gets, lists, etc. I'm using the base moleculer-db mixin for both, with a custom adapter on the command side and the moleculer-db-adapater-mongoose on the query side.
I want to disable some actions that come along with moleculer-db (for both the command and query sides) so that I can still leverage some of it's capabilities (validation for instance) while also overriding others with my own defined in my services and not publish actions for a particular service is not "responsible" for.
moleculer-db mixin.actionName: false)actionsPlease write your Moleculer & Moleculer DB versions
Edited: I updated and tested again with the same results.
"moleculer": "^0.12.6",
"moleculer-db": "^0.7.3",
"moleculer-db-adapter-mongoose": "^0.7.0",
Thanks, I'm checking....
It looks like this is at least partially to blame:
https://github.com/moleculerjs/moleculer/blob/master/src/service.js#L375
Object.keys(mods[key]).forEach(k => {
const modAction = wrapToHander(mods[key][k]);
const resAction = wrapToHander(res[key][k]);
res[key][k] = _.defaultsDeep(modAction, resAction);
});
The line, res[key][k] = _.defaultsDeep(modAction, resAction); handles the merge but has some strange results. I traced the process and determined that the mixed result ends up with an action where the first property is a Boolean object (if I'm reading this correctly) and the original params and handler are still attached (this appears to be mostly in line with the lodash documentation for defaultsdeep():
mod: insert = false
res: insert = { params:
{ entity: { type: 'object', optional: true },
entities: { type: 'array', optional: true } },
handler: [Function: handler] }
mix: insert = { [Boolean: false]
params:
{ entity: { type: 'object', optional: true },
entities: { type: 'array', optional: true } },
handler: [Function: handler] }
I made the following change to trace the above output and test locally; it seems works (the actions list no longer includes the action set to false), but the question is really whether this is the appropriate place for this to happen or if the broker should be modified to understand the results of the above and somehow leave this action out of the registry.
Object.keys(mods[key]).forEach(k => {
const modAction = wrapToHander(mods[key][k]);
const resAction = wrapToHander(res[key][k]);
console.log(`mod: ${k} = `, modAction);
console.log(`res: ${k} = `, resAction);
if (modAction){
res[key][k] = _.defaultsDeep(modAction, resAction);
}else{
res[key][k] = modAction;
}
console.log(`mix: ${k} = `, res[key][k]);
});
Anyway, just wanted to toss you some of my findings! Happy hunting!
Thank you. I can reproduce it and it seems this feature is not tested, because I don't find about it. So first I create a failed test and after that I start to fix it.
Makes sense to me!
Ok, issue is fixed & tested. You can try it with npm i moleculerjs/moleculer but tomorrow I will make a new release with this fix.
Fantastic! I tested the master branch locally and no longer see the action. Looking forward to the next release. Thanks again!