UNPKG

appwrite-utils-cli

Version:

Appwrite Utility Functions to help with database management, data conversion, data import, migrations, and much more. Meant to be used as a CLI tool, I do not recommend installing this in frontend environments.

139 lines (138 loc) 4.76 kB
export interface RateLimitConfig { dataInsertion?: number; dataUpdate?: number; dataQuery?: number; fileUpload?: number; fileDownload?: number; validation?: number; relationshipResolution?: number; userCreation?: number; userUpdate?: number; apiCalls?: number; } /** * Manages rate limiting across the import system. * Provides configurable p-limit instances for different operation types. * Builds on existing p-limit usage in attributeManager and other components. */ export declare class RateLimitManager { private limits; private config; private static readonly DEFAULT_LIMITS; constructor(config?: Partial<RateLimitConfig>); /** * Initializes p-limit instances for all operation types. */ private initializeLimits; /** * Gets the rate limiter for data insertion operations. */ get dataInsertion(): any; /** * Gets the rate limiter for data update operations. */ get dataUpdate(): any; /** * Gets the rate limiter for data query operations. */ get dataQuery(): any; /** * Gets the rate limiter for file upload operations. */ get fileUpload(): any; /** * Gets the rate limiter for file download operations. */ get fileDownload(): any; /** * Gets the rate limiter for validation operations. */ get validation(): any; /** * Gets the rate limiter for relationship resolution operations. */ get relationshipResolution(): any; /** * Gets the rate limiter for user creation operations. */ get userCreation(): any; /** * Gets the rate limiter for user update operations. */ get userUpdate(): any; /** * Gets the rate limiter for general API calls. */ get apiCalls(): any; /** * Gets a rate limiter by operation type name. * * @param operationType - The type of operation * @returns The p-limit instance for the operation type */ getLimiter(operationType: keyof RateLimitConfig): any; /** * Updates the rate limit for a specific operation type. * * @param operationType - The operation type to update * @param newLimit - The new concurrent operation limit */ updateLimit(operationType: keyof RateLimitConfig, newLimit: number): void; /** * Updates multiple rate limits at once. * * @param newConfig - Partial configuration with new limits */ updateLimits(newConfig: Partial<RateLimitConfig>): void; /** * Gets the current configuration. */ getConfig(): Required<RateLimitConfig>; /** * Gets statistics about pending and active operations. * Useful for monitoring and debugging rate limiting. */ getStatistics(): { [operationType: string]: { pending: number; active: number; }; }; /** * Waits for all pending operations to complete. * Useful for graceful shutdown or testing. * * @param timeout - Maximum time to wait in milliseconds (default: 30 seconds) */ waitForCompletion(timeout?: number): Promise<void>; /** * Creates a rate limiter with automatic retry logic. * Combines p-limit with retry functionality for robust operation handling. * * @param operationType - The operation type to get the limiter for * @param maxRetries - Maximum number of retries (default: 3) * @param retryDelay - Delay between retries in milliseconds (default: 1000) */ createRetryLimiter(operationType: keyof RateLimitConfig, maxRetries?: number, retryDelay?: number): <T>(operation: () => Promise<T>) => Promise<T>; /** * Adjusts rate limits based on API response times and error rates. * Implements adaptive rate limiting for optimal performance. * * @param operationType - The operation type to adjust * @param responseTime - Average response time in milliseconds * @param errorRate - Error rate as a percentage (0-100) */ adaptiveAdjust(operationType: keyof RateLimitConfig, responseTime: number, errorRate: number): void; /** * Resets all rate limits to default values. */ resetToDefaults(): void; /** * Creates a specialized batch processor with rate limiting. * Useful for processing large datasets with controlled concurrency. * * @param operationType - The operation type for rate limiting * @param batchSize - Number of items to process in each batch */ createBatchProcessor<T, R>(operationType: keyof RateLimitConfig, batchSize?: number): (items: T[], processor: (item: T) => Promise<R>, onProgress?: (processed: number, total: number) => void) => Promise<R[]>; }