import { type Effect, type EffectParams, type EffectResult, type Event, type EventCallable, type Store } from "effector"; import type { ApolloError } from "@apollo/client"; import { type OperationStatus, type ViewStatus } from "./lib/status.mjs"; export interface ExecutionParams { variables: Variables; meta: Meta; } interface CreateRemoteOperationOptions { handler: (params: ExecutionParams) => Promise; name?: string; } export interface RemoteOperationInternals { $variables: Store; execute: EventCallable>; executeFx: Effect, Data, ApolloError>; called: Event>; } export interface RemoteOperation extends ViewStatus { /** Reset operation state to `initial`. */ reset: EventCallable; /** Current operation status. */ $status: Store; /** Set of events that signal the end of your operation. */ finished: { /** The operation has succeeded, use `data` freely. */ success: Event<{ variables: Variables; meta: Meta; data: Data; }>; /** The operation has failed, and you need to handle `error`. */ failure: Event<{ variables: Variables; meta: Meta; error: ApolloError; }>; finally: Event<{ variables: Variables; meta: Meta; } & ({ status: "done"; data: Data; } | { status: "fail"; error: ApolloError; })>; }; /** * Internal tools, useful for testing. */ __: RemoteOperationInternals; } export type OperationParams> = EffectParams; export type OperationResult> = EffectResult; export declare function createRemoteOperation({ handler, name, }: CreateRemoteOperationOptions): RemoteOperation; export {};