@toss/nestjs-aop
Version:
<!-- PROJECT LOGO --> <br /> <div align="center"> <a href="https://github.com/toss/nestjs-aop"> <img src="https://toss.tech/wp-content/uploads/2022/11/tech-article-nest-js-02.png" alt="Logo" height="200"> </a>
21 lines (20 loc) • 674 B
text/typescript
export const AddMetadata = <K extends string | symbol = string, V = any>(
metadataKey: K,
metadataValue: V,
): MethodDecorator => {
const decoratorFactory = (
_: any,
__: string | symbol,
descriptor: PropertyDescriptor,
): TypedPropertyDescriptor<any> => {
const target = descriptor.value || descriptor.get || descriptor.set;
if (!Reflect.hasMetadata(metadataKey, target)) {
Reflect.defineMetadata(metadataKey, [], target);
}
const metadataValues: V[] = Reflect.getMetadata(metadataKey, target);
metadataValues.push(metadataValue);
return descriptor;
};
decoratorFactory.KEY = metadataKey;
return decoratorFactory;
};