@tanstack/angular-query 5.0.0-rc.5 → 5.108.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 (55) hide show
  1. package/README.md +1 -1
  2. package/hydration-state-key.mjs +1 -2
  3. package/index.d.ts +1 -1
  4. package/index.mjs +1 -2
  5. package/index.mjs.map +1 -1
  6. package/infinite-query-options.d.ts +15 -13
  7. package/infinite-query-options.mjs +1 -2
  8. package/infinite-query-options.mjs.map +1 -1
  9. package/inject-base-query.mjs +3 -4
  10. package/inject-base-query.mjs.map +1 -1
  11. package/inject-infinite-query.d.ts +170 -33
  12. package/inject-infinite-query.mjs +2 -3
  13. package/inject-infinite-query.mjs.map +1 -1
  14. package/inject-is-fetching.d.ts +37 -6
  15. package/inject-is-fetching.mjs +36 -6
  16. package/inject-is-fetching.mjs.map +1 -1
  17. package/inject-is-mutating.d.ts +21 -6
  18. package/inject-is-mutating.mjs +20 -6
  19. package/inject-is-mutating.mjs.map +1 -1
  20. package/inject-is-restoring.d.ts +5 -3
  21. package/inject-is-restoring.mjs +6 -5
  22. package/inject-is-restoring.mjs.map +1 -1
  23. package/inject-mutation-state.d.ts +51 -3
  24. package/inject-mutation-state.mjs +52 -5
  25. package/inject-mutation-state.mjs.map +1 -1
  26. package/inject-mutation.d.ts +118 -13
  27. package/inject-mutation.mjs +121 -17
  28. package/inject-mutation.mjs.map +1 -1
  29. package/inject-queries.d.ts +113 -15
  30. package/inject-queries.mjs +116 -19
  31. package/inject-queries.mjs.map +1 -1
  32. package/inject-queries.types.d.ts +25 -5
  33. package/inject-query.d.ts +11 -8
  34. package/inject-query.mjs +2 -3
  35. package/inject-query.mjs.map +1 -1
  36. package/mutation-options.mjs +1 -2
  37. package/package.json +2 -2
  38. package/providers.d.ts +31 -6
  39. package/providers.mjs +32 -8
  40. package/providers.mjs.map +1 -1
  41. package/query-options.d.ts +23 -13
  42. package/query-options.mjs +1 -2
  43. package/query-options.mjs.map +1 -1
  44. package/query-resource.d.ts +4 -1
  45. package/query-resource.mjs +4 -2
  46. package/query-resource.mjs.map +1 -1
  47. package/schematics/migrate-from-experimental/index.js +3 -3
  48. package/schematics/migrate-from-experimental/workspace.js +1 -1
  49. package/schematics/ng-add/index.js +5 -4
  50. package/types.d.ts +38 -7
  51. package/utils/inject-external-store.mjs +1 -2
  52. package/utils/inject-pending-tasks-lifecycle.mjs +1 -2
  53. package/utils/inject-query-zone.mjs +1 -2
  54. package/utils/result-fields.mjs +1 -2
  55. package/utils/signal-proxy.mjs +1 -2
package/types.d.ts CHANGED
@@ -1,11 +1,18 @@
1
- import { DefaultError, DefinedInfiniteQueryObserverResult, DefinedQueryObserverResult, InfiniteQueryObserverOptions, InfiniteQueryObserverResult, MutateFunction, MutationObserverOptions, MutationObserverResult, OmitKeyof, Override, QueryKey, QueryObserverOptions, QueryObserverResult } from '@tanstack/query-core';
2
1
  import { Signal } from '@angular/core';
3
- import { MapToSignals } from './utils/signal-proxy.js';
2
+ import { DefaultError, DefinedInfiniteQueryObserverResult, DefinedQueryObserverResult, InfiniteQueryObserverOptions, InfiniteQueryObserverResult, MutateFunction, MutationObserverOptions, MutationObserverResult, OmitKeyof, Override, QueryKey, QueryObserverOptions, QueryObserverResult } from '@tanstack/query-core';
4
3
  import { InfiniteQueryResultFields, MutationResultFields, QueryResultFields } from './utils/result-fields.js';
4
+ import { MapToSignals } from './utils/signal-proxy.js';
5
5
  type SignalFunction<T extends () => any> = T & Signal<ReturnType<T>>;
