traverse
Source Code | DocumentationRecursively walks and transforms fields in record(s) using neotraverse. The getObject function extracts the target from the context, and transformer is called for every node during traversal --- ideal for deep, structural transformations.
ts
import { traverse } from 'feathers-utils/hooks';Example
ts
import { traverse } from 'feathers-utils/hooks'
app.service('users').hooks({
after: {
all: [traverse({ getObject: (ctx) => ctx.result, transformer: function () { if (this.key === 'password') this.remove() } })]
}
})Type declaration
Show Type Declarations
ts
export type TraverseOptions = {
transformer: (transformContext: any) => any
getObject: (
context: HookContext,
) => Record<string, any> | Record<string, any>[]
}
/**
* Recursively walks and transforms fields in record(s) using `neotraverse`.
* The `getObject` function extracts the target from the context, and `transformer`
* is called for every node during traversal --- ideal for deep, structural transformations.
*
* @example
* ```ts
*
*
* app.service('users').hooks({
* after: {
* all: [traverse({ getObject: (ctx) => ctx.result, transformer: function () { if (this.key === 'password') this.remove() } })]
* }
* })
* ```
*
* @see https://utils.feathersjs.com/hooks/traverse.html
*/
export declare const traverse: <H extends HookContext = HookContext>({
transformer,
getObject,
}: TraverseOptions) => (context: H, next?: NextFunction) => any| Argument | Type | Description |
|---|---|---|
| { transformer, getObject, } | TraverseOptions |
| type | methods | multi |
|---|---|---|
| before, after, around | find, get, create, update, patch, remove | yes |
