@tramvai/react-query 2.150.1 → 2.151.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/__migrations__/1-react-query-creating.js +152 -0
- package/lib/baseQuery/types.d.ts +11 -3
- package/lib/infiniteQuery/types.d.ts +2 -2
- package/lib/query/types.d.ts +2 -2
- package/lib/shared/createUniqueActionKeyForQuery.es.js +6 -3
- package/lib/shared/createUniqueActionKeyForQuery.js +6 -3
- package/package.json +7 -6
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var tslib = require('tslib');
|
|
4
|
+
|
|
5
|
+
var createQueryModuleSpecifier = '@tramvai/react-query';
|
|
6
|
+
var createQueryImportSpecifier = 'createQuery';
|
|
7
|
+
var creatInfiniteQueryImportSpecifier = 'createInfiniteQuery';
|
|
8
|
+
function searchForImports(j, parsed, importSpecifierName) {
|
|
9
|
+
var result = {
|
|
10
|
+
isImported: false,
|
|
11
|
+
isImportedByName: false,
|
|
12
|
+
importedName: importSpecifierName,
|
|
13
|
+
importedDefaultName: '',
|
|
14
|
+
};
|
|
15
|
+
parsed
|
|
16
|
+
.find(j.ImportDeclaration, { source: { value: createQueryModuleSpecifier } })
|
|
17
|
+
.forEach(function (importDeclaration) {
|
|
18
|
+
result.isImported = true;
|
|
19
|
+
if (importDeclaration.value.specifiers) {
|
|
20
|
+
importDeclaration.value.specifiers.forEach(function (specifier) {
|
|
21
|
+
var _a, _b, _c;
|
|
22
|
+
// Default imports
|
|
23
|
+
if (specifier.type === 'ImportDefaultSpecifier') {
|
|
24
|
+
result.importedDefaultName = (_b = (_a = specifier.local) === null || _a === void 0 ? void 0 : _a.name) !== null && _b !== void 0 ? _b : '';
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
// Named imports
|
|
28
|
+
if (specifier.type === 'ImportSpecifier' &&
|
|
29
|
+
specifier.imported.name === importSpecifierName) {
|
|
30
|
+
result.isImportedByName = true;
|
|
31
|
+
// Named with overriding local name
|
|
32
|
+
if ((_c = specifier.local) === null || _c === void 0 ? void 0 : _c.name) {
|
|
33
|
+
result.importedName = specifier.local.name;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
return result;
|
|
40
|
+
}
|
|
41
|
+
// eslint-disable-next-line import/no-default-export
|
|
42
|
+
var _1ReactQueryCreating = (function (api) { return tslib.__awaiter(void 0, void 0, void 0, function () {
|
|
43
|
+
return tslib.__generator(this, function (_a) {
|
|
44
|
+
switch (_a.label) {
|
|
45
|
+
case 0: return [4 /*yield*/, api.transform(function (_a, _b, _c) {
|
|
46
|
+
var source = _a.source;
|
|
47
|
+
var j = _b.j;
|
|
48
|
+
var printOptions = _c.printOptions;
|
|
49
|
+
var parsed = j(source);
|
|
50
|
+
// ---------------- SEARCHING FOR THE RIGHT IMPORTS ------------------
|
|
51
|
+
var createQueryImport = searchForImports(j, parsed, createQueryImportSpecifier);
|
|
52
|
+
var createInfiniteQueryImport = searchForImports(j, parsed, creatInfiniteQueryImportSpecifier);
|
|
53
|
+
// -----------------------------------------------------------------
|
|
54
|
+
// ------- FUNCTION TO VALIDATE AND APPLY CHANGES IN PROPERTIES OF CALL EXPRESSION --------
|
|
55
|
+
var hasChanged = false;
|
|
56
|
+
var forEachCallExpression = function (callExpression) {
|
|
57
|
+
var firstArgument = callExpression.value.arguments[0];
|
|
58
|
+
var shouldAddActionNamePostfix = false;
|
|
59
|
+
var isObjectAlreadyHasActionNamePostfix = false;
|
|
60
|
+
if (!(firstArgument && firstArgument.type === 'ObjectExpression'))
|
|
61
|
+
return;
|
|
62
|
+
firstArgument.properties.forEach(function (property) {
|
|
63
|
+
// for arrow function in property
|
|
64
|
+
if (property.type === 'ObjectProperty' &&
|
|
65
|
+
property.key.type === 'Identifier' &&
|
|
66
|
+
property.key.name === 'key' &&
|
|
67
|
+
property.value.type === 'ArrowFunctionExpression') {
|
|
68
|
+
shouldAddActionNamePostfix = true;
|
|
69
|
+
}
|
|
70
|
+
// for method property
|
|
71
|
+
if (property.type === 'ObjectMethod' &&
|
|
72
|
+
property.key.type === 'Identifier' &&
|
|
73
|
+
property.key.name === 'key') {
|
|
74
|
+
shouldAddActionNamePostfix = true;
|
|
75
|
+
}
|
|
76
|
+
if (property.type === 'ObjectProperty' &&
|
|
77
|
+
property.key.type === 'Identifier' &&
|
|
78
|
+
property.key.name === 'actionNamePostfix') {
|
|
79
|
+
isObjectAlreadyHasActionNamePostfix = true;
|
|
80
|
+
}
|
|
81
|
+
return property;
|
|
82
|
+
});
|
|
83
|
+
if (shouldAddActionNamePostfix &&
|
|
84
|
+
!isObjectAlreadyHasActionNamePostfix &&
|
|
85
|
+
callExpression.parent.value.type === 'VariableDeclarator') {
|
|
86
|
+
hasChanged = true;
|
|
87
|
+
j(callExpression).replaceWith(j.callExpression(callExpression.value.callee, [
|
|
88
|
+
j.objectExpression(tslib.__spreadArray(tslib.__spreadArray([], firstArgument.properties, true), [
|
|
89
|
+
j.objectProperty(j.identifier('actionNamePostfix'), j.stringLiteral(callExpression.parent.value.id.name)),
|
|
90
|
+
], false)),
|
|
91
|
+
]));
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
// ---------------------------------------------------------------------
|
|
95
|
+
// --------- INITIATION OF RECOGNIZING CALL EXPRESSION WITH REQUIRED PROPERTIES ---------
|
|
96
|
+
if (createQueryImport.isImported) {
|
|
97
|
+
if (createQueryImport.isImportedByName) {
|
|
98
|
+
parsed
|
|
99
|
+
.find(j.CallExpression, { callee: { name: createQueryImport.importedName } })
|
|
100
|
+
.forEach(forEachCallExpression);
|
|
101
|
+
}
|
|
102
|
+
if (createQueryImport.importedDefaultName) {
|
|
103
|
+
parsed
|
|
104
|
+
.find(j.CallExpression, {
|
|
105
|
+
callee: {
|
|
106
|
+
object: {
|
|
107
|
+
name: createQueryImport.importedDefaultName,
|
|
108
|
+
},
|
|
109
|
+
property: {
|
|
110
|
+
name: createQueryImportSpecifier,
|
|
111
|
+
},
|
|
112
|
+
},
|
|
113
|
+
})
|
|
114
|
+
.forEach(forEachCallExpression);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
if (createInfiniteQueryImport.isImported) {
|
|
118
|
+
if (createInfiniteQueryImport.isImportedByName) {
|
|
119
|
+
parsed
|
|
120
|
+
.find(j.CallExpression, { callee: { name: createInfiniteQueryImport.importedName } })
|
|
121
|
+
.forEach(forEachCallExpression);
|
|
122
|
+
}
|
|
123
|
+
if (createInfiniteQueryImport.importedDefaultName) {
|
|
124
|
+
parsed
|
|
125
|
+
.find(j.CallExpression, {
|
|
126
|
+
callee: {
|
|
127
|
+
object: {
|
|
128
|
+
name: createInfiniteQueryImport.importedDefaultName,
|
|
129
|
+
},
|
|
130
|
+
property: {
|
|
131
|
+
name: creatInfiniteQueryImportSpecifier,
|
|
132
|
+
},
|
|
133
|
+
},
|
|
134
|
+
})
|
|
135
|
+
.forEach(forEachCallExpression);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
// ---------------------------------------------------------------------------
|
|
139
|
+
// --------- CHANGING FILES ---------------
|
|
140
|
+
if (hasChanged) {
|
|
141
|
+
return parsed.toSource(printOptions);
|
|
142
|
+
}
|
|
143
|
+
// ----------------------------------------
|
|
144
|
+
})];
|
|
145
|
+
case 1:
|
|
146
|
+
_a.sent();
|
|
147
|
+
return [2 /*return*/];
|
|
148
|
+
}
|
|
149
|
+
});
|
|
150
|
+
}); });
|
|
151
|
+
|
|
152
|
+
module.exports = _1ReactQueryCreating;
|
package/lib/baseQuery/types.d.ts
CHANGED
|
@@ -9,13 +9,21 @@ export interface ReactQueryContext<Deps extends ProviderDeps> {
|
|
|
9
9
|
}
|
|
10
10
|
export type ReactQueryKeyOrString = ReactQueryKey | string;
|
|
11
11
|
export type QueryKey<Options, Deps extends ProviderDeps> = ((this: ReactQueryContext<Deps>, options: Options) => ReactQueryKeyOrString) | ReactQueryKeyOrString;
|
|
12
|
-
export
|
|
13
|
-
key:
|
|
12
|
+
export type CreateQueryOptionsWithSerializableKey<Options, Deps extends ProviderDeps> = {
|
|
13
|
+
key: ReactQueryKeyOrString;
|
|
14
14
|
actionNamePostfix?: string;
|
|
15
15
|
fn: Function;
|
|
16
16
|
deps?: Deps;
|
|
17
17
|
conditions?: ActionConditionsParameters;
|
|
18
|
-
}
|
|
18
|
+
};
|
|
19
|
+
export type CreateQueryOptionsWithNonSerializableKey<Options, Deps extends ProviderDeps> = {
|
|
20
|
+
key: (this: ReactQueryContext<Deps>, options: Options) => ReactQueryKeyOrString;
|
|
21
|
+
actionNamePostfix: string;
|
|
22
|
+
fn: Function;
|
|
23
|
+
deps?: Deps;
|
|
24
|
+
conditions?: ActionConditionsParameters;
|
|
25
|
+
};
|
|
26
|
+
export type BaseCreateQueryOptions<Options, Deps extends ProviderDeps> = CreateQueryOptionsWithSerializableKey<Options, Deps> | CreateQueryOptionsWithNonSerializableKey<Options, Deps>;
|
|
19
27
|
export interface BaseQuery<Options, TCreateQuery, TQuery, TUseQuery> {
|
|
20
28
|
[QUERY_PARAMETERS]: TCreateQuery;
|
|
21
29
|
fork(options: TUseQuery): TQuery;
|
|
@@ -2,7 +2,7 @@ import type { ProvideDepsIterator, ProviderDeps } from '@tinkoff/dippy';
|
|
|
2
2
|
import type { UseInfiniteQueryOptions, InfiniteData } from '@tanstack/react-query';
|
|
3
3
|
import type { TramvaiAction } from '@tramvai/core';
|
|
4
4
|
import type { BaseCreateQueryOptions, BaseQuery, ReactQueryContext } from '../baseQuery/types';
|
|
5
|
-
export
|
|
5
|
+
export type CreateInfiniteQueryOptions<Options, PageParam, Result, Deps extends ProviderDeps> = BaseCreateQueryOptions<Options, Deps> & {
|
|
6
6
|
infiniteQueryOptions?: UseInfiniteQueryOptions<Result, Error>;
|
|
7
7
|
fn: (this: ReactQueryContext<Deps>, options: Options, pageParam: PageParam,
|
|
8
8
|
/**
|
|
@@ -11,7 +11,7 @@ export interface CreateInfiniteQueryOptions<Options, PageParam, Result, Deps ext
|
|
|
11
11
|
deps: ProvideDepsIterator<Deps>) => Promise<Result>;
|
|
12
12
|
getNextPageParam?: (lastPage: Result, allPages: Result[]) => PageParam;
|
|
13
13
|
getPreviousPageParam?: (firstPage: Result, allPages: Result[]) => PageParam;
|
|
14
|
-
}
|
|
14
|
+
};
|
|
15
15
|
export type InfiniteQuery<Options, PageParam, Result, Deps extends ProviderDeps> = BaseQuery<Options, CreateInfiniteQueryOptions<Options, PageParam, Result, Deps>, InfiniteQuery<Options, PageParam, Result, Deps>, UseInfiniteQueryOptions<Result, Error>> & {
|
|
16
16
|
fetchAction(options?: Options): TramvaiAction<[], Promise<InfiniteData<Result>>, any>;
|
|
17
17
|
};
|
package/lib/query/types.d.ts
CHANGED
|
@@ -2,14 +2,14 @@ import type { ProvideDepsIterator, ProviderDeps } from '@tinkoff/dippy';
|
|
|
2
2
|
import type { UseQueryOptions } from '@tanstack/react-query';
|
|
3
3
|
import type { TramvaiAction } from '@tramvai/core';
|
|
4
4
|
import type { BaseCreateQueryOptions, BaseQuery, ReactQueryContext } from '../baseQuery/types';
|
|
5
|
-
export
|
|
5
|
+
export type CreateQueryOptions<Options, Result, Deps extends ProviderDeps> = BaseCreateQueryOptions<Options, Deps> & {
|
|
6
6
|
queryOptions?: UseQueryOptions<Result, Error>;
|
|
7
7
|
fn: (this: ReactQueryContext<Deps>, options: Options,
|
|
8
8
|
/**
|
|
9
9
|
* @deprecated use this.deps instead
|
|
10
10
|
*/
|
|
11
11
|
deps: ProvideDepsIterator<Deps>) => Promise<Result>;
|
|
12
|
-
}
|
|
12
|
+
};
|
|
13
13
|
export type Query<Options, Result, Deps extends ProviderDeps> = BaseQuery<Options, CreateQueryOptions<Options, Result, Deps>, Query<Options, Result, Deps>, UseQueryOptions<Result, Error>> & {
|
|
14
14
|
fetchAction(options?: Options): TramvaiAction<[], Promise<Result>, any>;
|
|
15
15
|
};
|
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import { normalizeKey } from './normalizeKey.es.js';
|
|
2
2
|
|
|
3
|
+
function isSerializableKey(options) {
|
|
4
|
+
return !('actionNamePostfix' in options);
|
|
5
|
+
}
|
|
3
6
|
const createUniqueActionKeyForQuery = (queryParameters) => {
|
|
4
7
|
var _a;
|
|
5
|
-
const rawQueryKey =
|
|
6
|
-
? queryParameters.actionNamePostfix
|
|
7
|
-
:
|
|
8
|
+
const rawQueryKey = isSerializableKey(queryParameters)
|
|
9
|
+
? (_a = queryParameters.actionNamePostfix) !== null && _a !== void 0 ? _a : queryParameters.key
|
|
10
|
+
: queryParameters.actionNamePostfix;
|
|
8
11
|
const queryKeyArray = normalizeKey(rawQueryKey);
|
|
9
12
|
return queryKeyArray.join('_');
|
|
10
13
|
};
|
|
@@ -4,11 +4,14 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
var normalizeKey = require('./normalizeKey.js');
|
|
6
6
|
|
|
7
|
+
function isSerializableKey(options) {
|
|
8
|
+
return !('actionNamePostfix' in options);
|
|
9
|
+
}
|
|
7
10
|
const createUniqueActionKeyForQuery = (queryParameters) => {
|
|
8
11
|
var _a;
|
|
9
|
-
const rawQueryKey =
|
|
10
|
-
? queryParameters.actionNamePostfix
|
|
11
|
-
:
|
|
12
|
+
const rawQueryKey = isSerializableKey(queryParameters)
|
|
13
|
+
? (_a = queryParameters.actionNamePostfix) !== null && _a !== void 0 ? _a : queryParameters.key
|
|
14
|
+
: queryParameters.actionNamePostfix;
|
|
12
15
|
const queryKeyArray = normalizeKey.normalizeKey(rawQueryKey);
|
|
13
16
|
return queryKeyArray.join('_');
|
|
14
17
|
};
|
package/package.json
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tramvai/react-query",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.151.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"typings": "lib/index.d.ts",
|
|
7
7
|
"files": [
|
|
8
|
-
"lib"
|
|
8
|
+
"lib",
|
|
9
|
+
"__migrations__"
|
|
9
10
|
],
|
|
10
11
|
"sideEffects": false,
|
|
11
12
|
"repository": {
|
|
@@ -18,10 +19,10 @@
|
|
|
18
19
|
},
|
|
19
20
|
"dependencies": {
|
|
20
21
|
"@tinkoff/react-hooks": "0.1.6",
|
|
21
|
-
"@tramvai/core": "2.
|
|
22
|
-
"@tramvai/module-react-query": "2.
|
|
23
|
-
"@tramvai/react": "2.
|
|
24
|
-
"@tramvai/tokens-common": "2.
|
|
22
|
+
"@tramvai/core": "2.151.0",
|
|
23
|
+
"@tramvai/module-react-query": "2.151.0",
|
|
24
|
+
"@tramvai/react": "2.151.0",
|
|
25
|
+
"@tramvai/tokens-common": "2.151.0"
|
|
25
26
|
},
|
|
26
27
|
"peerDependencies": {
|
|
27
28
|
"@tinkoff/dippy": "0.8.16",
|