@openapi-qraft/react 2.8.0 → 2.10.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 +21 -0
- package/dist/cjs/callbacks/useIsFetching.cjs +1 -1
- package/dist/cjs/callbacks/useIsFetching.cjs.map +1 -1
- package/dist/cjs/callbacks/useIsMutating.cjs +1 -1
- package/dist/cjs/callbacks/useIsMutating.cjs.map +1 -1
- package/dist/cjs/callbacks/useMutationState.cjs +1 -1
- package/dist/cjs/callbacks/useMutationState.cjs.map +1 -1
- package/dist/cjs/lib/requestFn.cjs +11 -24
- package/dist/cjs/lib/requestFn.cjs.map +1 -1
- package/dist/cjs/qraftAPIClient.cjs +1 -1
- package/dist/cjs/qraftAPIClient.cjs.map +1 -1
- package/dist/esm/callbacks/useIsFetching.js +1 -1
- package/dist/esm/callbacks/useIsFetching.js.map +1 -1
- package/dist/esm/callbacks/useIsMutating.js +1 -1
- package/dist/esm/callbacks/useIsMutating.js.map +1 -1
- package/dist/esm/callbacks/useMutationState.js +1 -1
- package/dist/esm/callbacks/useMutationState.js.map +1 -1
- package/dist/esm/lib/requestFn.js +11 -24
- package/dist/esm/lib/requestFn.js.map +1 -1
- package/dist/esm/qraftAPIClient.js +1 -1
- package/dist/esm/qraftAPIClient.js.map +1 -1
- package/dist/types/callbacks/useIsFetching.d.ts +1 -1
- package/dist/types/callbacks/useIsFetching.d.ts.map +1 -1
- package/dist/types/callbacks/useIsMutating.d.ts +1 -1
- package/dist/types/callbacks/useIsMutating.d.ts.map +1 -1
- package/dist/types/callbacks/useMutationState.d.ts +1 -1
- package/dist/types/callbacks/useMutationState.d.ts.map +1 -1
- package/dist/types/lib/requestFn.d.ts.map +1 -1
- package/dist/types/qraftAPIClient.d.ts +39 -12
- package/dist/types/qraftAPIClient.d.ts.map +1 -1
- package/package.json +5 -5
- package/src/callbacks/useIsFetching.ts +2 -2
- package/src/callbacks/useIsMutating.ts +2 -2
- package/src/callbacks/useMutationState.ts +2 -2
- package/src/lib/requestFn.ts +15 -28
- package/src/lib/urlSerializer.test.ts +265 -0
- package/src/qraftAPIClient.ts +100 -35
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,26 @@
|
|
|
1
1
|
# @openapi-qraft/react
|
|
2
2
|
|
|
3
|
+
## 2.10.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- ea029f5: Refactor `getQueryString` function to use native `URLSearchParams` instead of custom implementation for better maintainability.
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- 16e68c8: Fix URL serialization using `encodeURIComponent` instead of `encodeURI` to avoid issues with slash serialization in path parameters.
|
|
12
|
+
- @openapi-qraft/tanstack-query-react-types@2.10.0
|
|
13
|
+
|
|
14
|
+
## 2.9.0
|
|
15
|
+
|
|
16
|
+
### Minor Changes
|
|
17
|
+
|
|
18
|
+
- 8f0b86a: Enable all hooks to automatically retrieve the QueryClient from the `<QueryClientProvider />` context instead of requiring it to be passed in explicitly when the API Client created.
|
|
19
|
+
|
|
20
|
+
### Patch Changes
|
|
21
|
+
|
|
22
|
+
- @openapi-qraft/tanstack-query-react-types@2.9.0
|
|
23
|
+
|
|
3
24
|
## 2.8.0
|
|
4
25
|
|
|
5
26
|
### Minor Changes
|
|
@@ -6,7 +6,7 @@ var composeQueryFilters = require('../lib/composeQueryFilters.cjs');
|
|
|
6
6
|
|
|
7
7
|
const useIsFetching = (qraftOptions, schema, args)=>{
|
|
8
8
|
const [filters] = args;
|
|
9
|
-
return reactQuery.useIsFetching(composeQueryFilters.composeQueryFilters(schema, filters), qraftOptions
|
|
9
|
+
return reactQuery.useIsFetching(composeQueryFilters.composeQueryFilters(schema, filters), qraftOptions?.queryClient);
|
|
10
10
|
};
|
|
11
11
|
|
|
12
12
|
exports.useIsFetching = useIsFetching;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useIsFetching.cjs","sources":["../../../src/callbacks/useIsFetching.ts"],"sourcesContent":["'use client';\n\nimport type {\n OperationSchema,\n ServiceOperationUseIsFetchingQueries,\n} from '@openapi-qraft/tanstack-query-react-types';\nimport type { CreateAPIQueryClientOptions } from '../qraftAPIClient.js';\nimport { useIsFetching as useIsFetchingTanstack } from '@tanstack/react-query';\nimport { composeQueryFilters } from '../lib/composeQueryFilters.js';\n\nexport const useIsFetching: <TVariables = unknown>(\n qraftOptions: CreateAPIQueryClientOptions,\n schema: OperationSchema,\n args: Parameters<\n ServiceOperationUseIsFetchingQueries<\n OperationSchema,\n object | undefined,\n TVariables,\n unknown\n >['useIsFetching']\n >\n) => number = (qraftOptions, schema, args) => {\n const [filters] = args;\n\n return useIsFetchingTanstack(\n composeQueryFilters(schema, filters as never) as never,\n qraftOptions
|
|
1
|
+
{"version":3,"file":"useIsFetching.cjs","sources":["../../../src/callbacks/useIsFetching.ts"],"sourcesContent":["'use client';\n\nimport type {\n OperationSchema,\n ServiceOperationUseIsFetchingQueries,\n} from '@openapi-qraft/tanstack-query-react-types';\nimport type { CreateAPIQueryClientOptions } from '../qraftAPIClient.js';\nimport { useIsFetching as useIsFetchingTanstack } from '@tanstack/react-query';\nimport { composeQueryFilters } from '../lib/composeQueryFilters.js';\n\nexport const useIsFetching: <TVariables = unknown>(\n qraftOptions: CreateAPIQueryClientOptions | undefined,\n schema: OperationSchema,\n args: Parameters<\n ServiceOperationUseIsFetchingQueries<\n OperationSchema,\n object | undefined,\n TVariables,\n unknown\n >['useIsFetching']\n >\n) => number = (qraftOptions, schema, args) => {\n const [filters] = args;\n\n return useIsFetchingTanstack(\n composeQueryFilters(schema, filters as never) as never,\n qraftOptions?.queryClient\n ) as never;\n};\n"],"names":["useIsFetching","qraftOptions","schema","args","filters","useIsFetchingTanstack","composeQueryFilters","queryClient"],"mappings":";;;;;;AAUaA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,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ElB,CAAA,CAAA;;"}
|
|
@@ -6,7 +6,7 @@ var composeMutationFilters = require('../lib/composeMutationFilters.cjs');
|
|
|
6
6
|
|
|
7
7
|
const useIsMutating = (qraftOptions, schema, args)=>{
|
|
8
8
|
const [filters] = args;
|
|
9
|
-
return reactQuery.useIsMutating(composeMutationFilters.composeMutationFilters(schema, filters), qraftOptions
|
|
9
|
+
return reactQuery.useIsMutating(composeMutationFilters.composeMutationFilters(schema, filters), qraftOptions?.queryClient);
|
|
10
10
|
};
|
|
11
11
|
|
|
12
12
|
exports.useIsMutating = useIsMutating;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useIsMutating.cjs","sources":["../../../src/callbacks/useIsMutating.ts"],"sourcesContent":["'use client';\n\nimport type {\n OperationSchema,\n ServiceOperationUseIsMutating,\n} from '@openapi-qraft/tanstack-query-react-types';\nimport type { DefaultError, UseMutationResult } from '@tanstack/react-query';\nimport type { CreateAPIQueryClientOptions } from '../qraftAPIClient.js';\nimport { useIsMutating as useIsMutatingStateTanstack } from '@tanstack/react-query';\nimport { composeMutationFilters } from '../lib/composeMutationFilters.js';\n\nexport const useIsMutating: <\n TData = unknown,\n TError = DefaultError,\n TVariables = unknown,\n TContext = unknown,\n>(\n qraftOptions: CreateAPIQueryClientOptions,\n schema: OperationSchema,\n args: Parameters<\n ServiceOperationUseIsMutating<\n OperationSchema,\n object | undefined,\n TVariables,\n TData,\n DefaultError\n >['useIsMutating']\n >\n) => UseMutationResult<TData, TError, TVariables, TContext> = (\n qraftOptions,\n schema,\n args\n) => {\n const [filters] = args;\n\n return useIsMutatingStateTanstack(\n composeMutationFilters(schema, filters) as never,\n qraftOptions
|
|
1
|
+
{"version":3,"file":"useIsMutating.cjs","sources":["../../../src/callbacks/useIsMutating.ts"],"sourcesContent":["'use client';\n\nimport type {\n OperationSchema,\n ServiceOperationUseIsMutating,\n} from '@openapi-qraft/tanstack-query-react-types';\nimport type { DefaultError, UseMutationResult } from '@tanstack/react-query';\nimport type { CreateAPIQueryClientOptions } from '../qraftAPIClient.js';\nimport { useIsMutating as useIsMutatingStateTanstack } from '@tanstack/react-query';\nimport { composeMutationFilters } from '../lib/composeMutationFilters.js';\n\nexport const useIsMutating: <\n TData = unknown,\n TError = DefaultError,\n TVariables = unknown,\n TContext = unknown,\n>(\n qraftOptions: CreateAPIQueryClientOptions | undefined,\n schema: OperationSchema,\n args: Parameters<\n ServiceOperationUseIsMutating<\n OperationSchema,\n object | undefined,\n TVariables,\n TData,\n DefaultError\n >['useIsMutating']\n >\n) => UseMutationResult<TData, TError, TVariables, TContext> = (\n qraftOptions,\n schema,\n args\n) => {\n const [filters] = args;\n\n return useIsMutatingStateTanstack(\n composeMutationFilters(schema, filters) as never,\n qraftOptions?.queryClient\n ) as never;\n};\n"],"names":["useIsMutating","qraftOptions","schema","args","filters","useIsMutatingStateTanstack","composeMutationFilters","queryClient"],"mappings":";;;;;;AAWaA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,GAiBiD,CAC5DC,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,EACAC,CACAC,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,IAAAA,CAAAA,CAAAA,CAAAA,CAAAA;IAEA,MAAM,CAACC,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,EAAQ,CAAA,CAAA,CAAGD,IAAAA,CAAAA;AAElB,CAAA,CAAA,CAAA,CAAA,CAAOE,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CACLC,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAuBJ,CAAQE,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAC/BH,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAcM,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA;AAElB,CAAA,CAAA;;"}
|
|
@@ -9,7 +9,7 @@ const useMutationState = (qraftOptions, schema, args)=>{
|
|
|
9
9
|
return reactQuery.useMutationState({
|
|
10
10
|
...options,
|
|
11
11
|
filters: composeMutationFilters.composeMutationFilters(schema, options?.filters)
|
|
12
|
-
}, qraftOptions
|
|
12
|
+
}, qraftOptions?.queryClient);
|
|
13
13
|
};
|
|
14
14
|
|
|
15
15
|
exports.useMutationState = useMutationState;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useMutationState.cjs","sources":["../../../src/callbacks/useMutationState.ts"],"sourcesContent":["'use client';\n\nimport type {\n OperationSchema,\n ServiceOperationUseMutationState,\n} from '@openapi-qraft/tanstack-query-react-types';\nimport type { DefaultError, UseMutationResult } from '@tanstack/react-query';\nimport type { CreateAPIQueryClientOptions } from '../qraftAPIClient.js';\nimport { useMutationState as useMutationStateTanstack } from '@tanstack/react-query';\nimport { composeMutationFilters } from '../lib/composeMutationFilters.js';\n\nexport const useMutationState: <\n TData = unknown,\n TError = DefaultError,\n TVariables = unknown,\n TContext = unknown,\n>(\n qraftOptions: CreateAPIQueryClientOptions,\n schema: OperationSchema,\n args: Parameters<\n ServiceOperationUseMutationState<\n OperationSchema,\n object | undefined,\n TVariables,\n TData,\n DefaultError\n >['useMutationState']\n >\n) => UseMutationResult<TData, TError, TVariables, TContext> = (\n qraftOptions,\n schema,\n args\n) => {\n const [options] = args;\n\n return useMutationStateTanstack(\n {\n ...options,\n filters: composeMutationFilters(schema, options?.filters),\n } as never,\n qraftOptions
|
|
1
|
+
{"version":3,"file":"useMutationState.cjs","sources":["../../../src/callbacks/useMutationState.ts"],"sourcesContent":["'use client';\n\nimport type {\n OperationSchema,\n ServiceOperationUseMutationState,\n} from '@openapi-qraft/tanstack-query-react-types';\nimport type { DefaultError, UseMutationResult } from '@tanstack/react-query';\nimport type { CreateAPIQueryClientOptions } from '../qraftAPIClient.js';\nimport { useMutationState as useMutationStateTanstack } from '@tanstack/react-query';\nimport { composeMutationFilters } from '../lib/composeMutationFilters.js';\n\nexport const useMutationState: <\n TData = unknown,\n TError = DefaultError,\n TVariables = unknown,\n TContext = unknown,\n>(\n qraftOptions: CreateAPIQueryClientOptions | undefined,\n schema: OperationSchema,\n args: Parameters<\n ServiceOperationUseMutationState<\n OperationSchema,\n object | undefined,\n TVariables,\n TData,\n DefaultError\n >['useMutationState']\n >\n) => UseMutationResult<TData, TError, TVariables, TContext> = (\n qraftOptions,\n schema,\n args\n) => {\n const [options] = args;\n\n return useMutationStateTanstack(\n {\n ...options,\n filters: composeMutationFilters(schema, options?.filters),\n } as never,\n qraftOptions?.queryClient\n ) as never;\n};\n"],"names":["useMutationState","qraftOptions","schema","args","options","useMutationStateTanstack","filters","composeMutationFilters","queryClient"],"mappings":";;;;;;AAWaA,CAAAA,CAAAA,CAA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,CAAA,CAAA,CAAA,CAAA,CAAA,CACAL,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAcO,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA;AAElB,CAAA,CAAA;;"}
|
|
@@ -66,7 +66,7 @@ var responseUtils = require('./responseUtils.cjs');
|
|
|
66
66
|
*/ function urlSerializer(schema, info) {
|
|
67
67
|
const path = schema.url.replace(/{(.*?)}/g, (substring, group)=>{
|
|
68
68
|
if (info.parameters?.path && Object.prototype.hasOwnProperty.call(info.parameters.path, group)) {
|
|
69
|
-
return
|
|
69
|
+
return encodeURIComponent(String(info.parameters?.path[group]));
|
|
70
70
|
}
|
|
71
71
|
return substring;
|
|
72
72
|
});
|
|
@@ -77,31 +77,18 @@ var responseUtils = require('./responseUtils.cjs');
|
|
|
77
77
|
return `${baseUrl}${path}`;
|
|
78
78
|
}
|
|
79
79
|
function getQueryString(params) {
|
|
80
|
-
const
|
|
81
|
-
const
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
if (typeof value === '
|
|
86
|
-
|
|
87
|
-
value.forEach((v)=>{
|
|
88
|
-
process(key, v);
|
|
89
|
-
});
|
|
90
|
-
} else if (typeof value === 'object') {
|
|
91
|
-
Object.entries(value).forEach(([k, v])=>{
|
|
92
|
-
process(`${key}[${k}]`, v);
|
|
93
|
-
});
|
|
94
|
-
} else {
|
|
95
|
-
append(key, value);
|
|
80
|
+
const search = new URLSearchParams();
|
|
81
|
+
const walk = (prefix, value)=>{
|
|
82
|
+
if (value == null) return;
|
|
83
|
+
if (value instanceof Date) return search.append(prefix, value.toISOString());
|
|
84
|
+
if (Array.isArray(value)) return value.forEach((v)=>walk(prefix, v));
|
|
85
|
+
if (typeof value === 'object') {
|
|
86
|
+
return Object.entries(value).forEach(([k, v])=>walk(`${prefix}[${k}]`, v));
|
|
96
87
|
}
|
|
88
|
+
search.append(prefix, String(value));
|
|
97
89
|
};
|
|
98
|
-
Object.entries(params).forEach(([
|
|
99
|
-
|
|
100
|
-
});
|
|
101
|
-
if (qs.length > 0) {
|
|
102
|
-
return `?${qs.join('&')}`;
|
|
103
|
-
}
|
|
104
|
-
return '';
|
|
90
|
+
Object.entries(params).forEach(([k, v])=>walk(k, v));
|
|
91
|
+
return search.toString() ? `?${search.toString()}` : '';
|
|
105
92
|
}
|
|
106
93
|
function mergeHeaders(...allHeaders) {
|
|
107
94
|
const headers = new Headers();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"requestFn.cjs","sources":["../../../src/lib/requestFn.ts"],"sourcesContent":["import type {\n HeadersOptions,\n OperationSchema,\n RequestFnInfo,\n RequestFnOptions,\n RequestFnResponse,\n} from '@openapi-qraft/tanstack-query-react-types';\nimport { processResponse, resolveResponse } from './responseUtils.js';\n\n/**\n * This function is used to make a request to a specified endpoint.\n *\n * @template T The expected return type of the request.\n *\n * @param schema The schema of the operation to be performed. It includes the OpenAPI path, HTTP method and media type.\n * @param requestInfo The information required to make the request. It includes parameters, headers, body, etc.\n * @param [options] Optional. Additional options for the request. It includes custom urlSerializer, bodySerializer, and fetch function.\n *\n * @returns {Promise<T>} Returns a promise that resolves with the response of the request.\n *\n * @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.\n */\nexport async function requestFn<TData, TError>(\n schema: OperationSchema,\n requestInfo: RequestFnInfo,\n options?: RequestFnOptions\n): Promise<RequestFnResponse<TData, TError>> {\n return baseRequestFn<TData, TError>(schema, requestInfo, {\n urlSerializer,\n bodySerializer,\n ...options,\n });\n}\n\n/**\n * This function is used to make a request to a specified endpoint.\n * It's necessary to create a custom `requestFn` with a custom `urlSerializer`\n * and `bodySerializer`, with the tree-shaking of the default `requestFn`\n * and its serializers.\n *\n * @template T The expected return type of the request.\n *\n * @param requestSchema The schema of the operation to be performed. It includes the OpenAPI path, HTTP method and media type.\n * @param requestInfo The information required to make the request. It includes parameters, headers, body, etc.\n * @param options The options for the request. It includes urlSerializer, bodySerializer, and fetch function. The 'urlSerializer' and 'bodySerializer' are required.\n *\n * @returns {Promise<T>} Returns a promise that resolves with the response of the request.\n *\n * @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.\n */\nexport async function baseRequestFn<TData, TError>(\n requestSchema: OperationSchema,\n requestInfo: RequestFnInfo,\n options: WithRequired<RequestFnOptions, 'urlSerializer' | 'bodySerializer'>\n): Promise<RequestFnResponse<TData, TError>> {\n const { parameters, headers, body, ...requestInfoRest } = requestInfo;\n\n const requestPayload = options.bodySerializer(requestSchema, body);\n\n const baseFetch = options.fetch ?? fetch;\n\n return baseFetch(options.urlSerializer(requestSchema, requestInfo), {\n method: requestSchema.method.toUpperCase(),\n body: requestPayload?.body,\n headers: mergeHeaders(\n { Accept: 'application/json' },\n requestPayload?.headers,\n headers,\n parameters?.header\n ),\n ...requestInfoRest,\n })\n .then(processResponse as typeof processResponse<TData, TError>)\n .catch(resolveResponse as typeof resolveResponse<TData, TError>);\n}\n\n/**\n * Serializes the given schema and request payload into a URL string.\n *\n * This function is implemented according to the URI Template standard\n * defined in RFC 6570. It supports the expansion of path and query parameters,\n * correctly handling empty arrays, `null`, and `undefined` values by ignoring\n * them during the expansion process, as specified by the standard.\n *\n * For more information, refer to the official documentation:\n * https://datatracker.ietf.org/doc/html/rfc6570\n *\n * @param schema - The operation schema containing the URL template and method.\n * @param info - The request payload including baseUrl, path parameters, and query parameters.\n * @returns The fully constructed URL string.\n */\nexport function urlSerializer(\n schema: OperationSchema,\n info: Pick<RequestFnInfo, 'baseUrl' | 'parameters'>\n): string {\n const path = schema.url.replace(\n /{(.*?)}/g,\n (substring: string, group: string) => {\n if (\n info.parameters?.path &&\n Object.prototype.hasOwnProperty.call(info.parameters.path, group)\n ) {\n return encodeURI(String(info.parameters?.path[group]));\n }\n return substring;\n }\n );\n\n const baseUrl = info.baseUrl ?? '';\n\n if (info.parameters?.query) {\n return `${baseUrl}${path}${getQueryString(info.parameters.query)}`;\n }\n\n return `${baseUrl}${path}`;\n}\n\nfunction getQueryString(params: Record<string, any>): string {\n const qs: string[] = [];\n\n const append = (key: string, value: any) => {\n qs.push(`${encodeURIComponent(key)}=${encodeURIComponent(String(value))}`);\n };\n\n const process = (key: string, value: any) => {\n if (typeof value === 'undefined' || value === null) return;\n\n if (Array.isArray(value)) {\n value.forEach((v) => {\n process(key, v);\n });\n } else if (typeof value === 'object') {\n Object.entries(value).forEach(([k, v]) => {\n process(`${key}[${k}]`, v);\n });\n } else {\n append(key, value);\n }\n };\n\n Object.entries(params).forEach(([key, value]) => {\n process(key, value);\n });\n\n if (qs.length > 0) {\n return `?${qs.join('&')}`;\n }\n\n return '';\n}\n\nexport function mergeHeaders(...allHeaders: (HeadersOptions | undefined)[]) {\n const headers = new Headers();\n\n for (const headerSet of allHeaders) {\n if (!headerSet || typeof headerSet !== 'object') {\n continue;\n }\n\n const headersIterator =\n headerSet instanceof Headers\n ? headerSet.entries()\n : Object.entries(headerSet);\n\n for (const [headerKey, headerValue] of headersIterator) {\n if (headerValue === null) {\n headers.delete(headerKey);\n } else if (headerValue !== undefined) {\n headers.set(headerKey, headerValue);\n }\n }\n }\n\n return headers;\n}\n\nexport function bodySerializer(\n schema: OperationSchema,\n body: RequestFnInfo['body']\n) {\n if (isReadOnlyOperation(schema)) return undefined;\n\n if (body === undefined || body === null) return undefined;\n\n if (typeof body === 'string') {\n return {\n body,\n headers: {\n 'Content-Type':\n // prefer text/* media type\n schema.mediaType?.find((mediaType) => mediaType.includes('text/')) ??\n // prefer JSON media type, assume that body is serialized as JSON\n schema.mediaType?.find((mediaType) => mediaType.includes('/json')) ??\n 'text/plain',\n },\n };\n }\n\n if (body instanceof FormData) {\n return {\n body,\n headers: {\n // remove `Content-Type` if the serialized body is FormData;\n // the browser will correctly set Content-Type & boundary expression\n 'Content-Type': null,\n },\n };\n }\n\n if (body instanceof Blob) {\n return {\n body,\n headers: {\n 'Content-Type':\n body.type ||\n schema.mediaType?.find(\n (mediaType) =>\n !(\n mediaType.includes('text/') &&\n mediaType.includes('/form-data') &&\n mediaType.includes('/json')\n )\n ) ||\n 'application/octet-stream',\n },\n };\n }\n\n let jsonMediaType: string | null = null;\n let formDataMediaType: string | null = null;\n\n if (schema.mediaType) {\n for (let i = 0; i < schema.mediaType.length; i++) {\n const mediaType = schema.mediaType[i];\n if (mediaType.includes('/json')) jsonMediaType = mediaType;\n else if (mediaType.includes('/form-data')) formDataMediaType = mediaType;\n }\n }\n\n if (formDataMediaType) {\n if (\n !jsonMediaType ||\n // Prefer FormData serialization if one of the fields is a Blob\n Object.values(body).some((value) => value instanceof Blob)\n ) {\n return {\n body: getRequestBodyFormData(body),\n headers: {\n // remove `Content-Type` if the serialized body is FormData;\n // the browser will correctly set Content-Type & boundary expression\n 'Content-Type': null,\n },\n };\n }\n }\n\n return {\n body: JSON.stringify(body),\n headers: {\n 'Content-Type': jsonMediaType ?? 'application/json',\n },\n };\n}\n\nfunction getRequestBodyFormData(\n body: NonNullable<RequestFnInfo['body']>\n): FormData {\n if (body instanceof FormData) return body;\n if (typeof body !== 'object')\n throw new Error(`Unsupported body type ${typeof body} in form-data.`);\n\n const formData = new FormData();\n\n const process = (key: string, value: any) => {\n if (typeof value === 'string' || value instanceof Blob) {\n formData.append(key, value);\n } else {\n formData.append(key, JSON.stringify(value));\n }\n };\n\n Object.entries(body)\n .filter(([_, value]) => typeof value !== 'undefined' && value !== null)\n .forEach(([key, value]) => {\n if (Array.isArray(value)) {\n value.forEach((v) => process(key, v));\n } else {\n process(key, value);\n }\n });\n\n return formData;\n}\n\ntype WithRequired<T, K extends keyof T> = T & {\n [_ in K]: {};\n};\n\nexport type {\n RequestFn,\n RequestFnResponse,\n HeadersOptions,\n RequestFnOptions,\n RequestFnInfo,\n OperationSchema,\n} from '@openapi-qraft/tanstack-query-react-types';\n\n/**\n * @deprecated use `RequestFnInfo` instead\n */\nexport type RequestFnPayload = RequestFnInfo;\n\nfunction isReadOnlyOperation(operation: {\n readonly method:\n | 'get'\n | 'put'\n | 'post'\n | 'patch'\n | 'delete'\n | 'options'\n | 'head'\n | 'trace';\n}) {\n return (\n operation.method === 'get' ||\n operation.method === 'head' ||\n operation.method === 'trace' ||\n operation.method === 'options'\n );\n}\n"],"names":["requestFn","schema","requestInfo","options","baseRequestFn","urlSerializer","bodySerializer","requestSchema","parameters","headers","body","requestInfoRest","requestPayload","baseFetch","fetch","method","toUpperCase","mergeHeaders","Accept","header","then","processResponse","catch","resolveResponse","info","path","url","replace","substring","group","Object","prototype","hasOwnProperty","call","encodeURI","String","baseUrl","query","getQueryString","params","qs","append","key","value","push","encodeURIComponent","process","Array","isArray","forEach","v","entries","k","length","join","allHeaders","Headers","headerSet","headersIterator","headerKey","headerValue","delete","undefined","set","isReadOnlyOperation","mediaType","find","includes","FormData","Blob","type","jsonMediaType","formDataMediaType","i","values","some","getRequestBodyFormData","JSON","stringify","Error","formData","filter","_","operation"],"mappings":";;;;AASA;;;;;;;;;;;;AAYC,IACM,eAAeA,SAAAA,CACpBC,MAAuB,EACvBC,WAA0B,EAC1BC,OAA0B,EAAA;IAE1B,OAAOC,aAAAA,CAA6BH,QAAQC,WAAa,EAAA;AACvDG,QAAAA,aAAAA;AACAC,QAAAA,cAAAA;AACA,QAAA,GAAGH,OAAO;AACZ,KAAA,CAAA,CAAA;AACF,CAAA;AAEA;;;;;;;;;;;;;;;AAeC,IACM,eAAeC,aAAAA,CACpBG,aAA8B,EAC9BL,WAA0B,EAC1BC,OAA2E,EAAA;IAE3E,MAAM,EAAEK,UAAU,EAAEC,OAAO,EAAEC,IAAI,EAAE,GAAGC,eAAAA,EAAiB,GAAGT,WAAAA,CAAAA;AAE1D,IAAA,MAAMU,cAAiBT,GAAAA,OAAAA,CAAQG,cAAc,CAACC,aAAeG,EAAAA,IAAAA,CAAAA,CAAAA;IAE7D,MAAM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\n OperationSchema,\n RequestFnInfo,\n RequestFnOptions,\n RequestFnResponse,\n} from '@openapi-qraft/tanstack-query-react-types';\nimport { processResponse, resolveResponse } from './responseUtils.js';\n\n/**\n * This function is used to make a request to a specified endpoint.\n *\n * @template T The expected return type of the request.\n *\n * @param schema The schema of the operation to be performed. It includes the OpenAPI path, HTTP method and media type.\n * @param requestInfo The information required to make the request. It includes parameters, headers, body, etc.\n * @param [options] Optional. Additional options for the request. It includes custom urlSerializer, bodySerializer, and fetch function.\n *\n * @returns {Promise<T>} Returns a promise that resolves with the response of the request.\n *\n * @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.\n */\nexport async function requestFn<TData, TError>(\n schema: OperationSchema,\n requestInfo: RequestFnInfo,\n options?: RequestFnOptions\n): Promise<RequestFnResponse<TData, TError>> {\n return baseRequestFn<TData, TError>(schema, requestInfo, {\n urlSerializer,\n bodySerializer,\n ...options,\n });\n}\n\n/**\n * This function is used to make a request to a specified endpoint.\n * It's necessary to create a custom `requestFn` with a custom `urlSerializer`\n * and `bodySerializer`, with the tree-shaking of the default `requestFn`\n * and its serializers.\n *\n * @template T The expected return type of the request.\n *\n * @param requestSchema The schema of the operation to be performed. It includes the OpenAPI path, HTTP method and media type.\n * @param requestInfo The information required to make the request. It includes parameters, headers, body, etc.\n * @param options The options for the request. It includes urlSerializer, bodySerializer, and fetch function. The 'urlSerializer' and 'bodySerializer' are required.\n *\n * @returns {Promise<T>} Returns a promise that resolves with the response of the request.\n *\n * @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.\n */\nexport async function baseRequestFn<TData, TError>(\n requestSchema: OperationSchema,\n requestInfo: RequestFnInfo,\n options: WithRequired<RequestFnOptions, 'urlSerializer' | 'bodySerializer'>\n): Promise<RequestFnResponse<TData, TError>> {\n const { parameters, headers, body, ...requestInfoRest } = requestInfo;\n\n const requestPayload = options.bodySerializer(requestSchema, body);\n\n const baseFetch = options.fetch ?? fetch;\n\n return baseFetch(options.urlSerializer(requestSchema, requestInfo), {\n method: requestSchema.method.toUpperCase(),\n body: requestPayload?.body,\n headers: mergeHeaders(\n { Accept: 'application/json' },\n requestPayload?.headers,\n headers,\n parameters?.header\n ),\n ...requestInfoRest,\n })\n .then(processResponse as typeof processResponse<TData, TError>)\n .catch(resolveResponse as typeof resolveResponse<TData, TError>);\n}\n\n/**\n * Serializes the given schema and request payload into a URL string.\n *\n * This function is implemented according to the URI Template standard\n * defined in RFC 6570. It supports the expansion of path and query parameters,\n * correctly handling empty arrays, `null`, and `undefined` values by ignoring\n * them during the expansion process, as specified by the standard.\n *\n * For more information, refer to the official documentation:\n * https://datatracker.ietf.org/doc/html/rfc6570\n *\n * @param schema - The operation schema containing the URL template and method.\n * @param info - The request payload including baseUrl, path parameters, and query parameters.\n * @returns The fully constructed URL string.\n */\nexport function urlSerializer(\n schema: OperationSchema,\n info: Pick<RequestFnInfo, 'baseUrl' | 'parameters'>\n): string {\n const path = schema.url.replace(\n /{(.*?)}/g,\n (substring: string, group: string) => {\n if (\n info.parameters?.path &&\n Object.prototype.hasOwnProperty.call(info.parameters.path, group)\n ) {\n return encodeURIComponent(String(info.parameters?.path[group]));\n }\n return substring;\n }\n );\n\n const baseUrl = info.baseUrl ?? '';\n\n if (info.parameters?.query) {\n return `${baseUrl}${path}${getQueryString(info.parameters.query)}`;\n }\n\n return `${baseUrl}${path}`;\n}\n\nfunction getQueryString(params: Record<string, any>): string {\n const search = new URLSearchParams();\n\n const walk = (prefix: string, value: any) => {\n if (value == null) return;\n if (value instanceof Date)\n return search.append(prefix, value.toISOString());\n if (Array.isArray(value)) return value.forEach((v) => walk(prefix, v));\n if (typeof value === 'object') {\n return Object.entries(value).forEach(([k, v]) =>\n walk(`${prefix}[${k}]`, v)\n );\n }\n search.append(prefix, String(value));\n };\n\n Object.entries(params).forEach(([k, v]) => walk(k, v));\n\n return search.toString() ? `?${search.toString()}` : '';\n}\n\nexport function mergeHeaders(...allHeaders: (HeadersOptions | undefined)[]) {\n const headers = new Headers();\n\n for (const headerSet of allHeaders) {\n if (!headerSet || typeof headerSet !== 'object') {\n continue;\n }\n\n const headersIterator =\n headerSet instanceof Headers\n ? headerSet.entries()\n : Object.entries(headerSet);\n\n for (const [headerKey, headerValue] of headersIterator) {\n if (headerValue === null) {\n headers.delete(headerKey);\n } else if (headerValue !== undefined) {\n headers.set(headerKey, headerValue);\n }\n }\n }\n\n return headers;\n}\n\nexport function bodySerializer(\n schema: OperationSchema,\n body: RequestFnInfo['body']\n) {\n if (isReadOnlyOperation(schema)) return undefined;\n\n if (body === undefined || body === null) return undefined;\n\n if (typeof body === 'string') {\n return {\n body,\n headers: {\n 'Content-Type':\n // prefer text/* media type\n schema.mediaType?.find((mediaType) => mediaType.includes('text/')) ??\n // prefer JSON media type, assume that body is serialized as JSON\n schema.mediaType?.find((mediaType) => mediaType.includes('/json')) ??\n 'text/plain',\n },\n };\n }\n\n if (body instanceof FormData) {\n return {\n body,\n headers: {\n // remove `Content-Type` if the serialized body is FormData;\n // the browser will correctly set Content-Type & boundary expression\n 'Content-Type': null,\n },\n };\n }\n\n if (body instanceof Blob) {\n return {\n body,\n headers: {\n 'Content-Type':\n body.type ||\n schema.mediaType?.find(\n (mediaType) =>\n !(\n mediaType.includes('text/') &&\n mediaType.includes('/form-data') &&\n mediaType.includes('/json')\n )\n ) ||\n 'application/octet-stream',\n },\n };\n }\n\n let jsonMediaType: string | null = null;\n let formDataMediaType: string | null = null;\n\n if (schema.mediaType) {\n for (let i = 0; i < schema.mediaType.length; i++) {\n const mediaType = schema.mediaType[i];\n if (mediaType.includes('/json')) jsonMediaType = mediaType;\n else if (mediaType.includes('/form-data')) formDataMediaType = mediaType;\n }\n }\n\n if (formDataMediaType) {\n if (\n !jsonMediaType ||\n // Prefer FormData serialization if one of the fields is a Blob\n Object.values(body).some((value) => value instanceof Blob)\n ) {\n return {\n body: getRequestBodyFormData(body),\n headers: {\n // remove `Content-Type` if the serialized body is FormData;\n // the browser will correctly set Content-Type & boundary expression\n 'Content-Type': null,\n },\n };\n }\n }\n\n return {\n body: JSON.stringify(body),\n headers: {\n 'Content-Type': jsonMediaType ?? 'application/json',\n },\n };\n}\n\nfunction getRequestBodyFormData(\n body: NonNullable<RequestFnInfo['body']>\n): FormData {\n if (body instanceof FormData) return body;\n if (typeof body !== 'object')\n throw new Error(`Unsupported body type ${typeof body} in form-data.`);\n\n const formData = new FormData();\n\n const process = (key: string, value: any) => {\n if (typeof value === 'string' || value instanceof Blob) {\n formData.append(key, value);\n } else {\n formData.append(key, JSON.stringify(value));\n }\n };\n\n Object.entries(body)\n .filter(([_, value]) => typeof value !== 'undefined' && value !== null)\n .forEach(([key, value]) => {\n if (Array.isArray(value)) {\n value.forEach((v) => process(key, v));\n } else {\n process(key, value);\n }\n });\n\n return formData;\n}\n\ntype WithRequired<T, K extends keyof T> = T & {\n [_ in K]: {};\n};\n\nexport type {\n RequestFn,\n RequestFnResponse,\n HeadersOptions,\n RequestFnOptions,\n RequestFnInfo,\n OperationSchema,\n} from '@openapi-qraft/tanstack-query-react-types';\n\n/**\n * @deprecated use `RequestFnInfo` instead\n */\nexport type RequestFnPayload = RequestFnInfo;\n\nfunction isReadOnlyOperation(operation: {\n readonly method:\n | 'get'\n | 'put'\n | 'post'\n | 'patch'\n | 'delete'\n | 'options'\n | 'head'\n | 'trace';\n}) {\n return (\n operation.method === 'get' ||\n operation.method === 'head' ||\n operation.method === 'trace' ||\n operation.method === 'options'\n );\n}\n"],"names":["requestFn","schema","requestInfo","options","baseRequestFn","urlSerializer","bodySerializer","requestSchema","parameters","headers","body","requestInfoRest","requestPayload","baseFetch","fetch","method","toUpperCase","mergeHeaders","Accept","header","then","processResponse","catch","resolveResponse","info","path","url","replace","substring","group","Object","prototype","hasOwnProperty","call","encodeURIComponent","String","baseUrl","query","getQueryString","params","search","URLSearchParams","walk","prefix","value","Date","append","toISOString","Array","isArray","forEach","v","entries","k","toString","allHeaders","Headers","headerSet","headersIterator","headerKey","headerValue","delete","undefined","set","isReadOnlyOperation","mediaType","find","includes","FormData","Blob","type","jsonMediaType","formDataMediaType","i","length","values","some","getRequestBodyFormData","JSON","stringify","Error","formData","process","key","filter","_","operation"],"mappings":";;;;AASA;;;;;;;;;;;;AAYC,IACM,eAAeA,SAAAA,CACpBC,MAAuB,EACvBC,WAA0B,EAC1BC,OAA0B,EAAA;IAE1B,OAAOC,aAAAA,CAA6BH,QAAQC,WAAa,EAAA;AACvDG,QAAAA,aAAAA;AACAC,QAAAA,cAAAA;AACA,QAAA,GAAGH,OAAO;AACZ,KAAA,CAAA,CAAA;AACF,CAAA;AAEA;;;;;;;;;;;;;;;AAeC,IACM,eAAeC,aAAAA,CACpBG,aAA8B,EAC9BL,WAA0B,EAC1BC,OAA2E,EAAA;IAE3E,MAAM,EAAEK,UAAU,EAAEC,OAAO,EAAEC,IAAI,EAAE,GAAGC,eAAAA,EAAiB,GAAGT,WAAAA,CAAAA;AAE1D,IAAA,MAAMU,cAAiBT,GAAAA,OAAAA,CAAQG,cAAc,CAACC,aAAeG,EAAAA,IAAAA,CAAAA,CAAAA;IAE7D,MAAMG,SAAAA,GAAYV,OAAQW,CAAAA,KAAK,IAAIA,KAAAA,CAAAA;AAEnC,IAAA,OAAOD,SAAUV,CAAAA,OAAAA,CAAQE,aAAa,CAACE,eAAeL,WAAc,CAAA,EAAA;QAClEa,MAAQR,EAAAA,aAAAA,CAAcQ,MAAM,CAACC,WAAW,EAAA;AACxCN,QAAAA,IAAAA,EAAME,cAAgBF,EAAAA,IAAAA;AACtBD,QAAAA,OAAAA,EAASQ,YACP,CAAA;YAAEC,MAAQ,EAAA,kBAAA;SACVN,EAAAA,cAAAA,EAAgBH,OAChBA,EAAAA,OAAAA,EACAD,UAAYW,EAAAA,MAAAA,CAAAA;AAEd,QAAA,GAAGR,eAAe;AACpB,KAAA,CAAA,CACGS,IAAI,CAACC,6BACLC,CAAAA,CAAAA,KAAK,CAACC,6BAAAA,CAAAA,CAAAA;AACX,CAAA;AAEA;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AAAA,KAAAA,CAAAA,CAAAA;AACf,SAAA;AACF,KAAA,CAAA,CAAA;IAEF,OAAOqC,QAAAA,CAAAA;AACT,CAAA;AAoBA,SAASjB,oBAAoBsB,SAU5B,EAAA;AACC,IAAA,OACEA,SAAUvE,CAAAA,MAAM,KAAK,KAAA,IACrBuE,UAAUvE,MAAM,KAAK,MACrBuE,IAAAA,SAAAA,CAAUvE,MAAM,KAAK,OACrBuE,IAAAA,SAAAA,CAAUvE,MAAM,KAAK,SAAA,CAAA;AAEzB;;;;;;;;"}
|
|
@@ -39,7 +39,7 @@ function qraftAPIClient(services, callbacks, options) {
|
|
|
39
39
|
assertValidCallbackName(callbackName, callbacks);
|
|
40
40
|
const serviceOperation = getByPath(services, path);
|
|
41
41
|
if (!isServiceOperation(serviceOperation)) throw new Error(`Service operation not found: ${path.join('.')}`);
|
|
42
|
-
if (callbackName !== 'operationInvokeFn' && callbackName !== 'getQueryKey' && callbackName !== 'getMutationKey' && callbackName !== 'getInfiniteQueryKey') {
|
|
42
|
+
if (callbackName !== 'operationInvokeFn' && callbackName !== 'getQueryKey' && callbackName !== 'getMutationKey' && callbackName !== 'getInfiniteQueryKey' && callbackName !== 'useInfiniteQuery' && callbackName !== 'useQueries' && callbackName !== 'useQuery' && callbackName !== 'useSuspenseInfiniteQuery' && callbackName !== 'useSuspenseQueries' && callbackName !== 'useSuspenseQuery' && callbackName !== 'useIsFetching' && callbackName !== 'useMutation' && callbackName !== 'useIsMutating' && callbackName !== 'useMutationState') {
|
|
43
43
|
if (!options || !('queryClient' in options && options.queryClient)) throw new Error(`'qraft.<service>.<operation>.${String(callbackName)}()' requires 'queryClient' in 'createAPIClient(...)' options.`);
|
|
44
44
|
}
|
|
45
45
|
// @ts-expect-error - Too complex union type
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"qraftAPIClient.cjs","sources":["../../src/qraftAPIClient.ts"],"sourcesContent":["import type { QraftServiceOperationsToken } from '@openapi-qraft/tanstack-query-react-types';\nimport type { QueryClient } from '@tanstack/react-query';\nimport type * as callbacks from './callbacks/index.js';\nimport type * as operationInvokeModule from './callbacks/operationInvokeFn.js';\nimport type {\n OperationSchema,\n RequestFnInfo,\n RequestFnResponse,\n} from './lib/requestFn.js';\nimport { createRecursiveProxy } from './lib/createRecursiveProxy.js';\n\nexport interface CreateAPIBasicClientOptions {\n requestFn: (\n schema: OperationSchema,\n requestInfo: RequestFnInfo\n ) => Promise<RequestFnResponse<any, any>>;\n baseUrl: string;\n}\n\nexport interface CreateAPIBasicQueryClientOptions {\n queryClient: QueryClient;\n}\n\nexport interface CreateAPIQueryClientOptions\n extends CreateAPIBasicClientOptions,\n CreateAPIBasicQueryClientOptions {}\n\n/**\n * @deprecated use `CreateAPIClientOptions` instead\n */\nexport type QraftClientOptions =\n | CreateAPIBasicClientOptions\n | CreateAPIQueryClientOptions;\n\nexport type CreateAPIClientOptions =\n | CreateAPIBasicClientOptions\n | CreateAPIBasicQueryClientOptions\n | CreateAPIQueryClientOptions;\n\n/**\n * Creates a QueryClient compatible API Client which contains all operations\n * such as `useQuery`, `useMutation`.\n *\n * @example Fetching data with QueryClient\n * ```ts\n * const api = qraftAPIClient(services, callbacks, {\n * requestFn: requestFn,\n * baseUrl: 'https://api.example.com',\n * queryClient: new QueryClient(),\n * });\n *\n * api.service.operation({\n * parameters: { path: { id: 1 } },\n * });\n * ```\n */\nexport function qraftAPIClient<\n Services extends UnionServiceOperationsDeclaration<Services>,\n Callbacks extends ServiceMethods,\n>(\n services: Services,\n callbacks: Callbacks,\n options: CreateAPIQueryClientOptions\n): APIDefaultQueryClientServices<Services>;\n\n/**\n * Creates a QueryClient compatible API Client which contains all operations\n * such as `useQuery`, `useMutation`.\n *\n * @example Fetching data with QueryClient\n * ```ts\n * const api = qraftAPIClient(services, callbacks, {\n * requestFn: requestFn,\n * baseUrl: 'https://api.example.com',\n * queryClient: new QueryClient(),\n * });\n *\n * api.service.operation({\n * parameters: { path: { id: 1 } },\n * });\n * ```\n */\nexport function qraftAPIClient<\n Services extends UnionServiceOperationsDeclaration<Services>,\n Callbacks extends PartialServiceMethods,\n>(\n services: Services,\n callbacks: Callbacks,\n options: CreateAPIQueryClientOptions\n): APIQueryClientServices<Services, Callbacks>;\n\n/**\n * Creates a QueryClient compatible API Client which contains\n * only state management manipulations such as `useIsMutating`,\n * `setQueryData`, `getQueryData` and `invalidateQueries`.\n *\n * @example Invalidating queries with QueryClient\n * ```ts\n * const api = qraftAPIClient(services, callbacks, {\n * // an instance of QueryClient shared between all clients\n * queryClient: sharedQueryClient\n * });\n *\n * api.service.operation.invalidateQueries({\n * parameters: { path: { id: 1 } },\n * });\n */\nexport function qraftAPIClient<\n Services extends UnionServiceOperationsDeclaration<Services>,\n Callbacks extends PartialServiceMethods,\n>(\n services: Services,\n callbacks: Callbacks,\n options: CreateAPIBasicQueryClientOptions\n): APIBasicQueryClientServices<Services, Callbacks>;\n\n/**\n * Creates a basic API Client which contains only \"fetch\" like\n * operations without any state management using QueryClient.\n *\n * @example Fetching data without QueryClient\n * ```ts\n * const api = qraftAPIClient(services, callbacks, {\n * requestFn: requestFn,\n * baseUrl: 'https://api.example.com',\n * });\n *\n * api.service.operation({\n * parameters: { path: { id: 1 } },\n * });\n * ```\n */\nexport function qraftAPIClient<\n Services extends UnionServiceOperationsDeclaration<Services>,\n Callbacks extends PartialServiceMethods,\n>(\n services: Services,\n callbacks: Callbacks,\n options: CreateAPIBasicClientOptions\n): APIBasicClientServices<Services, Callbacks>;\n\n/**\n * Creates a utility API Client which contains only utility operations\n * such as `getQueryKey`, `getInfiniteQueryKey` and `getMutationKey`.\n *\n * @example Getting query keys with utility client\n * ```ts\n * const api = qraftAPIClient(services, callbacks);\n *\n * api.service.operation.getQueryKey({\n * parameters: { path: { id: 1 } },\n * });\n * ```\n */\nexport function qraftAPIClient<\n Services extends UnionServiceOperationsDeclaration<Services>,\n Callbacks extends Pick<PartialServiceMethods, UtilityOperationCallbacks>,\n>(\n services: Services,\n callbacks: Callbacks\n): APIUtilityClientServices<Services, Callbacks>;\n\nexport function qraftAPIClient<\n Services extends UnionServiceOperationsDeclaration<Services>,\n Callbacks extends PartialServiceMethods,\n>(\n services: Services,\n callbacks: Callbacks,\n options?: CreateAPIClientOptions\n):\n | APIQueryClientServices<Services, Callbacks>\n | APIDefaultQueryClientServices<Services>\n | APIBasicQueryClientServices<Services, Callbacks>\n | APIUtilityClientServices<Services, Callbacks> {\n const stringTag = 'QraftAPIClient';\n\n const toString = (path: (symbol | string)[]): string => {\n return `[${stringTag}${path.length ? ' ' + path.join('.') : ''}]`;\n };\n\n const primitiveMethods = {\n [Symbol.toPrimitive](\n this: undefined,\n path: (string | symbol)[],\n hint: 'string' | 'number' | 'default'\n ): unknown {\n if (hint === 'number') return NaN;\n if (hint === 'string') return toString(path);\n return getByPath(services, path);\n },\n valueOf(this: undefined, path: (string | symbol)[]): unknown {\n return getByPath(services, path);\n },\n toJSON(this: undefined, path: (string | symbol)[]): string {\n return JSON.stringify(getByPath(services, path));\n },\n toString(this: undefined, path: (string | symbol)[]): string {\n return toString(path);\n },\n };\n\n return createRecursiveProxy(\n function getCallback(getPath, key) {\n if (Object.prototype.hasOwnProperty.call(primitiveMethods, key)) {\n return primitiveMethods[key as keyof typeof primitiveMethods].bind(\n undefined,\n getPath\n );\n } else if (key === Symbol.toStringTag) {\n return stringTag;\n }\n\n if (key !== 'schema') return;\n if (\n getPath.length !== 2 &&\n !('schema' in services) &&\n getPath.length !== 1 &&\n !(services[getPath[0] as never] as OperationsDeclaration<any>)?.schema\n )\n return;\n\n const serviceOperation = getByPath(services, getPath);\n if (!isServiceOperation(serviceOperation))\n throw new Error(`Service operation not found: ${getPath.join('.')}`);\n return serviceOperation.schema;\n },\n function applyCallback(applyPath, args) {\n const { path, callbackName } = extractCallbackDetails(\n applyPath,\n services\n );\n\n assertValidCallbackName(callbackName, callbacks);\n\n const serviceOperation = getByPath(services, path);\n\n if (!isServiceOperation(serviceOperation))\n throw new Error(`Service operation not found: ${path.join('.')}`);\n\n if (\n callbackName !== 'operationInvokeFn' &&\n callbackName !== 'getQueryKey' &&\n callbackName !== 'getMutationKey' &&\n callbackName !== 'getInfiniteQueryKey'\n )\n if (!options || !('queryClient' in options && options.queryClient))\n throw new Error(\n `'qraft.<service>.<operation>.${String(callbackName)}()' requires 'queryClient' in 'createAPIClient(...)' options.`\n );\n\n // @ts-expect-error - Too complex union type\n return callbacks[callbackName](options, serviceOperation.schema, args);\n },\n []\n ) as never;\n}\n\nfunction assertValidCallbackName<\n Callbacks extends Record<string, (...rest: any[]) => unknown>,\n>(\n callbackName: string | number | symbol,\n callbacks: Callbacks\n): asserts callbackName is keyof Callbacks {\n if (!(callbackName in callbacks)) {\n if (\n (callbackName as InvokeOperationCallback) ===\n ('operationInvokeFn' satisfies InvokeOperationCallback)\n )\n throw new Error(\n `Callback 'operationInvokeFn' is required for executing 'qraft.<service>.<operation>()', but it is not provided in the 'callbacks' object.`\n );\n throw new Error(\n `Callback for 'qraft.<service>.<operation>.${String(callbackName)}()' is not provided in the 'callbacks' object.`\n );\n }\n}\n\n/**\n * Extracts Callback details from the applyPath\n */\nfunction extractCallbackDetails(\n applyPath: (string | symbol)[],\n services: UnionServiceOperationsDeclaration<any>\n) {\n // client.<service>.<operation>() [OperationInvokeFn]\n // <service>.<operation>() [OperationInvokeFn]\n // client() [OperationInvokeFn]\n // client()\n if (\n (applyPath.length === 2 &&\n !(services[applyPath[0] as never] as OperationsDeclaration<any>)\n ?.schema) ||\n (applyPath.length === 0 && 'schema' in services)\n ) {\n return {\n path: applyPath,\n callbackName: 'operationInvokeFn' satisfies InvokeOperationCallback,\n };\n } else {\n // client.<service>.<operation>.<method>()\n // <service>.<operation>.<method>()\n // client.<method>()\n return {\n path: applyPath.slice(0, -1),\n // The last arg is for instance `.useMutation` or `.useQuery()`\n callbackName: applyPath[applyPath.length - 1],\n };\n }\n}\n\nfunction isServiceOperation(\n input: unknown\n): input is { schema: OperationSchema } {\n return input !== null && typeof input === 'object' && 'schema' in input;\n}\n\nfunction getByPath(obj: Record<string, unknown>, path: (string | symbol)[]) {\n return path.reduce<unknown>((acc, key) => {\n if (acc && typeof acc === 'object' && key in acc)\n return acc[key as keyof typeof acc];\n }, obj);\n}\n\ntype ServiceMethods = typeof callbacks;\n\ntype PartialServiceMethods = Partial<ServiceMethods>;\n\ntype OperationDeclaration = {\n schema: OperationSchema;\n [QraftServiceOperationsToken]: Partial<\n Record<\n | QueryOperationCallbacks\n | QueryOperationStateCallbacks\n | MutationOperationCallbacks\n | MutationOperationStateCallbacks\n | UtilityOperationCallbacks,\n any\n >\n > & {\n types: any;\n schema: OperationSchema;\n (...args: any[]): any;\n };\n};\n\ntype OperationsDeclaration<Operations> = {\n [operation in keyof Operations]: OperationDeclaration;\n};\n\ntype ServicesDeclaration<Services> = {\n [service in keyof Services]: OperationsDeclaration<Services[service]>;\n};\n\nexport type UnionServiceOperationsDeclaration<Services> =\n | ServicesDeclaration<Services>\n | OperationsDeclaration<Services>\n | OperationDeclaration;\n\ntype QueryOperationCallbacks = Extract<\n keyof ServiceMethods,\n | 'fetchInfiniteQuery'\n | 'fetchQuery'\n | 'prefetchInfiniteQuery'\n | 'prefetchQuery'\n | 'refetchQueries'\n | 'ensureQueryData'\n | 'ensureInfiniteQueryData'\n | 'useInfiniteQuery'\n | 'useQueries'\n | 'useQuery'\n | 'useSuspenseInfiniteQuery'\n | 'useSuspenseQueries'\n | 'useSuspenseQuery'\n>;\n\ntype QueryOperationStateCallbacks = Extract<\n keyof ServiceMethods,\n | 'cancelQueries'\n | 'getInfiniteQueryData'\n | 'getInfiniteQueryState'\n | 'getQueriesData'\n | 'getQueryData'\n | 'getQueryState'\n | 'invalidateQueries'\n | 'isFetching'\n | 'removeQueries'\n | 'resetQueries'\n | 'setInfiniteQueryData'\n | 'setQueriesData'\n | 'setQueryData'\n | 'useIsFetching'\n>;\n\ntype MutationOperationCallbacks = Extract<keyof ServiceMethods, 'useMutation'>;\n\ntype MutationOperationStateCallbacks = Extract<\n keyof ServiceMethods,\n 'isMutating' | 'useIsMutating' | 'useMutationState'\n>;\n\ntype InvokeOperationCallback = Extract<\n keyof typeof operationInvokeModule,\n 'operationInvokeFn'\n>;\n\ntype UtilityOperationCallbacks = Extract<\n keyof ServiceMethods,\n 'getQueryKey' | 'getInfiniteQueryKey' | 'getMutationKey'\n>;\n\ntype OperationCallbackList =\n | QueryOperationCallbacks\n | QueryOperationStateCallbacks\n | MutationOperationCallbacks\n | MutationOperationStateCallbacks\n | InvokeOperationCallback\n | UtilityOperationCallbacks;\n\nexport type APIQueryClientServices<\n Services extends UnionServiceOperationsDeclaration<Services>,\n Callbacks extends PartialServiceMethods,\n> = ServicesFilteredByCallbacks<\n Services,\n Extract<keyof Callbacks, OperationCallbackList>\n>;\n\nexport type APIDefaultQueryClientServices<\n Services extends UnionServiceOperationsDeclaration<Services>,\n> = Services extends OperationDeclaration\n ? Services[QraftServiceOperationsToken]\n : Services extends OperationsDeclaration<Services>\n ? {\n [operation in keyof Services]: Services[operation][QraftServiceOperationsToken];\n }\n : Services extends ServicesDeclaration<Services>\n ? {\n [service in keyof Services]: {\n [operation in keyof Services[service]]: Services[service][operation][QraftServiceOperationsToken];\n };\n }\n : never;\n\nexport type APIBasicQueryClientServices<\n Services extends UnionServiceOperationsDeclaration<Services>,\n Callbacks extends PartialServiceMethods,\n> = ServicesFilteredByCallbacks<\n Services,\n Extract<\n keyof Callbacks,\n | QueryOperationStateCallbacks\n | MutationOperationStateCallbacks\n | UtilityOperationCallbacks\n >\n>;\n\nexport type APIBasicClientServices<\n Services extends UnionServiceOperationsDeclaration<Services>,\n Callbacks extends PartialServiceMethods,\n> = ServicesFilteredByCallbacks<\n Services,\n Extract<keyof Callbacks, InvokeOperationCallback | UtilityOperationCallbacks>\n>;\n\nexport type APIUtilityClientServices<\n Services extends UnionServiceOperationsDeclaration<Services>,\n Callbacks extends Pick<PartialServiceMethods, UtilityOperationCallbacks>,\n> = ServicesFilteredByUtilityCallbacks<\n Services,\n Extract<keyof Callbacks, UtilityOperationCallbacks>\n>;\n\ntype ServicesFilteredByCallbacks<\n Services extends UnionServiceOperationsDeclaration<Services>,\n CallbackList extends OperationCallbackList,\n> = Services extends OperationDeclaration\n ? Pick<\n Services[QraftServiceOperationsToken],\n Extract<\n keyof Services[QraftServiceOperationsToken],\n CallbackList | 'schema' | 'types'\n >\n > &\n OperationInvokeFn<Services[QraftServiceOperationsToken], CallbackList>\n : Services extends OperationsDeclaration<Services>\n ? {\n [operation in keyof Services]: Pick<\n Services[operation][QraftServiceOperationsToken],\n Extract<\n keyof Services[operation][QraftServiceOperationsToken],\n CallbackList | 'schema' | 'types'\n >\n > &\n OperationInvokeFn<\n Services[operation][QraftServiceOperationsToken],\n CallbackList\n >;\n }\n : Services extends ServicesDeclaration<Services>\n ? {\n [serviceName in keyof Services]: {\n [operation in keyof Services[serviceName]]: Pick<\n Services[serviceName][operation][QraftServiceOperationsToken],\n Extract<\n keyof Services[serviceName][operation][QraftServiceOperationsToken],\n CallbackList | 'schema' | 'types'\n >\n > &\n OperationInvokeFn<\n Services[serviceName][operation][QraftServiceOperationsToken],\n CallbackList\n >;\n };\n }\n : never;\n\ntype OperationInvokeFn<\n InvokeFn extends (...args: any[]) => any,\n CallbackList extends OperationCallbackList,\n> = InvokeOperationCallback extends CallbackList\n ? InvokeFn extends (...args: infer Args) => infer Result\n ? { (...args: Args): Result }\n : Record<string, never>\n : Record<string, never>;\n\ntype ServicesFilteredByUtilityCallbacks<\n Services extends UnionServiceOperationsDeclaration<Services>,\n CallbackList extends UtilityOperationCallbacks,\n> = Services extends OperationDeclaration\n ? Pick<\n Services[QraftServiceOperationsToken],\n Extract<\n keyof Services[QraftServiceOperationsToken],\n CallbackList | 'schema' | 'types'\n >\n >\n : Services extends OperationsDeclaration<Services>\n ? {\n [operation in keyof Services]: Pick<\n Services[operation][QraftServiceOperationsToken],\n Extract<\n keyof Services[operation][QraftServiceOperationsToken],\n CallbackList | 'schema' | 'types'\n >\n >;\n }\n : Services extends ServicesDeclaration<Services>\n ? {\n [serviceName in keyof Services]: {\n [operation in keyof Services[serviceName]]: Pick<\n Services[serviceName][operation][QraftServiceOperationsToken],\n Extract<\n keyof Services[serviceName][operation][QraftServiceOperationsToken],\n CallbackList | 'schema' | 'types'\n >\n >;\n };\n }\n : never;\n"],"names":["qraftAPIClient","services","callbacks","options","stringTag","toString","path","length","join","primitiveMethods","Symbol","toPrimitive","hint","NaN","getByPath","valueOf","toJSON","JSON","stringify","createRecursiveProxy","getCallback","getPath","key","Object","prototype","hasOwnProperty","call","bind","undefined","toStringTag","schema","serviceOperation","isServiceOperation","Error","applyCallback","applyPath","args","callbackName","extractCallbackDetails","assertValidCallbackName","queryClient","String","slice","input","obj","reduce","acc"],"mappings":";;;;AAkKO,SAASA,cAIdC,CAAAA,QAAkB,EAClBC,SAAoB,EACpBC,OAAgC,EAAA;AAMhC,IAAA,MAAMC,SAAY,GAAA,gBAAA,CAAA;AAElB,IAAA,MAAMC,WAAW,CAACC,IAAAA,GAAAA;AAChB,QAAA,OAAO,CAAC,CAAC,EAAEF,SAAAA,CAAU,EAAEE,IAAKC,CAAAA,MAAM,GAAG,GAAA,GAAMD,KAAKE,IAAI,CAAC,GAAO,CAAA,GAAA,EAAA,CAAG,CAAC,CAAC,CAAA;AACnE,KAAA,CAAA;AAEA,IAAA,MAAMC,gBAAmB,GAAA;AACvB,QAAA,CAACC,OAAOC,WAAW,EAEjBL,CAAAA,IAAyB,EACzBM,IAAqC,EAAA;YAErC,IAAIA,IAAAA,KAAS,UAAU,OAAOC,GAAAA,CAAAA;YAC9B,IAAID,IAAAA,KAAS,QAAU,EAAA,OAAOP,QAASC,CAAAA,IAAAA,CAAAA,CAAAA;AACvC,YAAA,OAAOQ,UAAUb,QAAUK,EAAAA,IAAAA,CAAAA,CAAAA;AAC7B,SAAA;AACAS,QAAAA,OAAAA,CAAAA,CAAyBT,IAAyB,EAAA;AAChD,YAAA,OAAOQ,UAAUb,QAAUK,EAAA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raftServiceOperationsToken } from '@openapi-qraft/tanstack-query-react-types';\nimport type { QueryClient } from '@tanstack/react-query';\nimport type * as callbacks from './callbacks/index.js';\nimport type * as operationInvokeModule from './callbacks/operationInvokeFn.js';\nimport type {\n OperationSchema,\n RequestFnInfo,\n RequestFnResponse,\n} from './lib/requestFn.js';\nimport { createRecursiveProxy } from './lib/createRecursiveProxy.js';\n\nexport interface CreateAPIBasicClientOptions {\n requestFn: (\n schema: OperationSchema,\n requestInfo: RequestFnInfo\n ) => Promise<RequestFnResponse<any, any>>;\n baseUrl: string;\n}\n\nexport interface CreateAPIBasicQueryClientOptions {\n queryClient: QueryClient;\n}\n\nexport interface CreateAPIQueryClientOptions\n extends CreateAPIBasicClientOptions,\n CreateAPIBasicQueryClientOptions {}\n\n/**\n * @deprecated use `CreateAPIClientOptions` instead\n */\nexport type QraftClientOptions =\n | CreateAPIBasicClientOptions\n | CreateAPIQueryClientOptions;\n\nexport type CreateAPIClientOptions =\n | CreateAPIBasicClientOptions\n | CreateAPIBasicQueryClientOptions\n | CreateAPIQueryClientOptions;\n\n/**\n * Creates a QueryClient compatible API Client which contains all operations\n * such as `useQuery`, `useMutation`.\n *\n * @example Fetching data with QueryClient\n * ```ts\n * const api = qraftAPIClient(services, callbacks, {\n * requestFn: requestFn,\n * baseUrl: 'https://api.example.com',\n * queryClient: new QueryClient(),\n * });\n *\n * api.service.operation({\n * parameters: { path: { id: 1 } },\n * });\n * ```\n */\nexport function qraftAPIClient<\n Services extends UnionServiceOperationsDeclaration<Services>,\n Callbacks extends ServiceMethods,\n>(\n services: Services,\n callbacks: Callbacks,\n options: CreateAPIQueryClientOptions\n): APIDefaultQueryClientServices<Services>;\n\n/**\n * Creates a QueryClient compatible API Client which contains all operations\n * such as `useQuery`, `useMutation`.\n *\n * @example Fetching data with QueryClient\n * ```ts\n * const api = qraftAPIClient(services, callbacks, {\n * requestFn: requestFn,\n * baseUrl: 'https://api.example.com',\n * queryClient: new QueryClient(),\n * });\n *\n * api.service.operation({\n * parameters: { path: { id: 1 } },\n * });\n * ```\n */\nexport function qraftAPIClient<\n Services extends UnionServiceOperationsDeclaration<Services>,\n Callbacks extends PartialServiceMethods,\n>(\n services: Services,\n callbacks: Callbacks,\n options: CreateAPIQueryClientOptions\n): APIQueryClientServices<Services, Callbacks>;\n\n/**\n * Creates a QueryClient compatible API Client which contains\n * only state management manipulations such as `useIsMutating`,\n * `setQueryData`, `getQueryData` and `invalidateQueries`.\n *\n * @example Invalidating queries with QueryClient\n * ```ts\n * const api = qraftAPIClient(services, callbacks, {\n * // an instance of QueryClient shared between all clients\n * queryClient: sharedQueryClient\n * });\n *\n * api.service.operation.invalidateQueries({\n * parameters: { path: { id: 1 } },\n * });\n */\nexport function qraftAPIClient<\n Services extends UnionServiceOperationsDeclaration<Services>,\n Callbacks extends PartialServiceMethods,\n>(\n services: Services,\n callbacks: Callbacks,\n options: CreateAPIBasicQueryClientOptions\n): APIBasicQueryClientServices<Services, Callbacks>;\n\n/**\n * Creates a basic API Client which contains all hooks and methods\n * that don't require an explicitly provided QueryClient.\n * Hooks like `useQuery` and `useMutation` will automatically retrieve\n * the QueryClient from the `<QueryClientProvider />` context.\n *\n * @example Fetching data with QueryClient from context\n * ```ts\n * const api = qraftAPIClient(services, callbacks, {\n * requestFn: requestFn,\n * baseUrl: 'https://api.example.com',\n * });\n *\n * // QueryClient will be retrieved from React context\n * api.service.operation.useQuery({\n * parameters: { path: { id: 1 } },\n * });\n * ```\n *\n * @example Fetching data without QueryClient\n * ```ts\n * const api = qraftAPIClient(services, callbacks, {\n * requestFn: requestFn,\n * baseUrl: 'https://api.example.com',\n * });\n *\n * api.service.operation({\n * parameters: { path: { id: 1 } },\n * });\n * ```\n */\nexport function qraftAPIClient<\n Services extends UnionServiceOperationsDeclaration<Services>,\n Callbacks extends PartialServiceMethods,\n>(\n services: Services,\n callbacks: Callbacks,\n options: CreateAPIBasicClientOptions\n): APIBasicClientServices<Services, Callbacks>;\n\n/**\n * Creates a utility API Client which contains utility operations\n * such as `getQueryKey`, `getInfiniteQueryKey`, `getMutationKey` and state hooks\n * like `useIsFetching` and `useMutationData`.\n *\n * @example Using state hooks\n * ```ts\n * const api = qraftAPIClient(services, callbacks);\n *\n * // Check if any query is currently fetching\n * const isFetching = api.service.operation.useIsFetching();\n * ```\n *\n * @example Getting query keys with utility client\n * ```ts\n * const api = qraftAPIClient(services, callbacks);\n *\n * api.service.operation.getQueryKey({\n * parameters: { path: { id: 1 } },\n * });\n * ```\n */\nexport function qraftAPIClient<\n Services extends UnionServiceOperationsDeclaration<Services>,\n Callbacks extends Pick<PartialServiceMethods, UtilityOperationCallbacks>,\n>(\n services: Services,\n callbacks: Callbacks\n): APIUtilityClientServices<Services, Callbacks>;\n\nexport function qraftAPIClient<\n Services extends UnionServiceOperationsDeclaration<Services>,\n Callbacks extends PartialServiceMethods,\n>(\n services: Services,\n callbacks: Callbacks,\n options?: CreateAPIClientOptions\n):\n | APIQueryClientServices<Services, Callbacks>\n | APIDefaultQueryClientServices<Services>\n | APIBasicQueryClientServices<Services, Callbacks>\n | APIUtilityClientServices<Services, Callbacks> {\n const stringTag = 'QraftAPIClient';\n\n const toString = (path: (symbol | string)[]): string => {\n return `[${stringTag}${path.length ? ' ' + path.join('.') : ''}]`;\n };\n\n const primitiveMethods = {\n [Symbol.toPrimitive](\n this: undefined,\n path: (string | symbol)[],\n hint: 'string' | 'number' | 'default'\n ): unknown {\n if (hint === 'number') return NaN;\n if (hint === 'string') return toString(path);\n return getByPath(services, path);\n },\n valueOf(this: undefined, path: (string | symbol)[]): unknown {\n return getByPath(services, path);\n },\n toJSON(this: undefined, path: (string | symbol)[]): string {\n return JSON.stringify(getByPath(services, path));\n },\n toString(this: undefined, path: (string | symbol)[]): string {\n return toString(path);\n },\n };\n\n return createRecursiveProxy(\n function getCallback(getPath, key) {\n if (Object.prototype.hasOwnProperty.call(primitiveMethods, key)) {\n return primitiveMethods[key as keyof typeof primitiveMethods].bind(\n undefined,\n getPath\n );\n } else if (key === Symbol.toStringTag) {\n return stringTag;\n }\n\n if (key !== 'schema') return;\n if (\n getPath.length !== 2 &&\n !('schema' in services) &&\n getPath.length !== 1 &&\n !(services[getPath[0] as never] as OperationsDeclaration<any>)?.schema\n )\n return;\n\n const serviceOperation = getByPath(services, getPath);\n if (!isServiceOperation(serviceOperation))\n throw new Error(`Service operation not found: ${getPath.join('.')}`);\n return serviceOperation.schema;\n },\n function applyCallback(applyPath, args) {\n const { path, callbackName } = extractCallbackDetails(\n applyPath,\n services\n );\n\n assertValidCallbackName(callbackName, callbacks);\n\n const serviceOperation = getByPath(services, path);\n\n if (!isServiceOperation(serviceOperation))\n throw new Error(`Service operation not found: ${path.join('.')}`);\n\n if (\n callbackName !== 'operationInvokeFn' &&\n callbackName !== 'getQueryKey' &&\n callbackName !== 'getMutationKey' &&\n callbackName !== 'getInfiniteQueryKey' &&\n callbackName !== 'useInfiniteQuery' &&\n callbackName !== 'useQueries' &&\n callbackName !== 'useQuery' &&\n callbackName !== 'useSuspenseInfiniteQuery' &&\n callbackName !== 'useSuspenseQueries' &&\n callbackName !== 'useSuspenseQuery' &&\n callbackName !== 'useIsFetching' &&\n callbackName !== 'useMutation' &&\n callbackName !== 'useIsMutating' &&\n callbackName !== 'useMutationState'\n )\n if (!options || !('queryClient' in options && options.queryClient))\n throw new Error(\n `'qraft.<service>.<operation>.${String(callbackName)}()' requires 'queryClient' in 'createAPIClient(...)' options.`\n );\n\n // @ts-expect-error - Too complex union type\n return callbacks[callbackName](options, serviceOperation.schema, args);\n },\n []\n ) as never;\n}\n\nfunction assertValidCallbackName<\n Callbacks extends Record<string, (...rest: any[]) => unknown>,\n>(\n callbackName: string | number | symbol,\n callbacks: Callbacks\n): asserts callbackName is keyof Callbacks {\n if (!(callbackName in callbacks)) {\n if (\n (callbackName as InvokeOperationCallback) ===\n ('operationInvokeFn' satisfies InvokeOperationCallback)\n )\n throw new Error(\n `Callback 'operationInvokeFn' is required for executing 'qraft.<service>.<operation>()', but it is not provided in the 'callbacks' object.`\n );\n throw new Error(\n `Callback for 'qraft.<service>.<operation>.${String(callbackName)}()' is not provided in the 'callbacks' object.`\n );\n }\n}\n\n/**\n * Extracts Callback details from the applyPath\n */\nfunction extractCallbackDetails(\n applyPath: (string | symbol)[],\n services: UnionServiceOperationsDeclaration<any>\n) {\n // client.<service>.<operation>() [OperationInvokeFn]\n // <service>.<operation>() [OperationInvokeFn]\n // client() [OperationInvokeFn]\n // client()\n if (\n (applyPath.length === 2 &&\n !(services[applyPath[0] as never] as OperationsDeclaration<any>)\n ?.schema) ||\n (applyPath.length === 0 && 'schema' in services)\n ) {\n return {\n path: applyPath,\n callbackName: 'operationInvokeFn' satisfies InvokeOperationCallback,\n };\n } else {\n // client.<service>.<operation>.<method>()\n // <service>.<operation>.<method>()\n // client.<method>()\n return {\n path: applyPath.slice(0, -1),\n // The last arg is for instance `.useMutation` or `.useQuery()`\n callbackName: applyPath[applyPath.length - 1],\n };\n }\n}\n\nfunction isServiceOperation(\n input: unknown\n): input is { schema: OperationSchema } {\n return input !== null && typeof input === 'object' && 'schema' in input;\n}\n\nfunction getByPath(obj: Record<string, unknown>, path: (string | symbol)[]) {\n return path.reduce<unknown>((acc, key) => {\n if (acc && typeof acc === 'object' && key in acc)\n return acc[key as keyof typeof acc];\n }, obj);\n}\n\ntype ServiceMethods = typeof callbacks;\n\ntype PartialServiceMethods = Partial<ServiceMethods>;\n\ntype OperationDeclaration = {\n schema: OperationSchema;\n [QraftServiceOperationsToken]: Partial<\n Record<\n | QueryOperationCallbacks\n | QueryOperationStateCallbacks\n | MutationOperationHookCallbacks\n | MutationOperationStateCallbacks\n | UtilityOperationCallbacks,\n any\n >\n > & {\n types: any;\n schema: OperationSchema;\n (...args: any[]): any;\n };\n};\n\ntype OperationsDeclaration<Operations> = {\n [operation in keyof Operations]: OperationDeclaration;\n};\n\ntype ServicesDeclaration<Services> = {\n [service in keyof Services]: OperationsDeclaration<Services[service]>;\n};\n\nexport type UnionServiceOperationsDeclaration<Services> =\n | ServicesDeclaration<Services>\n | OperationsDeclaration<Services>\n | OperationDeclaration;\n\ntype QueryOperationHookCallbacks = Extract<\n keyof ServiceMethods,\n | 'useInfiniteQuery'\n | 'useQueries'\n | 'useQuery'\n | 'useSuspenseInfiniteQuery'\n | 'useSuspenseQueries'\n | 'useSuspenseQuery'\n>;\n\ntype QueryOperationCallbacks =\n | Extract<\n keyof ServiceMethods,\n | 'fetchInfiniteQuery'\n | 'fetchQuery'\n | 'prefetchInfiniteQuery'\n | 'prefetchQuery'\n | 'refetchQueries'\n | 'ensureQueryData'\n | 'ensureInfiniteQueryData'\n >\n | QueryOperationHookCallbacks;\n\ntype QueryOperationStateHookCallbacks = Extract<\n keyof ServiceMethods,\n 'useIsFetching'\n>;\n\ntype QueryOperationStateCallbacks =\n | Extract<\n keyof ServiceMethods,\n | 'cancelQueries'\n | 'getInfiniteQueryData'\n | 'getInfiniteQueryState'\n | 'getQueriesData'\n | 'getQueryData'\n | 'getQueryState'\n | 'invalidateQueries'\n | 'isFetching'\n | 'removeQueries'\n | 'resetQueries'\n | 'setInfiniteQueryData'\n | 'setQueriesData'\n | 'setQueryData'\n >\n | QueryOperationStateHookCallbacks;\n\ntype MutationOperationHookCallbacks = Extract<\n keyof ServiceMethods,\n 'useMutation'\n>;\n\ntype MutationOperationStateHookCallbacks = Extract<\n keyof ServiceMethods,\n 'useIsMutating' | 'useMutationState'\n>;\n\ntype MutationOperationStateCallbacks =\n | Extract<keyof ServiceMethods, 'isMutating'>\n | MutationOperationStateHookCallbacks;\n\ntype InvokeOperationCallback = Extract<\n keyof typeof operationInvokeModule,\n 'operationInvokeFn'\n>;\n\ntype UtilityOperationCallbacks = Extract<\n keyof ServiceMethods,\n | 'getQueryKey'\n | 'getInfiniteQueryKey'\n | 'getMutationKey'\n | QueryOperationStateHookCallbacks\n | MutationOperationStateHookCallbacks\n>;\n\ntype OperationCallbackList =\n | QueryOperationCallbacks\n | QueryOperationStateCallbacks\n | MutationOperationHookCallbacks\n | MutationOperationStateCallbacks\n | InvokeOperationCallback\n | UtilityOperationCallbacks;\n\nexport type APIQueryClientServices<\n Services extends UnionServiceOperationsDeclaration<Services>,\n Callbacks extends PartialServiceMethods,\n> = ServicesFilteredByCallbacks<\n Services,\n Extract<keyof Callbacks, OperationCallbackList>\n>;\n\nexport type APIDefaultQueryClientServices<\n Services extends UnionServiceOperationsDeclaration<Services>,\n> = Services extends OperationDeclaration\n ? Services[QraftServiceOperationsToken]\n : Services extends OperationsDeclaration<Services>\n ? {\n [operation in keyof Services]: Services[operation][QraftServiceOperationsToken];\n }\n : Services extends ServicesDeclaration<Services>\n ? {\n [service in keyof Services]: {\n [operation in keyof Services[service]]: Services[service][operation][QraftServiceOperationsToken];\n };\n }\n : never;\n\nexport type APIBasicQueryClientServices<\n Services extends UnionServiceOperationsDeclaration<Services>,\n Callbacks extends PartialServiceMethods,\n> = ServicesFilteredByCallbacks<\n Services,\n Extract<\n keyof Callbacks,\n | QueryOperationStateCallbacks\n | MutationOperationStateCallbacks\n | UtilityOperationCallbacks\n >\n>;\n\nexport type APIBasicClientServices<\n Services extends UnionServiceOperationsDeclaration<Services>,\n Callbacks extends PartialServiceMethods,\n> = ServicesFilteredByCallbacks<\n Services,\n Extract<\n keyof Callbacks,\n | InvokeOperationCallback\n | UtilityOperationCallbacks\n | QueryOperationHookCallbacks\n | QueryOperationStateHookCallbacks\n | MutationOperationStateHookCallbacks\n | MutationOperationHookCallbacks\n >\n>;\n\nexport type APIUtilityClientServices<\n Services extends UnionServiceOperationsDeclaration<Services>,\n Callbacks extends Pick<PartialServiceMethods, UtilityOperationCallbacks>,\n> = ServicesFilteredByUtilityCallbacks<\n Services,\n Extract<keyof Callbacks, UtilityOperationCallbacks>\n>;\n\ntype ServicesFilteredByCallbacks<\n Services extends UnionServiceOperationsDeclaration<Services>,\n CallbackList extends OperationCallbackList,\n> = Services extends OperationDeclaration\n ? Pick<\n Services[QraftServiceOperationsToken],\n Extract<\n keyof Services[QraftServiceOperationsToken],\n CallbackList | 'schema' | 'types'\n >\n > &\n OperationInvokeFn<Services[QraftServiceOperationsToken], CallbackList>\n : Services extends OperationsDeclaration<Services>\n ? {\n [operation in keyof Services]: Pick<\n Services[operation][QraftServiceOperationsToken],\n Extract<\n keyof Services[operation][QraftServiceOperationsToken],\n CallbackList | 'schema' | 'types'\n >\n > &\n OperationInvokeFn<\n Services[operation][QraftServiceOperationsToken],\n CallbackList\n >;\n }\n : Services extends ServicesDeclaration<Services>\n ? {\n [serviceName in keyof Services]: {\n [operation in keyof Services[serviceName]]: Pick<\n Services[serviceName][operation][QraftServiceOperationsToken],\n Extract<\n keyof Services[serviceName][operation][QraftServiceOperationsToken],\n CallbackList | 'schema' | 'types'\n >\n > &\n OperationInvokeFn<\n Services[serviceName][operation][QraftServiceOperationsToken],\n CallbackList\n >;\n };\n }\n : never;\n\ntype OperationInvokeFn<\n InvokeFn extends (...args: any[]) => any,\n CallbackList extends OperationCallbackList,\n> = InvokeOperationCallback extends CallbackList\n ? InvokeFn extends (...args: infer Args) => infer Result\n ? { (...args: Args): Result }\n : Record<string, never>\n : Record<string, never>;\n\ntype ServicesFilteredByUtilityCallbacks<\n Services extends UnionServiceOperationsDeclaration<Services>,\n CallbackList extends UtilityOperationCallbacks,\n> = Services extends OperationDeclaration\n ? Pick<\n Services[QraftServiceOperationsToken],\n Extract<\n keyof Services[QraftServiceOperationsToken],\n CallbackList | 'schema' | 'types'\n >\n >\n : Services extends OperationsDeclaration<Services>\n ? {\n [operation in keyof Services]: Pick<\n Services[operation][QraftServiceOperationsToken],\n Extract<\n keyof Services[operation][QraftServiceOperationsToken],\n CallbackList | 'schema' | 'types'\n >\n >;\n }\n : Services extends ServicesDeclaration<Services>\n ? {\n [serviceName in keyof Services]: {\n [operation in keyof Services[serviceName]]: Pick<\n Services[serviceName][operation][QraftServiceOperationsToken],\n Extract<\n keyof Services[serviceName][operation][QraftServiceOperationsToken],\n CallbackList | 'schema' | 'types'\n >\n >;\n };\n }\n : never;\n"],"names":["qraftAPIClient","services","callbacks","options","stringTag","toString","path","length","join","primitiveMethods","Symbol","toPrimitive","hint","NaN","getByPath","valueOf","toJSON","JSON","stringify","createRecursiveProxy","getCallback","getPath","key","Object","prototype","hasOwnProperty","call","bind","undefined","toStringTag","schema","serviceOperation","isServiceOperation","Error","applyCallback","applyPath","args","callbackName","extractCallbackDetails","assertValidCallbackName","queryClient","String","slice","input","obj","reduce","acc"],"mappings":";;;;AA0LO,SAASA,cAIdC,CAAAA,QAAkB,EAClBC,SAAoB,EACpBC,OAAgC,EAAA;AAMhC,IAAA,MAAMC,SAAY,GAAA,gBAAA,CAAA;AAElB,IAAA,MAAMC,WAAW,CAACC,IAAAA,GAAAA;AAChB,QAAA,OAAO,CAAC,CAAC,EAAEF,SAAAA,CAAU,EAAEE,IAAKC,CAAAA,MAAM,GAAG,GAAA,GAAMD,KAAKE,IAAI,CAAC,GAAO,CAAA,GAAA,EAAA,CAAG,CAAC,CAAC,CAAA;AACnE,KAAA,CAAA;AAEA,IAAA,MAAMC,gBAAmB,GAAA;AACvB,QAAA,CAACC,OAAOC,WAAW,EAEjBL,CAAAA,IAAyB,EACzBM,IAAqC,EAAA;YAErC,IAAIA,IAAAA,KAAS,UAAU,OAAOC,GAAAA,CAAAA;YAC9B,IAAID,IAAAA,KAAS,QAAU,EAAA,OAAOP,QAASC,CAAAA,IAAAA,CAAAA,CAAAA;AACvC,YAAA,OAAOQ,UAAUb,QAAUK,EAAAA,IAAAA,CAAAA,CAAAA;AAC7B,SAAA;AACAS,QAAAA,OAAAA,CAAAA,CAAyBT,IAAyB,EAAA;AAChD,YAAA,OAAOQ,UAAUb,QAAUK,EAAAA,IAAAA,CAAAA,CAAAA;AAC7B,SAAA;AACAU,QAAAA,MAAAA,CAAAA,CAAwBV,IAAyB,EAAA;AAC/C,YAAA,OAAOW,IAAKC,CAAAA,SAAS,CAACJ,SAAAA,CAAUb,QAAUK,EAAAA,IAAAA,CAAAA,CAAAA,CAAAA;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A,GAAAA,CAAAA,CAAAA;AACL;;;;"}
|
|
@@ -4,7 +4,7 @@ import { composeQueryFilters } from '../lib/composeQueryFilters.js';
|
|
|
4
4
|
|
|
5
5
|
const useIsFetching = (qraftOptions, schema, args)=>{
|
|
6
6
|
const [filters] = args;
|
|
7
|
-
return useIsFetching$1(composeQueryFilters(schema, filters), qraftOptions
|
|
7
|
+
return useIsFetching$1(composeQueryFilters(schema, filters), qraftOptions?.queryClient);
|
|
8
8
|
};
|
|
9
9
|
|
|
10
10
|
export { useIsFetching };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useIsFetching.js","sources":["../../../src/callbacks/useIsFetching.ts"],"sourcesContent":["'use client';\n\nimport type {\n OperationSchema,\n ServiceOperationUseIsFetchingQueries,\n} from '@openapi-qraft/tanstack-query-react-types';\nimport type { CreateAPIQueryClientOptions } from '../qraftAPIClient.js';\nimport { useIsFetching as useIsFetchingTanstack } from '@tanstack/react-query';\nimport { composeQueryFilters } from '../lib/composeQueryFilters.js';\n\nexport const useIsFetching: <TVariables = unknown>(\n qraftOptions: CreateAPIQueryClientOptions,\n schema: OperationSchema,\n args: Parameters<\n ServiceOperationUseIsFetchingQueries<\n OperationSchema,\n object | undefined,\n TVariables,\n unknown\n >['useIsFetching']\n >\n) => number = (qraftOptions, schema, args) => {\n const [filters] = args;\n\n return useIsFetchingTanstack(\n composeQueryFilters(schema, filters as never) as never,\n qraftOptions
|
|
1
|
+
{"version":3,"file":"useIsFetching.js","sources":["../../../src/callbacks/useIsFetching.ts"],"sourcesContent":["'use client';\n\nimport type {\n OperationSchema,\n ServiceOperationUseIsFetchingQueries,\n} from '@openapi-qraft/tanstack-query-react-types';\nimport type { CreateAPIQueryClientOptions } from '../qraftAPIClient.js';\nimport { useIsFetching as useIsFetchingTanstack } from '@tanstack/react-query';\nimport { composeQueryFilters } from '../lib/composeQueryFilters.js';\n\nexport const useIsFetching: <TVariables = unknown>(\n qraftOptions: CreateAPIQueryClientOptions | undefined,\n schema: OperationSchema,\n args: Parameters<\n ServiceOperationUseIsFetchingQueries<\n OperationSchema,\n object | undefined,\n TVariables,\n unknown\n >['useIsFetching']\n >\n) => number = (qraftOptions, schema, args) => {\n const [filters] = args;\n\n return useIsFetchingTanstack(\n composeQueryFilters(schema, filters as never) as never,\n qraftOptions?.queryClient\n ) as never;\n};\n"],"names":["useIsFetching","qraftOptions","schema","args","filters","useIsFetchingTanstack","composeQueryFilters","queryClient"],"mappings":";;;;AAUaA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,GAWC,CAACC,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,EAAcC,CAAQC,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,IAAAA,CAAAA,CAAAA,CAAAA,CAAAA;IACnC,MAAM,CAACC,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,EAAQ,CAAA,CAAA,CAAGD,IAAAA,CAAAA;AAElB,CAAA,CAAA,CAAA,CAAA,CAAOE,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CACLC,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAoBJ,CAAQE,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAC5BH,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAcM,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA;AAElB,CAAA,CAAA;;"}
|
|
@@ -4,7 +4,7 @@ import { composeMutationFilters } from '../lib/composeMutationFilters.js';
|
|
|
4
4
|
|
|
5
5
|
const useIsMutating = (qraftOptions, schema, args)=>{
|
|
6
6
|
const [filters] = args;
|
|
7
|
-
return useIsMutating$1(composeMutationFilters(schema, filters), qraftOptions
|
|
7
|
+
return useIsMutating$1(composeMutationFilters(schema, filters), qraftOptions?.queryClient);
|
|
8
8
|
};
|
|
9
9
|
|
|
10
10
|
export { useIsMutating };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useIsMutating.js","sources":["../../../src/callbacks/useIsMutating.ts"],"sourcesContent":["'use client';\n\nimport type {\n OperationSchema,\n ServiceOperationUseIsMutating,\n} from '@openapi-qraft/tanstack-query-react-types';\nimport type { DefaultError, UseMutationResult } from '@tanstack/react-query';\nimport type { CreateAPIQueryClientOptions } from '../qraftAPIClient.js';\nimport { useIsMutating as useIsMutatingStateTanstack } from '@tanstack/react-query';\nimport { composeMutationFilters } from '../lib/composeMutationFilters.js';\n\nexport const useIsMutating: <\n TData = unknown,\n TError = DefaultError,\n TVariables = unknown,\n TContext = unknown,\n>(\n qraftOptions: CreateAPIQueryClientOptions,\n schema: OperationSchema,\n args: Parameters<\n ServiceOperationUseIsMutating<\n OperationSchema,\n object | undefined,\n TVariables,\n TData,\n DefaultError\n >['useIsMutating']\n >\n) => UseMutationResult<TData, TError, TVariables, TContext> = (\n qraftOptions,\n schema,\n args\n) => {\n const [filters] = args;\n\n return useIsMutatingStateTanstack(\n composeMutationFilters(schema, filters) as never,\n qraftOptions
|
|
1
|
+
{"version":3,"file":"useIsMutating.js","sources":["../../../src/callbacks/useIsMutating.ts"],"sourcesContent":["'use client';\n\nimport type {\n OperationSchema,\n ServiceOperationUseIsMutating,\n} from '@openapi-qraft/tanstack-query-react-types';\nimport type { DefaultError, UseMutationResult } from '@tanstack/react-query';\nimport type { CreateAPIQueryClientOptions } from '../qraftAPIClient.js';\nimport { useIsMutating as useIsMutatingStateTanstack } from '@tanstack/react-query';\nimport { composeMutationFilters } from '../lib/composeMutationFilters.js';\n\nexport const useIsMutating: <\n TData = unknown,\n TError = DefaultError,\n TVariables = unknown,\n TContext = unknown,\n>(\n qraftOptions: CreateAPIQueryClientOptions | undefined,\n schema: OperationSchema,\n args: Parameters<\n ServiceOperationUseIsMutating<\n OperationSchema,\n object | undefined,\n TVariables,\n TData,\n DefaultError\n >['useIsMutating']\n >\n) => UseMutationResult<TData, TError, TVariables, TContext> = (\n qraftOptions,\n schema,\n args\n) => {\n const [filters] = args;\n\n return useIsMutatingStateTanstack(\n composeMutationFilters(schema, filters) as never,\n qraftOptions?.queryClient\n ) as never;\n};\n"],"names":["useIsMutating","qraftOptions","schema","args","filters","useIsMutatingStateTanstack","composeMutationFilters","queryClient"],"mappings":";;;;AAWaA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,GAiBiD,CAC5DC,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,EACAC,CACAC,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,IAAAA,CAAAA,CAAAA,CAAAA,CAAAA;IAEA,MAAM,CAACC,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,EAAQ,CAAA,CAAA,CAAGD,IAAAA,CAAAA;AAElB,CAAA,CAAA,CAAA,CAAA,CAAOE,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CACLC,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAuBJ,CAAQE,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAC/BH,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAcM,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA;AAElB,CAAA,CAAA;;"}
|
|
@@ -7,7 +7,7 @@ const useMutationState = (qraftOptions, schema, args)=>{
|
|
|
7
7
|
return useMutationState$1({
|
|
8
8
|
...options,
|
|
9
9
|
filters: composeMutationFilters(schema, options?.filters)
|
|
10
|
-
}, qraftOptions
|
|
10
|
+
}, qraftOptions?.queryClient);
|
|
11
11
|
};
|
|
12
12
|
|
|
13
13
|
export { useMutationState };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useMutationState.js","sources":["../../../src/callbacks/useMutationState.ts"],"sourcesContent":["'use client';\n\nimport type {\n OperationSchema,\n ServiceOperationUseMutationState,\n} from '@openapi-qraft/tanstack-query-react-types';\nimport type { DefaultError, UseMutationResult } from '@tanstack/react-query';\nimport type { CreateAPIQueryClientOptions } from '../qraftAPIClient.js';\nimport { useMutationState as useMutationStateTanstack } from '@tanstack/react-query';\nimport { composeMutationFilters } from '../lib/composeMutationFilters.js';\n\nexport const useMutationState: <\n TData = unknown,\n TError = DefaultError,\n TVariables = unknown,\n TContext = unknown,\n>(\n qraftOptions: CreateAPIQueryClientOptions,\n schema: OperationSchema,\n args: Parameters<\n ServiceOperationUseMutationState<\n OperationSchema,\n object | undefined,\n TVariables,\n TData,\n DefaultError\n >['useMutationState']\n >\n) => UseMutationResult<TData, TError, TVariables, TContext> = (\n qraftOptions,\n schema,\n args\n) => {\n const [options] = args;\n\n return useMutationStateTanstack(\n {\n ...options,\n filters: composeMutationFilters(schema, options?.filters),\n } as never,\n qraftOptions
|
|
1
|
+
{"version":3,"file":"useMutationState.js","sources":["../../../src/callbacks/useMutationState.ts"],"sourcesContent":["'use client';\n\nimport type {\n OperationSchema,\n ServiceOperationUseMutationState,\n} from '@openapi-qraft/tanstack-query-react-types';\nimport type { DefaultError, UseMutationResult } from '@tanstack/react-query';\nimport type { CreateAPIQueryClientOptions } from '../qraftAPIClient.js';\nimport { useMutationState as useMutationStateTanstack } from '@tanstack/react-query';\nimport { composeMutationFilters } from '../lib/composeMutationFilters.js';\n\nexport const useMutationState: <\n TData = unknown,\n TError = DefaultError,\n TVariables = unknown,\n TContext = unknown,\n>(\n qraftOptions: CreateAPIQueryClientOptions | undefined,\n schema: OperationSchema,\n args: Parameters<\n ServiceOperationUseMutationState<\n OperationSchema,\n object | undefined,\n TVariables,\n TData,\n DefaultError\n >['useMutationState']\n >\n) => UseMutationResult<TData, TError, TVariables, TContext> = (\n qraftOptions,\n schema,\n args\n) => {\n const [options] = args;\n\n return useMutationStateTanstack(\n {\n ...options,\n filters: composeMutationFilters(schema, options?.filters),\n } as never,\n qraftOptions?.queryClient\n ) as never;\n};\n"],"names":["useMutationState","qraftOptions","schema","args","options","useMutationStateTanstack","filters","composeMutationFilters","queryClient"],"mappings":";;;;AAWaA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAA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olveResponse } from './responseUtils.js';
|
|
|
64
64
|
*/ function urlSerializer(schema, info) {
|
|
65
65
|
const path = schema.url.replace(/{(.*?)}/g, (substring, group)=>{
|
|
66
66
|
if (info.parameters?.path && Object.prototype.hasOwnProperty.call(info.parameters.path, group)) {
|
|
67
|
-
return
|
|
67
|
+
return encodeURIComponent(String(info.parameters?.path[group]));
|
|
68
68
|
}
|
|
69
69
|
return substring;
|
|
70
70
|
});
|
|
@@ -75,31 +75,18 @@ import { processResponse, resolveResponse } from './responseUtils.js';
|
|
|
75
75
|
return `${baseUrl}${path}`;
|
|
76
76
|
}
|
|
77
77
|
function getQueryString(params) {
|
|
78
|
-
const
|
|
79
|
-
const
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
if (typeof value === '
|
|
84
|
-
|
|
85
|
-
value.forEach((v)=>{
|
|
86
|
-
process(key, v);
|
|
87
|
-
});
|
|
88
|
-
} else if (typeof value === 'object') {
|
|
89
|
-
Object.entries(value).forEach(([k, v])=>{
|
|
90
|
-
process(`${key}[${k}]`, v);
|
|
91
|
-
});
|
|
92
|
-
} else {
|
|
93
|
-
append(key, value);
|
|
78
|
+
const search = new URLSearchParams();
|
|
79
|
+
const walk = (prefix, value)=>{
|
|
80
|
+
if (value == null) return;
|
|
81
|
+
if (value instanceof Date) return search.append(prefix, value.toISOString());
|
|
82
|
+
if (Array.isArray(value)) return value.forEach((v)=>walk(prefix, v));
|
|
83
|
+
if (typeof value === 'object') {
|
|
84
|
+
return Object.entries(value).forEach(([k, v])=>walk(`${prefix}[${k}]`, v));
|
|
94
85
|
}
|
|
86
|
+
search.append(prefix, String(value));
|
|
95
87
|
};
|
|
96
|
-
Object.entries(params).forEach(([
|
|
97
|
-
|
|
98
|
-
});
|
|
99
|
-
if (qs.length > 0) {
|
|
100
|
-
return `?${qs.join('&')}`;
|
|
101
|
-
}
|
|
102
|
-
return '';
|
|
88
|
+
Object.entries(params).forEach(([k, v])=>walk(k, v));
|
|
89
|
+
return search.toString() ? `?${search.toString()}` : '';
|
|
103
90
|
}
|
|
104
91
|
function mergeHeaders(...allHeaders) {
|
|
105
92
|
const headers = new Headers();
|