@tanstack/query-core 5.0.0-alpha.88 → 5.0.0-alpha.91

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (225) hide show
  1. package/build/legacy/chunk-WPSKCR32.js +39 -0
  2. package/build/legacy/chunk-WPSKCR32.js.map +1 -0
  3. package/build/legacy/focusManager.cjs +7 -5
  4. package/build/legacy/focusManager.cjs.map +1 -1
  5. package/build/legacy/focusManager.js +12 -23
  6. package/build/legacy/focusManager.js.map +1 -1
  7. package/build/legacy/hydration.cjs +2 -0
  8. package/build/legacy/hydration.cjs.map +1 -1
  9. package/build/legacy/hydration.d.cts +1 -1
  10. package/build/legacy/hydration.d.ts +1 -1
  11. package/build/legacy/hydration.js +3 -0
  12. package/build/legacy/hydration.js.map +1 -1
  13. package/build/legacy/index.cjs +18 -16
  14. package/build/legacy/index.cjs.map +1 -1
  15. package/build/legacy/index.d.cts +1 -1
  16. package/build/legacy/index.d.ts +1 -1
  17. package/build/legacy/index.js +18 -15
  18. package/build/legacy/index.js.map +1 -1
  19. package/build/legacy/infiniteQueryBehavior.cjs +3 -1
  20. package/build/legacy/infiniteQueryBehavior.cjs.map +1 -1
  21. package/build/legacy/infiniteQueryBehavior.d.cts +1 -1
  22. package/build/legacy/infiniteQueryBehavior.d.ts +1 -1
  23. package/build/legacy/infiniteQueryBehavior.js +4 -1
  24. package/build/legacy/infiniteQueryBehavior.js.map +1 -1
  25. package/build/legacy/infiniteQueryObserver.cjs +6 -4
  26. package/build/legacy/infiniteQueryObserver.cjs.map +1 -1
  27. package/build/legacy/infiniteQueryObserver.d.cts +1 -1
  28. package/build/legacy/infiniteQueryObserver.d.ts +1 -1
  29. package/build/legacy/infiniteQueryObserver.js +7 -4
  30. package/build/legacy/infiniteQueryObserver.js.map +1 -1
  31. package/build/legacy/mutation.cjs +7 -5
  32. package/build/legacy/mutation.cjs.map +1 -1
  33. package/build/legacy/mutation.d.cts +1 -1
  34. package/build/legacy/mutation.d.ts +1 -1
  35. package/build/legacy/mutation.js +13 -27
  36. package/build/legacy/mutation.js.map +1 -1
  37. package/build/legacy/mutationCache.cjs +8 -6
  38. package/build/legacy/mutationCache.cjs.map +1 -1
  39. package/build/legacy/mutationCache.d.cts +1 -1
  40. package/build/legacy/mutationCache.d.ts +1 -1
  41. package/build/legacy/mutationCache.js +14 -32
  42. package/build/legacy/mutationCache.js.map +1 -1
  43. package/build/legacy/mutationObserver.cjs +8 -6
  44. package/build/legacy/mutationObserver.cjs.map +1 -1
  45. package/build/legacy/mutationObserver.d.cts +1 -1
  46. package/build/legacy/mutationObserver.d.ts +1 -1
  47. package/build/legacy/mutationObserver.js +14 -28
  48. package/build/legacy/mutationObserver.js.map +1 -1
  49. package/build/legacy/notifyManager.cjs +4 -2
  50. package/build/legacy/notifyManager.cjs.map +1 -1
  51. package/build/legacy/notifyManager.js +5 -2
  52. package/build/legacy/notifyManager.js.map +1 -1
  53. package/build/legacy/onlineManager.cjs +7 -5
  54. package/build/legacy/onlineManager.cjs.map +1 -1
  55. package/build/legacy/onlineManager.js +12 -23
  56. package/build/legacy/onlineManager.js.map +1 -1
  57. package/build/legacy/queriesObserver.cjs +9 -7
  58. package/build/legacy/queriesObserver.cjs.map +1 -1
  59. package/build/legacy/queriesObserver.d.cts +1 -1
  60. package/build/legacy/queriesObserver.d.ts +1 -1
  61. package/build/legacy/queriesObserver.js +15 -29
  62. package/build/legacy/queriesObserver.js.map +1 -1
  63. package/build/legacy/query.cjs +8 -6
  64. package/build/legacy/query.cjs.map +1 -1
  65. package/build/legacy/query.d.cts +1 -1
  66. package/build/legacy/query.d.ts +1 -1
  67. package/build/legacy/query.js +14 -28
  68. package/build/legacy/query.js.map +1 -1
  69. package/build/legacy/queryCache.cjs +8 -6
  70. package/build/legacy/queryCache.cjs.map +1 -1
  71. package/build/legacy/queryCache.d.cts +1 -1
  72. package/build/legacy/queryCache.d.ts +1 -1
  73. package/build/legacy/queryCache.js +13 -24
  74. package/build/legacy/queryCache.js.map +1 -1
  75. package/build/legacy/{queryClient-4ba6364e.d.ts → queryClient-7060338a.d.ts} +9 -4
  76. package/build/legacy/{queryClient-d615ed9f.d.ts → queryClient-9264ae39.d.ts} +9 -4
  77. package/build/legacy/queryClient.cjs +11 -9
  78. package/build/legacy/queryClient.cjs.map +1 -1
  79. package/build/legacy/queryClient.d.cts +1 -1
  80. package/build/legacy/queryClient.d.ts +1 -1
  81. package/build/legacy/queryClient.js +18 -36
  82. package/build/legacy/queryClient.js.map +1 -1
  83. package/build/legacy/queryObserver.cjs +14 -9
  84. package/build/legacy/queryObserver.cjs.map +1 -1
  85. package/build/legacy/queryObserver.d.cts +1 -1
  86. package/build/legacy/queryObserver.d.ts +1 -1
  87. package/build/legacy/queryObserver.js +21 -32
  88. package/build/legacy/queryObserver.js.map +1 -1
  89. package/build/legacy/removable.cjs +5 -3
  90. package/build/legacy/removable.cjs.map +1 -1
  91. package/build/legacy/removable.js +10 -21
  92. package/build/legacy/removable.js.map +1 -1
  93. package/build/legacy/retryer.cjs +7 -5
  94. package/build/legacy/retryer.cjs.map +1 -1
  95. package/build/legacy/retryer.d.cts +1 -1
  96. package/build/legacy/retryer.d.ts +1 -1
  97. package/build/legacy/retryer.js +8 -5
  98. package/build/legacy/retryer.js.map +1 -1
  99. package/build/legacy/subscribable.cjs +4 -2
  100. package/build/legacy/subscribable.cjs.map +1 -1
  101. package/build/legacy/subscribable.js +5 -2
  102. package/build/legacy/subscribable.js.map +1 -1
  103. package/build/legacy/types.cjs +2 -0
  104. package/build/legacy/types.cjs.map +1 -1
  105. package/build/legacy/types.d.cts +1 -1
  106. package/build/legacy/types.d.ts +1 -1
  107. package/build/legacy/utils.cjs +3 -1
  108. package/build/legacy/utils.cjs.map +1 -1
  109. package/build/legacy/utils.d.cts +1 -1
  110. package/build/legacy/utils.d.ts +1 -1
  111. package/build/legacy/utils.js +4 -1
  112. package/build/legacy/utils.js.map +1 -1
  113. package/build/modern/focusManager.cjs +7 -5
  114. package/build/modern/focusManager.cjs.map +1 -1
  115. package/build/modern/focusManager.js +6 -5
  116. package/build/modern/focusManager.js.map +1 -1
  117. package/build/modern/hydration.cjs +2 -0
  118. package/build/modern/hydration.cjs.map +1 -1
  119. package/build/modern/hydration.d.cts +1 -1
  120. package/build/modern/hydration.d.ts +1 -1
  121. package/build/modern/hydration.js +1 -0
  122. package/build/modern/hydration.js.map +1 -1
  123. package/build/modern/index.cjs +18 -16
  124. package/build/modern/index.cjs.map +1 -1
  125. package/build/modern/index.d.cts +1 -1
  126. package/build/modern/index.d.ts +1 -1
  127. package/build/modern/index.js +16 -15
  128. package/build/modern/index.js.map +1 -1
  129. package/build/modern/infiniteQueryBehavior.cjs +3 -1
  130. package/build/modern/infiniteQueryBehavior.cjs.map +1 -1
  131. package/build/modern/infiniteQueryBehavior.d.cts +1 -1
  132. package/build/modern/infiniteQueryBehavior.d.ts +1 -1
  133. package/build/modern/infiniteQueryBehavior.js +2 -1
  134. package/build/modern/infiniteQueryBehavior.js.map +1 -1
  135. package/build/modern/infiniteQueryObserver.cjs +6 -4
  136. package/build/modern/infiniteQueryObserver.cjs.map +1 -1
  137. package/build/modern/infiniteQueryObserver.d.cts +1 -1
  138. package/build/modern/infiniteQueryObserver.d.ts +1 -1
  139. package/build/modern/infiniteQueryObserver.js +5 -4
  140. package/build/modern/infiniteQueryObserver.js.map +1 -1
  141. package/build/modern/mutation.cjs +7 -5
  142. package/build/modern/mutation.cjs.map +1 -1
  143. package/build/modern/mutation.d.cts +1 -1
  144. package/build/modern/mutation.d.ts +1 -1
  145. package/build/modern/mutation.js +6 -5
  146. package/build/modern/mutation.js.map +1 -1
  147. package/build/modern/mutationCache.cjs +8 -6
  148. package/build/modern/mutationCache.cjs.map +1 -1
  149. package/build/modern/mutationCache.d.cts +1 -1
  150. package/build/modern/mutationCache.d.ts +1 -1
  151. package/build/modern/mutationCache.js +7 -6
  152. package/build/modern/mutationCache.js.map +1 -1
  153. package/build/modern/mutationObserver.cjs +8 -6
  154. package/build/modern/mutationObserver.cjs.map +1 -1
  155. package/build/modern/mutationObserver.d.cts +1 -1
  156. package/build/modern/mutationObserver.d.ts +1 -1
  157. package/build/modern/mutationObserver.js +7 -6
  158. package/build/modern/mutationObserver.js.map +1 -1
  159. package/build/modern/notifyManager.cjs +4 -2
  160. package/build/modern/notifyManager.cjs.map +1 -1
  161. package/build/modern/notifyManager.js +3 -2
  162. package/build/modern/notifyManager.js.map +1 -1
  163. package/build/modern/onlineManager.cjs +7 -5
  164. package/build/modern/onlineManager.cjs.map +1 -1
  165. package/build/modern/onlineManager.js +6 -5
  166. package/build/modern/onlineManager.js.map +1 -1
  167. package/build/modern/queriesObserver.cjs +8 -6
  168. package/build/modern/queriesObserver.cjs.map +1 -1
  169. package/build/modern/queriesObserver.d.cts +1 -1
  170. package/build/modern/queriesObserver.d.ts +1 -1
  171. package/build/modern/queriesObserver.js +7 -6
  172. package/build/modern/queriesObserver.js.map +1 -1
  173. package/build/modern/query.cjs +8 -6
  174. package/build/modern/query.cjs.map +1 -1
  175. package/build/modern/query.d.cts +1 -1
  176. package/build/modern/query.d.ts +1 -1
  177. package/build/modern/query.js +7 -6
  178. package/build/modern/query.js.map +1 -1
  179. package/build/modern/queryCache.cjs +8 -6
  180. package/build/modern/queryCache.cjs.map +1 -1
  181. package/build/modern/queryCache.d.cts +1 -1
  182. package/build/modern/queryCache.d.ts +1 -1
  183. package/build/modern/queryCache.js +7 -6
  184. package/build/modern/queryCache.js.map +1 -1
  185. package/build/modern/{queryClient-4ba6364e.d.ts → queryClient-7060338a.d.ts} +9 -4
  186. package/build/modern/{queryClient-d615ed9f.d.ts → queryClient-9264ae39.d.ts} +9 -4
  187. package/build/modern/queryClient.cjs +11 -9
  188. package/build/modern/queryClient.cjs.map +1 -1
  189. package/build/modern/queryClient.d.cts +1 -1
  190. package/build/modern/queryClient.d.ts +1 -1
  191. package/build/modern/queryClient.js +10 -9
  192. package/build/modern/queryClient.js.map +1 -1
  193. package/build/modern/queryObserver.cjs +14 -9
  194. package/build/modern/queryObserver.cjs.map +1 -1
  195. package/build/modern/queryObserver.d.cts +1 -1
  196. package/build/modern/queryObserver.d.ts +1 -1
  197. package/build/modern/queryObserver.js +13 -9
  198. package/build/modern/queryObserver.js.map +1 -1
  199. package/build/modern/removable.cjs +5 -3
  200. package/build/modern/removable.cjs.map +1 -1
  201. package/build/modern/removable.js +4 -3
  202. package/build/modern/removable.js.map +1 -1
  203. package/build/modern/retryer.cjs +7 -5
  204. package/build/modern/retryer.cjs.map +1 -1
  205. package/build/modern/retryer.d.cts +1 -1
  206. package/build/modern/retryer.d.ts +1 -1
  207. package/build/modern/retryer.js +6 -5
  208. package/build/modern/retryer.js.map +1 -1
  209. package/build/modern/subscribable.cjs +4 -2
  210. package/build/modern/subscribable.cjs.map +1 -1
  211. package/build/modern/subscribable.js +3 -2
  212. package/build/modern/subscribable.js.map +1 -1
  213. package/build/modern/types.cjs +2 -0
  214. package/build/modern/types.cjs.map +1 -1
  215. package/build/modern/types.d.cts +1 -1
  216. package/build/modern/types.d.ts +1 -1
  217. package/build/modern/utils.cjs +3 -1
  218. package/build/modern/utils.cjs.map +1 -1
  219. package/build/modern/utils.d.cts +1 -1
  220. package/build/modern/utils.d.ts +1 -1
  221. package/build/modern/utils.js +2 -1
  222. package/build/modern/utils.js.map +1 -1
  223. package/package.json +1 -1
  224. package/src/queryObserver.ts +9 -3
  225. package/src/types.ts +17 -5
