@povio/openapi-codegen-cli 3.3.0-rc.2 → 4.0.0-rc.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (68) hide show
  1. package/README.md +97 -9
  2. package/dist/AuthGuard-GbtTDXs0.d.mts +32 -0
  3. package/dist/AuthGuard-qpAtHaBz.mjs +24 -0
  4. package/dist/acl.d.mts +6 -19
  5. package/dist/acl.mjs +7 -7
  6. package/dist/{auth.context-BAz8frX9.mjs → auth.context-COWO6ssl.mjs} +1 -18
  7. package/dist/auth.d.mts +2 -0
  8. package/dist/auth.mjs +3 -0
  9. package/dist/axios.d.mts +2 -0
  10. package/dist/axios.mjs +2 -0
  11. package/dist/{config-BQqze8rU.d.mts → config-CiLFKLAY.d.mts} +1 -2
  12. package/dist/config.d.mts +4 -0
  13. package/dist/config.mjs +5 -0
  14. package/dist/{error-handling-D6ZYITQ3.d.mts → error-handling-LPEPQV1V.d.mts} +3 -42
  15. package/dist/{error-handling-CsnufAil.mjs → error-handling-uS0DgYUR.mjs} +23 -47
  16. package/dist/errors.d.mts +3 -0
  17. package/dist/errors.mjs +2 -0
  18. package/dist/generate.runner-BtPpBVj9.mjs +1667 -0
  19. package/dist/generate.utils-BJxdEik8.cjs +2269 -0
  20. package/dist/{generateCodeFromOpenAPIDoc-SYuVswEJ.mjs → generateCodeFromOpenAPIDoc-CGoR73wh.cjs} +1334 -2237
  21. package/dist/generateCodeFromOpenAPIDoc-D1H6MZiS.mjs +2101 -0
  22. package/dist/generator.d.mts +3 -10
  23. package/dist/generator.mjs +6 -4
  24. package/dist/getDataFromOpenAPIDoc-fJCwtr-2.mjs +2016 -0
  25. package/dist/i18n-B_brQh4X.d.mts +38 -0
  26. package/dist/i18n-D-FesqFb.mjs +36 -0
  27. package/dist/index.d.mts +12 -198
  28. package/dist/index.mjs +12 -256
  29. package/dist/metro.cjs +117 -4862
  30. package/dist/metro.d.mts +3 -4
  31. package/dist/metro.mjs +3 -3
  32. package/dist/native-rest-interceptor-BX45GDWd.d.mts +49 -0
  33. package/dist/native-rest-interceptor-Np4Ov54n.mjs +215 -0
  34. package/dist/native.d.mts +3 -0
  35. package/dist/native.mjs +3 -0
  36. package/dist/openapi-codegen-native-darwin-arm64.node +0 -0
  37. package/dist/openapi-codegen-native-linux-x64.node +0 -0
  38. package/dist/openapi-codegen-native-win32-x64.node +0 -0
  39. package/dist/{openapi-codegen.runner-CCXQsUum.mjs → openapi-codegen.runner-BpykceyD.mjs} +2 -2
  40. package/dist/{openapi-source.runner-B6KKrXw7.d.mts → openapi-source.runner-DIOvAX_R.d.mts} +2 -8
  41. package/dist/{openapi-source.runner-8kCe-g9S.mjs → openapi-source.runner-DPUNTduQ.mjs} +25 -11
  42. package/dist/{options-DdQJ9BSc.d.mts → options-X0zju7gw.d.mts} +8 -1
  43. package/dist/query.d.mts +3 -0
  44. package/dist/query.mjs +3 -0
  45. package/dist/queryConfig.context-CldQ5YL9.mjs +34 -0
  46. package/dist/queryConfig.context-aO4QOLru.d.mts +24 -0
  47. package/dist/rest-client-BSXsrOff.d.mts +55 -0
  48. package/dist/rest-interceptor-Dm9DFErh.mjs +115 -0
  49. package/dist/rest-transport.types-DM5-qyOJ.d.mts +66 -0
  50. package/dist/rest-transport.types-DxitRtsB.mjs +11 -0
  51. package/dist/rest.d.mts +2 -0
  52. package/dist/rest.mjs +2 -0
  53. package/dist/rest.utils-DpiFIdhF.d.mts +9 -0
  54. package/dist/router.context-EPlMBk3G.mjs +21 -0
  55. package/dist/sh.d.mts +1 -1
  56. package/dist/sh.mjs +52 -59
  57. package/dist/tiny.d.mts +1 -1
  58. package/dist/tiny.mjs +1 -1
  59. package/dist/useMutationEffects-D_wEEF6-.d.mts +29 -0
  60. package/dist/useMutationEffects-PB1fvKWM.mjs +68 -0
  61. package/dist/vite.d.mts +3 -4
  62. package/dist/vite.mjs +5 -4
  63. package/dist/workspace.context-XWvQ_7Hg.mjs +26 -0
  64. package/dist/workspace.context-isVY9ves.d.mts +23 -0
  65. package/dist/zod.d.mts +2 -7
  66. package/dist/zod.mjs +1 -1
  67. package/package.json +70 -22
  68. package/dist/generate.runner-B0Zm3pIl.mjs +0 -87
