{"version":3,"file":"resolvers.mjs","names":[],"sources":["../src/resolvers/helpers/omit/omit.ts","../src/resolvers/helpers/trim/trim.ts","../src/resolvers/helpers/lowercase/lowercase.ts","../src/resolvers/helpers/defaults/defaults.ts","../src/resolvers/helpers/set-now/set-now.ts","../src/resolvers/from-predicate/from-predicate.ts"],"sourcesContent":["import type { HookContext } from '@feathersjs/feathers'\nimport type { ResolverPropertyOptions } from '../../resolvers.internal.js'\nimport type { ResolverCondition } from '../../resolver-condition.js'\n\n/**\n * Returns a resolver property that removes the field by returning `undefined`.\n * When a condition is provided, the field is only omitted if the condition returns `true`.\n *\n * @example\n * ```ts\n * import { resolveResult, omit, fromPredicate } from 'feathers-utils/resolvers'\n * import { isProvider } from 'feathers-utils/predicates'\n *\n * resolveResult({\n *   password: omit(),\n *   secret: omit(fromPredicate(isProvider('external'))),\n * })\n * ```\n */\nexport function omit<H extends HookContext = HookContext>(\n  condition?: ResolverCondition<H>,\n) {\n  return (options: ResolverPropertyOptions<any, any, H>) => {\n    if (condition && !condition(options)) {\n      return options.value\n    }\n    return undefined\n  }\n}\n","import type { HookContext } from '@feathersjs/feathers'\nimport type { ResolverPropertyOptions } from '../../resolvers.internal.js'\nimport type { ResolverCondition } from '../../resolver-condition.js'\n\n/**\n * Returns a resolver property that trims whitespace from string values.\n * Non-string values are passed through unchanged.\n *\n * @example\n * ```ts\n * import { resolveData, trim } from 'feathers-utils/resolvers'\n *\n * resolveData({\n *   name: trim(),\n * })\n * ```\n */\nexport function trim<H extends HookContext = HookContext>(\n  condition?: ResolverCondition<H>,\n) {\n  return (options: ResolverPropertyOptions<any, any, H>) => {\n    if (condition && !condition(options)) {\n      return options.value\n    }\n    return typeof options.value === 'string'\n      ? options.value.trim()\n      : options.value\n  }\n}\n","import type { HookContext } from '@feathersjs/feathers'\nimport type { ResolverPropertyOptions } from '../../resolvers.internal.js'\nimport type { ResolverCondition } from '../../resolver-condition.js'\n\n/**\n * Returns a resolver property that converts string values to lowercase.\n * Non-string values are passed through unchanged.\n *\n * @example\n * ```ts\n * import { resolveData, lowercase } from 'feathers-utils/resolvers'\n *\n * resolveData({\n *   email: lowercase(),\n * })\n * ```\n */\nexport function lowercase<H extends HookContext = HookContext>(\n  condition?: ResolverCondition<H>,\n) {\n  return (options: ResolverPropertyOptions<any, any, H>) => {\n    if (condition && !condition(options)) {\n      return options.value\n    }\n    return typeof options.value === 'string'\n      ? options.value.toLowerCase()\n      : options.value\n  }\n}\n","import type { HookContext } from '@feathersjs/feathers'\nimport type { ResolverPropertyOptions } from '../../resolvers.internal.js'\nimport type { ResolverCondition } from '../../resolver-condition.js'\n\n/**\n * Returns a resolver property that sets a default value when the current value\n * is `undefined` or `null`. Accepts a static value or a function that receives\n * the hook context.\n *\n * @example\n * ```ts\n * import { resolveData, defaults } from 'feathers-utils/resolvers'\n *\n * resolveData({\n *   role: defaults('user'),\n *   createdBy: defaults((context) => context.params.user?.id),\n * })\n * ```\n */\nexport function defaults<H extends HookContext = HookContext>(\n  defaultValue: unknown | ((context: H) => unknown),\n  condition?: ResolverCondition<H>,\n) {\n  return (options: ResolverPropertyOptions<any, any, H>) => {\n    if (condition && !condition(options)) {\n      return options.value\n    }\n    if (options.value !== undefined && options.value !== null) {\n      return options.value\n    }\n    return typeof defaultValue === 'function'\n      ? (defaultValue as (context: H) => unknown)(options.context)\n      : defaultValue\n  }\n}\n","import type { HookContext } from '@feathersjs/feathers'\nimport type { ResolverPropertyOptions } from '../../resolvers.internal.js'\nimport type { ResolverCondition } from '../../resolver-condition.js'\n\n/**\n * Returns a resolver property that sets the field to the current timestamp\n * (`Date.now()`). Always overwrites the existing value.\n *\n * @example\n * ```ts\n * import { resolveData, setNow } from 'feathers-utils/resolvers'\n *\n * resolveData({\n *   createdAt: setNow(),\n * })\n * ```\n */\nexport function setNow<H extends HookContext = HookContext>(\n  condition?: ResolverCondition<H>,\n) {\n  return (options: ResolverPropertyOptions<any, any, H>) => {\n    if (condition && !condition(options)) {\n      return options.value\n    }\n    return Date.now()\n  }\n}\n","import type { HookContext } from '@feathersjs/feathers'\nimport type { PredicateFn } from '../../types.js'\nimport type { ResolverCondition } from '../resolver-condition.js'\n\n/**\n * Adapts an existing predicate function (like `isProvider`, `isContext`) into a\n * resolver condition. The predicate receives the hook context extracted from the\n * resolver options. Only synchronous predicates are supported.\n *\n * @example\n * ```ts\n * import { resolveResult, omit, fromPredicate } from 'feathers-utils/resolvers'\n * import { isProvider } from 'feathers-utils/predicates'\n *\n * resolveResult({\n *   password: omit(fromPredicate(isProvider('external'))),\n * })\n * ```\n */\nexport function fromPredicate<H extends HookContext = HookContext>(\n  predicate: PredicateFn<H>,\n): ResolverCondition<H> {\n  return ({ context }) => {\n    const result = predicate(context)\n    if (typeof result !== 'boolean') {\n      throw new Error('fromPredicate does not support async predicates')\n    }\n    return result\n  }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAmBA,SAAgB,KACd,WACA;CACA,QAAQ,YAAkD;EACxD,IAAI,aAAa,CAAC,UAAU,OAAO,GACjC,OAAO,QAAQ;CAGnB;AACF;;;;;;;;;;;;;;;;ACXA,SAAgB,KACd,WACA;CACA,QAAQ,YAAkD;EACxD,IAAI,aAAa,CAAC,UAAU,OAAO,GACjC,OAAO,QAAQ;EAEjB,OAAO,OAAO,QAAQ,UAAU,WAC5B,QAAQ,MAAM,KAAK,IACnB,QAAQ;CACd;AACF;;;;;;;;;;;;;;;;ACXA,SAAgB,UACd,WACA;CACA,QAAQ,YAAkD;EACxD,IAAI,aAAa,CAAC,UAAU,OAAO,GACjC,OAAO,QAAQ;EAEjB,OAAO,OAAO,QAAQ,UAAU,WAC5B,QAAQ,MAAM,YAAY,IAC1B,QAAQ;CACd;AACF;;;;;;;;;;;;;;;;;;ACTA,SAAgB,SACd,cACA,WACA;CACA,QAAQ,YAAkD;EACxD,IAAI,aAAa,CAAC,UAAU,OAAO,GACjC,OAAO,QAAQ;EAEjB,IAAI,QAAQ,UAAU,KAAA,KAAa,QAAQ,UAAU,MACnD,OAAO,QAAQ;EAEjB,OAAO,OAAO,iBAAiB,aAC1B,aAAyC,QAAQ,OAAO,IACzD;CACN;AACF;;;;;;;;;;;;;;;;ACjBA,SAAgB,OACd,WACA;CACA,QAAQ,YAAkD;EACxD,IAAI,aAAa,CAAC,UAAU,OAAO,GACjC,OAAO,QAAQ;EAEjB,OAAO,KAAK,IAAI;CAClB;AACF;;;;;;;;;;;;;;;;;;ACPA,SAAgB,cACd,WACsB;CACtB,QAAQ,EAAE,cAAc;EACtB,MAAM,SAAS,UAAU,OAAO;EAChC,IAAI,OAAO,WAAW,WACpB,MAAM,IAAI,MAAM,iDAAiD;EAEnE,OAAO;CACT;AACF"}