@povio/openapi-codegen-cli 3.1.1 → 3.2.0-rc.10

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 +63 -15
  2. package/dist/AuthGuard-GbtTDXs0.d.mts +32 -0
  3. package/dist/AuthGuard-qpAtHaBz.mjs +24 -0
  4. package/dist/acl.d.mts +6 -20
  5. package/dist/acl.mjs +8 -13
  6. package/dist/{auth.context-Bu5KW2sI.mjs → auth.context-COWO6ssl.mjs} +1 -21
  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-BU7wVf7U.d.mts → config-DgrOddSC.d.mts} +1 -2
  12. package/dist/config.d.mts +4 -0
  13. package/dist/config.mjs +5 -0
  14. package/dist/{error-handling-DSI86D3u.mjs → error-handling-BeydPL7s.mjs} +21 -51
  15. package/dist/{error-handling-D-mHJ60d.d.mts → error-handling-LPEPQV1V.d.mts} +3 -42
  16. package/dist/errors.d.mts +3 -0
  17. package/dist/errors.mjs +2 -0
  18. package/dist/generate.runner-CD7mlcJ4.mjs +184 -0
  19. package/dist/generate.utils-CT-LA-gX.cjs +2267 -0
  20. package/dist/generateCodeFromOpenAPIDoc-D9W5BtAt.mjs +2097 -0
  21. package/dist/{generateCodeFromOpenAPIDoc-DseBECa-.mjs → generateCodeFromOpenAPIDoc-DhI7CHeh.cjs} +1349 -2344
  22. package/dist/generator.d.mts +3 -10
  23. package/dist/generator.mjs +9 -9
  24. package/dist/getDataFromOpenAPIDoc-D8w0QElH.mjs +2011 -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 -200
  28. package/dist/index.mjs +12 -264
  29. package/dist/metro.cjs +114 -4959
  30. package/dist/metro.d.mts +3 -4
  31. package/dist/metro.mjs +4 -9
  32. package/dist/native-bindings-BTQGSGhU.mjs +1480 -0
  33. package/dist/native-rest-interceptor-CAWR8H5Y.mjs +208 -0
  34. package/dist/native-rest-interceptor-Cz6saoq5.d.mts +46 -0
  35. package/dist/native.d.mts +3 -0
  36. package/dist/native.mjs +3 -0
  37. package/dist/openapi-codegen-native-darwin-arm64.node +0 -0
  38. package/dist/openapi-codegen-native-linux-x64.node +0 -0
  39. package/dist/openapi-codegen-native-win32-x64.node +0 -0
  40. package/dist/{openapi-codegen.runner-Co_bG00_.mjs → openapi-codegen.runner-C4TIXQNx.mjs} +4 -5
  41. package/dist/{openapi-source.runner-wLs5vqw6.mjs → openapi-source.runner-BZ6ZLgRO.mjs} +19 -10
  42. package/dist/{openapi-source.runner-BSIrB6ny.d.mts → openapi-source.runner-ykstqlPC.d.mts} +2 -8
  43. package/dist/{options-CE4Koxof.d.mts → options-KPf-Fti5.d.mts} +6 -1
  44. package/dist/query.d.mts +3 -0
  45. package/dist/query.mjs +3 -0
  46. package/dist/queryConfig.context-CRJOgf19.d.mts +22 -0
  47. package/dist/queryConfig.context-CldQ5YL9.mjs +34 -0
  48. package/dist/rest-client-CQyFvqYC.d.mts +55 -0
  49. package/dist/rest-interceptor-D5NCNTm1.mjs +115 -0
  50. package/dist/rest-transport.types-DM5-qyOJ.d.mts +66 -0
  51. package/dist/rest-transport.types-DxitRtsB.mjs +11 -0
  52. package/dist/rest.d.mts +2 -0
  53. package/dist/rest.mjs +2 -0
  54. package/dist/rest.utils-rezWAIYL.d.mts +10 -0
  55. package/dist/router.context-EPlMBk3G.mjs +21 -0
  56. package/dist/sh.d.mts +1 -1
  57. package/dist/sh.mjs +41 -71
  58. package/dist/tiny.d.mts +1 -3
  59. package/dist/tiny.mjs +2 -3
  60. package/dist/useMutationEffects-DIdL8tlx.d.mts +29 -0
  61. package/dist/useMutationEffects-PB1fvKWM.mjs +68 -0
  62. package/dist/vite.d.mts +3 -4
  63. package/dist/vite.mjs +6 -10
  64. package/dist/workspace.context-XWvQ_7Hg.mjs +26 -0
  65. package/dist/workspace.context-isVY9ves.d.mts +23 -0
  66. package/dist/zod.d.mts +2 -7
  67. package/dist/zod.mjs +2 -4
  68. package/package.json +73 -26
  69. package/dist/generate.runner-C1HrS_9G.mjs +0 -90
