import { type Ref } from 'vue'; import { type CancelablePromise } from '@nzyme/utils'; import { type RefParam } from './reactivity/makeRef.js'; export interface DataSourceLoader { (params: TParams, oldValue: TResult | undefined): Promise | CancelablePromise | TResult; } export type DataSourceBehavior = 'lazy' | 'eager'; export interface DataSourceOptions { /** * Request payload - it will be watched for changes to make calls. * Can be function or a reference. * If undefined is returned, API call will not be made. */ readonly params?: RefParam; readonly load: DataSourceLoader; readonly default?: RefParam; readonly behavior?: DataSourceBehavior; /** Options for debouncing */ readonly debounce?: { /** Number of milliseconds to debounce api calls */ time?: number; leading?: boolean; trailing?: boolean; }; /** Data will be loaded into this ref. Optional. */ readonly data?: ((result: TResult) => void) | Ref; readonly onLoad?: (result: TResult, params: TParams) => unknown; } export interface DataSource extends Ref { readonly pending: Promise | null; readonly get: () => Promise; readonly reload: () => Promise; readonly clear: () => void; readonly invalidate: () => void; } export declare function useDataSource(opts: DataSourceOptions): DataSource;