Skip to content

resolveData

resolvers
Source Code | Documentation

Resolves and transforms context.data using a map of resolver functions. Each property in the resolver object receives the current value and can return a transformed value. Runs before next() in the hook pipeline.

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

Example

ts
import { resolveData, lowercase } from 'feathers-utils/resolvers'

app.service('users').hooks({
  before: {
    create: [resolveData({ email: lowercase() })]
  }
})

Type declaration

Show Type Declarations
ts
type Data<H extends HookContext> = AnyFallback<
  DataSingleHookContext<H>,
  Record<string, any>
>
/**
 * Resolves and transforms `context.data` using a map of resolver functions.
 * Each property in the resolver object receives the current value and can return
 * a transformed value. Runs before `next()` in the hook pipeline.
 *
 * @example
 * ```ts
 *
 *
 * app.service('users').hooks({
 *   before: {
 *     create: [resolveData({ email: lowercase() })]
 *   }
 * })
 * ```
 */
export declare const resolveData: <
  H extends HookContext = HookContext,
  D = Data<H>,
>(
  resolvers: ResolverObject<D, H>,
) => {
  (context: H, next: NextFunction): Promise<void>
  (context: H): Promisable<H>
}
ArgumentTypeDescription
resolversResolverObject<D, H>
typemethodsmulti
before, aroundcreate, update, patchyes

Resolver Helpers

ResolverDescription
defaults

Returns a resolver property that sets a default value when the current value is undefined or null. Accepts a static value or a function that receives the hook context.

fromPredicate

Adapts an existing predicate function (like isProvider, isContext) into a resolver condition. The predicate receives the hook context extracted from the resolver options. Only synchronous predicates are supported.

lowercase

Returns a resolver property that converts string values to lowercase. Non-string values are passed through unchanged.

omit

Returns a resolver property that removes the field by returning undefined. When a condition is provided, the field is only omitted if the condition returns true.

setNow

Returns a resolver property that sets the field to the current timestamp (Date.now()). Always overwrites the existing value.

trim

Returns a resolver property that trims whitespace from string values. Non-string values are passed through unchanged.

Conditions

ConditionDescription

Released under the MIT License.