@povio/openapi-codegen-cli 2.0.8-rc.15 → 2.0.8-rc.17
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.
- package/dist/acl.d.mts +12 -1
- package/dist/acl.mjs +13 -3
- package/dist/auth.context-HV1I5QMx.mjs +244 -0
- package/dist/{config-Cu_GYfai.d.mts → config-B4HK4BLi.d.mts} +1 -1
- package/dist/error-handling-p69GkKGP.d.mts +38 -0
- package/dist/{generate.runner-tAVdp_fl.mjs → generate.runner-CU-WCMgQ.mjs} +1 -1
- package/dist/{generateCodeFromOpenAPIDoc-CxXf-IaZ.mjs → generateCodeFromOpenAPIDoc-CV_esDUW.mjs} +26 -70
- package/dist/generator.d.mts +1 -1
- package/dist/generator.mjs +1 -1
- package/dist/index.d.mts +4 -38
- package/dist/index.mjs +2 -185
- package/dist/sh.mjs +3 -3
- package/dist/vite.d.mts +2 -2
- package/dist/vite.mjs +2 -2
- package/package.json +1 -1
- package/dist/auth.context-DKjzWiaA.mjs +0 -59
- /package/dist/{options-DBz5YE3s.d.mts → options-Bvmh6rai.d.mts} +0 -0
package/dist/acl.d.mts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { r as ErrorHandler } from "./error-handling-p69GkKGP.mjs";
|
|
1
2
|
import * as react from "react";
|
|
2
3
|
import { PropsWithChildren } from "react";
|
|
3
4
|
import * as react_jsx_runtime0 from "react/jsx-runtime";
|
|
@@ -45,4 +46,14 @@ declare const Can: <TAppAbilities extends AppAbilities = AppAbilities>({
|
|
|
45
46
|
...props
|
|
46
47
|
}: CanProps<TAppAbilities>) => react_jsx_runtime0.JSX.Element;
|
|
47
48
|
//#endregion
|
|
48
|
-
|
|
49
|
+
//#region src/lib/acl/useAclCheck.d.ts
|
|
50
|
+
interface UseAclCheckProps {
|
|
51
|
+
errorHandler?: ErrorHandler<never>;
|
|
52
|
+
}
|
|
53
|
+
declare function useAclCheck<TAppAbilities extends AppAbilities = AppAbilities>({
|
|
54
|
+
errorHandler
|
|
55
|
+
}?: UseAclCheckProps): {
|
|
56
|
+
checkAcl: (appAbility: TAppAbilities) => void;
|
|
57
|
+
};
|
|
58
|
+
//#endregion
|
|
59
|
+
export { AbilityContext, type AppAbilities, type AppAbility, Can, createAclGuard, useAclCheck };
|
package/dist/acl.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { n as OpenApiRouter, t as AuthContext } from "./auth.context-
|
|
2
|
-
import { createContext, useEffect, useState } from "react";
|
|
1
|
+
import { a as SharedErrorHandler, n as OpenApiRouter, t as AuthContext } from "./auth.context-HV1I5QMx.mjs";
|
|
2
|
+
import { createContext, useCallback, useEffect, useState } from "react";
|
|
3
3
|
import { jsx } from "react/jsx-runtime";
|
|
4
4
|
import { AbilityBuilder, createMongoAbility } from "@casl/ability";
|
|
5
5
|
import { unpackRules } from "@casl/ability/extra";
|
|
@@ -60,4 +60,14 @@ const Can = ({ use, ...props }) => {
|
|
|
60
60
|
};
|
|
61
61
|
|
|
62
62
|
//#endregion
|
|
63
|
-
|
|
63
|
+
//#region src/lib/acl/useAclCheck.ts
|
|
64
|
+
function useAclCheck({ errorHandler } = {}) {
|
|
65
|
+
const ability = AbilityContext.useAbility();
|
|
66
|
+
return { checkAcl: useCallback((appAbility) => {
|
|
67
|
+
const can = ability.can;
|
|
68
|
+
if (!can(...appAbility)) (errorHandler ?? SharedErrorHandler).rethrowError(/* @__PURE__ */ new Error("ACL check failed"));
|
|
69
|
+
}, [ability, errorHandler]) };
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
//#endregion
|
|
73
|
+
export { AbilityContext, Can, createAclGuard, useAclCheck };
|
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
import { isAxiosError, isCancel } from "axios";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import i18next from "i18next";
|
|
4
|
+
import { createContext, use, useMemo } from "react";
|
|
5
|
+
import { jsx } from "react/jsx-runtime";
|
|
6
|
+
|
|
7
|
+
//#region src/lib/assets/locales/en/translation.json
|
|
8
|
+
var translation_default$1 = { openapi: { "sharedErrors": {
|
|
9
|
+
"dataValidation": "An error occurred while validating the data",
|
|
10
|
+
"internalError": "An internal error occurred. This is most likely a bug on our end. Please try again later.",
|
|
11
|
+
"networkError": "A network error occurred. Are you connected to the internet?",
|
|
12
|
+
"canceledError": "The request was canceled.",
|
|
13
|
+
"unknownError": "An unknown error occurred. Please try again later.",
|
|
14
|
+
"unknownErrorWithCode": "An unknown error occurred. Error code: \"{{code}}\""
|
|
15
|
+
} } };
|
|
16
|
+
|
|
17
|
+
//#endregion
|
|
18
|
+
//#region src/lib/assets/locales/sl/translation.json
|
|
19
|
+
var translation_default = { openapi: { "sharedErrors": {
|
|
20
|
+
"dataValidation": "Pri preverjanju podatkov je prišlo do napake",
|
|
21
|
+
"internalError": "Prišlo je do notranje napake.",
|
|
22
|
+
"networkError": "Prišlo je do napake v omrežju.",
|
|
23
|
+
"canceledError": "Zahteva je bila preklicana.",
|
|
24
|
+
"unknownError": "Prišlo je do neznane napake.",
|
|
25
|
+
"unknownErrorWithCode": "Prišlo je do neznane napake. Koda napake: \"{{code}}\""
|
|
26
|
+
} } };
|
|
27
|
+
|
|
28
|
+
//#endregion
|
|
29
|
+
//#region src/lib/config/i18n.ts
|
|
30
|
+
const ns = "openapi";
|
|
31
|
+
const resources = {
|
|
32
|
+
en: { [ns]: translation_default$1 },
|
|
33
|
+
sl: { [ns]: translation_default }
|
|
34
|
+
};
|
|
35
|
+
const defaultLanguage = "en";
|
|
36
|
+
const i18n = i18next.createInstance();
|
|
37
|
+
i18n.init({
|
|
38
|
+
compatibilityJSON: "v4",
|
|
39
|
+
lng: defaultLanguage,
|
|
40
|
+
fallbackLng: defaultLanguage,
|
|
41
|
+
resources,
|
|
42
|
+
ns: Object.keys(resources.en),
|
|
43
|
+
defaultNS: ns,
|
|
44
|
+
interpolation: { escapeValue: false }
|
|
45
|
+
});
|
|
46
|
+
const defaultT = i18n.t.bind(i18n);
|
|
47
|
+
|
|
48
|
+
//#endregion
|
|
49
|
+
//#region src/lib/rest/rest.utils.ts
|
|
50
|
+
let RestUtils;
|
|
51
|
+
(function(_RestUtils) {
|
|
52
|
+
_RestUtils.extractServerResponseCode = (e) => {
|
|
53
|
+
if (e instanceof z.ZodError) return "validation-exception";
|
|
54
|
+
if (!isAxiosError(e)) return null;
|
|
55
|
+
if (!e.response) return null;
|
|
56
|
+
const data = e.response.data;
|
|
57
|
+
if (typeof data?.code === "string") return data.code;
|
|
58
|
+
return null;
|
|
59
|
+
};
|
|
60
|
+
_RestUtils.doesServerErrorMessageContain = (e, text) => {
|
|
61
|
+
const message = extractServerErrorMessage(e);
|
|
62
|
+
if (message === null || message === void 0) return false;
|
|
63
|
+
return message.toLowerCase().includes(text.toLowerCase());
|
|
64
|
+
};
|
|
65
|
+
const extractServerErrorMessage = _RestUtils.extractServerErrorMessage = (e) => {
|
|
66
|
+
if (e instanceof z.ZodError) return e.message;
|
|
67
|
+
if (!isAxiosError(e)) return null;
|
|
68
|
+
if (!e.response) return null;
|
|
69
|
+
const data = e.response.data;
|
|
70
|
+
if (typeof data?.message === "string") return data.message;
|
|
71
|
+
return null;
|
|
72
|
+
};
|
|
73
|
+
_RestUtils.extractContentDispositionFilename = (headers) => {
|
|
74
|
+
const contentDisposition = headers["content-disposition"];
|
|
75
|
+
return contentDisposition ? /filename=["']?([^"';]+)/i.exec(contentDisposition)?.[1] : void 0;
|
|
76
|
+
};
|
|
77
|
+
})(RestUtils || (RestUtils = {}));
|
|
78
|
+
|
|
79
|
+
//#endregion
|
|
80
|
+
//#region src/lib/rest/error-handling.ts
|
|
81
|
+
var ApplicationException = class extends Error {
|
|
82
|
+
code;
|
|
83
|
+
serverMessage = null;
|
|
84
|
+
constructor(message, code, serverMessage) {
|
|
85
|
+
super(message);
|
|
86
|
+
this.code = code;
|
|
87
|
+
this.serverMessage = serverMessage;
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
var ErrorHandler = class {
|
|
91
|
+
entries = [];
|
|
92
|
+
t;
|
|
93
|
+
onRethrowError;
|
|
94
|
+
constructor({ entries, t = defaultT, onRethrowError }) {
|
|
95
|
+
this.t = t;
|
|
96
|
+
this.onRethrowError = onRethrowError;
|
|
97
|
+
const dataValidationError = {
|
|
98
|
+
code: "DATA_VALIDATION_ERROR",
|
|
99
|
+
condition: (e) => {
|
|
100
|
+
return e instanceof z.ZodError;
|
|
101
|
+
},
|
|
102
|
+
getMessage: () => this.t("openapi.sharedErrors.dataValidation")
|
|
103
|
+
};
|
|
104
|
+
const internalError = {
|
|
105
|
+
code: "INTERNAL_ERROR",
|
|
106
|
+
condition: (e) => {
|
|
107
|
+
if (isAxiosError(e)) return e.response?.status != null && e.response.status >= 500 && e.response.status < 600;
|
|
108
|
+
return false;
|
|
109
|
+
},
|
|
110
|
+
getMessage: () => this.t("openapi.sharedErrors.internalError")
|
|
111
|
+
};
|
|
112
|
+
const networkError = {
|
|
113
|
+
code: "NETWORK_ERROR",
|
|
114
|
+
condition: (e) => {
|
|
115
|
+
if (isAxiosError(e)) return e.code === "ERR_NETWORK";
|
|
116
|
+
return false;
|
|
117
|
+
},
|
|
118
|
+
getMessage: () => this.t("openapi.sharedErrors.networkError")
|
|
119
|
+
};
|
|
120
|
+
const canceledError = {
|
|
121
|
+
code: "CANCELED_ERROR",
|
|
122
|
+
condition: (e) => {
|
|
123
|
+
if (isCancel(e)) return true;
|
|
124
|
+
if (isAxiosError(e) && e.code === "ECONNABORTED") return true;
|
|
125
|
+
return false;
|
|
126
|
+
},
|
|
127
|
+
getMessage: () => this.t("openapi.sharedErrors.canceledError")
|
|
128
|
+
};
|
|
129
|
+
const unknownError = {
|
|
130
|
+
code: "UNKNOWN_ERROR",
|
|
131
|
+
condition: () => true,
|
|
132
|
+
getMessage: (_, e) => {
|
|
133
|
+
const code = RestUtils.extractServerResponseCode(e);
|
|
134
|
+
const serverMessage = RestUtils.extractServerErrorMessage(e);
|
|
135
|
+
if (code) {
|
|
136
|
+
let message = `Unknown error, message from server: ${code}`;
|
|
137
|
+
if (serverMessage) message += ` ${serverMessage}`;
|
|
138
|
+
return message;
|
|
139
|
+
}
|
|
140
|
+
return this.t("openapi.sharedErrors.unknownError");
|
|
141
|
+
}
|
|
142
|
+
};
|
|
143
|
+
this.entries = [
|
|
144
|
+
...entries,
|
|
145
|
+
dataValidationError,
|
|
146
|
+
internalError,
|
|
147
|
+
networkError,
|
|
148
|
+
canceledError,
|
|
149
|
+
unknownError
|
|
150
|
+
];
|
|
151
|
+
}
|
|
152
|
+
matchesEntry(error, entry, code) {
|
|
153
|
+
if (entry.condition) return entry.condition(error);
|
|
154
|
+
return code === entry.code;
|
|
155
|
+
}
|
|
156
|
+
setTranslateFunction(t) {
|
|
157
|
+
this.t = t;
|
|
158
|
+
}
|
|
159
|
+
rethrowError(error) {
|
|
160
|
+
const code = RestUtils.extractServerResponseCode(error);
|
|
161
|
+
const errorEntry = this.entries.find((entry) => this.matchesEntry(error, entry, code));
|
|
162
|
+
const serverMessage = RestUtils.extractServerErrorMessage(error);
|
|
163
|
+
const exception = new ApplicationException(errorEntry.getMessage(this.t, error), errorEntry.code, serverMessage);
|
|
164
|
+
this.onRethrowError?.(error, exception);
|
|
165
|
+
throw exception;
|
|
166
|
+
}
|
|
167
|
+
getError(error) {
|
|
168
|
+
if (error instanceof ApplicationException) return error;
|
|
169
|
+
return null;
|
|
170
|
+
}
|
|
171
|
+
getErrorCode(error) {
|
|
172
|
+
if (error instanceof ApplicationException) return error.code;
|
|
173
|
+
return null;
|
|
174
|
+
}
|
|
175
|
+
static getErrorMessage(error, fallbackToUnknown = true) {
|
|
176
|
+
if (typeof error === "string") return error;
|
|
177
|
+
if (error instanceof Error) return error.message;
|
|
178
|
+
if (error instanceof ApplicationException) {
|
|
179
|
+
if (error.serverMessage != null) return error.serverMessage;
|
|
180
|
+
return error.message;
|
|
181
|
+
}
|
|
182
|
+
if (fallbackToUnknown) return defaultT("openapi.sharedErrors.unknownError");
|
|
183
|
+
return null;
|
|
184
|
+
}
|
|
185
|
+
};
|
|
186
|
+
const SharedErrorHandler = new ErrorHandler({ entries: [] });
|
|
187
|
+
|
|
188
|
+
//#endregion
|
|
189
|
+
//#region src/lib/config/router.context.tsx
|
|
190
|
+
let OpenApiRouter;
|
|
191
|
+
(function(_OpenApiRouter) {
|
|
192
|
+
const Context = createContext(null);
|
|
193
|
+
_OpenApiRouter.Provider = ({ children, replace }) => {
|
|
194
|
+
return /* @__PURE__ */ jsx(Context, {
|
|
195
|
+
value: useMemo(() => ({ replace }), [replace]),
|
|
196
|
+
children
|
|
197
|
+
});
|
|
198
|
+
};
|
|
199
|
+
_OpenApiRouter.useRouter = () => {
|
|
200
|
+
const context = use(Context);
|
|
201
|
+
if (!context) throw new Error("useRouter must be used within an OpenApiRouter.Provider");
|
|
202
|
+
return context;
|
|
203
|
+
};
|
|
204
|
+
})(OpenApiRouter || (OpenApiRouter = {}));
|
|
205
|
+
|
|
206
|
+
//#endregion
|
|
207
|
+
//#region src/lib/auth/auth.context.tsx
|
|
208
|
+
let AuthContext;
|
|
209
|
+
(function(_AuthContext) {
|
|
210
|
+
const Context = createContext({});
|
|
211
|
+
_AuthContext.Provider = ({ isAuthenticated, isInitializing, logout, updateTokens, accessToken, user, userPromise, routes, loadingState, children }) => {
|
|
212
|
+
const value = useMemo(() => ({
|
|
213
|
+
isAuthenticated,
|
|
214
|
+
isInitializing,
|
|
215
|
+
logout,
|
|
216
|
+
updateTokens,
|
|
217
|
+
accessToken,
|
|
218
|
+
user,
|
|
219
|
+
userPromise,
|
|
220
|
+
routes,
|
|
221
|
+
loadingState
|
|
222
|
+
}), [
|
|
223
|
+
isAuthenticated,
|
|
224
|
+
isInitializing,
|
|
225
|
+
logout,
|
|
226
|
+
updateTokens,
|
|
227
|
+
accessToken,
|
|
228
|
+
user,
|
|
229
|
+
userPromise,
|
|
230
|
+
routes,
|
|
231
|
+
loadingState
|
|
232
|
+
]);
|
|
233
|
+
return /* @__PURE__ */ jsx(Context.Provider, {
|
|
234
|
+
value,
|
|
235
|
+
children
|
|
236
|
+
});
|
|
237
|
+
};
|
|
238
|
+
_AuthContext.useAuth = () => {
|
|
239
|
+
return use(Context);
|
|
240
|
+
};
|
|
241
|
+
})(AuthContext || (AuthContext = {}));
|
|
242
|
+
|
|
243
|
+
//#endregion
|
|
244
|
+
export { SharedErrorHandler as a, resources as c, ErrorHandler as i, OpenApiRouter as n, RestUtils as o, ApplicationException as r, ns as s, AuthContext as t };
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { TFunction } from "i18next";
|
|
2
|
+
|
|
3
|
+
//#region src/lib/rest/error-handling.d.ts
|
|
4
|
+
type GeneralErrorCodes = "DATA_VALIDATION_ERROR" | "NETWORK_ERROR" | "CANCELED_ERROR" | "INTERNAL_ERROR" | "UNKNOWN_ERROR";
|
|
5
|
+
declare class ApplicationException<CodeT> extends Error {
|
|
6
|
+
code: CodeT;
|
|
7
|
+
serverMessage: string | null;
|
|
8
|
+
constructor(message: string, code: CodeT, serverMessage: string | null);
|
|
9
|
+
}
|
|
10
|
+
interface ErrorEntry<CodeT> {
|
|
11
|
+
code: CodeT;
|
|
12
|
+
condition?: (error: unknown) => boolean;
|
|
13
|
+
getMessage: (t: TFunction, error: unknown) => string;
|
|
14
|
+
}
|
|
15
|
+
interface ErrorHandlerOptions<CodeT extends string> {
|
|
16
|
+
entries: ErrorEntry<CodeT>[];
|
|
17
|
+
t?: TFunction;
|
|
18
|
+
onRethrowError?: (error: unknown, exception: ApplicationException<CodeT | GeneralErrorCodes>) => void;
|
|
19
|
+
}
|
|
20
|
+
declare class ErrorHandler<CodeT extends string> {
|
|
21
|
+
entries: ErrorEntry<CodeT | GeneralErrorCodes>[];
|
|
22
|
+
private t;
|
|
23
|
+
private onRethrowError?;
|
|
24
|
+
constructor({
|
|
25
|
+
entries,
|
|
26
|
+
t,
|
|
27
|
+
onRethrowError
|
|
28
|
+
}: ErrorHandlerOptions<CodeT>);
|
|
29
|
+
private matchesEntry;
|
|
30
|
+
setTranslateFunction(t: TFunction): void;
|
|
31
|
+
rethrowError(error: unknown): ApplicationException<CodeT | GeneralErrorCodes>;
|
|
32
|
+
getError(error: unknown): ApplicationException<CodeT | GeneralErrorCodes> | null;
|
|
33
|
+
getErrorCode(error: unknown): CodeT | GeneralErrorCodes | null;
|
|
34
|
+
static getErrorMessage(error: unknown, fallbackToUnknown?: boolean): string | null;
|
|
35
|
+
}
|
|
36
|
+
declare const SharedErrorHandler: ErrorHandler<never>;
|
|
37
|
+
//#endregion
|
|
38
|
+
export { GeneralErrorCodes as a, ErrorHandlerOptions as i, ErrorEntry as n, SharedErrorHandler as o, ErrorHandler as r, ApplicationException as t };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as deepMerge, p as DEFAULT_GENERATE_OPTIONS, r as writeGenerateFileData, t as generateCodeFromOpenAPIDoc, x as Profiler } from "./generateCodeFromOpenAPIDoc-
|
|
1
|
+
import { a as deepMerge, p as DEFAULT_GENERATE_OPTIONS, r as writeGenerateFileData, t as generateCodeFromOpenAPIDoc, x as Profiler } from "./generateCodeFromOpenAPIDoc-CV_esDUW.mjs";
|
|
2
2
|
import fs from "fs";
|
|
3
3
|
import path from "path";
|
|
4
4
|
import SwaggerParser from "@apidevtools/swagger-parser";
|
package/dist/{generateCodeFromOpenAPIDoc-CxXf-IaZ.mjs → generateCodeFromOpenAPIDoc-CV_esDUW.mjs}
RENAMED
|
@@ -488,11 +488,6 @@ const ERROR_HANDLING_IMPORT = {
|
|
|
488
488
|
bindings: [ERROR_HANDLERS.ErrorHandler, ERROR_HANDLERS.SharedErrorHandler],
|
|
489
489
|
from: PACKAGE_IMPORT_PATH
|
|
490
490
|
};
|
|
491
|
-
const ABILITY_CONTEXT = "AbilityContext";
|
|
492
|
-
const ABILITY_CONTEXT_IMPORT = {
|
|
493
|
-
bindings: [ABILITY_CONTEXT],
|
|
494
|
-
from: ACL_PACKAGE_IMPORT_PATH
|
|
495
|
-
};
|
|
496
491
|
const BUILDERS_UTILS = {
|
|
497
492
|
dynamicInputs: "dynamicInputs",
|
|
498
493
|
dynamicColumns: "dynamicColumns"
|
|
@@ -583,10 +578,6 @@ const ACL_APP_ABILITY_FILE = {
|
|
|
583
578
|
extension: "ts"
|
|
584
579
|
};
|
|
585
580
|
const ACL_APP_ABILITIES = "AppAbilities";
|
|
586
|
-
const ACL_CHECK_FILE = {
|
|
587
|
-
fileName: "acl/useAclCheck",
|
|
588
|
-
extension: "ts"
|
|
589
|
-
};
|
|
590
581
|
const ACL_CHECK_HOOK = "useAclCheck";
|
|
591
582
|
const CASL_ABILITY_BINDING = {
|
|
592
583
|
abilityTuple: "AbilityTuple",
|
|
@@ -1073,15 +1064,9 @@ function getQueryTypesImportPath(options) {
|
|
|
1073
1064
|
function getMutationEffectsImportPath(options) {
|
|
1074
1065
|
return `${getImportPath(options)}${MUTATION_EFFECTS_FILE.fileName}`;
|
|
1075
1066
|
}
|
|
1076
|
-
function getAclCheckImportPath(options) {
|
|
1077
|
-
return `${getImportPath(options)}${ACL_CHECK_FILE.fileName}`;
|
|
1078
|
-
}
|
|
1079
1067
|
function getZodExtendedImportPath(options) {
|
|
1080
1068
|
return `${getImportPath(options)}${ZOD_EXTENDED_FILE.fileName}`;
|
|
1081
1069
|
}
|
|
1082
|
-
function getAppAbilitiesImportPath(options) {
|
|
1083
|
-
return `${getImportPath(options)}${ACL_APP_ABILITY_FILE.fileName}`;
|
|
1084
|
-
}
|
|
1085
1070
|
|
|
1086
1071
|
//#endregion
|
|
1087
1072
|
//#region src/generators/utils/ts.utils.ts
|
|
@@ -3773,11 +3758,8 @@ function generateQueries(params) {
|
|
|
3773
3758
|
const queryImport = {
|
|
3774
3759
|
bindings: [
|
|
3775
3760
|
...queryEndpoints.length > 0 ? [QUERY_HOOKS.query] : [],
|
|
3776
|
-
...queryEndpoints.length > 0 ? ["UseQueryResult"] : [],
|
|
3777
3761
|
...resolver.options.infiniteQueries && infiniteQueryEndpoints.length > 0 ? [QUERY_HOOKS.infiniteQuery] : [],
|
|
3778
|
-
...
|
|
3779
|
-
...mutationEndpoints.length > 0 ? [QUERY_HOOKS.mutation] : [],
|
|
3780
|
-
...mutationEndpoints.length > 0 ? ["UseMutationResult"] : []
|
|
3762
|
+
...mutationEndpoints.length > 0 ? [QUERY_HOOKS.mutation] : []
|
|
3781
3763
|
],
|
|
3782
3764
|
from: QUERY_IMPORT.from
|
|
3783
3765
|
};
|
|
@@ -3794,7 +3776,7 @@ function generateQueries(params) {
|
|
|
3794
3776
|
const hasAclCheck = resolver.options.checkAcl && aclEndpoints.length > 0;
|
|
3795
3777
|
const aclCheckImport = {
|
|
3796
3778
|
bindings: [ACL_CHECK_HOOK],
|
|
3797
|
-
from:
|
|
3779
|
+
from: ACL_PACKAGE_IMPORT_PATH
|
|
3798
3780
|
};
|
|
3799
3781
|
const queryTypesImport = {
|
|
3800
3782
|
bindings: [
|
|
@@ -3986,7 +3968,7 @@ function renderAclCheckCall(resolver, endpoint, replacements, indent = "") {
|
|
|
3986
3968
|
function addAsteriskAfterNewLine(str) {
|
|
3987
3969
|
return str.replace(/\n/g, "\n *");
|
|
3988
3970
|
}
|
|
3989
|
-
function renderQueryJsDocs({ resolver, endpoint, mode }) {
|
|
3971
|
+
function renderQueryJsDocs({ resolver, endpoint, mode, tag }) {
|
|
3990
3972
|
const lines = ["/** "];
|
|
3991
3973
|
if (mode === "infiniteQuery") lines.push(` * Infinite query \`${getInfiniteQueryName(endpoint)}${endpoint.summary ? "" : ""}`);
|
|
3992
3974
|
else if (mode === "query") lines.push(` * Query \`${getQueryName(endpoint)}\`${endpoint.summary && endpoint.mediaDownload ? " - recommended when file should be cached" : ""}`);
|
|
@@ -3994,13 +3976,16 @@ function renderQueryJsDocs({ resolver, endpoint, mode }) {
|
|
|
3994
3976
|
if (endpoint.summary) lines.push(` * @summary ${addAsteriskAfterNewLine(endpoint.summary)}`);
|
|
3995
3977
|
if (endpoint.description) lines.push(` * @description ${addAsteriskAfterNewLine(endpoint.description)}`);
|
|
3996
3978
|
if (endpoint.acl) lines.push(` * @permission Requires \`${getAbilityFunctionName(endpoint)}\` ability `);
|
|
3997
|
-
const params = getEndpointParamMapping(resolver, endpoint, {
|
|
3979
|
+
const params = getEndpointParamMapping(resolver, endpoint, {
|
|
3980
|
+
...mode !== "infiniteQuery" ? { includeFileParam: true } : {},
|
|
3981
|
+
modelNamespaceTag: tag
|
|
3982
|
+
});
|
|
3998
3983
|
for (const endpointParam of params) lines.push(` * @param { ${endpointParam.type} } ${endpointParam.name} ${renderEndpointParamDescription(endpointParam)}`);
|
|
3999
3984
|
if (mode === "query") lines.push(" * @param { AppQueryOptions } options Query options");
|
|
4000
3985
|
else if (mode === "mutation") lines.push(` * @param { AppMutationOptions${resolver.options.mutationEffects ? ` & ${MUTATION_EFFECTS.optionsType}` : ""} } options Mutation options`);
|
|
4001
3986
|
else lines.push(" * @param { AppInfiniteQueryOptions } options Infinite query options");
|
|
4002
3987
|
const withAxiosResponse = endpoint.mediaDownload && mode !== "infiniteQuery";
|
|
4003
|
-
const resultType = `${withAxiosResponse ? "AxiosResponse<" : ""}${getImportedZodSchemaInferedTypeName(resolver, endpoint.response)}${withAxiosResponse ? ">" : ""}`;
|
|
3988
|
+
const resultType = `${withAxiosResponse ? "AxiosResponse<" : ""}${getImportedZodSchemaInferedTypeName(resolver, endpoint.response, void 0, tag)}${withAxiosResponse ? ">" : ""}`;
|
|
4004
3989
|
if (mode === "query") lines.push(` * @returns { UseQueryResult<${resultType}> } ${endpoint.responseDescription ?? ""}`);
|
|
4005
3990
|
else if (mode === "mutation") lines.push(` * @returns { UseMutationResult<${resultType}> } ${endpoint.responseDescription ?? ""}`);
|
|
4006
3991
|
else lines.push(` * @returns { UseInfiniteQueryResult<${resultType}> } ${endpoint.responseDescription ?? ""}`);
|
|
@@ -4081,10 +4066,14 @@ function renderInlineEndpointConfig(resolver, endpoint, modelNamespaceTag) {
|
|
|
4081
4066
|
function renderQuery({ resolver, endpoint, inlineEndpoints }) {
|
|
4082
4067
|
const hasAxiosRequestConfig = resolver.options.axiosRequestConfig;
|
|
4083
4068
|
const hasAclCheck = resolver.options.checkAcl && endpoint.acl;
|
|
4069
|
+
const tag = getEndpointTag(endpoint, resolver.options);
|
|
4084
4070
|
const workspaceParamReplacements = resolver.options.workspaceContext ? getWorkspaceParamReplacements(resolver, endpoint) : {};
|
|
4085
4071
|
const endpointArgs = renderEndpointArgs(resolver, endpoint, {});
|
|
4086
4072
|
const resolvedEndpointArgs = renderEndpointArgs(resolver, endpoint, {}, workspaceParamReplacements);
|
|
4087
|
-
const endpointParams = renderEndpointParams(resolver, endpoint, {
|
|
4073
|
+
const endpointParams = renderEndpointParams(resolver, endpoint, {
|
|
4074
|
+
optionalPathParams: resolver.options.workspaceContext,
|
|
4075
|
+
modelNamespaceTag: tag
|
|
4076
|
+
});
|
|
4088
4077
|
const hasQueryFn = endpointArgs.length > 0 || hasAxiosRequestConfig || hasAclCheck;
|
|
4089
4078
|
const hasQueryFnBody = Boolean(hasAclCheck) || Object.keys(workspaceParamReplacements).length > 0;
|
|
4090
4079
|
const importedEndpoint = inlineEndpoints ? getEndpointName(endpoint) : getImportedEndpointName(endpoint, resolver.options);
|
|
@@ -4092,7 +4081,8 @@ function renderQuery({ resolver, endpoint, inlineEndpoints }) {
|
|
|
4092
4081
|
lines.push(renderQueryJsDocs({
|
|
4093
4082
|
resolver,
|
|
4094
4083
|
endpoint,
|
|
4095
|
-
mode: "query"
|
|
4084
|
+
mode: "query",
|
|
4085
|
+
tag
|
|
4096
4086
|
}));
|
|
4097
4087
|
lines.push(`export const ${getQueryName(endpoint)} = <TData>(${endpointParams ? `{ ${endpointArgs} }: { ${endpointParams} }, ` : ""}options?: AppQueryOptions<typeof ${importedEndpoint}, TData>${hasAxiosRequestConfig ? `, ${AXIOS_REQUEST_CONFIG_NAME}?: ${AXIOS_REQUEST_CONFIG_TYPE}` : ""}) => {`);
|
|
4098
4088
|
if (hasAclCheck) lines.push(` const { checkAcl } = ${ACL_CHECK_HOOK}();`);
|
|
@@ -4117,10 +4107,12 @@ function renderMutation({ resolver, endpoint, inlineEndpoints, precomputed }) {
|
|
|
4117
4107
|
const hasAclCheck = resolver.options.checkAcl && endpoint.acl;
|
|
4118
4108
|
const hasMutationEffects = resolver.options.mutationEffects;
|
|
4119
4109
|
const hasAxiosRequestConfig = resolver.options.axiosRequestConfig;
|
|
4110
|
+
const tag = getEndpointTag(endpoint, resolver.options);
|
|
4120
4111
|
const workspaceParamReplacements = resolver.options.workspaceContext ? getWorkspaceParamReplacements(resolver, endpoint) : {};
|
|
4121
4112
|
const endpointParams = renderEndpointParams(resolver, endpoint, {
|
|
4122
4113
|
includeFileParam: true,
|
|
4123
|
-
optionalPathParams: resolver.options.workspaceContext
|
|
4114
|
+
optionalPathParams: resolver.options.workspaceContext,
|
|
4115
|
+
modelNamespaceTag: tag
|
|
4124
4116
|
});
|
|
4125
4117
|
const resolvedEndpointArgs = renderEndpointArgs(resolver, endpoint, {}, workspaceParamReplacements);
|
|
4126
4118
|
const destructuredMutationArgs = renderEndpointArgs(resolver, endpoint, { includeFileParam: true });
|
|
@@ -4133,7 +4125,8 @@ function renderMutation({ resolver, endpoint, inlineEndpoints, precomputed }) {
|
|
|
4133
4125
|
lines.push(renderQueryJsDocs({
|
|
4134
4126
|
resolver,
|
|
4135
4127
|
endpoint,
|
|
4136
|
-
mode: "mutation"
|
|
4128
|
+
mode: "mutation",
|
|
4129
|
+
tag
|
|
4137
4130
|
}));
|
|
4138
4131
|
lines.push(`export const ${getQueryName(endpoint, true)} = (options?: AppMutationOptions<typeof ${endpointFunction}, { ${mutationVariablesType} }>${hasMutationEffects ? ` & ${MUTATION_EFFECTS.optionsType}` : ""}${hasAxiosRequestConfig ? `, ${AXIOS_REQUEST_CONFIG_NAME}?: ${AXIOS_REQUEST_CONFIG_TYPE}` : ""}) => {`);
|
|
4139
4132
|
lines.push(" const queryConfig = OpenApiQueryConfig.useConfig();");
|
|
@@ -4233,14 +4226,15 @@ function groupEndpoints(endpoints, resolver) {
|
|
|
4233
4226
|
function renderInfiniteQuery({ resolver, endpoint, inlineEndpoints }) {
|
|
4234
4227
|
const hasAclCheck = resolver.options.checkAcl && endpoint.acl;
|
|
4235
4228
|
const hasAxiosRequestConfig = resolver.options.axiosRequestConfig;
|
|
4229
|
+
const tag = getEndpointTag(endpoint, resolver.options);
|
|
4236
4230
|
const workspaceParamReplacements = resolver.options.workspaceContext ? getWorkspaceParamReplacements(resolver, endpoint) : {};
|
|
4237
4231
|
const endpointParams = renderEndpointParams(resolver, endpoint, {
|
|
4238
4232
|
excludePageParam: true,
|
|
4239
|
-
optionalPathParams: resolver.options.workspaceContext
|
|
4233
|
+
optionalPathParams: resolver.options.workspaceContext,
|
|
4234
|
+
modelNamespaceTag: tag
|
|
4240
4235
|
});
|
|
4241
4236
|
const endpointArgsWithoutPage = renderEndpointArgs(resolver, endpoint, { excludePageParam: true });
|
|
4242
4237
|
const resolvedEndpointArgsWithoutPage = renderEndpointArgs(resolver, endpoint, { excludePageParam: true }, workspaceParamReplacements);
|
|
4243
|
-
renderEndpointArgs(resolver, endpoint, { replacePageParam: true });
|
|
4244
4238
|
const resolvedEndpointArgsWithPage = renderEndpointArgs(resolver, endpoint, { replacePageParam: true }, workspaceParamReplacements);
|
|
4245
4239
|
const endpointFunction = inlineEndpoints ? getEndpointName(endpoint) : getImportedEndpointName(endpoint, resolver.options);
|
|
4246
4240
|
const hasQueryFnBody = Boolean(hasAclCheck) || Object.keys(workspaceParamReplacements).length > 0;
|
|
@@ -4248,10 +4242,10 @@ function renderInfiniteQuery({ resolver, endpoint, inlineEndpoints }) {
|
|
|
4248
4242
|
lines.push(renderQueryJsDocs({
|
|
4249
4243
|
resolver,
|
|
4250
4244
|
endpoint,
|
|
4251
|
-
mode: "infiniteQuery"
|
|
4245
|
+
mode: "infiniteQuery",
|
|
4246
|
+
tag
|
|
4252
4247
|
}));
|
|
4253
4248
|
lines.push(`export const ${getInfiniteQueryName(endpoint)} = <TData>(${endpointParams ? `{ ${endpointArgsWithoutPage} }: { ${endpointParams} }, ` : ""}options?: AppInfiniteQueryOptions<typeof ${endpointFunction}, TData>${hasAxiosRequestConfig ? `, ${AXIOS_REQUEST_CONFIG_NAME}?: ${AXIOS_REQUEST_CONFIG_TYPE}` : ""}) => {`);
|
|
4254
|
-
lines.push(" const queryConfig = OpenApiQueryConfig.useConfig();");
|
|
4255
4249
|
if (hasAclCheck) lines.push(` const { checkAcl } = ${ACL_CHECK_HOOK}();`);
|
|
4256
4250
|
lines.push(...renderWorkspaceParamResolutions({
|
|
4257
4251
|
replacements: workspaceParamReplacements,
|
|
@@ -4269,43 +4263,11 @@ function renderInfiniteQuery({ resolver, endpoint, inlineEndpoints }) {
|
|
|
4269
4263
|
lines.push(` return pageParam * limitParam < ${resolver.options.infiniteQueryResponseParamNames.totalItems} ? pageParam + 1 : null;`);
|
|
4270
4264
|
lines.push(" },");
|
|
4271
4265
|
lines.push(" ...options,");
|
|
4272
|
-
lines.push(" onError: options?.onError ?? queryConfig.onError,");
|
|
4273
4266
|
lines.push(" });");
|
|
4274
4267
|
lines.push("};");
|
|
4275
4268
|
return lines.join("\n");
|
|
4276
4269
|
}
|
|
4277
4270
|
|
|
4278
|
-
//#endregion
|
|
4279
|
-
//#region src/generators/generate/generateAclCheck.ts
|
|
4280
|
-
function generateAclCheck(resolver) {
|
|
4281
|
-
const abilityContextImportPath = resolver.options.abilityContextImportPath ?? ABILITY_CONTEXT_IMPORT.from;
|
|
4282
|
-
const appAbilitiesImportPath = getAppAbilitiesImportPath(resolver.options);
|
|
4283
|
-
const errorHandlingImportPath = resolver.options.errorHandlingImportPath ?? ERROR_HANDLING_IMPORT.from;
|
|
4284
|
-
const genericAppAbilities = resolver.options.abilityContextGenericAppAbilities ? `<${ACL_APP_ABILITIES}>` : "";
|
|
4285
|
-
return `import { ${CASL_ABILITY_BINDING.abilityTuple} } from "@casl/ability";
|
|
4286
|
-
import { type ${ERROR_HANDLERS.ErrorHandler}, ${ERROR_HANDLERS.SharedErrorHandler} } from "${errorHandlingImportPath}";
|
|
4287
|
-
import { ${ABILITY_CONTEXT} } from "${abilityContextImportPath}";
|
|
4288
|
-
import { useCallback } from "react";
|
|
4289
|
-
import { ${ACL_APP_ABILITIES} } from "${appAbilitiesImportPath}";
|
|
4290
|
-
|
|
4291
|
-
interface UseAclCheckProps {
|
|
4292
|
-
errorHandler?: ${ERROR_HANDLERS.ErrorHandler}<never>;
|
|
4293
|
-
}
|
|
4294
|
-
|
|
4295
|
-
export function ${ACL_CHECK_HOOK}({ errorHandler }: UseAclCheckProps = {}) {
|
|
4296
|
-
const ability = ${ABILITY_CONTEXT}.useAbility${genericAppAbilities}();
|
|
4297
|
-
|
|
4298
|
-
const checkAcl = useCallback((appAbility: ${ACL_APP_ABILITIES}) => {
|
|
4299
|
-
if (!ability.can(...(appAbility as ${CASL_ABILITY_BINDING.abilityTuple}))) {
|
|
4300
|
-
(errorHandler ?? ${ERROR_HANDLERS.SharedErrorHandler}).rethrowError(new Error("ACL check failed"));
|
|
4301
|
-
}
|
|
4302
|
-
}, [ability, errorHandler]);
|
|
4303
|
-
|
|
4304
|
-
return { checkAcl };
|
|
4305
|
-
}
|
|
4306
|
-
`;
|
|
4307
|
-
}
|
|
4308
|
-
|
|
4309
4271
|
//#endregion
|
|
4310
4272
|
//#region src/generators/generate/generateAppRestClient.ts
|
|
4311
4273
|
function generateAppRestClient(resolver) {
|
|
@@ -4415,13 +4377,7 @@ function getAclFiles(data, resolver) {
|
|
|
4415
4377
|
resolver,
|
|
4416
4378
|
data
|
|
4417
4379
|
})
|
|
4418
|
-
}
|
|
4419
|
-
fileName: getOutputFileName({
|
|
4420
|
-
output: resolver.options.output,
|
|
4421
|
-
fileName: getFileNameWithExtension(ACL_CHECK_FILE)
|
|
4422
|
-
}),
|
|
4423
|
-
content: generateAclCheck(resolver)
|
|
4424
|
-
}] : []];
|
|
4380
|
+
}];
|
|
4425
4381
|
}
|
|
4426
4382
|
function getMutationEffectsFiles(data, resolver) {
|
|
4427
4383
|
if (!resolver.options.mutationEffects) return [];
|
package/dist/generator.d.mts
CHANGED
package/dist/generator.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { _ as isMediaTypeAllowed, b as formatTag, c as getSchemaTsMetaType, d as getTagImportPath, f as getQueryName, h as GenerateType, i as getDataFromOpenAPIDoc, l as getTsTypeBase, m as getNamespaceName, o as isMutation, p as DEFAULT_GENERATE_OPTIONS, s as isQuery, t as generateCodeFromOpenAPIDoc, v as isParamMediaTypeAllowed, y as invalidVariableNameCharactersToCamel } from "./generateCodeFromOpenAPIDoc-
|
|
1
|
+
import { _ as isMediaTypeAllowed, b as formatTag, c as getSchemaTsMetaType, d as getTagImportPath, f as getQueryName, h as GenerateType, i as getDataFromOpenAPIDoc, l as getTsTypeBase, m as getNamespaceName, o as isMutation, p as DEFAULT_GENERATE_OPTIONS, s as isQuery, t as generateCodeFromOpenAPIDoc, v as isParamMediaTypeAllowed, y as invalidVariableNameCharactersToCamel } from "./generateCodeFromOpenAPIDoc-CV_esDUW.mjs";
|
|
2
2
|
import SwaggerParser from "@apidevtools/swagger-parser";
|
|
3
3
|
|
|
4
4
|
//#region src/generators/core/getMetadataFromOpenAPIDoc.ts
|
package/dist/index.d.mts
CHANGED
|
@@ -1,48 +1,14 @@
|
|
|
1
|
-
import "./
|
|
2
|
-
import
|
|
1
|
+
import { a as GeneralErrorCodes, i as ErrorHandlerOptions, n as ErrorEntry, o as SharedErrorHandler, r as ErrorHandler, t as ApplicationException } from "./error-handling-p69GkKGP.mjs";
|
|
2
|
+
import "./options-Bvmh6rai.mjs";
|
|
3
|
+
import { t as OpenAPICodegenConfig } from "./config-B4HK4BLi.mjs";
|
|
3
4
|
import { AxiosError, AxiosInstance, AxiosRequestConfig, AxiosResponse, AxiosResponseHeaders, CreateAxiosDefaults } from "axios";
|
|
4
5
|
import { z } from "zod";
|
|
5
|
-
import
|
|
6
|
+
import "i18next";
|
|
6
7
|
import * as react from "react";
|
|
7
8
|
import { PropsWithChildren, ReactNode } from "react";
|
|
8
9
|
import * as react_jsx_runtime0 from "react/jsx-runtime";
|
|
9
10
|
import { InfiniteData, QueryKey, UseInfiniteQueryOptions, UseMutationOptions, UseQueryOptions } from "@tanstack/react-query";
|
|
10
11
|
|
|
11
|
-
//#region src/lib/rest/error-handling.d.ts
|
|
12
|
-
type GeneralErrorCodes = "DATA_VALIDATION_ERROR" | "NETWORK_ERROR" | "CANCELED_ERROR" | "INTERNAL_ERROR" | "UNKNOWN_ERROR";
|
|
13
|
-
declare class ApplicationException<CodeT> extends Error {
|
|
14
|
-
code: CodeT;
|
|
15
|
-
serverMessage: string | null;
|
|
16
|
-
constructor(message: string, code: CodeT, serverMessage: string | null);
|
|
17
|
-
}
|
|
18
|
-
interface ErrorEntry<CodeT> {
|
|
19
|
-
code: CodeT;
|
|
20
|
-
condition?: (error: unknown) => boolean;
|
|
21
|
-
getMessage: (t: TFunction, error: unknown) => string;
|
|
22
|
-
}
|
|
23
|
-
interface ErrorHandlerOptions<CodeT extends string> {
|
|
24
|
-
entries: ErrorEntry<CodeT>[];
|
|
25
|
-
t?: TFunction;
|
|
26
|
-
onRethrowError?: (error: unknown, exception: ApplicationException<CodeT | GeneralErrorCodes>) => void;
|
|
27
|
-
}
|
|
28
|
-
declare class ErrorHandler<CodeT extends string> {
|
|
29
|
-
entries: ErrorEntry<CodeT | GeneralErrorCodes>[];
|
|
30
|
-
private t;
|
|
31
|
-
private onRethrowError?;
|
|
32
|
-
constructor({
|
|
33
|
-
entries,
|
|
34
|
-
t,
|
|
35
|
-
onRethrowError
|
|
36
|
-
}: ErrorHandlerOptions<CodeT>);
|
|
37
|
-
private matchesEntry;
|
|
38
|
-
setTranslateFunction(t: TFunction): void;
|
|
39
|
-
rethrowError(error: unknown): ApplicationException<CodeT | GeneralErrorCodes>;
|
|
40
|
-
getError(error: unknown): ApplicationException<CodeT | GeneralErrorCodes> | null;
|
|
41
|
-
getErrorCode(error: unknown): CodeT | GeneralErrorCodes | null;
|
|
42
|
-
static getErrorMessage(error: unknown, fallbackToUnknown?: boolean): string | null;
|
|
43
|
-
}
|
|
44
|
-
declare const SharedErrorHandler: ErrorHandler<never>;
|
|
45
|
-
//#endregion
|
|
46
12
|
//#region src/lib/rest/rest-interceptor.d.ts
|
|
47
13
|
declare class RestInterceptor<T extends any[]> {
|
|
48
14
|
private applyInterceptor;
|
package/dist/index.mjs
CHANGED
|
@@ -1,192 +1,9 @@
|
|
|
1
|
-
import { n as OpenApiRouter, t as AuthContext } from "./auth.context-
|
|
2
|
-
import axios
|
|
1
|
+
import { a as SharedErrorHandler, c as resources, i as ErrorHandler, n as OpenApiRouter, o as RestUtils, r as ApplicationException, s as ns, t as AuthContext } from "./auth.context-HV1I5QMx.mjs";
|
|
2
|
+
import axios from "axios";
|
|
3
3
|
import { z } from "zod";
|
|
4
|
-
import i18next from "i18next";
|
|
5
4
|
import { createContext, use, useEffect, useMemo, useState } from "react";
|
|
6
5
|
import { jsx } from "react/jsx-runtime";
|
|
7
6
|
|
|
8
|
-
//#region src/lib/assets/locales/en/translation.json
|
|
9
|
-
var translation_default$1 = { openapi: { "sharedErrors": {
|
|
10
|
-
"dataValidation": "An error occurred while validating the data",
|
|
11
|
-
"internalError": "An internal error occurred. This is most likely a bug on our end. Please try again later.",
|
|
12
|
-
"networkError": "A network error occurred. Are you connected to the internet?",
|
|
13
|
-
"canceledError": "The request was canceled.",
|
|
14
|
-
"unknownError": "An unknown error occurred. Please try again later.",
|
|
15
|
-
"unknownErrorWithCode": "An unknown error occurred. Error code: \"{{code}}\""
|
|
16
|
-
} } };
|
|
17
|
-
|
|
18
|
-
//#endregion
|
|
19
|
-
//#region src/lib/assets/locales/sl/translation.json
|
|
20
|
-
var translation_default = { openapi: { "sharedErrors": {
|
|
21
|
-
"dataValidation": "Pri preverjanju podatkov je prišlo do napake",
|
|
22
|
-
"internalError": "Prišlo je do notranje napake.",
|
|
23
|
-
"networkError": "Prišlo je do napake v omrežju.",
|
|
24
|
-
"canceledError": "Zahteva je bila preklicana.",
|
|
25
|
-
"unknownError": "Prišlo je do neznane napake.",
|
|
26
|
-
"unknownErrorWithCode": "Prišlo je do neznane napake. Koda napake: \"{{code}}\""
|
|
27
|
-
} } };
|
|
28
|
-
|
|
29
|
-
//#endregion
|
|
30
|
-
//#region src/lib/config/i18n.ts
|
|
31
|
-
const ns = "openapi";
|
|
32
|
-
const resources = {
|
|
33
|
-
en: { [ns]: translation_default$1 },
|
|
34
|
-
sl: { [ns]: translation_default }
|
|
35
|
-
};
|
|
36
|
-
const defaultLanguage = "en";
|
|
37
|
-
const i18n = i18next.createInstance();
|
|
38
|
-
i18n.init({
|
|
39
|
-
compatibilityJSON: "v4",
|
|
40
|
-
lng: defaultLanguage,
|
|
41
|
-
fallbackLng: defaultLanguage,
|
|
42
|
-
resources,
|
|
43
|
-
ns: Object.keys(resources.en),
|
|
44
|
-
defaultNS: ns,
|
|
45
|
-
interpolation: { escapeValue: false }
|
|
46
|
-
});
|
|
47
|
-
const defaultT = i18n.t.bind(i18n);
|
|
48
|
-
|
|
49
|
-
//#endregion
|
|
50
|
-
//#region src/lib/rest/rest.utils.ts
|
|
51
|
-
let RestUtils;
|
|
52
|
-
(function(_RestUtils) {
|
|
53
|
-
_RestUtils.extractServerResponseCode = (e) => {
|
|
54
|
-
if (e instanceof z.ZodError) return "validation-exception";
|
|
55
|
-
if (!isAxiosError(e)) return null;
|
|
56
|
-
if (!e.response) return null;
|
|
57
|
-
const data = e.response.data;
|
|
58
|
-
if (typeof data?.code === "string") return data.code;
|
|
59
|
-
return null;
|
|
60
|
-
};
|
|
61
|
-
_RestUtils.doesServerErrorMessageContain = (e, text) => {
|
|
62
|
-
const message = extractServerErrorMessage(e);
|
|
63
|
-
if (message === null || message === void 0) return false;
|
|
64
|
-
return message.toLowerCase().includes(text.toLowerCase());
|
|
65
|
-
};
|
|
66
|
-
const extractServerErrorMessage = _RestUtils.extractServerErrorMessage = (e) => {
|
|
67
|
-
if (e instanceof z.ZodError) return e.message;
|
|
68
|
-
if (!isAxiosError(e)) return null;
|
|
69
|
-
if (!e.response) return null;
|
|
70
|
-
const data = e.response.data;
|
|
71
|
-
if (typeof data?.message === "string") return data.message;
|
|
72
|
-
return null;
|
|
73
|
-
};
|
|
74
|
-
_RestUtils.extractContentDispositionFilename = (headers) => {
|
|
75
|
-
const contentDisposition = headers["content-disposition"];
|
|
76
|
-
return contentDisposition ? /filename=["']?([^"';]+)/i.exec(contentDisposition)?.[1] : void 0;
|
|
77
|
-
};
|
|
78
|
-
})(RestUtils || (RestUtils = {}));
|
|
79
|
-
|
|
80
|
-
//#endregion
|
|
81
|
-
//#region src/lib/rest/error-handling.ts
|
|
82
|
-
var ApplicationException = class extends Error {
|
|
83
|
-
code;
|
|
84
|
-
serverMessage = null;
|
|
85
|
-
constructor(message, code, serverMessage) {
|
|
86
|
-
super(message);
|
|
87
|
-
this.code = code;
|
|
88
|
-
this.serverMessage = serverMessage;
|
|
89
|
-
}
|
|
90
|
-
};
|
|
91
|
-
var ErrorHandler = class {
|
|
92
|
-
entries = [];
|
|
93
|
-
t;
|
|
94
|
-
onRethrowError;
|
|
95
|
-
constructor({ entries, t = defaultT, onRethrowError }) {
|
|
96
|
-
this.t = t;
|
|
97
|
-
this.onRethrowError = onRethrowError;
|
|
98
|
-
const dataValidationError = {
|
|
99
|
-
code: "DATA_VALIDATION_ERROR",
|
|
100
|
-
condition: (e) => {
|
|
101
|
-
return e instanceof z.ZodError;
|
|
102
|
-
},
|
|
103
|
-
getMessage: () => this.t("openapi.sharedErrors.dataValidation")
|
|
104
|
-
};
|
|
105
|
-
const internalError = {
|
|
106
|
-
code: "INTERNAL_ERROR",
|
|
107
|
-
condition: (e) => {
|
|
108
|
-
if (isAxiosError(e)) return e.response?.status != null && e.response.status >= 500 && e.response.status < 600;
|
|
109
|
-
return false;
|
|
110
|
-
},
|
|
111
|
-
getMessage: () => this.t("openapi.sharedErrors.internalError")
|
|
112
|
-
};
|
|
113
|
-
const networkError = {
|
|
114
|
-
code: "NETWORK_ERROR",
|
|
115
|
-
condition: (e) => {
|
|
116
|
-
if (isAxiosError(e)) return e.code === "ERR_NETWORK";
|
|
117
|
-
return false;
|
|
118
|
-
},
|
|
119
|
-
getMessage: () => this.t("openapi.sharedErrors.networkError")
|
|
120
|
-
};
|
|
121
|
-
const canceledError = {
|
|
122
|
-
code: "CANCELED_ERROR",
|
|
123
|
-
condition: (e) => {
|
|
124
|
-
if (isCancel(e)) return true;
|
|
125
|
-
if (isAxiosError(e) && e.code === "ECONNABORTED") return true;
|
|
126
|
-
return false;
|
|
127
|
-
},
|
|
128
|
-
getMessage: () => this.t("openapi.sharedErrors.canceledError")
|
|
129
|
-
};
|
|
130
|
-
const unknownError = {
|
|
131
|
-
code: "UNKNOWN_ERROR",
|
|
132
|
-
condition: () => true,
|
|
133
|
-
getMessage: (_, e) => {
|
|
134
|
-
const code = RestUtils.extractServerResponseCode(e);
|
|
135
|
-
const serverMessage = RestUtils.extractServerErrorMessage(e);
|
|
136
|
-
if (code) {
|
|
137
|
-
let message = `Unknown error, message from server: ${code}`;
|
|
138
|
-
if (serverMessage) message += ` ${serverMessage}`;
|
|
139
|
-
return message;
|
|
140
|
-
}
|
|
141
|
-
return this.t("openapi.sharedErrors.unknownError");
|
|
142
|
-
}
|
|
143
|
-
};
|
|
144
|
-
this.entries = [
|
|
145
|
-
...entries,
|
|
146
|
-
dataValidationError,
|
|
147
|
-
internalError,
|
|
148
|
-
networkError,
|
|
149
|
-
canceledError,
|
|
150
|
-
unknownError
|
|
151
|
-
];
|
|
152
|
-
}
|
|
153
|
-
matchesEntry(error, entry, code) {
|
|
154
|
-
if (entry.condition) return entry.condition(error);
|
|
155
|
-
return code === entry.code;
|
|
156
|
-
}
|
|
157
|
-
setTranslateFunction(t) {
|
|
158
|
-
this.t = t;
|
|
159
|
-
}
|
|
160
|
-
rethrowError(error) {
|
|
161
|
-
const code = RestUtils.extractServerResponseCode(error);
|
|
162
|
-
const errorEntry = this.entries.find((entry) => this.matchesEntry(error, entry, code));
|
|
163
|
-
const serverMessage = RestUtils.extractServerErrorMessage(error);
|
|
164
|
-
const exception = new ApplicationException(errorEntry.getMessage(this.t, error), errorEntry.code, serverMessage);
|
|
165
|
-
this.onRethrowError?.(error, exception);
|
|
166
|
-
throw exception;
|
|
167
|
-
}
|
|
168
|
-
getError(error) {
|
|
169
|
-
if (error instanceof ApplicationException) return error;
|
|
170
|
-
return null;
|
|
171
|
-
}
|
|
172
|
-
getErrorCode(error) {
|
|
173
|
-
if (error instanceof ApplicationException) return error.code;
|
|
174
|
-
return null;
|
|
175
|
-
}
|
|
176
|
-
static getErrorMessage(error, fallbackToUnknown = true) {
|
|
177
|
-
if (typeof error === "string") return error;
|
|
178
|
-
if (error instanceof Error) return error.message;
|
|
179
|
-
if (error instanceof ApplicationException) {
|
|
180
|
-
if (error.serverMessage != null) return error.serverMessage;
|
|
181
|
-
return error.message;
|
|
182
|
-
}
|
|
183
|
-
if (fallbackToUnknown) return defaultT("openapi.sharedErrors.unknownError");
|
|
184
|
-
return null;
|
|
185
|
-
}
|
|
186
|
-
};
|
|
187
|
-
const SharedErrorHandler = new ErrorHandler({ entries: [] });
|
|
188
|
-
|
|
189
|
-
//#endregion
|
|
190
7
|
//#region src/lib/rest/rest-client.ts
|
|
191
8
|
var RestClient = class {
|
|
192
9
|
client;
|
package/dist/sh.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { S as VALIDATION_ERROR_TYPE_TITLE, g as groupByType, h as GenerateType, i as getDataFromOpenAPIDoc, n as getOutputFileName, u as getTagFileName, x as Profiler } from "./generateCodeFromOpenAPIDoc-
|
|
3
|
-
import { n as resolveConfig, t as runGenerate } from "./generate.runner-
|
|
2
|
+
import { S as VALIDATION_ERROR_TYPE_TITLE, g as groupByType, h as GenerateType, i as getDataFromOpenAPIDoc, n as getOutputFileName, u as getTagFileName, x as Profiler } from "./generateCodeFromOpenAPIDoc-CV_esDUW.mjs";
|
|
3
|
+
import { n as resolveConfig, t as runGenerate } from "./generate.runner-CU-WCMgQ.mjs";
|
|
4
4
|
import { createRequire } from "node:module";
|
|
5
5
|
import yargs from "yargs";
|
|
6
6
|
import { hideBin } from "yargs/helpers";
|
|
@@ -39,7 +39,7 @@ function logBanner(message) {
|
|
|
39
39
|
* Fetch the version from package.json
|
|
40
40
|
*/
|
|
41
41
|
function getVersion() {
|
|
42
|
-
return "2.0.8-rc.
|
|
42
|
+
return "2.0.8-rc.17";
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
//#endregion
|
package/dist/vite.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import "./options-
|
|
2
|
-
import { t as OpenAPICodegenConfig } from "./config-
|
|
1
|
+
import "./options-Bvmh6rai.mjs";
|
|
2
|
+
import { t as OpenAPICodegenConfig } from "./config-B4HK4BLi.mjs";
|
|
3
3
|
import { Plugin } from "vite";
|
|
4
4
|
|
|
5
5
|
//#region src/vite/openapi-codegen.plugin.d.ts
|
package/dist/vite.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { x as Profiler } from "./generateCodeFromOpenAPIDoc-
|
|
2
|
-
import { t as runGenerate } from "./generate.runner-
|
|
1
|
+
import { x as Profiler } from "./generateCodeFromOpenAPIDoc-CV_esDUW.mjs";
|
|
2
|
+
import { t as runGenerate } from "./generate.runner-CU-WCMgQ.mjs";
|
|
3
3
|
import path from "path";
|
|
4
4
|
|
|
5
5
|
//#region src/vite/openapi-codegen.plugin.ts
|
package/package.json
CHANGED
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import { createContext, use, useMemo } from "react";
|
|
2
|
-
import { jsx } from "react/jsx-runtime";
|
|
3
|
-
|
|
4
|
-
//#region src/lib/config/router.context.tsx
|
|
5
|
-
let OpenApiRouter;
|
|
6
|
-
(function(_OpenApiRouter) {
|
|
7
|
-
const Context = createContext(null);
|
|
8
|
-
_OpenApiRouter.Provider = ({ children, replace }) => {
|
|
9
|
-
return /* @__PURE__ */ jsx(Context, {
|
|
10
|
-
value: useMemo(() => ({ replace }), [replace]),
|
|
11
|
-
children
|
|
12
|
-
});
|
|
13
|
-
};
|
|
14
|
-
_OpenApiRouter.useRouter = () => {
|
|
15
|
-
const context = use(Context);
|
|
16
|
-
if (!context) throw new Error("useRouter must be used within an OpenApiRouter.Provider");
|
|
17
|
-
return context;
|
|
18
|
-
};
|
|
19
|
-
})(OpenApiRouter || (OpenApiRouter = {}));
|
|
20
|
-
|
|
21
|
-
//#endregion
|
|
22
|
-
//#region src/lib/auth/auth.context.tsx
|
|
23
|
-
let AuthContext;
|
|
24
|
-
(function(_AuthContext) {
|
|
25
|
-
const Context = createContext({});
|
|
26
|
-
_AuthContext.Provider = ({ isAuthenticated, isInitializing, logout, updateTokens, accessToken, user, userPromise, routes, loadingState, children }) => {
|
|
27
|
-
const value = useMemo(() => ({
|
|
28
|
-
isAuthenticated,
|
|
29
|
-
isInitializing,
|
|
30
|
-
logout,
|
|
31
|
-
updateTokens,
|
|
32
|
-
accessToken,
|
|
33
|
-
user,
|
|
34
|
-
userPromise,
|
|
35
|
-
routes,
|
|
36
|
-
loadingState
|
|
37
|
-
}), [
|
|
38
|
-
isAuthenticated,
|
|
39
|
-
isInitializing,
|
|
40
|
-
logout,
|
|
41
|
-
updateTokens,
|
|
42
|
-
accessToken,
|
|
43
|
-
user,
|
|
44
|
-
userPromise,
|
|
45
|
-
routes,
|
|
46
|
-
loadingState
|
|
47
|
-
]);
|
|
48
|
-
return /* @__PURE__ */ jsx(Context.Provider, {
|
|
49
|
-
value,
|
|
50
|
-
children
|
|
51
|
-
});
|
|
52
|
-
};
|
|
53
|
-
_AuthContext.useAuth = () => {
|
|
54
|
-
return use(Context);
|
|
55
|
-
};
|
|
56
|
-
})(AuthContext || (AuthContext = {}));
|
|
57
|
-
|
|
58
|
-
//#endregion
|
|
59
|
-
export { OpenApiRouter as n, AuthContext as t };
|
|
File without changes
|