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