@povio/openapi-codegen-cli 2.0.8-rc.37 → 2.0.8-rc.39

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 (191) hide show
  1. package/README.md +0 -87
  2. package/dist/acl.d.ts +4 -0
  3. package/dist/acl.mjs +7 -73
  4. package/dist/commands/check.command.d.ts +2 -0
  5. package/dist/commands/check.d.ts +7 -0
  6. package/dist/commands/generate.command.d.ts +2 -0
  7. package/dist/commands/generate.d.ts +8 -0
  8. package/dist/generator.d.ts +3 -0
  9. package/dist/generator.js +78 -0
  10. package/dist/generators/checkOpenAPIDoc.d.ts +3 -0
  11. package/dist/generators/const/acl.const.d.ts +13 -0
  12. package/dist/generators/const/buildConfigs.const.d.ts +1 -0
  13. package/dist/generators/const/deps.const.d.ts +38 -0
  14. package/dist/generators/const/endpoints.const.d.ts +11 -0
  15. package/dist/generators/const/js.const.d.ts +1 -0
  16. package/dist/generators/const/openapi.const.d.ts +7 -0
  17. package/dist/generators/const/options.const.d.ts +2 -0
  18. package/dist/generators/const/package.const.d.ts +2 -0
  19. package/dist/generators/const/queries.const.d.ts +8 -0
  20. package/dist/generators/const/validation.const.d.ts +53 -0
  21. package/dist/generators/const/zod.const.d.ts +19 -0
  22. package/dist/generators/core/SchemaResolver.class.d.ts +71 -0
  23. package/dist/generators/core/endpoints/getEndpointAcl.d.ts +8 -0
  24. package/dist/generators/core/endpoints/getEndpointBody.d.ts +13 -0
  25. package/dist/generators/core/endpoints/getEndpointParameter.d.ts +11 -0
  26. package/dist/generators/core/endpoints/getEndpointsFromOpenAPIDoc.d.ts +3 -0
  27. package/dist/generators/core/endpoints/getEndpointsFromOpenAPIDoc.test.d.ts +1 -0
  28. package/dist/generators/core/getDataFromOpenAPIDoc.d.ts +8 -0
  29. package/dist/generators/core/getMetadataFromOpenAPIDoc.d.ts +4 -0
  30. package/dist/generators/core/getMetadataFromOpenAPIDoc.test.d.ts +1 -0
  31. package/dist/generators/core/openapi/getOpenAPISchemaComplexity.d.ts +2 -0
  32. package/dist/generators/core/openapi/getOpenAPISchemaComplexity.test.d.ts +1 -0
  33. package/dist/generators/core/openapi/getOpenAPISchemaDependencyGraph.d.ts +6 -0
  34. package/dist/generators/core/openapi/getOpenAPISchemaDependencyGraph.test.d.ts +1 -0
  35. package/dist/generators/core/openapi/getSchemaRefObjs.d.ts +4 -0
  36. package/dist/generators/core/openapi/iterateSchema.d.ts +22 -0
  37. package/dist/generators/core/resolveConfig.d.ts +7 -0
  38. package/dist/generators/core/zod/ZodSchema.class.d.ts +26 -0
  39. package/dist/generators/core/zod/enumExtraction/resolveExtractedEnumZodSchemaNames.d.ts +2 -0
  40. package/dist/generators/core/zod/enumExtraction/resolveExtractedEnumZodSchemaTags.d.ts +2 -0
  41. package/dist/generators/core/zod/enumExtraction/updateExtractedEnumZodSchemaData.d.ts +17 -0
  42. package/dist/generators/core/zod/getZodChain.d.ts +8 -0
  43. package/dist/generators/core/zod/getZodSchema.d.ts +17 -0
  44. package/dist/generators/core/zod/getZodSchema.test.d.ts +1 -0
  45. package/dist/generators/core/zod/getZodSchemaRefs.d.ts +6 -0
  46. package/dist/generators/core/zod/getZodSchemasFromOpenAPIDoc.d.ts +6 -0
  47. package/dist/generators/core/zod/resolveZodSchemaName.d.ts +10 -0
  48. package/dist/generators/core/zod/sortZodSchemasByTopology.d.ts +4 -0
  49. package/dist/generators/generate/generateAcl.d.ts +3 -0
  50. package/dist/generators/generate/generateAclCheck.d.ts +2 -0
  51. package/dist/generators/generate/generateAppRestClient.d.ts +2 -0
  52. package/dist/generators/generate/generateConfigs.d.ts +2 -0
  53. package/dist/generators/generate/generateEndpoints.d.ts +2 -0
  54. package/dist/generators/generate/generateModels.d.ts +2 -0
  55. package/dist/generators/generate/generateQueries.d.ts +2 -0
  56. package/dist/generators/generate/generateQueryModules.d.ts +2 -0
  57. package/dist/generators/generate/generateZodExtended.d.ts +2 -0
  58. package/dist/generators/generateCodeFromOpenAPIDoc.d.ts +4 -0
  59. package/dist/generators/types/builder-config.d.ts +48 -0
  60. package/dist/generators/types/common.d.ts +27 -0
  61. package/dist/generators/types/config.d.ts +2 -0
  62. package/dist/generators/types/endpoint.d.ts +50 -0
  63. package/dist/generators/types/generate.d.ts +39 -0
  64. package/dist/generators/types/metadata.d.ts +51 -0
  65. package/dist/generators/types/openapi.d.ts +22 -0
  66. package/dist/generators/types/options.d.ts +66 -0
  67. package/dist/generators/types/validation.d.ts +5 -0
  68. package/dist/generators/utils/array.utils.d.ts +1 -0
  69. package/dist/generators/utils/endpoint.utils.d.ts +12 -0
  70. package/dist/generators/utils/endpoint.utils.test.d.ts +1 -0
  71. package/dist/generators/utils/file.utils.d.ts +8 -0
  72. package/dist/generators/utils/generate/generate.acl.utils.d.ts +23 -0
  73. package/dist/generators/utils/generate/generate.configs.utils.d.ts +15 -0
  74. package/dist/generators/utils/generate/generate.endpoints.utils.d.ts +41 -0
  75. package/dist/generators/utils/generate/generate.imports.utils.d.ts +39 -0
  76. package/dist/generators/utils/generate/generate.imports.utils.test.d.ts +1 -0
  77. package/dist/generators/utils/generate/generate.openapi.utils.d.ts +2 -0
  78. package/dist/generators/utils/generate/generate.query.utils.d.ts +6 -0
  79. package/dist/generators/utils/generate/generate.utils.d.ts +18 -0
  80. package/dist/generators/utils/generate/generate.zod.utils.d.ts +13 -0
  81. package/dist/generators/utils/generate-files.utils.d.ts +6 -0
  82. package/dist/generators/utils/hbs/hbs-template.utils.d.ts +3 -0
  83. package/dist/generators/utils/hbs/hbs.acl.utils.d.ts +2 -0
  84. package/dist/generators/utils/hbs/hbs.common.utils.d.ts +1 -0
  85. package/dist/generators/utils/hbs/hbs.endpoints.utils.d.ts +2 -0
  86. package/dist/generators/utils/hbs/hbs.imports.utils.d.ts +1 -0
  87. package/dist/generators/utils/hbs/hbs.partials.utils.d.ts +2 -0
  88. package/dist/generators/utils/hbs/hbs.query.utils.d.ts +2 -0
  89. package/dist/generators/utils/hbs/hbs.zod.utils.d.ts +2 -0
  90. package/dist/generators/utils/js.utils.d.ts +2 -0
  91. package/dist/generators/utils/js.utils.test.d.ts +1 -0
  92. package/dist/generators/utils/math.utils.d.ts +1 -0
  93. package/dist/generators/utils/namespace.utils.d.ts +7 -0
  94. package/dist/generators/utils/object.utils.d.ts +13 -0
  95. package/dist/generators/utils/object.utils.test.d.ts +1 -0
  96. package/dist/generators/utils/openapi-schema.utils.d.ts +15 -0
  97. package/dist/generators/utils/openapi.utils.d.ts +23 -0
  98. package/dist/generators/utils/openapi.utils.test.d.ts +1 -0
  99. package/dist/generators/utils/operation.utils.d.ts +22 -0
  100. package/dist/generators/utils/operation.utils.test.d.ts +1 -0
  101. package/dist/generators/utils/query.utils.d.ts +7 -0
  102. package/dist/generators/utils/sort.utils.d.ts +7 -0
  103. package/dist/generators/utils/string.utils.d.ts +14 -0
  104. package/dist/generators/utils/string.utils.test.d.ts +1 -0
  105. package/dist/generators/utils/tag.utils.d.ts +7 -0
  106. package/dist/generators/utils/ts.utils.d.ts +16 -0
  107. package/dist/generators/utils/validation.utils.d.ts +17 -0
  108. package/dist/generators/utils/zod-schema.utils.d.ts +15 -0
  109. package/dist/helpers/cli.helper.d.ts +22 -0
  110. package/dist/helpers/config.helper.d.ts +3 -0
  111. package/dist/helpers/version.helper.d.ts +4 -0
  112. package/dist/helpers/yargs.helper.d.ts +10 -0
  113. package/dist/index.d.ts +15 -0
  114. package/dist/index.mjs +22 -252
  115. package/dist/lib/acl/AclGuard.d.ts +8 -0
  116. package/dist/lib/acl/AclGuard.mjs +14 -0
  117. package/dist/lib/acl/Can.d.ts +9 -0
  118. package/dist/lib/acl/Can.mjs +11 -0
  119. package/dist/lib/acl/ability.context.d.ts +15 -0
  120. package/dist/lib/acl/ability.context.mjs +37 -0
  121. package/dist/lib/acl/appAbility.types.d.ts +3 -0
  122. package/dist/lib/assets/locales/en/translation.json.mjs +8 -0
  123. package/dist/lib/assets/locales/sl/translation.json.mjs +8 -0
  124. package/dist/lib/auth/AuthGuard.d.ts +6 -0
  125. package/dist/lib/auth/AuthGuard.mjs +26 -0
  126. package/dist/lib/auth/auth.context.d.ts +22 -0
  127. package/dist/lib/auth/auth.context.mjs +41 -0
  128. package/dist/lib/config/i18n.d.ts +32 -0
  129. package/dist/lib/config/i18n.mjs +31 -0
  130. package/dist/lib/config/queryConfig.context.d.ts +17 -0
  131. package/dist/lib/config/queryConfig.context.mjs +26 -0
  132. package/dist/lib/config/router.context.d.ts +9 -0
  133. package/dist/lib/config/router.context.mjs +20 -0
  134. package/dist/lib/react-query.types.d.ts +10 -0
  135. package/dist/lib/rest/error-handling.d.ts +30 -0
  136. package/dist/lib/rest/error-handling.mjs +132 -0
  137. package/dist/lib/rest/rest-client.d.ts +22 -0
  138. package/dist/lib/rest/rest-client.mjs +62 -0
  139. package/dist/lib/rest/rest-client.types.d.ts +23 -0
  140. package/dist/lib/rest/rest-interceptor.d.ts +8 -0
  141. package/dist/lib/rest/rest-interceptor.mjs +21 -0
  142. package/dist/lib/rest/rest.utils.d.ts +7 -0
  143. package/dist/lib/rest/rest.utils.mjs +51 -0
  144. package/dist/sh.d.ts +2 -0
  145. package/dist/sh.js +649 -0
  146. package/package.json +43 -51
  147. package/src/assets/useCrossTabQueryInvalidation.ts +40 -0
  148. package/src/assets/useMutationEffects.ts +94 -0
  149. package/src/generators/templates/acl-check.hbs +29 -0
  150. package/src/generators/templates/acl.hbs +19 -0
  151. package/src/generators/templates/app-acl.hbs +17 -0
  152. package/src/generators/templates/app-rest-client.hbs +7 -0
  153. package/src/generators/templates/configs.hbs +80 -0
  154. package/src/generators/templates/endpoints.hbs +44 -0
  155. package/src/generators/templates/models.hbs +23 -0
  156. package/src/generators/templates/partials/acl-check-call.hbs +1 -0
  157. package/src/generators/templates/partials/casl-ability-function.hbs +12 -0
  158. package/src/generators/templates/partials/casl-ability-query.hbs +1 -0
  159. package/src/generators/templates/partials/casl-ability-type.hbs +1 -0
  160. package/src/generators/templates/partials/columns-config.hbs +11 -0
  161. package/src/generators/templates/partials/endpoint-config.hbs +31 -0
  162. package/src/generators/templates/partials/endpoint-param-parse.hbs +1 -0
  163. package/src/generators/templates/partials/endpoint-params.hbs +1 -0
  164. package/src/generators/templates/partials/import.hbs +1 -0
  165. package/src/generators/templates/partials/inputs-config.hbs +10 -0
  166. package/src/generators/templates/partials/model-js-docs.hbs +6 -0
  167. package/src/generators/templates/partials/query-js-docs.hbs +31 -0
  168. package/src/generators/templates/partials/query-keys.hbs +11 -0
  169. package/src/generators/templates/partials/query-use-infinite-query.hbs +22 -0
  170. package/src/generators/templates/partials/query-use-mutation.hbs +54 -0
  171. package/src/generators/templates/partials/query-use-query.hbs +17 -0
  172. package/src/generators/templates/queries.hbs +54 -0
  173. package/src/generators/templates/query-modules.hbs +5 -0
  174. package/src/generators/templates/zod-extended.hbs +49 -0
  175. package/dist/acl.d.mts +0 -59
  176. package/dist/auth.context-Bu5KW2sI.mjs +0 -59
  177. package/dist/config-DTx4Ck6g.d.mts +0 -6
  178. package/dist/error-handling-CXeVTk1T.d.mts +0 -38
  179. package/dist/error-handling-DkPY7Asf.mjs +0 -187
  180. package/dist/generate.runner-DLLGYMVB.mjs +0 -90
  181. package/dist/generateCodeFromOpenAPIDoc-CFbiHxB7.mjs +0 -4729
  182. package/dist/generator.d.mts +0 -65
  183. package/dist/generator.mjs +0 -144
  184. package/dist/index.d.mts +0 -231
  185. package/dist/options-fyt0BYYE.d.mts +0 -95
  186. package/dist/sh.d.mts +0 -1
  187. package/dist/sh.mjs +0 -450
  188. package/dist/vite.d.mts +0 -11
  189. package/dist/vite.mjs +0 -53
  190. package/dist/zod.d.mts +0 -20
  191. package/dist/zod.mjs +0 -33
