Skip to content

control-flow

Decides whether or in which order other hooks run, rather than touching the call itself.

NameCategoryDescription
combine
hooks

Sequentially executes multiple hooks, passing the updated context from one to the next. Returns a single hook function that runs the entire chain. If any hook throws, the error is annotated with the current hook context.

iff
hooks

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 .else(...) chain for the falsy branch. Also exported as when.

iffElse
hooks

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 iff, both branches are provided upfront without chaining.

skippable
hooks

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.

throwIf
hooks

Throws a BadRequest error when the given predicate function returns true. The predicate receives the hook context and can be async. Useful for validating conditions before proceeding with a request.

unless
hooks

Executes a series of hooks when the predicate is falsy --- the inverse of iff. The predicate can be a boolean or a sync/async function. Useful for applying hooks to all contexts except those matching a condition.

addSkip
utils

Adds hook names to context.params.skipHooks so that skippable-wrapped hooks will be bypassed for the current service call. Accepts a single name or an array. Duplicates are automatically removed.

defineHooks
utils

TypeScript helper that provides full type inference and autocompletion when defining service hooks. It is an identity function that simply returns its input, but enables your IDE to infer the correct hook context types.

fromPredicate
resolvers

Adapts an existing predicate function (like isProvider, isContext) into a resolver condition. The predicate receives the hook context extracted from the resolver options. Only synchronous predicates are supported.

and
predicates

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
predicates

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

not
predicates

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

or
predicates

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.

shouldSkip
predicates

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.

See all tags for the full vocabulary.

Released under the MIT License.