@povio/openapi-codegen-cli 3.3.0-rc.2 → 3.3.0

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 (68) hide show
  1. package/README.md +125 -9
  2. package/dist/AuthGuard-GbtTDXs0.d.mts +32 -0
  3. package/dist/AuthGuard-qpAtHaBz.mjs +24 -0
  4. package/dist/acl.d.mts +6 -19
  5. package/dist/acl.mjs +7 -7
  6. package/dist/{auth.context-BAz8frX9.mjs → auth.context-COWO6ssl.mjs} +1 -18
  7. package/dist/auth.d.mts +2 -0
  8. package/dist/auth.mjs +3 -0
  9. package/dist/axios.d.mts +2 -0
  10. package/dist/axios.mjs +2 -0
  11. package/dist/{config-BQqze8rU.d.mts → config-FD2Y872S.d.mts} +1 -2
  12. package/dist/config.d.mts +4 -0
  13. package/dist/config.mjs +5 -0
  14. package/dist/{error-handling-D6ZYITQ3.d.mts → error-handling-LPEPQV1V.d.mts} +3 -42
  15. package/dist/{error-handling-CsnufAil.mjs → error-handling-uS0DgYUR.mjs} +23 -47
  16. package/dist/errors.d.mts +3 -0
  17. package/dist/errors.mjs +2 -0
  18. package/dist/generate.runner-CLK1FoLT.mjs +1669 -0
  19. package/dist/generate.utils-BSDYGp-0.cjs +2270 -0
  20. package/dist/{generateCodeFromOpenAPIDoc-SYuVswEJ.mjs → generateCodeFromOpenAPIDoc-BypeVKIE.cjs} +1496 -2258
  21. package/dist/generateCodeFromOpenAPIDoc-CDyGSv2w.mjs +2242 -0
  22. package/dist/generator.d.mts +3 -10
  23. package/dist/generator.mjs +6 -4
  24. package/dist/getDataFromOpenAPIDoc-DYiCTWno.mjs +2016 -0
  25. package/dist/i18n-B_brQh4X.d.mts +38 -0
  26. package/dist/i18n-D-FesqFb.mjs +36 -0
  27. package/dist/index.d.mts +12 -198
  28. package/dist/index.mjs +12 -256
  29. package/dist/metro.cjs +118 -4862
  30. package/dist/metro.d.mts +3 -4
  31. package/dist/metro.mjs +3 -3
  32. package/dist/native-rest-interceptor-Np4Ov54n.mjs +215 -0
  33. package/dist/native-rest-interceptor-PgziZt1f.d.mts +49 -0
  34. package/dist/native.d.mts +3 -0
  35. package/dist/native.mjs +3 -0
  36. package/dist/openapi-codegen-native-darwin-arm64.node +0 -0
  37. package/dist/openapi-codegen-native-linux-x64.node +0 -0
  38. package/dist/openapi-codegen-native-win32-x64.node +0 -0
  39. package/dist/{openapi-codegen.runner-CCXQsUum.mjs → openapi-codegen.runner-DUqQD2B5.mjs} +2 -2
  40. package/dist/{openapi-source.runner-B6KKrXw7.d.mts → openapi-source.runner-Bje-tMOV.d.mts} +2 -8
  41. package/dist/{openapi-source.runner-8kCe-g9S.mjs → openapi-source.runner-DPUNTduQ.mjs} +25 -11
  42. package/dist/{options-DdQJ9BSc.d.mts → options-rz2bcsaN.d.mts} +10 -1
  43. package/dist/query.d.mts +3 -0
  44. package/dist/query.mjs +3 -0
  45. package/dist/queryConfig.context-CRJOgf19.d.mts +22 -0
  46. package/dist/queryConfig.context-CldQ5YL9.mjs +34 -0
  47. package/dist/rest-client-CQyFvqYC.d.mts +55 -0
  48. package/dist/rest-interceptor-Dm9DFErh.mjs +115 -0
  49. package/dist/rest-transport.types-DM5-qyOJ.d.mts +66 -0
  50. package/dist/rest-transport.types-DxitRtsB.mjs +11 -0
  51. package/dist/rest.d.mts +2 -0
  52. package/dist/rest.mjs +2 -0
  53. package/dist/rest.utils-DpiFIdhF.d.mts +9 -0
  54. package/dist/router.context-EPlMBk3G.mjs +21 -0
  55. package/dist/sh.d.mts +1 -1
  56. package/dist/sh.mjs +50 -55
  57. package/dist/tiny.d.mts +1 -1
  58. package/dist/tiny.mjs +1 -1
  59. package/dist/useMutationEffects-DIdL8tlx.d.mts +29 -0
  60. package/dist/useMutationEffects-PB1fvKWM.mjs +68 -0
  61. package/dist/vite.d.mts +3 -4
  62. package/dist/vite.mjs +5 -4
  63. package/dist/workspace.context-XWvQ_7Hg.mjs +26 -0
  64. package/dist/workspace.context-isVY9ves.d.mts +23 -0
  65. package/dist/zod.d.mts +2 -7
  66. package/dist/zod.mjs +1 -1
  67. package/package.json +67 -19
  68. package/dist/generate.runner-B0Zm3pIl.mjs +0 -87
