@povio/openapi-codegen-cli 2.0.8-rc.3 → 2.0.8-rc.31

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 (193) hide show
  1. package/README.md +70 -0
  2. package/dist/acl.d.mts +59 -0
  3. package/dist/acl.mjs +73 -7
  4. package/dist/auth.context-Bu5KW2sI.mjs +59 -0
  5. package/dist/config-KffSntOs.d.mts +6 -0
  6. package/dist/error-handling-CXeVTk1T.d.mts +38 -0
  7. package/dist/error-handling-DkPY7Asf.mjs +187 -0
  8. package/dist/generate.runner-CXsHkwM7.mjs +87 -0
  9. package/dist/generateCodeFromOpenAPIDoc-DkNqNy-S.mjs +4627 -0
  10. package/dist/generator.d.mts +65 -0
  11. package/dist/generator.mjs +144 -0
  12. package/dist/index.d.mts +230 -0
  13. package/dist/index.mjs +251 -24
  14. package/dist/options-D9TC-n26.d.mts +94 -0
  15. package/dist/sh.d.mts +1 -0
  16. package/dist/sh.mjs +448 -0
  17. package/dist/vite.d.mts +11 -0
  18. package/dist/vite.mjs +51 -0
  19. package/dist/zod.d.mts +20 -0
  20. package/dist/zod.mjs +33 -0
  21. package/package.json +54 -47
  22. package/dist/acl.d.ts +0 -4
  23. package/dist/assets/useCrossTabQueryInvalidation.mjs +0 -23
  24. package/dist/assets/useMutationEffects.mjs +0 -56
  25. package/dist/commands/check.command.d.ts +0 -2
  26. package/dist/commands/check.d.ts +0 -7
  27. package/dist/commands/generate.command.d.ts +0 -2
  28. package/dist/commands/generate.d.ts +0 -8
  29. package/dist/generator.d.ts +0 -3
  30. package/dist/generator.js +0 -77
  31. package/dist/generators/checkOpenAPIDoc.d.ts +0 -3
  32. package/dist/generators/const/acl.const.d.ts +0 -13
  33. package/dist/generators/const/buildConfigs.const.d.ts +0 -1
  34. package/dist/generators/const/deps.const.d.ts +0 -38
  35. package/dist/generators/const/endpoints.const.d.ts +0 -11
  36. package/dist/generators/const/js.const.d.ts +0 -1
  37. package/dist/generators/const/openapi.const.d.ts +0 -7
  38. package/dist/generators/const/options.const.d.ts +0 -2
  39. package/dist/generators/const/package.const.d.ts +0 -2
  40. package/dist/generators/const/queries.const.d.ts +0 -8
  41. package/dist/generators/const/validation.const.d.ts +0 -53
  42. package/dist/generators/const/zod.const.d.ts +0 -19
  43. package/dist/generators/core/SchemaResolver.class.d.ts +0 -71
  44. package/dist/generators/core/endpoints/getEndpointAcl.d.ts +0 -8
  45. package/dist/generators/core/endpoints/getEndpointBody.d.ts +0 -13
  46. package/dist/generators/core/endpoints/getEndpointParameter.d.ts +0 -11
  47. package/dist/generators/core/endpoints/getEndpointsFromOpenAPIDoc.d.ts +0 -3
  48. package/dist/generators/core/endpoints/getEndpointsFromOpenAPIDoc.test.d.ts +0 -1
  49. package/dist/generators/core/getDataFromOpenAPIDoc.d.ts +0 -8
  50. package/dist/generators/core/getMetadataFromOpenAPIDoc.d.ts +0 -4
  51. package/dist/generators/core/getMetadataFromOpenAPIDoc.test.d.ts +0 -1
  52. package/dist/generators/core/openapi/getOpenAPISchemaComplexity.d.ts +0 -2
  53. package/dist/generators/core/openapi/getOpenAPISchemaComplexity.test.d.ts +0 -1
  54. package/dist/generators/core/openapi/getOpenAPISchemaDependencyGraph.d.ts +0 -6
  55. package/dist/generators/core/openapi/getOpenAPISchemaDependencyGraph.test.d.ts +0 -1
  56. package/dist/generators/core/openapi/getSchemaRefObjs.d.ts +0 -4
  57. package/dist/generators/core/openapi/iterateSchema.d.ts +0 -22
  58. package/dist/generators/core/resolveConfig.d.ts +0 -7
  59. package/dist/generators/core/zod/ZodSchema.class.d.ts +0 -26
  60. package/dist/generators/core/zod/enumExtraction/resolveExtractedEnumZodSchemaNames.d.ts +0 -2
  61. package/dist/generators/core/zod/enumExtraction/resolveExtractedEnumZodSchemaTags.d.ts +0 -2
  62. package/dist/generators/core/zod/enumExtraction/updateExtractedEnumZodSchemaData.d.ts +0 -17
  63. package/dist/generators/core/zod/getZodChain.d.ts +0 -8
  64. package/dist/generators/core/zod/getZodSchema.d.ts +0 -17
  65. package/dist/generators/core/zod/getZodSchema.test.d.ts +0 -1
  66. package/dist/generators/core/zod/getZodSchemaRefs.d.ts +0 -6
  67. package/dist/generators/core/zod/getZodSchemasFromOpenAPIDoc.d.ts +0 -6
  68. package/dist/generators/core/zod/resolveZodSchemaName.d.ts +0 -10
  69. package/dist/generators/core/zod/sortZodSchemasByTopology.d.ts +0 -4
  70. package/dist/generators/generate/generateAcl.d.ts +0 -3
  71. package/dist/generators/generate/generateAclCheck.d.ts +0 -2
  72. package/dist/generators/generate/generateAppRestClient.d.ts +0 -2
  73. package/dist/generators/generate/generateConfigs.d.ts +0 -2
  74. package/dist/generators/generate/generateEndpoints.d.ts +0 -2
  75. package/dist/generators/generate/generateModels.d.ts +0 -2
  76. package/dist/generators/generate/generateQueries.d.ts +0 -2
  77. package/dist/generators/generate/generateQueryModules.d.ts +0 -2
  78. package/dist/generators/generate/generateZodExtended.d.ts +0 -2
  79. package/dist/generators/generateCodeFromOpenAPIDoc.d.ts +0 -4
  80. package/dist/generators/types/builder-config.d.ts +0 -48
  81. package/dist/generators/types/common.d.ts +0 -27
  82. package/dist/generators/types/config.d.ts +0 -2
  83. package/dist/generators/types/endpoint.d.ts +0 -50
  84. package/dist/generators/types/generate.d.ts +0 -39
  85. package/dist/generators/types/metadata.d.ts +0 -51
  86. package/dist/generators/types/openapi.d.ts +0 -22
  87. package/dist/generators/types/options.d.ts +0 -66
  88. package/dist/generators/types/validation.d.ts +0 -5
  89. package/dist/generators/utils/array.utils.d.ts +0 -1
  90. package/dist/generators/utils/endpoint.utils.d.ts +0 -12
  91. package/dist/generators/utils/endpoint.utils.test.d.ts +0 -1
  92. package/dist/generators/utils/file.utils.d.ts +0 -8
  93. package/dist/generators/utils/generate/generate.acl.utils.d.ts +0 -23
  94. package/dist/generators/utils/generate/generate.configs.utils.d.ts +0 -15
  95. package/dist/generators/utils/generate/generate.endpoints.utils.d.ts +0 -39
  96. package/dist/generators/utils/generate/generate.imports.utils.d.ts +0 -39
  97. package/dist/generators/utils/generate/generate.imports.utils.test.d.ts +0 -1
  98. package/dist/generators/utils/generate/generate.openapi.utils.d.ts +0 -2
  99. package/dist/generators/utils/generate/generate.query.utils.d.ts +0 -6
  100. package/dist/generators/utils/generate/generate.utils.d.ts +0 -18
  101. package/dist/generators/utils/generate/generate.zod.utils.d.ts +0 -13
  102. package/dist/generators/utils/generate-files.utils.d.ts +0 -6
  103. package/dist/generators/utils/hbs/hbs-template.utils.d.ts +0 -3
  104. package/dist/generators/utils/hbs/hbs.acl.utils.d.ts +0 -2
  105. package/dist/generators/utils/hbs/hbs.common.utils.d.ts +0 -1
  106. package/dist/generators/utils/hbs/hbs.endpoints.utils.d.ts +0 -2
  107. package/dist/generators/utils/hbs/hbs.imports.utils.d.ts +0 -1
  108. package/dist/generators/utils/hbs/hbs.partials.utils.d.ts +0 -2
  109. package/dist/generators/utils/hbs/hbs.query.utils.d.ts +0 -2
  110. package/dist/generators/utils/hbs/hbs.zod.utils.d.ts +0 -2
  111. package/dist/generators/utils/js.utils.d.ts +0 -2
  112. package/dist/generators/utils/js.utils.test.d.ts +0 -1
  113. package/dist/generators/utils/math.utils.d.ts +0 -1
  114. package/dist/generators/utils/namespace.utils.d.ts +0 -7
  115. package/dist/generators/utils/object.utils.d.ts +0 -13
  116. package/dist/generators/utils/object.utils.test.d.ts +0 -1
  117. package/dist/generators/utils/openapi-schema.utils.d.ts +0 -15
  118. package/dist/generators/utils/openapi.utils.d.ts +0 -23
  119. package/dist/generators/utils/openapi.utils.test.d.ts +0 -1
  120. package/dist/generators/utils/operation.utils.d.ts +0 -22
  121. package/dist/generators/utils/operation.utils.test.d.ts +0 -1
  122. package/dist/generators/utils/query.utils.d.ts +0 -7
  123. package/dist/generators/utils/sort.utils.d.ts +0 -7
  124. package/dist/generators/utils/string.utils.d.ts +0 -14
  125. package/dist/generators/utils/string.utils.test.d.ts +0 -1
  126. package/dist/generators/utils/tag.utils.d.ts +0 -7
  127. package/dist/generators/utils/ts.utils.d.ts +0 -16
  128. package/dist/generators/utils/validation.utils.d.ts +0 -17
  129. package/dist/generators/utils/zod-schema.utils.d.ts +0 -15
  130. package/dist/helpers/cli.helper.d.ts +0 -22
  131. package/dist/helpers/config.helper.d.ts +0 -3
  132. package/dist/helpers/version.helper.d.ts +0 -4
  133. package/dist/helpers/yargs.helper.d.ts +0 -10
  134. package/dist/index.d.ts +0 -16
  135. package/dist/lib/acl/AclGuard.d.ts +0 -8
  136. package/dist/lib/acl/AclGuard.mjs +0 -14
  137. package/dist/lib/acl/Can.d.ts +0 -9
  138. package/dist/lib/acl/Can.mjs +0 -11
  139. package/dist/lib/acl/ability.context.d.ts +0 -15
  140. package/dist/lib/acl/ability.context.mjs +0 -37
  141. package/dist/lib/acl/appAbility.types.d.ts +0 -3
  142. package/dist/lib/assets/locales/en/translation.json.mjs +0 -8
  143. package/dist/lib/assets/locales/sl/translation.json.mjs +0 -8
  144. package/dist/lib/auth/AuthGuard.d.ts +0 -6
  145. package/dist/lib/auth/AuthGuard.mjs +0 -26
  146. package/dist/lib/auth/auth.context.d.ts +0 -22
  147. package/dist/lib/auth/auth.context.mjs +0 -41
  148. package/dist/lib/config/i18n.d.ts +0 -32
  149. package/dist/lib/config/i18n.mjs +0 -31
  150. package/dist/lib/config/queryConfig.context.d.ts +0 -17
  151. package/dist/lib/config/queryConfig.context.mjs +0 -26
  152. package/dist/lib/config/router.context.d.ts +0 -9
  153. package/dist/lib/config/router.context.mjs +0 -20
  154. package/dist/lib/react-query.types.d.ts +0 -10
  155. package/dist/lib/rest/error-handling.d.ts +0 -30
  156. package/dist/lib/rest/error-handling.mjs +0 -132
  157. package/dist/lib/rest/rest-client.d.ts +0 -22
  158. package/dist/lib/rest/rest-client.mjs +0 -62
  159. package/dist/lib/rest/rest-client.types.d.ts +0 -23
  160. package/dist/lib/rest/rest-interceptor.d.ts +0 -8
  161. package/dist/lib/rest/rest-interceptor.mjs +0 -21
  162. package/dist/lib/rest/rest.utils.d.ts +0 -7
  163. package/dist/lib/rest/rest.utils.mjs +0 -51
  164. package/dist/sh.d.ts +0 -2
  165. package/dist/sh.js +0 -634
  166. package/src/assets/useCrossTabQueryInvalidation.ts +0 -40
  167. package/src/assets/useMutationEffects.ts +0 -89
  168. package/src/generators/templates/acl-check.hbs +0 -29
  169. package/src/generators/templates/acl.hbs +0 -19
  170. package/src/generators/templates/app-acl.hbs +0 -17
  171. package/src/generators/templates/app-rest-client.hbs +0 -7
  172. package/src/generators/templates/configs.hbs +0 -80
  173. package/src/generators/templates/endpoints.hbs +0 -44
  174. package/src/generators/templates/models.hbs +0 -23
  175. package/src/generators/templates/partials/acl-check-call.hbs +0 -1
  176. package/src/generators/templates/partials/casl-ability-function.hbs +0 -12
  177. package/src/generators/templates/partials/casl-ability-query.hbs +0 -1
  178. package/src/generators/templates/partials/casl-ability-type.hbs +0 -1
  179. package/src/generators/templates/partials/columns-config.hbs +0 -11
  180. package/src/generators/templates/partials/endpoint-config.hbs +0 -31
  181. package/src/generators/templates/partials/endpoint-param-parse.hbs +0 -1
  182. package/src/generators/templates/partials/endpoint-params.hbs +0 -1
  183. package/src/generators/templates/partials/import.hbs +0 -1
  184. package/src/generators/templates/partials/inputs-config.hbs +0 -10
  185. package/src/generators/templates/partials/model-js-docs.hbs +0 -6
  186. package/src/generators/templates/partials/query-js-docs.hbs +0 -31
  187. package/src/generators/templates/partials/query-keys.hbs +0 -11
  188. package/src/generators/templates/partials/query-use-infinite-query.hbs +0 -21
  189. package/src/generators/templates/partials/query-use-mutation.hbs +0 -54
  190. package/src/generators/templates/partials/query-use-query.hbs +0 -16
  191. package/src/generators/templates/queries.hbs +0 -54
  192. package/src/generators/templates/query-modules.hbs +0 -9
  193. package/src/generators/templates/zod-extended.hbs +0 -49
