import type { AbstractLevel } from 'abstract-level';
import type { ProgressToken } from '@enbox/dwn-sdk-js';
import type { DirectionCheckpoint, LinkStatus, ReplicationLinkState, SyncScope } from './types/sync.js';
/**
 * Durable replication ledger — persists {@link ReplicationLinkState} for each
 * sync link in a LevelDB sublevel. Provides CRUD operations and replication
 * checkpoint helpers.
 *
 * Key format: `{tenantDid}^{remoteEndpoint}^{scopeId}`
 *
 * Each link tracks independent pull and push {@link DirectionCheckpoint}s.
 * The ledger does not own subscriptions or timers — it is a passive state
 * store called by the sync engine.
 */
export declare class ReplicationLedger {
    private readonly db;
    private readonly sublevel;
    constructor(db: AbstractLevel<string | Buffer | Uint8Array>);
    /** Build the compound key for a link. */
    private static buildKey;
    /**
     * Get-or-create a link. If the link does not exist, it is created with
     * `initializing` status and empty checkpoints.
     */
    getOrCreateLink(params: {
        tenantDid: string;
        remoteEndpoint: string;
        scope: SyncScope;
        delegateDid?: string;
        protocol?: string;
    }): Promise<ReplicationLinkState>;
    /** Persist the current state of a link. */
    saveLink(link: ReplicationLinkState): Promise<void>;
    /** Delete a link. */
    deleteLink(tenantDid: string, remoteEndpoint: string, scopeId: string): Promise<void>;
    /** List all links for a tenant. */
    getLinksForTenant(tenantDid: string): Promise<ReplicationLinkState[]>;
    /** List all links. */
    getAllLinks(): Promise<ReplicationLinkState[]>;
    /**
     * Update the `delegateDid` on all persisted links for a tenant and persist.
     * This ensures that repair and reconcile paths — which read `delegateDid`
     * from the durable {@link ReplicationLinkState} — use the current delegate
     * after a hot-swap via `updateIdentityOptions()`.
     *
     * @returns the links that were updated.
     */
    updateDelegateDid(tenantDid: string, delegateDid: string | undefined): Promise<ReplicationLinkState[]>;
    /** Transition a link to a new status and persist. */
    setStatus(link: ReplicationLinkState, status: LinkStatus): Promise<void>;
    /**
     * Compare two tokens by position (BigInt numeric comparison).
     * Returns negative if a < b, zero if equal, positive if a > b.
     * Caller must verify streamId and epoch match before calling.
     */
    static comparePosition(a: ProgressToken, b: ProgressToken): number;
    /**
     * Check whether a token belongs to the same domain (streamId + epoch) as
     * the checkpoint's current baseline. Returns `true` if domains match or if
     * the checkpoint has no baseline yet.
     */
    static validateTokenDomain(checkpoint: DirectionCheckpoint, token: ProgressToken): boolean;
    /**
     * Update `receivedToken` to the highest seen token (for observability).
     * Does NOT advance `contiguousAppliedToken` — that is owned by the engine's
     * delivery-order tracking.
     */
    static setReceivedToken(checkpoint: DirectionCheckpoint, token: ProgressToken): void;
    /**
     * Commit a token as the new contiguous applied baseline. The caller (engine)
     * must have already verified that all earlier delivered tokens for this link
     * are durably committed before calling this.
     */
    static commitContiguousToken(checkpoint: DirectionCheckpoint, token: ProgressToken): void;
    /**
     * Reset a replication checkpoint (e.g., after repair or domain change).
     * Clears all state.
     */
    static resetCheckpoint(checkpoint: DirectionCheckpoint, token?: ProgressToken): void;
    /**
     * Mark a link as needing SMT reconciliation and persist.
     * Idempotent — no-op if already set.
     */
    markNeedsReconcile(link: ReplicationLinkState, _reason?: string): Promise<void>;
    /**
     * Clear the reconciliation flag after successful SMT reconciliation.
     */
    clearNeedsReconcile(link: ReplicationLinkState): Promise<void>;
}
//# sourceMappingURL=sync-replication-ledger.d.ts.map