UNPKG

nodejs-cloud-taskmq

Version:

Node.js TypeScript library for integrating Google Cloud Tasks with MongoDB/Redis/Memory/Custom for a BullMQ-like queue system. Compatible with NestJS but framework-agnostic.

79 lines (78 loc) 2.2 kB
import { IStateStorageAdapter } from '../interfaces/storage-adapter.interface'; import { RateLimiterOptions } from '../interfaces/config.interface'; /** * Rate limiting result */ export interface RateLimitResult { /** * Whether the request is allowed */ allowed: boolean; /** * Current request count */ count: number; /** * Maximum requests allowed */ limit: number; /** * Time until reset in milliseconds */ resetTime: number; /** * Remaining requests */ remaining: number; } /** * Rate limiter service */ export declare class RateLimiterService { private readonly storageAdapter; constructor(storageAdapter: IStateStorageAdapter); /** * Check and increment rate limit */ checkRateLimit(key: string, options: RateLimiterOptions): Promise<RateLimitResult>; /** * Get current rate limit status without incrementing */ getRateLimitStatus(key: string, options: RateLimiterOptions): Promise<RateLimitResult | null>; /** * Reset rate limit for a key */ resetRateLimit(key: string): Promise<void>; /** * Check if a request would be allowed without incrementing the counter */ wouldAllow(key: string, options: RateLimiterOptions): Promise<boolean>; /** * Get remaining requests for a key */ getRemaining(key: string, options: RateLimiterOptions): Promise<number>; /** * Get time until reset for a key */ getTimeUntilReset(key: string): Promise<number>; /** * Create a rate limit key based on various parameters */ static createKey(prefix: string, ...parts: string[]): string; /** * Create a rate limit key for IP address */ static createIpKey(ip: string, endpoint?: string): string; /** * Create a rate limit key for user */ static createUserKey(userId: string, endpoint?: string): string; /** * Create a rate limit key for queue */ static createQueueKey(queueName: string): string; /** * Create a rate limit key for processor */ static createProcessorKey(queueName: string, processorName: string): string; }