@7nohe/openapi-react-query-codegen 2.0.0-beta.3 → 2.0.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/dist/common.mjs +4 -2
- package/dist/createImports.mjs +1 -0
- package/dist/createUseQuery.mjs +17 -4
- package/package.json +1 -1
package/dist/common.mjs
CHANGED
|
@@ -160,9 +160,11 @@ export function createQueryKeyExport({ methodName, queryKey, }) {
|
|
|
160
160
|
ts.factory.createVariableDeclaration(ts.factory.createIdentifier(queryKey), undefined, undefined, ts.factory.createStringLiteral(`${capitalizeFirstLetter(methodName)}`)),
|
|
161
161
|
], ts.NodeFlags.Const));
|
|
162
162
|
}
|
|
163
|
-
export function createQueryKeyFnExport(queryKey, method, type = "query") {
|
|
163
|
+
export function createQueryKeyFnExport(queryKey, method, type = "query", modelNames = []) {
|
|
164
164
|
// Mutation keys don't require clientOptions
|
|
165
|
-
const params = type === "query"
|
|
165
|
+
const params = type === "query"
|
|
166
|
+
? getRequestParamFromMethod(method, undefined, modelNames)
|
|
167
|
+
: null;
|
|
166
168
|
// override key is used to allow the user to override the the queryKey values
|
|
167
169
|
const overrideKey = ts.factory.createParameterDeclaration(undefined, undefined, ts.factory.createIdentifier(type === "query" ? "queryKey" : "mutationKey"), QuestionToken, ts.factory.createTypeReferenceNode("Array<unknown>", []));
|
|
168
170
|
return ts.factory.createVariableStatement([ts.factory.createModifier(ts.SyntaxKind.ExportKeyword)], ts.factory.createVariableDeclarationList([
|
package/dist/createImports.mjs
CHANGED
|
@@ -32,6 +32,7 @@ export const createImports = ({ project, client, }) => {
|
|
|
32
32
|
ts.factory.createImportSpecifier(false, undefined, ts.factory.createIdentifier("UseQueryOptions")),
|
|
33
33
|
ts.factory.createImportSpecifier(false, undefined, ts.factory.createIdentifier("UseMutationOptions")),
|
|
34
34
|
ts.factory.createImportSpecifier(false, undefined, ts.factory.createIdentifier("UseMutationResult")),
|
|
35
|
+
ts.factory.createImportSpecifier(false, undefined, ts.factory.createIdentifier("UseSuspenseQueryOptions")),
|
|
35
36
|
])), ts.factory.createStringLiteral("@tanstack/react-query"), undefined),
|
|
36
37
|
ts.factory.createImportDeclaration(undefined, ts.factory.createImportClause(false, undefined, ts.factory.createNamedImports([
|
|
37
38
|
// import all class names from service file
|
package/dist/createUseQuery.mjs
CHANGED
|
@@ -13,6 +13,10 @@ const createApiResponseType = ({ methodName, client, }) => {
|
|
|
13
13
|
*/
|
|
14
14
|
const apiResponse = ts.factory.createTypeAliasDeclaration([ts.factory.createModifier(ts.SyntaxKind.ExportKeyword)], ts.factory.createIdentifier(`${capitalizeFirstLetter(methodName)}DefaultResponse`), undefined, awaitedResponseDataType);
|
|
15
15
|
const responseDataType = ts.factory.createTypeParameterDeclaration(undefined, TData.text, undefined, ts.factory.createTypeReferenceNode(BuildCommonTypeName(apiResponse.name)));
|
|
16
|
+
// Response data type for suspense - wrap with NonNullable to exclude undefined
|
|
17
|
+
const suspenseResponseDataType = ts.factory.createTypeParameterDeclaration(undefined, TData.text, undefined, ts.factory.createTypeReferenceNode(ts.factory.createIdentifier("NonNullable"), [
|
|
18
|
+
ts.factory.createTypeReferenceNode(BuildCommonTypeName(apiResponse.name)),
|
|
19
|
+
]));
|
|
16
20
|
const responseErrorType = ts.factory.createTypeParameterDeclaration(undefined, TError.text, undefined, client === "@hey-api/client-axios"
|
|
17
21
|
? ts.factory.createTypeReferenceNode(ts.factory.createIdentifier("AxiosError"), [
|
|
18
22
|
ts.factory.createTypeReferenceNode(ts.factory.createIdentifier(`${capitalizeFirstLetter(methodName)}Error`)),
|
|
@@ -31,6 +35,12 @@ const createApiResponseType = ({ methodName, client, }) => {
|
|
|
31
35
|
* MyClassMethodDefaultResponse
|
|
32
36
|
*/
|
|
33
37
|
responseDataType,
|
|
38
|
+
/**
|
|
39
|
+
* ResponseDataType for suspense - wrap with NonNullable to exclude undefined
|
|
40
|
+
*
|
|
41
|
+
* NonNullable<MyClassMethodDefaultResponse>
|
|
42
|
+
*/
|
|
43
|
+
suspenseResponseDataType,
|
|
34
44
|
/**
|
|
35
45
|
* ErrorDataType
|
|
36
46
|
*
|
|
@@ -76,6 +86,7 @@ function createQueryHook({ queryString, suffix, responseDataType, responseErrorT
|
|
|
76
86
|
throw new Error("pageParam and nextPageParam are required for infinite queries");
|
|
77
87
|
}
|
|
78
88
|
const isInfiniteQuery = queryString === "useInfiniteQuery";
|
|
89
|
+
const isSuspenseQuery = queryString === "useSuspenseQuery";
|
|
79
90
|
const responseDataTypeRef = responseDataType.default;
|
|
80
91
|
const responseDataTypeIdentifier = responseDataTypeRef.typeName;
|
|
81
92
|
const hookExport = ts.factory.createVariableStatement([ts.factory.createModifier(ts.SyntaxKind.ExportKeyword)], ts.factory.createVariableDeclarationList([
|
|
@@ -93,7 +104,9 @@ function createQueryHook({ queryString, suffix, responseDataType, responseErrorT
|
|
|
93
104
|
ts.factory.createParameterDeclaration(undefined, undefined, ts.factory.createIdentifier("options"), ts.factory.createToken(ts.SyntaxKind.QuestionToken), ts.factory.createTypeReferenceNode(ts.factory.createIdentifier("Omit"), [
|
|
94
105
|
ts.factory.createTypeReferenceNode(ts.factory.createIdentifier(isInfiniteQuery
|
|
95
106
|
? "UseInfiniteQueryOptions"
|
|
96
|
-
:
|
|
107
|
+
: isSuspenseQuery
|
|
108
|
+
? "UseSuspenseQueryOptions"
|
|
109
|
+
: "UseQueryOptions"), [
|
|
97
110
|
ts.factory.createTypeReferenceNode(TData),
|
|
98
111
|
ts.factory.createTypeReferenceNode(TError),
|
|
99
112
|
]),
|
|
@@ -153,7 +166,7 @@ function createQueryHook({ queryString, suffix, responseDataType, responseErrorT
|
|
|
153
166
|
export const createUseQuery = ({ functionDescription: { method, jsDoc }, client, pageParam, nextPageParam, initialPageParam, paginatableMethods, modelNames, }) => {
|
|
154
167
|
const methodName = getNameFromVariable(method);
|
|
155
168
|
const queryKey = createQueryKeyFromMethod({ method });
|
|
156
|
-
const { apiResponse: defaultApiResponse, responseDataType, responseErrorType, } = createApiResponseType({
|
|
169
|
+
const { apiResponse: defaultApiResponse, responseDataType, suspenseResponseDataType, responseErrorType, } = createApiResponseType({
|
|
157
170
|
methodName,
|
|
158
171
|
client,
|
|
159
172
|
});
|
|
@@ -171,7 +184,7 @@ export const createUseQuery = ({ functionDescription: { method, jsDoc }, client,
|
|
|
171
184
|
const suspenseQueryHook = createQueryHook({
|
|
172
185
|
queryString: "useSuspenseQuery",
|
|
173
186
|
suffix: "Suspense",
|
|
174
|
-
responseDataType,
|
|
187
|
+
responseDataType: suspenseResponseDataType,
|
|
175
188
|
responseErrorType,
|
|
176
189
|
requestParams,
|
|
177
190
|
method,
|
|
@@ -203,7 +216,7 @@ export const createUseQuery = ({ functionDescription: { method, jsDoc }, client,
|
|
|
203
216
|
methodName,
|
|
204
217
|
queryKey,
|
|
205
218
|
});
|
|
206
|
-
const queryKeyFn = createQueryKeyFnExport(queryKey, method);
|
|
219
|
+
const queryKeyFn = createQueryKeyFnExport(queryKey, method, "query", modelNames);
|
|
207
220
|
return {
|
|
208
221
|
apiResponse: defaultApiResponse,
|
|
209
222
|
returnType: returnTypeExport,
|