import type { SyncOperation } from '@syncular/core';
import type { Insertable, Updateable } from 'kysely';
type AnyDb = Record<string, Record<string, unknown>>;
type ReservedKeys = '$commit' | '$table';
type KnownKeys<T> = string extends keyof T ? never : keyof T & string;
type KnownTableKey<DB> = Exclude<KnownKeys<DB>, ReservedKeys>;
type InsertPayload<Row> = Insertable<Row> extends {
    id?: infer I;
} ? Omit<Insertable<Row>, 'id'> & {
    id?: I;
} : Insertable<Row>;
type UpdatePayload<Row> = Omit<Updateable<Row>, 'id'> & {
    id?: never;
};
type BaseVersionOptions = {
    baseVersion?: number | null;
};
export interface MutationReceipt {
    commitId: string;
    clientCommitId: string;
}
export interface SyncularCommitMeta {
    operations: SyncOperation[];
    localMutations: Array<{
        table: string;
        rowId: string;
        op: 'upsert' | 'delete';
    }>;
}
export type TableMutations<DB, T extends keyof DB & string> = {
    insert: (values: InsertPayload<DB[T]>) => Promise<MutationReceipt & {
        id: string;
    }>;
    insertMany: (rows: Array<InsertPayload<DB[T]>>) => Promise<MutationReceipt & {
        ids: string[];
    }>;
    update: (id: string, patch: UpdatePayload<DB[T]>, options?: BaseVersionOptions) => Promise<MutationReceipt>;
    delete: (id: string, options?: BaseVersionOptions) => Promise<MutationReceipt>;
    upsert: (id: string, patch: UpdatePayload<DB[T]>, options?: BaseVersionOptions) => Promise<MutationReceipt>;
};
export type TableMutationsTx<DB, T extends keyof DB & string> = {
    insert: (values: InsertPayload<DB[T]>) => Promise<string>;
    insertMany: (rows: Array<InsertPayload<DB[T]>>) => Promise<string[]>;
    update: (id: string, patch: UpdatePayload<DB[T]>, options?: BaseVersionOptions) => Promise<void>;
    delete: (id: string, options?: BaseVersionOptions) => Promise<void>;
    upsert: (id: string, patch: UpdatePayload<DB[T]>, options?: BaseVersionOptions) => Promise<void>;
};
export type MutationsTx<DB> = {
    [T in KnownTableKey<DB>]: TableMutationsTx<DB, T>;
} & {
    [table: string]: TableMutationsTx<AnyDb, string>;
};
export type MutationsCommitFn<DB, Meta = unknown, Options = unknown> = <R>(fn: (tx: MutationsTx<DB>) => Promise<R> | R, options?: Options) => Promise<{
    result: R;
    receipt: MutationReceipt;
    meta: Meta;
}>;
export type MutationsApi<DB, CommitOptions = unknown> = {
    $commit: <R>(fn: (tx: MutationsTx<DB>) => Promise<R> | R, options?: CommitOptions) => Promise<{
        result: R;
        commit: MutationReceipt;
    }>;
    $table: {
        <T extends KnownTableKey<DB>>(table: T): TableMutations<DB, T>;
        (table: string): TableMutations<AnyDb, string>;
    };
} & {
    [T in KnownTableKey<DB>]: TableMutations<DB, T>;
};
export declare function createMutationsApi<DB, Meta = unknown, CommitOptions = unknown>(commit: MutationsCommitFn<DB, Meta, CommitOptions>): MutationsApi<DB, CommitOptions>;
export {};
//# sourceMappingURL=mutations.d.ts.map