@tanstack/angular-query 5.0.0-rc.3 → 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.
Files changed (70) hide show
  1. package/hydration-state-key.mjs +10 -13
  2. package/hydration-state-key.mjs.map +1 -1
  3. package/index.mjs +8 -20
  4. package/index.mjs.map +1 -1
  5. package/infinite-query-options.d.ts +7 -18
  6. package/infinite-query-options.mjs +6 -5
  7. package/infinite-query-options.mjs.map +1 -1
  8. package/inject-base-query.d.ts +3 -0
  9. package/inject-base-query.mjs +62 -58
  10. package/inject-base-query.mjs.map +1 -1
  11. package/inject-infinite-query.d.ts +7 -11
  12. package/inject-infinite-query.mjs +16 -32
  13. package/inject-infinite-query.mjs.map +1 -1
  14. package/inject-is-fetching.d.ts +1 -1
  15. package/inject-is-fetching.mjs +22 -15
  16. package/inject-is-fetching.mjs.map +1 -1
  17. package/inject-is-mutating.d.ts +1 -1
  18. package/inject-is-mutating.mjs +22 -15
  19. package/inject-is-mutating.mjs.map +1 -1
  20. package/inject-is-restoring.d.ts +2 -0
  21. package/inject-is-restoring.mjs +28 -17
  22. package/inject-is-restoring.mjs.map +1 -1
  23. package/inject-mutation-state.d.ts +9 -0
  24. package/inject-mutation-state.mjs +25 -23
  25. package/inject-mutation-state.mjs.map +1 -1
  26. package/inject-mutation.d.ts +2 -4
  27. package/inject-mutation.mjs +87 -67
  28. package/inject-mutation.mjs.map +1 -1
  29. package/inject-queries.d.ts +1 -3
  30. package/inject-queries.mjs +122 -114
  31. package/inject-queries.mjs.map +1 -1
  32. package/inject-queries.types.d.ts +17 -1
  33. package/inject-query.d.ts +7 -13
  34. package/inject-query.mjs +11 -14
  35. package/inject-query.mjs.map +1 -1
  36. package/internal.mjs +2 -7
  37. package/mutation-options.d.ts +2 -6
  38. package/mutation-options.mjs +6 -5
  39. package/mutation-options.mjs.map +1 -1
  40. package/package.json +2 -2
  41. package/providers.d.ts +16 -14
  42. package/providers.mjs +138 -75
  43. package/providers.mjs.map +1 -1
  44. package/query-options.d.ts +6 -16
  45. package/query-options.mjs +6 -5
  46. package/query-options.mjs.map +1 -1
  47. package/query-resource.d.ts +4 -3
  48. package/query-resource.mjs +72 -63
  49. package/query-resource.mjs.map +1 -1
  50. package/schematics/migrate-from-experimental/index.js +38 -9
  51. package/schematics/migrate-from-experimental/workspace.js +48 -12
  52. package/schematics/ng-add/index.js +1 -1
  53. package/types.d.ts +76 -16
  54. package/utils/inject-external-store.d.ts +3 -0
  55. package/utils/inject-external-store.mjs +54 -38
  56. package/utils/inject-external-store.mjs.map +1 -1
  57. package/utils/inject-pending-tasks-lifecycle.d.ts +13 -1
  58. package/utils/inject-pending-tasks-lifecycle.mjs +32 -29
  59. package/utils/inject-pending-tasks-lifecycle.mjs.map +1 -1
  60. package/utils/inject-query-zone.d.ts +4 -1
  61. package/utils/inject-query-zone.mjs +12 -7
  62. package/utils/inject-query-zone.mjs.map +1 -1
  63. package/utils/resource-types.d.ts +3 -0
  64. package/utils/result-fields.d.ts +9 -0
  65. package/utils/result-fields.mjs +55 -62
  66. package/utils/result-fields.mjs.map +1 -1
  67. package/utils/signal-proxy.d.ts +6 -0
  68. package/utils/signal-proxy.mjs +16 -9
  69. package/utils/signal-proxy.mjs.map +1 -1
  70. package/internal.mjs.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"inject-is-fetching.mjs","sources":["../src/inject-is-fetching.ts"],"sourcesContent":["import { assertInInjectionContext, inject } from '@angular/core'\nimport { QueryClient } from '@tanstack/query-core'\nimport { injectExternalStore } from './utils/inject-external-store'\nimport type { QueryFilters } from '@tanstack/query-core'\nimport type { Signal } from '@angular/core'\n\n/**\n * Injects a signal that tracks the number of queries that your application is loading or fetching in the\n * background (useful for app-wide loading indicators).\n *\n * Can be used for app-wide loading indicators\n * @param filters - A reactive factory for the filters.\n * @returns signal with number of loading or fetching queries.\n */\nexport function injectIsFetching(\n filters: () => QueryFilters = () => ({}),\n): Signal<number> {\n if (typeof ngDevMode === 'undefined' || ngDevMode) {\n assertInInjectionContext(injectIsFetching)\n }\n const queryClient = inject(QueryClient)\n const cache = queryClient.getQueryCache()\n\n return injectExternalStore(() => ({\n getSnapshot: () => queryClient.isFetching(filters()),\n subscribe: (onStoreChange) => cache.subscribe(onStoreChange),\n }))\n}\n"],"names":[],"mappings":";;;AAcO,SAAS,iBACd,UAA8B,OAAO,CAAA,IACrB;AAChB,MAAI,OAAO,cAAc,eAAe,WAAW;AACjD,6BAAyB,gBAAgB;AAAA,EAC3C;AACA,QAAM,cAAc,OAAO,WAAW;AACtC,QAAM,QAAQ,YAAY,cAAA;AAE1B,SAAO,oBAAoB,OAAO;AAAA,IAChC,aAAa,MAAM,YAAY,WAAW,SAAS;AAAA,IACnD,WAAW,CAAC,kBAAkB,MAAM,UAAU,aAAa;AAAA,EAAA,EAC3D;AACJ;"}
