@openapi-qraft/react 1.7.0 → 1.9.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 +8 -0
- package/README.md +61 -55
- package/dist/QraftContext.d.ts +1 -1
- package/dist/ServiceOperation.d.ts +1 -1
- package/dist/ServiceOperation.d.ts.map +1 -1
- package/dist/callbacks/mutationFn.js +2 -2
- package/dist/callbacks/mutationFn.js.map +1 -1
- package/dist/callbacks/operationInvokeFn.d.ts +9 -0
- package/dist/callbacks/operationInvokeFn.d.ts.map +1 -0
- package/dist/callbacks/operationInvokeFn.js +21 -0
- package/dist/callbacks/operationInvokeFn.js.map +1 -0
- package/dist/callbacks/queryFn.d.ts.map +1 -1
- package/dist/callbacks/queryFn.js +4 -2
- package/dist/callbacks/queryFn.js.map +1 -1
- package/dist/callbacks/useInfiniteQuery.js +1 -1
- package/dist/callbacks/useInfiniteQuery.js.map +1 -1
- package/dist/callbacks/useQueries.js +1 -1
- package/dist/callbacks/useQueries.js.map +1 -1
- package/dist/callbacks/useQuery.js +1 -1
- package/dist/callbacks/useQuery.js.map +1 -1
- package/dist/callbacks/useSuspenseInfiniteQuery.js +1 -1
- package/dist/callbacks/useSuspenseInfiniteQuery.js.map +1 -1
- package/dist/callbacks/useSuspenseQueries.js +1 -1
- package/dist/callbacks/useSuspenseQueries.js.map +1 -1
- package/dist/callbacks/useSuspenseQuery.js +1 -1
- package/dist/callbacks/useSuspenseQuery.js.map +1 -1
- package/dist/lib/callQueryClientFetchMethod.js +3 -3
- package/dist/lib/callQueryClientFetchMethod.js.map +1 -1
- package/dist/lib/callQueryClientMethodWithMutationFilters.js +2 -2
- package/dist/lib/callQueryClientMethodWithMutationFilters.js.map +1 -1
- package/dist/lib/callQueryClientMethodWithQueryFilters.js +2 -2
- 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/composeMutationKey.d.ts +1 -1
- package/dist/lib/composeMutationKey.d.ts.map +1 -1
- package/dist/lib/composeMutationKey.js +1 -1
- package/dist/lib/composeMutationKey.js.map +1 -1
- package/dist/lib/createRecursiveProxy.d.ts +6 -0
- package/dist/lib/createRecursiveProxy.d.ts.map +1 -1
- package/dist/lib/createRecursiveProxy.js +7 -0
- package/dist/lib/createRecursiveProxy.js.map +1 -1
- package/dist/lib/requestFn.d.ts +26 -3
- package/dist/lib/requestFn.d.ts.map +1 -1
- package/dist/lib/requestFn.js +27 -3
- package/dist/lib/requestFn.js.map +1 -1
- package/dist/lib/useComposeUseQueryOptions.js +2 -2
- package/dist/lib/useComposeUseQueryOptions.js.map +1 -1
- package/dist/lib/useQueryClient.d.ts.map +1 -1
- package/dist/lib/useQueryClient.js +1 -2
- package/dist/lib/useQueryClient.js.map +1 -1
- package/dist/qraftAPIClient.d.ts +4 -16
- package/dist/qraftAPIClient.d.ts.map +1 -1
- package/dist/qraftAPIClient.js +28 -9
- package/dist/qraftAPIClient.js.map +1 -1
- package/dist/service-operation/ServiceOperationKey.d.ts +1 -1
- package/dist/service-operation/ServiceOperationKey.d.ts.map +1 -1
- package/dist/service-operation/ServiceOperationMutationFn.d.ts +27 -0
- package/dist/service-operation/ServiceOperationMutationFn.d.ts.map +1 -1
- package/dist/service-operation/ServiceOperationQueryFn.d.ts +47 -0
- package/dist/service-operation/ServiceOperationQueryFn.d.ts.map +1 -1
- package/package.json +10 -5
- package/src/QraftContext.ts +1 -1
- package/src/ServiceOperation.ts +1 -1
- package/src/callbacks/mutationFn.ts +2 -2
- package/src/callbacks/operationInvokeFn.ts +45 -0
- package/src/callbacks/queryFn.ts +11 -6
- package/src/callbacks/useInfiniteQuery.ts +1 -1
- package/src/callbacks/useQueries.ts +1 -1
- package/src/callbacks/useQuery.ts +1 -1
- package/src/callbacks/useSuspenseInfiniteQuery.ts +1 -1
- package/src/callbacks/useSuspenseQueries.ts +1 -1
- package/src/callbacks/useSuspenseQuery.ts +1 -1
- package/src/lib/callQueryClientFetchMethod.ts +3 -3
- package/src/lib/callQueryClientMethodWithMutationFilters.ts +2 -2
- package/src/lib/callQueryClientMethodWithQueryFilters.ts +2 -2
- package/src/lib/callQueryClientMethodWithQueryKey.ts +1 -1
- package/src/lib/composeMutationKey.ts +6 -8
- package/src/lib/createRecursiveProxy.ts +7 -0
- package/src/lib/requestFn.ts +31 -5
- package/src/lib/useComposeUseQueryOptions.ts +2 -2
- package/src/lib/useQueryClient.ts +3 -2
- package/src/qraftAPIClient.ts +39 -39
- package/src/service-operation/ServiceOperationKey.ts +1 -1
- package/src/service-operation/ServiceOperationMutationFn.ts +58 -0
- package/src/service-operation/ServiceOperationQueryFn.ts +110 -0
|
@@ -19,7 +19,7 @@ export const useQuery: <TData = unknown, TError = DefaultError>(
|
|
|
19
19
|
>
|
|
20
20
|
) => UseQueryResult<TData, TError> = (qraftOptions, schema, args) => {
|
|
21
21
|
return useQueryTanstack(
|
|
22
|
-
// @ts-expect-error
|
|
22
|
+
// @ts-expect-error - Too complex to type
|
|
23
23
|
...useComposeUseQueryOptions(qraftOptions, schema, args, false)
|
|
24
24
|
) as never;
|
|
25
25
|
};
|
|
@@ -23,7 +23,7 @@ export const useSuspenseQuery: <
|
|
|
23
23
|
>
|
|
24
24
|
) => UseQueryResult<TData, TError> = (qraftOptions, schema, args) => {
|
|
25
25
|
return useSuspenseQueryTanstack(
|
|
26
|
-
// @ts-expect-error
|
|
26
|
+
// @ts-expect-error - Too complex to type
|
|
27
27
|
...useComposeUseQueryOptions(qraftOptions, schema, args, false)
|
|
28
28
|
) as never;
|
|
29
29
|
};
|
|
@@ -40,7 +40,7 @@ export function callQueryClientMethodWithQueryKey<
|
|
|
40
40
|
const queryFn =
|
|
41
41
|
options.queryFn ??
|
|
42
42
|
(requestFn
|
|
43
|
-
? // @ts-expect-error
|
|
43
|
+
? // @ts-expect-error - Not inferring the correct type for `queryFn`
|
|
44
44
|
function ({ queryKey: [, queryParams], signal, meta, pageParam }) {
|
|
45
45
|
return requestFn(schema, {
|
|
46
46
|
parameters: infinite
|
|
@@ -54,7 +54,7 @@ export function callQueryClientMethodWithQueryKey<
|
|
|
54
54
|
: undefined);
|
|
55
55
|
|
|
56
56
|
if (parameters) {
|
|
57
|
-
// @ts-expect-error
|
|
57
|
+
// @ts-expect-error - Too complex union to type
|
|
58
58
|
return queryClient[queryFilterMethod]({
|
|
59
59
|
...options,
|
|
60
60
|
// Event if queryFn is undefined, it will override the default queryFn from `setQueryDefaults(...)`
|
|
@@ -65,7 +65,7 @@ export function callQueryClientMethodWithQueryKey<
|
|
|
65
65
|
});
|
|
66
66
|
}
|
|
67
67
|
|
|
68
|
-
// @ts-expect-error
|
|
68
|
+
// @ts-expect-error - Too complex union to type
|
|
69
69
|
return queryClient[queryFilterMethod]({ ...options, queryFn });
|
|
70
70
|
}
|
|
71
71
|
|
|
@@ -23,10 +23,10 @@ export function callQueryClientMethodWithMutationFilters<
|
|
|
23
23
|
`queryClient is invalid, ${queryFilterMethod} method does not exist`
|
|
24
24
|
);
|
|
25
25
|
|
|
26
|
-
// @ts-expect-error
|
|
26
|
+
// @ts-expect-error - Too complex to type
|
|
27
27
|
return queryClient[queryFilterMethod](
|
|
28
28
|
composeMutationFilters(schema, filters as never),
|
|
29
|
-
// @ts-expect-error
|
|
29
|
+
// @ts-expect-error - Argument types are too complex
|
|
30
30
|
...args.slice(1, -1)
|
|
31
31
|
);
|
|
32
32
|
}
|
|
@@ -23,10 +23,10 @@ export function callQueryClientMethodWithQueryFilters<
|
|
|
23
23
|
`queryClient is invalid, ${queryFilterMethod} method does not exist`
|
|
24
24
|
);
|
|
25
25
|
|
|
26
|
-
// @ts-expect-error
|
|
26
|
+
// @ts-expect-error - Too complex to type
|
|
27
27
|
return queryClient[queryFilterMethod](
|
|
28
28
|
composeQueryFilters(schema, filters as never),
|
|
29
|
-
// @ts-expect-error
|
|
29
|
+
// @ts-expect-error - Argument types are too complex
|
|
30
30
|
...args.slice(1, -1)
|
|
31
31
|
);
|
|
32
32
|
}
|
|
@@ -31,7 +31,7 @@ export function callQueryClientMethodWithQueryKey<
|
|
|
31
31
|
? composeInfiniteQueryKey(schema, parameters)
|
|
32
32
|
: composeQueryKey(schema, parameters);
|
|
33
33
|
|
|
34
|
-
// @ts-expect-error
|
|
34
|
+
// @ts-expect-error - Too complex to type
|
|
35
35
|
return queryClient[queryFilterMethod](queryKey, ...args.slice(1, -1));
|
|
36
36
|
}
|
|
37
37
|
|
|
@@ -5,10 +5,7 @@ import type { OperationSchema } from './requestFn.js';
|
|
|
5
5
|
* Omit `body` or `requestBody` from mutation parameters if exists
|
|
6
6
|
* and return the rest of the parameters
|
|
7
7
|
*/
|
|
8
|
-
export function composeMutationKey<
|
|
9
|
-
TSchema extends OperationSchema,
|
|
10
|
-
TParams = undefined,
|
|
11
|
-
>(
|
|
8
|
+
export function composeMutationKey<TSchema extends OperationSchema>(
|
|
12
9
|
schema: TSchema,
|
|
13
10
|
parameters: undefined
|
|
14
11
|
): ServiceOperationMutationKey<TSchema, undefined>;
|
|
@@ -36,10 +33,11 @@ export function omitMutationPayload<T>(params: T) {
|
|
|
36
33
|
throw new Error('`params` must be object');
|
|
37
34
|
|
|
38
35
|
if ('body' in params || 'requestBody' in params) {
|
|
39
|
-
const {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
36
|
+
const {
|
|
37
|
+
body: _,
|
|
38
|
+
requestBody: __,
|
|
39
|
+
...paramsRest
|
|
40
|
+
} = params as Record<'body' | 'requestBody', unknown>;
|
|
43
41
|
return paramsRest;
|
|
44
42
|
}
|
|
45
43
|
|
|
@@ -5,6 +5,13 @@ type ProxyApplyCallback = (path: string[], args: unknown[]) => unknown;
|
|
|
5
5
|
*/
|
|
6
6
|
type ProxyGetCallback = (path: string[], key: string) => unknown | undefined;
|
|
7
7
|
|
|
8
|
+
// todo::rename to `qraftRecursiveProxy` with deprecated `createRecursiveProxy`
|
|
9
|
+
/**
|
|
10
|
+
* Creates a recursive proxy that calls the `getCallback` and `applyCallback` functions
|
|
11
|
+
* @param getCallback The callback to call when a proxy property is accessed
|
|
12
|
+
* @param applyCallback The callback to call when a proxy is called as a function
|
|
13
|
+
* @param path The current path of the proxy
|
|
14
|
+
*/
|
|
8
15
|
export function createRecursiveProxy(
|
|
9
16
|
getCallback: ProxyGetCallback,
|
|
10
17
|
applyCallback: ProxyApplyCallback,
|
package/src/lib/requestFn.ts
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* This function is used to make a request to a specified endpoint.
|
|
3
|
+
*
|
|
4
|
+
* @template T The expected return type of the request.
|
|
5
|
+
*
|
|
6
|
+
* @param schema The schema of the operation to be performed. It includes the OpenAPI path, HTTP method and media type.
|
|
7
|
+
* @param requestInfo The information required to make the request. It includes parameters, headers, body, etc.
|
|
8
|
+
* @param [options] Optional. Additional options for the request. It includes custom urlSerializer, bodySerializer, and fetch function.
|
|
9
|
+
*
|
|
10
|
+
* @returns {Promise<T>} Returns a promise that resolves with the response of the request.
|
|
11
|
+
*
|
|
12
|
+
* @throws {error: object|string, response: Response} Throws an error if the request fails. The error includes the error message and the response from the server.
|
|
3
13
|
*/
|
|
4
14
|
export async function requestFn<T>(
|
|
5
15
|
schema: OperationSchema,
|
|
@@ -14,7 +24,20 @@ export async function requestFn<T>(
|
|
|
14
24
|
}
|
|
15
25
|
|
|
16
26
|
/**
|
|
17
|
-
*
|
|
27
|
+
* This function is used to make a request to a specified endpoint.
|
|
28
|
+
* It's needed to create a custom `requestFn` with a custom `urlSerializer`
|
|
29
|
+
* and `bodySerializer`, with the tree-shaking of the default `requestFn`
|
|
30
|
+
* and its serializers.
|
|
31
|
+
*
|
|
32
|
+
* @template T The expected return type of the request.
|
|
33
|
+
*
|
|
34
|
+
* @param requestSchema The schema of the operation to be performed. It includes the OpenAPI path, HTTP method and media type.
|
|
35
|
+
* @param requestInfo The information required to make the request. It includes parameters, headers, body, etc.
|
|
36
|
+
* @param options The options for the request. It includes urlSerializer, bodySerializer, and fetch function. The 'urlSerializer' and 'bodySerializer' are required.
|
|
37
|
+
*
|
|
38
|
+
* @returns {Promise<T>} Returns a promise that resolves with the response of the request.
|
|
39
|
+
*
|
|
40
|
+
* @throws {error: object|string, response: Response} Throws an error if the request fails. The error includes the error message and the response from the server.
|
|
18
41
|
*/
|
|
19
42
|
export async function baseRequestFn<T>(
|
|
20
43
|
requestSchema: OperationSchema,
|
|
@@ -65,7 +88,10 @@ export function urlSerializer(
|
|
|
65
88
|
const path = schema.url.replace(
|
|
66
89
|
/{(.*?)}/g,
|
|
67
90
|
(substring: string, group: string) => {
|
|
68
|
-
if (
|
|
91
|
+
if (
|
|
92
|
+
info.parameters?.path &&
|
|
93
|
+
Object.prototype.hasOwnProperty.call(info.parameters.path, group)
|
|
94
|
+
) {
|
|
69
95
|
return encodeURI(String(info.parameters?.path[group]));
|
|
70
96
|
}
|
|
71
97
|
return substring;
|
|
@@ -254,7 +280,7 @@ export interface OperationSchema {
|
|
|
254
280
|
* Operation path
|
|
255
281
|
* @example /user/{id}
|
|
256
282
|
*/
|
|
257
|
-
readonly url: string;
|
|
283
|
+
readonly url: string; //todo::rename to `path`
|
|
258
284
|
|
|
259
285
|
/**
|
|
260
286
|
* Operation method
|
|
@@ -279,6 +305,7 @@ export interface OperationSchema {
|
|
|
279
305
|
export interface RequestFnPayload {
|
|
280
306
|
/**
|
|
281
307
|
* Base URL to use for the request
|
|
308
|
+
* @example 'https://api.example.com'
|
|
282
309
|
*/
|
|
283
310
|
baseUrl: string | undefined;
|
|
284
311
|
|
|
@@ -291,7 +318,6 @@ export interface RequestFnPayload {
|
|
|
291
318
|
*/
|
|
292
319
|
readonly parameters?: {
|
|
293
320
|
readonly path?: Record<string, any>;
|
|
294
|
-
readonly cookie?: Record<string, any>;
|
|
295
321
|
readonly header?: Record<string, any>;
|
|
296
322
|
readonly query?: Record<string, any>;
|
|
297
323
|
};
|
|
@@ -32,10 +32,10 @@ export function useComposeUseQueryOptions(
|
|
|
32
32
|
|
|
33
33
|
const queryFn =
|
|
34
34
|
options?.queryFn ??
|
|
35
|
-
// @ts-expect-error
|
|
35
|
+
// @ts-expect-error - Too complex to type
|
|
36
36
|
function ({ queryKey: [, queryParams], signal, meta, pageParam }) {
|
|
37
37
|
return contextValue.requestFn(schema, {
|
|
38
|
-
// @ts-expect-error
|
|
38
|
+
// @ts-expect-error - Too complex to type
|
|
39
39
|
parameters: infinite
|
|
40
40
|
? (shelfMerge(2, queryParams, pageParam) as never)
|
|
41
41
|
: queryParams,
|
|
@@ -19,8 +19,9 @@ export function useQueryClient(
|
|
|
19
19
|
qraftOptions: QraftClientOptions | undefined,
|
|
20
20
|
queryClient: QueryClient | undefined
|
|
21
21
|
) {
|
|
22
|
-
const queryClientByContext = useContext(
|
|
23
|
-
?.
|
|
22
|
+
const queryClientByContext = useContext(
|
|
23
|
+
qraftOptions?.context ?? QraftContext
|
|
24
|
+
)?.queryClient;
|
|
24
25
|
|
|
25
26
|
return useQueryClientTanstack(queryClient ?? queryClientByContext);
|
|
26
27
|
}
|
package/src/qraftAPIClient.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { Context } from 'react';
|
|
2
2
|
|
|
3
|
+
import type * as operationInvokeModule from './callbacks/operationInvokeFn.js';
|
|
3
4
|
import { createRecursiveProxy } from './lib/createRecursiveProxy.js';
|
|
4
5
|
import type { OperationSchema } from './lib/requestFn.js';
|
|
5
6
|
import type { QraftContextValue } from './QraftContext.js';
|
|
@@ -9,36 +10,34 @@ export interface QraftClientOptions {
|
|
|
9
10
|
}
|
|
10
11
|
|
|
11
12
|
export const qraftAPIClient = <
|
|
12
|
-
Services extends
|
|
13
|
+
Services extends ServicesBaseDeclaration<Services>,
|
|
13
14
|
Callbacks extends ServicesCallbacks,
|
|
14
15
|
>(
|
|
15
16
|
services: ServicesDeclaration<Services>,
|
|
16
17
|
callbacks: Callbacks,
|
|
17
18
|
options?: QraftClientOptions
|
|
18
|
-
):
|
|
19
|
+
): Services => {
|
|
19
20
|
return createRecursiveProxy(
|
|
20
|
-
(getPath, key)
|
|
21
|
-
if (getPath.length !== 2 || key !== 'schema') return;
|
|
21
|
+
function getCallback(getPath, key) {
|
|
22
|
+
if (getPath.length !== 2 || key !== 'schema') return; // todo::maybe return callback?
|
|
22
23
|
|
|
23
24
|
const serviceOperation = getByPath(services, getPath);
|
|
24
25
|
if (!isServiceOperation(serviceOperation))
|
|
25
26
|
throw new Error(`Service operation not found: ${getPath.join('.')}`);
|
|
26
27
|
return serviceOperation.schema;
|
|
27
28
|
},
|
|
28
|
-
(applyPath, args)
|
|
29
|
-
const path = applyPath
|
|
29
|
+
function applyCallback(applyPath, args) {
|
|
30
|
+
const { path, callbackName } = extractCallbackDetails(applyPath);
|
|
31
|
+
|
|
32
|
+
if (!(callbackName in callbacks))
|
|
33
|
+
throw new Error(`Function ${callbackName} is not supported`);
|
|
34
|
+
|
|
30
35
|
const serviceOperation = getByPath(services, path);
|
|
31
36
|
|
|
32
37
|
if (!isServiceOperation(serviceOperation))
|
|
33
38
|
throw new Error(`Service operation not found: ${path.join('.')}`);
|
|
34
39
|
|
|
35
|
-
|
|
36
|
-
const functionName = applyPath[applyPath.length - 1];
|
|
37
|
-
|
|
38
|
-
if (!(functionName in callbacks))
|
|
39
|
-
throw new Error(`Function ${functionName} is not supported`);
|
|
40
|
-
|
|
41
|
-
return callbacks[functionName as keyof Callbacks](
|
|
40
|
+
return callbacks[callbackName as keyof Callbacks](
|
|
42
41
|
options,
|
|
43
42
|
serviceOperation.schema,
|
|
44
43
|
args
|
|
@@ -48,6 +47,30 @@ export const qraftAPIClient = <
|
|
|
48
47
|
) as never;
|
|
49
48
|
};
|
|
50
49
|
|
|
50
|
+
/**
|
|
51
|
+
* Extracts Callback details from the applyPath
|
|
52
|
+
* @param applyPath
|
|
53
|
+
*/
|
|
54
|
+
function extractCallbackDetails(applyPath: string[]) {
|
|
55
|
+
// <service>.<operation>()
|
|
56
|
+
if (applyPath.length === 2) {
|
|
57
|
+
return {
|
|
58
|
+
path: applyPath,
|
|
59
|
+
callbackName: 'operationInvokeFn' satisfies Extract<
|
|
60
|
+
keyof typeof operationInvokeModule,
|
|
61
|
+
'operationInvokeFn'
|
|
62
|
+
>,
|
|
63
|
+
};
|
|
64
|
+
} else {
|
|
65
|
+
// <service>.<operation>.<method>()
|
|
66
|
+
return {
|
|
67
|
+
path: applyPath.slice(0, -1),
|
|
68
|
+
// The last arg is for instance `.useMutation` or `.useQuery()`
|
|
69
|
+
callbackName: applyPath[applyPath.length - 1],
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
51
74
|
function isServiceOperation(
|
|
52
75
|
input: unknown
|
|
53
76
|
): input is { schema: OperationSchema } {
|
|
@@ -61,13 +84,13 @@ function getByPath(obj: Record<string, unknown>, path: string[]) {
|
|
|
61
84
|
}, obj);
|
|
62
85
|
}
|
|
63
86
|
|
|
64
|
-
type
|
|
87
|
+
type ServicesBaseDeclaration<Services> = {
|
|
65
88
|
[service in keyof Services]: {
|
|
66
89
|
[method in keyof Services[service]]: { schema: OperationSchema };
|
|
67
90
|
};
|
|
68
91
|
};
|
|
69
92
|
|
|
70
|
-
type ServicesDeclaration<Services extends
|
|
93
|
+
type ServicesDeclaration<Services extends ServicesBaseDeclaration<Services>> = {
|
|
71
94
|
[service in keyof Services]: {
|
|
72
95
|
[method in keyof Services[service]]: {
|
|
73
96
|
schema: Services[service][method]['schema'];
|
|
@@ -75,27 +98,4 @@ type ServicesDeclaration<Services extends ServicesOutput<Services>> = {
|
|
|
75
98
|
};
|
|
76
99
|
};
|
|
77
100
|
|
|
78
|
-
type ServicesCallbacks = Record<string, (...rest: any[]) =>
|
|
79
|
-
|
|
80
|
-
type ServicesCallbacksFilter<
|
|
81
|
-
Services extends ServicesOutput<Services>,
|
|
82
|
-
Callbacks,
|
|
83
|
-
> = Services extends {
|
|
84
|
-
[serviceName in keyof Services]: {
|
|
85
|
-
[method in keyof Services[serviceName]]: { schema: OperationSchema };
|
|
86
|
-
};
|
|
87
|
-
}
|
|
88
|
-
? {
|
|
89
|
-
[serviceName in keyof Services]: {
|
|
90
|
-
[method in keyof Services[serviceName]]: Pick<
|
|
91
|
-
Services[serviceName][method],
|
|
92
|
-
FilterKeys<
|
|
93
|
-
keyof Services[serviceName][method],
|
|
94
|
-
Callbacks | 'schema' | 'types'
|
|
95
|
-
>
|
|
96
|
-
>;
|
|
97
|
-
};
|
|
98
|
-
}
|
|
99
|
-
: never;
|
|
100
|
-
|
|
101
|
-
type FilterKeys<T, K> = K extends T ? K : never;
|
|
101
|
+
type ServicesCallbacks = Record<string, (...rest: any[]) => unknown>;
|
|
@@ -1,9 +1,34 @@
|
|
|
1
|
+
interface QueryFnBaseUrlOptions {
|
|
2
|
+
/**
|
|
3
|
+
* Base URL to use for the request
|
|
4
|
+
* @example 'https://api.example.com'
|
|
5
|
+
*/
|
|
6
|
+
baseUrl: string;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
interface ServiceOperationMutationFnOptionsBase<TBody, TParams> {
|
|
10
|
+
parameters: TParams;
|
|
11
|
+
body: TBody;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
interface ServiceOperationMutationFnOptions<TBody, TParams>
|
|
15
|
+
extends ServiceOperationMutationFnOptionsBase<TBody, TParams> {
|
|
16
|
+
baseUrl?: never;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
interface ServiceOperationMutationFnOptionsWithBaseUrl<TBody, TParams>
|
|
20
|
+
extends ServiceOperationMutationFnOptionsBase<TBody, TParams>,
|
|
21
|
+
QueryFnBaseUrlOptions {}
|
|
22
|
+
|
|
1
23
|
export interface ServiceOperationMutationFn<
|
|
2
24
|
TSchema extends { url: string; method: string },
|
|
3
25
|
TBody,
|
|
4
26
|
TData,
|
|
5
27
|
TParams,
|
|
6
28
|
> {
|
|
29
|
+
/**
|
|
30
|
+
* @deprecated Use `<service>.<operation>(...)` instead.
|
|
31
|
+
*/
|
|
7
32
|
mutationFn(
|
|
8
33
|
client: (
|
|
9
34
|
schema: TSchema,
|
|
@@ -18,6 +43,9 @@ export interface ServiceOperationMutationFn<
|
|
|
18
43
|
}
|
|
19
44
|
): TData;
|
|
20
45
|
|
|
46
|
+
/**
|
|
47
|
+
* @deprecated Use `<service>.<operation>(...)` instead.
|
|
48
|
+
*/
|
|
21
49
|
mutationFn(
|
|
22
50
|
client: (
|
|
23
51
|
schema: TSchema,
|
|
@@ -31,4 +59,34 @@ export interface ServiceOperationMutationFn<
|
|
|
31
59
|
body: TBody;
|
|
32
60
|
}
|
|
33
61
|
): Promise<TData>;
|
|
62
|
+
|
|
63
|
+
<TOptions extends ServiceOperationMutationFnOptions<TBody, TParams>>(
|
|
64
|
+
options: TOptions,
|
|
65
|
+
client: (schema: TSchema, options: TOptions) => TData
|
|
66
|
+
): TData;
|
|
67
|
+
|
|
68
|
+
<
|
|
69
|
+
TOptions extends ServiceOperationMutationFnOptionsWithBaseUrl<
|
|
70
|
+
TBody,
|
|
71
|
+
TParams
|
|
72
|
+
>,
|
|
73
|
+
>(
|
|
74
|
+
options: TOptions,
|
|
75
|
+
client: (schema: TSchema, options: TOptions) => TData
|
|
76
|
+
): TData;
|
|
77
|
+
|
|
78
|
+
<TOptions extends ServiceOperationMutationFnOptions<TBody, TParams>>(
|
|
79
|
+
options: TOptions,
|
|
80
|
+
client: (schema: TSchema, options: TOptions) => Promise<TData>
|
|
81
|
+
): Promise<TData>;
|
|
82
|
+
|
|
83
|
+
<
|
|
84
|
+
TOptions extends ServiceOperationMutationFnOptionsWithBaseUrl<
|
|
85
|
+
TBody,
|
|
86
|
+
TParams
|
|
87
|
+
>,
|
|
88
|
+
>(
|
|
89
|
+
options: TOptions,
|
|
90
|
+
client: (schema: TSchema, options: TOptions) => Promise<TData>
|
|
91
|
+
): Promise<TData>;
|
|
34
92
|
}
|
|
@@ -14,6 +14,19 @@ interface QueryFnOptionsByParameters<
|
|
|
14
14
|
TSignal extends AbortSignal = AbortSignal,
|
|
15
15
|
> extends QueryFnOptionsBase<TMeta, TSignal> {
|
|
16
16
|
parameters: TParams;
|
|
17
|
+
|
|
18
|
+
queryKey?: never;
|
|
19
|
+
baseUrl?: never;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
interface QueryFnOptionsByParametersWithBaseUrl<
|
|
23
|
+
TParams,
|
|
24
|
+
TMeta extends Record<string, any>,
|
|
25
|
+
TSignal extends AbortSignal = AbortSignal,
|
|
26
|
+
> extends QueryFnOptionsBase<TMeta, TSignal>,
|
|
27
|
+
QueryFnBaseUrlOptions {
|
|
28
|
+
parameters: TParams;
|
|
29
|
+
|
|
17
30
|
queryKey?: never;
|
|
18
31
|
}
|
|
19
32
|
|
|
@@ -24,6 +37,29 @@ interface QueryFnOptionsByQueryKey<
|
|
|
24
37
|
TSignal extends AbortSignal = AbortSignal,
|
|
25
38
|
> extends QueryFnOptionsBase<TMeta, TSignal> {
|
|
26
39
|
queryKey: ServiceOperationQueryKey<TSchema, TParams>;
|
|
40
|
+
|
|
41
|
+
parameters?: never;
|
|
42
|
+
baseUrl?: never;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
interface QueryFnOptionsByQueryKeyWithBaseUrl<
|
|
46
|
+
TSchema extends { url: string; method: string },
|
|
47
|
+
TParams,
|
|
48
|
+
TMeta extends Record<string, any>,
|
|
49
|
+
TSignal extends AbortSignal = AbortSignal,
|
|
50
|
+
> extends QueryFnOptionsBase<TMeta, TSignal>,
|
|
51
|
+
QueryFnBaseUrlOptions {
|
|
52
|
+
queryKey: ServiceOperationQueryKey<TSchema, TParams>;
|
|
53
|
+
|
|
54
|
+
parameters?: never;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
interface QueryFnBaseUrlOptions {
|
|
58
|
+
/**
|
|
59
|
+
* Base URL to use for the request
|
|
60
|
+
* @example 'https://api.example.com'
|
|
61
|
+
*/
|
|
62
|
+
baseUrl: string;
|
|
27
63
|
}
|
|
28
64
|
|
|
29
65
|
export interface ServiceOperationQueryFn<
|
|
@@ -31,6 +67,9 @@ export interface ServiceOperationQueryFn<
|
|
|
31
67
|
TData,
|
|
32
68
|
TParams,
|
|
33
69
|
> {
|
|
70
|
+
/**
|
|
71
|
+
* @deprecated Use `<service>.<operation>(...)` instead.
|
|
72
|
+
*/
|
|
34
73
|
queryFn<
|
|
35
74
|
TMeta extends Record<string, any>,
|
|
36
75
|
TSignal extends AbortSignal = AbortSignal,
|
|
@@ -48,6 +87,9 @@ export interface ServiceOperationQueryFn<
|
|
|
48
87
|
) => TData
|
|
49
88
|
): TData;
|
|
50
89
|
|
|
90
|
+
/**
|
|
91
|
+
* @deprecated Use `<service>.<operation>(...)` instead.
|
|
92
|
+
*/
|
|
51
93
|
queryFn<
|
|
52
94
|
TMeta extends Record<string, any>,
|
|
53
95
|
TSignal extends AbortSignal = AbortSignal,
|
|
@@ -64,4 +106,72 @@ export interface ServiceOperationQueryFn<
|
|
|
64
106
|
}
|
|
65
107
|
) => Promise<TData>
|
|
66
108
|
): Promise<TData>;
|
|
109
|
+
|
|
110
|
+
<
|
|
111
|
+
TMeta extends Record<string, any>,
|
|
112
|
+
TSignal extends AbortSignal = AbortSignal,
|
|
113
|
+
>(
|
|
114
|
+
options:
|
|
115
|
+
| QueryFnOptionsByParameters<TParams, TMeta, TSignal>
|
|
116
|
+
| QueryFnOptionsByQueryKey<TSchema, TParams, TMeta, TSignal>,
|
|
117
|
+
client: (
|
|
118
|
+
schema: TSchema,
|
|
119
|
+
options: {
|
|
120
|
+
parameters: TParams;
|
|
121
|
+
signal?: TSignal;
|
|
122
|
+
meta?: TMeta;
|
|
123
|
+
}
|
|
124
|
+
) => TData
|
|
125
|
+
): TData;
|
|
126
|
+
|
|
127
|
+
<
|
|
128
|
+
TMeta extends Record<string, any>,
|
|
129
|
+
TSignal extends AbortSignal = AbortSignal,
|
|
130
|
+
>(
|
|
131
|
+
options:
|
|
132
|
+
| QueryFnOptionsByParametersWithBaseUrl<TParams, TMeta, TSignal>
|
|
133
|
+
| QueryFnOptionsByQueryKeyWithBaseUrl<TSchema, TParams, TMeta, TSignal>,
|
|
134
|
+
client: (
|
|
135
|
+
schema: TSchema,
|
|
136
|
+
options: {
|
|
137
|
+
parameters: TParams;
|
|
138
|
+
signal?: TSignal;
|
|
139
|
+
meta?: TMeta;
|
|
140
|
+
} & QueryFnBaseUrlOptions
|
|
141
|
+
) => TData
|
|
142
|
+
): TData;
|
|
143
|
+
|
|
144
|
+
<
|
|
145
|
+
TMeta extends Record<string, any>,
|
|
146
|
+
TSignal extends AbortSignal = AbortSignal,
|
|
147
|
+
>(
|
|
148
|
+
options:
|
|
149
|
+
| QueryFnOptionsByParameters<TParams, TMeta, TSignal>
|
|
150
|
+
| QueryFnOptionsByQueryKey<TSchema, TParams, TMeta, TSignal>,
|
|
151
|
+
client: (
|
|
152
|
+
schema: TSchema,
|
|
153
|
+
options: {
|
|
154
|
+
parameters: TParams;
|
|
155
|
+
signal?: TSignal;
|
|
156
|
+
meta?: TMeta;
|
|
157
|
+
}
|
|
158
|
+
) => Promise<TData>
|
|
159
|
+
): Promise<TData>;
|
|
160
|
+
|
|
161
|
+
<
|
|
162
|
+
TMeta extends Record<string, any>,
|
|
163
|
+
TSignal extends AbortSignal = AbortSignal,
|
|
164
|
+
>(
|
|
165
|
+
options:
|
|
166
|
+
| QueryFnOptionsByParametersWithBaseUrl<TParams, TMeta, TSignal>
|
|
167
|
+
| QueryFnOptionsByQueryKeyWithBaseUrl<TSchema, TParams, TMeta, TSignal>,
|
|
168
|
+
client: (
|
|
169
|
+
schema: TSchema,
|
|
170
|
+
options: {
|
|
171
|
+
parameters: TParams;
|
|
172
|
+
signal?: TSignal;
|
|
173
|
+
meta?: TMeta;
|
|
174
|
+
} & QueryFnBaseUrlOptions
|
|
175
|
+
) => Promise<TData>
|
|
176
|
+
): Promise<TData>;
|
|
67
177
|
}
|