@tanstack/angular-query-experimental 5.34.2 → 5.35.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 (59) hide show
  1. package/build/rollup.d.ts +591 -0
  2. package/package.json +9 -5
  3. package/build/create-base-query.d.ts +0 -6
  4. package/build/index.d.ts +0 -14
  5. package/build/infinite-query-options.d.ts +0 -34
  6. package/build/inject-infinite-query.d.ts +0 -31
  7. package/build/inject-is-fetching.d.ts +0 -13
  8. package/build/inject-is-mutating.d.ts +0 -12
  9. package/build/inject-mutation-state.d.ts +0 -21
  10. package/build/inject-mutation.d.ts +0 -13
  11. package/build/inject-queries.d.ts +0 -76
  12. package/build/inject-query-client.d.ts +0 -30
  13. package/build/inject-query.d.ts +0 -106
  14. package/build/providers.d.ts +0 -42
  15. package/build/query-options.d.ts +0 -66
  16. package/build/signal-proxy.d.ts +0 -11
  17. package/build/types.d.ts +0 -95
  18. package/build/util/assert-injector/assert-injector.d.ts +0 -54
  19. package/build/util/create-injection-token/create-injection-token.d.ts +0 -52
  20. package/build/util/index.d.ts +0 -2
  21. package/build/util/lazy-init/lazy-init.d.ts +0 -1
  22. package/build/util/lazy-signal-initializer/lazy-signal-initializer.d.ts +0 -4
  23. package/src/__tests__/inject-infinite-query.test.ts +0 -64
  24. package/src/__tests__/inject-is-fetching.test.ts +0 -35
  25. package/src/__tests__/inject-is-mutating.test.ts +0 -39
  26. package/src/__tests__/inject-mutation-state.test-d.ts +0 -22
  27. package/src/__tests__/inject-mutation-state.test.ts +0 -175
  28. package/src/__tests__/inject-mutation.test-d.ts +0 -71
  29. package/src/__tests__/inject-mutation.test.ts +0 -458
  30. package/src/__tests__/inject-query.test-d.ts +0 -59
  31. package/src/__tests__/inject-query.test.ts +0 -349
  32. package/src/__tests__/query-options.test-d.ts +0 -127
  33. package/src/__tests__/signal-proxy.test.ts +0 -27
  34. package/src/__tests__/test-utils.ts +0 -131
  35. package/src/__tests__/util/lazy-init/lazy-init.test.ts +0 -126
  36. package/src/__tests__/util/lazy-signal-initializer/lazy-signal-initializer.test.ts +0 -130
  37. package/src/create-base-query.ts +0 -116
  38. package/src/index.ts +0 -24
  39. package/src/infinite-query-options.ts +0 -118
  40. package/src/inject-infinite-query.ts +0 -125
  41. package/src/inject-is-fetching.ts +0 -49
  42. package/src/inject-is-mutating.ts +0 -48
  43. package/src/inject-mutation-state.ts +0 -107
  44. package/src/inject-mutation.ts +0 -118
  45. package/src/inject-queries.ts +0 -265
  46. package/src/inject-query-client.ts +0 -25
  47. package/src/inject-query.ts +0 -200
  48. package/src/providers.ts +0 -65
  49. package/src/query-options.ts +0 -122
  50. package/src/signal-proxy.ts +0 -46
  51. package/src/test-setup.ts +0 -12
  52. package/src/types.ts +0 -311
  53. package/src/util/assert-injector/assert-injector.test.ts +0 -74
  54. package/src/util/assert-injector/assert-injector.ts +0 -81
  55. package/src/util/create-injection-token/create-injection-token.test.ts +0 -32
  56. package/src/util/create-injection-token/create-injection-token.ts +0 -185
  57. package/src/util/index.ts +0 -13
  58. package/src/util/lazy-init/lazy-init.ts +0 -34
  59. package/src/util/lazy-signal-initializer/lazy-signal-initializer.ts +0 -28
