UNPKG

@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.

65 lines (64 loc) 2.09 kB
/** * @module RateLimiter */ import { type IEventDispatcher } from "../../../../event-bus/contracts/_module.js"; import { type IExecutionContext } from "../../../../execution-context/contracts/_module.js"; import { type IKey, type INamespace } from "../../../../namespace/contracts/_module.js"; import { type IRateLimiter, type IRateLimiterAdapter, type RateLimiterEventMap, type RateLimiterState } from "../../../../rate-limiter/contracts/_module.js"; import { type AsyncLazy, type ErrorPolicy, type WaitUntil } from "../../../../utilities/_module.js"; /** * @internal */ export type RateLimiterSettings = { limit: number; enableAsyncTracking: boolean; eventDispatcher: IEventDispatcher<RateLimiterEventMap>; adapter: IRateLimiterAdapter; key: IKey; errorPolicy: ErrorPolicy; onlyError: boolean; namespace: INamespace; serdeTransformerName: string; waitUntil: WaitUntil; executionContext: IExecutionContext; }; /** * @internal */ export type ISerializedRateLimiter = { version: "1"; key: string; limit: number; }; /** * @internal */ export declare class RateLimiter implements IRateLimiter { /** * @internal */ static _serialize(deserializedValue: RateLimiter): ISerializedRateLimiter; private readonly waitUntil; private readonly _key; private readonly _limit; private readonly errorPolicy; private readonly onlyError; private readonly adapter; private readonly eventDispatcher; private readonly enableAsyncTracking; private readonly serdeTransformerName; private readonly namespace; private readonly executionContext; constructor(settings: RateLimiterSettings); _getNamespace(): INamespace; _getSerdeTransformerName(): string; _getAdapter(): IRateLimiterAdapter; private toRateLimiterState; getState(): Promise<RateLimiterState>; get key(): IKey; get limit(): number; private trackErrorWrapper; private trackWrapper; runOrFail<TValue = void>(asyncFn: AsyncLazy<TValue>): Promise<TValue>; reset(): Promise<void>; }