@povio/openapi-codegen-cli 3.2.0-rc.5 → 3.2.0-rc.6
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-DVcx7AGc.mjs} +15 -8
- package/dist/{generate.utils-1rU0zIjA.cjs → generate.utils-CH2U2Dpr.cjs} +36 -5
- package/dist/{generateCodeFromOpenAPIDoc-5VZFVFK1.cjs → generateCodeFromOpenAPIDoc-D5lsVuPN.cjs} +48 -24
- package/dist/{generateCodeFromOpenAPIDoc-BOuCcW6U.mjs → generateCodeFromOpenAPIDoc-eAxTI0c4.mjs} +49 -25
- package/dist/generator.d.mts +1 -1
- package/dist/generator.mjs +3 -3
- package/dist/{getDataFromOpenAPIDoc-CkIfezoI.mjs → getDataFromOpenAPIDoc-BnQYK4sW.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-D7ZTawpO.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-eAxTI0c4.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-D5lsVuPN.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,20 @@ 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
|
+
};
|
|
2408
2414
|
const endpointsImports = require_generate_utils.getEndpointsImports({
|
|
2409
2415
|
tag,
|
|
2410
2416
|
endpoints,
|
|
@@ -2444,6 +2450,7 @@ function generateConfigs(generateTypeParams) {
|
|
|
2444
2450
|
};
|
|
2445
2451
|
const lines = [];
|
|
2446
2452
|
if (hasAxiosImport) lines.push(renderImport$3(axiosImport));
|
|
2453
|
+
if (nativeImport.typeBindings?.length) lines.push(renderImport$3(nativeImport));
|
|
2447
2454
|
if (hasZodImport) lines.push(renderImport$3(require_generate_utils.ZOD_IMPORT));
|
|
2448
2455
|
if (hasDynamicInputsImport) lines.push(renderImport$3(dynamicInputsImport));
|
|
2449
2456
|
if (hasDynamicColumnsImport) lines.push(renderImport$3(dynamicColumnsImport));
|
|
@@ -2519,7 +2526,7 @@ function renderMutationContent(resolver, endpoint, tag) {
|
|
|
2519
2526
|
const endpointFunction = require_generate_utils.getImportedEndpointName(endpoint, resolver.options);
|
|
2520
2527
|
const mutationVariablesType = endpoint.mediaUpload ? `{ ${endpointParamsStr}${endpointParamsStr ? "; " : ""}abortController?: AbortController; onUploadProgress?: (progress: { loaded: number; total: number }) => void }` : `{ ${endpointParamsStr} }`;
|
|
2521
2528
|
const lines = [];
|
|
2522
|
-
lines.push(`(options?: AppMutationOptions<typeof ${endpointFunction}, ${mutationVariablesType}>${hasMutationEffects ? ` & ${require_generate_utils.MUTATION_EFFECTS.optionsType}` : ""}${hasAxiosRequestConfig ? `, config?: ${require_generate_utils.
|
|
2529
|
+
lines.push(`(options?: AppMutationOptions<typeof ${endpointFunction}, ${mutationVariablesType}>${hasMutationEffects ? ` & ${require_generate_utils.MUTATION_EFFECTS.optionsType}` : ""}${hasAxiosRequestConfig ? `, config?: ${require_generate_utils.getRequestConfigTypeName(resolver.options.restClient)}` : ""}) => {`);
|
|
2523
2530
|
if (hasMutationDefaultOnError) lines.push(" const queryConfig = OpenApiQueryConfig.useConfig();");
|
|
2524
2531
|
if (hasMutationEffects) lines.push(` const { runMutationEffects } = useMutationEffects<${require_generate_utils.QUERY_MODULE_ENUM}.${endpointTag}>({ currentModule: ${require_generate_utils.QUERY_MODULE_ENUM}.${tag} });`);
|
|
2525
2532
|
if (hasAclCheck) lines.push(` const { checkAcl } = ${require_generate_utils.ACL_CHECK_HOOK}();`);
|
|
@@ -2621,12 +2628,18 @@ function generateEndpoints({ resolver, data, tag }) {
|
|
|
2621
2628
|
};
|
|
2622
2629
|
const hasAxiosRequestConfig = resolver.options.axiosRequestConfig;
|
|
2623
2630
|
const hasGetEndpoints = endpoints.some((endpoint) => endpoint.method === "get");
|
|
2624
|
-
const
|
|
2631
|
+
const nativeClient = resolver.options.restClient === "native";
|
|
2632
|
+
const hasAxiosImport = !nativeClient && (hasAxiosRequestConfig || hasGetEndpoints);
|
|
2625
2633
|
const axiosImport = {
|
|
2626
2634
|
bindings: [],
|
|
2627
2635
|
typeBindings: hasAxiosImport ? [require_generate_utils.AXIOS_REQUEST_CONFIG_TYPE] : [],
|
|
2628
2636
|
from: require_generate_utils.AXIOS_IMPORT.from
|
|
2629
2637
|
};
|
|
2638
|
+
const nativeImport = {
|
|
2639
|
+
bindings: [],
|
|
2640
|
+
typeBindings: nativeClient && (hasAxiosRequestConfig || hasGetEndpoints) ? [require_generate_utils.getRequestConfigTypeName("native")] : [],
|
|
2641
|
+
from: require_generate_utils.REST_PACKAGE_IMPORT_PATH
|
|
2642
|
+
};
|
|
2630
2643
|
const generateParse = resolver.options.parseRequestParams;
|
|
2631
2644
|
const endpointParams = endpoints.flatMap((endpoint) => endpoint.parameters);
|
|
2632
2645
|
const endpointParamsParseSchemas = endpointParams.filter((param) => !["Path", "Header"].includes(param.type)).map((param) => param.parameterSortingEnumSchemaName ?? param.zodSchema);
|
|
@@ -2647,6 +2660,7 @@ function generateEndpoints({ resolver, data, tag }) {
|
|
|
2647
2660
|
const lines = [];
|
|
2648
2661
|
lines.push(renderImport$2(appRestClientImport));
|
|
2649
2662
|
if (hasAxiosImport) lines.push(renderImport$2(axiosImport));
|
|
2663
|
+
if (nativeImport.typeBindings?.length) lines.push(renderImport$2(nativeImport));
|
|
2650
2664
|
if (hasZodImport) lines.push(renderImport$2(require_generate_utils.ZOD_IMPORT));
|
|
2651
2665
|
if (hasZodExtendedImport) lines.push(renderImport$2(zodExtendedImport));
|
|
2652
2666
|
for (const modelsImport of modelsImports) lines.push(renderImport$2(modelsImport));
|
|
@@ -2664,7 +2678,7 @@ function generateEndpoints({ resolver, data, tag }) {
|
|
|
2664
2678
|
const hasUndefinedEndpointBody = require_generate_utils.requiresBody(endpoint) && !endpointBody && require_generate_utils.hasEndpointConfig(endpoint, resolver);
|
|
2665
2679
|
const endpointConfig = renderEndpointConfig(resolver, endpoint, tag);
|
|
2666
2680
|
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()}` : ""}) => {`);
|
|
2681
|
+
lines.push(`export const ${require_generate_utils.getEndpointName(endpoint)} = (${endpointParams}${hasRequestConfigParam ? `${require_generate_utils.AXIOS_REQUEST_CONFIG_NAME}?: ${getRequestConfigType$1(resolver)}` : ""}) => {`);
|
|
2668
2682
|
lines.push(` return ${require_generate_utils.APP_REST_CLIENT_NAME}.${endpoint.method}(`);
|
|
2669
2683
|
lines.push(` ${renderRequestInfo(resolver, endpoint, tag)},`);
|
|
2670
2684
|
lines.push(` \`${require_generate_utils.getEndpointPath(endpoint)}\`,`);
|
|
@@ -2680,8 +2694,8 @@ function generateEndpoints({ resolver, data, tag }) {
|
|
|
2680
2694
|
function renderRequestInfo(resolver, endpoint, tag) {
|
|
2681
2695
|
return `{ resSchema: ${require_generate_utils.getImportedZodSchemaName(resolver, endpoint.response, (resolver.options.modelsInCommon || resolver.options.modelsInModules) && resolver.options.splitByTags ? tag : void 0)} }`;
|
|
2682
2696
|
}
|
|
2683
|
-
function getRequestConfigType$1() {
|
|
2684
|
-
return `${require_generate_utils.
|
|
2697
|
+
function getRequestConfigType$1(resolver) {
|
|
2698
|
+
return `${require_generate_utils.getRequestConfigTypeName(resolver.options.restClient)} & { allowInvalidResponseData?: boolean }`;
|
|
2685
2699
|
}
|
|
2686
2700
|
function renderImport$2(importData) {
|
|
2687
2701
|
const namedImports = [...importData.bindings, ...(importData.typeBindings ?? []).map((binding) => importData.typeOnly ? binding : `type ${binding}`)];
|
|
@@ -2892,15 +2906,22 @@ function generateQueries(params) {
|
|
|
2892
2906
|
if (!endpoints || endpoints.length === 0) return;
|
|
2893
2907
|
const endpointGroups = groupEndpoints(endpoints, resolver);
|
|
2894
2908
|
const hasAxiosRequestConfig = resolver.options.axiosRequestConfig;
|
|
2895
|
-
const
|
|
2909
|
+
const nativeClient = resolver.options.restClient === "native";
|
|
2910
|
+
const requestConfigType = require_generate_utils.getRequestConfigTypeName(resolver.options.restClient);
|
|
2911
|
+
const hasAxiosDefaultImport = !nativeClient && endpoints.some(({ mediaUpload }) => mediaUpload);
|
|
2896
2912
|
const hasGetEndpoints = endpoints.some((endpoint) => endpoint.method === "get");
|
|
2897
|
-
const hasAxiosImport = hasAxiosRequestConfig || hasAxiosDefaultImport || hasGetEndpoints;
|
|
2913
|
+
const hasAxiosImport = !nativeClient && (hasAxiosRequestConfig || hasAxiosDefaultImport || hasGetEndpoints);
|
|
2898
2914
|
const axiosImport = {
|
|
2899
2915
|
defaultImport: hasAxiosDefaultImport ? require_generate_utils.AXIOS_DEFAULT_IMPORT_NAME : void 0,
|
|
2900
2916
|
bindings: [],
|
|
2901
2917
|
typeBindings: hasAxiosImport ? [require_generate_utils.AXIOS_REQUEST_CONFIG_TYPE] : [],
|
|
2902
2918
|
from: require_generate_utils.AXIOS_IMPORT.from
|
|
2903
2919
|
};
|
|
2920
|
+
const nativeTransportImport = {
|
|
2921
|
+
bindings: [],
|
|
2922
|
+
typeBindings: nativeClient ? [...hasAxiosRequestConfig || hasGetEndpoints ? [requestConfigType] : [], ...endpoints.some(({ mediaDownload }) => mediaDownload) ? [require_generate_utils.NATIVE_RESPONSE_TYPE] : []] : [],
|
|
2923
|
+
from: require_generate_utils.REST_PACKAGE_IMPORT_PATH
|
|
2924
|
+
};
|
|
2904
2925
|
const { queryEndpoints, infiniteQueryEndpoints, mutationEndpoints, aclEndpoints } = endpointGroups;
|
|
2905
2926
|
const hasMutationDefaultOnError = resolver.options.mutationDefaultOnError && mutationEndpoints.length > 0;
|
|
2906
2927
|
const queryImport = {
|
|
@@ -2979,6 +3000,7 @@ function generateQueries(params) {
|
|
|
2979
3000
|
});
|
|
2980
3001
|
const lines = [];
|
|
2981
3002
|
if (hasAxiosImport) lines.push(renderImport(axiosImport));
|
|
3003
|
+
if (nativeTransportImport.typeBindings?.length) lines.push(renderImport(nativeTransportImport));
|
|
2982
3004
|
if (inlineEndpoints) {
|
|
2983
3005
|
lines.push(renderImport(appRestClientImport));
|
|
2984
3006
|
if (hasZodImport) lines.push(renderImport(require_generate_utils.ZOD_IMPORT));
|
|
@@ -3211,8 +3233,9 @@ function renderQueryJsDocs({ resolver, endpoint, mode, tag }) {
|
|
|
3211
3233
|
if (mode === "query") lines.push(" * @param { AppQueryOptions } options Query options");
|
|
3212
3234
|
else if (mode === "mutation") lines.push(` * @param { AppMutationOptions${resolver.options.mutationEffects ? ` & ${require_generate_utils.MUTATION_EFFECTS.optionsType}` : ""} } options Mutation options`);
|
|
3213
3235
|
else lines.push(" * @param { AppInfiniteQueryOptions } options Infinite query options");
|
|
3214
|
-
const
|
|
3215
|
-
const
|
|
3236
|
+
const withRawResponse = endpoint.mediaDownload && mode !== "infiniteQuery";
|
|
3237
|
+
const responseType = resolver.options.restClient === "native" ? require_generate_utils.NATIVE_RESPONSE_TYPE : "AxiosResponse";
|
|
3238
|
+
const resultType = `${withRawResponse ? `${responseType}<` : ""}${require_generate_utils.getImportedZodSchemaInferedTypeName(resolver, endpoint.response, void 0, tag)}${withRawResponse ? ">" : ""}`;
|
|
3216
3239
|
if (mode === "query") lines.push(` * @returns { UseQueryResult<${resultType}> } ${endpoint.responseDescription ?? ""}`);
|
|
3217
3240
|
else if (mode === "mutation") lines.push(` * @returns { UseMutationResult<${resultType}> } ${endpoint.responseDescription ?? ""}`);
|
|
3218
3241
|
else lines.push(` * @returns { UseInfiniteQueryResult<${resultType}> } ${endpoint.responseDescription ?? ""}`);
|
|
@@ -3247,7 +3270,7 @@ function renderInlineEndpoints({ resolver, endpoints, tag }) {
|
|
|
3247
3270
|
const hasUndefinedEndpointBody = require_generate_utils.requiresBody(endpoint) && !endpointBody && require_generate_utils.hasEndpointConfig(endpoint, resolver);
|
|
3248
3271
|
const endpointConfig = renderInlineEndpointConfig(resolver, endpoint, tag);
|
|
3249
3272
|
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()}` : ""}) => {`);
|
|
3273
|
+
lines.push(`const ${require_generate_utils.getEndpointName(endpoint)} = (${endpointParams}${hasRequestConfigParam ? `${endpointParams ? ", " : ""}${require_generate_utils.AXIOS_REQUEST_CONFIG_NAME}?: ${getRequestConfigType(resolver)}` : ""}) => {`);
|
|
3251
3274
|
lines.push(` return ${require_generate_utils.APP_REST_CLIENT_NAME}.${endpoint.method}(`);
|
|
3252
3275
|
lines.push(` ${renderInlineRequestInfo(resolver, endpoint, tag)},`);
|
|
3253
3276
|
lines.push(` \`${require_generate_utils.getEndpointPath(endpoint)}\`,`);
|
|
@@ -3263,8 +3286,8 @@ function renderInlineEndpoints({ resolver, endpoints, tag }) {
|
|
|
3263
3286
|
function renderInlineRequestInfo(resolver, endpoint, tag) {
|
|
3264
3287
|
return `{ resSchema: ${require_generate_utils.getImportedZodSchemaName(resolver, endpoint.response, tag)} }`;
|
|
3265
3288
|
}
|
|
3266
|
-
function getRequestConfigType() {
|
|
3267
|
-
return `${require_generate_utils.
|
|
3289
|
+
function getRequestConfigType(resolver) {
|
|
3290
|
+
return `${require_generate_utils.getRequestConfigTypeName(resolver.options.restClient)} & { allowInvalidResponseData?: boolean }`;
|
|
3268
3291
|
}
|
|
3269
3292
|
function renderRequestConfigWithSignal(hasRequestConfigParam) {
|
|
3270
3293
|
return `{ ${hasRequestConfigParam ? `...${require_generate_utils.AXIOS_REQUEST_CONFIG_NAME}, ` : ""}signal }`;
|
|
@@ -3313,7 +3336,7 @@ function renderQueryOptions({ resolver, endpoint, inlineEndpoints }) {
|
|
|
3313
3336
|
const endpointArgs = renderEndpointArgs(resolver, endpoint, {});
|
|
3314
3337
|
const endpointFunction = inlineEndpoints ? require_generate_utils.getEndpointName(endpoint) : require_generate_utils.getImportedEndpointName(endpoint, resolver.options);
|
|
3315
3338
|
const lines = [];
|
|
3316
|
-
lines.push(`const ${require_generate_utils.getQueryOptionsName(endpoint)} = (${endpointParams ? `{ ${endpointArgs} }: { ${endpointParams} }` : ""}${hasRequestConfigParam ? `${endpointParams ? ", " : ""}${require_generate_utils.AXIOS_REQUEST_CONFIG_NAME}?: ${getRequestConfigType()}` : ""}) => ({`);
|
|
3339
|
+
lines.push(`const ${require_generate_utils.getQueryOptionsName(endpoint)} = (${endpointParams ? `{ ${endpointArgs} }: { ${endpointParams} }` : ""}${hasRequestConfigParam ? `${endpointParams ? ", " : ""}${require_generate_utils.AXIOS_REQUEST_CONFIG_NAME}?: ${getRequestConfigType(resolver)}` : ""}) => ({`);
|
|
3317
3340
|
lines.push(` queryKey: keys.${require_generate_utils.getEndpointName(endpoint)}(${endpointArgs}),`);
|
|
3318
3341
|
const requestConfigWithSignal = renderRequestConfigWithSignal(hasRequestConfigParam);
|
|
3319
3342
|
lines.push(` queryFn: ({ signal }: { signal: AbortSignal }) => ${endpointFunction}(${endpointArgs}${hasRequestConfigParam ? `${endpointArgs ? ", " : ""}${requestConfigWithSignal}` : ""}),`);
|
|
@@ -3330,7 +3353,7 @@ function renderInfiniteQueryOptions({ resolver, endpoint, inlineEndpoints }) {
|
|
|
3330
3353
|
const endpointArgsWithPage = renderEndpointArgs(resolver, endpoint, { replacePageParam: true });
|
|
3331
3354
|
const endpointFunction = inlineEndpoints ? require_generate_utils.getEndpointName(endpoint) : require_generate_utils.getImportedEndpointName(endpoint, resolver.options);
|
|
3332
3355
|
const lines = [];
|
|
3333
|
-
lines.push(`const ${require_generate_utils.getInfiniteQueryOptionsName(endpoint)} = (${endpointParams ? `{ ${endpointArgsWithoutPage} }: { ${endpointParams} }` : ""}${hasRequestConfigParam ? `${endpointParams ? ", " : ""}${require_generate_utils.AXIOS_REQUEST_CONFIG_NAME}?: ${getRequestConfigType()}` : ""}) => ({`);
|
|
3356
|
+
lines.push(`const ${require_generate_utils.getInfiniteQueryOptionsName(endpoint)} = (${endpointParams ? `{ ${endpointArgsWithoutPage} }: { ${endpointParams} }` : ""}${hasRequestConfigParam ? `${endpointParams ? ", " : ""}${require_generate_utils.AXIOS_REQUEST_CONFIG_NAME}?: ${getRequestConfigType(resolver)}` : ""}) => ({`);
|
|
3334
3357
|
lines.push(` queryKey: keys.${require_generate_utils.getEndpointName(endpoint)}Infinite(${endpointArgsWithoutPage}),`);
|
|
3335
3358
|
const requestConfigWithSignal = renderRequestConfigWithSignal(hasRequestConfigParam);
|
|
3336
3359
|
lines.push(` queryFn: ({ pageParam, signal }: { pageParam: number; signal: AbortSignal }) => ${endpointFunction}(${endpointArgsWithPage}${hasRequestConfigParam ? `, ${requestConfigWithSignal}` : ""}),`);
|
|
@@ -3347,7 +3370,7 @@ function renderPrefetchQuery({ resolver, endpoint }) {
|
|
|
3347
3370
|
const endpointParams = renderEndpointParams(resolver, endpoint, { modelNamespaceTag: require_generate_utils.getEndpointTag(endpoint, resolver.options) });
|
|
3348
3371
|
const endpointArgs = renderEndpointArgs(resolver, endpoint, {});
|
|
3349
3372
|
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.
|
|
3373
|
+
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
3374
|
lines.push(` const queryOptions = { ...${require_generate_utils.getQueryOptionsName(endpoint)}(${endpointParams ? `{ ${endpointArgs} }` : ""}${hasRequestConfigParam ? `${endpointParams ? ", " : ""}${require_generate_utils.AXIOS_REQUEST_CONFIG_NAME}` : ""}), ...options };`);
|
|
3352
3375
|
lines.push(` return throwOnError ? queryClient.fetchQuery(queryOptions) : queryClient.prefetchQuery(queryOptions);`);
|
|
3353
3376
|
lines.push("};");
|
|
@@ -3362,7 +3385,7 @@ function renderPrefetchInfiniteQuery({ resolver, endpoint }) {
|
|
|
3362
3385
|
const endpointArgs = renderEndpointArgs(resolver, endpoint, { excludePageParam: true });
|
|
3363
3386
|
const optionsArgs = `${endpointParams ? `{ ${endpointArgs} }` : ""}${hasRequestConfigParam ? `${endpointParams ? ", " : ""}${require_generate_utils.AXIOS_REQUEST_CONFIG_NAME}` : ""}`;
|
|
3364
3387
|
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.
|
|
3388
|
+
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
3389
|
lines.push(` const queryOptions = { ...${require_generate_utils.getInfiniteQueryOptionsName(endpoint)}(${optionsArgs}), ...(options as {}) };`);
|
|
3367
3390
|
lines.push(` return throwOnError ? queryClient.fetchInfiniteQuery(queryOptions) : queryClient.prefetchInfiniteQuery(queryOptions);`);
|
|
3368
3391
|
lines.push("};");
|
|
@@ -3391,7 +3414,7 @@ function renderQuery({ resolver, endpoint, inlineEndpoints }) {
|
|
|
3391
3414
|
mode: "query",
|
|
3392
3415
|
tag
|
|
3393
3416
|
}));
|
|
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.
|
|
3417
|
+
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
3418
|
lines.push(" const queryConfig = OpenApiQueryConfig.useConfig();");
|
|
3396
3419
|
if (hasAclCheck) lines.push(` const { checkAcl } = ${require_generate_utils.ACL_CHECK_HOOK}();`);
|
|
3397
3420
|
lines.push(...renderWorkspaceParamResolutions({
|
|
@@ -3461,7 +3484,7 @@ function renderMutation({ resolver, endpoint, inlineEndpoints, precomputed }) {
|
|
|
3461
3484
|
mode: "mutation",
|
|
3462
3485
|
tag
|
|
3463
3486
|
}));
|
|
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.
|
|
3487
|
+
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
3488
|
if (hasMutationDefaultOnError) lines.push(" const queryConfig = OpenApiQueryConfig.useConfig();");
|
|
3466
3489
|
if (hasAclCheck) lines.push(` const { checkAcl } = ${require_generate_utils.ACL_CHECK_HOOK}();`);
|
|
3467
3490
|
lines.push(...renderWorkspaceContextDestructure({
|
|
@@ -3580,7 +3603,7 @@ function renderInfiniteQuery({ resolver, endpoint, inlineEndpoints }) {
|
|
|
3580
3603
|
mode: "infiniteQuery",
|
|
3581
3604
|
tag
|
|
3582
3605
|
}));
|
|
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.
|
|
3606
|
+
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
3607
|
lines.push(" const queryConfig = OpenApiQueryConfig.useConfig();");
|
|
3585
3608
|
if (hasAclCheck) lines.push(` const { checkAcl } = ${require_generate_utils.ACL_CHECK_HOOK}();`);
|
|
3586
3609
|
lines.push(...renderWorkspaceParamResolutions({
|
|
@@ -3605,9 +3628,10 @@ function renderInfiniteQuery({ resolver, endpoint, inlineEndpoints }) {
|
|
|
3605
3628
|
//#endregion
|
|
3606
3629
|
//#region src/generators/generate/generateAppRestClient.ts
|
|
3607
3630
|
function generateAppRestClient(resolver) {
|
|
3608
|
-
|
|
3631
|
+
const clientName = resolver.options.restClient === "native" ? "NativeRestClient" : "RestClient";
|
|
3632
|
+
return `import { ${clientName} } from "${resolver.options.restClient === "native" ? require_generate_utils.NATIVE_PACKAGE_IMPORT_PATH : require_generate_utils.PACKAGE_IMPORT_PATH}";
|
|
3609
3633
|
|
|
3610
|
-
export const ${require_generate_utils.APP_REST_CLIENT_NAME} = new
|
|
3634
|
+
export const ${require_generate_utils.APP_REST_CLIENT_NAME} = new ${clientName}({
|
|
3611
3635
|
config: {
|
|
3612
3636
|
baseURL: "${resolver.getBaseUrl()}"
|
|
3613
3637
|
},
|