/** * @module Lock */ import { type Kysely } from "kysely"; import { type IReadableContext } from "../../../../execution-context/contracts/_module.js"; import { type ILockAdapter, type ILockAdapterState } from "../../../../lock/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/lock/kysely-lock-adapter"` * @group Adapters */ export type KyselyLockTable = { key: string; owner: string; expiration: number | bigint | string | null; }; /** * IMPORT_PATH: `"@daiso-tech/core/lock/kysely-lock-adapter"` * @group Adapters */ export type KyselyLockTables = { lock: KyselyLockTable; }; /** * Configuration for `KyselyLockAdapter`. * Requires a Kysely database instance with the lock schema applied. * * IMPORT_PATH: `"@daiso-tech/core/lock/kysely-lock-adapter"` * @group Adapters */ export type KyselyLockAdapterSettings = { /** * The Kysely database instance typed with the required lock table. */ kysely: Kysely; }; /** * To utilize the `KyselyLockAdapter`, you must install the [`"kysely"`](https://www.npmjs.com/package/kysely) package and configure a `Kysely` class instance. * * Note in order to use `KyselyLockAdapter` correctly, ensure you use a single, consistent database across all server instances and use a database that has support for transactions. * The adapter have been tested with `sqlite`, `postgres` and `mysql` databases. * * IMPORT_PATH: `"@daiso-tech/core/lock/kysely-lock-adapter"` * @group Adapters */ export declare class KyselyLockAdapter implements ILockAdapter, IDeinitizable, IInitizable, IPrunable { private readonly kysely; private readonly isMysql; /** * @example * ```ts * import { KyselyLockAdapter } from "@daiso-tech/core/lock/kysely-lock-adapter"; * import Sqlite from "better-sqlite3"; * import { Kysely, SqliteDialect } from "kysely"; * * const lockAdapter = new KyselyLockAdapter({ * kysely: new Kysely({ * dialect: new SqliteDialect({ * database: new Sqlite("local.db"), * }), * }), * }); * // You need initialize the adapter once before using it. * await lockAdapter.init(); * ``` */ constructor(settings: KyselyLockAdapterSettings); private _transaction; /** * Removes all related lock tables and their rows. * Note all lock data will be removed. */ deInit(): Promise; /** * Creates all related tables and indexes. * Note the `init` method needs to be called once before using the adapter. */ init(): Promise; removeAllExpired(): Promise; private _find; acquire(key: string, lockId: string, ttl: TimeSpan | null, _context: IReadableContext): Promise; release(key: string, lockId: string, _context: IReadableContext): Promise; forceRelease(key: string, _context: IReadableContext): Promise; refresh(key: string, lockId: string, ttl: TimeSpan, _context: IReadableContext): Promise; getState(key: string, _context: IReadableContext): Promise; }