import type { ReceiveType } from '../reflection';
import type { BaseDatabase } from './database';
import type { DriverConnection, ExecuteResult } from './driver';
import type { EntityClass } from './metadata';
import type { QueryBuilder } from './query';
import type { SqlInput } from './sql';
import type { MutexKey } from './database';
import type { EntityMetadata } from './metadata';
import { type DatabaseEntitySnapshot, type DatabaseMutation, type DatabaseQueryMutation } from './mutation';
export interface DatabaseSessionOptions {
    transactional?: boolean;
}
export declare class DatabaseSession {
    readonly db: BaseDatabase;
    private readonly connection?;
    private readonly options;
    private queued;
    private managed;
    private removed;
    private pendingOperations;
    private pendingOperationErrors;
    private preCommitHooks;
    private postCommitHooks;
    private flushing;
    private autoFlushSuppressionDepth;
    private readonly mutationAccumulator;
    private insertedEntities;
    private readonly touchedEntities;
    private readonly transactionStates;
    private readonly savepointCheckpoints;
    private nextSavepointSequence;
    constructor(db: BaseDatabase, connection?: DriverConnection | undefined, options?: DatabaseSessionOptions);
    getConnection(): DriverConnection | undefined;
    get isFlushing(): boolean;
    get shouldAutoFlush(): boolean;
    get isTransactional(): boolean;
    add(...entities: object[]): void;
    manage(...entities: object[]): void;
    removeQueued(...entities: object[]): void;
    unmanage(...entities: object[]): void;
    remove(...entities: object[]): void;
    trackOperation<T>(worker: () => Promise<T>): Promise<T>;
    waitForPendingOperations(): Promise<void>;
    withoutAutoFlush<T>(worker: () => Promise<T>): Promise<T>;
    query<T extends object>(Entity: EntityClass<T>): QueryBuilder<T>;
    rawQuery<T = Record<string, unknown>>(input: SqlInput): Promise<T[]>;
    rawFind<T = Record<string, unknown>>(input: SqlInput): Promise<T[]>;
    rawFindOne<T = Record<string, unknown>>(input: SqlInput): Promise<T | undefined>;
    rawExecute(input: SqlInput): Promise<ExecuteResult>;
    raw(input: SqlInput): DatabaseSessionRawQuery;
    rawFindUnsafe<T = Record<string, unknown>>(text: string, bindings?: unknown[], type?: ReceiveType<T>): Promise<T[]>;
    rawFindOneUnsafe<T = Record<string, unknown>>(text: string, bindings?: unknown[], type?: ReceiveType<T>): Promise<T | undefined>;
    rawExecuteUnsafe(text: string, bindings?: unknown[], type?: unknown): Promise<ExecuteResult>;
    acquireSessionLock(key: MutexKey | MutexKey[]): Promise<void>;
    savepoint(name: string): Promise<void>;
    rollbackToSavepoint(name: string): Promise<void>;
    withSavepoint<T>(name: string, worker: () => Promise<T>): Promise<T>;
    /** Stores transaction-local policy state that participates in savepoint rollback. */
    getTransactionState<T, TCheckpoint>(key: object, create: () => T, checkpoint: (value: T) => TCheckpoint, restore: (value: T, checkpoint: TCheckpoint) => void): T;
    flush(): Promise<void>;
    addPreCommitHook(hook: () => Promise<void>): void;
    addPostCommitHook(hook: () => Promise<void>): void;
    recordEntityMutation(entity: object, metadata: EntityMetadata, before: DatabaseEntitySnapshot | null, after: DatabaseEntitySnapshot | null): void;
    /** Tracks successful inserts so savepoint rollback can restore reusable entity instances. */
    recordEntityInsert(entity: object, metadata: EntityMetadata, autoIncrementField?: string, previousAutoIncrementValue?: unknown): void;
    recordQueryMutation(mutation: DatabaseQueryMutation): void;
    getMutations(): readonly DatabaseMutation[];
    runPreCommitHooks(): Promise<void>;
    runPostCommitHooks(): Promise<void>;
    private createCheckpoint;
    private restoreCheckpoint;
    private assertTransactional;
    private settlePendingOperations;
}
export type DbSession = DatabaseSession;
export interface DatabaseSessionRawQuery {
    execute(): Promise<ExecuteResult>;
    find<T = Record<string, unknown>>(): Promise<T[]>;
    findOne<T = Record<string, unknown>>(): Promise<T | undefined>;
}
//# sourceMappingURL=session.d.ts.map