| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
Adds support for a cleaner chainable syntax when defining hook params:
@hooks([]).params('id', 'data')
async myMethod(id: string, data: any) {}
Instead of the more verbose:
@hooks(middleware([]).params('id', 'data'))
async myMethod(id: string, data: any) {}
The ChainableHookDecorator interface supports:
- .params(...params) - define context param names
- .props(props) - add static context properties
- .defaults(fn) - add default context values
These can be chained in any order and combination.
When a service method is decorated with @hooks([]).params(...), hookMixin
now respects those custom params instead of overriding them with defaults.
This enables the use of custom method signatures:
class MyService {
@(hooks([]).params('userId', 'message'))
async notify(userId: string, message: string) {}
}
When registered with feathers, the notify method will have context.userId
and context.message available instead of the default context.data/params.
Changes:
- hookMixin checks for existing params from decorated methods
- For decorated methods, Feathers context (app, path, service, method)
is added to the existing Context prototype instead of re-wrapping
- Added 5 tests for hookMixin respecting decorator params
Pending integration into main hooks documentation during v6-documentation rewrite.
- Add clone() method to HookManager for creating modified copies - Refactor createChainableDecorator to use clone() instead of manual property copying - Create createFeathersContextProps() helper to define Feathers context props once - Add propsFromDescriptors() helper to convert PropertyDescriptorMap to HookContextData - Tighten decorator types: use AnyFunction instead of Function, specify decorator context types - Simplify hookMixin by using the shared helper functions
- Extract shared statusCodeDescriptor to avoid duplication - Split into createFeathersProps() for HookContextData (standard path) - Split into createFeathersDescriptors() for PropertyDescriptorMap (decorated path) - Remove propsFromDescriptors() conversion function - no longer needed
Use clone().params/props/defaults() instead of directly accessing internal _params/_props/_defaults properties.
| Back | FazBrowse Home | New Git URL |
Summary
Adds a chainable @hooks().params() decorator syntax that allows defining custom parameter names for hook context on service methods. When registered as a Feathers service, hookMixin respects these custom params instead of overriding them with defaults.
Usage
Chainable Methods
All can be chained:
Changes
Why
Previously, custom service methods were limited to the default hook context params (data, params, id). If you had a method like notify(userId, message), hooks would receive ctx.data and ctx.params instead of ctx.userId and ctx.message.
This change allows:
Based on this comment.