@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
package/src/types.ts ADDED
@@ -0,0 +1,429 @@
1
+ /* istanbul ignore file */
2
+
3
+ import type {
4
+ DefaultError,
5
+ DefinedInfiniteQueryObserverResult,
6
+ DefinedQueryObserverResult,
7
+ InfiniteQueryObserverOptions,
8
+ InfiniteQueryObserverResult,
9
+ MutateFunction,
10
+ MutationObserverOptions,
11
+ MutationObserverResult,
12
+ OmitKeyof,
13
+ Override,
14
+ QueryKey,
15
+ QueryObserverOptions,
16
+ QueryObserverResult,
17
+ } from '@tanstack/query-core'
18
+ import type { Signal } from '@angular/core'
19
+ import type { MapToSignals } from './signal-proxy'
20
+
21
+ /**
22
+ * The options shared across `angular-query-experimental`'s query functions. Extends
23
+ * {@link QueryObserverOptions} from `@tanstack/query-core` as-is — unlike `react-query`,
24
+ * `angular-query-experimental` has no extra framework-specific option here.
25
+ *
26
+ * @template TQueryFnData - The type your `queryFn` resolves to.
27
+ * @template TError - The type of errors your `queryFn` may throw.
28
+ * @template TData - The type `data` ends up as after `select` runs. Defaults to `TQueryFnData` when no
29
+ * `select` is used.
30
+ * @template TQueryData - The type of the data actually held in the query cache — the input to `select` and
31
+ * `placeholderData`. Defaults to, and is usually the same as, `TQueryFnData`.
32
+ * @template TQueryKey - The type of your `queryKey`.
33
+ */
34
+ export interface CreateBaseQueryOptions<
35
+ TQueryFnData = unknown,
36
+ TError = DefaultError,
37
+ TData = TQueryFnData,
38
+ TQueryData = TQueryFnData,
39
+ TQueryKey extends QueryKey = QueryKey,
40
+ > extends QueryObserverOptions<
41
+ TQueryFnData,
42
+ TError,
43
+ TData,
44
+ TQueryData,
45
+ TQueryKey
46
+ > {}
47
+
48
+ /**
49
+ * The options accepted by `injectQuery`. Same as {@link CreateBaseQueryOptions}, minus `suspense` — which
50
+ * `angular-query-experimental` doesn't support, unlike `react-query`.
51
+ *
52
+ * @template TQueryFnData - The type your `queryFn` resolves to.
53
+ * @template TError - The type of errors your `queryFn` may throw.
54
+ * @template TData - The type `data` ends up as after `select` runs. Defaults to `TQueryFnData` when no
55
+ * `select` is used.
56
+ * @template TQueryKey - The type of your `queryKey`.
57
+ */
58
+ export interface CreateQueryOptions<
59
+ TQueryFnData = unknown,
60
+ TError = DefaultError,
61
+ TData = TQueryFnData,
62
+ TQueryKey extends QueryKey = QueryKey,
63
+ > extends OmitKeyof<
64
+ CreateBaseQueryOptions<TQueryFnData, TError, TData, TQueryFnData, TQueryKey>,
65
+ 'suspense'
66
+ > {}
67
+
68
+ type CreateStatusBasedQueryResult<
69
+ TStatus extends QueryObserverResult['status'],
70
+ TData = unknown,
71
+ TError = DefaultError,
72
+ > = Extract<QueryObserverResult<TData, TError>, { status: TStatus }>
73
+
74
+ /**
75
+ * The `isSuccess`/`isError`/`isPending` methods on a query result. Unlike `react-query`'s derived booleans,
76
+ * these are type-guard methods you call — `if (query.isSuccess())` — so that `query.data` narrows away
77
+ * `undefined` inside the branch, the same way `status` narrowing works on the plain object `react-query`
78
+ * returns.
79
+ *
80
+ * @template TData - The type `data` ends up as after `select` runs.
81
+ * @template TError - The type of errors your `queryFn` may throw.
82
+ */
83
+ export interface BaseQueryNarrowing<TData = unknown, TError = DefaultError> {
84
+ isSuccess: (
85
+ this: CreateBaseQueryResult<TData, TError>,
86
+ ) => this is CreateBaseQueryResult<
87
+ TData,
88
+ TError,
89
+ CreateStatusBasedQueryResult<'success', TData, TError>
90
+ >
91
+ isError: (
92
+ this: CreateBaseQueryResult<TData, TError>,
93
+ ) => this is CreateBaseQueryResult<
94
+ TData,
95
+ TError,
96
+ CreateStatusBasedQueryResult<'error', TData, TError>
97
+ >
98
+ isPending: (
99
+ this: CreateBaseQueryResult<TData, TError>,
100
+ ) => this is CreateBaseQueryResult<
101
+ TData,
102
+ TError,
103
+ CreateStatusBasedQueryResult<'pending', TData, TError>
104
+ >
105
+ }
106
+
107
+ /**
108
+ * The options accepted by `injectInfiniteQuery`. Same as {@link CreateBaseQueryOptions}, minus `suspense` —
109
+ * which `angular-query-experimental` doesn't support, unlike `react-query` — extends
110
+ * {@link InfiniteQueryObserverOptions} from `@tanstack/query-core` for the infinite-query-specific options
111
+ * (`getNextPageParam`, `initialPageParam`, etc.).
112
+ *
113
+ * @template TQueryFnData - The type of a single page, as your `queryFn` resolves it.
114
+ * @template TError - The type of errors your `queryFn` may throw.
115
+ * @template TData - The type `data` ends up as after `select` runs. Defaults to `TQueryFnData` here, though
116
+ * `injectInfiniteQuery` itself defaults it to `InfiniteData<TQueryFnData>` — the shape `data` actually has
117
+ * when no `select` is used.
118
+ * @template TQueryKey - The type of your `queryKey`.
119
+ * @template TPageParam - The type of the parameter passed to `queryFn` to fetch a given page.
120
+ */
121
+ export interface CreateInfiniteQueryOptions<
122
+ TQueryFnData = unknown,
123
+ TError = DefaultError,
124
+ TData = TQueryFnData,
125
+ TQueryKey extends QueryKey = QueryKey,
126
+ TPageParam = unknown,
127
+ > extends OmitKeyof<
128
+ InfiniteQueryObserverOptions<
129
+ TQueryFnData,
130
+ TError,
131
+ TData,
132
+ TQueryKey,
133
+ TPageParam
134
+ >,
135
+ 'suspense'
136
+ > {}
137
+
138
+ /**
139
+ * The result of `injectQuery` when `initialData` isn't set — `data` may be `undefined` while the query is
140
+ * `pending`. Same shape as {@link QueryObserverResult} from `@tanstack/query-core`, but value fields (like
141
+ * `data`, `error`, `status`) are exposed as a `Signal` — read them with `query.data()`, not `query.data` —
142
+ * while function fields (like `refetch`) are called directly, unchanged. `isSuccess`/`isError`/`isPending`
143
+ * are {@link BaseQueryNarrowing} type-guard methods rather than plain booleans.
144
+ * `injectInfiniteQuery` returns {@link CreateInfiniteQueryResult} instead.
145
+ *
146
+ * @template TData - The type `data` ends up as after `select` runs.
147
+ * @template TError - The type of errors your `queryFn` may throw.
148
+ */
149
+ export type CreateBaseQueryResult<
150
+ TData = unknown,
151
+ TError = DefaultError,
152
+ TState = QueryObserverResult<TData, TError>,
153
+ > = BaseQueryNarrowing<TData, TError> &
154
+ MapToSignals<OmitKeyof<TState, keyof BaseQueryNarrowing, 'safely'>>
155
+
156
+ /**
157
+ * The result of `injectQuery`. Same as {@link CreateBaseQueryResult}.
158
+ *
159
+ * @template TData - The type `data` ends up as after `select` runs.
160
+ * @template TError - The type of errors your `queryFn` may throw.
161
+ */
162
+ export type CreateQueryResult<
163
+ TData = unknown,
164
+ TError = DefaultError,
165
+ > = CreateBaseQueryResult<TData, TError>
166
+
167
+ /**
168
+ * The result of `injectQuery` when `initialData` is set — `data` is never `undefined`. Same shape as
169
+ * {@link DefinedQueryObserverResult} from `@tanstack/query-core`, but value fields are exposed as a
170
+ * `Signal` while function fields are called directly, unchanged.
171
+ *
172
+ * @template TData - The type `data` ends up as after `select` runs.
173
+ * @template TError - The type of errors your `queryFn` may throw.
174
+ */
175
+ export type DefinedCreateQueryResult<
176
+ TData = unknown,
177
+ TError = DefaultError,
178
+ TState = DefinedQueryObserverResult<TData, TError>,
179
+ > = BaseQueryNarrowing<TData, TError> &
180
+ MapToSignals<OmitKeyof<TState, keyof BaseQueryNarrowing, 'safely'>>
181
+
182
+ /**
183
+ * The result of `injectInfiniteQuery` when `initialData` isn't set — `data` may be `undefined` while the
184
+ * query is `pending`. Same shape as {@link InfiniteQueryObserverResult} from `@tanstack/query-core`, but
185
+ * value fields are exposed as a `Signal` while function fields (like `fetchNextPage`) are called directly,
186
+ * unchanged.
187
+ *
188
+ * @template TData - The type `data` ends up as after `select` runs.
189
+ * @template TError - The type of errors your `queryFn` may throw.
190
+ */
191
+ export type CreateInfiniteQueryResult<
192
+ TData = unknown,
193
+ TError = DefaultError,
194
+ > = BaseQueryNarrowing<TData, TError> &
195
+ MapToSignals<InfiniteQueryObserverResult<TData, TError>>
196
+
197
+ /**
198
+ * The result of `injectInfiniteQuery` when `initialData` is set — `data` is never `undefined`. Same shape as
199
+ * {@link DefinedInfiniteQueryObserverResult} from `@tanstack/query-core`, but value fields are exposed as a
200
+ * `Signal` while function fields are called directly, unchanged.
201
+ *
202
+ * @template TData - The type `data` ends up as after `select` runs.
203
+ * @template TError - The type of errors your `queryFn` may throw.
204
+ */
205
+ export type DefinedCreateInfiniteQueryResult<
206
+ TData = unknown,
207
+ TError = DefaultError,
208
+ TDefinedInfiniteQueryObserver = DefinedInfiniteQueryObserverResult<
209
+ TData,
210
+ TError
211
+ >,
212
+ > = MapToSignals<TDefinedInfiniteQueryObserver>
213
+
214
+ /**
215
+ * The options accepted by `injectMutation`. Same as {@link MutationObserverOptions} from
216
+ * `@tanstack/query-core`, minus the internal `_defaulted` flag.
217
+ *
218
+ * @template TData - The type your mutation function resolves to.
219
+ * @template TError - The type of errors your mutation function may throw.
220
+ * @template TVariables - The type of the variable passed to `mutate`/`mutateAsync`.
221
+ * @template TOnMutateResult - The type returned by `onMutate`, passed to `onSuccess`/`onError`/`onSettled` as
222
+ * their `onMutateResult` parameter — useful for optimistic-update rollback data.
223
+ */
224
+ export interface CreateMutationOptions<
225
+ TData = unknown,
226
+ TError = DefaultError,
227
+ TVariables = void,
228
+ TOnMutateResult = unknown,
229
+ > extends OmitKeyof<
230
+ MutationObserverOptions<TData, TError, TVariables, TOnMutateResult>,
231
+ '_defaulted'
232
+ > {}
233
+
234
+ /**
235
+ * The type of `mutate`, as returned by `injectMutation`. Forwards the variables (and an optional per-call
236
+ * `onSuccess`/`onError`/`onSettled`) to the underlying `mutate` call. Fire-and-forget — errors are surfaced
237
+ * through the mutation result, not thrown.
238
+ *
239
+ * @template TData - The type your mutation function resolves to.
240
+ * @template TError - The type of errors your mutation function may throw.
241
+ * @template TVariables - The type of the variable passed to `mutate`.
242
+ * @template TOnMutateResult - The type returned by `onMutate`, passed to `onSuccess`/`onError`/`onSettled` as
243
+ * their `onMutateResult` parameter — useful for optimistic-update rollback data.
244
+ */
245
+ export type CreateMutateFunction<
246
+ TData = unknown,
247
+ TError = DefaultError,
248
+ TVariables = void,
249
+ TOnMutateResult = unknown,
250
+ > = (
251
+ ...args: Parameters<
252
+ MutateFunction<TData, TError, TVariables, TOnMutateResult>
253
+ >
254
+ ) => void
255
+
256
+ /**
257
+ * The type of `mutateAsync`, as returned by `injectMutation`. Similar to {@link CreateMutateFunction}, but
258
+ * returns a promise which can be awaited.
259
+ *
260
+ * @template TData - The type your mutation function resolves to.
261
+ * @template TError - The type of errors your mutation function may throw.
262
+ * @template TVariables - The type of the variable passed to `mutateAsync`.
263
+ * @template TOnMutateResult - The type returned by `onMutate`, passed to `onSuccess`/`onError`/`onSettled` as
264
+ * their `onMutateResult` parameter — useful for optimistic-update rollback data.
265
+ */
266
+ export type CreateMutateAsyncFunction<
267
+ TData = unknown,
268
+ TError = DefaultError,
269
+ TVariables = void,
270
+ TOnMutateResult = unknown,
271
+ > = MutateFunction<TData, TError, TVariables, TOnMutateResult>
272
+
273
+ /**
274
+ * The pre-`Signal` shape {@link CreateMutationResult} is built from — not what `injectMutation` actually
275
+ * returns. Same as {@link MutationObserverResult} from `@tanstack/query-core`, with `mutate` narrowed to the
276
+ * fire-and-forget {@link CreateMutateFunction} signature, plus the added `mutateAsync`.
277
+ *
278
+ * @template TData - The type your mutation function resolves to.
279
+ * @template TError - The type of errors your mutation function may throw.
280
+ * @template TVariables - The type of the variable passed to `mutate`/`mutateAsync`.
281
+ * @template TOnMutateResult - The type returned by `onMutate`, passed to `onSuccess`/`onError`/`onSettled` as
282
+ * their `onMutateResult` parameter — useful for optimistic-update rollback data.
283
+ */
284
+ export type CreateBaseMutationResult<
285
+ TData = unknown,
286
+ TError = DefaultError,
287
+ TVariables = unknown,
288
+ TOnMutateResult = unknown,
289
+ > = Override<
290
+ MutationObserverResult<TData, TError, TVariables, TOnMutateResult>,
291
+ { mutate: CreateMutateFunction<TData, TError, TVariables, TOnMutateResult> }
292
+ > & {
293
+ /**
294
+ * Similar to `mutate`, but returns a promise which can be awaited.
295
+ */
296
+ mutateAsync: CreateMutateAsyncFunction<
297
+ TData,
298
+ TError,
299
+ TVariables,
300
+ TOnMutateResult
301
+ >
302
+ }
303
+
304
+ type CreateStatusBasedMutationResult<
305
+ TStatus extends CreateBaseMutationResult['status'],
306
+ TData = unknown,
307
+ TError = DefaultError,
308
+ TVariables = unknown,
309
+ TOnMutateResult = unknown,
310
+ > = Extract<
311
+ CreateBaseMutationResult<TData, TError, TVariables, TOnMutateResult>,
312
+ { status: TStatus }
313
+ >
314
+
315
+ type SignalFunction<T extends () => any> = T & Signal<ReturnType<T>>
316
+
317
+ /**
318
+ * The `isSuccess`/`isError`/`isPending`/`isIdle` methods on a mutation result. Each is both a `Signal`
319
+ * (its current boolean value is read reactively without calling it) and a type-guard function you can
320
+ * call — `if (mutation.isSuccess())` — so that `mutation.data` narrows away `undefined` inside the branch.
321
+ *
322
+ * @template TData - The type your mutation function resolves to.
323
+ * @template TError - The type of errors your mutation function may throw.
324
+ * @template TVariables - The type of the variable passed to `mutate`/`mutateAsync`.
325
+ * @template TOnMutateResult - The type returned by `onMutate`, passed to `onSuccess`/`onError`/`onSettled` as
326
+ * their `onMutateResult` parameter — useful for optimistic-update rollback data.
327
+ */
328
+ export interface BaseMutationNarrowing<
329
+ TData = unknown,
330
+ TError = DefaultError,
331
+ TVariables = unknown,
332
+ TOnMutateResult = unknown,
333
+ > {
334
+ isSuccess: SignalFunction<
335
+ (
336
+ this: CreateMutationResult<TData, TError, TVariables, TOnMutateResult>,
337
+ ) => this is CreateMutationResult<
338
+ TData,
339
+ TError,
340
+ TVariables,
341
+ TOnMutateResult,
342
+ CreateStatusBasedMutationResult<
343
+ 'success',
344
+ TData,
345
+ TError,
346
+ TVariables,
347
+ TOnMutateResult
348
+ >
349
+ >
350
+ >
351
+ isError: SignalFunction<
352
+ (
353
+ this: CreateMutationResult<TData, TError, TVariables, TOnMutateResult>,
354
+ ) => this is CreateMutationResult<
355
+ TData,
356
+ TError,
357
+ TVariables,
358
+ TOnMutateResult,
359
+ CreateStatusBasedMutationResult<
360
+ 'error',
361
+ TData,
362
+ TError,
363
+ TVariables,
364
+ TOnMutateResult
365
+ >
366
+ >
367
+ >
368
+ isPending: SignalFunction<
369
+ (
370
+ this: CreateMutationResult<TData, TError, TVariables, TOnMutateResult>,
371
+ ) => this is CreateMutationResult<
372
+ TData,
373
+ TError,
374
+ TVariables,
375
+ TOnMutateResult,
376
+ CreateStatusBasedMutationResult<
377
+ 'pending',
378
+ TData,
379
+ TError,
380
+ TVariables,
381
+ TOnMutateResult
382
+ >
383
+ >
384
+ >
385
+ isIdle: SignalFunction<
386
+ (
387
+ this: CreateMutationResult<TData, TError, TVariables, TOnMutateResult>,
388
+ ) => this is CreateMutationResult<
389
+ TData,
390
+ TError,
391
+ TVariables,
392
+ TOnMutateResult,
393
+ CreateStatusBasedMutationResult<
394
+ 'idle',
395
+ TData,
396
+ TError,
397
+ TVariables,
398
+ TOnMutateResult
399
+ >
400
+ >
401
+ >
402
+ }
403
+
404
+ /**
405
+ * The result of `injectMutation`. Based on {@link CreateBaseMutationResult}, but value fields are exposed as
406
+ * a `Signal` — read them with `mutation.data()`, not `mutation.data` — while function fields (`mutate`,
407
+ * `mutateAsync`, `reset`) are called directly, unchanged. `isSuccess`/`isError`/`isPending`/`isIdle` are
408
+ * {@link BaseMutationNarrowing} type-guard methods rather than plain booleans.
409
+ *
410
+ * @template TData - The type your mutation function resolves to.
411
+ * @template TError - The type of errors your mutation function may throw.
412
+ * @template TVariables - The type of the variable passed to `mutate`/`mutateAsync`.
413
+ * @template TOnMutateResult - The type returned by `onMutate`, passed to `onSuccess`/`onError`/`onSettled` as
414
+ * their `onMutateResult` parameter — useful for optimistic-update rollback data.
415
+ */
416
+ export type CreateMutationResult<
417
+ TData = unknown,
418
+ TError = DefaultError,
419
+ TVariables = unknown,
420
+ TOnMutateResult = unknown,
421
+ TState = CreateStatusBasedMutationResult<
422
+ CreateBaseMutationResult['status'],
423
+ TData,
424
+ TError,
425
+ TVariables,
426
+ TOnMutateResult
427
+ >,
428
+ > = BaseMutationNarrowing<TData, TError, TVariables, TOnMutateResult> &
429
+ MapToSignals<OmitKeyof<TState, keyof BaseMutationNarrowing, 'safely'>>
@@ -1,164 +0,0 @@
1
- import { QueryKey, QueryObserver, QueryObserverResult } from '@tanstack/query-core';
2
- import { CreateBaseQueryOptions } from './types.js';
3
- /**
4
- * Base implementation for `injectQuery` and `injectInfiniteQuery`.
5
- * @param optionsFn
6
- * @param Observer
7
- */
8
- export declare function createBaseQuery<TQueryFnData, TError, TData, TQueryData, TQueryKey extends QueryKey>(optionsFn: () => CreateBaseQueryOptions<TQueryFnData, TError, TData, TQueryData, TQueryKey>, Observer: typeof QueryObserver): import('./signal-proxy.js').MapToSignals<{
9
- refetch: (options?: import('@tanstack/query-core').RefetchOptions) => Promise<QueryObserverResult<TData, TError>>;
10
- data: TData;
11
- error: TError;
12
- isError: true;
13
- isPending: false;
14
- isLoading: false;
15
- isLoadingError: false;
16
- isRefetchError: true;
17
- isSuccess: false;
18
- isPlaceholderData: false;
19
- status: "error";
20
- dataUpdatedAt: number;
21
- errorUpdatedAt: number;
22
- failureCount: number;
23
- failureReason: TError | null;
24
- errorUpdateCount: number;
25
- isFetched: boolean;
26
- isFetchedAfterMount: boolean;
27
- isFetching: boolean;
28
- isInitialLoading: boolean;
29
- isPaused: boolean;
30
- isRefetching: boolean;
31
- isStale: boolean;
32
- isEnabled: boolean;
33
- fetchStatus: import('@tanstack/query-core').FetchStatus;
34
- } | {
35
- refetch: (options?: import('@tanstack/query-core').RefetchOptions) => Promise<QueryObserverResult<TData, TError>>;
36
- data: TData;
37
- error: null;
38
- isError: false;
39
- isPending: false;
40
- isLoading: false;
41
- isLoadingError: false;
42
- isRefetchError: false;
43
- isSuccess: true;
44
- isPlaceholderData: false;
45
- status: "success";
46
- dataUpdatedAt: number;
47
- errorUpdatedAt: number;
48
- failureCount: number;
49
- failureReason: TError | null;
50
- errorUpdateCount: number;
51
- isFetched: boolean;
52
- isFetchedAfterMount: boolean;
53
- isFetching: boolean;
54
- isInitialLoading: boolean;
55
- isPaused: boolean;
56
- isRefetching: boolean;
57
- isStale: boolean;
58
- isEnabled: boolean;
59
- fetchStatus: import('@tanstack/query-core').FetchStatus;
60
- } | {
61
- refetch: (options?: import('@tanstack/query-core').RefetchOptions) => Promise<QueryObserverResult<TData, TError>>;
62
- data: undefined;
63
- error: TError;
64
- isError: true;
65
- isPending: false;
66
- isLoading: false;
67
- isLoadingError: true;
68
- isRefetchError: false;
69
- isSuccess: false;
70
- isPlaceholderData: false;
71
- status: "error";
72
- dataUpdatedAt: number;
73
- errorUpdatedAt: number;
74
- failureCount: number;
75
- failureReason: TError | null;
76
- errorUpdateCount: number;
77
- isFetched: boolean;
78
- isFetchedAfterMount: boolean;
79
- isFetching: boolean;
80
- isInitialLoading: boolean;
81
- isPaused: boolean;
82
- isRefetching: boolean;
83
- isStale: boolean;
84
- isEnabled: boolean;
85
- fetchStatus: import('@tanstack/query-core').FetchStatus;
86
- } | {
87
- refetch: (options?: import('@tanstack/query-core').RefetchOptions) => Promise<QueryObserverResult<TData, TError>>;
88
- data: undefined;
89
- error: null;
90
- isError: false;
91
- isPending: true;
92
- isLoading: true;
93
- isLoadingError: false;
94
- isRefetchError: false;
95
- isSuccess: false;
96
- isPlaceholderData: false;
97
- status: "pending";
98
- dataUpdatedAt: number;
99
- errorUpdatedAt: number;
100
- failureCount: number;
101
- failureReason: TError | null;
102
- errorUpdateCount: number;
103
- isFetched: boolean;
104
- isFetchedAfterMount: boolean;
105
- isFetching: boolean;
106
- isInitialLoading: boolean;
107
- isPaused: boolean;
108
- isRefetching: boolean;
109
- isStale: boolean;
110
- isEnabled: boolean;
111
- fetchStatus: import('@tanstack/query-core').FetchStatus;
112
- } | {
113
- refetch: (options?: import('@tanstack/query-core').RefetchOptions) => Promise<QueryObserverResult<TData, TError>>;
114
- data: undefined;
115
- error: null;
116
- isError: false;
117
- isPending: true;
118
- isLoadingError: false;
119
- isRefetchError: false;
120
- isSuccess: false;
121
- isPlaceholderData: false;
122
- status: "pending";
123
- dataUpdatedAt: number;
124
- errorUpdatedAt: number;
125
- failureCount: number;
126
- failureReason: TError | null;
127
- errorUpdateCount: number;
128
- isFetched: boolean;
129
- isFetchedAfterMount: boolean;
130
- isFetching: boolean;
131
- isLoading: boolean;
132
- isInitialLoading: boolean;
133
- isPaused: boolean;
134
- isRefetching: boolean;
135
- isStale: boolean;
136
- isEnabled: boolean;
137
- fetchStatus: import('@tanstack/query-core').FetchStatus;
138
- } | {
139
- refetch: (options?: import('@tanstack/query-core').RefetchOptions) => Promise<QueryObserverResult<TData, TError>>;
140
- data: TData;
141
- isError: false;
142
- error: null;
143
- isPending: false;
144
- isLoading: false;
145
- isLoadingError: false;
146
- isRefetchError: false;
147
- isSuccess: true;
148
- isPlaceholderData: true;
149
- status: "success";
150
- dataUpdatedAt: number;
151
- errorUpdatedAt: number;
152
- failureCount: number;
153
- failureReason: TError | null;
154
- errorUpdateCount: number;
155
- isFetched: boolean;
156
- isFetchedAfterMount: boolean;
157
- isFetching: boolean;
158
- isInitialLoading: boolean;
159
- isPaused: boolean;
160
- isRefetching: boolean;
161
- isStale: boolean;
162
- isEnabled: boolean;
163
- fetchStatus: import('@tanstack/query-core').FetchStatus;
164
- }>;
@@ -1,99 +0,0 @@
1
- import { inject, NgZone, computed, signal, effect, untracked, VERSION } from "@angular/core";
2
- import { QueryClient, notifyManager, shouldThrowError } from "@tanstack/query-core";
3
- import { signalProxy } from "./signal-proxy.mjs";
4
- import { injectIsRestoring } from "./inject-is-restoring.mjs";
5
- import { PENDING_TASKS } from "./pending-tasks-compat.mjs";
6
- function createBaseQuery(optionsFn, Observer) {
7
- const ngZone = inject(NgZone);
8
- const pendingTasks = inject(PENDING_TASKS);
9
- const queryClient = inject(QueryClient);
10
- const isRestoring = injectIsRestoring();
11
- const defaultedOptionsSignal = computed(() => {
12
- const defaultedOptions = queryClient.defaultQueryOptions(optionsFn());
13
- defaultedOptions._optimisticResults = isRestoring() ? "isRestoring" : "optimistic";
14
- return defaultedOptions;
15
- });
16
- const observerSignal = (() => {
17
- let instance = null;
18
- return computed(() => {
19
- return instance || (instance = new Observer(queryClient, defaultedOptionsSignal()));
20
- });
21
- })();
22
- const optimisticResultSignal = computed(
23
- () => observerSignal().getOptimisticResult(defaultedOptionsSignal())
24
- );
25
- const resultFromSubscriberSignal = signal(null);
26
- effect(
27
- (onCleanup) => {
28
- const observer = observerSignal();
29
- const defaultedOptions = defaultedOptionsSignal();
30
- untracked(() => {
31
- observer.setOptions(defaultedOptions);
32
- });
33
- onCleanup(() => {
34
- ngZone.run(() => resultFromSubscriberSignal.set(null));
35
- });
36
- },
37
- {
38
- // Set allowSignalWrites to support Angular < v19
39
- // Set to undefined to avoid warning on newer versions
40
- allowSignalWrites: VERSION.major < "19" || void 0
41
- }
42
- );
43
- effect((onCleanup) => {
44
- const observer = observerSignal();
45
- let pendingTaskRef = null;
46
- const unsubscribe = isRestoring() ? () => void 0 : untracked(
47
- () => ngZone.runOutsideAngular(() => {
48
- return observer.subscribe(
49
- notifyManager.batchCalls((state) => {
50
- ngZone.run(() => {
51
- if (state.fetchStatus === "fetching" && !pendingTaskRef) {
52
- pendingTaskRef = pendingTasks.add();
53
- }
54
- if (state.fetchStatus === "idle" && pendingTaskRef) {
55
- pendingTaskRef();
56
- pendingTaskRef = null;
57
- }
58
- if (state.isError && !state.isFetching && shouldThrowError(observer.options.throwOnError, [
59
- state.error,
60
- observer.getCurrentQuery()
61
- ])) {
62
- ngZone.onError.emit(state.error);
63
- throw state.error;
64
- }
65
- resultFromSubscriberSignal.set(state);
66
- });
67
- })
68
- );
69
- })
70
- );
71
- onCleanup(() => {
72
- if (pendingTaskRef) {
73
- pendingTaskRef();
74
- pendingTaskRef = null;
75
- }
76
- unsubscribe();
77
- });
78
- });
79
- return signalProxy(
80
- computed(() => {
81
- const subscriberResult = resultFromSubscriberSignal();
82
- const optimisticResult = optimisticResultSignal();
83
- const result = subscriberResult ?? optimisticResult;
84
- const observer = observerSignal();
85
- const originalRefetch = result.refetch;
86
- return {
87
- ...result,
88
- refetch: ((...args) => {
89
- observer.setOptions(defaultedOptionsSignal());
90
- return originalRefetch(...args);
91
- })
92
- };
93
- })
94
- );
95
- }
96
- export {
97
- createBaseQuery
98
- };
99
- //# sourceMappingURL=create-base-query.mjs.map