walkQuery
utils
Source Code | DocumentationWalks every property of a Feathers query (including nested $and/$or/$nor/$not arrays) and calls the walker function for each one. The walker receives the property name, operator, value, and path, and can return a replacement value. Returns a new query only if changes were made.
ts
import { walkQuery } from 'feathers-utils/utils';Example
ts
import { walkQuery } from 'feathers-utils/utils'
const query = walkQuery({ age: { $gt: '18' } }, ({ value, operator }) => {
if (operator === '$gt') return Number(value)
})
// => { age: { $gt: 18 } }Type declaration
Show Type Declarations
ts
export type WalkQueryOptions = {
property: string
operator: string | undefined
value: any
path: (string | number)[]
}
export type WalkQueryCallback = (options: WalkQueryOptions) => any
/**
* Walks every property of a Feathers query (including nested `$and`/`$or`/`$nor`/`$not` arrays)
* and calls the `walker` function for each one. The walker receives the property name, operator,
* value, and path, and can return a replacement value. Returns a new query only if changes were made.
*
* @example
* ```ts
*
*
* const query = walkQuery({ age: { $gt: '18' } }, ({ value, operator }) => {
* if (operator === '$gt') return Number(value)
* })
* // => { age: { $gt: 18 } }
* ```
*
* @see https://utils.feathersjs.com/utils/walk-query.html
*/
export declare const walkQuery: <Q extends Query>(
query: Q,
walker: WalkQueryCallback,
) => Q| Argument | Type | Description |
|---|---|---|
| query | Q | |
| walker | WalkQueryCallback |
