import { KyselyRateLimiterStorageAdapter } from "@daiso-tech/core/rate-limiter/kysely-rate-limiter-storage-adapter";
import { Serde } from "@daiso-tech/core/serde";
import { SuperJsonSerdeAdapter } from "@daiso-tech/core/serde/super-json-serde-adapter"
import Sqlite from "better-sqlite3";
import { Kysely, SqliteDialect } from "kysely";
const serde = new Serde(new SuperJsonSerdeAdapter());
const rateLimiterStorageAdapter = new KyselyRateLimiterStorageAdapter({
kysely: new Kysely({
dialect: new SqliteDialect({
database: new Sqlite("local.db"),
}),
}),
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/kysely-rate-limiter-storage-adapter"