@tramvai/react-query 2.146.0 → 2.147.1

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.
@@ -11,6 +11,7 @@ export type ReactQueryKeyOrString = ReactQueryKey | string;
11
11
  export type QueryKey<Options, Deps extends ProviderDeps> = ((this: ReactQueryContext<Deps>, options: Options) => ReactQueryKeyOrString) | ReactQueryKeyOrString;
12
12
  export interface BaseCreateQueryOptions<Options, Deps extends ProviderDeps> {
13
13
  key: QueryKey<Options, Deps>;
14
+ actionNamePostfix?: string;
14
15
  fn: Function;
15
16
  deps?: Deps;
16
17
  conditions?: ActionConditionsParameters;
@@ -24,5 +25,6 @@ export interface BaseQuery<Options, TCreateQuery, TQuery, TUseQuery> {
24
25
  */
25
26
  raw(context: ActionContext, options?: Options): TUseQuery;
26
27
  prefetchAction(options?: Options): TramvaiAction<[], Promise<void>, any>;
28
+ actionNamePostfix: string;
27
29
  }
28
30
  export declare const isQuery: <Options, Result, TCreateQuery, TQuery, TUseQuery>(arg: BaseQuery<Options, TCreateQuery, TQuery, TUseQuery> | QueryOptions<Result, any, any, any>) => arg is BaseQuery<Options, TCreateQuery, TQuery, TUseQuery>;
@@ -1,12 +1,13 @@
1
1
  import identity from '@tinkoff/utils/function/identity';
2
2
  import { declareAction } from '@tramvai/core';
3
3
  import { QUERY_CLIENT_TOKEN } from '@tramvai/module-react-query';
4
- import { CONTEXT_TOKEN } from '@tramvai/tokens-common';
4
+ import { LOGGER_TOKEN, CONTEXT_TOKEN } from '@tramvai/tokens-common';
5
5
  import { DI_TOKEN } from '@tinkoff/dippy';
6
6
  import { QUERY_PARAMETERS } from '../baseQuery/types.es.js';
7
7
  import { normalizeKey } from '../shared/normalizeKey.es.js';
8
8
  import { resolveDI } from '../shared/resolveDI.es.js';
9
9
  import { mapQuerySignalToxecutionContext } from '../shared/signal.es.js';
10
+ import { createUniqueActionKeyForQuery } from '../shared/createUniqueActionKeyForQuery.es.js';
10
11
 
11
12
  const convertToRawQuery = (query, di, options) => {
12
13
  const { key = identity, fn, getNextPageParam, getPreviousPageParam, deps = {}, conditions, infiniteQueryOptions, } = query[QUERY_PARAMETERS];
@@ -15,7 +16,7 @@ const convertToRawQuery = (query, di, options) => {
15
16
  const rawQueryKey = typeof key === 'function' ? key.call(ctx, options) : key;
16
17
  const queryKey = normalizeKey(rawQueryKey);
17
18
  const actionWrapper = declareAction({
18
- name: 'infiniteQueryExecution',
19
+ name: `infiniteQueryExecution:${query.actionNamePostfix}`,
19
20
  async fn(queryContext) {
20
21
  const { abortSignal, abortController } = this;
21
22
  mapQuerySignalToxecutionContext(queryContext, this);
@@ -43,6 +44,7 @@ const createInfiniteQuery = (queryParameters) => {
43
44
  const { infiniteQueryOptions, conditions } = queryParameters;
44
45
  const query = {
45
46
  [QUERY_PARAMETERS]: queryParameters,
47
+ actionNamePostfix: createUniqueActionKeyForQuery(queryParameters),
46
48
  fork: (options) => {
47
49
  return createInfiniteQuery({
48
50
  ...queryParameters,
@@ -57,26 +59,28 @@ const createInfiniteQuery = (queryParameters) => {
57
59
  },
58
60
  prefetchAction: (options) => {
59
61
  return declareAction({
60
- name: 'infiniteQueryPrefetch',
62
+ name: `infiniteQueryPrefetch:${query.actionNamePostfix}`,
61
63
  fn() {
62
64
  return this.deps.queryClient.prefetchInfiniteQuery(convertToRawQuery(query, this.deps.di, options));
63
65
  },
64
66
  deps: {
65
67
  di: DI_TOKEN,
66
68
  queryClient: QUERY_CLIENT_TOKEN,
69
+ logger: LOGGER_TOKEN,
67
70
  },
68
71
  conditions,
69
72
  });
70
73
  },
71
74
  fetchAction: (options) => {
72
75
  return declareAction({
73
- name: 'infiniteQueryFetch',
76
+ name: `infiniteQueryFetch:${query.actionNamePostfix}`,
74
77
  fn() {
75
78
  return this.deps.queryClient.fetchInfiniteQuery(convertToRawQuery(query, this.deps.di, options));
76
79
  },
77
80
  deps: {
78
81
  di: DI_TOKEN,
79
82
  queryClient: QUERY_CLIENT_TOKEN,
83
+ logger: LOGGER_TOKEN,
80
84
  },
81
85
  conditions,
82
86
  });
@@ -11,6 +11,7 @@ var types = require('../baseQuery/types.js');
11
11
  var normalizeKey = require('../shared/normalizeKey.js');
12
12
  var resolveDI = require('../shared/resolveDI.js');
13
13
  var signal = require('../shared/signal.js');
14
+ var createUniqueActionKeyForQuery = require('../shared/createUniqueActionKeyForQuery.js');
14
15
 
15
16
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
16
17
 
@@ -23,7 +24,7 @@ const convertToRawQuery = (query, di, options) => {
23
24
  const rawQueryKey = typeof key === 'function' ? key.call(ctx, options) : key;
24
25
  const queryKey = normalizeKey.normalizeKey(rawQueryKey);
25
26
  const actionWrapper = core.declareAction({
26
- name: 'infiniteQueryExecution',
27
+ name: `infiniteQueryExecution:${query.actionNamePostfix}`,
27
28
  async fn(queryContext) {
28
29
  const { abortSignal, abortController } = this;
29
30
  signal.mapQuerySignalToxecutionContext(queryContext, this);
@@ -51,6 +52,7 @@ const createInfiniteQuery = (queryParameters) => {
51
52
  const { infiniteQueryOptions, conditions } = queryParameters;
52
53
  const query = {
53
54
  [types.QUERY_PARAMETERS]: queryParameters,
55
+ actionNamePostfix: createUniqueActionKeyForQuery.createUniqueActionKeyForQuery(queryParameters),
54
56
  fork: (options) => {
55
57
  return createInfiniteQuery({
56
58
  ...queryParameters,
@@ -65,26 +67,28 @@ const createInfiniteQuery = (queryParameters) => {
65
67
  },
66
68
  prefetchAction: (options) => {
67
69
  return core.declareAction({
68
- name: 'infiniteQueryPrefetch',
70
+ name: `infiniteQueryPrefetch:${query.actionNamePostfix}`,
69
71
  fn() {
70
72
  return this.deps.queryClient.prefetchInfiniteQuery(convertToRawQuery(query, this.deps.di, options));
71
73
  },
72
74
  deps: {
73
75
  di: dippy.DI_TOKEN,
74
76
  queryClient: moduleReactQuery.QUERY_CLIENT_TOKEN,
77
+ logger: tokensCommon.LOGGER_TOKEN,
75
78
  },
76
79
  conditions,
77
80
  });
78
81
  },
79
82
  fetchAction: (options) => {
80
83
  return core.declareAction({
81
- name: 'infiniteQueryFetch',
84
+ name: `infiniteQueryFetch:${query.actionNamePostfix}`,
82
85
  fn() {
83
86
  return this.deps.queryClient.fetchInfiniteQuery(convertToRawQuery(query, this.deps.di, options));
84
87
  },
85
88
  deps: {
86
89
  di: dippy.DI_TOKEN,
87
90
  queryClient: moduleReactQuery.QUERY_CLIENT_TOKEN,
91
+ logger: tokensCommon.LOGGER_TOKEN,
88
92
  },
89
93
  conditions,
90
94
  });
@@ -2,11 +2,12 @@ import identity from '@tinkoff/utils/function/identity';
2
2
  import { DI_TOKEN } from '@tinkoff/dippy';
3
3
  import { declareAction } from '@tramvai/core';
4
4
  import { QUERY_CLIENT_TOKEN } from '@tramvai/module-react-query';
5
- import { CONTEXT_TOKEN } from '@tramvai/tokens-common';
5
+ import { LOGGER_TOKEN, CONTEXT_TOKEN } from '@tramvai/tokens-common';
6
6
  import { QUERY_PARAMETERS } from '../baseQuery/types.es.js';
7
7
  import { normalizeKey } from '../shared/normalizeKey.es.js';
8
8
  import { resolveDI } from '../shared/resolveDI.es.js';
9
9
  import { mapQuerySignalToxecutionContext } from '../shared/signal.es.js';
10
+ import { createUniqueActionKeyForQuery } from '../shared/createUniqueActionKeyForQuery.es.js';
10
11
 
11
12
  const convertToRawQuery = (query, di, options) => {
12
13
  const { key = identity, fn, deps = {}, conditions, queryOptions } = query[QUERY_PARAMETERS];
@@ -15,7 +16,7 @@ const convertToRawQuery = (query, di, options) => {
15
16
  const rawQueryKey = typeof key === 'function' ? key.call(ctx, options) : key;
16
17
  const queryKey = normalizeKey(rawQueryKey);
17
18
  const actionWrapper = declareAction({
18
- name: 'queryExecution',
19
+ name: `queryExecution:${query.actionNamePostfix}`,
19
20
  async fn(queryContext) {
20
21
  const { abortSignal, abortController } = this;
21
22
  mapQuerySignalToxecutionContext(queryContext, this);
@@ -41,6 +42,7 @@ const createQuery = (queryParameters) => {
41
42
  const { queryOptions, conditions } = queryParameters;
42
43
  const query = {
43
44
  [QUERY_PARAMETERS]: queryParameters,
45
+ actionNamePostfix: createUniqueActionKeyForQuery(queryParameters),
44
46
  fork: (options) => {
45
47
  return createQuery({
46
48
  ...queryParameters,
@@ -55,26 +57,28 @@ const createQuery = (queryParameters) => {
55
57
  },
56
58
  prefetchAction: (options) => {
57
59
  return declareAction({
58
- name: 'queryPrefetch',
60
+ name: `queryPrefetch:${query.actionNamePostfix}`,
59
61
  fn() {
60
62
  return this.deps.queryClient.prefetchQuery(convertToRawQuery(query, this.deps.di, options));
61
63
  },
62
64
  deps: {
63
65
  di: DI_TOKEN,
64
66
  queryClient: QUERY_CLIENT_TOKEN,
67
+ logger: LOGGER_TOKEN,
65
68
  },
66
69
  conditions,
67
70
  });
68
71
  },
69
72
  fetchAction: (options) => {
70
73
  return declareAction({
71
- name: 'queryFetch',
74
+ name: `queryFetch:${query.actionNamePostfix}`,
72
75
  fn() {
73
76
  return this.deps.queryClient.fetchQuery(convertToRawQuery(query, this.deps.di, options));
74
77
  },
75
78
  deps: {
76
79
  di: DI_TOKEN,
77
80
  queryClient: QUERY_CLIENT_TOKEN,
81
+ logger: LOGGER_TOKEN,
78
82
  },
79
83
  conditions,
80
84
  });
@@ -11,6 +11,7 @@ var types = require('../baseQuery/types.js');
11
11
  var normalizeKey = require('../shared/normalizeKey.js');
12
12
  var resolveDI = require('../shared/resolveDI.js');
13
13
  var signal = require('../shared/signal.js');
14
+ var createUniqueActionKeyForQuery = require('../shared/createUniqueActionKeyForQuery.js');
14
15
 
15
16
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
16
17
 
@@ -23,7 +24,7 @@ const convertToRawQuery = (query, di, options) => {
23
24
  const rawQueryKey = typeof key === 'function' ? key.call(ctx, options) : key;
24
25
  const queryKey = normalizeKey.normalizeKey(rawQueryKey);
25
26
  const actionWrapper = core.declareAction({
26
- name: 'queryExecution',
27
+ name: `queryExecution:${query.actionNamePostfix}`,
27
28
  async fn(queryContext) {
28
29
  const { abortSignal, abortController } = this;
29
30
  signal.mapQuerySignalToxecutionContext(queryContext, this);
@@ -49,6 +50,7 @@ const createQuery = (queryParameters) => {
49
50
  const { queryOptions, conditions } = queryParameters;
50
51
  const query = {
51
52
  [types.QUERY_PARAMETERS]: queryParameters,
53
+ actionNamePostfix: createUniqueActionKeyForQuery.createUniqueActionKeyForQuery(queryParameters),
52
54
  fork: (options) => {
53
55
  return createQuery({
54
56
  ...queryParameters,
@@ -63,26 +65,28 @@ const createQuery = (queryParameters) => {
63
65
  },
64
66
  prefetchAction: (options) => {
65
67
  return core.declareAction({
66
- name: 'queryPrefetch',
68
+ name: `queryPrefetch:${query.actionNamePostfix}`,
67
69
  fn() {
68
70
  return this.deps.queryClient.prefetchQuery(convertToRawQuery(query, this.deps.di, options));
69
71
  },
70
72
  deps: {
71
73
  di: dippy.DI_TOKEN,
72
74
  queryClient: moduleReactQuery.QUERY_CLIENT_TOKEN,
75
+ logger: tokensCommon.LOGGER_TOKEN,
73
76
  },
74
77
  conditions,
75
78
  });
76
79
  },
77
80
  fetchAction: (options) => {
78
81
  return core.declareAction({
79
- name: 'queryFetch',
82
+ name: `queryFetch:${query.actionNamePostfix}`,
80
83
  fn() {
81
84
  return this.deps.queryClient.fetchQuery(convertToRawQuery(query, this.deps.di, options));
82
85
  },
83
86
  deps: {
84
87
  di: dippy.DI_TOKEN,
85
88
  queryClient: moduleReactQuery.QUERY_CLIENT_TOKEN,
89
+ logger: tokensCommon.LOGGER_TOKEN,
86
90
  },
87
91
  conditions,
88
92
  });
@@ -0,0 +1,3 @@
1
+ import type { ProviderDeps } from '@tinkoff/dippy';
2
+ import type { BaseCreateQueryOptions } from '../baseQuery/types';
3
+ export declare const createUniqueActionKeyForQuery: <Options, Deps extends ProviderDeps>(queryParameters: BaseCreateQueryOptions<Options, Deps>) => string;
@@ -0,0 +1,12 @@
1
+ import { normalizeKey } from './normalizeKey.es.js';
2
+
3
+ const createUniqueActionKeyForQuery = (queryParameters) => {
4
+ var _a;
5
+ const rawQueryKey = typeof queryParameters.key === 'function'
6
+ ? queryParameters.actionNamePostfix
7
+ : (_a = queryParameters.actionNamePostfix) !== null && _a !== void 0 ? _a : queryParameters.key;
8
+ const queryKeyArray = normalizeKey(rawQueryKey);
9
+ return queryKeyArray.join('_');
10
+ };
11
+
12
+ export { createUniqueActionKeyForQuery };
@@ -0,0 +1,16 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var normalizeKey = require('./normalizeKey.js');
6
+
7
+ const createUniqueActionKeyForQuery = (queryParameters) => {
8
+ var _a;
9
+ const rawQueryKey = typeof queryParameters.key === 'function'
10
+ ? queryParameters.actionNamePostfix
11
+ : (_a = queryParameters.actionNamePostfix) !== null && _a !== void 0 ? _a : queryParameters.key;
12
+ const queryKeyArray = normalizeKey.normalizeKey(rawQueryKey);
13
+ return queryKeyArray.join('_');
14
+ };
15
+
16
+ exports.createUniqueActionKeyForQuery = createUniqueActionKeyForQuery;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tramvai/react-query",
3
- "version": "2.146.0",
3
+ "version": "2.147.1",
4
4
  "description": "",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
@@ -18,10 +18,10 @@
18
18
  },
19
19
  "dependencies": {
20
20
  "@tinkoff/react-hooks": "0.1.6",
21
- "@tramvai/core": "2.146.0",
22
- "@tramvai/module-react-query": "2.146.0",
23
- "@tramvai/react": "2.146.0",
24
- "@tramvai/tokens-common": "2.146.0"
21
+ "@tramvai/core": "2.147.1",
22
+ "@tramvai/module-react-query": "2.147.1",
23
+ "@tramvai/react": "2.147.1",
24
+ "@tramvai/tokens-common": "2.147.1"
25
25
  },
26
26
  "peerDependencies": {
27
27
  "@tinkoff/dippy": "0.8.15",