Skip to content

validation

Rejects a call that does not meet a requirement.

NameCategoryDescription
checkMulti
hooks

Checks if the multi option is enabled for the current method and throws a MethodNotAllowed error if multi operations are not permitted. Useful to guard against accidental bulk create, patch, or remove calls.

checkRequired
hooks

Validates that the specified fields exist on context.data and are not falsy. Numeric 0 and boolean false are treated as valid values. Throws a BadRequest error if any required field is missing or null.

preventChanges
hooks

Prevents patch calls from modifying certain fields. By default, the protected fields are silently removed from context.data. When error is set, a BadRequest is thrown if any protected field is present.

Supports dot.notation for nested fields.

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.

throwIfIsMulti
hooks

Throws a BadRequest error when the current operation is a multi operation (array data on create, or id === null on patch/remove). Useful to prevent bulk operations on services that should only handle single items.

throwIfIsProvider
hooks

Throws a MethodNotAllowed error when the request comes from one of the specified transports. Combines throwIf with the isProvider predicate for a convenient one-liner. Use this to restrict methods to server-only or specific transport types.

checkContext
utils

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. Also narrows the context type based on the passed options.

See all tags for the full vocabulary.

Released under the MIT License.