@@ -0,0 +1,591 @@
1
+ import type { DataTag } from '@tanstack/query-core';
2
+ import { DefaultError } from '@tanstack/query-core';
3
+ import type { DefinedInfiniteQueryObserverResult } from '@tanstack/query-core';
4
+ import type { DefinedQueryObserverResult } from '@tanstack/query-core';
5
+ import type { EnvironmentProviders } from '@angular/core';
6
+ import type { InfiniteData } from '@tanstack/query-core';
7
+ import type { InfiniteQueryObserverOptions } from '@tanstack/query-core';
8
+ import type { InfiniteQueryObserverResult } from '@tanstack/query-core';
9
+ import { InjectOptions } from '@angular/core';
10
+ import { Injector } from '@angular/core';
11
+ import type { MutateFunction } from '@tanstack/query-core';
12
+ import { Mutation } from '@tanstack/query-core';
13
+ import { MutationFilters } from '@tanstack/query-core';
14
+ import type { MutationObserverOptions } from '@tanstack/query-core';
15
+ import type { MutationObserverResult } from '@tanstack/query-core';
16
+ import { MutationState } from '@tanstack/query-core';
17
+ import type { OmitKeyof } from '@tanstack/query-core';
18
+ import { Provider } from '@angular/core';
19
+ import type { QueriesPlaceholderDataFunction } from '@tanstack/query-core';
20
+ import type { QueryClient } from '@tanstack/query-core';
21
+ import { QueryFilters } from '@tanstack/query-core';
22
+ import type { QueryFunction } from '@tanstack/query-core';
23
+ import type { QueryKey } from '@tanstack/query-core';
24
+ import type { QueryObserverOptions } from '@tanstack/query-core';
25
+ import type { QueryObserverResult } from '@tanstack/query-core';
26
+ import type { Signal } from '@angular/core';
27
+ import type { SkipToken } from '@tanstack/query-core';
28
+ import type { ThrowOnError } from '@tanstack/query-core';
29
+
30
+ /**
31
+ * @public
32
+ */
33
+ export declare interface BaseMutationNarrowing<TData = unknown, TError = DefaultError, TVariables = unknown, TContext = unknown> {
34
+ isSuccess: (this: CreateMutationResult<TData, TError, TVariables, TContext>) => this is CreateMutationResult<TData, TError, TVariables, TContext, CreateStatusBasedMutationResult<'success', TData, TError, TVariables, TContext>>;
35
+ isError: (this: CreateMutationResult<TData, TError, TVariables, TContext>) => this is CreateMutationResult<TData, TError, TVariables, TContext, CreateStatusBasedMutationResult<'error', TData, TError, TVariables, TContext>>;
36
+ isPending: (this: CreateMutationResult<TData, TError, TVariables, TContext>) => this is CreateMutationResult<TData, TError, TVariables, TContext, CreateStatusBasedMutationResult<'pending', TData, TError, TVariables, TContext>>;
37
+ isIdle: (this: CreateMutationResult<TData, TError, TVariables, TContext>) => this is CreateMutationResult<TData, TError, TVariables, TContext, CreateStatusBasedMutationResult<'idle', TData, TError, TVariables, TContext>>;
38
+ }
39
+
40
+ /**
41
+ * @public
42
+ */
43
+ export declare interface BaseQueryNarrowing<TData = unknown, TError = DefaultError> {
44
+ isSuccess: (this: CreateBaseQueryResult<TData, TError>) => this is CreateBaseQueryResult<TData, TError, CreateStatusBasedQueryResult<'success', TData, TError>>;
45
+ isError: (this: CreateBaseQueryResult<TData, TError>) => this is CreateBaseQueryResult<TData, TError, CreateStatusBasedQueryResult<'error', TData, TError>>;
46
+ isPending: (this: CreateBaseQueryResult<TData, TError>) => this is CreateBaseQueryResult<TData, TError, CreateStatusBasedQueryResult<'pending', TData, TError>>;
47
+ }
48
+
49
+ /**
50
+ * @public
51
+ */
52
+ export declare type CreateBaseMutationResult<TData = unknown, TError = DefaultError, TVariables = unknown, TContext = unknown> = Override<MutationObserverResult<TData, TError, TVariables, TContext>, {
53
+ mutate: CreateMutateFunction<TData, TError, TVariables, TContext>;
54
+ }> & {
55
+ mutateAsync: CreateMutateAsyncFunction<TData, TError, TVariables, TContext>;
56
+ };
57
+
58
+ /**
59
+ * @public
60
+ */
61
+ export declare interface CreateBaseQueryOptions<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryData = TQueryFnData, TQueryKey extends QueryKey = QueryKey> extends QueryObserverOptions<TQueryFnData, TError, TData, TQueryData, TQueryKey> {
62
+ }
63
+
64
+ /**
65
+ * @public
66
+ */
67
+ export declare type CreateBaseQueryResult<TData = unknown, TError = DefaultError, TState = QueryObserverResult<TData, TError>> = BaseQueryNarrowing<TData, TError> & MapToSignals<OmitKeyof<TState, keyof BaseQueryNarrowing, 'safely'>>;
68
+
69
+ /**
70
+ * @public
71
+ */
72
+ export declare interface CreateInfiniteQueryOptions<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryData = TQueryFnData, TQueryKey extends QueryKey = QueryKey, TPageParam = unknown> extends OmitKeyof<InfiniteQueryObserverOptions<TQueryFnData, TError, TData, TQueryData, TQueryKey, TPageParam>, 'suspense'> {
73
+ }
74
+
75
+ /**
76
+ * @public
77
+ */
78
+ export declare type CreateInfiniteQueryResult<TData = unknown, TError = DefaultError> = MapToSignals<InfiniteQueryObserverResult<TData, TError>>;
79
+
80
+ /**
81
+ * @public
82
+ */
83
+ export declare type CreateMutateAsyncFunction<TData = unknown, TError = DefaultError, TVariables = void, TContext = unknown> = MutateFunction<TData, TError, TVariables, TContext>;
84
+
85
+ /**
86
+ * @public
87
+ */
88
+ export declare type CreateMutateFunction<TData = unknown, TError = DefaultError, TVariables = void, TContext = unknown> = (...args: Parameters<MutateFunction<TData, TError, TVariables, TContext>>) => void;
89
+
90
+ /**
91
+ * @public
92
+ */
93
+ export declare interface CreateMutationOptions<TData = unknown, TError = DefaultError, TVariables = void, TContext = unknown> extends OmitKeyof<MutationObserverOptions<TData, TError, TVariables, TContext>, '_defaulted'> {
94
+ }
95
+
96
+ /**
97
+ * @public
98
+ */
99
+ export declare type CreateMutationResult<TData = unknown, TError = DefaultError, TVariables = unknown, TContext = unknown, TState = CreateStatusBasedMutationResult<CreateBaseMutationResult['status'], TData, TError, TVariables, TContext>> = BaseMutationNarrowing<TData, TError, TVariables, TContext> & MapToSignals<OmitKeyof<TState, keyof BaseMutationNarrowing, 'safely'>>;
100
+
101
+ /**
102
+ * @public
103
+ */
104
+ export declare interface CreateQueryOptions<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey> extends OmitKeyof<CreateBaseQueryOptions<TQueryFnData, TError, TData, TQueryFnData, TQueryKey>, 'suspense'> {
105
+ }
106
+
107
+ /**
108
+ * @public
109
+ */
110
+ export declare type CreateQueryResult<TData = unknown, TError = DefaultError> = CreateBaseQueryResult<TData, TError>;
111
+
112
+ /**
113
+ * @public
114
+ */
115
+ declare type CreateStatusBasedMutationResult<TStatus extends CreateBaseMutationResult['status'], TData = unknown, TError = DefaultError, TVariables = unknown, TContext = unknown> = Extract<CreateBaseMutationResult<TData, TError, TVariables, TContext>, {
116
+ status: TStatus;
117
+ }>;
118
+
119
+ /**
120
+ * @public
121
+ */
122
+ declare type CreateStatusBasedQueryResult<TStatus extends QueryObserverResult['status'], TData = unknown, TError = DefaultError> = Extract<QueryObserverResult<TData, TError>, {
123
+ status: TStatus;
124
+ }>;
125
+
126
+ /**
127
+ * @public
128
+ */
129
+ export declare type DefinedCreateInfiniteQueryResult<TData = unknown, TError = DefaultError, TDefinedInfiniteQueryObserver = DefinedInfiniteQueryObserverResult<TData, TError>> = MapToSignals<TDefinedInfiniteQueryObserver>;
130
+
131
+ /**
132
+ * @public
133
+ */
134
+ export declare type DefinedCreateQueryResult<TData = unknown, TError = DefaultError, TDefinedQueryObserver = DefinedQueryObserverResult<TData, TError>> = MapToSignals<TDefinedQueryObserver>;
135
+
136
+ declare type DefinedInitialDataInfiniteOptions<TQueryFnData, TError = DefaultError, TData = InfiniteData<TQueryFnData>, TQueryKey extends QueryKey = QueryKey, TPageParam = unknown> = CreateInfiniteQueryOptions<TQueryFnData, TError, TData, TQueryFnData, TQueryKey, TPageParam> & {
137
+ initialData: NonUndefinedGuard_2<InfiniteData<TQueryFnData, TPageParam>> | (() => NonUndefinedGuard_2<InfiniteData<TQueryFnData, TPageParam>>);
138
+ };
139
+
140
+ /**
141
+ * @public
142
+ */
143
+ export declare type DefinedInitialDataOptions<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey> = CreateQueryOptions<TQueryFnData, TError, TData, TQueryKey> & {
144
+ initialData: NonUndefinedGuard<TQueryFnData> | (() => NonUndefinedGuard<TQueryFnData>);
145
+ };
146
+
147
+ declare type GetOptions<T> = T extends {
148
+ queryFnData: infer TQueryFnData;
149
+ error?: infer TError;
150
+ data: infer TData;
151
+ } ? QueryObserverOptionsForCreateQueries<TQueryFnData, TError, TData> : T extends {
152
+ queryFnData: infer TQueryFnData;
153
+ error?: infer TError;
154
+ } ? QueryObserverOptionsForCreateQueries<TQueryFnData, TError> : T extends {
155
+ data: infer TData;
156
+ error?: infer TError;
157
+ } ? QueryObserverOptionsForCreateQueries<unknown, TError, TData> : T extends [infer TQueryFnData, infer TError, infer TData] ? QueryObserverOptionsForCreateQueries<TQueryFnData, TError, TData> : T extends [infer TQueryFnData, infer TError] ? QueryObserverOptionsForCreateQueries<TQueryFnData, TError> : T extends [infer TQueryFnData] ? QueryObserverOptionsForCreateQueries<TQueryFnData> : T extends {
158
+ queryFn?: QueryFunction<infer TQueryFnData, infer TQueryKey> | SkipToken;
159
+ select: (data: any) => infer TData;
160
+ throwOnError?: ThrowOnError<any, infer TError, any, any>;
161
+ } ? QueryObserverOptionsForCreateQueries<TQueryFnData, TError, TData, TQueryKey> : T extends {
162
+ queryFn?: QueryFunction<infer TQueryFnData, infer TQueryKey> | SkipToken;
163
+ throwOnError?: ThrowOnError<any, infer TError, any, any>;
164
+ } ? QueryObserverOptionsForCreateQueries<TQueryFnData, TError, TQueryFnData, TQueryKey> : QueryObserverOptionsForCreateQueries;
165
+
166
+ declare type GetResults<T> = T extends {
167
+ queryFnData: any;
168
+ error?: infer TError;
169
+ data: infer TData;
170
+ } ? QueryObserverResult<TData, TError> : T extends {
171
+ queryFnData: infer TQueryFnData;
172
+ error?: infer TError;
173
+ } ? QueryObserverResult<TQueryFnData, TError> : T extends {
174
+ data: infer TData;
175
+ error?: infer TError;
176
+ } ? QueryObserverResult<TData, TError> : T extends [any, infer TError, infer TData] ? QueryObserverResult<TData, TError> : T extends [infer TQueryFnData, infer TError] ? QueryObserverResult<TQueryFnData, TError> : T extends [infer TQueryFnData] ? QueryObserverResult<TQueryFnData> : T extends {
177
+ queryFn?: QueryFunction<unknown, any>;
178
+ select: (data: any) => infer TData;
179
+ throwOnError?: ThrowOnError<any, infer TError, any, any>;
180
+ } ? QueryObserverResult<TData, unknown extends TError ? DefaultError : TError> : T extends {
181
+ queryFn?: QueryFunction<infer TQueryFnData, any>;
182
+ throwOnError?: ThrowOnError<any, infer TError, any, any>;
183
+ } ? QueryObserverResult<TQueryFnData, unknown extends TError ? DefaultError : TError> : QueryObserverResult;
184
+
185
+ /**
186
+ * Allows to share and re-use infinite query options in a type-safe way.
187
+ *
188
+ * The `queryKey` will be tagged with the type from `queryFn`.
189
+ * @param options - The infinite query options to tag with the type from `queryFn`.
190
+ * @returns The tagged infinite query options.
191
+ * @public
192
+ */
193
+ export declare function infiniteQueryOptions<TQueryFnData, TError = DefaultError, TData = InfiniteData<TQueryFnData>, TQueryKey extends QueryKey = QueryKey, TPageParam = unknown>(options: UndefinedInitialDataInfiniteOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>): UndefinedInitialDataInfiniteOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam> & {
194
+ queryKey: DataTag<TQueryKey, InfiniteData<TQueryFnData>>;
195
+ };
196
+
197
+ /**
198
+ * Allows to share and re-use infinite query options in a type-safe way.
199
+ *
200
+ * The `queryKey` will be tagged with the type from `queryFn`.
201
+ * @param options - The infinite query options to tag with the type from `queryFn`.
202
+ * @returns The tagged infinite query options.
203
+ * @public
204
+ */
205
+ export declare function infiniteQueryOptions<TQueryFnData, TError = DefaultError, TData = InfiniteData<TQueryFnData>, TQueryKey extends QueryKey = QueryKey, TPageParam = unknown>(options: DefinedInitialDataInfiniteOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>): DefinedInitialDataInfiniteOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam> & {
206
+ queryKey: DataTag<TQueryKey, InfiniteData<TQueryFnData>>;
207
+ };
208
+
209
+ /**
210
+ * Injects an infinite query: a declarative dependency on an asynchronous source of data that is tied to a unique key.
211
+ * Infinite queries can additively "load more" data onto an existing set of data or "infinite scroll"
212
+ * @param optionsFn - A function that returns infinite query options.
213
+ * @param injector - The Angular injector to use.
214
+ * @returns The infinite query result.
215
+ * @public
216
+ */
217
+ export declare function injectInfiniteQuery<TQueryFnData, TError = DefaultError, TData = InfiniteData<TQueryFnData>, TQueryKey extends QueryKey = QueryKey, TPageParam = unknown>(optionsFn: (client: QueryClient) => UndefinedInitialDataInfiniteOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>, injector?: Injector): CreateInfiniteQueryResult<TData, TError>;
218
+
219
+ /**
220
+ * Injects an infinite query: a declarative dependency on an asynchronous source of data that is tied to a unique key.
221
+ * Infinite queries can additively "load more" data onto an existing set of data or "infinite scroll"
222
+ * @param optionsFn - A function that returns infinite query options.
223
+ * @param injector - The Angular injector to use.
224
+ * @returns The infinite query result.
225
+ * @public
226
+ */
227
+ export declare function injectInfiniteQuery<TQueryFnData, TError = DefaultError, TData = InfiniteData<TQueryFnData>, TQueryKey extends QueryKey = QueryKey, TPageParam = unknown>(optionsFn: (client: QueryClient) => DefinedInitialDataInfiniteOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>, injector?: Injector): DefinedCreateInfiniteQueryResult<TData, TError>;
228
+
229
+ /**
230
+ * Injects an infinite query: a declarative dependency on an asynchronous source of data that is tied to a unique key.
231
+ * Infinite queries can additively "load more" data onto an existing set of data or "infinite scroll"
232
+ * @param optionsFn - A function that returns infinite query options.
233
+ * @param injector - The Angular injector to use.
234
+ * @returns The infinite query result.
235
+ * @public
236
+ */
237
+ export declare function injectInfiniteQuery<TQueryFnData, TError = DefaultError, TData = InfiniteData<TQueryFnData>, TQueryKey extends QueryKey = QueryKey, TPageParam = unknown>(optionsFn: (client: QueryClient) => CreateInfiniteQueryOptions<TQueryFnData, TError, TData, TQueryFnData, TQueryKey, TPageParam>, injector?: Injector): CreateInfiniteQueryResult<TData, TError>;
238
+
239
+ /**
240
+ * Injects a signal that tracks the number of queries that your application is loading or
241
+ * fetching in the background.
242
+ *
243
+ * Can be used for app-wide loading indicators
244
+ * @param filters - The filters to apply to the query.
245
+ * @param injector - The Angular injector to use.
246
+ * @returns signal with number of loading or fetching queries.
247
+ * @public
248
+ */
249
+ export declare function injectIsFetching(filters?: QueryFilters, injector?: Injector): Signal<number>;
250
+
251
+ /**
252
+ * Injects a signal that tracks the number of mutations that your application is fetching.
253
+ *
254
+ * Can be used for app-wide loading indicators
255
+ * @param filters - The filters to apply to the query.
256
+ * @param injector - The Angular injector to use.
257
+ * @returns signal with number of fetching mutations.
258
+ * @public
259
+ */
260
+ export declare function injectIsMutating(filters?: MutationFilters, injector?: Injector): Signal<number>;
261
+
262
+ /**
263
+ * Injects a mutation: an imperative function that can be invoked which typically performs server side effects.
264
+ *
265
+ * Unlike queries, mutations are not run automatically.
266
+ * @param optionsFn - A function that returns mutation options.
267
+ * @param injector - The Angular injector to use.
268
+ * @returns The mutation.
269
+ * @public
270
+ */
271
+ export declare function injectMutation<TData = unknown, TError = DefaultError, TVariables = void, TContext = unknown>(optionsFn: (client: QueryClient) => CreateMutationOptions<TData, TError, TVariables, TContext>, injector?: Injector): CreateMutationResult<TData, TError, TVariables, TContext>;
272
+
273
+ /**
274
+ * Injects a signal that tracks the state of all mutations.
275
+ * @param mutationStateOptionsFn - A function that returns mutation state options.
276
+ * @param options - The Angular injector to use.
277
+ * @returns The signal that tracks the state of all mutations.
278
+ * @public
279
+ */
280
+ export declare function injectMutationState<TResult = MutationState>(mutationStateOptionsFn?: () => MutationStateOptions<TResult>, options?: InjectMutationStateOptions): Signal<Array<TResult>>;
281
+
282
+ /**
283
+ * @public
284
+ */
285
+ export declare interface InjectMutationStateOptions {
286
+ injector?: Injector;
287
+ }
288
+
289
+ /**
290
+ * @public
291
+ */
292
+ export declare function injectQueries<T extends Array<any>, TCombinedResult = QueriesResults<T>>({ queries, ...options }: {
293
+ queries: Signal<[...QueriesOptions<T>]>;
294
+ combine?: (result: QueriesResults<T>) => TCombinedResult;
295
+ }, injector?: Injector): Signal<TCombinedResult>;
296
+
297
+ /**
298
+ * Injects a query: a declarative dependency on an asynchronous source of data that is tied to a unique key.
299
+ *
300
+ * **Basic example**
301
+ * ```ts
302
+ * class ServiceOrComponent {
303
+ * query = injectQuery(() => ({
304
+ * queryKey: ['repoData'],
305
+ * queryFn: () =>
306
+ * this.#http.get<Response>('https://api.github.com/repos/tanstack/query'),
307
+ * }))
308
+ * }
309
+ * ```
310
+ *
311
+ * **The options function can utilize signals**
312
+ * ```ts
313
+ * class ServiceOrComponent {
314
+ * filter = signal('')
315
+ *
316
+ * todosQuery = injectQuery(() => ({
317
+ * queryKey: ['todos', this.filter()],
318
+ * queryFn: () => fetchTodos(this.filter()),
319
+ * // Signals can be combined with expressions
320
+ * enabled: !!this.filter(),
321
+ * }))
322
+ * }
323
+ * ```
324
+ * @param optionsFn - A function that returns query options.
325
+ * @param injector - The Angular injector to use.
326
+ * @returns The query result.
327
+ * @public
328
+ * @see https://tanstack.com/query/latest/docs/framework/angular/guides/queries
329
+ */
330
+ export declare function injectQuery<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey>(optionsFn: (client: QueryClient) => DefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey>, injector?: Injector): DefinedCreateQueryResult<TData, TError>;
331
+
332
+ /**
333
+ * Injects a query: a declarative dependency on an asynchronous source of data that is tied to a unique key.
334
+ *
335
+ * **Basic example**
336
+ * ```ts
337
+ * class ServiceOrComponent {
338
+ * query = injectQuery(() => ({
339
+ * queryKey: ['repoData'],
340
+ * queryFn: () =>
341
+ * this.#http.get<Response>('https://api.github.com/repos/tanstack/query'),
342
+ * }))
343
+ * }
344
+ * ```
345
+ *
346
+ * **The options function can utilize signals**
347
+ * ```ts
348
+ * class ServiceOrComponent {
349
+ * filter = signal('')
350
+ *
351
+ * todosQuery = injectQuery(() => ({
352
+ * queryKey: ['todos', this.filter()],
353
+ * queryFn: () => fetchTodos(this.filter()),
354
+ * // Signals can be combined with expressions
355
+ * enabled: !!this.filter(),
356
+ * }))
357
+ * }
358
+ * ```
359
+ * @param optionsFn - A function that returns query options.
360
+ * @param injector - The Angular injector to use.
361
+ * @returns The query result.
362
+ * @public
363
+ * @see https://tanstack.com/query/latest/docs/framework/angular/guides/queries
364
+ */
365
+ export declare function injectQuery<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey>(optionsFn: (client: QueryClient) => UndefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey>, injector?: Injector): CreateQueryResult<TData, TError>;
366
+
367
+ /**
368
+ * Injects a query: a declarative dependency on an asynchronous source of data that is tied to a unique key.
369
+ *
370
+ * **Basic example**
371
+ * ```ts
372
+ * class ServiceOrComponent {
373
+ * query = injectQuery(() => ({
374
+ * queryKey: ['repoData'],
375
+ * queryFn: () =>
376
+ * this.#http.get<Response>('https://api.github.com/repos/tanstack/query'),
377
+ * }))
378
+ * }
379
+ * ```
380
+ *
381
+ * **The options function can utilize signals**
382
+ * ```ts
383
+ * class ServiceOrComponent {
384
+ * filter = signal('')
385
+ *
386
+ * todosQuery = injectQuery(() => ({
387
+ * queryKey: ['todos', this.filter()],
388
+ * queryFn: () => fetchTodos(this.filter()),
389
+ * // Signals can be combined with expressions
390
+ * enabled: !!this.filter(),
391
+ * }))
392
+ * }
393
+ * ```
394
+ * @param optionsFn - A function that returns query options.
395
+ * @param injector - The Angular injector to use.
396
+ * @returns The query result.
397
+ * @public
398
+ * @see https://tanstack.com/query/latest/docs/framework/angular/guides/queries
399
+ */
400
+ export declare function injectQuery<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey>(optionsFn: (client: QueryClient) => CreateQueryOptions<TQueryFnData, TError, TData, TQueryKey>, injector?: Injector): CreateQueryResult<TData, TError>;
401
+
402
+ /**
403
+ * Injects the `QueryClient` instance into the component or service.
404
+ *
405
+ * **Example**
406
+ * ```ts
407
+ * const queryClient = injectQueryClient();
408
+ * ```
409
+ * @returns The `QueryClient` instance.
410
+ * @public
411
+ */
412
+ export declare const injectQueryClient: {
413
+ (): QueryClient;
414
+ (injectOptions: InjectOptions & {
415
+ optional?: false;
416
+ } & {
417
+ injector?: Injector;
418
+ }): QueryClient;
419
+ (injectOptions: InjectOptions & {
420
+ injector?: Injector;
421
+ }): QueryClient;
422
+ };
423
+
424
+ declare type MapToSignals<T> = {
425
+ [K in keyof T]: T[K] extends Function ? T[K] : Signal<T[K]>;
426
+ };
427
+
428
+ declare type MAXIMUM_DEPTH = 20;
429
+
430
+ declare type MutationStateOptions<TResult = MutationState> = {
431
+ filters?: MutationFilters;
432
+ select?: (mutation: Mutation<unknown, DefaultError, unknown, unknown>) => TResult;
433
+ };
434
+
435
+ declare type NonUndefinedGuard<T> = T extends undefined ? never : T;
436
+
437
+ declare type NonUndefinedGuard_2<T> = T extends undefined ? never : T;
438
+
439
+ declare type Override<TTargetA, TTargetB> = {
440
+ [AKey in keyof TTargetA]: AKey extends keyof TTargetB ? TTargetB[AKey] : TTargetA[AKey];
441
+ };
442
+
443
+ /**
444
+ * Sets up providers necessary to enable TanStack Query functionality for Angular applications.
445
+ *
446
+ * Allows to configure a `QueryClient`.
447
+ *
448
+ * **Example - standalone**
449
+ *
450
+ * ```ts
451
+ * import {
452
+ * provideAngularQuery,
453
+ * QueryClient,
454
+ * } from '@tanstack/angular-query-experimental'
455
+ *
456
+ * bootstrapApplication(AppComponent, {
457
+ * providers: [provideAngularQuery(new QueryClient())],
458
+ * })
459
+ * ```
460
+ *
461
+ * **Example - NgModule-based**
462
+ *
463
+ * ```ts
464
+ * import {
465
+ * provideAngularQuery,
466
+ * QueryClient,
467
+ * } from '@tanstack/angular-query-experimental'
468
+ *
469
+ * @NgModule({
470
+ * declarations: [AppComponent],
471
+ * imports: [BrowserModule],
472
+ * providers: [provideAngularQuery(new QueryClient())],
473
+ * bootstrap: [AppComponent],
474
+ * })
475
+ * export class AppModule {}
476
+ * ```
477
+ * @param queryClient - A `QueryClient` instance.
478
+ * @returns A set of providers to set up TanStack Query.
479
+ * @public
480
+ * @see https://tanstack.com/query/v5/docs/framework/angular/quick-start
481
+ */
482
+ export declare function provideAngularQuery(queryClient: QueryClient): EnvironmentProviders;
483
+
484
+ /**
485
+ * Usually {@link provideAngularQuery} is used once to set up TanStack Query and the
486
+ * {@link https://tanstack.com/query/latest/docs/reference/QueryClient|QueryClient}
487
+ * for the entire application. You can use `provideQueryClient` to provide a
488
+ * different `QueryClient` instance for a part of the application.
489
+ * @public
490
+ */
491
+ export declare const provideQueryClient: ((value: QueryClient | (() => QueryClient)) => Provider) & ((value: QueryClient | (() => QueryClient)) => Provider);
492
+
493
+ /**
494
+ * QueriesOptions reducer recursively unwraps function arguments to infer/enforce type param
495
+ * @public
496
+ */
497
+ export declare type QueriesOptions<T extends Array<any>, TResult extends Array<any> = [], TDepth extends ReadonlyArray<number> = []> = TDepth['length'] extends MAXIMUM_DEPTH ? Array<QueryObserverOptionsForCreateQueries> : T extends [] ? [] : T extends [infer Head] ? [...TResult, GetOptions<Head>] : T extends [infer Head, ...infer Tail] ? QueriesOptions<[
498
+ ...Tail
499
+ ], [
500
+ ...TResult,
501
+ GetOptions<Head>
502
+ ], [
503
+ ...TDepth,
504
+ 1
505
+ ]> : ReadonlyArray<unknown> extends T ? T : T extends Array<QueryObserverOptionsForCreateQueries<infer TQueryFnData, infer TError, infer TData, infer TQueryKey>> ? Array<QueryObserverOptionsForCreateQueries<TQueryFnData, TError, TData, TQueryKey>> : Array<QueryObserverOptionsForCreateQueries>;
506
+
507
+ /**
508
+ * QueriesResults reducer recursively maps type param to results
509
+ * @public
510
+ */
511
+ export declare type QueriesResults<T extends Array<any>, TResult extends Array<any> = [], TDepth extends ReadonlyArray<number> = []> = TDepth['length'] extends MAXIMUM_DEPTH ? Array<QueryObserverResult> : T extends [] ? [] : T extends [infer Head] ? [...TResult, GetResults<Head>] : T extends [infer Head, ...infer Tail] ? QueriesResults<[
512
+ ...Tail
513
+ ], [
514
+ ...TResult,
515
+ GetResults<Head>
516
+ ], [
517
+ ...TDepth,
518
+ 1
519
+ ]> : T extends Array<QueryObserverOptionsForCreateQueries<infer TQueryFnData, infer TError, infer TData, any>> ? Array<QueryObserverResult<unknown extends TData ? TQueryFnData : TData, unknown extends TError ? DefaultError : TError>> : Array<QueryObserverResult>;
520
+
521
+ declare type QueryObserverOptionsForCreateQueries<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey> = OmitKeyof<QueryObserverOptions<TQueryFnData, TError, TData, TQueryFnData, TQueryKey>, 'placeholderData'> & {
522
+ placeholderData?: TQueryFnData | QueriesPlaceholderDataFunction<TQueryFnData>;
523
+ };
524
+
525
+ /**
526
+ * Allows to share and re-use query options in a type-safe way.
527
+ *
528
+ * The `queryKey` will be tagged with the type from `queryFn`.
529
+ *
530
+ * **Example**
531
+ *
532
+ * ```ts
533
+ * const { queryKey } = queryOptions({
534
+ * queryKey: ['key'],
535
+ * queryFn: () => Promise.resolve(5),
536
+ * // ^? Promise<number>
537
+ * })
538
+ *
539
+ * const queryClient = new QueryClient()
540
+ * const data = queryClient.getQueryData(queryKey)
541
+ * // ^? number | undefined
542
+ * ```
543
+ * @param options - The query options to tag with the type from `queryFn`.
544
+ * @returns The tagged query options.
545
+ * @public
546
+ */
547
+ export declare function queryOptions<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey>(options: UndefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey>): UndefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey> & {
548
+ queryKey: DataTag<TQueryKey, TQueryFnData>;
549
+ };
550
+
551
+ /**
552
+ * Allows to share and re-use query options in a type-safe way.
553
+ *
554
+ * The `queryKey` will be tagged with the type from `queryFn`.
555
+ *
556
+ * **Example**
557
+ *
558
+ * ```ts
559
+ * const { queryKey } = queryOptions({
560
+ * queryKey: ['key'],
561
+ * queryFn: () => Promise.resolve(5),
562
+ * // ^? Promise<number>
563
+ * })
564
+ *
565
+ * const queryClient = new QueryClient()
566
+ * const data = queryClient.getQueryData(queryKey)
567
+ * // ^? number | undefined
568
+ * ```
569
+ * @param options - The query options to tag with the type from `queryFn`.
570
+ * @returns The tagged query options.
571
+ * @public
572
+ */
573
+ export declare function queryOptions<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey>(options: DefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey>): DefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey> & {
574
+ queryKey: DataTag<TQueryKey, TQueryFnData>;
575
+ };
576
+
577
+ declare type UndefinedInitialDataInfiniteOptions<TQueryFnData, TError = DefaultError, TData = InfiniteData<TQueryFnData>, TQueryKey extends QueryKey = QueryKey, TPageParam = unknown> = CreateInfiniteQueryOptions<TQueryFnData, TError, TData, TQueryFnData, TQueryKey, TPageParam> & {
578
+ initialData?: undefined;
579
+ };
580
+
581
+ /**
582
+ * @public
583
+ */
584
+ export declare type UndefinedInitialDataOptions<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey> = CreateQueryOptions<TQueryFnData, TError, TData, TQueryKey> & {
585
+ initialData?: undefined;
586
+ };
587
+
588
+
589
+ export * from "@tanstack/query-core";
590
+
591
+ export { }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tanstack/angular-query-experimental",
3
- "version": "5.34.2",
3
+ "version": "5.35.0",
4
4
  "description": "Signals for managing, caching and syncing asynchronous and remote data in Angular",
