isContext
Returns a predicate that checks whether the hook context matches the given criteria. You can filter by path (service name), type (before/after/around/error), and/or method (find/get/create/update/patch/remove).
import { isContext } from 'feathers-utils/predicates';Example
import { iff, isContext } from 'feathers-utils/predicates'
app.service('users').hooks({
before: { all: [iff(isContext({ method: 'create', type: 'before' }), validateHook())] }
})Hooks for predicates
| Hook | Description |
|---|---|
iff | Conditionally executes a series of hooks when the predicate is truthy.
The predicate can be a boolean value or a sync/async function.
Supports an |
iffElse | Executes one array of hooks when the predicate is truthy, or another array when it is falsy.
The predicate can be a boolean or a sync/async function.
Unlike |
skippable | Wraps a hook so it can be conditionally skipped based on a predicate.
When the predicate returns |
throwIf | Throws a |
unless | Executes a series of hooks when the predicate is falsy --- the inverse of |
Type declaration
Show Type Declarations
export type IsContextOptions = {
path?: MaybeArray<string>
type?: MaybeArray<HookType>
method?: MaybeArray<MethodName>
}
/**
* Returns a predicate that checks whether the hook context matches the given criteria.
* You can filter by `path` (service name), `type` (before/after/around/error),
* and/or `method` (find/get/create/update/patch/remove).
*
* @example
* ```ts
*
*
* app.service('users').hooks({
* before: { all: [iff(isContext({ method: 'create', type: 'before' }), validateHook())] }
* })
* ```
*
* @see https://utils.feathersjs.com/predicates/is-context.html
*/
export declare const isContext: (
options: IsContextOptions,
) => (context: any) => boolean| Argument | Type | Description |
|---|---|---|
| options | IsContextOptions |
