@tanstack/angular-query-experimental 5.80.8 → 5.80.10

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 (91) hide show
  1. package/README.md +2 -0
  2. package/build/index.d.ts +821 -0
  3. package/build/index.mjs +622 -0
  4. package/build/index.mjs.map +1 -0
  5. package/package.json +10 -12
  6. package/src/create-base-query.ts +142 -0
  7. package/src/index.ts +64 -0
  8. package/src/infinite-query-options.ts +187 -0
  9. package/src/inject-infinite-query.ts +129 -0
  10. package/src/inject-is-fetching.ts +66 -0
  11. package/src/inject-is-mutating.ts +65 -0
  12. package/{dist-ts/src/inject-is-restoring.d.ts → src/inject-is-restoring.ts} +33 -7
  13. package/src/inject-mutation-state.ts +125 -0
  14. package/src/inject-mutation.ts +169 -0
  15. package/src/inject-queries.ts +271 -0
  16. package/{dist-ts/src/inject-query-client.d.ts → src/inject-query-client.ts} +9 -7
  17. package/{dist-ts/src/inject-query.d.ts → src/inject-query.ts} +117 -14
  18. package/{dist-ts/src/mutation-options.d.ts → src/mutation-options.ts} +26 -5
  19. package/src/providers.ts +368 -0
  20. package/src/query-options.ts +178 -0
  21. package/src/signal-proxy.ts +46 -0
  22. package/src/test-setup.ts +10 -0
  23. package/src/types.ts +309 -0
  24. package/src/util/is-dev-mode/is-dev-mode.ts +3 -0
  25. package/dist/create-base-query.mjs +0 -74
  26. package/dist/create-base-query.mjs.map +0 -1
  27. package/dist/index.mjs +0 -35
  28. package/dist/index.mjs.map +0 -1
  29. package/dist/infinite-query-options.mjs +0 -7
  30. package/dist/infinite-query-options.mjs.map +0 -1
  31. package/dist/inject-infinite-query.mjs +0 -18
  32. package/dist/inject-infinite-query.mjs.map +0 -1
  33. package/dist/inject-is-fetching.mjs +0 -31
  34. package/dist/inject-is-fetching.mjs.map +0 -1
  35. package/dist/inject-is-mutating.mjs +0 -31
  36. package/dist/inject-is-mutating.mjs.map +0 -1
  37. package/dist/inject-is-restoring.mjs +0 -24
  38. package/dist/inject-is-restoring.mjs.map +0 -1
  39. package/dist/inject-mutation-state.mjs +0 -51
  40. package/dist/inject-mutation-state.mjs.map +0 -1
  41. package/dist/inject-mutation.mjs +0 -79
  42. package/dist/inject-mutation.mjs.map +0 -1
  43. package/dist/inject-queries.mjs +0 -49
  44. package/dist/inject-queries.mjs.map +0 -1
  45. package/dist/inject-query-client.mjs +0 -9
  46. package/dist/inject-query-client.mjs.map +0 -1
  47. package/dist/inject-query.mjs +0 -14
  48. package/dist/inject-query.mjs.map +0 -1
  49. package/dist/mutation-options.mjs +0 -7
  50. package/dist/mutation-options.mjs.map +0 -1
  51. package/dist/providers.mjs +0 -109
  52. package/dist/providers.mjs.map +0 -1
  53. package/dist/query-options.mjs +0 -7
  54. package/dist/query-options.mjs.map +0 -1
  55. package/dist/signal-proxy.mjs +0 -29
  56. package/dist/signal-proxy.mjs.map +0 -1
  57. package/dist-ts/eslint.config.d.ts +0 -3
  58. package/dist-ts/root.eslint.config.d.ts +0 -3
  59. package/dist-ts/src/__tests__/inject-infinite-query.test-d.d.ts +0 -2
  60. package/dist-ts/src/__tests__/inject-infinite-query.test.d.ts +0 -2
  61. package/dist-ts/src/__tests__/inject-is-fetching.test.d.ts +0 -2
  62. package/dist-ts/src/__tests__/inject-is-mutating.test.d.ts +0 -2
  63. package/dist-ts/src/__tests__/inject-mutation-state.test-d.d.ts +0 -2
  64. package/dist-ts/src/__tests__/inject-mutation-state.test.d.ts +0 -2
  65. package/dist-ts/src/__tests__/inject-mutation.test-d.d.ts +0 -2
  66. package/dist-ts/src/__tests__/inject-mutation.test.d.ts +0 -2
  67. package/dist-ts/src/__tests__/inject-query.test-d.d.ts +0 -2
  68. package/dist-ts/src/__tests__/inject-query.test.d.ts +0 -2
  69. package/dist-ts/src/__tests__/mutation-options.test-d.d.ts +0 -2
  70. package/dist-ts/src/__tests__/provide-query-client.test.d.ts +0 -2
  71. package/dist-ts/src/__tests__/provide-tanstack-query.test.d.ts +0 -2
  72. package/dist-ts/src/__tests__/providers.test.d.ts +0 -2
  73. package/dist-ts/src/__tests__/query-options.test-d.d.ts +0 -2
  74. package/dist-ts/src/__tests__/signal-proxy.test.d.ts +0 -2
  75. package/dist-ts/src/__tests__/test-utils.d.ts +0 -16
  76. package/dist-ts/src/create-base-query.d.ts +0 -9
  77. package/dist-ts/src/index.d.ts +0 -27
  78. package/dist-ts/src/infinite-query-options.d.ts +0 -45
  79. package/dist-ts/src/inject-infinite-query.d.ts +0 -40
  80. package/dist-ts/src/inject-is-fetching.d.ts +0 -23
  81. package/dist-ts/src/inject-is-mutating.d.ts +0 -22
  82. package/dist-ts/src/inject-mutation-state.d.ts +0 -28
  83. package/dist-ts/src/inject-mutation.d.ts +0 -23
  84. package/dist-ts/src/inject-queries.d.ts +0 -78
  85. package/dist-ts/src/providers.d.ts +0 -217
  86. package/dist-ts/src/query-options.d.ts +0 -88
  87. package/dist-ts/src/signal-proxy.d.ts +0 -12
  88. package/dist-ts/src/test-setup.d.ts +0 -2
  89. package/dist-ts/src/types.d.ts +0 -90
  90. package/dist-ts/src/util/is-dev-mode/is-dev-mode.d.ts +0 -2
  91. package/dist-ts/vite.config.d.ts +0 -5