5
5
  "author": "Arnoud de Vries",
6
6
  "license": "MIT",
@@ -30,7 +30,9 @@
30
30
  "sideEffects": false,
31
31
  "files": [
32
32
  "build",
33
- "src"
33
+ "!**/*.d.ts",
34
+ "!**/*.d.ts.map",
35
+ "build/rollup.d.ts"
34
36
  ],
35
37
  "dependencies": {
36
38
  "tslib": "^2.6.2",
@@ -44,6 +46,8 @@
44
46
  "@angular/core": "^17.3.3",
45
47
  "@angular/platform-browser": "^17.3.3",
46
48
  "@angular/platform-browser-dynamic": "^17.3.3",
49
+ "eslint-plugin-jsdoc": "^48.2.2",
50
+ "@microsoft/api-extractor": "^7.43.1",
47
51
  "ng-packagr": "^17.3.0",
48
52
  "typescript": "5.2.2",
49
53
  "zone.js": "^0.14.4"
@@ -53,13 +57,13 @@
53
57
  "@angular/common": ">=16.0.0"
54
58
  },
55
59
  "module": "build/fesm2022/tanstack-angular-query-experimental.mjs",
56
- "types": "build/index.d.ts",
60
+ "types": "build/rollup.d.ts",
57
61
  "exports": {
58
62
  "./package.json": {
59
63
  "default": "./package.json"
60
64
  },
61
65
  ".": {
62
- "types": "./build/index.d.ts",
66
+ "types": "./build/rollup.d.ts",
63
67
  "esm2022": "./build/esm2022/tanstack-angular-query-experimental.mjs",
64
68
  "esm": "./build/esm2022/tanstack-angular-query-experimental.mjs",
65
69
  "default": "./build/fesm2022/tanstack-angular-query-experimental.mjs"
@@ -73,6 +77,6 @@
73
77
  "test:lib:dev": "pnpm run test:lib --watch",
74
78
  "test:build": "publint --strict",
75
79
  "test:attw": "attw --pack",
76
- "build": "ng-packagr -p ng-package.json -c tsconfig.build.json && rimraf ./build/package.json"
80
+ "build": "ng-packagr -p ng-package.json -c tsconfig.build.json && rimraf ./build/package.json && api-extractor run --local"
77
81
  }
78
82
  }
