import { type UseQueryResult, type UseMutationResult, type QueryKey, type QueryObserverOptions } from "@tanstack/react-query"; import { Reactor, BaseActor, FunctionName, TransformKey, ReactorArgs, ReactorReturnOk, ReactorReturnErr, FunctionType } from "@ic-reactor/core"; import { CallConfig } from "@icp-sdk/core/agent"; /** * Configuration for useActorMethod hook. * Extends react-query's QueryObserverOptions with custom reactor params. * * This is a unified hook that handles both query and mutation methods. * Query-specific options (like refetchInterval) only apply to query methods. * Mutation-specific options (like invalidateQueries) only apply to mutation methods. */ export interface UseActorMethodParameters = FunctionName, T extends TransformKey = "candid"> extends Omit, ReactorReturnErr, ReactorReturnOk, ReactorReturnOk, QueryKey>, "queryKey" | "queryFn"> { /** The reactor instance to use for method calls */ reactor: Reactor; /** The method name to call on the canister */ functionName: M; /** Arguments to pass to the method (optional for parameterless methods) */ args?: ReactorArgs; /** Agent call configuration (effectiveCanisterId, etc.) */ callConfig?: CallConfig; /** Custom query key (auto-generated if not provided) */ queryKey?: QueryKey; /** * Callback when the method call succeeds. * Works for both query and mutation methods. */ onSuccess?: (data: ReactorReturnOk) => void; /** * Callback when the method call fails. * Works for both query and mutation methods. */ onError?: (error: ReactorReturnErr) => void; /** * Query keys to invalidate after a successful mutation. * Only applies to mutation methods (updates). */ invalidateQueries?: QueryKey[]; } /** * Configuration type for bound useActorMethod hook (reactor omitted). * For use with createActorHooks. */ export type UseActorMethodConfig = FunctionName, T extends TransformKey = "candid"> = Omit, "reactor">; /** * Result type for useActorMethod hook. * Provides a unified interface for both query and mutation methods. */ export interface UseActorMethodResult = FunctionName, T extends TransformKey = "candid"> { /** The returned data from the method call */ data: ReactorReturnOk | undefined; /** Whether the method is currently executing */ isLoading: boolean; /** Alias for isLoading - whether a mutation is pending */ isPending: boolean; /** Whether there was an error */ isError: boolean; /** Whether the method has successfully completed at least once */ isSuccess: boolean; /** The error if one occurred */ error: ReactorReturnErr | null; /** Whether this is a query method (true) or mutation method (false) */ isQuery: boolean; /** The function type (query, update, composite_query) */ functionType: FunctionType; /** * Call the method with optional arguments. * For queries: triggers a refetch * For mutations: executes the mutation with the provided args */ call: (args?: ReactorArgs) => Promise | undefined>; /** * Reset the state (clear data and error). * For queries: removes the query from cache * For mutations: resets the mutation state */ reset: () => void; /** * For queries only: Refetch the query */ refetch: () => Promise | undefined>; /** The raw query result (only available for query methods) */ queryResult?: UseQueryResult, ReactorReturnErr>; /** The raw mutation result (only available for mutation methods) */ mutationResult?: UseMutationResult, ReactorReturnErr, ReactorArgs>; } /** * A unified hook for calling canister methods that automatically handles * both query and mutation methods based on the Candid interface. */ export declare function useActorMethod = FunctionName, T extends TransformKey = "candid">({ reactor, functionName, args, callConfig, queryKey: customQueryKey, enabled, onSuccess, onError, invalidateQueries, ...queryOptions }: UseActorMethodParameters): UseActorMethodResult; /** * Creates a bound useMethod hook for a specific reactor instance. * * @example * ```tsx * const { useMethod } = createActorMethodHooks(reactor) * ``` */ export declare function createActorMethodHooks(reactor: Reactor): { /** * Hook for calling methods on the bound reactor. */ useMethod: >(config: Omit, "reactor">) => UseActorMethodResult; }; //# sourceMappingURL=useActorMethod.d.ts.map