@@ -0,0 +1,271 @@
1
+ import {
2
+ QueriesObserver,
3
+ QueryClient,
4
+ notifyManager,
5
+ } from '@tanstack/query-core'
6
+ import {
7
+ DestroyRef,
8
+ Injector,
9
+ NgZone,
10
+ assertInInjectionContext,
11
+ computed,
12
+ effect,
13
+ inject,
14
+ runInInjectionContext,
15
+ signal,
16
+ } from '@angular/core'
17
+ import { injectIsRestoring } from './inject-is-restoring'
18
+ import type { Signal } from '@angular/core'
19
+ import type {
20
+ DefaultError,
21
+ OmitKeyof,
22
+ QueriesObserverOptions,
23
+ QueriesPlaceholderDataFunction,
24
+ QueryFunction,
25
+ QueryKey,
26
+ QueryObserverOptions,
27
+ QueryObserverResult,
28
+ ThrowOnError,
29
+ } from '@tanstack/query-core'
30
+
31
+ // This defines the `CreateQueryOptions` that are accepted in `QueriesOptions` & `GetOptions`.
32
+ // `placeholderData` function does not have a parameter
33
+ type QueryObserverOptionsForCreateQueries<
34
+ TQueryFnData = unknown,
35
+ TError = DefaultError,
36
+ TData = TQueryFnData,
37
+ TQueryKey extends QueryKey = QueryKey,
38
+ > = OmitKeyof<
39
+ QueryObserverOptions<TQueryFnData, TError, TData, TQueryFnData, TQueryKey>,
40
+ 'placeholderData'
41
+ > & {
42
+ placeholderData?: TQueryFnData | QueriesPlaceholderDataFunction<TQueryFnData>
43
+ }
44
+
45
+ // Avoid TS depth-limit error in case of large array literal
46
+ type MAXIMUM_DEPTH = 20
47
+
48
+ // Widen the type of the symbol to enable type inference even if skipToken is not immutable.
49
+ type SkipTokenForUseQueries = symbol
50
+
51
+ type GetOptions<T> =
52
+ // Part 1: responsible for applying explicit type parameter to function arguments, if object { queryFnData: TQueryFnData, error: TError, data: TData }
53
+ T extends {
54
+ queryFnData: infer TQueryFnData
55
+ error?: infer TError
56
+ data: infer TData
57
+ }
58
+ ? QueryObserverOptionsForCreateQueries<TQueryFnData, TError, TData>
59
+ : T extends { queryFnData: infer TQueryFnData; error?: infer TError }
60
+ ? QueryObserverOptionsForCreateQueries<TQueryFnData, TError>
61
+ : T extends { data: infer TData; error?: infer TError }
62
+ ? QueryObserverOptionsForCreateQueries<unknown, TError, TData>
63
+ : // Part 2: responsible for applying explicit type parameter to function arguments, if tuple [TQueryFnData, TError, TData]
64
+ T extends [infer TQueryFnData, infer TError, infer TData]
65
+ ? QueryObserverOptionsForCreateQueries<TQueryFnData, TError, TData>
66
+ : T extends [infer TQueryFnData, infer TError]
67
+ ? QueryObserverOptionsForCreateQueries<TQueryFnData, TError>
68
+ : T extends [infer TQueryFnData]
69
+ ? QueryObserverOptionsForCreateQueries<TQueryFnData>
70
+ : // Part 3: responsible for inferring and enforcing type if no explicit parameter was provided
71
+ T extends {
72
+ queryFn?:
73
+ | QueryFunction<infer TQueryFnData, infer TQueryKey>
74
+ | SkipTokenForUseQueries
75
+ select: (data: any) => infer TData
76
+ throwOnError?: ThrowOnError<any, infer TError, any, any>
77
+ }
78
+ ? QueryObserverOptionsForCreateQueries<
79
+ TQueryFnData,
80
+ unknown extends TError ? DefaultError : TError,
81
+ unknown extends TData ? TQueryFnData : TData,
82
+ TQueryKey
83
+ >
84
+ : // Fallback
85
+ QueryObserverOptionsForCreateQueries
86
+
87
+ type GetResults<T> =
88
+ // Part 1: responsible for mapping explicit type parameter to function result, if object
89
+ T extends { queryFnData: any; error?: infer TError; data: infer TData }
90
+ ? QueryObserverResult<TData, TError>
91
+ : T extends { queryFnData: infer TQueryFnData; error?: infer TError }
92
+ ? QueryObserverResult<TQueryFnData, TError>
93
+ : T extends { data: infer TData; error?: infer TError }
94
+ ? QueryObserverResult<TData, TError>
95
+ : // Part 2: responsible for mapping explicit type parameter to function result, if tuple
96
+ T extends [any, infer TError, infer TData]
97
+ ? QueryObserverResult<TData, TError>
98
+ : T extends [infer TQueryFnData, infer TError]
99
+ ? QueryObserverResult<TQueryFnData, TError>
100
+ : T extends [infer TQueryFnData]
101
+ ? QueryObserverResult<TQueryFnData>
102
+ : // Part 3: responsible for mapping inferred type to results, if no explicit parameter was provided
103
+ T extends {
104
+ queryFn?:
105
+ | QueryFunction<infer TQueryFnData, any>
106
+ | SkipTokenForUseQueries
107
+ select: (data: any) => infer TData
108
+ throwOnError?: ThrowOnError<any, infer TError, any, any>
109
+ }
110
+ ? QueryObserverResult<
111
+ unknown extends TData ? TQueryFnData : TData,
112
+ unknown extends TError ? DefaultError : TError
113
+ >
114
+ : // Fallback
115
+ QueryObserverResult
116
+
117
+ /**
118
+ * QueriesOptions reducer recursively unwraps function arguments to infer/enforce type param
119
+ * @public
120
+ */
121
+ export type QueriesOptions<
122
+ T extends Array<any>,
123
+ TResult extends Array<any> = [],
124
+ TDepth extends ReadonlyArray<number> = [],
125
+ > = TDepth['length'] extends MAXIMUM_DEPTH
126
+ ? Array<QueryObserverOptionsForCreateQueries>
127
+ : T extends []
128
+ ? []
129
+ : T extends [infer Head]
130
+ ? [...TResult, GetOptions<Head>]
131
+ : T extends [infer Head, ...infer Tail]
132
+ ? QueriesOptions<
133
+ [...Tail],
134
+ [...TResult, GetOptions<Head>],
135
+ [...TDepth, 1]
136
+ >
137
+ : ReadonlyArray<unknown> extends T
138
+ ? T
139
+ : // If T is *some* array but we couldn't assign unknown[] to it, then it must hold some known/homogenous type!
140
+ // use this to infer the param types in the case of Array.map() argument
141
+ T extends Array<
142
+ QueryObserverOptionsForCreateQueries<
143
+ infer TQueryFnData,
144
+ infer TError,
145
+ infer TData,
146
+ infer TQueryKey
147
+ >
148
+ >
149
+ ? Array<
150
+ QueryObserverOptionsForCreateQueries<
151
+ TQueryFnData,
152
+ TError,
153
+ TData,
154
+ TQueryKey
155
+ >
156
+ >
157
+ : // Fallback
158
+ Array<QueryObserverOptionsForCreateQueries>
159
+
160
+ /**
161
+ * QueriesResults reducer recursively maps type param to results
162
+ * @public
163
+ */
164
+ export type QueriesResults<
165
+ T extends Array<any>,
166
+ TResult extends Array<any> = [],
167
+ TDepth extends ReadonlyArray<number> = [],
168
+ > = TDepth['length'] extends MAXIMUM_DEPTH
169
+ ? Array<QueryObserverResult>
170
+ : T extends []
171
+ ? []
172
+ : T extends [infer Head]
173
+ ? [...TResult, GetResults<Head>]
174
+ : T extends [infer Head, ...infer Tail]
175
+ ? QueriesResults<
176
+ [...Tail],
177
+ [...TResult, GetResults<Head>],
178
+ [...TDepth, 1]
179
+ >
180
+ : T extends Array<
181
+ QueryObserverOptionsForCreateQueries<
182
+ infer TQueryFnData,
183
+ infer TError,
184
+ infer TData,
185
+ any
186
+ >
187
+ >
188
+ ? // Dynamic-size (homogenous) CreateQueryOptions array: map directly to array of results
189
+ Array<
190
+ QueryObserverResult<
191
+ unknown extends TData ? TQueryFnData : TData,
192
+ unknown extends TError ? DefaultError : TError
193
+ >
194
+ >
195
+ : // Fallback
196
+ Array<QueryObserverResult>
197
+
198
+ /**
199
+ * @param root0
200
+ * @param root0.queries
201
+ * @param root0.combine
202
+ * @param injector
203
+ * @param injector
204
+ * @public
205
+ */
206
+ export function injectQueries<
207
+ T extends Array<any>,
208
+ TCombinedResult = QueriesResults<T>,
209
+ >(
210
+ {
211
+ queries,
212
+ ...options
213
+ }: {
214
+ queries: Signal<[...QueriesOptions<T>]>
215
+ combine?: (result: QueriesResults<T>) => TCombinedResult
216
+ },
217
+ injector?: Injector,
218
+ ): Signal<TCombinedResult> {
219
+ !injector && assertInInjectionContext(injectQueries)
220
+ return runInInjectionContext(injector ?? inject(Injector), () => {
221
+ const destroyRef = inject(DestroyRef)
222
+ const ngZone = inject(NgZone)
223
+ const queryClient = inject(QueryClient)
224
+ const isRestoring = injectIsRestoring()
225
+
226
+ const defaultedQueries = computed(() => {
227
+ return queries().map((opts) => {
228
+ const defaultedOptions = queryClient.defaultQueryOptions(opts)
229
+ // Make sure the results are already in fetching state before subscribing or updating options
230
+ defaultedOptions._optimisticResults = isRestoring()
231
+ ? 'isRestoring'
232
+ : 'optimistic'
233
+
234
+ return defaultedOptions as QueryObserverOptions
235
+ })
236
+ })
237
+
238
+ const observer = new QueriesObserver<TCombinedResult>(
239
+ queryClient,
240
+ defaultedQueries(),
241
+ options as QueriesObserverOptions<TCombinedResult>,
242
+ )
243
+
244
+ // Do not notify on updates because of changes in the options because
245
+ // these changes should already be reflected in the optimistic result.
246
+ effect(() => {
247
+ observer.setQueries(
248
+ defaultedQueries(),
249
+ options as QueriesObserverOptions<TCombinedResult>,
250
+ )
251
+ })
252
+
253
+ const [, getCombinedResult] = observer.getOptimisticResult(
254
+ defaultedQueries(),
255
+ (options as QueriesObserverOptions<TCombinedResult>).combine,
256
+ )
257
+
258
+ const result = signal(getCombinedResult() as any)
259
+
260
+ effect(() => {
261
+ const unsubscribe = isRestoring()
262
+ ? () => undefined
263
+ : ngZone.runOutsideAngular(() =>
264
+ observer.subscribe(notifyManager.batchCalls(result.set)),
265
+ )
266
+ destroyRef.onDestroy(unsubscribe)
267
+ })
268
+
269
+ return result
270
+ })
271
+ }
@@ -1,6 +1,7 @@
1
- import { Injector } from '@angular/core';
2
- import { QueryClient } from '@tanstack/query-core';
3
- import type { InjectOptions } from '@angular/core';
1
+ import { Injector, inject } from '@angular/core'
2
+ import { QueryClient } from '@tanstack/query-core'
3
+ import type { InjectOptions } from '@angular/core'
4
+
4
5
  /**
5
6
  * Injects a `QueryClient` instance and allows passing a custom injector.
6
7
  * @param injectOptions - Type of the options argument to inject and optionally a custom injector.
@@ -15,7 +16,8 @@ import type { InjectOptions } from '@angular/core';
15
16
  * const queryClient = injectQueryClient();
16
17
  * ```
17
18
  */
