@tanstack/svelte-query 5.90.2 → 6.0.0

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 (89) hide show
  1. package/dist/HydrationBoundary.svelte +15 -4
  2. package/dist/HydrationBoundary.svelte.d.ts +9 -19
  3. package/dist/HydrationBoundary.svelte.d.ts.map +1 -1
  4. package/dist/QueryClientProvider.svelte +4 -2
  5. package/dist/QueryClientProvider.svelte.d.ts +4 -19
  6. package/dist/QueryClientProvider.svelte.d.ts.map +1 -1
  7. package/dist/containers.svelte.d.ts +19 -0
  8. package/dist/containers.svelte.d.ts.map +1 -0
  9. package/dist/containers.svelte.js +118 -0
  10. package/dist/context.d.ts +3 -3
  11. package/dist/context.d.ts.map +1 -1
  12. package/dist/context.js +4 -5
  13. package/dist/createBaseQuery.svelte.d.ts +10 -0
  14. package/dist/createBaseQuery.svelte.d.ts.map +1 -0
  15. package/dist/createBaseQuery.svelte.js +58 -0
  16. package/dist/createInfiniteQuery.d.ts +2 -2
  17. package/dist/createInfiniteQuery.d.ts.map +1 -1
  18. package/dist/createInfiniteQuery.js +1 -1
  19. package/dist/createMutation.svelte.d.ts +8 -0
  20. package/dist/createMutation.svelte.d.ts.map +1 -0
  21. package/dist/createMutation.svelte.js +50 -0
  22. package/dist/createQueries.svelte.d.ts +76 -0
  23. package/dist/createQueries.svelte.d.ts.map +1 -0
  24. package/dist/createQueries.svelte.js +39 -0
  25. package/dist/createQuery.d.ts +4 -4
  26. package/dist/createQuery.d.ts.map +1 -1
  27. package/dist/createQuery.js +1 -1
  28. package/dist/index.d.ts +6 -6
  29. package/dist/index.d.ts.map +1 -1
  30. package/dist/index.js +5 -5
  31. package/dist/types.d.ts +11 -8
  32. package/dist/types.d.ts.map +1 -1
  33. package/dist/useIsFetching.svelte.d.ts +4 -0
  34. package/dist/useIsFetching.svelte.d.ts.map +1 -0
  35. package/dist/useIsFetching.svelte.js +7 -0
  36. package/dist/useIsMutating.svelte.d.ts +4 -0
  37. package/dist/useIsMutating.svelte.d.ts.map +1 -0
  38. package/dist/useIsMutating.svelte.js +7 -0
  39. package/dist/useIsRestoring.d.ts +2 -2
  40. package/dist/useIsRestoring.d.ts.map +1 -1
  41. package/dist/{useMutationState.d.ts → useMutationState.svelte.d.ts} +2 -3
  42. package/dist/useMutationState.svelte.d.ts.map +1 -0
  43. package/dist/useMutationState.svelte.js +33 -0
  44. package/dist/utils.svelte.d.ts +4 -0
  45. package/dist/utils.svelte.d.ts.map +1 -0
  46. package/dist/utils.svelte.js +31 -0
  47. package/package.json +8 -2
  48. package/src/HydrationBoundary.svelte +15 -4
  49. package/src/QueryClientProvider.svelte +4 -2
  50. package/src/containers.svelte.ts +123 -0
  51. package/src/context.ts +10 -11
  52. package/src/createBaseQuery.svelte.ts +107 -0
  53. package/src/createInfiniteQuery.ts +4 -4
  54. package/src/createMutation.svelte.ts +91 -0
  55. package/src/{createQueries.ts → createQueries.svelte.ts} +86 -96
  56. package/src/createQuery.ts +15 -17
  57. package/src/index.ts +6 -6
  58. package/src/types.ts +12 -9
  59. package/src/useIsFetching.svelte.ts +16 -0
  60. package/src/useIsMutating.svelte.ts +16 -0
  61. package/src/useIsRestoring.ts +2 -2
  62. package/src/useMutationState.svelte.ts +56 -0
  63. package/src/utils.svelte.ts +44 -0
  64. package/dist/createBaseQuery.d.ts +0 -4
  65. package/dist/createBaseQuery.d.ts.map +0 -1
  66. package/dist/createBaseQuery.js +0 -40
  67. package/dist/createMutation.d.ts +0 -4
  68. package/dist/createMutation.d.ts.map +0 -1
  69. package/dist/createMutation.js +0 -25
  70. package/dist/createQueries.d.ts +0 -77
  71. package/dist/createQueries.d.ts.map +0 -1
  72. package/dist/createQueries.js +0 -40
  73. package/dist/useIsFetching.d.ts +0 -4
  74. package/dist/useIsFetching.d.ts.map +0 -1
  75. package/dist/useIsFetching.js +0 -20
  76. package/dist/useIsMutating.d.ts +0 -4
  77. package/dist/useIsMutating.d.ts.map +0 -1
  78. package/dist/useIsMutating.js +0 -20
  79. package/dist/useMutationState.d.ts.map +0 -1
  80. package/dist/useMutationState.js +0 -23
  81. package/dist/utils.d.ts +0 -4
  82. package/dist/utils.d.ts.map +0 -1
  83. package/dist/utils.js +0 -3
  84. package/src/createBaseQuery.ts +0 -85
  85. package/src/createMutation.ts +0 -54
  86. package/src/useIsFetching.ts +0 -30
  87. package/src/useIsMutating.ts +0 -30
  88. package/src/useMutationState.ts +0 -49
  89. package/src/utils.ts +0 -8
@@ -1,16 +1,27 @@
1
1
  <script lang="ts">
2
2
  import { useHydrate } from './useHydrate.js'
3
+ import type { Snippet } from 'svelte'
3
4
  import type {
4
5
  DehydratedState,
5
6
  HydrateOptions,
6
7
  QueryClient,
7
8
  } from '@tanstack/query-core'
8
9
 