1
+ {"version":3,"file":"inject-is-fetching.mjs","names":[],"sources":["../src/inject-is-fetching.ts"],"sourcesContent":["import { assertInInjectionContext, inject } from '@angular/core'\nimport { QueryClient } from '@tanstack/query-core'\nimport { injectExternalStore } from './utils/inject-external-store'\nimport type { QueryFilters } from '@tanstack/query-core'\nimport type { Signal } from '@angular/core'\n\n/**\n * Injects a signal that tracks the number of queries that your application is loading or fetching in the\n * background (useful for app-wide loading indicators).\n *\n * Can be used for app-wide loading indicators.\n * @param filters - A reactive factory for the filters.\n * @returns signal with number of loading or fetching queries.\n */\nexport function injectIsFetching(\n filters: () => QueryFilters = () => ({}),\n): Signal<number> {\n if (typeof ngDevMode === 'undefined' || ngDevMode) {\n assertInInjectionContext(injectIsFetching)\n }\n const queryClient = inject(QueryClient)\n const cache = queryClient.getQueryCache()\n\n return injectExternalStore(() => ({\n getSnapshot: () => queryClient.isFetching(filters()),\n subscribe: (onStoreChange) => cache.subscribe(onStoreChange),\n }))\n}\n"],"mappings":";;;;;;;;;;;;AAcA,SAAgB,iBACd,iBAAqC,CAAC,IACtB;CAChB,IAAI,OAAO,cAAc,eAAe,WACtC,yBAAyB,gBAAgB;CAE3C,MAAM,cAAc,OAAO,WAAW;CACtC,MAAM,QAAQ,YAAY,cAAc;CAExC,OAAO,2BAA2B;EAChC,mBAAmB,YAAY,WAAW,QAAQ,CAAC;EACnD,YAAY,kBAAkB,MAAM,UAAU,aAAa;CAC7D,EAAE;AACJ"}
@@ -4,7 +4,7 @@ import { Signal } from '@angular/core';
4
4
  * Injects a signal that tracks the number of mutations that your application currently has `pending`
