Type Alias IRateLimiterStorageAdapter<TType>

IRateLimiterStorageAdapter: {
    find(
        context: IReadableContext,
        key: string,
    ): Promise<null | IRateLimiterData<TType>>;
    remove(context: IReadableContext, key: string): Promise<void>;
    transaction<TValue>(
        context: IReadableContext,
        fn: InvokableFn<
            [transaction: IRateLimiterStorageAdapterTransaction<TType>],
            Promise<TValue>,
        >,
    ): Promise<TValue>;
}

Storage adapter contract for persisting rate limiter state in databases. Abstracts database operations for rate limiters with CRUD-based storage. Simplifies implementation for SQL databases and ORMs (TypeORM, MikroORM, etc.).

Adapters implementing this contract serialize the policy's TMetrics type for storage and deserialize it when loading, handling the conversion to/from TType.

IMPORT_PATH: "@daiso-tech/core/rate-limiter/contracts"

Type Parameters

  • TType = unknown

    The type of persisted metrics/state object in the database

Type declaration