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.

23 lines (22 loc) 1.21 kB
/** * Validates lock ID format (22 base64url characters from 16 bytes CSPRNG). * Client-side validation for immediate feedback before backend operations. * Prevents round-trip latency for malformed inputs. * * @param lockId - Lock identifier to validate * @throws {LockError} InvalidArgument for format violations (empty, wrong length, invalid characters) * @see docs/specs/interface.md#acquire-operation-requirements - Normative lockId validation requirement * @see docs/specs/interface.md#security-considerations - Lock ID security and CSPRNG requirements */ export declare function validateLockId(lockId: string): void; /** * Normalizes key to Unicode NFC and validates length constraints. * Prevents encoding-based key collisions (e.g., "café" vs "cafe\u0301"). * * @param key - User-provided lock key * @returns Normalized key safe for backend storage * @throws {LockError} InvalidArgument for empty/oversized keys (max 512 bytes after NFC normalization) * @see docs/specs/interface.md#core-constants - Normative MAX_KEY_LENGTH_BYTES requirement * @see common/constants.ts - MAX_KEY_LENGTH_BYTES constant definition */ export declare function normalizeAndValidateKey(key: string): string;