UNPKG

4.85 kBTypeScriptView Raw
1import { Mutation } from './mutation';
2import { Query } from './query';
3import { EnsuredQueryKey } from './types';
4import { MutationFunction, MutationKey, MutationOptions, QueryFunction, QueryKey, QueryOptions } from './types';
5export interface QueryFilters {
6 /**
7 * Include or exclude active queries
8 */
9 active?: boolean;
10 /**
11 * Match query key exactly
12 */
13 exact?: boolean;
14 /**
15 * Include or exclude inactive queries
16 */
17 inactive?: boolean;
18 /**
19 * Include queries matching this predicate function
20 */
21 predicate?: (query: Query) => boolean;
22 /**
23 * Include queries matching this query key
24 */
25 queryKey?: QueryKey;
26 /**
27 * Include or exclude stale queries
28 */
29 stale?: boolean;
30 /**
31 * Include or exclude fetching queries
32 */
33 fetching?: boolean;
34}
35export interface MutationFilters {
36 /**
37 * Match mutation key exactly
38 */
39 exact?: boolean;
40 /**
41 * Include mutations matching this predicate function
42 */
43 predicate?: (mutation: Mutation<any, any, any>) => boolean;
44 /**
45 * Include mutations matching this mutation key
46 */
47 mutationKey?: MutationKey;
48 /**
49 * Include or exclude fetching mutations
50 */
51 fetching?: boolean;
52}
53export declare type DataUpdateFunction<TInput, TOutput> = (input: TInput) => TOutput;
54export declare type Updater<TInput, TOutput> = TOutput | DataUpdateFunction<TInput, TOutput>;
55export declare type QueryStatusFilter = 'all' | 'active' | 'inactive' | 'none';
56export declare const isServer: boolean;
57export declare function noop(): undefined;
58export declare function functionalUpdate<TInput, TOutput>(updater: Updater<TInput, TOutput>, input: TInput): TOutput;
59export declare function isValidTimeout(value: unknown): value is number;
60export declare function ensureQueryKeyArray<T extends QueryKey>(value: T): EnsuredQueryKey<T>;
61export declare function difference<T>(array1: T[], array2: T[]): T[];
62export declare function replaceAt<T>(array: T[], index: number, value: T): T[];
63export declare function timeUntilStale(updatedAt: number, staleTime?: number): number;
64export declare function parseQueryArgs<TOptions extends QueryOptions<any, any, any, TQueryKey>, TQueryKey extends QueryKey = QueryKey>(arg1: TQueryKey | TOptions, arg2?: QueryFunction<any, TQueryKey> | TOptions, arg3?: TOptions): TOptions;
65export declare function parseMutationArgs<TOptions extends MutationOptions<any, any, any, any>>(arg1: MutationKey | MutationFunction<any, any> | TOptions, arg2?: MutationFunction<any, any> | TOptions, arg3?: TOptions): TOptions;
66export declare function parseFilterArgs<TFilters extends QueryFilters, TOptions = unknown>(arg1?: QueryKey | TFilters, arg2?: TFilters | TOptions, arg3?: TOptions): [TFilters, TOptions | undefined];
67export declare function parseMutationFilterArgs(arg1?: QueryKey | MutationFilters, arg2?: MutationFilters): MutationFilters | undefined;
68export declare function mapQueryStatusFilter(active?: boolean, inactive?: boolean): QueryStatusFilter;
69export declare function matchQuery(filters: QueryFilters, query: Query<any, any, any, any>): boolean;
70export declare function matchMutation(filters: MutationFilters, mutation: Mutation<any, any>): boolean;
71export declare function hashQueryKeyByOptions<TQueryKey extends QueryKey = QueryKey>(queryKey: TQueryKey, options?: QueryOptions<any, any, any, TQueryKey>): string;
72/**
73 * Default query keys hash function.
74 */
75export declare function hashQueryKey(queryKey: QueryKey): string;
76/**
77 * Hashes the value into a stable hash.
78 */
79export declare function stableValueHash(value: any): string;
80/**
81 * Checks if key `b` partially matches with key `a`.
82 */
83export declare function partialMatchKey(a: QueryKey, b: QueryKey): boolean;
84/**
85 * Checks if `b` partially matches with `a`.
86 */
87export declare function partialDeepEqual(a: any, b: any): boolean;
88/**
89 * This function returns `a` if `b` is deeply equal.
90 * If not, it will replace any deeply equal children of `b` with those of `a`.
91 * This can be used for structural sharing between JSON values for example.
92 */
93export declare function replaceEqualDeep<T>(a: unknown, b: T): T;
94/**
95 * Shallow compare objects. Only works with objects that always have the same properties.
96 */
97export declare function shallowEqualObjects<T>(a: T, b: T): boolean;
98export declare function isPlainObject(o: any): o is Object;
99export declare function isQueryKey(value: any): value is QueryKey;
100export declare function isError(value: any): value is Error;
101export declare function sleep(timeout: number): Promise<void>;
102/**
103 * Schedules a microtask.
104 * This can be useful to schedule state updates after rendering.
105 */
106export declare function scheduleMicrotask(callback: () => void): void;
107export declare function getAbortController(): AbortController | undefined;
108
\No newline at end of file