import type { MaybePromise } from '../../../shared/src/types.ts';
import { CRUD_MUTATION_NAME, type CRUDMutationArg, type CRUDOp, type DeleteOp, type InsertOp, type UpdateOp, type UpsertOp } from '../../../zero-protocol/src/push.ts';
import type { Schema } from '../../../zero-schema/src/builder/schema-builder.ts';
import type { TableSchema } from '../../../zero-schema/src/table-schema.ts';
import type { DeleteID, InsertValue, UpdateValue, UpsertValue } from '../../../zql/src/mutate/custom.ts';
import type { IVMSourceBranch } from './ivm-branch.ts';
import type { MutatorDefs, WriteTransaction } from './replicache-types.ts';
/**
 * This is the type of the generated mutate.<name>.<verb> function.
 */
export type TableMutator<S extends TableSchema> = {
    /**
     * Writes a row if a row with the same primary key doesn't already exists.
     * Non-primary-key fields that are 'optional' can be omitted or set to
     * `undefined`. Such fields will be assigned the value `null` optimistically
     * and then the default value as defined by the server.
     */
    insert: (value: InsertValue<S>) => Promise<void>;
    /**
     * Writes a row unconditionally, overwriting any existing row with the same
     * primary key. Non-primary-key fields that are 'optional' can be omitted or
     * set to `undefined`. Such fields will be assigned the value `null`
     * optimistically and then the default value as defined by the server.
     */
    upsert: (value: UpsertValue<S>) => Promise<void>;
    /**
     * Updates a row with the same primary key. If no such row exists, this
     * function does nothing. All non-primary-key fields can be omitted or set to
     * `undefined`. Such fields will be left unchanged from previous value.
     */
    update: (value: UpdateValue<S>) => Promise<void>;
    /**
     * Deletes the row with the specified primary key. If no such row exists, this
     * function does nothing.
     */
    delete: (id: DeleteID<S>) => Promise<void>;
};
export type DBMutator<S extends Schema> = S['enableLegacyMutators'] extends false ? {} : {
    [K in keyof S['tables']]: TableMutator<S['tables'][K]>;
};
export type BatchMutator<S extends Schema> = <R>(body: (m: DBMutator<S>) => MaybePromise<R>) => Promise<R>;
type ZeroCRUDMutate = {
    [CRUD_MUTATION_NAME]: CRUDMutate;
};
/**
 * This is the zero.mutate object part representing the CRUD operations. If the
 * queries are `issue` and `label`, then this object will have `issue` and
 * `label` properties.
 */
export declare function makeCRUDMutate<const S extends Schema>(schema: S, repMutate: ZeroCRUDMutate): {
    mutate: DBMutator<S>;
    mutateBatch: BatchMutator<S>;
};
/**
 * Creates the `{inesrt, upsert, update, delete}` object for use inside a
 * batch.
 */
export declare function makeBatchCRUDMutate<S extends TableSchema>(tableName: string, schema: Schema, ops: CRUDOp[]): TableMutator<S>;
export type WithCRUD<MD extends MutatorDefs> = MD & {
    [CRUD_MUTATION_NAME]: CRUDMutator;
};
export type CRUDMutate = (crudArg: CRUDMutationArg) => Promise<void>;
export type CRUDMutator = (tx: WriteTransaction, crudArg: CRUDMutationArg) => Promise<void>;
export declare function makeCRUDMutator(schema: Schema): CRUDMutator;
export declare function insertImpl(tx: WriteTransaction, arg: InsertOp, schema: Schema, ivmBranch: IVMSourceBranch | undefined): Promise<void>;
export declare function upsertImpl(tx: WriteTransaction, arg: InsertOp | UpsertOp, schema: Schema, ivmBranch: IVMSourceBranch | undefined): Promise<void>;
export declare function updateImpl(tx: WriteTransaction, arg: UpdateOp, schema: Schema, ivmBranch: IVMSourceBranch | undefined): Promise<void>;
export declare function deleteImpl(tx: WriteTransaction, arg: DeleteOp, schema: Schema, ivmBranch: IVMSourceBranch | undefined): Promise<void>;
export {};
//# sourceMappingURL=crud.d.ts.map