To utilize the MongodbSharedLockAdapter, you must install the "mongodb" package.

Note in order to use MongodbSharedLockAdapter correctly, ensure you use a single, consistent database across all server instances.

IMPORT_PATH: "@daiso-tech/core/shared-lock/mongodb-shared-lock-adapter"

Implements

Constructors

Methods

  • Attempts to acquire a writer lock for the specified key. Succeeds only if no non-expired writer lock exists and no non-expired reader slots are held.

    Parameters

    • _context: IReadableContext
    • key: string

      Unique identifier for the shared lock

    • lockId: string

      Unique identifier for this acquirer (becomes the owner)

    • ttl: null | TimeSpan

      Time-to-live duration or null for indefinite locks

    Returns Promise<boolean>

    Promise resolving to true if the writer lock was successfully acquired, false if already held by another owner

  • Forcibly releases all reader slots for the specified shared lock 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 reader slots existed and were released, false if no reader slots are acquired

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

    Parameters

    • _context: IReadableContext
    • key: string

      Unique identifier for the shared lock

    • slotId: string

      Unique identifier of the reader slot to refresh

    • ttl: TimeSpan

      New time-to-live duration to set

    Returns Promise<boolean>

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

  • Refreshes (extends) the time-to-live of an existing writer lock. Only succeeds if all conditions are met: ownership matches, lock hasn't expired, and it's expirable.

    Parameters

    • _context: IReadableContext
    • key: string

      Unique identifier for the shared lock

    • lockId: string

      Unique identifier of the lock owner

    • ttl: TimeSpan

      New time-to-live duration to set

    Returns Promise<boolean>

    Promise resolving to true if refresh succeeded, false if the lock is unexpirable, expired, or not owned by lockId

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

    Parameters

    • _context: IReadableContext
    • key: string

      Unique identifier for the shared lock

    • slotId: string

      Unique identifier of the reader slot to release

    Returns Promise<boolean>

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

  • Releases a writer lock if owned by the specified lockId. Ownership verification prevents accidental release of locks held by others.

    Parameters

    • _context: IReadableContext
    • key: string

      Unique identifier for the shared lock

    • lockId: string

      Unique identifier of the lock owner

    Returns Promise<boolean>

    Promise resolving to true if the writer lock was successfully released, false if not owned by lockId or doesn't exist