@leancodepl/react-query-cqrs-client 9.6.2 → 9.6.4
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.js +15 -14
- package/index.esm.js +15 -14
- package/package.json +4 -4
- package/src/lib/mkCqrsClient.d.ts +18 -18
package/index.cjs.js
CHANGED
|
@@ -59,11 +59,11 @@ function uncapitalizedParse() {
|
|
|
59
59
|
}
|
|
60
60
|
/**
|
|
61
61
|
* Creates React Query CQRS client with hooks for queries, operations, and commands.
|
|
62
|
-
*
|
|
62
|
+
*
|
|
63
63
|
* Integrates with React Query to provide caching, background updates, and optimistic updates
|
|
64
64
|
* for CQRS operations. Automatically handles authentication, retries, and response transformation
|
|
65
65
|
* with uncapitalized keys.
|
|
66
|
-
*
|
|
66
|
+
*
|
|
67
67
|
* @param cqrsEndpoint - Base URL for CQRS API endpoints
|
|
68
68
|
* @param queryClient - React Query client instance
|
|
69
69
|
* @param tokenProvider - Optional token provider for authentication
|
|
@@ -136,7 +136,7 @@ function uncapitalizedParse() {
|
|
|
136
136
|
queryKey: [
|
|
137
137
|
type
|
|
138
138
|
],
|
|
139
|
-
queryFn:
|
|
139
|
+
queryFn: (context)=>rxjs.firstValueFrom(useApiQuery.fetcher(context.pageParam, context)),
|
|
140
140
|
initialPageParam: initialPageData
|
|
141
141
|
}, options), queryClient);
|
|
142
142
|
};
|
|
@@ -187,8 +187,8 @@ function uncapitalizedParse() {
|
|
|
187
187
|
mutationKey: useApiOperation.key,
|
|
188
188
|
mutationFn: (variables)=>rxjs.firstValueFrom(useApiOperation.fetcher(variables))
|
|
189
189
|
}, options, {
|
|
190
|
-
async onSuccess (data, variables, context) {
|
|
191
|
-
const result = await (onSuccessBase == null ? void 0 : onSuccessBase(data, variables, context));
|
|
190
|
+
async onSuccess (data, variables, onMutateResult, context) {
|
|
191
|
+
const result = await (onSuccessBase == null ? void 0 : onSuccessBase(data, variables, onMutateResult, context));
|
|
192
192
|
if (invalidateQueries) {
|
|
193
193
|
await Promise.allSettled(invalidateQueries.map((queryKey)=>queryClient.invalidateQueries({
|
|
194
194
|
queryKey
|
|
@@ -219,26 +219,27 @@ function uncapitalizedParse() {
|
|
|
219
219
|
return reactQuery.useMutation(_extends({}, options, {
|
|
220
220
|
mutationKey: useApiCommand.key,
|
|
221
221
|
mutationFn: (variables)=>rxjs.firstValueFrom(useApiCommand.call(variables, handler)),
|
|
222
|
-
async onMutate (variables) {
|
|
222
|
+
async onMutate (variables, context) {
|
|
223
223
|
// there's really no good way to do it without type cast
|
|
224
|
-
const
|
|
224
|
+
const baseResult = await (onMutate == null ? void 0 : onMutate(variables, context));
|
|
225
225
|
var _optimisticUpdate;
|
|
226
226
|
const optimisticUpdateReverts = await Promise.all((_optimisticUpdate = optimisticUpdate == null ? void 0 : optimisticUpdate(variables)) != null ? _optimisticUpdate : []);
|
|
227
|
-
return _extends({},
|
|
227
|
+
return _extends({}, baseResult, {
|
|
228
228
|
revertOptimisticUpdate: ()=>optimisticUpdateReverts.forEach((revertOptimisticUpdate)=>revertOptimisticUpdate())
|
|
229
229
|
});
|
|
230
230
|
},
|
|
231
|
-
async onError (error, variables, context) {
|
|
232
|
-
await (onError == null ? void 0 : onError(error, variables, context));
|
|
233
|
-
|
|
231
|
+
async onError (error, variables, onMutateResult, context) {
|
|
232
|
+
await (onError == null ? void 0 : onError(error, variables, onMutateResult, context));
|
|
233
|
+
onMutateResult == null ? void 0 : onMutateResult.revertOptimisticUpdate();
|
|
234
234
|
},
|
|
235
|
-
|
|
235
|
+
// eslint-disable-next-line max-params
|
|
236
|
+
async onSettled (data, error, variables, onMutateResult, context) {
|
|
236
237
|
if (invalidateQueries) {
|
|
237
238
|
await Promise.allSettled(invalidateQueries.map((queryKey)=>queryClient.invalidateQueries({
|
|
238
239
|
queryKey
|
|
239
240
|
})));
|
|
240
241
|
}
|
|
241
|
-
return await (onSettled == null ? void 0 : onSettled(data, error, variables, context));
|
|
242
|
+
return await (onSettled == null ? void 0 : onSettled(data, error, variables, onMutateResult, context));
|
|
242
243
|
}
|
|
243
244
|
}), queryClient);
|
|
244
245
|
}
|
|
@@ -246,7 +247,7 @@ function uncapitalizedParse() {
|
|
|
246
247
|
useApiCommand.key = [
|
|
247
248
|
useApiCommand.type
|
|
248
249
|
];
|
|
249
|
-
useApiCommand.fetcher =
|
|
250
|
+
useApiCommand.fetcher = fetcher;
|
|
250
251
|
useApiCommand.call = (variables, handler)=>{
|
|
251
252
|
const $response = useApiCommand.fetcher(variables);
|
|
252
253
|
return $response.pipe(operators.map((result)=>({
|
package/index.esm.js
CHANGED
|
@@ -57,11 +57,11 @@ function uncapitalizedParse() {
|
|
|
57
57
|
}
|
|
58
58
|
/**
|
|
59
59
|
* Creates React Query CQRS client with hooks for queries, operations, and commands.
|
|
60
|
-
*
|
|
60
|
+
*
|
|
61
61
|
* Integrates with React Query to provide caching, background updates, and optimistic updates
|
|
62
62
|
* for CQRS operations. Automatically handles authentication, retries, and response transformation
|
|
63
63
|
* with uncapitalized keys.
|
|
64
|
-
*
|
|
64
|
+
*
|
|
65
65
|
* @param cqrsEndpoint - Base URL for CQRS API endpoints
|
|
66
66
|
* @param queryClient - React Query client instance
|
|
67
67
|
* @param tokenProvider - Optional token provider for authentication
|
|
@@ -134,7 +134,7 @@ function uncapitalizedParse() {
|
|
|
134
134
|
queryKey: [
|
|
135
135
|
type
|
|
136
136
|
],
|
|
137
|
-
queryFn:
|
|
137
|
+
queryFn: (context)=>firstValueFrom(useApiQuery.fetcher(context.pageParam, context)),
|
|
138
138
|
initialPageParam: initialPageData
|
|
139
139
|
}, options), queryClient);
|
|
140
140
|
};
|
|
@@ -185,8 +185,8 @@ function uncapitalizedParse() {
|
|
|
185
185
|
mutationKey: useApiOperation.key,
|
|
186
186
|
mutationFn: (variables)=>firstValueFrom(useApiOperation.fetcher(variables))
|
|
187
187
|
}, options, {
|
|
188
|
-
async onSuccess (data, variables, context) {
|
|
189
|
-
const result = await (onSuccessBase == null ? void 0 : onSuccessBase(data, variables, context));
|
|
188
|
+
async onSuccess (data, variables, onMutateResult, context) {
|
|
189
|
+
const result = await (onSuccessBase == null ? void 0 : onSuccessBase(data, variables, onMutateResult, context));
|
|
190
190
|
if (invalidateQueries) {
|
|
191
191
|
await Promise.allSettled(invalidateQueries.map((queryKey)=>queryClient.invalidateQueries({
|
|
192
192
|
queryKey
|
|
@@ -217,26 +217,27 @@ function uncapitalizedParse() {
|
|
|
217
217
|
return useMutation(_extends({}, options, {
|
|
218
218
|
mutationKey: useApiCommand.key,
|
|
219
219
|
mutationFn: (variables)=>firstValueFrom(useApiCommand.call(variables, handler)),
|
|
220
|
-
async onMutate (variables) {
|
|
220
|
+
async onMutate (variables, context) {
|
|
221
221
|
// there's really no good way to do it without type cast
|
|
222
|
-
const
|
|
222
|
+
const baseResult = await (onMutate == null ? void 0 : onMutate(variables, context));
|
|
223
223
|
var _optimisticUpdate;
|
|
224
224
|
const optimisticUpdateReverts = await Promise.all((_optimisticUpdate = optimisticUpdate == null ? void 0 : optimisticUpdate(variables)) != null ? _optimisticUpdate : []);
|
|
225
|
-
return _extends({},
|
|
225
|
+
return _extends({}, baseResult, {
|
|
226
226
|
revertOptimisticUpdate: ()=>optimisticUpdateReverts.forEach((revertOptimisticUpdate)=>revertOptimisticUpdate())
|
|
227
227
|
});
|
|
228
228
|
},
|
|
229
|
-
async onError (error, variables, context) {
|
|
230
|
-
await (onError == null ? void 0 : onError(error, variables, context));
|
|
231
|
-
|
|
229
|
+
async onError (error, variables, onMutateResult, context) {
|
|
230
|
+
await (onError == null ? void 0 : onError(error, variables, onMutateResult, context));
|
|
231
|
+
onMutateResult == null ? void 0 : onMutateResult.revertOptimisticUpdate();
|
|
232
232
|
},
|
|
233
|
-
|
|
233
|
+
// eslint-disable-next-line max-params
|
|
234
|
+
async onSettled (data, error, variables, onMutateResult, context) {
|
|
234
235
|
if (invalidateQueries) {
|
|
235
236
|
await Promise.allSettled(invalidateQueries.map((queryKey)=>queryClient.invalidateQueries({
|
|
236
237
|
queryKey
|
|
237
238
|
})));
|
|
238
239
|
}
|
|
239
|
-
return await (onSettled == null ? void 0 : onSettled(data, error, variables, context));
|
|
240
|
+
return await (onSettled == null ? void 0 : onSettled(data, error, variables, onMutateResult, context));
|
|
240
241
|
}
|
|
241
242
|
}), queryClient);
|
|
242
243
|
}
|
|
@@ -244,7 +245,7 @@ function uncapitalizedParse() {
|
|
|
244
245
|
useApiCommand.key = [
|
|
245
246
|
useApiCommand.type
|
|
246
247
|
];
|
|
247
|
-
useApiCommand.fetcher =
|
|
248
|
+
useApiCommand.fetcher = fetcher;
|
|
248
249
|
useApiCommand.call = (variables, handler)=>{
|
|
249
250
|
const $response = useApiCommand.fetcher(variables);
|
|
250
251
|
return $response.pipe(map((result)=>({
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leancodepl/react-query-cqrs-client",
|
|
3
|
-
"version": "9.6.
|
|
3
|
+
"version": "9.6.4",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"dependencies": {
|
|
6
|
-
"@leancodepl/cqrs-client-base": "9.6.
|
|
7
|
-
"@leancodepl/utils": "9.6.
|
|
8
|
-
"@leancodepl/validation": "9.6.
|
|
6
|
+
"@leancodepl/cqrs-client-base": "9.6.4",
|
|
7
|
+
"@leancodepl/utils": "9.6.4",
|
|
8
|
+
"@leancodepl/validation": "9.6.4",
|
|
9
9
|
"@tanstack/react-query": ">=5.0.0",
|
|
10
10
|
"rxjs": ">=7.0.0"
|
|
11
11
|
},
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { FetchQueryOptions, InfiniteData, QueryClient, QueryFunctionContext, QueryKey, UndefinedInitialDataInfiniteOptions, UndefinedInitialDataOptions, Updater, UseMutationOptions, UseMutationResult } from "@tanstack/react-query";
|
|
1
|
+
import { DefaultError, FetchQueryOptions, InfiniteData, QueryClient, QueryFunctionContext, QueryKey, UndefinedInitialDataInfiniteOptions, UndefinedInitialDataOptions, Updater, UseMutationOptions, UseMutationResult } from "@tanstack/react-query";
|
|
2
2
|
import { Observable, OperatorFunction } from "rxjs";
|
|
3
3
|
import { AjaxConfig } from "rxjs/ajax";
|
|
4
4
|
import { ApiResponse, ApiSuccess, CommandResult, FailedCommandResult, SuccessfulCommandResult, TokenProvider } from "@leancodepl/cqrs-client-base";
|
|
@@ -34,52 +34,52 @@ export declare function mkCqrsClient({ cqrsEndpoint, queryClient, tokenProvider,
|
|
|
34
34
|
tokenHeader?: string;
|
|
35
35
|
}): {
|
|
36
36
|
createQuery<TQuery, TResult>(type: string): {
|
|
37
|
-
(data: TQuery, options?: Omit<UndefinedInitialDataOptions<NullableUncapitalizeDeep<TResult>,
|
|
37
|
+
(data: TQuery, options?: Omit<UndefinedInitialDataOptions<NullableUncapitalizeDeep<TResult>, DefaultError, NullableUncapitalizeDeep<TResult>, readonly [string, (Partial<TQuery> | undefined)?]>, "queryFn" | "queryKey">): import("@tanstack/react-query").UseQueryResult<import("@tanstack/react-query").NoInfer<NullableUncapitalizeDeep<TResult>>, Error>;
|
|
38
38
|
type: string;
|
|
39
|
-
fetcher(data: TQuery, context?: QueryFunctionContext<
|
|
40
|
-
fetch(data: TQuery, options?: Omit<FetchQueryOptions<NullableUncapitalizeDeep<TResult>,
|
|
41
|
-
lazy<
|
|
42
|
-
infinite(initialPageData: TQuery, options: Omit<UndefinedInitialDataInfiniteOptions<NullableUncapitalizeDeep<TResult>,
|
|
43
|
-
key(query: Partial<TQuery>): readonly [string, Partial<TQuery>];
|
|
39
|
+
fetcher(data: TQuery, context?: QueryFunctionContext<readonly [string, (Partial<TQuery> | undefined)?]>): Observable<NullableUncapitalizeDeep<TResult>>;
|
|
40
|
+
fetch(data: TQuery, options?: Omit<FetchQueryOptions<NullableUncapitalizeDeep<TResult>, DefaultError, NullableUncapitalizeDeep<TResult>, readonly [string, (Partial<TQuery> | undefined)?]>, "queryFn" | "queryKey">): Promise<NullableUncapitalizeDeep<TResult>>;
|
|
41
|
+
lazy<TOnMutateResult = unknown>(options?: Omit<UseMutationOptions<NullableUncapitalizeDeep<TResult>, DefaultError, TQuery, TOnMutateResult>, "mutationFn" | "mutationKey">): UseMutationResult<NullableUncapitalizeDeep<TResult>, Error, TQuery, TOnMutateResult>;
|
|
42
|
+
infinite(initialPageData: TQuery, options: Omit<UndefinedInitialDataInfiniteOptions<NullableUncapitalizeDeep<TResult>, DefaultError, InfiniteData<NullableUncapitalizeDeep<TResult>>, readonly [string, (Partial<TQuery> | undefined)?], TQuery>, "initialPageParam" | "queryFn" | "queryKey" | "select">): import("@tanstack/react-query").UseInfiniteQueryResult<InfiniteData<NullableUncapitalizeDeep<TResult>, TQuery>, Error>;
|
|
43
|
+
key(query: Partial<TQuery>): readonly [string, (Partial<TQuery> | undefined)?];
|
|
44
44
|
setQueryData: {
|
|
45
45
|
(query: TQuery, updater: Updater<NullableUncapitalizeDeep<TResult> | undefined, NullableUncapitalizeDeep<TResult> | undefined>): NullableUncapitalizeDeep<TResult> | undefined;
|
|
46
|
-
(queryKey:
|
|
46
|
+
(queryKey: readonly [string, (Partial<TQuery> | undefined)?], updater: Updater<NullableUncapitalizeDeep<TResult> | undefined, NullableUncapitalizeDeep<TResult> | undefined>): NullableUncapitalizeDeep<TResult> | undefined;
|
|
47
47
|
};
|
|
48
48
|
setQueriesData(query: Partial<TQuery>, updater: Updater<NullableUncapitalizeDeep<TResult> | undefined, NullableUncapitalizeDeep<TResult> | undefined>): [readonly unknown[], unknown][];
|
|
49
49
|
getQueryData(query: TQuery): NullableUncapitalizeDeep<TResult> | undefined;
|
|
50
50
|
getQueriesData(query: Partial<TQuery>): [readonly unknown[], NullableUncapitalizeDeep<TResult> | undefined][];
|
|
51
|
-
prefetch(data: TQuery, options?: Omit<FetchQueryOptions<NullableUncapitalizeDeep<TResult>,
|
|
51
|
+
prefetch(data: TQuery, options?: Omit<FetchQueryOptions<NullableUncapitalizeDeep<TResult>, DefaultError, NullableUncapitalizeDeep<TResult>, readonly [string, (Partial<TQuery> | undefined)?]>, "initialData" | "queryFn" | "queryKey">): Promise<void>;
|
|
52
52
|
invalidate(query: Partial<TQuery>): Promise<void>;
|
|
53
53
|
cancel(query: Partial<TQuery>): Promise<void>;
|
|
54
54
|
optimisticUpdate(updater: Updater<NullableUncapitalizeDeep<TResult> | undefined, NullableUncapitalizeDeep<TResult> | undefined>, query?: Partial<TQuery>): Promise<() => void>;
|
|
55
55
|
};
|
|
56
56
|
createOperation<TOperation, TResult>(type: string): {
|
|
57
|
-
<
|
|
57
|
+
<TOnMutateResult = unknown>({ onSuccess: onSuccessBase, invalidateQueries, ...options }?: Omit<UseMutationOptions<NullableUncapitalizeDeep<TResult>, DefaultError, TOperation, TOnMutateResult>, "mutationFn" | "mutationKey"> & {
|
|
58
58
|
invalidateQueries?: QueryKey[];
|
|
59
|
-
}): UseMutationResult<NullableUncapitalizeDeep<TResult>,
|
|
59
|
+
}): UseMutationResult<NullableUncapitalizeDeep<TResult>, Error, TOperation, TOnMutateResult>;
|
|
60
60
|
type: string;
|
|
61
|
-
key: string
|
|
61
|
+
key: readonly [string];
|
|
62
62
|
fetcher(variables: TOperation): Observable<NullableUncapitalizeDeep<TResult>>;
|
|
63
63
|
};
|
|
64
64
|
createCommand<TCommand, TErrorCodes extends {
|
|
65
65
|
[name: string]: number;
|
|
66
66
|
}>(type: string, errorCodes: TErrorCodes): {
|
|
67
|
-
<
|
|
67
|
+
<TOnMutateResult extends Record<string, unknown> = {}>(options?: Omit<UseMutationOptions<ApiSuccess<SuccessfulCommandResult>, ApiResponse<FailedCommandResult<TErrorCodes>>, TCommand, TOnMutateResult>, "mutationFn" | "mutationKey"> & {
|
|
68
68
|
invalidateQueries?: QueryKey[];
|
|
69
69
|
handler?: undefined;
|
|
70
70
|
optimisticUpdate?: (variables: TCommand) => Promise<() => void>[];
|
|
71
|
-
}): UseMutationResult<ApiSuccess<SuccessfulCommandResult>, ApiResponse<FailedCommandResult<TErrorCodes>>, TCommand,
|
|
72
|
-
<TResult,
|
|
71
|
+
}): UseMutationResult<ApiSuccess<SuccessfulCommandResult>, ApiResponse<FailedCommandResult<TErrorCodes>>, TCommand, TOnMutateResult>;
|
|
72
|
+
<TResult, TOnMutateResult extends Record<string, unknown> = {}>(options?: Omit<UseMutationOptions<TResult, TResult, TCommand, TOnMutateResult>, "mutationFn" | "mutationKey"> & {
|
|
73
73
|
invalidateQueries?: QueryKey[];
|
|
74
74
|
handler: (handler: ValidationErrorsHandler<TErrorCodes & {
|
|
75
75
|
success: -1;
|
|
76
76
|
failure: -2;
|
|
77
77
|
}, never>) => TResult;
|
|
78
78
|
optimisticUpdate?: (variables: TCommand) => Promise<() => void>[];
|
|
79
|
-
}): UseMutationResult<TResult, TResult, TCommand,
|
|
79
|
+
}): UseMutationResult<TResult, TResult, TCommand, TOnMutateResult>;
|
|
80
80
|
type: string;
|
|
81
|
-
key: string
|
|
82
|
-
fetcher(
|
|
81
|
+
key: readonly [string];
|
|
82
|
+
fetcher: (data: TCommand) => Observable<SuccessfulCommandResult>;
|
|
83
83
|
call<TResult>(variables: TCommand, handler?: (handler: ValidationErrorsHandler<TErrorCodes & {
|
|
84
84
|
success: -1;
|
|
85
85
|
failure: -2;
|