@@ -0,0 +1,38 @@
1
+ //#region src/lib/config/i18n.d.ts
2
+ declare const ns = "openapi";
3
+ declare const resources: {
4
+ readonly en: {
5
+ readonly openapi: {
6
+ openapi: {
7
+ sharedErrors: {
8
+ dataValidation: string;
9
+ internalError: string;
10
+ networkError: string;
11
+ canceledError: string;
12
+ unknownError: string;
13
+ unknownErrorWithCode: string;
14
+ };
15
+ };
16
+ };
17
+ };
18
+ readonly sl: {
19
+ readonly openapi: {
20
+ openapi: {
21
+ sharedErrors: {
22
+ dataValidation: string;
23
+ internalError: string;
24
+ networkError: string;
25
+ canceledError: string;
26
+ unknownError: string;
27
+ unknownErrorWithCode: string;
28
+ };
29
+ };
30
+ };
31
+ };
32
+ };
33
+ type TranslateFunction = (key: string, options?: {
34
+ ns?: string;
35
+ }) => string;
36
+ declare function configureTranslations<T>(getter: () => T): void;
37
+ //#endregion
38
+ export { resources as i, configureTranslations as n, ns as r, TranslateFunction as t };
@@ -0,0 +1,36 @@
1
+ //#region src/lib/assets/locales/en/translation.json
2
+ var translation_default$1 = { openapi: { "sharedErrors": {
3
+ "dataValidation": "An error occurred while validating the data",
4
+ "internalError": "An internal error occurred. This is most likely a bug on our end. Please try again later.",
5
+ "networkError": "A network error occurred. Are you connected to the internet?",
6
+ "canceledError": "The request was canceled.",
7
+ "unknownError": "An unknown error occurred. Please try again later.",
8
+ "unknownErrorWithCode": "An unknown error occurred. Error code: \"{{code}}\""
9
+ } } };
10
+ //#endregion
11
+ //#region src/lib/assets/locales/sl/translation.json
12
+ var translation_default = { openapi: { "sharedErrors": {
13
+ "dataValidation": "Pri preverjanju podatkov je prišlo do napake",
14
+ "internalError": "Prišlo je do notranje napake.",
15
+ "networkError": "Prišlo je do napake v omrežju.",
16
+ "canceledError": "Zahteva je bila preklicana.",
17
+ "unknownError": "Prišlo je do neznane napake.",
18
+ "unknownErrorWithCode": "Prišlo je do neznane napake. Koda napake: \"{{code}}\""
19
+ } } };
20
+ //#endregion
21
+ //#region src/lib/config/i18n.ts
22
+ const ns = "openapi";
23
+ const resources = {
24
+ en: { [ns]: translation_default$1 },
25
+ sl: { [ns]: translation_default }
26
+ };
27
+ let getT = null;
28
+ function configureTranslations(getter) {
29
+ getT = () => getter();
30
+ }
31
+ function resolveT() {
32
+ if (!getT) throw new Error("Translations not configured. Call configureTranslations() at app startup.");
33
+ return getT();
34
+ }
35
+ //#endregion
36
+ export { resources as i, ns as n, resolveT as r, configureTranslations as t };
package/dist/index.d.mts CHANGED
@@ -1,198 +1,12 @@
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-D6ZYITQ3.mjs";
2
- import { t as OpenAPICodegenConfig } from "./config-BQqze8rU.mjs";
3
- import { AxiosError, AxiosInstance, AxiosRequestConfig, AxiosResponse, AxiosResponseHeaders, CreateAxiosDefaults } from "axios";
4
- import { z } from "zod";
5
- import * as _$react from "react";
6
- import { PropsWithChildren, ReactNode } from "react";
7
- import { InfiniteData, QueryKey, UseInfiniteQueryOptions, UseMutationOptions, UseQueryOptions } from "@tanstack/react-query";
8
-
9
- //#region src/lib/rest/rest-interceptor.d.ts
10
- declare class RestInterceptor<T extends any[]> {
11
- private applyInterceptor;
12
- private interceptorIdMap;
13
- constructor(applyInterceptor: (client: AxiosInstance, ...args: T) => number);
14
- addInterceptor(client: AxiosInstance, ...args: T): void;
15
- removeInterceptor(client: AxiosInstance): void;
16
- }
17
- //#endregion
18
- //#region src/lib/rest/rest-client.types.d.ts
19
- type GeneralErrorCodes$1 = string;
20
- interface RequestInfo<ZOutput, ECodes extends string> {
21
- resSchema: z.ZodType<ZOutput>;
22
- errorHandler?: ErrorHandler<ECodes>;
23
- }
24
- interface RequestConfig<IsRawRes extends boolean = false> {
25
- rawResponse?: IsRawRes;
26
- allowInvalidResponseData?: boolean;
27
- }
28
- type Response<ZOutput, IsRawRes extends boolean = false> = IsRawRes extends true ? AxiosResponse<ZOutput> : ZOutput;
29
- interface RestClient {
30
- attachInterceptors<T extends any[]>(interceptors?: RestInterceptor<T>[], ...args: T): void;
31
- attachInterceptor<T extends any[]>(interceptor: RestInterceptor<T>, ...args: T): void;
32
- ejectInterceptor<T extends any[]>(interceptor: RestInterceptor<T>): void;
33
- 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>>;
34
- 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>>;
35
- 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>>;
36
- 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>>;
37
- 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>>;
38
- }
39
- //#endregion
40
- //#region src/lib/rest/rest-client.d.ts
41
- declare class RestClient$1 implements RestClient {
42
- private readonly client;
43
- private readonly errorHandler;
44
- constructor({
45
- config,
46
- interceptors,
47
- errorHandler
48
- }?: {
49
- config?: CreateAxiosDefaults;
50
- interceptors?: RestInterceptor<any[]>[];
51
- errorHandler?: ErrorHandler<any>;
52
- });
53
- attachInterceptors<T extends any[]>(interceptors?: RestInterceptor<T>[], ...args: T): void;
54
- attachInterceptor<T extends any[]>(interceptor: RestInterceptor<T>, ...args: T): void;
55
- ejectInterceptor<T extends any[]>(interceptor: RestInterceptor<T>): void;
56
- get<ZOutput, ECodes extends string = GeneralErrorCodes, IsRawRes extends boolean = false>(requestInfo: RequestInfo<ZOutput, ECodes>, url: string, requestConfig?: AxiosRequestConfig & RequestConfig<IsRawRes>): Promise<Response<ZOutput, IsRawRes>>;
57
- 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>>;
58
- 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>>;
59
- 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>>;
60
- 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>>;
61
- private makeRequest;
62
- }
63
- //#endregion
64
- //#region src/lib/rest/rest.utils.d.ts
65
- declare namespace RestUtils {
66
- const extractServerResponseCode: (e: unknown) => string | number | null;
67
- const doesServerErrorMessageContain: (e: AxiosError, text: string) => boolean;
68
- const extractServerErrorMessage: (e: unknown) => string | null;
69
- const extractContentDispositionFilename: (headers: AxiosResponseHeaders) => string | undefined;
70
- }
71
- //#endregion
72
- //#region src/lib/react-query.types.d.ts
73
- type Function = (...args: any) => any;
74
- type IfAny<T, Y, N> = 0 extends 1 & T ? Y : N;
75
- type IsAny<T> = IfAny<T, true, never>;
76
- type IsUnknown<T, Y, N = T> = IsAny<T> extends never ? (unknown extends T ? Y : N) : N;
77
- type AppQueryOptions<TFunction extends Function, TData = Awaited<ReturnType<TFunction>>, TErrorCodes = GeneralErrorCodes> = Omit<UseQueryOptions<Awaited<ReturnType<TFunction>>, ApplicationException<TErrorCodes>, IsUnknown<TData, Awaited<ReturnType<TFunction>>>>, "queryKey" | "queryFn">;
78
- type AppMutationOptions<TFunction extends Function, TVariables = void, TData = Awaited<ReturnType<TFunction>>, TErrorCodes = GeneralErrorCodes> = Omit<UseMutationOptions<TData, ApplicationException<TErrorCodes>, TVariables>, "mutationKey" | "mutationFn">;
79
- type AppInfiniteQueryOptions<TFunction extends Function, TData = InfiniteData<Awaited<ReturnType<TFunction>>>, TErrorCodes = GeneralErrorCodes, TQueryKey extends QueryKey = QueryKey, TPageParam = number> = Omit<UseInfiniteQueryOptions<Awaited<ReturnType<TFunction>>, ApplicationException<TErrorCodes>, IsUnknown<TData, InfiniteData<Awaited<ReturnType<TFunction>>>>, TQueryKey, TPageParam>, "queryKey" | "queryFn" | "initialPageParam" | "getNextPageParam">;
80
- //#endregion
81
- //#region src/lib/config/queryConfig.context.d.ts
82
- type QueryModule = string | number | symbol;
83
- type InvalidationMapFunc<TData = any, TVariables = any> = (data: TData, variables: TVariables) => QueryKey[];
84
- type InvalidationMap<TQueryModule extends QueryModule = QueryModule, TData = any, TVariables = any> = Partial<Record<TQueryModule, InvalidationMapFunc<TData, TVariables>>>;
85
- declare namespace OpenApiQueryConfig {
86
- export interface Type<TQueryModule extends QueryModule = QueryModule> {
87
- preferUpdate?: boolean;
88
- invalidateCurrentModule?: boolean;
89
- invalidationMap?: InvalidationMap<TQueryModule>;
90
- crossTabInvalidation?: boolean;
91
- allowInvalidResponseData?: boolean;
92
- onError?: (error: unknown) => void;
93
- }
94
- type ProviderProps<TQueryModule extends QueryModule = QueryModule> = Type<TQueryModule>;
95
- export function Provider<TQueryModule extends QueryModule = QueryModule>({
96
- preferUpdate,
97
- invalidateCurrentModule,
98
- invalidationMap,
99
- crossTabInvalidation,
100
- allowInvalidResponseData,
101
- onError,
102
- children
103
- }: PropsWithChildren<ProviderProps<TQueryModule>>): _$react.JSX.Element;
104
- export const useConfig: <TQueryModule extends QueryModule = QueryModule>() => Type<TQueryModule>;
105
- export {};
106
- }
107
- //#endregion
108
- //#region src/lib/react-query/useMutationEffects.d.ts
109
- interface MutationEffectsOptions<TQueryModule extends QueryModule = QueryModule> {
110
- invalidateCurrentModule?: boolean;
111
- crossTabInvalidation?: boolean;
112
- invalidationMap?: InvalidationMap<TQueryModule>;
113
- invalidateModules?: QueryModule[];
114
- invalidateKeys?: QueryKey[];
115
- preferUpdate?: boolean;
116
- }
117
- interface UseMutationEffectsProps<TQueryModule extends QueryModule = QueryModule> {
118
- currentModule: TQueryModule;
119
- }
120
- declare function useMutationEffects<TQueryModule extends QueryModule = QueryModule>({
121
- currentModule
122
- }: UseMutationEffectsProps<TQueryModule>): {
123
- runMutationEffects: <TData, TVariables>(data: TData, variables: TVariables, options?: MutationEffectsOptions<TQueryModule>, updateKeys?: QueryKey[]) => Promise<void>;
124
- };
125
- //#endregion
126
- //#region src/lib/config/router.context.d.ts
127
- interface RouterProviderProps {
128
- replace: (url: string) => void;
129
- }
130
- declare namespace OpenApiRouter {
131
- const Provider: ({
132
- children,
133
- replace
134
- }: PropsWithChildren<RouterProviderProps>) => _$react.JSX.Element;
135
- const useRouter: () => RouterProviderProps;
136
- }
137
- //#endregion
138
- //#region src/lib/config/workspace.context.d.ts
139
- type WorkspaceValues = Record<string, unknown>;
140
- interface WorkspaceProviderProps {
141
- values?: WorkspaceValues;
142
- }
143
- declare namespace OpenApiWorkspaceContext {
144
- const Provider: ({
145
- values,
146
- children
147
- }: PropsWithChildren<WorkspaceProviderProps>) => _$react.JSX.Element;
148
- const useContext: <TValues extends WorkspaceValues = WorkspaceValues>() => TValues;
149
- const resolveParam: <T>(context: WorkspaceValues, name: string, value: T | null | undefined) => T;
150
- }
151
- declare const useWorkspaceContext: <TValues extends WorkspaceValues = WorkspaceValues>() => TValues;
152
- //#endregion
153
- //#region src/lib/auth/auth.context.d.ts
154
- declare namespace AuthContext {
155
- export interface Routes {
156
- authenticated?: string;
157
- unauthenticated?: string;
158
- }
159
- interface Type<TUser = unknown> {
160
- isAuthenticated: boolean;
161
- isInitializing: boolean;
162
- logout: () => void;
163
- updateTokens?: (accessToken: string | null, refreshToken?: string | null) => void;
164
- accessToken?: string | null;
165
- user?: TUser | null;
166
- userPromise?: () => Promise<TUser | null>;
167
- routes?: Routes;
168
- loadingState?: ReactNode;
169
- }
170
- type ProviderProps<TUser = unknown> = Type<TUser>;
171
- export const Provider: <TUser>({
172
- isAuthenticated,
173
- isInitializing,
174
- logout,
175
- updateTokens,
176
- accessToken,
177
- user,
178
- userPromise,
179
- routes,
180
- loadingState,
181
- children
182
- }: PropsWithChildren<ProviderProps<TUser>>) => _$react.JSX.Element;
183
- export const useAuth: <TUser>() => Type<TUser>;
184
- export {};
185
- }
186
- //#endregion
187
- //#region src/lib/auth/AuthGuard.d.ts
188
- interface AuthGuardProps {
189
- type: "public-only" | "private";
190
- redirectTo?: string;
191
- }
192
- declare const AuthGuard: ({
193
- type,
194
- redirectTo,
195
- children
196
- }: PropsWithChildren<AuthGuardProps>) => _$react.ReactNode;
197
- //#endregion
198
- 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 };
1
+ import { i as resources, n as configureTranslations, r as ns, t as TranslateFunction } from "./i18n-B_brQh4X.mjs";
2
+ import { a as ErrorHandler, c as SharedErrorHandler, i as ErrorEntry, n as DomainErrorEntry, o as ErrorHandlerOptions, r as DomainErrorRegistry, s as GeneralErrorCodes, t as ApplicationException } from "./error-handling-LPEPQV1V.mjs";
3
+ import { n as AuthGuardProps, r as AuthContext, t as AuthGuard } from "./AuthGuard-GbtTDXs0.mjs";
4
+ import { a as RestClient, i as Response, n as RequestConfig, o as RestInterceptor, r as RequestInfo, t as RestClient$1 } from "./rest-client-CQyFvqYC.mjs";
5
+ import { n as useWorkspaceContext, r as OpenApiRouter, t as OpenApiWorkspaceContext } from "./workspace.context-isVY9ves.mjs";
6
+ import { i as QueryModule, n as InvalidationMapFunc, r as OpenApiQueryConfig, t as InvalidationMap } from "./queryConfig.context-CRJOgf19.mjs";
7
+ import { t as RestUtils } from "./rest.utils-DpiFIdhF.mjs";
8
+ import { t as OpenAPICodegenConfig } from "./config-FD2Y872S.mjs";
9
+ import { d as TransportResponse, l as TransportRequest, n as HttpError, p as UploadProgress, u as TransportRequestConfig } from "./rest-transport.types-DM5-qyOJ.mjs";
10
+ import { n as NativeRestInterceptor, r as NativeRestClient, t as NativeInterceptor } from "./native-rest-interceptor-PgziZt1f.mjs";
11
+ import { a as AppQueryOptions, i as AppMutationOptions, n as useMutationEffects, r as AppInfiniteQueryOptions, t as MutationEffectsOptions } from "./useMutationEffects-DIdL8tlx.mjs";
12
+ 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,256 +1,12 @@
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-CsnufAil.mjs";
2
- import { n as OpenApiRouter, t as AuthContext } from "./auth.context-BAz8frX9.mjs";
3
- import axios from "axios";
4
- import { z } from "zod";
5
- import { createContext, use, useCallback, useEffect, useMemo, useState } from "react";
6
- import { useQueryClient } from "@tanstack/react-query";
7
- import { jsx } from "react/jsx-runtime";
8
- //#region src/lib/rest/rest-client.ts
9
- var RestClient = class {
10
- client;
11
- errorHandler;
12
- constructor({ config, interceptors, errorHandler } = {}) {
13
- this.client = axios.create(config);
14
- this.errorHandler = errorHandler ?? SharedErrorHandler;
15
- this.attachInterceptors(interceptors);
16
- }
17
- attachInterceptors(interceptors, ...args) {
18
- if (interceptors != null) interceptors.forEach((interceptor) => this.attachInterceptor(interceptor, ...args));
19
- }
20
- attachInterceptor(interceptor, ...args) {
21
- interceptor.addInterceptor(this.client, ...args);
22
- }
23
- ejectInterceptor(interceptor) {
24
- interceptor.removeInterceptor(this.client);
25
- }
26
- async get(requestInfo, url, requestConfig) {
27
- return this.makeRequest(requestInfo, {
28
- ...requestConfig,
29
- method: "get",
30
- url
31
- });
32
- }
33
- async post(requestInfo, url, data, requestConfig) {
34
- return this.makeRequest(requestInfo, {
35
- ...requestConfig,
36
- method: "post",
37
- url,
38
- data
39
- });
40
- }
41
- async patch(requestInfo, url, data, requestConfig) {
42
- return this.makeRequest(requestInfo, {
43
- ...requestConfig,
44
- method: "patch",
45
- url,
46
- data
47
- });
48
- }
49
- async put(requestInfo, url, data, requestConfig) {
50
- return this.makeRequest(requestInfo, {
51
- ...requestConfig,
52
- method: "put",
53
- url,
54
- data
55
- });
56
- }
57
- async delete(requestInfo, url, data, requestConfig) {
58
- return this.makeRequest(requestInfo, {
59
- ...requestConfig,
60
- method: "delete",
61
- url,
62
- data
63
- });
64
- }
65
- async makeRequest(requestInfo, requestConfig) {
66
- const errorStack = (/* @__PURE__ */ new Error()).stack;
67
- try {
68
- const { rawResponse, allowInvalidResponseData, ...config } = requestConfig;
69
- const res = await this.client(config);
70
- const responseData = res.status === 204 && res.data === "" ? void 0 : res.data;
71
- const parseResult = requestInfo.resSchema.safeParse(responseData);
72
- let resData;
73
- if (parseResult.success) resData = parseResult.data;
74
- else if (allowInvalidResponseData && config.method === "get") {
75
- parseResult.error.name = "BE Response schema mismatch - ZodError";
76
- parseResult.error.stack = [parseResult.error.stack, ...errorStack?.split("\n").slice(2) ?? []].join("\n");
77
- console.error(parseResult.error);
78
- resData = res.data;
79
- } else throw parseResult.error;
80
- return rawResponse ? {
81
- ...res,
82
- data: resData
83
- } : resData;
84
- } catch (error) {
85
- if (error instanceof z.ZodError) {
86
- error.name = "BE Response schema mismatch - ZodError";
87
- error.stack = [error.stack, ...errorStack?.split("\n").slice(2) ?? []].join("\n");
88
- }
89
- (requestInfo.errorHandler ?? this.errorHandler).rethrowError(error);
90
- throw error;
91
- }
92
- }
93
- };
94
- //#endregion
95
- //#region src/lib/rest/rest-interceptor.ts
96
- var RestInterceptor = class {
97
- interceptorIdMap = [];
98
- constructor(applyInterceptor) {
99
- this.applyInterceptor = applyInterceptor;
100
- }
101
- addInterceptor(client, ...args) {
102
- this.removeInterceptor(client);
103
- const interceptorId = this.applyInterceptor(client, ...args);
104
- this.interceptorIdMap.push({
105
- client,
106
- interceptorId
107
- });
108
- }
109
- removeInterceptor(client) {
110
- const interceptorId = this.interceptorIdMap.find((i) => i.client === client)?.interceptorId;
111
- if (interceptorId != null) {
112
- client.interceptors.request.eject(interceptorId);
113
- this.interceptorIdMap = this.interceptorIdMap.filter((i) => i.client !== client);
114
- }
115
- }
116
- };
117
- //#endregion
118
- //#region src/lib/config/queryConfig.context.tsx
119
- let OpenApiQueryConfig;
120
- (function(_OpenApiQueryConfig) {
121
- const Context = createContext({});
122
- function Provider({ preferUpdate, invalidateCurrentModule, invalidationMap, crossTabInvalidation, allowInvalidResponseData, onError, children }) {
123
- const value = useMemo(() => ({
124
- preferUpdate,
125
- invalidateCurrentModule,
126
- invalidationMap,
127
- crossTabInvalidation,
128
- allowInvalidResponseData,
129
- onError
130
- }), [
131
- preferUpdate,
132
- invalidateCurrentModule,
133
- invalidationMap,
134
- crossTabInvalidation,
135
- allowInvalidResponseData,
136
- onError
137
- ]);
138
- return /* @__PURE__ */ jsx(Context.Provider, {
139
- value,
140
- children
141
- });
142
- }
143
- _OpenApiQueryConfig.Provider = Provider;
144
- _OpenApiQueryConfig.useConfig = () => {
145
- return use(Context) ?? {};
146
- };
147
- })(OpenApiQueryConfig || (OpenApiQueryConfig = {}));
148
- //#endregion
149
- //#region src/lib/react-query/cross-tab-invalidation.ts
150
- const CROSS_TAB_INVALIDATE_KEY = "__rq_invalidate__";
151
- const broadcastQueryInvalidation = (queryKeys) => {
152
- localStorage.setItem(CROSS_TAB_INVALIDATE_KEY, JSON.stringify({
153
- keys: queryKeys,
154
- timestamp: Date.now()
155
- }));
156
- };
157
- let isListenerSetUp = false;
158
- const setupCrossTabListener = (queryClient) => {
159
- if (isListenerSetUp) return;
160
- isListenerSetUp = true;
161
- window.addEventListener("storage", (e) => {
162
- if (e.key !== CROSS_TAB_INVALIDATE_KEY || !e.newValue) return;
163
- try {
164
- const { keys } = JSON.parse(e.newValue);
165
- for (const queryKey of keys) queryClient.invalidateQueries({ queryKey });
166
- } catch {}
167
- });
168
- };
169
- //#endregion
170
- //#region src/lib/react-query/useMutationEffects.ts
171
- function useMutationEffects({ currentModule }) {
172
- const queryClient = useQueryClient();
173
- const config = OpenApiQueryConfig.useConfig();
174
- useEffect(() => {
175
- if (!config.crossTabInvalidation) return;
176
- setupCrossTabListener(queryClient);
177
- }, [queryClient, config.crossTabInvalidation]);
178
- return { runMutationEffects: useCallback(async (data, variables, options = {}, updateKeys) => {
179
- const { invalidateCurrentModule, invalidationMap, invalidateModules, invalidateKeys, preferUpdate } = options;
180
- const shouldUpdate = preferUpdate ?? config.preferUpdate ?? false;
181
- const shouldInvalidateCurrentModule = invalidateCurrentModule ?? config.invalidateCurrentModule ?? true;
182
- const isQueryKeyEqual = (keyA, keyB) => keyA.length === keyB.length && keyA.every((item, index) => item === keyB[index]);
183
- const isQueryKeyPrefix = (queryKey, prefixKey) => prefixKey.length <= queryKey.length && prefixKey.every((item, index) => item === queryKey[index]);
184
- const mappedInvalidationKeys = invalidationMap?.[currentModule]?.(data, variables) ?? config.invalidationMap?.[currentModule]?.(data, variables);
185
- const shouldInvalidateQuery = (queryKey) => {
186
- const isUpdateKey = updateKeys?.some((key) => isQueryKeyEqual(queryKey, key));
187
- if (shouldUpdate && isUpdateKey) return false;
188
- const isCurrentModule = shouldInvalidateCurrentModule && queryKey[0] === currentModule;
189
- const isInvalidateModule = !!invalidateModules && invalidateModules.some((module) => queryKey[0] === module);
190
- const isInvalidateKey = !!invalidateKeys && invalidateKeys.some((key) => isQueryKeyPrefix(queryKey, key));
191
- const isMappedKey = !!mappedInvalidationKeys && mappedInvalidationKeys.some((key) => isQueryKeyPrefix(queryKey, key));
192
- return isCurrentModule || isInvalidateModule || isInvalidateKey || isMappedKey;
193
- };
194
- const invalidatedQueryKeys = [];
195
- const shouldBroadcast = options.crossTabInvalidation ?? config.crossTabInvalidation;
196
- queryClient.invalidateQueries({ predicate: ({ queryKey }) => {
197
- const shouldInvalidate = shouldInvalidateQuery(queryKey);
198
- if (shouldInvalidate && shouldBroadcast) invalidatedQueryKeys.push([...queryKey]);
199
- return shouldInvalidate;
200
- } });
201
- if (shouldBroadcast && invalidatedQueryKeys.length > 0) broadcastQueryInvalidation(invalidatedQueryKeys);
202
- if (shouldUpdate && updateKeys) updateKeys.map((queryKey) => queryClient.setQueryData(queryKey, data));
203
- }, [
204
- queryClient,
205
- currentModule,
206
- config.preferUpdate,
207
- config.invalidateCurrentModule,
208
- config.invalidationMap,
209
- config.crossTabInvalidation
210
- ]) };
211
- }
212
- //#endregion
213
- //#region src/lib/config/workspace.context.tsx
214
- let OpenApiWorkspaceContext;
215
- (function(_OpenApiWorkspaceContext) {
216
- const Context = createContext({});
217
- _OpenApiWorkspaceContext.Provider = ({ values, children }) => {
218
- const contextValues = useMemo(() => values ?? {}, [values]);
219
- return /* @__PURE__ */ jsx(Context.Provider, {
220
- value: contextValues,
221
- children
222
- });
223
- };
224
- _OpenApiWorkspaceContext.useContext = () => {
225
- return use(Context);
226
- };
227
- _OpenApiWorkspaceContext.resolveParam = (context, name, value) => {
228
- if (value != null) return value;
229
- const workspaceValue = context[name];
230
- if (workspaceValue == null) throw new Error(`Missing workspace context param "${name}"`);
231
- return workspaceValue;
232
- };
233
- })(OpenApiWorkspaceContext || (OpenApiWorkspaceContext = {}));
234
- const useWorkspaceContext = () => OpenApiWorkspaceContext.useContext();
235
- //#endregion
236
- //#region src/lib/auth/AuthGuard.tsx
237
- const AuthGuard = ({ type, redirectTo, children }) => {
238
- const { isAuthenticated, routes, loadingState } = AuthContext.useAuth();
239
- const { replace } = OpenApiRouter.useRouter();
240
- const [hasMounted, setHasMounted] = useState(false);
241
- useEffect(() => {
242
- setHasMounted(true);
243
- }, []);
244
- if (!hasMounted) return loadingState;
245
- if (type === "private" && !isAuthenticated) {
246
- replace(redirectTo || routes?.unauthenticated || "/");
247
- return null;
248
- }
249
- if (type === "public-only" && isAuthenticated) {
250
- replace(redirectTo || routes?.authenticated || "/");
251
- return null;
252
- }
253
- return children;
254
- };
255
- //#endregion
256
- export { ApplicationException, AuthContext, AuthGuard, DomainErrorRegistry, ErrorHandler, OpenApiQueryConfig, OpenApiRouter, OpenApiWorkspaceContext, RestClient, RestInterceptor, RestUtils, SharedErrorHandler, configureTranslations, ns, resources, useMutationEffects, useWorkspaceContext };
1
+ import { i as resources, n as ns, t as configureTranslations } from "./i18n-D-FesqFb.mjs";
2
+ import { a as RestUtils, i as SharedErrorHandler, n as DomainErrorRegistry, r as ErrorHandler, t as ApplicationException } from "./error-handling-uS0DgYUR.mjs";
3
+ import { t as HttpError } from "./rest-transport.types-DxitRtsB.mjs";
4
+ import { n as RestClient, t as RestInterceptor } from "./rest-interceptor-Dm9DFErh.mjs";
5
+ import { n as NativeRestClient, t as NativeRestInterceptor } from "./native-rest-interceptor-Np4Ov54n.mjs";
6
+ import { t as OpenApiQueryConfig } from "./queryConfig.context-CldQ5YL9.mjs";
7
+ import { t as useMutationEffects } from "./useMutationEffects-PB1fvKWM.mjs";
8
+ import { t as OpenApiRouter } from "./router.context-EPlMBk3G.mjs";
9
+ import { n as useWorkspaceContext, t as OpenApiWorkspaceContext } from "./workspace.context-XWvQ_7Hg.mjs";
10
+ import { t as AuthContext } from "./auth.context-COWO6ssl.mjs";
11
+ import { t as AuthGuard } from "./AuthGuard-qpAtHaBz.mjs";
12
+ export { ApplicationException, AuthContext, AuthGuard, DomainErrorRegistry, ErrorHandler, HttpError as NativeHttpError, NativeRestClient, NativeRestInterceptor, OpenApiQueryConfig, OpenApiRouter, OpenApiWorkspaceContext, RestClient, RestInterceptor, RestUtils, SharedErrorHandler, configureTranslations, ns, resources, useMutationEffects, useWorkspaceContext };