import { MongodbRateLimiterStorageAdapter } from "@daiso-tech/core/rate-limiter/mongodb-rate-limiter-storage-adapter";
import { MongoClient } from "mongodb";
import { Serde } from "@daiso-tech/core/serde";
import { SuperJsonSerdeAdapter } from "@daiso-tech/core/serde/super-json-serde-adapter"
const client = await MongoClient.connect("YOUR_MONGODB_CONNECTION_STRING");
const database = client.db("database");
const serde = new Serde(new SuperJsonSerdeAdapter());
const rateLimiterStorageAdapter = new MongodbRateLimiterStorageAdapter({
client,
database,
serde
});
// You need initialize the adapter once before using it.
await rateLimiterStorageAdapter.init()
Retrieves the current rate limiter state for a given key.
The unique identifier for the rate limiter.
Returns the rate limiter state if found, otherwise null.
The transaction method runs the fn function inside a transaction.
The fn function is given a IRateLimiterStorageAdapterTransaction object.
IMPORT_PATH:
"@daiso-tech/core/rate-limiter/mongodb-rate-limiter-storage-adapter"