@povio/openapi-codegen-cli 3.2.0-rc.9 → 3.3.0-rc.1

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 (69) hide show
  1. package/README.md +2 -51
  2. package/dist/acl.d.mts +19 -6
  3. package/dist/acl.mjs +7 -7
  4. package/dist/{auth.context-COWO6ssl.mjs → auth.context-BAz8frX9.mjs} +18 -1
  5. package/dist/{config-DgrOddSC.d.mts → config-BQqze8rU.d.mts} +2 -1
  6. package/dist/{error-handling-BeydPL7s.mjs → error-handling-CsnufAil.mjs} +45 -21
  7. package/dist/{error-handling-LPEPQV1V.d.mts → error-handling-D6ZYITQ3.d.mts} +42 -3
  8. package/dist/generate.runner-BeCGJ1ar.mjs +87 -0
  9. package/dist/{generateCodeFromOpenAPIDoc-iEa8YAUQ.cjs → generateCodeFromOpenAPIDoc-KQT4kYxY.mjs} +2340 -1393
  10. package/dist/generator.d.mts +10 -3
  11. package/dist/generator.mjs +4 -7
  12. package/dist/index.d.mts +198 -12
  13. package/dist/index.mjs +256 -12
  14. package/dist/metro.cjs +4861 -112
  15. package/dist/metro.d.mts +4 -3
  16. package/dist/metro.mjs +3 -3
  17. package/dist/{openapi-codegen.runner-6Yth6QZC.mjs → openapi-codegen.runner-nPBssrBL.mjs} +2 -3
  18. package/dist/{openapi-source.runner-BZ6ZLgRO.mjs → openapi-source.runner-8kCe-g9S.mjs} +6 -18
  19. package/dist/{openapi-source.runner-ykstqlPC.d.mts → openapi-source.runner-B6KKrXw7.d.mts} +8 -2
  20. package/dist/{options-KPf-Fti5.d.mts → options-DdQJ9BSc.d.mts} +1 -6
  21. package/dist/sh.d.mts +1 -1
  22. package/dist/sh.mjs +53 -37
  23. package/dist/tiny.d.mts +1 -1
  24. package/dist/tiny.mjs +1 -1
  25. package/dist/vite.d.mts +4 -3
  26. package/dist/vite.mjs +4 -5
  27. package/dist/zod.d.mts +7 -2
  28. package/dist/zod.mjs +1 -1
  29. package/package.json +22 -69
  30. package/dist/AuthGuard-GbtTDXs0.d.mts +0 -32
  31. package/dist/AuthGuard-qpAtHaBz.mjs +0 -24
  32. package/dist/auth.d.mts +0 -2
  33. package/dist/auth.mjs +0 -3
  34. package/dist/axios.d.mts +0 -2
  35. package/dist/axios.mjs +0 -2
  36. package/dist/config.d.mts +0 -4
  37. package/dist/config.mjs +0 -5
  38. package/dist/errors.d.mts +0 -3
  39. package/dist/errors.mjs +0 -2
  40. package/dist/generate.runner-D8AYuEFm.mjs +0 -184
  41. package/dist/generate.utils-CT-LA-gX.cjs +0 -2267
  42. package/dist/generateCodeFromOpenAPIDoc--ufinTug.mjs +0 -2061
  43. package/dist/getDataFromOpenAPIDoc-D8w0QElH.mjs +0 -2011
  44. package/dist/i18n-B_brQh4X.d.mts +0 -38
  45. package/dist/i18n-D-FesqFb.mjs +0 -36
  46. package/dist/native-bindings-BTQGSGhU.mjs +0 -1480
  47. package/dist/native-rest-interceptor-CAWR8H5Y.mjs +0 -208
  48. package/dist/native-rest-interceptor-Cz6saoq5.d.mts +0 -46
  49. package/dist/native.d.mts +0 -3
  50. package/dist/native.mjs +0 -3
  51. package/dist/openapi-codegen-native-darwin-arm64.node +0 -0
  52. package/dist/openapi-codegen-native-linux-x64.node +0 -0
  53. package/dist/openapi-codegen-native-win32-x64.node +0 -0
  54. package/dist/query.d.mts +0 -3
  55. package/dist/query.mjs +0 -3
  56. package/dist/queryConfig.context-CRJOgf19.d.mts +0 -22
  57. package/dist/queryConfig.context-CldQ5YL9.mjs +0 -34
  58. package/dist/rest-client-CQyFvqYC.d.mts +0 -55
  59. package/dist/rest-interceptor-D5NCNTm1.mjs +0 -115
  60. package/dist/rest-transport.types-DM5-qyOJ.d.mts +0 -66
  61. package/dist/rest-transport.types-DxitRtsB.mjs +0 -11
  62. package/dist/rest.d.mts +0 -2
  63. package/dist/rest.mjs +0 -2
  64. package/dist/rest.utils-rezWAIYL.d.mts +0 -10
  65. package/dist/router.context-EPlMBk3G.mjs +0 -21
  66. package/dist/useMutationEffects-DIdL8tlx.d.mts +0 -29
  67. package/dist/useMutationEffects-PB1fvKWM.mjs +0 -68
  68. package/dist/workspace.context-XWvQ_7Hg.mjs +0 -26
  69. package/dist/workspace.context-isVY9ves.d.mts +0 -23
@@ -1,208 +0,0 @@
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.fetch = config?.fetch ?? globalThis.fetch.bind(globalThis);
11
- this.interceptors = [...interceptors];
12
- }
13
- baseURL;
14
- headers;
15
- credentials;
16
- fetch;
17
- attachInterceptor(interceptor) {
18
- this.interceptors.push(interceptor);
19
- }
20
- ejectInterceptor(interceptor) {
21
- const index = this.interceptors.indexOf(interceptor);
22
- if (index >= 0) this.interceptors.splice(index, 1);
23
- }
24
- get(info, url, config) {
25
- return this.request(info, "GET", url, void 0, config);
26
- }
27
- post(info, url, data, config) {
28
- return this.request(info, "POST", url, data, config);
29
- }
30
- patch(info, url, data, config) {
31
- return this.request(info, "PATCH", url, data, config);
32
- }
33
- put(info, url, data, config) {
34
- return this.request(info, "PUT", url, data, config);
35
- }
36
- delete(info, url, data, config) {
37
- return this.request(info, "DELETE", url, data, config);
38
- }
39
- async upload(url, data, config = {}, method = "put") {
40
- if (config.onUploadProgress && typeof XMLHttpRequest !== "undefined") {
41
- await this.uploadWithXhr(url, data, config, method);
42
- return;
43
- }
44
- await this.execute({
45
- url,
46
- method: method.toUpperCase(),
47
- body: data,
48
- headers: new Headers(config.headers),
49
- signal: config.signal
50
- }, config, false);
51
- }
52
- async request(info, method, path, data, config = {}) {
53
- const errorStack = (/* @__PURE__ */ new Error()).stack;
54
- try {
55
- const headers = new Headers(this.headers);
56
- new Headers(config.headers).forEach((value, key) => headers.set(key, value));
57
- let body;
58
- if (data != null) if (data instanceof FormData || data instanceof Blob || typeof data === "string") body = data;
59
- else {
60
- body = JSON.stringify(data);
61
- if (!headers.has("content-type")) headers.set("content-type", "application/json");
62
- }
63
- const request = {
64
- url: this.resolveUrl(path, config.params),
65
- method,
66
- headers,
67
- body,
68
- signal: config.signal,
69
- credentials: config.credentials ?? this.credentials
70
- };
71
- const response = await this.execute(request, config);
72
- const parseResult = info.resSchema.safeParse(response.data);
73
- let dataResult;
74
- if (parseResult.success) dataResult = parseResult.data;
75
- else if (config.allowInvalidResponseData && method === "GET") {
76
- parseResult.error.name = "BE Response schema mismatch - ZodError";
77
- parseResult.error.stack = [parseResult.error.stack, ...errorStack?.split("\n").slice(2) ?? []].join("\n");
78
- console.error(parseResult.error);
79
- dataResult = response.data;
80
- } else throw parseResult.error;
81
- return config.rawResponse ? {
82
- ...response,
83
- data: dataResult
84
- } : dataResult;
85
- } catch (error) {
86
- if (error instanceof z.ZodError) error.name = "BE Response schema mismatch - ZodError";
87
- throw await this.runErrorInterceptors(error);
88
- }
89
- }
90
- async execute(request, config = {}, applyInterceptors = true) {
91
- let next = request;
92
- if (applyInterceptors) for (const interceptor of this.interceptors) next = await interceptor.onRequest?.(next) ?? next;
93
- const timeoutController = config.timeout ? new AbortController() : void 0;
94
- const timer = timeoutController ? setTimeout(() => timeoutController.abort(), config.timeout) : void 0;
95
- if (timeoutController && next.signal) if (next.signal.aborted) timeoutController.abort(next.signal.reason);
96
- else next.signal.addEventListener("abort", () => timeoutController.abort(next.signal?.reason), { once: true });
97
- const signal = timeoutController?.signal ?? next.signal;
98
- try {
99
- const res = await this.fetch(next.url, {
100
- method: next.method,
101
- headers: next.headers,
102
- body: next.body,
103
- signal,
104
- credentials: next.credentials
105
- });
106
- let response = {
107
- data: await this.readResponse(res, config.responseType),
108
- status: res.status,
109
- statusText: res.statusText,
110
- headers: res.headers,
111
- url: res.url
112
- };
113
- if (!res.ok) throw new HttpError(`Request failed with status ${res.status}`, response);
114
- if (applyInterceptors) for (const interceptor of this.interceptors) response = await interceptor.onResponse?.(response) ?? response;
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;
129
- } finally {
130
- if (timer) clearTimeout(timer);
131
- }
132
- }
133
- async readResponse(response, type) {
134
- if (response.status === 204) return void 0;
135
- if (type === "blob") return response.blob();
136
- if (type === "arrayBuffer") return response.arrayBuffer();
137
- if (type === "text") return response.text();
138
- const text = await response.text();
139
- if (text === "") return void 0;
140
- if (!response.headers.get("content-type")?.includes("json")) try {
141
- return JSON.parse(text);
142
- } catch {
143
- return text;
144
- }
145
- return JSON.parse(text);
146
- }
147
- resolveUrl(path, params) {
148
- const baseURL = this.baseURL && !this.baseURL.endsWith("/") ? `${this.baseURL}/` : this.baseURL;
149
- const url = /^https?:\/\//.test(path) ? new URL(path) : new URL(path.replace(/^\//, ""), baseURL || globalThis.location?.origin);
150
- for (const [key, value] of Object.entries(params ?? {})) {
151
- if (value == null) continue;
152
- if (Array.isArray(value)) value.forEach((item) => url.searchParams.append(key, String(item)));
153
- else url.searchParams.append(key, String(value));
154
- }
155
- return url.toString();
156
- }
157
- async runErrorInterceptors(error, context) {
158
- let next = error;
159
- if (!context) return next;
160
- for (const interceptor of [...this.interceptors].reverse()) if (interceptor.onError) try {
161
- next = await interceptor.onError(next, context);
162
- } catch (transformed) {
163
- next = transformed;
164
- }
165
- return next;
166
- }
167
- isTransportResponse(value) {
168
- return !!value && typeof value === "object" && "status" in value && "headers" in value && "data" in value;
169
- }
170
- uploadWithXhr(url, data, config, method) {
171
- return new Promise((resolve, reject) => {
172
- const xhr = new XMLHttpRequest();
173
- xhr.open(method.toUpperCase(), url);
174
- new Headers(config.headers).forEach((value, key) => xhr.setRequestHeader(key, value));
175
- if (config.timeout) xhr.timeout = config.timeout;
176
- xhr.upload.onprogress = ({ loaded, total }) => config.onUploadProgress?.({
177
- loaded,
178
- total
179
- });
180
- xhr.onload = () => xhr.status >= 200 && xhr.status < 300 ? resolve() : reject(/* @__PURE__ */ new Error(`Upload failed with status ${xhr.status}`));
181
- xhr.onerror = () => reject(/* @__PURE__ */ new TypeError("Network request failed"));
182
- xhr.ontimeout = () => reject(new DOMException("Request timed out", "TimeoutError"));
183
- config.signal?.addEventListener("abort", () => xhr.abort(), { once: true });
184
- xhr.onabort = () => reject(config.signal?.reason ?? new DOMException("Request aborted", "AbortError"));
185
- xhr.send(data);
186
- });
187
- }
188
- };
189
- //#endregion
190
- //#region src/lib/rest/native-rest-interceptor.ts
191
- var NativeRestInterceptor = class {
192
- interceptor;
193
- constructor(interceptor) {
194
- this.interceptor = interceptor;
195
- }
196
- onRequest(request) {
197
- return this.interceptor.onRequest?.(request) ?? request;
198
- }
199
- onResponse(response) {
200
- return this.interceptor.onResponse?.(response) ?? response;
201
- }
202
- onError(error, context) {
203
- if (!this.interceptor.onError) throw error;
204
- return this.interceptor.onError(error, context);
205
- }
206
- };
207
- //#endregion
208
- export { NativeRestClient as n, NativeRestInterceptor as t };
@@ -1,46 +0,0 @@
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
- //#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
- fetch?: TransportFetch;
12
- };
13
- interceptors?: RestTransportInterceptor[];
14
- });
15
- private readonly baseURL;
16
- private readonly headers?;
17
- private readonly credentials?;
18
- private readonly fetch;
19
- attachInterceptor(interceptor: RestTransportInterceptor): void;
20
- ejectInterceptor(interceptor: RestTransportInterceptor): void;
21
- get<T, E extends string = GeneralTransportErrorCode, R extends boolean = false>(info: RestRequestInfo<T, E>, url: string, config?: TransportRequestConfig<R>): Promise<NativeResult<T, R>>;
22
- 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>>;
23
- 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>>;
24
- 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>>;
25
- 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>>;
26
- upload(url: string, data: BodyInit, config?: TransportRequestConfig, method?: "put" | "post"): Promise<void>;
27
- private request;
28
- private execute;
29
- private readResponse;
30
- private resolveUrl;
31
- private runErrorInterceptors;
32
- private isTransportResponse;
33
- private uploadWithXhr;
34
- }
35
- //#endregion
36
- //#region src/lib/rest/native-rest-interceptor.d.ts
37
- type NativeInterceptor = RestTransportInterceptor;
38
- declare class NativeRestInterceptor implements RestTransportInterceptor {
39
- private readonly interceptor;
40
- constructor(interceptor: RestTransportInterceptor);
41
- onRequest(request: TransportRequest): Promise<TransportRequest> | TransportRequest;
42
- onResponse<T>(response: TransportResponse<T>): Promise<TransportResponse<T>> | TransportResponse<T>;
43
- onError(error: unknown, context: TransportErrorContext): unknown;
44
- }
45
- //#endregion
46
- export { NativeRestInterceptor as n, NativeRestClient as r, NativeInterceptor as t };
package/dist/native.d.mts DELETED
@@ -1,3 +0,0 @@
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
- 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 DELETED
@@ -1,3 +0,0 @@
1
- import { t as HttpError } from "./rest-transport.types-DxitRtsB.mjs";
2
- import { n as NativeRestClient, t as NativeRestInterceptor } from "./native-rest-interceptor-CAWR8H5Y.mjs";
3
- export { HttpError, HttpError as NativeHttpError, NativeRestClient, NativeRestInterceptor };
package/dist/query.d.mts DELETED
@@ -1,3 +0,0 @@
1
- import { i as QueryModule, n as InvalidationMapFunc, r as OpenApiQueryConfig, t as InvalidationMap } from "./queryConfig.context-CRJOgf19.mjs";
2
- import { a as AppQueryOptions, i as AppMutationOptions, n as useMutationEffects, r as AppInfiniteQueryOptions, t as MutationEffectsOptions } from "./useMutationEffects-DIdL8tlx.mjs";
3
- export { type AppInfiniteQueryOptions, type AppMutationOptions, type AppQueryOptions, type InvalidationMap, type InvalidationMapFunc, type MutationEffectsOptions, OpenApiQueryConfig, type QueryModule, useMutationEffects };
package/dist/query.mjs DELETED
@@ -1,3 +0,0 @@
1
- import { t as OpenApiQueryConfig } from "./queryConfig.context-CldQ5YL9.mjs";
2
- import { t as useMutationEffects } from "./useMutationEffects-PB1fvKWM.mjs";
3
- export { OpenApiQueryConfig, useMutationEffects };
@@ -1,22 +0,0 @@
1
- import { PropsWithChildren } from "react";
2
- import { QueryKey } from "@tanstack/react-query";
3
- //#region src/lib/config/queryConfig.context.d.ts
4
- type QueryModule = string | number | symbol;
5
- type InvalidationMapFunc<TData = any, TVariables = any> = (data: TData, variables: TVariables) => QueryKey[];
6
- type InvalidationMap<TQueryModule extends QueryModule = QueryModule, TData = any, TVariables = any> = Partial<Record<TQueryModule, InvalidationMapFunc<TData, TVariables>>>;
7
- declare namespace OpenApiQueryConfig {
8
- export interface Type<TQueryModule extends QueryModule = QueryModule> {
9
- preferUpdate?: boolean;
10
- invalidateCurrentModule?: boolean;
11
- invalidationMap?: InvalidationMap<TQueryModule>;
12
- crossTabInvalidation?: boolean;
13
- allowInvalidResponseData?: boolean;
14
- onError?: (error: unknown) => void;
15
- }
16
- type ProviderProps<TQueryModule extends QueryModule = QueryModule> = Type<TQueryModule>;
17
- export function Provider<TQueryModule extends QueryModule = QueryModule>({ preferUpdate, invalidateCurrentModule, invalidationMap, crossTabInvalidation, allowInvalidResponseData, onError, children }: PropsWithChildren<ProviderProps<TQueryModule>>): import("react").JSX.Element;
18
- export const useConfig: <TQueryModule extends QueryModule = QueryModule>() => Type<TQueryModule>;
19
- export {};
20
- }
21
- //#endregion
22
- export { QueryModule as i, InvalidationMapFunc as n, OpenApiQueryConfig as r, InvalidationMap as t };
@@ -1,34 +0,0 @@
1
- import { createContext, use, useMemo } from "react";
2
- import { jsx } from "react/jsx-runtime";
3
- //#region src/lib/config/queryConfig.context.tsx
4
- let OpenApiQueryConfig;
5
- (function(_OpenApiQueryConfig) {
6
- const Context = createContext({});
7
- function Provider({ preferUpdate, invalidateCurrentModule, invalidationMap, crossTabInvalidation, allowInvalidResponseData, onError, children }) {
8
- const value = useMemo(() => ({
9
- preferUpdate,
10
- invalidateCurrentModule,
11
- invalidationMap,
12
- crossTabInvalidation,
13
- allowInvalidResponseData,
14
- onError
15
- }), [
16
- preferUpdate,
17
- invalidateCurrentModule,
18
- invalidationMap,
19
- crossTabInvalidation,
20
- allowInvalidResponseData,
21
- onError
22
- ]);
23
- return /* @__PURE__ */ jsx(Context.Provider, {
24
- value,
25
- children
26
- });
27
- }
28
- _OpenApiQueryConfig.Provider = Provider;
29
- _OpenApiQueryConfig.useConfig = () => {
30
- return use(Context) ?? {};
31
- };
32
- })(OpenApiQueryConfig || (OpenApiQueryConfig = {}));
33
- //#endregion
34
- export { OpenApiQueryConfig as t };
@@ -1,55 +0,0 @@
1
- import { a as ErrorHandler, s as GeneralErrorCodes$1 } from "./error-handling-LPEPQV1V.mjs";
2
- import { AxiosInstance, AxiosRequestConfig, AxiosResponse, CreateAxiosDefaults } from "axios";
3
- import { z } from "zod";
4
- //#region src/lib/rest/rest-interceptor.d.ts
5
- declare class RestInterceptor<T extends any[]> {
6
- private applyInterceptor;
7
- private interceptorIdMap;
8
- constructor(applyInterceptor: (client: AxiosInstance, ...args: T) => number);
9
- addInterceptor(client: AxiosInstance, ...args: T): void;
10
- removeInterceptor(client: AxiosInstance): void;
11
- }
12
- //#endregion
13
- //#region src/lib/rest/rest-client.types.d.ts
14
- type GeneralErrorCodes = string;
15
- interface RequestInfo<ZOutput, ECodes extends string> {
16
- resSchema: z.ZodType<ZOutput>;
17
- errorHandler?: ErrorHandler<ECodes>;
18
- }
19
- interface RequestConfig<IsRawRes extends boolean = false> {
20
- rawResponse?: IsRawRes;
21
- allowInvalidResponseData?: boolean;
22
- }
23
- type Response<ZOutput, IsRawRes extends boolean = false> = IsRawRes extends true ? AxiosResponse<ZOutput> : ZOutput;
24
- interface RestClient$1 {
25
- attachInterceptors<T extends any[]>(interceptors?: RestInterceptor<T>[], ...args: T): void;
26
- attachInterceptor<T extends any[]>(interceptor: RestInterceptor<T>, ...args: T): void;
27
- ejectInterceptor<T extends any[]>(interceptor: RestInterceptor<T>): void;
28
- get<ZOutput, ECodes extends string = GeneralErrorCodes, IsRawRes extends boolean = false>(requestInfo: RequestInfo<ZOutput, ECodes>, url: string, requestConfig?: AxiosRequestConfig & RequestConfig<IsRawRes>): Promise<Response<ZOutput, IsRawRes>>;
29
- post<ZOutput, ECodes extends string = GeneralErrorCodes, IsRawRes extends boolean = false>(requestInfo: RequestInfo<ZOutput, ECodes>, url: string, data?: any, requestConfig?: AxiosRequestConfig & RequestConfig<IsRawRes>): Promise<Response<ZOutput, IsRawRes>>;
30
- patch<ZOutput, ECodes extends string = GeneralErrorCodes, IsRawRes extends boolean = false>(requestInfo: RequestInfo<ZOutput, ECodes>, url: string, data?: any, requestConfig?: AxiosRequestConfig & RequestConfig<IsRawRes>): Promise<Response<ZOutput, IsRawRes>>;
31
- put<ZOutput, ECodes extends string = GeneralErrorCodes, IsRawRes extends boolean = false>(requestInfo: RequestInfo<ZOutput, ECodes>, url: string, data?: any, requestConfig?: AxiosRequestConfig & RequestConfig<IsRawRes>): Promise<Response<ZOutput, IsRawRes>>;
32
- delete<ZOutput, ECodes extends string = GeneralErrorCodes, IsRawRes extends boolean = false>(requestInfo: RequestInfo<ZOutput, ECodes>, url: string, data?: any, requestConfig?: AxiosRequestConfig & RequestConfig<IsRawRes>): Promise<Response<ZOutput, IsRawRes>>;
33
- }
34
- //#endregion
35
- //#region src/lib/rest/rest-client.d.ts
36
- declare class RestClient implements RestClient$1 {
37
- private readonly client;
38
- private readonly errorHandler;
39
- constructor({ config, interceptors, errorHandler }?: {
40
- config?: CreateAxiosDefaults;
41
- interceptors?: RestInterceptor<any[]>[];
42
- errorHandler?: ErrorHandler<any>;
43
- });
44
- attachInterceptors<T extends any[]>(interceptors?: RestInterceptor<T>[], ...args: T): void;
45
- attachInterceptor<T extends any[]>(interceptor: RestInterceptor<T>, ...args: T): void;
46
- ejectInterceptor<T extends any[]>(interceptor: RestInterceptor<T>): void;
47
- get<ZOutput, ECodes extends string = GeneralErrorCodes$1, IsRawRes extends boolean = false>(requestInfo: RequestInfo<ZOutput, ECodes>, url: string, requestConfig?: AxiosRequestConfig & RequestConfig<IsRawRes>): Promise<Response<ZOutput, IsRawRes>>;
48
- post<ZOutput, ECodes extends string = GeneralErrorCodes$1, IsRawRes extends boolean = false>(requestInfo: RequestInfo<ZOutput, ECodes>, url: string, data?: any, requestConfig?: AxiosRequestConfig & RequestConfig<IsRawRes>): Promise<Response<ZOutput, IsRawRes>>;
49
- patch<ZOutput, ECodes extends string = GeneralErrorCodes$1, IsRawRes extends boolean = false>(requestInfo: RequestInfo<ZOutput, ECodes>, url: string, data?: any, requestConfig?: AxiosRequestConfig & RequestConfig<IsRawRes>): Promise<Response<ZOutput, IsRawRes>>;
50
- put<ZOutput, ECodes extends string = GeneralErrorCodes$1, IsRawRes extends boolean = false>(requestInfo: RequestInfo<ZOutput, ECodes>, url: string, data?: any, requestConfig?: AxiosRequestConfig & RequestConfig<IsRawRes>): Promise<Response<ZOutput, IsRawRes>>;
51
- delete<ZOutput, ECodes extends string = GeneralErrorCodes$1, IsRawRes extends boolean = false>(requestInfo: RequestInfo<ZOutput, ECodes>, url: string, data?: any, requestConfig?: AxiosRequestConfig & RequestConfig<IsRawRes>): Promise<Response<ZOutput, IsRawRes>>;
52
- private makeRequest;
53
- }
54
- //#endregion
55
- export { RestClient$1 as a, Response as i, RequestConfig as n, RestInterceptor as o, RequestInfo as r, RestClient as t };
@@ -1,115 +0,0 @@
1
- import { i as SharedErrorHandler } from "./error-handling-BeydPL7s.mjs";
2
- import axios from "axios";
3
- import { z } from "zod";
4
- //#region src/lib/rest/rest-client.ts
5
- var RestClient = class {
6
- client;
7
- errorHandler;
8
- constructor({ config, interceptors, errorHandler } = {}) {
9
- this.client = axios.create(config);
10
- this.errorHandler = errorHandler ?? SharedErrorHandler;
11
- this.attachInterceptors(interceptors);
12
- }
13
- attachInterceptors(interceptors, ...args) {
14
- if (interceptors != null) interceptors.forEach((interceptor) => this.attachInterceptor(interceptor, ...args));
15
- }
16
- attachInterceptor(interceptor, ...args) {
17
- interceptor.addInterceptor(this.client, ...args);
18
- }
19
- ejectInterceptor(interceptor) {
20
- interceptor.removeInterceptor(this.client);
21
- }
22
- async get(requestInfo, url, requestConfig) {
23
- return this.makeRequest(requestInfo, {
24
- ...requestConfig,
25
- method: "get",
26
- url
27
- });
28
- }
29
- async post(requestInfo, url, data, requestConfig) {
30
- return this.makeRequest(requestInfo, {
31
- ...requestConfig,
32
- method: "post",
33
- url,
34
- data
35
- });
36
- }
37
- async patch(requestInfo, url, data, requestConfig) {
38
- return this.makeRequest(requestInfo, {
39
- ...requestConfig,
40
- method: "patch",
41
- url,
42
- data
43
- });
44
- }
45
- async put(requestInfo, url, data, requestConfig) {
46
- return this.makeRequest(requestInfo, {
47
- ...requestConfig,
48
- method: "put",
49
- url,
50
- data
51
- });
52
- }
53
- async delete(requestInfo, url, data, requestConfig) {
54
- return this.makeRequest(requestInfo, {
55
- ...requestConfig,
56
- method: "delete",
57
- url,
58
- data
59
- });
60
- }
61
- async makeRequest(requestInfo, requestConfig) {
62
- const errorStack = (/* @__PURE__ */ new Error()).stack;
63
- try {
64
- const { rawResponse, allowInvalidResponseData, ...config } = requestConfig;
65
- const res = await this.client(config);
66
- const responseData = res.status === 204 && res.data === "" ? void 0 : res.data;
67
- const parseResult = requestInfo.resSchema.safeParse(responseData);
68
- let resData;
69
- if (parseResult.success) resData = parseResult.data;
70
- else if (allowInvalidResponseData && config.method === "get") {
71
- parseResult.error.name = "BE Response schema mismatch - ZodError";
72
- parseResult.error.stack = [parseResult.error.stack, ...errorStack?.split("\n").slice(2) ?? []].join("\n");
73
- console.error(parseResult.error);
74
- resData = res.data;
75
- } else throw parseResult.error;
76
- return rawResponse ? {
77
- ...res,
78
- data: resData
79
- } : resData;
80
- } catch (error) {
81
- if (error instanceof z.ZodError) {
82
- error.name = "BE Response schema mismatch - ZodError";
83
- error.stack = [error.stack, ...errorStack?.split("\n").slice(2) ?? []].join("\n");
84
- }
85
- (requestInfo.errorHandler ?? this.errorHandler).rethrowError(error);
86
- throw error;
87
- }
88
- }
89
- };
90
- //#endregion
91
- //#region src/lib/rest/rest-interceptor.ts
92
- var RestInterceptor = class {
93
- applyInterceptor;
94
- interceptorIdMap = [];
95
- constructor(applyInterceptor) {
96
- this.applyInterceptor = applyInterceptor;
97
- }
98
- addInterceptor(client, ...args) {
99
- this.removeInterceptor(client);
100
- const interceptorId = this.applyInterceptor(client, ...args);
101
- this.interceptorIdMap.push({
102
- client,
103
- interceptorId
104
- });
105
- }
106
- removeInterceptor(client) {
107
- const interceptorId = this.interceptorIdMap.find((i) => i.client === client)?.interceptorId;
108
- if (interceptorId != null) {
109
- client.interceptors.request.eject(interceptorId);
110
- this.interceptorIdMap = this.interceptorIdMap.filter((i) => i.client !== client);
111
- }
112
- }
113
- };
114
- //#endregion
115
- export { RestClient as n, RestInterceptor as t };
@@ -1,66 +0,0 @@
1
- import { z } from "zod";
2
- //#region src/lib/rest/rest-transport.types.d.ts
3
- type GeneralTransportErrorCode = "DATA_VALIDATION_ERROR" | "NETWORK_ERROR" | "CANCELED_ERROR" | "INTERNAL_ERROR" | "UNKNOWN_ERROR";
4
- type RestResponseType = "json" | "text" | "blob" | "arrayBuffer";
5
- type TransportFetch = (input: RequestInfo | URL, init?: RequestInit) => Promise<Response>;
6
- interface UploadProgress {
7
- loaded: number;
8
- total: number;
9
- }
10
- interface TransportRequestConfig<IsRawRes extends boolean = false> {
11
- headers?: HeadersInit;
12
- params?: Record<string, unknown>;
13
- signal?: AbortSignal;
14
- timeout?: number;
15
- credentials?: RequestCredentials;
16
- responseType?: RestResponseType;
17
- rawResponse?: IsRawRes;
18
- allowInvalidResponseData?: boolean;
19
- onUploadProgress?: (progress: UploadProgress) => void;
20
- }
21
- interface TransportResponse<T> {
22
- data: T;
23
- status: number;
24
- statusText: string;
25
- headers: Headers;
26
- url: string;
27
- }
28
- interface RestRequestInfo<ZOutput, ECodes extends string> {
29
- resSchema: z.ZodType<ZOutput>;
30
- }
31
- interface TransportRequest {
32
- url: string;
33
- method: string;
34
- headers: Headers;
35
- body?: BodyInit | null;
36
- signal?: AbortSignal;
37
- credentials?: RequestCredentials;
38
- retryCount?: number;
39
- }
40
- interface TransportErrorContext {
41
- request: TransportRequest;
42
- response?: TransportResponse<unknown>;
43
- retry(request?: TransportRequest): Promise<TransportResponse<unknown>>;
44
- }
45
- interface RestTransportInterceptor {
46
- onRequest?(request: TransportRequest): TransportRequest | Promise<TransportRequest>;
47
- onResponse?<T>(response: TransportResponse<T>): TransportResponse<T> | Promise<TransportResponse<T>>;
48
- onError?(error: unknown, context: TransportErrorContext): unknown | Promise<unknown>;
49
- }
50
- type TransportResult<T, IsRawRes extends boolean> = IsRawRes extends true ? TransportResponse<T> : T;
51
- interface RestTransport {
52
- attachInterceptor(interceptor: RestTransportInterceptor): void;
53
- ejectInterceptor(interceptor: RestTransportInterceptor): void;
54
- get<T, E extends string, R extends boolean = false>(info: RestRequestInfo<T, E>, url: string, config?: TransportRequestConfig<R>): Promise<TransportResult<T, R>>;
55
- post<T, E extends string, R extends boolean = false>(info: RestRequestInfo<T, E>, url: string, data?: unknown, config?: TransportRequestConfig<R>): Promise<TransportResult<T, R>>;
56
- patch<T, E extends string, R extends boolean = false>(info: RestRequestInfo<T, E>, url: string, data?: unknown, config?: TransportRequestConfig<R>): Promise<TransportResult<T, R>>;
57
- put<T, E extends string, R extends boolean = false>(info: RestRequestInfo<T, E>, url: string, data?: unknown, config?: TransportRequestConfig<R>): Promise<TransportResult<T, R>>;
58
- delete<T, E extends string, R extends boolean = false>(info: RestRequestInfo<T, E>, url: string, data?: unknown, config?: TransportRequestConfig<R>): Promise<TransportResult<T, R>>;
59
- upload(url: string, data: BodyInit, config?: TransportRequestConfig, method?: "put" | "post"): Promise<void>;
60
- }
61
- declare class HttpError<T = unknown> extends Error {
62
- readonly response: TransportResponse<T>;
63
- constructor(message: string, response: TransportResponse<T>);
64
- }
65
- //#endregion
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 };
@@ -1,11 +0,0 @@
1
- //#region src/lib/rest/rest-transport.types.ts
2
- var HttpError = class extends Error {
3
- response;
4
- constructor(message, response) {
5
- super(message);
6
- this.response = response;
7
- this.name = "HttpError";
8
- }
9
- };
10
- //#endregion
11
- export { HttpError as t };
package/dist/rest.d.mts DELETED
@@ -1,2 +0,0 @@
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
- export { type GeneralTransportErrorCode, HttpError, type RestRequestInfo, type RestResponseType, type RestTransport, type RestTransportInterceptor, type TransportRequest, type TransportRequestConfig, type TransportResponse, type TransportResult, type UploadProgress };
package/dist/rest.mjs DELETED
@@ -1,2 +0,0 @@
1
- import { t as HttpError } from "./rest-transport.types-DxitRtsB.mjs";
2
- export { HttpError };
@@ -1,10 +0,0 @@
1
- import { AxiosError, AxiosResponseHeaders } from "axios";
2
- //#region src/lib/rest/rest.utils.d.ts
3
- declare namespace RestUtils {
4
- const extractServerResponseCode: (e: unknown) => string | number | null;
5
- const doesServerErrorMessageContain: (e: AxiosError, text: string) => boolean;
6
- const extractServerErrorMessage: (e: unknown) => string | null;
7
- const extractContentDispositionFilename: (headers: AxiosResponseHeaders) => string | undefined;
8
- }
9
- //#endregion
10
- export { RestUtils as t };
@@ -1,21 +0,0 @@
1
- import { createContext, use, useMemo } from "react";
2
- import { jsx } from "react/jsx-runtime";
3
- //#region src/lib/config/router.context.tsx
4
- let OpenApiRouter;
5
- (function(_OpenApiRouter) {
6
- const Context = createContext(null);
7
- _OpenApiRouter.Provider = ({ children, replace }) => {
8
- const value = useMemo(() => ({ replace }), [replace]);
9
- return /* @__PURE__ */ jsx(Context, {
10
- value,
11
- children
12
- });
13
- };
14
- _OpenApiRouter.useRouter = () => {
15
- const context = use(Context);
16
- if (!context) throw new Error("useRouter must be used within an OpenApiRouter.Provider");
17
- return context;
18
- };
19
- })(OpenApiRouter || (OpenApiRouter = {}));
20
- //#endregion
21
- export { OpenApiRouter as t };