{"version":3,"file":"transform-result.hook-V2QYN2K0.mjs","names":[],"sources":["../src/hooks/transform-data/transform-data.hook.ts","../src/hooks/transform-query/transform-query.hook.ts","../src/hooks/transform-result/transform-result.hook.ts"],"sourcesContent":["import type { HookContext, NextFunction } from '@feathersjs/feathers'\nimport { mutateData } from '../../utils/mutate-data/mutate-data.util.js'\nimport type { TransformerInputFn } from '../../types.js'\nimport type { DataSingleHookContext } from '../../utility-types/hook-context.js'\nimport type { AnyFallback } from '../../internal.utils.js'\n\ntype Data<H extends HookContext> = AnyFallback<\n  DataSingleHookContext<H>,\n  Record<string, any>\n>\n\n/**\n * Transforms each item in `context.data` using the provided transformer function.\n * The transformer receives each item and can mutate it in place or return a new object.\n * Commonly used with built-in transformers like `lowercase`, `trim`, or `setNow`.\n *\n * @example\n * ```ts\n * import { transformData, lowercase } from 'feathers-utils/transformers'\n *\n * app.service('users').hooks({\n *   before: { create: [transformData(item => lowercase(item, 'email'))] }\n * })\n * ```\n *\n * @see https://utils.feathersjs.com/hooks/transform-data.html\n */\nexport const transformData =\n  <H extends HookContext = HookContext, D = Data<H>>(\n    transformer: TransformerInputFn<D, H>,\n  ) =>\n  async (context: H, next?: NextFunction): Promise<void> => {\n    await mutateData(context, transformer)\n\n    if (next) {\n      await next()\n    }\n  }\n","import type { HookContext, NextFunction, Query } from '@feathersjs/feathers'\nimport type { TransformerFn } from '../../types.js'\n\n/**\n * Transforms `context.params.query` using the provided transformer function.\n * The transformer receives the current query and can return a modified version.\n * Useful for normalizing, sanitizing, or enriching queries before they hit the database.\n *\n * @example\n * ```ts\n * import { transformQuery } from 'feathers-utils/transformers'\n *\n * app.service('users').hooks({\n *   before: { find: [transformQuery((query) => ({ ...query, active: true }))] }\n * })\n * ```\n *\n * @see https://utils.feathersjs.com/hooks/transform-query.html\n */\nexport const transformQuery = <\n  Q extends Query,\n  H extends HookContext = HookContext,\n>(\n  transformer: TransformerFn<Q, H>,\n) => {\n  function hook(context: H): void\n  function hook(context: H, next: NextFunction): Promise<void>\n  function hook(context: H, next?: NextFunction): void | Promise<void> {\n    context.params.query = transformer(context.params.query ?? {}, {\n      context,\n      i: 0,\n    })\n\n    if (next) return next()\n\n    return\n  }\n  return hook\n}\n","import type { HookContext, NextFunction } from '@feathersjs/feathers'\nimport { mutateResult } from '../../utils/mutate-result/mutate-result.util.js'\nimport type { DispatchOption, TransformerInputFn } from '../../types.js'\nimport type { ResultSingleHookContext } from '../../utility-types/hook-context.js'\nimport type { AnyFallback } from '../../internal.utils.js'\n\ntype Result<H extends HookContext> = AnyFallback<\n  ResultSingleHookContext<H>,\n  Record<string, any>\n>\n\nexport type TransformResultOptions = {\n  dispatch?: DispatchOption\n}\n\n/**\n * Transforms each item in `context.result` using the provided transformer function.\n * The transformer receives each item and can mutate it in place or return a new object.\n * Optionally operates on `context.dispatch` via the `dispatch` option.\n *\n * @example\n * ```ts\n * import { transformResult, omit } from 'feathers-utils/transformers'\n *\n * app.service('users').hooks({\n *   after: { all: [transformResult(item => omit(item, 'password'))] }\n * })\n * ```\n *\n * @see https://utils.feathersjs.com/hooks/transform-result.html\n */\nexport const transformResult =\n  <H extends HookContext = HookContext, R = Result<H>>(\n    transformer: TransformerInputFn<R, H>,\n    options?: TransformResultOptions,\n  ) =>\n  async (context: H, next?: NextFunction): Promise<void> => {\n    await mutateResult(context, transformer, {\n      next,\n      dispatch: options?.dispatch,\n    })\n  }\n"],"mappings":";;;;;;;;;;;;;;;;;;AA2BA,MAAa,iBAET,gBAEF,OAAO,SAAY,SAAuC;CACxD,MAAM,WAAW,SAAS,WAAW;CAErC,IAAI,MACF,MAAM,KAAK;AAEf;;;;;;;;;;;;;;;;;;;AClBF,MAAa,kBAIX,gBACG;CAGH,SAAS,KAAK,SAAY,MAA2C;EACnE,QAAQ,OAAO,QAAQ,YAAY,QAAQ,OAAO,SAAS,CAAC,GAAG;GAC7D;GACA,GAAG;EACL,CAAC;EAED,IAAI,MAAM,OAAO,KAAK;CAGxB;CACA,OAAO;AACT;;;;;;;;;;;;;;;;;;;ACPA,MAAa,mBAET,aACA,YAEF,OAAO,SAAY,SAAuC;CACxD,MAAM,aAAa,SAAS,aAAa;EACvC;EACA,UAAU,SAAS;CACrB,CAAC;AACH"}