@tanstack/angular-query-experimental 5.103.1 → 5.103.3

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 (219) hide show
  1. package/dist/create-base-query.d.mts +169 -0
  2. package/dist/create-base-query.d.mts.map +1 -0
  3. package/dist/create-base-query.mjs +91 -0
  4. package/dist/create-base-query.mjs.map +1 -0
  5. package/dist/devtools/index.d.mts +3 -0
  6. package/dist/devtools/index.mjs +2 -0
  7. package/dist/devtools/production/index.d.mts +4 -0
  8. package/dist/devtools/production/index.mjs +2 -0
  9. package/dist/devtools/stub.d.mts +6 -0
  10. package/dist/devtools/stub.d.mts.map +1 -0
  11. package/dist/devtools/stub.mjs +9 -0
  12. package/dist/devtools/stub.mjs.map +1 -0
  13. package/dist/devtools/types.d.mts +107 -0
  14. package/dist/devtools/types.d.mts.map +1 -0
  15. package/dist/devtools/types.mjs +1 -0
  16. package/{devtools/with-devtools.d.ts → dist/devtools/with-devtools.d.mts} +6 -2
  17. package/dist/devtools/with-devtools.d.mts.map +1 -0
  18. package/dist/devtools/with-devtools.mjs +110 -0
  19. package/dist/devtools/with-devtools.mjs.map +1 -0
  20. package/dist/devtools-panel/index.d.mts +3 -0
  21. package/dist/devtools-panel/index.mjs +2 -0
  22. package/{devtools-panel/inject-devtools-panel.d.ts → dist/devtools-panel/inject-devtools-panel.d.mts} +6 -2
  23. package/dist/devtools-panel/inject-devtools-panel.d.mts.map +1 -0
  24. package/dist/devtools-panel/inject-devtools-panel.mjs +67 -0
  25. package/dist/devtools-panel/inject-devtools-panel.mjs.map +1 -0
  26. package/dist/devtools-panel/production/index.d.mts +4 -0
  27. package/dist/devtools-panel/production/index.mjs +2 -0
  28. package/dist/devtools-panel/stub.d.mts +6 -0
  29. package/dist/devtools-panel/stub.d.mts.map +1 -0
  30. package/dist/devtools-panel/stub.mjs +7 -0
  31. package/dist/devtools-panel/stub.mjs.map +1 -0
  32. package/dist/devtools-panel/types.d.mts +52 -0
  33. package/dist/devtools-panel/types.d.mts.map +1 -0
  34. package/dist/devtools-panel/types.mjs +1 -0
  35. package/dist/index.d.mts +16 -0
  36. package/{index.mjs → dist/index.mjs} +8 -21
  37. package/dist/index.mjs.map +1 -0
  38. package/{infinite-query-options.d.ts → dist/infinite-query-options.d.mts} +35 -31
  39. package/dist/infinite-query-options.d.mts.map +1 -0
  40. package/dist/infinite-query-options.mjs +8 -0
  41. package/dist/infinite-query-options.mjs.map +1 -0
  42. package/{inject-infinite-query.d.ts → dist/inject-infinite-query.d.mts} +18 -14
  43. package/dist/inject-infinite-query.d.mts.map +1 -0
  44. package/dist/inject-infinite-query.mjs +13 -0
  45. package/dist/inject-infinite-query.mjs.map +1 -0
  46. package/{inject-is-fetching.d.ts → dist/inject-is-fetching.d.mts} +14 -10
  47. package/dist/inject-is-fetching.d.mts.map +1 -0
  48. package/dist/inject-is-fetching.mjs +69 -0
  49. package/dist/inject-is-fetching.mjs.map +1 -0
  50. package/{inject-is-mutating.d.ts → dist/inject-is-mutating.d.mts} +14 -10
  51. package/dist/inject-is-mutating.d.mts.map +1 -0
  52. package/dist/inject-is-mutating.mjs +52 -0
  53. package/dist/inject-is-mutating.mjs.map +1 -0
  54. package/{inject-is-restoring.d.ts → dist/inject-is-restoring.d.mts} +13 -10
  55. package/dist/inject-is-restoring.d.mts.map +1 -0
  56. package/dist/inject-is-restoring.mjs +35 -0
  57. package/dist/inject-is-restoring.mjs.map +1 -0
  58. package/{inject-mutation-state.d.ts → dist/inject-mutation-state.d.mts} +16 -13
  59. package/dist/inject-mutation-state.d.mts.map +1 -0
  60. package/dist/inject-mutation-state.mjs +103 -0
  61. package/dist/inject-mutation-state.mjs.map +1 -0
  62. package/{inject-mutation.d.ts → dist/inject-mutation.d.mts} +15 -11
  63. package/dist/inject-mutation.d.mts.map +1 -0
  64. package/dist/inject-mutation.mjs +226 -0
  65. package/dist/inject-mutation.mjs.map +1 -0
  66. package/dist/inject-queries-experimental/index.d.mts +2 -0
  67. package/dist/inject-queries-experimental/index.mjs +2 -0
  68. package/{inject-queries.d.ts → dist/inject-queries.d.mts} +36 -55
  69. package/dist/inject-queries.d.mts.map +1 -0
  70. package/dist/inject-queries.mjs +203 -0
  71. package/dist/inject-queries.mjs.map +1 -0
  72. package/{inject-query-client.d.ts → dist/inject-query-client.d.mts} +8 -4
  73. package/dist/inject-query-client.d.mts.map +1 -0
  74. package/dist/inject-query-client.mjs +23 -0
  75. package/dist/inject-query-client.mjs.map +1 -0
  76. package/{inject-query.d.ts → dist/inject-query.d.mts} +18 -14
  77. package/dist/inject-query.d.mts.map +1 -0
  78. package/dist/inject-query.mjs +12 -0
  79. package/dist/inject-query.mjs.map +1 -0
  80. package/{mutation-options.d.ts → dist/mutation-options.d.mts} +8 -4
  81. package/dist/mutation-options.d.mts.map +1 -0
  82. package/dist/mutation-options.mjs +8 -0
  83. package/dist/mutation-options.mjs.map +1 -0
  84. package/dist/pending-tasks-compat.d.mts +10 -0
  85. package/dist/pending-tasks-compat.d.mts.map +1 -0
  86. package/dist/pending-tasks-compat.mjs +13 -0
  87. package/dist/pending-tasks-compat.mjs.map +1 -0
  88. package/{providers.d.ts → dist/providers.d.mts} +16 -13
  89. package/dist/providers.d.mts.map +1 -0
  90. package/dist/providers.mjs +124 -0
  91. package/dist/providers.mjs.map +1 -0
  92. package/{query-options.d.ts → dist/query-options.d.mts} +41 -37
  93. package/dist/query-options.d.mts.map +1 -0
  94. package/dist/query-options.mjs +8 -0
  95. package/dist/query-options.mjs.map +1 -0
  96. package/dist/signal-proxy.d.mts +13 -0
  97. package/dist/signal-proxy.d.mts.map +1 -0
  98. package/dist/signal-proxy.mjs +35 -0
  99. package/dist/signal-proxy.mjs.map +1 -0
  100. package/{types.d.ts → dist/types.d.mts} +36 -37
  101. package/dist/types.d.mts.map +1 -0
  102. package/dist/types.mjs +6 -0
  103. package/dist/types.mjs.map +1 -0
  104. package/package.json +48 -20
  105. package/src/__tests__/infinite-query-options.test-d.ts +314 -0
  106. package/src/__tests__/infinite-query-options.test.ts +19 -0
  107. package/src/__tests__/inject-devtools-panel.test.ts +196 -0
  108. package/src/__tests__/inject-infinite-query.test-d.ts +66 -0
  109. package/src/__tests__/inject-infinite-query.test.ts +227 -0
  110. package/src/__tests__/inject-is-fetching.test.ts +108 -0
  111. package/src/__tests__/inject-is-mutating.test.ts +113 -0
  112. package/src/__tests__/inject-is-restoring.test.ts +93 -0
  113. package/src/__tests__/inject-mutation-state.test-d.ts +22 -0
  114. package/src/__tests__/inject-mutation-state.test.ts +198 -0
  115. package/src/__tests__/inject-mutation.test-d.ts +158 -0
  116. package/src/__tests__/inject-mutation.test.ts +1161 -0
  117. package/src/__tests__/inject-queries.test-d.ts +196 -0
  118. package/src/__tests__/inject-queries.test.ts +240 -0
  119. package/src/__tests__/inject-query.test-d.ts +357 -0
  120. package/src/__tests__/inject-query.test.ts +700 -0
  121. package/src/__tests__/mutation-options.test-d.ts +234 -0
  122. package/src/__tests__/mutation-options.test.ts +344 -0
  123. package/src/__tests__/pending-tasks.test.ts +644 -0
  124. package/src/__tests__/provide-query-client.test.ts +38 -0
  125. package/src/__tests__/provide-tanstack-query.test.ts +38 -0
  126. package/src/__tests__/query-options.test-d.ts +262 -0
  127. package/src/__tests__/query-options.test.ts +14 -0
  128. package/src/__tests__/signal-proxy.test.ts +27 -0
  129. package/src/__tests__/test-utils.ts +77 -0
  130. package/src/__tests__/with-devtools.test.ts +674 -0
  131. package/src/create-base-query.ts +175 -0
  132. package/src/devtools/index.ts +8 -0
  133. package/src/devtools/production/index.ts +1 -0
  134. package/src/devtools/stub.ts +7 -0
  135. package/src/devtools/types.ts +116 -0
  136. package/src/devtools/with-devtools.ts +182 -0
  137. package/src/devtools-panel/index.ts +8 -0
  138. package/src/devtools-panel/inject-devtools-panel.ts +110 -0
  139. package/src/devtools-panel/production/index.ts +1 -0
  140. package/src/devtools-panel/stub.ts +7 -0
  141. package/src/devtools-panel/types.ts +57 -0
  142. package/src/index.ts +60 -0
  143. package/src/infinite-query-options.ts +354 -0
  144. package/src/inject-infinite-query.ts +296 -0
  145. package/src/inject-is-fetching.ts +97 -0
  146. package/src/inject-is-mutating.ts +80 -0
  147. package/src/inject-is-restoring.ts +53 -0
  148. package/src/inject-mutation-state.ts +167 -0
  149. package/src/inject-mutation.ts +328 -0
  150. package/src/inject-queries-experimental/index.ts +1 -0
  151. package/src/inject-queries.ts +479 -0
  152. package/src/inject-query-client.ts +22 -0
  153. package/src/inject-query.ts +208 -0
  154. package/src/mutation-options.ts +121 -0
  155. package/src/pending-tasks-compat.ts +27 -0
  156. package/src/providers.ts +170 -0
  157. package/src/query-options.ts +292 -0
  158. package/src/signal-proxy.ts +46 -0
  159. package/src/types.ts +429 -0
  160. package/create-base-query.d.ts +0 -164
  161. package/create-base-query.mjs +0 -99
  162. package/create-base-query.mjs.map +0 -1
  163. package/devtools/index.d.ts +0 -2
  164. package/devtools/index.mjs +0 -5
  165. package/devtools/index.mjs.map +0 -1
  166. package/devtools/production/index.d.ts +0 -1
  167. package/devtools/stub.d.ts +0 -2
  168. package/devtools/stub.mjs +0 -8
  169. package/devtools/stub.mjs.map +0 -1
  170. package/devtools/types.d.ts +0 -100
  171. package/devtools/with-devtools.mjs +0 -106
  172. package/devtools/with-devtools.mjs.map +0 -1
  173. package/devtools-panel/index.d.ts +0 -2
  174. package/devtools-panel/index.mjs +0 -5
  175. package/devtools-panel/index.mjs.map +0 -1
  176. package/devtools-panel/inject-devtools-panel.mjs +0 -72
  177. package/devtools-panel/inject-devtools-panel.mjs.map +0 -1
  178. package/devtools-panel/production/index.d.ts +0 -1
  179. package/devtools-panel/stub.d.ts +0 -2
  180. package/devtools-panel/stub.mjs +0 -8
  181. package/devtools-panel/stub.mjs.map +0 -1
  182. package/devtools-panel/types.d.ts +0 -48
  183. package/index.d.ts +0 -25
  184. package/index.mjs.map +0 -1
  185. package/infinite-query-options.mjs +0 -7
  186. package/infinite-query-options.mjs.map +0 -1
  187. package/inject-infinite-query.mjs +0 -18
  188. package/inject-infinite-query.mjs.map +0 -1
  189. package/inject-is-fetching.mjs +0 -31
  190. package/inject-is-fetching.mjs.map +0 -1
  191. package/inject-is-mutating.mjs +0 -31
  192. package/inject-is-mutating.mjs.map +0 -1
  193. package/inject-is-restoring.mjs +0 -21
  194. package/inject-is-restoring.mjs.map +0 -1
  195. package/inject-mutation-state.mjs +0 -51
  196. package/inject-mutation-state.mjs.map +0 -1
  197. package/inject-mutation.mjs +0 -94
  198. package/inject-mutation.mjs.map +0 -1
  199. package/inject-queries-experimental/index.d.ts +0 -1
  200. package/inject-queries-experimental/index.mjs +0 -5
  201. package/inject-queries-experimental/index.mjs.map +0 -1
  202. package/inject-queries.mjs +0 -82
  203. package/inject-queries.mjs.map +0 -1
  204. package/inject-query-client.mjs +0 -9
  205. package/inject-query-client.mjs.map +0 -1
  206. package/inject-query.mjs +0 -14
  207. package/inject-query.mjs.map +0 -1
  208. package/mutation-options.mjs +0 -7
  209. package/mutation-options.mjs.map +0 -1
  210. package/pending-tasks-compat.d.ts +0 -7
  211. package/pending-tasks-compat.mjs +0 -19
  212. package/pending-tasks-compat.mjs.map +0 -1
  213. package/providers.mjs +0 -32
  214. package/providers.mjs.map +0 -1
  215. package/query-options.mjs +0 -7
  216. package/query-options.mjs.map +0 -1
  217. package/signal-proxy.d.ts +0 -11
  218. package/signal-proxy.mjs +0 -29
  219. package/signal-proxy.mjs.map +0 -1
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mutation-options.mjs","names":[],"sources":["../src/mutation-options.ts"],"sourcesContent":["import type { DefaultError, WithRequired } from '@tanstack/query-core'\nimport type { CreateMutationOptions } from './types'\n\n/**\n * You can generally pass everything to `mutationOptions` that you can also pass to `injectMutation`. A\n * `mutationKey` is required on this overload so the mutation can be looked up later, e.g. with\n * `injectMutationState`.\n *\n * @see {@link injectMutation} to run the mutation these options describe.\n * @param options - The mutation options to use, identical to what you'd pass to `injectMutation`, with a\n * required `mutationKey`.\n * @returns The same options object, unchanged.\n *\n * @example\n * Looking the mutation up elsewhere via its `mutationKey`, e.g. for a global \"saving…\" indicator:\n * ```angular-ts\n * import { mutationOptions, injectMutationState } from '@tanstack/angular-query-experimental'\n *\n * const createPostOptions = mutationOptions({\n * mutationKey: ['posts', 'create'],\n * mutationFn: createPost,\n * })\n *\n * @Component({\n * selector: 'saving-indicator',\n * template: `\n * @if (isCreatingPost()) {\n * <span>Saving…</span>\n * }\n * `,\n * })\n * export class SavingIndicator {\n * readonly #pendingCreates = injectMutationState(() => ({\n * filters: { mutationKey: createPostOptions.mutationKey, status: 'pending' },\n * }))\n * readonly isCreatingPost = computed(() => this.#pendingCreates().length > 0)\n * }\n * ```\n */\nexport function mutationOptions<\n TData = unknown,\n TError = DefaultError,\n TVariables = void,\n TOnMutateResult = unknown,\n>(\n options: WithRequired<\n CreateMutationOptions<TData, TError, TVariables, TOnMutateResult>,\n 'mutationKey'\n >,\n): WithRequired<\n CreateMutationOptions<TData, TError, TVariables, TOnMutateResult>,\n 'mutationKey'\n>\n/**\n * You can generally pass everything to `mutationOptions` that you can also pass to `injectMutation`. No\n * `mutationKey` is required on this overload — use this when you don't need to target the mutation via a\n * `mutationKey` filter later (e.g. with `injectMutationState`); it can still be observed through other\n * filters, such as `status`.\n *\n * @see {@link injectMutation} to run the mutation these options describe.\n * @param options - The mutation options to use, identical to what you'd pass to `injectMutation`, without a\n * `mutationKey`.\n * @returns The same options object, unchanged.\n * @remarks See the other overload's example for looking a mutation up via `injectMutationState`.\n *\n * @example\n * Sharing options across services, so `QueriesService` stays the single place a mutation is defined:\n * ```angular-ts\n * import { mutationOptions, injectMutation } from '@tanstack/angular-query-experimental'\n *\n * @Injectable({ providedIn: 'root' })\n * export class QueriesService {\n * readonly #queryClient = inject(QueryClient)\n *\n * updatePost(id: number) {\n * return mutationOptions({\n * mutationFn: (post: Partial<Post>) => putPost(id, post),\n * onSuccess: (newPost) => this.#queryClient.setQueryData(['posts', id], newPost),\n * })\n * }\n * }\n *\n * @Component({\n * selector: 'post',\n * template: `<button (click)=\"save()\">Save</button>`,\n * })\n * export class Post {\n * readonly queries = inject(QueriesService)\n * readonly id = signal(0)\n * readonly updatePostMutation = injectMutation(() => this.queries.updatePost(this.id()))\n *\n * save() {\n * this.updatePostMutation.mutate({ title: 'New Title' })\n * }\n * }\n * ```\n */\nexport function mutationOptions<\n TData = unknown,\n TError = DefaultError,\n TVariables = void,\n TOnMutateResult = unknown,\n>(\n options: Omit<\n CreateMutationOptions<TData, TError, TVariables, TOnMutateResult>,\n 'mutationKey'\n >,\n): Omit<\n CreateMutationOptions<TData, TError, TVariables, TOnMutateResult>,\n 'mutationKey'\n>\nexport function mutationOptions<\n TData = unknown,\n TError = DefaultError,\n TVariables = void,\n TOnMutateResult = unknown,\n>(\n options: CreateMutationOptions<TData, TError, TVariables, TOnMutateResult>,\n): CreateMutationOptions<TData, TError, TVariables, TOnMutateResult> {\n return options\n}\n"],"mappings":";AA+GA,SAAgB,gBAMd,SACmE;CACnE,OAAO;AACT"}
@@ -0,0 +1,10 @@
1
+ import { InjectionToken } from "@angular/core";
2
+ //#region src/pending-tasks-compat.d.ts
3
+ type PendingTasksCompat = {
4
+ add: () => PendingTaskRef;
5
+ };
6
+ type PendingTaskRef = () => void;
7
+ declare const PENDING_TASKS: InjectionToken<PendingTasksCompat>;
8
+ //#endregion
9
+ export { PENDING_TASKS, PendingTaskRef };
10
+ //# sourceMappingURL=pending-tasks-compat.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pending-tasks-compat.d.mts","names":[],"sources":["../src/pending-tasks-compat.ts"],"mappings":";;KAIK;EAAuB,WAAW;;KAE3B;cAEC,eAAa,eAAA"}
@@ -0,0 +1,13 @@
1
+ import * as ng from "@angular/core";
2
+ import { InjectionToken, inject } from "@angular/core";
3
+ import { noop } from "@tanstack/query-core";
4
+ //#region src/pending-tasks-compat.ts
5
+ const PENDING_TASKS = new InjectionToken("PENDING_TASKS", { factory: () => {
6
+ const token = Reflect.get(ng, "PendingTasks");
7
+ const svc = token ? inject(token, { optional: true }) : null;
8
+ return { add: svc ? () => svc.add() : () => noop };
9
+ } });
10
+ //#endregion
11
+ export { PENDING_TASKS };
12
+
13
+ //# sourceMappingURL=pending-tasks-compat.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pending-tasks-compat.mjs","names":[],"sources":["../src/pending-tasks-compat.ts"],"sourcesContent":["import { InjectionToken, inject } from '@angular/core'\nimport * as ng from '@angular/core'\nimport { noop } from '@tanstack/query-core'\n\ntype PendingTasksCompat = { add: () => PendingTaskRef }\n\nexport type PendingTaskRef = () => void\n\nexport const PENDING_TASKS = new InjectionToken<PendingTasksCompat>(\n 'PENDING_TASKS',\n {\n factory: (): PendingTasksCompat => {\n // Access via Reflect so bundlers stay quiet when the token is absent (Angular < 19).\n const token = Reflect.get(ng, 'PendingTasks') as unknown as\n Parameters<typeof inject>[0] | undefined\n\n const svc: PendingTasksCompat | null = token\n ? (inject(token, { optional: true }) as PendingTasksCompat | null)\n : null\n\n // Without PendingTasks we fall back to a stable no-op shim.\n return {\n add: svc ? () => svc.add() : () => noop,\n }\n },\n },\n)\n"],"mappings":";;;;AAQA,MAAa,gBAAgB,IAAI,eAC/B,iBACA,EACE,eAAmC;CAEjC,MAAM,QAAQ,QAAQ,IAAI,IAAI,cAAc;CAG5C,MAAM,MAAiC,QAClC,OAAO,OAAO,EAAE,UAAU,KAAK,CAAC,IACjC;CAGJ,OAAO,EACL,KAAK,YAAY,IAAI,IAAI,UAAU,KACrC;AACF,EACF,CACF"}
@@ -1,5 +1,6 @@
1
- import { InjectionToken, Provider } from '@angular/core';
2
- import { QueryClient } from '@tanstack/query-core';
1
+ import { InjectionToken, Provider } from "@angular/core";
2
+ import { QueryClient } from "@tanstack/query-core";
3
+ //#region src/providers.d.ts
3
4
  /**
4
5
  * Usually {@link provideTanStackQuery} is used once to set up TanStack Query and the
5
6
  * [`QueryClient`](https://tanstack.com/query/latest/docs/reference/QueryClient) for the entire application —
@@ -17,7 +18,7 @@ import { QueryClient } from '@tanstack/query-core';
17
18
  * })
18
19
  * ```
19
20
  */