package/README.md CHANGED
@@ -69,12 +69,14 @@ yarn openapi-codegen generate --config my-config.ts
69
69
  --config Path to TS config file (default: 'openapi-codegen.config.ts')
70
70
  --input Path/URL to OpenAPI JSON/YAML document
71
71
  --output Output directory path (default: 'output')
72
+ --incremental Skip generation when OpenAPI and config are unchanged (default: true)
72
73
  --format Format the generated code using Oxfmt (default: true)
73
74
  --verbose Display detailed log messages during execution (default: false)
74
75
 
75
76
  --splitByTags Organize output into separate folders based on OpenAPI operation tags (default: true)
76
77
  --defaultTag (Requires `--splitByTags`) Default tag for shared code across multiple tags (default: 'Common')
77
78
 
79
+ --includeTags Comma-separated list of tags to include in generation
78
80
  --excludeTags Comma-separated list of tags to exclude from generation
79
81
  --excludePathRegex Exclude operations whose paths match the given regular expression
80
82
  --excludeRedundantZodSchemas Exclude any redundant Zod schemas (default: true)
@@ -84,11 +86,16 @@ yarn openapi-codegen generate --config my-config.ts
84
86
  --tsPath (Requires `--importPath` to be 'ts') Typescript import path (default: '@/data')
