/**
 * syncPatchLoader — patch loading helpers for the WARP sync protocol.
 *
 * Handles reading patches from Git commits: decoding commit messages,
 * loading patch blobs, and walking writer chains to collect patch ranges.
 *
 * @module domain/services/sync/syncPatchLoader
 * @see SyncProtocol — WARP sync spec Section 11 (Network Sync)
 */
import VersionVector from '../../crdt/VersionVector.ts';
import type { PatchOp } from '../../types/ops/unions.ts';
import type CommitPort from '../../../ports/CommitPort.ts';
import type BlobPort from '../../../ports/BlobPort.ts';
import type PatchJournalPort from '../../../ports/PatchJournalPort.ts';
import type CommitMessageCodecPort from '../../../ports/CommitMessageCodecPort.ts';
export interface DecodedPatch {
    context: VersionVector | Map<string, number> | Record<string, number> | null | undefined;
    ops: PatchOp[];
    writer: string;
    lamport: number;
    schema?: 2 | 3;
    reads?: string[] | undefined;
    writes?: string[] | undefined;
}
export interface LoadPatchRangeOptions {
    patchJournal?: PatchJournalPort;
    commitMessageCodec?: CommitMessageCodecPort;
}
/**
 * Normalizes a patch after CBOR deserialization.
 *
 * CBOR deserialization can return plain JavaScript objects, but the CRDT
 * merge logic (JoinReducer) expects the context field to be a VersionVector.
 * This function always constructs a validated Patch so decoded objects cannot
 * bypass constructor invariants.
 */
export declare function normalizePatch(patch: DecodedPatch): DecodedPatch;
/**
 * Loads a patch from a commit.
 *
 * WARP stores patches as Git blobs, with the blob OID embedded in the
 * commit message. This function:
 * 1. Reads the commit message via `showNode()`
 * 2. Decodes the message to extract the patch blob OID
 * 3. Reads the blob and CBOR-decodes it via `patchJournal.readPatch()`
 * 4. Normalizes the patch (converts context to VersionVector)
 *
 * @param persistence - Git persistence layer (CommitPort + BlobPort)
 * @param sha - The 40-character commit SHA to load the patch from
 * @param options - Options including optional patchJournal
 * @throws {PersistenceError} If patchJournal is not provided
 * @throws {Error} If the commit or patch blob cannot be read or decoded
 */
export declare function loadPatchFromCommit(persistence: CommitPort & BlobPort, sha: string, { patchJournal, commitMessageCodec }?: LoadPatchRangeOptions): Promise<DecodedPatch>;
/**
 * Loads patches for a writer between two SHAs.
 *
 * Walks the commit graph backwards from `toSha` to `fromSha` (exclusive),
 * collecting patches along the way. Returns them in chronological order
 * (oldest first) for correct application.
 *
 * **Ancestry requirement**: `toSha` must be a descendant of `fromSha` in the
 * writer's linear chain. If not, a divergence error is thrown.
 *
 * **Performance**: O(N) where N is the number of commits between fromSha and toSha.
 * Each commit requires two reads: commit info (for parent) and patch blob.
 *
 * @param persistence - Git persistence layer (CommitPort + BlobPort)
 * @param _graphName - Graph name (used in error messages, not for lookups)
 * @param writerId - Writer ID (used in error messages, not for lookups)
 * @param fromSha - Start SHA (exclusive). Pass null to load ALL patches from chain start.
 * @param toSha - End SHA (inclusive). Typically the writer's current tip.
 * @param options - Options including optional patchJournal
 * @returns Array of patch objects in chronological order (oldest first)
 * @throws {SyncError} If divergence is detected (toSha does not descend from fromSha)
 * @throws {Error} If any commit or patch cannot be loaded
 *
 * @example
 * // Load patches from sha-a (exclusive) to sha-c (inclusive)
 * const patches = await loadPatchRange(persistence, 'events', 'node-1', 'sha-a', 'sha-c');
 * // Returns [{patch, sha: 'sha-b'}, {patch, sha: 'sha-c'}] in chronological order
 *
 * @example
 * // Load ALL patches for a new writer
 * const patches = await loadPatchRange(persistence, 'events', 'new-writer', null, tipSha);
 */
export declare function loadPatchRange(persistence: CommitPort & BlobPort, _graphName: string, writerId: string, fromSha: string | null, toSha: string, { patchJournal, commitMessageCodec }?: LoadPatchRangeOptions): Promise<Array<{
    patch: DecodedPatch;
    sha: string;
}>>;