package/README.md CHANGED
@@ -4,9 +4,11 @@
4
4
 
5
5
  **NOTE:** Version 1+ requires zod v4 and is not compatible with zod v3.
6
6
 
7
- **NOTE:** Version 2+ includes supporting classes/types/components for the generated code as well as auth, therefore it has peerDependencies for @tanstack/react-query, axios, react and zod. @casl/ability and @casl/react are also required if you are generating ACL checks and/or using imports from "@povio/openapi-codegen-cli/acl"!
7
+ **NOTE:** The package includes supporting classes, types, components, and auth utilities. Zod is a required peer dependency. Axios, @tanstack/react-query, react, i18next, @casl/ability, @casl/react, and Vite are optional peers; install the ones used by your chosen features.
8
8
 
9
- Use this tool to generate code (Zod schemas, TypeScript types, API definitions, and React queries) from an OpenAPI v3 specification. API definitions are generated to use a REST client wrapper that utilizes Axios. React queries are generated in alignment with our code standards, without the need for explicit types.
9
+ Axios is required when using the Axios transport (the default) or the `/axios` entry point. Projects using the native transport can omit Axios: generate with `--restClient native` and import `NativeRestClient` from `@povio/openapi-codegen-cli/native`. The root exports remain available for compatibility and support tree-shaking in consumer bundles. For direct runtime imports without bundling, use `/native` and `/errors` to avoid loading the Axios client. The `/axios` entry point is also available for Axios-specific imports. CLI-only usage and the `/generator`, `/tiny`, `/vite`, and `/metro` entry points do not require Axios.
10
+
11
+ Use this tool to generate code (Zod schemas, TypeScript types, API definitions, and React queries) from an OpenAPI v3 specification. API definitions use a REST client wrapper with either Axios or the native transport. React queries are generated in alignment with our code standards, without the need for explicit types.
10
12
 