9
- export let state: DehydratedState
10
- export let options: HydrateOptions | undefined = undefined
11
- export let queryClient: QueryClient | undefined = undefined
10
+ type Props = {
11
+ children: Snippet
12
+ state: DehydratedState
13
+ options: HydrateOptions | undefined
14
+ queryClient: QueryClient | undefined
15
+ }
16
+
17
+ const {
18
+ children,
19
+ state,
20
+ options = undefined,
21
+ queryClient = undefined,
22
+ }: Props = $props()
12
23
 
13
24
  useHydrate(state, options, queryClient)
14
25
  </script>
15
26
 
16
- <slot />
27
+ {@render children()}
@@ -1,22 +1,12 @@
1
- import { SvelteComponentTyped } from "svelte";
1
+ import type { Snippet } from 'svelte';
2
2
  import type { DehydratedState, HydrateOptions, QueryClient } from '@tanstack/query-core';
3
- declare const __propDef: {
4
- props: {
5
- state: DehydratedState;
6
- options?: HydrateOptions | undefined;
7
- queryClient?: QueryClient | undefined;
8
- };
9
- events: {
10
- [evt: string]: CustomEvent<any>;
11
- };
12
- slots: {
13
- default: {};
14
- };
3
+ type Props = {
4
+ children: Snippet;
5
+ state: DehydratedState;
6
+ options: HydrateOptions | undefined;
7
+ queryClient: QueryClient | undefined;
15
8
  };
16
- export type HydrationBoundaryProps = typeof __propDef.props;
17
- export type HydrationBoundaryEvents = typeof __propDef.events;
18
- export type HydrationBoundarySlots = typeof __propDef.slots;
19
- export default class HydrationBoundary extends SvelteComponentTyped<HydrationBoundaryProps, HydrationBoundaryEvents, HydrationBoundarySlots> {
20
- }
21
- export {};
9
+ declare const HydrationBoundary: import("svelte").Component<Props, {}, "">;
10
+ type HydrationBoundary = ReturnType<typeof HydrationBoundary>;
11
+ export default HydrationBoundary;
22
12
  //# sourceMappingURL=HydrationBoundary.svelte.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"HydrationBoundary.svelte.d.ts","sourceRoot":"","sources":["../src/HydrationBoundary.svelte.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,QAAQ,CAE5C;AAED,OAAO,KAAK,EACR,eAAe,EACf,cAAc,EACd,WAAW,EACZ,MAAM,sBAAsB,CAAC;AAiBhC,QAAA,MAAM,SAAS;;eADyE,eAAe;kBAAY,cAAc,GAAG,SAAS;sBAAgB,WAAW,GAAG,SAAS;;;;;;;;CAC3H,CAAC;AAC1D,MAAM,MAAM,sBAAsB,GAAG,OAAO,SAAS,CAAC,KAAK,CAAC;AAC5D,MAAM,MAAM,uBAAuB,GAAG,OAAO,SAAS,CAAC,MAAM,CAAC;AAC9D,MAAM,MAAM,sBAAsB,GAAG,OAAO,SAAS,CAAC,KAAK,CAAC;AAE5D,MAAM,CAAC,OAAO,OAAO,iBAAkB,SAAQ,oBAAoB,CAAC,sBAAsB,EAAE,uBAAuB,EAAE,sBAAsB,CAAC;CAC3I"}
1
+ {"version":3,"file":"HydrationBoundary.svelte.d.ts","sourceRoot":"","sources":["../src/HydrationBoundary.svelte.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAA;AACrC,OAAO,KAAK,EACR,eAAe,EACf,cAAc,EACd,WAAW,EACZ,MAAM,sBAAsB,CAAC;AAG9B,KAAK,KAAK,GAAG;IACX,QAAQ,EAAE,OAAO,CAAA;IACjB,KAAK,EAAE,eAAe,CAAA;IACtB,OAAO,EAAE,cAAc,GAAG,SAAS,CAAA;IACnC,WAAW,EAAE,WAAW,GAAG,SAAS,CAAA;CACrC,CAAC;AAqBJ,QAAA,MAAM,iBAAiB,2CAAwC,CAAC;AAChE,KAAK,iBAAiB,GAAG,UAAU,CAAC,OAAO,iBAAiB,CAAC,CAAC;AAC9D,eAAe,iBAAiB,CAAC"}
@@ -2,8 +2,10 @@
2
2
  import { onDestroy, onMount } from 'svelte'
3
3
  import { QueryClient } from '@tanstack/query-core'
4
4
  import { setQueryClientContext } from './context.js'
5
+ import type { QueryClientProviderProps } from './types.js'
5
6
 
6
- export let client = new QueryClient()
7
+ const { client = new QueryClient(), children }: QueryClientProviderProps =
8
+ $props()
7
9
 
8
10
  onMount(() => {
9
11
  client.mount()
@@ -16,4 +18,4 @@
16
18
  })
17
19
  </script>
18
20
 
19
- <slot />
21
+ {@render children()}
@@ -1,20 +1,5 @@
1
- import { SvelteComponentTyped } from "svelte";
2
- import { QueryClient } from '@tanstack/query-core';
3
- declare const __propDef: {
4
- props: {
5
- client?: QueryClient;
6
- };
7
- events: {
8
- [evt: string]: CustomEvent<any>;
9
- };
10
- slots: {
11
- default: {};
12
- };
13
- };
14
- export type QueryClientProviderProps = typeof __propDef.props;
15
- export type QueryClientProviderEvents = typeof __propDef.events;
16
- export type QueryClientProviderSlots = typeof __propDef.slots;
17
- export default class QueryClientProvider extends SvelteComponentTyped<QueryClientProviderProps, QueryClientProviderEvents, QueryClientProviderSlots> {
18
- }
19
- export {};
1
+ import type { QueryClientProviderProps } from './types.js';
2
+ declare const QueryClientProvider: import("svelte").Component<QueryClientProviderProps, {}, "">;
3
+ type QueryClientProvider = ReturnType<typeof QueryClientProvider>;
4
+ export default QueryClientProvider;
20
5
  //# sourceMappingURL=QueryClientProvider.svelte.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"QueryClientProvider.svelte.d.ts","sourceRoot":"","sources":["../src/QueryClientProvider.svelte.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,QAAQ,CAE5C;AAED,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAA;AAyBlD,QAAA,MAAM,SAAS;;;;;;;;;;CAA0C,CAAC;AAC1D,MAAM,MAAM,wBAAwB,GAAG,OAAO,SAAS,CAAC,KAAK,CAAC;AAC9D,MAAM,MAAM,yBAAyB,GAAG,OAAO,SAAS,CAAC,MAAM,CAAC;AAChE,MAAM,MAAM,wBAAwB,GAAG,OAAO,SAAS,CAAC,KAAK,CAAC;AAE9D,MAAM,CAAC,OAAO,OAAO,mBAAoB,SAAQ,oBAAoB,CAAC,wBAAwB,EAAE,yBAAyB,EAAE,wBAAwB,CAAC;CACnJ"}
1
+ {"version":3,"file":"QueryClientProvider.svelte.d.ts","sourceRoot":"","sources":["../src/QueryClientProvider.svelte.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,YAAY,CAAC;AA0B3D,QAAA,MAAM,mBAAmB,8DAAwC,CAAC;AAClE,KAAK,mBAAmB,GAAG,UAAU,CAAC,OAAO,mBAAmB,CAAC,CAAC;AAClE,eAAe,mBAAmB,CAAC"}
@@ -0,0 +1,19 @@
1
+ type VoidFn = () => void;
2
+ type Subscriber = (update: VoidFn) => void | VoidFn;
3
+ export type Box<T> = {
4
+ current: T;
5
+ };
6
+ export declare class ReactiveValue<T> implements Box<T> {
7
+ #private;
8
+ constructor(fn: () => T, onSubscribe: Subscriber);
9
+ get current(): T;
10
+ }
11
+ /**
12
+ * Makes all of the top-level keys of an object into $state.raw fields whose initial values
13
+ * are the same as in the original object. Does not mutate the original object. Provides an `update`
14
+ * function that _can_ (but does not have to be) be used to replace all of the object's top-level keys
15
+ * with the values of the new object, while maintaining the original root object's reference.
16
+ */
17
+ export declare function createRawRef<T extends {} | Array<unknown>>(init: T): [T, (newValue: T) => void];
18
+ export {};
19
+ //# sourceMappingURL=containers.svelte.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"containers.svelte.d.ts","sourceRoot":"","sources":["../src/containers.svelte.ts"],"names":[],"mappings":"AAEA,KAAK,MAAM,GAAG,MAAM,IAAI,CAAA;AACxB,KAAK,UAAU,GAAG,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,GAAG,MAAM,CAAA;AAEnD,MAAM,MAAM,GAAG,CAAC,CAAC,IAAI;IAAE,OAAO,EAAE,CAAC,CAAA;CAAE,CAAA;AAEnC,qBAAa,aAAa,CAAC,CAAC,CAAE,YAAW,GAAG,CAAC,CAAC,CAAC;;gBAIjC,EAAE,EAAE,MAAM,CAAC,EAAE,WAAW,EAAE,UAAU;IAKhD,IAAI,OAAO,MAGV;CACF;AAED;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,CAAC,SAAS,EAAE,GAAG,KAAK,CAAC,OAAO,CAAC,EACxD,IAAI,EAAE,CAAC,GACN,CAAC,CAAC,EAAE,CAAC,QAAQ,EAAE,CAAC,KAAK,IAAI,CAAC,CA+E5B"}
@@ -0,0 +1,118 @@
1
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
2
+ if (kind === "m") throw new TypeError("Private method is not writable");
3
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
4
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
5
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
6
+ };
7
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
8
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
9
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
10
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
11
+ };
12
+ var _ReactiveValue_fn, _ReactiveValue_subscribe;
13
+ import { SvelteSet, createSubscriber } from 'svelte/reactivity';
14
+ export class ReactiveValue {
15
+ constructor(fn, onSubscribe) {
16
+ _ReactiveValue_fn.set(this, void 0);
17
+ _ReactiveValue_subscribe.set(this, void 0);
18
+ __classPrivateFieldSet(this, _ReactiveValue_fn, fn, "f");
19
+ __classPrivateFieldSet(this, _ReactiveValue_subscribe, createSubscriber((update) => onSubscribe(update)), "f");
20
+ }
21
+ get current() {
22
+ __classPrivateFieldGet(this, _ReactiveValue_subscribe, "f").call(this);
23
+ return __classPrivateFieldGet(this, _ReactiveValue_fn, "f").call(this);
24
+ }
25
+ }
26
+ _ReactiveValue_fn = new WeakMap(), _ReactiveValue_subscribe = new WeakMap();
27
+ /**
28
+ * Makes all of the top-level keys of an object into $state.raw fields whose initial values
29
+ * are the same as in the original object. Does not mutate the original object. Provides an `update`
30
+ * function that _can_ (but does not have to be) be used to replace all of the object's top-level keys
31
+ * with the values of the new object, while maintaining the original root object's reference.
32
+ */
33
+ export function createRawRef(init) {
34
+ const refObj = (Array.isArray(init) ? [] : {});
35
+ const hiddenKeys = new SvelteSet();
36
+ const out = new Proxy(refObj, {
37
+ set(target, prop, value, receiver) {
38
+ hiddenKeys.delete(prop);
39
+ if (prop in target) {
40
+ return Reflect.set(target, prop, value, receiver);
41
+ }
42
+ let state = $state.raw(value);
43
+ Object.defineProperty(target, prop, {
44
+ configurable: true,
45
+ enumerable: true,
46
+ get: () => {
47
+ // If this is a lazy value, we need to call it.
48
+ // We can't do something like typeof state === 'function'
49
+ // because the value could actually be a function that we don't want to call.
50
+ return state && isBranded(state) ? state() : state;
51
+ },
52
+ set: (v) => {
53
+ state = v;
54
+ },
55
+ });
56
+ return true;
57
+ },
58
+ has: (target, prop) => {
59
+ if (hiddenKeys.has(prop)) {
60
+ return false;
61
+ }
62
+ return prop in target;
63
+ },
64
+ ownKeys(target) {
65
+ return Reflect.ownKeys(target).filter((key) => !hiddenKeys.has(key));
66
+ },
67
+ getOwnPropertyDescriptor(target, prop) {
68
+ if (hiddenKeys.has(prop)) {
69
+ return undefined;
70
+ }
71
+ return Reflect.getOwnPropertyDescriptor(target, prop);
72
+ },
73
+ deleteProperty(target, prop) {
74
+ if (prop in target) {
75
+ // @ts-expect-error
76
+ // We need to set the value to undefined to signal to the listeners that the value has changed.
77
+ // If we just deleted it, the reactivity system wouldn't have any idea that the value was gone.
78
+ target[prop] = undefined;
79
+ hiddenKeys.add(prop);
80
+ if (Array.isArray(target)) {
81
+ target.length--;
82
+ }
83
+ return true;
84
+ }
85
+ return false;
86
+ },
87
+ });
88
+ function update(newValue) {
89
+ const existingKeys = Object.keys(out);
90
+ const newKeys = Object.keys(newValue);
91
+ const keysToRemove = existingKeys.filter((key) => !newKeys.includes(key));
92
+ for (const key of keysToRemove) {
93
+ // @ts-expect-error
94
+ delete out[key];
95
+ }
96
+ for (const key of newKeys) {
97
+ // @ts-expect-error
98
+ // This craziness is required because Tanstack Query defines getters for all of the keys on the object.
99
+ // These getters track property access, so if we access all of them here, we'll end up tracking everything.
100
+ // So we wrap the property access in a special function that we can identify later to lazily access the value.
101
+ // (See above)
102
+ out[key] = brand(() => newValue[key]);
103
+ }
104
+ }
105
+ // we can't pass `init` directly into the proxy because it'll never set the state fields
106
+ // (because (prop in target) will always be true)
107
+ update(init);
108
+ return [out, update];
109
+ }
110
+ const lazyBrand = Symbol('LazyValue');
111
+ function brand(fn) {
112
+ // @ts-expect-error
113
+ fn[lazyBrand] = true;
114
+ return fn;
115
+ }
116
+ function isBranded(fn) {
117
+ return Boolean(fn[lazyBrand]);
118
+ }
package/dist/context.d.ts CHANGED
@@ -1,11 +1,11 @@
1
1
  import type { QueryClient } from '@tanstack/query-core';
2
- import type { Readable } from 'svelte/store';
2
+ import type { Box } from './containers.svelte';
3
3
  /** Retrieves a Client from Svelte's context */
4
4
  export declare const getQueryClientContext: () => QueryClient;
5
5
  /** Sets a QueryClient on Svelte's context */
6
6
  export declare const setQueryClientContext: (client: QueryClient) => void;
7
7
  /** Retrieves a `isRestoring` from Svelte's context */
8
- export declare const getIsRestoringContext: () => Readable<boolean>;
8
+ export declare const getIsRestoringContext: () => Box<boolean>;
9
9
  /** Sets a `isRestoring` on Svelte's context */
10
- export declare const setIsRestoringContext: (isRestoring: Readable<boolean>) => void;
10
+ export declare const setIsRestoringContext: (isRestoring: Box<boolean>) => void;
11
11
  //# sourceMappingURL=context.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAA;AACvD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAA;AAI5C,+CAA+C;AAC/C,eAAO,MAAM,qBAAqB,QAAO,WASxC,CAAA;AAED,6CAA6C;AAC7C,eAAO,MAAM,qBAAqB,GAAI,QAAQ,WAAW,KAAG,IAE3D,CAAA;AAID,sDAAsD;AACtD,eAAO,MAAM,qBAAqB,QAAO,QAAQ,CAAC,OAAO,CASxD,CAAA;AAED,+CAA+C;AAC/C,eAAO,MAAM,qBAAqB,GAAI,aAAa,QAAQ,CAAC,OAAO,CAAC,KAAG,IAEtE,CAAA"}
1
+ {"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAA;AACvD,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,qBAAqB,CAAA;AAI9C,+CAA+C;AAC/C,eAAO,MAAM,qBAAqB,QAAO,WASxC,CAAA;AAED,6CAA6C;AAC7C,eAAO,MAAM,qBAAqB,GAAI,QAAQ,WAAW,KAAG,IAE3D,CAAA;AAID,sDAAsD;AACtD,eAAO,MAAM,qBAAqB,QAAO,GAAG,CAAC,OAAO,CASnD,CAAA;AAED,+CAA+C;AAC/C,eAAO,MAAM,qBAAqB,GAAI,aAAa,GAAG,CAAC,OAAO,CAAC,KAAG,IAEjE,CAAA"}
package/dist/context.js CHANGED
@@ -1,6 +1,5 @@
1
1
  import { getContext, setContext } from 'svelte';
2
- import { readable } from 'svelte/store';
3
- const _contextKey = '$$_queryClient';
2
+ const _contextKey = Symbol('QueryClient');
4
3
  /** Retrieves a Client from Svelte's context */
5
4
  export const getQueryClientContext = () => {
6
5
  const client = getContext(_contextKey);
@@ -13,15 +12,15 @@ export const getQueryClientContext = () => {
13
12
  export const setQueryClientContext = (client) => {
14
13
  setContext(_contextKey, client);
15
14
  };
16
- const _isRestoringContextKey = '$$_isRestoring';
15
+ const _isRestoringContextKey = Symbol('isRestoring');
17
16
  /** Retrieves a `isRestoring` from Svelte's context */
18
17
  export const getIsRestoringContext = () => {
19
18
  try {
20
19
  const isRestoring = getContext(_isRestoringContextKey);
21
- return isRestoring ? isRestoring : readable(false);
20
+ return isRestoring ?? { current: false };
22
21
  }
23
22
  catch (error) {
24
- return readable(false);
23
+ return { current: false };
25
24
  }
26
25
  };
27
26
  /** Sets a `isRestoring` on Svelte's context */
@@ -0,0 +1,10 @@
1
+ import type { QueryClient, QueryKey, QueryObserver } from '@tanstack/query-core';
2
+ import type { Accessor, CreateBaseQueryOptions, CreateBaseQueryResult } from './types.js';
3
+ /**
4
+ * Base implementation for `createQuery` and `createInfiniteQuery`
5
+ * @param options - A function that returns query options
6
+ * @param Observer - The observer from query-core
7
+ * @param queryClient - Custom query client which overrides provider
8
+ */
9
+ export declare function createBaseQuery<TQueryFnData, TError, TData, TQueryData, TQueryKey extends QueryKey>(options: Accessor<CreateBaseQueryOptions<TQueryFnData, TError, TData, TQueryData, TQueryKey>>, Observer: typeof QueryObserver, queryClient?: Accessor<QueryClient>): CreateBaseQueryResult<TData, TError>;
10
+ //# sourceMappingURL=createBaseQuery.svelte.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createBaseQuery.svelte.d.ts","sourceRoot":"","sources":["../src/createBaseQuery.svelte.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAA;AAChF,OAAO,KAAK,EACV,QAAQ,EACR,sBAAsB,EACtB,qBAAqB,EACtB,MAAM,YAAY,CAAA;AAEnB;;;;;GAKG;AACH,wBAAgB,eAAe,CAC7B,YAAY,EACZ,MAAM,EACN,KAAK,EACL,UAAU,EACV,SAAS,SAAS,QAAQ,EAE1B,OAAO,EAAE,QAAQ,CACf,sBAAsB,CAAC,YAAY,EAAE,MAAM,EAAE,KAAK,EAAE,UAAU,EAAE,SAAS,CAAC,CAC3E,EACD,QAAQ,EAAE,OAAO,aAAa,EAC9B,WAAW,CAAC,EAAE,QAAQ,CAAC,WAAW,CAAC,GAClC,qBAAqB,CAAC,KAAK,EAAE,MAAM,CAAC,CA6EtC"}
@@ -0,0 +1,58 @@
1
+ import { useIsRestoring } from './useIsRestoring.js';
2
+ import { useQueryClient } from './useQueryClient.js';
3
+ import { createRawRef } from './containers.svelte.js';
4
+ import { watchChanges } from './utils.svelte.js';
5
+ /**
6
+ * Base implementation for `createQuery` and `createInfiniteQuery`
7
+ * @param options - A function that returns query options
8
+ * @param Observer - The observer from query-core
9
+ * @param queryClient - Custom query client which overrides provider
10
+ */
11
+ export function createBaseQuery(options, Observer, queryClient) {
12
+ /** Load query client */
13
+ const client = $derived(useQueryClient(queryClient?.()));
14
+ const isRestoring = useIsRestoring();
15
+ const resolvedOptions = $derived.by(() => {
16
+ const opts = client.defaultQueryOptions(options());
17
+ opts._optimisticResults = isRestoring.current ? 'isRestoring' : 'optimistic';
18
+ return opts;
19
+ });
20
+ /** Creates the observer */
21
+ // svelte-ignore state_referenced_locally - intentional, initial value
22
+ let observer = $state(new Observer(client, resolvedOptions));
23
+ watchChanges(() => client, 'pre', () => {
24
+ observer = new Observer(client, resolvedOptions);
25
+ });
26
+ function createResult() {
27
+ const result = observer.getOptimisticResult(resolvedOptions);
28
+ return !resolvedOptions.notifyOnChangeProps
29
+ ? observer.trackResult(result)
30
+ : result;
31
+ }
32
+ const [query, update] = createRawRef(
33
+ // svelte-ignore state_referenced_locally - intentional, initial value
34
+ createResult());
35
+ $effect(() => {
36
+ const unsubscribe = isRestoring.current
37
+ ? () => undefined
38
+ : observer.subscribe(() => update(createResult()));
39
+ observer.updateResult();
40
+ return unsubscribe;
41
+ });
42
+ watchChanges(() => resolvedOptions, 'pre', () => {
43
+ observer.setOptions(resolvedOptions);
44
+ });
45
+ watchChanges(() => [resolvedOptions, observer], 'pre', () => {
46
+ // The only reason this is necessary is because of `isRestoring`.
47
+ // Because we don't subscribe while restoring, the following can occur:
48
+ // - `isRestoring` is true
49
+ // - `isRestoring` becomes false
50
+ // - `observer.subscribe` and `observer.updateResult` is called in the above effect,
51
+ // but the subsequent `fetch` has already completed
52
+ // - `result` misses the intermediate restored-but-not-fetched state
53
+ //
54
+ // this could technically be its own effect but that doesn't seem necessary
55
+ update(createResult());
56
+ });
57
+ return query;
58
+ }
@@ -1,4 +1,4 @@
1
1
  import type { DefaultError, InfiniteData, QueryClient, QueryKey } from '@tanstack/query-core';
2
- import type { CreateInfiniteQueryOptions, CreateInfiniteQueryResult, StoreOrVal } from './types.js';
3
- export declare function createInfiniteQuery<TQueryFnData, TError = DefaultError, TData = InfiniteData<TQueryFnData>, TQueryKey extends QueryKey = QueryKey, TPageParam = unknown>(options: StoreOrVal<CreateInfiniteQueryOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>>, queryClient?: QueryClient): CreateInfiniteQueryResult<TData, TError>;
2
+ import type { Accessor, CreateInfiniteQueryOptions, CreateInfiniteQueryResult } from './types.js';
3
+ export declare function createInfiniteQuery<TQueryFnData, TError = DefaultError, TData = InfiniteData<TQueryFnData>, TQueryKey extends QueryKey = QueryKey, TPageParam = unknown>(options: Accessor<CreateInfiniteQueryOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>>, queryClient?: Accessor<QueryClient>): CreateInfiniteQueryResult<TData, TError>;
4
4
  //# sourceMappingURL=createInfiniteQuery.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"createInfiniteQuery.d.ts","sourceRoot":"","sources":["../src/createInfiniteQuery.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,YAAY,EACZ,YAAY,EACZ,WAAW,EACX,QAAQ,EAET,MAAM,sBAAsB,CAAA;AAC7B,OAAO,KAAK,EACV,0BAA0B,EAC1B,yBAAyB,EACzB,UAAU,EACX,MAAM,YAAY,CAAA;AAEnB,wBAAgB,mBAAmB,CACjC,YAAY,EACZ,MAAM,GAAG,YAAY,EACrB,KAAK,GAAG,YAAY,CAAC,YAAY,CAAC,EAClC,SAAS,SAAS,QAAQ,GAAG,QAAQ,EACrC,UAAU,GAAG,OAAO,EAEpB,OAAO,EAAE,UAAU,CACjB,0BAA0B,CACxB,YAAY,EACZ,MAAM,EACN,KAAK,EACL,SAAS,EACT,UAAU,CACX,CACF,EACD,WAAW,CAAC,EAAE,WAAW,GACxB,yBAAyB,CAAC,KAAK,EAAE,MAAM,CAAC,CAM1C"}
1
+ {"version":3,"file":"createInfiniteQuery.d.ts","sourceRoot":"","sources":["../src/createInfiniteQuery.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,YAAY,EACZ,YAAY,EACZ,WAAW,EACX,QAAQ,EAET,MAAM,sBAAsB,CAAA;AAC7B,OAAO,KAAK,EACV,QAAQ,EACR,0BAA0B,EAC1B,yBAAyB,EAC1B,MAAM,YAAY,CAAA;AAEnB,wBAAgB,mBAAmB,CACjC,YAAY,EACZ,MAAM,GAAG,YAAY,EACrB,KAAK,GAAG,YAAY,CAAC,YAAY,CAAC,EAClC,SAAS,SAAS,QAAQ,GAAG,QAAQ,EACrC,UAAU,GAAG,OAAO,EAEpB,OAAO,EAAE,QAAQ,CACf,0BAA0B,CACxB,YAAY,EACZ,MAAM,EACN,KAAK,EACL,SAAS,EACT,UAAU,CACX,CACF,EACD,WAAW,CAAC,EAAE,QAAQ,CAAC,WAAW,CAAC,GAClC,yBAAyB,CAAC,KAAK,EAAE,MAAM,CAAC,CAM1C"}
@@ -1,5 +1,5 @@
1
1
  import { InfiniteQueryObserver } from '@tanstack/query-core';
2
- import { createBaseQuery } from './createBaseQuery.js';
2
+ import { createBaseQuery } from './createBaseQuery.svelte.js';
3
3
  export function createInfiniteQuery(options, queryClient) {
4
4
  return createBaseQuery(options, InfiniteQueryObserver, queryClient);
5
5
  }
@@ -0,0 +1,8 @@
1
+ import type { Accessor, CreateMutationOptions, CreateMutationResult } from './types.js';
2
+ import type { DefaultError, QueryClient } from '@tanstack/query-core';
3
+ /**
4
+ * @param options - A function that returns mutation options
5
+ * @param queryClient - Custom query client which overrides provider
6
+ */
7
+ export declare function createMutation<TData = unknown, TError = DefaultError, TVariables = void, TContext = unknown>(options: Accessor<CreateMutationOptions<TData, TError, TVariables, TContext>>, queryClient?: Accessor<QueryClient>): CreateMutationResult<TData, TError, TVariables, TContext>;
8
+ //# sourceMappingURL=createMutation.svelte.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createMutation.svelte.d.ts","sourceRoot":"","sources":["../src/createMutation.svelte.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,QAAQ,EAER,qBAAqB,EACrB,oBAAoB,EACrB,MAAM,YAAY,CAAA;AAEnB,OAAO,KAAK,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAA;AAErE;;;GAGG;AACH,wBAAgB,cAAc,CAC5B,KAAK,GAAG,OAAO,EACf,MAAM,GAAG,YAAY,EACrB,UAAU,GAAG,IAAI,EACjB,QAAQ,GAAG,OAAO,EAElB,OAAO,EAAE,QAAQ,CAAC,qBAAqB,CAAC,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,QAAQ,CAAC,CAAC,EAC7E,WAAW,CAAC,EAAE,QAAQ,CAAC,WAAW,CAAC,GAClC,oBAAoB,CAAC,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,QAAQ,CAAC,CAkE3D"}
@@ -0,0 +1,50 @@
1
+ import { MutationObserver, noop, notifyManager } from '@tanstack/query-core';
2
+ import { useQueryClient } from './useQueryClient.js';
3
+ import { watchChanges } from './utils.svelte.js';
4
+ /**
5
+ * @param options - A function that returns mutation options
6
+ * @param queryClient - Custom query client which overrides provider
7
+ */
8
+ export function createMutation(options, queryClient) {
9
+ const client = $derived(useQueryClient(queryClient?.()));
10
+ // svelte-ignore state_referenced_locally - intentional, initial value
11
+ let observer = $state(
12
+ // svelte-ignore state_referenced_locally - intentional, initial value
13
+ new MutationObserver(client, options()));
14
+ watchChanges(() => client, 'pre', () => {
15
+ observer = new MutationObserver(client, options());
16
+ });
17
+ $effect.pre(() => {
18
+ observer.setOptions(options());
19
+ });
20
+ const mutate = ((variables, mutateOptions) => {
21
+ observer.mutate(variables, mutateOptions).catch(noop);
22
+ });
23
+ let result = $state(observer.getCurrentResult());
24
+ watchChanges(() => observer, 'pre', () => {
25
+ result = observer.getCurrentResult();
26
+ });
27
+ $effect.pre(() => {
28
+ const unsubscribe = observer.subscribe((val) => {
29
+ notifyManager.batchCalls(() => {
30
+ Object.assign(result, val);
31
+ })();
32
+ });
33
+ return unsubscribe;
34
+ });
35
+ const resultProxy = $derived(new Proxy(result, {
36
+ get: (_, prop) => {
37
+ const r = {
38
+ ...result,
39
+ mutate,
40
+ mutateAsync: result.mutate,
41
+ };
42
+ if (prop == 'value')
43
+ return r;
44
+ // @ts-expect-error
45
+ return r[prop];
46
+ },
47
+ }));
48
+ // @ts-expect-error
49
+ return resultProxy;
50
+ }
@@ -0,0 +1,76 @@
1
+ import type { Accessor, CreateQueryOptions, CreateQueryResult, DefinedCreateQueryResult } from './types.js';
2
+ import type { DefaultError, OmitKeyof, QueriesPlaceholderDataFunction, QueryClient, QueryFunction, QueryKey, ThrowOnError } from '@tanstack/query-core';
3
+ type CreateQueryOptionsForCreateQueries<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey> = OmitKeyof<CreateQueryOptions<TQueryFnData, TError, TData, TQueryKey>, 'placeholderData'> & {
4
+ placeholderData?: TQueryFnData | QueriesPlaceholderDataFunction<TQueryFnData>;
5
+ };
6
+ type MAXIMUM_DEPTH = 20;
7
+ type SkipTokenForCreateQueries = symbol;
8
+ type GetCreateQueryOptionsForCreateQueries<T> = T extends {
9
+ queryFnData: infer TQueryFnData;
10
+ error?: infer TError;
11
+ data: infer TData;
12
+ } ? CreateQueryOptionsForCreateQueries<TQueryFnData, TError, TData> : T extends {
13
+ queryFnData: infer TQueryFnData;
14
+ error?: infer TError;
15
+ } ? CreateQueryOptionsForCreateQueries<TQueryFnData, TError> : T extends {
16
+ data: infer TData;
17
+ error?: infer TError;
18
+ } ? CreateQueryOptionsForCreateQueries<unknown, TError, TData> : T extends [infer TQueryFnData, infer TError, infer TData] ? CreateQueryOptionsForCreateQueries<TQueryFnData, TError, TData> : T extends [infer TQueryFnData, infer TError] ? CreateQueryOptionsForCreateQueries<TQueryFnData, TError> : T extends [infer TQueryFnData] ? CreateQueryOptionsForCreateQueries<TQueryFnData> : T extends {
19
+ queryFn?: QueryFunction<infer TQueryFnData, infer TQueryKey> | SkipTokenForCreateQueries;
20
+ select?: (data: any) => infer TData;
21
+ throwOnError?: ThrowOnError<any, infer TError, any, any>;
22
+ } ? CreateQueryOptionsForCreateQueries<TQueryFnData, unknown extends TError ? DefaultError : TError, unknown extends TData ? TQueryFnData : TData, TQueryKey> : CreateQueryOptionsForCreateQueries;
23
+ type GetDefinedOrUndefinedQueryResult<T, TData, TError = unknown> = T extends {
24
+ initialData?: infer TInitialData;
25
+ } ? unknown extends TInitialData ? CreateQueryResult<TData, TError> : TInitialData extends TData ? DefinedCreateQueryResult<TData, TError> : TInitialData extends () => infer TInitialDataResult ? unknown extends TInitialDataResult ? CreateQueryResult<TData, TError> : TInitialDataResult extends TData ? DefinedCreateQueryResult<TData, TError> : CreateQueryResult<TData, TError> : CreateQueryResult<TData, TError> : CreateQueryResult<TData, TError>;
26
+ type GetCreateQueryResult<T> = T extends {
27
+ queryFnData: any;
28
+ error?: infer TError;
29
+ data: infer TData;
30
+ } ? GetDefinedOrUndefinedQueryResult<T, TData, TError> : T extends {
31
+ queryFnData: infer TQueryFnData;
32
+ error?: infer TError;
33
+ } ? GetDefinedOrUndefinedQueryResult<T, TQueryFnData, TError> : T extends {
34
+ data: infer TData;
35
+ error?: infer TError;
36
+ } ? GetDefinedOrUndefinedQueryResult<T, TData, TError> : T extends [any, infer TError, infer TData] ? GetDefinedOrUndefinedQueryResult<T, TData, TError> : T extends [infer TQueryFnData, infer TError] ? GetDefinedOrUndefinedQueryResult<T, TQueryFnData, TError> : T extends [infer TQueryFnData] ? GetDefinedOrUndefinedQueryResult<T, TQueryFnData> : T extends {
37
+ queryFn?: QueryFunction<infer TQueryFnData, any> | SkipTokenForCreateQueries;
38
+ select?: (data: any) => infer TData;
39
+ throwOnError?: ThrowOnError<any, infer TError, any, any>;
40
+ } ? GetDefinedOrUndefinedQueryResult<T, unknown extends TData ? TQueryFnData : TData, unknown extends TError ? DefaultError : TError> : CreateQueryResult;
41
+ /**
42
+ * QueriesOptions reducer recursively unwraps function arguments to infer/enforce type param
43
+ */
44
+ export type QueriesOptions<T extends Array<any>, TResults extends Array<any> = [], TDepth extends ReadonlyArray<number> = []> = TDepth['length'] extends MAXIMUM_DEPTH ? Array<CreateQueryOptionsForCreateQueries> : T extends [] ? [] : T extends [infer Head] ? [...TResults, GetCreateQueryOptionsForCreateQueries<Head>] : T extends [infer Head, ...infer Tails] ? QueriesOptions<[
45
+ ...Tails
46
+ ], [
47
+ ...TResults,
48
+ GetCreateQueryOptionsForCreateQueries<Head>
49
+ ], [
50
+ ...TDepth,
51
+ 1
52
+ ]> : ReadonlyArray<unknown> extends T ? T : T extends Array<CreateQueryOptionsForCreateQueries<infer TQueryFnData, infer TError, infer TData, infer TQueryKey>> ? Array<CreateQueryOptionsForCreateQueries<TQueryFnData, TError, TData, TQueryKey>> : Array<CreateQueryOptionsForCreateQueries>;
53
+ /**
54
+ * QueriesResults reducer recursively maps type param to results
55
+ */
56
+ export type QueriesResults<T extends Array<any>, TResults extends Array<any> = [], TDepth extends ReadonlyArray<number> = []> = TDepth['length'] extends MAXIMUM_DEPTH ? Array<CreateQueryResult> : T extends [] ? [] : T extends [infer Head] ? [...TResults, GetCreateQueryResult<Head>] : T extends [infer Head, ...infer Tails] ? QueriesResults<[
57
+ ...Tails
58
+ ], [
59
+ ...TResults,
60
+ GetCreateQueryResult<Head>
61
+ ], [
62
+ ...TDepth,
63
+ 1
64
+ ]> : {
65
+ [K in keyof T]: GetCreateQueryResult<T[K]>;
66
+ };
67
+ export declare function createQueries<T extends Array<any>, TCombinedResult = QueriesResults<T>>(createQueriesOptions: Accessor<{
68
+ queries: readonly [...QueriesOptions<T>] | readonly [
69
+ ...{
70
+ [K in keyof T]: GetCreateQueryOptionsForCreateQueries<T[K]>;
71
+ }
72
+ ];
73
+ combine?: (result: QueriesResults<T>) => TCombinedResult;
74
+ }>, queryClient?: Accessor<QueryClient>): TCombinedResult;
75
+ export {};
76
+ //# sourceMappingURL=createQueries.svelte.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createQueries.svelte.d.ts","sourceRoot":"","sources":["../src/createQueries.svelte.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EACV,QAAQ,EACR,kBAAkB,EAClB,iBAAiB,EACjB,wBAAwB,EACzB,MAAM,YAAY,CAAA;AACnB,OAAO,KAAK,EACV,YAAY,EACZ,SAAS,EAET,8BAA8B,EAC9B,WAAW,EACX,aAAa,EACb,QAAQ,EACR,YAAY,EACb,MAAM,sBAAsB,CAAA;AAI7B,KAAK,kCAAkC,CACrC,YAAY,GAAG,OAAO,EACtB,MAAM,GAAG,YAAY,EACrB,KAAK,GAAG,YAAY,EACpB,SAAS,SAAS,QAAQ,GAAG,QAAQ,IACnC,SAAS,CACX,kBAAkB,CAAC,YAAY,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,CAAC,EAC1D,iBAAiB,CAClB,G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CAAC,GAAG,oBAAoB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;CAAE,CAAA;AAExD,wBAAgB,aAAa,CAC3B,CAAC,SAAS,KAAK,CAAC,GAAG,CAAC,EACpB,eAAe,GAAG,cAAc,CAAC,CAAC,CAAC,EAEnC,oBAAoB,EAAE,QAAQ,CAAC;IAC7B,OAAO,EACH,SAAS,CAAC,GAAG,cAAc,CAAC,CAAC,CAAC,CAAC,GAC/B,SAAS;QACP,GAAG;aAAG,CAAC,IAAI,MAAM,CAAC,GAAG,qCAAqC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;SAAE;KACnE,CAAA;IACL,OAAO,CAAC,EAAE,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC,CAAC,KAAK,eAAe,CAAA;CACzD,CAAC,EACF,WAAW,CAAC,EAAE,QAAQ,CAAC,WAAW,CAAC,GAClC,eAAe,CAoDjB"}
@@ -0,0 +1,39 @@
1
+ import { QueriesObserver } from '@tanstack/query-core';
2
+ import { useIsRestoring } from './useIsRestoring.js';
3
+ import { createRawRef } from './containers.svelte.js';
4
+ import { useQueryClient } from './useQueryClient.js';
5
+ export function createQueries(createQueriesOptions, queryClient) {
6
+ const client = $derived(useQueryClient(queryClient?.()));
7
+ const isRestoring = useIsRestoring();
8
+ const { queries, combine } = $derived.by(createQueriesOptions);
9
+ const resolvedQueryOptions = $derived(queries.map((opts) => {
10
+ const resolvedOptions = client.defaultQueryOptions(opts);
11
+ // Make sure the results are already in fetching state before subscribing or updating options
12
+ resolvedOptions._optimisticResults = isRestoring.current
13
+ ? 'isRestoring'
14
+ : 'optimistic';
15
+ return resolvedOptions;
16
+ }));
17
+ // can't do same as createMutation, as QueriesObserver has no `setOptions` method
18
+ const observer = $derived(new QueriesObserver(client, resolvedQueryOptions, combine));
19
+ function createResult() {
20
+ const [_, getCombinedResult, trackResult] = observer.getOptimisticResult(resolvedQueryOptions, combine);
21
+ return getCombinedResult(trackResult());
22
+ }
23
+ // @ts-expect-error - the crazy-complex TCombinedResult type doesn't like being called an array
24
+ // svelte-ignore state_referenced_locally
25
+ const [results, update] = createRawRef(createResult());
26
+ $effect(() => {
27
+ const unsubscribe = isRestoring.current
28
+ ? () => undefined
29
+ : observer.subscribe(() => update(createResult()));
30
+ return unsubscribe;
31
+ });
32
+ $effect.pre(() => {
33
+ observer.setQueries(resolvedQueryOptions, {
34
+ combine,
35
+ });
36
+ update(createResult());
37
+ });
38
+ return results;
39
+ }
@@ -1,7 +1,7 @@
1
1
  import type { DefaultError, QueryClient, QueryKey } from '@tanstack/query-core';
2
- import type { CreateQueryOptions, CreateQueryResult, DefinedCreateQueryResult, StoreOrVal } from './types.js';
2
+ import type { Accessor, CreateQueryOptions, CreateQueryResult, DefinedCreateQueryResult } from './types.js';
3
3
  import type { DefinedInitialDataOptions, UndefinedInitialDataOptions } from './queryOptions.js';
4
- export declare function createQuery<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey>(options: StoreOrVal<DefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey>>, queryClient?: QueryClient): DefinedCreateQueryResult<TData, TError>;
5
- export declare function createQuery<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey>(options: StoreOrVal<UndefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey>>, queryClient?: QueryClient): CreateQueryResult<TData, TError>;
6
- export declare function createQuery<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey>(options: StoreOrVal<CreateQueryOptions<TQueryFnData, TError, TData, TQueryKey>>, queryClient?: QueryClient): CreateQueryResult<TData, TError>;
4
+ export declare function createQuery<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey>(options: Accessor<UndefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey>>, queryClient?: Accessor<QueryClient>): CreateQueryResult<TData, TError>;
5
+ export declare function createQuery<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey>(options: Accessor<DefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey>>, queryClient?: Accessor<QueryClient>): DefinedCreateQueryResult<TData, TError>;
6
+ export declare function createQuery<TQueryFnData, TError = DefaultError, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey>(options: Accessor<CreateQueryOptions<TQueryFnData, TError, TData, TQueryKey>>, queryClient?: Accessor<QueryClient>): CreateQueryResult<TData, TError>;
7
7
  //# sourceMappingURL=createQuery.d.ts.map