Utilities
Utils are utility functions that can be used in hooks or anywhere else in your Feathers application. They can be used to perform common tasks such as mutating data, validating input, or formatting output.
| Utility | Description |
|---|---|
addSkip | Adds hook names to |
addToQuery | Safely merges properties into a Feathers query object. If a property already exists
with a different value, it wraps both in a The added query narrows the target — every condition is kept, so the result matches
at most what the target matched. Two conditions on the same property are therefore
intersected, never unioned: adding The query filters |
checkContext | 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. The options form takes the same criteria as |
chunkFind | Use This function is useful for processing large datasets in batches without loading everything into memory at once. It uses pagination to fetch results in chunks, yielding each page's data array. |
contextToJson | Converts a FeathersJS HookContext to a plain JSON object by calling |
createMany | Creates all given items with a single If the service does not allow multi creating (its |
defineHooks | 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. |
dotifyQuery | Converts the nested properties of a Feathers query into dot notation —
The conversion is query-aware rather than a generic object flatten:
A value is only treated as a path when it is a non-empty plain object with at
least one non- Use Nothing is ever dropped when two paths collide. Deep-equal values collapse
into one, operator objects with disjoint keys merge, and a genuine
contradiction is wrapped in |
eqOrIn | Turns a list of values into a query value that matches any of them: a single
remaining value becomes an equality match, everything else a Deduplication compares primitives with |
gateParams | Selects and/or projects Paths are resolved with lodash
Keys not mentioned in the schema are KEPT by default, so forgetting a relevant
key can only cause a harmless cache miss, never a false hit. Pass
|
getDataIsArray | Normalizes |
getExposedMethods | Returns the list of method names that are publicly exposed by a Feathers service.
Reads the internal |
getPaginate | Resolves the active pagination options for the current hook context.
Checks (in order): |
getResultIsArray | Normalizes |
iterateFind | Use This function is useful for iterating over large datasets without loading everything into memory at once. It uses pagination to fetch results in chunks, allowing you to process each item as it is retrieved. |
mergeQuery | Properties are combined with a logical operator rather than merged at the value
level, so the result is always a valid query: Under This is well suited to merging a client-provided query with a server-side restriction inside a hook. |
mutateData | Applies a transformer function to each item in |
mutateResult | Applies a transformer function to each item in |
neOrNin | Turns a list of values into a query value that excludes all of them: a single
remaining value becomes Deduplication compares primitives with |
nestifyQuery | Converts the dot-notation properties of a Feathers query into nested objects —
The conversion is query-aware rather than a generic object unflatten:
Use Nothing is ever dropped when two keys collide. Deep-equal values collapse into
one, objects with disjoint keys merge, and a genuine contradiction is wrapped
in Caveat: this direction is best effort and not semantics-preserving on
MongoDB, where |
patchBatch | Batch patching utility that takes an array of items to be changed and returns an array of arguments to be called with the This utility is useful when you need to patch multiple items with varying data in as few requests as possible. |
patchMany | Patches all items matching If the service does not allow multi patching (its The |
queryDefaults | Adds default properties to a Feathers query — but only for fields the query does
not already constrain. Presence is checked with {@link queryHasProperty}, so a field
referenced anywhere (including nested in |
queryHasProperty | Checks whether a Feathers query contains one or more properties — including
properties nested inside |
removeMany | Removes all items matching If the service does not allow multi removing (its The |
replaceData | Replaces |
replaceResult | Replaces |
simplifyQuery | Normalizes the logical structure of a Feathers query without changing what it
matches: empty |
skipResult | Sets |
sortQueryProperties | Recursively normalizes a Feathers query object for order-independent comparison.
Sorts object keys and sorts arrays within This is useful for generating stable cache keys where
|
stringifyParams | Serializes Feathers Two normalizations make semantically-equal params produce the same string:
Serialization is crash-safe and never throws on values that leak through a
params whitelist: circular references become |
toPaginated | Ensures a result is in Feathers paginated format ( |
transformParams | Safely applies a |
unpaginate | Extracts the items from a find result that may or may not be paginated.
A plain array is returned as-is, a paginated result yields its This is the lossy counterpart to |
waitForServiceEvent | Wait for a service event to fire and resolve with the emitted record. Useful
in tests to await the result of an asynchronous service event, a bit like
Curried: bind the Feathers emits events as |
walkQuery | Walks every property of a Feathers query (including nested |
zipDataResult | Pairs each item in |
