import { Inject } from '@nestjs/common' ; import { THROTTLER_LIMIT , THROTTLER_SKIP , THROTTLER_TTL } from './throttler.constants' ; import { getOptionsToken , getStorageToken } from './throttler.providers' ; function setThrottlerMetadata ( target , limit , ttl ) { Reflect . defineMetadata ( THROTTLER_TTL , ttl , target ) ; Reflect . defineMetadata ( THROTTLER_LIMIT , limit , target ) ; } usage Throttle publicApi export const Throttle = ( limit = 20 , ttl = 60 ) : MethodDecorator & ClassDecorator => { return ( target , propertyKey ? , descriptor ? ) => { if ( descriptor ) { setThrottlerMetadata ( descriptor . value , limit , ttl ) ; return descriptor ; } setThrottlerMetadata ( target , limit , ttl ) ; return target ; } ; } ; usage SkipThrottle usage SkipThrottle publicApi export const SkipThrottle = ( skip = true ) : MethodDecorator & ClassDecorator => { return ( target , propertyKey ? , descriptor ? ) => { if ( descriptor ) { Reflect . defineMetadata ( THROTTLER_SKIP , skip , descriptor . value ) ; return descriptor ; } Reflect . defineMetadata ( THROTTLER_SKIP , skip , target ) ; return target ; } ; } ; usage InjectThrottlerOptions publicApi export const InjectThrottlerOptions = ( ) => Inject ( getOptionsToken ( ) ) ; usage InjectThrottlerStorage publicApi export const InjectThrottlerStorage = ( ) => Inject ( getStorageToken ( ) ) ;