netstorage
Version:
A TypeScript API and CLI for the Akamai NetStorage REST interface
41 lines (40 loc) • 1.58 kB
TypeScript
import { RateLimiter } from 'limiter';
import type { NetStorageOperation } from '../index';
/**
* Configuration for throttling NetStorage API operations.
*
* @property {number} [read] - Max read ops (e.g., stat, du, dir) per interval.
* @property {number} [write] - Max write ops (e.g., upload, delete, mkdir) per interval.
* @property {number} [dir] - Max directory listing ops (e.g., dir) per interval.
* @property {number} [time] - Interval window in milliseconds (default: 1000ms).
*/
export interface RateLimitConfig {
read?: number;
write?: number;
dir?: number;
time?: number;
}
/**
* Creates rate limiters for read, write, and directory operations.
*
* @param {RateLimitConfig} [config] - Optional rate limit configuration.
* @returns {{
* readLimiter: RateLimiter,
* writeLimiter: RateLimiter,
* dirLimiter: RateLimiter
* }} Limiters for respective operation types.
*/
export declare function createRateLimiters(config?: RateLimitConfig): {
readLimiter: RateLimiter;
writeLimiter: RateLimiter;
dirLimiter: RateLimiter;
};
/**
* Resolves the appropriate limiter for a given NetStorage method.
*
* @param {NetStorageOperation} method - API operation name (e.g., 'stat', 'upload').
* @param {ReturnType<typeof createRateLimiters>} limiters - Available rate limiters.
* @returns {RateLimiter} Matching limiter instance.
* @throws {Error} If no limiter is mapped to the given method.
*/
export declare function selectLimiter(method: NetStorageOperation, limiters: ReturnType<typeof createRateLimiters>): RateLimiter;