-
-
Notifications
You must be signed in to change notification settings - Fork 793
feat: Allow hooks on all methods and add externalMethods option (#3457) #3638
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
base: v6
Are you sure you want to change the base?
Conversation
- Individual method hook chains now work without prior configuration - Add externalMethods option to control HTTP/transport exposure - methods option now controls which methods receive 'all' hooks - Backwards compatible: externalMethods defaults to methods
Deploying feathers-eagle with
|
| Latest commit: |
09bb238
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://2c692814.feathers-a8l.pages.dev |
| Branch Preview URL: | https://v6-hooks-all-methods.feathers-a8l.pages.dev |
Deploying feathers-dove with
|
| Latest commit: |
09bb238
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://09e7e607.feathers.pages.dev |
| Branch Preview URL: | https://v6-hooks-all-methods.feathers.pages.dev |
9d59599 to
da29174
Compare
|
I'm wondering if we need to add a new API if we are promoting using decorators going forward. For internal methods you need to list the parameter names of the method anyway to make it useful (to have things like This already works and lets you register hooks on any method: import { hooks } from 'feathers'
class MyService {
@hooks([]).params('message')
internalMethod(message: string) {}
@hooks([])
find() {
}
} |
|
There are still use cases where decorators will not work well, like when using built-in services from a database manager instance. It's a bit verbose to do custom adapter classes just to be able to add hooks. |
|
I forgot about the .params() calls |
|
Wouldn't that work with the object wrapper? import { hooks } from 'feathers'
import { MemoryService } from 'feathers-memory'
const messageService = hooks(new MemoryService(), {
myMethod: middleware([]).params('message')
})
app.use('messages', messageService) |
Summary
This PR implements the feature requested in #3457, allowing hooks to run on all service methods while providing fine-grained control over which methods are exposed externally.
Changes
@feathersjs/feathers
Type Declarations (
declarations.ts)methodsdescription to clarify it controls which methodsallhooks apply toexternalMethodsoption to control HTTP transport exposureService (
service.ts)getExternalMethods()function (defaults tomethodsfor backwards compatibility)normalizeServiceOptions()to includeexternalMethodsHooks (
hooks.ts)allMethodsto hook store to track which methods receiveallhookscollectHooks()to only includeallhooks for methods inallMethodshookMixin()to allow lazy creation of hook managers for any service methodHTTP Transport (
http/index.ts)getExternalMethods()for HTTP access controlTests
allhooks scopingexternalMethodsHTTP behaviorFeatures
1. Individual method hooks work without configuration
methodscontrols which methods receiveallhooks3.
externalMethodscontrols HTTP exposureBackwards Compatibility
externalMethodsis not specified, it defaults tomethodsRelated