To utilize the KyselySemaphoreAdapter, you must install the "kysely" package and configure a Kysely class instance.

Note in order to use KyselySemaphoreAdapter 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/semaphore/kysely-semaphore-adapter"

Implements

Constructors

Methods

  • Forcibly releases all slots for the specified semaphore regardless of ownership. Used for emergency cleanup or administrative operations. Bypasses ownership verification for situations where individual slot holders are unavailable.

    Parameters

    Returns Promise<boolean>

    Promise resolving to true if the semaphore existed and slots were released, false if the semaphore doesn't exist or has no acquired slots

  • Refreshes (extends) the time-to-live of an existing slot. Only succeeds if all conditions are met: the slot exists, hasn't expired, and is expirable.

    Parameters

    • key: string

      Unique identifier for the semaphore

    • slotId: string

      Unique identifier of the slot to refresh

    • ttl: TimeSpan

      New time-to-live duration to set

    • _context: IReadableContext

    Returns Promise<boolean>

    Promise resolving to true if refresh succeeded, false if the slot is unexpirable, expired, or doesn't exist

  • Releases a specific slot if it is currently acquired. Only the holder of the slot (identified by slotId) can release it.

    Parameters

    • key: string

      Unique identifier for the semaphore

    • slotId: string

      Unique identifier of the slot to release

    • _context: IReadableContext

    Returns Promise<boolean>

    Promise resolving to true if the slot was successfully released, false if the slot doesn't exist or is already released