Skip to content

skippable

hooks
Source Code | Documentation

See also: predicates utils/addSkip

Wraps a hook so it can be conditionally skipped based on a predicate. When the predicate returns true, the wrapped hook is skipped entirely. Commonly used with shouldSkip and addSkip for runtime hook control.

ts
  import { 
skippable
} from 'feathers-utils/hooks';

Example

ts
import { skippable, shouldSkip } from 'feathers-utils/predicates'

const myHook = skippable(someHook(), shouldSkip('someHook'))

Type declaration

Show Type Declarations
ts
/**
 * Wraps a hook so it can be conditionally skipped based on a predicate.
 * When the predicate returns `true`, the wrapped hook is skipped entirely.
 * Commonly used with `shouldSkip` and `addSkip` for runtime hook control.
 *
 * @example
 * ```ts
 *
 *
 * const myHook = skippable(someHook(), shouldSkip('someHook'))
 * ```
 *
 * @see https://utils.feathersjs.com/hooks/skippable.html
 */
export declare const skippable: <H extends HookContext = HookContext>(
  hook: HookFunction<H>,
  predicate: PredicateFn<H>,
) => (context: H, next?: NextFunction) => void | H | Promise<void | H>
ArgumentTypeDescription
hookHookFunction<H>
predicatePredicateFn<H>
typemethodsmulti
before, after, aroundallyes

Predicates

skippable is a utility function that wraps a hook to make it skippable based on a passed predicate. This is useful when you want to conditionally skip the execution of a hook based on certain criteria, such as the presence of a specific parameter in the context.

'feathers-utils' provides a set of predicates that can be used with this utility.

PredicateDescription
every

Returns a predicate that is true only when all given predicates are true (logical AND). Supports both sync and async predicates. Short-circuits on the first false result. Undefined predicates in the list are skipped.

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).

isMulti

Checks if the current hook context represents a multi operation. Returns true for find, for create with array data, and for patch/remove with id === null. Returns false for get and update.

isPaginated

Checks if the current find operation is paginated by inspecting params.paginate and the service's pagination options via getPaginate. Returns false for all methods other than find or when pagination is disabled.

isProvider

Returns a predicate that checks the transport provider of the service call. Matches against 'rest', 'socketio', 'external' (any external provider), or 'server' (internal call without a provider).

not

Negates a sync or async predicate function, inverting its boolean result. Useful for composing conditions like "not external" or "not multi".

shouldSkip

Returns a predicate that checks params.skipHooks to determine if a hook should be skipped. Matches by hook name, hook type (e.g. 'before'), prefixed name (e.g. 'before:myHook'), or 'all' to skip everything. Designed to be used with skippable and addSkip.

some

Returns a predicate that is true when any of the given predicates is true (logical OR). Supports both sync and async predicates. Short-circuits on the first true result. Undefined predicates in the list are skipped.

Released under the MIT License.