import { EventHookOn } from '@vueuse/core'; import { Ref } from 'vue'; /** * Type for the return value of a usefulApi wrapper, following the Vue.js 3 Composition API pattern. */ export interface UsefulApiProperties Promise> { /** * The execute function that triggers the API call. * @param args - Arguments for the API call */ execute: (...args: A) => Promise; /** * Event hook for handling successful API calls. */ onSuccess: (fn: (result: R, args: A) => any) => void; /** * Event hook for handling errors. */ onError: EventHookOn; /** * Event hook called after the API call is finished, regardless of success or failure. */ onFinally: EventHookOn; /** * A reactive reference indicating whether the API call has finished. */ isFinished: Ref; /** * A reactive reference indicating whether the API call is currently in progress. */ isLoading: Ref; /** * A reactive reference containing the API response. */ response: Ref; /** * A reactive reference containing any error that occurred during the API call. */ error: Ref; /** * Executes the API call directly without any reactivity. */ executeDirect: (...args: A) => Promise; } /** * Maps all async methods of a type to UsefulApiProperties */ export type UsefulApi = { [Property in keyof Type]: Type[Property] extends (...args: infer A) => Promise ? () => UsefulApiProperties : never; }; /** * A utility function that wraps an API call in a structure that provides loading, error, and response states. * * This function is designed to be used with Vue.js 3 and the Composition API. * @param fn - The API function to wrap. * @returns An object containing the execute function and state properties. */ export declare function usefulApi Promise>(fn: T): () => UsefulApiProperties; /** * Applies the usefulApi wrapper to all methods of the given API instance. * * This function automatically wraps all methods of an API class, making them reactive * with loading states, error handling, and event hooks. */ export declare function applyUsefulApi(apiInstance: T): UsefulApi; /** * A utility type for the return value of a UsefulApi method. */ export type UsefulApiMethod = T[K] extends (...args: infer A) => Promise ? UsefulApiProperties : never; //# sourceMappingURL=usefulApi.d.ts.map