@depup/reduxjs__toolkit 2.12.0-depup.28

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 (173) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +33 -0
  3. package/changes.json +18 -0
  4. package/dist/cjs/index.js +6 -0
  5. package/dist/cjs/redux-toolkit.development.cjs +2406 -0
  6. package/dist/cjs/redux-toolkit.development.cjs.map +1 -0
  7. package/dist/cjs/redux-toolkit.production.min.cjs +3 -0
  8. package/dist/cjs/redux-toolkit.production.min.cjs.map +1 -0
  9. package/dist/index.d.mts +2665 -0
  10. package/dist/index.d.ts +2665 -0
  11. package/dist/query/cjs/index.js +6 -0
  12. package/dist/query/cjs/rtk-query.development.cjs +3092 -0
  13. package/dist/query/cjs/rtk-query.development.cjs.map +1 -0
  14. package/dist/query/cjs/rtk-query.production.min.cjs +2 -0
  15. package/dist/query/cjs/rtk-query.production.min.cjs.map +1 -0
  16. package/dist/query/index.d.mts +3066 -0
  17. package/dist/query/index.d.ts +3066 -0
  18. package/dist/query/react/cjs/index.js +6 -0
  19. package/dist/query/react/cjs/rtk-query-react.development.cjs +748 -0
  20. package/dist/query/react/cjs/rtk-query-react.development.cjs.map +1 -0
  21. package/dist/query/react/cjs/rtk-query-react.production.min.cjs +2 -0
  22. package/dist/query/react/cjs/rtk-query-react.production.min.cjs.map +1 -0
  23. package/dist/query/react/index.d.mts +1009 -0
  24. package/dist/query/react/index.d.ts +1009 -0
  25. package/dist/query/react/rtk-query-react.browser.mjs +2 -0
  26. package/dist/query/react/rtk-query-react.browser.mjs.map +1 -0
  27. package/dist/query/react/rtk-query-react.legacy-esm.js +740 -0
  28. package/dist/query/react/rtk-query-react.legacy-esm.js.map +1 -0
  29. package/dist/query/react/rtk-query-react.modern.mjs +705 -0
  30. package/dist/query/react/rtk-query-react.modern.mjs.map +1 -0
  31. package/dist/query/rtk-query.browser.mjs +2 -0
  32. package/dist/query/rtk-query.browser.mjs.map +1 -0
  33. package/dist/query/rtk-query.legacy-esm.js +3117 -0
  34. package/dist/query/rtk-query.legacy-esm.js.map +1 -0
  35. package/dist/query/rtk-query.modern.mjs +3052 -0
  36. package/dist/query/rtk-query.modern.mjs.map +1 -0
  37. package/dist/react/cjs/index.js +6 -0
  38. package/dist/react/cjs/redux-toolkit-react.development.cjs +55 -0
  39. package/dist/react/cjs/redux-toolkit-react.development.cjs.map +1 -0
  40. package/dist/react/cjs/redux-toolkit-react.production.min.cjs +2 -0
  41. package/dist/react/cjs/redux-toolkit-react.production.min.cjs.map +1 -0
  42. package/dist/react/index.d.mts +22 -0
  43. package/dist/react/index.d.ts +22 -0
  44. package/dist/react/redux-toolkit-react.browser.mjs +2 -0
  45. package/dist/react/redux-toolkit-react.browser.mjs.map +1 -0
  46. package/dist/react/redux-toolkit-react.legacy-esm.js +47 -0
  47. package/dist/react/redux-toolkit-react.legacy-esm.js.map +1 -0
  48. package/dist/react/redux-toolkit-react.modern.mjs +28 -0
  49. package/dist/react/redux-toolkit-react.modern.mjs.map +1 -0
  50. package/dist/redux-toolkit.browser.mjs +3 -0
  51. package/dist/redux-toolkit.browser.mjs.map +1 -0
  52. package/dist/redux-toolkit.legacy-esm.js +2351 -0
  53. package/dist/redux-toolkit.legacy-esm.js.map +1 -0
  54. package/dist/redux-toolkit.modern.mjs +2330 -0
  55. package/dist/redux-toolkit.modern.mjs.map +1 -0
  56. package/dist/uncheckedindexed.ts +16 -0
  57. package/package.json +310 -0
  58. package/query/package.json +13 -0
  59. package/query/react/package.json +13 -0
  60. package/react/package.json +13 -0
  61. package/skills/build-modern-redux-apps/modern-redux/SKILL.md +304 -0
  62. package/skills/build-modern-redux-apps/modern-redux/references/store-lifetime.md +53 -0
  63. package/skills/build-modern-redux-apps/redux-dataflow/SKILL.md +264 -0
  64. package/skills/evolve-and-diagnose-redux-apps/debug-redux-toolkit-apps/SKILL.md +269 -0
  65. package/skills/evolve-and-diagnose-redux-apps/migrate-to-modern-redux/SKILL.md +226 -0
  66. package/skills/manage-server-data/adopt-rtk-query/SKILL.md +385 -0
  67. package/skills/manage-server-data/adopt-rtk-query/references/endpoint-lifecycle.md +36 -0
  68. package/skills/model-redux-state/build-slices-and-selectors/SKILL.md +364 -0
  69. package/skills/model-redux-state/build-slices-and-selectors/references/slice-patterns.md +59 -0
  70. package/skills/model-redux-state/design-state-ownership/SKILL.md +322 -0
  71. package/skills/model-redux-state/design-state-ownership/references/state-ownership.md +28 -0
  72. package/skills/orchestrate-side-effects/handle-side-effects/SKILL.md +271 -0
  73. package/skills/orchestrate-side-effects/handle-side-effects/references/listener-workflows.md +34 -0
  74. package/src/actionCreatorInvariantMiddleware.ts +34 -0
  75. package/src/autoBatchEnhancer.ts +146 -0
  76. package/src/combineSlices.ts +487 -0
  77. package/src/configureStore.ts +248 -0
  78. package/src/createAction.ts +324 -0
  79. package/src/createAsyncThunk.ts +791 -0
  80. package/src/createDraftSafeSelector.ts +30 -0
  81. package/src/createReducer.ts +217 -0
  82. package/src/createSlice.ts +1079 -0
  83. package/src/devtoolsExtension.ts +241 -0
  84. package/src/dynamicMiddleware/index.ts +93 -0
  85. package/src/dynamicMiddleware/react/index.ts +101 -0
  86. package/src/dynamicMiddleware/types.ts +82 -0
  87. package/src/entities/create_adapter.ts +47 -0
  88. package/src/entities/entity_state.ts +38 -0
  89. package/src/entities/index.ts +8 -0
  90. package/src/entities/models.ts +198 -0
  91. package/src/entities/sorted_state_adapter.ts +266 -0
  92. package/src/entities/state_adapter.ts +58 -0
  93. package/src/entities/state_selectors.ts +73 -0
  94. package/src/entities/unsorted_state_adapter.ts +204 -0
  95. package/src/entities/utils.ts +68 -0
  96. package/src/formatProdErrorMessage.ts +13 -0
  97. package/src/getDefaultEnhancers.ts +31 -0
  98. package/src/getDefaultMiddleware.ts +113 -0
  99. package/src/immerImports.ts +7 -0
  100. package/src/immutableStateInvariantMiddleware.ts +274 -0
  101. package/src/index.ts +213 -0
  102. package/src/listenerMiddleware/exceptions.ts +20 -0
  103. package/src/listenerMiddleware/index.ts +562 -0
  104. package/src/listenerMiddleware/task.ts +100 -0
  105. package/src/listenerMiddleware/types.ts +886 -0
  106. package/src/listenerMiddleware/utils.ts +30 -0
  107. package/src/mapBuilders.ts +298 -0
  108. package/src/matchers.ts +365 -0
  109. package/src/nanoid.ts +20 -0
  110. package/src/query/HandledError.ts +6 -0
  111. package/src/query/apiTypes.ts +120 -0
  112. package/src/query/baseQueryTypes.ts +101 -0
  113. package/src/query/core/apiState.ts +377 -0
  114. package/src/query/core/buildInitiate.ts +596 -0
  115. package/src/query/core/buildMiddleware/batchActions.ts +207 -0
  116. package/src/query/core/buildMiddleware/cacheCollection.ts +204 -0
  117. package/src/query/core/buildMiddleware/cacheLifecycle.ts +379 -0
  118. package/src/query/core/buildMiddleware/devMiddleware.ts +34 -0
  119. package/src/query/core/buildMiddleware/index.ts +162 -0
  120. package/src/query/core/buildMiddleware/invalidationByTags.ts +139 -0
  121. package/src/query/core/buildMiddleware/polling.ts +187 -0
  122. package/src/query/core/buildMiddleware/queryLifecycle.ts +508 -0
  123. package/src/query/core/buildMiddleware/types.ts +173 -0
  124. package/src/query/core/buildMiddleware/windowEventHandling.ts +64 -0
  125. package/src/query/core/buildSelectors.ts +413 -0
  126. package/src/query/core/buildSlice.ts +735 -0
  127. package/src/query/core/buildThunks.ts +1124 -0
  128. package/src/query/core/index.ts +58 -0
  129. package/src/query/core/module.ts +727 -0
  130. package/src/query/core/rtkImports.ts +24 -0
  131. package/src/query/core/setupListeners.ts +118 -0
  132. package/src/query/createApi.ts +506 -0
  133. package/src/query/defaultSerializeQueryArgs.ts +52 -0
  134. package/src/query/endpointDefinitions.ts +1717 -0
  135. package/src/query/fakeBaseQuery.ts +21 -0
  136. package/src/query/fetchBaseQuery.ts +385 -0
  137. package/src/query/index.ts +105 -0
  138. package/src/query/react/ApiProvider.tsx +69 -0
  139. package/src/query/react/buildHooks.ts +2297 -0
  140. package/src/query/react/constants.ts +2 -0
  141. package/src/query/react/index.ts +45 -0
  142. package/src/query/react/module.ts +275 -0
  143. package/src/query/react/namedHooks.ts +59 -0
  144. package/src/query/react/reactImports.ts +10 -0
  145. package/src/query/react/reactReduxImports.ts +1 -0
  146. package/src/query/react/rtkqImports.ts +8 -0
  147. package/src/query/react/useSerializedStableValue.ts +17 -0
  148. package/src/query/react/useShallowStableValue.ts +13 -0
  149. package/src/query/retry.ts +233 -0
  150. package/src/query/standardSchema.ts +35 -0
  151. package/src/query/tsHelpers.ts +48 -0
  152. package/src/query/utils/capitalize.ts +3 -0
  153. package/src/query/utils/copyWithStructuralSharing.ts +27 -0
  154. package/src/query/utils/countObjectKeys.ts +14 -0
  155. package/src/query/utils/filterMap.ts +27 -0
  156. package/src/query/utils/getCurrent.ts +6 -0
  157. package/src/query/utils/getOrInsert.ts +41 -0
  158. package/src/query/utils/immerImports.ts +9 -0
  159. package/src/query/utils/index.ts +11 -0
  160. package/src/query/utils/isAbsoluteUrl.ts +9 -0
  161. package/src/query/utils/isDocumentVisible.ts +12 -0
  162. package/src/query/utils/isNotNullish.ts +7 -0
  163. package/src/query/utils/isOnline.ts +12 -0
  164. package/src/query/utils/isValidUrl.ts +9 -0
  165. package/src/query/utils/joinUrls.ts +26 -0
  166. package/src/query/utils/signals.ts +33 -0
  167. package/src/react/index.ts +7 -0
  168. package/src/reduxImports.ts +8 -0
  169. package/src/reselectImports.ts +1 -0
  170. package/src/serializableStateInvariantMiddleware.ts +285 -0
  171. package/src/tsHelpers.ts +214 -0
  172. package/src/uncheckedindexed.ts +16 -0
  173. package/src/utils.ts +125 -0