11
13
  The tool partially leverages code from [openapi-zod-client](https://github.com/astahmer/openapi-zod-client) repository.
12
14
 
@@ -22,6 +24,18 @@ bun add @povio/openapi-codegen-cli
22
24
  bunx openapi-codegen generate --input http://localhost:3001/docs-json
23
25
  ```
24
26
 
27
+ ## Schema compilation
28
+
29
+ Generated models use ordinary Zod schemas by default, preserving validation without the startup work of explicit `z.compile(...)` calls. Regenerate existing clients to remove previously emitted compilation calls. A frontend entry-point `import "zod/compile"` used solely for these generated models can then be removed.
30
+
31
+ Set `compileSchemas: true` in your generator configuration (or pass `--compileSchemas`) to opt into eager compilation for non-recursive schemas. This trades initialization time for potential validation throughput improvements. Recursive schemas remain uncompiled. Both the TypeScript and native generators honor this option.
32
+
33
+ ```typescript
34
+ export default {
35
+ compileSchemas: false, // Default; normal Zod validation stays enabled.
36
+ };
37
+ ```
38
+
25
39
  ## Configuration Files
26
40
 
27
41
  The CLI supports TypeScript configuration files to simplify command execution and provide consistent settings with full type safety. Configuration files are automatically discovered in your project root.
@@ -33,7 +47,7 @@ The CLI supports TypeScript configuration files to simplify command execution an
33
47
  Create an `openapi-codegen.config.ts` file:
34
48
 
35
49
  ```typescript
36
- import { OpenAPICodegenConfig } from "@povio/openapi-codegen-cli";
50
+ import type { OpenAPICodegenConfig } from "@povio/openapi-codegen-cli";
37
51
 
38
52
  const config: OpenAPICodegenConfig = {
39
53
  input: "http://localhost:4000/docs-json/",
@@ -85,11 +99,13 @@ bunx openapi-codegen generate --config my-config.ts
85
99
  --importPath Module import style for generated files (default: 'ts'; options: 'ts' | 'relative' | 'absolute')
86
100
  --tsPath (Requires `--importPath` to be 'ts') Typescript import path (default: '@/data')
87
101
  --removeOperationPrefixEndingWith Remove operation name prefixes that end with the specified string (default: 'Controller_')
102
+ --compileSchemas Eagerly compile non-recursive Zod schemas (default: false)
88
103
  --extractEnums Extract enums into separate Zod schemas (default: true)
89
104
  --modelsInCommon Keep all schema declarations in defaultTag models and emit per-module proxy exports (default: false)
90
105
  --replaceOptionalWithNullish Replace `.optional()` chains with `.nullish()` in generated Zod schemas (default: false)
91
106
 
92
- --axiosRequestConfig Include Axios request config parameters in query hooks (default: false)
107
+ --restClient REST transport to generate: 'axios' or 'native' (default: 'axios')
108
+ --axiosRequestConfig Include transport request config parameters in query hooks (default: false)
93
109
  --infiniteQueries Generate infinite queries for paginated API endpoints (default: false)
94
110
  --mutationEffects Add mutation effects options to mutation hooks (default: true)
95
111
  --mutationScope Serialize mutations for the same path-param resource via TanStack scope.id (default: false).
@@ -138,7 +154,7 @@ bun install
138
154
  # run tests
139
155
  bun run test
140
156
 
141
- # run sources with tsx
157
+ # run TypeScript sources directly with Bun
142
158
  bun run start --help
143
159
  bun run start generate --input ./test/petstore.yaml --verbose
144
160
 
@@ -150,14 +166,66 @@ bun run start --help
150
166
  bun run start:dist generate --input ./test/petstore.yaml --verbose
151
167
  ```
152
168
 
169
+ ### Native Bun code generation
170
+
171
+ 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.
172
+
173
+ 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.
174
+
175
+ 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`.
176
+
177
+ Run `bun run test:parity` after building the addon to compare every generated file across 64 layout combinations and representative values for every other renderer option. The matrix uses both `test/petstore.yaml` and `test/configuration.yaml`, exercises complete native and hybrid native generation, and loads generated models to check runtime references. The contradictory combination `modelsInCommon: true` with `modelsInModules: true` is rejected explicitly. Arbitrary strings and lists are covered by representative cases, not every possible value.
178
+
179
+ The separate Renderer parity workflow generates this matrix with JavaScript and native on Linux and macOS, then compares exact file lists and SHA-256 hashes. Artifacts include route reports identifying complete versus hybrid native generation. Runner integration tests cover input/output, stale-file cleanup, and unchanged files; `incremental` is currently retained as a compatibility option and does not change the writer's unchanged-file optimization.
180
+
153
181
  ## Common Issues
154
182
 
155
183
  ### App REST Client Interceptors
156
184
 
185
+ Select the fetch-based client without changing endpoint and query APIs:
186
+
187
+ ```ts
188
+ import type { OpenAPICodegenConfig } from "@povio/openapi-codegen-cli";
189
+
190
+ export default {
191
+ restClient: "native",
192
+ } satisfies OpenAPICodegenConfig;
193
+ ```
194
+
195
+ Native mode imports common request/response contracts from `@povio/openapi-codegen-cli/rest` and the concrete
196
+ `NativeRestClient` from `@povio/openapi-codegen-cli/native`. It uses `fetch` for normal requests and uploads, switching
197
+ to `XMLHttpRequest` in browsers only when an upload progress callback is provided.
198
+
199
+ Native interceptors use the common transport interface:
200
+
201
+ ```ts
202
+ import { NativeRestClient } from "@povio/openapi-codegen-cli/native";
203
+ import type { RestTransportInterceptor } from "@povio/openapi-codegen-cli/rest";
204
+
205
+ const authorizationInterceptor: RestTransportInterceptor = {
206
+ onRequest(request) {
207
+ request.headers.set("Authorization", `Bearer ${localStorage.getItem("accessToken")}`);
208
+ return request;
209
+ },
210
+ };
211
+
212
+ export const AppRestClient = new NativeRestClient({
213
+ config: { baseURL: "https://api.example.com" },
214
+ interceptors: [authorizationInterceptor],
215
+ });
216
+ ```
217
+
218
+ Axios remains the default for backward compatibility. The existing Axios interceptor API remains available in Axios
219
+ mode.
220
+
221
+ Native mode does not run the library `ErrorHandler` or create `ApplicationException` values. It throws `HttpError` for
222
+ non-success HTTP responses and preserves Zod, network, cancellation, and timeout errors so applications can handle them
223
+ directly in query callbacks, error boundaries, or their own normalization layer.
224
+
157
225
  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.
158
226
 
159
227
  ```ts
160
- import { RestInterceptor } from "@povio/openapi-codegen-cli";
228
+ import { RestInterceptor } from "@povio/openapi-codegen-cli/axios";
161
229
 
162
230
  import { ACCESS_TOKEN_KEY } from "@/config/jwt.config";
163
231
 
@@ -174,7 +242,7 @@ export const AuthorizationHeaderInterceptor = new RestInterceptor((client) => {
174
242
  ```
175
243
 
176
244
  ```ts
177
- import { RestClient } from "@povio/openapi-codegen-cli";
245
+ import { RestClient } from "@povio/openapi-codegen-cli/axios";
178
246
 
179
247
  import { AuthorizationHeaderInterceptor } from "@/clients/rest/interceptors/authorization-header.interceptor";
180
248
  import { AppConfig } from "@/config/app.config";
@@ -203,7 +271,8 @@ export default config;
203
271
  Set `mutationDefaultOnError: true` in codegen config (or pass `--mutationDefaultOnError`) to let generated mutation hooks fall back to `OpenApiQueryConfig.Provider` when a mutation call does not define its own `onError`.
204
272
 
205
273
  ```tsx
206
- import { ErrorHandler, OpenApiQueryConfig } from "@povio/openapi-codegen-cli";
274
+ import { ErrorHandler } from "@povio/openapi-codegen-cli/errors";
275
+ import { OpenApiQueryConfig } from "@povio/openapi-codegen-cli/query";
207
276
 
208
277
  <OpenApiQueryConfig.Provider
209
278
  onError={(error) => {
@@ -229,7 +298,7 @@ Use `OpenApiQueryConfig.Provider` to allow generated GET query hooks to return i
229
298
  Set `workspaceContext` to a list of param names in codegen config (or pass `--workspaceContext officeId,projectId`) and wrap your app subtree with `OpenApiWorkspaceContext.Provider` if generated hooks frequently repeat workspace-scoped params.
230
299
 
231
300
  ```tsx
232
- import { OpenApiWorkspaceContext } from "@povio/openapi-codegen-cli";
301
+ import { OpenApiWorkspaceContext } from "@povio/openapi-codegen-cli/config";
233
302
  // openapi-codegen.config.ts -> { workspaceContext: ["officeId", "projectId"] }
234
303
 
235
304
  <OpenApiWorkspaceContext.Provider values={{ officeId: "office_123" }}>
@@ -501,3 +570,22 @@ export class JSONDto {
501
570
  nested: NestedDto;
502
571
  }
503
572
  ```
573
+
574
+ ### Runtime import paths
575
+
576
+ Use package subpaths for runtime imports. Pure `import type` imports may use the package root.
577
+
578
+ | Runtime exports | Subpath |
579
+ | --- | --- |
580
+ | `AuthContext`, `AuthGuard` | `/auth` |
581
+ | `AbilityContext`, `useAclCheck`, `Can`, `createAclGuard` | `/acl` |
582
+ | `ErrorHandler`, `SharedErrorHandler`, `ApplicationException`, `DomainErrorRegistry` | `/errors` |
583
+ | `useMutationEffects`, `OpenApiQueryConfig` | `/query` |
584
+ | `OpenApiRouter`, `OpenApiWorkspaceContext`, `useWorkspaceContext`, translation configuration | `/config` |
585
+ | `ZodExtended` | `/zod` |
586
+ | `HttpError`, transport types | `/rest` |
587
+ | `NativeRestClient` | `/native` |
588
+ | `RestClient`, `RestInterceptor` (Axios transport) | `/axios` |
589
+
590
+ For example: `import { AuthContext, AuthGuard } from "@povio/openapi-codegen-cli/auth"`.
591
+ Custom application helpers should import error helpers from `/errors`, `AbilityContext` from `/acl`, and mutation effects from `/query`.
@@ -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,25 +1,21 @@
1
- import { a as ErrorHandler } from "./error-handling-D6ZYITQ3.mjs";
2
- import * as _$react from "react";
1
+ import { a as ErrorHandler } from "./error-handling-LPEPQV1V.mjs";
3
2
  import { PropsWithChildren } from "react";
4
3
  import { AbilityTuple, PureAbility, RawRuleOf, Subject } from "@casl/ability";
5
4
  import { PackRule } from "@casl/ability/extra";
6
5
  import { BoundCanProps } from "@casl/react";
7
-
8
6
  //#region src/lib/acl/appAbility.types.d.ts
9
7
  type AppAbilities = AbilityTuple<string, Subject>;
10
8
  type AppAbility = PureAbility<AppAbilities>;
11
9
  //#endregion
12
10
  //#region src/lib/acl/ability.context.d.ts
13
11
  declare namespace AbilityContext {
14
- export const Consumer: _$react.Consumer<AppAbility>;
12
+ export const Consumer: import("react").Consumer<AppAbility>;
15
13
  interface ProviderProps {
16
14
  user?: {
17
15
  aclRules?: PackRule<RawRuleOf<AppAbility>>[];
18
16
  } | null;
19
17
  }
20
- export const Provider: ({
21
- children
22
- }: PropsWithChildren<ProviderProps>) => _$react.JSX.Element;
18
+ export const Provider: ({ children }: PropsWithChildren<ProviderProps>) => import("react").JSX.Element;
23
19
  export const useAbility: <TAppAbilities extends AppAbilities = AppAbilities>() => PureAbility<TAppAbilities>;
24
20
  export {};
25
21
  }
@@ -29,29 +25,20 @@ interface AclGuardProps<TAppAbilities extends AppAbilities = AppAbilities> {
29
25
  canUse: TAppAbilities;
30
26
  redirectTo?: string;
31
27
  }
32
- declare const createAclGuard: <TAppAbilities extends AppAbilities = AppAbilities>() => ({
33
- canUse,
34
- redirectTo,
35
- children
36
- }: PropsWithChildren<AclGuardProps<TAppAbilities>>) => _$react.ReactNode;
28
+ declare const createAclGuard: <TAppAbilities extends AppAbilities = AppAbilities>() => ({ canUse, redirectTo, children }: PropsWithChildren<AclGuardProps<TAppAbilities>>) => import("react").ReactNode;
37
29
  //#endregion
38
30
  //#region src/lib/acl/Can.d.ts
39
31
  type CanAbility = PureAbility<AbilityTuple<AppAbilities[0], AppAbilities[1]>>;
40
32
  type CanProps<TAppAbilities extends AppAbilities = AppAbilities> = {
41
33
  use: TAppAbilities;
42
34
  } & Omit<BoundCanProps<CanAbility>, "do" | "I" | "on" | "a" | "an" | "this">;
43
- declare const Can: <TAppAbilities extends AppAbilities = AppAbilities>({
44
- use,
45
- ...props
46
- }: CanProps<TAppAbilities>) => _$react.JSX.Element;
35
+ declare const Can: <TAppAbilities extends AppAbilities = AppAbilities>({ use, ...props }: CanProps<TAppAbilities>) => import("react").JSX.Element;
47
36
  //#endregion
48
37
  //#region src/lib/acl/useAclCheck.d.ts
49
38
  interface UseAclCheckProps {
50
39
  errorHandler?: ErrorHandler<never>;
51
40
  }
52
- declare function useAclCheck<TAppAbilities extends AppAbilities = AppAbilities>({
53
- errorHandler
54
- }?: UseAclCheckProps): {
41
+ declare function useAclCheck<TAppAbilities extends AppAbilities = AppAbilities>({ errorHandler }?: UseAclCheckProps): {
55
42
  checkAcl: (appAbility: TAppAbilities) => void;
56
43
  };
57
44
  //#endregion
package/dist/acl.mjs CHANGED
@@ -1,6 +1,7 @@
1
- import { i as SharedErrorHandler } from "./error-handling-CsnufAil.mjs";
2
- import { n as OpenApiRouter, t as AuthContext } from "./auth.context-BAz8frX9.mjs";
3
- import { createContext, useCallback, useEffect, useState } from "react";
1
+ import { i as SharedErrorHandler } from "./error-handling-uS0DgYUR.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";
@@ -14,16 +15,15 @@ let AbilityContext;
14
15
  const { Consumer } = Context;
15
16
  _AbilityContext.Consumer = Consumer;
16
17
  _AbilityContext.Provider = ({ children }) => {
17
- const [ability, setAbility] = useState(initialAppAbility);
18
18
  const { user } = AuthContext.useAuth();
19
- useEffect(() => {
20
- if (!user || !("aclRules" in user)) return;
19
+ const ability = useMemo(() => {
20
+ if (!user || !("aclRules" in user)) return initialAppAbility;
21
21
  const { can, build } = createAppAbilityBuilder();
22
22
  const packedRules = user.aclRules;
23
23
  unpackRules(packedRules).forEach(({ action, subject, conditions }) => {
24
24
  can(action, subject, conditions);
25
25
  });
26
- setAbility(build());
26
+ return build();
27
27
  }, [user]);
28
28
  return /* @__PURE__ */ jsx(Context.Provider, {
29
29
  value: ability,
@@ -1,22 +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
- return /* @__PURE__ */ jsx(Context, {
9
- value: useMemo(() => ({ replace }), [replace]),
10
- children
11
- });
12
- };
13
- _OpenApiRouter.useRouter = () => {
14
- const context = use(Context);
15
- if (!context) throw new Error("useRouter must be used within an OpenApiRouter.Provider");
16
- return context;
17
- };
18
- })(OpenApiRouter || (OpenApiRouter = {}));
19
- //#endregion
20
3
  //#region src/lib/auth/auth.context.tsx
21
4
  let AuthContext;
22
5
  (function(_AuthContext) {
@@ -53,4 +36,4 @@ let AuthContext;
53
36
  };
54
37
  })(AuthContext || (AuthContext = {}));
55
38
  //#endregion
56
- export { OpenApiRouter as n, AuthContext as t };
39
+ export { AuthContext as t };
@@ -0,0 +1,2 @@
1
+ import { n as AuthGuardProps, r as AuthContext, t as AuthGuard } from "./AuthGuard-GbtTDXs0.mjs";
2
+ export { AuthContext, AuthGuard, type AuthGuardProps };
package/dist/auth.mjs ADDED
@@ -0,0 +1,3 @@
1
+ import { t as AuthContext } from "./auth.context-COWO6ssl.mjs";
2
+ import { t as AuthGuard } from "./AuthGuard-qpAtHaBz.mjs";
3
+ export { AuthContext, AuthGuard };
@@ -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-BSXsrOff.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,2 @@
1
+ import { n as RestClient, t as RestInterceptor } from "./rest-interceptor-Dm9DFErh.mjs";
2
+ export { RestClient, RestInterceptor };
@@ -1,5 +1,4 @@
1
- import { t as GenerateOptions } from "./options-DdQJ9BSc.mjs";
2
-
1
+ import { t as GenerateOptions } from "./options-X0zju7gw.mjs";
3
2
  //#region src/generators/types/config.d.ts
4
3
  type OpenAPICodegenConfig = Partial<GenerateOptions>;
5
4
  //#endregion
@@ -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-aO4QOLru.mjs";
4
+ export { type InvalidationMap, type InvalidationMapFunc, OpenApiQueryConfig, OpenApiRouter, OpenApiWorkspaceContext, type QueryModule, type TranslateFunction, configureTranslations, ns, resources, useWorkspaceContext };
@@ -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,4 @@
1
- //#region src/lib/config/i18n.d.ts
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, ns as d, resources as f, ErrorEntry as i, TranslateFunction as l, DomainErrorEntry as n, ErrorHandlerOptions as o, DomainErrorRegistry as r, GeneralErrorCodes as s, ApplicationException as t, configureTranslations as u };
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 };
@@ -1,48 +1,26 @@
1
- import { isAxiosError, isCancel } from "axios";
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
- //#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();
4
+ //#region src/lib/rest/http-error.utils.ts
5
+ function isAxiosErrorLike(error) {
6
+ return typeof error === "object" && error !== null && "isAxiosError" in error;
32
7
  }
33
- function resolveT() {
34
- if (!getT) throw new Error("Translations not configured. Call configureTranslations() at app startup.");
35
- return getT();
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;
36
12
  }
37
13
  //#endregion
38
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
+ }
39
19
  let RestUtils;
40
20
  (function(_RestUtils) {
41
21
  _RestUtils.extractServerResponseCode = (e) => {
42
22
  if (e instanceof z.ZodError) return "validation-exception";
43
- if (!isAxiosError(e)) return null;
44
- if (!e.response) return null;
45
- const data = e.response.data;
23
+ const data = getResponseData(e);
46
24
  if (typeof data?.code === "string") return data.code;
47
25
  if (typeof data?.code === "number") return data.code;
48
26
  return null;
@@ -54,15 +32,13 @@ let RestUtils;
54
32
  };
55
33
  const extractServerErrorMessage = _RestUtils.extractServerErrorMessage = (e) => {
56
34
  if (e instanceof z.ZodError) return e.message;
57
- if (!isAxiosError(e)) return null;
58
- if (!e.response) return null;
59
- const data = e.response.data;
35
+ const data = getResponseData(e);
60
36
  if (typeof data?.message === "string") return data.message;
61
37
  return null;
62
38
  };
63
39
  _RestUtils.extractContentDispositionFilename = (headers) => {
64
- const contentDisposition = headers["content-disposition"];
65
- return contentDisposition ? /filename=["']?([^"';]+)/i.exec(contentDisposition)?.[1] : void 0;
40
+ const contentDisposition = headers instanceof Headers ? headers.get("content-disposition") : headers["content-disposition"];
41
+ return typeof contentDisposition === "string" ? /filename=["']?([^"';]+)/i.exec(contentDisposition)?.[1] : void 0;
66
42
  };
67
43
  })(RestUtils || (RestUtils = {}));
68
44
  //#endregion
@@ -109,7 +85,8 @@ var ErrorHandler = class ErrorHandler {
109
85
  const internalError = {
110
86
  code: "INTERNAL_ERROR",
111
87
  condition: (e) => {
112
- if (isAxiosError(e)) return e.response?.status != null && e.response.status >= 500 && e.response.status < 600;
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;
113
90
  return false;
114
91
  },
115
92
  getMessage: () => resolveT()("openapi.sharedErrors.internalError", { ns })
@@ -117,7 +94,8 @@ var ErrorHandler = class ErrorHandler {
117
94
  const networkError = {
118
95
  code: "NETWORK_ERROR",
119
96
  condition: (e) => {
120
- if (isAxiosError(e)) return e.code === "ERR_NETWORK";
97
+ if (isAxiosErrorLike(e)) return e.code === "ERR_NETWORK";
98
+ if (e instanceof TypeError) return true;
121
99
  return false;
122
100
  },
123
101
  getMessage: () => resolveT()("openapi.sharedErrors.networkError", { ns })
@@ -125,9 +103,7 @@ var ErrorHandler = class ErrorHandler {
125
103
  const canceledError = {
126
104
  code: "CANCELED_ERROR",
127
105
  condition: (e) => {
128
- if (isCancel(e)) return true;
129
- if (isAxiosError(e) && e.code === "ECONNABORTED") return true;
130
- return false;
106
+ return isCanceledRequest(e);
131
107
  },
132
108
  getMessage: () => resolveT()("openapi.sharedErrors.canceledError", { ns })
133
109
  };
@@ -205,4 +181,4 @@ var ErrorHandler = class ErrorHandler {
205
181
  };
206
182
  const SharedErrorHandler = new ErrorHandler({ entries: [] });
207
183
  //#endregion
208
- export { RestUtils as a, resources as c, SharedErrorHandler as i, DomainErrorRegistry as n, configureTranslations as o, ErrorHandler as r, ns as s, ApplicationException as t };
184
+ export { RestUtils as a, SharedErrorHandler as i, DomainErrorRegistry as n, ErrorHandler as r, 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-DpiFIdhF.mjs";
3
+ export { ApplicationException, type DomainErrorEntry, DomainErrorRegistry, type ErrorEntry, ErrorHandler, type ErrorHandlerOptions, type GeneralErrorCodes, RestUtils, SharedErrorHandler };
@@ -0,0 +1,2 @@
1
+ import { a as RestUtils, i as SharedErrorHandler, n as DomainErrorRegistry, r as ErrorHandler, t as ApplicationException } from "./error-handling-uS0DgYUR.mjs";
2
+ export { ApplicationException, DomainErrorRegistry, ErrorHandler, RestUtils, SharedErrorHandler };