@@ -1,3 +1,3 @@
1
- export { au as CancelOptions, D as DefaultError, at as DefaultOptions, z as DefaultPageParam, H as DefaultedInfiniteQueryObserverOptions, E as DefaultedQueryObserverOptions, a6 as DefinedQueryObserverResult, K as FetchInfiniteQueryOptions, Z as FetchNextPageOptions, _ as FetchPreviousPageOptions, J as FetchQueryOptions, a0 as FetchStatus, v as GetNextPageParamFunction, G as GetPreviousPageParamFunction, w as InfiniteData, a8 as InfiniteQueryObserverBaseResult, aa as InfiniteQueryObserverLoadingErrorResult, a9 as InfiniteQueryObserverLoadingResult, F as InfiniteQueryObserverOptions, ab as InfiniteQueryObserverRefetchErrorResult, ad as InfiniteQueryObserverResult, ac as InfiniteQueryObserverSuccessResult, A as InfiniteQueryPageParamsOptions, I as InitialDataFunction, X as InvalidateOptions, S as InvalidateQueryFilters, al as MutateFunction, ak as MutateOptions, ah as MutationFunction, ae as MutationKey, ag as MutationMeta, am as MutationObserverBaseResult, ap as MutationObserverErrorResult, an as MutationObserverIdleResult, ao as MutationObserverLoadingResult, aj as MutationObserverOptions, ar as MutationObserverResult, aq as MutationObserverSuccessResult, ai as MutationOptions, af as MutationStatus, N as NetworkMode, ax as NotifyEvent, aw as NotifyEventType, P as PlaceholderDataFunction, t as QueriesPlaceholderDataFunction, as as QueryClientConfig, q as QueryFunction, s as QueryFunctionContext, p as QueryKey, u as QueryKeyHashFunction, x as QueryMeta, a1 as QueryObserverBaseResult, a3 as QueryObserverLoadingErrorResult, a2 as QueryObserverLoadingResult, B as QueryObserverOptions, a4 as QueryObserverRefetchErrorResult, a7 as QueryObserverResult, a5 as QueryObserverSuccessResult, y as QueryOptions, $ as QueryStatus, O as RefetchOptions, V as RefetchQueryFilters, R as Register, Y as ResetOptions, L as ResultOptions, av as SetDataOptions, T as ThrowOnError, W as WithRequired } from './queryClient-d615ed9f.js';
1
+ export { aw as CancelOptions, D as DefaultError, av as DefaultOptions, A as DefaultPageParam, J as DefaultedInfiniteQueryObserverOptions, F as DefaultedQueryObserverOptions, ae as DefinedInfiniteQueryObserverResult, a7 as DefinedQueryObserverResult, L as FetchInfiniteQueryOptions, _ as FetchNextPageOptions, $ as FetchPreviousPageOptions, K as FetchQueryOptions, a1 as FetchStatus, v as GetNextPageParamFunction, G as GetPreviousPageParamFunction, w as InfiniteData, a9 as InfiniteQueryObserverBaseResult, ab as InfiniteQueryObserverLoadingErrorResult, aa as InfiniteQueryObserverLoadingResult, H as InfiniteQueryObserverOptions, ac as InfiniteQueryObserverRefetchErrorResult, af as InfiniteQueryObserverResult, ad as InfiniteQueryObserverSuccessResult, B as InfiniteQueryPageParamsOptions, I as InitialDataFunction, Y as InvalidateOptions, V as InvalidateQueryFilters, an as MutateFunction, am as MutateOptions, aj as MutationFunction, ag as MutationKey, ai as MutationMeta, ao as MutationObserverBaseResult, ar as MutationObserverErrorResult, ap as MutationObserverIdleResult, aq as MutationObserverLoadingResult, al as MutationObserverOptions, at as MutationObserverResult, as as MutationObserverSuccessResult, ak as MutationOptions, ah as MutationStatus, N as NetworkMode, az as NotifyEvent, ay as NotifyEventType, y as NotifyOnChangeProps, P as PlaceholderDataFunction, t as QueriesPlaceholderDataFunction, au as QueryClientConfig, q as QueryFunction, s as QueryFunctionContext, p as QueryKey, u as QueryKeyHashFunction, x as QueryMeta, a2 as QueryObserverBaseResult, a4 as QueryObserverLoadingErrorResult, a3 as QueryObserverLoadingResult, E as QueryObserverOptions, a5 as QueryObserverRefetchErrorResult, a8 as QueryObserverResult, a6 as QueryObserverSuccessResult, z as QueryOptions, a0 as QueryStatus, S as RefetchOptions, X as RefetchQueryFilters, R as Register, Z as ResetOptions, O as ResultOptions, ax as SetDataOptions, T as ThrowOnError, W as WithRequired } from './queryClient-9264ae39.js';
2
2
  import './removable.js';
