@povio/openapi-codegen-cli 2.0.8-rc.9 → 3.0.0-rc.2

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 (49) hide show
  1. package/README.md +32 -4
  2. package/dist/acl.d.mts +12 -1
  3. package/dist/acl.mjs +14 -3
  4. package/dist/{config-Cu_GYfai.d.mts → config-C1ME3Ay4.d.mts} +1 -1
  5. package/dist/error-handling-CvW_FecB.d.mts +38 -0
  6. package/dist/error-handling-DkPY7Asf.mjs +187 -0
  7. package/dist/generate.runner-BsNMtOTd.mjs +90 -0
  8. package/dist/{generateCodeFromOpenAPIDoc-BOjk_Ey8.mjs → generateCodeFromOpenAPIDoc-CbBWYEZG.mjs} +2482 -2132
  9. package/dist/generator.d.mts +1 -1
  10. package/dist/generator.mjs +1 -1
  11. package/dist/index.d.mts +45 -60
  12. package/dist/index.mjs +76 -189
  13. package/dist/{options-DBz5YE3s.d.mts → options-BPAjzilp.d.mts} +12 -2
  14. package/dist/sh.mjs +22 -6
  15. package/dist/vite.d.mts +7 -4
  16. package/dist/vite.mjs +9 -6
  17. package/dist/zod.d.mts +20 -0
  18. package/dist/zod.mjs +33 -0
  19. package/package.json +12 -8
  20. package/dist/generate.runner-CSqX4Uw7.mjs +0 -98
  21. package/src/assets/useCrossTabQueryInvalidation.ts +0 -40
  22. package/src/assets/useMutationEffects.ts +0 -94
  23. package/src/generators/templates/acl-check.hbs +0 -29
  24. package/src/generators/templates/acl.hbs +0 -19
  25. package/src/generators/templates/app-acl.hbs +0 -17
  26. package/src/generators/templates/app-rest-client.hbs +0 -7
  27. package/src/generators/templates/configs.hbs +0 -80
  28. package/src/generators/templates/endpoints.hbs +0 -43
  29. package/src/generators/templates/models.hbs +0 -23
  30. package/src/generators/templates/partials/acl-check-call.hbs +0 -1
  31. package/src/generators/templates/partials/casl-ability-function.hbs +0 -12
  32. package/src/generators/templates/partials/casl-ability-query.hbs +0 -1
  33. package/src/generators/templates/partials/casl-ability-type.hbs +0 -1
  34. package/src/generators/templates/partials/columns-config.hbs +0 -11
  35. package/src/generators/templates/partials/endpoint-config.hbs +0 -31
  36. package/src/generators/templates/partials/endpoint-param-parse.hbs +0 -1
  37. package/src/generators/templates/partials/endpoint-params.hbs +0 -1
  38. package/src/generators/templates/partials/import.hbs +0 -1
  39. package/src/generators/templates/partials/inputs-config.hbs +0 -10
  40. package/src/generators/templates/partials/model-js-docs.hbs +0 -6
  41. package/src/generators/templates/partials/query-js-docs.hbs +0 -31
  42. package/src/generators/templates/partials/query-keys.hbs +0 -11
  43. package/src/generators/templates/partials/query-use-infinite-query.hbs +0 -21
  44. package/src/generators/templates/partials/query-use-mutation.hbs +0 -54
  45. package/src/generators/templates/partials/query-use-query.hbs +0 -16
  46. package/src/generators/templates/queries.hbs +0 -54
  47. package/src/generators/templates/query-modules.hbs +0 -5
  48. package/src/generators/templates/zod-extended.hbs +0 -49
  49. /package/dist/{auth.context-DKjzWiaA.mjs → auth.context-Bu5KW2sI.mjs} +0 -0
