Skip to content

addToQuery

Category
Export size
min 0.71 kB · gzip 0.40 kB

Safely merges properties into a Feathers query object. If a property already exists with a different value, it wraps both in a $and array to preserve both conditions. If the exact same key-value pair already exists, no changes are made. When the added query is itself a pure $and ({ $and: [...] }), its branches are flattened into the target's $and rather than nested.

ts
  import {  } from 'feathers-utils/utils';

Example

ts
import { addToQuery } from 'feathers-utils/utils'

const query = { status: 'active' }
addToQuery(query, { role: 'admin' })
// => { status: 'active', role: 'admin' }

Type declaration

Show Type Declarations
ts
/**
 * Safely merges properties into a Feathers query object. If a property already exists
 * with a different value, it wraps both in a `$and` array to preserve both conditions.
 * If the exact same key-value pair already exists, no changes are made. When the added
 * query is itself a pure `$and` (`{ $and: [...] }`), its branches are flattened into the
 * target's `$and` rather than nested.
 *
 * @example
 * ```ts
 *
 *
 * const query = { status: 'active' }
 * addToQuery(query, { role: 'admin' })
 * // => { status: 'active', role: 'admin' }
 * ```
 *
 * @see https://utils.feathersjs.com/utils/add-to-query.html
 */
export declare function addToQuery<Q extends Query>(targetQuery: Q, query: Q): Q
ArgumentTypeDescription
targetQueryQ
queryQ

Released under the MIT License.