import { KyselyRateLimiterStorageAdapter } from "@daiso-tech/core/rate-limiter/kysely-rate-limiter-storage-adapter";
import { DatabaseRateLimiterAdapter } from "@daiso-tech/core/rate-limiter/database-rate-limiter-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();
const rateLimiterAdapter = new DatabaseRateLimiterAdapter({
adapter: rateLimiterStorageAdapter
});
const rateLimiterProvider = new RateLimiterProvider({
adapter: rateLimiterAdapter
})
The addListener method is used for listening to a BaseEvent.
The same listener can only be added once for a specific event. Adding the same listener multiple times will have no effect and nothing will occur.
The listenOnce method is used for listening to a BaseEvent once.
The removeListener method is used for stop listening to a BaseEvent.
Removing unadded listener will have no effect and nothing will occur.
The subscribe method is used for listening to a BaseEvent and it returns a cleanup function that removes listener when called.
The same listener can only be added once for a specific event. Adding the same listener multiple times will have no effect and nothing will occur.
The subscribeOnce method is used for listening to a BaseEvent once and it returns a cleanup function that removes listener when called.
The same listener can only be added once for a specific event. Adding the same listener multiple times will have no effect and nothing will occur.
The
RateLimiterProviderclass can be derived from anyIRateLimiterAdapter.IMPORT_PATH:
"@daiso-tech/core/rate-limiter"