-
-
Notifications
You must be signed in to change notification settings - Fork 751
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Proposal]: New hook data structure #562
Comments
These are good ideas to document for the future. We have permissions, improved filtering, Sequelize ORM handling, integrating feathers-authentication-management that we need to first design and code with our limited resources. They might have a bigger benefit for Feathers without causing disruption. As an aside, renaming |
This probably needs a separate issue of its own for discussion, to look at how existing hooks handle This would make it easier for a single hook to be applied when handling single items ( The proposal is a good one when just considering |
@hubgit The getItems and replaceItems hook utilities already exist to do what you suggest. See https://docs.feathersjs.com/api/hooks-common.html#util-getitems-replaceitems |
As an update we've run into some issues with the |
@ekryski We also need to account for |
100% agree with the proposals, especially for the new query syntax. |
all for the changes to |
Much of this seems to be achievable with one or more hook. It would be a hack compared to making the changes to the service library, but it would be a start. Normalizing the Would it be possible to add a universal after hook that runs before all service hooks instead of after? |
Currently I have done following using an app level
Although, it does not feel right (to me atleast) to check if it is not a
|
I think we need a slight restructure of the hook object that provides a bit firmer “contract” for what can be returned/modified and also helps people avoid common pitfalls. Overall the current structure has worked very well but after a bunch of real-world usage and feedback from the community I think we could improve things.
Problem
Some issues that I’ve noticed:
hook.params
can be a bit of a dumping ground and can be harder to reason as to what is in params, especially as an app grows or hook chains become complex.hook.params
that are required for things to work properly (ie.authenticated
,provider
) is sketchy and easy to accidentally overwrite causing much problems that can be catastrophic and hard to debugnull
as the id. This is really not good!Proposal
Personally I’d like to see the hook object look more like this:
I realize this is a VERY big breaking change that touches every pretty much every module but there are reasons for it:
hook.client
should exist for special client params (ip, mac address, os, app version, etc.)hook.params.provider
should be renamed totransport
to reflect our nomenclature in the docs and moved to the root of the hook and read-only.hook.results.data
. This reduces boilerplate we need to write to check if a response is paginated in each hook.query
outside ofhook.params.query
would not only actually separate thequery
object from params but would I think cognitively help people separate them and also make it easier to reason from the client side what is being sent.This would also change service calls so that they are always:
It would be quite a bit of work but I think would:
null
inadvertently and overwriting/removing all data for a serviceMigration Path
Since this touches pretty much every module and would be a breaking change we'd need to be able to roll it out incrementally. In order to do this I think we can:
I think we can create a hook(s) that you can include at the app or service level that would be able to map a new hook format back to the legacy one in order to keep things backwards compatible and ease migration.
Obviously learning from our previous issues with the
feathers-authentication
1.x release we'd likely want to do pre-releases for these until all the dependent pieces are ready and documented.If we are to proceed, I think the next release (Crow) is the best time to do it as will have brought
feathers-hooks
into core feathers itself, and we may be looking to renamefeathers-hooks-common
tofeathers-hooks
.Obviously this is a proposal and likely to change. I've talked with @daffl and @corymsmith about this at length over the last year but I would ❤️ some input from the community and the rest of the @feathersjs/core-team. Feel free to comment or simply give a 👍 or 👎 .
Related Issues
I'm sure there are more related issues as some of the problems highlighted in here have come up a quite few times in Github and Slack.
The text was updated successfully, but these errors were encountered: