@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/dist/{generateCodeFromOpenAPIDoc-BOuCcW6U.mjs → generateCodeFromOpenAPIDoc-glAKBEGP.mjs}
RENAMED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { r as getZodSchemaRefs, t as getDataFromOpenAPIDoc } from "./getDataFromOpenAPIDoc-
|
|
2
|
-
import { $ as getImportedAbilityFunctionName,
|
|
1
|
+
import { r as getZodSchemaRefs, t as getDataFromOpenAPIDoc } from "./getDataFromOpenAPIDoc-7RxjULpB.mjs";
|
|
2
|
+
import { $ as getImportedAbilityFunctionName, A as getEndpointsImports, An as AXIOS_REQUEST_CONFIG_NAME, B as getPrefetchInfiniteQueryName, Bn as shouldInlineEndpointsForTag, Bt as QUERY_MODULE_ENUM, C as getAppRestClientImportPath, Ct as isReadEndpoint, D as getTagFileName, Dn as ZOD_IMPORT, E as getQueryTypesImportPath, F as mergeImports, Fn as getRequestConfigTypeName, Ft as APP_REST_CLIENT_NAME, G as getAbilityConditionType, Gn as kebabToCamel, Gt as REST_PACKAGE_IMPORT_PATH, H as getQueryName, Hn as capitalize, Ht as ZOD_EXTENDED, I as getImportedInfiniteQueryName, It as BUILDERS_UTILS, J as getAbilityFunctionName, Jn as Profiler, K as getAbilityConditionsTypes, Kt as getNamespaceName, L as getImportedQueryName, Ln as getEndpointTag, Lt as DOMAIN_ERRORS_FILE, M as getInfiniteQueriesImports, Mt as isEnumZodSchema, N as getModelsImports, Nn as JSON_APPLICATION_FORMAT, Nt as isNamedZodSchema, O as getTagImportPath, On as AXIOS_DEFAULT_IMPORT_NAME, P as getQueriesImports, Pn as NATIVE_RESPONSE_TYPE, Pt as APP_REST_CLIENT_FILE, Q as getAppAbilitiesType, R as getInfiniteQueryName, Rt as MUTATION_EFFECTS, St as isReadAllEndpoint, T as getQueryModulesImportPath, Tt as invalidVariableNameCharactersToCamel, U as getQueryOptionsName, Ut as NATIVE_PACKAGE_IMPORT_PATH, V as getPrefetchQueryName, Vn as camelToSpaceSeparated, Vt as QUERY_OPTIONS_TYPES, W as getAbilityAction, Wt as PACKAGE_IMPORT_PATH, X as getAbilitySubjectTypes, Y as getAbilitySubject, Z as getAclData, _ as hasEndpointConfig, _t as getPathSegments, at as getZodSchemaInferedTypeName, b as requiresBody, bt as isDeleteEndpoint, c as getDestructuredVariables, ct as getSchemaDescriptions, d as isQuery, dt as DEFAULT_GENERATE_OPTIONS, et as hasAbilityConditions, f as getEndpointBody, fn as isReferenceObject, ft as ACL_APP_ABILITIES, g as getImportedEndpointName, gn as ANY_SCHEMA, gt as CASL_ABILITY_IMPORT, h as getEndpointPath, ht as CASL_ABILITY_BINDING, i as shouldUseNativeCodegen, it as getZodSchemaDescription, j as getImportPath, jn as AXIOS_REQUEST_CONFIG_TYPE, k as getAclImports, kn as AXIOS_IMPORT, l as isInfiniteQuery, m as getEndpointName, mt as ACL_CHECK_HOOK, nt as getImportedZodSchemaInferedTypeName, o as getOutputFileName, ot as getZodSchemaPropertyDescriptions, p as getEndpointConfig, pn as isSchemaObject, pt as ACL_APP_ABILITY_FILE, q as getAbilityDescription, r as compileNativeData, rt as getImportedZodSchemaName, st as getZodSchemaType, tn as isParamMediaTypeAllowed, tt as renderAclCheckCall, u as isMutation, ut as getUniqueArray, v as mapEndpointParamsToFunctionParams, vt as isBulkDeleteEndpoint, w as getFileNameWithExtension, wt as isUpdateEndpoint, xt as isPathSegmentParam, y as renderMediaUploadMutationBody, yt as isCreateEndpoint, z as getInfiniteQueryOptionsName, zt as QUERY_MODULES_FILE } from "./generate.runner-BvSprH6D.mjs";
|
|
3
3
|
import "node:module";
|
|
4
4
|
//#region \0rolldown/runtime.js
|
|
5
5
|
var __defProp = Object.defineProperty;
|
|
@@ -419,14 +419,24 @@ function generateConfigs(generateTypeParams) {
|
|
|
419
419
|
const hasMutationEffects = resolver.options.mutationEffects && hasMutation;
|
|
420
420
|
const hasMutationDefaultOnError = resolver.options.mutationDefaultOnError && hasMutation;
|
|
421
421
|
const hasAxiosRequestConfig = resolver.options.axiosRequestConfig;
|
|
422
|
-
const
|
|
423
|
-
const
|
|
422
|
+
const nativeClient = resolver.options.restClient === "native";
|
|
423
|
+
const hasAxiosDefaultImport = !nativeClient && endpoints.some((e) => e.mediaUpload);
|
|
424
|
+
const hasAxiosImport = !nativeClient && (hasAxiosRequestConfig || hasAxiosDefaultImport);
|
|
424
425
|
const axiosImport = {
|
|
425
426
|
defaultImport: hasAxiosDefaultImport ? AXIOS_DEFAULT_IMPORT_NAME : void 0,
|
|
426
427
|
bindings: [],
|
|
427
428
|
typeBindings: hasAxiosImport ? [AXIOS_REQUEST_CONFIG_TYPE] : [],
|
|
428
429
|
from: "axios"
|
|
429
430
|
};
|
|
431
|
+
const nativeImport = {
|
|
432
|
+
bindings: [],
|
|
433
|
+
typeBindings: nativeClient && hasAxiosRequestConfig ? [getRequestConfigTypeName("native")] : [],
|
|
434
|
+
from: REST_PACKAGE_IMPORT_PATH
|
|
435
|
+
};
|
|
436
|
+
const appRestClientImport = {
|
|
437
|
+
bindings: [APP_REST_CLIENT_NAME],
|
|
438
|
+
from: getAppRestClientImportPath(resolver.options)
|
|
439
|
+
};
|
|
430
440
|
const endpointsImports = getEndpointsImports({
|
|
431
441
|
tag,
|
|
432
442
|
endpoints,
|
|
@@ -466,6 +476,8 @@ function generateConfigs(generateTypeParams) {
|
|
|
466
476
|
};
|
|
467
477
|
const lines = [];
|
|
468
478
|
if (hasAxiosImport) lines.push(renderImport$3(axiosImport));
|
|
479
|
+
if (nativeImport.typeBindings?.length) lines.push(renderImport$3(nativeImport));
|
|
480
|
+
if (nativeClient && endpoints.some((endpoint) => endpoint.mediaUpload)) lines.push(renderImport$3(appRestClientImport));
|
|
469
481
|
if (hasZodImport) lines.push(renderImport$3(ZOD_IMPORT));
|
|
470
482
|
if (hasDynamicInputsImport) lines.push(renderImport$3(dynamicInputsImport));
|
|
471
483
|
if (hasDynamicColumnsImport) lines.push(renderImport$3(dynamicColumnsImport));
|
|
@@ -541,7 +553,7 @@ function renderMutationContent(resolver, endpoint, tag) {
|
|
|
541
553
|
const endpointFunction = getImportedEndpointName(endpoint, resolver.options);
|
|
542
554
|
const mutationVariablesType = endpoint.mediaUpload ? `{ ${endpointParamsStr}${endpointParamsStr ? "; " : ""}abortController?: AbortController; onUploadProgress?: (progress: { loaded: number; total: number }) => void }` : `{ ${endpointParamsStr} }`;
|
|
543
555
|
const lines = [];
|
|
544
|
-
lines.push(`(options?: AppMutationOptions<typeof ${endpointFunction}, ${mutationVariablesType}>${hasMutationEffects ? ` & ${MUTATION_EFFECTS.optionsType}` : ""}${hasAxiosRequestConfig ? `, config?: ${
|
|
556
|
+
lines.push(`(options?: AppMutationOptions<typeof ${endpointFunction}, ${mutationVariablesType}>${hasMutationEffects ? ` & ${MUTATION_EFFECTS.optionsType}` : ""}${hasAxiosRequestConfig ? `, config?: ${getRequestConfigTypeName(resolver.options.restClient)}` : ""}) => {`);
|
|
545
557
|
if (hasMutationDefaultOnError) lines.push(" const queryConfig = OpenApiQueryConfig.useConfig();");
|
|
546
558
|
if (hasMutationEffects) lines.push(` const { runMutationEffects } = useMutationEffects<${QUERY_MODULE_ENUM}.${endpointTag}>({ currentModule: ${QUERY_MODULE_ENUM}.${tag} });`);
|
|
547
559
|
if (hasAclCheck) lines.push(` const { checkAcl } = ${ACL_CHECK_HOOK}();`);
|
|
@@ -643,12 +655,18 @@ function generateEndpoints({ resolver, data, tag }) {
|
|
|
643
655
|
};
|
|
644
656
|
const hasAxiosRequestConfig = resolver.options.axiosRequestConfig;
|
|
645
657
|
const hasGetEndpoints = endpoints.some((endpoint) => endpoint.method === "get");
|
|
646
|
-
const
|
|
658
|
+
const nativeClient = resolver.options.restClient === "native";
|
|
659
|
+
const hasAxiosImport = !nativeClient && (hasAxiosRequestConfig || hasGetEndpoints);
|
|
647
660
|
const axiosImport = {
|
|
648
661
|
bindings: [],
|
|
649
662
|
typeBindings: hasAxiosImport ? [AXIOS_REQUEST_CONFIG_TYPE] : [],
|
|
650
663
|
from: AXIOS_IMPORT.from
|
|
651
664
|
};
|
|
665
|
+
const nativeImport = {
|
|
666
|
+
bindings: [],
|
|
667
|
+
typeBindings: nativeClient && (hasAxiosRequestConfig || hasGetEndpoints) ? [getRequestConfigTypeName("native")] : [],
|
|
668
|
+
from: REST_PACKAGE_IMPORT_PATH
|
|
669
|
+
};
|
|
652
670
|
const generateParse = resolver.options.parseRequestParams;
|
|
653
671
|
const endpointParams = endpoints.flatMap((endpoint) => endpoint.parameters);
|
|
654
672
|
const endpointParamsParseSchemas = endpointParams.filter((param) => !["Path", "Header"].includes(param.type)).map((param) => param.parameterSortingEnumSchemaName ?? param.zodSchema);
|
|
@@ -669,6 +687,7 @@ function generateEndpoints({ resolver, data, tag }) {
|
|
|
669
687
|
const lines = [];
|
|
670
688
|
lines.push(renderImport$2(appRestClientImport));
|
|
671
689
|
if (hasAxiosImport) lines.push(renderImport$2(axiosImport));
|
|
690
|
+
if (nativeImport.typeBindings?.length) lines.push(renderImport$2(nativeImport));
|
|
672
691
|
if (hasZodImport) lines.push(renderImport$2(ZOD_IMPORT));
|
|
673
692
|
if (hasZodExtendedImport) lines.push(renderImport$2(zodExtendedImport));
|
|
674
693
|
for (const modelsImport of modelsImports) lines.push(renderImport$2(modelsImport));
|
|
@@ -686,7 +705,7 @@ function generateEndpoints({ resolver, data, tag }) {
|
|
|
686
705
|
const hasUndefinedEndpointBody = requiresBody(endpoint) && !endpointBody && hasEndpointConfig(endpoint, resolver);
|
|
687
706
|
const endpointConfig = renderEndpointConfig(resolver, endpoint, tag);
|
|
688
707
|
const hasRequestConfigParam = hasAxiosRequestConfig || endpoint.method === "get";
|
|
689
|
-
lines.push(`export const ${getEndpointName(endpoint)} = (${endpointParams}${hasRequestConfigParam ? `${AXIOS_REQUEST_CONFIG_NAME}?: ${getRequestConfigType$1()}` : ""}) => {`);
|
|
708
|
+
lines.push(`export const ${getEndpointName(endpoint)} = (${endpointParams}${hasRequestConfigParam ? `${AXIOS_REQUEST_CONFIG_NAME}?: ${getRequestConfigType$1(resolver)}` : ""}) => {`);
|
|
690
709
|
lines.push(` return ${APP_REST_CLIENT_NAME}.${endpoint.method}(`);
|
|
691
710
|
lines.push(` ${renderRequestInfo(resolver, endpoint, tag)},`);
|
|
692
711
|
lines.push(` \`${getEndpointPath(endpoint)}\`,`);
|
|
@@ -702,8 +721,8 @@ function generateEndpoints({ resolver, data, tag }) {
|
|
|
702
721
|
function renderRequestInfo(resolver, endpoint, tag) {
|
|
703
722
|
return `{ resSchema: ${getImportedZodSchemaName(resolver, endpoint.response, (resolver.options.modelsInCommon || resolver.options.modelsInModules) && resolver.options.splitByTags ? tag : void 0)} }`;
|
|
704
723
|
}
|
|
705
|
-
function getRequestConfigType$1() {
|
|
706
|
-
return `${
|
|
724
|
+
function getRequestConfigType$1(resolver) {
|
|
725
|
+
return `${getRequestConfigTypeName(resolver.options.restClient)} & { allowInvalidResponseData?: boolean }`;
|
|
707
726
|
}
|
|
708
727
|
function renderImport$2(importData) {
|
|
709
728
|
const namedImports = [...importData.bindings, ...(importData.typeBindings ?? []).map((binding) => importData.typeOnly ? binding : `type ${binding}`)];
|
|
@@ -914,15 +933,23 @@ function generateQueries(params) {
|
|
|
914
933
|
if (!endpoints || endpoints.length === 0) return;
|
|
915
934
|
const endpointGroups = groupEndpoints(endpoints, resolver);
|
|
916
935
|
const hasAxiosRequestConfig = resolver.options.axiosRequestConfig;
|
|
917
|
-
const
|
|
936
|
+
const nativeClient = resolver.options.restClient === "native";
|
|
937
|
+
const hasNativeMediaUpload = nativeClient && endpoints.some(({ mediaUpload }) => mediaUpload);
|
|
938
|
+
const requestConfigType = getRequestConfigTypeName(resolver.options.restClient);
|
|
939
|
+
const hasAxiosDefaultImport = !nativeClient && endpoints.some(({ mediaUpload }) => mediaUpload);
|
|
918
940
|
const hasGetEndpoints = endpoints.some((endpoint) => endpoint.method === "get");
|
|
919
|
-
const hasAxiosImport = hasAxiosRequestConfig || hasAxiosDefaultImport || hasGetEndpoints;
|
|
941
|
+
const hasAxiosImport = !nativeClient && (hasAxiosRequestConfig || hasAxiosDefaultImport || hasGetEndpoints);
|
|
920
942
|
const axiosImport = {
|
|
921
943
|
defaultImport: hasAxiosDefaultImport ? AXIOS_DEFAULT_IMPORT_NAME : void 0,
|
|
922
944
|
bindings: [],
|
|
923
945
|
typeBindings: hasAxiosImport ? [AXIOS_REQUEST_CONFIG_TYPE] : [],
|
|
924
946
|
from: AXIOS_IMPORT.from
|
|
925
947
|
};
|
|
948
|
+
const nativeTransportImport = {
|
|
949
|
+
bindings: [],
|
|
950
|
+
typeBindings: nativeClient ? [...hasAxiosRequestConfig || hasGetEndpoints ? [requestConfigType] : [], ...endpoints.some(({ mediaDownload }) => mediaDownload) ? [NATIVE_RESPONSE_TYPE] : []] : [],
|
|
951
|
+
from: REST_PACKAGE_IMPORT_PATH
|
|
952
|
+
};
|
|
926
953
|
const { queryEndpoints, infiniteQueryEndpoints, mutationEndpoints, aclEndpoints } = endpointGroups;
|
|
927
954
|
const hasMutationDefaultOnError = resolver.options.mutationDefaultOnError && mutationEndpoints.length > 0;
|
|
928
955
|
const queryImport = {
|
|
@@ -1001,8 +1028,9 @@ function generateQueries(params) {
|
|
|
1001
1028
|
});
|
|
1002
1029
|
const lines = [];
|
|
1003
1030
|
if (hasAxiosImport) lines.push(renderImport(axiosImport));
|
|
1031
|
+
if (nativeTransportImport.typeBindings?.length) lines.push(renderImport(nativeTransportImport));
|
|
1032
|
+
if (inlineEndpoints || hasNativeMediaUpload) lines.push(renderImport(appRestClientImport));
|
|
1004
1033
|
if (inlineEndpoints) {
|
|
1005
|
-
lines.push(renderImport(appRestClientImport));
|
|
1006
1034
|
if (hasZodImport) lines.push(renderImport(ZOD_IMPORT));
|
|
1007
1035
|
if (hasZodExtendedImport) lines.push(renderImport(zodExtendedImport));
|
|
1008
1036
|
}
|
|
@@ -1233,8 +1261,9 @@ function renderQueryJsDocs({ resolver, endpoint, mode, tag }) {
|
|
|
1233
1261
|
if (mode === "query") lines.push(" * @param { AppQueryOptions } options Query options");
|
|
1234
1262
|
else if (mode === "mutation") lines.push(` * @param { AppMutationOptions${resolver.options.mutationEffects ? ` & ${MUTATION_EFFECTS.optionsType}` : ""} } options Mutation options`);
|
|
1235
1263
|
else lines.push(" * @param { AppInfiniteQueryOptions } options Infinite query options");
|
|
1236
|
-
const
|
|
1237
|
-
const
|
|
1264
|
+
const withRawResponse = endpoint.mediaDownload && mode !== "infiniteQuery";
|
|
1265
|
+
const responseType = resolver.options.restClient === "native" ? NATIVE_RESPONSE_TYPE : "AxiosResponse";
|
|
1266
|
+
const resultType = `${withRawResponse ? `${responseType}<` : ""}${getImportedZodSchemaInferedTypeName(resolver, endpoint.response, void 0, tag)}${withRawResponse ? ">" : ""}`;
|
|
1238
1267
|
if (mode === "query") lines.push(` * @returns { UseQueryResult<${resultType}> } ${endpoint.responseDescription ?? ""}`);
|
|
1239
1268
|
else if (mode === "mutation") lines.push(` * @returns { UseMutationResult<${resultType}> } ${endpoint.responseDescription ?? ""}`);
|
|
1240
1269
|
else lines.push(` * @returns { UseInfiniteQueryResult<${resultType}> } ${endpoint.responseDescription ?? ""}`);
|
|
@@ -1269,7 +1298,7 @@ function renderInlineEndpoints({ resolver, endpoints, tag }) {
|
|
|
1269
1298
|
const hasUndefinedEndpointBody = requiresBody(endpoint) && !endpointBody && hasEndpointConfig(endpoint, resolver);
|
|
1270
1299
|
const endpointConfig = renderInlineEndpointConfig(resolver, endpoint, tag);
|
|
1271
1300
|
const hasRequestConfigParam = resolver.options.axiosRequestConfig || endpoint.method === "get";
|
|
1272
|
-
lines.push(`const ${getEndpointName(endpoint)} = (${endpointParams}${hasRequestConfigParam ? `${endpointParams ? ", " : ""}${AXIOS_REQUEST_CONFIG_NAME}?: ${getRequestConfigType()}` : ""}) => {`);
|
|
1301
|
+
lines.push(`const ${getEndpointName(endpoint)} = (${endpointParams}${hasRequestConfigParam ? `${endpointParams ? ", " : ""}${AXIOS_REQUEST_CONFIG_NAME}?: ${getRequestConfigType(resolver)}` : ""}) => {`);
|
|
1273
1302
|
lines.push(` return ${APP_REST_CLIENT_NAME}.${endpoint.method}(`);
|
|
1274
1303
|
lines.push(` ${renderInlineRequestInfo(resolver, endpoint, tag)},`);
|
|
1275
1304
|
lines.push(` \`${getEndpointPath(endpoint)}\`,`);
|
|
@@ -1285,8 +1314,8 @@ function renderInlineEndpoints({ resolver, endpoints, tag }) {
|
|
|
1285
1314
|
function renderInlineRequestInfo(resolver, endpoint, tag) {
|
|
1286
1315
|
return `{ resSchema: ${getImportedZodSchemaName(resolver, endpoint.response, tag)} }`;
|
|
1287
1316
|
}
|
|
1288
|
-
function getRequestConfigType() {
|
|
1289
|
-
return `${
|
|
1317
|
+
function getRequestConfigType(resolver) {
|
|
1318
|
+
return `${getRequestConfigTypeName(resolver.options.restClient)} & { allowInvalidResponseData?: boolean }`;
|
|
1290
1319
|
}
|
|
1291
1320
|
function renderRequestConfigWithSignal(hasRequestConfigParam) {
|
|
1292
1321
|
return `{ ${hasRequestConfigParam ? `...${AXIOS_REQUEST_CONFIG_NAME}, ` : ""}signal }`;
|
|
@@ -1335,7 +1364,7 @@ function renderQueryOptions({ resolver, endpoint, inlineEndpoints }) {
|
|
|
1335
1364
|
const endpointArgs = renderEndpointArgs(resolver, endpoint, {});
|
|
1336
1365
|
const endpointFunction = inlineEndpoints ? getEndpointName(endpoint) : getImportedEndpointName(endpoint, resolver.options);
|
|
1337
1366
|
const lines = [];
|
|
1338
|
-
lines.push(`const ${getQueryOptionsName(endpoint)} = (${endpointParams ? `{ ${endpointArgs} }: { ${endpointParams} }` : ""}${hasRequestConfigParam ? `${endpointParams ? ", " : ""}${AXIOS_REQUEST_CONFIG_NAME}?: ${getRequestConfigType()}` : ""}) => ({`);
|
|
1367
|
+
lines.push(`const ${getQueryOptionsName(endpoint)} = (${endpointParams ? `{ ${endpointArgs} }: { ${endpointParams} }` : ""}${hasRequestConfigParam ? `${endpointParams ? ", " : ""}${AXIOS_REQUEST_CONFIG_NAME}?: ${getRequestConfigType(resolver)}` : ""}) => ({`);
|
|
1339
1368
|
lines.push(` queryKey: keys.${getEndpointName(endpoint)}(${endpointArgs}),`);
|
|
1340
1369
|
const requestConfigWithSignal = renderRequestConfigWithSignal(hasRequestConfigParam);
|
|
1341
1370
|
lines.push(` queryFn: ({ signal }: { signal: AbortSignal }) => ${endpointFunction}(${endpointArgs}${hasRequestConfigParam ? `${endpointArgs ? ", " : ""}${requestConfigWithSignal}` : ""}),`);
|
|
@@ -1352,7 +1381,7 @@ function renderInfiniteQueryOptions({ resolver, endpoint, inlineEndpoints }) {
|
|
|
1352
1381
|
const endpointArgsWithPage = renderEndpointArgs(resolver, endpoint, { replacePageParam: true });
|
|
1353
1382
|
const endpointFunction = inlineEndpoints ? getEndpointName(endpoint) : getImportedEndpointName(endpoint, resolver.options);
|
|
1354
1383
|
const lines = [];
|
|
1355
|
-
lines.push(`const ${getInfiniteQueryOptionsName(endpoint)} = (${endpointParams ? `{ ${endpointArgsWithoutPage} }: { ${endpointParams} }` : ""}${hasRequestConfigParam ? `${endpointParams ? ", " : ""}${AXIOS_REQUEST_CONFIG_NAME}?: ${getRequestConfigType()}` : ""}) => ({`);
|
|
1384
|
+
lines.push(`const ${getInfiniteQueryOptionsName(endpoint)} = (${endpointParams ? `{ ${endpointArgsWithoutPage} }: { ${endpointParams} }` : ""}${hasRequestConfigParam ? `${endpointParams ? ", " : ""}${AXIOS_REQUEST_CONFIG_NAME}?: ${getRequestConfigType(resolver)}` : ""}) => ({`);
|
|
1356
1385
|
lines.push(` queryKey: keys.${getEndpointName(endpoint)}Infinite(${endpointArgsWithoutPage}),`);
|
|
1357
1386
|
const requestConfigWithSignal = renderRequestConfigWithSignal(hasRequestConfigParam);
|
|
1358
1387
|
lines.push(` queryFn: ({ pageParam, signal }: { pageParam: number; signal: AbortSignal }) => ${endpointFunction}(${endpointArgsWithPage}${hasRequestConfigParam ? `, ${requestConfigWithSignal}` : ""}),`);
|
|
@@ -1369,7 +1398,7 @@ function renderPrefetchQuery({ resolver, endpoint }) {
|
|
|
1369
1398
|
const endpointParams = renderEndpointParams(resolver, endpoint, { modelNamespaceTag: getEndpointTag(endpoint, resolver.options) });
|
|
1370
1399
|
const endpointArgs = renderEndpointArgs(resolver, endpoint, {});
|
|
1371
1400
|
const lines = [];
|
|
1372
|
-
lines.push(`export const ${getPrefetchQueryName(endpoint)} = (queryClient: QueryClient, ${endpointParams ? `{ ${endpointArgs} }: { ${endpointParams} }, ` : ""}options?: Omit<Parameters<QueryClient["prefetchQuery"]>[0], "queryKey" | "queryFn">, ${hasRequestConfigParam ? `${AXIOS_REQUEST_CONFIG_NAME}?: ${
|
|
1401
|
+
lines.push(`export const ${getPrefetchQueryName(endpoint)} = (queryClient: QueryClient, ${endpointParams ? `{ ${endpointArgs} }: { ${endpointParams} }, ` : ""}options?: Omit<Parameters<QueryClient["prefetchQuery"]>[0], "queryKey" | "queryFn">, ${hasRequestConfigParam ? `${AXIOS_REQUEST_CONFIG_NAME}?: ${getRequestConfigTypeName(resolver.options.restClient)}, ` : ""}throwOnError = false) => {`);
|
|
1373
1402
|
lines.push(` const queryOptions = { ...${getQueryOptionsName(endpoint)}(${endpointParams ? `{ ${endpointArgs} }` : ""}${hasRequestConfigParam ? `${endpointParams ? ", " : ""}${AXIOS_REQUEST_CONFIG_NAME}` : ""}), ...options };`);
|
|
1374
1403
|
lines.push(` return throwOnError ? queryClient.fetchQuery(queryOptions) : queryClient.prefetchQuery(queryOptions);`);
|
|
1375
1404
|
lines.push("};");
|
|
@@ -1384,7 +1413,7 @@ function renderPrefetchInfiniteQuery({ resolver, endpoint }) {
|
|
|
1384
1413
|
const endpointArgs = renderEndpointArgs(resolver, endpoint, { excludePageParam: true });
|
|
1385
1414
|
const optionsArgs = `${endpointParams ? `{ ${endpointArgs} }` : ""}${hasRequestConfigParam ? `${endpointParams ? ", " : ""}${AXIOS_REQUEST_CONFIG_NAME}` : ""}`;
|
|
1386
1415
|
const lines = [];
|
|
1387
|
-
lines.push(`export const ${getPrefetchInfiniteQueryName(endpoint)} = (queryClient: QueryClient, ${endpointParams ? `{ ${endpointArgs} }: { ${endpointParams} }, ` : ""}options?: Omit<Parameters<QueryClient["prefetchInfiniteQuery"]>[0], "queryKey" | "queryFn" | "initialPageParam" | "getNextPageParam">, ${hasRequestConfigParam ? `${AXIOS_REQUEST_CONFIG_NAME}?: ${
|
|
1416
|
+
lines.push(`export const ${getPrefetchInfiniteQueryName(endpoint)} = (queryClient: QueryClient, ${endpointParams ? `{ ${endpointArgs} }: { ${endpointParams} }, ` : ""}options?: Omit<Parameters<QueryClient["prefetchInfiniteQuery"]>[0], "queryKey" | "queryFn" | "initialPageParam" | "getNextPageParam">, ${hasRequestConfigParam ? `${AXIOS_REQUEST_CONFIG_NAME}?: ${getRequestConfigTypeName(resolver.options.restClient)}, ` : ""}throwOnError = false) => {`);
|
|
1388
1417
|
lines.push(` const queryOptions = { ...${getInfiniteQueryOptionsName(endpoint)}(${optionsArgs}), ...(options as {}) };`);
|
|
1389
1418
|
lines.push(` return throwOnError ? queryClient.fetchInfiniteQuery(queryOptions) : queryClient.prefetchInfiniteQuery(queryOptions);`);
|
|
1390
1419
|
lines.push("};");
|
|
@@ -1413,7 +1442,7 @@ function renderQuery({ resolver, endpoint, inlineEndpoints }) {
|
|
|
1413
1442
|
mode: "query",
|
|
1414
1443
|
tag
|
|
1415
1444
|
}));
|
|
1416
|
-
lines.push(`export const ${getQueryName(endpoint)} = <TData>(${endpointParams ? `{ ${endpointArgs} }: { ${endpointParams} }, ` : ""}options?: AppQueryOptions<typeof ${inlineEndpoints ? getEndpointName(endpoint) : getImportedEndpointName(endpoint, resolver.options)}, TData>${hasAxiosRequestConfig ? `, ${AXIOS_REQUEST_CONFIG_NAME}?: ${
|
|
1445
|
+
lines.push(`export const ${getQueryName(endpoint)} = <TData>(${endpointParams ? `{ ${endpointArgs} }: { ${endpointParams} }, ` : ""}options?: AppQueryOptions<typeof ${inlineEndpoints ? getEndpointName(endpoint) : getImportedEndpointName(endpoint, resolver.options)}, TData>${hasAxiosRequestConfig ? `, ${AXIOS_REQUEST_CONFIG_NAME}?: ${getRequestConfigTypeName(resolver.options.restClient)}` : ""}) => {`);
|
|
1417
1446
|
lines.push(" const queryConfig = OpenApiQueryConfig.useConfig();");
|
|
1418
1447
|
if (hasAclCheck) lines.push(` const { checkAcl } = ${ACL_CHECK_HOOK}();`);
|
|
1419
1448
|
lines.push(...renderWorkspaceParamResolutions({
|
|
@@ -1483,7 +1512,7 @@ function renderMutation({ resolver, endpoint, inlineEndpoints, precomputed }) {
|
|
|
1483
1512
|
mode: "mutation",
|
|
1484
1513
|
tag
|
|
1485
1514
|
}));
|
|
1486
|
-
lines.push(`export const ${getQueryName(endpoint, true)} = (${pathParamFirstArg}options?: AppMutationOptions<typeof ${endpointFunction}${mutationOptionsTypeArg}>${hasMutationEffects ? ` & ${MUTATION_EFFECTS.optionsType}` : ""}${hasAxiosRequestConfig ? `, ${AXIOS_REQUEST_CONFIG_NAME}?: ${
|
|
1515
|
+
lines.push(`export const ${getQueryName(endpoint, true)} = (${pathParamFirstArg}options?: AppMutationOptions<typeof ${endpointFunction}${mutationOptionsTypeArg}>${hasMutationEffects ? ` & ${MUTATION_EFFECTS.optionsType}` : ""}${hasAxiosRequestConfig ? `, ${AXIOS_REQUEST_CONFIG_NAME}?: ${getRequestConfigTypeName(resolver.options.restClient)}` : ""}) => {`);
|
|
1487
1516
|
if (hasMutationDefaultOnError) lines.push(" const queryConfig = OpenApiQueryConfig.useConfig();");
|
|
1488
1517
|
if (hasAclCheck) lines.push(` const { checkAcl } = ${ACL_CHECK_HOOK}();`);
|
|
1489
1518
|
lines.push(...renderWorkspaceContextDestructure({
|
|
@@ -1602,7 +1631,7 @@ function renderInfiniteQuery({ resolver, endpoint, inlineEndpoints }) {
|
|
|
1602
1631
|
mode: "infiniteQuery",
|
|
1603
1632
|
tag
|
|
1604
1633
|
}));
|
|
1605
|
-
lines.push(`export const ${getInfiniteQueryName(endpoint)} = <TData>(${endpointParams ? `{ ${endpointArgsWithoutPage} }: { ${endpointParams} }, ` : ""}options?: AppInfiniteQueryOptions<typeof ${inlineEndpoints ? getEndpointName(endpoint) : getImportedEndpointName(endpoint, resolver.options)}, TData>${hasAxiosRequestConfig ? `, ${AXIOS_REQUEST_CONFIG_NAME}?: ${
|
|
1634
|
+
lines.push(`export const ${getInfiniteQueryName(endpoint)} = <TData>(${endpointParams ? `{ ${endpointArgsWithoutPage} }: { ${endpointParams} }, ` : ""}options?: AppInfiniteQueryOptions<typeof ${inlineEndpoints ? getEndpointName(endpoint) : getImportedEndpointName(endpoint, resolver.options)}, TData>${hasAxiosRequestConfig ? `, ${AXIOS_REQUEST_CONFIG_NAME}?: ${getRequestConfigTypeName(resolver.options.restClient)}` : ""}) => {`);
|
|
1606
1635
|
lines.push(" const queryConfig = OpenApiQueryConfig.useConfig();");
|
|
1607
1636
|
if (hasAclCheck) lines.push(` const { checkAcl } = ${ACL_CHECK_HOOK}();`);
|
|
1608
1637
|
lines.push(...renderWorkspaceParamResolutions({
|
|
@@ -1627,9 +1656,10 @@ function renderInfiniteQuery({ resolver, endpoint, inlineEndpoints }) {
|
|
|
1627
1656
|
//#endregion
|
|
1628
1657
|
//#region src/generators/generate/generateAppRestClient.ts
|
|
1629
1658
|
function generateAppRestClient(resolver) {
|
|
1630
|
-
|
|
1659
|
+
const clientName = resolver.options.restClient === "native" ? "NativeRestClient" : "RestClient";
|
|
1660
|
+
return `import { ${clientName} } from "${resolver.options.restClient === "native" ? NATIVE_PACKAGE_IMPORT_PATH : PACKAGE_IMPORT_PATH}";
|
|
1631
1661
|
|
|
1632
|
-
export const ${APP_REST_CLIENT_NAME} = new
|
|
1662
|
+
export const ${APP_REST_CLIENT_NAME} = new ${clientName}({
|
|
1633
1663
|
config: {
|
|
1634
1664
|
baseURL: "${resolver.getBaseUrl()}"
|
|
1635
1665
|
},
|
package/dist/generator.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as GenerateFileData, t as GenerateOptions } from "./options-
|
|
1
|
+
import { n as GenerateFileData, t as GenerateOptions } from "./options-KPf-Fti5.mjs";
|
|
2
2
|
import { OpenAPIV3 } from "openapi-types";
|
|
3
3
|
//#region src/generators/types/metadata.d.ts
|
|
4
4
|
interface GenerateParams {
|
package/dist/generator.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { t as generateCodeFromOpenAPIDoc } from "./generateCodeFromOpenAPIDoc-
|
|
2
|
-
import { t as getDataFromOpenAPIDoc } from "./getDataFromOpenAPIDoc-
|
|
3
|
-
import {
|
|
1
|
+
import { t as generateCodeFromOpenAPIDoc } from "./generateCodeFromOpenAPIDoc-glAKBEGP.mjs";
|
|
2
|
+
import { t as getDataFromOpenAPIDoc } from "./getDataFromOpenAPIDoc-7RxjULpB.mjs";
|
|
3
|
+
import { H as getQueryName, In as formatTag, Kt as getNamespaceName, O as getTagImportPath, S as getTsTypeBase, Tt as invalidVariableNameCharactersToCamel, d as isQuery, dt as DEFAULT_GENERATE_OPTIONS, en as isMediaTypeAllowed, t as getOpenApiDoc, tn as isParamMediaTypeAllowed, u as isMutation, x as getSchemaTsMetaType } from "./generate.runner-BvSprH6D.mjs";
|
|
4
4
|
//#region src/generators/core/getMetadataFromOpenAPIDoc.ts
|
|
5
5
|
async function getMetadataFromOpenAPIDoc(openApiDoc, options) {
|
|
6
6
|
const { resolver, data } = await getDataFromOpenAPIDoc(openApiDoc, options);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { $t as
|
|
1
|
+
import { $t as isMainResponseStatus, At as getZodSchemaName, Cn as STRING_SCHEMA, Dt as getEnumZodSchemaName, En as VOID_SCHEMA, Et as getBodyZodSchemaName, Hn as capitalize, In as formatTag, Jn as Profiler, Jt as escapeControlCharacters, Kn as removeWord, Kt as getNamespaceName, Ln as getEndpointTag, Mn as BODY_PARAMETER_NAME, Nn as JSON_APPLICATION_FORMAT, Nt as isNamedZodSchema, Ot as getParamZodSchemaName, Qt as isErrorStatus, Rn as getOperationTag, Sn as NUMBER_SCHEMA, Tn as UUID_SCHEMA, Tt as invalidVariableNameCharactersToCamel, Un as decapitalize, Wn as getMostCommonAdjacentCombinationSplit, Xt as getSchemaNameByRef, Yt as getParameterEnumNames, Zt as getSchemaRef, _n as BLOB_SCHEMA, an as pathParamToVariableName, bn as ENUM_SCHEMA, cn as unwrapQuotesIfNeeded, d as isQuery, dn as isArraySchemaObject, en as isMediaTypeAllowed, fn as isReferenceObject, gn as ANY_SCHEMA, hn as ALLOWED_PATH_IN, in as isSortingParameterObject, jt as getZodSchemaOperationName, kt as getResponseZodSchemaName, ln as wrapWithQuotesIfNeeded, lt as iterateSchema, mn as ALLOWED_METHODS, nn as isPathExcluded, on as pathToVariableName, pn as isSchemaObject, qn as snakeToCamel, qt as autocorrectRef, rn as isPrimitiveType, s as pick, sn as replaceHyphenatedPath, tn as isParamMediaTypeAllowed, un as inferRequiredSchema, ut as getUniqueArray, vn as DATETIME_SCHEMA, wn as URL_SCHEMA, xn as INT_SCHEMA, yn as EMAIL_SCHEMA, zn as isTagIncluded } from "./generate.runner-BvSprH6D.mjs";
|
|
2
2
|
//#region src/generators/const/validation.const.ts
|
|
3
3
|
const HTTP_STATUS_CODES = {
|
|
4
4
|
"100": "Continue",
|
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { a as ErrorHandler, c as SharedErrorHandler, d as ns, f as resources, i as ErrorEntry, l as TranslateFunction, n as DomainErrorEntry, o as ErrorHandlerOptions, r as DomainErrorRegistry, s as GeneralErrorCodes, t as ApplicationException, u as configureTranslations } from "./error-handling-CNOHs4Fc.mjs";
|
|
2
|
-
import { t as OpenAPICodegenConfig } from "./config-
|
|
2
|
+
import { t as OpenAPICodegenConfig } from "./config-DgrOddSC.mjs";
|
|
3
|
+
import { c as TransportRequestConfig, d as UploadProgress, l as TransportResponse, n as HttpError, s as TransportRequest } from "./rest-transport.types-D0R9mvGH.mjs";
|
|
4
|
+
import { n as NativeRestInterceptor, r as NativeRestClient, t as NativeInterceptor } from "./native-rest-interceptor-CTBBx6B3.mjs";
|
|
3
5
|
import { AxiosError, AxiosInstance, AxiosRequestConfig, AxiosResponse, AxiosResponseHeaders, CreateAxiosDefaults } from "axios";
|
|
4
6
|
import { z } from "zod";
|
|
5
7
|
import { PropsWithChildren, ReactNode } from "react";
|
|
@@ -158,4 +160,4 @@ interface AuthGuardProps {
|
|
|
158
160
|
}
|
|
159
161
|
declare const AuthGuard: ({ type, redirectTo, children }: PropsWithChildren<AuthGuardProps>) => import("react").ReactNode;
|
|
160
162
|
//#endregion
|
|
161
|
-
export { type AppInfiniteQueryOptions, type AppMutationOptions, type AppQueryOptions, ApplicationException, AuthContext, AuthGuard, type AuthGuardProps, type DomainErrorEntry, DomainErrorRegistry, type ErrorEntry, ErrorHandler, type ErrorHandlerOptions, type GeneralErrorCodes, type RestClient as IRestClient, type InvalidationMap, type InvalidationMapFunc, type MutationEffectsOptions, OpenAPICodegenConfig, OpenApiQueryConfig, OpenApiRouter, OpenApiWorkspaceContext, type QueryModule, type RequestConfig, type RequestInfo, type Response, RestClient$1 as RestClient, RestInterceptor, RestUtils, SharedErrorHandler, type TranslateFunction, configureTranslations, ns, resources, useMutationEffects, useWorkspaceContext };
|
|
163
|
+
export { type AppInfiniteQueryOptions, type AppMutationOptions, type AppQueryOptions, ApplicationException, AuthContext, AuthGuard, type AuthGuardProps, type DomainErrorEntry, DomainErrorRegistry, type ErrorEntry, ErrorHandler, type ErrorHandlerOptions, type GeneralErrorCodes, type RestClient as IRestClient, type InvalidationMap, type InvalidationMapFunc, type MutationEffectsOptions, HttpError as NativeHttpError, type NativeInterceptor, type TransportRequest as NativeRequest, type TransportRequestConfig as NativeRequestConfig, type TransportResponse as NativeResponse, NativeRestClient, NativeRestInterceptor, type UploadProgress as NativeUploadProgress, OpenAPICodegenConfig, OpenApiQueryConfig, OpenApiRouter, OpenApiWorkspaceContext, type QueryModule, type RequestConfig, type RequestInfo, type Response, RestClient$1 as RestClient, RestInterceptor, RestUtils, SharedErrorHandler, type TranslateFunction, configureTranslations, ns, resources, useMutationEffects, useWorkspaceContext };
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import { a as RestUtils, c as resources, i as SharedErrorHandler, n as DomainErrorRegistry, o as configureTranslations, r as ErrorHandler, s as ns, t as ApplicationException } from "./error-handling-
|
|
1
|
+
import { a as RestUtils, c as resources, i as SharedErrorHandler, n as DomainErrorRegistry, o as configureTranslations, r as ErrorHandler, s as ns, t as ApplicationException } from "./error-handling-BMXC5P08.mjs";
|
|
2
|
+
import { t as HttpError } from "./rest-transport.types-DxitRtsB.mjs";
|
|
3
|
+
import { n as NativeRestClient, t as NativeRestInterceptor } from "./native-rest-interceptor-Bcc2jx4e.mjs";
|
|
2
4
|
import { n as OpenApiRouter, t as AuthContext } from "./auth.context-YFWzkwoN.mjs";
|
|
3
5
|
import axios from "axios";
|
|
4
6
|
import { z } from "zod";
|
|
@@ -254,4 +256,4 @@ const AuthGuard = ({ type, redirectTo, children }) => {
|
|
|
254
256
|
return children;
|
|
255
257
|
};
|
|
256
258
|
//#endregion
|
|
257
|
-
export { ApplicationException, AuthContext, AuthGuard, DomainErrorRegistry, ErrorHandler, OpenApiQueryConfig, OpenApiRouter, OpenApiWorkspaceContext, RestClient, RestInterceptor, RestUtils, SharedErrorHandler, configureTranslations, ns, resources, useMutationEffects, useWorkspaceContext };
|
|
259
|
+
export { ApplicationException, AuthContext, AuthGuard, DomainErrorRegistry, ErrorHandler, HttpError as NativeHttpError, NativeRestClient, NativeRestInterceptor, OpenApiQueryConfig, OpenApiRouter, OpenApiWorkspaceContext, RestClient, RestInterceptor, RestUtils, SharedErrorHandler, configureTranslations, ns, resources, useMutationEffects, useWorkspaceContext };
|
package/dist/metro.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_generate_utils = require("./generate.utils-
|
|
2
|
+
const require_generate_utils = require("./generate.utils-CH2U2Dpr.cjs");
|
|
3
3
|
let fs = require("fs");
|
|
4
4
|
fs = require_generate_utils.__toESM(fs, 1);
|
|
5
5
|
let path = require("path");
|
|
@@ -47,7 +47,7 @@ function generateFilesFromNativeOpenAPI(source, yaml, options) {
|
|
|
47
47
|
if (!options.modelsOnly) {
|
|
48
48
|
if (options.acl && nativeData.renderedShared.appAcl) files.push(outputFile(options, "acl/app.ability.ts", nativeData.renderedShared.appAcl));
|
|
49
49
|
if (options.mutationEffects && nativeData.renderedShared.queryModules) files.push(outputFile(options, "queryModules.ts", nativeData.renderedShared.queryModules));
|
|
50
|
-
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`));
|
|
50
|
+
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`));
|
|
51
51
|
if (nativeData.renderedShared.domainErrors) files.push(outputFile(options, "domain-errors.ts", nativeData.renderedShared.domainErrors));
|
|
52
52
|
}
|
|
53
53
|
return files;
|
|
@@ -97,7 +97,7 @@ async function runGenerate({ fileConfig, params, formatGeneratedFile, profiler =
|
|
|
97
97
|
const nativeFiles = generateFilesFromNativeOpenAPI(nativeInput.source, nativeInput.yaml, config);
|
|
98
98
|
if (nativeFiles) return nativeFiles;
|
|
99
99
|
}
|
|
100
|
-
const { generateCodeFromOpenAPIDoc } = await Promise.resolve().then(() => require("./generateCodeFromOpenAPIDoc-
|
|
100
|
+
const { generateCodeFromOpenAPIDoc } = await Promise.resolve().then(() => require("./generateCodeFromOpenAPIDoc-CZT3sThI.cjs"));
|
|
101
101
|
return generateCodeFromOpenAPIDoc(openApiDoc, config, profiler, {
|
|
102
102
|
source: nativeInput.source,
|
|
103
103
|
yaml: nativeInput.yaml
|
package/dist/metro.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { r as GenerateFileFormatter } from "./options-
|
|
2
|
-
import { t as OpenAPICodegenConfig } from "./config-
|
|
3
|
-
import { d as GenerateOpenApiFile, m as GenerateOpenApiSpec, n as TinyOpenApiSpecModuleConfig } from "./openapi-source.runner-
|
|
1
|
+
import { r as GenerateFileFormatter } from "./options-KPf-Fti5.mjs";
|
|
2
|
+
import { t as OpenAPICodegenConfig } from "./config-DgrOddSC.mjs";
|
|
3
|
+
import { d as GenerateOpenApiFile, m as GenerateOpenApiSpec, n as TinyOpenApiSpecModuleConfig } from "./openapi-source.runner-ykstqlPC.mjs";
|
|
4
4
|
import { IncomingMessage, ServerResponse } from "http";
|
|
5
5
|
//#region src/metro/openapi-codegen.plugin.d.ts
|
|
6
6
|
type OpenApiCodegenMetroConfig = OpenAPICodegenConfig & {
|
package/dist/metro.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as createOpenApiCodegenRunner } from "./openapi-codegen.runner-
|
|
1
|
+
import { t as createOpenApiCodegenRunner } from "./openapi-codegen.runner-C93V7SGj.mjs";
|
|
2
2
|
import { i as normalizeWatchFolders, r as isTinyOpenApiFakeMode, t as createTinyOpenApiSourceRunner } from "./openapi-source.runner-BZ6ZLgRO.mjs";
|
|
3
3
|
import fs from "fs";
|
|
4
4
|
import path from "path";
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
import { t as HttpError } from "./rest-transport.types-DxitRtsB.mjs";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
//#region src/lib/rest/native-rest-client.ts
|
|
4
|
+
var NativeRestClient = class {
|
|
5
|
+
interceptors;
|
|
6
|
+
constructor({ config, interceptors = [] } = {}) {
|
|
7
|
+
this.baseURL = config?.baseURL ?? "";
|
|
8
|
+
this.headers = config?.headers;
|
|
9
|
+
this.credentials = config?.credentials;
|
|
10
|
+
this.interceptors = [...interceptors];
|
|
11
|
+
}
|
|
12
|
+
baseURL;
|
|
13
|
+
headers;
|
|
14
|
+
credentials;
|
|
15
|
+
attachInterceptor(interceptor) {
|
|
16
|
+
this.interceptors.push(interceptor);
|
|
17
|
+
}
|
|
18
|
+
ejectInterceptor(interceptor) {
|
|
19
|
+
const index = this.interceptors.indexOf(interceptor);
|
|
20
|
+
if (index >= 0) this.interceptors.splice(index, 1);
|
|
21
|
+
}
|
|
22
|
+
get(info, url, config) {
|
|
23
|
+
return this.request(info, "GET", url, void 0, config);
|
|
24
|
+
}
|
|
25
|
+
post(info, url, data, config) {
|
|
26
|
+
return this.request(info, "POST", url, data, config);
|
|
27
|
+
}
|
|
28
|
+
patch(info, url, data, config) {
|
|
29
|
+
return this.request(info, "PATCH", url, data, config);
|
|
30
|
+
}
|
|
31
|
+
put(info, url, data, config) {
|
|
32
|
+
return this.request(info, "PUT", url, data, config);
|
|
33
|
+
}
|
|
34
|
+
delete(info, url, data, config) {
|
|
35
|
+
return this.request(info, "DELETE", url, data, config);
|
|
36
|
+
}
|
|
37
|
+
async upload(url, data, config = {}, method = "put") {
|
|
38
|
+
if (config.onUploadProgress && typeof XMLHttpRequest !== "undefined") {
|
|
39
|
+
await this.uploadWithXhr(url, data, config, method);
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
await this.execute({
|
|
43
|
+
url,
|
|
44
|
+
method: method.toUpperCase(),
|
|
45
|
+
body: data,
|
|
46
|
+
headers: new Headers(config.headers),
|
|
47
|
+
signal: config.signal
|
|
48
|
+
}, config, false);
|
|
49
|
+
}
|
|
50
|
+
async request(info, method, path, data, config = {}) {
|
|
51
|
+
const errorStack = (/* @__PURE__ */ new Error()).stack;
|
|
52
|
+
try {
|
|
53
|
+
const headers = new Headers(this.headers);
|
|
54
|
+
new Headers(config.headers).forEach((value, key) => headers.set(key, value));
|
|
55
|
+
let body;
|
|
56
|
+
if (data != null) if (data instanceof FormData || data instanceof Blob || typeof data === "string") body = data;
|
|
57
|
+
else {
|
|
58
|
+
body = JSON.stringify(data);
|
|
59
|
+
if (!headers.has("content-type")) headers.set("content-type", "application/json");
|
|
60
|
+
}
|
|
61
|
+
const request = {
|
|
62
|
+
url: this.resolveUrl(path, config.params),
|
|
63
|
+
method,
|
|
64
|
+
headers,
|
|
65
|
+
body,
|
|
66
|
+
signal: config.signal,
|
|
67
|
+
credentials: config.credentials ?? this.credentials
|
|
68
|
+
};
|
|
69
|
+
const response = await this.execute(request, config);
|
|
70
|
+
const parseResult = info.resSchema.safeParse(response.data);
|
|
71
|
+
let dataResult;
|
|
72
|
+
if (parseResult.success) dataResult = parseResult.data;
|
|
73
|
+
else if (config.allowInvalidResponseData && method === "GET") {
|
|
74
|
+
parseResult.error.name = "BE Response schema mismatch - ZodError";
|
|
75
|
+
parseResult.error.stack = [parseResult.error.stack, ...errorStack?.split("\n").slice(2) ?? []].join("\n");
|
|
76
|
+
console.error(parseResult.error);
|
|
77
|
+
dataResult = response.data;
|
|
78
|
+
} else throw parseResult.error;
|
|
79
|
+
return config.rawResponse ? {
|
|
80
|
+
...response,
|
|
81
|
+
data: dataResult
|
|
82
|
+
} : dataResult;
|
|
83
|
+
} catch (error) {
|
|
84
|
+
if (error instanceof z.ZodError) error.name = "BE Response schema mismatch - ZodError";
|
|
85
|
+
throw await this.runErrorInterceptors(error);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
async execute(request, config = {}, applyInterceptors = true) {
|
|
89
|
+
let next = request;
|
|
90
|
+
if (applyInterceptors) for (const interceptor of this.interceptors) next = await interceptor.onRequest?.(next) ?? next;
|
|
91
|
+
const timeoutController = config.timeout ? new AbortController() : void 0;
|
|
92
|
+
const timer = timeoutController ? setTimeout(() => timeoutController.abort(), config.timeout) : void 0;
|
|
93
|
+
if (timeoutController && next.signal) if (next.signal.aborted) timeoutController.abort(next.signal.reason);
|
|
94
|
+
else next.signal.addEventListener("abort", () => timeoutController.abort(next.signal?.reason), { once: true });
|
|
95
|
+
const signal = timeoutController?.signal ?? next.signal;
|
|
96
|
+
try {
|
|
97
|
+
const res = await fetch(next.url, {
|
|
98
|
+
method: next.method,
|
|
99
|
+
headers: next.headers,
|
|
100
|
+
body: next.body,
|
|
101
|
+
signal,
|
|
102
|
+
credentials: next.credentials
|
|
103
|
+
});
|
|
104
|
+
let response = {
|
|
105
|
+
data: await this.readResponse(res, config.responseType),
|
|
106
|
+
status: res.status,
|
|
107
|
+
statusText: res.statusText,
|
|
108
|
+
headers: res.headers,
|
|
109
|
+
url: res.url
|
|
110
|
+
};
|
|
111
|
+
if (!res.ok) throw new HttpError(`Request failed with status ${res.status}`, response);
|
|
112
|
+
if (applyInterceptors) for (const interceptor of this.interceptors) response = await interceptor.onResponse?.(response) ?? response;
|
|
113
|
+
return response;
|
|
114
|
+
} finally {
|
|
115
|
+
if (timer) clearTimeout(timer);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
async readResponse(response, type) {
|
|
119
|
+
if (response.status === 204) return void 0;
|
|
120
|
+
if (type === "blob") return response.blob();
|
|
121
|
+
if (type === "arrayBuffer") return response.arrayBuffer();
|
|
122
|
+
if (type === "text") return response.text();
|
|
123
|
+
const text = await response.text();
|
|
124
|
+
if (text === "") return void 0;
|
|
125
|
+
if (!response.headers.get("content-type")?.includes("json")) try {
|
|
126
|
+
return JSON.parse(text);
|
|
127
|
+
} catch {
|
|
128
|
+
return text;
|
|
129
|
+
}
|
|
130
|
+
return JSON.parse(text);
|
|
131
|
+
}
|
|
132
|
+
resolveUrl(path, params) {
|
|
133
|
+
const baseURL = this.baseURL && !this.baseURL.endsWith("/") ? `${this.baseURL}/` : this.baseURL;
|
|
134
|
+
const url = /^https?:\/\//.test(path) ? new URL(path) : new URL(path.replace(/^\//, ""), baseURL || globalThis.location?.origin);
|
|
135
|
+
for (const [key, value] of Object.entries(params ?? {})) {
|
|
136
|
+
if (value == null) continue;
|
|
137
|
+
if (Array.isArray(value)) value.forEach((item) => url.searchParams.append(key, String(item)));
|
|
138
|
+
else url.searchParams.append(key, String(value));
|
|
139
|
+
}
|
|
140
|
+
return url.toString();
|
|
141
|
+
}
|
|
142
|
+
async runErrorInterceptors(error) {
|
|
143
|
+
let next = error;
|
|
144
|
+
for (const interceptor of [...this.interceptors].reverse()) if (interceptor.onError) try {
|
|
145
|
+
next = await interceptor.onError(next);
|
|
146
|
+
} catch (transformed) {
|
|
147
|
+
next = transformed;
|
|
148
|
+
}
|
|
149
|
+
return next;
|
|
150
|
+
}
|
|
151
|
+
uploadWithXhr(url, data, config, method) {
|
|
152
|
+
return new Promise((resolve, reject) => {
|
|
153
|
+
const xhr = new XMLHttpRequest();
|
|
154
|
+
xhr.open(method.toUpperCase(), url);
|
|
155
|
+
new Headers(config.headers).forEach((value, key) => xhr.setRequestHeader(key, value));
|
|
156
|
+
if (config.timeout) xhr.timeout = config.timeout;
|
|
157
|
+
xhr.upload.onprogress = ({ loaded, total }) => config.onUploadProgress?.({
|
|
158
|
+
loaded,
|
|
159
|
+
total
|
|
160
|
+
});
|
|
161
|
+
xhr.onload = () => xhr.status >= 200 && xhr.status < 300 ? resolve() : reject(/* @__PURE__ */ new Error(`Upload failed with status ${xhr.status}`));
|
|
162
|
+
xhr.onerror = () => reject(/* @__PURE__ */ new TypeError("Network request failed"));
|
|
163
|
+
xhr.ontimeout = () => reject(new DOMException("Request timed out", "TimeoutError"));
|
|
164
|
+
config.signal?.addEventListener("abort", () => xhr.abort(), { once: true });
|
|
165
|
+
xhr.onabort = () => reject(config.signal?.reason ?? new DOMException("Request aborted", "AbortError"));
|
|
166
|
+
xhr.send(data);
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
};
|
|
170
|
+
//#endregion
|
|
171
|
+
//#region src/lib/rest/native-rest-interceptor.ts
|
|
172
|
+
var NativeRestInterceptor = class {
|
|
173
|
+
interceptor;
|
|
174
|
+
constructor(interceptor) {
|
|
175
|
+
this.interceptor = interceptor;
|
|
176
|
+
}
|
|
177
|
+
onRequest(request) {
|
|
178
|
+
return this.interceptor.onRequest?.(request) ?? request;
|
|
179
|
+
}
|
|
180
|
+
onResponse(response) {
|
|
181
|
+
return this.interceptor.onResponse?.(response) ?? response;
|
|
182
|
+
}
|
|
183
|
+
onError(error) {
|
|
184
|
+
if (!this.interceptor.onError) throw error;
|
|
185
|
+
return this.interceptor.onError(error);
|
|
186
|
+
}
|
|
187
|
+
};
|
|
188
|
+
//#endregion
|
|
189
|
+
export { NativeRestClient as n, NativeRestInterceptor as t };
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { a as RestTransport, c as TransportRequestConfig, l as TransportResponse, o as RestTransportInterceptor, r as RestRequestInfo, s as TransportRequest, t as GeneralTransportErrorCode } from "./rest-transport.types-D0R9mvGH.mjs";
|
|
2
|
+
//#region src/lib/rest/native-rest-client.d.ts
|
|
3
|
+
type NativeResult<T, IsRawRes extends boolean> = IsRawRes extends true ? TransportResponse<T> : T;
|
|
4
|
+
declare class NativeRestClient implements RestTransport {
|
|
5
|
+
private readonly interceptors;
|
|
6
|
+
constructor({ config, interceptors }?: {
|
|
7
|
+
config?: {
|
|
8
|
+
baseURL?: string;
|
|
9
|
+
headers?: HeadersInit;
|
|
10
|
+
credentials?: RequestCredentials;
|
|
11
|
+
};
|
|
12
|
+
interceptors?: RestTransportInterceptor[];
|
|
13
|
+
});
|
|
14
|
+
private readonly baseURL;
|
|
15
|
+
private readonly headers?;
|
|
16
|
+
private readonly credentials?;
|
|
17
|
+
attachInterceptor(interceptor: RestTransportInterceptor): void;
|
|
18
|
+
ejectInterceptor(interceptor: RestTransportInterceptor): void;
|
|
19
|
+
get<T, E extends string = GeneralTransportErrorCode, R extends boolean = false>(info: RestRequestInfo<T, E>, url: string, config?: TransportRequestConfig<R>): Promise<NativeResult<T, R>>;
|
|
20
|
+
post<T, E extends string = GeneralTransportErrorCode, R extends boolean = false>(info: RestRequestInfo<T, E>, url: string, data?: unknown, config?: TransportRequestConfig<R>): Promise<NativeResult<T, R>>;
|
|
21
|
+
patch<T, E extends string = GeneralTransportErrorCode, R extends boolean = false>(info: RestRequestInfo<T, E>, url: string, data?: unknown, config?: TransportRequestConfig<R>): Promise<NativeResult<T, R>>;
|
|
22
|
+
put<T, E extends string = GeneralTransportErrorCode, R extends boolean = false>(info: RestRequestInfo<T, E>, url: string, data?: unknown, config?: TransportRequestConfig<R>): Promise<NativeResult<T, R>>;
|
|
23
|
+
delete<T, E extends string = GeneralTransportErrorCode, R extends boolean = false>(info: RestRequestInfo<T, E>, url: string, data?: unknown, config?: TransportRequestConfig<R>): Promise<NativeResult<T, R>>;
|
|
24
|
+
upload(url: string, data: BodyInit, config?: TransportRequestConfig, method?: "put" | "post"): Promise<void>;
|
|
25
|
+
private request;
|
|
26
|
+
private execute;
|
|
27
|
+
private readResponse;
|
|
28
|
+
private resolveUrl;
|
|
29
|
+
private runErrorInterceptors;
|
|
30
|
+
private uploadWithXhr;
|
|
31
|
+
}
|
|
32
|
+
//#endregion
|
|
33
|
+
//#region src/lib/rest/native-rest-interceptor.d.ts
|
|
34
|
+
type NativeInterceptor = RestTransportInterceptor;
|
|
35
|
+
declare class NativeRestInterceptor implements RestTransportInterceptor {
|
|
36
|
+
private readonly interceptor;
|
|
37
|
+
constructor(interceptor: RestTransportInterceptor);
|
|
38
|
+
onRequest(request: TransportRequest): Promise<TransportRequest> | TransportRequest;
|
|
39
|
+
onResponse<T>(response: TransportResponse<T>): Promise<TransportResponse<T>> | TransportResponse<T>;
|
|
40
|
+
onError(error: unknown): unknown;
|
|
41
|
+
}
|
|
42
|
+
//#endregion
|
|
43
|
+
export { NativeRestInterceptor as n, NativeRestClient as r, NativeInterceptor as t };
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { a as RestTransport, c as TransportRequestConfig, d as UploadProgress, i as RestResponseType, l as TransportResponse, n as HttpError, o as RestTransportInterceptor, r as RestRequestInfo, s as TransportRequest, t as GeneralTransportErrorCode, u as TransportResult } from "./rest-transport.types-D0R9mvGH.mjs";
|
|
2
|
+
import { n as NativeRestInterceptor, r as NativeRestClient, t as NativeInterceptor } from "./native-rest-interceptor-CTBBx6B3.mjs";
|
|
3
|
+
export { type GeneralTransportErrorCode, HttpError, HttpError as NativeHttpError, type NativeInterceptor, type TransportRequest as NativeRequest, type TransportRequest, type TransportRequestConfig as NativeRequestConfig, type TransportRequestConfig, type TransportResponse as NativeResponse, type TransportResponse, NativeRestClient, NativeRestInterceptor, type UploadProgress as NativeUploadProgress, type UploadProgress, type RestRequestInfo, type RestResponseType, type RestTransport, type RestTransportInterceptor, type TransportResult };
|
package/dist/native.mjs
ADDED
|
Binary file
|
|
Binary file
|
|
Binary file
|