@tramvai/react-query 2.11.0 → 2.21.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/lib/baseQuery/types.d.ts +2 -5
- package/lib/index.es.js +36 -22
- package/lib/index.js +35 -21
- package/lib/infiniteQuery/types.d.ts +2 -5
- package/lib/query/types.d.ts +2 -5
- package/package.json +7 -6
package/lib/baseQuery/types.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type { QUERY_CLIENT_TOKEN } from '@tramvai/module-react-query';
|
|
1
|
+
import type { ActionConditionsParameters, ActionContext, TramvaiAction } from '@tramvai/core';
|
|
3
2
|
import type { QueryKey as ReactQueryKey, QueryOptions } from 'react-query';
|
|
4
3
|
export declare const QUERY_PARAMETERS = "__query_parameters__";
|
|
5
4
|
export declare type QueryKey<Options> = ((options: Options) => ReactQueryKey) | ReactQueryKey;
|
|
@@ -13,8 +12,6 @@ export interface BaseQuery<Options, TCreateQuery, TQuery, TUseQuery> {
|
|
|
13
12
|
[QUERY_PARAMETERS]: TCreateQuery;
|
|
14
13
|
fork(options: TUseQuery): TQuery;
|
|
15
14
|
raw(context: ActionContext, options?: Options): TUseQuery;
|
|
16
|
-
prefetchAction(options?: Options):
|
|
17
|
-
queryClient: typeof QUERY_CLIENT_TOKEN;
|
|
18
|
-
}>;
|
|
15
|
+
prefetchAction(options?: Options): TramvaiAction<[], Promise<void>, any>;
|
|
19
16
|
}
|
|
20
17
|
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>;
|
package/lib/index.es.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import applyOrReturn from '@tinkoff/utils/function/applyOrReturn';
|
|
2
|
-
import {
|
|
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
5
|
import isString from '@tinkoff/utils/is/string';
|
|
5
6
|
import isArray from '@tinkoff/utils/is/array';
|
|
6
7
|
import { useMemo } from 'react';
|
|
@@ -24,17 +25,21 @@ const defaultKey = (options) => {
|
|
|
24
25
|
const convertToRawQuery$1 = (query, context, options) => {
|
|
25
26
|
const { key = defaultKey, fn, deps, conditions, queryOptions } = query[QUERY_PARAMETERS];
|
|
26
27
|
const queryKey = applyOrReturn([options], key);
|
|
27
|
-
const actionWrapper =
|
|
28
|
+
const actionWrapper = declareAction({
|
|
28
29
|
name: 'queryExecution',
|
|
29
|
-
|
|
30
|
-
return fn(options,
|
|
30
|
+
async fn() {
|
|
31
|
+
return fn(options, this.deps);
|
|
31
32
|
},
|
|
32
33
|
deps,
|
|
33
34
|
conditions,
|
|
35
|
+
conditionsFailResult: 'reject',
|
|
34
36
|
});
|
|
35
37
|
return {
|
|
36
38
|
...queryOptions,
|
|
37
39
|
queryKey,
|
|
40
|
+
tramvaiOptions: {
|
|
41
|
+
conditions,
|
|
42
|
+
},
|
|
38
43
|
queryFn: () => {
|
|
39
44
|
return context.executeAction(actionWrapper);
|
|
40
45
|
},
|
|
@@ -57,24 +62,26 @@ const createQuery = (queryParameters) => {
|
|
|
57
62
|
return convertToRawQuery$1(query, context, options);
|
|
58
63
|
},
|
|
59
64
|
prefetchAction: (options) => {
|
|
60
|
-
return
|
|
65
|
+
return declareAction({
|
|
61
66
|
name: 'queryPrefetch',
|
|
62
|
-
fn
|
|
63
|
-
return queryClient.prefetchQuery(convertToRawQuery$1(query, context, options));
|
|
67
|
+
fn() {
|
|
68
|
+
return this.deps.queryClient.prefetchQuery(convertToRawQuery$1(query, this.deps.context, options));
|
|
64
69
|
},
|
|
65
70
|
deps: {
|
|
71
|
+
context: CONTEXT_TOKEN,
|
|
66
72
|
queryClient: QUERY_CLIENT_TOKEN,
|
|
67
73
|
},
|
|
68
74
|
conditions,
|
|
69
75
|
});
|
|
70
76
|
},
|
|
71
77
|
fetchAction: (options) => {
|
|
72
|
-
return
|
|
78
|
+
return declareAction({
|
|
73
79
|
name: 'queryFetch',
|
|
74
|
-
fn
|
|
75
|
-
return queryClient.fetchQuery(convertToRawQuery$1(query, context, options));
|
|
80
|
+
fn() {
|
|
81
|
+
return this.deps.queryClient.fetchQuery(convertToRawQuery$1(query, this.deps.context, options));
|
|
76
82
|
},
|
|
77
83
|
deps: {
|
|
84
|
+
context: CONTEXT_TOKEN,
|
|
78
85
|
queryClient: QUERY_CLIENT_TOKEN,
|
|
79
86
|
},
|
|
80
87
|
conditions,
|
|
@@ -111,11 +118,12 @@ function useQueries(queries) {
|
|
|
111
118
|
const convertToRawQuery = (query, context, options) => {
|
|
112
119
|
const { key = defaultKey, fn, getNextPageParam, getPreviousPageParam, deps, conditions, infiniteQueryOptions, } = query[QUERY_PARAMETERS];
|
|
113
120
|
const queryKey = applyOrReturn([options], key);
|
|
114
|
-
const actionWrapper =
|
|
121
|
+
const actionWrapper = declareAction({
|
|
115
122
|
name: 'infiniteQueryExecution',
|
|
116
|
-
|
|
117
|
-
return fn(options, pageParam,
|
|
123
|
+
async fn(pageParam) {
|
|
124
|
+
return fn(options, pageParam, this.deps);
|
|
118
125
|
},
|
|
126
|
+
conditionsFailResult: 'reject',
|
|
119
127
|
deps,
|
|
120
128
|
conditions,
|
|
121
129
|
});
|
|
@@ -124,6 +132,9 @@ const convertToRawQuery = (query, context, options) => {
|
|
|
124
132
|
getNextPageParam,
|
|
125
133
|
getPreviousPageParam,
|
|
126
134
|
queryKey,
|
|
135
|
+
tramvaiOptions: {
|
|
136
|
+
conditions,
|
|
137
|
+
},
|
|
127
138
|
queryFn: ({ pageParam }) => {
|
|
128
139
|
return context.executeAction(actionWrapper, pageParam);
|
|
129
140
|
},
|
|
@@ -146,24 +157,26 @@ const createInfiniteQuery = (queryParameters) => {
|
|
|
146
157
|
return convertToRawQuery(query, context, options);
|
|
147
158
|
},
|
|
148
159
|
prefetchAction: (options) => {
|
|
149
|
-
return
|
|
160
|
+
return declareAction({
|
|
150
161
|
name: 'infiniteQueryPrefetch',
|
|
151
|
-
fn
|
|
152
|
-
return queryClient.prefetchInfiniteQuery(convertToRawQuery(query, context, options));
|
|
162
|
+
fn() {
|
|
163
|
+
return this.deps.queryClient.prefetchInfiniteQuery(convertToRawQuery(query, this.deps.context, options));
|
|
153
164
|
},
|
|
154
165
|
deps: {
|
|
166
|
+
context: CONTEXT_TOKEN,
|
|
155
167
|
queryClient: QUERY_CLIENT_TOKEN,
|
|
156
168
|
},
|
|
157
169
|
conditions,
|
|
158
170
|
});
|
|
159
171
|
},
|
|
160
172
|
fetchAction: (options) => {
|
|
161
|
-
return
|
|
173
|
+
return declareAction({
|
|
162
174
|
name: 'infiniteQueryFetch',
|
|
163
|
-
fn
|
|
164
|
-
return queryClient.fetchInfiniteQuery(convertToRawQuery(query, context, options));
|
|
175
|
+
fn() {
|
|
176
|
+
return this.deps.queryClient.fetchInfiniteQuery(convertToRawQuery(query, this.deps.context, options));
|
|
165
177
|
},
|
|
166
178
|
deps: {
|
|
179
|
+
context: CONTEXT_TOKEN,
|
|
167
180
|
queryClient: QUERY_CLIENT_TOKEN,
|
|
168
181
|
},
|
|
169
182
|
conditions,
|
|
@@ -192,13 +205,14 @@ const isMutation = (arg) => {
|
|
|
192
205
|
const convertToRawMutation = (mutation, context, options) => {
|
|
193
206
|
const { key = defaultKey, fn, deps, conditions, mutationOptions } = mutation[MUTATION_PARAMETERS];
|
|
194
207
|
const mutationKey = applyOrReturn([options], key);
|
|
195
|
-
const actionWrapper =
|
|
208
|
+
const actionWrapper = declareAction({
|
|
196
209
|
name: 'mutationExecution',
|
|
197
|
-
|
|
198
|
-
return fn(options, variables,
|
|
210
|
+
async fn(variables) {
|
|
211
|
+
return fn(options, variables, this.deps);
|
|
199
212
|
},
|
|
200
213
|
deps,
|
|
201
214
|
conditions,
|
|
215
|
+
conditionsFailResult: 'reject',
|
|
202
216
|
});
|
|
203
217
|
return {
|
|
204
218
|
...mutationOptions,
|
package/lib/index.js
CHANGED
|
@@ -5,6 +5,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
5
5
|
var applyOrReturn = require('@tinkoff/utils/function/applyOrReturn');
|
|
6
6
|
var core = require('@tramvai/core');
|
|
7
7
|
var moduleReactQuery = require('@tramvai/module-react-query');
|
|
8
|
+
var tokensCommon = require('@tramvai/tokens-common');
|
|
8
9
|
var isString = require('@tinkoff/utils/is/string');
|
|
9
10
|
var isArray = require('@tinkoff/utils/is/array');
|
|
10
11
|
var react = require('react');
|
|
@@ -33,17 +34,21 @@ const defaultKey = (options) => {
|
|
|
33
34
|
const convertToRawQuery$1 = (query, context, options) => {
|
|
34
35
|
const { key = defaultKey, fn, deps, conditions, queryOptions } = query[QUERY_PARAMETERS];
|
|
35
36
|
const queryKey = applyOrReturn__default["default"]([options], key);
|
|
36
|
-
const actionWrapper = core.
|
|
37
|
+
const actionWrapper = core.declareAction({
|
|
37
38
|
name: 'queryExecution',
|
|
38
|
-
|
|
39
|
-
return fn(options,
|
|
39
|
+
async fn() {
|
|
40
|
+
return fn(options, this.deps);
|
|
40
41
|
},
|
|
41
42
|
deps,
|
|
42
43
|
conditions,
|
|
44
|
+
conditionsFailResult: 'reject',
|
|
43
45
|
});
|
|
44
46
|
return {
|
|
45
47
|
...queryOptions,
|
|
46
48
|
queryKey,
|
|
49
|
+
tramvaiOptions: {
|
|
50
|
+
conditions,
|
|
51
|
+
},
|
|
47
52
|
queryFn: () => {
|
|
48
53
|
return context.executeAction(actionWrapper);
|
|
49
54
|
},
|
|
@@ -66,24 +71,26 @@ const createQuery = (queryParameters) => {
|
|
|
66
71
|
return convertToRawQuery$1(query, context, options);
|
|
67
72
|
},
|
|
68
73
|
prefetchAction: (options) => {
|
|
69
|
-
return core.
|
|
74
|
+
return core.declareAction({
|
|
70
75
|
name: 'queryPrefetch',
|
|
71
|
-
fn
|
|
72
|
-
return queryClient.prefetchQuery(convertToRawQuery$1(query, context, options));
|
|
76
|
+
fn() {
|
|
77
|
+
return this.deps.queryClient.prefetchQuery(convertToRawQuery$1(query, this.deps.context, options));
|
|
73
78
|
},
|
|
74
79
|
deps: {
|
|
80
|
+
context: tokensCommon.CONTEXT_TOKEN,
|
|
75
81
|
queryClient: moduleReactQuery.QUERY_CLIENT_TOKEN,
|
|
76
82
|
},
|
|
77
83
|
conditions,
|
|
78
84
|
});
|
|
79
85
|
},
|
|
80
86
|
fetchAction: (options) => {
|
|
81
|
-
return core.
|
|
87
|
+
return core.declareAction({
|
|
82
88
|
name: 'queryFetch',
|
|
83
|
-
fn
|
|
84
|
-
return queryClient.fetchQuery(convertToRawQuery$1(query, context, options));
|
|
89
|
+
fn() {
|
|
90
|
+
return this.deps.queryClient.fetchQuery(convertToRawQuery$1(query, this.deps.context, options));
|
|
85
91
|
},
|
|
86
92
|
deps: {
|
|
93
|
+
context: tokensCommon.CONTEXT_TOKEN,
|
|
87
94
|
queryClient: moduleReactQuery.QUERY_CLIENT_TOKEN,
|
|
88
95
|
},
|
|
89
96
|
conditions,
|
|
@@ -120,11 +127,12 @@ function useQueries(queries) {
|
|
|
120
127
|
const convertToRawQuery = (query, context, options) => {
|
|
121
128
|
const { key = defaultKey, fn, getNextPageParam, getPreviousPageParam, deps, conditions, infiniteQueryOptions, } = query[QUERY_PARAMETERS];
|
|
122
129
|
const queryKey = applyOrReturn__default["default"]([options], key);
|
|
123
|
-
const actionWrapper = core.
|
|
130
|
+
const actionWrapper = core.declareAction({
|
|
124
131
|
name: 'infiniteQueryExecution',
|
|
125
|
-
|
|
126
|
-
return fn(options, pageParam,
|
|
132
|
+
async fn(pageParam) {
|
|
133
|
+
return fn(options, pageParam, this.deps);
|
|
127
134
|
},
|
|
135
|
+
conditionsFailResult: 'reject',
|
|
128
136
|
deps,
|
|
129
137
|
conditions,
|
|
130
138
|
});
|
|
@@ -133,6 +141,9 @@ const convertToRawQuery = (query, context, options) => {
|
|
|
133
141
|
getNextPageParam,
|
|
134
142
|
getPreviousPageParam,
|
|
135
143
|
queryKey,
|
|
144
|
+
tramvaiOptions: {
|
|
145
|
+
conditions,
|
|
146
|
+
},
|
|
136
147
|
queryFn: ({ pageParam }) => {
|
|
137
148
|
return context.executeAction(actionWrapper, pageParam);
|
|
138
149
|
},
|
|
@@ -155,24 +166,26 @@ const createInfiniteQuery = (queryParameters) => {
|
|
|
155
166
|
return convertToRawQuery(query, context, options);
|
|
156
167
|
},
|
|
157
168
|
prefetchAction: (options) => {
|
|
158
|
-
return core.
|
|
169
|
+
return core.declareAction({
|
|
159
170
|
name: 'infiniteQueryPrefetch',
|
|
160
|
-
fn
|
|
161
|
-
return queryClient.prefetchInfiniteQuery(convertToRawQuery(query, context, options));
|
|
171
|
+
fn() {
|
|
172
|
+
return this.deps.queryClient.prefetchInfiniteQuery(convertToRawQuery(query, this.deps.context, options));
|
|
162
173
|
},
|
|
163
174
|
deps: {
|
|
175
|
+
context: tokensCommon.CONTEXT_TOKEN,
|
|
164
176
|
queryClient: moduleReactQuery.QUERY_CLIENT_TOKEN,
|
|
165
177
|
},
|
|
166
178
|
conditions,
|
|
167
179
|
});
|
|
168
180
|
},
|
|
169
181
|
fetchAction: (options) => {
|
|
170
|
-
return core.
|
|
182
|
+
return core.declareAction({
|
|
171
183
|
name: 'infiniteQueryFetch',
|
|
172
|
-
fn
|
|
173
|
-
return queryClient.fetchInfiniteQuery(convertToRawQuery(query, context, options));
|
|
184
|
+
fn() {
|
|
185
|
+
return this.deps.queryClient.fetchInfiniteQuery(convertToRawQuery(query, this.deps.context, options));
|
|
174
186
|
},
|
|
175
187
|
deps: {
|
|
188
|
+
context: tokensCommon.CONTEXT_TOKEN,
|
|
176
189
|
queryClient: moduleReactQuery.QUERY_CLIENT_TOKEN,
|
|
177
190
|
},
|
|
178
191
|
conditions,
|
|
@@ -201,13 +214,14 @@ const isMutation = (arg) => {
|
|
|
201
214
|
const convertToRawMutation = (mutation, context, options) => {
|
|
202
215
|
const { key = defaultKey, fn, deps, conditions, mutationOptions } = mutation[MUTATION_PARAMETERS];
|
|
203
216
|
const mutationKey = applyOrReturn__default["default"]([options], key);
|
|
204
|
-
const actionWrapper = core.
|
|
217
|
+
const actionWrapper = core.declareAction({
|
|
205
218
|
name: 'mutationExecution',
|
|
206
|
-
|
|
207
|
-
return fn(options, variables,
|
|
219
|
+
async fn(variables) {
|
|
220
|
+
return fn(options, variables, this.deps);
|
|
208
221
|
},
|
|
209
222
|
deps,
|
|
210
223
|
conditions,
|
|
224
|
+
conditionsFailResult: 'reject',
|
|
211
225
|
});
|
|
212
226
|
return {
|
|
213
227
|
...mutationOptions,
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import type { ProvideDepsIterator } from '@tinkoff/dippy';
|
|
2
2
|
import type { UseInfiniteQueryOptions, InfiniteData } from 'react-query';
|
|
3
|
-
import type {
|
|
4
|
-
import type { QUERY_CLIENT_TOKEN } from '@tramvai/module-react-query';
|
|
3
|
+
import type { TramvaiAction } from '@tramvai/core';
|
|
5
4
|
import type { BaseCreateQueryOptions, BaseQuery } from '../baseQuery/types';
|
|
6
5
|
export interface CreateInfiniteQueryOptions<Options, PageParam, Result, Deps> extends BaseCreateQueryOptions<Options, Deps> {
|
|
7
6
|
infiniteQueryOptions?: UseInfiniteQueryOptions<Result, Error>;
|
|
@@ -10,7 +9,5 @@ export interface CreateInfiniteQueryOptions<Options, PageParam, Result, Deps> ex
|
|
|
10
9
|
getPreviousPageParam?: (firstPage: Result, allPages: Result[]) => PageParam;
|
|
11
10
|
}
|
|
12
11
|
export declare type InfiniteQuery<Options, PageParam, Result, Deps> = BaseQuery<Options, CreateInfiniteQueryOptions<Options, PageParam, Result, Deps>, InfiniteQuery<Options, PageParam, Result, Deps>, UseInfiniteQueryOptions<Result, Error>> & {
|
|
13
|
-
fetchAction(options?: Options):
|
|
14
|
-
queryClient: typeof QUERY_CLIENT_TOKEN;
|
|
15
|
-
}>;
|
|
12
|
+
fetchAction(options?: Options): TramvaiAction<[], Promise<InfiniteData<Result>>, any>;
|
|
16
13
|
};
|
package/lib/query/types.d.ts
CHANGED
|
@@ -1,14 +1,11 @@
|
|
|
1
1
|
import type { ProvideDepsIterator } from '@tinkoff/dippy';
|
|
2
2
|
import type { UseQueryOptions } from 'react-query';
|
|
3
|
-
import type {
|
|
4
|
-
import type { QUERY_CLIENT_TOKEN } from '@tramvai/module-react-query';
|
|
3
|
+
import type { TramvaiAction } from '@tramvai/core';
|
|
5
4
|
import type { BaseCreateQueryOptions, BaseQuery } from '../baseQuery/types';
|
|
6
5
|
export interface CreateQueryOptions<Options, Result, Deps> extends BaseCreateQueryOptions<Options, Deps> {
|
|
7
6
|
queryOptions?: UseQueryOptions<Result, Error>;
|
|
8
7
|
fn: (options: Options, deps: ProvideDepsIterator<Deps>) => Promise<Result>;
|
|
9
8
|
}
|
|
10
9
|
export declare type Query<Options, Result, Deps> = BaseQuery<Options, CreateQueryOptions<Options, Result, Deps>, Query<Options, Result, Deps>, UseQueryOptions<Result, Error>> & {
|
|
11
|
-
fetchAction(options?: Options):
|
|
12
|
-
queryClient: typeof QUERY_CLIENT_TOKEN;
|
|
13
|
-
}>;
|
|
10
|
+
fetchAction(options?: Options): TramvaiAction<[], Promise<Result>, any>;
|
|
14
11
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tramvai/react-query",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.21.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"typings": "lib/index.d.ts",
|
|
@@ -18,13 +18,14 @@
|
|
|
18
18
|
"build-for-publish": "true"
|
|
19
19
|
},
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@tinkoff/react-hooks": "0.
|
|
22
|
-
"@tramvai/core": "2.
|
|
23
|
-
"@tramvai/module-react-query": "2.
|
|
24
|
-
"@tramvai/state": "2.
|
|
21
|
+
"@tinkoff/react-hooks": "0.1.2",
|
|
22
|
+
"@tramvai/core": "2.21.0",
|
|
23
|
+
"@tramvai/module-react-query": "2.21.0",
|
|
24
|
+
"@tramvai/state": "2.21.0",
|
|
25
|
+
"@tramvai/tokens-common": "2.21.0"
|
|
25
26
|
},
|
|
26
27
|
"peerDependencies": {
|
|
27
|
-
"@tinkoff/dippy": "0.
|
|
28
|
+
"@tinkoff/dippy": "0.8.2",
|
|
28
29
|
"@tinkoff/utils": "^2.1.2",
|
|
29
30
|
"react": ">=16.14.0",
|
|
30
31
|
"react-query": "^3.35.0",
|