@nestjs/core
Version:
Nest - modern, fast, powerful node.js web framework (@core)
36 lines (35 loc) • 1.1 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
/**
* Helper class providing Nest reflection capabilities.
*
* @see [Reflection](https://docs.nestjs.com/guards#putting-it-all-together)
*
* @publicApi
*/
class Reflector {
/**
* Retrieve metadata for a specified key for a specified target.
*
* @example
* `const roles = this.reflector.get<string[]>('roles', context.getHandler());`
*
* @param metadataKey lookup key for metadata to retrieve
* @param target context (decorated object) to retrieve metadata from
*
*/
get(metadataKey, target) {
return Reflect.getMetadata(metadataKey, target);
}
/**
* Retrieve metadata for a specified key for a specified set of targets.
*
* @param metadataKey lookup key for metadata to retrieve
* @param targets context (decorated objects) to retrieve metadata from
*
*/
getAll(metadataKey, targets) {
return (targets || []).map(target => Reflect.getMetadata(metadataKey, target));
}
}
exports.Reflector = Reflector;