endpointDefinitions.d.ts 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540
  1. import type { AnyAction, ThunkDispatch } from '@reduxjs/toolkit';
  2. import type { SerializeQueryArgs } from './defaultSerializeQueryArgs';
  3. import type { QuerySubState, RootState } from './core/apiState';
  4. import type { BaseQueryExtraOptions, BaseQueryFn, BaseQueryResult, BaseQueryArg, BaseQueryApi, QueryReturnValue, BaseQueryError, BaseQueryMeta } from './baseQueryTypes';
  5. import type { HasRequiredProps, MaybePromise, OmitFromUnion, CastAny, NonUndefined, UnwrapPromise } from './tsHelpers';
  6. import type { NEVER } from './fakeBaseQuery';
  7. import type { Api } from '@reduxjs/toolkit/query';
  8. declare const resultType: unique symbol;
  9. declare const baseQuery: unique symbol;
  10. interface EndpointDefinitionWithQuery<QueryArg, BaseQuery extends BaseQueryFn, ResultType> {
  11. /**
  12. * `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.
  13. *
  14. * @example
  15. *
  16. * ```ts
  17. * // codeblock-meta title="query example"
  18. *
  19. * import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query/react'
  20. * interface Post {
  21. * id: number
  22. * name: string
  23. * }
  24. * type PostsResponse = Post[]
  25. *
  26. * const api = createApi({
  27. * baseQuery: fetchBaseQuery({ baseUrl: '/' }),
  28. * tagTypes: ['Post'],
  29. * endpoints: (build) => ({
  30. * getPosts: build.query<PostsResponse, void>({
  31. * // highlight-start
  32. * query: () => 'posts',
  33. * // highlight-end
  34. * }),
  35. * addPost: build.mutation<Post, Partial<Post>>({
  36. * // highlight-start
  37. * query: (body) => ({
  38. * url: `posts`,
  39. * method: 'POST',
  40. * body,
  41. * }),
  42. * // highlight-end
  43. * invalidatesTags: [{ type: 'Post', id: 'LIST' }],
  44. * }),
  45. * })
  46. * })
  47. * ```
  48. */
  49. query(arg: QueryArg): BaseQueryArg<BaseQuery>;
  50. queryFn?: never;
  51. /**
  52. * A function to manipulate the data returned by a query or mutation.
  53. */
  54. transformResponse?(baseQueryReturnValue: BaseQueryResult<BaseQuery>, meta: BaseQueryMeta<BaseQuery>, arg: QueryArg): ResultType | Promise<ResultType>;
  55. /**
  56. * A function to manipulate the data returned by a failed query or mutation.
  57. */
  58. transformErrorResponse?(baseQueryReturnValue: BaseQueryError<BaseQuery>, meta: BaseQueryMeta<BaseQuery>, arg: QueryArg): unknown;
  59. /**
  60. * Defaults to `true`.
  61. *
  62. * Most apps should leave this setting on. The only time it can be a performance issue
  63. * is if an API returns extremely large amounts of data (e.g. 10,000 rows per request) and
  64. * you're unable to paginate it.
  65. *
  66. * For details of how this works, please see the below. When it is set to `false`,
  67. * every request will cause subscribed components to rerender, even when the data has not changed.
  68. *
  69. * @see https://redux-toolkit.js.org/api/other-exports#copywithstructuralsharing
  70. */
  71. structuralSharing?: boolean;
  72. }
  73. interface EndpointDefinitionWithQueryFn<QueryArg, BaseQuery extends BaseQueryFn, ResultType> {
  74. /**
  75. * Can be used in place of `query` as an inline function that bypasses `baseQuery` completely for the endpoint.
  76. *
  77. * @example
  78. * ```ts
  79. * // codeblock-meta title="Basic queryFn example"
  80. *
  81. * import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query/react'
  82. * interface Post {
  83. * id: number
  84. * name: string
  85. * }
  86. * type PostsResponse = Post[]
  87. *
  88. * const api = createApi({
  89. * baseQuery: fetchBaseQuery({ baseUrl: '/' }),
  90. * endpoints: (build) => ({
  91. * getPosts: build.query<PostsResponse, void>({
  92. * query: () => 'posts',
  93. * }),
  94. * flipCoin: build.query<'heads' | 'tails', void>({
  95. * // highlight-start
  96. * queryFn(arg, queryApi, extraOptions, baseQuery) {
  97. * const randomVal = Math.random()
  98. * if (randomVal < 0.45) {
  99. * return { data: 'heads' }
  100. * }
  101. * if (randomVal < 0.9) {
  102. * return { data: 'tails' }
  103. * }
  104. * return { error: { status: 500, statusText: 'Internal Server Error', data: "Coin landed on it's edge!" } }
  105. * }
  106. * // highlight-end
  107. * })
  108. * })
  109. * })
  110. * ```
  111. */
  112. queryFn(arg: QueryArg, api: BaseQueryApi, extraOptions: BaseQueryExtraOptions<BaseQuery>, baseQuery: (arg: Parameters<BaseQuery>[0]) => ReturnType<BaseQuery>): MaybePromise<QueryReturnValue<ResultType, BaseQueryError<BaseQuery>>>;
  113. query?: never;
  114. transformResponse?: never;
  115. transformErrorResponse?: never;
  116. /**
  117. * Defaults to `true`.
  118. *
  119. * Most apps should leave this setting on. The only time it can be a performance issue
  120. * is if an API returns extremely large amounts of data (e.g. 10,000 rows per request) and
  121. * you're unable to paginate it.
  122. *
  123. * For details of how this works, please see the below. When it is set to `false`,
  124. * every request will cause subscribed components to rerender, even when the data has not changed.
  125. *
  126. * @see https://redux-toolkit.js.org/api/other-exports#copywithstructuralsharing
  127. */
  128. structuralSharing?: boolean;
  129. }
  130. export interface BaseEndpointTypes<QueryArg, BaseQuery extends BaseQueryFn, ResultType> {
  131. QueryArg: QueryArg;
  132. BaseQuery: BaseQuery;
  133. ResultType: ResultType;
  134. }
  135. export declare type BaseEndpointDefinition<QueryArg, BaseQuery extends BaseQueryFn, ResultType> = (([CastAny<BaseQueryResult<BaseQuery>, {}>] extends [NEVER] ? never : EndpointDefinitionWithQuery<QueryArg, BaseQuery, ResultType>) | EndpointDefinitionWithQueryFn<QueryArg, BaseQuery, ResultType>) & {
  136. [resultType]?: ResultType;
  137. [baseQuery]?: BaseQuery;
  138. } & HasRequiredProps<BaseQueryExtraOptions<BaseQuery>, {
  139. extraOptions: BaseQueryExtraOptions<BaseQuery>;
  140. }, {
  141. extraOptions?: BaseQueryExtraOptions<BaseQuery>;
  142. }>;
  143. export declare enum DefinitionType {
  144. query = "query",
  145. mutation = "mutation"
  146. }
  147. export declare type GetResultDescriptionFn<TagTypes extends string, ResultType, QueryArg, ErrorType, MetaType> = (result: ResultType | undefined, error: ErrorType | undefined, arg: QueryArg, meta: MetaType) => ReadonlyArray<TagDescription<TagTypes>>;
  148. export declare type FullTagDescription<TagType> = {
  149. type: TagType;
  150. id?: number | string;
  151. };
  152. export declare type TagDescription<TagType> = TagType | FullTagDescription<TagType>;
  153. export declare type ResultDescription<TagTypes extends string, ResultType, QueryArg, ErrorType, MetaType> = ReadonlyArray<TagDescription<TagTypes>> | GetResultDescriptionFn<TagTypes, ResultType, QueryArg, ErrorType, MetaType>;
  154. /** @deprecated please use `onQueryStarted` instead */
  155. export interface QueryApi<ReducerPath extends string, Context extends {}> {
  156. /** @deprecated please use `onQueryStarted` instead */
  157. dispatch: ThunkDispatch<any, any, AnyAction>;
  158. /** @deprecated please use `onQueryStarted` instead */
  159. getState(): RootState<any, any, ReducerPath>;
  160. /** @deprecated please use `onQueryStarted` instead */
  161. extra: unknown;
  162. /** @deprecated please use `onQueryStarted` instead */
  163. requestId: string;
  164. /** @deprecated please use `onQueryStarted` instead */
  165. context: Context;
  166. }
  167. export interface QueryTypes<QueryArg, BaseQuery extends BaseQueryFn, TagTypes extends string, ResultType, ReducerPath extends string = string> extends BaseEndpointTypes<QueryArg, BaseQuery, ResultType> {
  168. /**
  169. * The endpoint definition type. To be used with some internal generic types.
  170. * @example
  171. * ```ts
  172. * const useMyWrappedHook: UseQuery<typeof api.endpoints.query.Types.QueryDefinition> = ...
  173. * ```
  174. */
  175. QueryDefinition: QueryDefinition<QueryArg, BaseQuery, TagTypes, ResultType, ReducerPath>;
  176. TagTypes: TagTypes;
  177. ReducerPath: ReducerPath;
  178. }
  179. export interface QueryExtraOptions<TagTypes extends string, ResultType, QueryArg, BaseQuery extends BaseQueryFn, ReducerPath extends string = string> {
  180. type: DefinitionType.query;
  181. /**
  182. * Used by `query` endpoints. Determines which 'tag' is attached to the cached data returned by the query.
  183. * Expects an array of tag type strings, an array of objects of tag types with ids, or a function that returns such an array.
  184. * 1. `['Post']` - equivalent to `2`
  185. * 2. `[{ type: 'Post' }]` - equivalent to `1`
  186. * 3. `[{ type: 'Post', id: 1 }]`
  187. * 4. `(result, error, arg) => ['Post']` - equivalent to `5`
  188. * 5. `(result, error, arg) => [{ type: 'Post' }]` - equivalent to `4`
  189. * 6. `(result, error, arg) => [{ type: 'Post', id: 1 }]`
  190. *
  191. * @example
  192. *
  193. * ```ts
  194. * // codeblock-meta title="providesTags example"
  195. *
  196. * import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query/react'
  197. * interface Post {
  198. * id: number
  199. * name: string
  200. * }
  201. * type PostsResponse = Post[]
  202. *
  203. * const api = createApi({
  204. * baseQuery: fetchBaseQuery({ baseUrl: '/' }),
  205. * tagTypes: ['Posts'],
  206. * endpoints: (build) => ({
  207. * getPosts: build.query<PostsResponse, void>({
  208. * query: () => 'posts',
  209. * // highlight-start
  210. * providesTags: (result) =>
  211. * result
  212. * ? [
  213. * ...result.map(({ id }) => ({ type: 'Posts' as const, id })),
  214. * { type: 'Posts', id: 'LIST' },
  215. * ]
  216. * : [{ type: 'Posts', id: 'LIST' }],
  217. * // highlight-end
  218. * })
  219. * })
  220. * })
  221. * ```
  222. */
  223. providesTags?: ResultDescription<TagTypes, ResultType, QueryArg, BaseQueryError<BaseQuery>, BaseQueryMeta<BaseQuery>>;
  224. /**
  225. * Not to be used. A query should not invalidate tags in the cache.
  226. */
  227. invalidatesTags?: never;
  228. /**
  229. * Can be provided to return a custom cache key value based on the query arguments.
  230. *
  231. * 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.
  232. *
  233. * 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.
  234. *
  235. *
  236. * @example
  237. *
  238. * ```ts
  239. * // codeblock-meta title="serializeQueryArgs : exclude value"
  240. *
  241. * import { createApi, fetchBaseQuery, defaultSerializeQueryArgs } from '@reduxjs/toolkit/query/react'
  242. * interface Post {
  243. * id: number
  244. * name: string
  245. * }
  246. *
  247. * interface MyApiClient {
  248. * fetchPost: (id: string) => Promise<Post>
  249. * }
  250. *
  251. * createApi({
  252. * baseQuery: fetchBaseQuery({ baseUrl: '/' }),
  253. * endpoints: (build) => ({
  254. * // Example: an endpoint with an API client passed in as an argument,
  255. * // but only the item ID should be used as the cache key
  256. * getPost: build.query<Post, { id: string; client: MyApiClient }>({
  257. * queryFn: async ({ id, client }) => {
  258. * const post = await client.fetchPost(id)
  259. * return { data: post }
  260. * },
  261. * // highlight-start
  262. * serializeQueryArgs: ({ queryArgs, endpointDefinition, endpointName }) => {
  263. * const { id } = queryArgs
  264. * // This can return a string, an object, a number, or a boolean.
  265. * // If it returns an object, number or boolean, that value
  266. * // will be serialized automatically via `defaultSerializeQueryArgs`
  267. * return { id } // omit `client` from the cache key
  268. *
  269. * // Alternately, you can use `defaultSerializeQueryArgs` yourself:
  270. * // return defaultSerializeQueryArgs({
  271. * // endpointName,
  272. * // queryArgs: { id },
  273. * // endpointDefinition
  274. * // })
  275. * // Or create and return a string yourself:
  276. * // return `getPost(${id})`
  277. * },
  278. * // highlight-end
  279. * }),
  280. * }),
  281. *})
  282. * ```
  283. */
  284. serializeQueryArgs?: SerializeQueryArgs<QueryArg, string | number | boolean | Record<any, any>>;
  285. /**
  286. * Can be provided to merge an incoming response value into the current cache data.
  287. * If supplied, no automatic structural sharing will be applied - it's up to
  288. * you to update the cache appropriately.
  289. *
  290. * Since RTKQ normally replaces cache entries with the new response, you will usually
  291. * need to use this with the `serializeQueryArgs` or `forceRefetch` options to keep
  292. * an existing cache entry so that it can be updated.
  293. *
  294. * Since this is wrapped with Immer, you may either mutate the `currentCacheValue` directly,
  295. * or return a new value, but _not_ both at once.
  296. *
  297. * Will only be called if the existing `currentCacheData` is _not_ `undefined` - on first response,
  298. * the cache entry will just save the response data directly.
  299. *
  300. * Useful if you don't want a new request to completely override the current cache value,
  301. * maybe because you have manually updated it from another source and don't want those
  302. * updates to get lost.
  303. *
  304. *
  305. * @example
  306. *
  307. * ```ts
  308. * // codeblock-meta title="merge: pagination"
  309. *
  310. * import { createApi, fetchBaseQuery, defaultSerializeQueryArgs } from '@reduxjs/toolkit/query/react'
  311. * interface Post {
  312. * id: number
  313. * name: string
  314. * }
  315. *
  316. * createApi({
  317. * baseQuery: fetchBaseQuery({ baseUrl: '/' }),
  318. * endpoints: (build) => ({
  319. * listItems: build.query<string[], number>({
  320. * query: (pageNumber) => `/listItems?page=${pageNumber}`,
  321. * // Only have one cache entry because the arg always maps to one string
  322. * serializeQueryArgs: ({ endpointName }) => {
  323. * return endpointName
  324. * },
  325. * // Always merge incoming data to the cache entry
  326. * merge: (currentCache, newItems) => {
  327. * currentCache.push(...newItems)
  328. * },
  329. * // Refetch when the page arg changes
  330. * forceRefetch({ currentArg, previousArg }) {
  331. * return currentArg !== previousArg
  332. * },
  333. * }),
  334. * }),
  335. *})
  336. * ```
  337. */
  338. merge?(currentCacheData: ResultType, responseData: ResultType, otherArgs: {
  339. arg: QueryArg;
  340. baseQueryMeta: BaseQueryMeta<BaseQuery>;
  341. requestId: string;
  342. fulfilledTimeStamp: number;
  343. }): ResultType | void;
  344. /**
  345. * Check to see if the endpoint should force a refetch in cases where it normally wouldn't.
  346. * This is primarily useful for "infinite scroll" / pagination use cases where
  347. * RTKQ is keeping a single cache entry that is added to over time, in combination
  348. * with `serializeQueryArgs` returning a fixed cache key and a `merge` callback
  349. * set to add incoming data to the cache entry each time.
  350. *
  351. * @example
  352. *
  353. * ```ts
  354. * // codeblock-meta title="forceRefresh: pagination"
  355. *
  356. * import { createApi, fetchBaseQuery, defaultSerializeQueryArgs } from '@reduxjs/toolkit/query/react'
  357. * interface Post {
  358. * id: number
  359. * name: string
  360. * }
  361. *
  362. * createApi({
  363. * baseQuery: fetchBaseQuery({ baseUrl: '/' }),
  364. * endpoints: (build) => ({
  365. * listItems: build.query<string[], number>({
  366. * query: (pageNumber) => `/listItems?page=${pageNumber}`,
  367. * // Only have one cache entry because the arg always maps to one string
  368. * serializeQueryArgs: ({ endpointName }) => {
  369. * return endpointName
  370. * },
  371. * // Always merge incoming data to the cache entry
  372. * merge: (currentCache, newItems) => {
  373. * currentCache.push(...newItems)
  374. * },
  375. * // Refetch when the page arg changes
  376. * forceRefetch({ currentArg, previousArg }) {
  377. * return currentArg !== previousArg
  378. * },
  379. * }),
  380. * }),
  381. *})
  382. * ```
  383. */
  384. forceRefetch?(params: {
  385. currentArg: QueryArg | undefined;
  386. previousArg: QueryArg | undefined;
  387. state: RootState<any, any, string>;
  388. endpointState?: QuerySubState<any>;
  389. }): boolean;
  390. /**
  391. * All of these are `undefined` at runtime, purely to be used in TypeScript declarations!
  392. */
  393. Types?: QueryTypes<QueryArg, BaseQuery, TagTypes, ResultType, ReducerPath>;
  394. }
  395. export declare type QueryDefinition<QueryArg, BaseQuery extends BaseQueryFn, TagTypes extends string, ResultType, ReducerPath extends string = string> = BaseEndpointDefinition<QueryArg, BaseQuery, ResultType> & QueryExtraOptions<TagTypes, ResultType, QueryArg, BaseQuery, ReducerPath>;
  396. export interface MutationTypes<QueryArg, BaseQuery extends BaseQueryFn, TagTypes extends string, ResultType, ReducerPath extends string = string> extends BaseEndpointTypes<QueryArg, BaseQuery, ResultType> {
  397. /**
  398. * The endpoint definition type. To be used with some internal generic types.
  399. * @example
  400. * ```ts
  401. * const useMyWrappedHook: UseMutation<typeof api.endpoints.query.Types.MutationDefinition> = ...
  402. * ```
  403. */
  404. MutationDefinition: MutationDefinition<QueryArg, BaseQuery, TagTypes, ResultType, ReducerPath>;
  405. TagTypes: TagTypes;
  406. ReducerPath: ReducerPath;
  407. }
  408. export interface MutationExtraOptions<TagTypes extends string, ResultType, QueryArg, BaseQuery extends BaseQueryFn, ReducerPath extends string = string> {
  409. type: DefinitionType.mutation;
  410. /**
  411. * Used by `mutation` endpoints. Determines which cached data should be either re-fetched or removed from the cache.
  412. * Expects the same shapes as `providesTags`.
  413. *
  414. * @example
  415. *
  416. * ```ts
  417. * // codeblock-meta title="invalidatesTags example"
  418. * import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query/react'
  419. * interface Post {
  420. * id: number
  421. * name: string
  422. * }
  423. * type PostsResponse = Post[]
  424. *
  425. * const api = createApi({
  426. * baseQuery: fetchBaseQuery({ baseUrl: '/' }),
  427. * tagTypes: ['Posts'],
  428. * endpoints: (build) => ({
  429. * getPosts: build.query<PostsResponse, void>({
  430. * query: () => 'posts',
  431. * providesTags: (result) =>
  432. * result
  433. * ? [
  434. * ...result.map(({ id }) => ({ type: 'Posts' as const, id })),
  435. * { type: 'Posts', id: 'LIST' },
  436. * ]
  437. * : [{ type: 'Posts', id: 'LIST' }],
  438. * }),
  439. * addPost: build.mutation<Post, Partial<Post>>({
  440. * query(body) {
  441. * return {
  442. * url: `posts`,
  443. * method: 'POST',
  444. * body,
  445. * }
  446. * },
  447. * // highlight-start
  448. * invalidatesTags: [{ type: 'Posts', id: 'LIST' }],
  449. * // highlight-end
  450. * }),
  451. * })
  452. * })
  453. * ```
  454. */
  455. invalidatesTags?: ResultDescription<TagTypes, ResultType, QueryArg, BaseQueryError<BaseQuery>, BaseQueryMeta<BaseQuery>>;
  456. /**
  457. * Not to be used. A mutation should not provide tags to the cache.
  458. */
  459. providesTags?: never;
  460. /**
  461. * All of these are `undefined` at runtime, purely to be used in TypeScript declarations!
  462. */
  463. Types?: MutationTypes<QueryArg, BaseQuery, TagTypes, ResultType, ReducerPath>;
  464. }
  465. export declare type MutationDefinition<QueryArg, BaseQuery extends BaseQueryFn, TagTypes extends string, ResultType, ReducerPath extends string = string> = BaseEndpointDefinition<QueryArg, BaseQuery, ResultType> & MutationExtraOptions<TagTypes, ResultType, QueryArg, BaseQuery, ReducerPath>;
  466. export declare type EndpointDefinition<QueryArg, BaseQuery extends BaseQueryFn, TagTypes extends string, ResultType, ReducerPath extends string = string> = QueryDefinition<QueryArg, BaseQuery, TagTypes, ResultType, ReducerPath> | MutationDefinition<QueryArg, BaseQuery, TagTypes, ResultType, ReducerPath>;
  467. export declare type EndpointDefinitions = Record<string, EndpointDefinition<any, any, any, any>>;
  468. export declare function isQueryDefinition(e: EndpointDefinition<any, any, any, any>): e is QueryDefinition<any, any, any, any>;
  469. export declare function isMutationDefinition(e: EndpointDefinition<any, any, any, any>): e is MutationDefinition<any, any, any, any>;
  470. export declare type EndpointBuilder<BaseQuery extends BaseQueryFn, TagTypes extends string, ReducerPath extends string> = {
  471. /**
  472. * An endpoint definition that retrieves data, and may provide tags to the cache.
  473. *
  474. * @example
  475. * ```js
  476. * // codeblock-meta title="Example of all query endpoint options"
  477. * const api = createApi({
  478. * baseQuery,
  479. * endpoints: (build) => ({
  480. * getPost: build.query({
  481. * query: (id) => ({ url: `post/${id}` }),
  482. * // Pick out data and prevent nested properties in a hook or selector
  483. * transformResponse: (response) => response.data,
  484. * // Pick out error and prevent nested properties in a hook or selector
  485. * transformErrorResponse: (response) => response.error,
  486. * // `result` is the server response
  487. * providesTags: (result, error, id) => [{ type: 'Post', id }],
  488. * // trigger side effects or optimistic updates
  489. * onQueryStarted(id, { dispatch, getState, extra, requestId, queryFulfilled, getCacheEntry, updateCachedData }) {},
  490. * // handle subscriptions etc
  491. * onCacheEntryAdded(id, { dispatch, getState, extra, requestId, cacheEntryRemoved, cacheDataLoaded, getCacheEntry, updateCachedData }) {},
  492. * }),
  493. * }),
  494. *});
  495. *```
  496. */
  497. query<ResultType, QueryArg>(definition: OmitFromUnion<QueryDefinition<QueryArg, BaseQuery, TagTypes, ResultType, ReducerPath>, 'type'>): QueryDefinition<QueryArg, BaseQuery, TagTypes, ResultType, ReducerPath>;
  498. /**
  499. * An endpoint definition that alters data on the server or will possibly invalidate the cache.
  500. *
  501. * @example
  502. * ```js
  503. * // codeblock-meta title="Example of all mutation endpoint options"
  504. * const api = createApi({
  505. * baseQuery,
  506. * endpoints: (build) => ({
  507. * updatePost: build.mutation({
  508. * query: ({ id, ...patch }) => ({ url: `post/${id}`, method: 'PATCH', body: patch }),
  509. * // Pick out data and prevent nested properties in a hook or selector
  510. * transformResponse: (response) => response.data,
  511. * // Pick out error and prevent nested properties in a hook or selector
  512. * transformErrorResponse: (response) => response.error,
  513. * // `result` is the server response
  514. * invalidatesTags: (result, error, id) => [{ type: 'Post', id }],
  515. * // trigger side effects or optimistic updates
  516. * onQueryStarted(id, { dispatch, getState, extra, requestId, queryFulfilled, getCacheEntry }) {},
  517. * // handle subscriptions etc
  518. * onCacheEntryAdded(id, { dispatch, getState, extra, requestId, cacheEntryRemoved, cacheDataLoaded, getCacheEntry }) {},
  519. * }),
  520. * }),
  521. * });
  522. * ```
  523. */
  524. mutation<ResultType, QueryArg>(definition: OmitFromUnion<MutationDefinition<QueryArg, BaseQuery, TagTypes, ResultType, ReducerPath>, 'type'>): MutationDefinition<QueryArg, BaseQuery, TagTypes, ResultType, ReducerPath>;
  525. };
  526. export declare type AssertTagTypes = <T extends FullTagDescription<string>>(t: T) => T;
  527. export declare function calculateProvidedBy<ResultType, QueryArg, ErrorType, MetaType>(description: ResultDescription<string, ResultType, QueryArg, ErrorType, MetaType> | undefined, result: ResultType | undefined, error: ErrorType | undefined, queryArg: QueryArg, meta: MetaType | undefined, assertTagTypes: AssertTagTypes): readonly FullTagDescription<string>[];
  528. export declare function expandTagDescription(description: TagDescription<string>): FullTagDescription<string>;
  529. export declare type QueryArgFrom<D extends BaseEndpointDefinition<any, any, any>> = D extends BaseEndpointDefinition<infer QA, any, any> ? QA : unknown;
  530. export declare type ResultTypeFrom<D extends BaseEndpointDefinition<any, any, any>> = D extends BaseEndpointDefinition<any, any, infer RT> ? RT : unknown;
  531. export declare type ReducerPathFrom<D extends EndpointDefinition<any, any, any, any, any>> = D extends EndpointDefinition<any, any, any, any, infer RP> ? RP : unknown;
  532. export declare type TagTypesFrom<D extends EndpointDefinition<any, any, any, any>> = D extends EndpointDefinition<any, any, infer RP, any> ? RP : unknown;
  533. export declare type TagTypesFromApi<T> = T extends Api<any, any, any, infer TagTypes> ? TagTypes : never;
  534. export declare type DefinitionsFromApi<T> = T extends Api<any, infer Definitions, any, any> ? Definitions : never;
  535. export declare type TransformedResponse<NewDefinitions extends EndpointDefinitions, K, ResultType> = K extends keyof NewDefinitions ? NewDefinitions[K]['transformResponse'] extends undefined ? ResultType : UnwrapPromise<ReturnType<NonUndefined<NewDefinitions[K]['transformResponse']>>> : ResultType;
  536. export declare type OverrideResultType<Definition, NewResultType> = Definition extends QueryDefinition<infer QueryArg, infer BaseQuery, infer TagTypes, any, infer ReducerPath> ? QueryDefinition<QueryArg, BaseQuery, TagTypes, NewResultType, ReducerPath> : Definition extends MutationDefinition<infer QueryArg, infer BaseQuery, infer TagTypes, any, infer ReducerPath> ? MutationDefinition<QueryArg, BaseQuery, TagTypes, NewResultType, ReducerPath> : never;
  537. export declare type UpdateDefinitions<Definitions extends EndpointDefinitions, NewTagTypes extends string, NewDefinitions extends EndpointDefinitions> = {
  538. [K in keyof Definitions]: Definitions[K] extends QueryDefinition<infer QueryArg, infer BaseQuery, any, infer ResultType, infer ReducerPath> ? QueryDefinition<QueryArg, BaseQuery, NewTagTypes, TransformedResponse<NewDefinitions, K, ResultType>, ReducerPath> : Definitions[K] extends MutationDefinition<infer QueryArg, infer BaseQuery, any, infer ResultType, infer ReducerPath> ? MutationDefinition<QueryArg, BaseQuery, NewTagTypes, TransformedResponse<NewDefinitions, K, ResultType>, ReducerPath> : never;
  539. };
  540. export {};