85
87
  --removeOperationPrefixEndingWith Remove operation name prefixes that end with the specified string (default: 'Controller_')
86
88
  --extractEnums Extract enums into separate Zod schemas (default: true)
89
+ --modelsInCommon Keep all schema declarations in defaultTag models and emit per-module proxy exports (default: false)
87
90
  --replaceOptionalWithNullish Replace `.optional()` chains with `.nullish()` in generated Zod schemas (default: false)
88
91
 
89
92
  --axiosRequestConfig Include Axios request config parameters in query hooks (default: false)
90
93
  --infiniteQueries Generate infinite queries for paginated API endpoints (default: false)
91
94
  --mutationEffects Add mutation effects options to mutation hooks (default: true)
95
+ --workspaceContext Allow generated hooks to resolve path/ACL params from OpenApiWorkspaceContext (default: false)
96
+ --inlineEndpoints Inline endpoint implementations into generated query files (default: false)
97
+ --inlineEndpointsExcludeModules Comma-separated modules/tags to keep as separate API files while inlineEndpoints=true
98
+ --modelsOnly Generate only model files (default: false)
92
99
  --parseRequestParams Add Zod parsing to API endpoints (default: true)
93
100
 
94
101
  --acl Generate ACL related files (default: true)
@@ -109,6 +116,7 @@ yarn openapi-codegen generate --config my-config.ts
109
116
  --splitByTags Organize output into separate folders based on OpenAPI operation tags (default: true)
