@daiso-tech/core
Version:
The library offers flexible, framework-agnostic solutions for modern web applications, built on adaptable components that integrate seamlessly with popular frameworks like Next Js.
42 lines (41 loc) • 1.4 kB
TypeScript
/**
* @module RateLimiter
*/
import { type IEventDispatcher } from "../../../../event-bus/contracts/_module.js";
import { type Key } from "../../../../namespace/_module.js";
import { type IRateLimiter, type IRateLimiterAdapter, type RateLimiterEventMap, type RateLimiterState } from "../../../../rate-limiter/contracts/_module.js";
import { type ITask } from "../../../../task/contracts/_module.js";
import { type AsyncLazy, type ErrorPolicy } from "../../../../utilities/_module.js";
/**
* @internal
*/
export type RateLimiterSettings = {
limit: number;
enableAsyncTracking: boolean;
eventDispatcher: IEventDispatcher<RateLimiterEventMap>;
adapter: IRateLimiterAdapter;
key: Key;
errorPolicy: ErrorPolicy;
onlyError: boolean;
};
/**
* @internal
*/
export declare class RateLimiter implements IRateLimiter {
private readonly _key;
private readonly _limit;
private readonly errorPolicy;
private readonly onlyError;
private readonly adapter;
private readonly eventDispatcher;
private readonly enableAsyncTracking;
constructor(settings: RateLimiterSettings);
private toRateLimiterState;
getState(): ITask<RateLimiterState>;
get key(): string;
get limit(): number;
private trackErrorWrapper;
private trackWrapper;
runOrFail<TValue = void>(asyncFn: AsyncLazy<TValue>): ITask<TValue>;
reset(): ITask<void>;
}