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.

61 lines (60 loc) 2.28 kB
/** * @module Lock */ import type { IDatabaseLockAdapter, ILockData } from "../../../../lock/contracts/_module-exports.js"; import { type IDeinitizable, type IInitizable, TimeSpan } from "../../../../utilities/_module-exports.js"; import type { Client } from "@libsql/client"; /** * * IMPORT_PATH: `"@daiso-tech/core/lock/adapters"` * @group Adapters */ export type LibsqlLockAdapterSettings = { database: Client; tableName?: string; expiredKeysRemovalInterval?: TimeSpan; shouldRemoveExpiredKeys?: boolean; }; /** * To utilize the `LibsqlLockAdapter`, you must install the `"@libsql/client"` package. * * Note in order to use `LibsqlLockAdapter` correctly, ensure you use a single, consistent database across all server instances. * This means you can't use libsql embedded replicas. * * IMPORT_PATH: `"@daiso-tech/core/lock/adapters"` * @group Adapters */ export declare class LibsqlLockAdapter implements IDatabaseLockAdapter, IDeinitizable, IInitizable { private databaseLockAdapter; /*** * @example * ```ts * import { LibsqlLockAdapter } from "@daiso-tech/core/lock/adapters"; * import { createClient } from "@libsql/client"; * * const database = createClient({ url: "file:local.db" }); * const lockAdapter = new LibsqlLockAdapter({ * database, * }); * // You need initialize the adapter once before using it. * await lockAdapter.init(); * ``` */ constructor(settings: LibsqlLockAdapterSettings); removeExpiredKeys(): Promise<void>; /** * Removes the table where the lock keys are stored and removes the table indexes. * Note all lock data will be removed. */ deInit(): Promise<void>; /** * Creates the table where the lock keys are stored and it's related indexes. * Note the `init` method needs to be called before using the adapter. */ init(): 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>; }