directus
directus copied to clipboard
Emit nested action events after the transaction completes
Description
Fixes #11172 by storing a queue of nested actionEvents that gets emitted after the main transaction completes. The top level action event will be emitted, followed by the nested action events.
The database in the context is updated from this.knex || getDatabase() to getDatabase() as the emitting of action runs outside of the transaction now.
Sample extension to verify sequence and availability of items
module.exports = function registerHooks({ action }) {
async function callback(data, { database, schema }) {
console.dir({ data }, { depth: null });
console.dir(
await database
.select('*')
.from(data.collection)
.where(schema.collections[data.collection].primary, '=', data.key ?? data.keys[0]),
{ depth: null }
);
}
action('items.create', callback);
action('items.update', callback);
action('items.delete', callback);
};
Type of Change
- [x] Bugfix
- [ ] Improvement
- [ ] New Feature
- [ ] Refactor / codestyle updates
- [ ] Other, please describe:
Requirements Checklist
- [ ] New / updated tests are included
- [x] All tests are passing locally
- [x] Performed a self-review of the submitted code
If adding a new feature:
- [ ] Documentation was added/updated