import { PlatformCompat } from './platforms/type'; import { MapStore, ReadableAtom } from 'nanostores'; type NoKey = null | undefined | void | false; type SomeKey = string | number | true; export type KeyInput = SomeKey | Array | FetcherStore>; type Key = string; type KeyParts = SomeKey[]; export type KeySelector = Key | Key[] | ((key: Key) => boolean); export type Fetcher = (...args: KeyParts) => Promise; export type OnErrorRetry = (opts: { error: unknown; key: Key; retryCount: number; }) => number | void | false | null | undefined; type EventTypes = { onError?: (error: unknown) => void; }; type RefetchSettings = { dedupeTime?: number; revalidateOnFocus?: boolean; revalidateOnReconnect?: boolean; revalidateInterval?: number; cacheLifetime?: number; onErrorRetry?: OnErrorRetry | null | false; }; export type CommonSettings = { fetcher?: Fetcher; } & RefetchSettings & EventTypes; export type NanoqueryArgs = { cache?: Map; } & CommonSettings; export type FetcherValue = { data?: T; error?: E; loading: boolean; promise?: Promise; }; type LazyFetchValue = { data: T; } | { error: E; }; export type FetcherStore = MapStore> & { _: Symbol; key?: Key; invalidate: (...args: any[]) => void; revalidate: (...args: any[]) => void; mutate: (data?: T) => void; fetch: () => Promise>; }; export type FetcherStoreCreator = (keys: KeyInput, settings?: CommonSettings) => FetcherStore; export type ManualMutator = (args: { data: Data; invalidate: (key: KeySelector) => void; revalidate: (key: KeySelector) => void; getCacheUpdater: (key: Key, shouldRevalidate?: boolean) => [(newValue?: T) => void, T | undefined]; }) => Promise; export type MutateCb = Data extends void ? () => Promise : (data: Data) => Promise; export type MutatorStore = MapStore<{ mutate: MutateCb; data?: Result; loading?: boolean; error?: E; }> & { mutate: MutateCb; }; /** * This piece of shenanigans is copy-pasted from SWR. God be my witness I don't like * all this bitwise shifting operations as they are absolutely unclear, but I'm * ok to compact the code a bit. */ export declare function defaultOnErrorRetry({ retryCount }: { retryCount: number; }): number; export declare const nanoqueryFactory: ([isAppVisible, visibilityChangeSubscribe, reconnectChangeSubscribe,]: PlatformCompat) => ({ cache, fetcher: globalFetcher, ...globalSettings }?: NanoqueryArgs) => readonly [(keyInput: KeyInput, { fetcher, ...fetcherSettings }?: CommonSettings) => FetcherStore, (mutator: ManualMutator, opts?: { throttleCalls?: boolean; onError?: EventTypes["onError"]; }) => MutatorStore, { readonly __unsafeOverruleSettings: (data: CommonSettings) => void; readonly invalidateKeys: (keySelector: KeySelector) => void; readonly revalidateKeys: (keySelector: KeySelector) => void; readonly mutateCache: (keySelector: KeySelector, data?: unknown) => void; }]; export {};