@@ -1,6 +0,0 @@
1
- import type { QueryClient, QueryKey, QueryObserver } from '@tanstack/query-core';
2
- import type { CreateBaseQueryOptions, CreateBaseQueryResult } from './types';
3
- /**
4
- * Base implementation for `injectQuery` and `injectInfiniteQuery`.
5
- */
6
- export declare function createBaseQuery<TQueryFnData, TError, TData, TQueryData, TQueryKey extends QueryKey>(optionsFn: (client: QueryClient) => CreateBaseQueryOptions<TQueryFnData, TError, TData, TQueryData, TQueryKey>, Observer: typeof QueryObserver, queryClient: QueryClient): CreateBaseQueryResult<TData, TError>;
package/build/index.d.ts DELETED
@@ -1,14 +0,0 @@
1
- export * from '@tanstack/query-core';
2
- export * from './types';
3
- export type { DefinedInitialDataOptions, UndefinedInitialDataOptions, } from './query-options';
4
- export { queryOptions } from './query-options';
5
- export { infiniteQueryOptions } from './infinite-query-options';
6
- export * from './inject-infinite-query';
7
- export * from './inject-is-fetching';
8
- export * from './inject-is-mutating';
9
- export * from './inject-mutation';
10
- export * from './inject-mutation-state';
11
- export * from './inject-queries';
12
- export * from './inject-query';
13
- export { injectQueryClient, provideQueryClient } from './inject-query-client';
14
- export { provideAngularQuery } from './providers';