18
- export declare function injectQueryClient(injectOptions?: InjectOptions & {
19
- injector?: Injector;
20
- }): QueryClient;
21
- //# sourceMappingURL=inject-query-client.d.ts.map
19
+ export function injectQueryClient(
20
+ injectOptions: InjectOptions & { injector?: Injector } = {},
21
+ ) {
22
+ return (injectOptions.injector ?? inject(Injector)).get(QueryClient)
23
+ }
@@ -1,15 +1,31 @@
1
- import { Injector } from '@angular/core';
2
- import type { DefaultError, QueryKey } from '@tanstack/query-core';
3
- import type { CreateQueryOptions, CreateQueryResult, DefinedCreateQueryResult } from './types';
4
- import type { DefinedInitialDataOptions, UndefinedInitialDataOptions } from './query-options';
1
+ import { QueryObserver } from '@tanstack/query-core'
2
+ import {
3
+ Injector,
4
+ assertInInjectionContext,
5
+ inject,
6
+ runInInjectionContext,
7
+ } from '@angular/core'
8
+ import { createBaseQuery } from './create-base-query'
9
+ import type { DefaultError, QueryKey } from '@tanstack/query-core'
10
+ import type {
11
+ CreateQueryOptions,
12
+ CreateQueryResult,
13
+ DefinedCreateQueryResult,
14
+ } from './types'
15
+ import type {
16
+ DefinedInitialDataOptions,
17
+ UndefinedInitialDataOptions,
18
+ } from './query-options'
19
+
5
20
  export interface InjectQueryOptions {
6
- /**
7
- * The `Injector` in which to create the query.
8
- *
9
- * If this is not provided, the current injection context will be used instead (via `inject`).
10
- */
11
- injector?: Injector;
21
+ /**
22
+ * The `Injector` in which to create the query.
23
+ *
24
+ * If this is not provided, the current injection context will be used instead (via `inject`).
25
+ */
26
+ injector?: Injector
12
27
  }
