import type { AccessorOptions } from '../hooks/types.js'; import type { BaseAction } from './types.js'; export type RevalidateContext = { /** * This property is only useful when using infinite accessor. * It specify how many pages should be fetched. */ pageNum?: number; }; export type Status = { isFetching: boolean; error: E | null; }; export type FetchPromiseResult = readonly [E] | readonly [null, D]; export type OnFetchingFinishContext = { error: E | null; data: D | null; }; type RetryTimeoutMeta = { timeoutId: number; reject: () => void; }; export declare abstract class BaseAccessor { protected status: Status; protected statusListeners: ((prev: Status, current: Status) => void)[]; protected fetchPromise: Promise>; protected arg: Arg; protected creatorName: string; private notifyModel; private retryTimeoutMeta; private startAt; private subscribeModel; private optionsRefSet; private removeOnFocusListener; private removeOnReconnectListener; private removeOnVisibilityChangeListener; private pollingTimeoutId; private onMount; private onUnmount; private autoListeners; private removeAllListeners; private isAuto; private setStaleTime; /** * Return the result of the revalidation. */ abstract revalidate: (context?: RevalidateContext) => Promise>; protected abstract action: BaseAction; /** * Get the state of the corresponding model. */ getState: (serverStateKey?: object) => S; isStale: () => boolean; getIsAuto: () => boolean; getKey: () => string; getArg(): Arg; subscribeData: (listener: () => void) => () => void; invalidate: () => void; protected updateStatus: (partialStatus: Partial>) => void; protected notifyStatusListeners: (oldStatus: Status) => void; protected notifyDataListeners: () => void; protected getOptions: () => Required; protected getRetryCount: () => number; protected getDedupeInterval: () => number; protected getRetryInterval: () => number; protected canFetch({ startAt }: { startAt: number; }): boolean; protected shouldDedupe(time: number): boolean; protected updateStartAt(time: number): void; protected isExpiredFetching(time: number): boolean; protected setRetryTimeoutMeta(meta: RetryTimeoutMeta): void; /** * Call this method before fetching start. * This method would: * - clear the polling timeout * - abort the error retry * - update the `fetchPromise` * - update the `startAt` * - update the status with `{ isFetching: true }` */ protected onFetchingStart: ({ fetchPromise, startAt, }: { fetchPromise: Promise>; startAt: number; }) => void; /** * Call this method after the fetching is done. * This method would * - Check whether it need to start polling * - Update the status * - Mark this accessor to be stale * - Notify the model if data is not `null` * - Return the fetchPromise result */ protected onFetchingFinish: ({ error, data, }: OnFetchingFinishContext) => FetchPromiseResult; private getFirstOptionsRef; private registerOnFocus; private registerOnReconnect; private registerOnVisibilityChange; private registerAllListeners; /** * invoke `this.revalidate` if `options.pollingInterval` is larger than 0. * @returns */ private invokePollingRevalidation; /** * Reject the current error retry and clear the error retry timeout. */ private abortRetry; private subscribeAutoAccessor; private notifyAutoAccessor; } export {};