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.
19 lines (18 loc) • 691 B
JavaScript
// SPDX-FileCopyrightText: 2025-present Kriasoft
// SPDX-License-Identifier: MIT
import { lock } from "../common/auto-lock.js";
import { createFirestoreBackend } from "./backend.js";
/**
* Creates distributed lock with Firestore backend
* @param db - Firestore client instance
* @param options - Retry, TTL, and collection config
* @returns Auto-managed lock function (see: common/auto-lock.ts)
*/
export function createLock(db, options = {}) {
const backend = createFirestoreBackend(db, options);
return (fn, config) => {
return lock(backend, fn, config);
};
}
// Re-exports for custom backend implementations
export { createFirestoreBackend } from "./backend.js";