@@ -1,6 +0,0 @@
1
- /**
2
- * {{name}}
3
- * @type { {{zodSchemaType zodSchema}} }{{#if (zodSchemaDescription zodSchema)}}
4
- * @description {{{zodSchemaDescription zodSchema}}}{{/if}}
5
- {{#if (zodSchemaPropertyDescriptions zodSchema tag)}}{{#each (zodSchemaPropertyDescriptions zodSchema tag) as | property |}} * @property { {{property.type}} } {{@key}} {{{addAsteriskAfterNewLine property.description}}}
6
- {{/each}}{{/if}} */
@@ -1,31 +0,0 @@
1
- {{#if infiniteQuery}}
2
- /**
3
- * Infinite query `{{infiniteQueryName endpoint}}{{#if endpoint.summary}}
4
- * @summary {{addAsteriskAfterNewLine endpoint.summary}}{{/if}}{{#if endpoint.description}}
5
- * @description {{addAsteriskAfterNewLine endpoint.description}}{{/if}}{{#if endpoint.acl}}
6
- * @permission Requires `{{abilityFunctionName endpoint}}` ability {{/if}}
7
- {{#if (endpointParams endpoint)}}{{#each (endpointParams endpoint infiniteQuery excludePageParam=true) as | endpointParam |}} * @param { {{{endpointParam.type}}} } object.{{endpointParam.name}} {{{endpointParamDescription endpointParam}}}
8
- {{/each}}{{/if}} * @param { AppInfiniteQueryOptions } options Infinite query options
9
- * @returns { UseInfiniteQueryResult<{{{importedZodSchemaInferedType endpoint.response}}}> } {{endpoint.responseDescription}}
10
- * @statusCodes [{{commaSeparated endpoint.responseStatusCodes}}]
11
- */{{else if query}}
12
- /**
13
- * Query `{{queryName endpoint}}`{{#if endpoint.summary}}{{#if endpoint.mediaDownload}} - recommended when file should be cached{{/if}}
14
- * @summary {{addAsteriskAfterNewLine endpoint.summary}}{{/if}}{{#if endpoint.description}}
15
- * @description {{addAsteriskAfterNewLine endpoint.description}}{{/if}}{{#if endpoint.acl}}
16
- * @permission Requires `{{abilityFunctionName endpoint}}` ability {{/if}}
17
- {{#if (endpointParams endpoint includeFileParam=true)}}{{#each (endpointParams endpoint includeFileParam=true) as | endpointParam |}} * @param { {{{endpointParam.type}}} } object.{{endpointParam.name}} {{{endpointParamDescription endpointParam}}}
18
- {{/each}}{{/if}} * @param { AppQueryOptions } options Query options
19
- * @returns { UseQueryResult<{{#if endpoint.mediaDownload}}AxiosResponse<{{/if}}{{{importedZodSchemaInferedType endpoint.response}}}{{#if endpoint.mediaDownload}}>{{/if}}> } {{endpoint.responseDescription}}
20
- * @statusCodes [{{commaSeparated endpoint.responseStatusCodes}}]
21
- */{{else if mutation}}
22
- /**
23
- * Mutation `{{queryName endpoint mutation=true}}`{{#if endpoint.summary}}{{#if endpoint.mediaDownload}} - recommended when file should not be cached{{/if}}
24
- * @summary {{addAsteriskAfterNewLine endpoint.summary}}{{/if}}{{#if endpoint.description}}
25
- * @description {{addAsteriskAfterNewLine endpoint.description}}{{/if}}{{#if endpoint.acl}}
26
- * @permission Requires `{{abilityFunctionName endpoint}}` ability {{/if}}
27
- {{#if (endpointParams endpoint includeFileParam=true)}}{{#each (endpointParams endpoint includeFileParam=true) as | endpointParam |}} * @param { {{{endpointParam.type}}} } mutation.{{endpointParam.name}} {{{endpointParamDescription endpointParam}}}
28
- {{/each}}{{/if}} * @param { AppMutationOptions{{#if hasMutationEffects}} & {{mutationEffectsType}}{{/if}} } options Mutation options
29
- * @returns { UseMutationResult<{{#if endpoint.mediaDownload}}AxiosResponse<{{/if}}{{{importedZodSchemaInferedType endpoint.response}}}{{#if endpoint.mediaDownload}}>{{/if}}> } {{endpoint.responseDescription}}
30
- * @statusCodes [{{commaSeparated endpoint.responseStatusCodes}}]
31
- */{{/if}}
@@ -1,11 +0,0 @@
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
- };
@@ -1,21 +0,0 @@
1
- {{! Js docs }}
2
- {{{genQueryJsDocs endpoint infiniteQuery=true}}}
3
- {{! Infinite query definition}}
4
- export const {{infiniteQueryName endpoint}} = <TData>({{#if (endpointParams endpoint)}}{ {{{endpointArgs endpoint excludePageParam=true}}} }: { {{{genEndpointParams endpoint excludePageParam=true}}} }, {{/if}}options?: AppInfiniteQueryOptions<typeof {{importedEndpointName endpoint}}, TData>{{#if hasAxiosRequestConfig}}, {{axiosRequestConfigName}}?: {{axiosRequestConfigType}}{{/if}}) => {
5
- {{! Use acl check }}
6
- {{#if hasAclCheck}}const { checkAcl } = {{aclCheckHook}}();{{/if}}
7
-
8
- return {{infiniteQueryHook}}({
9
- queryKey: keys.{{endpointName endpoint}}Infinite({{#if (endpointParams endpoint)}}{{{endpointArgs endpoint excludePageParam=true}}}{{/if}}),
10
- queryFn: ({ pageParam }) => {{#if hasQueryFnBody}}{ {{/if}}
11
- {{#if hasAclCheck}}{{{genAclCheckCall endpoint}}}{{/if}}
12
- {{#if hasQueryFnBody}}return {{/if}}{{importedEndpointName endpoint}}({{{endpointArgs endpoint replacePageParam=true}}}{{#if hasAxiosRequestConfig}}, {{axiosRequestConfigName}}{{/if}})
13
- {{#if hasQueryFnBody}} }{{/if}},
14
- initialPageParam: 1,
15
- getNextPageParam: ({ {{pageParamName}}, {{totalItemsName}}, {{limitParamName}}: limitParam }) => {
16
- const pageParam = {{pageParamName}} ?? 1;
17
- return pageParam * limitParam < {{totalItemsName}} ? pageParam + 1 : null;
18
- },
19
- ...options,
20
- });
21
- };
@@ -1,54 +0,0 @@
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
- };
@@ -1,16 +0,0 @@
1
- {{! Js docs }}
2
- {{{genQueryJsDocs endpoint query=true}}}
3
- {{! Query definition}}
4
- export const {{queryName endpoint}} = <TData>({{#if (endpointParams endpoint)}}{ {{{endpointArgs endpoint}}} }: { {{{genEndpointParams endpoint}}} }, {{/if}}options?: AppQueryOptions<typeof {{importedEndpointName endpoint}}, TData>{{#if hasAxiosRequestConfig}}, {{axiosRequestConfigName}}?: {{axiosRequestConfigType}}{{/if}}) => {
5
- {{! Use acl check }}
6
- {{#if hasAclCheck}}const { checkAcl } = {{aclCheckHook}}();{{/if}}
7
-
8
- return {{queryHook}}({
9
- queryKey: keys.{{endpointName endpoint}}({{#if (endpointParams endpoint)}}{{{endpointArgs endpoint}}}{{/if}}),
10
- queryFn: {{#if hasQueryFn}}() => {{#if hasQueryFnBody}}{ {{/if}}
11
- {{#if hasAclCheck}}{{{genAclCheckCall endpoint}}}{{/if}}
12
- {{#if hasQueryFnBody}}return {{/if}}{{importedEndpointName endpoint}}({{{endpointArgs endpoint}}}{{#if hasAxiosRequestConfig}}{{#if (endpointArgs endpoint)}}, {{/if}}{{axiosRequestConfigName}}{{/if}}){{else}}{{importedEndpointName endpoint}}{{/if}}
13
- {{#if hasQueryFnBody}} }{{/if}},
14
- ...options,
15
- });
16
- };
@@ -1,54 +0,0 @@
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}}
@@ -1,5 +0,0 @@
1
- export const enum QueryModule {
2
- {{#each modules as | module |}}
3
- {{module.tag}} = "{{module.namespace}}",
4
- {{/each}}
5
- }
@@ -1,49 +0,0 @@
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
- }