5
5
  * (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 A read-only signal with the number of fetching mutations.
10
10
  */
@@ -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-mutating.ts
5
+ /**
6
+ * Injects a signal that tracks the number of mutations that your application currently has `pending`
7
+ * (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 A read-only signal with the number of fetching mutations.
12
+ */
4
13
  function injectIsMutating(filters = () => ({})) {
5
- if (typeof ngDevMode === "undefined" || ngDevMode) {
6
- assertInInjectionContext(injectIsMutating);
7
- }
8
- const queryClient = inject(QueryClient);
9
- const cache = queryClient.getMutationCache();
10
- return injectExternalStore(() => ({
11
- getSnapshot: () => queryClient.isMutating(filters()),
12
- subscribe: (onStoreChange) => cache.subscribe(onStoreChange)
13
- }));
14
+ if (typeof ngDevMode === "undefined" || ngDevMode) assertInInjectionContext(injectIsMutating);
15
+ const queryClient = inject(QueryClient);
16
+ const cache = queryClient.getMutationCache();
17
+ return injectExternalStore(() => ({
18
+ getSnapshot: () => queryClient.isMutating(filters()),
19
+ subscribe: (onStoreChange) => cache.subscribe(onStoreChange)
20
+ }));
14
21
  }
15
- export {
16
- injectIsMutating
17
- };
18
- //# sourceMappingURL=inject-is-mutating.mjs.map
22
+ //#endregion
23
+ export { injectIsMutating };
24
+
25
+ //# sourceMappingURL=inject-is-mutating.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"inject-is-mutating.mjs","sources":["../src/inject-is-mutating.ts"],"sourcesContent":["import { assertInInjectionContext, inject } from '@angular/core'\nimport { QueryClient } from '@tanstack/query-core'\nimport { injectExternalStore } from './utils/inject-external-store'\nimport type { MutationFilters } from '@tanstack/query-core'\nimport type { Signal } from '@angular/core'\n\n/**\n * Injects a signal that tracks the number of mutations that your application currently has `pending`\n * (useful for app-wide loading indicators).\n *\n * Can be used for app-wide loading indicators\n * @param filters - A reactive factory for the filters.\n * @returns A read-only signal with the number of fetching mutations.\n */\nexport function injectIsMutating(\n filters: () => MutationFilters = () => ({}),\n): Signal<number> {\n if (typeof ngDevMode === 'undefined' || ngDevMode) {\n assertInInjectionContext(injectIsMutating)\n }\n const queryClient = inject(QueryClient)\n const cache = queryClient.getMutationCache()\n\n return injectExternalStore(() => ({\n getSnapshot: () => queryClient.isMutating(filters()),\n subscribe: (onStoreChange) => cache.subscribe(onStoreChange),\n }))\n}\n"],"names":[],"mappings":";;;AAcO,SAAS,iBACd,UAAiC,OAAO,CAAA,IACxB;AAChB,MAAI,OAAO,cAAc,eAAe,WAAW;AACjD,6BAAyB,gBAAgB;AAAA,EAC3C;AACA,QAAM,cAAc,OAAO,WAAW;AACtC,QAAM,QAAQ,YAAY,iBAAA;AAE1B,SAAO,oBAAoB,OAAO;AAAA,IAChC,aAAa,MAAM,YAAY,WAAW,SAAS;AAAA,IACnD,WAAW,CAAC,kBAAkB,MAAM,UAAU,aAAa;AAAA,EAAA,EAC3D;AACJ;"}
1
+ {"version":3,"file":"inject-is-mutating.mjs","names":[],"sources":["../src/inject-is-mutating.ts"],"sourcesContent":["import { assertInInjectionContext, inject } from '@angular/core'\nimport { QueryClient } from '@tanstack/query-core'\nimport { injectExternalStore } from './utils/inject-external-store'\nimport type { MutationFilters } from '@tanstack/query-core'\nimport type { Signal } from '@angular/core'\n\n/**\n * Injects a signal that tracks the number of mutations that your application currently has `pending`\n * (useful for app-wide loading indicators).\n *\n * Can be used for app-wide loading indicators.\n * @param filters - A reactive factory for the filters.\n * @returns A read-only signal with the number of fetching mutations.\n */\nexport function injectIsMutating(\n filters: () => MutationFilters = () => ({}),\n): Signal<number> {\n if (typeof ngDevMode === 'undefined' || ngDevMode) {\n assertInInjectionContext(injectIsMutating)\n }\n const queryClient = inject(QueryClient)\n const cache = queryClient.getMutationCache()\n\n return injectExternalStore(() => ({\n getSnapshot: () => queryClient.isMutating(filters()),\n subscribe: (onStoreChange) => cache.subscribe(onStoreChange),\n }))\n}\n"],"mappings":";;;;;;;;;;;;AAcA,SAAgB,iBACd,iBAAwC,CAAC,IACzB;CAChB,IAAI,OAAO,cAAc,eAAe,WACtC,yBAAyB,gBAAgB;CAE3C,MAAM,cAAc,OAAO,WAAW;CACtC,MAAM,QAAQ,YAAY,iBAAiB;CAE3C,OAAO,2BAA2B;EAChC,mBAAmB,YAAY,WAAW,QAAQ,CAAC;EACnD,YAAY,kBAAkB,MAAM,UAAU,aAAa;CAC7D,EAAE;AACJ"}
@@ -9,5 +9,7 @@ export declare function injectIsRestoring(): Signal<boolean>;
9
9
  * Supplies injector-scoped restoration state to the Angular Query integrations.
10
10
  * The factory runs once in Angular's injection context.
11
11
  * @internal
12
+ * @param isRestoringFactory - Produces the restoration signal for this injector.
13
+ * @returns The provider that makes the restoration state injectable.
12
14
  */
13
15
  export declare function provideIsRestoring(isRestoringFactory: () => Signal<boolean>): Provider;
@@ -1,21 +1,32 @@
1
- import { assertInInjectionContext, inject, InjectionToken, signal } from "@angular/core";
2
- const IS_RESTORING = new InjectionToken("", {
3
- factory: () => signal(false).asReadonly()
4
- });
1
+ import { InjectionToken, assertInInjectionContext, inject, signal } from "@angular/core";
2
+ //#region src/inject-is-restoring.ts
3
+ /**
4
+ * Internal token used to track isRestoring state, accessible in public API through `injectIsRestoring` and set via `provideIsRestoring`
5
+ */
6
+ var IS_RESTORING = new InjectionToken("", { factory: () => signal(false).asReadonly() });
7
+ /**
8
+ * Injects a readonly signal that is true while the persistence integration restores
9
+ * cached query data. Returns false when no restoration is in progress.
10
+ * @returns The current restoration state.
11
+ */
5
12
  function injectIsRestoring() {
6
- if (typeof ngDevMode === "undefined" || ngDevMode) {
7
- assertInInjectionContext(injectIsRestoring);
8
- }
9
- return inject(IS_RESTORING);
13
+ if (typeof ngDevMode === "undefined" || ngDevMode) assertInInjectionContext(injectIsRestoring);
14
+ return inject(IS_RESTORING);
10
15
  }
16
+ /**
17
+ * Supplies injector-scoped restoration state to the Angular Query integrations.
18
+ * The factory runs once in Angular's injection context.
19
+ * @internal
20
+ * @param isRestoringFactory - Produces the restoration signal for this injector.
21
+ * @returns The provider that makes the restoration state injectable.
22
+ */
11
23
  function provideIsRestoring(isRestoringFactory) {
12
- return {
13
- provide: IS_RESTORING,
14
- useFactory: isRestoringFactory
15
- };
24
+ return {
25
+ provide: IS_RESTORING,
26
+ useFactory: isRestoringFactory
27
+ };
16
28
  }
17
- export {
18
- injectIsRestoring,
19
- provideIsRestoring
20
- };
21
- //# sourceMappingURL=inject-is-restoring.mjs.map
29
+ //#endregion
30
+ export { injectIsRestoring, provideIsRestoring };
31
+
32
+ //# sourceMappingURL=inject-is-restoring.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"inject-is-restoring.mjs","sources":["../src/inject-is-restoring.ts"],"sourcesContent":["import {\n InjectionToken,\n assertInInjectionContext,\n inject,\n signal,\n} from '@angular/core'\nimport type { Provider, Signal } from '@angular/core'\n\n/**\n * Internal token used to track isRestoring state, accessible in public API through `injectIsRestoring` and set via `provideIsRestoring`\n */\nconst IS_RESTORING = new InjectionToken('', {\n factory: () => signal(false).asReadonly(),\n})\n\n/**\n * Injects a readonly signal that is true while the persistence integration restores\n * cached query data. Returns false when no restoration is in progress.\n * @returns The current restoration state.\n */\nexport function injectIsRestoring() {\n if (typeof ngDevMode === 'undefined' || ngDevMode) {\n assertInInjectionContext(injectIsRestoring)\n }\n return inject(IS_RESTORING)\n}\n\n/**\n * Supplies injector-scoped restoration state to the Angular Query integrations.\n * The factory runs once in Angular's injection context.\n * @internal\n */\nexport function provideIsRestoring(\n isRestoringFactory: () => Signal<boolean>,\n): Provider {\n return {\n provide: IS_RESTORING,\n useFactory: isRestoringFactory,\n }\n}\n"],"names":[],"mappings":";AAWA,MAAM,eAAe,IAAI,eAAe,IAAI;AAAA,EAC1C,SAAS,MAAM,OAAO,KAAK,EAAE,WAAA;AAC/B,CAAC;AAOM,SAAS,oBAAoB;AAClC,MAAI,OAAO,cAAc,eAAe,WAAW;AACjD,6BAAyB,iBAAiB;AAAA,EAC5C;AACA,SAAO,OAAO,YAAY;AAC5B;AAOO,SAAS,mBACd,oBACU;AACV,SAAO;AAAA,IACL,SAAS;AAAA,IACT,YAAY;AAAA,EAAA;AAEhB;"}
1
+ {"version":3,"file":"inject-is-restoring.mjs","names":[],"sources":["../src/inject-is-restoring.ts"],"sourcesContent":["import {\n InjectionToken,\n assertInInjectionContext,\n inject,\n signal,\n} from '@angular/core'\nimport type { Provider, Signal } from '@angular/core'\n\n/**\n * Internal token used to track isRestoring state, accessible in public API through `injectIsRestoring` and set via `provideIsRestoring`\n */\nconst IS_RESTORING = new InjectionToken('', {\n factory: () => signal(false).asReadonly(),\n})\n\n/**\n * Injects a readonly signal that is true while the persistence integration restores\n * cached query data. Returns false when no restoration is in progress.\n * @returns The current restoration state.\n */\nexport function injectIsRestoring() {\n if (typeof ngDevMode === 'undefined' || ngDevMode) {\n assertInInjectionContext(injectIsRestoring)\n }\n return inject(IS_RESTORING)\n}\n\n/**\n * Supplies injector-scoped restoration state to the Angular Query integrations.\n * The factory runs once in Angular's injection context.\n * @internal\n * @param isRestoringFactory - Produces the restoration signal for this injector.\n * @returns The provider that makes the restoration state injectable.\n */\nexport function provideIsRestoring(\n isRestoringFactory: () => Signal<boolean>,\n): Provider {\n return {\n provide: IS_RESTORING,\n useFactory: isRestoringFactory,\n }\n}\n"],"mappings":";;;;;AAWA,IAAM,eAAe,IAAI,eAAe,IAAI,EAC1C,eAAe,OAAO,KAAK,CAAC,CAAC,WAAW,EAC1C,CAAC;;;;;;AAOD,SAAgB,oBAAoB;CAClC,IAAI,OAAO,cAAc,eAAe,WACtC,yBAAyB,iBAAiB;CAE5C,OAAO,OAAO,YAAY;AAC5B;;;;;;;;AASA,SAAgB,mBACd,oBACU;CACV,OAAO;EACL,SAAS;EACT,YAAY;CACd;AACF"}
@@ -3,8 +3,17 @@ import { Mutation, MutationFilters, MutationState } from '@tanstack/query-core';
3
3
  type MutationTypeFromResult<TResult> = [TResult] extends [
4
4
  MutationState<infer TData, infer TError, infer TVariables, infer TOnMutateResult>
5
5
  ] ? Mutation<TData, TError, TVariables, TOnMutateResult> : Mutation;
6
+ /**
7
+ * Filters and optional projection for observing entries in the mutation cache.
8
+ */
6
9
  export type MutationStateOptions<TResult = MutationState, TMutation extends Mutation<any, any, any, any> = MutationTypeFromResult<TResult>> = {
10
+ /**
11
+ * Restricts the mutation cache entries included in the result.
12
+ */
7
13
  filters?: MutationFilters;
14
+ /**
15
+ * Maps each matching mutation to the value exposed in the result signal.
16
+ */
8
17
  select?: (mutation: TMutation) => TResult;
9
18
  };
10
19
  /**
@@ -1,28 +1,30 @@
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-mutation-state.ts
5
+ /**
6
+ * Reads and projects the matching entries in a mutation cache.
7
+ * @param mutationCache - The cache to inspect.
8
+ * @param options - Filters and an optional projection for each entry.
9
+ * @returns The selected values, or each matching mutation state.
10
+ */
4
11
  function getResult(mutationCache, options) {
5
- return mutationCache.findAll(options.filters).map(
6
- (mutation) => options.select ? options.select(mutation) : mutation.state
7
- );
12
+ return mutationCache.findAll(options.filters).map((mutation) => options.select ? options.select(mutation) : mutation.state);
8
13
  }
14
+ /**
15
+ * Injects a signal that tracks the state of all mutations.
16
+ * @param options - A function that returns mutation state options.
17
+ * @returns The signal that tracks the state of all mutations.
18
+ */
9
19
  function injectMutationState(options = () => ({})) {
10
- if (typeof ngDevMode === "undefined" || ngDevMode) {
11
- assertInInjectionContext(injectMutationState);
12
- }
13
- const queryClient = inject(QueryClient);
14
- const mutationCache = queryClient.getMutationCache();
15
- return injectExternalStore(
16
- () => ({
17
- getSnapshot: () => getResult(mutationCache, options()),
18
- subscribe: (onStoreChange) => mutationCache.subscribe(onStoreChange)
19
- }),
20
- {
21
- equal: (previous, next) => previous.length === next.length && previous.every((value, index) => Object.is(value, next[index]))
22
- }
23
- );
20
+ if (typeof ngDevMode === "undefined" || ngDevMode) assertInInjectionContext(injectMutationState);
21
+ const mutationCache = inject(QueryClient).getMutationCache();
22
+ return injectExternalStore(() => ({
23
+ getSnapshot: () => getResult(mutationCache, options()),
24
+ subscribe: (onStoreChange) => mutationCache.subscribe(onStoreChange)
25
+ }), { equal: (previous, next) => previous.length === next.length && previous.every((value, index) => Object.is(value, next[index])) });
24
26
  }
25
- export {
26
- injectMutationState
27
- };
28
- //# sourceMappingURL=inject-mutation-state.mjs.map
27
+ //#endregion
28
+ export { injectMutationState };
29
+
30
+ //# sourceMappingURL=inject-mutation-state.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"inject-mutation-state.mjs","sources":["../src/inject-mutation-state.ts"],"sourcesContent":["import { assertInInjectionContext, inject } from '@angular/core'\nimport { QueryClient } from '@tanstack/query-core'\nimport { injectExternalStore } from './utils/inject-external-store'\nimport type { Signal } from '@angular/core'\nimport type {\n Mutation,\n MutationCache,\n MutationFilters,\n MutationState,\n} from '@tanstack/query-core'\n\ntype MutationTypeFromResult<TResult> = [TResult] extends [\n MutationState<\n infer TData,\n infer TError,\n infer TVariables,\n infer TOnMutateResult\n >,\n]\n ? Mutation<TData, TError, TVariables, TOnMutateResult>\n : Mutation\n\nexport type MutationStateOptions<\n TResult = MutationState,\n TMutation extends Mutation<any, any, any, any> =\n MutationTypeFromResult<TResult>,\n> = {\n filters?: MutationFilters\n select?: (mutation: TMutation) => TResult\n}\n\nfunction getResult<\n TResult = MutationState,\n TMutation extends Mutation<any, any, any, any> =\n MutationTypeFromResult<TResult>,\n>(\n mutationCache: MutationCache,\n options: MutationStateOptions<TResult, TMutation>,\n): Array<TResult> {\n return mutationCache\n .findAll(options.filters)\n .map(\n (mutation): TResult =>\n (options.select\n ? options.select(mutation as TMutation)\n : mutation.state) as TResult,\n )\n}\n\n/**\n * Injects a signal that tracks the state of all mutations.\n * @param options - A function that returns mutation state options.\n * @returns The signal that tracks the state of all mutations.\n */\nexport function injectMutationState<\n TResult = MutationState,\n TMutation extends Mutation<any, any, any, any> =\n MutationTypeFromResult<TResult>,\n>(\n options: () => MutationStateOptions<TResult, TMutation> = () => ({}),\n): Signal<Array<TResult>> {\n if (typeof ngDevMode === 'undefined' || ngDevMode) {\n assertInInjectionContext(injectMutationState)\n }\n const queryClient = inject(QueryClient)\n const mutationCache = queryClient.getMutationCache()\n\n return injectExternalStore(\n () => ({\n getSnapshot: () => getResult(mutationCache, options()),\n subscribe: (onStoreChange) => mutationCache.subscribe(onStoreChange),\n }),\n {\n equal: (previous, next) =>\n previous.length === next.length &&\n previous.every((value, index) => Object.is(value, next[index])),\n },\n )\n}\n"],"names":[],"mappings":";;;AA+BA,SAAS,UAKP,eACA,SACgB;AAChB,SAAO,cACJ,QAAQ,QAAQ,OAAO,EACvB;AAAA,IACC,CAAC,aACE,QAAQ,SACL,QAAQ,OAAO,QAAqB,IACpC,SAAS;AAAA,EAAA;AAErB;AAOO,SAAS,oBAKd,UAA0D,OAAO,CAAA,IACzC;AACxB,MAAI,OAAO,cAAc,eAAe,WAAW;AACjD,6BAAyB,mBAAmB;AAAA,EAC9C;AACA,QAAM,cAAc,OAAO,WAAW;AACtC,QAAM,gBAAgB,YAAY,iBAAA;AAElC,SAAO;AAAA,IACL,OAAO;AAAA,MACL,aAAa,MAAM,UAAU,eAAe,SAAS;AAAA,MACrD,WAAW,CAAC,kBAAkB,cAAc,UAAU,aAAa;AAAA,IAAA;AAAA,IAErE;AAAA,MACE,OAAO,CAAC,UAAU,SAChB,SAAS,WAAW,KAAK,UACzB,SAAS,MAAM,CAAC,OAAO,UAAU,OAAO,GAAG,OAAO,KAAK,KAAK,CAAC,CAAC;AAAA,IAAA;AAAA,EAClE;AAEJ;"}
1
+ {"version":3,"file":"inject-mutation-state.mjs","names":[],"sources":["../src/inject-mutation-state.ts"],"sourcesContent":["import { assertInInjectionContext, inject } from '@angular/core'\nimport { QueryClient } from '@tanstack/query-core'\nimport { injectExternalStore } from './utils/inject-external-store'\nimport type { Signal } from '@angular/core'\nimport type {\n Mutation,\n MutationCache,\n MutationFilters,\n MutationState,\n} from '@tanstack/query-core'\n\ntype MutationTypeFromResult<TResult> = [TResult] extends [\n MutationState<\n infer TData,\n infer TError,\n infer TVariables,\n infer TOnMutateResult\n >,\n]\n ? Mutation<TData, TError, TVariables, TOnMutateResult>\n : Mutation\n\n/**\n * Filters and optional projection for observing entries in the mutation cache.\n */\nexport type MutationStateOptions<\n TResult = MutationState,\n TMutation extends Mutation<any, any, any, any> =\n MutationTypeFromResult<TResult>,\n> = {\n /**\n * Restricts the mutation cache entries included in the result.\n */\n filters?: MutationFilters\n /**\n * Maps each matching mutation to the value exposed in the result signal.\n */\n select?: (mutation: TMutation) => TResult\n}\n\n/**\n * Reads and projects the matching entries in a mutation cache.\n * @param mutationCache - The cache to inspect.\n * @param options - Filters and an optional projection for each entry.\n * @returns The selected values, or each matching mutation state.\n */\nfunction getResult<\n TResult = MutationState,\n TMutation extends Mutation<any, any, any, any> =\n MutationTypeFromResult<TResult>,\n>(\n mutationCache: MutationCache,\n options: MutationStateOptions<TResult, TMutation>,\n): Array<TResult> {\n return mutationCache\n .findAll(options.filters)\n .map(\n (mutation): TResult =>\n (options.select\n ? options.select(mutation as TMutation)\n : mutation.state) as TResult,\n )\n}\n\n/**\n * Injects a signal that tracks the state of all mutations.\n * @param options - A function that returns mutation state options.\n * @returns The signal that tracks the state of all mutations.\n */\nexport function injectMutationState<\n TResult = MutationState,\n TMutation extends Mutation<any, any, any, any> =\n MutationTypeFromResult<TResult>,\n>(\n options: () => MutationStateOptions<TResult, TMutation> = () => ({}),\n): Signal<Array<TResult>> {\n if (typeof ngDevMode === 'undefined' || ngDevMode) {\n assertInInjectionContext(injectMutationState)\n }\n const queryClient = inject(QueryClient)\n const mutationCache = queryClient.getMutationCache()\n\n return injectExternalStore(\n () => ({\n getSnapshot: () => getResult(mutationCache, options()),\n subscribe: (onStoreChange) => mutationCache.subscribe(onStoreChange),\n }),\n {\n equal: (previous, next) =>\n previous.length === next.length &&\n previous.every((value, index) => Object.is(value, next[index])),\n },\n )\n}\n"],"mappings":";;;;;;;;;;AA8CA,SAAS,UAKP,eACA,SACgB;CAChB,OAAO,cACJ,QAAQ,QAAQ,OAAO,CAAC,CACxB,KACE,aACE,QAAQ,SACL,QAAQ,OAAO,QAAqB,IACpC,SAAS,KACjB;AACJ;;;;;;AAOA,SAAgB,oBAKd,iBAAiE,CAAC,IAC1C;CACxB,IAAI,OAAO,cAAc,eAAe,WACtC,yBAAyB,mBAAmB;CAG9C,MAAM,gBADc,OAAO,WACL,CAAA,CAAY,iBAAiB;CAEnD,OAAO,2BACE;EACL,mBAAmB,UAAU,eAAe,QAAQ,CAAC;EACrD,YAAY,kBAAkB,cAAc,UAAU,aAAa;CACrE,IACA,EACE,QAAQ,UAAU,SAChB,SAAS,WAAW,KAAK,UACzB,SAAS,OAAO,OAAO,UAAU,OAAO,GAAG,OAAO,KAAK,MAAM,CAAC,EAClE,CACF;AACF"}
@@ -3,13 +3,11 @@ import { CreateMutationOptions, CreateMutationResult } from './types.js';
3
3
  /**
4
4
  * Injects a mutation: an imperative function that can be invoked which typically performs server side effects.
5
5
  * Unlike queries, mutations are not run automatically.
6
- *
7
- * @see https://tanstack.com/query/latest/docs/framework/angular/guides/mutations
8
- * @see {@link mutationOptions} to share these options between `injectMutation` and `injectMutationState`.
9
6
  * @param optionsFn - A function that returns mutation options. Similar to `computed` from Angular, this
10
7
  * function runs in the reactive context, so signals read inside it drive the mutation.
11
8
  * @returns The mutation result, including `mutate` and `mutateAsync`.
12
- *
9
+ * @see https://tanstack.com/query/latest/docs/framework/angular/guides/mutations
10
+ * @see {@link mutationOptions} to share these options between `injectMutation` and `injectMutationState`.
13
11
  * @example
14
12
  * ```angular-ts
15
13
  * @Component({
@@ -1,72 +1,92 @@
1
- import { assertInInjectionContext, inject, computed, untracked, effect } from "@angular/core";
2
- import { QueryClient, MutationObserver, noop } from "@tanstack/query-core";
3
1
  import { injectQueryZone } from "./utils/inject-query-zone.mjs";
4
- import { signalProxy } from "./utils/signal-proxy.mjs";
5
- import { mutationResultFields } from "./utils/result-fields.mjs";
6
2
  import { injectPendingTasksLifecycle } from "./utils/inject-pending-tasks-lifecycle.mjs";
7
3
  import { injectExternalStore } from "./utils/inject-external-store.mjs";
4
+ import { signalProxy } from "./utils/signal-proxy.mjs";
5
+ import { mutationResultFields } from "./utils/result-fields.mjs";
6
+ import { MutationObserver, QueryClient, noop } from "@tanstack/query-core";
7
+ import { assertInInjectionContext, computed, effect, inject, untracked } from "@angular/core";
8
+ //#region src/inject-mutation.ts
9
+ /**
10
+ * Injects a mutation: an imperative function that can be invoked which typically performs server side effects.
11
+ * Unlike queries, mutations are not run automatically.
12
+ * @param optionsFn - A function that returns mutation options. Similar to `computed` from Angular, this
13
+ * function runs in the reactive context, so signals read inside it drive the mutation.
14
+ * @returns The mutation result, including `mutate` and `mutateAsync`.
15
+ * @see https://tanstack.com/query/latest/docs/framework/angular/guides/mutations
16
+ * @see {@link mutationOptions} to share these options between `injectMutation` and `injectMutationState`.
17
+ * @example
18
+ * ```angular-ts
19
+ * @Component({
20
+ * template: `
21
+ * @if (mutation.isPending()) {
22
+ * Saving...
23
+ * } @else if (mutation.isError()) {
24
+ * <span>Error: {{ mutation.error()?.message }}</span>
25
+ * }
26
+ * <button (click)="mutation.mutate({ title: 'New post' })">Create</button>
27
+ * `,
28
+ * })
29
+ * export class CreatePost {
30
+ * readonly mutation = injectMutation(() => ({
31
+ * mutationFn: createPost,
32
+ * }))
33
+ * }
34
+ * ```
35
+ */
8
36
  function injectMutation(optionsFn) {
9
- if (typeof ngDevMode === "undefined" || ngDevMode) {
10
- assertInInjectionContext(injectMutation);
11
- }
12
- const outsideZone = injectQueryZone();
13
- const queryClient = inject(QueryClient);
14
- const lifecycle = injectPendingTasksLifecycle();
15
- const optionsSignal = computed(optionsFn);
16
- const observerSignal = computed(
17
- () => new MutationObserver(queryClient, untracked(optionsSignal))
18
- );
19
- effect(() => {
20
- const options = optionsSignal();
21
- outsideZone(() => untracked(() => observerSignal().setOptions(options)));
22
- });
23
- const mutationStateSignal = injectExternalStore(() => {
24
- const observer = observerSignal();
25
- return {
26
- getSnapshot: () => observer.getCurrentResult(),
27
- subscribe: (onStoreChange) => observer.subscribe(onStoreChange)
28
- };
29
- });
30
- const mutate = (...args) => {
31
- mutateAsync(...args).catch(noop);
32
- };
33
- let pendingInvocations = 0;
34
- const mutateAsync = (...args) => {
35
- return outsideZone(
36
- () => untracked(() => {
37
- const observer = observerSignal();
38
- observer.setOptions(optionsSignal());
39
- pendingInvocations++;
40
- lifecycle.setPending(true);
41
- const settled = () => {
42
- pendingInvocations--;
43
- lifecycle.setPending(pendingInvocations > 0);
44
- };
45
- try {
46
- return observer.mutate(args[0], args[1]).finally(settled);
47
- } catch (error) {
48
- settled();
49
- throw error;
50
- }
51
- })
52
- );
53
- };
54
- const reset = () => {
55
- outsideZone(
56
- () => untracked(() => {
57
- const observer = observerSignal();
58
- observer.setOptions(optionsSignal());
59
- observer.reset();
60
- })
61
- );
62
- };
63
- return Object.assign(signalProxy(mutationStateSignal, mutationResultFields), {
64
- mutate,
65
- mutateAsync,
66
- reset
67
- });
37
+ if (typeof ngDevMode === "undefined" || ngDevMode) assertInInjectionContext(injectMutation);
38
+ const outsideZone = injectQueryZone();
39
+ const queryClient = inject(QueryClient);
40
+ const lifecycle = injectPendingTasksLifecycle();
41
+ const optionsSignal = computed(optionsFn);
42
+ const observerSignal = computed(() => new MutationObserver(queryClient, untracked(optionsSignal)));
43
+ effect(() => {
44
+ const options = optionsSignal();
45
+ outsideZone(() => untracked(() => observerSignal().setOptions(options)));
46
+ });
47
+ const mutationStateSignal = injectExternalStore(() => {
48
+ const observer = observerSignal();
49
+ return {
50
+ getSnapshot: () => observer.getCurrentResult(),
51
+ subscribe: (onStoreChange) => observer.subscribe(onStoreChange)
52
+ };
53
+ });
54
+ const mutate = (...args) => {
55
+ mutateAsync(...args).catch(noop);
56
+ };
57
+ let pendingInvocations = 0;
58
+ const mutateAsync = (...args) => {
59
+ return outsideZone(() => untracked(() => {
60
+ const observer = observerSignal();
61
+ observer.setOptions(optionsSignal());
62
+ pendingInvocations++;
63
+ lifecycle.setPending(true);
64
+ const settled = () => {
65
+ pendingInvocations--;
66
+ lifecycle.setPending(pendingInvocations > 0);
67
+ };
68
+ try {
69
+ return observer.mutate(args[0], args[1]).finally(settled);
70
+ } catch (error) {
71
+ settled();
72
+ throw error;
73
+ }
74
+ }));
75
+ };
76
+ const reset = () => {
77
+ outsideZone(() => untracked(() => {
78
+ const observer = observerSignal();
79
+ observer.setOptions(optionsSignal());
80
+ observer.reset();
81
+ }));
82
+ };
83
+ return Object.assign(signalProxy(mutationStateSignal, mutationResultFields), {
84
+ mutate,
85
+ mutateAsync,
86
+ reset
87
+ });
68
88
  }
69
- export {
70
- injectMutation
71
- };
72
- //# sourceMappingURL=inject-mutation.mjs.map
89
+ //#endregion
90
+ export { injectMutation };
91
+
92
+ //# sourceMappingURL=inject-mutation.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"inject-mutation.mjs","sources":["../src/inject-mutation.ts"],"sourcesContent":["import {\n assertInInjectionContext,\n computed,\n effect,\n inject,\n untracked,\n} from '@angular/core'\nimport { MutationObserver, QueryClient, noop } from '@tanstack/query-core'\nimport { injectQueryZone } from './utils/inject-query-zone'\nimport { signalProxy } from './utils/signal-proxy'\nimport { mutationResultFields } from './utils/result-fields'\nimport { injectPendingTasksLifecycle } from './utils/inject-pending-tasks-lifecycle'\nimport { injectExternalStore } from './utils/inject-external-store'\nimport type { DefaultError } from '@tanstack/query-core'\nimport type {\n CreateMutateAsyncFunction,\n CreateMutateFunction,\n CreateMutationOptions,\n CreateMutationResult,\n} from './types'\n\n/**\n * Injects a mutation: an imperative function that can be invoked which typically performs server side effects.\n * Unlike queries, mutations are not run automatically.\n *\n * @see https://tanstack.com/query/latest/docs/framework/angular/guides/mutations\n * @see {@link mutationOptions} to share these options between `injectMutation` and `injectMutationState`.\n * @param optionsFn - A function that returns mutation options. Similar to `computed` from Angular, this\n * function runs in the reactive context, so signals read inside it drive the mutation.\n * @returns The mutation result, including `mutate` and `mutateAsync`.\n *\n * @example\n * ```angular-ts\n * @Component({\n * template: `\n * @if (mutation.isPending()) {\n * Saving...\n * } @else if (mutation.isError()) {\n * <span>Error: {{ mutation.error()?.message }}</span>\n * }\n * <button (click)=\"mutation.mutate({ title: 'New post' })\">Create</button>\n * `,\n * })\n * export class CreatePost {\n * readonly mutation = injectMutation(() => ({\n * mutationFn: createPost,\n * }))\n * }\n * ```\n */\nexport function injectMutation<\n TData = unknown,\n TError = DefaultError,\n TVariables = void,\n TOnMutateResult = unknown,\n>(\n optionsFn: () => CreateMutationOptions<\n TData,\n TError,\n TVariables,\n TOnMutateResult\n >,\n): CreateMutationResult<TData, TError, TVariables, TOnMutateResult> {\n if (typeof ngDevMode === 'undefined' || ngDevMode) {\n assertInInjectionContext(injectMutation)\n }\n const outsideZone = injectQueryZone()\n const queryClient = inject(QueryClient)\n const lifecycle = injectPendingTasksLifecycle()\n\n const optionsSignal = computed(optionsFn)\n\n const observerSignal = computed(\n () => new MutationObserver(queryClient, untracked(optionsSignal)),\n )\n\n // Configure the observer outside the result computation. Mutation-cache\n // listeners can synchronously read the public result while setOptions emits.\n effect(() => {\n const options = optionsSignal()\n outsideZone(() => untracked(() => observerSignal().setOptions(options)))\n })\n\n const mutationStateSignal = injectExternalStore(() => {\n const observer = observerSignal()\n return {\n getSnapshot: () => observer.getCurrentResult(),\n subscribe: (onStoreChange) => observer.subscribe(onStoreChange),\n }\n })\n\n const mutate: CreateMutateFunction<\n TData,\n TError,\n TVariables,\n TOnMutateResult\n > = (...args) => {\n mutateAsync(...args).catch(noop)\n }\n\n let pendingInvocations = 0\n\n const mutateAsync: CreateMutateAsyncFunction<\n TData,\n TError,\n TVariables,\n TOnMutateResult\n > = (...args) => {\n return outsideZone(() =>\n untracked(() => {\n const observer = observerSignal()\n observer.setOptions(optionsSignal())\n pendingInvocations++\n lifecycle.setPending(true)\n // Track invocations, not the observer's latest result: reset or a later\n // mutation completing must not release work which is still running.\n const settled = () => {\n pendingInvocations--\n lifecycle.setPending(pendingInvocations > 0)\n }\n try {\n return observer\n .mutate(args[0] as TVariables, args[1])\n .finally(settled)\n } catch (error) {\n settled()\n throw error\n }\n }),\n )\n }\n\n const reset = () => {\n outsideZone(() =>\n untracked(() => {\n const observer = observerSignal()\n observer.setOptions(optionsSignal())\n observer.reset()\n }),\n )\n }\n\n return Object.assign(signalProxy(mutationStateSignal, mutationResultFields), {\n mutate,\n mutateAsync,\n reset,\n }) as unknown as CreateMutationResult<\n TData,\n TError,\n TVariables,\n TOnMutateResult\n >\n}\n"],"names":[],"mappings":";;;;;;;AAkDO,SAAS,eAMd,WAMkE;AAClE,MAAI,OAAO,cAAc,eAAe,WAAW;AACjD,6BAAyB,cAAc;AAAA,EACzC;AACA,QAAM,cAAc,gBAAA;AACpB,QAAM,cAAc,OAAO,WAAW;AACtC,QAAM,YAAY,4BAAA;AAElB,QAAM,gBAAgB,SAAS,SAAS;AAExC,QAAM,iBAAiB;AAAA,IACrB,MAAM,IAAI,iBAAiB,aAAa,UAAU,aAAa,CAAC;AAAA,EAAA;AAKlE,SAAO,MAAM;AACX,UAAM,UAAU,cAAA;AAChB,gBAAY,MAAM,UAAU,MAAM,eAAA,EAAiB,WAAW,OAAO,CAAC,CAAC;AAAA,EACzE,CAAC;AAED,QAAM,sBAAsB,oBAAoB,MAAM;AACpD,UAAM,WAAW,eAAA;AACjB,WAAO;AAAA,MACL,aAAa,MAAM,SAAS,iBAAA;AAAA,MAC5B,WAAW,CAAC,kBAAkB,SAAS,UAAU,aAAa;AAAA,IAAA;AAAA,EAElE,CAAC;AAED,QAAM,SAKF,IAAI,SAAS;AACf,gBAAY,GAAG,IAAI,EAAE,MAAM,IAAI;AAAA,EACjC;AAEA,MAAI,qBAAqB;AAEzB,QAAM,cAKF,IAAI,SAAS;AACf,WAAO;AAAA,MAAY,MACjB,UAAU,MAAM;AACd,cAAM,WAAW,eAAA;AACjB,iBAAS,WAAW,eAAe;AACnC;AACA,kBAAU,WAAW,IAAI;AAGzB,cAAM,UAAU,MAAM;AACpB;AACA,oBAAU,WAAW,qBAAqB,CAAC;AAAA,QAC7C;AACA,YAAI;AACF,iBAAO,SACJ,OAAO,KAAK,CAAC,GAAiB,KAAK,CAAC,CAAC,EACrC,QAAQ,OAAO;AAAA,QACpB,SAAS,OAAO;AACd,kBAAA;AACA,gBAAM;AAAA,QACR;AAAA,MACF,CAAC;AAAA,IAAA;AAAA,EAEL;AAEA,QAAM,QAAQ,MAAM;AAClB;AAAA,MAAY,MACV,UAAU,MAAM;AACd,cAAM,WAAW,eAAA;AACjB,iBAAS,WAAW,eAAe;AACnC,iBAAS,MAAA;AAAA,MACX,CAAC;AAAA,IAAA;AAAA,EAEL;AAEA,SAAO,OAAO,OAAO,YAAY,qBAAqB,oBAAoB,GAAG;AAAA,IAC3E;AAAA,IACA;AAAA,IACA;AAAA,EAAA,CACD;AAMH;"}
1
+ {"version":3,"file":"inject-mutation.mjs","names":[],"sources":["../src/inject-mutation.ts"],"sourcesContent":["import {\n assertInInjectionContext,\n computed,\n effect,\n inject,\n untracked,\n} from '@angular/core'\nimport { MutationObserver, QueryClient, noop } from '@tanstack/query-core'\nimport { injectQueryZone } from './utils/inject-query-zone'\nimport { signalProxy } from './utils/signal-proxy'\nimport { mutationResultFields } from './utils/result-fields'\nimport { injectPendingTasksLifecycle } from './utils/inject-pending-tasks-lifecycle'\nimport { injectExternalStore } from './utils/inject-external-store'\nimport type { DefaultError } from '@tanstack/query-core'\nimport type {\n CreateMutateAsyncFunction,\n CreateMutateFunction,\n CreateMutationOptions,\n CreateMutationResult,\n} from './types'\n\n/**\n * Injects a mutation: an imperative function that can be invoked which typically performs server side effects.\n * Unlike queries, mutations are not run automatically.\n * @param optionsFn - A function that returns mutation options. Similar to `computed` from Angular, this\n * function runs in the reactive context, so signals read inside it drive the mutation.\n * @returns The mutation result, including `mutate` and `mutateAsync`.\n * @see https://tanstack.com/query/latest/docs/framework/angular/guides/mutations\n * @see {@link mutationOptions} to share these options between `injectMutation` and `injectMutationState`.\n * @example\n * ```angular-ts\n * @Component({\n * template: `\n * @if (mutation.isPending()) {\n * Saving...\n * } @else if (mutation.isError()) {\n * <span>Error: {{ mutation.error()?.message }}</span>\n * }\n * <button (click)=\"mutation.mutate({ title: 'New post' })\">Create</button>\n * `,\n * })\n * export class CreatePost {\n * readonly mutation = injectMutation(() => ({\n * mutationFn: createPost,\n * }))\n * }\n * ```\n */\nexport function injectMutation<\n TData = unknown,\n TError = DefaultError,\n TVariables = void,\n TOnMutateResult = unknown,\n>(\n optionsFn: () => CreateMutationOptions<\n TData,\n TError,\n TVariables,\n TOnMutateResult\n >,\n): CreateMutationResult<TData, TError, TVariables, TOnMutateResult> {\n if (typeof ngDevMode === 'undefined' || ngDevMode) {\n assertInInjectionContext(injectMutation)\n }\n const outsideZone = injectQueryZone()\n const queryClient = inject(QueryClient)\n const lifecycle = injectPendingTasksLifecycle()\n\n const optionsSignal = computed(optionsFn)\n\n const observerSignal = computed(\n () => new MutationObserver(queryClient, untracked(optionsSignal)),\n )\n\n // Configure the observer outside the result computation. Mutation-cache\n // listeners can synchronously read the public result while setOptions emits.\n effect(() => {\n const options = optionsSignal()\n outsideZone(() => untracked(() => observerSignal().setOptions(options)))\n })\n\n const mutationStateSignal = injectExternalStore(() => {\n const observer = observerSignal()\n return {\n getSnapshot: () => observer.getCurrentResult(),\n subscribe: (onStoreChange) => observer.subscribe(onStoreChange),\n }\n })\n\n const mutate: CreateMutateFunction<\n TData,\n TError,\n TVariables,\n TOnMutateResult\n > = (...args) => {\n mutateAsync(...args).catch(noop)\n }\n\n let pendingInvocations = 0\n\n const mutateAsync: CreateMutateAsyncFunction<\n TData,\n TError,\n TVariables,\n TOnMutateResult\n > = (...args) => {\n return outsideZone(() =>\n untracked(() => {\n const observer = observerSignal()\n observer.setOptions(optionsSignal())\n pendingInvocations++\n lifecycle.setPending(true)\n // Track invocations, not the observer's latest result: reset or a later\n // mutation completing must not release work which is still running.\n const settled = () => {\n pendingInvocations--\n lifecycle.setPending(pendingInvocations > 0)\n }\n try {\n return observer\n .mutate(args[0] as TVariables, args[1])\n .finally(settled)\n } catch (error) {\n settled()\n throw error\n }\n }),\n )\n }\n\n const reset = () => {\n outsideZone(() =>\n untracked(() => {\n const observer = observerSignal()\n observer.setOptions(optionsSignal())\n observer.reset()\n }),\n )\n }\n\n return Object.assign(signalProxy(mutationStateSignal, mutationResultFields), {\n mutate,\n mutateAsync,\n reset,\n }) as unknown as CreateMutationResult<\n TData,\n TError,\n TVariables,\n TOnMutateResult\n >\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgDA,SAAgB,eAMd,WAMkE;CAClE,IAAI,OAAO,cAAc,eAAe,WACtC,yBAAyB,cAAc;CAEzC,MAAM,cAAc,gBAAgB;CACpC,MAAM,cAAc,OAAO,WAAW;CACtC,MAAM,YAAY,4BAA4B;CAE9C,MAAM,gBAAgB,SAAS,SAAS;CAExC,MAAM,iBAAiB,eACf,IAAI,iBAAiB,aAAa,UAAU,aAAa,CAAC,CAClE;CAIA,aAAa;EACX,MAAM,UAAU,cAAc;EAC9B,kBAAkB,gBAAgB,eAAe,CAAC,CAAC,WAAW,OAAO,CAAC,CAAC;CACzE,CAAC;CAED,MAAM,sBAAsB,0BAA0B;EACpD,MAAM,WAAW,eAAe;EAChC,OAAO;GACL,mBAAmB,SAAS,iBAAiB;GAC7C,YAAY,kBAAkB,SAAS,UAAU,aAAa;EAChE;CACF,CAAC;CAED,MAAM,UAKD,GAAG,SAAS;EACf,YAAY,GAAG,IAAI,CAAC,CAAC,MAAM,IAAI;CACjC;CAEA,IAAI,qBAAqB;CAEzB,MAAM,eAKD,GAAG,SAAS;EACf,OAAO,kBACL,gBAAgB;GACd,MAAM,WAAW,eAAe;GAChC,SAAS,WAAW,cAAc,CAAC;GACnC;GACA,UAAU,WAAW,IAAI;GAGzB,MAAM,gBAAgB;IACpB;IACA,UAAU,WAAW,qBAAqB,CAAC;GAC7C;GACA,IAAI;IACF,OAAO,SACJ,OAAO,KAAK,IAAkB,KAAK,EAAE,CAAC,CACtC,QAAQ,OAAO;GACpB,SAAS,OAAO;IACd,QAAQ;IACR,MAAM;GACR;EACF,CAAC,CACH;CACF;CAEA,MAAM,cAAc;EAClB,kBACE,gBAAgB;GACd,MAAM,WAAW,eAAe;GAChC,SAAS,WAAW,cAAc,CAAC;GACnC,SAAS,MAAM;EACjB,CAAC,CACH;CACF;CAEA,OAAO,OAAO,OAAO,YAAY,qBAAqB,oBAAoB,GAAG;EAC3E;EACA;EACA;CACF,CAAC;AAMH"}
@@ -2,12 +2,10 @@ import { InjectQueriesOptions, QueriesResults } from './inject-queries.types.js'
2
2
  import { Signal } from '@angular/core';
3
3
  /**
4
4
  * Injects multiple queries that run in parallel and react to Angular signals.
5
- *
6
- * @see https://tanstack.com/query/latest/docs/framework/angular/guides/parallel-queries
7
5
  * @param optionsFn - A function that returns the queries' options. Similar to `computed` from Angular,
8
6
  * this function runs in the reactive context, so signals read inside it drive the queries.
9
7
  * @returns A signal containing the query results in the same order as the input queries.
10
- *
8
+ * @see https://tanstack.com/query/latest/docs/framework/angular/guides/parallel-queries
11
9
  * @example
12
10
  * ```angular-ts
13
11
  * @Component({