UNPKG

@daiso-tech/core

Version:

The library offers flexible, framework-agnostic solutions for modern web applications, built on adaptable components that integrate seamlessly with popular frameworks like Next Js.

73 lines (72 loc) 2.21 kB
/** * @module Lock */ import type { IDatabaseLockAdapter, ILockData } from "../../../../lock/contracts/_module-exports.js"; import type { Kysely } from "kysely"; import { type IDeinitizable, type IInitizable, type IPrunable, TimeSpan } from "../../../../utilities/_module-exports.js"; /** * * IMPORT_PATH: `"@daiso-tech/core/lock/adapters"` * @group Adapters */ type KyselyLockAdapterTable = { key: string; owner: string; expiresAt: number | string | null; }; /** * * IMPORT_PATH: `"@daiso-tech/core/lock/adapters"` * @group Adapters */ type KyselyLockAdapterTables = { lock: KyselyLockAdapterTable; }; /** * * IMPORT_PATH: `"@daiso-tech/core/lock/adapters"` * @group Adapters */ type KyselyLockAdapterSettings = { kysely: Kysely<KyselyLockAdapterTables>; expiredKeysRemovalInterval?: TimeSpan; shouldRemoveExpiredKeys?: boolean; }; /** * * IMPORT_PATH: `"@daiso-tech/core/lock/adapters"` * @group Adapters */ export declare class KyselyLockAdapter implements IDatabaseLockAdapter, IDeinitizable, IInitizable, IPrunable { private readonly kysely; private readonly expiredKeysRemovalInterval; private readonly shouldRemoveExpiredKeys; private timeoutId; /** * @example * ```ts * import { KyselyLockAdapter } from "@daiso-tech/core/lock/adapters"; * import Sqlite from "better-sqlite3"; * * 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); deInit(): Promise<void>; init(): Promise<void>; removeAllExpired(): Promise<void>; insert(key: string, owner: string, expiration: Date | null): Promise<void>; update(key: string, owner: string, expiration: Date | null): Promise<number>; remove(key: string, owner: string | null): Promise<void>; refresh(key: string, owner: string, expiration: Date): Promise<number>; find(key: string): Promise<ILockData | null>; } export {};