@leancodepl/react-query-cqrs-client 7.2.3 → 7.3.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/index.cjs.default.js +1 -0
- package/index.cjs.js +11 -23
- package/index.cjs.mjs +2 -0
- package/index.esm.js +11 -23
- package/package.json +13 -6
- package/src/lib/mkCqrsClient.d.ts +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
exports._default = require('./index.cjs.js').default;
|
package/index.cjs.js
CHANGED
|
@@ -34,14 +34,12 @@ function _object_without_properties_loose(source, excluded) {
|
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
function authGuard(tokenProvider) {
|
|
37
|
-
|
|
38
|
-
if (!((_tokenProvider = tokenProvider) == null ? void 0 : _tokenProvider.invalidateToken)) {
|
|
37
|
+
if (!(tokenProvider == null ? void 0 : tokenProvider.invalidateToken)) {
|
|
39
38
|
return (response)=>response;
|
|
40
39
|
}
|
|
41
40
|
return (response)=>response.pipe(rxjs.catchError((error)=>{
|
|
42
41
|
if (error.status === 401) {
|
|
43
|
-
|
|
44
|
-
(_tokenProvider_invalidateToken = (_tokenProvider = tokenProvider).invalidateToken) == null ? void 0 : _tokenProvider_invalidateToken.call(_tokenProvider);
|
|
42
|
+
tokenProvider.invalidateToken == null ? void 0 : tokenProvider.invalidateToken.call(tokenProvider);
|
|
45
43
|
}
|
|
46
44
|
return rxjs.throwError(()=>error);
|
|
47
45
|
}));
|
|
@@ -63,10 +61,8 @@ function uncapitalizedParse() {
|
|
|
63
61
|
}
|
|
64
62
|
function mkCqrsClient({ cqrsEndpoint, queryClient, tokenProvider, ajaxOptions }) {
|
|
65
63
|
function mkFetcher(endpoint, config = {}) {
|
|
66
|
-
var _tokenProvider;
|
|
67
|
-
var _ajaxOptions_withCredentials;
|
|
68
64
|
const apiCall = (data, token)=>{
|
|
69
|
-
var
|
|
65
|
+
var _ajaxOptions_withCredentials;
|
|
70
66
|
return ajax.ajax(_extends({}, ajaxOptions, config, {
|
|
71
67
|
headers: {
|
|
72
68
|
Authorization: token,
|
|
@@ -75,10 +71,10 @@ function mkCqrsClient({ cqrsEndpoint, queryClient, tokenProvider, ajaxOptions })
|
|
|
75
71
|
url: `${cqrsEndpoint}/${endpoint}`,
|
|
76
72
|
method: "POST",
|
|
77
73
|
body: data,
|
|
78
|
-
withCredentials: (_ajaxOptions_withCredentials =
|
|
74
|
+
withCredentials: (_ajaxOptions_withCredentials = ajaxOptions == null ? void 0 : ajaxOptions.withCredentials) != null ? _ajaxOptions_withCredentials : true
|
|
79
75
|
}));
|
|
80
76
|
};
|
|
81
|
-
const getToken =
|
|
77
|
+
const getToken = tokenProvider == null ? void 0 : tokenProvider.getToken;
|
|
82
78
|
const mk$apiCall = (data, token)=>apiCall(data, token).pipe(authGuard(tokenProvider), operators.map((result)=>result.response));
|
|
83
79
|
if (getToken) {
|
|
84
80
|
return (data)=>rxjs.from(getToken()).pipe(operators.mergeMap((token)=>mk$apiCall(data, token)));
|
|
@@ -96,15 +92,12 @@ function mkCqrsClient({ cqrsEndpoint, queryClient, tokenProvider, ajaxOptions })
|
|
|
96
92
|
queryFn: (context)=>rxjs.firstValueFrom(useApiQuery.fetcher(data, context))
|
|
97
93
|
}, options), queryClient);
|
|
98
94
|
}
|
|
99
|
-
useApiQuery.fetcher = (data, context)=>
|
|
100
|
-
var _context;
|
|
101
|
-
return rxjs.race([
|
|
95
|
+
useApiQuery.fetcher = (data, context)=>rxjs.race([
|
|
102
96
|
fetcher(data).pipe(uncapitalizedParse()),
|
|
103
|
-
...(
|
|
97
|
+
...(context == null ? void 0 : context.signal) ? [
|
|
104
98
|
rxjs.fromEvent(context.signal, "abort").pipe(operators.mergeMap(()=>rxjs.throwError(()=>new Error("Query aborted"))))
|
|
105
99
|
] : []
|
|
106
100
|
]);
|
|
107
|
-
};
|
|
108
101
|
useApiQuery.fetch = (data, options)=>queryClient.fetchQuery(_extends({
|
|
109
102
|
queryKey: useApiQuery.key(data),
|
|
110
103
|
queryFn: (context)=>rxjs.firstValueFrom(useApiQuery.fetcher(data, context))
|
|
@@ -122,12 +115,9 @@ function mkCqrsClient({ cqrsEndpoint, queryClient, tokenProvider, ajaxOptions })
|
|
|
122
115
|
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
123
116
|
return reactQuery.useInfiniteQuery(_extends({
|
|
124
117
|
queryKey: useApiQuery.key(data),
|
|
125
|
-
queryFn: (context)=>{
|
|
126
|
-
var _options;
|
|
127
|
-
return rxjs.firstValueFrom(useApiQuery.fetcher(((_options = options) == null ? void 0 : _options.pageParamKey) ? _extends({}, data, {
|
|
118
|
+
queryFn: (context)=>rxjs.firstValueFrom(useApiQuery.fetcher((options == null ? void 0 : options.pageParamKey) ? _extends({}, data, {
|
|
128
119
|
[options.pageParamKey]: context.pageParam
|
|
129
|
-
}) : data, context))
|
|
130
|
-
}
|
|
120
|
+
}) : data, context))
|
|
131
121
|
}, options), queryClient);
|
|
132
122
|
};
|
|
133
123
|
useApiQuery.key = (query)=>[
|
|
@@ -168,8 +158,7 @@ function mkCqrsClient({ cqrsEndpoint, queryClient, tokenProvider, ajaxOptions })
|
|
|
168
158
|
mutationFn: (variables)=>rxjs.firstValueFrom(useApiOperation.fetcher(variables))
|
|
169
159
|
}, options, {
|
|
170
160
|
async onSuccess (data, variables, context) {
|
|
171
|
-
|
|
172
|
-
const result = await ((_onSuccessBase = onSuccessBase) == null ? void 0 : _onSuccessBase(data, variables, context));
|
|
161
|
+
const result = await (onSuccessBase == null ? void 0 : onSuccessBase(data, variables, context));
|
|
173
162
|
invalidateQueries && await Promise.allSettled(invalidateQueries.map((queryKey)=>queryClient.invalidateQueries({
|
|
174
163
|
queryKey
|
|
175
164
|
})));
|
|
@@ -200,11 +189,10 @@ function mkCqrsClient({ cqrsEndpoint, queryClient, tokenProvider, ajaxOptions })
|
|
|
200
189
|
}
|
|
201
190
|
}, options, {
|
|
202
191
|
async onSuccess (data, variables, context) {
|
|
203
|
-
var _onSuccess;
|
|
204
192
|
invalidateQueries && await Promise.allSettled(invalidateQueries.map((queryKey)=>queryClient.invalidateQueries({
|
|
205
193
|
queryKey
|
|
206
194
|
})));
|
|
207
|
-
const result = await (
|
|
195
|
+
const result = await (onSuccess == null ? void 0 : onSuccess(data, variables, context));
|
|
208
196
|
return result;
|
|
209
197
|
}
|
|
210
198
|
}), queryClient);
|
package/index.cjs.mjs
ADDED
package/index.esm.js
CHANGED
|
@@ -30,14 +30,12 @@ function _object_without_properties_loose(source, excluded) {
|
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
function authGuard(tokenProvider) {
|
|
33
|
-
|
|
34
|
-
if (!((_tokenProvider = tokenProvider) == null ? void 0 : _tokenProvider.invalidateToken)) {
|
|
33
|
+
if (!(tokenProvider == null ? void 0 : tokenProvider.invalidateToken)) {
|
|
35
34
|
return (response)=>response;
|
|
36
35
|
}
|
|
37
36
|
return (response)=>response.pipe(catchError((error)=>{
|
|
38
37
|
if (error.status === 401) {
|
|
39
|
-
|
|
40
|
-
(_tokenProvider_invalidateToken = (_tokenProvider = tokenProvider).invalidateToken) == null ? void 0 : _tokenProvider_invalidateToken.call(_tokenProvider);
|
|
38
|
+
tokenProvider.invalidateToken == null ? void 0 : tokenProvider.invalidateToken.call(tokenProvider);
|
|
41
39
|
}
|
|
42
40
|
return throwError(()=>error);
|
|
43
41
|
}));
|
|
@@ -59,10 +57,8 @@ function uncapitalizedParse() {
|
|
|
59
57
|
}
|
|
60
58
|
function mkCqrsClient({ cqrsEndpoint, queryClient, tokenProvider, ajaxOptions }) {
|
|
61
59
|
function mkFetcher(endpoint, config = {}) {
|
|
62
|
-
var _tokenProvider;
|
|
63
|
-
var _ajaxOptions_withCredentials;
|
|
64
60
|
const apiCall = (data, token)=>{
|
|
65
|
-
var
|
|
61
|
+
var _ajaxOptions_withCredentials;
|
|
66
62
|
return ajax(_extends({}, ajaxOptions, config, {
|
|
67
63
|
headers: {
|
|
68
64
|
Authorization: token,
|
|
@@ -71,10 +67,10 @@ function mkCqrsClient({ cqrsEndpoint, queryClient, tokenProvider, ajaxOptions })
|
|
|
71
67
|
url: `${cqrsEndpoint}/${endpoint}`,
|
|
72
68
|
method: "POST",
|
|
73
69
|
body: data,
|
|
74
|
-
withCredentials: (_ajaxOptions_withCredentials =
|
|
70
|
+
withCredentials: (_ajaxOptions_withCredentials = ajaxOptions == null ? void 0 : ajaxOptions.withCredentials) != null ? _ajaxOptions_withCredentials : true
|
|
75
71
|
}));
|
|
76
72
|
};
|
|
77
|
-
const getToken =
|
|
73
|
+
const getToken = tokenProvider == null ? void 0 : tokenProvider.getToken;
|
|
78
74
|
const mk$apiCall = (data, token)=>apiCall(data, token).pipe(authGuard(tokenProvider), map((result)=>result.response));
|
|
79
75
|
if (getToken) {
|
|
80
76
|
return (data)=>from(getToken()).pipe(mergeMap((token)=>mk$apiCall(data, token)));
|
|
@@ -92,15 +88,12 @@ function mkCqrsClient({ cqrsEndpoint, queryClient, tokenProvider, ajaxOptions })
|
|
|
92
88
|
queryFn: (context)=>firstValueFrom(useApiQuery.fetcher(data, context))
|
|
93
89
|
}, options), queryClient);
|
|
94
90
|
}
|
|
95
|
-
useApiQuery.fetcher = (data, context)=>
|
|
96
|
-
var _context;
|
|
97
|
-
return race([
|
|
91
|
+
useApiQuery.fetcher = (data, context)=>race([
|
|
98
92
|
fetcher(data).pipe(uncapitalizedParse()),
|
|
99
|
-
...(
|
|
93
|
+
...(context == null ? void 0 : context.signal) ? [
|
|
100
94
|
fromEvent(context.signal, "abort").pipe(mergeMap(()=>throwError(()=>new Error("Query aborted"))))
|
|
101
95
|
] : []
|
|
102
96
|
]);
|
|
103
|
-
};
|
|
104
97
|
useApiQuery.fetch = (data, options)=>queryClient.fetchQuery(_extends({
|
|
105
98
|
queryKey: useApiQuery.key(data),
|
|
106
99
|
queryFn: (context)=>firstValueFrom(useApiQuery.fetcher(data, context))
|
|
@@ -118,12 +111,9 @@ function mkCqrsClient({ cqrsEndpoint, queryClient, tokenProvider, ajaxOptions })
|
|
|
118
111
|
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
119
112
|
return useInfiniteQuery(_extends({
|
|
120
113
|
queryKey: useApiQuery.key(data),
|
|
121
|
-
queryFn: (context)=>{
|
|
122
|
-
var _options;
|
|
123
|
-
return firstValueFrom(useApiQuery.fetcher(((_options = options) == null ? void 0 : _options.pageParamKey) ? _extends({}, data, {
|
|
114
|
+
queryFn: (context)=>firstValueFrom(useApiQuery.fetcher((options == null ? void 0 : options.pageParamKey) ? _extends({}, data, {
|
|
124
115
|
[options.pageParamKey]: context.pageParam
|
|
125
|
-
}) : data, context))
|
|
126
|
-
}
|
|
116
|
+
}) : data, context))
|
|
127
117
|
}, options), queryClient);
|
|
128
118
|
};
|
|
129
119
|
useApiQuery.key = (query)=>[
|
|
@@ -164,8 +154,7 @@ function mkCqrsClient({ cqrsEndpoint, queryClient, tokenProvider, ajaxOptions })
|
|
|
164
154
|
mutationFn: (variables)=>firstValueFrom(useApiOperation.fetcher(variables))
|
|
165
155
|
}, options, {
|
|
166
156
|
async onSuccess (data, variables, context) {
|
|
167
|
-
|
|
168
|
-
const result = await ((_onSuccessBase = onSuccessBase) == null ? void 0 : _onSuccessBase(data, variables, context));
|
|
157
|
+
const result = await (onSuccessBase == null ? void 0 : onSuccessBase(data, variables, context));
|
|
169
158
|
invalidateQueries && await Promise.allSettled(invalidateQueries.map((queryKey)=>queryClient.invalidateQueries({
|
|
170
159
|
queryKey
|
|
171
160
|
})));
|
|
@@ -196,11 +185,10 @@ function mkCqrsClient({ cqrsEndpoint, queryClient, tokenProvider, ajaxOptions })
|
|
|
196
185
|
}
|
|
197
186
|
}, options, {
|
|
198
187
|
async onSuccess (data, variables, context) {
|
|
199
|
-
var _onSuccess;
|
|
200
188
|
invalidateQueries && await Promise.allSettled(invalidateQueries.map((queryKey)=>queryClient.invalidateQueries({
|
|
201
189
|
queryKey
|
|
202
190
|
})));
|
|
203
|
-
const result = await (
|
|
191
|
+
const result = await (onSuccess == null ? void 0 : onSuccess(data, variables, context));
|
|
204
192
|
return result;
|
|
205
193
|
}
|
|
206
194
|
}), queryClient);
|
package/package.json
CHANGED
|
@@ -1,14 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leancodepl/react-query-cqrs-client",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.3.0",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"dependencies": {
|
|
6
|
-
"@leancodepl/utils": "7.
|
|
7
|
-
"@leancodepl/validation": "7.
|
|
6
|
+
"@leancodepl/utils": "7.3.0",
|
|
7
|
+
"@leancodepl/validation": "7.3.0",
|
|
8
8
|
"@tanstack/react-query": ">=5.0.0",
|
|
9
9
|
"rxjs": ">=7.0.0"
|
|
10
10
|
},
|
|
11
|
-
"
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
"exports": {
|
|
12
|
+
"./package.json": "./package.json",
|
|
13
|
+
".": {
|
|
14
|
+
"module": "./index.esm.js",
|
|
15
|
+
"import": "./index.cjs.mjs",
|
|
16
|
+
"default": "./index.cjs.js"
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
"module": "./index.esm.js",
|
|
20
|
+
"main": "./index.cjs.js"
|
|
14
21
|
}
|
|
@@ -18,7 +18,7 @@ export declare function mkCqrsClient({ cqrsEndpoint, queryClient, tokenProvider,
|
|
|
18
18
|
lazy<TContext = unknown>(options?: Omit<UseMutationOptions<NullableUncapitalizeDeep<TResult>, unknown, TQuery, TContext>, "mutationFn" | "mutationKey">): UseMutationResult<NullableUncapitalizeDeep<TResult>, unknown, TQuery, TContext>;
|
|
19
19
|
infinite(data: TQuery, options: Omit<UndefinedInitialDataInfiniteOptions<NullableUncapitalizeDeep<TResult>, unknown>, "queryKey" | "queryFn"> & {
|
|
20
20
|
pageParamKey?: keyof TQuery | undefined;
|
|
21
|
-
}): import("@tanstack/react-query/build/legacy/types").UseInfiniteQueryResult<import("@tanstack/query-core/build/legacy/queryClient-
|
|
21
|
+
}): import("@tanstack/react-query/build/legacy/types").UseInfiniteQueryResult<import("@tanstack/query-core/build/legacy/queryClient-IoYjXsnV").z<NullableUncapitalizeDeep<TResult>, unknown>, unknown>;
|
|
22
22
|
key(query: Partial<TQuery>): readonly [string, Partial<TQuery>];
|
|
23
23
|
setQueryData: {
|
|
24
24
|
(query: TQuery, updater: Updater<NullableUncapitalizeDeep<TResult> | undefined, NullableUncapitalizeDeep<TResult> | undefined>): NullableUncapitalizeDeep<TResult> | undefined;
|