@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.
Files changed (36) hide show
  1. package/README.md +42 -1
  2. package/dist/acl.mjs +1 -1
  3. package/dist/{config-mWuUhYNE.d.mts → config-DgrOddSC.d.mts} +1 -1
  4. package/dist/{error-handling-DDIXMA-R.mjs → error-handling-BMXC5P08.mjs} +22 -12
  5. package/dist/{generate.runner-BxdZdYX4.mjs → generate.runner-DVcx7AGc.mjs} +15 -8
  6. package/dist/{generate.utils-1rU0zIjA.cjs → generate.utils-CH2U2Dpr.cjs} +36 -5
  7. package/dist/{generateCodeFromOpenAPIDoc-5VZFVFK1.cjs → generateCodeFromOpenAPIDoc-D5lsVuPN.cjs} +48 -24
  8. package/dist/{generateCodeFromOpenAPIDoc-BOuCcW6U.mjs → generateCodeFromOpenAPIDoc-eAxTI0c4.mjs} +49 -25
  9. package/dist/generator.d.mts +1 -1
  10. package/dist/generator.mjs +3 -3
  11. package/dist/{getDataFromOpenAPIDoc-CkIfezoI.mjs → getDataFromOpenAPIDoc-BnQYK4sW.mjs} +1 -1
  12. package/dist/index.d.mts +4 -2
  13. package/dist/index.mjs +4 -2
  14. package/dist/metro.cjs +3 -3
  15. package/dist/metro.d.mts +3 -3
  16. package/dist/metro.mjs +1 -1
  17. package/dist/native-rest-interceptor-Bcc2jx4e.mjs +189 -0
  18. package/dist/native-rest-interceptor-CTBBx6B3.d.mts +43 -0
  19. package/dist/native.d.mts +3 -0
  20. package/dist/native.mjs +3 -0
  21. package/dist/openapi-codegen-native-darwin-arm64.node +0 -0
  22. package/dist/openapi-codegen-native-linux-x64.node +0 -0
  23. package/dist/openapi-codegen-native-win32-x64.node +0 -0
  24. package/dist/{openapi-codegen.runner-fS_gOezd.mjs → openapi-codegen.runner-D7ZTawpO.mjs} +1 -1
  25. package/dist/{openapi-source.runner-DmJoXvFj.d.mts → openapi-source.runner-ykstqlPC.d.mts} +1 -1
  26. package/dist/{options-B47gUU4P.d.mts → options-KPf-Fti5.d.mts} +1 -0
  27. package/dist/rest-transport.types-D0R9mvGH.d.mts +59 -0
  28. package/dist/rest-transport.types-DxitRtsB.mjs +11 -0
  29. package/dist/rest.d.mts +2 -0
  30. package/dist/rest.mjs +2 -0
  31. package/dist/sh.mjs +8 -3
  32. package/dist/tiny.d.mts +1 -1
  33. package/dist/vite.d.mts +3 -3
  34. package/dist/vite.mjs +1 -1
  35. package/dist/zod.mjs +1 -1
  36. package/package.json +9 -1
