Skip to content

zipDataResult

utils
Source Code | Documentation

Pairs each item in context.data with its corresponding item in context.result by index. Handles both single-item and array data, normalizing them into an array of { data, result } pairs. Only works in after/around hooks for create, update, and patch methods.

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

Example

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

const pairs = zipDataResult(context)
pairs.forEach(({ data, result }) => { /* process each pair *\/ })

Type declaration

Show Type Declarations
ts
export type ZipDataResultOptions = {
  onMismatch?: (context: HookContext) => void
}
export type ZipDataResultItem<D, R> = {
  data: D | undefined
  result: R | undefined
}
/**
 * Pairs each item in `context.data` with its corresponding item in `context.result` by index.
 * Handles both single-item and array data, normalizing them into an array of `{ data, result }` pairs.
 * Only works in `after`/`around` hooks for `create`, `update`, and `patch` methods.
 *
 * @example
 * ```ts
 *
 *
 * const pairs = zipDataResult(context)
 * pairs.forEach(({ data, result }) => { /* process each pair *\/ })
 * ```
 *
 * @see https://utils.feathersjs.com/utils/zip-data-result.html
 */
export declare function zipDataResult<
  H extends HookContext,
  D extends DataSingleHookContext<H> = DataSingleHookContext<H>,
  R extends ResultSingleHookContext<H> = ResultSingleHookContext<H>,
>(context: H, options?: ZipDataResultOptions): ZipDataResultItem<D, R>[]
ArgumentTypeDescription
contextH
optionsZipDataResultOptions

Released under the MIT License.