28
+
13
29
  /**
14
30
  * Injects a query: a declarative dependency on an asynchronous source of data that is tied to a unique key.
15
31
  *
@@ -47,7 +63,21 @@ export interface InjectQueryOptions {
47
63
  * @public
48
64
  * @see https://tanstack.com/query/latest/docs/framework/angular/guides/queries
49
65
  */
50
- export declare function injectQuery<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey>(injectQueryFn: () => DefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey>, options?: InjectQueryOptions): DefinedCreateQueryResult<TData, TError>;
66
+ export function injectQuery<
67
+ TQueryFnData = unknown,
68
+ TError = DefaultError,
69
+ TData = TQueryFnData,
70
+ TQueryKey extends QueryKey = QueryKey,
71
+ >(
72
+ injectQueryFn: () => DefinedInitialDataOptions<
73
+ TQueryFnData,
74
+ TError,
75
+ TData,
76
+ TQueryKey
77
+ >,
78
+ options?: InjectQueryOptions,
79
+ ): DefinedCreateQueryResult<TData, TError>
80
+
51
81
  /**
52
82
  * Injects a query: a declarative dependency on an asynchronous source of data that is tied to a unique key.
53
83
  *
@@ -85,7 +115,21 @@ export declare function injectQuery<TQueryFnData = unknown, TError = DefaultErro
85
115
  * @public
86
116
  * @see https://tanstack.com/query/latest/docs/framework/angular/guides/queries
87
117
  */
