checkContext
utils
Source Code | DocumentationValidates that the hook context matches the expected type(s) and method(s). Throws an error if the context is invalid, preventing hooks from running in unsupported configurations. Typically used internally by other hooks.
ts
import { } from 'feathers-utils/utils';Example
ts
import { checkContext } from 'feathers-utils/utils'
const myHook = (context) => {
checkContext(context, ['before', 'around'], ['create', 'patch'], 'myHook')
// or with options object:
checkContext(context, { type: ['before', 'around'], method: ['create', 'patch'], label: 'myHook' })
// ... hook logic
}Type declaration
Show Type Declarations
ts
export type CheckContextOptions<H extends HookContext = HookContext> =
IsContextOptions<H> & {
label?: string
}
/**
* Validates that the hook context matches the expected type(s) and method(s).
* Throws an error if the context is invalid, preventing hooks from running in
* unsupported configurations. Typically used internally by other hooks.
*
* @example
* ```ts
*
*
* const myHook = (context) => {
* checkContext(context, ['before', 'around'], ['create', 'patch'], 'myHook')
* // or with options object:
* checkContext(context, { type: ['before', 'around'], method: ['create', 'patch'], label: 'myHook' })
* // ... hook logic
* }
* ```
*
* @see https://utils.feathersjs.com/utils/check-context.html
*/
export declare function checkContext<H extends HookContext = HookContext>(
context: H,
options: CheckContextOptions<NoInfer<H>>,
): void
export declare function checkContext<H extends HookContext = HookContext>(
context: H,
type?: HookType | HookType[] | null,
methods?: MethodName | MethodName[] | null,
label?: string,
): void| Argument | Type | Description |
|---|---|---|
| context | H | |
| options | CheckContextOptions<NoInfer<H>> | |
| context | H | |
| type | HookType | HookType[] | null | |
| methods | MethodName | MethodName[] | null | |
| label | string | |
| context | H | |
| typeOrOptions | | HookType | HookType[] | CheckContextOptions<NoInfer<H>> | null | |
| methods | MethodName | MethodName[] | null | |
| label | any |
