import type { DataSource } from 'typeorm'; /** * A PostgreSQL advisory-lock key, using either its single-key or two-key form. * A single key must be a int64. * A two key form must be int32, int32. */ export type SessionAdvisoryLockKey = number | { namespace: number; key: number; }; /** Whether a session-level advisory lock is exclusive or may be shared. */ export type SessionAdvisoryLockMode = 'excl' | 'shared'; export type SessionAdvisoryLockAcquisition = 'blocking' | 'try-lock'; /** The outcome of attempting to acquire a non-blocking session-level advisory lock. */ export type SessionAdvisoryLockResult = { acquired: false; } | { acquired: true; value: T; }; /** Options for a session-level advisory lock that waits until it is acquired. */ export type BlockingSessionAdvisoryLockOptions = { acquisition: 'blocking'; /** Defaults to exclusive */ mode?: SessionAdvisoryLockMode; }; /** Options for a session-level advisory lock that returns immediately when it is held. */ export type NonBlockingSessionAdvisoryLockOptions = { acquisition: 'non-blocking'; /** Defaults to exclusive */ mode?: SessionAdvisoryLockMode; }; /** * Runs a callback while holding a PostgreSQL session-level advisory lock identified by one key. * * @typeParam T - The value returned by the callback. * @param dataSource - The PostgreSQL TypeORM data source used to create the lock-owning session. * @param acquisition - Whether to wait for the lock or return immediately when it is held. * @param mode - Whether the lock is exclusive or shared. * @param key - The single PostgreSQL advisory-lock key. * @param callback - Work to execute after the lock is acquired. */ export declare function advisoryLock(dataSource: DataSource, acquisition: 'try-lock', mode: SessionAdvisoryLockMode, key: number, callback: () => Promise | T): Promise>; /** * Runs a callback while holding a PostgreSQL session-level advisory lock identified by two keys. * * @typeParam T - The value returned by the callback. * @param dataSource - The PostgreSQL TypeORM data source used to create the lock-owning session. * @param acquisition - Whether to wait for the lock or return immediately when it is held. * @param mode - Whether the lock is exclusive or shared. * @param namespace - The first key, used as the application's lock namespace. * @param key - The second PostgreSQL advisory-lock key within the namespace. * @param callback - Work to execute after the lock is acquired. */ export declare function advisoryLock(dataSource: DataSource, acquisition: 'try-lock', mode: SessionAdvisoryLockMode, namespace: number, key: number, callback: () => Promise | T): Promise>; /** * Runs a callback while holding a blocking PostgreSQL session-level advisory lock identified by one key. * * @typeParam T - The value returned by the callback. * @param dataSource - The PostgreSQL TypeORM data source used to create the lock-owning session. * @param acquisition - Waits for the lock; must be `'blocking'`. * @param mode - Whether the lock is exclusive or shared. * @param key - The single PostgreSQL advisory-lock key. * @param callback - Work to execute after the lock is acquired. */ export declare function advisoryLock(dataSource: DataSource, acquisition: 'blocking', mode: SessionAdvisoryLockMode, key: number, callback: () => Promise | T): Promise; /** * Runs a callback while holding a blocking PostgreSQL session-level advisory lock identified by two keys. * * @typeParam T - The value returned by the callback. * @param dataSource - The PostgreSQL TypeORM data source used to create the lock-owning session. * @param acquisition - Waits for the lock; must be `'blocking'`. * @param mode - Whether the lock is exclusive or shared. * @param namespace - The first key, used as the application's lock namespace. * @param key - The second PostgreSQL advisory-lock key within the namespace. * @param callback - Work to execute after the lock is acquired. */ export declare function advisoryLock(dataSource: DataSource, acquisition: 'blocking', mode: SessionAdvisoryLockMode, namespace: number, key: number, callback: () => Promise | T): Promise; /** * Attempts to run a callback while holding a PostgreSQL session-level advisory lock identified by one key. * * @typeParam T - The value returned by the callback. * @param dataSource - The PostgreSQL TypeORM data source used to create the lock-owning session. * @param mode - Whether the lock is exclusive or shared. * @param key - The single PostgreSQL advisory-lock key. * @param callback - Work to execute after the lock is acquired. */ export declare function tryAdvisoryLock(dataSource: DataSource, mode: SessionAdvisoryLockMode, key: number, callback: () => Promise | T): Promise>; /** * Attempts to run a callback while holding a PostgreSQL session-level advisory lock identified by two keys. * * @typeParam T - The value returned by the callback. * @param dataSource - The PostgreSQL TypeORM data source used to create the lock-owning session. * @param mode - Whether the lock is exclusive or shared. * @param namespace - The first key, used as the application's lock namespace. * @param key - The second PostgreSQL advisory-lock key within the namespace. * @param callback - Work to execute after the lock is acquired. */ export declare function tryAdvisoryLock(dataSource: DataSource, mode: SessionAdvisoryLockMode, namespace: number, key: number, callback: () => Promise | T): Promise>;