import type { CompoundIndexDefinition } from './index-level.js';
import type { EventLogReadOptions, EventLogReadResult, ProgressToken, ReplicationFeedReader, WakePublisher } from '../types/subscriptions.js';
import type { Filter, KeyValues, PaginationCursor, QueryOptions } from '../types/query-types.js';
import type { GenericMessage, MessageSort, Pagination } from '../types/message-types.js';
import type { MessageStore, MessageStoreOptions, MessageStorePutResult } from '../types/message-store.js';
import { createLevelDatabase } from './level-wrapper.js';
/**
 * A {@link MessageStore} and {@link ReplicationFeedReader} implementation that works in both the
 * browser and server-side, backed by a SINGLE LevelDB root: message blocks, query indexes, the
 * per-tenant replication log, the cid→seq index, fingerprint domains, the tenant counters, and
 * the store epoch are all sublevels of one Level instance, so every mutation commits as one fully
 * atomic batch.
 *
 * A per-tenant async write mutex spans seq assignment through batch write, so commit order equals
 * seq order by construction. Seq assignment is gap-free (a failed batch never persists the head),
 * while the readable log stays sparse after compaction and under filters — readers never assume
 * contiguity.
 */
export declare class MessageStoreLevel implements MessageStore, ReplicationFeedReader {
    config: MessageStoreLevelConfig;
    private readonly wakePublisher?;
    private partitionsPromise?;
    private epochPromise?;
    private readonly writeLocks;
    /**
     * @param {MessageStoreLevelConfig} config
     * @param {string} config.location - must be a directory path (relative or absolute) where
     *  LevelDB will store its files, or in browsers, the name of the
     * {@link https://developer.mozilla.org/en-US/docs/Web/API/IDBDatabase IDBDatabase} to be opened.
     * @param {CompoundIndexDefinition[]} config.compoundIndexes - compound indexes to register.
     *   Defaults to DEFAULT_COMPOUND_INDEXES which cover the most common DWN query patterns.
     * @param {WakePublisher} config.wakePublisher - optional bus for store-owned wake publication.
     */
    constructor(config?: MessageStoreLevelConfig);
    open(): Promise<void>;
    close(): Promise<void>;
    /**
     * Lazily creates the single Level root and its partition handles.
     */
    private partitions;
    private createPartitions;
    /**
     * The query index over the shared root. Constructed lazily alongside the partitions.
     */
    private indexPromise?;
    private index;
    /**
     * Returns the persisted store epoch, generating and persisting a fresh `crypto.randomUUID()`
     * at first open. Replaced only by `clear()` — a full local reset with no surviving cursors.
     */
    epoch(): Promise<string>;
    private getEpoch;
    private initializeEpoch;
    get(tenant: string, cidString: string, options?: MessageStoreOptions): Promise<GenericMessage | undefined>;
    query(tenant: string, filters: Filter[], messageSort?: MessageSort, pagination?: Pagination, options?: MessageStoreOptions): Promise<{
        messages: GenericMessage[];
        cursor?: PaginationCursor;
    }>;
    count(tenant: string, filters: Filter[], messageSort?: MessageSort, options?: MessageStoreOptions): Promise<number>;
    /**
     * Builds the IndexLevel QueryOptions object given MessageStore sort and pagination parameters.
     */
    static buildQueryOptions(messageSort?: MessageSort, pagination?: Pagination): QueryOptions;
    put(tenant: string, message: GenericMessage, indexes: KeyValues, options?: MessageStoreOptions): Promise<MessageStorePutResult>;
    updateIndexes(tenant: string, messageCid: string, indexes: KeyValues, options?: MessageStoreOptions): Promise<void>;
    updateMessageAndIndexes(tenant: string, messageCid: string, message: GenericMessage, indexes: KeyValues, options?: MessageStoreOptions): Promise<void>;
    delete(tenant: string, cidString: string, options?: MessageStoreOptions): Promise<void>;
    /**
     * deletes everything in the underlying store, then persists a fresh epoch — a full local
     * reset after which no previously issued cursor is valid.
     */
    clear(): Promise<void>;
    logRead(tenant: string, options?: EventLogReadOptions): Promise<EventLogReadResult>;
    private readEventFromLogEntry;
    logBounds(tenant: string): Promise<{
        oldest: ProgressToken;
        latest: ProgressToken;
    } | undefined>;
    fingerprint(tenant: string, scopes: string[]): Promise<string>;
    /**
     * Serializes all log-mutating operations for a tenant: the lock spans seq assignment through
     * batch write, so commit order equals seq order (synchronous assignment alone is insufficient —
     * a later batch could land first).
     */
    private withTenantWriteLock;
    /**
     * Reads the tenant's counter high-water (the highest position ever issued), `0n` when unused.
     */
    private getHead;
    private assertNoPreSubstrateLayout;
    private static parseSublevelPartition;
    private readStoredMessage;
    /**
     * Validates a replication cursor against the tenant stream and persisted store epoch.
     * Throws `EventLogProgressGap` with bounds metadata when the cursor cannot be replayed.
     */
    private validateCursor;
    private validateCursorPosition;
    private getMessageCidAtPosition;
    /**
     * Resolves the log row for a same-CID mutation, throwing the given code when no row exists.
     */
    private getLogEntryForMutation;
    /**
     * Creates the batch operations that fold a message CID's contribution into the given
     * fingerprint domains. XOR is self-inverse, so the same operations serve insert and delete.
     */
    private createFingerprintFoldOperations;
    /**
     * Encodes a fingerprint domain name as a Level key. The uniform prefix keeps the global
     * domain (the empty string) a valid key.
     */
    private static fingerprintKey;
    private buildToken;
    /**
     * Publishes a wake post-commit. Best-effort by contract — never throws into the write path.
     */
    private publishWake;
}
export type MessageStoreLevelConfig = {
    /**
     * The single directory path (or IndexedDB database name in browsers) backing the whole store —
     * message blocks, query indexes, the replication log, fingerprints, counters, and epoch are all
     * sublevels of one Level instance.
     */
    location?: string;
    createLevelDatabase?: typeof createLevelDatabase;
    compoundIndexes?: CompoundIndexDefinition[];
    wakePublisher?: WakePublisher;
};
//# sourceMappingURL=message-store-level.d.ts.map