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 stored rate limiter data without a transaction. Useful for read-only operations or standalone state checks. Returns null if the rate limiter hasn't been initialized.
Unique identifier for the rate limiter
The stored rate limiter data if found, otherwise null
Removes a rate limiter entry from the database. Called when explicitly resetting a rate limiter or cleaning up expired entries. Safe to call even if the rate limiter doesn't exist.
Unique identifier for the rate limiter to remove
Executes rate limiter operations within a database transaction.
Provides an IRateLimiterStorageAdapterTransaction
object for atomic find/upsert operations.
All database operations within the transaction function should succeed or fail atomically. If the transaction function throws, the transaction should be rolled back.
Callback function receiving transaction object, should return a Promise
The value returned by the fn callback
IMPORT_PATH:
"@daiso-tech/core/rate-limiter/kysely-rate-limiter-storage-adapter"