@leancodepl/react-query-cqrs-client 8.3.6 → 8.4.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.js +6 -5
- package/index.esm.js +8 -7
- package/package.json +4 -4
- package/src/lib/mkCqrsClient.d.ts +16 -18
package/index.cjs.js
CHANGED
|
@@ -110,13 +110,14 @@ function mkCqrsClient({ cqrsEndpoint, queryClient, tokenProvider, ajaxOptions, t
|
|
|
110
110
|
mutationFn: (variables)=>rxjs.firstValueFrom(useApiQuery.fetcher(variables))
|
|
111
111
|
}, options), queryClient);
|
|
112
112
|
};
|
|
113
|
-
useApiQuery.infinite = function(
|
|
113
|
+
useApiQuery.infinite = function(initialPageData, options) {
|
|
114
114
|
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
115
115
|
return reactQuery.useInfiniteQuery(_extends({
|
|
116
|
-
queryKey:
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
116
|
+
queryKey: [
|
|
117
|
+
type
|
|
118
|
+
],
|
|
119
|
+
queryFn: async (context)=>await rxjs.firstValueFrom(useApiQuery.fetcher(context.pageParam, context)),
|
|
120
|
+
initialPageParam: initialPageData
|
|
120
121
|
}, options), queryClient);
|
|
121
122
|
};
|
|
122
123
|
useApiQuery.key = (query)=>[
|
package/index.esm.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { useMutation, useInfiniteQuery, useQuery } from '@tanstack/react-query';
|
|
2
|
-
import { catchError, throwError, race, fromEvent,
|
|
2
|
+
import { catchError, throwError, of, race, fromEvent, from, firstValueFrom } from 'rxjs';
|
|
3
3
|
import { AjaxError, ajax } from 'rxjs/ajax';
|
|
4
|
-
import {
|
|
4
|
+
import { map, mergeMap } from 'rxjs/operators';
|
|
5
5
|
import { handleResponse } from '@leancodepl/validation';
|
|
6
6
|
import { toLowerFirst } from '@leancodepl/utils';
|
|
7
7
|
|
|
@@ -108,13 +108,14 @@ function mkCqrsClient({ cqrsEndpoint, queryClient, tokenProvider, ajaxOptions, t
|
|
|
108
108
|
mutationFn: (variables)=>firstValueFrom(useApiQuery.fetcher(variables))
|
|
109
109
|
}, options), queryClient);
|
|
110
110
|
};
|
|
111
|
-
useApiQuery.infinite = function(
|
|
111
|
+
useApiQuery.infinite = function(initialPageData, options) {
|
|
112
112
|
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
113
113
|
return useInfiniteQuery(_extends({
|
|
114
|
-
queryKey:
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
114
|
+
queryKey: [
|
|
115
|
+
type
|
|
116
|
+
],
|
|
117
|
+
queryFn: async (context)=>await firstValueFrom(useApiQuery.fetcher(context.pageParam, context)),
|
|
118
|
+
initialPageParam: initialPageData
|
|
118
119
|
}, options), queryClient);
|
|
119
120
|
};
|
|
120
121
|
useApiQuery.key = (query)=>[
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leancodepl/react-query-cqrs-client",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.4.0",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"dependencies": {
|
|
6
|
-
"@leancodepl/cqrs-client-base": "8.
|
|
7
|
-
"@leancodepl/utils": "8.
|
|
8
|
-
"@leancodepl/validation": "8.
|
|
6
|
+
"@leancodepl/cqrs-client-base": "8.4.0",
|
|
7
|
+
"@leancodepl/utils": "8.4.0",
|
|
8
|
+
"@leancodepl/validation": "8.4.0",
|
|
9
9
|
"@tanstack/react-query": ">=5.0.0",
|
|
10
10
|
"rxjs": ">=7.0.0"
|
|
11
11
|
},
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { FetchQueryOptions, QueryClient, QueryFunctionContext, QueryKey, UndefinedInitialDataInfiniteOptions, UndefinedInitialDataOptions, Updater, UseMutationOptions, UseMutationResult } from "@tanstack/react-query";
|
|
1
|
+
import { 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";
|
|
@@ -18,26 +18,24 @@ export declare function mkCqrsClient({ cqrsEndpoint, queryClient, tokenProvider,
|
|
|
18
18
|
fetcher(data: TQuery, context?: QueryFunctionContext<QueryKey>): Observable<NullableUncapitalizeDeep<TResult>>;
|
|
19
19
|
fetch(data: TQuery, options?: Omit<FetchQueryOptions<NullableUncapitalizeDeep<TResult>, unknown>, "queryFn" | "queryKey">): Promise<NullableUncapitalizeDeep<TResult>>;
|
|
20
20
|
lazy<TContext = unknown>(options?: Omit<UseMutationOptions<NullableUncapitalizeDeep<TResult>, unknown, TQuery, TContext>, "mutationFn" | "mutationKey">): UseMutationResult<NullableUncapitalizeDeep<TResult>, unknown, TQuery, TContext>;
|
|
21
|
-
infinite(
|
|
22
|
-
pageParamKey?: keyof TQuery;
|
|
23
|
-
} & Omit<UndefinedInitialDataInfiniteOptions<NullableUncapitalizeDeep<TResult>, unknown>, "queryFn" | "queryKey">): import("@tanstack/react-query").UseInfiniteQueryResult<import("@tanstack/react-query").InfiniteData<NullableUncapitalizeDeep<TResult>, unknown>, unknown>;
|
|
21
|
+
infinite(initialPageData: TQuery, options: Omit<UndefinedInitialDataInfiniteOptions<NullableUncapitalizeDeep<TResult>, unknown, InfiniteData<NullableUncapitalizeDeep<TResult>>, QueryKey, TQuery>, "initialPageParam" | "queryFn" | "queryKey" | "select">): import("@tanstack/react-query").UseInfiniteQueryResult<InfiniteData<NullableUncapitalizeDeep<TResult>, TQuery>, unknown>;
|
|
24
22
|
key(query: Partial<TQuery>): readonly [string, Partial<TQuery>];
|
|
25
23
|
setQueryData: {
|
|
26
24
|
(query: TQuery, updater: Updater<NullableUncapitalizeDeep<TResult> | undefined, NullableUncapitalizeDeep<TResult> | undefined>): NullableUncapitalizeDeep<TResult> | undefined;
|
|
27
25
|
(queryKey: QueryKey, updater: Updater<NullableUncapitalizeDeep<TResult> | undefined, NullableUncapitalizeDeep<TResult> | undefined>): NullableUncapitalizeDeep<TResult> | undefined;
|
|
28
26
|
};
|
|
29
|
-
setQueriesData(query: Partial<TQuery>, updater: Updater<NullableUncapitalizeDeep<TResult> | undefined, NullableUncapitalizeDeep<TResult> | undefined>): [
|
|
27
|
+
setQueriesData(query: Partial<TQuery>, updater: Updater<NullableUncapitalizeDeep<TResult> | undefined, NullableUncapitalizeDeep<TResult> | undefined>): [readonly unknown[], unknown][];
|
|
30
28
|
getQueryData(query: TQuery): NullableUncapitalizeDeep<TResult> | undefined;
|
|
31
|
-
getQueriesData(query: Partial<TQuery>): [
|
|
29
|
+
getQueriesData(query: Partial<TQuery>): [readonly unknown[], NullableUncapitalizeDeep<TResult> | undefined][];
|
|
32
30
|
prefetch(data: TQuery, options?: Omit<FetchQueryOptions<NullableUncapitalizeDeep<TResult>, unknown>, "initialData" | "queryFn" | "queryKey">): Promise<void>;
|
|
33
31
|
invalidate(query: Partial<TQuery>): Promise<void>;
|
|
34
32
|
cancel(query: Partial<TQuery>): Promise<void>;
|
|
35
33
|
optimisticUpdate(updater: Updater<NullableUncapitalizeDeep<TResult> | undefined, NullableUncapitalizeDeep<TResult> | undefined>, query?: Partial<TQuery>): Promise<() => void>;
|
|
36
34
|
};
|
|
37
35
|
createOperation<TOperation, TResult>(type: string): {
|
|
38
|
-
<TContext = unknown>({ onSuccess: onSuccessBase, invalidateQueries, ...options }?: {
|
|
36
|
+
<TContext = unknown>({ onSuccess: onSuccessBase, invalidateQueries, ...options }?: Omit<UseMutationOptions<NullableUncapitalizeDeep<TResult>, unknown, TOperation, TContext>, "mutationFn" | "mutationKey"> & {
|
|
39
37
|
invalidateQueries?: QueryKey[];
|
|
40
|
-
}
|
|
38
|
+
}): UseMutationResult<NullableUncapitalizeDeep<TResult>, unknown, TOperation, TContext>;
|
|
41
39
|
type: string;
|
|
42
40
|
key: string[];
|
|
43
41
|
fetcher(variables: TOperation): Observable<NullableUncapitalizeDeep<TResult>>;
|
|
@@ -45,30 +43,30 @@ export declare function mkCqrsClient({ cqrsEndpoint, queryClient, tokenProvider,
|
|
|
45
43
|
createCommand<TCommand, TErrorCodes extends {
|
|
46
44
|
[name: string]: number;
|
|
47
45
|
}>(type: string, errorCodes: TErrorCodes): {
|
|
48
|
-
<TContext extends Record<string, unknown> = {}>(options?: {
|
|
46
|
+
<TContext extends Record<string, unknown> = {}>(options?: Omit<UseMutationOptions<ApiSuccess<SuccessfulCommandResult>, ApiResponse<FailedCommandResult<TErrorCodes>>, TCommand, TContext>, "mutationFn" | "mutationKey"> & {
|
|
49
47
|
invalidateQueries?: QueryKey[];
|
|
50
48
|
handler?: undefined;
|
|
51
49
|
optimisticUpdate?: (variables: TCommand) => Promise<() => void>[];
|
|
52
|
-
}
|
|
53
|
-
<TResult, TContext extends Record<string, unknown> = {}>(options?: {
|
|
50
|
+
}): UseMutationResult<ApiSuccess<SuccessfulCommandResult>, ApiResponse<FailedCommandResult<TErrorCodes>>, TCommand, TContext>;
|
|
51
|
+
<TResult, TContext extends Record<string, unknown> = {}>(options?: Omit<UseMutationOptions<TResult, TResult, TCommand, TContext>, "mutationFn" | "mutationKey"> & {
|
|
54
52
|
invalidateQueries?: QueryKey[];
|
|
55
|
-
handler: (handler: ValidationErrorsHandler<{
|
|
53
|
+
handler: (handler: ValidationErrorsHandler<TErrorCodes & {
|
|
56
54
|
success: -1;
|
|
57
55
|
failure: -2;
|
|
58
|
-
}
|
|
56
|
+
}, never>) => TResult;
|
|
59
57
|
optimisticUpdate?: (variables: TCommand) => Promise<() => void>[];
|
|
60
|
-
}
|
|
58
|
+
}): UseMutationResult<TResult, TResult, TCommand, TContext>;
|
|
61
59
|
type: string;
|
|
62
60
|
key: string[];
|
|
63
61
|
fetcher(variables: TCommand): Observable<SuccessfulCommandResult>;
|
|
64
|
-
call<TResult>(variables: TCommand, handler?: (handler: ValidationErrorsHandler<{
|
|
62
|
+
call<TResult>(variables: TCommand, handler?: (handler: ValidationErrorsHandler<TErrorCodes & {
|
|
65
63
|
success: -1;
|
|
66
64
|
failure: -2;
|
|
67
|
-
}
|
|
65
|
+
}, never>) => TResult): Observable<ApiSuccess<SuccessfulCommandResult> | TResult>;
|
|
68
66
|
mapError(e: unknown): ApiResponse<CommandResult<TErrorCodes>>;
|
|
69
|
-
handleResponse<TResult>(handler: (handler: ValidationErrorsHandler<{
|
|
67
|
+
handleResponse<TResult>(handler: (handler: ValidationErrorsHandler<TErrorCodes & {
|
|
70
68
|
success: -1;
|
|
71
69
|
failure: -2;
|
|
72
|
-
}
|
|
70
|
+
}, never>) => TResult): (response: ApiResponse<CommandResult<TErrorCodes>>) => TResult;
|
|
73
71
|
};
|
|
74
72
|
};
|