import type { GenericMessage } from '@enbox/dwn-sdk-js';
/**
 * Typed failure codes for closure resolution. Each code maps to a specific
 * dependency class from the closure RFC.
 */
export declare enum ClosureFailureCode {
    /** Class 1: The ProtocolsConfigure for the protocol could not be found. */
    ProtocolMetadataMissing = "ClosureProtocolMetadataMissing",
    /** Class 2: The initialWrite for a non-initial RecordsWrite is missing. */
    InitialWriteMissing = "ClosureInitialWriteMissing",
    /** Class 2: A parent record in the parentId chain is missing. */
    ParentChainMissing = "ClosureParentChainMissing",
    /** Class 2: A context ancestor record is missing. */
    ContextChainMissing = "ClosureContextChainMissing",
    /** Class 3: A permission grant referenced by permissionGrantId is missing. */
    GrantMissing = "ClosureGrantMissing",
    /** Class 3: The grant exists but is not yet active at the message's timestamp. */
    GrantNotYetActive = "ClosureGrantNotYetActive",
    /** Class 3: The grant exists but has expired at the message's timestamp. */
    GrantExpired = "ClosureGrantExpired",
    /** Class 3: A revocation record that affects a referenced grant is missing. */
    GrantRevocationMissing = "ClosureGrantRevocationMissing",
    /** Class 4: A squash floor or visibility-floor record is missing. */
    VisibilityFloorMissing = "ClosureVisibilityFloorMissing",
    /** Class 5: An encryption/key-delivery dependency is missing. */
    EncryptionDependencyMissing = "ClosureEncryptionDependencyMissing",
    /** Class 6: A cross-protocol $ref dependency is missing. */
    CrossProtocolReferenceMissing = "ClosureCrossProtocolReferenceMissing",
    /** A dependency exists but the syncing principal is not authorized to fetch it. */
    DependencyForbidden = "ClosureDependencyForbidden",
    /** Traversal depth exceeded the configured maximum (default 32). */
    DepthExceeded = "ClosureDepthExceeded"
}
/**
 * A single dependency edge in the closure graph — identifies what is needed
 * and why. Used for diagnostics, deduplication, and fetch queue management.
 */
export type ClosureDependencyEdge = {
    /** The dependency class that produced this edge. */
    dependencyClass: 1 | 2 | 3 | 4 | 5 | 6;
    /** Human-readable label for the dependency (e.g., "initialWrite", "grant", "protocolsConfigure"). */
    label: string;
    /**
     * The identifier used to look up this dependency. Typically a `messageCid`
     * or `recordId` depending on the dependency class.
     */
    identifier: string;
    /** The type of identifier — determines the fetch strategy. */
    identifierType: 'messageCid' | 'recordId' | 'protocol' | 'grantId' | 'filter';
    /**
     * When `identifierType` is `'filter'`, this carries the full query filter
     * as a structured object. Used for dependencies that require multi-field
     * queries (e.g., cross-protocol role records queried by protocol +
     * protocolPath + recipient + contextId prefix).
     */
    filter?: Record<string, unknown>;
};
/**
 * Result of closure evaluation for a single operation (closure root).
 */
export type ClosureResult = {
    /** Whether all hard dependencies are satisfied. */
    complete: boolean;
    /** The closure root's messageCid. */
    rootMessageCid: string;
    /** All dependency edges that were evaluated. */
    edges: ClosureDependencyEdge[];
    /**
     * If incomplete, the first unsatisfied dependency. Used for diagnostics
     * and determines the failure code for repair transitions.
     */
    failure?: {
        code: ClosureFailureCode;
        edge: ClosureDependencyEdge;
        detail: string;
    };
    /** Total number of dependency hops traversed. */
    depth: number;
};
/**
 * Shared context for a batch of closure evaluations. Caches protocol
 * definitions, grant records, and previously resolved operations to avoid
 * redundant queries across closure roots in the same evaluation pass.
 */
export type ClosureEvaluationContext = {
    /** Tenant DID for this evaluation batch. */
    tenantDid: string;
    /** Cached ProtocolsConfigure definitions keyed by protocol URI. */
    protocolCache: Map<string, any>;
    /** Cached grant records keyed by grantId. */
    grantCache: Map<string, GenericMessage | null>;
    /**
     * Set of dependency identifiers already known to be locally present.
     * Keyed by `${identifierType}:${identifier}` to prevent cross-namespace
     * collisions (e.g., a recordId and a grantId with the same string value).
     */
    satisfiedDeps: Set<string>;
    /**
     * Set of dependency identifiers already known to be missing/unfetchable.
     * Same composite key format as `satisfiedDeps`.
     */
    missingDeps: Set<string>;
    /** Maximum traversal depth. Default 32. */
    maxDepth: number;
    /**
     * When `true`, the sync link is operating as a delegated session.
     *
     * Affects class 5 (encryption) dependency extraction:
     *
     * - **Single-party** protocols: the delegate decrypts via pre-derived
     *   `delegateDecryptionKeys` (ProtocolPath keys).  No key-delivery
     *   records are involved, so the `keyDeliveryProtocol` edge is
     *   suppressed entirely in `extractProtocolAwareDeps()`.
     *
     * - **Multi-party** protocols: on in-memory cache miss the runtime
     *   falls back to `fetchCrossDeviceContextKey()` (see
     *   `dwn-encryption.ts:453`, `dwn-key-delivery.ts:268`) which queries
     *   the local DWN.  Both `keyDeliveryProtocol` and `contextKeyRecord`
     *   are emitted and resolved normally.
     */
    isDelegateSession?: boolean;
};
/**
 * Create a fresh evaluation context for a batch of closure evaluations.
 */
export declare function createClosureContext(tenantDid: string, maxDepth?: number, options?: {
    isDelegateSession?: boolean;
}): ClosureEvaluationContext;
/**
 * Invalidate cached entries that may be affected by a newly processed message.
 * Called after `processRawMessage` succeeds to ensure subsequent closure
 * evaluations see the updated state.
 *
 * - `ProtocolsConfigure` → clears protocolCache for that protocol URI
 * - Permissions grant write → clears grantCache for that recordId
 * - Permissions revocation → clears grantCache for the parent grantId
 * - Any Records message → clears satisfiedDeps/missingDeps for that recordId
 *   (the message may have changed what's locally present)
 */
export declare function invalidateClosureCache(context: ClosureEvaluationContext, message: GenericMessage): void;
//# sourceMappingURL=sync-closure-types.d.ts.map