import type { LogContext } from '@rocicorp/logger';
import type { InspectQueryRow } from '../../../../zero-protocol/src/inspect-down.ts';
import { ErrorForClient, ErrorWithLevel } from '../../types/error-for-client.ts';
import type { PostgresDB, PostgresTransaction } from '../../types/pg.ts';
import { type ShardID } from '../../types/shards.ts';
import type { PatchToVersion } from './client-handler.ts';
import type { CVR, CVRSnapshot } from './cvr.ts';
import { type RowsRow } from './schema/cvr.ts';
import { type ClientRecord, type CVRVersion, type NullableCVRVersion, type QueryPatch, type QueryRecord, type RowID, type RowRecord } from './schema/types.ts';
import { type TTLClock } from './ttl-clock.ts';
export type CVRFlushStats = {
    instances: number;
    queries: number;
    desires: number;
    clients: number;
    rows: number;
    rowsDeferred: number;
    statements: number;
};
export declare class CVRStore {
    #private;
    constructor(lc: LogContext, cvrDb: PostgresDB, upstreamDb: PostgresDB | undefined, shard: ShardID, taskID: string, cvrID: string, failService: (e: unknown) => void, loadAttemptIntervalMs?: number, maxLoadAttempts?: number, deferredRowFlushThreshold?: number, // somewhat arbitrary
    setTimeoutFn?: typeof setTimeout);
    load(lc: LogContext, lastConnectTime: number): Promise<CVR>;
    getRowRecords(): Promise<ReadonlyMap<RowID, RowRecord>>;
    putRowRecord(row: RowRecord): void;
    /**
     * Note: Removing a row from the CVR should be represented by a
     *       {@link putRowRecord()} with `refCounts: null` in order to properly
     *       produce the appropriate delete patch when catching up old clients.
     *
     * This `delRowRecord()` method, on the other hand, is only used:
     * - when a row record is being *replaced* by another RowRecord, which currently
     *   only happens when the columns of the row key change
     * - for "canceling" the put of a row that was not in the CVR in the first place.
     */
    delRowRecord(id: RowID): void;
    /**
     * Overrides the default logic that removes no-op writes and forces
     * the updates for the given row `ids`. This has no effect if there
     * are no corresponding puts or dels for the associated row records.
     */
    forceUpdates(...ids: RowID[]): void;
    /**
     * Updates the `ttlClock` of the CVR instance. The ttlClock starts at 0 when
     * the CVR instance is first created and increments based on elapsed time
     * since the base time established by the ViewSyncerService.
     */
    updateTTLClock(ttlClock: TTLClock, lastActive: number): Promise<void>;
    /**
     * @returns This returns the current `ttlClock` of the CVR instance. The ttlClock
     *          represents elapsed time since the instance was created (starting from 0).
     *          If the CVR has never been initialized for this client group, it returns
     *          `undefined`.
     */
    getTTLClock(): Promise<TTLClock | undefined>;
    putInstance({ version, replicaVersion, lastActive, clientSchema, ttlClock, }: Pick<CVRSnapshot, 'version' | 'replicaVersion' | 'lastActive' | 'clientSchema' | 'ttlClock'>): void;
    markQueryAsDeleted(version: CVRVersion, queryPatch: QueryPatch): void;
    putQuery(query: QueryRecord): void;
    updateQuery(query: QueryRecord): void;
    insertClient(client: ClientRecord): void;
    deleteClient(clientID: string): void;
    putDesiredQuery(newVersion: CVRVersion, query: {
        id: string;
    }, client: {
        id: string;
    }, deleted: boolean, inactivatedAt: TTLClock | undefined, ttl: number): void;
    catchupRowPatches(lc: LogContext, afterVersion: NullableCVRVersion, upToCVR: CVRSnapshot, current: CVRVersion, excludeQueryHashes?: string[]): AsyncGenerator<RowsRow[], void, undefined>;
    catchupConfigPatches(lc: LogContext, afterVersion: NullableCVRVersion, upToCVR: CVRSnapshot, current: CVRVersion): Promise<PatchToVersion[]>;
    get rowCount(): number;
    flush(lc: LogContext, expectedCurrentVersion: CVRVersion, cvr: CVRSnapshot, lastConnectTime: number): Promise<CVRFlushStats | null>;
    hasPendingUpdates(): boolean;
    /** Resolves when all pending updates are flushed. */
    flushed(lc: LogContext): Promise<void>;
    inspectQueries(lc: LogContext, ttlClock: TTLClock, clientID?: string): Promise<InspectQueryRow[]>;
}
/**
 * This is similar to {@link CVRStore.#checkVersionAndOwnership} except
 * that it only checks the version and is suitable for snapshot reads
 * (i.e. by doing a plain `SELECT` rather than a `SELECT ... FOR UPDATE`).
 */
export declare function checkVersion(tx: PostgresTransaction, schema: string, clientGroupID: string, expectedCurrentVersion: CVRVersion): Promise<void>;
export declare class ConcurrentModificationException extends ErrorWithLevel {
    readonly name = "ConcurrentModificationException";
    constructor(expectedVersion: string, actualVersion: string);
}
export declare class OwnershipError extends ErrorForClient {
    readonly name = "OwnershipError";
    constructor(owner: string | null, grantedAt: number | null, lastConnectTime: number);
}
export declare class InvalidClientSchemaError extends ErrorForClient {
    readonly name = "InvalidClientSchemaError";
    constructor(cause: unknown);
}
export declare class RowsVersionBehindError extends Error {
    readonly name = "RowsVersionBehindError";
    readonly cvrVersion: string;
    readonly rowsVersion: string | null;
    constructor(cvrVersion: string, rowsVersion: string | null);
}
//# sourceMappingURL=cvr-store.d.ts.map