You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We should extend the current Action Hooks feature. It is used by the ActionHook middleware and it can be defined only before, after & error hooks for actions.
For some major components, it would be good if the user can define custom hooks for the custom functions, e.g. define a beforeTransform or afterPopulate hook in moleculer-db.
Basic example
module.exports={name: "posts",mixins: [DbService],hooks: {// It will be called before transformingbeforeTransform(ctx,params,doc){doc.id=encrypt(doc._id);deletedoc._id;},// It will be called after populatingafterPopulate(ctx,populate,doc){if(doc.author){deletedoc.authorID;}}},};
functiontransformDocuments(ctx,params,doc){// Call beforeTransform hookif(this.hooks.beforeTransform){awaitthis.hooks.beforeTransform(ctx,params,doc);}// Do transforming// Call afterTransform hookif(this.hooks.afterTransform){awaitthis.hooks.afterTransform(ctx,params,doc);}}
Motivation
Detailed design
Drawbacks
Alternatives
Adoption strategy
Unresolved questions
The text was updated successfully, but these errors were encountered:
Summary
We should extend the current Action Hooks feature. It is used by the ActionHook middleware and it can be defined only
before
,after
&error
hooks for actions.For some major components, it would be good if the user can define custom hooks for the custom functions, e.g. define a
beforeTransform
orafterPopulate
hook in moleculer-db.Basic example
Motivation
Detailed design
Drawbacks
Alternatives
Adoption strategy
Unresolved questions
The text was updated successfully, but these errors were encountered: