import type { GenericMessage } from '../types/message-types.js';
import type { ProgressToken } from '../types/subscriptions.js';
import type { ProtocolDefinition } from '../types/protocols-types.js';
import type { ValidationStateReader } from '../types/validation-state-reader.js';
export type ReplicationApplyOptions = {
    dataStream?: ReadableStream<Uint8Array>;
};
export type ReplicationApplyResult = {
    kind: 'Applied';
    /** True when the local store retained dependency ancestry but did not advance latest state. */
    ancestryOnly?: true;
    /** Local admission position, when the receiving store has a durable replication log. */
    position?: ProgressToken;
} | {
    kind: 'Duplicate';
} | {
    kind: 'Superseded';
} | {
    kind: 'Incomplete';
    missing: DependencyRef[];
} | {
    kind: 'Invalid';
    reason: string;
} | {
    kind: 'Deferred';
    reason: 'tenant-inactive' | 'resolver-unavailable' | 'storage';
};
export type ReplicationApplyResultContext = {
    protocolDefinition?: ProtocolDefinition;
    /**
     * Complete set of locally-missing ancestor recordIds for a missing-ancestor failure
     * (immediate parent or record-chain construction), ordered root-first with the failure-named
     * ancestor last, as computed by `missingAncestorRecordIdsFromReply()`. When present, the
     * resulting `Incomplete` carries one ref per entry so the entire ancestry resolves in a
     * single fetch pass instead of one ancestry level per retry.
     */
    missingAncestorRecordIds?: string[];
};
export type DependencyRef = {
    type: 'Protocol';
    protocol: string;
    messageCid?: string;
    terminal?: boolean;
} | {
    type: 'InitialWrite';
    recordId: string;
    protocol?: string;
    messageCid?: string;
    terminal?: boolean;
} | {
    type: 'Parent';
    recordId: string;
    protocol: string;
    messageCid?: string;
    terminal?: boolean;
} | {
    type: 'Ancestor';
    recordId: string;
    protocol?: string;
    messageCid?: string;
    terminal?: boolean;
} | {
    type: 'Role';
    protocol: string;
    protocolPath: string;
    recipient: string;
    contextPrefix?: string;
    messageCid?: string;
    terminal?: boolean;
} | {
    type: 'Grant';
    permissionGrantId: string;
    messageCid?: string;
    terminal?: boolean;
} | {
    type: 'EncryptionProtocol';
    protocolPath: 'audienceEpoch' | 'audienceKey' | 'grantKey';
    tags?: Record<string, string | number>;
    recipient?: string;
    messageCid?: string;
    terminal?: boolean;
} | {
    type: 'CrossProtocolRef';
    protocol: string;
    recordId: string;
    messageCid?: string;
    terminal?: boolean;
} | {
    type: 'RecordData';
    recordId: string;
    dataCid: string;
    protocol?: string;
    messageCid?: string;
    terminal?: boolean;
};
/**
 * Converts a regular handler reply into the structured result consumed by
 * replication sync. The DWN handler remains the dependency authority; this
 * adapter only gives the sync transport a typed way to distinguish missing
 * dependencies from terminal invalid messages.
 */
export declare function replicationApplyResultFromReply(message: GenericMessage, reply: {
    status: {
        code: number;
        detail?: string;
    };
    position?: ProgressToken;
}, context?: ReplicationApplyResultContext): ReplicationApplyResult;
/**
 * Computes the complete set of locally-missing ancestor recordIds for a replicated message that
 * failed on a missing ancestor — either the immediate parent referential check
 * (`ProtocolAuthorizationParentRecordNotFound`) or record-chain construction
 * (`ProtocolAuthorizationParentNotFoundConstructingRecordChain`).
 *
 * Both failures name a single ancestor, but the message's `contextId` names the full ancestor
 * recordId chain, so every segment the failed check could not reach is presence-checked here and
 * all absent segments are returned in one batch (ordered root-first, named ancestor last).
 * Feeding the result to `replicationApplyResultFromReply()` via `ReplicationApplyResultContext`
 * lets sync fetch the entire ancestry in a single pass instead of one level per retry.
 *
 * @returns the missing ancestor recordIds, or `undefined` when the reply is not a
 *          missing-ancestor failure or the chain cannot be determined from the message (callers
 *          then fall back to emitting the single ancestor named by the failure).
 */
export declare function missingAncestorRecordIdsFromReply(tenant: string, message: GenericMessage, reply: {
    status: {
        detail?: string;
    };
}, validationStateReader: ValidationStateReader): Promise<string[] | undefined>;
//# sourceMappingURL=replication-apply.d.ts.map