//#region src/idempotency.d.ts
interface IdempotencyRecord {
  token: string;
  claimedAtMs: number;
  staleAtMs: number;
  expiresAtMs: number;
}
interface VersionedIdempotencyRecord {
  version: string;
  record: IdempotencyRecord;
}
interface IdempotencyCompareAndSwapInput {
  key: string;
  expectedVersion: string | null;
  next: IdempotencyRecord | null;
  ttlMs?: number;
}
interface IdempotencyStore {
  read(key: string): Promise<VersionedIdempotencyRecord | null>;
  compareAndSwap(input: IdempotencyCompareAndSwapInput): Promise<boolean>;
}
interface IdempotencyOptions {
  ttlMs: number;
  staleAfterMs: number;
  now?: () => number;
  generateToken?: () => string;
  maxAttempts?: number;
}
interface IdempotencyClaim {
  key: string;
  token: string;
  claimedAtMs: number;
  staleAtMs: number;
  expiresAtMs: number;
}
type IdempotencyClaimResult = {
  status: 'claimed';
  claim: IdempotencyClaim;
  reclaimed: boolean;
} | {
  status: 'duplicate';
  existing: Omit<IdempotencyRecord, 'token'>;
};
type IdempotencyValidationErrorCode = 'invalid-key' | 'invalid-duration' | 'invalid-attempts' | 'invalid-clock' | 'invalid-token' | 'reused-token' | 'token-generation-failed';
declare class IdempotencyValidationError extends Error {
  readonly code: IdempotencyValidationErrorCode;
  readonly field: string;
  constructor(code: IdempotencyValidationErrorCode, field: string, message: string);
}
declare class IdempotencyContentionError extends Error {
  readonly key: string;
  readonly attempts: number;
  constructor(key: string, attempts: number);
}
declare function claimIdempotency(store: IdempotencyStore, key: string, options: IdempotencyOptions): Promise<IdempotencyClaimResult>;
declare function releaseIdempotencyClaim(store: IdempotencyStore, claim: IdempotencyClaim, options?: {
  maxAttempts?: number;
}): Promise<boolean>;
//#endregion
export { IdempotencyClaim, IdempotencyClaimResult, IdempotencyCompareAndSwapInput, IdempotencyContentionError, IdempotencyOptions, IdempotencyRecord, IdempotencyStore, IdempotencyValidationError, IdempotencyValidationErrorCode, VersionedIdempotencyRecord, claimIdempotency, releaseIdempotencyClaim };