@@ -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,200 +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-D-mHJ60d.mjs";
2
- import "./options-CE4Koxof.mjs";
3
- import { t as OpenAPICodegenConfig } from "./config-BU7wVf7U.mjs";
4
- import { AxiosError, AxiosInstance, AxiosRequestConfig, AxiosResponse, AxiosResponseHeaders, CreateAxiosDefaults } from "axios";
5
- import { z } from "zod";
6
- import * as react from "react";
7
- import { PropsWithChildren, ReactNode } from "react";
8
- import { InfiniteData, QueryKey, UseInfiniteQueryOptions, UseMutationOptions, UseQueryOptions } from "@tanstack/react-query";
9
- import * as react_jsx_runtime0 from "react/jsx-runtime";
10
-
11
- //#region src/lib/rest/rest-interceptor.d.ts
12
- declare class RestInterceptor<T extends any[]> {
13
- private applyInterceptor;
14
- private interceptorIdMap;
15
- constructor(applyInterceptor: (client: AxiosInstance, ...args: T) => number);
16
- addInterceptor(client: AxiosInstance, ...args: T): void;
17
- removeInterceptor(client: AxiosInstance): void;
18
- }
19
- //#endregion
20
- //#region src/lib/rest/rest-client.types.d.ts
21
- type GeneralErrorCodes$1 = string;
22
- interface RequestInfo<ZOutput, ECodes extends string> {
23
- resSchema: z.ZodType<ZOutput>;
24
- errorHandler?: ErrorHandler<ECodes>;
25
- }
26
- interface RequestConfig<IsRawRes extends boolean = false> {
27
- rawResponse?: IsRawRes;
28
- allowInvalidResponseData?: boolean;
29
- }
30
- type Response<ZOutput, IsRawRes extends boolean = false> = IsRawRes extends true ? AxiosResponse<ZOutput> : ZOutput;
31
- interface RestClient {
32
- attachInterceptors<T extends any[]>(interceptors?: RestInterceptor<T>[], ...args: T): void;
33
- attachInterceptor<T extends any[]>(interceptor: RestInterceptor<T>, ...args: T): void;
34
- ejectInterceptor<T extends any[]>(interceptor: RestInterceptor<T>): void;
35
- 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>>;
36
- 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>>;
37
- 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>>;
38
- 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>>;
39
- 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>>;
40
- }
41
- //#endregion
42
- //#region src/lib/rest/rest-client.d.ts
43
- declare class RestClient$1 implements RestClient {
44
- private readonly client;
45
- private readonly errorHandler;
46
- constructor({
47
- config,
48
- interceptors,
49
- errorHandler
50
- }?: {
51
- config?: CreateAxiosDefaults;
52
- interceptors?: RestInterceptor<any[]>[];
53
- errorHandler?: ErrorHandler<any>;
54
- });
55
- attachInterceptors<T extends any[]>(interceptors?: RestInterceptor<T>[], ...args: T): void;
56
- attachInterceptor<T extends any[]>(interceptor: RestInterceptor<T>, ...args: T): void;
57
- ejectInterceptor<T extends any[]>(interceptor: RestInterceptor<T>): void;
58
- get<ZOutput, ECodes extends string = GeneralErrorCodes, IsRawRes extends boolean = false>(requestInfo: RequestInfo<ZOutput, ECodes>, url: string, requestConfig?: AxiosRequestConfig & RequestConfig<IsRawRes>): Promise<Response<ZOutput, IsRawRes>>;
59
- 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>>;
60
- 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>>;
61
- 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>>;
62
- 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>>;
63
- private makeRequest;
64
- }
65
- //#endregion
66
- //#region src/lib/rest/rest.utils.d.ts
67
- declare namespace RestUtils {
68
- const extractServerResponseCode: (e: unknown) => string | number | null;
69
- const doesServerErrorMessageContain: (e: AxiosError, text: string) => boolean;
70
- const extractServerErrorMessage: (e: unknown) => string | null;
71
- const extractContentDispositionFilename: (headers: AxiosResponseHeaders) => string | undefined;
72
- }
73
- //#endregion
74
- //#region src/lib/react-query.types.d.ts
75
- type Function = (...args: any) => any;
76
- type IfAny<T, Y, N> = 0 extends 1 & T ? Y : N;
77
- type IsAny<T> = IfAny<T, true, never>;
78
- type IsUnknown<T, Y, N = T> = IsAny<T> extends never ? (unknown extends T ? Y : N) : N;
79
- 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">;
80
- type AppMutationOptions<TFunction extends Function, TVariables = void, TData = Awaited<ReturnType<TFunction>>, TErrorCodes = GeneralErrorCodes> = Omit<UseMutationOptions<TData, ApplicationException<TErrorCodes>, TVariables>, "mutationKey" | "mutationFn">;
81
- 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">;
82
- //#endregion
83
- //#region src/lib/config/queryConfig.context.d.ts
84
- type QueryModule = string | number | symbol;
85
- type InvalidationMapFunc<TData = any, TVariables = any> = (data: TData, variables: TVariables) => QueryKey[];
86
- type InvalidationMap<TQueryModule extends QueryModule = QueryModule, TData = any, TVariables = any> = Partial<Record<TQueryModule, InvalidationMapFunc<TData, TVariables>>>;
87
- declare namespace OpenApiQueryConfig {
88
- export interface Type<TQueryModule extends QueryModule = QueryModule> {
89
- preferUpdate?: boolean;
90
- invalidateCurrentModule?: boolean;
91
- invalidationMap?: InvalidationMap<TQueryModule>;
92
- crossTabInvalidation?: boolean;
93
- allowInvalidResponseData?: boolean;
94
- onError?: (error: unknown) => void;
95
- }
96
- type ProviderProps<TQueryModule extends QueryModule = QueryModule> = Type<TQueryModule>;
97
- export function Provider<TQueryModule extends QueryModule = QueryModule>({
98
- preferUpdate,
99
- invalidateCurrentModule,
100
- invalidationMap,
101
- crossTabInvalidation,
102
- allowInvalidResponseData,
103
- onError,
104
- children
105
- }: PropsWithChildren<ProviderProps<TQueryModule>>): react_jsx_runtime0.JSX.Element;
106
- export const useConfig: <TQueryModule extends QueryModule = QueryModule>() => Type<TQueryModule>;
107
- export {};
108
- }
109
- //#endregion
110
- //#region src/lib/react-query/useMutationEffects.d.ts
111
- interface MutationEffectsOptions<TQueryModule extends QueryModule = QueryModule> {
112
- invalidateCurrentModule?: boolean;
113
- crossTabInvalidation?: boolean;
114
- invalidationMap?: InvalidationMap<TQueryModule>;
115
- invalidateModules?: QueryModule[];
116
- invalidateKeys?: QueryKey[];
117
- preferUpdate?: boolean;
118
- }
119
- interface UseMutationEffectsProps<TQueryModule extends QueryModule = QueryModule> {
120
- currentModule: TQueryModule;
121
- }
122
- declare function useMutationEffects<TQueryModule extends QueryModule = QueryModule>({
123
- currentModule
124
- }: UseMutationEffectsProps<TQueryModule>): {
125
- runMutationEffects: <TData, TVariables>(data: TData, variables: TVariables, options?: MutationEffectsOptions<TQueryModule>, updateKeys?: QueryKey[]) => Promise<void>;
126
- };
127
- //#endregion
128
- //#region src/lib/config/router.context.d.ts
129
- interface RouterProviderProps {
130
- replace: (url: string) => void;
131
- }
132
- declare namespace OpenApiRouter {
133
- const Provider: ({
134
- children,
135
- replace
136
- }: PropsWithChildren<RouterProviderProps>) => react_jsx_runtime0.JSX.Element;
137
- const useRouter: () => RouterProviderProps;
138
- }
139
- //#endregion
140
- //#region src/lib/config/workspace.context.d.ts
141
- type WorkspaceValues = Record<string, unknown>;
142
- interface WorkspaceProviderProps {
143
- values?: WorkspaceValues;
144
- }
145
- declare namespace OpenApiWorkspaceContext {
146
- const Provider: ({
147
- values,
148
- children
149
- }: PropsWithChildren<WorkspaceProviderProps>) => react_jsx_runtime0.JSX.Element;
150
- const useContext: <TValues extends WorkspaceValues = WorkspaceValues>() => TValues;
151
- const resolveParam: <T>(context: WorkspaceValues, name: string, value: T | null | undefined) => T;
152
- }
153
- declare const useWorkspaceContext: <TValues extends WorkspaceValues = WorkspaceValues>() => TValues;
154
- //#endregion
155
- //#region src/lib/auth/auth.context.d.ts
156
- declare namespace AuthContext {
157
- export interface Routes {
158
- authenticated?: string;
159
- unauthenticated?: string;
160
- }
161
- interface Type<TUser = unknown> {
162
- isAuthenticated: boolean;
163
- isInitializing: boolean;
164
- logout: () => void;
165
- updateTokens?: (accessToken: string | null, refreshToken?: string | null) => void;
166
- accessToken?: string | null;
167
- user?: TUser | null;
168
- userPromise?: () => Promise<TUser | null>;
169
- routes?: Routes;
170
- loadingState?: ReactNode;
171
- }
172
- type ProviderProps<TUser = unknown> = Type<TUser>;
173
- export const Provider: <TUser>({
174
- isAuthenticated,
175
- isInitializing,
176
- logout,
177
- updateTokens,
178
- accessToken,
179
- user,
180
- userPromise,
181
- routes,
182
- loadingState,
183
- children
184
- }: PropsWithChildren<ProviderProps<TUser>>) => react_jsx_runtime0.JSX.Element;
185
- export const useAuth: <TUser>() => Type<TUser>;
186
- export {};
187
- }
188
- //#endregion
189
- //#region src/lib/auth/AuthGuard.d.ts
190
- interface AuthGuardProps {
191
- type: "public-only" | "private";
192
- redirectTo?: string;
193
- }
194
- declare const AuthGuard: ({
195
- type,
196
- redirectTo,
197
- children
198
- }: PropsWithChildren<AuthGuardProps>) => react.ReactNode;
199
- //#endregion
200
- 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-rezWAIYL.mjs";
8
+ import { t as OpenAPICodegenConfig } from "./config-DgrOddSC.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-Cz6saoq5.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,264 +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-DSI86D3u.mjs";
2
- import { n as OpenApiRouter, t as AuthContext } from "./auth.context-Bu5KW2sI.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
-
9
- //#region src/lib/rest/rest-client.ts
10
- var RestClient = class {
11
- client;
12
- errorHandler;
13
- constructor({ config, interceptors, errorHandler } = {}) {
14
- this.client = axios.create(config);
15
- this.errorHandler = errorHandler ?? SharedErrorHandler;
16
- this.attachInterceptors(interceptors);
17
- }
18
- attachInterceptors(interceptors, ...args) {
19
- if (interceptors != null) interceptors.forEach((interceptor) => this.attachInterceptor(interceptor, ...args));
20
- }
21
- attachInterceptor(interceptor, ...args) {
22
- interceptor.addInterceptor(this.client, ...args);
23
- }
24
- ejectInterceptor(interceptor) {
25
- interceptor.removeInterceptor(this.client);
26
- }
27
- async get(requestInfo, url, requestConfig) {
28
- return this.makeRequest(requestInfo, {
29
- ...requestConfig,
30
- method: "get",
31
- url
32
- });
33
- }
34
- async post(requestInfo, url, data, requestConfig) {
35
- return this.makeRequest(requestInfo, {
36
- ...requestConfig,
37
- method: "post",
38
- url,
39
- data
40
- });
41
- }
42
- async patch(requestInfo, url, data, requestConfig) {
43
- return this.makeRequest(requestInfo, {
44
- ...requestConfig,
45
- method: "patch",
46
- url,
47
- data
48
- });
49
- }
50
- async put(requestInfo, url, data, requestConfig) {
51
- return this.makeRequest(requestInfo, {
52
- ...requestConfig,
53
- method: "put",
54
- url,
55
- data
56
- });
57
- }
58
- async delete(requestInfo, url, data, requestConfig) {
59
- return this.makeRequest(requestInfo, {
60
- ...requestConfig,
61
- method: "delete",
62
- url,
63
- data
64
- });
65
- }
66
- async makeRequest(requestInfo, requestConfig) {
67
- const errorStack = (/* @__PURE__ */ new Error()).stack;
68
- try {
69
- const { rawResponse, allowInvalidResponseData, ...config } = requestConfig;
70
- const res = await this.client(config);
71
- const responseData = res.status === 204 && res.data === "" ? void 0 : res.data;
72
- const parseResult = requestInfo.resSchema.safeParse(responseData);
73
- let resData;
74
- if (parseResult.success) resData = parseResult.data;
75
- else if (allowInvalidResponseData && config.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
- resData = res.data;
80
- } else throw parseResult.error;
81
- return rawResponse ? {
82
- ...res,
83
- data: resData
84
- } : resData;
85
- } catch (error) {
86
- if (error instanceof z.ZodError) {
87
- error.name = "BE Response schema mismatch - ZodError";
88
- error.stack = [error.stack, ...errorStack?.split("\n").slice(2) ?? []].join("\n");
89
- }
90
- (requestInfo.errorHandler ?? this.errorHandler).rethrowError(error);
91
- throw error;
92
- }
93
- }
94
- };
95
-
96
- //#endregion
97
- //#region src/lib/rest/rest-interceptor.ts
98
- var RestInterceptor = class {
99
- interceptorIdMap = [];
100
- constructor(applyInterceptor) {
101
- this.applyInterceptor = applyInterceptor;
102
- }
103
- addInterceptor(client, ...args) {
104
- this.removeInterceptor(client);
105
- const interceptorId = this.applyInterceptor(client, ...args);
106
- this.interceptorIdMap.push({
107
- client,
108
- interceptorId
109
- });
110
- }
111
- removeInterceptor(client) {
112
- const interceptorId = this.interceptorIdMap.find((i) => i.client === client)?.interceptorId;
113
- if (interceptorId != null) {
114
- client.interceptors.request.eject(interceptorId);
115
- this.interceptorIdMap = this.interceptorIdMap.filter((i) => i.client !== client);
116
- }
117
- }
118
- };
119
-
120
- //#endregion
121
- //#region src/lib/config/queryConfig.context.tsx
122
- let OpenApiQueryConfig;
123
- (function(_OpenApiQueryConfig) {
124
- const Context = createContext({});
125
- function Provider({ preferUpdate, invalidateCurrentModule, invalidationMap, crossTabInvalidation, allowInvalidResponseData, onError, children }) {
126
- const value = useMemo(() => ({
127
- preferUpdate,
128
- invalidateCurrentModule,
129
- invalidationMap,
130
- crossTabInvalidation,
131
- allowInvalidResponseData,
132
- onError
133
- }), [
134
- preferUpdate,
135
- invalidateCurrentModule,
136
- invalidationMap,
137
- crossTabInvalidation,
138
- allowInvalidResponseData,
139
- onError
140
- ]);
141
- return /* @__PURE__ */ jsx(Context.Provider, {
142
- value,
143
- children
144
- });
145
- }
146
- _OpenApiQueryConfig.Provider = Provider;
147
- _OpenApiQueryConfig.useConfig = () => {
148
- return use(Context) ?? {};
149
- };
150
- })(OpenApiQueryConfig || (OpenApiQueryConfig = {}));
151
-
152
- //#endregion
153
- //#region src/lib/react-query/cross-tab-invalidation.ts
154
- const CROSS_TAB_INVALIDATE_KEY = "__rq_invalidate__";
155
- const broadcastQueryInvalidation = (queryKeys) => {
156
- localStorage.setItem(CROSS_TAB_INVALIDATE_KEY, JSON.stringify({
157
- keys: queryKeys,
158
- timestamp: Date.now()
159
- }));
160
- };
161
- let isListenerSetUp = false;
162
- const setupCrossTabListener = (queryClient) => {
163
- if (isListenerSetUp) return;
164
- isListenerSetUp = true;
165
- window.addEventListener("storage", (e) => {
166
- if (e.key !== CROSS_TAB_INVALIDATE_KEY || !e.newValue) return;
167
- try {
168
- const { keys } = JSON.parse(e.newValue);
169
- for (const queryKey of keys) queryClient.invalidateQueries({ queryKey });
170
- } catch {}
171
- });
172
- };
173
-
174
- //#endregion
175
- //#region src/lib/react-query/useMutationEffects.ts
176
- function useMutationEffects({ currentModule }) {
177
- const queryClient = useQueryClient();
178
- const config = OpenApiQueryConfig.useConfig();
179
- useEffect(() => {
180
- if (!config.crossTabInvalidation) return;
181
- setupCrossTabListener(queryClient);
182
- }, [queryClient, config.crossTabInvalidation]);
183
- return { runMutationEffects: useCallback(async (data, variables, options = {}, updateKeys) => {
184
- const { invalidateCurrentModule, invalidationMap, invalidateModules, invalidateKeys, preferUpdate } = options;
185
- const shouldUpdate = preferUpdate ?? config.preferUpdate ?? false;
186
- const shouldInvalidateCurrentModule = invalidateCurrentModule ?? config.invalidateCurrentModule ?? true;
187
- const isQueryKeyEqual = (keyA, keyB) => keyA.length === keyB.length && keyA.every((item, index) => item === keyB[index]);
188
- const isQueryKeyPrefix = (queryKey, prefixKey) => prefixKey.length <= queryKey.length && prefixKey.every((item, index) => item === queryKey[index]);
189
- const mappedInvalidationKeys = invalidationMap?.[currentModule]?.(data, variables) ?? config.invalidationMap?.[currentModule]?.(data, variables);
190
- const shouldInvalidateQuery = (queryKey) => {
191
- const isUpdateKey = updateKeys?.some((key) => isQueryKeyEqual(queryKey, key));
192
- if (shouldUpdate && isUpdateKey) return false;
193
- const isCurrentModule = shouldInvalidateCurrentModule && queryKey[0] === currentModule;
194
- const isInvalidateModule = !!invalidateModules && invalidateModules.some((module) => queryKey[0] === module);
195
- const isInvalidateKey = !!invalidateKeys && invalidateKeys.some((key) => isQueryKeyPrefix(queryKey, key));
196
- const isMappedKey = !!mappedInvalidationKeys && mappedInvalidationKeys.some((key) => isQueryKeyPrefix(queryKey, key));
197
- return isCurrentModule || isInvalidateModule || isInvalidateKey || isMappedKey;
198
- };
199
- const invalidatedQueryKeys = [];
200
- const shouldBroadcast = options.crossTabInvalidation ?? config.crossTabInvalidation;
201
- queryClient.invalidateQueries({ predicate: ({ queryKey }) => {
202
- const shouldInvalidate = shouldInvalidateQuery(queryKey);
203
- if (shouldInvalidate && shouldBroadcast) invalidatedQueryKeys.push([...queryKey]);
204
- return shouldInvalidate;
205
- } });
206
- if (shouldBroadcast && invalidatedQueryKeys.length > 0) broadcastQueryInvalidation(invalidatedQueryKeys);
207
- if (shouldUpdate && updateKeys) updateKeys.map((queryKey) => queryClient.setQueryData(queryKey, data));
208
- }, [
209
- queryClient,
210
- currentModule,
211
- config.preferUpdate,
212
- config.invalidateCurrentModule,
213
- config.invalidationMap,
214
- config.crossTabInvalidation
215
- ]) };
216
- }
217
-
218
- //#endregion
219
- //#region src/lib/config/workspace.context.tsx
220
- let OpenApiWorkspaceContext;
221
- (function(_OpenApiWorkspaceContext) {
222
- const Context = createContext({});
223
- _OpenApiWorkspaceContext.Provider = ({ values, children }) => {
224
- const contextValues = useMemo(() => values ?? {}, [values]);
225
- return /* @__PURE__ */ jsx(Context.Provider, {
226
- value: contextValues,
227
- children
228
- });
229
- };
230
- _OpenApiWorkspaceContext.useContext = () => {
231
- return use(Context);
232
- };
233
- _OpenApiWorkspaceContext.resolveParam = (context, name, value) => {
234
- if (value != null) return value;
235
- const workspaceValue = context[name];
236
- if (workspaceValue == null) throw new Error(`Missing workspace context param "${name}"`);
237
- return workspaceValue;
238
- };
239
- })(OpenApiWorkspaceContext || (OpenApiWorkspaceContext = {}));
240
- const useWorkspaceContext = () => OpenApiWorkspaceContext.useContext();
241
-
242
- //#endregion
243
- //#region src/lib/auth/AuthGuard.tsx
244
- const AuthGuard = ({ type, redirectTo, children }) => {
245
- const { isAuthenticated, routes, loadingState } = AuthContext.useAuth();
246
- const { replace } = OpenApiRouter.useRouter();
247
- const [hasMounted, setHasMounted] = useState(false);
248
- useEffect(() => {
249
- setHasMounted(true);
250
- }, []);
251
- if (!hasMounted) return loadingState;
252
- if (type === "private" && !isAuthenticated) {
253
- replace(redirectTo || routes?.unauthenticated || "/");
254
- return null;
255
- }
256
- if (type === "public-only" && isAuthenticated) {
257
- replace(redirectTo || routes?.authenticated || "/");
258
- return null;
259
- }
260
- return children;
261
- };
262
-
263
- //#endregion
264
- 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-BeydPL7s.mjs";
3
+ import { t as HttpError } from "./rest-transport.types-DxitRtsB.mjs";
4
+ import { n as RestClient, t as RestInterceptor } from "./rest-interceptor-D5NCNTm1.mjs";
5
+ import { n as NativeRestClient, t as NativeRestInterceptor } from "./native-rest-interceptor-CAWR8H5Y.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 };