UNPKG

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