@povio/openapi-codegen-cli 3.2.0-rc.5 → 3.2.0-rc.7
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/README.md +42 -1
- package/dist/acl.mjs +1 -1
- package/dist/{config-mWuUhYNE.d.mts → config-DgrOddSC.d.mts} +1 -1
- package/dist/{error-handling-DDIXMA-R.mjs → error-handling-BMXC5P08.mjs} +22 -12
- package/dist/{generate.runner-BxdZdYX4.mjs → generate.runner-BvSprH6D.mjs} +15 -8
- package/dist/{generate.utils-1rU0zIjA.cjs → generate.utils-CH2U2Dpr.cjs} +36 -5
- package/dist/{generateCodeFromOpenAPIDoc-5VZFVFK1.cjs → generateCodeFromOpenAPIDoc-CZT3sThI.cjs} +55 -25
- package/dist/{generateCodeFromOpenAPIDoc-BOuCcW6U.mjs → generateCodeFromOpenAPIDoc-glAKBEGP.mjs} +56 -26
- package/dist/generator.d.mts +1 -1
- package/dist/generator.mjs +3 -3
- package/dist/{getDataFromOpenAPIDoc-CkIfezoI.mjs → getDataFromOpenAPIDoc-7RxjULpB.mjs} +1 -1
- package/dist/index.d.mts +4 -2
- package/dist/index.mjs +4 -2
- package/dist/metro.cjs +3 -3
- package/dist/metro.d.mts +3 -3
- package/dist/metro.mjs +1 -1
- package/dist/native-rest-interceptor-Bcc2jx4e.mjs +189 -0
- package/dist/native-rest-interceptor-CTBBx6B3.d.mts +43 -0
- package/dist/native.d.mts +3 -0
- package/dist/native.mjs +3 -0
- package/dist/openapi-codegen-native-darwin-arm64.node +0 -0
- package/dist/openapi-codegen-native-linux-x64.node +0 -0
- package/dist/openapi-codegen-native-win32-x64.node +0 -0
- package/dist/{openapi-codegen.runner-fS_gOezd.mjs → openapi-codegen.runner-C93V7SGj.mjs} +1 -1
- package/dist/{openapi-source.runner-DmJoXvFj.d.mts → openapi-source.runner-ykstqlPC.d.mts} +1 -1
- package/dist/{options-B47gUU4P.d.mts → options-KPf-Fti5.d.mts} +1 -0
- package/dist/rest-transport.types-D0R9mvGH.d.mts +59 -0
- package/dist/rest-transport.types-DxitRtsB.mjs +11 -0
- package/dist/rest.d.mts +2 -0
- package/dist/rest.mjs +2 -0
- package/dist/sh.mjs +8 -3
- package/dist/tiny.d.mts +1 -1
- package/dist/vite.d.mts +3 -3
- package/dist/vite.mjs +1 -1
- package/dist/zod.mjs +1 -1
- package/package.json +9 -1
package/README.md
CHANGED
|
@@ -89,7 +89,8 @@ bunx openapi-codegen generate --config my-config.ts
|
|
|
89
89
|
--modelsInCommon Keep all schema declarations in defaultTag models and emit per-module proxy exports (default: false)
|
|
90
90
|
--replaceOptionalWithNullish Replace `.optional()` chains with `.nullish()` in generated Zod schemas (default: false)
|
|
91
91
|
|
|
92
|
-
--
|
|
92
|
+
--restClient REST transport to generate: 'axios' or 'native' (default: 'axios')
|
|
93
|
+
--axiosRequestConfig Include transport request config parameters in query hooks (default: false)
|
|
93
94
|
--infiniteQueries Generate infinite queries for paginated API endpoints (default: false)
|
|
94
95
|
--mutationEffects Add mutation effects options to mutation hooks (default: true)
|
|
95
96
|
--mutationScope Serialize mutations for the same path-param resource via TanStack scope.id (default: false).
|
|
@@ -162,6 +163,46 @@ Release packages include native binaries for Linux x64, macOS arm64, and Windows
|
|
|
162
163
|
|
|
163
164
|
### App REST Client Interceptors
|
|
164
165
|
|
|
166
|
+
Select the fetch-based client without changing endpoint and query APIs:
|
|
167
|
+
|
|
168
|
+
```ts
|
|
169
|
+
import type { OpenAPICodegenConfig } from "@povio/openapi-codegen-cli";
|
|
170
|
+
|
|
171
|
+
export default {
|
|
172
|
+
restClient: "native",
|
|
173
|
+
} satisfies OpenAPICodegenConfig;
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
Native mode imports common request/response contracts from `@povio/openapi-codegen-cli/rest` and the concrete
|
|
177
|
+
`NativeRestClient` from `@povio/openapi-codegen-cli/native`. It uses `fetch` for normal requests and uploads, switching
|
|
178
|
+
to `XMLHttpRequest` in browsers only when an upload progress callback is provided.
|
|
179
|
+
|
|
180
|
+
Native interceptors use the common transport interface:
|
|
181
|
+
|
|
182
|
+
```ts
|
|
183
|
+
import { NativeRestClient } from "@povio/openapi-codegen-cli/native";
|
|
184
|
+
import type { RestTransportInterceptor } from "@povio/openapi-codegen-cli/rest";
|
|
185
|
+
|
|
186
|
+
const authorizationInterceptor: RestTransportInterceptor = {
|
|
187
|
+
onRequest(request) {
|
|
188
|
+
request.headers.set("Authorization", `Bearer ${localStorage.getItem("accessToken")}`);
|
|
189
|
+
return request;
|
|
190
|
+
},
|
|
191
|
+
};
|
|
192
|
+
|
|
193
|
+
export const AppRestClient = new NativeRestClient({
|
|
194
|
+
config: { baseURL: "https://api.example.com" },
|
|
195
|
+
interceptors: [authorizationInterceptor],
|
|
196
|
+
});
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
Axios remains the default for backward compatibility. The existing Axios interceptor API remains available in Axios
|
|
200
|
+
mode.
|
|
201
|
+
|
|
202
|
+
Native mode does not run the library `ErrorHandler` or create `ApplicationException` values. It throws `HttpError` for
|
|
203
|
+
non-success HTTP responses and preserves Zod, network, cancellation, and timeout errors so applications can handle them
|
|
204
|
+
directly in query callbacks, error boundaries, or their own normalization layer.
|
|
205
|
+
|
|
165
206
|
In order to add interceptors to the used REST client, you must create your own instance of a RestClient and pass your implemented interceptors into the constructor. Make sure to set `restClientImportPath` in your openapi generation configuration too.
|
|
166
207
|
|
|
167
208
|
```ts
|
package/dist/acl.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { i as SharedErrorHandler } from "./error-handling-
|
|
1
|
+
import { i as SharedErrorHandler } from "./error-handling-BMXC5P08.mjs";
|
|
2
2
|
import { n as OpenApiRouter, t as AuthContext } from "./auth.context-YFWzkwoN.mjs";
|
|
3
3
|
import { createContext, useCallback, useMemo } from "react";
|
|
4
4
|
import { jsx } from "react/jsx-runtime";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { t as HttpError } from "./rest-transport.types-DxitRtsB.mjs";
|
|
2
2
|
import { z } from "zod";
|
|
3
3
|
//#region src/lib/assets/locales/en/translation.json
|
|
4
4
|
var translation_default$1 = { openapi: { "sharedErrors": {
|
|
@@ -35,14 +35,26 @@ function resolveT() {
|
|
|
35
35
|
return getT();
|
|
36
36
|
}
|
|
37
37
|
//#endregion
|
|
38
|
+
//#region src/lib/rest/http-error.utils.ts
|
|
39
|
+
function isAxiosErrorLike(error) {
|
|
40
|
+
return typeof error === "object" && error !== null && "isAxiosError" in error;
|
|
41
|
+
}
|
|
42
|
+
function isCanceledRequest(error) {
|
|
43
|
+
if (error instanceof DOMException && ["AbortError", "TimeoutError"].includes(error.name)) return true;
|
|
44
|
+
if (isAxiosErrorLike(error)) return error.code === "ERR_CANCELED" || error.code === "ECONNABORTED";
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
//#endregion
|
|
38
48
|
//#region src/lib/rest/rest.utils.ts
|
|
49
|
+
function getResponseData(error) {
|
|
50
|
+
if (error instanceof HttpError) return error.response.data;
|
|
51
|
+
return isAxiosErrorLike(error) ? error.response?.data : void 0;
|
|
52
|
+
}
|
|
39
53
|
let RestUtils;
|
|
40
54
|
(function(_RestUtils) {
|
|
41
55
|
_RestUtils.extractServerResponseCode = (e) => {
|
|
42
56
|
if (e instanceof z.ZodError) return "validation-exception";
|
|
43
|
-
|
|
44
|
-
if (!e.response) return null;
|
|
45
|
-
const data = e.response.data;
|
|
57
|
+
const data = getResponseData(e);
|
|
46
58
|
if (typeof data?.code === "string") return data.code;
|
|
47
59
|
if (typeof data?.code === "number") return data.code;
|
|
48
60
|
return null;
|
|
@@ -54,9 +66,7 @@ let RestUtils;
|
|
|
54
66
|
};
|
|
55
67
|
const extractServerErrorMessage = _RestUtils.extractServerErrorMessage = (e) => {
|
|
56
68
|
if (e instanceof z.ZodError) return e.message;
|
|
57
|
-
|
|
58
|
-
if (!e.response) return null;
|
|
59
|
-
const data = e.response.data;
|
|
69
|
+
const data = getResponseData(e);
|
|
60
70
|
if (typeof data?.message === "string") return data.message;
|
|
61
71
|
return null;
|
|
62
72
|
};
|
|
@@ -109,7 +119,8 @@ var ErrorHandler = class ErrorHandler {
|
|
|
109
119
|
const internalError = {
|
|
110
120
|
code: "INTERNAL_ERROR",
|
|
111
121
|
condition: (e) => {
|
|
112
|
-
if (
|
|
122
|
+
if (isAxiosErrorLike(e)) return e.response?.status != null && e.response.status >= 500 && e.response.status < 600;
|
|
123
|
+
if (e instanceof HttpError) return e.response.status >= 500 && e.response.status < 600;
|
|
113
124
|
return false;
|
|
114
125
|
},
|
|
115
126
|
getMessage: () => resolveT()("openapi.sharedErrors.internalError", { ns })
|
|
@@ -117,7 +128,8 @@ var ErrorHandler = class ErrorHandler {
|
|
|
117
128
|
const networkError = {
|
|
118
129
|
code: "NETWORK_ERROR",
|
|
119
130
|
condition: (e) => {
|
|
120
|
-
if (
|
|
131
|
+
if (isAxiosErrorLike(e)) return e.code === "ERR_NETWORK";
|
|
132
|
+
if (e instanceof TypeError) return true;
|
|
121
133
|
return false;
|
|
122
134
|
},
|
|
123
135
|
getMessage: () => resolveT()("openapi.sharedErrors.networkError", { ns })
|
|
@@ -125,9 +137,7 @@ var ErrorHandler = class ErrorHandler {
|
|
|
125
137
|
const canceledError = {
|
|
126
138
|
code: "CANCELED_ERROR",
|
|
127
139
|
condition: (e) => {
|
|
128
|
-
|
|
129
|
-
if (isAxiosError(e) && e.code === "ECONNABORTED") return true;
|
|
130
|
-
return false;
|
|
140
|
+
return isCanceledRequest(e);
|
|
131
141
|
},
|
|
132
142
|
getMessage: () => resolveT()("openapi.sharedErrors.canceledError", { ns })
|
|
133
143
|
};
|
|
@@ -154,12 +154,17 @@ const BODY_PARAMETER_NAME = "data";
|
|
|
154
154
|
const AXIOS_DEFAULT_IMPORT_NAME = "axios";
|
|
155
155
|
const AXIOS_REQUEST_CONFIG_NAME = "config";
|
|
156
156
|
const AXIOS_REQUEST_CONFIG_TYPE = "AxiosRequestConfig";
|
|
157
|
+
const NATIVE_REQUEST_CONFIG_TYPE = "TransportRequestConfig";
|
|
158
|
+
const NATIVE_RESPONSE_TYPE = "TransportResponse";
|
|
157
159
|
const AXIOS_IMPORT = {
|
|
158
160
|
defaultImport: AXIOS_DEFAULT_IMPORT_NAME,
|
|
159
161
|
bindings: [],
|
|
160
162
|
typeBindings: [AXIOS_REQUEST_CONFIG_TYPE],
|
|
161
163
|
from: "axios"
|
|
162
164
|
};
|
|
165
|
+
function getRequestConfigTypeName(restClient) {
|
|
166
|
+
return restClient === "native" ? NATIVE_REQUEST_CONFIG_TYPE : AXIOS_REQUEST_CONFIG_TYPE;
|
|
167
|
+
}
|
|
163
168
|
//#endregion
|
|
164
169
|
//#region src/generators/const/zod.const.ts
|
|
165
170
|
const SCHEMA_SUFFIX = "Schema";
|
|
@@ -362,6 +367,8 @@ const getNamespaceName = ({ type, tag, options }) => `${capitalize(tag)}${option
|
|
|
362
367
|
//#endregion
|
|
363
368
|
//#region src/generators/const/package.const.ts
|
|
364
369
|
const PACKAGE_IMPORT_PATH = "@povio/openapi-codegen-cli";
|
|
370
|
+
const NATIVE_PACKAGE_IMPORT_PATH = `${PACKAGE_IMPORT_PATH}/native`;
|
|
371
|
+
const REST_PACKAGE_IMPORT_PATH = `${PACKAGE_IMPORT_PATH}/rest`;
|
|
365
372
|
//#endregion
|
|
366
373
|
//#region src/generators/const/deps.const.ts
|
|
367
374
|
const APP_REST_CLIENT_NAME = "AppRestClient";
|
|
@@ -515,6 +522,7 @@ const DEFAULT_GENERATE_OPTIONS = {
|
|
|
515
522
|
withDefaultValues: true,
|
|
516
523
|
extractEnums: true,
|
|
517
524
|
replaceOptionalWithNullish: false,
|
|
525
|
+
restClient: "axios",
|
|
518
526
|
restClientImportPath: "",
|
|
519
527
|
zodImportPath: "@povio/openapi-codegen-cli/zod",
|
|
520
528
|
errorHandlingImportPath: "",
|
|
@@ -1282,15 +1290,14 @@ function renderMediaUploadMutationBody({ resolver, endpointFunction, resolvedEnd
|
|
|
1282
1290
|
" }",
|
|
1283
1291
|
" dataToSend.append(\"file\", file);",
|
|
1284
1292
|
" }",
|
|
1285
|
-
" await axios[method](uploadInstructions.url, dataToSend, {",
|
|
1286
|
-
" headers: {",
|
|
1287
|
-
" \"Content-Type\": file.type,",
|
|
1288
|
-
" },",
|
|
1293
|
+
resolver.options.restClient === "native" ? " await AppRestClient.upload(uploadInstructions.url, dataToSend, {" : " await axios[method](uploadInstructions.url, dataToSend, {",
|
|
1294
|
+
resolver.options.restClient === "native" ? " headers: method === \"put\" ? { \"Content-Type\": file.type } : undefined," : " headers: {",
|
|
1295
|
+
...resolver.options.restClient === "native" ? [] : [" \"Content-Type\": file.type,", " },"],
|
|
1289
1296
|
" signal: abortController?.signal,",
|
|
1290
1297
|
" onUploadProgress: onUploadProgress",
|
|
1291
1298
|
" ? (progressEvent) => onUploadProgress({ loaded: progressEvent.loaded, total: progressEvent.total ?? 0 })",
|
|
1292
1299
|
" : undefined,",
|
|
1293
|
-
" });",
|
|
1300
|
+
resolver.options.restClient === "native" ? " }, method);" : " });",
|
|
1294
1301
|
"}",
|
|
1295
1302
|
"",
|
|
1296
1303
|
"return uploadInstructions;"
|
|
@@ -1535,7 +1542,7 @@ function generateFilesFromNativeOpenAPI(source, yaml, options) {
|
|
|
1535
1542
|
if (!options.modelsOnly) {
|
|
1536
1543
|
if (options.acl && nativeData.renderedShared.appAcl) files.push(outputFile(options, "acl/app.ability.ts", nativeData.renderedShared.appAcl));
|
|
1537
1544
|
if (options.mutationEffects && nativeData.renderedShared.queryModules) files.push(outputFile(options, "queryModules.ts", nativeData.renderedShared.queryModules));
|
|
1538
|
-
if (!options.restClientImportPath) files.push(outputFile(options, "app-rest-client.ts", `import { RestClient } from "@povio/openapi-codegen";\n\nexport const AppRestClient = new RestClient({\n config: {\n baseURL: "${nativeData.baseUrl}"\n },\n});\n`));
|
|
1545
|
+
if (!options.restClientImportPath) files.push(outputFile(options, "app-rest-client.ts", `import { ${options.restClient === "native" ? "NativeRestClient" : "RestClient"} } from "@povio/openapi-codegen-cli${options.restClient === "native" ? "/native" : ""}";\n\nexport const AppRestClient = new ${options.restClient === "native" ? "NativeRestClient" : "RestClient"}({\n config: {\n baseURL: "${nativeData.baseUrl}"\n },\n});\n`));
|
|
1539
1546
|
if (nativeData.renderedShared.domainErrors) files.push(outputFile(options, "domain-errors.ts", nativeData.renderedShared.domainErrors));
|
|
1540
1547
|
}
|
|
1541
1548
|
return files;
|
|
@@ -1585,7 +1592,7 @@ async function runGenerate({ fileConfig, params, formatGeneratedFile, profiler =
|
|
|
1585
1592
|
const nativeFiles = generateFilesFromNativeOpenAPI(nativeInput.source, nativeInput.yaml, config);
|
|
1586
1593
|
if (nativeFiles) return nativeFiles;
|
|
1587
1594
|
}
|
|
1588
|
-
const { generateCodeFromOpenAPIDoc } = await import("./generateCodeFromOpenAPIDoc-
|
|
1595
|
+
const { generateCodeFromOpenAPIDoc } = await import("./generateCodeFromOpenAPIDoc-glAKBEGP.mjs").then((n) => n.n);
|
|
1589
1596
|
return generateCodeFromOpenAPIDoc(openApiDoc, config, profiler, {
|
|
1590
1597
|
source: nativeInput.source,
|
|
1591
1598
|
yaml: nativeInput.yaml
|
|
@@ -1673,4 +1680,4 @@ function getGenerateStats(filesData, config) {
|
|
|
1673
1680
|
};
|
|
1674
1681
|
}
|
|
1675
1682
|
//#endregion
|
|
1676
|
-
export { getImportedAbilityFunctionName as $,
|
|
1683
|
+
export { getImportedAbilityFunctionName as $, isMainResponseStatus as $t, getEndpointsImports as A, AXIOS_REQUEST_CONFIG_NAME as An, getZodSchemaName as At, getPrefetchInfiniteQueryName as B, shouldInlineEndpointsForTag as Bn, QUERY_MODULE_ENUM as Bt, getAppRestClientImportPath as C, STRING_SCHEMA as Cn, isReadEndpoint as Ct, getTagFileName as D, ZOD_IMPORT as Dn, getEnumZodSchemaName as Dt, getQueryTypesImportPath as E, VOID_SCHEMA as En, getBodyZodSchemaName as Et, mergeImports as F, getRequestConfigTypeName as Fn, APP_REST_CLIENT_NAME as Ft, getAbilityConditionType as G, kebabToCamel as Gn, REST_PACKAGE_IMPORT_PATH as Gt, getQueryName as H, capitalize as Hn, ZOD_EXTENDED as Ht, getImportedInfiniteQueryName as I, formatTag as In, BUILDERS_UTILS as It, getAbilityFunctionName as J, Profiler as Jn, escapeControlCharacters as Jt, getAbilityConditionsTypes as K, removeWord as Kn, getNamespaceName as Kt, getImportedQueryName as L, getEndpointTag as Ln, DOMAIN_ERRORS_FILE as Lt, getInfiniteQueriesImports as M, BODY_PARAMETER_NAME as Mn, isEnumZodSchema as Mt, getModelsImports as N, JSON_APPLICATION_FORMAT as Nn, isNamedZodSchema as Nt, getTagImportPath as O, AXIOS_DEFAULT_IMPORT_NAME as On, getParamZodSchemaName as Ot, getQueriesImports as P, NATIVE_RESPONSE_TYPE as Pn, APP_REST_CLIENT_FILE as Pt, getAppAbilitiesType as Q, isErrorStatus as Qt, getInfiniteQueryName as R, getOperationTag as Rn, MUTATION_EFFECTS as Rt, getTsTypeBase as S, NUMBER_SCHEMA as Sn, isReadAllEndpoint as St, getQueryModulesImportPath as T, UUID_SCHEMA as Tn, invalidVariableNameCharactersToCamel as Tt, getQueryOptionsName as U, decapitalize as Un, NATIVE_PACKAGE_IMPORT_PATH as Ut, getPrefetchQueryName as V, camelToSpaceSeparated as Vn, QUERY_OPTIONS_TYPES as Vt, getAbilityAction as W, getMostCommonAdjacentCombinationSplit as Wn, PACKAGE_IMPORT_PATH as Wt, getAbilitySubjectTypes as X, getSchemaNameByRef as Xt, getAbilitySubject as Y, getParameterEnumNames as Yt, getAclData as Z, getSchemaRef as Zt, hasEndpointConfig as _, BLOB_SCHEMA as _n, getPathSegments as _t, resolveConfig as a, pathParamToVariableName as an, getZodSchemaInferedTypeName as at, requiresBody as b, ENUM_SCHEMA as bn, isDeleteEndpoint as bt, getDestructuredVariables as c, unwrapQuotesIfNeeded as cn, getSchemaDescriptions as ct, isQuery as d, isArraySchemaObject as dn, DEFAULT_GENERATE_OPTIONS as dt, isMediaTypeAllowed as en, hasAbilityConditions as et, getEndpointBody as f, isReferenceObject as fn, ACL_APP_ABILITIES as ft, getImportedEndpointName as g, ANY_SCHEMA as gn, CASL_ABILITY_IMPORT as gt, getEndpointPath as h, ALLOWED_PATH_IN as hn, CASL_ABILITY_BINDING as ht, shouldUseNativeCodegen as i, isSortingParameterObject as in, getZodSchemaDescription as it, getImportPath as j, AXIOS_REQUEST_CONFIG_TYPE as jn, getZodSchemaOperationName as jt, getAclImports as k, AXIOS_IMPORT as kn, getResponseZodSchemaName as kt, isInfiniteQuery as l, wrapWithQuotesIfNeeded as ln, iterateSchema as lt, getEndpointName as m, ALLOWED_METHODS as mn, ACL_CHECK_HOOK as mt, runGenerate as n, isPathExcluded as nn, getImportedZodSchemaInferedTypeName as nt, getOutputFileName as o, pathToVariableName as on, getZodSchemaPropertyDescriptions as ot, getEndpointConfig as p, isSchemaObject as pn, ACL_APP_ABILITY_FILE as pt, getAbilityDescription as q, snakeToCamel as qn, autocorrectRef as qt, compileNativeData as r, isPrimitiveType as rn, getImportedZodSchemaName as rt, pick as s, replaceHyphenatedPath as sn, getZodSchemaType as st, getOpenApiDoc as t, isParamMediaTypeAllowed as tn, renderAclCheckCall as tt, isMutation as u, inferRequiredSchema as un, getUniqueArray as ut, mapEndpointParamsToFunctionParams as v, DATETIME_SCHEMA as vn, isBulkDeleteEndpoint as vt, getFileNameWithExtension as w, URL_SCHEMA as wn, isUpdateEndpoint as wt, getSchemaTsMetaType as x, INT_SCHEMA as xn, isPathSegmentParam as xt, renderMediaUploadMutationBody as y, EMAIL_SCHEMA as yn, isCreateEndpoint as yt, getInfiniteQueryOptionsName as z, isTagIncluded as zn, QUERY_MODULES_FILE as zt };
|
|
@@ -33,6 +33,8 @@ node_path = __toESM(node_path, 1);
|
|
|
33
33
|
let openapi_types = require("openapi-types");
|
|
34
34
|
//#region src/generators/const/package.const.ts
|
|
35
35
|
const PACKAGE_IMPORT_PATH = "@povio/openapi-codegen-cli";
|
|
36
|
+
const NATIVE_PACKAGE_IMPORT_PATH = `${PACKAGE_IMPORT_PATH}/native`;
|
|
37
|
+
const REST_PACKAGE_IMPORT_PATH = `${PACKAGE_IMPORT_PATH}/rest`;
|
|
36
38
|
//#endregion
|
|
37
39
|
//#region src/generators/const/zod.const.ts
|
|
38
40
|
const SCHEMA_SUFFIX = "Schema";
|
|
@@ -105,6 +107,7 @@ const DEFAULT_GENERATE_OPTIONS = {
|
|
|
105
107
|
withDefaultValues: true,
|
|
106
108
|
extractEnums: true,
|
|
107
109
|
replaceOptionalWithNullish: false,
|
|
110
|
+
restClient: "axios",
|
|
108
111
|
restClientImportPath: "",
|
|
109
112
|
zodImportPath: "@povio/openapi-codegen-cli/zod",
|
|
110
113
|
errorHandlingImportPath: "",
|
|
@@ -991,12 +994,17 @@ const BODY_PARAMETER_NAME = "data";
|
|
|
991
994
|
const AXIOS_DEFAULT_IMPORT_NAME = "axios";
|
|
992
995
|
const AXIOS_REQUEST_CONFIG_NAME = "config";
|
|
993
996
|
const AXIOS_REQUEST_CONFIG_TYPE = "AxiosRequestConfig";
|
|
997
|
+
const NATIVE_REQUEST_CONFIG_TYPE = "TransportRequestConfig";
|
|
998
|
+
const NATIVE_RESPONSE_TYPE = "TransportResponse";
|
|
994
999
|
const AXIOS_IMPORT = {
|
|
995
1000
|
defaultImport: AXIOS_DEFAULT_IMPORT_NAME,
|
|
996
1001
|
bindings: [],
|
|
997
1002
|
typeBindings: [AXIOS_REQUEST_CONFIG_TYPE],
|
|
998
1003
|
from: "axios"
|
|
999
1004
|
};
|
|
1005
|
+
function getRequestConfigTypeName(restClient) {
|
|
1006
|
+
return restClient === "native" ? NATIVE_REQUEST_CONFIG_TYPE : AXIOS_REQUEST_CONFIG_TYPE;
|
|
1007
|
+
}
|
|
1000
1008
|
//#endregion
|
|
1001
1009
|
//#region src/generators/utils/endpoint.utils.ts
|
|
1002
1010
|
const isGetEndpoint = (endpoint) => endpoint.method === openapi_types.OpenAPIV3.HttpMethods.GET;
|
|
@@ -1167,15 +1175,14 @@ function renderMediaUploadMutationBody({ resolver, endpointFunction, resolvedEnd
|
|
|
1167
1175
|
" }",
|
|
1168
1176
|
" dataToSend.append(\"file\", file);",
|
|
1169
1177
|
" }",
|
|
1170
|
-
" await axios[method](uploadInstructions.url, dataToSend, {",
|
|
1171
|
-
" headers: {",
|
|
1172
|
-
" \"Content-Type\": file.type,",
|
|
1173
|
-
" },",
|
|
1178
|
+
resolver.options.restClient === "native" ? " await AppRestClient.upload(uploadInstructions.url, dataToSend, {" : " await axios[method](uploadInstructions.url, dataToSend, {",
|
|
1179
|
+
resolver.options.restClient === "native" ? " headers: method === \"put\" ? { \"Content-Type\": file.type } : undefined," : " headers: {",
|
|
1180
|
+
...resolver.options.restClient === "native" ? [] : [" \"Content-Type\": file.type,", " },"],
|
|
1174
1181
|
" signal: abortController?.signal,",
|
|
1175
1182
|
" onUploadProgress: onUploadProgress",
|
|
1176
1183
|
" ? (progressEvent) => onUploadProgress({ loaded: progressEvent.loaded, total: progressEvent.total ?? 0 })",
|
|
1177
1184
|
" : undefined,",
|
|
1178
|
-
" });",
|
|
1185
|
+
resolver.options.restClient === "native" ? " }, method);" : " });",
|
|
1179
1186
|
"}",
|
|
1180
1187
|
"",
|
|
1181
1188
|
"return uploadInstructions;"
|
|
@@ -1525,6 +1532,18 @@ Object.defineProperty(exports, "MUTATION_EFFECTS", {
|
|
|
1525
1532
|
return MUTATION_EFFECTS;
|
|
1526
1533
|
}
|
|
1527
1534
|
});
|
|
1535
|
+
Object.defineProperty(exports, "NATIVE_PACKAGE_IMPORT_PATH", {
|
|
1536
|
+
enumerable: true,
|
|
1537
|
+
get: function() {
|
|
1538
|
+
return NATIVE_PACKAGE_IMPORT_PATH;
|
|
1539
|
+
}
|
|
1540
|
+
});
|
|
1541
|
+
Object.defineProperty(exports, "NATIVE_RESPONSE_TYPE", {
|
|
1542
|
+
enumerable: true,
|
|
1543
|
+
get: function() {
|
|
1544
|
+
return NATIVE_RESPONSE_TYPE;
|
|
1545
|
+
}
|
|
1546
|
+
});
|
|
1528
1547
|
Object.defineProperty(exports, "NUMBER_SCHEMA", {
|
|
1529
1548
|
enumerable: true,
|
|
1530
1549
|
get: function() {
|
|
@@ -1561,6 +1580,12 @@ Object.defineProperty(exports, "QUERY_OPTIONS_TYPES", {
|
|
|
1561
1580
|
return QUERY_OPTIONS_TYPES;
|
|
1562
1581
|
}
|
|
1563
1582
|
});
|
|
1583
|
+
Object.defineProperty(exports, "REST_PACKAGE_IMPORT_PATH", {
|
|
1584
|
+
enumerable: true,
|
|
1585
|
+
get: function() {
|
|
1586
|
+
return REST_PACKAGE_IMPORT_PATH;
|
|
1587
|
+
}
|
|
1588
|
+
});
|
|
1564
1589
|
Object.defineProperty(exports, "STRING_SCHEMA", {
|
|
1565
1590
|
enumerable: true,
|
|
1566
1591
|
get: function() {
|
|
@@ -1927,6 +1952,12 @@ Object.defineProperty(exports, "getQueryTypesImportPath", {
|
|
|
1927
1952
|
return getQueryTypesImportPath;
|
|
1928
1953
|
}
|
|
1929
1954
|
});
|
|
1955
|
+
Object.defineProperty(exports, "getRequestConfigTypeName", {
|
|
1956
|
+
enumerable: true,
|
|
1957
|
+
get: function() {
|
|
1958
|
+
return getRequestConfigTypeName;
|
|
1959
|
+
}
|
|
1960
|
+
});
|
|
1930
1961
|
Object.defineProperty(exports, "getResponseZodSchemaName", {
|
|
1931
1962
|
enumerable: true,
|
|
1932
1963
|
get: function() {
|
package/dist/{generateCodeFromOpenAPIDoc-5VZFVFK1.cjs → generateCodeFromOpenAPIDoc-CZT3sThI.cjs}
RENAMED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const require_generate_utils = require("./generate.utils-
|
|
1
|
+
const require_generate_utils = require("./generate.utils-CH2U2Dpr.cjs");
|
|
2
2
|
//#region src/generators/core/zod/getZodChain.ts
|
|
3
3
|
const zodChainCache = /* @__PURE__ */ new WeakMap();
|
|
4
4
|
function getZodChain({ schema, meta, options }) {
|
|
@@ -2397,14 +2397,24 @@ function generateConfigs(generateTypeParams) {
|
|
|
2397
2397
|
const hasMutationEffects = resolver.options.mutationEffects && hasMutation;
|
|
2398
2398
|
const hasMutationDefaultOnError = resolver.options.mutationDefaultOnError && hasMutation;
|
|
2399
2399
|
const hasAxiosRequestConfig = resolver.options.axiosRequestConfig;
|
|
2400
|
-
const
|
|
2401
|
-
const
|
|
2400
|
+
const nativeClient = resolver.options.restClient === "native";
|
|
2401
|
+
const hasAxiosDefaultImport = !nativeClient && endpoints.some((e) => e.mediaUpload);
|
|
2402
|
+
const hasAxiosImport = !nativeClient && (hasAxiosRequestConfig || hasAxiosDefaultImport);
|
|
2402
2403
|
const axiosImport = {
|
|
2403
2404
|
defaultImport: hasAxiosDefaultImport ? require_generate_utils.AXIOS_DEFAULT_IMPORT_NAME : void 0,
|
|
2404
2405
|
bindings: [],
|
|
2405
2406
|
typeBindings: hasAxiosImport ? [require_generate_utils.AXIOS_REQUEST_CONFIG_TYPE] : [],
|
|
2406
2407
|
from: "axios"
|
|
2407
2408
|
};
|
|
2409
|
+
const nativeImport = {
|
|
2410
|
+
bindings: [],
|
|
2411
|
+
typeBindings: nativeClient && hasAxiosRequestConfig ? [require_generate_utils.getRequestConfigTypeName("native")] : [],
|
|
2412
|
+
from: require_generate_utils.REST_PACKAGE_IMPORT_PATH
|
|
2413
|
+
};
|
|
2414
|
+
const appRestClientImport = {
|
|
2415
|
+
bindings: [require_generate_utils.APP_REST_CLIENT_NAME],
|
|
2416
|
+
from: require_generate_utils.getAppRestClientImportPath(resolver.options)
|
|
2417
|
+
};
|
|
2408
2418
|
const endpointsImports = require_generate_utils.getEndpointsImports({
|
|
2409
2419
|
tag,
|
|
2410
2420
|
endpoints,
|
|
@@ -2444,6 +2454,8 @@ function generateConfigs(generateTypeParams) {
|
|
|
2444
2454
|
};
|
|
2445
2455
|
const lines = [];
|
|
2446
2456
|
if (hasAxiosImport) lines.push(renderImport$3(axiosImport));
|
|
2457
|
+
if (nativeImport.typeBindings?.length) lines.push(renderImport$3(nativeImport));
|
|
2458
|
+
if (nativeClient && endpoints.some((endpoint) => endpoint.mediaUpload)) lines.push(renderImport$3(appRestClientImport));
|
|
2447
2459
|
if (hasZodImport) lines.push(renderImport$3(require_generate_utils.ZOD_IMPORT));
|
|
2448
2460
|
if (hasDynamicInputsImport) lines.push(renderImport$3(dynamicInputsImport));
|
|
2449
2461
|
if (hasDynamicColumnsImport) lines.push(renderImport$3(dynamicColumnsImport));
|
|
@@ -2519,7 +2531,7 @@ function renderMutationContent(resolver, endpoint, tag) {
|
|
|
2519
2531
|
const endpointFunction = require_generate_utils.getImportedEndpointName(endpoint, resolver.options);
|
|
2520
2532
|
const mutationVariablesType = endpoint.mediaUpload ? `{ ${endpointParamsStr}${endpointParamsStr ? "; " : ""}abortController?: AbortController; onUploadProgress?: (progress: { loaded: number; total: number }) => void }` : `{ ${endpointParamsStr} }`;
|
|
2521
2533
|
const lines = [];
|
|
2522
|
-
lines.push(`(options?: AppMutationOptions<typeof ${endpointFunction}, ${mutationVariablesType}>${hasMutationEffects ? ` & ${require_generate_utils.MUTATION_EFFECTS.optionsType}` : ""}${hasAxiosRequestConfig ? `, config?: ${require_generate_utils.
|
|
2534
|
+
lines.push(`(options?: AppMutationOptions<typeof ${endpointFunction}, ${mutationVariablesType}>${hasMutationEffects ? ` & ${require_generate_utils.MUTATION_EFFECTS.optionsType}` : ""}${hasAxiosRequestConfig ? `, config?: ${require_generate_utils.getRequestConfigTypeName(resolver.options.restClient)}` : ""}) => {`);
|
|
2523
2535
|
if (hasMutationDefaultOnError) lines.push(" const queryConfig = OpenApiQueryConfig.useConfig();");
|
|
2524
2536
|
if (hasMutationEffects) lines.push(` const { runMutationEffects } = useMutationEffects<${require_generate_utils.QUERY_MODULE_ENUM}.${endpointTag}>({ currentModule: ${require_generate_utils.QUERY_MODULE_ENUM}.${tag} });`);
|
|
2525
2537
|
if (hasAclCheck) lines.push(` const { checkAcl } = ${require_generate_utils.ACL_CHECK_HOOK}();`);
|
|
@@ -2621,12 +2633,18 @@ function generateEndpoints({ resolver, data, tag }) {
|
|
|
2621
2633
|
};
|
|
2622
2634
|
const hasAxiosRequestConfig = resolver.options.axiosRequestConfig;
|
|
2623
2635
|
const hasGetEndpoints = endpoints.some((endpoint) => endpoint.method === "get");
|
|
2624
|
-
const
|
|
2636
|
+
const nativeClient = resolver.options.restClient === "native";
|
|
2637
|
+
const hasAxiosImport = !nativeClient && (hasAxiosRequestConfig || hasGetEndpoints);
|
|
2625
2638
|
const axiosImport = {
|
|
2626
2639
|
bindings: [],
|
|
2627
2640
|
typeBindings: hasAxiosImport ? [require_generate_utils.AXIOS_REQUEST_CONFIG_TYPE] : [],
|
|
2628
2641
|
from: require_generate_utils.AXIOS_IMPORT.from
|
|
2629
2642
|
};
|
|
2643
|
+
const nativeImport = {
|
|
2644
|
+
bindings: [],
|
|
2645
|
+
typeBindings: nativeClient && (hasAxiosRequestConfig || hasGetEndpoints) ? [require_generate_utils.getRequestConfigTypeName("native")] : [],
|
|
2646
|
+
from: require_generate_utils.REST_PACKAGE_IMPORT_PATH
|
|
2647
|
+
};
|
|
2630
2648
|
const generateParse = resolver.options.parseRequestParams;
|
|
2631
2649
|
const endpointParams = endpoints.flatMap((endpoint) => endpoint.parameters);
|
|
2632
2650
|
const endpointParamsParseSchemas = endpointParams.filter((param) => !["Path", "Header"].includes(param.type)).map((param) => param.parameterSortingEnumSchemaName ?? param.zodSchema);
|
|
@@ -2647,6 +2665,7 @@ function generateEndpoints({ resolver, data, tag }) {
|
|
|
2647
2665
|
const lines = [];
|
|
2648
2666
|
lines.push(renderImport$2(appRestClientImport));
|
|
2649
2667
|
if (hasAxiosImport) lines.push(renderImport$2(axiosImport));
|
|
2668
|
+
if (nativeImport.typeBindings?.length) lines.push(renderImport$2(nativeImport));
|
|
2650
2669
|
if (hasZodImport) lines.push(renderImport$2(require_generate_utils.ZOD_IMPORT));
|
|
2651
2670
|
if (hasZodExtendedImport) lines.push(renderImport$2(zodExtendedImport));
|
|
2652
2671
|
for (const modelsImport of modelsImports) lines.push(renderImport$2(modelsImport));
|
|
@@ -2664,7 +2683,7 @@ function generateEndpoints({ resolver, data, tag }) {
|
|
|
2664
2683
|
const hasUndefinedEndpointBody = require_generate_utils.requiresBody(endpoint) && !endpointBody && require_generate_utils.hasEndpointConfig(endpoint, resolver);
|
|
2665
2684
|
const endpointConfig = renderEndpointConfig(resolver, endpoint, tag);
|
|
2666
2685
|
const hasRequestConfigParam = hasAxiosRequestConfig || endpoint.method === "get";
|
|
2667
|
-
lines.push(`export const ${require_generate_utils.getEndpointName(endpoint)} = (${endpointParams}${hasRequestConfigParam ? `${require_generate_utils.AXIOS_REQUEST_CONFIG_NAME}?: ${getRequestConfigType$1()}` : ""}) => {`);
|
|
2686
|
+
lines.push(`export const ${require_generate_utils.getEndpointName(endpoint)} = (${endpointParams}${hasRequestConfigParam ? `${require_generate_utils.AXIOS_REQUEST_CONFIG_NAME}?: ${getRequestConfigType$1(resolver)}` : ""}) => {`);
|
|
2668
2687
|
lines.push(` return ${require_generate_utils.APP_REST_CLIENT_NAME}.${endpoint.method}(`);
|
|
2669
2688
|
lines.push(` ${renderRequestInfo(resolver, endpoint, tag)},`);
|
|
2670
2689
|
lines.push(` \`${require_generate_utils.getEndpointPath(endpoint)}\`,`);
|
|
@@ -2680,8 +2699,8 @@ function generateEndpoints({ resolver, data, tag }) {
|
|
|
2680
2699
|
function renderRequestInfo(resolver, endpoint, tag) {
|
|
2681
2700
|
return `{ resSchema: ${require_generate_utils.getImportedZodSchemaName(resolver, endpoint.response, (resolver.options.modelsInCommon || resolver.options.modelsInModules) && resolver.options.splitByTags ? tag : void 0)} }`;
|
|
2682
2701
|
}
|
|
2683
|
-
function getRequestConfigType$1() {
|
|
2684
|
-
return `${require_generate_utils.
|
|
2702
|
+
function getRequestConfigType$1(resolver) {
|
|
2703
|
+
return `${require_generate_utils.getRequestConfigTypeName(resolver.options.restClient)} & { allowInvalidResponseData?: boolean }`;
|
|
2685
2704
|
}
|
|
2686
2705
|
function renderImport$2(importData) {
|
|
2687
2706
|
const namedImports = [...importData.bindings, ...(importData.typeBindings ?? []).map((binding) => importData.typeOnly ? binding : `type ${binding}`)];
|
|
@@ -2892,15 +2911,23 @@ function generateQueries(params) {
|
|
|
2892
2911
|
if (!endpoints || endpoints.length === 0) return;
|
|
2893
2912
|
const endpointGroups = groupEndpoints(endpoints, resolver);
|
|
2894
2913
|
const hasAxiosRequestConfig = resolver.options.axiosRequestConfig;
|
|
2895
|
-
const
|
|
2914
|
+
const nativeClient = resolver.options.restClient === "native";
|
|
2915
|
+
const hasNativeMediaUpload = nativeClient && endpoints.some(({ mediaUpload }) => mediaUpload);
|
|
2916
|
+
const requestConfigType = require_generate_utils.getRequestConfigTypeName(resolver.options.restClient);
|
|
2917
|
+
const hasAxiosDefaultImport = !nativeClient && endpoints.some(({ mediaUpload }) => mediaUpload);
|
|
2896
2918
|
const hasGetEndpoints = endpoints.some((endpoint) => endpoint.method === "get");
|
|
2897
|
-
const hasAxiosImport = hasAxiosRequestConfig || hasAxiosDefaultImport || hasGetEndpoints;
|
|
2919
|
+
const hasAxiosImport = !nativeClient && (hasAxiosRequestConfig || hasAxiosDefaultImport || hasGetEndpoints);
|
|
2898
2920
|
const axiosImport = {
|
|
2899
2921
|
defaultImport: hasAxiosDefaultImport ? require_generate_utils.AXIOS_DEFAULT_IMPORT_NAME : void 0,
|
|
2900
2922
|
bindings: [],
|
|
2901
2923
|
typeBindings: hasAxiosImport ? [require_generate_utils.AXIOS_REQUEST_CONFIG_TYPE] : [],
|
|
2902
2924
|
from: require_generate_utils.AXIOS_IMPORT.from
|
|
2903
2925
|
};
|
|
2926
|
+
const nativeTransportImport = {
|
|
2927
|
+
bindings: [],
|
|
2928
|
+
typeBindings: nativeClient ? [...hasAxiosRequestConfig || hasGetEndpoints ? [requestConfigType] : [], ...endpoints.some(({ mediaDownload }) => mediaDownload) ? [require_generate_utils.NATIVE_RESPONSE_TYPE] : []] : [],
|
|
2929
|
+
from: require_generate_utils.REST_PACKAGE_IMPORT_PATH
|
|
2930
|
+
};
|
|
2904
2931
|
const { queryEndpoints, infiniteQueryEndpoints, mutationEndpoints, aclEndpoints } = endpointGroups;
|
|
2905
2932
|
const hasMutationDefaultOnError = resolver.options.mutationDefaultOnError && mutationEndpoints.length > 0;
|
|
2906
2933
|
const queryImport = {
|
|
@@ -2979,8 +3006,9 @@ function generateQueries(params) {
|
|
|
2979
3006
|
});
|
|
2980
3007
|
const lines = [];
|
|
2981
3008
|
if (hasAxiosImport) lines.push(renderImport(axiosImport));
|
|
3009
|
+
if (nativeTransportImport.typeBindings?.length) lines.push(renderImport(nativeTransportImport));
|
|
3010
|
+
if (inlineEndpoints || hasNativeMediaUpload) lines.push(renderImport(appRestClientImport));
|
|
2982
3011
|
if (inlineEndpoints) {
|
|
2983
|
-
lines.push(renderImport(appRestClientImport));
|
|
2984
3012
|
if (hasZodImport) lines.push(renderImport(require_generate_utils.ZOD_IMPORT));
|
|
2985
3013
|
if (hasZodExtendedImport) lines.push(renderImport(zodExtendedImport));
|
|
2986
3014
|
}
|
|
@@ -3211,8 +3239,9 @@ function renderQueryJsDocs({ resolver, endpoint, mode, tag }) {
|
|
|
3211
3239
|
if (mode === "query") lines.push(" * @param { AppQueryOptions } options Query options");
|
|
3212
3240
|
else if (mode === "mutation") lines.push(` * @param { AppMutationOptions${resolver.options.mutationEffects ? ` & ${require_generate_utils.MUTATION_EFFECTS.optionsType}` : ""} } options Mutation options`);
|
|
3213
3241
|
else lines.push(" * @param { AppInfiniteQueryOptions } options Infinite query options");
|
|
3214
|
-
const
|
|
3215
|
-
const
|
|
3242
|
+
const withRawResponse = endpoint.mediaDownload && mode !== "infiniteQuery";
|
|
3243
|
+
const responseType = resolver.options.restClient === "native" ? require_generate_utils.NATIVE_RESPONSE_TYPE : "AxiosResponse";
|
|
3244
|
+
const resultType = `${withRawResponse ? `${responseType}<` : ""}${require_generate_utils.getImportedZodSchemaInferedTypeName(resolver, endpoint.response, void 0, tag)}${withRawResponse ? ">" : ""}`;
|
|
3216
3245
|
if (mode === "query") lines.push(` * @returns { UseQueryResult<${resultType}> } ${endpoint.responseDescription ?? ""}`);
|
|
3217
3246
|
else if (mode === "mutation") lines.push(` * @returns { UseMutationResult<${resultType}> } ${endpoint.responseDescription ?? ""}`);
|
|
3218
3247
|
else lines.push(` * @returns { UseInfiniteQueryResult<${resultType}> } ${endpoint.responseDescription ?? ""}`);
|
|
@@ -3247,7 +3276,7 @@ function renderInlineEndpoints({ resolver, endpoints, tag }) {
|
|
|
3247
3276
|
const hasUndefinedEndpointBody = require_generate_utils.requiresBody(endpoint) && !endpointBody && require_generate_utils.hasEndpointConfig(endpoint, resolver);
|
|
3248
3277
|
const endpointConfig = renderInlineEndpointConfig(resolver, endpoint, tag);
|
|
3249
3278
|
const hasRequestConfigParam = resolver.options.axiosRequestConfig || endpoint.method === "get";
|
|
3250
|
-
lines.push(`const ${require_generate_utils.getEndpointName(endpoint)} = (${endpointParams}${hasRequestConfigParam ? `${endpointParams ? ", " : ""}${require_generate_utils.AXIOS_REQUEST_CONFIG_NAME}?: ${getRequestConfigType()}` : ""}) => {`);
|
|
3279
|
+
lines.push(`const ${require_generate_utils.getEndpointName(endpoint)} = (${endpointParams}${hasRequestConfigParam ? `${endpointParams ? ", " : ""}${require_generate_utils.AXIOS_REQUEST_CONFIG_NAME}?: ${getRequestConfigType(resolver)}` : ""}) => {`);
|
|
3251
3280
|
lines.push(` return ${require_generate_utils.APP_REST_CLIENT_NAME}.${endpoint.method}(`);
|
|
3252
3281
|
lines.push(` ${renderInlineRequestInfo(resolver, endpoint, tag)},`);
|
|
3253
3282
|
lines.push(` \`${require_generate_utils.getEndpointPath(endpoint)}\`,`);
|
|
@@ -3263,8 +3292,8 @@ function renderInlineEndpoints({ resolver, endpoints, tag }) {
|
|
|
3263
3292
|
function renderInlineRequestInfo(resolver, endpoint, tag) {
|
|
3264
3293
|
return `{ resSchema: ${require_generate_utils.getImportedZodSchemaName(resolver, endpoint.response, tag)} }`;
|
|
3265
3294
|
}
|
|
3266
|
-
function getRequestConfigType() {
|
|
3267
|
-
return `${require_generate_utils.
|
|
3295
|
+
function getRequestConfigType(resolver) {
|
|
3296
|
+
return `${require_generate_utils.getRequestConfigTypeName(resolver.options.restClient)} & { allowInvalidResponseData?: boolean }`;
|
|
3268
3297
|
}
|
|
3269
3298
|
function renderRequestConfigWithSignal(hasRequestConfigParam) {
|
|
3270
3299
|
return `{ ${hasRequestConfigParam ? `...${require_generate_utils.AXIOS_REQUEST_CONFIG_NAME}, ` : ""}signal }`;
|
|
@@ -3313,7 +3342,7 @@ function renderQueryOptions({ resolver, endpoint, inlineEndpoints }) {
|
|
|
3313
3342
|
const endpointArgs = renderEndpointArgs(resolver, endpoint, {});
|
|
3314
3343
|
const endpointFunction = inlineEndpoints ? require_generate_utils.getEndpointName(endpoint) : require_generate_utils.getImportedEndpointName(endpoint, resolver.options);
|
|
3315
3344
|
const lines = [];
|
|
3316
|
-
lines.push(`const ${require_generate_utils.getQueryOptionsName(endpoint)} = (${endpointParams ? `{ ${endpointArgs} }: { ${endpointParams} }` : ""}${hasRequestConfigParam ? `${endpointParams ? ", " : ""}${require_generate_utils.AXIOS_REQUEST_CONFIG_NAME}?: ${getRequestConfigType()}` : ""}) => ({`);
|
|
3345
|
+
lines.push(`const ${require_generate_utils.getQueryOptionsName(endpoint)} = (${endpointParams ? `{ ${endpointArgs} }: { ${endpointParams} }` : ""}${hasRequestConfigParam ? `${endpointParams ? ", " : ""}${require_generate_utils.AXIOS_REQUEST_CONFIG_NAME}?: ${getRequestConfigType(resolver)}` : ""}) => ({`);
|
|
3317
3346
|
lines.push(` queryKey: keys.${require_generate_utils.getEndpointName(endpoint)}(${endpointArgs}),`);
|
|
3318
3347
|
const requestConfigWithSignal = renderRequestConfigWithSignal(hasRequestConfigParam);
|
|
3319
3348
|
lines.push(` queryFn: ({ signal }: { signal: AbortSignal }) => ${endpointFunction}(${endpointArgs}${hasRequestConfigParam ? `${endpointArgs ? ", " : ""}${requestConfigWithSignal}` : ""}),`);
|
|
@@ -3330,7 +3359,7 @@ function renderInfiniteQueryOptions({ resolver, endpoint, inlineEndpoints }) {
|
|
|
3330
3359
|
const endpointArgsWithPage = renderEndpointArgs(resolver, endpoint, { replacePageParam: true });
|
|
3331
3360
|
const endpointFunction = inlineEndpoints ? require_generate_utils.getEndpointName(endpoint) : require_generate_utils.getImportedEndpointName(endpoint, resolver.options);
|
|
3332
3361
|
const lines = [];
|
|
3333
|
-
lines.push(`const ${require_generate_utils.getInfiniteQueryOptionsName(endpoint)} = (${endpointParams ? `{ ${endpointArgsWithoutPage} }: { ${endpointParams} }` : ""}${hasRequestConfigParam ? `${endpointParams ? ", " : ""}${require_generate_utils.AXIOS_REQUEST_CONFIG_NAME}?: ${getRequestConfigType()}` : ""}) => ({`);
|
|
3362
|
+
lines.push(`const ${require_generate_utils.getInfiniteQueryOptionsName(endpoint)} = (${endpointParams ? `{ ${endpointArgsWithoutPage} }: { ${endpointParams} }` : ""}${hasRequestConfigParam ? `${endpointParams ? ", " : ""}${require_generate_utils.AXIOS_REQUEST_CONFIG_NAME}?: ${getRequestConfigType(resolver)}` : ""}) => ({`);
|
|
3334
3363
|
lines.push(` queryKey: keys.${require_generate_utils.getEndpointName(endpoint)}Infinite(${endpointArgsWithoutPage}),`);
|
|
3335
3364
|
const requestConfigWithSignal = renderRequestConfigWithSignal(hasRequestConfigParam);
|
|
3336
3365
|
lines.push(` queryFn: ({ pageParam, signal }: { pageParam: number; signal: AbortSignal }) => ${endpointFunction}(${endpointArgsWithPage}${hasRequestConfigParam ? `, ${requestConfigWithSignal}` : ""}),`);
|
|
@@ -3347,7 +3376,7 @@ function renderPrefetchQuery({ resolver, endpoint }) {
|
|
|
3347
3376
|
const endpointParams = renderEndpointParams(resolver, endpoint, { modelNamespaceTag: require_generate_utils.getEndpointTag(endpoint, resolver.options) });
|
|
3348
3377
|
const endpointArgs = renderEndpointArgs(resolver, endpoint, {});
|
|
3349
3378
|
const lines = [];
|
|
3350
|
-
lines.push(`export const ${require_generate_utils.getPrefetchQueryName(endpoint)} = (queryClient: QueryClient, ${endpointParams ? `{ ${endpointArgs} }: { ${endpointParams} }, ` : ""}options?: Omit<Parameters<QueryClient["prefetchQuery"]>[0], "queryKey" | "queryFn">, ${hasRequestConfigParam ? `${require_generate_utils.AXIOS_REQUEST_CONFIG_NAME}?: ${require_generate_utils.
|
|
3379
|
+
lines.push(`export const ${require_generate_utils.getPrefetchQueryName(endpoint)} = (queryClient: QueryClient, ${endpointParams ? `{ ${endpointArgs} }: { ${endpointParams} }, ` : ""}options?: Omit<Parameters<QueryClient["prefetchQuery"]>[0], "queryKey" | "queryFn">, ${hasRequestConfigParam ? `${require_generate_utils.AXIOS_REQUEST_CONFIG_NAME}?: ${require_generate_utils.getRequestConfigTypeName(resolver.options.restClient)}, ` : ""}throwOnError = false) => {`);
|
|
3351
3380
|
lines.push(` const queryOptions = { ...${require_generate_utils.getQueryOptionsName(endpoint)}(${endpointParams ? `{ ${endpointArgs} }` : ""}${hasRequestConfigParam ? `${endpointParams ? ", " : ""}${require_generate_utils.AXIOS_REQUEST_CONFIG_NAME}` : ""}), ...options };`);
|
|
3352
3381
|
lines.push(` return throwOnError ? queryClient.fetchQuery(queryOptions) : queryClient.prefetchQuery(queryOptions);`);
|
|
3353
3382
|
lines.push("};");
|
|
@@ -3362,7 +3391,7 @@ function renderPrefetchInfiniteQuery({ resolver, endpoint }) {
|
|
|
3362
3391
|
const endpointArgs = renderEndpointArgs(resolver, endpoint, { excludePageParam: true });
|
|
3363
3392
|
const optionsArgs = `${endpointParams ? `{ ${endpointArgs} }` : ""}${hasRequestConfigParam ? `${endpointParams ? ", " : ""}${require_generate_utils.AXIOS_REQUEST_CONFIG_NAME}` : ""}`;
|
|
3364
3393
|
const lines = [];
|
|
3365
|
-
lines.push(`export const ${require_generate_utils.getPrefetchInfiniteQueryName(endpoint)} = (queryClient: QueryClient, ${endpointParams ? `{ ${endpointArgs} }: { ${endpointParams} }, ` : ""}options?: Omit<Parameters<QueryClient["prefetchInfiniteQuery"]>[0], "queryKey" | "queryFn" | "initialPageParam" | "getNextPageParam">, ${hasRequestConfigParam ? `${require_generate_utils.AXIOS_REQUEST_CONFIG_NAME}?: ${require_generate_utils.
|
|
3394
|
+
lines.push(`export const ${require_generate_utils.getPrefetchInfiniteQueryName(endpoint)} = (queryClient: QueryClient, ${endpointParams ? `{ ${endpointArgs} }: { ${endpointParams} }, ` : ""}options?: Omit<Parameters<QueryClient["prefetchInfiniteQuery"]>[0], "queryKey" | "queryFn" | "initialPageParam" | "getNextPageParam">, ${hasRequestConfigParam ? `${require_generate_utils.AXIOS_REQUEST_CONFIG_NAME}?: ${require_generate_utils.getRequestConfigTypeName(resolver.options.restClient)}, ` : ""}throwOnError = false) => {`);
|
|
3366
3395
|
lines.push(` const queryOptions = { ...${require_generate_utils.getInfiniteQueryOptionsName(endpoint)}(${optionsArgs}), ...(options as {}) };`);
|
|
3367
3396
|
lines.push(` return throwOnError ? queryClient.fetchInfiniteQuery(queryOptions) : queryClient.prefetchInfiniteQuery(queryOptions);`);
|
|
3368
3397
|
lines.push("};");
|
|
@@ -3391,7 +3420,7 @@ function renderQuery({ resolver, endpoint, inlineEndpoints }) {
|
|
|
3391
3420
|
mode: "query",
|
|
3392
3421
|
tag
|
|
3393
3422
|
}));
|
|
3394
|
-
lines.push(`export const ${require_generate_utils.getQueryName(endpoint)} = <TData>(${endpointParams ? `{ ${endpointArgs} }: { ${endpointParams} }, ` : ""}options?: AppQueryOptions<typeof ${inlineEndpoints ? require_generate_utils.getEndpointName(endpoint) : require_generate_utils.getImportedEndpointName(endpoint, resolver.options)}, TData>${hasAxiosRequestConfig ? `, ${require_generate_utils.AXIOS_REQUEST_CONFIG_NAME}?: ${require_generate_utils.
|
|
3423
|
+
lines.push(`export const ${require_generate_utils.getQueryName(endpoint)} = <TData>(${endpointParams ? `{ ${endpointArgs} }: { ${endpointParams} }, ` : ""}options?: AppQueryOptions<typeof ${inlineEndpoints ? require_generate_utils.getEndpointName(endpoint) : require_generate_utils.getImportedEndpointName(endpoint, resolver.options)}, TData>${hasAxiosRequestConfig ? `, ${require_generate_utils.AXIOS_REQUEST_CONFIG_NAME}?: ${require_generate_utils.getRequestConfigTypeName(resolver.options.restClient)}` : ""}) => {`);
|
|
3395
3424
|
lines.push(" const queryConfig = OpenApiQueryConfig.useConfig();");
|
|
3396
3425
|
if (hasAclCheck) lines.push(` const { checkAcl } = ${require_generate_utils.ACL_CHECK_HOOK}();`);
|
|
3397
3426
|
lines.push(...renderWorkspaceParamResolutions({
|
|
@@ -3461,7 +3490,7 @@ function renderMutation({ resolver, endpoint, inlineEndpoints, precomputed }) {
|
|
|
3461
3490
|
mode: "mutation",
|
|
3462
3491
|
tag
|
|
3463
3492
|
}));
|
|
3464
|
-
lines.push(`export const ${require_generate_utils.getQueryName(endpoint, true)} = (${pathParamFirstArg}options?: AppMutationOptions<typeof ${endpointFunction}${mutationOptionsTypeArg}>${hasMutationEffects ? ` & ${require_generate_utils.MUTATION_EFFECTS.optionsType}` : ""}${hasAxiosRequestConfig ? `, ${require_generate_utils.AXIOS_REQUEST_CONFIG_NAME}?: ${require_generate_utils.
|
|
3493
|
+
lines.push(`export const ${require_generate_utils.getQueryName(endpoint, true)} = (${pathParamFirstArg}options?: AppMutationOptions<typeof ${endpointFunction}${mutationOptionsTypeArg}>${hasMutationEffects ? ` & ${require_generate_utils.MUTATION_EFFECTS.optionsType}` : ""}${hasAxiosRequestConfig ? `, ${require_generate_utils.AXIOS_REQUEST_CONFIG_NAME}?: ${require_generate_utils.getRequestConfigTypeName(resolver.options.restClient)}` : ""}) => {`);
|
|
3465
3494
|
if (hasMutationDefaultOnError) lines.push(" const queryConfig = OpenApiQueryConfig.useConfig();");
|
|
3466
3495
|
if (hasAclCheck) lines.push(` const { checkAcl } = ${require_generate_utils.ACL_CHECK_HOOK}();`);
|
|
3467
3496
|
lines.push(...renderWorkspaceContextDestructure({
|
|
@@ -3580,7 +3609,7 @@ function renderInfiniteQuery({ resolver, endpoint, inlineEndpoints }) {
|
|
|
3580
3609
|
mode: "infiniteQuery",
|
|
3581
3610
|
tag
|
|
3582
3611
|
}));
|
|
3583
|
-
lines.push(`export const ${require_generate_utils.getInfiniteQueryName(endpoint)} = <TData>(${endpointParams ? `{ ${endpointArgsWithoutPage} }: { ${endpointParams} }, ` : ""}options?: AppInfiniteQueryOptions<typeof ${inlineEndpoints ? require_generate_utils.getEndpointName(endpoint) : require_generate_utils.getImportedEndpointName(endpoint, resolver.options)}, TData>${hasAxiosRequestConfig ? `, ${require_generate_utils.AXIOS_REQUEST_CONFIG_NAME}?: ${require_generate_utils.
|
|
3612
|
+
lines.push(`export const ${require_generate_utils.getInfiniteQueryName(endpoint)} = <TData>(${endpointParams ? `{ ${endpointArgsWithoutPage} }: { ${endpointParams} }, ` : ""}options?: AppInfiniteQueryOptions<typeof ${inlineEndpoints ? require_generate_utils.getEndpointName(endpoint) : require_generate_utils.getImportedEndpointName(endpoint, resolver.options)}, TData>${hasAxiosRequestConfig ? `, ${require_generate_utils.AXIOS_REQUEST_CONFIG_NAME}?: ${require_generate_utils.getRequestConfigTypeName(resolver.options.restClient)}` : ""}) => {`);
|
|
3584
3613
|
lines.push(" const queryConfig = OpenApiQueryConfig.useConfig();");
|
|
3585
3614
|
if (hasAclCheck) lines.push(` const { checkAcl } = ${require_generate_utils.ACL_CHECK_HOOK}();`);
|
|
3586
3615
|
lines.push(...renderWorkspaceParamResolutions({
|
|
@@ -3605,9 +3634,10 @@ function renderInfiniteQuery({ resolver, endpoint, inlineEndpoints }) {
|
|
|
3605
3634
|
//#endregion
|
|
3606
3635
|
//#region src/generators/generate/generateAppRestClient.ts
|
|
3607
3636
|
function generateAppRestClient(resolver) {
|
|
3608
|
-
|
|
3637
|
+
const clientName = resolver.options.restClient === "native" ? "NativeRestClient" : "RestClient";
|
|
3638
|
+
return `import { ${clientName} } from "${resolver.options.restClient === "native" ? require_generate_utils.NATIVE_PACKAGE_IMPORT_PATH : require_generate_utils.PACKAGE_IMPORT_PATH}";
|
|
3609
3639
|
|
|
3610
|
-
export const ${require_generate_utils.APP_REST_CLIENT_NAME} = new
|
|
3640
|
+
export const ${require_generate_utils.APP_REST_CLIENT_NAME} = new ${clientName}({
|
|
3611
3641
|
config: {
|
|
3612
3642
|
baseURL: "${resolver.getBaseUrl()}"
|
|
3613
3643
|
},
|