20
- export declare function provideQueryClient(queryClient: QueryClient | InjectionToken<QueryClient>): Provider;
21
+ declare function provideQueryClient(queryClient: QueryClient | InjectionToken<QueryClient>): Provider;
21
22
  /**
22
23
  * Sets up providers necessary to enable TanStack Query functionality for Angular applications. Allows
23
24
  * configuring a `QueryClient` and optional features such as developer tools.
@@ -80,7 +81,7 @@ export declare function provideQueryClient(queryClient: QueryClient | InjectionT
80
81
  * providers: [provideTanStackQuery(MY_QUERY_CLIENT)]
81
82
  * ```
82
83
  */
83
- export declare function provideTanStackQuery(queryClient: QueryClient | InjectionToken<QueryClient>, ...features: Array<QueryFeatures>): Array<Provider>;
84
+ declare function provideTanStackQuery(queryClient: QueryClient | InjectionToken<QueryClient>, ...features: Array<QueryFeatures>): Array<Provider>;
84
85
  /**
85
86
  * Sets up providers necessary to enable TanStack Query functionality for Angular applications.
86
87
  *
@@ -90,15 +91,15 @@ export declare function provideTanStackQuery(queryClient: QueryClient | Injectio
90
91
  * @returns A set of providers to set up TanStack Query.
91
92
  * @deprecated Use `provideTanStackQuery` instead.
92
93
  */
