feathersjs-ecosystem / feathers-sync

Synchronize service events between Feathers application instances
MIT License
222 stars 41 forks source link

Try to guess context data that's required down stream #199

Open mrfrase3 opened 7 months ago

mrfrase3 commented 7 months ago

Summary

Currently if you need to manually submit an event, like you want to push an update after calling _patch, this lib requires you to build a context object manually or else it wont work properly:

const newItem = await app.service(path)._patch(item._id, data);
app.service(path).emit('patched', newItem, { method: 'patch', id: item._id, result: newItem, path, params: {} });

most of the required info in context can already be gleaned from the execution context, so the code in this PR attempts a best guess context object. Whilst not perfect, it at least protects the developer from forgetting a fixed set of fields:

app.service(path).emit('patched', newItem);