@povio/openapi-codegen-cli 3.1.1-rc.1 → 3.2.0-rc.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +63 -15
- package/dist/AuthGuard-GbtTDXs0.d.mts +32 -0
- package/dist/AuthGuard-qpAtHaBz.mjs +24 -0
- package/dist/acl.d.mts +6 -20
- package/dist/acl.mjs +8 -13
- package/dist/{auth.context-Bu5KW2sI.mjs → auth.context-COWO6ssl.mjs} +1 -21
- 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-BU7wVf7U.d.mts → config-DgrOddSC.d.mts} +1 -2
- package/dist/config.d.mts +4 -0
- package/dist/config.mjs +5 -0
- package/dist/{error-handling-DSI86D3u.mjs → error-handling-BeydPL7s.mjs} +21 -51
- package/dist/{error-handling-D-mHJ60d.d.mts → error-handling-LPEPQV1V.d.mts} +3 -42
- package/dist/errors.d.mts +3 -0
- package/dist/errors.mjs +2 -0
- package/dist/generate.runner-CD7mlcJ4.mjs +184 -0
- package/dist/generate.utils-CT-LA-gX.cjs +2267 -0
- package/dist/generateCodeFromOpenAPIDoc-D9W5BtAt.mjs +2097 -0
- package/dist/{generateCodeFromOpenAPIDoc-DseBECa-.mjs → generateCodeFromOpenAPIDoc-DhI7CHeh.cjs} +1349 -2344
- package/dist/generator.d.mts +3 -10
- package/dist/generator.mjs +9 -9
- package/dist/getDataFromOpenAPIDoc-D8w0QElH.mjs +2011 -0
- package/dist/i18n-B_brQh4X.d.mts +38 -0
- package/dist/i18n-D-FesqFb.mjs +36 -0
- package/dist/index.d.mts +12 -200
- package/dist/index.mjs +12 -264
- package/dist/metro.cjs +114 -4959
- package/dist/metro.d.mts +3 -4
- package/dist/metro.mjs +4 -9
- package/dist/native-bindings-BTQGSGhU.mjs +1480 -0
- package/dist/native-rest-interceptor-CAWR8H5Y.mjs +208 -0
- package/dist/native-rest-interceptor-Cz6saoq5.d.mts +46 -0
- package/dist/native.d.mts +3 -0
- package/dist/native.mjs +3 -0
- 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-Co_bG00_.mjs → openapi-codegen.runner-C4TIXQNx.mjs} +4 -5
- package/dist/{openapi-source.runner-wLs5vqw6.mjs → openapi-source.runner-BZ6ZLgRO.mjs} +19 -10
- package/dist/{openapi-source.runner-BSIrB6ny.d.mts → openapi-source.runner-ykstqlPC.d.mts} +2 -8
- package/dist/{options-CE4Koxof.d.mts → options-KPf-Fti5.d.mts} +6 -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-transport.types-DM5-qyOJ.d.mts +66 -0
- package/dist/rest-transport.types-DxitRtsB.mjs +11 -0
- package/dist/rest.d.mts +2 -0
- package/dist/rest.mjs +2 -0
- package/dist/rest.utils-rezWAIYL.d.mts +10 -0
- package/dist/router.context-EPlMBk3G.mjs +21 -0
- package/dist/sh.d.mts +1 -1
- package/dist/sh.mjs +41 -71
- package/dist/tiny.d.mts +1 -3
- package/dist/tiny.mjs +2 -3
- package/dist/useMutationEffects-DIdL8tlx.d.mts +29 -0
- package/dist/useMutationEffects-PB1fvKWM.mjs +68 -0
- package/dist/vite.d.mts +3 -4
- package/dist/vite.mjs +6 -10
- package/dist/workspace.context-XWvQ_7Hg.mjs +26 -0
- package/dist/workspace.context-isVY9ves.d.mts +23 -0
- package/dist/zod.d.mts +2 -7
- package/dist/zod.mjs +2 -4
- package/package.json +73 -26
- package/dist/generate.runner-C1HrS_9G.mjs +0 -90
package/README.md
CHANGED
|
@@ -13,13 +13,13 @@ The tool partially leverages code from [openapi-zod-client](https://github.com/a
|
|
|
13
13
|
## Setup
|
|
14
14
|
|
|
15
15
|
```bash
|
|
16
|
-
|
|
16
|
+
bun add @povio/openapi-codegen-cli
|
|
17
17
|
```
|
|
18
18
|
|
|
19
19
|
## Example
|
|
20
20
|
|
|
21
21
|
```bash
|
|
22
|
-
|
|
22
|
+
bunx openapi-codegen generate --input http://localhost:3001/docs-json
|
|
23
23
|
```
|
|
24
24
|
|
|
25
25
|
## Configuration Files
|
|
@@ -46,7 +46,7 @@ export default config;
|
|
|
46
46
|
Then run without arguments:
|
|
47
47
|
|
|
48
48
|
```bash
|
|
49
|
-
|
|
49
|
+
bunx openapi-codegen generate
|
|
50
50
|
```
|
|
51
51
|
|
|
52
52
|
### Configuration File Discovery
|
|
@@ -58,7 +58,7 @@ The CLI automatically searches for the TypeScript configuration file:
|
|
|
58
58
|
You can also specify a custom configuration file:
|
|
59
59
|
|
|
60
60
|
```bash
|
|
61
|
-
|
|
61
|
+
bunx openapi-codegen generate --config my-config.ts
|
|
62
62
|
```
|
|
63
63
|
|
|
64
64
|
## Options
|
|
@@ -89,7 +89,8 @@ yarn openapi-codegen generate --config my-config.ts
|
|
|
89
89
|
--modelsInCommon Keep all schema declarations in defaultTag models and emit per-module proxy exports (default: false)
|
|
90
90
|
--replaceOptionalWithNullish Replace `.optional()` chains with `.nullish()` in generated Zod schemas (default: false)
|
|
91
91
|
|
|
92
|
-
--
|
|
92
|
+
--restClient REST transport to generate: 'axios' or 'native' (default: 'axios')
|
|
93
|
+
--axiosRequestConfig Include transport request config parameters in query hooks (default: false)
|
|
93
94
|
--infiniteQueries Generate infinite queries for paginated API endpoints (default: false)
|
|
94
95
|
--mutationEffects Add mutation effects options to mutation hooks (default: true)
|
|
95
96
|
--mutationScope Serialize mutations for the same path-param resource via TanStack scope.id (default: false).
|
|
@@ -132,29 +133,76 @@ yarn openapi-codegen generate --config my-config.ts
|
|
|
132
133
|
#### Test locally
|
|
133
134
|
|
|
134
135
|
```bash
|
|
135
|
-
#
|
|
136
|
-
|
|
137
|
-
yarn
|
|
136
|
+
# install dependencies
|
|
137
|
+
bun install
|
|
138
138
|
|
|
139
139
|
# run tests
|
|
140
|
-
|
|
140
|
+
bun run test
|
|
141
141
|
|
|
142
|
-
# run sources with
|
|
143
|
-
|
|
144
|
-
|
|
142
|
+
# run TypeScript sources directly with Bun
|
|
143
|
+
bun run start --help
|
|
144
|
+
bun run start generate --input ./test/petstore.yaml --verbose
|
|
145
145
|
|
|
146
146
|
# build new version
|
|
147
|
-
|
|
147
|
+
bun run build
|
|
148
148
|
|
|
149
149
|
# test build
|
|
150
|
-
|
|
151
|
-
|
|
150
|
+
bun run start --help
|
|
151
|
+
bun run start:dist generate --input ./test/petstore.yaml --verbose
|
|
152
152
|
```
|
|
153
153
|
|
|
154
|
+
### Native Bun code generation
|
|
155
|
+
|
|
156
|
+
The Bun and Node.js CLIs and the Vite plugin automatically use the bundled Rust code-generation core when a compatible native binary is available. Generated files remain byte-for-byte compatible with the TypeScript implementation, which is retained as the fallback when the addon cannot be loaded.
|
|
157
|
+
|
|
158
|
+
Set `OPENAPI_CODEGEN_NATIVE=0` to force the TypeScript path, or `OPENAPI_CODEGEN_NATIVE=1` to require the native path and fail when its binary is unavailable.
|
|
159
|
+
|
|
160
|
+
Release packages include native binaries for Linux x64, macOS arm64, and Windows x64. Build a binary for the current platform with `bun run build:native`.
|
|
161
|
+
|
|
154
162
|
## Common Issues
|
|
155
163
|
|
|
156
164
|
### App REST Client Interceptors
|
|
157
165
|
|
|
166
|
+
Select the fetch-based client without changing endpoint and query APIs:
|
|
167
|
+
|
|
168
|
+
```ts
|
|
169
|
+
import type { OpenAPICodegenConfig } from "@povio/openapi-codegen-cli";
|
|
170
|
+
|
|
171
|
+
export default {
|
|
172
|
+
restClient: "native",
|
|
173
|
+
} satisfies OpenAPICodegenConfig;
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
Native mode imports common request/response contracts from `@povio/openapi-codegen-cli/rest` and the concrete
|
|
177
|
+
`NativeRestClient` from `@povio/openapi-codegen-cli/native`. It uses `fetch` for normal requests and uploads, switching
|
|
178
|
+
to `XMLHttpRequest` in browsers only when an upload progress callback is provided.
|
|
179
|
+
|
|
180
|
+
Native interceptors use the common transport interface:
|
|
181
|
+
|
|
182
|
+
```ts
|
|
183
|
+
import { NativeRestClient } from "@povio/openapi-codegen-cli/native";
|
|
184
|
+
import type { RestTransportInterceptor } from "@povio/openapi-codegen-cli/rest";
|
|
185
|
+
|
|
186
|
+
const authorizationInterceptor: RestTransportInterceptor = {
|
|
187
|
+
onRequest(request) {
|
|
188
|
+
request.headers.set("Authorization", `Bearer ${localStorage.getItem("accessToken")}`);
|
|
189
|
+
return request;
|
|
190
|
+
},
|
|
191
|
+
};
|
|
192
|
+
|
|
193
|
+
export const AppRestClient = new NativeRestClient({
|
|
194
|
+
config: { baseURL: "https://api.example.com" },
|
|
195
|
+
interceptors: [authorizationInterceptor],
|
|
196
|
+
});
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
Axios remains the default for backward compatibility. The existing Axios interceptor API remains available in Axios
|
|
200
|
+
mode.
|
|
201
|
+
|
|
202
|
+
Native mode does not run the library `ErrorHandler` or create `ApplicationException` values. It throws `HttpError` for
|
|
203
|
+
non-success HTTP responses and preserves Zod, network, cancellation, and timeout errors so applications can handle them
|
|
204
|
+
directly in query callbacks, error boundaries, or their own normalization layer.
|
|
205
|
+
|
|
158
206
|
In order to add interceptors to the used REST client, you must create your own instance of a RestClient and pass your implemented interceptors into the constructor. Make sure to set `restClientImportPath` in your openapi generation configuration too.
|
|
159
207
|
|
|
160
208
|
```ts
|
|
@@ -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,26 +1,21 @@
|
|
|
1
|
-
import { a as ErrorHandler } from "./error-handling-
|
|
2
|
-
import * as react from "react";
|
|
1
|
+
import { a as ErrorHandler } from "./error-handling-LPEPQV1V.mjs";
|
|
3
2
|
import { PropsWithChildren } from "react";
|
|
4
|
-
import * as react_jsx_runtime0 from "react/jsx-runtime";
|
|
5
3
|
import { AbilityTuple, PureAbility, RawRuleOf, Subject } from "@casl/ability";
|
|
6
4
|
import { PackRule } from "@casl/ability/extra";
|
|
7
5
|
import { BoundCanProps } from "@casl/react";
|
|
8
|
-
|
|
9
6
|
//#region src/lib/acl/appAbility.types.d.ts
|
|
10
7
|
type AppAbilities = AbilityTuple<string, Subject>;
|
|
11
8
|
type AppAbility = PureAbility<AppAbilities>;
|
|
12
9
|
//#endregion
|
|
13
10
|
//#region src/lib/acl/ability.context.d.ts
|
|
14
11
|
declare namespace AbilityContext {
|
|
15
|
-
export const Consumer: react.Consumer<AppAbility>;
|
|
12
|
+
export const Consumer: import("react").Consumer<AppAbility>;
|
|
16
13
|
interface ProviderProps {
|
|
17
14
|
user?: {
|
|
18
15
|
aclRules?: PackRule<RawRuleOf<AppAbility>>[];
|
|
19
16
|
} | null;
|
|
20
17
|
}
|
|
21
|
-
export const Provider: ({
|
|
22
|
-
children
|
|
23
|
-
}: PropsWithChildren<ProviderProps>) => react_jsx_runtime0.JSX.Element;
|
|
18
|
+
export const Provider: ({ children }: PropsWithChildren<ProviderProps>) => import("react").JSX.Element;
|
|
24
19
|
export const useAbility: <TAppAbilities extends AppAbilities = AppAbilities>() => PureAbility<TAppAbilities>;
|
|
25
20
|
export {};
|
|
26
21
|
}
|
|
@@ -30,29 +25,20 @@ interface AclGuardProps<TAppAbilities extends AppAbilities = AppAbilities> {
|
|
|
30
25
|
canUse: TAppAbilities;
|
|
31
26
|
redirectTo?: string;
|
|
32
27
|
}
|
|
33
|
-
declare const createAclGuard: <TAppAbilities extends AppAbilities = AppAbilities>() => ({
|
|
34
|
-
canUse,
|
|
35
|
-
redirectTo,
|
|
36
|
-
children
|
|
37
|
-
}: PropsWithChildren<AclGuardProps<TAppAbilities>>) => react.ReactNode;
|
|
28
|
+
declare const createAclGuard: <TAppAbilities extends AppAbilities = AppAbilities>() => ({ canUse, redirectTo, children }: PropsWithChildren<AclGuardProps<TAppAbilities>>) => import("react").ReactNode;
|
|
38
29
|
//#endregion
|
|
39
30
|
//#region src/lib/acl/Can.d.ts
|
|
40
31
|
type CanAbility = PureAbility<AbilityTuple<AppAbilities[0], AppAbilities[1]>>;
|
|
41
32
|
type CanProps<TAppAbilities extends AppAbilities = AppAbilities> = {
|
|
42
33
|
use: TAppAbilities;
|
|
43
34
|
} & Omit<BoundCanProps<CanAbility>, "do" | "I" | "on" | "a" | "an" | "this">;
|
|
44
|
-
declare const Can: <TAppAbilities extends AppAbilities = AppAbilities>({
|
|
45
|
-
use,
|
|
46
|
-
...props
|
|
47
|
-
}: CanProps<TAppAbilities>) => react_jsx_runtime0.JSX.Element;
|
|
35
|
+
declare const Can: <TAppAbilities extends AppAbilities = AppAbilities>({ use, ...props }: CanProps<TAppAbilities>) => import("react").JSX.Element;
|
|
48
36
|
//#endregion
|
|
49
37
|
//#region src/lib/acl/useAclCheck.d.ts
|
|
50
38
|
interface UseAclCheckProps {
|
|
51
39
|
errorHandler?: ErrorHandler<never>;
|
|
52
40
|
}
|
|
53
|
-
declare function useAclCheck<TAppAbilities extends AppAbilities = AppAbilities>({
|
|
54
|
-
errorHandler
|
|
55
|
-
}?: UseAclCheckProps): {
|
|
41
|
+
declare function useAclCheck<TAppAbilities extends AppAbilities = AppAbilities>({ errorHandler }?: UseAclCheckProps): {
|
|
56
42
|
checkAcl: (appAbility: TAppAbilities) => void;
|
|
57
43
|
};
|
|
58
44
|
//#endregion
|
package/dist/acl.mjs
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { i as SharedErrorHandler } from "./error-handling-
|
|
2
|
-
import {
|
|
3
|
-
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";
|
|
4
|
+
import { createContext, useCallback, useMemo } from "react";
|
|
4
5
|
import { jsx } from "react/jsx-runtime";
|
|
5
6
|
import { AbilityBuilder, createMongoAbility } from "@casl/ability";
|
|
6
7
|
import { unpackRules } from "@casl/ability/extra";
|
|
7
8
|
import { createContextualCan, useAbility } from "@casl/react";
|
|
8
|
-
|
|
9
9
|
//#region src/lib/acl/ability.context.tsx
|
|
10
10
|
let AbilityContext;
|
|
11
11
|
(function(_AbilityContext) {
|
|
@@ -15,16 +15,15 @@ let AbilityContext;
|
|
|
15
15
|
const { Consumer } = Context;
|
|
16
16
|
_AbilityContext.Consumer = Consumer;
|
|
17
17
|
_AbilityContext.Provider = ({ children }) => {
|
|
18
|
-
const [ability, setAbility] = useState(initialAppAbility);
|
|
19
18
|
const { user } = AuthContext.useAuth();
|
|
20
|
-
|
|
21
|
-
if (!user || !("aclRules" in user)) return;
|
|
19
|
+
const ability = useMemo(() => {
|
|
20
|
+
if (!user || !("aclRules" in user)) return initialAppAbility;
|
|
22
21
|
const { can, build } = createAppAbilityBuilder();
|
|
23
22
|
const packedRules = user.aclRules;
|
|
24
23
|
unpackRules(packedRules).forEach(({ action, subject, conditions }) => {
|
|
25
24
|
can(action, subject, conditions);
|
|
26
25
|
});
|
|
27
|
-
|
|
26
|
+
return build();
|
|
28
27
|
}, [user]);
|
|
29
28
|
return /* @__PURE__ */ jsx(Context.Provider, {
|
|
30
29
|
value: ability,
|
|
@@ -35,7 +34,6 @@ let AbilityContext;
|
|
|
35
34
|
return useAbility(Context);
|
|
36
35
|
};
|
|
37
36
|
})(AbilityContext || (AbilityContext = {}));
|
|
38
|
-
|
|
39
37
|
//#endregion
|
|
40
38
|
//#region src/lib/acl/AclGuard.tsx
|
|
41
39
|
const createAclGuard = () => ({ canUse, redirectTo = "/", children }) => {
|
|
@@ -47,7 +45,6 @@ const createAclGuard = () => ({ canUse, redirectTo = "/", children }) => {
|
|
|
47
45
|
}
|
|
48
46
|
return children;
|
|
49
47
|
};
|
|
50
|
-
|
|
51
48
|
//#endregion
|
|
52
49
|
//#region src/lib/acl/Can.tsx
|
|
53
50
|
const ContextualCan = createContextualCan(AbilityContext.Consumer);
|
|
@@ -59,7 +56,6 @@ const Can = ({ use, ...props }) => {
|
|
|
59
56
|
on: subject
|
|
60
57
|
});
|
|
61
58
|
};
|
|
62
|
-
|
|
63
59
|
//#endregion
|
|
64
60
|
//#region src/lib/acl/useAclCheck.ts
|
|
65
61
|
function useAclCheck({ errorHandler } = {}) {
|
|
@@ -69,6 +65,5 @@ function useAclCheck({ errorHandler } = {}) {
|
|
|
69
65
|
if (!ability.can(action, subject)) (errorHandler ?? SharedErrorHandler).rethrowError(/* @__PURE__ */ new Error("ACL check failed"));
|
|
70
66
|
}, [ability, errorHandler]) };
|
|
71
67
|
}
|
|
72
|
-
|
|
73
68
|
//#endregion
|
|
74
|
-
export { AbilityContext, Can, createAclGuard, useAclCheck };
|
|
69
|
+
export { AbilityContext, Can, createAclGuard, useAclCheck };
|
|
@@ -1,24 +1,5 @@
|
|
|
1
1
|
import { createContext, use, useMemo } from "react";
|
|
2
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
3
|
//#region src/lib/auth/auth.context.tsx
|
|
23
4
|
let AuthContext;
|
|
24
5
|
(function(_AuthContext) {
|
|
@@ -54,6 +35,5 @@ let AuthContext;
|
|
|
54
35
|
return use(Context);
|
|
55
36
|
};
|
|
56
37
|
})(AuthContext || (AuthContext = {}));
|
|
57
|
-
|
|
58
38
|
//#endregion
|
|
59
|
-
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,52 +1,26 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { n as ns, r as resolveT } from "./i18n-D-FesqFb.mjs";
|
|
2
|
+
import { t as HttpError } from "./rest-transport.types-DxitRtsB.mjs";
|
|
2
3
|
import { z } from "zod";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
"dataValidation": "An error occurred while validating the data",
|
|
7
|
-
"internalError": "An internal error occurred. This is most likely a bug on our end. Please try again later.",
|
|
8
|
-
"networkError": "A network error occurred. Are you connected to the internet?",
|
|
9
|
-
"canceledError": "The request was canceled.",
|
|
10
|
-
"unknownError": "An unknown error occurred. Please try again later.",
|
|
11
|
-
"unknownErrorWithCode": "An unknown error occurred. Error code: \"{{code}}\""
|
|
12
|
-
} } };
|
|
13
|
-
|
|
14
|
-
//#endregion
|
|
15
|
-
//#region src/lib/assets/locales/sl/translation.json
|
|
16
|
-
var translation_default = { openapi: { "sharedErrors": {
|
|
17
|
-
"dataValidation": "Pri preverjanju podatkov je prišlo do napake",
|
|
18
|
-
"internalError": "Prišlo je do notranje napake.",
|
|
19
|
-
"networkError": "Prišlo je do napake v omrežju.",
|
|
20
|
-
"canceledError": "Zahteva je bila preklicana.",
|
|
21
|
-
"unknownError": "Prišlo je do neznane napake.",
|
|
22
|
-
"unknownErrorWithCode": "Prišlo je do neznane napake. Koda napake: \"{{code}}\""
|
|
23
|
-
} } };
|
|
24
|
-
|
|
25
|
-
//#endregion
|
|
26
|
-
//#region src/lib/config/i18n.ts
|
|
27
|
-
const ns = "openapi";
|
|
28
|
-
const resources = {
|
|
29
|
-
en: { [ns]: translation_default$1 },
|
|
30
|
-
sl: { [ns]: translation_default }
|
|
31
|
-
};
|
|
32
|
-
let getT = null;
|
|
33
|
-
function configureTranslations(getter) {
|
|
34
|
-
getT = () => getter();
|
|
4
|
+
//#region src/lib/rest/http-error.utils.ts
|
|
5
|
+
function isAxiosErrorLike(error) {
|
|
6
|
+
return typeof error === "object" && error !== null && "isAxiosError" in error;
|
|
35
7
|
}
|
|
36
|
-
function
|
|
37
|
-
if (
|
|
38
|
-
|
|
8
|
+
function isCanceledRequest(error) {
|
|
9
|
+
if (error instanceof DOMException && ["AbortError", "TimeoutError"].includes(error.name)) return true;
|
|
10
|
+
if (isAxiosErrorLike(error)) return error.code === "ERR_CANCELED" || error.code === "ECONNABORTED";
|
|
11
|
+
return false;
|
|
39
12
|
}
|
|
40
|
-
|
|
41
13
|
//#endregion
|
|
42
14
|
//#region src/lib/rest/rest.utils.ts
|
|
15
|
+
function getResponseData(error) {
|
|
16
|
+
if (error instanceof HttpError) return error.response.data;
|
|
17
|
+
return isAxiosErrorLike(error) ? error.response?.data : void 0;
|
|
18
|
+
}
|
|
43
19
|
let RestUtils;
|
|
44
20
|
(function(_RestUtils) {
|
|
45
21
|
_RestUtils.extractServerResponseCode = (e) => {
|
|
46
22
|
if (e instanceof z.ZodError) return "validation-exception";
|
|
47
|
-
|
|
48
|
-
if (!e.response) return null;
|
|
49
|
-
const data = e.response.data;
|
|
23
|
+
const data = getResponseData(e);
|
|
50
24
|
if (typeof data?.code === "string") return data.code;
|
|
51
25
|
if (typeof data?.code === "number") return data.code;
|
|
52
26
|
return null;
|
|
@@ -58,9 +32,7 @@ let RestUtils;
|
|
|
58
32
|
};
|
|
59
33
|
const extractServerErrorMessage = _RestUtils.extractServerErrorMessage = (e) => {
|
|
60
34
|
if (e instanceof z.ZodError) return e.message;
|
|
61
|
-
|
|
62
|
-
if (!e.response) return null;
|
|
63
|
-
const data = e.response.data;
|
|
35
|
+
const data = getResponseData(e);
|
|
64
36
|
if (typeof data?.message === "string") return data.message;
|
|
65
37
|
return null;
|
|
66
38
|
};
|
|
@@ -69,7 +41,6 @@ let RestUtils;
|
|
|
69
41
|
return contentDisposition ? /filename=["']?([^"';]+)/i.exec(contentDisposition)?.[1] : void 0;
|
|
70
42
|
};
|
|
71
43
|
})(RestUtils || (RestUtils = {}));
|
|
72
|
-
|
|
73
44
|
//#endregion
|
|
74
45
|
//#region src/lib/rest/error-handling.ts
|
|
75
46
|
var ApplicationException = class extends Error {
|
|
@@ -114,7 +85,8 @@ var ErrorHandler = class ErrorHandler {
|
|
|
114
85
|
const internalError = {
|
|
115
86
|
code: "INTERNAL_ERROR",
|
|
116
87
|
condition: (e) => {
|
|
117
|
-
if (
|
|
88
|
+
if (isAxiosErrorLike(e)) return e.response?.status != null && e.response.status >= 500 && e.response.status < 600;
|
|
89
|
+
if (e instanceof HttpError) return e.response.status >= 500 && e.response.status < 600;
|
|
118
90
|
return false;
|
|
119
91
|
},
|
|
120
92
|
getMessage: () => resolveT()("openapi.sharedErrors.internalError", { ns })
|
|
@@ -122,7 +94,8 @@ var ErrorHandler = class ErrorHandler {
|
|
|
122
94
|
const networkError = {
|
|
123
95
|
code: "NETWORK_ERROR",
|
|
124
96
|
condition: (e) => {
|
|
125
|
-
if (
|
|
97
|
+
if (isAxiosErrorLike(e)) return e.code === "ERR_NETWORK";
|
|
98
|
+
if (e instanceof TypeError) return true;
|
|
126
99
|
return false;
|
|
127
100
|
},
|
|
128
101
|
getMessage: () => resolveT()("openapi.sharedErrors.networkError", { ns })
|
|
@@ -130,9 +103,7 @@ var ErrorHandler = class ErrorHandler {
|
|
|
130
103
|
const canceledError = {
|
|
131
104
|
code: "CANCELED_ERROR",
|
|
132
105
|
condition: (e) => {
|
|
133
|
-
|
|
134
|
-
if (isAxiosError(e) && e.code === "ECONNABORTED") return true;
|
|
135
|
-
return false;
|
|
106
|
+
return isCanceledRequest(e);
|
|
136
107
|
},
|
|
137
108
|
getMessage: () => resolveT()("openapi.sharedErrors.canceledError", { ns })
|
|
138
109
|
};
|
|
@@ -209,6 +180,5 @@ var ErrorHandler = class ErrorHandler {
|
|
|
209
180
|
}
|
|
210
181
|
};
|
|
211
182
|
const SharedErrorHandler = new ErrorHandler({ entries: [] });
|
|
212
|
-
|
|
213
183
|
//#endregion
|
|
214
|
-
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 {
|
|
@@ -69,10 +33,7 @@ declare class ErrorHandler<CodeT extends string | number> {
|
|
|
69
33
|
private readonly userEntries;
|
|
70
34
|
private readonly generalEntries;
|
|
71
35
|
private onRethrowError?;
|
|
72
|
-
constructor({
|
|
73
|
-
entries,
|
|
74
|
-
onRethrowError
|
|
75
|
-
}: ErrorHandlerOptions<CodeT>);
|
|
36
|
+
constructor({ entries, onRethrowError }: ErrorHandlerOptions<CodeT>);
|
|
76
37
|
private matchesEntry;
|
|
77
38
|
/** Lazy so resolveT() only runs when getMessage actually uses `t`. */
|
|
78
39
|
private static lazyT;
|
|
@@ -83,4 +44,4 @@ declare class ErrorHandler<CodeT extends string | number> {
|
|
|
83
44
|
}
|
|
84
45
|
declare const SharedErrorHandler: ErrorHandler<never>;
|
|
85
46
|
//#endregion
|
|
86
|
-
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