@povio/openapi-codegen-cli 3.2.0-rc.6 → 3.2.0-rc.8

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.
@@ -1592,7 +1592,7 @@ async function runGenerate({ fileConfig, params, formatGeneratedFile, profiler =
1592
1592
  const nativeFiles = generateFilesFromNativeOpenAPI(nativeInput.source, nativeInput.yaml, config);
1593
1593
  if (nativeFiles) return nativeFiles;
1594
1594
  }
1595
- const { generateCodeFromOpenAPIDoc } = await import("./generateCodeFromOpenAPIDoc-eAxTI0c4.mjs").then((n) => n.n);
1595
+ const { generateCodeFromOpenAPIDoc } = await import("./generateCodeFromOpenAPIDoc-glAKBEGP.mjs").then((n) => n.n);
1596
1596
  return generateCodeFromOpenAPIDoc(openApiDoc, config, profiler, {
1597
1597
  source: nativeInput.source,
1598
1598
  yaml: nativeInput.yaml
@@ -2411,6 +2411,10 @@ function generateConfigs(generateTypeParams) {
2411
2411
  typeBindings: nativeClient && hasAxiosRequestConfig ? [require_generate_utils.getRequestConfigTypeName("native")] : [],
2412
2412
  from: require_generate_utils.REST_PACKAGE_IMPORT_PATH
2413
2413
  };
2414
+ const appRestClientImport = {
2415
+ bindings: [require_generate_utils.APP_REST_CLIENT_NAME],
2416
+ from: require_generate_utils.getAppRestClientImportPath(resolver.options)
2417
+ };
2414
2418
  const endpointsImports = require_generate_utils.getEndpointsImports({
2415
2419
  tag,
2416
2420
  endpoints,
@@ -2451,6 +2455,7 @@ function generateConfigs(generateTypeParams) {
2451
2455
  const lines = [];
2452
2456
  if (hasAxiosImport) lines.push(renderImport$3(axiosImport));
2453
2457
  if (nativeImport.typeBindings?.length) lines.push(renderImport$3(nativeImport));
2458
+ if (nativeClient && endpoints.some((endpoint) => endpoint.mediaUpload)) lines.push(renderImport$3(appRestClientImport));
2454
2459
  if (hasZodImport) lines.push(renderImport$3(require_generate_utils.ZOD_IMPORT));
2455
2460
  if (hasDynamicInputsImport) lines.push(renderImport$3(dynamicInputsImport));
2456
2461
  if (hasDynamicColumnsImport) lines.push(renderImport$3(dynamicColumnsImport));
@@ -2907,6 +2912,7 @@ function generateQueries(params) {
2907
2912
  const endpointGroups = groupEndpoints(endpoints, resolver);
2908
2913
  const hasAxiosRequestConfig = resolver.options.axiosRequestConfig;
2909
2914
  const nativeClient = resolver.options.restClient === "native";
2915
+ const hasNativeMediaUpload = nativeClient && endpoints.some(({ mediaUpload }) => mediaUpload);
2910
2916
  const requestConfigType = require_generate_utils.getRequestConfigTypeName(resolver.options.restClient);
2911
2917
  const hasAxiosDefaultImport = !nativeClient && endpoints.some(({ mediaUpload }) => mediaUpload);
2912
2918
  const hasGetEndpoints = endpoints.some((endpoint) => endpoint.method === "get");
@@ -3001,8 +3007,8 @@ function generateQueries(params) {
3001
3007
  const lines = [];
3002
3008
  if (hasAxiosImport) lines.push(renderImport(axiosImport));
3003
3009
  if (nativeTransportImport.typeBindings?.length) lines.push(renderImport(nativeTransportImport));
3010
+ if (inlineEndpoints || hasNativeMediaUpload) lines.push(renderImport(appRestClientImport));
3004
3011
  if (inlineEndpoints) {
3005
- lines.push(renderImport(appRestClientImport));
3006
3012
  if (hasZodImport) lines.push(renderImport(require_generate_utils.ZOD_IMPORT));
3007
3013
  if (hasZodExtendedImport) lines.push(renderImport(zodExtendedImport));
3008
3014
  }
@@ -1,5 +1,5 @@
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";
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;
@@ -433,6 +433,10 @@ function generateConfigs(generateTypeParams) {
433
433
  typeBindings: nativeClient && hasAxiosRequestConfig ? [getRequestConfigTypeName("native")] : [],
434
434
  from: REST_PACKAGE_IMPORT_PATH
435
435
  };
436
+ const appRestClientImport = {
437
+ bindings: [APP_REST_CLIENT_NAME],
438
+ from: getAppRestClientImportPath(resolver.options)
439
+ };
436
440
  const endpointsImports = getEndpointsImports({
437
441
  tag,
438
442
  endpoints,
@@ -473,6 +477,7 @@ function generateConfigs(generateTypeParams) {
473
477
  const lines = [];
474
478
  if (hasAxiosImport) lines.push(renderImport$3(axiosImport));
475
479
  if (nativeImport.typeBindings?.length) lines.push(renderImport$3(nativeImport));
480
+ if (nativeClient && endpoints.some((endpoint) => endpoint.mediaUpload)) lines.push(renderImport$3(appRestClientImport));
476
481
  if (hasZodImport) lines.push(renderImport$3(ZOD_IMPORT));
477
482
  if (hasDynamicInputsImport) lines.push(renderImport$3(dynamicInputsImport));
478
483
  if (hasDynamicColumnsImport) lines.push(renderImport$3(dynamicColumnsImport));
@@ -929,6 +934,7 @@ function generateQueries(params) {
929
934
  const endpointGroups = groupEndpoints(endpoints, resolver);
930
935
  const hasAxiosRequestConfig = resolver.options.axiosRequestConfig;
931
936
  const nativeClient = resolver.options.restClient === "native";
937
+ const hasNativeMediaUpload = nativeClient && endpoints.some(({ mediaUpload }) => mediaUpload);
932
938
  const requestConfigType = getRequestConfigTypeName(resolver.options.restClient);
933
939
  const hasAxiosDefaultImport = !nativeClient && endpoints.some(({ mediaUpload }) => mediaUpload);
934
940
  const hasGetEndpoints = endpoints.some((endpoint) => endpoint.method === "get");
@@ -1023,8 +1029,8 @@ function generateQueries(params) {
1023
1029
  const lines = [];
1024
1030
  if (hasAxiosImport) lines.push(renderImport(axiosImport));
1025
1031
  if (nativeTransportImport.typeBindings?.length) lines.push(renderImport(nativeTransportImport));
1032
+ if (inlineEndpoints || hasNativeMediaUpload) lines.push(renderImport(appRestClientImport));
1026
1033
  if (inlineEndpoints) {
1027
- lines.push(renderImport(appRestClientImport));
1028
1034
  if (hasZodImport) lines.push(renderImport(ZOD_IMPORT));
1029
1035
  if (hasZodExtendedImport) lines.push(renderImport(zodExtendedImport));
1030
1036
  }
@@ -1,6 +1,6 @@
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";
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 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";
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,7 +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
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
+ import { d as TransportResponse, l as TransportRequest, n as HttpError, p as UploadProgress, u as TransportRequestConfig } from "./rest-transport.types-DM5-qyOJ.mjs";
4
+ import { n as NativeRestInterceptor, r as NativeRestClient, t as NativeInterceptor } from "./native-rest-interceptor-Cz6saoq5.mjs";
5
5
  import { AxiosError, AxiosInstance, AxiosRequestConfig, AxiosResponse, AxiosResponseHeaders, CreateAxiosDefaults } from "axios";
6
6
  import { z } from "zod";
7
7
  import { PropsWithChildren, ReactNode } from "react";
package/dist/index.mjs CHANGED
@@ -1,6 +1,6 @@
1
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
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";
3
+ import { n as NativeRestClient, t as NativeRestInterceptor } from "./native-rest-interceptor-CAWR8H5Y.mjs";
4
4
  import { n as OpenApiRouter, t as AuthContext } from "./auth.context-YFWzkwoN.mjs";
5
5
  import axios from "axios";
6
6
  import { z } from "zod";
package/dist/metro.cjs CHANGED
@@ -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-D5lsVuPN.cjs"));
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.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { t as createOpenApiCodegenRunner } from "./openapi-codegen.runner-D7ZTawpO.mjs";
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";
@@ -7,11 +7,13 @@ var NativeRestClient = class {
7
7
  this.baseURL = config?.baseURL ?? "";
8
8
  this.headers = config?.headers;
9
9
  this.credentials = config?.credentials;
10
+ this.fetch = config?.fetch ?? globalThis.fetch.bind(globalThis);
10
11
  this.interceptors = [...interceptors];
11
12
  }
12
13
  baseURL;
13
14
  headers;
14
15
  credentials;
16
+ fetch;
15
17
  attachInterceptor(interceptor) {
16
18
  this.interceptors.push(interceptor);
17
19
  }
@@ -94,7 +96,7 @@ var NativeRestClient = class {
94
96
  else next.signal.addEventListener("abort", () => timeoutController.abort(next.signal?.reason), { once: true });
95
97
  const signal = timeoutController?.signal ?? next.signal;
96
98
  try {
97
- const res = await fetch(next.url, {
99
+ const res = await this.fetch(next.url, {
98
100
  method: next.method,
99
101
  headers: next.headers,
100
102
  body: next.body,
@@ -111,6 +113,19 @@ var NativeRestClient = class {
111
113
  if (!res.ok) throw new HttpError(`Request failed with status ${res.status}`, response);
112
114
  if (applyInterceptors) for (const interceptor of this.interceptors) response = await interceptor.onResponse?.(response) ?? response;
113
115
  return response;
116
+ } catch (error) {
117
+ if (!applyInterceptors) throw error;
118
+ const context = {
119
+ request: next,
120
+ response: error instanceof HttpError ? error.response : void 0,
121
+ retry: (request = next) => this.execute({
122
+ ...request,
123
+ retryCount: (next.retryCount ?? 0) + 1
124
+ }, config, true)
125
+ };
126
+ const transformed = await this.runErrorInterceptors(error, context);
127
+ if (this.isTransportResponse(transformed)) return transformed;
128
+ throw transformed;
114
129
  } finally {
115
130
  if (timer) clearTimeout(timer);
116
131
  }
@@ -139,15 +154,19 @@ var NativeRestClient = class {
139
154
  }
140
155
  return url.toString();
141
156
  }
142
- async runErrorInterceptors(error) {
157
+ async runErrorInterceptors(error, context) {
143
158
  let next = error;
159
+ if (!context) return next;
144
160
  for (const interceptor of [...this.interceptors].reverse()) if (interceptor.onError) try {
145
- next = await interceptor.onError(next);
161
+ next = await interceptor.onError(next, context);
146
162
  } catch (transformed) {
147
163
  next = transformed;
148
164
  }
149
165
  return next;
150
166
  }
167
+ isTransportResponse(value) {
168
+ return !!value && typeof value === "object" && "status" in value && "headers" in value && "data" in value;
169
+ }
151
170
  uploadWithXhr(url, data, config, method) {
152
171
  return new Promise((resolve, reject) => {
153
172
  const xhr = new XMLHttpRequest();
@@ -180,9 +199,9 @@ var NativeRestInterceptor = class {
180
199
  onResponse(response) {
181
200
  return this.interceptor.onResponse?.(response) ?? response;
182
201
  }
183
- onError(error) {
202
+ onError(error, context) {
184
203
  if (!this.interceptor.onError) throw error;
185
- return this.interceptor.onError(error);
204
+ return this.interceptor.onError(error, context);
186
205
  }
187
206
  };
188
207
  //#endregion
@@ -1,4 +1,4 @@
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";
1
+ import { a as RestTransport, c as TransportFetch, d as TransportResponse, l as TransportRequest, o as RestTransportInterceptor, r as RestRequestInfo, s as TransportErrorContext, t as GeneralTransportErrorCode, u as TransportRequestConfig } from "./rest-transport.types-DM5-qyOJ.mjs";
2
2
  //#region src/lib/rest/native-rest-client.d.ts
3
3
  type NativeResult<T, IsRawRes extends boolean> = IsRawRes extends true ? TransportResponse<T> : T;
4
4
  declare class NativeRestClient implements RestTransport {
@@ -8,12 +8,14 @@ declare class NativeRestClient implements RestTransport {
8
8
  baseURL?: string;
9
9
  headers?: HeadersInit;
10
10
  credentials?: RequestCredentials;
11
+ fetch?: TransportFetch;
11
12
  };
12
13
  interceptors?: RestTransportInterceptor[];
13
14
  });
14
15
  private readonly baseURL;
15
16
  private readonly headers?;
16
17
  private readonly credentials?;
18
+ private readonly fetch;
17
19
  attachInterceptor(interceptor: RestTransportInterceptor): void;
18
20
  ejectInterceptor(interceptor: RestTransportInterceptor): void;
19
21
  get<T, E extends string = GeneralTransportErrorCode, R extends boolean = false>(info: RestRequestInfo<T, E>, url: string, config?: TransportRequestConfig<R>): Promise<NativeResult<T, R>>;
@@ -27,6 +29,7 @@ declare class NativeRestClient implements RestTransport {
27
29
  private readResponse;
28
30
  private resolveUrl;
29
31
  private runErrorInterceptors;
32
+ private isTransportResponse;
30
33
  private uploadWithXhr;
31
34
  }
32
35
  //#endregion
@@ -37,7 +40,7 @@ declare class NativeRestInterceptor implements RestTransportInterceptor {
37
40
  constructor(interceptor: RestTransportInterceptor);
38
41
  onRequest(request: TransportRequest): Promise<TransportRequest> | TransportRequest;
39
42
  onResponse<T>(response: TransportResponse<T>): Promise<TransportResponse<T>> | TransportResponse<T>;
40
- onError(error: unknown): unknown;
43
+ onError(error: unknown, context: TransportErrorContext): unknown;
41
44
  }
42
45
  //#endregion
43
46
  export { NativeRestInterceptor as n, NativeRestClient as r, NativeInterceptor as t };
package/dist/native.d.mts CHANGED
@@ -1,3 +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";
1
+ import { a as RestTransport, d as TransportResponse, f as TransportResult, i as RestResponseType, l as TransportRequest, n as HttpError, o as RestTransportInterceptor, p as UploadProgress, r as RestRequestInfo, t as GeneralTransportErrorCode, u as TransportRequestConfig } from "./rest-transport.types-DM5-qyOJ.mjs";
2
+ import { n as NativeRestInterceptor, r as NativeRestClient, t as NativeInterceptor } from "./native-rest-interceptor-Cz6saoq5.mjs";
3
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 CHANGED
@@ -1,3 +1,3 @@
1
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";
2
+ import { n as NativeRestClient, t as NativeRestInterceptor } from "./native-rest-interceptor-CAWR8H5Y.mjs";
3
3
  export { HttpError, HttpError as NativeHttpError, NativeRestClient, NativeRestInterceptor };
@@ -1,4 +1,4 @@
1
- import { Jn as Profiler, n as runGenerate } from "./generate.runner-DVcx7AGc.mjs";
1
+ import { Jn as Profiler, n as runGenerate } from "./generate.runner-BvSprH6D.mjs";
2
2
  import path from "path";
3
3
  //#region src/plugins/openapi-codegen.runner.ts
4
4
  function createOpenApiCodegenRunner(config, options = {}) {
@@ -2,6 +2,7 @@ import { z } from "zod";
2
2
  //#region src/lib/rest/rest-transport.types.d.ts
3
3
  type GeneralTransportErrorCode = "DATA_VALIDATION_ERROR" | "NETWORK_ERROR" | "CANCELED_ERROR" | "INTERNAL_ERROR" | "UNKNOWN_ERROR";
4
4
  type RestResponseType = "json" | "text" | "blob" | "arrayBuffer";
5
+ type TransportFetch = (input: RequestInfo | URL, init?: RequestInit) => Promise<Response>;
5
6
  interface UploadProgress {
6
7
  loaded: number;
7
8
  total: number;
@@ -34,11 +35,17 @@ interface TransportRequest {
34
35
  body?: BodyInit | null;
35
36
  signal?: AbortSignal;
36
37
  credentials?: RequestCredentials;
38
+ retryCount?: number;
39
+ }
40
+ interface TransportErrorContext {
41
+ request: TransportRequest;
42
+ response?: TransportResponse<unknown>;
43
+ retry(request?: TransportRequest): Promise<TransportResponse<unknown>>;
37
44
  }
38
45
  interface RestTransportInterceptor {
39
46
  onRequest?(request: TransportRequest): TransportRequest | Promise<TransportRequest>;
40
47
  onResponse?<T>(response: TransportResponse<T>): TransportResponse<T> | Promise<TransportResponse<T>>;
41
- onError?(error: unknown): unknown | Promise<unknown>;
48
+ onError?(error: unknown, context: TransportErrorContext): unknown | Promise<unknown>;
42
49
  }
43
50
  type TransportResult<T, IsRawRes extends boolean> = IsRawRes extends true ? TransportResponse<T> : T;
44
51
  interface RestTransport {
@@ -56,4 +63,4 @@ declare class HttpError<T = unknown> extends Error {
56
63
  constructor(message: string, response: TransportResponse<T>);
57
64
  }
58
65
  //#endregion
59
- export { RestTransport as a, TransportRequestConfig as c, UploadProgress as d, RestResponseType as i, TransportResponse as l, HttpError as n, RestTransportInterceptor as o, RestRequestInfo as r, TransportRequest as s, GeneralTransportErrorCode as t, TransportResult as u };
66
+ export { RestTransport as a, TransportFetch as c, TransportResponse as d, TransportResult as f, RestResponseType as i, TransportRequest as l, HttpError as n, RestTransportInterceptor as o, UploadProgress as p, RestRequestInfo as r, TransportErrorContext as s, GeneralTransportErrorCode as t, TransportRequestConfig as u };
package/dist/rest.d.mts CHANGED
@@ -1,2 +1,2 @@
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";
1
+ import { a as RestTransport, d as TransportResponse, f as TransportResult, i as RestResponseType, l as TransportRequest, n as HttpError, o as RestTransportInterceptor, p as UploadProgress, r as RestRequestInfo, t as GeneralTransportErrorCode, u as TransportRequestConfig } from "./rest-transport.types-DM5-qyOJ.mjs";
2
2
  export { type GeneralTransportErrorCode, HttpError, type RestRequestInfo, type RestResponseType, type RestTransport, type RestTransportInterceptor, type TransportRequest, type TransportRequestConfig, type TransportResponse, type TransportResult, type UploadProgress };
package/dist/sh.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env bun
2
- import { i as VALIDATION_ERROR_TYPE_TITLE, n as groupByType, t as getDataFromOpenAPIDoc } from "./getDataFromOpenAPIDoc-BnQYK4sW.mjs";
3
- import { D as getTagFileName, Jn as Profiler, a as resolveConfig, n as runGenerate, o as getOutputFileName, t as getOpenApiDoc } from "./generate.runner-DVcx7AGc.mjs";
2
+ import { i as VALIDATION_ERROR_TYPE_TITLE, n as groupByType, t as getDataFromOpenAPIDoc } from "./getDataFromOpenAPIDoc-7RxjULpB.mjs";
3
+ import { D as getTagFileName, Jn as Profiler, a as resolveConfig, n as runGenerate, o as getOutputFileName, t as getOpenApiDoc } from "./generate.runner-BvSprH6D.mjs";
4
4
  import yargs from "yargs";
5
5
  import { hideBin } from "yargs/helpers";
6
6
  import { styleText } from "node:util";
@@ -31,7 +31,7 @@ function logBanner(message) {
31
31
  * Fetch the version from package.json
32
32
  */
33
33
  function getVersion() {
34
- return "3.2.0-rc.6";
34
+ return "3.2.0-rc.8";
35
35
  }
36
36
  //#endregion
37
37
  //#region src/helpers/yargs.helper.ts
package/dist/vite.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { t as createOpenApiCodegenRunner } from "./openapi-codegen.runner-D7ZTawpO.mjs";
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 path from "path";
4
4
  //#region src/vite/openapi-codegen.plugin.ts
package/package.json CHANGED
@@ -149,5 +149,5 @@
149
149
  "node": ">= 18"
150
150
  },
151
151
  "packageManager": "bun@1.3.14",
152
- "version": "3.2.0-rc.6"
152
+ "version": "3.2.0-rc.8"
153
153
  }