Working solution to add a lifecycle callback directly to component inside of collection.
// src/index.ts
async bootstrap() {
// your code
const _strapi: any = strapi;
const _metadata: Map<any, any> = _strapi.db.metadata;
_metadata.set("componentGroup.component", {
..._metadata.get("componentGroup.component"),
lifecycles: {
beforeUpdate: async (e: Event) => {
// change data object passed to the lifecycle event
e.params.data.your_attribute_1 = "new_value";
// or use current state of component to change data object
const comp = await strapi
.query("componentGroup.component")
.findOne({ where: { id: 25 } });
e.params.data.your_attribute = comp.your_attribute.concat("new_value");
},
},
});
//your code
}