@tanstack/angular-query 5.0.0-rc.4 → 5.0.0-rc.5
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.
- package/hydration-state-key.mjs +10 -13
- package/hydration-state-key.mjs.map +1 -1
- package/index.mjs +8 -20
- package/index.mjs.map +1 -1
- package/infinite-query-options.d.ts +7 -18
- package/infinite-query-options.mjs +6 -5
- package/infinite-query-options.mjs.map +1 -1
- package/inject-base-query.d.ts +3 -0
- package/inject-base-query.mjs +62 -58
- package/inject-base-query.mjs.map +1 -1
- package/inject-infinite-query.d.ts +7 -11
- package/inject-infinite-query.mjs +16 -32
- package/inject-infinite-query.mjs.map +1 -1
- package/inject-is-fetching.d.ts +1 -1
- package/inject-is-fetching.mjs +22 -15
- package/inject-is-fetching.mjs.map +1 -1
- package/inject-is-mutating.d.ts +1 -1
- package/inject-is-mutating.mjs +22 -15
- package/inject-is-mutating.mjs.map +1 -1
- package/inject-is-restoring.d.ts +2 -0
- package/inject-is-restoring.mjs +28 -17
- package/inject-is-restoring.mjs.map +1 -1
- package/inject-mutation-state.d.ts +9 -0
- package/inject-mutation-state.mjs +25 -23
- package/inject-mutation-state.mjs.map +1 -1
- package/inject-mutation.d.ts +2 -4
- package/inject-mutation.mjs +87 -67
- package/inject-mutation.mjs.map +1 -1
- package/inject-queries.d.ts +1 -3
- package/inject-queries.mjs +122 -114
- package/inject-queries.mjs.map +1 -1
- package/inject-queries.types.d.ts +15 -0
- package/inject-query.d.ts +7 -13
- package/inject-query.mjs +11 -14
- package/inject-query.mjs.map +1 -1
- package/internal.mjs +2 -7
- package/mutation-options.d.ts +2 -6
- package/mutation-options.mjs +6 -5
- package/mutation-options.mjs.map +1 -1
- package/package.json +2 -2
- package/providers.d.ts +16 -14
- package/providers.mjs +138 -75
- package/providers.mjs.map +1 -1
- package/query-options.d.ts +6 -16
- package/query-options.mjs +6 -5
- package/query-options.mjs.map +1 -1
- package/query-resource.d.ts +4 -3
- package/query-resource.mjs +72 -63
- package/query-resource.mjs.map +1 -1
- package/schematics/migrate-from-experimental/index.js +2 -2
- package/schematics/ng-add/index.js +1 -1
- package/types.d.ts +70 -10
- package/utils/inject-external-store.d.ts +3 -0
- package/utils/inject-external-store.mjs +54 -38
- package/utils/inject-external-store.mjs.map +1 -1
- package/utils/inject-pending-tasks-lifecycle.d.ts +13 -1
- package/utils/inject-pending-tasks-lifecycle.mjs +32 -29
- package/utils/inject-pending-tasks-lifecycle.mjs.map +1 -1
- package/utils/inject-query-zone.d.ts +4 -1
- package/utils/inject-query-zone.mjs +12 -7
- package/utils/inject-query-zone.mjs.map +1 -1
- package/utils/resource-types.d.ts +3 -0
- package/utils/result-fields.d.ts +9 -0
- package/utils/result-fields.mjs +55 -62
- package/utils/result-fields.mjs.map +1 -1
- package/utils/signal-proxy.d.ts +6 -0
- package/utils/signal-proxy.mjs +16 -9
- package/utils/signal-proxy.mjs.map +1 -1
- package/internal.mjs.map +0 -1
package/hydration-state-key.mjs
CHANGED
|
@@ -1,14 +1,11 @@
|
|
|
1
1
|
import { InjectionToken, makeStateKey } from "@angular/core";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
INTERNAL_TANSTACK_QUERY_HYDRATION_TRANSFER_KEY
|
|
13
|
-
};
|
|
14
|
-
//# sourceMappingURL=hydration-state-key.mjs.map
|
|
2
|
+
//#region src/hydration-state-key.ts
|
|
3
|
+
var INTERNAL_TANSTACK_QUERY_HYDRATION_STATE_KEY = makeStateKey("tanstack-query-hydration-state");
|
|
4
|
+
var INTERNAL_TANSTACK_QUERY_HYDRATION_TRANSFER_KEY = new InjectionToken("tanstack-query-hydration-transfer-key", {
|
|
5
|
+
providedIn: "root",
|
|
6
|
+
factory: () => INTERNAL_TANSTACK_QUERY_HYDRATION_STATE_KEY
|
|
7
|
+
});
|
|
8
|
+
//#endregion
|
|
9
|
+
export { INTERNAL_TANSTACK_QUERY_HYDRATION_STATE_KEY, INTERNAL_TANSTACK_QUERY_HYDRATION_TRANSFER_KEY };
|
|
10
|
+
|
|
11
|
+
//# sourceMappingURL=hydration-state-key.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hydration-state-key.mjs","sources":["../src/hydration-state-key.ts"],"sourcesContent":["import { InjectionToken, makeStateKey } from '@angular/core'\nimport type { StateKey } from '@angular/core'\nimport type { DehydratedState } from '@tanstack/query-core'\n\nexport const INTERNAL_TANSTACK_QUERY_HYDRATION_STATE_KEY =\n makeStateKey<DehydratedState>('tanstack-query-hydration-state')\n\nexport const INTERNAL_TANSTACK_QUERY_HYDRATION_TRANSFER_KEY =\n new InjectionToken<StateKey<DehydratedState>>(\n 'tanstack-query-hydration-transfer-key',\n {\n providedIn: 'root',\n factory: () => INTERNAL_TANSTACK_QUERY_HYDRATION_STATE_KEY,\n },\n )\n"],"
|
|
1
|
+
{"version":3,"file":"hydration-state-key.mjs","names":[],"sources":["../src/hydration-state-key.ts"],"sourcesContent":["import { InjectionToken, makeStateKey } from '@angular/core'\nimport type { StateKey } from '@angular/core'\nimport type { DehydratedState } from '@tanstack/query-core'\n\nexport const INTERNAL_TANSTACK_QUERY_HYDRATION_STATE_KEY =\n makeStateKey<DehydratedState>('tanstack-query-hydration-state')\n\nexport const INTERNAL_TANSTACK_QUERY_HYDRATION_TRANSFER_KEY =\n new InjectionToken<StateKey<DehydratedState>>(\n 'tanstack-query-hydration-transfer-key',\n {\n providedIn: 'root',\n factory: () => INTERNAL_TANSTACK_QUERY_HYDRATION_STATE_KEY,\n },\n )\n"],"mappings":";;AAIA,IAAa,8CACX,aAA8B,gCAAgC;AAEhE,IAAa,iDACX,IAAI,eACF,yCACA;CACE,YAAY;CACZ,eAAe;AACjB,CACF"}
|
package/index.mjs
CHANGED
|
@@ -1,32 +1,20 @@
|
|
|
1
|
-
export * from "@tanstack/query-core";
|
|
2
1
|
import { toResource } from "./query-resource.mjs";
|
|
3
2
|
import { queryOptions } from "./query-options.mjs";
|
|
4
3
|
import { mutationOptions } from "./mutation-options.mjs";
|
|
5
4
|
import { infiniteQueryOptions } from "./infinite-query-options.mjs";
|
|
5
|
+
import { injectIsRestoring } from "./inject-is-restoring.mjs";
|
|
6
6
|
import { injectInfiniteQuery } from "./inject-infinite-query.mjs";
|
|
7
7
|
import { injectIsFetching } from "./inject-is-fetching.mjs";
|
|
8
8
|
import { injectIsMutating } from "./inject-is-mutating.mjs";
|
|
9
|
-
import { injectIsRestoring } from "./inject-is-restoring.mjs";
|
|
10
9
|
import { injectMutation } from "./inject-mutation.mjs";
|
|
11
10
|
import { injectMutationState } from "./inject-mutation-state.mjs";
|
|
12
11
|
import { injectQueries } from "./inject-queries.mjs";
|
|
13
12
|
import { injectQuery } from "./inject-query.mjs";
|
|
14
13
|
import { provideTanStackQuery, withHydrationKey, withNoQueryHydration } from "./providers.mjs";
|
|
15
|
-
export
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
injectMutationState,
|
|
23
|
-
injectQueries,
|
|
24
|
-
injectQuery,
|
|
25
|
-
mutationOptions,
|
|
26
|
-
provideTanStackQuery,
|
|
27
|
-
queryOptions,
|
|
28
|
-
toResource,
|
|
29
|
-
withHydrationKey,
|
|
30
|
-
withNoQueryHydration
|
|
31
|
-
};
|
|
32
|
-
//# sourceMappingURL=index.mjs.map
|
|
14
|
+
export * from "@tanstack/query-core";
|
|
15
|
+
//#region src/index.ts
|
|
16
|
+
/* istanbul ignore file */
|
|
17
|
+
//#endregion
|
|
18
|
+
export { infiniteQueryOptions, injectInfiniteQuery, injectIsFetching, injectIsMutating, injectIsRestoring, injectMutation, injectMutationState, injectQueries, injectQuery, mutationOptions, provideTanStackQuery, queryOptions, toResource, withHydrationKey, withNoQueryHydration };
|
|
19
|
+
|
|
20
|
+
//# sourceMappingURL=index.mjs.map
|
package/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../src/index.ts"],"sourcesContent":["/* istanbul ignore file */\n\n// Re-export core\nexport * from '@tanstack/query-core'\n\nexport * from './types'\nexport type { QueryResource } from './query-resource'\nexport { toResource } from './query-resource'\n\nexport type {\n DefinedInitialDataOptions,\n UndefinedInitialDataOptions,\n UnusedSkipTokenOptions,\n} from './query-options'\nexport { queryOptions } from './query-options'\n\nexport type { CreateMutationOptions } from './types'\nexport { mutationOptions } from './mutation-options'\n\nexport type {\n DefinedInitialDataInfiniteOptions,\n UndefinedInitialDataInfiniteOptions,\n UnusedSkipTokenInfiniteOptions,\n} from './infinite-query-options'\nexport { infiniteQueryOptions } from './infinite-query-options'\n\nexport { injectInfiniteQuery } from './inject-infinite-query'\n\nexport { injectIsFetching } from './inject-is-fetching'\n\nexport { injectIsMutating } from './inject-is-mutating'\n\nexport { injectIsRestoring } from './inject-is-restoring'\n\nexport { injectMutation } from './inject-mutation'\n\nexport type { MutationStateOptions } from './inject-mutation-state'\nexport { injectMutationState } from './inject-mutation-state'\n\nexport type {\n InjectQueriesOptions,\n QueriesOptions,\n QueriesResults,\n} from './inject-queries.types'\nexport { injectQueries } from './inject-queries'\n\nexport { injectQuery } from './inject-query'\n\nexport type { QueryFeature } from './providers'\nexport {\n provideTanStackQuery,\n withHydrationKey,\n withNoQueryHydration,\n} from './providers'\n"],"mappings":""}
|
|
@@ -3,7 +3,6 @@ import { CreateInfiniteQueryOptions } from './types.js';
|
|
|
3
3
|
/**
|
|
4
4
|
* The options accepted by the `infiniteQueryOptions` overload selected when no `initialData` is set — `data`
|
|
5
5
|
* may be `undefined` while the query is `pending`.
|
|
6
|
-
*
|
|
7
6
|
* @template TQueryFnData - The type of a single page, as your `queryFn` resolves it.
|
|
8
7
|
* @template TError - The type of errors your `queryFn` may throw.
|
|
9
8
|
* @template TData - The type `data` ends up as after `select` runs — defaults to `InfiniteData<TQueryFnData>`,
|
|
@@ -25,7 +24,6 @@ export type UndefinedInitialDataInfiniteOptions<TQueryFnData, TError = DefaultEr
|
|
|
25
24
|
* The options accepted by the `infiniteQueryOptions` overload selected when no `initialData` is set and
|
|
26
25
|
* `queryFn` is not `skipToken` — same as {@link UndefinedInitialDataInfiniteOptions}, but `queryFn` may not be
|
|
27
26
|
* `skipToken`.
|
|
28
|
-
*
|
|
29
27
|
* @template TQueryFnData - The type of a single page, as your `queryFn` resolves it.
|
|
30
28
|
* @template TError - The type of errors your `queryFn` may throw.
|
|
31
29
|
* @template TData - The type `data` ends up as after `select` runs — defaults to `InfiniteData<TQueryFnData>`,
|
|
@@ -45,7 +43,6 @@ export type UnusedSkipTokenInfiniteOptions<TQueryFnData, TError = DefaultError,
|
|
|
45
43
|
/**
|
|
46
44
|
* The options accepted by the `infiniteQueryOptions` overload selected when `initialData` is set — `data` is
|
|
47
45
|
* never `undefined` (unless a `select` changes `TData` to include `undefined`).
|
|
48
|
-
*
|
|
49
46
|
* @template TQueryFnData - The type of a single page, as your `queryFn` resolves it.
|
|
50
47
|
* @template TError - The type of errors your `queryFn` may throw.
|
|
51
48
|
* @template TData - The type `data` ends up as after `select` runs — defaults to `InfiniteData<TQueryFnData>`,
|
|
@@ -70,14 +67,12 @@ export type DefinedInitialDataInfiniteOptions<TQueryFnData, TError = DefaultErro
|
|
|
70
67
|
* for.
|
|
71
68
|
*
|
|
72
69
|
* This overload is selected when `initialData` is set.
|
|
73
|
-
*
|
|
74
|
-
* @see {@link injectInfiniteQuery} to run an infinite query with these options.
|
|
75
70
|
* @param options - The {@link DefinedInitialDataInfiniteOptions} to use — everything you can pass to
|
|
76
71
|
* `injectInfiniteQuery`, with `initialData` set.
|
|
77
72
|
* @returns The same options object, typed so that `queryKey` carries the inferred data type.
|
|
78
73
|
* @remarks See {@link injectInfiniteQuery} for examples that fetch further pages, from a button click or
|
|
79
74
|
* automatically as the user scrolls.
|
|
80
|
-
*
|
|
75
|
+
* @see {@link injectInfiniteQuery} to run an infinite query with these options.
|
|
81
76
|
* @example
|
|
82
77
|
* ```angular-ts
|
|
83
78
|
* import { infiniteQueryOptions, injectInfiniteQuery } from '@tanstack/angular-query'
|
|
@@ -115,11 +110,12 @@ export declare function infiniteQueryOptions<TQueryFnData, TError = DefaultError
|
|
|
115
110
|
* `injectInfiniteQuery`. These options can be shared across functions and imperative APIs such as
|
|
116
111
|
* `queryClient.fetchInfiniteQuery`. `options.queryKey` is required and is the query key to generate options
|
|
117
112
|
* for.
|
|
118
|
-
*
|
|
113
|
+
* @param options - The {@link UnusedSkipTokenInfiniteOptions} to use — everything you can pass to
|
|
114
|
+
* `injectInfiniteQuery`.
|
|
119
115
|
* @returns The same options object, typed so that `queryKey` carries the inferred data type.
|
|
120
116
|
* @remarks See {@link injectInfiniteQuery} for examples that fetch further pages, from a button click or
|
|
121
117
|
* automatically as the user scrolls.
|
|
122
|
-
*
|
|
118
|
+
* @see {@link injectInfiniteQuery} to run an infinite query with these options.
|
|
123
119
|
* @example
|
|
124
120
|
* A parameterized factory, so the same options object can be reused per `postId`:
|
|
125
121
|
* ```angular-ts
|
|
@@ -156,10 +152,6 @@ export declare function infiniteQueryOptions<TQueryFnData, TError = DefaultError
|
|
|
156
152
|
* readonly commentsQuery = injectInfiniteQuery(() => commentsOptions(this.postId()))
|
|
157
153
|
* }
|
|
158
154
|
* ```
|
|
159
|
-
*
|
|
160
|
-
* @see {@link injectInfiniteQuery} to run an infinite query with these options.
|
|
161
|
-
* @param options - The {@link UnusedSkipTokenInfiniteOptions} to use — everything you can pass to
|
|
162
|
-
* `injectInfiniteQuery`.
|
|
163
155
|
*/
|
|
164
156
|
export declare function infiniteQueryOptions<TQueryFnData, TError = DefaultError, TData = InfiniteData<TQueryFnData>, TQueryKey extends QueryKey = QueryKey, TPageParam = unknown>(options: UnusedSkipTokenInfiniteOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>): UnusedSkipTokenInfiniteOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam> & QueryKeyWithDataTag<TQueryKey, InfiniteData<TQueryFnData>, TError>;
|
|
165
157
|
/**
|
|
@@ -167,11 +159,12 @@ export declare function infiniteQueryOptions<TQueryFnData, TError = DefaultError
|
|
|
167
159
|
* `injectInfiniteQuery`. These options can be shared across functions and imperative APIs such as
|
|
168
160
|
* `queryClient.fetchInfiniteQuery`. `options.queryKey` is required and is the query key to generate options
|
|
169
161
|
* for.
|
|
170
|
-
*
|
|
162
|
+
* @param options - The {@link UndefinedInitialDataInfiniteOptions} to use — everything you can pass to
|
|
163
|
+
* `injectInfiniteQuery`.
|
|
171
164
|
* @returns The same options object, typed so that `queryKey` carries the inferred data type.
|
|
172
165
|
* @remarks See {@link injectInfiniteQuery} for examples that fetch further pages (from a button click or
|
|
173
166
|
* automatically as the user scrolls) and that use `skipToken` to disable the query until `postId` is set.
|
|
174
|
-
*
|
|
167
|
+
* @see {@link injectInfiniteQuery} to run an infinite query with these options.
|
|
175
168
|
* @example
|
|
176
169
|
* A parameterized factory, so the same options object can be reused per `postId`:
|
|
177
170
|
* ```angular-ts
|
|
@@ -208,9 +201,5 @@ export declare function infiniteQueryOptions<TQueryFnData, TError = DefaultError
|
|
|
208
201
|
* readonly commentsQuery = injectInfiniteQuery(() => commentsOptions(this.postId()))
|
|
209
202
|
* }
|
|
210
203
|
* ```
|
|
211
|
-
*
|
|
212
|
-
* @see {@link injectInfiniteQuery} to run an infinite query with these options.
|
|
213
|
-
* @param options - The {@link UndefinedInitialDataInfiniteOptions} to use — everything you can pass to
|
|
214
|
-
* `injectInfiniteQuery`.
|
|
215
204
|
*/
|
|
216
205
|
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> & QueryKeyWithDataTag<TQueryKey, InfiniteData<TQueryFnData>, TError>;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
//#region src/infinite-query-options.ts
|
|
1
2
|
function infiniteQueryOptions(options) {
|
|
2
|
-
|
|
3
|
+
return options;
|
|
3
4
|
}
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
//# sourceMappingURL=infinite-query-options.mjs.map
|
|
5
|
+
//#endregion
|
|
6
|
+
export { infiniteQueryOptions };
|
|
7
|
+
|
|
8
|
+
//# sourceMappingURL=infinite-query-options.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"infinite-query-options.mjs","sources":["../src/infinite-query-options.ts"],"sourcesContent":["import type {\n DefaultError,\n InfiniteData,\n InitialDataFunction,\n NonUndefinedGuard,\n OmitKeyof,\n QueryKey,\n QueryKeyWithDataTag,\n SkipToken,\n} from '@tanstack/query-core'\nimport type { CreateInfiniteQueryOptions } from './types'\n\n/**\n * The options accepted by the `infiniteQueryOptions` overload selected when no `initialData` is set — `data`\n * may be `undefined` while the query is `pending`.\n *\n * @template TQueryFnData - The type of a single page, as your `queryFn` resolves it.\n * @template TError - The type of errors your `queryFn` may throw.\n * @template TData - The type `data` ends up as after `select` runs — defaults to `InfiniteData<TQueryFnData>`,\n * the shape of all fetched pages plus their page params.\n * @template TQueryKey - The type of your `queryKey`.\n * @template TPageParam - The type of the parameter passed to `queryFn` to fetch a given page.\n */\nexport type UndefinedInitialDataInfiniteOptions<\n TQueryFnData,\n TError = DefaultError,\n TData = InfiniteData<TQueryFnData>,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n> = CreateInfiniteQueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n> & {\n /**\n * If set, this value will be used as the initial data for the query cache (as long as the query hasn't been\n * created or cached yet). If set to a function, the function will be called **once** during the shared/root\n * query initialization, and be expected to synchronously return the initial data. Initial data is\n * considered stale by default unless a `staleTime` has been set. `initialData` **is persisted** to the\n * cache.\n */\n initialData?:\n | undefined\n | NonUndefinedGuard<InfiniteData<TQueryFnData, TPageParam>>\n | InitialDataFunction<\n NonUndefinedGuard<InfiniteData<TQueryFnData, TPageParam>>\n >\n}\n\n/**\n * The options accepted by the `infiniteQueryOptions` overload selected when no `initialData` is set and\n * `queryFn` is not `skipToken` — same as {@link UndefinedInitialDataInfiniteOptions}, but `queryFn` may not be\n * `skipToken`.\n *\n * @template TQueryFnData - The type of a single page, as your `queryFn` resolves it.\n * @template TError - The type of errors your `queryFn` may throw.\n * @template TData - The type `data` ends up as after `select` runs — defaults to `InfiniteData<TQueryFnData>`,\n * the shape of all fetched pages plus their page params.\n * @template TQueryKey - The type of your `queryKey`.\n * @template TPageParam - The type of the parameter passed to `queryFn` to fetch a given page.\n */\nexport type UnusedSkipTokenInfiniteOptions<\n TQueryFnData,\n TError = DefaultError,\n TData = InfiniteData<TQueryFnData>,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n> = OmitKeyof<\n CreateInfiniteQueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n >,\n 'queryFn'\n> & {\n /**\n * `skipToken` is not allowed as a value here — this overload is selected when no `initialData` is set. If\n * you don't intend to run the query yet, set `enabled: false` — omitting `queryFn` alone still triggers a\n * fetch that fails with \"Missing queryFn\" unless `enabled` is `false` or a default query function has been\n * defined. A default query function only supplies `queryFn`; it doesn't defer the fetch on its own.\n */\n queryFn?: Exclude<\n CreateInfiniteQueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n >['queryFn'],\n SkipToken | undefined\n >\n}\n\n/**\n * The options accepted by the `infiniteQueryOptions` overload selected when `initialData` is set — `data` is\n * never `undefined` (unless a `select` changes `TData` to include `undefined`).\n *\n * @template TQueryFnData - The type of a single page, as your `queryFn` resolves it.\n * @template TError - The type of errors your `queryFn` may throw.\n * @template TData - The type `data` ends up as after `select` runs — defaults to `InfiniteData<TQueryFnData>`,\n * the shape of all fetched pages plus their page params.\n * @template TQueryKey - The type of your `queryKey`.\n * @template TPageParam - The type of the parameter passed to `queryFn` to fetch a given page.\n */\nexport type DefinedInitialDataInfiniteOptions<\n TQueryFnData,\n TError = DefaultError,\n TData = InfiniteData<TQueryFnData>,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n> = CreateInfiniteQueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n> & {\n /**\n * If set, this value will be used as the initial data for the query cache (as long as the query hasn't been\n * created or cached yet). If set to a function, the function will be called **once** during the shared/root\n * query initialization, and be expected to synchronously return the initial data. Initial data is\n * considered stale by default unless a `staleTime` has been set. `initialData` **is persisted** to the\n * cache.\n */\n initialData:\n | NonUndefinedGuard<InfiniteData<TQueryFnData, TPageParam>>\n | (() => NonUndefinedGuard<InfiniteData<TQueryFnData, TPageParam>>)\n}\n\n/**\n * You can generally pass everything to `infiniteQueryOptions` that you can also pass to\n * `injectInfiniteQuery`. These options can be shared across functions and imperative APIs such as\n * `queryClient.fetchInfiniteQuery`. `options.queryKey` is required and is the query key to generate options\n * for.\n *\n * This overload is selected when `initialData` is set.\n *\n * @see {@link injectInfiniteQuery} to run an infinite query with these options.\n * @param options - The {@link DefinedInitialDataInfiniteOptions} to use — everything you can pass to\n * `injectInfiniteQuery`, with `initialData` set.\n * @returns The same options object, typed so that `queryKey` carries the inferred data type.\n * @remarks See {@link injectInfiniteQuery} for examples that fetch further pages, from a button click or\n * automatically as the user scrolls.\n *\n * @example\n * ```angular-ts\n * import { infiniteQueryOptions, injectInfiniteQuery } from '@tanstack/angular-query'\n *\n * export const projectsOptions = infiniteQueryOptions({\n * queryKey: ['projects'],\n * queryFn: ({ pageParam }) => fetchProjects(pageParam),\n * initialPageParam: 0,\n * getNextPageParam: (lastPage) => lastPage.nextId,\n * initialData: { pages: [], pageParams: [] },\n * })\n *\n * @Component({\n * selector: 'projects',\n * template: `\n * <!-- `projectsQuery.data()` is never `undefined`, thanks to `initialData` — even if a\n * refetch fails, so the list stays visible alongside the error. -->\n * <ul>\n * @for (page of projectsQuery.data().pages; track $index) {\n * @for (project of page.projects; track project.id) {\n * <li>{{ project.name }}</li>\n * }\n * }\n * </ul>\n * `,\n * })\n * export class Projects {\n * readonly projectsQuery = injectInfiniteQuery(() => projectsOptions)\n * }\n * ```\n */\nexport function infiniteQueryOptions<\n TQueryFnData,\n TError = DefaultError,\n TData = InfiniteData<TQueryFnData>,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n>(\n options: DefinedInitialDataInfiniteOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n >,\n): DefinedInitialDataInfiniteOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n> &\n QueryKeyWithDataTag<TQueryKey, InfiniteData<TQueryFnData>, TError>\n\n/**\n * You can generally pass everything to `infiniteQueryOptions` that you can also pass to\n * `injectInfiniteQuery`. These options can be shared across functions and imperative APIs such as\n * `queryClient.fetchInfiniteQuery`. `options.queryKey` is required and is the query key to generate options\n * for.\n *\n * @returns The same options object, typed so that `queryKey` carries the inferred data type.\n * @remarks See {@link injectInfiniteQuery} for examples that fetch further pages, from a button click or\n * automatically as the user scrolls.\n *\n * @example\n * A parameterized factory, so the same options object can be reused per `postId`:\n * ```angular-ts\n * import { infiniteQueryOptions, injectInfiniteQuery } from '@tanstack/angular-query'\n *\n * export const commentsOptions = (postId: string) =>\n * infiniteQueryOptions({\n * queryKey: ['post', postId, 'comments'],\n * queryFn: ({ pageParam }) => fetchComments(postId, pageParam),\n * initialPageParam: 0,\n * getNextPageParam: (lastPage) => lastPage.nextId,\n * })\n *\n * @Component({\n * selector: 'comments',\n * template: `\n * @if (commentsQuery.isPending()) {\n * Loading...\n * } @else if (commentsQuery.isError()) {\n * <span>Error: {{ commentsQuery.error()?.message }}</span>\n * } @else {\n * <ul>\n * @for (page of commentsQuery.data().pages; track $index) {\n * @for (comment of page.comments; track comment.id) {\n * <li>{{ comment.text }}</li>\n * }\n * }\n * </ul>\n * }\n * `,\n * })\n * export class Comments {\n * readonly postId = signal('1')\n * readonly commentsQuery = injectInfiniteQuery(() => commentsOptions(this.postId()))\n * }\n * ```\n *\n * @see {@link injectInfiniteQuery} to run an infinite query with these options.\n * @param options - The {@link UnusedSkipTokenInfiniteOptions} to use — everything you can pass to\n * `injectInfiniteQuery`.\n */\nexport function infiniteQueryOptions<\n TQueryFnData,\n TError = DefaultError,\n TData = InfiniteData<TQueryFnData>,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n>(\n options: UnusedSkipTokenInfiniteOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n >,\n): UnusedSkipTokenInfiniteOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n> &\n QueryKeyWithDataTag<TQueryKey, InfiniteData<TQueryFnData>, TError>\n\n/**\n * You can generally pass everything to `infiniteQueryOptions` that you can also pass to\n * `injectInfiniteQuery`. These options can be shared across functions and imperative APIs such as\n * `queryClient.fetchInfiniteQuery`. `options.queryKey` is required and is the query key to generate options\n * for.\n *\n * @returns The same options object, typed so that `queryKey` carries the inferred data type.\n * @remarks See {@link injectInfiniteQuery} for examples that fetch further pages (from a button click or\n * automatically as the user scrolls) and that use `skipToken` to disable the query until `postId` is set.\n *\n * @example\n * A parameterized factory, so the same options object can be reused per `postId`:\n * ```angular-ts\n * import { infiniteQueryOptions, injectInfiniteQuery } from '@tanstack/angular-query'\n *\n * export const commentsOptions = (postId: string) =>\n * infiniteQueryOptions({\n * queryKey: ['post', postId, 'comments'],\n * queryFn: ({ pageParam }) => fetchComments(postId, pageParam),\n * initialPageParam: 0,\n * getNextPageParam: (lastPage) => lastPage.nextId,\n * })\n *\n * @Component({\n * selector: 'comments',\n * template: `\n * @if (commentsQuery.isPending()) {\n * Loading...\n * } @else if (commentsQuery.isError()) {\n * <span>Error: {{ commentsQuery.error()?.message }}</span>\n * } @else {\n * <ul>\n * @for (page of commentsQuery.data().pages; track $index) {\n * @for (comment of page.comments; track comment.id) {\n * <li>{{ comment.text }}</li>\n * }\n * }\n * </ul>\n * }\n * `,\n * })\n * export class Comments {\n * readonly postId = signal('1')\n * readonly commentsQuery = injectInfiniteQuery(() => commentsOptions(this.postId()))\n * }\n * ```\n *\n * @see {@link injectInfiniteQuery} to run an infinite query with these options.\n * @param options - The {@link UndefinedInitialDataInfiniteOptions} to use — everything you can pass to\n * `injectInfiniteQuery`.\n */\nexport function infiniteQueryOptions<\n TQueryFnData,\n TError = DefaultError,\n TData = InfiniteData<TQueryFnData>,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n>(\n options: UndefinedInitialDataInfiniteOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n >,\n): UndefinedInitialDataInfiniteOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n> &\n QueryKeyWithDataTag<TQueryKey, InfiniteData<TQueryFnData>, TError>\n\nexport function infiniteQueryOptions(options: unknown) {\n return options\n}\n"],"names":[],"mappings":"AA8VO,SAAS,qBAAqB,SAAkB;AACrD,SAAO;AACT;"}
|
|
1
|
+
{"version":3,"file":"infinite-query-options.mjs","names":[],"sources":["../src/infinite-query-options.ts"],"sourcesContent":["import type {\n DefaultError,\n InfiniteData,\n InitialDataFunction,\n NonUndefinedGuard,\n OmitKeyof,\n QueryKey,\n QueryKeyWithDataTag,\n SkipToken,\n} from '@tanstack/query-core'\nimport type { CreateInfiniteQueryOptions } from './types'\n\n/**\n * The options accepted by the `infiniteQueryOptions` overload selected when no `initialData` is set — `data`\n * may be `undefined` while the query is `pending`.\n * @template TQueryFnData - The type of a single page, as your `queryFn` resolves it.\n * @template TError - The type of errors your `queryFn` may throw.\n * @template TData - The type `data` ends up as after `select` runs — defaults to `InfiniteData<TQueryFnData>`,\n * the shape of all fetched pages plus their page params.\n * @template TQueryKey - The type of your `queryKey`.\n * @template TPageParam - The type of the parameter passed to `queryFn` to fetch a given page.\n */\nexport type UndefinedInitialDataInfiniteOptions<\n TQueryFnData,\n TError = DefaultError,\n TData = InfiniteData<TQueryFnData>,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n> = CreateInfiniteQueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n> & {\n /**\n * If set, this value will be used as the initial data for the query cache (as long as the query hasn't been\n * created or cached yet). If set to a function, the function will be called **once** during the shared/root\n * query initialization, and be expected to synchronously return the initial data. Initial data is\n * considered stale by default unless a `staleTime` has been set. `initialData` **is persisted** to the\n * cache.\n */\n initialData?:\n | undefined\n | NonUndefinedGuard<InfiniteData<TQueryFnData, TPageParam>>\n | InitialDataFunction<\n NonUndefinedGuard<InfiniteData<TQueryFnData, TPageParam>>\n >\n}\n\n/**\n * The options accepted by the `infiniteQueryOptions` overload selected when no `initialData` is set and\n * `queryFn` is not `skipToken` — same as {@link UndefinedInitialDataInfiniteOptions}, but `queryFn` may not be\n * `skipToken`.\n * @template TQueryFnData - The type of a single page, as your `queryFn` resolves it.\n * @template TError - The type of errors your `queryFn` may throw.\n * @template TData - The type `data` ends up as after `select` runs — defaults to `InfiniteData<TQueryFnData>`,\n * the shape of all fetched pages plus their page params.\n * @template TQueryKey - The type of your `queryKey`.\n * @template TPageParam - The type of the parameter passed to `queryFn` to fetch a given page.\n */\nexport type UnusedSkipTokenInfiniteOptions<\n TQueryFnData,\n TError = DefaultError,\n TData = InfiniteData<TQueryFnData>,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n> = OmitKeyof<\n CreateInfiniteQueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n >,\n 'queryFn'\n> & {\n /**\n * `skipToken` is not allowed as a value here — this overload is selected when no `initialData` is set. If\n * you don't intend to run the query yet, set `enabled: false` — omitting `queryFn` alone still triggers a\n * fetch that fails with \"Missing queryFn\" unless `enabled` is `false` or a default query function has been\n * defined. A default query function only supplies `queryFn`; it doesn't defer the fetch on its own.\n */\n queryFn?: Exclude<\n CreateInfiniteQueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n >['queryFn'],\n SkipToken | undefined\n >\n}\n\n/**\n * The options accepted by the `infiniteQueryOptions` overload selected when `initialData` is set — `data` is\n * never `undefined` (unless a `select` changes `TData` to include `undefined`).\n * @template TQueryFnData - The type of a single page, as your `queryFn` resolves it.\n * @template TError - The type of errors your `queryFn` may throw.\n * @template TData - The type `data` ends up as after `select` runs — defaults to `InfiniteData<TQueryFnData>`,\n * the shape of all fetched pages plus their page params.\n * @template TQueryKey - The type of your `queryKey`.\n * @template TPageParam - The type of the parameter passed to `queryFn` to fetch a given page.\n */\nexport type DefinedInitialDataInfiniteOptions<\n TQueryFnData,\n TError = DefaultError,\n TData = InfiniteData<TQueryFnData>,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n> = CreateInfiniteQueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n> & {\n /**\n * If set, this value will be used as the initial data for the query cache (as long as the query hasn't been\n * created or cached yet). If set to a function, the function will be called **once** during the shared/root\n * query initialization, and be expected to synchronously return the initial data. Initial data is\n * considered stale by default unless a `staleTime` has been set. `initialData` **is persisted** to the\n * cache.\n */\n initialData:\n | NonUndefinedGuard<InfiniteData<TQueryFnData, TPageParam>>\n | (() => NonUndefinedGuard<InfiniteData<TQueryFnData, TPageParam>>)\n}\n\n/**\n * You can generally pass everything to `infiniteQueryOptions` that you can also pass to\n * `injectInfiniteQuery`. These options can be shared across functions and imperative APIs such as\n * `queryClient.fetchInfiniteQuery`. `options.queryKey` is required and is the query key to generate options\n * for.\n *\n * This overload is selected when `initialData` is set.\n * @param options - The {@link DefinedInitialDataInfiniteOptions} to use — everything you can pass to\n * `injectInfiniteQuery`, with `initialData` set.\n * @returns The same options object, typed so that `queryKey` carries the inferred data type.\n * @remarks See {@link injectInfiniteQuery} for examples that fetch further pages, from a button click or\n * automatically as the user scrolls.\n * @see {@link injectInfiniteQuery} to run an infinite query with these options.\n * @example\n * ```angular-ts\n * import { infiniteQueryOptions, injectInfiniteQuery } from '@tanstack/angular-query'\n *\n * export const projectsOptions = infiniteQueryOptions({\n * queryKey: ['projects'],\n * queryFn: ({ pageParam }) => fetchProjects(pageParam),\n * initialPageParam: 0,\n * getNextPageParam: (lastPage) => lastPage.nextId,\n * initialData: { pages: [], pageParams: [] },\n * })\n *\n * @Component({\n * selector: 'projects',\n * template: `\n * <!-- `projectsQuery.data()` is never `undefined`, thanks to `initialData` — even if a\n * refetch fails, so the list stays visible alongside the error. -->\n * <ul>\n * @for (page of projectsQuery.data().pages; track $index) {\n * @for (project of page.projects; track project.id) {\n * <li>{{ project.name }}</li>\n * }\n * }\n * </ul>\n * `,\n * })\n * export class Projects {\n * readonly projectsQuery = injectInfiniteQuery(() => projectsOptions)\n * }\n * ```\n */\nexport function infiniteQueryOptions<\n TQueryFnData,\n TError = DefaultError,\n TData = InfiniteData<TQueryFnData>,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n>(\n options: DefinedInitialDataInfiniteOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n >,\n): DefinedInitialDataInfiniteOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n> &\n QueryKeyWithDataTag<TQueryKey, InfiniteData<TQueryFnData>, TError>\n\n/**\n * You can generally pass everything to `infiniteQueryOptions` that you can also pass to\n * `injectInfiniteQuery`. These options can be shared across functions and imperative APIs such as\n * `queryClient.fetchInfiniteQuery`. `options.queryKey` is required and is the query key to generate options\n * for.\n * @param options - The {@link UnusedSkipTokenInfiniteOptions} to use — everything you can pass to\n * `injectInfiniteQuery`.\n * @returns The same options object, typed so that `queryKey` carries the inferred data type.\n * @remarks See {@link injectInfiniteQuery} for examples that fetch further pages, from a button click or\n * automatically as the user scrolls.\n * @see {@link injectInfiniteQuery} to run an infinite query with these options.\n * @example\n * A parameterized factory, so the same options object can be reused per `postId`:\n * ```angular-ts\n * import { infiniteQueryOptions, injectInfiniteQuery } from '@tanstack/angular-query'\n *\n * export const commentsOptions = (postId: string) =>\n * infiniteQueryOptions({\n * queryKey: ['post', postId, 'comments'],\n * queryFn: ({ pageParam }) => fetchComments(postId, pageParam),\n * initialPageParam: 0,\n * getNextPageParam: (lastPage) => lastPage.nextId,\n * })\n *\n * @Component({\n * selector: 'comments',\n * template: `\n * @if (commentsQuery.isPending()) {\n * Loading...\n * } @else if (commentsQuery.isError()) {\n * <span>Error: {{ commentsQuery.error()?.message }}</span>\n * } @else {\n * <ul>\n * @for (page of commentsQuery.data().pages; track $index) {\n * @for (comment of page.comments; track comment.id) {\n * <li>{{ comment.text }}</li>\n * }\n * }\n * </ul>\n * }\n * `,\n * })\n * export class Comments {\n * readonly postId = signal('1')\n * readonly commentsQuery = injectInfiniteQuery(() => commentsOptions(this.postId()))\n * }\n * ```\n */\nexport function infiniteQueryOptions<\n TQueryFnData,\n TError = DefaultError,\n TData = InfiniteData<TQueryFnData>,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n>(\n options: UnusedSkipTokenInfiniteOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n >,\n): UnusedSkipTokenInfiniteOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n> &\n QueryKeyWithDataTag<TQueryKey, InfiniteData<TQueryFnData>, TError>\n\n/**\n * You can generally pass everything to `infiniteQueryOptions` that you can also pass to\n * `injectInfiniteQuery`. These options can be shared across functions and imperative APIs such as\n * `queryClient.fetchInfiniteQuery`. `options.queryKey` is required and is the query key to generate options\n * for.\n * @param options - The {@link UndefinedInitialDataInfiniteOptions} to use — everything you can pass to\n * `injectInfiniteQuery`.\n * @returns The same options object, typed so that `queryKey` carries the inferred data type.\n * @remarks See {@link injectInfiniteQuery} for examples that fetch further pages (from a button click or\n * automatically as the user scrolls) and that use `skipToken` to disable the query until `postId` is set.\n * @see {@link injectInfiniteQuery} to run an infinite query with these options.\n * @example\n * A parameterized factory, so the same options object can be reused per `postId`:\n * ```angular-ts\n * import { infiniteQueryOptions, injectInfiniteQuery } from '@tanstack/angular-query'\n *\n * export const commentsOptions = (postId: string) =>\n * infiniteQueryOptions({\n * queryKey: ['post', postId, 'comments'],\n * queryFn: ({ pageParam }) => fetchComments(postId, pageParam),\n * initialPageParam: 0,\n * getNextPageParam: (lastPage) => lastPage.nextId,\n * })\n *\n * @Component({\n * selector: 'comments',\n * template: `\n * @if (commentsQuery.isPending()) {\n * Loading...\n * } @else if (commentsQuery.isError()) {\n * <span>Error: {{ commentsQuery.error()?.message }}</span>\n * } @else {\n * <ul>\n * @for (page of commentsQuery.data().pages; track $index) {\n * @for (comment of page.comments; track comment.id) {\n * <li>{{ comment.text }}</li>\n * }\n * }\n * </ul>\n * }\n * `,\n * })\n * export class Comments {\n * readonly postId = signal('1')\n * readonly commentsQuery = injectInfiniteQuery(() => commentsOptions(this.postId()))\n * }\n * ```\n */\nexport function infiniteQueryOptions<\n TQueryFnData,\n TError = DefaultError,\n TData = InfiniteData<TQueryFnData>,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n>(\n options: UndefinedInitialDataInfiniteOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n >,\n): UndefinedInitialDataInfiniteOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n> &\n QueryKeyWithDataTag<TQueryKey, InfiniteData<TQueryFnData>, TError>\n\nexport function infiniteQueryOptions(options: unknown) {\n return options\n}\n"],"mappings":";AAmVA,SAAgB,qBAAqB,SAAkB;CACrD,OAAO;AACT"}
|
package/inject-base-query.d.ts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { QueryKey, QueryObserver, QueryObserverOptions, QueryObserverResult } from '@tanstack/query-core';
|
|
2
2
|
/**
|
|
3
3
|
* Base implementation for `injectQuery` and `injectInfiniteQuery`.
|
|
4
|
+
* @param optionsFn - Produces the reactive query options.
|
|
5
|
+
* @param Observer - The core observer constructor for this query kind.
|
|
6
|
+
* @returns The current result signal and a function that reads its active observer.
|
|
4
7
|
*/
|
|
5
8
|
export declare function injectBaseQuery<TQueryFnData, TError, TData, TQueryData, TQueryKey extends QueryKey>(optionsFn: () => QueryObserverOptions<TQueryFnData, TError, TData, TQueryData, TQueryKey>, Observer: typeof QueryObserver): readonly [import('@angular/core').Signal<QueryObserverResult<TData, TError>>, () => QueryObserver<TQueryFnData, TError, TData, TQueryData, TQueryKey>];
|
package/inject-base-query.mjs
CHANGED
|
@@ -1,64 +1,68 @@
|
|
|
1
|
-
import { inject, computed, untracked, effect } from "@angular/core";
|
|
2
|
-
import { QueryClient } from "@tanstack/query-core";
|
|
3
1
|
import { injectQueryZone } from "./utils/inject-query-zone.mjs";
|
|
4
2
|
import { injectIsRestoring } from "./inject-is-restoring.mjs";
|
|
5
3
|
import { injectPendingTasksLifecycle } from "./utils/inject-pending-tasks-lifecycle.mjs";
|
|
6
4
|
import { injectExternalStore } from "./utils/inject-external-store.mjs";
|
|
5
|
+
import { QueryClient } from "@tanstack/query-core";
|
|
6
|
+
import { computed, effect, inject, untracked } from "@angular/core";
|
|
7
|
+
//#region src/inject-base-query.ts
|
|
8
|
+
/**
|
|
9
|
+
* Base implementation for `injectQuery` and `injectInfiniteQuery`.
|
|
10
|
+
* @param optionsFn - Produces the reactive query options.
|
|
11
|
+
* @param Observer - The core observer constructor for this query kind.
|
|
12
|
+
* @returns The current result signal and a function that reads its active observer.
|
|
13
|
+
*/
|
|
7
14
|
function injectBaseQuery(optionsFn, Observer) {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
return observer;
|
|
58
|
-
});
|
|
59
|
-
return [resultSignal, getObserver];
|
|
15
|
+
const outsideZone = injectQueryZone();
|
|
16
|
+
const queryClient = inject(QueryClient);
|
|
17
|
+
const isRestoring = injectIsRestoring();
|
|
18
|
+
const lifecycle = injectPendingTasksLifecycle();
|
|
19
|
+
const shouldBlockPendingTasks = (observer, result) => {
|
|
20
|
+
return observer.getCurrentQuery().state.fetchStatus !== "idle" || result.fetchStatus !== "idle" && result.isEnabled;
|
|
21
|
+
};
|
|
22
|
+
const defaultedOptionsSignal = computed(() => {
|
|
23
|
+
const defaultedOptions = queryClient.defaultQueryOptions(optionsFn());
|
|
24
|
+
defaultedOptions._optimisticResults = isRestoring() ? "isRestoring" : "optimistic";
|
|
25
|
+
defaultedOptions.notifyOnChangeProps = "all";
|
|
26
|
+
return defaultedOptions;
|
|
27
|
+
});
|
|
28
|
+
const observerSignal = computed(() => new Observer(queryClient, untracked(defaultedOptionsSignal)));
|
|
29
|
+
effect(() => {
|
|
30
|
+
const options = defaultedOptionsSignal();
|
|
31
|
+
outsideZone(() => untracked(() => observerSignal().setOptions(options)));
|
|
32
|
+
});
|
|
33
|
+
const resultSignal = injectExternalStore(() => {
|
|
34
|
+
const observer = observerSignal();
|
|
35
|
+
return {
|
|
36
|
+
getSnapshot: () => observer.getOptimisticResult(defaultedOptionsSignal()),
|
|
37
|
+
subscribe: isRestoring() ? void 0 : (onStoreChange) => {
|
|
38
|
+
const unsubscribe = observer.subscribe(() => {
|
|
39
|
+
if (lifecycle.destroyed) return;
|
|
40
|
+
onStoreChange();
|
|
41
|
+
});
|
|
42
|
+
return () => {
|
|
43
|
+
lifecycle.setPending(false);
|
|
44
|
+
unsubscribe();
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
});
|
|
49
|
+
effect((onCleanup) => {
|
|
50
|
+
const result = resultSignal();
|
|
51
|
+
if (isRestoring()) {
|
|
52
|
+
lifecycle.setPending(false);
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
lifecycle.setPending(shouldBlockPendingTasks(observerSignal(), result));
|
|
56
|
+
onCleanup(() => lifecycle.setPending(false));
|
|
57
|
+
});
|
|
58
|
+
const getObserver = () => untracked(() => {
|
|
59
|
+
const observer = observerSignal();
|
|
60
|
+
observer.setOptions(defaultedOptionsSignal());
|
|
61
|
+
return observer;
|
|
62
|
+
});
|
|
63
|
+
return [resultSignal, getObserver];
|
|
60
64
|
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
//# sourceMappingURL=inject-base-query.mjs.map
|
|
65
|
+
//#endregion
|
|
66
|
+
export { injectBaseQuery };
|
|
67
|
+
|
|
68
|
+
//# sourceMappingURL=inject-base-query.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"inject-base-query.mjs","sources":["../src/inject-base-query.ts"],"sourcesContent":["import { computed, effect, inject, untracked } from '@angular/core'\nimport { QueryClient } from '@tanstack/query-core'\nimport { injectQueryZone } from './utils/inject-query-zone'\nimport { injectIsRestoring } from './inject-is-restoring'\nimport { injectPendingTasksLifecycle } from './utils/inject-pending-tasks-lifecycle'\nimport { injectExternalStore } from './utils/inject-external-store'\nimport type {\n QueryKey,\n QueryObserver,\n QueryObserverOptions,\n QueryObserverResult,\n} from '@tanstack/query-core'\n\n/**\n * Base implementation for `injectQuery` and `injectInfiniteQuery`.\n */\nexport function injectBaseQuery<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey extends QueryKey,\n>(\n optionsFn: () => QueryObserverOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey\n >,\n Observer: typeof QueryObserver,\n) {\n const outsideZone = injectQueryZone()\n const queryClient = inject(QueryClient)\n const isRestoring = injectIsRestoring()\n const lifecycle = injectPendingTasksLifecycle()\n\n const shouldBlockPendingTasks = (\n observer: QueryObserver<TQueryFnData, TError, TData, TQueryData, TQueryKey>,\n result: QueryObserverResult<TData, TError>,\n ) => {\n return (\n observer.getCurrentQuery().state.fetchStatus !== 'idle' ||\n (result.fetchStatus !== 'idle' && result.isEnabled)\n )\n }\n\n const defaultedOptionsSignal = computed(() => {\n const defaultedOptions = queryClient.defaultQueryOptions(optionsFn())\n defaultedOptions._optimisticResults = isRestoring()\n ? 'isRestoring'\n : 'optimistic'\n defaultedOptions.notifyOnChangeProps = 'all'\n return defaultedOptions\n })\n\n const observerSignal = computed(\n () => new Observer(queryClient, untracked(defaultedOptionsSignal)),\n )\n\n effect(() => {\n const options = defaultedOptionsSignal()\n outsideZone(() => untracked(() => observerSignal().setOptions(options)))\n })\n\n const resultSignal = injectExternalStore(() => {\n const observer = observerSignal()\n const restoring = isRestoring()\n return {\n getSnapshot: () => observer.getOptimisticResult(defaultedOptionsSignal()),\n subscribe: restoring\n ? undefined\n : (onStoreChange) => {\n const unsubscribe = observer.subscribe(() => {\n if (lifecycle.destroyed) return\n onStoreChange()\n })\n return () => {\n lifecycle.setPending(false)\n unsubscribe()\n }\n },\n }\n })\n\n effect((onCleanup) => {\n const result = resultSignal()\n if (isRestoring()) {\n lifecycle.setPending(false)\n return\n }\n\n lifecycle.setPending(shouldBlockPendingTasks(observerSignal(), result))\n onCleanup(() => lifecycle.setPending(false))\n })\n\n // Imperative methods use current options before starting work, even when\n // invoked before the subscription effect runs.\n const getObserver = () =>\n untracked(() => {\n const observer = observerSignal()\n observer.setOptions(defaultedOptionsSignal())\n return observer\n })\n\n return [resultSignal, getObserver] as const\n}\n"],"
|
|
1
|
+
{"version":3,"file":"inject-base-query.mjs","names":[],"sources":["../src/inject-base-query.ts"],"sourcesContent":["import { computed, effect, inject, untracked } from '@angular/core'\nimport { QueryClient } from '@tanstack/query-core'\nimport { injectQueryZone } from './utils/inject-query-zone'\nimport { injectIsRestoring } from './inject-is-restoring'\nimport { injectPendingTasksLifecycle } from './utils/inject-pending-tasks-lifecycle'\nimport { injectExternalStore } from './utils/inject-external-store'\nimport type {\n QueryKey,\n QueryObserver,\n QueryObserverOptions,\n QueryObserverResult,\n} from '@tanstack/query-core'\n\n/**\n * Base implementation for `injectQuery` and `injectInfiniteQuery`.\n * @param optionsFn - Produces the reactive query options.\n * @param Observer - The core observer constructor for this query kind.\n * @returns The current result signal and a function that reads its active observer.\n */\nexport function injectBaseQuery<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey extends QueryKey,\n>(\n optionsFn: () => QueryObserverOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey\n >,\n Observer: typeof QueryObserver,\n) {\n const outsideZone = injectQueryZone()\n const queryClient = inject(QueryClient)\n const isRestoring = injectIsRestoring()\n const lifecycle = injectPendingTasksLifecycle()\n\n const shouldBlockPendingTasks = (\n observer: QueryObserver<TQueryFnData, TError, TData, TQueryData, TQueryKey>,\n result: QueryObserverResult<TData, TError>,\n ) => {\n return (\n observer.getCurrentQuery().state.fetchStatus !== 'idle' ||\n (result.fetchStatus !== 'idle' && result.isEnabled)\n )\n }\n\n const defaultedOptionsSignal = computed(() => {\n const defaultedOptions = queryClient.defaultQueryOptions(optionsFn())\n defaultedOptions._optimisticResults = isRestoring()\n ? 'isRestoring'\n : 'optimistic'\n defaultedOptions.notifyOnChangeProps = 'all'\n return defaultedOptions\n })\n\n const observerSignal = computed(\n () => new Observer(queryClient, untracked(defaultedOptionsSignal)),\n )\n\n effect(() => {\n const options = defaultedOptionsSignal()\n outsideZone(() => untracked(() => observerSignal().setOptions(options)))\n })\n\n const resultSignal = injectExternalStore(() => {\n const observer = observerSignal()\n const restoring = isRestoring()\n return {\n getSnapshot: () => observer.getOptimisticResult(defaultedOptionsSignal()),\n subscribe: restoring\n ? undefined\n : (onStoreChange) => {\n const unsubscribe = observer.subscribe(() => {\n if (lifecycle.destroyed) return\n onStoreChange()\n })\n return () => {\n lifecycle.setPending(false)\n unsubscribe()\n }\n },\n }\n })\n\n effect((onCleanup) => {\n const result = resultSignal()\n if (isRestoring()) {\n lifecycle.setPending(false)\n return\n }\n\n lifecycle.setPending(shouldBlockPendingTasks(observerSignal(), result))\n onCleanup(() => lifecycle.setPending(false))\n })\n\n // Imperative methods use current options before starting work, even when\n // invoked before the subscription effect runs.\n const getObserver = () =>\n untracked(() => {\n const observer = observerSignal()\n observer.setOptions(defaultedOptionsSignal())\n return observer\n })\n\n return [resultSignal, getObserver] as const\n}\n"],"mappings":";;;;;;;;;;;;;AAmBA,SAAgB,gBAOd,WAOA,UACA;CACA,MAAM,cAAc,gBAAgB;CACpC,MAAM,cAAc,OAAO,WAAW;CACtC,MAAM,cAAc,kBAAkB;CACtC,MAAM,YAAY,4BAA4B;CAE9C,MAAM,2BACJ,UACA,WACG;EACH,OACE,SAAS,gBAAgB,CAAC,CAAC,MAAM,gBAAgB,UAChD,OAAO,gBAAgB,UAAU,OAAO;CAE7C;CAEA,MAAM,yBAAyB,eAAe;EAC5C,MAAM,mBAAmB,YAAY,oBAAoB,UAAU,CAAC;EACpE,iBAAiB,qBAAqB,YAAY,IAC9C,gBACA;EACJ,iBAAiB,sBAAsB;EACvC,OAAO;CACT,CAAC;CAED,MAAM,iBAAiB,eACf,IAAI,SAAS,aAAa,UAAU,sBAAsB,CAAC,CACnE;CAEA,aAAa;EACX,MAAM,UAAU,uBAAuB;EACvC,kBAAkB,gBAAgB,eAAe,CAAC,CAAC,WAAW,OAAO,CAAC,CAAC;CACzE,CAAC;CAED,MAAM,eAAe,0BAA0B;EAC7C,MAAM,WAAW,eAAe;EAEhC,OAAO;GACL,mBAAmB,SAAS,oBAAoB,uBAAuB,CAAC;GACxE,WAHgB,YAGL,IACP,KAAA,KACC,kBAAkB;IACjB,MAAM,cAAc,SAAS,gBAAgB;KAC3C,IAAI,UAAU,WAAW;KACzB,cAAc;IAChB,CAAC;IACD,aAAa;KACX,UAAU,WAAW,KAAK;KAC1B,YAAY;IACd;GACF;EACN;CACF,CAAC;CAED,QAAQ,cAAc;EACpB,MAAM,SAAS,aAAa;EAC5B,IAAI,YAAY,GAAG;GACjB,UAAU,WAAW,KAAK;GAC1B;EACF;EAEA,UAAU,WAAW,wBAAwB,eAAe,GAAG,MAAM,CAAC;EACtE,gBAAgB,UAAU,WAAW,KAAK,CAAC;CAC7C,CAAC;CAID,MAAM,oBACJ,gBAAgB;EACd,MAAM,WAAW,eAAe;EAChC,SAAS,WAAW,uBAAuB,CAAC;EAC5C,OAAO;CACT,CAAC;CAEH,OAAO,CAAC,cAAc,WAAW;AACnC"}
|
|
@@ -4,26 +4,23 @@ import { DefinedInitialDataInfiniteOptions, UndefinedInitialDataInfiniteOptions
|
|
|
4
4
|
/**
|
|
5
5
|
* This overload is selected when `initialData` is set, so the resulting `data` signal is never `undefined`
|
|
6
6
|
* (unless a `select` changes `TData` to include `undefined`).
|
|
7
|
-
*
|
|
8
|
-
* @see https://tanstack.com/query/latest/docs/framework/angular/guides/infinite-queries
|
|
9
|
-
* @see {@link infiniteQueryOptions} to share these options between `injectInfiniteQuery` and
|
|
10
|
-
* `queryClient.infiniteQuery`.
|
|
11
7
|
* @param optionsFn - A function returning infinite-query options with `initialData` set. Similar to
|
|
12
8
|
* `computed` from Angular, this function runs in the reactive context.
|
|
13
9
|
* @returns The infinite query result, typed so that `data` is never `undefined`.
|
|
10
|
+
* @see https://tanstack.com/query/latest/docs/framework/angular/guides/infinite-queries
|
|
11
|
+
* @see {@link infiniteQueryOptions} to share these options between `injectInfiniteQuery` and
|
|
12
|
+
* `queryClient.infiniteQuery`.
|
|
14
13
|
*/
|
|
15
14
|
export declare function injectInfiniteQuery<TQueryFnData, TError = DefaultError, TData = InfiniteData<TQueryFnData>, TQueryKey extends QueryKey = QueryKey, TPageParam = unknown>(optionsFn: () => DefinedInitialDataInfiniteOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>): DefinedCreateInfiniteQueryResult<TData, TError>;
|
|
16
15
|
/**
|
|
17
16
|
* Injects an infinite query: a declarative dependency on an asynchronous source of data that is tied to a unique key.
|
|
18
17
|
* Infinite queries can additively "load more" data onto an existing set of data or support infinite scroll.
|
|
19
|
-
*
|
|
20
|
-
* @see https://tanstack.com/query/latest/docs/framework/angular/guides/infinite-queries
|
|
21
|
-
* @see {@link infiniteQueryOptions} to share these options between `injectInfiniteQuery` and
|
|
22
|
-
* `queryClient.infiniteQuery`.
|
|
23
18
|
* @param optionsFn - A function that returns infinite query options. Similar to `computed` from Angular,
|
|
24
19
|
* this function runs in the reactive context, so signals read inside it drive the query.
|
|
25
20
|
* @returns The infinite query result.
|
|
26
|
-
*
|
|
21
|
+
* @see https://tanstack.com/query/latest/docs/framework/angular/guides/infinite-queries
|
|
22
|
+
* @see {@link infiniteQueryOptions} to share these options between `injectInfiniteQuery` and
|
|
23
|
+
* `queryClient.infiniteQuery`.
|
|
27
24
|
* @example
|
|
28
25
|
* ```angular-ts
|
|
29
26
|
* @Component({
|
|
@@ -58,10 +55,9 @@ export declare function injectInfiniteQuery<TQueryFnData, TError = DefaultError,
|
|
|
58
55
|
* This overload accepts the general {@link CreateInfiniteQueryOptions} shape rather than the
|
|
59
56
|
* `initialData`-aware overloads above, so whether `data` is defined can't be inferred from the call
|
|
60
57
|
* site — useful when wrapping `injectInfiniteQuery` in your own helper.
|
|
61
|
-
*
|
|
62
|
-
* @see https://tanstack.com/query/latest/docs/framework/angular/guides/infinite-queries
|
|
63
58
|
* @param optionsFn - A function that returns infinite query options. Similar to `computed` from Angular,
|
|
64
59
|
* this function runs in the reactive context, so signals read inside it drive the query.
|
|
65
60
|
* @returns The infinite query result.
|
|
61
|
+
* @see https://tanstack.com/query/latest/docs/framework/angular/guides/infinite-queries
|
|
66
62
|
*/
|
|
67
63
|
export declare function injectInfiniteQuery<TQueryFnData, TError = DefaultError, TData = InfiniteData<TQueryFnData>, TQueryKey extends QueryKey = QueryKey, TPageParam = unknown>(optionsFn: () => CreateInfiniteQueryOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>): CreateInfiniteQueryResult<TData, TError>;
|
|
@@ -1,38 +1,22 @@
|
|
|
1
|
-
import { InfiniteQueryObserver } from "@tanstack/query-core";
|
|
2
|
-
import { assertInInjectionContext, untracked } from "@angular/core";
|
|
3
1
|
import { injectQueryZone } from "./utils/inject-query-zone.mjs";
|
|
4
2
|
import { injectBaseQuery } from "./inject-base-query.mjs";
|
|
5
3
|
import { signalProxy } from "./utils/signal-proxy.mjs";
|
|
6
4
|
import { infiniteQueryResultFields } from "./utils/result-fields.mjs";
|
|
5
|
+
import { InfiniteQueryObserver } from "@tanstack/query-core";
|
|
6
|
+
import { assertInInjectionContext, untracked } from "@angular/core";
|
|
7
|
+
//#region src/inject-infinite-query.ts
|
|
7
8
|
function injectInfiniteQuery(optionsFn) {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
return Object.assign(
|
|
18
|
-
signalProxy(
|
|
19
|
-
resultSignal,
|
|
20
|
-
infiniteQueryResultFields
|
|
21
|
-
),
|
|
22
|
-
{
|
|
23
|
-
refetch: (options) => outsideZone(
|
|
24
|
-
() => untracked(() => getInfiniteObserver().refetch(options))
|
|
25
|
-
),
|
|
26
|
-
fetchNextPage: (options) => outsideZone(
|
|
27
|
-
() => untracked(() => getInfiniteObserver().fetchNextPage(options))
|
|
28
|
-
),
|
|
29
|
-
fetchPreviousPage: (options) => outsideZone(
|
|
30
|
-
() => untracked(() => getInfiniteObserver().fetchPreviousPage(options))
|
|
31
|
-
)
|
|
32
|
-
}
|
|
33
|
-
);
|
|
9
|
+
if (typeof ngDevMode === "undefined" || ngDevMode) assertInInjectionContext(injectInfiniteQuery);
|
|
10
|
+
const outsideZone = injectQueryZone();
|
|
11
|
+
const [resultSignal, getObserver] = injectBaseQuery(optionsFn, InfiniteQueryObserver);
|
|
12
|
+
const getInfiniteObserver = () => getObserver();
|
|
13
|
+
return Object.assign(signalProxy(resultSignal, infiniteQueryResultFields), {
|
|
14
|
+
refetch: (options) => outsideZone(() => untracked(() => getInfiniteObserver().refetch(options))),
|
|
15
|
+
fetchNextPage: (options) => outsideZone(() => untracked(() => getInfiniteObserver().fetchNextPage(options))),
|
|
16
|
+
fetchPreviousPage: (options) => outsideZone(() => untracked(() => getInfiniteObserver().fetchPreviousPage(options)))
|
|
17
|
+
});
|
|
34
18
|
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
//# sourceMappingURL=inject-infinite-query.mjs.map
|
|
19
|
+
//#endregion
|
|
20
|
+
export { injectInfiniteQuery };
|
|
21
|
+
|
|
22
|
+
//# sourceMappingURL=inject-infinite-query.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"inject-infinite-query.mjs","sources":["../src/inject-infinite-query.ts"],"sourcesContent":["import { InfiniteQueryObserver } from '@tanstack/query-core'\nimport { assertInInjectionContext, untracked } from '@angular/core'\nimport { injectQueryZone } from './utils/inject-query-zone'\nimport { injectBaseQuery } from './inject-base-query'\nimport { signalProxy } from './utils/signal-proxy'\nimport { infiniteQueryResultFields } from './utils/result-fields'\nimport type {\n DefaultError,\n FetchNextPageOptions,\n FetchPreviousPageOptions,\n InfiniteData,\n InfiniteQueryObserverResult,\n QueryKey,\n QueryObserver,\n RefetchOptions,\n} from '@tanstack/query-core'\nimport type { Signal } from '@angular/core'\nimport type {\n CreateInfiniteQueryOptions,\n CreateInfiniteQueryResult,\n DefinedCreateInfiniteQueryResult,\n} from './types'\nimport type {\n DefinedInitialDataInfiniteOptions,\n UndefinedInitialDataInfiniteOptions,\n} from './infinite-query-options'\n\n/**\n * This overload is selected when `initialData` is set, so the resulting `data` signal is never `undefined`\n * (unless a `select` changes `TData` to include `undefined`).\n
|
|
1
|
+
{"version":3,"file":"inject-infinite-query.mjs","names":[],"sources":["../src/inject-infinite-query.ts"],"sourcesContent":["import { InfiniteQueryObserver } from '@tanstack/query-core'\nimport { assertInInjectionContext, untracked } from '@angular/core'\nimport { injectQueryZone } from './utils/inject-query-zone'\nimport { injectBaseQuery } from './inject-base-query'\nimport { signalProxy } from './utils/signal-proxy'\nimport { infiniteQueryResultFields } from './utils/result-fields'\nimport type {\n DefaultError,\n FetchNextPageOptions,\n FetchPreviousPageOptions,\n InfiniteData,\n InfiniteQueryObserverResult,\n QueryKey,\n QueryObserver,\n RefetchOptions,\n} from '@tanstack/query-core'\nimport type { Signal } from '@angular/core'\nimport type {\n CreateInfiniteQueryOptions,\n CreateInfiniteQueryResult,\n DefinedCreateInfiniteQueryResult,\n} from './types'\nimport type {\n DefinedInitialDataInfiniteOptions,\n UndefinedInitialDataInfiniteOptions,\n} from './infinite-query-options'\n\n/**\n * This overload is selected when `initialData` is set, so the resulting `data` signal is never `undefined`\n * (unless a `select` changes `TData` to include `undefined`).\n * @param optionsFn - A function returning infinite-query options with `initialData` set. Similar to\n * `computed` from Angular, this function runs in the reactive context.\n * @returns The infinite query result, typed so that `data` is never `undefined`.\n * @see https://tanstack.com/query/latest/docs/framework/angular/guides/infinite-queries\n * @see {@link infiniteQueryOptions} to share these options between `injectInfiniteQuery` and\n * `queryClient.infiniteQuery`.\n */\nexport function injectInfiniteQuery<\n TQueryFnData,\n TError = DefaultError,\n TData = InfiniteData<TQueryFnData>,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n>(\n optionsFn: () => DefinedInitialDataInfiniteOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n >,\n): DefinedCreateInfiniteQueryResult<TData, TError>\n\n/**\n * Injects an infinite query: a declarative dependency on an asynchronous source of data that is tied to a unique key.\n * Infinite queries can additively \"load more\" data onto an existing set of data or support infinite scroll.\n * @param optionsFn - A function that returns infinite query options. Similar to `computed` from Angular,\n * this function runs in the reactive context, so signals read inside it drive the query.\n * @returns The infinite query result.\n * @see https://tanstack.com/query/latest/docs/framework/angular/guides/infinite-queries\n * @see {@link infiniteQueryOptions} to share these options between `injectInfiniteQuery` and\n * `queryClient.infiniteQuery`.\n * @example\n * ```angular-ts\n * @Component({\n * selector: 'projects',\n * template: `\n * @if (query.isPending()) {\n * Loading...\n * } @else if (query.isError()) {\n * <span>Error: {{ query.error()?.message }}</span>\n * } @else {\n * @for (page of query.data().pages; track $index) {\n * @for (project of page; track project.id) {\n * <p>{{ project.name }}</p>\n * }\n * }\n * <button (click)=\"query.fetchNextPage()\">Load more</button>\n * }\n * `,\n * })\n * export class Projects {\n * readonly query = injectInfiniteQuery(() => ({\n * queryKey: ['projects'],\n * queryFn: ({ pageParam }) => fetchProjects(pageParam),\n * initialPageParam: 0,\n * getNextPageParam: (lastPage) => lastPage.nextCursor,\n * }))\n * }\n * ```\n */\nexport function injectInfiniteQuery<\n TQueryFnData,\n TError = DefaultError,\n TData = InfiniteData<TQueryFnData>,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n>(\n optionsFn: () => UndefinedInitialDataInfiniteOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n >,\n): CreateInfiniteQueryResult<TData, TError>\n\n/**\n * This overload accepts the general {@link CreateInfiniteQueryOptions} shape rather than the\n * `initialData`-aware overloads above, so whether `data` is defined can't be inferred from the call\n * site — useful when wrapping `injectInfiniteQuery` in your own helper.\n * @param optionsFn - A function that returns infinite query options. Similar to `computed` from Angular,\n * this function runs in the reactive context, so signals read inside it drive the query.\n * @returns The infinite query result.\n * @see https://tanstack.com/query/latest/docs/framework/angular/guides/infinite-queries\n */\nexport function injectInfiniteQuery<\n TQueryFnData,\n TError = DefaultError,\n TData = InfiniteData<TQueryFnData>,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n>(\n optionsFn: () => CreateInfiniteQueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n >,\n): CreateInfiniteQueryResult<TData, TError>\n\nexport function injectInfiniteQuery<\n TQueryFnData,\n TError = DefaultError,\n TData = InfiniteData<TQueryFnData>,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n>(\n optionsFn: () =>\n | DefinedInitialDataInfiniteOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n >\n | CreateInfiniteQueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n >,\n):\n | DefinedCreateInfiniteQueryResult<TData, TError>\n | CreateInfiniteQueryResult<TData, TError> {\n if (typeof ngDevMode === 'undefined' || ngDevMode) {\n assertInInjectionContext(injectInfiniteQuery)\n }\n const outsideZone = injectQueryZone()\n const [resultSignal, getObserver] = injectBaseQuery(\n optionsFn,\n InfiniteQueryObserver as typeof QueryObserver,\n )\n const getInfiniteObserver = () =>\n getObserver() as InfiniteQueryObserver<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n >\n return Object.assign(\n signalProxy(\n resultSignal as Signal<InfiniteQueryObserverResult<TData, TError>>,\n infiniteQueryResultFields,\n ),\n {\n refetch: (options?: RefetchOptions) =>\n outsideZone(() =>\n untracked(() => getInfiniteObserver().refetch(options)),\n ),\n fetchNextPage: (options?: FetchNextPageOptions) =>\n outsideZone(() =>\n untracked(() => getInfiniteObserver().fetchNextPage(options)),\n ),\n fetchPreviousPage: (options?: FetchPreviousPageOptions) =>\n outsideZone(() =>\n untracked(() => getInfiniteObserver().fetchPreviousPage(options)),\n ),\n },\n ) as unknown as\n | DefinedCreateInfiniteQueryResult<TData, TError>\n | CreateInfiniteQueryResult<TData, TError>\n}\n"],"mappings":";;;;;;;AAoIA,SAAgB,oBAOd,WAiB2C;CAC3C,IAAI,OAAO,cAAc,eAAe,WACtC,yBAAyB,mBAAmB;CAE9C,MAAM,cAAc,gBAAgB;CACpC,MAAM,CAAC,cAAc,eAAe,gBAClC,WACA,qBACF;CACA,MAAM,4BACJ,YAAY;CAOd,OAAO,OAAO,OACZ,YACE,cACA,yBACF,GACA;EACE,UAAU,YACR,kBACE,gBAAgB,oBAAoB,CAAC,CAAC,QAAQ,OAAO,CAAC,CACxD;EACF,gBAAgB,YACd,kBACE,gBAAgB,oBAAoB,CAAC,CAAC,cAAc,OAAO,CAAC,CAC9D;EACF,oBAAoB,YAClB,kBACE,gBAAgB,oBAAoB,CAAC,CAAC,kBAAkB,OAAO,CAAC,CAClE;CACJ,CACF;AAGF"}
|
package/inject-is-fetching.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { Signal } from '@angular/core';
|
|
|
4
4
|
* Injects a signal that tracks the number of queries that your application is loading or fetching in the
|
|
5
5
|
* background (useful for app-wide loading indicators).
|
|
6
6
|
*
|
|
7
|
-
* Can be used for app-wide loading indicators
|
|
7
|
+
* Can be used for app-wide loading indicators.
|
|
8
8
|
* @param filters - A reactive factory for the filters.
|
|
9
9
|
* @returns signal with number of loading or fetching queries.
|
|
10
10
|
*/
|
package/inject-is-fetching.mjs
CHANGED
|
@@ -1,18 +1,25 @@
|
|
|
1
|
-
import { assertInInjectionContext, inject } from "@angular/core";
|
|
2
|
-
import { QueryClient } from "@tanstack/query-core";
|
|
3
1
|
import { injectExternalStore } from "./utils/inject-external-store.mjs";
|
|
2
|
+
import { QueryClient } from "@tanstack/query-core";
|
|
3
|
+
import { assertInInjectionContext, inject } from "@angular/core";
|
|
4
|
+
//#region src/inject-is-fetching.ts
|
|
5
|
+
/**
|
|
6
|
+
* Injects a signal that tracks the number of queries that your application is loading or fetching in the
|
|
7
|
+
* background (useful for app-wide loading indicators).
|
|
8
|
+
*
|
|
9
|
+
* Can be used for app-wide loading indicators.
|
|
10
|
+
* @param filters - A reactive factory for the filters.
|
|
11
|
+
* @returns signal with number of loading or fetching queries.
|
|
12
|
+
*/
|
|
4
13
|
function injectIsFetching(filters = () => ({})) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
subscribe: (onStoreChange) => cache.subscribe(onStoreChange)
|
|
13
|
-
}));
|
|
14
|
+
if (typeof ngDevMode === "undefined" || ngDevMode) assertInInjectionContext(injectIsFetching);
|
|
15
|
+
const queryClient = inject(QueryClient);
|
|
16
|
+
const cache = queryClient.getQueryCache();
|
|
17
|
+
return injectExternalStore(() => ({
|
|
18
|
+
getSnapshot: () => queryClient.isFetching(filters()),
|
|
19
|
+
subscribe: (onStoreChange) => cache.subscribe(onStoreChange)
|
|
20
|
+
}));
|
|
14
21
|
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
//# sourceMappingURL=inject-is-fetching.mjs.map
|
|
22
|
+
//#endregion
|
|
23
|
+
export { injectIsFetching };
|
|
24
|
+
|
|
25
|
+
//# sourceMappingURL=inject-is-fetching.mjs.map
|