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.

21 lines (20 loc) 1.21 kB
import type { CollectionReference, Firestore } from "@google-cloud/firestore"; import { type LockOp, type ReleaseResult } from "../../common/backend.js"; import type { FirestoreConfig } from "../types.js"; /** * Creates Firestore release operation with atomic transaction and ownership verification. * * **Implementation Pattern:** * - Atomic transaction: Query by lockId → verify ownership → delete document * - TOCTOU protection: All steps within single `runTransaction()` (ADR-003, interface.md) * - Ownership verification: Explicit `data.lockId === opts.lockId` check (ADR-003) * - AbortSignal: Manual cancellation checks via `checkAbortedForTransaction()` at strategic points * * @remarks * Omits `.limit(1)` to detect duplicate lockIds (ADR-014). Expired duplicates cleaned, * live duplicates fail safely. * * @see docs/specs/interface.md#release-operation-requirements - Normative TOCTOU and ownership requirements * @see docs/specs/firestore-backend.md#release-operation-requirements - Firestore transaction pattern */ export declare function createReleaseOperation(db: Firestore, locksCollection: CollectionReference, config: FirestoreConfig): (opts: LockOp) => Promise<ReleaseResult>;