MCPcopy
hub / github.com/nestjs/nest / createDecorator

Method createDecorator

packages/core/services/reflector.service.ts:57–72  ·  view source on GitHub ↗
(
    options: CreateDecoratorOptions<TParam, TTransformed> = {},
  )

Source from the content-addressed store, hash-verified

55 options: CreateDecoratorWithTransformOptions<TParam, TTransformed>,
56 ): ReflectableDecorator<TParam, TTransformed>;
57 static createDecorator<TParam, TTransformed = TParam>(
58 options: CreateDecoratorOptions<TParam, TTransformed> = {},
59 ): ReflectableDecorator<TParam, TTransformed> {
60 const metadataKey = options.key ?? uid(21);
61 const decoratorFn =
62 (metadataValue: TParam) =>
63 (target: object | Function, key?: string | symbol, descriptor?: any) => {
64 const value = options.transform
65 ? options.transform(metadataValue)
66 : metadataValue;
67 SetMetadata(metadataKey, value ?? {})(target, key!, descriptor);
68 };
69
70 decoratorFn.KEY = metadataKey;
71 return decoratorFn as ReflectableDecorator<TParam, TTransformed>;
72 }
73
74 /**
75 * Retrieve metadata for a reflectable decorator for a specified target.

Calls

no outgoing calls

Tested by

no test coverage detected