@povio/openapi-codegen-cli 3.3.0-rc.2 → 3.3.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 +132 -9
  2. package/dist/AuthGuard-GbtTDXs0.d.mts +32 -0
  3. package/dist/AuthGuard-qpAtHaBz.mjs +24 -0
  4. package/dist/acl.d.mts +14 -27
  5. package/dist/acl.mjs +17 -14
  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-BYiBd1QI.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-CxlaA4c5.mjs +1670 -0
  19. package/dist/generate.utils-SfgYwPe7.cjs +2271 -0
  20. package/dist/generateCodeFromOpenAPIDoc-CmN4bFjv.mjs +2246 -0
  21. package/dist/{generateCodeFromOpenAPIDoc-SYuVswEJ.mjs → generateCodeFromOpenAPIDoc-Dv-hqKhh.cjs} +1511 -2269
  22. package/dist/generator.d.mts +3 -10
  23. package/dist/generator.mjs +6 -4
  24. package/dist/getDataFromOpenAPIDoc-DzeHecv2.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 +118 -4862
  30. package/dist/metro.d.mts +3 -4
  31. package/dist/metro.mjs +3 -3
  32. package/dist/native-rest-interceptor-Np4Ov54n.mjs +215 -0
  33. package/dist/native-rest-interceptor-PgziZt1f.d.mts +49 -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-DDd4AXRT.mjs} +2 -2
  40. package/dist/{openapi-source.runner-8kCe-g9S.mjs → openapi-source.runner-DPUNTduQ.mjs} +25 -11
  41. package/dist/{openapi-source.runner-B6KKrXw7.d.mts → openapi-source.runner-lmK-P6HE.d.mts} +2 -8
  42. package/dist/{options-DdQJ9BSc.d.mts → options-DH-fAG0w.d.mts} +12 -1
  43. package/dist/query.d.mts +3 -0
  44. package/dist/query.mjs +3 -0
  45. package/dist/queryConfig.context-CRJOgf19.d.mts +22 -0
  46. package/dist/queryConfig.context-CldQ5YL9.mjs +34 -0
  47. package/dist/rest-client-CQyFvqYC.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 +55 -55
  57. package/dist/tiny.d.mts +1 -1
  58. package/dist/tiny.mjs +1 -1
  59. package/dist/useMutationEffects-DIdL8tlx.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 +71 -21
  68. package/dist/generate.runner-B0Zm3pIl.mjs +0 -87
package/README.md CHANGED
@@ -4,9 +4,13 @@
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
+ ACL features require `@casl/ability@^7.1.1` and `@casl/react@^7.1.0`. When migrating to CASL 7, regenerate the client so `AppAbility` uses `Ability` instead of `PureAbility`, and update any handwritten CASL types. The runtime continues to use `createMongoAbility` for condition matching. CASL 7 treats empty conditions (`{}`) as matching everything. The `Can` helper keeps its `use` tuple and `(isAllowed, ability)` render callback.
12
+
13
+ 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
14
 
11
15
  The tool partially leverages code from [openapi-zod-client](https://github.com/astahmer/openapi-zod-client) repository.
12
16
 
@@ -22,6 +26,47 @@ bun add @povio/openapi-codegen-cli
22
26
  bunx openapi-codegen generate --input http://localhost:3001/docs-json
23
27
  ```
24
28
 
29
+ ## Schema compilation
30
+
31
+ 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.
32
+
33
+ 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.
34
+
35
+ ```typescript
36
+ export default {
37
+ compileSchemas: false, // Default; normal Zod validation stays enabled.
38
+ };
39
+ ```
40
+
41
+ ## JSDoc generation
42
+
43
+ JSDoc comments are omitted by default while schemas, inferred types, and runtime behavior are preserved. Set `generateJsDoc: true` in your generator configuration or pass `--generateJsDoc` to include comments. This applies to both TypeScript and native generation. Combine with `modelsOnly: true` if you only want model files.
44
+
45
+ ## Lazy schemas
46
+
47
+ With `tsNamespaces` enabled, every schema of a models namespace is built the moment the module is imported, even when the importer only needs one of them. Set `lazySchemas: true` (or pass `--lazySchemas`) to build each schema on first access instead:
48
+
49
+ ```typescript
50
+ // Generated with lazySchemas: true
51
+ const once = <T>(create: () => T) => {
52
+ let value: T | undefined;
53
+ return () => (value ??= create());
54
+ };
55
+
56
+ const PetSchema = once(() => z.object({ id: z.int(), category: CategorySchema() }));
57
+
58
+ export const PetModels = {
59
+ get PetSchema() {
60
+ return PetSchema();
61
+ },
62
+ };
63
+ export declare namespace PetModels {
64
+ export type Pet = z.infer<typeof PetModels.PetSchema>;
65
+ }
66
+ ```
67
+
68
+ `PetModels.PetSchema` stays a regular Zod schema (`.extend`, `.shape`, `.pick` all work and return the same instance on every access), `PetModels.Pet` keeps resolving as a type, and `modelsInCommon` proxies forward to the shared namespace lazily as well. The option requires `tsNamespaces` and is honored by both the TypeScript and native generators. It helps cold starts of apps that import large model modules but render only a slice of them.
69
+
25
70
  ## Configuration Files
26
71
 
27
72
  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 +78,7 @@ The CLI supports TypeScript configuration files to simplify command execution an
33
78
  Create an `openapi-codegen.config.ts` file:
34
79
 
35
80
  ```typescript
36
- import { OpenAPICodegenConfig } from "@povio/openapi-codegen-cli";
81
+ import type { OpenAPICodegenConfig } from "@povio/openapi-codegen-cli";
37
82
 
38
83
  const config: OpenAPICodegenConfig = {
39
84
  input: "http://localhost:4000/docs-json/",
@@ -85,11 +130,15 @@ bunx openapi-codegen generate --config my-config.ts
85
130
  --importPath Module import style for generated files (default: 'ts'; options: 'ts' | 'relative' | 'absolute')
86
131
  --tsPath (Requires `--importPath` to be 'ts') Typescript import path (default: '@/data')
87
132
  --removeOperationPrefixEndingWith Remove operation name prefixes that end with the specified string (default: 'Controller_')
133
+ --compileSchemas Eagerly compile non-recursive Zod schemas (default: false)
134
+ --generateJsDoc Emit JSDoc comments (default: false; enable with --generateJsDoc)
135
+ --lazySchemas Build namespace model schemas on first access instead of at import; requires `--tsNamespaces` (default: false)
88
136
  --extractEnums Extract enums into separate Zod schemas (default: true)
89
137
  --modelsInCommon Keep all schema declarations in defaultTag models and emit per-module proxy exports (default: false)
90
138
  --replaceOptionalWithNullish Replace `.optional()` chains with `.nullish()` in generated Zod schemas (default: false)
91
139
 
92
- --axiosRequestConfig Include Axios request config parameters in query hooks (default: false)
140
+ --restClient REST transport to generate: 'axios' or 'native' (default: 'axios')
141
+ --axiosRequestConfig Include transport request config parameters in query hooks (default: false)
93
142
  --infiniteQueries Generate infinite queries for paginated API endpoints (default: false)
94
143
  --mutationEffects Add mutation effects options to mutation hooks (default: true)
95
144
  --mutationScope Serialize mutations for the same path-param resource via TanStack scope.id (default: false).
@@ -138,7 +187,7 @@ bun install
138
187
  # run tests
139
188
  bun run test
140
189
 
141
- # run sources with tsx
190
+ # run TypeScript sources directly with Bun
142
191
  bun run start --help
143
192
  bun run start generate --input ./test/petstore.yaml --verbose
144
193
 
@@ -150,14 +199,66 @@ bun run start --help
150
199
  bun run start:dist generate --input ./test/petstore.yaml --verbose
151
200
  ```
152
201
 
202
+ ### Native Bun code generation
203
+
204
+ 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.
205
+
206
+ 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.
207
+
208
+ 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`.
209
+
210
+ 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.
211
+
212
+ 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.
213
+
153
214
  ## Common Issues
154
215
 
155
216
  ### App REST Client Interceptors
156
217
 
218
+ Select the fetch-based client without changing endpoint and query APIs:
219
+
220
+ ```ts
221
+ import type { OpenAPICodegenConfig } from "@povio/openapi-codegen-cli";
222
+
223
+ export default {
224
+ restClient: "native",
225
+ } satisfies OpenAPICodegenConfig;
226
+ ```
227
+
228
+ Native mode imports common request/response contracts from `@povio/openapi-codegen-cli/rest` and the concrete
229
+ `NativeRestClient` from `@povio/openapi-codegen-cli/native`. It uses `fetch` for normal requests and uploads, switching
230
+ to `XMLHttpRequest` in browsers only when an upload progress callback is provided.
231
+
232
+ Native interceptors use the common transport interface:
233
+
234
+ ```ts
235
+ import { NativeRestClient } from "@povio/openapi-codegen-cli/native";
236
+ import type { RestTransportInterceptor } from "@povio/openapi-codegen-cli/rest";
237
+
238
+ const authorizationInterceptor: RestTransportInterceptor = {
239
+ onRequest(request) {
240
+ request.headers.set("Authorization", `Bearer ${localStorage.getItem("accessToken")}`);
241
+ return request;
242
+ },
243
+ };
244
+
245
+ export const AppRestClient = new NativeRestClient({
246
+ config: { baseURL: "https://api.example.com" },
247
+ interceptors: [authorizationInterceptor],
248
+ });
249
+ ```
250
+
251
+ Axios remains the default for backward compatibility. The existing Axios interceptor API remains available in Axios
252
+ mode.
253
+
254
+ Native mode does not run the library `ErrorHandler` or create `ApplicationException` values. It throws `HttpError` for
255
+ non-success HTTP responses and preserves Zod, network, cancellation, and timeout errors so applications can handle them
256
+ directly in query callbacks, error boundaries, or their own normalization layer.
257
+
157
258
  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
259
 
159
260
  ```ts
160
- import { RestInterceptor } from "@povio/openapi-codegen-cli";
261
+ import { RestInterceptor } from "@povio/openapi-codegen-cli/axios";
161
262
 
162
263
  import { ACCESS_TOKEN_KEY } from "@/config/jwt.config";
163
264
 
@@ -174,7 +275,7 @@ export const AuthorizationHeaderInterceptor = new RestInterceptor((client) => {
174
275
  ```
175
276
 
176
277
  ```ts
177
- import { RestClient } from "@povio/openapi-codegen-cli";
278
+ import { RestClient } from "@povio/openapi-codegen-cli/axios";
178
279
 
179
280
  import { AuthorizationHeaderInterceptor } from "@/clients/rest/interceptors/authorization-header.interceptor";
180
281
  import { AppConfig } from "@/config/app.config";
@@ -203,7 +304,8 @@ export default config;
203
304
  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
305
 
205
306
  ```tsx
206
- import { ErrorHandler, OpenApiQueryConfig } from "@povio/openapi-codegen-cli";
307
+ import { ErrorHandler } from "@povio/openapi-codegen-cli/errors";
308
+ import { OpenApiQueryConfig } from "@povio/openapi-codegen-cli/query";
207
309
 
208
310
  <OpenApiQueryConfig.Provider
209
311
  onError={(error) => {
@@ -229,7 +331,7 @@ Use `OpenApiQueryConfig.Provider` to allow generated GET query hooks to return i
229
331
  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
332
 
231
333
  ```tsx
232
- import { OpenApiWorkspaceContext } from "@povio/openapi-codegen-cli";
334
+ import { OpenApiWorkspaceContext } from "@povio/openapi-codegen-cli/config";
233
335
  // openapi-codegen.config.ts -> { workspaceContext: ["officeId", "projectId"] }
234
336
 
235
337
  <OpenApiWorkspaceContext.Provider values={{ officeId: "office_123" }}>
@@ -256,6 +358,8 @@ const config: OpenAPICodegenConfig = {
256
358
  // modelsOnly: true,
257
359
  // 4) Keep all model declarations in common.models and generate per-module model proxies
258
360
  // modelsInCommon: true,
361
+ // 5) Build each namespace schema on first access instead of at import (requires tsNamespaces)
362
+ // lazySchemas: true,
259
363
  };
260
364
  ```
261
365
 
@@ -501,3 +605,22 @@ export class JSONDto {
501
605
  nested: NestedDto;
502
606
  }
503
607
  ```
608
+
609
+ ### Runtime import paths
610
+
611
+ Use package subpaths for runtime imports. Pure `import type` imports may use the package root.
612
+
613
+ | Runtime exports | Subpath |
614
+ | -------------------------------------------------------------------------------------------- | --------- |
615
+ | `AuthContext`, `AuthGuard` | `/auth` |
616
+ | `AbilityContext`, `useAclCheck`, `Can`, `createAclGuard` | `/acl` |
617
+ | `ErrorHandler`, `SharedErrorHandler`, `ApplicationException`, `DomainErrorRegistry` | `/errors` |
618
+ | `useMutationEffects`, `OpenApiQueryConfig` | `/query` |
619
+ | `OpenApiRouter`, `OpenApiWorkspaceContext`, `useWorkspaceContext`, translation configuration | `/config` |
620
+ | `ZodExtended` | `/zod` |
621
+ | `HttpError`, transport types | `/rest` |
622
+ | `NativeRestClient` | `/native` |
623
+ | `RestClient`, `RestInterceptor` (Axios transport) | `/axios` |
624
+
625
+ For example: `import { AuthContext, AuthGuard } from "@povio/openapi-codegen-cli/auth"`.
626
+ 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,26 +1,22 @@
1
- import { a as ErrorHandler } from "./error-handling-D6ZYITQ3.mjs";
2
- import * as _$react from "react";
3
- import { PropsWithChildren } from "react";
4
- import { AbilityTuple, PureAbility, RawRuleOf, Subject } from "@casl/ability";
1
+ import { a as ErrorHandler } from "./error-handling-LPEPQV1V.mjs";
2
+ import { PropsWithChildren, ReactNode } from "react";
3
+ import { Ability, AbilityTuple, RawRuleOf, Subject } from "@casl/ability";
5
4
  import { PackRule } from "@casl/ability/extra";
6
- import { BoundCanProps } from "@casl/react";
7
-
5
+ import { CanProps } from "@casl/react";
8
6
  //#region src/lib/acl/appAbility.types.d.ts
9
7
  type AppAbilities = AbilityTuple<string, Subject>;
10
- type AppAbility = PureAbility<AppAbilities>;
8
+ type AppAbility = Ability<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;
23
- export const useAbility: <TAppAbilities extends AppAbilities = AppAbilities>() => PureAbility<TAppAbilities>;
18
+ export const Provider: ({ children }: PropsWithChildren<ProviderProps>) => import("react").JSX.Element;
19
+ export const useAbility: <TAppAbilities extends AppAbilities = AppAbilities>() => Ability<TAppAbilities>;
24
20
  export {};
25
21
  }
26
22
  //#endregion
@@ -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
- type CanAbility = PureAbility<AbilityTuple<AppAbilities[0], AppAbilities[1]>>;
40
- type CanProps<TAppAbilities extends AppAbilities = AppAbilities> = {
31
+ type CanProps$1<TAppAbilities extends AppAbilities = AppAbilities> = {
41
32
  use: TAppAbilities;
42
- } & 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;
33
+ children: ReactNode | ((isAllowed: boolean, ability: AppAbility) => ReactNode);
34
+ } & Omit<CanProps<AppAbility>, "do" | "I" | "on" | "a" | "an" | "this" | "children">;
35
+ declare const Can: <TAppAbilities extends AppAbilities = AppAbilities>({ use, children, ...props }: CanProps$1<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,10 +1,11 @@
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";
7
- import { createContextualCan, useAbility } from "@casl/react";
8
+ import { AbilityProvider, Can as Can$1, useAbility } from "@casl/react";
8
9
  //#region src/lib/acl/ability.context.tsx
9
10
  let AbilityContext;
10
11
  (function(_AbilityContext) {
@@ -14,24 +15,26 @@ 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,
30
- children
30
+ children: /* @__PURE__ */ jsx(AbilityProvider, {
31
+ value: ability,
32
+ children
33
+ })
31
34
  });
32
35
  };
33
36
  _AbilityContext.useAbility = () => {
34
- return useAbility(Context);
37
+ return useAbility();
35
38
  };
36
39
  })(AbilityContext || (AbilityContext = {}));
37
40
  //#endregion
@@ -47,13 +50,13 @@ const createAclGuard = () => ({ canUse, redirectTo = "/", children }) => {
47
50
  };
48
51
  //#endregion
49
52
  //#region src/lib/acl/Can.tsx
50
- const ContextualCan = createContextualCan(AbilityContext.Consumer);
51
- const Can = ({ use, ...props }) => {
53
+ const Can = ({ use, children, ...props }) => {
52
54
  const [action, subject] = use;
53
- return /* @__PURE__ */ jsx(ContextualCan, {
55
+ return /* @__PURE__ */ jsx(Can$1, {
54
56
  ...props,
55
57
  do: action,
56
- on: subject
58
+ on: subject,
59
+ children: typeof children === "function" ? ({ isAllowed, ability }) => props.passThrough || isAllowed ? children(isAllowed, ability) : null : children
57
60
  });
58
61
  };
59
62
  //#endregion
@@ -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-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,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-DH-fAG0w.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-CRJOgf19.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 };