93
- export declare function provideAngularQuery(queryClient: QueryClient): Array<Provider>;
94
+ declare function provideAngularQuery(queryClient: QueryClient): Array<Provider>;
94
95
  declare const queryFeatures: readonly ["Devtools", "PersistQueryClient"];
95
96
  type QueryFeatureKind = (typeof queryFeatures)[number];
96
97
  /**
97
98
  * Helper type to represent a Query feature.
98
99
  */
99
- export interface QueryFeature<TFeatureKind extends QueryFeatureKind> {
100
- ɵkind: TFeatureKind;
101
- ɵproviders: Array<Provider>;
100
+ interface QueryFeature<TFeatureKind extends QueryFeatureKind> {
101
+ ɵkind: TFeatureKind;
102
+ ɵproviders: Array<Provider>;
102
103
  }
103
104
  /**
104
105
  * Helper function to create an object that represents a Query feature.
@@ -106,18 +107,18 @@ export interface QueryFeature<TFeatureKind extends QueryFeatureKind> {
106
107
  * @param providers - The Angular providers this feature contributes to `provideTanStackQuery`.
107
108
  * @returns A Query feature.
108
109
  */
109
- export declare function queryFeature<TFeatureKind extends QueryFeatureKind>(kind: TFeatureKind, providers: Array<Provider>): QueryFeature<TFeatureKind>;
110
+ declare function queryFeature<TFeatureKind extends QueryFeatureKind>(kind: TFeatureKind, providers: Array<Provider>): QueryFeature<TFeatureKind>;
110
111
  /**
111
112
  * A type alias that represents a feature which enables developer tools.
112
113
  * The type is used to describe the return value of the `withDevtools` function.
113
114
  * @see {@link withDevtools}
114
115
  */
115
- export type DevtoolsFeature = QueryFeature<'Devtools'>;
116
+ type DevtoolsFeature = QueryFeature<'Devtools'>;
116
117
  /**
117
118
  * A type alias that represents a feature which enables persistence.
118
119
  * The type is used to describe the return value of the `withPersistQueryClient` function.
119
120
  */
120
- export type PersistQueryClientFeature = QueryFeature<'PersistQueryClient'>;
121
+ type PersistQueryClientFeature = QueryFeature<'PersistQueryClient'>;
121
122
  /**
122
123
  * A type alias that represents all Query features available for use with `provideTanStackQuery`.
123
124
  * Features can be enabled by adding special functions to the `provideTanStackQuery` call.
@@ -125,5 +126,7 @@ export type PersistQueryClientFeature = QueryFeature<'PersistQueryClient'>;
125
126
  * documentation on how to use those functions.
126
127
  * @see {@link provideTanStackQuery}
127
128
  */
128
- export type QueryFeatures = DevtoolsFeature | PersistQueryClientFeature;
129
- export {};
129
+ type QueryFeatures = DevtoolsFeature | PersistQueryClientFeature;
130
+ //#endregion
131
+ export { DevtoolsFeature, PersistQueryClientFeature, QueryFeature, QueryFeatures, provideAngularQuery, provideQueryClient, provideTanStackQuery, queryFeature };
132
+ //# sourceMappingURL=providers.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"providers.d.mts","names":[],"sources":["../src/providers.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;iBAqBgB,mBACd,aAAa,cAAc,eAAe,eACzC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA8Ea,qBACd,aAAa,cAAc,eAAe,iBACvC,UAAU,MAAM,iBAClB,MAAM;;;;;;;;;;iBAgBO,oBAAoB,aAAa,cAAc,MAAM;cAI/D;KAED,2BAA2B;;;;UAKf,aAAa,qBAAqB;EACjD,OAAO;EACP,YAAY,MAAM;;;;;;;;iBASJ,aAAa,qBAAqB,kBAChD,MAAM,cACN,WAAW,MAAM,YAChB,aAAa;;;;;;KASJ,kBAAkB;;;;;KAMlB,4BAA4B;;;;;;;;KAS5B,gBAAgB,kBAAkB"}
@@ -0,0 +1,124 @@
1
+ import { DestroyRef, InjectionToken, inject } from "@angular/core";
2
+ import { QueryClient } from "@tanstack/query-core";
3
+ //#region src/providers.ts
4
+ /**
5
+ * Usually {@link provideTanStackQuery} is used once to set up TanStack Query and the
6
+ * [`QueryClient`](https://tanstack.com/query/latest/docs/reference/QueryClient) for the entire application —
7
+ * it calls `provideQueryClient` internally. Use `provideQueryClient` directly to provide a different
8
+ * `QueryClient` instance for part of the application, or for unit testing.
9
+ * @param queryClient - A `QueryClient` instance, or an `InjectionToken` which provides a `QueryClient`.
10
+ * @returns A provider object that can be used to provide the `QueryClient` instance.
11
+ *
12
+ * @example
13
+ * Providing a test-only `QueryClient` in a component test, without wiring up `provideTanStackQuery`'s other
14
+ * defaults:
15
+ * ```ts
16
+ * TestBed.configureTestingModule({
17
+ * providers: [provideQueryClient(new QueryClient())],
18
+ * })
19
+ * ```
20
+ */
21
+ function provideQueryClient(queryClient) {
22
+ return {
23
+ provide: QueryClient,
24
+ useFactory: () => {
25
+ const client = queryClient instanceof InjectionToken ? inject(queryClient) : queryClient;
26
+ inject(DestroyRef).onDestroy(() => client.unmount());
27
+ client.mount();
28
+ return client;
29
+ }
30
+ };
31
+ }
32
+ /**
33
+ * Sets up providers necessary to enable TanStack Query functionality for Angular applications. Allows
34
+ * configuring a `QueryClient` and optional features such as developer tools.
35
+ *
36
+ * @see https://tanstack.com/query/v5/docs/framework/angular/quick-start
37
+ * @see {@link withDevtools}
38
+ * @param queryClient - A `QueryClient` instance, or an `InjectionToken` which provides a `QueryClient`.
39
+ * @param features - Optional features to configure additional Query functionality.
40
+ * @returns A set of providers to set up TanStack Query.
41
+ *
42
+ * @example
43
+ * ```ts
44
+ * import { provideTanStackQuery, QueryClient } from '@tanstack/angular-query-experimental'
45
+ *
46
+ * bootstrapApplication(AppComponent, {
47
+ * providers: [provideTanStackQuery(new QueryClient())],
48
+ * })
49
+ * ```
50
+ *
51
+ * @example
52
+ * The same, in an `NgModule`-based application:
53
+ * ```ts
54
+ * import { provideTanStackQuery, QueryClient } from '@tanstack/angular-query-experimental'
55
+ *
56
+ * @NgModule({
57
+ * declarations: [AppComponent],
58
+ * imports: [BrowserModule],
59
+ * providers: [provideTanStackQuery(new QueryClient())],
60
+ * bootstrap: [AppComponent],
61
+ * })
62
+ * export class AppModule {}
63
+ * ```
64
+ *
65
+ * @example
66
+ * Enabling optional developer tools by adding `withDevtools` — by default, the tools are then loaded when
67
+ * your app is in development mode:
68
+ * ```ts
69
+ * import {
70
+ * provideTanStackQuery,
71
+ * withDevtools,
72
+ * QueryClient,
73
+ * } from '@tanstack/angular-query-experimental'
74
+ *
75
+ * bootstrapApplication(AppComponent, {
76
+ * providers: [provideTanStackQuery(new QueryClient(), withDevtools())],
77
+ * })
78
+ * ```
79
+ *
80
+ * @example
81
+ * Using an `InjectionToken` for the `QueryClient` — an advanced optimization that lets TanStack Query be
82
+ * absent from the main application bundle, useful for including it on lazy-loaded routes only while still
83
+ * sharing a `QueryClient`. This is a small optimization; for most applications it's preferable to provide
84
+ * the `QueryClient` in the main application config, as in the examples above:
85
+ * ```ts
86
+ * export const MY_QUERY_CLIENT = new InjectionToken('', {
87
+ * factory: () => new QueryClient(),
88
+ * })
89
+ *
90
+ * // In a lazy loaded route or lazy loaded component's providers array:
91
+ * providers: [provideTanStackQuery(MY_QUERY_CLIENT)]
92
+ * ```
93
+ */
94
+ function provideTanStackQuery(queryClient, ...features) {
95
+ return [provideQueryClient(queryClient), features.map((feature) => feature.ɵproviders)];
96
+ }
97
+ /**
98
+ * Sets up providers necessary to enable TanStack Query functionality for Angular applications.
99
+ *
100
+ * Allows configuring a `QueryClient`.
101
+ * @see https://tanstack.com/query/v5/docs/framework/angular/quick-start
102
+ * @param queryClient - A `QueryClient` instance.
103
+ * @returns A set of providers to set up TanStack Query.
104
+ * @deprecated Use `provideTanStackQuery` instead.
105
+ */
106
+ function provideAngularQuery(queryClient) {
107
+ return provideTanStackQuery(queryClient);
108
+ }
109
+ /**
110
+ * Helper function to create an object that represents a Query feature.
111
+ * @param kind - The kind of feature, e.g. `'Devtools'`.
112
+ * @param providers - The Angular providers this feature contributes to `provideTanStackQuery`.
113
+ * @returns A Query feature.
114
+ */
115
+ function queryFeature(kind, providers) {
116
+ return {
117
+ ɵkind: kind,
118
+ ɵproviders: providers
119
+ };
120
+ }
121
+ //#endregion
122
+ export { provideAngularQuery, provideQueryClient, provideTanStackQuery, queryFeature };
123
+
124
+ //# sourceMappingURL=providers.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"providers.mjs","names":[],"sources":["../src/providers.ts"],"sourcesContent":["import { DestroyRef, InjectionToken, inject } from '@angular/core'\nimport { QueryClient } from '@tanstack/query-core'\nimport type { Provider } from '@angular/core'\n\n/**\n * Usually {@link provideTanStackQuery} is used once to set up TanStack Query and the\n * [`QueryClient`](https://tanstack.com/query/latest/docs/reference/QueryClient) for the entire application —\n * it calls `provideQueryClient` internally. Use `provideQueryClient` directly to provide a different\n * `QueryClient` instance for part of the application, or for unit testing.\n * @param queryClient - A `QueryClient` instance, or an `InjectionToken` which provides a `QueryClient`.\n * @returns A provider object that can be used to provide the `QueryClient` instance.\n *\n * @example\n * Providing a test-only `QueryClient` in a component test, without wiring up `provideTanStackQuery`'s other\n * defaults:\n * ```ts\n * TestBed.configureTestingModule({\n * providers: [provideQueryClient(new QueryClient())],\n * })\n * ```\n */\nexport function provideQueryClient(\n queryClient: QueryClient | InjectionToken<QueryClient>,\n): Provider {\n return {\n provide: QueryClient,\n useFactory: () => {\n const client =\n queryClient instanceof InjectionToken\n ? inject(queryClient)\n : queryClient\n // Unmount the query client on injector destroy\n inject(DestroyRef).onDestroy(() => client.unmount())\n client.mount()\n return client\n },\n }\n}\n\n/**\n * Sets up providers necessary to enable TanStack Query functionality for Angular applications. Allows\n * configuring a `QueryClient` and optional features such as developer tools.\n *\n * @see https://tanstack.com/query/v5/docs/framework/angular/quick-start\n * @see {@link withDevtools}\n * @param queryClient - A `QueryClient` instance, or an `InjectionToken` which provides a `QueryClient`.\n * @param features - Optional features to configure additional Query functionality.\n * @returns A set of providers to set up TanStack Query.\n *\n * @example\n * ```ts\n * import { provideTanStackQuery, QueryClient } from '@tanstack/angular-query-experimental'\n *\n * bootstrapApplication(AppComponent, {\n * providers: [provideTanStackQuery(new QueryClient())],\n * })\n * ```\n *\n * @example\n * The same, in an `NgModule`-based application:\n * ```ts\n * import { provideTanStackQuery, QueryClient } from '@tanstack/angular-query-experimental'\n *\n * @NgModule({\n * declarations: [AppComponent],\n * imports: [BrowserModule],\n * providers: [provideTanStackQuery(new QueryClient())],\n * bootstrap: [AppComponent],\n * })\n * export class AppModule {}\n * ```\n *\n * @example\n * Enabling optional developer tools by adding `withDevtools` — by default, the tools are then loaded when\n * your app is in development mode:\n * ```ts\n * import {\n * provideTanStackQuery,\n * withDevtools,\n * QueryClient,\n * } from '@tanstack/angular-query-experimental'\n *\n * bootstrapApplication(AppComponent, {\n * providers: [provideTanStackQuery(new QueryClient(), withDevtools())],\n * })\n * ```\n *\n * @example\n * Using an `InjectionToken` for the `QueryClient` — an advanced optimization that lets TanStack Query be\n * absent from the main application bundle, useful for including it on lazy-loaded routes only while still\n * sharing a `QueryClient`. This is a small optimization; for most applications it's preferable to provide\n * the `QueryClient` in the main application config, as in the examples above:\n * ```ts\n * export const MY_QUERY_CLIENT = new InjectionToken('', {\n * factory: () => new QueryClient(),\n * })\n *\n * // In a lazy loaded route or lazy loaded component's providers array:\n * providers: [provideTanStackQuery(MY_QUERY_CLIENT)]\n * ```\n */\nexport function provideTanStackQuery(\n queryClient: QueryClient | InjectionToken<QueryClient>,\n ...features: Array<QueryFeatures>\n): Array<Provider> {\n return [\n provideQueryClient(queryClient),\n features.map((feature) => feature.ɵproviders),\n ]\n}\n\n/**\n * Sets up providers necessary to enable TanStack Query functionality for Angular applications.\n *\n * Allows configuring a `QueryClient`.\n * @see https://tanstack.com/query/v5/docs/framework/angular/quick-start\n * @param queryClient - A `QueryClient` instance.\n * @returns A set of providers to set up TanStack Query.\n * @deprecated Use `provideTanStackQuery` instead.\n */\nexport function provideAngularQuery(queryClient: QueryClient): Array<Provider> {\n return provideTanStackQuery(queryClient)\n}\n\nconst queryFeatures = ['Devtools', 'PersistQueryClient'] as const\n\ntype QueryFeatureKind = (typeof queryFeatures)[number]\n\n/**\n * Helper type to represent a Query feature.\n */\nexport interface QueryFeature<TFeatureKind extends QueryFeatureKind> {\n ɵkind: TFeatureKind\n ɵproviders: Array<Provider>\n}\n\n/**\n * Helper function to create an object that represents a Query feature.\n * @param kind - The kind of feature, e.g. `'Devtools'`.\n * @param providers - The Angular providers this feature contributes to `provideTanStackQuery`.\n * @returns A Query feature.\n */\nexport function queryFeature<TFeatureKind extends QueryFeatureKind>(\n kind: TFeatureKind,\n providers: Array<Provider>,\n): QueryFeature<TFeatureKind> {\n return { ɵkind: kind, ɵproviders: providers }\n}\n\n/**\n * A type alias that represents a feature which enables developer tools.\n * The type is used to describe the return value of the `withDevtools` function.\n * @see {@link withDevtools}\n */\nexport type DevtoolsFeature = QueryFeature<'Devtools'>\n\n/**\n * A type alias that represents a feature which enables persistence.\n * The type is used to describe the return value of the `withPersistQueryClient` function.\n */\nexport type PersistQueryClientFeature = QueryFeature<'PersistQueryClient'>\n\n/**\n * A type alias that represents all Query features available for use with `provideTanStackQuery`.\n * Features can be enabled by adding special functions to the `provideTanStackQuery` call.\n * See documentation for each symbol to find corresponding function name. See also `provideTanStackQuery`\n * documentation on how to use those functions.\n * @see {@link provideTanStackQuery}\n */\nexport type QueryFeatures = DevtoolsFeature | PersistQueryClientFeature\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAqBA,SAAgB,mBACd,aACU;CACV,OAAO;EACL,SAAS;EACT,kBAAkB;GAChB,MAAM,SACJ,uBAAuB,iBACnB,OAAO,WAAW,IAClB;GAEN,OAAO,UAAU,CAAC,CAAC,gBAAgB,OAAO,QAAQ,CAAC;GACnD,OAAO,MAAM;GACb,OAAO;EACT;CACF;AACF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgEA,SAAgB,qBACd,aACA,GAAG,UACc;CACjB,OAAO,CACL,mBAAmB,WAAW,GAC9B,SAAS,KAAK,YAAY,QAAQ,UAAU,CAC9C;AACF;;;;;;;;;;AAWA,SAAgB,oBAAoB,aAA2C;CAC7E,OAAO,qBAAqB,WAAW;AACzC;;;;;;;AAoBA,SAAgB,aACd,MACA,WAC4B;CAC5B,OAAO;EAAE,OAAO;EAAM,YAAY;CAAU;AAC9C"}
@@ -1,5 +1,6 @@
1
- import { DefaultError, InitialDataFunction, NonUndefinedGuard, OmitKeyof, QueryFunction, QueryKey, QueryKeyWithDataTag, SkipToken } from '@tanstack/query-core';
2
- import { CreateQueryOptions } from './types.js';
1
+ import { CreateQueryOptions } from "./types.mjs";
2
+ import { DefaultError, InitialDataFunction, NonUndefinedGuard, OmitKeyof, QueryFunction, QueryKey, QueryKeyWithDataTag, SkipToken } from "@tanstack/query-core";
3
+ //#region src/query-options.d.ts
3
4
  /**
4
5
  * The options accepted by the `queryOptions` overload selected when no `initialData` is set — `data` may be
5
6
  * `undefined` while the query is `pending`.
@@ -9,15 +10,15 @@ import { CreateQueryOptions } from './types.js';
9
10
  * @template TData - The type `data` ends up as after `select` runs.
10
11
  * @template TQueryKey - The type of your `queryKey`.
11
12
  */
12
- export type UndefinedInitialDataOptions<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey> = CreateQueryOptions<TQueryFnData, TError, TData, TQueryKey> & {
13
- /**
14
- * If set, this value will be used as the initial data for the query cache (as long as the query hasn't been
15
- * created or cached yet). If set to a function, the function will be called **once** during the shared/root
16
- * query initialization, and be expected to synchronously return the initial data. Initial data is
17
- * considered stale by default unless a `staleTime` has been set. `initialData` **is persisted** to the
18
- * cache.
19
- */
20
- initialData?: undefined | InitialDataFunction<NonUndefinedGuard<TQueryFnData>> | NonUndefinedGuard<TQueryFnData>;
13
+ type UndefinedInitialDataOptions<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey> = CreateQueryOptions<TQueryFnData, TError, TData, TQueryKey> & {
14
+ /**
15
+ * If set, this value will be used as the initial data for the query cache (as long as the query hasn't been
16
+ * created or cached yet). If set to a function, the function will be called **once** during the shared/root
17
+ * query initialization, and be expected to synchronously return the initial data. Initial data is
18
+ * considered stale by default unless a `staleTime` has been set. `initialData` **is persisted** to the
19
+ * cache.
20
+ */
21
+ initialData?: undefined | InitialDataFunction<NonUndefinedGuard<TQueryFnData>> | NonUndefinedGuard<TQueryFnData>;
21
22
  };
22
23
  /**
23
24
  * The options accepted by the `queryOptions` overload selected when no `initialData` is set and `queryFn` is
@@ -28,14 +29,14 @@ export type UndefinedInitialDataOptions<TQueryFnData = unknown, TError = Default
28
29
  * @template TData - The type `data` ends up as after `select` runs.
29
30
  * @template TQueryKey - The type of your `queryKey`.
30
31
  */
31
- export type UnusedSkipTokenOptions<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey> = OmitKeyof<CreateQueryOptions<TQueryFnData, TError, TData, TQueryKey>, 'queryFn'> & {
32
- /**
33
- * `skipToken` is not allowed as a value here — this overload is selected when no `initialData` is set. If
34
- * you don't intend to run the query yet, set `enabled: false` — omitting `queryFn` alone still triggers a
35
- * fetch that fails with "Missing queryFn" unless `enabled` is `false` or a default query function has been
36
- * defined. A default query function only supplies `queryFn`; it doesn't defer the fetch on its own.
37
- */
38
- queryFn?: Exclude<CreateQueryOptions<TQueryFnData, TError, TData, TQueryKey>['queryFn'], SkipToken | undefined>;
32
+ type UnusedSkipTokenOptions<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey> = OmitKeyof<CreateQueryOptions<TQueryFnData, TError, TData, TQueryKey>, 'queryFn'> & {
33
+ /**
34
+ * `skipToken` is not allowed as a value here — this overload is selected when no `initialData` is set. If
35
+ * you don't intend to run the query yet, set `enabled: false` — omitting `queryFn` alone still triggers a
36
+ * fetch that fails with "Missing queryFn" unless `enabled` is `false` or a default query function has been
37
+ * defined. A default query function only supplies `queryFn`; it doesn't defer the fetch on its own.
38
+ */
39
+ queryFn?: Exclude<CreateQueryOptions<TQueryFnData, TError, TData, TQueryKey>['queryFn'], SkipToken | undefined>;
39
40
  };
40
41
  /**
41
42
  * The options accepted by the `queryOptions` overload selected when `initialData` is set — `data` is never
@@ -46,21 +47,21 @@ export type UnusedSkipTokenOptions<TQueryFnData = unknown, TError = DefaultError
46
47
  * @template TData - The type `data` ends up as after `select` runs.
47
48
  * @template TQueryKey - The type of your `queryKey`.
48
49
  */
49
- export type DefinedInitialDataOptions<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey> = Omit<CreateQueryOptions<TQueryFnData, TError, TData, TQueryKey>, 'queryFn'> & {
50
- /**
51
- * If set, this value will be used as the initial data for the query cache (as long as the query hasn't been
52
- * created or cached yet). If set to a function, the function will be called **once** during the shared/root
53
- * query initialization, and be expected to synchronously return the initial data. Initial data is
54
- * considered stale by default unless a `staleTime` has been set. `initialData` **is persisted** to the
55
- * cache.
56
- */
57
- initialData: NonUndefinedGuard<TQueryFnData> | (() => NonUndefinedGuard<TQueryFnData>);
58
- /**
59
- * Optional here, but omitting it is only safe when no fetch will be attempted — for example with
60
- * `enabled: false`, or when a default query function has been defined. Otherwise, an enabled query with no
61
- * `queryFn` still tries to fetch and fails with a "Missing queryFn" error; `initialData` does not prevent this.
62
- */
63
- queryFn?: QueryFunction<TQueryFnData, TQueryKey>;
50
+ type DefinedInitialDataOptions<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey> = Omit<CreateQueryOptions<TQueryFnData, TError, TData, TQueryKey>, 'queryFn'> & {
51
+ /**
52
+ * If set, this value will be used as the initial data for the query cache (as long as the query hasn't been
53
+ * created or cached yet). If set to a function, the function will be called **once** during the shared/root
54
+ * query initialization, and be expected to synchronously return the initial data. Initial data is
55
+ * considered stale by default unless a `staleTime` has been set. `initialData` **is persisted** to the
56
+ * cache.
57
+ */
58
+ initialData: NonUndefinedGuard<TQueryFnData> | (() => NonUndefinedGuard<TQueryFnData>);
59
+ /**
60
+ * Optional here, but omitting it is only safe when no fetch will be attempted — for example with
61
+ * `enabled: false`, or when a default query function has been defined. Otherwise, an enabled query with no
62
+ * `queryFn` still tries to fetch and fails with a "Missing queryFn" error; `initialData` does not prevent this.
63
+ */
64
+ queryFn?: QueryFunction<TQueryFnData, TQueryKey>;
64
65
  };
65
66
  /**
66
67
  * You can generally pass everything to `queryOptions` that you can also pass to `injectQuery`. These options
@@ -106,7 +107,7 @@ export type DefinedInitialDataOptions<TQueryFnData = unknown, TError = DefaultEr
106
107
  * }
107
108
  * ```
108
109
  */
109
- export declare function queryOptions<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey>(options: DefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey>): DefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey> & QueryKeyWithDataTag<TQueryKey, TQueryFnData, TError>;
110
+ declare function queryOptions<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey>(options: DefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey>): DefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey> & QueryKeyWithDataTag<TQueryKey, TQueryFnData, TError>;
110
111
  /**
111
112
  * You can generally pass everything to `queryOptions` that you can also pass to `injectQuery`. These options
112
113
  * can be shared across functions and imperative APIs such as `queryClient.fetchQuery`. `options.queryKey` is
@@ -146,7 +147,7 @@ export declare function queryOptions<TQueryFnData = unknown, TError = DefaultErr
146
147
  * }
147
148
  * ```
148
149
  */
149
- export declare function queryOptions<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey>(options: UnusedSkipTokenOptions<TQueryFnData, TError, TData, TQueryKey>): UnusedSkipTokenOptions<TQueryFnData, TError, TData, TQueryKey> & QueryKeyWithDataTag<TQueryKey, TQueryFnData, TError>;
150
+ declare function queryOptions<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey>(options: UnusedSkipTokenOptions<TQueryFnData, TError, TData, TQueryKey>): UnusedSkipTokenOptions<TQueryFnData, TError, TData, TQueryKey> & QueryKeyWithDataTag<TQueryKey, TQueryFnData, TError>;
150
151
  /**
151
152
  * You can generally pass everything to `queryOptions` that you can also pass to `injectQuery`. These options
152
153
  * can be shared across functions and imperative APIs such as `queryClient.fetchQuery`. `options.queryKey` is
@@ -218,4 +219,7 @@ export declare function queryOptions<TQueryFnData = unknown, TError = DefaultErr
218
219
  * }
219
220
  * ```
220
221
  */
221
- export declare function queryOptions<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey>(options: UndefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey>): UndefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey> & QueryKeyWithDataTag<TQueryKey, TQueryFnData, TError>;
222
+ declare function queryOptions<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey>(options: UndefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey>): UndefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey> & QueryKeyWithDataTag<TQueryKey, TQueryFnData, TError>;
223
+ //#endregion
224
+ export { DefinedInitialDataOptions, UndefinedInitialDataOptions, UnusedSkipTokenOptions, queryOptions };
225
+ //# sourceMappingURL=query-options.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"query-options.d.mts","names":[],"sources":["../src/query-options.ts"],"mappings":";;;;;;;;;;;;KAqBY,4BACV,wBACA,SAAS,cACT,QAAQ,cACR,kBAAkB,WAAW,YAC3B,mBAAmB,cAAc,QAAQ,OAAO;;;;;;;;EAQlD,0BAEI,oBAAoB,kBAAkB,iBACtC,kBAAkB;;;;;;;;;;;KAYZ,uBACV,wBACA,SAAS,cACT,QAAQ,cACR,kBAAkB,WAAW,YAC3B,UACF,mBAAmB,cAAc,QAAQ,OAAO;;;;;;;EAShD,UAAU,QACR,mBAAmB,cAAc,QAAQ,OAAO,uBAChD;;;;;;;;;;;KAaQ,0BACV,wBACA,SAAS,cACT,QAAQ,cACR,kBAAkB,WAAW,YAC3B,KACF,mBAAmB,cAAc,QAAQ,OAAO;;;;;;;;EAUhD,aACE,kBAAkB,uBAAuB,kBAAkB;;;;;;EAM7D,UAAU,cAAc,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA+CxB,aACd,wBACA,SAAS,cACT,QAAQ,cACR,kBAAkB,WAAW,UAE7B,SAAS,0BAA0B,cAAc,QAAQ,OAAO,aAC/D,0BAA0B,cAAc,QAAQ,OAAO,aACxD,oBAAoB,WAAW,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAyC/B,aACd,wBACA,SAAS,cACT,QAAQ,cACR,kBAAkB,WAAW,UAE7B,SAAS,uBAAuB,cAAc,QAAQ,OAAO,aAC5D,uBAAuB,cAAc,QAAQ,OAAO,aACrD,oBAAoB,WAAW,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAyE/B,aACd,wBACA,SAAS,cACT,QAAQ,cACR,kBAAkB,WAAW,UAE7B,SAAS,4BAA4B,cAAc,QAAQ,OAAO,aACjE,4BAA4B,cAAc,QAAQ,OAAO,aAC1D,oBAAoB,WAAW,cAAc"}
@@ -0,0 +1,8 @@
1
+ //#region src/query-options.ts
2
+ function queryOptions(options) {
3
+ return options;
4
+ }
5
+ //#endregion
6
+ export { queryOptions };
7
+
8
+ //# sourceMappingURL=query-options.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"query-options.mjs","names":[],"sources":["../src/query-options.ts"],"sourcesContent":["import type {\n DefaultError,\n InitialDataFunction,\n NonUndefinedGuard,\n OmitKeyof,\n QueryFunction,\n QueryKey,\n QueryKeyWithDataTag,\n SkipToken,\n} from '@tanstack/query-core'\nimport type { CreateQueryOptions } from './types'\n\n/**\n * The options accepted by the `queryOptions` overload selected when no `initialData` is set — `data` may be\n * `undefined` while the query is `pending`.\n *\n * @template TQueryFnData - The type your `queryFn` resolves to.\n * @template TError - The type of errors your `queryFn` may throw.\n * @template TData - The type `data` ends up as after `select` runs.\n * @template TQueryKey - The type of your `queryKey`.\n */\nexport type UndefinedInitialDataOptions<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n> = CreateQueryOptions<TQueryFnData, TError, TData, TQueryKey> & {\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 | InitialDataFunction<NonUndefinedGuard<TQueryFnData>>\n | NonUndefinedGuard<TQueryFnData>\n}\n\n/**\n * The options accepted by the `queryOptions` overload selected when no `initialData` is set and `queryFn` is\n * not `skipToken` — same as {@link UndefinedInitialDataOptions}, but `queryFn` may not be `skipToken`.\n *\n * @template TQueryFnData - The type your `queryFn` resolves to.\n * @template TError - The type of errors your `queryFn` may throw.\n * @template TData - The type `data` ends up as after `select` runs.\n * @template TQueryKey - The type of your `queryKey`.\n */\nexport type UnusedSkipTokenOptions<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n> = OmitKeyof<\n CreateQueryOptions<TQueryFnData, TError, TData, TQueryKey>,\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 CreateQueryOptions<TQueryFnData, TError, TData, TQueryKey>['queryFn'],\n SkipToken | undefined\n >\n}\n\n/**\n * The options accepted by the `queryOptions` overload selected when `initialData` is set — `data` is never\n * `undefined` (unless a `select` changes `TData` to include `undefined`).\n *\n * @template TQueryFnData - The type your `queryFn` resolves to.\n * @template TError - The type of errors your `queryFn` may throw.\n * @template TData - The type `data` ends up as after `select` runs.\n * @template TQueryKey - The type of your `queryKey`.\n */\nexport type DefinedInitialDataOptions<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n> = Omit<\n CreateQueryOptions<TQueryFnData, TError, TData, TQueryKey>,\n 'queryFn'\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<TQueryFnData> | (() => NonUndefinedGuard<TQueryFnData>)\n /**\n * Optional here, but omitting it is only safe when no fetch will be attempted — for example with\n * `enabled: false`, or when a default query function has been defined. Otherwise, an enabled query with no\n * `queryFn` still tries to fetch and fails with a \"Missing queryFn\" error; `initialData` does not prevent this.\n */\n queryFn?: QueryFunction<TQueryFnData, TQueryKey>\n}\n\n/**\n * You can generally pass everything to `queryOptions` that you can also pass to `injectQuery`. These options\n * can be shared across functions and imperative APIs such as `queryClient.fetchQuery`. `options.queryKey` is\n * required and is the query key to generate options for.\n *\n * This overload is selected when `initialData` is set, so the resulting `data` is never `undefined` (unless\n * a `select` changes `TData` to include `undefined`).\n *\n * @see {@link injectQuery} to run a query with these options.\n * @see [The Query Options API](https://tkdodo.eu/blog/the-query-options-api) for more on this pattern.\n * @param options - The {@link DefinedInitialDataOptions} to use — everything you can pass to `injectQuery`,\n * with `initialData` set.\n * @returns The same options object, typed so that `queryKey` carries the inferred data type.\n *\n * @example\n * ```angular-ts\n * import { queryOptions, injectQuery } from '@tanstack/angular-query-experimental'\n *\n * export const postsOptions = queryOptions({\n * queryKey: ['posts'],\n * queryFn: fetchPosts,\n * initialData: [],\n * })\n *\n * @Component({\n * selector: 'posts',\n * template: `\n * <!-- `postsQuery.data()` is never `undefined`, thanks to `initialData` — even if a refetch\n * fails, so the list stays visible alongside the error. -->\n * @if (postsQuery.isError()) {\n * <span>Error: {{ postsQuery.error()?.message }}</span>\n * }\n * <ul>\n * @for (post of postsQuery.data(); track post.id) {\n * <li>{{ post.title }}</li>\n * }\n * </ul>\n * `,\n * })\n * export class Posts {\n * readonly postsQuery = injectQuery(() => postsOptions)\n * }\n * ```\n */\nexport function queryOptions<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n>(\n options: DefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey>,\n): DefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey> &\n QueryKeyWithDataTag<TQueryKey, TQueryFnData, TError>\n\n/**\n * You can generally pass everything to `queryOptions` that you can also pass to `injectQuery`. These options\n * can be shared across functions and imperative APIs such as `queryClient.fetchQuery`. `options.queryKey` is\n * required and is the query key to generate options for.\n *\n * @see {@link injectQuery} to run a query with these options.\n * @see [The Query Options API](https://tkdodo.eu/blog/the-query-options-api) for more on this pattern.\n * @param options - The {@link UnusedSkipTokenOptions} to use — everything you can pass to `injectQuery`.\n * @returns The same options object, typed so that `queryKey` carries the inferred data type.\n *\n * @example\n * A parameterized factory, so the same options object can be reused per `id`:\n * ```angular-ts\n * import { queryOptions, injectQuery } from '@tanstack/angular-query-experimental'\n *\n * export const postOptions = (id: string) =>\n * queryOptions({\n * queryKey: ['post', id],\n * queryFn: () => fetchPost(id),\n * })\n *\n * @Component({\n * selector: 'post',\n * template: `\n * @if (postQuery.isPending()) {\n * Loading...\n * } @else if (postQuery.isError()) {\n * <span>Error: {{ postQuery.error()?.message }}</span>\n * } @else {\n * <h1>{{ postQuery.data().title }}</h1>\n * }\n * `,\n * })\n * export class Post {\n * readonly id = signal('1')\n * readonly postQuery = injectQuery(() => postOptions(this.id()))\n * }\n * ```\n */\nexport function queryOptions<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n>(\n options: UnusedSkipTokenOptions<TQueryFnData, TError, TData, TQueryKey>,\n): UnusedSkipTokenOptions<TQueryFnData, TError, TData, TQueryKey> &\n QueryKeyWithDataTag<TQueryKey, TQueryFnData, TError>\n\n/**\n * You can generally pass everything to `queryOptions` that you can also pass to `injectQuery`. These options\n * can be shared across functions and imperative APIs such as `queryClient.fetchQuery`. `options.queryKey` is\n * required and is the query key to generate options for.\n *\n * @see {@link injectQuery} to run a query with these options.\n * @see [The Query Options API](https://tkdodo.eu/blog/the-query-options-api) for more on this pattern.\n * @param options - The {@link UndefinedInitialDataOptions} to use — everything you can pass to `injectQuery`.\n * @returns The same options object, typed so that `queryKey` carries the inferred data type.\n * @remarks This is the only overload that accepts `queryFn: skipToken`, shown below.\n *\n * @example\n * A parameterized factory, so the same options object can be reused per `id`:\n * ```angular-ts\n * import { queryOptions, injectQuery } from '@tanstack/angular-query-experimental'\n *\n * export const postOptions = (id: string) =>\n * queryOptions({\n * queryKey: ['post', id],\n * queryFn: () => fetchPost(id),\n * })\n *\n * @Component({\n * selector: 'post',\n * template: `\n * @if (postQuery.isPending()) {\n * Loading...\n * } @else if (postQuery.isError()) {\n * <span>Error: {{ postQuery.error()?.message }}</span>\n * } @else {\n * <h1>{{ postQuery.data().title }}</h1>\n * }\n * `,\n * })\n * export class Post {\n * readonly id = signal('1')\n * readonly postQuery = injectQuery(() => postOptions(this.id()))\n * }\n * ```\n *\n * @example\n * A factory that disables the query, type safe, until `postId` is set:\n * ```angular-ts\n * import { queryOptions, skipToken, injectQuery } from '@tanstack/angular-query-experimental'\n *\n * export const postOptions = (postId: number | undefined) =>\n * queryOptions({\n * queryKey: ['post', postId],\n * queryFn: postId != null ? () => fetchPost(postId) : skipToken,\n * })\n *\n * @Component({\n * selector: 'post',\n * template: `\n * @if (postId() == null) {\n * Select a post\n * } @else if (postQuery.isPending()) {\n * Loading...\n * } @else if (postQuery.isError()) {\n * <span>Error: {{ postQuery.error()?.message }}</span>\n * } @else {\n * <h1>{{ postQuery.data().title }}</h1>\n * }\n * `,\n * })\n * export class Post {\n * readonly postId = signal<number | undefined>(undefined)\n * readonly postQuery = injectQuery(() => postOptions(this.postId()))\n * }\n * ```\n */\nexport function queryOptions<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n>(\n options: UndefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey>,\n): UndefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey> &\n QueryKeyWithDataTag<TQueryKey, TQueryFnData, TError>\n\nexport function queryOptions(options: unknown) {\n return options\n}\n"],"mappings":";AAiSA,SAAgB,aAAa,SAAkB;CAC7C,OAAO;AACT"}
@@ -0,0 +1,13 @@
1
+ import { Signal } from "@angular/core";
2
+ //#region src/signal-proxy.d.ts
3
+ type MapToSignals<T> = { [K in keyof T]: T[K] extends Function ? T[K] : Signal<T[K]>; };
4
+ /**
5
+ * Exposes fields of an object passed via an Angular `Signal` as `Computed` signals.
6
+ * Functions on the object are passed through as-is.
7
+ * @param inputSignal - `Signal` that must return an object.
8
+ * @returns A proxy object with the same fields as the input object, but with each field wrapped in a `Computed` signal.
9
+ */
10
+ declare function signalProxy<TInput extends Record<string | symbol, any>>(inputSignal: Signal<TInput>): MapToSignals<TInput>;
11
+ //#endregion
12
+ export { MapToSignals, signalProxy };
13
+ //# sourceMappingURL=signal-proxy.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"signal-proxy.d.mts","names":[],"sources":["../src/signal-proxy.ts"],"mappings":";;KAGY,aAAa,QACtB,WAAW,IAAI,EAAE,WAAW,WAAW,EAAE,KAAK,OAAO,EAAE;;;;;;;iBAS1C,YAAY,eAAe,8BACzC,aAAa,OAAO,UAAO,aAAA"}
@@ -0,0 +1,35 @@
1
+ import { computed, untracked } from "@angular/core";
2
+ //#region src/signal-proxy.ts
3
+ /**
4
+ * Exposes fields of an object passed via an Angular `Signal` as `Computed` signals.
5
+ * Functions on the object are passed through as-is.
6
+ * @param inputSignal - `Signal` that must return an object.
7
+ * @returns A proxy object with the same fields as the input object, but with each field wrapped in a `Computed` signal.
8
+ */
9
+ function signalProxy(inputSignal) {
10
+ return new Proxy({}, {
11
+ get(target, prop) {
12
+ const computedField = target[prop];
13
+ if (computedField) return computedField;
14
+ const targetField = untracked(inputSignal)[prop];
15
+ if (typeof targetField === "function") return targetField;
16
+ return target[prop] = computed(() => inputSignal()[prop]);
17
+ },
18
+ has(_, prop) {
19
+ return !!untracked(inputSignal)[prop];
20
+ },
21
+ ownKeys() {
22
+ return Reflect.ownKeys(untracked(inputSignal));
23
+ },
24
+ getOwnPropertyDescriptor() {
25
+ return {
26
+ enumerable: true,
27
+ configurable: true
28
+ };
29
+ }
30
+ });
31
+ }
32
+ //#endregion
33
+ export { signalProxy };
34
+
35
+ //# sourceMappingURL=signal-proxy.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"signal-proxy.mjs","names":[],"sources":["../src/signal-proxy.ts"],"sourcesContent":["import { computed, untracked } from '@angular/core'\nimport type { Signal } from '@angular/core'\n\nexport type MapToSignals<T> = {\n [K in keyof T]: T[K] extends Function ? T[K] : Signal<T[K]>\n}\n\n/**\n * Exposes fields of an object passed via an Angular `Signal` as `Computed` signals.\n * Functions on the object are passed through as-is.\n * @param inputSignal - `Signal` that must return an object.\n * @returns A proxy object with the same fields as the input object, but with each field wrapped in a `Computed` signal.\n */\nexport function signalProxy<TInput extends Record<string | symbol, any>>(\n inputSignal: Signal<TInput>,\n) {\n const internalState = {} as MapToSignals<TInput>\n\n return new Proxy<MapToSignals<TInput>>(internalState, {\n get(target, prop) {\n // first check if we have it in our internal state and return it\n const computedField = target[prop]\n if (computedField) return computedField\n\n // then, check if it's a function on the resultState and return it\n const targetField = untracked(inputSignal)[prop]\n if (typeof targetField === 'function') return targetField\n\n // finally, create a computed field, store it and return it\n // @ts-expect-error\n return (target[prop] = computed(() => inputSignal()[prop]))\n },\n has(_, prop) {\n return !!untracked(inputSignal)[prop]\n },\n ownKeys() {\n return Reflect.ownKeys(untracked(inputSignal))\n },\n getOwnPropertyDescriptor() {\n return {\n enumerable: true,\n configurable: true,\n }\n },\n })\n}\n"],"mappings":";;;;;;;;AAaA,SAAgB,YACd,aACA;CAGA,OAAO,IAAI,MAA4B,CAAY,GAAG;EACpD,IAAI,QAAQ,MAAM;GAEhB,MAAM,gBAAgB,OAAO;GAC7B,IAAI,eAAe,OAAO;GAG1B,MAAM,cAAc,UAAU,WAAW,CAAC,CAAC;GAC3C,IAAI,OAAO,gBAAgB,YAAY,OAAO;GAI9C,OAAQ,OAAO,QAAQ,eAAe,YAAY,CAAC,CAAC,KAAK;EAC3D;EACA,IAAI,GAAG,MAAM;GACX,OAAO,CAAC,CAAC,UAAU,WAAW,CAAC,CAAC;EAClC;EACA,UAAU;GACR,OAAO,QAAQ,QAAQ,UAAU,WAAW,CAAC;EAC/C;EACA,2BAA2B;GACzB,OAAO;IACL,YAAY;IACZ,cAAc;GAChB;EACF;CACF,CAAC;AACH"}