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

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-B0Zm3pIl.mjs +87 -0
  9. package/dist/{generateCodeFromOpenAPIDoc-iEa8YAUQ.cjs → generateCodeFromOpenAPIDoc-SYuVswEJ.mjs} +2341 -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 +4862 -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-CCXQsUum.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,5 +1,6 @@
1
- import { n as GenerateFileData, t as GenerateOptions } from "./options-KPf-Fti5.mjs";
1
+ import { n as GenerateFileData, t as GenerateOptions } from "./options-DdQJ9BSc.mjs";
2
2
  import { OpenAPIV3 } from "openapi-types";
3
+
3
4
  //#region src/generators/types/metadata.d.ts
4
5
  interface GenerateParams {
5
6
  input: string;
@@ -52,7 +53,13 @@ interface GenerateMetadata {
52
53
  }
53
54
  //#endregion
54
55
  //#region src/generator.d.ts
55
- declare function getGenerateMetadata({ input, options: genOptions }: GenerateParams): Promise<GenerateMetadata>;
56
- declare function getGenerateFilesData({ input, options: genOptions }: GenerateParams): Promise<GenerateFileData[]>;
56
+ declare function getGenerateMetadata({
57
+ input,
58
+ options: genOptions
59
+ }: GenerateParams): Promise<GenerateMetadata>;
60
+ declare function getGenerateFilesData({
61
+ input,
62
+ options: genOptions
63
+ }: GenerateParams): Promise<GenerateFileData[]>;
57
64
  //#endregion
58
65
  export { getGenerateFilesData, getGenerateMetadata };
@@ -1,7 +1,5 @@
1
- import { t as generateCodeFromOpenAPIDoc } from "./generateCodeFromOpenAPIDoc--ufinTug.mjs";
2
- import { t as getDataFromOpenAPIDoc } from "./getDataFromOpenAPIDoc-D8w0QElH.mjs";
3
- import { H as getQueryName, Ht as getNamespaceName, Mn as formatTag, O as getTagImportPath, S as getTsTypeBase, Xt as isMediaTypeAllowed, Zt as isParamMediaTypeAllowed, bt as invalidVariableNameCharactersToCamel, d as isQuery, dt as DEFAULT_GENERATE_OPTIONS, u as isMutation, x as getSchemaTsMetaType } from "./native-bindings-BTQGSGhU.mjs";
4
- import { t as getOpenApiDoc } from "./generate.runner-D8AYuEFm.mjs";
1
+ import { _ as getNamespaceName, a as getDataFromOpenAPIDoc, b as formatTag, c as getSchemaTsMetaType, d as getTagImportPath, f as getQueryName, g as invalidVariableNameCharactersToCamel, l as getTsTypeBase, o as isMutation, p as DEFAULT_GENERATE_OPTIONS, s as isQuery, t as generateCodeFromOpenAPIDoc, v as isMediaTypeAllowed, y as isParamMediaTypeAllowed } from "./generateCodeFromOpenAPIDoc-SYuVswEJ.mjs";
2
+ import SwaggerParser from "@apidevtools/swagger-parser";
5
3
  //#region src/generators/core/getMetadataFromOpenAPIDoc.ts
6
4
  async function getMetadataFromOpenAPIDoc(openApiDoc, options) {
7
5
  const { resolver, data } = await getDataFromOpenAPIDoc(openApiDoc, options);
@@ -130,15 +128,14 @@ async function getGenerateMetadata({ input, options: genOptions }) {
130
128
  ...DEFAULT_GENERATE_OPTIONS,
131
129
  ...genOptions
132
130
  };
133
- return await getMetadataFromOpenAPIDoc(await getOpenApiDoc(input), options);
131
+ return await getMetadataFromOpenAPIDoc(await SwaggerParser.bundle(input), options);
134
132
  }
135
133
  async function getGenerateFilesData({ input, options: genOptions }) {
136
134
  const options = {
137
135
  ...DEFAULT_GENERATE_OPTIONS,
138
136
  ...genOptions
139
137
  };
140
- const openApiDoc = await getOpenApiDoc(input);
141
- return generateCodeFromOpenAPIDoc(openApiDoc, options);
138
+ return generateCodeFromOpenAPIDoc(await SwaggerParser.bundle(input), options);
142
139
  }
143
140
  //#endregion
144
141
  export { getGenerateFilesData, getGenerateMetadata };
package/dist/index.d.mts CHANGED
@@ -1,12 +1,198 @@
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 };
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 };
package/dist/index.mjs CHANGED
@@ -1,12 +1,256 @@
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 };
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 };