@@ -0,0 +1,11 @@
1
+ export const keys = {
2
+ all: [{{queriesModuleName}}] as const,
3
+ {{#each queryEndpoints as | endpoint |}}
4
+ {{endpointName endpoint}}: ({{{genEndpointParams endpoint pathParamsRequiredOnly=true}}}) => [...keys.all, "{{endpoint.path}}", {{{endpointArgs endpoint}}}] as const,
5
+ {{#if ../generateInfiniteQueries}}
6
+ {{#if (isInfiniteQuery endpoint)}}
7
+ {{endpointName endpoint}}Infinite: ({{{genEndpointParams endpoint excludePageParam=true pathParamsRequiredOnly=true}}}) => [...keys.all, "{{endpoint.path}}", "infinite", {{{endpointArgs endpoint excludePageParam=true}}}] as const,
8
+ {{/if}}
9
+ {{/if}}
10
+ {{/each}}
11
+ };
@@ -0,0 +1,22 @@
1
+ {{! Js docs }}
2
+ {{{genQueryJsDocs endpoint infiniteQuery=true}}}
3
+ {{! Infinite query definition}}
4
+ export const {{infiniteQueryName endpoint}} = <TData>({{#if (endpointParams endpoint)}}{{#if (endpointParamsAllOptional endpoint excludePageParam=true)}}params: { {{{genEndpointParams endpoint excludePageParam=true}}} } = {}{{else}}{ {{{endpointArgs endpoint excludePageParam=true}}} }: { {{{genEndpointParams endpoint excludePageParam=true}}} }{{/if}}, {{/if}}options?: AppInfiniteQueryOptions<typeof {{importedEndpointName endpoint}}, TData>{{#if hasAxiosRequestConfig}}, {{axiosRequestConfigName}}?: {{axiosRequestConfigType}}{{/if}}) => {
5
+ {{! Use acl check }}
6
+ {{#if hasAclCheck}}const { checkAcl } = {{aclCheckHook}}();{{/if}}
7
+ {{#if (endpointParams endpoint)}}{{#if (endpointParamsAllOptional endpoint excludePageParam=true)}}const { {{{endpointArgs endpoint excludePageParam=true}}} } = params;{{/if}}{{/if}}
8
+
9
+ return {{infiniteQueryHook}}({
10
+ queryKey: keys.{{endpointName endpoint}}Infinite({{#if (endpointParams endpoint)}}{{{endpointArgs endpoint excludePageParam=true}}}{{/if}}),
11
+ queryFn: ({ pageParam }) => {{#if hasQueryFnBody}}{ {{/if}}
12
+ {{#if hasAclCheck}}{{{genAclCheckCall endpoint}}}{{/if}}
13
+ {{#if hasQueryFnBody}}return {{/if}}{{importedEndpointName endpoint}}({{{endpointArgs endpoint replacePageParam=true}}}{{#if hasAxiosRequestConfig}}, {{axiosRequestConfigName}}{{/if}})
14
+ {{#if hasQueryFnBody}} }{{/if}},
15
+ initialPageParam: 1,
16
+ getNextPageParam: ({ {{pageParamName}}, {{totalItemsName}}, {{limitParamName}}: limitParam }) => {
17
+ const pageParam = {{pageParamName}} ?? 1;
18
+ return pageParam * limitParam < {{totalItemsName}} ? pageParam + 1 : null;
19
+ },
20
+ ...options,
21
+ });
22
+ };
@@ -0,0 +1,54 @@
1
+ {{! Js docs }}
2
+ {{{genQueryJsDocs endpoint mutation=true}}}
3
+ {{! Mutation definition}}
4
+ export const {{queryName endpoint mutation=true}} = (options?: AppMutationOptions<typeof {{importedEndpointName endpoint}}, { {{{genEndpointParams endpoint includeFileParam=true}}}{{#if endpoint.mediaUpload}} abortController?: AbortController, onUploadProgress?: (progress: { loaded: number; total: number }) => void{{/if}} }>{{#if hasMutationEffects}} & {{mutationEffectsType}}{{/if}}{{#if hasAxiosRequestConfig}}, {{axiosRequestConfigName}}?: {{axiosRequestConfigType}}{{/if}}) => {
5
+ {{! Use acl check }}
6
+ {{#if hasAclCheck}}const { checkAcl } = {{aclCheckHook}}();{{/if}}
7
+ {{! Use mutation effects }}
8
+ {{#if hasMutationEffects}}const { runMutationEffects } = useMutationEffects({ currentModule: {{queriesModuleName}} });{{/if}}
9
+
10
+ return {{queryHook}}({
11
+ mutationFn: {{#if endpoint.mediaUpload}}async {{/if}}({{#if (endpointParams endpoint includeFileParam=true)}} { {{{endpointArgs endpoint includeFileParam=true}}}{{#if endpoint.mediaUpload}}, abortController, onUploadProgress{{/if}} } {{/if}}) => {{#if hasMutationFnBody}} { {{/if}}
12
+ {{#if hasAclCheck}}{{{genAclCheckCall endpoint}}}{{/if}}
13
+ {{#if endpoint.mediaUpload}}const uploadInstructions = await {{importedEndpointName endpoint}}({{{endpointArgs endpoint}}}{{#if hasAxiosRequestConfig}}{{#if (endpointArgs endpoint)}}, {{/if}}{{axiosRequestConfigName}}{{/if}});
14
+
15
+ if (file && uploadInstructions.url) {
16
+ const method = (data?.method?.toLowerCase() ?? "put") as 'put' | 'post';
17
+ let dataToSend: File | FormData = file;
18
+ if (method === "post") {
19
+ dataToSend = new FormData();
20
+ if (uploadInstructions.fields) {
21
+ for (const [key, value] of uploadInstructions.fields) {
22
+ dataToSend.append(key, value);
23
+ }
24
+ }
25
+ dataToSend.append('file', file);
26
+ }
27
+ await axios[method](uploadInstructions.url, dataToSend, {
28
+ headers: {
29
+ "Content-Type": file.type,
30
+ },
31
+ signal: abortController?.signal,
32
+ onUploadProgress: onUploadProgress
33
+ ? (progressEvent) => onUploadProgress({ loaded: progressEvent.loaded, total: progressEvent.total ?? 0 })
34
+ : undefined,
35
+ });
36
+ }
37
+
38
+ return uploadInstructions;
39
+ {{else}}
40
+ {{#if hasMutationFnBody}}return {{/if}}{{importedEndpointName endpoint}}({{{endpointArgs endpoint}}}{{#if hasAxiosRequestConfig}}{{#if (endpointArgs endpoint)}}, {{/if}}{{axiosRequestConfigName}}{{/if}})
41
+ {{/if}}
42
+ {{#if hasMutationFnBody}} }{{/if}},
43
+ ...options, {{#if hasMutationEffects}}
44
+ onSuccess: async (resData, variables, onMutateResult, context) => {
45
+ {{! Mutation effects }}
46
+ {{#if updateQueryEndpoints}}
47
+ {{#if destructuredVariables}}const { {{commaSeparated destructuredVariables }} } = variables;{{/if}}
48
+ const updateKeys = [{{#each updateQueryEndpoints as | endpoint |}}keys.{{endpointName endpoint}}({{{endpointArgs endpoint includeOnlyRequiredParams=true}}}), {{/each}}];
49
+ {{/if}}
50
+ await runMutationEffects(resData, variables, options{{#if updateQueryEndpoints}}, updateKeys{{/if}});
51
+ options?.onSuccess?.(resData, variables, onMutateResult, context);
52
+ },{{/if}}
53
+ });
54
+ };
@@ -0,0 +1,17 @@
1
+ {{! Js docs }}
2
+ {{{genQueryJsDocs endpoint query=true}}}
3
+ {{! Query definition}}
4
+ export const {{queryName endpoint}} = <TData>({{#if (endpointParams endpoint)}}{{#if (endpointParamsAllOptional endpoint)}}params: { {{{genEndpointParams endpoint}}} } = {}{{else}}{ {{{endpointArgs endpoint}}} }: { {{{genEndpointParams endpoint}}} }{{/if}}, {{/if}}options?: AppQueryOptions<typeof {{importedEndpointName endpoint}}, TData>{{#if hasAxiosRequestConfig}}, {{axiosRequestConfigName}}?: {{axiosRequestConfigType}}{{/if}}) => {
5
+ {{! Use acl check }}
6
+ {{#if hasAclCheck}}const { checkAcl } = {{aclCheckHook}}();{{/if}}
7
+ {{#if (endpointParams endpoint)}}{{#if (endpointParamsAllOptional endpoint)}}const { {{{endpointArgs endpoint}}} } = params;{{/if}}{{/if}}
8
+
9
+ return {{queryHook}}({
10
+ queryKey: keys.{{endpointName endpoint}}({{#if (endpointParams endpoint)}}{{{endpointArgs endpoint}}}{{/if}}),
11
+ queryFn: {{#if hasQueryFn}}() => {{#if hasQueryFnBody}}{ {{/if}}
12
+ {{#if hasAclCheck}}{{{genAclCheckCall endpoint}}}{{/if}}
13
+ {{#if hasQueryFnBody}}return {{/if}}{{importedEndpointName endpoint}}({{{endpointArgs endpoint}}}{{#if hasAxiosRequestConfig}}{{#if (endpointArgs endpoint)}}, {{/if}}{{axiosRequestConfigName}}{{/if}}){{else}}{{importedEndpointName endpoint}}{{/if}}
14
+ {{#if hasQueryFnBody}} }{{/if}},
15
+ ...options,
16
+ });
17
+ };
@@ -0,0 +1,54 @@
1
+ {{! Axios import }}
2
+ {{#if hasAxiosImport}}
3
+ {{{genImport axiosImport}}}
4
+ {{/if}}
5
+ {{! React query import }}
6
+ {{{genImport queryImport}}}
7
+ {{! Query modules import }}
8
+ {{#if hasMutationEffects}}
9
+ {{{genImport queryModulesImport}}}
10
+ {{/if}}
11
+ {{! Mutation effects import }}
12
+ {{#if hasMutationEffectsImport}}
13
+ {{{genImport mutationEffectsImport}}}
14
+ {{/if}}
15
+ {{! Acl check import }}
16
+ {{#if hasAclCheck}}
17
+ {{{genImport aclCheckImport}}}
18
+ {{#each aclImports as | aclImport |}}
19
+ {{{genImport aclImport}}}
20
+ {{/each}}
21
+ {{/if}}
22
+ {{! React query types import }}
23
+ {{{genImport queryTypesImport}}}
24
+ {{! Models import }}
25
+ {{#each modelsImports as | modelsImport |}}
26
+ {{{genImport modelsImport}}}
27
+ {{/each}}
28
+ {{! Endpoints import }}
29
+ {{#each endpointsImports as | endpointsImport |}}
30
+ {{{genImport endpointsImport}}}
31
+ {{/each}}
32
+
33
+ {{#if includeNamespace}}
34
+ export namespace {{namespace}} {
35
+ {{/if}}
36
+
37
+ export const {{queriesModuleName}} = {{#if hasMutationEffects}}{{queryModuleEnum}}.{{tag}}{{else}}"{{namespace}}"{{/if}};
38
+
39
+ {{! Query keys export}}
40
+ {{{genQueryKeys queryEndpoints}}}
41
+
42
+ {{! Query export }}
43
+ {{#each endpoints as | endpoint |}}
44
+ {{{genQuery endpoint}}}
45
+
46
+ {{{genMutation endpoint ../queryEndpoints}}}
47
+
48
+ {{{genInfiniteQuery endpoint}}}
49
+
50
+ {{/each}}
51
+
52
+ {{#if includeNamespace}}
53
+ }
54
+ {{/if}}
@@ -0,0 +1,5 @@
1
+ export const enum QueryModule {
2
+ {{#each modules as | module |}}
3
+ {{module.tag}} = "{{module.namespace}}",
4
+ {{/each}}
5
+ }
@@ -0,0 +1,49 @@
1
+ {{! Zod import }}
2
+ {{{genImport zodImport}}}
3
+ {{! Error handling import }}
4
+ {{{genImport errorHandlingImport}}}
5
+
6
+ export namespace ZodExtended {
7
+ interface ParseOptions {
8
+ type: "body" | "query";
9
+ name?: string;
10
+ errorHandler?: ErrorHandler<never>;
11
+ }
12
+
13
+ export function {{parse}}<ZOutput, ZInput>(
14
+ schema: z.ZodType<ZOutput, ZInput>,
15
+ data: unknown,
16
+ { type, name, errorHandler }: ParseOptions = { type: "body" },
17
+ ) {
18
+ try {
19
+ return schema.parse(data);
20
+ } catch (e) {
21
+ if (e instanceof z.ZodError) {
22
+ e.name = `FE Request ${type === "body" ? "body" : "query param"}${name ? ` ("${name}")` : ""} schema mismatch - ZodError`;
23
+ }
24
+ (errorHandler ?? {{sharedErrorHandler}}).rethrowError(e);
25
+ throw e;
26
+ }
27
+ }
28
+
29
+ function is{{capitalize sortExp}}Valid(enumSchema: z.ZodEnum, data?: string) {
30
+ if (data === undefined || data === "" || enumSchema.options.length === 0) {
31
+ return true;
32
+ }
33
+
34
+ const prefixedEnumOptions = `([+-]?(${enumSchema.options.join("|")}))`;
35
+ const commaSeparatedOptions = `(${prefixedEnumOptions})(\s*,\s*${prefixedEnumOptions})*`;
36
+ return new RegExp(`^${commaSeparatedOptions}$`).test(data);
37
+ }
38
+
39
+ export const {{sortExp}} = (enumSchema: z.ZodEnum) =>
40
+ z.string().superRefine((arg, ctx) => {
41
+ if (!is{{capitalize sortExp}}Valid(enumSchema, arg)) {
42
+ ctx.addIssue({
43
+ code: "invalid_value",
44
+ message: "Invalid sorting string.",
45
+ values: [],
46
+ });
47
+ }
48
+ });
49
+ }
package/dist/acl.d.mts DELETED
@@ -1,59 +0,0 @@
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 };
@@ -1,59 +0,0 @@
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 };
@@ -1,6 +0,0 @@
1
- import { t as GenerateOptions } from "./options-fyt0BYYE.mjs";
2
-
3
- //#region src/generators/types/config.d.ts
4
- type OpenAPICodegenConfig = Partial<GenerateOptions>;
5
- //#endregion
6
- export { OpenAPICodegenConfig as t };
@@ -1,38 +0,0 @@
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 };
@@ -1,187 +0,0 @@
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 };
@@ -1,90 +0,0 @@
1
- import { S as Profiler, i as writeGenerateFileData, m as DEFAULT_GENERATE_OPTIONS, o as deepMerge, r as removeStaleGeneratedFiles, t as generateCodeFromOpenAPIDoc } from "./generateCodeFromOpenAPIDoc-CFbiHxB7.mjs";
2
- import path from "path";
3
- import SwaggerParser from "@apidevtools/swagger-parser";
4
-
5
- //#region src/generators/core/resolveConfig.ts
6
- function resolveConfig({ fileConfig = {}, params: { includeTags, excludeTags, inlineEndpointsExcludeModules, workspaceContext, ...options } }) {
7
- const resolvedConfig = deepMerge(DEFAULT_GENERATE_OPTIONS, fileConfig ?? {}, {
8
- ...options,
9
- includeTags: includeTags?.split(","),
10
- excludeTags: excludeTags?.split(","),
11
- inlineEndpointsExcludeModules: inlineEndpointsExcludeModules?.split(","),
12
- workspaceContext: workspaceContext?.split(",")
13
- });
14
- resolvedConfig.checkAcl = resolvedConfig.acl && resolvedConfig.checkAcl;
15
- resolvedConfig.workspaceContext = Array.from(new Set((resolvedConfig.workspaceContext ?? []).map((value) => value.trim()).filter(Boolean)));
16
- return resolvedConfig;
17
- }
18
-
19
- //#endregion
20
- //#region src/generators/run/generate.runner.ts
21
- async function runGenerate({ fileConfig, params, formatGeneratedFile, profiler = new Profiler(process.env.OPENAPI_CODEGEN_PROFILE === "1") }) {
22
- const config = profiler.runSync("config.resolve", () => resolveConfig({
23
- fileConfig,
24
- params: params ?? {}
25
- }));
26
- const openApiDoc = await getOpenApiDoc(config.input, profiler);
27
- const filesData = profiler.runSync("generate.total", () => generateCodeFromOpenAPIDoc(openApiDoc, config, profiler));
28
- if (config.clearOutput) profiler.runSync("files.removeStaleGenerated", () => {
29
- removeStaleGeneratedFiles({
30
- output: config.output,
31
- filesData,
32
- options: config
33
- });
34
- });
35
- await profiler.runAsync("files.write", async () => {
36
- await writeGenerateFileData(filesData, { formatGeneratedFile });
37
- });
38
- return {
39
- skipped: false,
40
- config,
41
- stats: getGenerateStats(filesData, config)
42
- };
43
- }
44
- async function getOpenApiDoc(input, profiler) {
45
- const parsedDoc = await profiler.runAsync("openapi.parse", async () => await SwaggerParser.parse(input));
46
- if (!profiler.runSync("openapi.detectExternalRefs", () => hasExternalRef(parsedDoc))) return parsedDoc;
47
- return await profiler.runAsync("openapi.bundle", async () => await SwaggerParser.bundle(input));
48
- }
49
- function hasExternalRef(value) {
50
- const stack = [value];
51
- const visited = /* @__PURE__ */ new Set();
52
- while (stack.length > 0) {
53
- const current = stack.pop();
54
- if (!current || typeof current !== "object") continue;
55
- if (visited.has(current)) continue;
56
- visited.add(current);
57
- if ("$ref" in current && typeof current.$ref === "string" && !current.$ref.startsWith("#/")) return true;
58
- for (const nested of Object.values(current)) if (nested && typeof nested === "object") stack.push(nested);
59
- }
60
- return false;
61
- }
62
- function getGenerateStats(filesData, config) {
63
- const generatedFilesCount = filesData.length;
64
- if (generatedFilesCount === 0) return {
65
- generatedFilesCount,
66
- generatedModulesCount: 0
67
- };
68
- if (!config.splitByTags) return {
69
- generatedFilesCount,
70
- generatedModulesCount: 1
71
- };
72
- const moduleSuffixes = new Set(Object.values(config.configs).map((generateConfig) => generateConfig.outputFileNameSuffix).filter(Boolean));
73
- const modules = /* @__PURE__ */ new Set();
74
- for (const file of filesData) {
75
- const segments = path.relative(config.output, file.fileName).split(path.sep).filter(Boolean);
76
- if (segments.length < 2) continue;
77
- const moduleName = segments[0];
78
- const fileName = segments[segments.length - 1];
79
- if (!fileName.startsWith(`${moduleName}.`)) continue;
80
- const suffix = fileName.slice(moduleName.length + 1).replace(/\.tsx?$/, "");
81
- if (moduleSuffixes.has(suffix)) modules.add(moduleName);
82
- }
83
- return {
84
- generatedFilesCount,
85
- generatedModulesCount: modules.size
86
- };
87
- }
88
-
89
- //#endregion
90
- export { resolveConfig as n, runGenerate as t };