Skip to content

Hooks

checkMulti

Check if the 'multi' option is set for a method. You can use this to early throw an error if 'multi' is not set.

checkRequired

Check selected fields exist and are not falsey. Numeric 0 is acceptable.

combine

Sequentially execute multiple hooks.

createRelated

Create related records in other services.

debug

Display the current hook context for debugging.

disablePagination

Disables pagination when query.$limit is -1 or '-1'.

disallow

Prevents access to a service method completely or for specific transports.

iff

Execute one or another series of hooks depending on a sync or async predicate.

iffElse

Execute one array of hooks or another based on a sync or async predicate.

onDelete

hook to manipulate related items on delete.

This can be handled by your database, but this hook allows you to do it in your application logic. Then you get service events and hooks for the related items.

paramsForServer

a hook to move params to query.$client the server only receives 'query' from params. All other params are ignored. So, to use $populateParams on the server, we need to move the params to query.$client the server will move them back to params

paramsFromClient

Pass context.params from client to server. Server hook.

preventChanges

Prevent patch service calls from changing certain fields.

setData

hook to set properties on context.data

setField

The setField hook allows to set a field on the hook context based on the value of another field on the hook context.

setResult

hook to set properties on context.result

setSlug

Fix slugs in URL, e.g. /stores/:storeId.

skippable

Wrap a hook to make it skippable

softDelete

Allow to mark items as deleted instead of removing them.

stashBefore

Stash current value of record, usually before mutating it. Performs a get call.

throwIf

Throw an error if the predicate function returns true.

This hook is useful for validating conditions before proceeding with the request.

throwIfIsMulti

Throw an error if the context is multi. You can use this to early return if a user provides an array on create or id:null on patch or remove.

throwIfIsProvider

Throw an error for certain transports.

transformData

Make changes to items in context.data. Very flexible.

transformQuery

Transforms the query object.

transformResult

Make changes to items in context.result. Very flexible.

traverse

Transform fields & objects in place in the record(s) using a recursive walk. Powerful. Check docs at https://github.com/substack/js-traverse for info on transformContext!

unless

Execute a series of hooks if a sync or async predicate is falsy.

Released under the MIT License.