import { it as VisualEditingNode } from "./types.js";
import { SanityClient, SanityDocument } from "@sanity/client";
import { DocumentMutatorMachineInput, createSharedListener } from "@sanity/mutate/_unstable_machine";
import { AnyStateMachine } from "xstate";
import { Mutation, NodePatchList } from "@sanity/mutate";
interface DatasetMutatorMachineInput extends Omit<DocumentMutatorMachineInput, 'id'> {
  client: SanityClient;
  /** A shared listener can be provided, if not it'll be created using `client.listen()` */
  sharedListener?: ReturnType<typeof createSharedListener>;
}
declare const createDatasetMutator: (comlink: VisualEditingNode) => AnyStateMachine;
type Path<T, K extends keyof T> = K extends string ? T[K] extends Record<string, any> ? `${K}.${Path<T[K], keyof T[K]>}` | K : K : never;
type PathValue<T, P extends string> = P extends `${infer K}.${infer Rest}` ? K extends keyof T ? PathValue<T[K], Rest> : never : P extends keyof T ? T[P] : never;
type DocumentsMutate = (documentId: string, mutations: Mutation[], options?: {
  commit?: boolean | {
    debounce: number;
  };
}) => void;
type DocumentsGet = <T extends Record<string, any>>(documentId: string) => OptimisticDocument<T>;
type OptimisticDocumentPatches<T extends Record<string, any> = Record<string, any>> = ((context: {
  draftId: string;
  publishedId: string;
  /**
   * @deprecated - use `getSnapshot` instead
   */
  snapshot: SanityDocument<T> | undefined;
  getSnapshot: () => Promise<SanityDocument<T> | null>;
}) => Promise<NodePatchList> | NodePatchList) | NodePatchList;
type OptimisticDocument<T extends Record<string, any> = Record<string, any>> = {
  /**
   * The document ID
   */
  id: string;
  /**
   * Commits any locally applied mutations to the remote document
   */
  commit: () => void;
  /**
   * @deprecated - use `getSnapshot` instead
   */
  get: {
    (): SanityDocument<T> | undefined;
    <P extends Path<T, keyof T>>(path: P): PathValue<T, P> | undefined;
  };
  /**
   * Returns a promise that resolves to the current document snapshot
   */
  getSnapshot: () => Promise<SanityDocument<T> | null>;
  /**
   * Applies the given patches to the document
   */
  patch: (patches: OptimisticDocumentPatches<T>, options?: {
    commit?: boolean | {
      debounce: number;
    };
  }) => void;
};
type OptimisticReducerAction<T> = {
  document: T;
  id: string;
  originalId: string;
  type: 'appear' | 'mutate' | 'disappear';
};
type OptimisticReducer<T, U> = (state: T, action: OptimisticReducerAction<U>) => T;
export { OptimisticReducer as a, PathValue as c, OptimisticDocumentPatches as i, DatasetMutatorMachineInput as l, DocumentsMutate as n, OptimisticReducerAction as o, OptimisticDocument as r, Path as s, DocumentsGet as t, createDatasetMutator as u };
//# sourceMappingURL=types2.d.ts.map