@openapi-qraft/react 1.4.0 → 1.6.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/CHANGELOG.md +14 -0
- package/dist/ServiceOperation.d.ts +114 -46
- package/dist/ServiceOperation.d.ts.map +1 -1
- package/dist/callbacks/getInfiniteQueryState.d.ts +5 -0
- package/dist/callbacks/getInfiniteQueryState.d.ts.map +1 -0
- package/dist/callbacks/getInfiniteQueryState.js +5 -0
- package/dist/callbacks/getInfiniteQueryState.js.map +1 -0
- package/dist/callbacks/getQueriesData.d.ts +5 -0
- package/dist/callbacks/getQueriesData.d.ts.map +1 -0
- package/dist/callbacks/getQueriesData.js +5 -0
- package/dist/callbacks/getQueriesData.js.map +1 -0
- package/dist/callbacks/getQueryState.d.ts +5 -0
- package/dist/callbacks/getQueryState.d.ts.map +1 -0
- package/dist/callbacks/getQueryState.js +5 -0
- package/dist/callbacks/getQueryState.js.map +1 -0
- package/dist/callbacks/setQueriesData.d.ts +5 -0
- package/dist/callbacks/setQueriesData.d.ts.map +1 -0
- package/dist/callbacks/setQueriesData.js +5 -0
- package/dist/callbacks/setQueriesData.js.map +1 -0
- package/dist/callbacks/useIsFetching.js.map +1 -1
- package/dist/lib/callQueryClientMethodWithMutationFilters.js +1 -1
- package/dist/lib/callQueryClientMethodWithMutationFilters.js.map +1 -1
- package/dist/lib/callQueryClientMethodWithQueryFilters.js +1 -1
- package/dist/lib/callQueryClientMethodWithQueryFilters.js.map +1 -1
- package/dist/lib/callQueryClientMethodWithQueryKey.js +1 -1
- package/dist/lib/callQueryClientMethodWithQueryKey.js.map +1 -1
- package/dist/lib/composeBaseQueryKey.d.ts +6 -0
- package/dist/lib/composeBaseQueryKey.d.ts.map +1 -0
- package/dist/lib/composeBaseQueryKey.js +7 -0
- package/dist/lib/composeBaseQueryKey.js.map +1 -0
- package/dist/lib/composeInfiniteQueryKey.d.ts.map +1 -1
- package/dist/lib/composeInfiniteQueryKey.js +2 -1
- package/dist/lib/composeInfiniteQueryKey.js.map +1 -1
- package/dist/lib/composeQueryFilters.d.ts +5 -2
- package/dist/lib/composeQueryFilters.d.ts.map +1 -1
- package/dist/lib/composeQueryFilters.js +17 -11
- package/dist/lib/composeQueryFilters.js.map +1 -1
- package/dist/lib/composeQueryKey.d.ts.map +1 -1
- package/dist/lib/composeQueryKey.js +2 -1
- package/dist/lib/composeQueryKey.js.map +1 -1
- package/package.json +3 -3
- package/src/ServiceOperation.ts +267 -104
- package/src/callbacks/getInfiniteQueryState.ts +23 -0
- package/src/callbacks/getQueriesData.ts +18 -0
- package/src/callbacks/getQueryState.ts +19 -0
- package/src/callbacks/setQueriesData.ts +22 -0
- package/src/callbacks/useIsFetching.ts +1 -1
- package/src/lib/callQueryClientMethodWithMutationFilters.ts +1 -1
- package/src/lib/callQueryClientMethodWithQueryFilters.ts +1 -1
- package/src/lib/callQueryClientMethodWithQueryKey.ts +1 -1
- package/src/lib/composeBaseQueryKey.ts +34 -0
- package/src/lib/composeInfiniteQueryKey.ts +2 -1
- package/src/lib/composeQueryFilters.ts +24 -16
- package/src/lib/composeQueryKey.ts +2 -1
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { callQueryClientMethodWithQueryKey } from '../lib/callQueryClientMethodWithQueryKey.js';
|
|
2
|
+
import type { OperationSchema } from '../lib/requestFn.js';
|
|
3
|
+
import type { QraftClientOptions } from '../qraftAPIClient.js';
|
|
4
|
+
import type { ServiceOperationQuery } from '../ServiceOperation.js';
|
|
5
|
+
|
|
6
|
+
export function getInfiniteQueryState<TData>(
|
|
7
|
+
_: QraftClientOptions | undefined,
|
|
8
|
+
schema: OperationSchema,
|
|
9
|
+
args: Parameters<
|
|
10
|
+
ServiceOperationQuery<
|
|
11
|
+
OperationSchema,
|
|
12
|
+
unknown,
|
|
13
|
+
TData
|
|
14
|
+
>['getInfiniteQueryState']
|
|
15
|
+
>
|
|
16
|
+
): TData | undefined {
|
|
17
|
+
return callQueryClientMethodWithQueryKey(
|
|
18
|
+
'getQueryState',
|
|
19
|
+
schema,
|
|
20
|
+
true,
|
|
21
|
+
args as never
|
|
22
|
+
) as never;
|
|
23
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { callQueryClientMethodWithQueryFilters } from '../lib/callQueryClientMethodWithQueryFilters.js';
|
|
2
|
+
import type { OperationSchema } from '../lib/requestFn.js';
|
|
3
|
+
import type { QraftClientOptions } from '../qraftAPIClient.js';
|
|
4
|
+
import { ServiceOperationQuery } from '../ServiceOperation.js';
|
|
5
|
+
|
|
6
|
+
export function getQueriesData<TData>(
|
|
7
|
+
_: QraftClientOptions | undefined,
|
|
8
|
+
schema: OperationSchema,
|
|
9
|
+
args: Parameters<
|
|
10
|
+
ServiceOperationQuery<OperationSchema, unknown, TData>['getQueriesData']
|
|
11
|
+
>
|
|
12
|
+
): TData | undefined {
|
|
13
|
+
return callQueryClientMethodWithQueryFilters(
|
|
14
|
+
'getQueriesData',
|
|
15
|
+
schema,
|
|
16
|
+
args as never
|
|
17
|
+
) as never;
|
|
18
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { callQueryClientMethodWithQueryKey } from '../lib/callQueryClientMethodWithQueryKey.js';
|
|
2
|
+
import type { OperationSchema } from '../lib/requestFn.js';
|
|
3
|
+
import type { QraftClientOptions } from '../qraftAPIClient.js';
|
|
4
|
+
import type { ServiceOperationQuery } from '../ServiceOperation.js';
|
|
5
|
+
|
|
6
|
+
export function getQueryState<TData>(
|
|
7
|
+
_: QraftClientOptions | undefined,
|
|
8
|
+
schema: OperationSchema,
|
|
9
|
+
args: Parameters<
|
|
10
|
+
ServiceOperationQuery<OperationSchema, unknown, TData>['getQueryState']
|
|
11
|
+
>
|
|
12
|
+
): TData | undefined {
|
|
13
|
+
return callQueryClientMethodWithQueryKey(
|
|
14
|
+
'getQueryState',
|
|
15
|
+
schema,
|
|
16
|
+
false,
|
|
17
|
+
args as never
|
|
18
|
+
) as never;
|
|
19
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { callQueryClientMethodWithQueryFilters } from '../lib/callQueryClientMethodWithQueryFilters.js';
|
|
2
|
+
import type { OperationSchema } from '../lib/requestFn.js';
|
|
3
|
+
import type { QraftClientOptions } from '../qraftAPIClient.js';
|
|
4
|
+
import type { ServiceOperationSetQueriesDataCallback } from '../ServiceOperation.js';
|
|
5
|
+
|
|
6
|
+
export function setQueriesData<TData>(
|
|
7
|
+
_: QraftClientOptions | undefined,
|
|
8
|
+
schema: OperationSchema,
|
|
9
|
+
args: Parameters<
|
|
10
|
+
ServiceOperationSetQueriesDataCallback<
|
|
11
|
+
OperationSchema,
|
|
12
|
+
unknown,
|
|
13
|
+
TData
|
|
14
|
+
>['setQueriesData']
|
|
15
|
+
>
|
|
16
|
+
): TData | undefined {
|
|
17
|
+
return callQueryClientMethodWithQueryFilters(
|
|
18
|
+
'setQueriesData',
|
|
19
|
+
schema,
|
|
20
|
+
args as never
|
|
21
|
+
) as never;
|
|
22
|
+
}
|
|
@@ -23,7 +23,7 @@ export const useIsFetching: <TVariables = unknown>(
|
|
|
23
23
|
const [filters, queryClientByArg] = args;
|
|
24
24
|
|
|
25
25
|
return useIsFetchingTanstack(
|
|
26
|
-
composeQueryFilters(schema, filters) as never,
|
|
26
|
+
composeQueryFilters(schema, filters as never) as never,
|
|
27
27
|
useQueryClient(qraftOptions, queryClientByArg)
|
|
28
28
|
) as never;
|
|
29
29
|
};
|
|
@@ -14,7 +14,7 @@ export function callQueryClientMethodWithMutationFilters<
|
|
|
14
14
|
schema: OperationSchema,
|
|
15
15
|
args: [...Parameters<(typeof QueryClient.prototype)[QFMethod]>, QueryClient]
|
|
16
16
|
): ReturnType<(typeof QueryClient.prototype)[QFMethod]> {
|
|
17
|
-
const filters = args[0];
|
|
17
|
+
const filters = args.length > 1 ? args[0] : undefined;
|
|
18
18
|
const queryClient = args[args.length - 1] as QueryClient | undefined;
|
|
19
19
|
|
|
20
20
|
if (!queryClient) throw new Error('queryClient is required');
|
|
@@ -14,7 +14,7 @@ export function callQueryClientMethodWithQueryFilters<
|
|
|
14
14
|
schema: OperationSchema,
|
|
15
15
|
args: [...Parameters<(typeof QueryClient.prototype)[QFMethod]>, QueryClient]
|
|
16
16
|
): ReturnType<(typeof QueryClient.prototype)[QFMethod]> {
|
|
17
|
-
const filters = args[0];
|
|
17
|
+
const filters = args.length > 1 ? args[0] : undefined;
|
|
18
18
|
const queryClient = args[args.length - 1] as QueryClient | undefined;
|
|
19
19
|
|
|
20
20
|
if (!queryClient) throw new Error('queryClient is required');
|
|
@@ -16,7 +16,7 @@ export function callQueryClientMethodWithQueryKey<
|
|
|
16
16
|
infinite: boolean,
|
|
17
17
|
args: [...Parameters<(typeof QueryClient.prototype)[QFMethod]>, QueryClient]
|
|
18
18
|
): ReturnType<(typeof QueryClient.prototype)[QFMethod]> {
|
|
19
|
-
const parameters = args[0];
|
|
19
|
+
const parameters = args.length > 1 ? args[0] : undefined;
|
|
20
20
|
const queryClient = args[args.length - 1] as QueryClient | undefined;
|
|
21
21
|
|
|
22
22
|
if (!queryClient) throw new Error('queryClient is required');
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ServiceOperationInfiniteQueryKey,
|
|
3
|
+
ServiceOperationQueryKey,
|
|
4
|
+
} from '../ServiceOperation.js';
|
|
5
|
+
import type { OperationSchema } from './requestFn.js';
|
|
6
|
+
|
|
7
|
+
export function composeBaseQueryKey<TSchema extends OperationSchema, TParams>(
|
|
8
|
+
schema: TSchema,
|
|
9
|
+
parameters: TParams | undefined,
|
|
10
|
+
infinite: undefined
|
|
11
|
+
): [TSchema, TParams];
|
|
12
|
+
export function composeBaseQueryKey<TSchema extends OperationSchema, TParams>(
|
|
13
|
+
schema: TSchema,
|
|
14
|
+
parameters: TParams | undefined,
|
|
15
|
+
infinite: true
|
|
16
|
+
): ServiceOperationInfiniteQueryKey<TSchema, TParams>;
|
|
17
|
+
export function composeBaseQueryKey<TSchema extends OperationSchema, TParams>(
|
|
18
|
+
schema: TSchema,
|
|
19
|
+
parameters: TParams | undefined,
|
|
20
|
+
infinite: false
|
|
21
|
+
): ServiceOperationQueryKey<TSchema, TParams>;
|
|
22
|
+
export function composeBaseQueryKey<TSchema extends OperationSchema, TParams>(
|
|
23
|
+
schema: TSchema,
|
|
24
|
+
parameters: TParams | undefined,
|
|
25
|
+
infinite: boolean | undefined
|
|
26
|
+
):
|
|
27
|
+
| ServiceOperationQueryKey<TSchema, TParams>
|
|
28
|
+
| ServiceOperationInfiniteQueryKey<TSchema, TParams>
|
|
29
|
+
| [TSchema, TParams] {
|
|
30
|
+
return [
|
|
31
|
+
typeof infinite === 'boolean' ? { ...schema, infinite } : schema,
|
|
32
|
+
parameters ?? ({} as TParams),
|
|
33
|
+
];
|
|
34
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { ServiceOperationInfiniteQueryKey } from '../ServiceOperation.js';
|
|
2
|
+
import { composeBaseQueryKey } from './composeBaseQueryKey.js';
|
|
2
3
|
import type { OperationSchema } from './requestFn.js';
|
|
3
4
|
|
|
4
5
|
export function composeInfiniteQueryKey<
|
|
@@ -8,5 +9,5 @@ export function composeInfiniteQueryKey<
|
|
|
8
9
|
schema: TSchema,
|
|
9
10
|
parameters: TParams | undefined
|
|
10
11
|
): ServiceOperationInfiniteQueryKey<TSchema, TParams> {
|
|
11
|
-
return
|
|
12
|
+
return composeBaseQueryKey(schema, parameters, true);
|
|
12
13
|
}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { composeBaseQueryKey } from './composeBaseQueryKey.js';
|
|
2
|
+
import { composeInfiniteQueryKey } from './composeInfiniteQueryKey.js';
|
|
1
3
|
import { composeQueryKey } from './composeQueryKey.js';
|
|
2
4
|
import type { OperationSchema } from './requestFn.js';
|
|
3
5
|
|
|
@@ -7,38 +9,44 @@ import type { OperationSchema } from './requestFn.js';
|
|
|
7
9
|
* @param schema
|
|
8
10
|
* @param filters
|
|
9
11
|
*/
|
|
10
|
-
export function composeQueryFilters<
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
export function composeQueryFilters<
|
|
13
|
+
Filters extends {
|
|
14
|
+
infinite: boolean;
|
|
15
|
+
parameters?: object;
|
|
16
|
+
} & Record<string, unknown>,
|
|
17
|
+
>(schema: OperationSchema, filters: Filters | undefined) {
|
|
14
18
|
if (!filters) {
|
|
15
19
|
return {
|
|
16
|
-
queryKey:
|
|
20
|
+
queryKey: composeBaseQueryKey(schema, undefined, undefined),
|
|
17
21
|
};
|
|
18
22
|
}
|
|
19
23
|
|
|
20
|
-
if (
|
|
24
|
+
if ('queryKey' in filters && 'parameters' in filters) {
|
|
21
25
|
throw new Error(
|
|
22
26
|
`'composeQueryFilters': 'queryKey' and 'parameters' cannot be used together`
|
|
23
27
|
);
|
|
24
28
|
}
|
|
25
29
|
|
|
26
|
-
|
|
27
|
-
return filters;
|
|
28
|
-
}
|
|
30
|
+
const { infinite, parameters, ...filtersRest } = filters;
|
|
29
31
|
|
|
30
|
-
if ('
|
|
31
|
-
|
|
32
|
+
if ('queryKey' in filtersRest) {
|
|
33
|
+
return filtersRest;
|
|
34
|
+
}
|
|
32
35
|
|
|
33
|
-
|
|
34
|
-
|
|
36
|
+
if (parameters) {
|
|
37
|
+
Object.assign(filtersRest, {
|
|
38
|
+
queryKey: infinite
|
|
39
|
+
? composeInfiniteQueryKey(schema, parameters)
|
|
40
|
+
: composeQueryKey(schema, parameters),
|
|
35
41
|
});
|
|
36
42
|
|
|
37
|
-
return
|
|
43
|
+
return filtersRest;
|
|
38
44
|
}
|
|
39
45
|
|
|
40
46
|
return {
|
|
41
|
-
...
|
|
42
|
-
queryKey:
|
|
47
|
+
...filtersRest,
|
|
48
|
+
queryKey: infinite
|
|
49
|
+
? composeInfiniteQueryKey(schema, undefined)
|
|
50
|
+
: composeQueryKey(schema, undefined),
|
|
43
51
|
};
|
|
44
52
|
}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import type { ServiceOperationQueryKey } from '../ServiceOperation.js';
|
|
2
|
+
import { composeBaseQueryKey } from './composeBaseQueryKey.js';
|
|
2
3
|
import type { OperationSchema } from './requestFn.js';
|
|
3
4
|
|
|
4
5
|
export function composeQueryKey<TSchema extends OperationSchema, TParams>(
|
|
5
6
|
schema: TSchema,
|
|
6
7
|
parameters: TParams | undefined
|
|
7
8
|
): ServiceOperationQueryKey<TSchema, TParams> {
|
|
8
|
-
return
|
|
9
|
+
return composeBaseQueryKey(schema, parameters, false);
|
|
9
10
|
}
|