-
Notifications
You must be signed in to change notification settings - Fork 89
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
Created support for event filter and permission hooks. Reorganized service hooks because of this. #75
Conversation
…ermissions - DO NOT MERGE - More than a POC, this is working. Just need to expose new funcs. - feathers-hooks-common works unchanged. - 'Unused' code has been added to the repo for the POC. - 'hooks' for filters were not implemented by duck typing, rather filters, permissions, and new-hooks use common code in /src/common. - (new-hooks are some of the existing services hooks but now using the common code) - It's easy to extend this design for other things. For now: - import filters from 'feathers-hooks-common/filters'; - import permissions from 'feathers-hooks-common/permissions'; - import newHooks from 'feathers-hooks-common/hooks'; Then: - filters.iffElse(predicate, [trueFilters], [falseFilters]); as well as iff, iff.else, when, unless, some, every, ifNot - permissions.iffElse(predicate, [truePermissions], [falsePermissions]) as well as iff, iff.else, when, unless, some, every, ifNot - [truePermissions] evals true if every func returns true i.e. like 'every' - newHooks.iff() works like the existing hooks.iff() but using the new code Also: - filters.remove(), .pluck(), .traverse(), .setFilteredAt() Pros and cons: - duck typing might look nice but what do you do with hooks.iff(predicate, [servicesHook, filterHook, permissionFunc]) ? - using filters., permissions., newHooks. is unambiguous and likely the 'right' way to implement this. - I think it reduces the cognative load on the dev. Code - src/common/conditionals.js is a factory to build conditional funcs. - src/common/alter-data.js has the code that does updates for non-conditional funcs. A factory wouldn't work well. - src/filters, src/permissions, src/hooks build the funcs - test/filters, test/permission, test/hook are tests for the new funcs. Outstanding - Leave these in feathers-hooks-common or bundle them with filters and permissions? - Do we want a filters.validateSchema? - Those new-hooks we have will have to replace any existing hooks.
- filters.iff(some(...), ...) now passes data, connection, hook to funcs within some(...) - added tests to check iffElse predicate gets (hook) or (data, connection, hook) properly - added tests for some/every to permissions
Code Climate is complaining about 'similar' 3 line pieces of code. The code would be harder to read if I refactored. Alternatively there would be going on a dozen fingerprints to file. I want to suppress similar code checking for this repo. |
- When feathers-hooks/bundled and eddyystop/feathers-hooks-common combined, their .js files were copied over as is. New hooks have since been added to new.js, populate.js and so on. - Basically the hooks are not organized in any reasonable fashion. - The tests are also a big bag of files. - The new-hooks have been organized in the same order of the docs. Hooks documented in hooks .. common .. query params are in src/hooks/query-params.js - The new-hooks test are similarly organized e.g. test/hooks/query-params - Repetitive code has been made DRY and JSDoc comments have been removed. The new-hook files are smaller than the regular hook ones. - BREAKING CHANGE Some bundled hooks allowed their last param to be an optional function that determined if the hooks was to be run. This feature has already been deprecated. It has now been removed. (Does anyone use this?) - validateSchema and $client, still under review for the normal hooks, are included here. - The babel-pollyfill has been removed from all the tests. - src/hooks is self contained. It does not refer to any other code. It has its own copy of legacyPopulate for example. The point: - We can use src/filters and src/permissions for filters and permissions. - Devs continue to use feathers-hooks-common as they do now. They don't run any new code that way. - I will update src/hooks with any changes or new hooks added to the current hooks. - We switch over to the new-hooks for Buzzard release and the repo's structure makes sense.
[Removed] |
- Disabled checking for duplication/similar code as per talk with Eric. - Using what Eric used in feathers-authentication
I think they probably should be their own repo but this is a good stop for now. Nice work! Nice work re-organizing the files. That was a good call and was something I was going to do when I had some time. On visual inspection it looks all good. I won't be able to pull this down and run it until this evening but if it's all good I'll merge and release (if that's cool with you @eddyystop) and then try and get |
There are some current hooks whose last param is an optional predicate func. That option displays a deprecated message, and the option was not documented since before I joined up here. Full disclosure: I removed those options in feathers-hooks-common/hooks. I can make changes to remain backward compatible if that's necessary,. |
I feel like I'm missing something, what was the reason for adding 8500 lines of code for supporting filters? I see there is some reorganization but it looks like all the old things are still there. Also, would it make more sense to just have each hook in their own file and not have to worry about how to organize them (that's what I was going for eventually)? |
The idea is to delete the old hook files and use the new, reorganized files. I can break the new hook files into one per hook. There will be something like 80 of them. |
I think it makes sense since the test files are already mostly individual per hook and it'll be easier for everybody to know where to find what. The only other thing I was going to suggest is to use |
I'm down with having 1 hook per file and would prefer it but I don't think it should stop this from shipping. That's some thing that really is internal to the module and doesn't affect the public API. In fact, I'd actually love to have all hook functions exposed top level (even utils) so that we can just do:
Again, not something that should happen in this PR. |
These changes do that. |
There is a related issue I'd like to address.
I think this is too tardy even for an approaching holiday season.
Can we make go, no go decisions on the above 3 PRs? I'll then break the hooks down to individual files. I suggest they remain under the folders as in this PR rather than a bag of 80 files. These folders tie into the structure of the docs. |
- Transpiling error in arrow func with (...hooks).call(this, hook) in iffElse() of old files - Changed code in case same error in slightly different iffElse() in new files
So I can take that as a ? |
It seems like a huge amount of additions to me which also makes it really hard to review but if it's what @ekryski needs then sure. |
I'm looking this afternoon for real. Will come back with comments. @daffl from what I can see the majority of the changes are just restructuring. |
It looks like it's mostly additions and no deletions which what I was wondering about. @eddyystop Should we move each hook into their own files? I think it'll be the best and most straightforward way of structuring it. I can make a PR for it. |
Once this PR is approved my intent was, first, to remove the old files like Second, to break the new files into files for individual hooks. I've already started on this breaking out of the files but stopped part way through because this PR was going nowhere and has enough PRs added to it. |
@eddyystop !!!!! 😄 Sorry it's taken me so long to review this properly but it looks good. Lemme know when you have another PR up to remove the old files and we'll get that merged ASAP. I think having the old files around and mixing new functionality with a re-structuring is what made this a harder review. Maybe in the future we can try and break those up into separate PRs. Really nice work! |
[Edited for simplification and clarity]
hooks = require('feathers-hooks-common')
filterHooks = require('feathers-hooks-common/filters')
filterHooks.iffElse(predicate, [trueFilters], [falseFilters]);
as well as iff, iff.else, when, unless and ifNot
https://github.com/feathersjs/feathers-socket-commons/blob/master/src/events.js#L41-L70
permissionHooks = require('feathers-hooks-common/permissions')
permissionHooks.iffElse(predicate, [truePermissions], [falsePermissions]);
as well as iff, iff.else, when, unless and ifNot
i.e. they work file every().
hooks = require('feathers-hooks-common/hooks')
and permission hooks.
Outstanding
Which hooks to use?
The packaging is sensible and follows the layout of the docs.