UNPKG

1.06 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.ApiSecurity = void 0;
4const lodash_1 = require("lodash");
5const constants_1 = require("../constants");
6const extend_metadata_util_1 = require("../utils/extend-metadata.util");
7function ApiSecurity(name, requirements = []) {
8 let metadata;
9 if (lodash_1.isString(name)) {
10 metadata = [{ [name]: requirements }];
11 }
12 else {
13 metadata = [name];
14 }
15 return (target, key, descriptor) => {
16 if (descriptor) {
17 metadata = extend_metadata_util_1.extendMetadata(metadata, constants_1.DECORATORS.API_SECURITY, descriptor.value);
18 Reflect.defineMetadata(constants_1.DECORATORS.API_SECURITY, metadata, descriptor.value);
19 return descriptor;
20 }
21 metadata = extend_metadata_util_1.extendMetadata(metadata, constants_1.DECORATORS.API_SECURITY, target);
22 Reflect.defineMetadata(constants_1.DECORATORS.API_SECURITY, metadata, target);
23 return target;
24 };
25}
26exports.ApiSecurity = ApiSecurity;