6
6
  /**
7
- * Options accepted by `injectQuery`, with cache data projected through an optional `select`.
8
- * Angular owns result notifications and exposes errors through signals rather than error boundaries.
7
+ * The options accepted by `injectQuery`, with cache data projected through an optional `select`. Same as
8
+ * {@link QueryObserverOptions} from `@tanstack/query-core`, minus `notifyOnChangeProps`, `suspense`, and
9
+ * `throwOnError`: Angular owns result notifications and exposes errors through signals rather than error
10
+ * boundaries.
11
+ * @template TQueryFnData - The type your `queryFn` resolves to.
12
+ * @template TError - The type of errors your `queryFn` may throw.
13
+ * @template TData - The type `data` ends up as after `select` runs. Defaults to `TQueryFnData` when no
14
+ * `select` is used.
15
+ * @template TQueryKey - The type of your `queryKey`.
9
16
  */
10
17
  export type CreateQueryOptions<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey> = OmitKeyof<QueryObserverOptions<TQueryFnData, TError, TData, TQueryFnData, TQueryKey>, 'notifyOnChangeProps' | 'suspense' | 'throwOnError'>;
11
18
  type CreateStatusBasedQueryResult<TStatus extends QueryObserverResult['status'], TData = unknown, TError = DefaultError> = Extract<QueryObserverResult<TData, TError>, {
@@ -21,7 +28,13 @@ type CreateStatusBasedDefinedInfiniteQueryResult<TStatus extends DefinedInfinite
21
28
  status: TStatus;
22
29
  }>;
23
30
  /**
24
- * Signal-backed guards that narrow a query result and its data and error fields by status.
31
+ * Signal-backed guards that narrow a query result and its data and error fields by status: the
32
+ * `isSuccess`/`isError`/`isPending` methods on a query result. Unlike `react-query`'s derived booleans, each
33
+ * is a `Signal` you call to read its current boolean value reactively, and the call is also a type guard —
34
+ * `if (query.isSuccess())` — so that `query.data` narrows away `undefined` inside the branch, the same way
35
+ * `status` narrowing works on the plain object `react-query` returns.
36
+ * @template TData - The type `data` ends up as after `select` runs.
37
+ * @template TError - The type of errors your `queryFn` may throw.
25
38
  */
