@povio/openapi-codegen-cli 3.2.0-rc.8 → 3.2.0-rc.9
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/AuthGuard-GbtTDXs0.d.mts +32 -0
- package/dist/AuthGuard-qpAtHaBz.mjs +24 -0
- package/dist/acl.d.mts +1 -1
- package/dist/acl.mjs +3 -2
- package/dist/{auth.context-YFWzkwoN.mjs → auth.context-COWO6ssl.mjs} +1 -19
- package/dist/auth.d.mts +2 -0
- package/dist/auth.mjs +3 -0
- package/dist/axios.d.mts +2 -0
- package/dist/axios.mjs +2 -0
- package/dist/config.d.mts +4 -0
- package/dist/config.mjs +5 -0
- package/dist/{error-handling-BMXC5P08.mjs → error-handling-BeydPL7s.mjs} +2 -36
- package/dist/{error-handling-CNOHs4Fc.d.mts → error-handling-LPEPQV1V.d.mts} +2 -38
- package/dist/errors.d.mts +3 -0
- package/dist/errors.mjs +2 -0
- package/dist/generate.runner-D8AYuEFm.mjs +184 -0
- package/dist/{generate.utils-CH2U2Dpr.cjs → generate.utils-CT-LA-gX.cjs} +6 -53
- package/dist/{generateCodeFromOpenAPIDoc-glAKBEGP.mjs → generateCodeFromOpenAPIDoc--ufinTug.mjs} +29 -4
- package/dist/{generateCodeFromOpenAPIDoc-CZT3sThI.cjs → generateCodeFromOpenAPIDoc-iEa8YAUQ.cjs} +48 -23
- package/dist/generator.mjs +4 -3
- package/dist/{getDataFromOpenAPIDoc-7RxjULpB.mjs → getDataFromOpenAPIDoc-D8w0QElH.mjs} +1 -1
- package/dist/i18n-B_brQh4X.d.mts +38 -0
- package/dist/i18n-D-FesqFb.mjs +36 -0
- package/dist/index.d.mts +8 -159
- package/dist/index.mjs +9 -256
- package/dist/metro.cjs +2 -2
- package/dist/metro.mjs +1 -1
- package/dist/{generate.runner-BvSprH6D.mjs → native-bindings-BTQGSGhU.mjs} +5 -208
- package/dist/openapi-codegen-native-darwin-arm64.node +0 -0
- package/dist/openapi-codegen-native-linux-x64.node +0 -0
- package/dist/openapi-codegen-native-win32-x64.node +0 -0
- package/dist/{openapi-codegen.runner-C93V7SGj.mjs → openapi-codegen.runner-6Yth6QZC.mjs} +2 -1
- package/dist/query.d.mts +3 -0
- package/dist/query.mjs +3 -0
- package/dist/queryConfig.context-CRJOgf19.d.mts +22 -0
- package/dist/queryConfig.context-CldQ5YL9.mjs +34 -0
- package/dist/rest-client-CQyFvqYC.d.mts +55 -0
- package/dist/rest-interceptor-D5NCNTm1.mjs +115 -0
- package/dist/rest.utils-rezWAIYL.d.mts +10 -0
- package/dist/router.context-EPlMBk3G.mjs +21 -0
- package/dist/sh.mjs +4 -3
- package/dist/useMutationEffects-DIdL8tlx.d.mts +29 -0
- package/dist/useMutationEffects-PB1fvKWM.mjs +68 -0
- package/dist/vite.mjs +1 -1
- package/dist/workspace.context-XWvQ_7Hg.mjs +26 -0
- package/dist/workspace.context-isVY9ves.d.mts +23 -0
- package/dist/zod.d.mts +1 -1
- package/dist/zod.mjs +1 -1
- package/package.json +39 -2
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { PropsWithChildren, ReactNode } from "react";
|
|
2
|
+
//#region src/lib/auth/auth.context.d.ts
|
|
3
|
+
declare namespace AuthContext {
|
|
4
|
+
export interface Routes {
|
|
5
|
+
authenticated?: string;
|
|
6
|
+
unauthenticated?: string;
|
|
7
|
+
}
|
|
8
|
+
interface Type<TUser = unknown> {
|
|
9
|
+
isAuthenticated: boolean;
|
|
10
|
+
isInitializing: boolean;
|
|
11
|
+
logout: () => void;
|
|
12
|
+
updateTokens?: (accessToken: string | null, refreshToken?: string | null) => void;
|
|
13
|
+
accessToken?: string | null;
|
|
14
|
+
user?: TUser | null;
|
|
15
|
+
userPromise?: () => Promise<TUser | null>;
|
|
16
|
+
routes?: Routes;
|
|
17
|
+
loadingState?: ReactNode;
|
|
18
|
+
}
|
|
19
|
+
type ProviderProps<TUser = unknown> = Type<TUser>;
|
|
20
|
+
export const Provider: <TUser>({ isAuthenticated, isInitializing, logout, updateTokens, accessToken, user, userPromise, routes, loadingState, children }: PropsWithChildren<ProviderProps<TUser>>) => import("react").JSX.Element;
|
|
21
|
+
export const useAuth: <TUser>() => Type<TUser>;
|
|
22
|
+
export {};
|
|
23
|
+
}
|
|
24
|
+
//#endregion
|
|
25
|
+
//#region src/lib/auth/AuthGuard.d.ts
|
|
26
|
+
interface AuthGuardProps {
|
|
27
|
+
type: "public-only" | "private";
|
|
28
|
+
redirectTo?: string;
|
|
29
|
+
}
|
|
30
|
+
declare const AuthGuard: ({ type, redirectTo, children }: PropsWithChildren<AuthGuardProps>) => import("react").ReactNode;
|
|
31
|
+
//#endregion
|
|
32
|
+
export { AuthGuardProps as n, AuthContext as r, AuthGuard as t };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { t as OpenApiRouter } from "./router.context-EPlMBk3G.mjs";
|
|
2
|
+
import { t as AuthContext } from "./auth.context-COWO6ssl.mjs";
|
|
3
|
+
import { useEffect, useState } from "react";
|
|
4
|
+
//#region src/lib/auth/AuthGuard.tsx
|
|
5
|
+
const AuthGuard = ({ type, redirectTo, children }) => {
|
|
6
|
+
const { isAuthenticated, routes, loadingState } = AuthContext.useAuth();
|
|
7
|
+
const { replace } = OpenApiRouter.useRouter();
|
|
8
|
+
const [hasMounted, setHasMounted] = useState(false);
|
|
9
|
+
useEffect(() => {
|
|
10
|
+
setHasMounted(true);
|
|
11
|
+
}, []);
|
|
12
|
+
if (!hasMounted) return loadingState;
|
|
13
|
+
if (type === "private" && !isAuthenticated) {
|
|
14
|
+
replace(redirectTo || routes?.unauthenticated || "/");
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
if (type === "public-only" && isAuthenticated) {
|
|
18
|
+
replace(redirectTo || routes?.authenticated || "/");
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
return children;
|
|
22
|
+
};
|
|
23
|
+
//#endregion
|
|
24
|
+
export { AuthGuard as t };
|
package/dist/acl.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as ErrorHandler } from "./error-handling-
|
|
1
|
+
import { a as ErrorHandler } from "./error-handling-LPEPQV1V.mjs";
|
|
2
2
|
import { PropsWithChildren } from "react";
|
|
3
3
|
import { AbilityTuple, PureAbility, RawRuleOf, Subject } from "@casl/ability";
|
|
4
4
|
import { PackRule } from "@casl/ability/extra";
|
package/dist/acl.mjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { i as SharedErrorHandler } from "./error-handling-
|
|
2
|
-
import {
|
|
1
|
+
import { i as SharedErrorHandler } from "./error-handling-BeydPL7s.mjs";
|
|
2
|
+
import { t as OpenApiRouter } from "./router.context-EPlMBk3G.mjs";
|
|
3
|
+
import { t as AuthContext } from "./auth.context-COWO6ssl.mjs";
|
|
3
4
|
import { createContext, useCallback, useMemo } from "react";
|
|
4
5
|
import { jsx } from "react/jsx-runtime";
|
|
5
6
|
import { AbilityBuilder, createMongoAbility } from "@casl/ability";
|
|
@@ -1,23 +1,5 @@
|
|
|
1
1
|
import { createContext, use, useMemo } from "react";
|
|
2
2
|
import { jsx } from "react/jsx-runtime";
|
|
3
|
-
//#region src/lib/config/router.context.tsx
|
|
4
|
-
let OpenApiRouter;
|
|
5
|
-
(function(_OpenApiRouter) {
|
|
6
|
-
const Context = createContext(null);
|
|
7
|
-
_OpenApiRouter.Provider = ({ children, replace }) => {
|
|
8
|
-
const value = useMemo(() => ({ replace }), [replace]);
|
|
9
|
-
return /* @__PURE__ */ jsx(Context, {
|
|
10
|
-
value,
|
|
11
|
-
children
|
|
12
|
-
});
|
|
13
|
-
};
|
|
14
|
-
_OpenApiRouter.useRouter = () => {
|
|
15
|
-
const context = use(Context);
|
|
16
|
-
if (!context) throw new Error("useRouter must be used within an OpenApiRouter.Provider");
|
|
17
|
-
return context;
|
|
18
|
-
};
|
|
19
|
-
})(OpenApiRouter || (OpenApiRouter = {}));
|
|
20
|
-
//#endregion
|
|
21
3
|
//#region src/lib/auth/auth.context.tsx
|
|
22
4
|
let AuthContext;
|
|
23
5
|
(function(_AuthContext) {
|
|
@@ -54,4 +36,4 @@ let AuthContext;
|
|
|
54
36
|
};
|
|
55
37
|
})(AuthContext || (AuthContext = {}));
|
|
56
38
|
//#endregion
|
|
57
|
-
export {
|
|
39
|
+
export { AuthContext as t };
|
package/dist/auth.d.mts
ADDED
package/dist/auth.mjs
ADDED
package/dist/axios.d.mts
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
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";
|
|
2
|
+
export { type RestClient as IRestClient, type RequestConfig, type RequestInfo, type Response, RestClient$1 as RestClient, RestInterceptor };
|
package/dist/axios.mjs
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { i as resources, n as configureTranslations, r as ns, t as TranslateFunction } from "./i18n-B_brQh4X.mjs";
|
|
2
|
+
import { n as useWorkspaceContext, r as OpenApiRouter, t as OpenApiWorkspaceContext } from "./workspace.context-isVY9ves.mjs";
|
|
3
|
+
import { i as QueryModule, n as InvalidationMapFunc, r as OpenApiQueryConfig, t as InvalidationMap } from "./queryConfig.context-CRJOgf19.mjs";
|
|
4
|
+
export { type InvalidationMap, type InvalidationMapFunc, OpenApiQueryConfig, OpenApiRouter, OpenApiWorkspaceContext, type QueryModule, type TranslateFunction, configureTranslations, ns, resources, useWorkspaceContext };
|
package/dist/config.mjs
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { i as resources, n as ns, t as configureTranslations } from "./i18n-D-FesqFb.mjs";
|
|
2
|
+
import { t as OpenApiQueryConfig } from "./queryConfig.context-CldQ5YL9.mjs";
|
|
3
|
+
import { t as OpenApiRouter } from "./router.context-EPlMBk3G.mjs";
|
|
4
|
+
import { n as useWorkspaceContext, t as OpenApiWorkspaceContext } from "./workspace.context-XWvQ_7Hg.mjs";
|
|
5
|
+
export { OpenApiQueryConfig, OpenApiRouter, OpenApiWorkspaceContext, configureTranslations, ns, resources, useWorkspaceContext };
|
|
@@ -1,40 +1,6 @@
|
|
|
1
|
+
import { n as ns, r as resolveT } from "./i18n-D-FesqFb.mjs";
|
|
1
2
|
import { t as HttpError } from "./rest-transport.types-DxitRtsB.mjs";
|
|
2
3
|
import { z } from "zod";
|
|
3
|
-
//#region src/lib/assets/locales/en/translation.json
|
|
4
|
-
var translation_default$1 = { openapi: { "sharedErrors": {
|
|
5
|
-
"dataValidation": "An error occurred while validating the data",
|
|
6
|
-
"internalError": "An internal error occurred. This is most likely a bug on our end. Please try again later.",
|
|
7
|
-
"networkError": "A network error occurred. Are you connected to the internet?",
|
|
8
|
-
"canceledError": "The request was canceled.",
|
|
9
|
-
"unknownError": "An unknown error occurred. Please try again later.",
|
|
10
|
-
"unknownErrorWithCode": "An unknown error occurred. Error code: \"{{code}}\""
|
|
11
|
-
} } };
|
|
12
|
-
//#endregion
|
|
13
|
-
//#region src/lib/assets/locales/sl/translation.json
|
|
14
|
-
var translation_default = { openapi: { "sharedErrors": {
|
|
15
|
-
"dataValidation": "Pri preverjanju podatkov je prišlo do napake",
|
|
16
|
-
"internalError": "Prišlo je do notranje napake.",
|
|
17
|
-
"networkError": "Prišlo je do napake v omrežju.",
|
|
18
|
-
"canceledError": "Zahteva je bila preklicana.",
|
|
19
|
-
"unknownError": "Prišlo je do neznane napake.",
|
|
20
|
-
"unknownErrorWithCode": "Prišlo je do neznane napake. Koda napake: \"{{code}}\""
|
|
21
|
-
} } };
|
|
22
|
-
//#endregion
|
|
23
|
-
//#region src/lib/config/i18n.ts
|
|
24
|
-
const ns = "openapi";
|
|
25
|
-
const resources = {
|
|
26
|
-
en: { [ns]: translation_default$1 },
|
|
27
|
-
sl: { [ns]: translation_default }
|
|
28
|
-
};
|
|
29
|
-
let getT = null;
|
|
30
|
-
function configureTranslations(getter) {
|
|
31
|
-
getT = () => getter();
|
|
32
|
-
}
|
|
33
|
-
function resolveT() {
|
|
34
|
-
if (!getT) throw new Error("Translations not configured. Call configureTranslations() at app startup.");
|
|
35
|
-
return getT();
|
|
36
|
-
}
|
|
37
|
-
//#endregion
|
|
38
4
|
//#region src/lib/rest/http-error.utils.ts
|
|
39
5
|
function isAxiosErrorLike(error) {
|
|
40
6
|
return typeof error === "object" && error !== null && "isAxiosError" in error;
|
|
@@ -215,4 +181,4 @@ var ErrorHandler = class ErrorHandler {
|
|
|
215
181
|
};
|
|
216
182
|
const SharedErrorHandler = new ErrorHandler({ entries: [] });
|
|
217
183
|
//#endregion
|
|
218
|
-
export { RestUtils as a,
|
|
184
|
+
export { RestUtils as a, SharedErrorHandler as i, DomainErrorRegistry as n, ErrorHandler as r, ApplicationException as t };
|
|
@@ -1,40 +1,4 @@
|
|
|
1
|
-
|
|
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
|
|
1
|
+
import { t as TranslateFunction } from "./i18n-B_brQh4X.mjs";
|
|
38
2
|
//#region src/lib/rest/error-handling.d.ts
|
|
39
3
|
type GeneralErrorCodes = "DATA_VALIDATION_ERROR" | "NETWORK_ERROR" | "CANCELED_ERROR" | "INTERNAL_ERROR" | "UNKNOWN_ERROR";
|
|
40
4
|
declare class ApplicationException<CodeT> extends Error {
|
|
@@ -80,4 +44,4 @@ declare class ErrorHandler<CodeT extends string | number> {
|
|
|
80
44
|
}
|
|
81
45
|
declare const SharedErrorHandler: ErrorHandler<never>;
|
|
82
46
|
//#endregion
|
|
83
|
-
export { ErrorHandler as a, SharedErrorHandler as c,
|
|
47
|
+
export { ErrorHandler as a, SharedErrorHandler as c, ErrorEntry as i, DomainErrorEntry as n, ErrorHandlerOptions as o, DomainErrorRegistry as r, GeneralErrorCodes as s, ApplicationException as t };
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
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";
|
|
2
|
+
import { t as RestUtils } from "./rest.utils-rezWAIYL.mjs";
|
|
3
|
+
export { ApplicationException, type DomainErrorEntry, DomainErrorRegistry, type ErrorEntry, ErrorHandler, type ErrorHandlerOptions, type GeneralErrorCodes, RestUtils, SharedErrorHandler };
|
package/dist/errors.mjs
ADDED
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
import { D as getTagFileName, Wn as Profiler, a as writeGenerateFileData, dt as DEFAULT_GENERATE_OPTIONS, i as removeStaleGeneratedFiles, n as shouldUseNativeCodegen, o as deepMerge, r as getOutputFileName, t as compileNativeData } from "./native-bindings-BTQGSGhU.mjs";
|
|
2
|
+
import fs from "fs";
|
|
3
|
+
import path from "path";
|
|
4
|
+
//#region src/generators/core/resolveConfig.ts
|
|
5
|
+
function resolveConfig({ fileConfig = {}, params: { includeTags, excludeTags, inlineEndpointsExcludeModules, workspaceContext, ...options } }) {
|
|
6
|
+
const resolvedConfig = deepMerge(DEFAULT_GENERATE_OPTIONS, fileConfig ?? {}, {
|
|
7
|
+
...options,
|
|
8
|
+
includeTags: includeTags?.split(","),
|
|
9
|
+
excludeTags: excludeTags?.split(","),
|
|
10
|
+
inlineEndpointsExcludeModules: inlineEndpointsExcludeModules?.split(","),
|
|
11
|
+
workspaceContext: workspaceContext?.split(",")
|
|
12
|
+
});
|
|
13
|
+
resolvedConfig.checkAcl = resolvedConfig.acl && resolvedConfig.checkAcl;
|
|
14
|
+
resolvedConfig.workspaceContext = Array.from(new Set((resolvedConfig.workspaceContext ?? []).map((value) => value.trim()).filter(Boolean)));
|
|
15
|
+
return resolvedConfig;
|
|
16
|
+
}
|
|
17
|
+
//#endregion
|
|
18
|
+
//#region src/native/generateFilesFromNativeOpenAPI.ts
|
|
19
|
+
function generateFilesFromNativeOpenAPI(source, yaml, options) {
|
|
20
|
+
if (!supportsCompleteNativeRender(options)) {
|
|
21
|
+
if (process.env.OPENAPI_CODEGEN_REQUIRE_FULL_NATIVE === "1") throw new Error("The selected options are not supported by the full native renderer");
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
const nativeData = compileNativeData(source, yaml, JSON.stringify({
|
|
25
|
+
...options,
|
|
26
|
+
nativeCompact: true
|
|
27
|
+
})).data;
|
|
28
|
+
if (!nativeData.renderedComplete) {
|
|
29
|
+
if (process.env.OPENAPI_CODEGEN_REQUIRE_FULL_NATIVE === "1") throw new Error("The selected options are not supported by the full native renderer");
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
const files = [];
|
|
33
|
+
const taggedRenderers = options.modelsOnly ? [["models", nativeData.renderedModels]] : [
|
|
34
|
+
["models", nativeData.renderedModels],
|
|
35
|
+
["endpoints", nativeData.renderedEndpoints],
|
|
36
|
+
["queries", nativeData.renderedQueries],
|
|
37
|
+
...options.acl ? [["acl", nativeData.renderedAcl]] : []
|
|
38
|
+
];
|
|
39
|
+
for (const tag of nativeData.renderedTags) for (const [type, rendered] of taggedRenderers) {
|
|
40
|
+
const content = rendered[tag];
|
|
41
|
+
if (content) files.push(taggedFile(options, tag, type, content));
|
|
42
|
+
}
|
|
43
|
+
if (!options.modelsOnly) {
|
|
44
|
+
if (options.acl && nativeData.renderedShared.appAcl) files.push(outputFile(options, "acl/app.ability.ts", nativeData.renderedShared.appAcl));
|
|
45
|
+
if (options.mutationEffects && nativeData.renderedShared.queryModules) files.push(outputFile(options, "queryModules.ts", nativeData.renderedShared.queryModules));
|
|
46
|
+
if (!options.restClientImportPath) files.push(outputFile(options, "app-rest-client.ts", `import { ${options.restClient === "native" ? "NativeRestClient" : "RestClient"} } from "@povio/openapi-codegen-cli${options.restClient === "native" ? "/native" : ""}";\n\nexport const AppRestClient = new ${options.restClient === "native" ? "NativeRestClient" : "RestClient"}({\n config: {\n baseURL: "${nativeData.baseUrl}"\n },\n});\n`));
|
|
47
|
+
if (nativeData.renderedShared.domainErrors) files.push(outputFile(options, "domain-errors.ts", nativeData.renderedShared.domainErrors));
|
|
48
|
+
}
|
|
49
|
+
return files;
|
|
50
|
+
}
|
|
51
|
+
function supportsCompleteNativeRender(options) {
|
|
52
|
+
return options.splitByTags && (options.modelsInCommon && options.tsNamespaces || !options.modelsInCommon && !options.tsNamespaces) && !options.inlineEndpoints && !options.builderConfigs && (options.workspaceContext?.length ?? 0) === 0;
|
|
53
|
+
}
|
|
54
|
+
function taggedFile(options, tag, type, content) {
|
|
55
|
+
return outputFile(options, getTagFileName({
|
|
56
|
+
tag,
|
|
57
|
+
type,
|
|
58
|
+
options
|
|
59
|
+
}), content);
|
|
60
|
+
}
|
|
61
|
+
function outputFile(options, fileName, content) {
|
|
62
|
+
return {
|
|
63
|
+
fileName: getOutputFileName({
|
|
64
|
+
output: options.output,
|
|
65
|
+
fileName
|
|
66
|
+
}),
|
|
67
|
+
content
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
//#endregion
|
|
71
|
+
//#region src/generators/run/generate.runner.ts
|
|
72
|
+
async function runGenerate({ fileConfig, params, formatGeneratedFile, profiler = new Profiler(process.env.OPENAPI_CODEGEN_PROFILE === "1") }) {
|
|
73
|
+
const config = profiler.runSync("config.resolve", () => resolveConfig({
|
|
74
|
+
fileConfig,
|
|
75
|
+
params: params ?? {}
|
|
76
|
+
}));
|
|
77
|
+
const useNative = shouldUseNativeCodegen();
|
|
78
|
+
const isJson = path.extname(new URL(config.input, "file://").pathname).toLowerCase() === ".json";
|
|
79
|
+
const useRawNativeInput = useNative && (isJson || typeof Bun === "undefined");
|
|
80
|
+
let nativeInput = useRawNativeInput ? await getRawOpenApiSource(config.input, profiler) : await getOpenApiSource(config.input, profiler);
|
|
81
|
+
if (useNative && !useRawNativeInput) {
|
|
82
|
+
const document = "document" in nativeInput ? nativeInput.document : void 0;
|
|
83
|
+
nativeInput = {
|
|
84
|
+
...nativeInput,
|
|
85
|
+
source: profiler.runSync("openapi.serialize", () => JSON.stringify(document)),
|
|
86
|
+
yaml: false
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
const openApiDoc = "document" in nativeInput ? nativeInput.document : {};
|
|
90
|
+
const outputExists = fs.existsSync(config.output);
|
|
91
|
+
const filesData = await profiler.runAsync("generate.total", async () => {
|
|
92
|
+
if (useNative) {
|
|
93
|
+
const nativeFiles = generateFilesFromNativeOpenAPI(nativeInput.source, nativeInput.yaml, config);
|
|
94
|
+
if (nativeFiles) return nativeFiles;
|
|
95
|
+
}
|
|
96
|
+
const { generateCodeFromOpenAPIDoc } = await import("./generateCodeFromOpenAPIDoc--ufinTug.mjs").then((n) => n.n);
|
|
97
|
+
return generateCodeFromOpenAPIDoc(openApiDoc, config, profiler, {
|
|
98
|
+
source: nativeInput.source,
|
|
99
|
+
yaml: nativeInput.yaml
|
|
100
|
+
});
|
|
101
|
+
});
|
|
102
|
+
if (config.clearOutput) profiler.runSync("files.removeStaleGenerated", () => {
|
|
103
|
+
removeStaleGeneratedFiles({
|
|
104
|
+
output: config.output,
|
|
105
|
+
filesData,
|
|
106
|
+
options: config
|
|
107
|
+
});
|
|
108
|
+
});
|
|
109
|
+
await profiler.runAsync("files.write", async () => {
|
|
110
|
+
await writeGenerateFileData(filesData, {
|
|
111
|
+
formatGeneratedFile,
|
|
112
|
+
skipExistingCheck: !outputExists
|
|
113
|
+
});
|
|
114
|
+
});
|
|
115
|
+
return {
|
|
116
|
+
skipped: false,
|
|
117
|
+
config,
|
|
118
|
+
stats: getGenerateStats(filesData, config)
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
async function getOpenApiDoc(input, profiler = new Profiler(false)) {
|
|
122
|
+
return (await getOpenApiSource(input, profiler)).document;
|
|
123
|
+
}
|
|
124
|
+
async function getOpenApiSource(input, profiler = new Profiler(false)) {
|
|
125
|
+
const raw = await getRawOpenApiSource(input, profiler);
|
|
126
|
+
const { source } = raw;
|
|
127
|
+
const document = await profiler.runAsync("openapi.parse", () => parseOpenApiSource(input, source));
|
|
128
|
+
return {
|
|
129
|
+
...raw,
|
|
130
|
+
document
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
async function getRawOpenApiSource(input, profiler = new Profiler(false)) {
|
|
134
|
+
return {
|
|
135
|
+
source: await profiler.runAsync("openapi.read", () => readOpenApiSource(input)),
|
|
136
|
+
yaml: path.extname(new URL(input, "file://").pathname).toLowerCase() !== ".json"
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
async function readOpenApiSource(input) {
|
|
140
|
+
if (/^https?:\/\//i.test(input)) {
|
|
141
|
+
const response = await fetch(input);
|
|
142
|
+
if (!response.ok) throw new Error(`Unable to load OpenAPI document: ${response.status} ${response.statusText}`);
|
|
143
|
+
return response.text();
|
|
144
|
+
}
|
|
145
|
+
return fs.promises.readFile(input, "utf-8");
|
|
146
|
+
}
|
|
147
|
+
async function parseOpenApiSource(input, source) {
|
|
148
|
+
try {
|
|
149
|
+
return JSON.parse(source.charCodeAt(0) === 65279 ? source.slice(1) : source);
|
|
150
|
+
} catch (error) {
|
|
151
|
+
if (path.extname(new URL(input, "file://").pathname).toLowerCase() === ".json") throw error;
|
|
152
|
+
if (typeof Bun !== "undefined") return Bun.YAML.parse(source);
|
|
153
|
+
const { parse } = await import("yaml");
|
|
154
|
+
return parse(source);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
function getGenerateStats(filesData, config) {
|
|
158
|
+
const generatedFilesCount = filesData.length;
|
|
159
|
+
if (generatedFilesCount === 0) return {
|
|
160
|
+
generatedFilesCount,
|
|
161
|
+
generatedModulesCount: 0
|
|
162
|
+
};
|
|
163
|
+
if (!config.splitByTags) return {
|
|
164
|
+
generatedFilesCount,
|
|
165
|
+
generatedModulesCount: 1
|
|
166
|
+
};
|
|
167
|
+
const moduleSuffixes = new Set(Object.values(config.configs).map((generateConfig) => generateConfig.outputFileNameSuffix).filter(Boolean));
|
|
168
|
+
const modules = /* @__PURE__ */ new Set();
|
|
169
|
+
for (const file of filesData) {
|
|
170
|
+
const segments = path.relative(config.output, file.fileName).split(path.sep).filter(Boolean);
|
|
171
|
+
if (segments.length < 2) continue;
|
|
172
|
+
const moduleName = segments[0];
|
|
173
|
+
const fileName = segments[segments.length - 1];
|
|
174
|
+
if (!fileName.startsWith(`${moduleName}.`)) continue;
|
|
175
|
+
const suffix = fileName.slice(moduleName.length + 1).replace(/\.tsx?$/, "");
|
|
176
|
+
if (moduleSuffixes.has(suffix)) modules.add(moduleName);
|
|
177
|
+
}
|
|
178
|
+
return {
|
|
179
|
+
generatedFilesCount,
|
|
180
|
+
generatedModulesCount: modules.size
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
//#endregion
|
|
184
|
+
export { runGenerate as n, resolveConfig as r, getOpenApiDoc as t };
|
|
@@ -35,6 +35,8 @@ let openapi_types = require("openapi-types");
|
|
|
35
35
|
const PACKAGE_IMPORT_PATH = "@povio/openapi-codegen-cli";
|
|
36
36
|
const NATIVE_PACKAGE_IMPORT_PATH = `${PACKAGE_IMPORT_PATH}/native`;
|
|
37
37
|
const REST_PACKAGE_IMPORT_PATH = `${PACKAGE_IMPORT_PATH}/rest`;
|
|
38
|
+
const QUERY_PACKAGE_IMPORT_PATH = `${PACKAGE_IMPORT_PATH}/query`;
|
|
39
|
+
const CONFIG_PACKAGE_IMPORT_PATH = `${PACKAGE_IMPORT_PATH}/config`;
|
|
38
40
|
//#endregion
|
|
39
41
|
//#region src/generators/const/zod.const.ts
|
|
40
42
|
const SCHEMA_SUFFIX = "Schema";
|
|
@@ -115,8 +117,8 @@ const DEFAULT_GENERATE_OPTIONS = {
|
|
|
115
117
|
parseRequestParams: true,
|
|
116
118
|
inlineEndpoints: false,
|
|
117
119
|
inlineEndpointsExcludeModules: [],
|
|
118
|
-
queryTypesImportPath:
|
|
119
|
-
mutationEffectsImportPath:
|
|
120
|
+
queryTypesImportPath: QUERY_PACKAGE_IMPORT_PATH,
|
|
121
|
+
mutationEffectsImportPath: QUERY_PACKAGE_IMPORT_PATH,
|
|
120
122
|
axiosRequestConfig: false,
|
|
121
123
|
mutationEffects: true,
|
|
122
124
|
mutationDefaultOnError: false,
|
|
@@ -376,31 +378,6 @@ function compileNativeData(source, yaml, optionsJson) {
|
|
|
376
378
|
return getNativeBindings().compileData(source, yaml, optionsJson);
|
|
377
379
|
}
|
|
378
380
|
//#endregion
|
|
379
|
-
//#region src/generators/const/acl.const.ts
|
|
380
|
-
const ACL_APP_ABILITY_FILE = {
|
|
381
|
-
fileName: "acl/app.ability",
|
|
382
|
-
extension: "ts"
|
|
383
|
-
};
|
|
384
|
-
const ACL_APP_ABILITIES = "AppAbilities";
|
|
385
|
-
const ACL_CHECK_HOOK = "useAclCheck";
|
|
386
|
-
const CASL_ABILITY_BINDING = {
|
|
387
|
-
abilityTuple: "AbilityTuple",
|
|
388
|
-
pureAbility: "PureAbility",
|
|
389
|
-
forcedSubject: "ForcedSubject",
|
|
390
|
-
subjectType: "Subject",
|
|
391
|
-
subject: "subject"
|
|
392
|
-
};
|
|
393
|
-
const CASL_ABILITY_IMPORT = {
|
|
394
|
-
bindings: [
|
|
395
|
-
CASL_ABILITY_BINDING.abilityTuple,
|
|
396
|
-
CASL_ABILITY_BINDING.pureAbility,
|
|
397
|
-
CASL_ABILITY_BINDING.forcedSubject,
|
|
398
|
-
CASL_ABILITY_BINDING.subjectType,
|
|
399
|
-
CASL_ABILITY_BINDING.subject
|
|
400
|
-
],
|
|
401
|
-
from: "@casl/ability"
|
|
402
|
-
};
|
|
403
|
-
//#endregion
|
|
404
381
|
//#region src/generators/const/deps.const.ts
|
|
405
382
|
const APP_REST_CLIENT_NAME = "AppRestClient";
|
|
406
383
|
const APP_REST_CLIENT_FILE = {
|
|
@@ -1382,24 +1359,6 @@ function getQueryTypesImportPath(options) {
|
|
|
1382
1359
|
return options.queryTypesImportPath;
|
|
1383
1360
|
}
|
|
1384
1361
|
//#endregion
|
|
1385
|
-
Object.defineProperty(exports, "ACL_APP_ABILITIES", {
|
|
1386
|
-
enumerable: true,
|
|
1387
|
-
get: function() {
|
|
1388
|
-
return ACL_APP_ABILITIES;
|
|
1389
|
-
}
|
|
1390
|
-
});
|
|
1391
|
-
Object.defineProperty(exports, "ACL_APP_ABILITY_FILE", {
|
|
1392
|
-
enumerable: true,
|
|
1393
|
-
get: function() {
|
|
1394
|
-
return ACL_APP_ABILITY_FILE;
|
|
1395
|
-
}
|
|
1396
|
-
});
|
|
1397
|
-
Object.defineProperty(exports, "ACL_CHECK_HOOK", {
|
|
1398
|
-
enumerable: true,
|
|
1399
|
-
get: function() {
|
|
1400
|
-
return ACL_CHECK_HOOK;
|
|
1401
|
-
}
|
|
1402
|
-
});
|
|
1403
1362
|
Object.defineProperty(exports, "ALLOWED_METHODS", {
|
|
1404
1363
|
enumerable: true,
|
|
1405
1364
|
get: function() {
|
|
@@ -1472,16 +1431,10 @@ Object.defineProperty(exports, "BUILDERS_UTILS", {
|
|
|
1472
1431
|
return BUILDERS_UTILS;
|
|
1473
1432
|
}
|
|
1474
1433
|
});
|
|
1475
|
-
Object.defineProperty(exports, "
|
|
1476
|
-
enumerable: true,
|
|
1477
|
-
get: function() {
|
|
1478
|
-
return CASL_ABILITY_BINDING;
|
|
1479
|
-
}
|
|
1480
|
-
});
|
|
1481
|
-
Object.defineProperty(exports, "CASL_ABILITY_IMPORT", {
|
|
1434
|
+
Object.defineProperty(exports, "CONFIG_PACKAGE_IMPORT_PATH", {
|
|
1482
1435
|
enumerable: true,
|
|
1483
1436
|
get: function() {
|
|
1484
|
-
return
|
|
1437
|
+
return CONFIG_PACKAGE_IMPORT_PATH;
|
|
1485
1438
|
}
|
|
1486
1439
|
});
|
|
1487
1440
|
Object.defineProperty(exports, "DATETIME_SCHEMA", {
|
package/dist/{generateCodeFromOpenAPIDoc-glAKBEGP.mjs → generateCodeFromOpenAPIDoc--ufinTug.mjs}
RENAMED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { r as getZodSchemaRefs, t as getDataFromOpenAPIDoc } from "./getDataFromOpenAPIDoc-
|
|
2
|
-
import { $ as getImportedAbilityFunctionName, A as getEndpointsImports, An as
|
|
1
|
+
import { r as getZodSchemaRefs, t as getDataFromOpenAPIDoc } from "./getDataFromOpenAPIDoc-D8w0QElH.mjs";
|
|
2
|
+
import { $ as getImportedAbilityFunctionName, A as getEndpointsImports, An as NATIVE_RESPONSE_TYPE, At as APP_REST_CLIENT_NAME, B as getPrefetchInfiniteQueryName, Bt as PACKAGE_IMPORT_PATH, C as getAppRestClientImportPath, Cn as ZOD_IMPORT, D as getTagFileName, Dn as AXIOS_REQUEST_CONFIG_TYPE, Dt as isEnumZodSchema, E as getQueryTypesImportPath, En as AXIOS_REQUEST_CONFIG_NAME, F as mergeImports, Ft as QUERY_MODULE_ENUM, G as getAbilityConditionType, H as getQueryName, Ht as getNamespaceName, I as getImportedInfiniteQueryName, In as shouldInlineEndpointsForTag, It as QUERY_OPTIONS_TYPES, J as getAbilityFunctionName, K as getAbilityConditionsTypes, L as getImportedQueryName, Ln as camelToSpaceSeparated, Lt as ZOD_EXTENDED, M as getInfiniteQueriesImports, Mt as DOMAIN_ERRORS_FILE, N as getModelsImports, Nn as getEndpointTag, Nt as MUTATION_EFFECTS, O as getTagImportPath, Ot as isNamedZodSchema, P as getQueriesImports, Pt as QUERY_MODULES_FILE, Q as getAppAbilitiesType, R as getInfiniteQueryName, Rn as capitalize, Rt as CONFIG_PACKAGE_IMPORT_PATH, T as getQueryModulesImportPath, Tn as AXIOS_IMPORT, U as getQueryOptionsName, V as getPrefetchQueryName, Vn as kebabToCamel, Vt as REST_PACKAGE_IMPORT_PATH, W as getAbilityAction, Wn as Profiler, X as getAbilitySubjectTypes, Y as getAbilitySubject, Z as getAclData, Zt as isParamMediaTypeAllowed, _ as hasEndpointConfig, _t as isReadAllEndpoint, at as getZodSchemaInferedTypeName, b as requiresBody, bt as invalidVariableNameCharactersToCamel, c as getDestructuredVariables, cn as isReferenceObject, ct as getSchemaDescriptions, d as isQuery, dt as DEFAULT_GENERATE_OPTIONS, et as hasAbilityConditions, f as getEndpointBody, fn as ANY_SCHEMA, ft as getPathSegments, g as getImportedEndpointName, gt as isPathSegmentParam, h as getEndpointPath, ht as isDeleteEndpoint, it as getZodSchemaDescription, j as getImportPath, jn as getRequestConfigTypeName, jt as BUILDERS_UTILS, k as getAclImports, kn as JSON_APPLICATION_FORMAT, kt as APP_REST_CLIENT_FILE, l as isInfiniteQuery, ln as isSchemaObject, m as getEndpointName, mt as isCreateEndpoint, n as shouldUseNativeCodegen, nt as getImportedZodSchemaInferedTypeName, ot as getZodSchemaPropertyDescriptions, p as getEndpointConfig, pt as isBulkDeleteEndpoint, q as getAbilityDescription, r as getOutputFileName, rt as getImportedZodSchemaName, st as getZodSchemaType, t as compileNativeData, tt as renderAclCheckCall, u as isMutation, ut as getUniqueArray, v as mapEndpointParamsToFunctionParams, vt as isReadEndpoint, w as getFileNameWithExtension, wn as AXIOS_DEFAULT_IMPORT_NAME, y as renderMediaUploadMutationBody, yt as isUpdateEndpoint, z as getInfiniteQueryOptionsName, zt as NATIVE_PACKAGE_IMPORT_PATH } from "./native-bindings-BTQGSGhU.mjs";
|
|
3
3
|
import "node:module";
|
|
4
4
|
//#region \0rolldown/runtime.js
|
|
5
5
|
var __defProp = Object.defineProperty;
|
|
@@ -13,6 +13,31 @@ var __exportAll = (all, no_symbols) => {
|
|
|
13
13
|
return target;
|
|
14
14
|
};
|
|
15
15
|
//#endregion
|
|
16
|
+
//#region src/generators/const/acl.const.ts
|
|
17
|
+
const ACL_APP_ABILITY_FILE = {
|
|
18
|
+
fileName: "acl/app.ability",
|
|
19
|
+
extension: "ts"
|
|
20
|
+
};
|
|
21
|
+
const ACL_APP_ABILITIES = "AppAbilities";
|
|
22
|
+
const ACL_CHECK_HOOK = "useAclCheck";
|
|
23
|
+
const CASL_ABILITY_BINDING = {
|
|
24
|
+
abilityTuple: "AbilityTuple",
|
|
25
|
+
pureAbility: "PureAbility",
|
|
26
|
+
forcedSubject: "ForcedSubject",
|
|
27
|
+
subjectType: "Subject",
|
|
28
|
+
subject: "subject"
|
|
29
|
+
};
|
|
30
|
+
const CASL_ABILITY_IMPORT = {
|
|
31
|
+
bindings: [
|
|
32
|
+
CASL_ABILITY_BINDING.abilityTuple,
|
|
33
|
+
CASL_ABILITY_BINDING.pureAbility,
|
|
34
|
+
CASL_ABILITY_BINDING.forcedSubject,
|
|
35
|
+
CASL_ABILITY_BINDING.subjectType,
|
|
36
|
+
CASL_ABILITY_BINDING.subject
|
|
37
|
+
],
|
|
38
|
+
from: "@casl/ability"
|
|
39
|
+
};
|
|
40
|
+
//#endregion
|
|
16
41
|
//#region src/generators/generate/generateAcl.ts
|
|
17
42
|
function generateAcl({ resolver, data, tag }) {
|
|
18
43
|
const nativeContent = resolver.getNativeRenderedAcl?.(tag);
|
|
@@ -32,7 +57,7 @@ function generateAcl({ resolver, data, tag }) {
|
|
|
32
57
|
};
|
|
33
58
|
const workspaceContextImport = {
|
|
34
59
|
bindings: ["useWorkspaceContext"],
|
|
35
|
-
from:
|
|
60
|
+
from: CONFIG_PACKAGE_IMPORT_PATH
|
|
36
61
|
};
|
|
37
62
|
const lines = [];
|
|
38
63
|
lines.push(renderImport$4(caslAbilityTupleImport));
|
|
@@ -989,7 +1014,7 @@ function generateQueries(params) {
|
|
|
989
1014
|
const hasWorkspaceContext = resolver.options.workspaceContext && endpoints.some((endpoint) => getWorkspaceParamNames(resolver, endpoint).length > 0);
|
|
990
1015
|
const workspaceContextImport = {
|
|
991
1016
|
bindings: ["useWorkspaceContext"],
|
|
992
|
-
from:
|
|
1017
|
+
from: CONFIG_PACKAGE_IMPORT_PATH
|
|
993
1018
|
};
|
|
994
1019
|
const endpointParams = endpoints.flatMap((endpoint) => endpoint.parameters);
|
|
995
1020
|
const endpointParamsParseSchemas = endpointParams.filter((param) => !["Path", "Header"].includes(param.type)).map((param) => param.parameterSortingEnumSchemaName ?? param.zodSchema);
|