utils.d.ts 4.7 KB

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