/** * @module Cache */ import { type Kysely } from "kysely"; import { type ICacheAdapter } from "../../../../cache/contracts/_module.js"; import { type IReadableContext } from "../../../../execution-context/contracts/_module.js"; import { type ISerde } from "../../../../serde/contracts/_module.js"; import { type TimeSpan } from "../../../../time-span/implementations/_module.js"; import { type IDeinitizable, type IInitizable, type IPrunable } from "../../../../utilities/_module.js"; /** * IMPORT_PATH: `"@daiso-tech/core/cache/kysely-cache-adapter"` * @group Adapters */ export type KyselyCacheTable = { key: string; value: string; expiration: number | string | null; }; /** * IMPORT_PATH: `"@daiso-tech/core/cache/kysely-cache-adapter"` * @group Adapters */ export type KyselyCacheTables = { cache: KyselyCacheTable; }; /** * Configuration for `KyselyCacheAdapter`. * Requires a Kysely database instance and a serde for serialising cache values to strings. * * IMPORT_PATH: `"@daiso-tech/core/cache/kysely-cache-adapter"` * @group Adapters */ export type KyselyCacheAdapterSettings = { /** * The Kysely database instance with the required cache schema tables applied. */ kysely: Kysely; /** * Serde instance for serializing and deserializing cache values to and from strings. */ serde: ISerde; }; /** * To utilize the `KyselyCacheAdapter`, you must install the [`"kysely"`](https://www.npmjs.com/package/kysely) package and configure a `Kysely` class instance. * The adapter have been tested with `sqlite`, `postgres` and `mysql` databases. * * IMPORT_PATH: `"@daiso-tech/core/cache/kysely-cache-adapter"` * @group Adapters */ export declare class KyselyCacheAdapter implements ICacheAdapter, IInitizable, IDeinitizable, IPrunable { private readonly isMysql; private readonly serde; private readonly kysely; /** * @example * ```ts * import { KyselyCacheAdapter } from "@daiso-tech/core/cache/kysely-cache-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 cacheAdapter = new KyselyCacheAdapter({ * kysely: new Kysely({ * dialect: new SqliteDialect({ * database: new Sqlite("local.db"), * }), * }), * serde, * }); * // You need initialize the adapter once before using it. * await cacheAdapter.init(); * ``` */ constructor(settings: KyselyCacheAdapterSettings); removeAllExpired(): Promise; init(): Promise; /** * Removes all related cache tables and their rows. * Note all cache data will be removed. */ deInit(): Promise; private _transaction; get(key: string, _context: IReadableContext): Promise; getAndRemove(key: string, _context: IReadableContext): Promise; add(key: string, value: TType, ttl: TimeSpan | null, _context: IReadableContext): Promise; getOrAdd(key: string, valueToAdd: TType, ttl: TimeSpan | null, _context: IReadableContext): Promise; put(key: string, value: TType, ttl: TimeSpan | null, _context: IReadableContext): Promise; update(key: string, value: TType, _context: IReadableContext): Promise; increment(key: string, value: number, _context: IReadableContext): Promise; removeMany(keys: Array, _context: IReadableContext): Promise; removeAll(_context: IReadableContext): Promise; removeByKeyPrefix(prefix: string, _context: IReadableContext): Promise; }