UNPKG

981 BJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3/**
4 * Decorator that assigns metadata to the class/function using the
5 * specified `key`.
6 *
7 * Requires two parameters:
8 * - `key` - a value defining the key under which the metadata is stored
9 * - `value[]` - array of metadata values to be associated with `key`
10 *
11 * This metadata can be reflected using the `Reflector` class.
12 *
13 * Example: `@SetMetadata('roles', ['admin'])`
14 *
15 * @see [Reflection](https://docs.nestjs.com/guards#reflection)
16 *
17 * @publicApi
18 */
19exports.SetMetadata = (metadataKey, metadataValue) => {
20 const decoratorFactory = (target, key, descriptor) => {
21 if (descriptor) {
22 Reflect.defineMetadata(metadataKey, metadataValue, descriptor.value);
23 return descriptor;
24 }
25 Reflect.defineMetadata(metadataKey, metadataValue, target);
26 return target;
27 };
28 decoratorFactory.KEY = metadataKey;
29 return decoratorFactory;
30};