Skip to content

multi ​

Concerns the multi flag or the single-vs-many shape of data and results.

NameCategoryDescription
checkMulti
hooks

Throws a MethodNotAllowed error for a multi call (create with an array, patch/remove with id: null) that the service's multi option - or the hook's own multi - doesn't allow, before the following hooks run. Useful to guard against accidental bulk create, patch, or remove calls.

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.

trigger
hooks

Runs actions for the items of create, update, patch and remove calls that match the conditions of a subscription. The conditions are predicates, tested against the data before the call, the items before the call and the items after it. The items come from {@link defineStash}, so subscriptions whose fetches have equal params share them.

Register it as a before and an after hook, or as an around hook.

defineStash
utils

Stashes the items of a call before it runs, to compare them with the items after it. Returns a pair: stash fetches the items before the call, stashed returns them - paired with the items after the call once it ran.

Every defineStash() is its own stash. Stashes of one call with equal params share their fetches. Nothing is stored on params, so concurrent calls with one params object and nested calls stay apart.

stash and stashed without options are exported as well.

getDataIsArray
utils

Normalizes context.data into an array for uniform processing. Returns { data, isArray } where data is always an array and isArray indicates whether the original value was already an array.

getResultIsArray
utils

Normalizes context.result (or context.dispatch) into an array for uniform processing. Handles paginated results by extracting the data array. Returns { result, isArray, key } where key indicates whether 'result' or 'dispatch' was used.

replaceData
utils

Replaces context.data wholesale with the given items, preserving the original single-vs-array shape. This is the explicit inverse of getDataIsArray: get the data as an array, modify or replace the items, then write them back.

replaceResult
utils

Replaces context.result (and/or context.dispatch) wholesale with the given items, preserving the original shape: single item, array, or paginated { data }. This is the explicit inverse of getResultIsArray.

zipDataResult
utils

Pairs each item in context.data with its corresponding item in context.result by index. Handles both single-item and array data, normalizing them into an array of { data, result } pairs. Only works in after/around hooks for create, update, and patch methods.

isMulti
predicates

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.

See all tags for the full vocabulary.

Released under the MIT License.