3
3
  import './subscribable.js';
@@ -16,6 +16,8 @@ var __copyProps = (to, from, except, desc) => {
16
16
  return to;
17
17
  };
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/utils.ts
19
21
  var utils_exports = {};
20
22
  __export(utils_exports, {
21
23
  addToEnd: () => addToEnd,
@@ -40,7 +42,7 @@ __export(utils_exports, {
40
42
  timeUntilStale: () => timeUntilStale
41
43
  });
42
44
  module.exports = __toCommonJS(utils_exports);
43
- const isServer = typeof window === "undefined" || "Deno" in window;
45
+ var isServer = typeof window === "undefined" || "Deno" in window;
44
46
  function noop() {
45
47
  return void 0;
46
48
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/utils.ts"],"sourcesContent":["import type { Mutation } from './mutation'\nimport type { Query } from './query'\nimport type {\n FetchStatus,\n MutationKey,\n MutationStatus,\n QueryKey,\n QueryOptions,\n} from './types'\n\n// TYPES\n\nexport interface QueryFilters {\n /**\n * Filter to active queries, inactive queries or all queries\n */\n type?: QueryTypeFilter\n /**\n * Match query key exactly\n */\n exact?: boolean\n /**\n * Include queries matching this predicate function\n */\n predicate?: (query: Query) => boolean\n /**\n * Include queries matching this query key\n */\n queryKey?: QueryKey\n /**\n * Include or exclude stale queries\n */\n stale?: boolean\n /**\n * Include queries matching their fetchStatus\n */\n fetchStatus?: FetchStatus\n}\n\nexport interface MutationFilters {\n /**\n * Match mutation key exactly\n */\n exact?: boolean\n /**\n * Include mutations matching this predicate function\n */\n predicate?: (mutation: Mutation<any, any, any>) => boolean\n /**\n * Include mutations matching this mutation key\n */\n mutationKey?: MutationKey\n /**\n * Filter by mutation status\n */\n status?: MutationStatus\n}\n\nexport type DataUpdateFunction<TInput, TOutput> = (input: TInput) => TOutput\n\nexport type Updater<TInput, TOutput> =\n | TOutput\n | DataUpdateFunction<TInput, TOutput>\n\nexport type QueryTypeFilter = 'all' | 'active' | 'inactive'\n\n// UTILS\n\nexport const isServer = typeof window === 'undefined' || 'Deno' in window\n\nexport function noop(): undefined {\n return undefined\n}\n\nexport function functionalUpdate<TInput, TOutput>(\n updater: Updater<TInput, TOutput>,\n input: TInput,\n): TOutput {\n return typeof updater === 'function'\n ? (updater as DataUpdateFunction<TInput, TOutput>)(input)\n : updater\n}\n\nexport function isValidTimeout(value: unknown): value is number {\n return typeof value === 'number' && value >= 0 && value !== Infinity\n}\n\nexport function timeUntilStale(updatedAt: number, staleTime?: number): number {\n return Math.max(updatedAt + (staleTime || 0) - Date.now(), 0)\n}\n\nexport function matchQuery(\n filters: QueryFilters,\n query: Query<any, any, any, any>,\n): boolean {\n const {\n type = 'all',\n exact,\n fetchStatus,\n predicate,\n queryKey,\n stale,\n } = filters\n\n if (queryKey) {\n if (exact) {\n if (query.queryHash !== hashQueryKeyByOptions(queryKey, query.options)) {\n return false\n }\n } else if (!partialMatchKey(query.queryKey, queryKey)) {\n return false\n }\n }\n\n if (type !== 'all') {\n const isActive = query.isActive()\n if (type === 'active' && !isActive) {\n return false\n }\n if (type === 'inactive' && isActive) {\n return false\n }\n }\n\n if (typeof stale === 'boolean' && query.isStale() !== stale) {\n return false\n }\n\n if (\n typeof fetchStatus !== 'undefined' &&\n fetchStatus !== query.state.fetchStatus\n ) {\n return false\n }\n\n if (predicate && !predicate(query)) {\n return false\n }\n\n return true\n}\n\nexport function matchMutation(\n filters: MutationFilters,\n mutation: Mutation<any, any>,\n): boolean {\n const { exact, status, predicate, mutationKey } = filters\n if (mutationKey) {\n if (!mutation.options.mutationKey) {\n return false\n }\n if (exact) {\n if (hashKey(mutation.options.mutationKey) !== hashKey(mutationKey)) {\n return false\n }\n } else if (!partialMatchKey(mutation.options.mutationKey, mutationKey)) {\n return false\n }\n }\n\n if (status && mutation.state.status !== status) {\n return false\n }\n\n if (predicate && !predicate(mutation)) {\n return false\n }\n\n return true\n}\n\nexport function hashQueryKeyByOptions<TQueryKey extends QueryKey = QueryKey>(\n queryKey: TQueryKey,\n options?: QueryOptions<any, any, any, TQueryKey>,\n): string {\n const hashFn = options?.queryKeyHashFn || hashKey\n return hashFn(queryKey)\n}\n\n/**\n * Default query & mutation keys hash function.\n * Hashes the value into a stable hash.\n */\nexport function hashKey(queryKey: QueryKey | MutationKey): string {\n return JSON.stringify(queryKey, (_, val) =>\n isPlainObject(val)\n ? Object.keys(val)\n .sort()\n .reduce((result, key) => {\n result[key] = val[key]\n return result\n }, {} as any)\n : val,\n )\n}\n\n/**\n * Checks if key `b` partially matches with key `a`.\n */\nexport function partialMatchKey(a: QueryKey, b: QueryKey): boolean\nexport function partialMatchKey(a: any, b: any): boolean {\n if (a === b) {\n return true\n }\n\n if (typeof a !== typeof b) {\n return false\n }\n\n if (a && b && typeof a === 'object' && typeof b === 'object') {\n return !Object.keys(b).some((key) => !partialMatchKey(a[key], b[key]))\n }\n\n return false\n}\n\n/**\n * This function returns `a` if `b` is deeply equal.\n * If not, it will replace any deeply equal children of `b` with those of `a`.\n * This can be used for structural sharing between JSON values for example.\n */\nexport function replaceEqualDeep<T>(a: unknown, b: T): T\nexport function replaceEqualDeep(a: any, b: any): any {\n if (a === b) {\n return a\n }\n\n const array = isPlainArray(a) && isPlainArray(b)\n\n if (array || (isPlainObject(a) && isPlainObject(b))) {\n const aSize = array ? a.length : Object.keys(a).length\n const bItems = array ? b : Object.keys(b)\n const bSize = bItems.length\n const copy: any = array ? [] : {}\n\n let equalItems = 0\n\n for (let i = 0; i < bSize; i++) {\n const key = array ? i : bItems[i]\n copy[key] = replaceEqualDeep(a[key], b[key])\n if (copy[key] === a[key]) {\n equalItems++\n }\n }\n\n return aSize === bSize && equalItems === aSize ? a : copy\n }\n\n return b\n}\n\n/**\n * Shallow compare objects. Only works with objects that always have the same properties.\n */\nexport function shallowEqualObjects<T>(a: T, b: T): boolean {\n if ((a && !b) || (b && !a)) {\n return false\n }\n\n for (const key in a) {\n if (a[key] !== b[key]) {\n return false\n }\n }\n\n return true\n}\n\nexport function isPlainArray(value: unknown) {\n return Array.isArray(value) && value.length === Object.keys(value).length\n}\n\n// Copied from: https://github.com/jonschlinkert/is-plain-object\nexport function isPlainObject(o: any): o is Object {\n if (!hasObjectPrototype(o)) {\n return false\n }\n\n // If has modified constructor\n const ctor = o.constructor\n if (typeof ctor === 'undefined') {\n return true\n }\n\n // If has modified prototype\n const prot = ctor.prototype\n if (!hasObjectPrototype(prot)) {\n return false\n }\n\n // If constructor does not have an Object-specific method\n if (!prot.hasOwnProperty('isPrototypeOf')) {\n return false\n }\n\n // Most likely a plain Object\n return true\n}\n\nfunction hasObjectPrototype(o: any): boolean {\n return Object.prototype.toString.call(o) === '[object Object]'\n}\n\nexport function sleep(timeout: number): Promise<void> {\n return new Promise((resolve) => {\n setTimeout(resolve, timeout)\n })\n}\n\n/**\n * Schedules a microtask.\n * This can be useful to schedule state updates after rendering.\n */\nexport function scheduleMicrotask(callback: () => void) {\n sleep(0).then(callback)\n}\n\nexport function replaceData<\n TData,\n TOptions extends QueryOptions<any, any, any, any>,\n>(prevData: TData | undefined, data: TData, options: TOptions): TData {\n if (typeof options.structuralSharing === 'function') {\n return options.structuralSharing(prevData, data)\n } else if (options.structuralSharing !== false) {\n // Structurally share data between prev and new data if needed\n return replaceEqualDeep(prevData, data)\n }\n return data\n}\n\nexport function keepPreviousData<T>(\n previousData: T | undefined,\n): T | undefined {\n return previousData\n}\n\nexport function addToEnd<T>(items: T[], item: T, max = 0): T[] {\n const newItems = [...items, item]\n return max && newItems.length > max ? newItems.slice(1) : newItems\n}\n\nexport function addToStart<T>(items: T[], item: T, max = 0): T[] {\n const newItems = [item, ...items]\n return max && newItems.length > max ? newItems.slice(0, -1) : newItems\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAoEO,MAAM,WAAW,OAAO,WAAW,eAAe,UAAU;AAE5D,SAAS,OAAkB;AAChC,SAAO;AACT;AAEO,SAAS,iBACd,SACA,OACS;AACT,SAAO,OAAO,YAAY,aACrB,QAAgD,KAAK,IACtD;AACN;AAEO,SAAS,eAAe,OAAiC;AAC9D,SAAO,OAAO,UAAU,YAAY,SAAS,KAAK,UAAU;AAC9D;AAEO,SAAS,eAAe,WAAmB,WAA4B;AAC5E,SAAO,KAAK,IAAI,aAAa,aAAa,KAAK,KAAK,IAAI,GAAG,CAAC;AAC9D;AAEO,SAAS,WACd,SACA,OACS;AACT,QAAM;AAAA,IACJ,OAAO;AAAA,IACP;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,IAAI;AAEJ,MAAI,UAAU;AACZ,QAAI,OAAO;AACT,UAAI,MAAM,cAAc,sBAAsB,U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WAAW,CAAC,GAAG,OAAO,IAAI;AAChC,SAAO,OAAO,SAAS,SAAS,MAAM,SAAS,MAAM,CAAC,IAAI;AAC5D;AAEO,SAAS,WAAc,OAAY,MAAS,MAAM,GAAQ;AAC/D,QAAM,WAAW,CAAC,MAAM,GAAG,KAAK;AAChC,SAAO,OAAO,SAAS,SAAS,MAAM,SAAS,MAAM,GAAG,EAAE,IAAI;AAChE;","names":[]}
1
+ {"version":3,"sources":["../../src/utils.ts"],"sourcesContent":["import type { Mutation } from './mutation'\nimport type { Query } from './query'\nimport type {\n FetchStatus,\n MutationKey,\n MutationStatus,\n QueryKey,\n QueryOptions,\n} from './types'\n\n// TYPES\n\nexport interface QueryFilters {\n /**\n * Filter to active queries, inactive queries or all queries\n */\n type?: QueryTypeFilter\n /**\n * Match query key exactly\n */\n exact?: boolean\n /**\n * Include queries matching this predicate function\n */\n predicate?: (query: Query) => boolean\n /**\n * Include queries matching this query key\n */\n queryKey?: QueryKey\n /**\n * Include or exclude stale queries\n */\n stale?: boolean\n /**\n * Include queries matching their fetchStatus\n */\n fetchStatus?: FetchStatus\n}\n\nexport interface MutationFilters {\n /**\n * Match mutation key exactly\n */\n exact?: boolean\n /**\n * Include mutations matching this predicate function\n */\n predicate?: (mutation: Mutation<any, any, any>) => boolean\n /**\n * Include mutations matching this mutation key\n */\n mutationKey?: MutationKey\n /**\n * Filter by mutation status\n */\n status?: MutationStatus\n}\n\nexport type DataUpdateFunction<TInput, TOutput> = (input: TInput) => TOutput\n\nexport type Updater<TInput, TOutput> =\n | TOutput\n | DataUpdateFunction<TInput, TOutput>\n\nexport type QueryTypeFilter = 'all' | 'active' | 'inactive'\n\n// UTILS\n\nexport const isServer = typeof window === 'undefined' || 'Deno' in window\n\nexport function noop(): undefined {\n return undefined\n}\n\nexport function functionalUpdate<TInput, TOutput>(\n updater: Updater<TInput, TOutput>,\n input: TInput,\n): TOutput {\n return typeof updater === 'function'\n ? (updater as DataUpdateFunction<TInput, TOutput>)(input)\n : updater\n}\n\nexport function isValidTimeout(value: unknown): value is number {\n return typeof value === 'number' && value >= 0 && value !== Infinity\n}\n\nexport function timeUntilStale(updatedAt: number, staleTime?: number): number {\n return Math.max(updatedAt + (staleTime || 0) - Date.now(), 0)\n}\n\nexport function matchQuery(\n filters: QueryFilters,\n query: Query<any, any, any, any>,\n): boolean {\n const {\n type = 'all',\n exact,\n fetchStatus,\n predicate,\n queryKey,\n stale,\n } = filters\n\n if (queryKey) {\n if (exact) {\n if (query.queryHash !== hashQueryKeyByOptions(queryKey, query.options)) {\n return false\n }\n } else if (!partialMatchKey(query.queryKey, queryKey)) {\n return false\n }\n }\n\n if (type !== 'all') {\n const isActive = query.isActive()\n if (type === 'active' && !isActive) {\n return false\n }\n if (type === 'inactive' && isActive) {\n return false\n }\n }\n\n if (typeof stale === 'boolean' && query.isStale() !== stale) {\n return false\n }\n\n if (\n typeof fetchStatus !== 'undefined' &&\n fetchStatus !== query.state.fetchStatus\n ) {\n return false\n }\n\n if (predicate && !predicate(query)) {\n return false\n }\n\n return true\n}\n\nexport function matchMutation(\n filters: MutationFilters,\n mutation: Mutation<any, any>,\n): boolean {\n const { exact, status, predicate, mutationKey } = filters\n if (mutationKey) {\n if (!mutation.options.mutationKey) {\n return false\n }\n if (exact) {\n if (hashKey(mutation.options.mutationKey) !== hashKey(mutationKey)) {\n return false\n }\n } else if (!partialMatchKey(mutation.options.mutationKey, mutationKey)) {\n return false\n }\n }\n\n if (status && mutation.state.status !== status) {\n return false\n }\n\n if (predicate && !predicate(mutation)) {\n return false\n }\n\n return true\n}\n\nexport function hashQueryKeyByOptions<TQueryKey extends QueryKey = QueryKey>(\n queryKey: TQueryKey,\n options?: QueryOptions<any, any, any, TQueryKey>,\n): string {\n const hashFn = options?.queryKeyHashFn || hashKey\n return hashFn(queryKey)\n}\n\n/**\n * Default query & mutation keys hash function.\n * Hashes the value into a stable hash.\n */\nexport function hashKey(queryKey: QueryKey | MutationKey): string {\n return JSON.stringify(queryKey, (_, val) =>\n isPlainObject(val)\n ? Object.keys(val)\n .sort()\n .reduce((result, key) => {\n result[key] = val[key]\n return result\n }, {} as any)\n : val,\n )\n}\n\n/**\n * Checks if key `b` partially matches with key `a`.\n */\nexport function partialMatchKey(a: QueryKey, b: QueryKey): boolean\nexport function partialMatchKey(a: any, b: any): boolean {\n if (a === b) {\n return true\n }\n\n if (typeof a !== typeof b) {\n return false\n }\n\n if (a && b && typeof a === 'object' && typeof b === 'object') {\n return !Object.keys(b).some((key) => !partialMatchKey(a[key], b[key]))\n }\n\n return false\n}\n\n/**\n * This function returns `a` if `b` is deeply equal.\n * If not, it will replace any deeply equal children of `b` with those of `a`.\n * This can be used for structural sharing between JSON values for example.\n */\nexport function replaceEqualDeep<T>(a: unknown, b: T): T\nexport function replaceEqualDeep(a: any, b: any): any {\n if (a === b) {\n return a\n }\n\n const array = isPlainArray(a) && isPlainArray(b)\n\n if (array || (isPlainObject(a) && isPlainObject(b))) {\n const aSize = array ? a.length : Object.keys(a).length\n const bItems = array ? b : Object.keys(b)\n const bSize = bItems.length\n const copy: any = array ? [] : {}\n\n let equalItems = 0\n\n for (let i = 0; i < bSize; i++) {\n const key = array ? i : bItems[i]\n copy[key] = replaceEqualDeep(a[key], b[key])\n if (copy[key] === a[key]) {\n equalItems++\n }\n }\n\n return aSize === bSize && equalItems === aSize ? a : copy\n }\n\n return b\n}\n\n/**\n * Shallow compare objects. Only works with objects that always have the same properties.\n */\nexport function shallowEqualObjects<T>(a: T, b: T): boolean {\n if ((a && !b) || (b && !a)) {\n return false\n }\n\n for (const key in a) {\n if (a[key] !== b[key]) {\n return false\n }\n }\n\n return true\n}\n\nexport function isPlainArray(value: unknown) {\n return Array.isArray(value) && value.length === Object.keys(value).length\n}\n\n// Copied from: https://github.com/jonschlinkert/is-plain-object\nexport function isPlainObject(o: any): o is Object {\n if (!hasObjectPrototype(o)) {\n return false\n }\n\n // If has modified constructor\n const ctor = o.constructor\n if (typeof ctor === 'undefined') {\n return true\n }\n\n // If has modified prototype\n const prot = ctor.prototype\n if (!hasObjectPrototype(prot)) {\n return false\n }\n\n // If constructor does not have an Object-specific method\n if (!prot.hasOwnProperty('isPrototypeOf')) {\n return false\n }\n\n // Most likely a plain Object\n return true\n}\n\nfunction hasObjectPrototype(o: any): boolean {\n return Object.prototype.toString.call(o) === '[object Object]'\n}\n\nexport function sleep(timeout: number): Promise<void> {\n return new Promise((resolve) => {\n setTimeout(resolve, timeout)\n })\n}\n\n/**\n * Schedules a microtask.\n * This can be useful to schedule state updates after rendering.\n */\nexport function scheduleMicrotask(callback: () => void) {\n sleep(0).then(callback)\n}\n\nexport function replaceData<\n TData,\n TOptions extends QueryOptions<any, any, any, any>,\n>(prevData: TData | undefined, data: TData, options: TOptions): TData {\n if (typeof options.structuralSharing === 'function') {\n return options.structuralSharing(prevData, data)\n } else if (options.structuralSharing !== false) {\n // Structurally share data between prev and new data if needed\n return replaceEqualDeep(prevData, data)\n }\n return data\n}\n\nexport function keepPreviousData<T>(\n previousData: T | undefined,\n): T | undefined {\n return previousData\n}\n\nexport function addToEnd<T>(items: T[], item: T, max = 0): T[] {\n const newItems = [...items, item]\n return max && newItems.length > max ? newItems.slice(1) : newItems\n}\n\nexport function addToStart<T>(items: T[], item: T, max = 0): T[] {\n const newItems = [item, ...items]\n return max && newItems.length > max ? newItems.slice(0, -1) : newItems\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAoEO,IAAM,WAAW,OAAO,WAAW,eAAe,UAAU;AAE5D,SAAS,OAAkB;AAChC,SAAO;AACT;AAEO,SAAS,iBACd,SACA,OACS;AACT,SAAO,OAAO,YAAY,aACrB,QAAgD,KAAK,IACtD;AACN;AAEO,SAAS,eAAe,OAAiC;AAC9D,SAAO,OAAO,UAAU,YAAY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K,QAAQ;AACxB;AAEO,SAAS,YAGd,UAA6B,MAAa,SAA0B;AACpE,MAAI,OAAO,QAAQ,sBAAsB,YAAY;AACnD,WAAO,QAAQ,kBAAkB,UAAU,IAAI;AAAA,EACjD,WAAW,QAAQ,sBAAsB,OAAO;AAE9C,WAAO,iBAAiB,UAAU,IAAI;AAAA,EACxC;AACA,SAAO;AACT;AAEO,SAAS,iBACd,cACe;AACf,SAAO;AACT;AAEO,SAAS,SAAY,OAAY,MAAS,MAAM,GAAQ;AAC7D,QAAM,WAAW,CAAC,GAAG,OAAO,IAAI;AAChC,SAAO,OAAO,SAAS,SAAS,MAAM,SAAS,MAAM,CAAC,IAAI;AAC5D;AAEO,SAAS,WAAc,OAAY,MAAS,MAAM,GAAQ;AAC/D,QAAM,WAAW,CAAC,MAAM,GAAG,KAAK;AAChC,SAAO,OAAO,SAAS,SAAS,MAAM,SAAS,MAAM,GAAG,EAAE,IAAI;AAChE;","names":[]}
@@ -1,3 +1,3 @@
1
- export { aB as DataUpdateFunction, e as MutationFilters, f as QueryFilters, aC as QueryTypeFilter, U as Updater, aQ as addToEnd, aR as addToStart, aE as functionalUpdate, h as hashKey, aI as hashQueryKeyByOptions, aL as isPlainArray, aM as isPlainObject, i as isServer, aF as isValidTimeout, k as keepPreviousData, aH as matchMutation, m as matchQuery, aD as noop, aJ as partialMatchKey, aP as replaceData, r as replaceEqualDeep, aO as scheduleMicrotask, aK as shallowEqualObjects, aN as sleep, aG as timeUntilStale } from './queryClient-4ba6364e.js';
1
+ export { aD as DataUpdateFunction, e as MutationFilters, f as QueryFilters, aE as QueryTypeFilter, U as Updater, aS as addToEnd, aT as addToStart, aG as functionalUpdate, h as hashKey, aK as hashQueryKeyByOptions, aN as isPlainArray, aO as isPlainObject, i as isServer, aH as isValidTimeout, k as keepPreviousData, aJ as matchMutation, m as matchQuery, aF as noop, aL as partialMatchKey, aR as replaceData, r as replaceEqualDeep, aQ as scheduleMicrotask, aM as shallowEqualObjects, aP as sleep, aI as timeUntilStale } from './queryClient-7060338a.js';
2
2
  import './removable.cjs';
3
3
  import './subscribable.cjs';
@@ -1,3 +1,3 @@
1
- export { aB as DataUpdateFunction, e as MutationFilters, f as QueryFilters, aC as QueryTypeFilter, U as Updater, aQ as addToEnd, aR as addToStart, aE as functionalUpdate, h as hashKey, aI as hashQueryKeyByOptions, aL as isPlainArray, aM as isPlainObject, i as isServer, aF as isValidTimeout, k as keepPreviousData, aH as matchMutation, m as matchQuery, aD as noop, aJ as partialMatchKey, aP as replaceData, r as replaceEqualDeep, aO as scheduleMicrotask, aK as shallowEqualObjects, aN as sleep, aG as timeUntilStale } from './queryClient-d615ed9f.js';
1
+ export { aD as DataUpdateFunction, e as MutationFilters, f as QueryFilters, aE as QueryTypeFilter, U as Updater, aS as addToEnd, aT as addToStart, aG as functionalUpdate, h as hashKey, aK as hashQueryKeyByOptions, aN as isPlainArray, aO as isPlainObject, i as isServer, aH as isValidTimeout, k as keepPreviousData, aJ as matchMutation, m as matchQuery, aF as noop, aL as partialMatchKey, aR as replaceData, r as replaceEqualDeep, aQ as scheduleMicrotask, aM as shallowEqualObjects, aP as sleep, aI as timeUntilStale } from './queryClient-9264ae39.js';
2
2
  import './removable.js';
3
3
  import './subscribable.js';
@@ -1,4 +1,5 @@
1
- const isServer = typeof window === "undefined" || "Deno" in window;
1
+ // src/utils.ts
2
+ var isServer = typeof window === "undefined" || "Deno" in window;
2
3
  function noop() {
3
4
  return void 0;
4
5
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/utils.ts"],"sourcesContent":["import type { Mutation } from './mutation'\nimport type { Query } from './query'\nimport type {\n FetchStatus,\n MutationKey,\n MutationStatus,\n QueryKey,\n QueryOptions,\n} from './types'\n\n// TYPES\n\nexport interface QueryFilters {\n /**\n * Filter to active queries, inactive queries or all queries\n */\n type?: QueryTypeFilter\n /**\n * Match query key exactly\n */\n exact?: boolean\n /**\n * Include queries matching this predicate function\n */\n predicate?: (query: Query) => boolean\n /**\n * Include queries matching this query key\n */\n queryKey?: QueryKey\n /**\n * Include or exclude stale queries\n */\n stale?: boolean\n /**\n * Include queries matching their fetchStatus\n */\n fetchStatus?: FetchStatus\n}\n\nexport interface MutationFilters {\n /**\n * Match mutation key exactly\n */\n exact?: boolean\n /**\n * Include mutations matching this predicate function\n */\n predicate?: (mutation: Mutation<any, any, any>) => boolean\n /**\n * Include mutations matching this mutation key\n */\n mutationKey?: MutationKey\n /**\n * Filter by mutation status\n */\n status?: MutationStatus\n}\n\nexport type DataUpdateFunction<TInput, TOutput> = (input: TInput) => TOutput\n\nexport type Updater<TInput, TOutput> =\n | TOutput\n | DataUpdateFunction<TInput, TOutput>\n\nexport type QueryTypeFilter = 'all' | 'active' | 'inactive'\n\n// UTILS\n\nexport const isServer = typeof window === 'undefined' || 'Deno' in window\n\nexport function noop(): undefined {\n return undefined\n}\n\nexport function functionalUpdate<TInput, TOutput>(\n updater: Updater<TInput, TOutput>,\n input: TInput,\n): TOutput {\n return typeof updater === 'function'\n ? (updater as DataUpdateFunction<TInput, TOutput>)(input)\n : updater\n}\n\nexport function isValidTimeout(value: unknown): value is number {\n return typeof value === 'number' && value >= 0 && value !== Infinity\n}\n\nexport function timeUntilStale(updatedAt: number, staleTime?: number): number {\n return Math.max(updatedAt + (staleTime || 0) - Date.now(), 0)\n}\n\nexport function matchQuery(\n filters: QueryFilters,\n query: Query<any, any, any, any>,\n): boolean {\n const {\n type = 'all',\n exact,\n fetchStatus,\n predicate,\n queryKey,\n stale,\n } = filters\n\n if (queryKey) {\n if (exact) {\n if (query.queryHash !== hashQueryKeyByOptions(queryKey, query.options)) {\n return false\n }\n } else if (!partialMatchKey(query.queryKey, queryKey)) {\n return false\n }\n }\n\n if (type !== 'all') {\n const isActive = query.isActive()\n if (type === 'active' && !isActive) {\n return false\n }\n if (type === 'inactive' && isActive) {\n return false\n }\n }\n\n if (typeof stale === 'boolean' && query.isStale() !== stale) {\n return false\n }\n\n if (\n typeof fetchStatus !== 'undefined' &&\n fetchStatus !== query.state.fetchStatus\n ) {\n return false\n }\n\n if (predicate && !predicate(query)) {\n return false\n }\n\n return true\n}\n\nexport function matchMutation(\n filters: MutationFilters,\n mutation: Mutation<any, any>,\n): boolean {\n const { exact, status, predicate, mutationKey } = filters\n if (mutationKey) {\n if (!mutation.options.mutationKey) {\n return false\n }\n if (exact) {\n if (hashKey(mutation.options.mutationKey) !== hashKey(mutationKey)) {\n return false\n }\n } else if (!partialMatchKey(mutation.options.mutationKey, mutationKey)) {\n return false\n }\n }\n\n if (status && mutation.state.status !== status) {\n return false\n }\n\n if (predicate && !predicate(mutation)) {\n return false\n }\n\n return true\n}\n\nexport function hashQueryKeyByOptions<TQueryKey extends QueryKey = QueryKey>(\n queryKey: TQueryKey,\n options?: QueryOptions<any, any, any, TQueryKey>,\n): string {\n const hashFn = options?.queryKeyHashFn || hashKey\n return hashFn(queryKey)\n}\n\n/**\n * Default query & mutation keys hash function.\n * Hashes the value into a stable hash.\n */\nexport function hashKey(queryKey: QueryKey | MutationKey): string {\n return JSON.stringify(queryKey, (_, val) =>\n isPlainObject(val)\n ? Object.keys(val)\n .sort()\n .reduce((result, key) => {\n result[key] = val[key]\n return result\n }, {} as any)\n : val,\n )\n}\n\n/**\n * Checks if key `b` partially matches with key `a`.\n */\nexport function partialMatchKey(a: QueryKey, b: QueryKey): boolean\nexport function partialMatchKey(a: any, b: any): boolean {\n if (a === b) {\n return true\n }\n\n if (typeof a !== typeof b) {\n return false\n }\n\n if (a && b && typeof a === 'object' && typeof b === 'object') {\n return !Object.keys(b).some((key) => !partialMatchKey(a[key], b[key]))\n }\n\n return false\n}\n\n/**\n * This function returns `a` if `b` is deeply equal.\n * If not, it will replace any deeply equal children of `b` with those of `a`.\n * This can be used for structural sharing between JSON values for example.\n */\nexport function replaceEqualDeep<T>(a: unknown, b: T): T\nexport function replaceEqualDeep(a: any, b: any): any {\n if (a === b) {\n return a\n }\n\n const array = isPlainArray(a) && isPlainArray(b)\n\n if (array || (isPlainObject(a) && isPlainObject(b))) {\n const aSize = array ? a.length : Object.keys(a).length\n const bItems = array ? b : Object.keys(b)\n const bSize = bItems.length\n const copy: any = array ? [] : {}\n\n let equalItems = 0\n\n for (let i = 0; i < bSize; i++) {\n const key = array ? i : bItems[i]\n copy[key] = replaceEqualDeep(a[key], b[key])\n if (copy[key] === a[key]) {\n equalItems++\n }\n }\n\n return aSize === bSize && equalItems === aSize ? a : copy\n }\n\n return b\n}\n\n/**\n * Shallow compare objects. Only works with objects that always have the same properties.\n */\nexport function shallowEqualObjects<T>(a: T, b: T): boolean {\n if ((a && !b) || (b && !a)) {\n return false\n }\n\n for (const key in a) {\n if (a[key] !== b[key]) {\n return false\n }\n }\n\n return true\n}\n\nexport function isPlainArray(value: unknown) {\n return Array.isArray(value) && value.length === Object.keys(value).length\n}\n\n// Copied from: https://github.com/jonschlinkert/is-plain-object\nexport function isPlainObject(o: any): o is Object {\n if (!hasObjectPrototype(o)) {\n return false\n }\n\n // If has modified constructor\n const ctor = o.constructor\n if (typeof ctor === 'undefined') {\n return true\n }\n\n // If has modified prototype\n const prot = ctor.prototype\n if (!hasObjectPrototype(prot)) {\n return false\n }\n\n // If constructor does not have an Object-specific method\n if (!prot.hasOwnProperty('isPrototypeOf')) {\n return false\n }\n\n // Most likely a plain Object\n return true\n}\n\nfunction hasObjectPrototype(o: any): boolean {\n return Object.prototype.toString.call(o) === '[object Object]'\n}\n\nexport function sleep(timeout: number): Promise<void> {\n return new Promise((resolve) => {\n setTimeout(resolve, timeout)\n })\n}\n\n/**\n * Schedules a microtask.\n * This can be useful to schedule state updates after rendering.\n */\nexport function scheduleMicrotask(callback: () => void) {\n sleep(0).then(callback)\n}\n\nexport function replaceData<\n TData,\n TOptions extends QueryOptions<any, any, any, any>,\n>(prevData: TData | undefined, data: TData, options: TOptions): TData {\n if (typeof options.structuralSharing === 'function') {\n return options.structuralSharing(prevData, data)\n } else if (options.structuralSharing !== false) {\n // Structurally share data between prev and new data if needed\n return replaceEqualDeep(prevData, data)\n }\n return data\n}\n\nexport function keepPreviousData<T>(\n previousData: T | undefined,\n): T | undefined {\n return previousData\n}\n\nexport function addToEnd<T>(items: T[], item: T, max = 0): T[] {\n const newItems = [...items, item]\n return max && newItems.length > max ? newItems.slice(1) : newItems\n}\n\nexport function addToStart<T>(items: T[], item: T, max = 0): T[] {\n const newItems = [item, ...items]\n return max && newItems.length > max ? newItems.slice(0, -1) : newItems\n}\n"],"mappings":"AAoEO,MAAM,WAAW,OAAO,WAAW,eAAe,UAAU;AAE5D,SAAS,OAAkB;AAChC,SAAO;AACT;AAEO,SAAS,iBACd,SACA,OACS;AACT,SAAO,OAAO,YAAY,aACrB,QAAgD,KAAK,IACtD;AACN;AAEO,SAAS,eAAe,OAAiC;AAC9D,SAAO,OAAO,UAAU,YAAY,SAAS,KAAK,UAAU;AAC9D;AAEO,SAAS,eAAe,WAAmB,WAA4B;AAC5E,SAAO,KAAK,IAAI,aAAa,aAAa,KAAK,KAAK,IAAI,GAAG,CAAC;AAC9D;AAEO,SAAS,WACd,SACA,OACS;AACT,QAAM;AAAA,IACJ,OAAO;AAAA,IACP;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,IAAI;AAEJ,MAAI,UAAU;AACZ,QAAI,OAAO;AACT,UAAI,MAAM,cAAc,sBAAsB,UAAU,MAAM,OAAO,GAAG;AACtE,eAAO;AAAA,MACT;AAAA,IACF,WAAW,CAAC,gBAAgB,MAAM,UAAU,QAAQ,GAAG;AACrD,aAAO;AAAA,IACT;AAAA,EACF;AAEA,MAAI,SAAS,OAAO;AAClB,UAAM,WAAW,MAAM,SAAS;AAChC,QAAI,SAAS,YAAY,CAAC,UAAU;AAClC,aAAO;AAAA,IACT;AACA,QAAI,SAAS,cAAc,UAAU;AACnC,aAAO;AAAA,IACT;AAAA,EACF;AAEA,MAAI,OAAO,UAAU,aAAa,MAAM,QAAQ,MAAM,OAAO;AAC3D,WAAO;AAAA,EACT;AAEA,MACE,OAAO,gBA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QAAM,OAAO,EAAE;AACf,MAAI,OAAO,SAAS,aAAa;AAC/B,WAAO;AAAA,EACT;AAGA,QAAM,OAAO,KAAK;AAClB,MAAI,CAAC,mBAAmB,IAAI,GAAG;AAC7B,WAAO;AAAA,EACT;AAGA,MAAI,CAAC,KAAK,eAAe,eAAe,GAAG;AACzC,WAAO;AAAA,EACT;AAGA,SAAO;AACT;AAEA,SAAS,mBAAmB,GAAiB;AAC3C,SAAO,OAAO,UAAU,SAAS,KAAK,CAAC,MAAM;AAC/C;AAEO,SAAS,MAAM,SAAgC;AACpD,SAAO,IAAI,QAAQ,CAAC,YAAY;AAC9B,eAAW,SAAS,OAAO;AAAA,EAC7B,CAAC;AACH;AAMO,SAAS,kBAAkB,UAAsB;AACtD,QAAM,CAAC,EAAE,KAAK,QAAQ;AACxB;AAEO,SAAS,YAGd,UAA6B,MAAa,SAA0B;AACpE,MAAI,OAAO,QAAQ,sBAAsB,YAAY;AACnD,WAAO,QAAQ,kBAAkB,UAAU,IAAI;AAAA,EACjD,WAAW,QAAQ,sBAAsB,OAAO;AAE9C,WAAO,iBAAiB,UAAU,IAAI;AAAA,EACxC;AACA,SAAO;AACT;AAEO,SAAS,iBACd,cACe;AACf,SAAO;AACT;AAEO,SAAS,SAAY,OAAY,MAAS,MAAM,GAAQ;AAC7D,QAAM,WAAW,CAAC,GAAG,OAAO,IAAI;AAChC,SAAO,OAAO,SAAS,SAAS,MAAM,SAAS,MAAM,CAAC,IAAI;AAC5D;AAEO,SAAS,WAAc,OAAY,MAAS,MAAM,GAAQ;AAC/D,QAAM,WAAW,CAAC,MAAM,GAAG,KAAK;AAChC,SAAO,OAAO,SAAS,SAAS,MAAM,SAAS,MAAM,GAAG,EAAE,IAAI;AAChE;","names":[]}
1
+ {"version":3,"sources":["../../src/utils.ts"],"sourcesContent":["import type { Mutation } from './mutation'\nimport type { Query } from './query'\nimport type {\n FetchStatus,\n MutationKey,\n MutationStatus,\n QueryKey,\n QueryOptions,\n} from './types'\n\n// TYPES\n\nexport interface QueryFilters {\n /**\n * Filter to active queries, inactive queries or all queries\n */\n type?: QueryTypeFilter\n /**\n * Match query key exactly\n */\n exact?: boolean\n /**\n * Include queries matching this predicate function\n */\n predicate?: (query: Query) => boolean\n /**\n * Include queries matching this query key\n */\n queryKey?: QueryKey\n /**\n * Include or exclude stale queries\n */\n stale?: boolean\n /**\n * Include queries matching their fetchStatus\n */\n fetchStatus?: FetchStatus\n}\n\nexport interface MutationFilters {\n /**\n * Match mutation key exactly\n */\n exact?: boolean\n /**\n * Include mutations matching this predicate function\n */\n predicate?: (mutation: Mutation<any, any, any>) => boolean\n /**\n * Include mutations matching this mutation key\n */\n mutationKey?: MutationKey\n /**\n * Filter by mutation status\n */\n status?: MutationStatus\n}\n\nexport type DataUpdateFunction<TInput, TOutput> = (input: TInput) => TOutput\n\nexport type Updater<TInput, TOutput> =\n | TOutput\n | DataUpdateFunction<TInput, TOutput>\n\nexport type QueryTypeFilter = 'all' | 'active' | 'inactive'\n\n// UTILS\n\nexport const isServer = typeof window === 'undefined' || 'Deno' in window\n\nexport function noop(): undefined {\n return undefined\n}\n\nexport function functionalUpdate<TInput, TOutput>(\n updater: Updater<TInput, TOutput>,\n input: TInput,\n): TOutput {\n return typeof updater === 'function'\n ? (updater as DataUpdateFunction<TInput, TOutput>)(input)\n : updater\n}\n\nexport function isValidTimeout(value: unknown): value is number {\n return typeof value === 'number' && value >= 0 && value !== Infinity\n}\n\nexport function timeUntilStale(updatedAt: number, staleTime?: number): number {\n return Math.max(updatedAt + (staleTime || 0) - Date.now(), 0)\n}\n\nexport function matchQuery(\n filters: QueryFilters,\n query: Query<any, any, any, any>,\n): boolean {\n const {\n type = 'all',\n exact,\n fetchStatus,\n predicate,\n queryKey,\n stale,\n } = filters\n\n if (queryKey) {\n if (exact) {\n if (query.queryHash !== hashQueryKeyByOptions(queryKey, query.options)) {\n return false\n }\n } else if (!partialMatchKey(query.queryKey, queryKey)) {\n return false\n }\n }\n\n if (type !== 'all') {\n const isActive = query.isActive()\n if (type === 'active' && !isActive) {\n return false\n }\n if (type === 'inactive' && isActive) {\n return false\n }\n }\n\n if (typeof stale === 'boolean' && query.isStale() !== stale) {\n return false\n }\n\n if (\n typeof fetchStatus !== 'undefined' &&\n fetchStatus !== query.state.fetchStatus\n ) {\n return false\n }\n\n if (predicate && !predicate(query)) {\n return false\n }\n\n return true\n}\n\nexport function matchMutation(\n filters: MutationFilters,\n mutation: Mutation<any, any>,\n): boolean {\n const { exact, status, predicate, mutationKey } = filters\n if (mutationKey) {\n if (!mutation.options.mutationKey) {\n return false\n }\n if (exact) {\n if (hashKey(mutation.options.mutationKey) !== hashKey(mutationKey)) {\n return false\n }\n } else if (!partialMatchKey(mutation.options.mutationKey, mutationKey)) {\n return false\n }\n }\n\n if (status && mutation.state.status !== status) {\n return false\n }\n\n if (predicate && !predicate(mutation)) {\n return false\n }\n\n return true\n}\n\nexport function hashQueryKeyByOptions<TQueryKey extends QueryKey = QueryKey>(\n queryKey: TQueryKey,\n options?: QueryOptions<any, any, any, TQueryKey>,\n): string {\n const hashFn = options?.queryKeyHashFn || hashKey\n return hashFn(queryKey)\n}\n\n/**\n * Default query & mutation keys hash function.\n * Hashes the value into a stable hash.\n */\nexport function hashKey(queryKey: QueryKey | MutationKey): string {\n return JSON.stringify(queryKey, (_, val) =>\n isPlainObject(val)\n ? Object.keys(val)\n .sort()\n .reduce((result, key) => {\n result[key] = val[key]\n return result\n }, {} as any)\n : val,\n )\n}\n\n/**\n * Checks if key `b` partially matches with key `a`.\n */\nexport function partialMatchKey(a: QueryKey, b: QueryKey): boolean\nexport function partialMatchKey(a: any, b: any): boolean {\n if (a === b) {\n return true\n }\n\n if (typeof a !== typeof b) {\n return false\n }\n\n if (a && b && typeof a === 'object' && typeof b === 'object') {\n return !Object.keys(b).some((key) => !partialMatchKey(a[key], b[key]))\n }\n\n return false\n}\n\n/**\n * This function returns `a` if `b` is deeply equal.\n * If not, it will replace any deeply equal children of `b` with those of `a`.\n * This can be used for structural sharing between JSON values for example.\n */\nexport function replaceEqualDeep<T>(a: unknown, b: T): T\nexport function replaceEqualDeep(a: any, b: any): any {\n if (a === b) {\n return a\n }\n\n const array = isPlainArray(a) && isPlainArray(b)\n\n if (array || (isPlainObject(a) && isPlainObject(b))) {\n const aSize = array ? a.length : Object.keys(a).length\n const bItems = array ? b : Object.keys(b)\n const bSize = bItems.length\n const copy: any = array ? [] : {}\n\n let equalItems = 0\n\n for (let i = 0; i < bSize; i++) {\n const key = array ? i : bItems[i]\n copy[key] = replaceEqualDeep(a[key], b[key])\n if (copy[key] === a[key]) {\n equalItems++\n }\n }\n\n return aSize === bSize && equalItems === aSize ? a : copy\n }\n\n return b\n}\n\n/**\n * Shallow compare objects. Only works with objects that always have the same properties.\n */\nexport function shallowEqualObjects<T>(a: T, b: T): boolean {\n if ((a && !b) || (b && !a)) {\n return false\n }\n\n for (const key in a) {\n if (a[key] !== b[key]) {\n return false\n }\n }\n\n return true\n}\n\nexport function isPlainArray(value: unknown) {\n return Array.isArray(value) && value.length === Object.keys(value).length\n}\n\n// Copied from: https://github.com/jonschlinkert/is-plain-object\nexport function isPlainObject(o: any): o is Object {\n if (!hasObjectPrototype(o)) {\n return false\n }\n\n // If has modified constructor\n const ctor = o.constructor\n if (typeof ctor === 'undefined') {\n return true\n }\n\n // If has modified prototype\n const prot = ctor.prototype\n if (!hasObjectPrototype(prot)) {\n return false\n }\n\n // If constructor does not have an Object-specific method\n if (!prot.hasOwnProperty('isPrototypeOf')) {\n return false\n }\n\n // Most likely a plain Object\n return true\n}\n\nfunction hasObjectPrototype(o: any): boolean {\n return Object.prototype.toString.call(o) === '[object Object]'\n}\n\nexport function sleep(timeout: number): Promise<void> {\n return new Promise((resolve) => {\n setTimeout(resolve, timeout)\n })\n}\n\n/**\n * Schedules a microtask.\n * This can be useful to schedule state updates after rendering.\n */\nexport function scheduleMicrotask(callback: () => void) {\n sleep(0).then(callback)\n}\n\nexport function replaceData<\n TData,\n TOptions extends QueryOptions<any, any, any, any>,\n>(prevData: TData | undefined, data: TData, options: TOptions): TData {\n if (typeof options.structuralSharing === 'function') {\n return options.structuralSharing(prevData, data)\n } else if (options.structuralSharing !== false) {\n // Structurally share data between prev and new data if needed\n return replaceEqualDeep(prevData, data)\n }\n return data\n}\n\nexport function keepPreviousData<T>(\n previousData: T | undefined,\n): T | undefined {\n return previousData\n}\n\nexport function addToEnd<T>(items: T[], item: T, max = 0): T[] {\n const newItems = [...items, item]\n return max && newItems.length > max ? newItems.slice(1) : newItems\n}\n\nexport function addToStart<T>(items: T[], item: T, max = 0): T[] {\n const newItems = [item, ...items]\n return max && newItems.length > max ? newItems.slice(0, -1) : newItems\n}\n"],"mappings":";AAoEO,IAAM,WAAW,OAAO,WAAW,eAAe,UAAU;AAE5D,SAAS,OAAkB;AAChC,SAAO;AACT;AAEO,SAAS,iBACd,SACA,OACS;AACT,SAAO,OAAO,YAAY,aACrB,QAAgD,KAAK,IACtD;AACN;AAEO,SAAS,eAAe,OAAiC;AAC9D,SAAO,OAAO,UAAU,YAAY,SAAS,KAAK,UAAU;AAC9D;AAEO,SAAS,eAAe,WAAmB,WAA4B;AAC5E,SAAO,KAAK,IAAI,aAAa,aAAa,KAAK,KAAK,IAAI,GAAG,CAAC;AAC9D;AAEO,SAAS,WACd,SACA,OACS;AACT,QAAM;AAAA,IACJ,OAAO;AAAA,IACP;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,IAAI;AAEJ,MAAI,UAAU;AACZ,QAAI,OAAO;AACT,UAAI,MAAM,cAAc,sBAAsB,UAAU,MAAM,OAAO,GAAG;AACtE,eAAO;AAAA,MACT;AAAA,IACF,WAAW,CAAC,gBAAgB,MAAM,UAAU,QAAQ,GAAG;AACrD,aAAO;AAAA,IACT;AAAA,EACF;AAEA,MAAI,SAAS,OAAO;AAClB,UAAM,WAAW,MAAM,SAAS;AAChC,QAAI,SAAS,YAAY,CAAC,UAAU;AAClC,aAAO;AAAA,IACT;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;AAChE;","names":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tanstack/query-core",
3
- "version": "5.0.0-alpha.88",
3
+ "version": "5.0.0-alpha.91",
4
4
  "description": "The framework agnostic core that powers TanStack Query",
5
5
  "author": "tannerlinsley",
6
6
  "license": "MIT",
@@ -612,15 +612,21 @@ export class QueryObserver<
612
612
  }
613
613
 
614
614
  const { notifyOnChangeProps } = this.options
615
+ const notifyOnChangePropsValue =
616
+ typeof notifyOnChangeProps === 'function'
617
+ ? notifyOnChangeProps()
618
+ : notifyOnChangeProps
615
619
 
616
620
  if (
617
- notifyOnChangeProps === 'all' ||
618
- (!notifyOnChangeProps && !this.#trackedProps.size)
621
+ notifyOnChangePropsValue === 'all' ||
622
+ (!notifyOnChangePropsValue && !this.#trackedProps.size)
619
623
  ) {
620
624
  return true
621
625
  }
622
626
 
623
- const includedProps = new Set(notifyOnChangeProps ?? this.#trackedProps)
627
+ const includedProps = new Set(
628
+ notifyOnChangePropsValue ?? this.#trackedProps,
629
+ )
624
630
 
625
631
  if (this.options.throwOnError) {
626
632
  includedProps.add('error')
package/src/types.ts CHANGED
@@ -95,6 +95,11 @@ export type QueryMeta = Register extends {
95
95
 
96
96
  export type NetworkMode = 'online' | 'always' | 'offlineFirst'
97
97
 
98
+ export type NotifyOnChangeProps =
99
+ | Array<keyof InfiniteQueryObserverResult>
100
+ | 'all'
101
+ | (() => Array<keyof InfiniteQueryObserverResult> | 'all')
102
+
98
103
  export interface QueryOptions<
99
104
  TQueryFnData = unknown,
100
105
  TError = DefaultError,
@@ -261,9 +266,10 @@ export interface QueryObserverOptions<
261
266
  * If set, the component will only re-render if any of the listed properties change.
262
267
  * When set to `['data', 'error']`, the component will only re-render when the `data` or `error` properties change.
263
268
  * When set to `'all'`, the component will re-render whenever a query is updated.
269
+ * When set to a function, the function will be executed to compute the list of properties.
264
270
  * By default, access to properties will be tracked, and the component will only re-render when one of the tracked properties change.
265
271
  */
266
- notifyOnChangeProps?: Array<keyof InfiniteQueryObserverResult> | 'all'
272
+ notifyOnChangeProps?: NotifyOnChangeProps
267
273
  /**
268
274
  * Whether errors should be thrown instead of setting the `error` property.
269
275
  * If set to `true` or `suspense` is `true`, all errors will be thrown to the error boundary.
@@ -292,8 +298,8 @@ export interface QueryObserverOptions<
292
298
  _optimisticResults?: 'optimistic' | 'isRestoring'
293
299
  }
294
300
 
295
- export type WithRequired<T, K extends keyof T> = Omit<T, K> &
296
- Required<Pick<T, K>>
301
+ export type WithRequired<T, K extends keyof T> = T & { [_ in K]: {} }
302
+
297
303
  export type DefaultedQueryObserverOptions<
298
304
  TQueryFnData = unknown,
299
305
  TError = DefaultError,
@@ -585,14 +591,20 @@ export interface InfiniteQueryObserverSuccessResult<
585
591
  status: 'success'
586
592
  }
587
593
 
594
+ export type DefinedInfiniteQueryObserverResult<
595
+ TData = unknown,
596
+ TError = DefaultError,
597
+ > =
598
+ | InfiniteQueryObserverRefetchErrorResult<TData, TError>
599
+ | InfiniteQueryObserverSuccessResult<TData, TError>
600
+
588
601
  export type InfiniteQueryObserverResult<
589
602
  TData = unknown,
590
603
  TError = DefaultError,
591
604
  > =
592
605
  | InfiniteQueryObserverLoadingErrorResult<TData, TError>
593
606
  | InfiniteQueryObserverLoadingResult<TData, TError>
594
- | InfiniteQueryObserverRefetchErrorResult<TData, TError>
595
- | InfiniteQueryObserverSuccessResult<TData, TError>
607
+ | DefinedInfiniteQueryObserverResult<TData, TError>
596
608
 
597
609
  export type MutationKey = readonly unknown[]
598
610