@leancodepl/react-query-cqrs-client 8.3.4 → 8.3.5

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 CHANGED
@@ -197,12 +197,7 @@ function mkCqrsClient({ cqrsEndpoint, queryClient, tokenProvider, ajaxOptions, t
197
197
  ]);
198
198
  return reactQuery.useMutation(_extends({}, options, {
199
199
  mutationKey: useApiCommand.key,
200
- mutationFn: (variables)=>{
201
- if (!handler) {
202
- return rxjs.firstValueFrom(useApiCommand.fetcher(variables));
203
- }
204
- return rxjs.firstValueFrom(useApiCommand.call(variables, handler));
205
- },
200
+ mutationFn: (variables)=>rxjs.firstValueFrom(useApiCommand.call(variables, handler)),
206
201
  async onMutate (variables) {
207
202
  // there's really no good way to do it without type cast
208
203
  const baseContext = await (onMutate == null ? void 0 : onMutate(variables));
@@ -237,7 +232,7 @@ function mkCqrsClient({ cqrsEndpoint, queryClient, tokenProvider, ajaxOptions, t
237
232
  isSuccess: true,
238
233
  result
239
234
  })), rxjs.catchError((e)=>rxjs.of(useApiCommand.mapError(e))), operators.map((response)=>{
240
- const result = useApiCommand.handleResponse(handler)(response);
235
+ const result = handler ? useApiCommand.handleResponse(handler)(response) : response;
241
236
  if (!response.isSuccess || !response.result.WasSuccessful) {
242
237
  throw result;
243
238
  }
package/index.esm.js CHANGED
@@ -195,12 +195,7 @@ function mkCqrsClient({ cqrsEndpoint, queryClient, tokenProvider, ajaxOptions, t
195
195
  ]);
196
196
  return useMutation(_extends({}, options, {
197
197
  mutationKey: useApiCommand.key,
198
- mutationFn: (variables)=>{
199
- if (!handler) {
200
- return firstValueFrom(useApiCommand.fetcher(variables));
201
- }
202
- return firstValueFrom(useApiCommand.call(variables, handler));
203
- },
198
+ mutationFn: (variables)=>firstValueFrom(useApiCommand.call(variables, handler)),
204
199
  async onMutate (variables) {
205
200
  // there's really no good way to do it without type cast
206
201
  const baseContext = await (onMutate == null ? void 0 : onMutate(variables));
@@ -235,7 +230,7 @@ function mkCqrsClient({ cqrsEndpoint, queryClient, tokenProvider, ajaxOptions, t
235
230
  isSuccess: true,
236
231
  result
237
232
  })), catchError((e)=>of(useApiCommand.mapError(e))), map((response)=>{
238
- const result = useApiCommand.handleResponse(handler)(response);
233
+ const result = handler ? useApiCommand.handleResponse(handler)(response) : response;
239
234
  if (!response.isSuccess || !response.result.WasSuccessful) {
240
235
  throw result;
241
236
  }
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@leancodepl/react-query-cqrs-client",
3
- "version": "8.3.4",
3
+ "version": "8.3.5",
4
4
  "license": "Apache-2.0",
5
5
  "dependencies": {
6
- "@leancodepl/cqrs-client-base": "8.3.4",
7
- "@leancodepl/utils": "8.3.4",
8
- "@leancodepl/validation": "8.3.4",
6
+ "@leancodepl/cqrs-client-base": "8.3.5",
7
+ "@leancodepl/utils": "8.3.5",
8
+ "@leancodepl/validation": "8.3.5",
9
9
  "@tanstack/react-query": ">=5.0.0",
10
10
  "rxjs": ">=7.0.0"
11
11
  },
@@ -1,7 +1,7 @@
1
1
  import { FetchQueryOptions, 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
- import { ApiResponse, CommandResult, TokenProvider } from "@leancodepl/cqrs-client-base";
4
+ import { ApiResponse, ApiSuccess, CommandResult, FailedCommandResult, SuccessfulCommandResult, TokenProvider } from "@leancodepl/cqrs-client-base";
5
5
  import { ValidationErrorsHandler } from "@leancodepl/validation";
6
6
  import { NullableUncapitalizeDeep } from "./types";
7
7
  export declare function uncapitalizedParse<TResult>(): OperatorFunction<string, NullableUncapitalizeDeep<TResult>>;
@@ -49,7 +49,7 @@ export declare function mkCqrsClient({ cqrsEndpoint, queryClient, tokenProvider,
49
49
  invalidateQueries?: QueryKey[];
50
50
  handler?: undefined;
51
51
  optimisticUpdate?: (variables: TCommand) => Promise<() => void>[];
52
- } & Omit<UseMutationOptions<CommandResult<TErrorCodes>, CommandResult<TErrorCodes>, TCommand, TContext>, "mutationFn" | "mutationKey">): UseMutationResult<CommandResult<TErrorCodes>, CommandResult<TErrorCodes>, TCommand, TContext>;
52
+ } & Omit<UseMutationOptions<ApiSuccess<SuccessfulCommandResult>, ApiResponse<FailedCommandResult<TErrorCodes>>, TCommand, TContext>, "mutationFn" | "mutationKey">): UseMutationResult<ApiSuccess<SuccessfulCommandResult>, ApiResponse<FailedCommandResult<TErrorCodes>>, TCommand, TContext>;
53
53
  <TResult, TContext extends Record<string, unknown> = {}>(options?: {
54
54
  invalidateQueries?: QueryKey[];
55
55
  handler: (handler: ValidationErrorsHandler<{
@@ -60,11 +60,11 @@ export declare function mkCqrsClient({ cqrsEndpoint, queryClient, tokenProvider,
60
60
  } & Omit<UseMutationOptions<TResult, TResult, TCommand, TContext>, "mutationFn" | "mutationKey">): UseMutationResult<TResult, TResult, TCommand, TContext>;
61
61
  type: string;
62
62
  key: string[];
63
- fetcher(variables: TCommand): Observable<CommandResult<TErrorCodes>>;
64
- call<TResult>(variables: TCommand, handler: (handler: ValidationErrorsHandler<{
63
+ fetcher(variables: TCommand): Observable<SuccessfulCommandResult>;
64
+ call<TResult>(variables: TCommand, handler?: (handler: ValidationErrorsHandler<{
65
65
  success: -1;
66
66
  failure: -2;
67
- } & TErrorCodes, never>) => TResult): Observable<TResult>;
67
+ } & TErrorCodes, never>) => TResult): Observable<ApiSuccess<SuccessfulCommandResult> | TResult>;
68
68
  mapError(e: unknown): ApiResponse<CommandResult<TErrorCodes>>;
69
69
  handleResponse<TResult>(handler: (handler: ValidationErrorsHandler<{
70
70
  success: -1;