110
117
  --defaultTag (Requires `--splitByTags`) Default tag for shared code across multiple tags (default: 'Common')
111
118
 
119
+ --includeTags Comma-separated list of tags to include in generation
112
120
  --excludeTags Comma-separated list of tags to exclude from generation
113
121
  --excludePathRegex Exclude operations whose paths match the given regular expression
114
122
  --excludeRedundantZodSchemas Exclude any redundant Zod schemas (default: true)
@@ -186,6 +194,68 @@ const config: OpenAPICodegenConfig = {
186
194
  export default config;
187
195
  ```
188
196
 
197
+ ### OpenApiWorkspaceContext (Path + ACL defaults)
198
+
199
+ Enable `workspaceContext: true` in codegen config (or pass `--workspaceContext`) and wrap your app subtree with `OpenApiWorkspaceContext.Provider` if generated hooks frequently repeat workspace-scoped params (for example `officeId`).
200
+
201
+ ```tsx
202
+ import { OpenApiWorkspaceContext } from "@povio/openapi-codegen-cli";
203
+ // openapi-codegen.config.ts -> { workspaceContext: true }
204
+
205
+ <OpenApiWorkspaceContext.Provider values={{ officeId: "office_123" }}>
206
+ <MyWorkspacePages />
207
+ </OpenApiWorkspaceContext.Provider>;
208
+ ```
209
+
210
+ Generated query/mutation hooks can then omit matching path/ACL params and resolve them from `OpenApiWorkspaceContext`.
211
+
212
+ ### Generation Modes
213
+
214
+ You can control whether API endpoint files are emitted, inlined into query files, or skipped entirely.
215
+
216
+ ```ts
217
+ import type { OpenAPICodegenConfig } from "@povio/openapi-codegen-cli";
218
+
219
+ const config: OpenAPICodegenConfig = {
220
+ // 1) Default mode: separate *.api.ts files are generated
221
+ // 2) Inline mode: endpoint logic is generated inside *.queries.ts
222
+ // and can be used without separate api files:
223
+ // inlineEndpoints: true,
224
+ // inlineEndpointsExcludeModules: ["Users", "Billing"],
225
+ // 3) Models-only mode: generate only *.models.ts files
226
+ // modelsOnly: true,
227
+ // 4) Keep all model declarations in common.models and generate per-module model proxies
228
+ // modelsInCommon: true,
229
+ };
230
+ ```
231
+
232
+ ### Vite Plugin
233
+
234
+ You can run codegen directly from Vite config (without CLI config file):
235
+
236
+ ```ts
237
+ import { defineConfig } from "vite";
238
+ import { openApiCodegen } from "@povio/openapi-codegen-cli/vite";
239
+
240
+ export default defineConfig({
241
+ plugins: [
242
+ openApiCodegen({
243
+ input: "./openapi.yaml",
244
+ output: "./src/data",
245
+ inlineEndpoints: true,
246
+ incremental: true,
247
+ formatGeneratedFile: async ({ fileName, content }) => {
248
+ void fileName;
249
+ return content;
250
+ },
251
+ }),
252
+ ],
253
+ });
254
+ ```
255
+
256
+ The plugin runs on both `vite serve` and `vite build`, and watches local OpenAPI files in dev mode.
257
+ If you provide `formatGeneratedFile`, the plugin formats each generated file in memory before comparing and writing it, which helps avoid unnecessary HMR when the formatted output is unchanged.
258
+
189
259
  ### Enums
190
260
 
191
261
  If you're using Enums in your backend DTOs with `@Expose()` and `@IsEnum`, they may still not appear correctly in the OpenAPI schema unless you also provide both `enum` **and** `enumName` to `@ApiProperty`.
package/dist/acl.d.mts ADDED
@@ -0,0 +1,59 @@
1
+ import { r as ErrorHandler } from "./error-handling-CXeVTk1T.mjs";
2
+ import * as react from "react";
3
+ import { PropsWithChildren } from "react";
4
+ import * as react_jsx_runtime0 from "react/jsx-runtime";
5
+ import { AbilityTuple, PureAbility, RawRuleOf, Subject } from "@casl/ability";
6
+ import { PackRule } from "@casl/ability/extra";
7
+ import { BoundCanProps } from "@casl/react";
8
+
9
+ //#region src/lib/acl/appAbility.types.d.ts
10
+ type AppAbilities = AbilityTuple<string, Subject>;
11
+ type AppAbility = PureAbility<AppAbilities>;
12
+ //#endregion
13
+ //#region src/lib/acl/ability.context.d.ts
14
+ declare namespace AbilityContext {
15
+ export const Consumer: react.Consumer<AppAbility>;
16
+ interface ProviderProps {
17
+ user?: {
18
+ aclRules?: PackRule<RawRuleOf<AppAbility>>[];
19
+ } | null;
20
+ }
21
+ export const Provider: ({
22
+ children
23
+ }: PropsWithChildren<ProviderProps>) => react_jsx_runtime0.JSX.Element;
24
+ export const useAbility: <TAppAbilities extends AppAbilities = AppAbilities>() => PureAbility<TAppAbilities>;
25
+ export {};
26
+ }
27
+ //#endregion
28
+ //#region src/lib/acl/AclGuard.d.ts
29
+ interface AclGuardProps<TAppAbilities extends AppAbilities = AppAbilities> {
30
+ canUse: TAppAbilities;
31
+ redirectTo?: string;
32
+ }
33
+ declare const createAclGuard: <TAppAbilities extends AppAbilities = AppAbilities>() => ({
34
+ canUse,
35
+ redirectTo,
36
+ children
37
+ }: PropsWithChildren<AclGuardProps<TAppAbilities>>) => react.ReactNode;
38
+ //#endregion
39
+ //#region src/lib/acl/Can.d.ts
40
+ type CanAbility = PureAbility<AbilityTuple<AppAbilities[0], AppAbilities[1]>>;
41
+ type CanProps<TAppAbilities extends AppAbilities = AppAbilities> = {
42
+ use: TAppAbilities;
43
+ } & 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;
48
+ //#endregion
49
+ //#region src/lib/acl/useAclCheck.d.ts
50
+ interface UseAclCheckProps {
51
+ errorHandler?: ErrorHandler<never>;
52
+ }
53
+ declare function useAclCheck<TAppAbilities extends AppAbilities = AppAbilities>({
54
+ errorHandler
55
+ }?: UseAclCheckProps): {
56
+ checkAcl: (appAbility: TAppAbilities) => void;
57
+ };
58
+ //#endregion
59
+ export { AbilityContext, type AppAbilities, type AppAbility, Can, createAclGuard, useAclCheck };
package/dist/acl.mjs CHANGED
@@ -1,8 +1,74 @@
1
- import { AbilityContext } from "./lib/acl/ability.context.mjs";
2
- import { createAclGuard } from "./lib/acl/AclGuard.mjs";
3
- import { Can } from "./lib/acl/Can.mjs";
4
- export {
5
- AbilityContext,
6
- Can,
7
- createAclGuard
1
+ import { r as SharedErrorHandler } from "./error-handling-DkPY7Asf.mjs";
2
+ import { n as OpenApiRouter, t as AuthContext } from "./auth.context-Bu5KW2sI.mjs";
3
+ import { createContext, useCallback, useEffect, useState } from "react";
4
+ import { jsx } from "react/jsx-runtime";
5
+ import { AbilityBuilder, createMongoAbility } from "@casl/ability";
6
+ import { unpackRules } from "@casl/ability/extra";
7
+ import { createContextualCan, useAbility } from "@casl/react";
8
+
9
+ //#region src/lib/acl/ability.context.tsx
10
+ let AbilityContext;
11
+ (function(_AbilityContext) {
12
+ const createAppAbilityBuilder = () => new AbilityBuilder(createMongoAbility);
13
+ const initialAppAbility = createAppAbilityBuilder().build();
14
+ const Context = createContext({});
15
+ const { Consumer } = Context;
16
+ _AbilityContext.Consumer = Consumer;
17
+ _AbilityContext.Provider = ({ children }) => {
18
+ const [ability, setAbility] = useState(initialAppAbility);
19
+ const { user } = AuthContext.useAuth();
20
+ useEffect(() => {
21
+ if (!user || !("aclRules" in user)) return;
22
+ const { can, build } = createAppAbilityBuilder();
23
+ const packedRules = user.aclRules;
24
+ unpackRules(packedRules).forEach(({ action, subject, conditions }) => {
25
+ can(action, subject, conditions);
26
+ });
27
+ setAbility(build());
28
+ }, [user]);
29
+ return /* @__PURE__ */ jsx(Context.Provider, {
30
+ value: ability,
31
+ children
32
+ });
33
+ };
34
+ _AbilityContext.useAbility = () => {
35
+ return useAbility(Context);
36
+ };
37
+ })(AbilityContext || (AbilityContext = {}));
38
+
39
+ //#endregion
40
+ //#region src/lib/acl/AclGuard.tsx
41
+ const createAclGuard = () => ({ canUse, redirectTo = "/", children }) => {
42
+ const ability = AbilityContext.useAbility();
43
+ const { replace } = OpenApiRouter.useRouter();
44
+ if (!ability.can(canUse[0], canUse[1])) {
45
+ replace(redirectTo);
46
+ return null;
47
+ }
48
+ return children;
8
49
  };
50
+
51
+ //#endregion
52
+ //#region src/lib/acl/Can.tsx
53
+ const ContextualCan = createContextualCan(AbilityContext.Consumer);
54
+ const Can = ({ use, ...props }) => {
55
+ const [action, subject] = use;
56
+ return /* @__PURE__ */ jsx(ContextualCan, {
57
+ ...props,
58
+ do: action,
59
+ on: subject
60
+ });
61
+ };
62
+
63
+ //#endregion
64
+ //#region src/lib/acl/useAclCheck.ts
65
+ function useAclCheck({ errorHandler } = {}) {
66
+ const ability = AbilityContext.useAbility();
67
+ return { checkAcl: useCallback((appAbility) => {
68
+ const [action, subject] = appAbility;
69
+ if (!ability.can(action, subject)) (errorHandler ?? SharedErrorHandler).rethrowError(/* @__PURE__ */ new Error("ACL check failed"));
70
+ }, [ability, errorHandler]) };
71
+ }
72
+
73
+ //#endregion
74
+ export { AbilityContext, Can, createAclGuard, useAclCheck };
@@ -0,0 +1,59 @@
1
+ import { createContext, use, useMemo } from "react";
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
+ //#region src/lib/auth/auth.context.tsx
23
+ let AuthContext;
24
+ (function(_AuthContext) {
25
+ const Context = createContext({});
26
+ _AuthContext.Provider = ({ isAuthenticated, isInitializing, logout, updateTokens, accessToken, user, userPromise, routes, loadingState, children }) => {
27
+ const value = useMemo(() => ({
28
+ isAuthenticated,
29
+ isInitializing,
30
+ logout,
31
+ updateTokens,
32
+ accessToken,
33
+ user,
34
+ userPromise,
35
+ routes,
36
+ loadingState
37
+ }), [
38
+ isAuthenticated,
39
+ isInitializing,
40
+ logout,
41
+ updateTokens,
42
+ accessToken,
43
+ user,
44
+ userPromise,
45
+ routes,
46
+ loadingState
47
+ ]);
48
+ return /* @__PURE__ */ jsx(Context.Provider, {
49
+ value,
50
+ children
51
+ });
52
+ };
53
+ _AuthContext.useAuth = () => {
54
+ return use(Context);
55
+ };
56
+ })(AuthContext || (AuthContext = {}));
57
+
58
+ //#endregion
59
+ export { OpenApiRouter as n, AuthContext as t };
@@ -0,0 +1,6 @@
1
+ import { t as GenerateOptions } from "./options-D9TC-n26.mjs";
2
+
3
+ //#region src/generators/types/config.d.ts
4
+ type OpenAPICodegenConfig = Partial<GenerateOptions>;
5
+ //#endregion
6
+ export { OpenAPICodegenConfig as t };
@@ -0,0 +1,38 @@
1
+ import { TFunction } from "i18next";
2
+
3
+ //#region src/lib/rest/error-handling.d.ts
4
+ type GeneralErrorCodes = "DATA_VALIDATION_ERROR" | "NETWORK_ERROR" | "CANCELED_ERROR" | "INTERNAL_ERROR" | "UNKNOWN_ERROR";
5
+ declare class ApplicationException<CodeT> extends Error {
6
+ code: CodeT;
7
+ serverMessage: string | null;
8
+ constructor(message: string, code: CodeT, serverMessage: string | null);
9
+ }
10
+ interface ErrorEntry<CodeT> {
11
+ code: CodeT;
12
+ condition?: (error: unknown) => boolean;
13
+ getMessage: (t: TFunction, error: unknown) => string;
14
+ }
15
+ interface ErrorHandlerOptions<CodeT extends string> {
16
+ entries: ErrorEntry<CodeT>[];
17
+ t?: TFunction;
18
+ onRethrowError?: (error: unknown, exception: ApplicationException<CodeT | GeneralErrorCodes>) => void;
19
+ }
20
+ declare class ErrorHandler<CodeT extends string> {
21
+ entries: ErrorEntry<CodeT | GeneralErrorCodes>[];
22
+ private t;
23
+ private onRethrowError?;
24
+ constructor({
25
+ entries,
26
+ t,
27
+ onRethrowError
28
+ }: ErrorHandlerOptions<CodeT>);
29
+ private matchesEntry;
30
+ setTranslateFunction(t: TFunction): void;
31
+ rethrowError(error: unknown): ApplicationException<CodeT | GeneralErrorCodes>;
32
+ getError(error: unknown): ApplicationException<CodeT | GeneralErrorCodes> | null;
33
+ getErrorCode(error: unknown): CodeT | GeneralErrorCodes | null;
34
+ static getErrorMessage(error: unknown, fallbackToUnknown?: boolean): string | null;
35
+ }
36
+ declare const SharedErrorHandler: ErrorHandler<never>;
37
+ //#endregion
38
+ export { GeneralErrorCodes as a, ErrorHandlerOptions as i, ErrorEntry as n, SharedErrorHandler as o, ErrorHandler as r, ApplicationException as t };
@@ -0,0 +1,187 @@
1
+ import { isAxiosError, isCancel } from "axios";
2
+ import { z } from "zod";
3
+ import i18next from "i18next";
4
+
5
+ //#region src/lib/assets/locales/en/translation.json
6
+ var translation_default$1 = { openapi: { "sharedErrors": {
7
+ "dataValidation": "An error occurred while validating the data",
8
+ "internalError": "An internal error occurred. This is most likely a bug on our end. Please try again later.",
9
+ "networkError": "A network error occurred. Are you connected to the internet?",
10
+ "canceledError": "The request was canceled.",
11
+ "unknownError": "An unknown error occurred. Please try again later.",
12
+ "unknownErrorWithCode": "An unknown error occurred. Error code: \"{{code}}\""
13
+ } } };
14
+
15
+ //#endregion
16
+ //#region src/lib/assets/locales/sl/translation.json
17
+ var translation_default = { openapi: { "sharedErrors": {
18
+ "dataValidation": "Pri preverjanju podatkov je prišlo do napake",
19
+ "internalError": "Prišlo je do notranje napake.",
20
+ "networkError": "Prišlo je do napake v omrežju.",
21
+ "canceledError": "Zahteva je bila preklicana.",
22
+ "unknownError": "Prišlo je do neznane napake.",
23
+ "unknownErrorWithCode": "Prišlo je do neznane napake. Koda napake: \"{{code}}\""
24
+ } } };
25
+
26
+ //#endregion
27
+ //#region src/lib/config/i18n.ts
28
+ const ns = "openapi";
29
+ const resources = {
30
+ en: { [ns]: translation_default$1 },
31
+ sl: { [ns]: translation_default }
32
+ };
33
+ const defaultLanguage = "en";
34
+ const i18n = i18next.createInstance();
35
+ i18n.init({
36
+ compatibilityJSON: "v4",
37
+ lng: defaultLanguage,
38
+ fallbackLng: defaultLanguage,
39
+ resources,
40
+ ns: Object.keys(resources.en),
41
+ defaultNS: ns,
42
+ interpolation: { escapeValue: false }
43
+ });
44
+ const defaultT = i18n.t.bind(i18n);
45
+
46
+ //#endregion
47
+ //#region src/lib/rest/rest.utils.ts
48
+ let RestUtils;
49
+ (function(_RestUtils) {
50
+ _RestUtils.extractServerResponseCode = (e) => {
51
+ if (e instanceof z.ZodError) return "validation-exception";
52
+ if (!isAxiosError(e)) return null;
53
+ if (!e.response) return null;
54
+ const data = e.response.data;
55
+ if (typeof data?.code === "string") return data.code;
56
+ return null;
57
+ };
58
+ _RestUtils.doesServerErrorMessageContain = (e, text) => {
59
+ const message = extractServerErrorMessage(e);
60
+ if (message === null || message === void 0) return false;
61
+ return message.toLowerCase().includes(text.toLowerCase());
62
+ };
63
+ const extractServerErrorMessage = _RestUtils.extractServerErrorMessage = (e) => {
64
+ if (e instanceof z.ZodError) return e.message;
65
+ if (!isAxiosError(e)) return null;
66
+ if (!e.response) return null;
67
+ const data = e.response.data;
68
+ if (typeof data?.message === "string") return data.message;
69
+ return null;
70
+ };
71
+ _RestUtils.extractContentDispositionFilename = (headers) => {
72
+ const contentDisposition = headers["content-disposition"];
73
+ return contentDisposition ? /filename=["']?([^"';]+)/i.exec(contentDisposition)?.[1] : void 0;
74
+ };
75
+ })(RestUtils || (RestUtils = {}));
76
+
77
+ //#endregion
78
+ //#region src/lib/rest/error-handling.ts
79
+ var ApplicationException = class extends Error {
80
+ code;
81
+ serverMessage = null;
82
+ constructor(message, code, serverMessage) {
83
+ super(message);
84
+ this.code = code;
85
+ this.serverMessage = serverMessage;
86
+ }
87
+ };
88
+ var ErrorHandler = class {
89
+ entries = [];
90
+ t;
91
+ onRethrowError;
92
+ constructor({ entries, t = defaultT, onRethrowError }) {
93
+ this.t = t;
94
+ this.onRethrowError = onRethrowError;
95
+ const dataValidationError = {
96
+ code: "DATA_VALIDATION_ERROR",
97
+ condition: (e) => {
98
+ return e instanceof z.ZodError;
99
+ },
100
+ getMessage: () => this.t("openapi.sharedErrors.dataValidation")
101
+ };
102
+ const internalError = {
103
+ code: "INTERNAL_ERROR",
104
+ condition: (e) => {
105
+ if (isAxiosError(e)) return e.response?.status != null && e.response.status >= 500 && e.response.status < 600;
106
+ return false;
107
+ },
108
+ getMessage: () => this.t("openapi.sharedErrors.internalError")
109
+ };
110
+ const networkError = {
111
+ code: "NETWORK_ERROR",
112
+ condition: (e) => {
113
+ if (isAxiosError(e)) return e.code === "ERR_NETWORK";
114
+ return false;
115
+ },
116
+ getMessage: () => this.t("openapi.sharedErrors.networkError")
117
+ };
118
+ const canceledError = {
119
+ code: "CANCELED_ERROR",
120
+ condition: (e) => {
121
+ if (isCancel(e)) return true;
122
+ if (isAxiosError(e) && e.code === "ECONNABORTED") return true;
123
+ return false;
124
+ },
125
+ getMessage: () => this.t("openapi.sharedErrors.canceledError")
126
+ };
127
+ const unknownError = {
128
+ code: "UNKNOWN_ERROR",
129
+ condition: () => true,
130
+ getMessage: (_, e) => {
131
+ const code = RestUtils.extractServerResponseCode(e);
132
+ const serverMessage = RestUtils.extractServerErrorMessage(e);
133
+ if (code) {
134
+ let message = `Unknown error, message from server: ${code}`;
135
+ if (serverMessage) message += ` ${serverMessage}`;
136
+ return message;
137
+ }
138
+ return this.t("openapi.sharedErrors.unknownError");
139
+ }
140
+ };
141
+ this.entries = [
142
+ ...entries,
143
+ dataValidationError,
144
+ internalError,
145
+ networkError,
146
+ canceledError,
147
+ unknownError
148
+ ];
149
+ }
150
+ matchesEntry(error, entry, code) {
151
+ if (entry.condition) return entry.condition(error);
152
+ return code === entry.code;
153
+ }
154
+ setTranslateFunction(t) {
155
+ this.t = t;
156
+ }
157
+ rethrowError(error) {
158
+ const code = RestUtils.extractServerResponseCode(error);
159
+ const errorEntry = this.entries.find((entry) => this.matchesEntry(error, entry, code));
160
+ const serverMessage = RestUtils.extractServerErrorMessage(error);
161
+ const exception = new ApplicationException(errorEntry.getMessage(this.t, error), errorEntry.code, serverMessage);
162
+ this.onRethrowError?.(error, exception);
163
+ throw exception;
164
+ }
165
+ getError(error) {
166
+ if (error instanceof ApplicationException) return error;
167
+ return null;
168
+ }
169
+ getErrorCode(error) {
170
+ if (error instanceof ApplicationException) return error.code;
171
+ return null;
172
+ }
173
+ static getErrorMessage(error, fallbackToUnknown = true) {
174
+ if (typeof error === "string") return error;
175
+ if (error instanceof Error) return error.message;
176
+ if (error instanceof ApplicationException) {
177
+ if (error.serverMessage != null) return error.serverMessage;
178
+ return error.message;
179
+ }
180
+ if (fallbackToUnknown) return defaultT("openapi.sharedErrors.unknownError");
181
+ return null;
182
+ }
183
+ };
184
+ const SharedErrorHandler = new ErrorHandler({ entries: [] });
185
+
186
+ //#endregion
187
+ export { ns as a, RestUtils as i, ErrorHandler as n, resources as o, SharedErrorHandler as r, ApplicationException as t };
@@ -0,0 +1,87 @@
1
+ import { a as deepMerge, p as DEFAULT_GENERATE_OPTIONS, r as writeGenerateFileData, t as generateCodeFromOpenAPIDoc, x as Profiler } from "./generateCodeFromOpenAPIDoc-DkNqNy-S.mjs";
2
+ import fs from "fs";
3
+ import SwaggerParser from "@apidevtools/swagger-parser";
4
+
5
+ //#region src/generators/core/resolveConfig.ts
6
+ function resolveConfig({ fileConfig = {}, params: { includeTags, excludeTags, inlineEndpointsExcludeModules, ...options } }) {
7
+ const resolvedConfig = deepMerge(DEFAULT_GENERATE_OPTIONS, fileConfig ?? {}, {
8
+ ...options,
9
+ includeTags: includeTags?.split(","),
10
+ excludeTags: excludeTags?.split(","),
11
+ inlineEndpointsExcludeModules: inlineEndpointsExcludeModules?.split(",")
12
+ });
13
+ resolvedConfig.checkAcl = resolvedConfig.acl && resolvedConfig.checkAcl;
14
+ return resolvedConfig;
15
+ }
16
+
17
+ //#endregion
18
+ //#region src/generators/run/generate.runner.ts
19
+ async function runGenerate({ fileConfig, params, formatGeneratedFile, profiler = new Profiler(process.env.OPENAPI_CODEGEN_PROFILE === "1") }) {
20
+ const config = profiler.runSync("config.resolve", () => resolveConfig({
21
+ fileConfig,
22
+ params: params ?? {}
23
+ }));
24
+ const openApiDoc = await getOpenApiDoc(config.input, profiler);
25
+ const filesData = profiler.runSync("generate.total", () => generateCodeFromOpenAPIDoc(openApiDoc, config, profiler));
26
+ if (config.clearOutput) profiler.runSync("files.clearOutput", () => {
27
+ fs.rmSync(config.output, {
28
+ force: true,
29
+ recursive: true
30
+ });
31
+ });
32
+ await profiler.runAsync("files.write", async () => {
33
+ await writeGenerateFileData(filesData, { formatGeneratedFile });
34
+ });
35
+ return {
36
+ skipped: false,
37
+ config,
38
+ stats: getGenerateStats(filesData, config)
39
+ };
40
+ }
41
+ async function getOpenApiDoc(input, profiler) {
42
+ const parsedDoc = await profiler.runAsync("openapi.parse", async () => await SwaggerParser.parse(input));
43
+ if (!profiler.runSync("openapi.detectExternalRefs", () => hasExternalRef(parsedDoc))) return parsedDoc;
44
+ return await profiler.runAsync("openapi.bundle", async () => await SwaggerParser.bundle(input));
45
+ }
46
+ function hasExternalRef(value) {
47
+ const stack = [value];
48
+ const visited = /* @__PURE__ */ new Set();
49
+ while (stack.length > 0) {
50
+ const current = stack.pop();
51
+ if (!current || typeof current !== "object") continue;
52
+ if (visited.has(current)) continue;
53
+ visited.add(current);
54
+ if ("$ref" in current && typeof current.$ref === "string" && !current.$ref.startsWith("#/")) return true;
55
+ for (const nested of Object.values(current)) if (nested && typeof nested === "object") stack.push(nested);
56
+ }
57
+ return false;
58
+ }
59
+ function getGenerateStats(filesData, config) {
60
+ const generatedFilesCount = filesData.length;
61
+ if (generatedFilesCount === 0) return {
62
+ generatedFilesCount,
63
+ generatedModulesCount: 0
64
+ };
65
+ if (!config.splitByTags) return {
66
+ generatedFilesCount,
67
+ generatedModulesCount: 1
68
+ };
69
+ const moduleSuffixes = new Set(Object.values(config.configs).map((generateConfig) => generateConfig.outputFileNameSuffix).filter(Boolean));
70
+ const modules = /* @__PURE__ */ new Set();
71
+ for (const file of filesData) {
72
+ const segments = path.relative(config.output, file.fileName).split(path.sep).filter(Boolean);
73
+ if (segments.length < 2) continue;
74
+ const moduleName = segments[0];
75
+ const fileName = segments[segments.length - 1];
76
+ if (!fileName.startsWith(`${moduleName}.`)) continue;
77
+ const suffix = fileName.slice(moduleName.length + 1).replace(/\.tsx?$/, "");
78
+ if (moduleSuffixes.has(suffix)) modules.add(moduleName);
79
+ }
80
+ return {
81
+ generatedFilesCount,
82
+ generatedModulesCount: modules.size
83
+ };
84
+ }
85
+
86
+ //#endregion
87
+ export { resolveConfig as n, runGenerate as t };