26
39
  export interface BaseQueryNarrowing<TData = unknown, TError = DefaultError> {
27
40
  /**
@@ -89,7 +102,17 @@ export interface DefinedInfiniteQueryNarrowing<TData = unknown, TError = Default
89
102
  isPending: SignalFunction<(this: DefinedCreateInfiniteQueryResult<TData, TError>) => this is never>;
90
103
  }
91
104
  /**
92
- * Options accepted by `injectInfiniteQuery`, including page parameters and pagination callbacks.
105
+ * The options accepted by `injectInfiniteQuery`, including page parameters and pagination callbacks. Same as
106
+ * {@link InfiniteQueryObserverOptions} from `@tanstack/query-core` — for the infinite-query-specific options
107
+ * (`getNextPageParam`, `initialPageParam`, etc.) — minus `notifyOnChangeProps`, `suspense`, and
108
+ * `throwOnError`, like {@link CreateQueryOptions}.
109
+ * @template TQueryFnData - The type of a single page, as your `queryFn` resolves it.
110
+ * @template TError - The type of errors your `queryFn` may throw.
111
+ * @template TData - The type `data` ends up as after `select` runs. Defaults to `TQueryFnData` here, though
112
+ * `injectInfiniteQuery` itself defaults it to `InfiniteData<TQueryFnData>` — the shape `data` actually has
113
+ * when no `select` is used.
114
+ * @template TQueryKey - The type of your `queryKey`.
115
+ * @template TPageParam - The type of the parameter passed to `queryFn` to fetch a given page.
93
116
  */
94
117
  export interface CreateInfiniteQueryOptions<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey, TPageParam = unknown> extends OmitKeyof<InfiniteQueryObserverOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>, 'notifyOnChangeProps' | 'suspense' | 'throwOnError'> {
95
118
  }
@@ -189,7 +212,15 @@ type CreateStatusBasedMutationResult<TStatus extends CreateBaseMutationResult['s
189
212
  status: TStatus;
190
213
  }>;
191
214
  /**
192
- * Signal-backed guards that narrow mutation data, errors, and variables by the current status.
215
+ * Signal-backed guards that narrow mutation data, errors, and variables by the current status: the
216
+ * `isSuccess`/`isError`/`isPending`/`isIdle` methods on a mutation result. Each is a `Signal` you call to
217
+ * read its current boolean value reactively, and the call is also a type guard — `if (mutation.isSuccess())`
218
+ * — so that `mutation.data` narrows away `undefined` inside the branch.
219
+ * @template TData - The type your mutation function resolves to.
220
+ * @template TError - The type of errors your mutation function may throw.
221
+ * @template TVariables - The type of the variable passed to `mutate`/`mutateAsync`.
222
+ * @template TOnMutateResult - The type returned by `onMutate`, passed to `onSuccess`/`onError`/`onSettled` as
223
+ * their `onMutateResult` parameter — useful for optimistic-update rollback data.
193
224
  */
194
225
  export interface BaseMutationNarrowing<TData = unknown, TError = DefaultError, TVariables = unknown, TOnMutateResult = unknown> {
195
226
  /**
@@ -1,6 +1,6 @@
1
1
  import { injectQueryZone } from "./inject-query-zone.mjs";
2
2
  import { DestroyRef, assertInInjectionContext, computed, effect, inject, signal, untracked } from "@angular/core";
3
- //#region src/utils/inject-external-store.ts
3
+ // src/utils/inject-external-store.ts
4
4
  /**
5
5
  * Creates a readonly Angular signal backed by a synchronous external store.
6
6
  *
@@ -51,7 +51,6 @@ function injectExternalStore(binding, options) {
51
51
  return outsideZone(() => requested().getSnapshot());
52
52
  }, options?.equal ? { equal: options.equal } : void 0);
53
53
  }
54
- //#endregion
55
54
  export { injectExternalStore };
56
55
 
57
56
  //# sourceMappingURL=inject-external-store.mjs.map
@@ -1,5 +1,5 @@
1
1
  import { DestroyRef, NgZone, PendingTasks, inject } from "@angular/core";
2
- //#region src/utils/inject-pending-tasks-lifecycle.ts
2
+ // src/utils/inject-pending-tasks-lifecycle.ts
3
3
  /**
4
4
  * Tracks pending work for the lifetime of the current injection context.
5
5
  * @returns The destruction state and pending-task controller for this context.
@@ -28,7 +28,6 @@ function injectPendingTasksLifecycle() {
28
28
  });
29
29
  return lifecycle;
30
30
  }
31
- //#endregion
32
31
  export { injectPendingTasksLifecycle };
33
32
 
34
33
  //# sourceMappingURL=inject-pending-tasks-lifecycle.mjs.map
@@ -1,5 +1,5 @@
1
1
  import { NgZone, inject } from "@angular/core";
2
- //#region src/utils/inject-query-zone.ts
2
+ // src/utils/inject-query-zone.ts
3
3
  /**
4
4
  * Keeps Query's background timers out of Angular's stability tracking.
5
5
  * @returns A function that runs callbacks outside the injected NgZone.
@@ -8,7 +8,6 @@ function injectQueryZone() {
8
8
  const ngZone = inject(NgZone);
9
9
  return (fn) => ngZone.runOutsideAngular(fn);
10
10
  }
11
- //#endregion
12
11
  export { injectQueryZone };
13
12
 
14
13
  //# sourceMappingURL=inject-query-zone.mjs.map
@@ -1,4 +1,4 @@
1
- //#region src/utils/result-fields.ts
1
+ // src/utils/result-fields.ts
2
2
  var queryFields = {
3
3
  data: true,
4
4
  dataUpdatedAt: true,
@@ -52,7 +52,6 @@ var mutationFields = {
52
52
  var queryResultFields = /* #__PURE__ */ Object.keys(queryFields);
53
53
  var infiniteQueryResultFields = /* #__PURE__ */ Object.keys(infiniteQueryFields);
54
54
  var mutationResultFields = /* #__PURE__ */ Object.keys(mutationFields);
55
- //#endregion
56
55
  export { infiniteQueryResultFields, mutationResultFields, queryResultFields };
57
56
 
58
57
  //# sourceMappingURL=result-fields.mjs.map
@@ -1,5 +1,5 @@
1
1
  import { computed } from "@angular/core";
2
- //#region src/utils/signal-proxy.ts
2
+ // src/utils/signal-proxy.ts
3
3
  /**
4
4
  * Maps known result fields to lazy computed signals on an ordinary object.
5
5
  * Creating or enumerating the fields never evaluates the source. Imperative
@@ -13,7 +13,6 @@ function signalProxy(inputSignal, fields) {
13
13
  for (const field of fields) result[field] = computed(() => inputSignal()[field]);
14
14
  return result;
15
15
  }
16
- //#endregion
17
16
  export { signalProxy };
18
17
 
19
18
  //# sourceMappingURL=signal-proxy.mjs.map