UNPKG

syncguard

Version:

Functional TypeScript library for distributed locking across microservices. Prevents race conditions with Redis, PostgreSQL, Firestore, and custom backends. Features automatic lock management, timeout handling, and extensible architecture.

27 lines (26 loc) 983 B
import type { Sql } from "postgres"; import { type KeyOp } from "../../common/backend.js"; import type { PostgresConfig } from "../types.js"; /** * Creates isLocked operation for PostgreSQL backend. * * **Implementation Pattern:** * - Read-only by default (no side effects) * - Optional cleanup when cleanupInIsLocked: true (fire-and-forget) * - Uses server time for liveness check * - Simple boolean return value * * Flow: * 1. Normalize and validate key * 2. Query lock by key * 3. Check liveness using server time * 4. Optionally cleanup expired locks (fire-and-forget, with safety guard) * 5. Return boolean result * * @param sql - postgres.js SQL instance * @param config - PostgreSQL backend configuration * @returns IsLocked operation function * * @see docs/specs/interface.md#islocked-operation-requirements - Normative requirements */ export declare function createIsLockedOperation(sql: Sql, config: PostgresConfig): (opts: KeyOp) => Promise<boolean>;