@tramvai/react-query 2.130.11 → 2.132.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.
@@ -4,6 +4,8 @@ import type { Container, ProvideDepsIterator, ProviderDeps } from '@tinkoff/dipp
4
4
  export declare const QUERY_PARAMETERS = "__query_parameters__";
5
5
  export interface ReactQueryContext<Deps extends ProviderDeps> {
6
6
  deps: ProvideDepsIterator<Deps>;
7
+ abortController?: AbortController;
8
+ abortSignal?: AbortSignal;
7
9
  }
8
10
  export type ReactQueryKeyOrString = ReactQueryKey | string;
9
11
  export type QueryKey<Options, Deps extends ProviderDeps> = ((this: ReactQueryContext<Deps>, options: Options) => ReactQueryKeyOrString) | ReactQueryKeyOrString;
@@ -6,6 +6,7 @@ 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
+ import { mapQuerySignalToxecutionContext } from '../shared/signal.es.js';
9
10
 
10
11
  const convertToRawQuery = (query, di, options) => {
11
12
  const { key = identity, fn, getNextPageParam, getPreviousPageParam, deps = {}, conditions, infiniteQueryOptions, } = query[QUERY_PARAMETERS];
@@ -15,8 +16,10 @@ const convertToRawQuery = (query, di, options) => {
15
16
  const queryKey = normalizeKey(rawQueryKey);
16
17
  const actionWrapper = declareAction({
17
18
  name: 'infiniteQueryExecution',
18
- async fn(pageParam) {
19
- return fn.call(ctx, options, pageParam, ctx.deps);
19
+ async fn(queryContext) {
20
+ const { abortSignal, abortController } = this;
21
+ mapQuerySignalToxecutionContext(queryContext, this);
22
+ return fn.call({ ...ctx, abortSignal, abortController }, options, queryContext.pageParam, ctx.deps);
20
23
  },
21
24
  conditionsFailResult: 'reject',
22
25
  deps,
@@ -30,9 +33,9 @@ const convertToRawQuery = (query, di, options) => {
30
33
  tramvaiOptions: {
31
34
  conditions,
32
35
  },
33
- queryFn: ({ pageParam }) => {
36
+ queryFn: (queryContext) => {
34
37
  const context = di.get(CONTEXT_TOKEN);
35
- return context.executeAction(actionWrapper, pageParam);
38
+ return context.executeAction(actionWrapper, queryContext);
36
39
  },
37
40
  };
38
41
  };
@@ -10,6 +10,7 @@ var dippy = require('@tinkoff/dippy');
10
10
  var types = require('../baseQuery/types.js');
11
11
  var normalizeKey = require('../shared/normalizeKey.js');
12
12
  var resolveDI = require('../shared/resolveDI.js');
13
+ var signal = require('../shared/signal.js');
13
14
 
14
15
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
15
16
 
@@ -23,8 +24,10 @@ const convertToRawQuery = (query, di, options) => {
23
24
  const queryKey = normalizeKey.normalizeKey(rawQueryKey);
24
25
  const actionWrapper = core.declareAction({
25
26
  name: 'infiniteQueryExecution',
26
- async fn(pageParam) {
27
- return fn.call(ctx, options, pageParam, ctx.deps);
27
+ async fn(queryContext) {
28
+ const { abortSignal, abortController } = this;
29
+ signal.mapQuerySignalToxecutionContext(queryContext, this);
30
+ return fn.call({ ...ctx, abortSignal, abortController }, options, queryContext.pageParam, ctx.deps);
28
31
  },
29
32
  conditionsFailResult: 'reject',
30
33
  deps,
@@ -38,9 +41,9 @@ const convertToRawQuery = (query, di, options) => {
38
41
  tramvaiOptions: {
39
42
  conditions,
40
43
  },
41
- queryFn: ({ pageParam }) => {
44
+ queryFn: (queryContext) => {
42
45
  const context = di.get(tokensCommon.CONTEXT_TOKEN);
43
- return context.executeAction(actionWrapper, pageParam);
46
+ return context.executeAction(actionWrapper, queryContext);
44
47
  },
45
48
  };
46
49
  };
@@ -6,6 +6,7 @@ import { 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
+ import { mapQuerySignalToxecutionContext } from '../shared/signal.es.js';
9
10
 
10
11
  const convertToRawQuery = (query, di, options) => {
11
12
  const { key = identity, fn, deps = {}, conditions, queryOptions } = query[QUERY_PARAMETERS];
@@ -15,8 +16,10 @@ const convertToRawQuery = (query, di, options) => {
15
16
  const queryKey = normalizeKey(rawQueryKey);
16
17
  const actionWrapper = declareAction({
17
18
  name: 'queryExecution',
18
- async fn() {
19
- return fn.call(ctx, options, ctx.deps);
19
+ async fn(queryContext) {
20
+ const { abortSignal, abortController } = this;
21
+ mapQuerySignalToxecutionContext(queryContext, this);
22
+ return fn.call({ ...ctx, abortSignal, abortController }, options, ctx.deps);
20
23
  },
21
24
  deps,
22
25
  conditions,
@@ -28,9 +31,9 @@ const convertToRawQuery = (query, di, options) => {
28
31
  tramvaiOptions: {
29
32
  conditions,
30
33
  },
31
- queryFn: () => {
34
+ queryFn: (queryContext) => {
32
35
  const context = di.get(CONTEXT_TOKEN);
33
- return context.executeAction(actionWrapper);
36
+ return context.executeAction(actionWrapper, queryContext);
34
37
  },
35
38
  };
36
39
  };
@@ -10,6 +10,7 @@ var tokensCommon = require('@tramvai/tokens-common');
10
10
  var types = require('../baseQuery/types.js');
11
11
  var normalizeKey = require('../shared/normalizeKey.js');
12
12
  var resolveDI = require('../shared/resolveDI.js');
13
+ var signal = require('../shared/signal.js');
13
14
 
14
15
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
15
16
 
@@ -23,8 +24,10 @@ const convertToRawQuery = (query, di, options) => {
23
24
  const queryKey = normalizeKey.normalizeKey(rawQueryKey);
24
25
  const actionWrapper = core.declareAction({
25
26
  name: 'queryExecution',
26
- async fn() {
27
- return fn.call(ctx, options, ctx.deps);
27
+ async fn(queryContext) {
28
+ const { abortSignal, abortController } = this;
29
+ signal.mapQuerySignalToxecutionContext(queryContext, this);
30
+ return fn.call({ ...ctx, abortSignal, abortController }, options, ctx.deps);
28
31
  },
29
32
  deps,
30
33
  conditions,
@@ -36,9 +39,9 @@ const convertToRawQuery = (query, di, options) => {
36
39
  tramvaiOptions: {
37
40
  conditions,
38
41
  },
39
- queryFn: () => {
42
+ queryFn: (queryContext) => {
40
43
  const context = di.get(tokensCommon.CONTEXT_TOKEN);
41
- return context.executeAction(actionWrapper);
44
+ return context.executeAction(actionWrapper, queryContext);
42
45
  },
43
46
  };
44
47
  };
@@ -0,0 +1,4 @@
1
+ import type { TramvaiActionContext } from '@tramvai/core';
2
+ export declare const mapQuerySignalToxecutionContext: (queryContext: {
3
+ signal?: AbortSignal | undefined;
4
+ } | undefined, actionContext: TramvaiActionContext<any>) => void;
@@ -0,0 +1,16 @@
1
+ // Support query cancellation - https://tanstack.com/query/v4/docs/react/guides/query-cancellation
2
+ const mapQuerySignalToxecutionContext = (queryContext = {}, actionContext) => {
3
+ if (queryContext.signal) {
4
+ if (queryContext.signal.aborted) {
5
+ actionContext.abortController.abort();
6
+ }
7
+ else {
8
+ // abort action context AbortController if react-query AbortController was aborted
9
+ queryContext.signal.addEventListener('abort', () => {
10
+ actionContext.abortController.abort();
11
+ });
12
+ }
13
+ }
14
+ };
15
+
16
+ export { mapQuerySignalToxecutionContext };
@@ -0,0 +1,20 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ // Support query cancellation - https://tanstack.com/query/v4/docs/react/guides/query-cancellation
6
+ const mapQuerySignalToxecutionContext = (queryContext = {}, actionContext) => {
7
+ if (queryContext.signal) {
8
+ if (queryContext.signal.aborted) {
9
+ actionContext.abortController.abort();
10
+ }
11
+ else {
12
+ // abort action context AbortController if react-query AbortController was aborted
13
+ queryContext.signal.addEventListener('abort', () => {
14
+ actionContext.abortController.abort();
15
+ });
16
+ }
17
+ }
18
+ };
19
+
20
+ exports.mapQuerySignalToxecutionContext = mapQuerySignalToxecutionContext;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tramvai/react-query",
3
- "version": "2.130.11",
3
+ "version": "2.132.0",
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.130.11",
22
- "@tramvai/module-react-query": "2.130.11",
23
- "@tramvai/react": "2.130.11",
24
- "@tramvai/tokens-common": "2.130.11"
21
+ "@tramvai/core": "2.132.0",
22
+ "@tramvai/module-react-query": "2.132.0",
23
+ "@tramvai/react": "2.132.0",
24
+ "@tramvai/tokens-common": "2.132.0"
25
25
  },
26
26
  "peerDependencies": {
27
27
  "@tinkoff/dippy": "0.8.15",