@@ -1,5 +1,5 @@
1
- import { r as getZodSchemaRefs, t as getDataFromOpenAPIDoc } from "./getDataFromOpenAPIDoc-CkIfezoI.mjs";
2
- import { $ as getImportedAbilityFunctionName, $t as isParamMediaTypeAllowed, A as getEndpointsImports, B as getPrefetchInfiniteQueryName, Bt as QUERY_MODULE_ENUM, C as getAppRestClientImportPath, Ct as isReadEndpoint, D as getTagFileName, Dn as AXIOS_IMPORT, E as getQueryTypesImportPath, En as AXIOS_DEFAULT_IMPORT_NAME, F as mergeImports, Ft as APP_REST_CLIENT_NAME, G as getAbilityConditionType, H as getQueryName, Ht as ZOD_EXTENDED, I as getImportedInfiniteQueryName, In as shouldInlineEndpointsForTag, It as BUILDERS_UTILS, J as getAbilityFunctionName, K as getAbilityConditionsTypes, L as getImportedQueryName, Ln as camelToSpaceSeparated, Lt as DOMAIN_ERRORS_FILE, M as getInfiniteQueriesImports, Mt as isEnumZodSchema, N as getModelsImports, Nn as getEndpointTag, Nt as isNamedZodSchema, O as getTagImportPath, On as AXIOS_REQUEST_CONFIG_NAME, P as getQueriesImports, Pt as APP_REST_CLIENT_FILE, Q as getAppAbilitiesType, R as getInfiniteQueryName, Rn as capitalize, Rt as MUTATION_EFFECTS, St as isReadAllEndpoint, T as getQueryModulesImportPath, Tn as ZOD_IMPORT, Tt as invalidVariableNameCharactersToCamel, U as getQueryOptionsName, Ut as PACKAGE_IMPORT_PATH, V as getPrefetchQueryName, Vn as kebabToCamel, Vt as QUERY_OPTIONS_TYPES, W as getAbilityAction, Wn as Profiler, Wt as getNamespaceName, 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, dn as isSchemaObject, dt as DEFAULT_GENERATE_OPTIONS, et as hasAbilityConditions, f as getEndpointBody, ft as ACL_APP_ABILITIES, g as getImportedEndpointName, gt as CASL_ABILITY_IMPORT, h as getEndpointPath, ht as CASL_ABILITY_BINDING, i as shouldUseNativeCodegen, it as getZodSchemaDescription, j as getImportPath, jn as JSON_APPLICATION_FORMAT, k as getAclImports, kn as AXIOS_REQUEST_CONFIG_TYPE, l as isInfiniteQuery, m as getEndpointName, mn as ANY_SCHEMA, mt as ACL_CHECK_HOOK, nt as getImportedZodSchemaInferedTypeName, o as getOutputFileName, ot as getZodSchemaPropertyDescriptions, p as getEndpointConfig, pt as ACL_APP_ABILITY_FILE, q as getAbilityDescription, r as compileNativeData, rt as getImportedZodSchemaName, st as getZodSchemaType, tt as renderAclCheckCall, u as isMutation, un as isReferenceObject, 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-BxdZdYX4.mjs";
1
+ import { r as getZodSchemaRefs, t as getDataFromOpenAPIDoc } from "./getDataFromOpenAPIDoc-BnQYK4sW.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-DVcx7AGc.mjs";
3
3
  import "node:module";
4
4
  //#region \0rolldown/runtime.js
5
5
  var __defProp = Object.defineProperty;
@@ -419,14 +419,20 @@ 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 hasAxiosDefaultImport = endpoints.some((e) => e.mediaUpload);
423
- const hasAxiosImport = hasAxiosRequestConfig || hasAxiosDefaultImport;
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
+ };
430
436
  const endpointsImports = getEndpointsImports({
431
437
  tag,
432
438
  endpoints,
@@ -466,6 +472,7 @@ function generateConfigs(generateTypeParams) {
466
472
  };
467
473
  const lines = [];
468
474
  if (hasAxiosImport) lines.push(renderImport$3(axiosImport));
475
+ if (nativeImport.typeBindings?.length) lines.push(renderImport$3(nativeImport));
469
476
  if (hasZodImport) lines.push(renderImport$3(ZOD_IMPORT));
470
477
  if (hasDynamicInputsImport) lines.push(renderImport$3(dynamicInputsImport));
471
478
  if (hasDynamicColumnsImport) lines.push(renderImport$3(dynamicColumnsImport));
@@ -541,7 +548,7 @@ function renderMutationContent(resolver, endpoint, tag) {
541
548
  const endpointFunction = getImportedEndpointName(endpoint, resolver.options);
542
549
  const mutationVariablesType = endpoint.mediaUpload ? `{ ${endpointParamsStr}${endpointParamsStr ? "; " : ""}abortController?: AbortController; onUploadProgress?: (progress: { loaded: number; total: number }) => void }` : `{ ${endpointParamsStr} }`;
543
550
  const lines = [];
544
- lines.push(`(options?: AppMutationOptions<typeof ${endpointFunction}, ${mutationVariablesType}>${hasMutationEffects ? ` & ${MUTATION_EFFECTS.optionsType}` : ""}${hasAxiosRequestConfig ? `, config?: ${AXIOS_REQUEST_CONFIG_TYPE}` : ""}) => {`);
551
+ lines.push(`(options?: AppMutationOptions<typeof ${endpointFunction}, ${mutationVariablesType}>${hasMutationEffects ? ` & ${MUTATION_EFFECTS.optionsType}` : ""}${hasAxiosRequestConfig ? `, config?: ${getRequestConfigTypeName(resolver.options.restClient)}` : ""}) => {`);
545
552
  if (hasMutationDefaultOnError) lines.push(" const queryConfig = OpenApiQueryConfig.useConfig();");
546
553
  if (hasMutationEffects) lines.push(` const { runMutationEffects } = useMutationEffects<${QUERY_MODULE_ENUM}.${endpointTag}>({ currentModule: ${QUERY_MODULE_ENUM}.${tag} });`);
547
554
  if (hasAclCheck) lines.push(` const { checkAcl } = ${ACL_CHECK_HOOK}();`);
@@ -643,12 +650,18 @@ function generateEndpoints({ resolver, data, tag }) {
643
650
  };
644
651
  const hasAxiosRequestConfig = resolver.options.axiosRequestConfig;
645
652
  const hasGetEndpoints = endpoints.some((endpoint) => endpoint.method === "get");
646
- const hasAxiosImport = hasAxiosRequestConfig || hasGetEndpoints;
653
+ const nativeClient = resolver.options.restClient === "native";
654
+ const hasAxiosImport = !nativeClient && (hasAxiosRequestConfig || hasGetEndpoints);
647
655
  const axiosImport = {
648
656
  bindings: [],
649
657
  typeBindings: hasAxiosImport ? [AXIOS_REQUEST_CONFIG_TYPE] : [],
650
658
  from: AXIOS_IMPORT.from
651
659
  };
660
+ const nativeImport = {
661
+ bindings: [],
662
+ typeBindings: nativeClient && (hasAxiosRequestConfig || hasGetEndpoints) ? [getRequestConfigTypeName("native")] : [],
663
+ from: REST_PACKAGE_IMPORT_PATH
664
+ };
652
665
  const generateParse = resolver.options.parseRequestParams;
653
666
  const endpointParams = endpoints.flatMap((endpoint) => endpoint.parameters);
654
667
  const endpointParamsParseSchemas = endpointParams.filter((param) => !["Path", "Header"].includes(param.type)).map((param) => param.parameterSortingEnumSchemaName ?? param.zodSchema);
@@ -669,6 +682,7 @@ function generateEndpoints({ resolver, data, tag }) {
669
682
  const lines = [];
670
683
  lines.push(renderImport$2(appRestClientImport));
671
684
  if (hasAxiosImport) lines.push(renderImport$2(axiosImport));
685
+ if (nativeImport.typeBindings?.length) lines.push(renderImport$2(nativeImport));
672
686
  if (hasZodImport) lines.push(renderImport$2(ZOD_IMPORT));
673
687
  if (hasZodExtendedImport) lines.push(renderImport$2(zodExtendedImport));
674
688
  for (const modelsImport of modelsImports) lines.push(renderImport$2(modelsImport));
@@ -686,7 +700,7 @@ function generateEndpoints({ resolver, data, tag }) {
686
700
  const hasUndefinedEndpointBody = requiresBody(endpoint) && !endpointBody && hasEndpointConfig(endpoint, resolver);
687
701
  const endpointConfig = renderEndpointConfig(resolver, endpoint, tag);
688
702
  const hasRequestConfigParam = hasAxiosRequestConfig || endpoint.method === "get";
689
- lines.push(`export const ${getEndpointName(endpoint)} = (${endpointParams}${hasRequestConfigParam ? `${AXIOS_REQUEST_CONFIG_NAME}?: ${getRequestConfigType$1()}` : ""}) => {`);
703
+ lines.push(`export const ${getEndpointName(endpoint)} = (${endpointParams}${hasRequestConfigParam ? `${AXIOS_REQUEST_CONFIG_NAME}?: ${getRequestConfigType$1(resolver)}` : ""}) => {`);
690
704
  lines.push(` return ${APP_REST_CLIENT_NAME}.${endpoint.method}(`);
691
705
  lines.push(` ${renderRequestInfo(resolver, endpoint, tag)},`);
692
706
  lines.push(` \`${getEndpointPath(endpoint)}\`,`);
@@ -702,8 +716,8 @@ function generateEndpoints({ resolver, data, tag }) {
702
716
  function renderRequestInfo(resolver, endpoint, tag) {
703
717
  return `{ resSchema: ${getImportedZodSchemaName(resolver, endpoint.response, (resolver.options.modelsInCommon || resolver.options.modelsInModules) && resolver.options.splitByTags ? tag : void 0)} }`;
704
718
  }
705
- function getRequestConfigType$1() {
706
- return `${AXIOS_REQUEST_CONFIG_TYPE} & { allowInvalidResponseData?: boolean }`;
719
+ function getRequestConfigType$1(resolver) {
720
+ return `${getRequestConfigTypeName(resolver.options.restClient)} & { allowInvalidResponseData?: boolean }`;
707
721
  }
708
722
  function renderImport$2(importData) {
709
723
  const namedImports = [...importData.bindings, ...(importData.typeBindings ?? []).map((binding) => importData.typeOnly ? binding : `type ${binding}`)];
@@ -914,15 +928,22 @@ function generateQueries(params) {
914
928
  if (!endpoints || endpoints.length === 0) return;
915
929
  const endpointGroups = groupEndpoints(endpoints, resolver);
916
930
  const hasAxiosRequestConfig = resolver.options.axiosRequestConfig;
917
- const hasAxiosDefaultImport = endpoints.some(({ mediaUpload }) => mediaUpload);
931
+ const nativeClient = resolver.options.restClient === "native";
932
+ const requestConfigType = getRequestConfigTypeName(resolver.options.restClient);
933
+ const hasAxiosDefaultImport = !nativeClient && endpoints.some(({ mediaUpload }) => mediaUpload);
918
934
  const hasGetEndpoints = endpoints.some((endpoint) => endpoint.method === "get");
919
- const hasAxiosImport = hasAxiosRequestConfig || hasAxiosDefaultImport || hasGetEndpoints;
935
+ const hasAxiosImport = !nativeClient && (hasAxiosRequestConfig || hasAxiosDefaultImport || hasGetEndpoints);
920
936
  const axiosImport = {
921
937
  defaultImport: hasAxiosDefaultImport ? AXIOS_DEFAULT_IMPORT_NAME : void 0,
922
938
  bindings: [],
923
939
  typeBindings: hasAxiosImport ? [AXIOS_REQUEST_CONFIG_TYPE] : [],
924
940
  from: AXIOS_IMPORT.from
925
941
  };
942
+ const nativeTransportImport = {
943
+ bindings: [],
944
+ typeBindings: nativeClient ? [...hasAxiosRequestConfig || hasGetEndpoints ? [requestConfigType] : [], ...endpoints.some(({ mediaDownload }) => mediaDownload) ? [NATIVE_RESPONSE_TYPE] : []] : [],
945
+ from: REST_PACKAGE_IMPORT_PATH
946
+ };
926
947
  const { queryEndpoints, infiniteQueryEndpoints, mutationEndpoints, aclEndpoints } = endpointGroups;
927
948
  const hasMutationDefaultOnError = resolver.options.mutationDefaultOnError && mutationEndpoints.length > 0;
928
949
  const queryImport = {
@@ -1001,6 +1022,7 @@ function generateQueries(params) {
1001
1022
  });
1002
1023
  const lines = [];
1003
1024
  if (hasAxiosImport) lines.push(renderImport(axiosImport));
1025
+ if (nativeTransportImport.typeBindings?.length) lines.push(renderImport(nativeTransportImport));
1004
1026
  if (inlineEndpoints) {
1005
1027
  lines.push(renderImport(appRestClientImport));
1006
1028
  if (hasZodImport) lines.push(renderImport(ZOD_IMPORT));
@@ -1233,8 +1255,9 @@ function renderQueryJsDocs({ resolver, endpoint, mode, tag }) {
1233
1255
  if (mode === "query") lines.push(" * @param { AppQueryOptions } options Query options");
1234
1256
  else if (mode === "mutation") lines.push(` * @param { AppMutationOptions${resolver.options.mutationEffects ? ` & ${MUTATION_EFFECTS.optionsType}` : ""} } options Mutation options`);
1235
1257
  else lines.push(" * @param { AppInfiniteQueryOptions } options Infinite query options");
1236
- const withAxiosResponse = endpoint.mediaDownload && mode !== "infiniteQuery";
1237
- const resultType = `${withAxiosResponse ? "AxiosResponse<" : ""}${getImportedZodSchemaInferedTypeName(resolver, endpoint.response, void 0, tag)}${withAxiosResponse ? ">" : ""}`;
1258
+ const withRawResponse = endpoint.mediaDownload && mode !== "infiniteQuery";
1259
+ const responseType = resolver.options.restClient === "native" ? NATIVE_RESPONSE_TYPE : "AxiosResponse";
1260
+ const resultType = `${withRawResponse ? `${responseType}<` : ""}${getImportedZodSchemaInferedTypeName(resolver, endpoint.response, void 0, tag)}${withRawResponse ? ">" : ""}`;
1238
1261
  if (mode === "query") lines.push(` * @returns { UseQueryResult<${resultType}> } ${endpoint.responseDescription ?? ""}`);
1239
1262
  else if (mode === "mutation") lines.push(` * @returns { UseMutationResult<${resultType}> } ${endpoint.responseDescription ?? ""}`);
1240
1263
  else lines.push(` * @returns { UseInfiniteQueryResult<${resultType}> } ${endpoint.responseDescription ?? ""}`);
@@ -1269,7 +1292,7 @@ function renderInlineEndpoints({ resolver, endpoints, tag }) {
1269
1292
  const hasUndefinedEndpointBody = requiresBody(endpoint) && !endpointBody && hasEndpointConfig(endpoint, resolver);
1270
1293
  const endpointConfig = renderInlineEndpointConfig(resolver, endpoint, tag);
1271
1294
  const hasRequestConfigParam = resolver.options.axiosRequestConfig || endpoint.method === "get";
1272
- lines.push(`const ${getEndpointName(endpoint)} = (${endpointParams}${hasRequestConfigParam ? `${endpointParams ? ", " : ""}${AXIOS_REQUEST_CONFIG_NAME}?: ${getRequestConfigType()}` : ""}) => {`);
1295
+ lines.push(`const ${getEndpointName(endpoint)} = (${endpointParams}${hasRequestConfigParam ? `${endpointParams ? ", " : ""}${AXIOS_REQUEST_CONFIG_NAME}?: ${getRequestConfigType(resolver)}` : ""}) => {`);
1273
1296
  lines.push(` return ${APP_REST_CLIENT_NAME}.${endpoint.method}(`);
1274
1297
  lines.push(` ${renderInlineRequestInfo(resolver, endpoint, tag)},`);
1275
1298
  lines.push(` \`${getEndpointPath(endpoint)}\`,`);
@@ -1285,8 +1308,8 @@ function renderInlineEndpoints({ resolver, endpoints, tag }) {
1285
1308
  function renderInlineRequestInfo(resolver, endpoint, tag) {
1286
1309
  return `{ resSchema: ${getImportedZodSchemaName(resolver, endpoint.response, tag)} }`;
1287
1310
  }
1288
- function getRequestConfigType() {
1289
- return `${AXIOS_REQUEST_CONFIG_TYPE} & { allowInvalidResponseData?: boolean }`;
1311
+ function getRequestConfigType(resolver) {
1312
+ return `${getRequestConfigTypeName(resolver.options.restClient)} & { allowInvalidResponseData?: boolean }`;
1290
1313
  }
1291
1314
  function renderRequestConfigWithSignal(hasRequestConfigParam) {
1292
1315
  return `{ ${hasRequestConfigParam ? `...${AXIOS_REQUEST_CONFIG_NAME}, ` : ""}signal }`;
@@ -1335,7 +1358,7 @@ function renderQueryOptions({ resolver, endpoint, inlineEndpoints }) {
1335
1358
  const endpointArgs = renderEndpointArgs(resolver, endpoint, {});
1336
1359
  const endpointFunction = inlineEndpoints ? getEndpointName(endpoint) : getImportedEndpointName(endpoint, resolver.options);
1337
1360
  const lines = [];
1338
- lines.push(`const ${getQueryOptionsName(endpoint)} = (${endpointParams ? `{ ${endpointArgs} }: { ${endpointParams} }` : ""}${hasRequestConfigParam ? `${endpointParams ? ", " : ""}${AXIOS_REQUEST_CONFIG_NAME}?: ${getRequestConfigType()}` : ""}) => ({`);
1361
+ lines.push(`const ${getQueryOptionsName(endpoint)} = (${endpointParams ? `{ ${endpointArgs} }: { ${endpointParams} }` : ""}${hasRequestConfigParam ? `${endpointParams ? ", " : ""}${AXIOS_REQUEST_CONFIG_NAME}?: ${getRequestConfigType(resolver)}` : ""}) => ({`);
1339
1362
  lines.push(` queryKey: keys.${getEndpointName(endpoint)}(${endpointArgs}),`);
1340
1363
  const requestConfigWithSignal = renderRequestConfigWithSignal(hasRequestConfigParam);
1341
1364
  lines.push(` queryFn: ({ signal }: { signal: AbortSignal }) => ${endpointFunction}(${endpointArgs}${hasRequestConfigParam ? `${endpointArgs ? ", " : ""}${requestConfigWithSignal}` : ""}),`);
@@ -1352,7 +1375,7 @@ function renderInfiniteQueryOptions({ resolver, endpoint, inlineEndpoints }) {
1352
1375
  const endpointArgsWithPage = renderEndpointArgs(resolver, endpoint, { replacePageParam: true });
1353
1376
  const endpointFunction = inlineEndpoints ? getEndpointName(endpoint) : getImportedEndpointName(endpoint, resolver.options);
1354
1377
  const lines = [];
1355
- lines.push(`const ${getInfiniteQueryOptionsName(endpoint)} = (${endpointParams ? `{ ${endpointArgsWithoutPage} }: { ${endpointParams} }` : ""}${hasRequestConfigParam ? `${endpointParams ? ", " : ""}${AXIOS_REQUEST_CONFIG_NAME}?: ${getRequestConfigType()}` : ""}) => ({`);
1378
+ lines.push(`const ${getInfiniteQueryOptionsName(endpoint)} = (${endpointParams ? `{ ${endpointArgsWithoutPage} }: { ${endpointParams} }` : ""}${hasRequestConfigParam ? `${endpointParams ? ", " : ""}${AXIOS_REQUEST_CONFIG_NAME}?: ${getRequestConfigType(resolver)}` : ""}) => ({`);
1356
1379
  lines.push(` queryKey: keys.${getEndpointName(endpoint)}Infinite(${endpointArgsWithoutPage}),`);
1357
1380
  const requestConfigWithSignal = renderRequestConfigWithSignal(hasRequestConfigParam);
1358
1381
  lines.push(` queryFn: ({ pageParam, signal }: { pageParam: number; signal: AbortSignal }) => ${endpointFunction}(${endpointArgsWithPage}${hasRequestConfigParam ? `, ${requestConfigWithSignal}` : ""}),`);
@@ -1369,7 +1392,7 @@ function renderPrefetchQuery({ resolver, endpoint }) {
1369
1392
  const endpointParams = renderEndpointParams(resolver, endpoint, { modelNamespaceTag: getEndpointTag(endpoint, resolver.options) });
1370
1393
  const endpointArgs = renderEndpointArgs(resolver, endpoint, {});
1371
1394
  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}?: ${AXIOS_REQUEST_CONFIG_TYPE}, ` : ""}throwOnError = false) => {`);
1395
+ 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
1396
  lines.push(` const queryOptions = { ...${getQueryOptionsName(endpoint)}(${endpointParams ? `{ ${endpointArgs} }` : ""}${hasRequestConfigParam ? `${endpointParams ? ", " : ""}${AXIOS_REQUEST_CONFIG_NAME}` : ""}), ...options };`);
1374
1397
  lines.push(` return throwOnError ? queryClient.fetchQuery(queryOptions) : queryClient.prefetchQuery(queryOptions);`);
1375
1398
  lines.push("};");
@@ -1384,7 +1407,7 @@ function renderPrefetchInfiniteQuery({ resolver, endpoint }) {
1384
1407
  const endpointArgs = renderEndpointArgs(resolver, endpoint, { excludePageParam: true });
1385
1408
  const optionsArgs = `${endpointParams ? `{ ${endpointArgs} }` : ""}${hasRequestConfigParam ? `${endpointParams ? ", " : ""}${AXIOS_REQUEST_CONFIG_NAME}` : ""}`;
1386
1409
  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}?: ${AXIOS_REQUEST_CONFIG_TYPE}, ` : ""}throwOnError = false) => {`);
1410
+ 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
1411
  lines.push(` const queryOptions = { ...${getInfiniteQueryOptionsName(endpoint)}(${optionsArgs}), ...(options as {}) };`);
1389
1412
  lines.push(` return throwOnError ? queryClient.fetchInfiniteQuery(queryOptions) : queryClient.prefetchInfiniteQuery(queryOptions);`);
1390
1413
  lines.push("};");
@@ -1413,7 +1436,7 @@ function renderQuery({ resolver, endpoint, inlineEndpoints }) {
1413
1436
  mode: "query",
1414
1437
  tag
1415
1438
  }));
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}?: ${AXIOS_REQUEST_CONFIG_TYPE}` : ""}) => {`);
1439
+ 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
1440
  lines.push(" const queryConfig = OpenApiQueryConfig.useConfig();");
1418
1441
  if (hasAclCheck) lines.push(` const { checkAcl } = ${ACL_CHECK_HOOK}();`);
1419
1442
  lines.push(...renderWorkspaceParamResolutions({
@@ -1483,7 +1506,7 @@ function renderMutation({ resolver, endpoint, inlineEndpoints, precomputed }) {
1483
1506
  mode: "mutation",
1484
1507
  tag
1485
1508
  }));
1486
- lines.push(`export const ${getQueryName(endpoint, true)} = (${pathParamFirstArg}options?: AppMutationOptions<typeof ${endpointFunction}${mutationOptionsTypeArg}>${hasMutationEffects ? ` & ${MUTATION_EFFECTS.optionsType}` : ""}${hasAxiosRequestConfig ? `, ${AXIOS_REQUEST_CONFIG_NAME}?: ${AXIOS_REQUEST_CONFIG_TYPE}` : ""}) => {`);
1509
+ 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
1510
  if (hasMutationDefaultOnError) lines.push(" const queryConfig = OpenApiQueryConfig.useConfig();");
1488
1511
  if (hasAclCheck) lines.push(` const { checkAcl } = ${ACL_CHECK_HOOK}();`);
1489
1512
  lines.push(...renderWorkspaceContextDestructure({
@@ -1602,7 +1625,7 @@ function renderInfiniteQuery({ resolver, endpoint, inlineEndpoints }) {
1602
1625
  mode: "infiniteQuery",
1603
1626
  tag
1604
1627
  }));
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}?: ${AXIOS_REQUEST_CONFIG_TYPE}` : ""}) => {`);
1628
+ 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
1629
  lines.push(" const queryConfig = OpenApiQueryConfig.useConfig();");
1607
1630
  if (hasAclCheck) lines.push(` const { checkAcl } = ${ACL_CHECK_HOOK}();`);
1608
1631
  lines.push(...renderWorkspaceParamResolutions({
@@ -1627,9 +1650,10 @@ function renderInfiniteQuery({ resolver, endpoint, inlineEndpoints }) {
1627
1650
  //#endregion
1628
1651
  //#region src/generators/generate/generateAppRestClient.ts
1629
1652
  function generateAppRestClient(resolver) {
1630
- return `import { RestClient } from "${PACKAGE_IMPORT_PATH}";
1653
+ const clientName = resolver.options.restClient === "native" ? "NativeRestClient" : "RestClient";
1654
+ return `import { ${clientName} } from "${resolver.options.restClient === "native" ? NATIVE_PACKAGE_IMPORT_PATH : PACKAGE_IMPORT_PATH}";
1631
1655
 
1632
- export const ${APP_REST_CLIENT_NAME} = new RestClient({
1656
+ export const ${APP_REST_CLIENT_NAME} = new ${clientName}({
1633
1657
  config: {
1634
1658
  baseURL: "${resolver.getBaseUrl()}"
1635
1659
  },
@@ -1,4 +1,4 @@
1
- import { n as GenerateFileData, t as GenerateOptions } from "./options-B47gUU4P.mjs";
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 {
@@ -1,6 +1,6 @@
1
- import { t as generateCodeFromOpenAPIDoc } from "./generateCodeFromOpenAPIDoc-BOuCcW6U.mjs";
2
- import { t as getDataFromOpenAPIDoc } from "./getDataFromOpenAPIDoc-CkIfezoI.mjs";
3
- import { $t as isParamMediaTypeAllowed, H as getQueryName, Mn as formatTag, O as getTagImportPath, Qt as isMediaTypeAllowed, S as getTsTypeBase, Tt as invalidVariableNameCharactersToCamel, Wt as getNamespaceName, d as isQuery, dt as DEFAULT_GENERATE_OPTIONS, t as getOpenApiDoc, u as isMutation, x as getSchemaTsMetaType } from "./generate.runner-BxdZdYX4.mjs";
1
+ import { t as generateCodeFromOpenAPIDoc } from "./generateCodeFromOpenAPIDoc-eAxTI0c4.mjs";
2
+ import { t as getDataFromOpenAPIDoc } from "./getDataFromOpenAPIDoc-BnQYK4sW.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-DVcx7AGc.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 isParamMediaTypeAllowed, An as BODY_PARAMETER_NAME, At as getZodSchemaName, Bn as getMostCommonAdjacentCombinationSplit, Cn as UUID_SCHEMA, Dt as getEnumZodSchemaName, Et as getBodyZodSchemaName, Fn as isTagIncluded, Gt as autocorrectRef, Hn as removeWord, Jt as getSchemaNameByRef, Kt as escapeControlCharacters, Mn as formatTag, Nn as getEndpointTag, Nt as isNamedZodSchema, Ot as getParamZodSchemaName, Pn as getOperationTag, Qt as isMediaTypeAllowed, Rn as capitalize, Sn as URL_SCHEMA, Tt as invalidVariableNameCharactersToCamel, Un as snakeToCamel, Wn as Profiler, Wt as getNamespaceName, Xt as isErrorStatus, Yt as getSchemaRef, Zt as isMainResponseStatus, _n as EMAIL_SCHEMA, an as replaceHyphenatedPath, bn as NUMBER_SCHEMA, cn as inferRequiredSchema, d as isQuery, dn as isSchemaObject, en as isPathExcluded, fn as ALLOWED_METHODS, gn as DATETIME_SCHEMA, hn as BLOB_SCHEMA, in as pathToVariableName, jn as JSON_APPLICATION_FORMAT, jt as getZodSchemaOperationName, kt as getResponseZodSchemaName, ln as isArraySchemaObject, lt as iterateSchema, mn as ANY_SCHEMA, nn as isSortingParameterObject, on as unwrapQuotesIfNeeded, pn as ALLOWED_PATH_IN, qt as getParameterEnumNames, rn as pathParamToVariableName, s as pick, sn as wrapWithQuotesIfNeeded, tn as isPrimitiveType, un as isReferenceObject, ut as getUniqueArray, vn as ENUM_SCHEMA, wn as VOID_SCHEMA, xn as STRING_SCHEMA, yn as INT_SCHEMA, zn as decapitalize } from "./generate.runner-BxdZdYX4.mjs";
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-DVcx7AGc.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-mWuUhYNE.mjs";
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-DDIXMA-R.mjs";
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-1rU0zIjA.cjs");
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-5VZFVFK1.cjs"));
100
+ const { generateCodeFromOpenAPIDoc } = await Promise.resolve().then(() => require("./generateCodeFromOpenAPIDoc-D5lsVuPN.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-B47gUU4P.mjs";
2
- import { t as OpenAPICodegenConfig } from "./config-mWuUhYNE.mjs";
3
- import { d as GenerateOpenApiFile, m as GenerateOpenApiSpec, n as TinyOpenApiSpecModuleConfig } from "./openapi-source.runner-DmJoXvFj.mjs";
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-fS_gOezd.mjs";
1
+ import { t as createOpenApiCodegenRunner } from "./openapi-codegen.runner-D7ZTawpO.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 };
@@ -0,0 +1,3 @@
1
+ import { t as HttpError } from "./rest-transport.types-DxitRtsB.mjs";
2
+ import { n as NativeRestClient, t as NativeRestInterceptor } from "./native-rest-interceptor-Bcc2jx4e.mjs";
3
+ export { HttpError, HttpError as NativeHttpError, NativeRestClient, NativeRestInterceptor };
@@ -1,4 +1,4 @@
1
- import { Wn as Profiler, n as runGenerate } from "./generate.runner-BxdZdYX4.mjs";
1
+ import { Jn as Profiler, n as runGenerate } from "./generate.runner-DVcx7AGc.mjs";
2
2
  import path from "path";
3
3
  //#region src/plugins/openapi-codegen.runner.ts
4
4
  function createOpenApiCodegenRunner(config, options = {}) {