@tramvai/react-query 2.29.0 → 2.32.0

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.
package/README.md CHANGED
@@ -5,7 +5,7 @@ sidebar_position: 5
5
5
 
6
6
  # React Query
7
7
 
8
- A library for handling requests in React components. Based on [react-query](https://react-query.tanstack.com/).
8
+ A library for handling requests in React components. Based on [@tanstack/react-query](https://tanstack.com/query/v4/).
9
9
 
10
10
  ## Explanation
11
11
 
@@ -86,7 +86,7 @@ const query = createQuery({
86
86
 
87
87
  #### Unique query parameters
88
88
 
89
- To create a generic `query` that takes parameters for a query, you must return a unique `key`, you can read more about this in the official documentation section [Query Keys](https://react-query.tanstack.com/guides/query-keys)
89
+ To create a generic `query` that takes parameters for a query, you must return a unique `key`, you can read more about this in the official documentation section [Query Keys](https://tanstack.com/query/v4/docs/guides/query-keys)
90
90
 
91
91
  As a parameter `key` you can use:
92
92
 
@@ -121,7 +121,7 @@ export function Component({ id }) {
121
121
 
122
122
  React hook for working with `Query` object
123
123
 
124
- [react-query docs](https://react-query.tanstack.com/reference/useQuery)
124
+ [react-query docs](https://tanstack.com/query/v4/docs/reference/useQuery)
125
125
 
126
126
  ```ts
127
127
  import { useQuery } from '@tramvai/react-query';
@@ -137,7 +137,7 @@ export function Component() {
137
137
 
138
138
  React Hook for working with the list of `Query` objects
139
139
 
140
- [react-query docs](https://react-query.tanstack.com/reference/useQueries)
140
+ [react-query docs](https://tanstack.com/query/v4/docs/reference/useQueries)
141
141
 
142
142
  ```ts
143
143
  import { useQueries } from '@tramvai/react-query';
@@ -189,7 +189,7 @@ const query = createInfiniteQuery({
189
189
 
190
190
  React hook for working with the `InfiniteQuery` object
191
191
 
192
- [react-query docs](https://react-query.tanstack.com/reference/useInfiniteQuery)
192
+ [react-query docs](https://tanstack.com/query/v4/docs/reference/useInfiniteQuery)
193
193
 
194
194
  ```ts
195
195
  import { useInfiniteQuery } from '@tramvai/react-query';
@@ -248,7 +248,7 @@ const mutation = createMutation({
248
248
 
249
249
  React hook for working with the `Mutation` object
250
250
 
251
- [react-query docs](https://react-query.tanstack.com/reference/useMutation)
251
+ [react-query docs](https://tanstack.com/query/v4/docs/reference/useMutation)
252
252
 
253
253
  ```ts
254
254
  import { useMutation } from '@tramvai/react-query';
@@ -276,6 +276,6 @@ export function Component() {
276
276
 
277
277
  :::warning Prefer to use methods from the `@tramvai/react-query` as it is can work both with the `Query` wrapper and the query options to `react-query` itself :::
278
278
 
279
- You can get [`QueryClient`](https://react-query.tanstack.com/reference/QueryClient) from di by token `QUERY_CLIENT_TOKEN` or using method `useQueryClient` in React-components.
279
+ You can get [`QueryClient`](https://tanstack.com/query/v4/docs/reference/QueryClient) from di by token `QUERY_CLIENT_TOKEN` or using method `useQueryClient` in React-components.
280
280
 
281
281
  To convert wrapped `Query` object to object acceptable by `react-query` use method [raw](#raw) of the `Query` instance.
@@ -1,7 +1,8 @@
1
1
  import type { ActionConditionsParameters, ActionContext, TramvaiAction } from '@tramvai/core';
2
- import type { QueryKey as ReactQueryKey, QueryOptions } from 'react-query';
2
+ import type { QueryKey as ReactQueryKey, QueryOptions } from '@tanstack/react-query';
3
3
  export declare const QUERY_PARAMETERS = "__query_parameters__";
4
- export declare type QueryKey<Options> = ((options: Options) => ReactQueryKey) | ReactQueryKey;
4
+ export declare type ReactQueryKeyOrString = ReactQueryKey | string;
5
+ export declare type QueryKey<Options> = ((options: Options) => ReactQueryKeyOrString) | ReactQueryKeyOrString;
5
6
  export interface BaseCreateQueryOptions<Options, Deps> {
6
7
  key: QueryKey<Options>;
7
8
  fn: Function;
package/lib/index.d.ts CHANGED
@@ -4,4 +4,4 @@ export { createInfiniteQuery } from './infiniteQuery/create';
4
4
  export { useInfiniteQuery } from './infiniteQuery/use';
5
5
  export { createMutation } from './mutation/create';
6
6
  export { useMutation } from './mutation/use';
7
- export { useQueryClient } from 'react-query';
7
+ export { useQueryClient } from '@tanstack/react-query';
package/lib/index.es.js CHANGED
@@ -1,12 +1,12 @@
1
+ import identity from '@tinkoff/utils/function/identity';
1
2
  import applyOrReturn from '@tinkoff/utils/function/applyOrReturn';
2
3
  import { declareAction } from '@tramvai/core';
3
4
  import { QUERY_CLIENT_TOKEN } from '@tramvai/module-react-query';
4
5
  import { CONTEXT_TOKEN } from '@tramvai/tokens-common';
5
- import isString from '@tinkoff/utils/is/string';
6
6
  import isArray from '@tinkoff/utils/is/array';
7
7
  import { useMemo } from 'react';
8
- import { useQuery as useQuery$1, useQueries as useQueries$1, useInfiniteQuery as useInfiniteQuery$1, useMutation as useMutation$1 } from 'react-query';
9
- export { useQueryClient } from 'react-query';
8
+ import { useQuery as useQuery$1, useQueries as useQueries$1, useInfiniteQuery as useInfiniteQuery$1, useMutation as useMutation$1 } from '@tanstack/react-query';
9
+ export { useQueryClient } from '@tanstack/react-query';
10
10
  import { useConsumerContext } from '@tramvai/state';
11
11
  import { useShallowEqual } from '@tinkoff/react-hooks';
12
12
 
@@ -15,16 +15,16 @@ const isQuery = (arg) => {
15
15
  return QUERY_PARAMETERS in arg;
16
16
  };
17
17
 
18
- const defaultKey = (options) => {
19
- if (isString(options) || isArray(options)) {
20
- return options;
18
+ const normalizeKey = (key) => {
19
+ if (isArray(key)) {
20
+ return key;
21
21
  }
22
- return [options];
22
+ return [key];
23
23
  };
24
24
 
25
25
  const convertToRawQuery$1 = (query, context, options) => {
26
- const { key = defaultKey, fn, deps, conditions, queryOptions } = query[QUERY_PARAMETERS];
27
- const queryKey = applyOrReturn([options], key);
26
+ const { key = identity, fn, deps, conditions, queryOptions } = query[QUERY_PARAMETERS];
27
+ const queryKey = normalizeKey(applyOrReturn([options], key));
28
28
  const actionWrapper = declareAction({
29
29
  name: 'queryExecution',
30
30
  async fn() {
@@ -112,12 +112,12 @@ function useQueries(queries) {
112
112
  return query;
113
113
  });
114
114
  }, [memoQueries, context]);
115
- return useQueries$1(resultQueries);
115
+ return useQueries$1({ queries: resultQueries });
116
116
  }
117
117
 
118
118
  const convertToRawQuery = (query, context, options) => {
119
- const { key = defaultKey, fn, getNextPageParam, getPreviousPageParam, deps, conditions, infiniteQueryOptions, } = query[QUERY_PARAMETERS];
120
- const queryKey = applyOrReturn([options], key);
119
+ const { key = identity, fn, getNextPageParam, getPreviousPageParam, deps, conditions, infiniteQueryOptions, } = query[QUERY_PARAMETERS];
120
+ const queryKey = normalizeKey(applyOrReturn([options], key));
121
121
  const actionWrapper = declareAction({
122
122
  name: 'infiniteQueryExecution',
123
123
  async fn(pageParam) {
@@ -203,8 +203,8 @@ const isMutation = (arg) => {
203
203
  };
204
204
 
205
205
  const convertToRawMutation = (mutation, context, options) => {
206
- const { key = defaultKey, fn, deps, conditions, mutationOptions } = mutation[MUTATION_PARAMETERS];
207
- const mutationKey = applyOrReturn([options], key);
206
+ const { key = identity, fn, deps, conditions, mutationOptions } = mutation[MUTATION_PARAMETERS];
207
+ const mutationKey = normalizeKey(applyOrReturn([options], key));
208
208
  const actionWrapper = declareAction({
209
209
  name: 'mutationExecution',
210
210
  async fn(variables) {
package/lib/index.js CHANGED
@@ -2,21 +2,21 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
+ var identity = require('@tinkoff/utils/function/identity');
5
6
  var applyOrReturn = require('@tinkoff/utils/function/applyOrReturn');
6
7
  var core = require('@tramvai/core');
7
8
  var moduleReactQuery = require('@tramvai/module-react-query');
8
9
  var tokensCommon = require('@tramvai/tokens-common');
9
- var isString = require('@tinkoff/utils/is/string');
10
10
  var isArray = require('@tinkoff/utils/is/array');
11
11
  var react = require('react');
12
- var reactQuery = require('react-query');
12
+ var reactQuery = require('@tanstack/react-query');
13
13
  var state = require('@tramvai/state');
14
14
  var reactHooks = require('@tinkoff/react-hooks');
15
15
 
16
16
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
17
17
 
18
+ var identity__default = /*#__PURE__*/_interopDefaultLegacy(identity);
18
19
  var applyOrReturn__default = /*#__PURE__*/_interopDefaultLegacy(applyOrReturn);
19
- var isString__default = /*#__PURE__*/_interopDefaultLegacy(isString);
20
20
  var isArray__default = /*#__PURE__*/_interopDefaultLegacy(isArray);
21
21
 
22
22
  const QUERY_PARAMETERS = '__query_parameters__';
@@ -24,16 +24,16 @@ const isQuery = (arg) => {
24
24
  return QUERY_PARAMETERS in arg;
25
25
  };
26
26
 
27
- const defaultKey = (options) => {
28
- if (isString__default["default"](options) || isArray__default["default"](options)) {
29
- return options;
27
+ const normalizeKey = (key) => {
28
+ if (isArray__default["default"](key)) {
29
+ return key;
30
30
  }
31
- return [options];
31
+ return [key];
32
32
  };
33
33
 
34
34
  const convertToRawQuery$1 = (query, context, options) => {
35
- const { key = defaultKey, fn, deps, conditions, queryOptions } = query[QUERY_PARAMETERS];
36
- const queryKey = applyOrReturn__default["default"]([options], key);
35
+ const { key = identity__default["default"], fn, deps, conditions, queryOptions } = query[QUERY_PARAMETERS];
36
+ const queryKey = normalizeKey(applyOrReturn__default["default"]([options], key));
37
37
  const actionWrapper = core.declareAction({
38
38
  name: 'queryExecution',
39
39
  async fn() {
@@ -121,12 +121,12 @@ function useQueries(queries) {
121
121
  return query;
122
122
  });
123
123
  }, [memoQueries, context]);
124
- return reactQuery.useQueries(resultQueries);
124
+ return reactQuery.useQueries({ queries: resultQueries });
125
125
  }
126
126
 
127
127
  const convertToRawQuery = (query, context, options) => {
128
- const { key = defaultKey, fn, getNextPageParam, getPreviousPageParam, deps, conditions, infiniteQueryOptions, } = query[QUERY_PARAMETERS];
129
- const queryKey = applyOrReturn__default["default"]([options], key);
128
+ const { key = identity__default["default"], fn, getNextPageParam, getPreviousPageParam, deps, conditions, infiniteQueryOptions, } = query[QUERY_PARAMETERS];
129
+ const queryKey = normalizeKey(applyOrReturn__default["default"]([options], key));
130
130
  const actionWrapper = core.declareAction({
131
131
  name: 'infiniteQueryExecution',
132
132
  async fn(pageParam) {
@@ -212,8 +212,8 @@ const isMutation = (arg) => {
212
212
  };
213
213
 
214
214
  const convertToRawMutation = (mutation, context, options) => {
215
- const { key = defaultKey, fn, deps, conditions, mutationOptions } = mutation[MUTATION_PARAMETERS];
216
- const mutationKey = applyOrReturn__default["default"]([options], key);
215
+ const { key = identity__default["default"], fn, deps, conditions, mutationOptions } = mutation[MUTATION_PARAMETERS];
216
+ const mutationKey = normalizeKey(applyOrReturn__default["default"]([options], key));
217
217
  const actionWrapper = core.declareAction({
218
218
  name: 'mutationExecution',
219
219
  async fn(variables) {
@@ -1,5 +1,5 @@
1
1
  import type { ProvideDepsIterator } from '@tinkoff/dippy';
2
- import type { UseInfiniteQueryOptions, InfiniteData } from 'react-query';
2
+ import type { UseInfiniteQueryOptions, InfiniteData } from '@tanstack/react-query';
3
3
  import type { TramvaiAction } from '@tramvai/core';
4
4
  import type { BaseCreateQueryOptions, BaseQuery } from '../baseQuery/types';
5
5
  export interface CreateInfiniteQueryOptions<Options, PageParam, Result, Deps> extends BaseCreateQueryOptions<Options, Deps> {
@@ -1,4 +1,4 @@
1
- import type { InfiniteQueryObserverResult, UseInfiniteQueryOptions } from 'react-query';
1
+ import type { InfiniteQueryObserverResult, UseInfiniteQueryOptions } from '@tanstack/react-query';
2
2
  import type { InfiniteQuery } from './types';
3
3
  declare function useInfiniteQuery<Options extends void, PageParam, Result, Deps>(query: UseInfiniteQueryOptions<Result, Error> | InfiniteQuery<Options, PageParam, Result, Deps>): InfiniteQueryObserverResult<Result, Error>;
4
4
  declare function useInfiniteQuery<Options, PageParam, Result, Deps>(query: UseInfiniteQueryOptions<Result, Error> | InfiniteQuery<Options, PageParam, Result, Deps>, options: Options): InfiniteQueryObserverResult<Result, Error>;
@@ -1,6 +1,6 @@
1
1
  import type { ActionConditionsParameters, ActionContext } from '@tramvai/core';
2
2
  import type { ProvideDepsIterator } from '@tinkoff/dippy';
3
- import type { MutationKey as ReactMutationKey, MutationOptions, UseMutationOptions } from 'react-query';
3
+ import type { MutationKey as ReactMutationKey, MutationOptions, UseMutationOptions } from '@tanstack/react-query';
4
4
  export declare const MUTATION_PARAMETERS = "__mutations_parameters__";
5
5
  export declare type MutationKey<Options> = ((options?: Options) => ReactMutationKey) | ReactMutationKey;
6
6
  export interface CreateMutationOptions<Options, Variables, Result, Deps, Key extends MutationKey<Options> = (options?: Options) => ReactMutationKey> {
@@ -1,4 +1,4 @@
1
- import type { UseMutationOptions, UseMutationResult, MutationKey as ReactMutationKey } from 'react-query';
1
+ import type { UseMutationOptions, UseMutationResult, MutationKey as ReactMutationKey } from '@tanstack/react-query';
2
2
  import type { Mutation } from './types';
3
3
  interface UseMutation {
4
4
  <Options, Variables, Result, Deps, Key extends (options?: Options) => ReactMutationKey>(Mutation: UseMutationOptions<Result, any, Variables> | Mutation<Options, Variables, Result, Deps, Key>, options: Options): UseMutationResult<Result, any, Variables>;
@@ -1,5 +1,5 @@
1
1
  import type { ProvideDepsIterator } from '@tinkoff/dippy';
2
- import type { UseQueryOptions } from 'react-query';
2
+ import type { UseQueryOptions } from '@tanstack/react-query';
3
3
  import type { TramvaiAction } from '@tramvai/core';
4
4
  import type { BaseCreateQueryOptions, BaseQuery } from '../baseQuery/types';
5
5
  export interface CreateQueryOptions<Options, Result, Deps> extends BaseCreateQueryOptions<Options, Deps> {
@@ -1,6 +1,6 @@
1
- import type { UseQueryOptions, QueryObserverResult } from 'react-query';
1
+ import type { UseQueryOptions, QueryObserverResult } from '@tanstack/react-query';
2
2
  import type { Query } from './types';
3
3
  declare function useQuery<Options extends void, Result, Deps>(query: UseQueryOptions<Result, Error> | Query<Options, Result, Deps>): QueryObserverResult<Result, Error>;
4
4
  declare function useQuery<Options, Result, Deps>(query: UseQueryOptions<Result, Error> | Query<Options, Result, Deps>, options: Options): QueryObserverResult<Result, Error>;
5
- declare function useQueries<Result, Deps>(queries: Array<UseQueryOptions<Result, Error> | Query<any, Result, Deps>>): import("react-query").UseQueryResult<unknown extends Result ? Result : Result, Error>[];
5
+ declare function useQueries<Result, Deps>(queries: Array<UseQueryOptions<Result, Error> | Query<any, Result, Deps>>): import("@tanstack/react-query").UseQueryResult<unknown extends Result ? Result : Result, Error>[];
6
6
  export { useQuery, useQueries };
@@ -0,0 +1,3 @@
1
+ import type { QueryKey } from '@tanstack/react-query';
2
+ import type { ReactQueryKeyOrString } from '../baseQuery/types';
3
+ export declare const normalizeKey: (key: ReactQueryKeyOrString) => QueryKey;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tramvai/react-query",
3
- "version": "2.29.0",
3
+ "version": "2.32.0",
4
4
  "description": "",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
@@ -19,16 +19,16 @@
19
19
  },
20
20
  "dependencies": {
21
21
  "@tinkoff/react-hooks": "0.1.3",
22
- "@tramvai/core": "2.29.0",
23
- "@tramvai/module-react-query": "2.29.0",
24
- "@tramvai/state": "2.29.0",
25
- "@tramvai/tokens-common": "2.29.0"
22
+ "@tramvai/core": "2.32.0",
23
+ "@tramvai/module-react-query": "2.32.0",
24
+ "@tramvai/state": "2.32.0",
25
+ "@tramvai/tokens-common": "2.32.0"
26
26
  },
27
27
  "peerDependencies": {
28
28
  "@tinkoff/dippy": "0.8.6",
29
29
  "@tinkoff/utils": "^2.1.2",
30
30
  "react": ">=16.14.0",
31
- "react-query": "^3.35.0",
31
+ "@tanstack/react-query": "^4.7.1",
32
32
  "tslib": "^2.4.0"
33
33
  },
34
34
  "module": "lib/index.es.js",
@@ -1,2 +0,0 @@
1
- import type { QueryKey as ReactQueryKey } from 'react-query';
2
- export declare const defaultKey: (options: any) => ReactQueryKey;