import { Transaction as LMDBTransaction } from 'lmdb';
import type { Context, Id } from './ResourceInterface.ts';
import { Transaction as RocksTransaction } from '@harperfast/rocksdb-js';
import type { RootDatabaseKind } from './databases.ts';
import type { Entry } from './RecordEncoder.ts';
export declare const TRANSACTION_STATE: {
    CLOSED: number;
    OPEN: number;
    LINGERING: number;
};
export declare function replicationConfirmation(callback: any): void;
declare class StartedTransaction extends Error {
}
type MaybePromise<T> = T | Promise<T>;
export type CommitOptions = {
    doneWriting?: boolean;
    timestamp?: number;
    retries?: number;
    flush?: boolean;
    transaction?: RocksTransaction;
};
type ReadTransaction = (LMDBTransaction | RocksTransaction) & {
    openTimer?: number;
    retryRisk?: number;
};
export type TransactionWrite = {
    key: Id;
    store: RootDatabaseKind;
    invalidated?: boolean;
    entry?: Partial<Entry>;
    before?: () => void | Promise<void>;
    beforeIntermediate?: () => void | Promise<void>;
    commit?: (txnTime: number, existingEntry: Entry, retry: boolean, transaction: RocksTransaction) => void;
    validate?: (txnTime: number) => void;
    fullUpdate?: boolean;
    saved?: boolean;
    deferSave?: boolean;
};
type RocksTransactionWithRetry = RocksTransaction & {
    isRetry?: boolean;
};
export declare class DatabaseTransaction implements Transaction {
    #private;
    writes: TransactionWrite[];
    completions: Promise<void>[];
    db: RootDatabaseKind;
    transaction: RocksTransactionWithRetry;
    readTxn: ReadTransaction;
    readTxnRefCount: number;
    readTxnsUsed: number;
    timeout: number;
    validated: number;
    timestamp: number;
    retries: number;
    next: DatabaseTransaction;
    stale: boolean;
    startedFrom?: {
        resourceName: string;
        method: string;
    };
    stackTraces?: StartedTransaction[];
    overloadChecked: boolean;
    open: number;
    replicatedConfirmation: number;
    getReadTxn(): ReadTransaction;
    useReadTxn(): ReadTransaction;
    doneReadTxn(): void;
    disregardReadTxn(): void;
    checkOverloaded(): void;
    addWrite(operation: TransactionWrite): TransactionWrite;
    save(operation: TransactionWrite, transaction?: RocksTransaction, reloadEntry?: boolean): MaybePromise<CommitResolution>;
    /**
     * Resolves with information on the timestamp and success of the commit
     */
    commit(options?: CommitOptions): MaybePromise<CommitResolution>;
    abort(): void;
    directCommitSync(): void;
    getContext(): Context;
    setContext(context: any): void;
}
export interface CommitResolution {
    txnTime: number;
    next?: CommitResolution;
}
export interface Transaction {
    commit(options: any): MaybePromise<CommitResolution>;
    abort?(): any;
}
export declare class ImmediateTransaction extends DatabaseTransaction {
    isCommitting: boolean;
    constructor(db: RootDatabaseKind);
    save(transaction: ImmediateTransaction): void | Promise<void>;
    get timestamp(): any;
    getReadTxn(): void;
}
export declare function setTxnExpiration(ms: any): Set<DatabaseTransaction>;
export {};
