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.

57 lines (56 loc) 1.88 kB
/** * @module Lock */ import { type ILockAdapter, type ILockAdapterState } from "../../../../lock/contracts/_module.js"; import { type TimeSpan } from "../../../../time-span/implementations/_module.js"; import { type IDeinitizable } from "../../../../utilities/_module.js"; /** * * IMPORT_PATH: `"@daiso-tech/core/lock/memory-lock-adapter"` * @group Adapters */ export type MemoryLockData = { owner: string; hasExpiration: true; timeoutId: string | number | NodeJS.Timeout; expiration: Date; } | { owner: string; hasExpiration: false; }; /** * Note the `MemoryLockAdapter` is limited to single process usage and cannot be shared across multiple servers or different processes. * This adapter is meant for testing. * * IMPORT_PATH: `"@daiso-tech/core/lock/memory-lock-adapter"` * @group Adapters */ export declare class MemoryLockAdapter implements ILockAdapter, IDeinitizable { private readonly map; /** * @example * ```ts * import { MemoryLockAdapter } from "@daiso-tech/core/lock/memory-lock-adapter"; * * const lockAdapter = new MemoryLockAdapter(); * ``` * You can also provide an `Map`. * @example * ```ts * import { MemoryLockAdapter } from "@daiso-tech/core/lock/memory-lock-adapter"; * * const map = new Map<any, any>(); * const lockAdapter = new MemoryLockAdapter(map); * ``` */ constructor(map?: Map<string, MemoryLockData>); /** * Removes all in-memory lock data. */ deInit(): Promise<void>; acquire(key: string, lockId: string, ttl: TimeSpan | null): Promise<boolean>; release(key: string, lockId: string): Promise<boolean>; forceRelease(key: string): Promise<boolean>; refresh(key: string, lockId: string, ttl: TimeSpan): Promise<boolean>; getState(key: string): Promise<ILockAdapterState | null>; }