88
- export declare function injectQuery<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey>(injectQueryFn: () => UndefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey>, options?: InjectQueryOptions): CreateQueryResult<TData, TError>;
118
+ export function injectQuery<
119
+ TQueryFnData = unknown,
120
+ TError = DefaultError,
121
+ TData = TQueryFnData,
122
+ TQueryKey extends QueryKey = QueryKey,
123
+ >(
124
+ injectQueryFn: () => UndefinedInitialDataOptions<
125
+ TQueryFnData,
126
+ TError,
127
+ TData,
128
+ TQueryKey
129
+ >,
130
+ options?: InjectQueryOptions,
131
+ ): CreateQueryResult<TData, TError>
132
+
89
133
  /**
90
134
  * Injects a query: a declarative dependency on an asynchronous source of data that is tied to a unique key.
91
135
  *
@@ -123,5 +167,64 @@ export declare function injectQuery<TQueryFnData = unknown, TError = DefaultErro
123
167
  * @public
124
168
  * @see https://tanstack.com/query/latest/docs/framework/angular/guides/queries
125
169
  */
126
- export declare function injectQuery<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey>(injectQueryFn: () => CreateQueryOptions<TQueryFnData, TError, TData, TQueryKey>, options?: InjectQueryOptions): CreateQueryResult<TData, TError>;
127
- //# sourceMappingURL=inject-query.d.ts.map
170
+ export function injectQuery<
171
+ TQueryFnData = unknown,
172
+ TError = DefaultError,
173
+ TData = TQueryFnData,
174
+ TQueryKey extends QueryKey = QueryKey,
175
+ >(
176
+ injectQueryFn: () => CreateQueryOptions<
177
+ TQueryFnData,
178
+ TError,
179
+ TData,
180
+ TQueryKey
181
+ >,
182
+ options?: InjectQueryOptions,
183
+ ): CreateQueryResult<TData, TError>
184
+
185
+ /**
186
+ * Injects a query: a declarative dependency on an asynchronous source of data that is tied to a unique key.
187
+ *
188
+ * **Basic example**
189
+ * ```ts
190
+ * class ServiceOrComponent {
191
+ * query = injectQuery(() => ({
192
+ * queryKey: ['repoData'],
193
+ * queryFn: () =>
194
+ * this.#http.get<Response>('https://api.github.com/repos/tanstack/query'),
195
+ * }))
196
+ * }
197
+ * ```
198
+ *
199
+ * Similar to `computed` from Angular, the function passed to `injectQuery` will be run in the reactive context.
200
+ * In the example below, the query will be automatically enabled and executed when the filter signal changes
201
+ * to a truthy value. When the filter signal changes back to a falsy value, the query will be disabled.
202
+ *
203
+ * **Reactive example**
204
+ * ```ts
205
+ * class ServiceOrComponent {
206
+ * filter = signal('')
207
+ *
208
+ * todosQuery = injectQuery(() => ({
209
+ * queryKey: ['todos', this.filter()],
210
+ * queryFn: () => fetchTodos(this.filter()),
211
+ * // Signals can be combined with expressions
212
+ * enabled: !!this.filter(),
213
+ * }))
214
+ * }
215
+ * ```
216
+ * @param injectQueryFn - A function that returns query options.
217
+ * @param options - Additional configuration
218
+ * @returns The query result.
219
+ * @public
220
+ * @see https://tanstack.com/query/latest/docs/framework/angular/guides/queries
221
+ */
222
+ export function injectQuery(
223
+ injectQueryFn: () => CreateQueryOptions,
224
+ options?: InjectQueryOptions,
225
+ ) {
226
+ !options?.injector && assertInInjectionContext(injectQuery)
227
+ return runInInjectionContext(options?.injector ?? inject(Injector), () =>
228
+ createBaseQuery(injectQueryFn, QueryObserver),
229
+ ) as unknown as CreateQueryResult
230
+ }
@@ -1,4 +1,9 @@
1
- import type { DefaultError, MutationObserverOptions, OmitKeyof } from '@tanstack/query-core';
1
+ import type {
2
+ DefaultError,
3
+ MutationObserverOptions,
4
+ OmitKeyof,
5
+ } from '@tanstack/query-core'
6
+
2
7
  /**
3
8
  * Allows to share and re-use mutation options in a type-safe way.
4
9
  *
@@ -30,10 +35,26 @@ import type { DefaultError, MutationObserverOptions, OmitKeyof } from '@tanstack
30
35
  * @returns Mutation options.
31
36
  * @public
32
37
  */
