@povio/openapi-codegen-cli 2.0.8-rc.9 → 3.0.0-rc.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +32 -4
- package/dist/acl.d.mts +12 -1
- package/dist/acl.mjs +14 -3
- package/dist/{config-Cu_GYfai.d.mts → config-C1ME3Ay4.d.mts} +1 -1
- package/dist/error-handling-B4aYKmyL.d.mts +53 -0
- package/dist/error-handling-nneQaE1_.mjs +221 -0
- package/dist/generate.runner-C-MWypBE.mjs +90 -0
- package/dist/{generateCodeFromOpenAPIDoc-BOjk_Ey8.mjs → generateCodeFromOpenAPIDoc-BOWjt2I0.mjs} +2574 -2128
- package/dist/generator.d.mts +1 -1
- package/dist/generator.mjs +1 -1
- package/dist/index.d.mts +46 -61
- package/dist/index.mjs +76 -189
- package/dist/{options-DBz5YE3s.d.mts → options-BPAjzilp.d.mts} +12 -2
- package/dist/sh.mjs +22 -6
- package/dist/vite.d.mts +7 -4
- package/dist/vite.mjs +9 -6
- package/dist/zod.d.mts +20 -0
- package/dist/zod.mjs +33 -0
- package/package.json +12 -8
- package/dist/generate.runner-CSqX4Uw7.mjs +0 -98
- package/src/assets/useCrossTabQueryInvalidation.ts +0 -40
- package/src/assets/useMutationEffects.ts +0 -94
- package/src/generators/templates/acl-check.hbs +0 -29
- package/src/generators/templates/acl.hbs +0 -19
- package/src/generators/templates/app-acl.hbs +0 -17
- package/src/generators/templates/app-rest-client.hbs +0 -7
- package/src/generators/templates/configs.hbs +0 -80
- package/src/generators/templates/endpoints.hbs +0 -43
- package/src/generators/templates/models.hbs +0 -23
- package/src/generators/templates/partials/acl-check-call.hbs +0 -1
- package/src/generators/templates/partials/casl-ability-function.hbs +0 -12
- package/src/generators/templates/partials/casl-ability-query.hbs +0 -1
- package/src/generators/templates/partials/casl-ability-type.hbs +0 -1
- package/src/generators/templates/partials/columns-config.hbs +0 -11
- package/src/generators/templates/partials/endpoint-config.hbs +0 -31
- package/src/generators/templates/partials/endpoint-param-parse.hbs +0 -1
- package/src/generators/templates/partials/endpoint-params.hbs +0 -1
- package/src/generators/templates/partials/import.hbs +0 -1
- package/src/generators/templates/partials/inputs-config.hbs +0 -10
- package/src/generators/templates/partials/model-js-docs.hbs +0 -6
- package/src/generators/templates/partials/query-js-docs.hbs +0 -31
- package/src/generators/templates/partials/query-keys.hbs +0 -11
- package/src/generators/templates/partials/query-use-infinite-query.hbs +0 -21
- package/src/generators/templates/partials/query-use-mutation.hbs +0 -54
- package/src/generators/templates/partials/query-use-query.hbs +0 -16
- package/src/generators/templates/queries.hbs +0 -54
- package/src/generators/templates/query-modules.hbs +0 -5
- package/src/generators/templates/zod-extended.hbs +0 -49
- /package/dist/{auth.context-DKjzWiaA.mjs → auth.context-Bu5KW2sI.mjs} +0 -0
package/dist/generator.d.mts
CHANGED
package/dist/generator.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { _ as
|
|
1
|
+
import { _ as getNamespaceName, a as getDataFromOpenAPIDoc, b as isParamMediaTypeAllowed, 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 GenerateType, x as formatTag, y as isMediaTypeAllowed } from "./generateCodeFromOpenAPIDoc-BOWjt2I0.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 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-B4aYKmyL.mjs";
|
|
2
|
+
import "./options-BPAjzilp.mjs";
|
|
3
|
+
import { t as OpenAPICodegenConfig } from "./config-C1ME3Ay4.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
|
-
import * as react_jsx_runtime0 from "react/jsx-runtime";
|
|
9
9
|
import { InfiniteData, QueryKey, UseInfiniteQueryOptions, UseMutationOptions, UseQueryOptions } from "@tanstack/react-query";
|
|
10
|
+
import * as react_jsx_runtime0 from "react/jsx-runtime";
|
|
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;
|
|
@@ -99,7 +65,7 @@ declare class RestClient$1 implements RestClient {
|
|
|
99
65
|
//#endregion
|
|
100
66
|
//#region src/lib/rest/rest.utils.d.ts
|
|
101
67
|
declare namespace RestUtils {
|
|
102
|
-
const extractServerResponseCode: (e: unknown) => string | null;
|
|
68
|
+
const extractServerResponseCode: (e: unknown) => string | number | null;
|
|
103
69
|
const doesServerErrorMessageContain: (e: AxiosError, text: string) => boolean;
|
|
104
70
|
const extractServerErrorMessage: (e: unknown) => string | null;
|
|
105
71
|
const extractContentDispositionFilename: (headers: AxiosResponseHeaders) => string | undefined;
|
|
@@ -114,43 +80,61 @@ type AppQueryOptions<TFunction extends Function, TData = Awaited<ReturnType<TFun
|
|
|
114
80
|
type AppMutationOptions<TFunction extends Function, TVariables = void, TData = Awaited<ReturnType<TFunction>>, TErrorCodes = GeneralErrorCodes> = Omit<UseMutationOptions<TData, ApplicationException<TErrorCodes>, TVariables>, "mutationKey" | "mutationFn">;
|
|
115
81
|
type AppInfiniteQueryOptions<TFunction extends Function, TData = InfiniteData<Awaited<ReturnType<TFunction>>>, TErrorCodes = GeneralErrorCodes, TQueryKey extends QueryKey = QueryKey, TPageParam = number> = Omit<UseInfiniteQueryOptions<Awaited<ReturnType<TFunction>>, ApplicationException<TErrorCodes>, IsUnknown<TData, InfiniteData<Awaited<ReturnType<TFunction>>>>, TQueryKey, TPageParam>, "queryKey" | "queryFn" | "initialPageParam" | "getNextPageParam">;
|
|
116
82
|
//#endregion
|
|
117
|
-
//#region src/lib/config/router.context.d.ts
|
|
118
|
-
interface RouterProviderProps {
|
|
119
|
-
replace: (url: string) => void;
|
|
120
|
-
}
|
|
121
|
-
declare namespace OpenApiRouter {
|
|
122
|
-
const Provider: ({
|
|
123
|
-
children,
|
|
124
|
-
replace
|
|
125
|
-
}: PropsWithChildren<RouterProviderProps>) => react_jsx_runtime0.JSX.Element;
|
|
126
|
-
const useRouter: () => RouterProviderProps;
|
|
127
|
-
}
|
|
128
|
-
//#endregion
|
|
129
83
|
//#region src/lib/config/queryConfig.context.d.ts
|
|
130
84
|
type QueryModule = string | number | symbol;
|
|
131
85
|
type InvalidationMapFunc<TData = any, TVariables = any> = (data: TData, variables: TVariables) => QueryKey[];
|
|
132
|
-
type InvalidationMap<TData = any, TVariables = any> = Record<
|
|
86
|
+
type InvalidationMap<TQueryModule extends QueryModule = QueryModule, TData = any, TVariables = any> = Partial<Record<TQueryModule, InvalidationMapFunc<TData, TVariables>>>;
|
|
133
87
|
declare namespace OpenApiQueryConfig {
|
|
134
|
-
interface Type {
|
|
88
|
+
export interface Type<TQueryModule extends QueryModule = QueryModule> {
|
|
135
89
|
preferUpdate?: boolean;
|
|
136
90
|
invalidateCurrentModule?: boolean;
|
|
137
|
-
invalidationMap?: InvalidationMap
|
|
91
|
+
invalidationMap?: InvalidationMap<TQueryModule>;
|
|
138
92
|
crossTabInvalidation?: boolean;
|
|
139
93
|
onError?: (error: unknown) => void;
|
|
140
94
|
}
|
|
141
|
-
type ProviderProps = Type
|
|
142
|
-
export
|
|
95
|
+
type ProviderProps<TQueryModule extends QueryModule = QueryModule> = Type<TQueryModule>;
|
|
96
|
+
export function Provider<TQueryModule extends QueryModule = QueryModule>({
|
|
143
97
|
preferUpdate,
|
|
144
98
|
invalidateCurrentModule,
|
|
145
99
|
invalidationMap,
|
|
146
100
|
crossTabInvalidation,
|
|
147
101
|
onError,
|
|
148
102
|
children
|
|
149
|
-
}: PropsWithChildren<ProviderProps
|
|
150
|
-
export const useConfig: () => Type
|
|
103
|
+
}: PropsWithChildren<ProviderProps<TQueryModule>>): react_jsx_runtime0.JSX.Element;
|
|
104
|
+
export const useConfig: <TQueryModule extends QueryModule = QueryModule>() => Type<TQueryModule>;
|
|
151
105
|
export {};
|
|
152
106
|
}
|
|
153
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_runtime0.JSX.Element;
|
|
135
|
+
const useRouter: () => RouterProviderProps;
|
|
136
|
+
}
|
|
137
|
+
//#endregion
|
|
154
138
|
//#region src/lib/config/workspace.context.d.ts
|
|
155
139
|
type WorkspaceValues = Record<string, unknown>;
|
|
156
140
|
interface WorkspaceProviderProps {
|
|
@@ -161,9 +145,10 @@ declare namespace OpenApiWorkspaceContext {
|
|
|
161
145
|
values,
|
|
162
146
|
children
|
|
163
147
|
}: PropsWithChildren<WorkspaceProviderProps>) => react_jsx_runtime0.JSX.Element;
|
|
164
|
-
const useContext: () =>
|
|
148
|
+
const useContext: <TValues extends WorkspaceValues = WorkspaceValues>() => TValues;
|
|
165
149
|
const resolveParam: <T>(context: WorkspaceValues, name: string, value: T | null | undefined) => T;
|
|
166
150
|
}
|
|
151
|
+
declare const useWorkspaceContext: <TValues extends WorkspaceValues = WorkspaceValues>() => TValues;
|
|
167
152
|
//#endregion
|
|
168
153
|
//#region src/lib/config/i18n.d.ts
|
|
169
154
|
declare const ns = "openapi";
|
|
@@ -243,4 +228,4 @@ declare const AuthGuard: ({
|
|
|
243
228
|
children
|
|
244
229
|
}: PropsWithChildren<AuthGuardProps>) => react.ReactNode;
|
|
245
230
|
//#endregion
|
|
246
|
-
export { type AppInfiniteQueryOptions, type AppMutationOptions, type AppQueryOptions, ApplicationException, AuthContext, AuthGuard, type AuthGuardProps, type ErrorEntry, ErrorHandler, type ErrorHandlerOptions, type GeneralErrorCodes, type RestClient as IRestClient, type InvalidationMap, OpenAPICodegenConfig, OpenApiQueryConfig, OpenApiRouter, OpenApiWorkspaceContext, type RequestConfig, type RequestInfo, type Response, RestClient$1 as RestClient, RestInterceptor, RestUtils, SharedErrorHandler, ns, resources };
|
|
231
|
+
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, ns, resources, useMutationEffects, useWorkspaceContext };
|
package/dist/index.mjs
CHANGED
|
@@ -1,192 +1,11 @@
|
|
|
1
|
-
import { n as
|
|
2
|
-
import
|
|
1
|
+
import { a as RestUtils, i as SharedErrorHandler, n as DomainErrorRegistry, o as ns, r as ErrorHandler, s as resources, t as ApplicationException } from "./error-handling-nneQaE1_.mjs";
|
|
2
|
+
import { n as OpenApiRouter, t as AuthContext } from "./auth.context-Bu5KW2sI.mjs";
|
|
3
|
+
import axios from "axios";
|
|
3
4
|
import { z } from "zod";
|
|
4
|
-
import
|
|
5
|
-
import {
|
|
5
|
+
import { createContext, use, useCallback, useEffect, useMemo, useState } from "react";
|
|
6
|
+
import { useQueryClient } from "@tanstack/react-query";
|
|
6
7
|
import { jsx } from "react/jsx-runtime";
|
|
7
8
|
|
|
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
9
|
//#region src/lib/rest/rest-client.ts
|
|
191
10
|
var RestClient = class {
|
|
192
11
|
client;
|
|
@@ -294,7 +113,7 @@ var RestInterceptor = class {
|
|
|
294
113
|
let OpenApiQueryConfig;
|
|
295
114
|
(function(_OpenApiQueryConfig) {
|
|
296
115
|
const Context = createContext({});
|
|
297
|
-
|
|
116
|
+
function Provider({ preferUpdate, invalidateCurrentModule, invalidationMap, crossTabInvalidation, onError, children }) {
|
|
298
117
|
const value = useMemo(() => ({
|
|
299
118
|
preferUpdate,
|
|
300
119
|
invalidateCurrentModule,
|
|
@@ -312,12 +131,79 @@ let OpenApiQueryConfig;
|
|
|
312
131
|
value,
|
|
313
132
|
children
|
|
314
133
|
});
|
|
315
|
-
}
|
|
134
|
+
}
|
|
135
|
+
_OpenApiQueryConfig.Provider = Provider;
|
|
316
136
|
_OpenApiQueryConfig.useConfig = () => {
|
|
317
137
|
return use(Context) ?? {};
|
|
318
138
|
};
|
|
319
139
|
})(OpenApiQueryConfig || (OpenApiQueryConfig = {}));
|
|
320
140
|
|
|
141
|
+
//#endregion
|
|
142
|
+
//#region src/lib/react-query/cross-tab-invalidation.ts
|
|
143
|
+
const CROSS_TAB_INVALIDATE_KEY = "__rq_invalidate__";
|
|
144
|
+
const broadcastQueryInvalidation = (queryKeys) => {
|
|
145
|
+
localStorage.setItem(CROSS_TAB_INVALIDATE_KEY, JSON.stringify({
|
|
146
|
+
keys: queryKeys,
|
|
147
|
+
timestamp: Date.now()
|
|
148
|
+
}));
|
|
149
|
+
};
|
|
150
|
+
let isListenerSetUp = false;
|
|
151
|
+
const setupCrossTabListener = (queryClient) => {
|
|
152
|
+
if (isListenerSetUp) return;
|
|
153
|
+
isListenerSetUp = true;
|
|
154
|
+
window.addEventListener("storage", (e) => {
|
|
155
|
+
if (e.key !== CROSS_TAB_INVALIDATE_KEY || !e.newValue) return;
|
|
156
|
+
try {
|
|
157
|
+
const { keys } = JSON.parse(e.newValue);
|
|
158
|
+
for (const queryKey of keys) queryClient.invalidateQueries({ queryKey });
|
|
159
|
+
} catch {}
|
|
160
|
+
});
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
//#endregion
|
|
164
|
+
//#region src/lib/react-query/useMutationEffects.ts
|
|
165
|
+
function useMutationEffects({ currentModule }) {
|
|
166
|
+
const queryClient = useQueryClient();
|
|
167
|
+
const config = OpenApiQueryConfig.useConfig();
|
|
168
|
+
useEffect(() => {
|
|
169
|
+
if (!config.crossTabInvalidation) return;
|
|
170
|
+
setupCrossTabListener(queryClient);
|
|
171
|
+
}, [queryClient, config.crossTabInvalidation]);
|
|
172
|
+
return { runMutationEffects: useCallback(async (data, variables, options = {}, updateKeys) => {
|
|
173
|
+
const { invalidateCurrentModule, invalidationMap, invalidateModules, invalidateKeys, preferUpdate } = options;
|
|
174
|
+
const shouldUpdate = preferUpdate ?? config.preferUpdate ?? false;
|
|
175
|
+
const shouldInvalidateCurrentModule = invalidateCurrentModule ?? config.invalidateCurrentModule ?? true;
|
|
176
|
+
const isQueryKeyEqual = (keyA, keyB) => keyA.length === keyB.length && keyA.every((item, index) => item === keyB[index]);
|
|
177
|
+
const isQueryKeyPrefix = (queryKey, prefixKey) => prefixKey.length <= queryKey.length && prefixKey.every((item, index) => item === queryKey[index]);
|
|
178
|
+
const mappedInvalidationKeys = invalidationMap?.[currentModule]?.(data, variables) ?? config.invalidationMap?.[currentModule]?.(data, variables);
|
|
179
|
+
const shouldInvalidateQuery = (queryKey) => {
|
|
180
|
+
const isUpdateKey = updateKeys?.some((key) => isQueryKeyEqual(queryKey, key));
|
|
181
|
+
if (shouldUpdate && isUpdateKey) return false;
|
|
182
|
+
const isCurrentModule = shouldInvalidateCurrentModule && queryKey[0] === currentModule;
|
|
183
|
+
const isInvalidateModule = !!invalidateModules && invalidateModules.some((module) => queryKey[0] === module);
|
|
184
|
+
const isInvalidateKey = !!invalidateKeys && invalidateKeys.some((key) => isQueryKeyPrefix(queryKey, key));
|
|
185
|
+
const isMappedKey = !!mappedInvalidationKeys && mappedInvalidationKeys.some((key) => isQueryKeyPrefix(queryKey, key));
|
|
186
|
+
return isCurrentModule || isInvalidateModule || isInvalidateKey || isMappedKey;
|
|
187
|
+
};
|
|
188
|
+
const invalidatedQueryKeys = [];
|
|
189
|
+
const shouldBroadcast = options.crossTabInvalidation ?? config.crossTabInvalidation;
|
|
190
|
+
queryClient.invalidateQueries({ predicate: ({ queryKey }) => {
|
|
191
|
+
const shouldInvalidate = shouldInvalidateQuery(queryKey);
|
|
192
|
+
if (shouldInvalidate && shouldBroadcast) invalidatedQueryKeys.push([...queryKey]);
|
|
193
|
+
return shouldInvalidate;
|
|
194
|
+
} });
|
|
195
|
+
if (shouldBroadcast && invalidatedQueryKeys.length > 0) broadcastQueryInvalidation(invalidatedQueryKeys);
|
|
196
|
+
if (shouldUpdate && updateKeys) updateKeys.map((queryKey) => queryClient.setQueryData(queryKey, data));
|
|
197
|
+
}, [
|
|
198
|
+
queryClient,
|
|
199
|
+
currentModule,
|
|
200
|
+
config.preferUpdate,
|
|
201
|
+
config.invalidateCurrentModule,
|
|
202
|
+
config.invalidationMap,
|
|
203
|
+
config.crossTabInvalidation
|
|
204
|
+
]) };
|
|
205
|
+
}
|
|
206
|
+
|
|
321
207
|
//#endregion
|
|
322
208
|
//#region src/lib/config/workspace.context.tsx
|
|
323
209
|
let OpenApiWorkspaceContext;
|
|
@@ -340,6 +226,7 @@ let OpenApiWorkspaceContext;
|
|
|
340
226
|
return workspaceValue;
|
|
341
227
|
};
|
|
342
228
|
})(OpenApiWorkspaceContext || (OpenApiWorkspaceContext = {}));
|
|
229
|
+
const useWorkspaceContext = () => OpenApiWorkspaceContext.useContext();
|
|
343
230
|
|
|
344
231
|
//#endregion
|
|
345
232
|
//#region src/lib/auth/AuthGuard.tsx
|
|
@@ -363,4 +250,4 @@ const AuthGuard = ({ type, redirectTo, children }) => {
|
|
|
363
250
|
};
|
|
364
251
|
|
|
365
252
|
//#endregion
|
|
366
|
-
export { ApplicationException, AuthContext, AuthGuard, ErrorHandler, OpenApiQueryConfig, OpenApiRouter, OpenApiWorkspaceContext, RestClient, RestInterceptor, RestUtils, SharedErrorHandler, ns, resources };
|
|
253
|
+
export { ApplicationException, AuthContext, AuthGuard, DomainErrorRegistry, ErrorHandler, OpenApiQueryConfig, OpenApiRouter, OpenApiWorkspaceContext, RestClient, RestInterceptor, RestUtils, SharedErrorHandler, ns, resources, useMutationEffects, useWorkspaceContext };
|
|
@@ -12,6 +12,7 @@ interface GenerateFileData {
|
|
|
12
12
|
fileName: string;
|
|
13
13
|
content: string;
|
|
14
14
|
}
|
|
15
|
+
type GenerateFileFormatter = (file: GenerateFileData) => string | Promise<string>;
|
|
15
16
|
//#endregion
|
|
16
17
|
//#region src/generators/types/options.d.ts
|
|
17
18
|
interface ZodGenerateOptions {
|
|
@@ -38,7 +39,14 @@ interface QueriesGenerateOptions {
|
|
|
38
39
|
queryTypesImportPath: string;
|
|
39
40
|
axiosRequestConfig?: boolean;
|
|
40
41
|
mutationEffects?: boolean;
|
|
41
|
-
|
|
42
|
+
mutationDefaultOnError?: boolean;
|
|
43
|
+
workspaceContext?: string[];
|
|
44
|
+
prefetchQueries?: boolean;
|
|
45
|
+
mutationScope?: boolean | {
|
|
46
|
+
include: string[];
|
|
47
|
+
} | {
|
|
48
|
+
exclude: string[];
|
|
49
|
+
};
|
|
42
50
|
}
|
|
43
51
|
interface InfiniteQueriesGenerateOptions {
|
|
44
52
|
infiniteQueries?: boolean;
|
|
@@ -71,9 +79,11 @@ interface GenerateConfig {
|
|
|
71
79
|
interface BaseGenerateOptions {
|
|
72
80
|
input: string;
|
|
73
81
|
output: string;
|
|
82
|
+
clearOutput?: boolean;
|
|
74
83
|
incremental?: boolean;
|
|
75
84
|
splitByTags: boolean;
|
|
76
85
|
defaultTag: string;
|
|
86
|
+
includeTags: string[];
|
|
77
87
|
excludeTags: string[];
|
|
78
88
|
excludePathRegex: string;
|
|
79
89
|
excludeRedundantZodSchemas: boolean;
|
|
@@ -87,4 +97,4 @@ interface BaseGenerateOptions {
|
|
|
87
97
|
}
|
|
88
98
|
interface GenerateOptions extends BaseGenerateOptions, ZodGenerateOptions, EndpointsGenerateOptions, QueriesGenerateOptions, InfiniteQueriesGenerateOptions, ACLGenerateOptions, BuilderConfigsGenerateOptions {}
|
|
89
99
|
//#endregion
|
|
90
|
-
export { GenerateFileData as n, GenerateOptions as t };
|
|
100
|
+
export { GenerateFileData as n, GenerateFileFormatter as r, GenerateOptions as t };
|
package/dist/sh.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import {
|
|
3
|
-
import { n as resolveConfig, t as runGenerate } from "./generate.runner-
|
|
2
|
+
import { C as VALIDATION_ERROR_TYPE_TITLE, S as Profiler, a as getDataFromOpenAPIDoc, m as groupByType, n as getOutputFileName, u as getTagFileName, v as GenerateType } from "./generateCodeFromOpenAPIDoc-BOWjt2I0.mjs";
|
|
3
|
+
import { n as resolveConfig, t as runGenerate } from "./generate.runner-C-MWypBE.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 "
|
|
42
|
+
return "3.0.0-rc.10";
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
//#endregion
|
|
@@ -187,7 +187,7 @@ function pathToFileURL(filePath) {
|
|
|
187
187
|
|
|
188
188
|
//#endregion
|
|
189
189
|
//#region src/commands/check.ts
|
|
190
|
-
async function check({ verbose, config: configParam, excludeTags: _excludeTagsParam, ...params }) {
|
|
190
|
+
async function check({ verbose, config: configParam, includeTags: _includeTagsParam, excludeTags: _excludeTagsParam, ...params }) {
|
|
191
191
|
const start = Date.now();
|
|
192
192
|
if (verbose) logInfo("Resolving config...");
|
|
193
193
|
const config = resolveConfig({
|
|
@@ -224,6 +224,7 @@ var CheckOptions = class {
|
|
|
224
224
|
input;
|
|
225
225
|
splitByTags;
|
|
226
226
|
defaultTag;
|
|
227
|
+
includeTags;
|
|
227
228
|
excludeTags;
|
|
228
229
|
excludePathRegex;
|
|
229
230
|
excludeRedundantZodSchemas;
|
|
@@ -236,6 +237,7 @@ __decorate([YargOption({
|
|
|
236
237
|
type: "boolean"
|
|
237
238
|
}), __decorateMetadata("design:type", Boolean)], CheckOptions.prototype, "splitByTags", void 0);
|
|
238
239
|
__decorate([YargOption({ envAlias: "defaultTag" }), __decorateMetadata("design:type", String)], CheckOptions.prototype, "defaultTag", void 0);
|
|
240
|
+
__decorate([YargOption({ envAlias: "includeTags" }), __decorateMetadata("design:type", String)], CheckOptions.prototype, "includeTags", void 0);
|
|
239
241
|
__decorate([YargOption({ envAlias: "excludeTags" }), __decorateMetadata("design:type", String)], CheckOptions.prototype, "excludeTags", void 0);
|
|
240
242
|
__decorate([YargOption({ envAlias: "excludePathRegex" }), __decorateMetadata("design:type", String)], CheckOptions.prototype, "excludePathRegex", void 0);
|
|
241
243
|
__decorate([YargOption({
|
|
@@ -298,11 +300,13 @@ var GenerateOptions = class {
|
|
|
298
300
|
config;
|
|
299
301
|
input;
|
|
300
302
|
output;
|
|
303
|
+
clearOutput;
|
|
301
304
|
incremental;
|
|
302
305
|
tsNamespaces;
|
|
303
306
|
tsPath;
|
|
304
307
|
splitByTags;
|
|
305
308
|
defaultTag;
|
|
309
|
+
includeTags;
|
|
306
310
|
excludeTags;
|
|
307
311
|
excludePathRegex;
|
|
308
312
|
excludeRedundantZodSchemas;
|
|
@@ -316,7 +320,9 @@ var GenerateOptions = class {
|
|
|
316
320
|
replaceOptionalWithNullish;
|
|
317
321
|
infiniteQueries;
|
|
318
322
|
mutationEffects;
|
|
323
|
+
mutationDefaultOnError;
|
|
319
324
|
workspaceContext;
|
|
325
|
+
mutationScope;
|
|
320
326
|
parseRequestParams;
|
|
321
327
|
inlineEndpoints;
|
|
322
328
|
inlineEndpointsExcludeModules;
|
|
@@ -329,6 +335,10 @@ var GenerateOptions = class {
|
|
|
329
335
|
__decorate([YargOption({ envAlias: "config" }), __decorateMetadata("design:type", String)], GenerateOptions.prototype, "config", void 0);
|
|
330
336
|
__decorate([YargOption({ envAlias: "input" }), __decorateMetadata("design:type", String)], GenerateOptions.prototype, "input", void 0);
|
|
331
337
|
__decorate([YargOption({ envAlias: "output" }), __decorateMetadata("design:type", String)], GenerateOptions.prototype, "output", void 0);
|
|
338
|
+
__decorate([YargOption({
|
|
339
|
+
envAlias: "clearOutput",
|
|
340
|
+
type: "boolean"
|
|
341
|
+
}), __decorateMetadata("design:type", Boolean)], GenerateOptions.prototype, "clearOutput", void 0);
|
|
332
342
|
__decorate([YargOption({
|
|
333
343
|
envAlias: "incremental",
|
|
334
344
|
type: "boolean"
|
|
@@ -343,6 +353,7 @@ __decorate([YargOption({
|
|
|
343
353
|
type: "boolean"
|
|
344
354
|
}), __decorateMetadata("design:type", Boolean)], GenerateOptions.prototype, "splitByTags", void 0);
|
|
345
355
|
__decorate([YargOption({ envAlias: "defaultTag" }), __decorateMetadata("design:type", String)], GenerateOptions.prototype, "defaultTag", void 0);
|
|
356
|
+
__decorate([YargOption({ envAlias: "includeTags" }), __decorateMetadata("design:type", String)], GenerateOptions.prototype, "includeTags", void 0);
|
|
346
357
|
__decorate([YargOption({ envAlias: "excludeTags" }), __decorateMetadata("design:type", String)], GenerateOptions.prototype, "excludeTags", void 0);
|
|
347
358
|
__decorate([YargOption({ envAlias: "excludePathRegex" }), __decorateMetadata("design:type", String)], GenerateOptions.prototype, "excludePathRegex", void 0);
|
|
348
359
|
__decorate([YargOption({
|
|
@@ -381,9 +392,14 @@ __decorate([YargOption({
|
|
|
381
392
|
type: "boolean"
|
|
382
393
|
}), __decorateMetadata("design:type", Boolean)], GenerateOptions.prototype, "mutationEffects", void 0);
|
|
383
394
|
__decorate([YargOption({
|
|
384
|
-
envAlias: "
|
|
395
|
+
envAlias: "mutationDefaultOnError",
|
|
396
|
+
type: "boolean"
|
|
397
|
+
}), __decorateMetadata("design:type", Boolean)], GenerateOptions.prototype, "mutationDefaultOnError", void 0);
|
|
398
|
+
__decorate([YargOption({ envAlias: "workspaceContext" }), __decorateMetadata("design:type", String)], GenerateOptions.prototype, "workspaceContext", void 0);
|
|
399
|
+
__decorate([YargOption({
|
|
400
|
+
envAlias: "mutationScope",
|
|
385
401
|
type: "boolean"
|
|
386
|
-
}), __decorateMetadata("design:type", Boolean)], GenerateOptions.prototype, "
|
|
402
|
+
}), __decorateMetadata("design:type", Boolean)], GenerateOptions.prototype, "mutationScope", void 0);
|
|
387
403
|
__decorate([YargOption({
|
|
388
404
|
envAlias: "parseRequestParams",
|
|
389
405
|
type: "boolean"
|
package/dist/vite.d.mts
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
|
-
import "./options-
|
|
2
|
-
import { t as OpenAPICodegenConfig } from "./config-
|
|
1
|
+
import { r as GenerateFileFormatter } from "./options-BPAjzilp.mjs";
|
|
2
|
+
import { t as OpenAPICodegenConfig } from "./config-C1ME3Ay4.mjs";
|
|
3
3
|
import { Plugin } from "vite";
|
|
4
4
|
|
|
5
5
|
//#region src/vite/openapi-codegen.plugin.d.ts
|
|
6
|
-
|
|
6
|
+
type OpenApiCodegenViteConfig = OpenAPICodegenConfig & {
|
|
7
|
+
formatGeneratedFile?: GenerateFileFormatter;
|
|
8
|
+
};
|
|
9
|
+
declare function openApiCodegen(config: OpenApiCodegenViteConfig): Plugin;
|
|
7
10
|
//#endregion
|
|
8
|
-
export { type OpenAPICodegenConfig, openApiCodegen };
|
|
11
|
+
export { type OpenAPICodegenConfig, type OpenApiCodegenViteConfig, openApiCodegen };
|