@@ -0,0 +1,1717 @@
1
+ import type { Api } from '@reduxjs/toolkit/query'
2
+ import type { StandardSchemaV1 } from '@standard-schema/spec'
3
+ import type {
4
+ BaseQueryApi,
5
+ BaseQueryArg,
6
+ BaseQueryError,
7
+ BaseQueryExtraOptions,
8
+ BaseQueryFn,
9
+ BaseQueryMeta,
10
+ BaseQueryResult,
11
+ QueryReturnValue,
12
+ } from './baseQueryTypes'
13
+ import type { CacheCollectionQueryExtraOptions } from './core/buildMiddleware/cacheCollection'
14
+ import type {
15
+ CacheLifecycleInfiniteQueryExtraOptions,
16
+ CacheLifecycleMutationExtraOptions,
17
+ CacheLifecycleQueryExtraOptions,
18
+ } from './core/buildMiddleware/cacheLifecycle'
19
+ import type {
20
+ QueryLifecycleInfiniteQueryExtraOptions,
21
+ QueryLifecycleMutationExtraOptions,
22
+ QueryLifecycleQueryExtraOptions,
23
+ } from './core/buildMiddleware/queryLifecycle'
24
+ import type {
25
+ InfiniteData,
26
+ InfiniteQueryConfigOptions,
27
+ QuerySubState,
28
+ RootState,
29
+ } from './core/index'
30
+ import type { SerializeQueryArgs } from './defaultSerializeQueryArgs'
31
+ import type { NEVER } from './fakeBaseQuery'
32
+ import type { NamedSchemaError } from './standardSchema'
33
+ import type {
34
+ CastAny,
35
+ HasRequiredProps,
36
+ MaybePromise,
37
+ NonUndefined,
38
+ OmitFromUnion,
39
+ UnwrapPromise,
40
+ } from './tsHelpers'
41
+ import { isNotNullish } from './utils'
42
+ import { filterMap } from './utils/filterMap'
43
+
44
+ const rawResultType = /* @__PURE__ */ Symbol()
45
+ const resultType = /* @__PURE__ */ Symbol()
46
+ const baseQuery = /* @__PURE__ */ Symbol()
47
+
48
+ export interface SchemaFailureInfo {
49
+ endpoint: string
50
+ arg: any
51
+ type: 'query' | 'mutation'
52
+ queryCacheKey?: string
53
+ }
54
+
55
+ export type SchemaFailureHandler = (
56
+ error: NamedSchemaError,
57
+ info: SchemaFailureInfo,
58
+ ) => void
59
+
60
+ export type SchemaFailureConverter<BaseQuery extends BaseQueryFn> = (
61
+ error: NamedSchemaError,
62
+ info: SchemaFailureInfo,
63
+ ) => BaseQueryError<BaseQuery>
64
+
65
+ export type EndpointDefinitionWithQuery<
66
+ QueryArg,
67
+ BaseQuery extends BaseQueryFn,
68
+ ResultType,
69
+ RawResultType extends BaseQueryResult<BaseQuery>,
70
+ > = {
71
+ /**
72
+ * `query` can be a function that returns either a `string` or an `object` which is passed to your `baseQuery`. If you are using [fetchBaseQuery](./fetchBaseQuery), this can return either a `string` or an `object` of properties in `FetchArgs`. If you use your own custom [`baseQuery`](../../rtk-query/usage/customizing-queries), you can customize this behavior to your liking.
73
+ *
74
+ * @example
75
+ *
76
+ * ```ts
77
+ * // codeblock-meta title="query example"
78
+ *
79
+ * import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query/react';
80
+ *
81
+ * interface Post {
82
+ * id: number;
83
+ * name: string;
84
+ * }
85
+ *
86
+ * type PostsResponse = Post[];
87
+ *
88
+ * const api = createApi({
89
+ * baseQuery: fetchBaseQuery({ baseUrl: '/' }),
90
+ * tagTypes: ['Post'],
91
+ * endpoints: (build) => ({
92
+ * getPosts: build.query<PostsResponse, void>({
93
+ * // highlight-start
94
+ * query: () => 'posts',
95
+ * // highlight-end
96
+ * }),
97
+ * addPost: build.mutation<Post, Partial<Post>>({
98
+ * // highlight-start
99
+ * query: (body) => ({
100
+ * url: `posts`,
101
+ * method: 'POST',
102
+ * body,
103
+ * }),
104
+ * // highlight-end
105
+ * invalidatesTags: [{ type: 'Post', id: 'LIST' }],
106
+ * }),
107
+ * }),
108
+ * });
109
+ * ```
110
+ */
111
+ query(arg: QueryArg): BaseQueryArg<BaseQuery>
112
+ queryFn?: never
113
+ /**
114
+ * A function to manipulate the data returned by a query or mutation.
115
+ */
116
+ transformResponse?(
117
+ baseQueryReturnValue: RawResultType,
118
+ meta: BaseQueryMeta<BaseQuery>,
119
+ arg: QueryArg,
120
+ ): ResultType | Promise<ResultType>
121
+ /**
122
+ * A function to manipulate the data returned by a failed query or mutation.
123
+ */
124
+ transformErrorResponse?(
125
+ baseQueryReturnValue: BaseQueryError<BaseQuery>,
126
+ meta: BaseQueryMeta<BaseQuery>,
127
+ arg: QueryArg,
128
+ ): unknown
129
+
130
+ /**
131
+ * A schema for the result *before* it's passed to `transformResponse`.
132
+ *
133
+ * @example
134
+ * ```ts
135
+ * // codeblock-meta no-transpile
136
+ * import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query/react';
137
+ * import * as v from 'valibot';
138
+ *
139
+ * const postSchema = v.object({ id: v.number(), name: v.string() });
140
+ * type Post = v.InferOutput<typeof postSchema>;
141
+ *
142
+ * const api = createApi({
143
+ * baseQuery: fetchBaseQuery({ baseUrl: '/' }),
144
+ * endpoints: (build) => ({
145
+ * getPostName: build.query<Post, { id: number }>({
146
+ * query: ({ id }) => `/post/${id}`,
147
+ * rawResponseSchema: postSchema,
148
+ * transformResponse: (post) => post.name,
149
+ * }),
150
+ * }),
151
+ * });
152
+ * ```
153
+ */
154
+ rawResponseSchema?: StandardSchemaV1<RawResultType>
155
+
156
+ /**
157
+ * A schema for the error object returned by the `query` or `queryFn`, *before* it's passed to `transformErrorResponse`.
158
+ *
159
+ * @example
160
+ * ```ts
161
+ * // codeblock-meta no-transpile
162
+ * import { createApi } from '@reduxjs/toolkit/query/react';
163
+ * import { baseQueryErrorSchema, customBaseQuery } from './customBaseQuery';
164
+ *
165
+ * interface Post {
166
+ * id: number;
167
+ * name: string;
168
+ * }
169
+ *
170
+ * const api = createApi({
171
+ * baseQuery: customBaseQuery,
172
+ * endpoints: (build) => ({
173
+ * getPost: build.query<Post, { id: number }>({
174
+ * query: ({ id }) => `/post/${id}`,
175
+ * rawErrorResponseSchema: baseQueryErrorSchema,
176
+ * transformErrorResponse: (error) => error.data,
177
+ * }),
178
+ * }),
179
+ * });
180
+ * ```
181
+ */
182
+ rawErrorResponseSchema?: StandardSchemaV1<BaseQueryError<BaseQuery>>
183
+ }
184
+
185
+ export type EndpointDefinitionWithQueryFn<
186
+ QueryArg,
187
+ BaseQuery extends BaseQueryFn,
188
+ ResultType,
189
+ > = {
190
+ /**
191
+ * Can be used in place of `query` as an inline function that bypasses `baseQuery` completely for the endpoint.
192
+ *
193
+ * @example
194
+ * ```ts
195
+ * // codeblock-meta title="Basic queryFn example"
196
+ *
197
+ * import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query/react';
198
+ *
199
+ * interface Post {
200
+ * id: number;
201
+ * name: string;
202
+ * }
203
+ *
204
+ * type PostsResponse = Post[];
205
+ *
206
+ * const api = createApi({
207
+ * baseQuery: fetchBaseQuery({ baseUrl: '/' }),
208
+ * endpoints: (build) => ({
209
+ * getPosts: build.query<PostsResponse, void>({
210
+ * query: () => 'posts',
211
+ * }),
212
+ * flipCoin: build.query<'heads' | 'tails', void>({
213
+ * // highlight-start
214
+ * queryFn(arg, queryApi, extraOptions, baseQuery) {
215
+ * const randomVal = Math.random();
216
+ * if (randomVal < 0.45) {
217
+ * return { data: 'heads' };
218
+ * }
219
+ * if (randomVal < 0.9) {
220
+ * return { data: 'tails' };
221
+ * }
222
+ * return {
223
+ * error: {
224
+ * status: 500,
225
+ * statusText: 'Internal Server Error',
226
+ * data: 'Coin landed on its edge!',
227
+ * },
228
+ * };
229
+ * },
230
+ * // highlight-end
231
+ * }),
232
+ * }),
233
+ * });
234
+ * ```
235
+ */
236
+ queryFn(
237
+ arg: QueryArg,
238
+ api: BaseQueryApi,
239
+ extraOptions: BaseQueryExtraOptions<BaseQuery>,
240
+ baseQuery: (arg: Parameters<BaseQuery>[0]) => ReturnType<BaseQuery>,
241
+ ): MaybePromise<
242
+ QueryReturnValue<
243
+ ResultType,
244
+ BaseQueryError<BaseQuery>,
245
+ BaseQueryMeta<BaseQuery>
246
+ >
247
+ >
248
+ query?: never
249
+ transformResponse?: never
250
+ transformErrorResponse?: never
251
+ rawResponseSchema?: never
252
+ rawErrorResponseSchema?: never
253
+ }
254
+
255
+ type BaseEndpointTypes<
256
+ QueryArg,
257
+ BaseQuery extends BaseQueryFn,
258
+ ResultType,
259
+ RawResultType,
260
+ > = {
261
+ QueryArg: QueryArg
262
+ BaseQuery: BaseQuery
263
+ ResultType: ResultType
264
+ RawResultType: RawResultType
265
+ }
266
+
267
+ export type SchemaType =
268
+ | 'arg'
269
+ | 'rawResponse'
270
+ | 'response'
271
+ | 'rawErrorResponse'
272
+ | 'errorResponse'
273
+ | 'meta'
274
+
275
+ interface CommonEndpointDefinition<
276
+ QueryArg,
277
+ BaseQuery extends BaseQueryFn,
278
+ ResultType,
279
+ > {
280
+ /**
281
+ * A schema for the arguments to be passed to the `query` or `queryFn`.
282
+ *
283
+ * @example
284
+ * ```ts
285
+ * // codeblock-meta no-transpile
286
+ * import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query/react';
287
+ * import * as v from 'valibot';
288
+ *
289
+ * interface Post {
290
+ * id: number;
291
+ * name: string;
292
+ * }
293
+ *
294
+ * const api = createApi({
295
+ * baseQuery: fetchBaseQuery({ baseUrl: '/' }),
296
+ * endpoints: (build) => ({
297
+ * getPost: build.query<Post, { id: number }>({
298
+ * query: ({ id }) => `/post/${id}`,
299
+ * argSchema: v.object({ id: v.number() }),
300
+ * }),
301
+ * }),
302
+ * });
303
+ * ```
304
+ */
305
+ argSchema?: StandardSchemaV1<QueryArg>
306
+
307
+ /**
308
+ * A schema for the result (including `transformResponse` if provided).
309
+ *
310
+ * @example
311
+ * ```ts
312
+ * // codeblock-meta no-transpile
313
+ * import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query/react';
314
+ * import * as v from 'valibot';
315
+ *
316
+ * const postSchema = v.object({ id: v.number(), name: v.string() });
317
+ * type Post = v.InferOutput<typeof postSchema>;
318
+ *
319
+ * const api = createApi({
320
+ * baseQuery: fetchBaseQuery({ baseUrl: '/' }),
321
+ * endpoints: (build) => ({
322
+ * getPost: build.query<Post, { id: number }>({
323
+ * query: ({ id }) => `/post/${id}`,
324
+ * responseSchema: postSchema,
325
+ * }),
326
+ * }),
327
+ * });
328
+ * ```
329
+ */
330
+ responseSchema?: StandardSchemaV1<ResultType>
331
+
332
+ /**
333
+ * A schema for the error object returned by the `query` or `queryFn` (including `transformErrorResponse` if provided).
334
+ *
335
+ * @example
336
+ * ```ts
337
+ * // codeblock-meta no-transpile
338
+ * import { createApi } from '@reduxjs/toolkit/query/react';
339
+ * import { baseQueryErrorSchema, customBaseQuery } from './customBaseQuery';
340
+ *
341
+ * interface Post {
342
+ * id: number;
343
+ * name: string;
344
+ * }
345
+ *
346
+ * const api = createApi({
347
+ * baseQuery: customBaseQuery,
348
+ * endpoints: (build) => ({
349
+ * getPost: build.query<Post, { id: number }>({
350
+ * query: ({ id }) => `/post/${id}`,
351
+ * errorResponseSchema: baseQueryErrorSchema,
352
+ * }),
353
+ * }),
354
+ * });
355
+ * ```
356
+ */
357
+ errorResponseSchema?: StandardSchemaV1<BaseQueryError<BaseQuery>>
358
+
359
+ /**
360
+ * A schema for the `meta` property returned by the `query` or `queryFn`.
361
+ *
362
+ * @example
363
+ * ```ts
364
+ * // codeblock-meta no-transpile
365
+ * import { createApi } from '@reduxjs/toolkit/query/react';
366
+ * import { baseQueryMetaSchema, customBaseQuery } from './customBaseQuery';
367
+ *
368
+ * interface Post {
369
+ * id: number;
370
+ * name: string;
371
+ * }
372
+ *
373
+ * const api = createApi({
374
+ * baseQuery: customBaseQuery,
375
+ * endpoints: (build) => ({
376
+ * getPost: build.query<Post, { id: number }>({
377
+ * query: ({ id }) => `/post/${id}`,
378
+ * metaSchema: baseQueryMetaSchema,
379
+ * }),
380
+ * }),
381
+ * });
382
+ * ```
383
+ */
384
+ metaSchema?: StandardSchemaV1<BaseQueryMeta<BaseQuery>>
385
+
386
+ /**
387
+ * Most apps should leave this setting on. The only time it can be a performance issue
388
+ * is if an API returns extremely large amounts of data (e.g. 10,000 rows per request) and
389
+ * you're unable to paginate it.
390
+ *
391
+ * For details of how this works, please see the below. When it is set to `false`,
392
+ * every request will cause subscribed components to rerender, even when the data has not changed.
393
+ *
394
+ * @default true
395
+ *
396
+ * @see https://redux-toolkit.js.org/api/other-exports#copywithstructuralsharing
397
+ */
398
+ structuralSharing?: boolean
399
+
400
+ /**
401
+ * A function that is called when a schema validation fails.
402
+ *
403
+ * Gets called with a `NamedSchemaError` and an object containing the endpoint name, the type of the endpoint, the argument passed to the endpoint, and the query cache key (if applicable).
404
+ *
405
+ * `NamedSchemaError` has the following properties:
406
+ * - `issues`: an array of issues that caused the validation to fail
407
+ * - `value`: the value that was passed to the schema
408
+ * - `schemaName`: the name of the schema that was used to validate the value (e.g. `argSchema`)
409
+ *
410
+ * @example
411
+ * ```ts
412
+ * // codeblock-meta no-transpile
413
+ * import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query/react';
414
+ *
415
+ * interface Post {
416
+ * id: number;
417
+ * name: string;
418
+ * }
419
+ *
420
+ * const api = createApi({
421
+ * baseQuery: fetchBaseQuery({ baseUrl: '/' }),
422
+ * endpoints: (build) => ({
423
+ * getPost: build.query<Post, { id: number }>({
424
+ * query: ({ id }) => `/post/${id}`,
425
+ * onSchemaFailure: (error, info) => {
426
+ * console.error(error, info);
427
+ * },
428
+ * }),
429
+ * }),
430
+ * });
431
+ * ```
432
+ */
433
+ onSchemaFailure?: SchemaFailureHandler
434
+
435
+ /**
436
+ * Convert a schema validation failure into an error shape matching base query errors.
437
+ *
438
+ * When not provided, schema failures are treated as fatal, and normal error handling such as tag invalidation will not be executed.
439
+ *
440
+ * @example
441
+ * ```ts
442
+ * // codeblock-meta no-transpile
443
+ * import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query/react';
444
+ * import * as v from 'valibot';
445
+ *
446
+ * interface Post {
447
+ * id: number;
448
+ * name: string;
449
+ * }
450
+ *
451
+ * const api = createApi({
452
+ * baseQuery: fetchBaseQuery({ baseUrl: '/' }),
453
+ * endpoints: (build) => ({
454
+ * getPost: build.query<Post, { id: number }>({
455
+ * query: ({ id }) => `/post/${id}`,
456
+ * responseSchema: v.object({ id: v.number(), name: v.string() }),
457
+ * catchSchemaFailure: (error, info) => ({
458
+ * status: 'CUSTOM_ERROR',
459
+ * error: `${error.schemaName} failed validation`,
460
+ * data: error.issues,
461
+ * }),
462
+ * }),
463
+ * }),
464
+ * });
465
+ * ```
466
+ */
467
+ catchSchemaFailure?: SchemaFailureConverter<BaseQuery>
468
+
469
+ /**
470
+ * If set to `true`, will skip schema validation for this endpoint.
471
+ * Overrides the global setting.
472
+ *
473
+ * Can be overridden for specific schemas by passing an array of schema types to skip.
474
+ *
475
+ * @example
476
+ * ```ts
477
+ * // codeblock-meta no-transpile
478
+ * import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query/react';
479
+ * import * as v from 'valibot';
480
+ *
481
+ * interface Post {
482
+ * id: number;
483
+ * name: string;
484
+ * }
485
+ *
486
+ * const api = createApi({
487
+ * baseQuery: fetchBaseQuery({ baseUrl: '/' }),
488
+ * endpoints: (build) => ({
489
+ * getPost: build.query<Post, { id: number }>({
490
+ * query: ({ id }) => `/post/${id}`,
491
+ * responseSchema: v.object({ id: v.number(), name: v.string() }),
492
+ * skipSchemaValidation:
493
+ * process.env.NODE_ENV === 'test' ? ['response'] : false, // skip schema validation for response in tests, since we'll be mocking the response
494
+ * }),
495
+ * }),
496
+ * });
497
+ * ```
498
+ *
499
+ * @default false
500
+ */
501
+ skipSchemaValidation?: boolean | SchemaType[]
502
+ }
503
+
504
+ export type BaseEndpointDefinition<
505
+ QueryArg,
506
+ BaseQuery extends BaseQueryFn,
507
+ ResultType,
508
+ RawResultType extends BaseQueryResult<BaseQuery> = BaseQueryResult<BaseQuery>,
509
+ > = (
510
+ | ([CastAny<BaseQueryResult<BaseQuery>, {}>] extends [NEVER]
511
+ ? never
512
+ : EndpointDefinitionWithQuery<
513
+ QueryArg,
514
+ BaseQuery,
515
+ ResultType,
516
+ RawResultType
517
+ >)
518
+ | EndpointDefinitionWithQueryFn<QueryArg, BaseQuery, ResultType>
519
+ ) &
520
+ CommonEndpointDefinition<QueryArg, BaseQuery, ResultType> & {
521
+ /* phantom type */
522
+ [rawResultType]?: RawResultType
523
+ /* phantom type */
524
+ [resultType]?: ResultType
525
+ /* phantom type */
526
+ [baseQuery]?: BaseQuery
527
+ } & HasRequiredProps<
528
+ BaseQueryExtraOptions<BaseQuery>,
529
+ { extraOptions: BaseQueryExtraOptions<BaseQuery> },
530
+ { extraOptions?: BaseQueryExtraOptions<BaseQuery> }
531
+ >
532
+
533
+ // NOTE As with QueryStatus in `apiState.ts`, don't use this for real comparisons
534
+ // at runtime, use the string constants defined below.
535
+ export enum DefinitionType {
536
+ query = 'query',
537
+ mutation = 'mutation',
538
+ infinitequery = 'infinitequery',
539
+ }
540
+
541
+ export const ENDPOINT_QUERY = DefinitionType.query
542
+ export const ENDPOINT_MUTATION = DefinitionType.mutation
543
+ export const ENDPOINT_INFINITEQUERY = DefinitionType.infinitequery
544
+
545
+ type TagDescriptionArray<TagTypes extends string> = ReadonlyArray<
546
+ TagDescription<TagTypes> | undefined | null
547
+ >
548
+
549
+ export type GetResultDescriptionFn<
550
+ TagTypes extends string,
551
+ ResultType,
552
+ QueryArg,
553
+ ErrorType,
554
+ MetaType,
555
+ > = (
556
+ result: ResultType | undefined,
557
+ error: ErrorType | undefined,
558
+ arg: QueryArg,
559
+ meta: MetaType,
560
+ ) => TagDescriptionArray<TagTypes>
561
+
562
+ export type FullTagDescription<TagType> = {
563
+ type: TagType
564
+ id?: number | string
565
+ }
566
+ export type TagDescription<TagType> = TagType | FullTagDescription<TagType>
567
+
568
+ /**
569
+ * @public
570
+ */
571
+ export type ResultDescription<
572
+ TagTypes extends string,
573
+ ResultType,
574
+ QueryArg,
575
+ ErrorType,
576
+ MetaType,
577
+ > =
578
+ | TagDescriptionArray<TagTypes>
579
+ | GetResultDescriptionFn<TagTypes, ResultType, QueryArg, ErrorType, MetaType>
580
+
581
+ type QueryTypes<
582
+ QueryArg,
583
+ BaseQuery extends BaseQueryFn,
584
+ TagTypes extends string,
585
+ ResultType,
586
+ ReducerPath extends string = string,
587
+ RawResultType extends BaseQueryResult<BaseQuery> = BaseQueryResult<BaseQuery>,
588
+ > = BaseEndpointTypes<QueryArg, BaseQuery, ResultType, RawResultType> & {
589
+ /**
590
+ * The endpoint definition type. To be used with some internal generic types.
591
+ * @example
592
+ * ```ts
593
+ * const useMyWrappedHook: UseQuery<typeof api.endpoints.query.Types.QueryDefinition> = ...
594
+ * ```
595
+ */
596
+ QueryDefinition: QueryDefinition<
597
+ QueryArg,
598
+ BaseQuery,
599
+ TagTypes,
600
+ ResultType,
601
+ ReducerPath
602
+ >
603
+ TagTypes: TagTypes
604
+ ReducerPath: ReducerPath
605
+ }
606
+
607
+ /**
608
+ * @public
609
+ */
610
+ export interface QueryExtraOptions<
611
+ TagTypes extends string,
612
+ ResultType,
613
+ QueryArg,
614
+ BaseQuery extends BaseQueryFn,
615
+ ReducerPath extends string = string,
616
+ RawResultType extends BaseQueryResult<BaseQuery> = BaseQueryResult<BaseQuery>,
617
+ > extends CacheLifecycleQueryExtraOptions<
618
+ ResultType,
619
+ QueryArg,
620
+ BaseQuery,
621
+ ReducerPath
622
+ >,
623
+ QueryLifecycleQueryExtraOptions<
624
+ ResultType,
625
+ QueryArg,
626
+ BaseQuery,
627
+ ReducerPath
628
+ >,
629
+ CacheCollectionQueryExtraOptions {
630
+ type: DefinitionType.query
631
+
632
+ /**
633
+ * Used by `query` endpoints. Determines which 'tag' is attached to the cached data returned by the query.
634
+ * Expects an array of tag type strings, an array of objects of tag types with ids, or a function that returns such an array.
635
+ * 1. `['Post']` - equivalent to `2`
636
+ * 2. `[{ type: 'Post' }]` - equivalent to `1`
637
+ * 3. `[{ type: 'Post', id: 1 }]`
638
+ * 4. `(result, error, arg) => ['Post']` - equivalent to `5`
639
+ * 5. `(result, error, arg) => [{ type: 'Post' }]` - equivalent to `4`
640
+ * 6. `(result, error, arg) => [{ type: 'Post', id: 1 }]`
641
+ *
642
+ * @example
643
+ *
644
+ * ```ts
645
+ * // codeblock-meta title="providesTags example"
646
+ *
647
+ * import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query/react';
648
+ *
649
+ * interface Post {
650
+ * id: number;
651
+ * name: string;
652
+ * }
653
+ *
654
+ * type PostsResponse = Post[];
655
+ *
656
+ * const api = createApi({
657
+ * baseQuery: fetchBaseQuery({ baseUrl: '/' }),
658
+ * tagTypes: ['Posts'],
659
+ * endpoints: (build) => ({
660
+ * getPosts: build.query<PostsResponse, void>({
661
+ * query: () => 'posts',
662
+ * // highlight-start
663
+ * providesTags: (result) =>
664
+ * result
665
+ * ? [
666
+ * ...result.map(({ id }) => ({ type: 'Posts' as const, id })),
667
+ * { type: 'Posts', id: 'LIST' },
668
+ * ]
669
+ * : [{ type: 'Posts', id: 'LIST' }],
670
+ * // highlight-end
671
+ * }),
672
+ * }),
673
+ * });
674
+ * ```
675
+ */
676
+ providesTags?: ResultDescription<
677
+ TagTypes,
678
+ ResultType,
679
+ QueryArg,
680
+ BaseQueryError<BaseQuery>,
681
+ BaseQueryMeta<BaseQuery>
682
+ >
683
+ /**
684
+ * Not to be used. A query should not invalidate tags in the cache.
685
+ */
686
+ invalidatesTags?: never
687
+
688
+ /**
689
+ * Can be provided to return a custom cache key value based on the query arguments.
690
+ *
691
+ * This is primarily intended for cases where a non-serializable value is passed as part of the query arg object and should be excluded from the cache key. It may also be used for cases where an endpoint should only have a single cache entry, such as an infinite loading / pagination implementation.
692
+ *
693
+ * Unlike the `createApi` version which can _only_ return a string, this per-endpoint option can also return an an object, number, or boolean. If it returns a string, that value will be used as the cache key directly. If it returns an object / number / boolean, that value will be passed to the built-in `defaultSerializeQueryArgs`. This simplifies the use case of stripping out args you don't want included in the cache key.
694
+ *
695
+ *
696
+ * @example
697
+ *
698
+ * ```ts
699
+ * // codeblock-meta title="serializeQueryArgs : exclude value"
700
+ *
701
+ * import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query/react';
702
+ *
703
+ * interface Post {
704
+ * id: number;
705
+ * name: string;
706
+ * }
707
+ *
708
+ * interface MyApiClient {
709
+ * fetchPost: (id: string) => Promise<Post>;
710
+ * }
711
+ *
712
+ * createApi({
713
+ * baseQuery: fetchBaseQuery({ baseUrl: '/' }),
714
+ * endpoints: (build) => ({
715
+ * // Example: an endpoint with an API client passed in as an argument,
716
+ * // but only the item ID should be used as the cache key
717
+ * getPost: build.query<Post, { id: string; client: MyApiClient }>({
718
+ * queryFn: async ({ id, client }) => {
719
+ * const post = await client.fetchPost(id);
720
+ * return { data: post };
721
+ * },
722
+ * // highlight-start
723
+ * serializeQueryArgs: ({ queryArgs, endpointDefinition, endpointName }) => {
724
+ * const { id } = queryArgs;
725
+ * // This can return a string, an object, a number, or a boolean.
726
+ * // If it returns an object, number or boolean, that value
727
+ * // will be serialized automatically via `defaultSerializeQueryArgs`
728
+ * return { id }; // omit `client` from the cache key
729
+ *
730
+ * // Alternately, you can use `defaultSerializeQueryArgs` yourself:
731
+ * // return defaultSerializeQueryArgs({
732
+ * // endpointName,
733
+ * // queryArgs: { id },
734
+ * // endpointDefinition
735
+ * // })
736
+ * // Or create and return a string yourself:
737
+ * // return `getPost(${id})`
738
+ * },
739
+ * // highlight-end
740
+ * }),
741
+ * }),
742
+ * });
743
+ * ```
744
+ */
745
+ serializeQueryArgs?: SerializeQueryArgs<
746
+ QueryArg,
747
+ string | number | boolean | Record<any, any>
748
+ >
749
+
750
+ /**
751
+ * Can be provided to merge an incoming response value into the current cache data.
752
+ * If supplied, no automatic structural sharing will be applied - it's up to
753
+ * you to update the cache appropriately.
754
+ *
755
+ * Since RTKQ normally replaces cache entries with the new response, you will usually
756
+ * need to use this with the `serializeQueryArgs` or `forceRefetch` options to keep
757
+ * an existing cache entry so that it can be updated.
758
+ *
759
+ * Since this is wrapped with Immer, you may either mutate the `currentCacheValue` directly,
760
+ * or return a new value, but _not_ both at once.
761
+ *
762
+ * Will only be called if the existing `currentCacheData` is _not_ `undefined` - on first response,
763
+ * the cache entry will just save the response data directly.
764
+ *
765
+ * Useful if you don't want a new request to completely override the current cache value,
766
+ * maybe because you have manually updated it from another source and don't want those
767
+ * updates to get lost.
768
+ *
769
+ *
770
+ * @example
771
+ *
772
+ * ```ts
773
+ * // codeblock-meta title="merge: pagination"
774
+ *
775
+ * import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query/react';
776
+ *
777
+ * interface Post {
778
+ * id: number;
779
+ * name: string;
780
+ * }
781
+ *
782
+ * createApi({
783
+ * baseQuery: fetchBaseQuery({ baseUrl: '/' }),
784
+ * endpoints: (build) => ({
785
+ * listItems: build.query<string[], number>({
786
+ * query: (pageNumber) => `/listItems?page=${pageNumber}`,
787
+ * // Only have one cache entry because the arg always maps to one string
788
+ * serializeQueryArgs: ({ endpointName }) => {
789
+ * return endpointName;
790
+ * },
791
+ * // Always merge incoming data to the cache entry
792
+ * merge: (currentCache, newItems) => {
793
+ * currentCache.push(...newItems);
794
+ * },
795
+ * // Refetch when the page arg changes
796
+ * forceRefetch({ currentArg, previousArg }) {
797
+ * return currentArg !== previousArg;
798
+ * },
799
+ * }),
800
+ * }),
801
+ * });
802
+ * ```
803
+ */
804
+ merge?(
805
+ currentCacheData: ResultType,
806
+ responseData: ResultType,
807
+ otherArgs: {
808
+ arg: QueryArg
809
+ baseQueryMeta: BaseQueryMeta<BaseQuery>
810
+ requestId: string
811
+ fulfilledTimeStamp: number
812
+ },
813
+ ): ResultType | void
814
+
815
+ /**
816
+ * Check to see if the endpoint should force a refetch in cases where it normally wouldn't.
817
+ * This is primarily useful for "infinite scroll" / pagination use cases where
818
+ * RTKQ is keeping a single cache entry that is added to over time, in combination
819
+ * with `serializeQueryArgs` returning a fixed cache key and a `merge` callback
820
+ * set to add incoming data to the cache entry each time.
821
+ *
822
+ * @example
823
+ *
824
+ * ```ts
825
+ * // codeblock-meta title="forceRefresh: pagination"
826
+ * import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query/react';
827
+ *
828
+ * interface Post {
829
+ * id: number;
830
+ * name: string;
831
+ * }
832
+ *
833
+ * createApi({
834
+ * baseQuery: fetchBaseQuery({ baseUrl: '/' }),
835
+ * endpoints: (build) => ({
836
+ * listItems: build.query<string[], number>({
837
+ * query: (pageNumber) => `/listItems?page=${pageNumber}`,
838
+ * // Only have one cache entry because the arg always maps to one string
839
+ * serializeQueryArgs: ({ endpointName }) => {
840
+ * return endpointName;
841
+ * },
842
+ * // Always merge incoming data to the cache entry
843
+ * merge: (currentCache, newItems) => {
844
+ * currentCache.push(...newItems);
845
+ * },
846
+ * // Refetch when the page arg changes
847
+ * forceRefetch({ currentArg, previousArg }) {
848
+ * return currentArg !== previousArg;
849
+ * },
850
+ * }),
851
+ * }),
852
+ * });
853
+ * ```
854
+ */
855
+ forceRefetch?(params: {
856
+ currentArg: QueryArg | undefined
857
+ previousArg: QueryArg | undefined
858
+ state: RootState<any, any, string>
859
+ endpointState?: QuerySubState<any>
860
+ }): boolean
861
+
862
+ /**
863
+ * All of these are `undefined` at runtime, purely to be used in TypeScript declarations!
864
+ */
865
+ Types?: QueryTypes<
866
+ QueryArg,
867
+ BaseQuery,
868
+ TagTypes,
869
+ ResultType,
870
+ ReducerPath,
871
+ RawResultType
872
+ >
873
+ }
874
+
875
+ export type QueryDefinition<
876
+ QueryArg,
877
+ BaseQuery extends BaseQueryFn,
878
+ TagTypes extends string,
879
+ ResultType,
880
+ ReducerPath extends string = string,
881
+ RawResultType extends BaseQueryResult<BaseQuery> = BaseQueryResult<BaseQuery>,
882
+ > = BaseEndpointDefinition<QueryArg, BaseQuery, ResultType, RawResultType> &
883
+ QueryExtraOptions<
884
+ TagTypes,
885
+ ResultType,
886
+ QueryArg,
887
+ BaseQuery,
888
+ ReducerPath,
889
+ RawResultType
890
+ >
891
+
892
+ export type InfiniteQueryTypes<
893
+ QueryArg,
894
+ PageParam,
895
+ BaseQuery extends BaseQueryFn,
896
+ TagTypes extends string,
897
+ ResultType,
898
+ ReducerPath extends string = string,
899
+ RawResultType extends BaseQueryResult<BaseQuery> = BaseQueryResult<BaseQuery>,
900
+ > = BaseEndpointTypes<QueryArg, BaseQuery, ResultType, RawResultType> & {
901
+ /**
902
+ * The endpoint definition type. To be used with some internal generic types.
903
+ * @example
904
+ * ```ts
905
+ * const useMyWrappedHook: UseInfiniteQuery<typeof api.endpoints.query.Types.InfiniteQueryDefinition> = ...
906
+ * ```
907
+ */
908
+ InfiniteQueryDefinition: InfiniteQueryDefinition<
909
+ QueryArg,
910
+ PageParam,
911
+ BaseQuery,
912
+ TagTypes,
913
+ ResultType,
914
+ ReducerPath
915
+ >
916
+ TagTypes: TagTypes
917
+ ReducerPath: ReducerPath
918
+ }
919
+
920
+ export interface InfiniteQueryExtraOptions<
921
+ TagTypes extends string,
922
+ ResultType,
923
+ QueryArg,
924
+ PageParam,
925
+ BaseQuery extends BaseQueryFn,
926
+ ReducerPath extends string = string,
927
+ RawResultType extends BaseQueryResult<BaseQuery> = BaseQueryResult<BaseQuery>,
928
+ > extends CacheLifecycleInfiniteQueryExtraOptions<
929
+ InfiniteData<ResultType, PageParam>,
930
+ QueryArg,
931
+ BaseQuery,
932
+ ReducerPath
933
+ >,
934
+ QueryLifecycleInfiniteQueryExtraOptions<
935
+ InfiniteData<ResultType, PageParam>,
936
+ QueryArg,
937
+ BaseQuery,
938
+ ReducerPath
939
+ >,
940
+ CacheCollectionQueryExtraOptions {
941
+ type: DefinitionType.infinitequery
942
+
943
+ providesTags?: ResultDescription<
944
+ TagTypes,
945
+ InfiniteData<ResultType, PageParam>,
946
+ QueryArg,
947
+ BaseQueryError<BaseQuery>,
948
+ BaseQueryMeta<BaseQuery>
949
+ >
950
+ /**
951
+ * Not to be used. A query should not invalidate tags in the cache.
952
+ */
953
+ invalidatesTags?: never
954
+
955
+ /**
956
+ * Required options to configure the infinite query behavior.
957
+ * `initialPageParam` and `getNextPageParam` are required, to
958
+ * ensure the infinite query can properly fetch the next page of data.
959
+ * `initialPageParam` may be specified when using the
960
+ * endpoint, to override the default value.
961
+ * `maxPages` and `getPreviousPageParam` are both optional.
962
+ *
963
+ * @example
964
+ *
965
+ * ```ts
966
+ * // codeblock-meta title="infiniteQueryOptions example"
967
+ * import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query/react';
968
+ *
969
+ * type Pokemon = {
970
+ * id: string;
971
+ * name: string;
972
+ * };
973
+ *
974
+ * const pokemonApi = createApi({
975
+ * baseQuery: fetchBaseQuery({ baseUrl: 'https://pokeapi.co/api/v2/' }),
976
+ * endpoints: (build) => ({
977
+ * getInfinitePokemonWithMax: build.infiniteQuery<Pokemon[], string, number>({
978
+ * infiniteQueryOptions: {
979
+ * initialPageParam: 0,
980
+ * maxPages: 3,
981
+ * getNextPageParam: (lastPage, allPages, lastPageParam, allPageParams) =>
982
+ * lastPageParam + 1,
983
+ * getPreviousPageParam: (
984
+ * firstPage,
985
+ * allPages,
986
+ * firstPageParam,
987
+ * allPageParams,
988
+ * ) => {
989
+ * return firstPageParam > 0 ? firstPageParam - 1 : undefined;
990
+ * },
991
+ * },
992
+ * query({ pageParam }) {
993
+ * return `https://example.com/listItems?page=${pageParam}`;
994
+ * },
995
+ * }),
996
+ * }),
997
+ * });
998
+ * ```
999
+ */
1000
+ infiniteQueryOptions: InfiniteQueryConfigOptions<
1001
+ ResultType,
1002
+ PageParam,
1003
+ QueryArg
1004
+ >
1005
+
1006
+ /**
1007
+ * Can be provided to return a custom cache key value based on the query arguments.
1008
+ *
1009
+ * This is primarily intended for cases where a non-serializable value is passed as part of the query arg object and should be excluded from the cache key. It may also be used for cases where an endpoint should only have a single cache entry, such as an infinite loading / pagination implementation.
1010
+ *
1011
+ * Unlike the `createApi` version which can _only_ return a string, this per-endpoint option can also return an an object, number, or boolean. If it returns a string, that value will be used as the cache key directly. If it returns an object / number / boolean, that value will be passed to the built-in `defaultSerializeQueryArgs`. This simplifies the use case of stripping out args you don't want included in the cache key.
1012
+ *
1013
+ *
1014
+ * @example
1015
+ *
1016
+ * ```ts
1017
+ * // codeblock-meta title="serializeQueryArgs : exclude value"
1018
+ * import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query/react';
1019
+ *
1020
+ * interface Post {
1021
+ * id: number;
1022
+ * name: string;
1023
+ * }
1024
+ *
1025
+ * interface MyApiClient {
1026
+ * fetchPost: (id: string) => Promise<Post>;
1027
+ * }
1028
+ *
1029
+ * createApi({
1030
+ * baseQuery: fetchBaseQuery({ baseUrl: '/' }),
1031
+ * endpoints: (build) => ({
1032
+ * // Example: an endpoint with an API client passed in as an argument,
1033
+ * // but only the item ID should be used as the cache key
1034
+ * getPost: build.query<Post, { id: string; client: MyApiClient }>({
1035
+ * queryFn: async ({ id, client }) => {
1036
+ * const post = await client.fetchPost(id);
1037
+ * return { data: post };
1038
+ * },
1039
+ * // highlight-start
1040
+ * serializeQueryArgs: ({ queryArgs, endpointDefinition, endpointName }) => {
1041
+ * const { id } = queryArgs;
1042
+ * // This can return a string, an object, a number, or a boolean.
1043
+ * // If it returns an object, number or boolean, that value
1044
+ * // will be serialized automatically via `defaultSerializeQueryArgs`
1045
+ * return { id }; // omit `client` from the cache key
1046
+ *
1047
+ * // Alternately, you can use `defaultSerializeQueryArgs` yourself:
1048
+ * // return defaultSerializeQueryArgs({
1049
+ * // endpointName,
1050
+ * // queryArgs: { id },
1051
+ * // endpointDefinition
1052
+ * // })
1053
+ * // Or create and return a string yourself:
1054
+ * // return `getPost(${id})`
1055
+ * },
1056
+ * // highlight-end
1057
+ * }),
1058
+ * }),
1059
+ * });
1060
+ * ```
1061
+ */
1062
+ serializeQueryArgs?: SerializeQueryArgs<
1063
+ QueryArg,
1064
+ string | number | boolean | Record<any, any>
1065
+ >
1066
+
1067
+ /**
1068
+ * All of these are `undefined` at runtime, purely to be used in TypeScript declarations!
1069
+ */
1070
+ Types?: InfiniteQueryTypes<
1071
+ QueryArg,
1072
+ PageParam,
1073
+ BaseQuery,
1074
+ TagTypes,
1075
+ ResultType,
1076
+ ReducerPath,
1077
+ RawResultType
1078
+ >
1079
+ }
1080
+
1081
+ export type InfiniteQueryDefinition<
1082
+ QueryArg,
1083
+ PageParam,
1084
+ BaseQuery extends BaseQueryFn,
1085
+ TagTypes extends string,
1086
+ ResultType,
1087
+ ReducerPath extends string = string,
1088
+ RawResultType extends BaseQueryResult<BaseQuery> = BaseQueryResult<BaseQuery>,
1089
+ > =
1090
+ // Infinite query endpoints receive `{queryArg, pageParam}`
1091
+ BaseEndpointDefinition<
1092
+ InfiniteQueryCombinedArg<QueryArg, PageParam>,
1093
+ BaseQuery,
1094
+ ResultType,
1095
+ RawResultType
1096
+ > &
1097
+ InfiniteQueryExtraOptions<
1098
+ TagTypes,
1099
+ ResultType,
1100
+ QueryArg,
1101
+ PageParam,
1102
+ BaseQuery,
1103
+ ReducerPath,
1104
+ RawResultType
1105
+ >
1106
+
1107
+ type MutationTypes<
1108
+ QueryArg,
1109
+ BaseQuery extends BaseQueryFn,
1110
+ TagTypes extends string,
1111
+ ResultType,
1112
+ ReducerPath extends string = string,
1113
+ RawResultType extends BaseQueryResult<BaseQuery> = BaseQueryResult<BaseQuery>,
1114
+ > = BaseEndpointTypes<QueryArg, BaseQuery, ResultType, RawResultType> & {
1115
+ /**
1116
+ * The endpoint definition type. To be used with some internal generic types.
1117
+ * @example
1118
+ * ```ts
1119
+ * const useMyWrappedHook: UseMutation<typeof api.endpoints.query.Types.MutationDefinition> = ...
1120
+ * ```
1121
+ */
1122
+ MutationDefinition: MutationDefinition<
1123
+ QueryArg,
1124
+ BaseQuery,
1125
+ TagTypes,
1126
+ ResultType,
1127
+ ReducerPath
1128
+ >
1129
+ TagTypes: TagTypes
1130
+ ReducerPath: ReducerPath
1131
+ }
1132
+
1133
+ /**
1134
+ * @public
1135
+ */
1136
+ export interface MutationExtraOptions<
1137
+ TagTypes extends string,
1138
+ ResultType,
1139
+ QueryArg,
1140
+ BaseQuery extends BaseQueryFn,
1141
+ ReducerPath extends string = string,
1142
+ RawResultType extends BaseQueryResult<BaseQuery> = BaseQueryResult<BaseQuery>,
1143
+ > extends CacheLifecycleMutationExtraOptions<
1144
+ ResultType,
1145
+ QueryArg,
1146
+ BaseQuery,
1147
+ ReducerPath
1148
+ >,
1149
+ QueryLifecycleMutationExtraOptions<
1150
+ ResultType,
1151
+ QueryArg,
1152
+ BaseQuery,
1153
+ ReducerPath
1154
+ > {
1155
+ type: DefinitionType.mutation
1156
+
1157
+ /**
1158
+ * Used by `mutation` endpoints. Determines which cached data should be either re-fetched or removed from the cache.
1159
+ * Expects the same shapes as `providesTags`.
1160
+ *
1161
+ * @example
1162
+ *
1163
+ * ```ts
1164
+ * // codeblock-meta title="invalidatesTags example"
1165
+ * import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query/react';
1166
+ *
1167
+ * interface Post {
1168
+ * id: number;
1169
+ * name: string;
1170
+ * }
1171
+ *
1172
+ * type PostsResponse = Post[];
1173
+ *
1174
+ * const api = createApi({
1175
+ * baseQuery: fetchBaseQuery({ baseUrl: '/' }),
1176
+ * tagTypes: ['Posts'],
1177
+ * endpoints: (build) => ({
1178
+ * getPosts: build.query<PostsResponse, void>({
1179
+ * query: () => 'posts',
1180
+ * providesTags: (result) =>
1181
+ * result
1182
+ * ? [
1183
+ * ...result.map(({ id }) => ({ type: 'Posts' as const, id })),
1184
+ * { type: 'Posts', id: 'LIST' },
1185
+ * ]
1186
+ * : [{ type: 'Posts', id: 'LIST' }],
1187
+ * }),
1188
+ * addPost: build.mutation<Post, Partial<Post>>({
1189
+ * query(body) {
1190
+ * return {
1191
+ * url: `posts`,
1192
+ * method: 'POST',
1193
+ * body,
1194
+ * };
1195
+ * },
1196
+ * // highlight-start
1197
+ * invalidatesTags: [{ type: 'Posts', id: 'LIST' }],
1198
+ * // highlight-end
1199
+ * }),
1200
+ * }),
1201
+ * });
1202
+ * ```
1203
+ */
1204
+ invalidatesTags?: ResultDescription<
1205
+ TagTypes,
1206
+ ResultType,
1207
+ QueryArg,
1208
+ BaseQueryError<BaseQuery>,
1209
+ BaseQueryMeta<BaseQuery>
1210
+ >
1211
+ /**
1212
+ * Not to be used. A mutation should not provide tags to the cache.
1213
+ */
1214
+ providesTags?: never
1215
+
1216
+ /**
1217
+ * All of these are `undefined` at runtime, purely to be used in TypeScript declarations!
1218
+ */
1219
+ Types?: MutationTypes<
1220
+ QueryArg,
1221
+ BaseQuery,
1222
+ TagTypes,
1223
+ ResultType,
1224
+ ReducerPath,
1225
+ RawResultType
1226
+ >
1227
+ }
1228
+
1229
+ export type MutationDefinition<
1230
+ QueryArg,
1231
+ BaseQuery extends BaseQueryFn,
1232
+ TagTypes extends string,
1233
+ ResultType,
1234
+ ReducerPath extends string = string,
1235
+ RawResultType extends BaseQueryResult<BaseQuery> = BaseQueryResult<BaseQuery>,
1236
+ > = BaseEndpointDefinition<QueryArg, BaseQuery, ResultType, RawResultType> &
1237
+ MutationExtraOptions<
1238
+ TagTypes,
1239
+ ResultType,
1240
+ QueryArg,
1241
+ BaseQuery,
1242
+ ReducerPath,
1243
+ RawResultType
1244
+ >
1245
+
1246
+ export type EndpointDefinition<
1247
+ QueryArg,
1248
+ BaseQuery extends BaseQueryFn,
1249
+ TagTypes extends string,
1250
+ ResultType,
1251
+ ReducerPath extends string = string,
1252
+ PageParam = any,
1253
+ RawResultType extends BaseQueryResult<BaseQuery> = BaseQueryResult<BaseQuery>,
1254
+ > =
1255
+ | QueryDefinition<
1256
+ QueryArg,
1257
+ BaseQuery,
1258
+ TagTypes,
1259
+ ResultType,
1260
+ ReducerPath,
1261
+ RawResultType
1262
+ >
1263
+ | MutationDefinition<
1264
+ QueryArg,
1265
+ BaseQuery,
1266
+ TagTypes,
1267
+ ResultType,
1268
+ ReducerPath,
1269
+ RawResultType
1270
+ >
1271
+ | InfiniteQueryDefinition<
1272
+ QueryArg,
1273
+ PageParam,
1274
+ BaseQuery,
1275
+ TagTypes,
1276
+ ResultType,
1277
+ ReducerPath,
1278
+ RawResultType
1279
+ >
1280
+
1281
+ export type EndpointDefinitions = Record<
1282
+ string,
1283
+ EndpointDefinition<any, any, any, any, any, any, any>
1284
+ >
1285
+
1286
+ export function isQueryDefinition(
1287
+ e: EndpointDefinition<any, any, any, any, any, any, any>,
1288
+ ): e is QueryDefinition<any, any, any, any, any, any> {
1289
+ return e.type === ENDPOINT_QUERY
1290
+ }
1291
+
1292
+ export function isMutationDefinition(
1293
+ e: EndpointDefinition<any, any, any, any, any, any, any>,
1294
+ ): e is MutationDefinition<any, any, any, any, any, any> {
1295
+ return e.type === ENDPOINT_MUTATION
1296
+ }
1297
+
1298
+ export function isInfiniteQueryDefinition(
1299
+ e: EndpointDefinition<any, any, any, any, any, any, any>,
1300
+ ): e is InfiniteQueryDefinition<any, any, any, any, any, any, any> {
1301
+ return e.type === ENDPOINT_INFINITEQUERY
1302
+ }
1303
+
1304
+ export function isAnyQueryDefinition(
1305
+ e: EndpointDefinition<any, any, any, any>,
1306
+ ): e is
1307
+ | QueryDefinition<any, any, any, any>
1308
+ | InfiniteQueryDefinition<any, any, any, any, any> {
1309
+ return isQueryDefinition(e) || isInfiniteQueryDefinition(e)
1310
+ }
1311
+
1312
+ export type EndpointBuilder<
1313
+ BaseQuery extends BaseQueryFn,
1314
+ TagTypes extends string,
1315
+ ReducerPath extends string,
1316
+ > = {
1317
+ /**
1318
+ * An endpoint definition that retrieves data, and may provide tags to the cache.
1319
+ *
1320
+ * @example
1321
+ * ```ts
1322
+ * // codeblock-meta title="Example of all query endpoint options"
1323
+ * import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query/react';
1324
+ *
1325
+ * interface Post {
1326
+ * id: number;
1327
+ * name: string;
1328
+ * }
1329
+ *
1330
+ * interface PostsResponse {
1331
+ * data: Post[];
1332
+ * }
1333
+ *
1334
+ * const api = createApi({
1335
+ * baseQuery: fetchBaseQuery({ baseUrl: '/' }),
1336
+ * tagTypes: ['Post'],
1337
+ * endpoints: (build) => ({
1338
+ * getPost: build.query<Post[], number, PostsResponse>({
1339
+ * query: (id) => ({ url: `post/${id}` }),
1340
+ * // Pick out data and prevent nested properties in a hook or selector
1341
+ * transformResponse: (response) => response.data,
1342
+ * // Pick out error and prevent nested properties in a hook or selector
1343
+ * transformErrorResponse: (response) => response.status,
1344
+ * // `result` is the server response
1345
+ * providesTags: (result, error, id) => [{ type: 'Post', id }],
1346
+ * // trigger side effects or optimistic updates
1347
+ * onQueryStarted(
1348
+ * id,
1349
+ * {
1350
+ * dispatch,
1351
+ * getState,
1352
+ * extra,
1353
+ * requestId,
1354
+ * queryFulfilled,
1355
+ * getCacheEntry,
1356
+ * updateCachedData,
1357
+ * },
1358
+ * ) {},
1359
+ * // handle subscriptions etc
1360
+ * onCacheEntryAdded(
1361
+ * id,
1362
+ * {
1363
+ * dispatch,
1364
+ * getState,
1365
+ * extra,
1366
+ * requestId,
1367
+ * cacheEntryRemoved,
1368
+ * cacheDataLoaded,
1369
+ * getCacheEntry,
1370
+ * updateCachedData,
1371
+ * },
1372
+ * ) {},
1373
+ * }),
1374
+ * }),
1375
+ * });
1376
+ * ```
1377
+ */
1378
+ query<
1379
+ ResultType,
1380
+ QueryArg,
1381
+ RawResultType extends
1382
+ BaseQueryResult<BaseQuery> = BaseQueryResult<BaseQuery>,
1383
+ >(
1384
+ definition: OmitFromUnion<
1385
+ QueryDefinition<
1386
+ QueryArg,
1387
+ BaseQuery,
1388
+ TagTypes,
1389
+ ResultType,
1390
+ ReducerPath,
1391
+ RawResultType
1392
+ >,
1393
+ 'type'
1394
+ >,
1395
+ ): QueryDefinition<
1396
+ QueryArg,
1397
+ BaseQuery,
1398
+ TagTypes,
1399
+ ResultType,
1400
+ ReducerPath,
1401
+ RawResultType
1402
+ >
1403
+
1404
+ /**
1405
+ * An endpoint definition that alters data on the server or will possibly invalidate the cache.
1406
+ *
1407
+ * @example
1408
+ * ```ts
1409
+ * // codeblock-meta title="Example of all mutation endpoint options"
1410
+ * import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query/react';
1411
+ *
1412
+ * interface Post {
1413
+ * id: number;
1414
+ * name: string;
1415
+ * }
1416
+ *
1417
+ * interface PostsResponse {
1418
+ * data: Post[];
1419
+ * }
1420
+ *
1421
+ * const api = createApi({
1422
+ * baseQuery: fetchBaseQuery({ baseUrl: '/' }),
1423
+ * tagTypes: ['Post'],
1424
+ * endpoints: (build) => ({
1425
+ * updatePost: build.mutation<Post[], Partial<Post>, PostsResponse>({
1426
+ * query: ({ id, ...patch }) => ({
1427
+ * url: `post/${id}`,
1428
+ * method: 'PATCH',
1429
+ * body: patch,
1430
+ * }),
1431
+ * // Pick out data and prevent nested properties in a hook or selector
1432
+ * transformResponse: (response) => response.data,
1433
+ * // Pick out error and prevent nested properties in a hook or selector
1434
+ * transformErrorResponse: (response) => response.status,
1435
+ * // `result` is the server response
1436
+ * invalidatesTags: (result, error, { id }) => [{ type: 'Post', id }],
1437
+ * // trigger side effects or optimistic updates
1438
+ * onQueryStarted(
1439
+ * { id },
1440
+ * { dispatch, getState, extra, requestId, queryFulfilled, getCacheEntry },
1441
+ * ) {},
1442
+ * // handle subscriptions etc
1443
+ * onCacheEntryAdded(
1444
+ * { id },
1445
+ * {
1446
+ * dispatch,
1447
+ * getState,
1448
+ * extra,
1449
+ * requestId,
1450
+ * cacheEntryRemoved,
1451
+ * cacheDataLoaded,
1452
+ * getCacheEntry,
1453
+ * },
1454
+ * ) {},
1455
+ * }),
1456
+ * }),
1457
+ * });
1458
+ * ```
1459
+ */
1460
+ mutation<
1461
+ ResultType,
1462
+ QueryArg,
1463
+ RawResultType extends
1464
+ BaseQueryResult<BaseQuery> = BaseQueryResult<BaseQuery>,
1465
+ >(
1466
+ definition: OmitFromUnion<
1467
+ MutationDefinition<
1468
+ QueryArg,
1469
+ BaseQuery,
1470
+ TagTypes,
1471
+ ResultType,
1472
+ ReducerPath,
1473
+ RawResultType
1474
+ >,
1475
+ 'type'
1476
+ >,
1477
+ ): MutationDefinition<
1478
+ QueryArg,
1479
+ BaseQuery,
1480
+ TagTypes,
1481
+ ResultType,
1482
+ ReducerPath,
1483
+ RawResultType
1484
+ >
1485
+
1486
+ infiniteQuery<
1487
+ ResultType,
1488
+ QueryArg,
1489
+ PageParam,
1490
+ RawResultType extends
1491
+ BaseQueryResult<BaseQuery> = BaseQueryResult<BaseQuery>,
1492
+ >(
1493
+ definition: OmitFromUnion<
1494
+ InfiniteQueryDefinition<
1495
+ QueryArg,
1496
+ PageParam,
1497
+ BaseQuery,
1498
+ TagTypes,
1499
+ ResultType,
1500
+ ReducerPath,
1501
+ RawResultType
1502
+ >,
1503
+ 'type'
1504
+ >,
1505
+ ): InfiniteQueryDefinition<
1506
+ QueryArg,
1507
+ PageParam,
1508
+ BaseQuery,
1509
+ TagTypes,
1510
+ ResultType,
1511
+ ReducerPath,
1512
+ RawResultType
1513
+ >
1514
+ }
1515
+
1516
+ export type AssertTagTypes = <T extends FullTagDescription<string>>(t: T) => T
1517
+
1518
+ export function calculateProvidedBy<ResultType, QueryArg, ErrorType, MetaType>(
1519
+ description:
1520
+ | ResultDescription<string, ResultType, QueryArg, ErrorType, MetaType>
1521
+ | undefined,
1522
+ result: ResultType | undefined,
1523
+ error: ErrorType | undefined,
1524
+ queryArg: QueryArg,
1525
+ meta: MetaType | undefined,
1526
+ assertTagTypes: AssertTagTypes,
1527
+ ): readonly FullTagDescription<string>[] {
1528
+ const finalDescription = isFunction(description)
1529
+ ? description(
1530
+ result as ResultType,
1531
+ error as undefined,
1532
+ queryArg,
1533
+ meta as MetaType,
1534
+ )
1535
+ : description
1536
+
1537
+ if (finalDescription) {
1538
+ return filterMap(finalDescription, isNotNullish, (tag) =>
1539
+ assertTagTypes(expandTagDescription(tag)),
1540
+ )
1541
+ }
1542
+
1543
+ return []
1544
+ }
1545
+
1546
+ function isFunction<T>(t: T): t is Extract<T, Function> {
1547
+ return typeof t === 'function'
1548
+ }
1549
+
1550
+ export function expandTagDescription(
1551
+ description: TagDescription<string>,
1552
+ ): FullTagDescription<string> {
1553
+ return typeof description === 'string' ? { type: description } : description
1554
+ }
1555
+
1556
+ export type QueryArgFrom<D extends BaseEndpointDefinition<any, any, any, any>> =
1557
+ D extends BaseEndpointDefinition<infer QA, any, any, any> ? QA : never
1558
+
1559
+ // Just extracting `QueryArg` from `BaseEndpointDefinition`
1560
+ // doesn't sufficiently match here.
1561
+ // We need to explicitly match against `InfiniteQueryDefinition`
1562
+ export type InfiniteQueryArgFrom<
1563
+ D extends BaseEndpointDefinition<any, any, any, any>,
1564
+ > =
1565
+ D extends InfiniteQueryDefinition<infer QA, any, any, any, any, any, any>
1566
+ ? QA
1567
+ : never
1568
+
1569
+ export type QueryArgFromAnyQuery<
1570
+ D extends BaseEndpointDefinition<any, any, any, any>,
1571
+ > =
1572
+ D extends InfiniteQueryDefinition<any, any, any, any, any, any, any>
1573
+ ? InfiniteQueryArgFrom<D>
1574
+ : D extends QueryDefinition<any, any, any, any, any, any>
1575
+ ? QueryArgFrom<D>
1576
+ : never
1577
+
1578
+ export type ResultTypeFrom<
1579
+ D extends BaseEndpointDefinition<any, any, any, any>,
1580
+ > = D extends BaseEndpointDefinition<any, any, infer RT, any> ? RT : unknown
1581
+
1582
+ export type ReducerPathFrom<
1583
+ D extends EndpointDefinition<any, any, any, any, any, any, any>,
1584
+ > =
1585
+ D extends EndpointDefinition<any, any, any, any, infer RP, any, any>
1586
+ ? RP
1587
+ : unknown
1588
+
1589
+ export type TagTypesFrom<
1590
+ D extends EndpointDefinition<any, any, any, any, any, any, any>,
1591
+ > =
1592
+ D extends EndpointDefinition<any, any, infer TT, any, any, any, any>
1593
+ ? TT
1594
+ : unknown
1595
+
1596
+ export type PageParamFrom<
1597
+ D extends InfiniteQueryDefinition<any, any, any, any, any, any, any>,
1598
+ > =
1599
+ D extends InfiniteQueryDefinition<any, infer PP, any, any, any, any, any>
1600
+ ? PP
1601
+ : unknown
1602
+
1603
+ export type InfiniteQueryCombinedArg<QueryArg, PageParam> = {
1604
+ queryArg: QueryArg
1605
+ pageParam: PageParam
1606
+ }
1607
+
1608
+ export type TagTypesFromApi<T> =
1609
+ T extends Api<any, any, any, infer TagTypes> ? TagTypes : never
1610
+
1611
+ export type DefinitionsFromApi<T> =
1612
+ T extends Api<any, infer Definitions, any, any> ? Definitions : never
1613
+
1614
+ export type TransformedResponse<
1615
+ NewDefinitions extends EndpointDefinitions,
1616
+ K,
1617
+ ResultType,
1618
+ > = K extends keyof NewDefinitions
1619
+ ? NewDefinitions[K]['transformResponse'] extends undefined
1620
+ ? ResultType
1621
+ : UnwrapPromise<
1622
+ ReturnType<NonUndefined<NewDefinitions[K]['transformResponse']>>
1623
+ >
1624
+ : ResultType
1625
+
1626
+ export type OverrideResultType<Definition, NewResultType> =
1627
+ Definition extends QueryDefinition<
1628
+ infer QueryArg,
1629
+ infer BaseQuery,
1630
+ infer TagTypes,
1631
+ any,
1632
+ infer ReducerPath
1633
+ >
1634
+ ? QueryDefinition<QueryArg, BaseQuery, TagTypes, NewResultType, ReducerPath>
1635
+ : Definition extends MutationDefinition<
1636
+ infer QueryArg,
1637
+ infer BaseQuery,
1638
+ infer TagTypes,
1639
+ any,
1640
+ infer ReducerPath
1641
+ >
1642
+ ? MutationDefinition<
1643
+ QueryArg,
1644
+ BaseQuery,
1645
+ TagTypes,
1646
+ NewResultType,
1647
+ ReducerPath
1648
+ >
1649
+ : Definition extends InfiniteQueryDefinition<
1650
+ infer QueryArg,
1651
+ infer PageParam,
1652
+ infer BaseQuery,
1653
+ infer TagTypes,
1654
+ any,
1655
+ infer ReducerPath
1656
+ >
1657
+ ? InfiniteQueryDefinition<
1658
+ QueryArg,
1659
+ PageParam,
1660
+ BaseQuery,
1661
+ TagTypes,
1662
+ NewResultType,
1663
+ ReducerPath
1664
+ >
1665
+ : never
1666
+
1667
+ export type UpdateDefinitions<
1668
+ Definitions extends EndpointDefinitions,
1669
+ NewTagTypes extends string,
1670
+ NewDefinitions extends EndpointDefinitions,
1671
+ > = {
1672
+ [K in keyof Definitions]: Definitions[K] extends QueryDefinition<
1673
+ infer QueryArg,
1674
+ infer BaseQuery,
1675
+ any,
1676
+ infer ResultType,
1677
+ infer ReducerPath
1678
+ >
1679
+ ? QueryDefinition<
1680
+ QueryArg,
1681
+ BaseQuery,
1682
+ NewTagTypes,
1683
+ TransformedResponse<NewDefinitions, K, ResultType>,
1684
+ ReducerPath
1685
+ >
1686
+ : Definitions[K] extends MutationDefinition<
1687
+ infer QueryArg,
1688
+ infer BaseQuery,
1689
+ any,
1690
+ infer ResultType,
1691
+ infer ReducerPath
1692
+ >
1693
+ ? MutationDefinition<
1694
+ QueryArg,
1695
+ BaseQuery,
1696
+ NewTagTypes,
1697
+ TransformedResponse<NewDefinitions, K, ResultType>,
1698
+ ReducerPath
1699
+ >
1700
+ : Definitions[K] extends InfiniteQueryDefinition<
1701
+ infer QueryArg,
1702
+ infer PageParam,
1703
+ infer BaseQuery,
1704
+ any,
1705
+ infer ResultType,
1706
+ infer ReducerPath
1707
+ >
1708
+ ? InfiniteQueryDefinition<
1709
+ QueryArg,
1710
+ PageParam,
1711
+ BaseQuery,
1712
+ NewTagTypes,
1713
+ TransformedResponse<NewDefinitions, K, ResultType>,
1714
+ ReducerPath
1715
+ >
1716
+ : never
1717
+ }