33
- export declare function mutationOptions<TData = unknown, TError = DefaultError, TVariables = void, TContext = unknown>(options: MutationObserverOptions<TData, TError, TVariables, TContext>): CreateMutationOptions<TData, TError, TVariables, TContext>;
38
+ export function mutationOptions<
39
+ TData = unknown,
40
+ TError = DefaultError,
41
+ TVariables = void,
42
+ TContext = unknown,
43
+ >(
44
+ options: MutationObserverOptions<TData, TError, TVariables, TContext>,
45
+ ): CreateMutationOptions<TData, TError, TVariables, TContext> {
46
+ return options
47
+ }
48
+
34
49
  /**
35
50
  * @public
36
51
  */
37
- export interface CreateMutationOptions<TData = unknown, TError = DefaultError, TVariables = void, TContext = unknown> extends OmitKeyof<MutationObserverOptions<TData, TError, TVariables, TContext>, '_defaulted'> {
38
- }
39
- //# sourceMappingURL=mutation-options.d.ts.map
52
+ export interface CreateMutationOptions<
53
+ TData = unknown,
54
+ TError = DefaultError,
55
+ TVariables = void,
56
+ TContext = unknown,
57
+ > extends OmitKeyof<
58
+ MutationObserverOptions<TData, TError, TVariables, TContext>,
59
+ '_defaulted'
60
+ > {}