import type { LogLevel } from '@rocicorp/logger';
import type { ReadonlyJSONValue } from '../../shared/src/json.ts';
import * as v from '../../shared/src/valita.ts';
import { pushParamsSchema, type CustomMutation, type MutationResponse, type PushResponse } from '../../zero-protocol/src/push.ts';
import type { CustomMutatorDefs, CustomMutatorImpl } from './custom.ts';
export interface TransactionProviderHooks {
    updateClientMutationID: () => Promise<{
        lastMutationID: number | bigint;
    }>;
    writeMutationResult: (result: MutationResponse) => Promise<void>;
}
export interface TransactionProviderInput {
    upstreamSchema: string;
    clientGroupID: string;
    clientID: string;
    mutationID: number;
}
/**
 * Defines the abstract interface for a database that PushProcessor can execute
 * transactions against.
 */
export interface Database<T> {
    transaction: <R>(callback: (tx: T, transactionHooks: TransactionProviderHooks) => Promise<R>, transactionInput?: TransactionProviderInput | undefined) => Promise<R>;
}
export type ExtractTransactionType<D> = D extends Database<infer T> ? T : never;
export type Params = v.Infer<typeof pushParamsSchema>;
export type TransactFn = <D extends Database<ExtractTransactionType<D>>>(dbProvider: D, cb: TransactFnCallback<D>) => Promise<MutationResponse>;
export type TransactFnCallback<D extends Database<ExtractTransactionType<D>>> = (tx: ExtractTransactionType<D>, mutatorName: string, mutatorArgs: ReadonlyJSONValue) => Promise<void>;
export type Parsed = {
    transact: TransactFn;
    mutations: CustomMutation[];
};
/**
 * Call `cb` for each mutation in the request.
 * The callback is called sequentially for each mutation.
 * If a mutation is out of order, the processing will stop and an error will be returned.
 * If a mutation has already been processed, it will be skipped and the processing will continue.
 * If a mutation receives an application error, it will be skipped, the error will be returned to the client, and processing will continue.
 */
export declare function handleMutationRequest(cb: (transact: TransactFn, mutation: CustomMutation) => Promise<MutationResponse>, queryString: URLSearchParams | Record<string, string>, body: ReadonlyJSONValue, logLevel?: LogLevel | undefined): Promise<PushResponse>;
export declare function handleMutationRequest(cb: (transact: TransactFn, mutation: CustomMutation) => Promise<MutationResponse>, request: Request, logLevel?: LogLevel | undefined): Promise<PushResponse>;
export declare class OutOfOrderMutation extends Error {
    constructor(clientID: string, receivedMutationID: number, lastMutationID: number | bigint);
}
export declare function getMutation(mutators: CustomMutatorDefs<any>, name: string): CustomMutatorImpl<any, any>;
//# sourceMappingURL=process-mutations.d.ts.map